@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
|
@@ -17,9 +17,17 @@ export class UploadEngine {
|
|
|
17
17
|
#transfers = new Map();
|
|
18
18
|
#checking = new Set();
|
|
19
19
|
#closed = false;
|
|
20
|
-
|
|
20
|
+
/** The queue lives at the absolute Data `path`; the engine keeps the Data root and the path. */
|
|
21
|
+
constructor({gramlot, window, data, path, operation, onComplete, onChange, getContext}) {
|
|
22
|
+
if (!(data instanceof Bag)) throw new TypeError('uploader requires the Data root Bag');
|
|
23
|
+
if (typeof path !== 'string' || !path) throw new TypeError(`uploader requires a Data path: ${path}`);
|
|
24
|
+
Object.assign(this, {gramlot, window, data, path, operation, onComplete, onChange, getContext});
|
|
25
|
+
}
|
|
26
|
+
/** The queue Bag, read at its address without resolvers at each use. */
|
|
27
|
+
get store() {
|
|
28
|
+
const store = this.data.getItem(this.path, null, true);
|
|
21
29
|
if (!(store instanceof Bag)) throw new TypeError('uploader storepath must resolve to a Bag');
|
|
22
|
-
|
|
30
|
+
return store;
|
|
23
31
|
}
|
|
24
32
|
add(file) {
|
|
25
33
|
if (this.#closed) throw new Error('Uploader is closed');
|
|
@@ -5,14 +5,14 @@ import {Container} from './container.js';
|
|
|
5
5
|
import {UploadEngine, readUploadContext} from './upload-engine.js';
|
|
6
6
|
|
|
7
7
|
export const Uploader = defineComponent({
|
|
8
|
-
name:'uploader', tag:'gramlot-uploader', base:Container, sourceContext:true,
|
|
8
|
+
name:'uploader', tag:'gramlot-uploader', base:Container, sourceContext:true,
|
|
9
9
|
parameters:{operation:{dtype:'T'}, storepath:{dtype:'T'}, contextPath:{dtype:'T',nullable:true,default:null}, accept:{dtype:'T', default:'', binding:'read'},
|
|
10
10
|
multiple:{dtype:'B', default:false, binding:'read'}, autoUpload:{dtype:'B', default:true, binding:'read'},
|
|
11
11
|
manualUpload:{dtype:'B', default:true, binding:'read'},
|
|
12
12
|
disabled:{dtype:'B', default:false, binding:'read'},
|
|
13
13
|
selectedPath:{dtype:'T', nullable:true, default:null, binding:'twoWay'}, onComplete:{dtype:'T', nullable:true, default:null}},
|
|
14
14
|
implementation: Base => class extends Base {
|
|
15
|
-
#context; #
|
|
15
|
+
#context; #engine; #draining = false; #previewUrl = null; #previewId = null;
|
|
16
16
|
#requestedPath; #selectedPath = null;
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
@@ -40,17 +40,19 @@ export const Uploader = defineComponent({
|
|
|
40
40
|
this.drop.addEventListener('drop', event => { if (!this.parameters?.disabled && [...event.dataTransfer.types].includes('Files')) { event.preventDefault(); event.stopPropagation(); this.#add(event.dataTransfer.files); } });
|
|
41
41
|
}
|
|
42
42
|
setSourceContext(context) { this.#context = context; }
|
|
43
|
-
|
|
43
|
+
/** The queue Bag, read at the storepath address at each use; the uploader never keeps it. */
|
|
44
|
+
#storeBag() {
|
|
45
|
+
const store = this.#context.getStaticData(this.#context.attrDatapath('storepath'));
|
|
44
46
|
if (!(store instanceof Bag)) throw new TypeError('uploader storepath must resolve to a Bag');
|
|
45
|
-
|
|
46
|
-
if (changed) {
|
|
47
|
-
this.#clearPreview(); this.#engine?.dispose(); this.#engine = null;
|
|
48
|
-
this.#selectedPath = null; this.#requestedPath = null;
|
|
49
|
-
}
|
|
50
|
-
this.#store = store;
|
|
51
|
-
if (changed && this.#context) this.#context.writeParameter('selectedPath', null);
|
|
47
|
+
return store;
|
|
52
48
|
}
|
|
53
49
|
projectAttributes(attrs, adapt) {
|
|
50
|
+
// A new address is a new queue: the engine of the previous one ends with its selection.
|
|
51
|
+
if (this.#engine && this.#engine.path !== this.#context.attrDatapath('storepath')) {
|
|
52
|
+
this.#clearPreview(); this.#engine.dispose(); this.#engine = null;
|
|
53
|
+
this.#selectedPath = null; this.#requestedPath = null;
|
|
54
|
+
this.#context.writeParameter('selectedPath', null);
|
|
55
|
+
}
|
|
54
56
|
const wasReady = Boolean(this.parameters?.autoUpload && !this.parameters.disabled);
|
|
55
57
|
const rest = super.projectAttributes(attrs, adapt);
|
|
56
58
|
this.input.accept = this.parameters.accept || '';
|
|
@@ -73,9 +75,10 @@ export const Uploader = defineComponent({
|
|
|
73
75
|
return rest;
|
|
74
76
|
}
|
|
75
77
|
#ensureEngine() {
|
|
76
|
-
if (!this.#engine && this.#context && this
|
|
78
|
+
if (!this.#engine && this.#context && this.parameters) {
|
|
77
79
|
const {gramlot, window} = this.#context.upload();
|
|
78
|
-
this.#engine = new UploadEngine({gramlot, window,
|
|
80
|
+
this.#engine = new UploadEngine({gramlot, window, data:this.#context.sourceNode.data,
|
|
81
|
+
path:this.#context.attrDatapath('storepath'), operation:this.parameters.operation,
|
|
79
82
|
onChange:() => this.#render(), getContext:() => readUploadContext(this.#context.sourceNode,this.parameters.contextPath),
|
|
80
83
|
onComplete:(item, result) => this.parameters.onComplete ? this.#context.callLogic(this.parameters.onComplete, {item, result}) : null});
|
|
81
84
|
}
|
|
@@ -109,7 +112,7 @@ export const Uploader = defineComponent({
|
|
|
109
112
|
const engine = this.#engine;
|
|
110
113
|
try {
|
|
111
114
|
while (!this.parameters.disabled && this.#engine === engine) {
|
|
112
|
-
const node =
|
|
115
|
+
const node = engine.store.getNodes().find(item => item.value.getItem('status') === 'queued');
|
|
113
116
|
if (!node) break;
|
|
114
117
|
await engine.start(node.label);
|
|
115
118
|
}
|
|
@@ -147,9 +150,9 @@ export const Uploader = defineComponent({
|
|
|
147
150
|
this.preview.textContent = 'No preview available';
|
|
148
151
|
}
|
|
149
152
|
#render() {
|
|
150
|
-
if (!this.list || !this.#
|
|
153
|
+
if (!this.list || !this.#context) return;
|
|
154
|
+
const nodes = this.#storeBag().getNodes();
|
|
151
155
|
this.list.replaceChildren();
|
|
152
|
-
const nodes = this.#store.getNodes();
|
|
153
156
|
const counts = new Map();
|
|
154
157
|
let loaded = 0, size = 0;
|
|
155
158
|
for (const node of nodes) {
|
|
@@ -160,42 +163,43 @@ export const Uploader = defineComponent({
|
|
|
160
163
|
this.summary.textContent = `${nodes.length} file${nodes.length === 1 ? '' : 's'} — ${loaded}/${size} bytes` +
|
|
161
164
|
[...counts].map(([state, count]) => ` · ${count} ${state}`).join('');
|
|
162
165
|
for (const node of nodes) {
|
|
163
|
-
|
|
166
|
+
// The listeners keep the row key only: the row is read at the queue address when they run.
|
|
167
|
+
const row = node.value, label = node.label, item = this.ownerDocument.createElement('li');
|
|
164
168
|
const select = this.ownerDocument.createElement('button');
|
|
165
169
|
select.type = 'button'; select.textContent = row.getItem('name');
|
|
166
170
|
select.disabled = Boolean(this.parameters.disabled);
|
|
167
|
-
select.setAttribute('aria-pressed', String(
|
|
171
|
+
select.setAttribute('aria-pressed', String(label === this.#selectedPath));
|
|
168
172
|
select.setAttribute('aria-label', `Select ${row.getItem('name')}`);
|
|
169
173
|
select.addEventListener('click', () => {
|
|
170
|
-
this.#select(
|
|
171
|
-
const index = this.#
|
|
174
|
+
this.#select(label);
|
|
175
|
+
const index = this.#storeBag().getNodes().findIndex(item => item.label === label);
|
|
172
176
|
if (index >= 0) this.list.children[index].firstElementChild.focus();
|
|
173
177
|
});
|
|
174
178
|
item.append(select, this.ownerDocument.createTextNode(` — ${row.getItem('status')} (${row.getItem('loaded')}/${row.getItem('size')}) `));
|
|
175
179
|
const state = row.getItem('status');
|
|
176
180
|
if (['preparing','uploading'].includes(state)) {
|
|
177
181
|
const button = this.ownerDocument.createElement('button'); button.textContent = 'Cancel'; button.type = 'button';
|
|
178
|
-
button.addEventListener('click', () => this.#engine.cancel(
|
|
182
|
+
button.addEventListener('click', () => this.#engine.cancel(label)); item.append(button);
|
|
179
183
|
} else if (['failed','cancelled'].includes(state)) {
|
|
180
184
|
const button = this.ownerDocument.createElement('button'); button.textContent = 'Retry'; button.type = 'button'; button.disabled = Boolean(this.parameters.disabled);
|
|
181
|
-
button.addEventListener('click', () => { this.#engine.retry(
|
|
185
|
+
button.addEventListener('click', () => { this.#engine.retry(label); if (this.parameters.autoUpload) void this.#startAll(); }); item.append(button);
|
|
182
186
|
}
|
|
183
187
|
if (state === 'uncertain') {
|
|
184
188
|
const button = this.ownerDocument.createElement('button'); button.textContent = 'Check status'; button.type = 'button';
|
|
185
|
-
button.addEventListener('click', () => void this.#engine.reconcile(
|
|
189
|
+
button.addEventListener('click', () => void this.#engine.reconcile(label)); item.append(button);
|
|
186
190
|
}
|
|
187
191
|
if (['queued','completed','failed','cancelled'].includes(state)) {
|
|
188
|
-
const file = this.#engine?.localFile(
|
|
192
|
+
const file = this.#engine?.localFile(label);
|
|
189
193
|
if (file) {
|
|
190
194
|
const preview = this.ownerDocument.createElement('button'); preview.textContent = 'Preview'; preview.type = 'button';
|
|
191
|
-
preview.addEventListener('click', () => void this.#showPreview(
|
|
195
|
+
preview.addEventListener('click', () => void this.#showPreview(label, file)); item.append(preview);
|
|
192
196
|
}
|
|
193
197
|
const remove = this.ownerDocument.createElement('button'); remove.textContent = 'Remove'; remove.type = 'button';
|
|
194
198
|
remove.disabled = Boolean(this.parameters.disabled);
|
|
195
199
|
remove.addEventListener('click', () => {
|
|
196
|
-
if (this.#engine.remove(
|
|
197
|
-
if (this.#previewId ===
|
|
198
|
-
if (this.#selectedPath ===
|
|
200
|
+
if (this.#engine.remove(label)) {
|
|
201
|
+
if (this.#previewId === label) this.#clearPreview();
|
|
202
|
+
if (this.#selectedPath === label) this.#select(null);
|
|
199
203
|
}
|
|
200
204
|
});
|
|
201
205
|
item.append(remove);
|
package/src/editing-session.d.ts
CHANGED
|
@@ -19,7 +19,10 @@ export class EditingSession {
|
|
|
19
19
|
readonly changeEntries: ReadonlyArray<{path: string; previous: unknown; current: unknown; existed: boolean; exists: boolean}>;
|
|
20
20
|
focusField(path: string): boolean;
|
|
21
21
|
registerNavigator(navigate: (path: string) => boolean): () => void;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Declare derived values (grid formula results, totals) that are never changes; returns the release.
|
|
24
|
+
* An attribute whose name starts with `_dv_` is derived without registration.
|
|
25
|
+
*/
|
|
23
26
|
registerDerived(match: (path: string) => boolean): () => void;
|
|
24
27
|
load(data: Bag): void;
|
|
25
28
|
validate(): Promise<boolean>;
|
package/src/editing-session.js
CHANGED
|
@@ -18,6 +18,7 @@ export class EditingSession {
|
|
|
18
18
|
this.node = node;
|
|
19
19
|
this.runtime = runtime;
|
|
20
20
|
this.registers = new Bag();
|
|
21
|
+
// Field Source nodes are keyed by fullpath and read again from the Source at each use (fieldNode).
|
|
21
22
|
this.validationQueue = new Set();
|
|
22
23
|
this.fields = new Map(); // mounted presentations only
|
|
23
24
|
this.validations = new Map(); // semantic fields, independent of their views
|
|
@@ -50,17 +51,25 @@ export class EditingSession {
|
|
|
50
51
|
this.path = path;
|
|
51
52
|
this.subscription = this.runtime.router.register({path, recipient:this, subtree:true});
|
|
52
53
|
this.updateChanges();
|
|
53
|
-
for (const adapter of this.fields
|
|
54
|
+
for (const [fullpath,adapter] of this.fields) {
|
|
55
|
+
const node = this.fieldNode(fullpath);
|
|
54
56
|
adapter.element.cancelValidation();
|
|
55
|
-
this.clearDraft(
|
|
57
|
+
this.clearDraft(node);
|
|
56
58
|
this.scheduleValidation(adapter);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
/** The field Source node at `fullpath`, below the session's own node. A field the session uses must be there. */
|
|
62
|
+
fieldNode(fullpath) {
|
|
63
|
+
const base = this.node.fullpath;
|
|
64
|
+
const node = fullpath.startsWith(base + '.') ? this.node.value.getNode(fullpath.slice(base.length + 1)) : null;
|
|
65
|
+
if (!node) throw new Error(`Editing field ${fullpath} is missing from the Source of its session.`);
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
59
68
|
get data() { return this.runtime.gramlot.data.getItem(this.path); }
|
|
60
69
|
/**
|
|
61
70
|
* Declare derived values (grid formula results, published totals): `match(path)` receives a path
|
|
62
71
|
* relative to the session, `<path>?<attribute>` for an attribute. Derived values are never changes.
|
|
63
|
-
* Returns the release.
|
|
72
|
+
* Returns the release. An attribute whose name starts with `_dv_` is derived without registration (GC-225).
|
|
64
73
|
*/
|
|
65
74
|
registerDerived(match) {
|
|
66
75
|
this.derived.add(match);
|
|
@@ -69,6 +78,8 @@ export class EditingSession {
|
|
|
69
78
|
return () => { this.derived.delete(match); };
|
|
70
79
|
}
|
|
71
80
|
isDerived(path) {
|
|
81
|
+
const separator = path.indexOf('?');
|
|
82
|
+
if (separator !== -1 && path.startsWith('_dv_', separator + 1)) return true;
|
|
72
83
|
for (const match of this.derived) if (match(path)) return true;
|
|
73
84
|
return false;
|
|
74
85
|
}
|
|
@@ -117,8 +128,8 @@ export class EditingSession {
|
|
|
117
128
|
}
|
|
118
129
|
focusField(path) {
|
|
119
130
|
if (this.disposed) return false;
|
|
120
|
-
for (const adapter of this.fields
|
|
121
|
-
if (fieldPath(
|
|
131
|
+
for (const [fullpath,adapter] of this.fields) {
|
|
132
|
+
if (fieldPath(this.fieldNode(fullpath)) === path && adapter.element.isConnected) {
|
|
122
133
|
adapter.element.control.focus();
|
|
123
134
|
return true;
|
|
124
135
|
}
|
|
@@ -153,33 +164,39 @@ export class EditingSession {
|
|
|
153
164
|
status:invalid ? 'error' : pending || incomplete ? 'pending' : dirty ? 'changed' : 'ok'};
|
|
154
165
|
}
|
|
155
166
|
register(adapter) {
|
|
156
|
-
const
|
|
157
|
-
this.fields.set(
|
|
158
|
-
const field = this.registerField(node,adapter.element.constructor);
|
|
167
|
+
const fullpath = adapter.node.fullpath;
|
|
168
|
+
this.fields.set(fullpath, adapter);
|
|
169
|
+
const field = this.registerField(adapter.node,adapter.element.constructor);
|
|
159
170
|
field.selection = adapter.element.validationSelection();
|
|
160
171
|
this.schedule(() => {
|
|
161
|
-
if (this.fields.get(
|
|
172
|
+
if (this.fields.get(fullpath) !== adapter) return;
|
|
173
|
+
const node = this.fieldNode(fullpath);
|
|
162
174
|
const draft = this.registers.getItem('drafts').getNode(key(node));
|
|
163
|
-
if (draft) { node.formDraft = draft.value; adapter.element.restoreFormDraft(draft.value); }
|
|
175
|
+
if (draft) { node._internal.formDraft = draft.value; adapter.element.restoreFormDraft(draft.value); }
|
|
164
176
|
if (field.result) adapter.element.presentValidation(field.result);
|
|
165
177
|
const errors = this.registers.getItem('errors').getItem(key(node));
|
|
166
178
|
if (errors) adapter.element.error(errors.getNodes().map(n => n.value).join('\n'));
|
|
167
179
|
adapter.element.setFieldState({invalid:Boolean(errors), pending:Boolean(this.fieldStatus(field.path).pending)});
|
|
168
180
|
});
|
|
169
|
-
return () => { this.fields.delete(
|
|
181
|
+
return () => { this.fields.delete(fullpath); };
|
|
170
182
|
}
|
|
171
183
|
/** A real Source declaration can validate without an element or ControlAdapter. */
|
|
172
184
|
registerField(node, component, schedule = true) {
|
|
173
|
-
|
|
185
|
+
const fullpath = node.fullpath;
|
|
186
|
+
let field = this.validations.get(fullpath);
|
|
174
187
|
if (field) return field;
|
|
175
188
|
if (!component.validationExecutor) throw new TypeError('Grid editors require shared input validation.');
|
|
176
|
-
const binding = this.runtime.bindingFor(node)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
189
|
+
const binding = this.runtime.bindingFor(node);
|
|
190
|
+
if (!binding) throw new Error(`Editing field ${fullpath} has no open binding.`);
|
|
191
|
+
// A draft left by a previous registration of this node (a node moved back into the Source) is stale:
|
|
192
|
+
// register() restores the current one from the drafts register.
|
|
193
|
+
delete node._internal.formDraft;
|
|
194
|
+
// The record holds plain values and the component class; binding, context and checks are derived at each use.
|
|
195
|
+
field = {component,run:new ValidationRun(),
|
|
196
|
+
path:fieldPath(node),rules:null,value:undefined,result:null,selection:null};
|
|
197
|
+
this.validations.set(fullpath,field);
|
|
181
198
|
binding.editingSession = this;
|
|
182
|
-
|
|
199
|
+
binding.track(() => this.forgetField(fullpath));
|
|
183
200
|
this.refreshField(node,schedule);
|
|
184
201
|
return field;
|
|
185
202
|
}
|
|
@@ -190,7 +207,11 @@ export class EditingSession {
|
|
|
190
207
|
}
|
|
191
208
|
invalidateValidation() {
|
|
192
209
|
this.validationRevision++;
|
|
193
|
-
if (this.fullValidation)
|
|
210
|
+
if (this.fullValidation) this.cancelActive(this.fullValidation);
|
|
211
|
+
}
|
|
212
|
+
/** Cancel the fields a full validation pass is checking; a field forgotten meanwhile was cancelled by forgetField. */
|
|
213
|
+
cancelActive(pass) {
|
|
214
|
+
for (const fullpath of pass.active) if (this.validations.has(fullpath)) this.cancelValidation(this.fieldNode(fullpath));
|
|
194
215
|
}
|
|
195
216
|
trackValidationDependency(absolute) {
|
|
196
217
|
if (absolute === null || this.validationDependencies.has(absolute)) return;
|
|
@@ -206,37 +227,37 @@ export class EditingSession {
|
|
|
206
227
|
validate() {
|
|
207
228
|
if (this.disposed) return Promise.resolve(false);
|
|
208
229
|
if (this.fullValidation) return this.fullValidation.promise;
|
|
209
|
-
for (const adapter of this.fields
|
|
230
|
+
for (const [fullpath,adapter] of this.fields) if (Object.hasOwn(this.fieldNode(fullpath)._internal,'formDraft')) adapter.commit();
|
|
210
231
|
this.clearValidationDependencies();
|
|
211
232
|
const pass = {revision:this.validationRevision,promise:null,active:new Set(),failed:false,complete:true};
|
|
212
233
|
this.fullValidation = pass;
|
|
213
234
|
this.notify();
|
|
214
235
|
const fields = this.validationFields();
|
|
215
236
|
const current = () => !this.disposed && !pass.failed && pass.revision === this.validationRevision;
|
|
216
|
-
const seen = new
|
|
237
|
+
const seen = new Set();
|
|
217
238
|
const worker = async () => {
|
|
218
239
|
let count = 0;
|
|
219
240
|
while (current()) {
|
|
220
241
|
const next = fields.next();
|
|
221
242
|
if (next.done) return;
|
|
222
|
-
const {node,release} = next.value;
|
|
243
|
+
const {node,release} = next.value, fullpath = node.fullpath;
|
|
223
244
|
try {
|
|
224
|
-
if (seen.has(
|
|
225
|
-
seen.add(
|
|
245
|
+
if (seen.has(fullpath)) continue;
|
|
246
|
+
seen.add(fullpath);
|
|
226
247
|
for (const [name,pointer] of node.pointers()) if (name !== 'value') {
|
|
227
248
|
this.trackValidationDependency((name === 'datapath' ? node.parentNode : node).absDatapath(pointer));
|
|
228
249
|
}
|
|
229
|
-
pass.active.add(
|
|
250
|
+
pass.active.add(fullpath);
|
|
230
251
|
const outcome = await this.validateField(node);
|
|
231
252
|
if (!outcome?.ok) pass.complete = false;
|
|
232
|
-
} finally { pass.active.delete(
|
|
253
|
+
} finally { pass.active.delete(fullpath); release(); }
|
|
233
254
|
if (++count % 20 === 0) await new Promise(resolve => setTimeout(resolve,0));
|
|
234
255
|
}
|
|
235
256
|
};
|
|
236
257
|
pass.promise = Promise.resolve().then(async () => {
|
|
237
258
|
const outcomes = await Promise.allSettled(Array.from({length:8},() => worker().catch(error => {
|
|
238
259
|
pass.failed = true;
|
|
239
|
-
|
|
260
|
+
this.cancelActive(pass);
|
|
240
261
|
throw error;
|
|
241
262
|
})));
|
|
242
263
|
const failure = outcomes.find(outcome => outcome.status === 'rejected');
|
|
@@ -256,18 +277,21 @@ export class EditingSession {
|
|
|
256
277
|
*validationFields() {
|
|
257
278
|
const existing = [...this.validations.keys()];
|
|
258
279
|
for (const fields of this.validationSources) yield* fields();
|
|
259
|
-
for (const
|
|
280
|
+
for (const fullpath of existing) if (this.validations.has(fullpath)) yield {node:this.fieldNode(fullpath),release:() => {}};
|
|
260
281
|
}
|
|
261
|
-
|
|
262
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Called when the field's binding closes, after its node left the Source, or when the session is disposed.
|
|
284
|
+
* The closing binding keeps no further use of the session; after dispose its disposer finds no record.
|
|
285
|
+
*/
|
|
286
|
+
forgetField(fullpath) {
|
|
287
|
+
const field = this.validations.get(fullpath);
|
|
263
288
|
if (!field) return;
|
|
264
|
-
field.run.cancel();
|
|
265
|
-
|
|
266
|
-
this.validations.delete(node); this.validationQueue.delete(node);
|
|
289
|
+
field.run.cancel();
|
|
290
|
+
this.validations.delete(fullpath); this.validationQueue.delete(fullpath);
|
|
267
291
|
for (const name of ['errors','pending']) {
|
|
268
292
|
const parts = this.registers.getItem(name).getItem(encoded(field.path));
|
|
269
293
|
if (parts) {
|
|
270
|
-
for (const part of [...parts.getNodes()]) if (part.label.startsWith(encoded(
|
|
294
|
+
for (const part of [...parts.getNodes()]) if (part.label.startsWith(encoded(fullpath) + ':')) parts.popNode(part.label);
|
|
271
295
|
if (!parts.length) this.registers.getItem(name).popNode(encoded(field.path));
|
|
272
296
|
}
|
|
273
297
|
}
|
|
@@ -275,19 +299,24 @@ export class EditingSession {
|
|
|
275
299
|
const drafts = this.registers.getItem('drafts');
|
|
276
300
|
if (drafts.getNode(encoded(field.path))) drafts.popNode(encoded(field.path));
|
|
277
301
|
}
|
|
278
|
-
delete node.formDraft;
|
|
279
302
|
this.notify();
|
|
280
303
|
}
|
|
304
|
+
/** The validation parameters of the field `node`, its `^`, `=` and `==` resolved. */
|
|
305
|
+
validationParameters(node, component) {
|
|
306
|
+
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
307
|
+
return component.validationParameters(this.runtime.renderer.evaluateExpressions(node,attrs));
|
|
308
|
+
}
|
|
281
309
|
refreshField(node, schedule = true) {
|
|
282
|
-
const field = this.validations.get(node);
|
|
310
|
+
const field = this.validations.get(node.fullpath);
|
|
283
311
|
if (!field || this.disposed || this.writing) return;
|
|
284
|
-
const
|
|
285
|
-
const resolved = field.component.validationParameters(this.runtime.renderer.evaluateExpressions(node,attrs));
|
|
312
|
+
const resolved = this.validationParameters(node,field.component);
|
|
286
313
|
const rules = Object.fromEntries(Object.entries(resolved).filter(([name]) => name.startsWith('validate_')));
|
|
287
314
|
const configuration = toTytx(Object.fromEntries(Object.entries(resolved).filter(([name]) => name !== 'value')));
|
|
288
|
-
|
|
315
|
+
// The field is compared by its Data path and value: a new node at the same path with the same value
|
|
316
|
+
// (a reloaded row) keeps the validation result and the draft.
|
|
317
|
+
const path = fieldPath(node);
|
|
289
318
|
const value = node.getRelativeData(node.getAttr('value'));
|
|
290
|
-
const dataChanged = field.path !== path ||
|
|
319
|
+
const dataChanged = field.path !== path || !same(field.value,value);
|
|
291
320
|
if (!dataChanged && field.configuration === configuration) return;
|
|
292
321
|
if (field.rules !== null) this.invalidateValidation();
|
|
293
322
|
this.cancelValidation(node);
|
|
@@ -297,14 +326,14 @@ export class EditingSession {
|
|
|
297
326
|
if (bag.getNode(encoded(field.path))) bag.popNode(encoded(field.path));
|
|
298
327
|
}
|
|
299
328
|
}
|
|
300
|
-
|
|
301
|
-
|
|
329
|
+
// A null selection is derived from the current parameters at validation time.
|
|
330
|
+
Object.assign(field,{path,value,rules,configuration,result:null,selection:null});
|
|
302
331
|
if (dataChanged) this.clearDraft(node);
|
|
303
332
|
if (schedule) this.scheduleField(node);
|
|
304
333
|
}
|
|
305
334
|
cancelValidation(node) {
|
|
306
|
-
this.validations.get(node)?.run.cancel();
|
|
307
|
-
this.validationQueue.delete(node);
|
|
335
|
+
this.validations.get(node.fullpath)?.run.cancel();
|
|
336
|
+
this.validationQueue.delete(node.fullpath);
|
|
308
337
|
this.pendingPart(node,'validation',null);
|
|
309
338
|
}
|
|
310
339
|
writeCandidate(node,value) {
|
|
@@ -312,63 +341,69 @@ export class EditingSession {
|
|
|
312
341
|
this.writing++;
|
|
313
342
|
try { this.runtime.renderer.html.writeParameter(node,'value',value); }
|
|
314
343
|
finally { this.writing--; }
|
|
315
|
-
const field = this.validations.get(node);
|
|
344
|
+
const field = this.validations.get(node.fullpath);
|
|
316
345
|
if (field) {
|
|
317
346
|
field.value = node.getRelativeData(node.getAttr('value'));
|
|
318
|
-
field.target = this.runtime.gramlot.data.getNode(field.path.split('?')[0]);
|
|
319
347
|
}
|
|
320
|
-
for (const other of this.validations.keys()) if (other !== node) this.refreshField(other);
|
|
348
|
+
for (const other of this.validations.keys()) if (other !== node.fullpath) this.refreshField(this.fieldNode(other));
|
|
321
349
|
}
|
|
322
350
|
validateCandidate(node,value,selection) {
|
|
323
351
|
this.invalidateValidation();
|
|
324
352
|
this.cancelValidation(node);
|
|
325
353
|
this.writeCandidate(node,value);
|
|
326
|
-
const field = this.validations.get(node);
|
|
354
|
+
const field = this.validations.get(node.fullpath);
|
|
327
355
|
field.selection = selection;
|
|
328
356
|
return this.validateField(node,false);
|
|
329
357
|
}
|
|
330
358
|
scheduleField(node) {
|
|
331
|
-
|
|
359
|
+
const fullpath = node.fullpath;
|
|
360
|
+
if (this.disposed || !this.validations.has(fullpath) || this.validationQueue.has(fullpath)) return;
|
|
332
361
|
if (this.registers.getItem('drafts').getNode(key(node))) return;
|
|
333
|
-
this.validationQueue.add(
|
|
362
|
+
this.validationQueue.add(fullpath);
|
|
334
363
|
this.pendingPart(node,'validation','scheduled');
|
|
335
|
-
this.schedule(() => { if (this.validationQueue.delete(
|
|
364
|
+
this.schedule(() => { if (this.validationQueue.delete(fullpath)) this.validateField(this.fieldNode(fullpath)); });
|
|
336
365
|
}
|
|
337
366
|
scheduleValidation(adapter) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
367
|
+
const node = adapter.node;
|
|
368
|
+
this.refreshField(node);
|
|
369
|
+
const field = this.validations.get(node.fullpath);
|
|
370
|
+
if (field && !field.result && !field.run.controller) this.scheduleField(node);
|
|
341
371
|
}
|
|
342
372
|
validateField(node, refreshSelection = true) {
|
|
343
|
-
const field = this.validations.get(
|
|
344
|
-
|
|
345
|
-
this.
|
|
373
|
+
const fullpath = node.fullpath, field = this.validations.get(fullpath);
|
|
374
|
+
// A closed binding has left the runtime map: bindingFor never opens one.
|
|
375
|
+
const binding = this.runtime.bindingFor(node);
|
|
376
|
+
if (!field || this.disposed || !binding || binding.closed) return;
|
|
377
|
+
this.validationQueue.delete(fullpath);
|
|
346
378
|
if (this.registers.getItem('drafts').getNode(key(node))) return;
|
|
347
379
|
if (this.registers.getItem('pending').getItem(key(node))?.getItem(contribution(node,'selection'))) return;
|
|
348
380
|
const value = node.getRelativeData(node.getAttr('value'));
|
|
349
|
-
const adapter = this.fields.get(
|
|
381
|
+
const adapter = this.fields.get(fullpath);
|
|
350
382
|
if (refreshSelection && adapter) field.selection = adapter.element.validationSelection();
|
|
351
|
-
const
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
383
|
+
const component = field.component, context = validationContext(binding);
|
|
384
|
+
const selection = field.selection ?? component.validationSelection(this.validationParameters(node,component),context);
|
|
385
|
+
const checkValue = component.validationValueCheck(context);
|
|
386
|
+
const path = field.path;
|
|
387
|
+
const current = context.validationCurrent();
|
|
388
|
+
return field.run.start(value,field.rules,{...context,
|
|
389
|
+
validationCurrent:() => () => !this.disposed && current() && this.validations.get(fullpath) === field
|
|
390
|
+
&& field.path === path,
|
|
357
391
|
selection
|
|
358
|
-
},
|
|
392
|
+
},component.validationExecutor,outcome => {
|
|
393
|
+
const node = this.fieldNode(fullpath);
|
|
359
394
|
if (outcome.ok) {
|
|
360
|
-
try {
|
|
395
|
+
try { checkValue(outcome.value,value); }
|
|
361
396
|
catch (error) { outcome.ok = false; outcome.result.error = error.message; }
|
|
362
397
|
}
|
|
363
398
|
this.result(node,outcome.result);
|
|
364
399
|
field.result = outcome.result;
|
|
365
400
|
if (outcome.ok) this.writeCandidate(node,outcome.value);
|
|
366
|
-
const mounted = this.fields.get(
|
|
401
|
+
const mounted = this.fields.get(fullpath);
|
|
367
402
|
if (mounted) mounted.element.presentValidation(outcome.result);
|
|
368
|
-
|
|
403
|
+
context.finishValidation(outcome);
|
|
369
404
|
},() => {
|
|
370
|
-
this.pendingPart(
|
|
371
|
-
this.fields.get(
|
|
405
|
+
this.pendingPart(this.fieldNode(fullpath),'validation','active');
|
|
406
|
+
this.fields.get(fullpath)?.element.setFieldState({pending:true});
|
|
372
407
|
});
|
|
373
408
|
}
|
|
374
409
|
remove(name, node) {
|
|
@@ -383,11 +418,11 @@ export class EditingSession {
|
|
|
383
418
|
draft(node, text) {
|
|
384
419
|
this.invalidateValidation();
|
|
385
420
|
this.cancelValidation(node);
|
|
386
|
-
node.formDraft = text;
|
|
421
|
+
node._internal.formDraft = text;
|
|
387
422
|
this.set('drafts',node,text);
|
|
388
423
|
}
|
|
389
424
|
clearDraft(node) {
|
|
390
|
-
delete node.formDraft;
|
|
425
|
+
delete node._internal.formDraft;
|
|
391
426
|
this.set('drafts',node,null);
|
|
392
427
|
this.issue(node,'parse',null);
|
|
393
428
|
}
|
|
@@ -418,7 +453,7 @@ export class EditingSession {
|
|
|
418
453
|
this.updateChanges(change.path);
|
|
419
454
|
if (this.writing) return;
|
|
420
455
|
this.invalidateValidation();
|
|
421
|
-
for (const
|
|
456
|
+
for (const fullpath of this.validations.keys()) this.refreshField(this.fieldNode(fullpath));
|
|
422
457
|
}
|
|
423
458
|
|
|
424
459
|
updateChanges(changedPath = null) {
|
|
@@ -473,15 +508,16 @@ export class EditingSession {
|
|
|
473
508
|
for (const listener of this.listeners) listener(); });
|
|
474
509
|
}
|
|
475
510
|
commitField(path) {
|
|
476
|
-
for (const adapter of this.fields
|
|
477
|
-
|
|
511
|
+
for (const [fullpath,adapter] of this.fields) {
|
|
512
|
+
const node = this.fieldNode(fullpath);
|
|
513
|
+
if (fieldPath(node) === path && Object.hasOwn(node._internal,'formDraft')) adapter.commit();
|
|
478
514
|
}
|
|
479
515
|
}
|
|
480
516
|
/** Flush active drafts. Refuse errors/pending checks; accept only a valid local snapshot. */
|
|
481
517
|
accept() {
|
|
482
518
|
if (this.disposed) return false;
|
|
483
|
-
for (const adapter of this.fields
|
|
484
|
-
if (Object.hasOwn(
|
|
519
|
+
for (const [fullpath,adapter] of this.fields) {
|
|
520
|
+
if (Object.hasOwn(this.fieldNode(fullpath)._internal,'formDraft')) adapter.commit();
|
|
485
521
|
}
|
|
486
522
|
if (!this.status.valid || this.status.pending) return false;
|
|
487
523
|
if (this.validationSources.size && this.validatedRevision !== this.validationRevision) return false;
|
|
@@ -498,23 +534,24 @@ export class EditingSession {
|
|
|
498
534
|
restore() {
|
|
499
535
|
if (this.disposed) return;
|
|
500
536
|
this.invalidateValidation();
|
|
501
|
-
for (const
|
|
502
|
-
for (const adapter of this.fields
|
|
537
|
+
for (const fullpath of this.validations.keys()) this.cancelValidation(this.fieldNode(fullpath));
|
|
538
|
+
for (const [fullpath,adapter] of this.fields) {
|
|
539
|
+
const node = this.fieldNode(fullpath);
|
|
503
540
|
adapter.element.cancelValidation();
|
|
504
|
-
this.clearDraft(
|
|
541
|
+
this.clearDraft(node);
|
|
505
542
|
adapter.element.restoreFormValue(this.registers.getItem('baseline').getItem(
|
|
506
|
-
|
|
543
|
+
node.absDatapath(node.getAttr('value')).slice(this.path ? this.path.length + 1 : 0)));
|
|
507
544
|
}
|
|
508
545
|
this.runtime.gramlot.data.setItem(this.path,copy(this.registers.getItem('baseline')));
|
|
509
546
|
for (const name of ['errors','pending','drafts']) this.registers.setItem(name,new Bag());
|
|
510
547
|
this.updateChanges();
|
|
511
|
-
for (const
|
|
548
|
+
for (const fullpath of this.validations.keys()) this.scheduleField(this.fieldNode(fullpath));
|
|
512
549
|
}
|
|
513
550
|
dispose() {
|
|
514
551
|
if (this.disposed) return;
|
|
515
552
|
this.disposed = true;
|
|
516
553
|
this.subscription.close();
|
|
517
|
-
for (const
|
|
554
|
+
for (const fullpath of this.validations.keys()) this.forgetField(fullpath);
|
|
518
555
|
this.fields.clear();
|
|
519
556
|
this.validationQueue.clear();
|
|
520
557
|
this.retainedFields.clear();
|
|
@@ -21,7 +21,6 @@ export const WindowSelection = defineComponent({
|
|
|
21
21
|
#context;
|
|
22
22
|
#key;
|
|
23
23
|
#viewport;
|
|
24
|
-
#last;
|
|
25
24
|
#request;
|
|
26
25
|
#timer;
|
|
27
26
|
#changingSelection = false;
|
|
@@ -48,7 +47,6 @@ export const WindowSelection = defineComponent({
|
|
|
48
47
|
const previous = this.#key ? JSON.parse(this.#key) : null;
|
|
49
48
|
this.#key = key;
|
|
50
49
|
this.#viewport = JSON.stringify(p.viewport);
|
|
51
|
-
this.#last = p.inbox;
|
|
52
50
|
clearTimeout(this.#timer);
|
|
53
51
|
this.#request = null;
|
|
54
52
|
this.#changingSelection = true;
|
|
@@ -66,11 +64,11 @@ export const WindowSelection = defineComponent({
|
|
|
66
64
|
this.#timer = setTimeout(() => this.#send(p.viewport.start, p.viewport.count, 'scroll', performance.now()), 0);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
if (!frame || frame === this.#last) return;
|
|
71
|
-
this.#last = frame;
|
|
67
|
+
// The reply is read at the inbox address; its request_id, not the Bag, marks its arrival.
|
|
72
68
|
const request = this.#request;
|
|
73
|
-
if (!request
|
|
69
|
+
if (!request) return;
|
|
70
|
+
const frame = this.#context.getStaticData(this.#context.attrDatapath('inbox'));
|
|
71
|
+
if (!frame || frame.getItem('request_id') !== request.id) return;
|
|
74
72
|
this.#request = null;
|
|
75
73
|
this.#changingSelection = false;
|
|
76
74
|
if (frame.getItem('error')) {
|
package/src/filesystem.js
CHANGED
|
@@ -99,11 +99,11 @@ export class FileSystemLogic {
|
|
|
99
99
|
fileSystemMount(node) {
|
|
100
100
|
const scope = node.parentNode;
|
|
101
101
|
const controller = new FileSystemController(this.page, scope);
|
|
102
|
-
|
|
102
|
+
scope._internal.fileSystemController = controller;
|
|
103
103
|
this.page.src.renderer.onDispose(scope, () => controller.dispose());
|
|
104
104
|
}
|
|
105
105
|
fileSystemOpen(node, {root}) {
|
|
106
|
-
if (root) return node.parentNode.fileSystemController.open(root);
|
|
106
|
+
if (root) return node.parentNode._internal.fileSystemController.open(root);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|