@vieo-io/ui 0.2.0 → 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 (102) hide show
  1. package/README.md +65 -5
  2. package/dist/core/index.d.ts +10 -0
  3. package/dist/core/index.js +9 -0
  4. package/dist/core/reveal.d.ts +10 -0
  5. package/dist/core/reveal.js +65 -0
  6. package/dist/core/search.d.ts +5 -0
  7. package/dist/core/search.js +12 -0
  8. package/dist/core/settingsSearch.d.ts +21 -0
  9. package/dist/core/settingsSearch.js +37 -0
  10. package/dist/core/update/build.d.ts +48 -0
  11. package/dist/core/update/build.js +90 -0
  12. package/dist/core/update/follow.d.ts +39 -0
  13. package/dist/core/update/follow.js +49 -0
  14. package/dist/core/update/notNow.d.ts +4 -0
  15. package/dist/core/update/notNow.js +18 -0
  16. package/dist/core/update/offer.d.ts +32 -0
  17. package/dist/core/update/offer.js +19 -0
  18. package/dist/core/update/reload.d.ts +12 -0
  19. package/dist/core/update/reload.js +16 -0
  20. package/dist/core/update/types.d.ts +33 -0
  21. package/dist/react/index.d.ts +4 -0
  22. package/dist/react/index.js +4 -0
  23. package/dist/react/settingsSearch.d.ts +35 -0
  24. package/dist/react/settingsSearch.js +97 -0
  25. package/dist/react/update/Offer.d.ts +9 -0
  26. package/dist/react/update/Offer.js +4 -0
  27. package/dist/react/update/UpdateNotice.d.ts +37 -0
  28. package/dist/react/update/UpdateNotice.js +141 -0
  29. package/dist/react/update/hooks.d.ts +9 -0
  30. package/dist/react/update/hooks.js +51 -0
  31. package/dist/search.css +83 -0
  32. package/dist/setting.css +26 -0
  33. package/dist/{CommandPalette.d.ts → solid/CommandPalette.d.ts} +1 -1
  34. package/dist/{CommandPalette.jsx → solid/CommandPalette.jsx} +5 -10
  35. package/dist/{Dialog.jsx → solid/Dialog.jsx} +1 -1
  36. package/dist/{Icon.d.ts → solid/Icon.d.ts} +1 -1
  37. package/dist/{Icon.jsx → solid/Icon.jsx} +1 -1
  38. package/dist/{Listbox.jsx → solid/Listbox.jsx} +2 -2
  39. package/dist/{Menu.jsx → solid/Menu.jsx} +3 -3
  40. package/dist/{Popover.jsx → solid/Popover.jsx} +2 -2
  41. package/dist/{SegmentedControl.jsx → solid/SegmentedControl.jsx} +2 -2
  42. package/dist/{Sidebar.jsx → solid/Sidebar.jsx} +1 -1
  43. package/dist/{Tabs.jsx → solid/Tabs.jsx} +2 -2
  44. package/dist/{TextField.jsx → solid/TextField.jsx} +1 -1
  45. package/dist/{Toolbar.jsx → solid/Toolbar.jsx} +1 -1
  46. package/dist/{Tooltip.jsx → solid/Tooltip.jsx} +1 -1
  47. package/dist/{Tree.jsx → solid/Tree.jsx} +2 -2
  48. package/dist/{index.d.ts → solid/index.d.ts} +1 -1
  49. package/dist/{index.js → solid/index.js} +1 -1
  50. package/dist/solid/trigger.js +1 -0
  51. package/dist/styles.css +2 -0
  52. package/dist/update.css +118 -0
  53. package/package.json +39 -8
  54. /package/dist/{aria.d.ts → core/aria.d.ts} +0 -0
  55. /package/dist/{aria.js → core/aria.js} +0 -0
  56. /package/dist/{layers.d.ts → core/layers.d.ts} +0 -0
  57. /package/dist/{layers.js → core/layers.js} +0 -0
  58. /package/dist/{paths.d.ts → core/paths.d.ts} +0 -0
  59. /package/dist/{paths.js → core/paths.js} +0 -0
  60. /package/dist/{roving.d.ts → core/roving.d.ts} +0 -0
  61. /package/dist/{roving.js → core/roving.js} +0 -0
  62. /package/dist/{trigger.js → core/update/types.js} +0 -0
  63. /package/dist/{AppShell.d.ts → solid/AppShell.d.ts} +0 -0
  64. /package/dist/{AppShell.jsx → solid/AppShell.jsx} +0 -0
  65. /package/dist/{AppSwitcher.d.ts → solid/AppSwitcher.d.ts} +0 -0
  66. /package/dist/{AppSwitcher.jsx → solid/AppSwitcher.jsx} +0 -0
  67. /package/dist/{Badge.d.ts → solid/Badge.d.ts} +0 -0
  68. /package/dist/{Badge.jsx → solid/Badge.jsx} +0 -0
  69. /package/dist/{Button.d.ts → solid/Button.d.ts} +0 -0
  70. /package/dist/{Button.jsx → solid/Button.jsx} +0 -0
  71. /package/dist/{Checkbox.d.ts → solid/Checkbox.d.ts} +0 -0
  72. /package/dist/{Checkbox.jsx → solid/Checkbox.jsx} +0 -0
  73. /package/dist/{Dialog.d.ts → solid/Dialog.d.ts} +0 -0
  74. /package/dist/{EmptyState.d.ts → solid/EmptyState.d.ts} +0 -0
  75. /package/dist/{EmptyState.jsx → solid/EmptyState.jsx} +0 -0
  76. /package/dist/{IconButton.d.ts → solid/IconButton.d.ts} +0 -0
  77. /package/dist/{IconButton.jsx → solid/IconButton.jsx} +0 -0
  78. /package/dist/{Kbd.d.ts → solid/Kbd.d.ts} +0 -0
  79. /package/dist/{Kbd.jsx → solid/Kbd.jsx} +0 -0
  80. /package/dist/{Listbox.d.ts → solid/Listbox.d.ts} +0 -0
  81. /package/dist/{Menu.d.ts → solid/Menu.d.ts} +0 -0
  82. /package/dist/{ObjectCard.d.ts → solid/ObjectCard.d.ts} +0 -0
  83. /package/dist/{ObjectCard.jsx → solid/ObjectCard.jsx} +0 -0
  84. /package/dist/{Popover.d.ts → solid/Popover.d.ts} +0 -0
  85. /package/dist/{Resizer.d.ts → solid/Resizer.d.ts} +0 -0
  86. /package/dist/{Resizer.jsx → solid/Resizer.jsx} +0 -0
  87. /package/dist/{SegmentedControl.d.ts → solid/SegmentedControl.d.ts} +0 -0
  88. /package/dist/{Select.d.ts → solid/Select.d.ts} +0 -0
  89. /package/dist/{Select.jsx → solid/Select.jsx} +0 -0
  90. /package/dist/{SettingRow.d.ts → solid/SettingRow.d.ts} +0 -0
  91. /package/dist/{SettingRow.jsx → solid/SettingRow.jsx} +0 -0
  92. /package/dist/{Sidebar.d.ts → solid/Sidebar.d.ts} +0 -0
  93. /package/dist/{Switch.d.ts → solid/Switch.d.ts} +0 -0
  94. /package/dist/{Switch.jsx → solid/Switch.jsx} +0 -0
  95. /package/dist/{Tabs.d.ts → solid/Tabs.d.ts} +0 -0
  96. /package/dist/{TextField.d.ts → solid/TextField.d.ts} +0 -0
  97. /package/dist/{Toast.d.ts → solid/Toast.d.ts} +0 -0
  98. /package/dist/{Toast.jsx → solid/Toast.jsx} +0 -0
  99. /package/dist/{Toolbar.d.ts → solid/Toolbar.d.ts} +0 -0
  100. /package/dist/{Tooltip.d.ts → solid/Tooltip.d.ts} +0 -0
  101. /package/dist/{Tree.d.ts → solid/Tree.d.ts} +0 -0
  102. /package/dist/{trigger.d.ts → solid/trigger.d.ts} +0 -0
