@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,45 @@
1
+ import type { NodePosition } from '@widgetic/workflows-engine';
2
+ import type { WorkflowsMessageKey } from '../i18n/messages.js';
3
+ import type { Chord } from './keyHints.js';
4
+ /**
5
+ * The menu a right click opens on the canvas: which rows it has for a block and for the empty canvas, in which groups, and
6
+ * which of them can act now. Plain data, so the rows are tested as that and the component only draws them.
7
+ *
8
+ * It has the rows of the Widgetic canvas's menu that a workflow has something to do with (Cut, Copy, Paste, Duplicate, Select
9
+ * all, Delete), and two of its own for the lines (Organise, Disconnect). Group, Ungroup and Layer order are not here: the
10
+ * blocks of a workflow are not stacked or grouped, they are joined.
11
+ */
12
+ /** A shortcut of the clipboard, pressed on the canvas. */
13
+ export type ClipboardCommand = 'copy' | 'cut' | 'paste' | 'duplicate';
14
+ /** What the canvas tells the screen when a right click asks for the menu. */
15
+ export interface CanvasMenuRequest {
16
+ /** Where the pointer was, in pixels of the page (the menu opens there). */
17
+ clientX: number;
18
+ clientY: number;
19
+ /** A right click on a block selects it first (unless it is selected) and opens the menu of blocks. */
20
+ target: 'block' | 'pane';
21
+ nodeId: string | null;
22
+ /** Where the right click was on the canvas, in canvas units (a paste goes there). */
23
+ canvasPoint: NodePosition;
24
+ }
25
+ export type CanvasMenuAction = 'cut' | 'copy' | 'paste' | 'duplicate' | 'selectAll' | 'delete' | 'organise' | 'disconnect';
26
+ export interface CanvasMenuRow {
27
+ action: CanvasMenuAction;
28
+ messageKey: WorkflowsMessageKey;
29
+ chord?: Chord;
30
+ /** A row that can act on what is selected only; shown dimmed otherwise, and it does nothing. */
31
+ disabled: boolean;
32
+ /** In the colour of a destructive action. */
33
+ isDestructive: boolean;
34
+ }
35
+ /** What decides which rows can act. */
36
+ export interface CanvasMenuState {
37
+ /** At least one block is selected. */
38
+ hasSelection: boolean;
39
+ /** Copy or Cut put something aside, and the draft can be changed. */
40
+ canPaste: boolean;
41
+ blockCount: number;
42
+ connectionCount: number;
43
+ }
44
+ /** The groups of rows of the menu for this target, each row with whether it can act now. */
45
+ export declare function buildCanvasMenu(target: CanvasMenuRequest['target'], state: CanvasMenuState): CanvasMenuRow[][];
@@ -0,0 +1,68 @@
1
+ const ROWS = {
2
+ cut: {
3
+ action: 'cut',
4
+ messageKey: 'workflows.canvasMenu.cut',
5
+ chord: { mod: true, key: 'X' },
6
+ isDestructive: false,
7
+ isEnabled: (state) => state.hasSelection
8
+ },
9
+ copy: {
10
+ action: 'copy',
11
+ messageKey: 'workflows.canvasMenu.copy',
12
+ chord: { mod: true, key: 'C' },
13
+ isDestructive: false,
14
+ isEnabled: (state) => state.hasSelection
15
+ },
16
+ paste: {
17
+ action: 'paste',
18
+ messageKey: 'workflows.canvasMenu.paste',
19
+ chord: { mod: true, key: 'V' },
20
+ isDestructive: false,
21
+ isEnabled: (state) => state.canPaste
22
+ },
23
+ duplicate: {
24
+ action: 'duplicate',
25
+ messageKey: 'workflows.canvasMenu.duplicate',
26
+ chord: { mod: true, key: 'D' },
27
+ isDestructive: false,
28
+ isEnabled: (state) => state.hasSelection
29
+ },
30
+ selectAll: {
31
+ action: 'selectAll',
32
+ messageKey: 'workflows.canvasMenu.selectAll',
33
+ chord: { mod: true, key: 'A' },
34
+ isDestructive: false,
35
+ isEnabled: (state) => state.blockCount > 0
36
+ },
37
+ delete: {
38
+ action: 'delete',
39
+ messageKey: 'workflows.canvasMenu.delete',
40
+ isDestructive: true,
41
+ isEnabled: (state) => state.hasSelection
42
+ },
43
+ // With one block there is nothing to put in order
44
+ organise: {
45
+ action: 'organise',
46
+ messageKey: 'workflows.canvasMenu.organise',
47
+ isDestructive: false,
48
+ isEnabled: (state) => state.blockCount > 1
49
+ },
50
+ disconnect: {
51
+ action: 'disconnect',
52
+ messageKey: 'workflows.canvasMenu.disconnect',
53
+ isDestructive: false,
54
+ isEnabled: (state) => state.connectionCount > 0
55
+ }
56
+ };
57
+ /** The rows of each menu, in groups (a thin rule between groups). */
58
+ const MENU_GROUPS = {
59
+ block: [['cut', 'copy', 'paste', 'duplicate'], ['selectAll'], ['delete']],
60
+ pane: [['paste'], ['selectAll'], ['organise', 'disconnect']]
61
+ };
62
+ /** The groups of rows of the menu for this target, each row with whether it can act now. */
63
+ export function buildCanvasMenu(target, state) {
64
+ return MENU_GROUPS[target].map((group) => group.map((action) => {
65
+ const { isEnabled, ...row } = ROWS[action];
66
+ return { ...row, disabled: !isEnabled(state) };
67
+ }));
68
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The magnet of a line that is being drawn: which block's connection point the end of the line snaps to, given where the
3
+ * pointer is. Plain numbers in and out, so it is read and tested as maths; the canvas (`connectionSnapController.ts`) hands
4
+ * it the blocks and uses its answer.
5
+ *
6
+ * How it feels, which is what the numbers below decide:
7
+ * - the line does not have to be dropped on the small circle: coming near a block (anywhere over it, or just outside its
8
+ * edge) is enough, and the end of the line jumps onto the block's point that accepts it;
9
+ * - once snapped, the line stays on the block until the pointer has gone a little further than it took to catch it
10
+ * (`releaseDistance` is larger than `captureDistance`), so a pointer that shakes right at the edge does not make the end of
11
+ * the line flicker; going away lets it go, and coming near again catches it again;
12
+ * - a pointer that is right on a point always means that point;
13
+ * - with two blocks close together the line stays with the one it holds until the other is clearly nearer.
14
+ *
15
+ * Distances are in pixels of the SCREEN, so they feel the same at every zoom; the blocks and the pointer are in canvas units
16
+ * and `zoom` turns one into the other.
17
+ */
18
+ /** A place on the canvas, in canvas units. */
19
+ export interface SnapPoint {
20
+ x: number;
21
+ y: number;
22
+ }
23
+ /** A block's box on the canvas, in canvas units. */
24
+ export interface SnapRectangle {
25
+ x: number;
26
+ y: number;
27
+ width: number;
28
+ height: number;
29
+ }
30
+ /** One place a line could end: a connection point of a block that accepts the line being drawn. */
31
+ export interface SnapCandidate {
32
+ nodeId: string;
33
+ handleId: string;
34
+ /** The block's box. */
35
+ nodeRectangle: SnapRectangle;
36
+ /** The centre of the connection point, where the end of the line goes when it snaps. */
37
+ handlePosition: SnapPoint;
38
+ }
39
+ /** The place the line is snapped to now. */
40
+ export interface HeldSnap {
41
+ nodeId: string;
42
+ handleId: string;
43
+ }
44
+ /**
45
+ * Whether lines snap at all. Set it to `false` and a line follows the pointer exactly and only ends where it is dropped on a
46
+ * connection point, as it did before the magnet was added.
47
+ */
48
+ export declare const CONNECTION_SNAP_ENABLED = true;
49
+ /** How near the pointer must come to a block, measured from the edge of the block (zero over it), for the line to snap to it. */
50
+ export declare const CONNECTION_SNAP_CAPTURE_DISTANCE = 56;
51
+ /**
52
+ * How far the pointer must go from the block the line holds before the line lets go of it. A little more than the capture
53
+ * distance, so that the line does not flicker on and off at the edge of the catching area.
54
+ */
55
+ export declare const CONNECTION_SNAP_RELEASE_DISTANCE = 80;
56
+ /** How much nearer another block must be, to take the line away from the one that holds it. */
57
+ export declare const CONNECTION_SNAP_SWITCH_MARGIN = 24;
58
+ /** A pointer this close to a connection point is on it: the line goes to that point, whatever the blocks around are. */
59
+ export declare const CONNECTION_SNAP_DIRECT_HIT_DISTANCE = 14;
60
+ /** The distances of one choice, in pixels of the screen. */
61
+ export interface SnapDistances {
62
+ captureDistance: number;
63
+ releaseDistance: number;
64
+ switchMargin: number;
65
+ directHitDistance: number;
66
+ }
67
+ export declare const DEFAULT_SNAP_DISTANCES: Readonly<SnapDistances>;
68
+ /** How far a point is from a box: zero when it is inside or on the edge, otherwise the straight distance to the nearest edge. */
69
+ export declare function distanceToRectangle(point: SnapPoint, rectangle: SnapRectangle): number;
70
+ export interface PickSnapTargetInput {
71
+ /** Where the pointer is, in canvas units. */
72
+ pointer: SnapPoint;
73
+ /** The canvas zoom: 1 is the size on the screen, 0.5 is half of it. */
74
+ zoom: number;
75
+ /** The places the line could end (the ones that would refuse it are not in the list). */
76
+ candidates: readonly SnapCandidate[];
77
+ /** What the line is snapped to now, if anything. */
78
+ held?: HeldSnap | null;
79
+ /** `false` turns the magnet off (the answer is always `null`). Defaults to `CONNECTION_SNAP_ENABLED`. */
80
+ enabled?: boolean;
81
+ /** The distances, in pixels of the screen. Defaults to the constants above. */
82
+ distances?: Partial<SnapDistances>;
83
+ }
84
+ /**
85
+ * The connection point the line snaps to, or `null` for a line that follows the pointer.
86
+ *
87
+ * Order of the questions: is the pointer right on a point (that point); does the line hold a point whose block is still near
88
+ * enough (it stays there, unless another block is clearly nearer); otherwise the nearest block within the catching distance.
89
+ */
90
+ export declare function pickSnapTarget(input: PickSnapTargetInput): SnapCandidate | null;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The magnet of a line that is being drawn: which block's connection point the end of the line snaps to, given where the
3
+ * pointer is. Plain numbers in and out, so it is read and tested as maths; the canvas (`connectionSnapController.ts`) hands
4
+ * it the blocks and uses its answer.
5
+ *
6
+ * How it feels, which is what the numbers below decide:
7
+ * - the line does not have to be dropped on the small circle: coming near a block (anywhere over it, or just outside its
8
+ * edge) is enough, and the end of the line jumps onto the block's point that accepts it;
9
+ * - once snapped, the line stays on the block until the pointer has gone a little further than it took to catch it
10
+ * (`releaseDistance` is larger than `captureDistance`), so a pointer that shakes right at the edge does not make the end of
11
+ * the line flicker; going away lets it go, and coming near again catches it again;
12
+ * - a pointer that is right on a point always means that point;
13
+ * - with two blocks close together the line stays with the one it holds until the other is clearly nearer.
14
+ *
15
+ * Distances are in pixels of the SCREEN, so they feel the same at every zoom; the blocks and the pointer are in canvas units
16
+ * and `zoom` turns one into the other.
17
+ */
18
+ /**
19
+ * Whether lines snap at all. Set it to `false` and a line follows the pointer exactly and only ends where it is dropped on a
20
+ * connection point, as it did before the magnet was added.
21
+ */
22
+ export const CONNECTION_SNAP_ENABLED = true;
23
+ /** How near the pointer must come to a block, measured from the edge of the block (zero over it), for the line to snap to it. */
24
+ export const CONNECTION_SNAP_CAPTURE_DISTANCE = 56;
25
+ /**
26
+ * How far the pointer must go from the block the line holds before the line lets go of it. A little more than the capture
27
+ * distance, so that the line does not flicker on and off at the edge of the catching area.
28
+ */
29
+ export const CONNECTION_SNAP_RELEASE_DISTANCE = 80;
30
+ /** How much nearer another block must be, to take the line away from the one that holds it. */
31
+ export const CONNECTION_SNAP_SWITCH_MARGIN = 24;
32
+ /** A pointer this close to a connection point is on it: the line goes to that point, whatever the blocks around are. */
33
+ export const CONNECTION_SNAP_DIRECT_HIT_DISTANCE = 14;
34
+ export const DEFAULT_SNAP_DISTANCES = {
35
+ captureDistance: CONNECTION_SNAP_CAPTURE_DISTANCE,
36
+ releaseDistance: CONNECTION_SNAP_RELEASE_DISTANCE,
37
+ switchMargin: CONNECTION_SNAP_SWITCH_MARGIN,
38
+ directHitDistance: CONNECTION_SNAP_DIRECT_HIT_DISTANCE
39
+ };
40
+ /** How far a point is from a box: zero when it is inside or on the edge, otherwise the straight distance to the nearest edge. */
41
+ export function distanceToRectangle(point, rectangle) {
42
+ const horizontal = Math.max(rectangle.x - point.x, 0, point.x - (rectangle.x + rectangle.width));
43
+ const vertical = Math.max(rectangle.y - point.y, 0, point.y - (rectangle.y + rectangle.height));
44
+ return Math.hypot(horizontal, vertical);
45
+ }
46
+ function isHeld(candidate, held) {
47
+ return held !== null && candidate.nodeId === held.nodeId && candidate.handleId === held.handleId;
48
+ }
49
+ /** The nearest block first; two points of one block (or of blocks equally near) by which is nearer the pointer. */
50
+ function compareByCloseness(left, right) {
51
+ return left.edgeDistance - right.edgeDistance || left.handleDistance - right.handleDistance;
52
+ }
53
+ /**
54
+ * The connection point the line snaps to, or `null` for a line that follows the pointer.
55
+ *
56
+ * Order of the questions: is the pointer right on a point (that point); does the line hold a point whose block is still near
57
+ * enough (it stays there, unless another block is clearly nearer); otherwise the nearest block within the catching distance.
58
+ */
59
+ export function pickSnapTarget(input) {
60
+ const enabled = input.enabled ?? CONNECTION_SNAP_ENABLED;
61
+ if (!enabled || input.candidates.length === 0)
62
+ return null;
63
+ const distances = { ...DEFAULT_SNAP_DISTANCES, ...input.distances };
64
+ // A canvas unit is `zoom` pixels on the screen: distances given in pixels are `1 / zoom` canvas units.
65
+ const unitsPerPixel = input.zoom > 0 && Number.isFinite(input.zoom) ? 1 / input.zoom : 1;
66
+ const captureDistance = distances.captureDistance * unitsPerPixel;
67
+ const releaseDistance = distances.releaseDistance * unitsPerPixel;
68
+ const switchMargin = distances.switchMargin * unitsPerPixel;
69
+ const directHitDistance = distances.directHitDistance * unitsPerPixel;
70
+ const measured = input.candidates.map((candidate) => ({
71
+ candidate,
72
+ edgeDistance: distanceToRectangle(input.pointer, candidate.nodeRectangle),
73
+ handleDistance: Math.hypot(input.pointer.x - candidate.handlePosition.x, input.pointer.y - candidate.handlePosition.y)
74
+ }));
75
+ // A pointer right on a point is on that point, even when it also is over another block.
76
+ const onAPoint = measured
77
+ .filter((entry) => entry.handleDistance <= directHitDistance)
78
+ .sort((left, right) => left.handleDistance - right.handleDistance)[0];
79
+ if (onAPoint)
80
+ return onAPoint.candidate;
81
+ const held = input.held ?? null;
82
+ const heldEntry = held ? measured.find((entry) => isHeld(entry.candidate, held)) : undefined;
83
+ const nearest = measured
84
+ .filter((entry) => entry.edgeDistance <= captureDistance)
85
+ .sort(compareByCloseness)[0];
86
+ if (heldEntry && heldEntry.edgeDistance <= releaseDistance) {
87
+ if (nearest && !isHeld(nearest.candidate, held)) {
88
+ // Another block has to be clearly nearer; another point of the same block has to be clearly nearer to the pointer.
89
+ const isClearlyNearer = nearest.candidate.nodeId === heldEntry.candidate.nodeId
90
+ ? nearest.handleDistance + switchMargin < heldEntry.handleDistance
91
+ : nearest.edgeDistance + switchMargin < heldEntry.edgeDistance;
92
+ if (isClearlyNearer)
93
+ return nearest.candidate;
94
+ }
95
+ return heldEntry.candidate;
96
+ }
97
+ return nearest?.candidate ?? null;
98
+ }