@widgetic/workflows 0.2.10 → 0.2.12

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 (75) hide show
  1. package/README.md +11 -13
  2. package/dist/api/workflowsApi.d.ts +9 -1
  3. package/dist/api/workflowsApi.js +2 -1
  4. package/dist/assistant/assistantEvents.d.ts +42 -0
  5. package/dist/assistant/assistantEvents.js +61 -0
  6. package/dist/assistant/assistantRemoteChange.d.ts +4 -0
  7. package/dist/assistant/assistantRemoteChange.js +8 -0
  8. package/dist/assistant/assistantSaveMode.d.ts +5 -0
  9. package/dist/assistant/assistantSaveMode.js +8 -0
  10. package/dist/assistant/assistantStream.d.ts +8 -0
  11. package/dist/assistant/assistantStream.js +140 -0
  12. package/dist/assistant/assistantTranscript.d.ts +11 -0
  13. package/dist/assistant/assistantTranscript.js +18 -0
  14. package/dist/assistant/types.d.ts +81 -0
  15. package/dist/assistant/types.js +1 -0
  16. package/dist/assistant/workflowPlanViewModel.d.ts +48 -0
  17. package/dist/assistant/workflowPlanViewModel.js +17 -0
  18. package/dist/components/Workflows.svelte +3 -1
  19. package/dist/components/WorkflowsEmptyState.svelte +15 -3
  20. package/dist/components/WorkflowsEmptyState.svelte.d.ts +2 -0
  21. package/dist/components/WorkflowsWorkspace.svelte +4 -0
  22. package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
  23. package/dist/components/assistant/WorkflowAssistantPanel.svelte +384 -0
  24. package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +8 -0
  25. package/dist/components/canvas/CompositionNodeView.svelte +5 -5
  26. package/dist/components/canvas/ConditionNodeView.svelte +4 -4
  27. package/dist/components/canvas/HandlePoint.svelte +1 -1
  28. package/dist/components/canvas/TriggerNodeView.svelte +5 -4
  29. package/dist/components/canvas/WorkflowCanvas.svelte +16 -6
  30. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +2 -2
  31. package/dist/components/editor/EditorCanvasArea.svelte +57 -2
  32. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +8 -1
  33. package/dist/components/editor/EditorTabs.svelte +1 -2
  34. package/dist/components/editor/EditorTopBar.svelte +29 -21
  35. package/dist/components/editor/EditorTopBar.svelte.d.ts +3 -0
  36. package/dist/components/editor/RunsFlow.svelte +73 -23
  37. package/dist/components/editor/WorkflowEditor.svelte +31 -3
  38. package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
  39. package/dist/components/editor/WorkflowNameControl.svelte +136 -0
  40. package/dist/components/editor/WorkflowNameControl.svelte.d.ts +13 -0
  41. package/dist/components/list/WorkflowList.svelte +112 -60
  42. package/dist/components/list/WorkflowList.svelte.d.ts +2 -0
  43. package/dist/components/list/WorkflowRow.svelte +2 -0
  44. package/dist/components/panel/ConditionForm.svelte +7 -7
  45. package/dist/components/ui/Menu.svelte +31 -7
  46. package/dist/components/ui/Menu.svelte.d.ts +4 -0
  47. package/dist/components/ui/icons.d.ts +2 -0
  48. package/dist/components/ui/icons.js +3 -1
  49. package/dist/drafts/draftJournal.d.ts +59 -0
  50. package/dist/drafts/draftJournal.js +261 -0
  51. package/dist/drafts/workflowDraft.d.ts +72 -0
  52. package/dist/drafts/workflowDraft.js +151 -0
  53. package/dist/drafts/workflowListViewState.d.ts +30 -0
  54. package/dist/drafts/workflowListViewState.js +92 -0
  55. package/dist/editor/createBlankWorkflow.d.ts +30 -0
  56. package/dist/editor/createBlankWorkflow.js +37 -0
  57. package/dist/editor/editorState.svelte.d.ts +68 -2
  58. package/dist/editor/editorState.svelte.js +273 -0
  59. package/dist/editor/listState.svelte.d.ts +73 -36
  60. package/dist/editor/listState.svelte.js +260 -46
  61. package/dist/editor/presetChoice.d.ts +4 -4
  62. package/dist/editor/presetChoice.js +4 -4
  63. package/dist/editor/runsFlowBandLabel.d.ts +16 -0
  64. package/dist/editor/runsFlowBandLabel.js +34 -0
  65. package/dist/editor/runsFlowLayout.d.ts +24 -9
  66. package/dist/editor/runsFlowLayout.js +73 -28
  67. package/dist/editor/workflowNameCommit.d.ts +12 -0
  68. package/dist/editor/workflowNameCommit.js +11 -0
  69. package/dist/i18n/language.d.ts +3 -3
  70. package/dist/i18n/messages.d.ts +40 -26
  71. package/dist/i18n/messages.js +43 -30
  72. package/dist/types/index.d.ts +4 -0
  73. package/package.json +8 -1
  74. package/dist/components/list/CreateWorkflowDialog.svelte +0 -262
  75. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +0 -9
