@glimstone/svelte 4.5.4 → 4.5.5

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.
@@ -0,0 +1,148 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from "svelte";
3
+ import type { PickGroup, PickItem, PickerText } from "@glimstone/core";
4
+ import type { WindowAction } from "./WindowFootRow.svelte";
5
+
6
+ export type { PickGroup, PickerText, TileMark } from "@glimstone/core";
7
+
8
+ export type PickerItem = PickItem<Snippet>;
9
+
10
+ export interface PickerWindowProps {
11
+ /** The notch's words, also the window's accessible name. */
12
+ title: string;
13
+ /** What the picker is for, as the (i) in its notch. */
14
+ hint?: string;
15
+ /** The choices, sorted by their names in the page's language. */
16
+ items: PickerItem[];
17
+ /** The groups the items name, in the order they stand. Without them the tiles stand in one. */
18
+ groups?: PickGroup[];
19
+ text: PickerText;
20
+ onPick: (id: string) => void;
21
+ /** The picked tile's form, which takes the tiles' place until it is gone again. */
22
+ children?: Snippet;
23
+ /** The form's buttons, the forward one last. Cancel and Back stand before them. */
24
+ actions?: WindowAction[];
25
+ /** Back from the form to the tiles, with the search as it was. */
26
+ onBack?: () => void;
27
+ /** Called for every way out: the foot, Escape and a press beside the window. */
28
+ onClose: () => void;
29
+ }
30
+ </script>
31
+
32
+ <script lang="ts">
33
+ import { tick } from "svelte";
34
+ import {
35
+ fill,
36
+ holdPickHeight,
37
+ isTileMark,
38
+ pageLocale,
39
+ pickSearchKey,
40
+ pickSections,
41
+ pickTileKey,
42
+ pickTileStyle,
43
+ windowFocusTarget,
44
+ } from "@glimstone/core";
45
+ import BrandMark from "./BrandMark.svelte";
46
+ import { IconBack, IconClose } from "./glyphs.js";
47
+ import InfoBubble from "./InfoBubble.svelte";
48
+ import ReadmeButton from "./ReadmeButton.svelte";
49
+ import { css } from "./style.js";
50
+ import Window from "./Window.svelte";
51
+
52
+ // A big picker ("Pickers and wizards" in design-language.md): the app's choices
53
+ // as brand tiles in their groups, under a search that stands open at the top
54
+ // end and narrows all of them at once. The arrows move across the grid, and a
55
+ // click or Enter on a tile hands its id to onPick. The caller decides what
56
+ // follows: it closes the window, or passes the picked tile's form as
57
+ // children, which takes the tiles' place with Back and the form's actions in
58
+ // the foot.
59
+ let { title, hint, items, groups = [], text, onPick, children, actions = [], onBack, onClose }: PickerWindowProps = $props();
60
+
61
+ let query = $state("");
62
+ let card: HTMLElement | null = $state(null);
63
+ let search: HTMLInputElement | undefined = $state();
64
+ let scroll: HTMLDivElement | undefined = $state();
65
+ const form = $derived(!!children);
66
+ $effect(() => {
67
+ void form;
68
+ void tick().then(() => {
69
+ if (scroll) holdPickHeight(scroll);
70
+ if (card) windowFocusTarget(card)?.focus();
71
+ });
72
+ });
73
+ // Back keeps the window open, so it returns false.
74
+ const back = $derived<WindowAction>({
75
+ label: text.back,
76
+ labelKey: "common.back",
77
+ glyph: IconBack,
78
+ onClick: () => {
79
+ onBack?.();
80
+ return false;
81
+ },
82
+ });
83
+
84
+ const sections = $derived(pickSections(items, groups, query, pageLocale()));
85
+ function used(e: KeyboardEvent, handled: boolean) {
86
+ if (!handled) return;
87
+ e.preventDefault();
88
+ e.stopPropagation();
89
+ }
90
+ function onTileKey(e: KeyboardEvent) {
91
+ if (e.target !== e.currentTarget) used(e, pickTileKey(e.key, e.target as Element, e.currentTarget as HTMLElement, search ?? null));
92
+ }
93
+ </script>
94
+
95
+ {#snippet notch()}{title}<InfoBubble tip={hint ?? ""} onAccent />{/snippet}
96
+
97
+ <Window
98
+ data-glim="PickerWindow"
99
+ {title}
100
+ drawn={hint ? notch : undefined}
101
+ class="glim-pick-window"
102
+ bind:ref={card}
103
+ text={{ cancel: text.cancel, close: text.close }}
104
+ actions={form ? [back, ...actions] : [{ label: text.close, labelKey: "common.close", glyph: IconClose, wayOut: true }]}
105
+ {onClose}
106
+ >
107
+ {#if children}
108
+ {@render children()}
109
+ {:else}
110
+ <input
111
+ bind:this={search}
112
+ bind:value={query}
113
+ class="glim-input glim-pick-search"
114
+ type="search"
115
+ aria-label={text.search}
116
+ placeholder={text.search}
117
+ spellcheck="false"
118
+ autocomplete="off"
119
+ onkeydown={(e) => used(e, pickSearchKey(e.key, query, scroll ?? null, () => (query = "")))}
120
+ />
121
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
122
+ <div bind:this={scroll} class="glim-pick-scroll" onkeydown={onTileKey}>
123
+ {#if sections.length === 0}
124
+ <p class="glim-pick-none">{fill(text.none, { query: query.trim() })}</p>
125
+ {:else}
126
+ {#each sections as s (s.id)}
127
+ <section class="glim-pick-section">
128
+ {#if s.title}<h3 class="glim-eyebrow">{s.title}</h3>{/if}
129
+ <ul class="glim-provider-pick">
130
+ {#each s.items as item (item.id)}
131
+ {#snippet brand()}{#if isTileMark(item.mark)}<BrandMark svg={item.mark.svg} />{/if}{/snippet}
132
+ <li style={css(pickTileStyle(item.mark))}>
133
+ <ReadmeButton
134
+ brand="house"
135
+ parts={[{ name: item.label, onClick: () => onPick(item.id) }]}
136
+ mark={isTileMark(item.mark) ? brand : (item.mark as Snippet | undefined)}
137
+ markClass={isTileMark(item.mark) ? undefined : "glim-house-mark"}
138
+ hint={item.hint}
139
+ />
140
+ </li>
141
+ {/each}
142
+ </ul>
143
+ </section>
144
+ {/each}
145
+ {/if}
146
+ </div>
147
+ {/if}
148
+ </Window>
@@ -0,0 +1,28 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { PickGroup, PickItem, PickerText } from "@glimstone/core";
3
+ import type { WindowAction } from "./WindowFootRow.svelte";
4
+ export type { PickGroup, PickerText, TileMark } from "@glimstone/core";
5
+ export type PickerItem = PickItem<Snippet>;
6
+ export interface PickerWindowProps {
7
+ /** The notch's words, also the window's accessible name. */
8
+ title: string;
9
+ /** What the picker is for, as the (i) in its notch. */
10
+ hint?: string;
11
+ /** The choices, sorted by their names in the page's language. */
12
+ items: PickerItem[];
13
+ /** The groups the items name, in the order they stand. Without them the tiles stand in one. */
14
+ groups?: PickGroup[];
15
+ text: PickerText;
16
+ onPick: (id: string) => void;
17
+ /** The picked tile's form, which takes the tiles' place until it is gone again. */
18
+ children?: Snippet;
19
+ /** The form's buttons, the forward one last. Cancel and Back stand before them. */
20
+ actions?: WindowAction[];
21
+ /** Back from the form to the tiles, with the search as it was. */
22
+ onBack?: () => void;
23
+ /** Called for every way out: the foot, Escape and a press beside the window. */
24
+ onClose: () => void;
25
+ }
26
+ declare const PickerWindow: import("svelte").Component<PickerWindowProps, {}, "">;
27
+ type PickerWindow = ReturnType<typeof PickerWindow>;
28
+ export default PickerWindow;
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export { default as NumberField, type NumberFieldProps } from "./NumberField.sve
42
42
  export { default as PasswordField, type PasswordFieldProps } from "./PasswordField.svelte";
43
43
  export { default as PathField, type PathFieldProps } from "./PathField.svelte";
44
44
  export { default as PaypalDialog, type PaypalDialogProps, type PaypalSelectorProps } from "./PaypalDialog.svelte";
45
+ export { default as PickerWindow, type PickGroup, type PickerItem, type PickerText, type PickerWindowProps, type TileMark } from "./PickerWindow.svelte";
45
46
  export { default as Pill, type PillProps, type PillTone } from "./Pill.svelte";
46
47
  export { default as Popover, type PopoverProps } from "./Popover.svelte";
47
48
  export { default as PresenceBadges, type PresenceBadgesProps } from "./PresenceBadges.svelte";
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@ export { default as NumberField } from "./NumberField.svelte";
42
42
  export { default as PasswordField } from "./PasswordField.svelte";
43
43
  export { default as PathField } from "./PathField.svelte";
44
44
  export { default as PaypalDialog } from "./PaypalDialog.svelte";
45
+ export { default as PickerWindow } from "./PickerWindow.svelte";
45
46
  export { default as Pill } from "./Pill.svelte";
46
47
  export { default as Popover } from "./Popover.svelte";
47
48
  export { default as PresenceBadges } from "./PresenceBadges.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/svelte",
3
- "version": "4.5.4",
3
+ "version": "4.5.5",
4
4
  "description": "GlimStone's components for Svelte",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -141,7 +141,7 @@
141
141
  "build": "svelte-package -i src -o dist"
142
142
  },
143
143
  "dependencies": {
144
- "@glimstone/core": "4.5.4"
144
+ "@glimstone/core": "4.5.5"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@internationalized/date": "^3.12.4",