@rohal12/spindle 0.64.27 → 0.64.29
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/pkg/format.js +1 -1
- package/dist/pkg/headless.js +133 -48
- package/dist/pkg/story-variables.js +6 -1
- package/package.json +1 -1
- package/src/action-registry.ts +5 -1
- package/src/class-registry.ts +1 -11
- package/src/code-check.ts +2 -2
- package/src/components/macros/Dialog.tsx +2 -4
- package/src/components/macros/Type.tsx +1 -0
- package/src/components/macros/arg-utils.ts +6 -0
- package/src/execute-mutation.ts +10 -0
- package/src/hooks/use-modal-focus.ts +3 -14
- package/src/observe/observable-text.ts +19 -5
- package/src/story-api.ts +21 -16
- package/src/structural.ts +7 -9
- package/src/utils/element-visibility.ts +89 -7
- package/src/utils/namespace.ts +15 -6
- package/src/utils/object-path.ts +2 -7
- package/src/utils/type-reveal.ts +55 -0
package/dist/pkg/headless.js
CHANGED
|
@@ -92,11 +92,36 @@ var SVG_NOT_TEXT = /* @__PURE__ */ new Set([
|
|
|
92
92
|
"pattern",
|
|
93
93
|
"marker"
|
|
94
94
|
]);
|
|
95
|
+
var hiddenDefaults = /* @__PURE__ */ new WeakSet();
|
|
96
|
+
var needsHiddenDefaults = /* @__PURE__ */ new WeakMap();
|
|
97
|
+
function ensureHiddenDefaults(el) {
|
|
98
|
+
if (!el.hasAttribute("hidden")) return;
|
|
99
|
+
const doc = el.ownerDocument;
|
|
100
|
+
const view = doc.defaultView ?? globalThis.window;
|
|
101
|
+
let needed = needsHiddenDefaults.get(doc);
|
|
102
|
+
if (needed === void 0) {
|
|
103
|
+
const detached = doc.implementation.createHTMLDocument("");
|
|
104
|
+
const probe = detached.createElement("div");
|
|
105
|
+
probe.hidden = true;
|
|
106
|
+
detached.body.append(probe);
|
|
107
|
+
needed = view?.getComputedStyle(probe).display === "block";
|
|
108
|
+
needsHiddenDefaults.set(doc, needed);
|
|
109
|
+
}
|
|
110
|
+
const root = el.getRootNode();
|
|
111
|
+
if (!needed || hiddenDefaults.has(root)) return;
|
|
112
|
+
const container = root.nodeType === 9 ? root.head : root;
|
|
113
|
+
if (root.nodeType !== 9 && !("host" in root)) return;
|
|
114
|
+
const style = doc.createElement("style");
|
|
115
|
+
style.textContent = ":where([hidden]:not([hidden=\"until-found\" i])){display:none}:where([hidden=\"until-found\" i]){content-visibility:hidden}";
|
|
116
|
+
container.prepend(style);
|
|
117
|
+
hiddenDefaults.add(root);
|
|
118
|
+
}
|
|
95
119
|
/** Detached/headless DOMs may have no computed value; CSSOM still resolves
|
|
96
120
|
* duplicate inline declarations and priorities correctly.
|
|
97
121
|
*/
|
|
98
122
|
function styleValue(el, name) {
|
|
99
|
-
|
|
123
|
+
ensureHiddenDefaults(el);
|
|
124
|
+
return (el.ownerDocument.defaultView ?? globalThis.window)?.getComputedStyle?.(el).getPropertyValue(name) || el.style?.getPropertyValue(name) || "";
|
|
100
125
|
}
|
|
101
126
|
/**
|
|
102
127
|
* Whether the element hides its whole subtree, including stylesheet rules.
|
|
@@ -104,7 +129,32 @@ function styleValue(el, name) {
|
|
|
104
129
|
* A symbol referenced by SVG use is rendered only as an instance root.
|
|
105
130
|
*/
|
|
106
131
|
function isHidden(el, svgInstanceRoot = false) {
|
|
107
|
-
|
|
132
|
+
const display = styleValue(el, "display");
|
|
133
|
+
return el.hasAttribute("hidden") && el.getAttribute("hidden")?.toLowerCase() !== "until-found" && display === "" || el.getAttribute("aria-hidden") === "true" || display === "none" || NOT_TEXT.has(el.localName.toLowerCase()) || el.namespaceURI === "http://www.w3.org/2000/svg" && SVG_NOT_TEXT.has(el.localName.toLowerCase()) && !(svgInstanceRoot && el.localName.toLowerCase() === "symbol") || el.parentElement?.tagName === "DETAILS" && !el.parentElement.hasAttribute("open") && el !== Array.from(el.parentElement.children).find((c) => c.tagName === "SUMMARY");
|
|
134
|
+
}
|
|
135
|
+
var NO_LAYOUT_CONTAINMENT = /* @__PURE__ */ new Set([
|
|
136
|
+
"none",
|
|
137
|
+
"contents",
|
|
138
|
+
"ruby",
|
|
139
|
+
"ruby-base",
|
|
140
|
+
"ruby-text",
|
|
141
|
+
"ruby-base-container",
|
|
142
|
+
"ruby-text-container",
|
|
143
|
+
"table-row",
|
|
144
|
+
"table-row-group",
|
|
145
|
+
"table-header-group",
|
|
146
|
+
"table-footer-group",
|
|
147
|
+
"table-column",
|
|
148
|
+
"table-column-group"
|
|
149
|
+
]);
|
|
150
|
+
/** content-visibility suppresses contents only in layout containment boxes. */
|
|
151
|
+
function hidesContents(el) {
|
|
152
|
+
const value = styleValue(el, "content-visibility");
|
|
153
|
+
if (!(value === "hidden" || value === "" && el.getAttribute("hidden")?.toLowerCase() === "until-found")) return false;
|
|
154
|
+
const display = styleValue(el, "display") || (el.localName === "td" || el.localName === "th" ? "table-cell" : "inline");
|
|
155
|
+
if (NO_LAYOUT_CONTAINMENT.has(display)) return false;
|
|
156
|
+
if (display === "inline" || display === "inline list-item") return el.namespaceURI === "http://www.w3.org/2000/svg" || el.matches("img, input, textarea, select, button, fieldset, video, audio, canvas, iframe, embed");
|
|
157
|
+
return true;
|
|
108
158
|
}
|
|
109
159
|
/**
|
|
110
160
|
* Whether `el` is in a closed `<details>`, other than in the summary that
|
|
@@ -134,6 +184,7 @@ function isRendered(el, root, checkVisibility = true) {
|
|
|
134
184
|
if (checkVisibility && (visibility === "hidden" || visibility === "collapse")) return false;
|
|
135
185
|
for (let e = el; e; e = composedParent(e)) {
|
|
136
186
|
if (styleValue(e, "display") === "none") return false;
|
|
187
|
+
if (e !== el && hidesContents(e)) return false;
|
|
137
188
|
if (e === root) break;
|
|
138
189
|
const parent = e.parentElement;
|
|
139
190
|
if (parent?.shadowRoot && !e.assignedSlot) return false;
|
|
@@ -147,6 +198,35 @@ function isReaderVisible(el) {
|
|
|
147
198
|
for (let at = el; at; at = composedParent(at)) if (isHidden(at) || at.hasAttribute("inert")) return false;
|
|
148
199
|
return true;
|
|
149
200
|
}
|
|
201
|
+
// src/utils/type-reveal.ts
|
|
202
|
+
/** Remaining revealed characters at this node, across nested typewriters. */
|
|
203
|
+
function revealedCharacters(node) {
|
|
204
|
+
let available = Infinity;
|
|
205
|
+
const element = node.nodeType === 1 ? node : node.parentElement;
|
|
206
|
+
for (let at = element; at; at = composedParent(at)) {
|
|
207
|
+
const count = at.getAttribute("data-type-revealed");
|
|
208
|
+
if (count === null) continue;
|
|
209
|
+
let left = Number(count);
|
|
210
|
+
if (!Number.isFinite(left)) continue;
|
|
211
|
+
if (!at.contains(node)) return 0;
|
|
212
|
+
for (let child = node; child !== at; child = child.parentNode) for (let sibling = child.previousSibling; sibling; sibling = sibling.previousSibling) if (sibling.nodeType === 1 || sibling.nodeType === 3) left -= sibling.textContent?.length ?? 0;
|
|
213
|
+
available = Math.min(available, Math.max(0, left));
|
|
214
|
+
}
|
|
215
|
+
return available;
|
|
216
|
+
}
|
|
217
|
+
/** Only the prefix that every containing typewriter has revealed. */
|
|
218
|
+
function revealedText(node) {
|
|
219
|
+
return node.data.slice(0, revealedCharacters(node));
|
|
220
|
+
}
|
|
221
|
+
/** Offer a control once its entire label is revealed, avoiding label spoilers.
|
|
222
|
+
* Controls without DOM text have no measured clip boxes; wait for completion.
|
|
223
|
+
*/
|
|
224
|
+
function isFullyRevealed(el) {
|
|
225
|
+
const available = revealedCharacters(el);
|
|
226
|
+
if (available !== Infinity && (!el.textContent || available < el.textContent.length)) return false;
|
|
227
|
+
for (const child of composedElements(el)) if (child.hasAttribute("data-type-revealed") && revealedCharacters(child) < (child.textContent?.length ?? 0)) return false;
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
150
230
|
// src/prng.ts
|
|
151
231
|
/**
|
|
152
232
|
* Seedable PRNG for Spindle — Mulberry32 algorithm.
|
|
@@ -6458,17 +6538,21 @@ var isArrayIndex = (key) => /^(?:0|[1-9]\d*)$/.test(key);
|
|
|
6458
6538
|
var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
6459
6539
|
/** `ns[key]` if `ns` holds it as an own property, else undefined. */
|
|
6460
6540
|
var ownValue = (ns, key) => ns && hasOwn(ns, key) ? ns[key] : void 0;
|
|
6461
|
-
/**
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
*/
|
|
6465
|
-
function setOwn(target, key, value) {
|
|
6466
|
-
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
6541
|
+
/** Define an own data field without invoking an inherited accessor. */
|
|
6542
|
+
function defineData(target, key, value) {
|
|
6543
|
+
Object.defineProperty(target, key, {
|
|
6467
6544
|
value,
|
|
6468
6545
|
enumerable: true,
|
|
6469
6546
|
writable: true,
|
|
6470
6547
|
configurable: true
|
|
6471
6548
|
});
|
|
6549
|
+
}
|
|
6550
|
+
/**
|
|
6551
|
+
* Set an own enumerable property. A "__proto__" key is defined as an own
|
|
6552
|
+
* property (as JSON.parse does) instead of replacing the prototype.
|
|
6553
|
+
*/
|
|
6554
|
+
function setOwn(target, key, value) {
|
|
6555
|
+
if (key === "__proto__") defineData(target, key, value);
|
|
6472
6556
|
else target[key] = value;
|
|
6473
6557
|
}
|
|
6474
6558
|
/**
|
|
@@ -7582,14 +7666,6 @@ var isObject = (v) => typeof v === "object" && v !== null;
|
|
|
7582
7666
|
/** Whether `v` is a plain object (as devalue revives one). */
|
|
7583
7667
|
var isPlainData = (v) => isObject(v) && Object.getPrototypeOf(v) === Object.prototype;
|
|
7584
7668
|
var malformedClass = (name) => /* @__PURE__ */ new TypeError(`spindle: Malformed data for class "${name}"`);
|
|
7585
|
-
var defineData = (target, key, value) => {
|
|
7586
|
-
Object.defineProperty(target, key, {
|
|
7587
|
-
value,
|
|
7588
|
-
enumerable: true,
|
|
7589
|
-
writable: true,
|
|
7590
|
-
configurable: true
|
|
7591
|
-
});
|
|
7592
|
-
};
|
|
7593
7669
|
/**
|
|
7594
7670
|
* A reducer extracts string keys, so devalue never sees the symbol keys of
|
|
7595
7671
|
* the original object: refuse them here, as it does for a plain object.
|
|
@@ -7931,12 +8007,7 @@ var builtinName = atomicName;
|
|
|
7931
8007
|
*/
|
|
7932
8008
|
function shallowCopy(value) {
|
|
7933
8009
|
const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
|
|
7934
|
-
for (const key of Object.keys(value))
|
|
7935
|
-
value: value[key],
|
|
7936
|
-
enumerable: true,
|
|
7937
|
-
writable: true,
|
|
7938
|
-
configurable: true
|
|
7939
|
-
});
|
|
8010
|
+
for (const key of Object.keys(value)) defineData(copy, key, value[key]);
|
|
7940
8011
|
return copy;
|
|
7941
8012
|
}
|
|
7942
8013
|
/**
|
|
@@ -8049,7 +8120,7 @@ function builtinLike(obj, empty, made, value) {
|
|
|
8049
8120
|
made(empty);
|
|
8050
8121
|
if (registeredClassName(obj) === void 0) return empty;
|
|
8051
8122
|
Object.setPrototypeOf(empty, Object.getPrototypeOf(obj));
|
|
8052
|
-
for (const key of extraKeys(obj))
|
|
8123
|
+
for (const key of extraKeys(obj)) defineData(empty, key, value(key));
|
|
8053
8124
|
return empty;
|
|
8054
8125
|
}
|
|
8055
8126
|
function deepClone(value, options = {}) {
|
|
@@ -8064,10 +8135,10 @@ function deepClone(value, options = {}) {
|
|
|
8064
8135
|
* save refuses them, which a copy must not hide.
|
|
8065
8136
|
*/
|
|
8066
8137
|
function copyKeys(obj, copy) {
|
|
8067
|
-
for (const key of Object.keys(obj))
|
|
8138
|
+
for (const key of Object.keys(obj)) defineData(copy, key, clone(obj[key]));
|
|
8068
8139
|
for (const sym of Object.getOwnPropertySymbols(obj)) {
|
|
8069
8140
|
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) continue;
|
|
8070
|
-
copy
|
|
8141
|
+
defineData(copy, sym, clone(obj[sym]));
|
|
8071
8142
|
}
|
|
8072
8143
|
return copy;
|
|
8073
8144
|
}
|
|
@@ -8115,7 +8186,7 @@ function deepClone(value, options = {}) {
|
|
|
8115
8186
|
if (seen.has(obj)) return seen.get(obj);
|
|
8116
8187
|
if (Array.isArray(val)) {
|
|
8117
8188
|
const arr = builtin(obj, new Array(val.length));
|
|
8118
|
-
for (const key of arrayIndices(val)) arr
|
|
8189
|
+
for (const key of arrayIndices(val)) defineData(arr, key, clone(val[Number(key)]));
|
|
8119
8190
|
return arr;
|
|
8120
8191
|
}
|
|
8121
8192
|
if (val instanceof Map) {
|
|
@@ -8241,13 +8312,13 @@ function shareEqual(prev, curr) {
|
|
|
8241
8312
|
}
|
|
8242
8313
|
if (Array.isArray(c) && Array.isArray(p)) {
|
|
8243
8314
|
const out = collection(new Array(c.length));
|
|
8244
|
-
for (const key of arrayIndices(c)) out
|
|
8315
|
+
for (const key of arrayIndices(c)) defineData(out, key, shareKey(key));
|
|
8245
8316
|
return out;
|
|
8246
8317
|
}
|
|
8247
8318
|
if (mergesWith(p, c, false)) {
|
|
8248
8319
|
const out = Object.create(Object.getPrototypeOf(c));
|
|
8249
8320
|
done.set(c, out);
|
|
8250
|
-
for (const key of Object.keys(cr))
|
|
8321
|
+
for (const key of Object.keys(cr)) defineData(out, key, shareKey(key));
|
|
8251
8322
|
return out;
|
|
8252
8323
|
}
|
|
8253
8324
|
return fresh(c);
|
|
@@ -8845,6 +8916,13 @@ function clonerFor(target, paths) {
|
|
|
8845
8916
|
settle
|
|
8846
8917
|
});
|
|
8847
8918
|
}
|
|
8919
|
+
/** Adopt setter inputs into a draft, retaining references to owned state. */
|
|
8920
|
+
function adoptStateValues(target) {
|
|
8921
|
+
const held = locateObjects(namespacesOf(useStoryStore.getState()), []);
|
|
8922
|
+
const scope = getActiveMutationScope();
|
|
8923
|
+
if (scope) for (const [value, path] of locateObjects(scope, [])) held.set(value, path);
|
|
8924
|
+
return clonerFor(target, held);
|
|
8925
|
+
}
|
|
8848
8926
|
/** One cloner per target copy, made when first used. */
|
|
8849
8927
|
var clonersFor = (paths) => {
|
|
8850
8928
|
const made = /* @__PURE__ */ new Map();
|
|
@@ -9510,7 +9588,7 @@ function effectiveAction(action) {
|
|
|
9510
9588
|
/** Whether any connected instance of this action is visible to a reader. */
|
|
9511
9589
|
function isActionVisible(action) {
|
|
9512
9590
|
const elements = actionElements(action.id);
|
|
9513
|
-
return elements.length === 0 || elements.some(isReaderVisible);
|
|
9591
|
+
return elements.length === 0 || elements.some((el) => isReaderVisible(el) && isFullyRevealed(el));
|
|
9514
9592
|
}
|
|
9515
9593
|
function resetIdCounters() {
|
|
9516
9594
|
idCounters.clear();
|
|
@@ -14469,6 +14547,11 @@ function readWholeQuoted(src) {
|
|
|
14469
14547
|
const quoted = readQuoted(src, 0);
|
|
14470
14548
|
return quoted && quoted.end === src.length ? quoted.value : null;
|
|
14471
14549
|
}
|
|
14550
|
+
/** A dialog body's passage name, optionally enclosed in matching quotes. */
|
|
14551
|
+
function readPassageBody(src) {
|
|
14552
|
+
const name = src.trim();
|
|
14553
|
+
return readWholeQuoted(name) ?? name;
|
|
14554
|
+
}
|
|
14472
14555
|
/**
|
|
14473
14556
|
* Strip an optional quote from each end of an unquoted-or-loosely-quoted
|
|
14474
14557
|
* argument (`"Red`, `Red'`), leaving at least one character. This is the
|
|
@@ -15252,7 +15335,7 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
15252
15335
|
const written = text.trim();
|
|
15253
15336
|
yield {
|
|
15254
15337
|
kind: "passage",
|
|
15255
|
-
name: written
|
|
15338
|
+
name: readPassageBody(written),
|
|
15256
15339
|
offset: token.end + text.indexOf(written),
|
|
15257
15340
|
length: written.length,
|
|
15258
15341
|
macro: name,
|
|
@@ -20949,12 +21032,7 @@ var FOCUSABLE = [
|
|
|
20949
21032
|
*/
|
|
20950
21033
|
function isAvailable(el) {
|
|
20951
21034
|
if (!isRendered(el)) return false;
|
|
20952
|
-
for (let at = el; at; at = composedParent(at))
|
|
20953
|
-
if (at.hasAttribute("hidden") || at.hasAttribute("inert")) return false;
|
|
20954
|
-
if (at.ownerDocument.defaultView?.getComputedStyle(at).display === "none") return false;
|
|
20955
|
-
const parent = composedParent(at);
|
|
20956
|
-
if (parent?.localName === "details" && !parent.hasAttribute("open") && at !== Array.from(parent.children).find((child) => child.localName === "summary")) return false;
|
|
20957
|
-
}
|
|
21035
|
+
for (let at = el; at; at = composedParent(at)) if (at.hasAttribute("inert")) return false;
|
|
20958
21036
|
return !el.matches(":disabled");
|
|
20959
21037
|
}
|
|
20960
21038
|
/** The `tabindex` of `el` as an integer, or null when absent or invalid. */
|
|
@@ -22359,8 +22437,8 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22359
22437
|
if (instanceRoot && --instanceNodes < 0) return;
|
|
22360
22438
|
if (node.nodeType === 3) {
|
|
22361
22439
|
const parent = node.assignedSlot ?? node.parentElement ?? node.getRootNode().host;
|
|
22362
|
-
if (parent && !isRendered(parent, instanceRoot ?? visibilityRoot)) return;
|
|
22363
|
-
const data = node
|
|
22440
|
+
if (parent && (hidesContents(parent) || !isRendered(parent, instanceRoot ?? visibilityRoot))) return;
|
|
22441
|
+
const data = revealedText(node);
|
|
22364
22442
|
if (inPre) out += data;
|
|
22365
22443
|
else {
|
|
22366
22444
|
const collapsed = data.replace(/\s+/g, " ");
|
|
@@ -22371,8 +22449,9 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22371
22449
|
if (node.nodeType !== 1) return;
|
|
22372
22450
|
const child = node;
|
|
22373
22451
|
if (isHidden(child, child === instanceRoot) || skip && child !== el && child.matches(skip)) return;
|
|
22452
|
+
if (!isRendered(child, instanceRoot ?? visibilityRoot, false)) return;
|
|
22374
22453
|
if (child.namespaceURI === "http://www.w3.org/2000/svg" && child.localName === "use") {
|
|
22375
|
-
if (
|
|
22454
|
+
if (hidesContents(child) || !isFullyRevealed(child)) return;
|
|
22376
22455
|
const target = localTarget(child);
|
|
22377
22456
|
if (!target || target.namespaceURI !== child.namespaceURI || references.has(target) || references.size >= 32) return;
|
|
22378
22457
|
references.add(target);
|
|
@@ -22383,7 +22462,7 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22383
22462
|
}
|
|
22384
22463
|
if (child.matches("input, textarea, select") || child.hasAttribute("data-action") && getAction(child.getAttribute("data-action"))?.type === "cycle") {
|
|
22385
22464
|
if (child.matches("input[type=\"hidden\" i]")) return;
|
|
22386
|
-
if (!isRendered(child, instanceRoot ?? visibilityRoot)) return;
|
|
22465
|
+
if (!isRendered(child, instanceRoot ?? visibilityRoot) || !isFullyRevealed(child)) return;
|
|
22387
22466
|
out += controlMarker(child);
|
|
22388
22467
|
return;
|
|
22389
22468
|
}
|
|
@@ -22392,6 +22471,7 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22392
22471
|
return;
|
|
22393
22472
|
}
|
|
22394
22473
|
const block = BLOCKS.has(child.tagName);
|
|
22474
|
+
if (hidesContents(child)) return;
|
|
22395
22475
|
if (block) endLine();
|
|
22396
22476
|
const closedDetails = child.tagName === "DETAILS" && !child.hasAttribute("open");
|
|
22397
22477
|
const rendered = composedChildNodes(child);
|
|
@@ -22421,7 +22501,7 @@ function observableErrors(el, skip, visibilityRoot) {
|
|
|
22421
22501
|
}
|
|
22422
22502
|
return false;
|
|
22423
22503
|
};
|
|
22424
|
-
return [...composedElements(el)].filter((e) => e.matches(".error") && !left(e) && isRendered(e, visibilityRoot)).map((e) => observableText(e, skip, visibilityRoot).trim());
|
|
22504
|
+
return [...composedElements(el)].filter((e) => e.matches(".error") && !left(e) && isRendered(e, visibilityRoot)).map((e) => observableText(e, skip, visibilityRoot).trim()).filter(Boolean);
|
|
22425
22505
|
}
|
|
22426
22506
|
// src/utils/stable-key.ts
|
|
22427
22507
|
/**
|
|
@@ -22685,10 +22765,13 @@ function warnIfUndeclared(isTransient, key) {
|
|
|
22685
22765
|
warnedUndeclared.add(label);
|
|
22686
22766
|
console.warn(`spindle: Story.set() wrote ${label}, which is not declared in ${isTransient ? "StoryTransients" : "StoryVariables"}. Passages cannot reference it; check the name or declare it.`);
|
|
22687
22767
|
}
|
|
22688
|
-
/**
|
|
22689
|
-
function
|
|
22690
|
-
const
|
|
22691
|
-
|
|
22768
|
+
/** Adopt the whole batch before writes can replace state-owned inputs. */
|
|
22769
|
+
function setEntries(draft, entries, adopt) {
|
|
22770
|
+
const adopted = entries.map(([name, value]) => [name, adopt(value)]);
|
|
22771
|
+
for (const [name, value] of adopted) {
|
|
22772
|
+
const { isTransient, key } = parseName(name);
|
|
22773
|
+
setByPath(isTransient ? draft.transient : draft.variables, key.split("."), value);
|
|
22774
|
+
}
|
|
22692
22775
|
}
|
|
22693
22776
|
/**
|
|
22694
22777
|
* The history index `index` names (the current moment's when left out), or
|
|
@@ -22726,12 +22809,13 @@ function createStoryAPI() {
|
|
|
22726
22809
|
}
|
|
22727
22810
|
if (entries.some(([k]) => k.includes("."))) {
|
|
22728
22811
|
mutateState((work, adopt) => {
|
|
22729
|
-
|
|
22812
|
+
setEntries(work, entries, adopt);
|
|
22730
22813
|
});
|
|
22731
22814
|
return;
|
|
22732
22815
|
}
|
|
22733
22816
|
useStoryStore.getState().updateVariables((draft) => {
|
|
22734
|
-
|
|
22817
|
+
const adopt = adoptStateValues(draft);
|
|
22818
|
+
setEntries(draft, entries, adopt);
|
|
22735
22819
|
});
|
|
22736
22820
|
},
|
|
22737
22821
|
goto: storeAction("navigate"),
|
|
@@ -25859,6 +25943,7 @@ defineMacro({
|
|
|
25859
25943
|
children: [/* @__PURE__ */ jsx("span", {
|
|
25860
25944
|
ref: innerRef,
|
|
25861
25945
|
class: "macro-type-inner",
|
|
25946
|
+
"data-type-revealed": done ? void 0 : visibleChars,
|
|
25862
25947
|
style: {
|
|
25863
25948
|
display: "inline",
|
|
25864
25949
|
visibility: measured === null ? "hidden" : "visible",
|
|
@@ -26056,7 +26141,7 @@ defineMacro({
|
|
|
26056
26141
|
const [open, setOpen] = ctx.hooks.useState(false);
|
|
26057
26142
|
const { noclose } = ctx.args;
|
|
26058
26143
|
const label = ctx.resolve(ctx.args.label ?? "") ?? "";
|
|
26059
|
-
const passageName = ctx.collectText(children)
|
|
26144
|
+
const passageName = readPassageBody(ctx.collectText(children));
|
|
26060
26145
|
const openDialog = () => setOpen(true);
|
|
26061
26146
|
const action = useControlAction({
|
|
26062
26147
|
type: "open-dialog",
|
|
@@ -10975,6 +10975,11 @@ function readWholeQuoted(src) {
|
|
|
10975
10975
|
const quoted = readQuoted(src, 0);
|
|
10976
10976
|
return quoted && quoted.end === src.length ? quoted.value : null;
|
|
10977
10977
|
}
|
|
10978
|
+
/** A dialog body's passage name, optionally enclosed in matching quotes. */
|
|
10979
|
+
function readPassageBody(src) {
|
|
10980
|
+
const name = src.trim();
|
|
10981
|
+
return readWholeQuoted(name) ?? name;
|
|
10982
|
+
}
|
|
10978
10983
|
/**
|
|
10979
10984
|
* Strip an optional quote from each end of an unquoted-or-loosely-quoted
|
|
10980
10985
|
* argument (`"Red`, `Red'`), leaving at least one character. This is the
|
|
@@ -11760,7 +11765,7 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11760
11765
|
const written = text.trim();
|
|
11761
11766
|
yield {
|
|
11762
11767
|
kind: "passage",
|
|
11763
|
-
name: written
|
|
11768
|
+
name: readPassageBody(written),
|
|
11764
11769
|
offset: token.end + text.indexOf(written),
|
|
11765
11770
|
length: written.length,
|
|
11766
11771
|
macro: name,
|
package/package.json
CHANGED
package/src/action-registry.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isReaderVisible } from './utils/element-visibility';
|
|
2
|
+
import { isFullyRevealed } from './utils/type-reveal';
|
|
2
3
|
import { readOnlyValue } from './execute-mutation';
|
|
3
4
|
import { emit } from './event-emitter';
|
|
4
5
|
import {
|
|
@@ -307,7 +308,10 @@ export function isActionVisible(action: StoryAction): boolean {
|
|
|
307
308
|
// Older custom actions need not associate a DOM control. Keep those
|
|
308
309
|
// registrations available; built-ins and associated custom controls are
|
|
309
310
|
// filtered against the live DOM.
|
|
310
|
-
return
|
|
311
|
+
return (
|
|
312
|
+
elements.length === 0 ||
|
|
313
|
+
elements.some((el) => isReaderVisible(el) && isFullyRevealed(el))
|
|
314
|
+
);
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
export function clearActions(): void {
|
package/src/class-registry.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Class registry for preserving class instances across clone/save/load cycles.
|
|
2
2
|
|
|
3
3
|
import { parse, stringify } from 'devalue';
|
|
4
|
-
import { hasOwn } from './utils/namespace';
|
|
4
|
+
import { defineData, hasOwn } from './utils/namespace';
|
|
5
5
|
import {
|
|
6
6
|
arrayIndices,
|
|
7
7
|
extraKeys,
|
|
@@ -155,16 +155,6 @@ const isPlainData = (v: unknown): v is Record<string, unknown> =>
|
|
|
155
155
|
const malformedClass = (name: string): TypeError =>
|
|
156
156
|
new TypeError(`spindle: Malformed data for class "${name}"`);
|
|
157
157
|
|
|
158
|
-
const defineData = (target: object, key: string, value: unknown): void => {
|
|
159
|
-
// Define, so that a "__proto__" key stays a key (devalue refuses it)
|
|
160
|
-
Object.defineProperty(target, key, {
|
|
161
|
-
value,
|
|
162
|
-
enumerable: true,
|
|
163
|
-
writable: true,
|
|
164
|
-
configurable: true,
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
158
|
/**
|
|
169
159
|
* A reducer extracts string keys, so devalue never sees the symbol keys of
|
|
170
160
|
* the original object: refuse them here, as it does for a plain object.
|
package/src/code-check.ts
CHANGED
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
type PassageTarget,
|
|
56
56
|
} from './components/macros/macro-args';
|
|
57
57
|
import { subMacroParameters } from './components/macros/option-utils';
|
|
58
|
-
import { splitArgSpans } from './components/macros/arg-utils';
|
|
58
|
+
import { readPassageBody, splitArgSpans } from './components/macros/arg-utils';
|
|
59
59
|
import { effectiveNamedDefinitions, NameMap } from './utils/macro-names';
|
|
60
60
|
import { hasOwn } from './utils/namespace';
|
|
61
61
|
import { isBuiltinBlockMacro, isRawMacro } from './markup/ast';
|
|
@@ -532,7 +532,7 @@ export function* codeAndText(
|
|
|
532
532
|
const written = text.trim();
|
|
533
533
|
yield {
|
|
534
534
|
kind: 'passage',
|
|
535
|
-
name: written
|
|
535
|
+
name: readPassageBody(written),
|
|
536
536
|
offset: token.end + text.indexOf(written),
|
|
537
537
|
length: written.length,
|
|
538
538
|
macro: name,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { renderActionButton, useControlAction } from '../../hooks/use-action';
|
|
2
2
|
import { defineMacro } from '../../define-macro';
|
|
3
3
|
import { PassageDialog } from '../PassageDialog';
|
|
4
|
+
import { readPassageBody } from './arg-utils';
|
|
4
5
|
|
|
5
6
|
defineMacro({
|
|
6
7
|
name: 'dialog',
|
|
@@ -15,10 +16,7 @@ defineMacro({
|
|
|
15
16
|
|
|
16
17
|
const { noclose } = ctx.args;
|
|
17
18
|
const label = ctx.resolve!(ctx.args.label ?? '') ?? '';
|
|
18
|
-
const passageName = ctx
|
|
19
|
-
.collectText(children)
|
|
20
|
-
.trim()
|
|
21
|
-
.replace(/^["']|["']$/g, '');
|
|
19
|
+
const passageName = readPassageBody(ctx.collectText(children));
|
|
22
20
|
const openDialog = () => setOpen(true);
|
|
23
21
|
|
|
24
22
|
// Its own type: the menubar's Saves and Settings are `dialog` (#540)
|
|
@@ -74,6 +74,12 @@ export function readWholeQuoted(src: string): string | null {
|
|
|
74
74
|
return quoted && quoted.end === src.length ? quoted.value : null;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** A dialog body's passage name, optionally enclosed in matching quotes. */
|
|
78
|
+
export function readPassageBody(src: string): string {
|
|
79
|
+
const name = src.trim();
|
|
80
|
+
return readWholeQuoted(name) ?? name;
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
/**
|
|
78
84
|
* Strip an optional quote from each end of an unquoted-or-loosely-quoted
|
|
79
85
|
* argument (`"Red`, `Red'`), leaving at least one character. This is the
|
package/src/execute-mutation.ts
CHANGED
|
@@ -116,6 +116,16 @@ function clonerFor(
|
|
|
116
116
|
return (value) => deepClone(value, { keepUnregistered: true, seen, settle });
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/** Adopt setter inputs into a draft, retaining references to owned state. */
|
|
120
|
+
export function adoptStateValues(target: VariableNamespaces): Cloner {
|
|
121
|
+
const held = locateObjects(namespacesOf(useStoryStore.getState()), []);
|
|
122
|
+
const scope = getActiveMutationScope();
|
|
123
|
+
if (scope) {
|
|
124
|
+
for (const [value, path] of locateObjects(scope, [])) held.set(value, path);
|
|
125
|
+
}
|
|
126
|
+
return clonerFor(target, held);
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
/** One cloner per target copy, made when first used. */
|
|
120
130
|
const clonersFor = (
|
|
121
131
|
paths?: (target: object) => ReadonlyMap<object, ObjectPath>,
|
|
@@ -28,21 +28,10 @@ const FOCUSABLE = [
|
|
|
28
28
|
*/
|
|
29
29
|
function isAvailable(el: HTMLElement): boolean {
|
|
30
30
|
if (!isRendered(el)) return false;
|
|
31
|
-
//
|
|
31
|
+
// Rendered visibility includes CSS overrides of hidden, until-found
|
|
32
|
+
// contents, closed details and shadow trees. Inertness is independent.
|
|
32
33
|
for (let at: Element | null = el; at; at = composedParent(at)) {
|
|
33
|
-
if (at.hasAttribute('
|
|
34
|
-
if (at.ownerDocument.defaultView?.getComputedStyle(at).display === 'none')
|
|
35
|
-
return false;
|
|
36
|
-
const parent = composedParent(at);
|
|
37
|
-
if (
|
|
38
|
-
parent?.localName === 'details' &&
|
|
39
|
-
!parent.hasAttribute('open') &&
|
|
40
|
-
at !==
|
|
41
|
-
Array.from(parent.children).find(
|
|
42
|
-
(child) => child.localName === 'summary',
|
|
43
|
-
)
|
|
44
|
-
)
|
|
45
|
-
return false;
|
|
34
|
+
if (at.hasAttribute('inert')) return false;
|
|
46
35
|
}
|
|
47
36
|
// Also covers controls disabled by a <fieldset disabled> ancestor
|
|
48
37
|
return !el.matches(':disabled');
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
composedParent,
|
|
5
5
|
isHidden,
|
|
6
6
|
isRendered,
|
|
7
|
+
hidesContents,
|
|
7
8
|
} from '../utils/element-visibility';
|
|
9
|
+
import { isFullyRevealed, revealedText } from '../utils/type-reveal';
|
|
8
10
|
import { getAction } from '../action-registry';
|
|
9
11
|
import { SvgInstances } from './svg-instances';
|
|
10
12
|
|
|
@@ -134,8 +136,13 @@ export function observableText(
|
|
|
134
136
|
(node as Text).assignedSlot ??
|
|
135
137
|
node.parentElement ??
|
|
136
138
|
(node.getRootNode() as ShadowRoot).host;
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
+
if (
|
|
140
|
+
parent &&
|
|
141
|
+
(hidesContents(parent) ||
|
|
142
|
+
!isRendered(parent, instanceRoot ?? visibilityRoot))
|
|
143
|
+
)
|
|
144
|
+
return;
|
|
145
|
+
const data = revealedText(node as Text);
|
|
139
146
|
if (inPre) out += data;
|
|
140
147
|
else {
|
|
141
148
|
// Source whitespace between blocks isn't a line of its own
|
|
@@ -152,13 +159,14 @@ export function observableText(
|
|
|
152
159
|
(skip && child !== el && child.matches(skip))
|
|
153
160
|
)
|
|
154
161
|
return;
|
|
162
|
+
if (!isRendered(child, instanceRoot ?? visibilityRoot, false)) return;
|
|
155
163
|
if (
|
|
156
164
|
child.namespaceURI === 'http://www.w3.org/2000/svg' &&
|
|
157
165
|
child.localName === 'use'
|
|
158
166
|
) {
|
|
159
167
|
// Visibility is inherited by the instance and can be overridden inside
|
|
160
168
|
// it; unlike display:none, it does not hide the entire subtree.
|
|
161
|
-
if (
|
|
169
|
+
if (hidesContents(child) || !isFullyRevealed(child)) return;
|
|
162
170
|
const target = localTarget(child);
|
|
163
171
|
if (
|
|
164
172
|
!target ||
|
|
@@ -179,7 +187,11 @@ export function observableText(
|
|
|
179
187
|
getAction(child.getAttribute('data-action')!)?.type === 'cycle')
|
|
180
188
|
) {
|
|
181
189
|
if (child.matches('input[type="hidden" i]')) return;
|
|
182
|
-
if (
|
|
190
|
+
if (
|
|
191
|
+
!isRendered(child, instanceRoot ?? visibilityRoot) ||
|
|
192
|
+
!isFullyRevealed(child)
|
|
193
|
+
)
|
|
194
|
+
return;
|
|
183
195
|
out += controlMarker(child);
|
|
184
196
|
return;
|
|
185
197
|
}
|
|
@@ -188,6 +200,7 @@ export function observableText(
|
|
|
188
200
|
return;
|
|
189
201
|
}
|
|
190
202
|
const block = BLOCKS.has(child.tagName);
|
|
203
|
+
if (hidesContents(child)) return;
|
|
191
204
|
if (block) endLine();
|
|
192
205
|
const closedDetails =
|
|
193
206
|
child.tagName === 'DETAILS' && !child.hasAttribute('open');
|
|
@@ -241,5 +254,6 @@ export function observableErrors(
|
|
|
241
254
|
.filter(
|
|
242
255
|
(e) => e.matches('.error') && !left(e) && isRendered(e, visibilityRoot),
|
|
243
256
|
)
|
|
244
|
-
.map((e) => observableText(e, skip, visibilityRoot).trim())
|
|
257
|
+
.map((e) => observableText(e, skip, visibilityRoot).trim())
|
|
258
|
+
.filter(Boolean);
|
|
245
259
|
}
|