@widgetic/workflows 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +107 -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 +168 -0
  5. package/dist/api/types.js +3 -0
  6. package/dist/api/workflowsApi.d.ts +109 -0
  7. package/dist/api/workflowsApi.js +657 -0
  8. package/dist/components/Workflows.svelte +41 -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 +87 -0
  13. package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -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/EditorBanners.svelte +143 -0
  31. package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
  32. package/dist/components/editor/EditorCanvasArea.svelte +85 -0
  33. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
  34. package/dist/components/editor/EditorTabs.svelte +81 -0
  35. package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
  36. package/dist/components/editor/EditorTopBar.svelte +132 -0
  37. package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
  38. package/dist/components/editor/RunsTab.svelte +256 -0
  39. package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
  40. package/dist/components/editor/SettingsTab.svelte +180 -0
  41. package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
  42. package/dist/components/editor/WorkflowEditor.svelte +185 -0
  43. package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
  44. package/dist/components/index.d.ts +0 -2
  45. package/dist/components/index.js +0 -2
  46. package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
  47. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
  48. package/dist/components/list/WorkflowList.svelte +204 -0
  49. package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
  50. package/dist/components/list/WorkflowRow.svelte +191 -0
  51. package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
  52. package/dist/components/panel/BlockProblems.svelte +47 -0
  53. package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
  54. package/dist/components/panel/CompositionForm.svelte +127 -0
  55. package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
  56. package/dist/components/panel/CompositionPicker.svelte +179 -0
  57. package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
  58. package/dist/components/panel/ConditionForm.svelte +105 -0
  59. package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
  60. package/dist/components/panel/EventValueRow.svelte +85 -0
  61. package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
  62. package/dist/components/panel/NextStepSelect.svelte +70 -0
  63. package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
  64. package/dist/components/panel/ProblemsList.svelte +101 -0
  65. package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
  66. package/dist/components/panel/RuleCard.svelte +191 -0
  67. package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
  68. package/dist/components/panel/SidePanel.svelte +82 -0
  69. package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
  70. package/dist/components/panel/TestRow.svelte +150 -0
  71. package/dist/components/panel/TestRow.svelte.d.ts +15 -0
  72. package/dist/components/panel/TestRunPanel.svelte +85 -0
  73. package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
  74. package/dist/components/panel/TestTriggerCard.svelte +121 -0
  75. package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
  76. package/dist/components/panel/TriggerForm.svelte +385 -0
  77. package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
  78. package/dist/components/panel/VersionHistory.svelte +123 -0
  79. package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
  80. package/dist/components/ui/ActionButton.svelte +85 -0
  81. package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
  82. package/dist/components/ui/ConfirmDialog.svelte +52 -0
  83. package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
  84. package/dist/components/ui/Icon.svelte +32 -0
  85. package/dist/components/ui/Icon.svelte.d.ts +9 -0
  86. package/dist/components/ui/Menu.svelte +211 -0
  87. package/dist/components/ui/Menu.svelte.d.ts +21 -0
  88. package/dist/components/ui/Modal.svelte +129 -0
  89. package/dist/components/ui/Modal.svelte.d.ts +13 -0
  90. package/dist/components/ui/Notice.svelte +36 -0
  91. package/dist/components/ui/Notice.svelte.d.ts +11 -0
  92. package/dist/components/ui/SelectField.svelte +74 -0
  93. package/dist/components/ui/SelectField.svelte.d.ts +16 -0
  94. package/dist/components/ui/StatusBadge.svelte +41 -0
  95. package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
  96. package/dist/components/ui/TextField.svelte +97 -0
  97. package/dist/components/ui/TextField.svelte.d.ts +29 -0
  98. package/dist/components/ui/icons.d.ts +34 -0
  99. package/dist/components/ui/icons.js +54 -0
  100. package/dist/components/ui/types.d.ts +26 -0
  101. package/dist/components/ui/types.js +1 -0
  102. package/dist/editor/apiErrorText.d.ts +10 -0
  103. package/dist/editor/apiErrorText.js +53 -0
  104. package/dist/editor/autosave.d.ts +47 -0
  105. package/dist/editor/autosave.js +119 -0
  106. package/dist/editor/blockLabels.d.ts +91 -0
  107. package/dist/editor/blockLabels.js +196 -0
  108. package/dist/editor/canvasContext.d.ts +52 -0
  109. package/dist/editor/canvasContext.js +37 -0
  110. package/dist/editor/canvasWords.d.ts +24 -0
  111. package/dist/editor/canvasWords.js +40 -0
  112. package/dist/editor/capabilityModel.d.ts +46 -0
  113. package/dist/editor/capabilityModel.js +113 -0
  114. package/dist/editor/editorState.svelte.d.ts +220 -0
  115. package/dist/editor/editorState.svelte.js +713 -0
  116. package/dist/editor/flowAdapter.d.ts +59 -0
  117. package/dist/editor/flowAdapter.js +166 -0
  118. package/dist/editor/formatCount.d.ts +5 -0
  119. package/dist/editor/formatCount.js +15 -0
  120. package/dist/editor/graphDiff.d.ts +27 -0
  121. package/dist/editor/graphDiff.js +64 -0
  122. package/dist/editor/graphModel.d.ts +154 -0
  123. package/dist/editor/graphModel.js +457 -0
  124. package/dist/editor/issueText.d.ts +64 -0
  125. package/dist/editor/issueText.js +101 -0
  126. package/dist/editor/listState.svelte.d.ts +82 -0
  127. package/dist/editor/listState.svelte.js +250 -0
  128. package/dist/editor/statsRange.d.ts +26 -0
  129. package/dist/editor/statsRange.js +41 -0
  130. package/dist/editor/testRun.d.ts +36 -0
  131. package/dist/editor/testRun.js +74 -0
  132. package/dist/editor/zonedTime.d.ts +20 -0
  133. package/dist/editor/zonedTime.js +134 -0
  134. package/dist/i18n/language.d.ts +3 -3
  135. package/dist/i18n/messages.d.ts +396 -4
  136. package/dist/i18n/messages.js +421 -8
  137. package/dist/index.d.ts +2 -1
  138. package/dist/index.js +1 -1
  139. package/dist/types/index.d.ts +31 -3
  140. package/package.json +5 -1
