@gramlot/gramlot 0.3.36 → 0.3.37
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/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +9 -9
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +0 -30
- package/dist/components/drawing/__init__.py +1 -1
- package/dist/components/drawing/assets/collection.js +3 -3
- package/dist/components/drawing/assets/index.js +1 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +6 -6
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +0 -2
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +8 -8
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +2 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +9 -9
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +2 -2
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +6 -6
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +0 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +3 -3
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +0 -3
- package/dist/gramlot.js +1205 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/standard-collections.js +1 -1
- package/package.json +2 -3
- package/src/binding/data-binder.js +11 -3
- package/src/binding/grid-struct.js +7 -4
- package/src/binding/runtime.js +203 -46
- package/src/builder/binding.json +23 -1
- package/src/builder/gramlot-builder.d.ts +1 -4
- package/src/builder/source.js +185 -29
- package/src/chat.js +26 -20
- package/src/components/attachment-manager.js +38 -34
- package/src/components/chart-data-view.js +4 -7
- package/src/components/chart-fields.js +18 -6
- package/src/components/chart-renderer.js +10 -3
- package/src/components/chart-timeline.js +7 -5
- package/src/components/charts.js +74 -67
- package/src/components/check-box-text-editor.js +3 -3
- package/src/components/check-box-text.js +7 -22
- package/src/components/check-box-tree.js +20 -16
- package/src/components/choice-editor.js +1 -1
- package/src/components/drawing.js +47 -34
- package/src/components/grid-cell-editor.js +72 -29
- package/src/components/grid-column-filters.js +47 -40
- package/src/components/grid-formulas.js +22 -17
- package/src/components/grid-header-interaction.js +9 -11
- package/src/components/grid-row-interaction.js +25 -24
- package/src/components/grid-row-layout.js +28 -29
- package/src/components/grid-search-box.js +3 -3
- package/src/components/grid-search.js +3 -8
- package/src/components/grid-selection.js +33 -29
- package/src/components/grid-structure.js +48 -10
- package/src/components/grid-tools.js +14 -14
- package/src/components/grid.js +83 -79
- package/src/components/image-crop-dialog.js +2 -2
- package/src/components/image-crop.js +16 -9
- package/src/components/image-uploader.js +21 -28
- package/src/components/inputs.js +19 -1
- package/src/components/registry.js +3 -5
- package/src/components/tray-pane.js +85 -61
- package/src/components/tree.js +332 -239
- package/src/components/upload-engine.js +10 -2
- package/src/components/uploader.js +31 -27
- package/src/editing-session.d.ts +4 -1
- package/src/editing-session.js +120 -83
- package/src/experiments/window-selection.js +4 -6
- package/src/filesystem.js +2 -2
- package/src/gramlot.js +1 -0
- package/src/handlers/device-handler.js +219 -213
- package/src/handlers/rpc-handler.d.ts +17 -0
- package/src/handlers/rpc-handler.js +22 -0
- package/src/ide-documents.js +29 -11
- package/src/ide-runtime.js +33 -31
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +67 -48
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +6 -1
- package/src/renderer/gramlot-renderer.js +21 -2
- package/src/source-picker.d.ts +2 -2
- package/src/source-picker.js +15 -6
- package/src/stores/bag-collection-store.js +25 -7
- package/src/stores/bag-collection-view.js +23 -22
- package/src/view/controls.js +1 -1
- package/src/view/html.js +40 -20
- package/src/visual-editor-canvas.js +1 -1
- package/src/visual-editor.js +18 -19
- package/tools/gramlot-tools-inspector.js +400 -374
- package/tools/inspector-agent.js +223 -49
- package/dist/components/vizabi/__init__.py +0 -13
- package/dist/components/vizabi/assets/collection.js +0 -4
- package/dist/components/vizabi/assets/index.js +0 -3
- package/dist/components/vizabi/commands.json +0 -7
- package/dist/components/vizabi/grammar.json +0 -128
- package/src/components/vizabi-session.js +0 -66
- package/src/components/vizabi.js +0 -66
package/src/components/tree.js
CHANGED
|
@@ -16,9 +16,16 @@ export const RowActions = defineComponent({
|
|
|
16
16
|
#context;
|
|
17
17
|
connectedCallback() { this.slot = 'row-actions'; this.hidden = true; }
|
|
18
18
|
setSourceContext(context) { this.#context = context; }
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/** Keep the row's tree `path`; `read` gives the row's item at each use, or null when the row is gone. */
|
|
20
|
+
setRowContext(path, read) { this.#rowContext = {path, read}; this.#refresh(); }
|
|
21
|
+
getRowContext() {
|
|
22
|
+
if (!this.#rowContext) return null;
|
|
23
|
+
const {path, read} = this.#rowContext, item = read();
|
|
24
|
+
return item ? {item, path} : null;
|
|
25
|
+
}
|
|
21
26
|
clearRowContext() { this.#rowContext = null; this.hidden = true; }
|
|
27
|
+
// `state` is a `^` parameter of dtype 'X': a change inside the Bag or a replacement at its address
|
|
28
|
+
// projects the bar again, and actionState receives the value read at that address for the call.
|
|
22
29
|
projectAttributes(attrs, adapt) {
|
|
23
30
|
const rest = super.projectAttributes(attrs, adapt);
|
|
24
31
|
if (!['start', 'end'].includes(this.parameters.position)) throw new TypeError('rowActions position must be start or end');
|
|
@@ -26,12 +33,13 @@ export const RowActions = defineComponent({
|
|
|
26
33
|
return rest;
|
|
27
34
|
}
|
|
28
35
|
#refresh() {
|
|
29
|
-
|
|
36
|
+
const context = this.getRowContext();
|
|
37
|
+
if (!context || !this.parameters.actionState) return;
|
|
30
38
|
for (const action of this.children) {
|
|
31
39
|
const code = action.getAttribute('rowAction');
|
|
32
40
|
if (code === null) continue;
|
|
33
41
|
const presentation = this.#context.callLogic(this.parameters.actionState,
|
|
34
|
-
{...
|
|
42
|
+
{...context, action: code, state: this.#context.getStaticData(this.#context.attrDatapath('state'))});
|
|
35
43
|
if (!presentation || typeof presentation.hidden !== 'boolean' ||
|
|
36
44
|
typeof presentation.icon !== 'string' || typeof presentation.title !== 'string') {
|
|
37
45
|
throw new TypeError('rowActions actionState must return hidden, icon and title');
|
|
@@ -43,7 +51,7 @@ export const RowActions = defineComponent({
|
|
|
43
51
|
});
|
|
44
52
|
|
|
45
53
|
export const Tree = defineComponent({
|
|
46
|
-
name: 'tree', tag: 'gramlot-tree', base: Container, subTags: 'rowActions[:1]', sourceContext: true,
|
|
54
|
+
name: 'tree', tag: 'gramlot-tree', base: Container, subTags: 'rowActions[:1]', sourceContext: true, dragSource: true,
|
|
47
55
|
parameters: {
|
|
48
56
|
storepath: {dtype: 'T'},
|
|
49
57
|
draggable: {dtype: 'B', default: false, binding: 'read'},
|
|
@@ -71,7 +79,6 @@ export const Tree = defineComponent({
|
|
|
71
79
|
checkChildren: {dtype: 'B', default: true, binding: 'read'}
|
|
72
80
|
},
|
|
73
81
|
implementation: Base => class extends Base {
|
|
74
|
-
#store;
|
|
75
82
|
#sanitizer;
|
|
76
83
|
#context;
|
|
77
84
|
#expanded = new Set();
|
|
@@ -84,11 +91,19 @@ export const Tree = defineComponent({
|
|
|
84
91
|
#selectionVersion = 0;
|
|
85
92
|
#selectedPath = null;
|
|
86
93
|
#scheduled = false;
|
|
87
|
-
#checkedPaths;
|
|
88
94
|
#checksEnabled = false;
|
|
89
95
|
#pathsEnabled = false;
|
|
90
|
-
|
|
91
|
-
#
|
|
96
|
+
// `checked_<attribute>` addresses, legacy syntax `path[:joiner]`, by attribute name.
|
|
97
|
+
#checkedAttributes = new Map();
|
|
98
|
+
// The check lists as last read or written by the tree, by list name; null before the first draw.
|
|
99
|
+
#seenLists = null;
|
|
100
|
+
// The path list of a tree without checkedPaths, kept like the expansion.
|
|
101
|
+
#ownCheckedPaths = null;
|
|
102
|
+
// The loaded branches whose loaded children are all checked (with checkChildren), derived like
|
|
103
|
+
// the other lists: a child added or reloaded under one of them is checked, as in the legacy.
|
|
104
|
+
#checkedBranches = null;
|
|
105
|
+
// Expansion, loading, errors and resolutions are kept by tree path (row keys from
|
|
106
|
+
// the store root), never by BagNode.
|
|
92
107
|
#loading = new Set();
|
|
93
108
|
#errors = new Map();
|
|
94
109
|
#searchInput = '';
|
|
@@ -97,8 +112,8 @@ export const Tree = defineComponent({
|
|
|
97
112
|
#searchTimer = null;
|
|
98
113
|
#searchVersion = 0;
|
|
99
114
|
#searchOpen = new Set();
|
|
100
|
-
#searchClosed = new
|
|
101
|
-
#searchAttempted = new
|
|
115
|
+
#searchClosed = new Set();
|
|
116
|
+
#searchAttempted = new Set();
|
|
102
117
|
#searching = false;
|
|
103
118
|
#resolutions = new Map();
|
|
104
119
|
|
|
@@ -150,13 +165,16 @@ export const Tree = defineComponent({
|
|
|
150
165
|
});
|
|
151
166
|
}
|
|
152
167
|
setSourceContext(context) { this.#context = context; }
|
|
153
|
-
|
|
168
|
+
/** The store Bag, read from the tree's address at each use; the tree never keeps it. */
|
|
169
|
+
get storeBag() { return this.#context.treeStore(); }
|
|
154
170
|
/** Read only the rendered row and its BagNode; never request a resolver value. */
|
|
155
171
|
getDragContext(event) {
|
|
156
172
|
for (const element of event.composedPath()) {
|
|
157
173
|
const row = this.#dragRows.get(element);
|
|
158
174
|
if (!row) continue;
|
|
159
|
-
const {
|
|
175
|
+
const {path, caption, favorite} = row;
|
|
176
|
+
const item = this.#rowItem(path, favorite);
|
|
177
|
+
if (!item) return null;
|
|
160
178
|
const rect = element.getBoundingClientRect();
|
|
161
179
|
const fraction = rect.height ? (event.clientY - rect.top) / rect.height : 0.5;
|
|
162
180
|
const placement = fraction < 0.25 ? 'before' : fraction > 0.75 ? 'after' : 'inside';
|
|
@@ -168,28 +186,25 @@ export const Tree = defineComponent({
|
|
|
168
186
|
}
|
|
169
187
|
return null;
|
|
170
188
|
}
|
|
171
|
-
setStoreBag(bag) {
|
|
172
|
-
if (!(bag instanceof Bag)) throw new TypeError('tree storepath must resolve to a Bag');
|
|
173
|
-
if (bag !== this.#store) {
|
|
174
|
-
this.#store = bag;
|
|
175
|
-
this.#resetSearch();
|
|
176
|
-
this.#searchText = this.#searchInput.toLowerCase();
|
|
177
|
-
this.#expanded.clear();
|
|
178
|
-
this.#errors.clear();
|
|
179
|
-
this.#requestedPath = undefined;
|
|
180
|
-
this.#selectionVersion++;
|
|
181
|
-
this.#checkedPaths = undefined;
|
|
182
|
-
this.#checkedBags = new WeakMap();
|
|
183
|
-
this.#checkedNodes = new WeakSet();
|
|
184
|
-
}
|
|
185
|
-
this.#schedule();
|
|
186
|
-
}
|
|
187
189
|
projectAttributes(attrs, adapt) {
|
|
190
|
+
const own = {};
|
|
191
|
+
this.#checkedAttributes = new Map();
|
|
192
|
+
for (const [name, raw] of Object.entries(attrs)) {
|
|
193
|
+
if (!name.startsWith('checked_')) { own[name] = raw; continue; }
|
|
194
|
+
// Legacy genro_tree.js updateCheckedAttr: a Data path, the joiner after ':'.
|
|
195
|
+
const attribute = name.slice('checked_'.length);
|
|
196
|
+
if (!attribute || typeof raw !== 'string' || !raw || /^[\^=]/.test(raw)) {
|
|
197
|
+
throw new TypeError(`tree ${name} requires a Data path, optionally followed by :joiner`);
|
|
198
|
+
}
|
|
199
|
+
const index = raw.indexOf(':');
|
|
200
|
+
this.#checkedAttributes.set(name, {attribute, path: index < 0 ? raw : raw.slice(0, index),
|
|
201
|
+
joiner: (index < 0 ? '' : raw.slice(index + 1)) || ','});
|
|
202
|
+
}
|
|
188
203
|
this.#pathsEnabled = Object.hasOwn(attrs, 'checkedPaths');
|
|
189
|
-
this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked);
|
|
204
|
+
this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked) || this.#checkedAttributes.size > 0;
|
|
190
205
|
const previousEager = this.parameters?.searchEager;
|
|
191
206
|
const previousResolve = this.parameters?.resolveLazy;
|
|
192
|
-
const rest = super.projectAttributes(
|
|
207
|
+
const rest = super.projectAttributes(own, adapt);
|
|
193
208
|
if (previousEager !== this.parameters.searchEager || previousResolve !== this.parameters.resolveLazy) {
|
|
194
209
|
this.#resetSearch();
|
|
195
210
|
this.#searchText = this.#searchInput.toLowerCase();
|
|
@@ -219,32 +234,33 @@ export const Tree = defineComponent({
|
|
|
219
234
|
#resetSearch() {
|
|
220
235
|
clearTimeout(this.#searchTimer); this.#searchTimer = null;
|
|
221
236
|
this.#searchVersion++; this.#searching = false;
|
|
222
|
-
this.#searchAttempted
|
|
237
|
+
this.#searchAttempted.clear(); this.#searchOpen.clear(); this.#searchClosed.clear();
|
|
223
238
|
}
|
|
224
|
-
#opened(
|
|
239
|
+
#opened(path) { return this.#searchText ? this.#searchOpen.has(path) : this.#expanded.has(path); }
|
|
225
240
|
async #searchBranches() {
|
|
226
|
-
const version = this.#searchVersion, store = this
|
|
227
|
-
const current = () => this.isConnected && version === this.#searchVersion
|
|
241
|
+
const version = this.#searchVersion, store = this.storeBag;
|
|
242
|
+
const current = () => this.isConnected && version === this.#searchVersion
|
|
228
243
|
&& this.parameters.searchEager && this.parameters.resolveLazy;
|
|
229
244
|
this.#searching = true;
|
|
230
|
-
const visit = async (bag, ancestors = new Set()) => {
|
|
245
|
+
const visit = async (bag, prefix, ancestors = new Set()) => {
|
|
231
246
|
if (!current()) return;
|
|
232
247
|
if (ancestors.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
233
248
|
const next = new Set(ancestors).add(bag);
|
|
234
249
|
for (const node of bag.getNodes()) {
|
|
235
|
-
if (
|
|
250
|
+
if (!prefix && node.label === this.parameters.excludeRoot) continue;
|
|
236
251
|
if (!current()) return;
|
|
237
252
|
if (node.attr.loop === true) continue;
|
|
238
253
|
if (node.resolver !== null && !this.parameters.resolveLazy) continue;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
254
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
255
|
+
if (node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(path)) {
|
|
256
|
+
this.#searchAttempted.add(path);
|
|
257
|
+
await this.#resolve(node, path, true);
|
|
242
258
|
}
|
|
243
259
|
if (!current()) return;
|
|
244
|
-
if (node.staticValue instanceof Bag) await visit(node.staticValue, next);
|
|
260
|
+
if (node.staticValue instanceof Bag) await visit(node.staticValue, path, next);
|
|
245
261
|
}
|
|
246
262
|
};
|
|
247
|
-
try { await visit(store); }
|
|
263
|
+
try { await visit(store, ''); }
|
|
248
264
|
finally { if (current()) { this.#searching = false; this.#schedule(); } }
|
|
249
265
|
}
|
|
250
266
|
#highlight(caption) {
|
|
@@ -268,25 +284,31 @@ export const Tree = defineComponent({
|
|
|
268
284
|
this.#scheduled = true;
|
|
269
285
|
queueMicrotask(() => {
|
|
270
286
|
this.#scheduled = false;
|
|
271
|
-
if (this.isConnected
|
|
287
|
+
if (!this.isConnected) return;
|
|
288
|
+
// The final read of the address: an address without a Bag is reported, not drawn.
|
|
289
|
+
let store;
|
|
290
|
+
try {
|
|
291
|
+
store = this.storeBag;
|
|
292
|
+
// A store resolver still loading: its value arrives as a Data change that projects the tree again.
|
|
293
|
+
if (store instanceof Promise) return;
|
|
294
|
+
if (!(store instanceof Bag)) throw new TypeError('tree storepath must resolve to a Bag');
|
|
295
|
+
} catch (error) {
|
|
296
|
+
this.#context.reportError(error, 'Tree');
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
this.#render(store);
|
|
272
300
|
});
|
|
273
301
|
}
|
|
274
|
-
#render() {
|
|
302
|
+
#render(store) {
|
|
275
303
|
const focused = this.shadowRoot.activeElement?.closest('[role=treeitem]')?.dataset.path;
|
|
276
304
|
const focusedFavorite = this.shadowRoot.activeElement?.dataset.favoritePath;
|
|
277
305
|
const focusedFavoritesGroup = this.shadowRoot.activeElement?.dataset.favoritesGroup === 'true';
|
|
278
|
-
const loaded = [];
|
|
279
|
-
let checksChanged = false;
|
|
280
|
-
if (this.#checksEnabled && this.parameters.checkChildren &&
|
|
281
|
-
!(this.#pathsEnabled && this.parameters.checkedPaths !== this.#checkedPaths)) {
|
|
282
|
-
checksChanged = this.#syncChecked(this.#store, new Set(), loaded);
|
|
283
|
-
}
|
|
284
306
|
const items = new Map(), seen = new Set();
|
|
285
307
|
const visit = (bag, prefix, ancestors) => {
|
|
286
308
|
if (seen.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
287
309
|
seen.add(bag);
|
|
288
310
|
for (const node of bag.getNodes()) {
|
|
289
|
-
if (
|
|
311
|
+
if (!prefix && node.label === this.parameters.excludeRoot) continue;
|
|
290
312
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
291
313
|
const value = node.resolver !== null && !this.parameters.resolveLazy ? null : node.staticValue;
|
|
292
314
|
items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
|
|
@@ -294,47 +316,16 @@ export const Tree = defineComponent({
|
|
|
294
316
|
}
|
|
295
317
|
seen.delete(bag);
|
|
296
318
|
};
|
|
297
|
-
visit(
|
|
298
|
-
if (this.parameters.searchEager && this.parameters.resolveLazy && this.#searchText && this.#searchTimer === null && !this.#searching && [...items
|
|
299
|
-
node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(
|
|
319
|
+
visit(store, '', []);
|
|
320
|
+
if (this.parameters.searchEager && this.parameters.resolveLazy && this.#searchText && this.#searchTimer === null && !this.#searching && [...items].some(([path, {node}]) =>
|
|
321
|
+
node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(path))) {
|
|
300
322
|
void this.#searchBranches();
|
|
301
323
|
}
|
|
302
324
|
const actionBar = this.#rowActions();
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
: items.get(actionContext.path)?.node === actionContext.item;
|
|
308
|
-
if (!valid) actionBar.clearRowContext();
|
|
309
|
-
}
|
|
310
|
-
if (this.#pathsEnabled && this.parameters.checkedPaths !== this.#checkedPaths) {
|
|
311
|
-
const initial = this.#checkedPaths === undefined;
|
|
312
|
-
this.#checkedPaths = this.parameters.checkedPaths;
|
|
313
|
-
for (const {node} of items.values()) {
|
|
314
|
-
if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') continue;
|
|
315
|
-
if (!initial || this.#checkedPaths !== null) node.setAttr({checked: false});
|
|
316
|
-
}
|
|
317
|
-
for (const path of (this.#checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean)) {
|
|
318
|
-
const item = items.get(path);
|
|
319
|
-
if (item) this.#check(item.node, true, false);
|
|
320
|
-
}
|
|
321
|
-
} else if (this.#pathsEnabled && loaded.length) {
|
|
322
|
-
const paths = (this.parameters.checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean);
|
|
323
|
-
for (const path of paths) {
|
|
324
|
-
const item = items.get(path);
|
|
325
|
-
if (!item || item.node.attr.checked === true || item.node.attr.checked === 'disabled:on' ||
|
|
326
|
-
item.node.attr.checked === 'disabled:off') continue;
|
|
327
|
-
let bag = item.node.parentBag;
|
|
328
|
-
while (bag && !loaded.includes(bag)) bag = bag.parentNode?.parentBag;
|
|
329
|
-
if (bag) this.#check(item.node, true, false);
|
|
330
|
-
}
|
|
331
|
-
if (checksChanged || paths.length) this.#publishChecked(true);
|
|
332
|
-
} else if (checksChanged) {
|
|
333
|
-
this.#publishChecked(true);
|
|
334
|
-
}
|
|
335
|
-
const identities = new Set([...items.values()].map(item => item.node));
|
|
336
|
-
for (const node of this.#expanded) if (!identities.has(node)) this.#expanded.delete(node);
|
|
337
|
-
for (const node of this.#errors.keys()) if (!identities.has(node)) this.#errors.delete(node);
|
|
325
|
+
if (actionBar && actionBar.getRowContext() === null) actionBar.clearRowContext();
|
|
326
|
+
const checks = this.#checksEnabled ? this.#drawnChecks(store) : null;
|
|
327
|
+
for (const path of this.#expanded) if (!items.has(path)) this.#expanded.delete(path);
|
|
328
|
+
for (const path of this.#errors.keys()) if (!items.has(path)) this.#errors.delete(path);
|
|
338
329
|
const requested = this.parameters.selectedPath;
|
|
339
330
|
let reveal = null;
|
|
340
331
|
if (requested !== this.#requestedPath) {
|
|
@@ -343,12 +334,12 @@ export const Tree = defineComponent({
|
|
|
343
334
|
const version = ++this.#selectionVersion;
|
|
344
335
|
const ancestors = items.get(requested)?.ancestors ?? [];
|
|
345
336
|
if (requested && !items.has(requested)) {
|
|
346
|
-
reveal = {requested, version
|
|
337
|
+
reveal = {requested, version};
|
|
347
338
|
}
|
|
348
339
|
for (let index = 0; index < ancestors.length; index++) {
|
|
349
|
-
const
|
|
350
|
-
if (this.#expanded.has(
|
|
351
|
-
this.#expand(
|
|
340
|
+
const path = requested.split('.').slice(0, index + 1).join('.');
|
|
341
|
+
if (this.#expanded.has(path)) continue;
|
|
342
|
+
this.#expand(path);
|
|
352
343
|
}
|
|
353
344
|
}
|
|
354
345
|
const selected = this.#selectedPath;
|
|
@@ -362,7 +353,7 @@ export const Tree = defineComponent({
|
|
|
362
353
|
list.className = 'group'; list.setAttribute('part', 'group');
|
|
363
354
|
list.setAttribute('role', 'group');
|
|
364
355
|
for (const node of bag.getNodes()) {
|
|
365
|
-
if (
|
|
356
|
+
if (!prefix && node.label === this.parameters.excludeRoot) continue;
|
|
366
357
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
367
358
|
const {children} = items.get(path);
|
|
368
359
|
const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
|
|
@@ -371,20 +362,20 @@ export const Tree = defineComponent({
|
|
|
371
362
|
const entry = this.ownerDocument.createElement('li');
|
|
372
363
|
entry.className = `node ${branch ? 'branch' : 'leaf'}`;
|
|
373
364
|
entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
|
|
374
|
-
entry.classList.toggle('loading', this.#loading.has(
|
|
375
|
-
entry.classList.toggle('error', this.#errors.has(
|
|
376
|
-
entry.setAttribute('aria-busy', String(this.#loading.has(
|
|
365
|
+
entry.classList.toggle('loading', this.#loading.has(path));
|
|
366
|
+
entry.classList.toggle('error', this.#errors.has(path));
|
|
367
|
+
entry.setAttribute('aria-busy', String(this.#loading.has(path)));
|
|
377
368
|
entry.setAttribute('role', 'treeitem');
|
|
378
369
|
entry.setAttribute('aria-selected', String(selected === path));
|
|
379
370
|
entry.classList.toggle('selected', selected === path);
|
|
380
371
|
entry.dataset.path = path;
|
|
381
372
|
entry.tabIndex = -1;
|
|
382
373
|
const row = this.ownerDocument.createElement('div'); row.className = 'row';
|
|
383
|
-
row.addEventListener('pointerenter', () => this.#showRowActions(row,
|
|
384
|
-
entry.addEventListener('focus', () => this.#showRowActions(row,
|
|
374
|
+
row.addEventListener('pointerenter', () => this.#showRowActions(row, path, false));
|
|
375
|
+
entry.addEventListener('focus', () => this.#showRowActions(row, path, false));
|
|
385
376
|
row.draggable = this.parameters.draggable;
|
|
386
377
|
row.setAttribute('part', `row ${branch ? 'branch-row' : 'leaf-row'}${selected === path ? ' selected-row' : ''}`);
|
|
387
|
-
if (this.#errors.has(
|
|
378
|
+
if (this.#errors.has(path)) row.title = String(this.#errors.get(path));
|
|
388
379
|
const expander = this.ownerDocument.createElement(branch ? 'button' : 'span');
|
|
389
380
|
expander.setAttribute('part', branch ? 'expander' : 'spacer');
|
|
390
381
|
if (branch) {
|
|
@@ -405,7 +396,7 @@ export const Tree = defineComponent({
|
|
|
405
396
|
const caption = this.ownerDocument.createElement('span'); caption.className = 'caption';
|
|
406
397
|
const badge = this.ownerDocument.createElement('span'); badge.className = 'badge';
|
|
407
398
|
badge.setAttribute('part', 'badge');
|
|
408
|
-
this.#dragRows.set(row, {
|
|
399
|
+
this.#dragRows.set(row, {path, caption, favorite: false});
|
|
409
400
|
caption.setAttribute('part', 'caption');
|
|
410
401
|
const icon = this.ownerDocument.createElement('span');
|
|
411
402
|
icon.className = `icon ${branch ? 'branch-icon' : 'leaf-icon'}`;
|
|
@@ -424,7 +415,7 @@ export const Tree = defineComponent({
|
|
|
424
415
|
if (result instanceof Promise) throw new TypeError('tree onChecked must be synchronous');
|
|
425
416
|
if (result === false) { this.#schedule(); return; }
|
|
426
417
|
}
|
|
427
|
-
this.#
|
|
418
|
+
this.#toggleCheck(path);
|
|
428
419
|
});
|
|
429
420
|
}
|
|
430
421
|
row.append(expander, check || icon, badge, caption); entry.append(row);
|
|
@@ -458,7 +449,7 @@ export const Tree = defineComponent({
|
|
|
458
449
|
});
|
|
459
450
|
}
|
|
460
451
|
const present = () => {
|
|
461
|
-
const opened = this.#opened(
|
|
452
|
+
const opened = this.#opened(path), selected = this.#selectedPath === path;
|
|
462
453
|
const value = node.attr.badge;
|
|
463
454
|
if (value != null && typeof value !== 'string' && typeof value !== 'number') {
|
|
464
455
|
throw new TypeError('tree badge must be text or a number');
|
|
@@ -469,7 +460,8 @@ export const Tree = defineComponent({
|
|
|
469
460
|
badge.hidden = value == null || value === '';
|
|
470
461
|
badge.style.backgroundColor = color ?? '';
|
|
471
462
|
badge.toggleAttribute('data-colored', color != null && color !== '');
|
|
472
|
-
|
|
463
|
+
// labelState is read at its address for the callbacks of this draw; the tree keeps only the path.
|
|
464
|
+
const keywords = {item: node, path, opened, selected, state: this.#context.getStaticData(this.#context.attrDatapath('labelState'))};
|
|
473
465
|
const attribute = this.parameters.labelAttribute;
|
|
474
466
|
const label = this.parameters.internalNames && node.getAttr('fieldpath') ? node.label
|
|
475
467
|
: this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
|
|
@@ -486,7 +478,7 @@ export const Tree = defineComponent({
|
|
|
486
478
|
const nodeClasses = this.#classes(node.attr.node_class ?? '');
|
|
487
479
|
entry.className = ['node', branch ? 'branch' : 'leaf', ...nodeClasses,
|
|
488
480
|
...(selected ? ['selected'] : []), ...(branch ? [opened ? 'opened' : 'closed'] : []),
|
|
489
|
-
...(this.#loading.has(
|
|
481
|
+
...(this.#loading.has(path) ? ['loading'] : []), ...(this.#errors.has(path) ? ['error'] : [])].join(' ');
|
|
490
482
|
entry.setAttribute('part', ['node', branch ? 'branch' : 'leaf', ...nodeClasses].join(' '));
|
|
491
483
|
const customIcon = !check && this.parameters.getIconClass !== null;
|
|
492
484
|
const iconClasses = customIcon ? this.#classes(this.#call('getIconClass', keywords))
|
|
@@ -495,7 +487,7 @@ export const Tree = defineComponent({
|
|
|
495
487
|
icon.setAttribute('part', ['icon', ...iconClasses].join(' '));
|
|
496
488
|
icon.hidden = customIcon && iconClasses.length === 0;
|
|
497
489
|
if (check) {
|
|
498
|
-
const value =
|
|
490
|
+
const value = checks.get(path);
|
|
499
491
|
check.checked = value === true || value === 'disabled:on';
|
|
500
492
|
check.indeterminate = value === -1;
|
|
501
493
|
entry.setAttribute('aria-checked', value === -1 ? 'mixed' : String(check.checked));
|
|
@@ -506,7 +498,7 @@ export const Tree = defineComponent({
|
|
|
506
498
|
};
|
|
507
499
|
this.#presentations.set(path, present);
|
|
508
500
|
const sync = () => {
|
|
509
|
-
const opened = this.#opened(
|
|
501
|
+
const opened = this.#opened(path);
|
|
510
502
|
entry.setAttribute('aria-expanded', String(opened));
|
|
511
503
|
entry.classList.toggle('opened', opened);
|
|
512
504
|
entry.classList.toggle('closed', !opened);
|
|
@@ -517,17 +509,17 @@ export const Tree = defineComponent({
|
|
|
517
509
|
};
|
|
518
510
|
const toggle = () => {
|
|
519
511
|
const expanded = this.#searchText ? this.#searchOpen : this.#expanded;
|
|
520
|
-
if (expanded.has(
|
|
521
|
-
expanded.delete(
|
|
522
|
-
if (this.#searchText) this.#searchClosed.add(
|
|
512
|
+
if (expanded.has(path)) {
|
|
513
|
+
expanded.delete(path);
|
|
514
|
+
if (this.#searchText) this.#searchClosed.add(path);
|
|
523
515
|
} else {
|
|
524
|
-
if (this.#searchText) { this.#searchClosed.delete(
|
|
525
|
-
if (node.resolver !== null) this.#resolve(node);
|
|
516
|
+
if (this.#searchText) { this.#searchClosed.delete(path); this.#searchOpen.add(path); } else this.#expand(path);
|
|
517
|
+
if (node.resolver !== null) this.#resolve(node, path);
|
|
526
518
|
}
|
|
527
519
|
for (const update of branchSync.values()) update();
|
|
528
520
|
this.#tabStop(path);
|
|
529
521
|
};
|
|
530
|
-
if (branch) { branchSync.set(
|
|
522
|
+
if (branch) { branchSync.set(path, sync); sync(); } else present();
|
|
531
523
|
row.addEventListener('click', () => this.#select(path));
|
|
532
524
|
entry.addEventListener('keydown', event => {
|
|
533
525
|
if (event.target !== entry) return;
|
|
@@ -538,9 +530,9 @@ export const Tree = defineComponent({
|
|
|
538
530
|
else if (event.key === 'Home') target = visible[0];
|
|
539
531
|
else if (event.key === 'End') target = visible.at(-1);
|
|
540
532
|
else if (event.key === 'ArrowRight' && branch) {
|
|
541
|
-
if (!this.#opened(
|
|
533
|
+
if (!this.#opened(path)) toggle(); else target = group.firstElementChild;
|
|
542
534
|
} else if (event.key === 'ArrowLeft') {
|
|
543
|
-
if (branch && this.#opened(
|
|
535
|
+
if (branch && this.#opened(path)) toggle(); else target = parent;
|
|
544
536
|
} else if (event.key === ' ' && check) check.click();
|
|
545
537
|
else if (event.key === 'Enter' || event.key === ' ') this.#select(path);
|
|
546
538
|
else return;
|
|
@@ -552,11 +544,9 @@ export const Tree = defineComponent({
|
|
|
552
544
|
}
|
|
553
545
|
return list;
|
|
554
546
|
};
|
|
555
|
-
const root = build(
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (this.parameters.favorites.length) root.prepend(this.#buildFavorites(this.parameters.favorites, selected));
|
|
559
|
-
}
|
|
547
|
+
const root = build(store, '', null);
|
|
548
|
+
const favorites = this.#favorites();
|
|
549
|
+
if (favorites?.length) root.prepend(this.#buildFavorites(favorites, selected));
|
|
560
550
|
this.control.replaceChildren(root);
|
|
561
551
|
this.control.setAttribute('aria-busy', String(this.#searching));
|
|
562
552
|
if (this.#searchText) {
|
|
@@ -572,12 +562,17 @@ export const Tree = defineComponent({
|
|
|
572
562
|
});
|
|
573
563
|
const match = [caption.textContent, ...metadata].some(text => text.toLowerCase().includes(this.#searchText));
|
|
574
564
|
if (match) matches.push(caption);
|
|
575
|
-
if (match || this.#errors.has(
|
|
576
|
-
visible.add(
|
|
577
|
-
|
|
565
|
+
if (match || this.#errors.has(path) || this.#loading.has(path)) {
|
|
566
|
+
visible.add(path);
|
|
567
|
+
const parts = path.split('.');
|
|
568
|
+
for (const index of item.ancestors.keys()) {
|
|
569
|
+
const ancestorPath = parts.slice(0, index + 1).join('.');
|
|
570
|
+
visible.add(ancestorPath);
|
|
571
|
+
if (!this.#searchClosed.has(ancestorPath)) this.#searchOpen.add(ancestorPath);
|
|
572
|
+
}
|
|
578
573
|
}
|
|
579
574
|
}
|
|
580
|
-
for (const [path, row] of this.#rows) row.hidden = !visible.has(
|
|
575
|
+
for (const [path, row] of this.#rows) row.hidden = !visible.has(path);
|
|
581
576
|
for (const update of branchSync.values()) update();
|
|
582
577
|
const status = this.ownerDocument.createElement('div'); status.className = 'search-status'; status.setAttribute('role', 'status');
|
|
583
578
|
status.textContent = this.#searching ? 'Searching…' : this.#errors.size ? 'Some branches could not be searched. Expand them to retry.' : matches.length ? '' : 'No matches';
|
|
@@ -636,9 +631,9 @@ export const Tree = defineComponent({
|
|
|
636
631
|
caption.textContent = node.getAttr(this.parameters.internalNames ? 'fieldpath' : 'fullcaption');
|
|
637
632
|
favoriteRow.title = node.getAttr('fieldpath');
|
|
638
633
|
favoriteRow.draggable = this.parameters.draggable;
|
|
639
|
-
this.#dragRows.set(favoriteRow, {
|
|
640
|
-
favoriteRow.addEventListener('pointerenter', () => this.#showRowActions(favoriteRow,
|
|
641
|
-
entry.addEventListener('focus', () => this.#showRowActions(favoriteRow,
|
|
634
|
+
this.#dragRows.set(favoriteRow, {path, caption, favorite: true});
|
|
635
|
+
favoriteRow.addEventListener('pointerenter', () => this.#showRowActions(favoriteRow, path, true));
|
|
636
|
+
entry.addEventListener('focus', () => this.#showRowActions(favoriteRow, path, true));
|
|
642
637
|
favoriteRow.addEventListener('click', () => this.#selectFavorite(path));
|
|
643
638
|
entry.addEventListener('keydown', event => {
|
|
644
639
|
if (event.target !== entry) return;
|
|
@@ -660,121 +655,196 @@ export const Tree = defineComponent({
|
|
|
660
655
|
if (this.parameters.selectedPath === path) this.retrySelection();
|
|
661
656
|
else this.#context.writeParameter('selectedPath', path);
|
|
662
657
|
}
|
|
663
|
-
async #loadSelection({requested, version
|
|
658
|
+
async #loadSelection({requested, version}) {
|
|
664
659
|
const current = () => this.isConnected && this.#selectionVersion === version &&
|
|
665
|
-
this
|
|
660
|
+
this.parameters.selectedPath === requested && this.#selectedPath === requested;
|
|
666
661
|
const parts = requested.split('.');
|
|
667
|
-
|
|
668
|
-
|
|
662
|
+
for (const index of parts.slice(0, -1).keys()) {
|
|
663
|
+
const path = parts.slice(0, index + 1).join('.');
|
|
669
664
|
if (!current()) return;
|
|
670
|
-
const node =
|
|
665
|
+
const node = this.#rowNode(path);
|
|
671
666
|
if (!node) return;
|
|
672
667
|
if (node.resolver !== null && !this.parameters.resolveLazy) return;
|
|
673
668
|
if (node.resolver === null && !(node.staticValue instanceof Bag)) return;
|
|
674
|
-
|
|
675
|
-
this.#expand(node);
|
|
669
|
+
this.#expand(path);
|
|
676
670
|
this.#schedule();
|
|
677
|
-
if (node.resolver !== null && !(node.staticValue instanceof Bag)) await this.#resolve(node);
|
|
678
|
-
if (!current() || bag.getNode(part) !== node || !(node.staticValue instanceof Bag)) return;
|
|
679
|
-
bag = node.staticValue;
|
|
671
|
+
if (node.resolver !== null && !(node.staticValue instanceof Bag)) await this.#resolve(node, path);
|
|
680
672
|
}
|
|
681
|
-
if (current() &&
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
if (this.parameters.checkChildren) {
|
|
704
|
-
for (let parent = node.parentBag.parentNode; parent && parent !== this.#store.parentNode; parent = parent.parentBag.parentNode) {
|
|
705
|
-
parent.setAttr({checked: this.#checkStatus(parent.staticValue)});
|
|
706
|
-
}
|
|
673
|
+
if (current() && this.#rowNode(requested)) this.#schedule();
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* The check lists: `checkedPaths` (or the tree's own path list without it) and each
|
|
677
|
+
* `checked_<attribute>`. Each carries its text, read at its address now, and its writer.
|
|
678
|
+
*/
|
|
679
|
+
#checkLists() {
|
|
680
|
+
// Legacy updateCheckedAttr: the tree's `_valuelabel` goes on the Data node of each written list.
|
|
681
|
+
const label = this.#context.sourceNode.getAttr('_valuelabel');
|
|
682
|
+
const attributes = label == null ? null : {_valuelabel: label};
|
|
683
|
+
const lists = [{name: 'checkedPaths', attribute: null, joiner: this.parameters.checkedPaths_joiner,
|
|
684
|
+
value: this.#pathsEnabled ? this.parameters.checkedPaths : this.#ownCheckedPaths,
|
|
685
|
+
write: text => {
|
|
686
|
+
if (this.#pathsEnabled) this.#context.writeParameter('checkedPaths', text, attributes);
|
|
687
|
+
else this.#ownCheckedPaths = text;
|
|
688
|
+
}},
|
|
689
|
+
{name: 'checkedBranches', attribute: null, branches: true, joiner: ',', value: this.#checkedBranches,
|
|
690
|
+
write: text => { this.#checkedBranches = text; }}];
|
|
691
|
+
for (const [name, {attribute, path, joiner}] of this.#checkedAttributes) {
|
|
692
|
+
const value = this.#context.readRelativeData(path);
|
|
693
|
+
if (value != null && typeof value !== 'string') throw new TypeError(`tree ${name} must address text`);
|
|
694
|
+
lists.push({name, attribute, joiner, value, write: text => this.#context.setRelativeData(path, text, attributes)});
|
|
707
695
|
}
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
#
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
this.#applyChecked(children, value);
|
|
719
|
-
child.setAttr({checked: this.#checkStatus(children)});
|
|
720
|
-
} else child.setAttr({checked: value});
|
|
696
|
+
return lists;
|
|
697
|
+
}
|
|
698
|
+
#entries(list) { return (list.value ?? '').split(list.joiner).filter(Boolean); }
|
|
699
|
+
/** The entries of `lists` as one source: tree paths and, by attribute, the listed values. */
|
|
700
|
+
#checkSources(lists) {
|
|
701
|
+
const sources = {paths: new Set(), attributes: new Map()};
|
|
702
|
+
for (const attribute of this.#checkedAttributes.values()) sources.attributes.set(attribute.attribute, new Set());
|
|
703
|
+
for (const list of lists) {
|
|
704
|
+
const target = list.attribute === null ? sources.paths : sources.attributes.get(list.attribute);
|
|
705
|
+
for (const entry of this.#entries(list)) target.add(entry);
|
|
721
706
|
}
|
|
707
|
+
return sources;
|
|
708
|
+
}
|
|
709
|
+
/** The children Bag the tree draws under `node`, read without running its resolver; null for none. */
|
|
710
|
+
#childBag(node) {
|
|
711
|
+
const value = node.resolver !== null && !this.parameters.resolveLazy ? null : node.staticValue;
|
|
712
|
+
return value instanceof Bag ? value : null;
|
|
722
713
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
714
|
+
/**
|
|
715
|
+
* The check state by tree path, computed from `sources` (legacy states): true, false, -1 for a
|
|
716
|
+
* branch with mixed loaded children (with checkChildren), or the node's own `disabled:on` /
|
|
717
|
+
* `disabled:off`, which nothing changes. A node is checked when the lists name its path or its
|
|
718
|
+
* value of a `checked_<attribute>`, or, with checkChildren, an ancestor's; a disabled node stops
|
|
719
|
+
* this propagation, as in the legacy click. `forced` sets the clicked `path` and, with
|
|
720
|
+
* checkChildren, its descendants to `value`, as the legacy clickOnCheckbox.
|
|
721
|
+
*/
|
|
722
|
+
#checkStates(store, sources, forced = null) {
|
|
723
|
+
const states = new Map(), propagate = this.parameters.checkChildren, ancestors = new Set();
|
|
724
|
+
const listed = (node, path) => sources.paths.has(path) || [...sources.attributes].some(([attribute, values]) =>
|
|
725
|
+
node.attr[attribute] != null && values.has(String(node.attr[attribute])));
|
|
726
|
+
const visit = (bag, prefix, inherited, force) => {
|
|
727
|
+
if (ancestors.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
728
|
+
ancestors.add(bag);
|
|
729
|
+
const values = [];
|
|
730
|
+
for (const node of bag.getNodes()) {
|
|
731
|
+
if (!prefix && node.label === this.parameters.excludeRoot) continue;
|
|
732
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
733
|
+
const children = this.#childBag(node);
|
|
734
|
+
const nodeForce = forced !== null && path === forced.path ? forced.value : force;
|
|
735
|
+
let state;
|
|
736
|
+
if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') {
|
|
737
|
+
state = node.attr.checked;
|
|
738
|
+
if (children) visit(children, path, false, undefined);
|
|
739
|
+
} else {
|
|
740
|
+
const own = nodeForce !== undefined ? nodeForce : inherited || listed(node, path);
|
|
741
|
+
const below = children ? visit(children, path, propagate && own, propagate ? nodeForce : undefined) : [];
|
|
742
|
+
state = propagate && below.length ? this.#aggregate(below) : own;
|
|
738
743
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
loaded.push(children);
|
|
742
|
-
childChanged = true;
|
|
743
|
-
}
|
|
744
|
-
childChanged = this.#syncChecked(children, ancestors, loaded) || childChanged;
|
|
745
|
-
if (childChanged && children.length && node.attr.checked !== 'disabled:on' && node.attr.checked !== 'disabled:off') {
|
|
746
|
-
node.setAttr({checked: this.#checkStatus(children)});
|
|
744
|
+
states.set(path, state);
|
|
745
|
+
values.push(state);
|
|
747
746
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
747
|
+
ancestors.delete(bag);
|
|
748
|
+
return values;
|
|
749
|
+
};
|
|
750
|
+
visit(store, '', false, undefined);
|
|
751
|
+
return states;
|
|
752
|
+
}
|
|
753
|
+
#aggregate(values) {
|
|
754
|
+
const plain = values.map(value => value === 'disabled:on' ? true : value === 'disabled:off' ? false : value);
|
|
755
|
+
return plain.every(value => value === true) ? true : plain.every(value => value === false) ? false : -1;
|
|
752
756
|
}
|
|
753
|
-
|
|
754
|
-
|
|
757
|
+
/**
|
|
758
|
+
* The text of `list` for `states`, as the legacy updateCheckedAttr walk: with checkChildren only
|
|
759
|
+
* the nodes without loaded children (an unloaded branch included), otherwise every checked node;
|
|
760
|
+
* attribute values once each. The checkedBranches list takes the checked loaded branches instead. `previous` keeps the entries the walk cannot reach: paths below an
|
|
761
|
+
* unloaded branch (except, with checkChildren, below `clicked`) and values no reachable node carries.
|
|
762
|
+
*/
|
|
763
|
+
#listText(store, states, list, previous = null, clicked = null) {
|
|
764
|
+
const entries = [], known = new Set(), propagate = this.parameters.checkChildren;
|
|
755
765
|
const visit = (bag, prefix) => {
|
|
756
|
-
for (const
|
|
757
|
-
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
766
|
+
for (const node of bag.getNodes()) {
|
|
767
|
+
if (!prefix && node.label === this.parameters.excludeRoot) continue;
|
|
768
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
769
|
+
const children = this.#childBag(node);
|
|
770
|
+
const entry = list.attribute === null ? path
|
|
771
|
+
: node.attr[list.attribute] == null ? null : String(node.attr[list.attribute]);
|
|
772
|
+
if (entry !== null) known.add(entry);
|
|
773
|
+
const listed = list.branches ? propagate && children?.length > 0 : !(propagate && children?.length);
|
|
774
|
+
if (entry !== null && listed && states.get(path) === true && !entries.includes(entry)) entries.push(entry);
|
|
775
|
+
if (children) visit(children, path);
|
|
763
776
|
}
|
|
764
777
|
};
|
|
765
|
-
visit(
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
778
|
+
visit(store, '');
|
|
779
|
+
if (previous !== null && !list.branches) for (const entry of this.#entries(previous)) {
|
|
780
|
+
if (entries.includes(entry)) continue;
|
|
781
|
+
if (list.attribute !== null ? !known.has(entry) : this.#pendingCheckedPath(entry) &&
|
|
782
|
+
!(propagate && clicked !== null && (entry === clicked || entry.startsWith(`${clicked}.`)))) entries.push(entry);
|
|
783
|
+
}
|
|
784
|
+
return entries.join(list.joiner);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* The check states of this draw. Lists changed outside the tree since it last read or wrote them
|
|
788
|
+
* are the source (at the first draw, the nonempty lists); the other lists are rewritten from the
|
|
789
|
+
* states they give. Otherwise all lists together are the source and nothing is written.
|
|
790
|
+
*/
|
|
791
|
+
#drawnChecks(store) {
|
|
792
|
+
const lists = this.#checkLists(), first = this.#seenLists === null;
|
|
793
|
+
const changed = lists.filter(list => first ? this.#entries(list).length
|
|
794
|
+
: (this.#seenLists.get(list.name) ?? '') !== (list.value ?? ''));
|
|
795
|
+
const states = this.#checkStates(store, this.#checkSources(changed.length || first ? changed : lists));
|
|
796
|
+
this.#seenLists = new Map(lists.map(list => [list.name, list.value ?? '']));
|
|
797
|
+
// Legacy setCheckedPaths checks each path of a changed checkedPaths, and each check publishes.
|
|
798
|
+
const paths = changed.find(list => list.name === 'checkedPaths');
|
|
799
|
+
if (paths && !first) for (const path of this.#entries(paths)) {
|
|
800
|
+
if (states.has(path) && typeof states.get(path) !== 'string') this.#publishChecked(path, true);
|
|
801
|
+
}
|
|
802
|
+
if (changed.length) for (const list of lists) {
|
|
803
|
+
if (changed.includes(list)) continue;
|
|
804
|
+
const text = this.#listText(store, states, list);
|
|
805
|
+
if (text === (list.value ?? '')) continue;
|
|
806
|
+
this.#seenLists.set(list.name, text);
|
|
807
|
+
list.write(text);
|
|
808
|
+
}
|
|
809
|
+
return states;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Toggle the check at `path` as the legacy click (a checked or mixed node unchecks) and write
|
|
813
|
+
* every list. With checkChildren a branch counts as checked when any leaf the click changes is
|
|
814
|
+
* checked: the disabled nodes below it, which the click does not change, do not decide.
|
|
815
|
+
*/
|
|
816
|
+
#toggleCheck(path) {
|
|
817
|
+
const store = this.storeBag, lists = this.#checkLists();
|
|
818
|
+
const current = this.#checkStates(store, this.#checkSources(lists));
|
|
819
|
+
const state = current.get(path);
|
|
820
|
+
if (state === 'disabled:on' || state === 'disabled:off') return;
|
|
821
|
+
let checked = state !== false;
|
|
822
|
+
if (this.parameters.checkChildren) {
|
|
823
|
+
const below = [...current].filter(([key]) => key.startsWith(`${path}.`));
|
|
824
|
+
const fixed = below.filter(([, value]) => value === 'disabled:on' || value === 'disabled:off').map(([key]) => `${key}.`);
|
|
825
|
+
const leaves = below.filter(([key, value]) => value !== 'disabled:on' && value !== 'disabled:off'
|
|
826
|
+
&& !fixed.some(prefix => key.startsWith(prefix)) && !below.some(([other]) => other.startsWith(`${key}.`)));
|
|
827
|
+
if (leaves.length) checked = leaves.some(([, value]) => value === true);
|
|
828
|
+
}
|
|
829
|
+
const states = this.#checkStates(store, this.#checkSources(lists), {path, value: !checked});
|
|
830
|
+
this.#publishChecked(path, !checked);
|
|
831
|
+
for (const list of lists) {
|
|
832
|
+
const text = this.#listText(store, states, list, list, path);
|
|
833
|
+
this.#seenLists.set(list.name, text);
|
|
834
|
+
if (text !== (list.value ?? '')) list.write(text);
|
|
770
835
|
}
|
|
771
|
-
this.#checkedPaths = paths.join(this.parameters.checkedPaths_joiner);
|
|
772
|
-
this.#context.writeParameter('checkedPaths', this.#checkedPaths);
|
|
773
836
|
this.#schedule();
|
|
774
837
|
}
|
|
838
|
+
/**
|
|
839
|
+
* Publish the legacy `<nodeId>_checked` topic of the tree for the check of `path` set to `checked`,
|
|
840
|
+
* before the lists are written; the payload is the store node (`item`), its tree path and the value.
|
|
841
|
+
*/
|
|
842
|
+
#publishChecked(path, checked) {
|
|
843
|
+
this.#context.publish('checked', {path, checked});
|
|
844
|
+
}
|
|
775
845
|
#pendingCheckedPath(path) {
|
|
776
846
|
const parts = path.split('.');
|
|
777
|
-
let bag = this
|
|
847
|
+
let bag = this.storeBag;
|
|
778
848
|
for (let index = 0; index < parts.length; index++) {
|
|
779
849
|
const node = bag.getNode(parts[index]);
|
|
780
850
|
if (!node) return false;
|
|
@@ -785,12 +855,6 @@ export const Tree = defineComponent({
|
|
|
785
855
|
}
|
|
786
856
|
return false;
|
|
787
857
|
}
|
|
788
|
-
#checkStatus(bag) {
|
|
789
|
-
const values = bag.getNodes().map(child => child.attr.checked === 'disabled:on' ? true
|
|
790
|
-
: child.attr.checked === 'disabled:off' || child.attr.checked == null ? false : child.attr.checked);
|
|
791
|
-
return values.every(value => value === true) ? true
|
|
792
|
-
: values.every(value => value === false) ? false : -1;
|
|
793
|
-
}
|
|
794
858
|
#classes(value) {
|
|
795
859
|
if (typeof value !== 'string') throw new TypeError('Tree classes must be a string');
|
|
796
860
|
return value.split(/\s+/).filter(Boolean);
|
|
@@ -800,11 +864,11 @@ export const Tree = defineComponent({
|
|
|
800
864
|
if (bars.length > 1) throw new Error('tree accepts one rowActions bar');
|
|
801
865
|
return bars[0] ?? null;
|
|
802
866
|
}
|
|
803
|
-
#showRowActions(row,
|
|
867
|
+
#showRowActions(row, path, favorite) {
|
|
804
868
|
const bar = this.#rowActions();
|
|
805
869
|
if (!bar || bar.contains(this.ownerDocument.activeElement)) return;
|
|
806
870
|
const hostBox = this.getBoundingClientRect(), rowBox = row.getBoundingClientRect();
|
|
807
|
-
bar.setRowContext(
|
|
871
|
+
bar.setRowContext(path, () => this.#rowItem(path, favorite));
|
|
808
872
|
bar.style.position = 'absolute';
|
|
809
873
|
bar.style.top = `${rowBox.top - hostBox.top}px`;
|
|
810
874
|
bar.style.left = bar.parameters.position === 'start' ? `${rowBox.left - hostBox.left}px` : 'auto';
|
|
@@ -834,26 +898,55 @@ export const Tree = defineComponent({
|
|
|
834
898
|
#visible() {
|
|
835
899
|
return [...this.control.querySelectorAll('[role=treeitem]')].filter(row => !row.closest('[hidden]'));
|
|
836
900
|
}
|
|
837
|
-
|
|
838
|
-
|
|
901
|
+
/** Expand the row at tree `path`; autoCollapse closes the expanded siblings, matched by key. */
|
|
902
|
+
#expand(path) {
|
|
903
|
+
if (this.#searchText) { this.#searchOpen.add(path); return; }
|
|
839
904
|
if (this.parameters.autoCollapse) {
|
|
840
|
-
|
|
841
|
-
|
|
905
|
+
const parent = path.includes('.') ? path.slice(0, path.lastIndexOf('.')) : '';
|
|
906
|
+
for (const other of [...this.#expanded]) {
|
|
907
|
+
const otherParent = other.includes('.') ? other.slice(0, other.lastIndexOf('.')) : '';
|
|
908
|
+
if (other !== path && otherParent === parent) this.#expanded.delete(other);
|
|
842
909
|
}
|
|
843
910
|
}
|
|
844
|
-
this.#expanded.add(
|
|
911
|
+
this.#expanded.add(path);
|
|
845
912
|
}
|
|
846
|
-
#resolve(node, searching = false) {
|
|
847
|
-
if (this.#resolutions.has(
|
|
848
|
-
this.#loading.add(
|
|
913
|
+
#resolve(node, path, searching = false) {
|
|
914
|
+
if (this.#resolutions.has(path)) return this.#resolutions.get(path);
|
|
915
|
+
this.#loading.add(path); this.#errors.delete(path); this.#schedule();
|
|
849
916
|
const pending = (async () => {
|
|
850
917
|
try { await Promise.resolve().then(() => node.getValue()); }
|
|
851
|
-
catch (error) { this.#errors.set(
|
|
852
|
-
finally { this.#loading.delete(
|
|
918
|
+
catch (error) { this.#errors.set(path, error); if (!searching) this.#expanded.delete(path); }
|
|
919
|
+
finally { this.#loading.delete(path); this.#resolutions.delete(path); this.#schedule(); }
|
|
853
920
|
})();
|
|
854
|
-
this.#resolutions.set(
|
|
921
|
+
this.#resolutions.set(path, pending);
|
|
855
922
|
return pending;
|
|
856
923
|
}
|
|
924
|
+
/** The node at tree `path`, read from the store without running resolvers; null when absent. */
|
|
925
|
+
#rowNode(path) {
|
|
926
|
+
let bag = this.storeBag, node = null;
|
|
927
|
+
for (const label of path.split('.')) {
|
|
928
|
+
if (!(bag instanceof Bag)) return null;
|
|
929
|
+
node = bag.getNode(label);
|
|
930
|
+
if (!node) return null;
|
|
931
|
+
bag = node.staticValue;
|
|
932
|
+
}
|
|
933
|
+
return node;
|
|
934
|
+
}
|
|
935
|
+
/** The item of a drawn row: the store node at `path`, or the favorite whose originalPath is `path`. */
|
|
936
|
+
#rowItem(path, favorite) {
|
|
937
|
+
if (!favorite) return this.#rowNode(path);
|
|
938
|
+
const favorites = this.#context.getStaticData(this.#context.attrDatapath('favorites'));
|
|
939
|
+
return favorites instanceof Bag ? favorites.getNodes().find(node => node.getAttr('originalPath') === path) ?? null : null;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* The favorites Bag, read at the address of the `favorites` pointer at each use; null without
|
|
943
|
+
* favorites. A change inside the Bag or a replacement at its address projects the tree again.
|
|
944
|
+
*/
|
|
945
|
+
#favorites() {
|
|
946
|
+
const favorites = this.#context.getStaticData(this.#context.attrDatapath('favorites'));
|
|
947
|
+
if (favorites !== null && !(favorites instanceof Bag)) throw new TypeError('tree favorites must be a Bag');
|
|
948
|
+
return favorites;
|
|
949
|
+
}
|
|
857
950
|
#tabStop(path) {
|
|
858
951
|
const visible = this.#visible(), target = typeof path === 'string' || path == null
|
|
859
952
|
? visible.find(row => row.dataset.path === path) ?? visible[0] : path;
|