mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Add distributed settings and workspace import/export (M5)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user