@gramlot/gramlot 0.3.35 → 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/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +4 -2
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/addon-fit-L6JK4OJX.js +12 -0
- package/dist/components/editors/assets/modules/xterm-BF3OSWRI.js +286 -0
- package/dist/components/editors/assets/modules/xterm-UBEXZEYY.js +47 -0
- package/dist/components/editors/grammar.json +207 -0
- 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 +1238 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/libraries.json +27 -0
- package/dist/standard-collections.js +1 -1
- package/package.json +4 -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/editors.js +3 -1
- 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/terminal.js +158 -0
- 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/libraries.js +9 -0
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +14 -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 +45 -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/dist/gramlot.js
CHANGED
|
@@ -15815,6 +15815,86 @@ var Handler = class {
|
|
|
15815
15815
|
}
|
|
15816
15816
|
};
|
|
15817
15817
|
|
|
15818
|
+
// src/message-port-connection.js
|
|
15819
|
+
function messageText(message) {
|
|
15820
|
+
const wire = new Bag();
|
|
15821
|
+
for (const [name, value] of Object.entries(message)) {
|
|
15822
|
+
if (value !== void 0) wire.setItem(name, value);
|
|
15823
|
+
}
|
|
15824
|
+
return toTytx(wire);
|
|
15825
|
+
}
|
|
15826
|
+
var MessagePortConnection = class {
|
|
15827
|
+
#port = null;
|
|
15828
|
+
// A protocol error is reported once per port; `closed` is a state and reports nothing.
|
|
15829
|
+
#reported = false;
|
|
15830
|
+
constructor(gramlot, name) {
|
|
15831
|
+
this.gramlot = gramlot;
|
|
15832
|
+
this.name = name;
|
|
15833
|
+
this.binders = /* @__PURE__ */ new Map();
|
|
15834
|
+
this.state = "waiting";
|
|
15835
|
+
this.error = null;
|
|
15836
|
+
}
|
|
15837
|
+
get port() {
|
|
15838
|
+
return this.#port;
|
|
15839
|
+
}
|
|
15840
|
+
/**
|
|
15841
|
+
* Carry the binders on `port`, or on none for null. The binders leave the previous port and
|
|
15842
|
+
* subscribe again on the new one: each snapshot replaces the branch of its binder.
|
|
15843
|
+
*/
|
|
15844
|
+
setPort(port) {
|
|
15845
|
+
if (port === this.#port) return;
|
|
15846
|
+
this.#release();
|
|
15847
|
+
this.#port = port;
|
|
15848
|
+
this.error = null;
|
|
15849
|
+
this.#reported = false;
|
|
15850
|
+
this.state = port ? "open" : "waiting";
|
|
15851
|
+
if (!port) return;
|
|
15852
|
+
port.addEventListener("message", this.#receive);
|
|
15853
|
+
port.start();
|
|
15854
|
+
for (const binder of this.binders.values()) this.#subscribe(binder);
|
|
15855
|
+
}
|
|
15856
|
+
#release() {
|
|
15857
|
+
const port = this.#port;
|
|
15858
|
+
if (!port) return;
|
|
15859
|
+
port.removeEventListener("message", this.#receive);
|
|
15860
|
+
for (const binder of this.binders.values()) {
|
|
15861
|
+
binder.ready = false;
|
|
15862
|
+
if (this.state === "open") port.postMessage(messageText({ op: "unsubscribe", binderId: binder.id }));
|
|
15863
|
+
}
|
|
15864
|
+
this.#port = null;
|
|
15865
|
+
}
|
|
15866
|
+
register(binder) {
|
|
15867
|
+
this.binders.set(binder.id, binder);
|
|
15868
|
+
if (this.state === "open") this.#subscribe(binder);
|
|
15869
|
+
}
|
|
15870
|
+
#subscribe(binder) {
|
|
15871
|
+
this.#port.postMessage(messageText({ op: "subscribe", binderId: binder.id, path: binder.serverPath }));
|
|
15872
|
+
}
|
|
15873
|
+
unregister(binder) {
|
|
15874
|
+
if (!this.binders.delete(binder.id)) return;
|
|
15875
|
+
if (this.state === "open") this.#port.postMessage(messageText({ op: "unsubscribe", binderId: binder.id }));
|
|
15876
|
+
}
|
|
15877
|
+
send(message) {
|
|
15878
|
+
if (this.state !== "open") throw new Error(`Connection '${this.name}' is not open`);
|
|
15879
|
+
this.#port.postMessage(messageText(message));
|
|
15880
|
+
}
|
|
15881
|
+
#receive = (event) => {
|
|
15882
|
+
const message = fromTytx(event.data).asDict();
|
|
15883
|
+
if (message.op === "snapshot" || message.op === "change") this.binders.get(message.binderId)?.apply(message);
|
|
15884
|
+
else if (message.op === "closed") this.#closed();
|
|
15885
|
+
else if (message.op === "error" && !this.#reported) {
|
|
15886
|
+
this.#reported = true;
|
|
15887
|
+
this.gramlot.src.binding.reportError(new Error(`Connection '${this.name}': ${message.error}`), "dataBinder");
|
|
15888
|
+
}
|
|
15889
|
+
};
|
|
15890
|
+
/** The other end closed: the binders stop and their copies keep the last values. */
|
|
15891
|
+
#closed() {
|
|
15892
|
+
this.state = "closed";
|
|
15893
|
+
this.#release();
|
|
15894
|
+
this.error = new Error(`Connection '${this.name}' was closed by the other end`);
|
|
15895
|
+
}
|
|
15896
|
+
};
|
|
15897
|
+
|
|
15818
15898
|
// src/handlers/rpc-handler.js
|
|
15819
15899
|
var RpcError = class extends Error {
|
|
15820
15900
|
name = "RpcError";
|
|
@@ -15830,6 +15910,23 @@ var RpcHandler = class extends Handler {
|
|
|
15830
15910
|
super(gramlot);
|
|
15831
15911
|
this.transport = transport === false ? null : transport ?? gramlot.serverAdapter.createTransport({ rpcUrl, closeUrl, document, channel: gramlot._pageStore });
|
|
15832
15912
|
this.remoteRequests = /* @__PURE__ */ new Map();
|
|
15913
|
+
this.connections = /* @__PURE__ */ new Map();
|
|
15914
|
+
}
|
|
15915
|
+
/** The dataBinder connection of `name`; created waiting for a port when the name is new. */
|
|
15916
|
+
connection(name) {
|
|
15917
|
+
if (!this.connections.has(name)) this.connections.set(name, new MessagePortConnection(this.gramlot, name));
|
|
15918
|
+
return this.connections.get(name);
|
|
15919
|
+
}
|
|
15920
|
+
/** Carry the binders of the connection `name` on `port`; a new port replaces the previous one. */
|
|
15921
|
+
registerConnection(name, port) {
|
|
15922
|
+
this.connection(name).setPort(port);
|
|
15923
|
+
}
|
|
15924
|
+
/** Release the port of the connection `name`: its binders wait for the next port. */
|
|
15925
|
+
unregisterConnection(name) {
|
|
15926
|
+
const connection = this.connections.get(name);
|
|
15927
|
+
if (!connection) return;
|
|
15928
|
+
connection.setPort(null);
|
|
15929
|
+
if (!connection.binders.size) this.connections.delete(name);
|
|
15833
15930
|
}
|
|
15834
15931
|
/**
|
|
15835
15932
|
* Send one envelope of `contentType` to `name` with `params`; resolves with the value or rejects with an
|
|
@@ -15927,6 +16024,13 @@ var PageStoreConnection = class {
|
|
|
15927
16024
|
this.address = address;
|
|
15928
16025
|
if (!this.parent) this.open();
|
|
15929
16026
|
}
|
|
16027
|
+
/** The address of the terminal socket of `session` for this page: `terminal` beside the store route. */
|
|
16028
|
+
terminalUrl(session) {
|
|
16029
|
+
const address = new URL("terminal", this.endpoint);
|
|
16030
|
+
address.searchParams.set("pageId", this.gramlot.pageId);
|
|
16031
|
+
address.searchParams.set("session", session);
|
|
16032
|
+
return address.href;
|
|
16033
|
+
}
|
|
15930
16034
|
/** Opens this page's own WebSocket: the page is the root of its family channel. */
|
|
15931
16035
|
open() {
|
|
15932
16036
|
const address = this.address;
|
|
@@ -16086,10 +16190,15 @@ var PageStoreConnection = class {
|
|
|
16086
16190
|
this.fail(error);
|
|
16087
16191
|
}
|
|
16088
16192
|
}
|
|
16193
|
+
/**
|
|
16194
|
+
* The first failure of an open channel is reported once. `Gramlot.dispose`, also on the
|
|
16195
|
+
* page's own pagehide, closes the channel first: a later failure reports nothing.
|
|
16196
|
+
*/
|
|
16089
16197
|
fail(error) {
|
|
16198
|
+
const report = !this.closed;
|
|
16090
16199
|
this.error = error;
|
|
16091
16200
|
this.close();
|
|
16092
|
-
this.
|
|
16201
|
+
if (report) this.gramlot.src.binding.reportError(error, "PageStore channel failed");
|
|
16093
16202
|
}
|
|
16094
16203
|
close() {
|
|
16095
16204
|
if (this.closed) return;
|
|
@@ -16666,7 +16775,7 @@ function annotation2(parameter) {
|
|
|
16666
16775
|
});
|
|
16667
16776
|
return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
|
|
16668
16777
|
}
|
|
16669
|
-
function defineComponent({ name, tag: tag2, base, doc = null, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false,
|
|
16778
|
+
function defineComponent({ name, tag: tag2, base, doc = null, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, dragSource = false, implementation }) {
|
|
16670
16779
|
webcomponentCode({ code: tag2 });
|
|
16671
16780
|
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
|
|
16672
16781
|
const effective = { ...base.parameters };
|
|
@@ -16690,8 +16799,6 @@ function defineComponent({ name, tag: tag2, base, doc = null, mixins = [], param
|
|
|
16690
16799
|
presentationDefaults: Object.freeze([...presentationDefaults]),
|
|
16691
16800
|
dataScope,
|
|
16692
16801
|
command,
|
|
16693
|
-
bagStore,
|
|
16694
|
-
bagStruct,
|
|
16695
16802
|
mixins: Object.freeze([...mixins]),
|
|
16696
16803
|
labelbox: mixins.some((mixin) => mixin.labelbox === true),
|
|
16697
16804
|
parameters: freeze(structuredClone(effective)),
|
|
@@ -16771,9 +16878,7 @@ var ComponentCollection = class _ComponentCollection {
|
|
|
16771
16878
|
...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
|
|
16772
16879
|
...component.sourceContext ? { sourceContext: true } : {},
|
|
16773
16880
|
...component.labelbox ? { labelbox: true } : {},
|
|
16774
|
-
...component.dragSource ? { dragSource: true } : {}
|
|
16775
|
-
...component.bagStore ? { bagStore: true } : {},
|
|
16776
|
-
...component.bagStruct ? { bagStruct: true } : {}
|
|
16881
|
+
...component.dragSource ? { dragSource: true } : {}
|
|
16777
16882
|
} }
|
|
16778
16883
|
}]))
|
|
16779
16884
|
};
|
|
@@ -18638,19 +18743,27 @@ var EditingSession = class {
|
|
|
18638
18743
|
this.path = path;
|
|
18639
18744
|
this.subscription = this.runtime.router.register({ path, recipient: this, subtree: true });
|
|
18640
18745
|
this.updateChanges();
|
|
18641
|
-
for (const adapter of this.fields
|
|
18746
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
18747
|
+
const node = this.fieldNode(fullpath);
|
|
18642
18748
|
adapter.element.cancelValidation();
|
|
18643
|
-
this.clearDraft(
|
|
18749
|
+
this.clearDraft(node);
|
|
18644
18750
|
this.scheduleValidation(adapter);
|
|
18645
18751
|
}
|
|
18646
18752
|
}
|
|
18753
|
+
/** The field Source node at `fullpath`, below the session's own node. A field the session uses must be there. */
|
|
18754
|
+
fieldNode(fullpath) {
|
|
18755
|
+
const base = this.node.fullpath;
|
|
18756
|
+
const node = fullpath.startsWith(base + ".") ? this.node.value.getNode(fullpath.slice(base.length + 1)) : null;
|
|
18757
|
+
if (!node) throw new Error(`Editing field ${fullpath} is missing from the Source of its session.`);
|
|
18758
|
+
return node;
|
|
18759
|
+
}
|
|
18647
18760
|
get data() {
|
|
18648
18761
|
return this.runtime.gramlot.data.getItem(this.path);
|
|
18649
18762
|
}
|
|
18650
18763
|
/**
|
|
18651
18764
|
* Declare derived values (grid formula results, published totals): `match(path)` receives a path
|
|
18652
18765
|
* relative to the session, `<path>?<attribute>` for an attribute. Derived values are never changes.
|
|
18653
|
-
* Returns the release.
|
|
18766
|
+
* Returns the release. An attribute whose name starts with `_dv_` is derived without registration (GC-225).
|
|
18654
18767
|
*/
|
|
18655
18768
|
registerDerived(match) {
|
|
18656
18769
|
this.derived.add(match);
|
|
@@ -18660,6 +18773,8 @@ var EditingSession = class {
|
|
|
18660
18773
|
};
|
|
18661
18774
|
}
|
|
18662
18775
|
isDerived(path) {
|
|
18776
|
+
const separator = path.indexOf("?");
|
|
18777
|
+
if (separator !== -1 && path.startsWith("_dv_", separator + 1)) return true;
|
|
18663
18778
|
for (const match of this.derived) if (match(path)) return true;
|
|
18664
18779
|
return false;
|
|
18665
18780
|
}
|
|
@@ -18715,8 +18830,8 @@ var EditingSession = class {
|
|
|
18715
18830
|
}
|
|
18716
18831
|
focusField(path) {
|
|
18717
18832
|
if (this.disposed) return false;
|
|
18718
|
-
for (const adapter of this.fields
|
|
18719
|
-
if (fieldPath(
|
|
18833
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
18834
|
+
if (fieldPath(this.fieldNode(fullpath)) === path && adapter.element.isConnected) {
|
|
18720
18835
|
adapter.element.control.focus();
|
|
18721
18836
|
return true;
|
|
18722
18837
|
}
|
|
@@ -18763,15 +18878,16 @@ var EditingSession = class {
|
|
|
18763
18878
|
};
|
|
18764
18879
|
}
|
|
18765
18880
|
register(adapter) {
|
|
18766
|
-
const
|
|
18767
|
-
this.fields.set(
|
|
18768
|
-
const field = this.registerField(node, adapter.element.constructor);
|
|
18881
|
+
const fullpath = adapter.node.fullpath;
|
|
18882
|
+
this.fields.set(fullpath, adapter);
|
|
18883
|
+
const field = this.registerField(adapter.node, adapter.element.constructor);
|
|
18769
18884
|
field.selection = adapter.element.validationSelection();
|
|
18770
18885
|
this.schedule(() => {
|
|
18771
|
-
if (this.fields.get(
|
|
18886
|
+
if (this.fields.get(fullpath) !== adapter) return;
|
|
18887
|
+
const node = this.fieldNode(fullpath);
|
|
18772
18888
|
const draft = this.registers.getItem("drafts").getNode(key(node));
|
|
18773
18889
|
if (draft) {
|
|
18774
|
-
node.formDraft = draft.value;
|
|
18890
|
+
node._internal.formDraft = draft.value;
|
|
18775
18891
|
adapter.element.restoreFormDraft(draft.value);
|
|
18776
18892
|
}
|
|
18777
18893
|
if (field.result) adapter.element.presentValidation(field.result);
|
|
@@ -18780,33 +18896,30 @@ var EditingSession = class {
|
|
|
18780
18896
|
adapter.element.setFieldState({ invalid: Boolean(errors), pending: Boolean(this.fieldStatus(field.path).pending) });
|
|
18781
18897
|
});
|
|
18782
18898
|
return () => {
|
|
18783
|
-
this.fields.delete(
|
|
18899
|
+
this.fields.delete(fullpath);
|
|
18784
18900
|
};
|
|
18785
18901
|
}
|
|
18786
18902
|
/** A real Source declaration can validate without an element or ControlAdapter. */
|
|
18787
18903
|
registerField(node, component, schedule = true) {
|
|
18788
|
-
|
|
18904
|
+
const fullpath = node.fullpath;
|
|
18905
|
+
let field = this.validations.get(fullpath);
|
|
18789
18906
|
if (field) return field;
|
|
18790
18907
|
if (!component.validationExecutor) throw new TypeError("Grid editors require shared input validation.");
|
|
18791
|
-
const binding = this.runtime.bindingFor(node)
|
|
18908
|
+
const binding = this.runtime.bindingFor(node);
|
|
18909
|
+
if (!binding) throw new Error(`Editing field ${fullpath} has no open binding.`);
|
|
18910
|
+
delete node._internal.formDraft;
|
|
18792
18911
|
field = {
|
|
18793
|
-
node,
|
|
18794
|
-
binding,
|
|
18795
|
-
context,
|
|
18796
18912
|
component,
|
|
18797
18913
|
run: new ValidationRun(),
|
|
18798
|
-
execute: component.validationExecutor,
|
|
18799
|
-
checkValue: component.validationValueCheck(context),
|
|
18800
18914
|
path: fieldPath(node),
|
|
18801
18915
|
rules: null,
|
|
18802
18916
|
value: void 0,
|
|
18803
|
-
target: null,
|
|
18804
18917
|
result: null,
|
|
18805
18918
|
selection: null
|
|
18806
18919
|
};
|
|
18807
|
-
this.validations.set(
|
|
18920
|
+
this.validations.set(fullpath, field);
|
|
18808
18921
|
binding.editingSession = this;
|
|
18809
|
-
|
|
18922
|
+
binding.track(() => this.forgetField(fullpath));
|
|
18810
18923
|
this.refreshField(node, schedule);
|
|
18811
18924
|
return field;
|
|
18812
18925
|
}
|
|
@@ -18820,7 +18933,11 @@ var EditingSession = class {
|
|
|
18820
18933
|
}
|
|
18821
18934
|
invalidateValidation() {
|
|
18822
18935
|
this.validationRevision++;
|
|
18823
|
-
if (this.fullValidation)
|
|
18936
|
+
if (this.fullValidation) this.cancelActive(this.fullValidation);
|
|
18937
|
+
}
|
|
18938
|
+
/** Cancel the fields a full validation pass is checking; a field forgotten meanwhile was cancelled by forgetField. */
|
|
18939
|
+
cancelActive(pass) {
|
|
18940
|
+
for (const fullpath of pass.active) if (this.validations.has(fullpath)) this.cancelValidation(this.fieldNode(fullpath));
|
|
18824
18941
|
}
|
|
18825
18942
|
trackValidationDependency(absolute) {
|
|
18826
18943
|
if (absolute === null || this.validationDependencies.has(absolute)) return;
|
|
@@ -18840,31 +18957,31 @@ var EditingSession = class {
|
|
|
18840
18957
|
validate() {
|
|
18841
18958
|
if (this.disposed) return Promise.resolve(false);
|
|
18842
18959
|
if (this.fullValidation) return this.fullValidation.promise;
|
|
18843
|
-
for (const adapter of this.fields
|
|
18960
|
+
for (const [fullpath, adapter] of this.fields) if (Object.hasOwn(this.fieldNode(fullpath)._internal, "formDraft")) adapter.commit();
|
|
18844
18961
|
this.clearValidationDependencies();
|
|
18845
18962
|
const pass = { revision: this.validationRevision, promise: null, active: /* @__PURE__ */ new Set(), failed: false, complete: true };
|
|
18846
18963
|
this.fullValidation = pass;
|
|
18847
18964
|
this.notify();
|
|
18848
18965
|
const fields = this.validationFields();
|
|
18849
18966
|
const current = () => !this.disposed && !pass.failed && pass.revision === this.validationRevision;
|
|
18850
|
-
const seen = /* @__PURE__ */ new
|
|
18967
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18851
18968
|
const worker = async () => {
|
|
18852
18969
|
let count = 0;
|
|
18853
18970
|
while (current()) {
|
|
18854
18971
|
const next = fields.next();
|
|
18855
18972
|
if (next.done) return;
|
|
18856
|
-
const { node, release } = next.value;
|
|
18973
|
+
const { node, release } = next.value, fullpath = node.fullpath;
|
|
18857
18974
|
try {
|
|
18858
|
-
if (seen.has(
|
|
18859
|
-
seen.add(
|
|
18975
|
+
if (seen.has(fullpath)) continue;
|
|
18976
|
+
seen.add(fullpath);
|
|
18860
18977
|
for (const [name, pointer] of node.pointers()) if (name !== "value") {
|
|
18861
18978
|
this.trackValidationDependency((name === "datapath" ? node.parentNode : node).absDatapath(pointer));
|
|
18862
18979
|
}
|
|
18863
|
-
pass.active.add(
|
|
18980
|
+
pass.active.add(fullpath);
|
|
18864
18981
|
const outcome = await this.validateField(node);
|
|
18865
18982
|
if (!outcome?.ok) pass.complete = false;
|
|
18866
18983
|
} finally {
|
|
18867
|
-
pass.active.delete(
|
|
18984
|
+
pass.active.delete(fullpath);
|
|
18868
18985
|
release();
|
|
18869
18986
|
}
|
|
18870
18987
|
if (++count % 20 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -18873,7 +18990,7 @@ var EditingSession = class {
|
|
|
18873
18990
|
pass.promise = Promise.resolve().then(async () => {
|
|
18874
18991
|
const outcomes = await Promise.allSettled(Array.from({ length: 8 }, () => worker().catch((error) => {
|
|
18875
18992
|
pass.failed = true;
|
|
18876
|
-
|
|
18993
|
+
this.cancelActive(pass);
|
|
18877
18994
|
throw error;
|
|
18878
18995
|
})));
|
|
18879
18996
|
const failure2 = outcomes.find((outcome) => outcome.status === "rejected");
|
|
@@ -18892,21 +19009,23 @@ var EditingSession = class {
|
|
|
18892
19009
|
*validationFields() {
|
|
18893
19010
|
const existing = [...this.validations.keys()];
|
|
18894
19011
|
for (const fields of this.validationSources) yield* fields();
|
|
18895
|
-
for (const
|
|
19012
|
+
for (const fullpath of existing) if (this.validations.has(fullpath)) yield { node: this.fieldNode(fullpath), release: () => {
|
|
18896
19013
|
} };
|
|
18897
19014
|
}
|
|
18898
|
-
|
|
18899
|
-
|
|
19015
|
+
/**
|
|
19016
|
+
* Called when the field's binding closes, after its node left the Source, or when the session is disposed.
|
|
19017
|
+
* The closing binding keeps no further use of the session; after dispose its disposer finds no record.
|
|
19018
|
+
*/
|
|
19019
|
+
forgetField(fullpath) {
|
|
19020
|
+
const field = this.validations.get(fullpath);
|
|
18900
19021
|
if (!field) return;
|
|
18901
19022
|
field.run.cancel();
|
|
18902
|
-
|
|
18903
|
-
|
|
18904
|
-
this.validations.delete(node);
|
|
18905
|
-
this.validationQueue.delete(node);
|
|
19023
|
+
this.validations.delete(fullpath);
|
|
19024
|
+
this.validationQueue.delete(fullpath);
|
|
18906
19025
|
for (const name of ["errors", "pending"]) {
|
|
18907
19026
|
const parts2 = this.registers.getItem(name).getItem(encoded(field.path));
|
|
18908
19027
|
if (parts2) {
|
|
18909
|
-
for (const part of [...parts2.getNodes()]) if (part.label.startsWith(encoded(
|
|
19028
|
+
for (const part of [...parts2.getNodes()]) if (part.label.startsWith(encoded(fullpath) + ":")) parts2.popNode(part.label);
|
|
18910
19029
|
if (!parts2.length) this.registers.getItem(name).popNode(encoded(field.path));
|
|
18911
19030
|
}
|
|
18912
19031
|
}
|
|
@@ -18914,19 +19033,22 @@ var EditingSession = class {
|
|
|
18914
19033
|
const drafts = this.registers.getItem("drafts");
|
|
18915
19034
|
if (drafts.getNode(encoded(field.path))) drafts.popNode(encoded(field.path));
|
|
18916
19035
|
}
|
|
18917
|
-
delete node.formDraft;
|
|
18918
19036
|
this.notify();
|
|
18919
19037
|
}
|
|
19038
|
+
/** The validation parameters of the field `node`, its `^`, `=` and `==` resolved. */
|
|
19039
|
+
validationParameters(node, component) {
|
|
19040
|
+
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
19041
|
+
return component.validationParameters(this.runtime.renderer.evaluateExpressions(node, attrs));
|
|
19042
|
+
}
|
|
18920
19043
|
refreshField(node, schedule = true) {
|
|
18921
|
-
const field = this.validations.get(node);
|
|
19044
|
+
const field = this.validations.get(node.fullpath);
|
|
18922
19045
|
if (!field || this.disposed || this.writing) return;
|
|
18923
|
-
const
|
|
18924
|
-
const resolved2 = field.component.validationParameters(this.runtime.renderer.evaluateExpressions(node, attrs));
|
|
19046
|
+
const resolved2 = this.validationParameters(node, field.component);
|
|
18925
19047
|
const rules = Object.fromEntries(Object.entries(resolved2).filter(([name]) => name.startsWith("validate_")));
|
|
18926
19048
|
const configuration = toTytx(Object.fromEntries(Object.entries(resolved2).filter(([name]) => name !== "value")));
|
|
18927
|
-
const path = fieldPath(node)
|
|
19049
|
+
const path = fieldPath(node);
|
|
18928
19050
|
const value = node.getRelativeData(node.getAttr("value"));
|
|
18929
|
-
const dataChanged = field.path !== path ||
|
|
19051
|
+
const dataChanged = field.path !== path || !same(field.value, value);
|
|
18930
19052
|
if (!dataChanged && field.configuration === configuration) return;
|
|
18931
19053
|
if (field.rules !== null) this.invalidateValidation();
|
|
18932
19054
|
this.cancelValidation(node);
|
|
@@ -18936,21 +19058,13 @@ var EditingSession = class {
|
|
|
18936
19058
|
if (bag.getNode(encoded(field.path))) bag.popNode(encoded(field.path));
|
|
18937
19059
|
}
|
|
18938
19060
|
}
|
|
18939
|
-
Object.assign(field, {
|
|
18940
|
-
path,
|
|
18941
|
-
target,
|
|
18942
|
-
value,
|
|
18943
|
-
rules,
|
|
18944
|
-
configuration,
|
|
18945
|
-
result: null,
|
|
18946
|
-
selection: field.component.validationSelection(resolved2, field.context)
|
|
18947
|
-
});
|
|
19061
|
+
Object.assign(field, { path, value, rules, configuration, result: null, selection: null });
|
|
18948
19062
|
if (dataChanged) this.clearDraft(node);
|
|
18949
19063
|
if (schedule) this.scheduleField(node);
|
|
18950
19064
|
}
|
|
18951
19065
|
cancelValidation(node) {
|
|
18952
|
-
this.validations.get(node)?.run.cancel();
|
|
18953
|
-
this.validationQueue.delete(node);
|
|
19066
|
+
this.validations.get(node.fullpath)?.run.cancel();
|
|
19067
|
+
this.validationQueue.delete(node.fullpath);
|
|
18954
19068
|
this.pendingPart(node, "validation", null);
|
|
18955
19069
|
}
|
|
18956
19070
|
writeCandidate(node, value) {
|
|
@@ -18961,69 +19075,74 @@ var EditingSession = class {
|
|
|
18961
19075
|
} finally {
|
|
18962
19076
|
this.writing--;
|
|
18963
19077
|
}
|
|
18964
|
-
const field = this.validations.get(node);
|
|
19078
|
+
const field = this.validations.get(node.fullpath);
|
|
18965
19079
|
if (field) {
|
|
18966
19080
|
field.value = node.getRelativeData(node.getAttr("value"));
|
|
18967
|
-
field.target = this.runtime.gramlot.data.getNode(field.path.split("?")[0]);
|
|
18968
19081
|
}
|
|
18969
|
-
for (const other of this.validations.keys()) if (other !== node) this.refreshField(other);
|
|
19082
|
+
for (const other of this.validations.keys()) if (other !== node.fullpath) this.refreshField(this.fieldNode(other));
|
|
18970
19083
|
}
|
|
18971
19084
|
validateCandidate(node, value, selection) {
|
|
18972
19085
|
this.invalidateValidation();
|
|
18973
19086
|
this.cancelValidation(node);
|
|
18974
19087
|
this.writeCandidate(node, value);
|
|
18975
|
-
const field = this.validations.get(node);
|
|
19088
|
+
const field = this.validations.get(node.fullpath);
|
|
18976
19089
|
field.selection = selection;
|
|
18977
19090
|
return this.validateField(node, false);
|
|
18978
19091
|
}
|
|
18979
19092
|
scheduleField(node) {
|
|
18980
|
-
|
|
19093
|
+
const fullpath = node.fullpath;
|
|
19094
|
+
if (this.disposed || !this.validations.has(fullpath) || this.validationQueue.has(fullpath)) return;
|
|
18981
19095
|
if (this.registers.getItem("drafts").getNode(key(node))) return;
|
|
18982
|
-
this.validationQueue.add(
|
|
19096
|
+
this.validationQueue.add(fullpath);
|
|
18983
19097
|
this.pendingPart(node, "validation", "scheduled");
|
|
18984
19098
|
this.schedule(() => {
|
|
18985
|
-
if (this.validationQueue.delete(
|
|
19099
|
+
if (this.validationQueue.delete(fullpath)) this.validateField(this.fieldNode(fullpath));
|
|
18986
19100
|
});
|
|
18987
19101
|
}
|
|
18988
19102
|
scheduleValidation(adapter) {
|
|
18989
|
-
|
|
18990
|
-
|
|
18991
|
-
|
|
19103
|
+
const node = adapter.node;
|
|
19104
|
+
this.refreshField(node);
|
|
19105
|
+
const field = this.validations.get(node.fullpath);
|
|
19106
|
+
if (field && !field.result && !field.run.controller) this.scheduleField(node);
|
|
18992
19107
|
}
|
|
18993
19108
|
validateField(node, refreshSelection = true) {
|
|
18994
|
-
const field = this.validations.get(
|
|
18995
|
-
|
|
18996
|
-
this.
|
|
19109
|
+
const fullpath = node.fullpath, field = this.validations.get(fullpath);
|
|
19110
|
+
const binding = this.runtime.bindingFor(node);
|
|
19111
|
+
if (!field || this.disposed || !binding || binding.closed) return;
|
|
19112
|
+
this.validationQueue.delete(fullpath);
|
|
18997
19113
|
if (this.registers.getItem("drafts").getNode(key(node))) return;
|
|
18998
19114
|
if (this.registers.getItem("pending").getItem(key(node))?.getItem(contribution(node, "selection"))) return;
|
|
18999
19115
|
const value = node.getRelativeData(node.getAttr("value"));
|
|
19000
|
-
const adapter = this.fields.get(
|
|
19116
|
+
const adapter = this.fields.get(fullpath);
|
|
19001
19117
|
if (refreshSelection && adapter) field.selection = adapter.element.validationSelection();
|
|
19002
|
-
const
|
|
19003
|
-
const
|
|
19004
|
-
const
|
|
19118
|
+
const component = field.component, context = validationContext(binding);
|
|
19119
|
+
const selection = field.selection ?? component.validationSelection(this.validationParameters(node, component), context);
|
|
19120
|
+
const checkValue = component.validationValueCheck(context);
|
|
19121
|
+
const path = field.path;
|
|
19122
|
+
const current = context.validationCurrent();
|
|
19005
19123
|
return field.run.start(value, field.rules, {
|
|
19006
|
-
...
|
|
19007
|
-
validationCurrent: () => () => !this.disposed && current() && this.validations.get(
|
|
19124
|
+
...context,
|
|
19125
|
+
validationCurrent: () => () => !this.disposed && current() && this.validations.get(fullpath) === field && field.path === path,
|
|
19008
19126
|
selection
|
|
19009
|
-
},
|
|
19127
|
+
}, component.validationExecutor, (outcome) => {
|
|
19128
|
+
const node2 = this.fieldNode(fullpath);
|
|
19010
19129
|
if (outcome.ok) {
|
|
19011
19130
|
try {
|
|
19012
|
-
|
|
19131
|
+
checkValue(outcome.value, value);
|
|
19013
19132
|
} catch (error) {
|
|
19014
19133
|
outcome.ok = false;
|
|
19015
19134
|
outcome.result.error = error.message;
|
|
19016
19135
|
}
|
|
19017
19136
|
}
|
|
19018
|
-
this.result(
|
|
19137
|
+
this.result(node2, outcome.result);
|
|
19019
19138
|
field.result = outcome.result;
|
|
19020
|
-
if (outcome.ok) this.writeCandidate(
|
|
19021
|
-
const mounted = this.fields.get(
|
|
19139
|
+
if (outcome.ok) this.writeCandidate(node2, outcome.value);
|
|
19140
|
+
const mounted = this.fields.get(fullpath);
|
|
19022
19141
|
if (mounted) mounted.element.presentValidation(outcome.result);
|
|
19023
|
-
|
|
19142
|
+
context.finishValidation(outcome);
|
|
19024
19143
|
}, () => {
|
|
19025
|
-
this.pendingPart(
|
|
19026
|
-
this.fields.get(
|
|
19144
|
+
this.pendingPart(this.fieldNode(fullpath), "validation", "active");
|
|
19145
|
+
this.fields.get(fullpath)?.element.setFieldState({ pending: true });
|
|
19027
19146
|
});
|
|
19028
19147
|
}
|
|
19029
19148
|
remove(name, node) {
|
|
@@ -19038,11 +19157,11 @@ var EditingSession = class {
|
|
|
19038
19157
|
draft(node, text3) {
|
|
19039
19158
|
this.invalidateValidation();
|
|
19040
19159
|
this.cancelValidation(node);
|
|
19041
|
-
node.formDraft = text3;
|
|
19160
|
+
node._internal.formDraft = text3;
|
|
19042
19161
|
this.set("drafts", node, text3);
|
|
19043
19162
|
}
|
|
19044
19163
|
clearDraft(node) {
|
|
19045
|
-
delete node.formDraft;
|
|
19164
|
+
delete node._internal.formDraft;
|
|
19046
19165
|
this.set("drafts", node, null);
|
|
19047
19166
|
this.issue(node, "parse", null);
|
|
19048
19167
|
}
|
|
@@ -19085,7 +19204,7 @@ var EditingSession = class {
|
|
|
19085
19204
|
this.updateChanges(change.path);
|
|
19086
19205
|
if (this.writing) return;
|
|
19087
19206
|
this.invalidateValidation();
|
|
19088
|
-
for (const
|
|
19207
|
+
for (const fullpath of this.validations.keys()) this.refreshField(this.fieldNode(fullpath));
|
|
19089
19208
|
}
|
|
19090
19209
|
updateChanges(changedPath = null) {
|
|
19091
19210
|
const changes = this.registers.getItem("changes");
|
|
@@ -19143,15 +19262,16 @@ var EditingSession = class {
|
|
|
19143
19262
|
});
|
|
19144
19263
|
}
|
|
19145
19264
|
commitField(path) {
|
|
19146
|
-
for (const adapter of this.fields
|
|
19147
|
-
|
|
19265
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
19266
|
+
const node = this.fieldNode(fullpath);
|
|
19267
|
+
if (fieldPath(node) === path && Object.hasOwn(node._internal, "formDraft")) adapter.commit();
|
|
19148
19268
|
}
|
|
19149
19269
|
}
|
|
19150
19270
|
/** Flush active drafts. Refuse errors/pending checks; accept only a valid local snapshot. */
|
|
19151
19271
|
accept() {
|
|
19152
19272
|
if (this.disposed) return false;
|
|
19153
|
-
for (const adapter of this.fields
|
|
19154
|
-
if (Object.hasOwn(
|
|
19273
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
19274
|
+
if (Object.hasOwn(this.fieldNode(fullpath)._internal, "formDraft")) adapter.commit();
|
|
19155
19275
|
}
|
|
19156
19276
|
if (!this.status.valid || this.status.pending) return false;
|
|
19157
19277
|
if (this.validationSources.size && this.validatedRevision !== this.validationRevision) return false;
|
|
@@ -19168,24 +19288,25 @@ var EditingSession = class {
|
|
|
19168
19288
|
restore() {
|
|
19169
19289
|
if (this.disposed) return;
|
|
19170
19290
|
this.invalidateValidation();
|
|
19171
|
-
for (const
|
|
19172
|
-
for (const adapter of this.fields
|
|
19291
|
+
for (const fullpath of this.validations.keys()) this.cancelValidation(this.fieldNode(fullpath));
|
|
19292
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
19293
|
+
const node = this.fieldNode(fullpath);
|
|
19173
19294
|
adapter.element.cancelValidation();
|
|
19174
|
-
this.clearDraft(
|
|
19295
|
+
this.clearDraft(node);
|
|
19175
19296
|
adapter.element.restoreFormValue(this.registers.getItem("baseline").getItem(
|
|
19176
|
-
|
|
19297
|
+
node.absDatapath(node.getAttr("value")).slice(this.path ? this.path.length + 1 : 0)
|
|
19177
19298
|
));
|
|
19178
19299
|
}
|
|
19179
19300
|
this.runtime.gramlot.data.setItem(this.path, copy(this.registers.getItem("baseline")));
|
|
19180
19301
|
for (const name of ["errors", "pending", "drafts"]) this.registers.setItem(name, new Bag());
|
|
19181
19302
|
this.updateChanges();
|
|
19182
|
-
for (const
|
|
19303
|
+
for (const fullpath of this.validations.keys()) this.scheduleField(this.fieldNode(fullpath));
|
|
19183
19304
|
}
|
|
19184
19305
|
dispose() {
|
|
19185
19306
|
if (this.disposed) return;
|
|
19186
19307
|
this.disposed = true;
|
|
19187
19308
|
this.subscription.close();
|
|
19188
|
-
for (const
|
|
19309
|
+
for (const fullpath of this.validations.keys()) this.forgetField(fullpath);
|
|
19189
19310
|
this.fields.clear();
|
|
19190
19311
|
this.validationQueue.clear();
|
|
19191
19312
|
this.retainedFields.clear();
|
|
@@ -19392,29 +19513,39 @@ function structFormulaCode(grid) {
|
|
|
19392
19513
|
if (grid.staticValue instanceof SourceBag) visit(grid.staticValue);
|
|
19393
19514
|
return items;
|
|
19394
19515
|
}
|
|
19516
|
+
var SYMBOLIC_ATTRIBUTES = ["_workspace", "_workspace_path", "childname"];
|
|
19517
|
+
function stringHash(text3) {
|
|
19518
|
+
let hash = 0;
|
|
19519
|
+
for (let index = 0; index < text3.length; index++) hash = (hash << 5) - hash + text3.charCodeAt(index) | 0;
|
|
19520
|
+
return Math.abs(hash);
|
|
19521
|
+
}
|
|
19522
|
+
function namedChild(bag, name) {
|
|
19523
|
+
const nodes = bag.getNodes();
|
|
19524
|
+
const direct = nodes.find((node) => node.getAttr("childname") === name);
|
|
19525
|
+
if (direct) return direct;
|
|
19526
|
+
for (const node of nodes) {
|
|
19527
|
+
if (node.getAttr("childname") != null || !(node.staticValue instanceof SourceBag)) continue;
|
|
19528
|
+
const found = namedChild(node.staticValue, name);
|
|
19529
|
+
if (found) return found;
|
|
19530
|
+
}
|
|
19531
|
+
return null;
|
|
19532
|
+
}
|
|
19395
19533
|
var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
19396
19534
|
#formState = null;
|
|
19397
|
-
#
|
|
19398
|
-
/**
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19406
|
-
this.#treeStore = bag;
|
|
19407
|
-
const runtime = this.rootBuilder.binding;
|
|
19408
|
-
const binding = runtime?.bindingFor(this);
|
|
19409
|
-
if (binding && !binding.closed) {
|
|
19410
|
-
binding.rebind();
|
|
19411
|
-
if (runtime.renderer.attached(this)) runtime.renderer.project(this);
|
|
19412
|
-
}
|
|
19535
|
+
#internal = null;
|
|
19536
|
+
/**
|
|
19537
|
+
* Internal state of this node for its component or runtime (GC-225): a plain object, created on first read.
|
|
19538
|
+
* It is not reactive, not an attribute, not Data and not serialized. It holds plain values and component helper
|
|
19539
|
+
* instances that hold no Bag, BagNode or Source node and reach Data and structure by address; state an author may
|
|
19540
|
+
* read or bind goes to `#WORKSPACE` in Data.
|
|
19541
|
+
*/
|
|
19542
|
+
get _internal() {
|
|
19543
|
+
return this.#internal ??= {};
|
|
19413
19544
|
}
|
|
19414
19545
|
/** The local form lifecycle owned by the nearest marked Source ancestor. */
|
|
19415
19546
|
get formState() {
|
|
19416
19547
|
for (let owner = this; owner; owner = owner.parentNode) {
|
|
19417
|
-
if (owner.#formState && owner._getMeta("gramlot_component")?.
|
|
19548
|
+
if (owner.#formState && owner._getMeta("gramlot_component")?.parameters?.storepath) return owner.#formState;
|
|
19418
19549
|
if (owner.getAttr("formId") != null || owner.getAttr("form") === true) {
|
|
19419
19550
|
const state = owner.#formState ??= new EditingSession(owner, this.rootBuilder.binding);
|
|
19420
19551
|
state.rebind();
|
|
@@ -19527,7 +19658,7 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19527
19658
|
}
|
|
19528
19659
|
}
|
|
19529
19660
|
if (isExpression2(this.staticValue) || this.nodeTag === "script" && typeof this.staticValue === "string") items.push(["", this.staticValue]);
|
|
19530
|
-
if (this._getMeta("gramlot_component")?.
|
|
19661
|
+
if (this._getMeta("gramlot_component")?.parameters?.structpath) items.push(...structFormulaCode(this));
|
|
19531
19662
|
return items;
|
|
19532
19663
|
}
|
|
19533
19664
|
/**
|
|
@@ -19701,10 +19832,16 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19701
19832
|
release?.();
|
|
19702
19833
|
};
|
|
19703
19834
|
}
|
|
19704
|
-
/**
|
|
19705
|
-
|
|
19835
|
+
/**
|
|
19836
|
+
* Builder's absDatapath, keeping `?attr` on symbolic paths. `row` is the row context of `#ROW`:
|
|
19837
|
+
* the key (label) of the row inside the collection at the `storepath` of the nearest node that
|
|
19838
|
+
* declares one; it is ignored by any other path. `#ROW` without a row context is an error.
|
|
19839
|
+
*/
|
|
19840
|
+
absDatapath(path, { row = null } = {}) {
|
|
19706
19841
|
path = pointerTransform(path)?.pointer ?? path;
|
|
19707
19842
|
const bare = this.pointerType(path) ? path.slice(1) : path;
|
|
19843
|
+
if (bare.startsWith("#") && bare.indexOf("?") !== bare.lastIndexOf("?")) throw new Error(`a symbolic path has one ?attr suffix at most: ${path}`);
|
|
19844
|
+
if (bare === "#ROW" || bare.startsWith("#ROW.") || bare.startsWith("#ROW?")) return this.#rowDatapath(bare, row, path);
|
|
19708
19845
|
if (bare.startsWith("#") && bare.includes("?")) {
|
|
19709
19846
|
const [target, attr] = bare.split("?", 2);
|
|
19710
19847
|
const resolved2 = super.absDatapath(target);
|
|
@@ -19740,16 +19877,142 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19740
19877
|
_finalizeAbsPath(path, attr) {
|
|
19741
19878
|
return path === null ? null : super._finalizeAbsPath(path, attr);
|
|
19742
19879
|
}
|
|
19743
|
-
/**
|
|
19880
|
+
/**
|
|
19881
|
+
* Symbolic resolution of `#<head>[.relpath]`, in the legacy order: `#ROW`, `#WORKSPACE`,
|
|
19882
|
+
* `#DATA`, then a start node (`#FORM`, `#ANCHOR`, `#<nodeId>`, `#/<childpath>`, each with an
|
|
19883
|
+
* optional `/<childpath>`), from which `relpath` is resolved relatively.
|
|
19884
|
+
*/
|
|
19744
19885
|
_resolveSymbolicDatapath(path, raw) {
|
|
19745
|
-
const
|
|
19746
|
-
|
|
19747
|
-
const
|
|
19748
|
-
|
|
19749
|
-
|
|
19750
|
-
if (
|
|
19751
|
-
|
|
19752
|
-
|
|
19886
|
+
const symbolic = path.slice(1);
|
|
19887
|
+
const dot = symbolic.indexOf(".");
|
|
19888
|
+
const head = dot === -1 ? symbolic : symbolic.slice(0, dot);
|
|
19889
|
+
const relpath = dot === -1 ? "" : symbolic.slice(dot + 1);
|
|
19890
|
+
if (head === "ROW") throw new Error(`#ROW: no row context for ${raw}`);
|
|
19891
|
+
if (head === "WORKSPACE") {
|
|
19892
|
+
const base = this.#workspaceDatapath(raw);
|
|
19893
|
+
return relpath ? `${base}.${relpath}` : base;
|
|
19894
|
+
}
|
|
19895
|
+
if (head === "DATA") {
|
|
19896
|
+
if (!relpath) throw new Error(`#DATA requires a path: ${raw}`);
|
|
19897
|
+
return relpath;
|
|
19898
|
+
}
|
|
19899
|
+
return this.#symbolicNode(head, raw).absDatapath(relpath ? `.${relpath}` : ".");
|
|
19900
|
+
}
|
|
19901
|
+
/**
|
|
19902
|
+
* The node reached by a child path from this node, as legacy `getChild`: the segments are
|
|
19903
|
+
* separated by `/`; `parent` moves to the parent node, `#<nodeId>` (also `#FORM`, `#ANCHOR`) to the
|
|
19904
|
+
* node of that symbol seen from the current node, any other segment to the nearest descendant whose
|
|
19905
|
+
* `childname` is the segment (direct children first; a named node hides its descendants). Null when
|
|
19906
|
+
* a step finds no node.
|
|
19907
|
+
*/
|
|
19908
|
+
getChild(childpath) {
|
|
19909
|
+
let node = this;
|
|
19910
|
+
for (const segment of childpath.split("/")) {
|
|
19911
|
+
if (segment === "parent") node = node.parentNode;
|
|
19912
|
+
else if (segment.startsWith("#")) node = node.#symbolicNode(segment.slice(1), childpath);
|
|
19913
|
+
else {
|
|
19914
|
+
this.#dependOn(`childname:${segment}`);
|
|
19915
|
+
node = node.staticValue instanceof SourceBag ? namedChild(node.staticValue, segment) : null;
|
|
19916
|
+
}
|
|
19917
|
+
if (!node) return null;
|
|
19918
|
+
this.#dependOn(node);
|
|
19919
|
+
}
|
|
19920
|
+
return node;
|
|
19921
|
+
}
|
|
19922
|
+
/**
|
|
19923
|
+
* The name of the private Data area of this node: the `_workspace` string value, or for `true`
|
|
19924
|
+
* the nodeId, else the tag followed by a hash of the node's Source path, as legacy. A node that
|
|
19925
|
+
* declares no `_workspace` has the name it would have with `_workspace=true`.
|
|
19926
|
+
*/
|
|
19927
|
+
get workspaceName() {
|
|
19928
|
+
const value = this.getAttr("_workspace") ?? true;
|
|
19929
|
+
if (value === true) return this.getAttr("nodeId") ?? `${this.nodeTag}_${stringHash(this.fullpath)}`;
|
|
19930
|
+
if (typeof value === "string" && value) return value;
|
|
19931
|
+
throw new TypeError(`${this.nodeTag} '${this.label}': _workspace must be true or a name, not ${value}`);
|
|
19932
|
+
}
|
|
19933
|
+
/**
|
|
19934
|
+
* The private Data area of this node, as `#WORKSPACE` sees it from the node that owns it:
|
|
19935
|
+
* `_workspace_path` resolved from this node, else `_gramlot.workspace.<workspaceName>`. A component
|
|
19936
|
+
* keeps its private states under the area of its own node, addressed by path.
|
|
19937
|
+
*/
|
|
19938
|
+
get workspaceDatapath() {
|
|
19939
|
+
const explicit = this.getAttr("_workspace_path");
|
|
19940
|
+
return explicit == null ? `_gramlot.workspace.${this.workspaceName}` : this.absDatapath(explicit);
|
|
19941
|
+
}
|
|
19942
|
+
/** `#WORKSPACE`: the private Data area of the nearest node with `_workspace`. */
|
|
19943
|
+
#workspaceDatapath(raw) {
|
|
19944
|
+
const owner = this.attributeOwnerNode("_workspace");
|
|
19945
|
+
if (!owner) throw new Error(`#WORKSPACE: no ancestor with _workspace for ${raw}`);
|
|
19946
|
+
return owner.workspaceDatapath;
|
|
19947
|
+
}
|
|
19948
|
+
/**
|
|
19949
|
+
* The inverse of `#ROW.<field>`: `{row, field}` when the absolute Data path `path` is a direct field of
|
|
19950
|
+
* a row of the collection at the `storepath` of the nearest node that declares one, as `#ROW.<field>`
|
|
19951
|
+
* gives it for that row key and `rowMode`; null for any other path.
|
|
19952
|
+
*/
|
|
19953
|
+
rowField(path) {
|
|
19954
|
+
const owner = this.attributeOwnerNode("storepath");
|
|
19955
|
+
if (!owner) throw new Error(`#ROW: no ancestor with storepath for ${path}`);
|
|
19956
|
+
const prefix = `${owner.absDatapath(owner.getAttr("storepath"))}.`;
|
|
19957
|
+
const match = path.startsWith(prefix) ? /^([^.?]+)[.?]([^.?]+)$/.exec(path.slice(prefix.length)) : null;
|
|
19958
|
+
if (!match) return null;
|
|
19959
|
+
const [, row, field] = match;
|
|
19960
|
+
return this.absDatapath(`#ROW.${field}`, { row }) === path ? { row, field } : null;
|
|
19961
|
+
}
|
|
19962
|
+
/** `#ROW[.field][?attr]` for the row `row` of the nearest node with `storepath`, following its `rowMode`. */
|
|
19963
|
+
#rowDatapath(bare, row, raw) {
|
|
19964
|
+
if (row === null) throw new Error(`#ROW: no row context for ${raw}`);
|
|
19965
|
+
const owner = this.attributeOwnerNode("storepath");
|
|
19966
|
+
if (!owner) throw new Error(`#ROW: no ancestor with storepath for ${raw}`);
|
|
19967
|
+
const mode = owner.getAttr("rowMode");
|
|
19968
|
+
if (mode !== "values" && mode !== "attributes") throw new Error(`#ROW: rowMode must be 'values' or 'attributes' for ${raw}`);
|
|
19969
|
+
const rowpath = `${owner.absDatapath(owner.getAttr("storepath"))}.${row}`;
|
|
19970
|
+
let [rest, attr = null] = bare.slice("#ROW".length).split("?", 2);
|
|
19971
|
+
if (mode === "attributes" && rest) {
|
|
19972
|
+
const field = rest.slice(1);
|
|
19973
|
+
if (field.includes(".") || attr !== null) throw new Error(`#ROW: a row in rowMode 'attributes' has only attribute fields: ${raw}`);
|
|
19974
|
+
return `${rowpath}?${field}`;
|
|
19975
|
+
}
|
|
19976
|
+
return `${rowpath}${rest}${attr === null ? "" : `?${attr}`}`;
|
|
19977
|
+
}
|
|
19978
|
+
/**
|
|
19979
|
+
* The start node of a symbolic head, as legacy `nodeById`: `/<childpath>` from the nearest ancestor
|
|
19980
|
+
* with a nodeId, through the `childname`s of the nodes in between; otherwise `<symbol>[/<childpath>]`
|
|
19981
|
+
* where the symbol is `FORM`, `ANCHOR` or a nodeId of the page (R06: the nodeId map of the runtime).
|
|
19982
|
+
*/
|
|
19983
|
+
#symbolicNode(head, raw) {
|
|
19984
|
+
let node, childpath;
|
|
19985
|
+
if (head.startsWith("/")) {
|
|
19986
|
+
childpath = head.slice(1);
|
|
19987
|
+
node = this;
|
|
19988
|
+
while (node && node.getAttr("nodeId") == null) {
|
|
19989
|
+
if (node.getAttr("childname") != null) childpath = `${node.getAttr("childname")}/${childpath}`;
|
|
19990
|
+
node = node.parentNode;
|
|
19991
|
+
}
|
|
19992
|
+
if (!node) throw new Error(`#/: no ancestor with a nodeId for ${raw}`);
|
|
19993
|
+
} else {
|
|
19994
|
+
const slash = head.indexOf("/");
|
|
19995
|
+
const symbol = slash === -1 ? head : head.slice(0, slash);
|
|
19996
|
+
childpath = slash === -1 ? "" : head.slice(slash + 1);
|
|
19997
|
+
if (symbol === "FORM") node = this._findMarkedDatapathAncestor(true, false, raw);
|
|
19998
|
+
else if (symbol === "ANCHOR") node = this._findMarkedDatapathAncestor(false, true, raw);
|
|
19999
|
+
else {
|
|
20000
|
+
this.#dependOn(`id:${symbol}`);
|
|
20001
|
+
const runtime = this.rootBuilder?.binding;
|
|
20002
|
+
if (!runtime && !this.rootBuilder) throw new Error(`#<id>: cannot resolve ${raw} on a node without builder`);
|
|
20003
|
+
node = runtime ? runtime.nodeIds.get(symbol) : this.rootBuilder.source.getNodeByAttr("nodeId", symbol);
|
|
20004
|
+
if (!node) throw new Error(`#<id>: cannot resolve ${raw}`);
|
|
20005
|
+
this.#dependOn(node);
|
|
20006
|
+
}
|
|
20007
|
+
}
|
|
20008
|
+
if (!childpath) return node;
|
|
20009
|
+
const child = node.getChild(childpath);
|
|
20010
|
+
if (!child) throw new Error(`#<id>: no child '${childpath}' for ${raw}`);
|
|
20011
|
+
return child;
|
|
20012
|
+
}
|
|
20013
|
+
/** Record, for the NodeBinding whose registrations are being resolved, that the resolution read `key`. */
|
|
20014
|
+
#dependOn(key2) {
|
|
20015
|
+
this.rootBuilder?.binding?.dependOn(key2);
|
|
19753
20016
|
}
|
|
19754
20017
|
/**
|
|
19755
20018
|
* The datapath read from Data for a pointer datapath, or null when empty. The pointer is read in
|
|
@@ -20054,7 +20317,7 @@ var binding_default = {
|
|
|
20054
20317
|
abstracts: {},
|
|
20055
20318
|
elements: {
|
|
20056
20319
|
dataBinder: {
|
|
20057
|
-
doc: "Bidirectional subscription between a client Data branch and its page's server store.",
|
|
20320
|
+
doc: "Bidirectional subscription between a client Data branch and its page's server store, or the store of a named connection.",
|
|
20058
20321
|
sub_tags: "",
|
|
20059
20322
|
parent_tags: null,
|
|
20060
20323
|
inherits_from: null,
|
|
@@ -20083,6 +20346,28 @@ var binding_default = {
|
|
|
20083
20346
|
},
|
|
20084
20347
|
has_default: false
|
|
20085
20348
|
},
|
|
20349
|
+
{
|
|
20350
|
+
name: "connection",
|
|
20351
|
+
kind: "positional_or_keyword",
|
|
20352
|
+
role: "attribute",
|
|
20353
|
+
annotation: {
|
|
20354
|
+
kind: "union",
|
|
20355
|
+
items: [
|
|
20356
|
+
{
|
|
20357
|
+
kind: "type",
|
|
20358
|
+
module: "builtins",
|
|
20359
|
+
name: "str"
|
|
20360
|
+
},
|
|
20361
|
+
{
|
|
20362
|
+
kind: "type",
|
|
20363
|
+
module: "builtins",
|
|
20364
|
+
name: "NoneType"
|
|
20365
|
+
}
|
|
20366
|
+
]
|
|
20367
|
+
},
|
|
20368
|
+
has_default: true,
|
|
20369
|
+
default: null
|
|
20370
|
+
},
|
|
20086
20371
|
{
|
|
20087
20372
|
name: "attr",
|
|
20088
20373
|
kind: "var_keyword",
|
|
@@ -21606,7 +21891,7 @@ function componentContext(adapter) {
|
|
|
21606
21891
|
if (binding.closed) return;
|
|
21607
21892
|
const pointer = node.getAttr("value");
|
|
21608
21893
|
if (node.pointerType(pointer) !== "^" || pointer.includes("?") || !Object.is(node.getRelativeData(pointer), value)) return;
|
|
21609
|
-
const path = pointer.slice(1) + "?
|
|
21894
|
+
const path = pointer.slice(1) + "?_dv_displayedValue";
|
|
21610
21895
|
if (node.getRelativeData(path) !== caption) node.setRelativeData(path, caption);
|
|
21611
21896
|
},
|
|
21612
21897
|
periodOutput: (path, value) => node.setRelativeData(path, value),
|
|
@@ -21764,12 +22049,24 @@ var HtmlElement = class {
|
|
|
21764
22049
|
frameRecipient: () => frameRecipient(commandFrame(node)),
|
|
21765
22050
|
locale: node.rootBuilder.binding.gramlot.locale,
|
|
21766
22051
|
timeZone: node.rootBuilder.binding.gramlot.timeZone,
|
|
21767
|
-
collectionView: (
|
|
22052
|
+
collectionView: (path, rowMode) => node.rootBuilder.binding.collectionView(node, path, rowMode),
|
|
21768
22053
|
format: this.format,
|
|
21769
22054
|
upload: () => this.uploadContext(),
|
|
22055
|
+
terminalUrl: (session) => {
|
|
22056
|
+
const store = node.rootBuilder.binding.gramlot._pageStore;
|
|
22057
|
+
if (!store) throw new Error("A terminal requires a server with a PageStore channel (websocket)");
|
|
22058
|
+
return store.terminalUrl(session);
|
|
22059
|
+
},
|
|
21770
22060
|
reportError: (error, title) => this.reportError(node, error, title),
|
|
21771
22061
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
21772
|
-
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
22062
|
+
writeParameter: (name, value, attributes = null) => this.writeParameter(node, name, value, attributes),
|
|
22063
|
+
attrDatapath: (name) => this.attrDatapath(node, name),
|
|
22064
|
+
getStaticData: (path) => this.getStaticData(node, path),
|
|
22065
|
+
// The value at the Data `path` relative to the node, read without running resolvers, and its write.
|
|
22066
|
+
readRelativeData: (path) => this.getStaticData(node, node.absDatapath(path)),
|
|
22067
|
+
setRelativeData: (path, value, attributes = null) => node.setRelativeData(path, value, { attributes }),
|
|
22068
|
+
// The tree's store, read from its storepath (`*S`, `*D` or a Data path) at each call.
|
|
22069
|
+
treeStore: () => node.rootBuilder.binding.treeStore(node),
|
|
21773
22070
|
callLogic: (name, keywords) => this.callLogic(node, name, keywords)
|
|
21774
22071
|
});
|
|
21775
22072
|
}
|
|
@@ -21806,12 +22103,36 @@ var HtmlElement = class {
|
|
|
21806
22103
|
* pointer writes; a literal, a `=` pointer and a pointer with a suffix write nothing (no inverse
|
|
21807
22104
|
* conversion, 11.81). A value equal (`Object.is`) to the Data value is not written, as the legacy
|
|
21808
22105
|
* `setAttributeInDatasource` with `lazySet`: a null value on a missing path creates no Data node.
|
|
22106
|
+
* `attributes` (legacy `setRelativeData` attributes, such as `_valuelabel`) go on the written Data node.
|
|
21809
22107
|
*/
|
|
21810
|
-
writeParameter(node, name, value) {
|
|
22108
|
+
writeParameter(node, name, value, attributes = null) {
|
|
21811
22109
|
const pointer = node.getAttr(name);
|
|
21812
22110
|
if (node.pointerType(pointer) === "^" && !pointerTransform(pointer) && !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
|
|
21813
|
-
node.setRelativeData(pointer.slice(1), value);
|
|
22111
|
+
node.setRelativeData(pointer.slice(1), value, { attributes });
|
|
22112
|
+
}
|
|
22113
|
+
}
|
|
22114
|
+
/**
|
|
22115
|
+
* The absolute Data path of the original attribute `name` of `node`, as the legacy
|
|
22116
|
+
* `attrDatapath`: a `^`/`=` pointer loses its symbol, a plain string (`storepath`) is a path;
|
|
22117
|
+
* relative paths and symbolic anchors resolve in the node's context. A missing attribute and a
|
|
22118
|
+
* pointer on a null path (Q7) give null. The path is resolved at each call, never kept.
|
|
22119
|
+
*/
|
|
22120
|
+
attrDatapath(node, name) {
|
|
22121
|
+
const value = node.getAttr(name);
|
|
22122
|
+
if (value == null) return null;
|
|
22123
|
+
if (typeof value !== "string" || value.startsWith("==")) {
|
|
22124
|
+
throw new TypeError(`${node.nodeTag} '${node.label}': attribute '${name}' is not a Data path`);
|
|
21814
22125
|
}
|
|
22126
|
+
return node.absDatapath(value);
|
|
22127
|
+
}
|
|
22128
|
+
/**
|
|
22129
|
+
* The value at the absolute Data `path`, read without running resolvers (Bag `getItem` with
|
|
22130
|
+
* `isStatic`); null on a null path (Q7). The caller reads at each use and keeps nothing.
|
|
22131
|
+
*/
|
|
22132
|
+
getStaticData(node, path) {
|
|
22133
|
+
if (path === null) return null;
|
|
22134
|
+
if (typeof path !== "string" || !path) throw new TypeError(`A static Data read requires a path: ${path}`);
|
|
22135
|
+
return node.data.getItem(path, null, true);
|
|
21815
22136
|
}
|
|
21816
22137
|
compose(record2, text3, children) {
|
|
21817
22138
|
record2.text.data = text3 ?? "";
|
|
@@ -21864,22 +22185,7 @@ var HtmlElement = class {
|
|
|
21864
22185
|
projectLabelbox(record2.labelbox, { ...defaults, ...attrs }, adapt);
|
|
21865
22186
|
}
|
|
21866
22187
|
if (this.definition(node).meta.gramlot_component) {
|
|
21867
|
-
|
|
21868
|
-
if (node.nodeTag === "tree") element.setStoreBag(node.rootBuilder.binding.treeStore(node));
|
|
21869
|
-
else {
|
|
21870
|
-
const path = node.absDatapath(node.getAttr("storepath"));
|
|
21871
|
-
if (!change || change.path === path || change.path.startsWith(`${path}.`) || path.startsWith(`${change.path}.`)) {
|
|
21872
|
-
element.setStoreBag(node.getRelativeData(node.getAttr("storepath")));
|
|
21873
|
-
}
|
|
21874
|
-
}
|
|
21875
|
-
}
|
|
21876
|
-
if (this.definition(node).meta.gramlot_component.bagStruct) {
|
|
21877
|
-
const path = node.absDatapath(node.getAttr("structpath"));
|
|
21878
|
-
if (!change || change.path === path || change.path.startsWith(`${path}.`) || path.startsWith(`${change.path}.`)) {
|
|
21879
|
-
element.setStructBag(node.getRelativeData(node.getAttr("structpath")));
|
|
21880
|
-
}
|
|
21881
|
-
}
|
|
21882
|
-
attrs = element.projectAttributes(attrs, adapt);
|
|
22188
|
+
attrs = element.projectAttributes(attrs, adapt, change?.path ?? null);
|
|
21883
22189
|
}
|
|
21884
22190
|
if (record2.labelbox) {
|
|
21885
22191
|
attrs = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== "lbl" && !name.startsWith("lbl_") && !name.startsWith("box_")));
|
|
@@ -23181,16 +23487,32 @@ function requireId(id) {
|
|
|
23181
23487
|
var bag_collection_store_exports = {};
|
|
23182
23488
|
__export(bag_collection_store_exports, {
|
|
23183
23489
|
BagCollectionStore: () => BagCollectionStore,
|
|
23490
|
+
collectionKey: () => collectionKey,
|
|
23184
23491
|
publishCollection: () => publishCollection
|
|
23185
23492
|
});
|
|
23186
23493
|
var BagCollectionStore = class {
|
|
23187
23494
|
#listeners = /* @__PURE__ */ new Set();
|
|
23188
|
-
|
|
23189
|
-
|
|
23495
|
+
#data;
|
|
23496
|
+
#path;
|
|
23497
|
+
#rowMode;
|
|
23498
|
+
constructor(data, path, rowMode) {
|
|
23499
|
+
if (!(data instanceof Bag)) throw new TypeError("collection store requires the Data root Bag");
|
|
23500
|
+
if (typeof path !== "string" || !path) throw new TypeError(`collection store requires a Data path: ${path}`);
|
|
23190
23501
|
if (!["values", "attributes"].includes(rowMode)) throw new TypeError("collection store rowMode must explicitly be values or attributes");
|
|
23191
|
-
|
|
23192
|
-
this
|
|
23193
|
-
this
|
|
23502
|
+
this.#data = data;
|
|
23503
|
+
this.#path = path;
|
|
23504
|
+
this.#rowMode = rowMode;
|
|
23505
|
+
}
|
|
23506
|
+
/** The absolute Data path of the collection. */
|
|
23507
|
+
get path() {
|
|
23508
|
+
return this.#path;
|
|
23509
|
+
}
|
|
23510
|
+
get rowMode() {
|
|
23511
|
+
return this.#rowMode;
|
|
23512
|
+
}
|
|
23513
|
+
/** The key of the store among the page's stores: one store per absolute path and rowMode. */
|
|
23514
|
+
get key() {
|
|
23515
|
+
return collectionKey(this.#path, this.#rowMode);
|
|
23194
23516
|
}
|
|
23195
23517
|
subscribe(listener) {
|
|
23196
23518
|
this.#listeners.add(listener);
|
|
@@ -23206,7 +23528,9 @@ var BagCollectionStore = class {
|
|
|
23206
23528
|
publishCollection(this.#listeners, { full: row === null, rows: row ? [row] : [], event, field });
|
|
23207
23529
|
}
|
|
23208
23530
|
getRows() {
|
|
23209
|
-
const
|
|
23531
|
+
const bag = this.#data.getItem(this.path, null, true);
|
|
23532
|
+
if (!(bag instanceof Bag)) throw new TypeError(`collection store requires a Bag at ${this.path}`);
|
|
23533
|
+
const nodes = bag.getNodes();
|
|
23210
23534
|
for (const node of nodes) {
|
|
23211
23535
|
if (node.resolver) throw new TypeError("collection store requires loaded rows");
|
|
23212
23536
|
if (this.rowMode === "values" && !(node.staticValue instanceof Bag)) {
|
|
@@ -23225,6 +23549,9 @@ var BagCollectionStore = class {
|
|
|
23225
23549
|
return cell?.staticValue;
|
|
23226
23550
|
}
|
|
23227
23551
|
};
|
|
23552
|
+
function collectionKey(path, rowMode) {
|
|
23553
|
+
return `${rowMode}:${path}`;
|
|
23554
|
+
}
|
|
23228
23555
|
function publishCollection(listeners, change) {
|
|
23229
23556
|
const errors = [];
|
|
23230
23557
|
const notice = Object.freeze({
|
|
@@ -23254,14 +23581,20 @@ var BagCollectionView = class {
|
|
|
23254
23581
|
#filters = /* @__PURE__ */ new Map();
|
|
23255
23582
|
#filtered = null;
|
|
23256
23583
|
constructor(store) {
|
|
23257
|
-
this
|
|
23584
|
+
this.#store = store;
|
|
23585
|
+
this.synchronize();
|
|
23258
23586
|
}
|
|
23259
|
-
|
|
23260
|
-
|
|
23587
|
+
/** The absolute Data path of the store: two views over the same path and rowMode share the collection. */
|
|
23588
|
+
get path() {
|
|
23589
|
+
return this.#store.path;
|
|
23261
23590
|
}
|
|
23262
23591
|
get rowMode() {
|
|
23263
23592
|
return this.#store.rowMode;
|
|
23264
23593
|
}
|
|
23594
|
+
/** The key of the store the view reads: two views over the same key show the same collection. */
|
|
23595
|
+
get storeKey() {
|
|
23596
|
+
return this.#store.key;
|
|
23597
|
+
}
|
|
23265
23598
|
get sortedBy() {
|
|
23266
23599
|
return this.#sortedBy;
|
|
23267
23600
|
}
|
|
@@ -23305,21 +23638,12 @@ var BagCollectionView = class {
|
|
|
23305
23638
|
this.#release?.();
|
|
23306
23639
|
this.#release = null;
|
|
23307
23640
|
}
|
|
23308
|
-
bindStore(store) {
|
|
23309
|
-
if (this.#store === store) return;
|
|
23310
|
-
const connected = this.#release !== null;
|
|
23311
|
-
this.disconnect();
|
|
23312
|
-
this.#store = store;
|
|
23313
|
-
this.#indices.clear();
|
|
23314
|
-
if (connected) this.connect();
|
|
23315
|
-
else this.synchronize();
|
|
23316
|
-
}
|
|
23317
23641
|
getRows(filtered = true) {
|
|
23318
23642
|
const nodes = this.#orderedNodes();
|
|
23319
23643
|
return filtered && this.#filtered !== null ? this.#filtered.map((index) => nodes[index]) : nodes;
|
|
23320
23644
|
}
|
|
23321
23645
|
#orderedNodes() {
|
|
23322
|
-
return this.#store.getRows().toSorted((a, b) => (this.#indices.get(a) ?? Infinity) - (this.#indices.get(b) ?? Infinity));
|
|
23646
|
+
return this.#store.getRows().toSorted((a, b) => (this.#indices.get(a.label) ?? Infinity) - (this.#indices.get(b.label) ?? Infinity));
|
|
23323
23647
|
}
|
|
23324
23648
|
synchronize(change = { full: true, rows: [] }) {
|
|
23325
23649
|
if (!change.full && !this.#sortedBy && !this.#filters.size) {
|
|
@@ -23332,11 +23656,12 @@ var BagCollectionView = class {
|
|
|
23332
23656
|
const nodes = this.#sorted(this.#orderedNodes(), parseSort(sortedBy));
|
|
23333
23657
|
this.#commit(nodes, sortedBy, this.#filters);
|
|
23334
23658
|
}
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
const nodes = this.getRows(false);
|
|
23338
|
-
|
|
23339
|
-
nodes.splice(
|
|
23659
|
+
/** Move the row of key `label` before or after the row of key `target`; a key absent from the collection moves nothing. */
|
|
23660
|
+
moveRow(label, target, after = false) {
|
|
23661
|
+
const nodes = this.getRows(false), from = nodes.findIndex((row) => row.label === label);
|
|
23662
|
+
if (label === target || from < 0 || !nodes.some((row) => row.label === target)) return;
|
|
23663
|
+
const [moved] = nodes.splice(from, 1);
|
|
23664
|
+
nodes.splice(nodes.findIndex((row) => row.label === target) + Number(after), 0, moved);
|
|
23340
23665
|
this.#commit(nodes, "", this.#filters);
|
|
23341
23666
|
}
|
|
23342
23667
|
applyFilter(filter, contribution2 = "search") {
|
|
@@ -23396,13 +23721,13 @@ var BagCollectionView = class {
|
|
|
23396
23721
|
#commit(nodes, sortedBy, filters, change = { full: false, rows: [] }) {
|
|
23397
23722
|
const predicates = [...filters.values()].map((entry) => entry.predicate).filter((predicate) => predicate !== null);
|
|
23398
23723
|
const filtered = predicates.length ? nodes.flatMap((node, index) => predicates.every((predicate) => predicate((field) => this.value(node, field))) ? [index] : []) : null;
|
|
23399
|
-
const full = change.full || sortedBy !== this.#sortedBy || filters !== this.#filters || nodes.length !== this.#indices.size || nodes.some((node, index) => this.#indices.get(node) !== index) || JSON.stringify(filtered) !== JSON.stringify(this.#filtered);
|
|
23400
|
-
this.#indices = new Map(nodes.map((node, index) => [node, index]));
|
|
23724
|
+
const full = change.full || sortedBy !== this.#sortedBy || filters !== this.#filters || nodes.length !== this.#indices.size || nodes.some((node, index) => this.#indices.get(node.label) !== index) || JSON.stringify(filtered) !== JSON.stringify(this.#filtered);
|
|
23725
|
+
this.#indices = new Map(nodes.map((node, index) => [node.label, index]));
|
|
23401
23726
|
this.#sortedBy = sortedBy;
|
|
23402
23727
|
this.#filters = filters;
|
|
23403
23728
|
this.#filtered = filtered;
|
|
23404
23729
|
const visible = filtered === null ? null : new Set(filtered);
|
|
23405
|
-
const rows = full ? [] : change.rows.filter((node) => this.#indices.has(node) && (visible === null || visible.has(this.#indices.get(node))));
|
|
23730
|
+
const rows = full ? [] : change.rows.filter((node) => this.#indices.has(node.label) && (visible === null || visible.has(this.#indices.get(node.label))));
|
|
23406
23731
|
if (full || rows.length || change.rows.length) publishCollection(this.#listeners, { full, rows });
|
|
23407
23732
|
}
|
|
23408
23733
|
#sorted(nodes, criteria) {
|
|
@@ -23906,21 +24231,18 @@ var GridFormulas = class {
|
|
|
23906
24231
|
this.#view = view;
|
|
23907
24232
|
this.#errors.clear();
|
|
23908
24233
|
if (!this.formulas.definitions.size) return;
|
|
24234
|
+
const pointers = [...this.formulas.definitions.values()].flatMap((definition) => [...definition.parameters.values()].filter((raw) => typeof raw === "string" && raw.startsWith("^")).map((raw) => [definition, ...this.source.absDatapath(raw).split("?")]));
|
|
23909
24235
|
this.#release = [
|
|
23910
24236
|
store.subscribe((change) => this.#storeChanged(change)),
|
|
23911
24237
|
view.subscribe(() => {
|
|
23912
24238
|
this.#viewValues = null;
|
|
23913
24239
|
})
|
|
23914
24240
|
];
|
|
23915
|
-
for (const definition of
|
|
23916
|
-
|
|
23917
|
-
|
|
23918
|
-
|
|
23919
|
-
|
|
23920
|
-
this.#viewValues = null;
|
|
23921
|
-
this.recalculate(this.#closure([definition.field]));
|
|
23922
|
-
} } }));
|
|
23923
|
-
}
|
|
24241
|
+
for (const [definition, path, attr = null] of pointers) {
|
|
24242
|
+
this.#registrations.push(this.runtime.router.register({ path, attr, recipient: { receive: () => {
|
|
24243
|
+
this.#viewValues = null;
|
|
24244
|
+
this.recalculate(this.#closure([definition.field]));
|
|
24245
|
+
} } }));
|
|
23924
24246
|
}
|
|
23925
24247
|
this.recalculate(this.#closure(this.#selected((definition) => definition.calculated)));
|
|
23926
24248
|
}
|
|
@@ -23937,7 +24259,7 @@ var GridFormulas = class {
|
|
|
23937
24259
|
/** The value shown by this grid: a view value, or the stored field. */
|
|
23938
24260
|
value(node, field) {
|
|
23939
24261
|
if (!this.viewFields.has(field)) return this.#store.value(node, field);
|
|
23940
|
-
const values = this.#computeViewValues().get(node);
|
|
24262
|
+
const values = this.#computeViewValues().get(node.label);
|
|
23941
24263
|
return values === void 0 ? null : values[field];
|
|
23942
24264
|
}
|
|
23943
24265
|
#selected(predicate) {
|
|
@@ -23975,10 +24297,14 @@ var GridFormulas = class {
|
|
|
23975
24297
|
const global = [...closure].some((name) => this.formulas.definitions.get(name).special?.kind === "percent");
|
|
23976
24298
|
this.recalculate(closure, global ? null : [row]);
|
|
23977
24299
|
}
|
|
23978
|
-
|
|
24300
|
+
/**
|
|
24301
|
+
* The `formula_<name>` parameters for the row `row`: a `^`/`=` pointer is read at its path, resolved
|
|
24302
|
+
* with the row key as row context, so `=#ROW.<field>` reads that field of the evaluated row.
|
|
24303
|
+
*/
|
|
24304
|
+
#parameters(definition, row) {
|
|
23979
24305
|
const result = {};
|
|
23980
24306
|
for (const [name, raw] of definition.parameters) {
|
|
23981
|
-
result[name] = typeof raw === "string" && (raw.startsWith("^") || raw.startsWith("=")) ? this.source.getRelativeData(raw) : raw;
|
|
24307
|
+
result[name] = typeof raw === "string" && (raw.startsWith("^") || raw.startsWith("=")) ? this.source.getRelativeData(this.source.absDatapath(raw, { row: row.label })) : raw;
|
|
23982
24308
|
}
|
|
23983
24309
|
return result;
|
|
23984
24310
|
}
|
|
@@ -23987,7 +24313,7 @@ var GridFormulas = class {
|
|
|
23987
24313
|
if (definition.special?.kind === "index") return index;
|
|
23988
24314
|
if (definition.special?.kind === "running") return addNumeric(aggregate, read(row, definition.special.field));
|
|
23989
24315
|
if (definition.special?.kind === "percent") return dividePercent(read(row, definition.special.field), aggregate);
|
|
23990
|
-
const parameters2 = this.#parameters(definition);
|
|
24316
|
+
const parameters2 = this.#parameters(definition, row);
|
|
23991
24317
|
const scope = {};
|
|
23992
24318
|
for (const name of definition.references) {
|
|
23993
24319
|
if (Object.hasOwn(parameters2, name)) scope[name] = parameters2[name];
|
|
@@ -24057,12 +24383,12 @@ var GridFormulas = class {
|
|
|
24057
24383
|
this.#running = false;
|
|
24058
24384
|
}
|
|
24059
24385
|
}
|
|
24060
|
-
/** View values of the visible rows in this grid's view order, cached until the next store or view change. */
|
|
24386
|
+
/** View values of the visible rows by row key, in this grid's view order, cached until the next store or view change. */
|
|
24061
24387
|
#computeViewValues() {
|
|
24062
24388
|
if (this.#viewValues !== null) return this.#viewValues;
|
|
24063
24389
|
const ordered = this.#view.getRows();
|
|
24064
|
-
const values = new Map(ordered.map((row) => [row, {}]));
|
|
24065
|
-
const read = (row, field) => this.viewFields.has(field) ? values.get(row)[field] : this.#store.value(row, field);
|
|
24390
|
+
const values = new Map(ordered.map((row) => [row.label, {}]));
|
|
24391
|
+
const read = (row, field) => this.viewFields.has(field) ? values.get(row.label)[field] : this.#store.value(row, field);
|
|
24066
24392
|
for (const field of this.formulas.order) {
|
|
24067
24393
|
const definition = this.formulas.definitions.get(field);
|
|
24068
24394
|
if (!definition.view) continue;
|
|
@@ -24075,7 +24401,7 @@ var GridFormulas = class {
|
|
|
24075
24401
|
} catch (error) {
|
|
24076
24402
|
failure2 = error;
|
|
24077
24403
|
}
|
|
24078
|
-
values.get(row)[field] = value;
|
|
24404
|
+
values.get(row.label)[field] = value;
|
|
24079
24405
|
}
|
|
24080
24406
|
if (failure2) this.#errors.set(field, failure2);
|
|
24081
24407
|
else this.#errors.delete(field);
|
|
@@ -24112,9 +24438,21 @@ var COLUMN_KEYS = /* @__PURE__ */ new Set([
|
|
|
24112
24438
|
]);
|
|
24113
24439
|
var FORMULA_PARAMETER = /^formula_[A-Za-z_$][\w$]*$/;
|
|
24114
24440
|
var GROUP_KEYS = /* @__PURE__ */ new Set(["tag", "code", "name", "background", "color"]);
|
|
24441
|
+
function requireIndependentBags(value, key2) {
|
|
24442
|
+
if (value instanceof Bag) {
|
|
24443
|
+
if (value.parent || value.parentNode) throw new TypeError(`grid edit option ${key2} holds a Bag with a parent; pass its path (storepath or a ^ pointer) instead`);
|
|
24444
|
+
} else if (Array.isArray(value)) value.forEach((item, index) => requireIndependentBags(item, `${key2}[${index}]`));
|
|
24445
|
+
else if (value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
24446
|
+
for (const [name, item] of Object.entries(value)) requireIndependentBags(item, `${key2}.${name}`);
|
|
24447
|
+
}
|
|
24448
|
+
}
|
|
24115
24449
|
var GridStructure = class {
|
|
24116
|
-
#
|
|
24117
|
-
|
|
24450
|
+
#labels = /* @__PURE__ */ new Map();
|
|
24451
|
+
#data;
|
|
24452
|
+
#path;
|
|
24453
|
+
constructor(bag, { data = null, path = null } = {}) {
|
|
24454
|
+
this.#data = data;
|
|
24455
|
+
this.#path = path;
|
|
24118
24456
|
if (!(bag instanceof Bag)) throw new TypeError("grid structpath must resolve to a Bag");
|
|
24119
24457
|
const view = branch(bag, "view_0"), info = branch(bag, "info");
|
|
24120
24458
|
const cells = branch(view, "rows_0"), definitions = branch(info, "columnsets");
|
|
@@ -24141,7 +24479,7 @@ var GridStructure = class {
|
|
|
24141
24479
|
requireIdentity(attrs.field, "field");
|
|
24142
24480
|
if (fields.has(attrs.field)) throw new TypeError(`Duplicate grid field: ${attrs.field}`);
|
|
24143
24481
|
fields.add(attrs.field);
|
|
24144
|
-
this.#
|
|
24482
|
+
this.#labels.set(attrs.field, node.label);
|
|
24145
24483
|
if (attrs.columnset != null && !groups.has(attrs.columnset)) throw new TypeError(`Unknown grid columnset: ${attrs.columnset}`);
|
|
24146
24484
|
if (attrs.dtype != null && !TYPES.has(attrs.dtype)) throw new TypeError(`Unsupported grid dtype: ${attrs.dtype}`);
|
|
24147
24485
|
if (attrs.align != null && !["start", "center", "end"].includes(attrs.align)) throw new TypeError("grid align requires start, center or end");
|
|
@@ -24154,6 +24492,7 @@ var GridStructure = class {
|
|
|
24154
24492
|
if (attrs.white_space != null && !["normal", "nowrap", "pre-wrap"].includes(attrs.white_space)) throw new TypeError("grid white_space requires normal, nowrap or pre-wrap");
|
|
24155
24493
|
for (const key2 of ["name", "title", "format"]) if (attrs[key2] != null && typeof attrs[key2] !== "string") throw new TypeError(`grid ${key2} must be text`);
|
|
24156
24494
|
if (attrs.edit != null && typeof attrs.edit !== "boolean" && (typeof attrs.edit !== "object" || Array.isArray(attrs.edit))) throw new TypeError("grid edit requires a boolean or editor options");
|
|
24495
|
+
if (attrs.edit != null && typeof attrs.edit === "object") for (const [key2, value] of Object.entries(attrs.edit)) requireIndependentBags(value, key2);
|
|
24157
24496
|
if (attrs.check != null || attrs.checked != null || attrs.checkedField != null) {
|
|
24158
24497
|
if (!["multiple", "single"].includes(attrs.check) || typeof attrs.checked !== "string" || !attrs.checked.startsWith("^") || attrs.checked.length < 2 || attrs.checked.includes("?")) {
|
|
24159
24498
|
throw new TypeError("grid check requires single or multiple and checked=^DataPath");
|
|
@@ -24189,20 +24528,35 @@ var GridStructure = class {
|
|
|
24189
24528
|
Object.freeze(this.groups);
|
|
24190
24529
|
Object.freeze(this);
|
|
24191
24530
|
}
|
|
24192
|
-
|
|
24193
|
-
|
|
24531
|
+
/** The cells Bag at the struct address, read at each use. */
|
|
24532
|
+
#cells() {
|
|
24533
|
+
if (this.#data === null || this.#path === null) throw new TypeError("grid structure without a Data address cannot be read or written");
|
|
24534
|
+
const bag = this.#data.getItem(this.#path, null, true);
|
|
24535
|
+
if (!(bag instanceof Bag)) throw new TypeError("grid structpath must resolve to a Bag");
|
|
24536
|
+
return branch(branch(bag, "view_0"), "rows_0");
|
|
24537
|
+
}
|
|
24538
|
+
/** The width written in the struct for `field`, read at its address. */
|
|
24539
|
+
columnWidth(field) {
|
|
24540
|
+
return this.#cells().getNode(this.#labels.get(field))?.getAttr("width");
|
|
24541
|
+
}
|
|
24542
|
+
/** The field of the cell `step` places after (negative: before) the cell of `field`, or null. */
|
|
24543
|
+
adjacentField(field, step) {
|
|
24544
|
+
const nodes = this.#cells().getNodes();
|
|
24545
|
+
const target = nodes[nodes.findIndex((node) => node.label === this.#labels.get(field)) + step];
|
|
24546
|
+
return target?.getAttr("tag") === "cell" ? target.getAttr("field") : null;
|
|
24194
24547
|
}
|
|
24195
24548
|
moveColumn(field, targetField, after = false) {
|
|
24196
|
-
const
|
|
24197
|
-
if (
|
|
24198
|
-
const bag =
|
|
24199
|
-
const from =
|
|
24549
|
+
const label = this.#labels.get(field), targetLabel = this.#labels.get(targetField);
|
|
24550
|
+
if (label === void 0 || targetLabel === void 0 || label === targetLabel) return;
|
|
24551
|
+
const bag = this.#cells(), labels = bag.keys();
|
|
24552
|
+
const from = labels.indexOf(label), targetIndex = labels.indexOf(targetLabel);
|
|
24553
|
+
if (from < 0 || targetIndex < 0) return;
|
|
24200
24554
|
const position = targetIndex + Number(after) - Number(from < targetIndex);
|
|
24201
24555
|
if (position !== from) bag.move(from, position);
|
|
24202
24556
|
}
|
|
24203
24557
|
setColumnWidth(field, width) {
|
|
24204
24558
|
if (!Number.isFinite(width) || width <= 0) throw new TypeError("grid resized width must be positive pixels");
|
|
24205
|
-
this.#
|
|
24559
|
+
this.#cells().getNode(this.#labels.get(field)).setAttr({ width: `${Math.round(width)}px` });
|
|
24206
24560
|
}
|
|
24207
24561
|
};
|
|
24208
24562
|
function branch(bag, label) {
|
|
@@ -24287,7 +24641,7 @@ function structureData(source) {
|
|
|
24287
24641
|
return data;
|
|
24288
24642
|
}
|
|
24289
24643
|
function validateGridDeclaration(node) {
|
|
24290
|
-
if (node._getMeta("gramlot_component")?.
|
|
24644
|
+
if (node._getMeta("gramlot_component")?.parameters?.structpath) {
|
|
24291
24645
|
const children = node.staticValue instanceof SourceBag ? node.staticValue.getNodes() : [];
|
|
24292
24646
|
if (children.some((child) => !child._getMeta("gridStruct")) || children.length > 1) throw new TypeError("grid accepts one struct declaration");
|
|
24293
24647
|
if (children.length && node.getAttr("structpath") != null) throw new TypeError("grid requires structpath or nested struct, not both");
|
|
@@ -24295,14 +24649,14 @@ function validateGridDeclaration(node) {
|
|
|
24295
24649
|
if (!["values", "attributes"].includes(node.getAttr("rowMode"))) throw new TypeError("grid rowMode must explicitly be values or attributes");
|
|
24296
24650
|
}
|
|
24297
24651
|
if (!node._getMeta("gridStruct")) return;
|
|
24298
|
-
if (!node.parentNode?._getMeta("gramlot_component")?.
|
|
24652
|
+
if (!node.parentNode?._getMeta("gramlot_component")?.parameters?.structpath) throw new TypeError("struct requires a grid parent");
|
|
24299
24653
|
if (!(node.staticValue instanceof SourceBag)) throw new TypeError("grid struct requires column declarations");
|
|
24300
24654
|
new GridStructure(structureData(node.staticValue));
|
|
24301
24655
|
}
|
|
24302
24656
|
function installGridStruct(node, data) {
|
|
24303
24657
|
const value = structureData(node.staticValue);
|
|
24304
24658
|
new GridStructure(value);
|
|
24305
|
-
const path =
|
|
24659
|
+
const path = `${node.parentNode.workspaceDatapath}.struct`;
|
|
24306
24660
|
data.setItem(path, value, null, ">", false, true, node);
|
|
24307
24661
|
node.parentNode.setAttr({ structpath: path }, false);
|
|
24308
24662
|
node.setValue(null, false);
|
|
@@ -25208,8 +25562,16 @@ var DataBinder = class {
|
|
|
25208
25562
|
}
|
|
25209
25563
|
register() {
|
|
25210
25564
|
const { runtime, node } = this.binding;
|
|
25211
|
-
|
|
25212
|
-
if (
|
|
25565
|
+
const name = node.getAttr("connection");
|
|
25566
|
+
if (name == null) {
|
|
25567
|
+
this.connection = runtime.gramlot._pageStore;
|
|
25568
|
+
if (!this.connection) throw new Error("dataBinder requires a PageStore WebSocket");
|
|
25569
|
+
} else {
|
|
25570
|
+
if (typeof name !== "string" || !/^[A-Za-z_][\w-]*$/.test(name)) {
|
|
25571
|
+
throw new TypeError("dataBinder connection requires a literal name");
|
|
25572
|
+
}
|
|
25573
|
+
this.connection = runtime.gramlot.rpc.connection(name);
|
|
25574
|
+
}
|
|
25213
25575
|
this.clientPath = node.absDatapath(node.pathAttribute("destination_path"));
|
|
25214
25576
|
this.serverPath = node.getAttr("server_path");
|
|
25215
25577
|
if (typeof this.clientPath !== "string" || !this.clientPath || this.clientPath.includes("?")) {
|
|
@@ -25511,11 +25873,24 @@ var PROVIDERS = {
|
|
|
25511
25873
|
dataRpc: RpcProvider,
|
|
25512
25874
|
dataRemote: RemoteProvider
|
|
25513
25875
|
};
|
|
25514
|
-
var CONTEXT_ATTRIBUTES = ["datapath", "_anchor", "nodeId", "form", "formId"];
|
|
25876
|
+
var CONTEXT_ATTRIBUTES = ["datapath", "_anchor", "nodeId", "form", "formId", ...SYMBOLIC_ATTRIBUTES];
|
|
25877
|
+
function startKeys(node) {
|
|
25878
|
+
const keys = [node];
|
|
25879
|
+
if (node.getAttr("nodeId") != null) keys.push(`id:${node.getAttr("nodeId")}`);
|
|
25880
|
+
if (node.getAttr("childname") != null) keys.push(`childname:${node.getAttr("childname")}`);
|
|
25881
|
+
return keys;
|
|
25882
|
+
}
|
|
25515
25883
|
var BindingRuntime = class {
|
|
25516
25884
|
#gramlot;
|
|
25517
25885
|
#bindings = /* @__PURE__ */ new Map();
|
|
25518
25886
|
#nodeIds = /* @__PURE__ */ new Map();
|
|
25887
|
+
// The NodeBindings whose registrations read a start of the symbolic resolution, by key: a Source
|
|
25888
|
+
// node, or `id:<nodeId>`, `childname:<name>`.
|
|
25889
|
+
#dependents = /* @__PURE__ */ new Map();
|
|
25890
|
+
// The NodeBinding whose registrations are being resolved, or null.
|
|
25891
|
+
#resolving = null;
|
|
25892
|
+
// The keys moved by the Source event being handled and the nodes already resolved again, or null outside one.
|
|
25893
|
+
#moved = null;
|
|
25519
25894
|
#router;
|
|
25520
25895
|
#installer;
|
|
25521
25896
|
#inlineCompiler;
|
|
@@ -25526,7 +25901,8 @@ var BindingRuntime = class {
|
|
|
25526
25901
|
#disposed = false;
|
|
25527
25902
|
#sourceTrees = /* @__PURE__ */ new Set();
|
|
25528
25903
|
#dataRootTrees = /* @__PURE__ */ new Set();
|
|
25529
|
-
|
|
25904
|
+
// One collection store per absolute Data path and rowMode, never per Bag identity.
|
|
25905
|
+
#collectionStores = /* @__PURE__ */ new Map();
|
|
25530
25906
|
constructor(gramlot, { subscriptions }) {
|
|
25531
25907
|
this.#gramlot = gramlot;
|
|
25532
25908
|
this.#subscriptions = subscriptions;
|
|
@@ -25561,7 +25937,6 @@ var BindingRuntime = class {
|
|
|
25561
25937
|
}
|
|
25562
25938
|
/** Resolve a tree store against the selected live root. */
|
|
25563
25939
|
treeStore(node) {
|
|
25564
|
-
if (node.treeStore !== null) return node.treeStore;
|
|
25565
25940
|
const path = node.getAttr("storepath");
|
|
25566
25941
|
if (path === "*S" || path.startsWith("*S.")) {
|
|
25567
25942
|
const root = this.renderer.source.getItem("main");
|
|
@@ -25611,23 +25986,64 @@ var BindingRuntime = class {
|
|
|
25611
25986
|
get nodeIds() {
|
|
25612
25987
|
return this.#nodeIds;
|
|
25613
25988
|
}
|
|
25614
|
-
/**
|
|
25615
|
-
|
|
25989
|
+
/** Run `run` resolving the registrations of `binding`: the starts it reads are recorded for it. */
|
|
25990
|
+
resolveFor(binding, run) {
|
|
25991
|
+
const previous = this.#resolving;
|
|
25992
|
+
this.#resolving = binding;
|
|
25993
|
+
try {
|
|
25994
|
+
return run();
|
|
25995
|
+
} finally {
|
|
25996
|
+
this.#resolving = previous;
|
|
25997
|
+
}
|
|
25998
|
+
}
|
|
25999
|
+
/** Record that the registrations being resolved read the start `key` (a Source node or a name key). */
|
|
26000
|
+
dependOn(key2) {
|
|
26001
|
+
const binding = this.#resolving;
|
|
26002
|
+
if (!binding) return;
|
|
26003
|
+
let dependents = this.#dependents.get(key2);
|
|
26004
|
+
if (!dependents) this.#dependents.set(key2, dependents = /* @__PURE__ */ new Set());
|
|
26005
|
+
dependents.add(binding);
|
|
26006
|
+
binding.dependencies.add(key2);
|
|
26007
|
+
}
|
|
26008
|
+
/** Forget the starts read by `binding`; called when its registrations close. */
|
|
26009
|
+
releaseDependencies(binding) {
|
|
26010
|
+
for (const key2 of binding.dependencies) {
|
|
26011
|
+
const dependents = this.#dependents.get(key2);
|
|
26012
|
+
dependents?.delete(binding);
|
|
26013
|
+
if (dependents && !dependents.size) this.#dependents.delete(key2);
|
|
26014
|
+
}
|
|
26015
|
+
binding.dependencies.clear();
|
|
26016
|
+
}
|
|
26017
|
+
/**
|
|
26018
|
+
* One shared resident data resource per absolute Data `path` and `rowMode`; presentation state
|
|
26019
|
+
* belongs to views. The store keeps the address: a replacement of the Bag at `path` keeps it.
|
|
26020
|
+
*/
|
|
26021
|
+
collectionStore(path, rowMode) {
|
|
25616
26022
|
if (this.disposed) throw new Error("BindingRuntime is disposed");
|
|
25617
|
-
|
|
26023
|
+
const key2 = collectionKey(path, rowMode);
|
|
26024
|
+
let store = this.#collectionStores.get(key2);
|
|
25618
26025
|
if (!store) {
|
|
25619
|
-
store = new BagCollectionStore(
|
|
25620
|
-
this.#collectionStores.set(
|
|
25621
|
-
}
|
|
26026
|
+
store = new BagCollectionStore(this.data, path, rowMode);
|
|
26027
|
+
this.#collectionStores.set(key2, store);
|
|
26028
|
+
}
|
|
25622
26029
|
return store;
|
|
25623
26030
|
}
|
|
25624
|
-
/**
|
|
25625
|
-
|
|
25626
|
-
|
|
25627
|
-
|
|
25628
|
-
|
|
25629
|
-
|
|
25630
|
-
|
|
26031
|
+
/**
|
|
26032
|
+
* Each grid Source owns one view over the store at `path`. A new address gives a new view that
|
|
26033
|
+
* starts from the criteria of the previous one; the previous view is disconnected.
|
|
26034
|
+
*/
|
|
26035
|
+
collectionView(node, path, rowMode) {
|
|
26036
|
+
const store = this.collectionStore(path, rowMode);
|
|
26037
|
+
const previous = node._internal.gridCollectionView ?? null;
|
|
26038
|
+
if (previous?.path === path && previous.rowMode === rowMode) return previous;
|
|
26039
|
+
const view = new BagCollectionView(store);
|
|
26040
|
+
if (previous) {
|
|
26041
|
+
previous.disconnect();
|
|
26042
|
+
view.sort(previous.sortedBy);
|
|
26043
|
+
view.copyFiltersFrom(previous);
|
|
26044
|
+
}
|
|
26045
|
+
node._internal.gridCollectionView = view;
|
|
26046
|
+
return view;
|
|
25631
26047
|
}
|
|
25632
26048
|
/** Subscribe once on Builder's Data wrapper; nothing is created. */
|
|
25633
26049
|
attach() {
|
|
@@ -25635,23 +26051,42 @@ var BindingRuntime = class {
|
|
|
25635
26051
|
}
|
|
25636
26052
|
/** Callback of the one Data subscription. */
|
|
25637
26053
|
receiveData(event) {
|
|
25638
|
-
|
|
25639
|
-
for (const [index, segment] of (event.pathlist ?? []).entries()) {
|
|
25640
|
-
const value = bag.node(segment)?.staticValue;
|
|
25641
|
-
if (!(value instanceof Bag)) break;
|
|
25642
|
-
const store = this.#collectionStores.get(value);
|
|
25643
|
-
store?.receiveData(
|
|
25644
|
-
event,
|
|
25645
|
-
index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null,
|
|
25646
|
-
event.pathlist[index + 2] ?? null
|
|
25647
|
-
);
|
|
25648
|
-
bag = value;
|
|
25649
|
-
}
|
|
26054
|
+
this.#notifyCollectionStores(event);
|
|
25650
26055
|
this.router.deliver(event);
|
|
25651
26056
|
for (const binding of [...this.#dataRootTrees]) {
|
|
25652
26057
|
if (!binding.closed && this.renderer.attached(binding.node)) this.renderer.project(binding.node);
|
|
25653
26058
|
}
|
|
25654
26059
|
}
|
|
26060
|
+
/**
|
|
26061
|
+
* Notify the collection stores an event reaches, by path. An event inside the collection
|
|
26062
|
+
* carries its row (the node under the store path, read without resolvers) and field; an event
|
|
26063
|
+
* on the store path, on a row list, or replacing an ancestor is a full change. A path that
|
|
26064
|
+
* does not hold a Bag notifies nothing: its consumers read the address and report the error.
|
|
26065
|
+
*/
|
|
26066
|
+
#notifyCollectionStores(event) {
|
|
26067
|
+
const { pathlist } = event;
|
|
26068
|
+
if (!this.#collectionStores.size || !pathlist?.length || pathlist[0] !== DATA_ROOT) return;
|
|
26069
|
+
const base = pathlist.slice(1), container = event.evt === "ins" || event.evt === "del";
|
|
26070
|
+
const labels = container ? (Array.isArray(event.node) ? event.node : [event.node]).map((node) => node.label) : [];
|
|
26071
|
+
for (const store of this.#collectionStores.values()) {
|
|
26072
|
+
const target = store.path.split(".");
|
|
26073
|
+
const shared = Math.min(base.length, target.length);
|
|
26074
|
+
let index = 0;
|
|
26075
|
+
while (index < shared && base[index] === target[index]) index++;
|
|
26076
|
+
if (index < shared) continue;
|
|
26077
|
+
let row = null, field = null;
|
|
26078
|
+
if (base.length > target.length) {
|
|
26079
|
+
row = base[target.length];
|
|
26080
|
+
field = base[target.length + 1] ?? null;
|
|
26081
|
+
} else if (base.length < target.length) {
|
|
26082
|
+
const reached = container ? labels.includes(target[base.length]) : event.evt === "upd_value";
|
|
26083
|
+
if (!reached) continue;
|
|
26084
|
+
}
|
|
26085
|
+
const bag = this.data.getItem(store.path, null, true);
|
|
26086
|
+
if (!(bag instanceof Bag)) continue;
|
|
26087
|
+
store.receiveData(event, row === null ? null : bag.node(row) ?? null, field);
|
|
26088
|
+
}
|
|
26089
|
+
}
|
|
25655
26090
|
/** The open NodeBinding of `node`, or null. */
|
|
25656
26091
|
bindingFor(node) {
|
|
25657
26092
|
return this.#bindings.get(node) ?? null;
|
|
@@ -25688,6 +26123,11 @@ var BindingRuntime = class {
|
|
|
25688
26123
|
} catch (error) {
|
|
25689
26124
|
errors.push(error);
|
|
25690
26125
|
}
|
|
26126
|
+
try {
|
|
26127
|
+
this.#moving(startKeys(node));
|
|
26128
|
+
} catch (error) {
|
|
26129
|
+
errors.push(error);
|
|
26130
|
+
}
|
|
25691
26131
|
}
|
|
25692
26132
|
if (errors.length) throw new AggregateError(errors, "Source branch close failed");
|
|
25693
26133
|
}
|
|
@@ -25702,6 +26142,52 @@ var BindingRuntime = class {
|
|
|
25702
26142
|
for (const each of nodes) this.bindingFor(each)?.rebind();
|
|
25703
26143
|
for (const each of nodes) this.renderer.project(each);
|
|
25704
26144
|
for (const each of nodes) this.bindingFor(each)?.remote?.trigger();
|
|
26145
|
+
this.#moving(nodes, nodes);
|
|
26146
|
+
}
|
|
26147
|
+
/**
|
|
26148
|
+
* Rebind and project the open NodeBindings whose registrations read one of `keys`, except those of
|
|
26149
|
+
* the nodes in `skip`; their errors are returned. A NodeBinding whose resolution fails keeps no
|
|
26150
|
+
* registration on the old paths and keeps its dependencies: it is rebound again when the start returns.
|
|
26151
|
+
*/
|
|
26152
|
+
#rebindDependents(keys, skip = /* @__PURE__ */ new Set()) {
|
|
26153
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
26154
|
+
for (const key2 of keys) {
|
|
26155
|
+
for (const binding of this.#dependents.get(key2) ?? []) if (!skip.has(binding.node)) bindings.add(binding);
|
|
26156
|
+
}
|
|
26157
|
+
const errors = [];
|
|
26158
|
+
const failed = /* @__PURE__ */ new Set();
|
|
26159
|
+
for (const binding of bindings) {
|
|
26160
|
+
if (binding.closed) continue;
|
|
26161
|
+
try {
|
|
26162
|
+
binding.rebind();
|
|
26163
|
+
} catch (error) {
|
|
26164
|
+
errors.push(error);
|
|
26165
|
+
failed.add(binding);
|
|
26166
|
+
}
|
|
26167
|
+
}
|
|
26168
|
+
for (const binding of bindings) {
|
|
26169
|
+
if (binding.closed || failed.has(binding)) continue;
|
|
26170
|
+
try {
|
|
26171
|
+
this.renderer.project(binding.node);
|
|
26172
|
+
binding.remote?.trigger();
|
|
26173
|
+
} catch (error) {
|
|
26174
|
+
errors.push(error);
|
|
26175
|
+
}
|
|
26176
|
+
}
|
|
26177
|
+
return errors;
|
|
26178
|
+
}
|
|
26179
|
+
/**
|
|
26180
|
+
* Keys moved by a Source change, with the nodes whose NodeBindings resolved again already: collected
|
|
26181
|
+
* until the end of the Source event, rebound at once outside one.
|
|
26182
|
+
*/
|
|
26183
|
+
#moving(keys, done = []) {
|
|
26184
|
+
if (this.#moved) {
|
|
26185
|
+
for (const key2 of keys) this.#moved.keys.add(key2);
|
|
26186
|
+
for (const node of done) this.#moved.done.add(node);
|
|
26187
|
+
return;
|
|
26188
|
+
}
|
|
26189
|
+
const errors = this.#rebindDependents(keys, new Set(done));
|
|
26190
|
+
if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Symbolic start rebinding failed");
|
|
25705
26191
|
}
|
|
25706
26192
|
/**
|
|
25707
26193
|
* Semantic work of one Source event, called inside the renderer FIFO (§5.2).
|
|
@@ -25725,6 +26211,7 @@ var BindingRuntime = class {
|
|
|
25725
26211
|
errors.push(error);
|
|
25726
26212
|
}
|
|
25727
26213
|
};
|
|
26214
|
+
const moved = this.#moved = { keys: /* @__PURE__ */ new Set(), done: /* @__PURE__ */ new Set() };
|
|
25728
26215
|
try {
|
|
25729
26216
|
if (evt === "ins") {
|
|
25730
26217
|
this.#openBranch(node);
|
|
@@ -25744,7 +26231,10 @@ var BindingRuntime = class {
|
|
|
25744
26231
|
} catch (error) {
|
|
25745
26232
|
if (!errors.length) throw error;
|
|
25746
26233
|
throw new AggregateError([...errors, error], "Source event failed");
|
|
26234
|
+
} finally {
|
|
26235
|
+
this.#moved = null;
|
|
25747
26236
|
}
|
|
26237
|
+
errors.push(...this.#rebindDependents(moved.keys, moved.done));
|
|
25748
26238
|
return errors;
|
|
25749
26239
|
}
|
|
25750
26240
|
/**
|
|
@@ -25780,7 +26270,8 @@ var BindingRuntime = class {
|
|
|
25780
26270
|
this.#disposed = true;
|
|
25781
26271
|
this.root.unsubscribe(this.#subscription, { any: true });
|
|
25782
26272
|
this.nodeIds.clear();
|
|
25783
|
-
this.#
|
|
26273
|
+
this.#dependents.clear();
|
|
26274
|
+
this.#collectionStores.clear();
|
|
25784
26275
|
const errors = [];
|
|
25785
26276
|
for (const [node, binding] of [...this.#bindings.entries()].reverse()) {
|
|
25786
26277
|
this.#bindings.delete(node);
|
|
@@ -25838,6 +26329,8 @@ var BindingRuntime = class {
|
|
|
25838
26329
|
if (errors.length > 1) throw new AggregateError(errors, "Source branch installation failed");
|
|
25839
26330
|
throw error;
|
|
25840
26331
|
}
|
|
26332
|
+
const installed = nodes.filter((node) => !known.has(node));
|
|
26333
|
+
this.#moving(installed.flatMap((node) => startKeys(node).slice(1)), installed);
|
|
25841
26334
|
for (const node of nodes) {
|
|
25842
26335
|
const binding = this.bindingFor(node);
|
|
25843
26336
|
if (!binding || binding.hasStamp("init") || !this.renderer.attached(node)) continue;
|
|
@@ -25886,7 +26379,9 @@ var BindingRuntime = class {
|
|
|
25886
26379
|
}
|
|
25887
26380
|
if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
|
|
25888
26381
|
if (current != null) this.nodeIds.set(current, node);
|
|
26382
|
+
this.#moving([`id:${previous}`, `id:${current}`]);
|
|
25889
26383
|
}
|
|
26384
|
+
if (Object.hasOwn(diff, "childname")) this.#moving([`childname:${diff.childname.old}`, `childname:${diff.childname.new}`]);
|
|
25890
26385
|
if (CONTEXT_ATTRIBUTES.some((name) => Object.hasOwn(diff, name))) this.rebindBranch(node);
|
|
25891
26386
|
else binding.rebind();
|
|
25892
26387
|
}
|
|
@@ -25932,6 +26427,8 @@ var NodeBinding = class {
|
|
|
25932
26427
|
// The registration of the node's own variable datapath, read in the parent's context.
|
|
25933
26428
|
#datapathRegistrations = /* @__PURE__ */ new Set();
|
|
25934
26429
|
#storeRegistration = null;
|
|
26430
|
+
// The starts of the symbolic resolution read by the registrations (BindingRuntime.dependOn).
|
|
26431
|
+
#dependencies = /* @__PURE__ */ new Set();
|
|
25935
26432
|
editingSession = null;
|
|
25936
26433
|
constructor(runtime, node) {
|
|
25937
26434
|
this.#runtime = runtime;
|
|
@@ -25950,6 +26447,10 @@ var NodeBinding = class {
|
|
|
25950
26447
|
get registrations() {
|
|
25951
26448
|
return [...this.#registrations];
|
|
25952
26449
|
}
|
|
26450
|
+
/** The starts of the symbolic resolution read by the active registrations: Source nodes and name keys. */
|
|
26451
|
+
get dependencies() {
|
|
26452
|
+
return this.#dependencies;
|
|
26453
|
+
}
|
|
25953
26454
|
/** The Provider of a `dataFormula`, `dataController`, `dataRpc` or `dataRemote`, as a list of zero or one. */
|
|
25954
26455
|
get providers() {
|
|
25955
26456
|
return this.#provider ? [this.#provider] : [];
|
|
@@ -25983,6 +26484,9 @@ var NodeBinding = class {
|
|
|
25983
26484
|
* again from its current value.
|
|
25984
26485
|
*/
|
|
25985
26486
|
registerPointers() {
|
|
26487
|
+
this.runtime.resolveFor(this, () => this.#registerPointers());
|
|
26488
|
+
}
|
|
26489
|
+
#registerPointers() {
|
|
25986
26490
|
if (this.node._getMeta("data_element")) {
|
|
25987
26491
|
this.runtime.renderer.references.remove(this.node);
|
|
25988
26492
|
this.runtime.renderer.references.register(this.node, null);
|
|
@@ -25997,33 +26501,33 @@ var NodeBinding = class {
|
|
|
25997
26501
|
}
|
|
25998
26502
|
const remoteDependencies = /* @__PURE__ */ new Set();
|
|
25999
26503
|
const component = node._getMeta("gramlot_component");
|
|
26000
|
-
for (const
|
|
26001
|
-
if (!component?.[
|
|
26002
|
-
|
|
26003
|
-
const store = node.treeStore;
|
|
26004
|
-
const subscription = `gramlot-tree-${randomId()}`;
|
|
26005
|
-
store.subscribe(subscription, { any: () => {
|
|
26006
|
-
if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
|
|
26007
|
-
} });
|
|
26008
|
-
this.#registrations.push({ close: () => store.unsubscribe(subscription, { any: true }) });
|
|
26009
|
-
continue;
|
|
26010
|
-
}
|
|
26504
|
+
for (const attribute of ["storepath", "structpath"]) {
|
|
26505
|
+
if (!component?.parameters?.[attribute]) continue;
|
|
26506
|
+
const store = attribute === "storepath";
|
|
26011
26507
|
const value = node.getAttr(attribute);
|
|
26012
26508
|
if (typeof value !== "string" || !value || /^[\^=]/.test(value) || value.includes("?")) {
|
|
26013
26509
|
throw new TypeError(`${attribute} requires a plain Bag data path`);
|
|
26014
26510
|
}
|
|
26015
|
-
if (
|
|
26511
|
+
if (store && node.nodeTag === "tree" && (value === "*S" || value.startsWith("*S."))) {
|
|
26016
26512
|
this.#registrations.push(this.runtime.registerTreeRoot(this, true));
|
|
26017
26513
|
continue;
|
|
26018
26514
|
}
|
|
26019
|
-
if (
|
|
26515
|
+
if (store && node.nodeTag === "tree" && value === "*D") {
|
|
26020
26516
|
this.#registrations.push(this.runtime.registerTreeRoot(this, false));
|
|
26021
26517
|
continue;
|
|
26022
26518
|
}
|
|
26023
|
-
const path =
|
|
26519
|
+
const path = store && node.nodeTag === "tree" && value.startsWith("*D.") ? value.slice(3) : node.absDatapath(value);
|
|
26024
26520
|
const registration = this.runtime.router.register({ path, recipient: this, subtree: true });
|
|
26025
26521
|
this.#registrations.push(registration);
|
|
26026
|
-
if (
|
|
26522
|
+
if (store && component.parameters.structpath) this.#storeRegistration = registration;
|
|
26523
|
+
}
|
|
26524
|
+
if (node.nodeTag === "tree") for (const [name, value] of Object.entries(node.getAttr())) {
|
|
26525
|
+
if (!name.startsWith("checked_")) continue;
|
|
26526
|
+
if (typeof value !== "string" || !value || /^[\^=]/.test(value)) {
|
|
26527
|
+
throw new TypeError(`tree ${name} requires a Data path, optionally followed by :joiner`);
|
|
26528
|
+
}
|
|
26529
|
+
const path = node.absDatapath(value.split(":")[0]);
|
|
26530
|
+
this.#registrations.push(this.runtime.router.register({ path, recipient: this }));
|
|
26027
26531
|
}
|
|
26028
26532
|
const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr("_timing")) : /* @__PURE__ */ new Set();
|
|
26029
26533
|
if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
|
|
@@ -26035,7 +26539,9 @@ var NodeBinding = class {
|
|
|
26035
26539
|
const absolute = context.absDatapath(pointer);
|
|
26036
26540
|
if (absolute === null) continue;
|
|
26037
26541
|
const [path, attr = null] = absolute.split("?", 2);
|
|
26038
|
-
const
|
|
26542
|
+
const spec = component?.parameters?.[name];
|
|
26543
|
+
const subtree = attr === null && spec !== void 0 && spec.binding !== "write" && [spec.dtype].flat().includes("X");
|
|
26544
|
+
const registration = this.runtime.router.register({ path, attr, recipient: this, subtree });
|
|
26039
26545
|
this.#registrations.push(registration);
|
|
26040
26546
|
if (name === "datapath") this.#datapathRegistrations.add(registration);
|
|
26041
26547
|
if (this.remote && (name === "remote" || name.startsWith("remote_") || remoteDependencies.has(name))) this.#remoteRegistrations.add(registration);
|
|
@@ -26151,6 +26657,7 @@ var NodeBinding = class {
|
|
|
26151
26657
|
if (errors.length) throw new AggregateError(errors, `NodeBinding of '${this.node.label}' cleanup failed`);
|
|
26152
26658
|
}
|
|
26153
26659
|
#closeRegistrations() {
|
|
26660
|
+
this.runtime.releaseDependencies(this);
|
|
26154
26661
|
this.#binder?.unregister();
|
|
26155
26662
|
for (const registration of this.#registrations.splice(0)) registration.close();
|
|
26156
26663
|
this.#storeRegistration = null;
|
|
@@ -26502,7 +27009,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26502
27009
|
this.destination = destination;
|
|
26503
27010
|
this.html = new HtmlElement({
|
|
26504
27011
|
uploadContext: () => ({ gramlot: binding.gramlot, window: destination.ownerDocument.defaultView }),
|
|
26505
|
-
metadataAttributes: ["__ref"],
|
|
27012
|
+
metadataAttributes: ["__ref", ...SYMBOLIC_ATTRIBUTES],
|
|
26506
27013
|
format: (value, options) => binding.gramlot.format(value, options),
|
|
26507
27014
|
reportError: (node, error, title) => {
|
|
26508
27015
|
if (this.records.has(node)) binding.reportError(error, title);
|
|
@@ -26604,9 +27111,26 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26604
27111
|
attrs = Object.assign({}, ...ancestors, attrs);
|
|
26605
27112
|
}
|
|
26606
27113
|
this.#rebuildAttributes.delete(node);
|
|
27114
|
+
attrs = this.#withoutHeldBags(attrs, component);
|
|
26607
27115
|
this.#resolvedAttributes.set(node, attrs);
|
|
26608
27116
|
return attrs;
|
|
26609
27117
|
}
|
|
27118
|
+
/**
|
|
27119
|
+
* A dtype 'X' component parameter whose value is a Bag with a parent (a sub Bag of Data or Source,
|
|
27120
|
+
* reached through a pointer) is projected as null: the component reads it at its address when it uses
|
|
27121
|
+
* it and never holds it (owner, 2026-11-10: "basta che non abbia parent"). A parentless Bag, such as a
|
|
27122
|
+
* Source-literal value, and every non-Bag value are projected as they are.
|
|
27123
|
+
*/
|
|
27124
|
+
#withoutHeldBags(attrs, component) {
|
|
27125
|
+
let result = attrs;
|
|
27126
|
+
for (const [name, spec] of Object.entries(component?.parameters ?? {})) {
|
|
27127
|
+
const value = attrs[name];
|
|
27128
|
+
if (!(value instanceof Bag) || !(value.parent || value.parentNode) || ![spec.dtype].flat().includes("X")) continue;
|
|
27129
|
+
if (result === attrs) result = { ...attrs };
|
|
27130
|
+
result[name] = null;
|
|
27131
|
+
}
|
|
27132
|
+
return result;
|
|
27133
|
+
}
|
|
26610
27134
|
/**
|
|
26611
27135
|
* Structural Source fragments are owned by the live renderer.
|
|
26612
27136
|
* A data-element has no DOM: it is recognized before validation and runtimeValues (R08).
|
|
@@ -27804,6 +28328,7 @@ var DeviceResolver = class extends BagResolver {
|
|
|
27804
28328
|
|
|
27805
28329
|
// src/handlers/device-handler.js
|
|
27806
28330
|
var NAMES = ["appinfo", "location"];
|
|
28331
|
+
var DEVICE = "_gramlot.device";
|
|
27807
28332
|
var ERROR_STATUS = {
|
|
27808
28333
|
UNAVAILABLE: "unavailable",
|
|
27809
28334
|
PERMISSION_DENIED: "denied",
|
|
@@ -27834,13 +28359,13 @@ var DeviceHandler = class extends Handler {
|
|
|
27834
28359
|
#pushEvents = null;
|
|
27835
28360
|
#shortcutEvents = null;
|
|
27836
28361
|
#linkEvents = null;
|
|
28362
|
+
#registration = null;
|
|
27837
28363
|
constructor(gramlot) {
|
|
27838
28364
|
super(gramlot);
|
|
27839
28365
|
this.provider = null;
|
|
27840
28366
|
this.disposed = false;
|
|
27841
28367
|
this.monitor = null;
|
|
27842
28368
|
this.retiring = null;
|
|
27843
|
-
this.resolvers = /* @__PURE__ */ new Map();
|
|
27844
28369
|
this.cleanup = Promise.resolve();
|
|
27845
28370
|
}
|
|
27846
28371
|
installData() {
|
|
@@ -27854,11 +28379,7 @@ var DeviceHandler = class extends Handler {
|
|
|
27854
28379
|
{ enabled: false, watching: false, status: "idle", error: null }
|
|
27855
28380
|
);
|
|
27856
28381
|
gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({ error: null }, false, true, false);
|
|
27857
|
-
this.#sensors.set(name, {
|
|
27858
|
-
node: gramlot.data.getNode(`_gramlot.device.${name}`),
|
|
27859
|
-
stream: null,
|
|
27860
|
-
cleanup: Promise.resolve()
|
|
27861
|
-
});
|
|
28382
|
+
this.#sensors.set(name, { stream: null, cleanup: Promise.resolve() });
|
|
27862
28383
|
}
|
|
27863
28384
|
for (const name of NAMES) {
|
|
27864
28385
|
const path = `_gramlot.device.${name}`;
|
|
@@ -27867,22 +28388,16 @@ var DeviceHandler = class extends Handler {
|
|
|
27867
28388
|
gramlot.data.setItem(path, null);
|
|
27868
28389
|
const node = gramlot.data.getNode(path);
|
|
27869
28390
|
node.setAttr(attrs, false, true, false);
|
|
27870
|
-
|
|
27871
|
-
node.resolver = resolver;
|
|
27872
|
-
this.resolvers.set(name, resolver);
|
|
28391
|
+
node.resolver = new DeviceResolver(this, name, attrs.cacheTime);
|
|
27873
28392
|
}
|
|
27874
28393
|
gramlot.data.setItem(
|
|
27875
28394
|
"_gramlot.device.clipboard",
|
|
27876
28395
|
null,
|
|
27877
28396
|
{ status: "idle", error: null, text: "", copy: null, paste: null, operation: null }
|
|
27878
28397
|
);
|
|
27879
|
-
const clipboard = gramlot.data.getNode("_gramlot.device.clipboard");
|
|
27880
28398
|
gramlot.data.setItem("_gramlot.device.camera", null, { status: "idle", error: null, capture: null, choose: null });
|
|
27881
|
-
const camera = gramlot.data.getNode("_gramlot.device.camera");
|
|
27882
28399
|
gramlot.data.setItem("_gramlot.device.barcode", null, { status: "idle", error: null, scan: null });
|
|
27883
|
-
const barcode = gramlot.data.getNode("_gramlot.device.barcode");
|
|
27884
28400
|
gramlot.data.setItem("_gramlot.device.biometrics", null, { status: "idle", error: null, verify: null });
|
|
27885
|
-
const biometrics = gramlot.data.getNode("_gramlot.device.biometrics");
|
|
27886
28401
|
const notifications = new Bag();
|
|
27887
28402
|
notifications.setItem("request", new Bag());
|
|
27888
28403
|
for (const name of ["scheduled", "received", "action"]) notifications.setItem(name, null);
|
|
@@ -27891,7 +28406,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27891
28406
|
notifications,
|
|
27892
28407
|
{ status: "idle", error: null, schedule: null, listening: false, listenerError: null }
|
|
27893
28408
|
);
|
|
27894
|
-
const notificationNode = gramlot.data.getNode("_gramlot.device.notifications");
|
|
27895
28409
|
const push = new Bag();
|
|
27896
28410
|
for (const name of ["registration", "received", "action"]) push.setItem(name, null);
|
|
27897
28411
|
gramlot.data.setItem(
|
|
@@ -27899,7 +28413,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27899
28413
|
push,
|
|
27900
28414
|
{ status: "idle", error: null, register: null, listening: false, listenerError: null }
|
|
27901
28415
|
);
|
|
27902
|
-
const pushNode = gramlot.data.getNode("_gramlot.device.push");
|
|
27903
28416
|
const links = new Bag();
|
|
27904
28417
|
links.setItem("request", null);
|
|
27905
28418
|
gramlot.data.setItem("_gramlot.device.links", links, { listening: false, listenerError: null });
|
|
@@ -27917,7 +28430,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27917
28430
|
null,
|
|
27918
28431
|
{ status: "idle", error: null, impact: null, style: "medium", vibrate: null, duration: 600 }
|
|
27919
28432
|
);
|
|
27920
|
-
const haptics = gramlot.data.getNode("_gramlot.device.haptics");
|
|
27921
28433
|
gramlot.data.setItem(
|
|
27922
28434
|
"_gramlot.device.audio",
|
|
27923
28435
|
null,
|
|
@@ -27934,62 +28446,56 @@ var DeviceHandler = class extends Handler {
|
|
|
27934
28446
|
shareActivity: null
|
|
27935
28447
|
}
|
|
27936
28448
|
);
|
|
27937
|
-
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
27943
|
-
|
|
27944
|
-
|
|
27945
|
-
|
|
27946
|
-
|
|
27947
|
-
|
|
27948
|
-
|
|
27949
|
-
|
|
27950
|
-
|
|
27951
|
-
|
|
27952
|
-
|
|
27953
|
-
|
|
27954
|
-
|
|
27955
|
-
|
|
27956
|
-
|
|
27957
|
-
|
|
27958
|
-
|
|
27959
|
-
if (
|
|
27960
|
-
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
27964
|
-
|
|
27965
|
-
if (
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
|
|
27969
|
-
|
|
27970
|
-
|
|
27971
|
-
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
|
|
27977
|
-
|
|
27978
|
-
|
|
27979
|
-
|
|
27980
|
-
|
|
27981
|
-
|
|
27982
|
-
|
|
27983
|
-
if (typeof
|
|
27984
|
-
|
|
27985
|
-
}
|
|
27986
|
-
resolver.cacheTime = cacheTime;
|
|
27987
|
-
if (resolver.name === "location") {
|
|
27988
|
-
if (typeof event.node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
|
|
27989
|
-
this.reconcile();
|
|
27990
|
-
}
|
|
28449
|
+
this.#registration = gramlot.src.binding.router.register({
|
|
28450
|
+
path: DEVICE,
|
|
28451
|
+
subtree: true,
|
|
28452
|
+
recipient: { receive: (change) => this.#receive(change) }
|
|
28453
|
+
});
|
|
28454
|
+
}
|
|
28455
|
+
/** The device node at `_gramlot.device.<name>`, read at each use. */
|
|
28456
|
+
#deviceNode(name) {
|
|
28457
|
+
return this.gramlot.data.getNode(`${DEVICE}.${name}`);
|
|
28458
|
+
}
|
|
28459
|
+
#receive(change) {
|
|
28460
|
+
if (this.disposed || !change.evt.startsWith("upd")) return;
|
|
28461
|
+
const segments = change.path.split(".");
|
|
28462
|
+
if (segments.length !== 3) return;
|
|
28463
|
+
const name = segments[2], diff = change.attrsDiff ?? {};
|
|
28464
|
+
const command = (attribute) => change.fired && diff[attribute]?.new === true;
|
|
28465
|
+
const node = change.node;
|
|
28466
|
+
if (this.#sensors.has(name) && diff.enabled) {
|
|
28467
|
+
if (typeof node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
|
|
28468
|
+
this.#reconcileSensor(name);
|
|
28469
|
+
}
|
|
28470
|
+
if (name === "clipboard") {
|
|
28471
|
+
if (command("copy")) this.#clipboardCommand("copy");
|
|
28472
|
+
if (command("paste")) this.#clipboardCommand("paste");
|
|
28473
|
+
}
|
|
28474
|
+
if (name === "audio") {
|
|
28475
|
+
if (command("start")) this.#startAudio();
|
|
28476
|
+
if (command("stop")) this.#stopAudio();
|
|
28477
|
+
if (command("cancel")) this.#cancelAudio();
|
|
28478
|
+
if (command("share")) this.#shareAudio();
|
|
28479
|
+
}
|
|
28480
|
+
if (name === "haptics" && command("impact")) this.#impact();
|
|
28481
|
+
if (name === "haptics" && command("vibrate")) this.#vibrate();
|
|
28482
|
+
if (name === "barcode" && command("scan")) this.#scanBarcode();
|
|
28483
|
+
if (name === "camera" && command("choose")) this.#photo("choose");
|
|
28484
|
+
if (name === "camera" && command("capture")) this.#photo("capture");
|
|
28485
|
+
if (name === "biometrics" && command("verify")) this.#verifyBiometrics();
|
|
28486
|
+
if (name === "notifications" && command("schedule")) this.#scheduleNotification();
|
|
28487
|
+
if (name === "push" && command("register")) this.#registerPush();
|
|
28488
|
+
if (NAMES.includes(name)) {
|
|
28489
|
+
const { cacheTime } = node.attr;
|
|
28490
|
+
if (typeof cacheTime !== "number" || !Number.isFinite(cacheTime) || cacheTime < 0 && cacheTime !== -1) {
|
|
28491
|
+
throw new TypeError("Device cacheTime must be -1 or a nonnegative number of seconds");
|
|
28492
|
+
}
|
|
28493
|
+
this.resolver(name).cacheTime = cacheTime;
|
|
28494
|
+
if (name === "location") {
|
|
28495
|
+
if (typeof node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
|
|
28496
|
+
this.reconcile();
|
|
27991
28497
|
}
|
|
27992
|
-
}
|
|
28498
|
+
}
|
|
27993
28499
|
}
|
|
27994
28500
|
/** Attach the explicitly selected provider once, before the page reads device values. */
|
|
27995
28501
|
attach(provider, { dispose = null } = {}) {
|
|
@@ -28030,16 +28536,16 @@ var DeviceHandler = class extends Handler {
|
|
|
28030
28536
|
node.setAttr({ status: "success", error: null }, true, true, false);
|
|
28031
28537
|
});
|
|
28032
28538
|
if (provider.capabilities.includes("links")) {
|
|
28033
|
-
this.#startLinkEvents(
|
|
28539
|
+
this.#startLinkEvents();
|
|
28034
28540
|
}
|
|
28035
28541
|
if (provider.capabilities.includes("shortcuts")) {
|
|
28036
|
-
this.#startShortcutEvents(
|
|
28542
|
+
this.#startShortcutEvents();
|
|
28037
28543
|
}
|
|
28038
28544
|
if (provider.capabilities.includes("push")) {
|
|
28039
|
-
this.#startPushEvents(
|
|
28545
|
+
this.#startPushEvents();
|
|
28040
28546
|
}
|
|
28041
28547
|
if (provider.capabilities.includes("notifications")) {
|
|
28042
|
-
this.#startNotificationEvents(
|
|
28548
|
+
this.#startNotificationEvents();
|
|
28043
28549
|
}
|
|
28044
28550
|
}
|
|
28045
28551
|
assertLive() {
|
|
@@ -28047,8 +28553,9 @@ var DeviceHandler = class extends Handler {
|
|
|
28047
28553
|
}
|
|
28048
28554
|
resolver(name) {
|
|
28049
28555
|
this.assertLive();
|
|
28050
|
-
|
|
28051
|
-
|
|
28556
|
+
const node = NAMES.includes(name) ? this.#deviceNode(name) : null;
|
|
28557
|
+
if (!node) throw new TypeError(`Unknown device value: ${name}`);
|
|
28558
|
+
return node.resolver;
|
|
28052
28559
|
}
|
|
28053
28560
|
invalidate(name) {
|
|
28054
28561
|
this.resolver(name).reset();
|
|
@@ -28060,65 +28567,67 @@ var DeviceHandler = class extends Handler {
|
|
|
28060
28567
|
const request = { revision: resolver.revision, received: resolver.received };
|
|
28061
28568
|
resolver.request = request;
|
|
28062
28569
|
this.attributes(resolver, { status: "pending", error: null });
|
|
28570
|
+
const current = () => this.resolver(name);
|
|
28063
28571
|
Promise.resolve().then(() => {
|
|
28064
|
-
if (this.disposed ||
|
|
28572
|
+
if (this.disposed || current().request !== request) return;
|
|
28065
28573
|
this.requireCapability(name);
|
|
28066
28574
|
return name === "appinfo" ? this.provider.readAppInfo() : this.provider.readLocation();
|
|
28067
28575
|
}).then((value) => {
|
|
28068
|
-
if (this.disposed ||
|
|
28069
|
-
this.accept(
|
|
28070
|
-
if (
|
|
28576
|
+
if (this.disposed || current().request !== request) return;
|
|
28577
|
+
this.accept(current(), value);
|
|
28578
|
+
if (current().revision !== request.revision) current()._lastUpdate = null;
|
|
28071
28579
|
}).catch((error) => {
|
|
28072
|
-
if (!this.disposed &&
|
|
28073
|
-
this.failure(
|
|
28580
|
+
if (!this.disposed && current().request === request && current().received === request.received) {
|
|
28581
|
+
this.failure(current(), error);
|
|
28074
28582
|
}
|
|
28075
28583
|
}).finally(() => {
|
|
28076
|
-
if (
|
|
28584
|
+
if (!this.disposed && current().request === request) current().request = null;
|
|
28077
28585
|
});
|
|
28078
28586
|
}
|
|
28079
28587
|
// Page-owned state streams share lifetime/error handling, never public dispatch.
|
|
28080
28588
|
#startStateEvents(name, start, accept) {
|
|
28081
|
-
const node = this
|
|
28589
|
+
const node = () => this.#deviceNode(name);
|
|
28082
28590
|
if (!this.provider.capabilities.includes(name)) {
|
|
28083
|
-
node.setAttr(failureAttributes({ code: "UNAVAILABLE", message: `${name} is unavailable` }), true, true, false);
|
|
28591
|
+
node().setAttr(failureAttributes({ code: "UNAVAILABLE", message: `${name} is unavailable` }), true, true, false);
|
|
28084
28592
|
return;
|
|
28085
28593
|
}
|
|
28086
28594
|
const events = { controller: new AbortController() };
|
|
28087
28595
|
this.#stateEvents.set(name, events);
|
|
28088
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28596
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28089
28597
|
events.start = Promise.resolve().then(() => {
|
|
28090
28598
|
if (events.controller.signal.aborted) return async () => {
|
|
28091
28599
|
};
|
|
28092
28600
|
return start((value) => {
|
|
28093
28601
|
if (events.controller.signal.aborted) return;
|
|
28094
28602
|
try {
|
|
28095
|
-
accept(node, value);
|
|
28603
|
+
accept(node(), value);
|
|
28096
28604
|
} catch (error) {
|
|
28097
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28605
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28098
28606
|
}
|
|
28099
28607
|
}, events.controller.signal);
|
|
28100
28608
|
}).then((stop) => {
|
|
28101
|
-
if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
|
|
28609
|
+
if (!events.controller.signal.aborted) node().setAttr({ listening: true }, true, true, false);
|
|
28102
28610
|
return stop;
|
|
28103
28611
|
});
|
|
28104
28612
|
events.start.catch((error) => {
|
|
28105
28613
|
const aborted = events.controller.signal.aborted;
|
|
28106
28614
|
events.controller.abort();
|
|
28107
|
-
if (!aborted) node.setAttr({ ...failureAttributes(error), listening: false }, true, true, false);
|
|
28615
|
+
if (!aborted) node().setAttr({ ...failureAttributes(error), listening: false }, true, true, false);
|
|
28108
28616
|
});
|
|
28109
28617
|
}
|
|
28110
|
-
#reconcileSensor(name
|
|
28111
|
-
const
|
|
28112
|
-
|
|
28618
|
+
#reconcileSensor(name) {
|
|
28619
|
+
const sensor = this.#sensors.get(name);
|
|
28620
|
+
const node = () => this.#deviceNode(name);
|
|
28621
|
+
if (!node().attr.enabled) {
|
|
28113
28622
|
const stream2 = sensor.stream;
|
|
28114
28623
|
if (!stream2) return;
|
|
28115
28624
|
sensor.stream = null;
|
|
28116
28625
|
stream2.controller.abort();
|
|
28117
28626
|
sensor.cleanup = stream2.start.then((stop) => stop(), () => void 0).then(() => {
|
|
28118
|
-
if (!this.disposed && !sensor.stream) node.setAttr({ watching: false, status: "idle", error: null }, true, true, false);
|
|
28627
|
+
if (!this.disposed && !sensor.stream) node().setAttr({ watching: false, status: "idle", error: null }, true, true, false);
|
|
28119
28628
|
});
|
|
28120
28629
|
sensor.cleanup.catch((error) => {
|
|
28121
|
-
if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
|
|
28630
|
+
if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
|
|
28122
28631
|
});
|
|
28123
28632
|
return;
|
|
28124
28633
|
}
|
|
@@ -28133,38 +28642,39 @@ var DeviceHandler = class extends Handler {
|
|
|
28133
28642
|
if (this.disposed || stream.controller.signal.aborted) return;
|
|
28134
28643
|
try {
|
|
28135
28644
|
if (event?.kind === "state" && typeof event.watching === "boolean") {
|
|
28136
|
-
node.setAttr({ watching: event.watching, status: event.watching ? "pending" : "idle", error: null }, true, true, false);
|
|
28645
|
+
node().setAttr({ watching: event.watching, status: event.watching ? "pending" : "idle", error: null }, true, true, false);
|
|
28137
28646
|
} else if (event?.kind === "sample") {
|
|
28138
28647
|
for (const field of ["x", "y", "z", "timestamp"]) {
|
|
28139
28648
|
if (!Number.isFinite(event[field])) throw new TypeError(`Invalid ${name}.${field}`);
|
|
28140
28649
|
}
|
|
28141
|
-
if (!node.attr.watching) return;
|
|
28142
|
-
if (node.staticValue && event.timestamp < node.staticValue.getItem("timestamp")) return;
|
|
28650
|
+
if (!node().attr.watching) return;
|
|
28651
|
+
if (node().staticValue && event.timestamp < node().staticValue.getItem("timestamp")) return;
|
|
28143
28652
|
const value = new Bag();
|
|
28144
28653
|
for (const field of ["x", "y", "z", "timestamp"]) value.setItem(field, event[field]);
|
|
28145
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28654
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28146
28655
|
} else if (event?.kind === "error" && event.error instanceof Error) {
|
|
28147
|
-
node.setAttr({ ...failureAttributes(event.error), watching: false }, true, true, false);
|
|
28656
|
+
node().setAttr({ ...failureAttributes(event.error), watching: false }, true, true, false);
|
|
28148
28657
|
} else throw new TypeError(`Invalid ${name} event`);
|
|
28149
28658
|
} catch (error) {
|
|
28150
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28659
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28151
28660
|
}
|
|
28152
28661
|
};
|
|
28153
28662
|
return name === "gyroscope" ? this.provider.startGyroscopeUpdates(accept, stream.controller.signal) : this.provider.startAccelerometerUpdates(accept, stream.controller.signal);
|
|
28154
28663
|
});
|
|
28155
28664
|
stream.start.catch((error) => {
|
|
28156
28665
|
if (!this.disposed && !stream.controller.signal.aborted) {
|
|
28157
|
-
node.setAttr({ ...failureAttributes(error), watching: false }, true, true, false);
|
|
28666
|
+
node().setAttr({ ...failureAttributes(error), watching: false }, true, true, false);
|
|
28158
28667
|
}
|
|
28159
28668
|
});
|
|
28160
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28669
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28161
28670
|
}
|
|
28162
|
-
#startAudio(
|
|
28671
|
+
#startAudio() {
|
|
28672
|
+
const node = () => this.#deviceNode("audio");
|
|
28163
28673
|
const previous = this.#audio;
|
|
28164
28674
|
if (previous) {
|
|
28165
28675
|
if (previous.phase !== "complete") return;
|
|
28166
28676
|
previous.phase = "replacing";
|
|
28167
|
-
node.setValue(null, true, {
|
|
28677
|
+
node().setValue(null, true, {
|
|
28168
28678
|
status: "pending",
|
|
28169
28679
|
error: null,
|
|
28170
28680
|
recording: false,
|
|
@@ -28175,18 +28685,18 @@ var DeviceHandler = class extends Handler {
|
|
|
28175
28685
|
previous.close = previous.start.then((session) => session.dispose()).then(() => {
|
|
28176
28686
|
if (this.disposed || previous.controller.signal.aborted || this.#audio !== previous) return;
|
|
28177
28687
|
this.#audio = null;
|
|
28178
|
-
this.#startAudio(
|
|
28688
|
+
this.#startAudio();
|
|
28179
28689
|
}).catch((error) => {
|
|
28180
28690
|
if (!this.disposed && this.#audio === previous) {
|
|
28181
28691
|
previous.phase = "failed";
|
|
28182
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28692
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28183
28693
|
}
|
|
28184
28694
|
});
|
|
28185
28695
|
return;
|
|
28186
28696
|
}
|
|
28187
28697
|
const audio = { controller: new AbortController(), phase: "starting" };
|
|
28188
28698
|
this.#audio = audio;
|
|
28189
|
-
node.setValue(null, true, {
|
|
28699
|
+
node().setValue(null, true, {
|
|
28190
28700
|
status: "pending",
|
|
28191
28701
|
error: null,
|
|
28192
28702
|
recording: false,
|
|
@@ -28198,24 +28708,25 @@ var DeviceHandler = class extends Handler {
|
|
|
28198
28708
|
if (audio.controller.signal.aborted) return null;
|
|
28199
28709
|
this.requireCapability("audio");
|
|
28200
28710
|
return this.provider.startAudioRecording((error) => {
|
|
28201
|
-
if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(
|
|
28711
|
+
if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(error);
|
|
28202
28712
|
}, audio.controller.signal);
|
|
28203
28713
|
});
|
|
28204
28714
|
audio.start.then((session) => {
|
|
28205
28715
|
if (!session || audio.controller.signal.aborted || this.disposed) return;
|
|
28206
28716
|
audio.phase = "recording";
|
|
28207
|
-
node.setAttr({ status: "recording", error: null, recording: true }, true, true, false);
|
|
28717
|
+
node().setAttr({ status: "recording", error: null, recording: true }, true, true, false);
|
|
28208
28718
|
}).catch((error) => {
|
|
28209
28719
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28210
28720
|
if (this.#audio === audio) this.#audio = null;
|
|
28211
|
-
node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28721
|
+
node().setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28212
28722
|
});
|
|
28213
28723
|
}
|
|
28214
|
-
#stopAudio(
|
|
28724
|
+
#stopAudio() {
|
|
28725
|
+
const node = () => this.#deviceNode("audio");
|
|
28215
28726
|
const audio = this.#audio;
|
|
28216
28727
|
if (!audio || audio.phase !== "recording") return;
|
|
28217
28728
|
audio.phase = "stopping";
|
|
28218
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28729
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28219
28730
|
audio.stop = audio.start.then((session) => session.stop()).then((result) => {
|
|
28220
28731
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28221
28732
|
if (typeof result?.url !== "string" || !result.url || typeof result.mimeType !== "string" || !result.mimeType.startsWith("audio/") || !Number.isFinite(result.duration) || result.duration < 0) {
|
|
@@ -28224,39 +28735,41 @@ var DeviceHandler = class extends Handler {
|
|
|
28224
28735
|
const value = new Bag();
|
|
28225
28736
|
for (const key2 of ["url", "mimeType", "duration"]) value.setItem(key2, result[key2]);
|
|
28226
28737
|
audio.phase = "complete";
|
|
28227
|
-
node.setValue(value, true, { status: "success", error: null, recording: false }, true, false);
|
|
28738
|
+
node().setValue(value, true, { status: "success", error: null, recording: false }, true, false);
|
|
28228
28739
|
}).catch((error) => {
|
|
28229
|
-
if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(
|
|
28740
|
+
if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(error);
|
|
28230
28741
|
});
|
|
28231
28742
|
}
|
|
28232
|
-
#shareAudio(
|
|
28743
|
+
#shareAudio() {
|
|
28744
|
+
const node = () => this.#deviceNode("audio");
|
|
28233
28745
|
const audio = this.#audio;
|
|
28234
28746
|
if (audio?.phase === "sharing") return;
|
|
28235
28747
|
if (!audio || audio.phase !== "complete") {
|
|
28236
28748
|
const failure2 = failureAttributes(new Error("Record and stop audio before sharing"));
|
|
28237
|
-
node.setAttr({ shareStatus: failure2.status, shareError: failure2.error, shareActivity: null }, true, true, false);
|
|
28749
|
+
node().setAttr({ shareStatus: failure2.status, shareError: failure2.error, shareActivity: null }, true, true, false);
|
|
28238
28750
|
return;
|
|
28239
28751
|
}
|
|
28240
28752
|
audio.phase = "sharing";
|
|
28241
|
-
node.setAttr({ shareStatus: "pending", shareError: null, shareActivity: null }, true, true, false);
|
|
28753
|
+
node().setAttr({ shareStatus: "pending", shareError: null, shareActivity: null }, true, true, false);
|
|
28242
28754
|
audio.share = audio.start.then((session) => session.share(audio.controller.signal)).then((result) => {
|
|
28243
28755
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28244
28756
|
if (typeof result?.activity !== "string") throw new TypeError("Invalid audio share result from device provider");
|
|
28245
|
-
node.setAttr({ shareStatus: "success", shareError: null, shareActivity: result.activity }, true, true, false);
|
|
28757
|
+
node().setAttr({ shareStatus: "success", shareError: null, shareActivity: result.activity }, true, true, false);
|
|
28246
28758
|
}).catch((error) => {
|
|
28247
28759
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28248
28760
|
const failure2 = failureAttributes(error);
|
|
28249
|
-
node.setAttr({ shareStatus: failure2.status, shareError: failure2.error, shareActivity: null }, true, true, false);
|
|
28761
|
+
node().setAttr({ shareStatus: failure2.status, shareError: failure2.error, shareActivity: null }, true, true, false);
|
|
28250
28762
|
}).finally(() => {
|
|
28251
28763
|
if (this.#audio === audio && !audio.controller.signal.aborted) audio.phase = "complete";
|
|
28252
28764
|
});
|
|
28253
28765
|
}
|
|
28254
|
-
#cancelAudio(
|
|
28766
|
+
#cancelAudio(error = { code: "CANCELLED", message: "Audio recording cancelled" }) {
|
|
28767
|
+
const node = () => this.#deviceNode("audio");
|
|
28255
28768
|
const audio = this.#audio;
|
|
28256
28769
|
if (!audio || audio.phase === "closing" || audio.phase === "sharing") return;
|
|
28257
28770
|
audio.phase = "closing";
|
|
28258
28771
|
audio.controller.abort();
|
|
28259
|
-
node.setValue(null, true, {
|
|
28772
|
+
node().setValue(null, true, {
|
|
28260
28773
|
status: "pending",
|
|
28261
28774
|
error: null,
|
|
28262
28775
|
shareStatus: "idle",
|
|
@@ -28268,20 +28781,21 @@ var DeviceHandler = class extends Handler {
|
|
|
28268
28781
|
}).then(() => {
|
|
28269
28782
|
if (this.disposed || this.#audio !== audio) return;
|
|
28270
28783
|
this.#audio = null;
|
|
28271
|
-
node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28784
|
+
node().setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28272
28785
|
}).catch((cleanupError) => {
|
|
28273
28786
|
if (!this.disposed && this.#audio === audio) {
|
|
28274
28787
|
audio.phase = "failed";
|
|
28275
|
-
node.setAttr(failureAttributes(cleanupError), true, true, false);
|
|
28788
|
+
node().setAttr(failureAttributes(cleanupError), true, true, false);
|
|
28276
28789
|
}
|
|
28277
28790
|
});
|
|
28278
28791
|
}
|
|
28279
|
-
#clipboardCommand(
|
|
28792
|
+
#clipboardCommand(operation) {
|
|
28793
|
+
const node = () => this.#deviceNode("clipboard");
|
|
28280
28794
|
if (this.#clipboardRequest) return;
|
|
28281
28795
|
const request = new AbortController();
|
|
28282
28796
|
this.#clipboardRequest = request;
|
|
28283
|
-
const text3 = node.attr.text;
|
|
28284
|
-
node.setValue(null, true, { status: "pending", error: null, operation }, true, false);
|
|
28797
|
+
const text3 = node().attr.text;
|
|
28798
|
+
node().setValue(null, true, { status: "pending", error: null, operation }, true, false);
|
|
28285
28799
|
Promise.resolve().then(async () => {
|
|
28286
28800
|
if (request.signal.aborted) return;
|
|
28287
28801
|
this.requireCapability("clipboard");
|
|
@@ -28297,19 +28811,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28297
28811
|
if (typeof result?.text !== "string") throw new TypeError("Invalid clipboard text from device provider");
|
|
28298
28812
|
const value = new Bag();
|
|
28299
28813
|
value.setItem("text", result.text);
|
|
28300
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28814
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28301
28815
|
}).catch((error) => {
|
|
28302
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28816
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28303
28817
|
}).finally(() => {
|
|
28304
28818
|
if (this.#clipboardRequest === request) this.#clipboardRequest = null;
|
|
28305
28819
|
});
|
|
28306
28820
|
}
|
|
28307
|
-
#vibrate(
|
|
28821
|
+
#vibrate() {
|
|
28822
|
+
const node = () => this.#deviceNode("haptics");
|
|
28308
28823
|
if (this.#hapticRequest) return;
|
|
28309
28824
|
const request = new AbortController();
|
|
28310
28825
|
this.#hapticRequest = request;
|
|
28311
|
-
const { duration } = node.attr;
|
|
28312
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28826
|
+
const { duration } = node().attr;
|
|
28827
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28313
28828
|
Promise.resolve().then(async () => {
|
|
28314
28829
|
if (request.signal.aborted) return;
|
|
28315
28830
|
this.requireCapability("haptics");
|
|
@@ -28321,19 +28836,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28321
28836
|
const value = new Bag();
|
|
28322
28837
|
value.setItem("duration", duration);
|
|
28323
28838
|
value.setItem("acknowledged", true);
|
|
28324
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28839
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28325
28840
|
}).catch((error) => {
|
|
28326
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28841
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28327
28842
|
}).finally(() => {
|
|
28328
28843
|
if (this.#hapticRequest === request) this.#hapticRequest = null;
|
|
28329
28844
|
});
|
|
28330
28845
|
}
|
|
28331
|
-
#impact(
|
|
28846
|
+
#impact() {
|
|
28847
|
+
const node = () => this.#deviceNode("haptics");
|
|
28332
28848
|
if (this.#hapticRequest) return;
|
|
28333
28849
|
const request = new AbortController();
|
|
28334
28850
|
this.#hapticRequest = request;
|
|
28335
|
-
const { style } = node.attr;
|
|
28336
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28851
|
+
const { style } = node().attr;
|
|
28852
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28337
28853
|
Promise.resolve().then(async () => {
|
|
28338
28854
|
if (request.signal.aborted) return;
|
|
28339
28855
|
this.requireCapability("haptics");
|
|
@@ -28343,18 +28859,19 @@ var DeviceHandler = class extends Handler {
|
|
|
28343
28859
|
const value = new Bag();
|
|
28344
28860
|
value.setItem("style", style);
|
|
28345
28861
|
value.setItem("acknowledged", true);
|
|
28346
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28862
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28347
28863
|
}).catch((error) => {
|
|
28348
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28864
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28349
28865
|
}).finally(() => {
|
|
28350
28866
|
if (this.#hapticRequest === request) this.#hapticRequest = null;
|
|
28351
28867
|
});
|
|
28352
28868
|
}
|
|
28353
|
-
#scanBarcode(
|
|
28869
|
+
#scanBarcode() {
|
|
28870
|
+
const node = () => this.#deviceNode("barcode");
|
|
28354
28871
|
if (this.#barcodeRequest) return;
|
|
28355
28872
|
const request = new AbortController();
|
|
28356
28873
|
this.#barcodeRequest = request;
|
|
28357
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28874
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28358
28875
|
Promise.resolve().then(() => {
|
|
28359
28876
|
if (request.signal.aborted) return;
|
|
28360
28877
|
this.requireCapability("barcode");
|
|
@@ -28367,19 +28884,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28367
28884
|
const value = new Bag();
|
|
28368
28885
|
value.setItem("text", result.text);
|
|
28369
28886
|
value.setItem("format", result.format);
|
|
28370
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28887
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28371
28888
|
}).catch((error) => {
|
|
28372
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28889
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28373
28890
|
}).finally(() => {
|
|
28374
28891
|
if (this.#barcodeRequest === request) this.#barcodeRequest = null;
|
|
28375
28892
|
});
|
|
28376
28893
|
}
|
|
28377
28894
|
// Camera is an explicit Data event, never a resolver read with a UI side effect.
|
|
28378
|
-
#photo(
|
|
28895
|
+
#photo(operation) {
|
|
28896
|
+
const node = () => this.#deviceNode("camera");
|
|
28379
28897
|
if (this.#captureRequest) return;
|
|
28380
28898
|
const request = new AbortController();
|
|
28381
28899
|
this.#captureRequest = request;
|
|
28382
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28900
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28383
28901
|
Promise.resolve().then(() => {
|
|
28384
28902
|
if (request.signal.aborted) return;
|
|
28385
28903
|
this.requireCapability("camera");
|
|
@@ -28392,19 +28910,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28392
28910
|
const value = new Bag();
|
|
28393
28911
|
value.setItem("url", photo.url);
|
|
28394
28912
|
value.setItem("format", photo.format);
|
|
28395
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28913
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28396
28914
|
}).catch((error) => {
|
|
28397
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28915
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28398
28916
|
}).finally(() => {
|
|
28399
28917
|
if (this.#captureRequest === request) this.#captureRequest = null;
|
|
28400
28918
|
});
|
|
28401
28919
|
}
|
|
28402
28920
|
// A fresh attempt clears the previous local verification, including on cancellation.
|
|
28403
|
-
#verifyBiometrics(
|
|
28921
|
+
#verifyBiometrics() {
|
|
28922
|
+
const node = () => this.#deviceNode("biometrics");
|
|
28404
28923
|
if (this.#biometricsRequest) return;
|
|
28405
28924
|
const request = new AbortController();
|
|
28406
28925
|
this.#biometricsRequest = request;
|
|
28407
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28926
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28408
28927
|
Promise.resolve().then(() => {
|
|
28409
28928
|
if (request.signal.aborted) return;
|
|
28410
28929
|
this.requireCapability("biometrics");
|
|
@@ -28413,14 +28932,15 @@ var DeviceHandler = class extends Handler {
|
|
|
28413
28932
|
if (request.signal.aborted) return;
|
|
28414
28933
|
const result = new Bag();
|
|
28415
28934
|
result.setItem("verified", true);
|
|
28416
|
-
node.setValue(result, true, { status: "success", error: null }, true, false);
|
|
28935
|
+
node().setValue(result, true, { status: "success", error: null }, true, false);
|
|
28417
28936
|
}).catch((error) => {
|
|
28418
|
-
if (!request.signal.aborted) node.setValue(null, true, failureAttributes(error), true, false);
|
|
28937
|
+
if (!request.signal.aborted) node().setValue(null, true, failureAttributes(error), true, false);
|
|
28419
28938
|
}).finally(() => {
|
|
28420
28939
|
if (this.#biometricsRequest === request) this.#biometricsRequest = null;
|
|
28421
28940
|
});
|
|
28422
28941
|
}
|
|
28423
|
-
#startNotificationEvents(
|
|
28942
|
+
#startNotificationEvents() {
|
|
28943
|
+
const node = () => this.#deviceNode("notifications");
|
|
28424
28944
|
if (this.#notificationEvents) return this.#notificationEvents.start;
|
|
28425
28945
|
const events = { controller: new AbortController() };
|
|
28426
28946
|
this.#notificationEvents = events;
|
|
@@ -28436,13 +28956,13 @@ var DeviceHandler = class extends Handler {
|
|
|
28436
28956
|
const value = new Bag();
|
|
28437
28957
|
for (const key2 of ["id", "title", "body"]) value.setItem(key2, event[key2]);
|
|
28438
28958
|
if (event.kind === "action") value.setItem("actionId", event.actionId);
|
|
28439
|
-
node.staticValue.setItem(event.kind, value);
|
|
28959
|
+
node().staticValue.setItem(event.kind, value);
|
|
28440
28960
|
} catch (error) {
|
|
28441
|
-
node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28961
|
+
node().setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28442
28962
|
}
|
|
28443
28963
|
}, events.controller.signal);
|
|
28444
28964
|
}).then((stop) => {
|
|
28445
|
-
if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
|
|
28965
|
+
if (!events.controller.signal.aborted) node().setAttr({ listening: true }, true, true, false);
|
|
28446
28966
|
return stop;
|
|
28447
28967
|
});
|
|
28448
28968
|
events.start.catch((error) => {
|
|
@@ -28450,27 +28970,28 @@ var DeviceHandler = class extends Handler {
|
|
|
28450
28970
|
events.controller.abort();
|
|
28451
28971
|
if (this.#notificationEvents === events) this.#notificationEvents = null;
|
|
28452
28972
|
if (!aborted) {
|
|
28453
|
-
node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28973
|
+
node().setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28454
28974
|
}
|
|
28455
28975
|
});
|
|
28456
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28976
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
28457
28977
|
return events.start;
|
|
28458
28978
|
}
|
|
28459
|
-
#scheduleNotification(
|
|
28979
|
+
#scheduleNotification() {
|
|
28980
|
+
const node = () => this.#deviceNode("notifications");
|
|
28460
28981
|
if (this.#notificationRequest) return;
|
|
28461
28982
|
const request = new AbortController();
|
|
28462
28983
|
this.#notificationRequest = request;
|
|
28463
|
-
const value = node.staticValue.getItem("request");
|
|
28984
|
+
const value = node().staticValue.getItem("request");
|
|
28464
28985
|
const input = value instanceof Bag ? Object.fromEntries(["id", "title", "body", "delay"].map((key2) => [key2, value.getItem(key2)])) : null;
|
|
28465
|
-
node.staticValue.setItem("scheduled", null);
|
|
28466
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28986
|
+
node().staticValue.setItem("scheduled", null);
|
|
28987
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28467
28988
|
Promise.resolve().then(async () => {
|
|
28468
28989
|
if (request.signal.aborted) return;
|
|
28469
28990
|
this.requireCapability("notifications");
|
|
28470
28991
|
if (!input || !Number.isInteger(input.id) || input.id < 1 || input.id > 2147483647 || typeof input.title !== "string" || !input.title.trim() || typeof input.body !== "string" || !input.body.trim() || typeof input.delay !== "number" || !Number.isFinite(input.delay) || input.delay <= 0) {
|
|
28471
28992
|
throw new TypeError("Notification requires a positive 32-bit id, title, body and positive delay in seconds");
|
|
28472
28993
|
}
|
|
28473
|
-
await this.#startNotificationEvents(
|
|
28994
|
+
await this.#startNotificationEvents();
|
|
28474
28995
|
if (request.signal.aborted) return;
|
|
28475
28996
|
return this.provider.scheduleNotification(input, request.signal);
|
|
28476
28997
|
}).then((result) => {
|
|
@@ -28481,10 +29002,10 @@ var DeviceHandler = class extends Handler {
|
|
|
28481
29002
|
const scheduled = new Bag();
|
|
28482
29003
|
scheduled.setItem("id", result.id);
|
|
28483
29004
|
scheduled.setItem("at", result.at);
|
|
28484
|
-
node.staticValue.setItem("scheduled", scheduled);
|
|
28485
|
-
node.setAttr({ status: "success", error: null }, true, true, false);
|
|
29005
|
+
node().staticValue.setItem("scheduled", scheduled);
|
|
29006
|
+
node().setAttr({ status: "success", error: null }, true, true, false);
|
|
28486
29007
|
}).catch((error) => {
|
|
28487
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
29008
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28488
29009
|
}).finally(() => {
|
|
28489
29010
|
if (this.#notificationRequest === request) this.#notificationRequest = null;
|
|
28490
29011
|
});
|
|
@@ -28495,18 +29016,19 @@ var DeviceHandler = class extends Handler {
|
|
|
28495
29016
|
if (request) clearTimeout(request.timer);
|
|
28496
29017
|
return request;
|
|
28497
29018
|
}
|
|
28498
|
-
#acceptPushEvent(
|
|
29019
|
+
#acceptPushEvent(event) {
|
|
29020
|
+
const node = () => this.#deviceNode("push");
|
|
28499
29021
|
if (event.kind === "registration") {
|
|
28500
29022
|
if (typeof event.token !== "string" || !event.token) throw new TypeError("Invalid push registration token");
|
|
28501
29023
|
this.#finishPushRequest();
|
|
28502
29024
|
const value = new Bag();
|
|
28503
29025
|
value.setItem("token", event.token);
|
|
28504
|
-
node.staticValue.setItem("registration", value);
|
|
28505
|
-
node.setAttr({ status: "success", error: null }, true, true, false);
|
|
29026
|
+
node().staticValue.setItem("registration", value);
|
|
29027
|
+
node().setAttr({ status: "success", error: null }, true, true, false);
|
|
28506
29028
|
} else if (event.kind === "registrationError") {
|
|
28507
29029
|
this.#finishPushRequest();
|
|
28508
|
-
node.staticValue.setItem("registration", null);
|
|
28509
|
-
node.setAttr(failureAttributes(event.error), true, true, false);
|
|
29030
|
+
node().staticValue.setItem("registration", null);
|
|
29031
|
+
node().setAttr(failureAttributes(event.error), true, true, false);
|
|
28510
29032
|
} else {
|
|
28511
29033
|
if (!["received", "action"].includes(event.kind)) throw new TypeError("Invalid push event kind");
|
|
28512
29034
|
const fields = ["id", "title", "body", "messageId", "destination"];
|
|
@@ -28516,10 +29038,11 @@ var DeviceHandler = class extends Handler {
|
|
|
28516
29038
|
if (typeof event[key2] !== "string") throw new TypeError(`Invalid push event ${key2}`);
|
|
28517
29039
|
value.setItem(key2, event[key2]);
|
|
28518
29040
|
}
|
|
28519
|
-
node.staticValue.setItem(event.kind, value);
|
|
29041
|
+
node().staticValue.setItem(event.kind, value);
|
|
28520
29042
|
}
|
|
28521
29043
|
}
|
|
28522
|
-
#startPushEvents(
|
|
29044
|
+
#startPushEvents() {
|
|
29045
|
+
const node = () => this.#deviceNode("push");
|
|
28523
29046
|
if (this.#pushEvents) return this.#pushEvents.start;
|
|
28524
29047
|
const events = { controller: new AbortController() };
|
|
28525
29048
|
this.#pushEvents = events;
|
|
@@ -28529,25 +29052,26 @@ var DeviceHandler = class extends Handler {
|
|
|
28529
29052
|
return this.provider.startPushEvents((event) => {
|
|
28530
29053
|
if (events.controller.signal.aborted) return;
|
|
28531
29054
|
try {
|
|
28532
|
-
this.#acceptPushEvent(
|
|
29055
|
+
this.#acceptPushEvent(event);
|
|
28533
29056
|
} catch (error) {
|
|
28534
|
-
node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
29057
|
+
node().setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28535
29058
|
}
|
|
28536
29059
|
}, events.controller.signal);
|
|
28537
29060
|
}).then((stop) => {
|
|
28538
|
-
if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
|
|
29061
|
+
if (!events.controller.signal.aborted) node().setAttr({ listening: true }, true, true, false);
|
|
28539
29062
|
return stop;
|
|
28540
29063
|
});
|
|
28541
29064
|
events.start.catch((error) => {
|
|
28542
29065
|
const aborted = events.controller.signal.aborted;
|
|
28543
29066
|
events.controller.abort();
|
|
28544
29067
|
if (this.#pushEvents === events) this.#pushEvents = null;
|
|
28545
|
-
if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
29068
|
+
if (!aborted) node().setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28546
29069
|
});
|
|
28547
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
29070
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
28548
29071
|
return events.start;
|
|
28549
29072
|
}
|
|
28550
|
-
#registerPush(
|
|
29073
|
+
#registerPush() {
|
|
29074
|
+
const node = () => this.#deviceNode("push");
|
|
28551
29075
|
if (this.#pushRequest) return;
|
|
28552
29076
|
const request = { controller: new AbortController(), timer: null };
|
|
28553
29077
|
this.#pushRequest = request;
|
|
@@ -28555,24 +29079,25 @@ var DeviceHandler = class extends Handler {
|
|
|
28555
29079
|
if (this.disposed || this.#pushRequest !== request) return;
|
|
28556
29080
|
this.#finishPushRequest();
|
|
28557
29081
|
request.controller.abort();
|
|
28558
|
-
node.setAttr(failureAttributes({ code: "TIMEOUT", message: "Push registration has not returned a token" }), true, true, false);
|
|
29082
|
+
node().setAttr(failureAttributes({ code: "TIMEOUT", message: "Push registration has not returned a token" }), true, true, false);
|
|
28559
29083
|
}, 3e4);
|
|
28560
|
-
node.staticValue.setItem("registration", null);
|
|
28561
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
29084
|
+
node().staticValue.setItem("registration", null);
|
|
29085
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28562
29086
|
Promise.resolve().then(async () => {
|
|
28563
29087
|
if (request.controller.signal.aborted) return;
|
|
28564
29088
|
this.requireCapability("push");
|
|
28565
|
-
await this.#startPushEvents(
|
|
29089
|
+
await this.#startPushEvents();
|
|
28566
29090
|
if (request.controller.signal.aborted || this.#pushRequest !== request) return;
|
|
28567
29091
|
await this.provider.registerPush(request.controller.signal);
|
|
28568
29092
|
}).catch((error) => {
|
|
28569
29093
|
if (this.disposed || this.#pushRequest !== request) return;
|
|
28570
29094
|
this.#finishPushRequest();
|
|
28571
29095
|
request.controller.abort();
|
|
28572
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
29096
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28573
29097
|
});
|
|
28574
29098
|
}
|
|
28575
|
-
#startShortcutEvents(
|
|
29099
|
+
#startShortcutEvents() {
|
|
29100
|
+
const node = () => this.#deviceNode("shortcuts");
|
|
28576
29101
|
const events = { controller: new AbortController() };
|
|
28577
29102
|
this.#shortcutEvents = events;
|
|
28578
29103
|
events.start = Promise.resolve().then(() => {
|
|
@@ -28587,27 +29112,28 @@ var DeviceHandler = class extends Handler {
|
|
|
28587
29112
|
throw new TypeError(`Invalid shortcut request ${key2}`);
|
|
28588
29113
|
}
|
|
28589
29114
|
}
|
|
28590
|
-
if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
29115
|
+
if (node().staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
28591
29116
|
const value = new Bag();
|
|
28592
29117
|
value.setItem("id", request.id);
|
|
28593
29118
|
value.setItem("destination", request.destination);
|
|
28594
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28595
|
-
node.staticValue.setItem("request", value);
|
|
29119
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
29120
|
+
node().staticValue.setItem("request", value);
|
|
28596
29121
|
} catch (error2) {
|
|
28597
|
-
node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
29122
|
+
node().setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
28598
29123
|
}
|
|
28599
29124
|
}, events.controller.signal);
|
|
28600
29125
|
}).then((stop) => {
|
|
28601
|
-
if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
|
|
29126
|
+
if (!events.controller.signal.aborted) node().setAttr({ listening: true }, true, true, false);
|
|
28602
29127
|
return stop;
|
|
28603
29128
|
});
|
|
28604
29129
|
events.start.catch((error) => {
|
|
28605
29130
|
const aborted = events.controller.signal.aborted;
|
|
28606
29131
|
events.controller.abort();
|
|
28607
|
-
if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
29132
|
+
if (!aborted) node().setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28608
29133
|
});
|
|
28609
29134
|
}
|
|
28610
|
-
#startLinkEvents(
|
|
29135
|
+
#startLinkEvents() {
|
|
29136
|
+
const node = () => this.#deviceNode("links");
|
|
28611
29137
|
const events = { controller: new AbortController() };
|
|
28612
29138
|
this.#linkEvents = events;
|
|
28613
29139
|
events.start = Promise.resolve().then(() => {
|
|
@@ -28622,24 +29148,24 @@ var DeviceHandler = class extends Handler {
|
|
|
28622
29148
|
throw new TypeError(`Invalid link request ${key2}`);
|
|
28623
29149
|
}
|
|
28624
29150
|
}
|
|
28625
|
-
if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
29151
|
+
if (node().staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
28626
29152
|
const value = new Bag();
|
|
28627
29153
|
value.setItem("id", request.id);
|
|
28628
29154
|
value.setItem("url", request.url);
|
|
28629
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28630
|
-
node.staticValue.setItem("request", value);
|
|
29155
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
29156
|
+
node().staticValue.setItem("request", value);
|
|
28631
29157
|
} catch (error2) {
|
|
28632
|
-
node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
29158
|
+
node().setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
28633
29159
|
}
|
|
28634
29160
|
}, events.controller.signal);
|
|
28635
29161
|
}).then((stop) => {
|
|
28636
|
-
if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
|
|
29162
|
+
if (!events.controller.signal.aborted) node().setAttr({ listening: true }, true, true, false);
|
|
28637
29163
|
return stop;
|
|
28638
29164
|
});
|
|
28639
29165
|
events.start.catch((error) => {
|
|
28640
29166
|
const aborted = events.controller.signal.aborted;
|
|
28641
29167
|
events.controller.abort();
|
|
28642
|
-
if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
29168
|
+
if (!aborted) node().setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28643
29169
|
});
|
|
28644
29170
|
}
|
|
28645
29171
|
requireCapability(name) {
|
|
@@ -28651,7 +29177,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28651
29177
|
const writing = resolver.writing;
|
|
28652
29178
|
resolver.writing = true;
|
|
28653
29179
|
try {
|
|
28654
|
-
resolver.
|
|
29180
|
+
this.#deviceNode(resolver.name).setAttr(attrs, true, true, false);
|
|
28655
29181
|
} finally {
|
|
28656
29182
|
resolver.writing = writing;
|
|
28657
29183
|
}
|
|
@@ -28677,7 +29203,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28677
29203
|
const writing = resolver.writing;
|
|
28678
29204
|
resolver.writing = true;
|
|
28679
29205
|
try {
|
|
28680
|
-
resolver.
|
|
29206
|
+
this.#deviceNode(resolver.name).setValue(bag, true, { status: "success", error: null }, true, false);
|
|
28681
29207
|
} finally {
|
|
28682
29208
|
resolver.writing = writing;
|
|
28683
29209
|
}
|
|
@@ -28687,8 +29213,8 @@ var DeviceHandler = class extends Handler {
|
|
|
28687
29213
|
this.attributes(resolver, failureAttributes(error));
|
|
28688
29214
|
}
|
|
28689
29215
|
reconcile() {
|
|
28690
|
-
const resolver = this.
|
|
28691
|
-
if (
|
|
29216
|
+
const resolver = () => this.resolver("location");
|
|
29217
|
+
if (this.#deviceNode("location").attr.enabled) {
|
|
28692
29218
|
if (this.monitor) return;
|
|
28693
29219
|
const monitor = { stop: null, controller: new AbortController() };
|
|
28694
29220
|
this.monitor = monitor;
|
|
@@ -28697,12 +29223,12 @@ var DeviceHandler = class extends Handler {
|
|
|
28697
29223
|
this.requireCapability("location");
|
|
28698
29224
|
return this.provider.startLocationUpdates((value, error) => {
|
|
28699
29225
|
if (this.disposed || this.monitor !== monitor) return;
|
|
28700
|
-
if (error) this.failure(resolver, error);
|
|
29226
|
+
if (error) this.failure(resolver(), error);
|
|
28701
29227
|
else {
|
|
28702
29228
|
try {
|
|
28703
|
-
this.accept(resolver, value);
|
|
29229
|
+
this.accept(resolver(), value);
|
|
28704
29230
|
} catch (failure2) {
|
|
28705
|
-
this.failure(resolver, failure2);
|
|
29231
|
+
this.failure(resolver(), failure2);
|
|
28706
29232
|
}
|
|
28707
29233
|
}
|
|
28708
29234
|
}, monitor.controller.signal);
|
|
@@ -28710,14 +29236,14 @@ var DeviceHandler = class extends Handler {
|
|
|
28710
29236
|
monitor.start.then((stop) => {
|
|
28711
29237
|
if (stop === null || this.disposed || this.monitor !== monitor) return;
|
|
28712
29238
|
monitor.stop = stop;
|
|
28713
|
-
this.attributes(resolver, { watching: true });
|
|
29239
|
+
this.attributes(resolver(), { watching: true });
|
|
28714
29240
|
}).catch((error) => {
|
|
28715
29241
|
if (!this.disposed && this.monitor === monitor) {
|
|
28716
|
-
this.attributes(resolver, { watching: false });
|
|
28717
|
-
this.failure(resolver, error);
|
|
29242
|
+
this.attributes(resolver(), { watching: false });
|
|
29243
|
+
this.failure(resolver(), error);
|
|
28718
29244
|
}
|
|
28719
29245
|
});
|
|
28720
|
-
this.attributes(resolver, { status: "pending", error: null });
|
|
29246
|
+
this.attributes(resolver(), { status: "pending", error: null });
|
|
28721
29247
|
} else if (this.monitor) {
|
|
28722
29248
|
const monitor = this.monitor;
|
|
28723
29249
|
this.monitor = null;
|
|
@@ -28727,14 +29253,14 @@ var DeviceHandler = class extends Handler {
|
|
|
28727
29253
|
if (this.retiring === monitor) this.retiring = null;
|
|
28728
29254
|
if (!this.disposed) {
|
|
28729
29255
|
const attrs = { watching: false };
|
|
28730
|
-
if (!this.monitor && !resolver.request &&
|
|
29256
|
+
if (!this.monitor && !resolver().request && this.#deviceNode("location").attr.status === "pending") {
|
|
28731
29257
|
Object.assign(attrs, { status: "cancelled", error: null });
|
|
28732
29258
|
}
|
|
28733
|
-
this.attributes(resolver, attrs);
|
|
29259
|
+
this.attributes(resolver(), attrs);
|
|
28734
29260
|
}
|
|
28735
29261
|
});
|
|
28736
29262
|
this.cleanup.catch((error) => {
|
|
28737
|
-
if (!this.disposed) this.failure(resolver, error);
|
|
29263
|
+
if (!this.disposed) this.failure(resolver(), error);
|
|
28738
29264
|
});
|
|
28739
29265
|
}
|
|
28740
29266
|
}
|
|
@@ -28743,9 +29269,9 @@ var DeviceHandler = class extends Handler {
|
|
|
28743
29269
|
this.assertLive();
|
|
28744
29270
|
if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== "string") throw new TypeError("Invalid database name");
|
|
28745
29271
|
if (this.#database) throw new Error("This page already owns a database connection");
|
|
28746
|
-
const node = this
|
|
29272
|
+
const node = () => this.#deviceNode("database");
|
|
28747
29273
|
const state = (status, error = null) => {
|
|
28748
|
-
if (!this.disposed) node.setAttr({ status, error }, true, true, false);
|
|
29274
|
+
if (!this.disposed) node().setAttr({ status, error }, true, true, false);
|
|
28749
29275
|
};
|
|
28750
29276
|
if (!this.provider.capabilities.includes("database")) {
|
|
28751
29277
|
const error = Object.assign(new Error("Native database unavailable"), { code: "UNAVAILABLE" });
|
|
@@ -28798,7 +29324,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28798
29324
|
};
|
|
28799
29325
|
} catch (error) {
|
|
28800
29326
|
if (this.#database === slot) this.#database = null;
|
|
28801
|
-
if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
|
|
29327
|
+
if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
|
|
28802
29328
|
throw error;
|
|
28803
29329
|
}
|
|
28804
29330
|
}
|
|
@@ -28848,7 +29374,8 @@ var DeviceHandler = class extends Handler {
|
|
|
28848
29374
|
const notificationEvents = this.#notificationEvents;
|
|
28849
29375
|
this.#notificationEvents = null;
|
|
28850
29376
|
notificationEvents?.controller.abort();
|
|
28851
|
-
this
|
|
29377
|
+
this.#registration?.close();
|
|
29378
|
+
this.#registration = null;
|
|
28852
29379
|
const monitor = this.monitor;
|
|
28853
29380
|
this.monitor = null;
|
|
28854
29381
|
monitor?.controller.abort();
|
|
@@ -28895,7 +29422,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28895
29422
|
this.cleanup.catch((error) => {
|
|
28896
29423
|
this.cleanupError = error;
|
|
28897
29424
|
});
|
|
28898
|
-
for (const
|
|
29425
|
+
if (this.provider) for (const name of NAMES) this.#deviceNode(name).resolver.request = null;
|
|
28899
29426
|
}
|
|
28900
29427
|
};
|
|
28901
29428
|
|
|
@@ -29157,6 +29684,7 @@ var Gramlot = class {
|
|
|
29157
29684
|
}
|
|
29158
29685
|
} finally {
|
|
29159
29686
|
this._pageStore?.close();
|
|
29687
|
+
for (const name of [...this.rpc.connections.keys()]) this.rpc.unregisterConnection(name);
|
|
29160
29688
|
this._frames.dispose();
|
|
29161
29689
|
if (this.rpc.transport) {
|
|
29162
29690
|
try {
|
|
@@ -29462,23 +29990,38 @@ IndexPage.registerSource("index_panel");
|
|
|
29462
29990
|
function mountIndexPage(renderer, root, onSelection = () => {
|
|
29463
29991
|
}, prepareEntry = () => {
|
|
29464
29992
|
}, {
|
|
29465
|
-
state = root.
|
|
29993
|
+
state = root.absDatapath("."),
|
|
29466
29994
|
createEntry = null,
|
|
29467
29995
|
onLoad = () => {
|
|
29468
29996
|
}
|
|
29469
29997
|
} = {}) {
|
|
29470
|
-
|
|
29471
|
-
|
|
29472
|
-
const
|
|
29998
|
+
if (typeof state !== "string" || !state) throw new TypeError("IndexPage state must be a Data path");
|
|
29999
|
+
const data = renderer.binding.gramlot.data;
|
|
30000
|
+
const read = (name) => data.getItem(`${state}.${name}`);
|
|
30001
|
+
const write = (name, value) => data.setItem(`${state}.${name}`, value);
|
|
30002
|
+
const navigation = () => read("navigation");
|
|
30003
|
+
if (!(navigation() instanceof Bag)) throw new TypeError("IndexPage navigation must be a Bag");
|
|
30004
|
+
const tabs = () => root.value.getNode("frame.center.tabs");
|
|
29473
30005
|
const builder = root.builder;
|
|
29474
30006
|
const entries3 = /* @__PURE__ */ new Map();
|
|
29475
30007
|
const context = { entries: entries3, disposed: false, selecting: false, sequence: 0, requested: null };
|
|
29476
|
-
|
|
29477
|
-
const
|
|
29478
|
-
|
|
30008
|
+
root._internal.indexContext = context;
|
|
30009
|
+
const createRecord = ({ url, path, title, paneLabel, loading }) => ({
|
|
30010
|
+
url,
|
|
30011
|
+
path,
|
|
30012
|
+
title,
|
|
30013
|
+
paneLabel,
|
|
30014
|
+
loading,
|
|
30015
|
+
get pane() {
|
|
30016
|
+
return tabs().value?.getNode(this.paneLabel) ?? null;
|
|
30017
|
+
},
|
|
30018
|
+
get node() {
|
|
30019
|
+
return navigation().getNode(this.path);
|
|
30020
|
+
}
|
|
30021
|
+
});
|
|
30022
|
+
for (const record2 of read("opened").getNodes()) {
|
|
29479
30023
|
const { url, path, title } = record2.attr;
|
|
29480
|
-
const
|
|
29481
|
-
const entry = { url, path, title, pane, node: navigation.getNode(path), loading: false };
|
|
30024
|
+
const entry = createRecord({ url, path, title, paneLabel: record2.label, loading: false });
|
|
29482
30025
|
prepareEntry(entry);
|
|
29483
30026
|
entries3.set(url, entry);
|
|
29484
30027
|
context.sequence++;
|
|
@@ -29499,20 +30042,23 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29499
30042
|
if (context.disposed) return;
|
|
29500
30043
|
context.selecting = true;
|
|
29501
30044
|
try {
|
|
29502
|
-
|
|
29503
|
-
|
|
30045
|
+
write("active", entry.url);
|
|
30046
|
+
write("navigationSelection", entry.path);
|
|
29504
30047
|
onSelection(entries3, entry.url);
|
|
29505
30048
|
} finally {
|
|
29506
30049
|
context.selecting = false;
|
|
29507
30050
|
}
|
|
29508
30051
|
};
|
|
30052
|
+
const forget = (paneLabel) => {
|
|
30053
|
+
if (read("opened").getNode(paneLabel)) read("opened").popNode(paneLabel);
|
|
30054
|
+
};
|
|
29509
30055
|
function requestSelection(path) {
|
|
29510
30056
|
void select(path).catch((error) => {
|
|
29511
30057
|
if (!context.disposed) renderer.binding.reportError(error, "Page could not be opened");
|
|
29512
30058
|
});
|
|
29513
30059
|
}
|
|
29514
30060
|
async function select(path) {
|
|
29515
|
-
const node = navigation.getNode(path);
|
|
30061
|
+
const node = navigation().getNode(path);
|
|
29516
30062
|
if (!node) throw new Error(`Unknown index navigation path: ${path}`);
|
|
29517
30063
|
const url = node.attr.url;
|
|
29518
30064
|
if (url == null) return;
|
|
@@ -29524,16 +30070,18 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29524
30070
|
activate(entry);
|
|
29525
30071
|
return;
|
|
29526
30072
|
}
|
|
29527
|
-
while (tabs.value !== null && tabs.value.getNode(`page${context.sequence}`)) context.sequence++;
|
|
29528
|
-
const
|
|
29529
|
-
|
|
29530
|
-
|
|
30073
|
+
while (tabs().value !== null && tabs().value.getNode(`page${context.sequence}`)) context.sequence++;
|
|
30074
|
+
const paneLabel = `page${context.sequence++}`;
|
|
30075
|
+
const title = node.attr.title ?? node.label;
|
|
30076
|
+
builder.wrapSource(tabs()).contentPane({
|
|
30077
|
+
node_label: paneLabel,
|
|
30078
|
+
title,
|
|
29531
30079
|
pageName: url,
|
|
29532
30080
|
height: "100%",
|
|
29533
30081
|
closable: true
|
|
29534
|
-
})
|
|
29535
|
-
const previous =
|
|
29536
|
-
entry = { url, path,
|
|
30082
|
+
});
|
|
30083
|
+
const previous = read("active");
|
|
30084
|
+
entry = createRecord({ url, path, title, paneLabel, loading: true });
|
|
29537
30085
|
entries3.set(url, entry);
|
|
29538
30086
|
try {
|
|
29539
30087
|
notifyLoad(entry, "loading");
|
|
@@ -29543,20 +30091,21 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29543
30091
|
if (createEntry) await createEntry(entry);
|
|
29544
30092
|
else {
|
|
29545
30093
|
const selection = new Bag();
|
|
29546
|
-
|
|
29547
|
-
|
|
30094
|
+
const selected = entry.node;
|
|
30095
|
+
selection.setItem(selected.label, null, { ...selected.attr });
|
|
30096
|
+
const mounted = await renderer.binding.gramlot.src.remoteSource(entry.pane, "index_panel", { selection });
|
|
29548
30097
|
if (!mounted) throw new Error("Panel loading was cancelled");
|
|
29549
30098
|
}
|
|
29550
30099
|
if (context.disposed || entries3.get(url) !== entry) return;
|
|
29551
|
-
opened.setItem(
|
|
30100
|
+
read("opened").setItem(paneLabel, null, { url, path: entry.path, title: entry.title });
|
|
29552
30101
|
prepareEntry(entry);
|
|
29553
30102
|
} catch (error) {
|
|
29554
30103
|
if (context.disposed || entries3.get(url) !== entry) return;
|
|
29555
30104
|
try {
|
|
29556
30105
|
renderer.binding.reportError(error, "Page could not be opened");
|
|
29557
30106
|
entries3.delete(url);
|
|
29558
|
-
|
|
29559
|
-
if (pane
|
|
30107
|
+
forget(paneLabel);
|
|
30108
|
+
if (entry.pane) tabs().value.popNode(paneLabel);
|
|
29560
30109
|
if (!context.disposed && context.requested === url) {
|
|
29561
30110
|
const restored = entries3.get(previous);
|
|
29562
30111
|
context.requested = restored?.url ?? null;
|
|
@@ -29564,8 +30113,8 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29564
30113
|
else {
|
|
29565
30114
|
context.selecting = true;
|
|
29566
30115
|
try {
|
|
29567
|
-
|
|
29568
|
-
|
|
30116
|
+
write("active", null);
|
|
30117
|
+
write("navigationSelection", null);
|
|
29569
30118
|
onSelection(entries3, null);
|
|
29570
30119
|
} finally {
|
|
29571
30120
|
context.selecting = false;
|
|
@@ -29582,65 +30131,69 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29582
30131
|
if (!context.disposed && entries3.get(url) === entry && context.requested === url) activate(entry);
|
|
29583
30132
|
}
|
|
29584
30133
|
const sourceSubscription = `${root.getAttr("id")}-page-close`;
|
|
29585
|
-
|
|
29586
|
-
|
|
29587
|
-
|
|
30134
|
+
const source = builder.source;
|
|
30135
|
+
const tabsPath = [...root.fullpath.split(".").slice(1), "frame", "center", "tabs"].join(".");
|
|
30136
|
+
source.subscribe(sourceSubscription, { any: (event) => {
|
|
30137
|
+
if (event.evt !== "del" || (event.pathlist ?? []).join(".") !== tabsPath) return;
|
|
30138
|
+
const entry = [...entries3.values()].find((candidate) => candidate.paneLabel === event.node.label);
|
|
29588
30139
|
if (!entry) return;
|
|
29589
|
-
const { url,
|
|
30140
|
+
const { url, paneLabel } = entry;
|
|
29590
30141
|
if (context.disposed || renderer.disposed || entries3.get(url) !== entry) return;
|
|
29591
30142
|
entries3.delete(url);
|
|
29592
|
-
|
|
30143
|
+
forget(paneLabel);
|
|
29593
30144
|
try {
|
|
29594
|
-
if (
|
|
30145
|
+
if (read("active") === url) {
|
|
29595
30146
|
const next = [...entries3.values()].at(-1);
|
|
29596
30147
|
context.requested = next?.url ?? null;
|
|
29597
30148
|
if (next) activate(next);
|
|
29598
30149
|
else {
|
|
29599
30150
|
context.selecting = true;
|
|
29600
30151
|
try {
|
|
29601
|
-
|
|
29602
|
-
|
|
30152
|
+
write("active", null);
|
|
30153
|
+
write("navigationSelection", null);
|
|
29603
30154
|
onSelection(entries3, null);
|
|
29604
30155
|
} finally {
|
|
29605
30156
|
context.selecting = false;
|
|
29606
30157
|
}
|
|
29607
30158
|
}
|
|
29608
|
-
} else onSelection(entries3,
|
|
30159
|
+
} else onSelection(entries3, read("active"));
|
|
29609
30160
|
} finally {
|
|
29610
30161
|
finishLoad(entry, "cancelled");
|
|
29611
30162
|
}
|
|
29612
30163
|
} });
|
|
29613
|
-
const
|
|
29614
|
-
|
|
29615
|
-
|
|
29616
|
-
|
|
29617
|
-
const path =
|
|
30164
|
+
const router = renderer.binding.router;
|
|
30165
|
+
const registrations2 = [
|
|
30166
|
+
router.register({ path: `${state}.navigationSelection`, recipient: { receive: () => {
|
|
30167
|
+
if (context.selecting || context.disposed) return;
|
|
30168
|
+
const path = read("navigationSelection");
|
|
29618
30169
|
if (path !== null) requestSelection(path);
|
|
29619
|
-
}
|
|
29620
|
-
|
|
30170
|
+
} } }),
|
|
30171
|
+
router.register({ path: `${state}.active`, recipient: { receive: () => {
|
|
30172
|
+
if (context.selecting || context.disposed) return;
|
|
30173
|
+
const entry = entries3.get(read("active"));
|
|
29621
30174
|
if (entry) {
|
|
29622
30175
|
context.requested = entry.url;
|
|
29623
30176
|
activate(entry);
|
|
29624
30177
|
}
|
|
29625
|
-
}
|
|
29626
|
-
|
|
30178
|
+
} } })
|
|
30179
|
+
];
|
|
29627
30180
|
const dispose = () => {
|
|
29628
30181
|
if (context.disposed) return;
|
|
29629
30182
|
context.disposed = true;
|
|
29630
|
-
|
|
29631
|
-
|
|
30183
|
+
for (const registration of registrations2) registration.close();
|
|
30184
|
+
source.unsubscribe(sourceSubscription, { any: true });
|
|
29632
30185
|
for (const entry of entries3.values()) if (entry.loading) {
|
|
29633
|
-
if (entry.pane
|
|
30186
|
+
if (entry.pane) tabs().value.popNode(entry.paneLabel);
|
|
29634
30187
|
finishLoad(entry, "cancelled");
|
|
29635
30188
|
}
|
|
29636
30189
|
entries3.clear();
|
|
29637
|
-
if (root.indexContext === context) delete root.indexContext;
|
|
30190
|
+
if (root._internal.indexContext === context) delete root._internal.indexContext;
|
|
29638
30191
|
};
|
|
29639
30192
|
context.dispose = dispose;
|
|
29640
30193
|
renderer.onDispose(root, dispose);
|
|
29641
|
-
const active = entries3.get(
|
|
30194
|
+
const active = entries3.get(read("active"));
|
|
29642
30195
|
if (active) activate(active);
|
|
29643
|
-
else if (
|
|
30196
|
+
else if (read("navigationSelection") !== null) requestSelection(read("navigationSelection"));
|
|
29644
30197
|
return context;
|
|
29645
30198
|
}
|
|
29646
30199
|
var IndexLogic = class {
|
|
@@ -29813,11 +30366,11 @@ var FileSystemLogic = class {
|
|
|
29813
30366
|
fileSystemMount(node) {
|
|
29814
30367
|
const scope = node.parentNode;
|
|
29815
30368
|
const controller = new FileSystemController(this.page, scope);
|
|
29816
|
-
|
|
30369
|
+
scope._internal.fileSystemController = controller;
|
|
29817
30370
|
this.page.src.renderer.onDispose(scope, () => controller.dispose());
|
|
29818
30371
|
}
|
|
29819
30372
|
fileSystemOpen(node, { root }) {
|
|
29820
|
-
if (root) return node.parentNode.fileSystemController.open(root);
|
|
30373
|
+
if (root) return node.parentNode._internal.fileSystemController.open(root);
|
|
29821
30374
|
}
|
|
29822
30375
|
};
|
|
29823
30376
|
function fileSystemTree(parent, { datapath, ...attributes }) {
|
|
@@ -29843,6 +30396,7 @@ function fileSystemTree(parent, { datapath, ...attributes }) {
|
|
|
29843
30396
|
// src/ide-documents.js
|
|
29844
30397
|
var documentKey = (root, path) => "d_" + [...new TextEncoder().encode(JSON.stringify([root, path]))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
29845
30398
|
var IdeDocuments = class {
|
|
30399
|
+
#registrations = /* @__PURE__ */ new Map();
|
|
29846
30400
|
constructor(gramlot, source) {
|
|
29847
30401
|
this.gramlot = gramlot;
|
|
29848
30402
|
this.source = source;
|
|
@@ -29855,6 +30409,18 @@ var IdeDocuments = class {
|
|
|
29855
30409
|
get documents() {
|
|
29856
30410
|
return this.state.getItem("documents");
|
|
29857
30411
|
}
|
|
30412
|
+
/** An image document's annotations, observed at their Data path, are serialized into its content. */
|
|
30413
|
+
#observeAnnotations(key2) {
|
|
30414
|
+
const path = this.source.absDatapath(`.documents.${key2}.annotations`);
|
|
30415
|
+
this.#registrations.set(key2, this.gramlot.src.binding.router.register({
|
|
30416
|
+
path,
|
|
30417
|
+
subtree: true,
|
|
30418
|
+
recipient: { receive: () => {
|
|
30419
|
+
const doc = this.documents.getItem(key2);
|
|
30420
|
+
doc.setItem("content", doc.getItem("annotations").toTytx());
|
|
30421
|
+
} }
|
|
30422
|
+
}));
|
|
30423
|
+
}
|
|
29858
30424
|
async open(root, path) {
|
|
29859
30425
|
if (!/\.(?:py|js|mjs|ts|json|html|css|xml|md|markdown|sql|typ|txt|png|jpg|jpeg|webp)$/i.test(path)) return null;
|
|
29860
30426
|
const key2 = documentKey(root, path);
|
|
@@ -29867,12 +30433,9 @@ var IdeDocuments = class {
|
|
|
29867
30433
|
const document = new Bag();
|
|
29868
30434
|
const content = result.language === "image" ? result.content.toTytx() : result.content;
|
|
29869
30435
|
for (const [name, value] of Object.entries({ ...result, content, root, saved: content, busy: false })) document.setItem(name, value);
|
|
29870
|
-
if (result.language === "image")
|
|
29871
|
-
const annotations = result.content;
|
|
29872
|
-
document.setItem("annotations", annotations);
|
|
29873
|
-
annotations.subscribe("ide-annotations", { any: () => document.setItem("content", annotations.toTytx()) });
|
|
29874
|
-
}
|
|
30436
|
+
if (result.language === "image") document.setItem("annotations", result.content);
|
|
29875
30437
|
this.documents.setItem(key2, document);
|
|
30438
|
+
if (result.language === "image") this.#observeAnnotations(key2);
|
|
29876
30439
|
return key2;
|
|
29877
30440
|
}).finally(() => this.pending.delete(key2));
|
|
29878
30441
|
this.pending.set(key2, { request, promise });
|
|
@@ -29913,16 +30476,17 @@ var IdeDocuments = class {
|
|
|
29913
30476
|
{ signal: request.signal }
|
|
29914
30477
|
).then((result) => {
|
|
29915
30478
|
if (this.disposed || request.signal.aborted) return false;
|
|
29916
|
-
|
|
29917
|
-
|
|
29918
|
-
|
|
29919
|
-
|
|
29920
|
-
|
|
29921
|
-
|
|
30479
|
+
const doc2 = this.documents.getItem(key2);
|
|
30480
|
+
doc2.setItem("root", result.root);
|
|
30481
|
+
doc2.setItem("path", result.path);
|
|
30482
|
+
doc2.setItem("revision", result.revision);
|
|
30483
|
+
doc2.setItem("saved", content);
|
|
30484
|
+
doc2.setItem("isNew", false);
|
|
30485
|
+
doc2.setItem("createHidden", true);
|
|
29922
30486
|
return true;
|
|
29923
30487
|
}).finally(() => {
|
|
29924
30488
|
this.pending.delete(key2);
|
|
29925
|
-
if (!this.disposed)
|
|
30489
|
+
if (!this.disposed) this.documents.getItem(key2).setItem("busy", false);
|
|
29926
30490
|
});
|
|
29927
30491
|
this.pending.set(key2, { request, promise });
|
|
29928
30492
|
return promise;
|
|
@@ -29950,19 +30514,22 @@ var IdeDocuments = class {
|
|
|
29950
30514
|
{ content },
|
|
29951
30515
|
{ signal: request.signal }
|
|
29952
30516
|
).then((result) => {
|
|
29953
|
-
if (this.disposed || request.signal.aborted
|
|
29954
|
-
|
|
29955
|
-
|
|
29956
|
-
|
|
30517
|
+
if (this.disposed || request.signal.aborted) return false;
|
|
30518
|
+
const doc2 = this.documents.getItem(key2);
|
|
30519
|
+
if (doc2.getItem("content") !== content) return false;
|
|
30520
|
+
doc2.setItem("typstSource", result.source);
|
|
30521
|
+
doc2.setItem("previewHidden", false);
|
|
30522
|
+
doc2.setItem("renderStatus", "Typst generated from the current recipe.");
|
|
29957
30523
|
return true;
|
|
29958
30524
|
}).catch((error) => {
|
|
29959
|
-
if (!this.disposed && !request.signal.aborted)
|
|
30525
|
+
if (!this.disposed && !request.signal.aborted) this.documents.getItem(key2).setItem("renderStatus", error.message);
|
|
29960
30526
|
return false;
|
|
29961
30527
|
}).finally(() => {
|
|
29962
30528
|
this.pending.delete(key2);
|
|
29963
30529
|
if (!this.disposed) {
|
|
29964
|
-
|
|
29965
|
-
|
|
30530
|
+
const doc2 = this.documents.getItem(key2);
|
|
30531
|
+
doc2.setItem("rendering", false);
|
|
30532
|
+
doc2.setItem("busy", false);
|
|
29966
30533
|
}
|
|
29967
30534
|
});
|
|
29968
30535
|
this.pending.set(key2, { request, promise });
|
|
@@ -29987,12 +30554,13 @@ var IdeDocuments = class {
|
|
|
29987
30554
|
...creating ? {} : { revision: doc.getItem("revision") }
|
|
29988
30555
|
}, { signal: request.signal }).then((result) => {
|
|
29989
30556
|
if (this.disposed || request.signal.aborted) return false;
|
|
29990
|
-
|
|
29991
|
-
|
|
30557
|
+
const doc2 = this.documents.getItem(key2);
|
|
30558
|
+
doc2.setItem("revision", result.revision);
|
|
30559
|
+
doc2.setItem("saved", content);
|
|
29992
30560
|
return true;
|
|
29993
30561
|
}).finally(() => {
|
|
29994
30562
|
this.pending.delete(key2);
|
|
29995
|
-
if (!this.disposed)
|
|
30563
|
+
if (!this.disposed) this.documents.getItem(key2).setItem("busy", false);
|
|
29996
30564
|
});
|
|
29997
30565
|
this.pending.set(key2, { request, promise });
|
|
29998
30566
|
return promise;
|
|
@@ -30012,6 +30580,8 @@ var IdeDocuments = class {
|
|
|
30012
30580
|
}
|
|
30013
30581
|
close(key2, discard = false) {
|
|
30014
30582
|
if (!this.canClose(key2, discard)) return false;
|
|
30583
|
+
this.#registrations.get(key2)?.close();
|
|
30584
|
+
this.#registrations.delete(key2);
|
|
30015
30585
|
this.documents.popNode(key2);
|
|
30016
30586
|
if (this.state.getItem("active") === key2) this.state.setItem("active", this.documents.getNodes()[0]?.label ?? null);
|
|
30017
30587
|
return true;
|
|
@@ -30019,6 +30589,8 @@ var IdeDocuments = class {
|
|
|
30019
30589
|
dispose() {
|
|
30020
30590
|
this.disposed = true;
|
|
30021
30591
|
for (const { request } of this.pending.values()) request.abort();
|
|
30592
|
+
for (const registration of this.#registrations.values()) registration.close();
|
|
30593
|
+
this.#registrations.clear();
|
|
30022
30594
|
}
|
|
30023
30595
|
};
|
|
30024
30596
|
var RecentWorkspaces = class {
|
|
@@ -30047,7 +30619,7 @@ var RecentWorkspaces = class {
|
|
|
30047
30619
|
// src/ide-runtime.js
|
|
30048
30620
|
function ideContext(node) {
|
|
30049
30621
|
for (let scope = node; scope; scope = scope.parentNode) {
|
|
30050
|
-
const context = scope.ideContext;
|
|
30622
|
+
const context = scope._internal.ideContext;
|
|
30051
30623
|
if (context) return context;
|
|
30052
30624
|
}
|
|
30053
30625
|
throw new Error("IDE operation requires a node inside a mounted IDE");
|
|
@@ -30068,41 +30640,43 @@ var IdeLogic = class {
|
|
|
30068
30640
|
editorPrefix: `ide_${randomId()}`,
|
|
30069
30641
|
recent: new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage)
|
|
30070
30642
|
};
|
|
30071
|
-
|
|
30643
|
+
scope._internal.ideContext = context;
|
|
30072
30644
|
const { documents, recent } = context;
|
|
30073
|
-
const state = scope.getRelativeData(".");
|
|
30645
|
+
const state = () => scope.getRelativeData(".");
|
|
30074
30646
|
const roots = recent.read();
|
|
30075
|
-
state.setItem("recent", recent.choices(roots));
|
|
30076
|
-
state.setItem("workspace", roots[0] ?? "");
|
|
30077
|
-
const
|
|
30078
|
-
|
|
30079
|
-
|
|
30080
|
-
|
|
30081
|
-
|
|
30082
|
-
state.
|
|
30083
|
-
state.setItem("
|
|
30084
|
-
|
|
30647
|
+
state().setItem("recent", recent.choices(roots));
|
|
30648
|
+
state().setItem("workspace", roots[0] ?? "");
|
|
30649
|
+
const router = this.page.src.binding.router;
|
|
30650
|
+
const statePath = scope.absDatapath(".");
|
|
30651
|
+
const documentsPath = `${statePath}.documents`;
|
|
30652
|
+
const registrations2 = [
|
|
30653
|
+
router.register({ path: `${statePath}.browser.root`, recipient: { receive: () => {
|
|
30654
|
+
const root = state().getItem("browser.root");
|
|
30655
|
+
state().setItem("workspace", root);
|
|
30656
|
+
state().setItem("recent", recent.choices(recent.remember(root)));
|
|
30657
|
+
state().setItem("status", `Workspace: ${root}`);
|
|
30658
|
+
} } }),
|
|
30659
|
+
router.register({ path: `${statePath}.browser.selectedPath`, recipient: { receive: () => {
|
|
30660
|
+
const browser = state().getItem("browser");
|
|
30085
30661
|
const path = browser.getItem("selectedPath");
|
|
30086
30662
|
const item = path === null ? null : browser.getItem("store").getNode(path);
|
|
30087
30663
|
if (item && !item.attr.is_directory) void this.ideOpenDocument(scope, browser.getItem("root"), item.attr.path);
|
|
30088
|
-
}
|
|
30089
|
-
|
|
30090
|
-
|
|
30091
|
-
|
|
30092
|
-
|
|
30093
|
-
|
|
30094
|
-
|
|
30095
|
-
|
|
30096
|
-
|
|
30097
|
-
|
|
30098
|
-
|
|
30099
|
-
pane.setAttr({ title: `${documents.dirty(key2) ? "\u25CF " : ""}${doc.getItem("path")}` });
|
|
30664
|
+
} } }),
|
|
30665
|
+
router.register({ path: documentsPath, subtree: true, recipient: { receive: (change) => {
|
|
30666
|
+
if (!["content", "saved", "busy", "writable", "view", "isNew", "path", "root"].includes(change.node.label)) return;
|
|
30667
|
+
for (const pane of scope.value.getNode("frame.center.tabs").value?.getNodes() ?? []) {
|
|
30668
|
+
const key2 = pane.getAttr("documentKey");
|
|
30669
|
+
const doc = documents.documents.getItem(key2);
|
|
30670
|
+
if (doc) {
|
|
30671
|
+
if (change.path === `${documentsPath}.${key2}.content`) documents.invalidateRecipe(key2);
|
|
30672
|
+
this.ideDocumentState(scope, key2);
|
|
30673
|
+
pane.setAttr({ title: `${documents.dirty(key2) ? "\u25CF " : ""}${doc.getItem("path")}` });
|
|
30674
|
+
}
|
|
30100
30675
|
}
|
|
30101
|
-
}
|
|
30102
|
-
|
|
30676
|
+
} } })
|
|
30677
|
+
];
|
|
30103
30678
|
this.page.src.renderer.onDispose(context.scope, () => {
|
|
30104
|
-
|
|
30105
|
-
documentBag.unsubscribe("ide-documents", { any: true });
|
|
30679
|
+
for (const registration of registrations2) registration.close();
|
|
30106
30680
|
documents.dispose();
|
|
30107
30681
|
});
|
|
30108
30682
|
}
|
|
@@ -30116,7 +30690,7 @@ var IdeLogic = class {
|
|
|
30116
30690
|
const context = ideContext(node), state = context.scope.getRelativeData(".");
|
|
30117
30691
|
if (state.getItem("browser.root") !== result.root) return;
|
|
30118
30692
|
state.setItem("upload.open", false);
|
|
30119
|
-
const controller = context.scope.value.getNode("frame.left.browser").fileSystemController;
|
|
30693
|
+
const controller = context.scope.value.getNode("frame.left.browser")._internal.fileSystemController;
|
|
30120
30694
|
if (controller.request) return;
|
|
30121
30695
|
const opened = await controller.open(result.root);
|
|
30122
30696
|
if (opened === result.root && !context.documents.disposed && state.getItem("browser.root") === result.root)
|
|
@@ -30340,7 +30914,7 @@ var IdeLogic = class {
|
|
|
30340
30914
|
if (!documents.disposed && saved) {
|
|
30341
30915
|
state.setItem("status", "File created.");
|
|
30342
30916
|
const browser = state.getItem("browser");
|
|
30343
|
-
if (browser.getItem("root")) await context.scope.value.getNode("frame.left.browser").fileSystemController.open(browser.getItem("root"));
|
|
30917
|
+
if (browser.getItem("root")) await context.scope.value.getNode("frame.left.browser")._internal.fileSystemController.open(browser.getItem("root"));
|
|
30344
30918
|
}
|
|
30345
30919
|
} catch (error) {
|
|
30346
30920
|
if (!documents.disposed) state.setItem("status", error.message);
|
|
@@ -33775,22 +34349,20 @@ var BrowserCameraProvider = class {
|
|
|
33775
34349
|
};
|
|
33776
34350
|
|
|
33777
34351
|
// src/chat.js
|
|
33778
|
-
var projections = /* @__PURE__ */ new WeakMap();
|
|
33779
34352
|
var LABEL = /^m_[a-f0-9]+$/;
|
|
33780
34353
|
function chatRender(page, node, { messages }) {
|
|
33781
34354
|
if (!(messages instanceof Bag) || messages instanceof SourceBag) throw new TypeError("Chat messages require a Data Bag");
|
|
33782
34355
|
const target = node.parentNode;
|
|
33783
34356
|
const viewport = page.dom.getDomNode(target);
|
|
33784
34357
|
if (!viewport) return;
|
|
33785
|
-
let state =
|
|
34358
|
+
let state = target._internal.chatRows;
|
|
33786
34359
|
if (!state) {
|
|
33787
|
-
state = { rows:
|
|
33788
|
-
projections.set(target, state);
|
|
34360
|
+
state = target._internal.chatRows = { rows: {}, active: true };
|
|
33789
34361
|
page.src.renderer.onDispose(target, () => {
|
|
33790
34362
|
state.active = false;
|
|
33791
|
-
for (const label of state.rows
|
|
33792
|
-
state.rows
|
|
33793
|
-
|
|
34363
|
+
for (const label of Object.keys(state.rows)) target.getRelativeData(".messageData").popNode(label);
|
|
34364
|
+
state.rows = {};
|
|
34365
|
+
delete target._internal.chatRows;
|
|
33794
34366
|
});
|
|
33795
34367
|
}
|
|
33796
34368
|
const incoming = messages.getNodes();
|
|
@@ -33802,8 +34374,9 @@ function chatRender(page, node, { messages }) {
|
|
|
33802
34374
|
const follow = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop < 48;
|
|
33803
34375
|
const plans = [];
|
|
33804
34376
|
for (const message of incoming) {
|
|
33805
|
-
const old = state.rows
|
|
33806
|
-
|
|
34377
|
+
const old = state.rows[message.label];
|
|
34378
|
+
const content = typeof message.staticValue === "string" ? message.staticValue : message.staticValue.toTytx();
|
|
34379
|
+
if (old && old.kind === typeof message.staticValue && old.content === content && old.role === message.attr.role && old.author === message.attr.author) continue;
|
|
33807
34380
|
const fragment = new GramlotBuilder();
|
|
33808
34381
|
const article = fragment.root.article({
|
|
33809
34382
|
node_label: message.label,
|
|
@@ -33819,19 +34392,20 @@ function chatRender(page, node, { messages }) {
|
|
|
33819
34392
|
}
|
|
33820
34393
|
const prepared = page.src.prepareSource(fragment.source);
|
|
33821
34394
|
page.src.renderer.validateCandidate(prepared);
|
|
33822
|
-
plans.push({ message, old, child: prepared.getNode(message.label) });
|
|
34395
|
+
plans.push({ message, old, content, child: prepared.getNode(message.label) });
|
|
33823
34396
|
}
|
|
33824
34397
|
const labels = new Set(incoming.map((message) => message.label));
|
|
33825
|
-
for (const
|
|
34398
|
+
for (const label of Object.keys(state.rows)) if (!labels.has(label)) {
|
|
33826
34399
|
target.value.popNode(label);
|
|
33827
34400
|
target.getRelativeData(".messageData").popNode(label);
|
|
33828
|
-
state.rows
|
|
34401
|
+
delete state.rows[label];
|
|
33829
34402
|
}
|
|
33830
|
-
for (const { message, old, child } of plans) {
|
|
34403
|
+
for (const { message, old, content, child } of plans) {
|
|
34404
|
+
const position = old ? "#" + target.value.keys().indexOf(message.label) : ">";
|
|
33831
34405
|
if (old) target.value.popNode(message.label);
|
|
33832
34406
|
if (!old) target.setRelativeData(".messageData." + message.label, new Bag());
|
|
33833
|
-
page.src.builder.setChild(target.value, child.nodeTag, child.value, { ...child.attr, node_label: message.label });
|
|
33834
|
-
state.rows
|
|
34407
|
+
page.src.builder.setChild(target.value, child.nodeTag, child.value, { ...child.attr, node_label: message.label, node_position: position });
|
|
34408
|
+
state.rows[message.label] = { kind: typeof message.staticValue, content, role: message.attr.role, author: message.attr.author };
|
|
33835
34409
|
}
|
|
33836
34410
|
if (follow) queueMicrotask(() => {
|
|
33837
34411
|
if (state.active) viewport.scrollTop = viewport.scrollHeight;
|
|
@@ -33862,13 +34436,13 @@ function chatCompleted(page, node, { response }) {
|
|
|
33862
34436
|
node.SET(".pending", false);
|
|
33863
34437
|
node.SET(".error", response.getItem("error"));
|
|
33864
34438
|
}
|
|
33865
|
-
var
|
|
34439
|
+
var COMPOSER_LAYOUT = /* @__PURE__ */ Symbol("chat composer layout");
|
|
33866
34440
|
function chatResize(page, node) {
|
|
33867
34441
|
const source = node.parentNode;
|
|
33868
|
-
|
|
34442
|
+
const body = page.dom.getDomNode(source);
|
|
34443
|
+
if (!body) return;
|
|
34444
|
+
let layout = body[COMPOSER_LAYOUT];
|
|
33869
34445
|
if (!layout) {
|
|
33870
|
-
const body = page.dom.getDomNode(source);
|
|
33871
|
-
if (!body) return;
|
|
33872
34446
|
const composer = body.closest("[data-chat-composer]");
|
|
33873
34447
|
const editor = body.querySelector("textarea");
|
|
33874
34448
|
const top = composer.querySelector("[data-chat-top]");
|
|
@@ -33896,10 +34470,9 @@ function chatResize(page, node) {
|
|
|
33896
34470
|
active = false;
|
|
33897
34471
|
observer.disconnect();
|
|
33898
34472
|
if (frame) win.cancelAnimationFrame(frame);
|
|
33899
|
-
|
|
34473
|
+
delete body[COMPOSER_LAYOUT];
|
|
33900
34474
|
});
|
|
33901
|
-
layout = { schedule };
|
|
33902
|
-
composerLayouts.set(source, layout);
|
|
34475
|
+
layout = body[COMPOSER_LAYOUT] = { schedule };
|
|
33903
34476
|
}
|
|
33904
34477
|
layout.schedule();
|
|
33905
34478
|
}
|
|
@@ -34003,7 +34576,6 @@ function chatRenderAttachments(page, node, { attachments }) {
|
|
|
34003
34576
|
var VisualEditorCanvas = class {
|
|
34004
34577
|
constructor({ app, editor, design }) {
|
|
34005
34578
|
this.renderer = app.src.renderer;
|
|
34006
|
-
this.design = design;
|
|
34007
34579
|
const presentation = this.renderer.records.get(design).presentation;
|
|
34008
34580
|
this.frame = presentation.ownerDocument.createElement("iframe");
|
|
34009
34581
|
this.frame.title = "Page canvas";
|
|
@@ -34081,7 +34653,8 @@ function parseScalar(type, text3) {
|
|
|
34081
34653
|
// src/source-picker.js
|
|
34082
34654
|
var SourcePicker = class {
|
|
34083
34655
|
#renderer;
|
|
34084
|
-
#
|
|
34656
|
+
#source;
|
|
34657
|
+
#path;
|
|
34085
34658
|
#canvas;
|
|
34086
34659
|
#onSelect;
|
|
34087
34660
|
#observer;
|
|
@@ -34089,11 +34662,15 @@ var SourcePicker = class {
|
|
|
34089
34662
|
#highlighted = null;
|
|
34090
34663
|
#release = null;
|
|
34091
34664
|
#disposed = false;
|
|
34092
|
-
|
|
34665
|
+
/** `source` is the Source root and `path` the address of the preview root in it; the root node is never held. */
|
|
34666
|
+
constructor({ renderer, source, path, onSelect, canvas }) {
|
|
34667
|
+
const root = typeof path === "string" ? source?.getNode(path) : null;
|
|
34093
34668
|
if (!root?.parentNode || typeof onSelect !== "function") throw new TypeError("SourcePicker requires a mounted Source root and onSelect");
|
|
34669
|
+
canvas ??= renderer.records.get(root.parentNode)?.presentation;
|
|
34094
34670
|
if (!canvas || canvas.nodeType !== 1) throw new TypeError("SourcePicker requires a mounted preview");
|
|
34095
34671
|
this.#renderer = renderer;
|
|
34096
|
-
this.#
|
|
34672
|
+
this.#source = source;
|
|
34673
|
+
this.#path = path;
|
|
34097
34674
|
this.#canvas = canvas;
|
|
34098
34675
|
this.#onSelect = onSelect;
|
|
34099
34676
|
canvas.addEventListener("pointerdown", this, true);
|
|
@@ -34102,9 +34679,15 @@ var SourcePicker = class {
|
|
|
34102
34679
|
this.#observer.observe(canvas, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
|
|
34103
34680
|
this.#release = renderer.onDispose(root.parentNode, () => this.dispose());
|
|
34104
34681
|
}
|
|
34682
|
+
/** The preview root node now at the picker's address, or null. */
|
|
34683
|
+
#root() {
|
|
34684
|
+
return this.#source.getNode(this.#path);
|
|
34685
|
+
}
|
|
34105
34686
|
handleEvent(event) {
|
|
34106
34687
|
if (this.#disposed) return;
|
|
34107
|
-
const
|
|
34688
|
+
const root = this.#root();
|
|
34689
|
+
if (!root) return;
|
|
34690
|
+
const prefix = root.fullpath + ".";
|
|
34108
34691
|
const record2 = event.composedPath().map((element) => this.#renderer.elements.get(element)).find((item) => item?.node.fullpath.startsWith(prefix));
|
|
34109
34692
|
if (!record2) return;
|
|
34110
34693
|
const editing = event.composedPath().some((element) => element.nodeType === 1 && (element.matches("input:not([type=button]):not([type=submit]):not([type=reset]):not([type=image]), textarea, select, label") || element.isContentEditable));
|
|
@@ -34118,7 +34701,9 @@ var SourcePicker = class {
|
|
|
34118
34701
|
if (this.#disposed) return;
|
|
34119
34702
|
if (node === null) this.#selectedPath = null;
|
|
34120
34703
|
else {
|
|
34121
|
-
const
|
|
34704
|
+
const root = this.#root();
|
|
34705
|
+
if (!root) throw new TypeError("SourcePicker preview root is missing");
|
|
34706
|
+
const prefix = root.fullpath + ".";
|
|
34122
34707
|
if (!node.fullpath.startsWith(prefix)) throw new TypeError("Selected node must be inside the preview Source root");
|
|
34123
34708
|
this.#selectedPath = node.fullpath.slice(prefix.length);
|
|
34124
34709
|
}
|
|
@@ -34126,7 +34711,7 @@ var SourcePicker = class {
|
|
|
34126
34711
|
}
|
|
34127
34712
|
#paint() {
|
|
34128
34713
|
if (this.#disposed) return;
|
|
34129
|
-
const node = this.#selectedPath ? this.#root
|
|
34714
|
+
const node = this.#selectedPath ? this.#root()?.staticValue.getNode(this.#selectedPath) ?? null : null;
|
|
34130
34715
|
const element = node ? this.#renderer.records.get(node)?.presentation : null;
|
|
34131
34716
|
const next = element?.nodeType === 1 ? element : null;
|
|
34132
34717
|
if (this.#highlighted !== next) {
|
|
@@ -34220,8 +34805,6 @@ var specifications = (node, tag2, current = null) => {
|
|
|
34220
34805
|
...node._getMeta("gramlot_component")?.childParameters ?? {}
|
|
34221
34806
|
};
|
|
34222
34807
|
};
|
|
34223
|
-
var canvasSelections = /* @__PURE__ */ new WeakMap();
|
|
34224
|
-
var canvasDocuments = /* @__PURE__ */ new WeakMap();
|
|
34225
34808
|
var VisualEditorLogic = class {
|
|
34226
34809
|
chatRender(node, params) {
|
|
34227
34810
|
return chatRender(this.page, node, params);
|
|
@@ -34407,37 +34990,44 @@ var VisualEditorLogic = class {
|
|
|
34407
34990
|
node.SET(".sourceSearch", "");
|
|
34408
34991
|
node.SET(".selection", selected);
|
|
34409
34992
|
}
|
|
34993
|
+
// Editor view resources live in the editor node's _internal (GC-225) and reach the design root by its
|
|
34994
|
+
// path; selection itself remains in the Data Bag.
|
|
34410
34995
|
initializeCanvasSelection(node) {
|
|
34411
34996
|
const renderer = node.rootBuilder.binding.renderer;
|
|
34412
|
-
const
|
|
34413
|
-
const editor = visualEditorScope(node), css = editor.GET(".canvasCss");
|
|
34997
|
+
const editor = visualEditorScope(node), css = editor.GET(".canvasCss"), path = sourceRoot(editor);
|
|
34414
34998
|
if (css != null) this.applyCanvasCss(editor, css);
|
|
34415
|
-
const previous =
|
|
34999
|
+
const previous = editor._internal.canvasSelection;
|
|
34416
35000
|
previous?.dispose();
|
|
35001
|
+
const canvas = editor._internal.canvasDocument;
|
|
34417
35002
|
const picker = new SourcePicker({
|
|
34418
35003
|
renderer,
|
|
34419
|
-
|
|
34420
|
-
|
|
35004
|
+
source: editor.builder.source,
|
|
35005
|
+
path,
|
|
35006
|
+
...canvas ? { canvas: canvas.body } : {},
|
|
34421
35007
|
onSelect: (selected) => {
|
|
34422
|
-
|
|
34423
|
-
|
|
35008
|
+
const design = editor.builder.source.getNode(path);
|
|
35009
|
+
editor.SET(".sourceSearch", "");
|
|
35010
|
+
editor.SET(".selection", selected.fullpath.slice(design.fullpath.length + 1));
|
|
34424
35011
|
}
|
|
34425
35012
|
});
|
|
34426
|
-
|
|
34427
|
-
if (!previous) renderer.onDispose(
|
|
34428
|
-
|
|
34429
|
-
|
|
35013
|
+
editor._internal.canvasSelection = picker;
|
|
35014
|
+
if (!previous) renderer.onDispose(editor.builder.source.getNode(path).parentNode, () => {
|
|
35015
|
+
delete editor._internal.canvasSelection;
|
|
35016
|
+
delete editor._internal.canvasDocument;
|
|
34430
35017
|
});
|
|
34431
35018
|
this.highlightSelection(node);
|
|
34432
35019
|
}
|
|
34433
35020
|
applyCanvasCss(node, texts) {
|
|
34434
35021
|
if (!Array.isArray(texts) || texts.some((text3) => typeof text3 !== "string"))
|
|
34435
35022
|
throw new TypeError("canvas CSS must be a list of CSS texts");
|
|
34436
|
-
const editor = visualEditorScope(node)
|
|
34437
|
-
let canvas =
|
|
35023
|
+
const editor = visualEditorScope(node);
|
|
35024
|
+
let canvas = editor._internal.canvasDocument;
|
|
34438
35025
|
if (!canvas) {
|
|
34439
|
-
canvas =
|
|
34440
|
-
|
|
35026
|
+
canvas = editor._internal.canvasDocument = new VisualEditorCanvas({
|
|
35027
|
+
app: editor.rootBuilder.binding.gramlot,
|
|
35028
|
+
editor,
|
|
35029
|
+
design: editor.builder.source.getNode(sourceRoot(editor))
|
|
35030
|
+
});
|
|
34441
35031
|
}
|
|
34442
35032
|
canvas.setCss(texts);
|
|
34443
35033
|
}
|
|
@@ -34450,7 +35040,7 @@ var VisualEditorLogic = class {
|
|
|
34450
35040
|
highlightSelection(node) {
|
|
34451
35041
|
const design = node.builder.source.getNode(sourceRoot(node));
|
|
34452
35042
|
const path = node.GET(".selection");
|
|
34453
|
-
|
|
35043
|
+
visualEditorScope(node)._internal.canvasSelection?.select(path ? design.staticValue.getNode(path) : null);
|
|
34454
35044
|
}
|
|
34455
35045
|
clipboardShortcut(node, event) {
|
|
34456
35046
|
if (event.defaultPrevented || event.repeat || node.GET(".clipboardOpen") || node.GET(".insertionOpen") || node.GET(".uploadOpen")) return;
|
|
@@ -35463,6 +36053,27 @@ var libraries = Object.freeze({
|
|
|
35463
36053
|
integrity: "sha384-IfV0B7MIOYuO95kO9G5ySKPz/85zqFNOAs8iy4tkK5zd9izhJAB8b7lHrwYqqmYE",
|
|
35464
36054
|
format: "style"
|
|
35465
36055
|
}),
|
|
36056
|
+
xterm: Object.freeze({
|
|
36057
|
+
packages: { "@xterm/xterm": "6.0.0" },
|
|
36058
|
+
local: "@xterm/xterm/lib/xterm.mjs",
|
|
36059
|
+
url: jsdelivr("@xterm/xterm", "6.0.0", "lib/xterm.mjs"),
|
|
36060
|
+
integrity: "sha384-8Xik+BkzF4UFDtZa8HkUiQ0FE/Xl+03xMuv69uQB3ichDzm8dWs4kPRihQxSZDiY",
|
|
36061
|
+
format: "module"
|
|
36062
|
+
}),
|
|
36063
|
+
xtermFit: Object.freeze({
|
|
36064
|
+
packages: { "@xterm/addon-fit": "0.11.0" },
|
|
36065
|
+
local: "@xterm/addon-fit/lib/addon-fit.mjs",
|
|
36066
|
+
url: jsdelivr("@xterm/addon-fit", "0.11.0", "lib/addon-fit.mjs"),
|
|
36067
|
+
integrity: "sha384-0/1EW6dUPoaun7dgdlOtb5Wk8x5UQRW6hYM3ihuCCnaA2Xd4HwMFcn378RpxmoAc",
|
|
36068
|
+
format: "module"
|
|
36069
|
+
}),
|
|
36070
|
+
xtermStyle: Object.freeze({
|
|
36071
|
+
packages: { "@xterm/xterm": "6.0.0" },
|
|
36072
|
+
local: "@xterm/xterm/css/xterm.css",
|
|
36073
|
+
url: jsdelivr("@xterm/xterm", "6.0.0", "css/xterm.css"),
|
|
36074
|
+
integrity: "sha384-n2n7twoohnW+d3myBKaUgl7DSiwidw6MkQy9oesGzkPpMjejKRR3XlnD+5yCdtBD",
|
|
36075
|
+
format: "style"
|
|
36076
|
+
}),
|
|
35466
36077
|
plotly: Object.freeze({
|
|
35467
36078
|
packages: { "plotly.js-dist-min": "4.2.0" },
|
|
35468
36079
|
local: "plotly.js-dist-min",
|