@rohal12/spindle 0.59.28 → 0.59.30

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.
Files changed (55) hide show
  1. package/README.md +1 -0
  2. package/dist/pkg/format.js +1 -1
  3. package/dist/pkg/headless.js +718 -300
  4. package/dist/pkg/macro-registry.js +19 -0
  5. package/dist/pkg/macro-registry.json +19 -0
  6. package/dist/pkg/story-variables.js +731 -234
  7. package/package.json +1 -1
  8. package/src/action-registry.ts +59 -5
  9. package/src/automation/load-yaml.ts +111 -20
  10. package/src/automation/runner.ts +15 -13
  11. package/src/automation/types.ts +7 -5
  12. package/src/class-registry.ts +8 -5
  13. package/src/code-check.ts +187 -24
  14. package/src/components/macros/Checkbox.tsx +5 -2
  15. package/src/components/macros/Cycle.tsx +1 -0
  16. package/src/components/macros/For.tsx +1 -7
  17. package/src/components/macros/Listbox.tsx +1 -0
  18. package/src/components/macros/MenubarButtons.tsx +6 -1
  19. package/src/components/macros/Nobr.tsx +1 -0
  20. package/src/components/macros/PassageDisplay.tsx +42 -0
  21. package/src/components/macros/Radiobutton.tsx +1 -0
  22. package/src/components/macros/SaveManager.tsx +19 -4
  23. package/src/components/macros/SettingsControls.tsx +19 -4
  24. package/src/components/macros/Span.tsx +1 -0
  25. package/src/components/macros/StoryTitle.tsx +1 -0
  26. package/src/components/macros/VarDisplay.tsx +2 -3
  27. package/src/components/macros/Widget.tsx +2 -0
  28. package/src/components/macros/WidgetInvocation.tsx +5 -6
  29. package/src/components/macros/arg-utils.ts +58 -21
  30. package/src/components/macros/input-macro.ts +1 -0
  31. package/src/components/macros/locals-scope.tsx +19 -8
  32. package/src/components/macros/macro-args.ts +11 -3
  33. package/src/expression.ts +34 -18
  34. package/src/hooks/use-merged-locals.ts +17 -2
  35. package/src/hooks/use-modal-focus.ts +190 -129
  36. package/src/index.tsx +23 -13
  37. package/src/js-bindings.ts +332 -0
  38. package/src/js-lexer.ts +12 -3
  39. package/src/macro-discovery.ts +25 -22
  40. package/src/static-literal.ts +87 -16
  41. package/src/store.ts +31 -2
  42. package/src/story-api.ts +15 -5
  43. package/src/story-variables.ts +91 -28
  44. package/src/structural.ts +19 -15
  45. package/src/tooling.ts +36 -10
  46. package/src/transform.ts +22 -7
  47. package/src/utils/namespace.ts +4 -0
  48. package/src/utils/object-path.ts +2 -2
  49. package/src/utils/stable-key.ts +17 -6
  50. package/src/utils/value-kinds.ts +38 -1
  51. package/src/widgets/register-widget-def.ts +7 -8
  52. package/src/widgets/widget-def.ts +41 -4
  53. package/src/widgets/widget-registry.ts +14 -0
  54. package/types/index.d.ts +12 -5
  55. package/types/tooling.d.ts +12 -2
package/src/code-check.ts CHANGED
@@ -34,7 +34,12 @@ import {
34
34
  MarkupError,
35
35
  mapOffsets,
36
36
  } from './markup/parse';
37
- import { CodeSyntaxError, parseCode, type JsGoal } from './js-lexer';
37
+ import {
38
+ CodeSyntaxError,
39
+ parseCode,
40
+ stringLiteralValue,
41
+ type JsGoal,
42
+ } from './js-lexer';
38
43
  import type { ParsedCode } from './js-lexer';
39
44
  import type { ParameterDef, StringHolds } from './registry';
