@vokril/ui-solid 0.19.0 → 0.20.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 +14 -0
- package/README.md +38 -2
- package/dist/createResizableSidebar-A0F4JmSU.js +472 -0
- package/dist/createResizableSidebar-DwCuRuho.cjs +1 -0
- package/dist/createVirtualWindow-9T5ZJCQR.cjs +1 -0
- package/dist/createVirtualWindow-Dqm5jxZa.js +117 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +108 -104
- package/dist/layout/createVirtualScroller.d.cts +8 -31
- package/dist/layout/createVirtualScroller.d.ts +8 -31
- package/dist/layout/createVirtualWindow.d.cts +64 -0
- package/dist/layout/createVirtualWindow.d.ts +64 -0
- package/dist/layout/index.cjs +1 -1
- package/dist/layout/index.d.cts +2 -0
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +7 -6
- package/dist/layout/virtualScrollerUtils.d.cts +58 -22
- package/dist/layout/virtualScrollerUtils.d.ts +58 -22
- package/dist/rowSource-BnUQ-LKT.cjs +1 -0
- package/dist/rowSource-CLEYuC95.js +1236 -0
- package/dist/server/createResizableSidebar-CZ0IGNm8.js +310 -0
- package/dist/server/createResizableSidebar-DDniLGSD.cjs +1 -0
- package/dist/server/createVirtualWindow-9T5ZJCQR.cjs +1 -0
- package/dist/server/createVirtualWindow-Dqm5jxZa.js +117 -0
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +110 -106
- package/dist/server/layout/index.cjs +1 -1
- package/dist/server/layout/index.js +7 -6
- package/dist/server/rowSource-CdvoDIN7.cjs +1 -0
- package/dist/server/rowSource-D7lSI6LT.js +1122 -0
- package/dist/server/tree/index.cjs +1 -1
- package/dist/server/tree/index.js +11 -8
- package/dist/solid/layout/createVirtualScroller.js +17 -100
- package/dist/solid/layout/createVirtualWindow.js +129 -0
- package/dist/solid/layout/index.js +1 -0
- package/dist/solid/layout/virtualScrollerUtils.js +31 -32
- package/dist/solid/tree/TreeSurface.jsx +20 -13
- package/dist/solid/tree/createTreeController.js +110 -62
- package/dist/solid/tree/createTreeSurface.js +29 -12
- package/dist/solid/tree/index.js +1 -0
- package/dist/solid/tree/rowSource.js +93 -0
- package/dist/solid/tree/selectAllInScope.js +31 -25
- package/dist/solid/tree/stickyScroll.js +12 -10
- package/dist/solid/tree/treeAria.js +11 -30
- package/dist/solid/tree/treeKeymap.js +2 -24
- package/dist/solid/tree/viewportAnchor.js +23 -0
- package/dist/style.css +1 -1
- package/dist/tree/TreeStickyHeader.d.cts +1 -1
- package/dist/tree/TreeStickyHeader.d.ts +1 -1
- package/dist/tree/TreeSurface.d.cts +1 -1
- package/dist/tree/TreeSurface.d.ts +1 -1
- package/dist/tree/createTreeController.d.cts +19 -8
- package/dist/tree/createTreeController.d.ts +19 -8
- package/dist/tree/createTreeSurface.d.cts +8 -3
- package/dist/tree/createTreeSurface.d.ts +8 -3
- package/dist/tree/descriptor.d.cts +8 -9
- package/dist/tree/descriptor.d.ts +8 -9
- package/dist/tree/index.cjs +1 -1
- package/dist/tree/index.d.cts +1 -0
- package/dist/tree/index.d.ts +1 -0
- package/dist/tree/index.js +11 -8
- package/dist/tree/rowSource.d.cts +41 -0
- package/dist/tree/rowSource.d.ts +41 -0
- package/dist/tree/selectAllInScope.d.cts +20 -2
- package/dist/tree/selectAllInScope.d.ts +20 -2
- package/dist/tree/stickyScroll.d.cts +32 -5
- package/dist/tree/stickyScroll.d.ts +32 -5
- package/dist/tree/treeAria.d.cts +26 -10
- package/dist/tree/treeAria.d.ts +26 -10
- package/dist/tree/treeKeymap.d.cts +2 -16
- package/dist/tree/treeKeymap.d.ts +2 -16
- package/dist/tree/viewportAnchor.d.cts +21 -0
- package/dist/tree/viewportAnchor.d.ts +21 -0
- package/dist/ui.css +1 -1
- package/package.json +1 -1
- package/dist/createResizableSidebar-Dau7TIuH.cjs +0 -1
- package/dist/createResizableSidebar-gvf9me4K.js +0 -449
- package/dist/createVirtualScroller-CL49JE2P.cjs +0 -1
- package/dist/createVirtualScroller-vu-l4rVv.js +0 -93
- package/dist/descriptor-CaHgh9N_.cjs +0 -1
- package/dist/descriptor-eGtcBtpI.js +0 -1106
- package/dist/server/createResizableSidebar-BQG5elmd.js +0 -287
- package/dist/server/createResizableSidebar-tU8FO2MK.cjs +0 -1
- package/dist/server/createVirtualScroller-CL49JE2P.cjs +0 -1
- package/dist/server/createVirtualScroller-vu-l4rVv.js +0 -93
- package/dist/server/descriptor-CEGvvJZh.cjs +0 -1
- package/dist/server/descriptor-GLoKPx6x.js +0 -992
|
@@ -1,18 +1,61 @@
|
|
|
1
|
-
import { createMemo, createSignal, onCleanup } from 'solid-js';
|
|
1
|
+
import { createEffect, createMemo, createSignal, onCleanup, } from 'solid-js';
|
|
2
2
|
import { DEFAULT_TREE_CAPABILITIES, } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import { findTypeAheadIndex, resolveTreeIntent } from './treeKeymap';
|
|
4
4
|
import { selectAllInScope } from './selectAllInScope';
|
|
5
5
|
import { isKey } from '../_internal/base/keys';
|
|
6
6
|
export const TYPE_AHEAD_RESET_MS = 1000;
|
|
7
|
+
function positionAt(rows, index) {
|
|
8
|
+
const ancestors = [];
|
|
9
|
+
for (let parent = rows.parentIndex(index); parent !== -1; parent = rows.parentIndex(parent))
|
|
10
|
+
ancestors.push(rows.at(parent).key);
|
|
11
|
+
return { key: rows.at(index).key, ancestors, index };
|
|
12
|
+
}
|
|
13
|
+
function resolvePosition(rows, position) {
|
|
14
|
+
if (position === null || rows.length === 0)
|
|
15
|
+
return -1;
|
|
16
|
+
if (position.index < rows.length &&
|
|
17
|
+
rows.at(position.index).key === position.key)
|
|
18
|
+
return position.index;
|
|
19
|
+
const own = rows.indexOfKey(position.key);
|
|
20
|
+
if (own >= 0)
|
|
21
|
+
return own;
|
|
22
|
+
for (const key of position.ancestors) {
|
|
23
|
+
const ancestor = rows.indexOfKey(key);
|
|
24
|
+
if (ancestor >= 0)
|
|
25
|
+
return ancestor;
|
|
26
|
+
}
|
|
27
|
+
return Math.min(position.index, rows.length - 1);
|
|
28
|
+
}
|
|
7
29
|
export function createTreeController(options) {
|
|
8
30
|
const caps = () => ({
|
|
9
31
|
...DEFAULT_TREE_CAPABILITIES,
|
|
10
32
|
...options.capabilities,
|
|
11
33
|
expandAll: false,
|
|
12
34
|
});
|
|
13
|
-
const [
|
|
35
|
+
const [cursor, setCursor] = createSignal(null);
|
|
14
36
|
const [selectedKeys, setSelectedKeys] = createSignal(new Set());
|
|
15
|
-
const [
|
|
37
|
+
const [anchor, setAnchor] = createSignal(null);
|
|
38
|
+
const cursorIndex = createMemo(() => resolvePosition(options.rows(), cursor()));
|
|
39
|
+
const anchorIndex = () => resolvePosition(options.rows(), anchor());
|
|
40
|
+
const cursorKey = createMemo(() => {
|
|
41
|
+
const index = cursorIndex();
|
|
42
|
+
return index < 0 ? null : options.rows().at(index).key;
|
|
43
|
+
});
|
|
44
|
+
createEffect(() => {
|
|
45
|
+
const position = cursor();
|
|
46
|
+
const index = cursorIndex();
|
|
47
|
+
if (position === null || index < 0)
|
|
48
|
+
return;
|
|
49
|
+
const rows = options.rows();
|
|
50
|
+
const key = rows.at(index).key;
|
|
51
|
+
if (key === position.key) {
|
|
52
|
+
if (index !== position.index)
|
|
53
|
+
setCursor(positionAt(rows, index));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (position.ancestors.includes(key))
|
|
57
|
+
setCursor(positionAt(rows, index));
|
|
58
|
+
});
|
|
16
59
|
const [typeAheadQuery, setTypeAheadQuery] = createSignal('');
|
|
17
60
|
let lastTypeAheadAt = 0;
|
|
18
61
|
let typeAheadResetTimer;
|
|
@@ -41,24 +84,39 @@ export function createTreeController(options) {
|
|
|
41
84
|
typeAheadResetTimer = undefined;
|
|
42
85
|
}
|
|
43
86
|
});
|
|
44
|
-
const
|
|
87
|
+
const rowAt = (index) => {
|
|
88
|
+
const rows = options.rows();
|
|
89
|
+
return index >= 0 && index < rows.length ? rows.at(index) : undefined;
|
|
90
|
+
};
|
|
91
|
+
const placeCursor = (index, moveAnchor) => {
|
|
92
|
+
const position = positionAt(options.rows(), index);
|
|
93
|
+
setCursor(position);
|
|
94
|
+
if (moveAnchor)
|
|
95
|
+
setAnchor(position);
|
|
96
|
+
options.onScrollToIndex?.(index);
|
|
97
|
+
};
|
|
45
98
|
const focusIndex = (index) => {
|
|
46
99
|
const rows = options.rows();
|
|
47
100
|
if (index < 0 || index >= rows.length || index === cursorIndex())
|
|
48
101
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
102
|
+
placeCursor(index, true);
|
|
103
|
+
};
|
|
104
|
+
const focusKey = (key) => {
|
|
105
|
+
const index = options.rows().indexOfKey(key);
|
|
106
|
+
if (index < 0)
|
|
107
|
+
return;
|
|
108
|
+
if (index === cursorIndex())
|
|
109
|
+
options.onScrollToIndex?.(index);
|
|
110
|
+
else
|
|
111
|
+
focusIndex(index);
|
|
52
112
|
};
|
|
53
113
|
const rangeKeys = (from, to) => {
|
|
54
114
|
const rows = options.rows();
|
|
55
|
-
const anchorKind =
|
|
115
|
+
const anchorKind = rowAt(from)?.kind;
|
|
56
116
|
const [lo, hi] = from <= to ? [from, to] : [to, from];
|
|
57
117
|
const keys = new Set();
|
|
58
|
-
for (let i = lo; i <= hi; i++) {
|
|
59
|
-
const row = rows
|
|
60
|
-
if (!row)
|
|
61
|
-
continue;
|
|
118
|
+
for (let i = Math.max(lo, 0); i <= Math.min(hi, rows.length - 1); i++) {
|
|
119
|
+
const row = rows.at(i);
|
|
62
120
|
if (row.selectable === false)
|
|
63
121
|
continue;
|
|
64
122
|
if (anchorKind !== undefined && row.kind !== anchorKind)
|
|
@@ -69,8 +127,7 @@ export function createTreeController(options) {
|
|
|
69
127
|
};
|
|
70
128
|
const selectIndex = (index, modifier) => {
|
|
71
129
|
clearTypeAhead();
|
|
72
|
-
const
|
|
73
|
-
const row = rows[index];
|
|
130
|
+
const row = rowAt(index);
|
|
74
131
|
if (!row)
|
|
75
132
|
return;
|
|
76
133
|
if (row.selectable === false && modifier !== 'range') {
|
|
@@ -84,82 +141,72 @@ export function createTreeController(options) {
|
|
|
84
141
|
else
|
|
85
142
|
next.add(row.key);
|
|
86
143
|
setSelectedKeys(next);
|
|
87
|
-
|
|
88
|
-
setAnchorIndex(index);
|
|
89
|
-
options.onScrollToIndex?.(index);
|
|
144
|
+
placeCursor(index, true);
|
|
90
145
|
return;
|
|
91
146
|
}
|
|
92
147
|
if (modifier === 'range' && caps().canMultiSelect) {
|
|
93
|
-
const
|
|
94
|
-
setSelectedKeys(rangeKeys(
|
|
95
|
-
|
|
96
|
-
options.onScrollToIndex?.(index);
|
|
148
|
+
const anchorAt = anchorIndex();
|
|
149
|
+
setSelectedKeys(rangeKeys(anchorAt >= 0 ? anchorAt : index, index));
|
|
150
|
+
placeCursor(index, false);
|
|
97
151
|
return;
|
|
98
152
|
}
|
|
99
153
|
setSelectedKeys(new Set([row.key]));
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
154
|
+
placeCursor(index, true);
|
|
155
|
+
};
|
|
156
|
+
const selectKey = (key, modifier) => {
|
|
157
|
+
const index = options.rows().indexOfKey(key);
|
|
158
|
+
if (index >= 0)
|
|
159
|
+
selectIndex(index, modifier);
|
|
103
160
|
};
|
|
104
161
|
const clearSelection = () => {
|
|
105
162
|
clearTypeAhead();
|
|
106
163
|
if (selectedKeys().size > 0)
|
|
107
164
|
setSelectedKeys(new Set());
|
|
108
165
|
};
|
|
109
|
-
const
|
|
166
|
+
const forEachDirectChild = (index, visit) => {
|
|
110
167
|
const rows = options.rows();
|
|
111
|
-
const parent =
|
|
168
|
+
const parent = rowAt(index);
|
|
112
169
|
if (!parent)
|
|
113
170
|
return;
|
|
114
171
|
const childDepth = parent.depth + 1;
|
|
172
|
+
const end = rows.subtreeEnd(index);
|
|
173
|
+
for (let i = index + 1; i <= end; i = rows.subtreeEnd(i) + 1) {
|
|
174
|
+
const row = rows.at(i);
|
|
175
|
+
if (row.depth === childDepth)
|
|
176
|
+
visit(row, i);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const selectChildren = (index) => {
|
|
115
180
|
const keys = new Set();
|
|
116
181
|
let anchorKind;
|
|
117
182
|
let seen = false;
|
|
118
183
|
let firstChild = -1;
|
|
119
|
-
|
|
120
|
-
const row = rows[i];
|
|
121
|
-
if (row.depth <= parent.depth)
|
|
122
|
-
break;
|
|
123
|
-
if (row.depth !== childDepth)
|
|
124
|
-
continue;
|
|
184
|
+
forEachDirectChild(index, (row, childIndex) => {
|
|
125
185
|
if (row.selectable === false)
|
|
126
|
-
|
|
186
|
+
return;
|
|
127
187
|
if (!seen) {
|
|
128
188
|
anchorKind = row.kind;
|
|
129
|
-
firstChild =
|
|
189
|
+
firstChild = childIndex;
|
|
130
190
|
seen = true;
|
|
131
191
|
}
|
|
132
192
|
else if (anchorKind !== undefined && row.kind !== anchorKind)
|
|
133
|
-
|
|
193
|
+
return;
|
|
134
194
|
keys.add(row.key);
|
|
135
|
-
}
|
|
195
|
+
});
|
|
136
196
|
if (keys.size === 0)
|
|
137
197
|
return;
|
|
138
198
|
setSelectedKeys(keys);
|
|
139
|
-
if (firstChild >= 0)
|
|
140
|
-
|
|
141
|
-
setAnchorIndex(firstChild);
|
|
142
|
-
options.onScrollToIndex?.(firstChild);
|
|
143
|
-
}
|
|
199
|
+
if (firstChild >= 0)
|
|
200
|
+
placeCursor(firstChild, true);
|
|
144
201
|
};
|
|
145
202
|
const childKindsHomogeneous = (index) => {
|
|
146
|
-
const rows = options.rows();
|
|
147
|
-
const parent = rows[index];
|
|
148
|
-
if (!parent)
|
|
149
|
-
return { homogeneous: false, total: 0, selectable: 0 };
|
|
150
|
-
const childDepth = parent.depth + 1;
|
|
151
203
|
let anchorKind;
|
|
152
204
|
let seen = false;
|
|
153
205
|
let total = 0;
|
|
154
206
|
let selectable = 0;
|
|
155
|
-
|
|
156
|
-
const row = rows[i];
|
|
157
|
-
if (row.depth <= parent.depth)
|
|
158
|
-
break;
|
|
159
|
-
if (row.depth !== childDepth)
|
|
160
|
-
continue;
|
|
207
|
+
forEachDirectChild(index, (row) => {
|
|
161
208
|
if (row.selectable === false)
|
|
162
|
-
|
|
209
|
+
return;
|
|
163
210
|
total++;
|
|
164
211
|
if (!seen) {
|
|
165
212
|
anchorKind = row.kind;
|
|
@@ -168,7 +215,7 @@ export function createTreeController(options) {
|
|
|
168
215
|
}
|
|
169
216
|
else if (anchorKind === undefined || row.kind === anchorKind)
|
|
170
217
|
selectable++;
|
|
171
|
-
}
|
|
218
|
+
});
|
|
172
219
|
return {
|
|
173
220
|
homogeneous: total > 0 && total === selectable,
|
|
174
221
|
total,
|
|
@@ -181,7 +228,7 @@ export function createTreeController(options) {
|
|
|
181
228
|
setSelectedKeys(new Set(selectAllInScope(options.rows(), cursorIndex(), selectedKeys())));
|
|
182
229
|
};
|
|
183
230
|
const openMenuAt = (index, point) => {
|
|
184
|
-
const row =
|
|
231
|
+
const row = rowAt(index);
|
|
185
232
|
if (row)
|
|
186
233
|
options.onOpenMenu?.(row, point);
|
|
187
234
|
};
|
|
@@ -201,7 +248,7 @@ export function createTreeController(options) {
|
|
|
201
248
|
});
|
|
202
249
|
if (!intent)
|
|
203
250
|
return;
|
|
204
|
-
const current =
|
|
251
|
+
const current = rowAt(index);
|
|
205
252
|
switch (intent.type) {
|
|
206
253
|
case 'move':
|
|
207
254
|
event.preventDefault();
|
|
@@ -209,10 +256,9 @@ export function createTreeController(options) {
|
|
|
209
256
|
return;
|
|
210
257
|
case 'extend': {
|
|
211
258
|
event.preventDefault();
|
|
212
|
-
const
|
|
213
|
-
setSelectedKeys(rangeKeys(
|
|
214
|
-
|
|
215
|
-
options.onScrollToIndex?.(intent.to);
|
|
259
|
+
const anchorAt = anchorIndex();
|
|
260
|
+
setSelectedKeys(rangeKeys(anchorAt >= 0 ? anchorAt : index, intent.to));
|
|
261
|
+
placeCursor(intent.to, false);
|
|
216
262
|
return;
|
|
217
263
|
}
|
|
218
264
|
case 'expandOrDescend':
|
|
@@ -233,7 +279,7 @@ export function createTreeController(options) {
|
|
|
233
279
|
options.onToggle?.(current);
|
|
234
280
|
return;
|
|
235
281
|
}
|
|
236
|
-
const parent =
|
|
282
|
+
const parent = rows.parentIndex(index);
|
|
237
283
|
if (parent >= 0)
|
|
238
284
|
focusIndex(parent);
|
|
239
285
|
return;
|
|
@@ -302,7 +348,9 @@ export function createTreeController(options) {
|
|
|
302
348
|
return caps();
|
|
303
349
|
},
|
|
304
350
|
focusIndex,
|
|
351
|
+
focusKey,
|
|
305
352
|
selectIndex,
|
|
353
|
+
selectKey,
|
|
306
354
|
clearSelection,
|
|
307
355
|
selectChildren,
|
|
308
356
|
selectAll,
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { createMemo, useContext } from 'solid-js';
|
|
2
|
-
import {
|
|
1
|
+
import { createEffect, createMemo, on, untrack, useContext } from 'solid-js';
|
|
2
|
+
import { createVirtualWindow, } from '../layout/createVirtualWindow';
|
|
3
3
|
import { DesktopContextMenuContext } from '../context/DesktopContextMenuContext';
|
|
4
4
|
import { createTreeController, } from './createTreeController';
|
|
5
5
|
import { computeStickyTreeState, stickyInsetForIndex, } from './stickyScroll';
|
|
6
|
+
import { anchoredContentTop, viewportAnchorAt, } from './viewportAnchor';
|
|
6
7
|
import { BugIndicatingError } from '../_internal/base/errors/bugIndicatingError';
|
|
7
8
|
const DEFAULT_OVERSCAN = 8;
|
|
8
9
|
const DEFAULT_STICKY_MAX_COUNT = 7;
|
|
9
10
|
const EMPTY_STICKY_STATE = { rows: [], height: 0 };
|
|
10
11
|
export function createTreeSurface(descriptor) {
|
|
11
12
|
const menu = useContext(DesktopContextMenuContext);
|
|
12
|
-
const
|
|
13
|
-
const scroller =
|
|
14
|
-
|
|
13
|
+
const source = createMemo(() => descriptor.rows());
|
|
14
|
+
const scroller = createVirtualWindow({
|
|
15
|
+
count: () => source().length,
|
|
15
16
|
itemHeight: descriptor.rowHeight,
|
|
16
17
|
overscan: descriptor.overscan ?? DEFAULT_OVERSCAN,
|
|
17
18
|
});
|
|
@@ -19,7 +20,7 @@ export function createTreeSurface(descriptor) {
|
|
|
19
20
|
if (descriptor.stickyScroll !== true)
|
|
20
21
|
return EMPTY_STICKY_STATE;
|
|
21
22
|
return computeStickyTreeState({
|
|
22
|
-
rows:
|
|
23
|
+
rows: source(),
|
|
23
24
|
scrollTop: scroller.scrollTop(),
|
|
24
25
|
rowHeight: descriptor.rowHeight,
|
|
25
26
|
viewportHeight: scroller.viewportHeight(),
|
|
@@ -27,10 +28,10 @@ export function createTreeSurface(descriptor) {
|
|
|
27
28
|
});
|
|
28
29
|
});
|
|
29
30
|
const stickyInsetFor = (index) => descriptor.stickyScroll === true
|
|
30
|
-
? stickyInsetForIndex(
|
|
31
|
+
? stickyInsetForIndex(source(), index, descriptor.rowHeight, descriptor.stickyScrollMaxCount ?? DEFAULT_STICKY_MAX_COUNT)
|
|
31
32
|
: 0;
|
|
32
33
|
const controller = createTreeController({
|
|
33
|
-
rows,
|
|
34
|
+
rows: source,
|
|
34
35
|
...(descriptor.capabilities
|
|
35
36
|
? { capabilities: descriptor.capabilities }
|
|
36
37
|
: {}),
|
|
@@ -43,9 +44,24 @@ export function createTreeSurface(descriptor) {
|
|
|
43
44
|
onDestroy: (row) => descriptor.onDestroy?.(row),
|
|
44
45
|
onScrollToIndex: (index) => scroller.scrollToIndex(index, 'auto', stickyInsetFor(index)),
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
+
const cursorRow = () => {
|
|
48
|
+
const index = controller.cursorIndex();
|
|
49
|
+
return index < 0 ? undefined : source().at(index);
|
|
50
|
+
};
|
|
51
|
+
let viewportAnchor = null;
|
|
52
|
+
createEffect(() => {
|
|
53
|
+
const contentTop = scroller.scrollTop();
|
|
54
|
+
viewportAnchor = viewportAnchorAt(untrack(source), contentTop, descriptor.rowHeight);
|
|
55
|
+
});
|
|
56
|
+
createEffect(on(source, (rows) => {
|
|
57
|
+
const target = anchoredContentTop(rows, viewportAnchor, scroller.readScrollTop(), descriptor.rowHeight);
|
|
58
|
+
if (target !== null)
|
|
59
|
+
scroller.scrollToContentTop(target);
|
|
60
|
+
viewportAnchor = viewportAnchorAt(rows, scroller.readScrollTop(), descriptor.rowHeight);
|
|
61
|
+
}, { defer: true }));
|
|
62
|
+
function openMenu(row, point, origin) {
|
|
47
63
|
if (descriptor.openMenu) {
|
|
48
|
-
descriptor.openMenu(row, point,
|
|
64
|
+
descriptor.openMenu(row, point, origin);
|
|
49
65
|
return;
|
|
50
66
|
}
|
|
51
67
|
if (!descriptor.buildMenu)
|
|
@@ -56,13 +72,14 @@ export function createTreeSurface(descriptor) {
|
|
|
56
72
|
if (!menu) {
|
|
57
73
|
throw new BugIndicatingError('createTreeSurface: descriptor builds a context menu but no DesktopContextMenuProvider is mounted');
|
|
58
74
|
}
|
|
59
|
-
menu.open(point.x, point.y, items,
|
|
75
|
+
menu.open(point.x, point.y, items, origin);
|
|
60
76
|
}
|
|
61
77
|
return {
|
|
62
78
|
descriptor,
|
|
63
79
|
controller,
|
|
64
80
|
scroller,
|
|
65
|
-
|
|
81
|
+
source,
|
|
82
|
+
cursorRow,
|
|
66
83
|
stickyState,
|
|
67
84
|
stickyInsetFor,
|
|
68
85
|
openMenu,
|
package/dist/solid/tree/index.js
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BugIndicatingError } from '../_internal/base/errors/bugIndicatingError';
|
|
2
|
+
export function assertRowIndex(source, index) {
|
|
3
|
+
if (!Number.isInteger(index) || index < 0 || index >= source.length) {
|
|
4
|
+
throw new BugIndicatingError(`tree row source: index ${index} is outside 0..${source.length - 1}`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function structureTables(rows) {
|
|
8
|
+
const length = rows.length;
|
|
9
|
+
const parent = new Int32Array(length);
|
|
10
|
+
const subtreeEnd = new Int32Array(length);
|
|
11
|
+
const posInSet = new Int32Array(length);
|
|
12
|
+
const group = new Int32Array(length);
|
|
13
|
+
const groupSizes = [];
|
|
14
|
+
const stack = [];
|
|
15
|
+
const openGroupDepth = [];
|
|
16
|
+
const openGroupId = [];
|
|
17
|
+
let rootGroupDepth = -1;
|
|
18
|
+
let rootGroupId = -1;
|
|
19
|
+
for (let index = 0; index < length; index++) {
|
|
20
|
+
const depth = rows[index].depth;
|
|
21
|
+
while (stack.length > 0 && rows[stack[stack.length - 1]].depth >= depth) {
|
|
22
|
+
subtreeEnd[stack.pop()] = index - 1;
|
|
23
|
+
openGroupDepth.pop();
|
|
24
|
+
openGroupId.pop();
|
|
25
|
+
}
|
|
26
|
+
const slot = stack.length - 1;
|
|
27
|
+
parent[index] = slot < 0 ? -1 : stack[slot];
|
|
28
|
+
const currentDepth = slot < 0 ? rootGroupDepth : openGroupDepth[slot];
|
|
29
|
+
let id = slot < 0 ? rootGroupId : openGroupId[slot];
|
|
30
|
+
if (currentDepth !== depth) {
|
|
31
|
+
id = groupSizes.length;
|
|
32
|
+
groupSizes.push(0);
|
|
33
|
+
if (slot < 0) {
|
|
34
|
+
rootGroupDepth = depth;
|
|
35
|
+
rootGroupId = id;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
openGroupDepth[slot] = depth;
|
|
39
|
+
openGroupId[slot] = id;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
groupSizes[id] = groupSizes[id] + 1;
|
|
43
|
+
group[index] = id;
|
|
44
|
+
posInSet[index] = groupSizes[id];
|
|
45
|
+
stack.push(index);
|
|
46
|
+
openGroupDepth.push(-1);
|
|
47
|
+
openGroupId.push(-1);
|
|
48
|
+
}
|
|
49
|
+
for (const open of stack)
|
|
50
|
+
subtreeEnd[open] = length - 1;
|
|
51
|
+
return { parent, subtreeEnd, posInSet, group, groupSizes };
|
|
52
|
+
}
|
|
53
|
+
function keyIndex(rows) {
|
|
54
|
+
const index = new Map();
|
|
55
|
+
for (let row = 0; row < rows.length; row++) {
|
|
56
|
+
const key = rows[row].key;
|
|
57
|
+
const seen = index.get(key);
|
|
58
|
+
if (seen !== undefined) {
|
|
59
|
+
throw new BugIndicatingError(`tree row source: key "${key}" occurs at rows ${seen} and ${row}`);
|
|
60
|
+
}
|
|
61
|
+
index.set(key, row);
|
|
62
|
+
}
|
|
63
|
+
return index;
|
|
64
|
+
}
|
|
65
|
+
export function treeRowsFrom(input) {
|
|
66
|
+
const rows = input.slice();
|
|
67
|
+
const tables = structureTables(rows);
|
|
68
|
+
const keys = keyIndex(rows);
|
|
69
|
+
const source = {
|
|
70
|
+
length: rows.length,
|
|
71
|
+
at: (index) => {
|
|
72
|
+
assertRowIndex(source, index);
|
|
73
|
+
return rows[index];
|
|
74
|
+
},
|
|
75
|
+
parentIndex: (index) => {
|
|
76
|
+
assertRowIndex(source, index);
|
|
77
|
+
return tables.parent[index];
|
|
78
|
+
},
|
|
79
|
+
subtreeEnd: (index) => {
|
|
80
|
+
assertRowIndex(source, index);
|
|
81
|
+
return tables.subtreeEnd[index];
|
|
82
|
+
},
|
|
83
|
+
siblingPosition: (index) => {
|
|
84
|
+
assertRowIndex(source, index);
|
|
85
|
+
return {
|
|
86
|
+
posInSet: tables.posInSet[index],
|
|
87
|
+
setSize: tables.groupSizes[tables.group[index]],
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
indexOfKey: (key) => keys.get(key) ?? -1,
|
|
91
|
+
};
|
|
92
|
+
return source;
|
|
93
|
+
}
|
|
@@ -1,47 +1,53 @@
|
|
|
1
|
-
import { findChildRange, findParentIndex } from './treeKeymap';
|
|
2
1
|
export function selectAllInScope(rows, cursor, selection) {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const start = startIndex(rows, cursor, selected, indexByKey);
|
|
2
|
+
const selected = [...selection].filter((key) => rows.indexOfKey(key) >= 0);
|
|
3
|
+
const start = startIndex(rows, cursor, selected);
|
|
6
4
|
const kind = lockKind(rows, start);
|
|
7
5
|
const pickable = (row) => row.selectable !== false && (kind === undefined || row.kind === kind);
|
|
8
6
|
const selectedSet = new Set(selected);
|
|
9
|
-
let scope = start < 0 ? -1 :
|
|
7
|
+
let scope = start < 0 ? -1 : rows.parentIndex(start);
|
|
10
8
|
for (;;) {
|
|
11
|
-
const picked =
|
|
12
|
-
.filter(pickable)
|
|
13
|
-
.map((row) => row.key);
|
|
9
|
+
const picked = pickedUnder(rows, scope, pickable);
|
|
14
10
|
if (scope < 0)
|
|
15
11
|
return picked;
|
|
16
12
|
const covered = picked.length === selectedSet.size &&
|
|
17
13
|
picked.every((key) => selectedSet.has(key));
|
|
18
14
|
if (picked.length > 0 && !covered)
|
|
19
15
|
return picked;
|
|
20
|
-
const scopeRow = rows
|
|
16
|
+
const scopeRow = rows.at(scope);
|
|
21
17
|
if (picked.length > 0 && pickable(scopeRow))
|
|
22
18
|
return [scopeRow.key, ...picked];
|
|
23
|
-
scope =
|
|
19
|
+
scope = rows.parentIndex(scope);
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
function startIndex(rows, cursor, selected
|
|
27
|
-
const cursorKey = rows
|
|
22
|
+
function startIndex(rows, cursor, selected) {
|
|
23
|
+
const cursorKey = cursor >= 0 && cursor < rows.length ? rows.at(cursor).key : undefined;
|
|
28
24
|
if (cursorKey !== undefined && !selected.includes(cursorKey))
|
|
29
25
|
return cursor;
|
|
30
26
|
const first = selected[0];
|
|
31
|
-
return first === undefined ? -1 :
|
|
27
|
+
return first === undefined ? -1 : rows.indexOfKey(first);
|
|
32
28
|
}
|
|
33
29
|
function lockKind(rows, start) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
if (start >= 0) {
|
|
31
|
+
const own = rows.at(start);
|
|
32
|
+
if (own.selectable !== false)
|
|
33
|
+
return own.kind;
|
|
34
|
+
}
|
|
35
|
+
const from = Math.max(start, 0);
|
|
36
|
+
for (let step = 0; step < rows.length; step++) {
|
|
37
|
+
const row = rows.at((from + step) % rows.length);
|
|
38
|
+
if (row.selectable !== false)
|
|
39
|
+
return row.kind;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
43
|
+
function pickedUnder(rows, scope, pickable) {
|
|
44
|
+
const first = scope < 0 ? 0 : scope + 1;
|
|
45
|
+
const last = scope < 0 ? rows.length - 1 : rows.subtreeEnd(scope);
|
|
46
|
+
const picked = [];
|
|
47
|
+
for (let index = first; index <= last; index++) {
|
|
48
|
+
const row = rows.at(index);
|
|
49
|
+
if (pickable(row))
|
|
50
|
+
picked.push(row.key);
|
|
51
|
+
}
|
|
52
|
+
return picked;
|
|
47
53
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { findChildRange, findParentIndex } from './treeKeymap';
|
|
2
1
|
const MAX_WIDGET_VIEW_RATIO = 0.4;
|
|
3
2
|
const EMPTY_STATE = { rows: [], height: 0 };
|
|
4
3
|
function clampMaxCount(maxCount) {
|
|
@@ -6,12 +5,12 @@ function clampMaxCount(maxCount) {
|
|
|
6
5
|
}
|
|
7
6
|
function ancestorUnderPrevious(rows, index, prevIndex) {
|
|
8
7
|
let cur = index;
|
|
9
|
-
let parent =
|
|
8
|
+
let parent = rows.parentIndex(cur);
|
|
10
9
|
while (parent !== -1) {
|
|
11
10
|
if (parent === prevIndex)
|
|
12
11
|
return cur;
|
|
13
12
|
cur = parent;
|
|
14
|
-
parent =
|
|
13
|
+
parent = rows.parentIndex(cur);
|
|
15
14
|
}
|
|
16
15
|
return prevIndex === -1 ? cur : -1;
|
|
17
16
|
}
|
|
@@ -44,18 +43,18 @@ export function computeStickyTreeState(params) {
|
|
|
44
43
|
const i = ancestorUnderPrevious(rows, underIndex, prevIndex);
|
|
45
44
|
if (i === -1)
|
|
46
45
|
break;
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
46
|
+
const end = rows.subtreeEnd(i);
|
|
47
|
+
if (end === i)
|
|
49
48
|
break;
|
|
50
49
|
if (i === underIndex && scrollTop === i * rowHeight - height)
|
|
51
50
|
break;
|
|
52
|
-
const bottomOfLastChild = (
|
|
51
|
+
const bottomOfLastChild = (end + 1) * rowHeight - scrollTop;
|
|
53
52
|
const desiredTop = height;
|
|
54
53
|
const top = desiredTop + rowHeight > bottomOfLastChild &&
|
|
55
54
|
desiredTop <= bottomOfLastChild
|
|
56
55
|
? bottomOfLastChild - rowHeight
|
|
57
56
|
: desiredTop;
|
|
58
|
-
sticky.push({ index: i, row: rows
|
|
57
|
+
sticky.push({ index: i, row: rows.at(i), top });
|
|
59
58
|
height = top + rowHeight;
|
|
60
59
|
prevIndex = i;
|
|
61
60
|
if (sticky.length >= maxCount)
|
|
@@ -66,11 +65,14 @@ export function computeStickyTreeState(params) {
|
|
|
66
65
|
export function stickyInsetForIndex(rows, index, rowHeight, maxCount) {
|
|
67
66
|
if (index < 0 || index >= rows.length)
|
|
68
67
|
return 0;
|
|
68
|
+
const limit = clampMaxCount(maxCount);
|
|
69
69
|
let ancestors = 0;
|
|
70
|
-
let cur =
|
|
70
|
+
let cur = rows.parentIndex(index);
|
|
71
71
|
while (cur !== -1) {
|
|
72
72
|
ancestors++;
|
|
73
|
-
|
|
73
|
+
if (ancestors === limit)
|
|
74
|
+
break;
|
|
75
|
+
cur = rows.parentIndex(cur);
|
|
74
76
|
}
|
|
75
|
-
return
|
|
77
|
+
return ancestors * rowHeight;
|
|
76
78
|
}
|
|
@@ -13,44 +13,25 @@ export function buildTreeContainerAria(params) {
|
|
|
13
13
|
: undefined,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
export function
|
|
17
|
-
const { treeId, rows, index
|
|
18
|
-
const row = rows
|
|
16
|
+
export function buildTreeRowStructureAria(params) {
|
|
17
|
+
const { treeId, rows, index } = params;
|
|
18
|
+
const row = rows.at(index);
|
|
19
19
|
const flat = params.flat === true;
|
|
20
|
-
|
|
21
|
-
for (let i = index - 1; i >= 0; i--) {
|
|
22
|
-
const depth = rows[i].depth;
|
|
23
|
-
if (depth < row.depth)
|
|
24
|
-
break;
|
|
25
|
-
if (depth === row.depth)
|
|
26
|
-
start = i;
|
|
27
|
-
}
|
|
28
|
-
let end = index;
|
|
29
|
-
for (let i = index + 1; i < rows.length; i++) {
|
|
30
|
-
const depth = rows[i].depth;
|
|
31
|
-
if (depth < row.depth)
|
|
32
|
-
break;
|
|
33
|
-
if (depth === row.depth)
|
|
34
|
-
end = i;
|
|
35
|
-
}
|
|
36
|
-
let setSize = 0;
|
|
37
|
-
let posInSet = 0;
|
|
38
|
-
for (let i = start; i <= end; i++) {
|
|
39
|
-
if (rows[i].depth !== row.depth)
|
|
40
|
-
continue;
|
|
41
|
-
setSize++;
|
|
42
|
-
if (i <= index)
|
|
43
|
-
posInSet++;
|
|
44
|
-
}
|
|
20
|
+
const { posInSet, setSize } = rows.siblingPosition(index);
|
|
45
21
|
return {
|
|
46
22
|
role: flat ? 'option' : 'treeitem',
|
|
47
23
|
id: treeRowDomId(treeId, row.key),
|
|
48
|
-
tabIndex: focusMode === 'roving-tabindex' && isCursor ? 0 : -1,
|
|
49
24
|
'aria-level': flat ? undefined : row.depth + 1,
|
|
50
25
|
'aria-setsize': setSize,
|
|
51
26
|
'aria-posinset': posInSet,
|
|
52
|
-
'aria-selected': isSelected,
|
|
53
27
|
'aria-expanded': !flat && row.expandable ? row.expanded : undefined,
|
|
54
28
|
'aria-busy': row.busy === true ? true : undefined,
|
|
55
29
|
};
|
|
56
30
|
}
|
|
31
|
+
export function buildTreeRowAria(params) {
|
|
32
|
+
return {
|
|
33
|
+
...params.structure,
|
|
34
|
+
tabIndex: params.focusMode === 'roving-tabindex' && params.isCursor ? 0 : -1,
|
|
35
|
+
'aria-selected': params.isSelected,
|
|
36
|
+
};
|
|
37
|
+
}
|