@newtone-dev/ui-react-web 0.49.0 → 0.50.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/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node-map/node-map.css +13 -0
- package/dist/node-map/node-map.d.ts +5 -0
- package/dist/node-map/node-map.d.ts.map +1 -1
- package/dist/node-map/node-map.js +12 -3
- package/dist/node-map/node-map.js.map +1 -1
- package/dist/outline/index.d.ts +2 -2
- package/dist/outline/index.d.ts.map +1 -1
- package/dist/outline/index.js +1 -1
- package/dist/outline/index.js.map +1 -1
- package/dist/outline/outline.css +105 -1
- package/dist/outline/outline.d.ts +77 -1
- package/dist/outline/outline.d.ts.map +1 -1
- package/dist/outline/outline.js +540 -13
- package/dist/outline/outline.js.map +1 -1
- package/dist/select/select.d.ts.map +1 -1
- package/dist/select/select.js +4 -1
- package/dist/select/select.js.map +1 -1
- package/package.json +1 -1
package/dist/outline/outline.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { Icon } from '../icon/index.js';
|
|
5
|
+
import { PopMenuRows, usePopMenu } from '../pop-menu/index.js';
|
|
5
6
|
import { Text } from '../text/index.js';
|
|
7
|
+
// How far a mouse moves before a press becomes a drag, in CSS pixels; how long a finger holds still first, in ms
|
|
8
|
+
// (LayerList's). How far past the first or last sibling a drag still lands, in CSS pixels: half a row.
|
|
9
|
+
const DRAG_AFTER = 4;
|
|
10
|
+
const HOLD = 500;
|
|
11
|
+
const SLACK = 18;
|
|
12
|
+
// How long a move told waits to be drawn before the outline stops waiting for it (to give the focus back, and say it).
|
|
13
|
+
const WAIT_DRAWN = 10_000;
|
|
14
|
+
// How far a finger held still (a long press) moves before it drags instead of opening the row's menu, in CSS pixels:
|
|
15
|
+
// a finger is less still than a mouse (2026-11-22).
|
|
16
|
+
const HELD_SLOP = 8;
|
|
6
17
|
// How long apart two presses on a name may be and still be one double press, in ms: a finger's, which no click count
|
|
7
18
|
// tells of. A mouse's double click says so itself.
|
|
8
19
|
const DOUBLE = 500;
|
|
@@ -27,6 +38,42 @@ function pathTo(items, id) {
|
|
|
27
38
|
}
|
|
28
39
|
return null;
|
|
29
40
|
}
|
|
41
|
+
// The items held with `id` (its own list, in order) and the item that holds them; null when no item has it.
|
|
42
|
+
function siblingsOf(items, id, holder = null) {
|
|
43
|
+
if (items.some((i) => i.id === id))
|
|
44
|
+
return { list: items, holder };
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
const deeper = item.children ? siblingsOf(item.children, id, item.id) : null;
|
|
47
|
+
if (deeper)
|
|
48
|
+
return deeper;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
// Where a row would stand if it went to `gap` among its siblings (0, before the first; the count, after the last),
|
|
53
|
+
// counted with the row still in its place; null where that is its own place.
|
|
54
|
+
function moveTo(list, holder, id, gap) {
|
|
55
|
+
const at = list.findIndex((i) => i.id === id);
|
|
56
|
+
if (at < 0 || gap === at || gap === at + 1 || gap < 0 || gap > list.length)
|
|
57
|
+
return null;
|
|
58
|
+
const others = list.filter((i) => i.id !== id);
|
|
59
|
+
const g = gap > at ? gap - 1 : gap;
|
|
60
|
+
return { holder, after: others[g - 1]?.id ?? null, before: others[g]?.id ?? null };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What a host needs for Move up and Move down (a row's menu): the move one place up and one place down among the row's
|
|
64
|
+
* siblings, each to pass to `onMove`'s handler, or null where the row is first, last, `stays`, or no item has it. The
|
|
65
|
+
* same answer Alt with Up or Down acts on.
|
|
66
|
+
*/
|
|
67
|
+
export function outlineMoves(items, id) {
|
|
68
|
+
const found = siblingsOf(items, id);
|
|
69
|
+
const at = found ? found.list.findIndex((i) => i.id === id) : -1;
|
|
70
|
+
if (!found || at < 0 || found.list[at]?.stays)
|
|
71
|
+
return { up: null, down: null };
|
|
72
|
+
return {
|
|
73
|
+
up: moveTo(found.list, found.holder, id, at - 1),
|
|
74
|
+
down: moveTo(found.list, found.holder, id, at + 2),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
30
77
|
// Whether `id` is somewhere under `item`.
|
|
31
78
|
const under = (item, id) => (item.children ?? []).some((c) => c.id === id || under(c, id));
|
|
32
79
|
// Whether a control in a cell is the Tab key's next stop: only in the row that holds the outline's own stop.
|
|
@@ -38,7 +85,7 @@ const InRow = createContext(false);
|
|
|
38
85
|
* changed in place, and cells at its end under the columns' headings. One row is chosen. The consumer keeps the tree
|
|
39
86
|
* and is told each change. Blueprint components/outline.md; contracts/outline.md.
|
|
40
87
|
*/
|
|
41
|
-
function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, onRename, onFold, className, ...rest }) {
|
|
88
|
+
function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, onRename, onFold, onMove, canHold, menu, className, onPointerMove, onPointerUp, onPointerCancel, ...rest }) {
|
|
42
89
|
const rows = useMemo(() => rowsOf(items), [items]);
|
|
43
90
|
const [renaming, setRenaming] = useState(null);
|
|
44
91
|
// A row that goes while its name is changed (deleted, or folded away from outside) takes its field with it, and
|
|
@@ -50,6 +97,45 @@ function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, o
|
|
|
50
97
|
const root = useRef(null);
|
|
51
98
|
const rowEls = useRef(new Map());
|
|
52
99
|
const pressed = useRef(null);
|
|
100
|
+
// A row being dragged (its id), and where it would land: the move, and the hairline's offset from the outline's
|
|
101
|
+
// top; null where it would stay where it is, or there is no landing. Kept in refs too, for the pointer's handlers.
|
|
102
|
+
const [dragging, setDraggingState] = useState(null);
|
|
103
|
+
const [landing, setLandingState] = useState(null);
|
|
104
|
+
const drag = useRef(null);
|
|
105
|
+
const land = useRef(null);
|
|
106
|
+
const setDragging = (id) => {
|
|
107
|
+
drag.current = id;
|
|
108
|
+
setDraggingState(id);
|
|
109
|
+
};
|
|
110
|
+
const setLanding = (l) => {
|
|
111
|
+
land.current = l;
|
|
112
|
+
setLandingState(l);
|
|
113
|
+
};
|
|
114
|
+
// A press that may become a drag: where it began, by which pointer, and a finger's hold.
|
|
115
|
+
const press = useRef(null);
|
|
116
|
+
// The row a finger holds (a long press, 2026-11-22), and how the page's scroll is let go again.
|
|
117
|
+
const [holding, setHolding] = useState(null);
|
|
118
|
+
const stillOff = useRef(null);
|
|
119
|
+
const unhold = () => {
|
|
120
|
+
stillOff.current?.();
|
|
121
|
+
stillOff.current = null;
|
|
122
|
+
setHolding(null);
|
|
123
|
+
};
|
|
124
|
+
// Whether the last press on a row was a finger's: the platform's own long-press menu (contextmenu) is then not one.
|
|
125
|
+
const lastTouch = useRef(false);
|
|
126
|
+
// The click that follows a drag is not a press: it chooses nothing and is not half a double press.
|
|
127
|
+
const swallow = useRef(false);
|
|
128
|
+
// A move told and not yet drawn: the row, its place then, and whether the focus was in it.
|
|
129
|
+
const pending = useRef(null);
|
|
130
|
+
// What the status beside the treegrid says: the last move drawn.
|
|
131
|
+
const [said, setSaid] = useState('');
|
|
132
|
+
useEffect(() => () => {
|
|
133
|
+
if (press.current?.timer)
|
|
134
|
+
clearTimeout(press.current.timer);
|
|
135
|
+
if (pending.current)
|
|
136
|
+
clearTimeout(pending.current.timer);
|
|
137
|
+
stillOff.current?.();
|
|
138
|
+
}, []);
|
|
53
139
|
// The Tab key's one stop: where the focus last went; else the chosen row, or the row that folds it away; else the
|
|
54
140
|
// first row.
|
|
55
141
|
const tab = useMemo(() => {
|
|
@@ -96,11 +182,39 @@ function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, o
|
|
|
96
182
|
};
|
|
97
183
|
const keys = (i) => (e) => {
|
|
98
184
|
// The row's own keys. A control in one of its cells, and the field its name is changed in, keep theirs.
|
|
99
|
-
if (e.target !== e.currentTarget
|
|
185
|
+
if (e.target !== e.currentTarget)
|
|
100
186
|
return;
|
|
101
187
|
const row = rows[i];
|
|
102
188
|
if (!row)
|
|
103
189
|
return;
|
|
190
|
+
// Alt with Up or Down moves the row one place among its siblings, where the consumer takes moves and the row
|
|
191
|
+
// may move; at the ends it tells nothing, and the keys are still the outline's.
|
|
192
|
+
if (e.altKey &&
|
|
193
|
+
!e.ctrlKey &&
|
|
194
|
+
!e.metaKey &&
|
|
195
|
+
(e.key === 'ArrowUp' || e.key === 'ArrowDown') &&
|
|
196
|
+
onMove &&
|
|
197
|
+
!row.item.stays &&
|
|
198
|
+
row.of > 1 &&
|
|
199
|
+
!drag.current) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
const to = outlineMoves(items, row.item.id)[e.key === 'ArrowUp' ? 'up' : 'down'];
|
|
202
|
+
if (to)
|
|
203
|
+
tell(row.item.id, to);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// Shift+F10 or the menu key opens the row's menu, where there is one (2026-11-22).
|
|
207
|
+
if (menu &&
|
|
208
|
+
!e.altKey &&
|
|
209
|
+
!e.ctrlKey &&
|
|
210
|
+
!e.metaKey &&
|
|
211
|
+
(e.key === 'ContextMenu' || (e.key === 'F10' && e.shiftKey))) {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
openMenu(row.item.id, 'row');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (e.altKey || e.ctrlKey || e.metaKey)
|
|
217
|
+
return;
|
|
104
218
|
const holds = !!row.item.children?.length;
|
|
105
219
|
const go = (to) => {
|
|
106
220
|
const next = rows[Math.max(0, Math.min(rows.length - 1, to))];
|
|
@@ -141,7 +255,7 @@ function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, o
|
|
|
141
255
|
};
|
|
142
256
|
// A double press on a name changes it: a mouse's double click, or a finger's two presses within half a second.
|
|
143
257
|
const namePress = (id) => (e) => {
|
|
144
|
-
if (!onRename || renaming)
|
|
258
|
+
if (!onRename || renaming || swallow.current)
|
|
145
259
|
return;
|
|
146
260
|
const twice = e.detail >= 2 ||
|
|
147
261
|
(pressed.current?.id === id && e.timeStamp - pressed.current.at < DOUBLE);
|
|
@@ -149,14 +263,409 @@ function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, o
|
|
|
149
263
|
if (twice)
|
|
150
264
|
setRenaming(id);
|
|
151
265
|
};
|
|
152
|
-
|
|
266
|
+
// Tells a move, and waits for the row to be drawn in its new place: then the focus goes back to it if it was in
|
|
267
|
+
// it (a browser drops the focus of a node it moves), it is brought into view, and the move is said.
|
|
268
|
+
const tell = (id, to) => {
|
|
269
|
+
const row = rows.find((r) => r.item.id === id);
|
|
270
|
+
if (!row || !onMove)
|
|
271
|
+
return;
|
|
272
|
+
if (pending.current)
|
|
273
|
+
clearTimeout(pending.current.timer);
|
|
274
|
+
const el = rowEls.current.get(id);
|
|
275
|
+
pending.current = {
|
|
276
|
+
id,
|
|
277
|
+
index: row.index,
|
|
278
|
+
holder: row.holder,
|
|
279
|
+
focus: !!el && el.contains(document.activeElement),
|
|
280
|
+
timer: setTimeout(() => {
|
|
281
|
+
pending.current = null;
|
|
282
|
+
}, WAIT_DRAWN),
|
|
283
|
+
};
|
|
284
|
+
onMove(id, to);
|
|
285
|
+
};
|
|
286
|
+
useLayoutEffect(() => {
|
|
287
|
+
const p = pending.current;
|
|
288
|
+
if (!p)
|
|
289
|
+
return;
|
|
290
|
+
const row = rows.find((r) => r.item.id === p.id);
|
|
291
|
+
// Not drawn yet where it was told to go (the consumer waits for a server, or refused): keep waiting.
|
|
292
|
+
if (!row || (row.index === p.index && row.holder === p.holder))
|
|
293
|
+
return;
|
|
294
|
+
clearTimeout(p.timer);
|
|
295
|
+
pending.current = null;
|
|
296
|
+
const el = rowEls.current.get(p.id);
|
|
297
|
+
// Only a focus the move dropped (on the page) or left in the outline comes back: one the person put elsewhere
|
|
298
|
+
// while the consumer waited stays there.
|
|
299
|
+
const at = document.activeElement;
|
|
300
|
+
const free = !at || at === document.body || !!root.current?.contains(at);
|
|
301
|
+
if (p.focus && free && el && at !== el)
|
|
302
|
+
el.focus({ preventScroll: true });
|
|
303
|
+
el?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
|
|
304
|
+
const words = labels.moved?.(row.item.name, row.index + 1, row.of);
|
|
305
|
+
if (words)
|
|
306
|
+
setSaid(words);
|
|
307
|
+
}, [rows, labels]);
|
|
308
|
+
// The landing under a point, for the row `id`: only among its siblings, never inside another holder. Over a
|
|
309
|
+
// sibling's own row, its upper half lands before it and its lower half after it; over the rows a sibling holds,
|
|
310
|
+
// after it. Outside the outline's width, or more than half a row beyond the first or last sibling, none.
|
|
311
|
+
const landingAt = (x, y, id) => {
|
|
312
|
+
const box = root.current?.getBoundingClientRect();
|
|
313
|
+
const at = rows.findIndex((r) => r.item.id === id);
|
|
314
|
+
const row = rows[at];
|
|
315
|
+
const found = siblingsOf(items, id);
|
|
316
|
+
if (!box || !row || !found || x < box.left || x > box.right)
|
|
317
|
+
return null;
|
|
318
|
+
// Into another row: over the middle half of a row that may hold it, not its own holder, not it nor a row it holds.
|
|
319
|
+
if (canHold) {
|
|
320
|
+
let end = at;
|
|
321
|
+
while (rows[end + 1] && rows[end + 1].depth > row.depth)
|
|
322
|
+
end++;
|
|
323
|
+
for (let i = 0; i < rows.length; i++) {
|
|
324
|
+
if (i >= at && i <= end)
|
|
325
|
+
continue;
|
|
326
|
+
const r = rows[i];
|
|
327
|
+
const rect = rowEls.current.get(r.item.id)?.getBoundingClientRect();
|
|
328
|
+
if (!rect || y < rect.top || y > rect.bottom)
|
|
329
|
+
continue;
|
|
330
|
+
const inner = y > rect.top + rect.height / 4 && y < rect.bottom - rect.height / 4;
|
|
331
|
+
if (inner && r.item.id !== row.holder && canHold(r.item.id, id)) {
|
|
332
|
+
const kids = r.item.children ?? [];
|
|
333
|
+
const last = kids.filter((k) => k.id !== id).at(-1)?.id ?? null;
|
|
334
|
+
return { to: { holder: r.item.id, after: last, before: null }, top: rect.top - box.top, into: r.item.id };
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const rect = (i) => rowEls.current.get(rows[i].item.id)?.getBoundingClientRect();
|
|
340
|
+
// Each sibling: where its own row stands, and where the rows it holds end.
|
|
341
|
+
const sibs = [];
|
|
342
|
+
rows.forEach((r, i) => {
|
|
343
|
+
if (r.holder !== row.holder || r.depth !== row.depth)
|
|
344
|
+
return;
|
|
345
|
+
let end = i;
|
|
346
|
+
while (rows[end + 1] && rows[end + 1].depth > r.depth)
|
|
347
|
+
end++;
|
|
348
|
+
const own = rect(i);
|
|
349
|
+
const last = rect(end);
|
|
350
|
+
if (!own || !last)
|
|
351
|
+
return;
|
|
352
|
+
sibs.push({ top: own.top, mid: own.top + own.height / 2, bottom: last.bottom });
|
|
353
|
+
});
|
|
354
|
+
const first = sibs[0];
|
|
355
|
+
const lastSib = sibs[sibs.length - 1];
|
|
356
|
+
if (!first || !lastSib || y < first.top - SLACK || y > lastSib.bottom + SLACK)
|
|
357
|
+
return null;
|
|
358
|
+
const gap = sibs.filter((s) => y > s.mid).length;
|
|
359
|
+
const to = moveTo(found.list, found.holder, id, gap);
|
|
360
|
+
if (!to)
|
|
361
|
+
return null;
|
|
362
|
+
const top = (gap < sibs.length ? sibs[gap].top : lastSib.bottom) - box.top;
|
|
363
|
+
return { to, top };
|
|
364
|
+
};
|
|
365
|
+
// A press on a row may become a drag: a mouse's once it moves 4px, a finger's once it holds still half a second.
|
|
366
|
+
// Never from the fold, a tick or the field a name is changed in.
|
|
367
|
+
// With a menu, a finger held still half a second is held (2026-11-22): lifted, the row's menu opens; moved 8px, it
|
|
368
|
+
// drags where the row may move. Without one, the hold starts the drag at once, as before.
|
|
369
|
+
const down = (row) => (e) => {
|
|
370
|
+
swallow.current = false;
|
|
371
|
+
const touch = e.pointerType === 'touch';
|
|
372
|
+
lastTouch.current = touch;
|
|
373
|
+
const movable = !!onMove && !row.item.stays && (row.of > 1 || !!canHold);
|
|
374
|
+
const holds = touch && !!menu;
|
|
375
|
+
if (e.button !== 0 || renaming !== null || (!movable && !holds))
|
|
376
|
+
return;
|
|
377
|
+
const inside = e.target.closest?.('button, input, textarea, select, a, [contenteditable]');
|
|
378
|
+
if (inside && e.currentTarget.contains(inside))
|
|
379
|
+
return;
|
|
380
|
+
if (press.current?.timer)
|
|
381
|
+
clearTimeout(press.current.timer);
|
|
382
|
+
unhold();
|
|
383
|
+
press.current = { id: row.item.id, x: e.clientX, y: e.clientY, pointer: e.pointerId, touch, movable };
|
|
384
|
+
if (touch) {
|
|
385
|
+
const el = e.currentTarget;
|
|
386
|
+
const pointer = e.pointerId;
|
|
387
|
+
press.current.timer = setTimeout(() => {
|
|
388
|
+
const p = press.current;
|
|
389
|
+
if (!p || p.pointer !== pointer)
|
|
390
|
+
return;
|
|
391
|
+
p.timer = undefined;
|
|
392
|
+
try {
|
|
393
|
+
el.setPointerCapture?.(pointer);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
// The pointer is gone already: the drag still runs on the outline's own handlers.
|
|
397
|
+
}
|
|
398
|
+
if (!menu)
|
|
399
|
+
return setDragging(row.item.id);
|
|
400
|
+
p.held = true;
|
|
401
|
+
setHolding(row.item.id);
|
|
402
|
+
// Held, the page does not scroll under the finger: a move is the row's (a drag), never the page's.
|
|
403
|
+
const still = (ev) => {
|
|
404
|
+
if (ev.cancelable)
|
|
405
|
+
ev.preventDefault();
|
|
406
|
+
};
|
|
407
|
+
document.addEventListener('touchmove', still, { passive: false });
|
|
408
|
+
stillOff.current = () => document.removeEventListener('touchmove', still);
|
|
409
|
+
}, HOLD);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const move = (e) => {
|
|
413
|
+
onPointerMove?.(e);
|
|
414
|
+
const p = press.current;
|
|
415
|
+
if (!p || p.pointer !== e.pointerId)
|
|
416
|
+
return;
|
|
417
|
+
if (drag.current !== p.id) {
|
|
418
|
+
const by = Math.hypot(e.clientX - p.x, e.clientY - p.y);
|
|
419
|
+
const far = by >= DRAG_AFTER;
|
|
420
|
+
if (p.touch && p.held) {
|
|
421
|
+
// Held: a finger that moves on drags the row, where it may move; else the hold ends. Never a menu then.
|
|
422
|
+
// The page stays still under a drag from a hold until the finger is lifted (the drag's own guard comes
|
|
423
|
+
// a render later, and one uncancelled touchmove would let the browser take the pointer).
|
|
424
|
+
if (by < HELD_SLOP)
|
|
425
|
+
return;
|
|
426
|
+
if (!p.movable) {
|
|
427
|
+
unhold();
|
|
428
|
+
press.current = null;
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
p.held = false;
|
|
432
|
+
setHolding(null);
|
|
433
|
+
setDragging(p.id);
|
|
434
|
+
setLanding(landingAt(e.clientX, e.clientY, p.id));
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (p.touch) {
|
|
438
|
+
// A finger that moves before holding still is scrolling the list.
|
|
439
|
+
if (far) {
|
|
440
|
+
clearTimeout(p.timer);
|
|
441
|
+
press.current = null;
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (!far || !p.movable)
|
|
446
|
+
return;
|
|
447
|
+
try {
|
|
448
|
+
rowEls.current.get(p.id)?.setPointerCapture?.(e.pointerId);
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
// As above.
|
|
452
|
+
}
|
|
453
|
+
setDragging(p.id);
|
|
454
|
+
}
|
|
455
|
+
setLanding(landingAt(e.clientX, e.clientY, p.id));
|
|
456
|
+
};
|
|
457
|
+
const end = () => {
|
|
458
|
+
setDragging(null);
|
|
459
|
+
setLanding(null);
|
|
460
|
+
};
|
|
461
|
+
const up = (e) => {
|
|
462
|
+
if (e.type === 'pointerup')
|
|
463
|
+
onPointerUp?.(e);
|
|
464
|
+
else
|
|
465
|
+
onPointerCancel?.(e);
|
|
466
|
+
const p = press.current;
|
|
467
|
+
if (!p || p.pointer !== e.pointerId)
|
|
468
|
+
return;
|
|
469
|
+
if (p.timer)
|
|
470
|
+
clearTimeout(p.timer);
|
|
471
|
+
press.current = null;
|
|
472
|
+
if (p.touch)
|
|
473
|
+
stillOff.current?.();
|
|
474
|
+
stillOff.current = null;
|
|
475
|
+
const id = drag.current;
|
|
476
|
+
if (id === null) {
|
|
477
|
+
// A finger held still and lifted there opens the row's menu; the click after it chooses nothing more. Opened
|
|
478
|
+
// once the finger is up, so the release does not put it away again as a press outside it.
|
|
479
|
+
if (p.held) {
|
|
480
|
+
unhold();
|
|
481
|
+
if (e.type === 'pointerup') {
|
|
482
|
+
swallow.current = true;
|
|
483
|
+
setTimeout(() => openMenu(p.id, 'row'));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const to = land.current;
|
|
489
|
+
end();
|
|
490
|
+
swallow.current = true;
|
|
491
|
+
if (e.type === 'pointerup' && to)
|
|
492
|
+
tell(id, to.to);
|
|
493
|
+
};
|
|
494
|
+
// Escape ends a drag and tells nothing; so does the platform taking the pointer back (pointercancel).
|
|
495
|
+
useEffect(() => {
|
|
496
|
+
if (dragging === null)
|
|
497
|
+
return;
|
|
498
|
+
const esc = (e) => {
|
|
499
|
+
if (e.key !== 'Escape')
|
|
500
|
+
return;
|
|
501
|
+
e.preventDefault();
|
|
502
|
+
e.stopPropagation();
|
|
503
|
+
if (press.current?.timer)
|
|
504
|
+
clearTimeout(press.current.timer);
|
|
505
|
+
press.current = null;
|
|
506
|
+
swallow.current = true;
|
|
507
|
+
unhold();
|
|
508
|
+
end();
|
|
509
|
+
};
|
|
510
|
+
// A finger's drag, once it has begun, does not scroll the page under it.
|
|
511
|
+
const still = (e) => {
|
|
512
|
+
if (e.cancelable)
|
|
513
|
+
e.preventDefault();
|
|
514
|
+
};
|
|
515
|
+
window.addEventListener('keydown', esc, true);
|
|
516
|
+
document.addEventListener('touchmove', still, { passive: false });
|
|
517
|
+
return () => {
|
|
518
|
+
window.removeEventListener('keydown', esc, true);
|
|
519
|
+
document.removeEventListener('touchmove', still);
|
|
520
|
+
};
|
|
521
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
522
|
+
}, [dragging]);
|
|
523
|
+
// ---- A row's ⋯ menu (2026-11-22) ----
|
|
524
|
+
// One menu for every row, standing by the ⋯ of the row it was opened for. `back`: where the focus goes when it
|
|
525
|
+
// closes on a pick or by itself (Escape): its ⋯ when the focus was on it as it opened, else the row.
|
|
526
|
+
const anchor = useRef(null);
|
|
527
|
+
const pop = usePopMenu('below', 'menu', anchor);
|
|
528
|
+
const [menuFor, setMenuFor] = useState(null);
|
|
529
|
+
const menuRef = useRef(null);
|
|
530
|
+
menuRef.current = menuFor;
|
|
531
|
+
// A press on the ⋯ of the row whose menu is open: the browser has already put the menu away; the press opens nothing.
|
|
532
|
+
const pressedOpen = useRef(false);
|
|
533
|
+
const openMenu = (id, back) => {
|
|
534
|
+
if (!menu || drag.current)
|
|
535
|
+
return;
|
|
536
|
+
const el = rowEls.current.get(id);
|
|
537
|
+
if (!el)
|
|
538
|
+
return;
|
|
539
|
+
anchor.current = el.querySelector('.newtone-outline-more') ?? el;
|
|
540
|
+
choose(id);
|
|
541
|
+
setMenuFor({ id, back });
|
|
542
|
+
pop.show();
|
|
543
|
+
};
|
|
544
|
+
// The focus back where the menu was opened from: the ⋯ or the row; the row gone, the outline's Tab stop.
|
|
545
|
+
const giveBack = (f) => {
|
|
546
|
+
const el = rowEls.current.get(f.id);
|
|
547
|
+
const to = el && f.back === 'more'
|
|
548
|
+
? (el.querySelector('.newtone-outline-more') ?? el)
|
|
549
|
+
: (el ?? root.current?.querySelector('.newtone-outline-row[tabindex="0"]'));
|
|
550
|
+
to?.focus({ preventScroll: true });
|
|
551
|
+
};
|
|
552
|
+
const wasOpen = useRef(false);
|
|
553
|
+
useEffect(() => {
|
|
554
|
+
if (pop.open) {
|
|
555
|
+
wasOpen.current = true;
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (!wasOpen.current)
|
|
559
|
+
return;
|
|
560
|
+
wasOpen.current = false;
|
|
561
|
+
const f = menuRef.current;
|
|
562
|
+
setMenuFor(null);
|
|
563
|
+
if (!f)
|
|
564
|
+
return;
|
|
565
|
+
// Closed by itself (Escape, a press outside): after the browser's own restore, a focus dropped on the page goes
|
|
566
|
+
// back; one a press outside put somewhere stays there.
|
|
567
|
+
setTimeout(() => {
|
|
568
|
+
const at = document.activeElement;
|
|
569
|
+
if (at && at !== document.body)
|
|
570
|
+
return;
|
|
571
|
+
giveBack(f);
|
|
572
|
+
});
|
|
573
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
574
|
+
}, [pop.open]);
|
|
575
|
+
// The row going (deleted, folded away) while its menu is open closes it.
|
|
576
|
+
useEffect(() => {
|
|
577
|
+
if (pop.open && menuFor && !rows.some((r) => r.item.id === menuFor.id))
|
|
578
|
+
pop.done(() => { });
|
|
579
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
580
|
+
}, [rows]);
|
|
581
|
+
const menuItems = menu && menuFor && pop.open
|
|
582
|
+
? menu.items(menuFor.id).map((i) => i.move
|
|
583
|
+
? { ...i, disabled: i.disabled || !onMove || !outlineMoves(items, menuFor.id)[i.move] }
|
|
584
|
+
: i)
|
|
585
|
+
: [];
|
|
586
|
+
const picked = (action) => {
|
|
587
|
+
const f = menuFor;
|
|
588
|
+
const item = menuItems.find((i) => i.id === action);
|
|
589
|
+
if (!f || !item || !menu)
|
|
590
|
+
return;
|
|
591
|
+
pop.done(() => {
|
|
592
|
+
giveBack(f);
|
|
593
|
+
if (item.move) {
|
|
594
|
+
const to = outlineMoves(items, f.id)[item.move];
|
|
595
|
+
if (to)
|
|
596
|
+
tell(f.id, to);
|
|
597
|
+
}
|
|
598
|
+
else
|
|
599
|
+
menu.onPick(f.id, action);
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
const menuName = (id) => {
|
|
603
|
+
const row = id === undefined ? undefined : rows.find((r) => r.item.id === id);
|
|
604
|
+
return row && menu ? menu.label(row.item.name) : undefined;
|
|
605
|
+
};
|
|
606
|
+
// A secondary press on a row opens its menu, once the button is let go (opened on the press, as macOS does, the
|
|
607
|
+
// release would put it away again). One that follows a finger's press is the platform's long press: the outline's
|
|
608
|
+
// own hold answers that. The menu key's, after its keydown opened it, does nothing more.
|
|
609
|
+
const context = (row) => (e) => {
|
|
610
|
+
if (!menu)
|
|
611
|
+
return;
|
|
612
|
+
if (e.target.closest?.('input, textarea, [contenteditable]'))
|
|
613
|
+
return;
|
|
614
|
+
e.preventDefault();
|
|
615
|
+
if (lastTouch.current || (pop.open && menuRef.current?.id === row.item.id))
|
|
616
|
+
return;
|
|
617
|
+
const id = row.item.id;
|
|
618
|
+
if (e.buttons)
|
|
619
|
+
window.addEventListener('pointerup', () => setTimeout(() => openMenu(id, 'row')), {
|
|
620
|
+
once: true,
|
|
621
|
+
capture: true,
|
|
622
|
+
});
|
|
623
|
+
else
|
|
624
|
+
openMenu(id, 'row');
|
|
625
|
+
};
|
|
626
|
+
// The rows that move with the dragged one: it, and every drawn row under it.
|
|
627
|
+
const moving = new Set();
|
|
628
|
+
if (dragging !== null) {
|
|
629
|
+
const d = rows.findIndex((r) => r.item.id === dragging);
|
|
630
|
+
const top = rows[d];
|
|
631
|
+
if (top) {
|
|
632
|
+
moving.add(top.item.id);
|
|
633
|
+
for (let k = d + 1; rows[k] && rows[k].depth > top.depth; k++)
|
|
634
|
+
moving.add(rows[k].item.id);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const draggedDepth = dragging === null ? 0 : (rows.find((r) => r.item.id === dragging)?.depth ?? 0);
|
|
638
|
+
const grid = (_jsxs("div", { ref: root, className: ['newtone-outline', className].filter(Boolean).join(' '), role: "treegrid", "aria-label": label, "data-dragging": dragging !== null ? '' : undefined, ...rest, onPointerMove: move, onPointerUp: up, onPointerCancel: up, children: [columns.length ? (_jsxs("div", { className: "newtone-outline-head", role: "row", children: [_jsx("div", { className: "newtone-outline-heading", role: "columnheader", "data-lead": "", children: _jsx(Text, { as: "span", scale: "caption", weight: "medium", tone: "secondary", lines: 1, children: labels.name }) }), columns.map((c) => (_jsx("div", { className: "newtone-outline-heading", role: "columnheader", "data-align": c.align, "data-wide-only": c.wideOnly ? '' : undefined, style: c.width
|
|
153
639
|
? { '--_outline-width': c.width }
|
|
154
|
-
: undefined, children: _jsx(Text, { as: "span", scale: "caption", weight: "medium", tone: "secondary", lines: 1, children: c.label }) }, c.id)))] })) : null, rows.map((row, i) => (_jsx(OutlineRow, { row: row, columns: columns, labels: labels, chosen: row.item.id === chosen, tab: row.item.id === tab, renaming: renaming === row.item.id, at: (el) => {
|
|
640
|
+
: undefined, children: _jsx(Text, { as: "span", scale: "caption", weight: "medium", tone: "secondary", lines: 1, children: c.label }) }, c.id))), menu ? _jsx("div", { className: "newtone-outline-more-cell", "aria-hidden": "true" }) : null] })) : null, rows.map((row, i) => (_jsx(OutlineRow, { row: row, columns: columns, labels: labels, chosen: row.item.id === chosen, tab: row.item.id === tab, renaming: renaming === row.item.id, at: (el) => {
|
|
155
641
|
if (el)
|
|
156
642
|
rowEls.current.set(row.item.id, el);
|
|
157
643
|
else
|
|
158
644
|
rowEls.current.delete(row.item.id);
|
|
159
|
-
},
|
|
645
|
+
}, movable: !!onMove && !row.item.stays && row.of > 1, moving: moving.has(row.item.id), landing: landing?.into === row.item.id, held: holding === row.item.id, more: menu
|
|
646
|
+
? {
|
|
647
|
+
label: menu.label(row.item.name),
|
|
648
|
+
open: pop.open && menuFor?.id === row.item.id,
|
|
649
|
+
controls: pop.menu.id,
|
|
650
|
+
onDown: () => {
|
|
651
|
+
pressedOpen.current = pop.open && menuRef.current?.id === row.item.id;
|
|
652
|
+
},
|
|
653
|
+
onPress: (focused) => {
|
|
654
|
+
if (pressedOpen.current) {
|
|
655
|
+
pressedOpen.current = false;
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
openMenu(row.item.id, focused ? 'more' : 'row');
|
|
659
|
+
},
|
|
660
|
+
}
|
|
661
|
+
: undefined, onContext: context(row), onDown: down(row), onPress: () => {
|
|
662
|
+
// The click that follows a drag chooses nothing.
|
|
663
|
+
if (swallow.current) {
|
|
664
|
+
swallow.current = false;
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
choose(row.item.id);
|
|
668
|
+
}, onNamePress: namePress(row.item.id), onKeys: keys(i), onHeld: () => setHeld((h) => h?.id === row.item.id && h.chosen === chosen
|
|
160
669
|
? h
|
|
161
670
|
: { id: row.item.id, chosen }), onFold: () => fold(row), onRenamed: (name, back) => {
|
|
162
671
|
setRenaming(null);
|
|
@@ -166,9 +675,17 @@ function OutlineRoot({ label, labels, items, columns = NONE, chosen, onChoose, o
|
|
|
166
675
|
// Enter and Escape hand the focus back to the row; a focus that left by itself stays where it went.
|
|
167
676
|
if (back)
|
|
168
677
|
rowEls.current.get(row.item.id)?.focus();
|
|
169
|
-
}, onLost: lost }, row.item.id)))
|
|
678
|
+
}, onLost: lost }, row.item.id))), landing && !landing.into ? (_jsx("div", { className: "newtone-outline-drop", "aria-hidden": "true", style: {
|
|
679
|
+
insetBlockStart: `${landing.top}px`,
|
|
680
|
+
'--_outline-depth': draggedDepth,
|
|
681
|
+
} })) : null] }));
|
|
682
|
+
// Where rows move, the move is said by a polite status beside the treegrid (a treegrid holds rows only), there
|
|
683
|
+
// from the start so the first move is heard. The rows' menu stands beside it too, in the top layer.
|
|
684
|
+
return onMove || menu ? (_jsxs(_Fragment, { children: [grid, onMove ? (_jsx("div", { role: "status", className: "newtone-outline-said", children: said })) : null, menu ? (_jsx("div", { ...pop.menu, "aria-label": menuName(menuFor?.id),
|
|
685
|
+
// The menu key's own contextmenu lands in the menu it just opened: never the platform's over it.
|
|
686
|
+
onContextMenu: (e) => e.preventDefault(), children: menuItems.length ? _jsx(PopMenuRows, { items: menuItems, onPick: picked }) : null })) : null] })) : (grid);
|
|
170
687
|
}
|
|
171
|
-
function OutlineRow({ row, columns, labels, chosen, tab, renaming, at, onPress, onNamePress, onKeys, onHeld, onFold, onRenamed, onLost, }) {
|
|
688
|
+
function OutlineRow({ row, columns, labels, chosen, tab, renaming, movable, moving, landing, held, more, onContext, at, onDown, onPress, onNamePress, onKeys, onHeld, onFold, onRenamed, onLost, }) {
|
|
172
689
|
const { item } = row;
|
|
173
690
|
const holds = !!item.children?.length;
|
|
174
691
|
const el = useRef(null);
|
|
@@ -184,19 +701,29 @@ function OutlineRow({ row, columns, labels, chosen, tab, renaming, at, onPress,
|
|
|
184
701
|
return (_jsxs("div", { ref: (node) => {
|
|
185
702
|
el.current = node;
|
|
186
703
|
at(node);
|
|
187
|
-
}, className: "newtone-outline-row", role: "row", "aria-level": row.depth + 1, "aria-posinset": row.index + 1, "aria-setsize": row.of, "aria-expanded": holds ? !item.folded : undefined, "aria-selected": chosen, tabIndex: tab ? 0 : -1, "
|
|
704
|
+
}, className: "newtone-outline-row", role: "row", "aria-level": row.depth + 1, "aria-posinset": row.index + 1, "aria-setsize": row.of, "aria-expanded": holds ? !item.folded : undefined, "aria-selected": chosen, tabIndex: tab ? 0 : -1, "aria-keyshortcuts": [movable ? 'Alt+ArrowUp Alt+ArrowDown' : '', more ? 'Shift+F10' : '']
|
|
705
|
+
.filter(Boolean)
|
|
706
|
+
.join(' ') || undefined, "data-chosen": chosen ? '' : undefined, "data-moving": moving ? '' : undefined, "data-landing": landing ? '' : undefined, "data-held": held ? '' : undefined, "data-menu": more?.open ? '' : undefined, style: { '--_outline-depth': row.depth }, onContextMenu: onContext, onPointerDown: onDown, onClick: onPress, onKeyDown: onKeys, onFocus: onHeld, children: [_jsxs("div", { className: "newtone-outline-lead", role: "rowheader", onClick: onNamePress, children: [holds ? (_jsx("button", { type: "button", className: "newtone-outline-fold", "aria-label": item.folded ? labels.unfold : labels.fold, title: item.folded ? labels.unfold : labels.fold, tabIndex: -1, "data-folded": item.folded ? '' : undefined,
|
|
188
707
|
// A pointer's press never puts the focus on the fold, which some browsers would and some
|
|
189
708
|
// not: the focus stays where it was on every one, so a focused row's keys go on working.
|
|
190
709
|
onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
|
|
191
710
|
// Its own press: it neither chooses the row nor counts toward a double press on the name.
|
|
192
711
|
e.stopPropagation();
|
|
193
712
|
onFold();
|
|
194
|
-
}, children: _jsx(Icon, { name: "expand_more", size: "sm" }) })) : (_jsx("span", { className: "newtone-outline-indent", "aria-hidden": "true" })), _jsx(Icon, { name: item.icon, size: "sm", className: "newtone-outline-glyph" }), renaming ? (_jsx(Rename, { name: item.name, label: labels.rename, onDone: onRenamed })) : (_jsx(Text, { as: "span", scale: "body-sm", lines: 1, measure: "none", className: "newtone-outline-name", children: item.name }))] }), _jsx(TabStop.Provider, { value: tab, children: _jsx(InRow.Provider, { value: true, children: columns.map((c) => {
|
|
713
|
+
}, children: _jsx(Icon, { name: "expand_more", size: "sm" }) })) : (_jsx("span", { className: "newtone-outline-indent", "aria-hidden": "true" })), _jsx(Icon, { name: item.icon, size: "sm", className: "newtone-outline-glyph" }), renaming ? (_jsx(Rename, { name: item.name, label: labels.rename, onDone: onRenamed })) : (_jsx(Text, { as: "span", scale: "body-sm", lines: 1, measure: "none", className: "newtone-outline-name", children: item.name })), item.mark ? (_jsx("span", { className: "newtone-outline-mark", role: "img", "aria-label": item.mark.label, title: item.mark.label, children: _jsx(Icon, { name: item.mark.icon, size: "sm" }) })) : null] }), _jsx(TabStop.Provider, { value: tab, children: _jsx(InRow.Provider, { value: true, children: columns.map((c) => {
|
|
195
714
|
const cell = item.cells?.[c.id];
|
|
196
715
|
return (_jsx("div", { className: "newtone-outline-cell", role: "gridcell", "data-align": c.align, "data-wide-only": c.wideOnly ? '' : undefined, style: c.width
|
|
197
716
|
? { '--_outline-width': c.width }
|
|
198
717
|
: undefined, children: typeof cell === 'string' || typeof cell === 'number' ? (_jsx(Text, { as: "span", scale: "body-sm", figures: "tabular", lines: 1, measure: "none", className: "newtone-outline-words", children: cell })) : (cell) }, c.id));
|
|
199
|
-
}) }) })
|
|
718
|
+
}) }) }), more ? (_jsx("div", { className: "newtone-outline-more-cell", role: "gridcell", children: _jsx("button", { type: "button", className: "newtone-outline-more", "aria-haspopup": "menu", "aria-expanded": more.open, "aria-controls": more.controls, "aria-label": more.label, title: more.label,
|
|
719
|
+
// A Tab stop only in the row that holds the outline's, after its tick.
|
|
720
|
+
tabIndex: tab ? 0 : -1,
|
|
721
|
+
// A pointer's press never puts the focus on it (as the tick's): the focus stays where it was.
|
|
722
|
+
onMouseDown: (e) => e.preventDefault(), onPointerDown: more.onDown, onClick: (e) => {
|
|
723
|
+
// Its own press: the row is chosen by the menu opening, once.
|
|
724
|
+
e.stopPropagation();
|
|
725
|
+
more.onPress(document.activeElement === e.currentTarget);
|
|
726
|
+
}, children: _jsx(Icon, { name: "more_horiz", size: "sm" }) }) })) : null] }));
|
|
200
727
|
}
|
|
201
728
|
// A name being changed in place: Enter keeps it and Escape drops it (null), the focus going back to the row; leaving
|
|
202
729
|
// the field keeps it, and the focus stays where it went.
|
|
@@ -242,5 +769,5 @@ function OutlineTick({ label, checked, onChange, disabled, className, onClick, o
|
|
|
242
769
|
onChange?.(!checked);
|
|
243
770
|
}, children: _jsx("span", { className: "newtone-outline-tick-box", children: _jsx("svg", { className: "newtone-outline-tick-mark", viewBox: "0 0 20 20", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M5.5 10.5l3 3 6-7" }) }) }) }));
|
|
244
771
|
}
|
|
245
|
-
export const Outline = Object.assign(OutlineRoot, { Tick: OutlineTick });
|
|
772
|
+
export const Outline = Object.assign(OutlineRoot, { Tick: OutlineTick, moves: outlineMoves });
|
|
246
773
|
//# sourceMappingURL=outline.js.map
|