@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.
Files changed (158) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/dist/button/TextLink.d.ts +27 -0
  3. package/dist/button/TextLink.js +15 -0
  4. package/dist/button/button.css +48 -0
  5. package/dist/button/index.d.ts +2 -1
  6. package/dist/button/index.js +2 -1
  7. package/dist/charts/Sparkline.d.ts +20 -0
  8. package/dist/charts/Sparkline.js +12 -0
  9. package/dist/charts/Sparkline.logic.d.ts +9 -0
  10. package/dist/charts/Sparkline.logic.js +27 -0
  11. package/dist/charts/charts.css +17 -0
  12. package/dist/charts/index.d.ts +2 -0
  13. package/dist/charts/index.js +2 -0
  14. package/dist/dialog/ConfirmDialog.d.ts +17 -1
  15. package/dist/dialog/ConfirmDialog.js +10 -4
  16. package/dist/dialog/DialogLists.d.ts +8 -1
  17. package/dist/dialog/DialogLists.js +3 -2
  18. package/dist/dialog/ModalDialog.d.ts +8 -0
  19. package/dist/dialog/ModalDialog.js +4 -2
  20. package/dist/dialog/ProgressDialog.d.ts +34 -0
  21. package/dist/dialog/ProgressDialog.js +40 -0
  22. package/dist/dialog/TypedNameDialog.d.ts +36 -0
  23. package/dist/dialog/TypedNameDialog.js +17 -0
  24. package/dist/dialog/index.d.ts +5 -2
  25. package/dist/dialog/index.js +4 -1
  26. package/dist/field/Switch.d.ts +26 -0
  27. package/dist/field/Switch.js +20 -0
  28. package/dist/field/field.css +110 -2
  29. package/dist/field/index.d.ts +3 -2
  30. package/dist/field/index.js +3 -2
  31. package/dist/filter/filter.css +16 -0
  32. package/dist/frame/AppRoot.d.ts +44 -0
  33. package/dist/frame/AppRoot.js +26 -0
  34. package/dist/frame/Dock.d.ts +88 -0
  35. package/dist/frame/Dock.js +129 -0
  36. package/dist/frame/FilterChips.d.ts +28 -0
  37. package/dist/frame/FilterChips.js +14 -0
  38. package/dist/frame/PageParts.d.ts +69 -0
  39. package/dist/frame/PageParts.js +60 -0
  40. package/dist/frame/PaneSplit.d.ts +74 -0
  41. package/dist/frame/PaneSplit.js +197 -0
  42. package/dist/frame/SidebarResizer.d.ts +35 -0
  43. package/dist/frame/SidebarResizer.js +43 -0
  44. package/dist/frame/StatusNotice.d.ts +20 -0
  45. package/dist/frame/StatusNotice.js +13 -0
  46. package/dist/frame/Tree.d.ts +140 -0
  47. package/dist/frame/Tree.js +141 -0
  48. package/dist/frame/TreeToggle.d.ts +18 -0
  49. package/dist/frame/TreeToggle.js +17 -0
  50. package/dist/frame/WindowFrame.d.ts +57 -0
  51. package/dist/frame/WindowFrame.js +19 -0
  52. package/dist/frame/frame.css +801 -0
  53. package/dist/frame/index.d.ts +22 -0
  54. package/dist/frame/index.js +22 -0
  55. package/dist/frame/sharedRef.d.ts +8 -0
  56. package/dist/frame/sharedRef.js +26 -0
  57. package/dist/grid/DataGrid.d.ts +10 -2
  58. package/dist/grid/DataGrid.js +47 -13
  59. package/dist/grid/DataGrid.logic.d.ts +16 -0
  60. package/dist/grid/DataGrid.logic.js +28 -0
  61. package/dist/grid/grid.css +128 -4
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.js +4 -0
  64. package/dist/labels/UiokLabels.d.ts +6 -0
  65. package/dist/labels/UiokLabels.js +5 -1
  66. package/dist/labels/dialog.d.ts +12 -0
  67. package/dist/labels/dialog.js +7 -1
  68. package/dist/labels/index.d.ts +2 -0
  69. package/dist/labels/index.js +2 -0
  70. package/dist/labels/keys.js +2 -0
  71. package/dist/labels/paneTabs.d.ts +27 -0
  72. package/dist/labels/paneTabs.js +10 -0
  73. package/dist/labels/selectAll.d.ts +4 -1
  74. package/dist/labels/selectAll.js +1 -1
  75. package/dist/labels/settings.d.ts +46 -0
  76. package/dist/labels/settings.js +29 -0
  77. package/dist/legend/KeyLegendStrip.d.ts +9 -1
  78. package/dist/legend/KeyLegendStrip.js +119 -5
  79. package/dist/legend/legend.css +52 -0
  80. package/dist/listing/EmptyState.d.ts +40 -0
  81. package/dist/listing/EmptyState.js +14 -0
  82. package/dist/listing/Listing.d.ts +23 -5
  83. package/dist/listing/Listing.js +11 -8
  84. package/dist/listing/index.d.ts +3 -1
  85. package/dist/listing/index.js +3 -1
  86. package/dist/listing/listing.css +172 -5
  87. package/dist/log/LogWell.d.ts +34 -0
  88. package/dist/log/LogWell.js +39 -0
  89. package/dist/log/LogWell.logic.d.ts +16 -0
  90. package/dist/log/LogWell.logic.js +26 -0
  91. package/dist/log/index.d.ts +8 -0
  92. package/dist/log/index.js +8 -0
  93. package/dist/log/log.css +57 -0
  94. package/dist/pane/Pane.d.ts +49 -0
  95. package/dist/pane/Pane.js +17 -0
  96. package/dist/pane/PaneActions.d.ts +3 -1
  97. package/dist/pane/PaneActions.js +6 -5
  98. package/dist/pane/PaneKeys.d.ts +10 -3
  99. package/dist/pane/PaneKeys.js +26 -7
  100. package/dist/pane/PaneTabs.d.ts +92 -0
  101. package/dist/pane/PaneTabs.js +326 -0
  102. package/dist/pane/PaneTabs.logic.d.ts +97 -0
  103. package/dist/pane/PaneTabs.logic.js +158 -0
  104. package/dist/pane/index.d.ts +7 -1
  105. package/dist/pane/index.js +7 -1
  106. package/dist/pane/panetabs.css +408 -0
  107. package/dist/pane/usePaneKeys.js +9 -11
  108. package/dist/pane/useTabDrag.d.ts +49 -0
  109. package/dist/pane/useTabDrag.js +306 -0
  110. package/dist/segmented/SegmentedChoice.d.ts +8 -1
  111. package/dist/segmented/SegmentedChoice.js +7 -4
  112. package/dist/shell/AboutWindow.d.ts +21 -0
  113. package/dist/shell/AboutWindow.js +10 -0
  114. package/dist/shell/LanguageChoice.d.ts +27 -0
  115. package/dist/shell/LanguageChoice.js +17 -0
  116. package/dist/shell/LoadFailure.d.ts +22 -0
  117. package/dist/shell/LoadFailure.js +15 -0
  118. package/dist/shell/Lockup.d.ts +52 -0
  119. package/dist/shell/Lockup.js +30 -0
  120. package/dist/shell/SettingsDialog.d.ts +97 -0
  121. package/dist/shell/SettingsDialog.js +219 -0
  122. package/dist/shell/SettingsDialog.logic.d.ts +33 -0
  123. package/dist/shell/SettingsDialog.logic.js +42 -0
  124. package/dist/shell/SettingsFiles.d.ts +55 -0
  125. package/dist/shell/SettingsFiles.js +30 -0
  126. package/dist/shell/SettingsPageKeys.d.ts +42 -0
  127. package/dist/shell/SettingsPageKeys.js +70 -0
  128. package/dist/shell/SettingsSubsection.d.ts +34 -0
  129. package/dist/shell/SettingsSubsection.js +30 -0
  130. package/dist/shell/SignIn.d.ts +61 -0
  131. package/dist/shell/SignIn.js +36 -0
  132. package/dist/shell/ThemePicker.d.ts +74 -0
  133. package/dist/shell/ThemePicker.js +96 -0
  134. package/dist/shell/ThemePicker.logic.d.ts +13 -0
  135. package/dist/shell/ThemePicker.logic.js +26 -0
  136. package/dist/shell/TitleBar.d.ts +44 -0
  137. package/dist/shell/TitleBar.js +23 -0
  138. package/dist/shell/UpdatePill.d.ts +26 -0
  139. package/dist/shell/UpdatePill.js +17 -0
  140. package/dist/shell/Updates.d.ts +99 -0
  141. package/dist/shell/Updates.js +72 -0
  142. package/dist/shell/index.d.ts +27 -0
  143. package/dist/shell/index.js +27 -0
  144. package/dist/shell/shell.css +243 -4
  145. package/dist/styles.css +10 -0
  146. package/dist/surface/GroupSwatch.d.ts +22 -0
  147. package/dist/surface/GroupSwatch.js +15 -0
  148. package/dist/surface/Tag.d.ts +26 -0
  149. package/dist/surface/Tag.js +12 -0
  150. package/dist/surface/index.d.ts +7 -0
  151. package/dist/surface/index.js +7 -0
  152. package/dist/surface/surface.css +116 -1
  153. package/dist/themes/catalog.js +4 -0
  154. package/dist/themes/themes.generated.css +244 -0
  155. package/dist/themes/tokens.d.ts +17 -5
  156. package/dist/themes/tokens.js +75 -1
  157. package/dist/tokens.css +11 -0
  158. package/package.json +1 -1
