@widgetic/workflows 0.2.15 → 0.2.17

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 (108) hide show
  1. package/README.md +117 -3
  2. package/dist/api/types.d.ts +17 -0
  3. package/dist/api/workflowsApi.d.ts +12 -1
  4. package/dist/api/workflowsApi.js +37 -0
  5. package/dist/assistant/assistantEvents.d.ts +44 -2
  6. package/dist/assistant/assistantEvents.js +58 -2
  7. package/dist/assistant/assistantReferences.d.ts +66 -0
  8. package/dist/assistant/assistantReferences.js +109 -0
  9. package/dist/assistant/assistantSaveMode.d.ts +15 -3
  10. package/dist/assistant/assistantSaveMode.js +16 -2
  11. package/dist/assistant/assistantSeed.d.ts +55 -0
  12. package/dist/assistant/assistantSeed.js +90 -0
  13. package/dist/assistant/assistantStream.js +81 -3
  14. package/dist/assistant/assistantSuggest.d.ts +18 -0
  15. package/dist/assistant/assistantSuggest.js +21 -0
  16. package/dist/assistant/assistantTurns.d.ts +75 -0
  17. package/dist/assistant/assistantTurns.js +56 -0
  18. package/dist/assistant/attachmentUploads.d.ts +42 -0
  19. package/dist/assistant/attachmentUploads.js +69 -0
  20. package/dist/assistant/canvasLink.d.ts +30 -0
  21. package/dist/assistant/canvasLink.js +51 -0
  22. package/dist/assistant/compositionMention.d.ts +18 -0
  23. package/dist/assistant/compositionMention.js +47 -0
  24. package/dist/assistant/liveData.d.ts +150 -0
  25. package/dist/assistant/liveData.js +286 -0
  26. package/dist/assistant/mcpMention.d.ts +20 -0
  27. package/dist/assistant/mcpMention.js +30 -0
  28. package/dist/assistant/mentionEntries.d.ts +39 -0
  29. package/dist/assistant/mentionEntries.js +69 -0
  30. package/dist/assistant/planFlow.d.ts +26 -0
  31. package/dist/assistant/planFlow.js +57 -0
  32. package/dist/assistant/templateDestinations.d.ts +37 -0
  33. package/dist/assistant/templateDestinations.js +64 -0
  34. package/dist/assistant/types.d.ts +99 -2
  35. package/dist/assistant/workflowPlanViewModel.d.ts +13 -2
  36. package/dist/assistant/workflowPlanViewModel.js +9 -1
  37. package/dist/components/Workflows.svelte +7 -1
  38. package/dist/components/WorkflowsEmptyState.svelte +8 -3
  39. package/dist/components/WorkflowsWorkspace.svelte +29 -1
  40. package/dist/components/WorkflowsWorkspace.svelte.d.ts +3 -0
  41. package/dist/components/assistant/AssistantPlanStepRow.svelte +56 -0
  42. package/dist/components/assistant/AssistantPlanStepRow.svelte.d.ts +9 -0
  43. package/dist/components/assistant/CompositionMentionMenu.svelte +135 -0
  44. package/dist/components/assistant/CompositionMentionMenu.svelte.d.ts +9 -0
  45. package/dist/components/assistant/DataPreviewCard.svelte +108 -0
  46. package/dist/components/assistant/DataPreviewCard.svelte.d.ts +7 -0
  47. package/dist/components/assistant/PlanBindingsBlock.svelte +200 -0
  48. package/dist/components/assistant/PlanBindingsBlock.svelte.d.ts +14 -0
  49. package/dist/components/assistant/TemplateProjectCard.svelte +81 -0
  50. package/dist/components/assistant/TemplateProjectCard.svelte.d.ts +14 -0
  51. package/dist/components/assistant/WorkflowAssistantPanel.svelte +1045 -147
  52. package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +5 -0
  53. package/dist/components/canvas/CanvasContextMenu.svelte +199 -0
  54. package/dist/components/canvas/CanvasContextMenu.svelte.d.ts +16 -0
  55. package/dist/components/canvas/CompositionNodeView.svelte +7 -2
  56. package/dist/components/canvas/ConditionNodeView.svelte +5 -1
  57. package/dist/components/canvas/HandlePoint.svelte +25 -3
  58. package/dist/components/canvas/WorkflowCanvas.svelte +351 -12
  59. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +12 -1
  60. package/dist/components/canvas/altDragDuplicateController.d.ts +29 -0
  61. package/dist/components/canvas/altDragDuplicateController.js +92 -0
  62. package/dist/components/canvas/connectionSnapController.d.ts +29 -0
  63. package/dist/components/canvas/connectionSnapController.js +182 -0
  64. package/dist/components/canvas/spacePanController.d.ts +16 -0
  65. package/dist/components/canvas/spacePanController.js +103 -0
  66. package/dist/components/editor/EditorCanvasArea.svelte +98 -4
  67. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +5 -0
  68. package/dist/components/editor/EditorTopBar.svelte +53 -42
  69. package/dist/components/editor/WorkflowEditor.svelte +74 -41
  70. package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
  71. package/dist/components/editor/WorkflowNameControl.svelte +9 -8
  72. package/dist/components/editor/WorkflowNameControl.svelte.d.ts +3 -1
  73. package/dist/components/list/WorkflowList.svelte +50 -26
  74. package/dist/components/list/WorkflowList.svelte.d.ts +5 -0
  75. package/dist/components/panel/CompositionForm.svelte +3 -2
  76. package/dist/components/panel/CompositionPicker.svelte +15 -20
  77. package/dist/components/panel/CompositionPicker.svelte.d.ts +2 -2
  78. package/dist/components/panel/CompositionSelect.svelte +4 -4
  79. package/dist/components/panel/CompositionSelect.svelte.d.ts +2 -2
  80. package/dist/components/ui/icons.d.ts +8 -0
  81. package/dist/components/ui/icons.js +24 -1
  82. package/dist/editor/autoLayout.d.ts +38 -0
  83. package/dist/editor/autoLayout.js +403 -0
  84. package/dist/editor/blockClipboard.svelte.d.ts +9 -0
  85. package/dist/editor/blockClipboard.svelte.js +24 -0
  86. package/dist/editor/blockCopy.d.ts +39 -0
  87. package/dist/editor/blockCopy.js +137 -0
  88. package/dist/editor/canvasMenu.d.ts +45 -0
  89. package/dist/editor/canvasMenu.js +68 -0
  90. package/dist/editor/connectionSnap.d.ts +90 -0
  91. package/dist/editor/connectionSnap.js +98 -0
  92. package/dist/editor/editorState.svelte.d.ts +122 -13
  93. package/dist/editor/editorState.svelte.js +262 -22
  94. package/dist/editor/graphIssues.d.ts +5 -0
  95. package/dist/editor/graphIssues.js +18 -0
  96. package/dist/editor/graphModel.d.ts +6 -1
  97. package/dist/editor/graphModel.js +8 -1
  98. package/dist/editor/keyHints.d.ts +21 -0
  99. package/dist/editor/keyHints.js +30 -0
  100. package/dist/editor/listState.svelte.d.ts +4 -4
  101. package/dist/editor/staleGuard.d.ts +111 -0
  102. package/dist/editor/staleGuard.js +279 -0
  103. package/dist/i18n/language.d.ts +3 -3
  104. package/dist/i18n/messages.d.ts +84 -1
  105. package/dist/i18n/messages.js +97 -4
  106. package/dist/index.d.ts +1 -0
  107. package/dist/types/index.d.ts +19 -2
  108. package/package.json +10 -10
