@bigpixelrocket/uiok 0.2.2 → 0.2.3

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 (57) hide show
  1. package/CHANGELOG.md +37 -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/dialog/ConfirmDialog.d.ts +7 -1
  8. package/dist/dialog/ConfirmDialog.js +9 -4
  9. package/dist/dialog/DialogLists.d.ts +8 -1
  10. package/dist/dialog/DialogLists.js +3 -2
  11. package/dist/field/field.css +110 -2
  12. package/dist/filter/filter.css +16 -0
  13. package/dist/grid/DataGrid.d.ts +10 -2
  14. package/dist/grid/DataGrid.js +47 -13
  15. package/dist/grid/DataGrid.logic.d.ts +16 -0
  16. package/dist/grid/DataGrid.logic.js +28 -0
  17. package/dist/grid/grid.css +128 -4
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/labels/UiokLabels.d.ts +3 -0
  21. package/dist/labels/UiokLabels.js +3 -1
  22. package/dist/labels/index.d.ts +1 -0
  23. package/dist/labels/index.js +1 -0
  24. package/dist/labels/keys.js +2 -0
  25. package/dist/labels/paneTabs.d.ts +27 -0
  26. package/dist/labels/paneTabs.js +10 -0
  27. package/dist/labels/selectAll.d.ts +4 -1
  28. package/dist/labels/selectAll.js +1 -1
  29. package/dist/legend/KeyLegendStrip.d.ts +9 -1
  30. package/dist/legend/KeyLegendStrip.js +119 -5
  31. package/dist/legend/legend.css +52 -0
  32. package/dist/listing/Listing.d.ts +23 -5
  33. package/dist/listing/Listing.js +11 -8
  34. package/dist/listing/listing.css +106 -3
  35. package/dist/pane/PaneActions.d.ts +3 -1
  36. package/dist/pane/PaneActions.js +6 -5
  37. package/dist/pane/PaneTabs.d.ts +92 -0
  38. package/dist/pane/PaneTabs.js +326 -0
  39. package/dist/pane/PaneTabs.logic.d.ts +97 -0
  40. package/dist/pane/PaneTabs.logic.js +158 -0
  41. package/dist/pane/index.d.ts +5 -1
  42. package/dist/pane/index.js +5 -1
  43. package/dist/pane/panetabs.css +408 -0
  44. package/dist/pane/useTabDrag.d.ts +49 -0
  45. package/dist/pane/useTabDrag.js +306 -0
  46. package/dist/segmented/SegmentedChoice.d.ts +8 -1
  47. package/dist/segmented/SegmentedChoice.js +7 -4
  48. package/dist/styles.css +8 -0
  49. package/dist/surface/GroupSwatch.d.ts +22 -0
  50. package/dist/surface/GroupSwatch.js +15 -0
  51. package/dist/surface/Tag.d.ts +26 -0
  52. package/dist/surface/Tag.js +12 -0
  53. package/dist/surface/index.d.ts +7 -0
  54. package/dist/surface/index.js +7 -0
  55. package/dist/surface/surface.css +116 -1
  56. package/dist/themes/tokens.js +12 -1
  57. package/package.json +1 -1