@@ -18,23 +18,30 @@
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 TextField from '../ui/TextField.svelte';
21
+ import WorkflowNameControl from './WorkflowNameControl.svelte';
22
22
 
23
23
  interface Props {
24
24
  onback: () => void;
25
25
  onpublish: () => void;
26
26
  /** Opens the embed code of this workflow; absent when the page that hosts the screen has no such dialog. */
27
27
  onshowembedcode?: () => void;
28
+ assistantEnabled?: boolean;
29
+ assistantOpen?: boolean;
30
+ onToggleAssistant?: () => void;
28
31
  }
29
32
 
30
- let { onback, onpublish, onshowembedcode }: Props = $props();
33
+ let {
34
+ onback,
35
+ onpublish,
36
+ onshowembedcode,
37
+ assistantEnabled = false,
38
+ assistantOpen = false,
39
+ onToggleAssistant
40
+ }: Props = $props();
31
41
 
32
42
  const editor = useEditorState();
33
43
  const { t } = useWorkflowsLanguage();
34
44
 
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
45
  const SAVE_STATE_KEYS = {
39
46
  saved: 'workflows.save.saved',
40
47
  pending: 'workflows.save.pending',
@@ -51,15 +58,6 @@
51
58
  : 'workflows.top.publishChanges'
52
59
  );
53
60
 
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
61
  function toggleTestRun(): void {
64
62
  if (editor.panel === 'test') editor.closeTestRun();
65
63
  else editor.openTestRun();
@@ -138,14 +136,12 @@
138
136
  <Icon name="back" class="size-4 rtl:rotate-180" />
139
137
  </IconButton>
140
138
  <div class="min-w-0 max-w-full flex-1 @3xl:w-60 @3xl:flex-none">
141
- <TextField
142
- label={$t('workflows.top.nameLabel')}
143
- hideLabel
144
- variant="soft"
139
+ <WorkflowNameControl
140
+ name={editor.name}
141
+ label={$t('workflows.top.renameLabel')}
142
+ readonly={editor.isReadOnly}
145
143
  maxlength={MAX_WORKFLOW_NAME_LENGTH}
146
- disabled={editor.isReadOnly}
147
- bind:value={nameDraft}
148
- onchange={commitName}
144
+ oncommit={(name) => editor.setName(name)}
149
145
  />
150
146
  </div>
151
147
  <div class="flex min-w-0 shrink-0 flex-col gap-1 @3xl:hidden" data-workflows-editor-status>
@@ -190,6 +186,18 @@
190
186
  <div class="hidden min-w-0 flex-1 @3xl:block"></div>
191
187
 
192
188
  <div class="hidden w-full flex-wrap items-center justify-end gap-2 @3xl:flex @3xl:w-auto">
189
+ {#if assistantEnabled && onToggleAssistant}
190
+ <Button
191
+ variant="outline"
192
+ size={dsButtonSize('small')}
193
+ aria-pressed={assistantOpen}
194
+ class={assistantOpen ? 'bg-accent' : ''}
195
+ disabled={editor.tab !== 'editor'}
196
+ onclick={onToggleAssistant}
197
+ >
198
+ {$t('workflows.assistant.toolbarButton')}
199
+ </Button>
200
+ {/if}
193
201
  <Button
194
202
  variant="outline"
195
203
  size={dsButtonSize('small')}
@@ -3,6 +3,9 @@ interface Props {
3
3
  onpublish: () => void;
4
4
  /** Opens the embed code of this workflow; absent when the page that hosts the screen has no such dialog. */
5
5
  onshowembedcode?: () => void;
6
+ assistantEnabled?: boolean;
7
+ assistantOpen?: boolean;
8
+ onToggleAssistant?: () => void;
6
9
  }
7
10
  declare const EditorTopBar: import("svelte").Component<Props, {}, "">;
8
11
  type EditorTopBar = ReturnType<typeof EditorTopBar>;
@@ -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
- /** The lines that say why a composition could not be shown hang under the line that says how often. */
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, for its tooltip: where it goes, how many went, and how a visitor gets along it. */
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
- <!-- The words are HTML in the drawing, so that a long name is cut with an ellipsis and a language that reads right to left is set properly. -->
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.x}
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
- <p
326
- class="truncate text-body-medium text-foreground"
327
- dir="auto"
328
- title={words.nameStep(step.nodeId)}
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 {line.kind === 'failed'
335
- ? 'text-destructive'
336
- : 'text-muted-foreground'} {isReasonLine(line.kind) ? 'ps-3' : ''}"
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
- {line.text}
360
+ {words.nameStep(step.nodeId)}
340
361
  </p>
341
- {/each}
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>
@@ -14,6 +14,8 @@
14
14
  import { useWorkflowsApi } from '../../api/apiContext.js';
15
15
  import { WorkflowEditorState, provideEditorState } from '../../editor/editorState.svelte.js';
16
16
  import { useWorkflowsLanguage } from '../../i18n/language.js';
17
+ import type { DraftRestoredInfo } from '../../drafts/workflowDraft.js';
18
+ import type { WorkflowAssistantConfig } from '../../assistant/types.js';
17
19
  import type { WorkflowsError } from '../../types/index.js';
18
20
  import { Button } from '@widgetic/design-system/components';
19
21
  import { dsButtonVariant } from '../ui/dsButtonProps.js';
@@ -38,6 +40,9 @@
38
40
  onshowembedcode?: (workflowId: string) => void;
39
41
  /** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
40
42
  presence?: boolean;
43
+ /** Called when unsaved edits were restored from the draft journal after load. */
44
+ onDraftRestored?: (info: DraftRestoredInfo) => void;
45
+ assistant?: WorkflowAssistantConfig | null;
41
46
  }
