@gramlot/gramlot 0.3.6 → 0.3.7
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 +30 -30
- package/dist/gramlot.min.js +6 -6
- package/package.json +2 -2
- package/src/binding/ask-dialog.js +1 -1
- package/src/binding/runtime.js +15 -15
- package/src/builder/gramlot-builder.js +2 -2
- package/src/builder/source.js +1 -1
- package/src/handlers/subscriptions-handler.js +2 -2
- package/src/index-page-runtime.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@genrojs/bag": ">=0.11.0",
|
|
20
|
-
"@genrojs/builders": ">=0.
|
|
20
|
+
"@genrojs/builders": ">=0.7.0",
|
|
21
21
|
"@genrojs/tytx": ">=0.16.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -82,7 +82,7 @@ export class AskDialog {
|
|
|
82
82
|
release = binding.track(() => finish(false));
|
|
83
83
|
try {
|
|
84
84
|
const builder = new GramlotBuilder();
|
|
85
|
-
const dialog = builder.root.dialog({
|
|
85
|
+
const dialog = builder.root.dialog({nodeId: id, datapath: id, request: id,
|
|
86
86
|
connect_oncancel: `${group}.cancel`, connect_onclose: `${group}.cancel`,
|
|
87
87
|
class: 'gramlot-ask', 'aria-labelledby': `${id}_title`,
|
|
88
88
|
style: 'border:1px solid #aab4c2;border-radius:8px;padding:16px;max-width:32rem;width:calc(100% - 48px);font:inherit;'});
|
package/src/binding/runtime.js
CHANGED
|
@@ -16,14 +16,14 @@ const PROVIDERS = {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// Attributes whose change moves the Data context of a whole branch (§4.4, upd_attrs row).
|
|
19
|
-
const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', '
|
|
19
|
+
const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', 'nodeId', 'form', 'formId'];
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Semantic lifetime of one Gramlot page (source plan §4.4).
|
|
23
23
|
*
|
|
24
24
|
* The runtime owns the one Data subscription of the page, on Builder's Data
|
|
25
25
|
* wrapper (`_dataroot` → `_root_` → `builder.data`), the DataRouter it feeds,
|
|
26
|
-
* the `
|
|
26
|
+
* the `nodeId → node` map of the Source (R06) and one NodeBinding per Source
|
|
27
27
|
* node, created once per node identity. The DOM lifetime stays in the
|
|
28
28
|
* renderer records.
|
|
29
29
|
*/
|
|
@@ -67,7 +67,7 @@ export class BindingRuntime {
|
|
|
67
67
|
get inlineCompiler() { return this.#inlineCompiler; }
|
|
68
68
|
/** The ask dialogs of the page (`_ask` of a provider, `ask` of a button). */
|
|
69
69
|
get askDialog() { return this.#askDialog; }
|
|
70
|
-
/** `
|
|
70
|
+
/** `nodeId → node` of the Source nodes with an open NodeBinding (R06). */
|
|
71
71
|
get nodeIds() { return this.#nodeIds; }
|
|
72
72
|
|
|
73
73
|
/** Subscribe once on Builder's Data wrapper; nothing is created. */
|
|
@@ -107,7 +107,7 @@ export class BindingRuntime {
|
|
|
107
107
|
const binding = this.bindingFor(node);
|
|
108
108
|
if (binding) {
|
|
109
109
|
this.#bindings.delete(node);
|
|
110
|
-
const nodeId = node.getAttr('
|
|
110
|
+
const nodeId = node.getAttr('nodeId');
|
|
111
111
|
if (this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
|
|
112
112
|
try { binding.close(); } catch (error) { errors.push(error); }
|
|
113
113
|
}
|
|
@@ -131,7 +131,7 @@ export class BindingRuntime {
|
|
|
131
131
|
* Semantic work of one Source event, called inside the renderer FIFO (§5.2).
|
|
132
132
|
*
|
|
133
133
|
* The rows of the event matrix: opening and closing of the NodeBindings,
|
|
134
|
-
* the `
|
|
134
|
+
* the `nodeId` map, the rebinding, and the installation of the `ins` and
|
|
135
135
|
* new-branch rows (§5.1 steps 2-5).
|
|
136
136
|
*
|
|
137
137
|
* A failing disposer does not block the rest of the event: the errors of the
|
|
@@ -200,7 +200,7 @@ export class BindingRuntime {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
/** Close every NodeBinding, the `
|
|
203
|
+
/** Close every NodeBinding, the `nodeId` map and the Data subscription; a second call does nothing. */
|
|
204
204
|
dispose() {
|
|
205
205
|
if (this.disposed) return;
|
|
206
206
|
this.#disposed = true;
|
|
@@ -215,8 +215,8 @@ export class BindingRuntime {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
* Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `
|
|
219
|
-
* complete, and a duplicate refused, before the first write or registration, so a `#<
|
|
218
|
+
* Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `nodeId` map is
|
|
219
|
+
* complete, and a duplicate refused, before the first write or registration, so a `#<nodeId>`
|
|
220
220
|
* of the branch translates; then the installation (`dataSetter`s and defaults), then one
|
|
221
221
|
* NodeBinding per node and the registrations, providers included. On an error the NodeBindings
|
|
222
222
|
* opened here are closed and the map entries they brought are removed; the Data is not rolled
|
|
@@ -231,10 +231,10 @@ export class BindingRuntime {
|
|
|
231
231
|
const known = new Set(nodes.filter(node => this.bindingFor(node)));
|
|
232
232
|
const entering = new Map();
|
|
233
233
|
for (const node of nodes) {
|
|
234
|
-
const nodeId = node.getAttr('
|
|
234
|
+
const nodeId = node.getAttr('nodeId');
|
|
235
235
|
if (nodeId == null) continue;
|
|
236
236
|
if (entering.has(nodeId) || (this.nodeIds.has(nodeId) && this.nodeIds.get(nodeId) !== node)) {
|
|
237
|
-
throw new Error(`Duplicate
|
|
237
|
+
throw new Error(`Duplicate nodeId '${nodeId}'`);
|
|
238
238
|
}
|
|
239
239
|
entering.set(nodeId, node);
|
|
240
240
|
}
|
|
@@ -246,7 +246,7 @@ export class BindingRuntime {
|
|
|
246
246
|
} catch (error) {
|
|
247
247
|
const errors = [error];
|
|
248
248
|
for (const node of nodes.filter(node => !known.has(node)).reverse()) {
|
|
249
|
-
const nodeId = node.getAttr('
|
|
249
|
+
const nodeId = node.getAttr('nodeId');
|
|
250
250
|
if (entering.get(nodeId) === node && this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
|
|
251
251
|
const binding = this.bindingFor(node);
|
|
252
252
|
if (!binding) continue;
|
|
@@ -295,16 +295,16 @@ export class BindingRuntime {
|
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
297
|
* An attribute change: the NodeBinding of the node is required first (GC-210 §090), then the inline
|
|
298
|
-
* declarations of the changed attributes are released (S09), then the `
|
|
298
|
+
* declarations of the changed attributes are released (S09), then the `nodeId` map, then the
|
|
299
299
|
* rebinding of the node, or of its branch for a context attribute.
|
|
300
300
|
*/
|
|
301
301
|
#attributesChanged(node, diff) {
|
|
302
302
|
const binding = this.#installedBinding(node);
|
|
303
303
|
this.inlineCompiler.release(node, Object.keys(diff));
|
|
304
|
-
if (Object.hasOwn(diff, '
|
|
305
|
-
const {old: previous, new: current} = diff.
|
|
304
|
+
if (Object.hasOwn(diff, 'nodeId')) {
|
|
305
|
+
const {old: previous, new: current} = diff.nodeId;
|
|
306
306
|
if (current != null && this.nodeIds.has(current) && this.nodeIds.get(current) !== node) {
|
|
307
|
-
throw new Error(`Duplicate
|
|
307
|
+
throw new Error(`Duplicate nodeId '${current}'`);
|
|
308
308
|
}
|
|
309
309
|
if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
|
|
310
310
|
if (current != null) this.nodeIds.set(current, node);
|
|
@@ -117,11 +117,11 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
117
117
|
: null;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
/** Builder's nodeById; inside a Gramlot page it reads the
|
|
120
|
+
/** Builder's nodeById; inside a Gramlot page it reads the nodeId map of the BindingRuntime (R06). */
|
|
121
121
|
nodeById(nodeId) {
|
|
122
122
|
if (!this.binding) return super.nodeById(nodeId);
|
|
123
123
|
const node = this.binding.nodeIds.get(nodeId);
|
|
124
|
-
if (!node) throw new Error(`
|
|
124
|
+
if (!node) throw new Error(`nodeId not found: ${nodeId}`);
|
|
125
125
|
return node.builder.wrapSource(node);
|
|
126
126
|
}
|
|
127
127
|
loadCollection(document) {
|
package/src/builder/source.js
CHANGED
|
@@ -447,7 +447,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
447
447
|
return path === null ? null : super._finalizeAbsPath(path, attr);
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
/** Builder's symbolic resolution; `#<
|
|
450
|
+
/** Builder's symbolic resolution; `#<nodeId>` reads the nodeId map of the page runtime when there is one (R06). */
|
|
451
451
|
_resolveSymbolicDatapath(path, raw) {
|
|
452
452
|
const symbol = path.slice(1).split('.', 1)[0];
|
|
453
453
|
if (symbol === 'FORM' || symbol === 'ANCHOR') return super._resolveSymbolicDatapath(path, raw);
|
|
@@ -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);
|
|
@@ -249,7 +249,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
249
249
|
const source = node(pane);
|
|
250
250
|
const savedWidth = preferences[widthProperty];
|
|
251
251
|
if (typeof savedWidth === 'number' && Number.isFinite(savedWidth) && savedWidth > 0) set(pane, {width: `${savedWidth}px`});
|
|
252
|
-
const handle = gramlot.subscribe(`${source.getAttr('
|
|
252
|
+
const handle = gramlot.subscribe(`${source.getAttr('nodeId')}_closable_change`, ({open}) => {
|
|
253
253
|
if (source.getAttr('hidden') === true || source.getAttr('drawer') === false) return;
|
|
254
254
|
state.setItem(property, open);
|
|
255
255
|
set(pane, {drawer: open ? true : 'close'});
|
|
@@ -260,7 +260,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
260
260
|
releases.push(() => gramlot.unsubscribe(handle));
|
|
261
261
|
}
|
|
262
262
|
const border = shell.querySelector('[data-index-regions]');
|
|
263
|
-
const handle = gramlot.subscribe(`${node(border).getAttr('
|
|
263
|
+
const handle = gramlot.subscribe(`${node(border).getAttr('nodeId')}_splitter_resize`, ({region, size}) => {
|
|
264
264
|
set(region === 'left' ? sidebar : codeSidebar, {width: size});
|
|
265
265
|
state.setItem(region === 'left' ? 'preferredSidebarWidth' : 'preferredCodeWidth', Number.parseFloat(size));
|
|
266
266
|
savePreferences();
|