@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,385 @@
1
+ <!--
2
+ The side panel for a trigger block: what the workflow waits for after a composition is shown, and which block comes next.
3
+
4
+ The kinds a composition cannot feed stay in the list, greyed out, with the reason written under the list (a widget that keeps
5
+ no visitor data has no "Input added"; one that reports no actions has no "Action in the widget"), so a person learns what
6
+ to change instead of wondering where a kind went. "Event from your page" and "Scheduled" need nothing from the widget.
7
+
8
+ Words typed here (the name of an event, of its values) are kept when the person leaves the field. A moment in time is
9
+ typed in the workflow's own time zone and stored as the same moment in UTC.
10
+ -->
11
+ <script lang="ts">
12
+ import {
13
+ EVENT_NAME_PATTERN,
14
+ MAX_EVENT_VALUES,
15
+ OUTPUT_PORT,
16
+ SCHEDULE_UNITS
17
+ } from '@widgetic/workflows-engine';
18
+ import type {
19
+ EventValueDeclaration,
20
+ ScheduleConfig,
21
+ ScheduleUnit,
22
+ TriggerNode
23
+ } from '@widgetic/workflows-engine';
24
+ import {
25
+ CAPABILITY_REASON_MESSAGE_KEYS,
26
+ TRIGGER_KIND_MESSAGE_KEYS,
27
+ UNIT_MESSAGE_KEYS
28
+ } from '../../editor/blockLabels.js';
29
+ import { findCompositionOfTrigger } from '../../editor/canvasWords.js';
30
+ import {
31
+ listActionChoices,
32
+ listInputTables,
33
+ readTriggerAvailability
34
+ } from '../../editor/capabilityModel.js';
35
+ import { useEditorState } from '../../editor/editorState.svelte.js';
36
+ import { TRIGGER_KINDS, changeScheduleMode, changeTriggerKind } from '../../editor/graphModel.js';
37
+ import type { TriggerKind } from '../../editor/graphModel.js';
38
+ import { utcIsoToZonedLocal, zonedLocalToUtcIso } from '../../editor/zonedTime.js';
39
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
40
+ import ActionButton from '../ui/ActionButton.svelte';
41
+ import Icon from '../ui/Icon.svelte';
42
+ import SelectField from '../ui/SelectField.svelte';
43
+ import TextField from '../ui/TextField.svelte';
44
+ import type { SelectChoice } from '../ui/types.js';
45
+ import BlockProblems from './BlockProblems.svelte';
46
+ import EventValueRow from './EventValueRow.svelte';
47
+ import NextStepSelect from './NextStepSelect.svelte';
48
+
49
+ interface Props {
50
+ node: TriggerNode;
51
+ }
52
+
53
+ let { node }: Props = $props();
54
+
55
+ const editor = useEditorState();
56
+ const { t } = useWorkflowsLanguage();
57
+
58
+ const trigger = $derived(node.trigger);
59
+
60
+ /** What the API says about the composition this trigger follows (`undefined` while it is not known). */
61
+ const sourceOption = $derived.by(() => {
62
+ const compositionId = findCompositionOfTrigger(editor.graph, node.id);
63
+ return compositionId ? editor.options[compositionId] : undefined;
64
+ });
65
+
66
+ // --- the kind -------------------------------------------------------------------------------------------------
67
+
68
+ const kindChoices = $derived<SelectChoice[]>(
69
+ TRIGGER_KINDS.map((kind) => ({
70
+ value: kind,
71
+ label: $t(TRIGGER_KIND_MESSAGE_KEYS[kind]),
72
+ // The kind it has now stays selectable, so the list can still show it.
73
+ disabled: !readTriggerAvailability(sourceOption, kind).enabled && kind !== trigger.kind
74
+ }))
75
+ );
76
+
77
+ /** Why each kind that is off is off, one sentence a kind. */
78
+ const unavailableNotes = $derived(
79
+ TRIGGER_KINDS.flatMap((kind) => {
80
+ const availability = readTriggerAvailability(sourceOption, kind);
81
+ return availability.enabled
82
+ ? []
83
+ : [
84
+ $t('workflows.trigger.unavailable', {
85
+ kind: $t(TRIGGER_KIND_MESSAGE_KEYS[kind]),
86
+ reason: $t(CAPABILITY_REASON_MESSAGE_KEYS[availability.reason])
87
+ })
88
+ ];
89
+ })
90
+ );
91
+
92
+ function chooseKind(kind: string): void {
93
+ editor.replaceBlock(changeTriggerKind(node, kind as TriggerKind));
94
+ }
95
+
96
+ // --- Input added ----------------------------------------------------------------------------------------------
97
+
98
+ const tableChoices = $derived.by<SelectChoice[]>(() => {
99
+ if (trigger.kind !== 'input') return [];
100
+ const tables = listInputTables(sourceOption);
101
+ const choices: SelectChoice[] = [
102
+ { value: '', label: $t('workflows.trigger.chooseOne') },
103
+ ...tables.map((table) => ({ value: table, label: table }))
104
+ ];
105
+ // A table the widget no longer has is still shown, marked, so the person sees what the draft holds.
106
+ if (trigger.table !== '' && !tables.includes(trigger.table)) {
107
+ choices.push({
108
+ value: trigger.table,
109
+ label: $t('workflows.trigger.notFound', { name: trigger.table })
110
+ });
111
+ }
112
+ return choices;
113
+ });
114
+
115
+ /** The values of the chosen table a condition after this trigger can read, by the widget's names for them. */
116
+ const readableColumns = $derived(
117
+ trigger.kind === 'input' && sourceOption
118
+ ? sourceOption.inputs.fields
119
+ .filter((field) => field.table === trigger.table)
120
+ .map((field) => field.label)
121
+ : []
122
+ );
123
+
124
+ // --- Action in the widget -------------------------------------------------------------------------------------
125
+
126
+ const actionChoices = $derived.by<SelectChoice[]>(() => {
127
+ if (trigger.kind !== 'action') return [];
128
+ const items = listActionChoices(sourceOption);
129
+ const choices: SelectChoice[] = [
130
+ { value: '', label: $t('workflows.trigger.chooseOne') },
131
+ ...items.map((item) => ({ value: item.id, label: item.label }))
132
+ ];
133
+ if (trigger.actionId !== '' && !items.some((item) => item.id === trigger.actionId)) {
134
+ choices.push({
135
+ value: trigger.actionId,
136
+ label: $t('workflows.trigger.notFound', { name: trigger.actionId })
137
+ });
138
+ }
139
+ return choices;
140
+ });
141
+
142
+ // --- Event from your page -------------------------------------------------------------------------------------
143
+
144
+ let eventNameDraft = $derived(trigger.kind === 'pageEvent' ? trigger.name : '');
145
+
146
+ const eventNameProblem = $derived(
147
+ eventNameDraft.trim() !== '' && !EVENT_NAME_PATTERN.test(eventNameDraft)
148
+ ? $t('workflows.event.nameInvalid')
149
+ : undefined
150
+ );
151
+
152
+ function commitEventName(): void {
153
+ if (trigger.kind !== 'pageEvent') return;
154
+ const name = eventNameDraft.trim();
155
+ if (name !== trigger.name) editor.replaceBlock({ ...node, trigger: { ...trigger, name } });
156
+ }
157
+
158
+ function changeEventValue(index: number, next: EventValueDeclaration): void {
159
+ if (trigger.kind !== 'pageEvent') return;
160
+ editor.replaceBlock({
161
+ ...node,
162
+ trigger: {
163
+ ...trigger,
164
+ values: trigger.values.map((value, position) => (position === index ? next : value))
165
+ }
166
+ });
167
+ }
168
+
169
+ function removeEventValue(index: number): void {
170
+ if (trigger.kind !== 'pageEvent') return;
171
+ editor.replaceBlock({
172
+ ...node,
173
+ trigger: { ...trigger, values: trigger.values.filter((_, position) => position !== index) }
174
+ });
175
+ }
176
+
177
+ function addEventValue(): void {
178
+ if (trigger.kind !== 'pageEvent' || trigger.values.length >= MAX_EVENT_VALUES) return;
179
+ editor.replaceBlock({
180
+ ...node,
181
+ trigger: { ...trigger, values: [...trigger.values, { name: '', type: 'text' }] }
182
+ });
183
+ }
184
+
185
+ // --- Scheduled ------------------------------------------------------------------------------------------------
186
+
187
+ const schedule = $derived(trigger.kind === 'scheduled' ? trigger.schedule : null);
188
+
189
+ const scheduleModeChoices = $derived<SelectChoice[]>([
190
+ { value: 'after', label: $t('workflows.schedule.modeAfter') },
191
+ { value: 'at', label: $t('workflows.schedule.modeAt') }
192
+ ]);
193
+
194
+ const unitChoices = $derived<SelectChoice[]>(
195
+ SCHEDULE_UNITS.map((unit) => ({ value: unit, label: $t(UNIT_MESSAGE_KEYS[unit]) }))
196
+ );
197
+
198
+ let waitAmountDraft = $derived(schedule?.mode === 'after' ? String(schedule.amount) : '1');
199
+ let momentDraft = $derived(
200
+ schedule?.mode === 'at' ? (utcIsoToZonedLocal(schedule.at, editor.timezone) ?? '') : ''
201
+ );
202
+ let momentProblem = $state<string | undefined>(undefined);
203
+
204
+ function replaceSchedule(next: ScheduleConfig): void {
205
+ editor.replaceBlock({ ...node, trigger: { kind: 'scheduled', schedule: next } });
206
+ }
207
+
208
+ function chooseScheduleMode(mode: string): void {
209
+ if (!schedule) return;
210
+ momentProblem = undefined;
211
+ replaceSchedule(changeScheduleMode(schedule, mode as ScheduleConfig['mode']));
212
+ }
213
+
214
+ function commitWaitAmount(): void {
215
+ if (schedule?.mode !== 'after') return;
216
+ const amount = Number(waitAmountDraft);
217
+ // A wait is a whole number of units, at least one; anything else is kept as typed so the check can say what is wrong.
218
+ replaceSchedule({ ...schedule, amount: Number.isFinite(amount) ? amount : 0 });
219
+ }
220
+
221
+ function chooseUnit(unit: string): void {
222
+ if (schedule?.mode !== 'after') return;
223
+ replaceSchedule({ ...schedule, unit: unit as ScheduleUnit });
224
+ }
225
+
226
+ function commitMoment(): void {
227
+ if (schedule?.mode !== 'at') return;
228
+ const moment = zonedLocalToUtcIso(momentDraft, editor.timezone);
229
+ if (moment === null) {
230
+ momentProblem = $t('workflows.schedule.invalidMoment');
231
+ return;
232
+ }
233
+ momentProblem = undefined;
234
+ if (moment !== schedule.at) replaceSchedule({ mode: 'at', at: moment });
235
+ }
236
+ </script>
237
+
238
+ <div class="flex flex-col gap-4">
239
+ <div>
240
+ <h3 class="text-sm font-semibold">{$t('workflows.trigger.heading')}</h3>
241
+ <p class="text-xs text-ink-muted">{$t('workflows.trigger.help')}</p>
242
+ </div>
243
+
244
+ <BlockProblems nodeId={node.id} />
245
+
246
+ <SelectField
247
+ label={$t('workflows.trigger.kindLabel')}
248
+ value={trigger.kind}
249
+ choices={kindChoices}
250
+ disabled={editor.isReadOnly}
251
+ onchange={chooseKind}
252
+ />
253
+ {#if unavailableNotes.length > 0}
254
+ <ul class="flex flex-col gap-1 text-xs text-ink-muted">
255
+ {#each unavailableNotes as note (note)}
256
+ <li>{note}</li>
257
+ {/each}
258
+ </ul>
259
+ {/if}
260
+
261
+ {#if trigger.kind === 'input'}
262
+ <SelectField
263
+ label={$t('workflows.trigger.tableLabel')}
264
+ value={trigger.table}
265
+ choices={tableChoices}
266
+ disabled={editor.isReadOnly}
267
+ help={$t('workflows.trigger.tableHelp')}
268
+ onchange={(table) => editor.replaceBlock({ ...node, trigger: { kind: 'input', table } })}
269
+ />
270
+ {#if trigger.table !== ''}
271
+ <p class="text-xs text-ink-muted">
272
+ {readableColumns.length > 0
273
+ ? $t('workflows.trigger.readableValues', { values: readableColumns.join(', ') })
274
+ : $t('workflows.trigger.noReadableValues')}
275
+ </p>
276
+ {/if}
277
+ {:else if trigger.kind === 'action'}
278
+ <SelectField
279
+ label={$t('workflows.trigger.actionLabel')}
280
+ value={trigger.actionId}
281
+ choices={actionChoices}
282
+ disabled={editor.isReadOnly}
283
+ help={$t('workflows.trigger.actionHelp')}
284
+ onchange={(actionId) =>
285
+ editor.replaceBlock({ ...node, trigger: { kind: 'action', actionId } })}
286
+ />
287
+ {:else if trigger.kind === 'pageEvent'}
288
+ <TextField
289
+ label={$t('workflows.event.nameLabel')}
290
+ placeholder={$t('workflows.event.namePlaceholder')}
291
+ help={$t('workflows.event.nameHelp')}
292
+ problem={eventNameProblem}
293
+ maxlength={64}
294
+ disabled={editor.isReadOnly}
295
+ bind:value={eventNameDraft}
296
+ onchange={commitEventName}
297
+ />
298
+ <div class="flex flex-col gap-2">
299
+ <h4 class="text-xs font-medium">{$t('workflows.event.valuesHeading')}</h4>
300
+ <p class="text-xs text-ink-muted">{$t('workflows.event.valuesHelp')}</p>
301
+ {#each trigger.values as value, index (index)}
302
+ <EventValueRow
303
+ {value}
304
+ {index}
305
+ disabled={editor.isReadOnly}
306
+ onchange={(next) => changeEventValue(index, next)}
307
+ onremove={() => removeEventValue(index)}
308
+ />
309
+ {/each}
310
+ {#if !editor.isReadOnly}
311
+ <ActionButton
312
+ size="small"
313
+ class="self-start"
314
+ disabled={trigger.values.length >= MAX_EVENT_VALUES}
315
+ onclick={addEventValue}
316
+ >
317
+ <Icon name="plus" />
318
+ {$t('workflows.event.addValue')}
319
+ </ActionButton>
320
+ {/if}
321
+ </div>
322
+ <p class="text-xs text-ink-muted">{$t('workflows.event.howToSend')}</p>
323
+ {:else if schedule}
324
+ <SelectField
325
+ label={$t('workflows.schedule.modeLabel')}
326
+ value={schedule.mode}
327
+ choices={scheduleModeChoices}
328
+ disabled={editor.isReadOnly}
329
+ onchange={chooseScheduleMode}
330
+ />
331
+ {#if schedule.mode === 'after'}
332
+ <div class="flex items-start gap-2">
333
+ <TextField
334
+ class="w-24"
335
+ type="number"
336
+ min={1}
337
+ inputmode="numeric"
338
+ label={$t('workflows.schedule.amountLabel')}
339
+ disabled={editor.isReadOnly}
340
+ bind:value={waitAmountDraft}
341
+ onchange={commitWaitAmount}
342
+ />
343
+ <SelectField
344
+ class="flex-1"
345
+ label={$t('workflows.schedule.unitLabel')}
346
+ value={schedule.unit}
347
+ choices={unitChoices}
348
+ disabled={editor.isReadOnly}
349
+ onchange={chooseUnit}
350
+ />
351
+ </div>
352
+ <p class="text-xs text-ink-muted">{$t('workflows.schedule.afterHelp')}</p>
353
+ {:else}
354
+ <TextField
355
+ type="datetime-local"
356
+ label={$t('workflows.schedule.momentLabel')}
357
+ help={$t('workflows.schedule.momentHelp', { zone: editor.timezone })}
358
+ problem={momentProblem}
359
+ disabled={editor.isReadOnly}
360
+ bind:value={momentDraft}
361
+ onchange={commitMoment}
362
+ />
363
+ {/if}
364
+ {/if}
365
+
366
+ <NextStepSelect
367
+ sourceId={node.id}
368
+ sourcePort={OUTPUT_PORT}
369
+ label={$t('workflows.trigger.nextLabel')}
370
+ emptyLabel={$t('workflows.trigger.nextNone')}
371
+ help={$t('workflows.trigger.nextHelp')}
372
+ />
373
+
374
+ {#if !editor.isReadOnly}
375
+ <ActionButton
376
+ variant="danger"
377
+ size="small"
378
+ class="self-start"
379
+ onclick={() => editor.removeBlock(node.id)}
380
+ >
381
+ <Icon name="trash" />
382
+ {$t('workflows.panel.removeBlock')}
383
+ </ActionButton>
384
+ {/if}
385
+ </div>
@@ -0,0 +1,7 @@
1
+ import type { TriggerNode } from '@widgetic/workflows-engine';
2
+ interface Props {
3
+ node: TriggerNode;
4
+ }
5
+ declare const TriggerForm: import("svelte").Component<Props, {}, "">;
6
+ type TriggerForm = ReturnType<typeof TriggerForm>;
7
+ export default TriggerForm;
@@ -0,0 +1,123 @@
1
+ <!--
2
+ Version history: every publish made a version that never changes. The list shows which one is live; a version can be looked
3
+ at on the canvas (read-only), and restored, which copies it into the draft (publishing it is a separate step), so nothing
4
+ is ever lost by going back.
5
+
6
+ Visitors who were part-way through finish on the version they started on, so older versions are not gone from the embed
7
+ for a while after a newer one is published; the help line says so.
8
+ -->
9
+ <script lang="ts">
10
+ import { formatMomentInZone } from '../../editor/blockLabels.js';
11
+ import { useEditorState } from '../../editor/editorState.svelte.js';
12
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
13
+ import ActionButton from '../ui/ActionButton.svelte';
14
+ import ConfirmDialog from '../ui/ConfirmDialog.svelte';
15
+ import Icon from '../ui/Icon.svelte';
16
+
17
+ const editor = useEditorState();
18
+ const { t, locale } = useWorkflowsLanguage();
19
+
20
+ let isAskingToRestore = $state(false);
21
+
22
+ const viewing = $derived(editor.viewing);
23
+
24
+ async function restore(): Promise<void> {
25
+ await editor.restoreViewedVersion();
26
+ isAskingToRestore = false;
27
+ }
28
+ </script>
29
+
30
+ <div class="flex flex-col gap-4">
31
+ <div class="flex items-start justify-between gap-2">
32
+ <div>
33
+ <h3 class="text-sm font-semibold">{$t('workflows.history.heading')}</h3>
34
+ <p class="text-xs text-ink-muted">{$t('workflows.history.help')}</p>
35
+ </div>
36
+ <ActionButton
37
+ variant="ghost"
38
+ iconOnly
39
+ ariaLabel={$t('workflows.history.close')}
40
+ title={$t('workflows.history.close')}
41
+ onclick={() => editor.closeHistory()}
42
+ >
43
+ <Icon name="close" />
44
+ </ActionButton>
45
+ </div>
46
+
47
+ <!-- The banner above the canvas says which version is shown and has the way back to the draft; here is what can be done with it. -->
48
+ {#if viewing}
49
+ <div class="flex flex-wrap gap-2">
50
+ <ActionButton
51
+ variant="primary"
52
+ size="small"
53
+ disabled={!editor.canChangeWorkflow || editor.status === 'archived'}
54
+ onclick={() => (isAskingToRestore = true)}
55
+ >
56
+ {$t('workflows.history.restore')}
57
+ </ActionButton>
58
+ </div>
59
+ {/if}
60
+
61
+ {#if editor.versionsState === 'loading' && editor.versions === null}
62
+ <p class="text-xs text-ink-muted" role="status">{$t('workflows.common.loading')}</p>
63
+ {:else if editor.versionsState === 'failed'}
64
+ <div class="flex flex-col items-start gap-2">
65
+ <p class="text-xs text-error" role="alert">{$t('workflows.history.failed')}</p>
66
+ <ActionButton size="small" onclick={() => void editor.loadVersions()}
67
+ >{$t('workflows.error.retry')}</ActionButton
68
+ >
69
+ </div>
70
+ {:else if editor.versions !== null && editor.versions.length === 0}
71
+ <p class="text-xs text-ink-muted">{$t('workflows.history.none')}</p>
72
+ {:else if editor.versions !== null}
73
+ <ul class="flex flex-col gap-2">
74
+ {#each editor.versions as version (version.id)}
75
+ {@const isShown = viewing?.id === version.id}
76
+ <li
77
+ class="flex items-start justify-between gap-2 rounded-medium border px-3 py-2 {isShown
78
+ ? 'border-primary-green'
79
+ : 'border-grey2'}"
80
+ >
81
+ <div class="flex min-w-0 flex-col gap-0.5">
82
+ <span class="flex items-center gap-2 text-sm font-medium">
83
+ {$t('workflows.history.version', { number: version.versionNumber })}
84
+ {#if version.isLive}
85
+ <span
86
+ class="rounded-pill border border-primary-green px-2 text-xs font-normal text-primary-green"
87
+ >{$t('workflows.history.live')}</span
88
+ >
89
+ {/if}
90
+ </span>
91
+ <span class="text-xs text-ink-muted"
92
+ >{formatMomentInZone(version.publishedAt, $locale, editor.timezone)}</span
93
+ >
94
+ {#if version.publishedBy?.name}
95
+ <span class="truncate text-xs text-ink-muted" dir="auto"
96
+ >{$t('workflows.history.by', { name: version.publishedBy.name })}</span
97
+ >
98
+ {/if}
99
+ </div>
100
+ <ActionButton
101
+ size="small"
102
+ pressed={isShown}
103
+ disabled={editor.busy !== null}
104
+ onclick={() => void editor.viewVersion(version.id)}
105
+ >
106
+ {$t('workflows.history.view')}
107
+ </ActionButton>
108
+ </li>
109
+ {/each}
110
+ </ul>
111
+ {/if}
112
+ </div>
113
+
114
+ {#if isAskingToRestore && viewing}
115
+ <ConfirmDialog
116
+ title={$t('workflows.history.restoreTitle', { number: viewing.versionNumber })}
117
+ message={$t('workflows.history.restoreMessage', { number: viewing.versionNumber })}
118
+ confirmLabel={$t('workflows.history.restore')}
119
+ busy={editor.busy === 'restoring'}
120
+ onconfirm={() => void restore()}
121
+ oncancel={() => (isAskingToRestore = false)}
122
+ />
123
+ {/if}
@@ -0,0 +1,3 @@
1
+ declare const VersionHistory: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type VersionHistory = ReturnType<typeof VersionHistory>;
3
+ export default VersionHistory;
@@ -0,0 +1,85 @@
1
+ <!--
2
+ A button of the screen. One place decides how a button looks (the palette, the corners, the focus ring), so every button
3
+ of the screen answers a theme the same way. The words on it are given by the caller, already in the page's language.
4
+
5
+ `iconOnly` makes it a square with a picture and no words: the caller must then give `ariaLabel`, because a picture says
6
+ nothing to a screen reader.
7
+ -->
8
+ <script lang="ts">
9
+ import type { Snippet } from 'svelte';
10
+
11
+ interface Props {
12
+ /** How loud the button is: `primary` is the one thing to do on a screen; `danger` takes something away. */
13
+ variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
14
+ size?: 'small' | 'medium';
15
+ type?: 'button' | 'submit';
16
+ disabled?: boolean;
17
+ /** For a button that stays on or off (a tab of tools, a toggle): whether it is on. */
18
+ pressed?: boolean;
19
+ /** A square button with only a picture. Needs `ariaLabel`. */
20
+ iconOnly?: boolean;
21
+ /** The name of the button for a screen reader, when it has no words of its own. */
22
+ ariaLabel?: string;
23
+ /** A tip on hover, and the name of the button when it has none. */
24
+ title?: string;
25
+ /** Whether the button opens a menu, and whether that menu is open. */
26
+ hasPopup?: 'menu' | 'dialog';
27
+ expanded?: boolean;
28
+ /** The element this button controls, for a screen reader. */
29
+ controls?: string;
30
+ class?: string;
31
+ onclick?: (event: MouseEvent) => void;
32
+ children: Snippet;
33
+ }
34
+
35
+ let {
36
+ variant = 'secondary',
37
+ size = 'medium',
38
+ type = 'button',
39
+ disabled = false,
40
+ pressed,
41
+ iconOnly = false,
42
+ ariaLabel,
43
+ title,
44
+ hasPopup,
45
+ expanded,
46
+ controls,
47
+ class: className = '',
48
+ onclick,
49
+ children
50
+ }: Props = $props();
51
+
52
+ const variantClasses = {
53
+ primary: 'bg-primary-green text-white hover:opacity-90',
54
+ secondary: 'border border-grey2 bg-white text-ink-primary hover:border-ink-subtle',
55
+ ghost: 'border border-transparent text-ink-primary hover:border-grey2',
56
+ danger: 'border border-error bg-white text-error hover:opacity-90'
57
+ };
58
+
59
+ const sizeClasses = $derived(
60
+ iconOnly
61
+ ? size === 'small'
62
+ ? 'size-7'
63
+ : 'size-9'
64
+ : size === 'small'
65
+ ? 'px-2.5 py-1 text-xs'
66
+ : 'px-4 py-2 text-sm'
67
+ );
68
+ </script>
69
+
70
+ <button
71
+ {type}
72
+ {disabled}
73
+ {title}
74
+ class="inline-flex shrink-0 items-center justify-center gap-2 rounded-medium font-medium whitespace-nowrap transition-opacity focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {variantClasses[
75
+ variant
76
+ ]} {sizeClasses} {className}"
77
+ aria-label={ariaLabel}
78
+ aria-pressed={pressed}
79
+ aria-haspopup={hasPopup}
80
+ aria-expanded={expanded}
81
+ aria-controls={controls}
82
+ {onclick}
83
+ >
84
+ {@render children()}
85
+ </button>
@@ -0,0 +1,27 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** How loud the button is: `primary` is the one thing to do on a screen; `danger` takes something away. */
4
+ variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
5
+ size?: 'small' | 'medium';
6
+ type?: 'button' | 'submit';
7
+ disabled?: boolean;
8
+ /** For a button that stays on or off (a tab of tools, a toggle): whether it is on. */
9
+ pressed?: boolean;
10
+ /** A square button with only a picture. Needs `ariaLabel`. */
11
+ iconOnly?: boolean;
12
+ /** The name of the button for a screen reader, when it has no words of its own. */
13
+ ariaLabel?: string;
14
+ /** A tip on hover, and the name of the button when it has none. */
15
+ title?: string;
16
+ /** Whether the button opens a menu, and whether that menu is open. */
17
+ hasPopup?: 'menu' | 'dialog';
18
+ expanded?: boolean;
19
+ /** The element this button controls, for a screen reader. */
20
+ controls?: string;
21
+ class?: string;
22
+ onclick?: (event: MouseEvent) => void;
23
+ children: Snippet;
24
+ }
25
+ declare const ActionButton: import("svelte").Component<Props, {}, "">;
26
+ type ActionButton = ReturnType<typeof ActionButton>;
27
+ export default ActionButton;
@@ -0,0 +1,52 @@
1
+ <!--
2
+ A question with two answers, for a thing that cannot be taken back or that changes what visitors see. The caller says what
3
+ is about to happen and what the button that agrees is called; "Cancel" is always there and is where the focus starts, so
4
+ that an Enter pressed too quickly does not agree.
5
+ -->
6
+ <script lang="ts">
7
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
8
+ import ActionButton from './ActionButton.svelte';
9
+ import Modal from './Modal.svelte';
10
+
11
+ interface Props {
12
+ title: string;
13
+ /** What is about to happen, in a sentence or two. */
14
+ message: string;
15
+ /** What the button that agrees says (`Delete`, `Publish`), never a bare "OK". */
16
+ confirmLabel: string;
17
+ /** `danger` for a thing that takes something away. */
18
+ tone?: 'normal' | 'danger';
19
+ /** While the thing is being done: both buttons wait and the window cannot be dismissed. */
20
+ busy?: boolean;
21
+ onconfirm: () => void;
22
+ oncancel: () => void;
23
+ }
24
+
25
+ let {
26
+ title,
27
+ message,
28
+ confirmLabel,
29
+ tone = 'normal',
30
+ busy = false,
31
+ onconfirm,
32
+ oncancel
33
+ }: Props = $props();
34
+
35
+ const { t } = useWorkflowsLanguage();
36
+ </script>
37
+
38
+ <Modal {title} size="small" {busy} onclose={oncancel}>
39
+ <p class="text-sm text-ink-primary">{message}</p>
40
+ {#snippet footer()}
41
+ <ActionButton variant="secondary" disabled={busy} onclick={oncancel}
42
+ >{$t('workflows.common.cancel')}</ActionButton
43
+ >
44
+ <ActionButton
45
+ variant={tone === 'danger' ? 'danger' : 'primary'}
46
+ disabled={busy}
47
+ onclick={onconfirm}
48
+ >
49
+ {confirmLabel}
50
+ </ActionButton>
51
+ {/snippet}
52
+ </Modal>