@glimstone/svelte 4.9.2 → 5.0.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/dist/AngleSlider.svelte +33 -9
- package/dist/AngleSlider.svelte.d.ts +1 -1
- package/dist/Avatar.svelte +1 -1
- package/dist/Badge.svelte +3 -7
- package/dist/Badge.svelte.d.ts +2 -5
- package/dist/Card.svelte +5 -1
- package/dist/Card.svelte.d.ts +3 -0
- package/dist/Chart.svelte +84 -0
- package/dist/Chart.svelte.d.ts +19 -0
- package/dist/ChartLegend.svelte +19 -0
- package/dist/ChartLegend.svelte.d.ts +7 -0
- package/dist/Checkbox.svelte +16 -3
- package/dist/ColorPicker.svelte +49 -4
- package/dist/ColorPicker.svelte.d.ts +2 -0
- package/dist/Combobox.svelte +12 -4
- package/dist/ConfirmDialog.svelte +8 -2
- package/dist/ContextMenu.svelte +4 -2
- package/dist/ContextMenu.svelte.d.ts +2 -0
- package/dist/DatePicker.svelte +21 -11
- package/dist/FieldErrorLine.svelte +24 -0
- package/dist/FieldErrorLine.svelte.d.ts +7 -0
- package/dist/FieldRow.svelte +16 -4
- package/dist/FileUpload.svelte +14 -4
- package/dist/FileUpload.svelte.d.ts +2 -0
- package/dist/FortressPermissions.svelte +3 -1
- package/dist/HoverCard.svelte +34 -5
- package/dist/HoverCard.svelte.d.ts +12 -2
- package/dist/IconTipButton.svelte +6 -2
- package/dist/IconTipButton.svelte.d.ts +3 -0
- package/dist/InfoBubble.svelte +1 -1
- package/dist/ListRow.svelte +71 -6
- package/dist/ListRow.svelte.d.ts +17 -2
- package/dist/ListSelect.svelte +7 -2
- package/dist/ListTable.svelte +33 -15
- package/dist/ListTable.svelte.d.ts +5 -0
- package/dist/MenuSelect.svelte +11 -3
- package/dist/Meter.svelte +21 -3
- package/dist/Meter.svelte.d.ts +4 -0
- package/dist/MultiSelect.svelte +2 -1
- package/dist/NotifyCard.svelte +1 -1
- package/dist/NumberField.svelte +2 -2
- package/dist/PasswordField.svelte +7 -6
- package/dist/PinInput.svelte +4 -2
- package/dist/Rating.svelte +10 -1
- package/dist/RevealEye.svelte +17 -0
- package/dist/RevealEye.svelte.d.ts +6 -0
- package/dist/SearchHit.svelte +10 -0
- package/dist/SearchHit.svelte.d.ts +7 -0
- package/dist/Selector.svelte +28 -4
- package/dist/Selector.svelte.d.ts +4 -3
- package/dist/SettingsNav.svelte +152 -0
- package/dist/SettingsNav.svelte.d.ts +46 -0
- package/dist/SignInTile.svelte +19 -14
- package/dist/SkeletonRow.svelte +8 -2
- package/dist/SkeletonRow.svelte.d.ts +4 -0
- package/dist/Slider.svelte +1 -0
- package/dist/Sparkline.svelte +24 -0
- package/dist/Sparkline.svelte.d.ts +11 -0
- package/dist/StatusSummary.svelte +55 -0
- package/dist/StatusSummary.svelte.d.ts +18 -0
- package/dist/SubCard.svelte +16 -16
- package/dist/SubCard.svelte.d.ts +3 -3
- package/dist/TextArea.svelte +13 -3
- package/dist/TextField.svelte +2 -2
- package/dist/TimeDial.svelte +74 -0
- package/dist/TimeDial.svelte.d.ts +13 -0
- package/dist/TimePicker.svelte +57 -0
- package/dist/TimePicker.svelte.d.ts +19 -0
- package/dist/TimeRangePicker.svelte +52 -0
- package/dist/TimeRangePicker.svelte.d.ts +16 -0
- package/dist/TimeShell.svelte +145 -0
- package/dist/TimeShell.svelte.d.ts +16 -0
- package/dist/Timer.svelte +6 -1
- package/dist/TipBubble.svelte +1 -1
- package/dist/ToastCard.svelte +7 -3
- package/dist/ToastCard.svelte.d.ts +2 -0
- package/dist/ToastViewport.svelte +6 -3
- package/dist/Toggle.svelte +3 -1
- package/dist/Tour.svelte +8 -2
- package/dist/Window.svelte +5 -3
- package/dist/Window.svelte.d.ts +3 -1
- package/dist/bubble.svelte.d.ts +12 -1
- package/dist/bubble.svelte.js +13 -5
- package/dist/engines.svelte.d.ts +7 -1
- package/dist/engines.svelte.js +13 -1
- package/dist/glyphs.d.ts +3 -0
- package/dist/glyphs.js +3 -0
- package/dist/index.d.ts +13 -7
- package/dist/index.js +9 -4
- package/package.json +2 -2
- package/dist/AboutCard.svelte +0 -116
- package/dist/AboutCard.svelte.d.ts +0 -40
- package/dist/DropdownListbox.svelte +0 -178
- package/dist/DropdownListbox.svelte.d.ts +0 -23
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as AboutCard } from "./AboutCard.svelte";
|
|
2
1
|
export { default as Badge } from "./Badge.svelte";
|
|
3
2
|
export { default as BrandMark } from "./BrandMark.svelte";
|
|
4
3
|
export { default as BusyRing } from "./BusyRing.svelte";
|
|
@@ -12,7 +11,6 @@ export { default as ConnectionRow } from "./ConnectionRow.svelte";
|
|
|
12
11
|
export { default as ContextMenu } from "./ContextMenu.svelte";
|
|
13
12
|
export { default as CopyField } from "./CopyField.svelte";
|
|
14
13
|
export { default as CryptoDonateDialog } from "./CryptoDonateDialog.svelte";
|
|
15
|
-
export { default as DropdownListbox } from "./DropdownListbox.svelte";
|
|
16
14
|
export { default as EmptyState } from "./EmptyState.svelte";
|
|
17
15
|
export { default as FieldError } from "./FieldError.svelte";
|
|
18
16
|
export { default as FieldRow } from "./FieldRow.svelte";
|
|
@@ -39,6 +37,9 @@ export { default as ListRow } from "./ListRow.svelte";
|
|
|
39
37
|
export { default as ListTable } from "./ListTable.svelte";
|
|
40
38
|
export { default as MarkSvg } from "./MarkSvg.svelte";
|
|
41
39
|
export { default as MenuBar } from "./MenuBar.svelte";
|
|
40
|
+
export { default as Chart } from "./Chart.svelte";
|
|
41
|
+
export { default as ChartLegend } from "./ChartLegend.svelte";
|
|
42
|
+
export { default as Sparkline } from "./Sparkline.svelte";
|
|
42
43
|
export { default as Meter } from "./Meter.svelte";
|
|
43
44
|
export { default as NumberField } from "./NumberField.svelte";
|
|
44
45
|
export { default as PasswordField } from "./PasswordField.svelte";
|
|
@@ -52,6 +53,7 @@ export { default as ProgressBar } from "./ProgressBar.svelte";
|
|
|
52
53
|
export { default as ReadmeButton } from "./ReadmeButton.svelte";
|
|
53
54
|
export { default as RowMark } from "./RowMark.svelte";
|
|
54
55
|
export { default as Selector, selectorTabId } from "./Selector.svelte";
|
|
56
|
+
export { default as SettingsNav } from "./SettingsNav.svelte";
|
|
55
57
|
export { default as Sheet } from "./Sheet.svelte";
|
|
56
58
|
export { default as SidebarRow } from "./SidebarRow.svelte";
|
|
57
59
|
export { default as SignInCard } from "./SignInCard.svelte";
|
|
@@ -60,10 +62,13 @@ export { default as SignInReauthWindow } from "./SignInReauthWindow.svelte";
|
|
|
60
62
|
export { default as SignInTile } from "./SignInTile.svelte";
|
|
61
63
|
export { default as NotifyCard } from "./NotifyCard.svelte";
|
|
62
64
|
export { default as SkeletonRow } from "./SkeletonRow.svelte";
|
|
65
|
+
export { default as StatusSummary } from "./StatusSummary.svelte";
|
|
63
66
|
export { default as SubCard } from "./SubCard.svelte";
|
|
64
67
|
export { default as Table } from "./Table.svelte";
|
|
65
68
|
export { default as TextArea } from "./TextArea.svelte";
|
|
66
69
|
export { default as TextField } from "./TextField.svelte";
|
|
70
|
+
export { default as TimePicker } from "./TimePicker.svelte";
|
|
71
|
+
export { default as TimeRangePicker } from "./TimeRangePicker.svelte";
|
|
67
72
|
export { default as ToastCard } from "./ToastCard.svelte";
|
|
68
73
|
export { default as ToastViewport } from "./ToastViewport.svelte";
|
|
69
74
|
export { default as Toggle } from "./Toggle.svelte";
|
|
@@ -71,11 +76,11 @@ export { default as Tree } from "./Tree.svelte";
|
|
|
71
76
|
export { default as UnavailableNotice } from "./UnavailableNotice.svelte";
|
|
72
77
|
export { default as Window } from "./Window.svelte";
|
|
73
78
|
export { default as WindowBar } from "./WindowBar.svelte";
|
|
74
|
-
export { useAccent, useDensity, useHue, useLabelMode, useMotion, useRainbow, useShape } from "./engines.svelte.js";
|
|
79
|
+
export { useAccent, useDensity, useGlyphs, useHue, useLabelMode, useLayout, useLight, useMotion, useRainbow, useShape } from "./engines.svelte.js";
|
|
75
80
|
export { useConfirm, useDialogKeys } from "./confirm.svelte.js";
|
|
76
81
|
export { useFieldName } from "./fieldName.js";
|
|
77
82
|
export { deviceGlyph } from "./fortressParts.js";
|
|
78
|
-
export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconTrash, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
|
|
83
|
+
export { glyphFor, IconBack, IconCalendar, IconCancel, IconClock, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconMore, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconTrash, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
|
|
79
84
|
export * from "./portalHue.svelte.js";
|
|
80
85
|
export { useTipBubble } from "./bubble.svelte.js";
|
|
81
86
|
export * from "./useDragArmed.svelte.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glimstone/svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "GlimStone's components for Svelte",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"build": "svelte-package -i src -o dist"
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
|
-
"@glimstone/core": "
|
|
149
|
+
"@glimstone/core": "5.0.0"
|
|
150
150
|
},
|
|
151
151
|
"peerDependencies": {
|
|
152
152
|
"@internationalized/date": "^3.12.4",
|
package/dist/AboutCard.svelte
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { Snippet } from "svelte";
|
|
3
|
-
|
|
4
|
-
export interface AboutCardProps {
|
|
5
|
-
text: {
|
|
6
|
-
title: string;
|
|
7
|
-
body: string;
|
|
8
|
-
coffee: string;
|
|
9
|
-
coffeeButton: string;
|
|
10
|
-
cryptoButton?: string;
|
|
11
|
-
paypalButton?: string;
|
|
12
|
-
report: string;
|
|
13
|
-
repoButton: string;
|
|
14
|
-
discordButton?: string;
|
|
15
|
-
mailButton: string;
|
|
16
|
-
mailSubject: string;
|
|
17
|
-
version: string;
|
|
18
|
-
unreleased: (version: string) => string;
|
|
19
|
-
/** The Help card's heading. Without it the card draws none. */
|
|
20
|
-
helpTitle?: string;
|
|
21
|
-
};
|
|
22
|
-
version: string | null;
|
|
23
|
-
glimstoneVersion: string;
|
|
24
|
-
repoUrl: string;
|
|
25
|
-
repoGlyph?: Snippet;
|
|
26
|
-
glimstoneRepoUrl: string;
|
|
27
|
-
onCoffee: () => void;
|
|
28
|
-
coffeeArt: Snippet;
|
|
29
|
-
cryptoGlyph?: Snippet;
|
|
30
|
-
paypalGlyph?: Snippet;
|
|
31
|
-
onPaypal?: () => void;
|
|
32
|
-
onCrypto?: () => void;
|
|
33
|
-
discordUrl?: string;
|
|
34
|
-
discordGlyph?: Snippet;
|
|
35
|
-
mailAddress?: string;
|
|
36
|
-
mailGlyph?: Snippet;
|
|
37
|
-
openUrl?: (url: string) => void;
|
|
38
|
-
hueIndex?: number;
|
|
39
|
-
}
|
|
40
|
-
</script>
|
|
41
|
-
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
import { openInBrowser, versionLink, warnDeprecated, type VersionRow } from "@glimstone/core";
|
|
44
|
-
import Card from "./Card.svelte";
|
|
45
|
-
import InfoAboutCard from "./InfoAboutCard.svelte";
|
|
46
|
-
import InfoHelpCard from "./InfoHelpCard.svelte";
|
|
47
|
-
|
|
48
|
-
// The 3.2.0 props of the single About card, laid out as the Info tile: the
|
|
49
|
-
// About card under `text.title`, the Version card under `text.version` with
|
|
50
|
-
// the app and GlimStone as its rows, and the Help card. Deprecated for
|
|
51
|
-
// InfoTile, which adds the update state, the components and the bug report.
|
|
52
|
-
let {
|
|
53
|
-
text,
|
|
54
|
-
version,
|
|
55
|
-
glimstoneVersion,
|
|
56
|
-
repoUrl,
|
|
57
|
-
repoGlyph,
|
|
58
|
-
glimstoneRepoUrl,
|
|
59
|
-
onCoffee,
|
|
60
|
-
coffeeArt,
|
|
61
|
-
cryptoGlyph,
|
|
62
|
-
paypalGlyph,
|
|
63
|
-
onPaypal,
|
|
64
|
-
onCrypto,
|
|
65
|
-
discordUrl,
|
|
66
|
-
discordGlyph,
|
|
67
|
-
mailAddress,
|
|
68
|
-
mailGlyph,
|
|
69
|
-
openUrl = openInBrowser,
|
|
70
|
-
hueIndex,
|
|
71
|
-
}: AboutCardProps = $props();
|
|
72
|
-
warnDeprecated("AboutCard");
|
|
73
|
-
|
|
74
|
-
const rows: VersionRow[] = $derived([
|
|
75
|
-
...(version ? [{ name: text.version, version, repoUrl }] : []),
|
|
76
|
-
{ name: "GlimStone", version: glimstoneVersion, repoUrl: glimstoneRepoUrl },
|
|
77
|
-
]);
|
|
78
|
-
const at = (offset: number) => (hueIndex === undefined ? undefined : hueIndex + offset);
|
|
79
|
-
</script>
|
|
80
|
-
|
|
81
|
-
<div data-glim="AboutCard" style="display: contents">
|
|
82
|
-
<Card title={text.version} hueIndex={at(0)}>
|
|
83
|
-
<ul class="glim-version-rows">
|
|
84
|
-
{#each rows as row (row.name)}
|
|
85
|
-
{@const link = versionLink(row)}
|
|
86
|
-
<li class="glim-version-row">
|
|
87
|
-
<span class="glim-version-name"><span class="glim-version-part">{row.name}</span></span>
|
|
88
|
-
{#if link.href}
|
|
89
|
-
<a href={link.href} target="_blank" rel="noopener noreferrer" class="glim-num glim-version-number">{link.shown}</a>
|
|
90
|
-
{:else}
|
|
91
|
-
<span class="glim-num glim-version-number">{link.released ? link.shown : text.unreleased(link.shown)}</span>
|
|
92
|
-
{/if}
|
|
93
|
-
</li>
|
|
94
|
-
{/each}
|
|
95
|
-
</ul>
|
|
96
|
-
</Card>
|
|
97
|
-
<InfoHelpCard
|
|
98
|
-
hueIndex={at(1)}
|
|
99
|
-
text={{
|
|
100
|
-
title: text.helpTitle,
|
|
101
|
-
report: text.report,
|
|
102
|
-
repoButton: text.repoButton,
|
|
103
|
-
discordButton: text.discordButton,
|
|
104
|
-
mailButton: text.mailButton,
|
|
105
|
-
mailSubject: text.mailSubject,
|
|
106
|
-
}}
|
|
107
|
-
{repoUrl}
|
|
108
|
-
{repoGlyph}
|
|
109
|
-
{discordUrl}
|
|
110
|
-
{discordGlyph}
|
|
111
|
-
{mailAddress}
|
|
112
|
-
{mailGlyph}
|
|
113
|
-
{openUrl}
|
|
114
|
-
/>
|
|
115
|
-
<InfoAboutCard hueIndex={at(2)} {text} {onCoffee} {coffeeArt} {onPaypal} {paypalGlyph} {onCrypto} {cryptoGlyph} />
|
|
116
|
-
</div>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from "svelte";
|
|
2
|
-
export interface AboutCardProps {
|
|
3
|
-
text: {
|
|
4
|
-
title: string;
|
|
5
|
-
body: string;
|
|
6
|
-
coffee: string;
|
|
7
|
-
coffeeButton: string;
|
|
8
|
-
cryptoButton?: string;
|
|
9
|
-
paypalButton?: string;
|
|
10
|
-
report: string;
|
|
11
|
-
repoButton: string;
|
|
12
|
-
discordButton?: string;
|
|
13
|
-
mailButton: string;
|
|
14
|
-
mailSubject: string;
|
|
15
|
-
version: string;
|
|
16
|
-
unreleased: (version: string) => string;
|
|
17
|
-
/** The Help card's heading. Without it the card draws none. */
|
|
18
|
-
helpTitle?: string;
|
|
19
|
-
};
|
|
20
|
-
version: string | null;
|
|
21
|
-
glimstoneVersion: string;
|
|
22
|
-
repoUrl: string;
|
|
23
|
-
repoGlyph?: Snippet;
|
|
24
|
-
glimstoneRepoUrl: string;
|
|
25
|
-
onCoffee: () => void;
|
|
26
|
-
coffeeArt: Snippet;
|
|
27
|
-
cryptoGlyph?: Snippet;
|
|
28
|
-
paypalGlyph?: Snippet;
|
|
29
|
-
onPaypal?: () => void;
|
|
30
|
-
onCrypto?: () => void;
|
|
31
|
-
discordUrl?: string;
|
|
32
|
-
discordGlyph?: Snippet;
|
|
33
|
-
mailAddress?: string;
|
|
34
|
-
mailGlyph?: Snippet;
|
|
35
|
-
openUrl?: (url: string) => void;
|
|
36
|
-
hueIndex?: number;
|
|
37
|
-
}
|
|
38
|
-
declare const AboutCard: import("svelte").Component<AboutCardProps, {}, "">;
|
|
39
|
-
type AboutCard = ReturnType<typeof AboutCard>;
|
|
40
|
-
export default AboutCard;
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { Snippet } from "svelte";
|
|
3
|
-
|
|
4
|
-
export interface DropdownListboxProps {
|
|
5
|
-
/** Whether the panel is mounted. The caller owns the trigger; only the
|
|
6
|
-
* panel is shared. */
|
|
7
|
-
open: boolean;
|
|
8
|
-
/** Called when the panel dismisses itself (outside click, Escape, scroll,
|
|
9
|
-
* resize). Picking an option does not call it: a single-select list closes
|
|
10
|
-
* itself at the call site, a multi-select one stays open. */
|
|
11
|
-
onClose: () => void;
|
|
12
|
-
/** The trigger, which anchors the panel and is exempt from the outside-click
|
|
13
|
-
* dismissal so clicking it does not close and reopen the list. */
|
|
14
|
-
triggerRef: HTMLElement | null | undefined;
|
|
15
|
-
/** Accessible name for the listbox, normally the same label the trigger
|
|
16
|
-
* carries. */
|
|
17
|
-
label: string;
|
|
18
|
-
/** `aria-multiselectable`, for a checkbox multi-select list. */
|
|
19
|
-
multiselectable?: boolean;
|
|
20
|
-
/** The `role="option"` buttons. */
|
|
21
|
-
children: Snippet;
|
|
22
|
-
}
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<script lang="ts">
|
|
26
|
-
import { tick } from "svelte";
|
|
27
|
-
import { computeBubblePosition, focusByLetter, isTypeahead, warnDeprecated } from "@glimstone/core";
|
|
28
|
-
import { lift } from "./lift.js";
|
|
29
|
-
import { usePortalHue } from "./portalHue.svelte.js";
|
|
30
|
-
import { css } from "./style.js";
|
|
31
|
-
|
|
32
|
-
// The `role="listbox"` panel a button-opens-a-list picker drops open. It is
|
|
33
|
-
// lifted to the portal target, because a card with `overflow: hidden` clips
|
|
34
|
-
// an absolutely positioned panel whatever its z-index, and placed with
|
|
35
|
-
// computeBubblePosition, which clamps it into the viewport and flips it above
|
|
36
|
-
// the trigger when needed. The panel takes the trigger's width and is centred
|
|
37
|
-
// on it with `translateX(-50%)`, since computeBubblePosition returns the
|
|
38
|
-
// centre.
|
|
39
|
-
//
|
|
40
|
-
// Kept for the apps that already use it; Select keeps focus on its trigger
|
|
41
|
-
// and adds typeahead.
|
|
42
|
-
let { open, onClose, triggerRef, label, multiselectable, children }: DropdownListboxProps = $props();
|
|
43
|
-
warnDeprecated("DropdownListbox");
|
|
44
|
-
|
|
45
|
-
/** The gap to the trigger and the least distance from the viewport's edge, 4px to match `mt-1`. */
|
|
46
|
-
const GAP = 4;
|
|
47
|
-
|
|
48
|
-
let panel = $state<HTMLDivElement | null>(null);
|
|
49
|
-
let pos = $state<{ left: number; top: number; width: number } | null>(null);
|
|
50
|
-
// The portal leaves the trigger's rainbow subtree, so the panel copies the
|
|
51
|
-
// trigger's hue.
|
|
52
|
-
const hue = usePortalHue(() => open, () => triggerRef);
|
|
53
|
-
// Whether focus was in the list as it closed. It is read the moment `open`
|
|
54
|
-
// turns false, before the list leaves the page: a browser that blurs a
|
|
55
|
-
// removed element reports the focus gone before the list is.
|
|
56
|
-
let focusWasInside = false;
|
|
57
|
-
let wasOpen = false;
|
|
58
|
-
$effect.pre(() => {
|
|
59
|
-
if (wasOpen && !open) focusWasInside = !!panel?.contains(document.activeElement);
|
|
60
|
-
wasOpen = open;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const options = () => [...(panel?.querySelectorAll<HTMLElement>('[role="option"]') ?? [])];
|
|
64
|
-
|
|
65
|
-
function place(el: HTMLDivElement, trigger: HTMLElement) {
|
|
66
|
-
const rect = trigger.getBoundingClientRect();
|
|
67
|
-
// Option labels wrap against the width, so it is set before the height is read.
|
|
68
|
-
el.style.width = `${rect.width}px`;
|
|
69
|
-
const viewport = {
|
|
70
|
-
width: document.documentElement.clientWidth || window.innerWidth,
|
|
71
|
-
height: document.documentElement.clientHeight || window.innerHeight,
|
|
72
|
-
};
|
|
73
|
-
const { left, top } = computeBubblePosition(rect, { width: rect.width, height: el.offsetHeight }, viewport, GAP);
|
|
74
|
-
pos = { left, top, width: rect.width };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// A fixed panel that has lost its trigger reads as broken, so an outside
|
|
78
|
-
// press, Escape, scroll or resize closes it. The panel itself is exempt from
|
|
79
|
-
// the outside press, or pressing an option would unmount the list before its
|
|
80
|
-
// click landed. A scroll inside the panel, which scrolls a long list itself,
|
|
81
|
-
// does not close it either.
|
|
82
|
-
$effect(() => {
|
|
83
|
-
if (!open) return;
|
|
84
|
-
const onPointerDown = (e: MouseEvent) => {
|
|
85
|
-
const target = e.target as Node;
|
|
86
|
-
if (panel?.contains(target) || triggerRef?.contains(target)) return;
|
|
87
|
-
onClose();
|
|
88
|
-
};
|
|
89
|
-
const onKey = (e: KeyboardEvent) => {
|
|
90
|
-
if (e.key === "Escape") onClose();
|
|
91
|
-
};
|
|
92
|
-
const onScroll = (e: Event) => {
|
|
93
|
-
if (e.target instanceof Node && panel?.contains(e.target)) return;
|
|
94
|
-
onClose();
|
|
95
|
-
};
|
|
96
|
-
const onResize = () => onClose();
|
|
97
|
-
document.addEventListener("mousedown", onPointerDown);
|
|
98
|
-
document.addEventListener("keydown", onKey);
|
|
99
|
-
window.addEventListener("scroll", onScroll, true);
|
|
100
|
-
window.addEventListener("resize", onResize);
|
|
101
|
-
return () => {
|
|
102
|
-
document.removeEventListener("mousedown", onPointerDown);
|
|
103
|
-
document.removeEventListener("keydown", onKey);
|
|
104
|
-
window.removeEventListener("scroll", onScroll, true);
|
|
105
|
-
window.removeEventListener("resize", onResize);
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Measured and placed before paint, so the panel never jumps from its
|
|
110
|
-
// off-screen parking spot. Focus then moves to the selected option, so a
|
|
111
|
-
// keyboard user reaches the list, but only once the panel stands at its real
|
|
112
|
-
// place: focusing an option parked off-screen makes the browser scroll to
|
|
113
|
-
// it, and that scroll closes the list.
|
|
114
|
-
$effect.pre(() => {
|
|
115
|
-
if (!open) {
|
|
116
|
-
pos = null;
|
|
117
|
-
// Focus goes back to the trigger only if it was in the list; a press
|
|
118
|
-
// elsewhere has already put it where somebody wants it.
|
|
119
|
-
if (focusWasInside) triggerRef?.focus();
|
|
120
|
-
focusWasInside = false;
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!panel || !triggerRef) return;
|
|
124
|
-
place(panel, triggerRef);
|
|
125
|
-
tick().then(() => {
|
|
126
|
-
const opts = options();
|
|
127
|
-
const active = opts.find((o) => o.getAttribute("aria-selected") === "true") ?? opts[0];
|
|
128
|
-
active?.scrollIntoView?.({ block: "nearest" });
|
|
129
|
-
active?.focus();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// Arrows, Home, End and a typed letter move between the options so every
|
|
134
|
-
// listbox behaves alike. Enter and Space need nothing: the options are real
|
|
135
|
-
// buttons.
|
|
136
|
-
function onPanelKey(e: KeyboardEvent) {
|
|
137
|
-
if (isTypeahead(e)) {
|
|
138
|
-
if (focusByLetter(options(), e.key)) e.preventDefault();
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) return;
|
|
142
|
-
const opts = options();
|
|
143
|
-
if (opts.length === 0) return;
|
|
144
|
-
e.preventDefault();
|
|
145
|
-
const at = opts.indexOf(document.activeElement as HTMLElement);
|
|
146
|
-
let next: number;
|
|
147
|
-
if (e.key === "Home") next = 0;
|
|
148
|
-
else if (e.key === "End") next = opts.length - 1;
|
|
149
|
-
else {
|
|
150
|
-
const dir = e.key === "ArrowDown" ? 1 : -1;
|
|
151
|
-
next = at < 0 ? (dir === 1 ? 0 : opts.length - 1) : (at + dir + opts.length) % opts.length;
|
|
152
|
-
}
|
|
153
|
-
opts[next]!.scrollIntoView?.({ block: "nearest" });
|
|
154
|
-
opts[next]!.focus();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
</script>
|
|
158
|
-
|
|
159
|
-
{#if open}
|
|
160
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions, a11y_interactive_supports_focus -->
|
|
161
|
-
<div
|
|
162
|
-
{@attach lift}
|
|
163
|
-
bind:this={panel}
|
|
164
|
-
data-glim="DropdownListbox"
|
|
165
|
-
role="listbox"
|
|
166
|
-
onkeydown={onPanelKey}
|
|
167
|
-
aria-multiselectable={multiselectable ? "true" : undefined}
|
|
168
|
-
aria-label={label}
|
|
169
|
-
class={`glim-listbox glim-fade${hue.className ? ` ${hue.className}` : ""}`}
|
|
170
|
-
style:left={`${pos?.left ?? -9999}px`}
|
|
171
|
-
style:top={`${pos?.top ?? -9999}px`}
|
|
172
|
-
style:width={pos ? `${pos.width}px` : undefined}
|
|
173
|
-
style:transform="translateX(-50%)"
|
|
174
|
-
style={css(hue.style)}
|
|
175
|
-
>
|
|
176
|
-
{@render children()}
|
|
177
|
-
</div>
|
|
178
|
-
{/if}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from "svelte";
|
|
2
|
-
export interface DropdownListboxProps {
|
|
3
|
-
/** Whether the panel is mounted. The caller owns the trigger; only the
|
|
4
|
-
* panel is shared. */
|
|
5
|
-
open: boolean;
|
|
6
|
-
/** Called when the panel dismisses itself (outside click, Escape, scroll,
|
|
7
|
-
* resize). Picking an option does not call it: a single-select list closes
|
|
8
|
-
* itself at the call site, a multi-select one stays open. */
|
|
9
|
-
onClose: () => void;
|
|
10
|
-
/** The trigger, which anchors the panel and is exempt from the outside-click
|
|
11
|
-
* dismissal so clicking it does not close and reopen the list. */
|
|
12
|
-
triggerRef: HTMLElement | null | undefined;
|
|
13
|
-
/** Accessible name for the listbox, normally the same label the trigger
|
|
14
|
-
* carries. */
|
|
15
|
-
label: string;
|
|
16
|
-
/** `aria-multiselectable`, for a checkbox multi-select list. */
|
|
17
|
-
multiselectable?: boolean;
|
|
18
|
-
/** The `role="option"` buttons. */
|
|
19
|
-
children: Snippet;
|
|
20
|
-
}
|
|
21
|
-
declare const DropdownListbox: import("svelte").Component<DropdownListboxProps, {}, "">;
|
|
22
|
-
type DropdownListbox = ReturnType<typeof DropdownListbox>;
|
|
23
|
-
export default DropdownListbox;
|