@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.
Files changed (94) hide show
  1. package/dist/AngleSlider.svelte +33 -9
  2. package/dist/AngleSlider.svelte.d.ts +1 -1
  3. package/dist/Avatar.svelte +1 -1
  4. package/dist/Badge.svelte +3 -7
  5. package/dist/Badge.svelte.d.ts +2 -5
  6. package/dist/Card.svelte +5 -1
  7. package/dist/Card.svelte.d.ts +3 -0
  8. package/dist/Chart.svelte +84 -0
  9. package/dist/Chart.svelte.d.ts +19 -0
  10. package/dist/ChartLegend.svelte +19 -0
  11. package/dist/ChartLegend.svelte.d.ts +7 -0
  12. package/dist/Checkbox.svelte +16 -3
  13. package/dist/ColorPicker.svelte +49 -4
  14. package/dist/ColorPicker.svelte.d.ts +2 -0
  15. package/dist/Combobox.svelte +12 -4
  16. package/dist/ConfirmDialog.svelte +8 -2
  17. package/dist/ContextMenu.svelte +4 -2
  18. package/dist/ContextMenu.svelte.d.ts +2 -0
  19. package/dist/DatePicker.svelte +21 -11
  20. package/dist/FieldErrorLine.svelte +24 -0
  21. package/dist/FieldErrorLine.svelte.d.ts +7 -0
  22. package/dist/FieldRow.svelte +16 -4
  23. package/dist/FileUpload.svelte +14 -4
  24. package/dist/FileUpload.svelte.d.ts +2 -0
  25. package/dist/FortressPermissions.svelte +3 -1
  26. package/dist/HoverCard.svelte +34 -5
  27. package/dist/HoverCard.svelte.d.ts +12 -2
  28. package/dist/IconTipButton.svelte +6 -2
  29. package/dist/IconTipButton.svelte.d.ts +3 -0
  30. package/dist/InfoBubble.svelte +1 -1
  31. package/dist/ListRow.svelte +71 -6
  32. package/dist/ListRow.svelte.d.ts +17 -2
  33. package/dist/ListSelect.svelte +7 -2
  34. package/dist/ListTable.svelte +33 -15
  35. package/dist/ListTable.svelte.d.ts +5 -0
  36. package/dist/MenuSelect.svelte +11 -3
  37. package/dist/Meter.svelte +21 -3
  38. package/dist/Meter.svelte.d.ts +4 -0
  39. package/dist/MultiSelect.svelte +2 -1
  40. package/dist/NotifyCard.svelte +1 -1
  41. package/dist/NumberField.svelte +2 -2
  42. package/dist/PasswordField.svelte +7 -6
  43. package/dist/PinInput.svelte +4 -2
  44. package/dist/Rating.svelte +10 -1
  45. package/dist/RevealEye.svelte +17 -0
  46. package/dist/RevealEye.svelte.d.ts +6 -0
  47. package/dist/SearchHit.svelte +10 -0
  48. package/dist/SearchHit.svelte.d.ts +7 -0
  49. package/dist/Selector.svelte +28 -4
  50. package/dist/Selector.svelte.d.ts +4 -3
  51. package/dist/SettingsNav.svelte +152 -0
  52. package/dist/SettingsNav.svelte.d.ts +46 -0
  53. package/dist/SignInTile.svelte +19 -14
  54. package/dist/SkeletonRow.svelte +8 -2
  55. package/dist/SkeletonRow.svelte.d.ts +4 -0
  56. package/dist/Slider.svelte +1 -0
  57. package/dist/Sparkline.svelte +24 -0
  58. package/dist/Sparkline.svelte.d.ts +11 -0
  59. package/dist/StatusSummary.svelte +55 -0
  60. package/dist/StatusSummary.svelte.d.ts +18 -0
  61. package/dist/SubCard.svelte +16 -16
  62. package/dist/SubCard.svelte.d.ts +3 -3
  63. package/dist/TextArea.svelte +13 -3
  64. package/dist/TextField.svelte +2 -2
  65. package/dist/TimeDial.svelte +74 -0
  66. package/dist/TimeDial.svelte.d.ts +13 -0
  67. package/dist/TimePicker.svelte +57 -0
  68. package/dist/TimePicker.svelte.d.ts +19 -0
  69. package/dist/TimeRangePicker.svelte +52 -0
  70. package/dist/TimeRangePicker.svelte.d.ts +16 -0
  71. package/dist/TimeShell.svelte +145 -0
  72. package/dist/TimeShell.svelte.d.ts +16 -0
  73. package/dist/Timer.svelte +6 -1
  74. package/dist/TipBubble.svelte +1 -1
  75. package/dist/ToastCard.svelte +7 -3
  76. package/dist/ToastCard.svelte.d.ts +2 -0
  77. package/dist/ToastViewport.svelte +6 -3
  78. package/dist/Toggle.svelte +3 -1
  79. package/dist/Tour.svelte +8 -2
  80. package/dist/Window.svelte +5 -3
  81. package/dist/Window.svelte.d.ts +3 -1
  82. package/dist/bubble.svelte.d.ts +12 -1
  83. package/dist/bubble.svelte.js +13 -5
  84. package/dist/engines.svelte.d.ts +7 -1
  85. package/dist/engines.svelte.js +13 -1
  86. package/dist/glyphs.d.ts +3 -0
  87. package/dist/glyphs.js +3 -0
  88. package/dist/index.d.ts +13 -7
  89. package/dist/index.js +9 -4
  90. package/package.json +2 -2
  91. package/dist/AboutCard.svelte +0 -116
  92. package/dist/AboutCard.svelte.d.ts +0 -40
  93. package/dist/DropdownListbox.svelte +0 -178
  94. package/dist/DropdownListbox.svelte.d.ts +0 -23
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import { TOAST_MARKS, whenFieldErrorClosed } from "@glimstone/core";
3
+ import MarkSvg from "./MarkSvg.svelte";
4
+
5
+ // The error line the fields draw under themselves. Once the value is fixed
6
+ // it stays a moment with data-closing, so the stylesheet can close it as
7
+ // softly as it opened instead of the form jumping.
8
+ let { id, error }: { id: string | undefined; error: string | undefined } = $props();
9
+
10
+ const current = $derived(id && error ? { id, error } : null);
11
+ // The last error, kept while its line closes.
12
+ let kept = $state<{ id: string; error: string } | null>(null);
13
+ $effect(() => {
14
+ if (current) kept = current;
15
+ });
16
+ const shown = $derived(current ?? kept);
17
+ const closing = $derived(!current && kept !== null);
18
+ let line = $state<HTMLSpanElement | null>(null);
19
+ $effect(() => {
20
+ if (closing && line) return whenFieldErrorClosed(line, () => (kept = null));
21
+ });
22
+ </script>
23
+
24
+ {#if shown}<span bind:this={line} data-glim="FieldError" id={closing ? undefined : shown.id} data-closing={closing ? "" : undefined} class="glim-field-error"><MarkSvg mark={TOAST_MARKS.fail} />{shown.error}</span>{/if}
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ id: string | undefined;
3
+ error: string | undefined;
4
+ };
5
+ declare const FieldErrorLine: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type FieldErrorLine = ReturnType<typeof FieldErrorLine>;
7
+ export default FieldErrorLine;
@@ -24,25 +24,37 @@
24
24
 
