@widgetic/workflows 0.0.0-stage → 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.
Files changed (149) hide show
  1. package/LICENSE +122 -0
  2. package/README.md +304 -2
  3. package/dist/api/apiContext.d.ts +4 -0
  4. package/dist/api/apiContext.js +17 -0
  5. package/dist/api/types.d.ts +168 -0
  6. package/dist/api/types.js +3 -0
  7. package/dist/api/workflowsApi.d.ts +109 -0
  8. package/dist/api/workflowsApi.js +657 -0
  9. package/dist/components/Workflows.svelte +131 -0
  10. package/dist/components/Workflows.svelte.d.ts +4 -0
  11. package/dist/components/WorkflowsEmptyState.svelte +32 -0
  12. package/dist/components/WorkflowsEmptyState.svelte.d.ts +7 -0
  13. package/dist/components/WorkflowsHeader.svelte +14 -0
  14. package/dist/components/WorkflowsHeader.svelte.d.ts +18 -0
  15. package/dist/components/WorkflowsWorkspace.svelte +87 -0
  16. package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
  17. package/dist/components/canvas/AddBlockMenu.svelte +101 -0
  18. package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
  19. package/dist/components/canvas/CanvasToolbar.svelte +95 -0
  20. package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
  21. package/dist/components/canvas/CompositionNodeView.svelte +125 -0
  22. package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
  23. package/dist/components/canvas/ConditionNodeView.svelte +95 -0
  24. package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
  25. package/dist/components/canvas/HandlePoint.svelte +32 -0
  26. package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
  27. package/dist/components/canvas/TriggerNodeView.svelte +75 -0
  28. package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
  29. package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
  30. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
  31. package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
  32. package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
  33. package/dist/components/editor/EditorBanners.svelte +143 -0
  34. package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
  35. package/dist/components/editor/EditorCanvasArea.svelte +85 -0
  36. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
  37. package/dist/components/editor/EditorTabs.svelte +81 -0
  38. package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
  39. package/dist/components/editor/EditorTopBar.svelte +132 -0
  40. package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
  41. package/dist/components/editor/RunsTab.svelte +256 -0
  42. package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
  43. package/dist/components/editor/SettingsTab.svelte +180 -0
  44. package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
  45. package/dist/components/editor/WorkflowEditor.svelte +185 -0
  46. package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
  47. package/dist/components/index.d.ts +1 -0
  48. package/dist/components/index.js +1 -0
  49. package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
  50. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
  51. package/dist/components/list/WorkflowList.svelte +204 -0
  52. package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
  53. package/dist/components/list/WorkflowRow.svelte +191 -0
  54. package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
  55. package/dist/components/panel/BlockProblems.svelte +47 -0
  56. package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
  57. package/dist/components/panel/CompositionForm.svelte +127 -0
  58. package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
  59. package/dist/components/panel/CompositionPicker.svelte +179 -0
  60. package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
  61. package/dist/components/panel/ConditionForm.svelte +105 -0
  62. package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
  63. package/dist/components/panel/EventValueRow.svelte +85 -0
  64. package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
  65. package/dist/components/panel/NextStepSelect.svelte +70 -0
  66. package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
  67. package/dist/components/panel/ProblemsList.svelte +101 -0
  68. package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
  69. package/dist/components/panel/RuleCard.svelte +191 -0
  70. package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
  71. package/dist/components/panel/SidePanel.svelte +82 -0
  72. package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
  73. package/dist/components/panel/TestRow.svelte +150 -0
  74. package/dist/components/panel/TestRow.svelte.d.ts +15 -0
  75. package/dist/components/panel/TestRunPanel.svelte +85 -0
  76. package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
  77. package/dist/components/panel/TestTriggerCard.svelte +121 -0
  78. package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
  79. package/dist/components/panel/TriggerForm.svelte +385 -0
  80. package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
  81. package/dist/components/panel/VersionHistory.svelte +123 -0
  82. package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
  83. package/dist/components/ui/ActionButton.svelte +85 -0
  84. package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
  85. package/dist/components/ui/ConfirmDialog.svelte +52 -0
  86. package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
  87. package/dist/components/ui/Icon.svelte +32 -0
  88. package/dist/components/ui/Icon.svelte.d.ts +9 -0
  89. package/dist/components/ui/Menu.svelte +211 -0
  90. package/dist/components/ui/Menu.svelte.d.ts +21 -0
  91. package/dist/components/ui/Modal.svelte +129 -0
  92. package/dist/components/ui/Modal.svelte.d.ts +13 -0
  93. package/dist/components/ui/Notice.svelte +36 -0
  94. package/dist/components/ui/Notice.svelte.d.ts +11 -0
  95. package/dist/components/ui/SelectField.svelte +74 -0
  96. package/dist/components/ui/SelectField.svelte.d.ts +16 -0
  97. package/dist/components/ui/StatusBadge.svelte +41 -0
  98. package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
  99. package/dist/components/ui/TextField.svelte +97 -0
  100. package/dist/components/ui/TextField.svelte.d.ts +29 -0
  101. package/dist/components/ui/icons.d.ts +34 -0
  102. package/dist/components/ui/icons.js +54 -0
  103. package/dist/components/ui/types.d.ts +26 -0
  104. package/dist/components/ui/types.js +1 -0
  105. package/dist/editor/apiErrorText.d.ts +10 -0
  106. package/dist/editor/apiErrorText.js +53 -0
  107. package/dist/editor/autosave.d.ts +47 -0
  108. package/dist/editor/autosave.js +119 -0
  109. package/dist/editor/blockLabels.d.ts +91 -0
  110. package/dist/editor/blockLabels.js +196 -0
  111. package/dist/editor/canvasContext.d.ts +52 -0
  112. package/dist/editor/canvasContext.js +37 -0
  113. package/dist/editor/canvasWords.d.ts +24 -0
  114. package/dist/editor/canvasWords.js +40 -0
  115. package/dist/editor/capabilityModel.d.ts +46 -0
  116. package/dist/editor/capabilityModel.js +113 -0
  117. package/dist/editor/editorState.svelte.d.ts +220 -0
  118. package/dist/editor/editorState.svelte.js +713 -0
  119. package/dist/editor/flowAdapter.d.ts +59 -0
  120. package/dist/editor/flowAdapter.js +166 -0
  121. package/dist/editor/formatCount.d.ts +5 -0
  122. package/dist/editor/formatCount.js +15 -0
  123. package/dist/editor/graphDiff.d.ts +27 -0
  124. package/dist/editor/graphDiff.js +64 -0
  125. package/dist/editor/graphModel.d.ts +154 -0
  126. package/dist/editor/graphModel.js +457 -0
  127. package/dist/editor/issueText.d.ts +64 -0
  128. package/dist/editor/issueText.js +101 -0
  129. package/dist/editor/listState.svelte.d.ts +82 -0
  130. package/dist/editor/listState.svelte.js +250 -0
  131. package/dist/editor/statsRange.d.ts +26 -0
  132. package/dist/editor/statsRange.js +41 -0
  133. package/dist/editor/testRun.d.ts +36 -0
  134. package/dist/editor/testRun.js +74 -0
  135. package/dist/editor/zonedTime.d.ts +20 -0
  136. package/dist/editor/zonedTime.js +134 -0
  137. package/dist/i18n/index.d.ts +2 -0
  138. package/dist/i18n/index.js +2 -0
  139. package/dist/i18n/language.d.ts +22 -0
  140. package/dist/i18n/language.js +34 -0
  141. package/dist/i18n/messages.d.ts +423 -0
  142. package/dist/i18n/messages.js +446 -0
  143. package/dist/index.d.ts +4 -0
  144. package/dist/index.js +5 -0
  145. package/dist/types/index.d.ts +66 -0
  146. package/dist/types/index.js +1 -0
  147. package/dist/utils/logger.d.ts +4 -0
  148. package/dist/utils/logger.js +35 -0
  149. package/package.json +103 -5
