@bigpixelrocket/uiok 0.2.3 → 0.3.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 (116) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/charts/Sparkline.d.ts +20 -0
  3. package/dist/charts/Sparkline.js +12 -0
  4. package/dist/charts/Sparkline.logic.d.ts +9 -0
  5. package/dist/charts/Sparkline.logic.js +27 -0
  6. package/dist/charts/charts.css +17 -0
  7. package/dist/charts/index.d.ts +2 -0
  8. package/dist/charts/index.js +2 -0
  9. package/dist/dialog/ConfirmDialog.d.ts +11 -1
  10. package/dist/dialog/ConfirmDialog.js +3 -2
  11. package/dist/dialog/ModalDialog.d.ts +8 -0
  12. package/dist/dialog/ModalDialog.js +4 -2
  13. package/dist/dialog/ProgressDialog.d.ts +34 -0
  14. package/dist/dialog/ProgressDialog.js +40 -0
  15. package/dist/dialog/TypedNameDialog.d.ts +36 -0
  16. package/dist/dialog/TypedNameDialog.js +17 -0
  17. package/dist/dialog/index.d.ts +5 -2
  18. package/dist/dialog/index.js +4 -1
  19. package/dist/field/Switch.d.ts +26 -0
  20. package/dist/field/Switch.js +20 -0
  21. package/dist/field/index.d.ts +3 -2
  22. package/dist/field/index.js +3 -2
  23. package/dist/frame/AppRoot.d.ts +44 -0
  24. package/dist/frame/AppRoot.js +26 -0
  25. package/dist/frame/Dock.d.ts +88 -0
  26. package/dist/frame/Dock.js +129 -0
  27. package/dist/frame/FilterChips.d.ts +28 -0
  28. package/dist/frame/FilterChips.js +14 -0
  29. package/dist/frame/PageParts.d.ts +69 -0
  30. package/dist/frame/PageParts.js +60 -0
  31. package/dist/frame/PaneSplit.d.ts +74 -0
  32. package/dist/frame/PaneSplit.js +197 -0
  33. package/dist/frame/SidebarResizer.d.ts +35 -0
  34. package/dist/frame/SidebarResizer.js +43 -0
  35. package/dist/frame/StatusNotice.d.ts +20 -0
  36. package/dist/frame/StatusNotice.js +13 -0
  37. package/dist/frame/Tree.d.ts +140 -0
  38. package/dist/frame/Tree.js +141 -0
  39. package/dist/frame/TreeToggle.d.ts +18 -0
  40. package/dist/frame/TreeToggle.js +17 -0
  41. package/dist/frame/WindowFrame.d.ts +57 -0
  42. package/dist/frame/WindowFrame.js +19 -0
  43. package/dist/frame/frame.css +801 -0
  44. package/dist/frame/index.d.ts +22 -0
  45. package/dist/frame/index.js +22 -0
  46. package/dist/frame/sharedRef.d.ts +8 -0
  47. package/dist/frame/sharedRef.js +26 -0
  48. package/dist/index.d.ts +3 -0
  49. package/dist/index.js +3 -0
  50. package/dist/labels/UiokLabels.d.ts +3 -0
  51. package/dist/labels/UiokLabels.js +3 -1
  52. package/dist/labels/dialog.d.ts +12 -0
  53. package/dist/labels/dialog.js +7 -1
  54. package/dist/labels/index.d.ts +1 -0
  55. package/dist/labels/index.js +1 -0
  56. package/dist/labels/settings.d.ts +46 -0
  57. package/dist/labels/settings.js +29 -0
  58. package/dist/listing/EmptyState.d.ts +40 -0
  59. package/dist/listing/EmptyState.js +14 -0
  60. package/dist/listing/index.d.ts +3 -1
  61. package/dist/listing/index.js +3 -1
  62. package/dist/listing/listing.css +66 -2
  63. package/dist/log/LogWell.d.ts +34 -0
  64. package/dist/log/LogWell.js +39 -0
  65. package/dist/log/LogWell.logic.d.ts +16 -0
  66. package/dist/log/LogWell.logic.js +26 -0
  67. package/dist/log/index.d.ts +8 -0
  68. package/dist/log/index.js +8 -0
  69. package/dist/log/log.css +57 -0
  70. package/dist/pane/Pane.d.ts +49 -0
  71. package/dist/pane/Pane.js +17 -0
  72. package/dist/pane/PaneKeys.d.ts +10 -3
  73. package/dist/pane/PaneKeys.js +26 -7
  74. package/dist/pane/index.d.ts +4 -2
  75. package/dist/pane/index.js +4 -2
  76. package/dist/pane/usePaneKeys.js +9 -11
  77. package/dist/shell/AboutWindow.d.ts +21 -0
  78. package/dist/shell/AboutWindow.js +10 -0
  79. package/dist/shell/LanguageChoice.d.ts +27 -0
  80. package/dist/shell/LanguageChoice.js +17 -0
  81. package/dist/shell/LoadFailure.d.ts +22 -0
  82. package/dist/shell/LoadFailure.js +15 -0
  83. package/dist/shell/Lockup.d.ts +52 -0
  84. package/dist/shell/Lockup.js +30 -0
  85. package/dist/shell/SettingsDialog.d.ts +97 -0
  86. package/dist/shell/SettingsDialog.js +219 -0
  87. package/dist/shell/SettingsDialog.logic.d.ts +33 -0
  88. package/dist/shell/SettingsDialog.logic.js +42 -0
  89. package/dist/shell/SettingsFiles.d.ts +55 -0
  90. package/dist/shell/SettingsFiles.js +30 -0
  91. package/dist/shell/SettingsPageKeys.d.ts +42 -0
  92. package/dist/shell/SettingsPageKeys.js +70 -0
  93. package/dist/shell/SettingsSubsection.d.ts +34 -0
  94. package/dist/shell/SettingsSubsection.js +30 -0
  95. package/dist/shell/SignIn.d.ts +61 -0
  96. package/dist/shell/SignIn.js +36 -0
  97. package/dist/shell/ThemePicker.d.ts +74 -0
  98. package/dist/shell/ThemePicker.js +96 -0
  99. package/dist/shell/ThemePicker.logic.d.ts +13 -0
  100. package/dist/shell/ThemePicker.logic.js +26 -0
  101. package/dist/shell/TitleBar.d.ts +44 -0
  102. package/dist/shell/TitleBar.js +23 -0
  103. package/dist/shell/UpdatePill.d.ts +26 -0
  104. package/dist/shell/UpdatePill.js +17 -0
  105. package/dist/shell/Updates.d.ts +99 -0
  106. package/dist/shell/Updates.js +72 -0
  107. package/dist/shell/index.d.ts +27 -0
  108. package/dist/shell/index.js +27 -0
  109. package/dist/shell/shell.css +243 -4
  110. package/dist/styles.css +2 -0
  111. package/dist/themes/catalog.js +4 -0
  112. package/dist/themes/themes.generated.css +244 -0
  113. package/dist/themes/tokens.d.ts +17 -5
  114. package/dist/themes/tokens.js +64 -1
  115. package/dist/tokens.css +11 -0
  116. package/package.json +1 -1
