@rohal12/spindle 0.59.25 → 0.59.26
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 +339 -285
- package/dist/pkg/story-variables.js +141 -100
- package/package.json +23 -24
- package/src/automation/load-yaml.ts +1 -1
- package/src/components/macros/MacroError.tsx +1 -1
- package/src/components/macros/SaveManager.tsx +2 -2
- package/src/components/macros/macro-args.ts +1 -2
- package/src/execute-mutation.ts +4 -3
- package/src/hooks/use-modal-focus.ts +1 -1
- package/src/hooks/use-story-fields.ts +1 -1
- package/src/markup/ast.ts +1 -5
- package/src/markup/code-attributes.ts +1 -3
- package/src/markup/code-end.ts +1 -1
- package/src/markup/line-column.ts +1 -1
- package/src/markup/pair.ts +1 -4
- package/src/markup/render.tsx +10 -9
- package/src/static-literal.ts +1 -6
- package/src/store.ts +1 -1
- package/src/story-variables.ts +1 -6
- package/types/index.d.ts +2 -10
- package/types/tooling.d.ts +4 -17
|
@@ -175,7 +175,7 @@ function frameStops(doc: Document | null): HTMLElement[] {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
export function useModalFocus(
|
|
178
|
-
panelRef: RefObject<HTMLElement>,
|
|
178
|
+
panelRef: RefObject<HTMLElement | null>,
|
|
179
179
|
bodySelector: string,
|
|
180
180
|
dismissible: boolean,
|
|
181
181
|
onClose: () => void,
|
|
@@ -31,7 +31,7 @@ export const OutgoingContext = createContext<(() => boolean) | null>(null);
|
|
|
31
31
|
export function useStoryFields<K extends keyof StoryState>(
|
|
32
32
|
...keys: K[]
|
|
33
33
|
): Pick<StoryState, K> {
|
|
34
|
-
const prev = useRef<Pick<StoryState, K
|
|
34
|
+
const prev = useRef<Pick<StoryState, K> | undefined>(undefined);
|
|
35
35
|
const freeze = useContext(FrozenStateContext);
|
|
36
36
|
return useStoryStore((s) => {
|
|
37
37
|
if (prev.current && freeze?.(s)) return prev.current;
|
package/src/markup/ast.ts
CHANGED
|
@@ -45,11 +45,7 @@ export interface HtmlNode {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export type ASTNode =
|
|
48
|
-
|
|
|
49
|
-
| VariableNode
|
|
50
|
-
| ExpressionNode
|
|
51
|
-
| MacroNode
|
|
52
|
-
| HtmlNode;
|
|
48
|
+
TextNode | VariableNode | ExpressionNode | MacroNode | HtmlNode;
|
|
53
49
|
|
|
54
50
|
/** Macros that require a closing tag and can contain children */
|
|
55
51
|
const BLOCK_MACROS = new NameSet([
|
|
@@ -17,9 +17,7 @@ export function isCodeAttribute(name: string): boolean {
|
|
|
17
17
|
/** Literal text, the source of one `{…}` reference (without braces), or a
|
|
18
18
|
* `{…}` block that is kept exactly as written. */
|
|
19
19
|
export type SigilPart =
|
|
20
|
-
| {
|
|
21
|
-
| { expr: string }
|
|
22
|
-
| { verbatim: string };
|
|
20
|
+
{ text: string } | { expr: string } | { verbatim: string };
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
23
|
* Split a code attribute value into literal text and its `{…}` blocks that
|
package/src/markup/code-end.ts
CHANGED
|
@@ -33,7 +33,7 @@ const NON_STRING_QUOTE_PREFIX = /[\p{L}\p{N}_\\]/u;
|
|
|
33
33
|
function skipLiteral(input: string, i: number): number {
|
|
34
34
|
const quote = input[i];
|
|
35
35
|
const template = quote === '`';
|
|
36
|
-
for (let j = i + 1; j < input.length;
|
|
36
|
+
for (let j = i + 1; j < input.length;) {
|
|
37
37
|
const c = input[j];
|
|
38
38
|
if (c === '\\') j += 2;
|
|
39
39
|
else if (c === quote) return j + 1;
|
|
@@ -5,7 +5,7 @@ export function lineColumn(
|
|
|
5
5
|
): { line: number; column: number } {
|
|
6
6
|
let line = 1;
|
|
7
7
|
let lineStart = 0;
|
|
8
|
-
for (let i = text.indexOf('\n'); i !== -1 && i < offset;
|
|
8
|
+
for (let i = text.indexOf('\n'); i !== -1 && i < offset;) {
|
|
9
9
|
line++;
|
|
10
10
|
lineStart = i + 1;
|
|
11
11
|
i = text.indexOf('\n', lineStart);
|
package/src/markup/pair.ts
CHANGED
|
@@ -16,10 +16,7 @@ import type { HtmlToken, MacroToken, Span, Token } from './tokens';
|
|
|
16
16
|
|
|
17
17
|
/** What is wrong with the pairing, by kind. */
|
|
18
18
|
export type PairingErrorCode =
|
|
19
|
-
|
|
20
|
-
| 'mismatched-closer'
|
|
21
|
-
| 'stray-closer'
|
|
22
|
-
| 'misplaced-branch';
|
|
19
|
+
'unclosed-block' | 'mismatched-closer' | 'stray-closer' | 'misplaced-branch';
|
|
23
20
|
|
|
24
21
|
/**
|
|
25
22
|
* A problem in the pairing of the tokens, at the token from `start` up to
|
package/src/markup/render.tsx
CHANGED
|
@@ -353,11 +353,10 @@ function convertDomNode(
|
|
|
353
353
|
const parts = splitPlaceholderText(value, ph);
|
|
354
354
|
if (parts.every((part) => typeof part === 'string')) continue;
|
|
355
355
|
placeholders ??= {};
|
|
356
|
-
placeholders[name] = parts.map(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
: ph.nodes[part]!,
|
|
356
|
+
placeholders[name] = parts.map((part): ASTNode =>
|
|
357
|
+
typeof part === 'string'
|
|
358
|
+
? { type: 'text', value: part }
|
|
359
|
+
: ph.nodes[part]!,
|
|
361
360
|
);
|
|
362
361
|
}
|
|
363
362
|
|
|
@@ -572,7 +571,7 @@ function splitAttributes(
|
|
|
572
571
|
*/
|
|
573
572
|
function useDirectAttributes(
|
|
574
573
|
direct: [string, string][],
|
|
575
|
-
): RefObject<Element> | undefined {
|
|
574
|
+
): RefObject<Element | null> | undefined {
|
|
576
575
|
const elementRef = useRef<Element>(null);
|
|
577
576
|
const directKey = JSON.stringify(direct);
|
|
578
577
|
useLayoutEffect(() => {
|
|
@@ -708,9 +707,11 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
708
707
|
const isSvgRoot = tag === 'svg';
|
|
709
708
|
const isRawRoot = !inRaw && (isSvgRoot || PREFORMATTED_ELEMENTS.has(tag));
|
|
710
709
|
const errors: AttributeError[] = [];
|
|
711
|
-
const resolved = Object.entries(node.attributes).map(
|
|
712
|
-
|
|
713
|
-
|
|
710
|
+
const resolved = Object.entries(node.attributes).map(([k, v]): Attribute => [
|
|
711
|
+
k,
|
|
712
|
+
resolveAttributeValue(k, v, scope, errors),
|
|
713
|
+
v,
|
|
714
|
+
]);
|
|
714
715
|
const { props, direct } = splitAttributes(resolved, inSvg || isSvgRoot);
|
|
715
716
|
const ref = useDirectAttributes(direct);
|
|
716
717
|
if (ref) props.ref = ref;
|
package/src/static-literal.ts
CHANGED
|
@@ -11,12 +11,7 @@ import { scanStringLiteral } from './js-lexer';
|
|
|
11
11
|
|
|
12
12
|
/** The type of a variable by its default (see story-variables.ts VarType). */
|
|
13
13
|
type LiteralType =
|
|
14
|
-
| '
|
|
15
|
-
| 'string'
|
|
16
|
-
| 'boolean'
|
|
17
|
-
| 'array'
|
|
18
|
-
| 'object'
|
|
19
|
-
| 'null';
|
|
14
|
+
'number' | 'string' | 'boolean' | 'array' | 'object' | 'null';
|
|
20
15
|
|
|
21
16
|
/** The shape of a literal (see story-variables.ts FieldSchema). */
|
|
22
17
|
export interface LiteralShape {
|
package/src/store.ts
CHANGED
|
@@ -165,7 +165,7 @@ function computeVarPatches(
|
|
|
165
165
|
}
|
|
166
166
|
// Probe an unchanged variable with a copy of its own: it shares with a
|
|
167
167
|
// recorded one if the copy meets an object already copied
|
|
168
|
-
for (let found = seen.size > 0; found;
|
|
168
|
+
for (let found = seen.size > 0; found;) {
|
|
169
169
|
found = false;
|
|
170
170
|
for (const key of unchanged) {
|
|
171
171
|
const probe = new Map<object, object>();
|
package/src/story-variables.ts
CHANGED
|
@@ -46,12 +46,7 @@ function tokensOf(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export type VarType =
|
|
49
|
-
| '
|
|
50
|
-
| 'string'
|
|
51
|
-
| 'boolean'
|
|
52
|
-
| 'array'
|
|
53
|
-
| 'object'
|
|
54
|
-
| 'null';
|
|
49
|
+
'number' | 'string' | 'boolean' | 'array' | 'object' | 'null';
|
|
55
50
|
|
|
56
51
|
export interface FieldSchema {
|
|
57
52
|
type: VarType;
|
package/types/index.d.ts
CHANGED
|
@@ -287,11 +287,7 @@ export type ParameterType =
|
|
|
287
287
|
* @see {@link ../../src/registry.ts} for the implementation.
|
|
288
288
|
*/
|
|
289
289
|
export type StringHolds =
|
|
290
|
-
| '
|
|
291
|
-
| 'text'
|
|
292
|
-
| 'passage'
|
|
293
|
-
| 'expression'
|
|
294
|
-
| 'statements';
|
|
290
|
+
'markup' | 'text' | 'passage' | 'expression' | 'statements';
|
|
295
291
|
|
|
296
292
|
/**
|
|
297
293
|
* Parameter metadata for a macro definition.
|
|
@@ -401,11 +397,7 @@ export interface HtmlNode {
|
|
|
401
397
|
* @see {@link ../../src/markup/ast.ts} for the implementation.
|
|
402
398
|
*/
|
|
403
399
|
export type ASTNode =
|
|
404
|
-
|
|
|
405
|
-
| VariableNode
|
|
406
|
-
| ExpressionNode
|
|
407
|
-
| MacroNode
|
|
408
|
-
| HtmlNode;
|
|
400
|
+
TextNode | VariableNode | ExpressionNode | MacroNode | HtmlNode;
|
|
409
401
|
|
|
410
402
|
/**
|
|
411
403
|
* Props passed to a macro's render function.
|
package/types/tooling.d.ts
CHANGED
|
@@ -44,11 +44,7 @@ export type ParameterType =
|
|
|
44
44
|
* any other `text`.
|
|
45
45
|
*/
|
|
46
46
|
export type StringHolds =
|
|
47
|
-
| '
|
|
48
|
-
| 'text'
|
|
49
|
-
| 'passage'
|
|
50
|
-
| 'expression'
|
|
51
|
-
| 'statements';
|
|
47
|
+
'markup' | 'text' | 'passage' | 'expression' | 'statements';
|
|
52
48
|
|
|
53
49
|
export interface ParameterDef {
|
|
54
50
|
name: string;
|
|
@@ -101,12 +97,7 @@ export declare function getMacroRegistry(): MacroMetadata[];
|
|
|
101
97
|
|
|
102
98
|
/** Variable type inferred from a StoryVariables/StoryTransients default value. */
|
|
103
99
|
export type VarType =
|
|
104
|
-
| '
|
|
105
|
-
| 'string'
|
|
106
|
-
| 'boolean'
|
|
107
|
-
| 'array'
|
|
108
|
-
| 'object'
|
|
109
|
-
| 'null';
|
|
100
|
+
'number' | 'string' | 'boolean' | 'array' | 'object' | 'null';
|
|
110
101
|
|
|
111
102
|
/** Inferred shape of a declared variable (or one of its object fields). */
|
|
112
103
|
export interface FieldSchema {
|
|
@@ -580,8 +571,7 @@ export declare function transform(expr: string, goal?: JsGoal): string;
|
|
|
580
571
|
|
|
581
572
|
/** What a `passage` argument is: a quoted name, or an expression. */
|
|
582
573
|
export type PassageTarget =
|
|
583
|
-
|
|
584
|
-
| { kind: 'expression'; expression: string };
|
|
574
|
+
{ kind: 'name'; name: string } | { kind: 'expression'; expression: string };
|
|
585
575
|
|
|
586
576
|
/**
|
|
587
577
|
* Read a `passage` argument (`{goto "Hall"}`, `{include $room}`) as written:
|
|
@@ -922,10 +912,7 @@ export declare function passagePieces(
|
|
|
922
912
|
|
|
923
913
|
/** What is wrong with the pairing of tags (a subset of {@link MarkupErrorCode}). */
|
|
924
914
|
export type PairingErrorCode =
|
|
925
|
-
|
|
926
|
-
| 'mismatched-closer'
|
|
927
|
-
| 'stray-closer'
|
|
928
|
-
| 'misplaced-branch';
|
|
915
|
+
'unclosed-block' | 'mismatched-closer' | 'stray-closer' | 'misplaced-branch';
|
|
929
916
|
|
|
930
917
|
/** A problem in the pairing of the tokens. */
|
|
931
918
|
export interface PairingError {
|