@flowdrop/flowdrop 2.9.0 → 2.10.1
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 +200 -0
- package/dist/commands/executor.js +52 -8
- package/dist/commands/types.d.ts +3 -0
- package/dist/components/App.svelte +8 -0
- package/dist/components/App.svelte.d.ts +6 -0
- package/dist/components/CanvasContextMenu.stories.svelte +63 -0
- package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
- package/dist/components/CanvasContextMenu.svelte +259 -0
- package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/CanvasController.svelte +24 -2
- package/dist/components/CanvasController.svelte.d.ts +16 -0
- package/dist/components/EdgeRefresher.svelte +1 -1
- package/dist/components/FlowDropZone.svelte +11 -7
- package/dist/components/FlowDropZone.svelte.d.ts +12 -0
- package/dist/components/PortCoordinateTracker.svelte +1 -1
- package/dist/components/UniversalNode.svelte +12 -13
- package/dist/components/WorkflowEditor.svelte +486 -149
- package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
- package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
- package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
- package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
- package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
- package/dist/components/nodes/CaptionNode.svelte +313 -0
- package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
- package/dist/components/nodes/NotesNode.svelte +6 -0
- package/dist/components/playground/ChatBubble.svelte +2 -0
- package/dist/components/playground/ChatInput.svelte +18 -34
- package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
- package/dist/components/playground/ControlPanel.svelte +27 -0
- package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -8
- package/dist/components/playground/InterfaceInputForm.svelte +74 -0
- package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
- package/dist/components/playground/LogRow.svelte +2 -0
- package/dist/components/playground/MessageCard.svelte +15 -3
- package/dist/components/playground/MessageNotice.svelte +2 -0
- package/dist/components/playground/MessageStream.svelte +87 -23
- package/dist/components/playground/OriginBadge.svelte +48 -0
- package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
- package/dist/components/playground/Playground.svelte +155 -38
- package/dist/components/playground/messageDisplay.d.ts +23 -1
- package/dist/components/playground/messageDisplay.js +49 -0
- package/dist/config/endpoints.d.ts +65 -0
- package/dist/config/endpoints.js +39 -0
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +2 -1
- package/dist/editor/contextMenu.d.ts +107 -0
- package/dist/editor/contextMenu.js +134 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messages/defaults.d.ts +63 -0
- package/dist/messages/defaults.js +59 -0
- package/dist/openapi/v1/openapi.yaml +356 -7
- package/dist/playground/commands/registry.js +4 -2
- package/dist/playground/index.d.ts +3 -2
- package/dist/playground/index.js +2 -1
- package/dist/registry/builtinNodeTypes.d.ts +1 -1
- package/dist/registry/builtinNodeTypes.js +1 -0
- package/dist/registry/builtinNodes.js +13 -0
- package/dist/registry/nodeComponentRegistry.d.ts +18 -0
- package/dist/registry/nodeComponentRegistry.js +14 -2
- package/dist/schemas/v1/workflow.schema.json +22 -1
- package/dist/services/historyService.d.ts +1 -1
- package/dist/services/historyService.js +2 -2
- package/dist/services/playgroundService.d.ts +35 -1
- package/dist/services/playgroundService.js +82 -36
- package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
- package/dist/stores/inlineEditStore.svelte.js +63 -0
- package/dist/stores/instanceContainer.svelte.d.ts +6 -0
- package/dist/stores/instanceContainer.svelte.js +2 -0
- package/dist/stores/playgroundStore.svelte.d.ts +59 -2
- package/dist/stores/playgroundStore.svelte.js +128 -2
- package/dist/styles/base.css +8 -0
- package/dist/styles/tokens.css +8 -0
- package/dist/svelte-app.d.ts +15 -0
- package/dist/svelte-app.js +6 -4
- package/dist/types/index.d.ts +34 -1
- package/dist/types/index.js +11 -0
- package/dist/types/playground.d.ts +90 -9
- package/dist/types/playground.js +12 -4
- package/dist/utils/captionText.d.ts +43 -0
- package/dist/utils/captionText.js +49 -0
- package/dist/utils/focus.d.ts +16 -0
- package/dist/utils/focus.js +40 -0
- package/dist/utils/nodeTypes.js +1 -0
- package/dist/utils/nodeWrapper.js +2 -0
- package/dist/utils/workflowInterface.d.ts +83 -1
- package/dist/utils/workflowInterface.js +192 -1
- package/package.json +2 -2
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
Background,
|
|
13
13
|
BackgroundVariant,
|
|
14
14
|
MiniMap,
|
|
15
|
-
SvelteFlowProvider,
|
|
16
15
|
type ColorMode
|
|
17
16
|
} from '@xyflow/svelte';
|
|
18
17
|
import '@xyflow/svelte/dist/style.css';
|
|
@@ -24,6 +23,19 @@
|
|
|
24
23
|
import type { WorkflowNode as WorkflowNodeType, Workflow, WorkflowEdge } from '../types/index.js';
|
|
25
24
|
import CanvasBanner from './CanvasBanner.svelte';
|
|
26
25
|
import CanvasController from './CanvasController.svelte';
|
|
26
|
+
import CanvasContextMenu from './CanvasContextMenu.svelte';
|
|
27
|
+
import {
|
|
28
|
+
resolveContextMenuEntries,
|
|
29
|
+
runContextMenuEntry,
|
|
30
|
+
type ContextMenuActions,
|
|
31
|
+
type ContextMenuContext,
|
|
32
|
+
type ContextMenuEntry,
|
|
33
|
+
type ContextMenuOptions,
|
|
34
|
+
type ContextMenuTarget
|
|
35
|
+
} from '../editor/contextMenu.js';
|
|
36
|
+
import type { NodeMetadata } from '../types/index.js';
|
|
37
|
+
import { resolveComponentName } from '../utils/nodeTypes.js';
|
|
38
|
+
import { decideInlineCommit } from '../utils/captionText.js';
|
|
27
39
|
import FlowDropZone from './FlowDropZone.svelte';
|
|
28
40
|
import EdgeRefresher from './EdgeRefresher.svelte';
|
|
29
41
|
import { tick, untrack, onMount } from 'svelte';
|
|
@@ -31,7 +43,7 @@
|
|
|
31
43
|
import type { AuthProvider } from '../types/auth.js';
|
|
32
44
|
import ConnectionLine from './ConnectionLine.svelte';
|
|
33
45
|
import FlowDropEdge from './FlowDropEdge.svelte';
|
|
34
|
-
import { m } from '../messages/index.js';
|
|
46
|
+
import { m, getMessages } from '../messages/index.js';
|
|
35
47
|
import { provideInstance } from '../stores/getInstance.svelte.js';
|
|
36
48
|
import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
|
|
37
49
|
import type { FlowDropGridVariant } from '../types/theme.js';
|
|
@@ -107,6 +119,12 @@
|
|
|
107
119
|
* @default true
|
|
108
120
|
*/
|
|
109
121
|
builtinEditors?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Customise the canvas context menu (right-click, Shift+F10, Menu key).
|
|
124
|
+
* `items` receives the built-in entries and returns the final list.
|
|
125
|
+
* The menu only opens in `'edit'` mode.
|
|
126
|
+
*/
|
|
127
|
+
contextMenu?: ContextMenuOptions;
|
|
110
128
|
}
|
|
111
129
|
|
|
112
130
|
let props: Props = $props();
|
|
@@ -117,6 +135,10 @@
|
|
|
117
135
|
// svelte-ignore state_referenced_locally
|
|
118
136
|
const fd = provideInstance(props.instance);
|
|
119
137
|
|
|
138
|
+
// Messages getter captured at init: `m()` reads Svelte context, which is only
|
|
139
|
+
// available during component initialisation, not inside event handlers.
|
|
140
|
+
const getMsgs = getMessages();
|
|
141
|
+
|
|
120
142
|
// Batteries-included: register the built-in heavy form editors (markdown /
|
|
121
143
|
// code / template) on this instance's field registry so node config fields
|
|
122
144
|
// render real editors out of the box. Dynamic import is deliberate — the
|
|
@@ -207,17 +229,23 @@
|
|
|
207
229
|
// ---------------------------------------------------------------------------
|
|
208
230
|
// Helper: derive flowNodes/flowEdges from a Workflow object
|
|
209
231
|
// ---------------------------------------------------------------------------
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
} {
|
|
214
|
-
const nodesWithCallbacks = workflow.nodes.map((node) => ({
|
|
232
|
+
/** Add the callbacks every node component can call: open config, commit an in-place edit. */
|
|
233
|
+
function withNodeCallbacks(node: WorkflowNodeType) {
|
|
234
|
+
return {
|
|
215
235
|
...node,
|
|
216
236
|
data: {
|
|
217
237
|
...node.data,
|
|
218
|
-
onConfigOpen: props.openConfigSidebar
|
|
238
|
+
onConfigOpen: props.openConfigSidebar,
|
|
239
|
+
onInlineCommit: handleInlineCommit
|
|
219
240
|
}
|
|
220
|
-
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function buildFlowNodesFromStore(workflow: Workflow): {
|
|
245
|
+
nodes: WorkflowNodeType[];
|
|
246
|
+
edges: WorkflowEdge[];
|
|
247
|
+
} {
|
|
248
|
+
const nodesWithCallbacks = workflow.nodes.map(withNodeCallbacks);
|
|
221
249
|
const styledEdges = EdgeStylingHelper.updateEdgeStyles(workflow.edges, nodesWithCallbacks);
|
|
222
250
|
return { nodes: nodesWithCallbacks, edges: styledEdges };
|
|
223
251
|
}
|
|
@@ -660,6 +688,58 @@
|
|
|
660
688
|
return WorkflowOperationsHelper.checkWorkflowCycles(flowNodes, flowEdges);
|
|
661
689
|
});
|
|
662
690
|
|
|
691
|
+
/**
|
|
692
|
+
* Create a node from node-type JSON at a flow position, append it to the
|
|
693
|
+
* canvas and the store, and record the "Add node" history entry. Shared by
|
|
694
|
+
* the sidebar drop and the context menu's `addNode` action.
|
|
695
|
+
*
|
|
696
|
+
* The node is on the canvas (and in the store) synchronously; `done`
|
|
697
|
+
* resolves once the history entry has been pushed.
|
|
698
|
+
*/
|
|
699
|
+
function placeNode(
|
|
700
|
+
nodeTypeData: string,
|
|
701
|
+
position: { x: number; y: number },
|
|
702
|
+
options: { history?: boolean; emptyLabel?: boolean } = {}
|
|
703
|
+
): { id: string | null; done: Promise<void> } {
|
|
704
|
+
const { history = true, emptyLabel = false } = options;
|
|
705
|
+
// The machine's `dropping` state is what holds the store -> canvas sync
|
|
706
|
+
// off while a node is added (see its permissions), so every placement
|
|
707
|
+
// goes through it, not only a sidebar drop.
|
|
708
|
+
machine.send('START_DROP');
|
|
709
|
+
|
|
710
|
+
const newNode = NodeOperationsHelper.createNodeFromDrop(nodeTypeData, position, flowNodes);
|
|
711
|
+
|
|
712
|
+
if (!newNode) {
|
|
713
|
+
logger.warn('Failed to create node from drop data');
|
|
714
|
+
machine.send('DROP_COMPLETE');
|
|
715
|
+
return { id: null, done: Promise.resolve() };
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// Add the node callbacks and append to flowNodes for immediate visual feedback
|
|
719
|
+
const nodeWithCallback = withNodeCallbacks(
|
|
720
|
+
emptyLabel ? { ...newNode, data: { ...newNode.data, label: '' } } : newNode
|
|
721
|
+
);
|
|
722
|
+
flowNodes = [...flowNodes, nodeWithCallback];
|
|
723
|
+
|
|
724
|
+
// Sync to store
|
|
725
|
+
syncFlowToStore();
|
|
726
|
+
|
|
727
|
+
const done = (async () => {
|
|
728
|
+
await tick();
|
|
729
|
+
|
|
730
|
+
if (history) {
|
|
731
|
+
const storeValue = fd.workflow.current;
|
|
732
|
+
if (storeValue) {
|
|
733
|
+
fd.workflow.pushHistory('Add node', storeValue);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
machine.send('DROP_COMPLETE');
|
|
738
|
+
})();
|
|
739
|
+
|
|
740
|
+
return { id: newNode.id, done };
|
|
741
|
+
}
|
|
742
|
+
|
|
663
743
|
/**
|
|
664
744
|
* Handle drop event and add new node to canvas
|
|
665
745
|
*/
|
|
@@ -667,34 +747,268 @@
|
|
|
667
747
|
nodeTypeData: string,
|
|
668
748
|
position: { x: number; y: number }
|
|
669
749
|
): Promise<void> {
|
|
670
|
-
|
|
750
|
+
await placeNode(nodeTypeData, position).done;
|
|
751
|
+
}
|
|
671
752
|
|
|
672
|
-
|
|
753
|
+
// ---------------------------------------------------------------------------
|
|
754
|
+
// Canvas context menu
|
|
755
|
+
// ---------------------------------------------------------------------------
|
|
673
756
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
757
|
+
interface OpenContextMenu {
|
|
758
|
+
ctx: ContextMenuContext;
|
|
759
|
+
entries: ContextMenuEntry[];
|
|
760
|
+
/** Viewport (client) position; the menu is in the top layer. */
|
|
761
|
+
x: number;
|
|
762
|
+
y: number;
|
|
763
|
+
}
|
|
681
764
|
|
|
682
|
-
|
|
683
|
-
|
|
765
|
+
let openMenu = $state.raw<OpenContextMenu | null>(null);
|
|
766
|
+
let canvasEl: HTMLDivElement | undefined = $state();
|
|
684
767
|
|
|
685
|
-
|
|
768
|
+
/** Whether a node's registered component edits its text in place (the caption). */
|
|
769
|
+
function nodeEditsInPlace(node: WorkflowNodeType): boolean {
|
|
770
|
+
return (
|
|
771
|
+
!!node.data.metadata &&
|
|
772
|
+
fd.nodes.editsInPlace(
|
|
773
|
+
resolveComponentName(fd.nodes, node.data.metadata, node.data.config?.nodeType as string)
|
|
774
|
+
)
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Ids of in-place nodes that were just added and have no history entry yet.
|
|
780
|
+
* Their first save pushes "Add caption"; cancelling or leaving them empty
|
|
781
|
+
* removes them without a trace.
|
|
782
|
+
*/
|
|
783
|
+
const pendingNewIds = new Set<string>();
|
|
784
|
+
|
|
785
|
+
/** Remove a node and its edges from the canvas and the store, without a history entry. */
|
|
786
|
+
function removeNode(id: string): void {
|
|
787
|
+
flowNodes = flowNodes.filter((n) => n.id !== id);
|
|
788
|
+
flowEdges = flowEdges.filter((e) => e.source !== id && e.target !== id);
|
|
789
|
+
syncFlowToStore();
|
|
790
|
+
}
|
|
686
791
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
792
|
+
/**
|
|
793
|
+
* An in-place edit ended (see CaptionNode): `text` is what was typed, or
|
|
794
|
+
* null when the user cancelled. `decideInlineCommit` holds the rules and
|
|
795
|
+
* cleans the text.
|
|
796
|
+
*/
|
|
797
|
+
function handleInlineCommit(id: string, text: string | null): void {
|
|
798
|
+
const node = flowNodes.find((n) => n.id === id);
|
|
799
|
+
const isNew = pendingNewIds.delete(id);
|
|
800
|
+
if (!node || !canvasEditable) {
|
|
801
|
+
// Gone (undo, workflow switch) or no longer editable: a pending node must not linger.
|
|
802
|
+
if (node && isNew) removeNode(id);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const { outcome, label } = decideInlineCommit(text, node.data.label ?? '', isNew);
|
|
807
|
+
if (outcome === 'none') return;
|
|
808
|
+
|
|
809
|
+
if (outcome === 'remove') {
|
|
810
|
+
removeNode(id);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
flowNodes = flowNodes.map((n) => (n.id === id ? { ...n, data: { ...n.data, label } } : n));
|
|
815
|
+
syncFlowToStore();
|
|
816
|
+
const storeValue = fd.workflow.current;
|
|
817
|
+
if (storeValue) {
|
|
818
|
+
fd.workflow.pushHistory(outcome === 'add' ? 'Add caption' : 'Edit caption', storeValue);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const contextMenuActions: ContextMenuActions = {
|
|
823
|
+
addNode(metadata: NodeMetadata, position, options) {
|
|
824
|
+
const editsHere =
|
|
825
|
+
options?.edit === true && fd.nodes.editsInPlace(resolveComponentName(fd.nodes, metadata));
|
|
826
|
+
if (!editsHere) return placeNode(JSON.stringify(metadata), position).id;
|
|
827
|
+
|
|
828
|
+
// New in-place node: empty text, no history entry until the first save.
|
|
829
|
+
const { id } = placeNode(JSON.stringify(metadata), position, {
|
|
830
|
+
history: false,
|
|
831
|
+
emptyLabel: true
|
|
832
|
+
});
|
|
833
|
+
if (id) {
|
|
834
|
+
pendingNewIds.add(id);
|
|
835
|
+
fd.inlineEdit.request(id);
|
|
690
836
|
}
|
|
691
|
-
|
|
692
|
-
|
|
837
|
+
return id;
|
|
838
|
+
},
|
|
839
|
+
async deleteNodes(ids) {
|
|
840
|
+
if (ids.length === 0) return;
|
|
841
|
+
// Through xyflow so confirm-delete, edge removal and history all apply.
|
|
842
|
+
await canvasControllerRef?.canvasDeleteNodes(ids);
|
|
843
|
+
},
|
|
844
|
+
openConfig(id) {
|
|
845
|
+
const node = flowNodes.find((n) => n.id === id);
|
|
846
|
+
if (!node || !props.openConfigSidebar) return;
|
|
847
|
+
// Same node shape UniversalNode's Enter key passes.
|
|
848
|
+
props.openConfigSidebar({
|
|
849
|
+
id,
|
|
850
|
+
type: node.data.metadata?.type ?? 'default',
|
|
851
|
+
data: node.data
|
|
852
|
+
} as WorkflowNodeType);
|
|
853
|
+
},
|
|
854
|
+
editInPlace(id) {
|
|
855
|
+
fd.inlineEdit.request(id);
|
|
693
856
|
}
|
|
857
|
+
};
|
|
694
858
|
|
|
695
|
-
|
|
859
|
+
/**
|
|
860
|
+
* Snap a flow position to the grid cell it falls in (floor, not round), so
|
|
861
|
+
* a node added from the menu has its top-left on the cell that was clicked.
|
|
862
|
+
*/
|
|
863
|
+
function snapPosition(position: { x: number; y: number }): { x: number; y: number } {
|
|
864
|
+
const settings = getEditorSettings();
|
|
865
|
+
if (!settings.snapToGrid) return position;
|
|
866
|
+
const grid = settings.gridSize;
|
|
867
|
+
return { x: Math.floor(position.x / grid) * grid, y: Math.floor(position.y / grid) * grid };
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function closeContextMenu(): void {
|
|
871
|
+
openMenu = null;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/** Run a menu entry. The menu closes first: running may open another one. */
|
|
875
|
+
function selectContextMenuEntry(entry: ContextMenuEntry): void {
|
|
876
|
+
const menu = openMenu;
|
|
877
|
+
if (!menu) return;
|
|
878
|
+
openMenu = null;
|
|
879
|
+
runContextMenuEntry(entry, menu.ctx);
|
|
696
880
|
}
|
|
697
881
|
|
|
882
|
+
/**
|
|
883
|
+
* Open the menu for a target at a viewport (client) point. Returns false
|
|
884
|
+
* when there is nothing to show, so the caller leaves the browser's own
|
|
885
|
+
* menu alone.
|
|
886
|
+
*/
|
|
887
|
+
function showContextMenu(
|
|
888
|
+
target: ContextMenuTarget,
|
|
889
|
+
nodes: WorkflowNodeType[],
|
|
890
|
+
clientX: number,
|
|
891
|
+
clientY: number
|
|
892
|
+
): boolean {
|
|
893
|
+
if (!canvasEditable || !canvasControllerRef) return false;
|
|
894
|
+
|
|
895
|
+
const ctx: ContextMenuContext = {
|
|
896
|
+
target,
|
|
897
|
+
nodes,
|
|
898
|
+
position: snapPosition(canvasControllerRef.canvasScreenToFlow({ x: clientX, y: clientY })),
|
|
899
|
+
nodeTypes: fd.nodeTypes.current,
|
|
900
|
+
actions: contextMenuActions
|
|
901
|
+
};
|
|
902
|
+
const entries = resolveContextMenuEntries(ctx, props.contextMenu, getMsgs().contextMenu, {
|
|
903
|
+
editsInPlace: nodeEditsInPlace
|
|
904
|
+
});
|
|
905
|
+
if (entries.length === 0) {
|
|
906
|
+
openMenu = null;
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
openMenu = { ctx, entries, x: clientX, y: clientY };
|
|
911
|
+
return true;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/** Right-click or keyboard on a node: select it alone first, unless it is part of a multi-selection. */
|
|
915
|
+
function openNodeMenu(nodeId: string, clientX: number, clientY: number): void {
|
|
916
|
+
const node = flowNodes.find((n) => n.id === nodeId);
|
|
917
|
+
if (!node) return;
|
|
918
|
+
|
|
919
|
+
const selected = flowNodes.filter((n) => n.selected);
|
|
920
|
+
if (node.selected && selected.length > 1) {
|
|
921
|
+
showContextMenu('selection', selected, clientX, clientY);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
if (!node.selected || selected.length > 1) {
|
|
926
|
+
flowNodes = flowNodes.map((n) =>
|
|
927
|
+
n.selected === (n.id === nodeId) ? n : { ...n, selected: n.id === nodeId }
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
showContextMenu('node', [flowNodes.find((n) => n.id === nodeId) ?? node], clientX, clientY);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
function handleNodeContextMenu({
|
|
934
|
+
event,
|
|
935
|
+
node
|
|
936
|
+
}: {
|
|
937
|
+
event: MouseEvent;
|
|
938
|
+
node: WorkflowNodeType;
|
|
939
|
+
}): void {
|
|
940
|
+
if (!canvasEditable) return;
|
|
941
|
+
event.preventDefault();
|
|
942
|
+
openNodeMenu(node.id, event.clientX, event.clientY);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function handleSelectionContextMenu({
|
|
946
|
+
event,
|
|
947
|
+
nodes
|
|
948
|
+
}: {
|
|
949
|
+
event: MouseEvent;
|
|
950
|
+
nodes: WorkflowNodeType[];
|
|
951
|
+
}): void {
|
|
952
|
+
if (!canvasEditable) return;
|
|
953
|
+
event.preventDefault();
|
|
954
|
+
showContextMenu(
|
|
955
|
+
nodes.length > 1 ? 'selection' : 'node',
|
|
956
|
+
nodes.map((n) => flowNodes.find((f) => f.id === n.id) ?? n),
|
|
957
|
+
event.clientX,
|
|
958
|
+
event.clientY
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function handlePaneContextMenu({ event }: { event: MouseEvent }): void {
|
|
963
|
+
if (!canvasEditable) return;
|
|
964
|
+
// Only take over the right-click when the pane menu has entries.
|
|
965
|
+
if (showContextMenu('pane', [], event.clientX, event.clientY)) event.preventDefault();
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Shift+F10 / the Menu key: on a focused node wrapper open that node's menu
|
|
970
|
+
* anchored at the node; elsewhere in the canvas open the pane menu at the
|
|
971
|
+
* viewport centre. Returns true when the key was handled.
|
|
972
|
+
*/
|
|
973
|
+
function handleMenuKey(event: KeyboardEvent, target: HTMLElement): boolean {
|
|
974
|
+
const isMenuKey = event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey);
|
|
975
|
+
if (!isMenuKey || !canvasEditable) return false;
|
|
976
|
+
if (!target.closest('.flowdrop-canvas') || target.closest('.canvas-context-menu')) return false;
|
|
977
|
+
|
|
978
|
+
event.preventDefault();
|
|
979
|
+
|
|
980
|
+
const wrapper = target.classList.contains('svelte-flow__node') ? target : null;
|
|
981
|
+
const nodeId = wrapper?.dataset.id;
|
|
982
|
+
if (wrapper && nodeId) {
|
|
983
|
+
const rect = wrapper.getBoundingClientRect();
|
|
984
|
+
openNodeMenu(nodeId, rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
985
|
+
return true;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const flowEl = canvasEl?.querySelector('.svelte-flow') ?? canvasEl;
|
|
989
|
+
if (flowEl) {
|
|
990
|
+
const rect = flowEl.getBoundingClientRect();
|
|
991
|
+
showContextMenu('pane', [], rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
992
|
+
}
|
|
993
|
+
return true;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// Menus never outlive edit mode or the workflow they were opened on.
|
|
997
|
+
$effect(() => {
|
|
998
|
+
if (!canvasEditable) openMenu = null;
|
|
999
|
+
});
|
|
1000
|
+
$effect(() => {
|
|
1001
|
+
void svelteFlowKey;
|
|
1002
|
+
openMenu = null;
|
|
1003
|
+
pendingNewIds.clear();
|
|
1004
|
+
fd.inlineEdit.clear();
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
// In-place editing follows edit mode.
|
|
1008
|
+
$effect(() => {
|
|
1009
|
+
fd.inlineEdit.setEditable(canvasEditable);
|
|
1010
|
+
});
|
|
1011
|
+
|
|
698
1012
|
/**
|
|
699
1013
|
* Handle a workflow JSON file dropped directly onto the canvas.
|
|
700
1014
|
*
|
|
@@ -736,7 +1050,8 @@
|
|
|
736
1050
|
*/
|
|
737
1051
|
let nodeIdToRefresh = $state<string | null>(null);
|
|
738
1052
|
|
|
739
|
-
// Canvas viewport controller ref
|
|
1053
|
+
// Canvas viewport controller ref. Rendered inside <SvelteFlow>, so it is
|
|
1054
|
+
// remounted with the canvas and always talks to the live instance's store.
|
|
740
1055
|
let canvasControllerRef: CanvasController | undefined = $state();
|
|
741
1056
|
|
|
742
1057
|
/**
|
|
@@ -784,7 +1099,7 @@
|
|
|
784
1099
|
nodeIdToRefresh = nodeId;
|
|
785
1100
|
}
|
|
786
1101
|
|
|
787
|
-
// Canvas viewport methods (forwarded to CanvasController inside
|
|
1102
|
+
// Canvas viewport methods (forwarded to CanvasController inside <SvelteFlow>)
|
|
788
1103
|
|
|
789
1104
|
export function canvasFitView(): void {
|
|
790
1105
|
canvasControllerRef?.canvasFitView();
|
|
@@ -841,6 +1156,11 @@
|
|
|
841
1156
|
return;
|
|
842
1157
|
}
|
|
843
1158
|
|
|
1159
|
+
// Shift+F10 / Menu key: open the canvas context menu.
|
|
1160
|
+
if (handleMenuKey(event, target)) {
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
844
1164
|
// Backspace/Delete on a canvas element: let SvelteFlow handle the
|
|
845
1165
|
// deletion, but block the browser default (WebKit navigates back).
|
|
846
1166
|
if ((event.key === 'Backspace' || event.key === 'Delete') && target.closest('.svelte-flow')) {
|
|
@@ -873,135 +1193,152 @@
|
|
|
873
1193
|
|
|
874
1194
|
<svelte:window onkeydown={handleKeydown} />
|
|
875
1195
|
|
|
876
|
-
<
|
|
877
|
-
<!--
|
|
878
|
-
<
|
|
879
|
-
|
|
880
|
-
<!-- EdgeRefresher component - handles updateNodeInternals calls -->
|
|
881
|
-
<EdgeRefresher {nodeIdToRefresh} onRefreshComplete={handleEdgeRefreshComplete} />
|
|
882
|
-
|
|
883
|
-
<!-- Port Coordinate Tracker - maintains port positions for proximity connect -->
|
|
884
|
-
<PortCoordinateTracker
|
|
885
|
-
nodeToUpdate={portCoordNodeToUpdate}
|
|
886
|
-
rebuildTrigger={portCoordRebuildTrigger}
|
|
887
|
-
nodes={flowNodes}
|
|
888
|
-
/>
|
|
889
|
-
|
|
890
|
-
<div class="flowdrop-workflow-editor">
|
|
891
|
-
<!-- Main Editor Area -->
|
|
892
|
-
<div class="flowdrop-workflow-editor__main">
|
|
893
|
-
<!-- Flow Canvas.
|
|
1196
|
+
<div class="flowdrop-workflow-editor">
|
|
1197
|
+
<!-- Main Editor Area -->
|
|
1198
|
+
<div class="flowdrop-workflow-editor__main">
|
|
1199
|
+
<!-- Flow Canvas.
|
|
894
1200
|
Capture-phase mousedown so dragging from a port never turns into a
|
|
895
1201
|
WebKit text-selection drag — see suppressPortDragSelection. -->
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1202
|
+
<div
|
|
1203
|
+
class="flowdrop-canvas"
|
|
1204
|
+
bind:this={canvasEl}
|
|
1205
|
+
onmousedowncapture={suppressPortDragSelection}
|
|
1206
|
+
>
|
|
1207
|
+
<FlowDropZone
|
|
1208
|
+
ondrop={handleNodeDrop}
|
|
1209
|
+
onfiledrop={handleWorkflowFileDrop}
|
|
1210
|
+
toFlowPosition={(point) => canvasControllerRef?.canvasScreenToFlow(point) ?? null}
|
|
1211
|
+
>
|
|
1212
|
+
{#key svelteFlowKey}
|
|
1213
|
+
<SvelteFlow
|
|
1214
|
+
id={fd.id}
|
|
1215
|
+
bind:nodes={flowNodes}
|
|
1216
|
+
bind:edges={flowEdges}
|
|
1217
|
+
{nodeTypes}
|
|
1218
|
+
{edgeTypes}
|
|
1219
|
+
{defaultEdgeOptions}
|
|
1220
|
+
onconnect={() => void handleConnect()}
|
|
1221
|
+
onbeforedelete={handleBeforeDelete}
|
|
1222
|
+
ondelete={handleNodesDelete}
|
|
1223
|
+
onnodedragstart={handleNodeDragStart}
|
|
1224
|
+
onnodedrag={handleNodeDrag}
|
|
1225
|
+
onnodedragstop={handleNodeDragStop}
|
|
1226
|
+
onnodecontextmenu={handleNodeContextMenu}
|
|
1227
|
+
onselectioncontextmenu={handleSelectionContextMenu}
|
|
1228
|
+
onpanecontextmenu={handlePaneContextMenu}
|
|
1229
|
+
minZoom={0.2}
|
|
1230
|
+
maxZoom={3}
|
|
1231
|
+
clickConnect={true}
|
|
1232
|
+
elevateEdgesOnSelect={true}
|
|
1233
|
+
connectionLineType={ConnectionLineType.Bezier}
|
|
1234
|
+
connectionLineComponent={ConnectionLine}
|
|
1235
|
+
{snapGrid}
|
|
1236
|
+
{initialViewport}
|
|
1237
|
+
colorMode={getResolvedTheme() as ColorMode}
|
|
1238
|
+
fitView={getEditorSettings().fitViewOnLoad}
|
|
1239
|
+
nodesDraggable={canvasEditable}
|
|
1240
|
+
nodesConnectable={canvasEditable}
|
|
1241
|
+
elementsSelectable={canvasEditable}
|
|
1242
|
+
>
|
|
1243
|
+
<!-- Renderless helpers. They live inside <SvelteFlow>, not beside it
|
|
1244
|
+
under a provider: @xyflow/svelte >= 1.6.6 replaces the provider's
|
|
1245
|
+
store with an empty one when a SvelteFlow is destroyed, so after
|
|
1246
|
+
the {#key} remount a helper outside would act on that empty
|
|
1247
|
+
store (context-menu Delete silently did nothing). -->
|
|
1248
|
+
<CanvasController bind:this={canvasControllerRef} />
|
|
1249
|
+
<EdgeRefresher {nodeIdToRefresh} onRefreshComplete={handleEdgeRefreshComplete} />
|
|
1250
|
+
<PortCoordinateTracker
|
|
1251
|
+
nodeToUpdate={portCoordNodeToUpdate}
|
|
1252
|
+
rebuildTrigger={portCoordRebuildTrigger}
|
|
1253
|
+
nodes={flowNodes}
|
|
1254
|
+
/>
|
|
1255
|
+
<Controls />
|
|
1256
|
+
{#if canvasEditable && props.onToggleConsole}
|
|
1257
|
+
<CanvasIconButton
|
|
1258
|
+
class="flowdrop-console-toggle"
|
|
1259
|
+
label={props.consoleToggleLabel ?? m().layout.commandConsole}
|
|
1260
|
+
active={props.consoleOpen}
|
|
1261
|
+
onclick={props.onToggleConsole}
|
|
1262
|
+
>
|
|
1263
|
+
{#snippet icon()}
|
|
1264
|
+
<CommandLineIcon />
|
|
1265
|
+
{/snippet}
|
|
1266
|
+
</CanvasIconButton>
|
|
1267
|
+
{/if}
|
|
1268
|
+
<!-- Always render Background for consistent bg color in dark/light mode -->
|
|
1269
|
+
<Background
|
|
1270
|
+
gap={getEditorSettings().gridSize}
|
|
1271
|
+
bgColor="var(--fd-canvas-bg)"
|
|
1272
|
+
variant={gridVariant}
|
|
1273
|
+
lineWidth={1}
|
|
1274
|
+
patternColor={getEditorSettings().showGrid
|
|
1275
|
+
? 'var(--fd-grid-pattern-color)'
|
|
1276
|
+
: 'transparent'}
|
|
1277
|
+
/>
|
|
1278
|
+
{#if getEditorSettings().showMinimap}
|
|
1279
|
+
<MiniMap />
|
|
1280
|
+
{/if}
|
|
1281
|
+
</SvelteFlow>
|
|
1282
|
+
{/key}
|
|
1283
|
+
<!-- Drop Zone Indicator -->
|
|
1284
|
+
{#if flowNodes.length === 0}
|
|
1285
|
+
<CanvasBanner
|
|
1286
|
+
title="Drag components here to start building"
|
|
1287
|
+
description="Use the sidebar to add components to your workflow"
|
|
1288
|
+
>
|
|
1289
|
+
{#snippet icon()}
|
|
1290
|
+
<svg
|
|
1291
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
1292
|
+
width="1em"
|
|
1293
|
+
height="1em"
|
|
1294
|
+
viewBox="0 0 24 24"
|
|
1295
|
+
fill="none"
|
|
1296
|
+
stroke="currentColor"
|
|
1297
|
+
stroke-width="1.5"
|
|
1298
|
+
stroke-linecap="round"
|
|
1299
|
+
stroke-linejoin="round"
|
|
1300
|
+
>
|
|
1301
|
+
<circle cx="18" cy="5" r="3" />
|
|
1302
|
+
<circle cx="6" cy="12" r="3" />
|
|
1303
|
+
<circle cx="18" cy="19" r="3" />
|
|
1304
|
+
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49" />
|
|
1305
|
+
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49" />
|
|
1306
|
+
</svg>
|
|
1307
|
+
{/snippet}
|
|
1308
|
+
</CanvasBanner>
|
|
1309
|
+
{/if}
|
|
1310
|
+
</FlowDropZone>
|
|
1311
|
+
|
|
1312
|
+
{#if openMenu}
|
|
1313
|
+
<CanvasContextMenu
|
|
1314
|
+
entries={openMenu.entries}
|
|
1315
|
+
x={openMenu.x}
|
|
1316
|
+
y={openMenu.y}
|
|
1317
|
+
onselect={selectContextMenuEntry}
|
|
1318
|
+
onclose={closeContextMenu}
|
|
1319
|
+
/>
|
|
1320
|
+
{/if}
|
|
1321
|
+
</div>
|
|
983
1322
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1323
|
+
<!-- Status Bar: aria-live announces dynamic changes (node/edge counts, cycle warnings) -->
|
|
1324
|
+
<div class="flowdrop-status-bar" aria-live="polite" aria-atomic="true">
|
|
1325
|
+
<div class="flowdrop-status-bar__content">
|
|
1326
|
+
<div class="flowdrop-flex flowdrop-gap--4">
|
|
1327
|
+
<span class="flowdrop-text--xs flowdrop-text--gray">{flowNodes.length} nodes</span>
|
|
1328
|
+
<span class="flowdrop-text--xs flowdrop-text--gray">•</span>
|
|
1329
|
+
<span class="flowdrop-text--xs flowdrop-text--gray">{flowEdges.length} connections</span>
|
|
1330
|
+
|
|
1331
|
+
{#if hasCycles}
|
|
989
1332
|
<span class="flowdrop-text--xs flowdrop-text--gray">•</span>
|
|
990
|
-
<span class="flowdrop-text--xs flowdrop-text--
|
|
1333
|
+
<span class="flowdrop-text--xs flowdrop-font--medium flowdrop-text--error"
|
|
1334
|
+
>⚠️ Cycles detected</span
|
|
991
1335
|
>
|
|
992
|
-
|
|
993
|
-
{#if hasCycles}
|
|
994
|
-
<span class="flowdrop-text--xs flowdrop-text--gray">•</span>
|
|
995
|
-
<span class="flowdrop-text--xs flowdrop-font--medium flowdrop-text--error"
|
|
996
|
-
>⚠️ Cycles detected</span
|
|
997
|
-
>
|
|
998
|
-
{/if}
|
|
999
|
-
</div>
|
|
1336
|
+
{/if}
|
|
1000
1337
|
</div>
|
|
1001
1338
|
</div>
|
|
1002
1339
|
</div>
|
|
1003
1340
|
</div>
|
|
1004
|
-
</
|
|
1341
|
+
</div>
|
|
1005
1342
|
|
|
1006
1343
|
<!-- Toast notifications container -->
|
|
1007
1344
|
<!-- aria-live="polite" ensures screen readers announce toast messages without interrupting -->
|