@@ -0,0 +1,182 @@
1
+ import { CONNECTION_SNAP_ENABLED, CONNECTION_SNAP_RELEASE_DISTANCE, distanceToRectangle, pickSnapTarget } from '../../editor/connectionSnap.js';
2
+ import { workflowsError } from '../../utils/logger.js';
3
+ const NO_MAGNET = { release() { }, dispose() { } };
4
+ /**
5
+ * Puts the magnet on a canvas. `wrapper` is the element that holds kaykay's canvas (the events and the marks are on it).
6
+ * Answers what the canvas calls to let go of a point and to take the magnet off again.
7
+ */
8
+ export function installConnectionSnap(flow, wrapper) {
9
+ if (!CONNECTION_SNAP_ENABLED)
10
+ return NO_MAGNET;
11
+ const updateConnectionOfKaykay = flow.updateConnection;
12
+ /** The point that holds the line now. */
13
+ let held = null;
14
+ /** The elements that carry the marks, to take them off again. */
15
+ let markedHandleElement = null;
16
+ let markedNodeElement = null;
17
+ // ---- reading the canvas ------------------------------------------------------------------------------------------
18
+ /** The places the line being drawn could end near `pointer`: the points that accept it, of the blocks within reach. */
19
+ function readCandidates(draft, pointer) {
20
+ const isMovingStart = draft.reconnect_type === 'source';
21
+ const wantedHandleType = isMovingStart ? 'output' : 'input';
22
+ const fixedNodeId = isMovingStart ? draft.fixed_target_node_id : draft.source_node_id;
23
+ const fixedHandleId = isMovingStart ? draft.fixed_target_handle_id : draft.source_handle_id;
24
+ if (fixedNodeId === undefined || fixedHandleId === undefined)
25
+ return [];
26
+ // Blocks further away than the distance that lets go are not asked about (asking the engine is the costly part).
27
+ const reach = CONNECTION_SNAP_RELEASE_DISTANCE / Math.max(flow.viewport.zoom, 0.01);
28
+ const candidates = [];
29
+ for (const node of flow.nodes) {
30
+ if (node.id === fixedNodeId)
31
+ continue;
32
+ const origin = flow.getAbsolutePosition(node.id);
33
+ const nodeRectangle = {
34
+ x: origin.x,
35
+ y: origin.y,
36
+ width: node.computed_width,
37
+ height: node.computed_height
38
+ };
39
+ if (distanceToRectangle(pointer, nodeRectangle) > reach)
40
+ continue;
41
+ for (const handle of node.handles.values()) {
42
+ if (handle.type !== wantedHandleType)
43
+ continue;
44
+ const verdict = isMovingStart
45
+ ? flow.getConnectionValidation(node.id, handle.id, fixedNodeId, fixedHandleId, draft.reconnect_edge_id)
46
+ : flow.getConnectionValidation(fixedNodeId, fixedHandleId, node.id, handle.id, draft.reconnect_edge_id);
47
+ if (!verdict.valid)
48
+ continue;
49
+ candidates.push({
50
+ nodeId: node.id,
51
+ handleId: handle.id,
52
+ nodeRectangle,
53
+ handlePosition: flow.getHandlePosition(node.id, handle.id) ?? handle.absolute_position
54
+ });
55
+ }
56
+ }
57
+ return candidates;
58
+ }
59
+ /** Which point holds the line for a pointer at this place of the canvas (and remembers it). */
60
+ function chooseTarget(pointer) {
61
+ const draft = flow.draft_connection;
62
+ if (!draft) {
63
+ held = null;
64
+ return null;
65
+ }
66
+ const target = pickSnapTarget({
67
+ pointer,
68
+ zoom: flow.viewport.zoom,
69
+ candidates: readCandidates(draft, pointer),
70
+ held,
71
+ enabled: CONNECTION_SNAP_ENABLED
72
+ });
73
+ held = target ? { nodeId: target.nodeId, handleId: target.handleId } : null;
74
+ return target;
75
+ }
76
+ /** Where a mouse event is on the canvas, in canvas units. */
77
+ function readCanvasPosition(event) {
78
+ const surface = wrapper.querySelector('.kaykay-canvas');
79
+ if (!surface)
80
+ return null;
81
+ const bounds = surface.getBoundingClientRect();
82
+ return flow.screenToCanvas({ x: event.clientX - bounds.left, y: event.clientY - bounds.top });
83
+ }
84
+ // ---- the marks ----------------------------------------------------------------------------------------------------
85
+ function clearMarks() {
86
+ markedHandleElement?.removeAttribute('data-snapped');
87
+ markedNodeElement?.removeAttribute('data-snap-target');
88
+ markedHandleElement = null;
89
+ markedNodeElement = null;
90
+ }
91
+ /** Marks the point that holds the line, and the block it is on; nothing for a line that is free. */
92
+ function markTarget(target) {
93
+ if (target === null) {
94
+ clearMarks();
95
+ return;
96
+ }
97
+ const nodeElement = [...wrapper.querySelectorAll('[data-node-id]')].find((element) => element.dataset.nodeId === target.nodeId);
98
+ const handleElement = nodeElement
99
+ ? [...nodeElement.querySelectorAll('[data-handle-id]')].find((element) => element.dataset.handleId === target.handleId)
100
+ : undefined;
101
+ if (handleElement === markedHandleElement && nodeElement === markedNodeElement)
102
+ return;
103
+ clearMarks();
104
+ handleElement?.setAttribute('data-snapped', 'true');
105
+ nodeElement?.setAttribute('data-snap-target', 'true');
106
+ markedHandleElement = handleElement ?? null;
107
+ markedNodeElement = nodeElement ?? null;
108
+ }
109
+ // ---- the end of the line ------------------------------------------------------------------------------------------
110
+ // kaykay calls this once per frame with the end of the line it worked out from the pointer.
111
+ flow.updateConnection = (position) => {
112
+ let end = position;
113
+ try {
114
+ const target = chooseTarget(position);
115
+ markTarget(target);
116
+ if (target)
117
+ end = target.handlePosition;
118
+ }
119
+ catch (error) {
120
+ // A failed magnet must not stop the line: it follows the pointer, as it does without the magnet.
121
+ workflowsError('The canvas could not snap a line; the line follows the pointer.', error);
122
+ held = null;
123
+ clearMarks();
124
+ }
125
+ updateConnectionOfKaykay.call(flow, end);
126
+ };
127
+ /**
128
+ * Finishes the line at the point that holds it, for a mouse event at this place. Answers whether it did, so that kaykay,
129
+ * which would cancel the line or look for a point under the pointer, is not told about the event.
130
+ */
131
+ function connectAtHeldPoint(event) {
132
+ if (!flow.draft_connection)
133
+ return false;
134
+ try {
135
+ // The pointer may have moved since the last frame: the point is chosen again for where it is now.
136
+ const position = readCanvasPosition(event);
137
+ if (position)
138
+ chooseTarget(position);
139
+ }
140
+ catch (error) {
141
+ workflowsError('The canvas could not snap a line; the line follows the pointer.', error);
142
+ held = null;
143
+ }
144
+ if (!held)
145
+ return false;
146
+ const { nodeId, handleId } = held;
147
+ held = null;
148
+ clearMarks();
149
+ flow.finishConnection(nodeId, handleId);
150
+ return true;
151
+ }
152
+ function handleMouseUpCapture(event) {
153
+ if (event.button !== 0)
154
+ return;
155
+ connectAtHeldPoint(event);
156
+ }
157
+ // A line started with a click (not a drag) waits for the next click: a click where the line is snapped connects it.
158
+ function handleMouseDownCapture(event) {
159
+ if (event.button !== 0 || !flow.draft_connection)
160
+ return;
161
+ if (connectAtHeldPoint(event)) {
162
+ event.preventDefault();
163
+ event.stopPropagation();
164
+ }
165
+ }
166
+ wrapper.addEventListener('mouseup', handleMouseUpCapture, true);
167
+ wrapper.addEventListener('mousedown', handleMouseDownCapture, true);
168
+ return {
169
+ release() {
170
+ held = null;
171
+ clearMarks();
172
+ },
173
+ dispose() {
174
+ wrapper.removeEventListener('mouseup', handleMouseUpCapture, true);
175
+ wrapper.removeEventListener('mousedown', handleMouseDownCapture, true);
176
+ // The wrapped call is an own property of this canvas's state: taking it away shows kaykay's own method again.
177
+ delete flow.updateConnection;
178
+ held = null;
179
+ clearMarks();
180
+ }
181
+ };
182
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Hold Space and drag to move the view, as on the Widgetic canvas. A drag on the empty canvas draws a selection box, so the
3
+ * view is moved with the middle button (kaykay does that), a two-finger scroll (kaykay does that too), or with Space held,
4
+ * which this controller adds: with Space down a press anywhere (on a block too) grabs the canvas instead of the thing under it.
5
+ *
6
+ * The state it keeps is written on the canvas's wrapper, where the stylesheet answers it: `data-space-held` while the key is
7
+ * down (the cursor is an open hand) and `data-panning` while the pointer drags (a closed hand).
8
+ */
9
+ import type { FlowState } from 'kaykay';
10
+ export interface SpacePanOptions {
11
+ flow: FlowState;
12
+ /** The element that holds kaykay's canvas. */
13
+ wrapper: HTMLElement;
14
+ }
15
+ /** Puts the gesture on the canvas. Answers what takes it off again. */
16
+ export declare function installSpacePan(options: SpacePanOptions): () => void;
@@ -0,0 +1,103 @@
1
+ /** Whether the key was pressed in a field where Space is text. */
2
+ function isTypingTarget(target) {
3
+ if (!(target instanceof HTMLElement))
4
+ return false;
5
+ return (target.tagName === 'INPUT' ||
6
+ target.tagName === 'TEXTAREA' ||
7
+ target.tagName === 'SELECT' ||
8
+ target.isContentEditable);
9
+ }
10
+ /** Puts the gesture on the canvas. Answers what takes it off again. */
11
+ export function installSpacePan(options) {
12
+ const { flow, wrapper } = options;
13
+ let isSpaceHeld = false;
14
+ let lastPointer = null;
15
+ /** The movement that is waiting for the next frame: the view moves once per frame, however many events came. */
16
+ let pendingPan = { x: 0, y: 0 };
17
+ let frame = null;
18
+ function flushPan() {
19
+ frame = null;
20
+ if (pendingPan.x === 0 && pendingPan.y === 0)
21
+ return;
22
+ const { x, y } = pendingPan;
23
+ pendingPan = { x: 0, y: 0 };
24
+ flow.pan(x, y);
25
+ }
26
+ function stopPanning() {
27
+ if (frame !== null) {
28
+ cancelAnimationFrame(frame);
29
+ flushPan();
30
+ }
31
+ lastPointer = null;
32
+ wrapper.removeAttribute('data-panning');
33
+ window.removeEventListener('mousemove', handleMouseMove);
34
+ window.removeEventListener('mouseup', handleMouseUp);
35
+ }
36
+ function releaseSpace() {
37
+ isSpaceHeld = false;
38
+ wrapper.removeAttribute('data-space-held');
39
+ }
40
+ function handleMouseMove(event) {
41
+ if (!lastPointer)
42
+ return;
43
+ pendingPan = {
44
+ x: pendingPan.x + (event.clientX - lastPointer.clientX),
45
+ y: pendingPan.y + (event.clientY - lastPointer.clientY)
46
+ };
47
+ lastPointer = { clientX: event.clientX, clientY: event.clientY };
48
+ if (frame === null)
49
+ frame = requestAnimationFrame(flushPan);
50
+ }
51
+ function handleMouseUp() {
52
+ stopPanning();
53
+ }
54
+ function handleKeyDownCapture(event) {
55
+ if (event.code !== 'Space' || isTypingTarget(event.target))
56
+ return;
57
+ // Space on a focused block would select it; here it is the key that grabs the canvas
58
+ event.preventDefault();
59
+ event.stopPropagation();
60
+ if (event.repeat || isSpaceHeld)
61
+ return;
62
+ isSpaceHeld = true;
63
+ wrapper.setAttribute('data-space-held', 'true');
64
+ }
65
+ // Heard on the window, not on the canvas: the key may be let go after the focus has moved to something else.
66
+ function handleKeyUp(event) {
67
+ if (event.code !== 'Space')
68
+ return;
69
+ releaseSpace();
70
+ }
71
+ function handleMouseDownCapture(event) {
72
+ if (!isSpaceHeld || event.button !== 0)
73
+ return;
74
+ const target = event.target instanceof Element ? event.target : null;
75
+ // A press on a connection point still draws a line; Space only grabs what is not one
76
+ if (target?.closest('[data-handle-id]'))
77
+ return;
78
+ event.preventDefault();
79
+ event.stopPropagation();
80
+ wrapper.querySelector('.kaykay-canvas')?.focus({ preventScroll: true });
81
+ lastPointer = { clientX: event.clientX, clientY: event.clientY };
82
+ wrapper.setAttribute('data-panning', 'true');
83
+ window.addEventListener('mousemove', handleMouseMove);
84
+ window.addEventListener('mouseup', handleMouseUp);
85
+ }
86
+ // The window may lose the keyboard while Space is down (another tab): the key is not held any more then
87
+ function handleWindowBlur() {
88
+ releaseSpace();
89
+ stopPanning();
90
+ }
91
+ wrapper.addEventListener('keydown', handleKeyDownCapture, true);
92
+ wrapper.addEventListener('mousedown', handleMouseDownCapture, true);
93
+ window.addEventListener('keyup', handleKeyUp);
94
+ window.addEventListener('blur', handleWindowBlur);
95
+ return () => {
96
+ wrapper.removeEventListener('keydown', handleKeyDownCapture, true);
97
+ wrapper.removeEventListener('mousedown', handleMouseDownCapture, true);
98
+ window.removeEventListener('keyup', handleKeyUp);
99
+ window.removeEventListener('blur', handleWindowBlur);
100
+ releaseSpace();
101
+ stopPanning();
102
+ };
103
+ }
@@ -4,29 +4,53 @@
4
4
  The canvas gives the editor a handle once it is on the screen; the editor uses it to apply changes made in the panel
5
5
  and the menu, so those are steps that Undo takes back like a drag. What the blocks need to say in words, and the marks
6
6
  on them (the start, problems, where the test visitor is), come from here.
7
+
8
+ A right click on the canvas opens the canvas menu (copy, cut, paste, duplicate, select all, delete, organise, disconnect);
9
+ the canvas says where it was asked and this runs the row that is chosen, through the same editor methods as the shortcuts.
7
10
  -->
8
11
  <script lang="ts">
9
12
  import type { NodeStatus } from 'kaykay';
13
+ import type { NodePosition } from '@widgetic/workflows-engine';
10
14
  import type { CanvasContext, CanvasMarks } from '../../editor/canvasContext.js';
15
+ import type {
16
+ CanvasMenuAction,
17
+ CanvasMenuRequest,
18
+ CanvasMenuState,
19
+ ClipboardCommand
20
+ } from '../../editor/canvasMenu.js';
11
21
  import { makeCanvasWords } from '../../editor/canvasWords.js';
12
22
  import { useEditorState } from '../../editor/editorState.svelte.js';
13
23
  import { useWorkflowsLanguage } from '../../i18n/language.js';
24
+ import { workflowsError } from '../../utils/logger.js';
14
25
  import { Button } from '@widgetic/design-system/components';
15
26
  import { dsButtonVariant } from '../ui/dsButtonProps.js';
27
+ import CanvasContextMenu from '../canvas/CanvasContextMenu.svelte';
16
28
  import CanvasToolbar from '../canvas/CanvasToolbar.svelte';
17
29
  import WorkflowCanvas from '../canvas/WorkflowCanvas.svelte';
18
30
  import SidePanel from '../panel/SidePanel.svelte';
19
31
  import WorkflowAssistantPanel from '../assistant/WorkflowAssistantPanel.svelte';
32
+ import type { ReadyAssistantSeed } from '../../assistant/assistantSeed.js';
20
33
  import type { WorkflowAssistantConfig } from '../../assistant/types.js';
21
34
 
22
35
  interface Props {
23
36
  workflowId: string;
24
37
  assistant?: WorkflowAssistantConfig | null;
38
+ /** The first message the page left waiting for the assistant: written to its composer when the panel is drawn. */
39
+ assistantSeed?: ReadyAssistantSeed | null;
40
+ /** The panel took the seed in (or left it alone because the person had begun). */
41
+ onAssistantSeedApplied?: () => void;
25
42
  assistantOpen?: boolean;
26
43
  onOpenAssistant?: () => void;
27
44
  }
28
45
 
29
- let { workflowId, assistant = null, assistantOpen = false, onOpenAssistant }: Props = $props();
46
+ let {
47
+ workflowId,
48
+ assistant = null,
49
+ assistantSeed = null,
50
+ onAssistantSeedApplied,
51
+ assistantOpen = false,
52
+ onOpenAssistant
53
+ }: Props = $props();
30
54
 
31
55
  const editor = useEditorState();
32
56
 
@@ -79,6 +103,57 @@
79
103
  if (testNodeId) result[testNodeId] = 'running';
80
104
  return result;
81
105
  });
