@widgetic/workflows 0.1.1 → 0.2.1

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 (148) hide show
  1. package/README.md +118 -46
  2. package/dist/api/apiContext.d.ts +4 -0
  3. package/dist/api/apiContext.js +17 -0
  4. package/dist/api/types.d.ts +201 -0
  5. package/dist/api/types.js +3 -0
  6. package/dist/api/workflowsApi.d.ts +133 -0
  7. package/dist/api/workflowsApi.js +763 -0
  8. package/dist/components/Workflows.svelte +43 -17
  9. package/dist/components/WorkflowsEmptyState.svelte +16 -5
  10. package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
  11. package/dist/components/WorkflowsHeader.svelte +2 -2
  12. package/dist/components/WorkflowsWorkspace.svelte +90 -0
  13. package/dist/components/WorkflowsWorkspace.svelte.d.ts +15 -0
  14. package/dist/components/canvas/AddBlockMenu.svelte +101 -0
  15. package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
  16. package/dist/components/canvas/CanvasToolbar.svelte +95 -0
  17. package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
  18. package/dist/components/canvas/CompositionNodeView.svelte +125 -0
  19. package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
  20. package/dist/components/canvas/ConditionNodeView.svelte +95 -0
  21. package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
  22. package/dist/components/canvas/HandlePoint.svelte +32 -0
  23. package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
  24. package/dist/components/canvas/TriggerNodeView.svelte +75 -0
  25. package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
  26. package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
  27. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
  28. package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
  29. package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
  30. package/dist/components/editor/ConflictBanner.svelte +78 -0
  31. package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
  32. package/dist/components/editor/EditorBanners.svelte +141 -0
  33. package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
  34. package/dist/components/editor/EditorCanvasArea.svelte +85 -0
  35. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
  36. package/dist/components/editor/EditorTabs.svelte +81 -0
  37. package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
  38. package/dist/components/editor/EditorTopBar.svelte +132 -0
  39. package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
  40. package/dist/components/editor/PresenceBanner.svelte +126 -0
  41. package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -0
  42. package/dist/components/editor/RunsTab.svelte +256 -0
  43. package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
  44. package/dist/components/editor/SettingsTab.svelte +180 -0
  45. package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
  46. package/dist/components/editor/WorkflowEditor.svelte +198 -0
  47. package/dist/components/editor/WorkflowEditor.svelte.d.ts +17 -0
  48. package/dist/components/index.d.ts +0 -2
  49. package/dist/components/index.js +0 -2
  50. package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
  51. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
  52. package/dist/components/list/WorkflowList.svelte +204 -0
  53. package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
  54. package/dist/components/list/WorkflowRow.svelte +191 -0
  55. package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
  56. package/dist/components/panel/BlockProblems.svelte +47 -0
  57. package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
  58. package/dist/components/panel/CompositionForm.svelte +127 -0
  59. package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
  60. package/dist/components/panel/CompositionPicker.svelte +179 -0
  61. package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
  62. package/dist/components/panel/ConditionForm.svelte +105 -0
  63. package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
  64. package/dist/components/panel/EventValueRow.svelte +85 -0
  65. package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
  66. package/dist/components/panel/NextStepSelect.svelte +70 -0
  67. package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
  68. package/dist/components/panel/ProblemsList.svelte +101 -0
  69. package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
  70. package/dist/components/panel/RuleCard.svelte +191 -0
  71. package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
  72. package/dist/components/panel/SidePanel.svelte +82 -0
  73. package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
  74. package/dist/components/panel/TestRow.svelte +150 -0
  75. package/dist/components/panel/TestRow.svelte.d.ts +15 -0
  76. package/dist/components/panel/TestRunPanel.svelte +85 -0
  77. package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
  78. package/dist/components/panel/TestTriggerCard.svelte +121 -0
  79. package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
  80. package/dist/components/panel/TriggerForm.svelte +385 -0
  81. package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
  82. package/dist/components/panel/VersionHistory.svelte +123 -0
  83. package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
  84. package/dist/components/ui/ActionButton.svelte +85 -0
  85. package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
  86. package/dist/components/ui/ConfirmDialog.svelte +52 -0
  87. package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
  88. package/dist/components/ui/Icon.svelte +32 -0
  89. package/dist/components/ui/Icon.svelte.d.ts +9 -0
  90. package/dist/components/ui/Menu.svelte +211 -0
  91. package/dist/components/ui/Menu.svelte.d.ts +21 -0
  92. package/dist/components/ui/Modal.svelte +129 -0
  93. package/dist/components/ui/Modal.svelte.d.ts +13 -0
  94. package/dist/components/ui/Notice.svelte +36 -0
  95. package/dist/components/ui/Notice.svelte.d.ts +11 -0
  96. package/dist/components/ui/SelectField.svelte +74 -0
  97. package/dist/components/ui/SelectField.svelte.d.ts +16 -0
  98. package/dist/components/ui/StatusBadge.svelte +41 -0
  99. package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
  100. package/dist/components/ui/TextField.svelte +97 -0
  101. package/dist/components/ui/TextField.svelte.d.ts +29 -0
  102. package/dist/components/ui/icons.d.ts +34 -0
  103. package/dist/components/ui/icons.js +54 -0
  104. package/dist/components/ui/types.d.ts +26 -0
  105. package/dist/components/ui/types.js +1 -0
  106. package/dist/editor/apiErrorText.d.ts +10 -0
  107. package/dist/editor/apiErrorText.js +53 -0
  108. package/dist/editor/autosave.d.ts +47 -0
  109. package/dist/editor/autosave.js +119 -0
  110. package/dist/editor/blockLabels.d.ts +91 -0
  111. package/dist/editor/blockLabels.js +196 -0
  112. package/dist/editor/canvasContext.d.ts +52 -0
  113. package/dist/editor/canvasContext.js +37 -0
  114. package/dist/editor/canvasWords.d.ts +24 -0
  115. package/dist/editor/canvasWords.js +40 -0
  116. package/dist/editor/capabilityModel.d.ts +46 -0
  117. package/dist/editor/capabilityModel.js +113 -0
  118. package/dist/editor/editLeaseController.d.ts +162 -0
  119. package/dist/editor/editLeaseController.js +459 -0
  120. package/dist/editor/editorState.svelte.d.ts +277 -0
  121. package/dist/editor/editorState.svelte.js +862 -0
  122. package/dist/editor/flowAdapter.d.ts +59 -0
  123. package/dist/editor/flowAdapter.js +166 -0
  124. package/dist/editor/formatCount.d.ts +5 -0
  125. package/dist/editor/formatCount.js +15 -0
  126. package/dist/editor/graphDiff.d.ts +27 -0
  127. package/dist/editor/graphDiff.js +64 -0
  128. package/dist/editor/graphModel.d.ts +154 -0
  129. package/dist/editor/graphModel.js +457 -0
  130. package/dist/editor/issueText.d.ts +64 -0
  131. package/dist/editor/issueText.js +101 -0
  132. package/dist/editor/keepCopy.d.ts +41 -0
  133. package/dist/editor/keepCopy.js +52 -0
  134. package/dist/editor/listState.svelte.d.ts +82 -0
  135. package/dist/editor/listState.svelte.js +250 -0
  136. package/dist/editor/statsRange.d.ts +26 -0
  137. package/dist/editor/statsRange.js +41 -0
  138. package/dist/editor/testRun.d.ts +36 -0
  139. package/dist/editor/testRun.js +74 -0
  140. package/dist/editor/zonedTime.d.ts +20 -0
  141. package/dist/editor/zonedTime.js +134 -0
  142. package/dist/i18n/language.d.ts +3 -3
  143. package/dist/i18n/messages.d.ts +429 -4
  144. package/dist/i18n/messages.js +456 -8
  145. package/dist/index.d.ts +2 -1
  146. package/dist/index.js +1 -1
  147. package/dist/types/index.d.ts +41 -3
  148. package/package.json +5 -1
