@glimstone/svelte 0.0.0-stage → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/AboutCard.svelte +87 -0
- package/dist/AboutCard.svelte.d.ts +37 -0
- package/dist/Accordion.svelte +60 -0
- package/dist/Accordion.svelte.d.ts +38 -0
- package/dist/AngleSlider.svelte +56 -0
- package/dist/AngleSlider.svelte.d.ts +13 -0
- package/dist/Avatar.svelte +37 -0
- package/dist/Avatar.svelte.d.ts +13 -0
- package/dist/Badge.svelte +119 -0
- package/dist/Badge.svelte.d.ts +54 -0
- package/dist/BrandMark.svelte +12 -0
- package/dist/BrandMark.svelte.d.ts +6 -0
- package/dist/BusyRing.svelte +39 -0
- package/dist/BusyRing.svelte.d.ts +15 -0
- package/dist/Button.svelte +172 -0
- package/dist/Button.svelte.d.ts +57 -0
- package/dist/Card.svelte +61 -0
- package/dist/Card.svelte.d.ts +23 -0
- package/dist/Carousel.svelte +72 -0
- package/dist/Carousel.svelte.d.ts +41 -0
- package/dist/Checkbox.svelte +48 -0
- package/dist/Checkbox.svelte.d.ts +17 -0
- package/dist/CoffeeDialog.svelte +70 -0
- package/dist/CoffeeDialog.svelte.d.ts +18 -0
- package/dist/Collapsible.svelte +49 -0
- package/dist/Collapsible.svelte.d.ts +14 -0
- package/dist/ColorPicker.svelte +122 -0
- package/dist/ColorPicker.svelte.d.ts +23 -0
- package/dist/Combobox.svelte +87 -0
- package/dist/Combobox.svelte.d.ts +18 -0
- package/dist/ConfirmDialog.svelte +106 -0
- package/dist/ConfirmDialog.svelte.d.ts +31 -0
- package/dist/ConfirmHost.svelte +41 -0
- package/dist/ConfirmHost.svelte.d.ts +7 -0
- package/dist/ContextMenu.svelte +213 -0
- package/dist/ContextMenu.svelte.d.ts +29 -0
- package/dist/CopyField.svelte +60 -0
- package/dist/CopyField.svelte.d.ts +19 -0
- package/dist/CryptoDonateDialog.svelte +162 -0
- package/dist/CryptoDonateDialog.svelte.d.ts +37 -0
- package/dist/DatePicker.svelte +149 -0
- package/dist/DatePicker.svelte.d.ts +18 -0
- package/dist/DropdownListbox.svelte +178 -0
- package/dist/DropdownListbox.svelte.d.ts +23 -0
- package/dist/EmptyState.svelte +31 -0
- package/dist/EmptyState.svelte.d.ts +16 -0
- package/dist/FieldError.svelte +20 -0
- package/dist/FieldError.svelte.d.ts +8 -0
- package/dist/FieldRow.svelte +52 -0
- package/dist/FieldRow.svelte.d.ts +23 -0
- package/dist/FieldRowGroup.svelte +33 -0
- package/dist/FieldRowGroup.svelte.d.ts +13 -0
- package/dist/FileUpload.svelte +74 -0
- package/dist/FileUpload.svelte.d.ts +18 -0
- package/dist/FloatingPanel.svelte +89 -0
- package/dist/FloatingPanel.svelte.d.ts +17 -0
- package/dist/Fortress.svelte +222 -0
- package/dist/Fortress.svelte.d.ts +62 -0
- package/dist/FortressAppCard.svelte +115 -0
- package/dist/FortressAppCard.svelte.d.ts +18 -0
- package/dist/FortressDoubtWindow.svelte +37 -0
- package/dist/FortressDoubtWindow.svelte.d.ts +12 -0
- package/dist/FortressPairing.svelte +85 -0
- package/dist/FortressPairing.svelte.d.ts +32 -0
- package/dist/FortressPermissions.svelte +93 -0
- package/dist/FortressPermissions.svelte.d.ts +24 -0
- package/dist/FortressStatusWindow.svelte +128 -0
- package/dist/FortressStatusWindow.svelte.d.ts +20 -0
- package/dist/FortressWindow.svelte +271 -0
- package/dist/FortressWindow.svelte.d.ts +18 -0
- package/dist/GlyphField.svelte +52 -0
- package/dist/GlyphField.svelte.d.ts +20 -0
- package/dist/GlyphTile.svelte +25 -0
- package/dist/GlyphTile.svelte.d.ts +14 -0
- package/dist/HoverCard.svelte +47 -0
- package/dist/HoverCard.svelte.d.ts +14 -0
- package/dist/IconButton.svelte +49 -0
- package/dist/IconButton.svelte.d.ts +20 -0
- package/dist/IconTipButton.svelte +67 -0
- package/dist/IconTipButton.svelte.d.ts +23 -0
- package/dist/InfoAboutCard.svelte +65 -0
- package/dist/InfoAboutCard.svelte.d.ts +35 -0
- package/dist/InfoBubble.svelte +50 -0
- package/dist/InfoBubble.svelte.d.ts +7 -0
- package/dist/InfoHelpCard.svelte +93 -0
- package/dist/InfoHelpCard.svelte.d.ts +44 -0
- package/dist/InfoTile.svelte +31 -0
- package/dist/InfoTile.svelte.d.ts +15 -0
- package/dist/InfoVersionCard.svelte +99 -0
- package/dist/InfoVersionCard.svelte.d.ts +29 -0
- package/dist/InstanceCard.svelte +85 -0
- package/dist/InstanceCard.svelte.d.ts +27 -0
- package/dist/Kbd.svelte +16 -0
- package/dist/Kbd.svelte.d.ts +8 -0
- package/dist/ListRow.svelte +51 -0
- package/dist/ListRow.svelte.d.ts +19 -0
- package/dist/ListSelect.svelte +135 -0
- package/dist/ListSelect.svelte.d.ts +25 -0
- package/dist/ListTable.svelte +183 -0
- package/dist/ListTable.svelte.d.ts +44 -0
- package/dist/MarkSvg.svelte +9 -0
- package/dist/MarkSvg.svelte.d.ts +8 -0
- package/dist/Marquee.svelte +63 -0
- package/dist/Marquee.svelte.d.ts +39 -0
- package/dist/MenuBar.svelte +98 -0
- package/dist/MenuBar.svelte.d.ts +19 -0
- package/dist/MenuChoice.svelte +30 -0
- package/dist/MenuChoice.svelte.d.ts +33 -0
- package/dist/MenuHeadEdit.svelte +29 -0
- package/dist/MenuHeadEdit.svelte.d.ts +10 -0
- package/dist/MenuRows.svelte +57 -0
- package/dist/MenuRows.svelte.d.ts +9 -0
- package/dist/MenuSelect.svelte +145 -0
- package/dist/MenuSelect.svelte.d.ts +25 -0
- package/dist/MenuSubmenu.svelte +64 -0
- package/dist/MenuSubmenu.svelte.d.ts +37 -0
- package/dist/Meter.svelte +55 -0
- package/dist/Meter.svelte.d.ts +20 -0
- package/dist/NumberField.svelte +70 -0
- package/dist/NumberField.svelte.d.ts +23 -0
- package/dist/Pagination.svelte +62 -0
- package/dist/Pagination.svelte.d.ts +16 -0
- package/dist/PasswordField.svelte +69 -0
- package/dist/PasswordField.svelte.d.ts +21 -0
- package/dist/PathField.svelte +111 -0
- package/dist/PathField.svelte.d.ts +33 -0
- package/dist/PaypalDialog.svelte +174 -0
- package/dist/PaypalDialog.svelte.d.ts +54 -0
- package/dist/Pill.svelte +25 -0
- package/dist/Pill.svelte.d.ts +14 -0
- package/dist/PinInput.svelte +81 -0
- package/dist/PinInput.svelte.d.ts +23 -0
- package/dist/Popover.svelte +38 -0
- package/dist/Popover.svelte.d.ts +16 -0
- package/dist/PresenceBadges.svelte +22 -0
- package/dist/PresenceBadges.svelte.d.ts +8 -0
- package/dist/ProgressBar.svelte +37 -0
- package/dist/ProgressBar.svelte.d.ts +16 -0
- package/dist/Rating.svelte +65 -0
- package/dist/Rating.svelte.d.ts +18 -0
- package/dist/ReadmeButton.svelte +82 -0
- package/dist/ReadmeButton.svelte.d.ts +27 -0
- package/dist/RowMark.svelte +16 -0
- package/dist/RowMark.svelte.d.ts +7 -0
- package/dist/ScrollArea.svelte +46 -0
- package/dist/ScrollArea.svelte.d.ts +11 -0
- package/dist/Select.svelte +97 -0
- package/dist/Select.svelte.d.ts +67 -0
- package/dist/SelectFace.svelte +18 -0
- package/dist/SelectFace.svelte.d.ts +32 -0
- package/dist/Selector.svelte +264 -0
- package/dist/Selector.svelte.d.ts +77 -0
- package/dist/SelectorSegment.svelte +159 -0
- package/dist/SelectorSegment.svelte.d.ts +27 -0
- package/dist/Sheet.svelte +51 -0
- package/dist/Sheet.svelte.d.ts +23 -0
- package/dist/SidebarRow.svelte +91 -0
- package/dist/SidebarRow.svelte.d.ts +31 -0
- package/dist/SignInCard.svelte +251 -0
- package/dist/SignInCard.svelte.d.ts +34 -0
- package/dist/SignInField.svelte +32 -0
- package/dist/SignInField.svelte.d.ts +11 -0
- package/dist/SignaturePad.svelte +72 -0
- package/dist/SignaturePad.svelte.d.ts +13 -0
- package/dist/SkeletonRow.svelte +29 -0
- package/dist/SkeletonRow.svelte.d.ts +12 -0
- package/dist/Slider.svelte +60 -0
- package/dist/Slider.svelte.d.ts +15 -0
- package/dist/Splitter.svelte +59 -0
- package/dist/Splitter.svelte.d.ts +37 -0
- package/dist/Steps.svelte +90 -0
- package/dist/Steps.svelte.d.ts +40 -0
- package/dist/SubCard.svelte +45 -0
- package/dist/SubCard.svelte.d.ts +14 -0
- package/dist/Table.svelte +48 -0
- package/dist/Table.svelte.d.ts +37 -0
- package/dist/TagsInput.svelte +77 -0
- package/dist/TagsInput.svelte.d.ts +18 -0
- package/dist/TextArea.svelte +55 -0
- package/dist/TextArea.svelte.d.ts +17 -0
- package/dist/TextField.svelte +61 -0
- package/dist/TextField.svelte.d.ts +18 -0
- package/dist/Timer.svelte +62 -0
- package/dist/Timer.svelte.d.ts +17 -0
- package/dist/TipBubble.svelte +11 -0
- package/dist/TipBubble.svelte.d.ts +7 -0
- package/dist/TipWrap.svelte +15 -0
- package/dist/TipWrap.svelte.d.ts +10 -0
- package/dist/ToastCard.svelte +68 -0
- package/dist/ToastCard.svelte.d.ts +18 -0
- package/dist/ToastViewport.svelte +65 -0
- package/dist/ToastViewport.svelte.d.ts +14 -0
- package/dist/Toggle.svelte +84 -0
- package/dist/Toggle.svelte.d.ts +25 -0
- package/dist/Tour.svelte +75 -0
- package/dist/Tour.svelte.d.ts +12 -0
- package/dist/Tree.svelte +122 -0
- package/dist/Tree.svelte.d.ts +22 -0
- package/dist/UnavailableNotice.svelte +36 -0
- package/dist/UnavailableNotice.svelte.d.ts +18 -0
- package/dist/Window.svelte +108 -0
- package/dist/Window.svelte.d.ts +33 -0
- package/dist/WindowBar.svelte +76 -0
- package/dist/WindowBar.svelte.d.ts +26 -0
- package/dist/WindowFootRow.svelte +67 -0
- package/dist/WindowFootRow.svelte.d.ts +28 -0
- package/dist/bubble.svelte.d.ts +15 -0
- package/dist/bubble.svelte.js +66 -0
- package/dist/confirm.svelte.d.ts +37 -0
- package/dist/confirm.svelte.js +62 -0
- package/dist/engines.svelte.d.ts +18 -0
- package/dist/engines.svelte.js +57 -0
- package/dist/entries/accordion.d.ts +1 -0
- package/dist/entries/accordion.js +2 -0
- package/dist/entries/angleslider.d.ts +1 -0
- package/dist/entries/angleslider.js +2 -0
- package/dist/entries/avatar.d.ts +1 -0
- package/dist/entries/avatar.js +2 -0
- package/dist/entries/carousel.d.ts +1 -0
- package/dist/entries/carousel.js +2 -0
- package/dist/entries/collapsible.d.ts +1 -0
- package/dist/entries/collapsible.js +2 -0
- package/dist/entries/combobox.d.ts +1 -0
- package/dist/entries/combobox.js +2 -0
- package/dist/entries/datepicker.d.ts +1 -0
- package/dist/entries/datepicker.js +2 -0
- package/dist/entries/fileupload.d.ts +1 -0
- package/dist/entries/fileupload.js +2 -0
- package/dist/entries/floatingpanel.d.ts +1 -0
- package/dist/entries/floatingpanel.js +2 -0
- package/dist/entries/hovercard.d.ts +1 -0
- package/dist/entries/hovercard.js +2 -0
- package/dist/entries/marquee.d.ts +1 -0
- package/dist/entries/marquee.js +2 -0
- package/dist/entries/pagination.d.ts +1 -0
- package/dist/entries/pagination.js +2 -0
- package/dist/entries/pininput.d.ts +1 -0
- package/dist/entries/pininput.js +2 -0
- package/dist/entries/rating.d.ts +1 -0
- package/dist/entries/rating.js +2 -0
- package/dist/entries/scrollarea.d.ts +1 -0
- package/dist/entries/scrollarea.js +2 -0
- package/dist/entries/select.d.ts +1 -0
- package/dist/entries/select.js +2 -0
- package/dist/entries/signaturepad.d.ts +1 -0
- package/dist/entries/signaturepad.js +2 -0
- package/dist/entries/slider.d.ts +1 -0
- package/dist/entries/slider.js +2 -0
- package/dist/entries/splitter.d.ts +1 -0
- package/dist/entries/splitter.js +2 -0
- package/dist/entries/steps.d.ts +1 -0
- package/dist/entries/steps.js +2 -0
- package/dist/entries/tagsinput.d.ts +1 -0
- package/dist/entries/tagsinput.js +2 -0
- package/dist/entries/timer.d.ts +1 -0
- package/dist/entries/timer.js +2 -0
- package/dist/entries/tour.d.ts +1 -0
- package/dist/entries/tour.js +2 -0
- package/dist/fieldName.d.ts +4 -0
- package/dist/fieldName.js +9 -0
- package/dist/fortressParts.d.ts +5 -0
- package/dist/fortressParts.js +16 -0
- package/dist/glyphs.d.ts +32 -0
- package/dist/glyphs.js +47 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +77 -0
- package/dist/lift.d.ts +5 -0
- package/dist/lift.js +9 -0
- package/dist/portalHue.svelte.d.ts +9 -0
- package/dist/portalHue.svelte.js +16 -0
- package/dist/selectParts.svelte.d.ts +39 -0
- package/dist/selectParts.svelte.js +28 -0
- package/dist/selectorItem.d.ts +22 -0
- package/dist/selectorItem.js +1 -0
- package/dist/style.d.ts +5 -0
- package/dist/style.js +12 -0
- package/dist/useDragArmed.svelte.d.ts +6 -0
- package/dist/useDragArmed.svelte.js +24 -0
- package/dist/usePaypalButtons.svelte.d.ts +18 -0
- package/dist/usePaypalButtons.svelte.js +41 -0
- package/package.json +173 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ColorName, ColorPickerPanelText } from "@glimstone/core";
|
|
3
|
+
|
|
4
|
+
export type { ColorName, ColorPickerPanelText } from "@glimstone/core";
|
|
5
|
+
|
|
6
|
+
export interface ColorPickerProps {
|
|
7
|
+
/** The colour the picker starts from, as `#rrggbb`. */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Apply or Enter, with the colour and the name it proposes. */
|
|
10
|
+
onApply: (hex: string, name: string | null) => void;
|
|
11
|
+
/** Every step of a drag, a key or a valid hex, for a live preview. */
|
|
12
|
+
onInput?: (hex: string) => void;
|
|
13
|
+
/** The control that opened the picker. With it the picker floats beside it
|
|
14
|
+
* and closes on Escape, on a click beside it and after Apply. */
|
|
15
|
+
anchor?: HTMLElement | null;
|
|
16
|
+
/** Called when a floating picker closes, however it closes. */
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
/** The names a colour is matched against, nearest in OKLab. `false` shows none. */
|
|
19
|
+
names?: readonly ColorName[] | false;
|
|
20
|
+
/** The words, read when the picker opens. */
|
|
21
|
+
text?: Partial<ColorPickerPanelText>;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { COLOR_NAMES_DE, COLOR_PICKER_TEXT, colorPicker, floatColorPicker, nearestColorName, normalizeHex } from "@glimstone/core";
|
|
28
|
+
import Button from "./Button.svelte";
|
|
29
|
+
import { IconCheck } from "./glyphs.js";
|
|
30
|
+
import { lift } from "./lift.js";
|
|
31
|
+
|
|
32
|
+
// The colour picker as a component: the core's square and hue bar, a preview
|
|
33
|
+
// with the name the colour proposes, the hex field and Apply. Nothing changes
|
|
34
|
+
// until Apply, so a caller can show the colour live through onInput and still
|
|
35
|
+
// keep the old one when the picker closes without it.
|
|
36
|
+
let { value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, text, class: className }: ColorPickerProps = $props();
|
|
37
|
+
|
|
38
|
+
// The words and the colour are read once, when the picker opens.
|
|
39
|
+
// svelte-ignore state_referenced_locally
|
|
40
|
+
const words = { ...COLOR_PICKER_TEXT, ...text };
|
|
41
|
+
// svelte-ignore state_referenced_locally
|
|
42
|
+
const start = normalizeHex(value) ?? "#000000";
|
|
43
|
+
let draft = $state(start);
|
|
44
|
+
let typed = $state(start);
|
|
45
|
+
const widget = colorPicker(
|
|
46
|
+
start,
|
|
47
|
+
(hex) => {
|
|
48
|
+
draft = hex;
|
|
49
|
+
typed = hex;
|
|
50
|
+
onInput?.(hex);
|
|
51
|
+
},
|
|
52
|
+
{ text: words },
|
|
53
|
+
);
|
|
54
|
+
let panel: HTMLDivElement;
|
|
55
|
+
let host: HTMLDivElement;
|
|
56
|
+
|
|
57
|
+
$effect(() => {
|
|
58
|
+
host.appendChild(widget.el);
|
|
59
|
+
return () => widget.el.remove();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
$effect.pre(() => {
|
|
63
|
+
const hex = normalizeHex(value);
|
|
64
|
+
if (!hex) return;
|
|
65
|
+
draft = hex;
|
|
66
|
+
typed = hex;
|
|
67
|
+
widget.setValue(hex);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
$effect(() => {
|
|
71
|
+
if (!anchor) return;
|
|
72
|
+
const done = floatColorPicker(panel, anchor, () => onClose?.());
|
|
73
|
+
widget.focus();
|
|
74
|
+
return done;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const name = $derived(names === false ? null : nearestColorName(draft, names));
|
|
78
|
+
|
|
79
|
+
function apply() {
|
|
80
|
+
onApply(draft, name);
|
|
81
|
+
if (anchor) {
|
|
82
|
+
anchor.focus();
|
|
83
|
+
onClose?.();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
88
|
+
if (e.key === "Enter" && !(e.target instanceof HTMLButtonElement)) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
apply();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onTyped(e: Event & { currentTarget: HTMLInputElement }) {
|
|
95
|
+
typed = e.currentTarget.value;
|
|
96
|
+
const hex = normalizeHex(typed);
|
|
97
|
+
if (!hex) return;
|
|
98
|
+
draft = hex;
|
|
99
|
+
widget.setValue(hex);
|
|
100
|
+
onInput?.(hex);
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
105
|
+
<div
|
|
106
|
+
{@attach anchor ? lift : undefined}
|
|
107
|
+
data-glim="ColorPicker"
|
|
108
|
+
bind:this={panel}
|
|
109
|
+
class={["glim-picker-panel", anchor && "glim-picker-panel--float", className].filter(Boolean).join(" ")}
|
|
110
|
+
style:--glim-picker-colour={draft}
|
|
111
|
+
onkeydown={onKeyDown}
|
|
112
|
+
>
|
|
113
|
+
<div bind:this={host} style="display: contents"></div>
|
|
114
|
+
<div class="glim-picker-foot">
|
|
115
|
+
<span class="glim-picker-swatch" aria-hidden="true"></span>
|
|
116
|
+
{#if name !== null}<span class="glim-picker-name">{name}</span>{/if}
|
|
117
|
+
<input class="glim-picker-hex" value={typed} maxlength={7} spellcheck={false} aria-label={words.hex} oninput={onTyped} />
|
|
118
|
+
</div>
|
|
119
|
+
<div class="glim-picker-actions">
|
|
120
|
+
<Button label={words.apply} labelKey="apply" glyph={IconCheck} tone="accent" onClick={apply} />
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ColorName, ColorPickerPanelText } from "@glimstone/core";
|
|
2
|
+
export type { ColorName, ColorPickerPanelText } from "@glimstone/core";
|
|
3
|
+
export interface ColorPickerProps {
|
|
4
|
+
/** The colour the picker starts from, as `#rrggbb`. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Apply or Enter, with the colour and the name it proposes. */
|
|
7
|
+
onApply: (hex: string, name: string | null) => void;
|
|
8
|
+
/** Every step of a drag, a key or a valid hex, for a live preview. */
|
|
9
|
+
onInput?: (hex: string) => void;
|
|
10
|
+
/** The control that opened the picker. With it the picker floats beside it
|
|
11
|
+
* and closes on Escape, on a click beside it and after Apply. */
|
|
12
|
+
anchor?: HTMLElement | null;
|
|
13
|
+
/** Called when a floating picker closes, however it closes. */
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
/** The names a colour is matched against, nearest in OKLab. `false` shows none. */
|
|
16
|
+
names?: readonly ColorName[] | false;
|
|
17
|
+
/** The words, read when the picker opens. */
|
|
18
|
+
text?: Partial<ColorPickerPanelText>;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const ColorPicker: import("svelte").Component<ColorPickerProps, {}, "">;
|
|
22
|
+
type ColorPicker = ReturnType<typeof ColorPicker>;
|
|
23
|
+
export default ColorPicker;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { SelectOption } from "./selectParts.svelte.js";
|
|
3
|
+
|
|
4
|
+
export interface ComboboxProps {
|
|
5
|
+
label?: string;
|
|
6
|
+
hideLabel?: boolean;
|
|
7
|
+
options: SelectOption[];
|
|
8
|
+
/** The chosen value, bound with `bind:value`, or "" while nothing is chosen. */
|
|
9
|
+
value: string;
|
|
10
|
+
onChange?: (value: string) => void;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
/** The line the list shows when nothing matches. */
|
|
13
|
+
empty: string;
|
|
14
|
+
/** Accessible name of the button that opens the full list. */
|
|
15
|
+
toggleLabel: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import * as combobox from "@zag-js/combobox";
|
|
22
|
+
import { normalizeProps, useMachine } from "@zag-js/svelte";
|
|
23
|
+
import { useFieldName } from "./fieldName.js";
|
|
24
|
+
import { IconCheck, IconExpand } from "./glyphs.js";
|
|
25
|
+
import { lift } from "./lift.js";
|
|
26
|
+
|
|
27
|
+
// A field that filters a list while somebody types, for lists too long for a
|
|
28
|
+
// Select: containers, time zones, languages. Focus stays in the field while
|
|
29
|
+
// the arrows move through the list, and a search that finds nothing says so
|
|
30
|
+
// instead of closing, since a list that vanishes reads as a broken field.
|
|
31
|
+
let { label, hideLabel, options, value = $bindable(), onChange, placeholder, empty, toggleLabel, disabled }: ComboboxProps = $props();
|
|
32
|
+
|
|
33
|
+
const name = useFieldName(() => label);
|
|
34
|
+
const id = $props.id();
|
|
35
|
+
// svelte-ignore state_referenced_locally
|
|
36
|
+
let shown = $state.raw(options);
|
|
37
|
+
const service = useMachine(combobox.machine, () => ({
|
|
38
|
+
id,
|
|
39
|
+
collection: combobox.collection({
|
|
40
|
+
items: shown,
|
|
41
|
+
itemToValue: (o: SelectOption) => o.value,
|
|
42
|
+
itemToString: (o: SelectOption) => o.label,
|
|
43
|
+
isItemDisabled: (o: SelectOption) => !!o.disabled,
|
|
44
|
+
}),
|
|
45
|
+
value: value ? [value] : [],
|
|
46
|
+
placeholder,
|
|
47
|
+
disabled,
|
|
48
|
+
positioning: { sameWidth: true, gutter: 6 },
|
|
49
|
+
// Typing opens the list after the filter has run, so only a close may put
|
|
50
|
+
// the full list back.
|
|
51
|
+
onOpenChange: ({ open }: { open: boolean }) => {
|
|
52
|
+
if (!open) shown = options;
|
|
53
|
+
},
|
|
54
|
+
onInputValueChange: ({ inputValue }: { inputValue: string }) => {
|
|
55
|
+
const q = inputValue.toLocaleLowerCase();
|
|
56
|
+
shown = options.filter((o) => o.label.toLocaleLowerCase().includes(q));
|
|
57
|
+
},
|
|
58
|
+
onValueChange: (d: { value: string[] }) => {
|
|
59
|
+
value = d.value[0] ?? "";
|
|
60
|
+
onChange?.(value);
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
const api = $derived(combobox.connect(service, normalizeProps));
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<div data-glim="Combobox" {...api.getRootProps()} class="glim-combobox">
|
|
67
|
+
<label {...api.getLabelProps()} class={hideLabel || label === undefined ? "glim-sr-only" : "glim-field-label"}>{name()}</label>
|
|
68
|
+
<div {...api.getControlProps()} class="glim-combobox-control">
|
|
69
|
+
<input {...api.getInputProps()} class="glim-combobox-input" />
|
|
70
|
+
<button {...api.getTriggerProps()} aria-label={toggleLabel} class="glim-combobox-toggle">
|
|
71
|
+
<span class="glim-select-indicator" data-state={api.open ? "open" : "closed"}>{@render IconExpand()}</span>
|
|
72
|
+
</button>
|
|
73
|
+
</div>
|
|
74
|
+
<div {@attach lift} {...api.getPositionerProps()} class="glim-select-positioner">
|
|
75
|
+
<ul {...api.getContentProps()} class="glim-select-content">
|
|
76
|
+
{#if shown.length === 0}
|
|
77
|
+
<li class="glim-select-empty">{empty}</li>
|
|
78
|
+
{/if}
|
|
79
|
+
{#each shown as item (item.value)}
|
|
80
|
+
<li {...api.getItemProps({ item })} class="glim-select-item">
|
|
81
|
+
<span {...api.getItemTextProps({ item })}>{item.label}</span>
|
|
82
|
+
<span {...api.getItemIndicatorProps({ item })} class="glim-select-check">{@render IconCheck()}</span>
|
|
83
|
+
</li>
|
|
84
|
+
{/each}
|
|
85
|
+
</ul>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SelectOption } from "./selectParts.svelte.js";
|
|
2
|
+
export interface ComboboxProps {
|
|
3
|
+
label?: string;
|
|
4
|
+
hideLabel?: boolean;
|
|
5
|
+
options: SelectOption[];
|
|
6
|
+
/** The chosen value, bound with `bind:value`, or "" while nothing is chosen. */
|
|
7
|
+
value: string;
|
|
8
|
+
onChange?: (value: string) => void;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** The line the list shows when nothing matches. */
|
|
11
|
+
empty: string;
|
|
12
|
+
/** Accessible name of the button that opens the full list. */
|
|
13
|
+
toggleLabel: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const Combobox: import("svelte").Component<ComboboxProps, {}, "value">;
|
|
17
|
+
type Combobox = ReturnType<typeof Combobox>;
|
|
18
|
+
export default Combobox;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
|
|
4
|
+
export interface ConfirmDialogProps {
|
|
5
|
+
/** A generic title such as "Confirm"; the call site's own text is `message`. */
|
|
6
|
+
title: string;
|
|
7
|
+
/** The question or explanation, also the dialog's accessible description. */
|
|
8
|
+
message: string;
|
|
9
|
+
confirmLabel: string;
|
|
10
|
+
/** Translation key behind `confirmLabel`, so the confirm button can pick
|
|
11
|
+
* a glyph. Optional: a caller passing a composed or data label has none. */
|
|
12
|
+
confirmLabelKey?: string;
|
|
13
|
+
cancelLabel: string;
|
|
14
|
+
/** A control the confirming action needs an answer to, such as "also remove
|
|
15
|
+
* X?", shown under the message so the question is asked in one window.
|
|
16
|
+
* Keep it to a switch or two. */
|
|
17
|
+
extra?: Snippet;
|
|
18
|
+
/** Glyph for the confirm button. The action changes per call site, so no
|
|
19
|
+
* fixed key can name it; without one the button beside a glyphed Cancel
|
|
20
|
+
* looks unfinished. */
|
|
21
|
+
confirmGlyph?: Snippet;
|
|
22
|
+
/** Accessible name for the header close button, separate from cancelLabel so
|
|
23
|
+
* the two controls are not announced alike. Leave it out and the button is
|
|
24
|
+
* not drawn, since a corner close beside Cancel reads as a second choice. */
|
|
25
|
+
closeLabel?: string;
|
|
26
|
+
onConfirm: () => void;
|
|
27
|
+
onCancel: () => void;
|
|
28
|
+
/** The dialog card's root DOM node, bound with `bind:ref`, for useConfirm's focus trap. */
|
|
29
|
+
ref?: HTMLElement | null;
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import Badge from "./Badge.svelte";
|
|
35
|
+
import Button from "./Button.svelte";
|
|
36
|
+
import { IconCancel, IconClose } from "./glyphs.js";
|
|
37
|
+
|
|
38
|
+
// The styled confirmation dialog that replaces window.confirm(): an anchored
|
|
39
|
+
// header, a scrolling message and a footer with Cancel and Confirm. A backdrop
|
|
40
|
+
// click, the header close button and Cancel all call onCancel.
|
|
41
|
+
//
|
|
42
|
+
// The component holds no state and never touches `document`. The companion
|
|
43
|
+
// hook useConfirm owns the queue, the promise, the portal, Escape, the focus
|
|
44
|
+
// trap and returning focus on close, because Escape and the trap must work
|
|
45
|
+
// after focus has left this subtree.
|
|
46
|
+
let {
|
|
47
|
+
title,
|
|
48
|
+
message,
|
|
49
|
+
confirmLabel,
|
|
50
|
+
confirmLabelKey,
|
|
51
|
+
confirmGlyph,
|
|
52
|
+
extra,
|
|
53
|
+
cancelLabel,
|
|
54
|
+
closeLabel,
|
|
55
|
+
onConfirm,
|
|
56
|
+
onCancel,
|
|
57
|
+
ref = $bindable(null),
|
|
58
|
+
}: ConfirmDialogProps = $props();
|
|
59
|
+
|
|
60
|
+
// Focus lands on Cancel, the answer that changes nothing.
|
|
61
|
+
let cancel = $state<HTMLElement | null>(null);
|
|
62
|
+
$effect(() => cancel?.focus());
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
66
|
+
<div
|
|
67
|
+
class="glim-modal-backdrop"
|
|
68
|
+
onclick={(e) => {
|
|
69
|
+
if (e.target === e.currentTarget) onCancel();
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<div
|
|
73
|
+
data-glim="ConfirmDialog"
|
|
74
|
+
data-glim-title={title}
|
|
75
|
+
bind:this={ref}
|
|
76
|
+
role="dialog"
|
|
77
|
+
aria-modal="true"
|
|
78
|
+
aria-labelledby="confirmdialog-title"
|
|
79
|
+
aria-describedby="confirmdialog-message"
|
|
80
|
+
class="glim-modal-card"
|
|
81
|
+
>
|
|
82
|
+
<div class="glim-modal-head">
|
|
83
|
+
<!-- The title is a heading badge that straddles the card's top edge
|
|
84
|
+
against the outer box, which does not scroll and so does not clip it. -->
|
|
85
|
+
<h2 id="confirmdialog-title" class="glim-modal-title">
|
|
86
|
+
<Badge tone="heading" size="heading" wrap>{title}</Badge>
|
|
87
|
+
</h2>
|
|
88
|
+
{#if closeLabel !== undefined}
|
|
89
|
+
<Button label={closeLabel} labelKey="common.close" glyph={IconClose} tone="neutral" onClick={onCancel} class="glim-modal-close" />
|
|
90
|
+
{/if}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<div class="glim-modal-body">
|
|
94
|
+
<p id="confirmdialog-message" class="glim-modal-text">{message}</p>
|
|
95
|
+
{#if extra !== undefined}
|
|
96
|
+
<div class="glim-modal-extra">{@render extra()}</div>
|
|
97
|
+
{/if}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div class="glim-modal-foot">
|
|
101
|
+
<Button bind:ref={cancel} label={cancelLabel} labelKey="common.cancel" glyph={IconCancel} tone="neutral" onClick={onCancel} />
|
|
102
|
+
<!-- Not red: the dialog's sentence is the warning, and neither button is recommended. -->
|
|
103
|
+
<Button label={confirmLabel} labelKey={confirmLabelKey ?? null} glyph={confirmGlyph} tone="neutral" onClick={onConfirm} />
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export interface ConfirmDialogProps {
|
|
3
|
+
/** A generic title such as "Confirm"; the call site's own text is `message`. */
|
|
4
|
+
title: string;
|
|
5
|
+
/** The question or explanation, also the dialog's accessible description. */
|
|
6
|
+
message: string;
|
|
7
|
+
confirmLabel: string;
|
|
8
|
+
/** Translation key behind `confirmLabel`, so the confirm button can pick
|
|
9
|
+
* a glyph. Optional: a caller passing a composed or data label has none. */
|
|
10
|
+
confirmLabelKey?: string;
|
|
11
|
+
cancelLabel: string;
|
|
12
|
+
/** A control the confirming action needs an answer to, such as "also remove
|
|
13
|
+
* X?", shown under the message so the question is asked in one window.
|
|
14
|
+
* Keep it to a switch or two. */
|
|
15
|
+
extra?: Snippet;
|
|
16
|
+
/** Glyph for the confirm button. The action changes per call site, so no
|
|
17
|
+
* fixed key can name it; without one the button beside a glyphed Cancel
|
|
18
|
+
* looks unfinished. */
|
|
19
|
+
confirmGlyph?: Snippet;
|
|
20
|
+
/** Accessible name for the header close button, separate from cancelLabel so
|
|
21
|
+
* the two controls are not announced alike. Leave it out and the button is
|
|
22
|
+
* not drawn, since a corner close beside Cancel reads as a second choice. */
|
|
23
|
+
closeLabel?: string;
|
|
24
|
+
onConfirm: () => void;
|
|
25
|
+
onCancel: () => void;
|
|
26
|
+
/** The dialog card's root DOM node, bound with `bind:ref`, for useConfirm's focus trap. */
|
|
27
|
+
ref?: HTMLElement | null;
|
|
28
|
+
}
|
|
29
|
+
declare const ConfirmDialog: import("svelte").Component<ConfirmDialogProps, {}, "ref">;
|
|
30
|
+
type ConfirmDialog = ReturnType<typeof ConfirmDialog>;
|
|
31
|
+
export default ConfirmDialog;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getAllContexts, mount, unmount, untrack } from "svelte";
|
|
3
|
+
import { portalTarget } from "@glimstone/core";
|
|
4
|
+
import ConfirmDialog from "./ConfirmDialog.svelte";
|
|
5
|
+
import type { ConfirmHostState } from "./confirm.svelte.js";
|
|
6
|
+
|
|
7
|
+
// useConfirm's dialog. An ancestor with a transform would confine a fixed
|
|
8
|
+
// backdrop to its own box, so it is mounted straight into <body> and draws
|
|
9
|
+
// nothing where the host stands.
|
|
10
|
+
let { host }: { host: ConfirmHostState } = $props();
|
|
11
|
+
const context = getAllContexts();
|
|
12
|
+
|
|
13
|
+
$effect(() => {
|
|
14
|
+
const p = host.pending;
|
|
15
|
+
if (!p) return;
|
|
16
|
+
const dialog = untrack(() =>
|
|
17
|
+
mount(ConfirmDialog, {
|
|
18
|
+
target: portalTarget(),
|
|
19
|
+
context,
|
|
20
|
+
props: {
|
|
21
|
+
title: host.text.title,
|
|
22
|
+
message: p.message,
|
|
23
|
+
confirmLabel: p.confirmLabel ?? host.text.confirm,
|
|
24
|
+
confirmLabelKey: p.confirmLabelKey,
|
|
25
|
+
confirmGlyph: p.confirmGlyph,
|
|
26
|
+
cancelLabel: host.text.cancel,
|
|
27
|
+
extra: p.extra,
|
|
28
|
+
onConfirm: () => host.settle(true),
|
|
29
|
+
onCancel: () => host.settle(false),
|
|
30
|
+
get ref() {
|
|
31
|
+
return host.dialog;
|
|
32
|
+
},
|
|
33
|
+
set ref(el) {
|
|
34
|
+
host.dialog = el;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
return () => void unmount(dialog);
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConfirmHostState } from "./confirm.svelte.js";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
host: ConfirmHostState;
|
|
4
|
+
};
|
|
5
|
+
declare const ConfirmHost: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type ConfirmHost = ReturnType<typeof ConfirmHost>;
|
|
7
|
+
export default ConfirmHost;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { MenuEntry as CoreMenuEntry, MenuHead as CoreMenuHead, MenuItem as CoreMenuItem } from "@glimstone/core";
|
|
4
|
+
|
|
5
|
+
export type MenuEntry = CoreMenuEntry<Snippet>;
|
|
6
|
+
export type MenuItem = CoreMenuItem<Snippet>;
|
|
7
|
+
export type MenuHead = CoreMenuHead<Snippet>;
|
|
8
|
+
|
|
9
|
+
export interface ContextMenuProps {
|
|
10
|
+
/** The point the menu hangs from, in viewport pixels, such as the pointer's. */
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
items: MenuEntry[];
|
|
14
|
+
/** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
|
|
15
|
+
above?: boolean;
|
|
16
|
+
/** The menu's accessible name. */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** The menu element's id, for a caller or a script that looks for it. */
|
|
19
|
+
id?: string;
|
|
20
|
+
/** The control that opened the menu. A click on it is not a click outside,
|
|
21
|
+
* and focus goes back to it; without one, focus goes back to wherever it was. */
|
|
22
|
+
opener?: HTMLElement | null;
|
|
23
|
+
/** Called on every way out: a choice, Escape, Tab or a click outside. */
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
/** Left or right on a row without a submenu, for a bar that steps to the next menu. */
|
|
26
|
+
onStep?: (direction: 1 | -1) => void;
|
|
27
|
+
/** Opens with the focus on the last row, as ArrowUp on a menu bar's word asks. */
|
|
28
|
+
fromEnd?: boolean;
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<script lang="ts">
|
|
33
|
+
import { onMount, untrack } from "svelte";
|
|
34
|
+
import {
|
|
35
|
+
claimMenu,
|
|
36
|
+
closeMenuOutside,
|
|
37
|
+
focusedAsker,
|
|
38
|
+
focusFirstMenuRow,
|
|
39
|
+
focusMenuRow,
|
|
40
|
+
focusMenuRowByLetter,
|
|
41
|
+
isTypeahead,
|
|
42
|
+
isMenuHead,
|
|
43
|
+
menuMove,
|
|
44
|
+
menuRowView,
|
|
45
|
+
placeMenu,
|
|
46
|
+
placeSubmenu,
|
|
47
|
+
returnFocus,
|
|
48
|
+
tidyMenu,
|
|
49
|
+
} from "@glimstone/core";
|
|
50
|
+
import { lift } from "./lift.js";
|
|
51
|
+
import MenuRows from "./MenuRows.svelte";
|
|
52
|
+
|
|
53
|
+
// A menu at a point: a right-click on a row, the More button of a list, or a
|
|
54
|
+
// menu of the bar. Mount it to open it and unmount it on onClose. The model,
|
|
55
|
+
// the placing and the keys come from menu.ts in the core.
|
|
56
|
+
//
|
|
57
|
+
// A submenu opens beside its row as a second menu on the body, one level deep.
|
|
58
|
+
// A checkbox item leaves the menu open, so several can be ticked in a row; the
|
|
59
|
+
// caller flips `checked` and the row follows.
|
|
60
|
+
let { x, y, items, above = false, label, id, opener, onClose, onStep, fromEnd = false }: ContextMenuProps = $props();
|
|
61
|
+
|
|
62
|
+
let menu = $state<HTMLElement | null>(null);
|
|
63
|
+
let subMenu = $state<HTMLElement | null>(null);
|
|
64
|
+
const asker = focusedAsker();
|
|
65
|
+
let pos = $state.raw(untrack(() => ({ left: x, top: y })));
|
|
66
|
+
let sub = $state.raw<{ at: number; focus: boolean } | null>(null);
|
|
67
|
+
let subPos = $state.raw<{ left: number; top: number } | null>(null);
|
|
68
|
+
|
|
69
|
+
const viewport = () => ({ width: innerWidth, height: innerHeight });
|
|
70
|
+
const opensSub = (entry: MenuEntry | undefined): entry is MenuItem => !!entry && entry !== "-" && !isMenuHead(entry) && !!entry.sub;
|
|
71
|
+
const px = (at: { left: number; top: number }) => `left: ${at.left}px; top: ${at.top}px`;
|
|
72
|
+
|
|
73
|
+
const rows = $derived(tidyMenu(items));
|
|
74
|
+
const host = $derived.by(() => {
|
|
75
|
+
const entry = sub ? rows[sub.at] : undefined;
|
|
76
|
+
return opensSub(entry) ? entry : undefined;
|
|
77
|
+
});
|
|
78
|
+
const subRows = $derived(host?.sub ? tidyMenu(host.sub) : null);
|
|
79
|
+
|
|
80
|
+
// Focus goes back only on a way out somebody chose; a click elsewhere keeps
|
|
81
|
+
// the focus it gave. The opener is read first, since closing unmounts the
|
|
82
|
+
// menu and the caller may forget it.
|
|
83
|
+
function finish(handBack: boolean) {
|
|
84
|
+
const back = opener ?? asker;
|
|
85
|
+
onClose();
|
|
86
|
+
if (handBack) returnFocus(back);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$effect(() => {
|
|
90
|
+
if (menu) pos = placeMenu(x, y, { width: menu.offsetWidth, height: menu.offsetHeight }, viewport(), above);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
onMount(() => {
|
|
94
|
+
const release = claimMenu(finish);
|
|
95
|
+
const outside = closeMenuOutside(
|
|
96
|
+
() => [menu, subMenu, opener],
|
|
97
|
+
() => finish(false),
|
|
98
|
+
);
|
|
99
|
+
if (menu && fromEnd) focusMenuRow(menu, "last");
|
|
100
|
+
else if (menu) focusFirstMenuRow(menu);
|
|
101
|
+
return () => {
|
|
102
|
+
release();
|
|
103
|
+
outside();
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
$effect(() => {
|
|
108
|
+
const open = sub;
|
|
109
|
+
const row = open && menu?.querySelector(`[data-row="${open.at}"]`);
|
|
110
|
+
const el = subMenu;
|
|
111
|
+
if (!open || !row || !el || !subRows) {
|
|
112
|
+
subPos = null;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const rtl = getComputedStyle(menu!).direction === "rtl";
|
|
116
|
+
subPos = placeSubmenu(row.getBoundingClientRect(), { width: el.offsetWidth, height: el.offsetHeight }, viewport(), rtl);
|
|
117
|
+
if (open.focus) focusFirstMenuRow(el);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
function pick(list: MenuEntry[], at: number) {
|
|
121
|
+
const entry = list[at]!;
|
|
122
|
+
if (entry === "-") return;
|
|
123
|
+
if (isMenuHead(entry)) {
|
|
124
|
+
finish(true);
|
|
125
|
+
entry.edit?.onSelect();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (entry.sub && list === rows) {
|
|
129
|
+
sub = { at, focus: true };
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (menuRowView(entry).staysOpen) {
|
|
133
|
+
entry.onSelect?.();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
finish(true);
|
|
137
|
+
entry.onSelect?.();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function keys(e: KeyboardEvent, inSub: boolean) {
|
|
141
|
+
if (e.key === "Tab") return finish(false);
|
|
142
|
+
const panel = e.currentTarget as HTMLElement;
|
|
143
|
+
if (isTypeahead(e)) {
|
|
144
|
+
if (focusMenuRowByLetter(panel, e.key)) e.preventDefault();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const move = menuMove(e.key, getComputedStyle(panel).direction === "rtl");
|
|
148
|
+
if (!move) return;
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
if (move !== "in" && move !== "out") return focusMenuRow(panel, move);
|
|
151
|
+
if (inSub) {
|
|
152
|
+
if (move === "out" && sub) {
|
|
153
|
+
menu?.querySelector<HTMLElement>(`[data-row="${sub.at}"]`)?.focus();
|
|
154
|
+
sub = null;
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const at = Number((document.activeElement as HTMLElement | null)?.dataset.row);
|
|
159
|
+
const entry = rows[at];
|
|
160
|
+
if (move === "in" && opensSub(entry) && !entry.disabled) sub = { at, focus: true };
|
|
161
|
+
else onStep?.(move === "in" ? 1 : -1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// The pointer opens a submenu by resting on its row and closes it on any other row.
|
|
165
|
+
function hover(e: MouseEvent) {
|
|
166
|
+
const row = (e.target as Element).closest<HTMLElement>("[data-row]");
|
|
167
|
+
if (!row) return;
|
|
168
|
+
const at = Number(row.dataset.row);
|
|
169
|
+
const entry = rows[at];
|
|
170
|
+
const opens = opensSub(entry) && !entry.disabled;
|
|
171
|
+
if (opens && sub?.at !== at) sub = { at, focus: false };
|
|
172
|
+
else if (!opens && sub) sub = null;
|
|
173
|
+
}
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
<!-- Both menus are lifted to the body. Each stands alone in a block of its
|
|
177
|
+
own, so it is the only node Svelte removes for it. -->
|
|
178
|
+
{#snippet first()}
|
|
179
|
+
<!-- svelte-ignore a11y_interactive_supports_focus, a11y_mouse_events_have_key_events -->
|
|
180
|
+
<div
|
|
181
|
+
{@attach lift}
|
|
182
|
+
data-glim="ContextMenu"
|
|
183
|
+
bind:this={menu}
|
|
184
|
+
role="menu"
|
|
185
|
+
{id}
|
|
186
|
+
aria-label={label}
|
|
187
|
+
class="glim-menu"
|
|
188
|
+
style={px(pos)}
|
|
189
|
+
onkeydown={(e) => keys(e, false)}
|
|
190
|
+
onmouseover={hover}
|
|
191
|
+
oncontextmenu={(e) => e.preventDefault()}
|
|
192
|
+
>
|
|
193
|
+
<MenuRows entries={rows} openAt={sub?.at} onPick={(i) => pick(rows, i)} />
|
|
194
|
+
</div>
|
|
195
|
+
{/snippet}
|
|
196
|
+
{@render first()}
|
|
197
|
+
{#if subRows}
|
|
198
|
+
{@const list = subRows}
|
|
199
|
+
<!-- svelte-ignore a11y_interactive_supports_focus -->
|
|
200
|
+
<div
|
|
201
|
+
{@attach lift}
|
|
202
|
+
bind:this={subMenu}
|
|
203
|
+
id={host?.subId}
|
|
204
|
+
role="menu"
|
|
205
|
+
aria-label={host?.label}
|
|
206
|
+
class="glim-menu"
|
|
207
|
+
style={px(subPos ?? { left: 0, top: 0 })}
|
|
208
|
+
onkeydown={(e) => keys(e, true)}
|
|
209
|
+
oncontextmenu={(e) => e.preventDefault()}
|
|
210
|
+
>
|
|
211
|
+
<MenuRows entries={list} onPick={(i) => pick(list, i)} />
|
|
212
|
+
</div>
|
|
213
|
+
{/if}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { MenuEntry as CoreMenuEntry, MenuHead as CoreMenuHead, MenuItem as CoreMenuItem } from "@glimstone/core";
|
|
3
|
+
export type MenuEntry = CoreMenuEntry<Snippet>;
|
|
4
|
+
export type MenuItem = CoreMenuItem<Snippet>;
|
|
5
|
+
export type MenuHead = CoreMenuHead<Snippet>;
|
|
6
|
+
export interface ContextMenuProps {
|
|
7
|
+
/** The point the menu hangs from, in viewport pixels, such as the pointer's. */
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
items: MenuEntry[];
|
|
11
|
+
/** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
|
|
12
|
+
above?: boolean;
|
|
13
|
+
/** The menu's accessible name. */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** The menu element's id, for a caller or a script that looks for it. */
|
|
16
|
+
id?: string;
|
|
17
|
+
/** The control that opened the menu. A click on it is not a click outside,
|
|
18
|
+
* and focus goes back to it; without one, focus goes back to wherever it was. */
|
|
19
|
+
opener?: HTMLElement | null;
|
|
20
|
+
/** Called on every way out: a choice, Escape, Tab or a click outside. */
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
/** Left or right on a row without a submenu, for a bar that steps to the next menu. */
|
|
23
|
+
onStep?: (direction: 1 | -1) => void;
|
|
24
|
+
/** Opens with the focus on the last row, as ArrowUp on a menu bar's word asks. */
|
|
25
|
+
fromEnd?: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare const ContextMenu: import("svelte").Component<ContextMenuProps, {}, "">;
|
|
28
|
+
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
29
|
+
export default ContextMenu;
|