@@ -0,0 +1,35 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type SettingItem } from '../core/settingsSearch.js';
3
+ export type SettingsSearchProps<Item extends SettingItem> = {
4
+ items: readonly Item[];
5
+ /** Opens the item's section with `item.id` as the target, through the app's own router. */
6
+ onOpen: (item: Item) => void;
7
+ label?: string;
8
+ placeholder?: string;
9
+ /** Shown in place of the results while the box is empty, usually the list of sections. */
10
+ children?: ReactNode;
11
+ };
12
+ type SettingTarget = {
13
+ target: string | undefined;
14
+ onReached: () => void;
15
+ };
16
+ /**
17
+ * A search box over an app's settings, with the matching settings listed under it while it holds text.
18
+ * Up and Down move through them, Enter or a click opens one, Escape clears the box, and `/` focuses it from anywhere
19
+ * but a text field.
20
+ */
21
+ export declare function SettingsSearch<Item extends SettingItem>({ items, onOpen, label, placeholder, children, }: SettingsSearchProps<Item>): import("react").JSX.Element;
22
+ /** Gives the row reached by a search its target, from the app's router, and clears it through `onReached`. */
23
+ export declare function SettingTargetProvider({ target, onReached, children, }: SettingTarget & {
24
+ children: ReactNode;
25
+ }): import("react").JSX.Element;
26
+ /**
27
+ * The props a setting's row spreads to be found by a search: its anchor, and a ref that reveals the row while it is
28
+ * mounted and the target.
29
+ */
30
+ export declare function useSettingTarget(id: string): {
31
+ id: string;
32
+ ref: import("react").Dispatch<import("react").SetStateAction<HTMLElement | null>>;
33
+ tabIndex: number;
34
+ };
35
+ export {};
@@ -0,0 +1,97 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, useMemo, useRef, useState, } from 'react';
3
+ import { revealSetting } from '../core/reveal.js';
4
+ import { searchSettings, settingAnchor } from '../core/settingsSearch.js';
5
+ const SettingTargetContext = createContext({
6
+ target: undefined,
7
+ onReached: () => { },
8
+ });
9
+ /**
10
+ * A search box over an app's settings, with the matching settings listed under it while it holds text.
11
+ * Up and Down move through them, Enter or a click opens one, Escape clears the box, and `/` focuses it from anywhere
12
+ * but a text field.
13
+ */
14
+ export function SettingsSearch({ items, onOpen, label = 'Search settings', placeholder = 'Search settings', children, }) {
15
+ const [query, setQuery] = useState('');
16
+ const [active, setActive] = useState(0);
17
+ const box = useRef(null);
18
+ const list = useId();
19
+ const results = useMemo(() => searchSettings(items, query), [items, query]);
20
+ const searching = query.trim() !== '';
21
+ const activeId = searching && results.length ? `${list}-${active}` : undefined;
22
+ useEffect(() => {
23
+ const focusOnSlash = (event) => {
24
+ const modified = event.ctrlKey || event.metaKey || event.altKey;
25
+ if (event.key !== '/' || modified || holdsText(document.activeElement))
26
+ return;
27
+ event.preventDefault();
28
+ box.current?.focus();
29
+ };
30
+ document.addEventListener('keydown', focusOnSlash);
31
+ return () => document.removeEventListener('keydown', focusOnSlash);
32
+ }, []);
33
+ const open = (item) => {
34
+ setQuery('');
35
+ setActive(0);
36
+ onOpen(item);
37
+ };
38
+ const keyDown = (event) => {
39
+ if (event.key === 'Escape' && query) {
40
+ event.preventDefault();
41
+ event.nativeEvent.stopImmediatePropagation();
42
+ setQuery('');
43
+ return;
44
+ }
45
+ if (!results.length)
46
+ return;
47
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
48
+ event.preventDefault();
49
+ const step = event.key === 'ArrowDown' ? 1 : -1;
50
+ setActive(Math.min(results.length - 1, Math.max(0, active + step)));
51
+ }
52
+ const chosen = results[active];
53
+ if (event.key === 'Enter' && chosen) {
54
+ event.preventDefault();
55
+ open(chosen);
56
+ }
57
+ };
58
+ return (_jsxs("div", { className: 'vds-settings-search', children: [_jsx("input", { ref: box, className: 'vds-settings-search__box', type: 'search', role: 'combobox', "aria-label": label, "aria-expanded": searching, "aria-controls": list, "aria-activedescendant": activeId, "aria-autocomplete": 'list', placeholder: placeholder, value: query, onChange: (event) => {
59
+ setQuery(event.target.value);
60
+ setActive(0);
61
+ }, onKeyDown: keyDown }), searching ? (_jsx(Results, { id: list, results: results, active: active, onOpen: open })) : (children)] }));
62
+ }
63
+ /** Gives the row reached by a search its target, from the app's router, and clears it through `onReached`. */
64
+ export function SettingTargetProvider({ target, onReached, children, }) {
65
+ const value = useMemo(() => ({ target, onReached }), [target, onReached]);
66
+ return _jsx(SettingTargetContext.Provider, { value: value, children: children });
67
+ }
68
+ /**
69
+ * The props a setting's row spreads to be found by a search: its anchor, and a ref that reveals the row while it is
70
+ * mounted and the target.
71
+ */
72
+ export function useSettingTarget(id) {
73
+ const { target, onReached } = useContext(SettingTargetContext);
74
+ const [element, setElement] = useState(null);
75
+ useEffect(() => {
76
+ if (!element || target !== id)
77
+ return;
78
+ revealSetting(element, {
79
+ reducedMotion: matchMedia('(prefers-reduced-motion: reduce)').matches,
80
+ });
81
+ onReached();
82
+ }, [element, id, target, onReached]);
83
+ return { id: settingAnchor(id), ref: setElement, tabIndex: -1 };
84
+ }
85
+ function holdsText(element) {
86
+ if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement)
87
+ return true;
88
+ if (element instanceof HTMLInputElement)
89
+ return !['button', 'checkbox', 'radio', 'range', 'submit'].includes(element.type);
90
+ return element instanceof HTMLElement && element.isContentEditable;
91
+ }
92
+ function Results({ id, results, active, onOpen, }) {
93
+ if (!results.length) {
94
+ return (_jsx("p", { className: 'vds-settings-search__empty', role: 'status', children: "No settings found" }));
95
+ }
96
+ return (_jsx("div", { className: 'vds-settings-search__results', id: id, role: 'listbox', children: results.map((item, index) => (_jsxs("div", { id: `${id}-${index}`, className: 'vds-settings-search__result', role: 'option', "aria-selected": index === active, onMouseDown: (event) => event.preventDefault(), onClick: () => onOpen(item), children: [_jsx("span", { className: 'vds-settings-search__title', children: item.title }), _jsx("span", { className: 'vds-settings-search__section', children: item.sectionTitle })] }, item.id))) }));
97
+ }
@@ -0,0 +1,9 @@
1
+ type OfferProps = {
2
+ text: string;
3
+ whatsNew: string;
4
+ id: string;
5
+ label: string;
6
+ onPress: () => void;
7
+ };
8
+ export declare function Offer({ text, whatsNew, id, label, onPress }: OfferProps): import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,4 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function Offer({ text, whatsNew, id, label, onPress }) {
3
+ return (_jsxs(_Fragment, { children: [_jsx("span", { children: text }), _jsx("a", { href: whatsNew, children: "What\u2019s new" }), _jsx("button", { type: 'button', className: 'primary vieo-update-action', id: id, onClick: onPress, children: label })] }));
4
+ }
@@ -0,0 +1,37 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type BuildWatch } from '../../core/update/build.js';
3
+ import { type AppOffer } from '../../core/update/offer.js';
4
+ import type { UpdateSource, UpdateStatus } from '../../core/update/types.js';
5
+ export type ReactOffer = AppOffer<ReactNode>;
6
+ export type UpdateNoticeApp = {
7
+ whatsNew: string;
8
+ /** The storage key that remembers which offer Not now was pressed for. */
9
+ notNowKey: string;
10
+ /** Asked before an update while the status has blockers. Resolves to whether to go ahead. */
11
+ confirm?: (status: UpdateStatus) => Promise<boolean>;
12
+ /** Runs before each reload that follows a pressed update. Resolves to true when it took the page elsewhere itself. */
13
+ afterUpdate?: () => Promise<boolean>;
14
+ reload?: () => void;
15
+ };
16
+ type UpdateNoticeProps = {
17
+ /** Null for a viewer who is only ever offered the page's refresh. */
18
+ source: UpdateSource | null;
19
+ status: UpdateStatus | null;
20
+ /** Has the status read again, as once an update ends. */
21
+ readAgain: () => void;
22
+ build: BuildWatch;
23
+ /** From {@link useStaleBuild}. */
24
+ stale: string | null;
25
+ app: UpdateNoticeApp;
26
+ first?: ReactOffer | null;
27
+ last?: ReactOffer | null;
28
+ /** Draws the Not now button in place of the package's own. */
29
+ renderNotNow?: (press: () => void) => ReactNode;
30
+ };
31
+ /**
32
+ * Pins one card for whatever is newer, in the order {@link pickOffer} gives.
33
+ * One press of Refresh to update on the server's update updates the server, follows it, and reloads once into the new
34
+ * build. A viewer who may update the server and finds an update already running follows it, then is offered the refresh.
35
+ */
36
+ export declare function UpdateNotice({ source, status, readAgain, build, stale, app, first, last, renderNotNow, }: UpdateNoticeProps): import("react").JSX.Element;
37
+ export {};
@@ -0,0 +1,141 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { checkForNewBuild } from '../../core/update/build.js';
4
+ import { FOLLOW_FOR_MS, followUpdate } from '../../core/update/follow.js';
5
+ import { isPutOff, putOff } from '../../core/update/notNow.js';
6
+ import { pickOffer } from '../../core/update/offer.js';
7
+ import { reloadWhenServing } from '../../core/update/reload.js';
8
+ import { Offer } from './Offer.js';
9
+ /**
10
+ * Pins one card for whatever is newer, in the order {@link pickOffer} gives.
11
+ * One press of Refresh to update on the server's update updates the server, follows it, and reloads once into the new
12
+ * build. A viewer who may update the server and finds an update already running follows it, then is offered the refresh.
13
+ */
14
+ export function UpdateNotice({ source, status, readAgain, build, stale, app, first, last, renderNotNow, }) {
15
+ const flow = useServerFlow({ source, status, readAgain, build, app });
16
+ const [putOffNow, setPutOffNow] = useState(null);
17
+ const offer = pickOffer({ first, last, server: flow.taken ?? status, stale });
18
+ const key = offer?.key ?? '';
19
+ const hidden = !offer || putOffNow === key || isPutOff(app.notNowKey, key);
20
+ const reload = app.reload ?? (() => location.reload());
21
+ function notNow() {
22
+ putOff(app.notNowKey, key);
23
+ setPutOffNow(key);
24
+ }
25
+ function content() {
26
+ if (offer?.kind === 'app')
27
+ return offer.offer.node;
28
+ if (offer?.kind === 'refresh')
29
+ return (_jsx(Offer, { text: 'New version ready', whatsNew: app.whatsNew, id: 'update-reload', label: 'Refresh to update', onPress: () => void reloadWhenServing({ ...build, reload }) }));
30
+ if (offer?.kind !== 'server')
31
+ return null;
32
+ if (flow.step)
33
+ return _jsx("span", { children: flow.step });
34
+ const { status: offered } = offer;
35
+ return (_jsx(Offer, { text: flow.stopped ?? 'New version ready', whatsNew: app.whatsNew, id: 'update-reload', label: 'Refresh to update', onPress: () => void flow.press(offered) }));
36
+ }
37
+ return (_jsxs("div", { className: 'vieo-update-notice', id: 'update-notice', role: 'status', hidden: hidden, children: [content(), renderNotNow ? renderNotNow(notNow) : _jsx(NotNow, { onPress: notNow })] }));
38
+ }
39
+ function errorText(error) {
40
+ return error instanceof Error ? error.message : String(error);
41
+ }
42
+ function NotNow({ onPress }) {
43
+ return (_jsx("button", { type: 'button', className: 'vieo-update-not-now', id: 'update-not-now', "aria-label": 'Not now', title: 'Not now', onClick: onPress, children: _jsx("svg", { viewBox: '0 0 24 24', "aria-hidden": 'true', children: _jsx("path", { d: 'M18 6 6 18M6 6l12 12' }) }) }));
44
+ }
45
+ /** Starts the server's update on a press, or follows one found running, and says each step. Only a press reloads at the end. */
46
+ function useServerFlow({ source, status, readAgain, build, app, }) {
47
+ const [taken, setTaken] = useState(null);
48
+ const [step, setStep] = useState(null);
49
+ const [stopped, setStopped] = useState(null);
50
+ // A run that ended is not followed again from the read that showed it running, which stays until the next read
51
+ // lands, nor from a later read of the version it installed, since a server can go on reporting the run that long.
52
+ const [endedOn, setEndedOn] = useState({
53
+ read: null,
54
+ installed: null,
55
+ });
56
+ const current = useRef(status);
57
+ current.current = status;
58
+ const reload = app.reload ?? (() => location.reload());
59
+ async function reloadAfterUpdate() {
60
+ const tookPageElsewhere = await app.afterUpdate?.().catch(() => false);
61
+ if (!tookPageElsewhere)
62
+ await reloadWhenServing({ ...build, reload });
63
+ }
64
+ async function servesNewerBuild() {
65
+ const served = await build.read().catch(() => null);
66
+ return served !== null && served !== build.loaded;
67
+ }
68
+ function settle(end) {
69
+ setEndedOn({ read: current.current, installed: end.installed });
70
+ setStep(null);
71
+ setTaken(null);
72
+ readAgain();
73
+ }
74
+ async function ended(end, pressed) {
75
+ if (!end) {
76
+ setStep(null);
77
+ setStopped(`The server’s update hasn’t finished in ${FOLLOW_FOR_MS / 60_000} minutes.`);
78
+ return;
79
+ }
80
+ const { progress, status: final } = end;
81
+ if (progress.kind === 'failed') {
82
+ setStep(null);
83
+ setStopped(`The server’s update stopped: ${progress.reason}`);
84
+ return;
85
+ }
86
+ const reloads = pressed && (progress.kind === 'updated' || (await servesNewerBuild()));
87
+ if (!reloads) {
88
+ settle(final);
89
+ checkForNewBuild(build.checkEvent, build.channel);
90
+ return;
91
+ }
92
+ await reloadAfterUpdate();
93
+ }
94
+ async function follow(before, pressed) {
95
+ if (!source)
96
+ return;
97
+ setTaken(before);
98
+ setStopped(null);
99
+ setStep('Updating the server…');
100
+ const end = await followUpdate(source, before, { away: () => setStep('Restarting…') });
101
+ await ended(end, pressed);
102
+ }
103
+ async function press(offered) {
104
+ if (!source || !offered.latest)
105
+ return;
106
+ if (offered.blockers > 0 && app.confirm && !(await app.confirm(offered)))
107
+ return;
108
+ setTaken(offered);
109
+ setStopped(null);
110
+ setStep('Updating the server…');
111
+ let answer;
112
+ try {
113
+ answer = await source.start(offered.latest);
114
+ }
115
+ catch (error) {
116
+ answer = { refused: errorText(error) };
117
+ }
118
+ if (typeof answer === 'object') {
119
+ setStep(null);
120
+ setStopped(`The server didn’t start its update: ${answer.refused}`);
121
+ return;
122
+ }
123
+ if (answer === 'current') {
124
+ if (await servesNewerBuild())
125
+ await reloadAfterUpdate();
126
+ else
127
+ settle(offered);
128
+ return;
129
+ }
130
+ await follow(offered, true);
131
+ }
132
+ const followedAlready = status === endedOn.read ||
133
+ (endedOn.installed !== null && status?.installed === endedOn.installed);
134
+ const runningHere = status?.running === true && status.mayStart && taken === null && !followedAlready;
135
+ // biome-ignore lint/correctness/useExhaustiveDependencies: a run found here is followed once, from the status that showed it.
136
+ useEffect(() => {
137
+ if (runningHere && status)
138
+ void follow(status, false);
139
+ }, [runningHere]);
140
+ return { taken, step, stopped, press };
141
+ }
@@ -0,0 +1,9 @@
1
+ import { type BuildWatch } from '../../core/update/build.js';
2
+ import type { UpdateSource, UpdateStatus } from '../../core/update/types.js';
3
+ /** The key of the build the server serves, while it is not the one this page loaded. */
4
+ export declare function useStaleBuild(build: BuildWatch): string | null;
5
+ /**
6
+ * The server's update, read at mount, then hourly while the page is in view and on `checkEvent`.
7
+ * Null until it first answers, and always for a null source.
8
+ */
9
+ export declare function useUpdateStatus(source: UpdateSource | null, checkEvent: string): [UpdateStatus | null, () => void];
@@ -0,0 +1,51 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { hourlyInView, watchForNewBuild } from '../../core/update/build.js';
3
+ /** The key of the build the server serves, while it is not the one this page loaded. */
4
+ export function useStaleBuild(build) {
5
+ const [stale, setStale] = useState(null);
6
+ const { loaded, read, checkEvent, channel } = build;
7
+ useEffect(() => {
8
+ if (!loaded)
9
+ return;
10
+ return watchForNewBuild({
11
+ loaded,
12
+ onStale: setStale,
13
+ read,
14
+ checkEvent,
15
+ channel: channel && typeof BroadcastChannel === 'function'
16
+ ? new BroadcastChannel(channel)
17
+ : undefined,
18
+ });
19
+ }, [loaded, read, checkEvent, channel]);
20
+ return stale;
21
+ }
22
+ /**
23
+ * The server's update, read at mount, then hourly while the page is in view and on `checkEvent`.
24
+ * Null until it first answers, and always for a null source.
25
+ */
26
+ export function useUpdateStatus(source, checkEvent) {
27
+ const [status, setStatus] = useState(null);
28
+ const readNow = useRef(() => { });
29
+ const readAgain = useCallback(() => readNow.current(), []);
30
+ useEffect(() => {
31
+ if (!source) {
32
+ setStatus(null);
33
+ return;
34
+ }
35
+ let current = true;
36
+ function read() {
37
+ source?.read().then((next) => {
38
+ if (current)
39
+ setStatus(next);
40
+ }, () => undefined);
41
+ }
42
+ readNow.current = read;
43
+ read();
44
+ const schedule = hourlyInView(read, checkEvent);
45
+ return () => {
46
+ current = false;
47
+ schedule.stop();
48
+ };
49
+ }, [source, checkEvent]);
50
+ return [status, readAgain];
51
+ }
@@ -0,0 +1,83 @@
1
+ .vds-settings-search {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: var(--space-2);
5
+ min-width: 0;
6
+ }
7
+
8
+ .vds-settings-search__box {
9
+ box-sizing: border-box;
10
+ width: 100%;
11
+ height: var(--control-height);
12
+ padding: 0 var(--space-3);
13
+ border: 1px solid var(--border-strong);
14
+ border-radius: var(--radius-sm);
15
+ background: var(--surface);
16
+ color: var(--text);
17
+ font: inherit;
18
+ font-size: var(--font-ui);
19
+ }
20
+
21
+ .vds-settings-search__box::placeholder {
22
+ color: var(--muted);
23
+ }
24
+
25
+ .vds-settings-search__box:focus-visible {
26
+ border-color: var(--accent);
27
+ outline: none;
28
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
29
+ }
30
+
31
+ .vds-settings-search__results {
32
+ display: flex;
33
+ flex-direction: column;
34
+ gap: var(--row-gap);
35
+ margin: 0;
36
+ padding: 0;
37
+ list-style: none;
38
+ }
39
+
40
+ .vds-settings-search__result {
41
+ display: flex;
42
+ flex-direction: column;
43
+ justify-content: center;
44
+ min-height: var(--row-height);
45
+ padding: var(--space-1) var(--space-2);
46
+ border-radius: var(--radius-sm);
47
+ cursor: pointer;
48
+ }
49
+
50
+ .vds-settings-search__result:hover {
51
+ background: var(--bg-hover);
52
+ }
53
+
54
+ .vds-settings-search__result[aria-selected="true"] {
55
+ background: var(--accent-soft);
56
+ }
57
+
58
+ .vds-settings-search__title {
59
+ font-size: var(--font-ui);
60
+ }
61
+
62
+ .vds-settings-search__section,
63
+ .vds-settings-search__empty {
64
+ color: var(--muted);
65
+ font-size: var(--font-sm);
66
+ }
67
+
68
+ /* --muted falls below 4.5:1 on the hover and --accent-soft fills. */
69
+ .vds-settings-search__result:hover .vds-settings-search__section,
70
+ .vds-settings-search__result[aria-selected="true"] .vds-settings-search__section {
71
+ color: var(--text);
72
+ }
73
+
74
+ .vds-settings-search__empty {
75
+ margin: 0;
76
+ padding: var(--space-2);
77
+ }
78
+
79
+ @media (pointer: coarse) {
80
+ .vds-settings-search__box {
81
+ height: 44px;
82
+ }
83
+ }
package/dist/setting.css CHANGED
@@ -40,3 +40,29 @@
40
40
  .vds-setting--stacked .vds-setting__control {
41
41
  flex: auto;
42
42
  }
