@glimstone/svelte 4.9.1 → 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 (100) 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/ConnectionRow.svelte +4 -1
  18. package/dist/ConnectionRow.svelte.d.ts +2 -0
  19. package/dist/ContextMenu.svelte +4 -2
  20. package/dist/ContextMenu.svelte.d.ts +2 -0
  21. package/dist/DatePicker.svelte +21 -11
  22. package/dist/FieldErrorLine.svelte +24 -0
  23. package/dist/FieldErrorLine.svelte.d.ts +7 -0
  24. package/dist/FieldRow.svelte +16 -4
  25. package/dist/FileUpload.svelte +14 -4
  26. package/dist/FileUpload.svelte.d.ts +2 -0
  27. package/dist/FortressPermissions.svelte +3 -1
  28. package/dist/HoverCard.svelte +34 -5
  29. package/dist/HoverCard.svelte.d.ts +12 -2
  30. package/dist/IconTipButton.svelte +6 -2
  31. package/dist/IconTipButton.svelte.d.ts +3 -0
  32. package/dist/InfoBubble.svelte +1 -1
  33. package/dist/ListRow.svelte +71 -6
  34. package/dist/ListRow.svelte.d.ts +17 -2
  35. package/dist/ListSelect.svelte +7 -2
  36. package/dist/ListTable.svelte +36 -16
  37. package/dist/ListTable.svelte.d.ts +5 -0
  38. package/dist/MenuSelect.svelte +11 -3
  39. package/dist/Meter.svelte +21 -3
  40. package/dist/Meter.svelte.d.ts +4 -0
  41. package/dist/MultiSelect.svelte +156 -0
  42. package/dist/MultiSelect.svelte.d.ts +20 -0
  43. package/dist/NotifyCard.svelte +1 -1
  44. package/dist/NumberField.svelte +2 -2
  45. package/dist/Pagination.svelte +15 -5
  46. package/dist/PasswordField.svelte +7 -6
  47. package/dist/PinInput.svelte +4 -2
  48. package/dist/Rating.svelte +10 -1
  49. package/dist/RevealEye.svelte +17 -0
  50. package/dist/RevealEye.svelte.d.ts +6 -0
  51. package/dist/SearchHit.svelte +10 -0
  52. package/dist/SearchHit.svelte.d.ts +7 -0
  53. package/dist/Selector.svelte +28 -4
  54. package/dist/Selector.svelte.d.ts +4 -3
  55. package/dist/SettingsNav.svelte +152 -0
  56. package/dist/SettingsNav.svelte.d.ts +46 -0
  57. package/dist/SignInTile.svelte +124 -114
  58. package/dist/SkeletonRow.svelte +8 -2
  59. package/dist/SkeletonRow.svelte.d.ts +4 -0
  60. package/dist/Slider.svelte +1 -0
  61. package/dist/Sparkline.svelte +24 -0
  62. package/dist/Sparkline.svelte.d.ts +11 -0
  63. package/dist/StatusSummary.svelte +55 -0
  64. package/dist/StatusSummary.svelte.d.ts +18 -0
  65. package/dist/SubCard.svelte +16 -16
  66. package/dist/SubCard.svelte.d.ts +3 -3
  67. package/dist/TextArea.svelte +13 -3
  68. package/dist/TextField.svelte +2 -2
  69. package/dist/TimeDial.svelte +74 -0
  70. package/dist/TimeDial.svelte.d.ts +13 -0
  71. package/dist/TimePicker.svelte +57 -0
  72. package/dist/TimePicker.svelte.d.ts +19 -0
  73. package/dist/TimeRangePicker.svelte +52 -0
  74. package/dist/TimeRangePicker.svelte.d.ts +16 -0
  75. package/dist/TimeShell.svelte +145 -0
  76. package/dist/TimeShell.svelte.d.ts +16 -0
  77. package/dist/Timer.svelte +6 -1
  78. package/dist/TipBubble.svelte +1 -1
  79. package/dist/ToastCard.svelte +7 -3
  80. package/dist/ToastCard.svelte.d.ts +2 -0
  81. package/dist/ToastViewport.svelte +6 -3
  82. package/dist/Toggle.svelte +3 -1
  83. package/dist/Tour.svelte +8 -2
  84. package/dist/Window.svelte +5 -3
  85. package/dist/Window.svelte.d.ts +3 -1
  86. package/dist/bubble.svelte.d.ts +12 -1
  87. package/dist/bubble.svelte.js +13 -5
  88. package/dist/engines.svelte.d.ts +7 -1
  89. package/dist/engines.svelte.js +13 -1
  90. package/dist/entries/multiselect.d.ts +1 -0
  91. package/dist/entries/multiselect.js +2 -0
  92. package/dist/glyphs.d.ts +3 -0
  93. package/dist/glyphs.js +3 -0
  94. package/dist/index.d.ts +13 -7
  95. package/dist/index.js +9 -4
  96. package/package.json +7 -2
  97. package/dist/AboutCard.svelte +0 -116
  98. package/dist/AboutCard.svelte.d.ts +0 -40
  99. package/dist/DropdownListbox.svelte +0 -178
  100. package/dist/DropdownListbox.svelte.d.ts +0 -23
