@bigpixelrocket/uiok 0.2.2 → 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.
- package/CHANGELOG.md +62 -1
- package/dist/button/TextLink.d.ts +27 -0
- package/dist/button/TextLink.js +15 -0
- package/dist/button/button.css +48 -0
- package/dist/button/index.d.ts +2 -1
- package/dist/button/index.js +2 -1
- package/dist/charts/Sparkline.d.ts +20 -0
- package/dist/charts/Sparkline.js +12 -0
- package/dist/charts/Sparkline.logic.d.ts +9 -0
- package/dist/charts/Sparkline.logic.js +27 -0
- package/dist/charts/charts.css +17 -0
- package/dist/charts/index.d.ts +2 -0
- package/dist/charts/index.js +2 -0
- package/dist/dialog/ConfirmDialog.d.ts +17 -1
- package/dist/dialog/ConfirmDialog.js +10 -4
- package/dist/dialog/DialogLists.d.ts +8 -1
- package/dist/dialog/DialogLists.js +3 -2
- package/dist/dialog/ModalDialog.d.ts +8 -0
- package/dist/dialog/ModalDialog.js +4 -2
- package/dist/dialog/ProgressDialog.d.ts +34 -0
- package/dist/dialog/ProgressDialog.js +40 -0
- package/dist/dialog/TypedNameDialog.d.ts +36 -0
- package/dist/dialog/TypedNameDialog.js +17 -0
- package/dist/dialog/index.d.ts +5 -2
- package/dist/dialog/index.js +4 -1
- package/dist/field/Switch.d.ts +26 -0
- package/dist/field/Switch.js +20 -0
- package/dist/field/field.css +110 -2
- package/dist/field/index.d.ts +3 -2
- package/dist/field/index.js +3 -2
- package/dist/filter/filter.css +16 -0
- package/dist/frame/AppRoot.d.ts +44 -0
- package/dist/frame/AppRoot.js +26 -0
- package/dist/frame/Dock.d.ts +88 -0
- package/dist/frame/Dock.js +129 -0
- package/dist/frame/FilterChips.d.ts +28 -0
- package/dist/frame/FilterChips.js +14 -0
- package/dist/frame/PageParts.d.ts +69 -0
- package/dist/frame/PageParts.js +60 -0
- package/dist/frame/PaneSplit.d.ts +74 -0
- package/dist/frame/PaneSplit.js +197 -0
- package/dist/frame/SidebarResizer.d.ts +35 -0
- package/dist/frame/SidebarResizer.js +43 -0
- package/dist/frame/StatusNotice.d.ts +20 -0
- package/dist/frame/StatusNotice.js +13 -0
- package/dist/frame/Tree.d.ts +140 -0
- package/dist/frame/Tree.js +141 -0
- package/dist/frame/TreeToggle.d.ts +18 -0
- package/dist/frame/TreeToggle.js +17 -0
- package/dist/frame/WindowFrame.d.ts +57 -0
- package/dist/frame/WindowFrame.js +19 -0
- package/dist/frame/frame.css +801 -0
- package/dist/frame/index.d.ts +22 -0
- package/dist/frame/index.js +22 -0
- package/dist/frame/sharedRef.d.ts +8 -0
- package/dist/frame/sharedRef.js +26 -0
- package/dist/grid/DataGrid.d.ts +10 -2
- package/dist/grid/DataGrid.js +47 -13
- package/dist/grid/DataGrid.logic.d.ts +16 -0
- package/dist/grid/DataGrid.logic.js +28 -0
- package/dist/grid/grid.css +128 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/labels/UiokLabels.d.ts +6 -0
- package/dist/labels/UiokLabels.js +5 -1
- package/dist/labels/dialog.d.ts +12 -0
- package/dist/labels/dialog.js +7 -1
- package/dist/labels/index.d.ts +2 -0
- package/dist/labels/index.js +2 -0
- package/dist/labels/keys.js +2 -0
- package/dist/labels/paneTabs.d.ts +27 -0
- package/dist/labels/paneTabs.js +10 -0
- package/dist/labels/selectAll.d.ts +4 -1
- package/dist/labels/selectAll.js +1 -1
- package/dist/labels/settings.d.ts +46 -0
- package/dist/labels/settings.js +29 -0
- package/dist/legend/KeyLegendStrip.d.ts +9 -1
- package/dist/legend/KeyLegendStrip.js +119 -5
- package/dist/legend/legend.css +52 -0
- package/dist/listing/EmptyState.d.ts +40 -0
- package/dist/listing/EmptyState.js +14 -0
- package/dist/listing/Listing.d.ts +23 -5
- package/dist/listing/Listing.js +11 -8
- package/dist/listing/index.d.ts +3 -1
- package/dist/listing/index.js +3 -1
- package/dist/listing/listing.css +172 -5
- package/dist/log/LogWell.d.ts +34 -0
- package/dist/log/LogWell.js +39 -0
- package/dist/log/LogWell.logic.d.ts +16 -0
- package/dist/log/LogWell.logic.js +26 -0
- package/dist/log/index.d.ts +8 -0
- package/dist/log/index.js +8 -0
- package/dist/log/log.css +57 -0
- package/dist/pane/Pane.d.ts +49 -0
- package/dist/pane/Pane.js +17 -0
- package/dist/pane/PaneActions.d.ts +3 -1
- package/dist/pane/PaneActions.js +6 -5
- package/dist/pane/PaneKeys.d.ts +10 -3
- package/dist/pane/PaneKeys.js +26 -7
- package/dist/pane/PaneTabs.d.ts +92 -0
- package/dist/pane/PaneTabs.js +326 -0
- package/dist/pane/PaneTabs.logic.d.ts +97 -0
- package/dist/pane/PaneTabs.logic.js +158 -0
- package/dist/pane/index.d.ts +7 -1
- package/dist/pane/index.js +7 -1
- package/dist/pane/panetabs.css +408 -0
- package/dist/pane/usePaneKeys.js +9 -11
- package/dist/pane/useTabDrag.d.ts +49 -0
- package/dist/pane/useTabDrag.js +306 -0
- package/dist/segmented/SegmentedChoice.d.ts +8 -1
- package/dist/segmented/SegmentedChoice.js +7 -4
- package/dist/shell/AboutWindow.d.ts +21 -0
- package/dist/shell/AboutWindow.js +10 -0
- package/dist/shell/LanguageChoice.d.ts +27 -0
- package/dist/shell/LanguageChoice.js +17 -0
- package/dist/shell/LoadFailure.d.ts +22 -0
- package/dist/shell/LoadFailure.js +15 -0
- package/dist/shell/Lockup.d.ts +52 -0
- package/dist/shell/Lockup.js +30 -0
- package/dist/shell/SettingsDialog.d.ts +97 -0
- package/dist/shell/SettingsDialog.js +219 -0
- package/dist/shell/SettingsDialog.logic.d.ts +33 -0
- package/dist/shell/SettingsDialog.logic.js +42 -0
- package/dist/shell/SettingsFiles.d.ts +55 -0
- package/dist/shell/SettingsFiles.js +30 -0
- package/dist/shell/SettingsPageKeys.d.ts +42 -0
- package/dist/shell/SettingsPageKeys.js +70 -0
- package/dist/shell/SettingsSubsection.d.ts +34 -0
- package/dist/shell/SettingsSubsection.js +30 -0
- package/dist/shell/SignIn.d.ts +61 -0
- package/dist/shell/SignIn.js +36 -0
- package/dist/shell/ThemePicker.d.ts +74 -0
- package/dist/shell/ThemePicker.js +96 -0
- package/dist/shell/ThemePicker.logic.d.ts +13 -0
- package/dist/shell/ThemePicker.logic.js +26 -0
- package/dist/shell/TitleBar.d.ts +44 -0
- package/dist/shell/TitleBar.js +23 -0
- package/dist/shell/UpdatePill.d.ts +26 -0
- package/dist/shell/UpdatePill.js +17 -0
- package/dist/shell/Updates.d.ts +99 -0
- package/dist/shell/Updates.js +72 -0
- package/dist/shell/index.d.ts +27 -0
- package/dist/shell/index.js +27 -0
- package/dist/shell/shell.css +243 -4
- package/dist/styles.css +10 -0
- package/dist/surface/GroupSwatch.d.ts +22 -0
- package/dist/surface/GroupSwatch.js +15 -0
- package/dist/surface/Tag.d.ts +26 -0
- package/dist/surface/Tag.js +12 -0
- package/dist/surface/index.d.ts +7 -0
- package/dist/surface/index.js +7 -0
- package/dist/surface/surface.css +116 -1
- package/dist/themes/catalog.js +4 -0
- package/dist/themes/themes.generated.css +244 -0
- package/dist/themes/tokens.d.ts +17 -5
- package/dist/themes/tokens.js +75 -1
- package/dist/tokens.css +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type LucideIcon } from 'lucide-react';
|
|
2
|
+
import type { ComponentType, ReactElement, ReactNode } from 'react';
|
|
3
|
+
/** A subsection of a Settings page: the sidebar lists it and scrolls the page to it. */
|
|
4
|
+
export interface SettingsSubsectionEntry {
|
|
5
|
+
/** Matches the `id` the page passes to its `SettingsSubsection`. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly title: string;
|
|
8
|
+
}
|
|
9
|
+
/** One page of the Settings dialog, with its body ready to draw. */
|
|
10
|
+
export interface SettingsPage {
|
|
11
|
+
/** Unique across every page in the dialog. */
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** The sidebar row's label and the page's title. */
|
|
14
|
+
readonly title: string;
|
|
15
|
+
/** The sidebar row's glyph. */
|
|
16
|
+
readonly Icon: ComponentType<{
|
|
17
|
+
readonly size?: number;
|
|
18
|
+
readonly 'aria-hidden'?: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
/** The page's subsections, in the order its body draws them; the sidebar unfolds them under the chosen page. */
|
|
21
|
+
readonly subsections: readonly SettingsSubsectionEntry[];
|
|
22
|
+
/**
|
|
23
|
+
* The body takes the column's whole height, so a part of it can scroll in
|
|
24
|
+
* its own box (an updates page's notes) while the rest stays put.
|
|
25
|
+
*/
|
|
26
|
+
readonly fills?: boolean;
|
|
27
|
+
/** A short label the page's sidebar row shows after its title as a warning chip (an offered build's version); none for none. */
|
|
28
|
+
readonly chip?: string | null;
|
|
29
|
+
readonly body: ReactNode;
|
|
30
|
+
}
|
|
31
|
+
/** A sidebar header and the pages under it, in the order they are listed. */
|
|
32
|
+
export interface SettingsGroup {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly title: string;
|
|
35
|
+
readonly pages: readonly SettingsPage[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A request to show Settings on one page: the page's id and a number that
|
|
39
|
+
* grows with every request, so a repeat for the page already chosen still
|
|
40
|
+
* counts as a new one.
|
|
41
|
+
*/
|
|
42
|
+
export interface SettingsPageRequest {
|
|
43
|
+
readonly pageId: string;
|
|
44
|
+
readonly seq: number;
|
|
45
|
+
}
|
|
46
|
+
/** Props for {@link SettingsDialog}. */
|
|
47
|
+
export interface SettingsDialogProps {
|
|
48
|
+
/** The pages under their headers; the dialog opens on the first page unless `pageRequest` names another. */
|
|
49
|
+
readonly groups: readonly SettingsGroup[];
|
|
50
|
+
/** The page to open on, and to turn to whenever a new request arrives; null for the first page. */
|
|
51
|
+
readonly pageRequest?: SettingsPageRequest | null;
|
|
52
|
+
/** Hears the id of each page as it comes into view, the first included. */
|
|
53
|
+
readonly onPageShown?: (pageId: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* What stands over the page column, outside its scroll, on the page in
|
|
56
|
+
* view (a change a settings file could not take: `SettingsSaveFailure`);
|
|
57
|
+
* `choosePage` turns the dialog to another page.
|
|
58
|
+
*/
|
|
59
|
+
readonly notice?: (pageId: string, choosePage: (pageId: string) => void) => ReactNode;
|
|
60
|
+
/** The title strip's glyph; a gear unless given. */
|
|
61
|
+
readonly icon?: LucideIcon;
|
|
62
|
+
/** Done, Escape, or a press outside the dialog with no page keys of its own. */
|
|
63
|
+
readonly onClose: () => void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Settings dialog: a fixed frame on the frosted wash, the sidebar of
|
|
67
|
+
* pages at its left, and the chosen page in a column that scrolls beside
|
|
68
|
+
* it. It opens on the page a request names, or on the first page, and keeps
|
|
69
|
+
* the chosen one until it closes or a new request names another
|
|
70
|
+
* (`pageRequest`). The title strip says Settings alone; the page's name
|
|
71
|
+
* heads its content, and the sidebar marks the page and the subsection in
|
|
72
|
+
* view, following the column's scroll. Every control applies its change at
|
|
73
|
+
* once, so there is nothing to commit: the legend's one verb is Done on
|
|
74
|
+
* Return, which Escape runs too, and a focused field, pop-up menu, or
|
|
75
|
+
* button keeps Return. A page that has keys of its own takes the legend and
|
|
76
|
+
* Escape over while it shows (`useSettingsPageKeys`) and gives them back
|
|
77
|
+
* when it goes. A new page starts at its top, its first subsection marked,
|
|
78
|
+
* and shows whole the control it marks to reveal.
|
|
79
|
+
*/
|
|
80
|
+
export declare function SettingsDialog({ groups, pageRequest, onPageShown, notice, icon, onClose }: SettingsDialogProps): ReactElement;
|
|
81
|
+
/** Props for {@link SettingsSaveFailure}. */
|
|
82
|
+
export interface SettingsSaveFailureProps {
|
|
83
|
+
/** What the file could not take, in the system's or the app's words. */
|
|
84
|
+
readonly message: string;
|
|
85
|
+
/** The verb that shows where the problem is (Show Files); none on that page itself. */
|
|
86
|
+
readonly action?: {
|
|
87
|
+
readonly label: string;
|
|
88
|
+
readonly onRun: () => void;
|
|
89
|
+
} | null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A change a settings file could not take, over the Settings page column
|
|
93
|
+
* (`SettingsDialog`'s `notice`), outside the page's scroll so it stays in
|
|
94
|
+
* view however far the page is scrolled: a danger notice, its words
|
|
95
|
+
* announced, and a verb that turns to the page that lists it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function SettingsSaveFailure({ message, action }: SettingsSaveFailureProps): ReactElement;
|
|
@@ -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;
|