@gramlot/gramlot 0.2.20 → 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 (60) hide show
  1. package/dist/gramlot.js +1343 -303
  2. package/dist/gramlot.min.js +363 -24
  3. package/package.json +6 -3
  4. package/src/binding/ask-dialog.js +2 -2
  5. package/src/binding/inline.js +3 -10
  6. package/src/binding/installation.js +2 -1
  7. package/src/binding/pointer.js +12 -148
  8. package/src/binding/providers.js +2 -1
  9. package/src/binding/runtime.js +2 -1
  10. package/src/bootstrap.d.ts +2 -0
  11. package/src/bootstrap.js +9 -2
  12. package/src/builder/gramlot-builder.js +21 -4
  13. package/src/builder/source.js +11 -10
  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/format.js +13 -6
  31. package/src/gramlot.d.ts +5 -1
  32. package/src/gramlot.js +8 -1
  33. package/src/handlers/dom-handler.d.ts +1 -0
  34. package/src/handlers/dom-handler.js +7 -0
  35. package/src/index-page-runtime.js +78 -30
  36. package/src/index-page-styles.js +2 -2
  37. package/src/index-theme.js +1 -1
  38. package/src/renderer/attributes.js +3 -40
  39. package/src/renderer/gramlot-html-renderer.js +4 -3
  40. package/src/renderer/gramlot-renderer.js +62 -4
  41. package/src/server/gramlot-server.d.ts +3 -0
  42. package/src/server/gramlot-server.js +9 -3
  43. package/src/server/index-page.d.ts +1 -0
  44. package/src/server/index-page.js +8 -3
  45. package/src/server/page-base.js +1 -0
  46. package/src/server/page.d.ts +1 -0
  47. package/src/server/resources.d.ts +2 -0
  48. package/src/view/button.js +17 -13
  49. package/src/view/controls.js +152 -4
  50. package/src/view/html.js +18 -0
  51. package/themes/gramlot-base/README.md +6 -0
  52. package/themes/gramlot-base/theme.css +34 -6
  53. package/themes/gramlot-compact/README.md +6 -0
  54. package/themes/gramlot-compact/theme.css +8 -4
  55. package/themes/joanna/README.md +23 -0
  56. package/themes/joanna/theme.css +89 -0
  57. package/themes/mimi/README.md +23 -0
  58. package/themes/mimi/theme.css +89 -0
  59. package/tools/gramlot-tools-inspector.js +42 -18
  60. 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.20",
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,9 +110,8 @@ 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);
@@ -123,12 +122,6 @@ export class InlineCompiler {
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
  }
@@ -2,7 +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, resolvePointerAttribute} from './pointer.js';
5
+ import {pointerTransform} from '@genrojs/builders';
6
+ import {resolvePointerAttribute} from './pointer.js';
6
7
 
