@rohal12/spindle 0.62.8 → 0.62.9
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 +63 -45
- package/dist/pkg/macro-registry.js +3 -1
- package/dist/pkg/macro-registry.json +3 -1
- package/dist/pkg/story-variables.js +76 -35
- package/package.json +1 -1
- package/src/components/macros/Computed.tsx +5 -3
- package/src/components/macros/Cycle.tsx +1 -0
- package/src/format/format-passage.ts +37 -1
- package/src/js-lexer.ts +26 -0
- package/src/markup/pair.ts +20 -1
- package/src/markup/render.tsx +4 -4
- package/src/parser.ts +2 -2
- package/src/registry.ts +3 -2
- package/src/story-api.ts +1 -5
- package/src/story-variables.ts +25 -42
- package/types/tooling.d.ts +5 -1
package/src/parser.ts
CHANGED
|
@@ -136,12 +136,12 @@ const escapeTextReferences = (text: string) =>
|
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* Elements whose text the renderer shows as written, with no character
|
|
139
|
-
* references decoded:
|
|
139
|
+
* references decoded: those it treats as raw text (`style`, `script`, see
|
|
140
140
|
* HtmlNodeRenderer), for which the browser did not decode any either.
|
|
141
141
|
*/
|
|
142
142
|
function isLiteralTextElement(parent: ParentNode): boolean {
|
|
143
143
|
return (
|
|
144
|
-
(parent as Element).localName
|
|
144
|
+
['style', 'script'].includes((parent as Element).localName) &&
|
|
145
145
|
(parent as Element).namespaceURI === HTML_NAMESPACE
|
|
146
146
|
);
|
|
147
147
|
}
|
package/src/registry.ts
CHANGED
|
@@ -254,20 +254,21 @@ export function registerMacroMetadata(
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
/** The parents declaring a branching companion (
|
|
257
|
+
/** The parents declaring a branching companion (input options are values). */
|
|
258
258
|
export function branchParents(
|
|
259
259
|
name: string,
|
|
260
260
|
macros?: readonly Pick<MacroMetadata, 'name' | 'subMacros'>[],
|
|
261
261
|
): string[] {
|
|
262
262
|
if (!macros) {
|
|
263
263
|
return [...(companionParents.get(name) ?? [])].filter(
|
|
264
|
-
(parent) => parent !== 'listbox',
|
|
264
|
+
(parent) => parent !== 'listbox' && parent !== 'cycle',
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
return effectiveNamedDefinitions(macros)
|
|
268
268
|
.filter(
|
|
269
269
|
(macro) =>
|
|
270
270
|
macro.name.toLowerCase() !== 'listbox' &&
|
|
271
|
+
macro.name.toLowerCase() !== 'cycle' &&
|
|
271
272
|
macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase()),
|
|
272
273
|
)
|
|
273
274
|
.map((macro) => macro.name.toLowerCase());
|
package/src/story-api.ts
CHANGED
|
@@ -275,11 +275,7 @@ function setOne(draft: VariableNamespaces, name: string, value: unknown): void {
|
|
|
275
275
|
const { isTransient, key } = parseName(name);
|
|
276
276
|
const namespace = isTransient ? draft.transient : draft.variables;
|
|
277
277
|
|
|
278
|
-
|
|
279
|
-
setByPath(namespace, key.split('.'), value);
|
|
280
|
-
} else {
|
|
281
|
-
namespace[key] = value;
|
|
282
|
-
}
|
|
278
|
+
setByPath(namespace, key.split('.'), value);
|
|
283
279
|
}
|
|
284
280
|
|
|
285
281
|
/** A method calling the store action `name`, as the store holds it then. */
|
package/src/story-variables.ts
CHANGED
|
@@ -11,8 +11,10 @@ import { errorMessage } from './utils/error-message';
|
|
|
11
11
|
import {
|
|
12
12
|
CodeSyntaxError,
|
|
13
13
|
lexJs,
|
|
14
|
+
readMemberPath,
|
|
14
15
|
scanStringLiteral,
|
|
15
16
|
type JsGoal,
|
|
17
|
+
type VariableRef,
|
|
16
18
|
} from './js-lexer';
|
|
17
19
|
import {
|
|
18
20
|
argPieces,
|
|
@@ -88,9 +90,6 @@ function declarationRegex(sigil: string): RegExp {
|
|
|
88
90
|
const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
89
91
|
return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
|
|
90
92
|
}
|
|
91
|
-
/** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
|
|
92
|
-
const VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
|
|
93
|
-
|
|
94
93
|
const VALID_VAR_TYPES = new Set<string>(['number', 'string', 'boolean']);
|
|
95
94
|
|
|
96
95
|
/** Boxed sample values whose members a primitive of each type can access. */
|
|
@@ -524,9 +523,6 @@ type Emit = (ref: VariableReference) => void;
|
|
|
524
523
|
|
|
525
524
|
const NO_STORE_VAR_MACROS: ReadonlySet<string> = new Set();
|
|
526
525
|
|
|
527
|
-
/** A `.field` path written right after a reference, which may be empty. */
|
|
528
|
-
const FIELD_PATH_RE = /(?:\.\w+)*/y;
|
|
529
|
-
|
|
530
526
|
/**
|
|
531
527
|
* The reference to variable `name`, which JavaScript reads at `[start, end)`
|
|
532
528
|
* of `code` (the sigil and the name as written, which may be spelled with
|
|
@@ -534,39 +530,21 @@ const FIELD_PATH_RE = /(?:\.\w+)*/y;
|
|
|
534
530
|
*/
|
|
535
531
|
function referenceAt(
|
|
536
532
|
code: string,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
533
|
+
{
|
|
534
|
+
sigil,
|
|
535
|
+
name,
|
|
536
|
+
start,
|
|
537
|
+
end,
|
|
538
|
+
}: Pick<VariableRef, 'sigil' | 'name' | 'start' | 'end'>,
|
|
541
539
|
at: At,
|
|
542
540
|
): VariableReference {
|
|
543
|
-
|
|
544
|
-
const fields = FIELD_PATH_RE.exec(code)![0];
|
|
541
|
+
const fields = readMemberPath(code, end);
|
|
545
542
|
return {
|
|
546
543
|
sigil: sigil as '$' | '%',
|
|
547
544
|
name,
|
|
548
|
-
path: fields
|
|
545
|
+
path: fields.path,
|
|
549
546
|
start: at(start),
|
|
550
|
-
end: at(
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/** A reference written at `index` of `term`, a `variable` parameter as written. */
|
|
555
|
-
function termReferenceAt(
|
|
556
|
-
term: string,
|
|
557
|
-
index: number,
|
|
558
|
-
at: At,
|
|
559
|
-
): VariableReference | undefined {
|
|
560
|
-
VAR_PATH_RE.lastIndex = index;
|
|
561
|
-
const match = VAR_PATH_RE.exec(term);
|
|
562
|
-
if (!match) return undefined;
|
|
563
|
-
const [name, ...path] = match[2]!.split('.');
|
|
564
|
-
return {
|
|
565
|
-
sigil: match[1] as '$' | '%',
|
|
566
|
-
name: name!,
|
|
567
|
-
path,
|
|
568
|
-
start: at(index),
|
|
569
|
-
end: at(index + match[0].length),
|
|
547
|
+
end: at(fields.end),
|
|
570
548
|
};
|
|
571
549
|
}
|
|
572
550
|
|
|
@@ -618,7 +596,7 @@ function scanCode(
|
|
|
618
596
|
}
|
|
619
597
|
for (const ref of parsed.refs) {
|
|
620
598
|
if (ref.sigil !== '$' && ref.sigil !== '%') continue;
|
|
621
|
-
emit(referenceAt(code, ref
|
|
599
|
+
emit(referenceAt(code, ref, at));
|
|
622
600
|
}
|
|
623
601
|
}
|
|
624
602
|
|
|
@@ -634,7 +612,7 @@ function scanCodeLeniently(
|
|
|
634
612
|
{
|
|
635
613
|
variable(sigil, name, index, _nesting, end) {
|
|
636
614
|
if (sigil !== '$' && sigil !== '%') return;
|
|
637
|
-
emit(referenceAt(code, sigil, name, index, end, at));
|
|
615
|
+
emit(referenceAt(code, { sigil, name, start: index, end }, at));
|
|
638
616
|
},
|
|
639
617
|
// Strings, regex literals and comments hold no references
|
|
640
618
|
literal() {},
|
|
@@ -682,8 +660,8 @@ function scanArgs(
|
|
|
682
660
|
const params = parametersOf(token.name);
|
|
683
661
|
let byParameters = false;
|
|
684
662
|
if (params) {
|
|
685
|
-
if (
|
|
686
|
-
scanVariableParameters(token, params, at, emit);
|
|
663
|
+
if (!options.storeVarMacros.has(token.name.toLowerCase())) {
|
|
664
|
+
scanVariableParameters(token, params, at, emit, options.all);
|
|
687
665
|
}
|
|
688
666
|
const pieces = [
|
|
689
667
|
...argPieces(token.rawArgs, token.argsStart, params, token.name, ''),
|
|
@@ -709,14 +687,15 @@ function scanArgs(
|
|
|
709
687
|
|
|
710
688
|
/**
|
|
711
689
|
* Report the variables the `variable` parameters of a macro name
|
|
712
|
-
* (`{unset $x}`, `{computed $x = …}`)
|
|
713
|
-
*
|
|
690
|
+
* (`{unset $x}`, `{computed $x = …}`). Computed members read variables even
|
|
691
|
+
* when the receiver itself is only included in the complete editor list.
|
|
714
692
|
*/
|
|
715
693
|
function scanVariableParameters(
|
|
716
694
|
token: Extract<Token, { type: 'macro' }>,
|
|
717
695
|
params: readonly ParameterDef[],
|
|
718
696
|
at: At,
|
|
719
697
|
emit: Emit,
|
|
698
|
+
all: boolean | undefined,
|
|
720
699
|
): void {
|
|
721
700
|
const spans: ArgSpans = new Map();
|
|
722
701
|
try {
|
|
@@ -728,10 +707,14 @@ function scanVariableParameters(
|
|
|
728
707
|
for (const param of params) {
|
|
729
708
|
const span = spans.get(param);
|
|
730
709
|
if (param.type !== 'variable' || !span) continue;
|
|
731
|
-
const
|
|
732
|
-
|
|
710
|
+
const start = token.argsStart + span[0];
|
|
711
|
+
scanCode(
|
|
712
|
+
token.rawArgs.slice(span[0], span[1]),
|
|
713
|
+
(i) => at(start + i),
|
|
714
|
+
(ref) => {
|
|
715
|
+
if (all || ref.start !== at(start)) emit(ref);
|
|
716
|
+
},
|
|
733
717
|
);
|
|
734
|
-
if (ref) emit(ref);
|
|
735
718
|
}
|
|
736
719
|
}
|
|
737
720
|
|
package/types/tooling.d.ts
CHANGED
|
@@ -955,7 +955,11 @@ export declare function passagePieces(
|
|
|
955
955
|
|
|
956
956
|
/** What is wrong with the pairing of tags (a subset of {@link MarkupErrorCode}). */
|
|
957
957
|
export type PairingErrorCode =
|
|
958
|
-
'unclosed-block'
|
|
958
|
+
| 'unclosed-block'
|
|
959
|
+
| 'mismatched-closer'
|
|
960
|
+
| 'stray-closer'
|
|
961
|
+
| 'misplaced-branch'
|
|
962
|
+
| 'nesting-limit';
|
|
959
963
|
|
|
960
964
|
/** A problem in the pairing of the tokens. */
|
|
961
965
|
export interface PairingError {
|