@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.
- package/README.md +11 -13
- package/dist/api/workflowsApi.d.ts +9 -1
- package/dist/api/workflowsApi.js +2 -1
- package/dist/assistant/assistantEvents.d.ts +42 -0
- package/dist/assistant/assistantEvents.js +61 -0
- package/dist/assistant/assistantRemoteChange.d.ts +4 -0
- package/dist/assistant/assistantRemoteChange.js +8 -0
- package/dist/assistant/assistantSaveMode.d.ts +5 -0
- package/dist/assistant/assistantSaveMode.js +8 -0
- package/dist/assistant/assistantStream.d.ts +8 -0
- package/dist/assistant/assistantStream.js +140 -0
- package/dist/assistant/assistantTranscript.d.ts +11 -0
- package/dist/assistant/assistantTranscript.js +18 -0
- package/dist/assistant/types.d.ts +81 -0
- package/dist/assistant/types.js +1 -0
- package/dist/assistant/workflowPlanViewModel.d.ts +48 -0
- package/dist/assistant/workflowPlanViewModel.js +17 -0
- package/dist/components/Workflows.svelte +3 -1
- package/dist/components/WorkflowsEmptyState.svelte +15 -3
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +2 -0
- package/dist/components/WorkflowsWorkspace.svelte +4 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +384 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +8 -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/canvas/WorkflowCanvas.svelte +16 -6
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +2 -2
- package/dist/components/editor/EditorCanvasArea.svelte +57 -2
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +8 -1
- package/dist/components/editor/EditorTabs.svelte +1 -2
- package/dist/components/editor/EditorTopBar.svelte +29 -21
- package/dist/components/editor/EditorTopBar.svelte.d.ts +3 -0
- package/dist/components/editor/RunsFlow.svelte +73 -23
- package/dist/components/editor/WorkflowEditor.svelte +31 -3
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
- package/dist/components/editor/WorkflowNameControl.svelte +136 -0
- package/dist/components/editor/WorkflowNameControl.svelte.d.ts +13 -0
- package/dist/components/list/WorkflowList.svelte +112 -60
- package/dist/components/list/WorkflowList.svelte.d.ts +2 -0
- package/dist/components/list/WorkflowRow.svelte +2 -0
- package/dist/components/panel/ConditionForm.svelte +7 -7
- package/dist/components/ui/Menu.svelte +31 -7
- package/dist/components/ui/Menu.svelte.d.ts +4 -0
- package/dist/components/ui/icons.d.ts +2 -0
- package/dist/components/ui/icons.js +3 -1
- package/dist/drafts/draftJournal.d.ts +59 -0
- package/dist/drafts/draftJournal.js +261 -0
- package/dist/drafts/workflowDraft.d.ts +72 -0
- package/dist/drafts/workflowDraft.js +151 -0
- package/dist/drafts/workflowListViewState.d.ts +30 -0
- package/dist/drafts/workflowListViewState.js +92 -0
- package/dist/editor/createBlankWorkflow.d.ts +30 -0
- package/dist/editor/createBlankWorkflow.js +37 -0
- package/dist/editor/editorState.svelte.d.ts +68 -2
- package/dist/editor/editorState.svelte.js +273 -0
- package/dist/editor/listState.svelte.d.ts +73 -36
- package/dist/editor/listState.svelte.js +260 -46
- 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 +40 -26
- package/dist/i18n/messages.js +43 -30
- package/dist/types/index.d.ts +4 -0
- package/package.json +8 -1
- package/dist/components/list/CreateWorkflowDialog.svelte +0 -262
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +0 -9
|
@@ -2,10 +2,9 @@
|
|
|
2
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
3
|
published, how many visitors started it) and a row for each, with "New workflow" at the top.
|
|
4
4
|
|
|
5
|
-
The filter is
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tab; choosing a tab puts Status back to Any. The model of it is in `WorkflowListState` (`chooseScope`, `chooseStatus`).
|
|
5
|
+
The filter is status tabs (All, Draft, Live, Paused, Archived) on a wide screen, and the same choices in one Status select on
|
|
6
|
+
a narrow one. `All` asks for the API default (not archived); each other tab asks for that state only. The model is in
|
|
7
|
+
`WorkflowListState` (`chooseTab`).
|
|
9
8
|
|
|
10
9
|
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"
|
|
11
10
|
adds the next page. A page of nothing says why: nothing made yet (and offers to make one), or nothing matches what was asked.
|
|
@@ -15,15 +14,14 @@
|
|
|
15
14
|
-->
|
|
16
15
|
<script lang="ts">
|
|
17
16
|
import { onDestroy, onMount, untrack } from 'svelte';
|
|
18
|
-
import type { WorkflowDetail } from '../../api/types.js';
|
|
19
17
|
import type { WorkflowSortField } from '../../api/types.js';
|
|
20
18
|
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
21
19
|
import {
|
|
22
|
-
|
|
20
|
+
LIST_TABS,
|
|
23
21
|
WorkflowListState,
|
|
24
|
-
provideListState
|
|
22
|
+
provideListState,
|
|
23
|
+
type ListTab
|
|
25
24
|
} from '../../editor/listState.svelte.js';
|
|
26
|
-
import type { ListScope } from '../../editor/listState.svelte.js';
|
|
27
25
|
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
28
26
|
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
29
27
|
import { STATUS_WORD_KEYS } from '../../i18n/statusWords.js';
|
|
@@ -38,10 +36,11 @@
|
|
|
38
36
|
import Tabs from '../ui/Tabs.svelte';
|
|
39
37
|
import TextField from '../ui/TextField.svelte';
|
|
40
38
|
import type { SelectChoice } from '../ui/types.js';
|
|
41
|
-
import CreateWorkflowDialog from './CreateWorkflowDialog.svelte';
|
|
42
39
|
import WorkflowRow from './WorkflowRow.svelte';
|
|
43
40
|
|
|
44
41
|
interface Props {
|
|
42
|
+
/** Keys persisted list view state and new-workflow dialog drafts for this workspace. */
|
|
43
|
+
workspaceId: string;
|
|
45
44
|
/** A workflow was chosen (or just made): open it. */
|
|
46
45
|
onopen: (workflowId: string) => void;
|
|
47
46
|
/** A failure the page should hear about. */
|
|
@@ -55,25 +54,27 @@
|
|
|
55
54
|
presence?: boolean;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
let { onopen, onerror, onshowembedcode, presence = false }: Props = $props();
|
|
57
|
+
let { workspaceId, onopen, onerror, onshowembedcode, presence = false }: Props = $props();
|
|
59
58
|
|
|
60
59
|
const api = useWorkflowsApi();
|
|
61
60
|
const { t } = useWorkflowsLanguage();
|
|
62
61
|
|
|
63
62
|
const list = new WorkflowListState({
|
|
64
63
|
api,
|
|
64
|
+
workspaceId: untrack(() => workspaceId),
|
|
65
65
|
reportError: (error) => onerror(error),
|
|
66
66
|
// Read once, like the list: presence belongs to this opening of it.
|
|
67
67
|
presence: untrack(() => presence)
|
|
68
68
|
});
|
|
69
69
|
provideListState(list);
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
const TAB_LABEL_KEYS = {
|
|
72
|
+
all: 'workflows.list.filterAll',
|
|
73
|
+
draft: STATUS_WORD_KEYS.draft,
|
|
74
|
+
live: STATUS_WORD_KEYS.live,
|
|
75
|
+
paused: STATUS_WORD_KEYS.paused,
|
|
76
|
+
archived: STATUS_WORD_KEYS.archived
|
|
77
|
+
} as const satisfies Record<ListTab, WorkflowsMessageKey>;
|
|
77
78
|
|
|
78
79
|
const SORT_KEYS = {
|
|
79
80
|
createdAt: 'workflows.list.sortCreated',
|
|
@@ -84,13 +85,9 @@
|
|
|
84
85
|
|
|
85
86
|
const listPanelId = $props.id();
|
|
86
87
|
|
|
87
|
-
const tabItems = $derived([
|
|
88
|
-
{ key: 'active', label: $t(TAB_FILTER_KEYS.active) },
|
|
89
|
-
{ key: 'all', label: $t(TAB_FILTER_KEYS.all) }
|
|
90
|
-
]);
|
|
88
|
+
const tabItems = $derived(LIST_TABS.map((key) => ({ key, label: $t(TAB_LABEL_KEYS[key]) })));
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
const tabValue = $derived(list.scope);
|
|
90
|
+
const tabValue = $derived(list.tab);
|
|
94
91
|
|
|
95
92
|
/**
|
|
96
93
|
* Nothing has been made yet and nothing narrows the list: the design then shows the title and the empty state alone (the
|
|
@@ -100,12 +97,11 @@
|
|
|
100
97
|
list.loadState === 'ready' && list.items.length === 0 && !list.isNarrowed
|
|
101
98
|
);
|
|
102
99
|
|
|
103
|
-
|
|
100
|
+
const isNewWorkflowBusy = $derived(list.isCreatingNew);
|
|
101
|
+
|
|
102
|
+
/** The lines of the mobile Status select: the same tabs as on a wide screen. */
|
|
104
103
|
const statusChoices = $derived<SelectChoice[]>(
|
|
105
|
-
|
|
106
|
-
value: choice,
|
|
107
|
-
label: $t(choice === 'any' ? 'workflows.list.statusAny' : STATUS_WORD_KEYS[choice])
|
|
108
|
-
}))
|
|
104
|
+
tabItems.map((item) => ({ value: item.key, label: item.label }))
|
|
109
105
|
);
|
|
110
106
|
|
|
111
107
|
const sortChoices = $derived<SelectChoice[]>(
|
|
@@ -116,18 +112,35 @@
|
|
|
116
112
|
);
|
|
117
113
|
|
|
118
114
|
let searchDraft = $state('');
|
|
115
|
+
let listBodyElement = $state<HTMLDivElement | undefined>();
|
|
116
|
+
let restoredListScroll = $state(false);
|
|
119
117
|
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
onopen(created.id);
|
|
118
|
+
function startNewWorkflow(): void {
|
|
119
|
+
void list.createBlankAndOpen(onopen);
|
|
123
120
|
}
|
|
124
121
|
|
|
125
|
-
/** A tab was chosen: the list covers what it says, and Status goes back to Any (see `WorkflowListState.chooseScope`). */
|
|
126
122
|
function setTab(key: string): void {
|
|
127
|
-
list.
|
|
123
|
+
list.chooseTab(key);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleListScroll(): void {
|
|
127
|
+
if (!listBodyElement) return;
|
|
128
|
+
list.followListScroll(listBodyElement.scrollTop);
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
$effect(() => {
|
|
132
|
+
if (restoredListScroll || list.loadState !== 'ready' || !listBodyElement) return;
|
|
133
|
+
if (list.listScrollTop <= 0) {
|
|
134
|
+
restoredListScroll = true;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
listBodyElement.scrollTop = list.listScrollTop;
|
|
138
|
+
restoredListScroll = true;
|
|
139
|
+
});
|
|
140
|
+
|
|
130
141
|
onMount(() => {
|
|
142
|
+
list.restorePersistedState();
|
|
143
|
+
searchDraft = list.search;
|
|
131
144
|
void list.load();
|
|
132
145
|
// Who is editing what is asked alongside the load (it looks again once the rows are there); nothing happens without `presence`.
|
|
133
146
|
list.startPresence();
|
|
@@ -154,10 +167,17 @@
|
|
|
154
167
|
oninput={() => list.setSearch(searchDraft)}
|
|
155
168
|
/>
|
|
156
169
|
<!-- The design draws this button outlined while the list could not be read (the error state has the main action). -->
|
|
157
|
-
<Button
|
|
158
|
-
|
|
170
|
+
<Button
|
|
171
|
+
variant={dsButtonVariant(list.loadState === 'failed' ? 'outline' : 'primary')}
|
|
172
|
+
disabled={isNewWorkflowBusy}
|
|
173
|
+
aria-busy={isNewWorkflowBusy}
|
|
174
|
+
onclick={startNewWorkflow}
|
|
159
175
|
>
|
|
160
|
-
|
|
176
|
+
{#if isNewWorkflowBusy}
|
|
177
|
+
<Icon name="loader" class="size-4 motion-safe:animate-spin" />
|
|
178
|
+
{:else}
|
|
179
|
+
<Icon name="plus" class="size-4" />
|
|
180
|
+
{/if}
|
|
161
181
|
{$t('workflows.list.newWorkflow')}
|
|
162
182
|
</Button>
|
|
163
183
|
</div>
|
|
@@ -173,9 +193,15 @@
|
|
|
173
193
|
variant={dsIconButtonVariant(list.loadState === 'failed' ? 'outline' : 'primary')}
|
|
174
194
|
label={$t('workflows.list.newWorkflow')}
|
|
175
195
|
title={$t('workflows.list.newWorkflow')}
|
|
176
|
-
|
|
196
|
+
disabled={isNewWorkflowBusy}
|
|
197
|
+
aria-busy={isNewWorkflowBusy}
|
|
198
|
+
onclick={startNewWorkflow}
|
|
177
199
|
>
|
|
178
|
-
|
|
200
|
+
{#if isNewWorkflowBusy}
|
|
201
|
+
<Icon name="loader" class="size-4 motion-safe:animate-spin" />
|
|
202
|
+
{:else}
|
|
203
|
+
<Icon name="plus" class="size-4" />
|
|
204
|
+
{/if}
|
|
179
205
|
</IconButton>
|
|
180
206
|
{/if}
|
|
181
207
|
</div>
|
|
@@ -194,14 +220,34 @@
|
|
|
194
220
|
{/if}
|
|
195
221
|
</div>
|
|
196
222
|
|
|
197
|
-
{#if list.
|
|
223
|
+
{#if list.createFailure}
|
|
224
|
+
<div class="px-4 pb-3 @3xl:px-8">
|
|
225
|
+
<Notice tone="problem">
|
|
226
|
+
{$t(list.createFailure)}
|
|
227
|
+
{#snippet action()}
|
|
228
|
+
<Button
|
|
229
|
+
variant={dsButtonVariant('ghost')}
|
|
230
|
+
size={dsButtonSize('small')}
|
|
231
|
+
onclick={() => {
|
|
232
|
+
list.createFailure = null;
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{$t('workflows.common.dismiss')}
|
|
236
|
+
</Button>
|
|
237
|
+
{/snippet}
|
|
238
|
+
</Notice>
|
|
239
|
+
</div>
|
|
240
|
+
{:else if list.notice}
|
|
198
241
|
{@const notice = list.notice}
|
|
199
242
|
<div class="px-4 pb-3 @3xl:px-8">
|
|
200
243
|
<Notice tone={notice.tone}>
|
|
201
244
|
{$t(notice.messageKey, notice.values)}
|
|
202
245
|
{#snippet action()}
|
|
203
|
-
<Button
|
|
204
|
-
|
|
246
|
+
<Button
|
|
247
|
+
variant={dsButtonVariant('ghost')}
|
|
248
|
+
size={dsButtonSize('small')}
|
|
249
|
+
onclick={() => list.dismissNotice()}>{$t('workflows.common.dismiss')}</Button
|
|
250
|
+
>
|
|
205
251
|
{/snippet}
|
|
206
252
|
</Notice>
|
|
207
253
|
</div>
|
|
@@ -212,10 +258,13 @@
|
|
|
212
258
|
<div
|
|
213
259
|
class="flex shrink-0 flex-col gap-3 px-4 pb-3 @3xl:flex-row @3xl:items-center @3xl:justify-between @3xl:gap-2 @3xl:px-8 @3xl:pb-4"
|
|
214
260
|
>
|
|
215
|
-
<!--
|
|
216
|
-
|
|
261
|
+
<!--
|
|
262
|
+
A wide screen has the status tabs; a narrow one has the Status select below instead. The tab list sets its own
|
|
263
|
+
`display`, which a `hidden` on it would not beat, so the wrapper is what is hidden (and, with `display: none`, its
|
|
264
|
+
tabs are out of the tab order and of what a screen reader reads).
|
|
265
|
+
-->
|
|
266
|
+
<div class="hidden @3xl:block">
|
|
217
267
|
<Tabs
|
|
218
|
-
class="self-start @3xl:self-auto"
|
|
219
268
|
tabs={tabItems}
|
|
220
269
|
value={tabValue}
|
|
221
270
|
label={$t('workflows.list.filterLabel')}
|
|
@@ -223,16 +272,16 @@
|
|
|
223
272
|
controls={listPanelId}
|
|
224
273
|
onselect={setTab}
|
|
225
274
|
/>
|
|
226
|
-
<SelectField
|
|
227
|
-
class="w-full min-w-0 @3xl:w-auto @3xl:flex-none"
|
|
228
|
-
label={$t('workflows.list.statusLabel')}
|
|
229
|
-
inlineLabel
|
|
230
|
-
value={list.statusChoice}
|
|
231
|
-
choices={statusChoices}
|
|
232
|
-
onchange={(choice) => list.chooseStatus(choice)}
|
|
233
|
-
/>
|
|
234
275
|
</div>
|
|
235
|
-
<
|
|
276
|
+
<SelectField
|
|
277
|
+
class="w-full min-w-0 @3xl:hidden"
|
|
278
|
+
label={$t('workflows.list.statusLabel')}
|
|
279
|
+
inlineLabel
|
|
280
|
+
value={list.tab}
|
|
281
|
+
choices={statusChoices}
|
|
282
|
+
onchange={(choice) => list.chooseTab(choice)}
|
|
283
|
+
/>
|
|
284
|
+
<div class="flex w-full min-w-0 items-center gap-2 @3xl:ms-auto @3xl:w-auto @3xl:shrink-0">
|
|
236
285
|
<SelectField
|
|
237
286
|
class="min-w-0 flex-1 @3xl:w-52 @3xl:flex-none"
|
|
238
287
|
label={$t('workflows.list.sortLabel')}
|
|
@@ -242,7 +291,7 @@
|
|
|
242
291
|
onchange={(field) => list.setSort(field as WorkflowSortField)}
|
|
243
292
|
/>
|
|
244
293
|
<IconButton
|
|
245
|
-
variant={dsIconButtonVariant(
|
|
294
|
+
variant={dsIconButtonVariant('outline')}
|
|
246
295
|
label={list.sortDirection === 'asc'
|
|
247
296
|
? $t('workflows.list.sortAscending')
|
|
248
297
|
: $t('workflows.list.sortDescending')}
|
|
@@ -262,11 +311,13 @@
|
|
|
262
311
|
|
|
263
312
|
<!-- List body -->
|
|
264
313
|
<div
|
|
314
|
+
bind:this={listBodyElement}
|
|
265
315
|
id={listPanelId}
|
|
266
316
|
role="tabpanel"
|
|
267
317
|
aria-labelledby="{listPanelId}-tab-{tabValue}"
|
|
268
318
|
class="flex min-h-0 flex-1 flex-col gap-1 overflow-auto px-4 pb-4 @3xl:px-4"
|
|
269
319
|
aria-label={$t('workflows.list.label')}
|
|
320
|
+
onscroll={handleListScroll}
|
|
270
321
|
>
|
|
271
322
|
{#if list.loadState === 'loading'}
|
|
272
323
|
<!-- Figma "Loading": the rows' own shape in `bg-muted` (tile, name bar, details bar, state pill). -->
|
|
@@ -299,7 +350,11 @@
|
|
|
299
350
|
{$t(list.failure ?? 'workflows.error.generic')}
|
|
300
351
|
</p>
|
|
301
352
|
</div>
|
|
302
|
-
<Button
|
|
353
|
+
<Button
|
|
354
|
+
class="mt-3"
|
|
355
|
+
variant={dsButtonVariant('primary')}
|
|
356
|
+
onclick={() => void list.load()}
|
|
357
|
+
>
|
|
303
358
|
<Icon name="refresh" class="size-4" />
|
|
304
359
|
{$t('workflows.error.retry')}
|
|
305
360
|
</Button>
|
|
@@ -317,7 +372,7 @@
|
|
|
317
372
|
</div>
|
|
318
373
|
</div>
|
|
319
374
|
{:else}
|
|
320
|
-
<WorkflowsEmptyState
|
|
375
|
+
<WorkflowsEmptyState busy={isNewWorkflowBusy} oncreate={startNewWorkflow} />
|
|
321
376
|
{/if}
|
|
322
377
|
{:else}
|
|
323
378
|
<ul class="flex flex-col gap-1">
|
|
@@ -326,7 +381,8 @@
|
|
|
326
381
|
{/each}
|
|
327
382
|
</ul>
|
|
328
383
|
{#if list.hasMore}
|
|
329
|
-
<Button
|
|
384
|
+
<Button
|
|
385
|
+
class="mt-2 self-center"
|
|
330
386
|
disabled={list.loadingMore}
|
|
331
387
|
onclick={() => void list.loadMore()}
|
|
332
388
|
>
|
|
@@ -336,7 +392,3 @@
|
|
|
336
392
|
{/if}
|
|
337
393
|
</div>
|
|
338
394
|
</div>
|
|
339
|
-
|
|
340
|
-
{#if isCreating}
|
|
341
|
-
<CreateWorkflowDialog oncancel={() => (isCreating = false)} oncreated={handleCreated} />
|
|
342
|
-
{/if}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { WorkflowsError } from '../../types/index.js';
|
|
2
2
|
interface Props {
|
|
3
|
+
/** Keys persisted list view state and new-workflow dialog drafts for this workspace. */
|
|
4
|
+
workspaceId: string;
|
|
3
5
|
/** A workflow was chosen (or just made): open it. */
|
|
4
6
|
onopen: (workflowId: string) => void;
|
|
5
7
|
/** A failure the page should hear about. */
|
|
@@ -227,6 +227,8 @@
|
|
|
227
227
|
size="small"
|
|
228
228
|
align="end"
|
|
229
229
|
disabled={isBusy}
|
|
230
|
+
initialOpen={list.openMenuWorkflowId === item.id}
|
|
231
|
+
onOpenChange={(open) => list.followRowMenuOpen(open ? item.id : null)}
|
|
230
232
|
class="relative z-20 col-start-3 row-start-1 self-start transition-opacity duration-fast @3xl:col-start-4 @3xl:self-center pointer-fine:opacity-0 pointer-fine:group-focus-within:opacity-100 pointer-fine:group-hover:opacity-100 pointer-fine:[.group:has([aria-expanded=true])_&]:opacity-100"
|
|
231
233
|
/>
|
|
232
234
|
</div>
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
/** At most one rule card is expanded (accordion); new rules open the last card. */
|
|
44
|
-
let expandedRuleId = $state<string | null>(null);
|
|
45
44
|
let lastCaseCount = $state(0);
|
|
46
45
|
let wasConditionSelected = $state(false);
|
|
47
46
|
|
|
@@ -54,9 +53,9 @@
|
|
|
54
53
|
return;
|
|
55
54
|
}
|
|
56
55
|
if (!wasConditionSelected && count > 0) {
|
|
57
|
-
expandedRuleId = node.cases[0]!.id;
|
|
56
|
+
editor.expandedRuleId = node.cases[0]!.id;
|
|
58
57
|
} else if (count > lastCaseCount && count > 0) {
|
|
59
|
-
expandedRuleId = node.cases[count - 1]!.id;
|
|
58
|
+
editor.expandedRuleId = node.cases[count - 1]!.id;
|
|
60
59
|
}
|
|
61
60
|
wasConditionSelected = true;
|
|
62
61
|
lastCaseCount = count;
|
|
@@ -69,12 +68,13 @@
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
function toggleRule(ruleId: string): void {
|
|
72
|
-
expandedRuleId = expandedRuleId === ruleId ? null : ruleId;
|
|
71
|
+
editor.expandedRuleId = editor.expandedRuleId === ruleId ? null : ruleId;
|
|
72
|
+
editor.persistEditorViewState();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
$effect(() => {
|
|
76
|
-
if (expandedRuleId !== null && !node.cases.some((c) => c.id === expandedRuleId)) {
|
|
77
|
-
expandedRuleId = node.cases[0]?.id ?? null;
|
|
76
|
+
if (editor.expandedRuleId !== null && !node.cases.some((c) => c.id === editor.expandedRuleId)) {
|
|
77
|
+
editor.expandedRuleId = node.cases[0]?.id ?? null;
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
</script>
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
{rule}
|
|
100
100
|
{index}
|
|
101
101
|
{choices}
|
|
102
|
-
expanded={expandedRuleId === rule.id}
|
|
102
|
+
expanded={editor.expandedRuleId === rule.id}
|
|
103
103
|
onToggle={() => toggleRule(rule.id)}
|
|
104
104
|
/>
|
|
105
105
|
{/each}
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
/** Classes for the button that opens the list (`class` is for the box around it and the list). */
|
|
38
38
|
triggerClass?: string;
|
|
39
39
|
onopen?: () => void;
|
|
40
|
+
/** Opens the menu once when the list restores which row had its menu up. */
|
|
41
|
+
initialOpen?: boolean;
|
|
42
|
+
/** Whether the menu is open (for persisting list view state). */
|
|
43
|
+
onOpenChange?: (open: boolean) => void;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
let {
|
|
@@ -51,7 +55,9 @@
|
|
|
51
55
|
placement = 'below',
|
|
52
56
|
class: className = '',
|
|
53
57
|
triggerClass = '',
|
|
54
|
-
onopen
|
|
58
|
+
onopen,
|
|
59
|
+
initialOpen = false,
|
|
60
|
+
onOpenChange
|
|
55
61
|
}: Props = $props();
|
|
56
62
|
|
|
57
63
|
const menuId = $props.id();
|
|
@@ -59,6 +65,21 @@
|
|
|
59
65
|
let isOpen = $state(false);
|
|
60
66
|
let rootElement = $state<HTMLDivElement>();
|
|
61
67
|
let menuElement = $state<HTMLDivElement>();
|
|
68
|
+
let appliedInitialOpen = $state(false);
|
|
69
|
+
|
|
70
|
+
function notifyOpenChange(open: boolean): void {
|
|
71
|
+
try {
|
|
72
|
+
onOpenChange?.(open);
|
|
73
|
+
} catch {
|
|
74
|
+
// A handler of the page must not break the menu.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
$effect(() => {
|
|
79
|
+
if (!initialOpen || appliedInitialOpen) return;
|
|
80
|
+
appliedInitialOpen = true;
|
|
81
|
+
void revealMenu('first');
|
|
82
|
+
});
|
|
62
83
|
|
|
63
84
|
/** The lines that can be reached with the arrows. */
|
|
64
85
|
function listItemButtons(): HTMLButtonElement[] {
|
|
@@ -67,9 +88,11 @@
|
|
|
67
88
|
: [];
|
|
68
89
|
}
|
|
69
90
|
|
|
70
|
-
async function
|
|
91
|
+
async function revealMenu(landOn: 'first' | 'last' = 'first'): Promise<void> {
|
|
71
92
|
if (disabled) return;
|
|
93
|
+
const wasOpen = isOpen;
|
|
72
94
|
isOpen = true;
|
|
95
|
+
if (!wasOpen) notifyOpenChange(true);
|
|
73
96
|
onopen?.();
|
|
74
97
|
await tick();
|
|
75
98
|
const buttons = listItemButtons();
|
|
@@ -78,7 +101,7 @@
|
|
|
78
101
|
|
|
79
102
|
/** Opens the list from outside (a shortcut key of the screen). */
|
|
80
103
|
export function openMenu(): void {
|
|
81
|
-
void
|
|
104
|
+
void revealMenu('first');
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
/** The button that opens the menu: the first button of the root, before the lines of the list. */
|
|
@@ -89,12 +112,13 @@
|
|
|
89
112
|
function close(returnFocus: boolean): void {
|
|
90
113
|
if (!isOpen) return;
|
|
91
114
|
isOpen = false;
|
|
115
|
+
notifyOpenChange(false);
|
|
92
116
|
if (returnFocus) findTriggerButton()?.focus();
|
|
93
117
|
}
|
|
94
118
|
|
|
95
119
|
function toggle(): void {
|
|
96
120
|
if (isOpen) close(false);
|
|
97
|
-
else void
|
|
121
|
+
else void revealMenu();
|
|
98
122
|
}
|
|
99
123
|
|
|
100
124
|
function choose(item: MenuItem): void {
|
|
@@ -108,10 +132,10 @@
|
|
|
108
132
|
if (event.target !== findTriggerButton()) return;
|
|
109
133
|
if (event.key === 'ArrowDown') {
|
|
110
134
|
event.preventDefault();
|
|
111
|
-
void
|
|
135
|
+
void revealMenu('first');
|
|
112
136
|
} else if (event.key === 'ArrowUp') {
|
|
113
137
|
event.preventDefault();
|
|
114
|
-
void
|
|
138
|
+
void revealMenu('last');
|
|
115
139
|
}
|
|
116
140
|
}
|
|
117
141
|
|
|
@@ -146,7 +170,7 @@
|
|
|
146
170
|
$effect(() => {
|
|
147
171
|
if (!isOpen) return;
|
|
148
172
|
const closeOnOutsidePress = (event: Event) => {
|
|
149
|
-
if (rootElement && !event.composedPath().includes(rootElement))
|
|
173
|
+
if (rootElement && !event.composedPath().includes(rootElement)) close(false);
|
|
150
174
|
};
|
|
151
175
|
document.addEventListener('pointerdown', closeOnOutsidePress, true);
|
|
152
176
|
return () => document.removeEventListener('pointerdown', closeOnOutsidePress, true);
|
|
@@ -17,6 +17,10 @@ interface Props {
|
|
|
17
17
|
/** Classes for the button that opens the list (`class` is for the box around it and the list). */
|
|
18
18
|
triggerClass?: string;
|
|
19
19
|
onopen?: () => void;
|
|
20
|
+
/** Opens the menu once when the list restores which row had its menu up. */
|
|
21
|
+
initialOpen?: boolean;
|
|
22
|
+
/** Whether the menu is open (for persisting list view state). */
|
|
23
|
+
onOpenChange?: (open: boolean) => void;
|
|
20
24
|
}
|
|
21
25
|
declare const Menu: import("svelte").Component<Props, {
|
|
22
26
|
openMenu: () => void;
|
|
@@ -44,5 +44,7 @@ export declare const ICON_PATHS: {
|
|
|
44
44
|
readonly clock: readonly ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M12 7v5l3 3"];
|
|
45
45
|
readonly forms: readonly ["M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3", "M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3", "M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7", "M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1", "M17 12h.01", "M13 12h.01"];
|
|
46
46
|
readonly condition: readonly ["M12 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M17 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 8v2a2 2 0 0 0 2 2h6a2 2 0 0 0 2 -2v-2", "M12 12l0 4"];
|
|
47
|
+
/** Small pencil shown on hover beside an editable title. */
|
|
48
|
+
readonly pencil: readonly ["M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4", "M13.5 6.5l4 4"];
|
|
47
49
|
};
|
|
48
50
|
export type IconName = keyof typeof ICON_PATHS;
|
|
@@ -110,6 +110,8 @@ export const ICON_PATHS = {
|
|
|
110
110
|
'M17 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0',
|
|
111
111
|
'M7 8v2a2 2 0 0 0 2 2h6a2 2 0 0 0 2 -2v-2',
|
|
112
112
|
'M12 12l0 4'
|
|
113
|
-
]
|
|
113
|
+
],
|
|
114
|
+
/** Small pencil shown on hover beside an editable title. */
|
|
115
|
+
pencil: ['M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4', 'M13.5 6.5l4 4']
|
|
114
116
|
// [extra icons]
|
|
115
117
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Refresh-safe draft journal (localStorage). Copied per package; see QoL persistence spec. */
|
|
2
|
+
export declare const DRAFT_STORAGE_PREFIX = "widgetic:draft:";
|
|
3
|
+
export declare const DRAFT_FORMAT_VERSION = 1;
|
|
4
|
+
export declare const DEFAULT_DRAFT_MAX_BYTES: number;
|
|
5
|
+
export declare const DEFAULT_DRAFT_MAX_AGE_MS: number;
|
|
6
|
+
export declare const DRAFT_WRITE_THROTTLE_MS = 250;
|
|
7
|
+
export interface DraftJournalEntry<T> {
|
|
8
|
+
v: number;
|
|
9
|
+
savedAtMs: number;
|
|
10
|
+
baseRevision: string | null;
|
|
11
|
+
payload: T;
|
|
12
|
+
}
|
|
13
|
+
export interface DraftJournalStorage {
|
|
14
|
+
getItem(key: string): string | null;
|
|
15
|
+
setItem(key: string, value: string): void;
|
|
16
|
+
removeItem(key: string): void;
|
|
17
|
+
length: number;
|
|
18
|
+
key(index: number): string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface DraftJournalClock {
|
|
21
|
+
now(): number;
|
|
22
|
+
}
|
|
23
|
+
export interface DraftJournalLogger {
|
|
24
|
+
debug(message: string, detail?: unknown): void;
|
|
25
|
+
}
|
|
26
|
+
export interface DraftJournalTimers {
|
|
27
|
+
setTimeout(callback: () => void, milliseconds: number): unknown;
|
|
28
|
+
clearTimeout(handle: unknown): void;
|
|
29
|
+
}
|
|
30
|
+
/** Minimal window/document surface for leave flushing (tests inject fakes). */
|
|
31
|
+
export interface DraftJournalWindow {
|
|
32
|
+
addEventListener(type: string, listener: () => void): void;
|
|
33
|
+
removeEventListener(type: string, listener: () => void): void;
|
|
34
|
+
}
|
|
35
|
+
export interface DraftJournalDocument {
|
|
36
|
+
addEventListener(type: string, listener: () => void): void;
|
|
37
|
+
removeEventListener(type: string, listener: () => void): void;
|
|
38
|
+
readonly visibilityState: DocumentVisibilityState | string;
|
|
39
|
+
}
|
|
40
|
+
export interface DraftJournalOptions {
|
|
41
|
+
storage?: DraftJournalStorage;
|
|
42
|
+
clock?: DraftJournalClock;
|
|
43
|
+
logger?: DraftJournalLogger;
|
|
44
|
+
timers?: DraftJournalTimers;
|
|
45
|
+
window?: DraftJournalWindow | null;
|
|
46
|
+
document?: DraftJournalDocument | null;
|
|
47
|
+
maxBytes?: number;
|
|
48
|
+
maxAgeMs?: number;
|
|
49
|
+
throttleMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface DraftJournal<T> {
|
|
52
|
+
read(key: string): DraftJournalEntry<T> | null;
|
|
53
|
+
write(key: string, payload: T, baseRevision?: string | null): boolean;
|
|
54
|
+
flushNow(key: string, payload: T, baseRevision?: string | null): boolean;
|
|
55
|
+
clear(key: string): void;
|
|
56
|
+
purgeExpired(): number;
|
|
57
|
+
installFlushOnLeave(flushNow: () => void): () => void;
|
|
58
|
+
}
|
|
59
|
+
export declare function createDraftJournal<T>(namespace: string, options?: DraftJournalOptions): DraftJournal<T>;
|