@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
@@ -50,6 +50,7 @@
50
50
  signInServiceStatus,
51
51
  signInTileCards,
52
52
  signInWhen,
53
+ signInCardGlyphKey,
53
54
  signInCardNotice,
54
55
  signInPasswordAsks,
55
56
  signInPasswordElsewhere,
@@ -123,7 +124,7 @@
123
124
  const eye = $derived({ show: text.show, hide: text.hide, confirm: text.confirmPassword, mismatch: text.mismatch });
124
125
  const err = (field: SignInTileField) => (s.invalid?.field === field ? s.invalid.message : undefined);
125
126
  const shown = $derived(signInTileCards(s, cards));
126
- const notice = (card: "askPassword" | "twoFactor" | "passkeys" | "tokens" | "services" | "sessions" | "accounts") => signInCardNotice(text, s, card);
127
+ const notice = (card: Exclude<SignInTileCard, "password">) => signInCardNotice(text, s, card);
127
128
  const elsewhere = $derived(signInPasswordElsewhere(text, s));
128
129
  const had = $derived(!!s.me?.password);
129
130
  const asks = $derived(signInPasswordAsks(s, cards) && !s.editing);
@@ -139,8 +140,10 @@
139
140
  }
140
141
  </script>
141
142
 
142
- {#snippet cardNotice(n: { title: string; reason: string })}
143
- <UnavailableNotice title={n.title} reason={n.reason} />
143
+ <!-- A card that waits for a password draws the empty state its list would, with the card's glyph. -->
144
+ {#snippet cardNotice(card: Exclude<SignInTileCard, "password">)}
145
+ {@const n = notice(card)!}
146
+ <EmptyState nested glyph={glyph(keys[signInCardGlyphKey(card)])} title={n.title} />
144
147
  {/snippet}
145
148
 
146
149
  {#snippet askPasswordRow()}
@@ -168,7 +171,7 @@
168
171
  {#if asks}{@render askPasswordRow()}{/if}
169
172
  </FieldRowGroup>
170
173
  {:else if !s.editing}
171
- <EmptyState nested glyph={glyph(keys.setPassword)} title={t.none} hint={t.noneHint} />
174
+ <EmptyState nested glyph={glyph(keys.setPassword)} title={t.none} />
172
175
  {/if}
173
176
  {#if s.editing}
174
177
  <FieldRowGroup>
@@ -220,7 +223,7 @@
220
223
  {@const t = text.askPassword}
221
224
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="askPassword">
222
225
  {#if notice("askPassword")}
223
- {@render cardNotice(notice("askPassword")!)}
226
+ {@render cardNotice("askPassword")}
224
227
  {:else}
225
228
  {@render askPasswordRow()}
226
229
  {/if}
@@ -230,7 +233,7 @@
230
233
  {@const on = !!s.me?.twoFactor}
231
234
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="twoFactor">
232
235
  {#if notice("twoFactor")}
233
- {@render cardNotice(notice("twoFactor")!)}
236
+ {@render cardNotice("twoFactor")}
234
237
  {:else}
235
238
  <div class="glim-signin-tile-body">
236
239
  {#if on}
@@ -239,7 +242,7 @@
239
242
  <FieldRow label={t.codesLeft} value={plural(lang, t.codesLeftValue, s.me?.recoveryLeft ?? 0)} />
240
243
  </FieldRowGroup>
241
244
  {:else}
242
- <EmptyState nested glyph={glyph(keys.setUp)} title={t.none} hint={t.noneHint} />
245
+ <EmptyState nested glyph={glyph(keys.setUp)} title={t.none} />
243
246
  {/if}
244
247
  <div class="glim-signin-tile-foot">
245
248
  {#if on}
@@ -257,7 +260,7 @@
257
260
  {@const here = s.passkeysHere}
258
261
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="passkeys">
259
262
  {#if notice("passkeys")}
260
- {@render cardNotice(notice("passkeys")!)}
263
+ {@render cardNotice("passkeys")}
261
264
  {:else}
262
265
  <div class="glim-signin-tile-body">
263
266
  {#if !here}<UnavailableNotice title={t.unavailableTitle} reason={t.unavailable} />{/if}
@@ -279,7 +282,7 @@
279
282
  {/each}
280
283
  </div>
281
284
  {:else if here}
282
- <EmptyState nested glyph={glyph(keys.passkey)} title={t.none} hint={t.noneHint} />
285
+ <EmptyState nested glyph={glyph(keys.passkey)} title={t.none} />
283
286
  {/if}
284
287
  {#if here}
285
288
  <div class="glim-signin-tile-foot">
@@ -293,7 +296,7 @@
293
296
  {@const t = text.sessions}
294
297
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="sessions">
295
298
  {#if notice("sessions")}
296
- {@render cardNotice(notice("sessions")!)}
299
+ {@render cardNotice("sessions")}
297
300
  {:else}
298
301
  <div class="glim-signin-tile-body">
299
302
  <div class="glim-signin-tile-rows">
@@ -328,7 +331,7 @@
328
331
  {@const t = text.tokens}
329
332
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="tokens">
330
333
  {#if notice("tokens")}
331
- {@render cardNotice(notice("tokens")!)}
334
+ {@render cardNotice("tokens")}
332
335
  {:else}
333
336
  <div class="glim-signin-tile-body">
334
337
  {#if s.tokens.length > 0}
@@ -348,7 +351,7 @@
348
351
  {/each}
349
352
  </div>
350
353
  {:else}
351
- <EmptyState nested glyph={glyph(keys.token)} title={t.none} hint={t.noneHint} />
354
+ <EmptyState nested glyph={glyph(keys.token)} title={t.none} />
352
355
  {/if}
353
356
  <div class="glim-signin-tile-foot">
354
357
  <Button label={t.create} labelKey={keys.createToken} data-signin-tile="token-ask" onClick={flow.askToken} />
@@ -360,7 +363,7 @@
360
363
  {@const t = text.services}
361
364
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="services">
362
365
  {#if notice("services")}
363
- {@render cardNotice(notice("services")!)}
366
+ {@render cardNotice("services")}
364
367
  {:else}
365
368
  <div class="glim-signin-tile-body">
366
369
  {#if (s.services?.length ?? 0) > 0}
@@ -396,6 +399,8 @@
396
399
  />
397
400
  {/each}
398
401
  </div>
402
+ {:else}
403
+ <EmptyState nested glyph={glyph(keys.service)} title={t.none} />
399
404
  {/if}
400
405
  <div class="glim-signin-tile-foot">
401
406
  <Button label={t.add} labelKey={keys.addService} data-signin-tile="service-pick" onClick={flow.pickService} />
@@ -407,7 +412,7 @@
407
412
  {@const t = text.accounts}
408
413
  <Card title={t.title} hint={t.hint} hueIndex={hue} data-signin-card="accounts">
409
414
  {#if notice("accounts")}
410
- {@render cardNotice(notice("accounts")!)}
415
+ {@render cardNotice("accounts")}
411
416
  {:else}
412
417
  <div class="glim-signin-tile-rows">
413
418
  {#each s.accounts ?? [] as a (a.id)}
@@ -6,6 +6,10 @@
6
6
  tile?: boolean;
7
7
  /** The badge at the row's end, for a list whose rows have one. */
8
8
  badge?: boolean;
9
+ /** A bar in the value column, for a list whose rows carry a `value`. */
10
+ value?: boolean;
11
+ /** How many row buttons to keep room for, so the value bar stands where the real rows put their figures. */
12
+ actions?: number;
9
13
  class?: string;
10
14
  }
11
15
  </script>
@@ -18,12 +22,14 @@
18
22
  // when the rows arrive. It shows only after BUSY_DELAY. The list around it
19
23
  // carries aria-busy and says what is loading; the row itself is hidden from
20
24
  // assistive technology.
21
- let { delay, tile = true, badge = true, class: className }: SkeletonRowProps = $props();
22
- const view = $derived(skeletonRowView({ delay, tile, badge }));
25
+ let { delay, tile = true, badge = true, value = false, actions = 0, class: className }: SkeletonRowProps = $props();
26
+ const view = $derived(skeletonRowView({ delay, tile, badge, value, actions }));
23
27
  </script>
24
28
 
25
29
  <div data-glim="SkeletonRow" aria-hidden="true" class={className ? `${view.className} ${className}` : view.className} style={css(view.style)}>
26
30
  {#if view.tile}<span class="glim-skeleton-block glim-skeleton-tile"></span>{/if}
27
31
  <span class="glim-skeleton-block glim-skeleton-name"></span>
28
32
  {#if view.badge}<span class="glim-skeleton-block glim-skeleton-badge"></span>{/if}
33
+ {#if view.value}<span class="glim-skeleton-block glim-skeleton-value"></span>{/if}
34
+ {#if view.actions > 0}<span class="glim-skeleton-actions"></span>{/if}
29
35
  </div>
@@ -5,6 +5,10 @@ export interface SkeletonRowProps {
5
5
  tile?: boolean;
6
6
  /** The badge at the row's end, for a list whose rows have one. */
7
7
  badge?: boolean;
8
+ /** A bar in the value column, for a list whose rows carry a `value`. */
9
+ value?: boolean;
10
+ /** How many row buttons to keep room for, so the value bar stands where the real rows put their figures. */
11
+ actions?: number;
8
12
  class?: string;
9
13
  }
10
14
  declare const SkeletonRow: import("svelte").Component<SkeletonRowProps, {}, "">;
@@ -53,6 +53,7 @@
53
53
  </div>
54
54
  {#each api.value as _, index (index)}
55
55
  <div {...api.getThumbProps({ index })} class="glim-slider-thumb">
56
+ <span class="glim-slider-bubble" aria-hidden="true">{format(api.value[index]!)}</span>
56
57
  <input {...api.getHiddenInputProps({ index })} />
57
58
  </div>
58
59
  {/each}
@@ -0,0 +1,24 @@
1
+ <script lang="ts" module>
2
+ export interface SparklineProps {
3
+ values: readonly number[];
4
+ /** What the line shows, for a screen reader. */
5
+ label: string;
6
+ color?: string;
7
+ width?: number;
8
+ height?: number;
9
+ }
10
+ </script>
11
+
12
+ <script lang="ts">
13
+ import { sparkline } from "@glimstone/core";
14
+
15
+ // A small line of the last values, beside a figure, without axes or a tooltip.
16
+ let { values, label, color = "var(--chart-1)", width = 96, height = 28 }: SparklineProps = $props();
17
+ const line = $derived(sparkline(values, width, height));
18
+ </script>
19
+
20
+ <svg data-glim="Sparkline" class="glim-sparkline" {width} {height} role="img" aria-label={label}>
21
+ <path d={line.area} fill={color} class="glim-chart-area" />
22
+ <polyline points={line.points} fill="none" stroke={color} stroke-width="1.5" stroke-linejoin="round" stroke-linecap="round" />
23
+ <circle cx={line.last[0]} cy={line.last[1]} r="2.5" fill={color} />
24
+ </svg>
@@ -0,0 +1,11 @@
1
+ export interface SparklineProps {
2
+ values: readonly number[];
3
+ /** What the line shows, for a screen reader. */
4
+ label: string;
5
+ color?: string;
6
+ width?: number;
7
+ height?: number;
8
+ }
9
+ declare const Sparkline: import("svelte").Component<SparklineProps, {}, "">;
10
+ type Sparkline = ReturnType<typeof Sparkline>;
11
+ export default Sparkline;
@@ -0,0 +1,55 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from "svelte";
3
+ import type { StatusNeed as CoreStatusNeed, StatusSummaryTone } from "@glimstone/core";
4
+
5
+ export type { StatusSummaryTone } from "@glimstone/core";
6
+ export type StatusNeed = CoreStatusNeed<Snippet>;
7
+
8
+ export interface StatusSummaryProps {
9
+ /** How things stand. A summary that says `ok` while something waits shows the warning's mark. */
10
+ tone: StatusSummaryTone;
11
+ /** The one sentence, such as "Documents needs a look" or "All is well". */
12
+ title: string;
13
+ /** A quiet line under it, such as when the last run was and when the next one is. */
14
+ detail?: string;
15
+ /** What waits for the person. A count of zero is left out, and with none the sentence stands alone. */
16
+ needs?: StatusNeed[];
17
+ class?: string;
18
+ }
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { statusSummaryView } from "@glimstone/core";
23
+ import Button from "./Button.svelte";
24
+ import MarkSvg from "./MarkSvg.svelte";
25
+
26
+ // The state of things at the top of an overview: one sentence with its mark,
27
+ // and under it only what wants something from the person, each count with its
28
+ // action (rule 33). It takes the place of a grid of tiles that count zeros.
29
+ let { tone, title, detail, needs, class: className }: StatusSummaryProps = $props();
30
+
31
+ const view = $derived(statusSummaryView(tone, needs));
32
+ </script>
33
+
34
+ <div data-glim="StatusSummary" data-tone={view.tone} class={className ? `glim-status-summary ${className}` : "glim-status-summary"}>
35
+ <div class="glim-status-summary-line">
36
+ <span class="glim-status-summary-mark" aria-hidden="true"><MarkSvg mark={view.mark} /></span>
37
+ <div>
38
+ <p class="glim-status-summary-title">{title}</p>
39
+ {#if detail}<p class="glim-status-summary-detail">{detail}</p>{/if}
40
+ </div>
41
+ </div>
42
+ {#if view.needs.length > 0}
43
+ <ul class="glim-card glim-status-summary-needs">
44
+ {#each view.needs as need (need.label)}
45
+ <!-- The whole row leads there. The button is its stop for the keyboard, and a press on it reaches the row. -->
46
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions -->
47
+ <li class="glim-status-summary-need" onclick={() => need.action.disabled || need.action.onClick()}>
48
+ <span class="glim-status-summary-count glim-num" data-tone={need.tone}>{need.count}</span>
49
+ <span class="glim-status-summary-label">{need.label}</span>
50
+ <Button tone="subtle" label={need.action.label} labelKey={need.action.labelKey} glyph={need.action.glyph} disabled={need.action.disabled} />
51
+ </li>
52
+ {/each}
53
+ </ul>
54
+ {/if}
55
+ </div>
@@ -0,0 +1,18 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { StatusNeed as CoreStatusNeed, StatusSummaryTone } from "@glimstone/core";
3
+ export type { StatusSummaryTone } from "@glimstone/core";
4
+ export type StatusNeed = CoreStatusNeed<Snippet>;
5
+ export interface StatusSummaryProps {
6
+ /** How things stand. A summary that says `ok` while something waits shows the warning's mark. */
7
+ tone: StatusSummaryTone;
8
+ /** The one sentence, such as "Documents needs a look" or "All is well". */
9
+ title: string;
10
+ /** A quiet line under it, such as when the last run was and when the next one is. */
11
+ detail?: string;
12
+ /** What waits for the person. A count of zero is left out, and with none the sentence stands alone. */
13
+ needs?: StatusNeed[];
14
+ class?: string;
15
+ }
16
+ declare const StatusSummary: import("svelte").Component<StatusSummaryProps, {}, "">;
17
+ type StatusSummary = ReturnType<typeof StatusSummary>;
18
+ export default StatusSummary;
@@ -2,25 +2,23 @@
2
2
  import type { Snippet } from "svelte";
3
3
 
4
4
  export interface SubCardProps {
5
- /** The group's name, drawn as a section badge on its top edge. */
5
+ /** The group's name, a title above its content. */
6
6
  title?: string;
7
- /** One line on what the group does, drawn as an "(i)" inside the badge. */
7
+ /** One line on what the group does, drawn as an "(i)" beside the title. */
8
8
  hint?: string;
9
9
  /** What belongs to the whole group, such as a switch, at the end of the
10
- * heading's row. */
10
+ * title's line. */
11
11
  end?: Snippet;
12
12
  children: Snippet;
13
13
  }
14
14
  </script>
15
15
 
16
16
  <script lang="ts">
17
- import Badge from "./Badge.svelte";
18
17
  import InfoBubble from "./InfoBubble.svelte";
19
18
 
20
- // A flat, filled group inside a card or a window. It groups without a second
21
- // raised surface and takes the place of a fold-out, so nothing hides behind a
22
- // click. Fields and quiet buttons inside it step up one surface, so they do
23
- // not vanish into its fill.
19
+ // A titled group that lies directly on a card or a window. It groups without
20
+ // a second surface and takes the place of a fold-out, so nothing hides behind
21
+ // a click.
24
22
  let { title, hint, end, children }: SubCardProps = $props();
25
23
  const titleId = $props.id();
26
24
  </script>
@@ -32,14 +30,16 @@
32
30
  aria-labelledby={title ? titleId : undefined}
33
31
  >
34
32
  <!-- The id is on the words alone, or the bubble's text would join the group's name. -->
35
- {#if title}
36
- <h3 class="glim-panel-heading">
37
- <Badge tone="heading" size="heading" wrap>
38
- <span id={titleId}>{title}</span>
39
- {#if hint}<InfoBubble tip={hint} onAccent />{/if}
40
- </Badge>
41
- </h3>
33
+ {#if title || end}
34
+ <div class="glim-subcard-head">
35
+ {#if title}
36
+ <h3 class="glim-subcard-title">
37
+ <span id={titleId}>{title}</span>
38
+ {#if hint}<InfoBubble tip={hint} />{/if}
39
+ </h3>
40
+ {/if}
41
+ {#if end}<div class="glim-subcard-end">{@render end()}</div>{/if}
42
+ </div>
42
43
  {/if}
43
- {#if end}<div class="glim-subcard-end">{@render end()}</div>{/if}
44
44
  {@render children()}
45
45
  </section>
@@ -1,11 +1,11 @@
1
1
  import type { Snippet } from "svelte";
2
2
  export interface SubCardProps {
3
- /** The group's name, drawn as a section badge on its top edge. */
3
+ /** The group's name, a title above its content. */
4
4
  title?: string;
5
- /** One line on what the group does, drawn as an "(i)" inside the badge. */
5
+ /** One line on what the group does, drawn as an "(i)" beside the title. */
6
6
  hint?: string;
7
7
  /** What belongs to the whole group, such as a switch, at the end of the
8
- * heading's row. */
8
+ * title's line. */
9
9
  end?: Snippet;
10
10
  children: Snippet;
11
11
  }
@@ -17,8 +17,8 @@
17
17
  </script>
18
18
 
19
19
  <script lang="ts">
20
- import { fieldErrorView, textFieldClass } from "@glimstone/core";
21
- import FieldError from "./FieldError.svelte";
20
+ import { fieldErrorView, fitTextArea, textFieldClass } from "@glimstone/core";
21
+ import FieldErrorLine from "./FieldErrorLine.svelte";
22
22
  import { useFieldName } from "./fieldName.js";
23
23
 
24
24
  // A few lines of text in the look of a TextField, bound with `bind:value`.
@@ -31,6 +31,7 @@
31
31
  class: className,
32
32
  id,
33
33
  "aria-describedby": describedBy,
34
+ oninput,
34
35
  value = $bindable(),
35
36
  ref = $bindable(null),
36
37
  ...rest
@@ -39,6 +40,11 @@
39
40
  const name = useFieldName(() => label);
40
41
  const own = $props.id();
41
42
  const err = $derived(fieldErrorView(error, id ?? own, describedBy ?? undefined));
43
+
44
+ $effect(() => {
45
+ void value;
46
+ fitTextArea(ref);
47
+ });
42
48
  </script>
43
49
 
44
50
  <textarea
@@ -47,9 +53,13 @@
47
53
  {...rest}
48
54
  bind:this={ref}
49
55
  bind:value
56
+ oninput={(e) => {
57
+ fitTextArea(e.currentTarget);
58
+ oninput?.(e);
59
+ }}
50
60
  {id}
51
61
  aria-invalid={err.invalid}
52
62
  aria-describedby={err.describedBy}
53
63
  class={`${textFieldClass({ width, mono, area: true })} ${className ?? ""}`.trim()}
54
64
  ></textarea>
55
- {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
65
+ <FieldErrorLine id={err.errorId} {error} />
@@ -20,7 +20,7 @@
20
20
 
21
21
  <script lang="ts">
22
22
  import { fieldErrorView, textFieldClass } from "@glimstone/core";
23
- import FieldError from "./FieldError.svelte";
23
+ import FieldErrorLine from "./FieldErrorLine.svelte";
24
24
  import { useFieldName } from "./fieldName.js";
25
25
 
26
26
  // A line of text: borderless and filled, focus a step up the ramp (rule 14).
@@ -58,4 +58,4 @@
58
58
  {type}
59
59
  class={`${textFieldClass({ width, mono })} ${className ?? ""}`.trim()}
60
60
  />
61
- {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
61
+ <FieldErrorLine id={err.errorId} {error} />
@@ -0,0 +1,74 @@
1
+ <script lang="ts" module>
2
+ import type { ClockFace } from "@glimstone/core";
3
+
4
+ export interface TimeDialProps {
5
+ anchor: HTMLElement;
6
+ face: ClockFace;
7
+ value: number | null;
8
+ minuteStep: number;
9
+ onPoint: (value: number, done: boolean) => void;
10
+ onTurn: (delta: 1 | -1) => void;
11
+ onClose: () => void;
12
+ }
13
+ </script>
14
+
15
+ <script lang="ts">
16
+ import { untrack } from "svelte";
17
+ import { DIAL, anchorName, attachDial, dialAngle, dialInner, dialMarks, floatBeside, nearestTurn } from "@glimstone/core";
18
+
19
+ // The clock face over a time field, a pointer aid on top of the segments:
20
+ // it floats beside the field without the focus and is hidden from a screen
21
+ // reader, since the segments it edits are the controls.
22
+ let { anchor, face, value, minuteStep, onPoint, onTurn, onClose }: TimeDialProps = $props();
23
+
24
+ let panel: HTMLDivElement;
25
+ let plate: SVGSVGElement;
26
+ const id = $props.id();
27
+ const middle = DIAL.size / 2;
28
+ const marks = $derived(dialMarks(face));
29
+ const reach = $derived(value !== null && dialInner(face, value) ? DIAL.inner : DIAL.outer);
30
+ // The hand keeps the turn it stands at, so the next value is reached the short way round.
31
+ let turned = $state(0);
32
+ $effect.pre(() => {
33
+ if (value !== null) turned = nearestTurn(untrack(() => turned), dialAngle(face, value));
34
+ });
35
+
36
+ $effect(() => {
37
+ const unfloat = floatBeside(panel, untrack(() => anchor), anchorName(id), () => onClose());
38
+ const unattach = attachDial(plate, {
39
+ face: () => face,
40
+ step: () => minuteStep,
41
+ point: (v, done) => onPoint(v, done),
42
+ turn: (delta) => onTurn(delta),
43
+ });
44
+ return () => {
45
+ unfloat();
46
+ unattach();
47
+ };
48
+ });
49
+ </script>
50
+
51
+ <div bind:this={panel} popover="manual" aria-hidden="true" data-face={face} class="glim-popover glim-time-dial">
52
+ <svg bind:this={plate} viewBox="0 0 {DIAL.size} {DIAL.size}">
53
+ <circle class="glim-time-dial-plate" cx={middle} cy={middle} r={middle} />
54
+ {#if value !== null}
55
+ <g class="glim-time-dial-hand" data-value={value} style:transform="rotate({turned}deg)">
56
+ <line x1={middle} y1={middle} x2={middle} y2={middle - reach} />
57
+ <circle cx={middle} cy={middle - reach} r={reach === DIAL.inner ? 14 : 16} />
58
+ {#if !marks.some((m) => m.value === value)}
59
+ <circle class="glim-time-dial-dot" cx={middle} cy={middle - reach} r={2} />
60
+ {/if}
61
+ </g>
62
+ {/if}
63
+ <circle class="glim-time-dial-hub" cx={middle} cy={middle} r={3} />
64
+ {#key face}
65
+ <g class="glim-time-dial-marks">
66
+ {#each marks as m (m.value)}
67
+ <g class="glim-time-dial-mark" data-value={m.value} data-inner={m.inner ? "" : undefined} data-chosen={m.value === value ? "" : undefined}>
68
+ <text x={m.x} y={m.y}>{m.text}</text>
69
+ </g>
70
+ {/each}
71
+ </g>
72
+ {/key}
73
+ </svg>
74
+ </div>
@@ -0,0 +1,13 @@
1
+ import type { ClockFace } from "@glimstone/core";
2
+ export interface TimeDialProps {
3
+ anchor: HTMLElement;
4
+ face: ClockFace;
5
+ value: number | null;
6
+ minuteStep: number;
7
+ onPoint: (value: number, done: boolean) => void;
8
+ onTurn: (delta: 1 | -1) => void;
9
+ onClose: () => void;
10
+ }
11
+ declare const TimeDial: import("svelte").Component<TimeDialProps, {}, "">;
12
+ type TimeDial = ReturnType<typeof TimeDial>;
13
+ export default TimeDial;
@@ -0,0 +1,57 @@
1
+ <script lang="ts" module>
2
+ import type { TimePickerText } from "@glimstone/core";
3
+
4
+ export type { TimePickerText } from "@glimstone/core";
5
+
6
+ export interface TimePickerProps {
7
+ label?: string;
8
+ /** The time as "08:30", or null while a segment is empty, bound with `bind:value`. */
9
+ value: string | null;
10
+ onChange?: (value: string | null) => void;
11
+ /** How far an arrow moves the minutes. */
12
+ minuteStep?: number;
13
+ /** The name the time is sent under in a form. */
14
+ name?: string;
15
+ disabled?: boolean;
16
+ /** The segments' names. English where left out. */
17
+ text?: Partial<TimePickerText>;
18
+ class?: string;
19
+ }
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import { untrack } from "svelte";
24
+ import { formatTime, parseTime, type TimeSegmentValue } from "@glimstone/core";
25
+ import TimeShell from "./TimeShell.svelte";
26
+
27
+ // A time of day in one field of two segments, hours and minutes. Each
28
+ // segment is a spin button: the arrows count it round the clock, digits type
29
+ // it and move on once it is full, Backspace empties it. A time is data, so
30
+ // the segments run left to right in every language. Inside a FieldRow the
31
+ // row names it.
32
+ let { label, value = $bindable(), onChange, minuteStep, name, disabled, text, class: className }: TimePickerProps = $props();
33
+
34
+ let values = $state<TimeSegmentValue[]>(untrack(() => parseTime(value)));
35
+
36
+ // A time from the app replaces the segments, and so does a null that clears
37
+ // a whole time, but a half-typed time the app only knows as null stays.
38
+ $effect.pre(() => {
39
+ const time = value;
40
+ untrack(() => {
41
+ if (time !== null || formatTime(values) !== null) values = parseTime(time);
42
+ });
43
+ });
44
+
45
+ function onValues(next: TimeSegmentValue[]) {
46
+ values = next;
47
+ const time = formatTime(next);
48
+ if (time !== value) {
49
+ value = time;
50
+ onChange?.(time);
51
+ }
52
+ }
53
+ </script>
54
+
55
+ <TimeShell data-glim="TimePicker" {label} {values} {onValues} {minuteStep} {disabled} {text} class={className}>
56
+ {#if name}<input type="hidden" {name} value={formatTime(values) ?? ""} />{/if}
57
+ </TimeShell>
@@ -0,0 +1,19 @@
1
+ import type { TimePickerText } from "@glimstone/core";
2
+ export type { TimePickerText } from "@glimstone/core";
3
+ export interface TimePickerProps {
4
+ label?: string;
5
+ /** The time as "08:30", or null while a segment is empty, bound with `bind:value`. */
6
+ value: string | null;
7
+ onChange?: (value: string | null) => void;
8
+ /** How far an arrow moves the minutes. */
9
+ minuteStep?: number;
10
+ /** The name the time is sent under in a form. */
11
+ name?: string;
12
+ disabled?: boolean;
13
+ /** The segments' names. English where left out. */
14
+ text?: Partial<TimePickerText>;
15
+ class?: string;
16
+ }
17
+ declare const TimePicker: import("svelte").Component<TimePickerProps, {}, "value">;
18
+ type TimePicker = ReturnType<typeof TimePicker>;
19
+ export default TimePicker;
@@ -0,0 +1,52 @@
1
+ <script lang="ts" module>
2
+ import type { TimePickerText } from "@glimstone/core";
3
+
4
+ export interface TimeRangePickerProps {
5
+ label?: string;
6
+ /** The start and the end as "08:00", each null while one of its segments is empty, bound with `bind:value`. */
7
+ value: [string | null, string | null];
8
+ onChange?: (value: [string | null, string | null]) => void;
9
+ /** How far an arrow moves the minutes. */
10
+ minuteStep?: number;
11
+ disabled?: boolean;
12
+ /** The segments' names, the halves' and the word between them. English where left out. */
13
+ text?: Partial<TimePickerText>;
14
+ class?: string;
15
+ }
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { untrack } from "svelte";
20
+ import { formatTime, parseTime, timeRangeValue, type TimeSegmentValue } from "@glimstone/core";
21
+ import TimeShell from "./TimeShell.svelte";
22
+
23
+ // A span of two times in one field, such as the quiet hours. The segments
24
+ // work as in a TimePicker, and the arrows walk on from the start into the
25
+ // end. Inside a FieldRow the row names it.
26
+ let { label, value = $bindable(), onChange, minuteStep, disabled, text, class: className }: TimeRangePickerProps = $props();
27
+
28
+ let values = $state<TimeSegmentValue[]>(untrack(() => value.flatMap(parseTime)));
29
+
30
+ // A time from the app replaces its half, and so does a null that clears a
31
+ // whole time, but a half-typed time the app only knows as null stays.
32
+ $effect.pre(() => {
33
+ const times = [...value];
34
+ untrack(() => {
35
+ values = times.flatMap((time, i) => {
36
+ const half = values.slice(i * 2, i * 2 + 2);
37
+ return time === null && formatTime(half) === null ? half : parseTime(time);
38
+ });
39
+ });
40
+ });
41
+
42
+ function onValues(next: TimeSegmentValue[]) {
43
+ values = next;
44
+ const span = timeRangeValue(next);
45
+ if (span[0] !== value[0] || span[1] !== value[1]) {
46
+ value = span;
47
+ onChange?.(span);
48
+ }
49
+ }
50
+ </script>
51
+
52
+ <TimeShell data-glim="TimeRangePicker" {label} {values} {onValues} {minuteStep} {disabled} {text} class={className} />