@glimstone/react 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,28 @@
1
+ import { type Catalog, type NotifyApi, type NotifyCardLabelKeys, type NotifyCardText, type NotifyChoice, type NotifyKind, type 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
+ export declare function NotifyCard(props: NotifyCardProps): import("react").JSX.Element;
@@ -0,0 +1,135 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState, useSyncExternalStore } from "react";
3
+ import { connectionTestFace, createNotifyCardFlow, fill, notifyChannelName, notifyForm, notifyGlyphKey, notifyPicker, notifyRemoval, notifyRows, showNotifyRefusal, NOTIFY_CARD_KEYS, NOTIFY_KINDS, NOTIFY_REDACTED, } from "@glimstone/core";
4
+ import { Badge } from "./Badge.js";
5
+ import { Button } from "./Button.js";
6
+ import { Card } from "./Card.js";
7
+ import { Checkbox } from "./Checkbox.js";
8
+ import { EmptyState } from "./EmptyState.js";
9
+ import { FieldRow } from "./FieldRow.js";
10
+ import { FieldRowGroup } from "./FieldRowGroup.js";
11
+ import { GlyphTile } from "./GlyphTile.js";
12
+ import { glyphFor, IconCheck, IconClose, IconPencil, IconTrash } from "./glyphs.js";
13
+ import { ListRow } from "./ListRow.js";
14
+ import { NumberField } from "./NumberField.js";
15
+ import { PasswordField } from "./PasswordField.js";
16
+ import { PickerWindow } from "./PickerWindow.js";
17
+ import { BrandMark } from "./ReadmeButton.js";
18
+ import { Select } from "./Select.js";
19
+ import { Selector } from "./Selector.js";
20
+ import { TextArea, TextField } from "./TextField.js";
21
+ import { Toggle } from "./Toggle.js";
22
+ import { UnavailableNotice } from "./UnavailableNotice.js";
23
+ import { useConfirm } from "./useConfirm.js";
24
+ import { Window } from "./Window.js";
25
+ const NONE = [];
26
+ const ANYWHERE = {};
27
+ export function NotifyCard(props) {
28
+ const { text, app, lang, providers, kinds = NOTIFY_KINDS, events = [], checks = [], unavailable = {}, hueIndex } = props;
29
+ const latest = useRef(props);
30
+ latest.current = props;
31
+ const [flow] = useState(() => createNotifyCardFlow(() => ({
32
+ ...latest.current,
33
+ kinds: latest.current.kinds ?? NOTIFY_KINDS,
34
+ events: latest.current.events ?? NONE,
35
+ checks: latest.current.checks ?? NONE,
36
+ unavailable: latest.current.unavailable ?? ANYWHERE,
37
+ })));
38
+ const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
39
+ useEffect(() => flow.start(), [flow]);
40
+ useEffect(() => showNotifyRefusal(s.refusal), [s.refusal?.count]);
41
+ const keys = { ...NOTIFY_CARD_KEYS, ...props.labelKeys };
42
+ const { confirm, confirmDialog } = useConfirm({ title: text.remove, cancel: text.cancel, confirm: text.remove });
43
+ const mark = (kind) => {
44
+ const m = providers.entries.find((e) => e.id === kind)?.mark;
45
+ return m ? _jsx(BrandMark, { svg: m.svg }) : glyphFor(notifyGlyphKey(kind, keys));
46
+ };
47
+ function ask(id) {
48
+ const c = s.channels.find((x) => x.id === id);
49
+ if (!c)
50
+ return;
51
+ const q = notifyRemoval(text, c);
52
+ void confirm(q.message, { confirmLabel: q.confirm, confirmLabelKey: keys.remove }).then((yes) => {
53
+ if (yes)
54
+ void flow.remove(id);
55
+ });
56
+ }
57
+ const rows = notifyRows(s, { text, providers, unavailable });
58
+ return (_jsxs("div", { "data-glim": "NotifyCard", children: [_jsx(Card, { title: text.title, hint: text.hint, hueIndex: hueIndex, children: _jsxs("div", { className: "glim-notify-body", children: [s.loadFailed && (_jsx("p", { className: "glim-notify-said glim-notify-said--fail", role: "alert", children: text.notLoaded })), rows.length > 0 ? (_jsx("div", { className: "glim-list glim-notify-rows", children: rows.map((row) => {
59
+ const test = s.rowTests[row.id];
60
+ const face = connectionTestFace(test);
61
+ return (_jsx(ListRow, { steady: true, name: row.name, meta: row.meta, tile: _jsx(GlyphTile, { glyph: mark(row.kind) }), badges: row.idle ? (_jsx(Badge, { size: "small", tone: "warn", children: text.idle })) : undefined, "data-notify-channel": row.id, actions: _jsxs(_Fragment, { children: [_jsx(Toggle, { checked: row.enabled, label: row.name, hideLabel: true, onChange: (on) => void flow.setEnabled(row.id, on), "data-notify": `switch-${row.id}` }), _jsx(Button, { compact: true, tone: face.tone === "neutral" ? "subtle" : face.tone, label: text.test, labelKey: keys.test, glyph: face.outcome === "cross" ? _jsx(IconClose, {}) : _jsx(IconCheck, {}), busy: test?.busy, title: test?.title, className: face.shake ? "glim-shake" : undefined, "data-notify": `test-${row.id}`, onClick: () => void flow.testRow(row.id) }), _jsx(Button, { compact: true, tone: "subtle", label: text.edit, labelKey: keys.edit, glyph: _jsx(IconPencil, {}), "data-notify": `edit-${row.id}`, onClick: () => flow.edit(row.id) }), _jsx(Button, { compact: true, tone: "subtle", label: text.remove, labelKey: keys.remove, glyph: _jsx(IconTrash, {}), busy: s.busy === `remove-${row.id}`, "data-notify": `remove-${row.id}`, onClick: () => ask(row.id) })] }) }, row.id));
62
+ }) })) : (s.loaded && _jsx(EmptyState, { nested: true, title: fill(text.empty, { app }) })), _jsx("div", { className: "glim-notify-foot", children: _jsx(Button, { label: text.add, labelKey: keys.add, disabled: !s.loaded, "data-notify": "add", onClick: flow.pick }) })] }) }), _jsx(NotifyCardWindow, { s: s, flow: flow, text: text, app: app, lang: lang, providers: providers, kinds: kinds, events: events, checks: checks, unavailable: unavailable, keys: keys, mark: mark }), confirmDialog] }));
63
+ }
64
+ // The picker, and the form of the channel being added or edited.
65
+ function NotifyCardWindow({ s, flow, text, app, lang, providers, kinds, events, checks, unavailable, keys, mark }) {
66
+ const w = s.window;
67
+ if (!w)
68
+ return null;
69
+ const { items, groups } = notifyPicker(providers, text, lang, kinds, mark);
70
+ const pickerText = { search: text.search, none: text.noMatch, clear: text.clear, close: text.close, cancel: text.cancel, back: text.back };
71
+ if (w.kind === "pick") {
72
+ return _jsx(PickerWindow, { title: text.add, hint: text.hint, items: items, groups: groups, text: pickerText, onPick: flow.choose, onClose: flow.close });
73
+ }
74
+ const form = notifyForm(s, { text, app, events, checks, unavailable });
75
+ if (!form || !s.draft)
76
+ return null;
77
+ const test = s.formTest;
78
+ const face = connectionTestFace(test);
79
+ const actions = [
80
+ {
81
+ label: text.test,
82
+ labelKey: keys.test,
83
+ glyph: face.outcome === "cross" ? _jsx(IconClose, {}) : face.outcome === "check" ? _jsx(IconCheck, {}) : undefined,
84
+ tone: test?.busy ? undefined : test?.tone,
85
+ busy: !!test?.busy,
86
+ title: test?.title,
87
+ attrs: { "data-notify": "form-test" },
88
+ onClick: () => {
89
+ void flow.test();
90
+ return false;
91
+ },
92
+ },
93
+ {
94
+ label: text.save,
95
+ labelKey: keys.save,
96
+ primary: true,
97
+ busy: s.busy === "save",
98
+ attrs: { "data-notify": "save" },
99
+ onClick: () => {
100
+ void flow.save();
101
+ return false;
102
+ },
103
+ },
104
+ ];
105
+ const body = _jsx(NotifyForm, { form: form, s: s, flow: flow, text: text, keys: keys });
106
+ if (w.adding) {
107
+ return (_jsx(PickerWindow, { title: text.add, items: items, groups: groups, text: pickerText, selected: form.kind, actions: actions, onPick: flow.choose, onBack: flow.pick, onClose: flow.close, children: body }));
108
+ }
109
+ return (_jsx(Window, { title: fill(text.editTitle, { name: notifyChannelName(text, s.draft) }), text: { cancel: text.cancel, close: text.close }, closeOnBackdrop: false, actions: actions, onClose: flow.close, children: body }));
110
+ }
111
+ function NotifyForm({ form, s, flow, text, keys }) {
112
+ const eye = { show: text.show, hide: text.hide };
113
+ const problem = (f) => f.error && (_jsx("p", { className: "glim-notify-problem", role: "alert", children: f.error }));
114
+ const control = (f) => {
115
+ switch (f.control) {
116
+ case "secret":
117
+ return _jsx(PasswordField, { autoComplete: "new-password", value: f.value, text: eye, note: f.note, error: f.error, onChange: (e) => flow.set(f.path, e.target.value) });
118
+ case "number":
119
+ return _jsx(NumberField, { min: 1, max: 65535, value: f.value, placeholder: f.placeholder, error: f.error, onChange: (e) => flow.set(f.path, e.target.value) });
120
+ case "area":
121
+ return _jsx(TextArea, { mono: f.mono, value: f.value, placeholder: f.placeholder, error: f.error, onChange: (e) => flow.set(f.path, e.target.value) });
122
+ case "select":
123
+ return (_jsxs(_Fragment, { children: [_jsx(Select, { value: f.value, options: (f.options ?? []).map((o) => ({ value: o.value, label: o.label })), onChange: (v) => flow.set(f.path, v) }), problem(f)] }));
124
+ case "segments":
125
+ return (_jsxs(_Fragment, { children: [_jsx(Selector, { inline: true, activation: "manual", value: f.value, items: (f.options ?? []).map((o) => ({ id: o.value, label: o.label })), onChange: (v) => flow.set(f.path, v) }), problem(f)] }));
126
+ case "checks":
127
+ return (_jsx("div", { className: "glim-notify-checks", "data-notify": "events", children: (f.options ?? []).map((o) => (_jsx(Checkbox, { checked: !!o.checked, label: o.label, onChange: (on) => flow.setEvent(o.value, on) }, o.value))) }));
128
+ case "headers":
129
+ return (_jsxs("div", { className: "glim-notify-headers", children: [s.headers.map((h, i) => (_jsxs("div", { className: "glim-notify-header", children: [_jsx(TextField, { mono: true, label: text.fields.headerName, value: h.name, placeholder: "Authorization", onChange: (e) => flow.setHeader(i, "name", e.target.value) }), _jsx(PasswordField, { autoComplete: "new-password", "aria-label": text.fields.headerValue, value: h.value === NOTIFY_REDACTED ? "" : h.value, text: eye, onChange: (e) => flow.setHeader(i, "value", e.target.value) }), _jsx(Button, { compact: true, tone: "subtle", label: text.fields.headerRemove, labelKey: keys.remove, glyph: _jsx(IconTrash, {}), onClick: () => flow.removeHeader(i) })] }, i))), _jsx("div", { children: _jsx(Button, { label: text.fields.headerAdd, labelKey: keys.add, onClick: flow.addHeader }) }), f.note && _jsx("p", { className: "glim-notify-text", children: f.note }), problem(f)] }));
130
+ default:
131
+ return _jsx(TextField, { mono: f.mono, value: f.value, placeholder: f.placeholder, error: f.error, onChange: (e) => flow.set(f.path, e.target.value) });
132
+ }
133
+ };
134
+ return (_jsxs("div", { className: "glim-notify-form", "data-notify-form": form.kind, children: [form.hint && _jsx("p", { className: "glim-notify-text", children: form.hint }), form.unavailable && _jsx(UnavailableNotice, { title: text.idle, reason: form.unavailable }), form.loose.map((line, i) => (_jsx("p", { className: "glim-notify-problem", role: "alert", children: line }, i))), _jsx(FieldRowGroup, { children: form.fields.map((f) => (_jsx(FieldRow, { label: f.label, hint: f.hint, children: control(f) }, f.path))) }), s.said && (_jsx("p", { className: s.said.ok ? "glim-notify-said" : "glim-notify-said glim-notify-said--fail", role: s.said.ok ? "status" : "alert", children: s.said.message }))] }));
135
+ }
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export * from "./Sheet.tsx";
49
49
  export * from "./SignInCard.tsx";
50
50
  export * from "./SignInReauthWindow.tsx";
51
51
  export * from "./SignInTile.tsx";
52
+ export * from "./NotifyCard.tsx";
52
53
  export * from "./SkeletonRow.tsx";
53
54
  export * from "./SubCard.tsx";
54
55
  export * from "./Table.tsx";
package/dist/index.js CHANGED
@@ -49,6 +49,7 @@ export * from "./Sheet.js";
49
49
  export * from "./SignInCard.js";
50
50
  export * from "./SignInReauthWindow.js";
51
51
  export * from "./SignInTile.js";
52
+ export * from "./NotifyCard.js";
52
53
  export * from "./SkeletonRow.js";
53
54
  export * from "./SubCard.js";
54
55
  export * from "./Table.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.9.0",
3
+ "version": "4.9.1",
4
4
  "description": "GlimStone's components for React",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
@@ -16,7 +16,7 @@
16
16
  "build": "tsc -p tsconfig.build.json"
17
17
  },
18
18
  "dependencies": {
19
- "@glimstone/core": "4.9.0"
19
+ "@glimstone/core": "4.9.1"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@internationalized/date": "^3.12.4",