@@ -0,0 +1,101 @@
1
+ <!--
2
+ Everything the check finds wrong with the draft, in sentences. It is what stops a publish, so it is the first thing the
3
+ panel shows when no block is selected. A problem that belongs to a block is a button that selects the block, so the person
4
+ lands on the form that fixes it. Warnings are advice and do not stop a publish.
5
+
6
+ It also lists what a refused publish said (the server checks again with what it knows), in the same place, so there is one
7
+ list to work through.
8
+ -->
9
+ <script lang="ts">
10
+ import type { ValidationIssue } from '@widgetic/workflows-engine';
11
+ import { describeBlocksUniquely } from '../../editor/blockLabels.js';
12
+ import { useEditorState } from '../../editor/editorState.svelte.js';
13
+ import { describeIssue } from '../../editor/issueText.js';
14
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
15
+ import Icon from '../ui/Icon.svelte';
16
+
17
+ const editor = useEditorState();
18
+ const { t } = useWorkflowsLanguage();
19
+
20
+ /** What makes two findings the same finding, so one the server repeats is listed once. */
21
+ function identify(issue: ValidationIssue): string {
22
+ return [
23
+ issue.code,
24
+ issue.nodeId ?? '',
25
+ issue.edgeId ?? '',
26
+ issue.caseId ?? '',
27
+ issue.detail ?? ''
28
+ ].join('|');
29
+ }
30
+
31
+ const sentences = $derived.by(() => {
32
+ const labels = describeBlocksUniquely(editor.graph, editor.options, $t);
33
+ const context = { t: $t, describeBlock: (blockId: string) => labels.get(blockId) ?? '' };
34
+ // A plain Set: it lives for one pass over the findings and is never state, so there is nothing for it to notify
35
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
36
+ const seen = new Set<string>();
37
+ const list: Array<{
38
+ key: string;
39
+ severity: ValidationIssue['severity'];
40
+ nodeId: string | undefined;
41
+ text: string;
42
+ }> = [];
43
+ for (const issue of [...editor.issues, ...editor.refusedIssues]) {
44
+ const key = identify(issue);
45
+ if (seen.has(key)) continue;
46
+ seen.add(key);
47
+ list.push({
48
+ key,
49
+ severity: issue.severity,
50
+ nodeId: issue.nodeId,
51
+ text: describeIssue(issue, context)
52
+ });
53
+ }
54
+ // Errors first: they are what stops a publish.
55
+ return list.sort(
56
+ (left, right) => Number(right.severity === 'error') - Number(left.severity === 'error')
57
+ );
58
+ });
59
+
60
+ function goToBlock(nodeId: string): void {
61
+ editor.canvas?.selectNodes([nodeId]);
62
+ editor.panel = 'selection';
63
+ }
64
+ </script>
65
+
66
+ {#if sentences.length > 0}
67
+ <ul class="flex flex-col gap-1" aria-label={$t('workflows.panel.problemsLabel')}>
68
+ {#each sentences as sentence (sentence.key)}
69
+ <li>
70
+ {#if sentence.nodeId}
71
+ {@const nodeId = sentence.nodeId}
72
+ <button
73
+ type="button"
74
+ class="flex w-full items-start gap-2 rounded-medium px-2 py-1.5 text-start text-xs hover:text-ink-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green {sentence.severity ===
75
+ 'error'
76
+ ? 'text-error'
77
+ : 'text-ink-muted'}"
78
+ onclick={() => goToBlock(nodeId)}
79
+ >
80
+ <Icon name="warning" class="mt-0.5 size-3.5" />
81
+ <span>{sentence.text}</span>
82
+ </button>
83
+ {:else}
84
+ <p
85
+ class="flex items-start gap-2 px-2 py-1.5 text-xs {sentence.severity === 'error'
86
+ ? 'text-error'
87
+ : 'text-ink-muted'}"
88
+ >
89
+ <Icon name="warning" class="mt-0.5 size-3.5" />
90
+ <span>{sentence.text}</span>
91
+ </p>
92
+ {/if}
93
+ </li>
94
+ {/each}
95
+ </ul>
96
+ {:else}
97
+ <p class="flex items-center gap-2 text-xs text-ink-muted">
98
+ <Icon name="check" class="size-3.5 text-primary-green" />
99
+ {$t('workflows.panel.noProblems')}
100
+ </p>
101
+ {/if}
@@ -0,0 +1,3 @@
1
+ declare const ProblemsList: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type ProblemsList = ReturnType<typeof ProblemsList>;
3
+ export default ProblemsList;
@@ -0,0 +1,191 @@
1
+ <!--
2
+ One rule of a condition: a name, whether all or any of its tests must hold, the tests, and where a visitor goes when the
3
+ rule matches. Rules are tried in the order they are listed and the first that matches wins, so each card can be moved up
4
+ or down.
5
+
6
+ A name is optional (without one the rule is "Rule 1", "Rule 2"…); it is kept when the person leaves the field.
7
+ -->
8
+ <script lang="ts">
9
+ import { MAX_TESTS_PER_CASE } from '@widgetic/workflows-engine';
10
+ import type { ConditionCase, ConditionNode, ConditionTest } from '@widgetic/workflows-engine';
11
+ import { nameRule } from '../../editor/blockLabels.js';
12
+ import type { FieldChoice } from '../../editor/capabilityModel.js';
13
+ import { useEditorState } from '../../editor/editorState.svelte.js';
14
+ import {
15
+ canAddTest,
16
+ changeRule,
17
+ makeTest,
18
+ moveRule,
19
+ removeRule
20
+ } from '../../editor/graphModel.js';
21
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
22
+ import ActionButton from '../ui/ActionButton.svelte';
23
+ import Icon from '../ui/Icon.svelte';
24
+ import SelectField from '../ui/SelectField.svelte';
25
+ import TextField from '../ui/TextField.svelte';
26
+ import type { SelectChoice } from '../ui/types.js';
27
+ import NextStepSelect from './NextStepSelect.svelte';
28
+ import TestRow from './TestRow.svelte';
29
+
30
+ interface Props {
31
+ node: ConditionNode;
32
+ rule: ConditionCase;
33
+ /** Its place among the rules, from 0. */
34
+ index: number;
35
+ /** The values the trigger before the condition carries. */
36
+ choices: readonly FieldChoice[];
37
+ }
38
+
39
+ let { node, rule, index, choices }: Props = $props();
40
+
41
+ const editor = useEditorState();
42
+ const { t } = useWorkflowsLanguage();
43
+ const headingId = $props.id();
44
+
45
+ const ruleName = $derived(nameRule(rule, index, $t));
46
+ const isFirst = $derived(index === 0);
47
+ const isLast = $derived(index === node.cases.length - 1);
48
+
49
+ /** What is in the name box while it is being typed; it follows the rule again whenever the rule changes. */
50
+ let nameDraft = $derived(rule.label ?? '');
51
+
52
+ const matchChoices = $derived<SelectChoice[]>([
53
+ { value: 'all', label: $t('workflows.rule.matchAll') },
54
+ { value: 'any', label: $t('workflows.rule.matchAny') }
55
+ ]);
56
+
57
+ function replaceRule(change: (current: ConditionCase) => ConditionCase): void {
58
+ editor.replaceBlock(changeRule(node, rule.id, change));
59
+ }
60
+
61
+ function commitName(): void {
62
+ const label = nameDraft.trim();
63
+ if (label === (rule.label ?? '')) return;
64
+ replaceRule((current) => {
65
+ const { label: _previous, ...rest } = current;
66
+ return label === '' ? rest : { ...rest, label };
67
+ });
68
+ }
69
+
70
+ function addTest(): void {
71
+ const firstChoice = choices[0];
72
+ if (!firstChoice || !canAddTest(rule)) return;
73
+ replaceRule((current) => ({
74
+ ...current,
75
+ tests: [...current.tests, makeTest(firstChoice.field)]
76
+ }));
77
+ }
78
+
79
+ function changeTest(position: number, next: ConditionTest): void {
80
+ replaceRule((current) => ({
81
+ ...current,
82
+ tests: current.tests.map((test, at) => (at === position ? next : test))
83
+ }));
84
+ }
85
+
86
+ function removeTest(position: number): void {
87
+ replaceRule((current) => ({
88
+ ...current,
89
+ tests: current.tests.filter((_, at) => at !== position)
90
+ }));
91
+ }
92
+ </script>
93
+
94
+ <section
95
+ class="flex flex-col gap-3 rounded-large border border-grey2 p-3"
96
+ aria-labelledby={headingId}
97
+ >
98
+ <div class="flex items-start gap-2">
99
+ <TextField
100
+ class="flex-1"
101
+ label={$t('workflows.rule.nameLabel', { name: ruleName })}
102
+ hideLabel
103
+ placeholder={ruleName}
104
+ maxlength={80}
105
+ disabled={editor.isReadOnly}
106
+ bind:value={nameDraft}
107
+ onchange={commitName}
108
+ />
109
+ <h4 id={headingId} class="sr-only">{ruleName}</h4>
110
+ {#if !editor.isReadOnly}
111
+ <ActionButton
112
+ variant="ghost"
113
+ iconOnly
114
+ disabled={isFirst}
115
+ ariaLabel={$t('workflows.rule.moveUp', { name: ruleName })}
116
+ title={$t('workflows.rule.moveUp', { name: ruleName })}
117
+ onclick={() => editor.replaceBlock(moveRule(node, rule.id, index - 1))}
118
+ >
119
+ <Icon name="up" />
120
+ </ActionButton>
121
+ <ActionButton
122
+ variant="ghost"
123
+ iconOnly
124
+ disabled={isLast}
125
+ ariaLabel={$t('workflows.rule.moveDown', { name: ruleName })}
126
+ title={$t('workflows.rule.moveDown', { name: ruleName })}
127
+ onclick={() => editor.replaceBlock(moveRule(node, rule.id, index + 1))}
128
+ >
129
+ <Icon name="down" />
130
+ </ActionButton>
131
+ <ActionButton
132
+ variant="ghost"
133
+ iconOnly
134
+ ariaLabel={$t('workflows.rule.remove', { name: ruleName })}
135
+ title={$t('workflows.rule.remove', { name: ruleName })}
136
+ onclick={() => editor.replaceBlock(removeRule(node, rule.id))}
137
+ >
138
+ <Icon name="trash" />
139
+ </ActionButton>
140
+ {/if}
141
+ </div>
142
+
143
+ {#if rule.tests.length === 0}
144
+ <p class="text-xs text-ink-muted">{$t('workflows.rule.noTests')}</p>
145
+ {:else}
146
+ {#if rule.tests.length > 1}
147
+ <SelectField
148
+ label={$t('workflows.rule.matchLabel')}
149
+ value={rule.match}
150
+ choices={matchChoices}
151
+ disabled={editor.isReadOnly}
152
+ onchange={(match) =>
153
+ replaceRule((current) => ({ ...current, match: match === 'any' ? 'any' : 'all' }))}
154
+ />
155
+ {/if}
156
+ <div class="flex flex-col gap-2">
157
+ {#each rule.tests as test, position (position)}
158
+ <TestRow
159
+ {test}
160
+ index={position}
161
+ {choices}
162
+ disabled={editor.isReadOnly}
163
+ onchange={(next) => changeTest(position, next)}
164
+ onremove={() => removeTest(position)}
165
+ />
166
+ {/each}
167
+ </div>
168
+ {/if}
169
+
170
+ {#if !editor.isReadOnly}
171
+ <ActionButton
172
+ size="small"
173
+ class="self-start"
174
+ disabled={choices.length === 0 || !canAddTest(rule)}
175
+ title={canAddTest(rule)
176
+ ? undefined
177
+ : $t('workflows.rule.testLimit', { max: MAX_TESTS_PER_CASE })}
178
+ onclick={addTest}
179
+ >
180
+ <Icon name="plus" />
181
+ {$t('workflows.rule.addTest')}
182
+ </ActionButton>
183
+ {/if}
184
+
185
+ <NextStepSelect
186
+ sourceId={node.id}
187
+ sourcePort={rule.id}
188
+ label={$t('workflows.rule.thenGoTo', { name: ruleName })}
189
+ emptyLabel={$t('workflows.trigger.nextNone')}
190
+ />
191
+ </section>
@@ -0,0 +1,13 @@
1
+ import type { ConditionCase, ConditionNode } from '@widgetic/workflows-engine';
2
+ import type { FieldChoice } from '../../editor/capabilityModel.js';
3
+ interface Props {
4
+ node: ConditionNode;
5
+ rule: ConditionCase;
6
+ /** Its place among the rules, from 0. */
7
+ index: number;
8
+ /** The values the trigger before the condition carries. */
9
+ choices: readonly FieldChoice[];
10
+ }
11
+ declare const RuleCard: import("svelte").Component<Props, {}, "">;
12
+ type RuleCard = ReturnType<typeof RuleCard>;
13
+ export default RuleCard;
@@ -0,0 +1,82 @@
1
+ <!--
2
+ The panel beside the canvas. It shows one of three things: the form of the selected block, the version history, or the
3
+ test run; with nothing selected it shows what is wrong with the draft and how to start. Everything a block's form can do is
4
+ also possible with the keyboard and on a touch screen, where the canvas itself cannot be drawn on.
5
+
6
+ A block's form starts again whenever another block is selected, so what was being typed for one block never lands in
7
+ another.
8
+ -->
9
+ <script lang="ts">
10
+ import { useEditorState } from '../../editor/editorState.svelte.js';
11
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
12
+ import ActionButton from '../ui/ActionButton.svelte';
13
+ import Icon from '../ui/Icon.svelte';
14
+ import CompositionForm from './CompositionForm.svelte';
15
+ import ConditionForm from './ConditionForm.svelte';
16
+ import ProblemsList from './ProblemsList.svelte';
17
+ import TestRunPanel from './TestRunPanel.svelte';
18
+ import TriggerForm from './TriggerForm.svelte';
19
+ import VersionHistory from './VersionHistory.svelte';
20
+
21
+ const editor = useEditorState();
22
+ const { t } = useWorkflowsLanguage();
23
+
24
+ const selectedNode = $derived(editor.selectedNode);
25
+ const selectedBlockCount = $derived(editor.selectedNodeIds.length);
26
+ const selectedConnectionCount = $derived(editor.selectedEdgeIds.length);
27
+ </script>
28
+
29
+ <aside
30
+ aria-label={$t('workflows.panel.label')}
31
+ class="flex min-h-0 min-w-0 flex-col gap-4 overflow-auto bg-white p-4"
32
+ >
33
+ {#if editor.panel === 'history'}
34
+ <VersionHistory />
35
+ {:else if editor.panel === 'test'}
36
+ <TestRunPanel />
37
+ {:else if selectedNode}
38
+ {#key selectedNode.id}
39
+ {#if selectedNode.type === 'composition'}
40
+ <CompositionForm node={selectedNode} />
41
+ {:else if selectedNode.type === 'trigger'}
42
+ <TriggerForm node={selectedNode} />
43
+ {:else}
44
+ <ConditionForm node={selectedNode} />
45
+ {/if}
46
+ {/key}
47
+ {:else if selectedBlockCount > 1 || selectedConnectionCount > 0}
48
+ <div class="flex flex-col gap-3">
49
+ <p class="text-sm">
50
+ {#if selectedBlockCount > 1}
51
+ {$t('workflows.panel.manyBlocksSelected', { count: selectedBlockCount })}
52
+ {:else}
53
+ {$t('workflows.panel.connectionSelected')}
54
+ {/if}
55
+ </p>
56
+ {#if !editor.isReadOnly}
57
+ <ActionButton
58
+ variant="danger"
59
+ size="small"
60
+ class="self-start"
61
+ onclick={() => editor.removeSelected()}
62
+ >
63
+ <Icon name="trash" />
64
+ {selectedBlockCount > 1
65
+ ? $t('workflows.panel.removeBlocks')
66
+ : $t('workflows.panel.removeConnection')}
67
+ </ActionButton>
68
+ {/if}
69
+ </div>
70
+ {:else}
71
+ <div class="flex flex-col gap-4">
72
+ <div>
73
+ <h3 class="text-sm font-semibold">{$t('workflows.panel.overviewHeading')}</h3>
74
+ <p class="text-xs text-ink-muted">{$t('workflows.panel.overviewHelp')}</p>
75
+ </div>
76
+ <div class="flex flex-col gap-2">
77
+ <h4 class="text-xs font-medium">{$t('workflows.panel.problemsHeading')}</h4>
78
+ <ProblemsList />
79
+ </div>
80
+ </div>
81
+ {/if}
82
+ </aside>
@@ -0,0 +1,3 @@
1
+ declare const SidePanel: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type SidePanel = ReturnType<typeof SidePanel>;
3
+ export default SidePanel;
@@ -0,0 +1,150 @@
1
+ <!--
2
+ One test of a rule: a value the trigger carries, how to compare it, and what to compare it with. The comparison chosen is
3
+ always one the kind of value allows (text has "contains", a number has "greater than", yes/no has "is"), and one that
4
+ needs nothing to compare with (is empty) shows no box for it.
5
+
6
+ What is typed in the box is kept when the person leaves it; a yes/no value is a choice and is kept at once.
7
+ -->
8
+ <script lang="ts">
9
+ import { OPERATORS_BY_TYPE, operatorNeedsValue } from '@widgetic/workflows-engine';
10
+ import type { ConditionTest, Operator } from '@widgetic/workflows-engine';
11
+ import { OPERATOR_MESSAGE_KEYS } from '../../editor/blockLabels.js';
12
+ import { fieldChoiceKey } from '../../editor/capabilityModel.js';
13
+ import type { FieldChoice } from '../../editor/capabilityModel.js';
14
+ import { changeTestField, changeTestOperator, readTypedValue } from '../../editor/graphModel.js';
15
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
16
+ import ActionButton from '../ui/ActionButton.svelte';
17
+ import Icon from '../ui/Icon.svelte';
18
+ import SelectField from '../ui/SelectField.svelte';
19
+ import TextField from '../ui/TextField.svelte';
20
+ import type { SelectChoice } from '../ui/types.js';
21
+
22
+ interface Props {
23
+ test: ConditionTest;
24
+ /** Its place in the rule, from 0: the person hears "Test 2", not an id. */
25
+ index: number;
26
+ /** The values the trigger before the condition carries. */
27
+ choices: readonly FieldChoice[];
28
+ disabled?: boolean;
29
+ onchange: (next: ConditionTest) => void;
30
+ onremove: () => void;
31
+ }
32
+
33
+ let { test, index, choices, disabled = false, onchange, onremove }: Props = $props();
34
+
35
+ const { t } = useWorkflowsLanguage();
36
+
37
+ const number = $derived(index + 1);
38
+ const fieldKey = $derived(fieldChoiceKey(test.field));
39
+
40
+ const fieldChoices = $derived.by<SelectChoice[]>(() => {
41
+ const list: SelectChoice[] = choices.map((choice) => ({
42
+ value: fieldChoiceKey(choice.field),
43
+ label: choice.label
44
+ }));
45
+ // A value that is not carried any more is kept in the list, marked, so the test is not silently changed.
46
+ if (!list.some((choice) => choice.value === fieldKey)) {
47
+ list.unshift({
48
+ value: fieldKey,
49
+ label: $t('workflows.trigger.notFound', { name: test.field.name })
50
+ });
51
+ }
52
+ return list;
53
+ });
54
+
55
+ const operatorChoices = $derived<SelectChoice[]>(
56
+ OPERATORS_BY_TYPE[test.field.type].map((operator) => ({
57
+ value: operator,
58
+ label: $t(OPERATOR_MESSAGE_KEYS[operator])
59
+ }))
60
+ );
61
+
62
+ const takesValue = $derived(operatorNeedsValue(test.operator));
63
+
64
+ /** What is in the box while it is being typed; it follows the value again whenever the value changes. */
65
+ let valueDraft = $derived(
66
+ test.value === undefined || test.value === null ? '' : String(test.value)
67
+ );
68
+
69
+ const yesNoChoices = $derived<SelectChoice[]>([
70
+ { value: 'true', label: $t('workflows.value.yes') },
71
+ { value: 'false', label: $t('workflows.value.no') }
72
+ ]);
73
+
74
+ function chooseField(key: string): void {
75
+ const choice = choices.find((candidate) => fieldChoiceKey(candidate.field) === key);
76
+ if (choice) onchange(changeTestField(test, choice.field));
77
+ }
78
+
79
+ /** The test with the value written, or without a `value` when the text is not a value yet (an empty number box). */
80
+ function withValue(text: string): ConditionTest {
81
+ const value = readTypedValue(test.field.type, text);
82
+ const { value: _previous, ...rest } = test;
83
+ return value === undefined ? rest : { ...rest, value };
84
+ }
85
+
86
+ function commitValue(): void {
87
+ onchange(withValue(valueDraft));
88
+ }
89
+ </script>
90
+
91
+ <div class="flex flex-col gap-2 rounded-medium border border-grey2 p-2">
92
+ <div class="flex items-start gap-2">
93
+ <SelectField
94
+ class="flex-1"
95
+ label={$t('workflows.test.field', { number })}
96
+ hideLabel
97
+ value={fieldKey}
98
+ choices={fieldChoices}
99
+ {disabled}
100
+ onchange={chooseField}
101
+ />
102
+ <ActionButton
103
+ variant="ghost"
104
+ iconOnly
105
+ {disabled}
106
+ ariaLabel={$t('workflows.test.remove', { number })}
107
+ title={$t('workflows.test.remove', { number })}
108
+ onclick={onremove}
109
+ >
110
+ <Icon name="trash" />
111
+ </ActionButton>
112
+ </div>
113
+ <div class="flex items-start gap-2">
114
+ <SelectField
115
+ class="flex-1"
116
+ label={$t('workflows.test.operator', { number })}
117
+ hideLabel
118
+ value={test.operator}
119
+ choices={operatorChoices}
120
+ {disabled}
121
+ onchange={(operator) => onchange(changeTestOperator(test, operator as Operator))}
122
+ />
123
+ {#if takesValue}
124
+ {#if test.field.type === 'boolean'}
125
+ <SelectField
126
+ class="flex-1"
127
+ label={$t('workflows.test.value', { number })}
128
+ hideLabel
129
+ value={String(test.value ?? true)}
130
+ choices={yesNoChoices}
131
+ {disabled}
132
+ onchange={(text) => onchange(withValue(text))}
133
+ />
134
+ {:else}
135
+ <TextField
136
+ class="flex-1"
137
+ type={test.field.type === 'number' ? 'number' : 'text'}
138
+ inputmode={test.field.type === 'number' ? 'decimal' : 'text'}
139
+ label={$t('workflows.test.value', { number })}
140
+ hideLabel
141
+ placeholder={$t('workflows.test.valuePlaceholder')}
142
+ maxlength={200}
143
+ {disabled}
144
+ bind:value={valueDraft}
145
+ onchange={commitValue}
146
+ />
147
+ {/if}
148
+ {/if}
149
+ </div>
150
+ </div>
@@ -0,0 +1,15 @@
1
+ import type { ConditionTest } from '@widgetic/workflows-engine';
2
+ import type { FieldChoice } from '../../editor/capabilityModel.js';
3
+ interface Props {
4
+ test: ConditionTest;
5
+ /** Its place in the rule, from 0: the person hears "Test 2", not an id. */
6
+ index: number;
7
+ /** The values the trigger before the condition carries. */
8
+ choices: readonly FieldChoice[];
9
+ disabled?: boolean;
10
+ onchange: (next: ConditionTest) => void;
11
+ onremove: () => void;
12
+ }
13
+ declare const TestRow: import("svelte").Component<Props, {}, "">;
14
+ type TestRow = ReturnType<typeof TestRow>;
15
+ export default TestRow;
@@ -0,0 +1,85 @@
1
+ <!--
2
+ Test run: the person plays a visitor on the draft. The visitor starts on the first composition; each trigger of the
3
+ composition they are on can be fired (with values typed for it), and the path the visitor takes lights up on the canvas.
4
+
5
+ It is the engine's own step (the one the embed takes for a real visitor), so what happens here is what visitors get. Nothing
6
+ is sent and no visit is counted; any change to the draft ends the test, because the path it showed is no longer the draft's.
7
+ -->
8
+ <script lang="ts">
9
+ import { describeBlocksUniquely } from '../../editor/blockLabels.js';
10
+ import { useEditorState } from '../../editor/editorState.svelte.js';
11
+ import { listTriggersOfCurrent } from '../../editor/testRun.js';
12
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
13
+ import ActionButton from '../ui/ActionButton.svelte';
14
+ import Icon from '../ui/Icon.svelte';
15
+ import TestTriggerCard from './TestTriggerCard.svelte';
16
+
17
+ const editor = useEditorState();
18
+ const { t } = useWorkflowsLanguage();
19
+
20
+ const run = $derived(editor.testRun);
21
+ const labels = $derived(describeBlocksUniquely(editor.graph, editor.options, $t));
22
+ const triggers = $derived(run ? listTriggersOfCurrent(editor.graph, run) : []);
23
+ const currentName = $derived(run?.currentNodeId ? (labels.get(run.currentNodeId) ?? '') : '');
24
+
25
+ /** One sentence for what the last trigger did. */
26
+ const resultText = $derived.by(() => {
27
+ const result = run?.lastResult;
28
+ if (!result) return null;
29
+ if (result.outcome === 'moved')
30
+ return $t('workflows.test.resultMoved', { name: labels.get(result.toNodeId) ?? '' });
31
+ return result.outcome === 'stayed'
32
+ ? $t('workflows.test.resultStayed')
33
+ : $t('workflows.test.resultIgnored');
34
+ });
35
+ </script>
36
+
37
+ <div class="flex flex-col gap-4">
38
+ <div class="flex items-start justify-between gap-2">
39
+ <div>
40
+ <h3 class="text-sm font-semibold">{$t('workflows.test.heading')}</h3>
41
+ <p class="text-xs text-ink-muted">{$t('workflows.test.help')}</p>
42
+ </div>
43
+ <ActionButton
44
+ variant="ghost"
45
+ iconOnly
46
+ ariaLabel={$t('workflows.test.close')}
47
+ title={$t('workflows.test.close')}
48
+ onclick={() => editor.closeTestRun()}
49
+ >
50
+ <Icon name="close" />
51
+ </ActionButton>
52
+ </div>
53
+
54
+ {#if run === null}
55
+ <p class="text-xs text-ink-muted">{$t('workflows.test.ended')}</p>
56
+ <ActionButton size="small" class="self-start" onclick={() => editor.openTestRun()}>
57
+ <Icon name="play" />
58
+ {$t('workflows.test.start')}
59
+ </ActionButton>
60
+ {:else if run.currentNodeId === null}
61
+ <p class="text-xs text-ink-muted">{$t('workflows.test.noStart')}</p>
62
+ {:else}
63
+ <p class="text-sm" aria-live="polite">
64
+ {$t('workflows.test.visitorIsOn', { name: currentName })}
65
+ </p>
66
+ {#if resultText}
67
+ <p class="text-xs text-ink-muted" role="status">{resultText}</p>
68
+ {/if}
69
+
70
+ {#if triggers.length === 0}
71
+ <p class="text-xs text-ink-muted">{$t('workflows.test.noTriggers')}</p>
72
+ {:else}
73
+ <div class="flex flex-col gap-3">
74
+ {#each triggers as trigger (trigger.id + ':' + run.visitedNodeIds.length)}
75
+ <TestTriggerCard {trigger} />
76
+ {/each}
77
+ </div>
78
+ {/if}
79
+
80
+ <ActionButton size="small" class="self-start" onclick={() => editor.restartTestRun()}>
81
+ <Icon name="undo" />
82
+ {$t('workflows.test.restart')}
83
+ </ActionButton>
84
+ {/if}
85
+ </div>
@@ -0,0 +1,3 @@
1
+ declare const TestRunPanel: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type TestRunPanel = ReturnType<typeof TestRunPanel>;
3
+ export default TestRunPanel;