42
47
 
43
48
  let {
@@ -46,7 +51,9 @@
46
51
  onopenworkflow,
47
52
  onerror,
48
53
  onshowembedcode,
49
- presence = false
54
+ presence = false,
55
+ onDraftRestored,
56
+ assistant = null
50
57
  }: Props = $props();
51
58
 
52
59
  const api = useWorkflowsApi();
@@ -61,12 +68,25 @@
61
68
  presence: untrack(() => presence),
62
69
  reportError: (error) => onerror(error),
63
70
  leave: () => onback(),
64
- openWorkflow: (openedId) => onopenworkflow(openedId)
71
+ openWorkflow: (openedId) => onopenworkflow(openedId),
72
+ // A closure, so the latest callback of the screen is the one that is told.
73
+ onDraftRestored: (info) => onDraftRestored?.(info)
65
74
  });
66
75
  provideEditorState(editor);
67
76
 
68
77
  let isAskingToPublish = $state(false);
69
78
  let isAskingToLeave = $state(false);
79
+ let assistantPanelOpen = $state(true);
80
+
81
+ const assistantEnabled = $derived(Boolean(assistant?.enabled));
82
+
83
+ function toggleAssistantPanel(): void {
84
+ assistantPanelOpen = !assistantPanelOpen;
85
+ }
86
+
87
+ function openAssistantPanel(): void {
88
+ assistantPanelOpen = true;
89
+ }
70
90
 
