@widgetic/workflows 0.0.0-stage → 0.2.0
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/LICENSE +122 -0
- package/README.md +304 -2
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +168 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +109 -0
- package/dist/api/workflowsApi.js +657 -0
- package/dist/components/Workflows.svelte +131 -0
- package/dist/components/Workflows.svelte.d.ts +4 -0
- package/dist/components/WorkflowsEmptyState.svelte +32 -0
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +7 -0
- package/dist/components/WorkflowsHeader.svelte +14 -0
- package/dist/components/WorkflowsHeader.svelte.d.ts +18 -0
- package/dist/components/WorkflowsWorkspace.svelte +87 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -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/EditorBanners.svelte +143 -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/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 +185 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- 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/editorState.svelte.d.ts +220 -0
- package/dist/editor/editorState.svelte.js +713 -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/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/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/language.d.ts +22 -0
- package/dist/i18n/language.js +34 -0
- package/dist/i18n/messages.d.ts +423 -0
- package/dist/i18n/messages.js +446 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.js +35 -0
- package/package.json +103 -5
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A button of the screen. One place decides how a button looks (the palette, the corners, the focus ring), so every button
|
|
3
|
+
of the screen answers a theme the same way. The words on it are given by the caller, already in the page's language.
|
|
4
|
+
|
|
5
|
+
`iconOnly` makes it a square with a picture and no words: the caller must then give `ariaLabel`, because a picture says
|
|
6
|
+
nothing to a screen reader.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { Snippet } from 'svelte';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** How loud the button is: `primary` is the one thing to do on a screen; `danger` takes something away. */
|
|
13
|
+
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
14
|
+
size?: 'small' | 'medium';
|
|
15
|
+
type?: 'button' | 'submit';
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** For a button that stays on or off (a tab of tools, a toggle): whether it is on. */
|
|
18
|
+
pressed?: boolean;
|
|
19
|
+
/** A square button with only a picture. Needs `ariaLabel`. */
|
|
20
|
+
iconOnly?: boolean;
|
|
21
|
+
/** The name of the button for a screen reader, when it has no words of its own. */
|
|
22
|
+
ariaLabel?: string;
|
|
23
|
+
/** A tip on hover, and the name of the button when it has none. */
|
|
24
|
+
title?: string;
|
|
25
|
+
/** Whether the button opens a menu, and whether that menu is open. */
|
|
26
|
+
hasPopup?: 'menu' | 'dialog';
|
|
27
|
+
expanded?: boolean;
|
|
28
|
+
/** The element this button controls, for a screen reader. */
|
|
29
|
+
controls?: string;
|
|
30
|
+
class?: string;
|
|
31
|
+
onclick?: (event: MouseEvent) => void;
|
|
32
|
+
children: Snippet;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let {
|
|
36
|
+
variant = 'secondary',
|
|
37
|
+
size = 'medium',
|
|
38
|
+
type = 'button',
|
|
39
|
+
disabled = false,
|
|
40
|
+
pressed,
|
|
41
|
+
iconOnly = false,
|
|
42
|
+
ariaLabel,
|
|
43
|
+
title,
|
|
44
|
+
hasPopup,
|
|
45
|
+
expanded,
|
|
46
|
+
controls,
|
|
47
|
+
class: className = '',
|
|
48
|
+
onclick,
|
|
49
|
+
children
|
|
50
|
+
}: Props = $props();
|
|
51
|
+
|
|
52
|
+
const variantClasses = {
|
|
53
|
+
primary: 'bg-primary-green text-white hover:opacity-90',
|
|
54
|
+
secondary: 'border border-grey2 bg-white text-ink-primary hover:border-ink-subtle',
|
|
55
|
+
ghost: 'border border-transparent text-ink-primary hover:border-grey2',
|
|
56
|
+
danger: 'border border-error bg-white text-error hover:opacity-90'
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const sizeClasses = $derived(
|
|
60
|
+
iconOnly
|
|
61
|
+
? size === 'small'
|
|
62
|
+
? 'size-7'
|
|
63
|
+
: 'size-9'
|
|
64
|
+
: size === 'small'
|
|
65
|
+
? 'px-2.5 py-1 text-xs'
|
|
66
|
+
: 'px-4 py-2 text-sm'
|
|
67
|
+
);
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<button
|
|
71
|
+
{type}
|
|
72
|
+
{disabled}
|
|
73
|
+
{title}
|
|
74
|
+
class="inline-flex shrink-0 items-center justify-center gap-2 rounded-medium font-medium whitespace-nowrap transition-opacity focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-green disabled:cursor-not-allowed disabled:opacity-50 {variantClasses[
|
|
75
|
+
variant
|
|
76
|
+
]} {sizeClasses} {className}"
|
|
77
|
+
aria-label={ariaLabel}
|
|
78
|
+
aria-pressed={pressed}
|
|
79
|
+
aria-haspopup={hasPopup}
|
|
80
|
+
aria-expanded={expanded}
|
|
81
|
+
aria-controls={controls}
|
|
82
|
+
{onclick}
|
|
83
|
+
>
|
|
84
|
+
{@render children()}
|
|
85
|
+
</button>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** How loud the button is: `primary` is the one thing to do on a screen; `danger` takes something away. */
|
|
4
|
+
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
5
|
+
size?: 'small' | 'medium';
|
|
6
|
+
type?: 'button' | 'submit';
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** For a button that stays on or off (a tab of tools, a toggle): whether it is on. */
|
|
9
|
+
pressed?: boolean;
|
|
10
|
+
/** A square button with only a picture. Needs `ariaLabel`. */
|
|
11
|
+
iconOnly?: boolean;
|
|
12
|
+
/** The name of the button for a screen reader, when it has no words of its own. */
|
|
13
|
+
ariaLabel?: string;
|
|
14
|
+
/** A tip on hover, and the name of the button when it has none. */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** Whether the button opens a menu, and whether that menu is open. */
|
|
17
|
+
hasPopup?: 'menu' | 'dialog';
|
|
18
|
+
expanded?: boolean;
|
|
19
|
+
/** The element this button controls, for a screen reader. */
|
|
20
|
+
controls?: string;
|
|
21
|
+
class?: string;
|
|
22
|
+
onclick?: (event: MouseEvent) => void;
|
|
23
|
+
children: Snippet;
|
|
24
|
+
}
|
|
25
|
+
declare const ActionButton: import("svelte").Component<Props, {}, "">;
|
|
26
|
+
type ActionButton = ReturnType<typeof ActionButton>;
|
|
27
|
+
export default ActionButton;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A question with two answers, for a thing that cannot be taken back or that changes what visitors see. The caller says what
|
|
3
|
+
is about to happen and what the button that agrees is called; "Cancel" is always there and is where the focus starts, so
|
|
4
|
+
that an Enter pressed too quickly does not agree.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
8
|
+
import ActionButton from './ActionButton.svelte';
|
|
9
|
+
import Modal from './Modal.svelte';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
title: string;
|
|
13
|
+
/** What is about to happen, in a sentence or two. */
|
|
14
|
+
message: string;
|
|
15
|
+
/** What the button that agrees says (`Delete`, `Publish`), never a bare "OK". */
|
|
16
|
+
confirmLabel: string;
|
|
17
|
+
/** `danger` for a thing that takes something away. */
|
|
18
|
+
tone?: 'normal' | 'danger';
|
|
19
|
+
/** While the thing is being done: both buttons wait and the window cannot be dismissed. */
|
|
20
|
+
busy?: boolean;
|
|
21
|
+
onconfirm: () => void;
|
|
22
|
+
oncancel: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
title,
|
|
27
|
+
message,
|
|
28
|
+
confirmLabel,
|
|
29
|
+
tone = 'normal',
|
|
30
|
+
busy = false,
|
|
31
|
+
onconfirm,
|
|
32
|
+
oncancel
|
|
33
|
+
}: Props = $props();
|
|
34
|
+
|
|
35
|
+
const { t } = useWorkflowsLanguage();
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<Modal {title} size="small" {busy} onclose={oncancel}>
|
|
39
|
+
<p class="text-sm text-ink-primary">{message}</p>
|
|
40
|
+
{#snippet footer()}
|
|
41
|
+
<ActionButton variant="secondary" disabled={busy} onclick={oncancel}
|
|
42
|
+
>{$t('workflows.common.cancel')}</ActionButton
|
|
43
|
+
>
|
|
44
|
+
<ActionButton
|
|
45
|
+
variant={tone === 'danger' ? 'danger' : 'primary'}
|
|
46
|
+
disabled={busy}
|
|
47
|
+
onclick={onconfirm}
|
|
48
|
+
>
|
|
49
|
+
{confirmLabel}
|
|
50
|
+
</ActionButton>
|
|
51
|
+
{/snippet}
|
|
52
|
+
</Modal>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
title: string;
|
|
3
|
+
/** What is about to happen, in a sentence or two. */
|
|
4
|
+
message: string;
|
|
5
|
+
/** What the button that agrees says (`Delete`, `Publish`), never a bare "OK". */
|
|
6
|
+
confirmLabel: string;
|
|
7
|
+
/** `danger` for a thing that takes something away. */
|
|
8
|
+
tone?: 'normal' | 'danger';
|
|
9
|
+
/** While the thing is being done: both buttons wait and the window cannot be dismissed. */
|
|
10
|
+
busy?: boolean;
|
|
11
|
+
onconfirm: () => void;
|
|
12
|
+
oncancel: () => void;
|
|
13
|
+
}
|
|
14
|
+
declare const ConfirmDialog: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type ConfirmDialog = ReturnType<typeof ConfirmDialog>;
|
|
16
|
+
export default ConfirmDialog;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A small picture of the screen (see `icons.ts`). It is decoration: the control that holds it carries the words (a label or
|
|
3
|
+
a title), so a screen reader skips the picture itself.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { ICON_PATHS, type IconName } from './icons.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
name: IconName;
|
|
10
|
+
/** Extra classes, for a size other than the text's. */
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let { name, class: className = 'size-4' }: Props = $props();
|
|
15
|
+
|
|
16
|
+
const pathData = $derived(ICON_PATHS[name]);
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<svg
|
|
20
|
+
class="shrink-0 {className}"
|
|
21
|
+
viewBox="0 0 24 24"
|
|
22
|
+
fill="none"
|
|
23
|
+
stroke="currentColor"
|
|
24
|
+
stroke-width="2"
|
|
25
|
+
stroke-linecap="round"
|
|
26
|
+
stroke-linejoin="round"
|
|
27
|
+
aria-hidden="true"
|
|
28
|
+
>
|
|
29
|
+
{#each pathData as segment (segment)}
|
|
30
|
+
<path d={segment} />
|
|
31
|
+
{/each}
|
|
32
|
+
</svg>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IconName } from './icons.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
name: IconName;
|
|
4
|
+
/** Extra classes, for a size other than the text's. */
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const Icon: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type Icon = ReturnType<typeof Icon>;
|
|
9
|
+
export default Icon;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A button that opens a list of things to do. The lines come in groups, each with an optional heading; a line may carry a
|
|
3
|
+
second, quieter line under it (what it does, or why it cannot be used now).
|
|
4
|
+
|
|
5
|
+
Keyboard: Enter or Space (or the arrow down) opens it and lands on the first line; the arrows, Home and End move; Escape
|
|
6
|
+
closes it and goes back to the button; Tab leaves it. A line that cannot be used stays in the list and in the reading
|
|
7
|
+
order (`aria-disabled`) so that the reason under it is read, and choosing it does nothing.
|
|
8
|
+
|
|
9
|
+
The listeners that watch for a press outside exist only while the menu is open.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { tick } from 'svelte';
|
|
13
|
+
import ActionButton from './ActionButton.svelte';
|
|
14
|
+
import Icon from './Icon.svelte';
|
|
15
|
+
import type { IconName } from './icons.js';
|
|
16
|
+
import type { MenuGroup, MenuItem } from './types.js';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
groups: readonly MenuGroup[];
|
|
20
|
+
/** The words on the button; for a button of only a picture, its name for a screen reader. */
|
|
21
|
+
label: string;
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
iconOnly?: boolean;
|
|
24
|
+
variant?: 'primary' | 'secondary' | 'ghost';
|
|
25
|
+
size?: 'small' | 'medium';
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/** Which edge of the button the list lines up with: `end` opens it toward the start of the line, away from the edge. */
|
|
28
|
+
align?: 'start' | 'end';
|
|
29
|
+
class?: string;
|
|
30
|
+
onopen?: () => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
groups,
|
|
35
|
+
label,
|
|
36
|
+
icon,
|
|
37
|
+
iconOnly = false,
|
|
38
|
+
variant = 'secondary',
|
|
39
|
+
size = 'medium',
|
|
40
|
+
disabled = false,
|
|
41
|
+
align = 'start',
|
|
42
|
+
class: className = '',
|
|
43
|
+
onopen
|
|
44
|
+
}: Props = $props();
|
|
45
|
+
|
|
46
|
+
const menuId = $props.id();
|
|
47
|
+
|
|
48
|
+
let isOpen = $state(false);
|
|
49
|
+
let rootElement = $state<HTMLDivElement>();
|
|
50
|
+
let menuElement = $state<HTMLDivElement>();
|
|
51
|
+
|
|
52
|
+
/** The lines that can be reached with the arrows. */
|
|
53
|
+
function listItemButtons(): HTMLButtonElement[] {
|
|
54
|
+
return menuElement
|
|
55
|
+
? [...menuElement.querySelectorAll<HTMLButtonElement>('[role="menuitem"]')]
|
|
56
|
+
: [];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function open(landOn: 'first' | 'last' = 'first'): Promise<void> {
|
|
60
|
+
if (disabled) return;
|
|
61
|
+
isOpen = true;
|
|
62
|
+
onopen?.();
|
|
63
|
+
await tick();
|
|
64
|
+
const buttons = listItemButtons();
|
|
65
|
+
(landOn === 'last' ? buttons[buttons.length - 1] : buttons[0])?.focus();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Opens the list from outside (a shortcut key of the screen). */
|
|
69
|
+
export function openMenu(): void {
|
|
70
|
+
void open('first');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The button that opens the menu: the first button of the root, before the lines of the list. */
|
|
74
|
+
function findTriggerButton(): HTMLButtonElement | null {
|
|
75
|
+
return rootElement?.querySelector<HTMLButtonElement>(':scope > button') ?? null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function close(returnFocus: boolean): void {
|
|
79
|
+
if (!isOpen) return;
|
|
80
|
+
isOpen = false;
|
|
81
|
+
if (returnFocus) findTriggerButton()?.focus();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toggle(): void {
|
|
85
|
+
if (isOpen) close(false);
|
|
86
|
+
else void open();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function choose(item: MenuItem): void {
|
|
90
|
+
if (item.disabled) return;
|
|
91
|
+
close(true);
|
|
92
|
+
item.onSelect();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The arrows on the button open the list, landing on its first or its last line. */
|
|
96
|
+
function handleTriggerKeydown(event: KeyboardEvent): void {
|
|
97
|
+
if (event.target !== findTriggerButton()) return;
|
|
98
|
+
if (event.key === 'ArrowDown') {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
void open('first');
|
|
101
|
+
} else if (event.key === 'ArrowUp') {
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
void open('last');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function handleMenuKeydown(event: KeyboardEvent): void {
|
|
108
|
+
const buttons = listItemButtons();
|
|
109
|
+
const position = buttons.findIndex(
|
|
110
|
+
(button) => button === (event.target as Element).closest('[role="menuitem"]')
|
|
111
|
+
);
|
|
112
|
+
let nextPosition: number | null = null;
|
|
113
|
+
if (event.key === 'ArrowDown') nextPosition = (position + 1) % buttons.length;
|
|
114
|
+
else if (event.key === 'ArrowUp')
|
|
115
|
+
nextPosition = (position - 1 + buttons.length) % buttons.length;
|
|
116
|
+
else if (event.key === 'Home') nextPosition = 0;
|
|
117
|
+
else if (event.key === 'End') nextPosition = buttons.length - 1;
|
|
118
|
+
else if (event.key === 'Escape') {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
close(true);
|
|
122
|
+
return;
|
|
123
|
+
} else if (event.key === 'Tab') {
|
|
124
|
+
close(false);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (nextPosition !== null) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
buttons[nextPosition]?.focus();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// A press outside closes the menu. The listener lives only while the menu is open, and looks at the whole path of the
|
|
134
|
+
// event, because a press inside a shadow root is reported to the page as a press on the shadow's host.
|
|
135
|
+
$effect(() => {
|
|
136
|
+
if (!isOpen) return;
|
|
137
|
+
const closeOnOutsidePress = (event: Event) => {
|
|
138
|
+
if (rootElement && !event.composedPath().includes(rootElement)) isOpen = false;
|
|
139
|
+
};
|
|
140
|
+
document.addEventListener('pointerdown', closeOnOutsidePress, true);
|
|
141
|
+
return () => document.removeEventListener('pointerdown', closeOnOutsidePress, true);
|
|
142
|
+
});
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<!-- The arrows are handled for the button inside; the root itself is not something a person operates. -->
|
|
146
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
147
|
+
<div
|
|
148
|
+
bind:this={rootElement}
|
|
149
|
+
class="relative inline-block text-start {className}"
|
|
150
|
+
onkeydown={handleTriggerKeydown}
|
|
151
|
+
>
|
|
152
|
+
<ActionButton
|
|
153
|
+
{variant}
|
|
154
|
+
{size}
|
|
155
|
+
{disabled}
|
|
156
|
+
{iconOnly}
|
|
157
|
+
ariaLabel={iconOnly ? label : undefined}
|
|
158
|
+
title={iconOnly ? label : undefined}
|
|
159
|
+
hasPopup="menu"
|
|
160
|
+
expanded={isOpen}
|
|
161
|
+
controls={menuId}
|
|
162
|
+
onclick={toggle}
|
|
163
|
+
>
|
|
164
|
+
{#if icon}<Icon name={icon} />{/if}
|
|
165
|
+
{#if !iconOnly}{label}{/if}
|
|
166
|
+
</ActionButton>
|
|
167
|
+
|
|
168
|
+
{#if isOpen}
|
|
169
|
+
<div
|
|
170
|
+
bind:this={menuElement}
|
|
171
|
+
id={menuId}
|
|
172
|
+
role="menu"
|
|
173
|
+
tabindex="-1"
|
|
174
|
+
class="absolute z-30 mt-1 flex max-h-[min(30rem,70vh)] min-w-56 max-w-80 flex-col gap-1 overflow-auto rounded-large border border-grey2 bg-white p-1 shadow-lg {align ===
|
|
175
|
+
'end'
|
|
176
|
+
? 'end-0'
|
|
177
|
+
: 'start-0'}"
|
|
178
|
+
onkeydown={handleMenuKeydown}
|
|
179
|
+
>
|
|
180
|
+
{#each groups as group (group.key)}
|
|
181
|
+
<div role="group" aria-label={group.heading} class="flex flex-col">
|
|
182
|
+
{#if group.heading}
|
|
183
|
+
<p class="px-3 pt-2 pb-1 text-xs font-medium text-ink-muted" aria-hidden="true">
|
|
184
|
+
{group.heading}
|
|
185
|
+
</p>
|
|
186
|
+
{/if}
|
|
187
|
+
{#each group.items as item (item.key)}
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
role="menuitem"
|
|
191
|
+
aria-disabled={item.disabled ? true : undefined}
|
|
192
|
+
class="flex w-full items-start gap-2 rounded-medium border border-transparent px-3 py-2 text-start text-sm hover:border-grey2 focus-visible:border-primary-green focus-visible:outline-none {item.tone ===
|
|
193
|
+
'danger'
|
|
194
|
+
? 'text-error'
|
|
195
|
+
: 'text-ink-primary'}"
|
|
196
|
+
onclick={() => choose(item)}
|
|
197
|
+
>
|
|
198
|
+
{#if item.icon}<Icon name={item.icon} class="mt-0.5 size-4" />{/if}
|
|
199
|
+
<span class="flex min-w-0 flex-col">
|
|
200
|
+
<span class={item.disabled ? 'opacity-60' : ''}>{item.label}</span>
|
|
201
|
+
{#if item.description}
|
|
202
|
+
<span class="text-xs text-ink-muted">{item.description}</span>
|
|
203
|
+
{/if}
|
|
204
|
+
</span>
|
|
205
|
+
</button>
|
|
206
|
+
{/each}
|
|
207
|
+
</div>
|
|
208
|
+
{/each}
|
|
209
|
+
</div>
|
|
210
|
+
{/if}
|
|
211
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IconName } from './icons.js';
|
|
2
|
+
import type { MenuGroup } from './types.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
groups: readonly MenuGroup[];
|
|
5
|
+
/** The words on the button; for a button of only a picture, its name for a screen reader. */
|
|
6
|
+
label: string;
|
|
7
|
+
icon?: IconName;
|
|
8
|
+
iconOnly?: boolean;
|
|
9
|
+
variant?: 'primary' | 'secondary' | 'ghost';
|
|
10
|
+
size?: 'small' | 'medium';
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Which edge of the button the list lines up with: `end` opens it toward the start of the line, away from the edge. */
|
|
13
|
+
align?: 'start' | 'end';
|
|
14
|
+
class?: string;
|
|
15
|
+
onopen?: () => void;
|
|
16
|
+
}
|
|
17
|
+
declare const Menu: import("svelte").Component<Props, {
|
|
18
|
+
openMenu: () => void;
|
|
19
|
+
}, "">;
|
|
20
|
+
type Menu = ReturnType<typeof Menu>;
|
|
21
|
+
export default Menu;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A window over the screen, for a question that must be answered or a thing that must be read before going on.
|
|
3
|
+
|
|
4
|
+
While it is open: the keyboard stays inside it (Tab goes round), Escape and a click on the dim part behind it close it, a
|
|
5
|
+
screen reader is told it is a dialog with a title, and when it closes the focus goes back to what had it before.
|
|
6
|
+
|
|
7
|
+
It is drawn in place (fixed over the element the screen is in) and not carried to the end of the page, so it is inside
|
|
8
|
+
the screen's own language, direction and styles wherever the screen is mounted, in a shadow root too.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { onMount, type Snippet } from 'svelte';
|
|
12
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
13
|
+
import ActionButton from './ActionButton.svelte';
|
|
14
|
+
import Icon from './Icon.svelte';
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
title: string;
|
|
18
|
+
onclose: () => void;
|
|
19
|
+
size?: 'small' | 'medium' | 'large';
|
|
20
|
+
/** While something is being done, the window cannot be dismissed by accident. */
|
|
21
|
+
busy?: boolean;
|
|
22
|
+
children: Snippet;
|
|
23
|
+
footer?: Snippet;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let { title, onclose, size = 'medium', busy = false, children, footer }: Props = $props();
|
|
27
|
+
|
|
28
|
+
const { t } = useWorkflowsLanguage();
|
|
29
|
+
const titleId = $props.id();
|
|
30
|
+
|
|
31
|
+
const FOCUSABLE_SELECTOR =
|
|
32
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
33
|
+
|
|
34
|
+
const widthClasses = { small: 'max-w-sm', medium: 'max-w-lg', large: 'max-w-3xl' };
|
|
35
|
+
|
|
36
|
+
let dialogElement = $state<HTMLDivElement>();
|
|
37
|
+
|
|
38
|
+
/** The element that has the focus now, looking into the shadow root the window is in. */
|
|
39
|
+
function readFocusedElement(): Element | null {
|
|
40
|
+
const root = dialogElement?.getRootNode();
|
|
41
|
+
return root instanceof ShadowRoot || root instanceof Document ? root.activeElement : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function requestClose(): void {
|
|
45
|
+
if (!busy) onclose();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Keeps Tab inside the window and closes it on Escape. */
|
|
49
|
+
function handleKeydown(event: KeyboardEvent): void {
|
|
50
|
+
if (event.key === 'Escape') {
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
requestClose();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (event.key !== 'Tab' || !dialogElement) return;
|
|
56
|
+
const focusable = [...dialogElement.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)];
|
|
57
|
+
if (focusable.length === 0) {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
dialogElement.focus();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const first = focusable[0];
|
|
63
|
+
const last = focusable[focusable.length - 1];
|
|
64
|
+
const focused = readFocusedElement();
|
|
65
|
+
if (event.shiftKey && (focused === first || focused === dialogElement)) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
last.focus();
|
|
68
|
+
} else if (!event.shiftKey && focused === last) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
first.focus();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A press on the dim part behind the window (and not one that started inside it and ended outside) closes it. */
|
|
75
|
+
function handleBackdropPress(event: MouseEvent): void {
|
|
76
|
+
if (event.target === event.currentTarget) requestClose();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onMount(() => {
|
|
80
|
+
const focusedBefore = readFocusedElement();
|
|
81
|
+
// A field that asked for the focus (autofocus) has it by now; otherwise the window itself takes it.
|
|
82
|
+
if (!dialogElement?.contains(readFocusedElement())) dialogElement?.focus();
|
|
83
|
+
return () => {
|
|
84
|
+
if (focusedBefore instanceof HTMLElement && focusedBefore.isConnected) focusedBefore.focus();
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<!-- The dim part is a mouse convenience: the keyboard has Escape, handled on the window itself. -->
|
|
90
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
91
|
+
<div
|
|
92
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-ink-primary/40 p-4"
|
|
93
|
+
onmousedown={handleBackdropPress}
|
|
94
|
+
>
|
|
95
|
+
<div
|
|
96
|
+
bind:this={dialogElement}
|
|
97
|
+
role="dialog"
|
|
98
|
+
aria-modal="true"
|
|
99
|
+
aria-labelledby={titleId}
|
|
100
|
+
tabindex="-1"
|
|
101
|
+
class="flex max-h-full w-full flex-col overflow-hidden rounded-large border border-grey2 bg-white text-start text-ink-primary shadow-lg focus:outline-none {widthClasses[
|
|
102
|
+
size
|
|
103
|
+
]}"
|
|
104
|
+
onkeydown={handleKeydown}
|
|
105
|
+
>
|
|
106
|
+
<header class="flex items-start justify-between gap-3 border-b border-grey2 px-5 py-4">
|
|
107
|
+
<h2 id={titleId} class="text-base font-semibold">{title}</h2>
|
|
108
|
+
<ActionButton
|
|
109
|
+
variant="ghost"
|
|
110
|
+
size="small"
|
|
111
|
+
iconOnly
|
|
112
|
+
disabled={busy}
|
|
113
|
+
ariaLabel={$t('workflows.common.close')}
|
|
114
|
+
title={$t('workflows.common.close')}
|
|
115
|
+
onclick={requestClose}
|
|
116
|
+
>
|
|
117
|
+
<Icon name="close" />
|
|
118
|
+
</ActionButton>
|
|
119
|
+
</header>
|
|
120
|
+
<div class="min-h-0 flex-1 overflow-auto px-5 py-4">
|
|
121
|
+
{@render children()}
|
|
122
|
+
</div>
|
|
123
|
+
{#if footer}
|
|
124
|
+
<footer class="flex flex-wrap items-center justify-end gap-2 border-t border-grey2 px-5 py-3">
|
|
125
|
+
{@render footer()}
|
|
126
|
+
</footer>
|
|
127
|
+
{/if}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
title: string;
|
|
4
|
+
onclose: () => void;
|
|
5
|
+
size?: 'small' | 'medium' | 'large';
|
|
6
|
+
/** While something is being done, the window cannot be dismissed by accident. */
|
|
7
|
+
busy?: boolean;
|
|
8
|
+
children: Snippet;
|
|
9
|
+
footer?: Snippet;
|
|
10
|
+
}
|
|
11
|
+
declare const Modal: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type Modal = ReturnType<typeof Modal>;
|
|
13
|
+
export default Modal;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A line that tells the person how something went, or what to do about it: a failed save, a draft with changes, a reason a
|
|
3
|
+
choice is off. A problem is announced to a screen reader as soon as it appears (`role="alert"`); the rest is read in
|
|
4
|
+
its turn (`role="status"`).
|
|
5
|
+
|
|
6
|
+
It has no fill (the palette's muted ink does not read on a grey), only a border and, for the tone, the colour of the
|
|
7
|
+
words that are the problem. An action may sit at its end, e.g. "Reload" next to "This workflow was changed elsewhere".
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { Snippet } from 'svelte';
|
|
11
|
+
import Icon from './Icon.svelte';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
tone?: 'info' | 'problem';
|
|
15
|
+
/** The action at the end of the line, if there is one. */
|
|
16
|
+
action?: Snippet;
|
|
17
|
+
class?: string;
|
|
18
|
+
children: Snippet;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let { tone = 'info', action, class: className = '', children }: Props = $props();
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div
|
|
25
|
+
role={tone === 'problem' ? 'alert' : 'status'}
|
|
26
|
+
class="flex items-start gap-3 rounded-medium border bg-white px-3 py-2 text-start text-sm {tone ===
|
|
27
|
+
'problem'
|
|
28
|
+
? 'border-error text-error'
|
|
29
|
+
: 'border-grey2 text-ink-primary'} {className}"
|
|
30
|
+
>
|
|
31
|
+
{#if tone === 'problem'}<Icon name="warning" class="mt-0.5 size-4" />{/if}
|
|
32
|
+
<div class="min-w-0 flex-1">{@render children()}</div>
|
|
33
|
+
{#if action}
|
|
34
|
+
<div class="flex shrink-0 items-center gap-2">{@render action()}</div>
|
|
35
|
+
{/if}
|
|
36
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
tone?: 'info' | 'problem';
|
|
4
|
+
/** The action at the end of the line, if there is one. */
|
|
5
|
+
action?: Snippet;
|
|
6
|
+
class?: string;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
}
|
|
9
|
+
declare const Notice: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type Notice = ReturnType<typeof Notice>;
|
|
11
|
+
export default Notice;
|