7
8
  /**
8
9
  * Installation of the `dataSetter`s and of the defaults of one Source branch (source plan §4.6,
@@ -1,115 +1,11 @@
1
- import {BagResolver, BagCbResolver} from '@genrojs/bag';
2
- import {sourceAttributeItems} from '@genrojs/builders';
1
+ import {BagResolver} from '@genrojs/bag';
2
+ import {sourceAttributeItems, pointerTransform, pointerTemplate, pointerExpression} from '@genrojs/builders';
3
3
 
4
- /** Split an authored attribute pointer. Names exclude colon; only the first one separates. */
5
- export function pointerTransform(value) {
6
- if (typeof value !== 'string' || !/^[\^=](?!=)/.test(value)) return null;
7
- const index = value.indexOf(':');
8
- if (index < 0) return null;
9
- const expression = value[index + 1] === '=';
10
- return {pointer: value.slice(0, index), expression, body: value.slice(index + (expression ? 2 : 1))};
11
- }
12
-
13
- const SLOT = /^\{(\??[A-Za-z_][A-Za-z0-9_]*|\?)?\}/;
14
-
15
- function failure(node, name, message) {
16
- return new Error(`${node.nodeTag} '${node.label}': '${name}': ${message}`);
17
- }
18
-
19
- /** Templates are text. Braces delimit slots; no code or inferred expression mode. */
20
- export function pointerTemplate(body, read) {
21
- let result = '', blocked = false;
22
- for (let i = 0; i < body.length;) {
23
- if (body[i] !== '{' && body[i] !== '}') { result += body[i++]; continue; }
24
- const match = body.slice(i).match(SLOT);
25
- if (!match) throw new SyntaxError('Invalid pointer template placeholder');
26
- const slot = match[1] ?? '';
27
- const optional = slot.startsWith('?');
28
- const value = read(optional ? slot.slice(1) : slot);
29
- if (value == null || (value === '' && !optional)) blocked = true;
30
- else result += String(value);
31
- i += match[0].length;
32
- }
33
- return blocked ? null : result;
34
- }
35
-
36
- /**
37
- * Replace slots only in expression code, never in quoted strings, comments or regex literals.
38
- * This scans lexical boundaries; InlineCompiler remains the sole JavaScript evaluator.
39
- * Empty objects and one-name shorthand objects coincide with slots: use explicit object members.
40
- */
41
- export function pointerExpression(body) {
42
- const slots = [], identifiers = new Set();
43
- let text = '', operand = true;
44
- for (let i = 0; i < body.length;) {
45
- const start = i, c = body[i];
46
- if (c === '"' || c === "'" || c === '`') {
47
- i++;
48
- while (i < body.length) {
49
- if (body[i] === '\\') { i += 2; continue; }
50
- if (body[i++] === c) break;
51
- }
52
- text += body.slice(start, i); operand = false; continue;
53
- }
54
- if (body.startsWith('//', i)) {
55
- i = body.indexOf('\n', i); if (i < 0) i = body.length;
56
- text += body.slice(start, i); continue;
57
- }
58
- if (body.startsWith('/*', i)) {
59
- const end = body.indexOf('*/', i + 2);
60
- i = end < 0 ? body.length : end + 2;
61
- text += body.slice(start, i); continue;
62
- }
63
- if (c === '/' && operand) {
64
- let bracket = false; i++;
65
- while (i < body.length) {
66
- const current = body[i++];
67
- if (current === '\\') { i++; continue; }
68
- if (current === '[') bracket = true;
69
- else if (current === ']') bracket = false;
70
- else if (current === '/' && !bracket) break;
71
- }
72
- while (/[a-z]/i.test(body[i] ?? '') && i < body.length) i++;
73
- text += body.slice(start, i); operand = false; continue;
74
- }
75
- const slot = c === '{' ? body.slice(i).match(SLOT) : null;
76
- if (slot) {
77
- const name = slot[1] ?? '';
78
- if (name.startsWith('?')) throw new SyntaxError('Optional slots are supported in pointer templates only');
79
- text += `_pointerValues[${slots.length}]`;
80
- slots.push(name); i += slot[0].length; operand = false; continue;
81
- }
82
- const word = body.slice(i).match(/^[A-Za-z_$][\w$]*/);
83
- if (word) {
84
- identifiers.add(word[0]); text += word[0]; i += word[0].length;
85
- operand = ['return', 'typeof', 'void', 'delete', 'new', 'in', 'instanceof', 'yield', 'await'].includes(word[0]);
86
- continue;
87
- }
88
- text += c; i++;
89
- if (!/\s/.test(c)) operand = /[([{,:;=!?&|+*%~<>\/-]/.test(c);
90
- }
91
- return {text, slots, identifiers};
92
- }
93
-
94
- /** Source-attribute dependencies of a suffix, including referenced helper declarations. */
95
- export function pointerDependencies(node, raw, seen = new Set()) {
96
- const transform = pointerTransform(raw);
97
- const names = [];
98
- if (transform?.expression) names.push(...pointerExpression(transform.body).slots.filter(Boolean));
99
- else if (transform) pointerTemplate(transform.body, name => { if (name) names.push(name); return ''; });
100
- else if (typeof raw === 'string' && raw.startsWith('==')) names.push(...pointerExpression(raw.slice(2)).identifiers);
101
- else if (typeof raw === 'string') names.push(...[...raw.matchAll(/(?<!\\)\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g)].map(match => match[1]));
102
- const attrs = new Map(sourceAttributeItems(node.getAttr()));
103
- for (const name of names) {
104
- if (seen.has(name) || !attrs.has(name)) continue;
105
- seen.add(name); pointerDependencies(node, attrs.get(name), seen);
106
- }
107
- return seen;
108
- }
109
-
110
- /** A per-resolution dependency graph; Source itself remains authored and unchanged. */
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. */
111
7
  function attributeReader(node, items, context = node) {
112
- const values = new Map(), active = new Set(), consumed = new Set();
8
+ const values = new Map(), active = new Set();
113
9
  const compiler = node.rootBuilder.binding?.inlineCompiler;
114
10
  // Resolve the complete Source attribute set before applying any suffix. Projection
115
11
  // and named references share these typed values; the DOM is never an input.
@@ -122,8 +18,8 @@ function attributeReader(node, items, context = node) {
122
18
  }
123
19
  const resolve = name => {
124
20
  if (values.has(name)) return values.get(name);
125
- if (!items.has(name)) throw failure(node, name, 'referenced Source attribute does not exist');
126
- if (active.has(name)) throw failure(node, name, `cyclic attribute dependency: ${[...active, name].join(' -> ')}`);
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(' -> ')}`);
127
23
  active.add(name);
128
24
  const raw = items.get(name), transform = pointerTransform(raw);
129
25
  const leading = transform ? current.get(name) : null;
@@ -135,10 +31,10 @@ function attributeReader(node, items, context = node) {
135
31
  try {
136
32
  if (transform) {
137
33
  if (transform.expression) {
138
- const {text, slots} = pointerExpression(transform.body);
34
+ const expression = pointerExpression(transform.body);
139
35
  // Validate references even in static output; JavaScript only executes in the browser.
140
- const inputs = slots.map(read);
141
- result = compiler ? compiler.compilePointerExpression(node, name, raw, text)(inputs) : null;
36
+ const inputs = expression.slots.map(read);
37
+ result = node.rootBuilder.evaluatePointerExpression(node, name, raw, expression, inputs);
142
38
  } else {
143
39
  result = pointerTemplate(transform.body, read);
144
40
  // A null leading pointer blocks even a constant template.
@@ -152,44 +48,12 @@ function attributeReader(node, items, context = node) {
152
48
  `return (${raw.slice(2)}\n)` )({...args, _F: (value, options) => node.rootBuilder.binding.gramlot.format(value, options)}) : null;
153
49
  } else {
154
50
  result = current.get(name);
155
- if (typeof result === 'string' && !node._getMeta('data_element')) {
156
- result = result.replace(/(\\)?\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (token, escaped, key) => {
157
- if (escaped) return token.slice(1);
158
- consumed.add(key); return String(resolve(key) ?? '');
159
- });
160
- }
161
51
  }
162
52
  values.set(name, result);
163
53
  return result;
164
54
  } finally { active.delete(name); }
165
55
  };
166
- return {resolve, consumed, current};
167
- }
168
-
169
- /**
170
- * Builder's runtimeToEvaluate hook accepts Bag resolvers as already typed values. Use that
171
- * existing hook so a result beginning with ^ or = is not read a second time as a pointer.
172
- * These ephemeral callbacks are never installed on Source/Data or serialized.
173
- */
174
- export function preparePointerItems(node, items) {
175
- const transformed = [...items].filter(([name, raw]) => typeof name === 'string' && pointerTransform(raw));
176
- if (!transformed.length) return items;
177
- const reader = attributeReader(node, items);
178
- // Keep the original declarations available until every transform has resolved.
179
- const results = new Map(transformed.map(([name]) => [name, reader.resolve(name)]));
180
- for (const [name, raw] of items) {
181
- if (typeof name !== 'string' || pointerTransform(raw)) continue;
182
- if (raw instanceof BagResolver || node.pointerType(raw)) {
183
- const result = reader.current.get(name);
184
- items.set(name, new BagCbResolver(() => result));
185
- }
186
- }
187
- for (const [name] of transformed) {
188
- const result = results.get(name);
189
- items.set(name, new BagCbResolver(() => result));
190
- }
191
- if (!node._getMeta('data_element')) for (const name of reader.consumed) items.delete(name);
192
- return items;
56
+ return {resolve};
193
57
  }
194
58
 
195
59
  /** Resolve a control/structural attribute with the same rules as visual projection. */
@@ -1,7 +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, resolvePointerAttribute} from './pointer.js';
4
+ import {pointerTransform, pointerDependencies} from '@genrojs/builders';
5
+ import {resolvePointerAttribute} from './pointer.js';
5
6
 
6
7
  /**
7
8
  * Providers of one Gramlot page (source plan §4.8): the semantic runtime of a `dataFormula`, a
@@ -4,7 +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 './pointer.js';
7
+ import {pointerDependencies} from '@genrojs/builders';
8
+
8
9
 
9
10
  // The Provider class of each provider data-element (§4.8).
10
11
  const PROVIDERS = {
@@ -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,7 +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';
18
- import {pointerTransform} from '../binding/pointer.js';
20
+ import {pointerTransform} from '@genrojs/builders';
21
+
19
22
 
20
23
  // P19: `data` is ambiguous between the legacy data-element and the HTML5 element.
21
24
  const DATA_FORBIDDEN = 'data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element';
@@ -39,7 +42,7 @@ function dataElementError(tag, attrs) {
39
42
  ['action', 'ask', '_delay', 'fire'].includes(name) || name.startsWith('fire_'))) {
40
43
  return 'plain HTML button: use button for action, ask, fire or _delay';
41
44
  }
42
- 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";
43
46
  if (Object.hasOwn(attrs, '_ask') && !['dataController', 'dataFormula', 'dataRpc'].includes(tag)) return "'_ask' requires a controller, formula or RPC";
44
47
  if (['dataSetter', 'dataRemote'].includes(tag) && Object.keys(attrs).some(name => name.startsWith('subscribe_') || name.startsWith('selfsubscribe_'))) {
45
48
  return 'topic subscriptions are supported on controllers, formulas, RPCs and rendered elements';
@@ -71,6 +74,7 @@ export class GramlotBuilder extends HtmlBuilder {
71
74
  // Composed on the inherited HtmlBuilder grammar; its data-elements replace Builder's.
72
75
  static { this.defineGrammar(BINDING); }
73
76
  static { this.defineGrammar(WEBCOMPONENT); }
77
+ static { this.defineGrammar(buttons.toDocument()); }
74
78
 
75
79
  /** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
76
80
  static get dialectPrefixes() {
@@ -97,6 +101,13 @@ export class GramlotBuilder extends HtmlBuilder {
97
101
  /** Set by Gramlot right after creating the builder (§4.3). */
98
102
  set binding(runtime) { this._binding = runtime; }
99
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
+
100
111
  /** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
101
112
  nodeById(nodeId) {
102
113
  if (!this.binding) return super.nodeById(nodeId);
@@ -105,7 +116,7 @@ export class GramlotBuilder extends HtmlBuilder {
105
116
  return node.builder.wrapSource(node);
106
117
  }
107
118
  loadCollection(document) {
108
- this.loadGrammar(document);
119
+ this.loadGrammar(document instanceof ComponentCollection ? document.toDocument() : document);
109
120
  return this;
110
121
  }
111
122
 
@@ -144,6 +155,9 @@ export class GramlotBuilder extends HtmlBuilder {
144
155
 
145
156
  /** Builder's value check, plus the excluded attributes (authoring names the tag). */
146
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
+ }
147
161
  if (tag === 'webcomponent') webcomponentCode(attrs);
148
162
  const excluded = excludedAttribute(attrs);
149
163
  if (excluded) throw new Error(`${tag}: attribute '${excluded}' is excluded from Gramlot 0.2.0`);
@@ -154,6 +168,9 @@ export class GramlotBuilder extends HtmlBuilder {
154
168
 
155
169
  /** Builder's node check, plus the excluded attributes (a Source node names tag and label). */
156
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
+ }
157
174
  if (node.nodeTag === 'webcomponent') webcomponentCode(options.attrs ?? node.getAttr());
158
175
  const excluded = excludedAttribute(options.attrs ?? node.getAttr());
159
176
  if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot 0.2.0`);
@@ -170,7 +187,7 @@ export class GramlotBuilder extends HtmlBuilder {
170
187
 
171
188
  /** Custom elements are outside the native HTML child catalogue, as components are. */
172
189
  _countsForGrammar(info) {
173
- 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));
174
191
  }
175
192
 
176
193
  /** Builder's child insertion; a plain object `value` of `dataSetter` becomes `new Bag(value)` (P25). */
@@ -1,6 +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';
3
- import {pointerTransform, pointerDependencies, preparePointerItems, resolvePointerAttribute} from '../binding/pointer.js';
4
+ import {pointerTransform, pointerDependencies} from '@genrojs/builders';
5
+ import {resolvePointerAttribute} from '../binding/pointer.js';
4
6
 
5
7
  // The inline code attributes of each tag, besides `connect_on<event>` and the `==` expressions of any tag.
6
8
  const CODE_ATTRIBUTES = {
@@ -8,7 +10,6 @@ const CODE_ATTRIBUTES = {
8
10
  dataController: ['script', '_if', '_else', '_ask_if', '_ask_onCancel'],
9
11
  dataRpc: ['_ask_if', '_ask_onCancel', '_if', '_else', '_onCalling', '_onResult', '_onError'],
10
12
  dataRemote: ['_if', '_else'],
11
- button: ['action', '_ask_if'],
12
13
  };
13
14
 
14
15
  // The control attributes of `remote`, written on the node as they are; every other parameter becomes `remote_<k>`.
@@ -44,10 +45,11 @@ export class GramlotBuilderBagNode extends SourceBagNode {
44
45
  */
45
46
  codeAttributes() {
46
47
  const own = [...(CODE_ATTRIBUTES[this.nodeTag] ?? []),
48
+ ...(this._getMeta('gramlot_component')?.command ? ['action', '_ask_if'] : []),
47
49
  ...(typeof this.getAttr('remote') === 'string' ? REMOTE_CODE_ATTRIBUTES : [])];
48
50
  const items = [];
49
51
  for (const [name, value] of Object.entries(this.getAttr() ?? {})) {
50
- 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]);
51
53
  }
52
54
  for (const attribute of ['ask', '_ask']) {
53
55
  const spec = this.getAttr(attribute);
@@ -118,12 +120,6 @@ export class GramlotBuilderBagNode extends SourceBagNode {
118
120
  return this.builder.binding.gramlot._subscriptions.publishNode(this, topic, payload);
119
121
  }
120
122
 
121
- /** Builder's pointerType, except that a string starting with `==` is not a pointer. */
122
- pointerType(v) {
123
- if (typeof v === 'string' && v.startsWith('==')) return null;
124
- return super.pointerType(v);
125
- }
126
-
127
123
  /** Builder's `^` pointers, except the attributes ending in `_path`, which hold a bare path. */
128
124
  pointers() {
129
125
  const datapath = this.getAttr('datapath');
@@ -148,12 +144,17 @@ export class GramlotBuilderBagNode extends SourceBagNode {
148
144
  if (!this.pointerType(value)) continue;
149
145
  if (pointerTransform(value)) {
150
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
+ }
151
152
  continue;
152
153
  }
153
154
  if (this.#isPathAttribute(name, value)) items.set(name, value.slice(1));
154
155
  else if (this.absDatapath(value) === null) items.set(name, null);
155
156
  }
156
- return preparePointerItems(this, items);
157
+ return items;
157
158
  }
158
159
 
159
160
  /**