@gramlot/gramlot 0.3.2 → 0.3.4

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
@@ -24976,12 +24976,7 @@ var HtmlElement = class {
24976
24976
  if (meta.gramlot_component?.sourceContext) {
24977
24977
  element.setSourceContext({
24978
24978
  publish: (topic, payload) => node.publish(topic, payload),
24979
- writeParameter: (name, value) => {
24980
- const pointer = node.getAttr(name);
24981
- if (node.pointerType(pointer) === "^" && !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
24982
- node.setRelativeData(pointer.slice(1), value);
24983
- }
24984
- }
24979
+ writeParameter: (name, value) => this.writeParameter(node, name, value)
24985
24980
  });
24986
24981
  }
24987
24982
  const text = document.createTextNode(this.text(node));
@@ -24994,6 +24989,13 @@ var HtmlElement = class {
24994
24989
  const { tag: tag2, namespace } = this.definition(node);
24995
24990
  return (namespace === XHTML_NS ? record2.tag.toLowerCase() === tag2.toLowerCase() : record2.tag === tag2) && record2.element.namespaceURI === namespace;
24996
24991
  }
24992
+ /** Write a component interaction through a plain reactive Source pointer. */
24993
+ writeParameter(node, name, value) {
24994
+ const pointer = node.getAttr(name);
24995
+ if (node.pointerType(pointer) === "^" && !pointerTransform(pointer) && !Object.is(node.getRelativeData(pointer.slice(1)), value)) {
24996
+ node.setRelativeData(pointer.slice(1), value);
24997
+ }
24998
+ }
24997
24999
  compose(record2, text, children) {
24998
25000
  record2.text.data = text ?? "";
24999
25001
  for (const child of children) record2.element.append(child);
@@ -25022,6 +25024,7 @@ var HtmlElement = class {
25022
25024
  invoke: (name, code, keywords) => this.invokeScript(node, name, code, keywords),
25023
25025
  publish: (topic, payload) => node.publish(topic, payload),
25024
25026
  publishParent: (topic, payload) => parent.publish(topic, payload),
25027
+ writeParameter: (name, value) => this.writeParameter(node, name, value),
25025
25028
  remove: () => node.parentBag.popNode(node.label)
25026
25029
  });
25027
25030
  }
@@ -28878,7 +28881,9 @@ var APPEARANCES = /* @__PURE__ */ new Set(["base", "compact", "mimi", "joanna"])
28878
28881
  // src/index-page-runtime.js
