@glimstone/react 4.3.7 → 4.4.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 (86) hide show
  1. package/README.md +6 -1
  2. package/dist/AboutCard.d.ts +3 -1
  3. package/dist/AboutCard.js +6 -6
  4. package/dist/Badge.d.ts +8 -3
  5. package/dist/Badge.js +6 -6
  6. package/dist/BusyRing.d.ts +13 -0
  7. package/dist/BusyRing.js +6 -0
  8. package/dist/Button.d.ts +1 -1
  9. package/dist/Button.js +2 -1
  10. package/dist/Card.d.ts +3 -1
  11. package/dist/Card.js +2 -2
  12. package/dist/Checkbox.js +1 -1
  13. package/dist/CoffeeDialog.js +1 -1
  14. package/dist/ColorPicker.js +3 -3
  15. package/dist/Combobox.js +2 -1
  16. package/dist/ConfirmDialog.js +1 -1
  17. package/dist/ContextMenu.js +3 -3
  18. package/dist/CopyField.js +1 -1
  19. package/dist/CryptoDonateDialog.js +1 -1
  20. package/dist/DropdownListbox.js +4 -4
  21. package/dist/EmptyState.js +1 -1
  22. package/dist/FieldError.d.ts +8 -0
  23. package/dist/FieldError.js +9 -0
  24. package/dist/FieldRow.js +1 -1
  25. package/dist/FieldRowGroup.js +1 -1
  26. package/dist/Fortress.d.ts +112 -0
  27. package/dist/Fortress.js +164 -0
  28. package/dist/FortressAppCard.d.ts +39 -0
  29. package/dist/FortressAppCard.js +40 -0
  30. package/dist/FortressPermissions.d.ts +23 -0
  31. package/dist/FortressPermissions.js +34 -0
  32. package/dist/FortressStatusWindow.d.ts +24 -0
  33. package/dist/FortressStatusWindow.js +18 -0
  34. package/dist/GlyphField.js +1 -1
  35. package/dist/GlyphTile.js +1 -1
  36. package/dist/IconButton.js +2 -2
  37. package/dist/IconTipButton.js +1 -1
  38. package/dist/InfoBubble.js +1 -1
  39. package/dist/InstanceCard.d.ts +25 -0
  40. package/dist/InstanceCard.js +7 -0
  41. package/dist/Kbd.js +1 -1
  42. package/dist/ListRow.js +1 -1
  43. package/dist/ListTable.d.ts +21 -0
  44. package/dist/ListTable.js +74 -0
  45. package/dist/MenuBar.js +1 -1
  46. package/dist/Meter.js +1 -1
  47. package/dist/NumberField.d.ts +3 -1
  48. package/dist/NumberField.js +14 -11
  49. package/dist/PasswordField.d.ts +3 -1
  50. package/dist/PasswordField.js +8 -5
  51. package/dist/PathField.js +1 -1
  52. package/dist/PaypalDialog.js +1 -1
  53. package/dist/Pill.js +1 -1
  54. package/dist/Popover.d.ts +14 -0
  55. package/dist/Popover.js +19 -0
  56. package/dist/ProgressBar.js +1 -1
  57. package/dist/ReadmeButton.js +2 -2
  58. package/dist/RowMark.js +1 -1
  59. package/dist/Select.js +4 -4
  60. package/dist/Selector.js +1 -1
  61. package/dist/Sheet.d.ts +21 -0
  62. package/dist/Sheet.js +21 -0
  63. package/dist/SidebarRow.js +2 -2
  64. package/dist/SignInCard.js +2 -2
  65. package/dist/SkeletonRow.d.ts +10 -0
  66. package/dist/SkeletonRow.js +6 -0
  67. package/dist/Slider.js +1 -1
  68. package/dist/SubCard.d.ts +10 -8
  69. package/dist/SubCard.js +7 -7
  70. package/dist/Table.js +1 -1
  71. package/dist/TextField.d.ts +7 -3
  72. package/dist/TextField.js +12 -6
  73. package/dist/Toast.js +18 -11
  74. package/dist/Toggle.js +1 -1
  75. package/dist/Tree.js +1 -1
  76. package/dist/UnavailableNotice.js +1 -1
  77. package/dist/Window.d.ts +2 -15
  78. package/dist/Window.js +13 -15
  79. package/dist/WindowBar.js +1 -1
  80. package/dist/WindowFootRow.d.ts +25 -0
  81. package/dist/WindowFootRow.js +17 -0
  82. package/dist/index.d.ts +11 -0
  83. package/dist/index.js +11 -0
  84. package/dist/useConfirm.js +2 -2
  85. package/dist/useTipBubble.js +2 -2
  86. package/package.json +2 -2
