@widgetic/workflows 0.2.14 → 0.2.16
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/README.md +117 -3
- package/dist/api/types.d.ts +17 -0
- package/dist/api/workflowsApi.d.ts +12 -1
- package/dist/api/workflowsApi.js +37 -0
- package/dist/assistant/assistantEvents.d.ts +44 -2
- package/dist/assistant/assistantEvents.js +58 -2
- package/dist/assistant/assistantReferences.d.ts +66 -0
- package/dist/assistant/assistantReferences.js +109 -0
- package/dist/assistant/assistantSaveMode.d.ts +15 -3
- package/dist/assistant/assistantSaveMode.js +16 -2
- package/dist/assistant/assistantSeed.d.ts +55 -0
- package/dist/assistant/assistantSeed.js +90 -0
- package/dist/assistant/assistantStream.js +81 -3
- package/dist/assistant/assistantSuggest.d.ts +18 -0
- package/dist/assistant/assistantSuggest.js +21 -0
- package/dist/assistant/assistantTurns.d.ts +75 -0
- package/dist/assistant/assistantTurns.js +56 -0
- package/dist/assistant/attachmentUploads.d.ts +42 -0
- package/dist/assistant/attachmentUploads.js +69 -0
- package/dist/assistant/canvasLink.d.ts +30 -0
- package/dist/assistant/canvasLink.js +51 -0
- package/dist/assistant/compositionMention.d.ts +18 -0
- package/dist/assistant/compositionMention.js +47 -0
- package/dist/assistant/liveData.d.ts +150 -0
- package/dist/assistant/liveData.js +286 -0
- package/dist/assistant/mcpMention.d.ts +20 -0
- package/dist/assistant/mcpMention.js +30 -0
- package/dist/assistant/mentionEntries.d.ts +39 -0
- package/dist/assistant/mentionEntries.js +69 -0
- package/dist/assistant/planFlow.d.ts +26 -0
- package/dist/assistant/planFlow.js +57 -0
- package/dist/assistant/templateDestinations.d.ts +37 -0
- package/dist/assistant/templateDestinations.js +64 -0
- package/dist/assistant/types.d.ts +99 -2
- package/dist/assistant/workflowPlanViewModel.d.ts +13 -2
- package/dist/assistant/workflowPlanViewModel.js +9 -1
- package/dist/components/Workflows.svelte +7 -1
- package/dist/components/WorkflowsWorkspace.svelte +29 -1
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +3 -0
- package/dist/components/assistant/AssistantPlanStepRow.svelte +56 -0
- package/dist/components/assistant/AssistantPlanStepRow.svelte.d.ts +9 -0
- package/dist/components/assistant/CompositionMentionMenu.svelte +135 -0
- package/dist/components/assistant/CompositionMentionMenu.svelte.d.ts +9 -0
- package/dist/components/assistant/DataPreviewCard.svelte +108 -0
- package/dist/components/assistant/DataPreviewCard.svelte.d.ts +7 -0
- package/dist/components/assistant/PlanBindingsBlock.svelte +200 -0
- package/dist/components/assistant/PlanBindingsBlock.svelte.d.ts +14 -0
- package/dist/components/assistant/TemplateProjectCard.svelte +81 -0
- package/dist/components/assistant/TemplateProjectCard.svelte.d.ts +14 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +1045 -147
- package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasContextMenu.svelte +199 -0
- package/dist/components/canvas/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/canvas/CompositionNodeView.svelte +7 -2
- package/dist/components/canvas/ConditionNodeView.svelte +5 -1
- package/dist/components/canvas/HandlePoint.svelte +25 -3
- package/dist/components/canvas/WorkflowCanvas.svelte +351 -12
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +12 -1
- package/dist/components/canvas/altDragDuplicateController.d.ts +29 -0
- package/dist/components/canvas/altDragDuplicateController.js +92 -0
- package/dist/components/canvas/connectionSnapController.d.ts +29 -0
- package/dist/components/canvas/connectionSnapController.js +182 -0
- package/dist/components/canvas/spacePanController.d.ts +16 -0
- package/dist/components/canvas/spacePanController.js +103 -0
- package/dist/components/editor/EditorCanvasArea.svelte +98 -4
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +5 -0
- package/dist/components/editor/EditorLoadFailure.svelte +53 -0
- package/dist/components/editor/EditorLoadFailure.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +53 -42
- package/dist/components/editor/WorkflowEditor.svelte +74 -50
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
- package/dist/components/editor/WorkflowNameControl.svelte +9 -8
- package/dist/components/editor/WorkflowNameControl.svelte.d.ts +3 -1
- package/dist/components/list/WorkflowList.svelte +43 -41
- package/dist/components/list/WorkflowList.svelte.d.ts +5 -0
- package/dist/components/panel/CompositionForm.svelte +3 -2
- package/dist/components/panel/CompositionPicker.svelte +25 -23
- package/dist/components/panel/CompositionPicker.svelte.d.ts +2 -2
- package/dist/components/panel/CompositionSelect.svelte +4 -4
- package/dist/components/panel/CompositionSelect.svelte.d.ts +2 -2
- package/dist/components/ui/ErrorState.svelte +43 -0
- package/dist/components/ui/ErrorState.svelte.d.ts +13 -0
- package/dist/components/ui/icons.d.ts +8 -0
- package/dist/components/ui/icons.js +24 -1
- package/dist/editor/apiErrorText.d.ts +2 -0
- package/dist/editor/apiErrorText.js +15 -0
- package/dist/editor/autoLayout.d.ts +38 -0
- package/dist/editor/autoLayout.js +403 -0
- package/dist/editor/blockClipboard.svelte.d.ts +9 -0
- package/dist/editor/blockClipboard.svelte.js +24 -0
- package/dist/editor/blockCopy.d.ts +39 -0
- package/dist/editor/blockCopy.js +137 -0
- package/dist/editor/canvasMenu.d.ts +45 -0
- package/dist/editor/canvasMenu.js +68 -0
- package/dist/editor/connectionSnap.d.ts +90 -0
- package/dist/editor/connectionSnap.js +98 -0
- package/dist/editor/editorState.svelte.d.ts +122 -13
- package/dist/editor/editorState.svelte.js +262 -22
- package/dist/editor/graphIssues.d.ts +5 -0
- package/dist/editor/graphIssues.js +18 -0
- package/dist/editor/graphModel.d.ts +6 -1
- package/dist/editor/graphModel.js +8 -1
- package/dist/editor/keyHints.d.ts +21 -0
- package/dist/editor/keyHints.js +30 -0
- package/dist/editor/listState.svelte.d.ts +4 -4
- package/dist/editor/listState.svelte.js +3 -1
- package/dist/editor/staleGuard.d.ts +111 -0
- package/dist/editor/staleGuard.js +279 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +85 -1
- package/dist/i18n/messages.js +99 -4
- package/dist/index.d.ts +1 -0
- package/dist/types/index.d.ts +19 -2
- 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 {
|
|
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
|
|
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('
|
|
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
|
|
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
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What the open workflow's screen shows when the workflow could not be read: the design's Error State (Figma "Error State",
|
|
3
|
+
component set 139:2) in the middle of the space the editor has, with the reason under the title.
|
|
4
|
+
|
|
5
|
+
The way on depends on the reason. A failure that can pass (offline, too slow, a server that had a problem) has "Try again" as
|
|
6
|
+
the one primary action, with the way back to the list beside it as a quiet outline button. A workflow that is not there (it
|
|
7
|
+
was deleted, or the address is not right), a plan without workflows and an ended session stay the same however often the
|
|
8
|
+
request is repeated, so "Try again" is not offered, and the way back to the list is the one primary action.
|
|
9
|
+
|
|
10
|
+
The screen only shows and asks; reading again is the editor's (`load`), and leaving is the page's (`onback`).
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
14
|
+
import { isRetryableFailure } from '../../editor/apiErrorText.js';
|
|
15
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
16
|
+
import { Button } from '@widgetic/design-system/components';
|
|
17
|
+
import { dsButtonVariant } from '../ui/dsButtonProps.js';
|
|
18
|
+
import ErrorState from '../ui/ErrorState.svelte';
|
|
19
|
+
import Icon from '../ui/Icon.svelte';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
/** The person is done with this workflow: back to the list. */
|
|
23
|
+
onback: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let { onback }: Props = $props();
|
|
27
|
+
|
|
28
|
+
const editor = useEditorState();
|
|
29
|
+
const { t } = useWorkflowsLanguage();
|
|
30
|
+
|
|
31
|
+
// The reason in words, as the editor put it when the request failed (the generic line for a failure it did not name).
|
|
32
|
+
const failureKey = $derived(editor.loadFailure ?? 'workflows.error.generic');
|
|
33
|
+
const canTryAgain = $derived(isRetryableFailure(failureKey));
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<ErrorState title={$t('workflows.error.openTitle')} description={$t(failureKey)}>
|
|
37
|
+
{#snippet actions()}
|
|
38
|
+
{#if canTryAgain}
|
|
39
|
+
<Button variant={dsButtonVariant('primary')} onclick={() => void editor.load()}>
|
|
40
|
+
<Icon name="refresh" class="size-4" />
|
|
41
|
+
{$t('workflows.error.retry')}
|
|
42
|
+
</Button>
|
|
43
|
+
<Button variant={dsButtonVariant('outline')} onclick={onback}
|
|
44
|
+
>{$t('workflows.top.back')}</Button
|
|
45
|
+
>
|
|
46
|
+
{:else}
|
|
47
|
+
<Button variant={dsButtonVariant('primary')} onclick={onback}>
|
|
48
|
+
<Icon name="back" class="size-4 rtl:rotate-180" />
|
|
49
|
+
{$t('workflows.top.back')}
|
|
50
|
+
</Button>
|
|
51
|
+
{/if}
|
|
52
|
+
{/snippet}
|
|
53
|
+
</ErrorState>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The person is done with this workflow: back to the list. */
|
|
3
|
+
onback: () => void;
|
|
4
|
+
}
|
|
5
|
+
declare const EditorLoadFailure: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type EditorLoadFailure = ReturnType<typeof EditorLoadFailure>;
|
|
7
|
+
export default EditorLoadFailure;
|