@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/src/types-drift-check.ts
CHANGED
|
@@ -116,6 +116,16 @@ type ToolingChecks = [
|
|
|
116
116
|
PublishedTooling.VariableReference
|
|
117
117
|
>,
|
|
118
118
|
Same<typeof SourceTooling.parseCode, typeof PublishedTooling.parseCode>,
|
|
119
|
+
Same<
|
|
120
|
+
typeof SourceTooling.analyzeCodeEffects,
|
|
121
|
+
typeof PublishedTooling.analyzeCodeEffects
|
|
122
|
+
>,
|
|
123
|
+
SameShape<SourceTooling.CodeEffects, PublishedTooling.CodeEffects>,
|
|
124
|
+
SameShape<SourceTooling.CodeMutation, PublishedTooling.CodeMutation>,
|
|
125
|
+
SameShape<
|
|
126
|
+
SourceTooling.CodeShapeUncertainty,
|
|
127
|
+
PublishedTooling.CodeShapeUncertainty
|
|
128
|
+
>,
|
|
119
129
|
Same<
|
|
120
130
|
typeof SourceTooling.macroArgumentSpans,
|
|
121
131
|
typeof PublishedTooling.macroArgumentSpans
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mutateState } from '../execute-mutation';
|
|
2
|
+
import { runAsControlEdits } from './control-edits';
|
|
3
|
+
import { setByPath } from './object-path';
|
|
4
|
+
import { notifyVariableWrite } from './variable-writes';
|
|
5
|
+
|
|
6
|
+
interface ControlWrite {
|
|
7
|
+
segments: readonly string[];
|
|
8
|
+
value: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let pending: ControlWrite[] | undefined;
|
|
12
|
+
|
|
13
|
+
/** Commit related bindings together, preserving references and item edits. */
|
|
14
|
+
function commit(writes: readonly ControlWrite[]): void {
|
|
15
|
+
if (!writes.length) return;
|
|
16
|
+
runAsControlEdits(
|
|
17
|
+
writes.map(({ segments }) => segments),
|
|
18
|
+
() => {
|
|
19
|
+
mutateState((work, adopt) => {
|
|
20
|
+
for (const { segments, value } of writes) {
|
|
21
|
+
setByPath(work.variables, segments, adopt(value), {
|
|
22
|
+
createMissing: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A control write, or one part of the form reset currently being collected. */
|
|
31
|
+
export function setControlValue(
|
|
32
|
+
segments: readonly string[],
|
|
33
|
+
value: unknown,
|
|
34
|
+
): void {
|
|
35
|
+
notifyVariableWrite(segments);
|
|
36
|
+
const write = { segments, value };
|
|
37
|
+
if (pending) pending.push(write);
|
|
38
|
+
else commit([write]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Subscribers see the complete reset, never a partially reset form. */
|
|
42
|
+
export function batchControlValues(run: () => void): void {
|
|
43
|
+
if (pending) return run();
|
|
44
|
+
const writes: ControlWrite[] = [];
|
|
45
|
+
pending = writes;
|
|
46
|
+
try {
|
|
47
|
+
run();
|
|
48
|
+
} finally {
|
|
49
|
+
pending = undefined;
|
|
50
|
+
}
|
|
51
|
+
commit(writes);
|
|
52
|
+
}
|
|
@@ -65,7 +65,18 @@ export function runAsControlEdit(
|
|
|
65
65
|
segments: readonly string[],
|
|
66
66
|
run: () => void,
|
|
67
67
|
): void {
|
|
68
|
-
|
|
68
|
+
runAsControlEdits([segments], run);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Attribute every binding of an atomic form reset to its own path. */
|
|
72
|
+
export function runAsControlEdits(
|
|
73
|
+
paths: readonly (readonly string[])[],
|
|
74
|
+
run: () => void,
|
|
75
|
+
): void {
|
|
76
|
+
withEdits(
|
|
77
|
+
paths.map((segments) => ['variables', ...segments]),
|
|
78
|
+
run,
|
|
79
|
+
);
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
/** Whether mutation code runs inside a {for} iteration. */
|
package/types/tooling.d.ts
CHANGED
|
@@ -1071,6 +1071,8 @@ export interface PairMarkupOptions {
|
|
|
1071
1071
|
isRaw?(name: string): boolean;
|
|
1072
1072
|
/** Parents declaring a branching sub-macro (default: registered metadata). */
|
|
1073
1073
|
branchParents?(name: string): readonly string[];
|
|
1074
|
+
/** Whether a companion name also has a standalone macro/widget implementation. */
|
|
1075
|
+
isStandalone?(name: string): boolean;
|
|
1074
1076
|
/**
|
|
1075
1077
|
* The markup the tokens are of: lets a message say at which line and column
|
|
1076
1078
|
* an element was opened (else it says at which offset).
|
|
@@ -1290,6 +1292,44 @@ export interface ParsedCode {
|
|
|
1290
1292
|
strings: string[];
|
|
1291
1293
|
}
|
|
1292
1294
|
|
|
1295
|
+
/** A binding write (empty path), or a member write, with the entire target span. */
|
|
1296
|
+
export interface CodeMutation {
|
|
1297
|
+
start: number;
|
|
1298
|
+
end: number;
|
|
1299
|
+
/** Null for an indirect target; null path segments are computed keys. */
|
|
1300
|
+
target: { sigil: Sigil; name: string; path: (string | null)[] } | null;
|
|
1301
|
+
/** Compound assignments and updates read the target as well as writing it. */
|
|
1302
|
+
read: boolean;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/** A reason declaration-time shapes alone cannot justify a missing-member advisory. */
|
|
1306
|
+
export interface CodeShapeUncertainty {
|
|
1307
|
+
start: number;
|
|
1308
|
+
end: number;
|
|
1309
|
+
reason:
|
|
1310
|
+
| 'computed-write'
|
|
1311
|
+
| 'indirect-write'
|
|
1312
|
+
| 'prototype-write'
|
|
1313
|
+
| 'call'
|
|
1314
|
+
| 'escape'
|
|
1315
|
+
| 'dynamic-scope';
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
export interface CodeEffects {
|
|
1319
|
+
mutations: CodeMutation[];
|
|
1320
|
+
uncertain: CodeShapeUncertainty[];
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
/** Conservative shape effects using parseCode's grammar and target roles.
|
|
1324
|
+
* Includes nested functions and unreachable branches. Offsets refer to src;
|
|
1325
|
+
* map through pieceOffset when analyzing decoded passagePieces code.
|
|
1326
|
+
* Throws for invalid code. No alias, call or control-flow analysis is attempted.
|
|
1327
|
+
*/
|
|
1328
|
+
export declare function analyzeCodeEffects(
|
|
1329
|
+
src: string,
|
|
1330
|
+
goal?: JsGoal,
|
|
1331
|
+
): CodeEffects;
|
|
1332
|
+
|
|
1293
1333
|
/** Parse executable code using the runtime grammar. Throws for malformed code
|
|
1294
1334
|
* (including sigil declarations); lexJs remains available for tolerant scanning.
|
|
1295
1335
|
* Member assignments read their root binding; only direct targets write it.
|