@rohal12/spindle 0.64.29 → 0.64.31

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.
@@ -3,7 +3,7 @@ import { useCallback, useContext, useEffect, useErrorBoundary, useId, useLayoutE
3
3
  import { memo, useSyncExternalStore } from "preact/compat";
4
4
  import { createStore } from "zustand/vanilla";
5
5
  import { immer } from "zustand/middleware/immer";
6
- import { Immer, current, enableMapSet, enablePatches, freeze, isDraft, original } from "immer";
6
+ import { Immer, current, enableMapSet, enablePatches, freeze, isDraft, original, produce } from "immer";
7
7
  import { shallow } from "zustand/vanilla/shallow";
8
8
  import { Fragment as Fragment$1, jsx, jsxs } from "preact/jsx-runtime";
9
9
  import { micromark } from "micromark";
@@ -9507,13 +9507,13 @@ function registerAction(action, dialog = null, panel = null, element = null) {
9507
9507
  console.warn(`spindle: two mounted controls share the action ID "${id}"; Story.getActions() lists only the newer one.`);
9508
9508
  entries.push(entry);
9509
9509
  } else actions.set(id, [entry]);
9510
- notify();
9510
+ notify$1();
9511
9511
  return {
9512
9512
  update(next) {
9513
9513
  const current = actions.get(id);
9514
9514
  if (!current?.includes(entry)) return;
9515
9515
  entry.action = next;
9516
- if (current[current.length - 1] === entry) notify();
9516
+ if (current[current.length - 1] === entry) notify$1();
9517
9517
  },
9518
9518
  unregister() {
9519
9519
  const current = actions.get(id);
@@ -9524,7 +9524,7 @@ function registerAction(action, dialog = null, panel = null, element = null) {
9524
9524
  actions.delete(id);
9525
9525
  reserved.delete(id);
9526
9526
  }
9527
- if (index === current.length) notify();
9527
+ if (index === current.length) notify$1();
9528
9528
  }
9529
9529
  };
9530
9530
  }
@@ -9594,7 +9594,7 @@ function resetIdCounters() {
9594
9594
  idCounters.clear();
9595
9595
  for (const id of reserved) if (!actions.has(id)) reserved.delete(id);
9596
9596
  }
