@gramlot/gramlot 0.3.36 → 0.3.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +9 -9
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +0 -30
- package/dist/components/drawing/__init__.py +1 -1
- package/dist/components/drawing/assets/collection.js +3 -3
- package/dist/components/drawing/assets/index.js +1 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +6 -6
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +0 -2
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +8 -8
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +2 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +9 -9
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +2 -2
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +6 -6
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +0 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +3 -3
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +0 -3
- package/dist/gramlot.js +1205 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/standard-collections.js +1 -1
- package/package.json +2 -3
- package/src/binding/data-binder.js +11 -3
- package/src/binding/grid-struct.js +7 -4
- package/src/binding/runtime.js +203 -46
- package/src/builder/binding.json +23 -1
- package/src/builder/gramlot-builder.d.ts +1 -4
- package/src/builder/source.js +185 -29
- package/src/chat.js +26 -20
- package/src/components/attachment-manager.js +38 -34
- package/src/components/chart-data-view.js +4 -7
- package/src/components/chart-fields.js +18 -6
- package/src/components/chart-renderer.js +10 -3
- package/src/components/chart-timeline.js +7 -5
- package/src/components/charts.js +74 -67
- package/src/components/check-box-text-editor.js +3 -3
- package/src/components/check-box-text.js +7 -22
- package/src/components/check-box-tree.js +20 -16
- package/src/components/choice-editor.js +1 -1
- package/src/components/drawing.js +47 -34
- package/src/components/grid-cell-editor.js +72 -29
- package/src/components/grid-column-filters.js +47 -40
- package/src/components/grid-formulas.js +22 -17
- package/src/components/grid-header-interaction.js +9 -11
- package/src/components/grid-row-interaction.js +25 -24
- package/src/components/grid-row-layout.js +28 -29
- package/src/components/grid-search-box.js +3 -3
- package/src/components/grid-search.js +3 -8
- package/src/components/grid-selection.js +33 -29
- package/src/components/grid-structure.js +48 -10
- package/src/components/grid-tools.js +14 -14
- package/src/components/grid.js +83 -79
- package/src/components/image-crop-dialog.js +2 -2
- package/src/components/image-crop.js +16 -9
- package/src/components/image-uploader.js +21 -28
- package/src/components/inputs.js +19 -1
- package/src/components/registry.js +3 -5
- package/src/components/tray-pane.js +85 -61
- package/src/components/tree.js +332 -239
- package/src/components/upload-engine.js +10 -2
- package/src/components/uploader.js +31 -27
- package/src/editing-session.d.ts +4 -1
- package/src/editing-session.js +120 -83
- package/src/experiments/window-selection.js +4 -6
- package/src/filesystem.js +2 -2
- package/src/gramlot.js +1 -0
- package/src/handlers/device-handler.js +219 -213
- package/src/handlers/rpc-handler.d.ts +17 -0
- package/src/handlers/rpc-handler.js +22 -0
- package/src/ide-documents.js +29 -11
- package/src/ide-runtime.js +33 -31
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +67 -48
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +6 -1
- package/src/renderer/gramlot-renderer.js +21 -2
- package/src/source-picker.d.ts +2 -2
- package/src/source-picker.js +15 -6
- package/src/stores/bag-collection-store.js +25 -7
- package/src/stores/bag-collection-view.js +23 -22
- package/src/view/controls.js +1 -1
- package/src/view/html.js +40 -20
- package/src/visual-editor-canvas.js +1 -1
- package/src/visual-editor.js +18 -19
- package/tools/gramlot-tools-inspector.js +400 -374
- package/tools/inspector-agent.js +223 -49
- package/dist/components/vizabi/__init__.py +0 -13
- package/dist/components/vizabi/assets/collection.js +0 -4
- package/dist/components/vizabi/assets/index.js +0 -3
- package/dist/components/vizabi/commands.json +0 -7
- package/dist/components/vizabi/grammar.json +0 -128
- package/src/components/vizabi-session.js +0 -66
- package/src/components/vizabi.js +0 -66
package/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
|
|
@@ -16093,10 +16190,15 @@ var PageStoreConnection = class {
|
|
|
16093
16190
|
this.fail(error);
|
|
16094
16191
|
}
|
|
16095
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
|
+
*/
|
|
16096
16197
|
fail(error) {
|
|
16198
|
+
const report = !this.closed;
|
|
16097
16199
|
this.error = error;
|
|
16098
16200
|
this.close();
|
|
16099
|
-
this.
|
|
16201
|
+
if (report) this.gramlot.src.binding.reportError(error, "PageStore channel failed");
|
|
16100
16202
|
}
|
|
16101
16203
|
close() {
|
|
16102
16204
|
if (this.closed) return;
|
|
@@ -16673,7 +16775,7 @@ function annotation2(parameter) {
|
|
|
16673
16775
|
});
|
|
16674
16776
|
return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
|
|
16675
16777
|
}
|
|
16676
|
-
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 }) {
|
|
16677
16779
|
webcomponentCode({ code: tag2 });
|
|
16678
16780
|
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
|
|
16679
16781
|
const effective = { ...base.parameters };
|
|
@@ -16697,8 +16799,6 @@ function defineComponent({ name, tag: tag2, base, doc = null, mixins = [], param
|
|
|
16697
16799
|
presentationDefaults: Object.freeze([...presentationDefaults]),
|
|
16698
16800
|
dataScope,
|
|
16699
16801
|
command,
|
|
16700
|
-
bagStore,
|
|
16701
|
-
bagStruct,
|
|
16702
16802
|
mixins: Object.freeze([...mixins]),
|
|
16703
16803
|
labelbox: mixins.some((mixin) => mixin.labelbox === true),
|
|
16704
16804
|
parameters: freeze(structuredClone(effective)),
|
|
@@ -16778,9 +16878,7 @@ var ComponentCollection = class _ComponentCollection {
|
|
|
16778
16878
|
...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
|
|
16779
16879
|
...component.sourceContext ? { sourceContext: true } : {},
|
|
16780
16880
|
...component.labelbox ? { labelbox: true } : {},
|
|
16781
|
-
...component.dragSource ? { dragSource: true } : {}
|
|
16782
|
-
...component.bagStore ? { bagStore: true } : {},
|
|
16783
|
-
...component.bagStruct ? { bagStruct: true } : {}
|
|
16881
|
+
...component.dragSource ? { dragSource: true } : {}
|
|
16784
16882
|
} }
|
|
16785
16883
|
}]))
|
|
16786
16884
|
};
|
|
@@ -18645,19 +18743,27 @@ var EditingSession = class {
|
|
|
18645
18743
|
this.path = path;
|
|
18646
18744
|
this.subscription = this.runtime.router.register({ path, recipient: this, subtree: true });
|
|
18647
18745
|
this.updateChanges();
|
|
18648
|
-
for (const adapter of this.fields
|
|
18746
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
18747
|
+
const node = this.fieldNode(fullpath);
|
|
18649
18748
|
adapter.element.cancelValidation();
|
|
18650
|
-
this.clearDraft(
|
|
18749
|
+
this.clearDraft(node);
|
|
18651
18750
|
this.scheduleValidation(adapter);
|
|
18652
18751
|
}
|
|
18653
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
|
+
}
|
|
18654
18760
|
get data() {
|
|
18655
18761
|
return this.runtime.gramlot.data.getItem(this.path);
|
|
18656
18762
|
}
|
|
18657
18763
|
/**
|
|
18658
18764
|
* Declare derived values (grid formula results, published totals): `match(path)` receives a path
|
|
18659
18765
|
* relative to the session, `<path>?<attribute>` for an attribute. Derived values are never changes.
|
|
18660
|
-
* Returns the release.
|
|
18766
|
+
* Returns the release. An attribute whose name starts with `_dv_` is derived without registration (GC-225).
|
|
18661
18767
|
*/
|
|
18662
18768
|
registerDerived(match) {
|
|
18663
18769
|
this.derived.add(match);
|
|
@@ -18667,6 +18773,8 @@ var EditingSession = class {
|
|
|
18667
18773
|
};
|
|
18668
18774
|
}
|
|
18669
18775
|
isDerived(path) {
|
|
18776
|
+
const separator = path.indexOf("?");
|
|
18777
|
+
if (separator !== -1 && path.startsWith("_dv_", separator + 1)) return true;
|
|
18670
18778
|
for (const match of this.derived) if (match(path)) return true;
|
|
18671
18779
|
return false;
|
|
18672
18780
|
}
|
|
@@ -18722,8 +18830,8 @@ var EditingSession = class {
|
|
|
18722
18830
|
}
|
|
18723
18831
|
focusField(path) {
|
|
18724
18832
|
if (this.disposed) return false;
|
|
18725
|
-
for (const adapter of this.fields
|
|
18726
|
-
if (fieldPath(
|
|
18833
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
18834
|
+
if (fieldPath(this.fieldNode(fullpath)) === path && adapter.element.isConnected) {
|
|
18727
18835
|
adapter.element.control.focus();
|
|
18728
18836
|
return true;
|
|
18729
18837
|
}
|
|
@@ -18770,15 +18878,16 @@ var EditingSession = class {
|
|
|
18770
18878
|
};
|
|
18771
18879
|
}
|
|
18772
18880
|
register(adapter) {
|
|
18773
|
-
const
|
|
18774
|
-
this.fields.set(
|
|
18775
|
-
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);
|
|
18776
18884
|
field.selection = adapter.element.validationSelection();
|
|
18777
18885
|
this.schedule(() => {
|
|
18778
|
-
if (this.fields.get(
|
|
18886
|
+
if (this.fields.get(fullpath) !== adapter) return;
|
|
18887
|
+
const node = this.fieldNode(fullpath);
|
|
18779
18888
|
const draft = this.registers.getItem("drafts").getNode(key(node));
|
|
18780
18889
|
if (draft) {
|
|
18781
|
-
node.formDraft = draft.value;
|
|
18890
|
+
node._internal.formDraft = draft.value;
|
|
18782
18891
|
adapter.element.restoreFormDraft(draft.value);
|
|
18783
18892
|
}
|
|
18784
18893
|
if (field.result) adapter.element.presentValidation(field.result);
|
|
@@ -18787,33 +18896,30 @@ var EditingSession = class {
|
|
|
18787
18896
|
adapter.element.setFieldState({ invalid: Boolean(errors), pending: Boolean(this.fieldStatus(field.path).pending) });
|
|
18788
18897
|
});
|
|
18789
18898
|
return () => {
|
|
18790
|
-
this.fields.delete(
|
|
18899
|
+
this.fields.delete(fullpath);
|
|
18791
18900
|
};
|
|
18792
18901
|
}
|
|
18793
18902
|
/** A real Source declaration can validate without an element or ControlAdapter. */
|
|
18794
18903
|
registerField(node, component, schedule = true) {
|
|
18795
|
-
|
|
18904
|
+
const fullpath = node.fullpath;
|
|
18905
|
+
let field = this.validations.get(fullpath);
|
|
18796
18906
|
if (field) return field;
|
|
18797
18907
|
if (!component.validationExecutor) throw new TypeError("Grid editors require shared input validation.");
|
|
18798
|
-
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;
|
|
18799
18911
|
field = {
|
|
18800
|
-
node,
|
|
18801
|
-
binding,
|
|
18802
|
-
context,
|
|
18803
18912
|
component,
|
|
18804
18913
|
run: new ValidationRun(),
|
|
18805
|
-
execute: component.validationExecutor,
|
|
18806
|
-
checkValue: component.validationValueCheck(context),
|
|
18807
18914
|
path: fieldPath(node),
|
|
18808
18915
|
rules: null,
|
|
18809
18916
|
value: void 0,
|
|
18810
|
-
target: null,
|
|
18811
18917
|
result: null,
|
|
18812
18918
|
selection: null
|
|
18813
18919
|
};
|
|
18814
|
-
this.validations.set(
|
|
18920
|
+
this.validations.set(fullpath, field);
|
|
18815
18921
|
binding.editingSession = this;
|
|
18816
|
-
|
|
18922
|
+
binding.track(() => this.forgetField(fullpath));
|
|
18817
18923
|
this.refreshField(node, schedule);
|
|
18818
18924
|
return field;
|
|
18819
18925
|
}
|
|
@@ -18827,7 +18933,11 @@ var EditingSession = class {
|
|
|
18827
18933
|
}
|
|
18828
18934
|
invalidateValidation() {
|
|
18829
18935
|
this.validationRevision++;
|
|
18830
|
-
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));
|
|
18831
18941
|
}
|
|
18832
18942
|
trackValidationDependency(absolute) {
|
|
18833
18943
|
if (absolute === null || this.validationDependencies.has(absolute)) return;
|
|
@@ -18847,31 +18957,31 @@ var EditingSession = class {
|
|
|
18847
18957
|
validate() {
|
|
18848
18958
|
if (this.disposed) return Promise.resolve(false);
|
|
18849
18959
|
if (this.fullValidation) return this.fullValidation.promise;
|
|
18850
|
-
for (const adapter of this.fields
|
|
18960
|
+
for (const [fullpath, adapter] of this.fields) if (Object.hasOwn(this.fieldNode(fullpath)._internal, "formDraft")) adapter.commit();
|
|
18851
18961
|
this.clearValidationDependencies();
|
|
18852
18962
|
const pass = { revision: this.validationRevision, promise: null, active: /* @__PURE__ */ new Set(), failed: false, complete: true };
|
|
18853
18963
|
this.fullValidation = pass;
|
|
18854
18964
|
this.notify();
|
|
18855
18965
|
const fields = this.validationFields();
|
|
18856
18966
|
const current = () => !this.disposed && !pass.failed && pass.revision === this.validationRevision;
|
|
18857
|
-
const seen = /* @__PURE__ */ new
|
|
18967
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18858
18968
|
const worker = async () => {
|
|
18859
18969
|
let count = 0;
|
|
18860
18970
|
while (current()) {
|
|
18861
18971
|
const next = fields.next();
|
|
18862
18972
|
if (next.done) return;
|
|
18863
|
-
const { node, release } = next.value;
|
|
18973
|
+
const { node, release } = next.value, fullpath = node.fullpath;
|
|
18864
18974
|
try {
|
|
18865
|
-
if (seen.has(
|
|
18866
|
-
seen.add(
|
|
18975
|
+
if (seen.has(fullpath)) continue;
|
|
18976
|
+
seen.add(fullpath);
|
|
18867
18977
|
for (const [name, pointer] of node.pointers()) if (name !== "value") {
|
|
18868
18978
|
this.trackValidationDependency((name === "datapath" ? node.parentNode : node).absDatapath(pointer));
|
|
18869
18979
|
}
|
|
18870
|
-
pass.active.add(
|
|
18980
|
+
pass.active.add(fullpath);
|
|
18871
18981
|
const outcome = await this.validateField(node);
|
|
18872
18982
|
if (!outcome?.ok) pass.complete = false;
|
|
18873
18983
|
} finally {
|
|
18874
|
-
pass.active.delete(
|
|
18984
|
+
pass.active.delete(fullpath);
|
|
18875
18985
|
release();
|
|
18876
18986
|
}
|
|
18877
18987
|
if (++count % 20 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -18880,7 +18990,7 @@ var EditingSession = class {
|
|
|
18880
18990
|
pass.promise = Promise.resolve().then(async () => {
|
|
18881
18991
|
const outcomes = await Promise.allSettled(Array.from({ length: 8 }, () => worker().catch((error) => {
|
|
18882
18992
|
pass.failed = true;
|
|
18883
|
-
|
|
18993
|
+
this.cancelActive(pass);
|
|
18884
18994
|
throw error;
|
|
18885
18995
|
})));
|
|
18886
18996
|
const failure2 = outcomes.find((outcome) => outcome.status === "rejected");
|
|
@@ -18899,21 +19009,23 @@ var EditingSession = class {
|
|
|
18899
19009
|
*validationFields() {
|
|
18900
19010
|
const existing = [...this.validations.keys()];
|
|
18901
19011
|
for (const fields of this.validationSources) yield* fields();
|
|
18902
|
-
for (const
|
|
19012
|
+
for (const fullpath of existing) if (this.validations.has(fullpath)) yield { node: this.fieldNode(fullpath), release: () => {
|
|
18903
19013
|
} };
|
|
18904
19014
|
}
|
|
18905
|
-
|
|
18906
|
-
|
|
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);
|
|
18907
19021
|
if (!field) return;
|
|
18908
19022
|
field.run.cancel();
|
|
18909
|
-
|
|
18910
|
-
|
|
18911
|
-
this.validations.delete(node);
|
|
18912
|
-
this.validationQueue.delete(node);
|
|
19023
|
+
this.validations.delete(fullpath);
|
|
19024
|
+
this.validationQueue.delete(fullpath);
|
|
18913
19025
|
for (const name of ["errors", "pending"]) {
|
|
18914
19026
|
const parts2 = this.registers.getItem(name).getItem(encoded(field.path));
|
|
18915
19027
|
if (parts2) {
|
|
18916
|
-
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);
|
|
18917
19029
|
if (!parts2.length) this.registers.getItem(name).popNode(encoded(field.path));
|
|
18918
19030
|
}
|
|
18919
19031
|
}
|
|
@@ -18921,19 +19033,22 @@ var EditingSession = class {
|
|
|
18921
19033
|
const drafts = this.registers.getItem("drafts");
|
|
18922
19034
|
if (drafts.getNode(encoded(field.path))) drafts.popNode(encoded(field.path));
|
|
18923
19035
|
}
|
|
18924
|
-
delete node.formDraft;
|
|
18925
19036
|
this.notify();
|
|
18926
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
|
+
}
|
|
18927
19043
|
refreshField(node, schedule = true) {
|
|
18928
|
-
const field = this.validations.get(node);
|
|
19044
|
+
const field = this.validations.get(node.fullpath);
|
|
18929
19045
|
if (!field || this.disposed || this.writing) return;
|
|
18930
|
-
const
|
|
18931
|
-
const resolved2 = field.component.validationParameters(this.runtime.renderer.evaluateExpressions(node, attrs));
|
|
19046
|
+
const resolved2 = this.validationParameters(node, field.component);
|
|
18932
19047
|
const rules = Object.fromEntries(Object.entries(resolved2).filter(([name]) => name.startsWith("validate_")));
|
|
18933
19048
|
const configuration = toTytx(Object.fromEntries(Object.entries(resolved2).filter(([name]) => name !== "value")));
|
|
18934
|
-
const path = fieldPath(node)
|
|
19049
|
+
const path = fieldPath(node);
|
|
18935
19050
|
const value = node.getRelativeData(node.getAttr("value"));
|
|
18936
|
-
const dataChanged = field.path !== path ||
|
|
19051
|
+
const dataChanged = field.path !== path || !same(field.value, value);
|
|
18937
19052
|
if (!dataChanged && field.configuration === configuration) return;
|
|
18938
19053
|
if (field.rules !== null) this.invalidateValidation();
|
|
18939
19054
|
this.cancelValidation(node);
|
|
@@ -18943,21 +19058,13 @@ var EditingSession = class {
|
|
|
18943
19058
|
if (bag.getNode(encoded(field.path))) bag.popNode(encoded(field.path));
|
|
18944
19059
|
}
|
|
18945
19060
|
}
|
|
18946
|
-
Object.assign(field, {
|
|
18947
|
-
path,
|
|
18948
|
-
target,
|
|
18949
|
-
value,
|
|
18950
|
-
rules,
|
|
18951
|
-
configuration,
|
|
18952
|
-
result: null,
|
|
18953
|
-
selection: field.component.validationSelection(resolved2, field.context)
|
|
18954
|
-
});
|
|
19061
|
+
Object.assign(field, { path, value, rules, configuration, result: null, selection: null });
|
|
18955
19062
|
if (dataChanged) this.clearDraft(node);
|
|
18956
19063
|
if (schedule) this.scheduleField(node);
|
|
18957
19064
|
}
|
|
18958
19065
|
cancelValidation(node) {
|
|
18959
|
-
this.validations.get(node)?.run.cancel();
|
|
18960
|
-
this.validationQueue.delete(node);
|
|
19066
|
+
this.validations.get(node.fullpath)?.run.cancel();
|
|
19067
|
+
this.validationQueue.delete(node.fullpath);
|
|
18961
19068
|
this.pendingPart(node, "validation", null);
|
|
18962
19069
|
}
|
|
18963
19070
|
writeCandidate(node, value) {
|
|
@@ -18968,69 +19075,74 @@ var EditingSession = class {
|
|
|
18968
19075
|
} finally {
|
|
18969
19076
|
this.writing--;
|
|
18970
19077
|
}
|
|
18971
|
-
const field = this.validations.get(node);
|
|
19078
|
+
const field = this.validations.get(node.fullpath);
|
|
18972
19079
|
if (field) {
|
|
18973
19080
|
field.value = node.getRelativeData(node.getAttr("value"));
|
|
18974
|
-
field.target = this.runtime.gramlot.data.getNode(field.path.split("?")[0]);
|
|
18975
19081
|
}
|
|
18976
|
-
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));
|
|
18977
19083
|
}
|
|
18978
19084
|
validateCandidate(node, value, selection) {
|
|
18979
19085
|
this.invalidateValidation();
|
|
18980
19086
|
this.cancelValidation(node);
|
|
18981
19087
|
this.writeCandidate(node, value);
|
|
18982
|
-
const field = this.validations.get(node);
|
|
19088
|
+
const field = this.validations.get(node.fullpath);
|
|
18983
19089
|
field.selection = selection;
|
|
18984
19090
|
return this.validateField(node, false);
|
|
18985
19091
|
}
|
|
18986
19092
|
scheduleField(node) {
|
|
18987
|
-
|
|
19093
|
+
const fullpath = node.fullpath;
|
|
19094
|
+
if (this.disposed || !this.validations.has(fullpath) || this.validationQueue.has(fullpath)) return;
|
|
18988
19095
|
if (this.registers.getItem("drafts").getNode(key(node))) return;
|
|
18989
|
-
this.validationQueue.add(
|
|
19096
|
+
this.validationQueue.add(fullpath);
|
|
18990
19097
|
this.pendingPart(node, "validation", "scheduled");
|
|
18991
19098
|
this.schedule(() => {
|
|
18992
|
-
if (this.validationQueue.delete(
|
|
19099
|
+
if (this.validationQueue.delete(fullpath)) this.validateField(this.fieldNode(fullpath));
|
|
18993
19100
|
});
|
|
18994
19101
|
}
|
|
18995
19102
|
scheduleValidation(adapter) {
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
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);
|
|
18999
19107
|
}
|
|
19000
19108
|
validateField(node, refreshSelection = true) {
|
|
19001
|
-
const field = this.validations.get(
|
|
19002
|
-
|
|
19003
|
-
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);
|
|
19004
19113
|
if (this.registers.getItem("drafts").getNode(key(node))) return;
|
|
19005
19114
|
if (this.registers.getItem("pending").getItem(key(node))?.getItem(contribution(node, "selection"))) return;
|
|
19006
19115
|
const value = node.getRelativeData(node.getAttr("value"));
|
|
19007
|
-
const adapter = this.fields.get(
|
|
19116
|
+
const adapter = this.fields.get(fullpath);
|
|
19008
19117
|
if (refreshSelection && adapter) field.selection = adapter.element.validationSelection();
|
|
19009
|
-
const
|
|
19010
|
-
const
|
|
19011
|
-
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();
|
|
19012
19123
|
return field.run.start(value, field.rules, {
|
|
19013
|
-
...
|
|
19014
|
-
validationCurrent: () => () => !this.disposed && current() && this.validations.get(
|
|
19124
|
+
...context,
|
|
19125
|
+
validationCurrent: () => () => !this.disposed && current() && this.validations.get(fullpath) === field && field.path === path,
|
|
19015
19126
|
selection
|
|
19016
|
-
},
|
|
19127
|
+
}, component.validationExecutor, (outcome) => {
|
|
19128
|
+
const node2 = this.fieldNode(fullpath);
|
|
19017
19129
|
if (outcome.ok) {
|
|
19018
19130
|
try {
|
|
19019
|
-
|
|
19131
|
+
checkValue(outcome.value, value);
|
|
19020
19132
|
} catch (error) {
|
|
19021
19133
|
outcome.ok = false;
|
|
19022
19134
|
outcome.result.error = error.message;
|
|
19023
19135
|
}
|
|
19024
19136
|
}
|
|
19025
|
-
this.result(
|
|
19137
|
+
this.result(node2, outcome.result);
|
|
19026
19138
|
field.result = outcome.result;
|
|
19027
|
-
if (outcome.ok) this.writeCandidate(
|
|
19028
|
-
const mounted = this.fields.get(
|
|
19139
|
+
if (outcome.ok) this.writeCandidate(node2, outcome.value);
|
|
19140
|
+
const mounted = this.fields.get(fullpath);
|
|
19029
19141
|
if (mounted) mounted.element.presentValidation(outcome.result);
|
|
19030
|
-
|
|
19142
|
+
context.finishValidation(outcome);
|
|
19031
19143
|
}, () => {
|
|
19032
|
-
this.pendingPart(
|
|
19033
|
-
this.fields.get(
|
|
19144
|
+
this.pendingPart(this.fieldNode(fullpath), "validation", "active");
|
|
19145
|
+
this.fields.get(fullpath)?.element.setFieldState({ pending: true });
|
|
19034
19146
|
});
|
|
19035
19147
|
}
|
|
19036
19148
|
remove(name, node) {
|
|
@@ -19045,11 +19157,11 @@ var EditingSession = class {
|
|
|
19045
19157
|
draft(node, text3) {
|
|
19046
19158
|
this.invalidateValidation();
|
|
19047
19159
|
this.cancelValidation(node);
|
|
19048
|
-
node.formDraft = text3;
|
|
19160
|
+
node._internal.formDraft = text3;
|
|
19049
19161
|
this.set("drafts", node, text3);
|
|
19050
19162
|
}
|
|
19051
19163
|
clearDraft(node) {
|
|
19052
|
-
delete node.formDraft;
|
|
19164
|
+
delete node._internal.formDraft;
|
|
19053
19165
|
this.set("drafts", node, null);
|
|
19054
19166
|
this.issue(node, "parse", null);
|
|
19055
19167
|
}
|
|
@@ -19092,7 +19204,7 @@ var EditingSession = class {
|
|
|
19092
19204
|
this.updateChanges(change.path);
|
|
19093
19205
|
if (this.writing) return;
|
|
19094
19206
|
this.invalidateValidation();
|
|
19095
|
-
for (const
|
|
19207
|
+
for (const fullpath of this.validations.keys()) this.refreshField(this.fieldNode(fullpath));
|
|
19096
19208
|
}
|
|
19097
19209
|
updateChanges(changedPath = null) {
|
|
19098
19210
|
const changes = this.registers.getItem("changes");
|
|
@@ -19150,15 +19262,16 @@ var EditingSession = class {
|
|
|
19150
19262
|
});
|
|
19151
19263
|
}
|
|
19152
19264
|
commitField(path) {
|
|
19153
|
-
for (const adapter of this.fields
|
|
19154
|
-
|
|
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();
|
|
19155
19268
|
}
|
|
19156
19269
|
}
|
|
19157
19270
|
/** Flush active drafts. Refuse errors/pending checks; accept only a valid local snapshot. */
|
|
19158
19271
|
accept() {
|
|
19159
19272
|
if (this.disposed) return false;
|
|
19160
|
-
for (const adapter of this.fields
|
|
19161
|
-
if (Object.hasOwn(
|
|
19273
|
+
for (const [fullpath, adapter] of this.fields) {
|
|
19274
|
+
if (Object.hasOwn(this.fieldNode(fullpath)._internal, "formDraft")) adapter.commit();
|
|
19162
19275
|
}
|
|
19163
19276
|
if (!this.status.valid || this.status.pending) return false;
|
|
19164
19277
|
if (this.validationSources.size && this.validatedRevision !== this.validationRevision) return false;
|
|
@@ -19175,24 +19288,25 @@ var EditingSession = class {
|
|
|
19175
19288
|
restore() {
|
|
19176
19289
|
if (this.disposed) return;
|
|
19177
19290
|
this.invalidateValidation();
|
|
19178
|
-
for (const
|
|
19179
|
-
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);
|
|
19180
19294
|
adapter.element.cancelValidation();
|
|
19181
|
-
this.clearDraft(
|
|
19295
|
+
this.clearDraft(node);
|
|
19182
19296
|
adapter.element.restoreFormValue(this.registers.getItem("baseline").getItem(
|
|
19183
|
-
|
|
19297
|
+
node.absDatapath(node.getAttr("value")).slice(this.path ? this.path.length + 1 : 0)
|
|
19184
19298
|
));
|
|
19185
19299
|
}
|
|
19186
19300
|
this.runtime.gramlot.data.setItem(this.path, copy(this.registers.getItem("baseline")));
|
|
19187
19301
|
for (const name of ["errors", "pending", "drafts"]) this.registers.setItem(name, new Bag());
|
|
19188
19302
|
this.updateChanges();
|
|
19189
|
-
for (const
|
|
19303
|
+
for (const fullpath of this.validations.keys()) this.scheduleField(this.fieldNode(fullpath));
|
|
19190
19304
|
}
|
|
19191
19305
|
dispose() {
|
|
19192
19306
|
if (this.disposed) return;
|
|
19193
19307
|
this.disposed = true;
|
|
19194
19308
|
this.subscription.close();
|
|
19195
|
-
for (const
|
|
19309
|
+
for (const fullpath of this.validations.keys()) this.forgetField(fullpath);
|
|
19196
19310
|
this.fields.clear();
|
|
19197
19311
|
this.validationQueue.clear();
|
|
19198
19312
|
this.retainedFields.clear();
|
|
@@ -19399,29 +19513,39 @@ function structFormulaCode(grid) {
|
|
|
19399
19513
|
if (grid.staticValue instanceof SourceBag) visit(grid.staticValue);
|
|
19400
19514
|
return items;
|
|
19401
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
|
+
}
|
|
19402
19533
|
var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
19403
19534
|
#formState = null;
|
|
19404
|
-
#
|
|
19405
|
-
/**
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
|
|
19413
|
-
this.#treeStore = bag;
|
|
19414
|
-
const runtime = this.rootBuilder.binding;
|
|
19415
|
-
const binding = runtime?.bindingFor(this);
|
|
19416
|
-
if (binding && !binding.closed) {
|
|
19417
|
-
binding.rebind();
|
|
19418
|
-
if (runtime.renderer.attached(this)) runtime.renderer.project(this);
|
|
19419
|
-
}
|
|
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 ??= {};
|
|
19420
19544
|
}
|
|
19421
19545
|
/** The local form lifecycle owned by the nearest marked Source ancestor. */
|
|
19422
19546
|
get formState() {
|
|
19423
19547
|
for (let owner = this; owner; owner = owner.parentNode) {
|
|
19424
|
-
if (owner.#formState && owner._getMeta("gramlot_component")?.
|
|
19548
|
+
if (owner.#formState && owner._getMeta("gramlot_component")?.parameters?.storepath) return owner.#formState;
|
|
19425
19549
|
if (owner.getAttr("formId") != null || owner.getAttr("form") === true) {
|
|
19426
19550
|
const state = owner.#formState ??= new EditingSession(owner, this.rootBuilder.binding);
|
|
19427
19551
|
state.rebind();
|
|
@@ -19534,7 +19658,7 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19534
19658
|
}
|
|
19535
19659
|
}
|
|
19536
19660
|
if (isExpression2(this.staticValue) || this.nodeTag === "script" && typeof this.staticValue === "string") items.push(["", this.staticValue]);
|
|
19537
|
-
if (this._getMeta("gramlot_component")?.
|
|
19661
|
+
if (this._getMeta("gramlot_component")?.parameters?.structpath) items.push(...structFormulaCode(this));
|
|
19538
19662
|
return items;
|
|
19539
19663
|
}
|
|
19540
19664
|
/**
|
|
@@ -19708,10 +19832,16 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19708
19832
|
release?.();
|
|
19709
19833
|
};
|
|
19710
19834
|
}
|
|
19711
|
-
/**
|
|
19712
|
-
|
|
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 } = {}) {
|
|
19713
19841
|
path = pointerTransform(path)?.pointer ?? path;
|
|
19714
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);
|
|
19715
19845
|
if (bare.startsWith("#") && bare.includes("?")) {
|
|
19716
19846
|
const [target, attr] = bare.split("?", 2);
|
|
19717
19847
|
const resolved2 = super.absDatapath(target);
|
|
@@ -19747,16 +19877,142 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
19747
19877
|
_finalizeAbsPath(path, attr) {
|
|
19748
19878
|
return path === null ? null : super._finalizeAbsPath(path, attr);
|
|
19749
19879
|
}
|
|
19750
|
-
/**
|
|
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
|
+
*/
|
|
19751
19885
|
_resolveSymbolicDatapath(path, raw) {
|
|
19752
|
-
const
|
|
19753
|
-
|
|
19754
|
-
const
|
|
19755
|
-
|
|
19756
|
-
|
|
19757
|
-
if (
|
|
19758
|
-
|
|
19759
|
-
|
|
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);
|
|
19760
20016
|
}
|
|
19761
20017
|
/**
|
|
19762
20018
|
* The datapath read from Data for a pointer datapath, or null when empty. The pointer is read in
|
|
@@ -20061,7 +20317,7 @@ var binding_default = {
|
|
|
20061
20317
|
abstracts: {},
|
|
20062
20318
|
elements: {
|
|
20063
20319
|
dataBinder: {
|
|
20064
|
-
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.",
|
|
20065
20321
|
sub_tags: "",
|
|
20066
20322
|
parent_tags: null,
|
|
20067
20323
|
inherits_from: null,
|
|
@@ -20090,6 +20346,28 @@ var binding_default = {
|
|
|
20090
20346
|
},
|
|
20091
20347
|
has_default: false
|
|
20092
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
|
+
},
|
|
20093
20371
|
{
|
|
20094
20372
|
name: "attr",
|
|
20095
20373
|
kind: "var_keyword",
|
|
@@ -21613,7 +21891,7 @@ function componentContext(adapter) {
|
|
|
21613
21891
|
if (binding.closed) return;
|
|
21614
21892
|
const pointer = node.getAttr("value");
|
|
21615
21893
|
if (node.pointerType(pointer) !== "^" || pointer.includes("?") || !Object.is(node.getRelativeData(pointer), value)) return;
|
|
21616
|
-
const path = pointer.slice(1) + "?
|
|
21894
|
+
const path = pointer.slice(1) + "?_dv_displayedValue";
|
|
21617
21895
|
if (node.getRelativeData(path) !== caption) node.setRelativeData(path, caption);
|
|
21618
21896
|
},
|
|
21619
21897
|
periodOutput: (path, value) => node.setRelativeData(path, value),
|
|
@@ -21771,7 +22049,7 @@ var HtmlElement = class {
|
|
|
21771
22049
|
frameRecipient: () => frameRecipient(commandFrame(node)),
|
|
21772
22050
|
locale: node.rootBuilder.binding.gramlot.locale,
|
|
21773
22051
|
timeZone: node.rootBuilder.binding.gramlot.timeZone,
|
|
21774
|
-
collectionView: (
|
|
22052
|
+
collectionView: (path, rowMode) => node.rootBuilder.binding.collectionView(node, path, rowMode),
|
|
21775
22053
|
format: this.format,
|
|
21776
22054
|
upload: () => this.uploadContext(),
|
|
21777
22055
|
terminalUrl: (session) => {
|
|
@@ -21781,7 +22059,14 @@ var HtmlElement = class {
|
|
|
21781
22059
|
},
|
|
21782
22060
|
reportError: (error, title) => this.reportError(node, error, title),
|
|
21783
22061
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
21784
|
-
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),
|
|
21785
22070
|
callLogic: (name, keywords) => this.callLogic(node, name, keywords)
|
|
21786
22071
|
});
|
|
21787
22072
|
}
|
|
@@ -21818,12 +22103,36 @@ var HtmlElement = class {
|
|
|
21818
22103
|
* pointer writes; a literal, a `=` pointer and a pointer with a suffix write nothing (no inverse
|
|
21819
22104
|
* conversion, 11.81). A value equal (`Object.is`) to the Data value is not written, as the legacy
|
|
21820
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.
|
|
21821
22107
|
*/
|
|
21822
|
-
writeParameter(node, name, value) {
|
|
22108
|
+
writeParameter(node, name, value, attributes = null) {
|
|
21823
22109
|
const pointer = node.getAttr(name);
|
|
21824
22110
|
if (node.pointerType(pointer) === "^" && !pointerTransform(pointer) && !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
|
|
21825
|
-
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`);
|
|
21826
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);
|
|
21827
22136
|
}
|
|
21828
22137
|
compose(record2, text3, children) {
|
|
21829
22138
|
record2.text.data = text3 ?? "";
|
|
@@ -21876,22 +22185,7 @@ var HtmlElement = class {
|
|
|
21876
22185
|
projectLabelbox(record2.labelbox, { ...defaults, ...attrs }, adapt);
|
|
21877
22186
|
}
|
|
21878
22187
|
if (this.definition(node).meta.gramlot_component) {
|
|
21879
|
-
|
|
21880
|
-
if (node.nodeTag === "tree") element.setStoreBag(node.rootBuilder.binding.treeStore(node));
|
|
21881
|
-
else {
|
|
21882
|
-
const path = node.absDatapath(node.getAttr("storepath"));
|
|
21883
|
-
if (!change || change.path === path || change.path.startsWith(`${path}.`) || path.startsWith(`${change.path}.`)) {
|
|
21884
|
-
element.setStoreBag(node.getRelativeData(node.getAttr("storepath")));
|
|
21885
|
-
}
|
|
21886
|
-
}
|
|
21887
|
-
}
|
|
21888
|
-
if (this.definition(node).meta.gramlot_component.bagStruct) {
|
|
21889
|
-
const path = node.absDatapath(node.getAttr("structpath"));
|
|
21890
|
-
if (!change || change.path === path || change.path.startsWith(`${path}.`) || path.startsWith(`${change.path}.`)) {
|
|
21891
|
-
element.setStructBag(node.getRelativeData(node.getAttr("structpath")));
|
|
21892
|
-
}
|
|
21893
|
-
}
|
|
21894
|
-
attrs = element.projectAttributes(attrs, adapt);
|
|
22188
|
+
attrs = element.projectAttributes(attrs, adapt, change?.path ?? null);
|
|
21895
22189
|
}
|
|
21896
22190
|
if (record2.labelbox) {
|
|
21897
22191
|
attrs = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== "lbl" && !name.startsWith("lbl_") && !name.startsWith("box_")));
|
|
@@ -23193,16 +23487,32 @@ function requireId(id) {
|
|
|
23193
23487
|
var bag_collection_store_exports = {};
|
|
23194
23488
|
__export(bag_collection_store_exports, {
|
|
23195
23489
|
BagCollectionStore: () => BagCollectionStore,
|
|
23490
|
+
collectionKey: () => collectionKey,
|
|
23196
23491
|
publishCollection: () => publishCollection
|
|
23197
23492
|
});
|
|
23198
23493
|
var BagCollectionStore = class {
|
|
23199
23494
|
#listeners = /* @__PURE__ */ new Set();
|
|
23200
|
-
|
|
23201
|
-
|
|
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}`);
|
|
23202
23501
|
if (!["values", "attributes"].includes(rowMode)) throw new TypeError("collection store rowMode must explicitly be values or attributes");
|
|
23203
|
-
|
|
23204
|
-
this
|
|
23205
|
-
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);
|
|
23206
23516
|
}
|
|
23207
23517
|
subscribe(listener) {
|
|
23208
23518
|
this.#listeners.add(listener);
|
|
@@ -23218,7 +23528,9 @@ var BagCollectionStore = class {
|
|
|
23218
23528
|
publishCollection(this.#listeners, { full: row === null, rows: row ? [row] : [], event, field });
|
|
23219
23529
|
}
|
|
23220
23530
|
getRows() {
|
|
23221
|
-
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();
|
|
23222
23534
|
for (const node of nodes) {
|
|
23223
23535
|
if (node.resolver) throw new TypeError("collection store requires loaded rows");
|
|
23224
23536
|
if (this.rowMode === "values" && !(node.staticValue instanceof Bag)) {
|
|
@@ -23237,6 +23549,9 @@ var BagCollectionStore = class {
|
|
|
23237
23549
|
return cell?.staticValue;
|
|
23238
23550
|
}
|
|
23239
23551
|
};
|
|
23552
|
+
function collectionKey(path, rowMode) {
|
|
23553
|
+
return `${rowMode}:${path}`;
|
|
23554
|
+
}
|
|
23240
23555
|
function publishCollection(listeners, change) {
|
|
23241
23556
|
const errors = [];
|
|
23242
23557
|
const notice = Object.freeze({
|
|
@@ -23266,14 +23581,20 @@ var BagCollectionView = class {
|
|
|
23266
23581
|
#filters = /* @__PURE__ */ new Map();
|
|
23267
23582
|
#filtered = null;
|
|
23268
23583
|
constructor(store) {
|
|
23269
|
-
this
|
|
23584
|
+
this.#store = store;
|
|
23585
|
+
this.synchronize();
|
|
23270
23586
|
}
|
|
23271
|
-
|
|
23272
|
-
|
|
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;
|
|
23273
23590
|
}
|
|
23274
23591
|
get rowMode() {
|
|
23275
23592
|
return this.#store.rowMode;
|
|
23276
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
|
+
}
|
|
23277
23598
|
get sortedBy() {
|
|
23278
23599
|
return this.#sortedBy;
|
|
23279
23600
|
}
|
|
@@ -23317,21 +23638,12 @@ var BagCollectionView = class {
|
|
|
23317
23638
|
this.#release?.();
|
|
23318
23639
|
this.#release = null;
|
|
23319
23640
|
}
|
|
23320
|
-
bindStore(store) {
|
|
23321
|
-
if (this.#store === store) return;
|
|
23322
|
-
const connected = this.#release !== null;
|
|
23323
|
-
this.disconnect();
|
|
23324
|
-
this.#store = store;
|
|
23325
|
-
this.#indices.clear();
|
|
23326
|
-
if (connected) this.connect();
|
|
23327
|
-
else this.synchronize();
|
|
23328
|
-
}
|
|
23329
23641
|
getRows(filtered = true) {
|
|
23330
23642
|
const nodes = this.#orderedNodes();
|
|
23331
23643
|
return filtered && this.#filtered !== null ? this.#filtered.map((index) => nodes[index]) : nodes;
|
|
23332
23644
|
}
|
|
23333
23645
|
#orderedNodes() {
|
|
23334
|
-
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));
|
|
23335
23647
|
}
|
|
23336
23648
|
synchronize(change = { full: true, rows: [] }) {
|
|
23337
23649
|
if (!change.full && !this.#sortedBy && !this.#filters.size) {
|
|
@@ -23344,11 +23656,12 @@ var BagCollectionView = class {
|
|
|
23344
23656
|
const nodes = this.#sorted(this.#orderedNodes(), parseSort(sortedBy));
|
|
23345
23657
|
this.#commit(nodes, sortedBy, this.#filters);
|
|
23346
23658
|
}
|
|
23347
|
-
|
|
23348
|
-
|
|
23349
|
-
const nodes = this.getRows(false);
|
|
23350
|
-
|
|
23351
|
-
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);
|
|
23352
23665
|
this.#commit(nodes, "", this.#filters);
|
|
23353
23666
|
}
|
|
23354
23667
|
applyFilter(filter, contribution2 = "search") {
|
|
@@ -23408,13 +23721,13 @@ var BagCollectionView = class {
|
|
|
23408
23721
|
#commit(nodes, sortedBy, filters, change = { full: false, rows: [] }) {
|
|
23409
23722
|
const predicates = [...filters.values()].map((entry) => entry.predicate).filter((predicate) => predicate !== null);
|
|
23410
23723
|
const filtered = predicates.length ? nodes.flatMap((node, index) => predicates.every((predicate) => predicate((field) => this.value(node, field))) ? [index] : []) : null;
|
|
23411
|
-
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);
|
|
23412
|
-
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]));
|
|
23413
23726
|
this.#sortedBy = sortedBy;
|
|
23414
23727
|
this.#filters = filters;
|
|
23415
23728
|
this.#filtered = filtered;
|
|
23416
23729
|
const visible = filtered === null ? null : new Set(filtered);
|
|
23417
|
-
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))));
|
|
23418
23731
|
if (full || rows.length || change.rows.length) publishCollection(this.#listeners, { full, rows });
|
|
23419
23732
|
}
|
|
23420
23733
|
#sorted(nodes, criteria) {
|
|
@@ -23918,21 +24231,18 @@ var GridFormulas = class {
|
|
|
23918
24231
|
this.#view = view;
|
|
23919
24232
|
this.#errors.clear();
|
|
23920
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("?")]));
|
|
23921
24235
|
this.#release = [
|
|
23922
24236
|
store.subscribe((change) => this.#storeChanged(change)),
|
|
23923
24237
|
view.subscribe(() => {
|
|
23924
24238
|
this.#viewValues = null;
|
|
23925
24239
|
})
|
|
23926
24240
|
];
|
|
23927
|
-
for (const definition of
|
|
23928
|
-
|
|
23929
|
-
|
|
23930
|
-
|
|
23931
|
-
|
|
23932
|
-
this.#viewValues = null;
|
|
23933
|
-
this.recalculate(this.#closure([definition.field]));
|
|
23934
|
-
} } }));
|
|
23935
|
-
}
|
|
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
|
+
} } }));
|
|
23936
24246
|
}
|
|
23937
24247
|
this.recalculate(this.#closure(this.#selected((definition) => definition.calculated)));
|
|
23938
24248
|
}
|
|
@@ -23949,7 +24259,7 @@ var GridFormulas = class {
|
|
|
23949
24259
|
/** The value shown by this grid: a view value, or the stored field. */
|
|
23950
24260
|
value(node, field) {
|
|
23951
24261
|
if (!this.viewFields.has(field)) return this.#store.value(node, field);
|
|
23952
|
-
const values = this.#computeViewValues().get(node);
|
|
24262
|
+
const values = this.#computeViewValues().get(node.label);
|
|
23953
24263
|
return values === void 0 ? null : values[field];
|
|
23954
24264
|
}
|
|
23955
24265
|
#selected(predicate) {
|
|
@@ -23987,10 +24297,14 @@ var GridFormulas = class {
|
|
|
23987
24297
|
const global = [...closure].some((name) => this.formulas.definitions.get(name).special?.kind === "percent");
|
|
23988
24298
|
this.recalculate(closure, global ? null : [row]);
|
|
23989
24299
|
}
|
|
23990
|
-
|
|
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) {
|
|
23991
24305
|
const result = {};
|
|
23992
24306
|
for (const [name, raw] of definition.parameters) {
|
|
23993
|
-
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;
|
|
23994
24308
|
}
|
|
23995
24309
|
return result;
|
|
23996
24310
|
}
|
|
@@ -23999,7 +24313,7 @@ var GridFormulas = class {
|
|
|
23999
24313
|
if (definition.special?.kind === "index") return index;
|
|
24000
24314
|
if (definition.special?.kind === "running") return addNumeric(aggregate, read(row, definition.special.field));
|
|
24001
24315
|
if (definition.special?.kind === "percent") return dividePercent(read(row, definition.special.field), aggregate);
|
|
24002
|
-
const parameters2 = this.#parameters(definition);
|
|
24316
|
+
const parameters2 = this.#parameters(definition, row);
|
|
24003
24317
|
const scope = {};
|
|
24004
24318
|
for (const name of definition.references) {
|
|
24005
24319
|
if (Object.hasOwn(parameters2, name)) scope[name] = parameters2[name];
|
|
@@ -24069,12 +24383,12 @@ var GridFormulas = class {
|
|
|
24069
24383
|
this.#running = false;
|
|
24070
24384
|
}
|
|
24071
24385
|
}
|
|
24072
|
-
/** 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. */
|
|
24073
24387
|
#computeViewValues() {
|
|
24074
24388
|
if (this.#viewValues !== null) return this.#viewValues;
|
|
24075
24389
|
const ordered = this.#view.getRows();
|
|
24076
|
-
const values = new Map(ordered.map((row) => [row, {}]));
|
|
24077
|
-
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);
|
|
24078
24392
|
for (const field of this.formulas.order) {
|
|
24079
24393
|
const definition = this.formulas.definitions.get(field);
|
|
24080
24394
|
if (!definition.view) continue;
|
|
@@ -24087,7 +24401,7 @@ var GridFormulas = class {
|
|
|
24087
24401
|
} catch (error) {
|
|
24088
24402
|
failure2 = error;
|
|
24089
24403
|
}
|
|
24090
|
-
values.get(row)[field] = value;
|
|
24404
|
+
values.get(row.label)[field] = value;
|
|
24091
24405
|
}
|
|
24092
24406
|
if (failure2) this.#errors.set(field, failure2);
|
|
24093
24407
|
else this.#errors.delete(field);
|
|
@@ -24124,9 +24438,21 @@ var COLUMN_KEYS = /* @__PURE__ */ new Set([
|
|
|
24124
24438
|
]);
|
|
24125
24439
|
var FORMULA_PARAMETER = /^formula_[A-Za-z_$][\w$]*$/;
|
|
24126
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
|
+
}
|
|
24127
24449
|
var GridStructure = class {
|
|
24128
|
-
#
|
|
24129
|
-
|
|
24450
|
+
#labels = /* @__PURE__ */ new Map();
|
|
24451
|
+
#data;
|
|
24452
|
+
#path;
|
|
24453
|
+
constructor(bag, { data = null, path = null } = {}) {
|
|
24454
|
+
this.#data = data;
|
|
24455
|
+
this.#path = path;
|
|
24130
24456
|
if (!(bag instanceof Bag)) throw new TypeError("grid structpath must resolve to a Bag");
|
|
24131
24457
|
const view = branch(bag, "view_0"), info = branch(bag, "info");
|
|
24132
24458
|
const cells = branch(view, "rows_0"), definitions = branch(info, "columnsets");
|
|
@@ -24153,7 +24479,7 @@ var GridStructure = class {
|
|
|
24153
24479
|
requireIdentity(attrs.field, "field");
|
|
24154
24480
|
if (fields.has(attrs.field)) throw new TypeError(`Duplicate grid field: ${attrs.field}`);
|
|
24155
24481
|
fields.add(attrs.field);
|
|
24156
|
-
this.#
|
|
24482
|
+
this.#labels.set(attrs.field, node.label);
|
|
24157
24483
|
if (attrs.columnset != null && !groups.has(attrs.columnset)) throw new TypeError(`Unknown grid columnset: ${attrs.columnset}`);
|
|
24158
24484
|
if (attrs.dtype != null && !TYPES.has(attrs.dtype)) throw new TypeError(`Unsupported grid dtype: ${attrs.dtype}`);
|
|
24159
24485
|
if (attrs.align != null && !["start", "center", "end"].includes(attrs.align)) throw new TypeError("grid align requires start, center or end");
|
|
@@ -24166,6 +24492,7 @@ var GridStructure = class {
|
|
|
24166
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");
|
|
24167
24493
|
for (const key2 of ["name", "title", "format"]) if (attrs[key2] != null && typeof attrs[key2] !== "string") throw new TypeError(`grid ${key2} must be text`);
|
|
24168
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);
|
|
24169
24496
|
if (attrs.check != null || attrs.checked != null || attrs.checkedField != null) {
|
|
24170
24497
|
if (!["multiple", "single"].includes(attrs.check) || typeof attrs.checked !== "string" || !attrs.checked.startsWith("^") || attrs.checked.length < 2 || attrs.checked.includes("?")) {
|
|
24171
24498
|
throw new TypeError("grid check requires single or multiple and checked=^DataPath");
|
|
@@ -24201,20 +24528,35 @@ var GridStructure = class {
|
|
|
24201
24528
|
Object.freeze(this.groups);
|
|
24202
24529
|
Object.freeze(this);
|
|
24203
24530
|
}
|
|
24204
|
-
|
|
24205
|
-
|
|
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;
|
|
24206
24547
|
}
|
|
24207
24548
|
moveColumn(field, targetField, after = false) {
|
|
24208
|
-
const
|
|
24209
|
-
if (
|
|
24210
|
-
const bag =
|
|
24211
|
-
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;
|
|
24212
24554
|
const position = targetIndex + Number(after) - Number(from < targetIndex);
|
|
24213
24555
|
if (position !== from) bag.move(from, position);
|
|
24214
24556
|
}
|
|
24215
24557
|
setColumnWidth(field, width) {
|
|
24216
24558
|
if (!Number.isFinite(width) || width <= 0) throw new TypeError("grid resized width must be positive pixels");
|
|
24217
|
-
this.#
|
|
24559
|
+
this.#cells().getNode(this.#labels.get(field)).setAttr({ width: `${Math.round(width)}px` });
|
|
24218
24560
|
}
|
|
24219
24561
|
};
|
|
24220
24562
|
function branch(bag, label) {
|
|
@@ -24299,7 +24641,7 @@ function structureData(source) {
|
|
|
24299
24641
|
return data;
|
|
24300
24642
|
}
|
|
24301
24643
|
function validateGridDeclaration(node) {
|
|
24302
|
-
if (node._getMeta("gramlot_component")?.
|
|
24644
|
+
if (node._getMeta("gramlot_component")?.parameters?.structpath) {
|
|
24303
24645
|
const children = node.staticValue instanceof SourceBag ? node.staticValue.getNodes() : [];
|
|
24304
24646
|
if (children.some((child) => !child._getMeta("gridStruct")) || children.length > 1) throw new TypeError("grid accepts one struct declaration");
|
|
24305
24647
|
if (children.length && node.getAttr("structpath") != null) throw new TypeError("grid requires structpath or nested struct, not both");
|
|
@@ -24307,14 +24649,14 @@ function validateGridDeclaration(node) {
|
|
|
24307
24649
|
if (!["values", "attributes"].includes(node.getAttr("rowMode"))) throw new TypeError("grid rowMode must explicitly be values or attributes");
|
|
24308
24650
|
}
|
|
24309
24651
|
if (!node._getMeta("gridStruct")) return;
|
|
24310
|
-
if (!node.parentNode?._getMeta("gramlot_component")?.
|
|
24652
|
+
if (!node.parentNode?._getMeta("gramlot_component")?.parameters?.structpath) throw new TypeError("struct requires a grid parent");
|
|
24311
24653
|
if (!(node.staticValue instanceof SourceBag)) throw new TypeError("grid struct requires column declarations");
|
|
24312
24654
|
new GridStructure(structureData(node.staticValue));
|
|
24313
24655
|
}
|
|
24314
24656
|
function installGridStruct(node, data) {
|
|
24315
24657
|
const value = structureData(node.staticValue);
|
|
24316
24658
|
new GridStructure(value);
|
|
24317
|
-
const path =
|
|
24659
|
+
const path = `${node.parentNode.workspaceDatapath}.struct`;
|
|
24318
24660
|
data.setItem(path, value, null, ">", false, true, node);
|
|
24319
24661
|
node.parentNode.setAttr({ structpath: path }, false);
|
|
24320
24662
|
node.setValue(null, false);
|
|
@@ -25220,8 +25562,16 @@ var DataBinder = class {
|
|
|
25220
25562
|
}
|
|
25221
25563
|
register() {
|
|
25222
25564
|
const { runtime, node } = this.binding;
|
|
25223
|
-
|
|
25224
|
-
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
|
+
}
|
|
25225
25575
|
this.clientPath = node.absDatapath(node.pathAttribute("destination_path"));
|
|
25226
25576
|
this.serverPath = node.getAttr("server_path");
|
|
25227
25577
|
if (typeof this.clientPath !== "string" || !this.clientPath || this.clientPath.includes("?")) {
|
|
@@ -25523,11 +25873,24 @@ var PROVIDERS = {
|
|
|
25523
25873
|
dataRpc: RpcProvider,
|
|
25524
25874
|
dataRemote: RemoteProvider
|
|
25525
25875
|
};
|
|
25526
|
-
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
|
+
}
|
|
25527
25883
|
var BindingRuntime = class {
|
|
25528
25884
|
#gramlot;
|
|
25529
25885
|
#bindings = /* @__PURE__ */ new Map();
|
|
25530
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;
|
|
25531
25894
|
#router;
|
|
25532
25895
|
#installer;
|
|
25533
25896
|
#inlineCompiler;
|
|
@@ -25538,7 +25901,8 @@ var BindingRuntime = class {
|
|
|
25538
25901
|
#disposed = false;
|
|
25539
25902
|
#sourceTrees = /* @__PURE__ */ new Set();
|
|
25540
25903
|
#dataRootTrees = /* @__PURE__ */ new Set();
|
|
25541
|
-
|
|
25904
|
+
// One collection store per absolute Data path and rowMode, never per Bag identity.
|
|
25905
|
+
#collectionStores = /* @__PURE__ */ new Map();
|
|
25542
25906
|
constructor(gramlot, { subscriptions }) {
|
|
25543
25907
|
this.#gramlot = gramlot;
|
|
25544
25908
|
this.#subscriptions = subscriptions;
|
|
@@ -25573,7 +25937,6 @@ var BindingRuntime = class {
|
|
|
25573
25937
|
}
|
|
25574
25938
|
/** Resolve a tree store against the selected live root. */
|
|
25575
25939
|
treeStore(node) {
|
|
25576
|
-
if (node.treeStore !== null) return node.treeStore;
|
|
25577
25940
|
const path = node.getAttr("storepath");
|
|
25578
25941
|
if (path === "*S" || path.startsWith("*S.")) {
|
|
25579
25942
|
const root = this.renderer.source.getItem("main");
|
|
@@ -25623,23 +25986,64 @@ var BindingRuntime = class {
|
|
|
25623
25986
|
get nodeIds() {
|
|
25624
25987
|
return this.#nodeIds;
|
|
25625
25988
|
}
|
|
25626
|
-
/**
|
|
25627
|
-
|
|
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) {
|
|
25628
26022
|
if (this.disposed) throw new Error("BindingRuntime is disposed");
|
|
25629
|
-
|
|
26023
|
+
const key2 = collectionKey(path, rowMode);
|
|
26024
|
+
let store = this.#collectionStores.get(key2);
|
|
25630
26025
|
if (!store) {
|
|
25631
|
-
store = new BagCollectionStore(
|
|
25632
|
-
this.#collectionStores.set(
|
|
25633
|
-
}
|
|
26026
|
+
store = new BagCollectionStore(this.data, path, rowMode);
|
|
26027
|
+
this.#collectionStores.set(key2, store);
|
|
26028
|
+
}
|
|
25634
26029
|
return store;
|
|
25635
26030
|
}
|
|
25636
|
-
/**
|
|
25637
|
-
|
|
25638
|
-
|
|
25639
|
-
|
|
25640
|
-
|
|
25641
|
-
|
|
25642
|
-
|
|
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;
|
|
25643
26047
|
}
|
|
25644
26048
|
/** Subscribe once on Builder's Data wrapper; nothing is created. */
|
|
25645
26049
|
attach() {
|
|
@@ -25647,23 +26051,42 @@ var BindingRuntime = class {
|
|
|
25647
26051
|
}
|
|
25648
26052
|
/** Callback of the one Data subscription. */
|
|
25649
26053
|
receiveData(event) {
|
|
25650
|
-
|
|
25651
|
-
for (const [index, segment] of (event.pathlist ?? []).entries()) {
|
|
25652
|
-
const value = bag.node(segment)?.staticValue;
|
|
25653
|
-
if (!(value instanceof Bag)) break;
|
|
25654
|
-
const store = this.#collectionStores.get(value);
|
|
25655
|
-
store?.receiveData(
|
|
25656
|
-
event,
|
|
25657
|
-
index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null,
|
|
25658
|
-
event.pathlist[index + 2] ?? null
|
|
25659
|
-
);
|
|
25660
|
-
bag = value;
|
|
25661
|
-
}
|
|
26054
|
+
this.#notifyCollectionStores(event);
|
|
25662
26055
|
this.router.deliver(event);
|
|
25663
26056
|
for (const binding of [...this.#dataRootTrees]) {
|
|
25664
26057
|
if (!binding.closed && this.renderer.attached(binding.node)) this.renderer.project(binding.node);
|
|
25665
26058
|
}
|
|
25666
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
|
+
}
|
|
25667
26090
|
/** The open NodeBinding of `node`, or null. */
|
|
25668
26091
|
bindingFor(node) {
|
|
25669
26092
|
return this.#bindings.get(node) ?? null;
|
|
@@ -25700,6 +26123,11 @@ var BindingRuntime = class {
|
|
|
25700
26123
|
} catch (error) {
|
|
25701
26124
|
errors.push(error);
|
|
25702
26125
|
}
|
|
26126
|
+
try {
|
|
26127
|
+
this.#moving(startKeys(node));
|
|
26128
|
+
} catch (error) {
|
|
26129
|
+
errors.push(error);
|
|
26130
|
+
}
|
|
25703
26131
|
}
|
|
25704
26132
|
if (errors.length) throw new AggregateError(errors, "Source branch close failed");
|
|
25705
26133
|
}
|
|
@@ -25714,6 +26142,52 @@ var BindingRuntime = class {
|
|
|
25714
26142
|
for (const each of nodes) this.bindingFor(each)?.rebind();
|
|
25715
26143
|
for (const each of nodes) this.renderer.project(each);
|
|
25716
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");
|
|
25717
26191
|
}
|
|
25718
26192
|
/**
|
|
25719
26193
|
* Semantic work of one Source event, called inside the renderer FIFO (§5.2).
|
|
@@ -25737,6 +26211,7 @@ var BindingRuntime = class {
|
|
|
25737
26211
|
errors.push(error);
|
|
25738
26212
|
}
|
|
25739
26213
|
};
|
|
26214
|
+
const moved = this.#moved = { keys: /* @__PURE__ */ new Set(), done: /* @__PURE__ */ new Set() };
|
|
25740
26215
|
try {
|
|
25741
26216
|
if (evt === "ins") {
|
|
25742
26217
|
this.#openBranch(node);
|
|
@@ -25756,7 +26231,10 @@ var BindingRuntime = class {
|
|
|
25756
26231
|
} catch (error) {
|
|
25757
26232
|
if (!errors.length) throw error;
|
|
25758
26233
|
throw new AggregateError([...errors, error], "Source event failed");
|
|
26234
|
+
} finally {
|
|
26235
|
+
this.#moved = null;
|
|
25759
26236
|
}
|
|
26237
|
+
errors.push(...this.#rebindDependents(moved.keys, moved.done));
|
|
25760
26238
|
return errors;
|
|
25761
26239
|
}
|
|
25762
26240
|
/**
|
|
@@ -25792,7 +26270,8 @@ var BindingRuntime = class {
|
|
|
25792
26270
|
this.#disposed = true;
|
|
25793
26271
|
this.root.unsubscribe(this.#subscription, { any: true });
|
|
25794
26272
|
this.nodeIds.clear();
|
|
25795
|
-
this.#
|
|
26273
|
+
this.#dependents.clear();
|
|
26274
|
+
this.#collectionStores.clear();
|
|
25796
26275
|
const errors = [];
|
|
25797
26276
|
for (const [node, binding] of [...this.#bindings.entries()].reverse()) {
|
|
25798
26277
|
this.#bindings.delete(node);
|
|
@@ -25850,6 +26329,8 @@ var BindingRuntime = class {
|
|
|
25850
26329
|
if (errors.length > 1) throw new AggregateError(errors, "Source branch installation failed");
|
|
25851
26330
|
throw error;
|
|
25852
26331
|
}
|
|
26332
|
+
const installed = nodes.filter((node) => !known.has(node));
|
|
26333
|
+
this.#moving(installed.flatMap((node) => startKeys(node).slice(1)), installed);
|
|
25853
26334
|
for (const node of nodes) {
|
|
25854
26335
|
const binding = this.bindingFor(node);
|
|
25855
26336
|
if (!binding || binding.hasStamp("init") || !this.renderer.attached(node)) continue;
|
|
@@ -25898,7 +26379,9 @@ var BindingRuntime = class {
|
|
|
25898
26379
|
}
|
|
25899
26380
|
if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
|
|
25900
26381
|
if (current != null) this.nodeIds.set(current, node);
|
|
26382
|
+
this.#moving([`id:${previous}`, `id:${current}`]);
|
|
25901
26383
|
}
|
|
26384
|
+
if (Object.hasOwn(diff, "childname")) this.#moving([`childname:${diff.childname.old}`, `childname:${diff.childname.new}`]);
|
|
25902
26385
|
if (CONTEXT_ATTRIBUTES.some((name) => Object.hasOwn(diff, name))) this.rebindBranch(node);
|
|
25903
26386
|
else binding.rebind();
|
|
25904
26387
|
}
|
|
@@ -25944,6 +26427,8 @@ var NodeBinding = class {
|
|
|
25944
26427
|
// The registration of the node's own variable datapath, read in the parent's context.
|
|
25945
26428
|
#datapathRegistrations = /* @__PURE__ */ new Set();
|
|
25946
26429
|
#storeRegistration = null;
|
|
26430
|
+
// The starts of the symbolic resolution read by the registrations (BindingRuntime.dependOn).
|
|
26431
|
+
#dependencies = /* @__PURE__ */ new Set();
|
|
25947
26432
|
editingSession = null;
|
|
25948
26433
|
constructor(runtime, node) {
|
|
25949
26434
|
this.#runtime = runtime;
|
|
@@ -25962,6 +26447,10 @@ var NodeBinding = class {
|
|
|
25962
26447
|
get registrations() {
|
|
25963
26448
|
return [...this.#registrations];
|
|
25964
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
|
+
}
|
|
25965
26454
|
/** The Provider of a `dataFormula`, `dataController`, `dataRpc` or `dataRemote`, as a list of zero or one. */
|
|
25966
26455
|
get providers() {
|
|
25967
26456
|
return this.#provider ? [this.#provider] : [];
|
|
@@ -25995,6 +26484,9 @@ var NodeBinding = class {
|
|
|
25995
26484
|
* again from its current value.
|
|
25996
26485
|
*/
|
|
25997
26486
|
registerPointers() {
|
|
26487
|
+
this.runtime.resolveFor(this, () => this.#registerPointers());
|
|
26488
|
+
}
|
|
26489
|
+
#registerPointers() {
|
|
25998
26490
|
if (this.node._getMeta("data_element")) {
|
|
25999
26491
|
this.runtime.renderer.references.remove(this.node);
|
|
26000
26492
|
this.runtime.renderer.references.register(this.node, null);
|
|
@@ -26009,33 +26501,33 @@ var NodeBinding = class {
|
|
|
26009
26501
|
}
|
|
26010
26502
|
const remoteDependencies = /* @__PURE__ */ new Set();
|
|
26011
26503
|
const component = node._getMeta("gramlot_component");
|
|
26012
|
-
for (const
|
|
26013
|
-
if (!component?.[
|
|
26014
|
-
|
|
26015
|
-
const store = node.treeStore;
|
|
26016
|
-
const subscription = `gramlot-tree-${randomId()}`;
|
|
26017
|
-
store.subscribe(subscription, { any: () => {
|
|
26018
|
-
if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
|
|
26019
|
-
} });
|
|
26020
|
-
this.#registrations.push({ close: () => store.unsubscribe(subscription, { any: true }) });
|
|
26021
|
-
continue;
|
|
26022
|
-
}
|
|
26504
|
+
for (const attribute of ["storepath", "structpath"]) {
|
|
26505
|
+
if (!component?.parameters?.[attribute]) continue;
|
|
26506
|
+
const store = attribute === "storepath";
|
|
26023
26507
|
const value = node.getAttr(attribute);
|
|
26024
26508
|
if (typeof value !== "string" || !value || /^[\^=]/.test(value) || value.includes("?")) {
|
|
26025
26509
|
throw new TypeError(`${attribute} requires a plain Bag data path`);
|
|
26026
26510
|
}
|
|
26027
|
-
if (
|
|
26511
|
+
if (store && node.nodeTag === "tree" && (value === "*S" || value.startsWith("*S."))) {
|
|
26028
26512
|
this.#registrations.push(this.runtime.registerTreeRoot(this, true));
|
|
26029
26513
|
continue;
|
|
26030
26514
|
}
|
|
26031
|
-
if (
|
|
26515
|
+
if (store && node.nodeTag === "tree" && value === "*D") {
|
|
26032
26516
|
this.#registrations.push(this.runtime.registerTreeRoot(this, false));
|
|
26033
26517
|
continue;
|
|
26034
26518
|
}
|
|
26035
|
-
const path =
|
|
26519
|
+
const path = store && node.nodeTag === "tree" && value.startsWith("*D.") ? value.slice(3) : node.absDatapath(value);
|
|
26036
26520
|
const registration = this.runtime.router.register({ path, recipient: this, subtree: true });
|
|
26037
26521
|
this.#registrations.push(registration);
|
|
26038
|
-
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 }));
|
|
26039
26531
|
}
|
|
26040
26532
|
const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr("_timing")) : /* @__PURE__ */ new Set();
|
|
26041
26533
|
if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
|
|
@@ -26047,7 +26539,9 @@ var NodeBinding = class {
|
|
|
26047
26539
|
const absolute = context.absDatapath(pointer);
|
|
26048
26540
|
if (absolute === null) continue;
|
|
26049
26541
|
const [path, attr = null] = absolute.split("?", 2);
|
|
26050
|
-
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 });
|
|
26051
26545
|
this.#registrations.push(registration);
|
|
26052
26546
|
if (name === "datapath") this.#datapathRegistrations.add(registration);
|
|
26053
26547
|
if (this.remote && (name === "remote" || name.startsWith("remote_") || remoteDependencies.has(name))) this.#remoteRegistrations.add(registration);
|
|
@@ -26163,6 +26657,7 @@ var NodeBinding = class {
|
|
|
26163
26657
|
if (errors.length) throw new AggregateError(errors, `NodeBinding of '${this.node.label}' cleanup failed`);
|
|
26164
26658
|
}
|
|
26165
26659
|
#closeRegistrations() {
|
|
26660
|
+
this.runtime.releaseDependencies(this);
|
|
26166
26661
|
this.#binder?.unregister();
|
|
26167
26662
|
for (const registration of this.#registrations.splice(0)) registration.close();
|
|
26168
26663
|
this.#storeRegistration = null;
|
|
@@ -26514,7 +27009,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26514
27009
|
this.destination = destination;
|
|
26515
27010
|
this.html = new HtmlElement({
|
|
26516
27011
|
uploadContext: () => ({ gramlot: binding.gramlot, window: destination.ownerDocument.defaultView }),
|
|
26517
|
-
metadataAttributes: ["__ref"],
|
|
27012
|
+
metadataAttributes: ["__ref", ...SYMBOLIC_ATTRIBUTES],
|
|
26518
27013
|
format: (value, options) => binding.gramlot.format(value, options),
|
|
26519
27014
|
reportError: (node, error, title) => {
|
|
26520
27015
|
if (this.records.has(node)) binding.reportError(error, title);
|
|
@@ -26616,9 +27111,26 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26616
27111
|
attrs = Object.assign({}, ...ancestors, attrs);
|
|
26617
27112
|
}
|
|
26618
27113
|
this.#rebuildAttributes.delete(node);
|
|
27114
|
+
attrs = this.#withoutHeldBags(attrs, component);
|
|
26619
27115
|
this.#resolvedAttributes.set(node, attrs);
|
|
26620
27116
|
return attrs;
|
|
26621
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
|
+
}
|
|
26622
27134
|
/**
|
|
26623
27135
|
* Structural Source fragments are owned by the live renderer.
|
|
26624
27136
|
* A data-element has no DOM: it is recognized before validation and runtimeValues (R08).
|
|
@@ -27816,6 +28328,7 @@ var DeviceResolver = class extends BagResolver {
|
|
|
27816
28328
|
|
|
27817
28329
|
// src/handlers/device-handler.js
|
|
27818
28330
|
var NAMES = ["appinfo", "location"];
|
|
28331
|
+
var DEVICE = "_gramlot.device";
|
|
27819
28332
|
var ERROR_STATUS = {
|
|
27820
28333
|
UNAVAILABLE: "unavailable",
|
|
27821
28334
|
PERMISSION_DENIED: "denied",
|
|
@@ -27846,13 +28359,13 @@ var DeviceHandler = class extends Handler {
|
|
|
27846
28359
|
#pushEvents = null;
|
|
27847
28360
|
#shortcutEvents = null;
|
|
27848
28361
|
#linkEvents = null;
|
|
28362
|
+
#registration = null;
|
|
27849
28363
|
constructor(gramlot) {
|
|
27850
28364
|
super(gramlot);
|
|
27851
28365
|
this.provider = null;
|
|
27852
28366
|
this.disposed = false;
|
|
27853
28367
|
this.monitor = null;
|
|
27854
28368
|
this.retiring = null;
|
|
27855
|
-
this.resolvers = /* @__PURE__ */ new Map();
|
|
27856
28369
|
this.cleanup = Promise.resolve();
|
|
27857
28370
|
}
|
|
27858
28371
|
installData() {
|
|
@@ -27866,11 +28379,7 @@ var DeviceHandler = class extends Handler {
|
|
|
27866
28379
|
{ enabled: false, watching: false, status: "idle", error: null }
|
|
27867
28380
|
);
|
|
27868
28381
|
gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({ error: null }, false, true, false);
|
|
27869
|
-
this.#sensors.set(name, {
|
|
27870
|
-
node: gramlot.data.getNode(`_gramlot.device.${name}`),
|
|
27871
|
-
stream: null,
|
|
27872
|
-
cleanup: Promise.resolve()
|
|
27873
|
-
});
|
|
28382
|
+
this.#sensors.set(name, { stream: null, cleanup: Promise.resolve() });
|
|
27874
28383
|
}
|
|
27875
28384
|
for (const name of NAMES) {
|
|
27876
28385
|
const path = `_gramlot.device.${name}`;
|
|
@@ -27879,22 +28388,16 @@ var DeviceHandler = class extends Handler {
|
|
|
27879
28388
|
gramlot.data.setItem(path, null);
|
|
27880
28389
|
const node = gramlot.data.getNode(path);
|
|
27881
28390
|
node.setAttr(attrs, false, true, false);
|
|
27882
|
-
|
|
27883
|
-
node.resolver = resolver;
|
|
27884
|
-
this.resolvers.set(name, resolver);
|
|
28391
|
+
node.resolver = new DeviceResolver(this, name, attrs.cacheTime);
|
|
27885
28392
|
}
|
|
27886
28393
|
gramlot.data.setItem(
|
|
27887
28394
|
"_gramlot.device.clipboard",
|
|
27888
28395
|
null,
|
|
27889
28396
|
{ status: "idle", error: null, text: "", copy: null, paste: null, operation: null }
|
|
27890
28397
|
);
|
|
27891
|
-
const clipboard = gramlot.data.getNode("_gramlot.device.clipboard");
|
|
27892
28398
|
gramlot.data.setItem("_gramlot.device.camera", null, { status: "idle", error: null, capture: null, choose: null });
|
|
27893
|
-
const camera = gramlot.data.getNode("_gramlot.device.camera");
|
|
27894
28399
|
gramlot.data.setItem("_gramlot.device.barcode", null, { status: "idle", error: null, scan: null });
|
|
27895
|
-
const barcode = gramlot.data.getNode("_gramlot.device.barcode");
|
|
27896
28400
|
gramlot.data.setItem("_gramlot.device.biometrics", null, { status: "idle", error: null, verify: null });
|
|
27897
|
-
const biometrics = gramlot.data.getNode("_gramlot.device.biometrics");
|
|
27898
28401
|
const notifications = new Bag();
|
|
27899
28402
|
notifications.setItem("request", new Bag());
|
|
27900
28403
|
for (const name of ["scheduled", "received", "action"]) notifications.setItem(name, null);
|
|
@@ -27903,7 +28406,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27903
28406
|
notifications,
|
|
27904
28407
|
{ status: "idle", error: null, schedule: null, listening: false, listenerError: null }
|
|
27905
28408
|
);
|
|
27906
|
-
const notificationNode = gramlot.data.getNode("_gramlot.device.notifications");
|
|
27907
28409
|
const push = new Bag();
|
|
27908
28410
|
for (const name of ["registration", "received", "action"]) push.setItem(name, null);
|
|
27909
28411
|
gramlot.data.setItem(
|
|
@@ -27911,7 +28413,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27911
28413
|
push,
|
|
27912
28414
|
{ status: "idle", error: null, register: null, listening: false, listenerError: null }
|
|
27913
28415
|
);
|
|
27914
|
-
const pushNode = gramlot.data.getNode("_gramlot.device.push");
|
|
27915
28416
|
const links = new Bag();
|
|
27916
28417
|
links.setItem("request", null);
|
|
27917
28418
|
gramlot.data.setItem("_gramlot.device.links", links, { listening: false, listenerError: null });
|
|
@@ -27929,7 +28430,6 @@ var DeviceHandler = class extends Handler {
|
|
|
27929
28430
|
null,
|
|
27930
28431
|
{ status: "idle", error: null, impact: null, style: "medium", vibrate: null, duration: 600 }
|
|
27931
28432
|
);
|
|
27932
|
-
const haptics = gramlot.data.getNode("_gramlot.device.haptics");
|
|
27933
28433
|
gramlot.data.setItem(
|
|
27934
28434
|
"_gramlot.device.audio",
|
|
27935
28435
|
null,
|
|
@@ -27946,62 +28446,56 @@ var DeviceHandler = class extends Handler {
|
|
|
27946
28446
|
shareActivity: null
|
|
27947
28447
|
}
|
|
27948
28448
|
);
|
|
27949
|
-
|
|
27950
|
-
|
|
27951
|
-
|
|
27952
|
-
|
|
27953
|
-
|
|
27954
|
-
|
|
27955
|
-
|
|
27956
|
-
|
|
27957
|
-
|
|
27958
|
-
|
|
27959
|
-
|
|
27960
|
-
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
27964
|
-
|
|
27965
|
-
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
|
|
27969
|
-
|
|
27970
|
-
|
|
27971
|
-
if (
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
|
|
27977
|
-
if (
|
|
27978
|
-
|
|
27979
|
-
|
|
27980
|
-
|
|
27981
|
-
|
|
27982
|
-
|
|
27983
|
-
|
|
27984
|
-
|
|
27985
|
-
|
|
27986
|
-
|
|
27987
|
-
|
|
27988
|
-
|
|
27989
|
-
|
|
27990
|
-
|
|
27991
|
-
|
|
27992
|
-
|
|
27993
|
-
|
|
27994
|
-
|
|
27995
|
-
if (typeof
|
|
27996
|
-
|
|
27997
|
-
}
|
|
27998
|
-
resolver.cacheTime = cacheTime;
|
|
27999
|
-
if (resolver.name === "location") {
|
|
28000
|
-
if (typeof event.node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
|
|
28001
|
-
this.reconcile();
|
|
28002
|
-
}
|
|
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();
|
|
28003
28497
|
}
|
|
28004
|
-
}
|
|
28498
|
+
}
|
|
28005
28499
|
}
|
|
28006
28500
|
/** Attach the explicitly selected provider once, before the page reads device values. */
|
|
28007
28501
|
attach(provider, { dispose = null } = {}) {
|
|
@@ -28042,16 +28536,16 @@ var DeviceHandler = class extends Handler {
|
|
|
28042
28536
|
node.setAttr({ status: "success", error: null }, true, true, false);
|
|
28043
28537
|
});
|
|
28044
28538
|
if (provider.capabilities.includes("links")) {
|
|
28045
|
-
this.#startLinkEvents(
|
|
28539
|
+
this.#startLinkEvents();
|
|
28046
28540
|
}
|
|
28047
28541
|
if (provider.capabilities.includes("shortcuts")) {
|
|
28048
|
-
this.#startShortcutEvents(
|
|
28542
|
+
this.#startShortcutEvents();
|
|
28049
28543
|
}
|
|
28050
28544
|
if (provider.capabilities.includes("push")) {
|
|
28051
|
-
this.#startPushEvents(
|
|
28545
|
+
this.#startPushEvents();
|
|
28052
28546
|
}
|
|
28053
28547
|
if (provider.capabilities.includes("notifications")) {
|
|
28054
|
-
this.#startNotificationEvents(
|
|
28548
|
+
this.#startNotificationEvents();
|
|
28055
28549
|
}
|
|
28056
28550
|
}
|
|
28057
28551
|
assertLive() {
|
|
@@ -28059,8 +28553,9 @@ var DeviceHandler = class extends Handler {
|
|
|
28059
28553
|
}
|
|
28060
28554
|
resolver(name) {
|
|
28061
28555
|
this.assertLive();
|
|
28062
|
-
|
|
28063
|
-
|
|
28556
|
+
const node = NAMES.includes(name) ? this.#deviceNode(name) : null;
|
|
28557
|
+
if (!node) throw new TypeError(`Unknown device value: ${name}`);
|
|
28558
|
+
return node.resolver;
|
|
28064
28559
|
}
|
|
28065
28560
|
invalidate(name) {
|
|
28066
28561
|
this.resolver(name).reset();
|
|
@@ -28072,65 +28567,67 @@ var DeviceHandler = class extends Handler {
|
|
|
28072
28567
|
const request = { revision: resolver.revision, received: resolver.received };
|
|
28073
28568
|
resolver.request = request;
|
|
28074
28569
|
this.attributes(resolver, { status: "pending", error: null });
|
|
28570
|
+
const current = () => this.resolver(name);
|
|
28075
28571
|
Promise.resolve().then(() => {
|
|
28076
|
-
if (this.disposed ||
|
|
28572
|
+
if (this.disposed || current().request !== request) return;
|
|
28077
28573
|
this.requireCapability(name);
|
|
28078
28574
|
return name === "appinfo" ? this.provider.readAppInfo() : this.provider.readLocation();
|
|
28079
28575
|
}).then((value) => {
|
|
28080
|
-
if (this.disposed ||
|
|
28081
|
-
this.accept(
|
|
28082
|
-
if (
|
|
28576
|
+
if (this.disposed || current().request !== request) return;
|
|
28577
|
+
this.accept(current(), value);
|
|
28578
|
+
if (current().revision !== request.revision) current()._lastUpdate = null;
|
|
28083
28579
|
}).catch((error) => {
|
|
28084
|
-
if (!this.disposed &&
|
|
28085
|
-
this.failure(
|
|
28580
|
+
if (!this.disposed && current().request === request && current().received === request.received) {
|
|
28581
|
+
this.failure(current(), error);
|
|
28086
28582
|
}
|
|
28087
28583
|
}).finally(() => {
|
|
28088
|
-
if (
|
|
28584
|
+
if (!this.disposed && current().request === request) current().request = null;
|
|
28089
28585
|
});
|
|
28090
28586
|
}
|
|
28091
28587
|
// Page-owned state streams share lifetime/error handling, never public dispatch.
|
|
28092
28588
|
#startStateEvents(name, start, accept) {
|
|
28093
|
-
const node = this
|
|
28589
|
+
const node = () => this.#deviceNode(name);
|
|
28094
28590
|
if (!this.provider.capabilities.includes(name)) {
|
|
28095
|
-
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);
|
|
28096
28592
|
return;
|
|
28097
28593
|
}
|
|
28098
28594
|
const events = { controller: new AbortController() };
|
|
28099
28595
|
this.#stateEvents.set(name, events);
|
|
28100
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28596
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28101
28597
|
events.start = Promise.resolve().then(() => {
|
|
28102
28598
|
if (events.controller.signal.aborted) return async () => {
|
|
28103
28599
|
};
|
|
28104
28600
|
return start((value) => {
|
|
28105
28601
|
if (events.controller.signal.aborted) return;
|
|
28106
28602
|
try {
|
|
28107
|
-
accept(node, value);
|
|
28603
|
+
accept(node(), value);
|
|
28108
28604
|
} catch (error) {
|
|
28109
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28605
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28110
28606
|
}
|
|
28111
28607
|
}, events.controller.signal);
|
|
28112
28608
|
}).then((stop) => {
|
|
28113
|
-
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);
|
|
28114
28610
|
return stop;
|
|
28115
28611
|
});
|
|
28116
28612
|
events.start.catch((error) => {
|
|
28117
28613
|
const aborted = events.controller.signal.aborted;
|
|
28118
28614
|
events.controller.abort();
|
|
28119
|
-
if (!aborted) node.setAttr({ ...failureAttributes(error), listening: false }, true, true, false);
|
|
28615
|
+
if (!aborted) node().setAttr({ ...failureAttributes(error), listening: false }, true, true, false);
|
|
28120
28616
|
});
|
|
28121
28617
|
}
|
|
28122
|
-
#reconcileSensor(name
|
|
28123
|
-
const
|
|
28124
|
-
|
|
28618
|
+
#reconcileSensor(name) {
|
|
28619
|
+
const sensor = this.#sensors.get(name);
|
|
28620
|
+
const node = () => this.#deviceNode(name);
|
|
28621
|
+
if (!node().attr.enabled) {
|
|
28125
28622
|
const stream2 = sensor.stream;
|
|
28126
28623
|
if (!stream2) return;
|
|
28127
28624
|
sensor.stream = null;
|
|
28128
28625
|
stream2.controller.abort();
|
|
28129
28626
|
sensor.cleanup = stream2.start.then((stop) => stop(), () => void 0).then(() => {
|
|
28130
|
-
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);
|
|
28131
28628
|
});
|
|
28132
28629
|
sensor.cleanup.catch((error) => {
|
|
28133
|
-
if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
|
|
28630
|
+
if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
|
|
28134
28631
|
});
|
|
28135
28632
|
return;
|
|
28136
28633
|
}
|
|
@@ -28145,38 +28642,39 @@ var DeviceHandler = class extends Handler {
|
|
|
28145
28642
|
if (this.disposed || stream.controller.signal.aborted) return;
|
|
28146
28643
|
try {
|
|
28147
28644
|
if (event?.kind === "state" && typeof event.watching === "boolean") {
|
|
28148
|
-
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);
|
|
28149
28646
|
} else if (event?.kind === "sample") {
|
|
28150
28647
|
for (const field of ["x", "y", "z", "timestamp"]) {
|
|
28151
28648
|
if (!Number.isFinite(event[field])) throw new TypeError(`Invalid ${name}.${field}`);
|
|
28152
28649
|
}
|
|
28153
|
-
if (!node.attr.watching) return;
|
|
28154
|
-
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;
|
|
28155
28652
|
const value = new Bag();
|
|
28156
28653
|
for (const field of ["x", "y", "z", "timestamp"]) value.setItem(field, event[field]);
|
|
28157
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28654
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28158
28655
|
} else if (event?.kind === "error" && event.error instanceof Error) {
|
|
28159
|
-
node.setAttr({ ...failureAttributes(event.error), watching: false }, true, true, false);
|
|
28656
|
+
node().setAttr({ ...failureAttributes(event.error), watching: false }, true, true, false);
|
|
28160
28657
|
} else throw new TypeError(`Invalid ${name} event`);
|
|
28161
28658
|
} catch (error) {
|
|
28162
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28659
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28163
28660
|
}
|
|
28164
28661
|
};
|
|
28165
28662
|
return name === "gyroscope" ? this.provider.startGyroscopeUpdates(accept, stream.controller.signal) : this.provider.startAccelerometerUpdates(accept, stream.controller.signal);
|
|
28166
28663
|
});
|
|
28167
28664
|
stream.start.catch((error) => {
|
|
28168
28665
|
if (!this.disposed && !stream.controller.signal.aborted) {
|
|
28169
|
-
node.setAttr({ ...failureAttributes(error), watching: false }, true, true, false);
|
|
28666
|
+
node().setAttr({ ...failureAttributes(error), watching: false }, true, true, false);
|
|
28170
28667
|
}
|
|
28171
28668
|
});
|
|
28172
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28669
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28173
28670
|
}
|
|
28174
|
-
#startAudio(
|
|
28671
|
+
#startAudio() {
|
|
28672
|
+
const node = () => this.#deviceNode("audio");
|
|
28175
28673
|
const previous = this.#audio;
|
|
28176
28674
|
if (previous) {
|
|
28177
28675
|
if (previous.phase !== "complete") return;
|
|
28178
28676
|
previous.phase = "replacing";
|
|
28179
|
-
node.setValue(null, true, {
|
|
28677
|
+
node().setValue(null, true, {
|
|
28180
28678
|
status: "pending",
|
|
28181
28679
|
error: null,
|
|
28182
28680
|
recording: false,
|
|
@@ -28187,18 +28685,18 @@ var DeviceHandler = class extends Handler {
|
|
|
28187
28685
|
previous.close = previous.start.then((session) => session.dispose()).then(() => {
|
|
28188
28686
|
if (this.disposed || previous.controller.signal.aborted || this.#audio !== previous) return;
|
|
28189
28687
|
this.#audio = null;
|
|
28190
|
-
this.#startAudio(
|
|
28688
|
+
this.#startAudio();
|
|
28191
28689
|
}).catch((error) => {
|
|
28192
28690
|
if (!this.disposed && this.#audio === previous) {
|
|
28193
28691
|
previous.phase = "failed";
|
|
28194
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
28692
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28195
28693
|
}
|
|
28196
28694
|
});
|
|
28197
28695
|
return;
|
|
28198
28696
|
}
|
|
28199
28697
|
const audio = { controller: new AbortController(), phase: "starting" };
|
|
28200
28698
|
this.#audio = audio;
|
|
28201
|
-
node.setValue(null, true, {
|
|
28699
|
+
node().setValue(null, true, {
|
|
28202
28700
|
status: "pending",
|
|
28203
28701
|
error: null,
|
|
28204
28702
|
recording: false,
|
|
@@ -28210,24 +28708,25 @@ var DeviceHandler = class extends Handler {
|
|
|
28210
28708
|
if (audio.controller.signal.aborted) return null;
|
|
28211
28709
|
this.requireCapability("audio");
|
|
28212
28710
|
return this.provider.startAudioRecording((error) => {
|
|
28213
|
-
if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(
|
|
28711
|
+
if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(error);
|
|
28214
28712
|
}, audio.controller.signal);
|
|
28215
28713
|
});
|
|
28216
28714
|
audio.start.then((session) => {
|
|
28217
28715
|
if (!session || audio.controller.signal.aborted || this.disposed) return;
|
|
28218
28716
|
audio.phase = "recording";
|
|
28219
|
-
node.setAttr({ status: "recording", error: null, recording: true }, true, true, false);
|
|
28717
|
+
node().setAttr({ status: "recording", error: null, recording: true }, true, true, false);
|
|
28220
28718
|
}).catch((error) => {
|
|
28221
28719
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28222
28720
|
if (this.#audio === audio) this.#audio = null;
|
|
28223
|
-
node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28721
|
+
node().setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28224
28722
|
});
|
|
28225
28723
|
}
|
|
28226
|
-
#stopAudio(
|
|
28724
|
+
#stopAudio() {
|
|
28725
|
+
const node = () => this.#deviceNode("audio");
|
|
28227
28726
|
const audio = this.#audio;
|
|
28228
28727
|
if (!audio || audio.phase !== "recording") return;
|
|
28229
28728
|
audio.phase = "stopping";
|
|
28230
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28729
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28231
28730
|
audio.stop = audio.start.then((session) => session.stop()).then((result) => {
|
|
28232
28731
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28233
28732
|
if (typeof result?.url !== "string" || !result.url || typeof result.mimeType !== "string" || !result.mimeType.startsWith("audio/") || !Number.isFinite(result.duration) || result.duration < 0) {
|
|
@@ -28236,39 +28735,41 @@ var DeviceHandler = class extends Handler {
|
|
|
28236
28735
|
const value = new Bag();
|
|
28237
28736
|
for (const key2 of ["url", "mimeType", "duration"]) value.setItem(key2, result[key2]);
|
|
28238
28737
|
audio.phase = "complete";
|
|
28239
|
-
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);
|
|
28240
28739
|
}).catch((error) => {
|
|
28241
|
-
if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(
|
|
28740
|
+
if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(error);
|
|
28242
28741
|
});
|
|
28243
28742
|
}
|
|
28244
|
-
#shareAudio(
|
|
28743
|
+
#shareAudio() {
|
|
28744
|
+
const node = () => this.#deviceNode("audio");
|
|
28245
28745
|
const audio = this.#audio;
|
|
28246
28746
|
if (audio?.phase === "sharing") return;
|
|
28247
28747
|
if (!audio || audio.phase !== "complete") {
|
|
28248
28748
|
const failure2 = failureAttributes(new Error("Record and stop audio before sharing"));
|
|
28249
|
-
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);
|
|
28250
28750
|
return;
|
|
28251
28751
|
}
|
|
28252
28752
|
audio.phase = "sharing";
|
|
28253
|
-
node.setAttr({ shareStatus: "pending", shareError: null, shareActivity: null }, true, true, false);
|
|
28753
|
+
node().setAttr({ shareStatus: "pending", shareError: null, shareActivity: null }, true, true, false);
|
|
28254
28754
|
audio.share = audio.start.then((session) => session.share(audio.controller.signal)).then((result) => {
|
|
28255
28755
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28256
28756
|
if (typeof result?.activity !== "string") throw new TypeError("Invalid audio share result from device provider");
|
|
28257
|
-
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);
|
|
28258
28758
|
}).catch((error) => {
|
|
28259
28759
|
if (audio.controller.signal.aborted || this.disposed) return;
|
|
28260
28760
|
const failure2 = failureAttributes(error);
|
|
28261
|
-
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);
|
|
28262
28762
|
}).finally(() => {
|
|
28263
28763
|
if (this.#audio === audio && !audio.controller.signal.aborted) audio.phase = "complete";
|
|
28264
28764
|
});
|
|
28265
28765
|
}
|
|
28266
|
-
#cancelAudio(
|
|
28766
|
+
#cancelAudio(error = { code: "CANCELLED", message: "Audio recording cancelled" }) {
|
|
28767
|
+
const node = () => this.#deviceNode("audio");
|
|
28267
28768
|
const audio = this.#audio;
|
|
28268
28769
|
if (!audio || audio.phase === "closing" || audio.phase === "sharing") return;
|
|
28269
28770
|
audio.phase = "closing";
|
|
28270
28771
|
audio.controller.abort();
|
|
28271
|
-
node.setValue(null, true, {
|
|
28772
|
+
node().setValue(null, true, {
|
|
28272
28773
|
status: "pending",
|
|
28273
28774
|
error: null,
|
|
28274
28775
|
shareStatus: "idle",
|
|
@@ -28280,20 +28781,21 @@ var DeviceHandler = class extends Handler {
|
|
|
28280
28781
|
}).then(() => {
|
|
28281
28782
|
if (this.disposed || this.#audio !== audio) return;
|
|
28282
28783
|
this.#audio = null;
|
|
28283
|
-
node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28784
|
+
node().setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
|
|
28284
28785
|
}).catch((cleanupError) => {
|
|
28285
28786
|
if (!this.disposed && this.#audio === audio) {
|
|
28286
28787
|
audio.phase = "failed";
|
|
28287
|
-
node.setAttr(failureAttributes(cleanupError), true, true, false);
|
|
28788
|
+
node().setAttr(failureAttributes(cleanupError), true, true, false);
|
|
28288
28789
|
}
|
|
28289
28790
|
});
|
|
28290
28791
|
}
|
|
28291
|
-
#clipboardCommand(
|
|
28792
|
+
#clipboardCommand(operation) {
|
|
28793
|
+
const node = () => this.#deviceNode("clipboard");
|
|
28292
28794
|
if (this.#clipboardRequest) return;
|
|
28293
28795
|
const request = new AbortController();
|
|
28294
28796
|
this.#clipboardRequest = request;
|
|
28295
|
-
const text3 = node.attr.text;
|
|
28296
|
-
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);
|
|
28297
28799
|
Promise.resolve().then(async () => {
|
|
28298
28800
|
if (request.signal.aborted) return;
|
|
28299
28801
|
this.requireCapability("clipboard");
|
|
@@ -28309,19 +28811,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28309
28811
|
if (typeof result?.text !== "string") throw new TypeError("Invalid clipboard text from device provider");
|
|
28310
28812
|
const value = new Bag();
|
|
28311
28813
|
value.setItem("text", result.text);
|
|
28312
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28814
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28313
28815
|
}).catch((error) => {
|
|
28314
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28816
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28315
28817
|
}).finally(() => {
|
|
28316
28818
|
if (this.#clipboardRequest === request) this.#clipboardRequest = null;
|
|
28317
28819
|
});
|
|
28318
28820
|
}
|
|
28319
|
-
#vibrate(
|
|
28821
|
+
#vibrate() {
|
|
28822
|
+
const node = () => this.#deviceNode("haptics");
|
|
28320
28823
|
if (this.#hapticRequest) return;
|
|
28321
28824
|
const request = new AbortController();
|
|
28322
28825
|
this.#hapticRequest = request;
|
|
28323
|
-
const { duration } = node.attr;
|
|
28324
|
-
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);
|
|
28325
28828
|
Promise.resolve().then(async () => {
|
|
28326
28829
|
if (request.signal.aborted) return;
|
|
28327
28830
|
this.requireCapability("haptics");
|
|
@@ -28333,19 +28836,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28333
28836
|
const value = new Bag();
|
|
28334
28837
|
value.setItem("duration", duration);
|
|
28335
28838
|
value.setItem("acknowledged", true);
|
|
28336
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28839
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28337
28840
|
}).catch((error) => {
|
|
28338
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28841
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28339
28842
|
}).finally(() => {
|
|
28340
28843
|
if (this.#hapticRequest === request) this.#hapticRequest = null;
|
|
28341
28844
|
});
|
|
28342
28845
|
}
|
|
28343
|
-
#impact(
|
|
28846
|
+
#impact() {
|
|
28847
|
+
const node = () => this.#deviceNode("haptics");
|
|
28344
28848
|
if (this.#hapticRequest) return;
|
|
28345
28849
|
const request = new AbortController();
|
|
28346
28850
|
this.#hapticRequest = request;
|
|
28347
|
-
const { style } = node.attr;
|
|
28348
|
-
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);
|
|
28349
28853
|
Promise.resolve().then(async () => {
|
|
28350
28854
|
if (request.signal.aborted) return;
|
|
28351
28855
|
this.requireCapability("haptics");
|
|
@@ -28355,18 +28859,19 @@ var DeviceHandler = class extends Handler {
|
|
|
28355
28859
|
const value = new Bag();
|
|
28356
28860
|
value.setItem("style", style);
|
|
28357
28861
|
value.setItem("acknowledged", true);
|
|
28358
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28862
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28359
28863
|
}).catch((error) => {
|
|
28360
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28864
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28361
28865
|
}).finally(() => {
|
|
28362
28866
|
if (this.#hapticRequest === request) this.#hapticRequest = null;
|
|
28363
28867
|
});
|
|
28364
28868
|
}
|
|
28365
|
-
#scanBarcode(
|
|
28869
|
+
#scanBarcode() {
|
|
28870
|
+
const node = () => this.#deviceNode("barcode");
|
|
28366
28871
|
if (this.#barcodeRequest) return;
|
|
28367
28872
|
const request = new AbortController();
|
|
28368
28873
|
this.#barcodeRequest = request;
|
|
28369
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28874
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28370
28875
|
Promise.resolve().then(() => {
|
|
28371
28876
|
if (request.signal.aborted) return;
|
|
28372
28877
|
this.requireCapability("barcode");
|
|
@@ -28379,19 +28884,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28379
28884
|
const value = new Bag();
|
|
28380
28885
|
value.setItem("text", result.text);
|
|
28381
28886
|
value.setItem("format", result.format);
|
|
28382
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28887
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28383
28888
|
}).catch((error) => {
|
|
28384
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28889
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28385
28890
|
}).finally(() => {
|
|
28386
28891
|
if (this.#barcodeRequest === request) this.#barcodeRequest = null;
|
|
28387
28892
|
});
|
|
28388
28893
|
}
|
|
28389
28894
|
// Camera is an explicit Data event, never a resolver read with a UI side effect.
|
|
28390
|
-
#photo(
|
|
28895
|
+
#photo(operation) {
|
|
28896
|
+
const node = () => this.#deviceNode("camera");
|
|
28391
28897
|
if (this.#captureRequest) return;
|
|
28392
28898
|
const request = new AbortController();
|
|
28393
28899
|
this.#captureRequest = request;
|
|
28394
|
-
node.setAttr({ status: "pending", error: null }, true, true, false);
|
|
28900
|
+
node().setAttr({ status: "pending", error: null }, true, true, false);
|
|
28395
28901
|
Promise.resolve().then(() => {
|
|
28396
28902
|
if (request.signal.aborted) return;
|
|
28397
28903
|
this.requireCapability("camera");
|
|
@@ -28404,19 +28910,20 @@ var DeviceHandler = class extends Handler {
|
|
|
28404
28910
|
const value = new Bag();
|
|
28405
28911
|
value.setItem("url", photo.url);
|
|
28406
28912
|
value.setItem("format", photo.format);
|
|
28407
|
-
node.setValue(value, true, { status: "success", error: null }, true, false);
|
|
28913
|
+
node().setValue(value, true, { status: "success", error: null }, true, false);
|
|
28408
28914
|
}).catch((error) => {
|
|
28409
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
28915
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28410
28916
|
}).finally(() => {
|
|
28411
28917
|
if (this.#captureRequest === request) this.#captureRequest = null;
|
|
28412
28918
|
});
|
|
28413
28919
|
}
|
|
28414
28920
|
// A fresh attempt clears the previous local verification, including on cancellation.
|
|
28415
|
-
#verifyBiometrics(
|
|
28921
|
+
#verifyBiometrics() {
|
|
28922
|
+
const node = () => this.#deviceNode("biometrics");
|
|
28416
28923
|
if (this.#biometricsRequest) return;
|
|
28417
28924
|
const request = new AbortController();
|
|
28418
28925
|
this.#biometricsRequest = request;
|
|
28419
|
-
node.setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28926
|
+
node().setValue(null, true, { status: "pending", error: null }, true, false);
|
|
28420
28927
|
Promise.resolve().then(() => {
|
|
28421
28928
|
if (request.signal.aborted) return;
|
|
28422
28929
|
this.requireCapability("biometrics");
|
|
@@ -28425,14 +28932,15 @@ var DeviceHandler = class extends Handler {
|
|
|
28425
28932
|
if (request.signal.aborted) return;
|
|
28426
28933
|
const result = new Bag();
|
|
28427
28934
|
result.setItem("verified", true);
|
|
28428
|
-
node.setValue(result, true, { status: "success", error: null }, true, false);
|
|
28935
|
+
node().setValue(result, true, { status: "success", error: null }, true, false);
|
|
28429
28936
|
}).catch((error) => {
|
|
28430
|
-
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);
|
|
28431
28938
|
}).finally(() => {
|
|
28432
28939
|
if (this.#biometricsRequest === request) this.#biometricsRequest = null;
|
|
28433
28940
|
});
|
|
28434
28941
|
}
|
|
28435
|
-
#startNotificationEvents(
|
|
28942
|
+
#startNotificationEvents() {
|
|
28943
|
+
const node = () => this.#deviceNode("notifications");
|
|
28436
28944
|
if (this.#notificationEvents) return this.#notificationEvents.start;
|
|
28437
28945
|
const events = { controller: new AbortController() };
|
|
28438
28946
|
this.#notificationEvents = events;
|
|
@@ -28448,13 +28956,13 @@ var DeviceHandler = class extends Handler {
|
|
|
28448
28956
|
const value = new Bag();
|
|
28449
28957
|
for (const key2 of ["id", "title", "body"]) value.setItem(key2, event[key2]);
|
|
28450
28958
|
if (event.kind === "action") value.setItem("actionId", event.actionId);
|
|
28451
|
-
node.staticValue.setItem(event.kind, value);
|
|
28959
|
+
node().staticValue.setItem(event.kind, value);
|
|
28452
28960
|
} catch (error) {
|
|
28453
|
-
node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28961
|
+
node().setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28454
28962
|
}
|
|
28455
28963
|
}, events.controller.signal);
|
|
28456
28964
|
}).then((stop) => {
|
|
28457
|
-
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);
|
|
28458
28966
|
return stop;
|
|
28459
28967
|
});
|
|
28460
28968
|
events.start.catch((error) => {
|
|
@@ -28462,27 +28970,28 @@ var DeviceHandler = class extends Handler {
|
|
|
28462
28970
|
events.controller.abort();
|
|
28463
28971
|
if (this.#notificationEvents === events) this.#notificationEvents = null;
|
|
28464
28972
|
if (!aborted) {
|
|
28465
|
-
node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28973
|
+
node().setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
|
|
28466
28974
|
}
|
|
28467
28975
|
});
|
|
28468
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28976
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
28469
28977
|
return events.start;
|
|
28470
28978
|
}
|
|
28471
|
-
#scheduleNotification(
|
|
28979
|
+
#scheduleNotification() {
|
|
28980
|
+
const node = () => this.#deviceNode("notifications");
|
|
28472
28981
|
if (this.#notificationRequest) return;
|
|
28473
28982
|
const request = new AbortController();
|
|
28474
28983
|
this.#notificationRequest = request;
|
|
28475
|
-
const value = node.staticValue.getItem("request");
|
|
28984
|
+
const value = node().staticValue.getItem("request");
|
|
28476
28985
|
const input = value instanceof Bag ? Object.fromEntries(["id", "title", "body", "delay"].map((key2) => [key2, value.getItem(key2)])) : null;
|
|
28477
|
-
node.staticValue.setItem("scheduled", null);
|
|
28478
|
-
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);
|
|
28479
28988
|
Promise.resolve().then(async () => {
|
|
28480
28989
|
if (request.signal.aborted) return;
|
|
28481
28990
|
this.requireCapability("notifications");
|
|
28482
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) {
|
|
28483
28992
|
throw new TypeError("Notification requires a positive 32-bit id, title, body and positive delay in seconds");
|
|
28484
28993
|
}
|
|
28485
|
-
await this.#startNotificationEvents(
|
|
28994
|
+
await this.#startNotificationEvents();
|
|
28486
28995
|
if (request.signal.aborted) return;
|
|
28487
28996
|
return this.provider.scheduleNotification(input, request.signal);
|
|
28488
28997
|
}).then((result) => {
|
|
@@ -28493,10 +29002,10 @@ var DeviceHandler = class extends Handler {
|
|
|
28493
29002
|
const scheduled = new Bag();
|
|
28494
29003
|
scheduled.setItem("id", result.id);
|
|
28495
29004
|
scheduled.setItem("at", result.at);
|
|
28496
|
-
node.staticValue.setItem("scheduled", scheduled);
|
|
28497
|
-
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);
|
|
28498
29007
|
}).catch((error) => {
|
|
28499
|
-
if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
|
|
29008
|
+
if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
|
|
28500
29009
|
}).finally(() => {
|
|
28501
29010
|
if (this.#notificationRequest === request) this.#notificationRequest = null;
|
|
28502
29011
|
});
|
|
@@ -28507,18 +29016,19 @@ var DeviceHandler = class extends Handler {
|
|
|
28507
29016
|
if (request) clearTimeout(request.timer);
|
|
28508
29017
|
return request;
|
|
28509
29018
|
}
|
|
28510
|
-
#acceptPushEvent(
|
|
29019
|
+
#acceptPushEvent(event) {
|
|
29020
|
+
const node = () => this.#deviceNode("push");
|
|
28511
29021
|
if (event.kind === "registration") {
|
|
28512
29022
|
if (typeof event.token !== "string" || !event.token) throw new TypeError("Invalid push registration token");
|
|
28513
29023
|
this.#finishPushRequest();
|
|
28514
29024
|
const value = new Bag();
|
|
28515
29025
|
value.setItem("token", event.token);
|
|
28516
|
-
node.staticValue.setItem("registration", value);
|
|
28517
|
-
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);
|
|
28518
29028
|
} else if (event.kind === "registrationError") {
|
|
28519
29029
|
this.#finishPushRequest();
|
|
28520
|
-
node.staticValue.setItem("registration", null);
|
|
28521
|
-
node.setAttr(failureAttributes(event.error), true, true, false);
|
|
29030
|
+
node().staticValue.setItem("registration", null);
|
|
29031
|
+
node().setAttr(failureAttributes(event.error), true, true, false);
|
|
28522
29032
|
} else {
|
|
28523
29033
|
if (!["received", "action"].includes(event.kind)) throw new TypeError("Invalid push event kind");
|
|
28524
29034
|
const fields = ["id", "title", "body", "messageId", "destination"];
|
|
@@ -28528,10 +29038,11 @@ var DeviceHandler = class extends Handler {
|
|
|
28528
29038
|
if (typeof event[key2] !== "string") throw new TypeError(`Invalid push event ${key2}`);
|
|
28529
29039
|
value.setItem(key2, event[key2]);
|
|
28530
29040
|
}
|
|
28531
|
-
node.staticValue.setItem(event.kind, value);
|
|
29041
|
+
node().staticValue.setItem(event.kind, value);
|
|
28532
29042
|
}
|
|
28533
29043
|
}
|
|
28534
|
-
#startPushEvents(
|
|
29044
|
+
#startPushEvents() {
|
|
29045
|
+
const node = () => this.#deviceNode("push");
|
|
28535
29046
|
if (this.#pushEvents) return this.#pushEvents.start;
|
|
28536
29047
|
const events = { controller: new AbortController() };
|
|
28537
29048
|
this.#pushEvents = events;
|
|
@@ -28541,25 +29052,26 @@ var DeviceHandler = class extends Handler {
|
|
|
28541
29052
|
return this.provider.startPushEvents((event) => {
|
|
28542
29053
|
if (events.controller.signal.aborted) return;
|
|
28543
29054
|
try {
|
|
28544
|
-
this.#acceptPushEvent(
|
|
29055
|
+
this.#acceptPushEvent(event);
|
|
28545
29056
|
} catch (error) {
|
|
28546
|
-
node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
29057
|
+
node().setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
|
|
28547
29058
|
}
|
|
28548
29059
|
}, events.controller.signal);
|
|
28549
29060
|
}).then((stop) => {
|
|
28550
|
-
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);
|
|
28551
29062
|
return stop;
|
|
28552
29063
|
});
|
|
28553
29064
|
events.start.catch((error) => {
|
|
28554
29065
|
const aborted = events.controller.signal.aborted;
|
|
28555
29066
|
events.controller.abort();
|
|
28556
29067
|
if (this.#pushEvents === events) this.#pushEvents = null;
|
|
28557
|
-
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);
|
|
28558
29069
|
});
|
|
28559
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
29070
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
28560
29071
|
return events.start;
|
|
28561
29072
|
}
|
|
28562
|
-
#registerPush(
|
|
29073
|
+
#registerPush() {
|
|
29074
|
+
const node = () => this.#deviceNode("push");
|
|
28563
29075
|
if (this.#pushRequest) return;
|
|
28564
29076
|
const request = { controller: new AbortController(), timer: null };
|
|
28565
29077
|
this.#pushRequest = request;
|
|
@@ -28567,24 +29079,25 @@ var DeviceHandler = class extends Handler {
|
|
|
28567
29079
|
if (this.disposed || this.#pushRequest !== request) return;
|
|
28568
29080
|
this.#finishPushRequest();
|
|
28569
29081
|
request.controller.abort();
|
|
28570
|
-
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);
|
|
28571
29083
|
}, 3e4);
|
|
28572
|
-
node.staticValue.setItem("registration", null);
|
|
28573
|
-
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);
|
|
28574
29086
|
Promise.resolve().then(async () => {
|
|
28575
29087
|
if (request.controller.signal.aborted) return;
|
|
28576
29088
|
this.requireCapability("push");
|
|
28577
|
-
await this.#startPushEvents(
|
|
29089
|
+
await this.#startPushEvents();
|
|
28578
29090
|
if (request.controller.signal.aborted || this.#pushRequest !== request) return;
|
|
28579
29091
|
await this.provider.registerPush(request.controller.signal);
|
|
28580
29092
|
}).catch((error) => {
|
|
28581
29093
|
if (this.disposed || this.#pushRequest !== request) return;
|
|
28582
29094
|
this.#finishPushRequest();
|
|
28583
29095
|
request.controller.abort();
|
|
28584
|
-
node.setAttr(failureAttributes(error), true, true, false);
|
|
29096
|
+
node().setAttr(failureAttributes(error), true, true, false);
|
|
28585
29097
|
});
|
|
28586
29098
|
}
|
|
28587
|
-
#startShortcutEvents(
|
|
29099
|
+
#startShortcutEvents() {
|
|
29100
|
+
const node = () => this.#deviceNode("shortcuts");
|
|
28588
29101
|
const events = { controller: new AbortController() };
|
|
28589
29102
|
this.#shortcutEvents = events;
|
|
28590
29103
|
events.start = Promise.resolve().then(() => {
|
|
@@ -28599,27 +29112,28 @@ var DeviceHandler = class extends Handler {
|
|
|
28599
29112
|
throw new TypeError(`Invalid shortcut request ${key2}`);
|
|
28600
29113
|
}
|
|
28601
29114
|
}
|
|
28602
|
-
if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
29115
|
+
if (node().staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
28603
29116
|
const value = new Bag();
|
|
28604
29117
|
value.setItem("id", request.id);
|
|
28605
29118
|
value.setItem("destination", request.destination);
|
|
28606
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28607
|
-
node.staticValue.setItem("request", value);
|
|
29119
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
29120
|
+
node().staticValue.setItem("request", value);
|
|
28608
29121
|
} catch (error2) {
|
|
28609
|
-
node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
29122
|
+
node().setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
28610
29123
|
}
|
|
28611
29124
|
}, events.controller.signal);
|
|
28612
29125
|
}).then((stop) => {
|
|
28613
|
-
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);
|
|
28614
29127
|
return stop;
|
|
28615
29128
|
});
|
|
28616
29129
|
events.start.catch((error) => {
|
|
28617
29130
|
const aborted = events.controller.signal.aborted;
|
|
28618
29131
|
events.controller.abort();
|
|
28619
|
-
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);
|
|
28620
29133
|
});
|
|
28621
29134
|
}
|
|
28622
|
-
#startLinkEvents(
|
|
29135
|
+
#startLinkEvents() {
|
|
29136
|
+
const node = () => this.#deviceNode("links");
|
|
28623
29137
|
const events = { controller: new AbortController() };
|
|
28624
29138
|
this.#linkEvents = events;
|
|
28625
29139
|
events.start = Promise.resolve().then(() => {
|
|
@@ -28634,24 +29148,24 @@ var DeviceHandler = class extends Handler {
|
|
|
28634
29148
|
throw new TypeError(`Invalid link request ${key2}`);
|
|
28635
29149
|
}
|
|
28636
29150
|
}
|
|
28637
|
-
if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
29151
|
+
if (node().staticValue.getItem("request")?.getItem("id") === request.id) return;
|
|
28638
29152
|
const value = new Bag();
|
|
28639
29153
|
value.setItem("id", request.id);
|
|
28640
29154
|
value.setItem("url", request.url);
|
|
28641
|
-
node.setAttr({ listenerError: null }, true, true, false);
|
|
28642
|
-
node.staticValue.setItem("request", value);
|
|
29155
|
+
node().setAttr({ listenerError: null }, true, true, false);
|
|
29156
|
+
node().staticValue.setItem("request", value);
|
|
28643
29157
|
} catch (error2) {
|
|
28644
|
-
node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
29158
|
+
node().setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
|
|
28645
29159
|
}
|
|
28646
29160
|
}, events.controller.signal);
|
|
28647
29161
|
}).then((stop) => {
|
|
28648
|
-
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);
|
|
28649
29163
|
return stop;
|
|
28650
29164
|
});
|
|
28651
29165
|
events.start.catch((error) => {
|
|
28652
29166
|
const aborted = events.controller.signal.aborted;
|
|
28653
29167
|
events.controller.abort();
|
|
28654
|
-
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);
|
|
28655
29169
|
});
|
|
28656
29170
|
}
|
|
28657
29171
|
requireCapability(name) {
|
|
@@ -28663,7 +29177,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28663
29177
|
const writing = resolver.writing;
|
|
28664
29178
|
resolver.writing = true;
|
|
28665
29179
|
try {
|
|
28666
|
-
resolver.
|
|
29180
|
+
this.#deviceNode(resolver.name).setAttr(attrs, true, true, false);
|
|
28667
29181
|
} finally {
|
|
28668
29182
|
resolver.writing = writing;
|
|
28669
29183
|
}
|
|
@@ -28689,7 +29203,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28689
29203
|
const writing = resolver.writing;
|
|
28690
29204
|
resolver.writing = true;
|
|
28691
29205
|
try {
|
|
28692
|
-
resolver.
|
|
29206
|
+
this.#deviceNode(resolver.name).setValue(bag, true, { status: "success", error: null }, true, false);
|
|
28693
29207
|
} finally {
|
|
28694
29208
|
resolver.writing = writing;
|
|
28695
29209
|
}
|
|
@@ -28699,8 +29213,8 @@ var DeviceHandler = class extends Handler {
|
|
|
28699
29213
|
this.attributes(resolver, failureAttributes(error));
|
|
28700
29214
|
}
|
|
28701
29215
|
reconcile() {
|
|
28702
|
-
const resolver = this.
|
|
28703
|
-
if (
|
|
29216
|
+
const resolver = () => this.resolver("location");
|
|
29217
|
+
if (this.#deviceNode("location").attr.enabled) {
|
|
28704
29218
|
if (this.monitor) return;
|
|
28705
29219
|
const monitor = { stop: null, controller: new AbortController() };
|
|
28706
29220
|
this.monitor = monitor;
|
|
@@ -28709,12 +29223,12 @@ var DeviceHandler = class extends Handler {
|
|
|
28709
29223
|
this.requireCapability("location");
|
|
28710
29224
|
return this.provider.startLocationUpdates((value, error) => {
|
|
28711
29225
|
if (this.disposed || this.monitor !== monitor) return;
|
|
28712
|
-
if (error) this.failure(resolver, error);
|
|
29226
|
+
if (error) this.failure(resolver(), error);
|
|
28713
29227
|
else {
|
|
28714
29228
|
try {
|
|
28715
|
-
this.accept(resolver, value);
|
|
29229
|
+
this.accept(resolver(), value);
|
|
28716
29230
|
} catch (failure2) {
|
|
28717
|
-
this.failure(resolver, failure2);
|
|
29231
|
+
this.failure(resolver(), failure2);
|
|
28718
29232
|
}
|
|
28719
29233
|
}
|
|
28720
29234
|
}, monitor.controller.signal);
|
|
@@ -28722,14 +29236,14 @@ var DeviceHandler = class extends Handler {
|
|
|
28722
29236
|
monitor.start.then((stop) => {
|
|
28723
29237
|
if (stop === null || this.disposed || this.monitor !== monitor) return;
|
|
28724
29238
|
monitor.stop = stop;
|
|
28725
|
-
this.attributes(resolver, { watching: true });
|
|
29239
|
+
this.attributes(resolver(), { watching: true });
|
|
28726
29240
|
}).catch((error) => {
|
|
28727
29241
|
if (!this.disposed && this.monitor === monitor) {
|
|
28728
|
-
this.attributes(resolver, { watching: false });
|
|
28729
|
-
this.failure(resolver, error);
|
|
29242
|
+
this.attributes(resolver(), { watching: false });
|
|
29243
|
+
this.failure(resolver(), error);
|
|
28730
29244
|
}
|
|
28731
29245
|
});
|
|
28732
|
-
this.attributes(resolver, { status: "pending", error: null });
|
|
29246
|
+
this.attributes(resolver(), { status: "pending", error: null });
|
|
28733
29247
|
} else if (this.monitor) {
|
|
28734
29248
|
const monitor = this.monitor;
|
|
28735
29249
|
this.monitor = null;
|
|
@@ -28739,14 +29253,14 @@ var DeviceHandler = class extends Handler {
|
|
|
28739
29253
|
if (this.retiring === monitor) this.retiring = null;
|
|
28740
29254
|
if (!this.disposed) {
|
|
28741
29255
|
const attrs = { watching: false };
|
|
28742
|
-
if (!this.monitor && !resolver.request &&
|
|
29256
|
+
if (!this.monitor && !resolver().request && this.#deviceNode("location").attr.status === "pending") {
|
|
28743
29257
|
Object.assign(attrs, { status: "cancelled", error: null });
|
|
28744
29258
|
}
|
|
28745
|
-
this.attributes(resolver, attrs);
|
|
29259
|
+
this.attributes(resolver(), attrs);
|
|
28746
29260
|
}
|
|
28747
29261
|
});
|
|
28748
29262
|
this.cleanup.catch((error) => {
|
|
28749
|
-
if (!this.disposed) this.failure(resolver, error);
|
|
29263
|
+
if (!this.disposed) this.failure(resolver(), error);
|
|
28750
29264
|
});
|
|
28751
29265
|
}
|
|
28752
29266
|
}
|
|
@@ -28755,9 +29269,9 @@ var DeviceHandler = class extends Handler {
|
|
|
28755
29269
|
this.assertLive();
|
|
28756
29270
|
if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== "string") throw new TypeError("Invalid database name");
|
|
28757
29271
|
if (this.#database) throw new Error("This page already owns a database connection");
|
|
28758
|
-
const node = this
|
|
29272
|
+
const node = () => this.#deviceNode("database");
|
|
28759
29273
|
const state = (status, error = null) => {
|
|
28760
|
-
if (!this.disposed) node.setAttr({ status, error }, true, true, false);
|
|
29274
|
+
if (!this.disposed) node().setAttr({ status, error }, true, true, false);
|
|
28761
29275
|
};
|
|
28762
29276
|
if (!this.provider.capabilities.includes("database")) {
|
|
28763
29277
|
const error = Object.assign(new Error("Native database unavailable"), { code: "UNAVAILABLE" });
|
|
@@ -28810,7 +29324,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28810
29324
|
};
|
|
28811
29325
|
} catch (error) {
|
|
28812
29326
|
if (this.#database === slot) this.#database = null;
|
|
28813
|
-
if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
|
|
29327
|
+
if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
|
|
28814
29328
|
throw error;
|
|
28815
29329
|
}
|
|
28816
29330
|
}
|
|
@@ -28860,7 +29374,8 @@ var DeviceHandler = class extends Handler {
|
|
|
28860
29374
|
const notificationEvents = this.#notificationEvents;
|
|
28861
29375
|
this.#notificationEvents = null;
|
|
28862
29376
|
notificationEvents?.controller.abort();
|
|
28863
|
-
this
|
|
29377
|
+
this.#registration?.close();
|
|
29378
|
+
this.#registration = null;
|
|
28864
29379
|
const monitor = this.monitor;
|
|
28865
29380
|
this.monitor = null;
|
|
28866
29381
|
monitor?.controller.abort();
|
|
@@ -28907,7 +29422,7 @@ var DeviceHandler = class extends Handler {
|
|
|
28907
29422
|
this.cleanup.catch((error) => {
|
|
28908
29423
|
this.cleanupError = error;
|
|
28909
29424
|
});
|
|
28910
|
-
for (const
|
|
29425
|
+
if (this.provider) for (const name of NAMES) this.#deviceNode(name).resolver.request = null;
|
|
28911
29426
|
}
|
|
28912
29427
|
};
|
|
28913
29428
|
|
|
@@ -29169,6 +29684,7 @@ var Gramlot = class {
|
|
|
29169
29684
|
}
|
|
29170
29685
|
} finally {
|
|
29171
29686
|
this._pageStore?.close();
|
|
29687
|
+
for (const name of [...this.rpc.connections.keys()]) this.rpc.unregisterConnection(name);
|
|
29172
29688
|
this._frames.dispose();
|
|
29173
29689
|
if (this.rpc.transport) {
|
|
29174
29690
|
try {
|
|
@@ -29474,23 +29990,38 @@ IndexPage.registerSource("index_panel");
|
|
|
29474
29990
|
function mountIndexPage(renderer, root, onSelection = () => {
|
|
29475
29991
|
}, prepareEntry = () => {
|
|
29476
29992
|
}, {
|
|
29477
|
-
state = root.
|
|
29993
|
+
state = root.absDatapath("."),
|
|
29478
29994
|
createEntry = null,
|
|
29479
29995
|
onLoad = () => {
|
|
29480
29996
|
}
|
|
29481
29997
|
} = {}) {
|
|
29482
|
-
|
|
29483
|
-
|
|
29484
|
-
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");
|
|
29485
30005
|
const builder = root.builder;
|
|
29486
30006
|
const entries3 = /* @__PURE__ */ new Map();
|
|
29487
30007
|
const context = { entries: entries3, disposed: false, selecting: false, sequence: 0, requested: null };
|
|
29488
|
-
|
|
29489
|
-
const
|
|
29490
|
-
|
|
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()) {
|
|
29491
30023
|
const { url, path, title } = record2.attr;
|
|
29492
|
-
const
|
|
29493
|
-
const entry = { url, path, title, pane, node: navigation.getNode(path), loading: false };
|
|
30024
|
+
const entry = createRecord({ url, path, title, paneLabel: record2.label, loading: false });
|
|
29494
30025
|
prepareEntry(entry);
|
|
29495
30026
|
entries3.set(url, entry);
|
|
29496
30027
|
context.sequence++;
|
|
@@ -29511,20 +30042,23 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29511
30042
|
if (context.disposed) return;
|
|
29512
30043
|
context.selecting = true;
|
|
29513
30044
|
try {
|
|
29514
|
-
|
|
29515
|
-
|
|
30045
|
+
write("active", entry.url);
|
|
30046
|
+
write("navigationSelection", entry.path);
|
|
29516
30047
|
onSelection(entries3, entry.url);
|
|
29517
30048
|
} finally {
|
|
29518
30049
|
context.selecting = false;
|
|
29519
30050
|
}
|
|
29520
30051
|
};
|
|
30052
|
+
const forget = (paneLabel) => {
|
|
30053
|
+
if (read("opened").getNode(paneLabel)) read("opened").popNode(paneLabel);
|
|
30054
|
+
};
|
|
29521
30055
|
function requestSelection(path) {
|
|
29522
30056
|
void select(path).catch((error) => {
|
|
29523
30057
|
if (!context.disposed) renderer.binding.reportError(error, "Page could not be opened");
|
|
29524
30058
|
});
|
|
29525
30059
|
}
|
|
29526
30060
|
async function select(path) {
|
|
29527
|
-
const node = navigation.getNode(path);
|
|
30061
|
+
const node = navigation().getNode(path);
|
|
29528
30062
|
if (!node) throw new Error(`Unknown index navigation path: ${path}`);
|
|
29529
30063
|
const url = node.attr.url;
|
|
29530
30064
|
if (url == null) return;
|
|
@@ -29536,16 +30070,18 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29536
30070
|
activate(entry);
|
|
29537
30071
|
return;
|
|
29538
30072
|
}
|
|
29539
|
-
while (tabs.value !== null && tabs.value.getNode(`page${context.sequence}`)) context.sequence++;
|
|
29540
|
-
const
|
|
29541
|
-
|
|
29542
|
-
|
|
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,
|
|
29543
30079
|
pageName: url,
|
|
29544
30080
|
height: "100%",
|
|
29545
30081
|
closable: true
|
|
29546
|
-
})
|
|
29547
|
-
const previous =
|
|
29548
|
-
entry = { url, path,
|
|
30082
|
+
});
|
|
30083
|
+
const previous = read("active");
|
|
30084
|
+
entry = createRecord({ url, path, title, paneLabel, loading: true });
|
|
29549
30085
|
entries3.set(url, entry);
|
|
29550
30086
|
try {
|
|
29551
30087
|
notifyLoad(entry, "loading");
|
|
@@ -29555,20 +30091,21 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29555
30091
|
if (createEntry) await createEntry(entry);
|
|
29556
30092
|
else {
|
|
29557
30093
|
const selection = new Bag();
|
|
29558
|
-
|
|
29559
|
-
|
|
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 });
|
|
29560
30097
|
if (!mounted) throw new Error("Panel loading was cancelled");
|
|
29561
30098
|
}
|
|
29562
30099
|
if (context.disposed || entries3.get(url) !== entry) return;
|
|
29563
|
-
opened.setItem(
|
|
30100
|
+
read("opened").setItem(paneLabel, null, { url, path: entry.path, title: entry.title });
|
|
29564
30101
|
prepareEntry(entry);
|
|
29565
30102
|
} catch (error) {
|
|
29566
30103
|
if (context.disposed || entries3.get(url) !== entry) return;
|
|
29567
30104
|
try {
|
|
29568
30105
|
renderer.binding.reportError(error, "Page could not be opened");
|
|
29569
30106
|
entries3.delete(url);
|
|
29570
|
-
|
|
29571
|
-
if (pane
|
|
30107
|
+
forget(paneLabel);
|
|
30108
|
+
if (entry.pane) tabs().value.popNode(paneLabel);
|
|
29572
30109
|
if (!context.disposed && context.requested === url) {
|
|
29573
30110
|
const restored = entries3.get(previous);
|
|
29574
30111
|
context.requested = restored?.url ?? null;
|
|
@@ -29576,8 +30113,8 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29576
30113
|
else {
|
|
29577
30114
|
context.selecting = true;
|
|
29578
30115
|
try {
|
|
29579
|
-
|
|
29580
|
-
|
|
30116
|
+
write("active", null);
|
|
30117
|
+
write("navigationSelection", null);
|
|
29581
30118
|
onSelection(entries3, null);
|
|
29582
30119
|
} finally {
|
|
29583
30120
|
context.selecting = false;
|
|
@@ -29594,65 +30131,69 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
29594
30131
|
if (!context.disposed && entries3.get(url) === entry && context.requested === url) activate(entry);
|
|
29595
30132
|
}
|
|
29596
30133
|
const sourceSubscription = `${root.getAttr("id")}-page-close`;
|
|
29597
|
-
|
|
29598
|
-
|
|
29599
|
-
|
|
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);
|
|
29600
30139
|
if (!entry) return;
|
|
29601
|
-
const { url,
|
|
30140
|
+
const { url, paneLabel } = entry;
|
|
29602
30141
|
if (context.disposed || renderer.disposed || entries3.get(url) !== entry) return;
|
|
29603
30142
|
entries3.delete(url);
|
|
29604
|
-
|
|
30143
|
+
forget(paneLabel);
|
|
29605
30144
|
try {
|
|
29606
|
-
if (
|
|
30145
|
+
if (read("active") === url) {
|
|
29607
30146
|
const next = [...entries3.values()].at(-1);
|
|
29608
30147
|
context.requested = next?.url ?? null;
|
|
29609
30148
|
if (next) activate(next);
|
|
29610
30149
|
else {
|
|
29611
30150
|
context.selecting = true;
|
|
29612
30151
|
try {
|
|
29613
|
-
|
|
29614
|
-
|
|
30152
|
+
write("active", null);
|
|
30153
|
+
write("navigationSelection", null);
|
|
29615
30154
|
onSelection(entries3, null);
|
|
29616
30155
|
} finally {
|
|
29617
30156
|
context.selecting = false;
|
|
29618
30157
|
}
|
|
29619
30158
|
}
|
|
29620
|
-
} else onSelection(entries3,
|
|
30159
|
+
} else onSelection(entries3, read("active"));
|
|
29621
30160
|
} finally {
|
|
29622
30161
|
finishLoad(entry, "cancelled");
|
|
29623
30162
|
}
|
|
29624
30163
|
} });
|
|
29625
|
-
const
|
|
29626
|
-
|
|
29627
|
-
|
|
29628
|
-
|
|
29629
|
-
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");
|
|
29630
30169
|
if (path !== null) requestSelection(path);
|
|
29631
|
-
}
|
|
29632
|
-
|
|
30170
|
+
} } }),
|
|
30171
|
+
router.register({ path: `${state}.active`, recipient: { receive: () => {
|
|
30172
|
+
if (context.selecting || context.disposed) return;
|
|
30173
|
+
const entry = entries3.get(read("active"));
|
|
29633
30174
|
if (entry) {
|
|
29634
30175
|
context.requested = entry.url;
|
|
29635
30176
|
activate(entry);
|
|
29636
30177
|
}
|
|
29637
|
-
}
|
|
29638
|
-
|
|
30178
|
+
} } })
|
|
30179
|
+
];
|
|
29639
30180
|
const dispose = () => {
|
|
29640
30181
|
if (context.disposed) return;
|
|
29641
30182
|
context.disposed = true;
|
|
29642
|
-
|
|
29643
|
-
|
|
30183
|
+
for (const registration of registrations2) registration.close();
|
|
30184
|
+
source.unsubscribe(sourceSubscription, { any: true });
|
|
29644
30185
|
for (const entry of entries3.values()) if (entry.loading) {
|
|
29645
|
-
if (entry.pane
|
|
30186
|
+
if (entry.pane) tabs().value.popNode(entry.paneLabel);
|
|
29646
30187
|
finishLoad(entry, "cancelled");
|
|
29647
30188
|
}
|
|
29648
30189
|
entries3.clear();
|
|
29649
|
-
if (root.indexContext === context) delete root.indexContext;
|
|
30190
|
+
if (root._internal.indexContext === context) delete root._internal.indexContext;
|
|
29650
30191
|
};
|
|
29651
30192
|
context.dispose = dispose;
|
|
29652
30193
|
renderer.onDispose(root, dispose);
|
|
29653
|
-
const active = entries3.get(
|
|
30194
|
+
const active = entries3.get(read("active"));
|
|
29654
30195
|
if (active) activate(active);
|
|
29655
|
-
else if (
|
|
30196
|
+
else if (read("navigationSelection") !== null) requestSelection(read("navigationSelection"));
|
|
29656
30197
|
return context;
|
|
29657
30198
|
}
|
|
29658
30199
|
var IndexLogic = class {
|
|
@@ -29825,11 +30366,11 @@ var FileSystemLogic = class {
|
|
|
29825
30366
|
fileSystemMount(node) {
|
|
29826
30367
|
const scope = node.parentNode;
|
|
29827
30368
|
const controller = new FileSystemController(this.page, scope);
|
|
29828
|
-
|
|
30369
|
+
scope._internal.fileSystemController = controller;
|
|
29829
30370
|
this.page.src.renderer.onDispose(scope, () => controller.dispose());
|
|
29830
30371
|
}
|
|
29831
30372
|
fileSystemOpen(node, { root }) {
|
|
29832
|
-
if (root) return node.parentNode.fileSystemController.open(root);
|
|
30373
|
+
if (root) return node.parentNode._internal.fileSystemController.open(root);
|
|
29833
30374
|
}
|
|
29834
30375
|
};
|
|
29835
30376
|
function fileSystemTree(parent, { datapath, ...attributes }) {
|
|
@@ -29855,6 +30396,7 @@ function fileSystemTree(parent, { datapath, ...attributes }) {
|
|
|
29855
30396
|
// src/ide-documents.js
|
|
29856
30397
|
var documentKey = (root, path) => "d_" + [...new TextEncoder().encode(JSON.stringify([root, path]))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
29857
30398
|
var IdeDocuments = class {
|
|
30399
|
+
#registrations = /* @__PURE__ */ new Map();
|
|
29858
30400
|
constructor(gramlot, source) {
|
|
29859
30401
|
this.gramlot = gramlot;
|
|
29860
30402
|
this.source = source;
|
|
@@ -29867,6 +30409,18 @@ var IdeDocuments = class {
|
|
|
29867
30409
|
get documents() {
|
|
29868
30410
|
return this.state.getItem("documents");
|
|
29869
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
|
+
}
|
|
29870
30424
|
async open(root, path) {
|
|
29871
30425
|
if (!/\.(?:py|js|mjs|ts|json|html|css|xml|md|markdown|sql|typ|txt|png|jpg|jpeg|webp)$/i.test(path)) return null;
|
|
29872
30426
|
const key2 = documentKey(root, path);
|
|
@@ -29879,12 +30433,9 @@ var IdeDocuments = class {
|
|
|
29879
30433
|
const document = new Bag();
|
|
29880
30434
|
const content = result.language === "image" ? result.content.toTytx() : result.content;
|
|
29881
30435
|
for (const [name, value] of Object.entries({ ...result, content, root, saved: content, busy: false })) document.setItem(name, value);
|
|
29882
|
-
if (result.language === "image")
|
|
29883
|
-
const annotations = result.content;
|
|
29884
|
-
document.setItem("annotations", annotations);
|
|
29885
|
-
annotations.subscribe("ide-annotations", { any: () => document.setItem("content", annotations.toTytx()) });
|
|
29886
|
-
}
|
|
30436
|
+
if (result.language === "image") document.setItem("annotations", result.content);
|
|
29887
30437
|
this.documents.setItem(key2, document);
|
|
30438
|
+
if (result.language === "image") this.#observeAnnotations(key2);
|
|
29888
30439
|
return key2;
|
|
29889
30440
|
}).finally(() => this.pending.delete(key2));
|
|
29890
30441
|
this.pending.set(key2, { request, promise });
|
|
@@ -29925,16 +30476,17 @@ var IdeDocuments = class {
|
|
|
29925
30476
|
{ signal: request.signal }
|
|
29926
30477
|
).then((result) => {
|
|
29927
30478
|
if (this.disposed || request.signal.aborted) return false;
|
|
29928
|
-
|
|
29929
|
-
|
|
29930
|
-
|
|
29931
|
-
|
|
29932
|
-
|
|
29933
|
-
|
|
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);
|
|
29934
30486
|
return true;
|
|
29935
30487
|
}).finally(() => {
|
|
29936
30488
|
this.pending.delete(key2);
|
|
29937
|
-
if (!this.disposed)
|
|
30489
|
+
if (!this.disposed) this.documents.getItem(key2).setItem("busy", false);
|
|
29938
30490
|
});
|
|
29939
30491
|
this.pending.set(key2, { request, promise });
|
|
29940
30492
|
return promise;
|
|
@@ -29962,19 +30514,22 @@ var IdeDocuments = class {
|
|
|
29962
30514
|
{ content },
|
|
29963
30515
|
{ signal: request.signal }
|
|
29964
30516
|
).then((result) => {
|
|
29965
|
-
if (this.disposed || request.signal.aborted
|
|
29966
|
-
|
|
29967
|
-
|
|
29968
|
-
|
|
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.");
|
|
29969
30523
|
return true;
|
|
29970
30524
|
}).catch((error) => {
|
|
29971
|
-
if (!this.disposed && !request.signal.aborted)
|
|
30525
|
+
if (!this.disposed && !request.signal.aborted) this.documents.getItem(key2).setItem("renderStatus", error.message);
|
|
29972
30526
|
return false;
|
|
29973
30527
|
}).finally(() => {
|
|
29974
30528
|
this.pending.delete(key2);
|
|
29975
30529
|
if (!this.disposed) {
|
|
29976
|
-
|
|
29977
|
-
|
|
30530
|
+
const doc2 = this.documents.getItem(key2);
|
|
30531
|
+
doc2.setItem("rendering", false);
|
|
30532
|
+
doc2.setItem("busy", false);
|
|
29978
30533
|
}
|
|
29979
30534
|
});
|
|
29980
30535
|
this.pending.set(key2, { request, promise });
|
|
@@ -29999,12 +30554,13 @@ var IdeDocuments = class {
|
|
|
29999
30554
|
...creating ? {} : { revision: doc.getItem("revision") }
|
|
30000
30555
|
}, { signal: request.signal }).then((result) => {
|
|
30001
30556
|
if (this.disposed || request.signal.aborted) return false;
|
|
30002
|
-
|
|
30003
|
-
|
|
30557
|
+
const doc2 = this.documents.getItem(key2);
|
|
30558
|
+
doc2.setItem("revision", result.revision);
|
|
30559
|
+
doc2.setItem("saved", content);
|
|
30004
30560
|
return true;
|
|
30005
30561
|
}).finally(() => {
|
|
30006
30562
|
this.pending.delete(key2);
|
|
30007
|
-
if (!this.disposed)
|
|
30563
|
+
if (!this.disposed) this.documents.getItem(key2).setItem("busy", false);
|
|
30008
30564
|
});
|
|
30009
30565
|
this.pending.set(key2, { request, promise });
|
|
30010
30566
|
return promise;
|
|
@@ -30024,6 +30580,8 @@ var IdeDocuments = class {
|
|
|
30024
30580
|
}
|
|
30025
30581
|
close(key2, discard = false) {
|
|
30026
30582
|
if (!this.canClose(key2, discard)) return false;
|
|
30583
|
+
this.#registrations.get(key2)?.close();
|
|
30584
|
+
this.#registrations.delete(key2);
|
|
30027
30585
|
this.documents.popNode(key2);
|
|
30028
30586
|
if (this.state.getItem("active") === key2) this.state.setItem("active", this.documents.getNodes()[0]?.label ?? null);
|
|
30029
30587
|
return true;
|
|
@@ -30031,6 +30589,8 @@ var IdeDocuments = class {
|
|
|
30031
30589
|
dispose() {
|
|
30032
30590
|
this.disposed = true;
|
|
30033
30591
|
for (const { request } of this.pending.values()) request.abort();
|
|
30592
|
+
for (const registration of this.#registrations.values()) registration.close();
|
|
30593
|
+
this.#registrations.clear();
|
|
30034
30594
|
}
|
|
30035
30595
|
};
|
|
30036
30596
|
var RecentWorkspaces = class {
|
|
@@ -30059,7 +30619,7 @@ var RecentWorkspaces = class {
|
|
|
30059
30619
|
// src/ide-runtime.js
|
|
30060
30620
|
function ideContext(node) {
|
|
30061
30621
|
for (let scope = node; scope; scope = scope.parentNode) {
|
|
30062
|
-
const context = scope.ideContext;
|
|
30622
|
+
const context = scope._internal.ideContext;
|
|
30063
30623
|
if (context) return context;
|
|
30064
30624
|
}
|
|
30065
30625
|
throw new Error("IDE operation requires a node inside a mounted IDE");
|
|
@@ -30080,41 +30640,43 @@ var IdeLogic = class {
|
|
|
30080
30640
|
editorPrefix: `ide_${randomId()}`,
|
|
30081
30641
|
recent: new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage)
|
|
30082
30642
|
};
|
|
30083
|
-
|
|
30643
|
+
scope._internal.ideContext = context;
|
|
30084
30644
|
const { documents, recent } = context;
|
|
30085
|
-
const state = scope.getRelativeData(".");
|
|
30645
|
+
const state = () => scope.getRelativeData(".");
|
|
30086
30646
|
const roots = recent.read();
|
|
30087
|
-
state.setItem("recent", recent.choices(roots));
|
|
30088
|
-
state.setItem("workspace", roots[0] ?? "");
|
|
30089
|
-
const
|
|
30090
|
-
|
|
30091
|
-
|
|
30092
|
-
|
|
30093
|
-
|
|
30094
|
-
state.
|
|
30095
|
-
state.setItem("
|
|
30096
|
-
|
|
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");
|
|
30097
30661
|
const path = browser.getItem("selectedPath");
|
|
30098
30662
|
const item = path === null ? null : browser.getItem("store").getNode(path);
|
|
30099
30663
|
if (item && !item.attr.is_directory) void this.ideOpenDocument(scope, browser.getItem("root"), item.attr.path);
|
|
30100
|
-
}
|
|
30101
|
-
|
|
30102
|
-
|
|
30103
|
-
|
|
30104
|
-
|
|
30105
|
-
|
|
30106
|
-
|
|
30107
|
-
|
|
30108
|
-
|
|
30109
|
-
|
|
30110
|
-
|
|
30111
|
-
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
|
+
}
|
|
30112
30675
|
}
|
|
30113
|
-
}
|
|
30114
|
-
|
|
30676
|
+
} } })
|
|
30677
|
+
];
|
|
30115
30678
|
this.page.src.renderer.onDispose(context.scope, () => {
|
|
30116
|
-
|
|
30117
|
-
documentBag.unsubscribe("ide-documents", { any: true });
|
|
30679
|
+
for (const registration of registrations2) registration.close();
|
|
30118
30680
|
documents.dispose();
|
|
30119
30681
|
});
|
|
30120
30682
|
}
|
|
@@ -30128,7 +30690,7 @@ var IdeLogic = class {
|
|
|
30128
30690
|
const context = ideContext(node), state = context.scope.getRelativeData(".");
|
|
30129
30691
|
if (state.getItem("browser.root") !== result.root) return;
|
|
30130
30692
|
state.setItem("upload.open", false);
|
|
30131
|
-
const controller = context.scope.value.getNode("frame.left.browser").fileSystemController;
|
|
30693
|
+
const controller = context.scope.value.getNode("frame.left.browser")._internal.fileSystemController;
|
|
30132
30694
|
if (controller.request) return;
|
|
30133
30695
|
const opened = await controller.open(result.root);
|
|
30134
30696
|
if (opened === result.root && !context.documents.disposed && state.getItem("browser.root") === result.root)
|
|
@@ -30352,7 +30914,7 @@ var IdeLogic = class {
|
|
|
30352
30914
|
if (!documents.disposed && saved) {
|
|
30353
30915
|
state.setItem("status", "File created.");
|
|
30354
30916
|
const browser = state.getItem("browser");
|
|
30355
|
-
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"));
|
|
30356
30918
|
}
|
|
30357
30919
|
} catch (error) {
|
|
30358
30920
|
if (!documents.disposed) state.setItem("status", error.message);
|
|
@@ -33787,22 +34349,20 @@ var BrowserCameraProvider = class {
|
|
|
33787
34349
|
};
|
|
33788
34350
|
|
|
33789
34351
|
// src/chat.js
|
|
33790
|
-
var projections = /* @__PURE__ */ new WeakMap();
|
|
33791
34352
|
var LABEL = /^m_[a-f0-9]+$/;
|
|
33792
34353
|
function chatRender(page, node, { messages }) {
|
|
33793
34354
|
if (!(messages instanceof Bag) || messages instanceof SourceBag) throw new TypeError("Chat messages require a Data Bag");
|
|
33794
34355
|
const target = node.parentNode;
|
|
33795
34356
|
const viewport = page.dom.getDomNode(target);
|
|
33796
34357
|
if (!viewport) return;
|
|
33797
|
-
let state =
|
|
34358
|
+
let state = target._internal.chatRows;
|
|
33798
34359
|
if (!state) {
|
|
33799
|
-
state = { rows:
|
|
33800
|
-
projections.set(target, state);
|
|
34360
|
+
state = target._internal.chatRows = { rows: {}, active: true };
|
|
33801
34361
|
page.src.renderer.onDispose(target, () => {
|
|
33802
34362
|
state.active = false;
|
|
33803
|
-
for (const label of state.rows
|
|
33804
|
-
state.rows
|
|
33805
|
-
|
|
34363
|
+
for (const label of Object.keys(state.rows)) target.getRelativeData(".messageData").popNode(label);
|
|
34364
|
+
state.rows = {};
|
|
34365
|
+
delete target._internal.chatRows;
|
|
33806
34366
|
});
|
|
33807
34367
|
}
|
|
33808
34368
|
const incoming = messages.getNodes();
|
|
@@ -33814,8 +34374,9 @@ function chatRender(page, node, { messages }) {
|
|
|
33814
34374
|
const follow = viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop < 48;
|
|
33815
34375
|
const plans = [];
|
|
33816
34376
|
for (const message of incoming) {
|
|
33817
|
-
const old = state.rows
|
|
33818
|
-
|
|
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;
|
|
33819
34380
|
const fragment = new GramlotBuilder();
|
|
33820
34381
|
const article = fragment.root.article({
|
|
33821
34382
|
node_label: message.label,
|
|
@@ -33831,19 +34392,20 @@ function chatRender(page, node, { messages }) {
|
|
|
33831
34392
|
}
|
|
33832
34393
|
const prepared = page.src.prepareSource(fragment.source);
|
|
33833
34394
|
page.src.renderer.validateCandidate(prepared);
|
|
33834
|
-
plans.push({ message, old, child: prepared.getNode(message.label) });
|
|
34395
|
+
plans.push({ message, old, content, child: prepared.getNode(message.label) });
|
|
33835
34396
|
}
|
|
33836
34397
|
const labels = new Set(incoming.map((message) => message.label));
|
|
33837
|
-
for (const
|
|
34398
|
+
for (const label of Object.keys(state.rows)) if (!labels.has(label)) {
|
|
33838
34399
|
target.value.popNode(label);
|
|
33839
34400
|
target.getRelativeData(".messageData").popNode(label);
|
|
33840
|
-
state.rows
|
|
34401
|
+
delete state.rows[label];
|
|
33841
34402
|
}
|
|
33842
|
-
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) : ">";
|
|
33843
34405
|
if (old) target.value.popNode(message.label);
|
|
33844
34406
|
if (!old) target.setRelativeData(".messageData." + message.label, new Bag());
|
|
33845
|
-
page.src.builder.setChild(target.value, child.nodeTag, child.value, { ...child.attr, node_label: message.label });
|
|
33846
|
-
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 };
|
|
33847
34409
|
}
|
|
33848
34410
|
if (follow) queueMicrotask(() => {
|
|
33849
34411
|
if (state.active) viewport.scrollTop = viewport.scrollHeight;
|
|
@@ -33874,13 +34436,13 @@ function chatCompleted(page, node, { response }) {
|
|
|
33874
34436
|
node.SET(".pending", false);
|
|
33875
34437
|
node.SET(".error", response.getItem("error"));
|
|
33876
34438
|
}
|
|
33877
|
-
var
|
|
34439
|
+
var COMPOSER_LAYOUT = /* @__PURE__ */ Symbol("chat composer layout");
|
|
33878
34440
|
function chatResize(page, node) {
|
|
33879
34441
|
const source = node.parentNode;
|
|
33880
|
-
|
|
34442
|
+
const body = page.dom.getDomNode(source);
|
|
34443
|
+
if (!body) return;
|
|
34444
|
+
let layout = body[COMPOSER_LAYOUT];
|
|
33881
34445
|
if (!layout) {
|
|
33882
|
-
const body = page.dom.getDomNode(source);
|
|
33883
|
-
if (!body) return;
|
|
33884
34446
|
const composer = body.closest("[data-chat-composer]");
|
|
33885
34447
|
const editor = body.querySelector("textarea");
|
|
33886
34448
|
const top = composer.querySelector("[data-chat-top]");
|
|
@@ -33908,10 +34470,9 @@ function chatResize(page, node) {
|
|
|
33908
34470
|
active = false;
|
|
33909
34471
|
observer.disconnect();
|
|
33910
34472
|
if (frame) win.cancelAnimationFrame(frame);
|
|
33911
|
-
|
|
34473
|
+
delete body[COMPOSER_LAYOUT];
|
|
33912
34474
|
});
|
|
33913
|
-
layout = { schedule };
|
|
33914
|
-
composerLayouts.set(source, layout);
|
|
34475
|
+
layout = body[COMPOSER_LAYOUT] = { schedule };
|
|
33915
34476
|
}
|
|
33916
34477
|
layout.schedule();
|
|
33917
34478
|
}
|
|
@@ -34015,7 +34576,6 @@ function chatRenderAttachments(page, node, { attachments }) {
|
|
|
34015
34576
|
var VisualEditorCanvas = class {
|
|
34016
34577
|
constructor({ app, editor, design }) {
|
|
34017
34578
|
this.renderer = app.src.renderer;
|
|
34018
|
-
this.design = design;
|
|
34019
34579
|
const presentation = this.renderer.records.get(design).presentation;
|
|
34020
34580
|
this.frame = presentation.ownerDocument.createElement("iframe");
|
|
34021
34581
|
this.frame.title = "Page canvas";
|
|
@@ -34093,7 +34653,8 @@ function parseScalar(type, text3) {
|
|
|
34093
34653
|
// src/source-picker.js
|
|
34094
34654
|
var SourcePicker = class {
|
|
34095
34655
|
#renderer;
|
|
34096
|
-
#
|
|
34656
|
+
#source;
|
|
34657
|
+
#path;
|
|
34097
34658
|
#canvas;
|
|
34098
34659
|
#onSelect;
|
|
34099
34660
|
#observer;
|
|
@@ -34101,11 +34662,15 @@ var SourcePicker = class {
|
|
|
34101
34662
|
#highlighted = null;
|
|
34102
34663
|
#release = null;
|
|
34103
34664
|
#disposed = false;
|
|
34104
|
-
|
|
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;
|
|
34105
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;
|
|
34106
34670
|
if (!canvas || canvas.nodeType !== 1) throw new TypeError("SourcePicker requires a mounted preview");
|
|
34107
34671
|
this.#renderer = renderer;
|
|
34108
|
-
this.#
|
|
34672
|
+
this.#source = source;
|
|
34673
|
+
this.#path = path;
|
|
34109
34674
|
this.#canvas = canvas;
|
|
34110
34675
|
this.#onSelect = onSelect;
|
|
34111
34676
|
canvas.addEventListener("pointerdown", this, true);
|
|
@@ -34114,9 +34679,15 @@ var SourcePicker = class {
|
|
|
34114
34679
|
this.#observer.observe(canvas, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
|
|
34115
34680
|
this.#release = renderer.onDispose(root.parentNode, () => this.dispose());
|
|
34116
34681
|
}
|
|
34682
|
+
/** The preview root node now at the picker's address, or null. */
|
|
34683
|
+
#root() {
|
|
34684
|
+
return this.#source.getNode(this.#path);
|
|
34685
|
+
}
|
|
34117
34686
|
handleEvent(event) {
|
|
34118
34687
|
if (this.#disposed) return;
|
|
34119
|
-
const
|
|
34688
|
+
const root = this.#root();
|
|
34689
|
+
if (!root) return;
|
|
34690
|
+
const prefix = root.fullpath + ".";
|
|
34120
34691
|
const record2 = event.composedPath().map((element) => this.#renderer.elements.get(element)).find((item) => item?.node.fullpath.startsWith(prefix));
|
|
34121
34692
|
if (!record2) return;
|
|
34122
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));
|
|
@@ -34130,7 +34701,9 @@ var SourcePicker = class {
|
|
|
34130
34701
|
if (this.#disposed) return;
|
|
34131
34702
|
if (node === null) this.#selectedPath = null;
|
|
34132
34703
|
else {
|
|
34133
|
-
const
|
|
34704
|
+
const root = this.#root();
|
|
34705
|
+
if (!root) throw new TypeError("SourcePicker preview root is missing");
|
|
34706
|
+
const prefix = root.fullpath + ".";
|
|
34134
34707
|
if (!node.fullpath.startsWith(prefix)) throw new TypeError("Selected node must be inside the preview Source root");
|
|
34135
34708
|
this.#selectedPath = node.fullpath.slice(prefix.length);
|
|
34136
34709
|
}
|
|
@@ -34138,7 +34711,7 @@ var SourcePicker = class {
|
|
|
34138
34711
|
}
|
|
34139
34712
|
#paint() {
|
|
34140
34713
|
if (this.#disposed) return;
|
|
34141
|
-
const node = this.#selectedPath ? this.#root
|
|
34714
|
+
const node = this.#selectedPath ? this.#root()?.staticValue.getNode(this.#selectedPath) ?? null : null;
|
|
34142
34715
|
const element = node ? this.#renderer.records.get(node)?.presentation : null;
|
|
34143
34716
|
const next = element?.nodeType === 1 ? element : null;
|
|
34144
34717
|
if (this.#highlighted !== next) {
|
|
@@ -34232,8 +34805,6 @@ var specifications = (node, tag2, current = null) => {
|
|
|
34232
34805
|
...node._getMeta("gramlot_component")?.childParameters ?? {}
|
|
34233
34806
|
};
|
|
34234
34807
|
};
|
|
34235
|
-
var canvasSelections = /* @__PURE__ */ new WeakMap();
|
|
34236
|
-
var canvasDocuments = /* @__PURE__ */ new WeakMap();
|
|
34237
34808
|
var VisualEditorLogic = class {
|
|
34238
34809
|
chatRender(node, params) {
|
|
34239
34810
|
return chatRender(this.page, node, params);
|
|
@@ -34419,37 +34990,44 @@ var VisualEditorLogic = class {
|
|
|
34419
34990
|
node.SET(".sourceSearch", "");
|
|
34420
34991
|
node.SET(".selection", selected);
|
|
34421
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.
|
|
34422
34995
|
initializeCanvasSelection(node) {
|
|
34423
34996
|
const renderer = node.rootBuilder.binding.renderer;
|
|
34424
|
-
const
|
|
34425
|
-
const editor = visualEditorScope(node), css = editor.GET(".canvasCss");
|
|
34997
|
+
const editor = visualEditorScope(node), css = editor.GET(".canvasCss"), path = sourceRoot(editor);
|
|
34426
34998
|
if (css != null) this.applyCanvasCss(editor, css);
|
|
34427
|
-
const previous =
|
|
34999
|
+
const previous = editor._internal.canvasSelection;
|
|
34428
35000
|
previous?.dispose();
|
|
35001
|
+
const canvas = editor._internal.canvasDocument;
|
|
34429
35002
|
const picker = new SourcePicker({
|
|
34430
35003
|
renderer,
|
|
34431
|
-
|
|
34432
|
-
|
|
35004
|
+
source: editor.builder.source,
|
|
35005
|
+
path,
|
|
35006
|
+
...canvas ? { canvas: canvas.body } : {},
|
|
34433
35007
|
onSelect: (selected) => {
|
|
34434
|
-
|
|
34435
|
-
|
|
35008
|
+
const design = editor.builder.source.getNode(path);
|
|
35009
|
+
editor.SET(".sourceSearch", "");
|
|
35010
|
+
editor.SET(".selection", selected.fullpath.slice(design.fullpath.length + 1));
|
|
34436
35011
|
}
|
|
34437
35012
|
});
|
|
34438
|
-
|
|
34439
|
-
if (!previous) renderer.onDispose(
|
|
34440
|
-
|
|
34441
|
-
|
|
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;
|
|
34442
35017
|
});
|
|
34443
35018
|
this.highlightSelection(node);
|
|
34444
35019
|
}
|
|
34445
35020
|
applyCanvasCss(node, texts) {
|
|
34446
35021
|
if (!Array.isArray(texts) || texts.some((text3) => typeof text3 !== "string"))
|
|
34447
35022
|
throw new TypeError("canvas CSS must be a list of CSS texts");
|
|
34448
|
-
const editor = visualEditorScope(node)
|
|
34449
|
-
let canvas =
|
|
35023
|
+
const editor = visualEditorScope(node);
|
|
35024
|
+
let canvas = editor._internal.canvasDocument;
|
|
34450
35025
|
if (!canvas) {
|
|
34451
|
-
canvas =
|
|
34452
|
-
|
|
35026
|
+
canvas = editor._internal.canvasDocument = new VisualEditorCanvas({
|
|
35027
|
+
app: editor.rootBuilder.binding.gramlot,
|
|
35028
|
+
editor,
|
|
35029
|
+
design: editor.builder.source.getNode(sourceRoot(editor))
|
|
35030
|
+
});
|
|
34453
35031
|
}
|
|
34454
35032
|
canvas.setCss(texts);
|
|
34455
35033
|
}
|
|
@@ -34462,7 +35040,7 @@ var VisualEditorLogic = class {
|
|
|
34462
35040
|
highlightSelection(node) {
|
|
34463
35041
|
const design = node.builder.source.getNode(sourceRoot(node));
|
|
34464
35042
|
const path = node.GET(".selection");
|
|
34465
|
-
|
|
35043
|
+
visualEditorScope(node)._internal.canvasSelection?.select(path ? design.staticValue.getNode(path) : null);
|
|
34466
35044
|
}
|
|
34467
35045
|
clipboardShortcut(node, event) {
|
|
34468
35046
|
if (event.defaultPrevented || event.repeat || node.GET(".clipboardOpen") || node.GET(".insertionOpen") || node.GET(".uploadOpen")) return;
|