@bigpixelrocket/uiok 0.0.0-stage → 0.1.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 (280) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +569 -0
  4. package/README.md +44 -2
  5. package/dist/VisuallyHidden.d.ts +13 -0
  6. package/dist/VisuallyHidden.js +13 -0
  7. package/dist/activity/ActivityBar.d.ts +29 -0
  8. package/dist/activity/ActivityBar.js +21 -0
  9. package/dist/activity/activity.css +43 -0
  10. package/dist/activity/index.d.ts +2 -0
  11. package/dist/activity/index.js +2 -0
  12. package/dist/button/Button.d.ts +26 -0
  13. package/dist/button/Button.js +14 -0
  14. package/dist/button/IconButton.d.ts +18 -0
  15. package/dist/button/IconButton.js +14 -0
  16. package/dist/button/button.css +95 -0
  17. package/dist/button/index.d.ts +3 -0
  18. package/dist/button/index.js +3 -0
  19. package/dist/charts/Drawing.d.ts +27 -0
  20. package/dist/charts/Drawing.js +117 -0
  21. package/dist/charts/Drawing.logic.d.ts +2 -0
  22. package/dist/charts/Drawing.logic.js +22 -0
  23. package/dist/charts/Line.logic.d.ts +33 -0
  24. package/dist/charts/Line.logic.js +72 -0
  25. package/dist/charts/LineChart.d.ts +34 -0
  26. package/dist/charts/LineChart.js +100 -0
  27. package/dist/charts/Pie.logic.d.ts +16 -0
  28. package/dist/charts/Pie.logic.js +28 -0
  29. package/dist/charts/PieChart.d.ts +20 -0
  30. package/dist/charts/PieChart.js +16 -0
  31. package/dist/charts/ResultChart.d.ts +47 -0
  32. package/dist/charts/ResultChart.js +175 -0
  33. package/dist/charts/ResultChart.logic.d.ts +42 -0
  34. package/dist/charts/ResultChart.logic.js +165 -0
  35. package/dist/charts/Scatter.logic.d.ts +55 -0
  36. package/dist/charts/Scatter.logic.js +134 -0
  37. package/dist/charts/ScatterChart.d.ts +36 -0
  38. package/dist/charts/ScatterChart.js +99 -0
  39. package/dist/charts/charts.css +310 -0
  40. package/dist/charts/index.d.ts +14 -0
  41. package/dist/charts/index.js +11 -0
  42. package/dist/charts/seriesColour.d.ts +2 -0
  43. package/dist/charts/seriesColour.js +8 -0
  44. package/dist/clock/index.d.ts +2 -0
  45. package/dist/clock/index.js +2 -0
  46. package/dist/clock/useClock.d.ts +14 -0
  47. package/dist/clock/useClock.js +57 -0
  48. package/dist/datetime/DateTimePicker.d.ts +50 -0
  49. package/dist/datetime/DateTimePicker.js +98 -0
  50. package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
  51. package/dist/datetime/DateTimePicker.logic.js +103 -0
  52. package/dist/datetime/datetime.css +115 -0
  53. package/dist/datetime/index.d.ts +7 -0
  54. package/dist/datetime/index.js +7 -0
  55. package/dist/dialog/ConfirmDialog.d.ts +73 -0
  56. package/dist/dialog/ConfirmDialog.js +30 -0
  57. package/dist/dialog/DialogLegend.d.ts +21 -0
  58. package/dist/dialog/DialogLegend.js +28 -0
  59. package/dist/dialog/DialogLegend.logic.d.ts +145 -0
  60. package/dist/dialog/DialogLegend.logic.js +71 -0
  61. package/dist/dialog/ModalDialog.d.ts +101 -0
  62. package/dist/dialog/ModalDialog.js +184 -0
  63. package/dist/dialog/dialog.css +283 -0
  64. package/dist/dialog/index.d.ts +8 -0
  65. package/dist/dialog/index.js +8 -0
  66. package/dist/filter/FilterEscape.d.ts +16 -0
  67. package/dist/filter/FilterEscape.js +15 -0
  68. package/dist/filter/FilterIcon.d.ts +8 -0
  69. package/dist/filter/FilterIcon.js +11 -0
  70. package/dist/filter/filter.css +42 -0
  71. package/dist/filter/index.d.ts +3 -0
  72. package/dist/filter/index.js +3 -0
  73. package/dist/grid/DataGrid.d.ts +149 -0
  74. package/dist/grid/DataGrid.js +373 -0
  75. package/dist/grid/DataGrid.logic.d.ts +57 -0
  76. package/dist/grid/DataGrid.logic.js +121 -0
  77. package/dist/grid/grid.css +206 -0
  78. package/dist/grid/index.d.ts +7 -0
  79. package/dist/grid/index.js +7 -0
  80. package/dist/index.d.ts +32 -0
  81. package/dist/index.js +32 -0
  82. package/dist/keyboard/BrowserKeys.d.ts +15 -0
  83. package/dist/keyboard/BrowserKeys.js +28 -0
  84. package/dist/keyboard/KeyChord.logic.d.ts +25 -0
  85. package/dist/keyboard/KeyChord.logic.js +50 -0
  86. package/dist/keyboard/Keyboard.logic.d.ts +84 -0
  87. package/dist/keyboard/Keyboard.logic.js +137 -0
  88. package/dist/keyboard/OverlayWatch.d.ts +28 -0
  89. package/dist/keyboard/OverlayWatch.js +119 -0
  90. package/dist/keyboard/PageSelectAll.d.ts +14 -0
  91. package/dist/keyboard/PageSelectAll.js +22 -0
  92. package/dist/keyboard/index.d.ts +9 -0
  93. package/dist/keyboard/index.js +9 -0
  94. package/dist/keychord/KeyChord.d.ts +16 -0
  95. package/dist/keychord/KeyChord.js +55 -0
  96. package/dist/keychord/index.d.ts +2 -0
  97. package/dist/keychord/index.js +2 -0
  98. package/dist/keychord/keychord.css +41 -0
  99. package/dist/labels/UiokLabels.d.ts +41 -0
  100. package/dist/labels/UiokLabels.js +31 -0
  101. package/dist/labels/UiokProvider.d.ts +44 -0
  102. package/dist/labels/UiokProvider.js +54 -0
  103. package/dist/labels/charts.d.ts +34 -0
  104. package/dist/labels/charts.js +15 -0
  105. package/dist/labels/dateTime.d.ts +32 -0
  106. package/dist/labels/dateTime.js +14 -0
  107. package/dist/labels/dialog.d.ts +18 -0
  108. package/dist/labels/dialog.js +6 -0
  109. package/dist/labels/index.d.ts +13 -0
  110. package/dist/labels/index.js +13 -0
  111. package/dist/labels/keys.d.ts +28 -0
  112. package/dist/labels/keys.js +53 -0
  113. package/dist/labels/legend.d.ts +21 -0
  114. package/dist/labels/legend.js +7 -0
  115. package/dist/labels/listing.d.ts +16 -0
  116. package/dist/labels/listing.js +8 -0
  117. package/dist/labels/pager.d.ts +32 -0
  118. package/dist/labels/pager.js +20 -0
  119. package/dist/labels/palette.d.ts +17 -0
  120. package/dist/labels/palette.js +6 -0
  121. package/dist/labels/selectAll.d.ts +15 -0
  122. package/dist/labels/selectAll.js +6 -0
  123. package/dist/labels/terminal.d.ts +25 -0
  124. package/dist/labels/terminal.js +9 -0
  125. package/dist/legend/KeyLegend.logic.d.ts +84 -0
  126. package/dist/legend/KeyLegend.logic.js +109 -0
  127. package/dist/legend/KeyLegendStrip.d.ts +36 -0
  128. package/dist/legend/KeyLegendStrip.js +82 -0
  129. package/dist/legend/index.d.ts +3 -0
  130. package/dist/legend/index.js +3 -0
  131. package/dist/legend/legend.css +148 -0
  132. package/dist/listing/CurrentDot.d.ts +15 -0
  133. package/dist/listing/CurrentDot.js +13 -0
  134. package/dist/listing/Listing.d.ts +230 -0
  135. package/dist/listing/Listing.js +265 -0
  136. package/dist/listing/PathParts.logic.d.ts +17 -0
  137. package/dist/listing/PathParts.logic.js +18 -0
  138. package/dist/listing/index.d.ts +10 -0
  139. package/dist/listing/index.js +10 -0
  140. package/dist/listing/listing.css +867 -0
  141. package/dist/menu/MenuQuery.logic.d.ts +69 -0
  142. package/dist/menu/MenuQuery.logic.js +75 -0
  143. package/dist/menu/fuzzyMatch.d.ts +31 -0
  144. package/dist/menu/fuzzyMatch.js +296 -0
  145. package/dist/menu/index.d.ts +9 -0
  146. package/dist/menu/index.js +9 -0
  147. package/dist/menu/menu.css +203 -0
  148. package/dist/menu/useBellBeat.d.ts +8 -0
  149. package/dist/menu/useBellBeat.js +26 -0
  150. package/dist/namecut/NameCut.d.ts +22 -0
  151. package/dist/namecut/NameCut.js +28 -0
  152. package/dist/namecut/NameCut.logic.d.ts +51 -0
  153. package/dist/namecut/NameCut.logic.js +120 -0
  154. package/dist/namecut/index.d.ts +3 -0
  155. package/dist/namecut/index.js +3 -0
  156. package/dist/namecut/namecut.css +67 -0
  157. package/dist/pager/Pager.d.ts +37 -0
  158. package/dist/pager/Pager.js +38 -0
  159. package/dist/pager/Pager.logic.d.ts +13 -0
  160. package/dist/pager/Pager.logic.js +63 -0
  161. package/dist/pager/index.d.ts +7 -0
  162. package/dist/pager/index.js +7 -0
  163. package/dist/pager/pager.css +62 -0
  164. package/dist/palette/Palette.d.ts +79 -0
  165. package/dist/palette/Palette.js +60 -0
  166. package/dist/palette/index.d.ts +6 -0
  167. package/dist/palette/index.js +6 -0
  168. package/dist/palette/palette.css +159 -0
  169. package/dist/pane/PaneActions.d.ts +104 -0
  170. package/dist/pane/PaneActions.js +62 -0
  171. package/dist/pane/PaneFrame.d.ts +51 -0
  172. package/dist/pane/PaneFrame.js +28 -0
  173. package/dist/pane/PaneKeys.d.ts +41 -0
  174. package/dist/pane/PaneKeys.js +104 -0
  175. package/dist/pane/PaneKeys.logic.d.ts +95 -0
  176. package/dist/pane/PaneKeys.logic.js +109 -0
  177. package/dist/pane/index.d.ts +11 -0
  178. package/dist/pane/index.js +11 -0
  179. package/dist/pane/usePaneKeys.d.ts +141 -0
  180. package/dist/pane/usePaneKeys.js +313 -0
  181. package/dist/run/RunHeader.d.ts +50 -0
  182. package/dist/run/RunHeader.js +31 -0
  183. package/dist/run/RunProgress.logic.d.ts +29 -0
  184. package/dist/run/RunProgress.logic.js +34 -0
  185. package/dist/run/index.d.ts +3 -0
  186. package/dist/run/index.js +3 -0
  187. package/dist/run/run.css +190 -0
  188. package/dist/segmented/SegmentedChoice.d.ts +22 -0
  189. package/dist/segmented/SegmentedChoice.js +31 -0
  190. package/dist/segmented/index.d.ts +2 -0
  191. package/dist/segmented/index.js +2 -0
  192. package/dist/segmented/segmented.css +49 -0
  193. package/dist/selectall/CheckRange.logic.d.ts +8 -0
  194. package/dist/selectall/CheckRange.logic.js +23 -0
  195. package/dist/selectall/SelectAllBar.d.ts +25 -0
  196. package/dist/selectall/SelectAllBar.js +24 -0
  197. package/dist/selectall/index.d.ts +7 -0
  198. package/dist/selectall/index.js +7 -0
  199. package/dist/selectall/selectall.css +31 -0
  200. package/dist/store/KeepUnchanged.logic.d.ts +19 -0
  201. package/dist/store/KeepUnchanged.logic.js +33 -0
  202. package/dist/store/SameProps.d.ts +15 -0
  203. package/dist/store/SameProps.js +46 -0
  204. package/dist/store/ValueStore.d.ts +17 -0
  205. package/dist/store/ValueStore.js +23 -0
  206. package/dist/store/index.d.ts +8 -0
  207. package/dist/store/index.js +8 -0
  208. package/dist/store/useStableHandlers.d.ts +13 -0
  209. package/dist/store/useStableHandlers.js +22 -0
  210. package/dist/styles.css +85 -0
  211. package/dist/tabs/PageTabs.d.ts +38 -0
  212. package/dist/tabs/PageTabs.js +33 -0
  213. package/dist/tabs/index.d.ts +2 -0
  214. package/dist/tabs/index.js +2 -0
  215. package/dist/tabs/tabs.css +64 -0
  216. package/dist/terminal/Terminal.d.ts +104 -0
  217. package/dist/terminal/Terminal.js +309 -0
  218. package/dist/terminal/Terminal.logic.d.ts +66 -0
  219. package/dist/terminal/Terminal.logic.js +156 -0
  220. package/dist/terminal/TerminalMenu.d.ts +36 -0
  221. package/dist/terminal/TerminalMenu.js +87 -0
  222. package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
  223. package/dist/terminal/TerminalMenu.logic.js +68 -0
  224. package/dist/terminal/TerminalScrollback.d.ts +10 -0
  225. package/dist/terminal/TerminalScrollback.js +11 -0
  226. package/dist/terminal/ghostty/LICENSE +21 -0
  227. package/dist/terminal/ghostty/core.d.ts +315 -0
  228. package/dist/terminal/ghostty/core.js +1189 -0
  229. package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
  230. package/dist/terminal/ghostty/fallbackColors.js +23 -0
  231. package/dist/terminal/ghostty/fonts/LICENSE +21 -0
  232. package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
  233. package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
  234. package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
  235. package/dist/terminal/ghostty/links.logic.d.ts +39 -0
  236. package/dist/terminal/ghostty/links.logic.js +84 -0
  237. package/dist/terminal/ghostty/renderer.d.ts +98 -0
  238. package/dist/terminal/ghostty/renderer.js +481 -0
  239. package/dist/terminal/ghostty/runtime.d.ts +126 -0
  240. package/dist/terminal/ghostty/runtime.js +346 -0
  241. package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
  242. package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
  243. package/dist/terminal/ghostty/surface.d.ts +285 -0
  244. package/dist/terminal/ghostty/surface.js +1565 -0
  245. package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
  246. package/dist/terminal/ghostty/surface.logic.js +392 -0
  247. package/dist/terminal/ghostty/vendor/LICENSE +21 -0
  248. package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
  249. package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
  250. package/dist/terminal/index.d.ts +12 -0
  251. package/dist/terminal/index.js +12 -0
  252. package/dist/terminal/terminal.css +169 -0
  253. package/dist/text/MarkedText.d.ts +14 -0
  254. package/dist/text/MarkedText.js +11 -0
  255. package/dist/text/highlightSegments.d.ts +13 -0
  256. package/dist/text/highlightSegments.js +29 -0
  257. package/dist/text/index.d.ts +3 -0
  258. package/dist/text/index.js +3 -0
  259. package/dist/text/text.css +11 -0
  260. package/dist/themes/attributes.d.ts +21 -0
  261. package/dist/themes/attributes.js +41 -0
  262. package/dist/themes/catalog.d.ts +125 -0
  263. package/dist/themes/catalog.js +940 -0
  264. package/dist/themes/color.d.ts +29 -0
  265. package/dist/themes/color.js +52 -0
  266. package/dist/themes/ids.d.ts +139 -0
  267. package/dist/themes/ids.js +59 -0
  268. package/dist/themes/index.d.ts +12 -0
  269. package/dist/themes/index.js +12 -0
  270. package/dist/themes/themes.generated.css +1830 -0
  271. package/dist/themes/tokens.d.ts +189 -0
  272. package/dist/themes/tokens.js +462 -0
  273. package/dist/tooltip/Tooltip.d.ts +21 -0
  274. package/dist/tooltip/Tooltip.js +105 -0
  275. package/dist/tooltip/Tooltip.logic.d.ts +49 -0
  276. package/dist/tooltip/Tooltip.logic.js +50 -0
  277. package/dist/tooltip/index.d.ts +3 -0
  278. package/dist/tooltip/index.js +3 -0
  279. package/dist/tooltip/tooltip.css +45 -0
  280. package/package.json +91 -4
