@widgetic/workflows 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +122 -0
  2. package/README.md +304 -2
  3. package/dist/api/apiContext.d.ts +4 -0
  4. package/dist/api/apiContext.js +17 -0
  5. package/dist/api/types.d.ts +168 -0
  6. package/dist/api/types.js +3 -0
  7. package/dist/api/workflowsApi.d.ts +109 -0
  8. package/dist/api/workflowsApi.js +657 -0
  9. package/dist/components/Workflows.svelte +131 -0
  10. package/dist/components/Workflows.svelte.d.ts +4 -0
  11. package/dist/components/WorkflowsEmptyState.svelte +32 -0
  12. package/dist/components/WorkflowsEmptyState.svelte.d.ts +7 -0
  13. package/dist/components/WorkflowsHeader.svelte +14 -0
  14. package/dist/components/WorkflowsHeader.svelte.d.ts +18 -0
  15. package/dist/components/WorkflowsWorkspace.svelte +87 -0
  16. package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
  17. package/dist/components/canvas/AddBlockMenu.svelte +101 -0
  18. package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
  19. package/dist/components/canvas/CanvasToolbar.svelte +95 -0
  20. package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
  21. package/dist/components/canvas/CompositionNodeView.svelte +125 -0
  22. package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
  23. package/dist/components/canvas/ConditionNodeView.svelte +95 -0
  24. package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
  25. package/dist/components/canvas/HandlePoint.svelte +32 -0
  26. package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
  27. package/dist/components/canvas/TriggerNodeView.svelte +75 -0
  28. package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
  29. package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
  30. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
  31. package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
  32. package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
  33. package/dist/components/editor/EditorBanners.svelte +143 -0
  34. package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
  35. package/dist/components/editor/EditorCanvasArea.svelte +85 -0
  36. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
  37. package/dist/components/editor/EditorTabs.svelte +81 -0
  38. package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
  39. package/dist/components/editor/EditorTopBar.svelte +132 -0
  40. package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
  41. package/dist/components/editor/RunsTab.svelte +256 -0
  42. package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
  43. package/dist/components/editor/SettingsTab.svelte +180 -0
  44. package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
  45. package/dist/components/editor/WorkflowEditor.svelte +185 -0
  46. package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
  47. package/dist/components/index.d.ts +1 -0
  48. package/dist/components/index.js +1 -0
  49. package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
  50. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
  51. package/dist/components/list/WorkflowList.svelte +204 -0
  52. package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
  53. package/dist/components/list/WorkflowRow.svelte +191 -0
  54. package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
  55. package/dist/components/panel/BlockProblems.svelte +47 -0
  56. package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
  57. package/dist/components/panel/CompositionForm.svelte +127 -0
  58. package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
  59. package/dist/components/panel/CompositionPicker.svelte +179 -0
  60. package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
  61. package/dist/components/panel/ConditionForm.svelte +105 -0
  62. package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
  63. package/dist/components/panel/EventValueRow.svelte +85 -0
  64. package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
  65. package/dist/components/panel/NextStepSelect.svelte +70 -0
  66. package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
  67. package/dist/components/panel/ProblemsList.svelte +101 -0
  68. package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
  69. package/dist/components/panel/RuleCard.svelte +191 -0
  70. package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
  71. package/dist/components/panel/SidePanel.svelte +82 -0
  72. package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
  73. package/dist/components/panel/TestRow.svelte +150 -0
  74. package/dist/components/panel/TestRow.svelte.d.ts +15 -0
  75. package/dist/components/panel/TestRunPanel.svelte +85 -0
  76. package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
  77. package/dist/components/panel/TestTriggerCard.svelte +121 -0
  78. package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
  79. package/dist/components/panel/TriggerForm.svelte +385 -0
  80. package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
  81. package/dist/components/panel/VersionHistory.svelte +123 -0
  82. package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
  83. package/dist/components/ui/ActionButton.svelte +85 -0
  84. package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
  85. package/dist/components/ui/ConfirmDialog.svelte +52 -0
  86. package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
  87. package/dist/components/ui/Icon.svelte +32 -0
  88. package/dist/components/ui/Icon.svelte.d.ts +9 -0
  89. package/dist/components/ui/Menu.svelte +211 -0
  90. package/dist/components/ui/Menu.svelte.d.ts +21 -0
  91. package/dist/components/ui/Modal.svelte +129 -0
  92. package/dist/components/ui/Modal.svelte.d.ts +13 -0
  93. package/dist/components/ui/Notice.svelte +36 -0
  94. package/dist/components/ui/Notice.svelte.d.ts +11 -0
  95. package/dist/components/ui/SelectField.svelte +74 -0
  96. package/dist/components/ui/SelectField.svelte.d.ts +16 -0
  97. package/dist/components/ui/StatusBadge.svelte +41 -0
  98. package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
  99. package/dist/components/ui/TextField.svelte +97 -0
  100. package/dist/components/ui/TextField.svelte.d.ts +29 -0
  101. package/dist/components/ui/icons.d.ts +34 -0
  102. package/dist/components/ui/icons.js +54 -0
  103. package/dist/components/ui/types.d.ts +26 -0
  104. package/dist/components/ui/types.js +1 -0
  105. package/dist/editor/apiErrorText.d.ts +10 -0
  106. package/dist/editor/apiErrorText.js +53 -0
  107. package/dist/editor/autosave.d.ts +47 -0
  108. package/dist/editor/autosave.js +119 -0
  109. package/dist/editor/blockLabels.d.ts +91 -0
  110. package/dist/editor/blockLabels.js +196 -0
  111. package/dist/editor/canvasContext.d.ts +52 -0
  112. package/dist/editor/canvasContext.js +37 -0
  113. package/dist/editor/canvasWords.d.ts +24 -0
  114. package/dist/editor/canvasWords.js +40 -0
  115. package/dist/editor/capabilityModel.d.ts +46 -0
  116. package/dist/editor/capabilityModel.js +113 -0
  117. package/dist/editor/editorState.svelte.d.ts +220 -0
  118. package/dist/editor/editorState.svelte.js +713 -0
  119. package/dist/editor/flowAdapter.d.ts +59 -0
  120. package/dist/editor/flowAdapter.js +166 -0
  121. package/dist/editor/formatCount.d.ts +5 -0
  122. package/dist/editor/formatCount.js +15 -0
  123. package/dist/editor/graphDiff.d.ts +27 -0
  124. package/dist/editor/graphDiff.js +64 -0
  125. package/dist/editor/graphModel.d.ts +154 -0
  126. package/dist/editor/graphModel.js +457 -0
  127. package/dist/editor/issueText.d.ts +64 -0
  128. package/dist/editor/issueText.js +101 -0
  129. package/dist/editor/listState.svelte.d.ts +82 -0
  130. package/dist/editor/listState.svelte.js +250 -0
  131. package/dist/editor/statsRange.d.ts +26 -0
  132. package/dist/editor/statsRange.js +41 -0
  133. package/dist/editor/testRun.d.ts +36 -0
  134. package/dist/editor/testRun.js +74 -0
  135. package/dist/editor/zonedTime.d.ts +20 -0
  136. package/dist/editor/zonedTime.js +134 -0
  137. package/dist/i18n/index.d.ts +2 -0
  138. package/dist/i18n/index.js +2 -0
  139. package/dist/i18n/language.d.ts +22 -0
  140. package/dist/i18n/language.js +34 -0
  141. package/dist/i18n/messages.d.ts +423 -0
  142. package/dist/i18n/messages.js +446 -0
  143. package/dist/index.d.ts +4 -0
  144. package/dist/index.js +5 -0
  145. package/dist/types/index.d.ts +66 -0
  146. package/dist/types/index.js +1 -0
  147. package/dist/utils/logger.d.ts +4 -0
  148. package/dist/utils/logger.js +35 -0
  149. package/package.json +103 -5