@@ -5,8 +5,26 @@
5
5
  * panes say what they offer by these marks, so the keys run exactly what a
6
6
  * click would, disabled where the control is.
7
7
  */
8
- /** The rows a pane's cursor walks, top to bottom: its `data-row-key` elements. */
9
- export const paneRows = (pane) => pane === null ? [] : [...pane.querySelectorAll('[data-row-key]')];
8
+ /**
9
+ * The elements in `root` matching `selector` that show: none inside a
10
+ * `hidden` element under `root`, such as a page held mounted out of sight
11
+ * behind the front tab (`PageSlot`), whose rows, home, and verbs the keys
12
+ * never reach.
13
+ */
14
+ const shownMatches = (root, selector) => [...root.querySelectorAll(selector)].filter((match) => {
15
+ const hidden = match.closest('[hidden]');
16
+ return hidden === null || !root.contains(hidden) || hidden === root;
17
+ });
18
+ /**
19
+ * A pane's home that shows: the first `data-pane-home` element in it (the
20
+ * sidebar's with `"sidebar"`) outside a hidden page, or null for none.
21
+ * Internal to the pane area.
22
+ */
23
+ export const shownHome = (pane, sidebar = false) => pane === null
24
+ ? null
25
+ : (shownMatches(pane, sidebar ? '[data-pane-home="sidebar"]' : '[data-pane-home]')[0] ?? null);
26
+ /** The rows a pane's cursor walks, top to bottom: its `data-row-key` elements that show. */
27
+ export const paneRows = (pane) => pane === null ? [] : shownMatches(pane, '[data-row-key]');
10
28
  /** A pane's row by its key, or null for none. */
11
29
  export const paneRow = (pane, key) => key === null ? null : (paneRows(pane).find((row) => row.dataset.rowKey === key) ?? null);
12
30
  /** Whether a control takes a click: not disabled, not inert behind `aria-disabled`. */
