@flowdrop/flowdrop 1.15.0 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +648 -0
- package/MIGRATION-2.0.md +642 -0
- package/README.md +28 -28
- package/dist/adapters/WorkflowAdapter.d.ts +1 -1
- package/dist/adapters/WorkflowAdapter.js +18 -13
- package/dist/adapters/agentspec/AgentSpecAdapter.js +10 -10
- package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
- package/dist/api/enhanced-client.js +6 -11
- package/dist/chat/batchFeedback.d.ts +39 -0
- package/dist/chat/batchFeedback.js +51 -0
- package/dist/commands/executor.js +66 -27
- package/dist/commands/storeIntegration.svelte.d.ts +4 -1
- package/dist/commands/storeIntegration.svelte.js +36 -21
- package/dist/commands/types.d.ts +2 -0
- package/dist/commands/types.js +5 -5
- package/dist/components/App.svelte +696 -565
- package/dist/components/App.svelte.d.ts +63 -16
- package/dist/components/Button.stories.svelte +65 -0
- package/dist/components/Button.stories.svelte.d.ts +19 -0
- package/dist/components/Button.svelte +62 -0
- package/dist/components/Button.svelte.d.ts +24 -0
- package/dist/components/CanvasIconButton.svelte +76 -0
- package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
- package/dist/components/ConfigForm.svelte +181 -552
- package/dist/components/ConfigForm.svelte.d.ts +24 -7
- package/dist/components/ConfigModal.svelte +16 -3
- package/dist/components/ConfigPanel.svelte +234 -15
- package/dist/components/ConfigPanel.svelte.d.ts +6 -0
- package/dist/components/ConnectionLine.svelte +4 -2
- package/dist/components/EditorStatusBar.stories.svelte +44 -0
- package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
- package/dist/components/EditorStatusBar.svelte +99 -0
- package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
- package/dist/components/IconButton.svelte +80 -0
- package/dist/components/IconButton.svelte.d.ts +30 -0
- package/dist/components/Input.svelte +74 -0
- package/dist/components/Input.svelte.d.ts +17 -0
- package/dist/components/LogoWordmark.svelte +113 -0
- package/dist/components/LogoWordmark.svelte.d.ts +26 -0
- package/dist/components/Navbar.svelte +78 -64
- package/dist/components/Navbar.svelte.d.ts +3 -0
- package/dist/components/NodeSidebar.svelte +48 -171
- package/dist/components/NodeStatusOverlay.svelte +94 -6
- package/dist/components/NodeSwapPicker.svelte +22 -38
- package/dist/components/PipelineStatus.svelte +22 -68
- package/dist/components/PipelineStatus.svelte.d.ts +3 -0
- package/dist/components/PortCoordinateTracker.svelte +5 -6
- package/dist/components/PortMappingRow.svelte +0 -2
- package/dist/components/SchemaForm.stories.svelte +1 -3
- package/dist/components/SchemaForm.svelte +22 -39
- package/dist/components/SchemaForm.svelte.d.ts +0 -8
- package/dist/components/Select.svelte +53 -0
- package/dist/components/Select.svelte.d.ts +15 -0
- package/dist/components/SettingsModal.svelte +8 -8
- package/dist/components/SettingsPanel.svelte +44 -10
- package/dist/components/SwapMappingEditor.svelte +67 -49
- package/dist/components/SwapMappingEditor.svelte.d.ts +0 -2
- package/dist/components/Textarea.svelte +39 -0
- package/dist/components/Textarea.svelte.d.ts +12 -0
- package/dist/components/ThemeToggle.svelte +15 -94
- package/dist/components/UniversalNode.svelte +45 -11
- package/dist/components/UniversalNode.svelte.d.ts +1 -1
- package/dist/components/WorkflowEditor.svelte +183 -162
- package/dist/components/WorkflowEditor.svelte.d.ts +39 -10
- package/dist/components/chat/AIChatPanel.svelte +99 -90
- package/dist/components/chat/AIChatPanel.svelte.d.ts +0 -4
- package/dist/components/chat/CommandPreview.svelte +2 -1
- package/dist/components/console/CommandConsole.svelte +7 -5
- package/dist/components/console/ConsoleAutocomplete.svelte +11 -12
- package/dist/components/console/ConsoleAutocomplete.svelte.d.ts +6 -0
- package/dist/components/console/ConsoleInput.svelte +18 -9
- package/dist/components/console/ConsoleOutput.svelte +4 -3
- package/dist/components/form/FormArray.svelte +42 -182
- package/dist/components/form/FormArray.svelte.d.ts +2 -1
- package/dist/components/form/FormAutocomplete.svelte +26 -21
- package/dist/components/form/FormCheckboxGroup.svelte +1 -5
- package/dist/components/form/FormCodeEditor.svelte +9 -7
- package/dist/components/form/FormField.svelte +22 -44
- package/dist/components/form/FormFieldLight.svelte +56 -50
- package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
- package/dist/components/form/FormFieldset.svelte +45 -11
- package/dist/components/form/FormMarkdownEditor.svelte +17 -9
- package/dist/components/form/FormNumberField.svelte +4 -36
- package/dist/components/form/FormPorts.svelte +262 -0
- package/dist/components/form/FormPorts.svelte.d.ts +13 -0
- package/dist/components/form/FormRangeField.svelte +62 -30
- package/dist/components/form/FormSelect.svelte +13 -75
- package/dist/components/form/FormTemplateEditor.svelte +17 -7
- package/dist/components/form/FormTextField.svelte +3 -35
- package/dist/components/form/FormTextarea.svelte +4 -39
- package/dist/components/form/FormToggle.svelte +5 -16
- package/dist/components/form/FormToggle.svelte.d.ts +4 -2
- package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
- package/dist/components/form/resolveFieldType.d.ts +24 -0
- package/dist/components/form/resolveFieldType.js +55 -0
- package/dist/components/form/templateAutocomplete.js +1 -5
- package/dist/components/form/types.d.ts +1 -14
- package/dist/components/icons/CloseIcon.svelte +6 -0
- package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
- package/dist/components/icons/CommandLineIcon.svelte +15 -0
- package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuIcon.svelte +4 -0
- package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuOpenIcon.svelte +6 -0
- package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
- package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
- package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
- package/dist/components/interrupt/FormPrompt.svelte +3 -2
- package/dist/components/interrupt/InterruptBubble.svelte +25 -27
- package/dist/components/interrupt/ReviewPrompt.svelte +10 -23
- package/dist/components/interrupt/TextInputPrompt.svelte +2 -7
- package/dist/components/layouts/MainLayout.svelte +24 -18
- package/dist/components/layouts/MainLayout.svelte.d.ts +4 -0
- package/dist/components/nodes/AtomNode.svelte +70 -72
- package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
- package/dist/components/nodes/GatewayNode.svelte +134 -172
- package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
- package/dist/components/nodes/IdeaNode.svelte +79 -98
- package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
- package/dist/components/nodes/NodeConfigButton.svelte +86 -0
- package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
- package/dist/components/nodes/NotesNode.svelte +76 -85
- package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
- package/dist/components/nodes/SimpleNode.svelte +68 -137
- package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
- package/dist/components/nodes/SquareNode.svelte +122 -169
- package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
- package/dist/components/nodes/TerminalNode.svelte +70 -127
- package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
- package/dist/components/nodes/ToolNode.svelte +99 -104
- package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
- package/dist/components/nodes/WorkflowNode.svelte +145 -195
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
- package/dist/components/playground/ChatInput.svelte +11 -15
- package/dist/components/playground/ChatPanel.svelte +6 -49
- package/dist/components/playground/ChatPanel.svelte.d.ts +0 -14
- package/dist/components/playground/ControlPanel.svelte +134 -123
- package/dist/components/playground/ControlPanel.svelte.d.ts +3 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -9
- package/dist/components/playground/InputCollector.svelte +22 -57
- package/dist/components/playground/MessageStream.svelte +17 -23
- package/dist/components/playground/PipelineKanbanView.svelte +69 -8
- package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
- package/dist/components/playground/PipelinePanel.svelte +31 -8
- package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
- package/dist/components/playground/PipelineTableView.svelte +188 -44
- package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
- package/dist/components/playground/Playground.svelte +154 -105
- package/dist/components/playground/Playground.svelte.d.ts +5 -0
- package/dist/components/playground/PlaygroundApp.svelte +12 -2
- package/dist/components/playground/PlaygroundApp.svelte.d.ts +6 -0
- package/dist/components/playground/PlaygroundModal.svelte +18 -3
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +6 -0
- package/dist/components/playground/PlaygroundStudio.svelte +40 -37
- package/dist/components/playground/PlaygroundStudio.svelte.d.ts +6 -0
- package/dist/components/playground/SessionManager.svelte +9 -12
- package/dist/components/playground/pipelineViewUtils.svelte.d.ts +30 -1
- package/dist/components/playground/pipelineViewUtils.svelte.js +40 -3
- package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
- package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
- package/dist/components/surfaces/TabbedSurface.svelte +133 -0
- package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
- package/dist/config/endpoints.d.ts +23 -7
- package/dist/config/endpoints.js +30 -10
- package/dist/core/index.d.ts +6 -7
- package/dist/core/index.js +8 -12
- package/dist/display/index.d.ts +6 -3
- package/dist/display/index.js +7 -5
- package/dist/editor/index.d.ts +20 -21
- package/dist/editor/index.js +26 -36
- package/dist/form/code.d.ts +25 -15
- package/dist/form/code.js +44 -41
- package/dist/form/fieldRegistry.d.ts +17 -13
- package/dist/form/fieldRegistry.js +32 -12
- package/dist/form/full.d.ts +19 -14
- package/dist/form/full.js +26 -28
- package/dist/form/index.d.ts +3 -4
- package/dist/form/index.js +6 -5
- package/dist/form/markdown.d.ts +13 -8
- package/dist/form/markdown.js +22 -23
- package/dist/helpers/proximityConnect.d.ts +3 -2
- package/dist/helpers/proximityConnect.js +2 -5
- package/dist/helpers/workflowEditorHelper.d.ts +14 -5
- package/dist/helpers/workflowEditorHelper.js +32 -30
- package/dist/index.d.ts +28 -24
- package/dist/index.js +27 -50
- package/dist/messages/defaults.d.ts +2 -5
- package/dist/messages/defaults.js +3 -6
- package/dist/messages/index.d.ts +1 -2
- package/dist/messages/index.js +1 -2
- package/dist/mocks/app-forms.d.ts +6 -2
- package/dist/mocks/app-forms.js +11 -4
- package/dist/openapi/v1/openapi.yaml +38 -26
- package/dist/playground/index.d.ts +4 -5
- package/dist/playground/index.js +4 -32
- package/dist/playground/mount.d.ts +34 -5
- package/dist/playground/mount.js +58 -24
- package/dist/registry/{BaseRegistry.d.ts → BaseRegistry.svelte.d.ts} +22 -1
- package/dist/registry/{BaseRegistry.js → BaseRegistry.svelte.js} +37 -1
- package/dist/registry/builtinFormats.d.ts +9 -18
- package/dist/registry/builtinFormats.js +9 -39
- package/dist/registry/builtinNodeTypes.d.ts +53 -0
- package/dist/registry/builtinNodeTypes.js +67 -0
- package/dist/registry/builtinNodes.d.ts +2 -64
- package/dist/registry/builtinNodes.js +7 -103
- package/dist/registry/index.d.ts +3 -4
- package/dist/registry/index.js +4 -6
- package/dist/registry/nodeComponentRegistry.d.ts +184 -16
- package/dist/registry/nodeComponentRegistry.js +235 -17
- package/dist/registry/workflowFormatRegistry.d.ts +14 -9
- package/dist/registry/workflowFormatRegistry.js +24 -8
- package/dist/{schema → schemas}/index.d.ts +2 -2
- package/dist/{schema → schemas}/index.js +2 -2
- package/dist/schemas/v1/workflow.schema.json +19 -17
- package/dist/services/agentSpecExecutionService.d.ts +0 -2
- package/dist/services/agentSpecExecutionService.js +0 -3
- package/dist/services/apiVariableService.d.ts +2 -1
- package/dist/services/apiVariableService.js +16 -47
- package/dist/services/autoSaveService.d.ts +7 -0
- package/dist/services/autoSaveService.js +6 -4
- package/dist/services/categoriesApi.js +3 -6
- package/dist/services/chatService.d.ts +9 -4
- package/dist/services/chatService.js +23 -28
- package/dist/services/draftStorage.d.ts +129 -13
- package/dist/services/draftStorage.js +185 -37
- package/dist/services/dynamicSchemaService.d.ts +33 -5
- package/dist/services/dynamicSchemaService.js +67 -55
- package/dist/services/globalSave.d.ts +13 -12
- package/dist/services/globalSave.js +29 -51
- package/dist/services/historyService.d.ts +39 -11
- package/dist/services/historyService.js +60 -18
- package/dist/services/interruptService.d.ts +15 -9
- package/dist/services/interruptService.js +35 -37
- package/dist/services/nodeExecutionService.d.ts +18 -3
- package/dist/services/nodeExecutionService.js +71 -45
- package/dist/services/playgroundService.d.ts +16 -10
- package/dist/services/playgroundService.js +42 -43
- package/dist/services/portConfigApi.js +3 -6
- package/dist/services/settingsService.d.ts +9 -4
- package/dist/services/settingsService.js +23 -12
- package/dist/services/variableService.d.ts +2 -1
- package/dist/services/variableService.js +2 -2
- package/dist/services/workflowStorage.js +6 -6
- package/dist/skins/drafter.d.ts +30 -0
- package/dist/skins/drafter.js +198 -0
- package/dist/skins/index.d.ts +2 -1
- package/dist/skins/index.js +4 -2
- package/dist/stores/apiContext.d.ts +56 -0
- package/dist/stores/apiContext.js +80 -0
- package/dist/stores/categoriesStore.svelte.d.ts +28 -23
- package/dist/stores/categoriesStore.svelte.js +69 -64
- package/dist/stores/getInstance.svelte.d.ts +39 -0
- package/dist/stores/getInstance.svelte.js +65 -0
- package/dist/stores/historyStore.svelte.d.ts +89 -91
- package/dist/stores/historyStore.svelte.js +159 -158
- package/dist/stores/instanceContainer.svelte.d.ts +111 -0
- package/dist/stores/instanceContainer.svelte.js +119 -0
- package/dist/stores/interruptStore.svelte.d.ts +112 -82
- package/dist/stores/interruptStore.svelte.js +253 -226
- package/dist/stores/pipelinePanelStore.svelte.d.ts +27 -3
- package/dist/stores/pipelinePanelStore.svelte.js +61 -14
- package/dist/stores/playgroundStore.svelte.d.ts +169 -222
- package/dist/stores/playgroundStore.svelte.js +513 -580
- package/dist/stores/portCoordinateStore.svelte.d.ts +57 -51
- package/dist/stores/portCoordinateStore.svelte.js +109 -98
- package/dist/stores/settingsStore.svelte.d.ts +17 -1
- package/dist/stores/settingsStore.svelte.js +79 -12
- package/dist/stores/workflowStore.svelte.d.ts +212 -210
- package/dist/stores/workflowStore.svelte.js +527 -502
- package/dist/stories/EdgeDecorator.svelte +5 -2
- package/dist/stories/NodeDecorator.svelte +5 -3
- package/dist/styles/base.css +285 -14
- package/dist/styles/tokens.css +60 -2
- package/dist/svelte-app.d.ts +78 -11
- package/dist/svelte-app.js +210 -141
- package/dist/themes/drafter.d.ts +2 -0
- package/dist/themes/drafter.js +15 -0
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +8 -2
- package/dist/types/auth.d.ts +9 -51
- package/dist/types/auth.js +4 -54
- package/dist/types/events.d.ts +24 -3
- package/dist/types/events.js +2 -1
- package/dist/types/index.d.ts +117 -32
- package/dist/types/index.js +0 -1
- package/dist/types/navbar.d.ts +7 -0
- package/dist/types/playground.d.ts +18 -3
- package/dist/types/settings.d.ts +30 -1
- package/dist/types/settings.js +5 -2
- package/dist/types/skin.d.ts +1 -1
- package/dist/types/theme.d.ts +16 -2
- package/dist/types/uischema.d.ts +5 -0
- package/dist/utils/colors.d.ts +74 -21
- package/dist/utils/colors.js +92 -68
- package/dist/utils/connections.d.ts +9 -15
- package/dist/utils/connections.js +33 -88
- package/dist/utils/duration.d.ts +13 -0
- package/dist/utils/duration.js +45 -0
- package/dist/utils/edgeStyling.js +9 -5
- package/dist/utils/fetchWithAuth.d.ts +36 -15
- package/dist/utils/fetchWithAuth.js +53 -23
- package/dist/utils/icons.d.ts +5 -2
- package/dist/utils/icons.js +6 -5
- package/dist/utils/nodeIds.d.ts +1 -1
- package/dist/utils/nodeIds.js +1 -1
- package/dist/utils/nodeSwap.d.ts +6 -2
- package/dist/utils/nodeSwap.js +62 -129
- package/dist/utils/nodeTypes.d.ts +17 -8
- package/dist/utils/nodeTypes.js +27 -20
- package/dist/utils/performanceUtils.js +7 -0
- package/dist/utils/portUtils.d.ts +47 -11
- package/dist/utils/portUtils.js +67 -14
- package/dist/utils/portal.d.ts +18 -0
- package/dist/utils/portal.js +34 -0
- package/dist/utils/schemaMerge.d.ts +25 -0
- package/dist/utils/schemaMerge.js +61 -0
- package/package.json +7 -5
- package/dist/messages/deprecation.d.ts +0 -20
- package/dist/messages/deprecation.js +0 -33
- package/dist/registry/plugin.d.ts +0 -215
- package/dist/registry/plugin.js +0 -249
- package/dist/services/api.d.ts +0 -129
- package/dist/services/api.js +0 -217
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-component access to the FlowDrop instance container.
|
|
3
|
+
*
|
|
4
|
+
* Components call `getInstance()` during init to resolve the instance
|
|
5
|
+
* provided by the nearest `<App>` / `<WorkflowEditor>` via Svelte context.
|
|
6
|
+
* When no provider exists (legacy single-instance usage), it falls back to
|
|
7
|
+
* the browser-only default instance.
|
|
8
|
+
*
|
|
9
|
+
* @module stores/getInstance
|
|
10
|
+
*/
|
|
11
|
+
import { DEV } from 'esm-env';
|
|
12
|
+
import { getContext, setContext } from 'svelte';
|
|
13
|
+
import { createFlowDropInstance, getDefaultInstance } from './instanceContainer.svelte.js';
|
|
14
|
+
/**
|
|
15
|
+
* Context key under which the FlowDrop instance is provided.
|
|
16
|
+
* A Symbol (matching `messages/context.ts`) so consumer context can't collide.
|
|
17
|
+
*/
|
|
18
|
+
export const FLOWDROP_INSTANCE_KEY = Symbol('flowdrop.instance');
|
|
19
|
+
let warnedAboutFallback = false;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the FlowDrop instance for the current component tree.
|
|
22
|
+
*
|
|
23
|
+
* Must be called during component initialisation (it reads Svelte context).
|
|
24
|
+
*
|
|
25
|
+
* Unlike the messages-context fallback (immutable defaults, silent), this
|
|
26
|
+
* fallback hands out *mutable shared state*, so it warns once in dev and
|
|
27
|
+
* throws during SSR rather than leaking state across server requests.
|
|
28
|
+
*/
|
|
29
|
+
export function getInstance() {
|
|
30
|
+
const instance = getContext(FLOWDROP_INSTANCE_KEY);
|
|
31
|
+
if (instance) {
|
|
32
|
+
return instance;
|
|
33
|
+
}
|
|
34
|
+
if (typeof window === 'undefined') {
|
|
35
|
+
throw new Error('[flowdrop] No FlowDrop instance in context during SSR. Render inside ' +
|
|
36
|
+
'<App> or <WorkflowEditor> (which set context), or provide one with ' +
|
|
37
|
+
'setContext(FLOWDROP_INSTANCE_KEY, createFlowDropInstance()).');
|
|
38
|
+
}
|
|
39
|
+
if (DEV && !warnedAboutFallback) {
|
|
40
|
+
warnedAboutFallback = true;
|
|
41
|
+
// eslint-disable-next-line no-console -- intentional one-time dev diagnostic for silent shared-state fallback
|
|
42
|
+
console.warn('[flowdrop] getInstance() fell back to the page-default instance — ' +
|
|
43
|
+
'fine for a single editor, but two editors mounted this way will share state.');
|
|
44
|
+
}
|
|
45
|
+
return getDefaultInstance();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve and provide the FlowDrop instance for a provider component
|
|
49
|
+
* (`<App>`, `<WorkflowEditor>`, `<Playground>`, `<PlaygroundStudio>`).
|
|
50
|
+
*
|
|
51
|
+
* Must be called during component initialisation. Resolution order:
|
|
52
|
+
* 1. An explicitly passed instance (from a mount function or consumer)
|
|
53
|
+
* 2. An instance already in context (provider nested inside another provider)
|
|
54
|
+
* 3. Browser: the page-default instance (legacy single-instance behavior)
|
|
55
|
+
* Server: a fresh per-render instance (no cross-request leakage)
|
|
56
|
+
*
|
|
57
|
+
* The resolved instance is (re-)provided via context for all children.
|
|
58
|
+
*/
|
|
59
|
+
export function provideInstance(explicit) {
|
|
60
|
+
const instance = explicit ??
|
|
61
|
+
getContext(FLOWDROP_INSTANCE_KEY) ??
|
|
62
|
+
(typeof window === 'undefined' ? createFlowDropInstance() : getDefaultInstance());
|
|
63
|
+
setContext(FLOWDROP_INSTANCE_KEY, instance);
|
|
64
|
+
return instance;
|
|
65
|
+
}
|
|
@@ -1,136 +1,134 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* History Store for FlowDrop (Svelte 5 Runes)
|
|
3
3
|
*
|
|
4
|
-
* Provides reactive Svelte 5 rune-based bindings for
|
|
4
|
+
* Provides reactive Svelte 5 rune-based bindings for a history service.
|
|
5
5
|
* Exposes undo/redo state and actions for the workflow editor.
|
|
6
6
|
*
|
|
7
|
+
* The reactive state lives in the {@link HistoryStore} class — one per
|
|
8
|
+
* FlowDrop instance, created by `createFlowDropInstance()` and resolved in
|
|
9
|
+
* components via `getInstance().historyBindings`.
|
|
10
|
+
*
|
|
7
11
|
* @module stores/historyStore
|
|
8
12
|
*/
|
|
9
|
-
import { type HistoryState, type PushOptions } from '../services/historyService.js';
|
|
13
|
+
import { HistoryService, type HistoryState, type PushOptions } from '../services/historyService.js';
|
|
10
14
|
import type { Workflow } from '../types/index.js';
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
13
|
-
* Call this when tearing down the history store (e.g., in tests or on app
|
|
14
|
-
* unmount) to prevent memory leaks.
|
|
15
|
-
*/
|
|
16
|
-
export declare function cleanupHistorySubscription(): void;
|
|
17
|
-
/**
|
|
18
|
-
* Get the current history state snapshot.
|
|
19
|
-
*
|
|
20
|
-
* Use this for binding to UI elements like undo/redo buttons.
|
|
16
|
+
* Undo/redo actions for a {@link HistoryStore}.
|
|
21
17
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* <script>
|
|
25
|
-
* import { getHistoryState } from "./historyStore.svelte.js";
|
|
26
|
-
*
|
|
27
|
-
* const state = $derived(getHistoryState());
|
|
28
|
-
* </script>
|
|
29
|
-
*
|
|
30
|
-
* <button disabled={!state.canUndo} onclick={historyActions.undo}>
|
|
31
|
-
* Undo
|
|
32
|
-
* </button>
|
|
33
|
-
* ```
|
|
18
|
+
* Bound facade — safe to detach (`onclick={fd.historyBindings.actions.undo}`)
|
|
19
|
+
* because every entry is bound to its store in the constructor.
|
|
34
20
|
*/
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set the callback for restoring workflow state
|
|
50
|
-
*
|
|
51
|
-
* This callback is invoked when undo/redo operations return a workflow.
|
|
52
|
-
* Use this to update the workflow store or other state management.
|
|
53
|
-
*
|
|
54
|
-
* @param callback - Function to call with restored workflow
|
|
55
|
-
*/
|
|
56
|
-
export declare function setOnRestoreCallback(callback: ((workflow: Workflow) => void) | null): void;
|
|
21
|
+
export interface HistoryStoreActions {
|
|
22
|
+
initialize: (workflow: Workflow) => void;
|
|
23
|
+
pushState: (workflow: Workflow, options?: PushOptions) => void;
|
|
24
|
+
undo: () => boolean;
|
|
25
|
+
redo: () => boolean;
|
|
26
|
+
startTransaction: (workflow: Workflow, description?: string) => void;
|
|
27
|
+
commitTransaction: (finalWorkflow: Workflow) => void;
|
|
28
|
+
cancelTransaction: () => void;
|
|
29
|
+
clear: (currentWorkflow?: Workflow) => void;
|
|
30
|
+
canUndo: () => boolean;
|
|
31
|
+
canRedo: () => boolean;
|
|
32
|
+
getState: () => HistoryState;
|
|
33
|
+
}
|
|
57
34
|
/**
|
|
58
|
-
*
|
|
35
|
+
* Reactive rune bindings around a {@link HistoryService}.
|
|
59
36
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
37
|
+
* Subscribes to the service on construction; call {@link cleanup} when the
|
|
38
|
+
* owning instance is destroyed to release the subscription.
|
|
62
39
|
*/
|
|
63
|
-
export declare
|
|
40
|
+
export declare class HistoryStore {
|
|
41
|
+
#private;
|
|
42
|
+
/** Bound action facade — see {@link HistoryStoreActions}. */
|
|
43
|
+
readonly actions: HistoryStoreActions;
|
|
44
|
+
constructor(service: HistoryService);
|
|
64
45
|
/**
|
|
65
|
-
*
|
|
46
|
+
* The current history state snapshot.
|
|
66
47
|
*
|
|
67
|
-
*
|
|
48
|
+
* Use this for binding to UI elements like undo/redo buttons.
|
|
68
49
|
*
|
|
69
|
-
* @
|
|
50
|
+
* @example
|
|
51
|
+
* ```svelte
|
|
52
|
+
* <script>
|
|
53
|
+
* const fd = getInstance();
|
|
54
|
+
* const state = $derived(fd.historyBindings.state);
|
|
55
|
+
* </script>
|
|
56
|
+
*
|
|
57
|
+
* <button disabled={!state.canUndo} onclick={fd.historyBindings.actions.undo}>
|
|
58
|
+
* Undo
|
|
59
|
+
* </button>
|
|
60
|
+
* ```
|
|
70
61
|
*/
|
|
71
|
-
|
|
62
|
+
get state(): HistoryState;
|
|
63
|
+
/** Whether undo is currently available (reactive). */
|
|
64
|
+
get canUndo(): boolean;
|
|
65
|
+
/** Whether redo is currently available (reactive). */
|
|
66
|
+
get canRedo(): boolean;
|
|
72
67
|
/**
|
|
73
|
-
*
|
|
68
|
+
* Set the callback for restoring workflow state.
|
|
74
69
|
*
|
|
75
|
-
*
|
|
70
|
+
* This callback is invoked when undo/redo operations return a workflow.
|
|
71
|
+
* Use this to update the workflow store or other state management.
|
|
72
|
+
*/
|
|
73
|
+
setOnRestoreCallback(callback: ((workflow: Workflow) => void) | null): void;
|
|
74
|
+
/**
|
|
75
|
+
* Set the callback run just before every undo/redo.
|
|
76
76
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* Use this to finalize an in-progress edit session (e.g. the workflow store's
|
|
78
|
+
* `finalizeNodeConfig`) so it is committed as one history step *before* being
|
|
79
|
+
* undone. The history service intentionally does not commit dangling
|
|
80
|
+
* transactions itself — it has no access to the live state — so this hook is
|
|
81
|
+
* how the owner of that state flushes it first.
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
setBeforeNavigateCallback(callback: (() => void) | null): void;
|
|
84
|
+
/**
|
|
85
|
+
* Release the history service subscription.
|
|
86
|
+
* Called by the owning instance's destroy(); safe to call repeatedly.
|
|
87
|
+
*/
|
|
88
|
+
cleanup(): void;
|
|
89
|
+
/** Initialize history with the current workflow (resets history). */
|
|
90
|
+
initialize(workflow: Workflow): void;
|
|
91
|
+
/**
|
|
92
|
+
* Push the current state to history before making changes.
|
|
93
|
+
*
|
|
94
|
+
* Call this BEFORE modifying the workflow to capture the "before" state.
|
|
95
|
+
*/
|
|
96
|
+
pushState(workflow: Workflow, options?: PushOptions): void;
|
|
81
97
|
/**
|
|
82
|
-
* Undo the last change
|
|
98
|
+
* Undo the last change.
|
|
83
99
|
*
|
|
84
100
|
* Restores the previous workflow state and invokes the restore callback.
|
|
85
101
|
*
|
|
86
102
|
* @returns true if undo was successful, false if at beginning of history
|
|
87
103
|
*/
|
|
88
|
-
undo
|
|
104
|
+
undo(): boolean;
|
|
89
105
|
/**
|
|
90
|
-
* Redo the last undone change
|
|
106
|
+
* Redo the last undone change.
|
|
91
107
|
*
|
|
92
108
|
* Restores the next workflow state and invokes the restore callback.
|
|
93
109
|
*
|
|
94
110
|
* @returns true if redo was successful, false if at end of history
|
|
95
111
|
*/
|
|
96
|
-
redo
|
|
112
|
+
redo(): boolean;
|
|
97
113
|
/**
|
|
98
|
-
* Start a transaction for grouping multiple changes
|
|
114
|
+
* Start a transaction for grouping multiple changes.
|
|
99
115
|
*
|
|
100
116
|
* All changes during a transaction are combined into a single undo entry.
|
|
101
|
-
*
|
|
102
|
-
* @param workflow - The current workflow state (before changes)
|
|
103
|
-
* @param description - Description for the combined change
|
|
104
|
-
*/
|
|
105
|
-
startTransaction: (workflow: Workflow, description?: string) => void;
|
|
106
|
-
/**
|
|
107
|
-
* Commit the current transaction
|
|
108
|
-
*/
|
|
109
|
-
commitTransaction: () => void;
|
|
110
|
-
/**
|
|
111
|
-
* Cancel the current transaction without committing
|
|
112
117
|
*/
|
|
113
|
-
|
|
118
|
+
startTransaction(workflow: Workflow, description?: string): void;
|
|
114
119
|
/**
|
|
115
|
-
*
|
|
120
|
+
* Commit the current transaction with its final (post-change) state.
|
|
116
121
|
*
|
|
117
|
-
* @param
|
|
118
|
-
*/
|
|
119
|
-
clear: (currentWorkflow?: Workflow) => void;
|
|
120
|
-
/**
|
|
121
|
-
* Check if undo is available
|
|
122
|
+
* @param finalWorkflow - The workflow state after the grouped change.
|
|
122
123
|
*/
|
|
123
|
-
|
|
124
|
+
commitTransaction(finalWorkflow: Workflow): void;
|
|
125
|
+
/** Cancel the current transaction without committing. */
|
|
126
|
+
cancelTransaction(): void;
|
|
124
127
|
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
canRedo: () => boolean;
|
|
128
|
-
/**
|
|
129
|
-
* Get the current history state synchronously
|
|
128
|
+
* Clear all history.
|
|
130
129
|
*
|
|
131
|
-
* @
|
|
130
|
+
* @param currentWorkflow - If provided, keeps this as the initial state
|
|
132
131
|
*/
|
|
133
|
-
|
|
134
|
-
}
|
|
132
|
+
clear(currentWorkflow?: Workflow): void;
|
|
133
|
+
}
|
|
135
134
|
export type { HistoryEntry, HistoryState, PushOptions } from '../services/historyService.js';
|
|
136
|
-
export { HistoryService, historyService } from '../services/historyService.js';
|
|
@@ -1,207 +1,208 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* History Store for FlowDrop (Svelte 5 Runes)
|
|
3
3
|
*
|
|
4
|
-
* Provides reactive Svelte 5 rune-based bindings for
|
|
4
|
+
* Provides reactive Svelte 5 rune-based bindings for a history service.
|
|
5
5
|
* Exposes undo/redo state and actions for the workflow editor.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// =========================================================================
|
|
11
|
-
// Reactive State (Runes)
|
|
12
|
-
// =========================================================================
|
|
13
|
-
/**
|
|
14
|
-
* Internal reactive state for history, powered by $state.
|
|
15
|
-
*/
|
|
16
|
-
let historyState = $state({
|
|
17
|
-
canUndo: false,
|
|
18
|
-
canRedo: false,
|
|
19
|
-
currentIndex: 0,
|
|
20
|
-
historyLength: 0,
|
|
21
|
-
isInTransaction: false
|
|
22
|
-
});
|
|
23
|
-
// Subscribe to history service changes and update the rune state.
|
|
24
|
-
// The unsubscribe function is stored so it can be called via
|
|
25
|
-
// cleanupHistorySubscription() when the store is torn down.
|
|
26
|
-
const _unsubscribeHistoryService = historyService.subscribe((state) => {
|
|
27
|
-
historyState = state;
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Clean up the historyService subscription created at module initialisation.
|
|
31
|
-
* Call this when tearing down the history store (e.g., in tests or on app
|
|
32
|
-
* unmount) to prevent memory leaks.
|
|
33
|
-
*/
|
|
34
|
-
export function cleanupHistorySubscription() {
|
|
35
|
-
_unsubscribeHistoryService();
|
|
36
|
-
}
|
|
37
|
-
// =========================================================================
|
|
38
|
-
// Reactive Getters
|
|
39
|
-
// =========================================================================
|
|
40
|
-
/**
|
|
41
|
-
* Get the current history state snapshot.
|
|
42
|
-
*
|
|
43
|
-
* Use this for binding to UI elements like undo/redo buttons.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```svelte
|
|
47
|
-
* <script>
|
|
48
|
-
* import { getHistoryState } from "./historyStore.svelte.js";
|
|
49
|
-
*
|
|
50
|
-
* const state = $derived(getHistoryState());
|
|
51
|
-
* </script>
|
|
52
|
-
*
|
|
53
|
-
* <button disabled={!state.canUndo} onclick={historyActions.undo}>
|
|
54
|
-
* Undo
|
|
55
|
-
* </button>
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export function getHistoryState() {
|
|
59
|
-
return historyState;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Convenience getter for canUndo state.
|
|
7
|
+
* The reactive state lives in the {@link HistoryStore} class — one per
|
|
8
|
+
* FlowDrop instance, created by `createFlowDropInstance()` and resolved in
|
|
9
|
+
* components via `getInstance().historyBindings`.
|
|
63
10
|
*
|
|
64
|
-
* @
|
|
65
|
-
*/
|
|
66
|
-
export function getCanUndo() {
|
|
67
|
-
return historyState.canUndo;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Convenience getter for canRedo state.
|
|
71
|
-
*
|
|
72
|
-
* @returns Whether redo is currently available
|
|
11
|
+
* @module stores/historyStore
|
|
73
12
|
*/
|
|
74
|
-
|
|
75
|
-
return historyState.canRedo;
|
|
76
|
-
}
|
|
13
|
+
import { HistoryService } from '../services/historyService.js';
|
|
77
14
|
// =========================================================================
|
|
78
|
-
//
|
|
15
|
+
// HistoryStore (per-instance reactive bindings)
|
|
79
16
|
// =========================================================================
|
|
80
17
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* Set this to handle the restored workflow state (e.g., update the workflow store)
|
|
84
|
-
*/
|
|
85
|
-
let onRestoreCallback = null;
|
|
86
|
-
/**
|
|
87
|
-
* Set the callback for restoring workflow state
|
|
18
|
+
* Reactive rune bindings around a {@link HistoryService}.
|
|
88
19
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param callback - Function to call with restored workflow
|
|
93
|
-
*/
|
|
94
|
-
export function setOnRestoreCallback(callback) {
|
|
95
|
-
onRestoreCallback = callback;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* History actions for undo/redo operations
|
|
99
|
-
*
|
|
100
|
-
* Use these functions to interact with the history service.
|
|
101
|
-
* They handle the coordination between history and workflow state.
|
|
20
|
+
* Subscribes to the service on construction; call {@link cleanup} when the
|
|
21
|
+
* owning instance is destroyed to release the subscription.
|
|
102
22
|
*/
|
|
103
|
-
export
|
|
23
|
+
export class HistoryStore {
|
|
24
|
+
/** Reactive snapshot of the history service state. */
|
|
25
|
+
#state = $state({
|
|
26
|
+
canUndo: false,
|
|
27
|
+
canRedo: false,
|
|
28
|
+
currentIndex: 0,
|
|
29
|
+
historyLength: 0,
|
|
30
|
+
isInTransaction: false
|
|
31
|
+
});
|
|
104
32
|
/**
|
|
105
|
-
*
|
|
33
|
+
* Callback for when workflow state is restored from history.
|
|
34
|
+
* Invoked when undo/redo operations return a workflow.
|
|
35
|
+
*/
|
|
36
|
+
#onRestore = null;
|
|
37
|
+
/**
|
|
38
|
+
* Callback run immediately before an undo/redo, to flush any pending edit
|
|
39
|
+
* session into a committed history step (see {@link setBeforeNavigateCallback}).
|
|
40
|
+
*/
|
|
41
|
+
#onBeforeNavigate = null;
|
|
42
|
+
/** Unsubscribe handle for the service subscription. */
|
|
43
|
+
#unsubscribe;
|
|
44
|
+
/** The underlying (non-reactive) history service. */
|
|
45
|
+
#service;
|
|
46
|
+
/** Bound action facade — see {@link HistoryStoreActions}. */
|
|
47
|
+
actions;
|
|
48
|
+
constructor(service) {
|
|
49
|
+
this.#service = service;
|
|
50
|
+
this.#unsubscribe = service.subscribe((state) => {
|
|
51
|
+
this.#state = state;
|
|
52
|
+
});
|
|
53
|
+
this.actions = Object.freeze({
|
|
54
|
+
initialize: this.initialize.bind(this),
|
|
55
|
+
pushState: this.pushState.bind(this),
|
|
56
|
+
undo: this.undo.bind(this),
|
|
57
|
+
redo: this.redo.bind(this),
|
|
58
|
+
startTransaction: this.startTransaction.bind(this),
|
|
59
|
+
commitTransaction: this.commitTransaction.bind(this),
|
|
60
|
+
cancelTransaction: this.cancelTransaction.bind(this),
|
|
61
|
+
clear: this.clear.bind(this),
|
|
62
|
+
canUndo: () => this.#service.canUndo(),
|
|
63
|
+
canRedo: () => this.#service.canRedo(),
|
|
64
|
+
getState: () => this.#state
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// -----------------------------------------------------------------------
|
|
68
|
+
// Reactive getters
|
|
69
|
+
// -----------------------------------------------------------------------
|
|
70
|
+
/**
|
|
71
|
+
* The current history state snapshot.
|
|
72
|
+
*
|
|
73
|
+
* Use this for binding to UI elements like undo/redo buttons.
|
|
106
74
|
*
|
|
107
|
-
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```svelte
|
|
77
|
+
* <script>
|
|
78
|
+
* const fd = getInstance();
|
|
79
|
+
* const state = $derived(fd.historyBindings.state);
|
|
80
|
+
* </script>
|
|
108
81
|
*
|
|
109
|
-
*
|
|
82
|
+
* <button disabled={!state.canUndo} onclick={fd.historyBindings.actions.undo}>
|
|
83
|
+
* Undo
|
|
84
|
+
* </button>
|
|
85
|
+
* ```
|
|
110
86
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
87
|
+
get state() {
|
|
88
|
+
return this.#state;
|
|
89
|
+
}
|
|
90
|
+
/** Whether undo is currently available (reactive). */
|
|
91
|
+
get canUndo() {
|
|
92
|
+
return this.#state.canUndo;
|
|
93
|
+
}
|
|
94
|
+
/** Whether redo is currently available (reactive). */
|
|
95
|
+
get canRedo() {
|
|
96
|
+
return this.#state.canRedo;
|
|
97
|
+
}
|
|
98
|
+
// -----------------------------------------------------------------------
|
|
99
|
+
// Wiring & lifecycle
|
|
100
|
+
// -----------------------------------------------------------------------
|
|
114
101
|
/**
|
|
115
|
-
*
|
|
102
|
+
* Set the callback for restoring workflow state.
|
|
116
103
|
*
|
|
117
|
-
*
|
|
104
|
+
* This callback is invoked when undo/redo operations return a workflow.
|
|
105
|
+
* Use this to update the workflow store or other state management.
|
|
106
|
+
*/
|
|
107
|
+
setOnRestoreCallback(callback) {
|
|
108
|
+
this.#onRestore = callback;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the callback run just before every undo/redo.
|
|
118
112
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
113
|
+
* Use this to finalize an in-progress edit session (e.g. the workflow store's
|
|
114
|
+
* `finalizeNodeConfig`) so it is committed as one history step *before* being
|
|
115
|
+
* undone. The history service intentionally does not commit dangling
|
|
116
|
+
* transactions itself — it has no access to the live state — so this hook is
|
|
117
|
+
* how the owner of that state flushes it first.
|
|
118
|
+
*/
|
|
119
|
+
setBeforeNavigateCallback(callback) {
|
|
120
|
+
this.#onBeforeNavigate = callback;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Release the history service subscription.
|
|
124
|
+
* Called by the owning instance's destroy(); safe to call repeatedly.
|
|
125
|
+
*/
|
|
126
|
+
cleanup() {
|
|
127
|
+
this.#unsubscribe();
|
|
128
|
+
}
|
|
129
|
+
// -----------------------------------------------------------------------
|
|
130
|
+
// Actions
|
|
131
|
+
// -----------------------------------------------------------------------
|
|
132
|
+
/** Initialize history with the current workflow (resets history). */
|
|
133
|
+
initialize(workflow) {
|
|
134
|
+
this.#service.initialize(workflow);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Push the current state to history before making changes.
|
|
138
|
+
*
|
|
139
|
+
* Call this BEFORE modifying the workflow to capture the "before" state.
|
|
121
140
|
*/
|
|
122
|
-
pushState
|
|
123
|
-
|
|
124
|
-
}
|
|
141
|
+
pushState(workflow, options) {
|
|
142
|
+
this.#service.push(workflow, options);
|
|
143
|
+
}
|
|
125
144
|
/**
|
|
126
|
-
* Undo the last change
|
|
145
|
+
* Undo the last change.
|
|
127
146
|
*
|
|
128
147
|
* Restores the previous workflow state and invokes the restore callback.
|
|
129
148
|
*
|
|
130
149
|
* @returns true if undo was successful, false if at beginning of history
|
|
131
150
|
*/
|
|
132
|
-
undo
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
151
|
+
undo() {
|
|
152
|
+
// Flush any pending edit session into a committed step first, so undo reverts
|
|
153
|
+
// exactly that step rather than skipping over an uncommitted edit.
|
|
154
|
+
this.#onBeforeNavigate?.();
|
|
155
|
+
const previousState = this.#service.undo();
|
|
156
|
+
if (previousState && this.#onRestore) {
|
|
157
|
+
this.#onRestore(previousState);
|
|
136
158
|
return true;
|
|
137
159
|
}
|
|
138
160
|
return previousState !== null;
|
|
139
|
-
}
|
|
161
|
+
}
|
|
140
162
|
/**
|
|
141
|
-
* Redo the last undone change
|
|
163
|
+
* Redo the last undone change.
|
|
142
164
|
*
|
|
143
165
|
* Restores the next workflow state and invokes the restore callback.
|
|
144
166
|
*
|
|
145
167
|
* @returns true if redo was successful, false if at end of history
|
|
146
168
|
*/
|
|
147
|
-
redo
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
169
|
+
redo() {
|
|
170
|
+
// A pending edit session invalidates the redo stack (it is a new change), so
|
|
171
|
+
// finalize it first; redo then correctly reports nothing to redo.
|
|
172
|
+
this.#onBeforeNavigate?.();
|
|
173
|
+
const nextState = this.#service.redo();
|
|
174
|
+
if (nextState && this.#onRestore) {
|
|
175
|
+
this.#onRestore(nextState);
|
|
151
176
|
return true;
|
|
152
177
|
}
|
|
153
178
|
return false;
|
|
154
|
-
}
|
|
179
|
+
}
|
|
155
180
|
/**
|
|
156
|
-
* Start a transaction for grouping multiple changes
|
|
181
|
+
* Start a transaction for grouping multiple changes.
|
|
157
182
|
*
|
|
158
183
|
* All changes during a transaction are combined into a single undo entry.
|
|
159
|
-
*
|
|
160
|
-
* @param workflow - The current workflow state (before changes)
|
|
161
|
-
* @param description - Description for the combined change
|
|
162
184
|
*/
|
|
163
|
-
startTransaction
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Commit the current transaction
|
|
168
|
-
*/
|
|
169
|
-
commitTransaction: () => {
|
|
170
|
-
historyService.commitTransaction();
|
|
171
|
-
},
|
|
172
|
-
/**
|
|
173
|
-
* Cancel the current transaction without committing
|
|
174
|
-
*/
|
|
175
|
-
cancelTransaction: () => {
|
|
176
|
-
historyService.cancelTransaction();
|
|
177
|
-
},
|
|
185
|
+
startTransaction(workflow, description) {
|
|
186
|
+
this.#service.startTransaction(workflow, description);
|
|
187
|
+
}
|
|
178
188
|
/**
|
|
179
|
-
*
|
|
189
|
+
* Commit the current transaction with its final (post-change) state.
|
|
180
190
|
*
|
|
181
|
-
* @param
|
|
182
|
-
*/
|
|
183
|
-
clear: (currentWorkflow) => {
|
|
184
|
-
historyService.clear(currentWorkflow);
|
|
185
|
-
},
|
|
186
|
-
/**
|
|
187
|
-
* Check if undo is available
|
|
188
|
-
*/
|
|
189
|
-
canUndo: () => {
|
|
190
|
-
return historyService.canUndo();
|
|
191
|
-
},
|
|
192
|
-
/**
|
|
193
|
-
* Check if redo is available
|
|
191
|
+
* @param finalWorkflow - The workflow state after the grouped change.
|
|
194
192
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
193
|
+
commitTransaction(finalWorkflow) {
|
|
194
|
+
this.#service.commitTransaction(finalWorkflow);
|
|
195
|
+
}
|
|
196
|
+
/** Cancel the current transaction without committing. */
|
|
197
|
+
cancelTransaction() {
|
|
198
|
+
this.#service.cancelTransaction();
|
|
199
|
+
}
|
|
198
200
|
/**
|
|
199
|
-
*
|
|
201
|
+
* Clear all history.
|
|
200
202
|
*
|
|
201
|
-
* @
|
|
203
|
+
* @param currentWorkflow - If provided, keeps this as the initial state
|
|
202
204
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
clear(currentWorkflow) {
|
|
206
|
+
this.#service.clear(currentWorkflow);
|
|
205
207
|
}
|
|
206
|
-
}
|
|
207
|
-
export { HistoryService, historyService } from '../services/historyService.js';
|
|
208
|
+
}
|