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
+17
View File
@@ -69,6 +69,14 @@ export interface DatasetState {
/** Low-level: add a fully-formed dataset and select it. */
add: (dataset: Dataset) => void;
/**
* Append imported datasets (spec §08 → datasets imported before snippets). Each
* is given a fresh monotonic numeric id so a batch never collides on the
* `Date.now()` default (the `add` TODO) nor with existing ids — safe because
* datasets are referenced by **name**, not id (docs/architecture/07 §1). Names
* are assumed already de-duped by the import service. Selection is unchanged.
*/
addDatasets: (incoming: Dataset[]) => void;
/** Low-level: merge a patch into a dataset, advancing `modified`. */
update: (id: number, patch: Partial<Dataset>, now?: Date) => void;
/** Low-level: remove a dataset; clears the selection if it was selected. */
@@ -237,6 +245,15 @@ export const useDatasetStore = create<DatasetState>((set, get) => ({
// before wiring import.
add: (dataset) => set((s) => ({ datasets: [dataset, ...s.datasets], selectedId: dataset.id })),
addDatasets: (incoming) => {
if (incoming.length === 0) return;
set((s) => {
let nextId = s.datasets.reduce((max, d) => Math.max(max, d.id), 0) + 1;
const withIds = incoming.map((d) => ({ ...d, id: nextId++ }));
return { datasets: [...withIds, ...s.datasets] };
});
},
update: (id, patch, now) => {
const modified = patch.modified ?? (now ?? new Date()).toISOString();
set((s) => ({