@@ -18,7 +36,7 @@ const enabled = (control) => !control.disabled && control.getAttribute('aria-dis
18
36
  export function verbControl(root, verb, attribute = 'verb') {
19
37
  // The verb is quoted, so only a quote or a backslash in it needs escaping.
20
38
  const quoted = verb.replace(/["\\]/g, '\\$&');
21
- const control = root?.querySelector(`[data-${attribute}~="${quoted}"]`) ?? null;
39
+ const control = root === null ? null : (shownMatches(root, `[data-${attribute}~="${quoted}"]`)[0] ?? null);
22
40
  return control !== null && enabled(control) ? control : null;
23
41
  }
24
42
  const FOCUSABLE = 'a[href], button, input, select, textarea, summary, [tabindex]';
@@ -61,9 +79,10 @@ const inDocumentOrder = (a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_P
61
79
  * document puts it, make one cycle in document order that wraps at either
62
80
  * end. A row's controls are no stops (the cursor row's keys run them) unless
63
81
  * its listing keeps them in the Tab order (`Row`'s `tabbable`); a sidebar
64
- * row's never are.
82
+ * row's never are. With `alone` (no sidebar shown) the page's stops make
83
+ * the one cycle, wrapping at either end, and the sidebar is never named.
65
84
  */
66
- export function nextTabStop(main, home, from, back, sidebar = null) {
85
+ export function nextTabStop(main, home, from, back, sidebar = null, alone = false) {
67
86
  if (from === 'sidebar' && sidebar === null)
68
87
  return 'page';
69
88
  const at = from === 'sidebar' ? (sidebar?.home ?? home) : from === 'page' ? home : from;
@@ -84,7 +103,7 @@ export function nextTabStop(main, home, from, back, sidebar = null) {
84
103
  .filter((stop) => stop.compareDocumentPosition(at) & Node.DOCUMENT_POSITION_FOLLOWING)
85
104
  .pop()
86
105
  : stops.find((stop) => stop.compareDocumentPosition(at) & Node.DOCUMENT_POSITION_PRECEDING);
87
- const landed = next ?? (sidebar === null ? undefined : back ? stops.at(-1) : stops[0]);
106
+ const landed = next ?? (sidebar === null && !alone ? undefined : back ? stops.at(-1) : stops[0]);
88
107
  if (landed === undefined || landed === sidebar?.home)
89
108
  return 'sidebar';
90
109
  return landed === home ? 'page' : landed;
@@ -94,7 +113,7 @@ export function nextTabStop(main, home, from, back, sidebar = null) {
94
113
  * (`data-pane-home`) shows of 24px rows, less one kept in view.
95
114
  */
96
115
  export const pageRows = (pane) => {
97
- const list = pane?.querySelector('[data-pane-home]');
116
+ const list = shownHome(pane);
98
117
  return Math.max(1, Math.floor((list?.clientHeight ?? 0) / 24) - 1);
99
118
  };
100
119
  /** Brings a row the keys moved to into view, clear of its strip (the row's own scroll margin). */
@@ -0,0 +1,92 @@
1
+ import { type MouseEvent, type ReactElement, type ReactNode } from 'react';
2
+ import type { Chord } from '../keyboard/Keyboard.logic.js';
3
+ /** One tab of a pane's strip. */
4
+ export interface PaneTabItem {
5
+ /** Names the tab to every callback; also its `data-pane-tab` attribute. */
6
+ readonly id: string;
7
+ /** What the tab shows. */
8
+ readonly name: string;
9
+ /**
10
+ * Dim words before the name and a slash, to tell two tabs of one name
11
+ * apart (`shop` / `orders`). They give way to an ellipsis before the
12
+ * name loses a character.
13
+ */
14
+ readonly context?: string;
15
+ /** A node ahead of the name: a group's swatch or a lucide icon at `ICON_SM`. Decorative. */
16
+ readonly mark?: ReactNode;
17
+ /** The tooltip, at every width: the tab's whole path. Also its accessible description. */
18
+ readonly tip?: string;
19
+ /** The next place opened takes this tab over: its name is set in italic. */
20
+ readonly following?: boolean;
21
+ /**
22
+ * The tab holds changes not saved: the warning mark stands where its close
23
+ * control is, and the control comes back under the pointer.
24
+ */
25
+ readonly dirty?: boolean;
26
+ /** Stands before the pin rule, keeps its width, and carries a pin in place of a close control. */
27
+ readonly pinned?: boolean;
28
+ /** `'danger'` outlines the tab in the danger colour at every width (a place that needs care). */
29
+ readonly tone?: 'danger';
30
+ /** False draws no close control, and a middle click closes nothing. True by default. */
31
+ readonly closable?: boolean;
32
+ }
33
+ /** Props for {@link PaneTabs}. */
34
+ export interface PaneTabsProps {
35
+ /** The tablist's accessible name. */
36
+ readonly label: string;
37
+ /** The tabs in strip order; pinned tabs must come first. */
38
+ readonly tabs: readonly PaneTabItem[];
39
+ /** The id of the tab in front: exactly one, among `tabs`. */
40
+ readonly front: string;
41
+ /**
42
+ * The ids picked beside the tab in front, which the host keeps
43
+ * (`togglePick`, `pickRun`, `pickedTabs`). A picked tab wears the marked
44
+ * look and a drag of it carries every pick.
45
+ */
46
+ readonly picked?: readonly string[];
47
+ /** A press on a tab, or a choice in the folded tabs' menu: bring that tab to the front. */
48
+ readonly onSelect: (id: string) => void;
49
+ /** A tab's close control, or a middle click on a tab that has one. */
50
+ readonly onClose: (id: string) => void;
51
+ /** ⌘-click picks or drops a tab (`'toggle'`); ⇧-click picks the run from the front tab (`'run'`). */
52
+ readonly onPick?: (id: string, how: 'toggle' | 'run') => void;
53
+ /** A double-click on a tab: keeps a following tab. */
54
+ readonly onKeep?: (id: string) => void;
55
+ /** After a drag drops, the full order, folded tabs included. Omit to turn dragging off. */
56
+ readonly onReorder?: (order: readonly string[]) => void;
57
+ /** The New Tab button, and a double-click on the strip's empty end. Omit to draw no button. */
58
+ readonly onNew?: () => void;
59
+ /** The chord New Tab's tooltip shows; ⌘T by default. */
60
+ readonly newChord?: Chord;
61
+ /** A secondary click on a tab; the host decides whether to prevent the browser's menu. */
62
+ readonly onTabContextMenu?: (id: string, event: MouseEvent) => void;
63
+ /** Drawn after the folded tabs' count, at the strip's end (an update pill). */
64
+ readonly trailing?: ReactNode;
65
+ }
66
+ /**
67
+ * The tabs a pane hangs from: the first child of a `.pane` under
68
+ * `.listing-root`, whose frame hangs from the tab in front. A tab wears its
69
+ * place's name, with dim context before it when two tabs share a name; the
70
+ * one in front joins the frame, the others stand behind it, shorter and
71
+ * fainter. A following tab's name is italic, a dirty tab carries the
72
+ * warning mark in its close control's place, a pinned tab stands before the
73
+ * pin rule with a pin, and a danger-toned tab keeps its danger outline.
74
+ *
75
+ * The strip never wraps or scrolls. Tabs behind the front one shrink
76
+ * together to a floor (eight characters of the name, three of the
77
+ * context), then fold into a count after New Tab, farthest from the front
78
+ * tab first; pinned, front, and following tabs never fold, and pinned and
79
+ * front never shrink. The count's menu names the folded tabs.
80
+ *
81
+ * A press brings a tab to the front at once and, with `onReorder`, may
82
+ * start a drag (past a 4px slop): the held tab follows the pointer, its
83
+ * neighbours step aside at half cover, it stays its side of the pin rule,
84
+ * picked tabs ride with it, Escape puts every tab back, and release hands
85
+ * the full order to `onReorder`. ⌘-click and ⇧-click pick (`onPick`), a
86
+ * middle click closes, a double-click keeps (`onKeep`), and a double-click
87
+ * on the strip's empty end opens a new tab (`onNew`).
88
+ *
89
+ * Tabs take no focus: the host's verbs are the keyboard's way in. Words
90
+ * come from `useLabels().paneTabs`.
91
+ */
92
+ export declare function PaneTabs({ label, tabs, front, picked, onSelect, onClose, onPick, onKeep, onReorder, onNew, newChord, onTabContextMenu, trailing }: PaneTabsProps): ReactElement;
@@ -0,0 +1,326 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronDown, Pin, Plus, X } from 'lucide-react';
3
+ import { Fragment, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { ICON_MD, ICON_SM } from '../icon/index.js';
6
+ import { useLabels } from '../labels/UiokProvider.js';
7
+ import { StateMark } from '../listing/Listing.js';
8
+ import { movedPickableCursor, pickableCursor } from '../menu/MenuQuery.logic.js';
9
+ import { describedTooltip, tooltip } from '../tooltip/Tooltip.logic.js';
10
+ import { foldOrder, foldsNeeded, tabLabelFloor } from './PaneTabs.logic.js';
11
+ import { useTabDrag } from './useTabDrag.js';
12
+ /** New Tab's chord when the host names none. */
13
+ const NEW_TAB_CHORD = { key: 't', meta: true };
14
+ /** No picks. */
15
+ const NO_PICKS = [];
16
+ /** Keeps the focus where it was on a press, so a press on the strip leaves the keys where they were. */
17
+ const keepFocus = (event) => event.preventDefault();
18
+ /** The words a tab is called by: its context and name, as the strip shows them. */
19
+ const spokenTab = (tab) => tab.context === undefined ? tab.name : `${tab.context}/${tab.name}`;
20
+ /** Whether the tab draws a close control. */
21
+ const closes = (tab) => tab.pinned !== true && tab.closable !== false;
22
+ /** A tab's label: the context giving way to its floor before the name gives a character. */
23
+ function TabLabel({ tab }) {
24
+ const floor = tabLabelFloor(tab);
25
+ return (_jsxs("span", { className: "pane-tab-label", children: [tab.context === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: "pane-tab-context", style: { minWidth: `${floor.context}ch` }, children: tab.context }), _jsx("span", { className: "pane-tab-context pane-tab-slash", children: "/" })] })), _jsx("span", { className: "pane-tab-name", children: tab.name })] }));
26
+ }
27
+ /**
28
+ * The folded tabs' count at the strip's end: "+N" and a chevron, the
29
+ * warning mark before it while a folded tab is dirty. It opens the menu of
30
+ * the folded tabs, in strip order; the menu holds the keys (↑ ↓, Return,
31
+ * Escape) and hands the focus back to where it was when it opened.
32
+ */
33
+ function FoldedTabs({ folded, labels, onSelect }) {
34
+ const buttonRef = useRef(null);
35
+ const menuRef = useRef(null);
36
+ const returnRef = useRef(null);
37
+ const menuId = useId();
38
+ const [host, setHost] = useState(null);
39
+ const [pointed, setPointed] = useState(null);
40
+ const dirty = folded.filter((tab) => tab.dirty === true).length;
41
+ const words = labels.folded(folded.length, dirty);
42
+ const rows = folded.map((tab) => ({ key: tab.id, taken: false }));
43
+ const cursor = host === null ? null : pickableCursor(rows, pointed);
44
+ const close = (by) => {
45
+ setHost(null);
46
+ setPointed(null);
47
+ const back = returnRef.current;
48
+ returnRef.current = null;
49
+ if (by === 'keyboard' && back instanceof HTMLElement && back.isConnected) {
50
+ back.focus({ preventScroll: true });
51
+ }
52
+ };
53
+ const closeRef = useRef(close);
54
+ useLayoutEffect(() => {
55
+ closeRef.current = close;
56
+ });
57
+ // Placed under the count, its trailing edge on the count's, and given the
58
+ // keys; over the count instead when the window has no room for it below
59
+ // and has room above, so no row the keys reach falls out of the window.
60
+ useLayoutEffect(() => {
61
+ const menu = menuRef.current;
62
+ const button = buttonRef.current;
63
+ if (host === null || menu === null || button === null) {
64
+ return;
65
+ }
66
+ const box = button.getBoundingClientRect();
67
+ const gap = parseFloat(getComputedStyle(menu).getPropertyValue('--space-2')) || 0;
68
+ const width = menu.offsetWidth;
69
+ const height = menu.offsetHeight;
70
+ const above = box.top - gap - height;
71
+ const below = box.bottom + gap;
72
+ menu.style.top = `${below + height > window.innerHeight - gap && above >= gap ? above : below}px`;
73
+ menu.style.left = `${Math.max(gap, Math.min(box.right - width, window.innerWidth - width - gap))}px`;
74
+ menu.focus({ preventScroll: true });
75
+ }, [host]);
76
+ // The row the keys move to scrolls into the list's view, so Return never
77
+ // chooses a row out of sight. Optional call: jsdom has no scrollIntoView.
78
+ useLayoutEffect(() => {
79
+ if (host === null || cursor === null) {
80
+ return;
81
+ }
82
+ menuRef.current
83
+ ?.querySelector('.pane-tabs-folded-option.cursor')
84
+ ?.scrollIntoView?.({ block: 'nearest' });
85
+ }, [host, cursor]);
86
+ // A press outside closes it; the press goes on to whatever it landed on.
87
+ useEffect(() => {
88
+ if (host === null) {
89
+ return;
90
+ }
91
+ const listener = (event) => {
92
+ if (!(event.target instanceof Node) ||
93
+ !(menuRef.current?.contains(event.target) || buttonRef.current?.contains(event.target))) {
94
+ closeRef.current('pointer');
95
+ }
96
+ };
97
+ // A window that changes size moves the count out from under the menu:
98
+ // the menu closes, and the keys go back to where they were.
99
+ const resized = () => closeRef.current('keyboard');
100
+ document.addEventListener('mousedown', listener, true);
101
+ window.addEventListener('resize', resized);
102
+ return () => {
103
+ document.removeEventListener('mousedown', listener, true);
104
+ window.removeEventListener('resize', resized);
105
+ };
106
+ }, [host]);
107
+ const choose = (tab) => {
108
+ if (tab !== undefined) {
109
+ close('keyboard');
110
+ onSelect(tab.id);
111
+ }
112
+ };
113
+ return (_jsxs(_Fragment, { children: [_jsxs("button", { "aria-expanded": host !== null, "aria-haspopup": "menu", "aria-label": labels.foldedHeading, className: "pane-tabs-folded hit-target quiet-control", onClick: () => {
114
+ if (host !== null) {
115
+ close('pointer');
116
+ return;
117
+ }
118
+ returnRef.current = document.activeElement;
119
+ setHost(buttonRef.current?.closest('.listing-root') ?? document.body);
120
+ }, onMouseDown: keepFocus, ref: buttonRef, type: "button", ...describedTooltip(words), children: [dirty > 0 ? (_jsx("span", { "aria-hidden": true, className: "pane-tab-dirty", children: _jsx(StateMark, { tone: "warning", word: "" }) })) : null, _jsx("span", { className: "pane-tabs-folded-count", children: `+${folded.length.toLocaleString('en-US')}` }), _jsx(ChevronDown, { "aria-hidden": true, size: ICON_SM })] }), host === null
121
+ ? null
122
+ : createPortal(_jsxs("div", { "aria-activedescendant": cursor === null ? undefined : `${menuId}-${cursor}`, "aria-label": labels.foldedHeading, className: "folder-menu folder-menu-compact pane-tabs-folded-menu", "data-native-keyboard": true, "data-overlay": true, onBlur: (event) => {
123
+ if (!(event.relatedTarget instanceof Node &&
124
+ event.currentTarget.contains(event.relatedTarget))) {
125
+ close('pointer');
126
+ }
127
+ }, onKeyDown: (event) => {
128
+ if (event.metaKey || event.ctrlKey || event.altKey) {
129
+ return;
130
+ }
131
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
132
+ const next = movedPickableCursor(rows, cursor, event.key === 'ArrowDown' ? 1 : -1);
133
+ setPointed(next === null ? null : (folded[next]?.id ?? null));
134
+ }
135
+ else if (event.key === 'Enter' || event.key === ' ') {
136
+ choose(cursor === null ? undefined : folded[cursor]);
137
+ }
138
+ else if (event.key === 'Escape') {
139
+ close('keyboard');
140
+ }
141
+ else if (event.key === 'Tab') {
142
+ close('pointer');
143
+ return;
144
+ }
145
+ else {
146
+ return;
147
+ }
148
+ event.preventDefault();
149
+ event.stopPropagation();
150
+ },
151
+ // A press on a row must not take the focus from the menu, which holds the keys.
152
+ onMouseDown: keepFocus, ref: menuRef, role: "menu", tabIndex: -1, children: [_jsx("div", { "aria-hidden": true, className: "entry-menu-heading overline", children: labels.foldedHeading }), _jsx("div", { className: "folder-menu-options", role: "none", children: folded.map((tab, index) => (_jsxs("div", { "aria-description": [tab.tip, tab.dirty === true ? labels.notSaved : undefined]
153
+ .filter((part) => part !== undefined && part !== '')
154
+ .join(', ') || undefined, "aria-label": spokenTab(tab), className: index === cursor
155
+ ? 'folder-menu-option pane-tabs-folded-option cursor'
156
+ : 'folder-menu-option pane-tabs-folded-option', "data-tone": tab.tone, id: `${menuId}-${index}`, onClick: () => choose(tab), onMouseMove: () => setPointed(tab.id), role: "menuitem", ...tooltip(tab.tip, null, { value: true }), children: [_jsx("span", { "aria-hidden": true, className: "pane-tabs-folded-mark", children: tab.mark }), _jsxs("span", { className: "pane-tabs-folded-label", children: [tab.context === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: "pane-tab-context", children: tab.context }), _jsx("span", { className: "pane-tab-context pane-tab-slash", children: "/" })] })), _jsx("span", { className: "pane-tab-name", children: tab.name })] }), _jsxs("span", { "aria-hidden": true, className: "pane-tabs-folded-marks", children: [tab.dirty === true ? _jsx(StateMark, { tone: "warning", word: "" }) : null, tab.tone === 'danger' ? _jsx(StateMark, { tone: "danger", word: "" }) : null] })] }, tab.id))) })] }), host)] }));
157
+ }
158
+ /**
159
+ * The tabs a pane hangs from: the first child of a `.pane` under
160
+ * `.listing-root`, whose frame hangs from the tab in front. A tab wears its
161
+ * place's name, with dim context before it when two tabs share a name; the
162
+ * one in front joins the frame, the others stand behind it, shorter and
163
+ * fainter. A following tab's name is italic, a dirty tab carries the
164
+ * warning mark in its close control's place, a pinned tab stands before the
165
+ * pin rule with a pin, and a danger-toned tab keeps its danger outline.
166
+ *
167
+ * The strip never wraps or scrolls. Tabs behind the front one shrink
168
+ * together to a floor (eight characters of the name, three of the
169
+ * context), then fold into a count after New Tab, farthest from the front
170
+ * tab first; pinned, front, and following tabs never fold, and pinned and
171
+ * front never shrink. The count's menu names the folded tabs.
172
+ *
173
+ * A press brings a tab to the front at once and, with `onReorder`, may
174
+ * start a drag (past a 4px slop): the held tab follows the pointer, its
175
+ * neighbours step aside at half cover, it stays its side of the pin rule,
176
+ * picked tabs ride with it, Escape puts every tab back, and release hands
177
+ * the full order to `onReorder`. ⌘-click and ⇧-click pick (`onPick`), a
178
+ * middle click closes, a double-click keeps (`onKeep`), and a double-click
179
+ * on the strip's empty end opens a new tab (`onNew`).
180
+ *
181
+ * Tabs take no focus: the host's verbs are the keyboard's way in. Words
182
+ * come from `useLabels().paneTabs`.
183
+ */
184
+ export function PaneTabs({ label, tabs, front, picked = NO_PICKS, onSelect, onClose, onPick, onKeep, onReorder, onNew, newChord = NEW_TAB_CHORD, onTabContextMenu, trailing }) {
185
+ const labels = useLabels().paneTabs;
186
+ const headerRef = useRef(null);
187
+ const stripRef = useRef(null);
188
+ const trailingRef = useRef(null);
189
+ const [room, setRoom] = useState('');
190
+ const drag = useTabDrag();
191
+ const liveOrder = drag.liveOrder;
192
+ const hasTrailing = trailing !== undefined;
193
+ const byId = new Map(tabs.map((tab) => [tab.id, tab]));
194
+ const order = tabs.map((tab) => tab.id);
195
+ // While a drag runs the strip draws the hand's order; the host's comes back on release.
196
+ const drawn = liveOrder !== null && liveOrder.length === order.length && liveOrder.every((id) => byId.has(id))
197
+ ? liveOrder
198
+ : order;
199
+ // Whatever changes the strip's natural width starts the folding over.
200
+ const shape = `${room}|${front}|${onNew === undefined ? '' : 'new'}|${tabs
201
+ .map((tab) => `${tab.id}:${tab.pinned === true ? 'p' : ''}${tab.following === true ? 'f' : ''}${tab.mark === undefined ? '' : 'm'}${closes(tab) ? 'x' : ''}${tab.dirty === true ? 'd' : ''}:${tab.context ?? ''}/${tab.name}`)
202
+ .join('|')}`;
203
+ const [folding, setFolding] = useState({ shape, count: 0 });
204
+ const count = folding.shape === shape ? folding.count : 0;
205
+ if (folding.shape !== shape) {
206
+ setFolding({ shape, count: 0 });
207
+ }
208
+ const folds = foldOrder(tabs, front);
209
+ const folded = new Set(folds.slice(0, count));
210
+ const foldRank = new Map(folds.map((id, rank) => [id, rank]));
211
+ const foldedTabs = tabs.filter((tab) => folded.has(tab.id));
212
+ const pinnedIds = new Set(tabs.filter((tab) => tab.pinned === true).map((tab) => tab.id));
213
+ const shown = drawn.filter((id) => !folded.has(id));
214
+ const lastPinned = shown.reduce((last, id, index) => (pinnedIds.has(id) ? index : last), -1);
215
+ const carried = drawn.filter((id) => id === front || picked.includes(id));
216
+ const hasPicks = carried.length > 1;
217
+ // While the tabs on show, each at its floor, run past the strip's room,
218
+ // fold as many as cover the overrun in one step; the count taking its own
219
+ // room costs a pass or two more. Box widths, not offsets: each offset
220
+ // rounds on its own, and a tab in the hand is drawn away from its place.
221
+ useLayoutEffect(() => {
222
+ const strip = stripRef.current;
223
+ if (!strip || count >= folds.length) {
224
+ return;
225
+ }
226
+ const boxes = [...strip.children].map((element) => ({
227
+ rank: element instanceof HTMLElement ? element.dataset.foldRank : undefined,
228
+ width: element.getBoundingClientRect().width
229
+ }));
230
+ const gap = parseFloat(getComputedStyle(strip).columnGap) || 0;
231
+ const run = boxes.reduce((sum, box) => sum + box.width, 0) + gap * Math.max(0, boxes.length - 1);
232
+ const deficit = run - strip.getBoundingClientRect().width;
233
+ if (deficit <= 0.5) {
234
+ return;
235
+ }
236
+ const widths = boxes
237
+ .flatMap((box) => box.rank === undefined ? [] : [{ rank: Number(box.rank), width: box.width }])
238
+ .sort((a, b) => a.rank - b.rank)
239
+ .map((box) => box.width);
240
+ setFolding({ shape, count: count + foldsNeeded(deficit, widths, gap) });
241
+ }, [count, folds.length, shape]);
242
+ // The header's width and the trailing slot's, which the folding starts over on.
243
+ useEffect(() => {
244
+ const header = headerRef.current;
245
+ // Optional: jsdom has no ResizeObserver.
246
+ if (!header || typeof ResizeObserver === 'undefined') {
247
+ return;
248
+ }
249
+ const observer = new ResizeObserver(() => setRoom(`${header.clientWidth}:${trailingRef.current?.offsetWidth ?? 0}`));
250
+ observer.observe(header);
251
+ if (trailingRef.current) {
252
+ observer.observe(trailingRef.current);
253
+ }
254
+ return () => observer.disconnect();
255
+ }, [hasTrailing]);
256
+ // After every layout, since any of them may have moved a tab.
257
+ useLayoutEffect(() => {
258
+ drag.afterLayout({
259
+ order: drawn,
260
+ pinned: pinnedIds,
261
+ strip: stripRef.current,
262
+ commit: (next) => onReorder?.(next)
263
+ });
264
+ });
265
+ const tabElement = (tab) => {
266
+ const isFront = tab.id === front;
267
+ const isPicked = hasPicks && !isFront && picked.includes(tab.id);
268
+ const spoken = spokenTab(tab);
269
+ const floor = tabLabelFloor(tab);
270
+ const description = [
271
+ tab.tip,
272
+ tab.pinned === true ? labels.pinned : undefined,
273
+ tab.dirty === true ? labels.notSaved : undefined
274
+ ]
275
+ .filter((part) => part !== undefined && part !== '')
276
+ .join(', ');
277
+ return (_jsxs("div", { ...tooltip(tab.tip, null, { value: true }), "aria-description": description === '' ? undefined : description, "aria-label": isPicked ? labels.picked(spoken) : spoken, "aria-selected": isFront, className: [
278
+ 'pane-tab',
279
+ isFront ? 'active' : '',
280
+ tab.following === true ? 'following' : '',
281
+ tab.dirty === true ? 'dirty' : '',
282
+ tab.pinned === true ? 'pinned' : '',
283
+ isPicked ? 'picked' : '',
284
+ drag.draggingIds.includes(tab.id) ? 'dragging' : ''
285
+ ]
286
+ .filter(Boolean)
287
+ .join(' '), "data-fold-rank": foldRank.get(tab.id), "data-pane-tab": tab.id, "data-tone": tab.tone, onAuxClick: (event) => {
288
+ if (event.button === 1 && closes(tab)) {
289
+ onClose(tab.id);
290
+ }
291
+ }, onContextMenu: (event) => onTabContextMenu?.(tab.id, event), onDoubleClick: () => onKeep?.(tab.id), onMouseDown: keepFocus, onPointerDown: (event) => {
292
+ if (event.button !== 0 || event.ctrlKey) {
293
+ return;
294
+ }
295
+ if (onPick !== undefined && (event.metaKey || event.shiftKey)) {
296
+ onPick(tab.id, event.metaKey ? 'toggle' : 'run');
297
+ return;
298
+ }
299
+ // A press on a picked tab waits for its release: it may start a drag of every pick.
300
+ if (onReorder !== undefined && hasPicks && carried.includes(tab.id)) {
301
+ drag.begin(tab.id, event.currentTarget, event.clientX, {
302
+ ids: carried,
303
+ onClick: () => onSelect(tab.id)
304
+ });
305
+ return;
306
+ }
307
+ if (!isFront || hasPicks) {
308
+ onSelect(tab.id);
309
+ }
310
+ if (onReorder !== undefined) {
311
+ drag.begin(tab.id, event.currentTarget, event.clientX);
312
+ }
313
+ }, ref: drag.tabRef(tab.id), role: "tab", style: {
314
+ '--pane-tab-floor': `${floor.context + (tab.context === undefined ? 0 : 1) + floor.name}ch`
315
+ }, children: [tab.mark === undefined ? null : (_jsx("span", { "aria-hidden": true, className: "pane-tab-mark", children: tab.mark })), _jsx(TabLabel, { tab: tab }), tab.dirty === true ? (_jsx("span", { "aria-hidden": true, className: "pane-tab-dirty", ...tooltip(labels.notSaved), children: _jsx(StateMark, { tone: "warning", word: "" }) })) : null, tab.pinned === true ? (_jsx("span", { "aria-hidden": true, className: "pane-tab-pin", ...tooltip(labels.pinned), children: _jsx(Pin, { size: ICON_SM }) })) : closes(tab) ? (_jsx("button", { "aria-label": labels.close(spoken), className: "pane-tab-close hit-target quiet-control", onClick: (event) => {
316
+ event.stopPropagation();
317
+ onClose(tab.id);
318
+ }, onDoubleClick: (event) => event.stopPropagation(), onMouseDown: keepFocus,
319
+ // A press on the control is not the start of a drag of its tab.
320
+ onPointerDown: (event) => event.stopPropagation(), tabIndex: -1, type: "button", ...tooltip(labels.close(spoken)), children: _jsx(X, { "aria-hidden": true, size: ICON_SM }) })) : null] }));
321
+ };
322
+ return (_jsxs("div", { className: "pane-header", ref: headerRef, children: [_jsx("div", { "aria-label": label, className: "pane-tabs", ref: stripRef, role: "tablist", children: shown.map((id, index) => {
323
+ const tab = byId.get(id);
324
+ return tab === undefined ? null : (_jsxs(Fragment, { children: [tabElement(tab), index === lastPinned && index < shown.length - 1 ? (_jsx("span", { "aria-hidden": true, className: "pane-pin-rule" })) : null] }, id));
325
+ }) }), onNew === undefined ? null : (_jsx("button", { "aria-label": labels.newTab, className: "pane-tab-new hit-target quiet-control", onClick: onNew, onMouseDown: keepFocus, tabIndex: -1, type: "button", ...tooltip(labels.newTab, newChord), children: _jsx(Plus, { "aria-hidden": true, size: ICON_MD }) })), _jsx("span", { "aria-hidden": true, className: "pane-tabs-rest", onDoubleClick: onNew }), foldedTabs.length === 0 ? null : (_jsx(FoldedTabs, { folded: foldedTabs, labels: labels, onSelect: onSelect })), !hasTrailing ? null : (_jsx("span", { className: "pane-tabs-trailing", ref: trailingRef, children: trailing }))] }));
326
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The rules a pane's tab strip draws by, as pure functions: which tabs are
3
+ * picked to close or move together, which tabs a crowded strip folds away
4
+ * and how many in one step, how narrow a tab's label may get, and where a
5
+ * dragged tab lands. A host keeps its tab state with the pick helpers;
6
+ * `PaneTabs` uses the rest.
7
+ */
8
+ /**
9
+ * The tabs picked on a strip beside the one in front. They belong to the
10
+ * tab in front when they were picked, and lapse once another tab comes to
11
+ * the front. A host keeps them in memory; they are never worth saving.
12
+ */
13
+ export interface TabPicks {
14
+ /** The tab in front when the picks were made. */
15
+ readonly front: string;
16
+ /** The picked tabs other than the one in front, in the order they were picked. */
17
+ readonly ids: readonly string[];
18
+ }
19
+ /**
20
+ * The tabs a strip's picks stand for, in strip order: the tab in front,
21
+ * always, and every pick that still stands.
22
+ */
23
+ export declare function pickedTabs(order: readonly string[], frontId: string, picks: TabPicks | null): readonly string[];
24
+ /**
25
+ * A Command press on the tab `id`: picks it, or drops it when it was
26
+ * picked. The tab in front is always among the picks and is never dropped,
27
+ * so a press on it changes nothing. Null once nothing beside the tab in
28
+ * front is picked.
29
+ */
30
+ export declare function togglePick(order: readonly string[], frontId: string, picks: TabPicks | null, id: string): TabPicks | null;
31
+ /**
32
+ * A Shift press on the tab `id`: picks the run of tabs from the one in
33
+ * front to it, both ends included, in place of the picks before. Null for a
34
+ * press on the tab in front, or on a tab not in `order`.
35
+ */
36
+ export declare function pickRun(order: readonly string[], frontId: string, id: string): TabPicks | null;
37
+ /**
38
+ * The strip's order with the tabs `carried` drawn together around `held`,
39
+ * the tab under the pointer, as a drag of picked tabs lifts them: the ones
40
+ * before it close up just before it and the ones after it just after, in
41
+ * their order, and every other tab keeps its order.
42
+ */
43
+ export declare function gatherTabs(order: readonly string[], carried: readonly string[], held: string): readonly string[];
44
+ /**
45
+ * The fewest characters a tab's label keeps, its ellipses counted, split
46
+ * into the context (its slash not counted) and the name: eight characters
47
+ * of the name and three of the context, or all of a shorter one. The
48
+ * context shrinks to its floor before the name loses a character: the name
49
+ * is what the eye looks for, and the context only tells two tabs apart.
50
+ */
51
+ export declare function tabLabelFloor(label: {
52
+ readonly name: string;
53
+ readonly context?: string;
54
+ }): {
55
+ readonly context: number;
56
+ readonly name: number;
57
+ };
58
+ /** What `foldOrder` reads of a tab. */
59
+ export interface FoldableTab {
60
+ readonly id: string;
61
+ readonly pinned?: boolean;
62
+ readonly following?: boolean;
63
+ }
64
+ /**
65
+ * The order in which a crowded strip folds its tabs into the count:
66
+ * farthest from the tab in front first and, of two as far, the later one.
67
+ * The tab in front, pinned tabs, and the following tab never fold, so they
68
+ * are left out.
69
+ */
70
+ export declare function foldOrder(tabs: readonly FoldableTab[], frontId: string): readonly string[];
71
+ /**
72
+ * How many more tabs a crowded strip folds in one step. `deficit` is how far
73
+ * the tabs on show run past their room, `widths` the foldable tabs still on
74
+ * show in fold order, and `gap` the space between two tabs. Folding one tab
75
+ * per layout pass would take a pass per tab, and a strip can hold more tabs
76
+ * than React allows passes in a row. A deficit folds at least one tab, and
77
+ * one that no tab covers folds them all.
78
+ */
79
+ export declare function foldsNeeded(deficit: number, widths: readonly number[], gap: number): number;
80
+ /** A tab on show in a strip, as a drag measures it. */
81
+ export interface TabBox {
82
+ readonly id: string;
83
+ readonly left: number;
84
+ readonly width: number;
85
+ }
86
+ /**
87
+ * The strip's order while a tab is dragged along it. `held` is the dragged
88
+ * tab where the pointer has it, `boxes` the other tabs on show where the
89
+ * layout has them, and `order` every tab, folded ones included. A neighbour
90
+ * steps aside once the tab coming toward it covers half of it; one the tab
91
+ * is moving away from stays put, so a tab resting on the line between two
92
+ * places cannot flicker between them. Folded tabs keep their places: a tab
93
+ * that crosses no neighbour returns `order` itself, and one that crosses
94
+ * lands beside the last neighbour it passed. `direction` is the sign of the
95
+ * pointer's last move.
96
+ */
97
+ export declare function draggedTabOrder(order: readonly string[], held: TabBox, boxes: readonly TabBox[], direction: number): readonly string[];