@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.
- package/README.md +118 -46
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +201 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +133 -0
- package/dist/api/workflowsApi.js +763 -0
- package/dist/components/Workflows.svelte +43 -17
- package/dist/components/WorkflowsEmptyState.svelte +16 -5
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
- package/dist/components/WorkflowsHeader.svelte +2 -2
- package/dist/components/WorkflowsWorkspace.svelte +90 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +15 -0
- package/dist/components/canvas/AddBlockMenu.svelte +101 -0
- package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasToolbar.svelte +95 -0
- package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
- package/dist/components/canvas/CompositionNodeView.svelte +125 -0
- package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/ConditionNodeView.svelte +95 -0
- package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/HandlePoint.svelte +32 -0
- package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
- package/dist/components/canvas/TriggerNodeView.svelte +75 -0
- package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
- package/dist/components/editor/ConflictBanner.svelte +78 -0
- package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
- package/dist/components/editor/EditorBanners.svelte +141 -0
- package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
- package/dist/components/editor/EditorCanvasArea.svelte +85 -0
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
- package/dist/components/editor/EditorTabs.svelte +81 -0
- package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +132 -0
- package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
- package/dist/components/editor/PresenceBanner.svelte +126 -0
- package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -0
- package/dist/components/editor/RunsTab.svelte +256 -0
- package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +180 -0
- package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
- package/dist/components/editor/WorkflowEditor.svelte +198 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +17 -0
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.js +0 -2
- package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
- package/dist/components/list/WorkflowList.svelte +204 -0
- package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
- package/dist/components/list/WorkflowRow.svelte +191 -0
- package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
- package/dist/components/panel/BlockProblems.svelte +47 -0
- package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
- package/dist/components/panel/CompositionForm.svelte +127 -0
- package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
- package/dist/components/panel/CompositionPicker.svelte +179 -0
- package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
- package/dist/components/panel/ConditionForm.svelte +105 -0
- package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
- package/dist/components/panel/EventValueRow.svelte +85 -0
- package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
- package/dist/components/panel/NextStepSelect.svelte +70 -0
- package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
- package/dist/components/panel/ProblemsList.svelte +101 -0
- package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
- package/dist/components/panel/RuleCard.svelte +191 -0
- package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
- package/dist/components/panel/SidePanel.svelte +82 -0
- package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestRow.svelte +150 -0
- package/dist/components/panel/TestRow.svelte.d.ts +15 -0
- package/dist/components/panel/TestRunPanel.svelte +85 -0
- package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestTriggerCard.svelte +121 -0
- package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
- package/dist/components/panel/TriggerForm.svelte +385 -0
- package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
- package/dist/components/panel/VersionHistory.svelte +123 -0
- package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
- package/dist/components/ui/ActionButton.svelte +85 -0
- package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
- package/dist/components/ui/ConfirmDialog.svelte +52 -0
- package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
- package/dist/components/ui/Icon.svelte +32 -0
- package/dist/components/ui/Icon.svelte.d.ts +9 -0
- package/dist/components/ui/Menu.svelte +211 -0
- package/dist/components/ui/Menu.svelte.d.ts +21 -0
- package/dist/components/ui/Modal.svelte +129 -0
- package/dist/components/ui/Modal.svelte.d.ts +13 -0
- package/dist/components/ui/Notice.svelte +36 -0
- package/dist/components/ui/Notice.svelte.d.ts +11 -0
- package/dist/components/ui/SelectField.svelte +74 -0
- package/dist/components/ui/SelectField.svelte.d.ts +16 -0
- package/dist/components/ui/StatusBadge.svelte +41 -0
- package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TextField.svelte +97 -0
- package/dist/components/ui/TextField.svelte.d.ts +29 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.js +54 -0
- package/dist/components/ui/types.d.ts +26 -0
- package/dist/components/ui/types.js +1 -0
- package/dist/editor/apiErrorText.d.ts +10 -0
- package/dist/editor/apiErrorText.js +53 -0
- package/dist/editor/autosave.d.ts +47 -0
- package/dist/editor/autosave.js +119 -0
- package/dist/editor/blockLabels.d.ts +91 -0
- package/dist/editor/blockLabels.js +196 -0
- package/dist/editor/canvasContext.d.ts +52 -0
- package/dist/editor/canvasContext.js +37 -0
- package/dist/editor/canvasWords.d.ts +24 -0
- package/dist/editor/canvasWords.js +40 -0
- package/dist/editor/capabilityModel.d.ts +46 -0
- package/dist/editor/capabilityModel.js +113 -0
- package/dist/editor/editLeaseController.d.ts +162 -0
- package/dist/editor/editLeaseController.js +459 -0
- package/dist/editor/editorState.svelte.d.ts +277 -0
- package/dist/editor/editorState.svelte.js +862 -0
- package/dist/editor/flowAdapter.d.ts +59 -0
- package/dist/editor/flowAdapter.js +166 -0
- package/dist/editor/formatCount.d.ts +5 -0
- package/dist/editor/formatCount.js +15 -0
- package/dist/editor/graphDiff.d.ts +27 -0
- package/dist/editor/graphDiff.js +64 -0
- package/dist/editor/graphModel.d.ts +154 -0
- package/dist/editor/graphModel.js +457 -0
- package/dist/editor/issueText.d.ts +64 -0
- package/dist/editor/issueText.js +101 -0
- package/dist/editor/keepCopy.d.ts +41 -0
- package/dist/editor/keepCopy.js +52 -0
- package/dist/editor/listState.svelte.d.ts +82 -0
- package/dist/editor/listState.svelte.js +250 -0
- package/dist/editor/statsRange.d.ts +26 -0
- package/dist/editor/statsRange.js +41 -0
- package/dist/editor/testRun.d.ts +36 -0
- package/dist/editor/testRun.js +74 -0
- package/dist/editor/zonedTime.d.ts +20 -0
- package/dist/editor/zonedTime.js +134 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +429 -4
- package/dist/i18n/messages.js +456 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +41 -3
- package/package.json +5 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One workflow in the list: its name (which opens it), where it stands, how many compositions it uses, how many visitors
|
|
3
|
+
started it, when it was last published and made, and a menu of what can be done to it from here.
|
|
4
|
+
|
|
5
|
+
What the menu offers follows the workflow: a live one can be paused, a published one can be archived (never deleted: pages
|
|
6
|
+
out there may carry its id), an archived one can be brought back, and any can be copied. The two that cannot be taken back
|
|
7
|
+
ask first.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { WorkflowListItem } from '../../api/types.js';
|
|
11
|
+
import { formatDay } from '../../editor/blockLabels.js';
|
|
12
|
+
import { formatCount } from '../../editor/formatCount.js';
|
|
13
|
+
import { useListState } from '../../editor/listState.svelte.js';
|
|
14
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
15
|
+
import ConfirmDialog from '../ui/ConfirmDialog.svelte';
|
|
16
|
+
import Menu from '../ui/Menu.svelte';
|
|
17
|
+
import StatusBadge from '../ui/StatusBadge.svelte';
|
|
18
|
+
import type { MenuGroup } from '../ui/types.js';
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
item: WorkflowListItem;
|
|
22
|
+
onopen: (workflowId: string) => void;
|
|
23
|
+
/** Shows the embed code of a workflow; absent when the page that hosts the screen has no such dialog. */
|
|
24
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let { item, onopen, onshowembedcode }: Props = $props();
|
|
28
|
+
|
|
29
|
+
const list = useListState();
|
|
30
|
+
const { t, locale } = useWorkflowsLanguage();
|
|
31
|
+
|
|
32
|
+
let asking = $state<'archive' | 'delete' | null>(null);
|
|
33
|
+
|
|
34
|
+
const isBusy = $derived(list.busyIds.has(item.id));
|
|
35
|
+
const wasPublished = $derived(item.firstPublishedAt !== null);
|
|
36
|
+
|
|
37
|
+
const groups = $derived.by<MenuGroup[]>(() => {
|
|
38
|
+
const states: MenuGroup['items'][number][] = [];
|
|
39
|
+
if (item.status === 'live') {
|
|
40
|
+
states.push({
|
|
41
|
+
key: 'pause',
|
|
42
|
+
label: $t('workflows.settings.pause'),
|
|
43
|
+
icon: 'pause',
|
|
44
|
+
onSelect: () => void list.changeState(item.id, 'pause')
|
|
45
|
+
});
|
|
46
|
+
} else if (item.status === 'paused') {
|
|
47
|
+
states.push({
|
|
48
|
+
key: 'resume',
|
|
49
|
+
label: $t('workflows.settings.resume'),
|
|
50
|
+
icon: 'play',
|
|
51
|
+
onSelect: () => void list.changeState(item.id, 'resume')
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (item.status === 'archived') {
|
|
55
|
+
states.push({
|
|
56
|
+
key: 'unarchive',
|
|
57
|
+
label: $t('workflows.settings.unarchive'),
|
|
58
|
+
icon: 'undo',
|
|
59
|
+
onSelect: () => void list.changeState(item.id, 'unarchive')
|
|
60
|
+
});
|
|
61
|
+
} else if (wasPublished) {
|
|
62
|
+
states.push({
|
|
63
|
+
key: 'archive',
|
|
64
|
+
label: $t('workflows.settings.archive'),
|
|
65
|
+
icon: 'archive',
|
|
66
|
+
onSelect: () => (asking = 'archive')
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
key: 'open',
|
|
72
|
+
items: [
|
|
73
|
+
{
|
|
74
|
+
key: 'open',
|
|
75
|
+
label: $t('workflows.list.open'),
|
|
76
|
+
icon: 'open',
|
|
77
|
+
onSelect: () => onopen(item.id)
|
|
78
|
+
},
|
|
79
|
+
...(onshowembedcode && wasPublished
|
|
80
|
+
? [
|
|
81
|
+
{
|
|
82
|
+
key: 'embed',
|
|
83
|
+
label: $t('workflows.top.embedCode'),
|
|
84
|
+
icon: 'code' as const,
|
|
85
|
+
onSelect: () => onshowembedcode(item.id)
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
: []),
|
|
89
|
+
{
|
|
90
|
+
key: 'duplicate',
|
|
91
|
+
label: $t('workflows.settings.duplicate'),
|
|
92
|
+
icon: 'copy',
|
|
93
|
+
onSelect: () => void list.duplicate(item.id)
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
...(states.length > 0 ? [{ key: 'states', items: states }] : []),
|
|
98
|
+
{
|
|
99
|
+
key: 'danger',
|
|
100
|
+
items: [
|
|
101
|
+
{
|
|
102
|
+
key: 'delete',
|
|
103
|
+
label: $t('workflows.settings.delete'),
|
|
104
|
+
description: wasPublished ? $t('workflows.settings.deleteBlocked') : undefined,
|
|
105
|
+
icon: 'trash',
|
|
106
|
+
tone: 'danger',
|
|
107
|
+
disabled: wasPublished,
|
|
108
|
+
onSelect: () => (asking = 'delete')
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
async function confirmArchive(): Promise<void> {
|
|
116
|
+
await list.changeState(item.id, 'archive');
|
|
117
|
+
asking = null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function confirmDelete(): Promise<void> {
|
|
121
|
+
await list.remove(item.id);
|
|
122
|
+
asking = null;
|
|
123
|
+
}
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<li
|
|
127
|
+
class="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 rounded-large border border-grey2 px-4 py-3 aria-busy:opacity-60 @2xl:grid-cols-[minmax(0,2fr)_7rem_6rem_8rem_8rem_auto]"
|
|
128
|
+
aria-busy={isBusy}
|
|
129
|
+
>
|
|
130
|
+
<div class="flex min-w-0 flex-col">
|
|
131
|
+
<button
|
|
132
|
+
type="button"
|
|
133
|
+
class="truncate text-start text-sm font-medium hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-green"
|
|
134
|
+
dir="auto"
|
|
135
|
+
onclick={() => onopen(item.id)}
|
|
136
|
+
>
|
|
137
|
+
{item.name}
|
|
138
|
+
</button>
|
|
139
|
+
<span class="text-xs text-ink-muted"
|
|
140
|
+
>{$t('workflows.list.compositionsCount', { count: item.compositionIds.length })}</span
|
|
141
|
+
>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="@2xl:order-none">
|
|
144
|
+
<StatusBadge status={item.status} hasUnpublishedChanges={item.unpublishedChanges} />
|
|
145
|
+
</div>
|
|
146
|
+
<span class="hidden text-sm @2xl:block">{formatCount(item.runsCount, $locale)}</span>
|
|
147
|
+
<span class="hidden text-sm text-ink-muted @2xl:block">
|
|
148
|
+
{item.lastPublishedAt ? formatDay(item.lastPublishedAt, $locale) : $t('workflows.list.never')}
|
|
149
|
+
</span>
|
|
150
|
+
<span class="hidden text-sm text-ink-muted @2xl:block">{formatDay(item.createdAt, $locale)}</span>
|
|
151
|
+
<!-- On a narrow screen the figures that have no column of their own are one line under the name. -->
|
|
152
|
+
<p class="col-span-2 text-xs text-ink-muted @2xl:hidden">
|
|
153
|
+
{$t('workflows.list.runsCount', { count: item.runsCount })} ·
|
|
154
|
+
{item.lastPublishedAt
|
|
155
|
+
? $t('workflows.list.publishedOn', { date: formatDay(item.lastPublishedAt, $locale) })
|
|
156
|
+
: $t('workflows.list.neverPublished')}
|
|
157
|
+
</p>
|
|
158
|
+
<div class="col-start-2 row-start-1 @2xl:col-start-auto @2xl:row-start-auto">
|
|
159
|
+
<Menu
|
|
160
|
+
{groups}
|
|
161
|
+
label={$t('workflows.list.rowMenu', { name: item.name })}
|
|
162
|
+
icon="more"
|
|
163
|
+
iconOnly
|
|
164
|
+
variant="ghost"
|
|
165
|
+
size="small"
|
|
166
|
+
align="end"
|
|
167
|
+
disabled={isBusy}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
</li>
|
|
171
|
+
|
|
172
|
+
{#if asking === 'archive'}
|
|
173
|
+
<ConfirmDialog
|
|
174
|
+
title={$t('workflows.settings.archiveTitle')}
|
|
175
|
+
message={$t('workflows.settings.archiveMessage')}
|
|
176
|
+
confirmLabel={$t('workflows.settings.archive')}
|
|
177
|
+
busy={isBusy}
|
|
178
|
+
onconfirm={() => void confirmArchive()}
|
|
179
|
+
oncancel={() => (asking = null)}
|
|
180
|
+
/>
|
|
181
|
+
{:else if asking === 'delete'}
|
|
182
|
+
<ConfirmDialog
|
|
183
|
+
title={$t('workflows.settings.deleteTitle')}
|
|
184
|
+
message={$t('workflows.settings.deleteMessage', { name: item.name })}
|
|
185
|
+
confirmLabel={$t('workflows.settings.delete')}
|
|
186
|
+
tone="danger"
|
|
187
|
+
busy={isBusy}
|
|
188
|
+
onconfirm={() => void confirmDelete()}
|
|
189
|
+
oncancel={() => (asking = null)}
|
|
190
|
+
/>
|
|
191
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkflowListItem } from '../../api/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
item: WorkflowListItem;
|
|
4
|
+
onopen: (workflowId: string) => void;
|
|
5
|
+
/** Shows the embed code of a workflow; absent when the page that hosts the screen has no such dialog. */
|
|
6
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const WorkflowRow: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type WorkflowRow = ReturnType<typeof WorkflowRow>;
|
|
10
|
+
export default WorkflowRow;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What the check finds wrong with one block, in sentences, under the form of that block. The draft is checked all the time
|
|
3
|
+
with the engine's own rules (the same ones the publish applies), so a person sees what stops a publish while they build
|
|
4
|
+
instead of after they press the button. Warnings are advice and are not red.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { describeBlocksUniquely } from '../../editor/blockLabels.js';
|
|
8
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
9
|
+
import { describeIssue } from '../../editor/issueText.js';
|
|
10
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
11
|
+
import Icon from '../ui/Icon.svelte';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
nodeId: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let { nodeId }: Props = $props();
|
|
18
|
+
|
|
19
|
+
const editor = useEditorState();
|
|
20
|
+
const { t } = useWorkflowsLanguage();
|
|
21
|
+
|
|
22
|
+
const sentences = $derived.by(() => {
|
|
23
|
+
const issues = editor.issuesOnCanvas.byNode.get(nodeId) ?? [];
|
|
24
|
+
if (issues.length === 0) return [];
|
|
25
|
+
const labels = describeBlocksUniquely(editor.graph, editor.options, $t);
|
|
26
|
+
const context = { t: $t, describeBlock: (blockId: string) => labels.get(blockId) ?? '' };
|
|
27
|
+
return issues.map((issue) => ({
|
|
28
|
+
severity: issue.severity,
|
|
29
|
+
text: describeIssue(issue, context)
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
{#if sentences.length > 0}
|
|
35
|
+
<ul class="flex flex-col gap-1.5" aria-label={$t('workflows.panel.problemsLabel')}>
|
|
36
|
+
{#each sentences as sentence, index (index)}
|
|
37
|
+
<li
|
|
38
|
+
class="flex items-start gap-2 text-xs {sentence.severity === 'error'
|
|
39
|
+
? 'text-error'
|
|
40
|
+
: 'text-ink-muted'}"
|
|
41
|
+
>
|
|
42
|
+
<Icon name="warning" class="mt-0.5 size-3.5" />
|
|
43
|
+
<span>{sentence.text}</span>
|
|
44
|
+
</li>
|
|
45
|
+
{/each}
|
|
46
|
+
</ul>
|
|
47
|
+
{/if}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The side panel for a composition block: which composition it shows, whether it is where visitors start, and what the
|
|
3
|
+
composition can do for a workflow (the values it keeps and the actions its widget reports), which decides what triggers
|
|
4
|
+
can follow it. Choosing another composition keeps the block and the lines around it.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { CompositionNode } from '@widgetic/workflows-engine';
|
|
8
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
9
|
+
import { CAPABILITY_REASON_MESSAGE_KEYS } from '../../editor/blockLabels.js';
|
|
10
|
+
import {
|
|
11
|
+
listActionChoices,
|
|
12
|
+
listInputTables,
|
|
13
|
+
readTriggerAvailability
|
|
14
|
+
} from '../../editor/capabilityModel.js';
|
|
15
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
16
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
17
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
18
|
+
import Icon from '../ui/Icon.svelte';
|
|
19
|
+
import BlockProblems from './BlockProblems.svelte';
|
|
20
|
+
import CompositionPicker from './CompositionPicker.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
node: CompositionNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let { node }: Props = $props();
|
|
27
|
+
|
|
28
|
+
const editor = useEditorState();
|
|
29
|
+
const { t } = useWorkflowsLanguage();
|
|
30
|
+
const capabilitiesHeadingId = $props.id();
|
|
31
|
+
|
|
32
|
+
/** What the API says about the composition of this block; `undefined` before it answers, `null` when it is not there. */
|
|
33
|
+
const option = $derived(node.compositionId ? editor.options[node.compositionId] : undefined);
|
|
34
|
+
const otherCompositionIds = $derived(
|
|
35
|
+
editor.compositionIds.filter((compositionId) => compositionId !== node.compositionId)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const inputAvailability = $derived(readTriggerAvailability(option, 'input'));
|
|
39
|
+
const actionAvailability = $derived(readTriggerAvailability(option, 'action'));
|
|
40
|
+
|
|
41
|
+
function chooseComposition(chosen: CompositionOption): void {
|
|
42
|
+
editor.rememberCompositions([chosen]);
|
|
43
|
+
editor.replaceBlock({ ...node, compositionId: chosen.id });
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div class="flex flex-col gap-4">
|
|
48
|
+
<div>
|
|
49
|
+
<h3 class="text-sm font-semibold">{$t('workflows.composition.heading')}</h3>
|
|
50
|
+
<p class="text-xs text-ink-muted">{$t('workflows.composition.help')}</p>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<BlockProblems nodeId={node.id} />
|
|
54
|
+
|
|
55
|
+
{#if !editor.isReadOnly}
|
|
56
|
+
<CompositionPicker
|
|
57
|
+
selectedId={node.compositionId || null}
|
|
58
|
+
takenIds={otherCompositionIds}
|
|
59
|
+
onpick={chooseComposition}
|
|
60
|
+
onread={(options) => editor.rememberCompositions(options)}
|
|
61
|
+
/>
|
|
62
|
+
{/if}
|
|
63
|
+
|
|
64
|
+
{#if node.startsHere}
|
|
65
|
+
<p class="flex items-center gap-2 text-xs text-primary-green">
|
|
66
|
+
<Icon name="check" class="size-3.5" />
|
|
67
|
+
{$t('workflows.composition.isStart')}
|
|
68
|
+
</p>
|
|
69
|
+
{:else if !editor.isReadOnly}
|
|
70
|
+
<ActionButton size="small" onclick={() => editor.makeStart(node.id)}
|
|
71
|
+
>{$t('workflows.composition.makeStart')}</ActionButton
|
|
72
|
+
>
|
|
73
|
+
{/if}
|
|
74
|
+
|
|
75
|
+
{#if option}
|
|
76
|
+
<section
|
|
77
|
+
class="flex flex-col gap-2 border-t border-grey2 pt-3"
|
|
78
|
+
aria-labelledby={capabilitiesHeadingId}
|
|
79
|
+
>
|
|
80
|
+
<h4 id={capabilitiesHeadingId} class="text-xs font-semibold">
|
|
81
|
+
{$t('workflows.composition.capabilitiesHeading')}
|
|
82
|
+
</h4>
|
|
83
|
+
<dl class="flex flex-col gap-2 text-xs">
|
|
84
|
+
<div class="flex flex-col gap-0.5">
|
|
85
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityInput')}</dt>
|
|
86
|
+
<dd>
|
|
87
|
+
{#if inputAvailability.enabled}
|
|
88
|
+
{$t('workflows.composition.inputTables', {
|
|
89
|
+
tables: listInputTables(option).join(', ')
|
|
90
|
+
})}
|
|
91
|
+
{:else}
|
|
92
|
+
{$t(CAPABILITY_REASON_MESSAGE_KEYS[inputAvailability.reason])}
|
|
93
|
+
{/if}
|
|
94
|
+
</dd>
|
|
95
|
+
</div>
|
|
96
|
+
<div class="flex flex-col gap-0.5">
|
|
97
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityAction')}</dt>
|
|
98
|
+
<dd>
|
|
99
|
+
{#if actionAvailability.enabled}
|
|
100
|
+
{$t('workflows.composition.actionCount', { count: listActionChoices(option).length })}
|
|
101
|
+
{:else}
|
|
102
|
+
{$t(CAPABILITY_REASON_MESSAGE_KEYS[actionAvailability.reason])}
|
|
103
|
+
{/if}
|
|
104
|
+
</dd>
|
|
105
|
+
</div>
|
|
106
|
+
{#if option.allowedWebsites.length > 0}
|
|
107
|
+
<div class="flex flex-col gap-0.5">
|
|
108
|
+
<dt class="text-ink-muted">{$t('workflows.composition.capabilityWebsites')}</dt>
|
|
109
|
+
<dd class="break-words">{option.allowedWebsites.join(', ')}</dd>
|
|
110
|
+
</div>
|
|
111
|
+
{/if}
|
|
112
|
+
</dl>
|
|
113
|
+
</section>
|
|
114
|
+
{/if}
|
|
115
|
+
|
|
116
|
+
{#if !editor.isReadOnly}
|
|
117
|
+
<ActionButton
|
|
118
|
+
variant="danger"
|
|
119
|
+
size="small"
|
|
120
|
+
class="self-start"
|
|
121
|
+
onclick={() => editor.removeBlock(node.id)}
|
|
122
|
+
>
|
|
123
|
+
<Icon name="trash" />
|
|
124
|
+
{$t('workflows.panel.removeBlock')}
|
|
125
|
+
</ActionButton>
|
|
126
|
+
{/if}
|
|
127
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CompositionNode } from '@widgetic/workflows-engine';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: CompositionNode;
|
|
4
|
+
}
|
|
5
|
+
declare const CompositionForm: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type CompositionForm = ReturnType<typeof CompositionForm>;
|
|
7
|
+
export default CompositionForm;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A list of the compositions a person may use in a workflow, with a search above it. Used where a composition is chosen: when a
|
|
3
|
+
workflow is made, and on a composition block. Each line has the composition's picture and name; one that is already in the
|
|
4
|
+
workflow is shown but cannot be chosen again (a composition has one block), and one whose widget was never published says so.
|
|
5
|
+
|
|
6
|
+
It asks the API for twenty at a time (`composition-options`), and for the next twenty when asked. Every search replaces the
|
|
7
|
+
one before it: an answer to an older search that arrives late is dropped.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { onDestroy, onMount } from 'svelte';
|
|
11
|
+
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
12
|
+
import { isCancelled } from '../../api/workflowsApi.js';
|
|
13
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
14
|
+
import { pickApiErrorMessage } from '../../editor/apiErrorText.js';
|
|
15
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
16
|
+
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
17
|
+
import { workflowsError } from '../../utils/logger.js';
|
|
18
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
19
|
+
import Icon from '../ui/Icon.svelte';
|
|
20
|
+
import TextField from '../ui/TextField.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
/** The composition that is chosen now, if any. */
|
|
24
|
+
selectedId?: string | null;
|
|
25
|
+
/** Compositions already in the workflow: shown, but cannot be chosen. */
|
|
26
|
+
takenIds?: readonly string[];
|
|
27
|
+
/** Called with every composition the person picks, so the owner can remember its name and picture. */
|
|
28
|
+
onpick: (option: CompositionOption) => void;
|
|
29
|
+
/** Called with each page of compositions that was read, so the owner can remember them. */
|
|
30
|
+
onread?: (options: readonly CompositionOption[]) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let { selectedId = null, takenIds = [], onpick, onread }: Props = $props();
|
|
34
|
+
|
|
35
|
+
const PAGE_SIZE = 20;
|
|
36
|
+
const SEARCH_DELAY_MILLISECONDS = 300;
|
|
37
|
+
|
|
38
|
+
const api = useWorkflowsApi();
|
|
39
|
+
const { t } = useWorkflowsLanguage();
|
|
40
|
+
|
|
41
|
+
let search = $state('');
|
|
42
|
+
let items = $state.raw<readonly CompositionOption[]>([]);
|
|
43
|
+
let total = $state(0);
|
|
44
|
+
let loadState = $state<'loading' | 'ready' | 'failed'>('loading');
|
|
45
|
+
let failureKey = $state.raw<WorkflowsMessageKey | null>(null);
|
|
46
|
+
let isLoadingMore = $state(false);
|
|
47
|
+
|
|
48
|
+
let controller: AbortController | null = null;
|
|
49
|
+
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
|
50
|
+
|
|
51
|
+
const taken = $derived(new Set(takenIds));
|
|
52
|
+
const hasMore = $derived(items.length < total);
|
|
53
|
+
|
|
54
|
+
/** Reads the first page for what is in the search box now (or the next page, when `append`). */
|
|
55
|
+
async function read(append: boolean): Promise<void> {
|
|
56
|
+
controller?.abort();
|
|
57
|
+
const current = new AbortController();
|
|
58
|
+
controller = current;
|
|
59
|
+
if (append) isLoadingMore = true;
|
|
60
|
+
else loadState = items.length === 0 ? 'loading' : loadState;
|
|
61
|
+
failureKey = null;
|
|
62
|
+
try {
|
|
63
|
+
const trimmed = search.trim();
|
|
64
|
+
const page = await api.listCompositionOptions(
|
|
65
|
+
{
|
|
66
|
+
...(trimmed === '' ? {} : { search: trimmed }),
|
|
67
|
+
limit: PAGE_SIZE,
|
|
68
|
+
offset: append ? items.length : 0
|
|
69
|
+
},
|
|
70
|
+
{ signal: current.signal }
|
|
71
|
+
);
|
|
72
|
+
if (current.signal.aborted) return;
|
|
73
|
+
const known = new Set(append ? items.map((item) => item.id) : []);
|
|
74
|
+
items = append ? [...items, ...page.items.filter((item) => !known.has(item.id))] : page.items;
|
|
75
|
+
total = page.total;
|
|
76
|
+
loadState = 'ready';
|
|
77
|
+
onread?.(page.items);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (isCancelled(error)) return;
|
|
80
|
+
workflowsError('Reading the compositions failed.', error);
|
|
81
|
+
failureKey = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
82
|
+
loadState = 'failed';
|
|
83
|
+
} finally {
|
|
84
|
+
if (controller === current) isLoadingMore = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleSearchChange(): void {
|
|
89
|
+
if (searchTimer !== null) clearTimeout(searchTimer);
|
|
90
|
+
searchTimer = setTimeout(() => {
|
|
91
|
+
searchTimer = null;
|
|
92
|
+
void read(false);
|
|
93
|
+
}, SEARCH_DELAY_MILLISECONDS);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onMount(() => {
|
|
97
|
+
void read(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
onDestroy(() => {
|
|
101
|
+
controller?.abort();
|
|
102
|
+
if (searchTimer !== null) clearTimeout(searchTimer);
|
|
103
|
+
});
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<div class="flex min-h-0 flex-col gap-2">
|
|
107
|
+
<TextField
|
|
108
|
+
type="search"
|
|
109
|
+
label={$t('workflows.composition.searchLabel')}
|
|
110
|
+
placeholder={$t('workflows.composition.searchPlaceholder')}
|
|
111
|
+
hideLabel
|
|
112
|
+
bind:value={search}
|
|
113
|
+
oninput={handleSearchChange}
|
|
114
|
+
/>
|
|
115
|
+
|
|
116
|
+
{#if loadState === 'loading'}
|
|
117
|
+
<p class="py-4 text-center text-sm text-ink-muted" role="status">
|
|
118
|
+
{$t('workflows.common.loading')}
|
|
119
|
+
</p>
|
|
120
|
+
{:else if loadState === 'failed'}
|
|
121
|
+
<div class="flex flex-col items-start gap-2 py-2">
|
|
122
|
+
<p class="text-sm text-error" role="alert">{failureKey ? $t(failureKey) : ''}</p>
|
|
123
|
+
<ActionButton size="small" onclick={() => void read(false)}
|
|
124
|
+
>{$t('workflows.error.retry')}</ActionButton
|
|
125
|
+
>
|
|
126
|
+
</div>
|
|
127
|
+
{:else if items.length === 0}
|
|
128
|
+
<p class="py-4 text-center text-sm text-ink-muted">{$t('workflows.composition.none')}</p>
|
|
129
|
+
{:else}
|
|
130
|
+
<ul class="flex max-h-72 flex-col gap-1 overflow-auto">
|
|
131
|
+
{#each items as option (option.id)}
|
|
132
|
+
{@const isSelected = option.id === selectedId}
|
|
133
|
+
{@const isTaken = taken.has(option.id) && !isSelected}
|
|
134
|
+
<li>
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
disabled={isTaken}
|
|
138
|
+
aria-current={isSelected ? 'true' : undefined}
|
|
139
|
+
class="flex w-full items-center gap-3 rounded-medium border px-2 py-2 text-start text-sm focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {isSelected
|
|
140
|
+
? 'border-primary-green'
|
|
141
|
+
: 'border-grey2 hover:border-ink-subtle'}"
|
|
142
|
+
onclick={() => onpick(option)}
|
|
143
|
+
>
|
|
144
|
+
{#if option.thumbnailUrl}
|
|
145
|
+
<img
|
|
146
|
+
src={option.thumbnailUrl}
|
|
147
|
+
alt=""
|
|
148
|
+
loading="lazy"
|
|
149
|
+
draggable="false"
|
|
150
|
+
class="h-10 w-14 shrink-0 rounded-small border border-grey2 object-cover"
|
|
151
|
+
/>
|
|
152
|
+
{:else}
|
|
153
|
+
<span
|
|
154
|
+
class="flex h-10 w-14 shrink-0 items-center justify-center rounded-small border border-grey2 text-ink-muted"
|
|
155
|
+
>
|
|
156
|
+
<Icon name="composition" />
|
|
157
|
+
</span>
|
|
158
|
+
{/if}
|
|
159
|
+
<span class="flex min-w-0 flex-1 flex-col">
|
|
160
|
+
<span class="truncate font-medium" dir="auto">{option.name}</span>
|
|
161
|
+
{#if isTaken}
|
|
162
|
+
<span class="text-xs text-ink-muted">{$t('workflows.composition.alreadyUsed')}</span
|
|
163
|
+
>
|
|
164
|
+
{:else if !option.published}
|
|
165
|
+
<span class="text-xs text-ink-muted">{$t('workflows.block.notPublished')}</span>
|
|
166
|
+
{/if}
|
|
167
|
+
</span>
|
|
168
|
+
{#if isSelected}<Icon name="check" class="size-4 text-primary-green" />{/if}
|
|
169
|
+
</button>
|
|
170
|
+
</li>
|
|
171
|
+
{/each}
|
|
172
|
+
</ul>
|
|
173
|
+
{#if hasMore}
|
|
174
|
+
<ActionButton size="small" disabled={isLoadingMore} onclick={() => void read(true)}>
|
|
175
|
+
{isLoadingMore ? $t('workflows.common.loading') : $t('workflows.list.showMore')}
|
|
176
|
+
</ActionButton>
|
|
177
|
+
{/if}
|
|
178
|
+
{/if}
|
|
179
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CompositionOption } from '../../api/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The composition that is chosen now, if any. */
|
|
4
|
+
selectedId?: string | null;
|
|
5
|
+
/** Compositions already in the workflow: shown, but cannot be chosen. */
|
|
6
|
+
takenIds?: readonly string[];
|
|
7
|
+
/** Called with every composition the person picks, so the owner can remember its name and picture. */
|
|
8
|
+
onpick: (option: CompositionOption) => void;
|
|
9
|
+
/** Called with each page of compositions that was read, so the owner can remember them. */
|
|
10
|
+
onread?: (options: readonly CompositionOption[]) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const CompositionPicker: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type CompositionPicker = ReturnType<typeof CompositionPicker>;
|
|
14
|
+
export default CompositionPicker;
|