@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
@@ -1,10 +1,12 @@
1
1
  <!--
2
- The workflows screen: where a team builds the workflows that decide which composition an embed shows, and (later) how
3
- visitors moved through them. This is the root. It is the one place that knows the page's language and reading
4
- direction; every part of the screen below it asks for them.
2
+ The workflows screen: where a team builds the workflows that decide which composition an embed shows next (a list of
3
+ them, and for each one a canvas of blocks, a side panel, versions, a test run and the counts of where visitors went).
4
+ This is the root. It is the one place that knows the page's language and reading direction; every part of the screen
5
+ below it asks for them.
5
6
 
6
- V1 draws the shell only: the header and the "nothing yet" state. The editor and the runs arrive on top of this root
7
- without changing what a page passes in.
7
+ What it needs from the page: where the Widgetic API is, a way to get a token for it, and which workspace's workflows to
8
+ show (`apiUrl`, `getAccessToken`, `workspaceId`). Which workflow is open is the page's too (`workflowId`, told about
9
+ changes through `onOpenWorkflow`), so that it can be part of the page's address. See `WorkflowsProps`.
8
10
 
9
11
  Look and feel: nothing in here is a literal colour, font or corner. Everything reads the Widgetic palette
10
12
  (`bg-white`, `text-ink-*`, `border-grey2`, `bg-primary-green`, `text-error`) and the `font-sans` / `rounded-*` scales,
@@ -24,15 +26,22 @@
24
26
  import { provideWorkflowsLanguage } from '../i18n/language.js';
25
27
  import type { WorkflowsProps } from '../types/index.js';
26
28
  import { workflowsError } from '../utils/logger.js';
27
- import WorkflowsEmptyState from './WorkflowsEmptyState.svelte';
28
- import WorkflowsHeader from './WorkflowsHeader.svelte';
29
+ import WorkflowsWorkspace from './WorkflowsWorkspace.svelte';
29
30
 
30
31
  let {
32
+ apiUrl,
33
+ getAccessToken,
34
+ workspaceId,
35
+ workflowId = null,
36
+ onOpenWorkflow,
37
+ onShowEmbedCode,
38
+ presence = false,
31
39
  locale = null,
32
40
  messages: languageMessages = null,
33
41
  dir = undefined,
34
42
  class: className = '',
35
- onError
43
+ onError,
44
+ fetchImplementation
36
45
  }: WorkflowsProps = $props();
37
46
 
38
47
  // Why stores and effects below instead of `$derived`: the design system's language (`update()`) and direction
@@ -56,29 +65,46 @@
56
65
  givenDirection.set(dir);
57
66
  });
58
67
 
68
+ /** Tells the page about a failure without letting a handler of the page that throws take the screen down. */
69
+ function reportToPage(error: Parameters<NonNullable<WorkflowsProps['onError']>>[0]): void {
70
+ try {
71
+ onError?.(error);
72
+ } catch (handlerError) {
73
+ workflowsError('The onError handler of the page threw.', handlerError);
74
+ }
75
+ }
76
+
59
77
  /**
60
78
  * A part of the screen threw while it was being drawn. The screen shows its "Try again" in place of the part, and the
61
- * page is told once. A handler of the page that throws must not take the screen down with it.
79
+ * page is told once.
62
80
  */
63
81
  function reportRenderFailure(error: unknown): void {
64
82
  const failureMessage = error instanceof Error ? error.message : String(error);
65
83
  workflowsError(`The screen could not be drawn: ${failureMessage}`, error);
66
- try {
67
- onError?.({ message: failureMessage, code: 'RENDER_FAILED', fatal: false });
68
- } catch (handlerError) {
69
- workflowsError('The onError handler of the page threw.', handlerError);
70
- }
84
+ reportToPage({ message: failureMessage, code: 'RENDER_FAILED', fatal: false });
71
85
  }
72
86
  </script>
73
87
 
74
88
  <svelte:boundary onerror={reportRenderFailure}>
75
89
  <section
76
- class="flex h-full min-h-0 w-full flex-col gap-6 overflow-auto bg-white p-6 font-sans text-ink-primary {className}"
90
+ class="flex h-full min-h-0 w-full flex-col overflow-auto bg-white font-sans text-ink-primary {className}"
77
91
  dir={$textDirection}