@@ -0,0 +1,74 @@
1
+ <!--
2
+ A choice of one among several, with its label above it. It is the browser's own select, so it opens the way every select of
3
+ the person's device does (a wheel on a phone, the keyboard everywhere) and needs nothing to float above the page.
4
+
5
+ The choices come with their words already in the page's language. A choice whose words were written by a person (the
6
+ name of a composition, a column) keeps the direction of that text.
7
+ -->
8
+ <script lang="ts">
9
+ import type { SelectChoice } from './types.js';
10
+
11
+ interface Props {
12
+ label: string;
13
+ value: string;
14
+ choices: readonly SelectChoice[];
15
+ help?: string;
16
+ problem?: string;
17
+ disabled?: boolean;
18
+ /** Hides the label but keeps it for a screen reader, when the surroundings already say what is chosen. */
19
+ hideLabel?: boolean;
20
+ class?: string;
21
+ onchange?: (value: string) => void;
22
+ }
23
+
24
+ let {
25
+ label,
26
+ value = $bindable(),
27
+ choices,
28
+ help,
29
+ problem,
30
+ disabled = false,
31
+ hideLabel = false,
32
+ class: className = '',
33
+ onchange
34
+ }: Props = $props();
35
+
36
+ const fieldId = $props.id();
37
+ const helpId = $derived(`${fieldId}-help`);
38
+ const problemId = $derived(`${fieldId}-problem`);
39
+ const describedBy = $derived(
40
+ [help ? helpId : '', problem ? problemId : ''].filter(Boolean).join(' ') || undefined
41
+ );
42
+
43
+ /** What the browser reports when the person picks: the value of the choice, which goes up to the one that listens. */
44
+ function reportChoice(event: Event & { currentTarget: HTMLSelectElement }): void {
45
+ onchange?.(event.currentTarget.value);
46
+ }
47
+ </script>
48
+
49
+ <div class="flex min-w-0 flex-col gap-1 text-start {className}">
50
+ <label for={fieldId} class={hideLabel ? 'sr-only' : 'text-xs font-medium text-ink-primary'}
51
+ >{label}</label
52
+ >
53
+ <select
54
+ id={fieldId}
55
+ bind:value
56
+ {disabled}
57
+ class="w-full min-w-0 rounded-medium border bg-white px-3 py-2 text-sm text-ink-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {problem
58
+ ? 'border-error'
59
+ : 'border-grey2'}"
60
+ aria-invalid={problem ? true : undefined}
61
+ aria-describedby={describedBy}
62
+ onchange={reportChoice}
63
+ >
64
+ {#each choices as choice (choice.value)}
65
+ <option value={choice.value} disabled={choice.disabled}>{choice.label}</option>
66
+ {/each}
67
+ </select>
68
+ {#if help}
69
+ <p id={helpId} class="text-xs text-ink-muted">{help}</p>
70
+ {/if}
71
+ {#if problem}
72
+ <p id={problemId} class="text-xs text-error">{problem}</p>
73
+ {/if}
74
+ </div>
@@ -0,0 +1,16 @@
1
+ import type { SelectChoice } from './types.js';
2
+ interface Props {
3
+ label: string;
4
+ value: string;
5
+ choices: readonly SelectChoice[];
6
+ help?: string;
7
+ problem?: string;
8
+ disabled?: boolean;
9
+ /** Hides the label but keeps it for a screen reader, when the surroundings already say what is chosen. */
10
+ hideLabel?: boolean;
11
+ class?: string;
12
+ onchange?: (value: string) => void;
13
+ }
14
+ declare const SelectField: import("svelte").Component<Props, {}, "value">;
15
+ type SelectField = ReturnType<typeof SelectField>;
16
+ export default SelectField;
@@ -0,0 +1,41 @@
1
+ <!--
2
+ Where a workflow stands, as a dot and a word: live (visitors move through it), a draft that was never published, paused
3
+ (the embed shows only its first composition), archived. The word always carries the meaning; the dot only helps the eye,
4
+ so a person who cannot tell the colours apart loses nothing.
5
+ -->
6
+ <script lang="ts">
7
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
8
+ import type { WorkflowStatus } from '../../api/types.js';
9
+
10
+ interface Props {
11
+ status: WorkflowStatus;
12
+ /** Whether the draft holds changes that are not live yet (shown next to a live workflow). */
13
+ hasUnpublishedChanges?: boolean;
14
+ }
15
+
16
+ let { status, hasUnpublishedChanges = false }: Props = $props();
17
+
18
+ const { t } = useWorkflowsLanguage();
19
+
20
+ const dotClasses: Record<WorkflowStatus, string> = {
21
+ draft: 'bg-ink-subtle',
22
+ live: 'bg-primary-green',
23
+ paused: 'bg-ink-muted',
24
+ archived: 'bg-ink-subtle'
25
+ };
26
+
27
+ const wordKeys = {
28
+ draft: 'workflows.status.draft',
29
+ live: 'workflows.status.live',
30
+ paused: 'workflows.status.paused',
31
+ archived: 'workflows.status.archived'
32
+ } as const;
33
+ </script>
34
+
35
+ <span class="inline-flex items-center gap-1.5 text-xs text-ink-primary">
36
+ <span class="size-2 shrink-0 rounded-pill {dotClasses[status]}" aria-hidden="true"></span>
37
+ <span>{$t(wordKeys[status])}</span>
38
+ {#if hasUnpublishedChanges && status === 'live'}
39
+ <span class="text-ink-muted">· {$t('workflows.status.unpublishedChanges')}</span>
40
+ {/if}
41
+ </span>
@@ -0,0 +1,9 @@
1
+ import type { WorkflowStatus } from '../../api/types.js';
2
+ interface Props {
3
+ status: WorkflowStatus;
4
+ /** Whether the draft holds changes that are not live yet (shown next to a live workflow). */
5
+ hasUnpublishedChanges?: boolean;
6
+ }
7
+ declare const StatusBadge: import("svelte").Component<Props, {}, "">;
8
+ type StatusBadge = ReturnType<typeof StatusBadge>;
9
+ export default StatusBadge;
@@ -0,0 +1,97 @@
1
+ <!--
2
+ A line of text to fill in, with its label above it, an optional line of help and the problem with the answer, if any.
3
+ The label is tied to the field (for a screen reader and for a click on the label), and the help and the problem are
4
+ read with the field.
5
+
6
+ What a person types is theirs and may be in any language: the field takes the direction of its own text (`dir="auto"`),
7
+ whichever way the screen is read.
8
+ -->
9
+ <script lang="ts">
10
+ interface Props {
11
+ label: string;
12
+ value: string;
13
+ placeholder?: string;
14
+ /** A line under the field that says what to fill in. */
15
+ help?: string;
16
+ /** What is wrong with the answer, already in the page's language. */
17
+ problem?: string;
18
+ type?: 'text' | 'number' | 'search' | 'datetime-local' | 'date';
19
+ disabled?: boolean;
20
+ readonly?: boolean;
21
+ maxlength?: number;
22
+ inputmode?: 'text' | 'numeric' | 'decimal' | 'search';
23
+ /** The smallest and the largest value of a number, or the first and last day of a date. */
24
+ min?: string | number;
25
+ max?: string | number;
26
+ /** Hides the label but keeps it for a screen reader, when the surroundings already say what the field is. */
27
+ hideLabel?: boolean;
28
+ /** The field is the first thing to fill in when its dialog opens. */
29
+ autofocus?: boolean;
30
+ class?: string;
31
+ /** Called for every letter typed (a search that follows the typing). */
32
+ oninput?: () => void;
33
+ /** Called when the person is done with the field (Enter, or leaving it): the moment to keep what they typed. */
34
+ onchange?: () => void;
35
+ }
36
+
37
+ let {
38
+ label,
39
+ value = $bindable(),
40
+ placeholder,
41
+ help,
42
+ problem,
43
+ type = 'text',
44
+ disabled = false,
45
+ readonly = false,
46
+ maxlength,
47
+ inputmode,
48
+ min,
49
+ max,
50
+ hideLabel = false,
51
+ autofocus = false,
52
+ class: className = '',
53
+ oninput,
54
+ onchange
55
+ }: Props = $props();
56
+
57
+ const fieldId = $props.id();
58
+ const helpId = $derived(`${fieldId}-help`);
59
+ const problemId = $derived(`${fieldId}-problem`);
60
+ const describedBy = $derived(
61
+ [help ? helpId : '', problem ? problemId : ''].filter(Boolean).join(' ') || undefined
62
+ );
63
+ </script>
64
+
65
+ <div class="flex min-w-0 flex-col gap-1 text-start {className}">
66
+ <label for={fieldId} class={hideLabel ? 'sr-only' : 'text-xs font-medium text-ink-primary'}
67
+ >{label}</label
68
+ >
69
+ <!-- svelte-ignore a11y_autofocus -->
70
+ <input
71
+ id={fieldId}
72
+ {type}
73
+ {placeholder}
74
+ {disabled}
75
+ {readonly}
76
+ {maxlength}
77
+ {inputmode}
78
+ {min}
79
+ {max}
80
+ {autofocus}
81
+ bind:value
82
+ dir="auto"
83
+ class="w-full min-w-0 rounded-medium border bg-white px-3 py-2 text-sm text-ink-primary placeholder:text-ink-muted focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {problem
84
+ ? 'border-error'
85
+ : 'border-grey2'}"
86
+ aria-invalid={problem ? true : undefined}
87
+ aria-describedby={describedBy}
88
+ oninput={() => oninput?.()}
89
+ onchange={() => onchange?.()}
90
+ />
91
+ {#if help}
92
+ <p id={helpId} class="text-xs text-ink-muted">{help}</p>
93
+ {/if}
94
+ {#if problem}
95
+ <p id={problemId} class="text-xs text-error">{problem}</p>
96
+ {/if}
97
+ </div>
@@ -0,0 +1,29 @@
1
+ interface Props {
2
+ label: string;
3
+ value: string;
4
+ placeholder?: string;
5
+ /** A line under the field that says what to fill in. */
6
+ help?: string;
7
+ /** What is wrong with the answer, already in the page's language. */
8
+ problem?: string;
9
+ type?: 'text' | 'number' | 'search' | 'datetime-local' | 'date';
10
+ disabled?: boolean;
11
+ readonly?: boolean;
12
+ maxlength?: number;
13
+ inputmode?: 'text' | 'numeric' | 'decimal' | 'search';
14
+ /** The smallest and the largest value of a number, or the first and last day of a date. */
15
+ min?: string | number;
16
+ max?: string | number;
17
+ /** Hides the label but keeps it for a screen reader, when the surroundings already say what the field is. */
18
+ hideLabel?: boolean;
19
+ /** The field is the first thing to fill in when its dialog opens. */
20
+ autofocus?: boolean;
21
+ class?: string;
22
+ /** Called for every letter typed (a search that follows the typing). */
23
+ oninput?: () => void;
24
+ /** Called when the person is done with the field (Enter, or leaving it): the moment to keep what they typed. */
25
+ onchange?: () => void;
26
+ }
27
+ declare const TextField: import("svelte").Component<Props, {}, "value">;
28
+ type TextField = ReturnType<typeof TextField>;
29
+ export default TextField;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The small pictures the screen uses (24 by 24, drawn with a line of the text's colour). They are paths only, so they take
3
+ * the colour of the text around them (`currentColor`) and a theme needs to know nothing about them.
4
+ */
5
+ export declare const ICON_PATHS: {
6
+ readonly plus: readonly ["M12 5v14", "M5 12h14"];
7
+ readonly minus: readonly ["M5 12h14"];
8
+ readonly undo: readonly ["M3 7v6h6", "M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"];
9
+ readonly redo: readonly ["M21 7v6h-6", "M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13"];
10
+ readonly zoomIn: readonly ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "m21 21-4.3-4.3", "M11 8v6", "M8 11h6"];
11
+ readonly zoomOut: readonly ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "m21 21-4.3-4.3", "M8 11h6"];
12
+ readonly fit: readonly ["M8 3H5a2 2 0 0 0-2 2v3", "M21 8V5a2 2 0 0 0-2-2h-3", "M3 16v3a2 2 0 0 0 2 2h3", "M16 21h3a2 2 0 0 0 2-2v-3"];
13
+ readonly play: readonly ["M6 3l14 9-14 9z"];
14
+ readonly stop: readonly ["M6 6h12v12H6z"];
15
+ readonly close: readonly ["M18 6 6 18", "M6 6l12 12"];
16
+ readonly more: readonly ["M12 12h.01", "M19 12h.01", "M5 12h.01"];
17
+ readonly back: readonly ["m15 18-6-6 6-6"];
18
+ readonly open: readonly ["M7 7h10v10", "M7 17 17 7"];
19
+ readonly pause: readonly ["M14 4h4v16h-4z", "M6 4h4v16H6z"];
20
+ readonly archive: readonly ["M21 8v13H3V8", "M1 3h22v5H1z", "M10 12h4"];
21
+ readonly down: readonly ["m6 9 6 6 6-6"];
22
+ readonly up: readonly ["m18 15-6-6-6 6"];
23
+ readonly search: readonly ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "m21 21-4.3-4.3"];
24
+ readonly history: readonly ["M2 12a10 10 0 1 0 20 0 10 10 0 1 0-20 0", "M12 6v6l4 2"];
25
+ readonly trash: readonly ["M3 6h18", "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6", "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"];
26
+ readonly copy: readonly ["M8 10a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2z", "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"];
27
+ readonly code: readonly ["m16 18 6-6-6-6", "m8 6-6 6 6 6"];
28
+ readonly warning: readonly ["M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z", "M12 9v4", "M12 17h.01"];
29
+ readonly check: readonly ["M20 6 9 17l-5-5"];
30
+ readonly composition: readonly ["M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z", "M3 9h18"];
31
+ readonly trigger: readonly ["M13 2 3 14h9l-1 8 10-12h-9z"];
32
+ readonly condition: readonly ["M6 3v12", "M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z", "M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6z", "M18 9a9 9 0 0 1-9 9"];
33
+ };
34
+ export type IconName = keyof typeof ICON_PATHS;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The small pictures the screen uses (24 by 24, drawn with a line of the text's colour). They are paths only, so they take
3
+ * the colour of the text around them (`currentColor`) and a theme needs to know nothing about them.
4
+ */
5
+ export const ICON_PATHS = {
6
+ plus: ['M12 5v14', 'M5 12h14'],
7
+ minus: ['M5 12h14'],
8
+ undo: ['M3 7v6h6', 'M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13'],
9
+ redo: ['M21 7v6h-6', 'M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13'],
10
+ zoomIn: ['M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0', 'm21 21-4.3-4.3', 'M11 8v6', 'M8 11h6'],
11
+ zoomOut: ['M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0', 'm21 21-4.3-4.3', 'M8 11h6'],
12
+ fit: [
13
+ 'M8 3H5a2 2 0 0 0-2 2v3',
14
+ 'M21 8V5a2 2 0 0 0-2-2h-3',
15
+ 'M3 16v3a2 2 0 0 0 2 2h3',
16
+ 'M16 21h3a2 2 0 0 0 2-2v-3'
17
+ ],
18
+ play: ['M6 3l14 9-14 9z'],
19
+ stop: ['M6 6h12v12H6z'],
20
+ close: ['M18 6 6 18', 'M6 6l12 12'],
21
+ more: ['M12 12h.01', 'M19 12h.01', 'M5 12h.01'],
22
+ back: ['m15 18-6-6 6-6'],
23
+ open: ['M7 7h10v10', 'M7 17 17 7'],
24
+ pause: ['M14 4h4v16h-4z', 'M6 4h4v16H6z'],
25
+ archive: ['M21 8v13H3V8', 'M1 3h22v5H1z', 'M10 12h4'],
26
+ down: ['m6 9 6 6 6-6'],
27
+ up: ['m18 15-6-6-6 6'],
28
+ search: ['M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0', 'm21 21-4.3-4.3'],
29
+ history: ['M2 12a10 10 0 1 0 20 0 10 10 0 1 0-20 0', 'M12 6v6l4 2'],
30
+ trash: [
31
+ 'M3 6h18',
32
+ 'M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6',
33
+ 'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'
34
+ ],
35
+ copy: [
36
+ 'M8 10a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2z',
37
+ 'M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'
38
+ ],
39
+ code: ['m16 18 6-6-6-6', 'm8 6-6 6 6 6'],
40
+ warning: [
41
+ 'M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z',
42
+ 'M12 9v4',
43
+ 'M12 17h.01'
44
+ ],
45
+ check: ['M20 6 9 17l-5-5'],
46
+ composition: ['M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z', 'M3 9h18'],
47
+ trigger: ['M13 2 3 14h9l-1 8 10-12h-9z'],
48
+ condition: [
49
+ 'M6 3v12',
50
+ 'M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z',
51
+ 'M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6z',
52
+ 'M18 9a9 9 0 0 1-9 9'
53
+ ]
54
+ };
@@ -0,0 +1,26 @@
1
+ import type { IconName } from './icons.js';
2
+ /** One choice of a select: its value, and its words already in the page's language. */
3
+ export interface SelectChoice {
4
+ value: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ /** One line of a menu. */
9
+ export interface MenuItem {
10
+ /** Tells the lines apart; never shown. */
11
+ key: string;
12
+ label: string;
13
+ /** A second, quieter line under the label (what the line does, or why it cannot be used). */
14
+ description?: string;
15
+ icon?: IconName;
16
+ disabled?: boolean;
17
+ /** `danger` takes something away. */
18
+ tone?: 'normal' | 'danger';
19
+ onSelect: () => void;
20
+ }
21
+ /** A group of lines of a menu, with an optional heading. */
22
+ export interface MenuGroup {
23
+ key: string;
24
+ heading?: string;
25
+ items: readonly MenuItem[];
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { WorkflowsMessageKey } from '../i18n/messages.js';
2
+ /**
3
+ * The words for a request that failed. The API never gives a sentence of its own to show (see `workflowsApi.ts`): the
4
+ * screen reads what kind of failure it was and says it in the person's language, so this is one table from a failure to a
5
+ * message of the catalog.
6
+ *
7
+ * `null` for a request that was cancelled on purpose (the screen was taken down, a newer search replaced an older one):
8
+ * nothing went wrong, so nothing is said.
9
+ */
10
+ export declare function pickApiErrorMessage(error: unknown): WorkflowsMessageKey | null;
@@ -0,0 +1,53 @@
1
+ import { isCancelled, WorkflowsApiError } from '../api/workflowsApi.js';
2
+ /**
3
+ * The words for a request that failed. The API never gives a sentence of its own to show (see `workflowsApi.ts`): the
4
+ * screen reads what kind of failure it was and says it in the person's language, so this is one table from a failure to a
5
+ * message of the catalog.
6
+ *
7
+ * `null` for a request that was cancelled on purpose (the screen was taken down, a newer search replaced an older one):
8
+ * nothing went wrong, so nothing is said.
9
+ */
10
+ export function pickApiErrorMessage(error) {
11
+ if (isCancelled(error))
12
+ return null;
13
+ if (!(error instanceof WorkflowsApiError))
14
+ return 'workflows.error.generic';
15
+ if (error.sessionEnded || error.code === 'TOKEN_UNAVAILABLE')
16
+ return 'workflows.error.sessionEnded';
17
+ if (error.planRestricted)
18
+ return 'workflows.error.planRestricted';
19
+ if (error.notFound)
20
+ return 'workflows.error.notFound';
21
+ if (error.revisionChanged)
22
+ return 'workflows.error.revisionChanged';
23
+ switch (error.conflictReason) {
24
+ case 'workflow_archived':
25
+ return 'workflows.error.archived';
26
+ case 'nothing_to_publish':
27
+ return 'workflows.error.nothingToPublish';
28
+ case 'nothing_to_discard':
29
+ return 'workflows.error.nothingToDiscard';
30
+ case 'ever_published':
31
+ return 'workflows.error.everPublished';
32
+ case 'wrong_state':
33
+ return 'workflows.error.wrongState';
34
+ default:
35
+ break;
36
+ }
37
+ const reason = error.details?.reason;
38
+ if (error.status === 422 && reason === 'too_many_workflows')
39
+ return 'workflows.error.tooManyWorkflows';
40
+ if (error.status === 422)
41
+ return 'workflows.error.publishBlocked';
42
+ if (error.status === 400)
43
+ return 'workflows.error.invalidGraph';
44
+ if (error.status === 429)
45
+ return 'workflows.error.tooManyRequests';
46
+ if (error.code === 'NETWORK_ERROR')
47
+ return 'workflows.error.network';
48
+ if (error.code === 'TIMEOUT')
49
+ return 'workflows.error.timeout';
50
+ if (error.status !== null && error.status >= 500)
51
+ return 'workflows.error.server';
52
+ return 'workflows.error.generic';
53
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Saving a draft while a person works on it. Every change starts a short wait; when it ends, the draft is sent. A change
3
+ * that comes in while a save is on its way is not lost and does not start a second save at the same time: it is sent
4
+ * right after the first one is answered (the save sends the revision the draft is at, so two at once would refuse each
5
+ * other). Nothing here knows what is being saved: the caller reads the draft, sends it and says what the server answered.
6
+ *
7
+ * changed ──▶ pending ──(delay)──▶ saving ──▶ saved
8
+ * ▲ │ ├──▶ failed (the next change tries again, and so does `flush`)
9
+ * └── changed again ───┘ └──▶ conflict (somebody else saved the draft: nothing is sent until the screen reloads)
10
+ *
11
+ * The clock is a parameter so that a test runs a whole afternoon in a moment.
12
+ */
13
+ export type SaveState = 'saved' | 'pending' | 'saving' | 'failed' | 'conflict';
14
+ /** The two functions of a clock this needs; the page's own by default. */
15
+ export interface SaveClock {
16
+ setTimeout(callback: () => void, delayMilliseconds: number): unknown;
17
+ clearTimeout(handle: unknown): void;
18
+ }
19
+ export interface DraftSaverOptions<Snapshot, Answer> {
20
+ /** What should be saved right now, or `null` when what the server has is already what the person sees. */
21
+ readSnapshot(): Snapshot | null;
22
+ /** Sends it. Whatever it throws is the failure; `isConflict` tells a refusal that no retry can fix. */
23
+ send(snapshot: Snapshot): Promise<Answer>;
24
+ /** Called after a successful send, with what was sent and what the server answered, before the state becomes `saved`. */
25
+ onSaved(snapshot: Snapshot, answer: Answer): void;
26
+ /** Called when the state changes (and with the error on `failed` and `conflict`). */
27
+ onStateChange(state: SaveState, error?: unknown): void;
28
+ /** Whether this error means the draft was changed somewhere else. */
29
+ isConflict(error: unknown): boolean;
30
+ /** How long a change waits for the next one before it is sent. */
31
+ delayMilliseconds?: number;
32
+ clock?: SaveClock;
33
+ }
34
+ export interface DraftSaver {
35
+ /** Something changed: send the draft after the wait. */
36
+ markChanged(): void;
37
+ /** Send now what is waiting, and resolve once nothing is waiting or on its way (or the save failed or conflicted). */
38
+ flush(): Promise<SaveState>;
39
+ /** The state right now. */
40
+ readonly state: SaveState;
41
+ /** After a reload: forget the conflict and what was waiting, and start from `saved`. */
42
+ reset(): void;
43
+ /** The screen goes away: stop the wait. A save that is on its way still ends, but nothing new starts. */
44
+ dispose(): void;
45
+ }
46
+ export declare const DEFAULT_SAVE_DELAY_MILLISECONDS = 1200;
47
+ export declare function createDraftSaver<Snapshot, Answer>(options: DraftSaverOptions<Snapshot, Answer>): DraftSaver;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Saving a draft while a person works on it. Every change starts a short wait; when it ends, the draft is sent. A change
3
+ * that comes in while a save is on its way is not lost and does not start a second save at the same time: it is sent
4
+ * right after the first one is answered (the save sends the revision the draft is at, so two at once would refuse each
5
+ * other). Nothing here knows what is being saved: the caller reads the draft, sends it and says what the server answered.
6
+ *
7
+ * changed ──▶ pending ──(delay)──▶ saving ──▶ saved
8
+ * ▲ │ ├──▶ failed (the next change tries again, and so does `flush`)
9
+ * └── changed again ───┘ └──▶ conflict (somebody else saved the draft: nothing is sent until the screen reloads)
10
+ *
11
+ * The clock is a parameter so that a test runs a whole afternoon in a moment.
12
+ */
13
+ export const DEFAULT_SAVE_DELAY_MILLISECONDS = 1200;
14
+ const pageClock = {
15
+ setTimeout: (callback, delayMilliseconds) => globalThis.setTimeout(callback, delayMilliseconds),
16
+ clearTimeout: (handle) => globalThis.clearTimeout(handle)
17
+ };
18
+ export function createDraftSaver(options) {
19
+ const delayMilliseconds = options.delayMilliseconds ?? DEFAULT_SAVE_DELAY_MILLISECONDS;
20
+ const clock = options.clock ?? pageClock;
21
+ let state = 'saved';
22
+ let waitHandle = null;
23
+ let disposed = false;
24
+ /** The save that is on its way, so `flush` can wait for it. */
25
+ let sending = null;
26
+ /** A change came in while a save was on its way: another one follows it. */
27
+ let changedWhileSending = false;
28
+ function setState(next, error) {
29
+ if (state === next && error === undefined)
30
+ return;
31
+ state = next;
32
+ options.onStateChange(next, error);
33
+ }
34
+ function cancelWait() {
35
+ if (waitHandle !== null) {
36
+ clock.clearTimeout(waitHandle);
37
+ waitHandle = null;
38
+ }
39
+ }
40
+ async function sendOnce() {
41
+ cancelWait();
42
+ const snapshot = options.readSnapshot();
43
+ if (snapshot === null) {
44
+ setState('saved');
45
+ return;
46
+ }
47
+ setState('saving');
48
+ changedWhileSending = false;
49
+ try {
50
+ const answer = await options.send(snapshot);
51
+ options.onSaved(snapshot, answer);
52
+ }
53
+ catch (error) {
54
+ if (options.isConflict(error))
55
+ setState('conflict', error);
56
+ else
57
+ setState('failed', error);
58
+ return;
59
+ }
60
+ if (disposed)
61
+ return;
62
+ if (changedWhileSending) {
63
+ // What came in meanwhile is sent in its own save: the revision the server holds moved with this one.
64
+ changedWhileSending = false;
65
+ await sendOnce();
66
+ return;
67
+ }
68
+ setState('saved');
69
+ }
70
+ function startSending() {
71
+ if (sending)
72
+ return sending;
73
+ sending = sendOnce().finally(() => {
74
+ sending = null;
75
+ });
76
+ return sending;
77
+ }
78
+ return {
79
+ markChanged() {
80
+ if (disposed || state === 'conflict')
81
+ return;
82
+ if (sending) {
83
+ changedWhileSending = true;
84
+ return;
85
+ }
86
+ setState('pending');
87
+ cancelWait();
88
+ waitHandle = clock.setTimeout(() => {
89
+ waitHandle = null;
90
+ void startSending();
91
+ }, delayMilliseconds);
92
+ },
93
+ async flush() {
94
+ if (state === 'conflict')
95
+ return state;
96
+ cancelWait();
97
+ if (sending) {
98
+ // The save that is on its way also sends what came in while it was (see `sendOnce`): waiting for it is enough.
99
+ await sending;
100
+ return state;
101
+ }
102
+ if (state === 'pending' || state === 'failed')
103
+ await startSending();
104
+ return state;
105
+ },
106
+ get state() {
107
+ return state;
108
+ },
109
+ reset() {
110
+ cancelWait();
111
+ changedWhileSending = false;
112
+ setState('saved');
113
+ },
114
+ dispose() {
115
+ disposed = true;
116
+ cancelWait();
117
+ }
118
+ };
119
+ }