@@ -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;
@@ -0,0 +1,121 @@
1
+ <!--
2
+ One trigger of the composition the test visitor is on, with a button that fires it. A trigger that carries values (a new
3
+ entry, a page's event) asks for them first, so the person can try each rule of the condition that follows; one that carries
4
+ none (an action, a wait) is only fired.
5
+
6
+ Nothing is sent anywhere and nothing is counted: this is the engine running the draft on the screen.
7
+ -->
8
+ <script lang="ts">
9
+ import type { FieldType, FieldValue, TriggerNode } from '@widgetic/workflows-engine';
10
+ import { FIELD_TYPE_MESSAGE_KEYS, summarizeTrigger } from '../../editor/blockLabels.js';
11
+ import { findCompositionOfTrigger } from '../../editor/canvasWords.js';
12
+ import { useEditorState } from '../../editor/editorState.svelte.js';
13
+ import { readTypedValue } from '../../editor/graphModel.js';
14
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
15
+ import ActionButton from '../ui/ActionButton.svelte';
16
+ import Icon from '../ui/Icon.svelte';
17
+ import SelectField from '../ui/SelectField.svelte';
18
+ import TextField from '../ui/TextField.svelte';
19
+ import type { SelectChoice } from '../ui/types.js';
20
+
21
+ interface Props {
22
+ trigger: TriggerNode;
23
+ }
24
+
25
+ let { trigger }: Props = $props();
26
+
27
+ const editor = useEditorState();
28
+ const { t, locale } = useWorkflowsLanguage();
29
+
30
+ interface TestValueField {
31
+ name: string;
32
+ label: string;
33
+ type: FieldType;
34
+ }
35
+
36
+ /** The composition of this trigger, for the names its widget gives to its columns and actions. */
37
+ const sourceOption = $derived.by(() => {
38
+ const compositionId = findCompositionOfTrigger(editor.graph, trigger.id);
39
+ return compositionId ? editor.options[compositionId] : undefined;
40
+ });
41
+
42
+ const summary = $derived(
43
+ summarizeTrigger(trigger.trigger, {
44
+ t: $t,
45
+ locale: $locale,
46
+ timeZone: editor.timezone,
47
+ describeAction: (actionId) =>
48
+ sourceOption?.actions.items.find((item) => item.id === actionId)?.label ?? actionId
49
+ })
50
+ );
51
+
52
+ /** The values this trigger carries, which the person can set for the test. */
53
+ const fields = $derived.by<TestValueField[]>(() => {
54
+ const config = trigger.trigger;
55
+ if (config.kind === 'pageEvent')
56
+ return config.values.map((value) => ({
57
+ name: value.name,
58
+ label: value.name,
59
+ type: value.type
60
+ }));
61
+ if (config.kind === 'input' && sourceOption) {
62
+ return sourceOption.inputs.fields
63
+ .filter((field) => field.table === config.table)
64
+ .map((field) => ({ name: field.column, label: field.label, type: field.type }));
65
+ }
66
+ return [];
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
+ /** What the person typed for each value, by its name. */
75
+ let typed = $state<Record<string, string>>({});
76
+
77
+ /** What is in the box of a value: what was typed, or the start of its kind (an empty box, "No" for a yes/no value). */
78
+ function readTyped(field: TestValueField): string {
79
+ return typed[field.name] ?? (field.type === 'boolean' ? 'false' : '');
80
+ }
81
+
82
+ /** Fires the trigger with the values typed; a text box left empty carries no value, as an empty value would not. */
83
+ function fire(): void {
84
+ const values: Record<string, FieldValue> = {};
85
+ for (const field of fields) {
86
+ const text = readTyped(field);
87
+ const value = readTypedValue(field.type, text);
88
+ if (value !== undefined && !(field.type === 'text' && text === ''))
89
+ values[field.name] = value;
90
+ }
91
+ editor.fireTrigger(trigger.id, values);
92
+ }
93
+ </script>
94
+
95
+ <div class="flex flex-col gap-2 rounded-large border border-grey2 p-3">
96
+ <p class="text-sm font-medium" dir="auto">{summary}</p>
97
+ {#each fields as field (field.name)}
98
+ {#if field.type === 'boolean'}
99
+ <SelectField
100
+ label={field.label}
101
+ value={readTyped(field)}
102
+ choices={yesNoChoices}
103
+ help={$t(FIELD_TYPE_MESSAGE_KEYS[field.type])}
104
+ onchange={(text) => (typed[field.name] = text)}
105
+ />
106
+ {:else}
107
+ <TextField
108
+ label={field.label}
109
+ type={field.type === 'number' ? 'number' : 'text'}
110
+ inputmode={field.type === 'number' ? 'decimal' : 'text'}
111
+ maxlength={200}
112
+ help={$t(FIELD_TYPE_MESSAGE_KEYS[field.type])}
113
+ bind:value={() => readTyped(field), (text) => (typed[field.name] = text)}
114
+ />
115
+ {/if}
116
+ {/each}
117
+ <ActionButton size="small" class="self-start" onclick={fire}>
118
+ <Icon name="play" />
119
+ {$t('workflows.test.fire')}
120
+ </ActionButton>
121
+ </div>
@@ -0,0 +1,7 @@
1
+ import type { TriggerNode } from '@widgetic/workflows-engine';
2
+ interface Props {
3
+ trigger: TriggerNode;
4
+ }
5
+ declare const TestTriggerCard: import("svelte").Component<Props, {}, "">;
6
+ type TestTriggerCard = ReturnType<typeof TestTriggerCard>;
7
+ export default TestTriggerCard;