@flowdrop/flowdrop 2.8.0 → 2.10.0

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/dist/commands/executor.js +52 -8
  3. package/dist/commands/types.d.ts +3 -0
  4. package/dist/components/App.svelte +8 -0
  5. package/dist/components/App.svelte.d.ts +6 -0
  6. package/dist/components/CanvasContextMenu.stories.svelte +63 -0
  7. package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
  8. package/dist/components/CanvasContextMenu.svelte +259 -0
  9. package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
  10. package/dist/components/CanvasController.svelte +23 -1
  11. package/dist/components/CanvasController.svelte.d.ts +16 -0
  12. package/dist/components/UniversalNode.svelte +12 -13
  13. package/dist/components/WorkflowEditor.svelte +364 -27
  14. package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
  15. package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
  16. package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
  17. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
  18. package/dist/components/form/FieldFactory.svelte +478 -0
  19. package/dist/components/form/FieldFactory.svelte.d.ts +14 -0
  20. package/dist/components/form/FormField.svelte +19 -404
  21. package/dist/components/form/FormField.svelte.d.ts +2 -27
  22. package/dist/components/form/FormFieldLight.svelte +11 -424
  23. package/dist/components/form/FormFieldLight.svelte.d.ts +2 -28
  24. package/dist/components/form/FormMarkdownEditor.svelte +11 -4
  25. package/dist/components/form/FormTemplateEditor.svelte +12 -5
  26. package/dist/components/form/resolveFieldType.d.ts +18 -15
  27. package/dist/components/form/resolveFieldType.js +33 -12
  28. package/dist/components/form/types.d.ts +14 -2
  29. package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
  30. package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
  31. package/dist/components/nodes/CaptionNode.svelte +313 -0
  32. package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
  33. package/dist/components/nodes/NotesNode.svelte +6 -0
  34. package/dist/components/playground/ChatBubble.svelte +2 -0
  35. package/dist/components/playground/ChatInput.svelte +18 -34
  36. package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
  37. package/dist/components/playground/ControlPanel.svelte +27 -0
  38. package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
  39. package/dist/components/playground/ExecutionLogs.svelte +11 -8
  40. package/dist/components/playground/InterfaceInputForm.svelte +74 -0
  41. package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
  42. package/dist/components/playground/LogRow.svelte +2 -0
  43. package/dist/components/playground/MessageCard.svelte +15 -3
  44. package/dist/components/playground/MessageNotice.svelte +2 -0
  45. package/dist/components/playground/MessageStream.svelte +87 -23
  46. package/dist/components/playground/OriginBadge.svelte +48 -0
  47. package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
  48. package/dist/components/playground/Playground.svelte +155 -38
  49. package/dist/components/playground/messageDisplay.d.ts +23 -1
  50. package/dist/components/playground/messageDisplay.js +49 -0
  51. package/dist/config/endpoints.d.ts +65 -0
  52. package/dist/config/endpoints.js +39 -0
  53. package/dist/core/index.d.ts +6 -3
  54. package/dist/core/index.js +2 -1
  55. package/dist/editor/contextMenu.d.ts +107 -0
  56. package/dist/editor/contextMenu.js +134 -0
  57. package/dist/editor/index.d.ts +2 -0
  58. package/dist/editor/index.js +1 -0
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.js +1 -1
  61. package/dist/messages/defaults.d.ts +63 -0
  62. package/dist/messages/defaults.js +59 -0
  63. package/dist/openapi/v1/openapi.yaml +356 -7
  64. package/dist/playground/commands/registry.js +4 -2
  65. package/dist/playground/index.d.ts +3 -2
  66. package/dist/playground/index.js +2 -1
  67. package/dist/registry/builtinNodeTypes.d.ts +1 -1
  68. package/dist/registry/builtinNodeTypes.js +1 -0
  69. package/dist/registry/builtinNodes.js +13 -0
  70. package/dist/registry/nodeComponentRegistry.d.ts +18 -0
  71. package/dist/registry/nodeComponentRegistry.js +14 -2
  72. package/dist/schemas/v1/workflow.schema.json +22 -1
  73. package/dist/services/historyService.d.ts +1 -1
  74. package/dist/services/historyService.js +2 -2
  75. package/dist/services/playgroundService.d.ts +35 -1
  76. package/dist/services/playgroundService.js +82 -36
  77. package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
  78. package/dist/stores/inlineEditStore.svelte.js +63 -0
  79. package/dist/stores/instanceContainer.svelte.d.ts +6 -0
  80. package/dist/stores/instanceContainer.svelte.js +2 -0
  81. package/dist/stores/playgroundStore.svelte.d.ts +59 -2
  82. package/dist/stores/playgroundStore.svelte.js +128 -2
  83. package/dist/styles/base.css +8 -0
  84. package/dist/styles/tokens.css +8 -0
  85. package/dist/svelte-app.d.ts +15 -0
  86. package/dist/svelte-app.js +6 -4
  87. package/dist/types/index.d.ts +34 -1
  88. package/dist/types/index.js +11 -0
  89. package/dist/types/playground.d.ts +90 -9
  90. package/dist/types/playground.js +12 -4
  91. package/dist/utils/captionText.d.ts +43 -0
  92. package/dist/utils/captionText.js +49 -0
  93. package/dist/utils/focus.d.ts +16 -0
  94. package/dist/utils/focus.js +40 -0
  95. package/dist/utils/nodeTypes.js +1 -0
  96. package/dist/utils/nodeWrapper.js +2 -0
  97. package/dist/utils/workflowInterface.d.ts +83 -1
  98. package/dist/utils/workflowInterface.js +192 -1
  99. package/package.json +1 -1
