@gramlot/gramlot 0.3.6 → 0.3.8

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
@@ -15353,7 +15353,7 @@ var VALUE = /* @__PURE__ */ Symbol("value");
15353
15353
  var META_ATTRS = /* @__PURE__ */ new Set([
15354
15354
  "_meta",
15355
15355
  "datapath",
15356
- "node_id",
15356
+ "nodeId",
15357
15357
  "ns",
15358
15358
  "form",
15359
15359
  "formId",
@@ -15480,7 +15480,7 @@ var SourceBagNode = class extends BagNode {
15480
15480
  /** Resolve a `#SYMBOL[.relpath]` path.
15481
15481
  * #FORM → nearest ancestor with formId set or form=true;
15482
15482
  * #ANCHOR → nearest ancestor with `_anchor` present;
15483
- * #<id> → node carrying that node_id. The anchor then resolves
15483
+ * #<id> → node carrying that nodeId. The anchor then resolves
15484
15484
  * `relpath` relatively (its own datapath chain is consulted). */
15485
15485
  _resolveSymbolicDatapath(path, raw) {
15486
15486
  const s = path.slice(1);
@@ -15497,7 +15497,7 @@ var SourceBagNode = class extends BagNode {
15497
15497
  if (!builder) {
15498
15498
  throw new Error(`#<id>: cannot resolve ${raw} on a node without builder`);
15499
15499
  }
15500
- anchor = builder.source.getNodeByAttr("node_id", symbol);
15500
+ anchor = builder.source.getNodeByAttr("nodeId", symbol);
15501
15501
  if (anchor === null || anchor === void 0) {
15502
15502
  throw new Error(`#<id>: cannot resolve ${raw}`);
15503
15503
  }
@@ -16030,7 +16030,7 @@ function validateElementValues(tag2, spec, value, attrs) {
16030
16030
  const supplied = { ...attrs };
16031
16031
  if (value !== null && value !== void 0) supplied.node_value = value;
16032
16032
  const known = new Set(signature.parameters.filter((p) => p.role === "attribute").map((p) => p.name));
16033
- const framework = /* @__PURE__ */ new Set(["node_label", "node_position", "node_id", "target_id", "datapath", "iterate", "store", "_tag", "_meta", "ns"]);
16033
+ const framework = /* @__PURE__ */ new Set(["node_label", "node_position", "nodeId", "target_id", "datapath", "iterate", "store", "_tag", "_meta", "ns"]);
16034
16034
  if (!signature.accepts_var_keyword) {
16035
16035
  for (const name of Object.keys(attrs)) if (!known.has(name) && !framework.has(name)) fail(tag2, `unknown attribute '${name}'`);
16036
16036
  }
@@ -16904,8 +16904,8 @@ var BuilderBase = class _BuilderBase {
16904
16904
  const branchBuilder = subbuilder || this;
16905
16905
  const branchBindings = value instanceof SourceBag ? value._builderBindingPlan(branchBuilder) : null;
16906
16906
  const rootBuilder = parentOverride?.rootBuilder || bag.root._builder || this;
16907
- if (attributes.node_id != null && rootBuilder.source.getNodeByAttr("node_id", attributes.node_id)) {
16908
- throw new Error(`Duplicate node_id '${attributes.node_id}'`);
16907
+ if (attributes.nodeId != null && rootBuilder.source.getNodeByAttr("nodeId", attributes.nodeId)) {
16908
+ throw new Error(`Duplicate nodeId '${attributes.nodeId}'`);
16909
16909
  }
16910
16910
  if (value instanceof SourceBag) {
16911
16911
  this._validateChildren(tag2, info, value.getNodes().map((node2) => node2.nodeTag), false);
@@ -17018,9 +17018,9 @@ var BuilderBase = class _BuilderBase {
17018
17018
  /** Source node carrying `nodeId` (per-builder id namespace), wrapped
17019
17019
  * so the grammar dispatch (`.li(...)`) works, like Python's __getattr__. */
17020
17020
  nodeById(nodeId) {
17021
- const node = this.source.getNodeByAttr("node_id", nodeId);
17021
+ const node = this.source.getNodeByAttr("nodeId", nodeId);
17022
17022
  if (node === null || node === void 0) {
17023
- throw new Error(`node_id not found: ${nodeId}`);
17023
+ throw new Error(`nodeId not found: ${nodeId}`);
17024
17024
  }
17025
17025
  return node.builder.wrapSource(node);
17026
17026
  }
@@ -22157,7 +22157,7 @@ function annotation2(parameter) {
22157
22157
  });
22158
22158
  return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
22159
22159
  }
22160
- function defineComponent({ name, tag: tag2, base, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, implementation }) {
22160
+ function defineComponent({ name, tag: tag2, base, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, dragSource = false, implementation }) {
22161
22161
  webcomponentCode({ code: tag2 });
22162
22162
  if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
22163
22163
  const effective = { ...base.parameters };
@@ -22177,10 +22177,12 @@ function defineComponent({ name, tag: tag2, base, mixins = [], parameters: param
22177
22177
  presentationDefaults: Object.freeze([...presentationDefaults]),
22178
22178
  dataScope,
22179
22179
  command,
22180
+ bagStore,
22180
22181
  mixins: Object.freeze([...mixins]),
22181
22182
  parameters: freeze(structuredClone(effective)),
22182
22183
  childParameters: freeze(structuredClone(childParameters)),
22183
22184
  sourceContext,
22185
+ dragSource,
22184
22186
  implementation
22185
22187
  });
22186
22188
  }
@@ -22239,7 +22241,9 @@ var ComponentCollection = class {
22239
22241
  dataScope: component.dataScope,
22240
22242
  command: component.command,
22241
22243
  ...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
22242
- ...component.sourceContext ? { sourceContext: true } : {}
22244
+ ...component.sourceContext ? { sourceContext: true } : {},
22245
+ ...component.dragSource ? { dragSource: true } : {},
22246
+ ...component.bagStore ? { bagStore: true } : {}
22243
22247
  } }
22244
22248
  }]))
22245
22249
  };
@@ -22962,7 +22966,18 @@ var BINDING_ATTRIBUTES = /* @__PURE__ */ new Set([
22962
22966
  "_cachedRemote",
22963
22967
  "_onRemote",
22964
22968
  "_onCalling",
22965
- "onClose"
22969
+ "onClose",
22970
+ "onDrag",
22971
+ "onDrop",
22972
+ "dropTargetCb",
22973
+ "onDragEnd",
22974
+ "dropTarget",
22975
+ "dropTypes",
22976
+ "dragTags",
22977
+ "dropTags",
22978
+ "effectAllowed",
22979
+ "dropEffect",
22980
+ "dragClass"
22966
22981
  ]);
22967
22982
  var BINDING_ATTRIBUTE_PREFIXES = ["default_", "attr_", "fire_", "connect_on", "subscribe_", "selfsubscribe_", "formsubscribe_", "remote_"];
22968
22983
  var NATIVE_ATTRIBUTES = {
@@ -23506,7 +23521,7 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
23506
23521
  _finalizeAbsPath(path, attr) {
23507
23522
  return path === null ? null : super._finalizeAbsPath(path, attr);
23508
23523
  }
23509
- /** Builder's symbolic resolution; `#<node_id>` reads the node_id map of the page runtime when there is one (R06). */
23524
+ /** Builder's symbolic resolution; `#<nodeId>` reads the nodeId map of the page runtime when there is one (R06). */
23510
23525
  _resolveSymbolicDatapath(path, raw) {
23511
23526
  const symbol = path.slice(1).split(".", 1)[0];
23512
23527
  if (symbol === "FORM" || symbol === "ANCHOR") return super._resolveSymbolicDatapath(path, raw);
@@ -24374,11 +24389,11 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
24374
24389
  evaluatePointerExpression(node, name, raw, expression, inputs) {
24375
24390
  return this.binding ? this.binding.inlineCompiler.compilePointerExpression(node, name, raw, expression.text)(inputs) : null;
24376
24391
  }
24377
- /** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
24392
+ /** Builder's nodeById; inside a Gramlot page it reads the nodeId map of the BindingRuntime (R06). */
24378
24393
  nodeById(nodeId) {
24379
24394
  if (!this.binding) return super.nodeById(nodeId);
24380
24395
  const node = this.binding.nodeIds.get(nodeId);
24381
- if (!node) throw new Error(`node_id not found: ${nodeId}`);
24396
+ if (!node) throw new Error(`nodeId not found: ${nodeId}`);
24382
24397
  return node.builder.wrapSource(node);
24383
24398
  }
24384
24399
  loadCollection(document) {
@@ -25137,8 +25152,9 @@ function domPropertyName(name) {
25137
25152
  return PROPERTY_NAMES.get(camel.toLowerCase()) ?? camel;
25138
25153
  }
25139
25154
  var HtmlElement = class {
25140
- constructor({ metadataAttributes = [], invokeScript = null } = {}) {
25155
+ constructor({ metadataAttributes = [], invokeScript = null, callLogic = null } = {}) {
25141
25156
  this.invokeScript = invokeScript;
25157
+ this.callLogic = callLogic;
25142
25158
  this.metadataAttributes = /* @__PURE__ */ new Set([...META_ATTRS, "_text", ...metadataAttributes]);
25143
25159
  }
25144
25160
  definition(node) {
@@ -25186,7 +25202,8 @@ var HtmlElement = class {
25186
25202
  if (meta.gramlot_component?.sourceContext) {
25187
25203
  element.setSourceContext({
25188
25204
  publish: (topic, payload) => node.publish(topic, payload),
25189
- writeParameter: (name, value) => this.writeParameter(node, name, value)
25205
+ writeParameter: (name, value) => this.writeParameter(node, name, value),
25206
+ callLogic: (name, keywords) => this.callLogic(node, name, keywords)
25190
25207
  });
25191
25208
  }
25192
25209
  const text = document.createTextNode(this.text(node));
@@ -25245,6 +25262,9 @@ var HtmlElement = class {
25245
25262
  });
25246
25263
  }
25247
25264
  if (this.definition(node).meta.gramlot_component) {
25265
+ if (this.definition(node).meta.gramlot_component.bagStore) {
25266
+ element.setStoreBag(node.getRelativeData(node.getAttr("storepath")));
25267
+ }
25248
25268
  attrs = element.projectAttributes(attrs, adapt);
25249
25269
  }
25250
25270
  attrs = Object.fromEntries(sourceAttributeItems({ ...attrs, ...renderAttributes }));
@@ -25600,12 +25620,14 @@ var DataRegistration = class {
25600
25620
  #recipient;
25601
25621
  #order;
25602
25622
  #active = true;
25603
- constructor(router, { path, attr, recipient, order }) {
25623
+ #subtree;
25624
+ constructor(router, { path, attr, recipient, order, subtree = false }) {
25604
25625
  this.#router = router;
25605
25626
  this.#path = path;
25606
25627
  this.#attr = attr;
25607
25628
  this.#recipient = recipient;
25608
25629
  this.#order = order;
25630
+ this.#subtree = subtree;
25609
25631
  }
25610
25632
  get router() {
25611
25633
  return this.#router;
@@ -25619,6 +25641,10 @@ var DataRegistration = class {
25619
25641
  get recipient() {
25620
25642
  return this.#recipient;
25621
25643
  }
25644
+ /** Store registration: structural, value and attribute events throughout the subtree. */
25645
+ get subtree() {
25646
+ return this.#subtree;
25647
+ }
25622
25648
  get active() {
25623
25649
  return this.#active;
25624
25650
  }
@@ -25662,8 +25688,10 @@ var DataRouter = class {
25662
25688
  get size() {
25663
25689
  return this.#size;
25664
25690
  }
25665
- /** Register `recipient` on the absolute Data `path` (without `_root_`), optionally on its attribute `attr`. */
25666
- register({ path, attr = null, recipient }) {
25691
+ /** Register on an absolute Data path, optionally on an attribute.
25692
+ * `subtree` includes descendant attribute events for Bag-backed components.
25693
+ */
25694
+ register({ path, attr = null, recipient, subtree = false }) {
25667
25695
  if (typeof path !== "string" || path === "") throw new TypeError(`A Data registration requires a path: ${path}`);
25668
25696
  let route = this.#root;
25669
25697
  for (const segment of path.split(".")) {
@@ -25675,7 +25703,7 @@ var DataRouter = class {
25675
25703
  route = next;
25676
25704
  }
25677
25705
  this.#order += 1;
25678
- const registration = new DataRegistration(this, { path, attr, recipient, order: this.#order });
25706
+ const registration = new DataRegistration(this, { path, attr, recipient, order: this.#order, subtree });
25679
25707
  route.registrations.add(registration);
25680
25708
  this.#routes.set(registration, route);
25681
25709
  this.#size += 1;
@@ -25757,6 +25785,7 @@ var DataRouter = class {
25757
25785
  */
25758
25786
  #accepts(registration, level, event) {
25759
25787
  const { evt } = event;
25788
+ if (registration.subtree) return level !== "container" || evt !== "upd_attrs";
25760
25789
  if (registration.attr === null) {
25761
25790
  if (evt === "upd_attrs") return false;
25762
25791
  return !(level === "child" && event.fired);
@@ -25945,65 +25974,24 @@ function branchNodes(branch) {
25945
25974
  return nodes;
25946
25975
  }
25947
25976
 
25948
- // src/binding/rpc-resolver.js
25949
- var RpcResolver = class extends BagResolver {
25977
+ // src/binding/remote-resolver.js
25978
+ var RemoteResolver = class extends BagResolver {
25950
25979
  static classKwargs = { ...BagResolver.classKwargs, asBag: false };
25951
- static internalParams = /* @__PURE__ */ new Set([
25952
- ...BagResolver.internalParams,
25953
- "binding",
25954
- "method",
25955
- "params",
25956
- "onCalling",
25957
- "onError",
25958
- "sync"
25959
- ]);
25960
- constructor({ binding, method, params, cacheTime, onCalling = null, onError, sync = false }) {
25980
+ constructor({ cacheTime, onError }) {
25961
25981
  super({ cacheTime: cacheTime ?? -1 });
25962
- this.binding = binding;
25963
- this.sync = sync;
25964
- this.method = method;
25965
- this.params = params;
25966
- this.onCalling = onCalling;
25967
25982
  this.onError = onError;
25968
25983
  this.loading = null;
25969
25984
  this.loaded = false;
25970
25985
  this.writing = false;
25971
25986
  }
25972
- /**
25973
- * The current value. With `sync` an expired read calls the endpoint and returns its value (BagResolver
25974
- * `resolve`, then `load`); without, it starts the load and returns the current value. A static read, or
25975
- * a read during a load or its write, returns the current value.
25976
- */
25977
- resolve(options = {}) {
25978
- const { static: isStatic = false } = options;
25979
- if (isStatic || this.loading || this.writing) return this.cachedValue;
25980
- if (!this.sync) {
25981
- if (this.expired) this.refresh();
25982
- return this.cachedValue;
25983
- }
25984
- if (this.expired && !this.binding.node.requests.calling(this.onCalling)) return this.cachedValue;
25985
- return super.resolve(options);
25987
+ resolve({ static: isStatic = false } = {}) {
25988
+ if (!isStatic && !this.closed && !this.loading && !this.writing && this.expired) this.refresh();
25989
+ return this.cachedValue;
25986
25990
  }
25987
- /** The synchronous call of a `sync` read: BagResolver `resolve` stores the value it returns. */
25988
- load() {
25989
- let value;
25990
- try {
25991
- value = this.binding.callSync("data", this.method, this.params);
25992
- } catch (error) {
25993
- this.onError(error);
25994
- }
25995
- this.loaded = true;
25996
- return value;
25997
- }
25998
- /**
25999
- * Start a load and write its value on the node, with the Data event unless `cacheTime` is 0; returns
26000
- * `loading`, which settles with the written value, or undefined when nothing was written. A false
26001
- * `_onCalling` starts no load and returns null.
26002
- */
26003
25991
  refresh() {
26004
- const requests = this.binding.node.requests;
26005
- if (!requests.calling(this.onCalling)) return null;
26006
- const loading = requests.submit(this.method, this.params, (request) => this.#load(request));
25992
+ if (this.closed) return null;
25993
+ const loading = this.startLoad((request) => this.#load(request));
25994
+ if (loading === null) return null;
26007
25995
  const settle = () => {
26008
25996
  if (this.loading === loading) this.loading = null;
26009
25997
  };
@@ -26014,10 +26002,12 @@ var RpcResolver = class extends BagResolver {
26014
26002
  });
26015
26003
  return loading;
26016
26004
  }
26017
- /**
26018
- * The fingerprint of the parameters of a read without call kwargs, as `BagResolver.resolve` computes it:
26019
- * the kwargs of the resolver and the attributes of its node that are not internal.
26020
- */
26005
+ resolveSync(options) {
26006
+ return super.resolve(options);
26007
+ }
26008
+ prepareValue(value) {
26009
+ return value;
26010
+ }
26021
26011
  #fingerprint() {
26022
26012
  const kwargs = { ...this._kw };
26023
26013
  for (const [name, value] of Object.entries(this.node?.attr ?? {})) {
@@ -26025,13 +26015,12 @@ var RpcResolver = class extends BagResolver {
26025
26015
  }
26026
26016
  return this._computeEffectiveFingerprint(kwargs);
26027
26017
  }
26028
- /** The asynchronous call of the endpoint with the params given at construction; the read kwargs are not sent. */
26029
26018
  async #load(request) {
26030
- const binding = this.binding;
26031
- if (binding.closed) return void 0;
26019
+ if (this.closed) return void 0;
26032
26020
  const fingerprint = this.#fingerprint();
26033
- const value = await binding.call("data", request);
26034
- if (binding.closed || request.ignored) return void 0;
26021
+ const received = await this.loadAsync(request);
26022
+ if (this.closed || request.ignored) return void 0;
26023
+ const value = this.prepareValue(received);
26035
26024
  this._lastUpdate = Date.now();
26036
26025
  this._lastEffectiveFingerprint = fingerprint;
26037
26026
  this.loaded = true;
@@ -26046,6 +26035,46 @@ var RpcResolver = class extends BagResolver {
26046
26035
  }
26047
26036
  };
26048
26037
 
26038
+ // src/binding/rpc-resolver.js
26039
+ var RpcResolver = class extends RemoteResolver {
26040
+ static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "binding", "method", "params", "onCalling", "onError", "sync"]);
26041
+ constructor({ binding, method, params, cacheTime, onCalling = null, onError, sync = false }) {
26042
+ super({ cacheTime, onError });
26043
+ this.binding = binding;
26044
+ this.sync = sync;
26045
+ this.method = method;
26046
+ this.params = params;
26047
+ this.onCalling = onCalling;
26048
+ }
26049
+ get closed() {
26050
+ return this.binding.closed;
26051
+ }
26052
+ resolve(options = {}) {
26053
+ if (!this.sync) return super.resolve(options);
26054
+ if (options.static || this.loading || this.writing) return this.cachedValue;
26055
+ if (this.expired && !this.binding.node.requests.calling(this.onCalling)) return this.cachedValue;
26056
+ return super.resolveSync(options);
26057
+ }
26058
+ load() {
26059
+ let value;
26060
+ try {
26061
+ value = this.binding.callSync("data", this.method, this.params);
26062
+ } catch (error) {
26063
+ this.onError(error);
26064
+ }
26065
+ this.loaded = true;
26066
+ return value;
26067
+ }
26068
+ startLoad(perform) {
26069
+ const requests = this.binding.node.requests;
26070
+ if (!requests.calling(this.onCalling)) return null;
26071
+ return requests.submit(this.method, this.params, perform);
26072
+ }
26073
+ loadAsync(request) {
26074
+ return this.binding.call("data", request);
26075
+ }
26076
+ };
26077
+
26049
26078
  // src/binding/providers.js
26050
26079
  var CONTROL_ATTRIBUTES = /* @__PURE__ */ new Set([
26051
26080
  "destination_path",
@@ -26816,7 +26845,7 @@ var AskDialog = class {
26816
26845
  try {
26817
26846
  const builder = new GramlotBuilder();
26818
26847
  const dialog = builder.root.dialog({
26819
- node_id: id,
26848
+ nodeId: id,
26820
26849
  datapath: id,
26821
26850
  request: id,
26822
26851
  connect_oncancel: `${group}.cancel`,
@@ -26882,7 +26911,7 @@ var PROVIDERS = {
26882
26911
  dataRpc: RpcProvider,
26883
26912
  dataRemote: RemoteProvider
26884
26913
  };
26885
- var CONTEXT_ATTRIBUTES = ["datapath", "_anchor", "node_id", "form", "formId"];
26914
+ var CONTEXT_ATTRIBUTES = ["datapath", "_anchor", "nodeId", "form", "formId"];
26886
26915
  var BindingRuntime = class {
26887
26916
  #gramlot;
26888
26917
  #bindings = /* @__PURE__ */ new Map();
@@ -26947,7 +26976,7 @@ var BindingRuntime = class {
26947
26976
  get askDialog() {
26948
26977
  return this.#askDialog;
26949
26978
  }
26950
- /** `node_id → node` of the Source nodes with an open NodeBinding (R06). */
26979
+ /** `nodeId → node` of the Source nodes with an open NodeBinding (R06). */
26951
26980
  get nodeIds() {
26952
26981
  return this.#nodeIds;
26953
26982
  }
@@ -26988,7 +27017,7 @@ var BindingRuntime = class {
26988
27017
  const binding = this.bindingFor(node);
26989
27018
  if (binding) {
26990
27019
  this.#bindings.delete(node);
26991
- const nodeId = node.getAttr("node_id");
27020
+ const nodeId = node.getAttr("nodeId");
26992
27021
  if (this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
26993
27022
  try {
26994
27023
  binding.close();
@@ -27014,7 +27043,7 @@ var BindingRuntime = class {
27014
27043
  * Semantic work of one Source event, called inside the renderer FIFO (§5.2).
27015
27044
  *
27016
27045
  * The rows of the event matrix: opening and closing of the NodeBindings,
27017
- * the `node_id` map, the rebinding, and the installation of the `ins` and
27046
+ * the `nodeId` map, the rebinding, and the installation of the `ins` and
27018
27047
  * new-branch rows (§5.1 steps 2-5).
27019
27048
  *
27020
27049
  * A failing disposer does not block the rest of the event: the errors of the
@@ -27081,7 +27110,7 @@ var BindingRuntime = class {
27081
27110
  if (!binding.closed && binding.hasStamp("built")) this.#start(binding);
27082
27111
  }
27083
27112
  }
27084
- /** Close every NodeBinding, the `node_id` map and the Data subscription; a second call does nothing. */
27113
+ /** Close every NodeBinding, the `nodeId` map and the Data subscription; a second call does nothing. */
27085
27114
  dispose() {
27086
27115
  if (this.disposed) return;
27087
27116
  this.#disposed = true;
@@ -27099,8 +27128,8 @@ var BindingRuntime = class {
27099
27128
  if (errors.length) throw new AggregateError(errors, "Binding cleanup failed");
27100
27129
  }
27101
27130
  /**
27102
- * Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `node_id` map is
27103
- * complete, and a duplicate refused, before the first write or registration, so a `#<node_id>`
27131
+ * Steps 2-4 of §5.1 on `branch` (a SourceBagNode or a new SourceBag value). The `nodeId` map is
27132
+ * complete, and a duplicate refused, before the first write or registration, so a `#<nodeId>`
27104
27133
  * of the branch translates; then the installation (`dataSetter`s and defaults), then one
27105
27134
  * NodeBinding per node and the registrations, providers included. On an error the NodeBindings
27106
27135
  * opened here are closed and the map entries they brought are removed; the Data is not rolled
@@ -27113,10 +27142,10 @@ var BindingRuntime = class {
27113
27142
  const known = new Set(nodes.filter((node) => this.bindingFor(node)));
27114
27143
  const entering = /* @__PURE__ */ new Map();
27115
27144
  for (const node of nodes) {
27116
- const nodeId = node.getAttr("node_id");
27145
+ const nodeId = node.getAttr("nodeId");
27117
27146
  if (nodeId == null) continue;
27118
27147
  if (entering.has(nodeId) || this.nodeIds.has(nodeId) && this.nodeIds.get(nodeId) !== node) {
27119
- throw new Error(`Duplicate node_id '${nodeId}'`);
27148
+ throw new Error(`Duplicate nodeId '${nodeId}'`);
27120
27149
  }
27121
27150
  entering.set(nodeId, node);
27122
27151
  }
@@ -27128,7 +27157,7 @@ var BindingRuntime = class {
27128
27157
  } catch (error) {
27129
27158
  const errors = [error];
27130
27159
  for (const node of nodes.filter((node2) => !known.has(node2)).reverse()) {
27131
- const nodeId = node.getAttr("node_id");
27160
+ const nodeId = node.getAttr("nodeId");
27132
27161
  if (entering.get(nodeId) === node && this.nodeIds.get(nodeId) === node) this.nodeIds.delete(nodeId);
27133
27162
  const binding = this.bindingFor(node);
27134
27163
  if (!binding) continue;
@@ -27177,16 +27206,16 @@ var BindingRuntime = class {
27177
27206
  }
27178
27207
  /**
27179
27208
  * An attribute change: the NodeBinding of the node is required first (GC-210 §090), then the inline
27180
- * declarations of the changed attributes are released (S09), then the `node_id` map, then the
27209
+ * declarations of the changed attributes are released (S09), then the `nodeId` map, then the
27181
27210
  * rebinding of the node, or of its branch for a context attribute.
27182
27211
  */
27183
27212
  #attributesChanged(node, diff) {
27184
27213
  const binding = this.#installedBinding(node);
27185
27214
  this.inlineCompiler.release(node, Object.keys(diff));
27186
- if (Object.hasOwn(diff, "node_id")) {
27187
- const { old: previous, new: current } = diff.node_id;
27215
+ if (Object.hasOwn(diff, "nodeId")) {
27216
+ const { old: previous, new: current } = diff.nodeId;
27188
27217
  if (current != null && this.nodeIds.has(current) && this.nodeIds.get(current) !== node) {
27189
- throw new Error(`Duplicate node_id '${current}'`);
27218
+ throw new Error(`Duplicate nodeId '${current}'`);
27190
27219
  }
27191
27220
  if (this.nodeIds.get(previous) === node) this.nodeIds.delete(previous);
27192
27221
  if (current != null) this.nodeIds.set(current, node);
@@ -27293,6 +27322,14 @@ var NodeBinding = class {
27293
27322
  if (dataElement && !PROVIDERS[node.nodeTag]) return;
27294
27323
  if (!dataElement && typeof node.getAttr("remote") === "string") this.#remote ??= new RemoteBinding(this);
27295
27324
  const remoteDependencies = /* @__PURE__ */ new Set();
27325
+ if (node._getMeta("gramlot_component")?.bagStore) {
27326
+ const storepath = node.getAttr("storepath");
27327
+ if (typeof storepath !== "string" || !storepath || /^[\^=]/.test(storepath) || storepath.includes("?")) {
27328
+ throw new TypeError("storepath requires a plain Bag data path");
27329
+ }
27330
+ const path = node.absDatapath(storepath);
27331
+ this.#registrations.push(this.runtime.router.register({ path, recipient: this, subtree: true }));
27332
+ }
27296
27333
  const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr("_timing")) : /* @__PURE__ */ new Set();
27297
27334
  if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
27298
27335
  if (name.startsWith("remote_")) for (const dependency of pointerDependencies(node, raw)) remoteDependencies.add(dependency);
@@ -27420,6 +27457,320 @@ var NodeBinding = class {
27420
27457
  }
27421
27458
  };
27422
27459
 
27460
+ // src/renderer/drag-preparation.js
27461
+ var DragPreparation = class {
27462
+ constructor(renderer) {
27463
+ this.renderer = renderer;
27464
+ }
27465
+ prepare(sourceNode, event) {
27466
+ const record2 = this.renderer.records.get(sourceNode);
27467
+ if (!record2 || record2.resolved.draggable !== true) return null;
27468
+ const context = sourceNode._getMeta("gramlot_component")?.dragSource ? record2.element.getDragContext(event) : { dragValues: {}, item: void 0, path: void 0 };
27469
+ if (context === null) return null;
27470
+ const { dragValues, item, path } = context;
27471
+ if (record2.resolved.onDrag) {
27472
+ const result = this.renderer.html.callLogic(sourceNode, record2.resolved.onDrag, { dragValues, item, path });
27473
+ if (result && typeof result.then === "function") {
27474
+ throw new TypeError("onDrag must run synchronously");
27475
+ }
27476
+ if (result === false) return null;
27477
+ }
27478
+ assertTransportData(dragValues);
27479
+ const snapshot = Object.fromEntries(Object.entries(dragValues).map(([type, value]) => {
27480
+ if (type.startsWith("text/") || type === "dragTags") {
27481
+ if (typeof value !== "string") throw new TypeError(`${type} drag data must be text`);
27482
+ return [type, value];
27483
+ }
27484
+ return [type, fromTytx(toTytx(value))];
27485
+ }));
27486
+ return { dragValues: snapshot, item, path };
27487
+ }
27488
+ };
27489
+
27490
+ // src/renderer/drag-drop-policy.js
27491
+ var DragDropPolicy = class {
27492
+ static isTarget(attributes) {
27493
+ return attributes.dropTarget === true || Boolean(attributes.dropTargetCb) || Object.entries(attributes).some(([name, value]) => name.startsWith("dropTargetCb_") && Boolean(value));
27494
+ }
27495
+ /** Handler types are already resolved by the dispatcher; no MIME/name encoding is assumed here. */
27496
+ static acceptedTypes(payloadTypes, dropTypes = "", handlerTypes = []) {
27497
+ const patterns = dropTypes.split(",").map((type) => type.trim()).filter(Boolean).map((pattern) => {
27498
+ const literalParts = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
27499
+ return new RegExp(`^${literalParts.join(".*")}$`);
27500
+ });
27501
+ return payloadTypes.filter((type) => type !== "dragTags" && (handlerTypes.includes(type) || patterns.some((pattern) => pattern.test(type))));
27502
+ }
27503
+ static acceptsTags(dragTags = "", dropTags = "") {
27504
+ if (!dropTags.trim()) return true;
27505
+ const tags = new Set(dragTags.split(",").map((tag2) => tag2.trim()).filter(Boolean));
27506
+ if (!tags.size) return false;
27507
+ return dropTags.split(",").some((alternative) => alternative.split(" AND ").every((term) => {
27508
+ term = term.trim();
27509
+ if (!term || term === "!") return false;
27510
+ return term.startsWith("!") ? !tags.has(term.slice(1)) : tags.has(term);
27511
+ }));
27512
+ }
27513
+ static acceptsEffect(effectAllowed = "all", dropEffect = "move") {
27514
+ const effects = {
27515
+ all: ["copy", "move", "link"],
27516
+ none: [],
27517
+ copy: ["copy"],
27518
+ move: ["move"],
27519
+ link: ["link"],
27520
+ copyMove: ["copy", "move"],
27521
+ copyLink: ["copy", "link"],
27522
+ linkMove: ["link", "move"]
27523
+ };
27524
+ if (!Object.hasOwn(effects, effectAllowed)) throw new TypeError(`Invalid effectAllowed: ${effectAllowed}`);
27525
+ if (!["copy", "move", "link"].includes(dropEffect)) throw new TypeError(`Invalid dropEffect: ${dropEffect}`);
27526
+ return effects[effectAllowed].includes(dropEffect);
27527
+ }
27528
+ /** A true result still requires the destination's dynamic callbacks to pass, including at drop. */
27529
+ static evaluate(payloadTypes, dragTags, effectAllowed, target, handlerTypes = []) {
27530
+ const types = this.acceptedTypes(payloadTypes, target.dropTypes, handlerTypes);
27531
+ const dropEffect = target.dropEffect ?? "move";
27532
+ const accepted = this.isTarget(target) && types.length > 0 && this.acceptsTags(dragTags, target.dropTags) && this.acceptsEffect(effectAllowed, dropEffect);
27533
+ return { accepted, types, dropEffect: accepted ? dropEffect : "none" };
27534
+ }
27535
+ };
27536
+
27537
+ // src/renderer/drag-drop.js
27538
+ var EVENTS = ["dragstart", "dragover", "dragleave", "drop", "dragend"];
27539
+ var DragDrop = class {
27540
+ #renderer;
27541
+ #document;
27542
+ #session = null;
27543
+ #feedback = null;
27544
+ #style = null;
27545
+ #hide;
27546
+ constructor(renderer) {
27547
+ this.#renderer = renderer;
27548
+ this.#document = renderer.destination.ownerDocument;
27549
+ for (const name of EVENTS) this.#document.addEventListener(name, this);
27550
+ this.#hide = () => this.#finish("none");
27551
+ this.#document.defaultView.addEventListener("pagehide", this.#hide);
27552
+ }
27553
+ handleEvent(event) {
27554
+ if (event.type === "dragstart") this.#start(event);
27555
+ else if (event.type === "dragend") this.#finish(event.dataTransfer.dropEffect);
27556
+ else if (event.type === "dragleave") this.#clearFeedback();
27557
+ else if (event.type === "dragover") this.#over(event);
27558
+ else if (event.type === "drop") void this.#drop(event);
27559
+ }
27560
+ #record(event, predicate) {
27561
+ for (const element of event.composedPath()) {
27562
+ const record2 = this.#renderer.elements.get(element);
27563
+ if (record2 && predicate(record2.resolved)) return record2;
27564
+ }
27565
+ return null;
27566
+ }
27567
+ #context(record2, event) {
27568
+ return record2.node._getMeta("gramlot_component")?.dragSource ? record2.element.getDragContext(event) : { element: record2.element, item: void 0, path: void 0 };
27569
+ }
27570
+ #start(event) {
27571
+ const record2 = this.#record(event, (attrs) => attrs.draggable === true);
27572
+ if (!record2) return;
27573
+ this.#finish("none");
27574
+ try {
27575
+ const prepared = this.#renderer.prepareDrag(record2.node, event);
27576
+ if (!prepared || !record2.element.isConnected || this.#renderer.records.get(record2.node) !== record2) {
27577
+ event.preventDefault();
27578
+ return;
27579
+ }
27580
+ const context = this.#context(record2, event);
27581
+ if (!context) {
27582
+ event.preventDefault();
27583
+ return;
27584
+ }
27585
+ const wires = new Map(Object.entries(prepared.dragValues).filter(([type]) => type !== "dragTags").map(([type, value]) => [type, type.startsWith("text/") ? value : toTytx(value)]));
27586
+ if (!wires.size) {
27587
+ event.preventDefault();
27588
+ return;
27589
+ }
27590
+ const effectAllowed = record2.resolved.effectAllowed ?? "all";
27591
+ DragDropPolicy.acceptsEffect(effectAllowed, "move");
27592
+ let declaredTags = "";
27593
+ for (let ancestor = record2; ancestor; ancestor = ancestor.parent) {
27594
+ if (ancestor.resolved?.dragTags != null) {
27595
+ declaredTags = ancestor.resolved.dragTags;
27596
+ break;
27597
+ }
27598
+ }
27599
+ const session = this.#session = {
27600
+ record: record2,
27601
+ wires,
27602
+ effectAllowed,
27603
+ phase: "active",
27604
+ tags: [declaredTags, prepared.dragValues.dragTags].filter(Boolean).join(","),
27605
+ endTopic: this.#renderer.binding.gramlot._subscriptions.topicFor(record2.node, "endDrag"),
27606
+ source: {
27607
+ pageId: this.#renderer.binding.gramlot.pageId ?? null,
27608
+ sourcePath: record2.node.fullpath,
27609
+ itemPath: prepared.path ?? null
27610
+ },
27611
+ preview: null,
27612
+ release: null
27613
+ };
27614
+ event.dataTransfer.clearData();
27615
+ for (const [type, wire] of wires) event.dataTransfer.setData(type, wire);
27616
+ event.dataTransfer.effectAllowed = effectAllowed;
27617
+ this.#style = this.#document.createElement("style");
27618
+ this.#style.textContent = ".canBeDropped{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}.cannotBeDropped{outline:2px dashed currentColor;outline-offset:-2px}.draggedItem{opacity:.75}";
27619
+ this.#document.head.append(this.#style);
27620
+ this.#preview(session, context.element, event.dataTransfer);
27621
+ session.release = this.#renderer.onDispose(record2.node, () => this.#finish("none"));
27622
+ } catch (error) {
27623
+ event.preventDefault();
27624
+ this.#clearSession();
27625
+ this.#report(error);
27626
+ }
27627
+ }
27628
+ #preview(session, element, transfer) {
27629
+ const preview = element.cloneNode(true);
27630
+ preview.removeAttribute("id");
27631
+ for (const child of preview.querySelectorAll("[id]")) child.removeAttribute("id");
27632
+ preview.setAttribute("aria-hidden", "true");
27633
+ preview.classList.add(...(session.record.resolved.dragClass ?? "draggedItem").split(/\s+/).filter(Boolean));
27634
+ Object.assign(preview.style, {
27635
+ position: "fixed",
27636
+ left: "-10000px",
27637
+ top: "0",
27638
+ width: `${element.getBoundingClientRect().width}px`,
27639
+ pointerEvents: "none"
27640
+ });
27641
+ element.parentNode.append(preview);
27642
+ session.preview = preview;
27643
+ transfer.setDragImage(preview, 0, 0);
27644
+ }
27645
+ #target(event) {
27646
+ const session = this.#session;
27647
+ const record2 = this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs));
27648
+ if (!record2) return null;
27649
+ const row = this.#context(record2, event);
27650
+ if (!row) return { record: record2, element: record2.element, accepted: false };
27651
+ const policy = DragDropPolicy.evaluate([...session.wires.keys()], session.tags, session.effectAllowed, record2.resolved);
27652
+ const dropValues = Object.fromEntries(policy.types.map((type) => [
27653
+ type,
27654
+ type.startsWith("text/") ? session.wires.get(type) : fromTytx(session.wires.get(type))
27655
+ ]));
27656
+ const context = {
27657
+ dropValues,
27658
+ item: row.item,
27659
+ path: row.path,
27660
+ source: { ...session.source },
27661
+ selfdrop: record2 === session.record,
27662
+ dropEffect: policy.dropEffect,
27663
+ dataAvailable: true
27664
+ };
27665
+ const accepted = policy.accepted && this.#renderer.checkDropTarget(record2.node, context) && this.#renderer.records.get(record2.node) === record2 && row.element.isConnected;
27666
+ return { record: record2, element: row.element, accepted, context };
27667
+ }
27668
+ #over(event) {
27669
+ if (!this.#session) {
27670
+ if (this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs))) {
27671
+ event.preventDefault();
27672
+ event.dataTransfer.dropEffect = "none";
27673
+ }
27674
+ return;
27675
+ }
27676
+ event.preventDefault();
27677
+ if (this.#session.phase !== "active") {
27678
+ event.dataTransfer.dropEffect = "none";
27679
+ return;
27680
+ }
27681
+ try {
27682
+ const session = this.#session;
27683
+ const target = this.#target(event);
27684
+ if (this.#session !== session) {
27685
+ event.dataTransfer.dropEffect = "none";
27686
+ return;
27687
+ }
27688
+ event.dataTransfer.dropEffect = target?.accepted ? target.context.dropEffect : "none";
27689
+ this.#clearFeedback();
27690
+ if (target) this.#showFeedback(target.element, target.accepted);
27691
+ } catch (error) {
27692
+ event.dataTransfer.dropEffect = "none";
27693
+ if (this.#session) this.#session.phase = "rejected";
27694
+ this.#clearPayload();
27695
+ this.#report(error);
27696
+ }
27697
+ }
27698
+ async #drop(event) {
27699
+ if (!this.#session) {
27700
+ if (this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs))) event.preventDefault();
27701
+ return;
27702
+ }
27703
+ event.preventDefault();
27704
+ if (this.#session.phase !== "active") return;
27705
+ const session = this.#session;
27706
+ try {
27707
+ const target = this.#target(event);
27708
+ if (this.#session !== session) {
27709
+ event.dataTransfer.dropEffect = "none";
27710
+ return;
27711
+ }
27712
+ session.phase = "dropped";
27713
+ this.#clearPayload();
27714
+ if (!target?.accepted) {
27715
+ event.dataTransfer.dropEffect = "none";
27716
+ return;
27717
+ }
27718
+ event.dataTransfer.dropEffect = target.context.dropEffect;
27719
+ target.record.node.publish("onDrop", target.context);
27720
+ await this.#renderer.invokeDrop(target.record.node, target.context);
27721
+ } catch (error) {
27722
+ if (this.#session === session) {
27723
+ session.phase = "rejected";
27724
+ this.#clearPayload();
27725
+ }
27726
+ this.#report(error);
27727
+ }
27728
+ }
27729
+ #showFeedback(element, accepted) {
27730
+ const name = accepted ? "canBeDropped" : "cannotBeDropped";
27731
+ const parts2 = (element.getAttribute("part") ?? "").split(/\s+/).filter(Boolean);
27732
+ this.#feedback = { element, name, hadClass: element.classList.contains(name), hadPart: parts2.includes(name) };
27733
+ element.classList.add(name);
27734
+ if (!parts2.includes(name)) element.setAttribute("part", [...parts2, name].join(" "));
27735
+ }
27736
+ #clearFeedback() {
27737
+ if (!this.#feedback) return;
27738
+ const { element, name, hadClass, hadPart } = this.#feedback;
27739
+ if (!hadClass) element.classList.remove(name);
27740
+ if (!hadPart) element.setAttribute("part", (element.getAttribute("part") ?? "").split(/\s+/).filter((part) => part !== name).join(" "));
27741
+ this.#feedback = null;
27742
+ }
27743
+ #clearPayload() {
27744
+ this.#clearFeedback();
27745
+ if (!this.#session) return;
27746
+ this.#session.preview?.remove();
27747
+ this.#session.preview = null;
27748
+ this.#session.wires.clear();
27749
+ }
27750
+ #clearSession() {
27751
+ const session = this.#session;
27752
+ this.#clearPayload();
27753
+ this.#session = null;
27754
+ session?.release?.();
27755
+ this.#style?.remove();
27756
+ this.#style = null;
27757
+ return session;
27758
+ }
27759
+ #finish(dropEffect) {
27760
+ const session = this.#clearSession();
27761
+ if (!session || this.#renderer.disposed) return;
27762
+ void this.#renderer.endDrag(session.record.node, { source: { ...session.source }, dropEffect }, session.endTopic).catch((error) => this.#report(error));
27763
+ }
27764
+ #report(error) {
27765
+ console.error("Gramlot drag/drop failed:", error);
27766
+ }
27767
+ dispose() {
27768
+ this.#clearSession();
27769
+ for (const name of EVENTS) this.#document.removeEventListener(name, this);
27770
+ this.#document.defaultView.removeEventListener("pagehide", this.#hide);
27771
+ }
27772
+ };
27773
+
27423
27774
  // src/renderer/gramlot-renderer.js
27424
27775
  var GramlotRenderer = class extends GramlotHtmlRenderer {
27425
27776
  static renderType = "object";
@@ -27444,6 +27795,10 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
27444
27795
  this.destination = destination;
27445
27796
  this.html = new HtmlElement({
27446
27797
  metadataAttributes: ["__ref"],
27798
+ callLogic: (node, name, keywords) => {
27799
+ const { group, method } = binding.gramlot.src.logicRegistry.resolve(name, node);
27800
+ return method.call(group, node, keywords);
27801
+ },
27447
27802
  invokeScript: (node, name, code, keywords) => this.inlineCompiler.compile(
27448
27803
  node,
27449
27804
  name,
@@ -27457,14 +27812,59 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
27457
27812
  this.building = false;
27458
27813
  this.disposed = false;
27459
27814
  this.elements = /* @__PURE__ */ new WeakMap();
27815
+ this.dragPreparation = new DragPreparation(this);
27460
27816
  this.instanceId = randomId();
27461
27817
  this.radioGroups = new RadioGroups(this);
27818
+ this.dragDrop = new DragDrop(this);
27462
27819
  this.subscription = `html-source-renderer-${this.instanceId}`;
27463
27820
  source.subscribe(this.subscription, { any: (event) => this.receive(event) });
27464
27821
  }
27465
27822
  get binding() {
27466
27823
  return this._binding;
27467
27824
  }
27825
+ /** Prepare a local payload snapshot: no DataTransfer writes or native gesture commit. */
27826
+ prepareDrag(node, event) {
27827
+ return this.dragPreparation.prepare(node, event);
27828
+ }
27829
+ /** Dynamic eligibility only; cannot replace the independent type/tag/effect policy. */
27830
+ checkDropTarget(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
27831
+ const record2 = this.records.get(node);
27832
+ if (!record2) return false;
27833
+ if (!record2.resolved.dropTargetCb) return true;
27834
+ const allowed = this.html.callLogic(
27835
+ node,
27836
+ record2.resolved.dropTargetCb,
27837
+ { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
27838
+ );
27839
+ if (typeof allowed !== "boolean") throw new TypeError("dropTargetCb must return a boolean synchronously");
27840
+ return allowed;
27841
+ }
27842
+ /** Invoke only the general action, after acceptance and removal of data handled by typed actions. */
27843
+ async invokeDrop(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
27844
+ const record2 = this.records.get(node);
27845
+ if (!record2 || !record2.resolved.onDrop || Object.keys(dropValues).length === 0) return;
27846
+ await this.html.callLogic(
27847
+ node,
27848
+ record2.resolved.onDrop,
27849
+ { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
27850
+ );
27851
+ }
27852
+ /** Notify origin completion independently of application-operation success. */
27853
+ async endDrag(node, { source, dropEffect }, topic) {
27854
+ const context = { source, dropEffect }, errors = [];
27855
+ const record2 = this.records.get(node);
27856
+ try {
27857
+ if (record2 && !record2.binding.closed && record2.resolved.onDragEnd) await this.html.callLogic(node, record2.resolved.onDragEnd, context);
27858
+ } catch (error) {
27859
+ errors.push(error);
27860
+ }
27861
+ try {
27862
+ this.binding.gramlot.publish(topic, context);
27863
+ } catch (error) {
27864
+ errors.push(error);
27865
+ }
27866
+ if (errors.length) throw new AggregateError(errors, "Drag completion notification failed");
27867
+ }
27468
27868
  /** The page's InlineCompiler: the live renderer evaluates the `==` expressions (S09). */
27469
27869
  get inlineCompiler() {
27470
27870
  return this.binding.inlineCompiler;
@@ -28078,6 +28478,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
28078
28478
  dispose() {
28079
28479
  if (this.disposed) return;
28080
28480
  this.disposed = true;
28481
+ this.dragDrop.dispose();
28081
28482
  this.source.unsubscribe(this.subscription, { any: true });
28082
28483
  this.pending.length = 0;
28083
28484
  const errors = [];
@@ -28728,7 +29129,7 @@ var SubscriptionsHandler = class extends Handler {
28728
29129
  const forward = topic.parent || topic.iframe !== void 0 ? this.#frames.prepare(topic, payload) : null;
28729
29130
  if (Object.hasOwn(topic, "nodeId")) {
28730
29131
  const node = this.gramlot.src.binding.nodeIds.get(topic.nodeId);
28731
- if (!node) throw new Error(`node_id not found: ${topic.nodeId}`);
29132
+ if (!node) throw new Error(`nodeId not found: ${topic.nodeId}`);
28732
29133
  return this.publishNode(node, topic.topic, payload);
28733
29134
  }
28734
29135
  this.#deliver(topic.topic, payload);
@@ -28739,7 +29140,7 @@ var SubscriptionsHandler = class extends Handler {
28739
29140
  node = sourceTarget(node);
28740
29141
  const binding = this.gramlot.src.binding.bindingFor(node);
28741
29142
  if (!binding || binding.closed) throw new Error("Topic target is not an active Source node of this page");
28742
- let id = node.getAttr("node_id");
29143
+ let id = node.getAttr("nodeId");
28743
29144
  if (id == null) {
28744
29145
  if (!this.#nodeIds.has(node)) this.#nodeIds.set(node, `gramlot-self-${++this.#sequence}`);
28745
29146
  id = this.#nodeIds.get(node);
@@ -29190,578 +29591,206 @@ var Page = class extends Exposed {
29190
29591
  }
29191
29592
  };
29192
29593
 
29193
- // src/server/index-page.js
29194
- var IndexPage = class extends Page {
29195
- static title = "Application";
29196
- static logoUrl = "";
29197
- static shellId = "index";
29198
- static navigation = [];
29199
- static css = ["/themes/gramlot-index/theme.css"];
29594
+ // src/server/frame-page.js
29595
+ var FramePage = class extends Page {
29596
+ static shellId = "frame";
29597
+ static datapath = null;
29200
29598
  main(root) {
29201
- const families = this.constructor.navigation;
29202
- const shell = root.div({ class: "index-shell", id: this.constructor.shellId });
29203
- this.header(shell);
29204
- const sidebar = shell.aside({ class: "index-sidebar", id: "index-sidebar" });
29205
- const brand = sidebar.header();
29206
- if (this.constructor.logoUrl) brand.img({ src: this.constructor.logoUrl, alt: this.constructor.title, class: "index-logo" });
29207
- brand.h1(this.constructor.title);
29208
- const navigation = sidebar.nav({ "aria-label": "Pages" }).ul({ class: "index-list" });
29209
- for (const family of families) {
29210
- const category = navigation.li().details({ open: family === families[0] });
29211
- category.summary({ tabindex: -1 }).a(family.title, {
29212
- id: `open-${family.key}`,
29213
- href: `#panel-${family.key}`,
29214
- class: "index-family",
29215
- aria_current: null,
29216
- tabindex: -1
29217
- });
29218
- const examplesList = category.ul({ class: "index-list" });
29219
- for (const example of family.children) {
29220
- examplesList.li().a(example.title, {
29221
- id: `open-${example.key}`,
29222
- href: example.url,
29223
- aria_current: null,
29224
- tabindex: -1
29225
- });
29226
- }
29227
- }
29228
- shell.div({
29229
- class: "index-divider",
29230
- id: "index-sidebar-divider",
29231
- role: "separator",
29232
- aria_orientation: "vertical",
29233
- tabindex: 0,
29234
- aria_label: "Resize sidebar",
29235
- aria_controls: "index-sidebar",
29236
- aria_valuemin: 120,
29237
- aria_valuemax: 460,
29238
- aria_valuenow: 240
29239
- });
29240
- const content = shell.main({ class: "index-main" });
29241
- const tabs = content.div({ class: "index-tabs", role: "tablist", aria_label: "Open pages" });
29242
- tabs.html_button("Introduction", {
29243
- type: "button",
29244
- role: "tab",
29245
- id: "tab-intro",
29246
- aria_controls: "panel-intro",
29247
- aria_selected: "true",
29248
- tabindex: -1,
29249
- hidden: false
29599
+ const shell = root.div({
29600
+ id: this.constructor.shellId,
29601
+ datapath: this.constructor.datapath,
29602
+ class: "frame-page",
29603
+ height: "100vh",
29604
+ display: "flex",
29605
+ flex_direction: "column",
29606
+ min_height: 0
29250
29607
  });
29251
- for (const family of families) {
29252
- for (const { key, title } of [family, ...family.children]) {
29253
- tabs.html_button(title, {
29254
- type: "button",
29255
- role: "tab",
29256
- id: `tab-${key}`,
29257
- aria_controls: `panel-${key}`,
29258
- aria_selected: "false",
29259
- tabindex: -1,
29260
- hidden: true
29261
- });
29608
+ const frame = shell.borderContainer({ node_label: "frame", height: "100%", flex: "1", min_height: 0 });
29609
+ for (const region of ["top", "bottom", "left", "right", "center"]) {
29610
+ if (this[region] !== void 0) {
29611
+ const pane = frame.contentPane({ region, node_label: region });
29612
+ this[region](pane);
29262
29613
  }
29263
29614
  }
29264
- const panels = content.div({ class: "index-panels" });
29265
- const intro = panels.section({
29266
- id: "panel-intro",
29267
- class: "index-intro",
29268
- role: "tabpanel",
29269
- aria_labelledby: "tab-intro",
29270
- hidden: false
29271
- });
29272
- this.introduction(intro);
29273
- for (const family of families) {
29274
- const categoryPanel = panels.section({
29275
- id: `panel-${family.key}`,
29276
- class: "index-category",
29277
- role: "tabpanel",
29278
- aria_labelledby: `tab-${family.key}`,
29279
- hidden: true
29280
- });
29281
- this.groupPanel(categoryPanel, family);
29282
- for (const example of family.children) this.panel(panels, example);
29283
- }
29284
- const footer = shell.footer({ class: "index-footer" });
29285
- this.footer(footer);
29286
29615
  this.behavior(shell);
29287
29616
  }
29288
- header(shell) {
29617
+ center(pane) {
29618
+ }
29619
+ behavior(shell) {
29620
+ }
29621
+ };
29622
+
29623
+ // src/server/index-page.js
29624
+ var IndexPage = class extends FramePage {
29625
+ static title = "Application";
29626
+ static shellId = "index";
29627
+ static datapath = "index";
29628
+ static navigation = null;
29629
+ main(root) {
29630
+ const { navigation, datapath } = this.constructor;
29631
+ if (!(navigation instanceof Bag)) throw new TypeError("IndexPage.navigation must be a Bag");
29632
+ root.dataSetter({ destination_path: `${datapath}.navigation`, value: navigation });
29633
+ root.dataSetter({ destination_path: `${datapath}.navigationSelection`, value: null });
29634
+ root.dataSetter({ destination_path: `${datapath}.active`, value: null });
29635
+ root.dataSetter({ destination_path: `${datapath}.opened`, value: new Bag() });
29636
+ super.main(root);
29637
+ }
29638
+ left(pane) {
29639
+ pane.setAttr({ width: "240px", splitter: true, drawer: true, drawer_label: "Navigation" });
29640
+ pane.tree({
29641
+ node_label: "tree",
29642
+ storepath: `${this.constructor.datapath}.navigation`,
29643
+ labelAttribute: "title",
29644
+ hideValues: true,
29645
+ selectedPath: `^${this.constructor.datapath}.navigationSelection`
29646
+ });
29647
+ }
29648
+ center(pane) {
29649
+ pane.tabContainer({ node_label: "tabs", height: "100%", selectedPage: `^${this.constructor.datapath}.active` });
29289
29650
  }
29290
29651
  behavior(shell) {
29291
29652
  shell.dataController({ func: "indexMount", _onStart: true, shell_id: this.constructor.shellId });
29292
29653
  }
29293
- introduction(pane) {
29294
- pane.h2(this.constructor.title);
29295
- pane.p("Choose a page from the navigation. Open pages remain available in tabs.");
29296
- }
29297
- groupPanel(pane, group) {
29298
- pane.h2(group.title);
29299
- }
29300
- footer(footer) {
29301
- const theme = footer.div({ class: "index-theme" });
29302
- theme.html_label("Theme", { for: "index-appearance" });
29303
- const appearance = theme.select({ id: "index-appearance", value: "compact" });
29304
- appearance.option("Base", { value: "base", selected: false });
29305
- appearance.option("Compact", { value: "compact", selected: true });
29306
- appearance.option("mimi", { value: "mimi" });
29307
- appearance.option("joanna", { value: "joanna" });
29308
- const color = footer.div({ class: "index-theme" });
29309
- color.html_label("Color mode", { for: "index-theme" });
29310
- const choices = color.select({ id: "index-theme", value: "light" });
29311
- choices.option("Light", { value: "light", selected: true });
29312
- choices.option("Dark", { value: "dark", selected: false });
29313
- const keyboard = footer.div({ class: "index-keyboard" });
29314
- const label = keyboard.html_label({ for: "keyboard-navigation" });
29315
- label.input({ type: "checkbox", id: "keyboard-navigation", checked: false });
29316
- label.span("Keyboard navigation");
29317
- if (this.constructor.installable) {
29318
- const app = footer.details({ class: "index-install" });
29319
- app.summary("Install app");
29320
- app.html_button("Install", { type: "button", id: "index-install-button", hidden: true });
29321
- app.p("", { id: "index-install-status", role: "status" });
29322
- app.p("Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.");
29323
- app.p("Use HTTPS or localhost. For a static export, serve the directory; direct file opening is not installable. Keep the server running for hosted pages.");
29324
- }
29325
- }
29326
- panel(parent, item) {
29327
- const pane = parent.section({
29328
- id: `panel-${item.key}`,
29329
- class: "index-panel",
29330
- role: "tabpanel",
29331
- aria_labelledby: `tab-${item.key}`,
29332
- hidden: true
29654
+ index_panel(pane, { selection }) {
29655
+ this.panel(pane, selection.getNode("#0"));
29656
+ }
29657
+ panel(pane, node) {
29658
+ pane.iframe({
29659
+ src: node.attr.url,
29660
+ title: node.attr.title ?? node.label,
29661
+ width: "100%",
29662
+ height: "100%",
29663
+ border: 0
29333
29664
  });
29334
- pane.iframe({ id: `frame-${item.key}`, title: item.title, name: `page-${item.key}` });
29335
29665
  }
29336
29666
  };
29337
-
29338
- // src/index-page-styles.js
29339
- var appearanceStyles = { "base": "", "compact": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n', "mimi": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy mimi; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-tab-height: 24px;\n --gramlot-tab-padding: 3px 10px;\n --gramlot-tab-radius: 3px;\n --gramlot-tab-gap: 2px;\n --gramlot-tab-strip-padding: 3px;\n --gramlot-tab-background: var(--gramlot-background);\n --gramlot-tab-selected-background: var(--gramlot-surface);\n --gramlot-tab-selected-color: var(--gramlot-ink);\n --gramlot-tab-border: var(--gramlot-border);\n --gramlot-background: #EDEEF0;\n --gramlot-surface: #F5F5F6;\n --gramlot-surface-subtle: #E0E1E3;\n --gramlot-ink: #3C3D40;\n --gramlot-text-secondary: #6B6E72;\n --gramlot-border: #BDBFC2;\n --gramlot-border-control: #9EA0A3;\n --gramlot-navigation: #48494C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #0071E3;\n --gramlot-action-hover: #005BBB;\n --gramlot-brand-blue: #0071E3;\n --gramlot-brand-yellow: #9EA0A3;\n --gramlot-selected: #E8F1FC;\n --gramlot-focus-ring: #0071E3;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #E0E1E3;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 4px;\n --gramlot-radius: 3px;\n --gramlot-radius-lg: 3px;\n --gramlot-field-height: 18px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .9em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme="dark"] {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 12px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) { min-block-size: 24px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n', "joanna": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy joanna; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-tab-height: 26px;\n --gramlot-tab-padding: 3px 10px;\n --gramlot-tab-radius: 6px;\n --gramlot-tab-gap: 2px;\n --gramlot-tab-strip-padding: 3px;\n --gramlot-tab-background: var(--gramlot-background);\n --gramlot-tab-selected-background: var(--gramlot-surface);\n --gramlot-tab-selected-color: var(--gramlot-ink);\n --gramlot-tab-border: var(--gramlot-border);\n --gramlot-background: #F2F2F7;\n --gramlot-surface: #FFFFFF;\n --gramlot-surface-subtle: #F2F2F7;\n --gramlot-ink: #3A3A3C;\n --gramlot-text-secondary: #636366;\n --gramlot-border: #D1D1D6;\n --gramlot-border-control: #AEAEB2;\n --gramlot-navigation: #3A3A3C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #007AFF;\n --gramlot-action-hover: #0061CC;\n --gramlot-brand-blue: #007AFF;\n --gramlot-brand-yellow: #AEAEB2;\n --gramlot-selected: #E0EFFF;\n --gramlot-focus-ring: #007AFF;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #F2F2F7;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 6px;\n --gramlot-radius: 6px;\n --gramlot-radius-lg: 6px;\n --gramlot-field-height: 20px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .8em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme="dark"] {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 13px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) { min-block-size: 26px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n' };
29340
-
29341
- // src/index-theme.js
29342
- var THEME_READY = "index:theme-ready";
29343
- var THEME_SET = "index:theme-set";
29344
- var THEMES = /* @__PURE__ */ new Set(["light", "dark"]);
29345
- var APPEARANCES = /* @__PURE__ */ new Set(["base", "compact", "mimi", "joanna"]);
29667
+ IndexPage.registerSource("index_panel");
29346
29668
 
29347
29669
  // src/index-page-runtime.js
29348
29670
  function mountIndexPage(renderer, root, onSelection = () => {
29349
29671
  }, prepareEntry = () => {
29350
- }, { containerLayout = false, state: suppliedState = null, createEntry = null, onLoad = () => {
29351
- } } = {}) {
29352
- if (createEntry && !containerLayout) throw new TypeError("Deferred index entries require containerLayout");
29353
- const shell = renderer.records.get(root).element;
29354
- const document = shell.ownerDocument;
29355
- const window2 = document.defaultView;
29356
- const byId = (id) => document.getElementById(id);
29357
- const node = (element) => renderer.elements.get(element).node;
29358
- const set = (element, attrs) => node(element).setAttr(attrs);
29359
- const keyboard = byId("keyboard-navigation");
29360
- const theme = byId("index-theme");
29361
- const appearance = byId("index-appearance");
29362
- const sidebar = byId("index-sidebar");
29363
- const sidebarHandle = byId("index-sidebar-divider");
29364
- const navigationToggle = byId("index-navigation-toggle");
29365
- const codeToggle = byId("index-code-toggle");
29366
- const codeSidebar = byId("index-code");
29367
- const codeHandle = byId("index-code-divider");
29368
- const preferencesKey = `gramlot.${shell.id}.preferences:${window2.location.pathname}`;
29369
- let preferences = {};
29370
- try {
29371
- const saved = JSON.parse(window2.localStorage.getItem(preferencesKey));
29372
- if (saved !== null && typeof saved === "object" && !Array.isArray(saved)) preferences = saved;
29373
- } catch (error) {
29374
- if (error.name !== "SyntaxError" && error.name !== "SecurityError") throw error;
29375
- }
29376
- const restoreChoice = (control, value, allowed) => {
29377
- if (!control || !allowed.has(value)) return;
29378
- set(control, { value });
29379
- for (const option of control.options) set(option, { selected: option.value === value });
29380
- };
29381
- restoreChoice(theme, preferences.theme, THEMES);
29382
- restoreChoice(appearance, preferences.appearance, APPEARANCES);
29383
- const families = [...shell.querySelectorAll(".index-sidebar details")];
29384
- const Bag2 = root.builder.data.constructor;
29385
- const state = suppliedState ?? new Bag2();
29386
- const opened = new Bag2();
29387
- state.setItem("opened", opened);
29388
- state.setItem("keyboard", keyboard?.checked ?? false);
29389
- state.setItem("theme", theme?.value ?? "light");
29390
- state.setItem("appearance", appearance?.value ?? "compact");
29391
- state.setItem("navigationVisible", preferences.navigationVisible !== false);
29392
- state.setItem("codeVisible", preferences.codeVisible !== false);
29393
- const savePreferences = () => {
29394
- try {
29395
- window2.localStorage.setItem(preferencesKey, JSON.stringify({
29396
- theme: state.getItem("theme"),
29397
- appearance: state.getItem("appearance"),
29398
- sidebarWidth: state.getItem("preferredSidebarWidth"),
29399
- codeWidth: state.getItem("preferredCodeWidth"),
29400
- navigationVisible: state.getItem("navigationVisible"),
29401
- codeVisible: state.getItem("codeVisible")
29402
- }));
29403
- } catch (error) {
29404
- if (error.name !== "SecurityError" && error.name !== "QuotaExceededError") throw error;
29405
- }
29406
- };
29672
+ }, {
29673
+ state = root.builder.data.getItem(root.getAttr("datapath")),
29674
+ createEntry = null,
29675
+ onLoad = () => {
29676
+ }
29677
+ } = {}) {
29678
+ const navigation = state.getItem("navigation");
29679
+ if (!(navigation instanceof Bag)) throw new TypeError("IndexPage navigation must be a Bag");
29680
+ const tabs = root.value.getNode("frame.center.tabs");
29681
+ const builder = root.builder;
29407
29682
  const entries = /* @__PURE__ */ new Map();
29408
- const releases = [];
29409
- const style = root.builder.wrapSource(root.value).style(appearanceStyles[appearance?.value ?? "compact"]);
29410
- let drag = null;
29411
- let disposed = false;
29412
- let installPrompt = null;
29413
- const previousTheme = document.documentElement.getAttribute("data-theme");
29414
- const listen = (element, type, handler) => {
29415
- if (!element) return;
29416
- element.addEventListener(type, handler);
29417
- releases.push(() => element.removeEventListener(type, handler));
29418
- };
29419
- const stopDrag = () => {
29420
- if (!drag) return;
29421
- const { handle, pointerId } = drag;
29422
- drag = null;
29423
- if (!disposed) set(shell, { data_resizing: null });
29424
- if (handle.hasPointerCapture(pointerId)) handle.releasePointerCapture(pointerId);
29425
- };
29426
- const dispose = () => {
29683
+ let disposed = false, selecting = false, sequence = 0, requested = null;
29684
+ const opened = state.getItem("opened");
29685
+ for (const record2 of opened.getNodes()) {
29686
+ const { url, path, title } = record2.attr;
29687
+ const pane = tabs.value.getNode(record2.label);
29688
+ const entry = { url, path, title, pane, node: navigation.getNode(path), loading: false };
29689
+ prepareEntry(entry);
29690
+ entries.set(url, entry);
29691
+ sequence++;
29692
+ }
29693
+ const activate = (entry) => {
29427
29694
  if (disposed) return;
29428
- disposed = true;
29429
- installPrompt = null;
29430
- stopDrag();
29431
- for (const release of releases.reverse()) release();
29432
- if (style.parentBag) style.parentBag.popNode(style.label);
29433
- if (previousTheme == null) document.documentElement.removeAttribute("data-theme");
29434
- else document.documentElement.setAttribute("data-theme", previousTheme);
29435
- };
29436
- const send = (frame) => frame.contentWindow.postMessage({ type: THEME_SET, theme: state.getItem("theme"), appearance: state.getItem("appearance") }, "*");
29437
- const applyTheme = () => {
29438
- document.documentElement.setAttribute("data-theme", state.getItem("theme"));
29439
- style.setValue(appearanceStyles[state.getItem("appearance")]);
29440
- for (const { frame } of entries.values()) if (frame) send(frame);
29441
- };
29442
- const updateInspector = () => onSelection(entries, state.getItem("active"));
29443
- const updatePanels = () => {
29444
- if (navigationToggle) {
29445
- const visible = state.getItem("navigationVisible");
29446
- set(sidebar, containerLayout ? { drawer: visible ? true : "close" } : { hidden: !visible });
29447
- if (!containerLayout) set(sidebarHandle, { hidden: !visible });
29448
- set(navigationToggle, { aria_expanded: String(visible) });
29449
- set(shell, { data_navigation_hidden: String(!visible) });
29450
- }
29451
- if (codeSidebar) {
29452
- const available = Boolean(entries.get(state.getItem("active"))?.code);
29453
- const visible = available && state.getItem("codeVisible");
29454
- set(codeSidebar, containerLayout ? { hidden: !available, drawer: visible ? true : "close" } : { hidden: !visible });
29455
- if (!containerLayout) set(codeHandle, { hidden: !visible });
29456
- set(codeToggle, { disabled: !available, aria_expanded: String(visible) });
29457
- set(shell, { data_code_visible: String(visible) });
29695
+ selecting = true;
29696
+ try {
29697
+ state.setItem("active", entry.url);
29698
+ state.setItem("navigationSelection", entry.path);
29699
+ onSelection(entries, entry.url);
29700
+ } finally {
29701
+ selecting = false;
29458
29702
  }
29459
29703
  };
29460
- const prepare = (entry) => {
29461
- entry.panel = byId(`panel-${entry.key}`);
29462
- entry.tab = containerLayout ? entry.panel : byId(`tab-${entry.key}`);
29463
- entry.code = byId(`codepane-${entry.key}`);
29464
- if (entry.key === "intro") return;
29465
- prepareEntry(entry, { byId, node, set, listen });
29466
- entry.frame = byId(`frame-${entry.key}`);
29467
- if (entry.frame) listen(entry.frame, "load", () => send(entry.frame));
29468
- };
29469
- const openEntry = (entry) => {
29470
- if (opened.getItem(entry.key)) return;
29471
- opened.setItem(entry.key, true);
29472
- set(containerLayout ? entry.panel : entry.tab, { hidden: false });
29473
- if (entry.frame) set(entry.frame, { src: entry.open.getAttribute("href") });
29474
- };
29475
- let selecting = false;
29476
- function select(key) {
29477
- if (selecting || disposed) return;
29478
- const requested = entries.get(key);
29479
- if (!requested) return;
29480
- state.setItem("requested", key);
29481
- if (!requested.panel) {
29482
- onLoad(key, "loading");
29483
- if (!requested.loading) {
29484
- requested.loading = Promise.resolve().then(() => {
29485
- if (!disposed) return createEntry(requested);
29486
- }).then(() => {
29487
- if (disposed) return;
29488
- prepare(requested);
29489
- openEntry(requested);
29490
- if (state.getItem("requested") === key) {
29491
- onLoad(key, "ready");
29492
- select(key);
29493
- }
29494
- }).catch((error) => {
29495
- if (!disposed && state.getItem("requested") === key) onLoad(key, "error", error);
29496
- }).finally(() => {
29497
- requested.loading = null;
29498
- });
29499
- }
29704
+ async function select(path) {
29705
+ const node = navigation.getNode(path);
29706
+ if (!node) throw new Error(`Unknown index navigation path: ${path}`);
29707
+ const url = node.attr.url;
29708
+ if (url == null) return;
29709
+ if (typeof url !== "string" || !url) throw new TypeError("IndexPage URL must be nonempty text");
29710
+ requested = url;
29711
+ let entry = entries.get(url);
29712
+ if (entry) {
29713
+ entry.path = path;
29714
+ activate(entry);
29500
29715
  return;
29501
29716
  }
29502
- onLoad(key, "ready");
29503
- selecting = true;
29717
+ while (tabs.value !== null && tabs.value.getNode(`page${sequence}`)) sequence++;
29718
+ const pane = sourceTarget(builder.wrapSource(tabs).contentPane({
29719
+ node_label: `page${sequence++}`,
29720
+ title: node.attr.title ?? node.label,
29721
+ pageName: url,
29722
+ height: "100%"
29723
+ }));
29724
+ const previous = state.getItem("active");
29725
+ entry = { url, path, node, pane, title: node.attr.title ?? node.label, loading: true };
29726
+ entries.set(url, entry);
29504
29727
  try {
29505
- const entry = entries.get(key);
29506
- openEntry(entry);
29507
- if (entry.family) set(entry.family, { open: true });
29508
- for (const [current, item] of entries) {
29509
- const active = current === key;
29510
- if (!containerLayout) {
29511
- set(item.tab, { aria_selected: String(active), tabindex: active && state.getItem("keyboard") ? 0 : -1 });
29512
- set(item.panel, { hidden: !active });
29728
+ activate(entry);
29729
+ onLoad(url, "loading");
29730
+ if (createEntry) await createEntry(entry);
29731
+ else {
29732
+ const selection = new Bag();
29733
+ selection.setItem(node.label, null, { ...node.attr });
29734
+ const mounted = await renderer.binding.gramlot.src.remoteSource(pane, "index_panel", { selection });
29735
+ if (!mounted) throw new Error("Panel loading was cancelled");
29736
+ }
29737
+ if (disposed) return;
29738
+ entry.loading = false;
29739
+ opened.setItem(pane.label, null, { url, path: entry.path, title: entry.title });
29740
+ prepareEntry(entry);
29741
+ if (requested === url) {
29742
+ onLoad(url, "ready");
29743
+ activate(entry);
29744
+ }
29745
+ } catch (error) {
29746
+ entries.delete(url);
29747
+ if (opened.getNode(pane.label)) opened.popNode(pane.label);
29748
+ if (pane.parentBag) pane.parentBag.popNode(pane.label);
29749
+ if (!disposed && requested === url) {
29750
+ onLoad(url, "error", error);
29751
+ const restored = entries.get(previous);
29752
+ requested = restored?.url ?? null;
29753
+ if (restored) activate(restored);
29754
+ else {
29755
+ selecting = true;
29756
+ try {
29757
+ state.setItem("active", null);
29758
+ state.setItem("navigationSelection", null);
29759
+ onSelection(entries, null);
29760
+ } finally {
29761
+ selecting = false;
29762
+ }
29513
29763
  }
29514
- if (item.code) set(item.code, { hidden: !active });
29515
- if (item.open) set(item.open, { aria_current: active ? "page" : null });
29516
29764
  }
29517
- if (state.getItem("active") !== key) state.setItem("active", key);
29518
- updatePanels();
29519
- updateInspector();
29520
- } finally {
29521
- selecting = false;
29522
29765
  }
29523
29766
  }
29524
- const sidebarMaximum = () => Math.max(120, Math.min(460, Math.floor(window2.innerWidth * 0.6)));
29525
- const applyWidths = () => set(shell, { style: `--sidebar-width: ${state.getItem("sidebarWidth")}px; --code-width: ${state.getItem("codeWidth") ?? 420}px` });
29526
- const setSidebarWidth = (value, remember = false) => {
29527
- const maximum = sidebarMaximum();
29528
- const width = Math.max(120, Math.min(maximum, value));
29529
- state.setItem("sidebarWidth", width);
29530
- applyWidths();
29531
- set(sidebarHandle, { aria_valuenow: width, aria_valuemax: maximum });
29532
- if (remember) {
29533
- state.setItem("preferredSidebarWidth", width);
29534
- savePreferences();
29767
+ const subscription = `${root.getAttr("id")}-selection`;
29768
+ state.subscribe(subscription, { any: (event) => {
29769
+ if (selecting || disposed) return;
29770
+ if (event.node === state.getNode("navigationSelection")) {
29771
+ const path = state.getItem("navigationSelection");
29772
+ if (path !== null) void select(path);
29773
+ } else if (event.node === state.getNode("active")) {
29774
+ const entry = entries.get(state.getItem("active"));
29775
+ if (entry) {
29776
+ requested = entry.url;
29777
+ activate(entry);
29778
+ }
29535
29779
  }
29536
- };
29537
- const codeMaximum = () => Math.max(200, Math.floor(window2.innerWidth * 0.6));
29538
- const setCodeWidth = (value, remember = false) => {
29539
- const maximum = codeMaximum();
29540
- const width = Math.max(200, Math.min(maximum, value));
29541
- state.setItem("codeWidth", width);
29542
- applyWidths();
29543
- set(codeHandle, { aria_valuenow: width, aria_valuemax: maximum });
29544
- if (remember) {
29545
- state.setItem("preferredCodeWidth", width);
29546
- savePreferences();
29780
+ } });
29781
+ const dispose = () => {
29782
+ if (disposed) return;
29783
+ disposed = true;
29784
+ state.unsubscribe(subscription, { any: true });
29785
+ for (const entry of entries.values()) if (entry.loading && entry.pane.parentBag) {
29786
+ entry.pane.parentBag.popNode(entry.pane.label);
29547
29787
  }
29548
29788
  };
29549
- const beginDrag = (handle, event, move) => {
29550
- if (event.button !== 0) return;
29551
- stopDrag();
29552
- handle.setPointerCapture(event.pointerId);
29553
- drag = { handle, pointerId: event.pointerId, move };
29554
- set(shell, { data_resizing: "true" });
29555
- event.preventDefault();
29556
- };
29557
- try {
29558
- const install = byId("index-install-button");
29559
- if (install) {
29560
- listen(window2, "beforeinstallprompt", (event) => {
29561
- event.preventDefault();
29562
- installPrompt = event;
29563
- set(install, { hidden: false, disabled: false });
29564
- });
29565
- listen(window2, "appinstalled", () => {
29566
- installPrompt = null;
29567
- set(install, { hidden: true });
29568
- node(byId("index-install-status")).setValue("App installed.");
29569
- });
29570
- listen(install, "click", async () => {
29571
- if (!installPrompt) return;
29572
- const prompt = installPrompt;
29573
- installPrompt = null;
29574
- set(install, { disabled: true });
29575
- try {
29576
- await prompt.prompt();
29577
- const { outcome } = await prompt.userChoice;
29578
- if (!disposed) node(byId("index-install-status")).setValue(
29579
- outcome === "accepted" ? "Installation accepted." : "Installation cancelled. You can also use the browser menu."
29580
- );
29581
- } catch (error) {
29582
- if (!disposed) node(byId("index-install-status")).setValue(`Installation failed: ${error.message}`);
29583
- } finally {
29584
- if (!disposed) set(install, { hidden: true });
29585
- }
29586
- });
29587
- }
29588
- set(shell, { data_resizing: null });
29589
- if (!containerLayout) {
29590
- const savedWidth = preferences.sidebarWidth;
29591
- const width = typeof savedWidth === "number" && Number.isFinite(savedWidth) && savedWidth >= 120 && savedWidth <= 460 ? savedWidth : sidebar.getBoundingClientRect().width || Number(sidebarHandle.getAttribute("aria-valuenow"));
29592
- state.setItem("preferredSidebarWidth", width);
29593
- setSidebarWidth(width);
29594
- } else {
29595
- const gramlot = renderer.binding.gramlot;
29596
- for (const [pane, property, widthProperty] of [[sidebar, "navigationVisible", "sidebarWidth"], [codeSidebar, "codeVisible", "codeWidth"]]) {
29597
- const source = node(pane);
29598
- const savedWidth = preferences[widthProperty];
29599
- if (typeof savedWidth === "number" && Number.isFinite(savedWidth) && savedWidth > 0) set(pane, { width: `${savedWidth}px` });
29600
- const handle2 = gramlot.subscribe(`${source.getAttr("node_id")}_closable_change`, ({ open }) => {
29601
- if (source.getAttr("hidden") === true || source.getAttr("drawer") === false) return;
29602
- state.setItem(property, open);
29603
- set(pane, { drawer: open ? true : "close" });
29604
- set(property === "navigationVisible" ? navigationToggle : codeToggle, { aria_expanded: String(open) });
29605
- set(shell, { [property === "navigationVisible" ? "data_navigation_hidden" : "data_code_visible"]: String(property === "navigationVisible" ? !open : open) });
29606
- savePreferences();
29607
- });
29608
- releases.push(() => gramlot.unsubscribe(handle2));
29609
- }
29610
- const border = shell.querySelector("[data-index-regions]");
29611
- const handle = gramlot.subscribe(`${node(border).getAttr("node_id")}_splitter_resize`, ({ region, size }) => {
29612
- set(region === "left" ? sidebar : codeSidebar, { width: size });
29613
- state.setItem(region === "left" ? "preferredSidebarWidth" : "preferredCodeWidth", Number.parseFloat(size));
29614
- savePreferences();
29615
- });
29616
- releases.push(() => gramlot.unsubscribe(handle));
29617
- state.setItem("preferredSidebarWidth", preferences.sidebarWidth);
29618
- state.setItem("preferredCodeWidth", preferences.codeWidth);
29619
- }
29620
- listen(navigationToggle, "click", () => {
29621
- state.setItem("navigationVisible", !state.getItem("navigationVisible"));
29622
- updatePanels();
29623
- savePreferences();
29624
- });
29625
- listen(codeToggle, "click", () => {
29626
- state.setItem("codeVisible", !state.getItem("codeVisible"));
29627
- updatePanels();
29628
- savePreferences();
29629
- });
29630
- if (!containerLayout && codeHandle) {
29631
- const saved = preferences.codeWidth;
29632
- const width = typeof saved === "number" && Number.isFinite(saved) && saved >= 200 ? saved : 420;
29633
- state.setItem("preferredCodeWidth", width);
29634
- setCodeWidth(width);
29635
- listen(codeHandle, "keydown", (event) => {
29636
- const current = state.getItem("codeWidth");
29637
- const value = event.key === "ArrowLeft" ? current + 10 : event.key === "ArrowRight" ? current - 10 : event.key === "Home" ? 200 : event.key === "End" ? codeMaximum() : null;
29638
- if (value == null) return;
29639
- event.preventDefault();
29640
- setCodeWidth(value, true);
29641
- });
29642
- listen(codeHandle, "pointerdown", (event) => beginDrag(
29643
- codeHandle,
29644
- event,
29645
- (x) => setCodeWidth(Math.round(shell.getBoundingClientRect().right - x), true)
29646
- ));
29647
- listen(codeHandle, "lostpointercapture", () => {
29648
- if (drag?.handle === codeHandle) stopDrag();
29649
- });
29650
- listen(window2, "resize", () => setCodeWidth(state.getItem("preferredCodeWidth")));
29651
- }
29652
- if (!containerLayout) {
29653
- listen(sidebarHandle, "keydown", (event) => {
29654
- const current = state.getItem("sidebarWidth");
29655
- const value = event.key === "ArrowLeft" ? current - 10 : event.key === "ArrowRight" ? current + 10 : event.key === "Home" ? 120 : event.key === "End" ? sidebarMaximum() : null;
29656
- if (value == null) return;
29657
- event.preventDefault();
29658
- setSidebarWidth(value, true);
29659
- });
29660
- listen(sidebarHandle, "pointerdown", (event) => beginDrag(
29661
- sidebarHandle,
29662
- event,
29663
- (x) => setSidebarWidth(Math.round(x - shell.getBoundingClientRect().left), true)
29664
- ));
29665
- listen(sidebarHandle, "lostpointercapture", () => {
29666
- if (drag?.handle === sidebarHandle) stopDrag();
29667
- });
29668
- listen(window2, "resize", () => setSidebarWidth(state.getItem("preferredSidebarWidth")));
29669
- }
29670
- const choices = createEntry ? [byId("panel-intro"), ...shell.querySelectorAll('.index-sidebar a[id^="open-"]')] : containerLayout ? byId("index-pages").children : shell.querySelectorAll(".index-tabs button");
29671
- for (const tab of choices) {
29672
- const key = tab.id.slice(createEntry && tab.id.startsWith("open-") ? "open-".length : containerLayout ? "panel-".length : "tab-".length);
29673
- const entry = {
29674
- key,
29675
- tab,
29676
- panel: byId(`panel-${key}`),
29677
- code: byId(`codepane-${key}`),
29678
- open: key === "intro" ? null : byId(`open-${key}`)
29679
- };
29680
- entries.set(key, entry);
29681
- if (entry.panel && (containerLayout ? node(entry.panel).getAttr("hidden") !== true : !tab.hidden)) opened.setItem(key, true);
29682
- if (!containerLayout && tab.getAttribute("aria-selected") === "true") state.setItem("active", key);
29683
- if (!containerLayout) listen(tab, "click", () => select(key));
29684
- if (entry.open) listen(entry.open, "click", (event) => {
29685
- event.preventDefault();
29686
- select(key);
29687
- });
29688
- if (!containerLayout) listen(tab, "keydown", (event) => {
29689
- if (!state.getItem("keyboard") || !["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
29690
- const keys = [...entries.keys()].filter((key2) => opened.getItem(key2));
29691
- const index = keys.indexOf(key);
29692
- const next = event.key === "Home" ? 0 : event.key === "End" ? keys.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + keys.length) % keys.length;
29693
- event.preventDefault();
29694
- select(keys[next]);
29695
- entries.get(keys[next]).tab.focus();
29696
- });
29697
- if (key === "intro") continue;
29698
- entry.family = entry.open.closest("details");
29699
- if (entry.panel) prepare(entry);
29700
- }
29701
- if (containerLayout) {
29702
- const pages = byId("index-pages");
29703
- listen(pages, "click", (event) => {
29704
- if (event.target === pages && event.composedPath().some((element) => element instanceof window2.Element && element.getAttribute("role") === "tab")) {
29705
- select(state.getItem("active"));
29706
- }
29707
- });
29708
- const subscription = `${shell.id}-selection`;
29709
- state.subscribe(subscription, { any: (event) => {
29710
- if (event.node === state.getNode("active")) select(state.getItem("active"));
29711
- } });
29712
- releases.push(() => state.unsubscribe(subscription, { any: true }));
29713
- }
29714
- listen(document, "pointermove", (event) => {
29715
- if (!drag || event.pointerId !== drag.pointerId) return;
29716
- drag.move(event.clientX);
29717
- });
29718
- for (const type of ["pointerup", "pointercancel"]) listen(document, type, (event) => {
29719
- if (drag && event.pointerId === drag.pointerId) stopDrag();
29720
- });
29721
- for (const family of families) listen(family, "toggle", () => set(family, { open: family.open }));
29722
- listen(keyboard, "change", () => {
29723
- state.setItem("keyboard", keyboard?.checked ?? false);
29724
- set(keyboard, { checked: keyboard?.checked ?? false });
29725
- for (const [key, entry] of entries) {
29726
- if (entry.open) set(entry.open, { tabindex: keyboard?.checked ?? false ? 0 : -1 });
29727
- if (!containerLayout) set(entry.tab, { tabindex: (keyboard?.checked ?? false) && key === state.getItem("active") ? 0 : -1 });
29728
- }
29729
- });
29730
- listen(appearance, "change", () => {
29731
- if (!APPEARANCES.has(appearance?.value ?? "compact")) throw new Error("Unknown index appearance");
29732
- state.setItem("appearance", appearance?.value ?? "compact");
29733
- set(appearance, { value: appearance?.value ?? "compact" });
29734
- for (const option of appearance.options) set(option, { selected: option.value === (appearance?.value ?? "compact") });
29735
- applyTheme();
29736
- savePreferences();
29737
- });
29738
- listen(theme, "change", () => {
29739
- if (!THEMES.has(theme?.value ?? "light")) throw new Error("Index theme must be light or dark");
29740
- state.setItem("theme", theme?.value ?? "light");
29741
- set(theme, { value: theme?.value ?? "light" });
29742
- for (const option of theme.options) set(option, { selected: option.value === (theme?.value ?? "light") });
29743
- applyTheme();
29744
- savePreferences();
29745
- });
29746
- listen(window2, "message", (event) => {
29747
- if (event.data?.type !== THEME_READY) return;
29748
- for (const { frame } of entries.values()) {
29749
- if (frame && frame.contentWindow === event.source) {
29750
- send(frame);
29751
- updateInspector();
29752
- break;
29753
- }
29754
- }
29755
- });
29756
- applyTheme();
29757
- updatePanels();
29758
- updateInspector();
29759
- renderer.onDispose(root, dispose);
29760
- } catch (error) {
29761
- dispose();
29762
- throw error;
29763
- }
29764
- return { dispose };
29789
+ renderer.onDispose(root, dispose);
29790
+ const active = entries.get(state.getItem("active"));
29791
+ if (active) activate(active);
29792
+ else if (state.getItem("navigationSelection") !== null) void select(state.getItem("navigationSelection"));
29793
+ return { entries, dispose };
29765
29794
  }
29766
29795
  var IndexLogic = class {
29767
29796
  indexMount(node, { shell_id }) {
@@ -29771,6 +29800,69 @@ var IndexLogic = class {
29771
29800
  }
29772
29801
  };
29773
29802
 
29803
+ // src/navigation-resolver.js
29804
+ var NavigationResolver = class _NavigationResolver extends RemoteResolver {
29805
+ static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "gramlot", "method", "params", "onError"]);
29806
+ #closed = false;
29807
+ #controller = null;
29808
+ constructor({ gramlot, method, directory, onError }) {
29809
+ super({ cacheTime: -1, onError });
29810
+ this.gramlot = gramlot;
29811
+ this.method = method;
29812
+ this.params = { directory };
29813
+ this.children = /* @__PURE__ */ new Set();
29814
+ }
29815
+ get closed() {
29816
+ return this.#closed;
29817
+ }
29818
+ startLoad(perform) {
29819
+ if (this.loading) return this.loading;
29820
+ const controller = new AbortController();
29821
+ this.#controller = controller;
29822
+ return perform({ controller, method: this.method, params: this.params, ignored: false });
29823
+ }
29824
+ async loadAsync({ controller, method, params }) {
29825
+ const { signal } = controller;
29826
+ let abort;
29827
+ const cancelled = new Promise((_, reject) => {
29828
+ abort = () => reject(signal.reason);
29829
+ signal.addEventListener("abort", abort, { once: true });
29830
+ });
29831
+ try {
29832
+ const value = await Promise.race([this.gramlot.rpc.call("data", method, params, { signal }), cancelled]);
29833
+ if (signal.aborted) throw signal.reason;
29834
+ return value;
29835
+ } finally {
29836
+ signal.removeEventListener("abort", abort);
29837
+ if (this.#controller === controller) this.#controller = null;
29838
+ }
29839
+ }
29840
+ prepareValue(bag) {
29841
+ if (!(bag instanceof Bag)) throw new TypeError("Directory navigation must return a Bag");
29842
+ for (const child of this.children) child.abort();
29843
+ this.children.clear();
29844
+ for (const node of bag.getNodes()) {
29845
+ if (node.attr.directory !== void 0) {
29846
+ const resolver = new _NavigationResolver({
29847
+ gramlot: this.gramlot,
29848
+ method: this.method,
29849
+ directory: node.attr.directory,
29850
+ onError: this.onError
29851
+ });
29852
+ this.children.add(resolver);
29853
+ bag.setResolver(node.label, resolver);
29854
+ }
29855
+ }
29856
+ return bag;
29857
+ }
29858
+ abort() {
29859
+ this.#closed = true;
29860
+ this.#controller?.abort();
29861
+ for (const child of this.children) child.abort();
29862
+ this.children.clear();
29863
+ }
29864
+ };
29865
+
29774
29866
  // src/date-parser/civil.js
29775
29867
  function daysInMonth(year, month) {
29776
29868
  if (month === 2) return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
@@ -30274,6 +30366,7 @@ export {
30274
30366
  BagNode,
30275
30367
  DomHandler,
30276
30368
  Exposed,
30369
+ FramePage,
30277
30370
  Gramlot,
30278
30371
  GramlotBuilder,
30279
30372
  GramlotHtmlRenderer,
@@ -30284,6 +30377,7 @@ export {
30284
30377
  InOut,
30285
30378
  IndexLogic,
30286
30379
  IndexPage,
30380
+ NavigationResolver,
30287
30381
  Page,
30288
30382
  PageBootstrap,
30289
30383
  References,