106
+
107
+ // ---- the canvas menu and the clipboard shortcuts ------------------------------------------------------------------
108
+
109
+ /** The box the menu is drawn into: the canvas surface. */
110
+ let surfaceElement = $state<HTMLDivElement>();
111
+
112
+ /** Where the menu is open and what it is on; `null` while it is closed. */
113
+ let menuRequest = $state<CanvasMenuRequest | null>(null);
114
+
115
+ /** What decides which rows of the menu can act. */
116
+ const menuState = $derived<CanvasMenuState>({
117
+ hasSelection: editor.selectedNodeIds.length > 0,
118
+ canPaste: editor.canPaste,
119
+ blockCount: editor.graph.nodes.length,
120
+ connectionCount: editor.graph.edges.length
121
+ });
122
+
123
+ // A canvas that can no longer be changed (a version is opened, the draft is archived) has no menu to leave open
124
+ $effect(() => {
125
+ if (!editor.canEditCanvas) menuRequest = null;
126
+ });
127
+
128
+ /** Cmd or Ctrl with C, X, V or D on the canvas. `at` is where the pointer is, for a paste. */
129
+ function runClipboardShortcut(command: ClipboardCommand, at: NodePosition | null): void {
130
+ menuRequest = null;
131
+ try {
132
+ if (command === 'copy') editor.copySelected();
133
+ else if (command === 'cut') editor.cutSelected();
134
+ else if (command === 'paste') editor.pasteClipboard(at ?? undefined);
135
+ else editor.duplicateSelected();
136
+ } catch (error) {
137
+ workflowsError('The clipboard shortcut could not be run.', error);
138
+ }
139
+ }
140
+
141
+ /** A row of the menu was chosen: the menu closes, and the editor does the work as one step. */
142
+ function runMenuAction(action: CanvasMenuAction, request: CanvasMenuRequest): void {
143
+ menuRequest = null;
144
+ try {
145
+ if (action === 'cut') editor.cutSelected();
146
+ else if (action === 'copy') editor.copySelected();
147
+ else if (action === 'paste') editor.pasteClipboard(request.canvasPoint);
148
+ else if (action === 'duplicate') editor.duplicateSelected();
149
+ else if (action === 'selectAll') editor.selectAllBlocks();
150
+ else if (action === 'delete') editor.removeSelected();
151
+ else if (action === 'organise') editor.organise();
152
+ else editor.disconnectAll();
153
+ } catch (error) {
154
+ workflowsError(`The canvas menu could not run "${action}".`, error);
155
+ }
156
+ }
82
157
  </script>
