Add snippet metadata panel, duplicate, and immediate-load preview (M4.5)

This commit is contained in:
2026-06-06 23:54:59 +03:00
parent 3e89d9a531
commit 80bedd2a8d
13 changed files with 785 additions and 51 deletions
+29
View File
@@ -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;