@@ -24,6 +24,19 @@
24
24
  import type { WorkflowNode as WorkflowNodeType, Workflow, WorkflowEdge } from '../types/index.js';
25
25
  import CanvasBanner from './CanvasBanner.svelte';
26
26
  import CanvasController from './CanvasController.svelte';
27
+ import CanvasContextMenu from './CanvasContextMenu.svelte';
28
+ import {
29
+ resolveContextMenuEntries,
30
+ runContextMenuEntry,
31
+ type ContextMenuActions,
32
+ type ContextMenuContext,
33
+ type ContextMenuEntry,
34
+ type ContextMenuOptions,
35
+ type ContextMenuTarget
36
+ } from '../editor/contextMenu.js';
37
+ import type { NodeMetadata } from '../types/index.js';
38
+ import { resolveComponentName } from '../utils/nodeTypes.js';
39
+ import { decideInlineCommit } from '../utils/captionText.js';
27
40
  import FlowDropZone from './FlowDropZone.svelte';
28
41
  import EdgeRefresher from './EdgeRefresher.svelte';
29
42
  import { tick, untrack, onMount } from 'svelte';
@@ -31,7 +44,7 @@
31
44
  import type { AuthProvider } from '../types/auth.js';
32
45
  import ConnectionLine from './ConnectionLine.svelte';
33
46
  import FlowDropEdge from './FlowDropEdge.svelte';
34
- import { m } from '../messages/index.js';
47
+ import { m, getMessages } from '../messages/index.js';
35
48
  import { provideInstance } from '../stores/getInstance.svelte.js';
36
49
  import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
37
50
  import type { FlowDropGridVariant } from '../types/theme.js';
@@ -107,6 +120,12 @@
107
120
  * @default true
108
121
  */
109
122
  builtinEditors?: boolean;
123
+ /**
124
+ * Customise the canvas context menu (right-click, Shift+F10, Menu key).
125
+ * `items` receives the built-in entries and returns the final list.
126
+ * The menu only opens in `'edit'` mode.
127
+ */
128
+ contextMenu?: ContextMenuOptions;
110
129
  }
111
130
 
112
131
  let props: Props = $props();
@@ -117,6 +136,10 @@
117
136
  // svelte-ignore state_referenced_locally
118
137
  const fd = provideInstance(props.instance);
119
138
 
139
+ // Messages getter captured at init: `m()` reads Svelte context, which is only
140
+ // available during component initialisation, not inside event handlers.
141
+ const getMsgs = getMessages();
142
+
120
143
  // Batteries-included: register the built-in heavy form editors (markdown /
121
144
  // code / template) on this instance's field registry so node config fields
122
145
  // render real editors out of the box. Dynamic import is deliberate — the
@@ -207,17 +230,23 @@
207
230
  // ---------------------------------------------------------------------------
208
231
  // Helper: derive flowNodes/flowEdges from a Workflow object
209
232
  // ---------------------------------------------------------------------------