@@ -0,0 +1,164 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
+ import { COPIED_MS, copyText, createFortressFlow, fill, hueVars, listOf, MARKS, othersLine, phraseReady, shake, storedShowOthers, storeShowOthers, qrCode, windowFocusTarget, } from "@glimstone/core";
4
+ import { Button } from "./Button.js";
5
+ import { Card } from "./Card.js";
6
+ import { FieldRow } from "./FieldRow.js";
7
+ import { FortressAppCard } from "./FortressAppCard.js";
8
+ import { FortressPermissions } from "./FortressPermissions.js";
9
+ import { InfoBubble } from "./InfoBubble.js";
10
+ import { PasswordField } from "./PasswordField.js";
11
+ import { Toggle } from "./Toggle.js";
12
+ import { Window } from "./Window.js";
13
+ import { glyphFor, IconClose, MarkSvg } from "./glyphs.js";
14
+ const LABEL_KEYS = {
15
+ join: "fortressJoin",
16
+ leave: "fortressLeave",
17
+ showPhrase: "fortressShowPhrase",
18
+ changePhrase: "fortressChangePhrase",
19
+ remove: "delete",
20
+ later: "fortressLater",
21
+ unlock: "unlock",
22
+ copy: "copy",
23
+ };
24
+ /**
25
+ * The fortress in the Instances tab ("The fortress" in the design language):
26
+ * the app's own instances first, the switch for the other apps and, once it is
27
+ * on, their cards and the permissions, with Show phrase or Enter phrase in the
28
+ * corner. Changing the phrase and leaving live in the pairing settings
29
+ * (FortressPairing).
30
+ */
31
+ export function Fortress(props) {
32
+ const { text, lang, app, joined, apps, permissions, onPermission, found, removed = [], hueStart = 0, children } = props;
33
+ const latest = useRef(props);
34
+ latest.current = props;
35
+ const flow = useMemo(() => createFortressFlow(() => ({ ...latest.current, failed: latest.current.text.failed })), []);
36
+ const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
37
+ const keys = { ...LABEL_KEYS, ...props.labelKeys };
38
+ const [ownShow, setOwnShow] = useState(storedShowOthers);
39
+ const showOthers = props.showOthers ?? ownShow;
40
+ const setShowOthers = (on) => {
41
+ if (props.onShowOthers)
42
+ props.onShowOthers(on);
43
+ else {
44
+ storeShowOthers(on);
45
+ setOwnShow(on);
46
+ }
47
+ };
48
+ const line = othersLine(text, lang, apps);
49
+ // An app that shows the phrase in its pairing settings leaves the corner out.
50
+ const corner = !joined ? (_jsx(Button, { label: text.enterPhrase, labelKey: keys.join, tone: "accent", size: "key", onClick: flow.openJoin, "data-fortress": "open-join" })) : (props.onShowPhrase && (_jsx(Button, { label: text.showPhrase, labelKey: keys.showPhrase, tone: "accent", size: "key", busy: s.busy === "show", onClick: () => void flow.openPhrase(), "data-fortress": "show" })));
51
+ return (_jsxs("div", { "data-glim": "Fortress", className: "glim-fortress", children: [_jsxs("div", { className: "glim-fortress-grid", children: [typeof children === "function" ? children(flow.openRemove) : children, !joined && (_jsxs("div", { className: "glim-card glim-instance glim-instance--out", "data-fortress": "out", children: [_jsx("h3", { className: "glim-instance-title", children: props.removedHere ? text.removedHereTitle : text.outTitle }), _jsx("p", { className: "glim-instance-hint", children: fill(props.removedHere ? text.removedHereHint : text.outHint, { app: app.name }) }), found && (_jsxs("p", { className: "glim-instance-found", children: [found.logo && _jsx("img", { src: found.logo, alt: "" }), _jsx("span", { children: fill(text.found, { app: found.app, device: found.device }) })] }))] }))] }), joined && !props.hideSwitch && (_jsxs("div", { className: "glim-card glim-fortress-switch glim-hue", style: hueVars(hueStart), children: [_jsxs("span", { className: "glim-fortress-switch-text", children: [_jsxs("span", { className: "glim-fortress-switch-name", children: [text.showOthers, _jsx(InfoBubble, { tip: text.about })] }), _jsx("span", { className: "glim-fortress-sub", children: line })] }), _jsx(Toggle, { label: text.showOthers, hideLabel: true, checked: showOthers, onChange: setShowOthers, "data-fortress": "others" })] })), joined && removed.length > 0 && (_jsxs("div", { className: "glim-fortress-removed", "data-fortress": "removed", role: "status", children: [glyphFor("info"), _jsx("span", { children: fill(text.removedNote, { devices: listOf(lang, removed) }) }), props.onChangePhrase && (_jsx(Button, { label: text.changePhrase, labelKey: keys.changePhrase, tone: "subtle", onClick: flow.openChange, "data-fortress": "open-change" }))] })), joined && showOthers && (_jsxs(_Fragment, { children: [_jsx("div", { className: "glim-fortress-grid", children: apps.map((a, i) => props.renderApp ? (_jsx(Fragment, { children: props.renderApp(a, hueStart + 1 + i, props.onRemove && flow.openRemove) }, a.id)) : (_jsx(FortressAppCard, { app: a, text: text, lang: lang, hueIndex: hueStart + 1 + i, onOpen: props.onOpen, onRemove: props.onRemove && flow.openRemove, removeKey: keys.remove }, a.id))) }), _jsx(FortressPermissions, { text: text, app: app, apps: [app, ...apps], permissions: permissions, onPermission: onPermission, notify: props.notify, hueIndex: hueStart + 1 + apps.length, extra: props.permissionExtra })] })), corner && _jsx("div", { className: "glim-fortress-actions", children: corner }), s.window && _jsx(FortressWindow, { flow: flow, state: s, props: props, keys: keys })] }));
52
+ }
53
+ function PhraseQr({ content, name }) {
54
+ const code = useMemo(() => qrCode(content), [content]);
55
+ const side = code.size + 8;
56
+ // A camera reads dark modules on a light ground, so these two colours stay put in every theme.
57
+ return (_jsxs("svg", { className: "glim-phrase-qr", "data-fortress": "qr", role: "img", "aria-label": name, viewBox: `-4 -4 ${side} ${side}`, shapeRendering: "crispEdges", children: [_jsx("rect", { x: -4, y: -4, width: side, height: side, fill: "#ffffff" }), _jsx("path", { d: code.path, fill: "#161616" })] }));
58
+ }
59
+ function FortressWindow({ flow, state, props, keys }) {
60
+ const { text, lang, app } = props;
61
+ const w = state.window;
62
+ const card = useRef(null);
63
+ const [copied, setCopied] = useState(false);
64
+ const paired = props.pairedWith?.length ? listOf(lang, props.pairedWith) : null;
65
+ const way = { cancel: text.cancel, close: text.close };
66
+ const busy = state.busy !== null;
67
+ useEffect(() => {
68
+ const refused = state.refusal && card.current?.querySelector(`[data-fortress="${state.refusal.button}"]`);
69
+ return refused ? shake(refused) : undefined;
70
+ }, [state.refusal]);
71
+ const focus = w.kind === "join" ? w.focus : -1;
72
+ useEffect(() => {
73
+ if (focus >= 0)
74
+ card.current?.querySelector(`[data-word="${focus}"]`)?.focus();
75
+ }, [focus]);
76
+ // The window stays mounted from one step to the next, so the focus it takes
77
+ // on opening does not come again, and the button that was pressed may be gone.
78
+ const kind = w.kind;
79
+ const opened = useRef(false);
80
+ useEffect(() => {
81
+ if (!opened.current) {
82
+ opened.current = true;
83
+ return;
84
+ }
85
+ if (card.current)
86
+ windowFocusTarget(card.current)?.focus();
87
+ }, [kind]);
88
+ useEffect(() => {
89
+ if (!copied)
90
+ return;
91
+ const t = setTimeout(() => setCopied(false), COPIED_MS);
92
+ return () => clearTimeout(t);
93
+ }, [copied]);
94
+ const error = state.error && (_jsx("p", { className: "glim-fortress-error", role: "alert", children: state.error }));
95
+ const send = (button, run, label, key, disabled = false) => ({
96
+ label,
97
+ labelKey: key,
98
+ primary: true,
99
+ disabled: disabled || busy,
100
+ attrs: { "data-fortress": button },
101
+ onClick: () => {
102
+ void run();
103
+ return false;
104
+ },
105
+ });
106
+ const words = (list) => (_jsxs("div", { className: "glim-phrase-show", children: [_jsx("ol", { className: "glim-phrase-words", "data-fortress": "words", children: list.map((word, i) => (_jsxs("li", { children: [_jsx("span", { className: "glim-phrase-number glim-num", children: i + 1 }), word] }, i))) }), _jsx(PhraseQr, { content: props.phraseQr ? props.phraseQr(list) : list.join(" "), name: text.qrName }), _jsx("p", { className: "glim-phrase-scan", children: text.scanHint })] }));
107
+ const copy = (list) => ({
108
+ label: text.copy,
109
+ labelKey: keys.copy,
110
+ attrs: { "data-fortress": "copy" },
111
+ onClick: () => {
112
+ void copyText(list.join(" ")).then(setCopied);
113
+ return false;
114
+ },
115
+ });
116
+ // Window adds Close only to a foot with something in it, so a window that only says something brings its own.
117
+ const close = { label: text.close, labelKey: "common.close", glyph: _jsx(IconClose, {}), wayOut: true };
118
+ const common = { ref: card, text: way, onClose: flow.close };
119
+ switch (w.kind) {
120
+ case "join":
121
+ return (_jsx(Window, { ...common, title: text.joinTitle, size: "wide", actions: [send("join", flow.join, text.join, keys.join, !phraseReady(w.words))], children: _jsxs("form", { className: "glim-fortress-text", onSubmit: (e) => {
122
+ e.preventDefault();
123
+ void flow.join();
124
+ }, children: [_jsx("p", { children: text.about }), _jsx("div", { className: "glim-phrase-fields", children: w.words.map((word, i) => (_jsxs("label", { className: "glim-phrase-field", children: [_jsx("span", { className: "glim-phrase-number glim-num", children: i + 1 }), _jsx("input", { className: "glim-input", "data-word": i, value: word, "aria-label": fill(text.word, { n: i + 1 }), autoComplete: "off", autoCapitalize: "none", autoCorrect: "off", spellCheck: false, onChange: (e) => flow.enter(i, e.target.value) })] }, i))) }), _jsx("button", { type: "submit", hidden: true }), _jsx("p", { className: "glim-fortress-sub", children: text.phraseWhere }), paired && (_jsxs("p", { className: "glim-fortress-note", "data-fortress": "moves", children: [glyphFor("info"), _jsx("span", { children: fill(text.moves, { app: app.name, devices: paired }) })] })), error] }) }));
125
+ case "joined":
126
+ return (_jsx(Window, { ...common, title: text.joinTitle, actions: [close], children: _jsxs("div", { className: "glim-fortress-result", children: [_jsx("span", { className: "glim-fortress-result-mark", "aria-hidden": "true", children: _jsx(MarkSvg, { mark: MARKS.check }) }), _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { className: "glim-fortress-result-title", children: fill(text.joinedTitle, { app: app.name }) }), _jsxs("p", { className: "glim-fortress-sub", children: [paired ? `${fill(text.joinedMoved, { devices: paired })} ` : "", text.joinedNext] })] })] }) }));
127
+ case "leave":
128
+ return (_jsx(Window, { ...common, title: text.leaveTitle, actions: [send("leave", flow.leave, text.leaveConfirm, keys.leave)], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsxs("p", { children: [fill(text.leaveBody, { app: app.name }), paired && ` ${fill(text.leavePairing, { devices: paired })}`, props.leaveNote && ` ${props.leaveNote}`] }), _jsx("p", { className: "glim-fortress-sub", children: text.leaveBack }), error] }) }));
129
+ case "remove":
130
+ return (_jsx(Window, { ...common, title: fill(text.removeTitle, { device: w.device }), actions: [send("remove", flow.remove, text.remove, keys.remove)], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { children: fill(text.removeBody, { device: w.device }) }), _jsx("p", { className: "glim-fortress-sub", children: text.removeBack }), error] }) }));
131
+ case "removed":
132
+ return (_jsx(Window, { ...common, title: text.removedTitle, actions: [
133
+ { label: text.later, labelKey: keys.later, wayOut: true, attrs: { "data-fortress": "later" } },
134
+ send("change", flow.change, text.changeConfirm, keys.changePhrase),
135
+ ], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { children: fill(text.removedBody, { device: w.device }) }), error] }) }));
136
+ case "phrase":
137
+ if (w.step === "password") {
138
+ return (_jsx(Window, { ...common, title: text.phraseTitle, actions: [send("unlock", flow.unlock, text.unlock, keys.unlock, w.password === "")], children: _jsxs("form", { className: "glim-fortress-text", onSubmit: (e) => {
139
+ e.preventDefault();
140
+ void flow.unlock();
141
+ }, children: [_jsx("p", { children: fill(text.phrasePassword, { app: app.name }) }), _jsx(PasswordField, { "aria-label": fill(text.password, { app: app.name }), placeholder: fill(text.password, { app: app.name }), value: w.password, onChange: (e) => flow.setPassword(e.target.value), text: { show: text.showPassword, hide: text.hidePassword } }), error] }) }));
142
+ }
143
+ return (_jsx(Window, { ...common, title: text.phraseTitle, size: "wide", start: copied ? text.copied : undefined, actions: [copy(w.words)], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { children: text.phraseBody }), words(w.words)] }) }));
144
+ case "change":
145
+ return (_jsx(Window, { ...common, title: text.changeTitle, actions: [send("change", flow.change, text.changeConfirm, keys.changePhrase)], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { children: text.changeBody }), _jsx("p", { className: "glim-fortress-sub", children: text.changeAway }), error] }) }));
146
+ case "changed":
147
+ return (_jsx(Window, { ...common, title: text.changedTitle, size: "wide", start: copied ? text.copied : undefined, actions: [copy(w.words)], children: _jsxs("div", { className: "glim-fortress-text", children: [_jsx("p", { children: text.phraseBody }), words(w.words), w.left.length > 0 && _jsx("p", { className: "glim-fortress-sub", children: fill(text.changedLeft, { devices: listOf(lang, w.left) }) })] }) }));
148
+ }
149
+ }
150
+ /**
151
+ * The fortress in the app's pairing settings: the one place where the phrase
152
+ * shows and changes and the app leaves, each behind a window that says what
153
+ * it does. An app that shows the phrase here leaves Show phrase out of its
154
+ * Fortress.
155
+ */
156
+ export function FortressPairing(props) {
157
+ const { text, app, hueIndex, children } = props;
158
+ const latest = useRef(props);
159
+ latest.current = props;
160
+ const flow = useMemo(() => createFortressFlow(() => ({ ...latest.current, failed: latest.current.text.failed })), []);
161
+ const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
162
+ const keys = { ...LABEL_KEYS, ...props.labelKeys };
163
+ return (_jsxs(Card, { "data-glim": "FortressPairing", title: text.pairing, hueIndex: hueIndex, children: [children, (props.onShowPhrase || props.onChangePhrase) && (_jsxs(FieldRow, { label: text.phraseTitle, hint: props.onChangePhrase && text.changePhraseAbout, children: [props.onShowPhrase && (_jsx(Button, { label: text.showPhrase, labelKey: keys.showPhrase, busy: s.busy === "show", onClick: () => void flow.openPhrase(), "data-fortress": "show" })), props.onChangePhrase && _jsx(Button, { label: text.change, labelKey: keys.changePhrase, onClick: flow.openChange, "data-fortress": "open-change" })] })), _jsx(FieldRow, { label: text.leaveRow, hint: fill(text.leaveAbout, { app: app.name }), children: _jsx(Button, { label: text.leaveConfirm, labelKey: keys.leave, onClick: flow.openLeave, "data-fortress": "open-leave" }) }), props.after, s.window && _jsx(FortressWindow, { flow: flow, state: s, props: props, keys: keys })] }));
164
+ }
@@ -0,0 +1,39 @@
1
+ import { type FortressApp, type FortressInstance, type FortressText } from "@glimstone/core";
2
+ export type { FortressApp, FortressInstance } from "@glimstone/core";
3
+ export interface FortressAppCardProps {
4
+ app: FortressApp;
5
+ text: FortressText;
6
+ /** The interface language, for the counts. */
7
+ lang: string;
8
+ hueIndex?: number;
9
+ /** Opens an instance, through the fortress where it runs elsewhere. Without it the instance's `open.href` opens in a new tab. */
10
+ onOpen?: (app: FortressApp, instance: FortressInstance) => void;
11
+ /** Asks before an instance is removed, with its name. Without it nothing here removes. */
12
+ onRemove?: (id: string, name: string) => void;
13
+ /** The label key behind Remove, which picks its glyph. */
14
+ removeKey?: string;
15
+ }
16
+ /** The state of one instance: reached through the relay, and connected, checking or away. */
17
+ export declare function PresenceBadges({ instance, text }: {
18
+ instance: FortressInstance;
19
+ text: FortressText;
20
+ }): import("react").JSX.Element;
21
+ /** A device's glyph, asked for by its kind through the app's resolver (`deviceServer`, `devicePc`, `deviceLaptop`, `devicePhone`). */
22
+ export declare function deviceGlyph(kind: FortressInstance["deviceKind"]): import("react").ReactNode;
23
+ export interface FortressDoubtWindowProps {
24
+ app: FortressApp;
25
+ instance: FortressInstance;
26
+ text: FortressText;
27
+ /** Runs on Open anyway. The window closes either way. */
28
+ onOpen: () => void;
29
+ onClose: () => void;
30
+ }
31
+ /**
32
+ * The question before an instance with `doubt` opens: two members claim the
33
+ * same app on the same device, so the person opens one only by the end of its
34
+ * id. An app that draws the other apps in cards of its own shows it before
35
+ * `onOpen`.
36
+ */
37
+ export declare function FortressDoubtWindow({ app, instance, text, onOpen, onClose }: FortressDoubtWindowProps): import("react").JSX.Element;
38
+ /** Another app of the fortress: its state, where it runs, and the way to open it. */
39
+ export declare function FortressAppCard({ app, text, lang, hueIndex, onOpen, onRemove, removeKey }: FortressAppCardProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { appCardView, doubtView, memberName, openInstance, presenceTone } from "@glimstone/core";
4
+ import { Badge } from "./Badge.js";
5
+ import { Button } from "./Button.js";
6
+ import { InfoBubble } from "./InfoBubble.js";
7
+ import { InstanceCard } from "./InstanceCard.js";
8
+ import { Window } from "./Window.js";
9
+ import { glyphFor } from "./glyphs.js";
10
+ const presenceText = (text, i) => ({ connected: text.connected, checking: text.checking, away: text.away })[i.presence];
11
+ /** The state of one instance: reached through the relay, and connected, checking or away. */
12
+ export function PresenceBadges({ instance, text }) {
13
+ return (_jsxs("span", { "data-glim": "PresenceBadges", style: { display: "contents" }, children: [instance.relay && _jsx(Badge, { children: text.viaRelay }), _jsx(Badge, { tone: presenceTone(instance.presence), children: presenceText(text, instance) })] }));
14
+ }
15
+ /** A device's glyph, asked for by its kind through the app's resolver (`deviceServer`, `devicePc`, `deviceLaptop`, `devicePhone`). */
16
+ export function deviceGlyph(kind) {
17
+ return kind ? glyphFor(`device${kind.charAt(0).toUpperCase()}${kind.slice(1)}`) : undefined;
18
+ }
19
+ /**
20
+ * The question before an instance with `doubt` opens: two members claim the
21
+ * same app on the same device, so the person opens one only by the end of its
22
+ * id. An app that draws the other apps in cards of its own shows it before
23
+ * `onOpen`.
24
+ */
25
+ export function FortressDoubtWindow({ app, instance, text, onOpen, onClose }) {
26
+ const view = doubtView(text, app, instance);
27
+ return (_jsx(Window, { "data-glim": "FortressDoubtWindow", title: view.title, text: { cancel: text.cancel, close: text.close }, onClose: onClose, actions: [{ label: view.open, labelKey: "open", primary: true, attrs: { "data-fortress": "open-anyway" }, onClick: onOpen }], children: _jsx("div", { className: "glim-fortress-text", children: _jsx("p", { children: view.body }) }) }));
28
+ }
29
+ /** Another app of the fortress: its state, where it runs, and the way to open it. */
30
+ export function FortressAppCard({ app, text, lang, hueIndex, onOpen, onRemove, removeKey = "delete" }) {
31
+ const view = appCardView(app, text, lang);
32
+ const [asking, setAsking] = useState(null);
33
+ const open = (instance) => (instance.doubt ? setAsking(instance) : openInstance(app, instance, onOpen));
34
+ // Remove stays quiet at the end of a row, or after Open on a card with one instance.
35
+ const remove = (instance, inRow) => onRemove &&
36
+ !instance.self && (_jsx(Button, { label: text.remove, labelKey: removeKey, tone: "subtle", variant: inRow ? "icon" : "default", compact: inRow, title: memberName(text, app, instance), onClick: () => onRemove(instance.id, memberName(text, app, instance)), "data-fortress": "open-remove" }));
37
+ const single = view.rows.length === 0;
38
+ const removes = single && onRemove && !view.main.self;
39
+ return (_jsxs(_Fragment, { children: [_jsx(InstanceCard, { "data-glim": "FortressAppCard", "data-fortress-app": app.id, logo: app.logo, name: app.name, eyebrow: view.eyebrow, hueIndex: hueIndex, badges: _jsxs(_Fragment, { children: [view.doubt && (_jsxs(Badge, { tone: "warn", children: [view.doubt.label, _jsx(InfoBubble, { tip: view.doubt.tip, onAccent: true })] })), view.needs && _jsx(Badge, { tone: "warn", children: view.needs }), _jsx(PresenceBadges, { instance: view.main, text: text })] }), facts: view.facts, actions: (view.open || removes) && (_jsxs(_Fragment, { children: [view.open && _jsx(Button, { label: view.open.label, labelKey: "open", onClick: () => open(view.main), "data-fortress": "open" }), single && remove(view.main, false)] })), children: !single && (_jsx("ul", { className: "glim-instance-rows", children: view.rows.map(({ instance, sub, open: opens }) => (_jsxs("li", { className: "glim-instance-row", "data-instance": instance.id, children: [_jsx("span", { className: "glim-instance-device", "aria-hidden": "true", children: deviceGlyph(instance.deviceKind) }), _jsxs("span", { className: "glim-instance-row-text", children: [_jsx("span", { className: "glim-instance-row-name", children: instance.device }), _jsx("span", { className: "glim-instance-row-sub glim-num", children: sub })] }), _jsxs("span", { className: "glim-instance-row-end", children: [_jsx(Badge, { tone: presenceTone(instance.presence), children: presenceText(text, instance) }), opens && (_jsx(Button, { label: text.open, labelKey: "open", tone: "subtle", variant: "icon", compact: true, title: memberName(text, app, instance), onClick: () => open(instance), "data-fortress": "open" })), remove(instance, true)] })] }, instance.id))) })) }), asking && _jsx(FortressDoubtWindow, { app: app, instance: asking, text: text, onOpen: () => openInstance(app, asking, onOpen), onClose: () => setAsking(null) })] }));
40
+ }
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from "react";
2
+ import { type FortressAnswer, type FortressApp, type FortressPermission, type FortressText, type ToastSeverity } from "@glimstone/core";
3
+ export type { FortressPermission } from "@glimstone/core";
4
+ export interface FortressPermissionsProps {
5
+ text: FortressText;
6
+ /** The app showing the card, for the filter "With {app}". */
7
+ app: {
8
+ id: string;
9
+ name: string;
10
+ };
11
+ /** Every app of the fortress, this one included, for the marks. */
12
+ apps: Pick<FortressApp, "id" | "name" | "logo">[];
13
+ permissions: FortressPermission[];
14
+ /** Saves one switch the moment it flips. A refusal leaves it as it was and shakes it. */
15
+ onPermission: (id: string, on: boolean) => Promise<FortressAnswer>;
16
+ /** Puts the small confirmation of a save, or the reason it failed, into the app's toasts. */
17
+ notify?: (message: string, severity: ToastSeverity) => void;
18
+ hueIndex?: number;
19
+ /** Something of the app's own under one permission's words, such as the folder it writes to. */
20
+ extra?: (permission: FortressPermission) => ReactNode;
21
+ }
22
+ /** What one app may do at another, a switch for each, all on unless switched off. */
23
+ export declare function FortressPermissions({ text, app, apps, permissions, onPermission, notify, hueIndex, extra }: FortressPermissionsProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { fill, MARKS, permissionsWith, shake } from "@glimstone/core";
4
+ import { Card } from "./Card.js";
5
+ import { Selector } from "./Selector.js";
6
+ import { Toggle } from "./Toggle.js";
7
+ import { MarkSvg } from "./glyphs.js";
8
+ /** What one app may do at another, a switch for each, all on unless switched off. */
9
+ export function FortressPermissions({ text, app, apps, permissions, onPermission, notify, hueIndex, extra }) {
10
+ const [filter, setFilter] = useState("all");
11
+ const mine = permissionsWith(permissions, app.id);
12
+ // The filter is offered only where it leaves some permissions out.
13
+ const narrows = mine.length < permissions.length;
14
+ const shown = filter === "all" || !narrows ? permissions : mine;
15
+ const logo = (id) => {
16
+ const a = apps.find((x) => x.id === id);
17
+ return a?.logo ? _jsx("img", { src: a.logo, alt: "", draggable: false }, id) : null;
18
+ };
19
+ async function flip(p) {
20
+ const answer = await onPermission(p.id, !p.on).catch(() => ({}));
21
+ if (answer.ok) {
22
+ notify?.(fill(p.on ? text.permissionOff : text.permissionOn, { permission: p.title }), "success");
23
+ return;
24
+ }
25
+ notify?.(answer.error ?? text.failed, "fail");
26
+ const toggle = document.querySelector(`[data-permission="${CSS.escape(p.id)}"] .glim-toggle`);
27
+ if (toggle)
28
+ shake(toggle);
29
+ }
30
+ return (_jsx(Card, { "data-glim": "FortressPermissions", title: text.permissions, hint: text.permissionsAbout, hueIndex: hueIndex, children: permissions.length === 0 ? (_jsx("p", { className: "glim-fortress-sub", children: text.noPermissions })) : (_jsxs(_Fragment, { children: [narrows && (_jsx(Selector, { label: text.permissions, inline: true, activation: "manual", value: filter, onChange: setFilter, items: [
31
+ { id: "all", label: `${text.all} ${permissions.length}` },
32
+ { id: "with", label: `${fill(text.withApp, { app: app.name })} ${mine.length}` },
33
+ ] })), _jsx("ul", { className: "glim-permissions", children: shown.map((p) => (_jsxs("li", { className: `glim-permission${p.on ? " glim-permission--on" : ""}`, "data-permission": p.id, children: [_jsxs("span", { className: "glim-permission-pair", "aria-hidden": "true", children: [logo(p.from), _jsx(MarkSvg, { mark: MARKS.expand, className: "glim-permission-arrow" }), _jsx("span", { className: "glim-permission-to", children: p.to.map(logo) })] }), _jsxs("span", { className: "glim-permission-text", children: [_jsx("span", { className: "glim-permission-title", children: p.title }), p.detail && _jsx("span", { className: "glim-fortress-sub", children: p.detail }), extra?.(p)] }), _jsx(Toggle, { label: p.title, hideLabel: true, checked: p.on, onChange: () => flip(p) })] }, p.id))) })] })) }));
34
+ }
@@ -0,0 +1,24 @@
1
+ import { type FortressApp, type FortressInstance, type FortressLogLine, type FortressStatusReport, type FortressText } from "@glimstone/core";
2
+ export type { FortressLogLine, FortressStatusReport } from "@glimstone/core";
3
+ export interface FortressStatusWindowProps {
4
+ app: FortressApp;
5
+ instance: FortressInstance;
6
+ /** The member's status report, its words and times already in the person's language. */
7
+ report?: FortressStatusReport;
8
+ /** The member's log, newest first. The window shows the first ten lines. */
9
+ log?: FortressLogLine[];
10
+ loading?: boolean;
11
+ /** Why the report did not come, such as `openRefusalText` puts it. */
12
+ error?: string;
13
+ text: FortressText;
14
+ /** The interface language. */
15
+ lang: string;
16
+ onClose: () => void;
17
+ }
18
+ /**
19
+ * What Open shows for a member without pages of its own, such as an Unraid
20
+ * plugin, whose pages need Unraid's own sign-in and so never go through the
21
+ * fortress: its state from the status report, its last log lines and, for a
22
+ * plugin, where its settings are.
23
+ */
24
+ export declare function FortressStatusWindow({ app, instance, report, log, loading, error, text, lang, onClose }: FortressStatusWindowProps): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { statusView } from "@glimstone/core";
3
+ import { Badge } from "./Badge.js";
4
+ import { BusyRing } from "./BusyRing.js";
5
+ import { ProgressBar } from "./ProgressBar.js";
6
+ import { Window } from "./Window.js";
7
+ import { glyphFor, IconClose } from "./glyphs.js";
8
+ /**
9
+ * What Open shows for a member without pages of its own, such as an Unraid
10
+ * plugin, whose pages need Unraid's own sign-in and so never go through the
11
+ * fortress: its state from the status report, its last log lines and, for a
12
+ * plugin, where its settings are.
13
+ */
14
+ export function FortressStatusWindow({ app, instance, report, log, loading, error, text, lang, onClose }) {
15
+ const view = statusView({ app, instance, report, log, loading, error, text });
16
+ const section = (name, title, items) => items.length > 0 && (_jsxs("section", { className: "glim-status-section", "data-fortress": name, children: [_jsx("h3", { className: "glim-status-heading", children: title }), _jsx("ul", { className: "glim-status-list", children: items })] }));
17
+ return (_jsx(Window, { "data-glim": "FortressStatusWindow", lang: lang, title: view.title, drawn: _jsxs("span", { className: "glim-status-title", children: [app.logo && _jsx("img", { src: app.logo, alt: "" }), view.title] }), text: { cancel: text.cancel, close: text.close }, onClose: onClose, actions: [{ label: text.close, labelKey: "common.close", glyph: _jsx(IconClose, {}), wayOut: true }], children: _jsxs("div", { className: "glim-fortress-text", "data-fortress": "status", children: [view.loading && (_jsxs("p", { className: "glim-fortress-note", "data-fortress": "loading", children: [_jsx(BusyRing, { size: "small", delay: 0 }), _jsx("span", { role: "status", children: view.loading })] })), view.error !== undefined && (_jsxs("p", { className: "glim-fortress-note", role: "status", "data-fortress": "error", children: [glyphFor("info"), _jsx("span", { children: view.error })] })), view.state && (_jsxs("p", { className: "glim-status-state", "data-fortress": "state", children: [_jsx(Badge, { tone: view.state.tone, children: view.state.label }), view.quiet && _jsx("span", { className: "glim-fortress-sub", children: view.quiet })] })), section("needs", text.statusNeedsYou, view.needsYou.map((n, i) => (_jsxs("li", { className: "glim-status-line", children: [n.level && _jsx(Badge, { tone: n.level.tone, children: n.level.label }), " ", _jsx("span", { children: n.text })] }, i)))), section("work", text.statusWork, view.work.map((w, i) => (_jsxs("li", { className: "glim-status-work", children: [_jsx("span", { children: w.title }), _jsx(ProgressBar, { value: w.progress, label: w.title })] }, i)))), section("next", text.statusNext, view.next.map((n, i) => (_jsxs("li", { className: "glim-status-line", children: [_jsx("span", { children: n.title }), " ", _jsx("span", { className: "glim-status-at glim-num", children: n.at })] }, i)))), section("log", text.statusLog, view.log.map((l, i) => (_jsxs("li", { className: "glim-status-line", children: [_jsx("span", { className: "glim-status-at glim-num", children: l.at }), " ", l.level && _jsx(Badge, { tone: l.level.tone, children: l.level.label }), " ", _jsx("span", { children: l.text })] }, i)))), view.where && (_jsx("p", { className: "glim-fortress-sub", "data-fortress": "where", children: view.where }))] }) }));
18
+ }
@@ -4,5 +4,5 @@ import { useFieldName } from "./fieldName.js";
4
4
  export function GlyphField({ glyph, label, after, mono, width, className, style, type = "text", ...rest }) {
5
5
  const name = useFieldName(label);
6
6
  const classes = ["glim-input", "glim-glyph-field", fieldWidthClass(width), mono && "glim-input--mono", className].filter(Boolean).join(" ");
7
- return (_jsxs("label", { className: classes, style: style, children: [_jsx("span", { className: "glim-glyph-field-glyph", "aria-hidden": "true", children: glyph }), _jsx("input", { "aria-label": name, ...rest, type: type, className: "glim-glyph-field-input" }), after] }));
7
+ return (_jsxs("label", { "data-glim": "GlyphField", className: classes, style: style, children: [_jsx("span", { className: "glim-glyph-field-glyph", "aria-hidden": "true", children: glyph }), _jsx("input", { "aria-label": name, ...rest, type: type, className: "glim-glyph-field-input" }), after] }));
8
8
  }
package/dist/GlyphTile.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  export function GlyphTile({ glyph, quiet, ground, active, className }) {
3
3
  const classes = ["glim-tile", quiet && "glim-tile--quiet", ground && "glim-tile--ground", active && "glim-tile--active", className].filter(Boolean).join(" ");
4
- return (_jsx("span", { className: classes, "aria-hidden": "true", children: glyph }));
4
+ return (_jsx("span", { "data-glim": "GlyphTile", className: classes, "aria-hidden": "true", children: glyph }));
5
5
  }
@@ -4,6 +4,6 @@ import { IconTipButton } from "./IconTipButton.js";
4
4
  const reach = (e) => takePageHue(e.currentTarget);
5
5
  export function IconButton({ tip, glyph, pressed, absent, className, ...rest }) {
6
6
  if (absent)
7
- return _jsx("span", { className: "glim-icon-btn-gap", "aria-hidden": "true" });
8
- return (_jsx(IconTipButton, { ...rest, tip: tip, ariaPressed: pressed, className: `glim-btn-bare glim-icon-btn ${className ?? ""}`.trim(), onPointerEnter: reach, onFocusCapture: reach, children: glyph }));
7
+ return _jsx("span", { "data-glim": "IconButton", className: "glim-icon-btn-gap", "aria-hidden": "true" });
8
+ return (_jsx(IconTipButton, { "data-glim": "IconButton", ...rest, tip: tip, ariaPressed: pressed, className: `glim-btn-bare glim-icon-btn ${className ?? ""}`.trim(), onPointerEnter: reach, onFocusCapture: reach, children: glyph }));
9
9
  }
@@ -4,5 +4,5 @@ export function IconTipButton({ tip, disabled, className, style, children, href,
4
4
  const tooltip = useTipBubble(tip, disabled);
5
5
  const Element = (href && !disabled ? "a" : "button");
6
6
  const own = href && !disabled ? { href } : { type, disabled };
7
- return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsx(Element, { ...rest, ...own, ref: tooltip.ref, "aria-label": tip, "aria-pressed": ariaPressed, "aria-expanded": ariaExpanded, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: className, style: style, children: children })), tooltip.bubble] }));
7
+ return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsx(Element, { "data-glim": "IconTipButton", ...rest, ...own, ref: tooltip.ref, "aria-label": tip, "aria-pressed": ariaPressed, "aria-expanded": ariaExpanded, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: className, style: style, children: children })), tooltip.bubble] }));
8
8
  }