43
+
44
+ /* A row a settings search opened. The pulse stands in for the focus ring. */
45
+ .vds-setting-pulse {
46
+ border-radius: var(--radius-sm);
47
+ outline: 2px solid transparent;
48
+ outline-offset: 4px;
49
+ animation: vds-setting-pulse 650ms ease-in-out 2;
50
+ }
51
+
52
+ @keyframes vds-setting-pulse {
53
+ 50% {
54
+ outline-color: color-mix(in srgb, var(--accent) 70%, transparent);
55
+ }
56
+ }
57
+
58
+ /* A revealed row keeps the focus after its pulse, without the browser's focus ring. */
59
+ [id^="setting-"][tabindex="-1"]:focus:not(.vds-setting-pulse) {
60
+ outline: none;
61
+ }
62
+
63
+ @media (prefers-reduced-motion: reduce) {
64
+ .vds-setting-pulse {
65
+ animation: none;
66
+ outline-color: var(--accent);
67
+ }
68
+ }
@@ -37,6 +37,6 @@ type Group = {
37
37
  export declare function CommandPalette(props: CommandPaletteProps): import("@solidjs/web").JSX.Element;
38
38
  /** The commands in group order, each group in the order its commands were given. */
39
39
  export declare function grouped(commands: Command[]): Group[];
40
- /** The commands whose label or keywords contain every word of the query, ignoring case. */
40
+ /** The commands whose label or keywords contain every word of the query, ignoring case and accents. */
41
41
  export declare function matching(commands: Command[], query: string): Command[];
42
42
  export {};
@@ -1,8 +1,9 @@
1
1
  import { For, Show } from '@solidjs/web';
2
2
  import { createEffect, createMemo, createSignal, createUniqueId } from 'solid-js';
3
- import { aria } from './aria';
3
+ import { aria } from '../core/aria';
4
+ import { first, moveFor, rows } from '../core/roving';
5
+ import { matchWords } from '../core/search';
4
6
  import { Icon } from './Icon';
5
- import { first, moveFor, rows } from './roving';
6
7
  /**
7
8
  * A search field over a list of commands, in the combobox pattern: focus stays in the field, arrow
8
9
  * keys move the highlighted command, and Enter runs it. Every word typed must appear in a command's
@@ -95,13 +96,7 @@ export function grouped(commands) {
95
96
  row.index = index++;
96
97
  return [...groups.values()];
97
98
  }
98
- /** The commands whose label or keywords contain every word of the query, ignoring case. */
99
+ /** The commands whose label or keywords contain every word of the query, ignoring case and accents. */
99
100
  export function matching(commands, query) {
100
- const words = query.toLowerCase().split(/\s+/).filter(Boolean);
101
- if (!words.length)
102
- return commands;
103
- return commands.filter((command) => {
104
- const text = [command.label, ...(command.keywords ?? [])].join(' ').toLowerCase();
105
- return words.every((word) => text.includes(word));
106
- });
101
+ return commands.filter((command) => matchWords(query, [command.label, ...(command.keywords ?? [])]));
107
102
  }
@@ -1,7 +1,7 @@
1
1
  import { createFocusTrap } from '@solid-primitives/focus';
2
2
  import { Portal, Show } from '@solidjs/web';
3
3
  import { createEffect, createSignal, createUniqueId } from 'solid-js';
4
- import { isTopDialog, pushDialog } from './layers';
4
+ import { isTopDialog, pushDialog } from '../core/layers';
5
5
  /**
6
6
  * A modal dialog. Escape or a click on the backdrop closes the top dialog only, focus stays inside
7
7
  * while it's open, and focus goes back to whatever had it before the dialog opened.
@@ -1,5 +1,5 @@
1
1
  import type { ComponentProps } from '@solidjs/web';
2
- import { PATHS } from './paths';
2
+ import { PATHS } from '../core/paths';
3
3
  export type IconName = keyof typeof PATHS;
4
4
  export type IconProps = Omit<ComponentProps<'svg'>, 'name'> & {
5
5
  name: IconName;
@@ -1,5 +1,5 @@
1
1
  import { omit } from 'solid-js';
2
- import { PATHS } from './paths';
2
+ import { PATHS } from '../core/paths';
3
3
  /** An inline SVG icon in `currentColor`, hidden from assistive technology. */
4
4
  export function Icon(props) {
5
5
  const rest = omit(props, 'class', 'name', 'size', 'style');
@@ -1,7 +1,7 @@
1
1
  import { For, Show } from '@solidjs/web';
2
2
  import { createSignal } from 'solid-js';
3
- import { aria } from './aria';
4
- import { first, moveFor, rows } from './roving';
3
+ import { aria } from '../core/aria';
4
+ import { first, moveFor, rows } from '../core/roving';
5
5
  /**
6
6
  * A single-choice list with roving focus: one option is in the tab order, arrow keys, Home, and End
7
7
  * move between the enabled ones, and Enter, Space, or a click chooses.
@@ -1,9 +1,9 @@
1
1
  import { For, Portal, Show } from '@solidjs/web';
2
2
  import { createEffect, createSignal, createUniqueId, onFlush } from 'solid-js';
3
- import { aria } from './aria';
3
+ import { aria } from '../core/aria';
4
+ import { closeOnOutside, place } from '../core/layers';
5
+ import { first, moveFor, rows, typeahead } from '../core/roving';
4
6
  import { Icon } from './Icon';
5
- import { closeOnOutside, place } from './layers';
6
- import { first, moveFor, rows, typeahead } from './roving';
7
7
  /**
8
8
  * A menu of actions. Arrow keys, Home, End, and a typed letter move between items; Enter or a click
9
9
  * runs one. Escape, Tab, and a click elsewhere close it, and Escape and a choice return focus to the
@@ -1,7 +1,7 @@
1
1
  import { Portal, Show } from '@solidjs/web';
2
2
  import { createEffect, createSignal, createUniqueId } from 'solid-js';
3
- import { aria } from './aria';
4
- import { closeOnOutside, place } from './layers';
3
+ import { aria } from '../core/aria';
4
+ import { closeOnOutside, place } from '../core/layers';
5
5
  /**
6
6
  * Content that floats beside its trigger. A click on the trigger toggles it; Escape closes it and
7
7
  * returns focus to the trigger, and a click elsewhere closes it and leaves focus where the click put it.
@@ -1,7 +1,7 @@
1
1
  import { For, Show } from '@solidjs/web';
2
- import { aria } from './aria';
2
+ import { aria } from '../core/aria';
3
+ import { first, moveFor, rows } from '../core/roving';
3
4
  import { Icon } from './Icon';
4
- import { first, moveFor, rows } from './roving';
5
5
  /**
6
6
  * A row of mutually exclusive options, as a radio group. The chosen option is the one tab stop, and
7
7
  * arrow keys, Home, and End choose the next enabled option as they move.
@@ -2,7 +2,7 @@ import { createFocusTrap } from '@solid-primitives/focus';
2
2
  import { createPresence } from '@solid-primitives/presence';
3
3
  import { Show } from '@solidjs/web';
4
4
  import { createEffect, createSignal, onSettled } from 'solid-js';
5
- import { isTopDialog, pushDialog } from './layers';
5
+ import { isTopDialog, pushDialog } from '../core/layers';
6
6
  import { Resizer } from './Resizer';
7
7
  const BREAKPOINT = 640;
8
8
  /** How long the drawer takes to slide in or out, matching `--vds-drawer-duration`. */
@@ -1,7 +1,7 @@
1
1
  import { For } from '@solidjs/web';
2
2
  import { createUniqueId } from 'solid-js';
3
- import { aria } from './aria';
4
- import { moveFor, rows } from './roving';
3
+ import { aria } from '../core/aria';
4
+ import { moveFor, rows } from '../core/roving';
5
5
  /** A row of tabs over one panel. Arrow keys, Home, and End move between tabs and select as they go. */
6
6
  export function Tabs(props) {
7
7
  const id = createUniqueId();
@@ -1,6 +1,6 @@
1
1
  import { Show } from '@solidjs/web';
2
2
  import { createSignal, createUniqueId } from 'solid-js';
3
- import { aria } from './aria';
3
+ import { aria } from '../core/aria';
4
4
  /**
5
5
  * A labelled text input with a hint and an error read along with it. Typing goes to a draft that
6
6
  * follows `value` whenever the caller changes it, so typed text survives any other prop changing.
@@ -1,6 +1,6 @@
1
1
  import { Show } from '@solidjs/web';
2
2
  import { onSettled } from 'solid-js';
3
- import { moveFor } from './roving';
3
+ import { moveFor } from '../core/roving';
4
4
  const CONTROLS = 'button, a[href], input, select, textarea, [role="button"], [role="switch"]';
5
5
  /** Fields whose arrow keys move within them, which the toolbar leaves alone. */
6
6
  const TEXT_ENTRY = 'input:not([type="button"], [type="checkbox"], [type="radio"]), textarea, select';