@glimstone/svelte 4.5.4 → 4.5.6

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,168 @@
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, while the tiles show, 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
+ pickerHue,
40
+ pickSearchKey,
41
+ pickSections,
42
+ pickTileKey,
43
+ pickTileStyle,
44
+ windowFocusTarget,
45
+ } from "@glimstone/core";
46
+ import BrandMark from "./BrandMark.svelte";
47
+ import GlyphField from "./GlyphField.svelte";
48
+ import { IconBack, IconClose, IconSearch } from "./glyphs.js";
49
+ import IconButton from "./IconButton.svelte";
50
+ import InfoBubble from "./InfoBubble.svelte";
51
+ import ReadmeButton from "./ReadmeButton.svelte";
52
+ import { css } from "./style.js";
53
+ import Window from "./Window.svelte";
54
+
55
+ // A big picker ("Pickers and wizards" in design-language.md): the app's choices
56
+ // as brand tiles in their groups, under a search that stands open at the top
57
+ // end and narrows all of them at once. The arrows move across the grid, and a
58
+ // click or Enter on a tile hands its id to onPick. The caller decides what
59
+ // follows: it closes the window, or passes the picked tile's form as
60
+ // children, which takes the tiles' place with Back and the form's actions in
61
+ // the foot.
62
+ let { title, hint, items, groups = [], text, onPick, children, actions = [], onBack, onClose }: PickerWindowProps = $props();
63
+
64
+ let query = $state("");
65
+ const hue = pickerHue();
66
+ let card: HTMLElement | null = $state(null);
67
+ let search: HTMLInputElement | null = $state(null);
68
+ let scroll: HTMLDivElement | undefined = $state();
69
+ const form = $derived(!!children);
70
+ $effect(() => {
71
+ void form;
72
+ void tick().then(() => {
73
+ if (scroll) holdPickHeight(scroll);
74
+ if (card) windowFocusTarget(card)?.focus();
75
+ });
76
+ });
77
+ // Back keeps the window open, so it returns false.
78
+ const back = $derived<WindowAction>({
79
+ label: text.back,
80
+ labelKey: "common.back",
81
+ glyph: IconBack,
82
+ onClick: () => {
83
+ onBack?.();
84
+ return false;
85
+ },
86
+ });
87
+
88
+ const sections = $derived(pickSections(items, groups, query, pageLocale()));
89
+ function used(e: KeyboardEvent, handled: boolean) {
90
+ if (!handled) return;
91
+ e.preventDefault();
92
+ e.stopPropagation();
93
+ }
94
+ function onTileKey(e: KeyboardEvent) {
95
+ if (e.target !== e.currentTarget) used(e, pickTileKey(e.key, e.target as Element, e.currentTarget as HTMLElement, search ?? null));
96
+ }
97
+ </script>
98
+
99
+ {#snippet clearButton()}
100
+ <IconButton
101
+ tip={text.clear}
102
+ glyph={IconClose}
103
+ onclick={() => {
104
+ query = "";
105
+ search?.focus();
106
+ }}
107
+ />
108
+ {/snippet}
109
+
110
+ {#snippet notch()}{title}<InfoBubble tip={hint ?? ""} onAccent />{/snippet}
111
+
112
+ <Window
113
+ data-glim="PickerWindow"
114
+ {title}
115
+ drawn={hint ? notch : undefined}
116
+ class={["glim-pick-window", form && "glim-pick-window--form", hue && "glim-hue"].filter(Boolean).join(" ")}
117
+ style={css(hue ?? undefined)}
118
+ bind:ref={card}
119
+ text={{ cancel: text.cancel, close: text.close }}
120
+ actions={form ? [back, ...actions] : [{ label: text.close, labelKey: "common.close", glyph: IconClose, wayOut: true }]}
121
+ closeOnBackdrop={!form}
122
+ {onClose}
123
+ >
124
+ {#if children}
125
+ {@render children()}
126
+ {:else}
127
+ <GlyphField
128
+ bind:ref={search}
129
+ bind:value={query}
130
+ class="glim-pick-search"
131
+ glyph={IconSearch}
132
+ type="search"
133
+ label={text.search}
134
+ placeholder={text.search}
135
+ spellcheck="false"
136
+ autocomplete="off"
137
+ onkeydown={(e) => used(e, pickSearchKey(e.key, query, scroll ?? null, () => (query = "")))}
138
+ after={query ? clearButton : undefined}
139
+ />
140
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
141
+ <div bind:this={scroll} class="glim-pick-scroll" onkeydown={onTileKey}>
142
+ {#if sections.length === 0}
143
+ <p class="glim-pick-none">{fill(text.none, { query: query.trim() })}</p>
144
+ {:else}
145
+ {#each sections as s (s.id)}
146
+ <section class="glim-pick-section">
147
+ {#if s.title}<h3 class="glim-eyebrow">{s.title}</h3>{/if}
148
+ <ul class="glim-provider-pick">
149
+ {#each s.items as item (item.id)}
150
+ {#snippet brand()}{#if isTileMark(item.mark)}<BrandMark svg={item.mark.svg} />{/if}{/snippet}
151
+ <li style={css(pickTileStyle(item.mark))}>
152
+ <ReadmeButton
153
+ brand="house"
154
+ parts={[{ name: item.label, sub: item.sub, onClick: () => onPick(item.id) }]}
155
+ mark={isTileMark(item.mark) ? brand : (item.mark as Snippet | undefined)}
156
+ markClass={isTileMark(item.mark) ? undefined : "glim-house-mark"}
157
+ hint={item.hint}
158
+ tip={item.tip}
159
+ />
160
+ </li>
161
+ {/each}
162
+ </ul>
163
+ </section>
164
+ {/each}
165
+ {/if}
166
+ </div>
167
+ {/if}
168
+ </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, while the tiles show, 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;
@@ -17,6 +17,8 @@
17
17
  art?: Snippet;
18
18
  /** The "(i)" at the end of the unit, for what the name cannot say. */
19
19
  hint?: string;
20
+ /** A few words in the first part's bubble, for a name that needs no (i). */
21
+ tip?: string;
20
22
  /** Holds the second lines in view while one reports what it did, such as "Copied". */
21
23
  note?: boolean;
22
24
  /** The second line of a unit whose first part has neither `href` nor `onClick`. */
@@ -29,7 +31,9 @@
29
31
 
30
32
  <script lang="ts">
31
33
  import { keepReadmeFit, readmePartClass, readmePartLabel, readmeSoon, readmeUnitClass } from "@glimstone/core";
34
+ import { useTipBubble } from "./bubble.svelte.js";
32
35
  import InfoBubble from "./InfoBubble.svelte";
36
+ import TipBubble from "./TipBubble.svelte";
33
37
 
34
38
  // A button in the shape of the README's download buttons, on the App tab and
35
39
  // the About card ("The App tab" in design-language.md). The first part carries
@@ -38,7 +42,7 @@
38
42
  // brand's colour ("Brand tiles"). A link where a part leads to a file or a
39
43
  // listing, a button where it does something on the page, and a quiet unit with
40
44
  // "Soon" as its second line where the listing does not exist yet.
41
- let { brand, parts, mark, markClass, art, hint, note, soonLabel, onLinkClick }: ReadmeButtonProps = $props();
45
+ let { brand, parts, mark, markClass, art, hint, tip, note, soonLabel, onLinkClick }: ReadmeButtonProps = $props();
42
46
 
43
47
  let root: HTMLDivElement;
44
48
  const soon = $derived(readmeSoon(parts));
@@ -49,6 +53,22 @@
49
53
  });
50
54
 
51
55
  const sub = (part: ReadmePart) => (soon ? soonLabel : part.sub);
56
+
57
+ const tooltip = useTipBubble(() => tip);
58
+ // The first part is the bubble's trigger; the segments after it say nothing of their own.
59
+ const tipped = (i: number) =>
60
+ i === 0
61
+ ? {
62
+ "aria-describedby": tooltip.describedBy,
63
+ onmouseenter: tooltip.show,
64
+ onmouseleave: tooltip.hide,
65
+ onfocus: tooltip.showOnFocus,
66
+ onblur: tooltip.hide,
67
+ }
68
+ : {};
69
+ const trigger = (el: HTMLElement) => {
70
+ tooltip.trigger = el;
71
+ };
52
72
  </script>
53
73
 
54
74
  {#snippet face(part: ReadmePart, i: number)}
@@ -68,15 +88,16 @@
68
88
  <div data-glim="ReadmeButton" bind:this={root} class={readmeUnitClass(brand, parts.length, !!note, soon)}>
69
89
  {#each parts as part, i (i)}
70
90
  {#if soon}
71
- <span class={readmePartClass(i, soon)} aria-disabled="true" aria-label={readmePartLabel(part, sub(part))}>{@render face(part, i)}</span>
91
+ <span {...tipped(i)} {@attach i === 0 && trigger} class={readmePartClass(i, soon)} aria-disabled="true" aria-label={readmePartLabel(part, sub(part))}>{@render face(part, i)}</span>
72
92
  {:else if part.href}
73
- <a href={part.href} target="_blank" rel="noreferrer noopener" onclick={onLinkClick} aria-label={readmePartLabel(part, sub(part))} class={readmePartClass(i, soon)}>
93
+ <a {...tipped(i)} {@attach i === 0 && trigger} href={part.href} target="_blank" rel="noreferrer noopener" onclick={onLinkClick} aria-label={readmePartLabel(part, sub(part))} class={readmePartClass(i, soon)}>
74
94
  {@render face(part, i)}
75
95
  </a>
76
96
  {:else}
77
- <button type="button" onclick={part.onClick} aria-label={readmePartLabel(part, sub(part))} class={readmePartClass(i, soon)}>{@render face(part, i)}</button>
97
+ <button {...tipped(i)} {@attach i === 0 && trigger} type="button" onclick={part.onClick} aria-label={readmePartLabel(part, sub(part))} class={readmePartClass(i, soon)}>{@render face(part, i)}</button>
78
98
  {/if}
79
99
  {/each}
80
100
  {#if !soon}<span class="glim-readme-btn-sheen" aria-hidden="true"></span>{/if}
81
101
  {#if hint}<span class="glim-readme-btn-hint"><InfoBubble tip={hint} /></span>{/if}
102
+ <TipBubble state={tooltip} />
82
103
  </div>
@@ -14,6 +14,8 @@ export interface ReadmeButtonProps {
14
14
  art?: Snippet;
15
15
  /** The "(i)" at the end of the unit, for what the name cannot say. */
16
16
  hint?: string;
17
+ /** A few words in the first part's bubble, for a name that needs no (i). */
18
+ tip?: string;
17
19
  /** Holds the second lines in view while one reports what it did, such as "Copied". */
18
20
  note?: boolean;
19
21
  /** The second line of a unit whose first part has neither `href` nor `onClick`. */
@@ -22,6 +22,9 @@
22
22
  size?: WindowSize;
23
23
  /** The words of the way out the window adds. */
24
24
  text: { cancel: string; close: string };
25
+ /** Off while the window holds typed input, which a stray press beside the
26
+ * card would throw away. Escape and the foot still close it. */
27
+ closeOnBackdrop?: boolean;
25
28
  /** Called for every way out: the foot, Escape and a press beside the window. */
26
29
  onClose: () => void;
27
30
  class?: string;
@@ -49,6 +52,7 @@
49
52
  start,
50
53
  size = "normal",
51
54
  text,
55
+ closeOnBackdrop = true,
52
56
  onClose,
53
57
  class: className,
54
58
  ref = $bindable(null),
@@ -77,7 +81,7 @@
77
81
 
78
82
  // A press beside an open menu only closes the menu, not the window under it.
79
83
  function pressBeside(e: MouseEvent) {
80
- if (e.target === e.currentTarget && !menuIsOpen()) leave();
84
+ if (closeOnBackdrop && e.target === e.currentTarget && !menuIsOpen()) leave();
81
85
  }
82
86
  </script>
83
87
 
@@ -22,6 +22,9 @@ export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title
22
22
  cancel: string;
23
23
  close: string;
24
24
  };
25
+ /** Off while the window holds typed input, which a stray press beside the
26
+ * card would throw away. Escape and the foot still close it. */
27
+ closeOnBackdrop?: boolean;
25
28
  /** Called for every way out: the foot, Escape and a press beside the window. */
26
29
  onClose: () => void;
27
30
  class?: string;
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
+ import type { ButtonTone } from "@glimstone/core";
3
4
 
4
5
  export interface WindowAction {
5
6
  label: string;
@@ -11,6 +12,12 @@
11
12
  /** This action already leaves the window, so no Cancel or Close is added. */
12
13
  wayOut?: boolean;
13
14
  disabled?: boolean;
15
+ /** Its fill once it has run, such as `ok` or `danger`, in place of the accent or the neutral grey. */
16
+ tone?: ButtonTone;
17
+ /** The busy ring in place of the glyph while it runs. The words, and so the width, stay. */
18
+ busy?: boolean;
19
+ /** What changes, such as how a test came out, in the button's bubble. */
20
+ title?: string;
14
21
  /** Attributes for the action's button, such as a data hook. */
15
22
  attrs?: Record<string, string>;
16
23
  /** Runs on press. The window closes afterwards unless it returns false. */
@@ -56,7 +63,9 @@
56
63
  label={a.label}
57
64
  labelKey={a.labelKey}
58
65
  glyph={a.glyph}
59
- tone={a.primary ? "accent" : "neutral"}
66
+ tone={a.tone ?? (a.primary ? "accent" : "neutral")}
67
+ busy={a.busy}
68
+ title={a.title}
60
69
  disabled={a.disabled}
61
70
  onClick={() => {
62
71
  if (a.onClick?.() !== false) onClose();
@@ -1,4 +1,5 @@
1
1
  import type { Snippet } from "svelte";
2
+ import type { ButtonTone } from "@glimstone/core";
2
3
  export interface WindowAction {
3
4
  label: string;
4
5
  /** The translation key behind `label`, which picks the glyph, or `null`. */
@@ -9,6 +10,12 @@ export interface WindowAction {
9
10
  /** This action already leaves the window, so no Cancel or Close is added. */
10
11
  wayOut?: boolean;
11
12
  disabled?: boolean;
13
+ /** Its fill once it has run, such as `ok` or `danger`, in place of the accent or the neutral grey. */
14
+ tone?: ButtonTone;
15
+ /** The busy ring in place of the glyph while it runs. The words, and so the width, stay. */
16
+ busy?: boolean;
17
+ /** What changes, such as how a test came out, in the button's bubble. */
18
+ title?: string;
12
19
  /** Attributes for the action's button, such as a data hook. */
13
20
  attrs?: Record<string, string>;
14
21
  /** Runs on press. The window closes afterwards unless it returns false. */
package/dist/glyphs.d.ts CHANGED
@@ -23,6 +23,7 @@ export declare const IconEye: Snippet<[]>;
23
23
  export declare const IconEyeOff: Snippet<[]>;
24
24
  export declare const IconCopy: Snippet<[]>;
25
25
  export declare const IconBack: Snippet<[]>;
26
+ export declare const IconSearch: Snippet<[]>;
26
27
  export declare const IconForward: Snippet<[]>;
27
28
  export declare const IconUpload: Snippet<[]>;
28
29
  export declare const IconCalendar: Snippet<[]>;
package/dist/glyphs.js CHANGED
@@ -38,6 +38,7 @@ export const IconEye = markSnippet(MARKS.eye);
38
38
  export const IconEyeOff = markSnippet(MARKS.eyeOff);
39
39
  export const IconCopy = markSnippet(MARKS.copy);
40
40
  export const IconBack = markSnippet(MARKS.back);
41
+ export const IconSearch = markSnippet(MARKS.search);
41
42
  export const IconForward = markSnippet(MARKS.forward);
42
43
  export const IconUpload = markSnippet(MARKS.upload);
43
44
  export const IconCalendar = markSnippet(MARKS.calendar);
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";
@@ -69,7 +70,7 @@ export { useAccent, useDensity, useHue, useLabelMode, useMotion, useRainbow, use
69
70
  export { useConfirm, useDialogKeys, type ConfirmOptions, type ConfirmText } from "./confirm.svelte.js";
70
71
  export { useFieldName } from "./fieldName.js";
71
72
  export { deviceGlyph } from "./fortressParts.js";
72
- export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
73
+ export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
73
74
  export * from "./portalHue.svelte.js";
74
75
  export { useTipBubble, type TipBubble } from "./bubble.svelte.js";
75
76
  export * from "./useDragArmed.svelte.js";
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";
@@ -69,7 +70,7 @@ export { useAccent, useDensity, useHue, useLabelMode, useMotion, useRainbow, use
69
70
  export { useConfirm, useDialogKeys } from "./confirm.svelte.js";
70
71
  export { useFieldName } from "./fieldName.js";
71
72
  export { deviceGlyph } from "./fortressParts.js";
72
- export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
73
+ export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
73
74
  export * from "./portalHue.svelte.js";
74
75
  export { useTipBubble } from "./bubble.svelte.js";
75
76
  export * from "./useDragArmed.svelte.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/svelte",
3
- "version": "4.5.4",
3
+ "version": "4.5.6",
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.6"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@internationalized/date": "^3.12.4",