83
158
 
84
159
  <div
@@ -86,7 +161,10 @@
86
161
  >
87
162
  <div class="relative min-h-80 min-w-0 flex-1 @3xl:min-h-0">
88
163
  <!-- Canvas surface: muted, clipped; toolbar is the only floating shadow (see CanvasToolbar). -->
89
- <div class="relative h-full min-h-0 w-full overflow-hidden rounded-xl bg-muted">
164
+ <div
165
+ bind:this={surfaceElement}
166
+ class="relative h-full min-h-0 w-full overflow-hidden rounded-xl bg-muted"
167
+ >
90
168
  <WorkflowCanvas
91
169
  initialGraph={editor.graph}
92
170
  readContext={() => context}
@@ -95,6 +173,9 @@
95
173
  onGraphChange={(graph) => editor.acceptCanvasGraph(graph)}
96
174
  onSelectionChange={(nodeIds, edgeIds) => editor.followSelection(nodeIds, edgeIds)}
97
175
  onAddBlockShortcut={() => toolbar?.openAddBlock()}
176
+ onClipboardShortcut={runClipboardShortcut}
177
+ onContextMenuRequest={(request) => (menuRequest = request)}
178
+ onCopyRefused={(refusal) => editor.reportCopyRefusal(refusal)}
98
179
  onViewportChange={(viewport) => {
99
180
  canvasZoom = viewport.zoom;
100
181
  editor.followViewport({
@@ -110,6 +191,13 @@
110
191
  }}
111
192
  />
112
193
  <CanvasToolbar bind:this={toolbar} canEdit={!editor.isReadOnly} zoomLevel={canvasZoom} />
194
+ <CanvasContextMenu
195
+ request={menuRequest}
196
+ container={surfaceElement ?? null}
197
+ {menuState}
198
+ onChoose={runMenuAction}
199
+ onClose={() => (menuRequest = null)}
200
+ />
113
201
  {#if showEmptyAssistantEntry}
114
202
  <div
115
203
  class="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center"
@@ -117,9 +205,10 @@
117
205
  >
118
206
  <p class="text-body text-muted-foreground">{$t('workflows.assistant.emptyCanvas')}</p>
119
207
  {#if onOpenAssistant}
208
+ <!-- Secondary: the Publish button in the header is the one main (primary) button of the screen. -->
120
209
  <Button
121
210
  class="pointer-events-auto"
122
- variant={dsButtonVariant('primary')}
211
+ variant={dsButtonVariant('secondary')}
123
212
  size="sm"
124
213
  onclick={onOpenAssistant}
125
214
  >
@@ -138,7 +227,12 @@
138
227
  {/if}
139
228
  {#if showAssistant && assistant}
140
229
  <div class="min-h-0 w-full shrink-0 @3xl:w-80 @3xl:shrink-0">
141
- <WorkflowAssistantPanel {workflowId} config={assistant} />
230
+ <WorkflowAssistantPanel
231
+ {workflowId}
232
+ config={assistant}
233
+ seed={assistantSeed}
234
+ onseedapplied={onAssistantSeedApplied}
235
+ />
142
236
  </div>
143
237
  {/if}
144
238
  </div>
@@ -1,7 +1,12 @@
1
+ import type { ReadyAssistantSeed } from '../../assistant/assistantSeed.js';
1
2
  import type { WorkflowAssistantConfig } from '../../assistant/types.js';
2
3
  interface Props {
3
4
  workflowId: string;
4
5
  assistant?: WorkflowAssistantConfig | null;
6
+ /** The first message the page left waiting for the assistant: written to its composer when the panel is drawn. */
7
+ assistantSeed?: ReadyAssistantSeed | null;
8
+ /** The panel took the seed in (or left it alone because the person had begun). */
9
+ onAssistantSeedApplied?: () => void;
5
10
  assistantOpen?: boolean;
6
11
  onOpenAssistant?: () => void;
7
12
  }
@@ -42,6 +42,8 @@
42
42
  const editor = useEditorState();
43
43
  const { t } = useWorkflowsLanguage();
44
44
 
45
+ let isRenamingTitle = $state(false);
46
+
45
47
  const SAVE_STATE_KEYS = {
46
48
  saved: 'workflows.save.saved',
47
49
  pending: 'workflows.save.pending',
@@ -84,6 +86,15 @@
84
86
 
85
87
  const moreMenuGroups = $derived.by((): readonly MenuGroup[] => {
86
88
  const items: MenuItem[] = [];
89
+ if (assistantEnabled && onToggleAssistant) {
90
+ items.push({
91
+ key: 'assistant',
92
+ label: $t('workflows.assistant.toolbarButton'),
93
+ icon: 'chat',
94
+ disabled: editor.tab !== 'editor',
95
+ onSelect: onToggleAssistant
96
+ });
97
+ }
87
98
  items.push({
88
99
  key: 'test',
89
100
  label: $t('workflows.top.testRun'),
@@ -122,9 +133,8 @@
122
133
  data-workflows-editor-top-bar
123
134
  >
124
135
  <div class="flex w-full min-w-0 flex-wrap items-center gap-3 @3xl:flex-nowrap @3xl:gap-4">
125
- <!-- Narrow: back, name (flex-1), status, more menu -->
126
136
  <div
127
- class="flex min-w-0 w-full flex-1 items-center gap-3 @3xl:w-auto @3xl:max-w-none @3xl:flex-none"
137
+ class="flex min-w-0 w-full flex-1 items-center gap-3 @3xl:w-auto @3xl:max-w-none @3xl:flex-1"
128
138
  >
129
139
  <IconButton
130
140
  variant={dsIconButtonVariant('ghost')}
@@ -135,17 +145,34 @@
135
145
  >
136
146
  <Icon name="back" class="size-4 rtl:rotate-180" />
137
147
  </IconButton>
138
- <div class="min-w-0 max-w-full flex-1 @3xl:w-60 @3xl:flex-none">
148
+ <div class="flex min-w-0 flex-1 items-center gap-1.5" data-workflows-editor-title-group>
139
149
  <WorkflowNameControl
140
150
  name={editor.name}
141
151
  label={$t('workflows.top.renameLabel')}
142
152
  readonly={editor.isReadOnly}
143
153
  maxlength={MAX_WORKFLOW_NAME_LENGTH}
154
+ bind:isEditing={isRenamingTitle}
144
155
  oncommit={(name) => editor.setName(name)}
145
156
  />
146
- </div>
147
- <div class="flex min-w-0 shrink-0 flex-col gap-1 @3xl:hidden" data-workflows-editor-status>
148
- <StatusBadge status={editor.status} />
157
+ <div class="flex shrink-0 items-center gap-1.5" data-workflows-editor-status>
158
+ <StatusBadge status={editor.status} />
159
+ </div>
160
+ <div
161
+ class="hidden min-w-0 shrink-0 items-center gap-1.5 @3xl:flex"
162
+ data-workflows-editor-save
163
+ >
164
+ <Icon
165
+ name={saveIcon}
166
+ class="size-4 shrink-0 {saveIcon === 'loader'
167
+ ? 'motion-safe:animate-spin'
168
+ : ''} {saveCaptionClass}"
169
+ />
170
+ <span
171
+ class="text-caption whitespace-nowrap {saveCaptionClass}"
172
+ role="status"
173
+ aria-live="polite">{$t(SAVE_STATE_KEYS[editor.saveState])}</span
174
+ >
175
+ </div>
149
176
  </div>
150
177
  <div class="ms-auto flex items-center @3xl:hidden">
151
178
  <Menu
@@ -160,44 +187,9 @@
160
187
  </div>
161
188
  </div>
162
189
 
163
- <!-- Desktop: status column -->
164
- <div
165
- class="hidden min-w-0 flex-col gap-1 @3xl:flex @3xl:w-auto @3xl:shrink-0"
166
- data-workflows-editor-status-desktop
167
- >
168
- <StatusBadge status={editor.status} />
169
- </div>
170
-
171
- <div
172
- class="hidden w-full min-w-0 items-center gap-1.5 @3xl:flex @3xl:w-auto @3xl:shrink-0"
173
- data-workflows-editor-save
174
- >
175
- <Icon
176
- name={saveIcon}
177
- class="size-4 shrink-0 {saveIcon === 'loader'
178
- ? 'motion-safe:animate-spin'
179
- : ''} {saveCaptionClass}"
180
- />
181
- <span class="text-caption {saveCaptionClass}" role="status" aria-live="polite"
182
- >{$t(SAVE_STATE_KEYS[editor.saveState])}</span
183
- >
184
- </div>
185
-
186
190
  <div class="hidden min-w-0 flex-1 @3xl:block"></div>
187
191
 
188
192
  <div class="hidden w-full flex-wrap items-center justify-end gap-2 @3xl:flex @3xl:w-auto">
189
- {#if assistantEnabled && onToggleAssistant}
190
- <Button
191
- variant="outline"
192
- size={dsButtonSize('small')}
193
- aria-pressed={assistantOpen}
194
- class={assistantOpen ? 'bg-accent' : ''}
195
- disabled={editor.tab !== 'editor'}
196
- onclick={onToggleAssistant}
197
- >
198
- {$t('workflows.assistant.toolbarButton')}
199
- </Button>
200
- {/if}
201
193
  <Button
202
194
  variant="outline"
203
195
  size={dsButtonSize('small')}
@@ -221,6 +213,21 @@
221
213
  >
222
214
  <Icon name="history" />
223
215
  </IconButton>
216
+ {#if assistantEnabled && onToggleAssistant}
217
+ <IconButton
218
+ variant={dsIconButtonVariant('ghost')}
219
+ size={dsButtonSize('small')}
220
+ aria-pressed={assistantOpen}
221
+ class={assistantOpen ? 'bg-accent' : ''}
222
+ disabled={editor.tab !== 'editor'}
223
+ label={$t('workflows.assistant.toolbarButton')}
224
+ title={$t('workflows.assistant.toolbarButton')}
225
+ data-workflows-assistant-toggle
226
+ onclick={onToggleAssistant}
227
+ >
228
+ <Icon name="chat" />
229
+ </IconButton>
230
+ {/if}
224
231
  {#if onshowembedcode && editor.workflow?.everPublished}
225
232
  <IconButton
226
233
  variant={dsIconButtonVariant('ghost')}
@@ -232,7 +239,11 @@
232
239
  <Icon name="code" />
233
240
  </IconButton>
234
241
  {/if}
235
- <Button variant={dsButtonVariant("primary")} disabled={!editor.canTryPublish} onclick={onpublish}>
242
+ <Button
243
+ variant={dsButtonVariant('primary')}
244
+ disabled={!editor.canTryPublish}
245
+ onclick={onpublish}
246
+ >
236
247
  {$t(publishLabelKey)}
237
248
  </Button>
238
249
  </div>