210
- function buildFlowNodesFromStore(workflow: Workflow): {
211
- nodes: WorkflowNodeType[];
212
- edges: WorkflowEdge[];
213
- } {
214
- const nodesWithCallbacks = workflow.nodes.map((node) => ({
233
+ /** Add the callbacks every node component can call: open config, commit an in-place edit. */
234
+ function withNodeCallbacks(node: WorkflowNodeType) {
235
+ return {
215
236
  ...node,
216
237
  data: {
217
238
  ...node.data,
218
- onConfigOpen: props.openConfigSidebar
239
+ onConfigOpen: props.openConfigSidebar,
240
+ onInlineCommit: handleInlineCommit
219
241
  }
220
- }));
242
+ };
243
+ }
244
+
245
+ function buildFlowNodesFromStore(workflow: Workflow): {
246
+ nodes: WorkflowNodeType[];
247
+ edges: WorkflowEdge[];
248
+ } {
249
+ const nodesWithCallbacks = workflow.nodes.map(withNodeCallbacks);
221
250
  const styledEdges = EdgeStylingHelper.updateEdgeStyles(workflow.edges, nodesWithCallbacks);
222
251
  return { nodes: nodesWithCallbacks, edges: styledEdges };
223
252
  }
@@ -660,6 +689,58 @@
660
689
  return WorkflowOperationsHelper.checkWorkflowCycles(flowNodes, flowEdges);
661
690
  });
662
691
 
692
+ /**
693
+ * Create a node from node-type JSON at a flow position, append it to the
694
+ * canvas and the store, and record the "Add node" history entry. Shared by
695
+ * the sidebar drop and the context menu's `addNode` action.
696
+ *
697
+ * The node is on the canvas (and in the store) synchronously; `done`
698
+ * resolves once the history entry has been pushed.
699
+ */
700
+ function placeNode(
701
+ nodeTypeData: string,
702
+ position: { x: number; y: number },
703
+ options: { history?: boolean; emptyLabel?: boolean } = {}
704
+ ): { id: string | null; done: Promise<void> } {
705
+ const { history = true, emptyLabel = false } = options;
706
+ // The machine's `dropping` state is what holds the store -> canvas sync
707
+ // off while a node is added (see its permissions), so every placement
708
+ // goes through it, not only a sidebar drop.
709
+ machine.send('START_DROP');
710
+
711
+ const newNode = NodeOperationsHelper.createNodeFromDrop(nodeTypeData, position, flowNodes);
712
+
713
+ if (!newNode) {
714
+ logger.warn('Failed to create node from drop data');
715
+ machine.send('DROP_COMPLETE');
716
+ return { id: null, done: Promise.resolve() };
717
+ }
718
+
719
+ // Add the node callbacks and append to flowNodes for immediate visual feedback
720
+ const nodeWithCallback = withNodeCallbacks(
721
+ emptyLabel ? { ...newNode, data: { ...newNode.data, label: '' } } : newNode
722
+ );
723
+ flowNodes = [...flowNodes, nodeWithCallback];
724
+
725
+ // Sync to store
726
+ syncFlowToStore();
727
+
728
+ const done = (async () => {
729
+ await tick();
730
+
731
+ if (history) {
732
+ const storeValue = fd.workflow.current;
733
+ if (storeValue) {
734
+ fd.workflow.pushHistory('Add node', storeValue);
735
+ }
736
+ }
737
+
738
+ machine.send('DROP_COMPLETE');
739
+ })();
740
+
741
+ return { id: newNode.id, done };
742
+ }
743
+
663
744
  /**
664
745
  * Handle drop event and add new node to canvas
665
746
  */
@@ -667,34 +748,268 @@
667
748
  nodeTypeData: string,
668
749
  position: { x: number; y: number }
669
750
  ): Promise<void> {
670
- machine.send('START_DROP');
751
+ await placeNode(nodeTypeData, position).done;
752
+ }
671
753
 
672
- const newNode = NodeOperationsHelper.createNodeFromDrop(nodeTypeData, position, flowNodes);
754
+ // ---------------------------------------------------------------------------
755
+ // Canvas context menu
756
+ // ---------------------------------------------------------------------------
673
757
 
