@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
package/dist/Tree.svelte
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { TreeNode as CoreTreeNode } from "@glimstone/core";
|
|
4
|
+
|
|
5
|
+
export type TreeNode = CoreTreeNode<Snippet>;
|
|
6
|
+
|
|
7
|
+
export interface TreeProps {
|
|
8
|
+
/** The tree's accessible name. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Asked once for the children of a row, and for the top with null. A list that fails is asked for again on the next opening. */
|
|
11
|
+
load: (id: string | null) => readonly TreeNode[] | Promise<readonly TreeNode[]>;
|
|
12
|
+
/** The chosen row's id, bound with `bind:value`. */
|
|
13
|
+
value: string | null;
|
|
14
|
+
onChange?: (id: string) => void;
|
|
15
|
+
/** Called on a double click or Enter on a row, for a picker that takes it at once. */
|
|
16
|
+
onActivate?: (id: string) => void;
|
|
17
|
+
/** The open rows' ids, bound with `bind:open` by a caller that holds them. */
|
|
18
|
+
open?: string[];
|
|
19
|
+
onOpenChange?: (open: string[]) => void;
|
|
20
|
+
/** The rows open from the start, for a tree that holds them itself. */
|
|
21
|
+
defaultOpen?: string[];
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { SvelteMap } from "svelte/reactivity";
|
|
27
|
+
import { focusTreeRow, treeRows, treeStep } from "@glimstone/core";
|
|
28
|
+
import { IconExpand } from "./glyphs.js";
|
|
29
|
+
|
|
30
|
+
// A hierarchy to walk through, loaded as it opens. The rows and the keys come
|
|
31
|
+
// from tree.ts in the core.
|
|
32
|
+
let { label, load, value = $bindable(), onChange, onActivate, open = $bindable(), onOpenChange, defaultOpen = [] }: TreeProps = $props();
|
|
33
|
+
|
|
34
|
+
// svelte-ignore state_referenced_locally
|
|
35
|
+
let ownOpen = $state(defaultOpen);
|
|
36
|
+
const opened = $derived(open ?? ownOpen);
|
|
37
|
+
const children = new SvelteMap<string | null, readonly TreeNode[]>();
|
|
38
|
+
const asked = new Set<string | null>();
|
|
39
|
+
let tree: HTMLDivElement;
|
|
40
|
+
|
|
41
|
+
$effect(() => {
|
|
42
|
+
for (const id of [null, ...opened]) {
|
|
43
|
+
if (asked.has(id)) continue;
|
|
44
|
+
asked.add(id);
|
|
45
|
+
Promise.resolve(load(id)).then(
|
|
46
|
+
(nodes) => children.set(id, nodes),
|
|
47
|
+
() => asked.delete(id),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const rows = $derived(treeRows(children, opened));
|
|
53
|
+
const stop = $derived(Math.max(rows.findIndex((r) => r.node.id === value), 0));
|
|
54
|
+
|
|
55
|
+
function choose(id: string) {
|
|
56
|
+
value = id;
|
|
57
|
+
onChange?.(id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function toggle(id: string) {
|
|
61
|
+
const next = opened.includes(id) ? opened.filter((o) => o !== id) : [...opened, id];
|
|
62
|
+
ownOpen = next;
|
|
63
|
+
if (open !== undefined) open = next;
|
|
64
|
+
onOpenChange?.(next);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function keys(e: KeyboardEvent, at: number) {
|
|
68
|
+
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
69
|
+
const id = rows[at]!.node.id;
|
|
70
|
+
if (e.key === " " || e.key === "Enter") {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
choose(id);
|
|
73
|
+
if (e.key === "Enter") onActivate?.(id);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const step = treeStep(rows, at, e.key, getComputedStyle(tree).direction === "rtl");
|
|
77
|
+
if (!step) return;
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
if ("focus" in step) {
|
|
80
|
+
choose(step.focus);
|
|
81
|
+
focusTreeRow(tree, step.focus);
|
|
82
|
+
} else toggle("open" in step ? step.open : step.close);
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<div data-glim="Tree" bind:this={tree} role="tree" aria-label={label} class="glim-tree">
|
|
87
|
+
{#each rows as r, i (r.node.id)}
|
|
88
|
+
<div
|
|
89
|
+
{...r.node.attrs}
|
|
90
|
+
role="treeitem"
|
|
91
|
+
aria-level={r.level}
|
|
92
|
+
aria-posinset={r.position}
|
|
93
|
+
aria-setsize={r.siblings}
|
|
94
|
+
aria-expanded={r.node.hasChildren ? r.open : undefined}
|
|
95
|
+
aria-selected={r.node.id === value}
|
|
96
|
+
tabindex={i === stop ? 0 : -1}
|
|
97
|
+
data-tree-id={r.node.id}
|
|
98
|
+
class="glim-tree-row"
|
|
99
|
+
style="--tree-level: {r.level - 1}"
|
|
100
|
+
onclick={() => choose(r.node.id)}
|
|
101
|
+
ondblclick={() => onActivate?.(r.node.id)}
|
|
102
|
+
onkeydown={(e) => keys(e, i)}
|
|
103
|
+
>
|
|
104
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
105
|
+
<span
|
|
106
|
+
class="glim-tree-toggle"
|
|
107
|
+
aria-hidden="true"
|
|
108
|
+
onclick={(e) => {
|
|
109
|
+
e.stopPropagation();
|
|
110
|
+
if (r.node.hasChildren) toggle(r.node.id);
|
|
111
|
+
}}
|
|
112
|
+
ondblclick={(e) => e.stopPropagation()}
|
|
113
|
+
>
|
|
114
|
+
{#if r.node.hasChildren}{@render IconExpand()}{/if}
|
|
115
|
+
</span>
|
|
116
|
+
{#if r.node.glyph}
|
|
117
|
+
<span class="glim-tree-glyph" aria-hidden="true">{@render ((r.open && r.node.openGlyph) || r.node.glyph)()}</span>
|
|
118
|
+
{/if}
|
|
119
|
+
<span class="glim-tree-label">{r.node.label}</span>
|
|
120
|
+
</div>
|
|
121
|
+
{/each}
|
|
122
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { TreeNode as CoreTreeNode } from "@glimstone/core";
|
|
3
|
+
export type TreeNode = CoreTreeNode<Snippet>;
|
|
4
|
+
export interface TreeProps {
|
|
5
|
+
/** The tree's accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Asked once for the children of a row, and for the top with null. A list that fails is asked for again on the next opening. */
|
|
8
|
+
load: (id: string | null) => readonly TreeNode[] | Promise<readonly TreeNode[]>;
|
|
9
|
+
/** The chosen row's id, bound with `bind:value`. */
|
|
10
|
+
value: string | null;
|
|
11
|
+
onChange?: (id: string) => void;
|
|
12
|
+
/** Called on a double click or Enter on a row, for a picker that takes it at once. */
|
|
13
|
+
onActivate?: (id: string) => void;
|
|
14
|
+
/** The open rows' ids, bound with `bind:open` by a caller that holds them. */
|
|
15
|
+
open?: string[];
|
|
16
|
+
onOpenChange?: (open: string[]) => void;
|
|
17
|
+
/** The rows open from the start, for a tree that holds them itself. */
|
|
18
|
+
defaultOpen?: string[];
|
|
19
|
+
}
|
|
20
|
+
declare const Tree: import("svelte").Component<TreeProps, {}, "value" | "open">;
|
|
21
|
+
type Tree = ReturnType<typeof Tree>;
|
|
22
|
+
export default Tree;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
|
|
4
|
+
export interface UnavailableNoticeProps {
|
|
5
|
+
/** One line saying what is unavailable. Already translated. */
|
|
6
|
+
title: string;
|
|
7
|
+
/**
|
|
8
|
+
* Why, and ideally what would change it. Already translated. A snippet lets
|
|
9
|
+
* a caller mark up a hostname or a path inside it.
|
|
10
|
+
*/
|
|
11
|
+
reason: string | Snippet;
|
|
12
|
+
/**
|
|
13
|
+
* A control for what somebody can do from here, such as opening the setting
|
|
14
|
+
* that fixes the cause. Never the control that was refused.
|
|
15
|
+
*/
|
|
16
|
+
action?: Snippet;
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
// What a card shows in place of a control when the environment forbids what the
|
|
22
|
+
// control would do, such as a passkey on a bare IP address or an untrusted
|
|
23
|
+
// certificate, where WebAuthn refuses the exchange. See "The second way in
|
|
24
|
+
// (second factor and passkey)" in the design language.
|
|
25
|
+
//
|
|
26
|
+
// Every string is a prop and arrives translated; a server's verdict travels as a
|
|
27
|
+
// boolean, never as the sentence shown here. It is a paragraph rather than an
|
|
28
|
+
// info bubble because there is no control to hang a bubble off.
|
|
29
|
+
let { title, reason, action }: UnavailableNoticeProps = $props();
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<div data-glim="UnavailableNotice" data-glim-title={title} class="glim-notice">
|
|
33
|
+
<p class="glim-notice-title">{title}</p>
|
|
34
|
+
<p class="glim-notice-reason">{#if typeof reason === "string"}{reason}{:else}{@render reason()}{/if}</p>
|
|
35
|
+
{#if action}<div class="glim-notice-action">{@render action()}</div>{/if}
|
|
36
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export interface UnavailableNoticeProps {
|
|
3
|
+
/** One line saying what is unavailable. Already translated. */
|
|
4
|
+
title: string;
|
|
5
|
+
/**
|
|
6
|
+
* Why, and ideally what would change it. Already translated. A snippet lets
|
|
7
|
+
* a caller mark up a hostname or a path inside it.
|
|
8
|
+
*/
|
|
9
|
+
reason: string | Snippet;
|
|
10
|
+
/**
|
|
11
|
+
* A control for what somebody can do from here, such as opening the setting
|
|
12
|
+
* that fixes the cause. Never the control that was refused.
|
|
13
|
+
*/
|
|
14
|
+
action?: Snippet;
|
|
15
|
+
}
|
|
16
|
+
declare const UnavailableNotice: import("svelte").Component<UnavailableNoticeProps, {}, "">;
|
|
17
|
+
type UnavailableNotice = ReturnType<typeof UnavailableNotice>;
|
|
18
|
+
export default UnavailableNotice;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
import type { WindowSize } from "@glimstone/core";
|
|
5
|
+
import type { WindowAction } from "./WindowFootRow.svelte";
|
|
6
|
+
|
|
7
|
+
export type { WindowSize } from "@glimstone/core";
|
|
8
|
+
export type { WindowAction } from "./WindowFootRow.svelte";
|
|
9
|
+
|
|
10
|
+
export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "children" | "class"> {
|
|
11
|
+
/** The notch's words, also the window's accessible name. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Takes the words' place in the notch with markup, such as a count. `title` alone stays the name. */
|
|
14
|
+
drawn?: Snippet;
|
|
15
|
+
children: Snippet;
|
|
16
|
+
/** The foot's buttons, in reading order. Cancel or Close is added before
|
|
17
|
+
* them unless one of them is a way out itself. */
|
|
18
|
+
actions?: WindowAction[];
|
|
19
|
+
/** A quiet line at the start of the foot, such as where the work carries on. */
|
|
20
|
+
start?: string | Snippet;
|
|
21
|
+
/** `normal` for a question or a form, `wide` for a list, `full` for a tool. */
|
|
22
|
+
size?: WindowSize;
|
|
23
|
+
/** The words of the way out the window adds. */
|
|
24
|
+
text: { cancel: string; close: string };
|
|
25
|
+
/** Called for every way out: the foot, Escape and a press beside the window. */
|
|
26
|
+
onClose: () => void;
|
|
27
|
+
class?: string;
|
|
28
|
+
/** The card element, bound with `bind:ref`. */
|
|
29
|
+
ref?: HTMLElement | null;
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import { onMount } from "svelte";
|
|
35
|
+
import { focusedAsker, menuIsOpen, returnFocus, stackWindow, windowFocusTarget } from "@glimstone/core";
|
|
36
|
+
import Badge from "./Badge.svelte";
|
|
37
|
+
import { lift } from "./lift.js";
|
|
38
|
+
import WindowFootRow from "./WindowFootRow.svelte";
|
|
39
|
+
|
|
40
|
+
// The general window: a notch with the title, a body for anything and a foot
|
|
41
|
+
// whose actions stand at the end. It owns the portal, its place on the stack,
|
|
42
|
+
// Escape, the Tab trap and the focus, so a caller only mounts it and unmounts
|
|
43
|
+
// it on onClose. The other props of a <div> go to the card.
|
|
44
|
+
let {
|
|
45
|
+
title,
|
|
46
|
+
drawn,
|
|
47
|
+
children,
|
|
48
|
+
actions = [],
|
|
49
|
+
start,
|
|
50
|
+
size = "normal",
|
|
51
|
+
text,
|
|
52
|
+
onClose,
|
|
53
|
+
class: className,
|
|
54
|
+
ref = $bindable(null),
|
|
55
|
+
...rest
|
|
56
|
+
}: WindowProps = $props();
|
|
57
|
+
|
|
58
|
+
const titleId = $props.id();
|
|
59
|
+
// Read before the window takes the focus.
|
|
60
|
+
const asker = focusedAsker();
|
|
61
|
+
|
|
62
|
+
// Leaving takes the window off the stack at once, so the page is live again
|
|
63
|
+
// by the time the caller hands the focus back to a field in it.
|
|
64
|
+
let unstack: (() => void) | undefined;
|
|
65
|
+
function leave() {
|
|
66
|
+
unstack?.();
|
|
67
|
+
onClose();
|
|
68
|
+
}
|
|
69
|
+
onMount(() => {
|
|
70
|
+
unstack = stackWindow(() => ref, leave);
|
|
71
|
+
if (ref) windowFocusTarget(ref)?.focus();
|
|
72
|
+
return () => {
|
|
73
|
+
unstack?.();
|
|
74
|
+
returnFocus(asker);
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// A press beside an open menu only closes the menu, not the window under it.
|
|
79
|
+
function pressBeside(e: MouseEvent) {
|
|
80
|
+
if (e.target === e.currentTarget && !menuIsOpen()) leave();
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<!-- The backdrop is lifted to the body. It stands alone in a block of its own,
|
|
85
|
+
so it is the only node Svelte removes for it, wherever the caller put it. -->
|
|
86
|
+
{#snippet backdrop()}
|
|
87
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
88
|
+
<div class="glim-modal-backdrop" {@attach lift} onmousedown={pressBeside}>
|
|
89
|
+
<div
|
|
90
|
+
data-glim="Window"
|
|
91
|
+
data-glim-title={title}
|
|
92
|
+
{...rest}
|
|
93
|
+
bind:this={ref}
|
|
94
|
+
role="dialog"
|
|
95
|
+
aria-modal="true"
|
|
96
|
+
aria-labelledby={drawn ? undefined : titleId}
|
|
97
|
+
aria-label={drawn ? title : undefined}
|
|
98
|
+
class={["glim-modal-card", "glim-window", size !== "normal" && `glim-window--${size}`, className].filter(Boolean).join(" ")}
|
|
99
|
+
>
|
|
100
|
+
<h2 id={titleId} class="glim-window-title">
|
|
101
|
+
<Badge tone="heading" size="heading" wrap insetStart={5}>{#if drawn}{@render drawn()}{:else}{title}{/if}</Badge>
|
|
102
|
+
</h2>
|
|
103
|
+
<div class="glim-modal-body glim-window-body">{@render children()}</div>
|
|
104
|
+
<WindowFootRow {actions} {start} {text} onClose={leave} />
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
{/snippet}
|
|
108
|
+
{@render backdrop()}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { WindowSize } from "@glimstone/core";
|
|
4
|
+
import type { WindowAction } from "./WindowFootRow.svelte";
|
|
5
|
+
export type { WindowSize } from "@glimstone/core";
|
|
6
|
+
export type { WindowAction } from "./WindowFootRow.svelte";
|
|
7
|
+
export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "children" | "class"> {
|
|
8
|
+
/** The notch's words, also the window's accessible name. */
|
|
9
|
+
title: string;
|
|
10
|
+
/** Takes the words' place in the notch with markup, such as a count. `title` alone stays the name. */
|
|
11
|
+
drawn?: Snippet;
|
|
12
|
+
children: Snippet;
|
|
13
|
+
/** The foot's buttons, in reading order. Cancel or Close is added before
|
|
14
|
+
* them unless one of them is a way out itself. */
|
|
15
|
+
actions?: WindowAction[];
|
|
16
|
+
/** A quiet line at the start of the foot, such as where the work carries on. */
|
|
17
|
+
start?: string | Snippet;
|
|
18
|
+
/** `normal` for a question or a form, `wide` for a list, `full` for a tool. */
|
|
19
|
+
size?: WindowSize;
|
|
20
|
+
/** The words of the way out the window adds. */
|
|
21
|
+
text: {
|
|
22
|
+
cancel: string;
|
|
23
|
+
close: string;
|
|
24
|
+
};
|
|
25
|
+
/** Called for every way out: the foot, Escape and a press beside the window. */
|
|
26
|
+
onClose: () => void;
|
|
27
|
+
class?: string;
|
|
28
|
+
/** The card element, bound with `bind:ref`. */
|
|
29
|
+
ref?: HTMLElement | null;
|
|
30
|
+
}
|
|
31
|
+
declare const Window: import("svelte").Component<WindowProps, {}, "ref">;
|
|
32
|
+
type Window = ReturnType<typeof Window>;
|
|
33
|
+
export default Window;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface WindowBarProps {
|
|
3
|
+
/** The app's name. The bar shows none, so this is what a screen reader
|
|
4
|
+
* announces for it. */
|
|
5
|
+
appName: string;
|
|
6
|
+
/** Whether the window fills the screen. The middle button then restores it,
|
|
7
|
+
* and the app turns its edge resizing off. */
|
|
8
|
+
maximised: boolean;
|
|
9
|
+
/** The buttons' accessible names, which also show in their bubbles. */
|
|
10
|
+
text: { minimise: string; maximise: string; restore: string; close: string };
|
|
11
|
+
onMinimise: () => void;
|
|
12
|
+
onToggleMaximise: () => void;
|
|
13
|
+
/** Asks the way the native close button does, so an app that hides to the
|
|
14
|
+
* tray on close still does. */
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
/** Called once a press on the bar starts to move. The app hands the press to
|
|
17
|
+
* the system, which moves the window from there. */
|
|
18
|
+
onDragStart: () => void;
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { IconClose, IconWindowMaximise, IconWindowMinimise, IconWindowRestore } from "./glyphs.js";
|
|
24
|
+
import IconTipButton from "./IconTipButton.svelte";
|
|
25
|
+
|
|
26
|
+
// The title bar a desktop app draws where its window has no native one
|
|
27
|
+
// (design-language.md, "The desktop window frame"): a strip to drag and the
|
|
28
|
+
// three window buttons, nothing else. The rail already shows the mark and the
|
|
29
|
+
// name. It knows nothing of the shell that hosts the page; the app hands it
|
|
30
|
+
// the window calls and whether the window is maximised.
|
|
31
|
+
//
|
|
32
|
+
// Render it only where the app draws its own frame. tokens.css moves the page
|
|
33
|
+
// and every scrim below it as soon as it is in the document.
|
|
34
|
+
let { appName, maximised, text, onMinimise, onToggleMaximise, onClose, onDragStart }: WindowBarProps = $props();
|
|
35
|
+
|
|
36
|
+
const onButton = (e: MouseEvent) => (e.target as Element).closest("button") !== null;
|
|
37
|
+
|
|
38
|
+
// The drag starts on the first move, not on the press, so a click and a
|
|
39
|
+
// double click on the bar stay clicks. An edge the app's resize has taken
|
|
40
|
+
// arrives with its default prevented and is left to it.
|
|
41
|
+
let pressed = false;
|
|
42
|
+
function down(e: MouseEvent) {
|
|
43
|
+
pressed = e.button === 0 && !e.defaultPrevented && !onButton(e);
|
|
44
|
+
}
|
|
45
|
+
function move(e: MouseEvent) {
|
|
46
|
+
if (!pressed) return;
|
|
47
|
+
pressed = false;
|
|
48
|
+
if (e.buttons === 1) onDragStart();
|
|
49
|
+
}
|
|
50
|
+
function toggle(e: MouseEvent) {
|
|
51
|
+
if (!onButton(e)) onToggleMaximise();
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<!-- Each button takes the bar's full height and shows the house square inside,
|
|
56
|
+
so a pointer thrown into the corner of a maximised window still lands on close. -->
|
|
57
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
58
|
+
<header
|
|
59
|
+
data-glim="WindowBar"
|
|
60
|
+
aria-label={appName}
|
|
61
|
+
class="glim-window-bar"
|
|
62
|
+
onmousedown={down}
|
|
63
|
+
onmousemove={move}
|
|
64
|
+
onmouseup={() => (pressed = false)}
|
|
65
|
+
ondblclick={toggle}
|
|
66
|
+
>
|
|
67
|
+
<IconTipButton tip={text.minimise} onclick={onMinimise} class="glim-window-button">
|
|
68
|
+
<span class="glim-window-square">{@render IconWindowMinimise()}</span>
|
|
69
|
+
</IconTipButton>
|
|
70
|
+
<IconTipButton tip={maximised ? text.restore : text.maximise} onclick={onToggleMaximise} class="glim-window-button">
|
|
71
|
+
<span class="glim-window-square">{#if maximised}{@render IconWindowRestore()}{:else}{@render IconWindowMaximise()}{/if}</span>
|
|
72
|
+
</IconTipButton>
|
|
73
|
+
<IconTipButton tip={text.close} onclick={onClose} class="glim-window-button">
|
|
74
|
+
<span class="glim-window-square">{@render IconClose()}</span>
|
|
75
|
+
</IconTipButton>
|
|
76
|
+
</header>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface WindowBarProps {
|
|
2
|
+
/** The app's name. The bar shows none, so this is what a screen reader
|
|
3
|
+
* announces for it. */
|
|
4
|
+
appName: string;
|
|
5
|
+
/** Whether the window fills the screen. The middle button then restores it,
|
|
6
|
+
* and the app turns its edge resizing off. */
|
|
7
|
+
maximised: boolean;
|
|
8
|
+
/** The buttons' accessible names, which also show in their bubbles. */
|
|
9
|
+
text: {
|
|
10
|
+
minimise: string;
|
|
11
|
+
maximise: string;
|
|
12
|
+
restore: string;
|
|
13
|
+
close: string;
|
|
14
|
+
};
|
|
15
|
+
onMinimise: () => void;
|
|
16
|
+
onToggleMaximise: () => void;
|
|
17
|
+
/** Asks the way the native close button does, so an app that hides to the
|
|
18
|
+
* tray on close still does. */
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
/** Called once a press on the bar starts to move. The app hands the press to
|
|
21
|
+
* the system, which moves the window from there. */
|
|
22
|
+
onDragStart: () => void;
|
|
23
|
+
}
|
|
24
|
+
declare const WindowBar: import("svelte").Component<WindowBarProps, {}, "">;
|
|
25
|
+
type WindowBar = ReturnType<typeof WindowBar>;
|
|
26
|
+
export default WindowBar;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
|
|
4
|
+
export interface WindowAction {
|
|
5
|
+
label: string;
|
|
6
|
+
/** The translation key behind `label`, which picks the glyph, or `null`. */
|
|
7
|
+
labelKey: string | null;
|
|
8
|
+
glyph?: Snippet;
|
|
9
|
+
/** The forward action, filled with the accent and placed last. */
|
|
10
|
+
primary?: boolean;
|
|
11
|
+
/** This action already leaves the window, so no Cancel or Close is added. */
|
|
12
|
+
wayOut?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Attributes for the action's button, such as a data hook. */
|
|
15
|
+
attrs?: Record<string, string>;
|
|
16
|
+
/** Runs on press. The window closes afterwards unless it returns false. */
|
|
17
|
+
onClick?: () => void | false;
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { windowFoot } from "@glimstone/core";
|
|
23
|
+
import Button from "./Button.svelte";
|
|
24
|
+
import { IconCancel, IconClose } from "./glyphs.js";
|
|
25
|
+
|
|
26
|
+
// The foot of a Window or a Sheet: a quiet start line and the actions at the
|
|
27
|
+
// end, with Cancel or Close added by windowFoot() in the core.
|
|
28
|
+
let {
|
|
29
|
+
actions,
|
|
30
|
+
start,
|
|
31
|
+
text,
|
|
32
|
+
onClose,
|
|
33
|
+
}: {
|
|
34
|
+
actions: WindowAction[];
|
|
35
|
+
start?: string | Snippet;
|
|
36
|
+
text: { cancel: string; close: string };
|
|
37
|
+
onClose: () => void;
|
|
38
|
+
} = $props();
|
|
39
|
+
|
|
40
|
+
const foot = $derived(
|
|
41
|
+
windowFoot<WindowAction>(actions, start !== undefined, {
|
|
42
|
+
cancel: { label: text.cancel, labelKey: "common.cancel", glyph: IconCancel, wayOut: true },
|
|
43
|
+
close: { label: text.close, labelKey: "common.close", glyph: IconClose, wayOut: true },
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
{#if foot.length > 0}
|
|
49
|
+
<div class="glim-modal-foot">
|
|
50
|
+
{#if start !== undefined}
|
|
51
|
+
<span class="glim-window-start">{#if typeof start === "string"}{start}{:else}{@render start()}{/if}</span>
|
|
52
|
+
{/if}
|
|
53
|
+
{#each foot as a, i (i)}
|
|
54
|
+
<Button
|
|
55
|
+
{...a.attrs}
|
|
56
|
+
label={a.label}
|
|
57
|
+
labelKey={a.labelKey}
|
|
58
|
+
glyph={a.glyph}
|
|
59
|
+
tone={a.primary ? "accent" : "neutral"}
|
|
60
|
+
disabled={a.disabled}
|
|
61
|
+
onClick={() => {
|
|
62
|
+
if (a.onClick?.() !== false) onClose();
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
{/each}
|
|
66
|
+
</div>
|
|
67
|
+
{/if}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export interface WindowAction {
|
|
3
|
+
label: string;
|
|
4
|
+
/** The translation key behind `label`, which picks the glyph, or `null`. */
|
|
5
|
+
labelKey: string | null;
|
|
6
|
+
glyph?: Snippet;
|
|
7
|
+
/** The forward action, filled with the accent and placed last. */
|
|
8
|
+
primary?: boolean;
|
|
9
|
+
/** This action already leaves the window, so no Cancel or Close is added. */
|
|
10
|
+
wayOut?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Attributes for the action's button, such as a data hook. */
|
|
13
|
+
attrs?: Record<string, string>;
|
|
14
|
+
/** Runs on press. The window closes afterwards unless it returns false. */
|
|
15
|
+
onClick?: () => void | false;
|
|
16
|
+
}
|
|
17
|
+
type $$ComponentProps = {
|
|
18
|
+
actions: WindowAction[];
|
|
19
|
+
start?: string | Snippet;
|
|
20
|
+
text: {
|
|
21
|
+
cancel: string;
|
|
22
|
+
close: string;
|
|
23
|
+
};
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
};
|
|
26
|
+
declare const WindowFootRow: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
27
|
+
type WindowFootRow = ReturnType<typeof WindowFootRow>;
|
|
28
|
+
export default WindowFootRow;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TipBubble {
|
|
2
|
+
/** The trigger the bubble is placed against. */
|
|
3
|
+
trigger: HTMLElement | null;
|
|
4
|
+
bubble: HTMLElement | null;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly text: string | undefined;
|
|
7
|
+
readonly shown: boolean;
|
|
8
|
+
/** `aria-describedby` while open, so the bubble is announced as the trigger's description. */
|
|
9
|
+
readonly describedBy: string | undefined;
|
|
10
|
+
show: () => void;
|
|
11
|
+
hide: () => void;
|
|
12
|
+
/** Focus opens the bubble only when the keyboard was used last; a mouse user gets focus as a side effect. */
|
|
13
|
+
showOnFocus: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function useTipBubble(tip: () => string | undefined, disabled?: () => boolean): TipBubble;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { dismissBubbleOn, placeBubble, pointerWasLast, trackInputModality } from "@glimstone/core";
|
|
2
|
+
let count = 0;
|
|
3
|
+
export function useTipBubble(tip, disabled = () => false) {
|
|
4
|
+
let open = $state(false);
|
|
5
|
+
let trigger = $state(null);
|
|
6
|
+
let bubble = $state(null);
|
|
7
|
+
const id = `glim-tip-${++count}`;
|
|
8
|
+
const text = $derived(tip());
|
|
9
|
+
const shown = $derived(!!text && open);
|
|
10
|
+
// A disabled trigger is boxed in TipWrap, so flipping `disabled` swaps the
|
|
11
|
+
// element and its mouseleave never comes; the bubble closes with it.
|
|
12
|
+
let seen = disabled();
|
|
13
|
+
$effect.pre(() => {
|
|
14
|
+
const now = disabled();
|
|
15
|
+
if (now !== seen)
|
|
16
|
+
open = false;
|
|
17
|
+
seen = now;
|
|
18
|
+
});
|
|
19
|
+
trackInputModality();
|
|
20
|
+
const show = () => {
|
|
21
|
+
if (text)
|
|
22
|
+
open = true;
|
|
23
|
+
};
|
|
24
|
+
const hide = () => {
|
|
25
|
+
open = false;
|
|
26
|
+
};
|
|
27
|
+
// Effects run once the bubble is in the document and before the browser
|
|
28
|
+
// paints, so it is measured and placed without a visible jump.
|
|
29
|
+
$effect(() => {
|
|
30
|
+
if (!shown)
|
|
31
|
+
return;
|
|
32
|
+
if (trigger && bubble)
|
|
33
|
+
placeBubble(trigger, bubble);
|
|
34
|
+
return dismissBubbleOn(hide);
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
get trigger() {
|
|
38
|
+
return trigger;
|
|
39
|
+
},
|
|
40
|
+
set trigger(el) {
|
|
41
|
+
trigger = el;
|
|
42
|
+
},
|
|
43
|
+
get bubble() {
|
|
44
|
+
return bubble;
|
|
45
|
+
},
|
|
46
|
+
set bubble(el) {
|
|
47
|
+
bubble = el;
|
|
48
|
+
},
|
|
49
|
+
id,
|
|
50
|
+
get text() {
|
|
51
|
+
return text;
|
|
52
|
+
},
|
|
53
|
+
get shown() {
|
|
54
|
+
return shown;
|
|
55
|
+
},
|
|
56
|
+
get describedBy() {
|
|
57
|
+
return shown ? id : undefined;
|
|
58
|
+
},
|
|
59
|
+
show,
|
|
60
|
+
hide,
|
|
61
|
+
showOnFocus: () => {
|
|
62
|
+
if (!pointerWasLast())
|
|
63
|
+
show();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Component, Snippet } from "svelte";
|
|
2
|
+
export interface ConfirmText {
|
|
3
|
+
/** The dialog's title, the same for every question, such as "Confirm". */
|
|
4
|
+
title: string;
|
|
5
|
+
cancel: string;
|
|
6
|
+
/** The confirm button's words where a question passes none of its own. */
|
|
7
|
+
confirm: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ConfirmOptions {
|
|
10
|
+
/** The words of the action being confirmed, so the answer repeats "Delete"
|
|
11
|
+
* rather than a bare "Confirm". */
|
|
12
|
+
confirmLabel?: string;
|
|
13
|
+
/** Translation key behind confirmLabel, so the confirm button shows its glyph. */
|
|
14
|
+
confirmLabelKey?: string;
|
|
15
|
+
confirmGlyph?: Snippet;
|
|
16
|
+
/** A switch or two the answer needs, shown under the question. */
|
|
17
|
+
extra?: Snippet;
|
|
18
|
+
}
|
|
19
|
+
export interface PendingQuestion extends ConfirmOptions {
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
/** What the host component reads and answers through. */
|
|
23
|
+
export interface ConfirmHostState {
|
|
24
|
+
readonly text: ConfirmText;
|
|
25
|
+
readonly pending: PendingQuestion | null;
|
|
26
|
+
dialog: HTMLElement | null;
|
|
27
|
+
settle: (result: boolean) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function useConfirm(text: ConfirmText): {
|
|
30
|
+
confirm: (message: string, options?: ConfirmOptions) => Promise<boolean>;
|
|
31
|
+
confirmDialog: Component<{}, {}, string>;
|
|
32
|
+
dismiss: () => void;
|
|
33
|
+
};
|
|
34
|
+
/** Escape from anywhere and a Tab trap over the dialog's own controls while
|
|
35
|
+
* it is open, so focus never reaches the page it covers. For any other modal
|
|
36
|
+
* window too. */
|
|
37
|
+
export declare function useDialogKeys(open: () => boolean, dialog: () => HTMLElement | null, onCancel: () => void): void;
|