@gramlot/gramlot 0.3.24 → 0.3.27
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/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +21 -20
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
- package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
- package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
- package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
- package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
- package/dist/components/grid/__init__.py +3 -2
- package/dist/components/grid/assets/collection.js +77 -17
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +78 -1
- package/dist/components/grouplets/__init__.py +2 -2
- package/dist/components/grouplets/assets/collection.js +3 -20
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +59 -34
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +64 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +67 -57
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +35 -0
- 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/selection_trial/grammar.json +35 -0
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +26 -23
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +341 -1
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +3 -3
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +13 -0
- package/dist/components/uploads/assets/collection.js +67 -0
- package/dist/components/uploads/assets/index.js +3 -0
- package/dist/components/uploads/commands.json +7 -0
- package/dist/components/uploads/grammar.json +789 -0
- package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
- package/dist/gramlot.js +5455 -573
- package/dist/gramlot.min.js +1588 -43
- package/dist/runtime-notices.json +28 -0
- package/package.json +4 -2
- package/src/binding/grid-struct.js +1 -1
- package/src/binding/providers.js +4 -1
- package/src/binding/remote-resolver.js +1 -8
- package/src/binding/runtime.js +40 -1
- package/src/binding/validation-context.js +41 -0
- package/src/browser-camera-provider.d.ts +8 -0
- package/src/browser-camera-provider.js +104 -0
- package/src/builder/source.js +13 -2
- package/src/components/attachment-manager.js +160 -0
- package/src/components/bases.js +19 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/choice-editor.js +44 -16
- package/src/components/database-choices.js +13 -8
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +44 -58
- package/src/components/grid-cell-editor.js +245 -0
- package/src/components/grid-grammar.json +42 -0
- package/src/components/grid-structure.js +5 -1
- package/src/components/grid-styles.js +60 -1
- package/src/components/grid.js +103 -11
- package/src/components/grouplet-card.js +11 -3
- package/src/components/html-preview.js +17 -4
- package/src/components/image-crop-dialog.js +272 -0
- package/src/components/image-crop.js +79 -0
- package/src/components/image-uploader.js +252 -0
- package/src/components/inputs.js +4 -3
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/parameters.js +6 -2
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tree.js +417 -17
- package/src/components/typed-editor.js +19 -9
- package/src/components/upload-engine.js +156 -0
- package/src/components/uploader.js +208 -0
- package/src/components/uploads.js +7 -0
- package/src/components/validation.js +1 -1
- package/src/editing-session.d.ts +26 -0
- package/src/editing-session.js +494 -0
- package/src/editor-values.js +57 -0
- package/src/experiments/selection-trial.js +18 -2
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +3 -0
- package/src/gramlot.js +9 -5
- package/src/handlers/device-handler.d.ts +2 -1
- package/src/handlers/rpc-handler.d.ts +3 -3
- package/src/index-page-styles.js +1 -0
- package/src/index.d.ts +14 -1
- package/src/index.js +13 -0
- package/src/inout.d.ts +2 -0
- package/src/inout.js +6 -0
- package/src/markdown-loader.d.ts +1 -0
- package/src/markdown-loader.js +4 -0
- package/src/markdown.d.ts +1 -0
- package/src/markdown.js +2 -0
- package/src/media-frame.js +9 -0
- package/src/renderer/attributes.js +7 -1
- package/src/renderer/gramlot-renderer.d.ts +3 -0
- package/src/renderer/gramlot-renderer.js +42 -2
- package/src/server/assets.d.ts +1 -1
- package/src/server/assets.js +1 -1
- package/src/server/gramlot-server.d.ts +8 -1
- package/src/server/gramlot-server.js +83 -7
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +2 -0
- package/src/server/page-base.js +17 -4
- package/src/server/page.d.ts +13 -1
- package/src/server/page.js +6 -0
- package/src/server/source-import.d.ts +2 -0
- package/src/server/source-import.js +35 -0
- package/src/server/upload.d.ts +20 -0
- package/src/server/upload.js +142 -0
- package/src/server/visual-editor.d.ts +11 -0
- package/src/server/visual-editor.js +159 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +56 -0
- package/src/tree-store.d.ts +24 -0
- package/src/tree-store.js +193 -0
- package/src/validation-run.js +50 -0
- package/src/view/button.js +8 -5
- package/src/view/controls.js +9 -42
- package/src/view/html.js +10 -2
- package/src/visual-editor-canvas.js +29 -0
- package/src/visual-editor-catalogue.js +34 -0
- package/src/visual-editor-icons.js +10 -0
- package/src/visual-editor.d.ts +61 -0
- package/src/visual-editor.js +1062 -0
- package/themes/gramlot-base/theme.css +141 -0
- package/tools/gramlot-tools-inspector.js +1 -1
- package/tools/inspector-agent.js +1 -1
- package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
- package/src/form-state.d.ts +0 -20
- package/src/form-state.js +0 -198
package/src/components/tree.js
CHANGED
|
@@ -1,25 +1,70 @@
|
|
|
1
1
|
/** Bag hierarchy, lazy branch expansion, captions and path selection. */
|
|
2
|
-
import {Bag} from '@gramlot/gramlot';
|
|
3
|
-
import createDOMPurify from 'dompurify';
|
|
2
|
+
import {Bag, createDOMPurify} from '@gramlot/gramlot';
|
|
4
3
|
import {defineComponent, defineCollection} from './registry.js';
|
|
5
4
|
import {Container} from './container.js';
|
|
6
5
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
7
6
|
|
|
7
|
+
export const RowActions = defineComponent({
|
|
8
|
+
name: 'rowActions', tag: 'gramlot-row-actions', base: Container,
|
|
9
|
+
subTags: 'button,dropDownButton', sourceContext: true, parameters: {
|
|
10
|
+
position: {dtype: 'T', default: 'end'},
|
|
11
|
+
actionState: {dtype: 'T', nullable: true, default: null},
|
|
12
|
+
state: {dtype: 'X', nullable: true, default: null, binding: 'read'}
|
|
13
|
+
},
|
|
14
|
+
implementation: Base => class extends Base {
|
|
15
|
+
#rowContext = null;
|
|
16
|
+
#context;
|
|
17
|
+
connectedCallback() { this.slot = 'row-actions'; this.hidden = true; }
|
|
18
|
+
setSourceContext(context) { this.#context = context; }
|
|
19
|
+
setRowContext(item, path) { this.#rowContext = {item, path}; this.#refresh(); }
|
|
20
|
+
getRowContext() { return this.#rowContext; }
|
|
21
|
+
clearRowContext() { this.#rowContext = null; this.hidden = true; }
|
|
22
|
+
projectAttributes(attrs, adapt) {
|
|
23
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
24
|
+
if (!['start', 'end'].includes(this.parameters.position)) throw new TypeError('rowActions position must be start or end');
|
|
25
|
+
this.#refresh();
|
|
26
|
+
return rest;
|
|
27
|
+
}
|
|
28
|
+
#refresh() {
|
|
29
|
+
if (!this.#rowContext || !this.parameters.actionState) return;
|
|
30
|
+
for (const action of this.children) {
|
|
31
|
+
const code = action.getAttribute('rowAction');
|
|
32
|
+
if (code === null) continue;
|
|
33
|
+
const presentation = this.#context.callLogic(this.parameters.actionState,
|
|
34
|
+
{...this.#rowContext, action: code, state: this.parameters.state});
|
|
35
|
+
if (!presentation || typeof presentation.hidden !== 'boolean' ||
|
|
36
|
+
typeof presentation.icon !== 'string' || typeof presentation.title !== 'string') {
|
|
37
|
+
throw new TypeError('rowActions actionState must return hidden, icon and title');
|
|
38
|
+
}
|
|
39
|
+
action.setActionPresentation(presentation);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
8
45
|
export const Tree = defineComponent({
|
|
9
|
-
name: 'tree', tag: 'gramlot-tree', base: Container, sourceContext: true, bagStore: true, dragSource: true,
|
|
46
|
+
name: 'tree', tag: 'gramlot-tree', base: Container, subTags: 'rowActions[:1]', sourceContext: true, bagStore: true, dragSource: true,
|
|
10
47
|
parameters: {
|
|
11
48
|
storepath: {dtype: 'T'},
|
|
12
49
|
draggable: {dtype: 'B', default: false, binding: 'read'},
|
|
13
50
|
labelAttribute: {dtype: 'T', nullable: true, default: null, binding: 'read'},
|
|
51
|
+
internalNames: {dtype: 'B', default: false, binding: 'read'},
|
|
14
52
|
hideValues: {dtype: 'B', default: false, binding: 'read'},
|
|
53
|
+
excludeRoot: {dtype: 'T', nullable: true, default: null, binding: 'read'},
|
|
15
54
|
labelCb: {dtype: 'T', nullable: true, default: null},
|
|
16
55
|
getLabel: {dtype: 'T', nullable: true, default: null},
|
|
17
56
|
getLabelClass: {dtype: 'T', nullable: true, default: null},
|
|
18
57
|
getIconClass: {dtype: 'T', nullable: true, default: null},
|
|
19
58
|
selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
|
|
20
59
|
searchText: {dtype: 'T', default: '', binding: 'read'},
|
|
60
|
+
favorites: {dtype: 'X', nullable: true, default: null, binding: 'read'},
|
|
61
|
+
favoritesLabel: {dtype: 'T', default: 'Favorites', binding: 'read'},
|
|
21
62
|
autoCollapse: {dtype: 'B', default: false, binding: 'read'},
|
|
22
|
-
selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'}
|
|
63
|
+
selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
64
|
+
onChecked: {dtype: ['B', 'T'], nullable: true, default: null},
|
|
65
|
+
checkedPaths: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
66
|
+
checkedPaths_joiner: {dtype: 'T', default: ','},
|
|
67
|
+
checkChildren: {dtype: 'B', default: true, binding: 'read'}
|
|
23
68
|
},
|
|
24
69
|
implementation: Base => class extends Base {
|
|
25
70
|
#store;
|
|
@@ -27,14 +72,23 @@ export const Tree = defineComponent({
|
|
|
27
72
|
#context;
|
|
28
73
|
#expanded = new Set();
|
|
29
74
|
#rows = new Map();
|
|
75
|
+
#favoriteRows = new Map();
|
|
76
|
+
#favoritesOpen = false;
|
|
30
77
|
#dragRows = new WeakMap();
|
|
31
78
|
#presentations = new Map();
|
|
32
79
|
#requestedPath;
|
|
80
|
+
#selectionVersion = 0;
|
|
33
81
|
#selectedPath = null;
|
|
34
82
|
#scheduled = false;
|
|
83
|
+
#checkedPaths;
|
|
84
|
+
#checksEnabled = false;
|
|
85
|
+
#pathsEnabled = false;
|
|
86
|
+
#checkedBags = new WeakMap();
|
|
87
|
+
#checkedNodes = new WeakSet();
|
|
35
88
|
#loading = new Set();
|
|
36
89
|
#errors = new Map();
|
|
37
90
|
#searchInput = '';
|
|
91
|
+
#excludedRoot = null;
|
|
38
92
|
#searchText = '';
|
|
39
93
|
#searchTimer = null;
|
|
40
94
|
#searchVersion = 0;
|
|
@@ -54,6 +108,7 @@ export const Tree = defineComponent({
|
|
|
54
108
|
this.control.setAttribute('part', 'tree');
|
|
55
109
|
const style = this.ownerDocument.createElement('style');
|
|
56
110
|
style.textContent = `
|
|
111
|
+
:host{position:relative}
|
|
57
112
|
.control-box{overflow:auto;padding:4px;min-height:32px}
|
|
58
113
|
ul{list-style:none;margin:0;padding:0} ul ul{padding-inline-start:20px}
|
|
59
114
|
.row{display:flex;align-items:center;min-height:var(--gramlot-tree-row-height,28px);gap:2px;border-radius:3px;cursor:default}
|
|
@@ -69,6 +124,10 @@ export const Tree = defineComponent({
|
|
|
69
124
|
.expander svg{display:block;width:14px;height:14px;pointer-events:none}
|
|
70
125
|
[aria-expanded=true]>.row>.expander svg{transform:rotate(90deg)}
|
|
71
126
|
.spacer{width:max(20px,var(--gramlot-touch-target,0px));flex:none}.caption{min-width:0;overflow-wrap:anywhere}
|
|
127
|
+
.badge{display:inline-flex;align-items:center;justify-content:center;flex:none;min-width:18px;
|
|
128
|
+
height:16px;padding:0 3px;border-radius:3px;font-size:10px;line-height:1;
|
|
129
|
+
background:var(--gramlot-tree-badge-background,#e7eaf0);color:var(--gramlot-tree-badge-color,#394452)}
|
|
130
|
+
.badge[data-colored]{color:var(--gramlot-tree-colored-badge-color,white)}
|
|
72
131
|
.icon{width:16px;height:16px;flex:none;background:currentColor;opacity:.7;mask:center/contain no-repeat;
|
|
73
132
|
mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M5 3h9l5 5v13H5zM14 3v6h5M8 13h8M8 17h8'/%3E%3C/svg%3E")}
|
|
74
133
|
.branch-icon{mask-image:url("data:image/svg+xml,%3Csvg xmlns='${SVG_NS}' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.7' d='M3 7V4h7l3 3h8v13H3z'/%3E%3C/svg%3E")}
|
|
@@ -78,6 +137,13 @@ export const Tree = defineComponent({
|
|
|
78
137
|
.search-status{padding:4px;color:var(--gramlot-text-secondary,#555);font-size:.9em}
|
|
79
138
|
[hidden]{display:none}`;
|
|
80
139
|
this.shadowRoot.append(style);
|
|
140
|
+
const actions = this.ownerDocument.createElement('slot');
|
|
141
|
+
actions.name = 'row-actions';
|
|
142
|
+
this.shadowRoot.append(actions);
|
|
143
|
+
this.addEventListener('pointerleave', () => {
|
|
144
|
+
const bar = this.#rowActions();
|
|
145
|
+
if (bar && !bar.contains(this.ownerDocument.activeElement)) bar.clearRowContext();
|
|
146
|
+
});
|
|
81
147
|
}
|
|
82
148
|
setSourceContext(context) { this.#context = context; }
|
|
83
149
|
/** Read only the rendered row and its BagNode; never request a resolver value. */
|
|
@@ -103,11 +169,22 @@ export const Tree = defineComponent({
|
|
|
103
169
|
this.#expanded.clear();
|
|
104
170
|
this.#errors.clear();
|
|
105
171
|
this.#requestedPath = undefined;
|
|
172
|
+
this.#selectionVersion++;
|
|
173
|
+
this.#checkedPaths = undefined;
|
|
174
|
+
this.#checkedBags = new WeakMap();
|
|
175
|
+
this.#checkedNodes = new WeakSet();
|
|
106
176
|
}
|
|
107
177
|
this.#schedule();
|
|
108
178
|
}
|
|
109
179
|
projectAttributes(attrs, adapt) {
|
|
180
|
+
this.#pathsEnabled = Object.hasOwn(attrs, 'checkedPaths');
|
|
181
|
+
this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked);
|
|
110
182
|
const rest = super.projectAttributes(attrs, adapt);
|
|
183
|
+
if (this.#excludedRoot !== this.parameters.excludeRoot) {
|
|
184
|
+
this.#excludedRoot = this.parameters.excludeRoot;
|
|
185
|
+
this.#resetSearch();
|
|
186
|
+
this.#searchText = this.#searchInput.toLowerCase();
|
|
187
|
+
}
|
|
111
188
|
const text = this.parameters.searchText.trim();
|
|
112
189
|
if (text !== this.#searchInput) {
|
|
113
190
|
this.#resetSearch();
|
|
@@ -140,7 +217,9 @@ export const Tree = defineComponent({
|
|
|
140
217
|
if (ancestors.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
141
218
|
const next = new Set(ancestors).add(bag);
|
|
142
219
|
for (const node of bag.getNodes()) {
|
|
220
|
+
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
143
221
|
if (!current()) return;
|
|
222
|
+
if (node.attr.loop === true) continue;
|
|
144
223
|
if (node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node)) {
|
|
145
224
|
this.#searchAttempted.add(node);
|
|
146
225
|
await this.#resolve(node, true);
|
|
@@ -167,6 +246,7 @@ export const Tree = defineComponent({
|
|
|
167
246
|
fragment.append(value.slice(cursor)); text.replaceWith(fragment);
|
|
168
247
|
}
|
|
169
248
|
}
|
|
249
|
+
retrySelection() { this.#requestedPath = undefined; this.#schedule(); }
|
|
170
250
|
#schedule() {
|
|
171
251
|
if (this.#scheduled) return;
|
|
172
252
|
this.#scheduled = true;
|
|
@@ -177,11 +257,20 @@ export const Tree = defineComponent({
|
|
|
177
257
|
}
|
|
178
258
|
#render() {
|
|
179
259
|
const focused = this.shadowRoot.activeElement?.closest('[role=treeitem]')?.dataset.path;
|
|
260
|
+
const focusedFavorite = this.shadowRoot.activeElement?.dataset.favoritePath;
|
|
261
|
+
const focusedFavoritesGroup = this.shadowRoot.activeElement?.dataset.favoritesGroup === 'true';
|
|
262
|
+
const loaded = [];
|
|
263
|
+
let checksChanged = false;
|
|
264
|
+
if (this.#checksEnabled && this.parameters.checkChildren &&
|
|
265
|
+
!(this.#pathsEnabled && this.parameters.checkedPaths !== this.#checkedPaths)) {
|
|
266
|
+
checksChanged = this.#syncChecked(this.#store, new Set(), loaded);
|
|
267
|
+
}
|
|
180
268
|
const items = new Map(), seen = new Set();
|
|
181
269
|
const visit = (bag, prefix, ancestors) => {
|
|
182
270
|
if (seen.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
183
271
|
seen.add(bag);
|
|
184
272
|
for (const node of bag.getNodes()) {
|
|
273
|
+
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
185
274
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
186
275
|
const value = node.staticValue; // Rendering never evaluates resolvers.
|
|
187
276
|
items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
|
|
@@ -191,20 +280,64 @@ export const Tree = defineComponent({
|
|
|
191
280
|
};
|
|
192
281
|
visit(this.#store, '', []);
|
|
193
282
|
if (this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
|
|
194
|
-
node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node))) {
|
|
283
|
+
node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node))) {
|
|
195
284
|
void this.#searchBranches();
|
|
196
285
|
}
|
|
286
|
+
const actionBar = this.#rowActions();
|
|
287
|
+
const actionContext = actionBar ? actionBar.getRowContext() : null;
|
|
288
|
+
if (actionContext) {
|
|
289
|
+
const favorite = actionContext.item.getAttr('favoriteEntry') === true;
|
|
290
|
+
const valid = favorite ? this.parameters.favorites instanceof Bag && this.parameters.favorites.getNodes().includes(actionContext.item)
|
|
291
|
+
: items.get(actionContext.path)?.node === actionContext.item;
|
|
292
|
+
if (!valid) actionBar.clearRowContext();
|
|
293
|
+
}
|
|
294
|
+
if (this.#pathsEnabled && this.parameters.checkedPaths !== this.#checkedPaths) {
|
|
295
|
+
const initial = this.#checkedPaths === undefined;
|
|
296
|
+
this.#checkedPaths = this.parameters.checkedPaths;
|
|
297
|
+
for (const {node} of items.values()) {
|
|
298
|
+
if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') continue;
|
|
299
|
+
if (!initial || this.#checkedPaths !== null) node.setAttr({checked: false});
|
|
300
|
+
}
|
|
301
|
+
for (const path of (this.#checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean)) {
|
|
302
|
+
const item = items.get(path);
|
|
303
|
+
if (item) this.#check(item.node, true, false);
|
|
304
|
+
}
|
|
305
|
+
} else if (this.#pathsEnabled && loaded.length) {
|
|
306
|
+
const paths = (this.parameters.checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean);
|
|
307
|
+
for (const path of paths) {
|
|
308
|
+
const item = items.get(path);
|
|
309
|
+
if (!item || item.node.attr.checked === true || item.node.attr.checked === 'disabled:on' ||
|
|
310
|
+
item.node.attr.checked === 'disabled:off') continue;
|
|
311
|
+
let bag = item.node.parentBag;
|
|
312
|
+
while (bag && !loaded.includes(bag)) bag = bag.parentNode?.parentBag;
|
|
313
|
+
if (bag) this.#check(item.node, true, false);
|
|
314
|
+
}
|
|
315
|
+
if (checksChanged || paths.length) this.#publishChecked(true);
|
|
316
|
+
} else if (checksChanged) {
|
|
317
|
+
this.#publishChecked(true);
|
|
318
|
+
}
|
|
197
319
|
const identities = new Set([...items.values()].map(item => item.node));
|
|
198
320
|
for (const node of this.#expanded) if (!identities.has(node)) this.#expanded.delete(node);
|
|
199
321
|
for (const node of this.#errors.keys()) if (!identities.has(node)) this.#errors.delete(node);
|
|
200
322
|
const requested = this.parameters.selectedPath;
|
|
323
|
+
let reveal = null;
|
|
201
324
|
if (requested !== this.#requestedPath) {
|
|
202
325
|
this.#requestedPath = requested;
|
|
203
326
|
this.#selectedPath = requested;
|
|
204
|
-
|
|
327
|
+
const version = ++this.#selectionVersion;
|
|
328
|
+
const ancestors = items.get(requested)?.ancestors ?? [];
|
|
329
|
+
if (requested && !items.has(requested)) {
|
|
330
|
+
reveal = {requested, version, store: this.#store};
|
|
331
|
+
}
|
|
332
|
+
for (let index = 0; index < ancestors.length; index++) {
|
|
333
|
+
const node = ancestors[index];
|
|
334
|
+
if (this.#expanded.has(node)) continue;
|
|
335
|
+
this.#expand(node);
|
|
336
|
+
}
|
|
205
337
|
}
|
|
206
338
|
const selected = this.#selectedPath;
|
|
207
339
|
this.#rows.clear();
|
|
340
|
+
this.#favoriteRows.clear();
|
|
208
341
|
this.#dragRows = new WeakMap();
|
|
209
342
|
this.#presentations.clear();
|
|
210
343
|
const branchSync = new Map();
|
|
@@ -213,6 +346,7 @@ export const Tree = defineComponent({
|
|
|
213
346
|
list.className = 'group'; list.setAttribute('part', 'group');
|
|
214
347
|
list.setAttribute('role', 'group');
|
|
215
348
|
for (const node of bag.getNodes()) {
|
|
349
|
+
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
216
350
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
217
351
|
const {children} = items.get(path);
|
|
218
352
|
const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
|
|
@@ -230,6 +364,8 @@ export const Tree = defineComponent({
|
|
|
230
364
|
entry.dataset.path = path;
|
|
231
365
|
entry.tabIndex = -1;
|
|
232
366
|
const row = this.ownerDocument.createElement('div'); row.className = 'row';
|
|
367
|
+
row.addEventListener('pointerenter', () => this.#showRowActions(row, node, path));
|
|
368
|
+
entry.addEventListener('focus', () => this.#showRowActions(row, node, path));
|
|
233
369
|
row.draggable = this.parameters.draggable;
|
|
234
370
|
row.setAttribute('part', `row ${branch ? 'branch-row' : 'leaf-row'}${selected === path ? ' selected-row' : ''}`);
|
|
235
371
|
if (this.#errors.has(node)) row.title = String(this.#errors.get(node));
|
|
@@ -247,10 +383,12 @@ export const Tree = defineComponent({
|
|
|
247
383
|
chevronPath.setAttribute('stroke-linecap', 'round'); chevronPath.setAttribute('stroke-linejoin', 'round');
|
|
248
384
|
chevron.append(chevronPath); expander.append(chevron);
|
|
249
385
|
expander.addEventListener('click', event => {
|
|
250
|
-
event.stopPropagation();
|
|
386
|
+
event.stopPropagation(); entry.focus(); toggle();
|
|
251
387
|
});
|
|
252
388
|
} else expander.className = 'spacer';
|
|
253
389
|
const caption = this.ownerDocument.createElement('span'); caption.className = 'caption';
|
|
390
|
+
const badge = this.ownerDocument.createElement('span'); badge.className = 'badge';
|
|
391
|
+
badge.setAttribute('part', 'badge');
|
|
254
392
|
this.#dragRows.set(row, {item: node, path, caption});
|
|
255
393
|
caption.setAttribute('part', 'caption');
|
|
256
394
|
const icon = this.ownerDocument.createElement('span');
|
|
@@ -258,7 +396,22 @@ export const Tree = defineComponent({
|
|
|
258
396
|
icon.setAttribute('aria-hidden', 'true');
|
|
259
397
|
icon.setAttribute('part', `icon ${branch ? 'branch-icon' : 'leaf-icon'}`);
|
|
260
398
|
|
|
261
|
-
|
|
399
|
+
let check;
|
|
400
|
+
if (this.#checksEnabled) {
|
|
401
|
+
check = this.ownerDocument.createElement('input');
|
|
402
|
+
check.type = 'checkbox'; check.className = 'checkbox'; check.setAttribute('part', 'checkbox');
|
|
403
|
+
check.tabIndex = -1;
|
|
404
|
+
check.addEventListener('click', event => {
|
|
405
|
+
event.stopPropagation();
|
|
406
|
+
if (typeof this.parameters.onChecked === 'string') {
|
|
407
|
+
const result = this.#context.callLogic(this.parameters.onChecked, {item: node, path});
|
|
408
|
+
if (result instanceof Promise) throw new TypeError('tree onChecked must be synchronous');
|
|
409
|
+
if (result === false) { this.#schedule(); return; }
|
|
410
|
+
}
|
|
411
|
+
this.#check(node, check.checked, true);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
row.append(expander, check || icon, badge, caption); entry.append(row);
|
|
262
415
|
const group = branch ? (children ? build(children, path, entry) : this.ownerDocument.createElement('ul')) : null;
|
|
263
416
|
if (group) { group.className = 'group'; group.setAttribute('role', 'group'); group.setAttribute('part', 'group'); }
|
|
264
417
|
if (group) entry.append(group);
|
|
@@ -290,12 +443,24 @@ export const Tree = defineComponent({
|
|
|
290
443
|
}
|
|
291
444
|
const present = () => {
|
|
292
445
|
const opened = this.#opened(node), selected = this.#selectedPath === path;
|
|
446
|
+
const value = node.attr.badge;
|
|
447
|
+
if (value != null && typeof value !== 'string' && typeof value !== 'number') {
|
|
448
|
+
throw new TypeError('tree badge must be text or a number');
|
|
449
|
+
}
|
|
450
|
+
const color = node.attr.badge_color;
|
|
451
|
+
if (color != null && typeof color !== 'string') throw new TypeError('tree badge_color must be text');
|
|
452
|
+
badge.textContent = value == null ? '' : String(value);
|
|
453
|
+
badge.hidden = value == null || value === '';
|
|
454
|
+
badge.style.backgroundColor = color ?? '';
|
|
455
|
+
badge.toggleAttribute('data-colored', color != null && color !== '');
|
|
293
456
|
const keywords = {item: node, path, opened, selected};
|
|
294
457
|
const attribute = this.parameters.labelAttribute;
|
|
295
|
-
const label = this.parameters.
|
|
458
|
+
const label = this.parameters.internalNames && node.getAttr('fieldpath') ? node.label
|
|
459
|
+
: this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
|
|
296
460
|
: attribute !== null ? (Object.hasOwn(node.attr, attribute) ? node.attr[attribute] : node.label)
|
|
297
461
|
: this.parameters.labelCb !== null ? this.#call('labelCb', keywords) : node.label;
|
|
298
|
-
this.#setCaption(caption, label, this.parameters.
|
|
462
|
+
this.#setCaption(caption, label, !(this.parameters.internalNames && node.getAttr('fieldpath')) &&
|
|
463
|
+
(this.parameters.getLabel !== null || (attribute === null && this.parameters.labelCb !== null)));
|
|
299
464
|
if (this.#searchText) this.#highlight(caption);
|
|
300
465
|
const labelClass = this.parameters.getLabelClass !== null ? this.#call('getLabelClass', keywords)
|
|
301
466
|
: node.attr[opened ? 'labelClassOpened' : 'labelClassClosed'] || node.attr.labelClass || '';
|
|
@@ -307,12 +472,20 @@ export const Tree = defineComponent({
|
|
|
307
472
|
...(selected ? ['selected'] : []), ...(branch ? [opened ? 'opened' : 'closed'] : []),
|
|
308
473
|
...(this.#loading.has(node) ? ['loading'] : []), ...(this.#errors.has(node) ? ['error'] : [])].join(' ');
|
|
309
474
|
entry.setAttribute('part', ['node', branch ? 'branch' : 'leaf', ...nodeClasses].join(' '));
|
|
310
|
-
const customIcon = this.parameters.getIconClass !== null;
|
|
475
|
+
const customIcon = !check && this.parameters.getIconClass !== null;
|
|
311
476
|
const iconClasses = customIcon ? this.#classes(this.#call('getIconClass', keywords))
|
|
312
477
|
: [branch ? 'branch-icon' : 'leaf-icon', ...(branch ? [opened ? 'opened-icon' : 'closed-icon'] : [])];
|
|
313
478
|
icon.className = ['icon', ...iconClasses].join(' ');
|
|
314
479
|
icon.setAttribute('part', ['icon', ...iconClasses].join(' '));
|
|
315
480
|
icon.hidden = customIcon && iconClasses.length === 0;
|
|
481
|
+
if (check) {
|
|
482
|
+
const value = node.attr.checked;
|
|
483
|
+
check.checked = value === true || value === 'disabled:on';
|
|
484
|
+
check.indeterminate = value === -1;
|
|
485
|
+
entry.setAttribute('aria-checked', value === -1 ? 'mixed' : String(check.checked));
|
|
486
|
+
check.disabled = value === 'disabled:on' || value === 'disabled:off';
|
|
487
|
+
check.setAttribute('aria-label', caption.textContent);
|
|
488
|
+
}
|
|
316
489
|
if (branch) expander.setAttribute('aria-label', `${opened ? 'Collapse' : 'Expand'} ${caption.textContent}`);
|
|
317
490
|
};
|
|
318
491
|
this.#presentations.set(path, present);
|
|
@@ -331,8 +504,7 @@ export const Tree = defineComponent({
|
|
|
331
504
|
if (expanded.has(node)) {
|
|
332
505
|
expanded.delete(node);
|
|
333
506
|
if (this.#searchText) this.#searchClosed.add(node);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
507
|
+
} else {
|
|
336
508
|
if (this.#searchText) { this.#searchClosed.delete(node); this.#searchOpen.add(node); } else this.#expand(node);
|
|
337
509
|
if (node.resolver !== null) this.#resolve(node);
|
|
338
510
|
}
|
|
@@ -353,7 +525,8 @@ export const Tree = defineComponent({
|
|
|
353
525
|
if (!this.#opened(node)) toggle(); else target = group.firstElementChild;
|
|
354
526
|
} else if (event.key === 'ArrowLeft') {
|
|
355
527
|
if (branch && this.#opened(node)) toggle(); else target = parent;
|
|
356
|
-
} else if (event.key === '
|
|
528
|
+
} else if (event.key === ' ' && check) check.click();
|
|
529
|
+
else if (event.key === 'Enter' || event.key === ' ') this.#select(path);
|
|
357
530
|
else return;
|
|
358
531
|
event.preventDefault(); event.stopPropagation();
|
|
359
532
|
if (target) { this.#tabStop(target); target.focus(); }
|
|
@@ -363,13 +536,19 @@ export const Tree = defineComponent({
|
|
|
363
536
|
}
|
|
364
537
|
return list;
|
|
365
538
|
};
|
|
366
|
-
|
|
539
|
+
const root = build(this.#store, '', null);
|
|
540
|
+
if (this.parameters.favorites !== null) {
|
|
541
|
+
if (!(this.parameters.favorites instanceof Bag)) throw new TypeError('tree favorites must be a Bag');
|
|
542
|
+
if (this.parameters.favorites.length) root.prepend(this.#buildFavorites(this.parameters.favorites, selected));
|
|
543
|
+
}
|
|
544
|
+
this.control.replaceChildren(root);
|
|
367
545
|
this.control.setAttribute('aria-busy', String(this.#searching));
|
|
368
546
|
if (this.#searchText) {
|
|
369
547
|
const visible = new Set(), matches = [];
|
|
370
548
|
this.#searchOpen.clear();
|
|
371
549
|
for (const [path, row] of this.#rows) {
|
|
372
550
|
const caption = row.firstElementChild.querySelector('.caption'), item = items.get(path);
|
|
551
|
+
if (item.ancestors.some(ancestor => ancestor.attr.loop === true)) continue;
|
|
373
552
|
const match = caption.textContent.toLowerCase().includes(this.#searchText);
|
|
374
553
|
if (match) matches.push(caption);
|
|
375
554
|
if (match || this.#errors.has(item.node) || this.#loading.has(item.node)) {
|
|
@@ -384,12 +563,233 @@ export const Tree = defineComponent({
|
|
|
384
563
|
this.control.append(status);
|
|
385
564
|
}
|
|
386
565
|
this.#tabStop(focused ?? selected);
|
|
387
|
-
if (
|
|
566
|
+
if (focusedFavorite) this.#favoriteRows.get(focusedFavorite)?.focus();
|
|
567
|
+
else if (focusedFavoritesGroup) root.querySelector('[data-favorites-group]')?.focus();
|
|
568
|
+
else if (focused) this.#rows.get(focused)?.focus();
|
|
569
|
+
if (reveal) queueMicrotask(() => this.#loadSelection(reveal));
|
|
570
|
+
}
|
|
571
|
+
#buildFavorites(favorites, selected) {
|
|
572
|
+
const document = this.ownerDocument;
|
|
573
|
+
const group = document.createElement('li');
|
|
574
|
+
group.className = 'node branch'; group.setAttribute('role', 'treeitem');
|
|
575
|
+
group.dataset.favoritesGroup = 'true'; group.tabIndex = -1;
|
|
576
|
+
const row = document.createElement('div'); row.className = 'row';
|
|
577
|
+
const button = document.createElement('button'); button.type = 'button'; button.className = 'expander'; button.tabIndex = -1;
|
|
578
|
+
const heart = document.createElement('span'); heart.textContent = '♡'; heart.setAttribute('aria-hidden', 'true');
|
|
579
|
+
const title = document.createElement('span'); title.className = 'caption'; title.textContent = this.parameters.favoritesLabel;
|
|
580
|
+
const children = document.createElement('ul'); children.className = 'group'; children.setAttribute('role', 'group');
|
|
581
|
+
const sync = () => {
|
|
582
|
+
group.setAttribute('aria-expanded', String(this.#favoritesOpen));
|
|
583
|
+
button.textContent = this.#favoritesOpen ? '▾' : '▸';
|
|
584
|
+
button.setAttribute('aria-label', `${this.#favoritesOpen ? 'Collapse' : 'Expand'} ${this.parameters.favoritesLabel}`);
|
|
585
|
+
children.hidden = !this.#favoritesOpen;
|
|
586
|
+
};
|
|
587
|
+
const toggle = () => { this.#favoritesOpen = !this.#favoritesOpen; sync(); };
|
|
588
|
+
button.addEventListener('click', event => { event.stopPropagation(); toggle(); group.focus(); });
|
|
589
|
+
row.addEventListener('click', toggle);
|
|
590
|
+
group.addEventListener('focus', () => this.#rowActions()?.clearRowContext());
|
|
591
|
+
group.addEventListener('keydown', event => {
|
|
592
|
+
if (event.target !== group) return;
|
|
593
|
+
if (event.key === 'ArrowRight') { if (!this.#favoritesOpen) toggle(); else children.firstElementChild?.focus(); }
|
|
594
|
+
else if (event.key === 'ArrowLeft') { if (this.#favoritesOpen) toggle(); }
|
|
595
|
+
else if (event.key === 'Enter' || event.key === ' ') toggle();
|
|
596
|
+
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
597
|
+
const visible = this.#visible(), index = visible.indexOf(group);
|
|
598
|
+
visible[index + (event.key === 'ArrowDown' ? 1 : -1)]?.focus();
|
|
599
|
+
} else return;
|
|
600
|
+
event.preventDefault(); event.stopPropagation();
|
|
601
|
+
});
|
|
602
|
+
row.append(button, heart, title); group.append(row, children);
|
|
603
|
+
for (const node of favorites.getNodes()) {
|
|
604
|
+
const path = node.getAttr('originalPath');
|
|
605
|
+
const entry = document.createElement('li'); entry.className = 'node leaf'; entry.setAttribute('role', 'treeitem');
|
|
606
|
+
entry.dataset.favoritePath = path; entry.tabIndex = -1; entry.setAttribute('aria-selected', String(selected === path));
|
|
607
|
+
const favoriteRow = document.createElement('div'); favoriteRow.className = 'row';
|
|
608
|
+
const spacer = document.createElement('span'); spacer.className = 'spacer';
|
|
609
|
+
const icon = document.createElement('span'); icon.className = 'icon'; icon.setAttribute('aria-hidden', 'true');
|
|
610
|
+
const badge = document.createElement('span'); badge.className = 'badge'; badge.setAttribute('part', 'badge');
|
|
611
|
+
const badgeValue = node.getAttr('badge'); badge.textContent = badgeValue == null ? '' : String(badgeValue);
|
|
612
|
+
badge.hidden = badgeValue == null || badgeValue === '';
|
|
613
|
+
const color = node.getAttr('badge_color'); if (color) { badge.style.backgroundColor = color; badge.setAttribute('data-colored', ''); }
|
|
614
|
+
const caption = document.createElement('span'); caption.className = 'caption';
|
|
615
|
+
caption.textContent = node.getAttr(this.parameters.internalNames ? 'fieldpath' : 'fullcaption');
|
|
616
|
+
favoriteRow.title = node.getAttr('fieldpath');
|
|
617
|
+
favoriteRow.draggable = this.parameters.draggable;
|
|
618
|
+
this.#dragRows.set(favoriteRow, {item: node, path, caption});
|
|
619
|
+
favoriteRow.addEventListener('pointerenter', () => this.#showRowActions(favoriteRow, node, path));
|
|
620
|
+
entry.addEventListener('focus', () => this.#showRowActions(favoriteRow, node, path));
|
|
621
|
+
favoriteRow.addEventListener('click', () => this.#selectFavorite(path));
|
|
622
|
+
entry.addEventListener('keydown', event => {
|
|
623
|
+
if (event.target !== entry) return;
|
|
624
|
+
if (event.key === 'Enter' || event.key === ' ') this.#selectFavorite(path);
|
|
625
|
+
else if (event.key === 'ArrowLeft') group.focus();
|
|
626
|
+
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
627
|
+
const visible = this.#visible(), index = visible.indexOf(entry);
|
|
628
|
+
visible[index + (event.key === 'ArrowDown' ? 1 : -1)]?.focus();
|
|
629
|
+
} else return;
|
|
630
|
+
event.preventDefault(); event.stopPropagation();
|
|
631
|
+
});
|
|
632
|
+
favoriteRow.append(spacer, icon, badge, caption); entry.append(favoriteRow); children.append(entry);
|
|
633
|
+
this.#favoriteRows.set(path, entry);
|
|
634
|
+
}
|
|
635
|
+
sync();
|
|
636
|
+
return group;
|
|
637
|
+
}
|
|
638
|
+
#selectFavorite(path) {
|
|
639
|
+
if (this.parameters.selectedPath === path) this.retrySelection();
|
|
640
|
+
else this.#context.writeParameter('selectedPath', path);
|
|
641
|
+
}
|
|
642
|
+
async #loadSelection({requested, version, store}) {
|
|
643
|
+
const current = () => this.isConnected && this.#selectionVersion === version &&
|
|
644
|
+
this.#store === store && this.parameters.selectedPath === requested && this.#selectedPath === requested;
|
|
645
|
+
const parts = requested.split('.');
|
|
646
|
+
let bag = store;
|
|
647
|
+
for (const part of parts.slice(0, -1)) {
|
|
648
|
+
if (!current()) return;
|
|
649
|
+
const node = bag.getNode(part);
|
|
650
|
+
if (!node) return;
|
|
651
|
+
if (node.resolver === null && !(node.staticValue instanceof Bag)) return;
|
|
652
|
+
if (!current() || bag.getNode(part) !== node) return;
|
|
653
|
+
this.#expand(node);
|
|
654
|
+
this.#schedule();
|
|
655
|
+
if (node.resolver !== null && !(node.staticValue instanceof Bag)) await this.#resolve(node);
|
|
656
|
+
if (!current() || bag.getNode(part) !== node || !(node.staticValue instanceof Bag)) return;
|
|
657
|
+
bag = node.staticValue;
|
|
658
|
+
}
|
|
659
|
+
if (current() && bag.getNode(parts.at(-1))) this.#schedule();
|
|
660
|
+
}
|
|
661
|
+
#check(node, value, publish) {
|
|
662
|
+
if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') return;
|
|
663
|
+
const children = this.#resolutions.get(node) ?? node.getValue();
|
|
664
|
+
if (children instanceof Promise && !this.#resolutions.has(node)) {
|
|
665
|
+
this.#errors.delete(node);
|
|
666
|
+
const pending = children.catch(error => {
|
|
667
|
+
this.#errors.set(node, error);
|
|
668
|
+
this.#expanded.delete(node);
|
|
669
|
+
}).finally(() => {
|
|
670
|
+
if (this.#resolutions.get(node) === pending) this.#resolutions.delete(node);
|
|
671
|
+
this.#schedule();
|
|
672
|
+
});
|
|
673
|
+
this.#resolutions.set(node, pending);
|
|
674
|
+
}
|
|
675
|
+
if (this.parameters.checkChildren && children instanceof Bag) {
|
|
676
|
+
if (node.resolver !== null) this.#checkedBags.set(node, children);
|
|
677
|
+
this.#applyChecked(children, value);
|
|
678
|
+
}
|
|
679
|
+
node.setAttr({checked: this.parameters.checkChildren && children instanceof Bag && children.length
|
|
680
|
+
? this.#checkStatus(children) : value});
|
|
681
|
+
if (this.parameters.checkChildren) {
|
|
682
|
+
for (let parent = node.parentBag.parentNode; parent && parent !== this.#store.parentNode; parent = parent.parentBag.parentNode) {
|
|
683
|
+
parent.setAttr({checked: this.#checkStatus(parent.staticValue)});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (publish) this.#publishChecked();
|
|
687
|
+
}
|
|
688
|
+
#applyChecked(bag, value, onlyNew = false) {
|
|
689
|
+
for (const child of bag.getNodes()) {
|
|
690
|
+
if (onlyNew && this.#checkedNodes.has(child)) continue;
|
|
691
|
+
this.#checkedNodes.add(child);
|
|
692
|
+
if (child.attr.checked === 'disabled:on' || child.attr.checked === 'disabled:off') continue;
|
|
693
|
+
const children = child.staticValue;
|
|
694
|
+
if (children instanceof Bag && children.length) {
|
|
695
|
+
if (child.resolver !== null) this.#checkedBags.set(child, children);
|
|
696
|
+
this.#applyChecked(children, value);
|
|
697
|
+
child.setAttr({checked: this.#checkStatus(children)});
|
|
698
|
+
} else child.setAttr({checked: value});
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
#syncChecked(bag, ancestors = new Set(), loaded = []) {
|
|
702
|
+
if (ancestors.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
703
|
+
ancestors.add(bag);
|
|
704
|
+
let changed = false;
|
|
705
|
+
for (const node of bag.getNodes()) {
|
|
706
|
+
this.#checkedNodes.add(node);
|
|
707
|
+
const children = node.staticValue;
|
|
708
|
+
if (!(children instanceof Bag)) continue;
|
|
709
|
+
let childChanged = false;
|
|
710
|
+
if (node.resolver !== null && this.#checkedBags.get(node) !== children) {
|
|
711
|
+
this.#checkedBags.set(node, children);
|
|
712
|
+
loaded.push(children);
|
|
713
|
+
if (typeof node.attr.checked === 'boolean') {
|
|
714
|
+
this.#applyChecked(children, node.attr.checked);
|
|
715
|
+
childChanged = true;
|
|
716
|
+
}
|
|
717
|
+
} else if (typeof node.attr.checked === 'boolean' && children.getNodes().some(child => !this.#checkedNodes.has(child))) {
|
|
718
|
+
this.#applyChecked(children, node.attr.checked, true);
|
|
719
|
+
loaded.push(children);
|
|
720
|
+
childChanged = true;
|
|
721
|
+
}
|
|
722
|
+
childChanged = this.#syncChecked(children, ancestors, loaded) || childChanged;
|
|
723
|
+
if (childChanged && children.length && node.attr.checked !== 'disabled:on' && node.attr.checked !== 'disabled:off') {
|
|
724
|
+
node.setAttr({checked: this.#checkStatus(children)});
|
|
725
|
+
}
|
|
726
|
+
changed ||= childChanged;
|
|
727
|
+
}
|
|
728
|
+
ancestors.delete(bag);
|
|
729
|
+
return changed;
|
|
730
|
+
}
|
|
731
|
+
#publishChecked(preservePending = false) {
|
|
732
|
+
const paths = [];
|
|
733
|
+
const visit = (bag, prefix) => {
|
|
734
|
+
for (const child of bag.getNodes()) {
|
|
735
|
+
const path = prefix ? `${prefix}.${child.label}` : child.label;
|
|
736
|
+
const children = child.staticValue;
|
|
737
|
+
if (children instanceof Bag && children.length) {
|
|
738
|
+
if (!this.parameters.checkChildren && child.attr.checked === true) paths.push(path);
|
|
739
|
+
visit(children, path);
|
|
740
|
+
} else if (child.attr.checked === true) paths.push(path);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
visit(this.#store, '');
|
|
744
|
+
if (preservePending && this.#pathsEnabled) {
|
|
745
|
+
for (const path of (this.parameters.checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean)) {
|
|
746
|
+
if (!paths.includes(path) && this.#pendingCheckedPath(path)) paths.push(path);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
this.#checkedPaths = paths.join(this.parameters.checkedPaths_joiner);
|
|
750
|
+
this.#context.writeParameter('checkedPaths', this.#checkedPaths);
|
|
751
|
+
this.#schedule();
|
|
752
|
+
}
|
|
753
|
+
#pendingCheckedPath(path) {
|
|
754
|
+
const parts = path.split('.');
|
|
755
|
+
let bag = this.#store;
|
|
756
|
+
for (let index = 0; index < parts.length; index++) {
|
|
757
|
+
const node = bag.getNode(parts[index]);
|
|
758
|
+
if (!node) return false;
|
|
759
|
+
if (index === parts.length - 1) return false;
|
|
760
|
+
if (node.resolver !== null && !(node.staticValue instanceof Bag)) return true;
|
|
761
|
+
if (!(node.staticValue instanceof Bag)) return false;
|
|
762
|
+
bag = node.staticValue;
|
|
763
|
+
}
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
#checkStatus(bag) {
|
|
767
|
+
const values = bag.getNodes().map(child => child.attr.checked === 'disabled:on' ? true
|
|
768
|
+
: child.attr.checked === 'disabled:off' || child.attr.checked == null ? false : child.attr.checked);
|
|
769
|
+
return values.every(value => value === true) ? true
|
|
770
|
+
: values.every(value => value === false) ? false : -1;
|
|
388
771
|
}
|
|
389
772
|
#classes(value) {
|
|
390
773
|
if (typeof value !== 'string') throw new TypeError('Tree classes must be a string');
|
|
391
774
|
return value.split(/\s+/).filter(Boolean);
|
|
392
775
|
}
|
|
776
|
+
#rowActions() {
|
|
777
|
+
const bars = this.querySelectorAll(':scope > gramlot-row-actions');
|
|
778
|
+
if (bars.length > 1) throw new Error('tree accepts one rowActions bar');
|
|
779
|
+
return bars[0] ?? null;
|
|
780
|
+
}
|
|
781
|
+
#showRowActions(row, item, path) {
|
|
782
|
+
const bar = this.#rowActions();
|
|
783
|
+
if (!bar || bar.contains(this.ownerDocument.activeElement)) return;
|
|
784
|
+
const hostBox = this.getBoundingClientRect(), rowBox = row.getBoundingClientRect();
|
|
785
|
+
bar.setRowContext(item, path);
|
|
786
|
+
bar.style.position = 'absolute';
|
|
787
|
+
bar.style.top = `${rowBox.top - hostBox.top}px`;
|
|
788
|
+
bar.style.left = bar.parameters.position === 'start' ? `${rowBox.left - hostBox.left}px` : 'auto';
|
|
789
|
+
bar.style.right = bar.parameters.position === 'end' ? `${hostBox.right - rowBox.right}px` : 'auto';
|
|
790
|
+
bar.style.zIndex = '1';
|
|
791
|
+
bar.hidden = false;
|
|
792
|
+
}
|
|
393
793
|
#call(name, keywords) {
|
|
394
794
|
const result = this.#context.callLogic(this.parameters[name], keywords);
|
|
395
795
|
if (name === 'labelCb' || name === 'getLabel') {
|
|
@@ -451,4 +851,4 @@ export const Tree = defineComponent({
|
|
|
451
851
|
}
|
|
452
852
|
}
|
|
453
853
|
});
|
|
454
|
-
export default defineCollection({name: 'tree', components: [Tree]});
|
|
854
|
+
export default defineCollection({name: 'tree', components: [Tree, RowActions]});
|