Add distributed settings and workspace import/export (M5)

This commit is contained in:
2026-06-07 15:51:00 +03:00
parent 80bedd2a8d
commit 548aa199d9
38 changed files with 3150 additions and 101 deletions
+23
View File
@@ -46,6 +46,13 @@ export interface SnippetState {
/** Replace the library from storage and choose an active snippet. */
hydrate: (snippets: Snippet[], activeId?: string | null) => void;
/**
* Append imported snippets (spec §08 → merge: appended, never overwritten). Ids
* are assumed already unique against the library (the import service reassigns
* collisions). Keeps the current selection; selects the newest import only when
* nothing is active, so an import into an empty workspace lands the user on it.
*/
addSnippets: (incoming: Snippet[]) => void;
/** Create a new snippet (sample template by default), prepend, and select it. */
createSnippet: (options?: CreateSnippetOptions) => string;
/** Make a snippet active and load its draft into the editor buffer. */
@@ -148,6 +155,22 @@ export const useSnippetStore = create<SnippetState>((set, get) => ({
}));
},
addSnippets: (incoming) => {
if (incoming.length === 0) return;
set((s) => {
const snippets = [...incoming, ...s.snippets];
if (s.activeSnippetId !== null) return { snippets };
const id = newestId(snippets);
return {
snippets,
activeSnippetId: id,
draftText: draftFor(snippets, id),
editorView: 'draft',
bufferEpoch: s.bufferEpoch + 1,
};
});
},
createSnippet: (options) => {
get().commitDraft(); // flush the outgoing snippet's valid edits before switching away
const created = createSnippet(options);