@gramlot/gramlot 0.3.27 → 0.3.30
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/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- 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/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +51 -30
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +258 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -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/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +11 -11
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +572 -176
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +12 -4
- package/src/binding/grid-struct.js +2 -2
- package/src/binding/runtime.js +10 -0
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +22 -3
- package/src/builder/source.js +24 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +6 -4
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +44 -0
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-structure.js +10 -2
- package/src/components/grid-styles.js +23 -0
- package/src/components/grid.js +52 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/menus.js +19 -11
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/visual-editor.js +17 -17
- package/src/stores/bag-collection-view.js +79 -17
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
package/src/components/tree.js
CHANGED
|
@@ -53,13 +53,17 @@ export const Tree = defineComponent({
|
|
|
53
53
|
excludeRoot: {dtype: 'T', nullable: true, default: null, binding: 'read'},
|
|
54
54
|
labelCb: {dtype: 'T', nullable: true, default: null},
|
|
55
55
|
getLabel: {dtype: 'T', nullable: true, default: null},
|
|
56
|
+
labelState: {dtype: 'X', nullable: true, default: null, binding: 'read'},
|
|
56
57
|
getLabelClass: {dtype: 'T', nullable: true, default: null},
|
|
57
58
|
getIconClass: {dtype: 'T', nullable: true, default: null},
|
|
58
59
|
selectedLabelClass: {dtype: 'T', default: '', binding: 'read'},
|
|
59
60
|
searchText: {dtype: 'T', default: '', binding: 'read'},
|
|
61
|
+
searchEager: {dtype: 'B', default: true, binding: 'read'},
|
|
62
|
+
searchAttributes: {dtype: 'T', default: '', binding: 'read'},
|
|
60
63
|
favorites: {dtype: 'X', nullable: true, default: null, binding: 'read'},
|
|
61
64
|
favoritesLabel: {dtype: 'T', default: 'Favorites', binding: 'read'},
|
|
62
65
|
autoCollapse: {dtype: 'B', default: false, binding: 'read'},
|
|
66
|
+
resolveLazy: {dtype: 'B', default: true, binding: 'read'},
|
|
63
67
|
selectedPath: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
64
68
|
onChecked: {dtype: ['B', 'T'], nullable: true, default: null},
|
|
65
69
|
checkedPaths: {dtype: 'T', nullable: true, default: null, binding: 'twoWay'},
|
|
@@ -146,13 +150,17 @@ export const Tree = defineComponent({
|
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
152
|
setSourceContext(context) { this.#context = context; }
|
|
153
|
+
get storeBag() { return this.#store; }
|
|
149
154
|
/** Read only the rendered row and its BagNode; never request a resolver value. */
|
|
150
155
|
getDragContext(event) {
|
|
151
156
|
for (const element of event.composedPath()) {
|
|
152
157
|
const row = this.#dragRows.get(element);
|
|
153
158
|
if (!row) continue;
|
|
154
159
|
const {item, path, caption} = row;
|
|
155
|
-
|
|
160
|
+
const rect = element.getBoundingClientRect();
|
|
161
|
+
const fraction = rect.height ? (event.clientY - rect.top) / rect.height : 0.5;
|
|
162
|
+
const placement = fraction < 0.25 ? 'before' : fraction > 0.75 ? 'after' : 'inside';
|
|
163
|
+
return {element, item, path, placement, dragValues: {
|
|
156
164
|
'text/plain': caption.textContent,
|
|
157
165
|
nodeattr: {...item.getAttr()},
|
|
158
166
|
treenode: {fullpath: item.fullpath, relpath: path}
|
|
@@ -179,7 +187,13 @@ export const Tree = defineComponent({
|
|
|
179
187
|
projectAttributes(attrs, adapt) {
|
|
180
188
|
this.#pathsEnabled = Object.hasOwn(attrs, 'checkedPaths');
|
|
181
189
|
this.#checksEnabled = this.#pathsEnabled || Boolean(attrs.onChecked);
|
|
190
|
+
const previousEager = this.parameters?.searchEager;
|
|
191
|
+
const previousResolve = this.parameters?.resolveLazy;
|
|
182
192
|
const rest = super.projectAttributes(attrs, adapt);
|
|
193
|
+
if (previousEager !== this.parameters.searchEager || previousResolve !== this.parameters.resolveLazy) {
|
|
194
|
+
this.#resetSearch();
|
|
195
|
+
this.#searchText = this.#searchInput.toLowerCase();
|
|
196
|
+
}
|
|
183
197
|
if (this.#excludedRoot !== this.parameters.excludeRoot) {
|
|
184
198
|
this.#excludedRoot = this.parameters.excludeRoot;
|
|
185
199
|
this.#resetSearch();
|
|
@@ -210,7 +224,8 @@ export const Tree = defineComponent({
|
|
|
210
224
|
#opened(node) { return this.#searchText ? this.#searchOpen.has(node) : this.#expanded.has(node); }
|
|
211
225
|
async #searchBranches() {
|
|
212
226
|
const version = this.#searchVersion, store = this.#store;
|
|
213
|
-
const current = () => this.isConnected && version === this.#searchVersion && store === this.#store
|
|
227
|
+
const current = () => this.isConnected && version === this.#searchVersion && store === this.#store
|
|
228
|
+
&& this.parameters.searchEager && this.parameters.resolveLazy;
|
|
214
229
|
this.#searching = true;
|
|
215
230
|
const visit = async (bag, ancestors = new Set()) => {
|
|
216
231
|
if (!current()) return;
|
|
@@ -220,6 +235,7 @@ export const Tree = defineComponent({
|
|
|
220
235
|
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
221
236
|
if (!current()) return;
|
|
222
237
|
if (node.attr.loop === true) continue;
|
|
238
|
+
if (node.resolver !== null && !this.parameters.resolveLazy) continue;
|
|
223
239
|
if (node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node)) {
|
|
224
240
|
this.#searchAttempted.add(node);
|
|
225
241
|
await this.#resolve(node, true);
|
|
@@ -272,14 +288,14 @@ export const Tree = defineComponent({
|
|
|
272
288
|
for (const node of bag.getNodes()) {
|
|
273
289
|
if (bag === this.#store && node.label === this.parameters.excludeRoot) continue;
|
|
274
290
|
const path = prefix ? `${prefix}.${node.label}` : node.label;
|
|
275
|
-
const value = node.
|
|
291
|
+
const value = node.resolver !== null && !this.parameters.resolveLazy ? null : node.staticValue;
|
|
276
292
|
items.set(path, {node, ancestors, children: value instanceof Bag ? value : null});
|
|
277
293
|
if (value instanceof Bag) visit(value, path, [...ancestors, node]);
|
|
278
294
|
}
|
|
279
295
|
seen.delete(bag);
|
|
280
296
|
};
|
|
281
297
|
visit(this.#store, '', []);
|
|
282
|
-
if (this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
|
|
298
|
+
if (this.parameters.searchEager && this.parameters.resolveLazy && this.#searchText && this.#searchTimer === null && !this.#searching && [...items.values()].some(({node}) =>
|
|
283
299
|
node.attr.loop !== true && node.resolver !== null && node.resolver.expired && !this.#searchAttempted.has(node))) {
|
|
284
300
|
void this.#searchBranches();
|
|
285
301
|
}
|
|
@@ -351,7 +367,7 @@ export const Tree = defineComponent({
|
|
|
351
367
|
const {children} = items.get(path);
|
|
352
368
|
const scalar = children === null && !this.parameters.hideValues && (node.resolver === null || !node.resolver.expired);
|
|
353
369
|
const branch = children !== null ? children.length > 0
|
|
354
|
-
: scalar || (node.resolver !== null && node.attr.child_count !== 0);
|
|
370
|
+
: scalar || (node.resolver !== null && this.parameters.resolveLazy && node.attr.child_count !== 0);
|
|
355
371
|
const entry = this.ownerDocument.createElement('li');
|
|
356
372
|
entry.className = `node ${branch ? 'branch' : 'leaf'}`;
|
|
357
373
|
entry.setAttribute('part', `node ${branch ? 'branch' : 'leaf'}`);
|
|
@@ -453,7 +469,7 @@ export const Tree = defineComponent({
|
|
|
453
469
|
badge.hidden = value == null || value === '';
|
|
454
470
|
badge.style.backgroundColor = color ?? '';
|
|
455
471
|
badge.toggleAttribute('data-colored', color != null && color !== '');
|
|
456
|
-
const keywords = {item: node, path, opened, selected};
|
|
472
|
+
const keywords = {item: node, path, opened, selected, state: this.parameters.labelState};
|
|
457
473
|
const attribute = this.parameters.labelAttribute;
|
|
458
474
|
const label = this.parameters.internalNames && node.getAttr('fieldpath') ? node.label
|
|
459
475
|
: this.parameters.getLabel !== null ? this.#call('getLabel', keywords)
|
|
@@ -549,7 +565,12 @@ export const Tree = defineComponent({
|
|
|
549
565
|
for (const [path, row] of this.#rows) {
|
|
550
566
|
const caption = row.firstElementChild.querySelector('.caption'), item = items.get(path);
|
|
551
567
|
if (item.ancestors.some(ancestor => ancestor.attr.loop === true)) continue;
|
|
552
|
-
const
|
|
568
|
+
const metadata = this.parameters.searchAttributes.split(',').map(name => name.trim()).filter(Boolean)
|
|
569
|
+
.flatMap(name => {
|
|
570
|
+
const value = item.node.getAttr(name);
|
|
571
|
+
return Array.isArray(value) ? value.filter(part => typeof part === 'string') : typeof value === 'string' ? [value] : [];
|
|
572
|
+
});
|
|
573
|
+
const match = [caption.textContent, ...metadata].some(text => text.toLowerCase().includes(this.#searchText));
|
|
553
574
|
if (match) matches.push(caption);
|
|
554
575
|
if (match || this.#errors.has(item.node) || this.#loading.has(item.node)) {
|
|
555
576
|
visible.add(item.node);
|
|
@@ -648,6 +669,7 @@ export const Tree = defineComponent({
|
|
|
648
669
|
if (!current()) return;
|
|
649
670
|
const node = bag.getNode(part);
|
|
650
671
|
if (!node) return;
|
|
672
|
+
if (node.resolver !== null && !this.parameters.resolveLazy) return;
|
|
651
673
|
if (node.resolver === null && !(node.staticValue instanceof Bag)) return;
|
|
652
674
|
if (!current() || bag.getNode(part) !== node) return;
|
|
653
675
|
this.#expand(node);
|
|
@@ -774,7 +796,7 @@ export const Tree = defineComponent({
|
|
|
774
796
|
return value.split(/\s+/).filter(Boolean);
|
|
775
797
|
}
|
|
776
798
|
#rowActions() {
|
|
777
|
-
const bars = this.
|
|
799
|
+
const bars = [...this.children].filter(child => child.localName === 'gramlot-row-actions');
|
|
778
800
|
if (bars.length > 1) throw new Error('tree accepts one rowActions bar');
|
|
779
801
|
return bars[0] ?? null;
|
|
780
802
|
}
|
|
@@ -90,12 +90,14 @@ export function TypedEditor(HTMLElement) {
|
|
|
90
90
|
this.checkValue(value);
|
|
91
91
|
return this.validateCandidate(value, accepted => {
|
|
92
92
|
this.checkValue(accepted);
|
|
93
|
+
this.acceptDraft(accepted, this.#selection ? null : this.control.value, this.#policy ?? this.context());
|
|
93
94
|
this.#value = accepted; this.#selection = null; this.#dirty = false;
|
|
94
95
|
// Preserve accepted spelling unless validation normalized the candidate.
|
|
95
96
|
if (!this.#focused || !this.sameControlValue(value, accepted)) { this.#policy = null; this.display(); }
|
|
96
97
|
});
|
|
97
98
|
} catch (error) { if (this.pageContext.form) this.pageContext.formParseError(error.message); this.error(error.message); return {ok: false}; }
|
|
98
99
|
}
|
|
100
|
+
acceptDraft(value, text, context) {}
|
|
99
101
|
restoreFormDraft(text) { this.#dirty = true; this.#policy = this.context(); this.control.value = text; }
|
|
100
102
|
restoreFormValue(value) { this.#dirty = false; this.#policy = null; this.#selection = null; this.error(''); this.writeControlValue(value); this.display(); }
|
|
101
103
|
display() {
|
|
@@ -234,14 +236,23 @@ export const dateEditor = Base => class extends Base {
|
|
|
234
236
|
static validationValueCheck() { return checkCivilDate; }
|
|
235
237
|
checkValue(value) { checkCivilDate(value); }
|
|
236
238
|
editText(value, context) { return this.pageContext.format(value, {...context, pattern: 'short'}); }
|
|
237
|
-
|
|
239
|
+
dateExpression(text, context) {
|
|
238
240
|
const now = new Date();
|
|
239
241
|
const workdate = this.parameters.workdate ?? `${now.getFullYear()}-${pad(now.getMonth()+1)}-${pad(now.getDate())}`;
|
|
240
242
|
const options = {locale: context.locale, workdate};
|
|
241
243
|
const result = parseDateExpression(text, options);
|
|
242
244
|
if (!result.ok) throw new Error(result.error.message);
|
|
243
|
-
if (result.kind !== 'date') throw new Error('Enter one complete date, not a period.');
|
|
244
|
-
|
|
245
|
+
if (result.kind !== 'date' && !this.parameters.period_to) throw new Error('Enter one complete date, not a period.');
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
acceptDraft(value, text, context) {
|
|
249
|
+
if (!text?.trim() || !this.parameters.period_to) return;
|
|
250
|
+
const result = this.dateExpression(text, context);
|
|
251
|
+
if (result.kind === 'period') this.pageContext.periodOutput(this.parameters.period_to, new Date(result.end + 'T00:00:00Z'));
|
|
252
|
+
}
|
|
253
|
+
parse(text, context) {
|
|
254
|
+
const result = this.dateExpression(text, context);
|
|
255
|
+
const [y, m, d] = (result.kind === 'date' ? result.date : result.start).split('-').map(Number);
|
|
245
256
|
const value = new Date(0); value.setUTCFullYear(y, m - 1, d); return value;
|
|
246
257
|
}
|
|
247
258
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {randomId} from '../random-id.js';
|
|
2
|
+
|
|
3
|
+
/** One optional Vizabi instance; the Gramlot Bag owns authored state. */
|
|
4
|
+
export class VizabiSession {
|
|
5
|
+
constructor(library, element, view, configuration) {
|
|
6
|
+
this.library=library; this.configuration=configuration; this.element=element;
|
|
7
|
+
const {Vizabi,BubbleChart,mobx}=library;
|
|
8
|
+
if(!Number.isInteger(configuration.getItem('year'))||typeof configuration.getItem('playing')!=='boolean'||!Number.isFinite(configuration.getItem('speed'))||configuration.getItem('speed')<=0)throw new TypeError('Vizabi requires an integer year, Boolean playing and positive speed in milliseconds');
|
|
9
|
+
const keys=['entityField','timeField','xField','yField','sizeField','colorField'];
|
|
10
|
+
const fields=Object.fromEntries(keys.map(key=>[key,configuration.getItem(key)]));
|
|
11
|
+
for(const [key,value] of Object.entries(fields))if(typeof value!=='string'||!value)throw new TypeError(`${key} requires a field name`);
|
|
12
|
+
if(Object.entries(fields).some(([key,value])=>value==='name'&&key!=='entityField'))throw new TypeError('The Vizabi entity catalogue reserves name for the entity display name');
|
|
13
|
+
const rows=view.getRows().map(node=>Object.fromEntries([...new Set(Object.values(fields))].map(field=>[field,view.value(node,field)])));
|
|
14
|
+
const identities=new Set();
|
|
15
|
+
for(const row of rows) {
|
|
16
|
+
if(typeof row[fields.entityField]!=='string'||!Number.isInteger(row[fields.timeField]))throw new TypeError('Vizabi trial requires text entities and integer years');
|
|
17
|
+
const key=JSON.stringify([row[fields.entityField],row[fields.timeField]]);
|
|
18
|
+
if(identities.has(key))throw new TypeError('Vizabi requires one prepared row per entity and year');
|
|
19
|
+
identities.add(key);
|
|
20
|
+
for(const field of [fields.xField,fields.yField,fields.sizeField])if(typeof row[field]!=='number'||!Number.isFinite(row[field]))throw new TypeError(`${field} requires finite numbers`);
|
|
21
|
+
if(row[fields.sizeField]<0)throw new TypeError('Bubble size cannot be negative');
|
|
22
|
+
if(typeof row[fields.colorField]!=='string')throw new TypeError('Bubble color requires a text category');
|
|
23
|
+
}
|
|
24
|
+
// Vizabi's entity catalogue requires its reserved display-name property.
|
|
25
|
+
for(const row of rows)row.name=row[fields.entityField];
|
|
26
|
+
if(!rows.length)throw new TypeError('No data to display');
|
|
27
|
+
this.id=`bubble_${randomId()}`;this.legendId=`legend_${randomId()}`;this.sourceId=`data_${randomId()}`;
|
|
28
|
+
const defaults=JSON.parse(JSON.stringify(BubbleChart.DEFAULT_MODEL).replaceAll('markers.bubble',`markers.${this.id}`).replaceAll('markers.legend',`markers.${this.legendId}`));
|
|
29
|
+
const bubble=defaults.bubble;
|
|
30
|
+
bubble.data={source:this.sourceId,space:[fields.entityField,fields.timeField]};
|
|
31
|
+
for(const [encoding,field] of Object.entries({x:fields.xField,y:fields.yField,size:fields.sizeField,color:fields.colorField,label:fields.entityField}))bubble.encoding[encoding].data={concept:field,constant:null};
|
|
32
|
+
bubble.encoding.label.data={modelType:'entityPropertyDataConfig',concept:'name'};
|
|
33
|
+
bubble.requiredEncodings=['x','y','size','color','label'];
|
|
34
|
+
bubble.encoding.y.modelType='baseType';
|
|
35
|
+
bubble.encoding.y.scale.type='linear';
|
|
36
|
+
bubble.encoding.frame={modelType:'frame',data:{concept:fields.timeField},value:String(configuration.getItem('year')),speed:configuration.getItem('speed'),splash:false,loop:true};
|
|
37
|
+
const models=Vizabi({dataSources:{[this.sourceId]:{values:rows,keyConcepts:[fields.entityField,fields.timeField],dtypes:{[fields.timeField]:'year'}}},markers:{[this.id]:bubble,[this.legendId]:defaults.legend}});
|
|
38
|
+
this.models=models;
|
|
39
|
+
this.frame=models.markers[this.id].encoding.frame;
|
|
40
|
+
this.tool=new BubbleChart({Vizabi,placeholder:element,model:{config:models.config,dataSources:models.dataSources,markers:{bubble:models.markers[this.id],legend:models.markers[this.legendId]}},locale:{id:'en',resolve:{en:library.locale},placeholder:element},layout:{placeholder:element},ui:{buttons:{buttons:[]},dialogs:{dialogs:{sidebar:[],popup:[]}}}});
|
|
41
|
+
this.release=mobx.reaction(()=>{const marker=models.markers[this.id];return [marker.state==='fulfilled'?this.frame.value.getUTCFullYear():null,this.frame.playing,...['x','y','size','color'].map(key=>marker.encoding[key].data.concept)];},([year,playing,x,y,size,color])=>{
|
|
42
|
+
if(!Number.isFinite(year))return;
|
|
43
|
+
this.writing=true;
|
|
44
|
+
try { for(const [key,value] of Object.entries({xField:x,yField:y,sizeField:size,colorField:color}))if(configuration.getItem(key)!==value)configuration.setItem(key,value);if(configuration.getItem('year')!==year)configuration.setItem('year',year);if(configuration.getItem('playing')!==playing)configuration.setItem('playing',playing); }
|
|
45
|
+
finally {this.writing=false;}
|
|
46
|
+
});
|
|
47
|
+
this.ready=mobx.when(()=>models.markers[this.id].state==='fulfilled',()=>this.update());
|
|
48
|
+
}
|
|
49
|
+
update() {
|
|
50
|
+
|
|
51
|
+
if(this.writing||this.models.markers[this.id].state!=='fulfilled')return;
|
|
52
|
+
const c=this.configuration,f=this.frame;
|
|
53
|
+
this.library.mobx.runInAction(()=>{
|
|
54
|
+
f.setSpeed(c.getItem('speed'));
|
|
55
|
+
if(f.value?.getUTCFullYear()!==c.getItem('year'))f.setValue(String(c.getItem('year')));
|
|
56
|
+
if(f.playing!==c.getItem('playing'))f.setPlaying(c.getItem('playing'));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
resize() { this.tool.services.layout._resizeHandler(); }
|
|
60
|
+
dispose() {
|
|
61
|
+
this.release();this.ready();this.frame.stopPlaying();this.tool.deconstruct();
|
|
62
|
+
const stores=this.library.Vizabi.stores;
|
|
63
|
+
stores.markers.dispose(this.legendId);stores.markers.dispose(this.id);stores.dataSources.dispose(this.sourceId);
|
|
64
|
+
this.element.replaceChildren();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {Bag} from '@gramlot/gramlot';
|
|
2
|
+
import {defineCollection,defineComponent} from '@gramlot/gramlot/components';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {BagCollectionView} from '../stores/bag-collection-view.js';
|
|
5
|
+
import {VizabiSession} from './vizabi-session.js';
|
|
6
|
+
|
|
7
|
+
const VizabiBubble=defineComponent({
|
|
8
|
+
name:'vizabiBubble',tag:'gramlot-vizabi-bubble',base:Container,sourceContext:true,bagStore:true,
|
|
9
|
+
parameters:{storepath:{dtype:'T'},rowMode:{dtype:'T',default:'attributes'},configuration:{dtype:'X',binding:'read'},libraryUrl:{dtype:'T'}},
|
|
10
|
+
implementation:Base=>class extends Base {
|
|
11
|
+
#context;#bag;#signature;#libraryUrl;#configuration;#view;#release;#session;#resize;#revision=0;#active=false;#subscription=Symbol('vizabi-config');#style;#message;#host;
|
|
12
|
+
constructor(){
|
|
13
|
+
super();this.control.replaceChildren();
|
|
14
|
+
this.#style=this.ownerDocument.createElement('style');this.shadowRoot.append(this.#style);
|
|
15
|
+
this.#message=this.ownerDocument.createElement('div');this.#message.setAttribute('role','status');
|
|
16
|
+
this.#host=this.ownerDocument.createElement('div');this.#host.style.cssText='width:100%;height:100%;position:relative;background:white;color:#222';
|
|
17
|
+
this.control.append(this.#message,this.#host);this.control.style.height='100%';
|
|
18
|
+
this.#resize=new this.ownerDocument.defaultView.ResizeObserver(()=>this.#session?.resize());
|
|
19
|
+
}
|
|
20
|
+
setSourceContext(context){this.#context=context;}
|
|
21
|
+
setStoreBag(bag){this.#bag=bag;}
|
|
22
|
+
projectAttributes(attrs,adapt){const result=super.projectAttributes(attrs,adapt);if(this.#active)this.#connect();return result;}
|
|
23
|
+
connectedCallback(){this.#active=true;this.#connect();this.#resize.observe(this.#host);}
|
|
24
|
+
#connect(){
|
|
25
|
+
let changed=this.#libraryUrl!==this.parameters.libraryUrl;this.#libraryUrl=this.parameters.libraryUrl;
|
|
26
|
+
const configuration=this.parameters.configuration;
|
|
27
|
+
if(!(configuration instanceof Bag))throw new TypeError('vizabiBubble requires a configuration Bag');
|
|
28
|
+
if(this.#configuration!==configuration){
|
|
29
|
+
changed=true;
|
|
30
|
+
this.#configuration?.unsubscribe(this.#subscription,{any:true});this.#configuration=configuration;
|
|
31
|
+
configuration.subscribe(this.#subscription,{any:()=>{
|
|
32
|
+
if(this.#session?.writing)return;
|
|
33
|
+
this.#refreshConfiguration();
|
|
34
|
+
}});
|
|
35
|
+
}
|
|
36
|
+
const store=this.#context.sourceNode.rootBuilder.binding.collectionStore(this.#bag,this.parameters.rowMode);
|
|
37
|
+
if(!this.#view){changed=true;this.#view=new BagCollectionView(store);this.#view.connect();this.#release=this.#view.subscribe(()=>this.#render());}
|
|
38
|
+
else if(this.#view.bag!==this.#bag){this.#view.bindStore(store);return;}
|
|
39
|
+
if(changed)this.#signature=null;
|
|
40
|
+
this.#refreshConfiguration();
|
|
41
|
+
}
|
|
42
|
+
#refreshConfiguration(){
|
|
43
|
+
const signature=JSON.stringify(['entityField','timeField','xField','yField','sizeField','colorField'].map(key=>this.#configuration.getItem(key)));
|
|
44
|
+
if(this.#session?.writing){this.#signature=signature;return;}
|
|
45
|
+
if(signature!==this.#signature){this.#signature=signature;this.#render();}
|
|
46
|
+
else this.#session?.update();
|
|
47
|
+
}
|
|
48
|
+
async #render(){
|
|
49
|
+
const revision=++this.#revision;this.#session?.dispose();this.#session=null;
|
|
50
|
+
this.#message.hidden=false;this.#message.textContent='Loading optional Vizabi library…';
|
|
51
|
+
try{
|
|
52
|
+
if(!this.parameters.libraryUrl)throw new Error('Provide libraryUrl to load the optional Vizabi module');
|
|
53
|
+
const library=await import(this.parameters.libraryUrl);
|
|
54
|
+
if(!this.#active||revision!==this.#revision)return;
|
|
55
|
+
this.#style.textContent=library.style+'\n:host{display:block;height:100%;min-height:0}.control-box{height:100%}';
|
|
56
|
+
this.#session=new VizabiSession(library,this.#host,this.#view,this.#configuration);
|
|
57
|
+
this.#message.hidden=true;
|
|
58
|
+
}catch(error){if(revision!==this.#revision)return;this.#message.setAttribute('role','alert');this.#message.textContent=error.message;}
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback(){
|
|
61
|
+
this.#active=false;this.#revision++;this.#resize.disconnect();this.#configuration?.unsubscribe(this.#subscription,{any:true});
|
|
62
|
+
this.#release?.();this.#view?.disconnect();this.#session?.dispose();this.#session=null;this.#view=null;this.#configuration=null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
export default defineCollection({name:'vizabi',components:[VizabiBubble]});
|
|
@@ -6,7 +6,7 @@ export class WindowSurface {
|
|
|
6
6
|
#context; #observer; #scheduled = false; #live = false;
|
|
7
7
|
#open = false; #collapsed = false; #maximized = false; #pending = null; #generation = 0;
|
|
8
8
|
#geometry = null; #gesture = null; #previousFocus = null;
|
|
9
|
-
#resize = () => { if (this.#open) this.#fit(); };
|
|
9
|
+
#resize = () => { if (this.#open && !this.parameters.docked) this.#fit(); };
|
|
10
10
|
constructor(host, root, {modal, validateContent}) {
|
|
11
11
|
this.host = host; this.root = root; this.modal = modal;
|
|
12
12
|
this.validateContent = validateContent;
|
|
@@ -20,6 +20,10 @@ export class WindowSurface {
|
|
|
20
20
|
background:var(--gramlot-surface,Canvas);box-shadow:0 2px 6px #00000014,0 16px 36px #00000029;overflow:hidden;
|
|
21
21
|
max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px)}
|
|
22
22
|
.window-surface dialog[open]{display:flex;flex-direction:column}
|
|
23
|
+
.window-surface dialog[data-docked]{position:relative!important;inset:0!important;width:100%!important;height:100%!important;
|
|
24
|
+
min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;
|
|
25
|
+
border:0;border-radius:0;box-shadow:none;z-index:auto!important}
|
|
26
|
+
.window-surface dialog[data-docked] .titlebar,.window-surface dialog[data-docked] .resize{display:none!important}
|
|
23
27
|
.window-surface dialog[data-maximized]{max-width:100vw;max-height:100dvh;border-radius:0}
|
|
24
28
|
.window-surface dialog::backdrop{background:var(--gramlot-window-backdrop,#0006)}
|
|
25
29
|
.window-surface .titlebar{display:flex;align-items:center;gap:4px;flex:none;min-height:max(32px,var(--gramlot-tab-height,32px));padding:3px 5px 3px 12px;
|
|
@@ -104,7 +108,7 @@ export class WindowSurface {
|
|
|
104
108
|
this.#cancelGesture();this.#geometry=null;this.#collapsed=false;this.#maximized=false;
|
|
105
109
|
}
|
|
106
110
|
if(previous.open!==this.parameters.open) { this.#generation++;this.#pending=null; }
|
|
107
|
-
if(previous.movable!==this.parameters.movable || previous.resizable!==this.parameters.resizable)this.#cancelGesture();
|
|
111
|
+
if(previous.movable!==this.parameters.movable || previous.resizable!==this.parameters.resizable || previous.docked!==this.parameters.docked)this.#cancelGesture();
|
|
108
112
|
}
|
|
109
113
|
this.#schedule();
|
|
110
114
|
}
|
|
@@ -118,14 +122,16 @@ export class WindowSurface {
|
|
|
118
122
|
this.heading.textContent=p.title;this.shell.setAttribute('aria-label',p.title);
|
|
119
123
|
this.closeButton.hidden=!p.closable;this.closeButton.disabled=Boolean(this.#pending);
|
|
120
124
|
this.collapseButton.hidden=!p.collapsible;this.maximizeButton.hidden=!p.maximizable;
|
|
125
|
+
this.shell.toggleAttribute('data-docked', p.docked === true);
|
|
121
126
|
if(!p.open) { this.#close(false);return; }
|
|
122
127
|
if(!this.#open) {
|
|
123
128
|
this.#previousFocus=this.#activeElement();
|
|
124
129
|
this.#collapsed=false;this.#maximized=false;this.body.hidden=false;this.shell.removeAttribute('data-collapsed');
|
|
125
130
|
if(this.modal)this.shell.showModal();else this.shell.show();
|
|
126
|
-
this.#open=true;this.#applySize();this.#fit();this.#raise();
|
|
131
|
+
this.#open=true;if(!p.docked){this.#applySize();this.#fit();this.#raise();}
|
|
127
132
|
this.#context.publish('opened',{});
|
|
128
|
-
} else if(!this.#geometry) { this.#applySize();this.#fit(); }
|
|
133
|
+
} else if(!p.docked && !this.#geometry) { this.#applySize();this.#fit(); }
|
|
134
|
+
if(p.docked) { this.body.hidden=false;this.resizeButton.hidden=true;return; }
|
|
129
135
|
this.#setMaximized(p.maximizable&&p.maximized,false);
|
|
130
136
|
this.#setCollapsed(p.collapsible&&p.collapsed,false);
|
|
131
137
|
if(!p.maximizable && p.maximized)this.#context.writeParameter('maximized',false);
|
|
@@ -156,7 +162,7 @@ export class WindowSurface {
|
|
|
156
162
|
}
|
|
157
163
|
#paint(rect) { for(const key of ['left','top','width','height'])this.shell.style[key]=`${rect[key]}px`; }
|
|
158
164
|
#raise() {
|
|
159
|
-
if(this.modal||!this.#open)return;
|
|
165
|
+
if(this.modal||!this.#open||this.parameters.docked)return;
|
|
160
166
|
// Reserve the page's low stacking levels for layout chrome (splitters/drawers).
|
|
161
167
|
// Modal dialogs and menu popovers remain above these nonmodal windows in the top layer.
|
|
162
168
|
const base=100;
|
|
@@ -175,7 +181,7 @@ export class WindowSurface {
|
|
|
175
181
|
this.#paint(rect);
|
|
176
182
|
const movable=this.parameters.movable&&!this.#maximized;
|
|
177
183
|
this.titlebar.toggleAttribute('data-movable',movable);this.titlebar.tabIndex=movable?0:-1;
|
|
178
|
-
this.titlebar.setAttribute('aria-label',movable?'Move window: use arrow keys':this.parameters.title);
|
|
184
|
+
this.titlebar.setAttribute('aria-label',movable?'Move window: use arrow keys, Home to reset':this.parameters.title);
|
|
179
185
|
this.resizeButton.hidden=this.#collapsed||this.#maximized||!this.parameters.resizable;
|
|
180
186
|
}
|
|
181
187
|
#setMaximized(value,write) {
|
|
@@ -233,7 +239,7 @@ export class WindowSurface {
|
|
|
233
239
|
this.#context.publish('closed',{});
|
|
234
240
|
}
|
|
235
241
|
#startGesture(event,kind) {
|
|
236
|
-
if(event.button!==0||!this.#open||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
|
|
242
|
+
if(event.button!==0||!this.#open||this.parameters.docked||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
|
|
237
243
|
if(kind==='move'&&event.target.closest('button'))return;
|
|
238
244
|
event.preventDefault();this.#cancelGesture();
|
|
239
245
|
const r=this.shell.getBoundingClientRect();
|
|
@@ -271,10 +277,15 @@ export class WindowSurface {
|
|
|
271
277
|
}
|
|
272
278
|
}
|
|
273
279
|
#keyGeometry(event,kind) {
|
|
274
|
-
if(event.target!==event.currentTarget||!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(event.key))return;
|
|
275
|
-
if(this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed))return;
|
|
280
|
+
if(event.target!==event.currentTarget||!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Home'].includes(event.key))return;
|
|
281
|
+
if(this.parameters.docked||this.#maximized||kind==='move'&&!this.parameters.movable||kind==='resize'&&(!this.parameters.resizable||this.#collapsed)||event.key==='Home'&&kind!=='move')return;
|
|
276
282
|
event.preventDefault();event.stopPropagation();
|
|
277
283
|
const r=this.shell.getBoundingClientRect(),step=event.shiftKey?1:10;
|
|
284
|
+
if(event.key==='Home') {
|
|
285
|
+
const x=parseFloat(this.parameters.left),y=parseFloat(this.parameters.top);
|
|
286
|
+
this.#adjust({left:r.left,top:r.top,width:r.width,height:r.height},(Number.isFinite(x)?x:8)-r.left,(Number.isFinite(y)?y:8)-r.top,kind);
|
|
287
|
+
this.#commitGeometry(kind);return;
|
|
288
|
+
}
|
|
278
289
|
this.#adjust({left:r.left,top:r.top,width:r.width,height:r.height},event.key==='ArrowLeft'?-step:event.key==='ArrowRight'?step:0,event.key==='ArrowUp'?-step:event.key==='ArrowDown'?step:0,kind);
|
|
279
290
|
this.#commitGeometry(kind);
|
|
280
291
|
}
|
|
@@ -52,4 +52,4 @@ WindowShell.parameters={
|
|
|
52
52
|
};
|
|
53
53
|
export const Dialog=defineComponent({name:'dialog',tag:'gramlot-dialog',base:WindowShell,sourceContext:true,subTags:'framePane',implementation:Base=>class extends Base{}});
|
|
54
54
|
export const FloatingPane=defineComponent({name:'floatingPane',tag:'gramlot-floating-pane',base:WindowShell,sourceContext:true,subTags:'framePane',
|
|
55
|
-
parameters:{movable:bool(true),resizable:bool(true),collapsible:bool(true)},implementation:Base=>class extends Base{}});
|
|
55
|
+
parameters:{movable:bool(true),resizable:bool(true),collapsible:bool(true),docked:bool(false)},implementation:Base=>class extends Base{}});
|
package/src/gramlot.d.ts
CHANGED
|
@@ -118,6 +118,7 @@ export class Gramlot {
|
|
|
118
118
|
publish(topic: Publication, payload?: Record<string, unknown>): void | Promise<'ok'>;
|
|
119
119
|
/** Subscribe to a local page topic, synchronously in registration order. */
|
|
120
120
|
registerDocument(document:Document):void;
|
|
121
|
+
getCollection(name:string): {readonly name:string; toDocument():unknown; register(window:Window):void} | undefined;
|
|
121
122
|
subscribe(topic: string, callback: (payload: Record<string, unknown>, metadata: {pageId?: string}) => unknown): SubscriptionHandle;
|
|
122
123
|
/** Remove a registration; repeating removal of an owned handle is harmless. */
|
|
123
124
|
unsubscribe(registration: SubscriptionHandle): void;
|
package/src/gramlot.js
CHANGED
|
@@ -71,6 +71,8 @@ export class Gramlot {
|
|
|
71
71
|
registerDocument(document) {
|
|
72
72
|
for (const collection of this.#collections) collection.register(document.defaultView);
|
|
73
73
|
}
|
|
74
|
+
/** The prepared collection already activated by this page. */
|
|
75
|
+
getCollection(name) { return this.#collections.find(collection => collection.name === name); }
|
|
74
76
|
subscribe(topic, callback) { return this._subscriptions.subscribe(topic, callback); }
|
|
75
77
|
unsubscribe(registration) { this._subscriptions.unsubscribe(registration); }
|
|
76
78
|
format(value, options) { return formatValue(value, options, {locale: this.locale, timeZone: this.timeZone}); }
|
|
@@ -43,17 +43,17 @@ export class DeviceHandler extends Handler {
|
|
|
43
43
|
|
|
44
44
|
installData() {
|
|
45
45
|
const {gramlot} = this;
|
|
46
|
-
gramlot.data.setItem('
|
|
47
|
-
gramlot.data.setItem('
|
|
46
|
+
gramlot.data.setItem('_gramlot.device.database', null, {status: 'idle', error: null});
|
|
47
|
+
gramlot.data.setItem('_gramlot.device.orientation', null, {status: 'idle', error: null, listening: false});
|
|
48
48
|
for (const name of ['gyroscope', 'accelerometer']) {
|
|
49
|
-
gramlot.data.setItem(`
|
|
49
|
+
gramlot.data.setItem(`_gramlot.device.${name}`, null,
|
|
50
50
|
{enabled: false, watching: false, status: 'idle', error: null});
|
|
51
|
-
gramlot.data.getNode(`
|
|
52
|
-
this.#sensors.set(name, {node: gramlot.data.getNode(`
|
|
51
|
+
gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({error: null}, false, true, false);
|
|
52
|
+
this.#sensors.set(name, {node: gramlot.data.getNode(`_gramlot.device.${name}`),
|
|
53
53
|
stream: null, cleanup: Promise.resolve()});
|
|
54
54
|
}
|
|
55
55
|
for (const name of NAMES) {
|
|
56
|
-
const path = `
|
|
56
|
+
const path = `_gramlot.device.${name}`;
|
|
57
57
|
const attrs = {status: 'idle', error: null, cacheTime: name === 'appinfo' ? -1 : 5};
|
|
58
58
|
if (name === 'location') Object.assign(attrs, {enabled: false, watching: false});
|
|
59
59
|
gramlot.data.setItem(path, null);
|
|
@@ -63,45 +63,45 @@ export class DeviceHandler extends Handler {
|
|
|
63
63
|
node.resolver = resolver;
|
|
64
64
|
this.resolvers.set(name, resolver);
|
|
65
65
|
}
|
|
66
|
-
gramlot.data.setItem('
|
|
66
|
+
gramlot.data.setItem('_gramlot.device.clipboard', null,
|
|
67
67
|
{status: 'idle', error: null, text: '', copy: null, paste: null, operation: null});
|
|
68
|
-
const clipboard = gramlot.data.getNode('
|
|
69
|
-
gramlot.data.setItem('
|
|
70
|
-
const camera = gramlot.data.getNode('
|
|
71
|
-
gramlot.data.setItem('
|
|
72
|
-
const barcode = gramlot.data.getNode('
|
|
73
|
-
gramlot.data.setItem('
|
|
74
|
-
const biometrics = gramlot.data.getNode('
|
|
68
|
+
const clipboard = gramlot.data.getNode('_gramlot.device.clipboard');
|
|
69
|
+
gramlot.data.setItem('_gramlot.device.camera', null, {status: 'idle', error: null, capture: null, choose: null});
|
|
70
|
+
const camera = gramlot.data.getNode('_gramlot.device.camera');
|
|
71
|
+
gramlot.data.setItem('_gramlot.device.barcode', null, {status: 'idle', error: null, scan: null});
|
|
72
|
+
const barcode = gramlot.data.getNode('_gramlot.device.barcode');
|
|
73
|
+
gramlot.data.setItem('_gramlot.device.biometrics', null, {status: 'idle', error: null, verify: null});
|
|
74
|
+
const biometrics = gramlot.data.getNode('_gramlot.device.biometrics');
|
|
75
75
|
const notifications = new Bag();
|
|
76
76
|
notifications.setItem('request', new Bag());
|
|
77
77
|
for (const name of ['scheduled', 'received', 'action']) notifications.setItem(name, null);
|
|
78
|
-
gramlot.data.setItem('
|
|
78
|
+
gramlot.data.setItem('_gramlot.device.notifications', notifications,
|
|
79
79
|
{status: 'idle', error: null, schedule: null, listening: false, listenerError: null});
|
|
80
|
-
const notificationNode = gramlot.data.getNode('
|
|
80
|
+
const notificationNode = gramlot.data.getNode('_gramlot.device.notifications');
|
|
81
81
|
const push = new Bag();
|
|
82
82
|
for (const name of ['registration', 'received', 'action']) push.setItem(name, null);
|
|
83
|
-
gramlot.data.setItem('
|
|
83
|
+
gramlot.data.setItem('_gramlot.device.push', push,
|
|
84
84
|
{status: 'idle', error: null, register: null, listening: false, listenerError: null});
|
|
85
|
-
const pushNode = gramlot.data.getNode('
|
|
85
|
+
const pushNode = gramlot.data.getNode('_gramlot.device.push');
|
|
86
86
|
const links = new Bag();
|
|
87
87
|
links.setItem('request', null);
|
|
88
|
-
gramlot.data.setItem('
|
|
88
|
+
gramlot.data.setItem('_gramlot.device.links', links, {listening: false, listenerError: null});
|
|
89
89
|
const shortcuts = new Bag();
|
|
90
90
|
shortcuts.setItem('request', null);
|
|
91
|
-
gramlot.data.setItem('
|
|
92
|
-
gramlot.data.setItem('
|
|
91
|
+
gramlot.data.setItem('_gramlot.device.shortcuts', shortcuts, {listening: false, listenerError: null});
|
|
92
|
+
gramlot.data.setItem('_gramlot.device.network', null, {status: 'idle', error: null, listening: false});
|
|
93
93
|
const lifecycle = new Bag();
|
|
94
94
|
lifecycle.setItem('active', null);
|
|
95
95
|
lifecycle.setItem('event', null);
|
|
96
96
|
lifecycle.setItem('sequence', 0);
|
|
97
|
-
gramlot.data.setItem('
|
|
98
|
-
gramlot.data.setItem('
|
|
97
|
+
gramlot.data.setItem('_gramlot.device.lifecycle', lifecycle, {status: 'idle', error: null, listening: false});
|
|
98
|
+
gramlot.data.setItem('_gramlot.device.haptics', null,
|
|
99
99
|
{status: 'idle', error: null, impact: null, style: 'medium', vibrate: null, duration: 600});
|
|
100
|
-
const haptics = gramlot.data.getNode('
|
|
101
|
-
gramlot.data.setItem('
|
|
100
|
+
const haptics = gramlot.data.getNode('_gramlot.device.haptics');
|
|
101
|
+
gramlot.data.setItem('_gramlot.device.audio', null,
|
|
102
102
|
{status: 'idle', error: null, recording: false, start: null, stop: null, cancel: null,
|
|
103
103
|
share: null, shareStatus: 'idle', shareError: null, shareActivity: null});
|
|
104
|
-
const audio = gramlot.data.getNode('
|
|
104
|
+
const audio = gramlot.data.getNode('_gramlot.device.audio');
|
|
105
105
|
gramlot.data.subscribe('gramlot.device', {update: event => {
|
|
106
106
|
if (this.disposed) return;
|
|
107
107
|
for (const [name, sensor] of this.#sensors) {
|
|
@@ -199,16 +199,16 @@ export class DeviceHandler extends Handler {
|
|
|
199
199
|
node.setAttr({status: 'success', error: null}, true, true, false);
|
|
200
200
|
});
|
|
201
201
|
if (provider.capabilities.includes('links')) {
|
|
202
|
-
this.#startLinkEvents(this.gramlot.data.getNode('
|
|
202
|
+
this.#startLinkEvents(this.gramlot.data.getNode('_gramlot.device.links'));
|
|
203
203
|
}
|
|
204
204
|
if (provider.capabilities.includes('shortcuts')) {
|
|
205
|
-
this.#startShortcutEvents(this.gramlot.data.getNode('
|
|
205
|
+
this.#startShortcutEvents(this.gramlot.data.getNode('_gramlot.device.shortcuts'));
|
|
206
206
|
}
|
|
207
207
|
if (provider.capabilities.includes('push')) {
|
|
208
|
-
this.#startPushEvents(this.gramlot.data.getNode('
|
|
208
|
+
this.#startPushEvents(this.gramlot.data.getNode('_gramlot.device.push'));
|
|
209
209
|
}
|
|
210
210
|
if (provider.capabilities.includes('notifications')) {
|
|
211
|
-
this.#startNotificationEvents(this.gramlot.data.getNode('
|
|
211
|
+
this.#startNotificationEvents(this.gramlot.data.getNode('_gramlot.device.notifications'));
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -251,7 +251,7 @@ export class DeviceHandler extends Handler {
|
|
|
251
251
|
|
|
252
252
|
// Page-owned state streams share lifetime/error handling, never public dispatch.
|
|
253
253
|
#startStateEvents(name, start, accept) {
|
|
254
|
-
const node = this.gramlot.data.getNode(`
|
|
254
|
+
const node = this.gramlot.data.getNode(`_gramlot.device.${name}`);
|
|
255
255
|
if (!this.provider.capabilities.includes(name)) {
|
|
256
256
|
node.setAttr(failureAttributes({code: 'UNAVAILABLE', message: `${name} is unavailable`}), true, true, false);
|
|
257
257
|
return;
|
|
@@ -913,7 +913,7 @@ export class DeviceHandler extends Handler {
|
|
|
913
913
|
this.assertLive();
|
|
914
914
|
if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== 'string') throw new TypeError('Invalid database name');
|
|
915
915
|
if (this.#database) throw new Error('This page already owns a database connection');
|
|
916
|
-
const node = this.gramlot.data.getNode('
|
|
916
|
+
const node = this.gramlot.data.getNode('_gramlot.device.database');
|
|
917
917
|
const state = (status, error = null) => {
|
|
918
918
|
if (!this.disposed) node.setAttr({status, error}, true, true, false);
|
|
919
919
|
};
|
|
@@ -7,7 +7,7 @@ import type {Bag} from '@genrojs/bag';
|
|
|
7
7
|
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
8
8
|
import type {DomElement} from '../dom.d.ts';
|
|
9
9
|
import type {Gramlot} from '../gramlot.js';
|
|
10
|
-
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
10
|
+
import type {GramlotBuilder, GramlotSourceBag} from '../builder/gramlot-builder.js';
|
|
11
11
|
import type {NameSyntax} from '../builder/name-syntax.js';
|
|
12
12
|
import type {GramlotRenderer} from '../renderer/gramlot-renderer.js';
|
|
13
13
|
import {Handler} from './handler.js';
|
|
@@ -24,7 +24,7 @@ export class SourceHandler extends Handler {
|
|
|
24
24
|
/** The binding runtime of the page. */
|
|
25
25
|
binding: unknown;
|
|
26
26
|
/** The Source Bag observed by the renderer. */
|
|
27
|
-
source:
|
|
27
|
+
source: GramlotSourceBag;
|
|
28
28
|
/** The live renderer of the page. */
|
|
29
29
|
renderer: GramlotRenderer;
|
|
30
30
|
/**
|