@@ -0,0 +1,313 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
2
+ import { isTextEditingTarget } from '../keyboard/Keyboard.logic.js';
3
+ import { watchOverlays } from '../keyboard/OverlayWatch.js';
4
+ import { createValueStore, unheard } from '../store/ValueStore.js';
5
+ import { isTabStop, nextTabStop, pageRows, paneRow, paneRows, showRow } from './PaneKeys.js';
6
+ import { movedIndex, sameVerbs } from './PaneKeys.logic.js';
7
+ /** The sidebar's cursor row: the one moved to while it is listed, else the open row, else the first. */
8
+ const sidebarRow = (moved, keys, openKey) => (moved !== null && keys.includes(moved) ? moved : (openKey ?? keys[0] ?? null));
9
+ /** The sidebar pane: the frame around its home, which holds its other controls (Refresh) too. */
10
+ const sidebarPane = (root) => root.querySelector('[data-pane-home="sidebar"]')?.closest('.pane') ?? null;
11
+ /**
12
+ * The keyboard of a view with a sidebar beside a page: each pane has a
13
+ * cursor row the arrows move and the pointer shares (`data-row-key` rows;
14
+ * the main pane's through `RowCursorContext`), Tab and Shift-Tab switch
15
+ * panes and walk the page's other controls, and the sidebar's too where
16
+ * the view asks (`sidebarStops`, `nextTabStop`), and the view's own
17
+ * actions run through `run`. The listener sits on the window in the capture
18
+ * phase and acts only while the view is shown, no overlay is open
19
+ * (`watchOverlays`), no input method is composing, and the key is aimed at
20
+ * the view or at nothing. A text field keeps every key but Tab, a
21
+ * terminal that takes input (a text field inside `.terminal`) keeps Tab
22
+ * too, and a focused control keeps its own arrows and Return. Each pane's
23
+ * home is the element marked `data-pane-home` (`sidebar` for the
24
+ * sidebar's), which the keys hand the focus to.
25
+ */
26
+ export function usePaneKeys(options) {
27
+ const { shown, loaded, page, sidebarKeys, openKey } = options;
28
+ const [activePane, setActivePane] = useState(options.initialPane);
29
+ // Both panes' cursor rows live outside React state, so a move draws only
30
+ // the rows that follow them, and the view too where it reads the rows in
31
+ // render (`cursorInRender`). The sidebar's is the row moved to; null
32
+ // stands on the open page's row.
33
+ const [sidebarStore] = useState(() => createValueStore(null));
34
+ const [cursorStore] = useState(() => createValueStore(null));
35
+ const inRender = options.cursorInRender !== false;
36
+ const sidebarMoved = useSyncExternalStore(inRender ? sidebarStore.subscribe : unheard, sidebarStore.get);
37
+ const mainCursor = useSyncExternalStore(inRender ? cursorStore.subscribe : unheard, cursorStore.get);
38
+ const [offered, setOffered] = useState(options.noVerbs);
39
+ const rootRef = useRef(null);
40
+ const mainRef = useRef(null);
41
+ const mainKey = inRender && mainCursor?.page === page ? mainCursor.key : null;
42
+ const sidebarKey = inRender ? sidebarRow(sidebarMoved, sidebarKeys, openKey) : null;
43
+ const sidebarRest = openKey ?? sidebarKeys[0] ?? null;
44
+ const optionsRef = useRef(options);
45
+ optionsRef.current = options;
46
+ // The sidebar's cursor row as its rows read it, from the latest render's
47
+ // keys and open row and the row moved to now; the last answer is kept, so
48
+ // every row asking after one move costs one look through the keys.
49
+ const sidebarSeen = useRef(null);
50
+ // The sidebar's cursor row its followers were last told of.
51
+ const [sidebarShown] = useState(() => createValueStore(null));
52
+ const sidebarCursor = useMemo(() => ({
53
+ current: () => {
54
+ const moved = sidebarStore.get();
55
+ const { sidebarKeys: keys, openKey: open } = optionsRef.current;
56
+ const seen = sidebarSeen.current;
57
+ if (seen?.moved === moved && seen.keys === keys && seen.openKey === open)
58
+ return seen.row;
59
+ const row = sidebarRow(moved, keys, open);
60
+ sidebarSeen.current = { moved, keys, openKey: open, row };
61
+ return row;
62
+ },
63
+ subscribe: sidebarShown.subscribe,
64
+ point: sidebarStore.set
65
+ }), [sidebarStore, sidebarShown]);
66
+ // The sidebar's followers hear a change of its cursor row, whether a move
67
+ // or the keys and open row a render hands in made it. The render's is
68
+ // told once its followers have taken in what they drew (a passive
69
+ // effect, after theirs), so a row that drew with the render reads the
70
+ // same row again and draws no more.
71
+ useEffect(() => sidebarStore.subscribe(() => sidebarShown.set(sidebarCursor.current())), [sidebarStore, sidebarShown, sidebarCursor]);
72
+ useEffect(() => {
73
+ sidebarShown.set(sidebarCursor.current());
74
+ });
75
+ /** Puts the main pane's cursor on a row of a page; a move to where it stands tells no one. */
76
+ const setMainCursor = useCallback((next) => {
77
+ const held = cursorStore.get();
78
+ if (held?.page !== next.page || held.key !== next.key)
79
+ cursorStore.set(next);
80
+ }, [cursorStore]);
81
+ // Settles the main pane's cursor on the rendered rows and reads its
82
+ // verbs (below); the latest render's, so a row coming or going with a
83
+ // render of its page alone settles it with the view's latest state.
84
+ const settleMainRef = useRef(() => undefined);
85
+ const settlePending = useRef(false);
86
+ const rowCursor = useMemo(() => ({
87
+ current: () => {
88
+ const held = cursorStore.get();
89
+ return held?.page === page ? held.key : null;
90
+ },
91
+ subscribe: cursorStore.subscribe,
92
+ point: (key) => setMainCursor({ page, key }),
93
+ // Once per commit, after it: a row going is still in the document
94
+ // while its cleanup runs, and every row of a listing calls this.
95
+ rowsChanged: () => {
96
+ if (settlePending.current)
97
+ return;
98
+ settlePending.current = true;
99
+ queueMicrotask(() => {
100
+ settlePending.current = false;
101
+ settleMainRef.current();
102
+ });
103
+ }
104
+ }), [cursorStore, page, setMainCursor]);
105
+ const pointMain = rowCursor.point;
106
+ /** Reads what the main pane's cursor row and path bar offer the keys now. */
107
+ const readOffered = useCallback((key) => {
108
+ const next = optionsRef.current.readVerbs(mainRef.current, key);
109
+ setOffered((current) => (sameVerbs(current, next) ? current : next));
110
+ }, []);
111
+ // The main pane's cursor needs the rendered rows: while the pane is
112
+ // active it stands on a row, the first when its own is gone. The legend
113
+ // then reads what that row and the path bar offer. The rows and their
114
+ // controls follow the page and what the view names in `follows`, or,
115
+ // where the cursor is out of render, whatever the view drew; a row its
116
+ // page alone adds or removes settles it too (`rowsChanged`).
117
+ // `follows` is the view's own list of what the rows follow, the same length every render.
118
+ const readAfter = inRender ? [activePane, mainKey, page, ...(options.follows ?? [])] : undefined;
119
+ settleMainRef.current = () => {
120
+ const main = mainRef.current;
121
+ const rows = paneRows(main);
122
+ const key = rowCursor.current();
123
+ if (activePane === 'main' && rows.length > 0 && paneRow(main, key) === null) {
124
+ const first = rows[0]?.dataset.rowKey;
125
+ if (first !== undefined)
126
+ setMainCursor({ page, key: first });
127
+ return;
128
+ }
129
+ readOffered(key);
130
+ };
131
+ // eslint-disable-next-line react-hooks/exhaustive-deps
132
+ useLayoutEffect(() => settleMainRef.current(), readAfter);
133
+ // Where the view leaves the cursor out of render, a move reads the verbs
134
+ // at once: the rows' controls are drawn whichever row is the cursor's,
135
+ // so the row the cursor lands on already shows what it offers.
136
+ useEffect(() => {
137
+ if (inRender)
138
+ return undefined;
139
+ return cursorStore.subscribe(() => {
140
+ const held = cursorStore.get();
141
+ readOffered(held?.page === optionsRef.current.page ? held.key : null);
142
+ });
143
+ }, [inRender, cursorStore, readOffered]);
144
+ const focusPane = (pane) => {
145
+ setActivePane(pane);
146
+ if (pane === 'main')
147
+ sidebarStore.set(null);
148
+ const home = pane === 'sidebar'
149
+ ? rootRef.current?.querySelector('[data-pane-home="sidebar"]')
150
+ : (mainRef.current?.querySelector('[data-pane-home]') ?? mainRef.current);
151
+ home?.focus({ preventScroll: true });
152
+ };
153
+ // Coming into view, the app focuses the view; the active pane's home
154
+ // takes it so the first key lands there, and again when the first
155
+ // data replaces the panes the focus was in. Only a focus the view
156
+ // already holds (or one lost with the replaced panes) is handed on: a
157
+ // switcher tab the arrows walk keeps it, and so does a dialog or palette
158
+ // open over the window, whose keys work only while it holds the focus.
159
+ useEffect(() => {
160
+ const root = rootRef.current;
161
+ const focused = document.activeElement;
162
+ const onView = focused === null ||
163
+ focused === document.body ||
164
+ (root !== null && (focused.contains(root) || root.contains(focused)));
165
+ if (shown && onView && !watchOverlays(document).overlayOpen())
166
+ focusPane(activePane);
167
+ // Only the view being shown or its first data hands the focus on.
168
+ // eslint-disable-next-line react-hooks/exhaustive-deps
169
+ }, [shown, loaded]);
170
+ const move = (to, pane) => {
171
+ const root = rootRef.current;
172
+ if (pane === 'sidebar') {
173
+ const keys = optionsRef.current.sidebarKeys;
174
+ const current = sidebarCursor.current();
175
+ const at = current === null ? -1 : keys.indexOf(current);
176
+ const next = movedIndex(keys.length, at, to, pageRows(root));
177
+ const key = next === null ? undefined : keys[next];
178
+ if (key === undefined)
179
+ return;
180
+ sidebarStore.set(key);
181
+ showRow(paneRow(root?.querySelector('[data-pane-home="sidebar"]') ?? null, key));
182
+ return;
183
+ }
184
+ const rows = paneRows(mainRef.current);
185
+ const current = rowCursor.current();
186
+ const at = rows.findIndex((entry) => entry.dataset.rowKey === current);
187
+ const next = movedIndex(rows.length, at, to, pageRows(mainRef.current));
188
+ const target = next === null ? undefined : rows[next];
189
+ const key = target?.dataset.rowKey;
190
+ if (target === undefined || key === undefined)
191
+ return;
192
+ setMainCursor({ page, key });
193
+ showRow(target);
194
+ };
195
+ // The view's keys, in the capture phase while it is shown and nothing
196
+ // modal is open, for a key aimed at the view or at nothing.
197
+ const keysRef = useRef(() => undefined);
198
+ keysRef.current = (event) => {
199
+ const root = rootRef.current;
200
+ const main = mainRef.current;
201
+ const current = optionsRef.current;
202
+ if (!current.shown || event.isComposing || root === null || main === null)
203
+ return;
204
+ if (watchOverlays(document).overlayOpen())
205
+ return;
206
+ const node = event.target instanceof Element ? event.target : null;
207
+ if (node !== null && !node.contains(root) && !root.contains(node))
208
+ return;
209
+ const typing = isTextEditingTarget(node);
210
+ // A terminal that takes input is a program's keyboard, Tab included.
211
+ if (typing && node?.closest('.terminal') != null)
212
+ return;
213
+ const action = current.readKey(event);
214
+ if (action === null)
215
+ return;
216
+ const sidebar = sidebarPane(root);
217
+ const home = main.querySelector('[data-pane-home]') ?? main;
218
+ const inSidebar = node !== null && sidebar?.contains(node) === true;
219
+ const inMain = node !== null && main.contains(node);
220
+ const pane = inSidebar ? 'sidebar' : inMain ? 'main' : activePane;
221
+ // Where in its pane the key was aimed: the pane's home (the listing,
222
+ // the frame, or nothing in particular), a control in one of its rows,
223
+ // or another control, which keeps its own keys.
224
+ const inRow = (node?.closest('[data-row-key]') ?? null) !== null;
225
+ const onHome = node === null ||
226
+ node.contains(root) ||
227
+ !(inSidebar || inMain) ||
228
+ node === home ||
229
+ node === main ||
230
+ (inSidebar && node.closest('[data-pane-home="sidebar"]') !== null) ||
231
+ (inMain &&
232
+ !inRow &&
233
+ node.closest('button, input, select, textarea, summary, a, [tabindex]') === home);
234
+ if (action.kind === 'switch-pane') {
235
+ const sidebarHome = root.querySelector('[data-pane-home="sidebar"]');
236
+ const walked = current.sidebarStops === true && sidebar !== null && sidebarHome !== null
237
+ ? { pane: sidebar, home: sidebarHome }
238
+ : null;
239
+ // A control that is a Tab stop goes on from itself. Otherwise a
240
+ // sidebar control (Refresh) switches panes as the listing does, and a
241
+ // row's control out of the Tab order goes on from the page's home.
242
+ const stop = node !== null && isTabStop(node) ? node : null;
243
+ const from = pane === 'sidebar'
244
+ ? walked !== null && stop !== null && !inRow
245
+ ? stop
246
+ : 'sidebar'
247
+ : onHome || (inRow && stop === null)
248
+ ? 'page'
249
+ : node;
250
+ const back = 'back' in action && action.back === true;
251
+ const to = nextTabStop(main, home, from, back, walked);
252
+ event.preventDefault();
253
+ event.stopPropagation();
254
+ if (to === 'sidebar' || to === 'page')
255
+ focusPane(to === 'sidebar' ? 'sidebar' : 'main');
256
+ else
257
+ to.focus();
258
+ return;
259
+ }
260
+ if (typing)
261
+ return;
262
+ const isMove = action.kind === 'move';
263
+ // A control keeps its own arrows and Return; the arrows go on from a
264
+ // row's control, which hands the focus to the pane's home.
265
+ if (current.cursorKey(action) && !onHome && !(inRow && action.kind !== 'enter'))
266
+ return;
267
+ event.preventDefault();
268
+ event.stopPropagation();
269
+ if (event.repeat && !isMove)
270
+ return;
271
+ if (pane !== activePane)
272
+ setActivePane(pane);
273
+ if (inRow && isMove) {
274
+ (pane === 'sidebar'
275
+ ? root.querySelector('[data-pane-home="sidebar"]')
276
+ : home)?.focus({
277
+ preventScroll: true
278
+ });
279
+ }
280
+ current.run(action, pane);
281
+ };
282
+ useEffect(() => {
283
+ const listener = (event) => keysRef.current(event);
284
+ window.addEventListener('keydown', listener, true);
285
+ return () => window.removeEventListener('keydown', listener, true);
286
+ }, []);
287
+ return {
288
+ rootRef,
289
+ mainRef,
290
+ activePane,
291
+ sidebarKey,
292
+ sidebarCursor,
293
+ sidebarRest,
294
+ mainKey,
295
+ offered,
296
+ activateSidebar: () => setActivePane('sidebar'),
297
+ activateMain: () => {
298
+ setActivePane('main');
299
+ sidebarStore.set(null);
300
+ },
301
+ focusPane,
302
+ pointSidebar: sidebarStore.set,
303
+ leaveSidebar: () => {
304
+ if (activePane !== 'sidebar')
305
+ sidebarStore.set(null);
306
+ },
307
+ restSidebar: () => sidebarStore.set(null),
308
+ pointMain,
309
+ rowCursor,
310
+ placeMain: (onPage, key) => setMainCursor({ page: onPage, key }),
311
+ move
312
+ };
313
+ }
@@ -0,0 +1,50 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import type { RunState } from './RunProgress.logic.js';
3
+ /** The header's optional bar: how much of the run is done, and what it measures. */
4
+ export interface RunHeaderBar {
5
+ /**
6
+ * Fraction done, in [0, 1]; null for a run that reports no fraction while
7
+ * it works (a compression, a delete on a server, a transfer still sizing
8
+ * its sources): the bar is then the activity stripes, which move only
9
+ * while the run goes on (`ActivityBar`).
10
+ */
11
+ readonly fraction: number | null;
12
+ /** The bar's accessible name ("Whole transfer"). */
13
+ readonly label: string;
14
+ }
15
+ /** Props for {@link RunHeader}; every word is the caller's. */
16
+ export interface RunHeaderProps {
17
+ /** Where the run stands; picks the glyph, the colours, and whether the stripes move. */
18
+ readonly state: RunState;
19
+ /** One sentence: where the run stands, or its outcome once it settles. */
20
+ readonly headline: string;
21
+ /**
22
+ * What the status region says instead of the headline, for a headline
23
+ * that changes as often as a figure does (a transfer's time left): the
24
+ * headline then stays readable but is not announced, and only a change
25
+ * of this text is. Left out, the headline is announced.
26
+ */
27
+ readonly announcement?: string;
28
+ /** The one big figure at the right edge (elapsed time, a percentage), or none. */
29
+ readonly figure?: string | null;
30
+ /** Under a failed headline, why it failed; announced with it. */
31
+ readonly reason?: string | null;
32
+ /** Left out where nothing reports a fraction. */
33
+ readonly bar?: RunHeaderBar;
34
+ /** Short facts in a row, separated by dots; the first gives way when space runs out. */
35
+ readonly facts?: readonly ReactNode[];
36
+ }
37
+ /**
38
+ * The progress header a dialog watching work in progress opens its body
39
+ * with (an install, a transfer, an export): the state's glyph and one
40
+ * sentence, one big figure at the right edge, an optional bar, a row of
41
+ * facts, and, on failure, the reason under the sentence.
42
+ *
43
+ * The sentence (and a failure's reason) is a status region, or an alert
44
+ * once the run failed, so each change of state is announced once; the
45
+ * figure sits outside it, so a ticking clock is never read out, and so does
46
+ * a sentence that ticks too, given an `announcement` to say instead. Styled
47
+ * by the `.run-header` rules in `@bigpixelrocket/uiok/styles.css`; the type family is the
48
+ * surrounding dialog's own, like the frame around it.
49
+ */
50
+ export declare function RunHeader({ state, headline, announcement, figure, reason, bar, facts }: RunHeaderProps): ReactElement;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CircleCheck, CirclePause, CircleSlash, CircleX, Hourglass, LoaderCircle } from 'lucide-react';
3
+ import { ActivityBar } from '../activity/ActivityBar.js';
4
+ /** Each run state's glyph; the running one spins unless motion is reduced. */
5
+ const STATE_ICONS = {
6
+ waiting: Hourglass,
7
+ running: LoaderCircle,
8
+ paused: CirclePause,
9
+ done: CircleCheck,
10
+ failed: CircleX,
11
+ stopped: CircleSlash
12
+ };
13
+ /**
14
+ * The progress header a dialog watching work in progress opens its body
15
+ * with (an install, a transfer, an export): the state's glyph and one
16
+ * sentence, one big figure at the right edge, an optional bar, a row of
17
+ * facts, and, on failure, the reason under the sentence.
18
+ *
19
+ * The sentence (and a failure's reason) is a status region, or an alert
20
+ * once the run failed, so each change of state is announced once; the
21
+ * figure sits outside it, so a ticking clock is never read out, and so does
22
+ * a sentence that ticks too, given an `announcement` to say instead. Styled
23
+ * by the `.run-header` rules in `@bigpixelrocket/uiok/styles.css`; the type family is the
24
+ * surrounding dialog's own, like the frame around it.
25
+ */
26
+ export function RunHeader({ state, headline, announcement, figure = null, reason = null, bar, facts = [] }) {
27
+ const Icon = STATE_ICONS[state];
28
+ const failed = state === 'failed';
29
+ const role = failed ? 'alert' : 'status';
30
+ return (_jsxs("div", { className: "run-header", "data-state": state, children: [_jsxs("div", { className: "run-header-top", children: [_jsx(Icon, { "aria-hidden": true, className: "run-header-glyph" }), _jsxs("div", { className: "run-header-said", children: [announcement !== undefined && _jsx("span", { className: "run-header-headline", children: headline }), _jsxs("div", { role: role, children: [announcement === undefined ? (_jsx("span", { className: "run-header-headline", children: headline })) : (_jsx("span", { className: "visually-hidden", children: announcement })), reason !== null && reason !== '' && _jsx("p", { className: "run-header-reason", children: reason })] }, role)] }), figure !== null && _jsx("span", { className: "run-header-figure", children: figure })] }), bar && (_jsx(ActivityBar, { className: "run-header-bar", fillClassName: "run-header-fill", fraction: bar.fraction, label: bar.label, moving: state === 'running' })), facts.length > 0 && (_jsx("div", { className: bar ? 'run-header-facts' : 'run-header-facts indented', children: facts.map((fact, index) => (_jsx("span", { className: "run-header-fact", children: fact }, index))) }))] }));
31
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * What every view that watches work in progress shares: where a run stands
3
+ * and how long it has taken, for the progress header (`RunHeader`).
4
+ */
5
+ /**
6
+ * Where a run stands: waiting its turn, running, paused, or settled one way
7
+ * or another (done, failed, or stopped before it finished).
8
+ */
9
+ export type RunState = 'waiting' | 'running' | 'paused' | 'done' | 'failed' | 'stopped';
10
+ /** Settled: done, failed, or stopped. A settled run never changes again. */
11
+ export declare function isSettledRun(state: RunState): boolean;
12
+ /** The start and finish a run reports, in epoch milliseconds; null until each happens. */
13
+ export interface RunTimes {
14
+ readonly startedMs: number | null;
15
+ readonly finishedMs: number | null;
16
+ }
17
+ /**
18
+ * How long a run has taken: from its start to `nowMs` while it goes on, from
19
+ * its start to its finish once it settles. Null before it starts (waiting
20
+ * its turn) and for a settled run that never reported its finish, so a
21
+ * settled time never keeps counting.
22
+ */
23
+ export declare function runElapsedMs(times: RunTimes, state: RunState, nowMs: number): number | null;
24
+ /**
25
+ * A duration as a clock: minutes and seconds ("0:07", "12:03"), with hours
26
+ * in front once there is one ("1:02:03"). Partial seconds are dropped, so
27
+ * the clock never shows a second that has not passed.
28
+ */
29
+ export declare function runClock(ms: number): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * What every view that watches work in progress shares: where a run stands
3
+ * and how long it has taken, for the progress header (`RunHeader`).
4
+ */
5
+ /** Settled: done, failed, or stopped. A settled run never changes again. */
6
+ export function isSettledRun(state) {
7
+ return state === 'done' || state === 'failed' || state === 'stopped';
8
+ }
9
+ /**
10
+ * How long a run has taken: from its start to `nowMs` while it goes on, from
11
+ * its start to its finish once it settles. Null before it starts (waiting
12
+ * its turn) and for a settled run that never reported its finish, so a
13
+ * settled time never keeps counting.
14
+ */
15
+ export function runElapsedMs(times, state, nowMs) {
16
+ if (state === 'waiting' || times.startedMs === null)
17
+ return null;
18
+ const end = isSettledRun(state) ? times.finishedMs : nowMs;
19
+ return end === null ? null : Math.max(end - times.startedMs, 0);
20
+ }
21
+ /**
22
+ * A duration as a clock: minutes and seconds ("0:07", "12:03"), with hours
23
+ * in front once there is one ("1:02:03"). Partial seconds are dropped, so
24
+ * the clock never shows a second that has not passed.
25
+ */
26
+ export function runClock(ms) {
27
+ const seconds = Math.floor(Math.max(ms, 0) / 1000);
28
+ const hours = Math.floor(seconds / 3600);
29
+ const minutes = Math.floor((seconds % 3600) / 60);
30
+ const pad = (part) => String(part).padStart(2, '0');
31
+ return hours > 0
32
+ ? `${hours}:${pad(minutes)}:${pad(seconds % 60)}`
33
+ : `${minutes}:${pad(seconds % 60)}`;
34
+ }
@@ -0,0 +1,3 @@
1
+ /** Work in progress: the `RunHeader` a progress view opens with, and the run state helpers it reads. */
2
+ export { RunHeader, type RunHeaderBar, type RunHeaderProps } from './RunHeader.js';
3
+ export { isSettledRun, runClock, runElapsedMs, type RunState, type RunTimes } from './RunProgress.logic.js';
@@ -0,0 +1,3 @@
1
+ /** Work in progress: the `RunHeader` a progress view opens with, and the run state helpers it reads. */
2
+ export { RunHeader } from './RunHeader.js';
3
+ export { isSettledRun, runClock, runElapsedMs } from './RunProgress.logic.js';
@@ -0,0 +1,190 @@
1
+ /* ---- Progress header (RunHeader) ----
2
+
3
+ The header a view watching work in progress opens with: the state's
4
+ glyph and sentence, the big figure at the right edge, the optional bar,
5
+ and the facts. It keeps the surrounding dialog's type family, like the
6
+ frame; sizes, weights, and colours are its own. */
7
+ .run-header {
8
+ display: flex;
9
+ flex: none;
10
+ flex-direction: column;
11
+ gap: 6px;
12
+ min-width: 0;
13
+ }
14
+
15
+ .run-header-top {
16
+ display: grid;
17
+ grid-template-columns: auto minmax(0, 1fr) auto;
18
+ align-items: start;
19
+ column-gap: 8px;
20
+ }
21
+
22
+ /* 18px on the headline's 20px line. */
23
+ .run-header-glyph {
24
+ width: 18px;
25
+ height: 18px;
26
+ margin-top: 1px;
27
+ stroke-width: 2;
28
+ color: var(--text-dim);
29
+ }
30
+
31
+ /* The running glyph turns in the accent; it stands still under reduced
32
+ motion (below), where the clock and the counts say the run is working. */
33
+ .run-header[data-state='running'] .run-header-glyph {
34
+ color: var(--accent);
35
+ animation: run-header-spin 1s linear infinite;
36
+ }
37
+
38
+ @keyframes run-header-spin {
39
+ to {
40
+ transform: rotate(360deg);
41
+ }
42
+ }
43
+
44
+ /* The done sentence keeps the plain text colour: a light theme's green can
45
+ miss 4.5:1 as text on the dialog surface, so only the glyph (and the bar)
46
+ carries it. The red meets 4.5:1 in every theme. */
47
+ .run-header[data-state='done'] .run-header-glyph {
48
+ color: var(--success);
49
+ }
50
+
51
+ .run-header[data-state='failed'] .run-header-glyph,
52
+ .run-header[data-state='failed'] .run-header-headline {
53
+ color: var(--danger);
54
+ }
55
+
56
+ .run-header-said {
57
+ min-width: 0;
58
+ }
59
+
60
+ .run-header-headline {
61
+ display: block;
62
+ overflow: hidden;
63
+ color: var(--text);
64
+ font-size: 14px;
65
+ font-weight: 600;
66
+ line-height: 20px;
67
+ text-overflow: ellipsis;
68
+ white-space: nowrap;
69
+ }
70
+
71
+ .run-header-reason {
72
+ margin: 4px 0 0;
73
+ color: var(--text);
74
+ font-size: 12px;
75
+ line-height: 1.5;
76
+ overflow-wrap: anywhere;
77
+ }
78
+
79
+ /* The figure reads live while the run goes on and dims once it is history
80
+ (or before it starts). */
81
+ .run-header-figure {
82
+ color: var(--text);
83
+ font-size: 18px;
84
+ font-variant-numeric: tabular-nums;
85
+ font-weight: 600;
86
+ line-height: 20px;
87
+ white-space: nowrap;
88
+ }
89
+
90
+ .run-header:is(
91
+ [data-state='waiting'],
92
+ [data-state='done'],
93
+ [data-state='failed'],
94
+ [data-state='stopped']
95
+ )
96
+ .run-header-figure {
97
+ color: var(--text-dim);
98
+ }
99
+
100
+ .run-header-bar {
101
+ height: 8px;
102
+ border-radius: 4px;
103
+ background: var(--cursor-bg);
104
+ overflow: hidden;
105
+ }
106
+
107
+ .run-header-fill {
108
+ height: 100%;
109
+ border-radius: 4px;
110
+ background: var(--accent);
111
+ transition: width 0.1s linear;
112
+ }
113
+
114
+ /* A bar that stopped short (paused, failed, or stopped) dims: it no longer
115
+ moves. Stripes dim through their own colour (below), which this fill
116
+ colour would otherwise paint over. */
117
+ .run-header:is([data-state='paused'], [data-state='failed'], [data-state='stopped'])
118
+ .run-header-bar:not(.indeterminate)
119
+ .run-header-fill {
120
+ background: var(--text-dim);
121
+ }
122
+
123
+ /* The stripes of a run that stopped short stand still and dim, through the
124
+ hooks the activity stripes read. */
125
+ .run-header:is([data-state='paused'], [data-state='failed'], [data-state='stopped'])
126
+ .indeterminate
127
+ > .activity-stripes {
128
+ --stripe-ink: var(--text-dim);
129
+ --stripe-ground: 16%;
130
+ }
131
+
132
+ .run-header[data-state='done'] .run-header-fill {
133
+ background: var(--success);
134
+ }
135
+
136
+ .run-header-facts {
137
+ display: flex;
138
+ align-items: center;
139
+ gap: 8px;
140
+ min-width: 0;
141
+ overflow: hidden;
142
+ color: var(--text-dim);
143
+ font-size: 12px;
144
+ font-variant-numeric: tabular-nums;
145
+ line-height: 18px;
146
+ white-space: nowrap;
147
+ }
148
+
149
+ /* Under a bar the facts sit closer to it than the bar sits to the
150
+ sentence: they describe the bar. */
151
+ .run-header-bar + .run-header-facts {
152
+ margin-top: -2px;
153
+ }
154
+
155
+ /* Without a bar the facts line up under the sentence, past the glyph. */
156
+ .run-header-facts.indented {
157
+ padding-left: 26px;
158
+ }
159
+
160
+ .run-header-fact {
161
+ flex: none;
162
+ }
163
+
164
+ .run-header-fact:first-child {
165
+ flex: 0 1 auto;
166
+ min-width: 0;
167
+ overflow: hidden;
168
+ text-overflow: ellipsis;
169
+ }
170
+
171
+ .run-header-fact + .run-header-fact::before {
172
+ content: '·';
173
+ margin-right: 8px;
174
+ color: var(--row-meta-text);
175
+ }
176
+
177
+ .run-header-fact code {
178
+ color: var(--text);
179
+ font-family: var(--font-mono);
180
+ }
181
+
182
+ @media (prefers-reduced-motion: reduce) {
183
+ .run-header[data-state='running'] .run-header-glyph {
184
+ animation: none;
185
+ }
186
+
187
+ .run-header-fill {
188
+ transition: none;
189
+ }
190
+ }