@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.3.6",
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.6.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({node_id: id, datapath: id, request: id,
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;'});
@@ -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', 'node_id', 'form', 'formId'];
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 `node_id → node` map of the Source (R06) and one NodeBinding per Source
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
- /** `node_id → node` of the Source nodes with an open NodeBinding (R06). */
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('node_id');
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 `node_id` map, the rebinding, and the installation of the `ins` and
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 `node_id` map and the Data subscription; a second call does nothing. */
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 `node_id` map is
219
- * complete, and a duplicate refused, before the first write or registration, so a `#<node_id>`
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('node_id');
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 node_id '${nodeId}'`);
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('node_id');
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 `node_id` map, 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, 'node_id')) {
305
- const {old: previous, new: current} = diff.node_id;
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 node_id '${current}'`);
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 node_id map of the BindingRuntime (R06). */
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(`node_id not found: ${nodeId}`);
124
+ if (!node) throw new Error(`nodeId not found: ${nodeId}`);
125
125
  return node.builder.wrapSource(node);
126
126
  }
127
127
  loadCollection(document) {
@@ -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; `#<node_id>` reads the node_id map of the page runtime when there is one (R06). */
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(`node_id not found: ${topic.nodeId}`);
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('node_id');
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('node_id')}_closable_change`, ({open}) => {
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('node_id')}_splitter_resize`, ({region, size}) => {
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();