@gramlot/gramlot 0.3.36 → 0.3.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +9 -9
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +0 -30
- package/dist/components/drawing/__init__.py +1 -1
- package/dist/components/drawing/assets/collection.js +3 -3
- package/dist/components/drawing/assets/index.js +1 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +6 -6
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +0 -2
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +8 -8
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +2 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +9 -9
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +2 -2
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +6 -6
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +0 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +3 -3
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +0 -3
- package/dist/gramlot.js +1205 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/standard-collections.js +1 -1
- package/package.json +2 -3
- package/src/binding/data-binder.js +11 -3
- package/src/binding/grid-struct.js +7 -4
- package/src/binding/runtime.js +203 -46
- package/src/builder/binding.json +23 -1
- package/src/builder/gramlot-builder.d.ts +1 -4
- package/src/builder/source.js +185 -29
- package/src/chat.js +26 -20
- package/src/components/attachment-manager.js +38 -34
- package/src/components/chart-data-view.js +4 -7
- package/src/components/chart-fields.js +18 -6
- package/src/components/chart-renderer.js +10 -3
- package/src/components/chart-timeline.js +7 -5
- package/src/components/charts.js +74 -67
- package/src/components/check-box-text-editor.js +3 -3
- package/src/components/check-box-text.js +7 -22
- package/src/components/check-box-tree.js +20 -16
- package/src/components/choice-editor.js +1 -1
- package/src/components/drawing.js +47 -34
- package/src/components/grid-cell-editor.js +72 -29
- package/src/components/grid-column-filters.js +47 -40
- package/src/components/grid-formulas.js +22 -17
- package/src/components/grid-header-interaction.js +9 -11
- package/src/components/grid-row-interaction.js +25 -24
- package/src/components/grid-row-layout.js +28 -29
- package/src/components/grid-search-box.js +3 -3
- package/src/components/grid-search.js +3 -8
- package/src/components/grid-selection.js +33 -29
- package/src/components/grid-structure.js +48 -10
- package/src/components/grid-tools.js +14 -14
- package/src/components/grid.js +83 -79
- package/src/components/image-crop-dialog.js +2 -2
- package/src/components/image-crop.js +16 -9
- package/src/components/image-uploader.js +21 -28
- package/src/components/inputs.js +19 -1
- package/src/components/registry.js +3 -5
- package/src/components/tray-pane.js +85 -61
- package/src/components/tree.js +332 -239
- package/src/components/upload-engine.js +10 -2
- package/src/components/uploader.js +31 -27
- package/src/editing-session.d.ts +4 -1
- package/src/editing-session.js +120 -83
- package/src/experiments/window-selection.js +4 -6
- package/src/filesystem.js +2 -2
- package/src/gramlot.js +1 -0
- package/src/handlers/device-handler.js +219 -213
- package/src/handlers/rpc-handler.d.ts +17 -0
- package/src/handlers/rpc-handler.js +22 -0
- package/src/ide-documents.js +29 -11
- package/src/ide-runtime.js +33 -31
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +67 -48
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +6 -1
- package/src/renderer/gramlot-renderer.js +21 -2
- package/src/source-picker.d.ts +2 -2
- package/src/source-picker.js +15 -6
- package/src/stores/bag-collection-store.js +25 -7
- package/src/stores/bag-collection-view.js +23 -22
- package/src/view/controls.js +1 -1
- package/src/view/html.js +40 -20
- package/src/visual-editor-canvas.js +1 -1
- package/src/visual-editor.js +18 -19
- package/tools/gramlot-tools-inspector.js +400 -374
- package/tools/inspector-agent.js +223 -49
- package/dist/components/vizabi/__init__.py +0 -13
- package/dist/components/vizabi/assets/collection.js +0 -4
- package/dist/components/vizabi/assets/index.js +0 -3
- package/dist/components/vizabi/commands.json +0 -7
- package/dist/components/vizabi/grammar.json +0 -128
- package/src/components/vizabi-session.js +0 -66
- package/src/components/vizabi.js +0 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.37",
|
|
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": {
|
|
@@ -93,8 +93,7 @@
|
|
|
93
93
|
"./components/chat": "./src/components/chat.js",
|
|
94
94
|
"./components/selection_trial": "./src/experiments/selection-trial.js",
|
|
95
95
|
"./components/charts": "./src/components/charts.js",
|
|
96
|
-
"./components/drawing": "./src/components/drawing.js"
|
|
97
|
-
"./components/vizabi": "./src/components/vizabi.js"
|
|
96
|
+
"./components/drawing": "./src/components/drawing.js"
|
|
98
97
|
},
|
|
99
98
|
"files": [
|
|
100
99
|
"LICENSE",
|
|
@@ -2,7 +2,7 @@ import {randomId} from '../random-id.js';
|
|
|
2
2
|
|
|
3
3
|
const REMOTE = 'gramlot-page-store-remote';
|
|
4
4
|
|
|
5
|
-
/** One Source node's subscription between client Data and its page's server Bag. */
|
|
5
|
+
/** One Source node's subscription between client Data and its page's server Bag, or the Bag of a named connection. */
|
|
6
6
|
export class DataBinder {
|
|
7
7
|
constructor(binding) {
|
|
8
8
|
this.binding = binding;
|
|
@@ -12,8 +12,16 @@ export class DataBinder {
|
|
|
12
12
|
|
|
13
13
|
register() {
|
|
14
14
|
const {runtime, node} = this.binding;
|
|
15
|
-
|
|
16
|
-
if (
|
|
15
|
+
const name = node.getAttr('connection');
|
|
16
|
+
if (name == null) {
|
|
17
|
+
this.connection = runtime.gramlot._pageStore;
|
|
18
|
+
if (!this.connection) throw new Error('dataBinder requires a PageStore WebSocket');
|
|
19
|
+
} else {
|
|
20
|
+
if (typeof name !== 'string' || !/^[A-Za-z_][\w-]*$/.test(name)) {
|
|
21
|
+
throw new TypeError('dataBinder connection requires a literal name');
|
|
22
|
+
}
|
|
23
|
+
this.connection = runtime.gramlot.rpc.connection(name);
|
|
24
|
+
}
|
|
17
25
|
this.clientPath = node.absDatapath(node.pathAttribute('destination_path'));
|
|
18
26
|
this.serverPath = node.getAttr('server_path');
|
|
19
27
|
if (typeof this.clientPath !== 'string' || !this.clientPath || this.clientPath.includes('?')) {
|
|
@@ -42,7 +42,7 @@ function structureData(source) {
|
|
|
42
42
|
|
|
43
43
|
/** Validate before DataInstaller writes any setters in the incoming branch. */
|
|
44
44
|
export function validateGridDeclaration(node) {
|
|
45
|
-
if (node._getMeta('gramlot_component')?.
|
|
45
|
+
if (node._getMeta('gramlot_component')?.parameters?.structpath) {
|
|
46
46
|
const children = node.staticValue instanceof SourceBag ? node.staticValue.getNodes() : [];
|
|
47
47
|
if (children.some(child => !child._getMeta('gridStruct')) || children.length > 1) throw new TypeError('grid accepts one struct declaration');
|
|
48
48
|
if (children.length && node.getAttr('structpath') != null) throw new TypeError('grid requires structpath or nested struct, not both');
|
|
@@ -50,16 +50,19 @@ export function validateGridDeclaration(node) {
|
|
|
50
50
|
if (!['values', 'attributes'].includes(node.getAttr('rowMode'))) throw new TypeError('grid rowMode must explicitly be values or attributes');
|
|
51
51
|
}
|
|
52
52
|
if (!node._getMeta('gridStruct')) return;
|
|
53
|
-
if (!node.parentNode?._getMeta('gramlot_component')?.
|
|
53
|
+
if (!node.parentNode?._getMeta('gramlot_component')?.parameters?.structpath) throw new TypeError('struct requires a grid parent');
|
|
54
54
|
if (!(node.staticValue instanceof SourceBag)) throw new TypeError('grid struct requires column declarations');
|
|
55
55
|
new GridStructure(structureData(node.staticValue));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* DataInstaller consumes this declaration after its one ordinary Data write: the structure goes to
|
|
60
|
+
* the private area of its grid, `<workspaceDatapath>.struct`, whose name derives from the grid node.
|
|
61
|
+
*/
|
|
59
62
|
export function installGridStruct(node, data) {
|
|
60
63
|
const value = structureData(node.staticValue);
|
|
61
64
|
new GridStructure(value);
|
|
62
|
-
const path =
|
|
65
|
+
const path = `${node.parentNode.workspaceDatapath}.struct`;
|
|
63
66
|
data.setItem(path, value, null, '>', false, true, node);
|
|
64
67
|
node.parentNode.setAttr({structpath: path}, false);
|
|
65
68
|
node.setValue(null, false);
|
package/src/binding/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Bag} from '@genrojs/bag';
|
|
2
2
|
import {BagCollectionView} from '../stores/bag-collection-view.js';
|
|
3
|
-
import {BagCollectionStore} from '../stores/bag-collection-store.js';
|
|
3
|
+
import {BagCollectionStore, collectionKey} from '../stores/bag-collection-store.js';
|
|
4
4
|
import {SourceBag} from '@genrojs/builders';
|
|
5
5
|
import {DataRouter} from './router.js';
|
|
6
6
|
import {DataInstaller} from './installation.js';
|
|
@@ -12,7 +12,8 @@ import {DataBinder} from './data-binder.js';
|
|
|
12
12
|
import {AskDialog} from './ask-dialog.js';
|
|
13
13
|
import {ErrorNotifications} from './error-notifications.js';
|
|
14
14
|
import {randomId} from '../random-id.js';
|
|
15
|
-
import {pointerDependencies} from '@genrojs/builders';
|
|
15
|
+
import {DATA_ROOT, pointerDependencies} from '@genrojs/builders';
|
|
16
|
+
import {SYMBOLIC_ATTRIBUTES} from '../builder/source.js';
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
// The Provider class of each provider data-element (§4.8).
|
|
@@ -22,7 +23,19 @@ const PROVIDERS = {
|
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// Attributes whose change moves the Data context of a whole branch (§4.4, upd_attrs row).
|
|
25
|
-
const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', 'nodeId', 'form', 'formId'];
|
|
26
|
+
const CONTEXT_ATTRIBUTES = ['datapath', '_anchor', 'nodeId', 'form', 'formId', ...SYMBOLIC_ATTRIBUTES];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The names a node gives to the symbolic resolution, besides the node itself: its nodeId and its
|
|
30
|
+
* childname. A NodeBinding whose resolution read one of them is rebound when it
|
|
31
|
+
* changes.
|
|
32
|
+
*/
|
|
33
|
+
function startKeys(node) {
|
|
34
|
+
const keys = [node];
|
|
35
|
+
if (node.getAttr('nodeId') != null) keys.push(`id:${node.getAttr('nodeId')}`);
|
|
36
|
+
if (node.getAttr('childname') != null) keys.push(`childname:${node.getAttr('childname')}`);
|
|
37
|
+
return keys;
|
|
38
|
+
}
|
|
26
39
|
|
|
27
40
|
/**
|
|
28
41
|
* Semantic lifetime of one Gramlot page (source plan §4.4).
|
|
@@ -37,6 +50,13 @@ export class BindingRuntime {
|
|
|
37
50
|
#gramlot;
|
|
38
51
|
#bindings = new Map();
|
|
39
52
|
#nodeIds = new Map();
|
|
53
|
+
// The NodeBindings whose registrations read a start of the symbolic resolution, by key: a Source
|
|
54
|
+
// node, or `id:<nodeId>`, `childname:<name>`.
|
|
55
|
+
#dependents = new Map();
|
|
56
|
+
// The NodeBinding whose registrations are being resolved, or null.
|
|
57
|
+
#resolving = null;
|
|
58
|
+
// The keys moved by the Source event being handled and the nodes already resolved again, or null outside one.
|
|
59
|
+
#moved = null;
|
|
40
60
|
#router;
|
|
41
61
|
#installer;
|
|
42
62
|
#inlineCompiler;
|
|
@@ -47,7 +67,8 @@ export class BindingRuntime {
|
|
|
47
67
|
#disposed = false;
|
|
48
68
|
#sourceTrees = new Set();
|
|
49
69
|
#dataRootTrees = new Set();
|
|
50
|
-
|
|
70
|
+
// One collection store per absolute Data path and rowMode, never per Bag identity.
|
|
71
|
+
#collectionStores = new Map();
|
|
51
72
|
|
|
52
73
|
constructor(gramlot, {subscriptions}) {
|
|
53
74
|
this.#gramlot = gramlot;
|
|
@@ -70,7 +91,6 @@ export class BindingRuntime {
|
|
|
70
91
|
get data() { return this.builder.data; }
|
|
71
92
|
/** Resolve a tree store against the selected live root. */
|
|
72
93
|
treeStore(node) {
|
|
73
|
-
if (node.treeStore !== null) return node.treeStore;
|
|
74
94
|
const path = node.getAttr('storepath');
|
|
75
95
|
if (path === '*S' || path.startsWith('*S.')) {
|
|
76
96
|
const root = this.renderer.source.getItem('main');
|
|
@@ -105,24 +125,64 @@ export class BindingRuntime {
|
|
|
105
125
|
/** `nodeId → node` of the Source nodes with an open NodeBinding (R06). */
|
|
106
126
|
get nodeIds() { return this.#nodeIds; }
|
|
107
127
|
|
|
108
|
-
/**
|
|
109
|
-
|
|
128
|
+
/** Run `run` resolving the registrations of `binding`: the starts it reads are recorded for it. */
|
|
129
|
+
resolveFor(binding, run) {
|
|
130
|
+
const previous = this.#resolving;
|
|
131
|
+
this.#resolving = binding;
|
|
132
|
+
try { return run(); } finally { this.#resolving = previous; }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Record that the registrations being resolved read the start `key` (a Source node or a name key). */
|
|
136
|
+
dependOn(key) {
|
|
137
|
+
const binding = this.#resolving;
|
|
138
|
+
if (!binding) return;
|
|
139
|
+
let dependents = this.#dependents.get(key);
|
|
140
|
+
if (!dependents) this.#dependents.set(key, dependents = new Set());
|
|
141
|
+
dependents.add(binding);
|
|
142
|
+
binding.dependencies.add(key);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Forget the starts read by `binding`; called when its registrations close. */
|
|
146
|
+
releaseDependencies(binding) {
|
|
147
|
+
for (const key of binding.dependencies) {
|
|
148
|
+
const dependents = this.#dependents.get(key);
|
|
149
|
+
dependents?.delete(binding);
|
|
150
|
+
if (dependents && !dependents.size) this.#dependents.delete(key);
|
|
151
|
+
}
|
|
152
|
+
binding.dependencies.clear();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* One shared resident data resource per absolute Data `path` and `rowMode`; presentation state
|
|
157
|
+
* belongs to views. The store keeps the address: a replacement of the Bag at `path` keeps it.
|
|
158
|
+
*/
|
|
159
|
+
collectionStore(path, rowMode) {
|
|
110
160
|
if (this.disposed) throw new Error('BindingRuntime is disposed');
|
|
111
|
-
|
|
161
|
+
const key = collectionKey(path, rowMode);
|
|
162
|
+
let store = this.#collectionStores.get(key);
|
|
112
163
|
if (!store) {
|
|
113
|
-
store = new BagCollectionStore(
|
|
114
|
-
this.#collectionStores.set(
|
|
115
|
-
}
|
|
164
|
+
store = new BagCollectionStore(this.data, path, rowMode);
|
|
165
|
+
this.#collectionStores.set(key, store);
|
|
166
|
+
}
|
|
116
167
|
return store;
|
|
117
168
|
}
|
|
118
169
|
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Each grid Source owns one view over the store at `path`. A new address gives a new view that
|
|
172
|
+
* starts from the criteria of the previous one; the previous view is disconnected.
|
|
173
|
+
*/
|
|
174
|
+
collectionView(node, path, rowMode) {
|
|
175
|
+
const store = this.collectionStore(path,rowMode);
|
|
176
|
+
const previous = node._internal.gridCollectionView ?? null;
|
|
177
|
+
if (previous?.path === path && previous.rowMode === rowMode) return previous;
|
|
178
|
+
const view = new BagCollectionView(store);
|
|
179
|
+
if (previous) {
|
|
180
|
+
previous.disconnect();
|
|
181
|
+
view.sort(previous.sortedBy);
|
|
182
|
+
view.copyFiltersFrom(previous);
|
|
183
|
+
}
|
|
184
|
+
node._internal.gridCollectionView = view;
|
|
185
|
+
return view;
|
|
126
186
|
}
|
|
127
187
|
|
|
128
188
|
/** Subscribe once on Builder's Data wrapper; nothing is created. */
|
|
@@ -132,23 +192,45 @@ export class BindingRuntime {
|
|
|
132
192
|
|
|
133
193
|
/** Callback of the one Data subscription. */
|
|
134
194
|
receiveData(event) {
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
let bag = this.root;
|
|
138
|
-
for (const [index, segment] of (event.pathlist ?? []).entries()) {
|
|
139
|
-
const value = bag.node(segment)?.staticValue;
|
|
140
|
-
if (!(value instanceof Bag)) break;
|
|
141
|
-
const store = this.#collectionStores.get(value);
|
|
142
|
-
store?.receiveData(event, index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null,
|
|
143
|
-
event.pathlist[index + 2] ?? null);
|
|
144
|
-
bag = value;
|
|
145
|
-
}
|
|
195
|
+
// Resident stores reconcile before the consumers that the router reaches.
|
|
196
|
+
this.#notifyCollectionStores(event);
|
|
146
197
|
this.router.deliver(event);
|
|
147
198
|
for (const binding of [...this.#dataRootTrees]) {
|
|
148
199
|
if (!binding.closed && this.renderer.attached(binding.node)) this.renderer.project(binding.node);
|
|
149
200
|
}
|
|
150
201
|
}
|
|
151
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Notify the collection stores an event reaches, by path. An event inside the collection
|
|
205
|
+
* carries its row (the node under the store path, read without resolvers) and field; an event
|
|
206
|
+
* on the store path, on a row list, or replacing an ancestor is a full change. A path that
|
|
207
|
+
* does not hold a Bag notifies nothing: its consumers read the address and report the error.
|
|
208
|
+
*/
|
|
209
|
+
#notifyCollectionStores(event) {
|
|
210
|
+
const {pathlist} = event;
|
|
211
|
+
if (!this.#collectionStores.size || !pathlist?.length || pathlist[0] !== DATA_ROOT) return;
|
|
212
|
+
const base = pathlist.slice(1), container = event.evt === 'ins' || event.evt === 'del';
|
|
213
|
+
const labels = container ? (Array.isArray(event.node) ? event.node : [event.node]).map(node => node.label) : [];
|
|
214
|
+
for (const store of this.#collectionStores.values()) {
|
|
215
|
+
const target = store.path.split('.');
|
|
216
|
+
const shared = Math.min(base.length, target.length);
|
|
217
|
+
let index = 0;
|
|
218
|
+
while (index < shared && base[index] === target[index]) index++;
|
|
219
|
+
if (index < shared) continue;
|
|
220
|
+
let row = null, field = null;
|
|
221
|
+
if (base.length > target.length) {
|
|
222
|
+
row = base[target.length];
|
|
223
|
+
field = base[target.length + 1] ?? null;
|
|
224
|
+
} else if (base.length < target.length) {
|
|
225
|
+
const reached = container ? labels.includes(target[base.length]) : event.evt === 'upd_value';
|
|
226
|
+
if (!reached) continue;
|
|
227
|
+
}
|
|
228
|
+
const bag = this.data.getItem(store.path, null, true);
|
|
229
|
+
if (!(bag instanceof Bag)) continue;
|
|
230
|
+
store.receiveData(event, row === null ? null : bag.node(row) ?? null, field);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
152
234
|
/** The open NodeBinding of `node`, or null. */
|
|
153
235
|
bindingFor(node) {
|
|
154
236
|
return this.#bindings.get(node) ?? null;
|
|
@@ -179,6 +261,7 @@ export class BindingRuntime {
|
|
|
179
261
|
const nodeId = node.getAttr('nodeId');
|
|
180
262
|
if (this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
|
|
181
263
|
try { binding.close(); } catch (error) { errors.push(error); }
|
|
264
|
+
try { this.#moving(startKeys(node)); } catch (error) { errors.push(error); }
|
|
182
265
|
}
|
|
183
266
|
if (errors.length) throw new AggregateError(errors, 'Source branch close failed');
|
|
184
267
|
}
|
|
@@ -194,6 +277,47 @@ export class BindingRuntime {
|
|
|
194
277
|
for (const each of nodes) this.bindingFor(each)?.rebind();
|
|
195
278
|
for (const each of nodes) this.renderer.project(each);
|
|
196
279
|
for (const each of nodes) this.bindingFor(each)?.remote?.trigger();
|
|
280
|
+
this.#moving(nodes, nodes);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Rebind and project the open NodeBindings whose registrations read one of `keys`, except those of
|
|
285
|
+
* the nodes in `skip`; their errors are returned. A NodeBinding whose resolution fails keeps no
|
|
286
|
+
* registration on the old paths and keeps its dependencies: it is rebound again when the start returns.
|
|
287
|
+
*/
|
|
288
|
+
#rebindDependents(keys, skip = new Set()) {
|
|
289
|
+
const bindings = new Set();
|
|
290
|
+
for (const key of keys) {
|
|
291
|
+
for (const binding of this.#dependents.get(key) ?? []) if (!skip.has(binding.node)) bindings.add(binding);
|
|
292
|
+
}
|
|
293
|
+
const errors = [];
|
|
294
|
+
const failed = new Set();
|
|
295
|
+
for (const binding of bindings) {
|
|
296
|
+
if (binding.closed) continue;
|
|
297
|
+
try { binding.rebind(); } catch (error) { errors.push(error); failed.add(binding); }
|
|
298
|
+
}
|
|
299
|
+
for (const binding of bindings) {
|
|
300
|
+
if (binding.closed || failed.has(binding)) continue;
|
|
301
|
+
try {
|
|
302
|
+
this.renderer.project(binding.node);
|
|
303
|
+
binding.remote?.trigger();
|
|
304
|
+
} catch (error) { errors.push(error); }
|
|
305
|
+
}
|
|
306
|
+
return errors;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Keys moved by a Source change, with the nodes whose NodeBindings resolved again already: collected
|
|
311
|
+
* until the end of the Source event, rebound at once outside one.
|
|
312
|
+
*/
|
|
313
|
+
#moving(keys, done = []) {
|
|
314
|
+
if (this.#moved) {
|
|
315
|
+
for (const key of keys) this.#moved.keys.add(key);
|
|
316
|
+
for (const node of done) this.#moved.done.add(node);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const errors = this.#rebindDependents(keys, new Set(done));
|
|
320
|
+
if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, 'Symbolic start rebinding failed');
|
|
197
321
|
}
|
|
198
322
|
|
|
199
323
|
/**
|
|
@@ -214,6 +338,7 @@ export class BindingRuntime {
|
|
|
214
338
|
const close = removed => {
|
|
215
339
|
try { this.closeBranch(removed); } catch (error) { errors.push(error); }
|
|
216
340
|
};
|
|
341
|
+
const moved = this.#moved = {keys: new Set(), done: new Set()};
|
|
217
342
|
try {
|
|
218
343
|
if (evt === 'ins') {
|
|
219
344
|
this.#openBranch(node);
|
|
@@ -235,7 +360,11 @@ export class BindingRuntime {
|
|
|
235
360
|
} catch (error) {
|
|
236
361
|
if (!errors.length) throw error;
|
|
237
362
|
throw new AggregateError([...errors, error], 'Source event failed');
|
|
363
|
+
} finally {
|
|
364
|
+
this.#moved = null;
|
|
238
365
|
}
|
|
366
|
+
// The NodeBindings that read a start this event moved resolve again; their errors follow the closings'.
|
|
367
|
+
errors.push(...this.#rebindDependents(moved.keys, moved.done));
|
|
239
368
|
return errors;
|
|
240
369
|
}
|
|
241
370
|
|
|
@@ -275,7 +404,8 @@ export class BindingRuntime {
|
|
|
275
404
|
this.#disposed = true;
|
|
276
405
|
this.root.unsubscribe(this.#subscription, {any: true});
|
|
277
406
|
this.nodeIds.clear();
|
|
278
|
-
this.#
|
|
407
|
+
this.#dependents.clear();
|
|
408
|
+
this.#collectionStores.clear();
|
|
279
409
|
const errors = [];
|
|
280
410
|
for (const [node, binding] of [...this.#bindings.entries()].reverse()) {
|
|
281
411
|
this.#bindings.delete(node);
|
|
@@ -328,6 +458,10 @@ export class BindingRuntime {
|
|
|
328
458
|
if (errors.length > 1) throw new AggregateError(errors, 'Source branch installation failed');
|
|
329
459
|
throw error;
|
|
330
460
|
}
|
|
461
|
+
// The nodeIds and childnames that entered can be the start a NodeBinding waits for; the
|
|
462
|
+
// NodeBindings installed here resolved them already.
|
|
463
|
+
const installed = nodes.filter(node => !known.has(node));
|
|
464
|
+
this.#moving(installed.flatMap(node => startKeys(node).slice(1)), installed);
|
|
331
465
|
// An `_init` may remove a later node of the branch: each node is checked when its turn comes.
|
|
332
466
|
for (const node of nodes) {
|
|
333
467
|
const binding = this.bindingFor(node);
|
|
@@ -380,7 +514,9 @@ export class BindingRuntime {
|
|
|
380
514
|
}
|
|
381
515
|
if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
|
|
382
516
|
if (current != null) this.nodeIds.set(current, node);
|
|
517
|
+
this.#moving([`id:${previous}`, `id:${current}`]);
|
|
383
518
|
}
|
|
519
|
+
if (Object.hasOwn(diff, 'childname')) this.#moving([`childname:${diff.childname.old}`, `childname:${diff.childname.new}`]);
|
|
384
520
|
if (CONTEXT_ATTRIBUTES.some(name => Object.hasOwn(diff, name))) this.rebindBranch(node);
|
|
385
521
|
else binding.rebind();
|
|
386
522
|
}
|
|
@@ -433,6 +569,8 @@ export class NodeBinding {
|
|
|
433
569
|
// The registration of the node's own variable datapath, read in the parent's context.
|
|
434
570
|
#datapathRegistrations = new Set();
|
|
435
571
|
#storeRegistration = null;
|
|
572
|
+
// The starts of the symbolic resolution read by the registrations (BindingRuntime.dependOn).
|
|
573
|
+
#dependencies = new Set();
|
|
436
574
|
editingSession = null;
|
|
437
575
|
|
|
438
576
|
constructor(runtime, node) {
|
|
@@ -445,6 +583,8 @@ export class NodeBinding {
|
|
|
445
583
|
get closed() { return this.#closed; }
|
|
446
584
|
/** The active DataRegistrations of the node. */
|
|
447
585
|
get registrations() { return [...this.#registrations]; }
|
|
586
|
+
/** The starts of the symbolic resolution read by the active registrations: Source nodes and name keys. */
|
|
587
|
+
get dependencies() { return this.#dependencies; }
|
|
448
588
|
/** The Provider of a `dataFormula`, `dataController`, `dataRpc` or `dataRemote`, as a list of zero or one. */
|
|
449
589
|
get providers() { return this.#provider ? [this.#provider] : []; }
|
|
450
590
|
/** The RemoteBinding of a node whose `remote` attribute is a string, or null. */
|
|
@@ -477,6 +617,10 @@ export class NodeBinding {
|
|
|
477
617
|
* again from its current value.
|
|
478
618
|
*/
|
|
479
619
|
registerPointers() {
|
|
620
|
+
this.runtime.resolveFor(this, () => this.#registerPointers());
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
#registerPointers() {
|
|
480
624
|
// Data elements have semantic lifetime but no rendered item to register their reference.
|
|
481
625
|
if (this.node._getMeta('data_element')) {
|
|
482
626
|
this.runtime.renderer.references.remove(this.node);
|
|
@@ -492,36 +636,41 @@ export class NodeBinding {
|
|
|
492
636
|
}
|
|
493
637
|
const remoteDependencies = new Set();
|
|
494
638
|
const component = node._getMeta('gramlot_component');
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
|
|
502
|
-
}});
|
|
503
|
-
this.#registrations.push({close: () => store.unsubscribe(subscription, {any: true})});
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
639
|
+
// A component that declares `storepath` or `structpath` reads data or structure at that
|
|
640
|
+
// address when it draws: a change inside the Bag and a replacement of the Bag at the
|
|
641
|
+
// address reach the node through one subtree registration.
|
|
642
|
+
for (const attribute of ['storepath', 'structpath']) {
|
|
643
|
+
if (!component?.parameters?.[attribute]) continue;
|
|
644
|
+
const store = attribute === 'storepath';
|
|
506
645
|
const value = node.getAttr(attribute);
|
|
507
646
|
if (typeof value !== 'string' || !value || /^[\^=]/.test(value) || value.includes('?')) {
|
|
508
647
|
throw new TypeError(`${attribute} requires a plain Bag data path`);
|
|
509
648
|
}
|
|
510
|
-
if (
|
|
649
|
+
if (store && node.nodeTag === 'tree' && (value === '*S' || value.startsWith('*S.'))) {
|
|
511
650
|
this.#registrations.push(this.runtime.registerTreeRoot(this, true));
|
|
512
651
|
continue;
|
|
513
652
|
}
|
|
514
|
-
if (
|
|
653
|
+
if (store && node.nodeTag === 'tree' && value === '*D') {
|
|
515
654
|
this.#registrations.push(this.runtime.registerTreeRoot(this, false));
|
|
516
655
|
continue;
|
|
517
656
|
}
|
|
518
|
-
const path =
|
|
657
|
+
const path = store && node.nodeTag === 'tree' && value.startsWith('*D.')
|
|
519
658
|
? value.slice(3) : node.absDatapath(value);
|
|
520
659
|
const registration = this.runtime.router.register({path, recipient: this, subtree: true});
|
|
521
660
|
this.#registrations.push(registration);
|
|
522
661
|
// Grid receives store invalidations separately. Other Bag consumers
|
|
523
662
|
// (such as tree) continue to receive every ordinary Data event.
|
|
524
|
-
if (
|
|
663
|
+
if (store && component.parameters.structpath) this.#storeRegistration = registration;
|
|
664
|
+
}
|
|
665
|
+
// A tree `checked_<attribute>` names a Data path with the legacy syntax `path[:joiner]`: the tree
|
|
666
|
+
// reads that list when it draws, so a change at the path projects the tree again.
|
|
667
|
+
if (node.nodeTag === 'tree') for (const [name, value] of Object.entries(node.getAttr())) {
|
|
668
|
+
if (!name.startsWith('checked_')) continue;
|
|
669
|
+
if (typeof value !== 'string' || !value || /^[\^=]/.test(value)) {
|
|
670
|
+
throw new TypeError(`tree ${name} requires a Data path, optionally followed by :joiner`);
|
|
671
|
+
}
|
|
672
|
+
const path = node.absDatapath(value.split(':')[0]);
|
|
673
|
+
this.#registrations.push(this.runtime.router.register({path, recipient: this}));
|
|
525
674
|
}
|
|
526
675
|
const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr('_timing')) : new Set();
|
|
527
676
|
if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
|
|
@@ -533,7 +682,14 @@ export class NodeBinding {
|
|
|
533
682
|
const absolute = context.absDatapath(pointer);
|
|
534
683
|
if (absolute === null) continue;
|
|
535
684
|
const [path, attr = null] = absolute.split('?', 2);
|
|
536
|
-
|
|
685
|
+
// A component parameter declared with dtype 'X' carries data or structure: a change
|
|
686
|
+
// inside the Bag and a replacement of the Bag at the path reach the node through the
|
|
687
|
+
// same subtree registration, as storepath/structpath above. Write-only parameters
|
|
688
|
+
// are not read by the component and keep the value registration.
|
|
689
|
+
const spec = component?.parameters?.[name];
|
|
690
|
+
const subtree = attr === null && spec !== undefined && spec.binding !== 'write'
|
|
691
|
+
&& [spec.dtype].flat().includes('X');
|
|
692
|
+
const registration = this.runtime.router.register({path, attr, recipient: this, subtree});
|
|
537
693
|
this.#registrations.push(registration);
|
|
538
694
|
if (name === 'datapath') this.#datapathRegistrations.add(registration);
|
|
539
695
|
if (this.remote && (name === 'remote' || name.startsWith('remote_') || remoteDependencies.has(name))) this.#remoteRegistrations.add(registration);
|
|
@@ -649,6 +805,7 @@ export class NodeBinding {
|
|
|
649
805
|
}
|
|
650
806
|
|
|
651
807
|
#closeRegistrations() {
|
|
808
|
+
this.runtime.releaseDependencies(this);
|
|
652
809
|
this.#binder?.unregister();
|
|
653
810
|
for (const registration of this.#registrations.splice(0)) registration.close();
|
|
654
811
|
this.#storeRegistration = null;
|
package/src/builder/binding.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"abstracts": {},
|
|
13
13
|
"elements": {
|
|
14
14
|
"dataBinder": {
|
|
15
|
-
"doc": "Bidirectional subscription between a client Data branch and its page's server store.",
|
|
15
|
+
"doc": "Bidirectional subscription between a client Data branch and its page's server store, or the store of a named connection.",
|
|
16
16
|
"sub_tags": "",
|
|
17
17
|
"parent_tags": null,
|
|
18
18
|
"inherits_from": null,
|
|
@@ -41,6 +41,28 @@
|
|
|
41
41
|
},
|
|
42
42
|
"has_default": false
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
"name": "connection",
|
|
46
|
+
"kind": "positional_or_keyword",
|
|
47
|
+
"role": "attribute",
|
|
48
|
+
"annotation": {
|
|
49
|
+
"kind": "union",
|
|
50
|
+
"items": [
|
|
51
|
+
{
|
|
52
|
+
"kind": "type",
|
|
53
|
+
"module": "builtins",
|
|
54
|
+
"name": "str"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"kind": "type",
|
|
58
|
+
"module": "builtins",
|
|
59
|
+
"name": "NoneType"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"has_default": true,
|
|
64
|
+
"default": null
|
|
65
|
+
},
|
|
44
66
|
{
|
|
45
67
|
"name": "attr",
|
|
46
68
|
"kind": "var_keyword",
|
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import {HtmlBuilder} from '@genrojs/builders';
|
|
7
|
-
import type {Bag} from '@genrojs/bag';
|
|
8
7
|
import type {SourceAttributes, SourceBag, SourceBagNode, ValidateNodeOptions} from '@genrojs/builders';
|
|
9
8
|
import type {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
|
|
10
9
|
import type {SourceReference} from '../references.js';
|
|
11
10
|
import type {NameSyntax} from './name-syntax.js';
|
|
12
11
|
|
|
13
|
-
/** Gramlot Source node
|
|
12
|
+
/** Gramlot Source node. */
|
|
14
13
|
export interface GramlotSourceNode extends SourceBagNode {
|
|
15
14
|
/** Existing shared top toolbar of a frameGrid; never creates a second bar. */
|
|
16
15
|
readonly toolbar: GramlotSourceNode;
|
|
17
|
-
readonly treeStore: Bag | null;
|
|
18
|
-
setTreeStore(bag: Bag | null): void;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
export interface GramlotSourceBag extends SourceBag {
|