@widgetic/workflows 0.2.9 → 0.2.11
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 +11 -13
- package/dist/components/WorkflowsEmptyState.svelte +15 -3
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +2 -0
- package/dist/components/canvas/CompositionNodeView.svelte +5 -5
- package/dist/components/canvas/ConditionNodeView.svelte +4 -4
- package/dist/components/canvas/HandlePoint.svelte +1 -1
- package/dist/components/canvas/TriggerNodeView.svelte +5 -4
- package/dist/components/editor/EditorTopBar.svelte +6 -20
- package/dist/components/editor/RunsFlow.svelte +73 -23
- package/dist/components/editor/WorkflowNameControl.svelte +126 -0
- package/dist/components/editor/WorkflowNameControl.svelte.d.ts +13 -0
- package/dist/components/list/WorkflowList.svelte +87 -59
- package/dist/components/panel/CompositionSelect.svelte +5 -1
- package/dist/components/ui/icons.d.ts +2 -0
- package/dist/components/ui/icons.js +3 -1
- package/dist/editor/createBlankWorkflow.d.ts +30 -0
- package/dist/editor/createBlankWorkflow.js +37 -0
- package/dist/editor/editorState.svelte.d.ts +2 -2
- package/dist/editor/listState.svelte.d.ts +24 -36
- package/dist/editor/listState.svelte.js +50 -45
- package/dist/editor/presetChoice.d.ts +4 -4
- package/dist/editor/presetChoice.js +4 -4
- package/dist/editor/runsFlowBandLabel.d.ts +16 -0
- package/dist/editor/runsFlowBandLabel.js +34 -0
- package/dist/editor/runsFlowLayout.d.ts +24 -9
- package/dist/editor/runsFlowLayout.js +73 -28
- package/dist/editor/workflowNameCommit.d.ts +12 -0
- package/dist/editor/workflowNameCommit.js +11 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +8 -26
- package/dist/i18n/messages.js +9 -29
- package/package.json +1 -1
- package/dist/components/list/CreateWorkflowDialog.svelte +0 -262
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +0 -9
package/README.md
CHANGED
|
@@ -14,18 +14,16 @@ Workflows are for **Teams and partner accounts** only. On Widgetic the page is
|
|
|
14
14
|
## What it does
|
|
15
15
|
|
|
16
16
|
- **The list.** The workspace's workflows with where each one stands (draft, live, paused, archived), how many visitors
|
|
17
|
-
went through, and when it was last published. Search by name,
|
|
18
|
-
created, last published or visitors, and make a workflow (`New workflow`), duplicate it or delete it. The
|
|
19
|
-
when one is opened (`onOpenWorkflow`) so the address can follow.
|
|
20
|
-
- **
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
so it is given longer than another request, and it is sent with an `Idempotency-Key`: asking again after a timeout does
|
|
28
|
-
not copy twice.
|
|
17
|
+
went through, and when it was last published. Search by name, filter by state (All, Draft, Live, Paused, Archived), order
|
|
18
|
+
by name, date created, last published or visitors, and make a workflow (`New workflow`), duplicate it or delete it. The
|
|
19
|
+
page is told when one is opened (`onOpenWorkflow`) so the address can follow.
|
|
20
|
+
- **New workflow.** `New workflow` makes a blank draft named `Untitled` at once and opens the editor: there is no dialog,
|
|
21
|
+
no name to type and no choice to make (the name is changed in the editor's header, by clicking it).
|
|
22
|
+
- **Start from a preset (model and API only).** A preset is a published workflow that Widgetic (or a partner) offers as a
|
|
23
|
+
place to start; starting from one copies every widget it chains and wires a draft like the preset's live version. The
|
|
24
|
+
list no longer shows a preset choice, but its model (`loadPresets()`, `startFromPreset()`) and the API client
|
|
25
|
+
(`listPresets()`, `startFromPreset()`) still do this, for a host that wants to offer templates itself. The copy is sent
|
|
26
|
+
with an `Idempotency-Key`: asking again after a timeout does not copy twice.
|
|
29
27
|
- **The editor.** A canvas of blocks joined by lines. A **Composition** block shows a composition; a **Trigger** block
|
|
30
28
|
waits for something a visitor does (a value they add to a widget, an action in the widget, an event on the page, or a
|
|
31
29
|
time); a **Condition** block sends the visitor on by the first rule that matches. Blocks go forward only, a workflow
|
|
@@ -222,7 +220,7 @@ The catalog's messages are grouped by the part of the screen that says them:
|
|
|
222
220
|
| Group | What it says |
|
|
223
221
|
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
224
222
|
| `workflows.header.*`, `empty.*` | The title and the empty state. |
|
|
225
|
-
| `workflows.list.*`, `create.*`, `status.*` | The list: search,
|
|
223
|
+
| `workflows.list.*`, `create.*`, `status.*` | The list: search, status tabs, order, rows, blank New workflow, states. |
|
|
226
224
|
| `workflows.top.*`, `save.*`, `tabs.*`, `banner.*`, `leave.*` | The bar above the canvas, the save state, the tabs and the banners. |
|
|
227
225
|
| `workflows.canvas.*`, `toolbar.*`, `addBlock.*`, `block.*` | The canvas, its tools, the Add block menu and what a block is called. |
|
|
228
226
|
| `workflows.panel.*`, `composition.*`, `trigger.*`, `schedule.*`, `event.*`, `reason.*` | The side panel for a composition and for each kind of trigger, and why a trigger is not offered. |
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
interface Props {
|
|
12
12
|
/** The person pressed the button that makes the first workflow. */
|
|
13
13
|
oncreate: () => void;
|
|
14
|
+
/** A workflow is already being made (the button is disabled and shows a spinner). */
|
|
15
|
+
busy?: boolean;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
let { oncreate }: Props = $props();
|
|
18
|
+
let { oncreate, busy = false }: Props = $props();
|
|
17
19
|
|
|
18
20
|
const { t } = useWorkflowsLanguage();
|
|
19
21
|
</script>
|
|
@@ -27,8 +29,18 @@
|
|
|
27
29
|
<h2 class="text-heading-section text-foreground">{$t('workflows.empty.title')}</h2>
|
|
28
30
|
<p class="text-body text-muted-foreground">{$t('workflows.empty.hint')}</p>
|
|
29
31
|
</div>
|
|
30
|
-
<Button
|
|
31
|
-
|
|
32
|
+
<Button
|
|
33
|
+
class="mt-3"
|
|
34
|
+
variant={dsButtonVariant('primary')}
|
|
35
|
+
disabled={busy}
|
|
36
|
+
aria-busy={busy}
|
|
37
|
+
onclick={oncreate}
|
|
38
|
+
>
|
|
39
|
+
{#if busy}
|
|
40
|
+
<Icon name="loader" class="size-4 motion-safe:animate-spin" />
|
|
41
|
+
{:else}
|
|
42
|
+
<Icon name="plus" class="size-4" />
|
|
43
|
+
{/if}
|
|
32
44
|
{$t('workflows.list.newWorkflow')}
|
|
33
45
|
</Button>
|
|
34
46
|
</div>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
interface Props {
|
|
2
2
|
/** The person pressed the button that makes the first workflow. */
|
|
3
3
|
oncreate: () => void;
|
|
4
|
+
/** A workflow is already being made (the button is disabled and shows a spinner). */
|
|
5
|
+
busy?: boolean;
|
|
4
6
|
}
|
|
5
7
|
declare const WorkflowsEmptyState: import("svelte").Component<Props, {}, "">;
|
|
6
8
|
type WorkflowsEmptyState = ReturnType<typeof WorkflowsEmptyState>;
|
|
@@ -62,15 +62,15 @@
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
const rootBorder = $derived.by(() => {
|
|
65
|
-
if (status === 'error') return 'border-
|
|
66
|
-
if (selected) return 'border-
|
|
67
|
-
if (isEmpty) return 'border
|
|
68
|
-
return 'border
|
|
65
|
+
if (status === 'error') return 'border-destructive';
|
|
66
|
+
if (selected) return 'border-primary';
|
|
67
|
+
if (isEmpty) return 'border-dashed border-input';
|
|
68
|
+
return 'border-border';
|
|
69
69
|
});
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
72
|
<div
|
|
73
|
-
class="relative flex w-60 flex-col overflow-hidden rounded-xl bg-background text-start text-foreground {rootBorder}"
|
|
73
|
+
class="relative flex w-60 flex-col overflow-hidden rounded-xl border-2 bg-background text-start text-foreground {rootBorder}"
|
|
74
74
|
dir={$textDirection}
|
|
75
75
|
data-workflow-block="composition"
|
|
76
76
|
>
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const rootBorder = $derived.by(() => {
|
|
45
|
-
if (status === 'error') return 'border-
|
|
46
|
-
if (selected) return 'border-
|
|
47
|
-
return 'border
|
|
45
|
+
if (status === 'error') return 'border-destructive';
|
|
46
|
+
if (selected) return 'border-primary';
|
|
47
|
+
return 'border-border';
|
|
48
48
|
});
|
|
49
49
|
</script>
|
|
50
50
|
|
|
51
51
|
<div
|
|
52
|
-
class="relative flex w-66 flex-col overflow-hidden rounded-xl bg-background text-start text-foreground {rootBorder}"
|
|
52
|
+
class="relative flex w-66 flex-col overflow-hidden rounded-xl border-2 bg-background text-start text-foreground {rootBorder}"
|
|
53
53
|
dir={$textDirection}
|
|
54
54
|
data-workflow-block="condition"
|
|
55
55
|
>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
{port}
|
|
32
32
|
accept={accept ? [...accept] : undefined}
|
|
33
33
|
{position}
|
|
34
|
-
class="group flex size-2.5 items-center justify-center border-0 bg-transparent p-0 [&_.kaykay-handle-label]:hidden"
|
|
34
|
+
class="group z-10 flex size-2.5 items-center justify-center border-0 bg-transparent p-0 [&_.kaykay-handle-label]:hidden"
|
|
35
35
|
>
|
|
36
36
|
<span
|
|
37
37
|
class="pointer-events-none block size-2.5 rounded-full border border-muted-foreground bg-background transition-colors duration-fast group-[.can-connect]:border-primary group-[.can-connect]:bg-primary group-[.connecting]:border-primary group-[.connecting]:bg-primary group-[.incompatible]:opacity-50"
|
|
@@ -51,15 +51,16 @@
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
/** Two pixels reserved always so selection does not shift the block; handles sit above this ring in z-order. */
|
|
54
55
|
const rootBorder = $derived.by(() => {
|
|
55
|
-
if (status === 'error') return 'border-
|
|
56
|
-
if (selected) return 'border-
|
|
57
|
-
return 'border
|
|
56
|
+
if (status === 'error') return 'border-destructive';
|
|
57
|
+
if (selected) return 'border-primary';
|
|
58
|
+
return 'border-border';
|
|
58
59
|
});
|
|
59
60
|
</script>
|
|
60
61
|
|
|
61
62
|
<div
|
|
62
|
-
class="relative flex w-58 flex-col gap-2 rounded-xl bg-background px-4 py-3 text-start text-foreground {rootBorder}"
|
|
63
|
+
class="relative flex w-58 flex-col gap-2 rounded-xl border-2 bg-background px-4 py-3 text-start text-foreground {rootBorder}"
|
|
63
64
|
dir={$textDirection}
|
|
64
65
|
data-workflow-block="trigger"
|
|
65
66
|
>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import Menu from '../ui/Menu.svelte';
|
|
19
19
|
import type { MenuGroup, MenuItem } from '../ui/types.js';
|
|
20
20
|
import StatusBadge from '../ui/StatusBadge.svelte';
|
|
21
|
-
import
|
|
21
|
+
import WorkflowNameControl from './WorkflowNameControl.svelte';
|
|
22
22
|
|
|
23
23
|
interface Props {
|
|
24
24
|
onback: () => void;
|
|
@@ -32,9 +32,6 @@
|
|
|
32
32
|
const editor = useEditorState();
|
|
33
33
|
const { t } = useWorkflowsLanguage();
|
|
34
34
|
|
|
35
|
-
/** What is in the name box while it is being typed; it follows the workflow's name again whenever that changes. */
|
|
36
|
-
let nameDraft = $derived(editor.name);
|
|
37
|
-
|
|
38
35
|
const SAVE_STATE_KEYS = {
|
|
39
36
|
saved: 'workflows.save.saved',
|
|
40
37
|
pending: 'workflows.save.pending',
|
|
@@ -51,15 +48,6 @@
|
|
|
51
48
|
: 'workflows.top.publishChanges'
|
|
52
49
|
);
|
|
53
50
|
|
|
54
|
-
function commitName(): void {
|
|
55
|
-
if (nameDraft.trim() === '') {
|
|
56
|
-
// An empty name is not a name: put the old one back.
|
|
57
|
-
nameDraft = editor.name;
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
editor.setName(nameDraft);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
51
|
function toggleTestRun(): void {
|
|
64
52
|
if (editor.panel === 'test') editor.closeTestRun();
|
|
65
53
|
else editor.openTestRun();
|
|
@@ -138,14 +126,12 @@
|
|
|
138
126
|
<Icon name="back" class="size-4 rtl:rotate-180" />
|
|
139
127
|
</IconButton>
|
|
140
128
|
<div class="min-w-0 max-w-full flex-1 @3xl:w-60 @3xl:flex-none">
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
129
|
+
<WorkflowNameControl
|
|
130
|
+
name={editor.name}
|
|
131
|
+
label={$t('workflows.top.renameLabel')}
|
|
132
|
+
readonly={editor.isReadOnly}
|
|
145
133
|
maxlength={MAX_WORKFLOW_NAME_LENGTH}
|
|
146
|
-
|
|
147
|
-
bind:value={nameDraft}
|
|
148
|
-
onchange={commitName}
|
|
134
|
+
oncommit={(name) => editor.setName(name)}
|
|
149
135
|
/>
|
|
150
136
|
</div>
|
|
151
137
|
<div class="flex min-w-0 shrink-0 flex-col gap-1 @3xl:hidden" data-workflows-editor-status>
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import type { WorkflowGraph } from '@widgetic/workflows-engine';
|
|
19
19
|
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
20
20
|
import { formatCount } from '../../editor/formatCount.js';
|
|
21
|
+
import { formatBandLabelPercent } from '../../editor/runsFlowBandLabel.js';
|
|
21
22
|
import { buildRunsFlow, listNumberLines } from '../../editor/runsFlow.js';
|
|
22
23
|
import type { RunsFlow, RunsFlowLineKind, RunsFlowStep } from '../../editor/runsFlow.js';
|
|
23
24
|
import { RUNS_FLOW_METRICS, layoutRunsFlow } from '../../editor/runsFlowLayout.js';
|
|
@@ -44,6 +45,9 @@
|
|
|
44
45
|
const WIDTH_BEFORE_MEASURING = 720;
|
|
45
46
|
/** The width of the place a band can be pointed at, however thin the band is. */
|
|
46
47
|
const LEAST_POINTING_WIDTH = 14;
|
|
48
|
+
/** The room of the "count · percent" words on a band: wide enough for "12,345 · 100%" in the chart's caption size. */
|
|
49
|
+
const BAND_LABEL_WIDTH = 112;
|
|
50
|
+
const BAND_LABEL_HEIGHT = 16;
|
|
47
51
|
/** The distance between the pointer and the tooltip of a band, and the room the tooltip needs (its widest and a tall one). */
|
|
48
52
|
const TOOLTIP_GAP = 14;
|
|
49
53
|
const TOOLTIP_WIDTH = 240;
|
|
@@ -138,26 +142,30 @@
|
|
|
138
142
|
}));
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
/**
|
|
142
|
-
const isReasonLine = (kind: RunsFlowLineKind): boolean =>
|
|
143
|
-
kind !== 'entered' && kind !== 'stayed' && kind !== 'failed';
|
|
144
|
-
|
|
145
|
-
/** One composition in one line, for its tooltip. */
|
|
145
|
+
/** One composition in one line, for its tooltip (the reasons it could not be shown are here, not on the chart). */
|
|
146
146
|
function describeStep(step: PlacedStep): string {
|
|
147
147
|
return [words.nameStep(step.nodeId), ...readNumbersOf(step).map((line) => line.text)].join(
|
|
148
148
|
' · '
|
|
149
149
|
);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
/** One band in one line
|
|
152
|
+
/** One band in one short line for its tooltip: how many went and how a visitor gets along it. */
|
|
153
153
|
function describeBand(band: PlacedLink): string {
|
|
154
154
|
return [
|
|
155
|
-
words.namePath(band),
|
|
156
155
|
$t('workflows.list.runsCount', { count: band.value }),
|
|
157
156
|
...words.describeRoute(band)
|
|
158
157
|
].join(' · ');
|
|
159
158
|
}
|
|
160
159
|
|
|
160
|
+
const visitorsStarted = $derived(
|
|
161
|
+
counts.started ?? flow.steps.find((step) => step.isStart)?.entered ?? 0
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
function bandOnChartLabel(band: PlacedLink): string {
|
|
165
|
+
const percent = formatBandLabelPercent(band.value, visitorsStarted, $locale);
|
|
166
|
+
return `${formatCount(band.value, $locale)} · ${percent}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
161
169
|
/**
|
|
162
170
|
* Tells a mouse (or a pen) what the band under it is: next to the pointer, kept inside the frame (at the right edge it moves
|
|
163
171
|
* to the pointer's left, at the bottom above it). A finger gets no tooltip: it has no pointer to rest on a band, and the list
|
|
@@ -265,6 +273,23 @@
|
|
|
265
273
|
</g>
|
|
266
274
|
{/each}
|
|
267
275
|
|
|
276
|
+
<!-- How many went along a band, and what share of the visitors who started: drawn over every band (a band is see-through) and never in the way of a pointer. -->
|
|
277
|
+
{#each placed.links as band (band.id)}
|
|
278
|
+
{#if band.showBandLabel && band.labelCenter}
|
|
279
|
+
<foreignObject
|
|
280
|
+
x={band.labelCenter.x - BAND_LABEL_WIDTH / 2}
|
|
281
|
+
y={band.labelCenter.y - BAND_LABEL_HEIGHT / 2}
|
|
282
|
+
width={BAND_LABEL_WIDTH}
|
|
283
|
+
height={BAND_LABEL_HEIGHT}
|
|
284
|
+
class="pointer-events-none overflow-visible"
|
|
285
|
+
>
|
|
286
|
+
<p class="truncate text-center text-caption text-muted-foreground">
|
|
287
|
+
{bandOnChartLabel(band)}
|
|
288
|
+
</p>
|
|
289
|
+
</foreignObject>
|
|
290
|
+
{/if}
|
|
291
|
+
{/each}
|
|
292
|
+
|
|
268
293
|
{#each placed.steps as step (step.nodeId)}
|
|
269
294
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
270
295
|
<g
|
|
@@ -313,34 +338,59 @@
|
|
|
313
338
|
class="fill-destructive"
|
|
314
339
|
/>
|
|
315
340
|
{/if}
|
|
316
|
-
<!--
|
|
341
|
+
<!-- On-chart labels only: names and counts; stayed/failed sit beside the bar; details stay in <title> and sr-only. -->
|
|
317
342
|
<foreignObject
|
|
318
|
-
x={step.
|
|
343
|
+
x={step.labelX}
|
|
319
344
|
y={step.labelY}
|
|
320
345
|
width={step.labelWidth}
|
|
321
346
|
height={step.labelHeight}
|
|
322
347
|
class="overflow-visible"
|
|
323
348
|
>
|
|
324
349
|
<div class="w-fit max-w-full" dir={$textDirection}>
|
|
325
|
-
|
|
326
|
-
class="
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
{words.nameStep(step.nodeId)}
|
|
331
|
-
</p>
|
|
332
|
-
{#each readNumbersOf(step) as line (line.kind)}
|
|
350
|
+
{#if step.labelPlacement === 'entryCount'}
|
|
351
|
+
<p class="text-body-medium font-medium text-foreground">
|
|
352
|
+
{formatCount(step.entered, $locale)}
|
|
353
|
+
</p>
|
|
354
|
+
{:else}
|
|
333
355
|
<p
|
|
334
|
-
class="truncate text-caption
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
data-line={line.kind}
|
|
356
|
+
class="truncate text-caption font-medium text-foreground"
|
|
357
|
+
dir="auto"
|
|
358
|
+
title={words.nameStep(step.nodeId)}
|
|
338
359
|
>
|
|
339
|
-
{
|
|
360
|
+
{words.nameStep(step.nodeId)}
|
|
340
361
|
</p>
|
|
341
|
-
|
|
362
|
+
<p class="text-body-medium font-medium text-foreground">
|
|
363
|
+
{formatCount(step.entered, $locale)}
|
|
364
|
+
</p>
|
|
365
|
+
{/if}
|
|
342
366
|
</div>
|
|
343
367
|
</foreignObject>
|
|
368
|
+
{#if step.stayedHeight > 0}
|
|
369
|
+
<foreignObject
|
|
370
|
+
x={step.x + RUNS_FLOW_METRICS.barWidth + RUNS_FLOW_METRICS.barSideLabelGap}
|
|
371
|
+
y={step.stayedY}
|
|
372
|
+
width={step.labelWidth}
|
|
373
|
+
height={RUNS_FLOW_METRICS.nameLineHeight}
|
|
374
|
+
class="overflow-visible"
|
|
375
|
+
>
|
|
376
|
+
<p class="text-caption text-muted-foreground">
|
|
377
|
+
{$t('workflows.runs.chartStayed', { count: formatCount(step.stayed, $locale) })}
|
|
378
|
+
</p>
|
|
379
|
+
</foreignObject>
|
|
380
|
+
{/if}
|
|
381
|
+
{#if step.failedHeight > 0}
|
|
382
|
+
<foreignObject
|
|
383
|
+
x={step.x + RUNS_FLOW_METRICS.barWidth + RUNS_FLOW_METRICS.barSideLabelGap}
|
|
384
|
+
y={step.failedY}
|
|
385
|
+
width={step.labelWidth}
|
|
386
|
+
height={RUNS_FLOW_METRICS.nameLineHeight}
|
|
387
|
+
class="overflow-visible"
|
|
388
|
+
>
|
|
389
|
+
<p class="text-caption text-destructive">
|
|
390
|
+
{$t('workflows.runs.chartFailed', { count: formatCount(step.failed, $locale) })}
|
|
391
|
+
</p>
|
|
392
|
+
</foreignObject>
|
|
393
|
+
{/if}
|
|
344
394
|
</g>
|
|
345
395
|
{/each}
|
|
346
396
|
</svg>
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The workflow name in the editor header: plain text until the person hovers and chooses to edit it, then a field that
|
|
3
|
+
commits on Enter or blur and cancels on Escape.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { tick } from 'svelte';
|
|
7
|
+
import { MAX_WORKFLOW_NAME_LENGTH } from '../../api/types.js';
|
|
8
|
+
import { decideWorkflowNameCommit } from '../../editor/workflowNameCommit.js';
|
|
9
|
+
import Icon from '../ui/Icon.svelte';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** The name as the editor knows it (saved on the server). */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Accessible label, e.g. "Rename workflow". */
|
|
15
|
+
label: string;
|
|
16
|
+
readonly?: boolean;
|
|
17
|
+
maxlength?: number;
|
|
18
|
+
class?: string;
|
|
19
|
+
oncommit: (name: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
name,
|
|
24
|
+
label,
|
|
25
|
+
readonly = false,
|
|
26
|
+
maxlength = MAX_WORKFLOW_NAME_LENGTH,
|
|
27
|
+
class: className = '',
|
|
28
|
+
oncommit
|
|
29
|
+
}: Props = $props();
|
|
30
|
+
|
|
31
|
+
let isEditing = $state(false);
|
|
32
|
+
let draft = $state('');
|
|
33
|
+
let inputElement = $state<HTMLInputElement | null>(null);
|
|
34
|
+
let nameButton = $state<HTMLButtonElement | null>(null);
|
|
35
|
+
|
|
36
|
+
const fieldId = $props.id();
|
|
37
|
+
|
|
38
|
+
function beginEditing(): void {
|
|
39
|
+
if (readonly || isEditing) return;
|
|
40
|
+
isEditing = true;
|
|
41
|
+
draft = name;
|
|
42
|
+
void tick().then(() => {
|
|
43
|
+
inputElement?.focus();
|
|
44
|
+
inputElement?.select();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Ends the edit. `restoreFocus` is true when the keyboard ended it (Enter, Escape): the person is still in the header,
|
|
50
|
+
* so the focus goes back to the name. It is false for a blur: the person has already moved on to something else, and
|
|
51
|
+
* taking the focus back would pull it away from what they chose.
|
|
52
|
+
*/
|
|
53
|
+
function finishEditing(commit: boolean, restoreFocus: boolean): void {
|
|
54
|
+
if (!isEditing) return;
|
|
55
|
+
if (commit) {
|
|
56
|
+
const decision = decideWorkflowNameCommit(name, draft);
|
|
57
|
+
if (decision.kind === 'revert') {
|
|
58
|
+
draft = decision.value;
|
|
59
|
+
} else {
|
|
60
|
+
oncommit(decision.value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
isEditing = false;
|
|
64
|
+
// The name button is not in the page until the update that follows `isEditing = false`, so it takes the focus after it.
|
|
65
|
+
if (restoreFocus) void tick().then(() => nameButton?.focus());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function handleViewKeydown(event: KeyboardEvent): void {
|
|
69
|
+
if (readonly) return;
|
|
70
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
beginEditing();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function handleInputKeydown(event: KeyboardEvent): void {
|
|
77
|
+
if (event.key === 'Enter') {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
finishEditing(true, true);
|
|
80
|
+
} else if (event.key === 'Escape') {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
draft = name;
|
|
83
|
+
finishEditing(false, true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<div class="min-w-0 {className}">
|
|
89
|
+
{#if isEditing}
|
|
90
|
+
<input
|
|
91
|
+
bind:this={inputElement}
|
|
92
|
+
id={fieldId}
|
|
93
|
+
type="text"
|
|
94
|
+
class="workflow-name-control-input w-full min-w-0 rounded-md border border-input bg-background px-2 py-1.5 text-body-medium text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
95
|
+
bind:value={draft}
|
|
96
|
+
{maxlength}
|
|
97
|
+
aria-label={label}
|
|
98
|
+
onkeydown={handleInputKeydown}
|
|
99
|
+
onblur={() => finishEditing(true, false)}
|
|
100
|
+
/>
|
|
101
|
+
{:else if readonly}
|
|
102
|
+
<p
|
|
103
|
+
id={fieldId}
|
|
104
|
+
class="workflow-name-control-view min-w-0 truncate px-2 py-1.5 text-body-medium text-foreground"
|
|
105
|
+
dir="auto"
|
|
106
|
+
>
|
|
107
|
+
{name}
|
|
108
|
+
</p>
|
|
109
|
+
{:else}
|
|
110
|
+
<button
|
|
111
|
+
bind:this={nameButton}
|
|
112
|
+
id={fieldId}
|
|
113
|
+
type="button"
|
|
114
|
+
class="workflow-name-control-view group flex w-full min-w-0 items-center gap-1.5 rounded-md border border-transparent px-2 py-1.5 text-start text-body-medium text-foreground transition-colors hover:cursor-text hover:border-input hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
115
|
+
aria-label={label}
|
|
116
|
+
onclick={beginEditing}
|
|
117
|
+
onkeydown={handleViewKeydown}
|
|
118
|
+
>
|
|
119
|
+
<span class="min-w-0 flex-1 truncate" dir="auto">{name}</span>
|
|
120
|
+
<Icon
|
|
121
|
+
name="pencil"
|
|
122
|
+
class="size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
|
|
123
|
+
/>
|
|
124
|
+
</button>
|
|
125
|
+
{/if}
|
|
126
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The name as the editor knows it (saved on the server). */
|
|
3
|
+
name: string;
|
|
4
|
+
/** Accessible label, e.g. "Rename workflow". */
|
|
5
|
+
label: string;
|
|
6
|
+
readonly?: boolean;
|
|
7
|
+
maxlength?: number;
|
|
8
|
+
class?: string;
|
|
9
|
+
oncommit: (name: string) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const WorkflowNameControl: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type WorkflowNameControl = ReturnType<typeof WorkflowNameControl>;
|
|
13
|
+
export default WorkflowNameControl;
|