@bigpixelrocket/uiok 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -1
- package/dist/button/TextLink.d.ts +21 -2
- package/dist/button/TextLink.js +14 -3
- package/dist/button/button.css +7 -0
- package/dist/dialog/SectionedDialog.d.ts +37 -0
- package/dist/dialog/SectionedDialog.js +158 -0
- package/dist/dialog/dialog.css +102 -0
- package/dist/dialog/index.d.ts +4 -2
- package/dist/dialog/index.js +4 -2
- package/dist/field/FieldLayout.d.ts +3 -2
- package/dist/field/FieldLayout.js +8 -3
- package/dist/frame/AppRoot.d.ts +1 -1
- package/dist/frame/AppRoot.js +2 -1
- package/dist/frame/Dock.d.ts +1 -1
- package/dist/frame/Dock.js +2 -1
- package/dist/frame/FilterChips.d.ts +5 -2
- package/dist/frame/FilterChips.js +35 -2
- package/dist/frame/FilterChips.logic.d.ts +24 -0
- package/dist/frame/FilterChips.logic.js +34 -0
- package/dist/frame/PageParts.d.ts +4 -3
- package/dist/frame/PageParts.js +10 -3
- package/dist/frame/SideBySide.d.ts +33 -0
- package/dist/frame/SideBySide.js +62 -0
- package/dist/frame/Tree.d.ts +20 -7
- package/dist/frame/Tree.js +21 -8
- package/dist/frame/WindowFrame.d.ts +1 -1
- package/dist/frame/WindowFrame.js +2 -1
- package/dist/frame/frame.css +56 -1
- package/dist/frame/index.d.ts +4 -2
- package/dist/frame/index.js +4 -2
- package/dist/grid/grid.css +1 -0
- package/dist/keyboard/Keyboard.logic.js +20 -3
- package/dist/keychord/KeyChord.d.ts +21 -4
- package/dist/keychord/KeyChord.js +24 -5
- package/dist/keychord/ShortcutIndex.d.ts +49 -0
- package/dist/keychord/ShortcutIndex.js +28 -0
- package/dist/keychord/index.d.ts +8 -2
- package/dist/keychord/index.js +8 -2
- package/dist/keychord/keychord.css +101 -0
- package/dist/labels/dialog.d.ts +2 -0
- package/dist/labels/dialog.js +2 -1
- package/dist/labels/keys.d.ts +5 -0
- package/dist/labels/keys.js +2 -1
- package/dist/legend/legend.css +6 -10
- package/dist/listing/Listing.d.ts +54 -4
- package/dist/listing/Listing.js +61 -7
- package/dist/listing/PaneMessage.d.ts +7 -4
- package/dist/listing/PaneMessage.js +11 -4
- package/dist/listing/index.d.ts +1 -1
- package/dist/listing/listing.css +124 -5
- package/dist/menu/Menu.d.ts +52 -8
- package/dist/menu/Menu.js +288 -80
- package/dist/menu/Menu.logic.d.ts +39 -12
- package/dist/menu/Menu.logic.js +36 -8
- package/dist/menu/index.d.ts +4 -3
- package/dist/menu/index.js +2 -1
- package/dist/menu/menu.css +4 -0
- package/dist/palette/Palette.d.ts +3 -1
- package/dist/palette/Palette.js +14 -2
- package/dist/palette/PaletteRows.d.ts +28 -14
- package/dist/palette/PaletteRows.js +21 -17
- package/dist/pane/Pane.d.ts +50 -6
- package/dist/pane/Pane.js +112 -5
- package/dist/pane/PaneKeys.d.ts +5 -1
- package/dist/pane/PaneKeys.js +28 -3
- package/dist/pane/PaneKeys.logic.d.ts +25 -0
- package/dist/pane/PaneKeys.logic.js +30 -0
- package/dist/pane/PaneTabs.js +7 -3
- package/dist/pane/index.d.ts +1 -1
- package/dist/pane/index.js +1 -1
- package/dist/pane/panetabs.css +14 -2
- package/dist/pane/usePaneKeys.d.ts +8 -1
- package/dist/pane/usePaneKeys.js +32 -12
- package/dist/styles.css +40 -3
- package/dist/surface/FactList.d.ts +54 -0
- package/dist/surface/FactList.js +33 -0
- package/dist/surface/index.d.ts +4 -1
- package/dist/surface/index.js +4 -1
- package/dist/surface/surface.css +85 -2
- package/dist/terminal/TerminalMenu.js +1 -1
- package/dist/terminal/ghostty/core.d.ts +12 -4
- package/dist/terminal/ghostty/core.js +12 -4
- package/dist/terminal/index.d.ts +4 -2
- package/dist/terminal/index.js +4 -2
- package/dist/terminal/terminal.css +3 -2
- package/dist/text/Code.d.ts +15 -0
- package/dist/text/Code.js +12 -0
- package/dist/text/index.d.ts +6 -1
- package/dist/text/index.js +6 -1
- package/dist/text/text.css +21 -0
- package/dist/themes/tokens.js +8 -3
- package/dist/tokens.css +4 -0
- package/dist/viewer/HexView.js +17 -8
- package/dist/viewer/ImageView.js +5 -3
- package/dist/viewer/PdfView.d.ts +8 -1
- package/dist/viewer/PdfView.js +27 -2
- package/dist/viewer/SyntaxHighlighter.d.ts +3 -2
- package/dist/viewer/SyntaxHighlighter.js +7 -2
- package/dist/viewer/SyntaxLanguage.logic.d.ts +5 -0
- package/dist/viewer/SyntaxLanguage.logic.js +17 -3
- package/dist/viewer/SyntaxService.d.ts +3 -1
- package/dist/viewer/SyntaxService.js +8 -1
- package/dist/viewer/TextView.js +14 -7
- package/dist/viewer/ViewerClipboard.js +17 -6
- package/dist/viewer/ViewerFrame.logic.js +4 -1
- package/dist/viewer/types.d.ts +3 -2
- package/package.json +1 -1
package/dist/menu/Menu.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { ICON_MD } from '../icon/sizes.js';
|
|
@@ -13,53 +13,51 @@ const revealItem = (itemId, position) => {
|
|
|
13
13
|
return;
|
|
14
14
|
document.getElementById(`${itemId}-${position}`)?.scrollIntoView?.({ block: 'nearest' });
|
|
15
15
|
};
|
|
16
|
+
const isRow = (entry) => entry.kind === undefined || entry.kind === 'item' || entry.kind === 'submenu';
|
|
16
17
|
const isItem = (entry) => entry.kind === undefined || entry.kind === 'item';
|
|
18
|
+
const pickableRows = (rows) => rows.map((row) => ({ key: row.id, taken: row.disabled === true }));
|
|
19
|
+
/** Whether an element reads right to left, where a submenu stands on the left. */
|
|
20
|
+
const isRtl = (element) => getComputedStyle(element).direction === 'rtl';
|
|
21
|
+
const NO_BOX = { left: 0, top: 0, right: 0, bottom: 0 };
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* danger tone; a setting with its check; the current place with its dot;
|
|
22
|
-
* separators and group headings between them. It is the menu look
|
|
23
|
-
* (`.folder-menu`) drawn through a portal on the document's body (or the
|
|
24
|
-
* element shown full screen), so no pane or dialog clips it, placed inside
|
|
25
|
-
* the window (`placeMenu`); React still carries its events to its owner.
|
|
26
|
-
*
|
|
27
|
-
* It takes the focus and holds the keys while open (`menuKeyAction`: ↑ ↓,
|
|
28
|
-
* Home, End, Return and Space, Escape and Tab), which travel no further, so
|
|
29
|
-
* neither a dialog nor the page hears them; `data-native-keyboard` keeps
|
|
30
|
-
* the browser-key guard and a page's own key handlers out
|
|
31
|
-
* (`isNativeKeyboardTarget`), and `data-overlay` marks it an open overlay
|
|
32
|
-
* while it shows. A press on it never takes the focus from it; a press or
|
|
33
|
-
* a focus anywhere else closes it. A menu taller than the window less its
|
|
34
|
-
* margins scrolls, and the keys keep the cursor's item in view.
|
|
23
|
+
* How long the pointer may cross other items on its way into an open
|
|
24
|
+
* submenu, in milliseconds, before the item it stays on takes the cursor
|
|
25
|
+
* and the submenu gives way.
|
|
35
26
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const onCloseRef = useRef(onClose);
|
|
27
|
+
const SUBMENU_GRACE_MS = 250;
|
|
28
|
+
/**
|
|
29
|
+
* The surface a menu or its submenu is drawn on, through a portal on the
|
|
30
|
+
* document's body (or the element shown full screen), placed after layout,
|
|
31
|
+
* when its size is known, and placed again when the window resizes, the
|
|
32
|
+
* cursor's item kept in view.
|
|
33
|
+
*/
|
|
34
|
+
function MenuSurface({ surfaceRef, id, label, labelledBy, entries, cursor, itemId, expanded, compact, at, anchor, besideId, onKeyDown, onBlur, onMouseMove, onMouseLeave, dir, onRowClick, onRowMove }) {
|
|
45
35
|
const cursorRef = useRef(cursor);
|
|
46
36
|
useLayoutEffect(() => {
|
|
47
|
-
onCloseRef.current = onClose;
|
|
48
37
|
cursorRef.current = cursor;
|
|
49
38
|
});
|
|
50
|
-
// Placed
|
|
51
|
-
//
|
|
52
|
-
//
|
|
39
|
+
// Placed again when its menu moves or turns direction: a submenu is given
|
|
40
|
+
// its menu's point and anchor too, so it follows the item it stands beside,
|
|
41
|
+
// and turns sides with the direction, which places a menu itself nowhere new.
|
|
42
|
+
const turn = besideId === undefined ? undefined : dir;
|
|
53
43
|
useLayoutEffect(() => {
|
|
54
|
-
const menu =
|
|
44
|
+
const menu = surfaceRef.current;
|
|
55
45
|
if (menu === null)
|
|
56
46
|
return;
|
|
47
|
+
const from = () => {
|
|
48
|
+
if (besideId !== undefined) {
|
|
49
|
+
const item = document.getElementById(besideId);
|
|
50
|
+
return {
|
|
51
|
+
beside: item?.getBoundingClientRect() ?? NO_BOX,
|
|
52
|
+
rtl: item !== null && isRtl(item)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return at !== undefined ? { point: at } : { box: anchor?.getBoundingClientRect() ?? NO_BOX };
|
|
56
|
+
};
|
|
57
57
|
const place = () => {
|
|
58
58
|
const size = { width: menu.offsetWidth, height: menu.offsetHeight };
|
|
59
59
|
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
60
|
-
const spot = placeMenu(
|
|
61
|
-
? { point: at }
|
|
62
|
-
: { box: anchor?.getBoundingClientRect() ?? { left: 0, top: 0, right: 0, bottom: 0 } }, size, viewport);
|
|
60
|
+
const spot = placeMenu(from(), size, viewport);
|
|
63
61
|
menu.style.left = `${spot.left}px`;
|
|
64
62
|
menu.style.top = `${spot.top}px`;
|
|
65
63
|
};
|
|
@@ -69,75 +67,285 @@ export function Menu({ label, entries, at, anchor = null, initial = null, compac
|
|
|
69
67
|
revealItem(itemId, cursorRef.current);
|
|
70
68
|
};
|
|
71
69
|
place();
|
|
72
|
-
menu.focus({ preventScroll: true });
|
|
73
70
|
// A menu taller than the window scrolls; it opens with its cursor in view.
|
|
74
71
|
revealItem(itemId, cursorRef.current);
|
|
75
72
|
window.addEventListener('resize', replace);
|
|
76
73
|
return () => window.removeEventListener('resize', replace);
|
|
77
|
-
}, [at, anchor, itemId]);
|
|
74
|
+
}, [at, anchor, besideId, turn, itemId, surfaceRef]);
|
|
75
|
+
let index = -1;
|
|
76
|
+
return createPortal(_jsx("div", { "aria-activedescendant": cursor === null ? undefined : `${itemId}-${cursor}`, "aria-label": label, "aria-labelledby": labelledBy, className: compact ? 'folder-menu folder-menu-compact menu-popup' : 'folder-menu menu-popup', "data-native-keyboard": true, "data-overlay": true, dir: dir, id: id, onBlur: onBlur, onContextMenu: (event) => event.preventDefault(), onKeyDown: onKeyDown,
|
|
77
|
+
// A press on an item must not take the focus from the menu, which holds the keys.
|
|
78
|
+
onMouseDown: (event) => event.preventDefault(), onMouseLeave: onMouseLeave, onMouseMove: onMouseMove, ref: surfaceRef, role: "menu", tabIndex: -1, children: entries.map((entry, entryIndex) => {
|
|
79
|
+
if (entry.kind === 'separator') {
|
|
80
|
+
return (_jsx("div", { className: "folder-menu-separator", role: "separator" }, `separator-${entryIndex}`));
|
|
81
|
+
}
|
|
82
|
+
if (entry.kind === 'heading') {
|
|
83
|
+
return (_jsx("div", { className: "entry-menu-heading", role: "presentation", children: entry.label }, `heading-${entryIndex}`));
|
|
84
|
+
}
|
|
85
|
+
index += 1;
|
|
86
|
+
const position = index;
|
|
87
|
+
const Icon = entry.icon;
|
|
88
|
+
const submenu = entry.kind === 'submenu';
|
|
89
|
+
const open = submenu && expanded?.id === entry.id;
|
|
90
|
+
const classes = [
|
|
91
|
+
'folder-menu-option',
|
|
92
|
+
position === cursor ? 'cursor' : '',
|
|
93
|
+
!submenu && entry.danger === true ? 'danger' : ''
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.join(' ');
|
|
97
|
+
return (_jsxs("div", { "aria-checked": submenu ? undefined : entry.checked, "aria-controls": open ? expanded.menu : undefined, "aria-disabled": entry.disabled === true || undefined, "aria-expanded": submenu ? open : undefined, "aria-haspopup": submenu ? 'menu' : undefined, className: classes, id: `${itemId}-${position}`, onClick: () => onRowClick(entry), onMouseMove: () => onRowMove(entry), role: submenu || entry.checked === undefined ? 'menuitem' : 'menuitemcheckbox', ...describedTooltip(entry.tip), children: [_jsx("span", { "aria-hidden": true, className: "row-icon", children: Icon === undefined ? entry.mark : _jsx(Icon, { size: ICON_MD }) }), _jsxs("span", { className: "menu-label", children: [_jsx("span", { className: "menu-label-text", children: entry.label }), submenu || entry.current === undefined || entry.current === null ? null : (_jsxs(_Fragment, { children: [' ', _jsx(CurrentDot, { label: entry.current })] }))] }), submenu || entry.chord === undefined ? null : (_jsxs(_Fragment, { children: [' ', _jsx(KeyChord, { chord: entry.chord })] }))] }, entry.id));
|
|
98
|
+
}) }), document.fullscreenElement ?? document.body);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A menu of verbs or places, opened at a point (a secondary click's) or
|
|
102
|
+
* dropped from an element (a crumb's ⌄, an Actions button): each item its
|
|
103
|
+
* glyph, its words, and its chord as key caps; a destructive one in the
|
|
104
|
+
* danger tone; a setting with its check; the current place with its dot;
|
|
105
|
+
* separators and group headings between them; and items that open a
|
|
106
|
+
* submenu beside them, one level deep. It is the menu look
|
|
107
|
+
* (`.folder-menu`) drawn through a portal on the document's body (or the
|
|
108
|
+
* element shown full screen), so no pane or dialog clips it, placed inside
|
|
109
|
+
* the window (`placeMenu`); React still carries its events to its owner.
|
|
110
|
+
*
|
|
111
|
+
* It takes the focus and holds the keys while open (`menuKeyAction`: ↑ ↓,
|
|
112
|
+
* Home, End, Return and Space, → and ←, Escape and Tab), which travel no
|
|
113
|
+
* further, so neither a dialog nor the page hears them; `data-native-keyboard`
|
|
114
|
+
* keeps the browser-key guard and a page's own key handlers out
|
|
115
|
+
* (`isNativeKeyboardTarget`), and `data-overlay` marks it an open overlay
|
|
116
|
+
* while it shows. A press on it never takes the focus from it; a press or
|
|
117
|
+
* a focus anywhere else closes it. A menu taller than the window less its
|
|
118
|
+
* margins scrolls, and the keys keep the cursor's item in view.
|
|
119
|
+
*
|
|
120
|
+
* A submenu opens beside its item (on the inline-end side, or the other
|
|
121
|
+
* when the window has no room there) when the pointer rests on the item or
|
|
122
|
+
* presses it, showing without the keys, or with the keys and its cursor on
|
|
123
|
+
* its first item that can run on → (← in a right-to-left page), Return,
|
|
124
|
+
* or Space. ← goes back to its item, and Escape closes the submenu alone;
|
|
125
|
+
* Tab closes the whole menu. The pointer crossing other items on its way
|
|
126
|
+
* into the submenu leaves it open for a moment, and moving over the
|
|
127
|
+
* submenu gives it the keys.
|
|
128
|
+
*/
|
|
129
|
+
export function Menu({ label, entries, at, anchor = null, initial = null, compact = false, dir: dirGiven, onPick, onClose }) {
|
|
130
|
+
const rootRef = useRef(null);
|
|
131
|
+
const originRef = useRef(null);
|
|
132
|
+
const [dirFound, setDirFound] = useState(undefined);
|
|
133
|
+
const dir = dirGiven ?? dirFound;
|
|
134
|
+
const subRef = useRef(null);
|
|
135
|
+
const itemId = useId();
|
|
136
|
+
const subItemId = useId();
|
|
137
|
+
const [pointed, setPointed] = useState(initial);
|
|
138
|
+
const [subState, setSub] = useState(null);
|
|
139
|
+
const grace = useRef(null);
|
|
140
|
+
const rows = entries.filter(isRow);
|
|
141
|
+
const pickable = pickableRows(rows);
|
|
142
|
+
const cursor = pickableCursor(pickable, pointed);
|
|
143
|
+
const cursorRow = cursor === null ? null : (rows[cursor] ?? null);
|
|
144
|
+
const subPlace = subState === null
|
|
145
|
+
? -1
|
|
146
|
+
: rows.findIndex((row) => row.kind === 'submenu' && row.id === subState.id && !row.disabled);
|
|
147
|
+
const subEntry = subPlace === -1 ? null : rows[subPlace];
|
|
148
|
+
// The submenu shown: none once its item is disabled or gone from `entries`.
|
|
149
|
+
const sub = subEntry === null ? null : subState;
|
|
150
|
+
const subRows = subEntry === null ? [] : subEntry.entries.filter(isItem);
|
|
151
|
+
const subPickable = pickableRows(subRows);
|
|
152
|
+
const subCursor = sub === null || sub.pointed === null ? null : pickableCursor(subPickable, sub.pointed);
|
|
153
|
+
const subCursorRow = subCursor === null ? null : (subRows[subCursor] ?? null);
|
|
154
|
+
const keysInSub = subEntry !== null && sub?.keys === true;
|
|
155
|
+
const onCloseRef = useRef(onClose);
|
|
156
|
+
const subCursorRef = useRef(subCursor);
|
|
157
|
+
useLayoutEffect(() => {
|
|
158
|
+
onCloseRef.current = onClose;
|
|
159
|
+
subCursorRef.current = subCursor;
|
|
160
|
+
});
|
|
161
|
+
// Drawn on the body, it reads in the direction of what opened it, read
|
|
162
|
+
// again when the anchor changes or a given direction is taken away (the
|
|
163
|
+
// marker the fallback reads mounts only then).
|
|
164
|
+
useLayoutEffect(() => {
|
|
165
|
+
const opener = anchor ?? originRef.current;
|
|
166
|
+
if (opener !== null)
|
|
167
|
+
setDirFound(isRtl(opener) ? 'rtl' : 'ltr');
|
|
168
|
+
}, [anchor, dirGiven]);
|
|
169
|
+
// An item disabled or gone takes its submenu with it.
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (subState !== null && subEntry === null)
|
|
172
|
+
setSub(null);
|
|
173
|
+
}, [subState, subEntry]);
|
|
174
|
+
// The keys stay where the menu holds them, the menu or its submenu, and
|
|
175
|
+
// come back to it when it moves (the anchor may have taken them). Keys
|
|
176
|
+
// taking over a submenu the pointer opened bring its cursor into view.
|
|
177
|
+
useLayoutEffect(() => {
|
|
178
|
+
(keysInSub ? subRef : rootRef).current?.focus({ preventScroll: true });
|
|
179
|
+
if (keysInSub)
|
|
180
|
+
revealItem(subItemId, subCursorRef.current);
|
|
181
|
+
}, [keysInSub, at, anchor, subItemId]);
|
|
78
182
|
// A press outside closes it, but one on its anchor, which toggles it.
|
|
79
183
|
useEffect(() => {
|
|
80
184
|
const listener = (event) => {
|
|
81
185
|
const target = event.target;
|
|
82
186
|
if (!(target instanceof Node))
|
|
83
187
|
return;
|
|
84
|
-
if (rootRef.current?.contains(target) ||
|
|
188
|
+
if (rootRef.current?.contains(target) ||
|
|
189
|
+
subRef.current?.contains(target) ||
|
|
190
|
+
anchor?.contains(target))
|
|
85
191
|
return;
|
|
86
192
|
onCloseRef.current('pointer');
|
|
87
193
|
};
|
|
88
194
|
document.addEventListener('mousedown', listener, true);
|
|
89
195
|
return () => document.removeEventListener('mousedown', listener, true);
|
|
90
196
|
}, [anchor]);
|
|
197
|
+
useEffect(() => () => {
|
|
198
|
+
if (grace.current !== null)
|
|
199
|
+
window.clearTimeout(grace.current.timer);
|
|
200
|
+
}, []);
|
|
201
|
+
const clearGrace = () => {
|
|
202
|
+
if (grace.current === null)
|
|
203
|
+
return;
|
|
204
|
+
window.clearTimeout(grace.current.timer);
|
|
205
|
+
grace.current = null;
|
|
206
|
+
};
|
|
91
207
|
const run = (item) => {
|
|
92
|
-
if (item !== null && item.disabled !== true)
|
|
208
|
+
if (item !== null && item.kind !== 'submenu' && item.disabled !== true)
|
|
93
209
|
onPick(item.id);
|
|
94
210
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
211
|
+
// The keys go back to the menu before the submenu goes, so its unmount never drops the focus.
|
|
212
|
+
const closeSub = () => {
|
|
213
|
+
clearGrace();
|
|
214
|
+
if (subRef.current?.contains(document.activeElement)) {
|
|
215
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
216
|
+
}
|
|
217
|
+
setSub(null);
|
|
218
|
+
};
|
|
219
|
+
// With the keys, its cursor starts on its first item that can run; for the pointer, on none.
|
|
220
|
+
const openSub = (item, keys) => {
|
|
221
|
+
clearGrace();
|
|
222
|
+
const items = item.entries.filter(isItem);
|
|
223
|
+
const first = keys ? pickableCursor(pickableRows(items), null) : null;
|
|
224
|
+
setPointed(item.id);
|
|
225
|
+
setSub({ id: item.id, keys, pointed: first === null ? null : (items[first]?.id ?? null) });
|
|
226
|
+
};
|
|
227
|
+
// The pointer rests on a row of the menu: it takes the cursor, and a submenu's opens.
|
|
228
|
+
const pointAt = (row) => {
|
|
229
|
+
clearGrace();
|
|
230
|
+
if (sub?.id === row.id)
|
|
231
|
+
return;
|
|
232
|
+
if (sub !== null)
|
|
233
|
+
closeSub();
|
|
234
|
+
if (row.disabled === true)
|
|
235
|
+
return;
|
|
236
|
+
if (row.kind === 'submenu')
|
|
237
|
+
openSub(row, false);
|
|
238
|
+
else
|
|
239
|
+
setPointed(row.id);
|
|
240
|
+
};
|
|
241
|
+
const within = (to) => to instanceof Node &&
|
|
242
|
+
(rootRef.current?.contains(to) === true ||
|
|
243
|
+
subRef.current?.contains(to) === true ||
|
|
244
|
+
anchor?.contains(to) === true);
|
|
245
|
+
const onBlur = (event) => {
|
|
246
|
+
if (!within(event.relatedTarget))
|
|
100
247
|
onClose('pointer');
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
248
|
+
};
|
|
249
|
+
const take = (event) => {
|
|
250
|
+
const action = menuKeyAction(event, isRtl(event.currentTarget));
|
|
251
|
+
if (action === null)
|
|
252
|
+
return null;
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
return action;
|
|
256
|
+
};
|
|
257
|
+
const onMenuKey = (event) => {
|
|
258
|
+
const action = take(event);
|
|
259
|
+
if (action === null)
|
|
260
|
+
return;
|
|
261
|
+
switch (action.kind) {
|
|
262
|
+
case 'close':
|
|
263
|
+
// Escape closes a submenu the pointer opened before the menu.
|
|
264
|
+
if (action.all || sub === null)
|
|
265
|
+
onClose('keyboard');
|
|
266
|
+
else
|
|
267
|
+
closeSub();
|
|
104
268
|
return;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
269
|
+
case 'back':
|
|
270
|
+
if (sub !== null)
|
|
271
|
+
closeSub();
|
|
272
|
+
return;
|
|
273
|
+
case 'open':
|
|
274
|
+
case 'run':
|
|
275
|
+
if (cursorRow?.kind === 'submenu')
|
|
276
|
+
openSub(cursorRow, true);
|
|
277
|
+
else if (action.kind === 'run')
|
|
278
|
+
run(cursorRow);
|
|
279
|
+
return;
|
|
280
|
+
default: {
|
|
112
281
|
const next = action.kind === 'move'
|
|
113
|
-
? movedPickableCursor(
|
|
114
|
-
: movedPickableCursor(
|
|
115
|
-
|
|
282
|
+
? movedPickableCursor(pickable, cursor, action.delta)
|
|
283
|
+
: movedPickableCursor(pickable, null, action.to === 'first' ? 1 : -1);
|
|
284
|
+
if (sub !== null)
|
|
285
|
+
closeSub();
|
|
286
|
+
setPointed(next === null ? null : (rows[next]?.id ?? null));
|
|
116
287
|
// Only the keys scroll: an item under the pointer is already in view.
|
|
117
288
|
revealItem(itemId, next);
|
|
118
289
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
const onSubKey = (event) => {
|
|
293
|
+
const action = take(event);
|
|
294
|
+
if (action === null || sub === null)
|
|
295
|
+
return;
|
|
296
|
+
switch (action.kind) {
|
|
297
|
+
case 'close':
|
|
298
|
+
if (action.all)
|
|
299
|
+
onClose('keyboard');
|
|
300
|
+
else
|
|
301
|
+
closeSub();
|
|
302
|
+
return;
|
|
303
|
+
case 'back':
|
|
304
|
+
closeSub();
|
|
305
|
+
return;
|
|
306
|
+
case 'open':
|
|
307
|
+
return;
|
|
308
|
+
case 'run':
|
|
309
|
+
run(subCursorRow);
|
|
310
|
+
return;
|
|
311
|
+
default: {
|
|
312
|
+
const next = action.kind === 'move'
|
|
313
|
+
? movedPickableCursor(subPickable, subCursor, action.delta)
|
|
314
|
+
: movedPickableCursor(subPickable, null, action.to === 'first' ? 1 : -1);
|
|
315
|
+
setSub({ ...sub, pointed: next === null ? null : (subRows[next]?.id ?? null) });
|
|
316
|
+
revealItem(subItemId, next);
|
|
127
317
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
const subMenuId = `${subItemId}-menu`;
|
|
321
|
+
return (_jsxs(_Fragment, { children: [dirGiven === undefined && anchor === null ? _jsx("span", { hidden: true, ref: originRef }) : null, _jsx(MenuSurface, { anchor: anchor, at: at, compact: compact, cursor: cursor, dir: dir, entries: entries, expanded: subEntry === null ? null : { id: subEntry.id, menu: subMenuId }, itemId: itemId, label: label, onBlur: onBlur, onKeyDown: onMenuKey, onMouseLeave: clearGrace, onRowClick: (row) => {
|
|
322
|
+
if (row.kind === 'submenu')
|
|
323
|
+
pointAt(row);
|
|
324
|
+
else
|
|
325
|
+
run(row);
|
|
326
|
+
}, onRowMove: (row) => {
|
|
327
|
+
if (sub === null || row.id === sub.id) {
|
|
328
|
+
pointAt(row);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
// On its way into the submenu the pointer may cross other items:
|
|
332
|
+
// the one it stays on takes the cursor once the moment passes.
|
|
333
|
+
if (grace.current !== null) {
|
|
334
|
+
grace.current.to = row;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
grace.current = {
|
|
338
|
+
to: row,
|
|
339
|
+
timer: window.setTimeout(() => {
|
|
340
|
+
const to = grace.current?.to;
|
|
341
|
+
grace.current = null;
|
|
342
|
+
if (to !== undefined)
|
|
343
|
+
pointAt(to);
|
|
344
|
+
}, SUBMENU_GRACE_MS)
|
|
345
|
+
};
|
|
346
|
+
}, surfaceRef: rootRef }), subEntry === null ? null : (_jsx(MenuSurface, { anchor: anchor, at: at, besideId: `${itemId}-${subPlace}`, compact: compact, cursor: subCursor, dir: dir, entries: subEntry.entries, expanded: null, id: subMenuId, itemId: subItemId, labelledBy: `${itemId}-${subPlace}`, onBlur: onBlur, onKeyDown: onSubKey, onMouseLeave: clearGrace, onMouseMove: clearGrace, onRowClick: run, onRowMove: (row) => {
|
|
347
|
+
clearGrace();
|
|
348
|
+
if (row.disabled !== true && sub !== null)
|
|
349
|
+
setSub({ ...sub, pointed: row.id, keys: true });
|
|
350
|
+
}, surfaceRef: subRef }))] }));
|
|
143
351
|
}
|
|
@@ -17,25 +17,44 @@ export interface MenuSize {
|
|
|
17
17
|
}
|
|
18
18
|
/** The room a menu keeps from the window's edges, and the gap it leaves under what it drops from, in pixels. */
|
|
19
19
|
export declare const MENU_MARGIN = 4;
|
|
20
|
+
/**
|
|
21
|
+
* Where a menu opens from: a point (a secondary click's), a box it drops
|
|
22
|
+
* from (a crumb, a button), or the box of the item whose submenu it is,
|
|
23
|
+
* which it stands beside (on the item's inline-end side, the right unless
|
|
24
|
+
* `rtl`).
|
|
25
|
+
*/
|
|
26
|
+
export type MenuFrom = {
|
|
27
|
+
readonly point: MenuPoint;
|
|
28
|
+
} | {
|
|
29
|
+
readonly box: MenuBox;
|
|
30
|
+
} | {
|
|
31
|
+
readonly beside: MenuBox;
|
|
32
|
+
readonly rtl?: boolean;
|
|
33
|
+
};
|
|
20
34
|
/**
|
|
21
35
|
* Where a menu stands, its top-left corner in window coordinates. Opened at
|
|
22
36
|
* a point, it hangs down and right from it, moved in to stay inside the
|
|
23
37
|
* window, and opens upward from the point when there is no room below.
|
|
24
38
|
* Dropped from a box, it starts under the box's leading edge, a margin
|
|
25
39
|
* below, and stands over the box instead when there is room above and none
|
|
26
|
-
* below
|
|
27
|
-
*
|
|
28
|
-
*
|
|
40
|
+
* below. A submenu stands beside its item, on the item's inline-end side,
|
|
41
|
+
* its first item level with it (a margin above the item's top, the menu's
|
|
42
|
+
* own padding), and on the other side when the window has no room on that
|
|
43
|
+
* one; when neither side has room it keeps to the side with more. Every
|
|
44
|
+
* way it stays inside the window. A menu its stylesheet caps at the
|
|
45
|
+
* window's height less both margins (`.menu-popup`) measures at that cap,
|
|
46
|
+
* so it starts at the top margin.
|
|
29
47
|
*/
|
|
30
|
-
export declare function placeMenu(from: {
|
|
31
|
-
readonly point: MenuPoint;
|
|
32
|
-
} | {
|
|
33
|
-
readonly box: MenuBox;
|
|
34
|
-
}, size: MenuSize, viewport: MenuSize): {
|
|
48
|
+
export declare function placeMenu(from: MenuFrom, size: MenuSize, viewport: MenuSize): {
|
|
35
49
|
readonly left: number;
|
|
36
50
|
readonly top: number;
|
|
37
51
|
};
|
|
38
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* What a key pressed in an open menu does. `open` and `back` are the arrows
|
|
54
|
+
* along the line: into the cursor's submenu, and out of a submenu to its
|
|
55
|
+
* item. `close` closes one level (Escape: a submenu, else the menu), or
|
|
56
|
+
* with `all` the whole menu (Tab).
|
|
57
|
+
*/
|
|
39
58
|
export type MenuKeyAction = {
|
|
40
59
|
readonly kind: 'move';
|
|
41
60
|
readonly delta: number;
|
|
@@ -44,13 +63,21 @@ export type MenuKeyAction = {
|
|
|
44
63
|
readonly to: 'first' | 'last';
|
|
45
64
|
} | {
|
|
46
65
|
readonly kind: 'run';
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: 'open';
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: 'back';
|
|
47
70
|
} | {
|
|
48
71
|
readonly kind: 'close';
|
|
72
|
+
readonly all: boolean;
|
|
49
73
|
};
|
|
50
74
|
/**
|
|
51
75
|
* The menu's keys, as a desktop menu's: ↑ and ↓ move the cursor over the
|
|
52
76
|
* items that can run, Home and End to the first and the last, Return and
|
|
53
|
-
* Space run the cursor's item
|
|
54
|
-
*
|
|
77
|
+
* Space run the cursor's item (or open its submenu), → opens the cursor's
|
|
78
|
+
* submenu and ← goes back out of one (the other way round when `rtl`, so
|
|
79
|
+
* the arrow points where the submenu stands), Escape closes one level and
|
|
80
|
+
* Tab the whole menu. A chord with a modifier is not the menu's (null),
|
|
81
|
+
* and neither is any other key.
|
|
55
82
|
*/
|
|
56
|
-
export declare function menuKeyAction(event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'
|
|
83
|
+
export declare function menuKeyAction(event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'>, rtl?: boolean): MenuKeyAction | null;
|
package/dist/menu/Menu.logic.js
CHANGED
|
@@ -8,12 +8,33 @@ const clamp = (start, extent, room) => Math.max(MENU_MARGIN, Math.min(start, roo
|
|
|
8
8
|
* window, and opens upward from the point when there is no room below.
|
|
9
9
|
* Dropped from a box, it starts under the box's leading edge, a margin
|
|
10
10
|
* below, and stands over the box instead when there is room above and none
|
|
11
|
-
* below
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* below. A submenu stands beside its item, on the item's inline-end side,
|
|
12
|
+
* its first item level with it (a margin above the item's top, the menu's
|
|
13
|
+
* own padding), and on the other side when the window has no room on that
|
|
14
|
+
* one; when neither side has room it keeps to the side with more. Every
|
|
15
|
+
* way it stays inside the window. A menu its stylesheet caps at the
|
|
16
|
+
* window's height less both margins (`.menu-popup`) measures at that cap,
|
|
17
|
+
* so it starts at the top margin.
|
|
14
18
|
*/
|
|
15
19
|
export function placeMenu(from, size, viewport) {
|
|
16
20
|
const room = (top) => top + size.height <= viewport.height - MENU_MARGIN;
|
|
21
|
+
if ('beside' in from) {
|
|
22
|
+
const { beside: item, rtl = false } = from;
|
|
23
|
+
const after = item.right;
|
|
24
|
+
const before = item.left - size.width;
|
|
25
|
+
const fitsAfter = after + size.width <= viewport.width - MENU_MARGIN;
|
|
26
|
+
const fitsBefore = before >= MENU_MARGIN;
|
|
27
|
+
const roomAfter = viewport.width - item.right;
|
|
28
|
+
const roomBefore = item.left;
|
|
29
|
+
// Its own side while it fits there; the other while that fits; else the roomier one.
|
|
30
|
+
const startsAfter = rtl
|
|
31
|
+
? !fitsBefore && (fitsAfter || roomAfter > roomBefore)
|
|
32
|
+
: fitsAfter || (!fitsBefore && roomAfter >= roomBefore);
|
|
33
|
+
return {
|
|
34
|
+
left: clamp(startsAfter ? after : before, size.width, viewport.width),
|
|
35
|
+
top: clamp(item.top - MENU_MARGIN, size.height, viewport.height)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
17
38
|
if ('point' in from) {
|
|
18
39
|
const { x, y } = from.point;
|
|
19
40
|
const top = room(y) || y - size.height < MENU_MARGIN ? y : y - size.height;
|
|
@@ -34,14 +55,17 @@ export function placeMenu(from, size, viewport) {
|
|
|
34
55
|
/**
|
|
35
56
|
* The menu's keys, as a desktop menu's: ↑ and ↓ move the cursor over the
|
|
36
57
|
* items that can run, Home and End to the first and the last, Return and
|
|
37
|
-
* Space run the cursor's item
|
|
38
|
-
*
|
|
58
|
+
* Space run the cursor's item (or open its submenu), → opens the cursor's
|
|
59
|
+
* submenu and ← goes back out of one (the other way round when `rtl`, so
|
|
60
|
+
* the arrow points where the submenu stands), Escape closes one level and
|
|
61
|
+
* Tab the whole menu. A chord with a modifier is not the menu's (null),
|
|
62
|
+
* and neither is any other key.
|
|
39
63
|
*/
|
|
40
|
-
export function menuKeyAction(event) {
|
|
64
|
+
export function menuKeyAction(event, rtl = false) {
|
|
41
65
|
if (event.metaKey || event.ctrlKey || event.altKey)
|
|
42
66
|
return null;
|
|
43
67
|
if (event.key === 'Tab')
|
|
44
|
-
return { kind: 'close' };
|
|
68
|
+
return { kind: 'close', all: true };
|
|
45
69
|
if (event.shiftKey)
|
|
46
70
|
return null;
|
|
47
71
|
switch (event.key) {
|
|
@@ -49,6 +73,10 @@ export function menuKeyAction(event) {
|
|
|
49
73
|
return { kind: 'move', delta: -1 };
|
|
50
74
|
case 'ArrowDown':
|
|
51
75
|
return { kind: 'move', delta: 1 };
|
|
76
|
+
case 'ArrowRight':
|
|
77
|
+
return { kind: rtl ? 'back' : 'open' };
|
|
78
|
+
case 'ArrowLeft':
|
|
79
|
+
return { kind: rtl ? 'open' : 'back' };
|
|
52
80
|
case 'Home':
|
|
53
81
|
return { kind: 'edge', to: 'first' };
|
|
54
82
|
case 'End':
|
|
@@ -57,7 +85,7 @@ export function menuKeyAction(event) {
|
|
|
57
85
|
case ' ':
|
|
58
86
|
return { kind: 'run' };
|
|
59
87
|
case 'Escape':
|
|
60
|
-
return { kind: 'close' };
|
|
88
|
+
return { kind: 'close', all: false };
|
|
61
89
|
default:
|
|
62
90
|
return null;
|
|
63
91
|
}
|
package/dist/menu/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Menus: `Menu`, a menu of verbs or places opened at a point or dropped
|
|
3
|
-
* from an element,
|
|
3
|
+
* from an element, its items able to open one level of submenus, with
|
|
4
|
+
* `placeMenu` and `menuKeyAction` under it; and for
|
|
4
5
|
* filtered menus: the fuzzy matcher (`matchQuery`), the rules every filtered
|
|
5
6
|
* menu and palette shares (a refused keystroke, the cursor's moves, the trail
|
|
6
7
|
* of levels opened in place), the visual bell's beat, and the menu look in
|
|
@@ -9,5 +10,5 @@
|
|
|
9
10
|
export { hasNegativeTerms, hasQueryTerms, matchQuery, type FuzzyMatch } from './fuzzyMatch.js';
|
|
10
11
|
export { enteredLevel, leftLevel, menuQueryRefused, movedPickableCursor, moveMenuCursor, pickableCursor, returnedCursor, trailLevel, type LevelReturn, type LevelStep, type PickableRow } from './MenuQuery.logic.js';
|
|
11
12
|
export { useBellBeat } from './useBellBeat.js';
|
|
12
|
-
export { Menu, type MenuEntry, type MenuHeadingEntry, type MenuItemEntry, type MenuProps, type MenuSeparatorEntry } from './Menu.js';
|
|
13
|
-
export { MENU_MARGIN, menuKeyAction, placeMenu, type MenuBox, type MenuKeyAction, type MenuPoint, type MenuSize } from './Menu.logic.js';
|
|
13
|
+
export { Menu, type MenuEntry, type MenuHeadingEntry, type MenuItemEntry, type MenuLeafEntry, type MenuProps, type MenuSeparatorEntry, type MenuSubmenuEntry } from './Menu.js';
|
|
14
|
+
export { MENU_MARGIN, menuKeyAction, placeMenu, type MenuBox, type MenuFrom, type MenuKeyAction, type MenuPoint, type MenuSize } from './Menu.logic.js';
|
package/dist/menu/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Menus: `Menu`, a menu of verbs or places opened at a point or dropped
|
|
3
|
-
* from an element,
|
|
3
|
+
* from an element, its items able to open one level of submenus, with
|
|
4
|
+
* `placeMenu` and `menuKeyAction` under it; and for
|
|
4
5
|
* filtered menus: the fuzzy matcher (`matchQuery`), the rules every filtered
|
|
5
6
|
* menu and palette shares (a refused keystroke, the cursor's moves, the trail
|
|
6
7
|
* of levels opened in place), the visual bell's beat, and the menu look in
|
package/dist/menu/menu.css
CHANGED
|
@@ -244,6 +244,10 @@
|
|
|
244
244
|
background: var(--text-dim);
|
|
245
245
|
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E")
|
|
246
246
|
center / contain no-repeat;
|
|
247
|
+
/* Right to left, a submenu opens on the left, so the chevron points
|
|
248
|
+
there: --inline-flip follows the nearest dir attribute (styles.css), as
|
|
249
|
+
the menu's own placement follows the nearest direction. */
|
|
250
|
+
transform: scaleX(var(--inline-flip, 1));
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
.folder-menu-option.cursor[aria-haspopup='menu']:not([aria-disabled='true'])::after {
|
|
@@ -72,7 +72,9 @@ export interface PaletteQueryProps {
|
|
|
72
72
|
* stands below its first level, the field (a combobox over the list it
|
|
73
73
|
* names, holding the focus), then the count ("3 of 12") while a query
|
|
74
74
|
* narrows the list, or, after a refused keystroke, why it was refused in the
|
|
75
|
-
* count's place, and any tag the caller puts at the field's end.
|
|
75
|
+
* count's place, and any tag the caller puts at the field's end. The field
|
|
76
|
+
* cancels Return's default before the caller's `onKeyDown` runs, so a focus
|
|
77
|
+
* the caller hands back on close cannot take the same key. A refused
|
|
76
78
|
* keystroke also rings the visual bell on the row, once per refusal
|
|
77
79
|
* (`useBellBeat`). The chip's words and the refusal come from the `palette`
|
|
78
80
|
* label group.
|