From 3301d81ed6c4acf7acf0465d47acbaafb50e2172 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Wed, 13 May 2026 15:40:17 +0200 Subject: [PATCH] refactor(frontend): per-workspace UserDraft handles in Resource/Variable editors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier commits in this PR wired the resource and variable editors to a single multi-workspace bundle stored under the user's session workspace key — which mixed workspaces in one localStorage entry and required a custom multi-key fix-up pass to persist edits for other workspaces. Reset both editors to their pre-PR shape and apply the minimal change: the per-workspace `Record` (resp. `VariableState`) becomes `Record>`, with one handle per workspace created via `UserDraft.use(…, { workspace: ws })`. The handle keys its own localStorage entry under that workspace, so cross-workspace edits stay cleanly separated and reactivity flows through the handle's `draft` accessor — `bind:` on form fields just works. Adds `manualRelease: true` + `handle.release()` to `UserDraft.use` so the editors can register handles lazily inside an effect (Svelte 5 forbids `onDestroy` outside component init). The editors register a single top-level `onDestroy` that releases every collected handle. After a successful save, the per-workspace autosave is cleared via `UserDraft.remove(itemKind, path, { workspace })`. --- .../src/lib/components/ResourceEditor.svelte | 105 ++++++++---------- .../src/lib/components/VariableEditor.svelte | 89 +++++++-------- frontend/src/lib/userDraft.svelte.ts | 28 ++++- frontend/src/lib/userDraft.test.ts | 22 ++++ 4 files changed, 135 insertions(+), 109 deletions(-) diff --git a/frontend/src/lib/components/ResourceEditor.svelte b/frontend/src/lib/components/ResourceEditor.svelte index 4e8d2cb363..39bf946f21 100644 --- a/frontend/src/lib/components/ResourceEditor.svelte +++ b/frontend/src/lib/components/ResourceEditor.svelte @@ -1,8 +1,8 @@