674
- if (newNode) {
675
- // Add onConfigOpen callback and append to flowNodes for immediate visual feedback
676
- const nodeWithCallback = {
677
- ...newNode,
678
- data: { ...newNode.data, onConfigOpen: props.openConfigSidebar }
679
- };
680
- flowNodes = [...flowNodes, nodeWithCallback];
758
+ interface OpenContextMenu {
759
+ ctx: ContextMenuContext;
760
+ entries: ContextMenuEntry[];
761
+ /** Viewport (client) position; the menu is in the top layer. */
762
+ x: number;
763
+ y: number;
764
+ }
681
765
 
682
- // Sync to store
683
- syncFlowToStore();
766
+ let openMenu = $state.raw<OpenContextMenu | null>(null);
767
+ let canvasEl: HTMLDivElement | undefined = $state();
684
768
 
685
- await tick();
769
+ /** Whether a node's registered component edits its text in place (the caption). */
770
+ function nodeEditsInPlace(node: WorkflowNodeType): boolean {
771
+ return (
772
+ !!node.data.metadata &&
773
+ fd.nodes.editsInPlace(
774
+ resolveComponentName(fd.nodes, node.data.metadata, node.data.config?.nodeType as string)
775
+ )
776
+ );
777
+ }
778
+
779
+ /**
780
+ * Ids of in-place nodes that were just added and have no history entry yet.
781
+ * Their first save pushes "Add caption"; cancelling or leaving them empty
782
+ * removes them without a trace.
783
+ */
784
+ const pendingNewIds = new Set<string>();
785
+
786
+ /** Remove a node and its edges from the canvas and the store, without a history entry. */
787
+ function removeNode(id: string): void {
788
+ flowNodes = flowNodes.filter((n) => n.id !== id);
789
+ flowEdges = flowEdges.filter((e) => e.source !== id && e.target !== id);
790
+ syncFlowToStore();
791
+ }
792
+
793
+ /**
794
+ * An in-place edit ended (see CaptionNode): `text` is what was typed, or
795
+ * null when the user cancelled. `decideInlineCommit` holds the rules and
796
+ * cleans the text.
797
+ */
798
+ function handleInlineCommit(id: string, text: string | null): void {
799
+ const node = flowNodes.find((n) => n.id === id);
800
+ const isNew = pendingNewIds.delete(id);
801
+ if (!node || !canvasEditable) {
802
+ // Gone (undo, workflow switch) or no longer editable: a pending node must not linger.
803
+ if (node && isNew) removeNode(id);
804
+ return;
805
+ }
806
+
807
+ const { outcome, label } = decideInlineCommit(text, node.data.label ?? '', isNew);
808
+ if (outcome === 'none') return;
809
+
810
+ if (outcome === 'remove') {
811
+ removeNode(id);
812
+ return;
813
+ }
686
814
 
687
- const storeValue = fd.workflow.current;
688
- if (storeValue) {
689
- fd.workflow.pushHistory('Add node', storeValue);
815
+ flowNodes = flowNodes.map((n) => (n.id === id ? { ...n, data: { ...n.data, label } } : n));
816
+ syncFlowToStore();
817
+ const storeValue = fd.workflow.current;
818
+ if (storeValue) {
819
+ fd.workflow.pushHistory(outcome === 'add' ? 'Add caption' : 'Edit caption', storeValue);
820
+ }
821
+ }
822
+
823
+ const contextMenuActions: ContextMenuActions = {
824
+ addNode(metadata: NodeMetadata, position, options) {
825
+ const editsHere =
826
+ options?.edit === true && fd.nodes.editsInPlace(resolveComponentName(fd.nodes, metadata));
827
+ if (!editsHere) return placeNode(JSON.stringify(metadata), position).id;
828
+
829
+ // New in-place node: empty text, no history entry until the first save.
830
+ const { id } = placeNode(JSON.stringify(metadata), position, {
831
+ history: false,
832
+ emptyLabel: true
833
+ });
834
+ if (id) {
835
+ pendingNewIds.add(id);
836
+ fd.inlineEdit.request(id);
690
837
  }
691
- } else {
692
- logger.warn('Failed to create node from drop data');
838
+ return id;
839
+ },
840
+ async deleteNodes(ids) {
841
+ if (ids.length === 0) return;
842
+ // Through xyflow so confirm-delete, edge removal and history all apply.
843
+ await canvasControllerRef?.canvasDeleteNodes(ids);
844
+ },
845
+ openConfig(id) {
846
+ const node = flowNodes.find((n) => n.id === id);
847
+ if (!node || !props.openConfigSidebar) return;
848
+ // Same node shape UniversalNode's Enter key passes.
849
+ props.openConfigSidebar({
850
+ id,
851
+ type: node.data.metadata?.type ?? 'default',
852
+ data: node.data
853
+ } as WorkflowNodeType);
854
+ },
855
+ editInPlace(id) {
856
+ fd.inlineEdit.request(id);
857
+ }
858
+ };
859
+
860
+ /**
861
+ * Snap a flow position to the grid cell it falls in (floor, not round), so
862
+ * a node added from the menu has its top-left on the cell that was clicked.
863
+ */
864
+ function snapPosition(position: { x: number; y: number }): { x: number; y: number } {
865
+ const settings = getEditorSettings();
866
+ if (!settings.snapToGrid) return position;
867
+ const grid = settings.gridSize;
868
+ return { x: Math.floor(position.x / grid) * grid, y: Math.floor(position.y / grid) * grid };
869
+ }
870
+
871
+ function closeContextMenu(): void {
872
+ openMenu = null;
873
+ }
874
+
875
+ /** Run a menu entry. The menu closes first: running may open another one. */
876
+ function selectContextMenuEntry(entry: ContextMenuEntry): void {
877
+ const menu = openMenu;
878
+ if (!menu) return;
879
+ openMenu = null;
880
+ runContextMenuEntry(entry, menu.ctx);
881
+ }
882
+
883
+ /**
884
+ * Open the menu for a target at a viewport (client) point. Returns false
885
+ * when there is nothing to show, so the caller leaves the browser's own
886
+ * menu alone.
887
+ */
888
+ function showContextMenu(
889
+ target: ContextMenuTarget,
890
+ nodes: WorkflowNodeType[],
891
+ clientX: number,
892
+ clientY: number
893
+ ): boolean {
894
+ if (!canvasEditable || !canvasControllerRef) return false;
895
+
896
+ const ctx: ContextMenuContext = {
897
+ target,
898
+ nodes,
899
+ position: snapPosition(canvasControllerRef.canvasScreenToFlow({ x: clientX, y: clientY })),
900
+ nodeTypes: fd.nodeTypes.current,
901
+ actions: contextMenuActions
902
+ };
903
+ const entries = resolveContextMenuEntries(ctx, props.contextMenu, getMsgs().contextMenu, {
904
+ editsInPlace: nodeEditsInPlace
905
+ });
906
+ if (entries.length === 0) {
907
+ openMenu = null;
908
+ return false;
909
+ }
910
+
911
+ openMenu = { ctx, entries, x: clientX, y: clientY };
912
+ return true;
913
+ }
914
+
915
+ /** Right-click or keyboard on a node: select it alone first, unless it is part of a multi-selection. */
916
+ function openNodeMenu(nodeId: string, clientX: number, clientY: number): void {
917
+ const node = flowNodes.find((n) => n.id === nodeId);
918
+ if (!node) return;
919
+
920
+ const selected = flowNodes.filter((n) => n.selected);
921
+ if (node.selected && selected.length > 1) {
922
+ showContextMenu('selection', selected, clientX, clientY);
923
+ return;
924
+ }
925
+
926
+ if (!node.selected || selected.length > 1) {
927
+ flowNodes = flowNodes.map((n) =>
928
+ n.selected === (n.id === nodeId) ? n : { ...n, selected: n.id === nodeId }
929
+ );
930
+ }
931
+ showContextMenu('node', [flowNodes.find((n) => n.id === nodeId) ?? node], clientX, clientY);
932
+ }
933
+
934
+ function handleNodeContextMenu({
935
+ event,
936
+ node
937
+ }: {
938
+ event: MouseEvent;
939
+ node: WorkflowNodeType;
940
+ }): void {
941
+ if (!canvasEditable) return;
942
+ event.preventDefault();
943
+ openNodeMenu(node.id, event.clientX, event.clientY);
944
+ }
945
+
946
+ function handleSelectionContextMenu({
947
+ event,
948
+ nodes
949
+ }: {
950
+ event: MouseEvent;
951
+ nodes: WorkflowNodeType[];
952
+ }): void {
953
+ if (!canvasEditable) return;
954
+ event.preventDefault();
955
+ showContextMenu(
956
+ nodes.length > 1 ? 'selection' : 'node',
957
+ nodes.map((n) => flowNodes.find((f) => f.id === n.id) ?? n),
958
+ event.clientX,
959
+ event.clientY
960
+ );
961
+ }
962
+
963
+ function handlePaneContextMenu({ event }: { event: MouseEvent }): void {
964
+ if (!canvasEditable) return;
965
+ // Only take over the right-click when the pane menu has entries.
966
+ if (showContextMenu('pane', [], event.clientX, event.clientY)) event.preventDefault();
967
+ }
968
+
969
+ /**
970
+ * Shift+F10 / the Menu key: on a focused node wrapper open that node's menu
971
+ * anchored at the node; elsewhere in the canvas open the pane menu at the
972
+ * viewport centre. Returns true when the key was handled.
973
+ */
974
+ function handleMenuKey(event: KeyboardEvent, target: HTMLElement): boolean {
975
+ const isMenuKey = event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey);
976
+ if (!isMenuKey || !canvasEditable) return false;
977
+ if (!target.closest('.flowdrop-canvas') || target.closest('.canvas-context-menu')) return false;
978
+
979
+ event.preventDefault();
980
+
981
+ const wrapper = target.classList.contains('svelte-flow__node') ? target : null;
982
+ const nodeId = wrapper?.dataset.id;
983
+ if (wrapper && nodeId) {
984
+ const rect = wrapper.getBoundingClientRect();
985
+ openNodeMenu(nodeId, rect.left + rect.width / 2, rect.top + rect.height / 2);
986
+ return true;
693
987
  }
694
988
 
695
- machine.send('DROP_COMPLETE');
989
+ const flowEl = canvasEl?.querySelector('.svelte-flow') ?? canvasEl;
990
+ if (flowEl) {
991
+ const rect = flowEl.getBoundingClientRect();
992
+ showContextMenu('pane', [], rect.left + rect.width / 2, rect.top + rect.height / 2);
993
+ }
994
+ return true;
696
995
  }
697
996
 
997
+ // Menus never outlive edit mode or the workflow they were opened on.
998
+ $effect(() => {
999
+ if (!canvasEditable) openMenu = null;
1000
+ });
1001
+ $effect(() => {
1002
+ void svelteFlowKey;
1003
+ openMenu = null;
1004
+ pendingNewIds.clear();
1005
+ fd.inlineEdit.clear();
1006
+ });
1007
+
1008
+ // In-place editing follows edit mode.
1009
+ $effect(() => {
1010
+ fd.inlineEdit.setEditable(canvasEditable);
1011
+ });
1012
+
698
1013
  /**
699
1014
  * Handle a workflow JSON file dropped directly onto the canvas.
700
1015
  *
@@ -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')) {
@@ -893,7 +1213,11 @@
893
1213
  <!-- Flow Canvas.
894
1214
  Capture-phase mousedown so dragging from a port never turns into a
895
1215
  WebKit text-selection drag — see suppressPortDragSelection. -->
896
- <div class="flowdrop-canvas" onmousedowncapture={suppressPortDragSelection}>
1216
+ <div
1217
+ class="flowdrop-canvas"
1218
+ bind:this={canvasEl}
1219
+ onmousedowncapture={suppressPortDragSelection}
1220
+ >
897
1221
  <FlowDropZone ondrop={handleNodeDrop} onfiledrop={handleWorkflowFileDrop}>
898
1222
  {#key svelteFlowKey}
899
1223
  <SvelteFlow
@@ -909,6 +1233,9 @@
909
1233
  onnodedragstart={handleNodeDragStart}
910
1234
  onnodedrag={handleNodeDrag}
911
1235
  onnodedragstop={handleNodeDragStop}
1236
+ onnodecontextmenu={handleNodeContextMenu}
1237
+ onselectioncontextmenu={handleSelectionContextMenu}
1238
+ onpanecontextmenu={handlePaneContextMenu}
912
1239
  minZoom={0.2}
913
1240
  maxZoom={3}
914
1241
  clickConnect={true}
@@ -979,6 +1306,16 @@
979
1306
  </CanvasBanner>
980
1307
  {/if}
981
1308
  </FlowDropZone>
1309
+
1310
+ {#if openMenu}
1311
+ <CanvasContextMenu
1312
+ entries={openMenu.entries}
1313
+ x={openMenu.x}
1314
+ y={openMenu.y}
1315
+ onselect={selectContextMenuEntry}
1316
+ onclose={closeContextMenu}
1317
+ />
1318
+ {/if}
982
1319
  </div>
983
1320
 
984
1321
  <!-- Status Bar: aria-live announces dynamic changes (node/edge counts, cycle warnings) -->
@@ -1,5 +1,6 @@
1
1
  import '@xyflow/svelte/dist/style.css';
2
2
  import type { WorkflowNode as WorkflowNodeType } from '../types/index.js';
3
+ import { type ContextMenuOptions } from '../editor/contextMenu.js';
3
4
  import type { EndpointConfig } from '../config/endpoints.js';
4
5
  import type { AuthProvider } from '../types/auth.js';
5
6
  import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
@@ -47,6 +48,12 @@ interface Props {
47
48
  * @default true
48
49
  */
49
50
  builtinEditors?: boolean;
51
+ /**
52
+ * Customise the canvas context menu (right-click, Shift+F10, Menu key).
53
+ * `items` receives the built-in entries and returns the final list.
54
+ * The menu only opens in `'edit'` mode.
55
+ */
56
+ contextMenu?: ContextMenuOptions;
50
57
  }