25
25
  <script lang="ts">
26
26
  import { getContext, setContext } from "svelte";
27
- import { pressRowControl } from "@glimstone/core";
27
+ import { pressRowControl, pressRowSwitch, watchRowStack } from "@glimstone/core";
28
28
  import { FIELD_ROW, FIELD_ROW_GROUP } from "./fieldName.js";
29
29
  import InfoBubble from "./InfoBubble.svelte";
30
30
  import Pill from "./Pill.svelte";
31
31
 
32
32
  // One labelled row of a card or a window (rule 35): the name at its start and
33
- // the control at its end, which takes its accessible name from `label`.
34
- let { label, drawn, hint, value, tone, wide, children, class: className, ...rest }: FieldRowProps = $props();
33
+ // the control at its end, which takes its accessible name from `label`. A row
34
+ // with a switch is one target from end to end.
35
+ let { label, drawn, hint, value, tone, wide, children, class: className, onclick, ...rest }: FieldRowProps = $props();
35
36
 
36
37
  setContext(FIELD_ROW, () => label);
37
38
  const inGroup = getContext<boolean | undefined>(FIELD_ROW_GROUP) ?? false;
38
39
  let row: HTMLDivElement;
40
+ $effect(() => watchRowStack(row));
39
41
  </script>
40
42
 