78
92
  aria-label={$t('workflows.region.label')}
79
93
  >
80
- <WorkflowsHeader />
81
- <WorkflowsEmptyState />
94
+ <!-- A workspace or an API that changes is a different set of workflows: the screen starts again for it. -->
95
+ {#key `${apiUrl}|${workspaceId}`}
96
+ <WorkflowsWorkspace
97
+ {apiUrl}
98
+ {workspaceId}
99
+ {getAccessToken}
100
+ {fetchImplementation}
101
+ {workflowId}
102
+ {onOpenWorkflow}
103
+ {onShowEmbedCode}
104
+ {presence}
105
+ onError={reportToPage}
106
+ />
107
+ {/key}
82
108
  </section>
83
109
 
84
110
  <!--
@@ -1,21 +1,32 @@
1
1
  <!--
2
- What the screen shows while there is nothing to list: what a workflow is, and that building them is on its way. In V1
3
- this is the whole body of the screen; once workflows can be made, the list takes this place and this becomes the
4
- "first workflow" prompt.
2
+ What the list shows while the workspace has no workflow yet: what a workflow is, and the button that makes the first one.
3
+ A list that is empty because a search or a filter matches nothing does not show this; it says so in a line of its own.
5
4
 
6
5
  No fill: the palette's `ink-muted` reads at 4.6 to 1 on white and at 4.2 to 1 on `grey1`, which is under WCAG's 4.5 for
7
6
  text this size, so the hints sit on the screen's own white and the box is drawn with its dashed border alone.
8
7
  -->
9
8
  <script lang="ts">
10
9
  import { useWorkflowsLanguage } from '../i18n/language.js';
10
+ import ActionButton from './ui/ActionButton.svelte';
11
+ import Icon from './ui/Icon.svelte';
12
+
13
+ interface Props {
14
+ /** The person pressed the button that makes the first workflow. */
15
+ oncreate: () => void;
16
+ }
17
+
18
+ let { oncreate }: Props = $props();
11
19
 
12
20
  const { t } = useWorkflowsLanguage();
13
21
  </script>
14
22
 
15
23
  <div
16
- class="flex flex-1 flex-col items-center justify-center gap-2 rounded-large border border-dashed border-grey2 p-10 text-center"
24
+ class="flex flex-1 flex-col items-center justify-center gap-3 rounded-large border border-dashed border-grey2 p-10 text-center"
17
25
  >
18
26
  <h2 class="text-base font-medium">{$t('workflows.empty.title')}</h2>
19
27
  <p class="max-w-md text-sm text-ink-muted">{$t('workflows.empty.hint')}</p>
20
- <p class="text-xs text-ink-muted">{$t('workflows.empty.comingSoon')}</p>
28
+ <ActionButton variant="primary" onclick={oncreate}>
29
+ <Icon name="plus" />
30
+ {$t('workflows.list.newWorkflow')}
31
+ </ActionButton>
21
32
  </div>
@@ -1,18 +1,7 @@
1
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
1
+ interface Props {
2
+ /** The person pressed the button that makes the first workflow. */
3
+ oncreate: () => void;
13
4
  }
14
- declare const WorkflowsEmptyState: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
- [evt: string]: CustomEvent<any>;
16
- }, {}, {}, string>;
17
- type WorkflowsEmptyState = InstanceType<typeof WorkflowsEmptyState>;
5
+ declare const WorkflowsEmptyState: import("svelte").Component<Props, {}, "">;
6
+ type WorkflowsEmptyState = ReturnType<typeof WorkflowsEmptyState>;
18
7
  export default WorkflowsEmptyState;
@@ -1,6 +1,6 @@
1
1
  <!--
2
- The top of the workflows screen: its title and the one line that says what a workflow does. Later the "New workflow"
3
- action lands here, next to the title.
2
+ The top of the list of workflows: its title and the one line that says what a workflow does. The "New workflow" button
3
+ sits next to it, in the list.
4
4
  -->
5
5
  <script lang="ts">
6
6
  import { useWorkflowsLanguage } from '../i18n/language.js';
