@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.
- package/dist/AngleSlider.svelte +33 -9
- package/dist/AngleSlider.svelte.d.ts +1 -1
- package/dist/Avatar.svelte +1 -1
- package/dist/Badge.svelte +3 -7
- package/dist/Badge.svelte.d.ts +2 -5
- package/dist/Card.svelte +5 -1
- package/dist/Card.svelte.d.ts +3 -0
- package/dist/Chart.svelte +84 -0
- package/dist/Chart.svelte.d.ts +19 -0
- package/dist/ChartLegend.svelte +19 -0
- package/dist/ChartLegend.svelte.d.ts +7 -0
- package/dist/Checkbox.svelte +16 -3
- package/dist/ColorPicker.svelte +49 -4
- package/dist/ColorPicker.svelte.d.ts +2 -0
- package/dist/Combobox.svelte +12 -4
- package/dist/ConfirmDialog.svelte +8 -2
- package/dist/ConnectionRow.svelte +4 -1
- package/dist/ConnectionRow.svelte.d.ts +2 -0
- package/dist/ContextMenu.svelte +4 -2
- package/dist/ContextMenu.svelte.d.ts +2 -0
- package/dist/DatePicker.svelte +21 -11
- package/dist/FieldErrorLine.svelte +24 -0
- package/dist/FieldErrorLine.svelte.d.ts +7 -0
- package/dist/FieldRow.svelte +16 -4
- package/dist/FileUpload.svelte +14 -4
- package/dist/FileUpload.svelte.d.ts +2 -0
- package/dist/FortressPermissions.svelte +3 -1
- package/dist/HoverCard.svelte +34 -5
- package/dist/HoverCard.svelte.d.ts +12 -2
- package/dist/IconTipButton.svelte +6 -2
- package/dist/IconTipButton.svelte.d.ts +3 -0
- package/dist/InfoBubble.svelte +1 -1
- package/dist/ListRow.svelte +71 -6
- package/dist/ListRow.svelte.d.ts +17 -2
- package/dist/ListSelect.svelte +7 -2
- package/dist/ListTable.svelte +36 -16
- package/dist/ListTable.svelte.d.ts +5 -0
- package/dist/MenuSelect.svelte +11 -3
- package/dist/Meter.svelte +21 -3
- package/dist/Meter.svelte.d.ts +4 -0
- package/dist/MultiSelect.svelte +156 -0
- package/dist/MultiSelect.svelte.d.ts +20 -0
- package/dist/NotifyCard.svelte +1 -1
- package/dist/NumberField.svelte +2 -2
- package/dist/Pagination.svelte +15 -5
- package/dist/PasswordField.svelte +7 -6
- package/dist/PinInput.svelte +4 -2
- package/dist/Rating.svelte +10 -1
- package/dist/RevealEye.svelte +17 -0
- package/dist/RevealEye.svelte.d.ts +6 -0
- package/dist/SearchHit.svelte +10 -0
- package/dist/SearchHit.svelte.d.ts +7 -0
- package/dist/Selector.svelte +28 -4
- package/dist/Selector.svelte.d.ts +4 -3
- package/dist/SettingsNav.svelte +152 -0
- package/dist/SettingsNav.svelte.d.ts +46 -0
- package/dist/SignInTile.svelte +124 -114
- package/dist/SkeletonRow.svelte +8 -2
- package/dist/SkeletonRow.svelte.d.ts +4 -0
- package/dist/Slider.svelte +1 -0
- package/dist/Sparkline.svelte +24 -0
- package/dist/Sparkline.svelte.d.ts +11 -0
- package/dist/StatusSummary.svelte +55 -0
- package/dist/StatusSummary.svelte.d.ts +18 -0
- package/dist/SubCard.svelte +16 -16
- package/dist/SubCard.svelte.d.ts +3 -3
- package/dist/TextArea.svelte +13 -3
- package/dist/TextField.svelte +2 -2
- package/dist/TimeDial.svelte +74 -0
- package/dist/TimeDial.svelte.d.ts +13 -0
- package/dist/TimePicker.svelte +57 -0
- package/dist/TimePicker.svelte.d.ts +19 -0
- package/dist/TimeRangePicker.svelte +52 -0
- package/dist/TimeRangePicker.svelte.d.ts +16 -0
- package/dist/TimeShell.svelte +145 -0
- package/dist/TimeShell.svelte.d.ts +16 -0
- package/dist/Timer.svelte +6 -1
- package/dist/TipBubble.svelte +1 -1
- package/dist/ToastCard.svelte +7 -3
- package/dist/ToastCard.svelte.d.ts +2 -0
- package/dist/ToastViewport.svelte +6 -3
- package/dist/Toggle.svelte +3 -1
- package/dist/Tour.svelte +8 -2
- package/dist/Window.svelte +5 -3
- package/dist/Window.svelte.d.ts +3 -1
- package/dist/bubble.svelte.d.ts +12 -1
- package/dist/bubble.svelte.js +13 -5
- package/dist/engines.svelte.d.ts +7 -1
- package/dist/engines.svelte.js +13 -1
- package/dist/entries/multiselect.d.ts +1 -0
- package/dist/entries/multiselect.js +2 -0
- package/dist/glyphs.d.ts +3 -0
- package/dist/glyphs.js +3 -0
- package/dist/index.d.ts +13 -7
- package/dist/index.js +9 -4
- package/package.json +7 -2
- package/dist/AboutCard.svelte +0 -116
- package/dist/AboutCard.svelte.d.ts +0 -40
- package/dist/DropdownListbox.svelte +0 -178
- package/dist/DropdownListbox.svelte.d.ts +0 -23
|
@@ -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;
|
package/dist/SubCard.svelte
CHANGED
|
@@ -2,25 +2,23 @@
|
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
|
|
4
4
|
export interface SubCardProps {
|
|
5
|
-
/** The group's name,
|
|
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)"
|
|
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
|
-
*
|
|
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
|
|
21
|
-
//
|
|
22
|
-
// click.
|
|
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
|
-
<
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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>
|
package/dist/SubCard.svelte.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
2
|
export interface SubCardProps {
|
|
3
|
-
/** The group's name,
|
|
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)"
|
|
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
|
-
*
|
|
8
|
+
* title's line. */
|
|
9
9
|
end?: Snippet;
|
|
10
10
|
children: Snippet;
|
|
11
11
|
}
|
package/dist/TextArea.svelte
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
<script lang="ts">
|
|
20
|
-
import { fieldErrorView, textFieldClass } from "@glimstone/core";
|
|
21
|
-
import
|
|
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
|
-
|
|
65
|
+
<FieldErrorLine id={err.errorId} {error} />
|
package/dist/TextField.svelte
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<script lang="ts">
|
|
22
22
|
import { fieldErrorView, textFieldClass } from "@glimstone/core";
|
|
23
|
-
import
|
|
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
|
-
|
|
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} />
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TimePickerText } from "@glimstone/core";
|
|
2
|
+
export interface TimeRangePickerProps {
|
|
3
|
+
label?: string;
|
|
4
|
+
/** The start and the end as "08:00", each null while one of its segments is empty, bound with `bind:value`. */
|
|
5
|
+
value: [string | null, string | null];
|
|
6
|
+
onChange?: (value: [string | null, string | null]) => void;
|
|
7
|
+
/** How far an arrow moves the minutes. */
|
|
8
|
+
minuteStep?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** The segments' names, the halves' and the word between them. English where left out. */
|
|
11
|
+
text?: Partial<TimePickerText>;
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const TimeRangePicker: import("svelte").Component<TimeRangePickerProps, {}, "value">;
|
|
15
|
+
type TimeRangePicker = ReturnType<typeof TimeRangePicker>;
|
|
16
|
+
export default TimeRangePicker;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { TimePickerText, TimeSegmentValue } from "@glimstone/core";
|
|
4
|
+
|
|
5
|
+
export interface TimeShellProps {
|
|
6
|
+
"data-glim": string;
|
|
7
|
+
label?: string;
|
|
8
|
+
values: TimeSegmentValue[];
|
|
9
|
+
onValues: (values: TimeSegmentValue[]) => void;
|
|
10
|
+
minuteStep?: number;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
text?: Partial<TimePickerText>;
|
|
13
|
+
class?: string;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { TIME_PICKER_TEXT, dialSegment, faceOf, segmentText, stepSegment, timeKey, timeWheel, wheelSegments } from "@glimstone/core";
|
|
20
|
+
import { useFieldName } from "./fieldName.js";
|
|
21
|
+
import TimeDial from "./TimeDial.svelte";
|
|
22
|
+
|
|
23
|
+
// The field TimePicker and TimeRangePicker share: one or two times, each two
|
|
24
|
+
// segments, whose keys, wheel and clock face come from timePicker.ts in the
|
|
25
|
+
// core.
|
|
26
|
+
let { "data-glim": glim, label, values, onValues, minuteStep = 1, disabled = false, text, class: className, children }: TimeShellProps = $props();
|
|
27
|
+
|
|
28
|
+
const fieldName = useFieldName(() => label);
|
|
29
|
+
const words = $derived({ ...TIME_PICKER_TEXT, ...text });
|
|
30
|
+
const range = $derived(values.length > 2);
|
|
31
|
+
const segments: HTMLSpanElement[] = [];
|
|
32
|
+
// The segment the clock face edits while it is open.
|
|
33
|
+
let dial = $state<number | null>(null);
|
|
34
|
+
let typed = "";
|
|
35
|
+
let root = $state<HTMLDivElement | null>(null);
|
|
36
|
+
|
|
37
|
+
$effect(() =>
|
|
38
|
+
wheelSegments(root!, (at, deltaY) => {
|
|
39
|
+
const next = disabled ? null : timeWheel(values, at, deltaY, minuteStep);
|
|
40
|
+
if (next) onValues(next);
|
|
41
|
+
return next !== null;
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
function focus(at: number) {
|
|
46
|
+
typed = "";
|
|
47
|
+
segments[at]?.focus();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function onKeyDown(at: number, e: KeyboardEvent) {
|
|
51
|
+
if (disabled) return;
|
|
52
|
+
const result = timeKey(values, at, e.key, typed, minuteStep);
|
|
53
|
+
if (!result) return;
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
if (result.values.some((v, i) => v !== values[i])) onValues(result.values);
|
|
56
|
+
if (result.focus !== at) focus(result.focus);
|
|
57
|
+
else typed = result.buffer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// A press into the field opens the face for the segment it hit, and a press
|
|
61
|
+
// beside the segments lands on the hours, as on a text field's padding.
|
|
62
|
+
function onMouseDown(e: MouseEvent) {
|
|
63
|
+
if (disabled) return;
|
|
64
|
+
const target = e.target as HTMLElement;
|
|
65
|
+
const pressed = target.closest<HTMLSpanElement>(".glim-time-seg");
|
|
66
|
+
const half = target.closest(".glim-time-half");
|
|
67
|
+
const at = dialSegment(pressed ? segments.indexOf(pressed) : null, half ? [...root!.querySelectorAll(".glim-time-half")].indexOf(half) : null);
|
|
68
|
+
if (!pressed) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
focus(at);
|
|
71
|
+
}
|
|
72
|
+
dial = at;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function setSegment(at: number, value: number) {
|
|
76
|
+
if (values[at] !== value) onValues(values.map((v, i) => (i === at ? value : v)));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function onPoint(value: number, done: boolean) {
|
|
80
|
+
const at = dial!;
|
|
81
|
+
setSegment(at, value);
|
|
82
|
+
if (!done) return;
|
|
83
|
+
if (at % 2 === 0) focus(at + 1);
|
|
84
|
+
else dial = null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onTurn(delta: 1 | -1) {
|
|
88
|
+
const at = dial!;
|
|
89
|
+
setSegment(at, stepSegment(values[at] ?? null, at, delta, at % 2 === 1 ? minuteStep : 1));
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#snippet segment(at: number)}
|
|
94
|
+
<span
|
|
95
|
+
bind:this={segments[at]}
|
|
96
|
+
role="spinbutton"
|
|
97
|
+
tabindex={disabled ? -1 : 0}
|
|
98
|
+
aria-label={at % 2 === 0 ? words.hour : words.minute}
|
|
99
|
+
aria-valuemin={0}
|
|
100
|
+
aria-valuemax={at % 2 === 0 ? 23 : 59}
|
|
101
|
+
aria-valuenow={values[at] ?? undefined}
|
|
102
|
+
aria-valuetext={values[at] === null ? undefined : segmentText(values[at]!)}
|
|
103
|
+
aria-disabled={disabled || undefined}
|
|
104
|
+
data-empty={values[at] === null ? "" : undefined}
|
|
105
|
+
data-editing={dial === at ? "" : undefined}
|
|
106
|
+
class="glim-time-seg"
|
|
107
|
+
onkeydown={(e) => onKeyDown(at, e)}
|
|
108
|
+
onfocus={() => {
|
|
109
|
+
typed = "";
|
|
110
|
+
if (dial !== null) dial = at;
|
|
111
|
+
}}>{segmentText(values[at]!)}</span
|
|
112
|
+
>
|
|
113
|
+
{/snippet}
|
|
114
|
+
|
|
115
|
+
{#snippet time(first: number)}
|
|
116
|
+
{@render segment(first)}<span class="glim-time-colon" aria-hidden="true">:</span>{@render segment(first + 1)}
|
|
117
|
+
{/snippet}
|
|
118
|
+
|
|
119
|
+
<!-- The press on the group opens the clock face and hands the focus to a segment, which takes the keys. -->
|
|
120
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
121
|
+
<div
|
|
122
|
+
bind:this={root}
|
|
123
|
+
data-glim={glim}
|
|
124
|
+
role="group"
|
|
125
|
+
aria-label={fieldName()}
|
|
126
|
+
data-disabled={disabled ? "" : undefined}
|
|
127
|
+
class={["glim-time", className].filter(Boolean).join(" ")}
|
|
128
|
+
onmousedown={onMouseDown}
|
|
129
|
+
onfocusout={(e) => {
|
|
130
|
+
if (!root!.contains(e.relatedTarget as Node | null)) dial = null;
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
{#if range}
|
|
134
|
+
{#each [0, 2] as first (first)}
|
|
135
|
+
{#if first > 0}<span class="glim-time-to" aria-hidden="true">{words.to}</span>{/if}
|
|
136
|
+
<span role="group" aria-label={first === 0 ? words.start : words.end} class="glim-time-half">{@render time(first)}</span>
|
|
137
|
+
{/each}
|
|
138
|
+
{:else}
|
|
139
|
+
{@render time(0)}
|
|
140
|
+
{/if}
|
|
141
|
+
{#if dial !== null}
|
|
142
|
+
<TimeDial anchor={root!} face={faceOf(dial)} value={values[dial] ?? null} {minuteStep} {onPoint} {onTurn} onClose={() => (dial = null)} />
|
|
143
|
+
{/if}
|
|
144
|
+
{@render children?.()}
|
|
145
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { TimePickerText, TimeSegmentValue } from "@glimstone/core";
|
|
3
|
+
export interface TimeShellProps {
|
|
4
|
+
"data-glim": string;
|
|
5
|
+
label?: string;
|
|
6
|
+
values: TimeSegmentValue[];
|
|
7
|
+
onValues: (values: TimeSegmentValue[]) => void;
|
|
8
|
+
minuteStep?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
text?: Partial<TimePickerText>;
|
|
11
|
+
class?: string;
|
|
12
|
+
children?: Snippet;
|
|
13
|
+
}
|
|
14
|
+
declare const TimeShell: import("svelte").Component<TimeShellProps, {}, "">;
|
|
15
|
+
type TimeShell = ReturnType<typeof TimeShell>;
|
|
16
|
+
export default TimeShell;
|
package/dist/Timer.svelte
CHANGED
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
onComplete: () => onComplete?.(),
|
|
42
42
|
}));
|
|
43
43
|
const api = $derived(timer.connect(service, normalizeProps));
|
|
44
|
+
// Zag's reset keeps a running timer going, and Reset waits for Start, so a running timer pauses first.
|
|
45
|
+
function reset() {
|
|
46
|
+
api.pause();
|
|
47
|
+
api.reset();
|
|
48
|
+
}
|
|
44
49
|
const spoken = $derived(words.spoken(api.time.hours, api.time.minutes, api.time.seconds));
|
|
45
50
|
</script>
|
|
46
51
|
|
|
@@ -57,6 +62,6 @@
|
|
|
57
62
|
{:else}
|
|
58
63
|
<Button label={words.start} labelKey={null} glyph={IconPlay} onClick={() => api.start()} />
|
|
59
64
|
{/if}
|
|
60
|
-
<Button label={words.reset} labelKey={null} glyph={IconResetArrow} onClick={
|
|
65
|
+
<Button label={words.reset} labelKey={null} glyph={IconResetArrow} onClick={reset} />
|
|
61
66
|
</div>
|
|
62
67
|
</div>
|