@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
|
@@ -655,7 +655,7 @@ function peg$parse(input, options) {
|
|
|
655
655
|
return lexeme("text", location(), { value });
|
|
656
656
|
}
|
|
657
657
|
function peg$f24() {
|
|
658
|
-
return completionMode || offset()
|
|
658
|
+
return completionMode || findDelimiter("-->", offset()) >= 0;
|
|
659
659
|
}
|
|
660
660
|
function peg$f25(value) {
|
|
661
661
|
const node = lexeme("text", location(), { value });
|
|
@@ -712,8 +712,8 @@ function peg$parse(input, options) {
|
|
|
712
712
|
fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
|
|
713
713
|
}
|
|
714
714
|
function peg$f37(start) {
|
|
715
|
-
const close =
|
|
716
|
-
const nested =
|
|
715
|
+
const close = findDelimiter("]]", start);
|
|
716
|
+
const nested = findDelimiter("[[", start);
|
|
717
717
|
linkTextEnd = Math.min(close < 0 ? input.length : close, nested < 0 ? input.length : nested);
|
|
718
718
|
return true;
|
|
719
719
|
}
|
|
@@ -3573,7 +3573,7 @@ function peg$parse(input, options) {
|
|
|
3573
3573
|
const textMode = options.text === true;
|
|
3574
3574
|
const completionMode = options.completion === true;
|
|
3575
3575
|
const hooks = options.hooks;
|
|
3576
|
-
const
|
|
3576
|
+
const findDelimiter = options.findDelimiter;
|
|
3577
3577
|
/** End of the stretch a `.|n|` repetition consumes (see skipTo). */
|
|
3578
3578
|
let skipEnd = -1;
|
|
3579
3579
|
/** Whether the attribute whose value is being read holds code. */
|
|
@@ -3710,7 +3710,11 @@ function consumesOptionClauses(macro) {
|
|
|
3710
3710
|
const name = macro.name.toLowerCase();
|
|
3711
3711
|
return macro.source === "builtin" && !macro.widget && (name === "listbox" || name === "cycle");
|
|
3712
3712
|
}
|
|
3713
|
-
|
|
3713
|
+
// src/registry.ts
|
|
3714
|
+
var registry = new NameMap();
|
|
3715
|
+
function getMacro(name) {
|
|
3716
|
+
return registry.get(name);
|
|
3717
|
+
}
|
|
3714
3718
|
new NameMap();
|
|
3715
3719
|
new NameSet();
|
|
3716
3720
|
/**
|
|
@@ -3870,6 +3874,10 @@ function isBlockMacro(name) {
|
|
|
3870
3874
|
if (DEFINED_MACROS.has(name)) return DEFINED_BLOCK_MACROS.has(name);
|
|
3871
3875
|
return isBuiltinBlockMacro(name);
|
|
3872
3876
|
}
|
|
3877
|
+
/** Explicit implementations can also be invoked outside a companion owner. */
|
|
3878
|
+
function isStandaloneMacro(name) {
|
|
3879
|
+
return WIDGETS.has(name) || getMacro(name) !== void 0;
|
|
3880
|
+
}
|
|
3873
3881
|
/** Built-in defaults without any process-global registrations or widgets. */
|
|
3874
3882
|
function isBuiltinBlockMacro(name) {
|
|
3875
3883
|
return BLOCK_MACROS.has(name);
|
|
@@ -4030,6 +4038,7 @@ var closes = (open, close) => open.type === close.type && lowerName(open) === lo
|
|
|
4030
4038
|
function pairMarkup(tokens, options = {}) {
|
|
4031
4039
|
const isBlock = options.isBlock ?? isBlockMacro;
|
|
4032
4040
|
const isRaw = options.isRaw ?? isRawMacro;
|
|
4041
|
+
const isStandalone = options.isStandalone ?? isStandaloneMacro;
|
|
4033
4042
|
const parentsOf = (name) => {
|
|
4034
4043
|
if (options.branchParents) return options.branchParents(name);
|
|
4035
4044
|
const registered = branchParents(name);
|
|
@@ -4109,7 +4118,7 @@ function pairMarkup(tokens, options = {}) {
|
|
|
4109
4118
|
}
|
|
4110
4119
|
continue;
|
|
4111
4120
|
}
|
|
4112
|
-
if (token.type === "macro" && !token.isClose && parentsOf(token.name).length > 0) {
|
|
4121
|
+
if (token.type === "macro" && !token.isClose && parentsOf(token.name).length > 0 && (!isStandalone(token.name) || last$1(stack)?.node.token.type === "macro" && parentsOf(token.name).includes(lowerName(last$1(stack).node.token)))) {
|
|
4113
4122
|
const tag = token;
|
|
4114
4123
|
const frame = last$1(stack);
|
|
4115
4124
|
if (!frame) {
|
|
@@ -9677,6 +9686,21 @@ function bracketsBefore(src, pos) {
|
|
|
9677
9686
|
};
|
|
9678
9687
|
}
|
|
9679
9688
|
/**
|
|
9689
|
+
* Conservative shape effects, using the same grammar and target roles as
|
|
9690
|
+
* parseCode. Includes nested functions and unreachable branches; does not
|
|
9691
|
+
* attempt alias, call, control-flow or execution-order analysis.
|
|
9692
|
+
*/
|
|
9693
|
+
function analyzeCodeEffects(src, goal = "expression") {
|
|
9694
|
+
const effects = {
|
|
9695
|
+
mutations: [],
|
|
9696
|
+
uncertain: []
|
|
9697
|
+
};
|
|
9698
|
+
parseWithAst(src, goal, effects);
|
|
9699
|
+
effects.mutations.sort((a, b) => a.start - b.start);
|
|
9700
|
+
effects.uncertain.sort((a, b) => a.start - b.start);
|
|
9701
|
+
return effects;
|
|
9702
|
+
}
|
|
9703
|
+
/**
|
|
9680
9704
|
* Parse `src` as `goal`, and find its variable references and string text.
|
|
9681
9705
|
* Throws a `CodeSyntaxError` for code that is not well-formed, and for a
|
|
9682
9706
|
* sigil variable declared (`let _x`) or used as a property name (`a.@x`).
|
|
@@ -9685,13 +9709,13 @@ function parseCode(src, goal = "expression") {
|
|
|
9685
9709
|
return parseWithAst(src, goal).out;
|
|
9686
9710
|
}
|
|
9687
9711
|
/** What parseCode finds in `src`, and the syntax tree it is in. */
|
|
9688
|
-
function parseWithAst(src, goal) {
|
|
9712
|
+
function parseWithAst(src, goal, effects) {
|
|
9689
9713
|
const ast = parseAst(src, goal);
|
|
9690
9714
|
const out = {
|
|
9691
9715
|
refs: [],
|
|
9692
9716
|
strings: []
|
|
9693
9717
|
};
|
|
9694
|
-
walk(ast, src, out, false, false);
|
|
9718
|
+
walk(ast, src, out, false, false, "read", effects);
|
|
9695
9719
|
out.refs.sort((a, b) => a.start - b.start);
|
|
9696
9720
|
return {
|
|
9697
9721
|
out,
|
|
@@ -9789,47 +9813,83 @@ function propertyName(node, src) {
|
|
|
9789
9813
|
const c = src.charAt(node.start);
|
|
9790
9814
|
if (c === "@" || c === "%") throw new CodeSyntaxError(`"${node.name}" can't be a property name`, src, node.start);
|
|
9791
9815
|
}
|
|
9816
|
+
/** Keep static member keys decoded; an arbitrary computed key stays unknown. */
|
|
9817
|
+
function mutationTarget(node, src) {
|
|
9818
|
+
const path = [];
|
|
9819
|
+
while (node.type === "MemberExpression") {
|
|
9820
|
+
const property = node.property;
|
|
9821
|
+
path.push(!node.computed && property.type === "Identifier" ? property.name : property.type === "Literal" && ["string", "number"].includes(typeof property.value) ? String(property.value) : null);
|
|
9822
|
+
node = node.object;
|
|
9823
|
+
}
|
|
9824
|
+
return {
|
|
9825
|
+
root: node.type === "Identifier" ? sigilOf(node, src) : null,
|
|
9826
|
+
path: path.reverse()
|
|
9827
|
+
};
|
|
9828
|
+
}
|
|
9792
9829
|
/**
|
|
9793
9830
|
* Collect the references and string text under `node`. `binding`: the
|
|
9794
9831
|
* identifiers here are declared (a `let`, a parameter), where a sigil
|
|
9795
9832
|
* variable can't be. `shorthand`: the node is a shorthand property's value.
|
|
9796
9833
|
*/
|
|
9797
|
-
function walk(root, src, out, binding, shorthand, access = "read") {
|
|
9834
|
+
function walk(root, src, out, binding, shorthand, access = "read", effects) {
|
|
9798
9835
|
const pending = [[
|
|
9799
9836
|
root,
|
|
9800
9837
|
binding,
|
|
9801
9838
|
shorthand,
|
|
9802
|
-
access
|
|
9839
|
+
access,
|
|
9840
|
+
false,
|
|
9841
|
+
false
|
|
9803
9842
|
]];
|
|
9804
9843
|
while (pending.length) {
|
|
9805
|
-
const [node, bind, short, role] = pending.pop();
|
|
9844
|
+
const [node, bind, short, role, memberObject, escapes] = pending.pop();
|
|
9806
9845
|
const children = [];
|
|
9807
|
-
visit(node, bind, short, role, children);
|
|
9846
|
+
visit(node, bind, short, role, memberObject, escapes, children);
|
|
9808
9847
|
for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
|
|
9809
9848
|
}
|
|
9810
|
-
function visit(node, binding, shorthand, access, children) {
|
|
9849
|
+
function visit(node, binding, shorthand, access, memberObject, escapes, children) {
|
|
9811
9850
|
if (Array.isArray(node)) {
|
|
9812
9851
|
for (const n of node) children.push([
|
|
9813
9852
|
n,
|
|
9814
9853
|
binding,
|
|
9815
9854
|
false,
|
|
9816
|
-
access
|
|
9855
|
+
access,
|
|
9856
|
+
false,
|
|
9857
|
+
escapes
|
|
9817
9858
|
]);
|
|
9818
9859
|
return;
|
|
9819
9860
|
}
|
|
9820
9861
|
if (!isNode(node)) return;
|
|
9821
|
-
const sub = (child, bind = false, short = false, role = "read") => {
|
|
9862
|
+
const sub = (child, bind = false, short = false, role = "read", member = false, escape = escapes) => {
|
|
9822
9863
|
children.push([
|
|
9823
9864
|
child,
|
|
9824
9865
|
bind,
|
|
9825
9866
|
short,
|
|
9826
|
-
role
|
|
9867
|
+
role,
|
|
9868
|
+
member,
|
|
9869
|
+
escape
|
|
9827
9870
|
]);
|
|
9828
9871
|
};
|
|
9872
|
+
const uncertain = (reason) => effects?.uncertain.push({
|
|
9873
|
+
start: node.start,
|
|
9874
|
+
end: node.end,
|
|
9875
|
+
reason
|
|
9876
|
+
});
|
|
9877
|
+
if (effects) {
|
|
9878
|
+
if ([
|
|
9879
|
+
"CallExpression",
|
|
9880
|
+
"NewExpression",
|
|
9881
|
+
"TaggedTemplateExpression"
|
|
9882
|
+
].includes(node.type)) uncertain("call");
|
|
9883
|
+
if (node.type === "WithStatement") uncertain("dynamic-scope");
|
|
9884
|
+
if (escapes && node.type === "ThisExpression") uncertain("escape");
|
|
9885
|
+
}
|
|
9829
9886
|
switch (node.type) {
|
|
9830
9887
|
case "Identifier": {
|
|
9831
9888
|
const sigil = sigilOf(node, src);
|
|
9832
|
-
if (!sigil)
|
|
9889
|
+
if (!sigil) {
|
|
9890
|
+
if (effects && escapes && !binding && !memberObject && access === "read") uncertain("escape");
|
|
9891
|
+
return;
|
|
9892
|
+
}
|
|
9833
9893
|
if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
|
|
9834
9894
|
out.refs.push({
|
|
9835
9895
|
sigil: sigil[0],
|
|
@@ -9840,6 +9900,19 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9840
9900
|
read: access !== "write",
|
|
9841
9901
|
write: access !== "read"
|
|
9842
9902
|
});
|
|
9903
|
+
if (effects) {
|
|
9904
|
+
if (access !== "read") effects.mutations.push({
|
|
9905
|
+
start: node.start,
|
|
9906
|
+
end: node.end,
|
|
9907
|
+
target: {
|
|
9908
|
+
sigil: sigil[0],
|
|
9909
|
+
name: sigil[1],
|
|
9910
|
+
path: []
|
|
9911
|
+
},
|
|
9912
|
+
read: access !== "write"
|
|
9913
|
+
});
|
|
9914
|
+
else if (!memberObject) uncertain("escape");
|
|
9915
|
+
}
|
|
9843
9916
|
return;
|
|
9844
9917
|
}
|
|
9845
9918
|
case "Literal":
|
|
@@ -9848,8 +9921,29 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9848
9921
|
case "TemplateElement":
|
|
9849
9922
|
out.strings.push(node.value.raw);
|
|
9850
9923
|
return;
|
|
9924
|
+
case "ChainExpression":
|
|
9925
|
+
sub(node.expression, binding, shorthand, access, memberObject);
|
|
9926
|
+
return;
|
|
9851
9927
|
case "MemberExpression":
|
|
9852
|
-
|
|
9928
|
+
if (effects && escapes && !memberObject && access === "read") uncertain("escape");
|
|
9929
|
+
if (effects && !binding && access !== "read") {
|
|
9930
|
+
const { root, path } = mutationTarget(node, src);
|
|
9931
|
+
const target = root ? {
|
|
9932
|
+
sigil: root[0],
|
|
9933
|
+
name: root[1],
|
|
9934
|
+
path
|
|
9935
|
+
} : null;
|
|
9936
|
+
effects.mutations.push({
|
|
9937
|
+
start: node.start,
|
|
9938
|
+
end: node.end,
|
|
9939
|
+
target,
|
|
9940
|
+
read: access !== "write"
|
|
9941
|
+
});
|
|
9942
|
+
if (!target) uncertain("indirect-write");
|
|
9943
|
+
if (path.includes(null)) uncertain("computed-write");
|
|
9944
|
+
if (path.some((key) => key === "prototype" || key === "__proto__")) uncertain("prototype-write");
|
|
9945
|
+
}
|
|
9946
|
+
sub(node.object, false, false, "read", true);
|
|
9853
9947
|
if (node.computed) sub(node.property);
|
|
9854
9948
|
else propertyName(node.property, src);
|
|
9855
9949
|
return;
|
|
@@ -9860,7 +9954,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9860
9954
|
const value = node.value;
|
|
9861
9955
|
if (value.type === "AssignmentPattern") {
|
|
9862
9956
|
sub(value.left, binding, true, access);
|
|
9863
|
-
sub(value.right);
|
|
9957
|
+
sub(value.right, false, false, "read", false, true);
|
|
9864
9958
|
} else sub(value, binding, true, access);
|
|
9865
9959
|
} else sub(node.value, binding, false, access);
|
|
9866
9960
|
return;
|
|
@@ -9868,7 +9962,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9868
9962
|
case "PropertyDefinition":
|
|
9869
9963
|
if (node.computed) sub(node.key);
|
|
9870
9964
|
else propertyName(node.key, src);
|
|
9871
|
-
sub(node.value);
|
|
9965
|
+
sub(node.value, false, false, "read", false, node.type === "PropertyDefinition" || escapes);
|
|
9872
9966
|
return;
|
|
9873
9967
|
case "LabeledStatement":
|
|
9874
9968
|
sub(node.body);
|
|
@@ -9879,7 +9973,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9879
9973
|
case "PrivateIdentifier": return;
|
|
9880
9974
|
case "VariableDeclarator":
|
|
9881
9975
|
sub(node.id, true);
|
|
9882
|
-
sub(node.init);
|
|
9976
|
+
sub(node.init, false, false, "read", false, true);
|
|
9883
9977
|
return;
|
|
9884
9978
|
case "FunctionDeclaration":
|
|
9885
9979
|
case "FunctionExpression":
|
|
@@ -9900,7 +9994,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9900
9994
|
return;
|
|
9901
9995
|
case "AssignmentExpression":
|
|
9902
9996
|
sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
|
|
9903
|
-
sub(node.right);
|
|
9997
|
+
sub(node.right, false, false, "read", false, true);
|
|
9998
|
+
return;
|
|
9999
|
+
case "ReturnStatement":
|
|
10000
|
+
case "ThrowStatement":
|
|
10001
|
+
case "YieldExpression":
|
|
10002
|
+
sub(node.argument, false, false, "read", false, true);
|
|
9904
10003
|
return;
|
|
9905
10004
|
case "UnaryExpression":
|
|
9906
10005
|
sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
|
|
@@ -9911,12 +10010,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
|
|
|
9911
10010
|
case "ForInStatement":
|
|
9912
10011
|
case "ForOfStatement":
|
|
9913
10012
|
sub(node.left, false, false, "write");
|
|
9914
|
-
sub(node.right);
|
|
10013
|
+
sub(node.right, false, false, "read", false, true);
|
|
9915
10014
|
sub(node.body);
|
|
9916
10015
|
return;
|
|
9917
10016
|
case "AssignmentPattern":
|
|
9918
10017
|
sub(node.left, binding, false, access);
|
|
9919
|
-
sub(node.right);
|
|
10018
|
+
sub(node.right, false, false, "read", false, true);
|
|
9920
10019
|
return;
|
|
9921
10020
|
case "ObjectPattern":
|
|
9922
10021
|
case "ArrayPattern":
|
|
@@ -10858,7 +10957,7 @@ var MarkupError = class extends Error {
|
|
|
10858
10957
|
this.name = "MarkupError";
|
|
10859
10958
|
}
|
|
10860
10959
|
};
|
|
10861
|
-
function run$1(source, startRule, options, completion = false) {
|
|
10960
|
+
function run$1(source, startRule, options, completion = false, findDelimiter = indexDelimiters(source)) {
|
|
10862
10961
|
const hooks = {
|
|
10863
10962
|
...defaultHooks,
|
|
10864
10963
|
...options.hooks
|
|
@@ -10872,7 +10971,8 @@ function run$1(source, startRule, options, completion = false) {
|
|
|
10872
10971
|
startRule,
|
|
10873
10972
|
text: options.text === true,
|
|
10874
10973
|
hooks,
|
|
10875
|
-
completion
|
|
10974
|
+
completion,
|
|
10975
|
+
findDelimiter
|
|
10876
10976
|
});
|
|
10877
10977
|
} catch (err) {
|
|
10878
10978
|
const { location, code } = err;
|
|
@@ -10884,6 +10984,20 @@ function run$1(source, startRule, options, completion = false) {
|
|
|
10884
10984
|
throw err;
|
|
10885
10985
|
}
|
|
10886
10986
|
}
|
|
10987
|
+
/** Literal delimiter searches shared by suffix and prefix recovery attempts. */
|
|
10988
|
+
function indexDelimiters(source) {
|
|
10989
|
+
const positions = /* @__PURE__ */ new Map();
|
|
10990
|
+
return (delimiter, from, end = source.length) => {
|
|
10991
|
+
let offsets = positions.get(delimiter);
|
|
10992
|
+
if (!offsets) {
|
|
10993
|
+
offsets = [];
|
|
10994
|
+
for (let at = source.indexOf(delimiter); at >= 0; at = source.indexOf(delimiter, at + 1)) offsets.push(at);
|
|
10995
|
+
positions.set(delimiter, offsets);
|
|
10996
|
+
}
|
|
10997
|
+
const at = offsets[upperBound(offsets, from - 1)];
|
|
10998
|
+
return at !== void 0 && at + delimiter.length <= end ? at : -1;
|
|
10999
|
+
};
|
|
11000
|
+
}
|
|
10887
11001
|
/**
|
|
10888
11002
|
* Read markup that may be malformed: its tokens, their pairing and every
|
|
10889
11003
|
* error (malformed tags, and closers and branches that pair with nothing),
|
|
@@ -10900,6 +11014,7 @@ function analyzeMarkup(source, options = {}) {
|
|
|
10900
11014
|
isBlock: hooks.isBlock,
|
|
10901
11015
|
isRaw: hooks.isRaw,
|
|
10902
11016
|
branchParents: hooks.branchParents,
|
|
11017
|
+
isStandalone: hooks.isStandalone,
|
|
10903
11018
|
source
|
|
10904
11019
|
});
|
|
10905
11020
|
if (errors.length === 0 && paired.errors.length === 0) return {
|
|
@@ -10984,6 +11099,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
10984
11099
|
const damage = [];
|
|
10985
11100
|
let position;
|
|
10986
11101
|
const codeEnd = indexCodeEnds(source);
|
|
11102
|
+
const findDelimiter = indexDelimiters(source);
|
|
10987
11103
|
const customCloseBrace = options.hooks?.closeBrace;
|
|
10988
11104
|
const lastBrace = source.lastIndexOf("}");
|
|
10989
11105
|
/** `text` shifted by `base`, tokenized: the tokens or the error. */
|
|
@@ -11001,7 +11117,10 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
11001
11117
|
return run$1(text, "Tokens", {
|
|
11002
11118
|
...options,
|
|
11003
11119
|
hooks
|
|
11004
|
-
}, completion
|
|
11120
|
+
}, completion, (delimiter, from) => {
|
|
11121
|
+
const at = findDelimiter(delimiter, base + from, base + text.length);
|
|
11122
|
+
return at < 0 ? -1 : at - base;
|
|
11123
|
+
}).map((token) => shiftOffsets(token, base));
|
|
11005
11124
|
} catch (error) {
|
|
11006
11125
|
if (!(error instanceof MarkupError)) throw error;
|
|
11007
11126
|
return error;
|
|
@@ -11715,6 +11834,7 @@ function parameterLookup(macros) {
|
|
|
11715
11834
|
lookup.source = (name) => sources.get(name);
|
|
11716
11835
|
const definitions = new NameMap(effectiveNamedDefinitions([...list.filter((macro) => !macro.widget), ...list.filter((macro) => macro.widget)]).map((macro) => [macro.name, macro]));
|
|
11717
11836
|
lookup.pairing = {
|
|
11837
|
+
isStandalone: (name) => widgets.has(name) || sources.get(name) === "user",
|
|
11718
11838
|
isBlock: (name) => definitions.get(name)?.block ?? isBuiltinBlockMacro(name),
|
|
11719
11839
|
isRaw: (name) => isRawMacro(name, widgets.has(name)),
|
|
11720
11840
|
branchParents: branchParentLookup([...definitions.values()].map((macro) => ({
|
|
@@ -12655,6 +12775,7 @@ function validateMarkup(passages, options) {
|
|
|
12655
12775
|
const diagnostics = [];
|
|
12656
12776
|
const positions = /* @__PURE__ */ new Map();
|
|
12657
12777
|
const hooks = {
|
|
12778
|
+
...options.parametersOf?.pairing?.isStandalone && { isStandalone: options.parametersOf.pairing.isStandalone },
|
|
12658
12779
|
...options.isBlockMacro && { isBlock: options.isBlockMacro },
|
|
12659
12780
|
...options.branchParents && { branchParents: options.branchParents },
|
|
12660
12781
|
isRaw: (name) => isRawMacro(name, options.parametersOf ? options.parametersOf.widget?.(name) !== void 0 : void 0)
|
|
@@ -13798,6 +13919,7 @@ var Bindings = class {
|
|
|
13798
13919
|
this.byClose = /* @__PURE__ */ new Map();
|
|
13799
13920
|
this.functions = /* @__PURE__ */ new Map();
|
|
13800
13921
|
this.functionStarts = /* @__PURE__ */ new Map();
|
|
13922
|
+
this.listKeywords = /* @__PURE__ */ new Map();
|
|
13801
13923
|
this.facts = /* @__PURE__ */ new Map();
|
|
13802
13924
|
this.top = {
|
|
13803
13925
|
start: -1,
|
|
@@ -13969,29 +14091,46 @@ var Bindings = class {
|
|
|
13969
14091
|
*/
|
|
13970
14092
|
statementEnd(from) {
|
|
13971
14093
|
const { code } = this;
|
|
13972
|
-
const
|
|
13973
|
-
|
|
13974
|
-
|
|
13975
|
-
|
|
13976
|
-
|
|
13977
|
-
|
|
13978
|
-
|
|
13979
|
-
|
|
13980
|
-
|
|
13981
|
-
|
|
14094
|
+
const pendingIf = [];
|
|
14095
|
+
statements: while (true) {
|
|
14096
|
+
const start = this.forward(from);
|
|
14097
|
+
const block = this.byOpen.get(start);
|
|
14098
|
+
let end;
|
|
14099
|
+
if (block?.kind === "{") end = Math.min(block.close + 1, code.length);
|
|
14100
|
+
else {
|
|
14101
|
+
const word = this.wordAt(start);
|
|
14102
|
+
if (/^(?:if|for|while|with)$/.test(word)) {
|
|
14103
|
+
let paren = this.forward(start + word.length);
|
|
14104
|
+
if (word === "for" && this.wordAt(paren) === "await") paren = this.forward(paren + 5);
|
|
14105
|
+
const header = this.byOpen.get(paren);
|
|
14106
|
+
if (header) {
|
|
14107
|
+
pendingIf.push(word === "if");
|
|
14108
|
+
from = header.close + 1;
|
|
14109
|
+
continue;
|
|
14110
|
+
}
|
|
14111
|
+
}
|
|
14112
|
+
for (end = start; end < code.length; end++) {
|
|
14113
|
+
const c = code.charAt(end);
|
|
14114
|
+
if (c === ";") {
|
|
14115
|
+
end++;
|
|
14116
|
+
break;
|
|
14117
|
+
}
|
|
14118
|
+
if (CLOSERS[c]) break;
|
|
14119
|
+
const group = this.byOpen.get(end);
|
|
14120
|
+
if (group) end = group.close;
|
|
14121
|
+
else if (c === "\n" && this.startsStatement(end)) break;
|
|
14122
|
+
}
|
|
14123
|
+
}
|
|
14124
|
+
while (pendingIf.length) {
|
|
14125
|
+
const isIf = pendingIf.pop();
|
|
13982
14126
|
const next = this.forward(end);
|
|
13983
|
-
|
|
14127
|
+
if (isIf && this.wordAt(next) === "else") {
|
|
14128
|
+
from = next + 4;
|
|
14129
|
+
continue statements;
|
|
14130
|
+
}
|
|
13984
14131
|
}
|
|
14132
|
+
return end;
|
|
13985
14133
|
}
|
|
13986
|
-
for (let end = start; end < code.length; end++) {
|
|
13987
|
-
const c = code.charAt(end);
|
|
13988
|
-
if (c === ";") return end + 1;
|
|
13989
|
-
if (CLOSERS[c]) return end;
|
|
13990
|
-
const group = this.byOpen.get(end);
|
|
13991
|
-
if (group) end = group.close;
|
|
13992
|
-
else if (c === "\n" && this.startsStatement(end)) return end;
|
|
13993
|
-
}
|
|
13994
|
-
return code.length;
|
|
13995
14134
|
}
|
|
13996
14135
|
/** Whether the line break at `index` ends a statement, and one follows. */
|
|
13997
14136
|
startsStatement(index) {
|
|
@@ -14087,17 +14226,35 @@ var Bindings = class {
|
|
|
14087
14226
|
listKeyword(comma) {
|
|
14088
14227
|
const { code } = this;
|
|
14089
14228
|
const floor = this.innermost(comma)?.open ?? -1;
|
|
14090
|
-
|
|
14229
|
+
const visited = [];
|
|
14230
|
+
let result;
|
|
14231
|
+
for (let i = comma; i > floor; i--) {
|
|
14091
14232
|
const c = code.charAt(i);
|
|
14092
|
-
if (c === ";")
|
|
14233
|
+
if (c === ";") break;
|
|
14234
|
+
if (c === ",") {
|
|
14235
|
+
const cached = this.listKeywords.get(i);
|
|
14236
|
+
if (cached?.floor === floor) {
|
|
14237
|
+
result = cached.word;
|
|
14238
|
+
break;
|
|
14239
|
+
}
|
|
14240
|
+
visited.push(i);
|
|
14241
|
+
}
|
|
14093
14242
|
const group = CLOSERS[c] ? this.byClose.get(i) : void 0;
|
|
14094
14243
|
if (group) i = group.open;
|
|
14095
14244
|
else if (isWordChar(c)) {
|
|
14096
14245
|
const word = this.wordBefore(i + 1);
|
|
14097
|
-
if (DECLARATIONS.has(word.text) && code.charAt(word.start - 1) !== ".")
|
|
14246
|
+
if (DECLARATIONS.has(word.text) && code.charAt(word.start - 1) !== ".") {
|
|
14247
|
+
result = word;
|
|
14248
|
+
break;
|
|
14249
|
+
}
|
|
14098
14250
|
i = word.start;
|
|
14099
14251
|
}
|
|
14100
14252
|
}
|
|
14253
|
+
for (const at of visited) this.listKeywords.set(at, {
|
|
14254
|
+
floor,
|
|
14255
|
+
word: result
|
|
14256
|
+
});
|
|
14257
|
+
return result;
|
|
14101
14258
|
}
|
|
14102
14259
|
nameEnd(at) {
|
|
14103
14260
|
let end = at;
|
|
@@ -25888,6 +26045,7 @@ async function formatLf(text, options) {
|
|
|
25888
26045
|
return (await format(code, prettier, prettierOptions) ?? code).trim() + "\n";
|
|
25889
26046
|
}
|
|
25890
26047
|
const isBlock = options.isBlock ?? defaultIsBlock(body, options.blockMacros);
|
|
26048
|
+
if (analyzeMarkup(body, { hooks: { isBlock } }).errors.some((error) => error.code === "nesting-limit")) return text;
|
|
25891
26049
|
const isDedenting = options.isDedentingSubMacro ?? ((name) => DEFAULT_DEDENTING.has(name.toLowerCase()));
|
|
25892
26050
|
const sentinel = newlineSentinel(body);
|
|
25893
26051
|
const literalSentinel = newlineSentinel(body + sentinel);
|
|
@@ -26378,6 +26536,7 @@ function tokenizationOptions(options) {
|
|
|
26378
26536
|
isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0),
|
|
26379
26537
|
isBlock: blockLookup(macros),
|
|
26380
26538
|
branchParents: branchParentLookup(macros),
|
|
26539
|
+
isStandalone: parametersOf.pairing.isStandalone,
|
|
26381
26540
|
...options.hooks
|
|
26382
26541
|
}
|
|
26383
26542
|
};
|
|
@@ -26632,4 +26791,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
|
|
|
26632
26791
|
const list = [...passages];
|
|
26633
26792
|
return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
|
|
26634
26793
|
}
|
|
26635
|
-
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, indexStrictCodeEnds, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|
|
26794
|
+
export { MarkupError, SIGIL_SCOPES, analyzeCodeEffects, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, indexStrictCodeEnds, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|
package/dist/pkg/tooling.js
CHANGED
package/package.json
CHANGED
package/src/code-check.ts
CHANGED
|
@@ -396,6 +396,7 @@ export function parameterLookup(
|
|
|
396
396
|
]).map((macro) => [macro.name, macro]),
|
|
397
397
|
);
|
|
398
398
|
lookup.pairing = {
|
|
399
|
+
isStandalone: (name) => widgets.has(name) || sources.get(name) === 'user',
|
|
399
400
|
isBlock: (name) =>
|
|
400
401
|
definitions.get(name)?.block ?? isBuiltinBlockMacro(name),
|
|
401
402
|
isRaw: (name) => isRawMacro(name, widgets.has(name)),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useState,
|
|
3
3
|
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
4
5
|
useCallback,
|
|
5
6
|
useRef,
|
|
6
7
|
useContext,
|
|
@@ -135,7 +136,7 @@ export function SaveManagerContent({
|
|
|
135
136
|
statusTimer.current = window.setTimeout(() => setStatus(null), 3000);
|
|
136
137
|
};
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
useLayoutEffect(() => {
|
|
139
140
|
mounted.current = true;
|
|
140
141
|
return () => {
|
|
141
142
|
mounted.current = false;
|
|
@@ -243,8 +244,11 @@ export function SaveManagerContent({
|
|
|
243
244
|
replacement,
|
|
244
245
|
);
|
|
245
246
|
showStatus('Game loaded');
|
|
246
|
-
if (closeDialog) {
|
|
247
|
-
closeTimer.current
|
|
247
|
+
if (closeDialog && mounted.current) {
|
|
248
|
+
clearTimeout(closeTimer.current);
|
|
249
|
+
closeTimer.current = window.setTimeout(() => {
|
|
250
|
+
if (mounted.current) closeDialog();
|
|
251
|
+
}, 500);
|
|
248
252
|
}
|
|
249
253
|
// A playthrough deleted since the list was read is recorded again
|
|
250
254
|
await refresh();
|
|
@@ -3,6 +3,7 @@ import { useCallback, useLayoutEffect, useRef, useState } from 'preact/hooks';
|
|
|
3
3
|
import { defineMacro, type MacroContext } from '../../define-macro';
|
|
4
4
|
import { useStoryStore } from '../../store';
|
|
5
5
|
import { subscribeVariableWrites } from '../../utils/variable-writes';
|
|
6
|
+
import { batchControlValues } from '../../utils/control-bindings';
|
|
6
7
|
import {
|
|
7
8
|
actionAttributes,
|
|
8
9
|
useControlAction,
|
|
@@ -65,7 +66,9 @@ function subscribeFormReset(
|
|
|
65
66
|
});
|
|
66
67
|
restoreDefaults();
|
|
67
68
|
const commits = controls.map(({ read, element }) => read(element));
|
|
68
|
-
|
|
69
|
+
batchControlValues(() => {
|
|
70
|
+
for (const commit of commits) commit();
|
|
71
|
+
});
|
|
69
72
|
}, 0);
|
|
70
73
|
};
|
|
71
74
|
subscription = { readers, reset };
|
package/src/define-macro.ts
CHANGED
|
@@ -12,11 +12,7 @@ import {
|
|
|
12
12
|
useMemo,
|
|
13
13
|
} from 'preact/hooks';
|
|
14
14
|
import { useInterpolate } from './hooks/use-interpolate';
|
|
15
|
-
import {
|
|
16
|
-
ItemEditContext,
|
|
17
|
-
runAsControlEdit,
|
|
18
|
-
runAsItemEdit,
|
|
19
|
-
} from './utils/control-edits';
|
|
15
|
+
import { ItemEditContext, runAsItemEdit } from './utils/control-edits';
|
|
20
16
|
import { useMergedLocals } from './hooks/use-merged-locals';
|
|
21
17
|
import { useRenderOptions } from './hooks/use-render-options';
|
|
22
18
|
import {
|
|
@@ -25,10 +21,10 @@ import {
|
|
|
25
21
|
renderInlineNodes,
|
|
26
22
|
} from './markup/render';
|
|
27
23
|
import type { ASTNode } from './markup/ast';
|
|
28
|
-
import { executeMutation,
|
|
24
|
+
import { executeMutation, readState } from './execute-mutation';
|
|
29
25
|
import { evaluateDisplay } from './expression';
|
|
30
26
|
import { useStoryFields } from './hooks/use-story-fields';
|
|
31
|
-
import { getByPath
|
|
27
|
+
import { getByPath } from './utils/object-path';
|
|
32
28
|
import { useAction } from './hooks/use-action';
|
|
33
29
|
import type { UseActionOptions } from './hooks/use-action';
|
|
34
30
|
import { collectText } from './utils/extract-text';
|
|
@@ -47,7 +43,7 @@ import {
|
|
|
47
43
|
displayOnlyError,
|
|
48
44
|
} from './display-only';
|
|
49
45
|
import { NameSet } from './utils/macro-names';
|
|
50
|
-
import {
|
|
46
|
+
import { setControlValue } from './utils/control-bindings';
|
|
51
47
|
import {
|
|
52
48
|
checkParameterTypes,
|
|
53
49
|
registerMacro,
|
|
@@ -254,19 +250,7 @@ export function defineMacro<const P extends readonly ParameterDef[] = []>(
|
|
|
254
250
|
ctx.getValue = () => getByPath(readState().variables, segments);
|
|
255
251
|
ctx.setValue = displayOnly
|
|
256
252
|
? refuse
|
|
257
|
-
: (value: unknown) =>
|
|
258
|
-
notifyVariableWrite(segments);
|
|
259
|
-
// The commit mutation code uses, which keeps the references among
|
|
260
|
-
// variables: a write to a draft copies only the path written, and
|
|
261
|
-
// other variables sharing the object would keep the old one.
|
|
262
|
-
runAsControlEdit(segments, () => {
|
|
263
|
-
mutateState((work, adopt) => {
|
|
264
|
-
setByPath(work.variables, segments, adopt(value), {
|
|
265
|
-
createMissing: true,
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
};
|
|
253
|
+
: (value: unknown) => setControlValue(segments, value);
|
|
270
254
|
}
|
|
271
255
|
|
|
272
256
|
try {
|
|
@@ -216,6 +216,15 @@ async function formatLf(
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
const isBlock = options.isBlock ?? defaultIsBlock(body, options.blockMacros);
|
|
219
|
+
// Pairing retains a tolerant tree beyond the runtime's nesting limit.
|
|
220
|
+
// Leave unsupported passages intact before any recursive formatter walks.
|
|
221
|
+
if (
|
|
222
|
+
analyzeMarkup(body, { hooks: { isBlock } }).errors.some(
|
|
223
|
+
(error) => error.code === 'nesting-limit',
|
|
224
|
+
)
|
|
225
|
+
) {
|
|
226
|
+
return text;
|
|
227
|
+
}
|
|
219
228
|
const isDedenting =
|
|
220
229
|
options.isDedentingSubMacro ??
|
|
221
230
|
((name: string) => DEFAULT_DEDENTING.has(name.toLowerCase()));
|