@rohal12/spindle 0.64.32 → 0.64.34
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 +182 -45
- package/dist/pkg/story-variables.js +210 -51
- package/dist/pkg/tooling.js +1 -0
- package/package.json +1 -1
- package/src/code-check.ts +1 -0
- package/src/components/macros/SaveManager.tsx +7 -3
- package/src/components/macros/input-macro.ts +4 -1
- package/src/define-macro.ts +5 -21
- package/src/format/format-passage.ts +9 -0
- package/src/hooks/use-modal-focus.ts +23 -10
- package/src/js-bindings.ts +64 -27
- package/src/js-lexer.ts +155 -15
- package/src/markup/ast.ts +6 -1
- package/src/markup/pair.ts +10 -2
- package/src/markup/parse.ts +40 -1
- package/src/markup/spindle.d.peggy.ts +2 -0
- package/src/markup/spindle.peggy +5 -6
- package/src/markup/validate.ts +3 -0
- package/src/tooling.ts +5 -0
- package/src/types-drift-check.ts +10 -0
- package/src/utils/control-bindings.ts +52 -0
- package/src/utils/control-edits.ts +12 -1
- package/types/tooling.d.ts +40 -0
package/dist/pkg/headless.js
CHANGED
|
@@ -5878,13 +5878,13 @@ function parseCode(src, goal = "expression") {
|
|
|
5878
5878
|
return parseWithAst(src, goal).out;
|
|
5879
5879
|
}
|
|
5880
5880
|
/** What parseCode finds in `src`, and the syntax tree it is in. */
|
|
5881
|
-
function parseWithAst(src, goal) {
|
|
5881
|
+
function parseWithAst(src, goal, effects) {
|
|
5882
5882
|
const ast = parseAst(src, goal);
|
|
5883
5883
|
const out = {
|
|
5884
5884
|
refs: [],
|
|
5885
5885
|
strings: []
|
|
5886
5886
|
};
|
|
5887
|
-
walk(ast, src, out, false, false);
|
|
5887
|
+
walk(ast, src, out, false, false, "read", effects);
|
|
5888
5888
|
out.refs.sort((a, b) => a.start - b.start);
|
|
5889
5889
|
return {
|
|
5890
5890
|
out,
|
|
@@ -5982,47 +5982,83 @@ function propertyName(node, src) {
|
|
|
5982
5982
|
const c = src.charAt(node.start);
|
|
5983
5983
|
if (c === "@" || c === "%") throw new CodeSyntaxError(`"${node.name}" can't be a property name`, src, node.start);
|
|
5984
5984
|
}
|
|
5985
|
+
/** Keep static member keys decoded; an arbitrary computed key stays unknown. */
|
|
5986
|
+
function mutationTarget(node, src) {
|
|
5987
|
+
const path = [];
|
|
5988
|
+
while (node.type === "MemberExpression") {
|
|
5989
|
+
const property = node.property;
|
|
5990
|
+
path.push(!node.computed && property.type === "Identifier" ? property.name : property.type === "Literal" && ["string", "number"].includes(typeof property.value) ? String(property.value) : null);
|
|
5991
|
+
node = node.object;
|
|
5992
|
+
}
|
|
5993
|
+
return {
|
|
5994
|
+
root: node.type === "Identifier" ? sigilOf(node, src) : null,
|
|
5995
|
+
path: path.reverse()
|
|
5996
|
+
};
|
|
5997
|
+
}
|
|
5985
5998
|
/**
|
|
5986
5999
|
* Collect the references and string text under `node`. `binding`: the
|
|
5987
6000
|
* identifiers here are declared (a `let`, a parameter), where a sigil
|
|
5988
6001
|
* variable can't be. `shorthand`: the node is a shorthand property's value.
|
|
5989
6002
|
*/
|
|
5990
|
-
function walk(root, src, out, binding, shorthand, access = "read") {
|
|
6003
|
+
function walk(root, src, out, binding, shorthand, access = "read", effects) {
|
|
5991
6004
|
const pending = [[
|
|
5992
6005
|
root,
|
|
5993
6006
|
binding,
|
|
5994
6007
|
shorthand,
|
|
5995
|
-
access
|
|
6008
|
+
access,
|
|
6009
|
+
false,
|
|
6010
|
+
false
|
|
5996
6011
|
]];
|
|
5997
6012
|
while (pending.length) {
|
|
5998
|
-
const [node, bind, short, role] = pending.pop();
|
|
6013
|
+
const [node, bind, short, role, memberObject, escapes] = pending.pop();
|
|
5999
6014
|
const children = [];
|
|
6000
|
-
visit(node, bind, short, role, children);
|
|
6015
|
+
visit(node, bind, short, role, memberObject, escapes, children);
|
|
6001
6016
|
for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
|
|
6002
6017
|
}
|
|
6003
|
-
function visit(node, binding, shorthand, access, children) {
|
|
6018
|
+
function visit(node, binding, shorthand, access, memberObject, escapes, children) {
|
|
6004
6019
|
if (Array.isArray(node)) {
|
|
6005
6020
|
for (const n of node) children.push([
|
|
6006
6021
|
n,
|
|
6007
6022
|
binding,
|
|
6008
6023
|
false,
|
|
6009
|
-
access
|
|
6024
|
+
access,
|
|
6025
|
+
false,
|
|
6026
|
+
escapes
|
|
6010
6027
|
]);
|
|
6011
6028
|
return;
|
|
6012
6029
|
}
|
|
6013
6030
|
if (!isNode(node)) return;
|
|
6014
|
-
const sub = (child, bind = false, short = false, role = "read") => {
|
|
6031
|
+
const sub = (child, bind = false, short = false, role = "read", member = false, escape = escapes) => {
|
|
6015
6032
|
children.push([
|
|
6016
6033
|
child,
|
|
6017
6034
|
bind,
|
|
6018
6035
|
short,
|
|
6019
|
-
role
|
|
6036
|
+
role,
|
|
6037
|
+
member,
|
|
6038
|
+
escape
|
|
6020
6039
|
]);
|
|
6021
6040
|
};
|
|
6041
|
+
const uncertain = (reason) => effects?.uncertain.push({
|
|
6042
|
+
start: node.start,
|
|
6043
|
+
end: node.end,
|
|
6044
|
+
reason
|
|
6045
|
+
});
|
|
6046
|
+
if (effects) {
|
|
6047
|
+
if ([
|
|
6048
|
+
"CallExpression",
|
|
6049
|
+
"NewExpression",
|
|
6050
|
+
"TaggedTemplateExpression"
|
|
6051
|
+
].includes(node.type)) uncertain("call");
|
|
6052
|
+
if (node.type === "WithStatement") uncertain("dynamic-scope");
|
|
6053
|
+
if (escapes && node.type === "ThisExpression") uncertain("escape");
|
|
6054
|
+
}
|
|
6022
6055
|
switch (node.type) {
|
|
6023
6056
|
case "Identifier": {
|
|
6024
6057
|
const sigil = sigilOf(node, src);
|
|
6025
|
-
if (!sigil)
|
|
6058
|
+
if (!sigil) {
|
|
6059
|
+
if (effects && escapes && !binding && !memberObject && access === "read") uncertain("escape");
|
|
6060
|
+
return;
|
|
6061
|
+
}
|
|
6026
6062
|
if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
|
|
6027
6063
|
out.refs.push({
|
|
6028
6064
|
sigil: sigil[0],
|
|
@@ -6033,6 +6069,19 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6033
6069
|
read: access !== "write",
|
|
6034
6070
|
write: access !== "read"
|
|
6035
6071
|
});
|
|
6072
|
+
if (effects) {
|
|
6073
|
+
if (access !== "read") effects.mutations.push({
|
|
6074
|
+
start: node.start,
|
|
6075
|
+
end: node.end,
|
|
6076
|
+
target: {
|
|
6077
|
+
sigil: sigil[0],
|
|
6078
|
+
name: sigil[1],
|
|
6079
|
+
path: []
|
|
6080
|
+
},
|
|
6081
|
+
read: access !== "write"
|
|
6082
|
+
});
|
|
6083
|
+
else if (!memberObject) uncertain("escape");
|
|
6084
|
+
}
|
|
6036
6085
|
return;
|
|
6037
6086
|
}
|
|
6038
6087
|
case "Literal":
|
|
@@ -6041,8 +6090,29 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6041
6090
|
case "TemplateElement":
|
|
6042
6091
|
out.strings.push(node.value.raw);
|
|
6043
6092
|
return;
|
|
6093
|
+
case "ChainExpression":
|
|
6094
|
+
sub(node.expression, binding, shorthand, access, memberObject);
|
|
6095
|
+
return;
|
|
6044
6096
|
case "MemberExpression":
|
|
6045
|
-
|
|
6097
|
+
if (effects && escapes && !memberObject && access === "read") uncertain("escape");
|
|
6098
|
+
if (effects && !binding && access !== "read") {
|
|
6099
|
+
const { root, path } = mutationTarget(node, src);
|
|
6100
|
+
const target = root ? {
|
|
6101
|
+
sigil: root[0],
|
|
6102
|
+
name: root[1],
|
|
6103
|
+
path
|
|
6104
|
+
} : null;
|
|
6105
|
+
effects.mutations.push({
|
|
6106
|
+
start: node.start,
|
|
6107
|
+
end: node.end,
|
|
6108
|
+
target,
|
|
6109
|
+
read: access !== "write"
|
|
6110
|
+
});
|
|
6111
|
+
if (!target) uncertain("indirect-write");
|
|
6112
|
+
if (path.includes(null)) uncertain("computed-write");
|
|
6113
|
+
if (path.some((key) => key === "prototype" || key === "__proto__")) uncertain("prototype-write");
|
|
6114
|
+
}
|
|
6115
|
+
sub(node.object, false, false, "read", true);
|
|
6046
6116
|
if (node.computed) sub(node.property);
|
|
6047
6117
|
else propertyName(node.property, src);
|
|
6048
6118
|
return;
|
|
@@ -6053,7 +6123,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6053
6123
|
const value = node.value;
|
|
6054
6124
|
if (value.type === "AssignmentPattern") {
|
|
6055
6125
|
sub(value.left, binding, true, access);
|
|
6056
|
-
sub(value.right);
|
|
6126
|
+
sub(value.right, false, false, "read", false, true);
|
|
6057
6127
|
} else sub(value, binding, true, access);
|
|
6058
6128
|
} else sub(node.value, binding, false, access);
|
|
6059
6129
|
return;
|
|
@@ -6061,7 +6131,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6061
6131
|
case "PropertyDefinition":
|
|
6062
6132
|
if (node.computed) sub(node.key);
|
|
6063
6133
|
else propertyName(node.key, src);
|
|
6064
|
-
sub(node.value);
|
|
6134
|
+
sub(node.value, false, false, "read", false, node.type === "PropertyDefinition" || escapes);
|
|
6065
6135
|
return;
|
|
6066
6136
|
case "LabeledStatement":
|
|
6067
6137
|
sub(node.body);
|
|
@@ -6072,7 +6142,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6072
6142
|
case "PrivateIdentifier": return;
|
|
6073
6143
|
case "VariableDeclarator":
|
|
6074
6144
|
sub(node.id, true);
|
|
6075
|
-
sub(node.init);
|
|
6145
|
+
sub(node.init, false, false, "read", false, true);
|
|
6076
6146
|
return;
|
|
6077
6147
|
case "FunctionDeclaration":
|
|
6078
6148
|
case "FunctionExpression":
|
|
@@ -6093,7 +6163,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6093
6163
|
return;
|
|
6094
6164
|
case "AssignmentExpression":
|
|
6095
6165
|
sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
|
|
6096
|
-
sub(node.right);
|
|
6166
|
+
sub(node.right, false, false, "read", false, true);
|
|
6167
|
+
return;
|
|
6168
|
+
case "ReturnStatement":
|
|
6169
|
+
case "ThrowStatement":
|
|
6170
|
+
case "YieldExpression":
|
|
6171
|
+
sub(node.argument, false, false, "read", false, true);
|
|
6097
6172
|
return;
|
|
6098
6173
|
case "UnaryExpression":
|
|
6099
6174
|
sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
|
|
@@ -6104,12 +6179,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
6104
6179
|
case "ForInStatement":
|
|
6105
6180
|
case "ForOfStatement":
|
|
6106
6181
|
sub(node.left, false, false, "write");
|
|
6107
|
-
sub(node.right);
|
|
6182
|
+
sub(node.right, false, false, "read", false, true);
|
|
6108
6183
|
sub(node.body);
|
|
6109
6184
|
return;
|
|
6110
6185
|
case "AssignmentPattern":
|
|
6111
6186
|
sub(node.left, binding, false, access);
|
|
6112
|
-
sub(node.right);
|
|
6187
|
+
sub(node.right, false, false, "read", false, true);
|
|
6113
6188
|
return;
|
|
6114
6189
|
case "ObjectPattern":
|
|
6115
6190
|
case "ArrayPattern":
|
|
@@ -10353,7 +10428,7 @@ function peg$parse(input, options) {
|
|
|
10353
10428
|
return lexeme("text", location(), { value });
|
|
10354
10429
|
}
|
|
10355
10430
|
function peg$f24() {
|
|
10356
|
-
return completionMode || offset()
|
|
10431
|
+
return completionMode || findDelimiter("-->", offset()) >= 0;
|
|
10357
10432
|
}
|
|
10358
10433
|
function peg$f25(value) {
|
|
10359
10434
|
const node = lexeme("text", location(), { value });
|
|
@@ -10410,8 +10485,8 @@ function peg$parse(input, options) {
|
|
|
10410
10485
|
fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
|
|
10411
10486
|
}
|
|
10412
10487
|
function peg$f37(start) {
|
|
10413
|
-
const close =
|
|
10414
|
-
const nested =
|
|
10488
|
+
const close = findDelimiter("]]", start);
|
|
10489
|
+
const nested = findDelimiter("[[", start);
|
|
10415
10490
|
linkTextEnd = Math.min(close < 0 ? input.length : close, nested < 0 ? input.length : nested);
|
|
10416
10491
|
return true;
|
|
10417
10492
|
}
|
|
@@ -13271,7 +13346,7 @@ function peg$parse(input, options) {
|
|
|
13271
13346
|
const textMode = options.text === true;
|
|
13272
13347
|
const completionMode = options.completion === true;
|
|
13273
13348
|
const hooks = options.hooks;
|
|
13274
|
-
const
|
|
13349
|
+
const findDelimiter = options.findDelimiter;
|
|
13275
13350
|
/** End of the stretch a `.|n|` repetition consumes (see skipTo). */
|
|
13276
13351
|
let skipEnd = -1;
|
|
13277
13352
|
/** Whether the attribute whose value is being read holds code. */
|
|
@@ -13605,6 +13680,10 @@ function isBlockMacro(name) {
|
|
|
13605
13680
|
if (DEFINED_MACROS.has(name)) return DEFINED_BLOCK_MACROS.has(name);
|
|
13606
13681
|
return isBuiltinBlockMacro(name);
|
|
13607
13682
|
}
|
|
13683
|
+
/** Explicit implementations can also be invoked outside a companion owner. */
|
|
13684
|
+
function isStandaloneMacro(name) {
|
|
13685
|
+
return WIDGETS.has(name) || getMacro(name) !== void 0;
|
|
13686
|
+
}
|
|
13608
13687
|
/** Built-in defaults without any process-global registrations or widgets. */
|
|
13609
13688
|
function isBuiltinBlockMacro(name) {
|
|
13610
13689
|
return BLOCK_MACROS.has(name);
|
|
@@ -13769,6 +13848,7 @@ var closes = (open, close) => open.type === close.type && lowerName(open) === lo
|
|
|
13769
13848
|
function pairMarkup(tokens, options = {}) {
|
|
13770
13849
|
const isBlock = options.isBlock ?? isBlockMacro;
|
|
13771
13850
|
const isRaw = options.isRaw ?? isRawMacro;
|
|
13851
|
+
const isStandalone = options.isStandalone ?? isStandaloneMacro;
|
|
13772
13852
|
const parentsOf = (name) => {
|
|
13773
13853
|
if (options.branchParents) return options.branchParents(name);
|
|
13774
13854
|
const registered = branchParents(name);
|
|
@@ -13848,7 +13928,7 @@ function pairMarkup(tokens, options = {}) {
|
|
|
13848
13928
|
}
|
|
13849
13929
|
continue;
|
|
13850
13930
|
}
|
|
13851
|
-
if (token.type === "macro" && !token.isClose && parentsOf(token.name).length > 0) {
|
|
13931
|
+
if (token.type === "macro" && !token.isClose && parentsOf(token.name).length > 0 && (!isStandalone(token.name) || last(stack)?.node.token.type === "macro" && parentsOf(token.name).includes(lowerName(last(stack).node.token)))) {
|
|
13852
13932
|
const tag = token;
|
|
13853
13933
|
const frame = last(stack);
|
|
13854
13934
|
if (!frame) {
|
|
@@ -14378,7 +14458,7 @@ var MarkupError = class extends Error {
|
|
|
14378
14458
|
this.name = "MarkupError";
|
|
14379
14459
|
}
|
|
14380
14460
|
};
|
|
14381
|
-
function run(source, startRule, options, completion = false) {
|
|
14461
|
+
function run(source, startRule, options, completion = false, findDelimiter = indexDelimiters(source)) {
|
|
14382
14462
|
const hooks = {
|
|
14383
14463
|
...defaultHooks,
|
|
14384
14464
|
...options.hooks
|
|
@@ -14392,7 +14472,8 @@ function run(source, startRule, options, completion = false) {
|
|
|
14392
14472
|
startRule,
|
|
14393
14473
|
text: options.text === true,
|
|
14394
14474
|
hooks,
|
|
14395
|
-
completion
|
|
14475
|
+
completion,
|
|
14476
|
+
findDelimiter
|
|
14396
14477
|
});
|
|
14397
14478
|
} catch (err) {
|
|
14398
14479
|
const { location, code } = err;
|
|
@@ -14404,6 +14485,20 @@ function run(source, startRule, options, completion = false) {
|
|
|
14404
14485
|
throw err;
|
|
14405
14486
|
}
|
|
14406
14487
|
}
|
|
14488
|
+
/** Literal delimiter searches shared by suffix and prefix recovery attempts. */
|
|
14489
|
+
function indexDelimiters(source) {
|
|
14490
|
+
const positions = /* @__PURE__ */ new Map();
|
|
14491
|
+
return (delimiter, from, end = source.length) => {
|
|
14492
|
+
let offsets = positions.get(delimiter);
|
|
14493
|
+
if (!offsets) {
|
|
14494
|
+
offsets = [];
|
|
14495
|
+
for (let at = source.indexOf(delimiter); at >= 0; at = source.indexOf(delimiter, at + 1)) offsets.push(at);
|
|
14496
|
+
positions.set(delimiter, offsets);
|
|
14497
|
+
}
|
|
14498
|
+
const at = offsets[upperBound(offsets, from - 1)];
|
|
14499
|
+
return at !== void 0 && at + delimiter.length <= end ? at : -1;
|
|
14500
|
+
};
|
|
14501
|
+
}
|
|
14407
14502
|
/**
|
|
14408
14503
|
* Read markup that may be malformed: its tokens, their pairing and every
|
|
14409
14504
|
* error (malformed tags, and closers and branches that pair with nothing),
|
|
@@ -14420,6 +14515,7 @@ function analyzeMarkup(source, options = {}) {
|
|
|
14420
14515
|
isBlock: hooks.isBlock,
|
|
14421
14516
|
isRaw: hooks.isRaw,
|
|
14422
14517
|
branchParents: hooks.branchParents,
|
|
14518
|
+
isStandalone: hooks.isStandalone,
|
|
14423
14519
|
source
|
|
14424
14520
|
});
|
|
14425
14521
|
if (errors.length === 0 && paired.errors.length === 0) return {
|
|
@@ -14492,6 +14588,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
14492
14588
|
const damage = [];
|
|
14493
14589
|
let position;
|
|
14494
14590
|
const codeEnd = indexCodeEnds(source);
|
|
14591
|
+
const findDelimiter = indexDelimiters(source);
|
|
14495
14592
|
const customCloseBrace = options.hooks?.closeBrace;
|
|
14496
14593
|
const lastBrace = source.lastIndexOf("}");
|
|
14497
14594
|
/** `text` shifted by `base`, tokenized: the tokens or the error. */
|
|
@@ -14509,7 +14606,10 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
14509
14606
|
return run(text, "Tokens", {
|
|
14510
14607
|
...options,
|
|
14511
14608
|
hooks
|
|
14512
|
-
}, completion
|
|
14609
|
+
}, completion, (delimiter, from) => {
|
|
14610
|
+
const at = findDelimiter(delimiter, base + from, base + text.length);
|
|
14611
|
+
return at < 0 ? -1 : at - base;
|
|
14612
|
+
}).map((token) => shiftOffsets(token, base));
|
|
14513
14613
|
} catch (error) {
|
|
14514
14614
|
if (!(error instanceof MarkupError)) throw error;
|
|
14515
14615
|
return error;
|
|
@@ -15263,6 +15363,7 @@ function parameterLookup(macros) {
|
|
|
15263
15363
|
lookup.source = (name) => sources.get(name);
|
|
15264
15364
|
const definitions = new NameMap(effectiveNamedDefinitions([...list.filter((macro) => !macro.widget), ...list.filter((macro) => macro.widget)]).map((macro) => [macro.name, macro]));
|
|
15265
15365
|
lookup.pairing = {
|
|
15366
|
+
isStandalone: (name) => widgets.has(name) || sources.get(name) === "user",
|
|
15266
15367
|
isBlock: (name) => definitions.get(name)?.block ?? isBuiltinBlockMacro(name),
|
|
15267
15368
|
isRaw: (name) => isRawMacro(name, widgets.has(name)),
|
|
15268
15369
|
branchParents: branchParentLookup([...definitions.values()].map((macro) => ({
|
|
@@ -19784,9 +19885,9 @@ function withEdits(edits, run) {
|
|
|
19784
19885
|
activeEdits = previous;
|
|
19785
19886
|
}
|
|
19786
19887
|
}
|
|
19787
|
-
/** Attribute
|
|
19788
|
-
function
|
|
19789
|
-
withEdits([
|
|
19888
|
+
/** Attribute every binding of an atomic form reset to its own path. */
|
|
19889
|
+
function runAsControlEdits(paths, run) {
|
|
19890
|
+
withEdits(paths.map((segments) => ["variables", ...segments]), run);
|
|
19790
19891
|
}
|
|
19791
19892
|
/** Whether mutation code runs inside a {for} iteration. */
|
|
19792
19893
|
var ItemEditContext = createContext(false);
|
|
@@ -21190,6 +21291,10 @@ var FOCUSABLE = [
|
|
|
21190
21291
|
"[contenteditable]",
|
|
21191
21292
|
"[tabindex]"
|
|
21192
21293
|
].join(",");
|
|
21294
|
+
/** Only the first summary child of a details element is its native toggle. */
|
|
21295
|
+
function isDetailsToggle(el) {
|
|
21296
|
+
return el.localName === "summary" && el.parentElement?.localName === "details" && Array.from(el.parentElement.children).find((c) => c.localName === "summary") === el;
|
|
21297
|
+
}
|
|
21193
21298
|
/**
|
|
21194
21299
|
* Whether `el` can be focused at all: shown, rendered, enabled (also by its
|
|
21195
21300
|
* fieldset) and not inert.
|
|
@@ -21198,7 +21303,8 @@ function isAvailable(el) {
|
|
|
21198
21303
|
if (!isRendered(el)) return false;
|
|
21199
21304
|
if ((el.ownerDocument.defaultView ?? window).getComputedStyle(el).display === "contents") return false;
|
|
21200
21305
|
for (let at = el; at; at = composedParent(at)) if (at.hasAttribute("inert")) return false;
|
|
21201
|
-
|
|
21306
|
+
if (el.matches(":disabled")) return false;
|
|
21307
|
+
return tabIndexAttr(el) !== null || el.tabIndex >= 0 || el.isContentEditable && !el.parentElement?.isContentEditable || isDetailsToggle(el);
|
|
21202
21308
|
}
|
|
21203
21309
|
/** The `tabindex` of `el` as an integer, or null when absent or invalid. */
|
|
21204
21310
|
function tabIndexAttr(el) {
|
|
@@ -21228,10 +21334,7 @@ function isTabStop(el, radioStops) {
|
|
|
21228
21334
|
const tabIndex = tabIndexAttr(el);
|
|
21229
21335
|
if (tabIndex !== null && tabIndex < 0) return false;
|
|
21230
21336
|
if (tabIndex === null && el.hasAttribute("contenteditable") && !el.matches("a[href], button, input, select, textarea, iframe, summary") && (!el.isContentEditable || el.parentElement?.isContentEditable)) return false;
|
|
21231
|
-
if (el.localName === "summary")
|
|
21232
|
-
const details = el.parentElement;
|
|
21233
|
-
if (details?.localName !== "details" || Array.from(details.children).find((c) => c.localName === "summary") !== el) return tabIndex !== null;
|
|
21234
|
-
}
|
|
21337
|
+
if (el.localName === "summary" && !isDetailsToggle(el)) return tabIndex !== null;
|
|
21235
21338
|
const input = el;
|
|
21236
21339
|
if (el.localName === "input" && input.type === "radio" && input.name) {
|
|
21237
21340
|
const tree = el.getRootNode();
|
|
@@ -22110,6 +22213,39 @@ var settings = {
|
|
|
22110
22213
|
function collectText(nodes) {
|
|
22111
22214
|
return nodes.map((n) => n.type === "text" ? n.value : "").join("");
|
|
22112
22215
|
}
|
|
22216
|
+
// src/utils/control-bindings.ts
|
|
22217
|
+
var pending;
|
|
22218
|
+
/** Commit related bindings together, preserving references and item edits. */
|
|
22219
|
+
function commit(writes) {
|
|
22220
|
+
if (!writes.length) return;
|
|
22221
|
+
runAsControlEdits(writes.map(({ segments }) => segments), () => {
|
|
22222
|
+
mutateState((work, adopt) => {
|
|
22223
|
+
for (const { segments, value } of writes) setByPath(work.variables, segments, adopt(value), { createMissing: true });
|
|
22224
|
+
});
|
|
22225
|
+
});
|
|
22226
|
+
}
|
|
22227
|
+
/** A control write, or one part of the form reset currently being collected. */
|
|
22228
|
+
function setControlValue(segments, value) {
|
|
22229
|
+
notifyVariableWrite(segments);
|
|
22230
|
+
const write = {
|
|
22231
|
+
segments,
|
|
22232
|
+
value
|
|
22233
|
+
};
|
|
22234
|
+
if (pending) pending.push(write);
|
|
22235
|
+
else commit([write]);
|
|
22236
|
+
}
|
|
22237
|
+
/** Subscribers see the complete reset, never a partially reset form. */
|
|
22238
|
+
function batchControlValues(run) {
|
|
22239
|
+
if (pending) return run();
|
|
22240
|
+
const writes = [];
|
|
22241
|
+
pending = writes;
|
|
22242
|
+
try {
|
|
22243
|
+
run();
|
|
22244
|
+
} finally {
|
|
22245
|
+
pending = void 0;
|
|
22246
|
+
}
|
|
22247
|
+
commit(writes);
|
|
22248
|
+
}
|
|
22113
22249
|
// src/define-macro.ts
|
|
22114
22250
|
function macroClass(type, className) {
|
|
22115
22251
|
const base = `macro-${type}`;
|
|
@@ -22203,14 +22339,7 @@ function defineMacro(config, source = "builtin") {
|
|
|
22203
22339
|
ctx.varName = segments.join(".");
|
|
22204
22340
|
ctx.value = getByPath(useStoryFields("variables").variables, segments);
|
|
22205
22341
|
ctx.getValue = () => getByPath(readState().variables, segments);
|
|
22206
|
-
ctx.setValue = displayOnly ? refuse : (value) =>
|
|
22207
|
-
notifyVariableWrite(segments);
|
|
22208
|
-
runAsControlEdit(segments, () => {
|
|
22209
|
-
mutateState((work, adopt) => {
|
|
22210
|
-
setByPath(work.variables, segments, adopt(value), { createMissing: true });
|
|
22211
|
-
});
|
|
22212
|
-
});
|
|
22213
|
-
};
|
|
22342
|
+
ctx.setValue = displayOnly ? refuse : (value) => setControlValue(segments, value);
|
|
22214
22343
|
}
|
|
22215
22344
|
try {
|
|
22216
22345
|
return entryRender?.pending ? duringEntryRender(() => config.render(props, ctx)) : duringMacroRender(() => config.render(props, ctx));
|
|
@@ -23241,6 +23370,7 @@ function validateMarkup(passages, options) {
|
|
|
23241
23370
|
const diagnostics = [];
|
|
23242
23371
|
const positions = /* @__PURE__ */ new Map();
|
|
23243
23372
|
const hooks = {
|
|
23373
|
+
...options.parametersOf?.pairing?.isStandalone && { isStandalone: options.parametersOf.pairing.isStandalone },
|
|
23244
23374
|
...options.isBlockMacro && { isBlock: options.isBlockMacro },
|
|
23245
23375
|
...options.branchParents && { branchParents: options.branchParents },
|
|
23246
23376
|
isRaw: (name) => isRawMacro(name, options.parametersOf ? options.parametersOf.widget?.(name) !== void 0 : void 0)
|
|
@@ -26353,7 +26483,7 @@ function SaveManagerContent({ className, id }) {
|
|
|
26353
26483
|
});
|
|
26354
26484
|
statusTimer.current = window.setTimeout(() => setStatus(null), 3e3);
|
|
26355
26485
|
};
|
|
26356
|
-
|
|
26486
|
+
useLayoutEffect(() => {
|
|
26357
26487
|
mounted.current = true;
|
|
26358
26488
|
return () => {
|
|
26359
26489
|
mounted.current = false;
|
|
@@ -26427,7 +26557,12 @@ function SaveManagerContent({ className, id }) {
|
|
|
26427
26557
|
if (isStateReplacementSuperseded(replacement)) return;
|
|
26428
26558
|
loadFromPayload(decodeSavePayload(current.payload), void 0, current.meta.playthroughId, replacement);
|
|
26429
26559
|
showStatus("Game loaded");
|
|
26430
|
-
if (closeDialog
|
|
26560
|
+
if (closeDialog && mounted.current) {
|
|
26561
|
+
clearTimeout(closeTimer.current);
|
|
26562
|
+
closeTimer.current = window.setTimeout(() => {
|
|
26563
|
+
if (mounted.current) closeDialog();
|
|
26564
|
+
}, 500);
|
|
26565
|
+
}
|
|
26431
26566
|
await refresh();
|
|
26432
26567
|
} catch {
|
|
26433
26568
|
showStatus("Failed to load save", "error");
|
|
@@ -26935,7 +27070,9 @@ function subscribeFormReset(form, read) {
|
|
|
26935
27070
|
});
|
|
26936
27071
|
restoreDefaults();
|
|
26937
27072
|
const commits = controls.map(({ read, element }) => read(element));
|
|
26938
|
-
|
|
27073
|
+
batchControlValues(() => {
|
|
27074
|
+
for (const commit of commits) commit();
|
|
27075
|
+
});
|
|
26939
27076
|
}, 0);
|
|
26940
27077
|
};
|
|
26941
27078
|
subscription = {
|