@gramlot/gramlot 0.2.19 → 0.3.0

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.
Files changed (66) hide show
  1. package/dist/gramlot.js +2145 -224
  2. package/dist/gramlot.min.js +363 -21
  3. package/package.json +6 -3
  4. package/src/binding/ask-dialog.js +2 -2
  5. package/src/binding/inline.js +11 -12
  6. package/src/binding/installation.js +4 -1
  7. package/src/binding/pointer.js +63 -0
  8. package/src/binding/providers.js +8 -4
  9. package/src/binding/runtime.js +11 -5
  10. package/src/bootstrap.d.ts +2 -0
  11. package/src/bootstrap.js +9 -2
  12. package/src/builder/gramlot-builder.js +24 -3
  13. package/src/builder/source.js +33 -9
  14. package/src/components/bases.js +182 -0
  15. package/src/components/buttons.js +254 -0
  16. package/src/components/choice-editor.js +221 -0
  17. package/src/components/choices.js +13 -0
  18. package/src/components/date-calendar.js +139 -0
  19. package/src/components/field-state.js +166 -0
  20. package/src/components/formlet-labels.js +80 -0
  21. package/src/components/index.js +5 -0
  22. package/src/components/inputs.js +196 -0
  23. package/src/components/labelbox.js +74 -0
  24. package/src/components/layout.js +190 -0
  25. package/src/components/parameters.js +6 -0
  26. package/src/components/popup.js +22 -0
  27. package/src/components/registry.js +83 -0
  28. package/src/components/typed-editor.js +260 -0
  29. package/src/components/validation.js +138 -0
  30. package/src/date-parser/civil.js +61 -0
  31. package/src/date-parser/index.d.ts +18 -0
  32. package/src/date-parser/index.js +196 -0
  33. package/src/date-parser/locales.js +257 -0
  34. package/src/format.js +128 -0
  35. package/src/gramlot.d.ts +25 -0
  36. package/src/gramlot.js +15 -1
  37. package/src/handlers/dom-handler.d.ts +1 -0
  38. package/src/handlers/dom-handler.js +7 -0
  39. package/src/index-page-runtime.js +78 -30
  40. package/src/index-page-styles.js +2 -2
  41. package/src/index-theme.js +1 -1
  42. package/src/index.d.ts +4 -1
  43. package/src/index.js +2 -0
  44. package/src/renderer/attributes.js +25 -50
  45. package/src/renderer/gramlot-html-renderer.js +4 -3
  46. package/src/renderer/gramlot-renderer.js +63 -3
  47. package/src/server/gramlot-server.d.ts +5 -0
  48. package/src/server/gramlot-server.js +14 -5
  49. package/src/server/index-page.d.ts +1 -0
  50. package/src/server/index-page.js +8 -3
  51. package/src/server/page-base.js +3 -0
  52. package/src/server/page.d.ts +3 -0
  53. package/src/server/resources.d.ts +2 -0
  54. package/src/view/button.js +17 -13
  55. package/src/view/controls.js +152 -4
  56. package/src/view/html.js +18 -0
  57. package/themes/gramlot-base/README.md +6 -0
  58. package/themes/gramlot-base/theme.css +34 -6
  59. package/themes/gramlot-compact/README.md +6 -0
  60. package/themes/gramlot-compact/theme.css +8 -4
  61. package/themes/joanna/README.md +23 -0
  62. package/themes/joanna/theme.css +89 -0
  63. package/themes/mimi/README.md +23 -0
  64. package/themes/mimi/theme.css +89 -0
  65. package/tools/gramlot-tools-inspector.js +42 -18
  66. package/tools/inspector-agent.js +8 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.2.19",
3
+ "version": "0.3.0",
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.5.2",
20
+ "@genrojs/builders": ">=0.6.0",
21
21
  "@genrojs/tytx": ">=0.16.2"
22
22
  },
23
23
  "devDependencies": {
@@ -35,7 +35,10 @@
35
35
  "./assets/branding/*": "./assets/branding/*",
36
36
  "./tools/inspector": "./tools/gramlot-tools-inspector.js",
37
37
  "./index-page-runtime": "./src/index-page-runtime.js",
38
- "./tools/inspector-agent": "./tools/inspector-agent.js"
38
+ "./tools/inspector-agent": "./tools/inspector-agent.js",
39
+ "./components": "./src/components/index.js",
40
+ "./components/inputs": "./src/components/inputs.js",
41
+ "./components/layout": "./src/components/layout.js"
39
42
  },
