@gramlot/gramlot 0.2.1

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.
@@ -0,0 +1,216 @@
1
+ {
2
+ "document_format": {
3
+ "name": "builder_grammar",
4
+ "version": "1.1"
5
+ },
6
+ "grammar": {
7
+ "name": "binding",
8
+ "version": null,
9
+ "title": "Gramlot binding",
10
+ "description": "Data-elements of Gramlot 0.2.0 with the signatures of decision P18; loaded after the HTML grammar."
11
+ },
12
+ "abstracts": {},
13
+ "elements": {
14
+ "dataSetter": {
15
+ "doc": "Initial Data value, written literally at destination_path.",
16
+ "sub_tags": "",
17
+ "parent_tags": null,
18
+ "inherits_from": null,
19
+ "ns": null,
20
+ "attributes": {
21
+ "parameters": [
22
+ {
23
+ "name": "destination_path",
24
+ "kind": "positional_or_keyword",
25
+ "role": "attribute",
26
+ "annotation": {
27
+ "kind": "type",
28
+ "module": "builtins",
29
+ "name": "str"
30
+ },
31
+ "has_default": false
32
+ },
33
+ {
34
+ "name": "value",
35
+ "kind": "positional_or_keyword",
36
+ "role": "attribute",
37
+ "annotation": {
38
+ "kind": "any"
39
+ },
40
+ "has_default": true,
41
+ "default": null
42
+ },
43
+ {
44
+ "name": "attr",
45
+ "kind": "var_keyword",
46
+ "role": "attribute",
47
+ "annotation": {
48
+ "kind": "any"
49
+ },
50
+ "has_default": false
51
+ }
52
+ ],
53
+ "accepts_var_keyword": true,
54
+ "accepts_var_positional": false
55
+ },
56
+ "node_label": null,
57
+ "collection_key": null,
58
+ "_meta": {
59
+ "data_element": true
60
+ }
61
+ },
62
+ "dataFormula": {
63
+ "doc": "Computed Data value written at result_path; formula is inline, func is a name.",
64
+ "sub_tags": "",
65
+ "parent_tags": null,
66
+ "inherits_from": null,
67
+ "ns": null,
68
+ "attributes": {
69
+ "parameters": [
70
+ {
71
+ "name": "result_path",
72
+ "kind": "positional_or_keyword",
73
+ "role": "attribute",
74
+ "annotation": {
75
+ "kind": "type",
76
+ "module": "builtins",
77
+ "name": "str"
78
+ },
79
+ "has_default": false
80
+ },
81
+ {
82
+ "name": "formula",
83
+ "kind": "positional_or_keyword",
84
+ "role": "attribute",
85
+ "annotation": {
86
+ "kind": "union",
87
+ "items": [
88
+ {
89
+ "kind": "type",
90
+ "module": "builtins",
91
+ "name": "str"
92
+ },
93
+ {
94
+ "kind": "type",
95
+ "module": "builtins",
96
+ "name": "NoneType"
97
+ }
98
+ ]
99
+ },
100
+ "has_default": true,
101
+ "default": null
102
+ },
103
+ {
104
+ "name": "func",
105
+ "kind": "positional_or_keyword",
106
+ "role": "attribute",
107
+ "annotation": {
108
+ "kind": "union",
109
+ "items": [
110
+ {
111
+ "kind": "type",
112
+ "module": "builtins",
113
+ "name": "str"
114
+ },
115
+ {
116
+ "kind": "type",
117
+ "module": "builtins",
118
+ "name": "NoneType"
119
+ }
120
+ ]
121
+ },
122
+ "has_default": true,
123
+ "default": null
124
+ },
125
+ {
126
+ "name": "params",
127
+ "kind": "var_keyword",
128
+ "role": "attribute",
129
+ "annotation": {
130
+ "kind": "any"
131
+ },
132
+ "has_default": false
133
+ }
134
+ ],
135
+ "accepts_var_keyword": true,
136
+ "accepts_var_positional": false
137
+ },
138
+ "node_label": null,
139
+ "collection_key": null,
140
+ "_meta": {
141
+ "data_element": true
142
+ }
143
+ },
144
+ "dataController": {
145
+ "doc": "Side effects on Data; script is inline, func is a name.",
146
+ "sub_tags": "",
147
+ "parent_tags": null,
148
+ "inherits_from": null,
149
+ "ns": null,
150
+ "attributes": {
151
+ "parameters": [
152
+ {
153
+ "name": "script",
154
+ "kind": "positional_or_keyword",
155
+ "role": "attribute",
156
+ "annotation": {
157
+ "kind": "union",
158
+ "items": [
159
+ {
160
+ "kind": "type",
161
+ "module": "builtins",
162
+ "name": "str"
163
+ },
164
+ {
165
+ "kind": "type",
166
+ "module": "builtins",
167
+ "name": "NoneType"
168
+ }
169
+ ]
170
+ },
171
+ "has_default": true,
172
+ "default": null
173
+ },
174
+ {
175
+ "name": "func",
176
+ "kind": "positional_or_keyword",
177
+ "role": "attribute",
178
+ "annotation": {
179
+ "kind": "union",
180
+ "items": [
181
+ {
182
+ "kind": "type",
183
+ "module": "builtins",
184
+ "name": "str"
185
+ },
186
+ {
187
+ "kind": "type",
188
+ "module": "builtins",
189
+ "name": "NoneType"
190
+ }
191
+ ]
192
+ },
193
+ "has_default": true,
194
+ "default": null
195
+ },
196
+ {
197
+ "name": "params",
198
+ "kind": "var_keyword",
199
+ "role": "attribute",
200
+ "annotation": {
201
+ "kind": "any"
202
+ },
203
+ "has_default": false
204
+ }
205
+ ],
206
+ "accepts_var_keyword": true,
207
+ "accepts_var_positional": false
208
+ },
209
+ "node_label": null,
210
+ "collection_key": null,
211
+ "_meta": {
212
+ "data_element": true
213
+ }
214
+ }
215
+ }
216
+ }
@@ -0,0 +1,181 @@
1
+ import {Bag} from '@genrojs/bag';
2
+ import {HtmlBuilder, SourceBagNode, sourceTarget} from '@genrojs/builders';
3
+ import {toTytx} from '@genrojs/tytx';
4
+ // Loading the Gramlot Source classes adds GramlotBuilderBag to the TYTX subtype
5
+ // dictionary of X, so every GramlotBuilder user can encode and decode it.
6
+ import {GramlotBuilderBag} from './source.js';
7
+ import {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
8
+ // Byte copy of src/gramlot/collections/binding.json: the JS package ships js/ only.
9
+ import BINDING from './binding.json' with {type: 'json'};
10
+
11
+ // P19: `data` is ambiguous between the legacy data-element and the HTML5 element.
12
+ const DATA_FORBIDDEN = 'data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element';
13
+ // Declarations outside Gramlot 0.2.0 that fail explicitly (source plan, section 2).
14
+ const EXCLUDED_ELEMENTS = new Set(['datarpc', 'dataremote']);
15
+ const EXCLUDED_ATTRIBUTES = new Set(['serverpath', 'dbenv', 'shared_id', 'remote', '_ask', 'ask']);
16
+ const EXCLUDED_ATTRIBUTE_PREFIXES = ['subscribe_', 'selfsubscribe_', 'formsubscribe_'];
17
+
18
+ // P18 and B8: the Data path of each data-element, which does not accept `?attr`,
19
+ // and its inline attribute, which excludes `func` on the same node, as `_if` does (Q11.1).
20
+ const DATA_PATH_ATTRIBUTES = {dataSetter: 'destination_path', dataFormula: 'result_path'};
21
+ const DATA_INLINE_ATTRIBUTES = {dataFormula: 'formula', dataController: 'script'};
22
+
23
+ /** The P18 violation of a data-element's attributes, or null. */
24
+ function dataElementError(tag, attrs) {
25
+ const pathName = DATA_PATH_ATTRIBUTES[tag];
26
+ if (pathName && String(attrs[pathName] ?? '').includes('?')) {
27
+ return `'${pathName}' does not accept '?attr': '${attrs[pathName]}'`;
28
+ }
29
+ const inlineName = DATA_INLINE_ATTRIBUTES[tag];
30
+ if (inlineName && attrs[inlineName] != null && attrs.func != null) {
31
+ return `'func' and '${inlineName}' cannot be declared on the same node`;
32
+ }
33
+ if (inlineName && attrs._if != null && attrs.func != null) {
34
+ return "'_if' is inline and cannot be declared with 'func': write the condition in the method";
35
+ }
36
+ return null;
37
+ }
38
+
39
+ /** The first excluded attribute name of `attrs`, or undefined. */
40
+ function excludedAttribute(attrs) {
41
+ return Object.keys(attrs).find(name => EXCLUDED_ATTRIBUTES.has(name)
42
+ || EXCLUDED_ATTRIBUTE_PREFIXES.some(prefix => name.startsWith(prefix)));
43
+ }
44
+
45
+ /** Gramlot vocabulary and inert authoring on the shared builder grammar. */
46
+ export class GramlotBuilder extends HtmlBuilder {
47
+ static _name = 'gramlot';
48
+ static _sourceClass = GramlotBuilderBag;
49
+ // Composed on the inherited HtmlBuilder grammar; its data-elements replace Builder's.
50
+ static { this.defineGrammar(BINDING); }
51
+
52
+ /** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
53
+ static get dialectPrefixes() {
54
+ const prefixes = [];
55
+ for (let cls = Object.getPrototypeOf(GramlotBuilder); cls && cls !== Function.prototype; cls = Object.getPrototypeOf(cls)) {
56
+ if (Object.hasOwn(cls, '_name') && cls._name) prefixes.push(`${cls._name}_`);
57
+ }
58
+ return prefixes;
59
+ }
60
+
61
+ constructor(name = null, {collections = []} = {}) {
62
+ super(name);
63
+ this._binding = null;
64
+ for (const collection of collections) this.loadCollection(collection);
65
+ }
66
+
67
+ /** The BindingRuntime of the Gramlot page that owns this builder, or null for authoring alone. */
68
+ get binding() { return this._binding; }
69
+ /** Set by Gramlot right after creating the builder (§4.3). */
70
+ set binding(runtime) { this._binding = runtime; }
71
+
72
+ /** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
73
+ nodeById(nodeId) {
74
+ if (!this.binding) return super.nodeById(nodeId);
75
+ const node = this.binding.nodeIds.get(nodeId);
76
+ if (!node) throw new Error(`node_id not found: ${nodeId}`);
77
+ return node.builder.wrapSource(node);
78
+ }
79
+ loadCollection(document) {
80
+ this.loadGrammar(document);
81
+ return this;
82
+ }
83
+
84
+ /**
85
+ * Builder's schemaTag for authored names and resolved tags.
86
+ *
87
+ * A parent-dialect prefix reaches an element the node API shadows (`html_label`):
88
+ * the prefixed name is returned as written and `bagCall`/`commandOnNode` resolve it,
89
+ * because Builder's validation calls this method with resolved tags such as `data`.
90
+ * The prefix `gramlot_` and the excluded declarations are errors.
91
+ */
92
+ schemaTag(name) {
93
+ const lookup = name.toLowerCase();
94
+ const prefixes = GramlotBuilder.dialectPrefixes;
95
+ if (lookup.startsWith(`${GramlotBuilder._name}_`)) {
96
+ throw new Error(`${name}: the tag prefix '${GramlotBuilder._name}_' is not accepted; use the prefix '${prefixes[0]}'`);
97
+ }
98
+ if (EXCLUDED_ELEMENTS.has(lookup)) throw new Error(`${name}: excluded from Gramlot 0.2.0`);
99
+ const tag = this.schemaTagNames[lookup];
100
+ if (tag) return tag;
101
+ for (const prefix of prefixes) {
102
+ if (lookup.startsWith(prefix) && this.schemaTagNames[lookup.slice(prefix.length)]) return lookup;
103
+ }
104
+ return null;
105
+ }
106
+
107
+ /** Builder's element call from the Proxy on a Source Bag. */
108
+ bagCall(bag, tag, value, attrs) {
109
+ return super.bagCall(bag, this.#authoredTag(tag), value, attrs);
110
+ }
111
+
112
+ /** Builder's element call from the Proxy on a Source node. */
113
+ commandOnNode(node, tag, value, attrs) {
114
+ return super.commandOnNode(node, this.#authoredTag(tag), value, attrs);
115
+ }
116
+
117
+ /** Builder's value check, plus the excluded attributes (authoring names the tag). */
118
+ validateNodeValues(tag, value, attrs = {}) {
119
+ const excluded = excludedAttribute(attrs);
120
+ if (excluded) throw new Error(`${tag}: attribute '${excluded}' is excluded from Gramlot 0.2.0`);
121
+ const error = dataElementError(tag, attrs);
122
+ if (error) throw new Error(`${tag}: ${error}`);
123
+ return super.validateNodeValues(tag, value, attrs);
124
+ }
125
+
126
+ /** Builder's node check, plus the excluded attributes (a Source node names tag and label). */
127
+ validateNode(node, options = {}) {
128
+ const excluded = excludedAttribute(options.attrs ?? node.getAttr());
129
+ if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot 0.2.0`);
130
+ const error = dataElementError(node.nodeTag, options.attrs ?? node.getAttr());
131
+ if (error) throw new Error(`${node.nodeTag} '${node.label}': ${error}`);
132
+ return super.validateNode(node, options);
133
+ }
134
+
135
+ /** Builder's child insertion; a plain object `value` of `dataSetter` becomes `new Bag(value)` (P25). */
136
+ setChild(bag, tag, value, attrs, parentOverride = null) {
137
+ const plain = tag === 'dataSetter' && attrs?.value !== null && typeof attrs?.value === 'object'
138
+ && Object.getPrototypeOf(attrs.value) === Object.prototype;
139
+ const actual = plain ? {...attrs, value: new Bag(attrs.value)} : attrs;
140
+ return super.setChild(bag, tag, value, actual, parentOverride);
141
+ }
142
+
143
+ /** The schema tag of a `schemaTag` result; `data` is forbidden (P19). */
144
+ #authoredTag(tag) {
145
+ if (tag === 'data') throw new Error(DATA_FORBIDDEN);
146
+ if (this.schemaTagNames[tag.toLowerCase()] === tag) return tag;
147
+ const prefix = GramlotBuilder.dialectPrefixes.find(prefix => tag.startsWith(prefix));
148
+ return this.schemaTagNames[tag.slice(prefix.length)];
149
+ }
150
+ /** The string renderer of the Gramlot Source (static render; authoring stays inert). */
151
+ get renderer_html() { return new GramlotHtmlRenderer(this); }
152
+
153
+ create() { this.setup(this.data); this.main(this.root); }
154
+ computeLogic() {} // Browser declarations are not executed by server authoring.
155
+
156
+ /**
157
+ * Preserve mixed leading text when a scalar element gains children. The promoted `_text` keeps
158
+ * its type, as the Python `_promote_child_content`; the browser renderer converts it to text once.
159
+ */
160
+ promoteNodeValue(node, oldValue, branch) {
161
+ const attributes = oldValue !== null && oldValue !== undefined
162
+ ? {_text: oldValue} : null;
163
+ node.setValue(branch, true, attributes, true);
164
+ }
165
+
166
+ /** Create a transportable reference descriptor for an authored node. */
167
+ reference(node, kind = 'node') {
168
+ node = sourceTarget(node);
169
+ if (!(node instanceof SourceBagNode) || !['node', 'dom'].includes(kind)) {
170
+ throw new TypeError('Reference requires an element and node/dom kind');
171
+ }
172
+ let id = node.getAttr('__ref');
173
+ if (id === null || id === undefined) {
174
+ id = crypto.randomUUID().replaceAll('-', '');
175
+ node.setAttr({__ref: id});
176
+ }
177
+ return {$gramlotRef: id, kind};
178
+ }
179
+
180
+ toTytx() { return toTytx(this.source); }
181
+ }
@@ -0,0 +1,227 @@
1
+ import {SourceBag, SourceBagNode} from '@genrojs/builders';
2
+ import {getSubtypeDict, setSubtypeDict} from '@genrojs/tytx';
3
+
4
+ /**
5
+ * Gramlot Source node: Builder's SourceBagNode plus the Data behavior Builder lacks.
6
+ *
7
+ * SET and GET remain Builder's and go through setRelativeData and getRelativeData, which apply
8
+ * the null path rule (Q7): a read gives null, a write is an error. FIRE writes through
9
+ * setRelativeData too, with the Gramlot reset rules.
10
+ */
11
+ export class GramlotBuilderBagNode extends SourceBagNode {
12
+ // Attributes ending in `_path` whose pointer symbol was already reported.
13
+ #reportedPathPointers = new Set();
14
+
15
+ /** Builder's pointerType, except that a string starting with `==` is not a pointer. */
16
+ pointerType(v) {
17
+ if (typeof v === 'string' && v.startsWith('==')) return null;
18
+ return super.pointerType(v);
19
+ }
20
+
21
+ /** Builder's `^` pointers, except the attributes ending in `_path`, which hold a bare path. */
22
+ pointers() {
23
+ return super.pointers().filter(([name, pointer]) => !this.#isPathAttribute(name, pointer));
24
+ }
25
+
26
+ /**
27
+ * Builder's items to resolve, with the Gramlot rules applied before Builder's runtimeValues:
28
+ * an attribute ending in `_path` loses its pointer symbol; a pointer on a null path (Q7)
29
+ * is resolved as null.
30
+ */
31
+ runtimeToEvaluate() {
32
+ const items = super.runtimeToEvaluate();
33
+ for (const [name, value] of items) {
34
+ if (!this.pointerType(value)) continue;
35
+ if (this.#isPathAttribute(name, value)) items.set(name, value.slice(1));
36
+ else if (this.absDatapath(value) === null) items.set(name, null);
37
+ }
38
+ return items;
39
+ }
40
+
41
+ /**
42
+ * The value of the attribute `name`; for an attribute ending in `_path` written as a pointer, the
43
+ * bare path, with the one warning per declaration of the `_path` rule (the same check as
44
+ * runtimeToEvaluate).
45
+ */
46
+ pathAttribute(name) {
47
+ const value = this.getAttr(name);
48
+ return this.pointerType(value) && this.#isPathAttribute(name, value) ? value.slice(1) : value;
49
+ }
50
+
51
+ /** Builder's read; null on a null path (Q7). */
52
+ getRelativeData(path, defaultValue = null, options = {}) {
53
+ if (this.absDatapath(path) === null) return null;
54
+ return super.getRelativeData(path, defaultValue, options);
55
+ }
56
+
57
+ /** Builder's write; an error on a null path (Q7). */
58
+ setRelativeData(path, value, options = {}) {
59
+ this.#requireWritablePath(path);
60
+ super.setRelativeData(path, value, options);
61
+ }
62
+
63
+ /** Write without any Data event (Bag doTrigger=false); an error on a null path (Q7). */
64
+ PUT(path, value) {
65
+ this.#requireWritablePath(path);
66
+ this.data.setItem(this.absDatapath(path), value, null, '>', false, true, this, false, false);
67
+ }
68
+
69
+ /**
70
+ * A fired write that always fires (Q8): the current value is reset to null silently, then written
71
+ * with `fired`; a null value writes `true` (D4). The value is reset to null in a `finally`, also
72
+ * when a recipient raises, and the error propagates (P12, R10). A `?attr` path fires the
73
+ * attribute with the same rules and leaves the node value alone, as legacy `fireEvent`.
74
+ * `attributes` are written on the Data node with the fired value, as legacy `setRelativeData`
75
+ * with `fired` (a button's `fire` writes `modifier` and `_counter`, S12); they stay after the reset.
76
+ */
77
+ FIRE(path, value = true, attributes = null) {
78
+ if (value === null) value = true;
79
+ this.#requireWritablePath(path);
80
+ const absolute = this.absDatapath(path);
81
+ if (absolute.includes('?')) {
82
+ this.#fireAttribute(absolute, value);
83
+ return;
84
+ }
85
+ this.data.getNode(absolute)?.setValue(null, false);
86
+ try {
87
+ this.fireEvent(path, value, {attributes});
88
+ } finally {
89
+ this.data.getNode(absolute)?.setValue(null, false);
90
+ }
91
+ }
92
+
93
+ /**
94
+ * FIRE of the attribute `attr` of `target?attr`: silent reset of the attribute, the write of the
95
+ * attribute alone with `fired` (the node value is kept; a missing node is created with null), then
96
+ * the silent reset to null in a `finally`.
97
+ */
98
+ #fireAttribute(absolute, value) {
99
+ const [target, attr] = absolute.split('?', 2);
100
+ const data = this.data;
101
+ data.getNode(target)?.setAttr({[attr]: null}, false);
102
+ try {
103
+ const existing = data.getNode(target);
104
+ if (existing) existing.setValue(existing.staticValue, true, {[attr]: value}, true, true, true, true);
105
+ else data.setItem(target, null, {[attr]: value}, '>', true, true, true, true);
106
+ } finally {
107
+ data.getNode(target)?.setAttr({[attr]: null}, false);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * FIRE after `delay` ms. A null path (Q7) is an error at the call, not inside the timer. The timer
113
+ * is tracked on the node's NodeBinding when the node has one, so the close of the node cancels it;
114
+ * the returned function cancels it as well.
115
+ */
116
+ FIRE_AFTER(path, value = true, delay = 10) {
117
+ this.#requireWritablePath(path);
118
+ const binding = this.rootBuilder?.binding?.bindingFor(this) ?? null;
119
+ let release = null;
120
+ const timer = setTimeout(() => {
121
+ release?.();
122
+ this.FIRE(path, value);
123
+ }, delay);
124
+ release = binding?.track(() => clearTimeout(timer)) ?? null;
125
+ return () => {
126
+ clearTimeout(timer);
127
+ release?.();
128
+ };
129
+ }
130
+
131
+ /** Builder's absDatapath, keeping `?attr` on symbolic paths. */
132
+ absDatapath(path) {
133
+ const bare = this.pointerType(path) ? path.slice(1) : path;
134
+ if (bare.startsWith('#') && bare.includes('?')) {
135
+ const [target, attr] = bare.split('?', 2);
136
+ const resolved = super.absDatapath(target);
137
+ return resolved === null ? null : `${resolved}?${attr}`;
138
+ }
139
+ return super.absDatapath(path);
140
+ }
141
+
142
+ /**
143
+ * Builder's datapath climb, reading a pointer datapath from Data (variable datapath).
144
+ * A datapath that makes the path symbolic (`#<id>`, `#FORM`, `#ANCHOR`), written or read
145
+ * from Data, is resolved from the parent of the node that carries it.
146
+ */
147
+ _composeRelativeDatapath(path, raw) {
148
+ let current = this;
149
+ while (current !== null && path.startsWith('.')) {
150
+ let datapath = current.getAttr('datapath');
151
+ if (this.pointerType(datapath)) {
152
+ datapath = this.#variableDatapath(current, datapath);
153
+ if (datapath === null) return null;
154
+ }
155
+ if (datapath !== null && datapath !== undefined) {
156
+ path = path === '.' ? datapath : datapath + path;
157
+ }
158
+ if (path.startsWith('#')) return current.parentNode._resolveSymbolicDatapath(path, raw);
159
+ current = current.parentNode;
160
+ }
161
+ if (path.startsWith('.')) {
162
+ throw new Error(`unresolved relative datapath: ${raw}`);
163
+ }
164
+ return path;
165
+ }
166
+
167
+ /** An empty variable datapath gives a null path. */
168
+ _finalizeAbsPath(path, attr) {
169
+ return path === null ? null : super._finalizeAbsPath(path, attr);
170
+ }
171
+
172
+ /** Builder's symbolic resolution; `#<node_id>` reads the node_id map of the page runtime when there is one (R06). */
173
+ _resolveSymbolicDatapath(path, raw) {
174
+ const symbol = path.slice(1).split('.', 1)[0];
175
+ if (symbol === 'FORM' || symbol === 'ANCHOR') return super._resolveSymbolicDatapath(path, raw);
176
+ const runtime = this.rootBuilder?.binding;
177
+ if (!runtime) return super._resolveSymbolicDatapath(path, raw);
178
+ const anchor = runtime.nodeIds.get(symbol);
179
+ if (!anchor) throw new Error(`#<id>: cannot resolve ${raw}`);
180
+ const relpath = path.slice(symbol.length + 2);
181
+ return anchor.absDatapath(relpath ? `.${relpath}` : '.');
182
+ }
183
+
184
+ /**
185
+ * The datapath read from Data for a pointer datapath, or null when empty. The pointer is read in
186
+ * the context of the carrier's parent; the value counts as if written in place of the pointer.
187
+ */
188
+ #variableDatapath(carrier, pointer) {
189
+ const path = carrier.parentNode.absDatapath(pointer);
190
+ if (path === null) return null;
191
+ const value = this.data.getItem(path);
192
+ return value === null || value === undefined || value === '' ? null : value;
193
+ }
194
+
195
+ /** Whether `name` ends in `_path`; a pointer there loses its symbol, with one warning per attribute. */
196
+ #isPathAttribute(name, value) {
197
+ if (typeof name !== 'string' || !name.endsWith('_path')) return false;
198
+ if (!this.#reportedPathPointers.has(name)) {
199
+ this.#reportedPathPointers.add(name);
200
+ console.warn(`${this.nodeTag} '${this.label}': '${name}' holds a bare Data path; `
201
+ + `the pointer symbol of '${value}' is removed`);
202
+ }
203
+ return true;
204
+ }
205
+
206
+ /** A write on a null path (Q7) is an error naming the node and the path. */
207
+ #requireWritablePath(path) {
208
+ if (this.absDatapath(path) === null) {
209
+ throw new Error(`${this.nodeTag} '${this.label}': write on a null path: '${path}'`);
210
+ }
211
+ }
212
+ }
213
+
214
+ /** Gramlot Source Bag: every node it creates is a GramlotBuilderBagNode. */
215
+ export class GramlotBuilderBag extends SourceBag {
216
+ get nodeClass() {
217
+ return GramlotBuilderBagNode;
218
+ }
219
+ }
220
+
221
+ // GramlotBuilderBag travels on the TYTX wire as "::X" with __cls "GramlotBuilderBag":
222
+ // its name joins the subtype dictionary of its type, as Builder does for SourceBag.
223
+ // The name already owned by another class is a collision.
224
+ if ((getSubtypeDict(GramlotBuilderBag.tytxSuffix).GramlotBuilderBag ?? GramlotBuilderBag) !== GramlotBuilderBag) {
225
+ throw new Error("TYTX subtype name 'GramlotBuilderBag' is already registered for another class");
226
+ }
227
+ setSubtypeDict(GramlotBuilderBag.tytxSuffix, {...getSubtypeDict(GramlotBuilderBag.tytxSuffix), GramlotBuilderBag});