71
91
  const showEmbedCode = $derived(
72
92
  onshowembedcode ? () => onshowembedcode(editor.workflowId) : undefined
@@ -145,6 +165,9 @@
145
165
  onback={() => void goBack()}
146
166
  onpublish={requestPublish}
147
167
  onshowembedcode={showEmbedCode}
168
+ assistantEnabled={assistantEnabled}
169
+ assistantOpen={assistantPanelOpen}
170
+ onToggleAssistant={toggleAssistantPanel}
148
171
  />
149
172
  <EditorTabs {panelId} />
150
173
  <EditorBanners />
@@ -155,7 +178,12 @@
155
178
  class="flex min-h-0 flex-1 min-w-0 flex-col"
156
179
  >
157
180
  {#if editor.tab === 'editor'}
158
- <EditorCanvasArea />
181
+ <EditorCanvasArea
182
+ {assistant}
183
+ assistantOpen={assistantPanelOpen}
184
+ onOpenAssistant={openAssistantPanel}
185
+ workflowId={workflowId}
186
+ />
159
187
  {:else if editor.tab === 'runs'}
160
188
  <RunsTab />
161
189
  {:else}
@@ -1,3 +1,5 @@
1
+ import type { DraftRestoredInfo } from '../../drafts/workflowDraft.js';
2
+ import type { WorkflowAssistantConfig } from '../../assistant/types.js';
1
3
  import type { WorkflowsError } from '../../types/index.js';
2
4
  interface Props {
3
5
  workflowId: string;
@@ -11,6 +13,9 @@ interface Props {
11
13
  onshowembedcode?: (workflowId: string) => void;
12
14
  /** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
13
15
  presence?: boolean;
16
+ /** Called when unsaved edits were restored from the draft journal after load. */
17
+ onDraftRestored?: (info: DraftRestoredInfo) => void;
18
+ assistant?: WorkflowAssistantConfig | null;
14
19
  }
15
20
  declare const WorkflowEditor: import("svelte").Component<Props, {}, "">;
16
21
  type WorkflowEditor = ReturnType<typeof WorkflowEditor>;
@@ -0,0 +1,136 @@
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 { useEditorState } from '../../editor/editorState.svelte.js';
9
+ import { decideWorkflowNameCommit } from '../../editor/workflowNameCommit.js';
10
+ import Icon from '../ui/Icon.svelte';
11
+
12
+ interface Props {
13
+ /** The name as the editor knows it (saved on the server). */
14
+ name: string;
15
+ /** Accessible label, e.g. "Rename workflow". */
16
+ label: string;
17
+ readonly?: boolean;
18
+ maxlength?: number;
19
+ class?: string;
20
+ oncommit: (name: string) => void;
21
+ }
22
+
23
+ const editor = useEditorState();
24
+
25
+ let {
26
+ name,
27
+ label,
28
+ readonly = false,
29
+ maxlength = MAX_WORKFLOW_NAME_LENGTH,
30
+ class: className = '',
31
+ oncommit
32
+ }: Props = $props();
33
+
34
+ let isEditing = $state(false);
35
+ let draft = $state('');
36
+ let inputElement = $state<HTMLInputElement | null>(null);
37
+ let nameButton = $state<HTMLButtonElement | null>(null);
38
+
39
+ const fieldId = $props.id();
40
+
41
+ function beginEditing(): void {
42
+ if (readonly || isEditing) return;
43
+ isEditing = true;
44
+ draft = name;
45
+ editor.setPendingWorkflowName(draft);
46
+ void tick().then(() => {
47
+ inputElement?.focus();
48
+ inputElement?.select();
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Ends the edit. `restoreFocus` is true when the keyboard ended it (Enter, Escape): the person is still in the header,
54
+ * so the focus goes back to the name. It is false for a blur: the person has already moved on to something else, and
55
+ * taking the focus back would pull it away from what they chose.
56
+ */
57
+ function finishEditing(commit: boolean, restoreFocus: boolean): void {
58
+ if (!isEditing) return;
59
+ if (commit) {
60
+ const decision = decideWorkflowNameCommit(name, draft);
61
+ if (decision.kind === 'revert') {
62
+ draft = decision.value;
63
+ } else {
64
+ oncommit(decision.value);
65
+ }
66
+ }
67
+ isEditing = false;
68
+ editor.setPendingWorkflowName(null);
69
+ // The name button is not in the page until the update that follows `isEditing = false`, so it takes the focus after it.
70
+ if (restoreFocus) void tick().then(() => nameButton?.focus());
71
+ }
72
+
73
+ function handleDraftInput(): void {
74
+ if (isEditing) editor.setPendingWorkflowName(draft);
75
+ }
76
+
77
+ function handleViewKeydown(event: KeyboardEvent): void {
78
+ if (readonly) return;
79
+ if (event.key === 'Enter' || event.key === 'F2') {
80
+ event.preventDefault();
81
+ beginEditing();
82
+ }
83
+ }
84
+
85
+ function handleInputKeydown(event: KeyboardEvent): void {
86
+ if (event.key === 'Enter') {
87
+ event.preventDefault();
88
+ finishEditing(true, true);
89
+ } else if (event.key === 'Escape') {
90
+ event.preventDefault();
91
+ draft = name;
92
+ finishEditing(false, true);
93
+ }
94
+ }
95
+ </script>
96
+
97
+ <div class="min-w-0 {className}">
98
+ {#if isEditing}
99
+ <input
100
+ bind:this={inputElement}
101
+ id={fieldId}
102
+ type="text"
103
+ 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"
104
+ bind:value={draft}
105
+ oninput={handleDraftInput}
106
+ {maxlength}
107
+ aria-label={label}
108
+ onkeydown={handleInputKeydown}
109
+ onblur={() => finishEditing(true, false)}
110
+ />
111
+ {:else if readonly}
112
+ <p
113
+ id={fieldId}
114
+ class="workflow-name-control-view min-w-0 truncate px-2 py-1.5 text-body-medium text-foreground"
115
+ dir="auto"
116
+ >
117
+ {name}
118
+ </p>
119
+ {:else}
120
+ <button
121
+ bind:this={nameButton}
122
+ id={fieldId}
123
+ type="button"
124
+ 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"
125
+ aria-label={label}
126
+ onclick={beginEditing}
127
+ onkeydown={handleViewKeydown}
128
+ >
129
+ <span class="min-w-0 flex-1 truncate" dir="auto">{name}</span>
130
+ <Icon
131
+ name="pencil"
132
+ class="size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
133
+ />
134
+ </button>
135
+ {/if}
136
+ </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;