@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,198 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
An open workflow: the top bar, the tabs (Editor, Runs, Settings), the lines that say where it stands, and the tab that is
|
|
3
|
+
open. It makes the editor's state for the workflow, shares it with every part below it, reads the workflow and keeps the
|
|
4
|
+
draft saved while the person works.
|
|
5
|
+
|
|
6
|
+
Leaving: what is waiting to be saved is sent first. If it cannot be sent (offline, or the draft was changed somewhere else)
|
|
7
|
+
the person is asked before it is thrown away.
|
|
8
|
+
|
|
9
|
+
What it listens to outside itself it takes back when it goes: the media query for a screen touched by a finger, and the
|
|
10
|
+
page being put away (which sends what is waiting, as far as the browser lets it).
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { onDestroy, onMount, untrack } from 'svelte';
|
|
14
|
+
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
15
|
+
import { WorkflowEditorState, provideEditorState } from '../../editor/editorState.svelte.js';
|
|
16
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
17
|
+
import type { WorkflowsError } from '../../types/index.js';
|
|
18
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
19
|
+
import ConfirmDialog from '../ui/ConfirmDialog.svelte';
|
|
20
|
+
import Notice from '../ui/Notice.svelte';
|
|
21
|
+
import EditorBanners from './EditorBanners.svelte';
|
|
22
|
+
import EditorCanvasArea from './EditorCanvasArea.svelte';
|
|
23
|
+
import EditorTabs from './EditorTabs.svelte';
|
|
24
|
+
import EditorTopBar from './EditorTopBar.svelte';
|
|
25
|
+
import RunsTab from './RunsTab.svelte';
|
|
26
|
+
import SettingsTab from './SettingsTab.svelte';
|
|
27
|
+
|
|
28
|
+
interface Props {
|
|
29
|
+
workflowId: string;
|
|
30
|
+
/** The person is done with this workflow: back to the list. */
|
|
31
|
+
onback: () => void;
|
|
32
|
+
/** Another workflow should be opened (a duplicate was made). */
|
|
33
|
+
onopenworkflow: (workflowId: string) => void;
|
|
34
|
+
/** A failure the page should hear about. */
|
|
35
|
+
onerror: (error: WorkflowsError) => void;
|
|
36
|
+
/** Shows the embed code of the workflow; the page that hosts the screen decides what that looks like. */
|
|
37
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
38
|
+
/** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
|
|
39
|
+
presence?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let {
|
|
43
|
+
workflowId,
|
|
44
|
+
onback,
|
|
45
|
+
onopenworkflow,
|
|
46
|
+
onerror,
|
|
47
|
+
onshowembedcode,
|
|
48
|
+
presence = false
|
|
49
|
+
}: Props = $props();
|
|
50
|
+
|
|
51
|
+
const api = useWorkflowsApi();
|
|
52
|
+
const { t } = useWorkflowsLanguage();
|
|
53
|
+
const panelId = $props.id();
|
|
54
|
+
|
|
55
|
+
// The editor belongs to one workflow: the screen that shows another one makes this again (a `{#key}` around it).
|
|
56
|
+
const editor = new WorkflowEditorState({
|
|
57
|
+
api,
|
|
58
|
+
workflowId: untrack(() => workflowId),
|
|
59
|
+
// Read once, like the workflow: presence belongs to this opening of it.
|
|
60
|
+
presence: untrack(() => presence),
|
|
61
|
+
reportError: (error) => onerror(error),
|
|
62
|
+
leave: () => onback(),
|
|
63
|
+
openWorkflow: (openedId) => onopenworkflow(openedId)
|
|
64
|
+
});
|
|
65
|
+
provideEditorState(editor);
|
|
66
|
+
|
|
67
|
+
let isAskingToPublish = $state(false);
|
|
68
|
+
let isAskingToLeave = $state(false);
|
|
69
|
+
|
|
70
|
+
const showEmbedCode = $derived(
|
|
71
|
+
onshowembedcode ? () => onshowembedcode(editor.workflowId) : undefined
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// ---- publishing ---------------------------------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
/** Publish was pressed: a draft with problems says what is wrong, any other asks once before visitors get the change. */
|
|
77
|
+
function requestPublish(): void {
|
|
78
|
+
if (editor.hasPublishBlockers) void editor.publish();
|
|
79
|
+
else isAskingToPublish = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function confirmPublish(): Promise<void> {
|
|
83
|
+
await editor.publish();
|
|
84
|
+
isAskingToPublish = false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ---- leaving ------------------------------------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
async function goBack(): Promise<void> {
|
|
90
|
+
const saveState = await editor.flushSaves();
|
|
91
|
+
if (saveState === 'failed' || saveState === 'conflict') {
|
|
92
|
+
isAskingToLeave = true;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
onback();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onMount(() => {
|
|
99
|
+
void editor.load();
|
|
100
|
+
// Who else is editing is asked alongside the load (it needs only the workflow's id); nothing happens without `presence`.
|
|
101
|
+
editor.startPresence();
|
|
102
|
+
|
|
103
|
+
// A finger cannot draw a line between two small points: on a touch screen the canvas only shows (the panel edits).
|
|
104
|
+
const touchQuery = window.matchMedia('(pointer: coarse)');
|
|
105
|
+
editor.canvasTouchOnly = touchQuery.matches;
|
|
106
|
+
const followTouch = (event: MediaQueryListEvent) => (editor.canvasTouchOnly = event.matches);
|
|
107
|
+
touchQuery.addEventListener('change', followTouch);
|
|
108
|
+
|
|
109
|
+
// A page put away (a tab closed, an app switched on a phone) sends what is waiting, as far as the browser allows it.
|
|
110
|
+
const sendWhenHidden = () => {
|
|
111
|
+
if (document.visibilityState === 'hidden') void editor.flushSaves();
|
|
112
|
+
};
|
|
113
|
+
document.addEventListener('visibilitychange', sendWhenHidden);
|
|
114
|
+
window.addEventListener('pagehide', sendWhenHidden);
|
|
115
|
+
|
|
116
|
+
return () => {
|
|
117
|
+
touchQuery.removeEventListener('change', followTouch);
|
|
118
|
+
document.removeEventListener('visibilitychange', sendWhenHidden);
|
|
119
|
+
window.removeEventListener('pagehide', sendWhenHidden);
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
onDestroy(() => {
|
|
124
|
+
void editor.finish();
|
|
125
|
+
});
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<div class="@container flex h-full min-h-0 w-full flex-col" data-workflows-editor>
|
|
129
|
+
{#if editor.loadState === 'loading'}
|
|
130
|
+
<p class="m-auto py-10 text-sm text-ink-muted" role="status">
|
|
131
|
+
{$t('workflows.common.loading')}
|
|
132
|
+
</p>
|
|
133
|
+
{:else if editor.loadState === 'failed'}
|
|
134
|
+
<div class="m-auto flex max-w-md flex-col items-start gap-3 p-6">
|
|
135
|
+
<Notice tone="problem">{$t(editor.loadFailure ?? 'workflows.error.generic')}</Notice>
|
|
136
|
+
<div class="flex gap-2">
|
|
137
|
+
<ActionButton variant="primary" onclick={() => void editor.load()}
|
|
138
|
+
>{$t('workflows.error.retry')}</ActionButton
|
|
139
|
+
>
|
|
140
|
+
<ActionButton onclick={onback}>{$t('workflows.top.back')}</ActionButton>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
{:else}
|
|
144
|
+
<EditorTopBar
|
|
145
|
+
onback={() => void goBack()}
|
|
146
|
+
onpublish={requestPublish}
|
|
147
|
+
onshowembedcode={showEmbedCode}
|
|
148
|
+
/>
|
|
149
|
+
<EditorTabs {panelId} />
|
|
150
|
+
<div class="hidden flex-col gap-2 px-4 pt-3 has-[>*]:flex">
|
|
151
|
+
<EditorBanners onpublish={requestPublish} />
|
|
152
|
+
</div>
|
|
153
|
+
<div
|
|
154
|
+
id={panelId}
|
|
155
|
+
role="tabpanel"
|
|
156
|
+
aria-labelledby="{panelId}-tab-{editor.tab}"
|
|
157
|
+
class="flex min-h-0 flex-1 flex-col"
|
|
158
|
+
>
|
|
159
|
+
{#if editor.tab === 'editor'}
|
|
160
|
+
<EditorCanvasArea />
|
|
161
|
+
{:else if editor.tab === 'runs'}
|
|
162
|
+
<RunsTab />
|
|
163
|
+
{:else}
|
|
164
|
+
<div class="min-h-0 flex-1 overflow-auto">
|
|
165
|
+
<SettingsTab onshowembedcode={showEmbedCode} />
|
|
166
|
+
</div>
|
|
167
|
+
{/if}
|
|
168
|
+
</div>
|
|
169
|
+
{/if}
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
{#if isAskingToPublish}
|
|
173
|
+
<ConfirmDialog
|
|
174
|
+
title={editor.status === 'draft'
|
|
175
|
+
? $t('workflows.publish.firstTitle')
|
|
176
|
+
: $t('workflows.publish.changesTitle')}
|
|
177
|
+
message={editor.status === 'draft'
|
|
178
|
+
? $t('workflows.publish.firstMessage')
|
|
179
|
+
: $t('workflows.publish.changesMessage')}
|
|
180
|
+
confirmLabel={editor.status === 'draft'
|
|
181
|
+
? $t('workflows.top.publish')
|
|
182
|
+
: $t('workflows.top.publishChanges')}
|
|
183
|
+
busy={editor.busy === 'publishing'}
|
|
184
|
+
onconfirm={() => void confirmPublish()}
|
|
185
|
+
oncancel={() => (isAskingToPublish = false)}
|
|
186
|
+
/>
|
|
187
|
+
{/if}
|
|
188
|
+
|
|
189
|
+
{#if isAskingToLeave}
|
|
190
|
+
<ConfirmDialog
|
|
191
|
+
title={$t('workflows.leave.title')}
|
|
192
|
+
message={$t('workflows.leave.message')}
|
|
193
|
+
confirmLabel={$t('workflows.leave.confirm')}
|
|
194
|
+
tone="danger"
|
|
195
|
+
onconfirm={onback}
|
|
196
|
+
oncancel={() => (isAskingToLeave = false)}
|
|
197
|
+
/>
|
|
198
|
+
{/if}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WorkflowsError } from '../../types/index.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
workflowId: string;
|
|
4
|
+
/** The person is done with this workflow: back to the list. */
|
|
5
|
+
onback: () => void;
|
|
6
|
+
/** Another workflow should be opened (a duplicate was made). */
|
|
7
|
+
onopenworkflow: (workflowId: string) => void;
|
|
8
|
+
/** A failure the page should hear about. */
|
|
9
|
+
onerror: (error: WorkflowsError) => void;
|
|
10
|
+
/** Shows the embed code of the workflow; the page that hosts the screen decides what that looks like. */
|
|
11
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
12
|
+
/** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
|
|
13
|
+
presence?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const WorkflowEditor: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type WorkflowEditor = ReturnType<typeof WorkflowEditor>;
|
|
17
|
+
export default WorkflowEditor;
|
package/dist/components/index.js
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
"New workflow": a name, and the composition visitors see first (optional: it can be chosen in the editor). Making it opens
|
|
3
|
+
the editor straight away, with the composition already on the canvas as the start.
|
|
4
|
+
|
|
5
|
+
The name is the only thing required, so the dialog never asks for what it could do without.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { MAX_WORKFLOW_NAME_LENGTH } from '../../api/types.js';
|
|
9
|
+
import type { CompositionOption, WorkflowDetail } from '../../api/types.js';
|
|
10
|
+
import { useListState } from '../../editor/listState.svelte.js';
|
|
11
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
12
|
+
import CompositionPicker from '../panel/CompositionPicker.svelte';
|
|
13
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
14
|
+
import Modal from '../ui/Modal.svelte';
|
|
15
|
+
import Notice from '../ui/Notice.svelte';
|
|
16
|
+
import TextField from '../ui/TextField.svelte';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
oncancel: () => void;
|
|
20
|
+
/** The workflow was made; the screen opens it. */
|
|
21
|
+
oncreated: (created: WorkflowDetail) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let { oncancel, oncreated }: Props = $props();
|
|
25
|
+
|
|
26
|
+
const list = useListState();
|
|
27
|
+
const { t } = useWorkflowsLanguage();
|
|
28
|
+
|
|
29
|
+
let name = $state('');
|
|
30
|
+
let chosen = $state.raw<CompositionOption | null>(null);
|
|
31
|
+
let isCreating = $state(false);
|
|
32
|
+
|
|
33
|
+
const canCreate = $derived(name.trim() !== '' && !isCreating);
|
|
34
|
+
|
|
35
|
+
async function create(): Promise<void> {
|
|
36
|
+
if (!canCreate) return;
|
|
37
|
+
isCreating = true;
|
|
38
|
+
try {
|
|
39
|
+
const created = await list.create({ name: name.trim(), composition: chosen });
|
|
40
|
+
if (created) oncreated(created);
|
|
41
|
+
} finally {
|
|
42
|
+
isCreating = false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Enter in the name box makes the workflow, as the button does. */
|
|
47
|
+
function handleKeydown(event: KeyboardEvent): void {
|
|
48
|
+
if (
|
|
49
|
+
event.key === 'Enter' &&
|
|
50
|
+
event.target instanceof HTMLInputElement &&
|
|
51
|
+
event.target.type === 'text'
|
|
52
|
+
) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
void create();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<Modal title={$t('workflows.create.title')} size="medium" busy={isCreating} onclose={oncancel}>
|
|
60
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
61
|
+
<div class="flex flex-col gap-4" onkeydown={handleKeydown}>
|
|
62
|
+
<TextField
|
|
63
|
+
label={$t('workflows.create.nameLabel')}
|
|
64
|
+
placeholder={$t('workflows.create.namePlaceholder')}
|
|
65
|
+
maxlength={MAX_WORKFLOW_NAME_LENGTH}
|
|
66
|
+
autofocus
|
|
67
|
+
bind:value={name}
|
|
68
|
+
/>
|
|
69
|
+
<div class="flex flex-col gap-2">
|
|
70
|
+
<p class="text-xs font-medium">{$t('workflows.create.compositionLabel')}</p>
|
|
71
|
+
<p class="text-xs text-ink-muted">{$t('workflows.create.compositionHelp')}</p>
|
|
72
|
+
<CompositionPicker
|
|
73
|
+
selectedId={chosen?.id ?? null}
|
|
74
|
+
onpick={(option) => (chosen = chosen?.id === option.id ? null : option)}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
{#if list.createFailure}
|
|
78
|
+
<Notice tone="problem">{$t(list.createFailure)}</Notice>
|
|
79
|
+
{/if}
|
|
80
|
+
</div>
|
|
81
|
+
{#snippet footer()}
|
|
82
|
+
<ActionButton disabled={isCreating} onclick={oncancel}
|
|
83
|
+
>{$t('workflows.common.cancel')}</ActionButton
|
|
84
|
+
>
|
|
85
|
+
<ActionButton variant="primary" disabled={!canCreate} onclick={() => void create()}>
|
|
86
|
+
{isCreating ? $t('workflows.create.creating') : $t('workflows.create.create')}
|
|
87
|
+
</ActionButton>
|
|
88
|
+
{/snippet}
|
|
89
|
+
</Modal>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorkflowDetail } from '../../api/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
oncancel: () => void;
|
|
4
|
+
/** The workflow was made; the screen opens it. */
|
|
5
|
+
oncreated: (created: WorkflowDetail) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const CreateWorkflowDialog: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type CreateWorkflowDialog = ReturnType<typeof CreateWorkflowDialog>;
|
|
9
|
+
export default CreateWorkflowDialog;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The list of a workspace's workflows: search, a filter by state, an order (name, when it was made, when it was last
|
|
3
|
+
published, how many visitors started it) and a row for each, with "New workflow" at the top.
|
|
4
|
+
|
|
5
|
+
The list can be longer than a page, so every change of the search, the filter or the order asks the API again; "Show more"
|
|
6
|
+
adds the next page. A page of nothing says why: nothing made yet (and offers to make one), or nothing matches what was asked.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { onDestroy, onMount } from 'svelte';
|
|
10
|
+
import type { WorkflowDetail } from '../../api/types.js';
|
|
11
|
+
import { WORKFLOW_STATUSES } from '../../api/types.js';
|
|
12
|
+
import type { WorkflowSortField } from '../../api/types.js';
|
|
13
|
+
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
14
|
+
import { WorkflowListState, provideListState } from '../../editor/listState.svelte.js';
|
|
15
|
+
import type { ListStatusFilter } from '../../editor/listState.svelte.js';
|
|
16
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
17
|
+
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
18
|
+
import type { WorkflowsError } from '../../types/index.js';
|
|
19
|
+
import WorkflowsEmptyState from '../WorkflowsEmptyState.svelte';
|
|
20
|
+
import WorkflowsHeader from '../WorkflowsHeader.svelte';
|
|
21
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
22
|
+
import Icon from '../ui/Icon.svelte';
|
|
23
|
+
import Notice from '../ui/Notice.svelte';
|
|
24
|
+
import SelectField from '../ui/SelectField.svelte';
|
|
25
|
+
import TextField from '../ui/TextField.svelte';
|
|
26
|
+
import type { SelectChoice } from '../ui/types.js';
|
|
27
|
+
import CreateWorkflowDialog from './CreateWorkflowDialog.svelte';
|
|
28
|
+
import WorkflowRow from './WorkflowRow.svelte';
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
/** A workflow was chosen (or just made): open it. */
|
|
32
|
+
onopen: (workflowId: string) => void;
|
|
33
|
+
/** A failure the page should hear about. */
|
|
34
|
+
onerror: (error: WorkflowsError) => void;
|
|
35
|
+
/** Shows the embed code of a workflow; the page that hosts the screen decides what that looks like. */
|
|
36
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let { onopen, onerror, onshowembedcode }: Props = $props();
|
|
40
|
+
|
|
41
|
+
const api = useWorkflowsApi();
|
|
42
|
+
const { t } = useWorkflowsLanguage();
|
|
43
|
+
|
|
44
|
+
const list = new WorkflowListState({ api, reportError: (error) => onerror(error) });
|
|
45
|
+
provideListState(list);
|
|
46
|
+
|
|
47
|
+
let isCreating = $state(false);
|
|
48
|
+
|
|
49
|
+
const STATUS_FILTER_KEYS = {
|
|
50
|
+
'': 'workflows.list.filterActive',
|
|
51
|
+
all: 'workflows.list.filterAll',
|
|
52
|
+
draft: 'workflows.status.draft',
|
|
53
|
+
live: 'workflows.status.live',
|
|
54
|
+
paused: 'workflows.status.paused',
|
|
55
|
+
archived: 'workflows.status.archived'
|
|
56
|
+
} as const satisfies Record<ListStatusFilter, WorkflowsMessageKey>;
|
|
57
|
+
|
|
58
|
+
const SORT_KEYS = {
|
|
59
|
+
createdAt: 'workflows.list.sortCreated',
|
|
60
|
+
lastPublishedAt: 'workflows.list.sortPublished',
|
|
61
|
+
runsCount: 'workflows.list.sortRuns',
|
|
62
|
+
name: 'workflows.list.sortName'
|
|
63
|
+
} as const satisfies Record<WorkflowSortField, WorkflowsMessageKey>;
|
|
64
|
+
|
|
65
|
+
const statusChoices = $derived<SelectChoice[]>(
|
|
66
|
+
(['', 'all', ...WORKFLOW_STATUSES] as ListStatusFilter[]).map((filter) => ({
|
|
67
|
+
value: filter,
|
|
68
|
+
label: $t(STATUS_FILTER_KEYS[filter])
|
|
69
|
+
}))
|
|
70
|
+
);
|
|
71
|
+
const sortChoices = $derived<SelectChoice[]>(
|
|
72
|
+
(Object.keys(SORT_KEYS) as WorkflowSortField[]).map((field) => ({
|
|
73
|
+
value: field,
|
|
74
|
+
label: $t(SORT_KEYS[field])
|
|
75
|
+
}))
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let searchDraft = $state('');
|
|
79
|
+
|
|
80
|
+
function handleCreated(created: WorkflowDetail): void {
|
|
81
|
+
isCreating = false;
|
|
82
|
+
onopen(created.id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onMount(() => {
|
|
86
|
+
void list.load();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
onDestroy(() => list.dispose());
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<div class="@container flex flex-1 flex-col gap-5">
|
|
93
|
+
<div class="flex flex-wrap items-start justify-between gap-3">
|
|
94
|
+
<WorkflowsHeader />
|
|
95
|
+
<ActionButton variant="primary" onclick={() => (isCreating = true)}>
|
|
96
|
+
<Icon name="plus" />
|
|
97
|
+
{$t('workflows.list.newWorkflow')}
|
|
98
|
+
</ActionButton>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
{#if list.notice}
|
|
102
|
+
{@const notice = list.notice}
|
|
103
|
+
<Notice tone={notice.tone}>
|
|
104
|
+
{$t(notice.messageKey, notice.values)}
|
|
105
|
+
{#snippet action()}
|
|
106
|
+
<ActionButton variant="ghost" size="small" onclick={() => list.dismissNotice()}
|
|
107
|
+
>{$t('workflows.common.dismiss')}</ActionButton
|
|
108
|
+
>
|
|
109
|
+
{/snippet}
|
|
110
|
+
</Notice>
|
|
111
|
+
{/if}
|
|
112
|
+
|
|
113
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
114
|
+
<TextField
|
|
115
|
+
class="min-w-56 flex-1"
|
|
116
|
+
type="search"
|
|
117
|
+
label={$t('workflows.list.searchLabel')}
|
|
118
|
+
placeholder={$t('workflows.list.searchPlaceholder')}
|
|
119
|
+
hideLabel
|
|
120
|
+
bind:value={searchDraft}
|
|
121
|
+
oninput={() => list.setSearch(searchDraft)}
|
|
122
|
+
/>
|
|
123
|
+
<SelectField
|
|
124
|
+
class="w-44"
|
|
125
|
+
label={$t('workflows.list.filterLabel')}
|
|
126
|
+
value={list.statusFilter}
|
|
127
|
+
choices={statusChoices}
|
|
128
|
+
onchange={(filter) => list.setStatusFilter(filter as ListStatusFilter)}
|
|
129
|
+
/>
|
|
130
|
+
<SelectField
|
|
131
|
+
class="w-44"
|
|
132
|
+
label={$t('workflows.list.sortLabel')}
|
|
133
|
+
value={list.sortField}
|
|
134
|
+
choices={sortChoices}
|
|
135
|
+
onchange={(field) => list.setSort(field as WorkflowSortField)}
|
|
136
|
+
/>
|
|
137
|
+
<ActionButton
|
|
138
|
+
iconOnly
|
|
139
|
+
ariaLabel={list.sortDirection === 'asc'
|
|
140
|
+
? $t('workflows.list.sortAscending')
|
|
141
|
+
: $t('workflows.list.sortDescending')}
|
|
142
|
+
title={list.sortDirection === 'asc'
|
|
143
|
+
? $t('workflows.list.sortAscending')
|
|
144
|
+
: $t('workflows.list.sortDescending')}
|
|
145
|
+
onclick={() => list.toggleSortDirection()}
|
|
146
|
+
>
|
|
147
|
+
<Icon name={list.sortDirection === 'asc' ? 'up' : 'down'} />
|
|
148
|
+
</ActionButton>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
{#if list.loadState === 'loading'}
|
|
152
|
+
<p class="py-10 text-center text-sm text-ink-muted" role="status">
|
|
153
|
+
{$t('workflows.common.loading')}
|
|
154
|
+
</p>
|
|
155
|
+
{:else if list.loadState === 'failed'}
|
|
156
|
+
<Notice tone="problem">
|
|
157
|
+
{$t(list.failure ?? 'workflows.error.generic')}
|
|
158
|
+
{#snippet action()}
|
|
159
|
+
<ActionButton size="small" onclick={() => void list.load()}
|
|
160
|
+
>{$t('workflows.error.retry')}</ActionButton
|
|
161
|
+
>
|
|
162
|
+
{/snippet}
|
|
163
|
+
</Notice>
|
|
164
|
+
{:else if list.items.length === 0}
|
|
165
|
+
{#if list.isNarrowed}
|
|
166
|
+
<p class="py-10 text-center text-sm text-ink-muted">{$t('workflows.list.noMatches')}</p>
|
|
167
|
+
{:else}
|
|
168
|
+
<WorkflowsEmptyState oncreate={() => (isCreating = true)} />
|
|
169
|
+
{/if}
|
|
170
|
+
{:else}
|
|
171
|
+
<div class="flex flex-col gap-2">
|
|
172
|
+
<!-- The column headings are only drawn where the rows have columns. -->
|
|
173
|
+
<div
|
|
174
|
+
class="hidden grid-cols-[minmax(0,2fr)_7rem_6rem_8rem_8rem_auto] gap-x-4 px-4 text-xs text-ink-muted @2xl:grid"
|
|
175
|
+
aria-hidden="true"
|
|
176
|
+
>
|
|
177
|
+
<span>{$t('workflows.list.columnName')}</span>
|
|
178
|
+
<span>{$t('workflows.list.columnStatus')}</span>
|
|
179
|
+
<span>{$t('workflows.list.columnRuns')}</span>
|
|
180
|
+
<span>{$t('workflows.list.columnPublished')}</span>
|
|
181
|
+
<span>{$t('workflows.list.columnCreated')}</span>
|
|
182
|
+
<span class="w-8"></span>
|
|
183
|
+
</div>
|
|
184
|
+
<ul class="flex flex-col gap-2" aria-label={$t('workflows.list.label')}>
|
|
185
|
+
{#each list.items as item (item.id)}
|
|
186
|
+
<WorkflowRow {item} {onopen} {onshowembedcode} />
|
|
187
|
+
{/each}
|
|
188
|
+
</ul>
|
|
189
|
+
{#if list.hasMore}
|
|
190
|
+
<ActionButton
|
|
191
|
+
class="self-center"
|
|
192
|
+
disabled={list.loadingMore}
|
|
193
|
+
onclick={() => void list.loadMore()}
|
|
194
|
+
>
|
|
195
|
+
{list.loadingMore ? $t('workflows.common.loading') : $t('workflows.list.showMore')}
|
|
196
|
+
</ActionButton>
|
|
197
|
+
{/if}
|
|
198
|
+
</div>
|
|
199
|
+
{/if}
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
{#if isCreating}
|
|
203
|
+
<CreateWorkflowDialog oncancel={() => (isCreating = false)} oncreated={handleCreated} />
|
|
204
|
+
{/if}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WorkflowsError } from '../../types/index.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** A workflow was chosen (or just made): open it. */
|
|
4
|
+
onopen: (workflowId: string) => void;
|
|
5
|
+
/** A failure the page should hear about. */
|
|
6
|
+
onerror: (error: WorkflowsError) => void;
|
|
7
|
+
/** Shows the embed code of a workflow; the page that hosts the screen decides what that looks like. */
|
|
8
|
+
onshowembedcode?: (workflowId: string) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const WorkflowList: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type WorkflowList = ReturnType<typeof WorkflowList>;
|
|
12
|
+
export default WorkflowList;
|