@glimstone/svelte 4.9.0 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,147 @@
1
+ <script lang="ts" module>
2
+ import type { Catalog, NotifyApi, NotifyCardLabelKeys, NotifyCardText, NotifyChoice, NotifyKind, ToastSeverity } from "@glimstone/core";
3
+
4
+ export type { NotifyCardLabelKeys, NotifyCardText } from "@glimstone/core";
5
+
6
+ export interface NotifyCardProps {
7
+ /** Loads, saves and tests the channels in the kit's notify format. */
8
+ api: NotifyApi;
9
+ /** The card's words, `notifyCardText(lang)` or the app's own. */
10
+ text: NotifyCardText;
11
+ /** The app's name, for the sentences that say it. */
12
+ app: string;
13
+ /** The interface language, which sorts the picker. */
14
+ lang: string;
15
+ /** The notification catalog, `NOTIFY_PROVIDERS`. */
16
+ providers: Catalog;
17
+ /** The kinds the app sends to, every kind of the kit by default. */
18
+ kinds?: readonly NotifyKind[];
19
+ /** The event kinds the app sends, which each channel can choose among. */
20
+ events?: readonly NotifyChoice[];
21
+ /** The keys a Healthchecks channel can give a check of their own, such as a job. */
22
+ checks?: readonly NotifyChoice[];
23
+ /** Kinds that send nothing where the app runs, with the sentence that says why. */
24
+ unavailable?: Partial<Record<NotifyKind, string>>;
25
+ /** Puts what a change did, or why it failed, into the app's toasts. */
26
+ notify?: (message: string, severity: ToastSeverity) => void;
27
+ /** The card's rainbow position. */
28
+ hueIndex?: number;
29
+ labelKeys?: Partial<NotifyCardLabelKeys>;
30
+ }
31
+ </script>
32
+
33
+ <script lang="ts">
34
+ import { onDestroy, onMount, untrack, type Snippet } from "svelte";
35
+ import { connectionTestFace, createNotifyCardFlow, fill, notifyGlyphKey, notifyRemoval, notifyRows, showNotifyRefusal, NOTIFY_CARD_KEYS, NOTIFY_KINDS } from "@glimstone/core";
36
+ import Badge from "./Badge.svelte";
37
+ import BrandMark from "./BrandMark.svelte";
38
+ import Button from "./Button.svelte";
39
+ import Card from "./Card.svelte";
40
+ import EmptyState from "./EmptyState.svelte";
41
+ import GlyphTile from "./GlyphTile.svelte";
42
+ import ListRow from "./ListRow.svelte";
43
+ import NotifyCardWindow from "./NotifyCardWindow.svelte";
44
+ import Toggle from "./Toggle.svelte";
45
+ import { useConfirm } from "./confirm.svelte.js";
46
+ import { glyphFor, IconCheck, IconClose, IconPencil, IconTrash } from "./glyphs.js";
47
+
48
+ // The settings card "Notifications" ("The notification card" in the design
49
+ // language): the app's channels as rows, each with its switch, its test, Edit
50
+ // and Remove, and the catalog's picker to add one. The flow lives in the core
51
+ // and talks to the app through three calls, so the card names no app or route.
52
+ let { api, text, app, lang, providers, kinds = NOTIFY_KINDS, events = [], checks = [], unavailable = {}, notify, hueIndex, labelKeys }: NotifyCardProps = $props();
53
+
54
+ const flow = createNotifyCardFlow(() => ({ api, text, app, lang, providers, kinds, events, checks, unavailable, notify }));
55
+ let s = $state.raw(flow.state());
56
+ onDestroy(flow.subscribe(() => (s = flow.state())));
57
+ onMount(() => flow.start());
58
+ const refusals = $derived(s.refusal?.count);
59
+ $effect(() => {
60
+ void refusals;
61
+ return untrack(() => showNotifyRefusal(s.refusal));
62
+ });
63
+ const ask = useConfirm({
64
+ get title() {
65
+ return text.remove;
66
+ },
67
+ get cancel() {
68
+ return text.cancel;
69
+ },
70
+ get confirm() {
71
+ return text.remove;
72
+ },
73
+ });
74
+
75
+ const keys = $derived<NotifyCardLabelKeys>({ ...NOTIFY_CARD_KEYS, ...labelKeys });
76
+ const rows = $derived(notifyRows(s, { text, providers, unavailable }));
77
+ const glyph = (kind: NotifyKind): Snippet => glyphFor(notifyGlyphKey(kind, keys))!;
78
+ const markOf = (kind: NotifyKind) => providers.entries.find((e) => e.id === kind)?.mark;
79
+
80
+ function remove(id: string) {
81
+ const c = s.channels.find((x) => x.id === id);
82
+ if (!c) return;
83
+ const q = notifyRemoval(text, c);
84
+ void ask.confirm(q.message, { confirmLabel: q.confirm, confirmLabelKey: keys.remove }).then((yes) => {
85
+ if (yes) void flow.remove(id);
86
+ });
87
+ }
88
+ </script>
89
+
90
+ <div data-glim="NotifyCard">
91
+ <Card title={text.title} hint={text.hint} {hueIndex}>
92
+ <div class="glim-notify-body">
93
+ {#if s.loadFailed}
94
+ <p class="glim-notify-said glim-notify-said--fail" role="alert">{text.notLoaded}</p>
95
+ {/if}
96
+ {#if rows.length > 0}
97
+ <div class="glim-list glim-notify-rows">
98
+ {#each rows as row (row.id)}
99
+ {@const test = s.rowTests[row.id]}
100
+ {@const face = connectionTestFace(test)}
101
+ {@const m = markOf(row.kind)}
102
+ {#snippet brand()}<BrandMark svg={m?.svg ?? ""} />{/snippet}
103
+ {#snippet idle()}<Badge size="small" tone="warn">{text.idle}</Badge>{/snippet}
104
+ <ListRow steady name={row.name} meta={row.meta} badges={row.idle ? idle : undefined} data-notify-channel={row.id}>
105
+ {#snippet tile()}<GlyphTile glyph={m ? brand : glyph(row.kind)} />{/snippet}
106
+ {#snippet actions()}
107
+ <Toggle bind:checked={() => row.enabled, (on) => void flow.setEnabled(row.id, on)} label={row.name} hideLabel data-notify={`switch-${row.id}`} />
108
+ <Button
109
+ compact
110
+ tone={face.tone === "neutral" ? "subtle" : face.tone}
111
+ label={text.test}
112
+ labelKey={keys.test}
113
+ glyph={face.outcome === "cross" ? IconClose : IconCheck}
114
+ busy={test?.busy}
115
+ title={test?.title}
116
+ class={face.shake ? "glim-shake" : undefined}
117
+ data-notify={`test-${row.id}`}
118
+ onClick={() => void flow.testRow(row.id)}
119
+ />
120
+ <Button compact tone="subtle" label={text.edit} labelKey={keys.edit} glyph={IconPencil} data-notify={`edit-${row.id}`} onClick={() => flow.edit(row.id)} />
121
+ <Button
122
+ compact
123
+ tone="subtle"
124
+ label={text.remove}
125
+ labelKey={keys.remove}
126
+ glyph={IconTrash}
127
+ busy={s.busy === `remove-${row.id}`}
128
+ data-notify={`remove-${row.id}`}
129
+ onClick={() => remove(row.id)}
130
+ />
131
+ {/snippet}
132
+ </ListRow>
133
+ {/each}
134
+ </div>
135
+ {:else if s.loaded}
136
+ <EmptyState nested title={fill(text.empty, { app })} />
137
+ {/if}
138
+ <div class="glim-notify-foot">
139
+ <Button label={text.add} labelKey={keys.add} disabled={!s.loaded} data-notify="add" onClick={flow.pick} />
140
+ </div>
141
+ </div>
142
+ </Card>
143
+ {#if s.window}
144
+ <NotifyCardWindow {flow} flowState={s} {text} {app} {lang} {providers} {kinds} {events} {checks} {unavailable} {keys} {glyph} />
145
+ {/if}
146
+ <ask.confirmDialog />
147
+ </div>
@@ -0,0 +1,30 @@
1
+ import type { Catalog, NotifyApi, NotifyCardLabelKeys, NotifyCardText, NotifyChoice, NotifyKind, ToastSeverity } from "@glimstone/core";
2
+ export type { NotifyCardLabelKeys, NotifyCardText } from "@glimstone/core";
3
+ export interface NotifyCardProps {
4
+ /** Loads, saves and tests the channels in the kit's notify format. */
5
+ api: NotifyApi;
6
+ /** The card's words, `notifyCardText(lang)` or the app's own. */
7
+ text: NotifyCardText;
8
+ /** The app's name, for the sentences that say it. */
9
+ app: string;
10
+ /** The interface language, which sorts the picker. */
11
+ lang: string;
12
+ /** The notification catalog, `NOTIFY_PROVIDERS`. */
13
+ providers: Catalog;
14
+ /** The kinds the app sends to, every kind of the kit by default. */
15
+ kinds?: readonly NotifyKind[];
16
+ /** The event kinds the app sends, which each channel can choose among. */
17
+ events?: readonly NotifyChoice[];
18
+ /** The keys a Healthchecks channel can give a check of their own, such as a job. */
19
+ checks?: readonly NotifyChoice[];
20
+ /** Kinds that send nothing where the app runs, with the sentence that says why. */
21
+ unavailable?: Partial<Record<NotifyKind, string>>;
22
+ /** Puts what a change did, or why it failed, into the app's toasts. */
23
+ notify?: (message: string, severity: ToastSeverity) => void;
24
+ /** The card's rainbow position. */
25
+ hueIndex?: number;
26
+ labelKeys?: Partial<NotifyCardLabelKeys>;
27
+ }
28
+ declare const NotifyCard: import("svelte").Component<NotifyCardProps, {}, "">;
29
+ type NotifyCard = ReturnType<typeof NotifyCard>;
30
+ export default NotifyCard;
@@ -0,0 +1,206 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import {
4
+ connectionTestFace,
5
+ fill,
6
+ notifyChannelName,
7
+ notifyForm,
8
+ notifyPicker,
9
+ NOTIFY_REDACTED,
10
+ type Catalog,
11
+ type NotifyCardFlow,
12
+ type NotifyCardLabelKeys,
13
+ type NotifyCardState,
14
+ type NotifyCardText,
15
+ type NotifyChoice,
16
+ type NotifyField,
17
+ type NotifyKind,
18
+ } from "@glimstone/core";
19
+ import Button from "./Button.svelte";
20
+ import Checkbox from "./Checkbox.svelte";
21
+ import FieldRow from "./FieldRow.svelte";
22
+ import FieldRowGroup from "./FieldRowGroup.svelte";
23
+ import NumberField from "./NumberField.svelte";
24
+ import PasswordField from "./PasswordField.svelte";
25
+ import PickerWindow from "./PickerWindow.svelte";
26
+ import Select from "./Select.svelte";
27
+ import Selector from "./Selector.svelte";
28
+ import TextArea from "./TextArea.svelte";
29
+ import TextField from "./TextField.svelte";
30
+ import UnavailableNotice from "./UnavailableNotice.svelte";
31
+ import Window, { type WindowAction } from "./Window.svelte";
32
+ import { IconCheck, IconClose, IconTrash } from "./glyphs.js";
33
+
34
+ // The notification card's window: the picker, and the form of the channel
35
+ // being added or edited.
36
+ let {
37
+ flow,
38
+ flowState: s,
39
+ text,
40
+ app,
41
+ lang,
42
+ providers,
43
+ kinds,
44
+ events,
45
+ checks,
46
+ unavailable,
47
+ keys,
48
+ glyph,
49
+ }: {
50
+ flow: NotifyCardFlow;
51
+ flowState: NotifyCardState;
52
+ text: NotifyCardText;
53
+ app: string;
54
+ lang: string;
55
+ providers: Catalog;
56
+ kinds: readonly NotifyKind[];
57
+ events: readonly NotifyChoice[];
58
+ checks: readonly NotifyChoice[];
59
+ unavailable: Partial<Record<NotifyKind, string>>;
60
+ keys: NotifyCardLabelKeys;
61
+ glyph: (kind: NotifyKind) => Snippet;
62
+ } = $props();
63
+
64
+ const w = $derived(s.window!);
65
+ const picker = $derived(notifyPicker(providers, text, lang, kinds, glyph));
66
+ const pickerText = $derived({ search: text.search, none: text.noMatch, clear: text.clear, close: text.close, cancel: text.cancel, back: text.back });
67
+ const form = $derived(w.kind === "form" ? notifyForm(s, { text, app, events, checks, unavailable }) : null);
68
+ const eye = $derived({ show: text.show, hide: text.hide });
69
+ const title = $derived(s.draft ? fill(text.editTitle, { name: notifyChannelName(text, s.draft) }) : "");
70
+ const actions = $derived.by<WindowAction[]>(() => {
71
+ const test = s.formTest;
72
+ const face = connectionTestFace(test);
73
+ return [
74
+ {
75
+ label: text.test,
76
+ labelKey: keys.test,
77
+ glyph: face.outcome === "cross" ? IconClose : face.outcome === "check" ? IconCheck : undefined,
78
+ tone: test?.busy ? undefined : test?.tone,
79
+ busy: !!test?.busy,
80
+ title: test?.title,
81
+ attrs: { "data-notify": "form-test" },
82
+ onClick: () => {
83
+ void flow.test();
84
+ return false;
85
+ },
86
+ },
87
+ {
88
+ label: text.save,
89
+ labelKey: keys.save,
90
+ primary: true,
91
+ busy: s.busy === "save",
92
+ attrs: { "data-notify": "save" },
93
+ onClick: () => {
94
+ void flow.save();
95
+ return false;
96
+ },
97
+ },
98
+ ];
99
+ });
100
+ const items = (options: NotifyField["options"]) => (options ?? []).map((o) => ({ id: o.value, label: o.label }));
101
+ const port = (v: string) => (v === "" ? null : Number(v));
102
+ </script>
103
+
104
+ {#snippet problem(f: NotifyField)}
105
+ {#if f.error}
106
+ <p class="glim-notify-problem" role="alert">{f.error}</p>
107
+ {/if}
108
+ {/snippet}
109
+
110
+ {#snippet body()}
111
+ {#if form}
112
+ <div class="glim-notify-form" data-notify-form={form.kind}>
113
+ {#if form.hint}
114
+ <p class="glim-notify-text">{form.hint}</p>
115
+ {/if}
116
+ {#if form.unavailable}
117
+ <UnavailableNotice title={text.idle} reason={form.unavailable} />
118
+ {/if}
119
+ {#each form.loose as line, i (i)}
120
+ <p class="glim-notify-problem" role="alert">{line}</p>
121
+ {/each}
122
+ <FieldRowGroup>
123
+ {#each form.fields as f (f.path)}
124
+ <FieldRow label={f.label} hint={f.hint}>
125
+ {#if f.control === "secret"}
126
+ <PasswordField autocomplete="new-password" value={f.value} text={eye} note={f.note} error={f.error} oninput={(e) => flow.set(f.path, e.currentTarget.value)} />
127
+ {:else if f.control === "number"}
128
+ <NumberField
129
+ min={1}
130
+ max={65535}
131
+ value={port(f.value)}
132
+ placeholder={f.placeholder}
133
+ error={f.error}
134
+ onChange={(e) => flow.set(f.path, e.currentTarget.value)}
135
+ />
136
+ {:else if f.control === "area"}
137
+ <TextArea mono={f.mono} value={f.value} placeholder={f.placeholder} error={f.error} oninput={(e) => flow.set(f.path, e.currentTarget.value)} />
138
+ {:else if f.control === "select"}
139
+ <Select value={f.value} options={(f.options ?? []).map((o) => ({ value: o.value, label: o.label }))} onChange={(v) => flow.set(f.path, v)} />
140
+ {@render problem(f)}
141
+ {:else if f.control === "segments"}
142
+ <Selector inline activation="manual" value={f.value} items={items(f.options)} onChange={(v) => flow.set(f.path, v)} />
143
+ {@render problem(f)}
144
+ {:else if f.control === "checks"}
145
+ <div class="glim-notify-checks" data-notify="events">
146
+ {#each f.options ?? [] as o (o.value)}
147
+ <Checkbox bind:checked={() => !!o.checked, (on) => flow.setEvent(o.value, on)} label={o.label} />
148
+ {/each}
149
+ </div>
150
+ {:else if f.control === "headers"}
151
+ <div class="glim-notify-headers">
152
+ {#each s.headers as h, i (i)}
153
+ <div class="glim-notify-header">
154
+ <TextField mono label={text.fields.headerName} value={h.name} placeholder="Authorization" oninput={(e) => flow.setHeader(i, "name", e.currentTarget.value)} />
155
+ <PasswordField
156
+ autocomplete="new-password"
157
+ aria-label={text.fields.headerValue}
158
+ value={h.value === NOTIFY_REDACTED ? "" : h.value}
159
+ text={eye}
160
+ oninput={(e) => flow.setHeader(i, "value", e.currentTarget.value)}
161
+ />
162
+ <Button compact tone="subtle" label={text.fields.headerRemove} labelKey={keys.remove} glyph={IconTrash} onClick={() => flow.removeHeader(i)} />
163
+ </div>
164
+ {/each}
165
+ <div>
166
+ <Button label={text.fields.headerAdd} labelKey={keys.add} onClick={flow.addHeader} />
167
+ </div>
168
+ {#if f.note}
169
+ <p class="glim-notify-text">{f.note}</p>
170
+ {/if}
171
+ {@render problem(f)}
172
+ </div>
173
+ {:else}
174
+ <TextField mono={f.mono} value={f.value} placeholder={f.placeholder} error={f.error} oninput={(e) => flow.set(f.path, e.currentTarget.value)} />
175
+ {/if}
176
+ </FieldRow>
177
+ {/each}
178
+ </FieldRowGroup>
179
+ {#if s.said}
180
+ <p class={s.said.ok ? "glim-notify-said" : "glim-notify-said glim-notify-said--fail"} role={s.said.ok ? "status" : "alert"}>{s.said.message}</p>
181
+ {/if}
182
+ </div>
183
+ {/if}
184
+ {/snippet}
185
+
186
+ {#if w.kind === "pick"}
187
+ <PickerWindow title={text.add} hint={text.hint} items={picker.items} groups={picker.groups} text={pickerText} onPick={flow.choose} onClose={flow.close} />
188
+ {:else if form && w.adding}
189
+ <PickerWindow
190
+ title={text.add}
191
+ items={picker.items}
192
+ groups={picker.groups}
193
+ text={pickerText}
194
+ selected={form.kind}
195
+ {actions}
196
+ onPick={flow.choose}
197
+ onBack={flow.pick}
198
+ onClose={flow.close}
199
+ >
200
+ {@render body()}
201
+ </PickerWindow>
202
+ {:else if form}
203
+ <Window {title} text={{ cancel: text.cancel, close: text.close }} closeOnBackdrop={false} {actions} onClose={flow.close}>
204
+ {@render body()}
205
+ </Window>
206
+ {/if}
@@ -0,0 +1,19 @@
1
+ import type { Snippet } from "svelte";
2
+ import { type Catalog, type NotifyCardFlow, type NotifyCardLabelKeys, type NotifyCardState, type NotifyCardText, type NotifyChoice, type NotifyKind } from "@glimstone/core";
3
+ type $$ComponentProps = {
4
+ flow: NotifyCardFlow;
5
+ flowState: NotifyCardState;
6
+ text: NotifyCardText;
7
+ app: string;
8
+ lang: string;
9
+ providers: Catalog;
10
+ kinds: readonly NotifyKind[];
11
+ events: readonly NotifyChoice[];
12
+ checks: readonly NotifyChoice[];
13
+ unavailable: Partial<Record<NotifyKind, string>>;
14
+ keys: NotifyCardLabelKeys;
15
+ glyph: (kind: NotifyKind) => Snippet;
16
+ };
17
+ declare const NotifyCardWindow: import("svelte").Component<$$ComponentProps, {}, "">;
18
+ type NotifyCardWindow = ReturnType<typeof NotifyCardWindow>;
19
+ export default NotifyCardWindow;
package/dist/index.d.ts CHANGED
@@ -58,6 +58,7 @@ export { default as SignInCard, type ResetAnswer, type SignInAnswer, type SignIn
58
58
  export { default as SignInField, type SignInFieldProps } from "./SignInField.svelte";
59
59
  export { default as SignInReauthWindow, type SignInReauthText, type SignInReauthWindowProps } from "./SignInReauthWindow.svelte";
60
60
  export { default as SignInTile, type SignInTileCard, type SignInTileLabelKeys, type SignInTileProps, type SignInTileText } from "./SignInTile.svelte";
61
+ export { default as NotifyCard, type NotifyCardLabelKeys, type NotifyCardProps, type NotifyCardText } from "./NotifyCard.svelte";
61
62
  export { default as SkeletonRow, type SkeletonRowProps } from "./SkeletonRow.svelte";
62
63
  export { default as SubCard, type SubCardProps } from "./SubCard.svelte";
63
64
  export { default as Table, type TableColumn, type TableProps } from "./Table.svelte";
package/dist/index.js CHANGED
@@ -58,6 +58,7 @@ export { default as SignInCard } from "./SignInCard.svelte";
58
58
  export { default as SignInField } from "./SignInField.svelte";
59
59
  export { default as SignInReauthWindow } from "./SignInReauthWindow.svelte";
60
60
  export { default as SignInTile } from "./SignInTile.svelte";
61
+ export { default as NotifyCard } from "./NotifyCard.svelte";
61
62
  export { default as SkeletonRow } from "./SkeletonRow.svelte";
62
63
  export { default as SubCard } from "./SubCard.svelte";
63
64
  export { default as Table } from "./Table.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/svelte",
3
- "version": "4.9.0",
3
+ "version": "4.9.1",
4
4
  "description": "GlimStone's components for Svelte",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -141,7 +141,7 @@
141
141
  "build": "svelte-package -i src -o dist"
142
142
  },
143
143
  "dependencies": {
144
- "@glimstone/core": "4.9.0"
144
+ "@glimstone/core": "4.9.1"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@internationalized/date": "^3.12.4",