@@ -5,23 +5,27 @@
5
5
  value: number;
6
6
  onChange?: (value: number) => void;
7
7
  step?: number;
8
- /** The angles that carry a tick on the dial. */
8
+ /** The angles that carry a tick on the dial. A tick on a quarter is longer. */
9
9
  marks?: number[];
10
10
  disabled?: boolean;
11
11
  }
12
12
  </script>
13
13
 
14
14
  <script lang="ts">
15
+ import type { KeyboardEventHandler } from "svelte/elements";
15
16
  import * as angleSlider from "@zag-js/angle-slider";
16
17
  import { normalizeProps, useMachine } from "@zag-js/svelte";
17
- import { pageDir } from "@glimstone/core";
18
+ import { ANGLE_MARKS, angleKeyTarget, pageDir } from "@glimstone/core";
18
19
  import { useFieldName } from "./fieldName.js";
19
20
 
20
21
  // An angle set on a dial, such as how far a picture turns. The dial is round
21
- // whatever the shape setting, since a circle is its geometry and not a corner,
22
- // and the value stands beside it in degrees, left to right in every language.
23
- // Inside a FieldRow the row names it.
24
- let { label, value = $bindable(), onChange, step = 1, marks = [0, 90, 180, 270], disabled = false }: AngleSliderProps = $props();
22
+ // whatever the shape setting, since a circle is its geometry and not a corner.
23
+ // A hand points from the middle to the knob, and the value stands in the
24
+ // middle in degrees, left to right in every language. It snaps every 15
25
+ // degrees unless `step` asks for finer, with a tick at each snap. Inside a
26
+ // FieldRow the row names it.
27
+
28
+ let { label, value = $bindable(), onChange, step = 15, marks = ANGLE_MARKS, disabled = false }: AngleSliderProps = $props();
25
29
 
26
30
  const name = useFieldName(() => label);
27
31
  const id = $props.id();
@@ -37,6 +41,24 @@
37
41
  },
38
42
  }));
39
43
  const api = $derived(angleSlider.connect(service, normalizeProps));
44
+ // Zag sends End to 359 whatever the step, so Home and End are answered here.
45
+ const thumb = $derived.by(() => {
46
+ const own = api.getThumbProps();
47
+ const onkeydown: KeyboardEventHandler<HTMLElement> = (e) => {
48
+ const to = angleKeyTarget(e.key, step);
49
+ if (to === undefined) return own.onkeydown?.(e);
50
+ e.preventDefault();
51
+ api.setValue(to);
52
+ };
53
+ return { ...own, onkeydown };
54
+ });
55
+ // A turn past 0° would spring the long way round, so that step lands at once.
56
+ let last: number | undefined;
57
+ const across = $derived.by(() => {
58
+ const turn = last !== undefined && Math.abs(api.value - last) > 180;
59
+ last = api.value;
60
+ return turn;
61
+ });
40
62
  </script>
41
63
 
42
64
  <div data-glim="AngleSlider" {...api.getRootProps()} class="glim-angle">
@@ -45,12 +67,14 @@
45
67
  <div {...api.getControlProps()} class="glim-angle-dial">
46
68
  <div {...api.getMarkerGroupProps()} class="glim-angle-marks">
