@gramlot/gramlot 0.3.6 → 0.3.8
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/gramlot.js +731 -637
- package/dist/gramlot.min.js +24 -405
- package/package.json +6 -4
- package/src/binding/ask-dialog.js +1 -1
- package/src/binding/remote-resolver.js +52 -0
- package/src/binding/router.js +11 -4
- package/src/binding/rpc-resolver.js +14 -93
- package/src/binding/runtime.js +23 -15
- package/src/builder/gramlot-builder.js +2 -2
- package/src/builder/source.js +1 -1
- package/src/components/border-container.js +46 -23
- package/src/components/registry.js +6 -4
- package/src/components/tree.js +350 -0
- package/src/handlers/subscriptions-handler.js +2 -2
- package/src/index-page-runtime.d.ts +7 -8
- package/src/index-page-runtime.js +100 -396
- package/src/index.d.ts +3 -0
- package/src/index.js +2 -1
- package/src/navigation-resolver.d.ts +6 -0
- package/src/navigation-resolver.js +60 -0
- package/src/renderer/attributes.js +2 -1
- package/src/renderer/drag-drop-policy.js +48 -0
- package/src/renderer/drag-drop.js +213 -0
- package/src/renderer/drag-preparation.js +33 -0
- package/src/renderer/gramlot-renderer.d.ts +18 -0
- package/src/renderer/gramlot-renderer.js +38 -0
- package/src/server/frame-page.d.ts +12 -0
- package/src/server/frame-page.js +23 -0
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index-page.d.ts +10 -14
- package/src/server/index-page.js +26 -95
- package/src/server/page.d.ts +2 -0
- package/src/server/page.js +1 -0
- package/src/view/html.js +6 -1
- package/tools/gramlot-tools-inspector.js +16 -9
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/** Bag hierarchy, lazy branch expansion, captions and path selection. */
|
|
2
|
+
import {Bag} from '@gramlot/gramlot';
|
|
3
|
+
import createDOMPurify from 'dompurify';
|
|
4
|
+
import {defineComponent, defineCollection} from './registry.js';
|
|
5
|
+
import {Container} from './container.js';
|
|
6
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
7
|
+
|
|
8
|
+
export const Tree = defineComponent({
|
|
9
|
+
name: 'tree', tag: 'gramlot-tree', base: Container, sourceContext: true, bagStore: true, dragSource: true,
|
|
10
|
+
parameters: {
|
|
11
|
+
storepath: {dtype: 'T'},
|
|
12
|
+
draggable: {dtype: 'B', default: false, binding: 'read'},
|
|
13
|
+
labelAttribute: {dtype: 'T', nullable: true, default: null, binding: 'read'},
|
|
14
|
+
hideValues: {dtype: 'B', default: false, binding: 'read'},
|
|
15
|
+
labelCb: {dtype: 'T', nullable: true, default: null},
|
|
16
|
+
getLabel: {dtype: 'T', nullable: true, default: null},
|
|
17
|
+
getLabelClass: {dtype: 'T', nullable: true, default: null},
|
|
18
|
+
getIconClass: {dtype: 'T', nullable: true, default: null},
|
|
19
|
+
selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
|
|
20
|
+
autoCollapse: {dtype: 'B', default: false, binding: 'read'},
|
|
21
|
+
selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'}
|
|
22
|
+
},
|
|
23
|
+
implementation: Base => class extends Base {
|
|
24
|
+
#store;
|
|
25
|
+
#sanitizer;
|
|
26
|
+
#context;
|
|
27
|
+
#expanded = new Set();
|
|
28
|
+
#rows = new Map();
|
|
29
|
+
#dragRows = new WeakMap();
|
|
30
|
+
#presentations = new Map();
|
|
31
|
+
#requestedPath;
|
|
32
|
+
#selectedPath = null;
|
|
33
|
+
#scheduled = false;
|
|
34
|
+
#loading = new Set();
|
|
35
|
+
#errors = new Map();
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
this.#sanitizer = createDOMPurify(this.ownerDocument.defaultView);
|
|
40
|
+
this.control.replaceChildren();
|
|
41
|
+
this.control.setAttribute('role', 'tree');
|
|
42
|
+
this.control.setAttribute('aria-label', 'Tree');
|
|
43
|
+
this.control.classList.add('tree');
|
|
44
|
+
this.control.setAttribute('part', 'tree');
|
|
45
|
+
const style = this.ownerDocument.createElement('style');
|
|
46
|
+
style.textContent = `
|
|
47
|
+
.control-box{overflow:auto;padding:4px;min-height:32px}
|
|
48
|
+
ul{list-style:none;margin:0;padding:0} ul ul{padding-inline-start:20px}
|
|
49
|
+
.row{display:flex;align-items:center;min-height:var(--gramlot-tree-row-height,28px);gap:4px;border-radius:3px;cursor:default}
|
|
50
|
+
.row:hover{background:var(--gramlot-tree-hover-background,var(--gramlot-field-readonly-background,#f2f4f7))}
|
|
51
|
+
.canBeDropped{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}
|
|
52
|
+
.cannotBeDropped{outline:2px dashed currentColor;outline-offset:-2px}.draggedItem{opacity:.75}
|
|
53
|
+
[role=treeitem][aria-selected=true]>.row{background:var(--gramlot-tree-selected-background,#e3edff);
|
|
54
|
+
color:var(--gramlot-tree-selected-color,#214f91)}
|
|
55
|
+
[role=treeitem]:focus{outline:none}
|
|
56
|
+
[role=treeitem]:focus-visible>.row{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}
|
|
57
|
+
button{border:0;background:transparent;color:inherit;width:24px;height:24px;padding:0;font:inherit;cursor:pointer}
|
|
58
|
+
.spacer{width:24px;flex:none}.caption{min-width:0;overflow-wrap:anywhere}
|
|
59
|
+
.icon{width:16px;height:16px;flex:none;background:currentColor;opacity:.7;mask:center/contain no-repeat;
|
|
60
|
+
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")}
|
|
61
|
+
.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")}
|
|
62
|
+
.opened-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 19V4h7l3 3h8v3M3 20l3-9h16l-3 9z'/%3E%3C/svg%3E")}
|
|
63
|
+
.loading>.row{opacity:.65}.error>.row .caption{text-decoration:underline dotted}
|
|
64
|
+
[hidden]{display:none}`;
|
|
65
|
+
this.shadowRoot.append(style);
|
|
66
|
+
}
|
|
67
|
+
setSourceContext(context) { this.#context = context; }
|
|
68
|
+
/** Read only the rendered row and its BagNode; never request a resolver value. */
|
|
69
|
+
getDragContext(event) {
|
|
70
|
+
for (const element of event.composedPath()) {
|
|
71
|
+
const row = this.#dragRows.get(element);
|
|
72
|
+
if (!row) continue;
|
|
73
|
+
const {item, path, caption} = row;
|
|
74
|
+
return {element, item, path, dragValues: {
|
|
75
|
+
'text/plain': caption.textContent,
|
|
76
|
+
nodeattr: {...item.getAttr()},
|
|
77
|
+
treenode: {fullpath: item.fullpath, relpath: path}
|
|
78
|
+
}};
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
setStoreBag(bag) {
|
|
83
|
+
if (!(bag instanceof Bag)) throw new TypeError('tree storepath must resolve to a Bag');
|
|
84
|
+
if (bag !== this.#store) {
|
|
85
|
+
this.#store = bag;
|
|
86
|
+
this.#expanded.clear();
|
|
87
|
+
this.#errors.clear();
|
|
88
|
+
this.#requestedPath = undefined;
|
|
89
|
+
}
|
|
90
|
+
this.#schedule();
|
|
91
|
+
}
|
|
92
|
+
projectAttributes(attrs, adapt) {
|
|
93
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
94
|
+
this.#schedule();
|
|
95
|
+
return rest;
|
|
96
|
+
}
|
|
97
|
+
connectedCallback() { this.#schedule(); }
|
|
98
|
+
#schedule() {
|
|
99
|
+
if (this.#scheduled) return;
|
|
100
|
+
this.#scheduled = true;
|
|
101
|
+
queueMicrotask(() => {
|
|
102
|
+
this.#scheduled = false;
|
|
103
|
+
if (this.isConnected && this.#store) this.#render();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
#render() {
|
|
107
|
+
const focused = this.shadowRoot.activeElement?.closest('[role=treeitem]')?.dataset.path;
|
|
108
|
+
const items = new Map(), seen = new Set();
|
|
109
|
+
const visit = (bag, prefix, ancestors) => {
|
|
110
|
+
if (seen.has(bag)) throw new TypeError('tree requires an acyclic Bag store');
|
|
111
|
+
seen.add(bag);
|
|
112
|
+
for (const node of bag.getNodes()) {
|
|
113
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
114
|
+
const value = node.staticValue; // Rendering never evaluates resolvers.
|
|
115
|
+
items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
|
|
116
|
+
if (value instanceof Bag) visit(value, path, [...ancestors, node]);
|
|
117
|
+
}
|
|
118
|
+
seen.delete(bag);
|
|
119
|
+
};
|
|
120
|
+
visit(this.#store, '', []);
|
|
121
|
+
const identities = new Set([...items.values()].map(item => item.node));
|
|
122
|
+
for (const node of this.#expanded) if (!identities.has(node)) this.#expanded.delete(node);
|
|
123
|
+
for (const node of this.#errors.keys()) if (!identities.has(node)) this.#errors.delete(node);
|
|
124
|
+
const requested = this.parameters.selectedPath;
|
|
125
|
+
if (requested !== this.#requestedPath) {
|
|
126
|
+
this.#requestedPath = requested;
|
|
127
|
+
this.#selectedPath = requested;
|
|
128
|
+
for (const node of items.get(requested)?.ancestors ?? []) this.#expand(node);
|
|
129
|
+
}
|
|
130
|
+
const selected = this.#selectedPath;
|
|
131
|
+
this.#rows.clear();
|
|
132
|
+
this.#dragRows = new WeakMap();
|
|
133
|
+
this.#presentations.clear();
|
|
134
|
+
const branchSync = new Map();
|
|
135
|
+
const build = (bag, prefix, parent) => {
|
|
136
|
+
const list = this.ownerDocument.createElement('ul');
|
|
137
|
+
list.className = 'group'; list.setAttribute('part', 'group');
|
|
138
|
+
list.setAttribute('role', 'group');
|
|
139
|
+
for (const node of bag.getNodes()) {
|
|
140
|
+
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
141
|
+
const {children} = items.get(path);
|
|
142
|
+
const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
|
|
143
|
+
const branch = children !== null ? children.length > 0
|
|
144
|
+
: scalar || (node.resolver !== null && node.attr.child_count !== 0);
|
|
145
|
+
const entry = this.ownerDocument.createElement('li');
|
|
146
|
+
entry.className = `node ${branch ? 'branch' : 'leaf'}`;
|
|
147
|
+
entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
|
|
148
|
+
entry.classList.toggle('loading', this.#loading.has(node));
|
|
149
|
+
entry.classList.toggle('error', this.#errors.has(node));
|
|
150
|
+
entry.setAttribute('aria-busy', String(this.#loading.has(node)));
|
|
151
|
+
entry.setAttribute('role', 'treeitem');
|
|
152
|
+
entry.setAttribute('aria-selected', String(selected === path));
|
|
153
|
+
entry.classList.toggle('selected', selected === path);
|
|
154
|
+
entry.dataset.path = path;
|
|
155
|
+
entry.tabIndex = -1;
|
|
156
|
+
const row = this.ownerDocument.createElement('div'); row.className = 'row';
|
|
157
|
+
row.draggable = this.parameters.draggable;
|
|
158
|
+
row.setAttribute('part', `row ${branch ? 'branch-row' : 'leaf-row'}${selected === path ? ' selected-row' : ''}`);
|
|
159
|
+
if (this.#errors.has(node)) row.title = String(this.#errors.get(node));
|
|
160
|
+
const expander = this.ownerDocument.createElement(branch ? 'button' : 'span');
|
|
161
|
+
expander.setAttribute('part', branch ? 'expander' : 'spacer');
|
|
162
|
+
if (branch) {
|
|
163
|
+
expander.className = 'expander';
|
|
164
|
+
expander.type = 'button'; expander.tabIndex = -1;
|
|
165
|
+
expander.addEventListener('click', event => {
|
|
166
|
+
event.stopPropagation(); toggle(); entry.focus();
|
|
167
|
+
});
|
|
168
|
+
} else expander.className = 'spacer';
|
|
169
|
+
const caption = this.ownerDocument.createElement('span'); caption.className = 'caption';
|
|
170
|
+
this.#dragRows.set(row, {item: node, path, caption});
|
|
171
|
+
caption.setAttribute('part', 'caption');
|
|
172
|
+
const icon = this.ownerDocument.createElement('span');
|
|
173
|
+
icon.className = `icon ${branch ? 'branch-icon' : 'leaf-icon'}`;
|
|
174
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
175
|
+
icon.setAttribute('part', `icon ${branch ? 'branch-icon' : 'leaf-icon'}`);
|
|
176
|
+
|
|
177
|
+
row.append(expander, icon, caption); entry.append(row);
|
|
178
|
+
const group = branch ? (children ? build(children, path, entry) : this.ownerDocument.createElement('ul')) : null;
|
|
179
|
+
if (group) { group.className = 'group'; group.setAttribute('role', 'group'); group.setAttribute('part', 'group'); }
|
|
180
|
+
if (group) entry.append(group);
|
|
181
|
+
if (scalar) {
|
|
182
|
+
const valueEntry = this.ownerDocument.createElement('li');
|
|
183
|
+
valueEntry.className = 'value-node'; valueEntry.setAttribute('part', 'value-node');
|
|
184
|
+
valueEntry.setAttribute('role', 'treeitem'); valueEntry.setAttribute('aria-selected', 'false');
|
|
185
|
+
valueEntry.tabIndex = -1; valueEntry.dataset.path = path; valueEntry.dataset.valueRow = 'true';
|
|
186
|
+
const valueRow = this.ownerDocument.createElement('div');
|
|
187
|
+
valueRow.className = 'row value-row'; valueRow.setAttribute('part', 'row value-row');
|
|
188
|
+
const spacer = this.ownerDocument.createElement('span'); spacer.className = 'spacer';
|
|
189
|
+
const text = this.ownerDocument.createElement('span');
|
|
190
|
+
text.className = 'value'; text.setAttribute('part', 'value'); text.textContent = String(node.staticValue);
|
|
191
|
+
valueRow.append(spacer, text); valueEntry.append(valueRow); group.append(valueEntry);
|
|
192
|
+
valueRow.addEventListener('click', () => this.#select(path));
|
|
193
|
+
valueEntry.addEventListener('keydown', event => {
|
|
194
|
+
const visible = this.#visible(), index = visible.indexOf(valueEntry);
|
|
195
|
+
let target;
|
|
196
|
+
if (event.key === 'ArrowUp') target = visible[index - 1];
|
|
197
|
+
else if (event.key === 'ArrowDown') target = visible[index + 1];
|
|
198
|
+
else if (event.key === 'Home') target = visible[0];
|
|
199
|
+
else if (event.key === 'End') target = visible.at(-1);
|
|
200
|
+
else if (event.key === 'ArrowLeft') target = entry;
|
|
201
|
+
else if (event.key === 'Enter' || event.key === ' ') this.#select(path);
|
|
202
|
+
else return;
|
|
203
|
+
event.preventDefault(); event.stopPropagation();
|
|
204
|
+
if (target) { this.#tabStop(target); target.focus(); }
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const present = () => {
|
|
208
|
+
const opened = this.#expanded.has(node), selected = this.#selectedPath === path;
|
|
209
|
+
const keywords = {item: node, path, opened, selected};
|
|
210
|
+
const attribute = this.parameters.labelAttribute;
|
|
211
|
+
const label = this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
|
|
212
|
+
: attribute !== null ? (Object.hasOwn(node.attr, attribute) ? node.attr[attribute] : node.label)
|
|
213
|
+
: this.parameters.labelCb !== null ? this.#call('labelCb', keywords) : node.label;
|
|
214
|
+
this.#setCaption(caption, label, this.parameters.getLabel !== null || (attribute === null && this.parameters.labelCb !== null));
|
|
215
|
+
const labelClass = this.parameters.getLabelClass !== null ? this.#call('getLabelClass', keywords)
|
|
216
|
+
: node.attr[opened ? 'labelClassOpened' : 'labelClassClosed'] || node.attr.labelClass || '';
|
|
217
|
+
const labelClasses = [...this.#classes(labelClass), ...(selected ? this.#classes(this.parameters.selectedLabelClass) : [])];
|
|
218
|
+
caption.className = ['caption', ...labelClasses].join(' ');
|
|
219
|
+
caption.setAttribute('part', ['caption', ...labelClasses].join(' '));
|
|
220
|
+
const nodeClasses = this.#classes(node.attr.node_class ?? '');
|
|
221
|
+
entry.className = ['node', branch ? 'branch' : 'leaf', ...nodeClasses,
|
|
222
|
+
...(selected ? ['selected'] : []), ...(branch ? [opened ? 'opened' : 'closed'] : []),
|
|
223
|
+
...(this.#loading.has(node) ? ['loading'] : []), ...(this.#errors.has(node) ? ['error'] : [])].join(' ');
|
|
224
|
+
entry.setAttribute('part', ['node', branch ? 'branch' : 'leaf', ...nodeClasses].join(' '));
|
|
225
|
+
const customIcon = this.parameters.getIconClass !== null;
|
|
226
|
+
const iconClasses = customIcon ? this.#classes(this.#call('getIconClass', keywords))
|
|
227
|
+
: [branch ? 'branch-icon' : 'leaf-icon', ...(branch ? [opened ? 'opened-icon' : 'closed-icon'] : [])];
|
|
228
|
+
icon.className = ['icon', ...iconClasses].join(' ');
|
|
229
|
+
icon.setAttribute('part', ['icon', ...iconClasses].join(' '));
|
|
230
|
+
icon.hidden = customIcon && iconClasses.length === 0;
|
|
231
|
+
if (branch) expander.setAttribute('aria-label', `${opened ? 'Collapse' : 'Expand'} ${caption.textContent}`);
|
|
232
|
+
};
|
|
233
|
+
this.#presentations.set(path, present);
|
|
234
|
+
const sync = () => {
|
|
235
|
+
const opened = this.#expanded.has(node);
|
|
236
|
+
entry.setAttribute('aria-expanded', String(opened));
|
|
237
|
+
entry.classList.toggle('opened', opened);
|
|
238
|
+
entry.classList.toggle('closed', !opened);
|
|
239
|
+
icon.classList.toggle('opened-icon', opened);
|
|
240
|
+
icon.setAttribute('part', `icon branch-icon ${opened ? 'opened-icon' : 'closed-icon'}`);
|
|
241
|
+
expander.textContent = opened ? '▾' : '▸';
|
|
242
|
+
group.hidden = !opened;
|
|
243
|
+
present();
|
|
244
|
+
};
|
|
245
|
+
const toggle = () => {
|
|
246
|
+
if (this.#expanded.has(node)) this.#expanded.delete(node);
|
|
247
|
+
else {
|
|
248
|
+
this.#expand(node);
|
|
249
|
+
if (node.resolver !== null) this.#resolve(node);
|
|
250
|
+
}
|
|
251
|
+
for (const update of branchSync.values()) update();
|
|
252
|
+
this.#tabStop(path);
|
|
253
|
+
};
|
|
254
|
+
if (branch) { branchSync.set(node, sync); sync(); } else present();
|
|
255
|
+
row.addEventListener('click', () => this.#select(path));
|
|
256
|
+
entry.addEventListener('keydown', event => {
|
|
257
|
+
if (event.target !== entry) return;
|
|
258
|
+
const visible = this.#visible(), index = visible.indexOf(entry);
|
|
259
|
+
let target;
|
|
260
|
+
if (event.key === 'ArrowDown') target = visible[index + 1];
|
|
261
|
+
else if (event.key === 'ArrowUp') target = visible[index - 1];
|
|
262
|
+
else if (event.key === 'Home') target = visible[0];
|
|
263
|
+
else if (event.key === 'End') target = visible.at(-1);
|
|
264
|
+
else if (event.key === 'ArrowRight' && branch) {
|
|
265
|
+
if (!this.#expanded.has(node)) toggle(); else target = group.firstElementChild;
|
|
266
|
+
} else if (event.key === 'ArrowLeft') {
|
|
267
|
+
if (branch && this.#expanded.has(node)) toggle(); else target = parent;
|
|
268
|
+
} else if (event.key === 'Enter' || event.key === ' ') this.#select(path);
|
|
269
|
+
else return;
|
|
270
|
+
event.preventDefault(); event.stopPropagation();
|
|
271
|
+
if (target) { this.#tabStop(target); target.focus(); }
|
|
272
|
+
});
|
|
273
|
+
this.#rows.set(path, entry);
|
|
274
|
+
list.append(entry);
|
|
275
|
+
}
|
|
276
|
+
return list;
|
|
277
|
+
};
|
|
278
|
+
this.control.replaceChildren(build(this.#store, '', null));
|
|
279
|
+
this.#tabStop(focused ?? selected);
|
|
280
|
+
if (focused) this.#rows.get(focused)?.focus();
|
|
281
|
+
}
|
|
282
|
+
#classes(value) {
|
|
283
|
+
if (typeof value !== 'string') throw new TypeError('Tree classes must be a string');
|
|
284
|
+
return value.split(/\s+/).filter(Boolean);
|
|
285
|
+
}
|
|
286
|
+
#call(name, keywords) {
|
|
287
|
+
const result = this.#context.callLogic(this.parameters[name], keywords);
|
|
288
|
+
if (name === 'labelCb' || name === 'getLabel') {
|
|
289
|
+
if (!result || typeof result !== 'object' || Object.keys(result).length !== 1 ||
|
|
290
|
+
!(Object.hasOwn(result, 'text') && typeof result.text === 'string' ||
|
|
291
|
+
Object.hasOwn(result, 'html') && typeof result.html === 'string')) {
|
|
292
|
+
throw new TypeError(`tree ${name} must return {text: string} or {html: string} synchronously`);
|
|
293
|
+
}
|
|
294
|
+
} else if (typeof result !== 'string') throw new TypeError(`tree ${name} must return a string synchronously`);
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
#setCaption(caption, label, computed) {
|
|
298
|
+
if (computed && Object.hasOwn(label, 'html')) {
|
|
299
|
+
caption.replaceChildren(this.#sanitizer.sanitize(label.html, {
|
|
300
|
+
USE_PROFILES: {html: true}, FORBID_TAGS: ['style', 'form', 'input', 'button', 'select', 'textarea'],
|
|
301
|
+
RETURN_DOM_FRAGMENT: true
|
|
302
|
+
}));
|
|
303
|
+
} else caption.textContent = computed ? label.text : label;
|
|
304
|
+
}
|
|
305
|
+
#visible() {
|
|
306
|
+
return [...this.control.querySelectorAll('[role=treeitem]')].filter(row => !row.closest('[hidden]'));
|
|
307
|
+
}
|
|
308
|
+
#expand(node) {
|
|
309
|
+
if (this.parameters.autoCollapse) {
|
|
310
|
+
for (const sibling of node.parentBag.getNodes()) {
|
|
311
|
+
if (sibling !== node) this.#expanded.delete(sibling);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this.#expanded.add(node);
|
|
315
|
+
}
|
|
316
|
+
async #resolve(node) {
|
|
317
|
+
if (this.#loading.has(node)) return;
|
|
318
|
+
this.#loading.add(node);
|
|
319
|
+
this.#errors.delete(node);
|
|
320
|
+
this.#schedule();
|
|
321
|
+
try {
|
|
322
|
+
await node.getValue();
|
|
323
|
+
} catch (error) {
|
|
324
|
+
this.#errors.set(node, error);
|
|
325
|
+
this.#expanded.delete(node);
|
|
326
|
+
} finally {
|
|
327
|
+
this.#loading.delete(node);
|
|
328
|
+
this.#schedule();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
#tabStop(path) {
|
|
332
|
+
const visible = this.#visible(), target = typeof path === 'string' || path == null
|
|
333
|
+
? visible.find(row => row.dataset.path === path) ?? visible[0] : path;
|
|
334
|
+
for (const row of this.control.querySelectorAll('[role=treeitem]')) row.tabIndex = row === target ? 0 : -1;
|
|
335
|
+
}
|
|
336
|
+
#select(path) {
|
|
337
|
+
this.#selectedPath = path;
|
|
338
|
+
for (const [key, row] of this.#rows) {
|
|
339
|
+
row.setAttribute('aria-selected', String(key === path));
|
|
340
|
+
row.classList.toggle('selected', key === path);
|
|
341
|
+
this.#presentations.get(key)();
|
|
342
|
+
row.firstElementChild.setAttribute('part', `row ${row.classList.contains('branch') ? 'branch-row' : 'leaf-row'}${key === path ? ' selected-row' : ''}`);
|
|
343
|
+
}
|
|
344
|
+
this.#tabStop(path);
|
|
345
|
+
this.#rows.get(path).focus();
|
|
346
|
+
this.#context.writeParameter('selectedPath', path);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
export default defineCollection({name: 'tree', components: [Tree]});
|
|
@@ -54,7 +54,7 @@ export class SubscriptionsHandler extends Handler {
|
|
|
54
54
|
const forward = topic.parent || topic.iframe !== undefined ? this.#frames.prepare(topic, payload) : null;
|
|
55
55
|
if (Object.hasOwn(topic, 'nodeId')) {
|
|
56
56
|
const node = this.gramlot.src.binding.nodeIds.get(topic.nodeId);
|
|
57
|
-
if (!node) throw new Error(`
|
|
57
|
+
if (!node) throw new Error(`nodeId not found: ${topic.nodeId}`);
|
|
58
58
|
return this.publishNode(node, topic.topic, payload);
|
|
59
59
|
}
|
|
60
60
|
this.#deliver(topic.topic, payload);
|
|
@@ -66,7 +66,7 @@ export class SubscriptionsHandler extends Handler {
|
|
|
66
66
|
node = sourceTarget(node);
|
|
67
67
|
const binding = this.gramlot.src.binding.bindingFor(node);
|
|
68
68
|
if (!binding || binding.closed) throw new Error('Topic target is not an active Source node of this page');
|
|
69
|
-
let id = node.getAttr('
|
|
69
|
+
let id = node.getAttr('nodeId');
|
|
70
70
|
if (id == null) {
|
|
71
71
|
if (!this.#nodeIds.has(node)) this.#nodeIds.set(node, `gramlot-self-${++this.#sequence}`);
|
|
72
72
|
id = this.#nodeIds.get(node);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import type {Bag, BagNode} from '@genrojs/bag';
|
|
2
|
+
export interface IndexEntry {url: string; path: string; node: BagNode; pane: any; title: string; loading: boolean;}
|
|
1
3
|
export function mountIndexPage(renderer: any, root: any,
|
|
2
|
-
onSelection?: (entries: Map<string,
|
|
3
|
-
prepareEntry?: (entry:
|
|
4
|
-
options?: {
|
|
5
|
-
onLoad?: (
|
|
6
|
-
|
|
7
|
-
export class IndexLogic {
|
|
8
|
-
indexMount(node: any, args: {shell_id: string}): void;
|
|
9
|
-
}
|
|
4
|
+
onSelection?: (entries: Map<string, IndexEntry>, active: string | null) => void,
|
|
5
|
+
prepareEntry?: (entry: IndexEntry) => void,
|
|
6
|
+
options?: {state?: Bag; createEntry?: (entry: IndexEntry) => Promise<void>;
|
|
7
|
+
onLoad?: (url: string, status: string, error?: Error) => void}): {entries: Map<string, IndexEntry>; dispose(): void};
|
|
8
|
+
export class IndexLogic {indexMount(node: any, args: {shell_id: string}): void;}
|
|
10
9
|
export const THEME_READY: string;
|
|
11
10
|
export const THEME_SET: string;
|
|
12
11
|
export const THEMES: Set<string>;
|