@widgetic/workflows 0.1.1 → 0.2.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.
- package/README.md +107 -46
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +168 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +109 -0
- package/dist/api/workflowsApi.js +657 -0
- package/dist/components/Workflows.svelte +41 -17
- package/dist/components/WorkflowsEmptyState.svelte +16 -5
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
- package/dist/components/WorkflowsHeader.svelte +2 -2
- package/dist/components/WorkflowsWorkspace.svelte +87 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
- package/dist/components/canvas/AddBlockMenu.svelte +101 -0
- package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasToolbar.svelte +95 -0
- package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
- package/dist/components/canvas/CompositionNodeView.svelte +125 -0
- package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/ConditionNodeView.svelte +95 -0
- package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/HandlePoint.svelte +32 -0
- package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
- package/dist/components/canvas/TriggerNodeView.svelte +75 -0
- package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
- package/dist/components/editor/EditorBanners.svelte +143 -0
- package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
- package/dist/components/editor/EditorCanvasArea.svelte +85 -0
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
- package/dist/components/editor/EditorTabs.svelte +81 -0
- package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +132 -0
- package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
- package/dist/components/editor/RunsTab.svelte +256 -0
- package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +180 -0
- package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
- package/dist/components/editor/WorkflowEditor.svelte +185 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.js +0 -2
- package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
- package/dist/components/list/WorkflowList.svelte +204 -0
- package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
- package/dist/components/list/WorkflowRow.svelte +191 -0
- package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
- package/dist/components/panel/BlockProblems.svelte +47 -0
- package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
- package/dist/components/panel/CompositionForm.svelte +127 -0
- package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
- package/dist/components/panel/CompositionPicker.svelte +179 -0
- package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
- package/dist/components/panel/ConditionForm.svelte +105 -0
- package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
- package/dist/components/panel/EventValueRow.svelte +85 -0
- package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
- package/dist/components/panel/NextStepSelect.svelte +70 -0
- package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
- package/dist/components/panel/ProblemsList.svelte +101 -0
- package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
- package/dist/components/panel/RuleCard.svelte +191 -0
- package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
- package/dist/components/panel/SidePanel.svelte +82 -0
- package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestRow.svelte +150 -0
- package/dist/components/panel/TestRow.svelte.d.ts +15 -0
- package/dist/components/panel/TestRunPanel.svelte +85 -0
- package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestTriggerCard.svelte +121 -0
- package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
- package/dist/components/panel/TriggerForm.svelte +385 -0
- package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
- package/dist/components/panel/VersionHistory.svelte +123 -0
- package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
- package/dist/components/ui/ActionButton.svelte +85 -0
- package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
- package/dist/components/ui/ConfirmDialog.svelte +52 -0
- package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
- package/dist/components/ui/Icon.svelte +32 -0
- package/dist/components/ui/Icon.svelte.d.ts +9 -0
- package/dist/components/ui/Menu.svelte +211 -0
- package/dist/components/ui/Menu.svelte.d.ts +21 -0
- package/dist/components/ui/Modal.svelte +129 -0
- package/dist/components/ui/Modal.svelte.d.ts +13 -0
- package/dist/components/ui/Notice.svelte +36 -0
- package/dist/components/ui/Notice.svelte.d.ts +11 -0
- package/dist/components/ui/SelectField.svelte +74 -0
- package/dist/components/ui/SelectField.svelte.d.ts +16 -0
- package/dist/components/ui/StatusBadge.svelte +41 -0
- package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TextField.svelte +97 -0
- package/dist/components/ui/TextField.svelte.d.ts +29 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.js +54 -0
- package/dist/components/ui/types.d.ts +26 -0
- package/dist/components/ui/types.js +1 -0
- package/dist/editor/apiErrorText.d.ts +10 -0
- package/dist/editor/apiErrorText.js +53 -0
- package/dist/editor/autosave.d.ts +47 -0
- package/dist/editor/autosave.js +119 -0
- package/dist/editor/blockLabels.d.ts +91 -0
- package/dist/editor/blockLabels.js +196 -0
- package/dist/editor/canvasContext.d.ts +52 -0
- package/dist/editor/canvasContext.js +37 -0
- package/dist/editor/canvasWords.d.ts +24 -0
- package/dist/editor/canvasWords.js +40 -0
- package/dist/editor/capabilityModel.d.ts +46 -0
- package/dist/editor/capabilityModel.js +113 -0
- package/dist/editor/editorState.svelte.d.ts +220 -0
- package/dist/editor/editorState.svelte.js +713 -0
- package/dist/editor/flowAdapter.d.ts +59 -0
- package/dist/editor/flowAdapter.js +166 -0
- package/dist/editor/formatCount.d.ts +5 -0
- package/dist/editor/formatCount.js +15 -0
- package/dist/editor/graphDiff.d.ts +27 -0
- package/dist/editor/graphDiff.js +64 -0
- package/dist/editor/graphModel.d.ts +154 -0
- package/dist/editor/graphModel.js +457 -0
- package/dist/editor/issueText.d.ts +64 -0
- package/dist/editor/issueText.js +101 -0
- package/dist/editor/listState.svelte.d.ts +82 -0
- package/dist/editor/listState.svelte.js +250 -0
- package/dist/editor/statsRange.d.ts +26 -0
- package/dist/editor/statsRange.js +41 -0
- package/dist/editor/testRun.d.ts +36 -0
- package/dist/editor/testRun.js +74 -0
- package/dist/editor/zonedTime.d.ts +20 -0
- package/dist/editor/zonedTime.js +134 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +396 -4
- package/dist/i18n/messages.js +421 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +31 -3
- package/package.json +5 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { NodePosition, ValidationIssue, WorkflowEdge, WorkflowGraph, WorkflowNode } from '@widgetic/workflows-engine';
|
|
2
|
+
import type { ConnectionValidationContext, ConnectionValidationResultObject, Flow, FlowEdge, FlowNode } from 'kaykay';
|
|
3
|
+
/** The type of the custom line the canvas draws every connection with. */
|
|
4
|
+
export declare const WORKFLOW_EDGE_TYPE = "workflow";
|
|
5
|
+
/** The one place a line comes in, on every kind of block. */
|
|
6
|
+
export declare const INPUT_HANDLE_ID = "in";
|
|
7
|
+
/** The place a line leaves a composition or a trigger from (a condition has one per rule, and `default`). */
|
|
8
|
+
export declare const OUTPUT_HANDLE_ID = "out";
|
|
9
|
+
/** The port types of the canvas: what a handle carries and what an input accepts. */
|
|
10
|
+
export declare const PORT_TYPES: {
|
|
11
|
+
readonly shown: "shown";
|
|
12
|
+
readonly fired: "fired";
|
|
13
|
+
readonly path: "path";
|
|
14
|
+
};
|
|
15
|
+
/** What each kind of block sends out, on every output it has. */
|
|
16
|
+
export declare const OUTPUT_PORT_TYPE: Readonly<Record<WorkflowNode['type'], string>>;
|
|
17
|
+
/** What each kind of block takes in. */
|
|
18
|
+
export declare const INPUT_ACCEPTS: Readonly<Record<WorkflowNode['type'], readonly string[]>>;
|
|
19
|
+
/** What every block of the canvas holds: the engine's block, without its position (the canvas owns that). */
|
|
20
|
+
export interface WorkflowBlockData extends Record<string, unknown> {
|
|
21
|
+
node: WorkflowNode;
|
|
22
|
+
}
|
|
23
|
+
/** Where a block goes when the graph does not say (a graph made by hand, or by a newer editor that did not save positions). */
|
|
24
|
+
export declare function fallbackPositionFor(index: number): NodePosition;
|
|
25
|
+
/** One block as the canvas holds it. */
|
|
26
|
+
export declare function toFlowNode(node: WorkflowNode, fallbackIndex?: number): FlowNode<WorkflowBlockData>;
|
|
27
|
+
/** One connection as the canvas holds it: it leaves the port named by `sourcePort` and comes into the block's one input. */
|
|
28
|
+
export declare function toFlowEdge(edge: WorkflowEdge): FlowEdge;
|
|
29
|
+
/** The whole workflow as the canvas loads it. */
|
|
30
|
+
export declare function graphToFlow(graph: WorkflowGraph): Flow;
|
|
31
|
+
/** The engine's block a canvas block holds, or `undefined` for a block that is not one of ours. */
|
|
32
|
+
export declare function readBlock(flowNode: {
|
|
33
|
+
id: string;
|
|
34
|
+
data: unknown;
|
|
35
|
+
}): WorkflowNode | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The workflow the canvas holds, as the engine reads it: every block with the position the canvas gives it (whole numbers),
|
|
38
|
+
* every connection with the port it leaves from. A block that is not one of ours, and a line to or from one that is gone,
|
|
39
|
+
* are left out.
|
|
40
|
+
*/
|
|
41
|
+
export declare function flowToGraph(flow: Pick<Flow, 'nodes' | 'edges'>): WorkflowGraph;
|
|
42
|
+
/**
|
|
43
|
+
* The function the canvas asks while a line is dragged, for every place it could end, and again when it is dropped. The
|
|
44
|
+
* answer is the engine's, from the workflow as it stands now (`readGraph` is asked every time: the lines change while a
|
|
45
|
+
* person works, and a loop is a path through blocks the canvas does not hand over). The reason of a refusal is the engine's
|
|
46
|
+
* issue code, which the screen says in the person's language.
|
|
47
|
+
*
|
|
48
|
+
* `readMovingEdgeId` is the connection a person is moving by its end (the canvas does not leave it out of what it hands
|
|
49
|
+
* over): it is judged as gone, otherwise moving the end of a trigger's only line would always meet "one next step".
|
|
50
|
+
*/
|
|
51
|
+
export declare function createConnectionValidator(readGraph: () => WorkflowGraph, readMovingEdgeId?: () => string | undefined): (context: ConnectionValidationContext) => ConnectionValidationResultObject;
|
|
52
|
+
/** The issues of a draft, grouped by the block and the connection they belong to, for the marks on the canvas. */
|
|
53
|
+
export interface IssuesOnCanvas {
|
|
54
|
+
byNode: ReadonlyMap<string, readonly ValidationIssue[]>;
|
|
55
|
+
byEdge: ReadonlyMap<string, readonly ValidationIssue[]>;
|
|
56
|
+
/** Issues that belong to no block (no start, too many blocks ...). */
|
|
57
|
+
general: readonly ValidationIssue[];
|
|
58
|
+
}
|
|
59
|
+
export declare function groupIssues(issues: readonly ValidationIssue[]): IssuesOnCanvas;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Between the workflow the engine knows (blocks, connections, rules) and the canvas the editor draws it on (kaykay).
|
|
3
|
+
*
|
|
4
|
+
* The canvas keeps its own state while a person edits (where a block sits, what is selected, the undo history), and every
|
|
5
|
+
* block carries the engine's block as its `data.node`. These functions turn one into the other, in both directions, and
|
|
6
|
+
* ask the engine whether a connection may be drawn. Nothing here draws or touches the page, so it is read and tested as
|
|
7
|
+
* plain TypeScript; the only things taken from kaykay are types.
|
|
8
|
+
*
|
|
9
|
+
* Ports are typed so that the canvas itself greys out the places a line cannot go while one is being dragged:
|
|
10
|
+
* composition ──shown──▶ trigger ──fired──▶ condition | composition
|
|
11
|
+
* condition ──path──▶ condition | composition
|
|
12
|
+
* and the engine has the last word (`checkConnection`): one next step per trigger and per rule, one way into a trigger and
|
|
13
|
+
* a condition, and no loop.
|
|
14
|
+
*/
|
|
15
|
+
import { checkConnection } from '@widgetic/workflows-engine';
|
|
16
|
+
/** The type of the custom line the canvas draws every connection with. */
|
|
17
|
+
export const WORKFLOW_EDGE_TYPE = 'workflow';
|
|
18
|
+
/** The one place a line comes in, on every kind of block. */
|
|
19
|
+
export const INPUT_HANDLE_ID = 'in';
|
|
20
|
+
/** The place a line leaves a composition or a trigger from (a condition has one per rule, and `default`). */
|
|
21
|
+
export const OUTPUT_HANDLE_ID = 'out';
|
|
22
|
+
/** The port types of the canvas: what a handle carries and what an input accepts. */
|
|
23
|
+
export const PORT_TYPES = { shown: 'shown', fired: 'fired', path: 'path' };
|
|
24
|
+
/** What each kind of block sends out, on every output it has. */
|
|
25
|
+
export const OUTPUT_PORT_TYPE = {
|
|
26
|
+
composition: PORT_TYPES.shown,
|
|
27
|
+
trigger: PORT_TYPES.fired,
|
|
28
|
+
condition: PORT_TYPES.path
|
|
29
|
+
};
|
|
30
|
+
/** What each kind of block takes in. */
|
|
31
|
+
export const INPUT_ACCEPTS = {
|
|
32
|
+
composition: [PORT_TYPES.fired, PORT_TYPES.path],
|
|
33
|
+
trigger: [PORT_TYPES.shown],
|
|
34
|
+
condition: [PORT_TYPES.fired, PORT_TYPES.path]
|
|
35
|
+
};
|
|
36
|
+
/** Where a block goes when the graph does not say (a graph made by hand, or by a newer editor that did not save positions). */
|
|
37
|
+
export function fallbackPositionFor(index) {
|
|
38
|
+
return { x: 80 + (index % 4) * 360, y: 120 + Math.floor(index / 4) * 220 };
|
|
39
|
+
}
|
|
40
|
+
function withoutPosition(node) {
|
|
41
|
+
const { position: _position, ...rest } = node;
|
|
42
|
+
return rest;
|
|
43
|
+
}
|
|
44
|
+
/** One block as the canvas holds it. */
|
|
45
|
+
export function toFlowNode(node, fallbackIndex = 0) {
|
|
46
|
+
return {
|
|
47
|
+
id: node.id,
|
|
48
|
+
type: node.type,
|
|
49
|
+
position: node.position
|
|
50
|
+
? { x: node.position.x, y: node.position.y }
|
|
51
|
+
: fallbackPositionFor(fallbackIndex),
|
|
52
|
+
data: { node: withoutPosition(node) }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** One connection as the canvas holds it: it leaves the port named by `sourcePort` and comes into the block's one input. */
|
|
56
|
+
export function toFlowEdge(edge) {
|
|
57
|
+
return {
|
|
58
|
+
id: edge.id,
|
|
59
|
+
source: edge.source,
|
|
60
|
+
source_handle: edge.sourcePort,
|
|
61
|
+
target: edge.target,
|
|
62
|
+
target_handle: INPUT_HANDLE_ID,
|
|
63
|
+
type: WORKFLOW_EDGE_TYPE
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The whole workflow as the canvas loads it. */
|
|
67
|
+
export function graphToFlow(graph) {
|
|
68
|
+
return {
|
|
69
|
+
nodes: graph.nodes.map((node, index) => toFlowNode(node, index)),
|
|
70
|
+
edges: graph.edges.map(toFlowEdge)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function isRecord(value) {
|
|
74
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
/** The engine's block a canvas block holds, or `undefined` for a block that is not one of ours. */
|
|
77
|
+
export function readBlock(flowNode) {
|
|
78
|
+
if (!isRecord(flowNode.data) || !isRecord(flowNode.data.node))
|
|
79
|
+
return undefined;
|
|
80
|
+
const node = flowNode.data.node;
|
|
81
|
+
if (node.type !== 'composition' && node.type !== 'trigger' && node.type !== 'condition')
|
|
82
|
+
return undefined;
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The workflow the canvas holds, as the engine reads it: every block with the position the canvas gives it (whole numbers),
|
|
87
|
+
* every connection with the port it leaves from. A block that is not one of ours, and a line to or from one that is gone,
|
|
88
|
+
* are left out.
|
|
89
|
+
*/
|
|
90
|
+
export function flowToGraph(flow) {
|
|
91
|
+
const nodes = [];
|
|
92
|
+
for (const flowNode of flow.nodes) {
|
|
93
|
+
const node = readBlock(flowNode);
|
|
94
|
+
if (!node)
|
|
95
|
+
continue;
|
|
96
|
+
nodes.push({
|
|
97
|
+
...node,
|
|
98
|
+
id: flowNode.id,
|
|
99
|
+
position: { x: Math.round(flowNode.position.x), y: Math.round(flowNode.position.y) }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const knownIds = new Set(nodes.map((node) => node.id));
|
|
103
|
+
const edges = [];
|
|
104
|
+
for (const flowEdge of flow.edges) {
|
|
105
|
+
if (!knownIds.has(flowEdge.source) || !knownIds.has(flowEdge.target))
|
|
106
|
+
continue;
|
|
107
|
+
edges.push({
|
|
108
|
+
id: flowEdge.id,
|
|
109
|
+
source: flowEdge.source,
|
|
110
|
+
sourcePort: flowEdge.source_handle,
|
|
111
|
+
target: flowEdge.target
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return { schemaVersion: 1, nodes, edges };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The function the canvas asks while a line is dragged, for every place it could end, and again when it is dropped. The
|
|
118
|
+
* answer is the engine's, from the workflow as it stands now (`readGraph` is asked every time: the lines change while a
|
|
119
|
+
* person works, and a loop is a path through blocks the canvas does not hand over). The reason of a refusal is the engine's
|
|
120
|
+
* issue code, which the screen says in the person's language.
|
|
121
|
+
*
|
|
122
|
+
* `readMovingEdgeId` is the connection a person is moving by its end (the canvas does not leave it out of what it hands
|
|
123
|
+
* over): it is judged as gone, otherwise moving the end of a trigger's only line would always meet "one next step".
|
|
124
|
+
*/
|
|
125
|
+
export function createConnectionValidator(readGraph, readMovingEdgeId = () => undefined) {
|
|
126
|
+
return (context) => {
|
|
127
|
+
const movingEdgeId = readMovingEdgeId();
|
|
128
|
+
const graph = readGraph();
|
|
129
|
+
const judgedGraph = movingEdgeId === undefined
|
|
130
|
+
? graph
|
|
131
|
+
: { ...graph, edges: graph.edges.filter((edge) => edge.id !== movingEdgeId) };
|
|
132
|
+
const verdict = checkConnection(judgedGraph, {
|
|
133
|
+
source: context.source_node.id,
|
|
134
|
+
sourcePort: context.source_handle.id,
|
|
135
|
+
target: context.target_node.id
|
|
136
|
+
});
|
|
137
|
+
return verdict.ok
|
|
138
|
+
? { valid: true }
|
|
139
|
+
: { valid: false, reason: verdict.reason };
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function groupIssues(issues) {
|
|
143
|
+
const byNode = new Map();
|
|
144
|
+
const byEdge = new Map();
|
|
145
|
+
const general = [];
|
|
146
|
+
for (const issue of issues) {
|
|
147
|
+
if (issue.nodeId !== undefined) {
|
|
148
|
+
const list = byNode.get(issue.nodeId);
|
|
149
|
+
if (list)
|
|
150
|
+
list.push(issue);
|
|
151
|
+
else
|
|
152
|
+
byNode.set(issue.nodeId, [issue]);
|
|
153
|
+
}
|
|
154
|
+
else if (issue.edgeId !== undefined) {
|
|
155
|
+
const list = byEdge.get(issue.edgeId);
|
|
156
|
+
if (list)
|
|
157
|
+
list.push(issue);
|
|
158
|
+
else
|
|
159
|
+
byEdge.set(issue.edgeId, [issue]);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
general.push(issue);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { byNode, byEdge, general };
|
|
166
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A number of visitors, written the way the person's language writes numbers (`1,234` or `1.234` or `١٬٢٣٤`). A number the
|
|
3
|
+
* browser cannot format in that language is written plainly, so a count is never empty and never throws.
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatCount(count: number, locale: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A number of visitors, written the way the person's language writes numbers (`1,234` or `1.234` or `١٬٢٣٤`). A number the
|
|
3
|
+
* browser cannot format in that language is written plainly, so a count is never empty and never throws.
|
|
4
|
+
*/
|
|
5
|
+
export function formatCount(count, locale) {
|
|
6
|
+
if (!Number.isFinite(count))
|
|
7
|
+
return '0';
|
|
8
|
+
try {
|
|
9
|
+
return new Intl.NumberFormat(locale || undefined).format(count);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// A language tag the browser does not know: say the number in the plain way.
|
|
13
|
+
return String(count);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NodePosition, WorkflowEdge, WorkflowGraph, WorkflowNode } from '@widgetic/workflows-engine';
|
|
2
|
+
/**
|
|
3
|
+
* What it takes to turn the workflow on the canvas into another one: which blocks and connections go, which come, which
|
|
4
|
+
* block's content changed and which only moved. The side panel and the Add block menu work on the engine's graph (plain
|
|
5
|
+
* data), and the canvas has to be told the difference as small operations, so that a person's undo takes one step back
|
|
6
|
+
* and the blocks that did not change are not redrawn.
|
|
7
|
+
*
|
|
8
|
+
* A connection that keeps its id but now leaves from another place, or leads to another block, is a connection that goes
|
|
9
|
+
* and one that comes: the canvas has no "change where it points".
|
|
10
|
+
*/
|
|
11
|
+
export interface GraphDiff {
|
|
12
|
+
removedEdgeIds: string[];
|
|
13
|
+
removedNodeIds: string[];
|
|
14
|
+
addedNodes: WorkflowNode[];
|
|
15
|
+
/** Same block, other content (a composition chosen, a rule added); the position is not content. */
|
|
16
|
+
changedNodes: WorkflowNode[];
|
|
17
|
+
/** Same block, other place. */
|
|
18
|
+
movedNodes: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
position: NodePosition;
|
|
21
|
+
}>;
|
|
22
|
+
addedEdges: WorkflowEdge[];
|
|
23
|
+
/** Nothing to do: the two graphs say the same. */
|
|
24
|
+
isEmpty: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** The difference between two workflows, in the order the canvas should apply it (see {@link GraphDiff}). */
|
|
27
|
+
export declare function diffGraphs(before: WorkflowGraph, after: WorkflowGraph): GraphDiff;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { writeStableJson } from './graphModel.js';
|
|
2
|
+
function withoutPosition(node) {
|
|
3
|
+
const { position: _position, ...rest } = node;
|
|
4
|
+
return rest;
|
|
5
|
+
}
|
|
6
|
+
function isSamePosition(left, right) {
|
|
7
|
+
if (left === undefined || right === undefined)
|
|
8
|
+
return left === right;
|
|
9
|
+
return Math.round(left.x) === Math.round(right.x) && Math.round(left.y) === Math.round(right.y);
|
|
10
|
+
}
|
|
11
|
+
function isSameEdge(left, right) {
|
|
12
|
+
return (left.source === right.source &&
|
|
13
|
+
left.sourcePort === right.sourcePort &&
|
|
14
|
+
left.target === right.target);
|
|
15
|
+
}
|
|
16
|
+
/** The difference between two workflows, in the order the canvas should apply it (see {@link GraphDiff}). */
|
|
17
|
+
export function diffGraphs(before, after) {
|
|
18
|
+
const beforeNodes = new Map(before.nodes.map((node) => [node.id, node]));
|
|
19
|
+
const afterNodes = new Map(after.nodes.map((node) => [node.id, node]));
|
|
20
|
+
const beforeEdges = new Map(before.edges.map((edge) => [edge.id, edge]));
|
|
21
|
+
const afterEdges = new Map(after.edges.map((edge) => [edge.id, edge]));
|
|
22
|
+
const removedNodeIds = before.nodes
|
|
23
|
+
.filter((node) => !afterNodes.has(node.id))
|
|
24
|
+
.map((node) => node.id);
|
|
25
|
+
const addedNodes = after.nodes.filter((node) => !beforeNodes.has(node.id));
|
|
26
|
+
const changedNodes = [];
|
|
27
|
+
const movedNodes = [];
|
|
28
|
+
for (const node of after.nodes) {
|
|
29
|
+
const previous = beforeNodes.get(node.id);
|
|
30
|
+
if (!previous)
|
|
31
|
+
continue;
|
|
32
|
+
if (writeStableJson(withoutPosition(previous)) !== writeStableJson(withoutPosition(node)))
|
|
33
|
+
changedNodes.push(node);
|
|
34
|
+
if (!isSamePosition(previous.position, node.position) && node.position !== undefined) {
|
|
35
|
+
movedNodes.push({ id: node.id, position: node.position });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const removedEdgeIds = [];
|
|
39
|
+
for (const edge of before.edges) {
|
|
40
|
+
const next = afterEdges.get(edge.id);
|
|
41
|
+
if (!next || !isSameEdge(edge, next))
|
|
42
|
+
removedEdgeIds.push(edge.id);
|
|
43
|
+
}
|
|
44
|
+
const addedEdges = [];
|
|
45
|
+
for (const edge of after.edges) {
|
|
46
|
+
const previous = beforeEdges.get(edge.id);
|
|
47
|
+
if (!previous || !isSameEdge(previous, edge))
|
|
48
|
+
addedEdges.push(edge);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
removedEdgeIds,
|
|
52
|
+
removedNodeIds,
|
|
53
|
+
addedNodes,
|
|
54
|
+
changedNodes,
|
|
55
|
+
movedNodes,
|
|
56
|
+
addedEdges,
|
|
57
|
+
isEmpty: removedEdgeIds.length === 0 &&
|
|
58
|
+
removedNodeIds.length === 0 &&
|
|
59
|
+
addedNodes.length === 0 &&
|
|
60
|
+
changedNodes.length === 0 &&
|
|
61
|
+
movedNodes.length === 0 &&
|
|
62
|
+
addedEdges.length === 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { CompositionNode, ConditionCase, ConditionNode, ConditionTest, FieldReference, FieldType, FieldValue, NodePosition, Operator, ScheduleConfig, TriggerConfig, TriggerNode, WorkflowEdge, WorkflowGraph, WorkflowNode } from '@widgetic/workflows-engine';
|
|
2
|
+
/** The three kinds of block, as the Add block menu lists them. */
|
|
3
|
+
export type BlockKind = 'composition' | 'trigger' | 'condition';
|
|
4
|
+
/** What a trigger can wait for. Manual is not one: it is the editor's Test run. */
|
|
5
|
+
export type TriggerKind = TriggerConfig['kind'];
|
|
6
|
+
/** In the order the menu lists them. */
|
|
7
|
+
export declare const TRIGGER_KINDS: readonly TriggerKind[];
|
|
8
|
+
/** How far apart blocks are placed, in canvas units. A composition card is about 240 wide. */
|
|
9
|
+
export declare const BLOCK_SPACING: {
|
|
10
|
+
readonly horizontal: 360;
|
|
11
|
+
readonly vertical: 220;
|
|
12
|
+
};
|
|
13
|
+
/** Where the first block of an empty workflow goes. */
|
|
14
|
+
export declare const FIRST_BLOCK_POSITION: NodePosition;
|
|
15
|
+
/**
|
|
16
|
+
* A new id for a block (`n_`), a connection (`e_`) or a rule (`r_`) that no other has in this graph. The engine accepts
|
|
17
|
+
* letters, digits, `_` and `-` up to 64 characters; these are short so a person who reads an exported graph can follow them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function makeId(prefix: 'n' | 'e' | 'r', takenIds: ReadonlySet<string>, random?: () => number): string;
|
|
20
|
+
/** Every id of a block, a connection and a rule of the graph: what a new id must not be. */
|
|
21
|
+
export declare function collectTakenIds(graph: WorkflowGraph): Set<string>;
|
|
22
|
+
export declare function makeEmptyGraph(): WorkflowGraph;
|
|
23
|
+
/** Whether another block fits (a workflow holds at most 25). */
|
|
24
|
+
export declare function canAddBlock(graph: WorkflowGraph): boolean;
|
|
25
|
+
export declare function makeCompositionBlock(options: {
|
|
26
|
+
id: string;
|
|
27
|
+
compositionId: string;
|
|
28
|
+
position: NodePosition;
|
|
29
|
+
startsHere?: boolean;
|
|
30
|
+
}): CompositionNode;
|
|
31
|
+
/** What a trigger starts as: the kind decides the shape, and the person fills in the rest (an unfinished draft is allowed). */
|
|
32
|
+
export declare function makeTriggerConfig(kind: TriggerKind): TriggerConfig;
|
|
33
|
+
export declare function makeTriggerBlock(options: {
|
|
34
|
+
id: string;
|
|
35
|
+
kind: TriggerKind;
|
|
36
|
+
position: NodePosition;
|
|
37
|
+
}): TriggerNode;
|
|
38
|
+
export declare function makeConditionBlock(options: {
|
|
39
|
+
id: string;
|
|
40
|
+
firstRuleId: string;
|
|
41
|
+
position: NodePosition;
|
|
42
|
+
}): ConditionNode;
|
|
43
|
+
/**
|
|
44
|
+
* The same trigger asked to wait for something else. What belonged to the old kind goes with it; nothing is kept that the
|
|
45
|
+
* new kind has no place for.
|
|
46
|
+
*/
|
|
47
|
+
export declare function changeTriggerKind(node: TriggerNode, kind: TriggerKind): TriggerNode;
|
|
48
|
+
/**
|
|
49
|
+
* Where a new block is put. After a block, it goes one step to the right of it, and moves down until the place is free.
|
|
50
|
+
* With nothing to follow it goes under the lowest block of the leftmost column, or in the first place when the canvas is
|
|
51
|
+
* empty. A person moves it afterwards; this only makes sure it never lands on another block.
|
|
52
|
+
*/
|
|
53
|
+
export declare function suggestPosition(graph: WorkflowGraph, afterNodeId?: string | null): NodePosition;
|
|
54
|
+
/** What a person asks the Add block menu for. */
|
|
55
|
+
export type BlockRequest = {
|
|
56
|
+
kind: 'composition';
|
|
57
|
+
compositionId?: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: 'trigger';
|
|
60
|
+
triggerKind: TriggerKind;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'condition';
|
|
63
|
+
};
|
|
64
|
+
/** What adding a block changes: the new block, the line that joins it to the block it follows (when one could be drawn). */
|
|
65
|
+
export interface AddBlockPlan {
|
|
66
|
+
/** Why nothing is added: the workflow holds as many blocks as it may. */
|
|
67
|
+
refused: 'too_many_blocks' | null;
|
|
68
|
+
node: WorkflowNode | null;
|
|
69
|
+
edge: WorkflowEdge | null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The output a new block is joined from, after `anchor`: a composition and a trigger have one (a composition may lead to
|
|
73
|
+
* several triggers, so it is always free; a trigger leads to one next step, and is free only without one); a condition offers
|
|
74
|
+
* its first rule that leads nowhere yet, then Default.
|
|
75
|
+
*/
|
|
76
|
+
export declare function findFreeOutput(graph: WorkflowGraph, anchor: WorkflowNode): string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Plans a new block of this kind after the block the person has selected (or at a free place when nothing is selected).
|
|
79
|
+
* The block is joined to the anchor only when the engine would allow that line: a composition after a composition is not
|
|
80
|
+
* drawn for the person, and a trigger after a trigger neither. Nothing is changed here; the editor applies the plan.
|
|
81
|
+
*
|
|
82
|
+
* `random` is for tests.
|
|
83
|
+
*/
|
|
84
|
+
export declare function planAddBlock(graph: WorkflowGraph, request: BlockRequest, anchorId: string | null, random?: () => number): AddBlockPlan;
|
|
85
|
+
/** The graph without these blocks and without every connection that touched one of them. */
|
|
86
|
+
export declare function removeBlocks(graph: WorkflowGraph, nodeIds: readonly string[]): WorkflowGraph;
|
|
87
|
+
/** The graph without these connections. */
|
|
88
|
+
export declare function removeConnections(graph: WorkflowGraph, edgeIds: readonly string[]): WorkflowGraph;
|
|
89
|
+
/**
|
|
90
|
+
* Exactly one composition starts a workflow. After blocks were taken away, the start may be gone while compositions are
|
|
91
|
+
* left; the first one (the one furthest left) starts it then. A graph that already has one start is returned as it is.
|
|
92
|
+
*/
|
|
93
|
+
export declare function ensureOneStart(graph: WorkflowGraph): WorkflowGraph;
|
|
94
|
+
/** Makes this composition the start, and no other. Not a composition: the graph is returned as it is. */
|
|
95
|
+
export declare function setStartBlock(graph: WorkflowGraph, nodeId: string): WorkflowGraph;
|
|
96
|
+
/** Whether another rule fits in this condition. */
|
|
97
|
+
export declare function canAddRule(node: ConditionNode): boolean;
|
|
98
|
+
/** Whether another test fits in this rule. */
|
|
99
|
+
export declare function canAddTest(conditionCase: ConditionCase): boolean;
|
|
100
|
+
/** The operator a field starts with: the first one its type offers, "is". */
|
|
101
|
+
export declare function defaultOperatorFor(type: FieldType): Operator;
|
|
102
|
+
/** The value a test starts with for a type, or none for an operator that needs no value. */
|
|
103
|
+
export declare function defaultValueFor(type: FieldType, operator: Operator): FieldValue | undefined;
|
|
104
|
+
/** A new test on a field, with its type's first operator. */
|
|
105
|
+
export declare function makeTest(field: FieldReference): ConditionTest;
|
|
106
|
+
/** A test whose field was replaced: the operator and the value stay when the new type still has them, and start over when not. */
|
|
107
|
+
export declare function changeTestField(test: ConditionTest, field: FieldReference): ConditionTest;
|
|
108
|
+
/** A test with another operator: an operator that takes no value drops the value, one that takes a value gets a start for it. */
|
|
109
|
+
export declare function changeTestOperator(test: ConditionTest, operator: Operator): ConditionTest;
|
|
110
|
+
/**
|
|
111
|
+
* What a person typed into the value of a test, as the value the engine compares. A number field keeps what is not yet a
|
|
112
|
+
* number as nothing (the field is empty while the person types), a yes/no field reads `true` and `false`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function readTypedValue(type: FieldType, text: string): FieldValue | undefined;
|
|
115
|
+
/** A new rule: a fresh id, matching all of its tests, with the first field a person can read when there is one. */
|
|
116
|
+
export declare function makeRule(takenIds: ReadonlySet<string>, firstField?: FieldReference, random?: () => number): ConditionCase;
|
|
117
|
+
/** The condition with a rule more. */
|
|
118
|
+
export declare function addRule(node: ConditionNode, rule: ConditionCase): ConditionNode;
|
|
119
|
+
/** The condition with one rule less. */
|
|
120
|
+
export declare function removeRule(node: ConditionNode, ruleId: string): ConditionNode;
|
|
121
|
+
/** The condition with a rule moved to another place in the order (rules are tried in order, the first match wins). */
|
|
122
|
+
export declare function moveRule(node: ConditionNode, ruleId: string, toIndex: number): ConditionNode;
|
|
123
|
+
/** The condition with one of its rules replaced by what `change` makes of it. */
|
|
124
|
+
export declare function changeRule(node: ConditionNode, ruleId: string, change: (rule: ConditionCase) => ConditionCase): ConditionNode;
|
|
125
|
+
/** The connections that leave a port that no longer exists: after a rule is removed its line goes with it. */
|
|
126
|
+
export declare function findStrandedConnections(graph: WorkflowGraph): WorkflowEdge[];
|
|
127
|
+
/** The workflow without the lines that left from a place that is gone: removing a rule takes the line of that rule with it. */
|
|
128
|
+
export declare function dropStrandedConnections(graph: WorkflowGraph): WorkflowGraph;
|
|
129
|
+
/** A wait of some time, the way a Scheduled trigger starts. */
|
|
130
|
+
export declare function makeWaitSchedule(): ScheduleConfig;
|
|
131
|
+
/**
|
|
132
|
+
* A first moment for a schedule that is switched to "at a date and time": the next full hour, a day from `now`. It is a
|
|
133
|
+
* starting point the person changes, so the field never opens empty or in the past.
|
|
134
|
+
*/
|
|
135
|
+
export declare function makeDateSchedule(now?: Date): ScheduleConfig;
|
|
136
|
+
/** Switches a schedule between "wait for" and "at a date and time"; the same mode keeps what was typed. */
|
|
137
|
+
export declare function changeScheduleMode(schedule: ScheduleConfig, mode: ScheduleConfig['mode'], now?: Date): ScheduleConfig;
|
|
138
|
+
/** The composition blocks of a graph, in the order they are stored. */
|
|
139
|
+
export declare function listCompositionBlocks(graph: WorkflowGraph): CompositionNode[];
|
|
140
|
+
/** The ids of the compositions a graph shows, once each. */
|
|
141
|
+
export declare function listCompositionIds(graph: WorkflowGraph): string[];
|
|
142
|
+
/**
|
|
143
|
+
* The draft as the API stores it again: positions rounded to whole numbers, so that a block that was only touched by a
|
|
144
|
+
* pointer does not look changed. Two graphs that differ only below that are the same graph.
|
|
145
|
+
*/
|
|
146
|
+
export declare function normalizePositions(graph: WorkflowGraph): WorkflowGraph;
|
|
147
|
+
/** JSON with the keys of every object in order, so that two documents with the same content read the same. */
|
|
148
|
+
export declare function writeStableJson(value: unknown): string;
|
|
149
|
+
/**
|
|
150
|
+
* Whether two graphs are the same document (every block, connection and setting), used to tell "saved" from "changed".
|
|
151
|
+
* The order of the rules of a condition counts (it is their meaning). The order of the blocks and of the connections in the
|
|
152
|
+
* list does not (the canvas may bring a block to the front), and neither does the order of an object's keys.
|
|
153
|
+
*/
|
|
154
|
+
export declare function isSameGraph(left: WorkflowGraph, right: WorkflowGraph): boolean;
|