51
58
  declare const WorkflowEditor: import("svelte").Component<Props, {
52
59
  updateNodeData: (nodeId: string, dataUpdates: Partial<WorkflowNodeType["data"]>) => void;
@@ -21,7 +21,9 @@
21
21
  so every edit here goes through the store's normal history path.
22
22
 
23
23
  `meta` is never editable here (design decision 4) — it round-trips verbatim
24
- and is shown as a read-only JSON disclosure when present.
24
+ and is shown as a read-only JSON disclosure when present. One exception: the
25
+ Chat turn selector writes `meta.limit` on a `history` entry (and removes it
26
+ when the entry stops being one), the one key `turn` owns.
25
27
  -->
26
28
 
27
29
  <script lang="ts">
@@ -42,6 +44,7 @@
42
44
  entryFromBindablePort,
43
45
  rankBindablePorts,
44
46
  resolveInterface,
47
+ turnTakenBy,
45
48
  validateWorkflowInterface,
46
49
  type InterfaceIssue,
47
50
  type RankedBindablePort,
@@ -113,7 +116,8 @@
113
116
  */
114
117
  const INLINE_ISSUE_CODES = new Set([
115
118
  'interface-type-mismatch',
116
- 'interface-input-already-connected'
119
+ 'interface-input-already-connected',
120
+ 'interface-turn-duplicate'
117
121
  ]);
118
122
 
119
123
  function footerIssues(
@@ -297,10 +301,28 @@
297
301
  patch: Partial<WorkflowInterfaceEntry>
298
302
  ): void {
299
303
  const list = entriesFor(direction).map((entry, i) =>
300
- i === index ? { ...entry, ...patch } : entry
304
+ i === index ? applyPatch(entry, patch) : entry
301
305
  );
302
306
  commit(direction, list);
303
307
  }
308
+
309
+ /**
310
+ * Merge a patch into an entry. A key the patch sets to `undefined` is
311
+ * removed rather than kept as an own `undefined` property, so clearing a
312
+ * field (a turn set back to none, an emptied name) leaves no key behind.
313
+ * Keys the patch does not mention — including ones this editor does not
314
+ * know — are carried over untouched.
315
+ */
316
+ function applyPatch(
317
+ entry: WorkflowInterfaceEntry,
318
+ patch: Partial<WorkflowInterfaceEntry>
319
+ ): WorkflowInterfaceEntry {
320
+ const next: WorkflowInterfaceEntry = { ...entry, ...patch };
321
+ for (const key of Object.keys(patch) as Array<keyof WorkflowInterfaceEntry>) {
322
+ if (patch[key] === undefined) delete next[key];
323
+ }
324
+ return next;
325
+ }
304
326
  </script>
305
327
 
306
328
  <div class="wf-interface">
@@ -341,6 +363,9 @@
341
363
  'interface-input-already-connected'
342
364
  )}
343
365
  conflictingSource={conflictingSourceLabel(entry)}
366
+ turnTakenBy={section.key === 'inputs'
367
+ ? turnTakenBy(entriesFor('inputs'), entry)
368
+ : undefined}
344
369
  isFirst={index === 0}
345
370
  isLast={index === list.length - 1}
346
371
  onPatch={(patch: Partial<WorkflowInterfaceEntry>) =>