@gramlot/gramlot 0.2.15 → 0.2.16

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/gramlot.js CHANGED
@@ -21783,8 +21783,12 @@ var CODE_ATTRIBUTES = {
21783
21783
  dataFormula: ["formula", "_if", "_else"],
21784
21784
  dataController: ["script", "_if", "_else"],
21785
21785
  dataRpc: ["_if", "_else", "_onCalling", "_onResult", "_onError"],
21786
+ dataRemote: ["_if", "_else"],
21786
21787
  button: ["action"]
21787
21788
  };
21789
+ var REMOTE_CONTROLS = ["_cachedRemote", "_if", "_else", "_onRemote"];
21790
+ var REMOTE_CODE_ATTRIBUTES = ["_if", "_else", "_onRemote"];
21791
+ var REMOTE_NAME = /^[A-Za-z]\w*$/;
21788
21792
  function isExpression(value) {
21789
21793
  return typeof value === "string" && value.startsWith("==");
21790
21794
  }
@@ -21797,10 +21801,14 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
21797
21801
  * The inline code attributes of this node as `[name, text]`, under the names InlineCompiler uses:
21798
21802
  * `formula` of a dataFormula, `script` of a dataController, `_if`/`_else` of the three providers and the
21799
21803
  * `_onCalling`/`_onResult`/`_onError` of a dataRpc, `action` of a
21800
- * button, every `connect_on<event>`, every `==` attribute (canonical name) and a `==` node value (`''`).
21804
+ * button, `_if`/`_else`/`_onRemote` of a node whose `remote` is a string, every `connect_on<event>`,
21805
+ * every `==` attribute (canonical name) and a `==` node value (`''`).
21801
21806
  */
