mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Add snippet metadata panel, duplicate, and immediate-load preview (M4.5)
This commit is contained in:
@@ -126,6 +126,35 @@ export function createSnippet(options: CreateSnippetOptions = {}): Snippet {
|
||||
};
|
||||
}
|
||||
|
||||
export interface DuplicateSnippetOptions {
|
||||
/** Clock injection for deterministic tests; defaults to the current time. */
|
||||
now?: Date;
|
||||
/** Id injection for deterministic tests; defaults to a random UUID. */
|
||||
id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an independent copy of a snippet (spec §02 → Duplicate). The copy carries
|
||||
* over the specification (both published and draft), comment, tags, and dataset
|
||||
* references, gets a new identity and fresh created/modified timestamps, and a name
|
||||
* suffixed "(copy)". Mutable members are cloned so the copy shares no references
|
||||
* with its source.
|
||||
*/
|
||||
export function duplicateSnippet(source: Snippet, options: DuplicateSnippetOptions = {}): Snippet {
|
||||
const iso = (options.now ?? new Date()).toISOString();
|
||||
return {
|
||||
...source,
|
||||
id: options.id ?? crypto.randomUUID(),
|
||||
version: CURRENT_SNIPPET_VERSION,
|
||||
name: `${source.name} (copy)`,
|
||||
created: iso,
|
||||
modified: iso,
|
||||
tags: [...source.tags],
|
||||
datasetRefs: [...source.datasetRefs],
|
||||
meta: { ...source.meta },
|
||||
};
|
||||
}
|
||||
|
||||
/** True when the snippet's draft differs from its published spec (§03D). */
|
||||
export function hasUnpublishedChanges(snippet: Snippet): boolean {
|
||||
return snippet.draftSpec !== snippet.spec;
|
||||
|
||||
Reference in New Issue
Block a user