47
69
  {#each marks as mark (mark)}
48
- <span {...api.getMarkerProps({ value: mark })} class="glim-angle-mark"></span>
70
+ <span {...api.getMarkerProps({ value: mark })} data-quarter={mark % 90 === 0 ? "" : undefined} class="glim-angle-mark"></span>
49
71
  {/each}
50
72
  </div>
51
- <div {...api.getThumbProps()} aria-valuetext={`${api.value}°`} class="glim-angle-thumb"></div>
73
+ <div {...thumb} aria-valuetext={`${api.value}°`} data-across={across ? "" : undefined} class="glim-angle-thumb">
74
+ <span class="glim-angle-hand"></span>
75
+ </div>
76
+ <div {...api.getValueTextProps()} class="glim-angle-value glim-num">{`${api.value}°`}</div>
52
77
  </div>
53
- <div {...api.getValueTextProps()} class="glim-angle-value glim-num">{`${api.value}°`}</div>
54
78
  </div>
55
79
  <input {...api.getHiddenInputProps()} />
56
80
  </div>
@@ -4,7 +4,7 @@ export interface AngleSliderProps {
4
4
  value: number;
5
5
  onChange?: (value: number) => void;
6
6
  step?: number;
7
- /** The angles that carry a tick on the dial. */
7
+ /** The angles that carry a tick on the dial. A tick on a quarter is longer. */
8
8
  marks?: number[];
9
9
  disabled?: boolean;
10
10
  }
@@ -26,7 +26,7 @@
26
26
  const id = $props.id();
27
27
  const service = useMachine(avatar.machine, () => ({ id, dir: pageDir() }));
28
28
  const api = $derived(avatar.connect(service, normalizeProps));
29
- const view = $derived(avatarView({ size, hueIndex }));
29
+ const view = $derived(avatarView({ size, hueIndex, name }));
30
30
  </script>
31
31
 
32
32
  <span data-glim="Avatar" {...api.getRootProps()} role="img" aria-label={name} class={view.className} style={css(view.style)}>
package/dist/Badge.svelte CHANGED
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
- import type { BadgeForm, BadgeShape, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
3
+ import type { BadgeForm, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
4
4
 
5
- export type { BadgeForm, BadgeShape, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
5
+ export type { BadgeForm, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
6
6
 
7
7
  export interface BadgeProps {
8
8
  children: Snippet;
@@ -14,9 +14,6 @@
14
14
  /** The corners: rounded, square, pill or circle. Without it they follow the
15
15
  * shape setting. */
16
16
  form?: BadgeForm;
17
- /** @deprecated Use `form`. Only "circle" has an effect: it makes the badge
18
- * icon-only. */
19
- shape?: BadgeShape;
20
17
  /** Render as a <button> or a real <a href>, with the same box as a span. */
21
18
  as?: "span" | "button" | "a";
22
19
  onClick?: () => void;
@@ -72,7 +69,6 @@
72
69
  tone = "neutral",
73
70
  size = "medium",
74
71
  form,
75
- shape,
76
72
  as = "span",
77
73
  onClick,
78
74
  disabled,
@@ -99,7 +95,7 @@
99
95
  // `.glim-notch-hue` drives the card-wide reactive hover in tokens.css, so
100
96
  // it is only set on a heading-sized badge.
101
97
  hueOn && size === "heading" && "glim-notch-hue",
102
- badgeClassName({ tone, size, form, shape, wrap, iconOnly: tip !== undefined, inFlow, insetStart, action: as !== "span" }),
98
+ badgeClassName({ tone, size, form, wrap, iconOnly: tip !== undefined, inFlow, insetStart, action: as !== "span" }),
103
99
  className,
104
100
  ]
105
101
  .filter(Boolean)
@@ -1,6 +1,6 @@
1
1
  import type { Snippet } from "svelte";
2
- import type { BadgeForm, BadgeShape, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
3
- export type { BadgeForm, BadgeShape, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
2
+ import type { BadgeForm, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
3
+ export type { BadgeForm, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
4
4
  export interface BadgeProps {
5
5
  children: Snippet;
6
6
  /** Status colour. Defaults to the neutral chip. */
@@ -11,9 +11,6 @@ export interface BadgeProps {
11
11
  /** The corners: rounded, square, pill or circle. Without it they follow the
12
12
  * shape setting. */
13
13
  form?: BadgeForm;
14
- /** @deprecated Use `form`. Only "circle" has an effect: it makes the badge
15
- * icon-only. */
16
- shape?: BadgeShape;
17
14
  /** Render as a <button> or a real <a href>, with the same box as a span. */
18
15
  as?: "span" | "button" | "a";
19
16
  onClick?: () => void;
package/dist/Card.svelte CHANGED
@@ -10,6 +10,9 @@
10
10
  /** One line saying what this whole card does, drawn as an "(i)" beside the
11
11
  * title. */
12
12
  hint?: string;
13
+ /** One control for the whole card, such as an icon button or a status
14
+ * badge, at the end of the top edge level with the notch. */
15
+ action?: Snippet;
13
16
  children: Snippet;
14
17
  /** This card's position in the rainbow, counted across the cards visible on
15
18
  * the active tab. Omit it for a tab's only card. */
@@ -39,7 +42,7 @@
39
42
  // but keeps its top padding, which the heading notch pokes into.
40
43
  //
41
44
  // A card with neither `title` nor `hint` draws no heading.
42
- let { title, drawn, hint, children, hueIndex, nested, ...data }: CardProps = $props();
45
+ let { title, drawn, hint, action, children, hueIndex, nested, ...data }: CardProps = $props();
43
46
  </script>
44
47
 
45
48
  <div
@@ -57,5 +60,6 @@
57
60
  </Badge>
58
61
  </h2>
59
62
  {/if}
63
+ {#if action}<div class="glim-panel-action">{@render action()}</div>{/if}
60
64
  {@render children()}
61
65
  </div>
@@ -8,6 +8,9 @@ export interface CardProps {
8
8
  /** One line saying what this whole card does, drawn as an "(i)" beside the
9
9
  * title. */
10
10
  hint?: string;
11
+ /** One control for the whole card, such as an icon button or a status
12
+ * badge, at the end of the top edge level with the notch. */
13
+ action?: Snippet;
11
14
  children: Snippet;
12
15
  /** This card's position in the rainbow, counted across the cards visible on
13
16
  * the active tab. Omit it for a tab's only card. */
@@ -0,0 +1,84 @@
1
+ <script lang="ts" module>
2
+ import type { ChartKind, ChartRow, ChartSeries } from "@glimstone/core";
3
+
4
+ export type { ChartKind, ChartRow, ChartSeries } from "@glimstone/core";
5
+
6
+ export interface ChartProps {
7
+ data: readonly ChartRow[];
8
+ /** The field that names each point on the x axis, such as "day". */
9
+ x: string;
10
+ series: readonly ChartSeries[];
11
+ /** What the chart shows, for a screen reader. */
12
+ label: string;
13
+ kind?: ChartKind;
14
+ height?: number;
15
+ /** How a figure reads on the axis and in the tooltip. */
16
+ format?: (n: number) => string;
17
+ /** The legend under the plot, shown where there is more than one series. */
18
+ legend?: boolean;
19
+ }
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import { chartIndexAt, chartLayout, chartTooltip, chartTooltipPlace, watchChartFrame } from "@glimstone/core";
24
+ import ChartLegend from "./ChartLegend.svelte";
25
+
26
+ // A bar, line or area chart on the frame every chart shares; chart.ts in the
27
+ // core lays it out. The figures live in the tooltip, so the drawing itself is
28
+ // one image named by `label`.
29
+ let { data, x, series, label, kind = "bar", height = 200, format, legend = true }: ChartProps = $props();
30
+
31
+ let box: HTMLDivElement;
32
+ let frame = $state({ width: 0, radius: 4 });
33
+ $effect(() => watchChartFrame(box, (f) => (frame = f)));
34
+ let hover = $state<number | null>(null);
35
+ const layout = $derived(chartLayout({ data, x, series, kind, width: frame.width, height, radius: frame.radius, format }));
36
+ const tip = $derived(hover === null ? null : { ...chartTooltip(data, x, series, hover, format), ...chartTooltipPlace(layout, hover) });
37
+ const move = (e: PointerEvent & { currentTarget: SVGSVGElement }) => (hover = chartIndexAt(layout, e.clientX - e.currentTarget.getBoundingClientRect().left));
38
+ </script>
39
+
40
+ <div data-glim="Chart" class="glim-chart">
41
+ <div bind:this={box} class="glim-chart-plot" style="height: {height}px">
42
+ {#if frame.width > 0}
43
+ <svg width={frame.width} {height} role="img" aria-label={label} onpointermove={move} onpointerleave={() => (hover = null)}>
44
+ {#each layout.ticks as t (t.value)}
45
+ <g>
46
+ <line x1={layout.plot.left} x2={layout.plot.left + layout.plot.width} y1={t.y} y2={t.y} class="glim-chart-grid" />
47
+ <text x={layout.plot.left - 8} y={t.y} dy="0.32em" text-anchor="end" class="glim-chart-tick">{t.text}</text>
48
+ </g>
49
+ {/each}
50
+ {#if hover !== null}
51
+ {#if kind === "bar"}
52
+ <rect x={layout.plot.left + layout.band * hover} y={layout.plot.top} width={layout.band} height={layout.plot.height} class="glim-chart-cursor" />
53
+ {:else}
54
+ <line x1={layout.centres[hover]} x2={layout.centres[hover]} y1={layout.plot.top} y2={layout.plot.top + layout.plot.height} class="glim-chart-cursor-line" />
55
+ {/if}
56
+ {/if}
57
+ {#each layout.bars as b (b.key)}<path class="glim-chart-bar" d={b.d} fill={b.color} />{/each}
58
+ {#each layout.lines as l (l.key)}
59
+ <g>
60
+ {#if kind === "area"}<path d={l.area} fill={l.color} class="glim-chart-area" />{/if}
61
+ <polyline points={l.points} fill="none" stroke={l.color} stroke-width="2" stroke-linejoin="round" stroke-linecap="round" />
62
+ {#if hover !== null}<circle cx={l.dots[hover]!.x} cy={l.dots[hover]!.y} r="4" fill={l.color} class="glim-chart-dot" />{/if}
63
+ </g>
64
+ {/each}
65
+ {#each layout.labels as l, i (i)}
66
+ <text x={l.x} y={height - 6} text-anchor="middle" class="glim-chart-tick">{l.text}</text>
67
+ {/each}
68
+ </svg>
69
+ {/if}
70
+ {#if tip}
71
+ <div class="glim-chart-tooltip" aria-hidden="true" style="left: {tip.left}px; top: {tip.top}px; translate: {tip.flip ? 'calc(-100% - 12px) 0' : '12px 0'}">
72
+ <div class="glim-chart-tooltip-title">{tip.title}</div>
73
+ {#each tip.rows as r (r.label)}
74
+ <div class="glim-chart-tooltip-row">
75
+ <span class="glim-chart-swatch" style="background: {r.color}"></span>
76
+ <span>{r.label}</span>
77
+ <span class="glim-chart-tooltip-value glim-num">{r.value}</span>
78
+ </div>
79
+ {/each}
80
+ </div>
81
+ {/if}
82
+ </div>
83
+ {#if legend && series.length > 1}<ChartLegend {series} />{/if}
84
+ </div>
@@ -0,0 +1,19 @@
1
+ import type { ChartKind, ChartRow, ChartSeries } from "@glimstone/core";
2
+ export type { ChartKind, ChartRow, ChartSeries } from "@glimstone/core";
3
+ export interface ChartProps {
4
+ data: readonly ChartRow[];
5
+ /** The field that names each point on the x axis, such as "day". */
6
+ x: string;
7
+ series: readonly ChartSeries[];
8
+ /** What the chart shows, for a screen reader. */
9
+ label: string;
10
+ kind?: ChartKind;
11
+ height?: number;
12
+ /** How a figure reads on the axis and in the tooltip. */
13
+ format?: (n: number) => string;
14
+ /** The legend under the plot, shown where there is more than one series. */
15
+ legend?: boolean;
16
+ }
17
+ declare const Chart: import("svelte").Component<ChartProps, {}, "">;
18
+ type Chart = ReturnType<typeof Chart>;
19
+ export default Chart;
@@ -0,0 +1,19 @@
1
+ <script lang="ts" module>
2
+ import type { ChartSeries } from "@glimstone/core";
3
+
4
+ export interface ChartLegendProps {
5
+ series: readonly ChartSeries[];
6
+ }
7
+ </script>
8
+
9
+ <script lang="ts">
10
+ import { seriesColor } from "@glimstone/core";
11
+
12
+ let { series }: ChartLegendProps = $props();
13
+ </script>
14
+
15
+ <ul data-glim="ChartLegend" class="glim-chart-legend">
16
+ {#each series as s, i (s.key)}
17
+ <li><span class="glim-chart-swatch" style="background: {seriesColor(s, i)}"></span>{s.label}</li>
18
+ {/each}
19
+ </ul>
@@ -0,0 +1,7 @@
1
+ import type { ChartSeries } from "@glimstone/core";
2
+ export interface ChartLegendProps {
3
+ series: readonly ChartSeries[];
4
+ }
5
+ declare const ChartLegend: import("svelte").Component<ChartLegendProps, {}, "">;
6
+ type ChartLegend = ReturnType<typeof ChartLegend>;
7
+ export default ChartLegend;
@@ -16,8 +16,6 @@
16
16
  </script>
17
17
 
18
18
  <script lang="ts">
19
- import { IconCheck } from "./glyphs.js";
20
-
21
19
  // The checkbox, for the places a box stands instead of a switch (rule 39):
22
20
  // "Don't show again" under a notice, and choices that are applied together,
23
21
  // such as which columns a list shows. Every setting is a Toggle. It is a
@@ -43,6 +41,21 @@
43
41
  onkeydown={(e) => e.key === "Enter" && e.preventDefault()}
44
42
  class={["glim-checkbox", slim && "glim-checkbox--slim", className].filter(Boolean).join(" ")}
45
43
  >
46
- <span class="glim-checkbox-box" aria-hidden="true">{@render IconCheck()}</span>
44
+ <!-- The tick draws itself in as its dash closes. -->
45
+ <span class="glim-checkbox-box" aria-hidden="true"
46
+ ><svg viewBox="0 0 14 14" width="14" height="14" fill="none" class="glim-mark"
47
+ ><path
48
+ d="M3 7.4 5.7 10 11 4.2"
49
+ stroke="currentColor"
50
+ stroke-width="2.2"
51
+ stroke-linecap="round"
52
+ stroke-linejoin="round"
53
+ pathLength="1"
54
+ stroke-dasharray="1"
55
+ stroke-dashoffset={checked ? 0 : 1}
56
+ class="glim-checkbox-tick"
57
+ /></svg
58
+ ></span
59
+ >
47
60
  {#if !bare}<span>{label}</span>{/if}
48
61
  </button>
@@ -17,6 +17,8 @@
17
17
  onClose?: () => void;
18
18
  /** The names a colour is matched against, nearest in OKLab. `false` shows none. */
19
19
  names?: readonly ColorName[] | false;
20
+ /** The ready colours under the hue bar, as `#rrggbb`. The page's rainbow unless given, and `false` shows none. */
21
+ swatches?: string[] | false;
20
22
  /** The words, read when the picker opens. */
21
23
  text?: Partial<ColorPickerPanelText>;
22
24
  class?: string;
@@ -24,16 +26,28 @@
24
26
  </script>
25
27
 
26
28
  <script lang="ts">
27
- import { COLOR_NAMES_DE, COLOR_PICKER_TEXT, colorPicker, floatColorPicker, nearestColorName, normalizeHex } from "@glimstone/core";
29
+ import {
30
+ canPickFromScreen,
31
+ COLOR_NAMES_DE,
32
+ COLOR_PICKER_TEXT,
33
+ colorPicker,
34
+ floatColorPicker,
35
+ nearestColorName,
36
+ normalizeHex,
37
+ pickFromScreen,
38
+ rainbowSwatches,
39
+ } from "@glimstone/core";
28
40
  import Button from "./Button.svelte";
29
- import { IconCheck } from "./glyphs.js";
41
+ import IconButton from "./IconButton.svelte";
42
+ import { IconCheck, IconEyedropper } from "./glyphs.js";
30
43
  import { lift } from "./lift.js";
31
44
 
32
45
  // The colour picker as a component: the core's square and hue bar, a preview
33
- // with the name the colour proposes, the hex field and Apply. Nothing changes
46
+ // with the name the colour proposes, a row of ready colours, the hex field, an
47
+ // eyedropper where the browser has one, and Apply. Nothing changes
34
48
  // until Apply, so a caller can show the colour live through onInput and still
35
49
  // keep the old one when the picker closes without it.
36
- let { value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, text, class: className }: ColorPickerProps = $props();
50
+ let { value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, swatches, text, class: className }: ColorPickerProps = $props();
37
51
 
38
52
  // The words and the colour are read once, when the picker opens.
39
53
  // svelte-ignore state_referenced_locally
@@ -42,6 +56,8 @@
42
56
  const start = normalizeHex(value) ?? "#000000";
43
57
  let draft = $state(start);
44
58
  let typed = $state(start);
59
+ let ready = $state<string[]>([]);
60
+ const dropper = canPickFromScreen();
45
61
  const widget = colorPicker(
46
62
  start,
47
63
  (hex) => {
@@ -74,6 +90,18 @@
74
90
  return done;
75
91
  });
76
92
 
93
+ $effect.pre(() => {
94
+ ready = swatches === false ? [] : (swatches ?? rainbowSwatches()).flatMap((c) => normalizeHex(c) ?? []);
95
+ });
96
+
97
+ /** A colour from a ready swatch or from the screen, taken as a drag on the square would be. */
98
+ function take(hex: string) {
99
+ draft = hex;
100
+ typed = hex;
101
+ widget.setValue(hex);
102
+ onInput?.(hex);
103
+ }
104
+
77
105
  const name = $derived(names === false ? null : nearestColorName(draft, names));
78
106
 
79
107
  function apply() {
@@ -111,10 +139,27 @@
111
139
  onkeydown={onKeyDown}
112
140
  >
113
141
  <div bind:this={host} style="display: contents"></div>
142
+ {#if ready.length > 0}
143
+ <div role="group" aria-label={words.swatches} class="glim-picker-swatches">
144
+ {#each ready as hex}
145
+ <button type="button" aria-label={hex} aria-pressed={hex === draft} class="glim-picker-preset" style:--glim-preset={hex} onclick={() => take(hex)}></button>
146
+ {/each}
147
+ </div>
148
+ {/if}
114
149
  <div class="glim-picker-foot">
115
150
  <span class="glim-picker-swatch" aria-hidden="true"></span>
116
151
  {#if name !== null}<span class="glim-picker-name">{name}</span>{/if}
117
152
  <input class="glim-picker-hex" value={typed} maxlength={7} spellcheck={false} aria-label={words.hex} oninput={onTyped} />
153
+ {#if dropper}
154
+ <IconButton
155
+ tip={words.eyedropper}
156
+ glyph={IconEyedropper}
157
+ onclick={async () => {
158
+ const hex = await pickFromScreen();
159
+ if (hex) take(hex);
160
+ }}
161
+ />
162
+ {/if}
118
163
  </div>
119
164
  <div class="glim-picker-actions">
120
165
  <Button label={words.apply} labelKey="apply" glyph={IconCheck} tone="accent" onClick={apply} />
@@ -14,6 +14,8 @@ export interface ColorPickerProps {
14
14
  onClose?: () => void;
15
15
  /** The names a colour is matched against, nearest in OKLab. `false` shows none. */
16
16
  names?: readonly ColorName[] | false;
17
+ /** The ready colours under the hue bar, as `#rrggbb`. The page's rainbow unless given, and `false` shows none. */
18
+ swatches?: string[] | false;
17
19
  /** The words, read when the picker opens. */
18
20
  text?: Partial<ColorPickerPanelText>;
19
21
  class?: string;
@@ -23,17 +23,20 @@
23
23
  import { useFieldName } from "./fieldName.js";
24
24
  import { IconCheck, IconExpand } from "./glyphs.js";
25
25
  import { lift } from "./lift.js";
26
+ import SearchHit from "./SearchHit.svelte";
26
27
 
27
28
  // A field that filters a list while somebody types, for lists too long for a
28
29
  // Select: containers, time zones, languages. Focus stays in the field while
29
30
  // the arrows move through the list, and a search that finds nothing says so
30
31
  // instead of closing, since a list that vanishes reads as a broken field.
32
+ // While somebody types, each row sets apart the part that matches.
31
33
  let { label, hideLabel, options, value = $bindable(), onChange, placeholder, empty, toggleLabel, disabled }: ComboboxProps = $props();
32
34
 
33
35
  const name = useFieldName(() => label);
34
36
  const id = $props.id();
35
37
  // svelte-ignore state_referenced_locally
36
38
  let shown = $state.raw(options);
39
+ let query = $state("");
37
40
  const service = useMachine(combobox.machine, () => ({
38
41
  id,
39
42
  collection: combobox.collection({
@@ -49,10 +52,15 @@
49
52
  // Typing opens the list after the filter has run, so only a close may put
50
53
  // the full list back.
51
54
  onOpenChange: ({ open }: { open: boolean }) => {
52
- if (!open) shown = options;
55
+ if (open) return;
56
+ shown = options;
57
+ query = "";
53
58
  },
54
- onInputValueChange: ({ inputValue }: { inputValue: string }) => {
55
- const q = inputValue.toLocaleLowerCase();
59
+ onInputValueChange: ({ inputValue, reason }: { inputValue: string; reason?: string }) => {
60
+ // Picking an item writes its label into the field, which is no search.
61
+ const typed = reason === "input-change" ? inputValue : "";
62
+ const q = typed.toLocaleLowerCase();
63
+ query = typed;
56
64
  shown = options.filter((o) => o.label.toLocaleLowerCase().includes(q));
57
65
  },
58
66
  onValueChange: (d: { value: string[] }) => {
@@ -78,7 +86,7 @@
78
86
  {/if}
79
87
  {#each shown as item (item.value)}
80
88
  <li {...api.getItemProps({ item })} class="glim-select-item">
81
- <span {...api.getItemTextProps({ item })}>{item.label}</span>
89
+ <span {...api.getItemTextProps({ item })} data-search={query ? "" : undefined}><SearchHit label={item.label} {query} /></span>
82
90
  <span {...api.getItemIndicatorProps({ item })} class="glim-select-check">{@render IconCheck()}</span>
83
91
  </li>
84
92
  {/each}
@@ -31,6 +31,7 @@
31
31
  </script>
32
32
 
33
33
  <script lang="ts">
34
+ import { leaveBehind, splitQuestion } from "@glimstone/core";
34
35
  import Badge from "./Badge.svelte";
35
36
  import Button from "./Button.svelte";
36
37
  import { IconCancel, IconClose } from "./glyphs.js";
@@ -56,6 +57,7 @@
56
57
  onCancel,
57
58
  ref = $bindable(null),
58
59
  }: ConfirmDialogProps = $props();
60
+ const split = $derived(splitQuestion(message));
59
61
 
60
62
  // Focus lands on Cancel, the answer that changes nothing.
61
63
  let cancel = $state<HTMLElement | null>(null);
@@ -64,6 +66,7 @@
64
66
 
65
67
  <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
66
68
  <div
69
+ {@attach leaveBehind}
67
70
  class="glim-modal-backdrop"
68
71
  onclick={(e) => {
69
72
  if (e.target === e.currentTarget) onCancel();
@@ -77,7 +80,7 @@
77
80
  aria-modal="true"
78
81
  aria-labelledby="confirmdialog-title"
79
82
  aria-describedby="confirmdialog-message"
80
- class="glim-modal-card"
83
+ class="glim-modal-card glim-window--small"
81
84
  >
82
85
  <div class="glim-modal-head">
83
86
  <!-- The title is a heading badge that straddles the card's top edge
@@ -91,7 +94,10 @@
91
94
  </div>
92
95
 
93
96
  <div class="glim-modal-body">
94
- <p id="confirmdialog-message" class="glim-modal-text">{message}</p>
97
+ <div id="confirmdialog-message">
98
+ <p class="glim-modal-question">{split.question}</p>
99
+ {#if split.detail}<p class="glim-modal-text">{split.detail}</p>{/if}
100
+ </div>
95
101
  {#if extra !== undefined}
96
102
  <div class="glim-modal-extra">{@render extra()}</div>
97
103
  {/if}
@@ -18,6 +18,8 @@
18
18
  badges?: Snippet;
19
19
  /** More quiet lines under the status, such as what uses the connection. */
20
20
  children?: Snippet;
21
+ /** A switch of the row, such as whether a service shows on the sign-in page, at the end of the name's line above the buttons. */
22
+ control?: Snippet;
21
23
  /** Where the test stands: `busy` while it runs, then `tone` and a `title` with what it found. */
22
24
  test?: ConnectionTest;
23
25
  /** Buttons of the app's own, such as Mount, before Test, Edit and Remove, so those keep their places at the end. */
@@ -43,7 +45,7 @@
43
45
  // badges, one quiet line on how it stands, and at the end the app's own
44
46
  // actions, then its test, edit and remove. A built-in button stands only where
45
47
  // its handler is passed. The other props of a <div> go to the row.
46
- let { name, mark, status, badges, children, test, actions, text, labelKeys, onTest, onEdit, onRemove, class: className, ...rest }: ConnectionRowProps = $props();
48
+ let { name, mark, status, badges, children, control, test, actions, text, labelKeys, onTest, onEdit, onRemove, class: className, ...rest }: ConnectionRowProps = $props();
47
49
 
48
50
  // On a phone the buttons show their glyphs alone, so they keep to one line.
49
51
  const NARROW = 640;
@@ -67,6 +69,7 @@
67
69
  <div class="glim-connection-head">
68
70
  <span class="glim-connection-name">{name}</span>
69
71
  {#if badges}<span class="glim-connection-badges">{@render badges()}</span>{/if}
72
+ {@render control?.()}
70
73
  </div>
71
74
  <div class="glim-connection-foot">
72
75
  <div class="glim-connection-about">
@@ -14,6 +14,8 @@ export interface ConnectionRowProps extends Omit<HTMLAttributes<HTMLDivElement>,
14
14
  badges?: Snippet;
15
15
  /** More quiet lines under the status, such as what uses the connection. */
16
16
  children?: Snippet;
17
+ /** A switch of the row, such as whether a service shows on the sign-in page, at the end of the name's line above the buttons. */
18
+ control?: Snippet;
17
19
  /** Where the test stands: `busy` while it runs, then `tone` and a `title` with what it found. */
18
20
  test?: ConnectionTest;
19
21
  /** Buttons of the app's own, such as Mount, before Test, Edit and Remove, so those keep their places at the end. */
@@ -13,6 +13,8 @@
13
13
  items: MenuEntry[];
14
14
  /** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
15
15
  above?: boolean;
16
+ /** Line the menu's end edge up with the point, for a menu opened from a button at a row's end (`menuPointUnder()`). */
17
+ end?: boolean;
16
18
  /** The menu's accessible name. */
17
19
  label?: string;
18
20
  /** The menu element's id, for a caller or a script that looks for it. */
@@ -57,7 +59,7 @@
57
59
  // A submenu opens beside its row as a second menu on the body, one level deep.
58
60
  // A checkbox item leaves the menu open, so several can be ticked in a row; the
59
61
  // caller flips `checked` and the row follows.
60
- let { x, y, items, above = false, label, id, opener, onClose, onStep, fromEnd = false }: ContextMenuProps = $props();
62
+ let { x, y, items, above = false, end = false, label, id, opener, onClose, onStep, fromEnd = false }: ContextMenuProps = $props();
61
63
 
62
64
  let menu = $state<HTMLElement | null>(null);
63
65
  let subMenu = $state<HTMLElement | null>(null);
@@ -87,7 +89,7 @@
87
89
  }
88
90
 
89
91
  $effect(() => {
90
- if (menu) pos = placeMenu(x, y, { width: menu.offsetWidth, height: menu.offsetHeight }, viewport(), above);
92
+ if (menu) pos = placeMenu(x, y, { width: menu.offsetWidth, height: menu.offsetHeight }, viewport(), above, end, getComputedStyle(menu).direction === "rtl");
91
93
  });
92
94
 
93
95
  onMount(() => {
@@ -10,6 +10,8 @@ export interface ContextMenuProps {
10
10
  items: MenuEntry[];
11
11
  /** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
12
12
  above?: boolean;
13
+ /** Line the menu's end edge up with the point, for a menu opened from a button at a row's end (`menuPointUnder()`). */
14
+ end?: boolean;
13
15
  /** The menu's accessible name. */
14
16
  label?: string;
15
17
  /** The menu element's id, for a caller or a script that looks for it. */