@@ -0,0 +1,219 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CircleAlert, Settings } from 'lucide-react';
3
+ import { Fragment, useEffect, useLayoutEffect, useRef, useState } from 'react';
4
+ import { Button } from '../button/Button.js';
5
+ import { ModalDialog } from '../dialog/ModalDialog.js';
6
+ import { ICON_MD } from '../icon/sizes.js';
7
+ import { useLabels } from '../labels/UiokProvider.js';
8
+ import { cutTooltip } from '../tooltip/Tooltip.logic.js';
9
+ import { spiedSubsection, subsectionScrollTop } from './SettingsDialog.logic.js';
10
+ import { SettingsPageKeysContext, settingsLegend } from './SettingsPageKeys.js';
11
+ import { SETTINGS_PAGE_HEAD_ATTRIBUTE, SETTINGS_REVEAL_ATTRIBUTE, SETTINGS_SUBSECTION_ATTRIBUTE } from './SettingsSubsection.js';
12
+ const DIALOG_LABEL_ID = 'settings-dialog-title';
13
+ const PAGE_TITLE_ID = 'settings-page-title';
14
+ /**
15
+ * Where each subsection drawn in the content column starts, in page order,
16
+ * less the height of a sticky page head, so a subsection reads as reaching
17
+ * the top once it reaches the head's lower edge.
18
+ */
19
+ const subsectionAnchors = (column) => {
20
+ const columnTop = column.getBoundingClientRect().top - column.scrollTop;
21
+ const head = column.querySelector(`[${SETTINGS_PAGE_HEAD_ATTRIBUTE}]`)?.offsetHeight ?? 0;
22
+ return [...column.querySelectorAll(`[${SETTINGS_SUBSECTION_ATTRIBUTE}]`)].map((section) => ({
23
+ id: section.getAttribute(SETTINGS_SUBSECTION_ATTRIBUTE) ?? '',
24
+ top: section.getBoundingClientRect().top - columnTop - head
25
+ }));
26
+ };
27
+ /**
28
+ * Opens a page's view: the column at its top, and, when the page marks a
29
+ * control to reveal (`SETTINGS_REVEAL_ATTRIBUTE`) that is not wholly in
30
+ * view there, the column scrolled to show it whole, resting where an edge
31
+ * starts at the page's top padding: the edge of the group that holds it
32
+ * where the column can scroll that far, else the nearest edge of a row in
33
+ * the group past the least scroll that shows the control. Where no edge
34
+ * fits because the page ends too soon, the page gains just the room at its
35
+ * foot that lets it rest on the nearest edge, so it never opens on a row
36
+ * half under the top fade. A control already in view moves nothing. Where
37
+ * the row above the group ends below that edge, it rests on that row's foot
38
+ * instead, so the first thing in view is whole. It measures in layout
39
+ * pixels (the column's rendered height over its layout height), since the
40
+ * dialog opens scaling up and a reselect runs at whatever frame that
41
+ * animation has reached.
42
+ */
43
+ function openPageView(column) {
44
+ column.style.paddingBlockEnd = '';
45
+ column.scrollTop = 0;
46
+ const chosen = column.querySelector(`[${SETTINGS_REVEAL_ATTRIBUTE}]`);
47
+ if (chosen === null)
48
+ return;
49
+ const view = column.getBoundingClientRect();
50
+ const scale = column.offsetHeight > 0 ? view.height / column.offsetHeight || 1 : 1;
51
+ const top = (element) => (element.getBoundingClientRect().top - view.top) / scale;
52
+ const bottom = (element) => (element.getBoundingClientRect().bottom - view.top) / scale;
53
+ const height = column.offsetHeight;
54
+ const cardTop = top(chosen);
55
+ const cardBottom = bottom(chosen);
56
+ if (cardTop >= 0 && cardBottom <= height)
57
+ return;
58
+ const inset = Number.parseFloat(getComputedStyle(column).paddingTop) || 0;
59
+ const group = chosen.closest('[role="radiogroup"]') ?? chosen;
60
+ const edge = (element) => top(element) - inset;
61
+ const margin = Number.parseFloat(getComputedStyle(chosen).scrollMarginBlockEnd) || 0;
62
+ const least = cardBottom + margin > height ? cardBottom + margin - height : cardTop - inset;
63
+ const range = column.scrollHeight - column.clientHeight;
64
+ const marginTop = Number.parseFloat(getComputedStyle(chosen).scrollMarginBlockStart) || 0;
65
+ const furthest = cardTop - Math.max(inset, marginTop);
66
+ const most = Math.min(range, furthest);
67
+ const reachable = [group, ...column.querySelectorAll('[role="radiogroup"] > *')]
68
+ .map(edge)
69
+ .filter((offset) => offset >= least && offset <= furthest)
70
+ .sort((left, right) => left - right);
71
+ const edges = reachable.filter((offset) => offset <= most);
72
+ const groupEdge = edge(group);
73
+ const chosenRest = groupEdge >= least && groupEdge <= most ? groupEdge : (edges[0] ?? reachable[0] ?? least);
74
+ // The foot of the row before the group: the lowest of the cells before
75
+ // the group's own cell in its grid that end above the group.
76
+ const cell = group.parentElement ?? group;
77
+ const groupTop = top(group);
78
+ let previousFoot = Number.NEGATIVE_INFINITY;
79
+ let previousCell = null;
80
+ for (let sibling = cell.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
81
+ const foot = bottom(sibling);
82
+ if (foot <= groupTop && foot > previousFoot) {
83
+ previousFoot = foot;
84
+ previousCell = sibling;
85
+ }
86
+ }
87
+ const lastLine = previousCell?.lastElementChild ?? previousCell;
88
+ const back = lastLine === null ? Number.NaN : top(lastLine) - inset;
89
+ let rest = chosenRest;
90
+ if (previousFoot > chosenRest && previousFoot < groupTop) {
91
+ if (previousFoot <= furthest) {
92
+ rest = previousFoot;
93
+ }
94
+ else if (back >= least && back < chosenRest) {
95
+ rest = back;
96
+ }
97
+ }
98
+ if (rest > range) {
99
+ const padding = Number.parseFloat(getComputedStyle(column).paddingBlockEnd) || 0;
100
+ column.style.paddingBlockEnd = `${padding + rest - range}px`;
101
+ }
102
+ column.scrollTop = rest;
103
+ chosen.scrollIntoView?.({ block: 'nearest' });
104
+ }
105
+ /** A press on a sidebar row leaves the focus where it was, as a list row's does. */
106
+ const keepFocus = (event) => event.preventDefault();
107
+ /**
108
+ * The sidebar: the pages under their headers, the chosen page unfolding its
109
+ * subsections on a rail, the one in view marked. Every row is a button in
110
+ * the Tab order that leaves the focus where it was when pressed.
111
+ */
112
+ function SettingsSidebar({ groups, page, subsectionId, onPage, onSubsection }) {
113
+ const labels = useLabels().settings;
114
+ return (_jsx("nav", { "aria-label": labels.sidebar, className: "settings-sidebar scroll-fade", children: groups.map((group) => (_jsxs("div", { "aria-labelledby": `settings-group-${group.id}`, className: "settings-sidebar-group", role: "group", children: [_jsx("span", { className: "settings-sidebar-header overline", id: `settings-group-${group.id}`, children: group.title }), group.pages.map((item) => (_jsxs(Fragment, { children: [_jsxs("button", { "aria-current": item.id === page.id ? 'page' : undefined, className: "settings-sidebar-page", "data-settings-page": item.id, onClick: () => onPage(item.id), onMouseDown: keepFocus, type: "button", children: [_jsx(item.Icon, { "aria-hidden": true, size: ICON_MD }), _jsx("span", { ...cutTooltip(item.title), children: item.title }), item.chip ? _jsx("span", { className: "settings-sidebar-chip", children: item.chip }) : null] }), item.id === page.id && item.subsections.length > 0 ? (_jsx("div", { className: "settings-sidebar-subsections", children: item.subsections.map((subsection) => (_jsx("button", { "aria-current": subsection.id === subsectionId ? 'location' : undefined, className: "settings-sidebar-subsection", onClick: () => onSubsection(subsection.id), onMouseDown: keepFocus, type: "button", ...cutTooltip(subsection.title), children: subsection.title }, subsection.id))) })) : null] }, item.id)))] }, group.id))) }));
115
+ }
116
+ /**
117
+ * The Settings dialog: a fixed frame on the frosted wash, the sidebar of
118
+ * pages at its left, and the chosen page in a column that scrolls beside
119
+ * it. It opens on the page a request names, or on the first page, and keeps
120
+ * the chosen one until it closes or a new request names another
121
+ * (`pageRequest`). The title strip says Settings alone; the page's name
122
+ * heads its content, and the sidebar marks the page and the subsection in
123
+ * view, following the column's scroll. Every control applies its change at
124
+ * once, so there is nothing to commit: the legend's one verb is Done on
125
+ * Return, which Escape runs too, and a focused field, pop-up menu, or
126
+ * button keeps Return. A page that has keys of its own takes the legend and
127
+ * Escape over while it shows (`useSettingsPageKeys`) and gives them back
128
+ * when it goes. A new page starts at its top, its first subsection marked,
129
+ * and shows whole the control it marks to reveal.
130
+ */
131
+ export function SettingsDialog({ groups, pageRequest = null, onPageShown, notice, icon = Settings, onClose }) {
132
+ const labels = useLabels().settings;
133
+ const pages = groups.flatMap((group) => group.pages);
134
+ const [pageId, setPageId] = useState(pageRequest?.pageId ?? pages[0]?.id);
135
+ const [requestSeq, setRequestSeq] = useState(pageRequest?.seq);
136
+ if (pageRequest && pageRequest.seq !== requestSeq) {
137
+ setRequestSeq(pageRequest.seq);
138
+ setPageId(pageRequest.pageId);
139
+ }
140
+ const page = pages.find((candidate) => candidate.id === pageId) ?? pages[0];
141
+ if (page === undefined) {
142
+ throw new Error('SettingsDialog needs at least one page.');
143
+ }
144
+ useEffect(() => {
145
+ onPageShown?.(page.id);
146
+ }, [onPageShown, page.id]);
147
+ const [subsectionId, setSubsectionId] = useState(null);
148
+ const columnRef = useRef(null);
149
+ // Set while the column scrolls to the subsection a sidebar row chose, so
150
+ // that scroll keeps the choice marked even where the column cannot bring
151
+ // it to the top.
152
+ const chosenScrollRef = useRef(false);
153
+ // A row press leaves the focus where it was, so a control the old page
154
+ // held is gone with it: the dialog takes the focus back, or Escape and
155
+ // Tab would stop reaching it.
156
+ useLayoutEffect(() => {
157
+ const column = columnRef.current;
158
+ if (column) {
159
+ const dialog = column.closest('[role="dialog"]');
160
+ if (dialog && !dialog.contains(dialog.ownerDocument.activeElement)) {
161
+ dialog.focus({ preventScroll: true });
162
+ }
163
+ openPageView(column);
164
+ chosenScrollRef.current = false;
165
+ setSubsectionId(spiedSubsection(subsectionAnchors(column), column));
166
+ }
167
+ }, [page.id]);
168
+ // A page that adds or drops subsections as it is used moves the one in
169
+ // view without a scroll, so the mark follows the page's content too.
170
+ useLayoutEffect(() => {
171
+ const column = columnRef.current;
172
+ if (!column || typeof MutationObserver === 'undefined') {
173
+ return undefined;
174
+ }
175
+ const observer = new MutationObserver(() => {
176
+ if (!chosenScrollRef.current) {
177
+ setSubsectionId(spiedSubsection(subsectionAnchors(column), column));
178
+ }
179
+ });
180
+ observer.observe(column, { childList: true, subtree: true });
181
+ return () => observer.disconnect();
182
+ }, [page.id]);
183
+ const handleScroll = () => {
184
+ const column = columnRef.current;
185
+ if (chosenScrollRef.current) {
186
+ chosenScrollRef.current = false;
187
+ }
188
+ else if (column) {
189
+ setSubsectionId(spiedSubsection(subsectionAnchors(column), column));
190
+ }
191
+ };
192
+ const choosePage = (id) => {
193
+ if (id === page.id && columnRef.current) {
194
+ openPageView(columnRef.current);
195
+ }
196
+ setPageId(id);
197
+ };
198
+ const showSubsection = (id) => {
199
+ const column = columnRef.current;
200
+ const top = column ? subsectionScrollTop(subsectionAnchors(column), id) : null;
201
+ setSubsectionId(id);
202
+ if (column && top !== null) {
203
+ const before = column.scrollTop;
204
+ column.scrollTop = top;
205
+ chosenScrollRef.current = column.scrollTop !== before;
206
+ }
207
+ };
208
+ const [pageKeys, setPageKeys] = useState(null);
209
+ return (_jsx(ModalDialog, { className: "settings-dialog", frosted: true, icon: icon, labelId: DIALOG_LABEL_ID, legend: settingsLegend(pageKeys, onClose, labels.done), onCancel: pageKeys?.onLeave ?? onClose, title: labels.title, children: _jsxs("div", { className: "settings-dialog-body", children: [_jsx(SettingsSidebar, { groups: groups, onPage: choosePage, onSubsection: showSubsection, page: page, subsectionId: subsectionId }), _jsxs("div", { className: "settings-column", children: [notice?.(page.id, choosePage), _jsxs("section", { "aria-labelledby": PAGE_TITLE_ID, className: page.fills ? 'settings-page scroll-fade fills' : 'settings-page scroll-fade', onScroll: handleScroll, ref: columnRef, children: [_jsx("h3", { className: "settings-page-title", id: PAGE_TITLE_ID, children: page.title }), _jsx(SettingsPageKeysContext.Provider, { value: setPageKeys, children: _jsx(Fragment, { children: page.body }, page.id) })] })] })] }) }));
210
+ }
211
+ /**
212
+ * A change a settings file could not take, over the Settings page column
213
+ * (`SettingsDialog`'s `notice`), outside the page's scroll so it stays in
214
+ * view however far the page is scrolled: a danger notice, its words
215
+ * announced, and a verb that turns to the page that lists it.
216
+ */
217
+ export function SettingsSaveFailure({ message, action = null }) {
218
+ return (_jsxs("div", { className: "settings-save-failure notice notice-danger", children: [_jsx(CircleAlert, { "aria-hidden": true, size: ICON_MD }), _jsx("p", { className: "notice-text", role: "alert", children: message }), action === null ? null : (_jsx("div", { className: "notice-actions", children: _jsx(Button, { onClick: action.onRun, size: "small", children: action.label }) }))] }));
219
+ }
@@ -0,0 +1,33 @@
1
+ /** Where a subsection starts, in pixels from the top of the scrolled content. */
2
+ export interface SubsectionAnchor {
3
+ readonly id: string;
4
+ readonly top: number;
5
+ }
6
+ /** A Settings page column's scroll state. */
7
+ export interface SettingsScrollView {
8
+ readonly scrollTop: number;
9
+ readonly clientHeight: number;
10
+ readonly scrollHeight: number;
11
+ }
12
+ /**
13
+ * How far below the column's top edge a subsection's start may sit and
14
+ * still count as the one in view: the column's top padding and some slack,
15
+ * so the subsection a sidebar click scrolled to is the one marked.
16
+ */
17
+ export declare const SUBSECTION_SPY_SLACK_PX = 24;
18
+ /** The column's top padding, which a subsection keeps above it once scrolled to. */
19
+ export declare const SUBSECTION_SCROLL_INSET_PX = 14;
20
+ /**
21
+ * The subsection the sidebar marks as in view: the last one whose start has
22
+ * reached the column's top edge, or the last of all once the column is
23
+ * scrolled to its end (a short last subsection never reaches the top). A
24
+ * page that cannot scroll, or one not yet scrolled past its title, marks
25
+ * its first. Null when the page has no subsections.
26
+ */
27
+ export declare function spiedSubsection(anchors: readonly SubsectionAnchor[], view: SettingsScrollView): string | null;
28
+ /**
29
+ * Where to scroll the column to show a subsection: the top for the first,
30
+ * so the page title stays in view, and otherwise the subsection's start
31
+ * under the column's top padding. Null for an id the page does not draw.
32
+ */
33
+ export declare function subsectionScrollTop(anchors: readonly SubsectionAnchor[], id: string): number | null;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * How far below the column's top edge a subsection's start may sit and
3
+ * still count as the one in view: the column's top padding and some slack,
4
+ * so the subsection a sidebar click scrolled to is the one marked.
5
+ */
6
+ export const SUBSECTION_SPY_SLACK_PX = 24;
7
+ /** The column's top padding, which a subsection keeps above it once scrolled to. */
8
+ export const SUBSECTION_SCROLL_INSET_PX = 14;
9
+ /**
10
+ * The subsection the sidebar marks as in view: the last one whose start has
11
+ * reached the column's top edge, or the last of all once the column is
12
+ * scrolled to its end (a short last subsection never reaches the top). A
13
+ * page that cannot scroll, or one not yet scrolled past its title, marks
14
+ * its first. Null when the page has no subsections.
15
+ */
16
+ export function spiedSubsection(anchors, view) {
17
+ const first = anchors[0];
18
+ if (!first) {
19
+ return null;
20
+ }
21
+ if (view.scrollHeight <= view.clientHeight + 1) {
22
+ return first.id;
23
+ }
24
+ if (view.scrollTop + view.clientHeight >= view.scrollHeight - 1) {
25
+ return anchors.at(-1)?.id ?? first.id;
26
+ }
27
+ const passed = anchors.filter((anchor) => anchor.top <= view.scrollTop + SUBSECTION_SPY_SLACK_PX);
28
+ return passed.at(-1)?.id ?? first.id;
29
+ }
30
+ /**
31
+ * Where to scroll the column to show a subsection: the top for the first,
32
+ * so the page title stays in view, and otherwise the subsection's start
33
+ * under the column's top padding. Null for an id the page does not draw.
34
+ */
35
+ export function subsectionScrollTop(anchors, id) {
36
+ const index = anchors.findIndex((anchor) => anchor.id === id);
37
+ const anchor = anchors[index];
38
+ if (!anchor) {
39
+ return null;
40
+ }
41
+ return index === 0 ? 0 : Math.max(0, anchor.top - SUBSECTION_SCROLL_INSET_PX);
42
+ }
@@ -0,0 +1,55 @@
1
+ import type { ReactElement } from 'react';
2
+ /**
3
+ * Runs a host request a row's button makes, and keeps the failure it
4
+ * answers: a message to show under the row, or null when it went through.
5
+ */
6
+ export type SettingsFileRequest = () => Promise<string | null>;
7
+ /** One problem in a settings file. */
8
+ export interface SettingsFileProblem {
9
+ /** A mistake (`problem`) or a note about a value the app adjusted (`note`). */
10
+ readonly kind: 'problem' | 'note';
11
+ /** Where it is ("Line 12"); null where the file as a whole is at fault. */
12
+ readonly place: string | null;
13
+ /** The key it is about, set in the code face; null for none. */
14
+ readonly key: string | null;
15
+ readonly message: string;
16
+ }
17
+ /** One settings file the app reads. */
18
+ export interface SettingsFileEntry {
19
+ /** The file's name ("settings.toml"). */
20
+ readonly name: string;
21
+ /** Its state in a few words ("Read 2 minutes ago", "Not created yet"). */
22
+ readonly summary: string;
23
+ /** Opens the file in the system's editor; none while the file does not exist. */
24
+ readonly onOpen?: SettingsFileRequest;
25
+ /** Its problems in line order. */
26
+ readonly problems: readonly SettingsFileProblem[];
27
+ /** The problem list's accessible name ("Problems in settings.toml"). */
28
+ readonly problemsLabel: string;
29
+ }
30
+ /** Props for {@link SettingsFiles}. */
31
+ export interface SettingsFilesProps {
32
+ /** The folder row's label ("Folder"). */
33
+ readonly folderLabel: string;
34
+ /** What the folder is, the label's tooltip. */
35
+ readonly folderHelp?: string;
36
+ /** The folder's path, selectable, cut with an ellipsis. */
37
+ readonly folder: string;
38
+ /** The verb that shows the folder ("Show in Finder"). */
39
+ readonly showFolderLabel: string;
40
+ readonly onShowFolder: SettingsFileRequest;
41
+ /** Why the folder cannot be used; null when it can. */
42
+ readonly folderProblem?: string | null;
43
+ /** The open verb on each file's row ("Open"). */
44
+ readonly openLabel: string;
45
+ readonly files: readonly SettingsFileEntry[];
46
+ }
47
+ /**
48
+ * A Files page of Settings: the settings folder with a verb that shows it,
49
+ * then each file the app reads there, with Open and its problems under it
50
+ * (where, which key, what is wrong), on the label column every page shares.
51
+ * A request the host refuses shows its message under its row. Problems show
52
+ * only here; the host keeps the page current while it is open, so a fix
53
+ * made in an editor clears its problem as soon as the file is saved.
54
+ */
55
+ export declare function SettingsFiles({ folderLabel, folderHelp, folder, showFolderLabel, onShowFolder, folderProblem, openLabel, files }: SettingsFilesProps): ReactElement;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { CircleAlert, FolderOpen, Info, SquarePen } from 'lucide-react';
3
+ import { useState } from 'react';
4
+ import { Button } from '../button/Button.js';
5
+ import { labelHelp } from '../field/labelHelp.js';
6
+ import { ICON_MD, ICON_SM } from '../icon/sizes.js';
7
+ /** A request's failure under its row, or nothing. */
8
+ function Failure({ message }) {
9
+ return message === null ? null : (_jsx("p", { className: "field-problem", role: "alert", children: message }));
10
+ }
11
+ /** One file: its name, its state and Open, and its problems under it. */
12
+ function SettingsFileRow({ file, openLabel }) {
13
+ const [failure, setFailure] = useState(null);
14
+ const open = file.onOpen;
15
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: "field-label settings-file-name", children: file.name }), _jsxs("div", { className: "field-value", children: [_jsxs("div", { className: "field-option", children: [_jsx("span", { className: "settings-file-summary", children: file.summary }), open === undefined ? null : (_jsxs(Button, { onClick: () => void open().then(setFailure), size: "small", children: [_jsx(SquarePen, { "aria-hidden": true, size: ICON_SM }), openLabel] }))] }), file.problems.length > 0 ? (_jsx("ul", { "aria-label": file.problemsLabel, className: "settings-file-problems", children: file.problems.map((problem, index) => (_jsxs("li", { className: problem.kind === 'note'
16
+ ? 'settings-file-problem notice note'
17
+ : 'settings-file-problem notice notice-danger', children: [problem.kind === 'note' ? (_jsx(Info, { "aria-hidden": true, size: ICON_MD })) : (_jsx(CircleAlert, { "aria-hidden": true, size: ICON_MD })), _jsxs("span", { className: "notice-text settings-file-problem-text", children: [problem.place === null && problem.key === null ? null : (_jsxs("span", { className: "settings-file-problem-place", children: [problem.place, problem.place !== null && problem.key !== null ? ' · ' : null, problem.key === null ? null : _jsx("code", { children: problem.key })] })), _jsx("span", { children: problem.message })] })] }, index))) })) : null, _jsx(Failure, { message: failure })] })] }));
18
+ }
19
+ /**
20
+ * A Files page of Settings: the settings folder with a verb that shows it,
21
+ * then each file the app reads there, with Open and its problems under it
22
+ * (where, which key, what is wrong), on the label column every page shares.
23
+ * A request the host refuses shows its message under its row. Problems show
24
+ * only here; the host keeps the page current while it is open, so a fix
25
+ * made in an editor clears its problem as soon as the file is saved.
26
+ */
27
+ export function SettingsFiles({ folderLabel, folderHelp, folder, showFolderLabel, onShowFolder, folderProblem = null, openLabel, files }) {
28
+ const [failure, setFailure] = useState(null);
29
+ return (_jsxs("div", { className: "field-grid", children: [_jsx("span", { className: "field-label", ...labelHelp(folderHelp).label, children: folderLabel }), _jsxs("div", { className: "field-value", children: [_jsxs("div", { className: "field-option", children: [_jsx("code", { className: "settings-file-path", children: folder }), _jsxs(Button, { onClick: () => void onShowFolder().then(setFailure), size: "small", children: [_jsx(FolderOpen, { "aria-hidden": true, size: ICON_SM }), showFolderLabel] })] }), folderProblem === null ? null : _jsx("p", { className: "field-problem", children: folderProblem }), _jsx(Failure, { message: failure })] }), files.map((file) => (_jsx(SettingsFileRow, { file: file, openLabel: openLabel }, file.name)))] }));
30
+ }
@@ -0,0 +1,42 @@
1
+ import { type DialogLegendModel } from '../dialog/DialogLegend.logic.js';
2
+ /**
3
+ * The keys a Settings page takes over while it shows: the legend it draws
4
+ * in place of the dialog's Done, and what Escape does instead of closing
5
+ * the dialog.
6
+ */
7
+ export interface SettingsPageKeys {
8
+ readonly legend: DialogLegendModel;
9
+ /**
10
+ * True while the page has nothing of its own for Return (a cursor on a
11
+ * locked row, a find that shows no row): the dialog's Done stands as the
12
+ * legend's primary, and Return runs it from anywhere, a find field
13
+ * included. The legend then names no primary of its own.
14
+ */
15
+ readonly done?: boolean;
16
+ /**
17
+ * What Escape, the leave slot, and a press outside the dialog run (Clear a
18
+ * find, Cancel a recording); null leaves them closing the dialog.
19
+ */
20
+ readonly onLeave: (() => void) | null;
21
+ }
22
+ /**
23
+ * Where a page hands its keys to `SettingsDialog`, which provides it around
24
+ * the page it shows; null gives the dialog's own keys back. The default
25
+ * drops them, so a page rendered on its own still works.
26
+ */
27
+ export declare const SettingsPageKeysContext: import("react").Context<(keys: SettingsPageKeys | null) => void>;
28
+ /**
29
+ * The Settings dialog's legend while `keys` show, or its own with none:
30
+ * `done` (the dialog's Done) on Return, which a focused field, pop-up menu,
31
+ * or button keeps, since every control applies at once; the page's legend
32
+ * while it shows one, with Done as its primary when the page says Return
33
+ * is Done.
34
+ */
35
+ export declare function settingsLegend(keys: SettingsPageKeys | null, onDone: () => void, done: string): DialogLegendModel;
36
+ /**
37
+ * Hands a page's keys to `SettingsDialog` while the page is mounted, and
38
+ * gives the dialog its own back when it unmounts. The page may build
39
+ * `keys` afresh on every render: the dialog redraws only when the legend's
40
+ * slots or the leave choice change, and every verb runs the latest handler.
41
+ */
42
+ export declare function useSettingsPageKeys(keys: SettingsPageKeys): void;
@@ -0,0 +1,70 @@
1
+ import { createContext, useContext, useLayoutEffect, useRef } from 'react';
2
+ import { legendSignature } from '../dialog/DialogLegend.logic.js';
3
+ /**
4
+ * Where a page hands its keys to `SettingsDialog`, which provides it around
5
+ * the page it shows; null gives the dialog's own keys back. The default
6
+ * drops them, so a page rendered on its own still works.
7
+ */
8
+ export const SettingsPageKeysContext = createContext(() => { });
9
+ /**
10
+ * The keys with every verb running the latest model's: the dialog holds one
11
+ * model per legend drawn, while the page's handlers change on each render.
12
+ */
13
+ function relayed(latest) {
14
+ const { legend, onLeave } = latest.current;
15
+ const slot = (chosen, index) => ({
16
+ ...chosen,
17
+ onRun: () => latest.current.legend.secondary?.[index]?.onRun()
18
+ });
19
+ const primary = legend.primary
20
+ ? { primary: { ...legend.primary, onRun: () => latest.current.legend.primary?.onRun() } }
21
+ : {};
22
+ const [first, second] = legend.secondary ?? [];
23
+ const relayedLegend = {
24
+ ...(legend.leave === undefined ? {} : { leave: legend.leave }),
25
+ secondary: first === undefined
26
+ ? []
27
+ : second === undefined
28
+ ? [slot(first, 0)]
29
+ : [slot(first, 0), slot(second, 1)],
30
+ ...primary
31
+ };
32
+ return {
33
+ legend: relayedLegend,
34
+ ...(latest.current.done === true ? { done: true } : {}),
35
+ onLeave: onLeave === null ? null : () => latest.current.onLeave?.()
36
+ };
37
+ }
38
+ /**
39
+ * The Settings dialog's legend while `keys` show, or its own with none:
40
+ * `done` (the dialog's Done) on Return, which a focused field, pop-up menu,
41
+ * or button keeps, since every control applies at once; the page's legend
42
+ * while it shows one, with Done as its primary when the page says Return
43
+ * is Done.
44
+ */
45
+ export function settingsLegend(keys, onDone, done) {
46
+ if (keys === null) {
47
+ return { primary: { label: done, onRun: onDone, yieldsReturn: true } };
48
+ }
49
+ return keys.done === true
50
+ ? { ...keys.legend, primary: { label: done, onRun: onDone } }
51
+ : keys.legend;
52
+ }
53
+ /**
54
+ * Hands a page's keys to `SettingsDialog` while the page is mounted, and
55
+ * gives the dialog its own back when it unmounts. The page may build
56
+ * `keys` afresh on every render: the dialog redraws only when the legend's
57
+ * slots or the leave choice change, and every verb runs the latest handler.
58
+ */
59
+ export function useSettingsPageKeys(keys) {
60
+ const publish = useContext(SettingsPageKeysContext);
61
+ const latest = useRef(keys);
62
+ const signature = `${legendSignature(keys.legend)}|${keys.onLeave === null ? 'close' : 'page'}|${keys.done === true ? 'done' : ''}`;
63
+ useLayoutEffect(() => {
64
+ latest.current = keys;
65
+ });
66
+ useLayoutEffect(() => {
67
+ publish(relayed(latest));
68
+ }, [publish, signature]);
69
+ useLayoutEffect(() => () => publish(null), [publish]);
70
+ }
@@ -0,0 +1,34 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /**
3
+ * The attribute that marks a subsection of a Settings page, carrying its
4
+ * id; `SettingsDialog` finds the subsections by it to scroll to one and to
5
+ * follow the one in view.
6
+ */
7
+ export declare const SETTINGS_SUBSECTION_ATTRIBUTE = "data-settings-subsection";
8
+ /**
9
+ * The attribute that marks a page's sticky head (a find field and its
10
+ * tools, pinned at the top of the column while the subsections scroll
11
+ * under it); `SettingsDialog` counts its height, so a subsection it scrolls
12
+ * to, or marks as in view, starts below the head rather than under it.
13
+ */
14
+ export declare const SETTINGS_PAGE_HEAD_ATTRIBUTE = "data-settings-page-head";
15
+ /**
16
+ * The attribute that marks the control a page brings into view as it opens
17
+ * (the theme in use on Appearance), when it is not wholly in view at the
18
+ * page's top.
19
+ */
20
+ export declare const SETTINGS_REVEAL_ATTRIBUTE = "data-settings-reveal";
21
+ /** Props for {@link SettingsSubsection}. */
22
+ export interface SettingsSubsectionProps {
23
+ /** The id the page lists in its `subsections`. */
24
+ readonly id: string;
25
+ readonly title: string;
26
+ /** The rows: a `field-grid` on the label column every page shares. */
27
+ readonly children: ReactNode;
28
+ }
29
+ /**
30
+ * One subsection of a Settings page: its name as an overline over its rows,
31
+ * with a hairline between subsections, marked so `SettingsDialog`'s sidebar
32
+ * can scroll to it and follow it.
33
+ */
34
+ export declare function SettingsSubsection({ id, title, children }: SettingsSubsectionProps): ReactElement;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from 'react';
3
+ /**
4
+ * The attribute that marks a subsection of a Settings page, carrying its
5
+ * id; `SettingsDialog` finds the subsections by it to scroll to one and to
6
+ * follow the one in view.
7
+ */
8
+ export const SETTINGS_SUBSECTION_ATTRIBUTE = 'data-settings-subsection';
9
+ /**
10
+ * The attribute that marks a page's sticky head (a find field and its
11
+ * tools, pinned at the top of the column while the subsections scroll
12
+ * under it); `SettingsDialog` counts its height, so a subsection it scrolls
13
+ * to, or marks as in view, starts below the head rather than under it.
14
+ */
15
+ export const SETTINGS_PAGE_HEAD_ATTRIBUTE = 'data-settings-page-head';
16
+ /**
17
+ * The attribute that marks the control a page brings into view as it opens
18
+ * (the theme in use on Appearance), when it is not wholly in view at the
19
+ * page's top.
20
+ */
21
+ export const SETTINGS_REVEAL_ATTRIBUTE = 'data-settings-reveal';
22
+ /**
23
+ * One subsection of a Settings page: its name as an overline over its rows,
24
+ * with a hairline between subsections, marked so `SettingsDialog`'s sidebar
25
+ * can scroll to it and follow it.
26
+ */
27
+ export function SettingsSubsection({ id, title, children }) {
28
+ const headingId = useId();
29
+ return (_jsxs("section", { "aria-labelledby": headingId, className: "settings-subsection", [SETTINGS_SUBSECTION_ATTRIBUTE]: id, children: [_jsx("h4", { className: "settings-subsection-title overline", id: headingId, children: title }), children] }));
30
+ }
@@ -0,0 +1,61 @@
1
+ import { type LucideIcon } from 'lucide-react';
2
+ import { type ReactElement, type ReactNode } from 'react';
3
+ import type { DialogItem } from '../dialog/DialogLists.js';
4
+ /** A fact row a sign-in opens with: where (Server) and who (Account, Key file). */
5
+ export interface SignInFact {
6
+ readonly label: string;
7
+ readonly value: string;
8
+ }
9
+ /** Props for {@link SignInDialog}. */
10
+ export interface SignInDialogProps {
11
+ /** The title: "Sign In", never the host's name. */
12
+ readonly title: string;
13
+ /** The verb on Return ("Sign In"). */
14
+ readonly confirmLabel: string;
15
+ /** Where and who, as fact rows before the field. */
16
+ readonly facts: readonly SignInFact[];
17
+ /** The field's one-word label ("Password", "Passphrase"). */
18
+ readonly secretLabel: string;
19
+ /** Why it asks again after a refusal ("That password was not accepted."); null on a first ask. */
20
+ readonly rejection?: string | null;
21
+ /** Whether the typed value may be sent; any non-empty value unless given. */
22
+ readonly accepts?: (value: string) => boolean;
23
+ /** What goes under the field (a Save in Keychain choice). */
24
+ readonly children?: ReactNode;
25
+ /** The title strip's glyph; a key unless given. */
26
+ readonly icon?: LucideIcon;
27
+ readonly onSubmit: (value: string) => void;
28
+ readonly onCancel: () => void;
29
+ }
30
+ /**
31
+ * One password or passphrase, asked in the dialog frame: fact rows for
32
+ * where and who, then the field's one-word label beside one secure field,
33
+ * and why it asks again when it does, on one label column. Return signs in
34
+ * and Escape cancels. The value lives in this field alone and leaves only
35
+ * as the answer; the field takes the focus once the dialog is up.
36
+ */
37
+ export declare function SignInDialog({ title, confirmLabel, facts, secretLabel, rejection, accepts, children, icon, onSubmit, onCancel }: SignInDialogProps): ReactElement;
38
+ /** Props for {@link HostKeyDialog}. */
39
+ export interface HostKeyDialogProps {
40
+ /** At most five words ("Trust Host Key?"). */
41
+ readonly title: string;
42
+ /** Why it asks and when to trust the key. */
43
+ readonly message: ReactNode;
44
+ /** The verb ("Trust"). */
45
+ readonly confirmLabel: string;
46
+ /** The host, as the confirmation's one item (its saved name as the detail). */
47
+ readonly host: DialogItem;
48
+ /** The key's type ("ED25519"). */
49
+ readonly keyType: string;
50
+ /** The key's whole fingerprint, selectable. */
51
+ readonly fingerprint: string;
52
+ readonly onTrust: () => void;
53
+ readonly onCancel: () => void;
54
+ }
55
+ /**
56
+ * A host key the computer has not seen before, as a confirmation read at a
57
+ * glance: the lead says why it asks and when to trust it, the host is the
58
+ * one item, and then the key's type and its whole fingerprint in a framed
59
+ * well. The verb answers yes, Cancel no.
60
+ */
61
+ export declare function HostKeyDialog({ title, message, confirmLabel, host, keyType, fingerprint, onTrust, onCancel }: HostKeyDialogProps): ReactElement;