40
45
  import {
@@ -45,7 +50,9 @@ import {
45
50
  type PassageTarget,
46
51
  } from './components/macros/macro-args';
47
52
  import { subMacroParameters } from './components/macros/option-utils';
53
+ import { splitArgSpans } from './components/macros/arg-utils';
48
54
  import { NameMap } from './utils/macro-names';
55
+ import { hasOwn } from './utils/namespace';
49
56
 
50
57
  /** While a pass runs: the code it parsed so far, by goal and source. */
51
58
  let parses: Map<string, ParsedCode | CodeSyntaxError> | null = null;
@@ -190,16 +197,52 @@ const PASSAGE_BODIES = new Set(['dialog']);
190
197
  /** What a passage runs and names, and where (see passagePieces). */
191
198
  export type Piece = CodePiece | TextPiece | PassagePiece | ArgumentErrorPiece;
192
199
 
200
+ /**
201
+ * A parameter of a widget, by position: what its argument holds when it
202
+ * declares it (`@target:passage`).
203
+ */
204
+ export interface WidgetParameter {
205
+ name: string;
206
+ holds?: StringHolds;
207
+ }
208
+
209
+ /**
210
+ * The parameters of a widget given its `@` parameters and what they declare
211
+ * to hold, or none when it declares nothing (a call is then not read by
212
+ * parameter).
213
+ */
214
+ export function widgetParameters(
215
+ params: readonly string[],
216
+ holds: Readonly<Record<string, StringHolds>> = {},
217
+ ): WidgetParameter[] | undefined {
218
+ if (!params.some((param) => hasOwn(holds, param))) return undefined;
219
+ return params.map((name) => ({
220
+ name,
221
+ ...(hasOwn(holds, name) ? { holds: holds[name]! } : {}),
222
+ }));
223
+ }
224
+
193
225
  /** The declared parameters of a macro, if it has any. */
194
- export type ParametersOf = (
195
- macro: string,
196
- ) => readonly ParameterDef[] | undefined;
226
+ export interface ParametersOf {
227
+ (macro: string): readonly ParameterDef[] | undefined;
228
+ /**
229
+ * The parameters of the widget `name` if it declares what some argument
230
+ * holds. Its arguments are read as a widget call reads them (separated by
231
+ * commas or spaces, see splitArgs), not by parseMacroArgs.
232
+ */
233
+ widget?(name: string): readonly WidgetParameter[] | undefined;
234
+ }
197
235
 
198
236
  /** What the argument check needs to know of a macro (see MacroMetadata). */
199
237
  export interface MacroParameters {
200
238
  name: string;
201
239
  parameters?: readonly ParameterDef[];
202
240
  interpolate?: boolean;
241
+ /** For a widget: its `@` parameters and what some declare to hold. */
242
+ widget?: {
243
+ params: readonly string[];
244
+ holds?: Readonly<Record<string, StringHolds>>;
245
+ };
203
246
  }
204
247
 
205
248
  /**
@@ -225,16 +268,20 @@ function withHolds(
225
268
  * collection and tooling read arguments by. Each `string` and `text`
226
269
  * parameter says what it holds: what it declares, else `markup` for a macro
227
270
  * with `interpolate` (which can resolve markup) and `text` for any other.
271
+ * A widget among `macros` says what its parameters hold (see ParametersOf).
228
272
  */
229
273
  export function parameterLookup(
230
274
  macros: Iterable<MacroParameters>,
231
275
  ): ParametersOf {
232
276
  const parameters = new NameMap<readonly ParameterDef[]>();
233
- for (const { name, parameters: params, interpolate } of macros) {
277
+ const widgets = new NameMap<readonly WidgetParameter[]>();
278
+ for (const { name, parameters: params, interpolate, widget } of macros) {
234
279
  if (params)
235
280
  parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
281
+ const declared = widget && widgetParameters(widget.params, widget.holds);
282
+ if (declared) widgets.set(name, declared);
236
283
  }
237
- return (name) => {
284
+ const lookup: ParametersOf = (name) => {
238
285
  let params = parameters.get(name);
239
286
  if (!params) {
240
287
  const sub = subMacroParameters(name);
@@ -242,6 +289,8 @@ export function parameterLookup(
242
289
  }
243
290
  return params;
244
291
  };
292
+ if (widgets.size > 0) lookup.widget = (name) => widgets.get(name);
293
+ return lookup;
245
294
  }
246
295
 
247
296
  /** What a `string` or `text` argument holds when its parameter doesn't say. */
@@ -390,6 +439,8 @@ export function* codeAndText(
390
439
  }
391
440
  const params = parametersOf(name);
392
441
  if (params) yield* argPieces(args, argsAt, params, token.name, label);
442
+ const widget = parametersOf.widget?.(name);
443
+ if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
393
444
  }
394
445
  }
395
446
  }
@@ -495,30 +546,66 @@ function nestedPiece(
495
546
  : { ...piece, ...nested };
496
547
  }
497
548
 
549
+ /** How the string of an argument is unescaped, which its escapes depend on. */
550
+ type Escapes =
551
+ /** A macro's text: a backslash before a quote or a backslash is dropped. */
552
+ | 'quotes'
553
+ /** A widget's argument: a JavaScript string literal, with all its escapes. */
554
+ | 'javascript';
555
+
556
+ /** An escape sequence of a JavaScript string literal (with its backslash). */
557
+ const JS_ESCAPE_RE =
558
+ /\\(?:u\{[0-9a-fA-F]+\}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|[0-3][0-7]{0,2}|[4-7][0-7]?|\r\n|[^])/y;
559
+
560
+ /**
561
+ * The escape written at `raw[i]` (a backslash): how long it is as written and
562
+ * what it stands for, or none when it is not one under these `escapes`.
563
+ */
564
+ function escapeAt(
565
+ raw: string,
566
+ i: number,
567
+ escapes: Escapes,
568
+ ): { length: number; text: string } | undefined {
569
+ if (escapes === 'quotes') {
570
+ const next = raw.charAt(i + 1);
571
+ return /["'\\]/.test(next) ? { length: 2, text: next } : undefined;
572
+ }
573
+ JS_ESCAPE_RE.lastIndex = i;
574
+ const written = JS_ESCAPE_RE.exec(raw)?.[0];
575
+ const text = written && stringLiteralValue(`"${written}"`);
576
+ return typeof text === 'string'
577
+ ? { length: written!.length, text }
578
+ : undefined;
579
+ }
580
+
498
581
  /**
499
582
  * Where each character of `value`, the unescaped text of a quoted string
500
- * written as `raw` from `at` on (a backslash before a quote or a backslash
501
- * is dropped), is
502
- * in the source, and where the text ends. None when the text is where its
503
- * length says, or is not that string.
583
+ * written as `raw` from `at` on (its escapes are those of `escapes`), is in
584
+ * the source, and where the text ends. A character that an escape stands for
585
+ * is where the escape begins. None when the text is where its length says, or
586
+ * is not that string.
504
587
  */
505
588
  function escapeOffsets(
506
589
  raw: string,
507
590
  at: number,
508
591
  value: string,
592
+ escapes: Escapes,
509
593
  ): number[] | undefined {
510
594
  const offsets: number[] = [];
511
595
  let escaped = false;
512
596
  let i = 0;
513
597
  while (offsets.length < value.length) {
514
598
  if (i >= raw.length) return undefined;
515
- offsets.push(at + i);
516
- if (raw[i] === '\\' && /["'\\]/.test(raw.charAt(i + 1))) {
517
- escaped = true;
518
- i += 2;
519
- } else {
520
- i++;
599
+ const escape = raw[i] === '\\' ? escapeAt(raw, i, escapes) : undefined;
600
+ if (!escape) {
601
+ offsets.push(at + i++);
602
+ continue;
521
603
  }
604
+ // What the escape stands for is what the text has there
605
+ if (!value.startsWith(escape.text, offsets.length)) return undefined;
606
+ for (let k = 0; k < escape.text.length; k++) offsets.push(at + i);
607
+ escaped = true;
608
+ i += escape.length;
522
609
  }
523
610
  offsets.push(at + i);
524
611
  return escaped ? offsets : undefined;
@@ -532,7 +619,6 @@ export function* argPieces(
532
619
  macro: string,
533
620
  label: string,
534
621
  ): Generator<Piece> {
535
- const name = macro.toLowerCase();
536
622
  let values: Record<string, unknown>;
537
623
  const spans: ArgSpans = new Map();
538
624
  try {
@@ -545,10 +631,76 @@ export function* argPieces(
545
631
  offset,
546
632
  length: args.length,
547
633
  label,
548
- macro: name,
634
+ macro: macro.toLowerCase(),
549
635
  };
550
636
  return;
551
637
  }
638
+ yield* valuePieces(
639
+ args,
640
+ offset,
641
+ params,
642
+ values,
643
+ spans,
644
+ macro,
645
+ label,
646
+ 'quotes',
647
+ );
648
+ }
649
+
650
+ /**
651
+ * The code and text in the arguments `args` (at `offset`) of the widget
652
+ * `macro`, the ones whose parameter declares what it holds. Such an argument
653
+ * is checked when it is one quoted string, as a `string` parameter with that
654
+ * `holds` of a macro is; any other expression is its value at run time.
655
+ */
656
+ export function* widgetPieces(
657
+ args: string,
658
+ offset: number,
659
+ params: readonly WidgetParameter[],
660
+ macro: string,
661
+ label: string,
662
+ ): Generator<Piece> {
663
+ const written = splitArgSpans(args);
664
+ const declared: ParameterDef[] = [];
665
+ const values: Record<string, unknown> = {};
666
+ const spans: ArgSpans = new Map();
667
+ params.forEach(({ name, holds }, i) => {
668
+ const span = written[i];
669
+ const value = span && stringLiteralValue(args.slice(...span));
670
+ if (!holds || value == null) return;
671
+ const param: ParameterDef = { name, type: 'string', holds };
672
+ declared.push(param);
673
+ values[name] = value;
674
+ spans.set(param, span!);
675
+ });
676
+ yield* valuePieces(
677
+ args,
678
+ offset,
679
+ declared,
680
+ values,
681
+ spans,
682
+ macro,
683
+ label,
684
+ 'javascript',
685
+ );
686
+ }
687
+
688
+ /**
689
+ * The pieces of the `params` of `macro` with the `values` read from `args`
690
+ * (at `offset`), whose `spans` tell where each was written and whose strings
691
+ * are unescaped as `escapes` says.
692
+ */
693
+ function* valuePieces(
694
+ args: string,
695
+ offset: number,
696
+ params: readonly ParameterDef[],
697
+ values: Record<string, unknown>,
698
+ spans: ArgSpans,
699
+ macro: string,
700
+ label: string,
701
+ escapes: Escapes,
702
+ ): Generator<Piece> {
703
+ const name = macro.toLowerCase();
552
704
  /** The pieces of the parameters `list`, with their values in `from`. */
553
705
  function* visit(
554
706
  list: readonly ParameterDef[],
@@ -604,7 +756,12 @@ export function* argPieces(
604
756
  const at =
605
757
  offset + start + (value !== written && /^["']/.test(written) ? 1 : 0);
606
758
  const holds = stringHolds(param);
607
- const sourceOffsets = escapeOffsets(args.slice(at - offset), at, value);
759
+ const sourceOffsets = escapeOffsets(
760
+ args.slice(at - offset),
761
+ at,
762
+ value,
763
+ escapes,
764
+ );
608
765
  if (holds === 'expression' || holds === 'statements') {
609
766
  const piece: CodePiece = {
610
767
  kind: 'code',
@@ -678,7 +835,10 @@ export function attributeValues(
678
835
 
679
836
  /**
680
837
  * The `{$…}` expressions in the value of a code attribute (`onclick`, see
681
- * isCodeAttribute), with where each is in the value.
838
+ * isCodeAttribute), with where each is in the value. The parts of the value
839
+ * are written out as they are (splitSigilTemplate decodes nothing), so each
840
+ * starts where the one before it ends: an expression is not found by its
841
+ * text, which a string of the code may repeat.
682
842
  */
683
843
  export function sigilExpressions(
684
844
  value: string,
@@ -686,10 +846,13 @@ export function sigilExpressions(
686
846
  const found = [];
687
847
  let from = 0;
688
848
  for (const part of splitSigilTemplate(value)) {
689
- if (!('expr' in part)) continue;
690
- const at = locate(value, part.expr, from);
691
- from = at + part.expr.length;
692
- found.push({ expr: part.expr, at });
849
+ if ('expr' in part) {
850
+ // Inside its braces
851
+ found.push({ expr: part.expr, at: from + 1 });
852
+ from += part.expr.length + 2;
853
+ } else {
854
+ from += ('text' in part ? part.text : part.verbatim).length;
855
+ }
693
856
  }
694
857
  return found;
695
858
  }
@@ -3,6 +3,7 @@ import { VARIABLE_PARAMETER, useVariableAction } from './input-macro';
3
3
 
4
4
  defineMacro({
5
5
  name: 'checkbox',
6
+ interpolate: true,
6
7
  storeVar: true,
7
8
  parameters: [
8
9
  VARIABLE_PARAMETER,
@@ -15,7 +16,7 @@ defineMacro({
15
16
  type: 'checkbox',
16
17
  label: label || ctx.varName || '',
17
18
  value: !!ctx.value,
18
- perform: (v) => ctx.setValue!(v !== undefined ? !!v : !ctx.value),
19
+ perform: (v) => ctx.setValue!(v !== undefined ? !!v : !ctx.getValue!()),
19
20
  });
20
21
 
21
22
  return (
@@ -26,7 +27,9 @@ defineMacro({
26
27
  <input
27
28
  type="checkbox"
28
29
  checked={!!ctx.value}
29
- onChange={() => ctx.setValue!(!ctx.value)}
30
+ onChange={(e) =>
31
+ ctx.setValue!((e.target as HTMLInputElement).checked)
32
+ }
30
33
  />
31
34
  {label ? ` ${label}` : null}
32
35
  </label>
@@ -4,6 +4,7 @@ import { VARIABLE_PARAMETER, useVariableAction } from './input-macro';
4
4
  defineMacro({
5
5
  name: 'cycle',
6
6
  block: true,
7
+ interpolate: true,
7
8
  storeVar: true,
8
9
  parameters: [VARIABLE_PARAMETER],
9
10
  render({ children = [] }, ctx) {
@@ -1,5 +1,4 @@
1
- import { useContext, useMemo } from 'preact/hooks';
2
- import { LocalsValuesContext } from '../../markup/render';
1
+ import { useMemo } from 'preact/hooks';
3
2
  import { defineMacro } from '../../define-macro';
4
3
  import { MacroError } from './MacroError';
5
4
  import { stableKey } from '../../utils/stable-key';
@@ -51,14 +50,12 @@ function loopArgs(
51
50
  }
52
51
 
53
52
  function ForIteration({
54
- parentValues,
55
53
  itemVar,
56
54
  itemValue,
57
55
  indexVar,
58
56
  indexValue,
59
57
  children,
60
58
  }: {
61
- parentValues: Record<string, unknown>;
62
59
  itemVar: string;
63
60
  itemValue: unknown;
64
61
  indexVar: string | null;
@@ -76,7 +73,6 @@ function ForIteration({
76
73
  return (
77
74
  <LocalsScope
78
75
  body={children}
79
- parentValues={parentValues}
80
76
  ownKeys={ownKeys}
81
77
  />
82
78
  );
@@ -101,7 +97,6 @@ defineMacro({
101
97
  { name: 'list', type: 'expression', required: true },
102
98
  ],
103
99
  render({ rawArgs, children = [] }, ctx) {
104
- const parentValues = useContext(LocalsValuesContext);
105
100
  const keys = ctx.hooks.useRef<IterationKeys>({
106
101
  contents: [],
107
102
  generations: [],
@@ -154,7 +149,6 @@ defineMacro({
154
149
  const content = list.map((item, i) => (
155
150
  <ForIteration
156
151
  key={`${i}-${generations[i]}`}
157
- parentValues={parentValues}
158
152
  itemVar={itemVar}
159
153
  itemValue={item}
160
154
  indexVar={indexVar}
@@ -4,6 +4,7 @@ import { display } from './display';
4
4
 
5
5
  defineMacro({
6
6
  name: 'listbox',
7
+ interpolate: true,
7
8
  subMacros: ['option'],
8
9
  storeVar: true,
9
10
  parameters: [VARIABLE_PARAMETER],
@@ -15,7 +15,11 @@ interface MenubarActionConfig {
15
15
  title?: string;
16
16
  confirm?: string;
17
17
  hidden?: () => boolean;
18
- setup?: () => { perform: () => void; disabled?: boolean; title?: string };
18
+ setup?: () => {
19
+ perform: () => void | Promise<void>;
20
+ disabled?: boolean;
21
+ title?: string;
22
+ };
19
23
  dialog?: {
20
24
  passageName: string;
21
25
  fallbackMarkup?: string;
@@ -31,6 +35,7 @@ function hotkeyTitle(label: string, key: string | null): string {
31
35
  export function defineMenubarAction(config: MenubarActionConfig) {
32
36
  defineMacro({
33
37
  name: config.name,
38
+ interpolate: true,
34
39
  render(_, ctx) {
35
40
  if (config.hidden?.()) return null;
36
41
 
@@ -4,6 +4,7 @@ import { NobrContext } from '../../markup/render';
4
4
  defineMacro({
5
5
  name: 'nobr',
6
6
  block: true,
7
+ interpolate: true,
7
8
  render({ children = [] }, ctx) {
8
9
  return ctx.wrap(
9
10
  ctx.h(
@@ -15,11 +15,52 @@ import { Passage, renderPassageContent } from '../Passage';
15
15
  import { defineMacro } from '../../define-macro';
16
16
  import { resolveTransition, type ResolvedTransition } from '../../transition';
17
17
 
18
+ /**
19
+ * Copy the live state cloneNode drops from `source` into its clone: the
20
+ * pixels of each canvas and the values of form controls (cloneNode keeps
21
+ * attributes only, and a canvas's bitmap is not one). Source and clone have
22
+ * the same structure, so elements pair up by position. Best effort: a canvas
23
+ * that can not be drawn from stays as cloned.
24
+ */
25
+ function copyLiveState(source: Element, clone: Element): void {
26
+ const pairs = <T extends Element>(
27
+ selector: string,
28
+ each: (a: T, b: T) => void,
29
+ ) => {
30
+ const from = source.querySelectorAll<T>(selector);
31
+ const to = clone.querySelectorAll<T>(selector);
32
+ from.forEach((el, i) => to[i] && each(el, to[i]!));
33
+ };
34
+
35
+ pairs<HTMLCanvasElement>('canvas', (from, to) => {
36
+ if (!from.width || !from.height) return;
37
+ try {
38
+ if (to.width !== from.width) to.width = from.width;
39
+ if (to.height !== from.height) to.height = from.height;
40
+ to.getContext('2d')?.drawImage(from, 0, 0);
41
+ } catch {
42
+ // tainted, lost or foreign-context canvas: the snapshot shows it blank
43
+ }
44
+ });
45
+
46
+ pairs<HTMLInputElement>('input, textarea, select', (from, to) => {
47
+ if (from instanceof HTMLInputElement && to instanceof HTMLInputElement) {
48
+ to.checked = from.checked;
49
+ }
50
+ // A file input's value can not be set
51
+ if (!(from instanceof HTMLInputElement && from.type === 'file')) {
52
+ to.value = from.value;
53
+ }
54
+ });
55
+ }
56
+
18
57
  /**
19
58
  * Create a snapshot clone of a .passage element for outgoing transitions.
20
59
  * - Strips `id` attributes from the clone tree
21
60
  * - Disables interaction (pointer-events, user-select, inert, aria-hidden)
22
61
  * - Pauses/mutes any <audio>/<video>
62
+ * - Copies what cloneNode leaves behind: canvas pixels and the values of
63
+ * form controls (#512)
23
64
  * - Adds `.passage-snapshot` class and `data-transition` attribute
24
65
  */
25
66
  function createSnapshot(
@@ -27,6 +68,7 @@ function createSnapshot(
27
68
  transitionType: string,
28
69
  ): HTMLElement {
29
70
  const clone = passageEl.cloneNode(true) as HTMLElement;
71
+ copyLiveState(passageEl, clone);
30
72
 
31
73
  // Strip id attributes to avoid duplicates
32
74
  clone.removeAttribute('id');
@@ -4,6 +4,7 @@ import { VARIABLE_PARAMETER, useVariableAction } from './input-macro';
4
4
 
5
5
  defineMacro({
6
6
  name: 'radiobutton',
7
+ interpolate: true,
7
8
  storeVar: true,
8
9
  parameters: [
9
10
  VARIABLE_PARAMETER,
@@ -54,7 +54,13 @@ function formatDate(iso: string): string {
54
54
  });
55
55
  }
56
56
 
57
- export function SaveManagerContent() {
57
+ export function SaveManagerContent({
58
+ className,
59
+ id,
60
+ }: {
61
+ className?: string;
62
+ id?: string;
63
+ }) {
58
64
  const [mode, setMode] = useState<'save' | 'load'>('load');
59
65
  const [groups, setGroups] = useState<PlaythroughGroup[]>([]);
60
66
  const [loading, setLoading] = useState(true);
@@ -307,7 +313,10 @@ export function SaveManagerContent() {
307
313
  const totalSaves = groups.reduce((n, g) => n + g.saves.length, 0);
308
314
 
309
315
  return (
310
- <div class="save-manager">
316
+ <div
317
+ id={id}
318
+ class={className ? `save-manager ${className}` : 'save-manager'}
319
+ >
311
320
  <div class="saves-header">
312
321
  <div class="saves-header-left">
313
322
  <div class="saves-mode-toggle">
@@ -512,7 +521,13 @@ export function SaveManagerContent() {
512
521
 
513
522
  defineMacro({
514
523
  name: 'save-manager',
515
- render() {
516
- return <SaveManagerContent />;
524
+ interpolate: true,
525
+ render(_props, ctx) {
526
+ return (
527
+ <SaveManagerContent
528
+ className={ctx.className}
529
+ id={ctx.id}
530
+ />
531
+ );
517
532
  },
518
533
  });
@@ -68,11 +68,20 @@ function SettingControl({ name, def }: { name: string; def: SettingDef }) {
68
68
  }
69
69
  }
70
70
 
71
- function SettingsControlsContent() {
71
+ function SettingsControlsContent({
72
+ className,
73
+ id,
74
+ }: {
75
+ className?: string;
76
+ id?: string;
77
+ }) {
72
78
  const defs = settings.getDefinitions();
73
79
 
74
80
  return (
75
- <div class="settings-controls">
81
+ <div
82
+ id={id}
83
+ class={className ? `settings-controls ${className}` : 'settings-controls'}
84
+ >
76
85
  {Array.from(defs.entries()).map(([name, def]) => (
77
86
  <SettingControl
78
87
  key={name}
@@ -86,7 +95,13 @@ function SettingsControlsContent() {
86
95
 
87
96
  defineMacro({
88
97
  name: 'settings-controls',
89
- render() {
90
- return <SettingsControlsContent />;
98
+ interpolate: true,
99
+ render(_props, ctx) {
100
+ return (
101
+ <SettingsControlsContent
102
+ className={ctx.className}
103
+ id={ctx.id}
104
+ />
105
+ );
91
106
  },
92
107
  });
@@ -3,6 +3,7 @@ import { defineMacro } from '../../define-macro';
3
3
  defineMacro({
4
4
  name: 'span',
5
5
  block: true,
6
+ interpolate: true,
6
7
  render({ children = [] }, ctx) {
7
8
  return ctx.wrap(ctx.renderNodes(children));
8
9
  },
@@ -3,6 +3,7 @@ import { defineMacro } from '../../define-macro';
3
3
 
4
4
  defineMacro({
5
5
  name: 'story-title',
6
+ interpolate: true,
6
7
  render(_, ctx) {
7
8
  const name = useStoryStore((s) => s.storyData?.name || '');
8
9
  const cls = ctx.className ? `story-title ${ctx.className}` : 'story-title';
@@ -1,6 +1,5 @@
1
1
  import { useStoryStore } from '../../store';
2
- import { useContext } from 'preact/hooks';
3
- import { LocalsValuesContext } from '../../markup/render';
2
+ import { useLiveLocals } from '../../hooks/use-merged-locals';
4
3
  import { useInterpolate } from '../../hooks/use-interpolate';
5
4
  import { ownValue, variableNameError } from '../../utils/namespace';
6
5
  import { SCOPE_SIGILS } from '../../markup/tokens';
@@ -19,7 +18,7 @@ export function VarDisplay({ node }: { node: VariableNode }) {
19
18
  const resolve = useInterpolate();
20
19
  const className = resolve(node.className);
21
20
  const id = resolve(node.id);
22
- const localsValues = useContext(LocalsValuesContext);
21
+ const localsValues = useLiveLocals();
23
22
  const parts = name.split('.');
24
23
  const root = parts[0]!;
25
24
  // Own entries only, as the expression engine reads them
@@ -4,6 +4,7 @@ import { checkVariableName } from '../../utils/namespace';
4
4
  import { MacroError } from './MacroError';
5
5
  import {
6
6
  WIDGET_PARAMETERS,
7
+ checkWidgetHolds,
7
8
  widgetDef,
8
9
  type WidgetDef,
9
10
  } from '../../widgets/widget-def';
@@ -19,6 +20,7 @@ defineMacro({
19
20
  // Refuse `@` parameters that no namespace can hold
20
21
  const def = widgetDef(ctx.args);
21
22
  for (const param of def.params) checkVariableName(param.slice(1), param);
23
+ checkWidgetHolds(def);
22
24
  parsed = def;
23
25
  } catch (err) {
24
26
  error = err;