9597
- function notify() {
9597
+ function notify$1() {
9598
9598
  emit("actionsChanged");
9599
9599
  }
9600
9600
  // src/components/dialog-close-context.ts
@@ -14055,12 +14055,13 @@ function jsCodeEnd(onOpenEnd) {
14055
14055
  var defaultCodeEnd = jsCodeEnd();
14056
14056
  /**
14057
14057
  * Index possible brace ends for repeated recovery attempts in one template.
14058
- * Within plain code, nested braces must close first. At a quote, slash or
14059
- * escape we stop making lexical assumptions, but the remaining raw `}`s
14060
- * still bound how many pending braces could close. Indexing visits each
14061
- * opener once, so unmatched plain-code openers can skip suffix scans.
14058
+ * Within plain code, nested braces must close first. At a quote, slash,
14059
+ * escape or HTML-style comment we stop making lexical assumptions, but the
14060
+ * remaining raw `}`s still bound how many pending braces could close.
14061
+ * Indexing visits each opener once, so unmatched plain-code openers can
14062
+ * skip suffix scans.
14062
14063
  */
14063
- function indexCodeEnds(input) {
14064
+ function indexCodeEnds(input, closeBrace = defaultCodeEnd.closeBrace) {
14064
14065
  const possible = /* @__PURE__ */ new Set();
14065
14066
  const pending = [];
14066
14067
  let remaining = 0;
@@ -14080,12 +14081,12 @@ function indexCodeEnds(input) {
14080
14081
  remaining--;
14081
14082
  const open = pending.pop();
14082
14083
  if (open !== void 0) possible.add(open);
14083
- } else if (/['"`/\\]/.test(c)) uncertain();
14084
+ } else if (/['"`/\\]/.test(c) || input.startsWith("<!--", i) || input.startsWith("-->", i)) uncertain();
14084
14085
  }
14085
14086
  return (start, codeStart = start, limit = input.length) => {
14086
14087
  if (start > lastBrace || codeStart >= limit) return -1;
14087
14088
  const source = limit === input.length ? input : input.slice(0, limit);
14088
- if (input[start - 1] !== "{" || possible.has(start - 1) || input.slice(start, codeStart).includes("{")) return defaultCodeEnd.closeBrace(source, codeStart, start);
14089
+ if (input[start - 1] !== "{" || possible.has(start - 1) || input.slice(start, codeStart).includes("{")) return closeBrace(source, codeStart, start);
14089
14090
  const base = Math.max(0, codeStart - 1);
14090
14091
  const end = parsedCodeEnd(source.slice(base), codeStart - base, "expression");
14091
14092
  return end < 0 ? -1 : base + end;
@@ -15690,9 +15691,8 @@ function locate(text, part, from) {
15690
15691
  return anywhere >= 0 ? anywhere : from;
15691
15692
  }
15692
15693
  // src/widgets/ast-scanner.ts
15693
- /** The declared parameters of the macros registered so far. */
15694
- var registeredParameters = (name) => parameterLookup(getMacroRegistry())(name);
15695
- registeredParameters.source = getMacroParameters.source;
15694
+ /** Snapshot effective macro metadata once per scan. */
15695
+ var registeredParameters = () => parameterLookup(getMacroRegistry());
15696
15696
  /**
15697
15697
  * Whether the text of an attribute value or macro label renders a
15698
15698
  * `{@children}`: it is markup, parsed as the renderer parses it.
@@ -15719,7 +15719,7 @@ function textContainsChildren(text, parametersOf, hooks, budget = new MarkupExpa
15719
15719
  * are read from it); a token made from an AST has none. Discovery hooks
15720
15720
  * also apply inside these texts, before widgets have been registered.
15721
15721
  */
15722
- function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks, budget) {
15722
+ function tokenTextContainsChildren(token, parametersOf = registeredParameters(), src = "", hooks, budget) {
15723
15723
  for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks, budget)) return true;
15724
15724
  return false;
15725
15725
  }
@@ -15730,7 +15730,7 @@ function tokenTextContainsChildren(token, parametersOf = registeredParameters, s
15730
15730
  * entered: its slot belongs to the innermost widget (as widgetDefinitions
15731
15731
  * reads it), and a definition renders nothing of its own.
15732
15732
  */
15733
- function astContainsChildren(nodes, parametersOf = registeredParameters, hooks, budget) {
15733
+ function astContainsChildren(nodes, parametersOf = registeredParameters(), hooks, budget) {
15734
15734
  const pending = [...nodes];
15735
15735
  while (pending.length) {
15736
15736
  const node = pending.pop();
@@ -15837,7 +15837,7 @@ function nameSpan(rawArgs) {
15837
15837
  * here as it is to the parser, and does not make a block widget (#387). In
15838
15838
  * nested definitions, it belongs to the innermost.
15839
15839
  */
15840
- function widgetDefinitions(passages, parametersOf = registeredParameters) {
15840
+ function widgetDefinitions(passages, parametersOf = registeredParameters()) {
15841
15841
  const list = [...passages];
15842
15842
  const scan = (replacesDo) => {
15843
15843
  const found = [];
@@ -15902,7 +15902,7 @@ function effectiveWidgetDefinitions(definitions) {
15902
15902
  * takes a body must be known before any passage is parsed, so that passages
15903
15903
  * invoking them nest their content (or don't) whatever the passage order.
15904
15904
  */
15905
- function effectiveWidgets(passages, parametersOf = registeredParameters) {
15905
+ function effectiveWidgets(passages, parametersOf = registeredParameters()) {
15906
15906
  return effectiveWidgetDefinitions(widgetDefinitions(passages, parametersOf));
15907
15907
  }
15908
15908
  // src/widgets/register-widget-def.ts
@@ -19690,6 +19690,128 @@ function initializeStory(savedSession) {
19690
19690
  recordStoryInitState();
19691
19691
  }
19692
19692
  }
19693
+ // src/utils/control-edits.ts
19694
+ /**
19695
+ * Records the edits made to the items of a list from inside a {for}
19696
+ * iteration, which {for} tells apart from a list that is replaced:
19697
+ *
19698
+ * - a reader editing a variable through a control (`{textbox}`,
19699
+ * `{checkbox}`, ...): typing into a control inside an iteration changes
19700
+ * its item, but must not remount the iteration and drop the control's
19701
+ * focus (#369);
19702
+ * - mutation code an iteration runs as it renders (`{set $party[@i].hp +=
19703
+ * 1}`): remounting would run the iteration's mount-only macros, and so the
19704
+ * write, again for every write it makes (#400).
19705
+ *
19706
+ * An edit is attributed to the variable path it wrote, so a replacement made
19707
+ * elsewhere (a watcher reacting to the edit, a button outside the loop)
19708
+ * still remounts.
19709
+ */
19710
+ var version = 0;
19711
+ var MAX_LOG = 4096;
19712
+ /** Object identities at their own commit; old story graphs stay collectible. */
19713
+ var through = /* @__PURE__ */ new WeakMap();
19714
+ /** Paths, not story graphs: revisit only the prefixes an edit actually used. */
19715
+ var tracked = /* @__PURE__ */ new Map();
19716
+ /** Primitive slot edits also retain their committed value. */
19717
+ var log = [];
19718
+ function note(path, state) {
19719
+ const at = ++version;
19720
+ const key = JSON.stringify(path);
19721
+ tracked.delete(key);
19722
+ tracked.set(key, path);
19723
+ if (tracked.size > MAX_LOG) tracked.delete(tracked.keys().next().value);
19724
+ let node = state;
19725
+ for (const segment of path) {
19726
+ node = node !== null && typeof node === "object" ? getByPath(node, [segment]) : void 0;
19727
+ if (node !== null && typeof node === "object") through.set(node, at);
19728
+ }
19729
+ if (node !== null && typeof node === "object") return;
19730
+ log.push({
19731
+ version: at,
19732
+ path,
19733
+ value: node
19734
+ });
19735
+ if (log.length > MAX_LOG) log.shift();
19736
+ }
19737
+ var activeEdits;
19738
+ function withEdits(edits, run) {
19739
+ const previous = activeEdits;
19740
+ activeEdits = edits;
19741
+ try {
19742
+ run();
19743
+ } finally {
19744
+ activeEdits = previous;
19745
+ }
19746
+ }
19747
+ /** Attribute only the control's own writes, before subscribers can replace them. */
19748
+ function runAsControlEdit(segments, run) {
19749
+ withEdits([["variables", ...segments]], run);
19750
+ }
19751
+ /** Whether mutation code runs inside a {for} iteration. */
19752
+ var ItemEditContext = createContext(false);
19753
+ var NAMESPACES = [
19754
+ "variables",
19755
+ "temporary",
19756
+ "transient"
19757
+ ];
19758
+ /** Run `run`, noting each variable path its own updates change as an edit. */
19759
+ function runAsItemEdit(run) {
19760
+ withEdits("changed", run);
19761
+ }
19762
+ /** Called with finalized state before the store notifies its subscribers. */
19763
+ function notifyItemEdits(before, after, notify) {
19764
+ const compared = /* @__PURE__ */ new WeakMap();
19765
+ for (const path of tracked.values()) {
19766
+ const ns = path[0];
19767
+ if (before[ns] === after[ns]) continue;
19768
+ let previous = before[ns];
19769
+ let next = after[ns];
19770
+ for (const segment of path.slice(1)) {
19771
+ previous = previous !== null && typeof previous === "object" ? getByPath(previous, [segment]) : void 0;
19772
+ next = next !== null && typeof next === "object" ? getByPath(next, [segment]) : void 0;
19773
+ if (previous === null || typeof previous !== "object" || next === null || typeof next !== "object" || previous === next) continue;
19774
+ const edited = through.get(previous);
19775
+ if (edited === void 0) continue;
19776
+ const copies = compared.get(previous) ?? /* @__PURE__ */ new WeakSet();
19777
+ if (copies.has(next)) continue;
19778
+ copies.add(next);
19779
+ compared.set(previous, copies);
19780
+ if (deepEqualStrict(previous, next)) through.set(next, Math.max(through.get(next) ?? 0, edited));
19781
+ }
19782
+ }
19783
+ if (activeEdits === "changed") for (const ns of NAMESPACES) {
19784
+ if (before[ns] === after[ns]) continue;
19785
+ for (const { path } of diffPaths(before[ns], after[ns], true)) note([ns, ...path], after);
19786
+ }
19787
+ else for (const path of activeEdits ?? []) note(path, after);
19788
+ withEdits(void 0, notify);
19789
+ }
19790
+ function controlEditVersion() {
19791
+ return version;
19792
+ }
19793
+ /**
19794
+ * A test of whether an edit made since `since` wrote inside `item`, element
19795
+ * `index` of `list`: the path leads through the item (compared by reference
19796
+ * in `state`), or, for a primitive item, ends at its slot in the list.
19797
+ */
19798
+ function editedItems(since, state) {
19799
+ const ends = /* @__PURE__ */ new Map();
19800
+ for (let i = log.length - 1; i >= 0 && log[i].version > since; i--) {
19801
+ const { path, value } = log[i];
19802
+ const parent = getByPath(state, path.slice(0, -1));
19803
+ const key = path[path.length - 1];
19804
+ if (parent !== null && typeof parent === "object") {
19805
+ const current = getByPath(parent, [key]);
19806
+ if ((current === null || typeof current !== "object") && Object.is(current, value)) {
19807
+ const keys = ends.get(parent) ?? /* @__PURE__ */ new Set();
19808
+ keys.add(key);
19809
+ ends.set(parent, keys);
19810
+ }
19811
+ }
19812
+ }
19813
+ return (list, item, index) => typeof item === "object" && item !== null ? (through.get(item) ?? 0) > since : ends.get(list)?.has(String(index)) === true;
19814
+ }
19693
19815
  // src/passage-roles.ts
19694
19816
  /** Runtime-owned passage roles, shared with stateless authoring tools. */
19695
19817
  var SPECIAL_PASSAGES = /* @__PURE__ */ new Set([
@@ -20455,10 +20577,12 @@ function storyStateGuard(creator) {
20455
20577
  Object.assign(draft, updater);
20456
20578
  };
20457
20579
  const routed = routeStoreUpdate(recipe);
20458
- set((draft) => {
20580
+ const before = get();
20581
+ const next = produce(before, (draft) => {
20459
20582
  (routed ?? recipe)(draft);
20460
20583
  keepNamespacesBare(draft);
20461
20584
  });
20585
+ notifyItemEdits(before, next, () => set(next));
20462
20586
  });
20463
20587
  api.setState = guarded;
20464
20588
  const state = creator(guarded, get, api);
@@ -21032,6 +21156,7 @@ var FOCUSABLE = [
21032
21156
  */
21033
21157
  function isAvailable(el) {
21034
21158
  if (!isRendered(el)) return false;
21159
+ if ((el.ownerDocument.defaultView ?? window).getComputedStyle(el).display === "contents") return false;
21035
21160
  for (let at = el; at; at = composedParent(at)) if (at.hasAttribute("inert")) return false;
21036
21161
  return !el.matches(":disabled");
21037
21162
  }
@@ -21815,7 +21940,13 @@ var values = createNamespace();
21815
21940
  var storageLoaded = false;
21816
21941
  var unsubscribeStoryData = null;
21817
21942
  var listeners = /* @__PURE__ */ new Set();
21818
- /** Call `listener` after a setting changes; returns the unsubscribe. */
21943
+ var revision = 0;
21944
+ var getSettingsRevision = () => revision;
21945
+ function notify() {
21946
+ revision++;
21947
+ for (const listener of [...listeners]) listener();
21948
+ }
21949
+ /** Call `listener` after a definition or value changes; returns the unsubscribe. */
21819
21950
  function subscribeSettings(listener) {
21820
21951
  listeners.add(listener);
21821
21952
  return () => listeners.delete(listener);
@@ -21853,6 +21984,7 @@ function define(name, def) {
21853
21984
  definitions.set(name, def);
21854
21985
  if (!hasOwn(values, name)) values[name] = def.config.default;
21855
21986
  loadFromStorage();
21987
+ notify();
21856
21988
  }
21857
21989
  /** The value of setting `name` if it has the type of `fallback`, else that. */
21858
21990
  function valueOf(name, fallback) {
@@ -21900,7 +22032,7 @@ var settings = {
21900
22032
  values[name] = value;
21901
22033
  persist();
21902
22034
  if (unchanged) return;
21903
- for (const listener of [...listeners]) listener();
22035
+ notify();
21904
22036
  emit("settingchanged", name, value);
21905
22037
  },
21906
22038
  getAll() {
@@ -21913,88 +22045,6 @@ var settings = {
21913
22045
  return definitions.size > 0;
21914
22046
  }
21915
22047
  };
21916
- // src/utils/control-edits.ts
21917
- /**
21918
- * Records the edits made to the items of a list from inside a {for}
21919
- * iteration, which {for} tells apart from a list that is replaced:
21920
- *
21921
- * - a reader editing a variable through a control (`{textbox}`,
21922
- * `{checkbox}`, ...): typing into a control inside an iteration changes
21923
- * its item, but must not remount the iteration and drop the control's
21924
- * focus (#369);
21925
- * - mutation code an iteration runs as it renders (`{set $party[@i].hp +=
21926
- * 1}`): remounting would run the iteration's mount-only macros, and so the
21927
- * write, again for every write it makes (#400).
21928
- *
21929
- * An edit is attributed to the variable path it wrote, so a replacement made
21930
- * elsewhere (a watcher reacting to the edit, a button outside the loop)
21931
- * still remounts.
21932
- */
21933
- var version = 0;
21934
- var MAX_LOG = 4096;
21935
- /** Edits in the order made: paths below the namespaces (`['variables', 'a']`). */
21936
- var log = [];
21937
- function note(path) {
21938
- log.push({
21939
- version: ++version,
21940
- path
21941
- });
21942
- if (log.length > MAX_LOG) log.shift();
21943
- }
21944
- /** Note an edit a control made to the story variable at `segments`. */
21945
- function noteControlEdit(segments) {
21946
- note(["variables", ...segments]);
21947
- }
21948
- /**
21949
- * Whether mutation code runs inside a {for} iteration: {for} provides true
21950
- * around its iterations, and the writes of such code are noted as edits of
21951
- * the items they reach (see runAsItemEdit).
21952
- */
21953
- var ItemEditContext = createContext(false);
21954
- var NAMESPACES = [
21955
- "variables",
21956
- "temporary",
21957
- "transient"
21958
- ];
21959
- /** Run `run`, noting each variable path it changes as an edit. */
21960
- function runAsItemEdit(run) {
21961
- const before = readState();
21962
- try {
21963
- run();
21964
- } finally {
21965
- const after = readState();
21966
- for (const ns of NAMESPACES) {
21967
- if (before[ns] === after[ns]) continue;
21968
- for (const { path } of diffPaths(before[ns], after[ns], true)) note([ns, ...path]);
21969
- }
21970
- }
21971
- }
21972
- function controlEditVersion() {
21973
- return version;
21974
- }
21975
- /**
21976
- * A test of whether an edit made since `since` wrote inside `item`, element
21977
- * `index` of `list`: the path leads through the item (compared by reference
21978
- * in `state`), or, for a primitive item, ends at its slot in the list.
21979
- */
21980
- function editedItems(since, state) {
21981
- const through = /* @__PURE__ */ new Set();
21982
- const ends = /* @__PURE__ */ new Map();
21983
- for (let i = log.length - 1; i >= 0 && log[i].version > since; i--) {
21984
- const { path } = log[i];
21985
- let node = state;
21986
- path.forEach((seg, n) => {
21987
- if (n === path.length - 1 && node !== null && typeof node === "object") {
21988
- const keys = ends.get(node) ?? /* @__PURE__ */ new Set();
21989
- keys.add(seg);
21990
- ends.set(node, keys);
21991
- }
21992
- node = node !== null && typeof node === "object" ? getByPath(node, [seg]) : void 0;
21993
- if (node !== null && typeof node === "object") through.add(node);
21994
- });
21995
- }
21996
- return (list, item, index) => typeof item === "object" && item !== null ? through.has(item) : ends.get(list)?.has(String(index)) === true;
21997
- }
21998
22048
  // src/utils/extract-text.ts
21999
22049
  /**
22000
22050
  * Collect plain text from AST nodes, ignoring non-text nodes.
@@ -22096,9 +22146,10 @@ function defineMacro(config, source = "builtin") {
22096
22146
  ctx.value = getByPath(useStoryFields("variables").variables, segments);
22097
22147
  ctx.getValue = () => getByPath(readState().variables, segments);
22098
22148
  ctx.setValue = displayOnly ? refuse : (value) => {
22099
- noteControlEdit(segments);
22100
- mutateState((work, adopt) => {
22101
- setByPath(work.variables, segments, adopt(value), { createMissing: true });
22149
+ runAsControlEdit(segments, () => {
22150
+ mutateState((work, adopt) => {
22151
+ setByPath(work.variables, segments, adopt(value), { createMissing: true });
22152
+ });
22102
22153
  });
22103
22154
  };
22104
22155
  }
@@ -22423,10 +22474,14 @@ function observableText(el, skip, visibilityRoot) {
22423
22474
  const localTarget = (use) => {
22424
22475
  use = instances.source(use);
22425
22476
  const href = use.getAttribute("href") ?? use.getAttributeNS("http://www.w3.org/1999/xlink", "href");
22426
- if (!href?.startsWith("#") || href.length === 1) return;
22477
+ if (!href) return;
22427
22478
  let id;
22428
22479
  try {
22429
- id = decodeURIComponent(href.slice(1));
22480
+ const url = new URL(href, use.baseURI);
22481
+ const current = new URL(use.ownerDocument.URL);
22482
+ if (url.href.split("#")[0] !== current.href.split("#")[0]) return;
22483
+ if (url.hash.length <= 1) return;
22484
+ id = decodeURIComponent(url.hash.slice(1));
22430
22485
  } catch {
22431
22486
  return;
22432
22487
  }
@@ -25075,7 +25130,10 @@ defineMacro({
25075
25130
  class: ctx.className ?? "story",
25076
25131
  children: [!renderDeferred && readyPassage && /* @__PURE__ */ jsx("div", {
25077
25132
  hidden: true,
25078
- children: renderPassageContent(readyPassage)
25133
+ children: /* @__PURE__ */ jsx(InterfaceContext.Provider, {
25134
+ value: false,
25135
+ children: renderPassageContent(readyPassage)
25136
+ })
25079
25137
  }, `ready-${navigationId}`), /* @__PURE__ */ jsx("div", {
25080
25138
  class: "passage-container",
25081
25139
  ref: containerRef,
@@ -26010,44 +26068,49 @@ function hotkeyTitle(label, key) {
26010
26068
  return key ? `${label} (${key})` : label;
26011
26069
  }
26012
26070
  function defineMenubarAction(config) {
26071
+ function Button({ className, id }) {
26072
+ const [dialogOpen, setDialogOpen] = useState(false);
26073
+ const setup = config.setup?.() ?? { perform: () => {} };
26074
+ const { disabled, title = config.title } = setup;
26075
+ const cls = className ? `menubar-button ${className}` : "menubar-button";
26076
+ const perform = config.dialog ? () => setDialogOpen(true) : config.confirm ? () => {
26077
+ if (confirm(config.confirm)) setup.perform();
26078
+ } : setup.perform;
26079
+ const action = useControlAction({
26080
+ type: config.actionType,
26081
+ key: config.name,
26082
+ authorId: id,
26083
+ label: typeof config.label === "string" ? config.label : config.name,
26084
+ disabled,
26085
+ perform: config.dialog ? () => setDialogOpen(true) : setup.perform
26086
+ });
26087
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
26088
+ type: "button",
26089
+ ...actionAttributes(action, {
26090
+ id,
26091
+ cls
26092
+ }),
26093
+ onClick: perform,
26094
+ disabled,
26095
+ title,
26096
+ children: config.label
26097
+ }), config.dialog && dialogOpen && /* @__PURE__ */ jsx(PassageDialog, {
26098
+ passageName: config.dialog.passageName,
26099
+ fallbackMarkup: config.dialog.fallbackMarkup,
26100
+ panelClass: config.dialog.panelClass,
26101
+ label: typeof config.label === "string" ? config.label : config.name,
26102
+ onClose: () => setDialogOpen(false),
26103
+ showCloseButton: config.dialog.showCloseButton
26104
+ })] });
26105
+ }
26013
26106
  defineMacro({
26014
26107
  name: config.name,
26015
26108
  interpolate: true,
26016
26109
  render(_, ctx) {
26017
- if (config.hidden?.()) return null;
26018
- const [dialogOpen, setDialogOpen] = useState(false);
26019
- const setup = config.setup?.() ?? { perform: () => {} };
26020
- const { disabled, title = config.title } = setup;
26021
- const cls = ctx.className ? `menubar-button ${ctx.className}` : "menubar-button";
26022
- const perform = config.dialog ? () => setDialogOpen(true) : config.confirm ? () => {
26023
- if (confirm(config.confirm)) setup.perform();
26024
- } : setup.perform;
26025
- const action = useControlAction({
26026
- type: config.actionType,
26027
- key: config.name,
26028
- authorId: ctx.id,
26029
- label: typeof config.label === "string" ? config.label : config.name,
26030
- disabled,
26031
- perform: config.dialog ? () => setDialogOpen(true) : setup.perform
26110
+ return config.useHidden?.() ? null : /* @__PURE__ */ jsx(Button, {
26111
+ className: ctx.className,
26112
+ id: ctx.id
26032
26113
  });
26033
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
26034
- type: "button",
26035
- ...actionAttributes(action, {
26036
- id: ctx.id,
26037
- cls
26038
- }),
26039
- onClick: perform,
26040
- disabled,
26041
- title,
26042
- children: config.label
26043
- }), config.dialog && dialogOpen && /* @__PURE__ */ jsx(PassageDialog, {
26044
- passageName: config.dialog.passageName,
26045
- fallbackMarkup: config.dialog.fallbackMarkup,
26046
- panelClass: config.dialog.panelClass,
26047
- label: typeof config.label === "string" ? config.label : config.name,
26048
- onClose: () => setDialogOpen(false),
26049
- showCloseButton: config.dialog.showCloseButton
26050
- })] });
26051
26114
  }
26052
26115
  });
26053
26116
  }
@@ -26116,7 +26179,7 @@ defineMenubarAction({
26116
26179
  name: "settings",
26117
26180
  label: "Settings",
26118
26181
  actionType: "dialog",
26119
- hidden: () => !settings.hasAny(),
26182
+ useHidden: () => !useSyncExternalStore(subscribeSettings, settings.hasAny),
26120
26183
  dialog: {
26121
26184
  passageName: "Settings",
26122
26185
  fallbackMarkup: "{settings-controls}",
@@ -26644,6 +26707,7 @@ function SettingControl({ name, def }) {
26644
26707
  });
26645
26708
  }
26646
26709
  function SettingsControlsContent({ className, id }) {
26710
+ useSyncExternalStore(subscribeSettings, getSettingsRevision);
26647
26711
  const defs = settings.getDefinitions();
26648
26712
  return /* @__PURE__ */ jsx("div", {
26649
26713
  id,