40
43
  "files": [
41
44
  "LICENSE",
@@ -95,8 +95,8 @@ export class AskDialog {
95
95
  else row.input({...attrs, type: field.type ?? 'text'});
96
96
  }
97
97
  const buttons = form.div({style: 'display:flex;justify-content:flex-end;gap:8px;margin-top:16px;'});
98
- buttons.button('Cancel', {type: 'button', request: id, connect_onclick: `${page.group}.cancel`});
99
- buttons.button('Confirm', {type: 'submit', autofocus: fields.length === 0});
98
+ buttons.html_button('Cancel', {type: 'button', request: id, connect_onclick: `${page.group}.cancel`});
99
+ buttons.html_button('Confirm', {type: 'submit', autofocus: fields.length === 0});
100
100
  app.src.source.setItem(id, app.src.prepareSource(builder.source));
101
101
  const node = app.src.binding.nodeIds.get(id);
102
102
  app.dom.getDomNode(node).showModal();
@@ -1,5 +1,5 @@
1
1
  import {sourceAttributeItems} from '@genrojs/builders';
2
- import {isExpression, templateParameters} from '../renderer/attributes.js';
2
+ import {isExpression} from '../renderer/attributes.js';
3
3
 
4
4
  /**
5
5
  * Inline code of one Gramlot page (source plan §4.10): the `formula`/`script` bodies, `_if`/`_else`,
@@ -110,33 +110,32 @@ export class InlineCompiler {
110
110
  * The function of the `==` expression `code` of the attribute `attr` of `node` (`''` for the node
111
111
  * value), as written in the Source: `run(resolved)` evaluates it on the attributes resolved by
112
112
  * runtimeValues. Its arguments are the
113
- * other attributes of the node, except the other `==` (Q11.2): the resolved value, or, for an
114
- * attribute a template consumed, its pointer resolved from Data (D6). A consumed attribute that is
115
- * itself a template has no value: an expression using it is an error naming both attributes.
113
+ * other attributes of the node, except the other `==` (Q11.2). Named pointer slots retain
114
+ * those attributes in the resolved projection; ordinary ${name} strings remain literal.
116
115
  */
117
116
  compileExpression(node, attr, code) {
118
117
  const expr = code.slice(2);
119
118
  const items = sourceAttributeItems(node.getAttr()).filter(([, raw]) => !isExpression(raw));
120
- const run = this.compile(node, attr, code, items.map(([name]) => name), `return ${expr}`);
119
+ const run = this.compile(node, attr, code, [...items.map(([name]) => name).filter(name => name !== '_F'), '_F'], `return ${expr}`);
121
120
  return resolved => {
122
121
  const values = {};
123
122
  for (const [name, raw] of items) {
124
123
  if (Object.hasOwn(resolved, name)) {
125
124
  values[name] = resolved[name];
126
- } else if (templateParameters(raw).length) {
127
- // Only a parameter can be used by name; the text of the expression is searched for it.
128
- if (isIdentifier(name) && new RegExp(`(?<![\\w$])${name.replaceAll('$', '\\$')}(?![\\w$])`).test(expr)) {
129
- throw new Error(`${node.nodeTag} '${node.label}': '${attr}' uses '${name}', a template consumed by `
130
- + 'another template, whose value is not available; write a dataFormula');
131
- }
132
125
  } else {
133
126
  values[name] = node.pointerType(raw) ? node.getRelativeData(raw) : raw;
134
127
  }
135
128
  }
136
- return run(values);
129
+ return run({...values, _F: (value, options) => this.runtime.gramlot.format(value, options)});
137
130
  };
138
131
  }
139
132
 
133
+ /** Typed placeholder inputs, compiled under the exact declaration activated with Source. */
134
+ compilePointerExpression(node, attr, code, expression) {
135
+ const run = this.compile(node, attr, code, ['_pointerValues', '_F'], `return (${expression}\n)`);
136
+ return values => run({_pointerValues: values, _F: (value, options) => this.runtime.gramlot.format(value, options)});
137
+ }
138
+
140
139
  /**
141
140
  * Release the compiled declarations of `node`: those of the attributes `names` (Source names; `''`
142
141
  * is the node value, `_if`/`_else`/`formula`/`script` their own), or all of them when `names` is null.
@@ -2,6 +2,8 @@ import {Bag} from '@genrojs/bag';
2
2
  import {META_ATTRS, SourceBag} from '@genrojs/builders';
3
3
  import {isExpression, withoutBindingAttributes} from '../renderer/attributes.js';
4
4
  import {GramlotBuilder} from '../builder/gramlot-builder.js';
5
+ import {pointerTransform} from '@genrojs/builders';
6
+ import {resolvePointerAttribute} from './pointer.js';
5
7
 
6
8
  /**
7
9
  * Installation of the `dataSetter`s and of the defaults of one Source branch (source plan §4.6,
@@ -114,7 +116,8 @@ export class DataInstaller {
114
116
  const special = {};
115
117
  for (const [name, value] of Object.entries(attrs)) {
116
118
  if (name.startsWith('attr_')) {
117
- special[name.slice(5)] = node.pointerType(value) ? node.getRelativeData(value) : value;
119
+ special[name.slice(5)] = pointerTransform(value) ? resolvePointerAttribute(node, name)
120
+ : node.pointerType(value) ? node.getRelativeData(value) : value;
118
121
  }
119
122
  }
120
123
  if (!Object.keys(special).length) return;
@@ -0,0 +1,63 @@
1
+ import {BagResolver} from '@genrojs/bag';
2
+ import {sourceAttributeItems, pointerTransform, pointerTemplate, pointerExpression} from '@genrojs/builders';
3
+
4
+ /** Structural attributes (not projected by Builder) may use a parent context, notably
5
+ * variable datapath. Reuse Builder's grammar; only the contextual reads and runtime
6
+ * compilation belong here. Visual attributes go through Builder.runtimeValues. */
7
+ function attributeReader(node, items, context = node) {
8
+ const values = new Map(), active = new Set();
9
+ const compiler = node.rootBuilder.binding?.inlineCompiler;
10
+ // Resolve the complete Source attribute set before applying any suffix. Projection
11
+ // and named references share these typed values; the DOM is never an input.
12
+ const current = new Map();
13
+ for (const [name, raw] of items) {
14
+ if (typeof name !== 'string') continue;
15
+ const pointer = pointerTransform(raw)?.pointer ?? raw;
16
+ current.set(name, pointer instanceof BagResolver ? pointer.resolve()
17
+ : node.pointerType(pointer) ? context.getRelativeData(pointer) : pointer);
18
+ }
19
+ const resolve = name => {
20
+ if (values.has(name)) return values.get(name);
21
+ if (!items.has(name)) throw new Error(`Source attribute '${name}' does not exist`);
22
+ if (active.has(name)) throw new Error(`cyclic attribute dependency: ${[...active, name].join(' -> ')}`);
23
+ active.add(name);
24
+ const raw = items.get(name), transform = pointerTransform(raw);
25
+ const leading = transform ? current.get(name) : null;
26
+ let result;
27
+ const read = key => {
28
+ if (!key) return leading;
29
+ return resolve(key);
30
+ };
31
+ try {
32
+ if (transform) {
33
+ if (transform.expression) {
34
+ const expression = pointerExpression(transform.body);
35
+ // Validate references even in static output; JavaScript only executes in the browser.
36
+ const inputs = expression.slots.map(read);
37
+ result = node.rootBuilder.evaluatePointerExpression(node, name, raw, expression, inputs);
38
+ } else {
39
+ result = pointerTemplate(transform.body, read);
40
+ // A null leading pointer blocks even a constant template.
41
+ if (leading == null) result = null;
42
+ }
43
+ } else if (typeof raw === 'string' && raw.startsWith('==')) {
44
+ const names = pointerExpression(raw.slice(2)).identifiers;
45
+ const args = {};
46
+ for (const key of names) if (key !== name && key !== '_F' && items.has(key)) args[key] = resolve(key);
47
+ result = compiler ? compiler.compile(node, name, raw, [...Object.keys(args), '_F'],
48
+ `return (${raw.slice(2)}\n)` )({...args, _F: (value, options) => node.rootBuilder.binding.gramlot.format(value, options)}) : null;
49
+ } else {
50
+ result = current.get(name);
51
+ }
52
+ values.set(name, result);
53
+ return result;
54
+ } finally { active.delete(name); }
55
+ };
56
+ return {resolve};
57
+ }
58
+
59
+ /** Resolve a control/structural attribute with the same rules as visual projection. */
60
+ export function resolvePointerAttribute(node, name, context = node) {
61
+ const items = new Map([...Object.entries(node.getAttr()), ...sourceAttributeItems(node.getAttr())]);
62
+ return attributeReader(node, items, context).resolve(name);
63
+ }
@@ -1,6 +1,8 @@
1
1
  import {AskDialog} from './ask-dialog.js';
2
2
  import {Bag} from '@genrojs/bag';
3
3
  import {RpcResolver} from './rpc-resolver.js';
4
+ import {pointerTransform, pointerDependencies} from '@genrojs/builders';
5
+ import {resolvePointerAttribute} from './pointer.js';
4
6
 
5
7
  /**
6
8
  * Providers of one Gramlot page (source plan §4.8): the semantic runtime of a `dataFormula`, a
@@ -25,7 +27,7 @@ const CONTROL_ATTRIBUTES = new Set([
25
27
  export class Provider {
26
28
  #binding;
27
29
  #registrations = [];
28
- #timingRegistration = null;
30
+ #timingRegistrations = new Set();
29
31
  #stopTiming = null;
30
32
  #cancelDelay = null;
31
33
  // The AbortController of the in-flight call of a `dataRpc`: a new call aborts it (latest wins).
@@ -63,6 +65,7 @@ export class Provider {
63
65
  }
64
66
  this.#closeRegistrations();
65
67
  const router = this.binding.runtime.router;
68
+ const timingDependencies = pointerDependencies(node, node.getAttr('_timing'));
66
69
  for (const [name, pointer] of node.pointers()) {
67
70
  if (name === 'datapath') continue;
68
71
  const absolute = node.absDatapath(pointer);
@@ -70,7 +73,7 @@ export class Provider {
70
73
  const [path, attr = null] = absolute.split('?', 2);
71
74
  const registration = router.register({path, attr, recipient: this});
72
75
  this.#registrations.push(registration);
73
- if (name === '_timing') this.#timingRegistration = registration;
76
+ if (name === '_timing' || timingDependencies.has(name)) this.#timingRegistrations.add(registration);
74
77
  }
75
78
  const subscriptions = this.binding.runtime.gramlot._subscriptions;
76
79
  for (const name of Object.keys(node.getAttr())) {
@@ -98,7 +101,7 @@ export class Provider {
98
101
  * debounces, the last call wins, and the arguments are read when the body runs.
99
102
  */
100
103
  receive(change) {
101
- if (change.registration === this.#timingRegistration) {
104
+ if (this.#timingRegistrations.has(change.registration)) {
102
105
  this.#startTiming();
103
106
  return;
104
107
  }
@@ -236,6 +239,7 @@ export class Provider {
236
239
  #resolved(name) {
237
240
  const node = this.node;
238
241
  const value = node.getAttr(name);
242
+ if (pointerTransform(value)) return resolvePointerAttribute(node, name);
239
243
  return node.pointerType(value) ? node.getRelativeData(value) : value ?? null;
240
244
  }
241
245
 
@@ -340,7 +344,7 @@ export class Provider {
340
344
 
341
345
  #closeRegistrations() {
342
346
  for (const registration of this.#registrations.splice(0)) registration.close();
343
- this.#timingRegistration = null;
347
+ this.#timingRegistrations.clear();
344
348
  }
345
349
  }
346
350
 
@@ -4,6 +4,8 @@ import {DataInstaller} from './installation.js';
4
4
  import {ControllerProvider, FormulaProvider, RemoteProvider, RpcProvider} from './providers.js';
5
5
  import {InlineCompiler} from './inline.js';
6
6
  import {RemoteBinding} from './remote.js';
7
+ import {pointerDependencies} from '@genrojs/builders';
8
+
7
9
 
8
10
  // The Provider class of each provider data-element (§4.8).
9
11
  const PROVIDERS = {
@@ -345,7 +347,7 @@ export class NodeBinding {
345
347
  // The clicks of a button, counted for its whole semantic life: a rebuild keeps them (P9, S12).
346
348
  #clickCount = 0;
347
349
  // The registration of the node's own variable datapath, read in the parent's context.
348
- #datapathRegistration = null;
350
+ #datapathRegistrations = new Set();
349
351
 
350
352
  constructor(runtime, node) {
351
353
  this.#runtime = runtime;
@@ -397,6 +399,10 @@ export class NodeBinding {
397
399
  const dataElement = node._getMeta('data_element');
398
400
  if (dataElement && !PROVIDERS[node.nodeTag]) return;
399
401
  if (!dataElement && typeof node.getAttr('remote') === 'string') this.#remote ??= new RemoteBinding(this);
402
+ const remoteDependencies = new Set();
403
+ if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
404
+ if (name.startsWith('remote_')) for (const dependency of pointerDependencies(node, raw)) remoteDependencies.add(dependency);
405
+ }
400
406
  for (const [name, pointer] of node.pointers()) {
401
407
  if (dataElement && name !== 'datapath') continue;
402
408
  const context = name === 'datapath' ? node.parentNode : node;
@@ -405,8 +411,8 @@ export class NodeBinding {
405
411
  const [path, attr = null] = absolute.split('?', 2);
406
412
  const registration = this.runtime.router.register({path, attr, recipient: this});
407
413
  this.#registrations.push(registration);
408
- if (name === 'datapath') this.#datapathRegistration = registration;
409
- if (this.remote && (name === 'remote' || name.startsWith('remote_'))) this.#remoteRegistrations.add(registration);
414
+ if (name === 'datapath') this.#datapathRegistrations.add(registration);
415
+ if (this.remote && (name === 'remote' || name.startsWith('remote_') || remoteDependencies.has(name))) this.#remoteRegistrations.add(registration);
410
416
  }
411
417
  if (!dataElement) {
412
418
  this.#registerTopics();
@@ -453,7 +459,7 @@ export class NodeBinding {
453
459
  * after a registration of `remote` or of a `remote_<k>` parameter requested the fragment again.
454
460
  */
455
461
  receive(change) {
456
- if (change.registration === this.#datapathRegistration) {
462
+ if (this.#datapathRegistrations.has(change.registration)) {
457
463
  this.runtime.rebindBranch(this.node);
458
464
  return;
459
465
  }
@@ -486,7 +492,7 @@ export class NodeBinding {
486
492
 
487
493
  #closeRegistrations() {
488
494
  for (const registration of this.#registrations.splice(0)) registration.close();
489
- this.#datapathRegistration = null;
495
+ this.#datapathRegistrations.clear();
490
496
  this.#remoteRegistrations.clear();
491
497
  }
492
498
  }
@@ -10,6 +10,8 @@ import type {Gramlot, GramlotOptions} from './gramlot.js';
10
10
  export interface PageResources {
11
11
  /** CSS stylesheet URLs. */
12
12
  css: string[];
13
+ /** Application collection modules, each exporting its ComponentCollection as default. */
14
+ collections?: string[];
13
15
  /** JavaScript module URLs, each with its Logic group (null for the page logic). */
14
16
  js: {url: string; group: string | null}[];
15
17
  }
package/src/bootstrap.js CHANGED
@@ -43,7 +43,7 @@ export class PageBootstrap {
43
43
  this.closePage();
44
44
  };
45
45
  window.addEventListener('pagehide', pagehide);
46
- let entries;
46
+ let entries, collections;
47
47
  try {
48
48
  // A relative module URL is resolved against the document, as in HTML (D8).
49
49
  const settled = await Promise.allSettled(resources.js.map(({url}) => import(new URL(url, document.baseURI).href)));
@@ -56,13 +56,20 @@ export class PageBootstrap {
56
56
  return {logicClass: outcome.value.Logic, group, resource: url};
57
57
  });
58
58
  LogicRegistry.check(entries);
59
+ collections = await Promise.all((resources.collections ?? []).map(async url => {
60
+ try { return (await import(new URL(url, document.baseURI).href)).default; }
61
+ catch (error) { throw new Error(`${url}: collection import failed: ${error.message}`, {cause: error}); }
62
+ }));
63
+ if (closed) return null;
64
+ for (const collection of collections) collection.register(window);
59
65
  } catch (error) {
60
66
  this.closePage();
61
67
  throw error;
62
68
  } finally {
63
69
  window.removeEventListener('pagehide', pagehide);
64
70
  }
65
- const app = new Gramlot({...config, document});
71
+ const app = new Gramlot({...config, document,
72
+ collections: [...(config.collections ?? []), ...collections.map(collection => collection.toDocument())]});
66
73
  for (const {logicClass, group, resource} of entries) app.src.logicRegistry.register(logicClass, {group, resource});
67
74
  window.gramlot = app;
68
75
  await app.start();
@@ -4,6 +4,8 @@
4
4
  *
5
5
  * @module
6
6
  */
7
+ import buttons from '../components/buttons.js';
8
+ import {ComponentCollection} from '../components/registry.js';
7
9
  import {Bag} from '@genrojs/bag';
8
10
  import {HtmlBuilder, SourceBagNode, sourceTarget} from '@genrojs/builders';
9
11
  import {toTytx} from '@genrojs/tytx';
@@ -15,6 +17,8 @@ import {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
15
17
  import BINDING from './binding.json' with {type: 'json'};
16
18
  import WEBCOMPONENT from './webcomponent.json' with {type: 'json'};
17
19
  import {webcomponentCode} from '../webcomponent.js';
20
+ import {pointerTransform} from '@genrojs/builders';
21
+
18
22
 
19
23
  // P19: `data` is ambiguous between the legacy data-element and the HTML5 element.
20
24
  const DATA_FORBIDDEN = 'data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element';
@@ -31,11 +35,14 @@ const DATA_INLINE_ATTRIBUTES = {dataFormula: 'formula', dataController: 'script'
31
35
 
32
36
  /** The P18 violation of a data-element's attributes, or null. */
33
37
  function dataElementError(tag, attrs) {
38
+ if (['input', 'textarea', 'select', 'webcomponent'].includes(tag) && pointerTransform(attrs.value)) {
39
+ return "'value' does not accept pointer suffixes; use an ordinary value pointer";
40
+ }
34
41
  if (tag === 'html_button' && Object.keys(attrs).some(name =>
35
42
  ['action', 'ask', '_delay', 'fire'].includes(name) || name.startsWith('fire_'))) {
36
43
  return 'plain HTML button: use button for action, ask, fire or _delay';
37
44
  }
38
- if (Object.hasOwn(attrs, 'ask') && tag !== 'button') return "'ask' is supported on buttons";
45
+ if (Object.hasOwn(attrs, 'ask') && !['button', 'toggleButton', 'dropDownButton', 'menuline'].includes(tag)) return "'ask' is supported on buttons";
39
46
  if (Object.hasOwn(attrs, '_ask') && !['dataController', 'dataFormula', 'dataRpc'].includes(tag)) return "'_ask' requires a controller, formula or RPC";
40
47
  if (['dataSetter', 'dataRemote'].includes(tag) && Object.keys(attrs).some(name => name.startsWith('subscribe_') || name.startsWith('selfsubscribe_'))) {
41
48
  return 'topic subscriptions are supported on controllers, formulas, RPCs and rendered elements';
@@ -67,6 +74,7 @@ export class GramlotBuilder extends HtmlBuilder {
67
74
  // Composed on the inherited HtmlBuilder grammar; its data-elements replace Builder's.
68
75
  static { this.defineGrammar(BINDING); }
69
76
  static { this.defineGrammar(WEBCOMPONENT); }
77
+ static { this.defineGrammar(buttons.toDocument()); }
70
78
 
71
79
  /** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
72
80
  static get dialectPrefixes() {
@@ -93,6 +101,13 @@ export class GramlotBuilder extends HtmlBuilder {
93
101
  /** Set by Gramlot right after creating the builder (§4.3). */
94
102
  set binding(runtime) { this._binding = runtime; }
95
103
 
104
+ /** Builder supplies typed slots; Gramlot owns activation, CSP and page-local _F. */
105
+ evaluatePointerExpression(node, name, raw, expression, inputs) {
106
+ return this.binding
107
+ ? this.binding.inlineCompiler.compilePointerExpression(node, name, raw, expression.text)(inputs)
108
+ : null;
109
+ }
110
+
96
111
  /** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
97
112
  nodeById(nodeId) {
98
113
  if (!this.binding) return super.nodeById(nodeId);
@@ -101,7 +116,7 @@ export class GramlotBuilder extends HtmlBuilder {
101
116
  return node.builder.wrapSource(node);
102
117
  }
103
118
  loadCollection(document) {
104
- this.loadGrammar(document);
119
+ this.loadGrammar(document instanceof ComponentCollection ? document.toDocument() : document);
105
120
  return this;
106
121
  }
107
122
 
@@ -140,6 +155,9 @@ export class GramlotBuilder extends HtmlBuilder {
140
155
 
141
156
  /** Builder's value check, plus the excluded attributes (authoring names the tag). */
142
157
  validateNodeValues(tag, value, attrs = {}) {
158
+ if (this.schema[tag]?._meta?.gramlot_component && pointerTransform(attrs.value)) {
159
+ throw new Error("'value' does not accept pointer suffixes");
160
+ }
143
161
  if (tag === 'webcomponent') webcomponentCode(attrs);
144
162
  const excluded = excludedAttribute(attrs);
145
163
  if (excluded) throw new Error(`${tag}: attribute '${excluded}' is excluded from Gramlot 0.2.0`);
@@ -150,6 +168,9 @@ export class GramlotBuilder extends HtmlBuilder {
150
168
 
151
169
  /** Builder's node check, plus the excluded attributes (a Source node names tag and label). */
152
170
  validateNode(node, options = {}) {
171
+ if (node._getMeta('gramlot_component') && pointerTransform((options.attrs ?? node.getAttr()).value)) {
172
+ throw new Error("'value' does not accept pointer suffixes");
173
+ }
153
174
  if (node.nodeTag === 'webcomponent') webcomponentCode(options.attrs ?? node.getAttr());
154
175
  const excluded = excludedAttribute(options.attrs ?? node.getAttr());
155
176
  if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot 0.2.0`);
@@ -166,7 +187,7 @@ export class GramlotBuilder extends HtmlBuilder {
166
187
 
167
188
  /** Custom elements are outside the native HTML child catalogue, as components are. */
168
189
  _countsForGrammar(info) {
169
- return info !== this.schema.webcomponent && super._countsForGrammar(info);
190
+ return info === this.schema.button || (!info?._meta?.gramlot_component && info !== this.schema.webcomponent && super._countsForGrammar(info));
170
191
  }
171
192
 
172
193
  /** Builder's child insertion; a plain object `value` of `dataSetter` becomes `new Bag(value)` (P25). */
@@ -1,5 +1,8 @@
1
+ import {BagCbResolver} from '@genrojs/bag';
1
2
  import {SourceBag, SourceBagNode, sourceAttributeItems, wrapSource} from '@genrojs/builders';
2
3
  import {getSubtypeDict, setSubtypeDict} from '@genrojs/tytx';
4
+ import {pointerTransform, pointerDependencies} from '@genrojs/builders';
5
+ import {resolvePointerAttribute} from '../binding/pointer.js';
3
6
 
4
7
  // The inline code attributes of each tag, besides `connect_on<event>` and the `==` expressions of any tag.
5
8
  const CODE_ATTRIBUTES = {
@@ -7,7 +10,6 @@ const CODE_ATTRIBUTES = {
7
10
  dataController: ['script', '_if', '_else', '_ask_if', '_ask_onCancel'],
8
11
  dataRpc: ['_ask_if', '_ask_onCancel', '_if', '_else', '_onCalling', '_onResult', '_onError'],
9
12
  dataRemote: ['_if', '_else'],
10
- button: ['action', '_ask_if'],
11
13
  };
12
14
 
13
15
  // The control attributes of `remote`, written on the node as they are; every other parameter becomes `remote_<k>`.
@@ -43,10 +45,11 @@ export class GramlotBuilderBagNode extends SourceBagNode {
43
45
  */
44
46
  codeAttributes() {
45
47
  const own = [...(CODE_ATTRIBUTES[this.nodeTag] ?? []),
48
+ ...(this._getMeta('gramlot_component')?.command ? ['action', '_ask_if'] : []),
46
49
  ...(typeof this.getAttr('remote') === 'string' ? REMOTE_CODE_ATTRIBUTES : [])];
47
50
  const items = [];
48
51
  for (const [name, value] of Object.entries(this.getAttr() ?? {})) {
49
- if (typeof value === 'string' && (own.includes(name) || name.startsWith('connect_on') || name.startsWith('subscribe_') || name.startsWith('selfsubscribe_'))) items.push([name, value]);
52
+ if (typeof value === 'string' && (own.includes(name) || name === 'validate_call' || name === 'validate__onResult' || name === 'validate_onAccept' || name === 'validate_onReject' || /^validate_\w+_if$/.test(name) || name.startsWith('connect_on') || name.startsWith('subscribe_') || name.startsWith('selfsubscribe_'))) items.push([name, value]);
50
53
  }
51
54
  for (const attribute of ['ask', '_ask']) {
52
55
  const spec = this.getAttr(attribute);
@@ -78,6 +81,9 @@ export class GramlotBuilderBagNode extends SourceBagNode {
78
81
  }
79
82
  code.set(name, text);
80
83
  }
84
+ for (const [name, text] of [...sourceAttributeItems(this.getAttr()), ['datapath', this.getAttr('datapath')]]) {
85
+ if (pointerTransform(text)?.expression) code.set(name, text);
86
+ }
81
87
  this.#activatedCode = code;
82
88
  }
83
89
 
@@ -114,15 +120,17 @@ export class GramlotBuilderBagNode extends SourceBagNode {
114
120
  return this.builder.binding.gramlot._subscriptions.publishNode(this, topic, payload);
115
121
  }
116
122
 
117
- /** Builder's pointerType, except that a string starting with `==` is not a pointer. */
118
- pointerType(v) {
119
- if (typeof v === 'string' && v.startsWith('==')) return null;
120
- return super.pointerType(v);
121
- }
122
-
123
123
  /** Builder's `^` pointers, except the attributes ending in `_path`, which hold a bare path. */
124
124
  pointers() {
125
- return super.pointers().filter(([name, pointer]) => !this.#isPathAttribute(name, pointer));
125
+ const datapath = this.getAttr('datapath');
126
+ const dependencies = pointerTransform(datapath) ? pointerDependencies(this, datapath) : new Set();
127
+ const result = super.pointers().filter(([name, pointer]) => !dependencies.has(name) && !this.#isPathAttribute(name, pointer))
128
+ .map(([name, pointer]) => [name, pointerTransform(pointer)?.pointer ?? pointer]);
129
+ for (const name of dependencies) {
130
+ const value = this.getAttr(name);
131
+ if (this.pointerType(value) === '^') result.push(['datapath', pointerTransform(value)?.pointer ?? value]);
132
+ }
133
+ return result;
126
134
  }
127
135
 
128
136
  /**
@@ -134,6 +142,15 @@ export class GramlotBuilderBagNode extends SourceBagNode {
134
142
  const items = super.runtimeToEvaluate();
135
143
  for (const [name, value] of items) {
136
144
  if (!this.pointerType(value)) continue;
145
+ if (pointerTransform(value)) {
146
+ if (typeof name !== 'string') throw new Error(`${this.nodeTag} '${this.label}': pointer suffixes belong to attributes; use format/mask for node text`);
147
+ // Gramlot's empty variable context has no absolute Data path. Resolve
148
+ // that structural state here; Builder receives an already typed value.
149
+ if (this.absDatapath(value) === null) {
150
+ items.set(name, new BagCbResolver(() => resolvePointerAttribute(this, name)));
151
+ }
152
+ continue;
153
+ }
137
154
  if (this.#isPathAttribute(name, value)) items.set(name, value.slice(1));
138
155
  else if (this.absDatapath(value) === null) items.set(name, null);
139
156
  }
@@ -147,6 +164,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
147
164
  */
148
165
  pathAttribute(name) {
149
166
  const value = this.getAttr(name);
167
+ if (pointerTransform(value)) return resolvePointerAttribute(this, name);
150
168
  return this.pointerType(value) && this.#isPathAttribute(name, value) ? value.slice(1) : value;
151
169
  }
152
170
 
@@ -232,6 +250,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
232
250
 
233
251
  /** Builder's absDatapath, keeping `?attr` on symbolic paths. */
234
252
  absDatapath(path) {
253
+ path = pointerTransform(path)?.pointer ?? path;
235
254
  const bare = this.pointerType(path) ? path.slice(1) : path;
236
255
  if (bare.startsWith('#') && bare.includes('?')) {
237
256
  const [target, attr] = bare.split('?', 2);
@@ -288,6 +307,10 @@ export class GramlotBuilderBagNode extends SourceBagNode {
288
307
  * the context of the carrier's parent; the value counts as if written in place of the pointer.
289
308
  */
290
309
  #variableDatapath(carrier, pointer) {
310
+ if (pointerTransform(pointer)) {
311
+ const value = resolvePointerAttribute(carrier, 'datapath', carrier.parentNode);
312
+ return value == null || value === '' ? null : value;
313
+ }
291
314
  const path = carrier.parentNode.absDatapath(pointer);
292
315
  if (path === null) return null;
293
316
  const value = this.data.getItem(path);
@@ -296,6 +319,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
296
319
 
297
320
  /** Whether `name` ends in `_path`; a pointer there loses its symbol, with one warning per attribute. */
298
321
  #isPathAttribute(name, value) {
322
+ if (pointerTransform(value)) return false;
299
323
  if (typeof name !== 'string' || !name.endsWith('_path')) return false;
300
324
  if (!this.#reportedPathPointers.has(name)) {
301
325
  this.#reportedPathPointers.add(name);