@@ -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[];
@@ -0,0 +1,158 @@
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
+ /** The picks that still stand: those made under the tab in front now, on tabs still in `order`. */
9
+ const livePicks = (order, frontId, picks) => picks === null || picks.front !== frontId
10
+ ? []
11
+ : picks.ids.filter((id) => id !== frontId && order.includes(id));
12
+ /**
13
+ * The tabs a strip's picks stand for, in strip order: the tab in front,
14
+ * always, and every pick that still stands.
15
+ */
16
+ export function pickedTabs(order, frontId, picks) {
17
+ const live = livePicks(order, frontId, picks);
18
+ return order.filter((id) => id === frontId || live.includes(id));
19
+ }
20
+ /**
21
+ * A Command press on the tab `id`: picks it, or drops it when it was
22
+ * picked. The tab in front is always among the picks and is never dropped,
23
+ * so a press on it changes nothing. Null once nothing beside the tab in
24
+ * front is picked.
25
+ */
26
+ export function togglePick(order, frontId, picks, id) {
27
+ const live = livePicks(order, frontId, picks);
28
+ const ids = id === frontId || !order.includes(id)
29
+ ? live
30
+ : live.includes(id)
31
+ ? live.filter((other) => other !== id)
32
+ : [...live, id];
33
+ return ids.length === 0 ? null : { front: frontId, ids };
34
+ }
35
+ /**
36
+ * A Shift press on the tab `id`: picks the run of tabs from the one in
37
+ * front to it, both ends included, in place of the picks before. Null for a
38
+ * press on the tab in front, or on a tab not in `order`.
39
+ */
40
+ export function pickRun(order, frontId, id) {
41
+ const from = order.indexOf(frontId);
42
+ const to = order.indexOf(id);
43
+ if (from < 0 || to < 0 || from === to) {
44
+ return null;
45
+ }
46
+ return {
47
+ front: frontId,
48
+ ids: order
49
+ .slice(Math.min(from, to), Math.max(from, to) + 1)
50
+ .filter((other) => other !== frontId)
51
+ };
52
+ }
53
+ /**
54
+ * The strip's order with the tabs `carried` drawn together around `held`,
55
+ * the tab under the pointer, as a drag of picked tabs lifts them: the ones
56
+ * before it close up just before it and the ones after it just after, in
57
+ * their order, and every other tab keeps its order.
58
+ */
59
+ export function gatherTabs(order, carried, held) {
60
+ const block = order.filter((id) => id === held || carried.includes(id));
61
+ const rest = order.filter((id) => id === held || !carried.includes(id));
62
+ const at = rest.indexOf(held);
63
+ return at < 0 ? order : [...rest.slice(0, at), ...block, ...rest.slice(at + 1)];
64
+ }
65
+ /** The characters of its name a tab keeps before it folds away instead of shrinking further. */
66
+ const NAME_FLOOR = 8;
67
+ /** The characters of its context a tab keeps before its name starts to shrink. */
68
+ const CONTEXT_FLOOR = 3;
69
+ /** How many characters a part cut to `floor` takes: all of a shorter one, else `floor` and its ellipsis. */
70
+ const kept = (text, floor) => {
71
+ const length = [...text].length;
72
+ return length <= floor ? length : floor + 1;
73
+ };
74
+ /**
75
+ * The fewest characters a tab's label keeps, its ellipses counted, split
76
+ * into the context (its slash not counted) and the name: eight characters
77
+ * of the name and three of the context, or all of a shorter one. The
78
+ * context shrinks to its floor before the name loses a character: the name
79
+ * is what the eye looks for, and the context only tells two tabs apart.
80
+ */
81
+ export function tabLabelFloor(label) {
82
+ return {
83
+ context: label.context === undefined ? 0 : kept(label.context, CONTEXT_FLOOR),
84
+ name: kept(label.name, NAME_FLOOR)
85
+ };
86
+ }
87
+ /**
88
+ * The order in which a crowded strip folds its tabs into the count:
89
+ * farthest from the tab in front first and, of two as far, the later one.
90
+ * The tab in front, pinned tabs, and the following tab never fold, so they
91
+ * are left out.
92
+ */
93
+ export function foldOrder(tabs, frontId) {
94
+ const frontAt = tabs.findIndex((tab) => tab.id === frontId);
95
+ return tabs
96
+ .map((tab, index) => ({ tab, index, distance: Math.abs(index - frontAt) }))
97
+ .filter(({ tab }) => tab.id !== frontId && tab.pinned !== true && tab.following !== true)
98
+ .sort((a, b) => b.distance - a.distance || b.index - a.index)
99
+ .map(({ tab }) => tab.id);
100
+ }
101
+ /**
102
+ * How many more tabs a crowded strip folds in one step. `deficit` is how far
103
+ * the tabs on show run past their room, `widths` the foldable tabs still on
104
+ * show in fold order, and `gap` the space between two tabs. Folding one tab
105
+ * per layout pass would take a pass per tab, and a strip can hold more tabs
106
+ * than React allows passes in a row. A deficit folds at least one tab, and
107
+ * one that no tab covers folds them all.
108
+ */
109
+ export function foldsNeeded(deficit, widths, gap) {
110
+ let freed = 0;
111
+ let count = 0;
112
+ for (const width of widths) {
113
+ if (freed >= deficit) {
114
+ break;
115
+ }
116
+ freed += width + gap;
117
+ count += 1;
118
+ }
119
+ return count;
120
+ }
121
+ /**
122
+ * The strip's order while a tab is dragged along it. `held` is the dragged
123
+ * tab where the pointer has it, `boxes` the other tabs on show where the
124
+ * layout has them, and `order` every tab, folded ones included. A neighbour
125
+ * steps aside once the tab coming toward it covers half of it; one the tab
126
+ * is moving away from stays put, so a tab resting on the line between two
127
+ * places cannot flicker between them. Folded tabs keep their places: a tab
128
+ * that crosses no neighbour returns `order` itself, and one that crosses
129
+ * lands beside the last neighbour it passed. `direction` is the sign of the
130
+ * pointer's last move.
131
+ */
132
+ export function draggedTabOrder(order, held, boxes, direction) {
133
+ const mine = order.indexOf(held.id);
134
+ const rest = order.filter((id) => id !== held.id);
135
+ const shown = rest.filter((id) => boxes.some((box) => box.id === id));
136
+ const right = held.left + held.width;
137
+ const passed = shown.filter((id) => {
138
+ const box = boxes.find((candidate) => candidate.id === id);
139
+ if (box === undefined) {
140
+ return false;
141
+ }
142
+ const centre = box.left + box.width / 2;
143
+ return order.indexOf(id) < mine
144
+ ? !(direction < 0 && held.left < centre)
145
+ : direction > 0 && right > centre;
146
+ }).length;
147
+ const stayed = shown.filter((id) => order.indexOf(id) < mine).length;
148
+ // Nothing crossed: the tab keeps its place among the folded tabs too.
149
+ if (passed === stayed) {
150
+ return order;
151
+ }
152
+ // Past a neighbour, the tab lands beside it: folded tabs on the far side
153
+ // of that neighbour stay where they were.
154
+ const at = passed > stayed
155
+ ? rest.indexOf(shown[passed - 1]) + 1
156
+ : rest.indexOf(shown[passed]);
157
+ return [...rest.slice(0, at), held.id, ...rest.slice(at)];
158
+ }
@@ -3,11 +3,15 @@
3
3
  * compact controls inside them, in listing rows, and in a toolbar that