@@ -0,0 +1,131 @@
1
+ <!--
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.
6
+
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`.
10
+
11
+ Look and feel: nothing in here is a literal colour, font or corner. Everything reads the Widgetic palette
12
+ (`bg-white`, `text-ink-*`, `border-grey2`, `bg-primary-green`, `text-error`) and the `font-sans` / `rounded-*` scales,
13
+ which a page, or a ui-sdk theme, sets through CSS custom properties. Placement is logical (`ms-`, `me-`, `text-start`)
14
+ so the screen turns around for right to left languages.
15
+
16
+ Room: the screen fills the element it is in (`h-full w-full`). The element is the page's, and it may be shorter than
17
+ the screen needs, so the screen scrolls inside it (`overflow-auto`) and never spills over what the page has below.
18
+ -->
19
+ <script lang="ts">
20
+ import { untrack } from 'svelte';
21
+ import { writable } from 'svelte/store';
22
+ import {
23
+ shareTextDirection,
24
+ type TextDirection
25
+ } from '@widgetic/design-system/components/textDirection';
26
+ import { provideWorkflowsLanguage } from '../i18n/language.js';
27
+ import type { WorkflowsProps } from '../types/index.js';
28
+ import { workflowsError } from '../utils/logger.js';
29
+ import WorkflowsWorkspace from './WorkflowsWorkspace.svelte';
30
+
31
+ let {
32
+ apiUrl,
33
+ getAccessToken,
34
+ workspaceId,
35
+ workflowId = null,
36
+ onOpenWorkflow,
37
+ onShowEmbedCode,
38
+ locale = null,
39
+ messages: languageMessages = null,
40
+ dir = undefined,
41
+ class: className = '',
42
+ onError,
43
+ fetchImplementation
44
+ }: WorkflowsProps = $props();
45
+
46
+ // Why stores and effects below instead of `$derived`: the design system's language (`update()`) and direction
47
+ // (`shareTextDirection(given: Readable)`) contexts are store based, and every part below this root reads them as
48
+ // stores. The effects push the props into those stores; no `$state` is assigned here, so there is nothing for
49
+ // `$derived` to replace.
50
+
51
+ // "Language": made once from what the page gave, and set again below whenever the page changes it.
52
+ const language = provideWorkflowsLanguage(
53
+ untrack(() => ({ locale, messages: languageMessages }))
54
+ );
55
+ $effect(() => {
56
+ language.update({ locale, messages: languageMessages });
57
+ });
58
+ const { t } = language;
59
+
60
+ // "Reading Direction": handed down to every part through the shared store; `dir` left out means the surrounding screen's.
61
+ const givenDirection = writable<TextDirection | undefined>(untrack(() => dir));
62
+ const textDirection = shareTextDirection(givenDirection);
63
+ $effect(() => {
64
+ givenDirection.set(dir);
65
+ });
66
+
67
+ /** Tells the page about a failure without letting a handler of the page that throws take the screen down. */
68
+ function reportToPage(error: Parameters<NonNullable<WorkflowsProps['onError']>>[0]): void {
69
+ try {
70
+ onError?.(error);
71
+ } catch (handlerError) {
72
+ workflowsError('The onError handler of the page threw.', handlerError);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * A part of the screen threw while it was being drawn. The screen shows its "Try again" in place of the part, and the
78
+ * page is told once.
79
+ */
80
+ function reportRenderFailure(error: unknown): void {
81
+ const failureMessage = error instanceof Error ? error.message : String(error);
82
+ workflowsError(`The screen could not be drawn: ${failureMessage}`, error);
83
+ reportToPage({ message: failureMessage, code: 'RENDER_FAILED', fatal: false });
84
+ }
85
+ </script>
86
+
87
+ <svelte:boundary onerror={reportRenderFailure}>
88
+ <section
89
+ class="flex h-full min-h-0 w-full flex-col overflow-auto bg-white font-sans text-ink-primary {className}"
90
+ dir={$textDirection}
91
+ aria-label={$t('workflows.region.label')}
92
+ >
93
+ <!-- A workspace or an API that changes is a different set of workflows: the screen starts again for it. -->
94
+ {#key `${apiUrl}|${workspaceId}`}
95
+ <WorkflowsWorkspace
96
+ {apiUrl}
97
+ {workspaceId}
98
+ {getAccessToken}
99
+ {fetchImplementation}
100
+ {workflowId}
101
+ {onOpenWorkflow}
102
+ {onShowEmbedCode}
103
+ onError={reportToPage}
104
+ />
105
+ {/key}
106
+ </section>
107
+
108
+ <!--
109
+ The failure itself is already reported to the console and to the page (reportRenderFailure); this only needs `reset`.
110
+ `justify-center-safe`: centred while it fits, and from the top when the page's element is too short, so that the
111
+ part above the edge can still be scrolled to (plain `justify-center` would cut it off).
112
+ -->
113
+ <!-- eslint-disable-next-line @typescript-eslint/no-unused-vars -->
114
+ {#snippet failed(_error, reset)}
115
+ <section
116
+ class="flex h-full min-h-0 w-full flex-col items-center justify-center-safe gap-3 overflow-auto bg-white p-6 text-center font-sans text-ink-primary {className}"
117
+ dir={$textDirection}
118
+ role="alert"
119
+ >
120
+ <h2 class="text-base font-medium text-error">{$t('workflows.error.title')}</h2>
121
+ <p class="max-w-md text-sm text-ink-muted">{$t('workflows.error.hint')}</p>
122
+ <button
123
+ type="button"
124
+ class="rounded-medium bg-primary-green px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-green"
125
+ onclick={reset}
126
+ >
127
+ {$t('workflows.error.retry')}
128
+ </button>
129
+ </section>
130
+ {/snippet}
131
+ </svelte:boundary>
@@ -0,0 +1,4 @@
1
+ import type { WorkflowsProps } from '../types/index.js';
2
+ declare const Workflows: import("svelte").Component<WorkflowsProps, {}, "">;
3
+ type Workflows = ReturnType<typeof Workflows>;
4
+ export default Workflows;
@@ -0,0 +1,32 @@
1
+ <!--
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.
4
+
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
6
+ text this size, so the hints sit on the screen's own white and the box is drawn with its dashed border alone.
7
+ -->
8
+ <script lang="ts">
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();
19
+
20
+ const { t } = useWorkflowsLanguage();
21
+ </script>
22
+
23
+ <div
24
+ class="flex flex-1 flex-col items-center justify-center gap-3 rounded-large border border-dashed border-grey2 p-10 text-center"
25
+ >
26
+ <h2 class="text-base font-medium">{$t('workflows.empty.title')}</h2>
27
+ <p class="max-w-md text-sm text-ink-muted">{$t('workflows.empty.hint')}</p>
28
+ <ActionButton variant="primary" onclick={oncreate}>
29
+ <Icon name="plus" />
30
+ {$t('workflows.list.newWorkflow')}
31
+ </ActionButton>
32
+ </div>
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ /** The person pressed the button that makes the first workflow. */
3
+ oncreate: () => void;
4
+ }
5
+ declare const WorkflowsEmptyState: import("svelte").Component<Props, {}, "">;
6
+ type WorkflowsEmptyState = ReturnType<typeof WorkflowsEmptyState>;
7
+ export default WorkflowsEmptyState;
@@ -0,0 +1,14 @@
1
+ <!--
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
+ -->
5
+ <script lang="ts">
6
+ import { useWorkflowsLanguage } from '../i18n/language.js';
7
+
8
+ const { t } = useWorkflowsLanguage();
9
+ </script>
10
+
11
+ <header class="flex flex-col gap-1 text-start">
12
+ <h1 class="text-2xl font-semibold tracking-tight">{$t('workflows.header.title')}</h1>
13
+ <p class="text-sm text-ink-muted">{$t('workflows.header.subtitle')}</p>
14
+ </header>
@@ -0,0 +1,18 @@
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;
13
+ }
14
+ declare const WorkflowsHeader: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type WorkflowsHeader = InstanceType<typeof WorkflowsHeader>;
18
+ export default WorkflowsHeader;
@@ -0,0 +1,87 @@
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
+ onError: (error: WorkflowsError) => void;
29
+ }
30
+
31
+ let {
32
+ apiUrl,
33
+ workspaceId,
34
+ getAccessToken,
35
+ fetchImplementation,
36
+ workflowId,
37
+ onOpenWorkflow,
38
+ onShowEmbedCode,
39
+ onError
40
+ }: Props = $props();
41
+
42
+ // The client keeps what it was made with: a new workspace is a new screen, so reading the props once is what is meant.
43
+ provideWorkflowsApi(
44
+ createWorkflowsApi({
45
+ apiUrl: untrack(() => apiUrl),
46
+ workspaceId: untrack(() => workspaceId),
47
+ // The token function is read at every request, so a page that replaces it is heard.
48
+ getAccessToken: (reason, refusedToken) => getAccessToken(reason, refusedToken),
49
+ fetchImplementation: untrack(() => fetchImplementation)
50
+ })
51
+ );
52
+
53
+ /** The workflow that is open: what the page says, until the person opens or leaves one. */
54
+ let openId = $derived(workflowId ?? null);
55
+
56
+ function open(id: string | null): void {
57
+ openId = id;
58
+ try {
59
+ onOpenWorkflow?.(id);
60
+ } catch (handlerError) {
61
+ // A handler of the page that throws must not take the screen down with it; the console tells the page's developer.
62
+ workflowsError(
63
+ `The onOpenWorkflow handler of the page threw: ${handlerError instanceof Error ? handlerError.message : String(handlerError)}`,
64
+ handlerError
65
+ );
66
+ }
67
+ }
68
+ </script>
69
+
70
+ {#if openId}
71
+ <!-- A room tall enough for the canvas even when the page's element is shorter: then the screen scrolls inside it. -->
72
+ <div class="flex min-h-[36rem] flex-1 flex-col">
73
+ {#key openId}
74
+ <WorkflowEditor
75
+ workflowId={openId}
76
+ onback={() => open(null)}
77
+ onopenworkflow={(id) => open(id)}
78
+ onerror={onError}
79
+ onshowembedcode={onShowEmbedCode}
80
+ />
81
+ {/key}
82
+ </div>
83
+ {:else}
84
+ <div class="flex flex-1 flex-col p-6">
85
+ <WorkflowList onopen={(id) => open(id)} onerror={onError} onshowembedcode={onShowEmbedCode} />
86
+ </div>
87
+ {/if}
@@ -0,0 +1,14 @@
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
+ onError: (error: WorkflowsError) => void;
11
+ }
12
+ declare const WorkflowsWorkspace: import("svelte").Component<Props, {}, "">;
13
+ type WorkflowsWorkspace = ReturnType<typeof WorkflowsWorkspace>;
14
+ 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;