@@ -10,7 +10,7 @@ import { useTipBubble } from "./useTipBubble.js";
10
10
  // has less margin on a busy fill.
11
11
  export function InfoBubble({ tip, onAccent = false }) {
12
12
  const tooltip = useTipBubble(tip);
13
- return (_jsxs(_Fragment, { children: [_jsx("span", { ref: tooltip.ref, "aria-label": tip, "aria-describedby": tooltip.describedBy, tabIndex: 0, ...tooltip.handlers,
13
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "data-glim": "InfoBubble", ref: tooltip.ref, "aria-label": tip, "aria-describedby": tooltip.describedBy, tabIndex: 0, ...tooltip.handlers,
14
14
  // Inside a <label>, a click on a span is forwarded to the label's field,
15
15
  // which takes focus and closes the bubble at once. stopPropagation does
16
16
  // not stop the native forwarding; preventDefault does, and the span
@@ -0,0 +1,25 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ export interface InstanceFigure {
3
+ value: string;
4
+ label: string;
5
+ }
6
+ export interface InstanceCardProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
7
+ /** The app's mark, as an address or as an inline `<svg>`. */
8
+ logo?: string | ReactNode;
9
+ /** The device's name for an instance of this app, the app's name for another app. */
10
+ name: string;
11
+ eyebrow?: string;
12
+ /** Badges after the name, such as the state. */
13
+ badges?: ReactNode;
14
+ /** One quiet line of facts, joined with a dot. Empty ones are left out. */
15
+ facts?: (string | undefined)[];
16
+ /** A few numbers under the facts, each with its small label. */
17
+ figures?: InstanceFigure[];
18
+ /** What the card holds under the head, such as a row per instance. */
19
+ children?: ReactNode;
20
+ /** The card's buttons. Without a body they stand beside the mark. */
21
+ actions?: ReactNode;
22
+ /** The card's position in the rainbow, counted over the cards on the page. */
23
+ hueIndex?: number;
24
+ }
25
+ export declare function InstanceCard({ logo, name, eyebrow, badges, facts, figures, children, actions, hueIndex, className, style, ...rest }: InstanceCardProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { hueVars } from "@glimstone/core";
3
+ export function InstanceCard({ logo, name, eyebrow, badges, facts, figures, children, actions, hueIndex, className, style, ...rest }) {
4
+ const shown = facts?.filter(Boolean) ?? [];
5
+ const acts = actions && _jsx("div", { className: "glim-instance-acts", children: actions });
6
+ return (_jsxs("div", { "data-glim": "InstanceCard", "data-glim-title": name, ...rest, className: ["glim-card glim-instance", hueIndex !== undefined && "glim-hue", className].filter(Boolean).join(" "), style: hueIndex !== undefined ? { ...hueVars(hueIndex), ...style } : style, children: [_jsxs("div", { className: "glim-instance-top", children: [typeof logo === "string" ? (_jsx("img", { className: "glim-instance-mark", src: logo, alt: "", draggable: false })) : (logo && (_jsx("span", { className: "glim-instance-mark", "aria-hidden": "true", children: logo }))), _jsxs("div", { className: "glim-instance-main", children: [_jsxs("div", { className: "glim-instance-name", children: [_jsx("h3", { className: "glim-instance-title", children: name }), badges && _jsx("span", { className: "glim-instance-badges", children: badges })] }), eyebrow && _jsx("span", { className: "glim-eyebrow", children: eyebrow }), shown.length > 0 && _jsx("p", { className: "glim-instance-facts glim-num", children: shown.join(" · ") }), figures && figures.length > 0 && (_jsx("dl", { className: "glim-instance-figures", children: figures.map((f) => (_jsxs("div", { children: [_jsx("dt", { children: f.label }), _jsx("dd", { className: "glim-num", children: f.value })] }, f.label))) })), !children && acts] })] }), children && _jsx("div", { className: "glim-instance-body", children: children }), children && acts] }));
7
+ }
package/dist/Kbd.js CHANGED
@@ -2,5 +2,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // A key or a key combination as it is written on the keys, such as "Ctrl+K".
3
3
  // The words are the app's, so a German app writes "Strg".
4
4
  export function Kbd({ children, className }) {
5
- return _jsx("kbd", { className: className ? `glim-kbd ${className}` : "glim-kbd", children: children });
5
+ return _jsx("kbd", { "data-glim": "Kbd", className: className ? `glim-kbd ${className}` : "glim-kbd", children: children });
6
6
  }
package/dist/ListRow.js CHANGED
@@ -10,5 +10,5 @@ export function ListRow({ name, tip, mono, tile, badges, actions, className, onC
10
10
  e.currentTarget.click();
11
11
  }
12
12
  const classes = ["glim-list-row", onClick && "glim-list-row--opens", className].filter(Boolean).join(" ");
13
- return (_jsxs("div", { role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), _jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
13
+ return (_jsxs("div", { "data-glim": "ListRow", role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), _jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
14
14
  }
@@ -0,0 +1,21 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ListColumn, type ListTableText } from "@glimstone/core";
3
+ export type { ListColumn, ListTableText } from "@glimstone/core";
4
+ export interface ListTableProps<T extends object> {
5
+ /** The list's accessible name. */
6
+ label: string;
7
+ columns: readonly ListColumn[];
8
+ rows: readonly T[];
9
+ /** A key that stays with a row through sorting and filtering. */
10
+ rowKey: (row: T) => string;
11
+ /** The columns the search looks in; the first column by default. */
12
+ search?: readonly string[];
13
+ text: ListTableText;
14
+ /** Draws a cell of its own. Nothing returned shows the value. */
15
+ cell?: (row: T, column: ListColumn) => ReactNode;
16
+ /** Enter or a double click on a row: open its object. */
17
+ onOpen?: (row: T) => void;
18
+ /** The picked rows, in the list's order, after every change. */
19
+ onSelect?: (rows: T[]) => void;
20
+ }
21
+ export declare function ListTable<T extends object>({ label, columns, rows, rowKey, search, text, cell, onOpen, onSelect }: ListTableProps<T>): import("react").JSX.Element;
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { ariaSort, columnValues, listKey, listView, MARKS, nextSort, selectByClick, tableCellClass, } from "@glimstone/core";
4
+ import { Checkbox } from "./Checkbox.js";
5
+ import { MarkSvg } from "./glyphs.js";
6
+ import { Popover } from "./Popover.js";
7
+ export function ListTable({ label, columns, rows, rowKey, search, text, cell, onOpen, onSelect }) {
8
+ const [sort, setSort] = useState(null);
9
+ const [filters, setFilters] = useState({});
10
+ const [query, setQuery] = useState(null);
11
+ const [picked, setPicked] = useState({ keys: [], anchor: null, focus: null });
12
+ const [filterOpen, setFilterOpen] = useState(null);
13
+ const grid = useRef(null);
14
+ const searchField = useRef(null);
15
+ const hintId = useId();
16
+ const moved = useRef(false);
17
+ const searched = search ?? [columns[0].key];
18
+ const view = useMemo(() => listView(rows, { sort, filters, query: query ?? "", search: searched }), [rows, sort, filters, query, searched.join()]);
19
+ const keys = view.map(rowKey);
20
+ const at = (key) => (key === null ? -1 : keys.indexOf(key));
21
+ const selection = {
22
+ selected: keys.flatMap((k, i) => (picked.keys.includes(k) ? [i] : [])),
23
+ anchor: at(picked.anchor) < 0 ? null : at(picked.anchor),
24
+ focus: Math.max(0, at(picked.focus)),
25
+ };
26
+ function apply(next) {
27
+ const chosen = next.selected.map((i) => keys[i]);
28
+ setPicked({ keys: chosen, anchor: next.anchor === null ? null : keys[next.anchor], focus: keys[next.focus] ?? null });
29
+ moved.current = true;
30
+ onSelect?.(next.selected.map((i) => view[i]));
31
+ }
32
+ useLayoutEffect(() => {
33
+ if (!moved.current)
34
+ return;
35
+ moved.current = false;
36
+ grid.current?.querySelector(`tbody tr:nth-child(${selection.focus + 1}) > td`)?.focus();
37
+ });
38
+ useLayoutEffect(() => {
39
+ if (query !== null)
40
+ searchField.current?.focus();
41
+ }, [query !== null]);
42
+ function onKey(e) {
43
+ const action = listKey(selection, e.key, { toggle: e.ctrlKey || e.metaKey, range: e.shiftKey }, view.length);
44
+ if (!action || e.altKey)
45
+ return;
46
+ e.preventDefault();
47
+ if ("open" in action)
48
+ onOpen?.(view[action.open]);
49
+ else if ("search" in action)
50
+ setQuery((q) => (q ?? "") + action.search);
51
+ else
52
+ apply(action.select);
53
+ }
54
+ function onRowClick(e, i) {
55
+ apply(selectByClick(selection, i, { toggle: e.ctrlKey || e.metaKey, range: e.shiftKey }));
56
+ }
57
+ function closeSearch() {
58
+ setQuery(null);
59
+ moved.current = true;
60
+ }
61
+ const open = filterOpen && columns.find((c) => c.key === filterOpen.key);
62
+ const kept = (key) => filters[key] ?? [];
63
+ const flip = (key, value) => setFilters((f) => {
64
+ const now = f[key] ?? [];
65
+ return { ...f, [key]: now.includes(value) ? now.filter((v) => v !== value) : [...now, value] };
66
+ });
67
+ return (_jsxs("div", { "data-glim": "ListTable", className: "glim-list", children: [query !== null && (_jsx("input", { ref: searchField, className: "glim-input glim-list-search", type: "search", "aria-label": text.search, value: query, onChange: (e) => setQuery(e.target.value), onKeyDown: (e) => {
68
+ if (e.key === "Escape") {
69
+ e.preventDefault();
70
+ e.stopPropagation();
71
+ closeSearch();
72
+ }
73
+ } })), _jsxs("table", { ref: grid, role: "grid", "aria-label": label, "aria-multiselectable": "true", "aria-describedby": hintId, className: "glim-list-table", children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((c) => (_jsx("th", { scope: "col", "aria-sort": ariaSort(sort, c.key), className: c.end ? "glim-list-th glim-table-end" : "glim-list-th", children: _jsxs("span", { className: "glim-list-th-box", children: [_jsxs("button", { type: "button", className: "glim-list-sort", onClick: () => setSort((s) => nextSort(s, c.key)), children: [c.label, sort?.key === c.key && _jsx(MarkSvg, { mark: MARKS.expand, className: `glim-list-sort-mark glim-list-sort-mark--${sort.dir}` })] }), c.filter && (_jsx("button", { type: "button", "aria-label": text.filterOf(c.label), "aria-haspopup": "dialog", "aria-expanded": filterOpen?.key === c.key, "aria-pressed": kept(c.key).length > 0, className: "glim-list-filter", onClick: (e) => setFilterOpen(filterOpen?.key === c.key ? null : { key: c.key, at: e.currentTarget }), children: _jsx(MarkSvg, { mark: MARKS.expand }) }))] }) }, c.key))) }) }), _jsx("tbody", { onKeyDown: onKey, children: view.map((row, i) => (_jsx("tr", { "aria-selected": selection.selected.includes(i), className: "glim-list-tr", onClick: (e) => onRowClick(e, i), onDoubleClick: () => onOpen?.(row), children: columns.map((c, ci) => (_jsx("td", { tabIndex: ci === 0 ? (i === selection.focus ? 0 : -1) : undefined, className: tableCellClass(c) || undefined, children: cell?.(row, c) ?? String(row[c.key] ?? "") }, c.key))) }, keys[i]))) })] }), view.length === 0 && _jsx("p", { className: "glim-list-empty", children: text.noMatch }), _jsx("p", { id: hintId, className: "glim-list-hint", children: text.hint }), open && (_jsx(Popover, { open: true, anchor: filterOpen.at, label: text.filterOf(open.label), onClose: () => setFilterOpen(null), children: _jsx("div", { className: "glim-list-filter-values", children: columnValues(rows, open.key).map((v) => (_jsx(Checkbox, { label: v, checked: kept(open.key).includes(v), onChange: () => flip(open.key, v) }, v))) }) }))] }));
74
+ }
package/dist/MenuBar.js CHANGED
@@ -34,7 +34,7 @@ export function MenuBar({ label, menus, ref, className }) {
34
34
  show(at);
35
35
  }
36
36
  }
37
- return (_jsxs("div", { role: "menubar", "aria-label": label, className: className ? `glim-menubar ${className}` : "glim-menubar", children: [menus.map((m, i) => (_jsx("button", { ref: (el) => {
37
+ return (_jsxs("div", { "data-glim": "MenuBar", role: "menubar", "aria-label": label, className: className ? `glim-menubar ${className}` : "glim-menubar", children: [menus.map((m, i) => (_jsx("button", { ref: (el) => {
38
38
  buttons.current[i] = el;
39
39
  }, type: "button", role: "menuitem", "aria-haspopup": "menu", "aria-expanded": open?.at === i, tabIndex: i === stop ? 0 : -1, className: "glim-menubar-item", onClick: () => (open?.at === i ? setOpen(null) : show(i)), onMouseEnter: () => open && open.at !== i && show(i), onKeyDown: (e) => keys(e, i), onFocus: () => setStop(i), children: m.label }, i))), open && menus[open.at] && (_jsx(ContextMenu, { x: open.x, y: open.y, items: menus[open.at].items, label: menus[open.at].label, id: menus[open.at].id, opener: buttons.current[open.at], onClose: () => setOpen(null), onStep: (d) => show((open.at + d + count) % count) }, open.at))] }));
40
40
  }
package/dist/Meter.js CHANGED
@@ -5,5 +5,5 @@ export function Meter({ value, label, size = "medium", threshold, quiet, valueTe
5
5
  const view = meterView(value, { size, threshold, quiet });
6
6
  const tip = useTipBubble(valueText);
7
7
  const busy = view.percent === null;
8
- return (_jsxs(_Fragment, { children: [_jsx("span", { ref: tip.ref, ...tip.handlers, role: busy ? "progressbar" : "meter", "aria-label": label, "aria-valuemin": busy ? undefined : 0, "aria-valuemax": busy ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, "aria-busy": busy || undefined, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-meter-fill", style: view.width ? { width: view.width } : undefined }) }), tip.bubble] }));
8
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "data-glim": "Meter", ref: tip.ref, ...tip.handlers, role: busy ? "progressbar" : "meter", "aria-label": label, "aria-valuemin": busy ? undefined : 0, "aria-valuemax": busy ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, "aria-busy": busy || undefined, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-meter-fill", style: view.width ? { width: view.width } : undefined }) }), tip.bubble] }));
9
9
  }
@@ -10,7 +10,9 @@ export interface NumberFieldProps extends Omit<InputHTMLAttributes<HTMLInputElem
10
10
  onChange?: ChangeEventHandler<HTMLInputElement>;
11
11
  /** Classes for the input. A width set here has to be definite, since the
12
12
  * arrows sit against the input's end. */
13
+ /** Why the value cannot stand, as a line under the field until it is fixed. */
14
+ error?: string;
13
15
  className?: string;
14
16
  ref?: Ref<HTMLInputElement>;
15
17
  }
16
- export declare function NumberField({ className, ref, "aria-label": ariaLabel, ...rest }: NumberFieldProps): import("react").JSX.Element;
18
+ export declare function NumberField({ className, ref, error, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }: NumberFieldProps): import("react").JSX.Element;