4
4
  * fits its tools to one line (`useToolbarFit`), and the keyboard of a
5
5
  * sidebar beside a page (`usePaneKeys`) with the pure key mapping and DOM
6
- * readers it is built on. Styled by the listing look under `.listing-root`.
6
+ * readers it is built on, and the tab strip a pane hangs from (`PaneTabs`)
7
+ * with the pure rules it and its host keep tab state by. Styled by the
8
+ * listing look under `.listing-root`.
7
9
  */
8
10
  export { InRowContext, QuietAction, RowIconAction, RowLinkLookContext, useInRow, type ControlVerb, type LinkLook, type QuietActionProps, type RowIconActionProps } from './PaneActions.js';
9
11
  export { PanePathBar, PaneStatus, PathFact, type PaneCrumb, type PanePathBarProps, type PaneStatusProps, type PathFactProps } from './PaneFrame.js';
10
12
  export { isTabStop, nextTabStop, pageRows, paneRow, paneRows, showRow, tabStops, verbControl, type SidebarTabStops, type TabStop } from './PaneKeys.js';
11
13
  export { movedIndex, NO_MAIN_VERBS, paneKeyAction, sameVerbs, type MainVerbs, type PaneKeyAction, type PaneKeyOptions, type PaneKeyStroke, type PaneMove } from './PaneKeys.logic.js';
14
+ export { PaneTabs, type PaneTabItem, type PaneTabsProps } from './PaneTabs.js';
15
+ export { draggedTabOrder, foldOrder, foldsNeeded, gatherTabs, pickedTabs, pickRun, tabLabelFloor, togglePick, type FoldableTab, type TabBox, type TabPicks } from './PaneTabs.logic.js';
12
16
  export { useToolbarFit } from './useToolbarFit.js';
13
17
  export { usePaneKeys, type Pane, type PaneKeys, type PaneKeysOptions } from './usePaneKeys.js';
@@ -3,11 +3,15 @@
3
3
  * compact controls inside them, in listing rows, and in a toolbar that
4
4
  * fits its tools to one line (`useToolbarFit`), and the keyboard of a
5
5
  * sidebar beside a page (`usePaneKeys`) with the pure key mapping and DOM
6
- * readers it is built on. Styled by the listing look under `.listing-root`.
6
+ * readers it is built on, and the tab strip a pane hangs from (`PaneTabs`)
7
+ * with the pure rules it and its host keep tab state by. Styled by the
8
+ * listing look under `.listing-root`.
7
9
  */
8
10
  export { InRowContext, QuietAction, RowIconAction, RowLinkLookContext, useInRow } from './PaneActions.js';
9
11
  export { PanePathBar, PaneStatus, PathFact } from './PaneFrame.js';
10
12
  export { isTabStop, nextTabStop, pageRows, paneRow, paneRows, showRow, tabStops, verbControl } from './PaneKeys.js';
11
13
  export { movedIndex, NO_MAIN_VERBS, paneKeyAction, sameVerbs } from './PaneKeys.logic.js';
14
+ export { PaneTabs } from './PaneTabs.js';
15
+ export { draggedTabOrder, foldOrder, foldsNeeded, gatherTabs, pickedTabs, pickRun, tabLabelFloor, togglePick } from './PaneTabs.logic.js';
12
16
  export { useToolbarFit } from './useToolbarFit.js';
13
17
  export { usePaneKeys } from './usePaneKeys.js';