28879
28882
  function mountIndexPage(renderer, root, onSelection = () => {
28880
28883
  }, prepareEntry = () => {
28881
- }, { containerLayout = false, state: suppliedState = null } = {}) {
28884
+ }, { containerLayout = false, state: suppliedState = null, createEntry = null, onLoad = () => {
28885
+ } } = {}) {
28886
+ if (createEntry && !containerLayout) throw new TypeError("Deferred index entries require containerLayout");
28882
28887
  const shell = renderer.records.get(root).element;
28883
28888
  const document = shell.ownerDocument;
28884
28889
  const window2 = document.defaultView;
@@ -28986,17 +28991,53 @@ function mountIndexPage(renderer, root, onSelection = () => {
28986
28991
  set(shell, { data_code_visible: String(visible) });
28987
28992
  }
28988
28993
  };
28994
+ const prepare = (entry) => {
28995
+ entry.panel = byId(`panel-${entry.key}`);
28996
+ entry.tab = containerLayout ? entry.panel : byId(`tab-${entry.key}`);
28997
+ entry.code = byId(`codepane-${entry.key}`);
28998
+ if (entry.key === "intro") return;
28999
+ prepareEntry(entry, { byId, node, set, listen });
29000
+ entry.frame = byId(`frame-${entry.key}`);
29001
+ if (entry.frame) listen(entry.frame, "load", () => send(entry.frame));
29002
+ };
29003
+ const openEntry = (entry) => {
29004
+ if (opened.getItem(entry.key)) return;
29005
+ opened.setItem(entry.key, true);
29006
+ set(containerLayout ? entry.panel : entry.tab, { hidden: false });
29007
+ if (entry.frame) set(entry.frame, { src: entry.open.getAttribute("href") });
29008
+ };
28989
29009
  let selecting = false;
28990
29010
  function select(key) {
28991
- if (selecting) return;
29011
+ if (selecting || disposed) return;
29012
+ const requested = entries.get(key);
29013
+ if (!requested) return;
29014
+ state.setItem("requested", key);
29015
+ if (!requested.panel) {
29016
+ onLoad(key, "loading");
29017
+ if (!requested.loading) {
29018
+ requested.loading = Promise.resolve().then(() => {
29019
+ if (!disposed) return createEntry(requested);
29020
+ }).then(() => {
29021
+ if (disposed) return;
29022
+ prepare(requested);
29023
+ openEntry(requested);
29024
+ if (state.getItem("requested") === key) {
29025
+ onLoad(key, "ready");
29026
+ select(key);
29027
+ }
29028
+ }).catch((error) => {
29029
+ if (!disposed && state.getItem("requested") === key) onLoad(key, "error", error);
29030
+ }).finally(() => {
29031
+ requested.loading = null;
29032
+ });
29033
+ }
29034
+ return;
29035
+ }
29036
+ onLoad(key, "ready");
28992
29037
  selecting = true;
28993
29038
  try {
28994
29039
  const entry = entries.get(key);
28995
- if (!opened.getItem(key)) {
28996
- opened.setItem(key, true);
28997
- set(containerLayout ? entry.panel : entry.tab, { hidden: false });
28998
- if (entry.frame) set(entry.frame, { src: entry.open.getAttribute("href") });
28999
- }
29040
+ openEntry(entry);
29000
29041
  if (entry.family) set(entry.family, { open: true });
29001
29042
  for (const [current, item] of entries) {
29002
29043
  const active = current === key;
@@ -29160,9 +29201,9 @@ function mountIndexPage(renderer, root, onSelection = () => {
29160
29201
  });
29161
29202
  listen(window2, "resize", () => setSidebarWidth(state.getItem("preferredSidebarWidth")));
29162
29203
  }
29163
- const choices = containerLayout ? byId("index-pages").children : shell.querySelectorAll(".index-tabs button");
29204
+ const choices = createEntry ? [byId("panel-intro"), ...shell.querySelectorAll('.index-sidebar a[id^="open-"]')] : containerLayout ? byId("index-pages").children : shell.querySelectorAll(".index-tabs button");
29164
29205
  for (const tab of choices) {
29165
- const key = tab.id.slice(containerLayout ? "panel-".length : "tab-".length);
29206
+ const key = tab.id.slice(createEntry && tab.id.startsWith("open-") ? "open-".length : containerLayout ? "panel-".length : "tab-".length);
29166
29207
  const entry = {
29167
29208
  key,
29168
29209
  tab,
@@ -29171,7 +29212,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
29171
29212
  open: key === "intro" ? null : byId(`open-${key}`)
29172
29213
  };
29173
29214
  entries.set(key, entry);
29174
- if (containerLayout ? node(tab).getAttr("hidden") !== true : !tab.hidden) opened.setItem(key, true);
29215
+ if (entry.panel && (containerLayout ? node(entry.panel).getAttr("hidden") !== true : !tab.hidden)) opened.setItem(key, true);
29175
29216
  if (!containerLayout && tab.getAttribute("aria-selected") === "true") state.setItem("active", key);
29176
29217
  if (!containerLayout) listen(tab, "click", () => select(key));
29177
29218
  if (entry.open) listen(entry.open, "click", (event) => {
@@ -29189,12 +29230,15 @@ function mountIndexPage(renderer, root, onSelection = () => {
29189
29230
  });
29190
29231
  if (key === "intro") continue;
29191
29232
  entry.family = entry.open.closest("details");
29192
- prepareEntry(entry, { byId, node, set, listen });
29193
- if (entry.panel.classList.contains("index-category")) continue;
29194
- entry.frame = byId(`frame-${key}`);
29195
- listen(entry.frame, "load", () => send(entry.frame));
29233
+ if (entry.panel) prepare(entry);
29196
29234
  }
29197
29235
  if (containerLayout) {
29236
+ const pages2 = byId("index-pages");
29237
+ listen(pages2, "click", (event) => {
29238
+ if (event.target === pages2 && event.composedPath().some((element) => element instanceof window2.Element && element.getAttribute("role") === "tab")) {
29239
+ select(state.getItem("active"));
29240
+ }
29241
+ });
29198
29242
  const subscription = `${shell.id}-selection`;
29199
29243
  state.subscribe(subscription, { any: (event) => {
29200
29244
  if (event.node === state.getNode("active")) select(state.getItem("active"));