41
43
  {#snippet control()}
42
44
  {#if children}{@render children()}{:else if value !== undefined}<Pill class="glim-num" {tone}>{value}</Pill>{/if}
43
45
  {/snippet}
44
46
 
45
- <div data-glim="FieldRow" {...rest} bind:this={row} class={["glim-field-row", wide && "glim-field-row--wide", className].filter(Boolean).join(" ")}>
47
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
48
+ <div
49
+ data-glim="FieldRow"
50
+ data-press=""
51
+ {...rest}
52
+ bind:this={row}
53
+ onclick={(e) => {
54
+ onclick?.(e);
55
+ pressRowSwitch(row, e.target);
56
+ }}
57
+ class={["glim-field-row", wide && "glim-field-row--wide", className].filter(Boolean).join(" ")}>
46
58
  <span class="glim-field-row-name">
47
59
  <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
48
60
  <span class="glim-field-row-label" onclick={() => pressRowControl(row)}>{#if drawn}{@render drawn()}{:else}{label}{/if}</span>
@@ -14,6 +14,8 @@
14
14
  /** The largest file it takes, in bytes. */
15
15
  maxFileSize?: number;
16
16
  disabled?: boolean;
17
+ /** How far a file has gone up, from 0 to 1, while the app sends it. Its row fills with it. */
18
+ progress?: (file: File) => number | undefined;
17
19
  text?: Partial<FileUploadText>;
18
20
  }
19
21
  </script>
@@ -21,15 +23,16 @@
21
23
  <script lang="ts">
22
24
  import * as fileUpload from "@zag-js/file-upload";
23
25
  import { normalizeProps, useMachine } from "@zag-js/svelte";
24
- import { FILE_UPLOAD_TEXT, formatFileSize, pageDir, type FileRefusal } from "@glimstone/core";
26
+ import { FILE_UPLOAD_TEXT, formatFileSize, pageDir, uploadProgressView, type FileRefusal } from "@glimstone/core";
25
27
  import IconButton from "./IconButton.svelte";
26
28
  import { IconClose, IconUpload } from "./glyphs.js";
27
29
 
28
30
  // Files handed to the app by dropping them or from the picker, such as a
29
31
  // settings file to import. The drop zone is itself the button that opens the
30
32
  // picker, so there is one control and one stop for Tab. The files stand under
31
- // it as rows, and a refused one is named with its reason.
32
- let { label, value = $bindable(), onChange, accept, maxFiles = 1, maxFileSize, disabled = false, text }: FileUploadProps = $props();
33
+ // it as rows, each filling as its file goes up, and a refused one is named
34
+ // with its reason.
35
+ let { label, value = $bindable(), onChange, accept, maxFiles = 1, maxFileSize, disabled = false, progress, text }: FileUploadProps = $props();
33
36
 
34
37
  const words = $derived({ ...FILE_UPLOAD_TEXT, ...text });
35
38
  const id = $props.id();
@@ -60,7 +63,14 @@
60
63
  {#if api.acceptedFiles.length > 0}
61
64
  <ul {...api.getItemGroupProps()} class="glim-upload-files">
62
65
  {#each api.acceptedFiles as file (`${file.name}-${file.size}`)}
63
- <li {...api.getItemProps({ file })} class="glim-upload-file">
66
+ {@const sent = uploadProgressView(progress?.(file))}
67
+ <li
68
+ {...api.getItemProps({ file })}
69
+ aria-busy={sent.state === "sending" ? true : undefined}
70
+ data-progress={sent.state}
71
+ style:--glim-upload-progress={sent.share}
72
+ class="glim-upload-file"
73
+ >
64
74
  <span {...api.getItemNameProps({ file })} class="glim-upload-name">{file.name}</span>
65
75
  <span {...api.getItemSizeTextProps({ file })} class="glim-upload-size glim-num">{formatFileSize(file.size)}</span>
66
76
  <IconButton tip={words.remove(file.name)} glyph={IconClose} onclick={() => api.deleteFile(file)} />
@@ -11,6 +11,8 @@ export interface FileUploadProps {
11
11
  /** The largest file it takes, in bytes. */
12
12
  maxFileSize?: number;
13
13
  disabled?: boolean;
14
+ /** How far a file has gone up, from 0 to 1, while the app sends it. Its row fills with it. */
15
+ progress?: (file: File) => number | undefined;
14
16
  text?: Partial<FileUploadText>;
15
17
  }
16
18
  declare const FileUpload: import("svelte").Component<FileUploadProps, {}, "value">;
@@ -24,6 +24,8 @@
24
24
  <script lang="ts">
25
25
  import { fill, MARKS, permissionsWith, shake } from "@glimstone/core";
26
26
  import Card from "./Card.svelte";
27
+ import EmptyState from "./EmptyState.svelte";
28
+ import { glyphFor } from "./glyphs.js";
27
29
  import MarkSvg from "./MarkSvg.svelte";
28
30
  import Selector from "./Selector.svelte";
29
31
  import Toggle from "./Toggle.svelte";
@@ -56,7 +58,7 @@
56
58
 
57
59
  <Card data-glim="FortressPermissions" title={text.permissions} hint={text.permissionsAbout} {hueIndex}>
58
60
  {#if permissions.length === 0}
59
- <p class="glim-fortress-sub">{text.noPermissions}</p>
61
+ <EmptyState nested glyph={glyphFor("link")} title={text.noPermissions} />
60
62
  {:else}
61
63
  {#if narrows}
62
64
  <Selector
@@ -1,5 +1,8 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
+ import type { HoverCardFact } from "@glimstone/core";
4
+
5
+ export type { HoverCardFact } from "@glimstone/core";
3
6
 
4
7
  export interface HoverCardProps {
5
8
  /** The link's words. */
@@ -8,15 +11,23 @@
8
11
  /** How long the pointer rests before the card opens, and after it leaves before it closes, in ms. */
9
12
  openDelay?: number;
10
13
  closeDelay?: number;
11
- /** Draws the card. */
12
- content: Snippet;
14
+ /** A glyph or an avatar for the card's head, in a 40px tile. */
15
+ media?: Snippet;
16
+ /** The head's name. */
17
+ title?: string;
18
+ /** One quiet line under the name, such as an address or a state. */
19
+ meta?: string;
20
+ /** Up to three figures under the head, each a name and a value. */
21
+ facts?: readonly HoverCardFact[];
22
+ /** Draws the card's body below the head, or the whole card without one. */
23
+ content?: Snippet;
13
24
  }
14
25
  </script>
15
26
 
16
27
  <script lang="ts">
17
28
  import * as hoverCard from "@zag-js/hover-card";
18
29
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
19
- import { pageDir } from "@glimstone/core";
30
+ import { hoverCardFacts, pageDir } from "@glimstone/core";
20
31
  import { lift } from "./lift.js";
21
32
  import { usePortalHue } from "./portalHue.svelte.js";
22
33
 
@@ -24,7 +35,7 @@
24
35
  // keyboard reaches it, such as the details of a server named in a sentence.
25
36
  // It only previews: everything in it is also behind the link, so a touch
26
37
  // screen, which has no hover, loses nothing.
27
- let { label, href, openDelay = 600, closeDelay = 300, content }: HoverCardProps = $props();
38
+ let { label, href, openDelay = 400, closeDelay = 150, media, title, meta, facts, content }: HoverCardProps = $props();
28
39
 
29
40
  const id = $props.id();
30
41
  const service = useMachine(hoverCard.machine, () => ({
@@ -42,6 +53,24 @@
42
53
  <a data-glim="HoverCard" {...api.getTriggerProps()} bind:this={trigger} {href} class="glim-hovercard-link">{label}</a>
43
54
  {#if api.open}
44
55
  <div {@attach lift} {...mergeProps(api.getPositionerProps(), { style: hue.style })} class={`glim-hovercard-positioner ${hue.className}`.trim()}>
45
- <div {...api.getContentProps()} class="glim-hovercard">{@render content()}</div>
56
+ <div {...api.getContentProps()} class="glim-hovercard">
57
+ {#if media || title}
58
+ <div class="glim-hovercard-head">
59
+ {#if media}<span class="glim-hovercard-media">{@render media()}</span>{/if}
60
+ <span class="glim-hovercard-names">
61
+ {#if title}<strong class="glim-hovercard-title">{title}</strong>{/if}
62
+ {#if meta}<span class="glim-hovercard-meta">{meta}</span>{/if}
63
+ </span>
64
+ </div>
65
+ {/if}
66
+ {#if hoverCardFacts(facts).length}
67
+ <dl class="glim-hovercard-facts">
68
+ {#each hoverCardFacts(facts) as f (f.label)}
69
+ <div class="glim-hovercard-fact"><dt>{f.label}</dt><dd class="glim-num">{f.value}</dd></div>
70
+ {/each}
71
+ </dl>
72
+ {/if}
73
+ {@render content?.()}
74
+ </div>
46
75
  </div>
47
76
  {/if}
@@ -1,4 +1,6 @@
1
1
  import type { Snippet } from "svelte";
2
+ import type { HoverCardFact } from "@glimstone/core";
3
+ export type { HoverCardFact } from "@glimstone/core";
2
4
  export interface HoverCardProps {
3
5
  /** The link's words. */
4
6
  label: string;
@@ -6,8 +8,16 @@ export interface HoverCardProps {
6
8
  /** How long the pointer rests before the card opens, and after it leaves before it closes, in ms. */
7
9
  openDelay?: number;
8
10
  closeDelay?: number;
9
- /** Draws the card. */
10
- content: Snippet;
11
+ /** A glyph or an avatar for the card's head, in a 40px tile. */
12
+ media?: Snippet;
13
+ /** The head's name. */
14
+ title?: string;
15
+ /** One quiet line under the name, such as an address or a state. */
16
+ meta?: string;
17
+ /** Up to three figures under the head, each a name and a value. */
18
+ facts?: readonly HoverCardFact[];
19
+ /** Draws the card's body below the head, or the whole card without one. */
20
+ content?: Snippet;
11
21
  }
12
22
  declare const HoverCard: import("svelte").Component<HoverCardProps, {}, "">;
13
23
  type HoverCard = ReturnType<typeof HoverCard>;
@@ -5,6 +5,9 @@
5
5
  export interface IconTipButtonProps extends Omit<HTMLButtonAttributes, "children" | "type" | "class" | "disabled" | "style"> {
6
6
  /** The hover and focus explanation, and the button's `aria-label`. */
7
7
  tip: string;
8
+ /** The keyboard shortcut that does the same, drawn beside the tip and
9
+ * announced as `aria-keyshortcuts`, such as "Ctrl K". */
10
+ shortcut?: string;
8
11
  disabled?: boolean;
9
12
  class?: string;
10
13
  /** `aria-pressed` for a trigger that toggles rather than acts once. Omitted,
@@ -34,9 +37,9 @@
34
37
  // Unlike Button, this control has no label to hide: a bare glyph in a box the
35
38
  // caller sizes, with no width stage, no tone fill and no place in the label
36
39
  // mode engine. The other props of a <button> go to the button.
37
- let { tip, disabled, class: className, style, children, href, type = "button", ariaPressed, ariaExpanded, ...rest }: IconTipButtonProps = $props();
40
+ let { tip, shortcut, disabled, class: className, style, children, href, type = "button", ariaPressed, ariaExpanded, ...rest }: IconTipButtonProps = $props();
38
41
 
39
- const tooltip = useTipBubble(() => tip, () => !!disabled);
42
+ const tooltip = useTipBubble(() => tip, () => !!disabled, { shortcut: () => shortcut });
40
43
  const link = $derived(!!href && !disabled);
41
44
  </script>
42
45
 
@@ -51,6 +54,7 @@
51
54
  disabled={link ? undefined : disabled}
52
55
  bind:this={tooltip.trigger}
53
56
  aria-label={tip}
57
+ aria-keyshortcuts={shortcut?.trim().replace(/\s+/g, "+")}
54
58
  aria-pressed={ariaPressed}
55
59
  aria-expanded={ariaExpanded}
56
60
  aria-describedby={tooltip.describedBy}
@@ -3,6 +3,9 @@ import type { HTMLButtonAttributes } from "svelte/elements";
3
3
  export interface IconTipButtonProps extends Omit<HTMLButtonAttributes, "children" | "type" | "class" | "disabled" | "style"> {
4
4
  /** The hover and focus explanation, and the button's `aria-label`. */
5
5
  tip: string;
6
+ /** The keyboard shortcut that does the same, drawn beside the tip and
7
+ * announced as `aria-keyshortcuts`, such as "Ctrl K". */
8
+ shortcut?: string;
6
9
  disabled?: boolean;
7
10
  class?: string;
8
11
  /** `aria-pressed` for a trigger that toggles rather than acts once. Omitted,
@@ -19,7 +19,7 @@
19
19
  // has less margin on a busy fill.
20
20
  let { tip, onAccent = false }: InfoBubbleProps = $props();
21
21
 
22
- const tooltip = useTipBubble(() => tip);
22
+ const tooltip = useTipBubble(() => tip, undefined, { kind: "info" });
23
23
  </script>
24
24
 
25
25
  <!-- Inside a <label>, a click on a span is forwarded to the label's field,
@@ -1,6 +1,11 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
3
  import type { HTMLAttributes } from "svelte/elements";
4
+ import type { ListRowAction as CoreListRowAction, ListRowMenu as CoreListRowMenu, ListRowStatus } from "@glimstone/core";
5
+
6
+ export type { ListRowStatus } from "@glimstone/core";
7
+ export type ListRowAction = CoreListRowAction<Snippet>;
8
+ export type ListRowMenu = CoreListRowMenu<Snippet>;
4
9
 
5
10
  export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "class"> {
6
11
  name: string;
@@ -10,27 +15,55 @@
10
15
  mono?: boolean;
11
16
  /** A quiet line under the name, such as when it was made or where it comes from. */
12
17
  meta?: string;
13
- /** Keeps the buttons in view at rest, for a short list of the person's own things, where each row's buttons are the point. */
18
+ /** Lets the buttons drop under the name where the row is narrow, for a short list of the person's own things, where each row's buttons are the point. */
14
19
  steady?: boolean;
15
20
  /** The glyph at the row's start, which fills with the accent while the row is reached. */
16
21
  tile?: Snippet;
17
22
  /** What stands at the row's end at rest. */
18
23
  badges?: Snippet;
19
- /** The buttons that come in on hover and focus. A press on one does not open the row. */
24
+ /** A row that differs from the rest, as a mark in the state colour with
25
+ * neutral words, in its own place before the value. The normal case passes
26
+ * nothing and stays quiet. */
27
+ status?: ListRowStatus;
28
+ /** The row's figure, such as a size, in a column of fixed width at its end,
29
+ * so a status beside it moves nothing. A unit in <small> stands quieter. */
30
+ value?: Snippet;
31
+ /** A control of the row's own, such as its switch, before the action. Buttons go in `action` and `menu`. A press on it does not open the row. */
20
32
  actions?: Snippet;
33
+ /** The one action the row keeps in view, such as Run, as a quiet button. */
34
+ action?: ListRowAction;
35
+ /** Every other action, such as pause, edit and delete, in the menu of the More button at the row's end. */
36
+ menu?: ListRowMenu;
21
37
  class?: string;
22
38
  }
23
39
  </script>
24
40
 
25
41
  <script lang="ts">
42
+ import { listRowStatus, menuPointUnder, takePageHue } from "@glimstone/core";
43
+ import Button from "./Button.svelte";
44
+ import ContextMenu from "./ContextMenu.svelte";
45
+ import IconTipButton from "./IconTipButton.svelte";
26
46
  import InfoBubble from "./InfoBubble.svelte";
47
+ import MarkSvg from "./MarkSvg.svelte";
48
+ import { IconMore } from "./glyphs.js";
49
+
50
+ // One row of a list: a glyph tile, the name, badges, and at its end one quiet
51
+ // action and a More button for the rest, both in view (rule 6). A click
52
+ // handler makes the whole row a way into its object, by keyboard too. The
53
+ // other props of a <div> go to the row.
54
+ let { name, tip, mono, meta, steady, tile, badges, status, value, actions, action, menu, class: className, onclick, onkeydown, ...rest }: ListRowProps = $props();
27
55
 
28
- // One row of a list: a glyph tile, the name, badges and buttons that come in on
29
- // hover and focus (rule 6). A click handler makes the whole row a way into its
30
- // object, by keyboard too. The other props of a <div> go to the row.
31
- let { name, tip, mono, meta, steady, tile, badges, actions, class: className, onclick, onkeydown, ...rest }: ListRowProps = $props();
56
+ // The row narrows its action to the glyph below this window width, as a connection row does.
57
+ const NARROW = 640;
58
+ let menuAt = $state<{ x: number; y: number } | null>(null);
59
+ let more = $state<HTMLElement | null>(null);
32
60
 
33
61
  const stay = (e: MouseEvent) => e.stopPropagation();
62
+ const reach = (e: Event) => takePageHue(e.currentTarget as HTMLElement);
63
+ function toggleMenu(e: MouseEvent & { currentTarget: EventTarget & HTMLElement }) {
64
+ more = e.currentTarget;
65
+ menuAt = menuAt ? null : menuPointUnder(e.currentTarget);
66
+ }
34
67
 
35
68
  function keys(e: KeyboardEvent & { currentTarget: EventTarget & HTMLDivElement }) {
36
69
  onkeydown?.(e);
@@ -61,6 +94,38 @@
61
94
  {@render nameLine()}
62
95
  {/if}
63
96
  {#if badges}<span class="glim-list-row-badges">{@render badges()}</span>{/if}
97
+ {#if status}
98
+ {@const mark = listRowStatus(status.tone).mark}
99
+ <span class="glim-list-row-status" data-tone={status.tone}>
100
+ {#if mark}<MarkSvg {mark} class="glim-status-mark" />{:else}<span class="glim-status-dot" aria-hidden="true"></span>{/if}
101
+ <span>{status.label}</span>
102
+ </span>
103
+ {/if}
104
+ {#if value}<span class="glim-list-row-value">{@render value()}</span>{/if}
64
105
  <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
65
106
  {#if actions}<span class="glim-list-row-actions" onclick={stay}>{@render actions()}</span>{/if}
107
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
108
+ {#if action || menu}
109
+ <span class="glim-list-row-end" onclick={stay}>
110
+ {#if action}
111
+ <Button tone="subtle" label={action.label} labelKey={action.labelKey} glyph={action.glyph} disabled={action.disabled} compactBelow={NARROW} onClick={action.onClick} />
112
+ {/if}
113
+ {#if menu}
114
+ <IconTipButton
115
+ tip={menu.label}
116
+ aria-haspopup="menu"
117
+ ariaExpanded={menuAt !== null}
118
+ class="glim-btn-bare glim-icon-btn glim-list-row-more"
119
+ onpointerenter={reach}
120
+ onfocusin={reach}
121
+ onclick={toggleMenu}
122
+ >
123
+ {@render IconMore()}
124
+ </IconTipButton>
125
+ {#if menuAt}
126
+ <ContextMenu x={menuAt.x} y={menuAt.y} end items={menu.items} label={menu.label} opener={more} onClose={() => (menuAt = null)} />
127
+ {/if}
128
+ {/if}
129
+ </span>
130
+ {/if}
66
131
  </div>
@@ -1,5 +1,9 @@
1
1
  import type { Snippet } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
+ import type { ListRowAction as CoreListRowAction, ListRowMenu as CoreListRowMenu, ListRowStatus } from "@glimstone/core";
4
+ export type { ListRowStatus } from "@glimstone/core";
5
+ export type ListRowAction = CoreListRowAction<Snippet>;
6
+ export type ListRowMenu = CoreListRowMenu<Snippet>;
3
7
  export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "class"> {
4
8
  name: string;
5
9
  /** More about the row, drawn as an "(i)" beside the name. */
@@ -8,14 +12,25 @@ export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "chil
8
12
  mono?: boolean;
9
13
  /** A quiet line under the name, such as when it was made or where it comes from. */
10
14
  meta?: string;
11
- /** Keeps the buttons in view at rest, for a short list of the person's own things, where each row's buttons are the point. */
15
+ /** Lets the buttons drop under the name where the row is narrow, for a short list of the person's own things, where each row's buttons are the point. */
12
16
  steady?: boolean;
13
17
  /** The glyph at the row's start, which fills with the accent while the row is reached. */
14
18
  tile?: Snippet;
15
19
  /** What stands at the row's end at rest. */
16
20
  badges?: Snippet;
17
- /** The buttons that come in on hover and focus. A press on one does not open the row. */
21
+ /** A row that differs from the rest, as a mark in the state colour with
22
+ * neutral words, in its own place before the value. The normal case passes
23
+ * nothing and stays quiet. */
24
+ status?: ListRowStatus;
25
+ /** The row's figure, such as a size, in a column of fixed width at its end,
26
+ * so a status beside it moves nothing. A unit in <small> stands quieter. */
27
+ value?: Snippet;
28
+ /** A control of the row's own, such as its switch, before the action. Buttons go in `action` and `menu`. A press on it does not open the row. */
18
29
  actions?: Snippet;
30
+ /** The one action the row keeps in view, such as Run, as a quiet button. */
31
+ action?: ListRowAction;
32
+ /** Every other action, such as pause, edit and delete, in the menu of the More button at the row's end. */
33
+ menu?: ListRowMenu;
19
34
  class?: string;
20
35
  }
21
36
  declare const ListRow: import("svelte").Component<ListRowProps, {}, "">;
@@ -1,7 +1,8 @@
1
1
  <script lang="ts" generics="T extends string">
2
+ import { untrack } from "svelte";
2
3
  import * as select from "@zag-js/select";
3
4
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
4
- import { closeOnPageMove, endOption, flattenRuns, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts } from "@glimstone/core";
5
+ import { alignOverTrigger, closeOnPageMove, endOption, flattenRuns, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts } from "@glimstone/core";
5
6
  import { useTipBubble } from "./bubble.svelte.js";
6
7
  import { IconCheck, IconExpand } from "./glyphs.js";
7
8
  import { lift } from "./lift.js";
@@ -73,6 +74,10 @@
73
74
  $effect(() => {
74
75
  if (open) return closeOnPageMove(() => api.setOpen(false));
75
76
  });
77
+ let content: HTMLDivElement;
78
+ $effect(() => {
79
+ if (open) return untrack(() => alignOverTrigger(content, ref!, value));
80
+ });
76
81
  const hue = usePortalHue(() => open, () => ref);
77
82
 
78
83
  const choices = (g: SelectGroup<T>) => g.entries as SelectOption<T>[];
@@ -110,7 +115,7 @@
110
115
  </div>
111
116
  <TipBubble state={bubble} />
112
117
  <div {@attach lift} {...mergeProps(api.getPositionerProps(), { style: hue.style })} class={`glim-select-positioner ${hue.className}`.trim()}>
113
- <div {...api.getContentProps()} class={parts.content}>
118
+ <div {...api.getContentProps()} bind:this={content} class={parts.content}>
114
119
  {#each groups as g, gi (gi)}
115
120
  {#if g.entries.length > 0}
116
121
  <div {...g.heading ? api.getItemGroupProps({ id: `${uid}-g${gi}` }) : {}} class="glim-select-group">
@@ -20,6 +20,11 @@
20
20
  onOpen?: (row: T) => void;
21
21
  /** The picked rows, in the list's order, after every change. */
22
22
  onSelect?: (rows: T[]) => void;
23
+ /** Puts the rows in sections, one per value, such as the instance a row
24
+ * comes from, each under that value as a plain title in the one card. */
25
+ section?: (row: T) => string;
26
+ /** Draws every row on one line, leaving out the columns' `sub` lines. */
27
+ oneLine?: boolean;
23
28
  }
24
29
  </script>
25
30
 
@@ -29,6 +34,7 @@
29
34
  ariaSort,
30
35
  columnValues,
31
36
  listKey,
37
+ listSections,
32
38
  listView,
33
39
  MARKS,
34
40
  nextSort,
@@ -47,7 +53,7 @@
47
53
  // header sorts, the ▾ beside it filters, typing floats a search inside the list,
48
54
  // and rows are picked the way a file manager picks them. It is an APG grid with
49
55
  // row selection; the rules live in listModel.ts in the core.
50
- let { label, columns, rows, rowKey, search, text, cell, onOpen, onSelect }: ListTableProps<T> = $props();
56
+ let { label, columns, rows, rowKey, search, text, cell, onOpen, onSelect, section, oneLine }: ListTableProps<T> = $props();
51
57
 
52
58
  let sort = $state<ListSort | null>(null);
53
59
  let filters = $state<ListFilters>({});
@@ -58,7 +64,10 @@
58
64
  let searchField = $state<HTMLInputElement | null>(null);
59
65
  const hintId = $props.id();
60
66
 
61
- const view = $derived(listView(rows, { sort, filters, query: query ?? "", search: search ?? [columns[0]!.key] }));
67
+ const grouped = $derived(listSections(rows, listView(rows, { sort, filters, query: query ?? "", search: search ?? [columns[0]!.key] }), section));
68
+ const view = $derived(grouped.sections.flatMap((s) => s.rows));
69
+ // Where each section starts in the view, so a row keeps one index across them.
70
+ const starts = $derived(grouped.sections.map((_, p) => grouped.sections.slice(0, p).reduce((n, s) => n + s.rows.length, 0)));
62
71
  const keys = $derived(view.map(rowKey));
63
72
  const selection = $derived.by((): ListSelection => {
64
73
  const at = (key: string | null) => (key === null ? -1 : keys.indexOf(key));
@@ -72,7 +81,7 @@
72
81
  // The focus follows the rows once they are drawn.
73
82
  async function focusRow() {
74
83
  await tick();
75
- grid.querySelector<HTMLElement>(`tbody tr:nth-child(${selection.focus + 1}) > td`)?.focus();
84
+ grid.querySelector<HTMLElement>(`tr[data-row="${selection.focus}"] > td`)?.focus();
76
85
  }
77
86
 
78
87
  function apply(next: ListSelection) {
@@ -110,6 +119,7 @@
110
119
  filters = { ...filters, [key]: now.includes(value) ? now.filter((v) => v !== value) : [...now, value] };
111
120
  }
112
121
  const shown = (row: T, c: ListColumn) => String((row as Record<string, unknown>)[c.key] ?? "");
122
+ const subOf = (row: T, c: ListColumn) => (oneLine || !c.sub ? "" : String((row as Record<string, unknown>)[c.sub] ?? ""));
113
123
  </script>
114
124
 
115
125
  <div data-glim="ListTable" class="glim-list">
@@ -158,18 +168,26 @@
158
168
  {/each}
159
169
  </tr>
160
170
  </thead>
161
- <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
162
- <tbody onkeydown={onKey}>
163
- {#each view as row, i (rowKey(row))}
164
- <tr aria-selected={selection.selected.includes(i)} class="glim-list-tr" onclick={(e) => onRowClick(e, i)} ondblclick={() => onOpen?.(row)}>
165
- {#each columns as c, ci (c.key)}
166
- <td tabindex={ci === 0 ? (i === selection.focus ? 0 : -1) : undefined} class={tableCellClass(c) || undefined}>
167
- {#if cell}{@render cell(row, c, shown(row, c))}{:else}{shown(row, c)}{/if}
168
- </td>
169
- {/each}
170
- </tr>
171
- {/each}
172
- </tbody>
171
+ {#each grouped.sections as part, p (part.title)}
172
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
173
+ <tbody onkeydown={onKey}>
174
+ {#if grouped.titled}
175
+ <tr class="glim-list-section"><th scope="rowgroup" colspan={columns.length}>{part.title}</th></tr>
176
+ {/if}
177
+ {#each part.rows as row, r (rowKey(row))}
178
+ {@const i = starts[p]! + r}
179
+ <tr data-row={i} aria-selected={selection.selected.includes(i)} class="glim-list-tr" onclick={(e) => onRowClick(e, i)} ondblclick={() => onOpen?.(row)}>
180
+ {#each columns as c, ci (c.key)}
181
+ {@const sub = subOf(row, c)}
182
+ <td tabindex={ci === 0 ? (i === selection.focus ? 0 : -1) : undefined} class={tableCellClass(c) || undefined}>
183
+ {#if sub}<span class="glim-list-cell-main">{#if cell}{@render cell(row, c, shown(row, c))}{:else}{shown(row, c)}{/if}</span><span class="glim-list-cell-sub">{sub}</span
184
+ >{:else if cell}{@render cell(row, c, shown(row, c))}{:else}{shown(row, c)}{/if}
185
+ </td>
186
+ {/each}
187
+ </tr>
188
+ {/each}
189
+ </tbody>
190
+ {/each}
173
191
  </table>
174
192
  {#if view.length === 0}<p class="glim-list-empty">{text.noMatch}</p>{/if}
175
193
  <p id={hintId} class="glim-sr-only">{text.hint}</p>
@@ -17,6 +17,11 @@ export interface ListTableProps<T extends object> {
17
17
  onOpen?: (row: T) => void;
18
18
  /** The picked rows, in the list's order, after every change. */
19
19
  onSelect?: (rows: T[]) => void;
20
+ /** Puts the rows in sections, one per value, such as the instance a row
21
+ * comes from, each under that value as a plain title in the one card. */
22
+ section?: (row: T) => string;
23
+ /** Draws every row on one line, leaving out the columns' `sub` lines. */
24
+ oneLine?: boolean;
20
25
  }
21
26
  declare function $$render<T extends object>(): {
22
27
  props: ListTableProps<T>;
@@ -2,7 +2,7 @@
2
2
  import { untrack } from "svelte";
3
3
  import * as menu from "@zag-js/menu";
4
4
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
5
- import { closeOnPageMove, faceLabels, flattenRuns, homeRow, isSubmenu, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts } from "@glimstone/core";
5
+ import { alignOverTrigger, closeOnPageMove, faceLabels, flattenRuns, homeRow, isSubmenu, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts } from "@glimstone/core";
6
6
  import { useTipBubble } from "./bubble.svelte.js";
7
7
  import { IconExpand } from "./glyphs.js";
8
8
  import { lift } from "./lift.js";
@@ -65,6 +65,7 @@
65
65
  count: () => shake ?? 0,
66
66
  });
67
67
  const hue = usePortalHue(() => open, () => ref);
68
+ let content: HTMLDivElement;
68
69
 
69
70
  $effect(() => {
70
71
  if (!open) return;
@@ -72,13 +73,20 @@
72
73
  // Zag highlights on the frame after the list opens, so the home row goes
73
74
  // one frame later still.
74
75
  const home = untrack(() => homeRow(groups, value, subId));
75
- if (home === null) return stop;
76
+ const unalign = untrack(() => alignOverTrigger(content, ref!, home));
77
+ if (home === null) {
78
+ return () => {
79
+ stop();
80
+ unalign();
81
+ };
82
+ }
76
83
  let inner = 0;
77
84
  const outer = requestAnimationFrame(() => {
78
85
  inner = requestAnimationFrame(() => api.setHighlightedValue(home));
79
86
  });
80
87
  return () => {
81
88
  stop();
89
+ unalign();
82
90
  cancelAnimationFrame(outer);
83
91
  cancelAnimationFrame(inner);
84
92
  };
@@ -123,7 +131,7 @@
123
131
  </div>
124
132
  <TipBubble state={bubble} />
125
133
  <div {@attach lift} {...mergeProps(api.getPositionerProps(), { style: hue.style })} class={`glim-select-positioner ${hue.className}`.trim()}>
126
- <div {...api.getContentProps()} class={parts.content}>
134
+ <div {...api.getContentProps()} bind:this={content} class={parts.content}>
127
135
  {#each groups as g, gi (gi)}
128
136
  {#if g.entries.length > 0}
129
137
  <div {...g.heading ? api.getItemGroupProps({ id: `g${gi}` }) : {}} class="glim-select-group">