21802
21807
  codeAttributes() {
21803
- const own = CODE_ATTRIBUTES[this.nodeTag] ?? [];
21808
+ const own = [
21809
+ ...CODE_ATTRIBUTES[this.nodeTag] ?? [],
21810
+ ...typeof this.getAttr("remote") === "string" ? REMOTE_CODE_ATTRIBUTES : []
21811
+ ];
21804
21812
  const items = [];
21805
21813
  for (const [name, value] of Object.entries(this.getAttr() ?? {})) {
21806
21814
  if (typeof value === "string" && (own.includes(name) || name.startsWith("connect_on"))) items.push([name, value]);
@@ -21831,6 +21839,27 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
21831
21839
  activatedCode(name) {
21832
21840
  return this.#activatedCode?.get(name) ?? null;
21833
21841
  }
21842
+ /**
21843
+ * Declare the content of this element as the fragment `name` of a `@source` method: writes
21844
+ * `remote = name` and one `remote_<k> = v` per entry of `params` on this node; the control attributes
21845
+ * `_cachedRemote`, `_if`, `_else` and `_onRemote` are written as they are. Returns this node. A bad
21846
+ * name or another `_` parameter is a TypeError.
21847
+ */
21848
+ remote(name, params = {}) {
21849
+ if (typeof name !== "string" || !REMOTE_NAME.test(name)) {
21850
+ throw new TypeError(`${this.nodeTag} '${this.label}': remote name must match ${REMOTE_NAME.source}, not ${JSON.stringify(name)}`);
21851
+ }
21852
+ const invalid = Object.keys(params).find((key) => key.startsWith("_") && !REMOTE_CONTROLS.includes(key));
21853
+ if (invalid) {
21854
+ throw new TypeError(`${this.nodeTag} '${this.label}': remote parameter '${invalid}' is not accepted; the control attributes are ${REMOTE_CONTROLS.join(", ")}`);
21855
+ }
21856
+ const attributes = { remote: name };
21857
+ for (const [key, value] of Object.entries(params)) {
21858
+ attributes[REMOTE_CONTROLS.includes(key) ? key : `remote_${key}`] = value;
21859
+ }
21860
+ this.setAttr(attributes);
21861
+ return wrapSource(this);
21862
+ }
21834
21863
  /** Builder's pointerType, except that a string starting with `==` is not a pointer. */
21835
21864
  pointerType(v) {
21836
21865
  if (typeof v === "string" && v.startsWith("==")) return null;
@@ -22085,9 +22114,12 @@ var BINDING_ATTRIBUTES = /* @__PURE__ */ new Set([
22085
22114
  "_onBuilt",
22086
22115
  "_delay",
22087
22116
  "_timing",
22088
- "_userChanges"
22117
+ "_userChanges",
22118
+ "remote",
22119
+ "_cachedRemote",
22120
+ "_onRemote"
22089
22121
  ]);
22090
- var BINDING_ATTRIBUTE_PREFIXES = ["default_", "attr_", "fire_", "connect_on"];
22122
+ var BINDING_ATTRIBUTE_PREFIXES = ["default_", "attr_", "fire_", "connect_on", "remote_"];
22091
22123
  var NATIVE_ATTRIBUTES = {
22092
22124
  table: ["width", "border"],
22093
22125
  editor: ["height"],
@@ -22681,16 +22713,97 @@ var binding_default = {
22681
22713
  _meta: {
22682
22714
  data_element: true
22683
22715
  }
22716
+ },
22717
+ dataRemote: {
22718
+ doc: "Data node resolved by a server endpoint through gramlot.rpc, on first read and again when cacheTime expires.",
22719
+ sub_tags: "",
22720
+ parent_tags: null,
22721
+ inherits_from: null,
22722
+ ns: null,
22723
+ attributes: {
22724
+ parameters: [
22725
+ {
22726
+ name: "destination_path",
22727
+ kind: "positional_or_keyword",
22728
+ role: "attribute",
22729
+ annotation: {
22730
+ kind: "type",
22731
+ module: "builtins",
22732
+ name: "str"
22733
+ },
22734
+ has_default: false
22735
+ },
22736
+ {
22737
+ name: "method",
22738
+ kind: "positional_or_keyword",
22739
+ role: "attribute",
22740
+ annotation: {
22741
+ kind: "type",
22742
+ module: "builtins",
22743
+ name: "str"
22744
+ },
22745
+ has_default: false
22746
+ },
22747
+ {
22748
+ name: "cacheTime",
22749
+ kind: "positional_or_keyword",
22750
+ role: "attribute",
22751
+ annotation: {
22752
+ kind: "union",
22753
+ items: [
22754
+ {
22755
+ kind: "type",
22756
+ module: "builtins",
22757
+ name: "int"
22758
+ },
22759
+ {
22760
+ kind: "type",
22761
+ module: "builtins",
22762
+ name: "float"
22763
+ },
22764
+ {
22765
+ kind: "type",
22766
+ module: "builtins",
22767
+ name: "NoneType"
22768
+ }
22769
+ ]
22770
+ },
22771
+ has_default: true,
22772
+ default: null
22773
+ },
22774
+ {
22775
+ name: "params",
22776
+ kind: "var_keyword",
22777
+ role: "attribute",
22778
+ annotation: {
22779
+ kind: "any"
22780
+ },
22781
+ has_default: false
22782
+ }
22783
+ ],
22784
+ accepts_var_keyword: true,
22785
+ accepts_var_positional: false
22786
+ },
22787
+ node_label: null,
22788
+ collection_key: null,
22789
+ _meta: {
22790
+ data_element: true
22791
+ }
22684
22792
  }
22685
22793
  }
22686
22794
  };
22687
22795
 
22688
22796
  // src/builder/gramlot-builder.js
22689
22797
  var DATA_FORBIDDEN = "data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element";
22690
- var EXCLUDED_ELEMENTS = /* @__PURE__ */ new Set(["dataremote"]);
22691
- var EXCLUDED_ATTRIBUTES = /* @__PURE__ */ new Set(["serverpath", "dbenv", "shared_id", "remote", "_ask", "ask"]);
22798
+ var EXCLUDED_ELEMENTS = /* @__PURE__ */ new Set();
22799
+ var EXCLUDED_ATTRIBUTES = /* @__PURE__ */ new Set(["serverpath", "dbenv", "shared_id", "_ask", "ask"]);
22692
22800
  var EXCLUDED_ATTRIBUTE_PREFIXES = ["subscribe_", "selfsubscribe_", "formsubscribe_"];
22693
- var DATA_PATH_ATTRIBUTES = { dataSetter: "destination_path", dataFormula: "result_path", dataRpc: "result_path" };
22801
+ var DATA_PATH_ATTRIBUTES = {
22802
+ dataSetter: "destination_path",
22803
+ dataFormula: "result_path",
22804
+ dataRpc: "result_path",
22805
+ dataRemote: "destination_path"
22806
+ };
22694
22807
  var DATA_INLINE_ATTRIBUTES = { dataFormula: "formula", dataController: "script" };
22695
22808
  function dataElementError(tag2, attrs) {
22696
22809
  const pathName = DATA_PATH_ATTRIBUTES[tag2];
@@ -23950,7 +24063,7 @@ function requireInstallable(branch) {
23950
24063
  }
23951
24064
  }
23952
24065
  var PROVIDER_ATTRIBUTES = ["_init", "_onStart", "_onBuilt", "_delay", "_timing", "_userChanges"];
23953
- var PROVIDER_TAGS = /* @__PURE__ */ new Set(["dataFormula", "dataController", "dataRpc"]);
24066
+ var PROVIDER_TAGS = /* @__PURE__ */ new Set(["dataFormula", "dataController", "dataRpc", "dataRemote"]);
23954
24067
  var RPC_ATTRIBUTES = ["_onCalling", "_onResult", "_onError"];
23955
24068
  var LIFECYCLE_ATTRIBUTES = ["_init", "_onBuilt", "_onStart"];
23956
24069
  function requireProviderAttributes(node) {
@@ -23964,6 +24077,10 @@ function requireProviderAttributes(node) {
23964
24077
  if (expression) {
23965
24078
  throw new Error(`${node.nodeTag} '${node.label}': '${expression[0]}' is a == expression, not accepted on ${node.nodeTag}`);
23966
24079
  }
24080
+ const lifecycle = node.nodeTag === "dataRemote" ? LIFECYCLE_ATTRIBUTES.find(isSet) : null;
24081
+ if (lifecycle) {
24082
+ throw new Error(`dataRemote '${node.label}': '${lifecycle}' is not accepted on dataRemote, its resolver loads when the Data is read`);
24083
+ }
23967
24084
  for (const name2 of LIFECYCLE_ATTRIBUTES) {
23968
24085
  const value = node.getAttr(name2);
23969
24086
  if (value === null || value === void 0 || typeof value === "boolean" || typeof value === "number") continue;
@@ -23972,7 +24089,9 @@ function requireProviderAttributes(node) {
23972
24089
  return;
23973
24090
  }
23974
24091
  const name = PROVIDER_ATTRIBUTES.find(isSet);
23975
- if (name) throw new Error(`${node.nodeTag ?? "fragment"} '${node.label}': '${name}' is allowed only on dataFormula, dataController and dataRpc`);
24092
+ if (!name) return;
24093
+ const tags = LIFECYCLE_ATTRIBUTES.includes(name) ? "dataFormula, dataController and dataRpc" : "dataFormula, dataController, dataRpc and dataRemote";
24094
+ throw new Error(`${node.nodeTag ?? "fragment"} '${node.label}': '${name}' is allowed only on ${tags}`);
23976
24095
  }
23977
24096
  function branchNodes(branch) {
23978
24097
  if (branch instanceof SourceBag) return branch.getNodes().flatMap((node) => branchNodes(node));
@@ -23981,6 +24100,74 @@ function branchNodes(branch) {
23981
24100
  return nodes;
23982
24101
  }
23983
24102
 
24103
+ // src/binding/rpc-resolver.js
24104
+ var RpcResolver = class extends BagResolver {
24105
+ static classKwargs = { ...BagResolver.classKwargs, asBag: false };
24106
+ static internalParams = /* @__PURE__ */ new Set([...BagResolver.internalParams, "gramlot", "method", "params", "onError"]);
24107
+ constructor({ gramlot, method, params, cacheTime, onError }) {
24108
+ super({ cacheTime: cacheTime ?? -1 });
24109
+ this.gramlot = gramlot;
24110
+ this.method = method;
24111
+ this.params = params;
24112
+ this.onError = onError;
24113
+ this.controller = null;
24114
+ this.loading = null;
24115
+ this.loaded = false;
24116
+ this.writing = false;
24117
+ }
24118
+ /** The current value; a non-static read starts the load when the cache has expired. */
24119
+ resolve({ static: isStatic = false } = {}) {
24120
+ if (!isStatic && !this.loading && !this.writing && this.expired) this.refresh();
24121
+ return this.cachedValue;
24122
+ }
24123
+ /** Start a load and write its value on the node, with the Data event unless `cacheTime` is 0; returns `loading`. */
24124
+ refresh() {
24125
+ const settle = () => {
24126
+ if (this.loading !== loading) return;
24127
+ this.controller = null;
24128
+ this.loading = null;
24129
+ };
24130
+ const load = this.load();
24131
+ const { signal } = this.controller;
24132
+ const loading = load.then((value) => {
24133
+ settle();
24134
+ if (signal.aborted) throw signal.reason;
24135
+ this._lastUpdate = Date.now();
24136
+ this.loaded = true;
24137
+ this.writing = true;
24138
+ try {
24139
+ if (this._node) this._node.setValue(value, this.cacheTime !== 0);
24140
+ else this.cachedValue = value;
24141
+ } finally {
24142
+ this.writing = false;
24143
+ }
24144
+ return value;
24145
+ }, (error) => {
24146
+ settle();
24147
+ throw error;
24148
+ });
24149
+ this.loading = loading;
24150
+ loading.catch((error) => {
24151
+ if (error?.name !== "AbortError") this.onError(error);
24152
+ });
24153
+ return loading;
24154
+ }
24155
+ /** The call of the endpoint with the params given at construction; the read kwargs are not sent. */
24156
+ load() {
24157
+ const controller = new AbortController();
24158
+ const aborted = new Promise((_, reject) => {
24159
+ controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
24160
+ });
24161
+ const call = this.gramlot.rpc.call("data", this.method, this.params, { signal: controller.signal });
24162
+ this.controller = controller;
24163
+ return Promise.race([call, aborted]);
24164
+ }
24165
+ /** Cancel the pending load, if any. */
24166
+ abort() {
24167
+ this.controller?.abort();
24168
+ }
24169
+ };
24170
+
23984
24171
  // src/binding/providers.js
23985
24172
  var CONTROL_ATTRIBUTES = /* @__PURE__ */ new Set([
23986
24173
  "destination_path",
@@ -24000,7 +24187,8 @@ var CONTROL_ATTRIBUTES = /* @__PURE__ */ new Set([
24000
24187
  "timeout",
24001
24188
  "_onCalling",
24002
24189
  "_onResult",
24003
- "_onError"
24190
+ "_onError",
24191
+ "cacheTime"
24004
24192
  ]);
24005
24193
  var Provider = class {
24006
24194
  #binding;
@@ -24010,11 +24198,16 @@ var Provider = class {
24010
24198
  #cancelDelay = null;
24011
24199
  // The AbortController of the in-flight call of a `dataRpc`: a new call aborts it (latest wins).
24012
24200
  #rpcCall = null;
24201
+ // The RpcResolver a `dataRemote` installed and its absolute Data path.
24202
+ #installed = null;
24203
+ // The resolver removed last had loaded or was loading: the next one loads at once.
24204
+ #reload = false;
24013
24205
  constructor(binding) {
24014
24206
  this.#binding = binding;
24015
24207
  binding.track(() => {
24016
24208
  this.cancel();
24017
24209
  this.#closeRegistrations();
24210
+ this.#uninstall();
24018
24211
  });
24019
24212
  }
24020
24213
  get binding() {
@@ -24023,14 +24216,15 @@ var Provider = class {
24023
24216
  get node() {
24024
24217
  return this.binding.node;
24025
24218
  }
24026
- /** 'formula' | 'controller' | 'rpc'. */
24219
+ /** 'formula' | 'controller' | 'rpc' | 'remote'. */
24027
24220
  get kind() {
24028
- throw new Error("Provider.kind is defined by FormulaProvider, ControllerProvider and RpcProvider");
24221
+ throw new Error("Provider.kind is defined by FormulaProvider, ControllerProvider, RpcProvider and RemoteProvider");
24029
24222
  }
24030
24223
  /**
24031
24224
  * Step 4 of §5.1, and every rebinding: the `^` pointers are registered again from the current
24032
24225
  * context (a pointer on a null path is not registered, Q7), and `_timing` starts again from its
24033
- * current value. A numeric `_onStart` must be a finite number not below zero (P22).
24226
+ * current value. A numeric `_onStart` must be a finite number not below zero (P22). A `dataRemote`
24227
+ * then installs its resolver with the current arguments.
24034
24228
  */
24035
24229
  register() {
24036
24230
  const node = this.node;
@@ -24050,6 +24244,7 @@ var Provider = class {
24050
24244
  if (name === "_timing") this.#timingRegistration = registration;
24051
24245
  }
24052
24246
  this.#startTiming();
24247
+ if (this.kind === "remote") this.invoke({ kind: "install", change: null });
24053
24248
  }
24054
24249
  /**
24055
24250
  * Router recipient. The `_timing` pointer restarts the timer; any other change is a Data
@@ -24076,24 +24271,29 @@ var Provider = class {
24076
24271
  * the inline `formula`/`script`, compiled by the page's InlineCompiler, or the named `func`. An
24077
24272
  * error propagates to the caller (P12). A closed node runs nothing. The body of a `dataRpc` is the
24078
24273
  * call: `invoke` returns its promise, and a false `_if` runs `_else` as inline code without calling.
24274
+ * The body of a `dataRemote` is the installation of its resolver; a false `_if` removes it, the
24275
+ * Data node keeping its last value, and runs `_else` as inline code.
24079
24276
  */
24080
24277
  invoke(trigger) {
24081
24278
  if (this.binding.closed) return;
24082
24279
  const node = this.node;
24083
24280
  const formula = this.kind === "formula";
24084
24281
  const rpc = this.kind === "rpc";
24282
+ const remote = this.kind === "remote";
24085
24283
  const kwargs = this.readArguments(trigger);
24086
24284
  let [attr, body] = [formula ? "formula" : "script", node.getAttr(formula ? "formula" : "script")];
24087
24285
  const condition = node.getAttr("_if");
24088
24286
  if (condition && !this.#inline("_if", condition, `return (${condition})`, kwargs, false)) {
24287
+ if (remote) this.#uninstall();
24089
24288
  [attr, body] = ["_else", node.getAttr("_else")];
24090
24289
  if (!body) return;
24091
- if (rpc) {
24290
+ if (rpc || remote) {
24092
24291
  this.#inline(attr, body, body, kwargs, true);
24093
24292
  return;
24094
24293
  }
24095
24294
  }
24096
24295
  if (rpc) return this.#call(kwargs);
24296
+ if (remote) return this.#install(kwargs);
24097
24297
  const func = node.getAttr("func");
24098
24298
  let result;
24099
24299
  if (body) {
@@ -24232,6 +24432,47 @@ var Provider = class {
24232
24432
  if (node.getAttr("result_path") != null) node.setRelativeData(node.pathAttribute("result_path"), result);
24233
24433
  if (onResult) this.#inline("_onResult", onResult, onResult, { ...kwargs, result }, true);
24234
24434
  }
24435
+ /**
24436
+ * The body of a `dataRemote`: a new RpcResolver on the Data node at `destination_path`, with the
24437
+ * author arguments as params, in place of the previous one, so the next read loads again. When the
24438
+ * resolver removed last, by this call or by a false `_if`, had loaded or was loading, the new one
24439
+ * loads at once: its consumers receive the new value through the Data event without reading again.
24440
+ * A failed load is thrown again naming the node, as an unhandled rejection. A null path (Q7)
24441
+ * installs nothing.
24442
+ */
24443
+ #install(kwargs) {
24444
+ this.#uninstall();
24445
+ const reload = this.#reload;
24446
+ this.#reload = false;
24447
+ const node = this.node;
24448
+ const path = node.absDatapath(node.pathAttribute("destination_path"));
24449
+ if (path === null) return;
24450
+ const resolver = new RpcResolver({
24451
+ gramlot: this.binding.runtime.gramlot,
24452
+ method: this.#resolved("method"),
24453
+ params: authorArguments(kwargs),
24454
+ cacheTime: this.#resolved("cacheTime"),
24455
+ onError: (error) => {
24456
+ throw new Error(
24457
+ `${node.nodeTag} '${node.label}': dataRemote '${resolver.method}' failed: ${error.message}`,
24458
+ { cause: error }
24459
+ );
24460
+ }
24461
+ });
24462
+ this.binding.runtime.data.setResolver(path, resolver);
24463
+ this.#installed = { path, resolver };
24464
+ if (reload) resolver.refresh();
24465
+ }
24466
+ /** Remove the resolver this `dataRemote` installed, when it is still on its Data node, and abort its load. */
24467
+ #uninstall() {
24468
+ if (!this.#installed) return;
24469
+ const { path, resolver } = this.#installed;
24470
+ this.#installed = null;
24471
+ this.#reload = resolver.loaded || resolver.loading !== null;
24472
+ resolver.abort();
24473
+ const dataNode = this.binding.runtime.data.getNode(path);
24474
+ if (dataNode?.resolver === resolver) dataNode.resolver = null;
24475
+ }
24235
24476
  #closeRegistrations() {
24236
24477
  for (const registration of this.#registrations.splice(0)) registration.close();
24237
24478
  this.#timingRegistration = null;
@@ -24252,6 +24493,11 @@ var RpcProvider = class extends Provider {
24252
24493
  return "rpc";
24253
24494
  }
24254
24495
  };
24496
+ var RemoteProvider = class extends Provider {
24497
+ get kind() {
24498
+ return "remote";
24499
+ }
24500
+ };
24255
24501
  var TRIGGER_FIELDS = ["_node", "_triggerpars", "_reason"];
24256
24502
  var CLICK_FIELDS = ["_evt", "button_counter", "button_shift", "button_ctrl", "button_alt", "button_meta"];
24257
24503
  function authorArguments(kwargs) {
@@ -24462,8 +24708,80 @@ ${text}`, { cause: error });
24462
24708
  }
24463
24709
  }
24464
24710
 
24711
+ // src/binding/remote.js
24712
+ var RemoteBinding = class {
24713
+ #binding;
24714
+ // The parameters of the last call, compared by `_cachedRemote`.
24715
+ #lastParams = null;
24716
+ constructor(binding) {
24717
+ this.#binding = binding;
24718
+ }
24719
+ get binding() {
24720
+ return this.#binding;
24721
+ }
24722
+ get node() {
24723
+ return this.binding.node;
24724
+ }
24725
+ get closed() {
24726
+ return this.binding.closed;
24727
+ }
24728
+ /**
24729
+ * Request the fragment for the current parameters. Nothing happens before the node's `start` step,
24730
+ * on a closed node, without a name, or when `_if` or `_cachedRemote` stop the call; a false `_if`
24731
+ * also cancels the request in flight, so its fragment is not mounted after `_else`. A failure of the
24732
+ * request rejects with an error naming the node, its cause attached.
24733
+ */
24734
+ async update() {
24735
+ if (this.closed || !this.binding.hasStamp("start")) return;
24736
+ const node = this.node;
24737
+ const [, attrs] = node.builder.runtimeValues(node);
24738
+ const name = attrs.remote;
24739
+ if (!name) return;
24740
+ const params = {};
24741
+ for (const [key, value] of Object.entries(attrs)) {
24742
+ if (key.startsWith("remote_")) params[key.slice("remote_".length)] = value;
24743
+ }
24744
+ const condition = node.getAttr("_if");
24745
+ if (condition && !this.#inline("_if", condition, `return (${condition})`, params)) {
24746
+ this.binding.runtime.gramlot.rpc.remoteRequests.get(node)?.controller.abort();
24747
+ const otherwise = node.getAttr("_else");
24748
+ if (otherwise) this.#inline("_else", otherwise, otherwise, params);
24749
+ return;
24750
+ }
24751
+ if (attrs._cachedRemote && this.#lastParams && sameValue(params, this.#lastParams)) return;
24752
+ let mounted;
24753
+ try {
24754
+ mounted = await this.binding.runtime.gramlot.src.remoteSource(node, name, params);
24755
+ } catch (error) {
24756
+ throw new Error(`${node.nodeTag} '${node.label}': remote '${name}' failed: ${error.message}`, { cause: error });
24757
+ }
24758
+ if (mounted) this.#lastParams = params;
24759
+ const onRemote = node.getAttr("_onRemote");
24760
+ if (mounted && onRemote) this.#inline("_onRemote", onRemote, onRemote, params);
24761
+ }
24762
+ #inline(attr, code, source, params) {
24763
+ return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, Object.keys(params), source)(params);
24764
+ }
24765
+ };
24766
+ function sameValue(a, b) {
24767
+ if (Object.is(a, b)) return true;
24768
+ if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
24769
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, i) => sameValue(item, b[i]));
24770
+ if (!isPlain(a) || !isPlain(b)) return false;
24771
+ const keys = Object.keys(a);
24772
+ return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && sameValue(a[key], b[key]));
24773
+ }
24774
+ function isPlain(value) {
24775
+ return value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
24776
+ }
24777
+
24465
24778
  // src/binding/runtime.js
24466
- var PROVIDERS = { dataFormula: FormulaProvider, dataController: ControllerProvider, dataRpc: RpcProvider };
24779
+ var PROVIDERS = {
24780
+ dataFormula: FormulaProvider,
24781
+ dataController: ControllerProvider,
24782
+ dataRpc: RpcProvider,
24783
+ dataRemote: RemoteProvider
24784
+ };
24467
24785
  var CONTEXT_ATTRIBUTES = ["datapath", "_anchor", "node_id", "form", "formId"];
24468
24786
  var BindingRuntime = class {
24469
24787
  #gramlot;
@@ -24570,12 +24888,15 @@ var BindingRuntime = class {
24570
24888
  }
24571
24889
  /**
24572
24890
  * Redo the registrations of `node` and of its descendants (change of Data context), then
24573
- * project the branch again: the elements already built follow the new paths.
24891
+ * project the branch again: the elements already built follow the new paths, and a started
24892
+ * `remote` requests its fragment for the new context. Not in `rebind`: the fragment mounted by
24893
+ * `remoteSource` is a value event of the node itself, which rebinds it.
24574
24894
  */
24575
24895
  rebindBranch(node) {
24576
24896
  const nodes = this.#branchNodes(node);
24577
24897
  for (const each of nodes) this.bindingFor(each)?.rebind();
24578
24898
  for (const each of nodes) this.renderer.project(each);
24899
+ for (const each of nodes) this.bindingFor(each)?.remote?.update();
24579
24900
  }
24580
24901
  /**
24581
24902
  * Semantic work of one Source event, called inside the renderer FIFO (§5.2).
@@ -24718,11 +25039,12 @@ var BindingRuntime = class {
24718
25039
  }
24719
25040
  }
24720
25041
  }
24721
- /** The `_onStart` of a built node, once. */
25042
+ /** The `_onStart` of a built node, then the first request of its `remote`, once. */
24722
25043
  #start(binding) {
24723
25044
  if (binding.hasStamp("start")) return;
24724
25045
  binding.stamp("start");
24725
25046
  this.#lifecycle(binding, "start", "_onStart");
25047
+ binding.remote?.update();
24726
25048
  }
24727
25049
  /** Invoke the providers of `binding` for the lifecycle trigger `kind` when `attribute` is on; a number delays it. */
24728
25050
  #lifecycle(binding, kind, attribute) {
@@ -24791,6 +25113,9 @@ var NodeBinding = class {
24791
25113
  #registrations = [];
24792
25114
  #stamps = /* @__PURE__ */ new Set();
24793
25115
  #provider = null;
25116
+ #remote = null;
25117
+ // The registrations of `remote` and of the `remote_<k>` parameters: their changes request the fragment again.
25118
+ #remoteRegistrations = /* @__PURE__ */ new Set();
24794
25119
  // The clicks of a button, counted for its whole semantic life: a rebuild keeps them (P9, S12).
24795
25120
  #clickCount = 0;
24796
25121
  // The registration of the node's own variable datapath, read in the parent's context.
@@ -24812,10 +25137,14 @@ var NodeBinding = class {
24812
25137
  get registrations() {
24813
25138
  return [...this.#registrations];
24814
25139
  }
24815
- /** The Provider of a `dataFormula`, `dataController` or `dataRpc`, as a list of zero or one. */
25140
+ /** The Provider of a `dataFormula`, `dataController`, `dataRpc` or `dataRemote`, as a list of zero or one. */
24816
25141
  get providers() {
24817
25142
  return this.#provider ? [this.#provider] : [];
24818
25143
  }
25144
+ /** The RemoteBinding of a node whose `remote` attribute is a string, or null. */
25145
+ get remote() {
25146
+ return this.#remote;
25147
+ }
24819
25148
  /** The clicks counted by the node's ButtonBinding since the node entered the Source (P9). */
24820
25149
  get clickCount() {
24821
25150
  return this.#clickCount;
@@ -24837,11 +25166,13 @@ var NodeBinding = class {
24837
25166
  * pointer on a null path (Q7) is not registered. The `datapath` pointer is resolved in the
24838
25167
  * parent's context. A `dataSetter` registers nothing; a `dataFormula` or `dataController`
24839
25168
  * registers its `datapath` here and the rest through its Provider, created once (§5.1 step 4).
25169
+ * A node whose `remote` is a string gets its RemoteBinding, created once.
24840
25170
  */
24841
25171
  registerPointers() {
24842
25172
  const node = this.node;
24843
25173
  const dataElement = node._getMeta("data_element");
24844
25174
  if (dataElement && !PROVIDERS[node.nodeTag]) return;
25175
+ if (!dataElement && typeof node.getAttr("remote") === "string") this.#remote ??= new RemoteBinding(this);
24845
25176
  for (const [name, pointer] of node.pointers()) {
24846
25177
  if (dataElement && name !== "datapath") continue;
24847
25178
  const context = name === "datapath" ? node.parentNode : node;
@@ -24851,6 +25182,7 @@ var NodeBinding = class {
24851
25182
  const registration = this.runtime.router.register({ path, attr, recipient: this });
24852
25183
  this.#registrations.push(registration);
24853
25184
  if (name === "datapath") this.#datapathRegistration = registration;
25185
+ if (this.remote && (name === "remote" || name.startsWith("remote_"))) this.#remoteRegistrations.add(registration);
24854
25186
  }
24855
25187
  if (!dataElement) return;
24856
25188
  this.#provider ??= new PROVIDERS[node.nodeTag](this);
@@ -24861,10 +25193,17 @@ var NodeBinding = class {
24861
25193
  this.#closeRegistrations();
24862
25194
  this.registerPointers();
24863
25195
  }
24864
- /** Router recipient: the node's datapath rebinds its branch; any other registration projects the node. */
25196
+ /**
25197
+ * Router recipient: the node's datapath rebinds its branch; any other registration projects the node,
25198
+ * after a registration of `remote` or of a `remote_<k>` parameter requested the fragment again.
25199
+ */
24865
25200
  receive(change) {
24866
- if (change.registration === this.#datapathRegistration) this.runtime.rebindBranch(this.node);
24867
- else this.runtime.renderer.project(this.node, change);
25201
+ if (change.registration === this.#datapathRegistration) {
25202
+ this.runtime.rebindBranch(this.node);
25203
+ return;
25204
+ }
25205
+ if (this.#remoteRegistrations.has(change.registration)) this.remote.update();
25206
+ this.runtime.renderer.project(this.node, change);
24868
25207
  }
24869
25208
  /** Own a semantic resource until close; the returned function releases it without running it. */
24870
25209
  track(disposer) {
@@ -24893,6 +25232,7 @@ var NodeBinding = class {
24893
25232
  #closeRegistrations() {
24894
25233
  for (const registration of this.#registrations.splice(0)) registration.close();
24895
25234
  this.#datapathRegistration = null;
25235
+ this.#remoteRegistrations.clear();
24896
25236
  }
24897
25237
  };
24898
25238
 
@@ -25789,7 +26129,7 @@ var SourceHandler = class extends Handler {
25789
26129
  * or a freeze keeps it, the removal of the target cancels it.
25790
26130
  *
25791
26131
  * `@source` / `registerSource` declare the fragments this method requests (GC-230 §035); the
25792
- * declarative `remote` grammar attribute is not yet available.
26132
+ * `remote` attribute requests them declaratively (GC-095 §105).
25793
26133
  */
25794
26134
  async remoteSource(target, method, params = {}) {
25795
26135
  const rpc = this.gramlot.rpc;