@@ -0,0 +1,90 @@
1
+ <!--
2
+ The workflows of one workspace: the list, and the editor of the workflow that is open. It makes the client of the Widgetic
3
+ API for the workspace and shares it with everything below.
4
+
5
+ Which workflow is open is the page's to decide (it is part of the page's address): `workflowId` says it, and every
6
+ change the person makes (opening one, going back) is told to the page through `onOpenWorkflow`. A page that does not keep
7
+ track is still served: the screen follows what the person did.
8
+
9
+ It belongs to one workspace and one API: the root draws it again (a `{#key}`) when either changes.
10
+ -->
11
+ <script lang="ts">
12
+ import { untrack } from 'svelte';
13
+ import { provideWorkflowsApi } from '../api/apiContext.js';
14
+ import { createWorkflowsApi } from '../api/workflowsApi.js';
15
+ import type { WorkflowsError, WorkflowsProps } from '../types/index.js';
16
+ import { workflowsError } from '../utils/logger.js';
17
+ import WorkflowEditor from './editor/WorkflowEditor.svelte';
18
+ import WorkflowList from './list/WorkflowList.svelte';
19
+
20
+ interface Props {
21
+ apiUrl: WorkflowsProps['apiUrl'];
22
+ workspaceId: WorkflowsProps['workspaceId'];
23
+ getAccessToken: WorkflowsProps['getAccessToken'];
24
+ fetchImplementation?: WorkflowsProps['fetchImplementation'];
25
+ workflowId?: WorkflowsProps['workflowId'];
26
+ onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
27
+ onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
28
+ presence?: WorkflowsProps['presence'];
29
+ onError: (error: WorkflowsError) => void;
30
+ }
31
+
32
+ let {
33
+ apiUrl,
34
+ workspaceId,
35
+ getAccessToken,
36
+ fetchImplementation,
37
+ workflowId,
38
+ onOpenWorkflow,
39
+ onShowEmbedCode,
40
+ presence = false,
41
+ onError
42
+ }: Props = $props();
43
+
44
+ // The client keeps what it was made with: a new workspace is a new screen, so reading the props once is what is meant.
45
+ provideWorkflowsApi(
46
+ createWorkflowsApi({
47
+ apiUrl: untrack(() => apiUrl),
48
+ workspaceId: untrack(() => workspaceId),
49
+ // The token function is read at every request, so a page that replaces it is heard.
50
+ getAccessToken: (reason, refusedToken) => getAccessToken(reason, refusedToken),
51
+ fetchImplementation: untrack(() => fetchImplementation)
52
+ })
53
+ );
54
+
55
+ /** The workflow that is open: what the page says, until the person opens or leaves one. */
56
+ let openId = $derived(workflowId ?? null);
57
+
58
+ function open(id: string | null): void {
59
+ openId = id;
60
+ try {
61
+ onOpenWorkflow?.(id);
62
+ } catch (handlerError) {
63
+ // A handler of the page that throws must not take the screen down with it; the console tells the page's developer.
64
+ workflowsError(
65
+ `The onOpenWorkflow handler of the page threw: ${handlerError instanceof Error ? handlerError.message : String(handlerError)}`,
66
+ handlerError
67
+ );
68
+ }
69
+ }
70
+ </script>
71
+
72
+ {#if openId}
73
+ <!-- A room tall enough for the canvas even when the page's element is shorter: then the screen scrolls inside it. -->
74
+ <div class="flex min-h-[36rem] flex-1 flex-col">
75
+ {#key openId}
76
+ <WorkflowEditor
77
+ workflowId={openId}
78
+ onback={() => open(null)}
79
+ onopenworkflow={(id) => open(id)}
80
+ onerror={onError}
81
+ onshowembedcode={onShowEmbedCode}
82
+ {presence}
83
+ />
84
+ {/key}
85
+ </div>
86
+ {:else}
87
+ <div class="flex flex-1 flex-col p-6">
88
+ <WorkflowList onopen={(id) => open(id)} onerror={onError} onshowembedcode={onShowEmbedCode} />
89
+ </div>
90
+ {/if}
@@ -0,0 +1,15 @@
1
+ import type { WorkflowsError, WorkflowsProps } from '../types/index.js';
2
+ interface Props {
3
+ apiUrl: WorkflowsProps['apiUrl'];
4
+ workspaceId: WorkflowsProps['workspaceId'];
5
+ getAccessToken: WorkflowsProps['getAccessToken'];
6
+ fetchImplementation?: WorkflowsProps['fetchImplementation'];
7
+ workflowId?: WorkflowsProps['workflowId'];
8
+ onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
9
+ onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
10
+ presence?: WorkflowsProps['presence'];
11
+ onError: (error: WorkflowsError) => void;
12
+ }
13
+ declare const WorkflowsWorkspace: import("svelte").Component<Props, {}, "">;
14
+ type WorkflowsWorkspace = ReturnType<typeof WorkflowsWorkspace>;
15
+ export default WorkflowsWorkspace;
@@ -0,0 +1,101 @@
1
+ <!--
2
+ The "Add block" menu: a composition, a condition, or one of the four triggers. A new block goes after the block that is
3
+ selected (joined to it when the engine allows that line), or to a free place on the canvas when nothing is selected.
4
+
5
+ The triggers say what the selected composition can do. "Input added" needs a widget that keeps a table a visitor can add
6
+ to, and "Action in the widget" needs a published widget that reports actions; when the composition lacks that, the trigger
7
+ stays in the list, dimmed, with the reason under it, so a person learns why and does not wonder where it went. "Event from
8
+ your page" and "Scheduled" need nothing from the widget and are always on.
9
+ -->
10
+ <script lang="ts">
11
+ import {
12
+ CAPABILITY_REASON_MESSAGE_KEYS,
13
+ TRIGGER_KIND_MESSAGE_KEYS
14
+ } from '../../editor/blockLabels.js';
15
+ import { readTriggerAvailability } from '../../editor/capabilityModel.js';
16
+ import { useEditorState } from '../../editor/editorState.svelte.js';
17
+ import { MAX_BLOCKS } from '@widgetic/workflows-engine';
18
+ import { TRIGGER_KINDS, type BlockRequest, type TriggerKind } from '../../editor/graphModel.js';
19
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
20
+ import type { WorkflowsMessageKey } from '../../i18n/messages.js';
21
+ import Menu from '../ui/Menu.svelte';
22
+ import type { MenuGroup } from '../ui/types.js';
23
+
24
+ const editor = useEditorState();
25
+ const { t } = useWorkflowsLanguage();
26
+
27
+ let menu = $state<ReturnType<typeof Menu>>();
28
+
29
+ /** Opens the menu from the outside: the `B` key of the canvas. */
30
+ export function open(): void {
31
+ menu?.openMenu();
32
+ }
33
+
34
+ const TRIGGER_HELP_KEYS = {
35
+ input: 'workflows.addBlock.helpInput',
36
+ action: 'workflows.addBlock.helpAction',
37
+ pageEvent: 'workflows.addBlock.helpPageEvent',
38
+ scheduled: 'workflows.addBlock.helpScheduled'
39
+ } as const satisfies Record<TriggerKind, WorkflowsMessageKey>;
40
+
41
+ /** What the selected composition can do; unknown (nothing selected, or not a composition) means every trigger is on. */
42
+ const anchorOption = $derived.by(() => {
43
+ const selected = editor.selectedNode;
44
+ if (selected?.type !== 'composition' || !selected.compositionId) return undefined;
45
+ return editor.options[selected.compositionId];
46
+ });
47
+
48
+ function add(request: BlockRequest): void {
49
+ const refused = editor.addBlock(request);
50
+ if (refused === 'too_many_blocks')
51
+ editor.showNotice('problem', 'workflows.editor.blockLimit', { max: MAX_BLOCKS });
52
+ }
53
+
54
+ const groups = $derived.by<MenuGroup[]>(() => [
55
+ {
56
+ key: 'blocks',
57
+ items: [
58
+ {
59
+ key: 'composition',
60
+ label: $t('workflows.addBlock.composition'),
61
+ description: $t('workflows.addBlock.helpComposition'),
62
+ icon: 'composition',
63
+ onSelect: () => add({ kind: 'composition' })
64
+ },
65
+ {
66
+ key: 'condition',
67
+ label: $t('workflows.addBlock.condition'),
68
+ description: $t('workflows.addBlock.helpCondition'),
69
+ icon: 'condition',
70
+ onSelect: () => add({ kind: 'condition' })
71
+ }
72
+ ]
73
+ },
74
+ {
75
+ key: 'triggers',
76
+ heading: $t('workflows.addBlock.triggerHeading'),
77
+ items: TRIGGER_KINDS.map((kind) => {
78
+ const availability = readTriggerAvailability(anchorOption, kind);
79
+ return {
80
+ key: kind,
81
+ label: $t(TRIGGER_KIND_MESSAGE_KEYS[kind]),
82
+ description: availability.enabled
83
+ ? $t(TRIGGER_HELP_KEYS[kind])
84
+ : $t(CAPABILITY_REASON_MESSAGE_KEYS[availability.reason]),
85
+ icon: 'trigger',
86
+ disabled: !availability.enabled,
87
+ onSelect: () => add({ kind: 'trigger', triggerKind: kind })
88
+ };
89
+ })
90
+ }
91
+ ]);
92
+ </script>
93
+
94
+ <Menu
95
+ bind:this={menu}
96
+ {groups}
97
+ label={$t('workflows.toolbar.addBlock')}
98
+ icon="plus"
99
+ variant="primary"
100
+ size="small"
101
+ />
@@ -0,0 +1,5 @@
1
+ declare const AddBlockMenu: import("svelte").Component<Record<string, never>, {
2
+ open: () => void;
3
+ }, "">;
4
+ type AddBlockMenu = ReturnType<typeof AddBlockMenu>;
5
+ export default AddBlockMenu;
@@ -0,0 +1,95 @@
1
+ <!--
2
+ The tools laid over the canvas: Add block, zoom out, zoom in, fit to the screen, undo and redo. They sit in the top corner
3
+ of the canvas, on the side where the line begins. A canvas that cannot be changed (a version, an archived workflow, a touch
4
+ screen) keeps the zoom and fit tools and drops the ones that change the workflow.
5
+ -->
6
+ <script lang="ts">
7
+ import { useEditorState } from '../../editor/editorState.svelte.js';
8
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
9
+ import ActionButton from '../ui/ActionButton.svelte';
10
+ import Icon from '../ui/Icon.svelte';
11
+ import AddBlockMenu from './AddBlockMenu.svelte';
12
+
13
+ interface Props {
14
+ /** Whether the workflow can be changed from the canvas (the Add block menu, undo and redo are shown only then). */
15
+ canEdit: boolean;
16
+ }
17
+
18
+ let { canEdit }: Props = $props();
19
+
20
+ const editor = useEditorState();
21
+ const { t } = useWorkflowsLanguage();
22
+
23
+ let addBlockMenu = $state<ReturnType<typeof AddBlockMenu>>();
24
+
25
+ /** Opens the Add block menu from the outside: the `B` key of the canvas. */
26
+ export function openAddBlock(): void {
27
+ addBlockMenu?.open();
28
+ }
29
+ </script>
30
+
31
+ <div
32
+ class="absolute start-3 top-3 z-20 flex items-center gap-1 rounded-large border border-grey2 bg-white p-1 shadow-sm"
33
+ role="toolbar"
34
+ aria-label={$t('workflows.toolbar.label')}
35
+ >
36
+ {#if canEdit}
37
+ <AddBlockMenu bind:this={addBlockMenu} />
38
+ <span class="mx-1 h-5 border-s border-grey2" aria-hidden="true"></span>
39
+ {/if}
40
+ <ActionButton
41
+ variant="ghost"
42
+ size="small"
43
+ iconOnly
44
+ ariaLabel={$t('workflows.toolbar.zoomOut')}
45
+ title={$t('workflows.toolbar.zoomOut')}
46
+ onclick={() => editor.canvas?.zoomOut()}
47
+ >
48
+ <Icon name="zoomOut" />
49
+ </ActionButton>
50
+ <ActionButton
51
+ variant="ghost"
52
+ size="small"
53
+ iconOnly
54
+ ariaLabel={$t('workflows.toolbar.zoomIn')}
55
+ title={$t('workflows.toolbar.zoomIn')}
56
+ onclick={() => editor.canvas?.zoomIn()}
57
+ >
58
+ <Icon name="zoomIn" />
59
+ </ActionButton>
60
+ <ActionButton
61
+ variant="ghost"
62
+ size="small"
63
+ iconOnly
64
+ ariaLabel={$t('workflows.toolbar.fit')}
65
+ title={$t('workflows.toolbar.fit')}
66
+ onclick={() => editor.canvas?.fitView()}
67
+ >
68
+ <Icon name="fit" />
69
+ </ActionButton>
70
+ {#if canEdit}
71
+ <span class="mx-1 h-5 border-s border-grey2" aria-hidden="true"></span>
72
+ <ActionButton
73
+ variant="ghost"
74
+ size="small"
75
+ iconOnly
76
+ disabled={!editor.canvas?.canUndo}
77
+ ariaLabel={$t('workflows.toolbar.undo')}
78
+ title={$t('workflows.toolbar.undo')}
79
+ onclick={() => editor.canvas?.undo()}
80
+ >
81
+ <Icon name="undo" />
82
+ </ActionButton>
83
+ <ActionButton
84
+ variant="ghost"
85
+ size="small"
86
+ iconOnly
87
+ disabled={!editor.canvas?.canRedo}
88
+ ariaLabel={$t('workflows.toolbar.redo')}
89
+ title={$t('workflows.toolbar.redo')}
90
+ onclick={() => editor.canvas?.redo()}
91
+ >
92
+ <Icon name="redo" />
93
+ </ActionButton>
94
+ {/if}
95
+ </div>
@@ -0,0 +1,9 @@
1
+ interface Props {
2
+ /** Whether the workflow can be changed from the canvas (the Add block menu, undo and redo are shown only then). */
3
+ canEdit: boolean;
4
+ }
5
+ declare const CanvasToolbar: import("svelte").Component<Props, {
6
+ openAddBlock: () => void;
7
+ }, "">;
8
+ type CanvasToolbar = ReturnType<typeof CanvasToolbar>;
9
+ export default CanvasToolbar;
@@ -0,0 +1,125 @@
1
+ <!--
2
+ A composition block on the canvas: the composition a visitor sees at this step (its name and picture), whether it is where
3
+ the workflow starts, what is wrong with it, and, in the Runs tab, how many visitors reached it. A line comes in on the
4
+ left, and the next steps leave from the right.
5
+
6
+ Nothing here can be edited: a block is changed from the side panel, so the block itself only has to be picked up and moved
7
+ (kaykay does that for the whole block). The block follows the direction of the page for its words, while the canvas around
8
+ it stays left to right, because the lines run from left to right in every language.
9
+ -->
10
+ <script lang="ts">
11
+ import type { NodeProps } from 'kaykay';
12
+ import type { CompositionNode } from '@widgetic/workflows-engine';
13
+ import { useTextDirection } from '@widgetic/design-system/components/textDirection';
14
+ import {
15
+ INPUT_ACCEPTS,
16
+ INPUT_HANDLE_ID,
17
+ OUTPUT_HANDLE_ID,
18
+ OUTPUT_PORT_TYPE,
19
+ type WorkflowBlockData
20
+ } from '../../editor/flowAdapter.js';
21
+ import { useCanvasContext } from '../../editor/canvasContext.js';
22
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
23
+ import { formatCount } from '../../editor/formatCount.js';
24
+ import Icon from '../ui/Icon.svelte';
25
+ import HandlePoint from './HandlePoint.svelte';
26
+
27
+ let { id, data }: NodeProps<WorkflowBlockData> = $props();
28
+
29
+ const { t, locale } = useWorkflowsLanguage();
30
+ const textDirection = useTextDirection();
31
+ const readContext = useCanvasContext();
32
+
33
+ const node = $derived(data.node as CompositionNode);
34
+ /** `undefined` while the API has not answered, `null` when it does not know the composition. */
35
+ const composition = $derived(
36
+ node.compositionId ? readContext().words.findComposition(node.compositionId) : undefined
37
+ );
38
+ const marks = $derived(readContext().marks);
39
+ const problemCount = $derived(marks.problemCountOf(id));
40
+ const entryCount = $derived(marks.entryCountOf(id));
41
+ const failureCount = $derived(marks.failureCountOf(id));
42
+
43
+ /** The words at the top of the block: the composition's name, or what is missing. */
44
+ const title = $derived.by(() => {
45
+ if (!node.compositionId) return $t('workflows.block.compositionNotChosen');
46
+ if (composition === null) return $t('workflows.block.compositionUnavailable');
47
+ return composition?.name?.trim() ? composition.name : $t('workflows.block.compositionLoading');
48
+ });
49
+ const isTitleMissing = $derived(!node.compositionId || composition === null);
50
+
51
+ /** A picture that failed to load is left out, and the block looks as it would without one. It is tried again for another address. */
52
+ const thumbnailUrl = $derived(composition?.thumbnailUrl ?? null);
53
+ let failedThumbnailUrl = $state<string | null>(null);
54
+ const hasThumbnailFailed = $derived(
55
+ failedThumbnailUrl !== null && failedThumbnailUrl === thumbnailUrl
56
+ );
57
+ </script>
58
+
59
+ <div
60
+ class="relative flex w-64 flex-col gap-2 rounded-large border border-grey2 bg-white p-3 text-start text-ink-primary shadow-sm"
61
+ dir={$textDirection}
62
+ data-workflow-block="composition"
63
+ >
64
+ <div class="flex items-center gap-2">
65
+ <Icon name="composition" class="size-4 text-ink-muted" />
66
+ <p
67
+ class="min-w-0 flex-1 truncate text-sm font-medium {isTitleMissing ? 'text-ink-muted' : ''}"
68
+ dir={isTitleMissing ? undefined : 'auto'}
69
+ >
70
+ {title}
71
+ </p>
72
+ {#if node.startsHere}
73
+ <span
74
+ class="shrink-0 rounded-pill border border-primary-green px-2 py-0.5 text-xs text-primary-green"
75
+ >
76
+ {$t('workflows.block.startsHere')}
77
+ </span>
78
+ {/if}
79
+ </div>
80
+
81
+ {#if thumbnailUrl && !hasThumbnailFailed}
82
+ <img
83
+ src={thumbnailUrl}
84
+ alt=""
85
+ loading="lazy"
86
+ draggable="false"
87
+ class="h-24 w-full rounded-medium border border-grey2 object-cover"
88
+ onerror={() => (failedThumbnailUrl = thumbnailUrl)}
89
+ />
90
+ {/if}
91
+
92
+ {#if composition && !composition.published}
93
+ <p class="text-xs text-ink-muted">{$t('workflows.block.notPublished')}</p>
94
+ {/if}
95
+ {#if problemCount > 0}
96
+ <p class="flex items-center gap-1 text-xs text-error">
97
+ <Icon name="warning" class="size-3.5" />
98
+ {$t('workflows.block.problems', { count: problemCount })}
99
+ </p>
100
+ {/if}
101
+ {#if entryCount !== null}
102
+ <p class="text-xs text-ink-muted">
103
+ {$t('workflows.runs.entered', { count: formatCount(entryCount, $locale) })}
104
+ </p>
105
+ {/if}
106
+ {#if failureCount > 0}
107
+ <p class="text-xs text-error">
108
+ {$t('workflows.runs.failed', { count: formatCount(failureCount, $locale) })}
109
+ </p>
110
+ {/if}
111
+
112
+ <HandlePoint
113
+ id={INPUT_HANDLE_ID}
114
+ type="input"
115
+ port={INPUT_HANDLE_ID}
116
+ accept={INPUT_ACCEPTS.composition}
117
+ position="left"
118
+ />
119
+ <HandlePoint
120
+ id={OUTPUT_HANDLE_ID}
121
+ type="output"
122
+ port={OUTPUT_PORT_TYPE.composition}
123
+ position="right"
124
+ />
125
+ </div>
@@ -0,0 +1,5 @@
1
+ import type { NodeProps } from 'kaykay';
2
+ import { type WorkflowBlockData } from '../../editor/flowAdapter.js';
3
+ declare const CompositionNodeView: import("svelte").Component<NodeProps<WorkflowBlockData>, {}, "">;
4
+ type CompositionNodeView = ReturnType<typeof CompositionNodeView>;
5
+ export default CompositionNodeView;