@rohal12/spindle 0.44.0 → 0.45.0
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/story-variables.js +125 -0
- package/dist/pkg/tooling.js +2 -0
- package/package.json +2 -1
- package/src/components/App.tsx +6 -4
- package/src/components/PassageDialog.tsx +10 -1
- package/src/components/TriggerDialogHost.tsx +1 -0
- package/src/components/macros/MenubarButtons.tsx +17 -6
- package/src/saves/save-manager.ts +88 -19
- package/src/store.ts +52 -1
- package/src/story-api.ts +36 -2
- package/src/triggers.ts +1 -0
- package/src/types-drift-check.ts +10 -0
- package/types/index.d.ts +82 -1
- package/types/tooling.d.ts +68 -0
package/types/index.d.ts
CHANGED
|
@@ -359,6 +359,54 @@ export interface SaveInfo {
|
|
|
359
359
|
custom: Record<string, unknown>;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Metadata stored with each save record.
|
|
364
|
+
* @see {@link ../../src/saves/types.ts} for the implementation.
|
|
365
|
+
*/
|
|
366
|
+
export interface SaveMeta {
|
|
367
|
+
/** Unique save ID. */
|
|
368
|
+
id: string;
|
|
369
|
+
/** IFID of the story that created the save. */
|
|
370
|
+
ifid: string;
|
|
371
|
+
/** Playthrough the save belongs to. */
|
|
372
|
+
playthroughId: string;
|
|
373
|
+
/** ISO 8601 timestamp when the save was first created. */
|
|
374
|
+
createdAt: string;
|
|
375
|
+
/** ISO 8601 timestamp when the save was last updated. */
|
|
376
|
+
updatedAt: string;
|
|
377
|
+
/** Save title (generated or custom). */
|
|
378
|
+
title: string;
|
|
379
|
+
/** Passage name at the time of saving. */
|
|
380
|
+
passage: string;
|
|
381
|
+
/** Custom metadata passed when saving. */
|
|
382
|
+
custom: Record<string, unknown>;
|
|
383
|
+
/** Estimated size of the stored payload in bytes. */
|
|
384
|
+
estimatedBytes?: number;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* A stored save: metadata plus the serialized payload.
|
|
389
|
+
* @see {@link ../../src/saves/types.ts} for the implementation.
|
|
390
|
+
*/
|
|
391
|
+
export interface SaveRecord {
|
|
392
|
+
meta: SaveMeta;
|
|
393
|
+
payload: SavePayload;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Portable save file produced by `exportSave()` and accepted by `importSave()`.
|
|
398
|
+
* Plain JSON: `JSON.stringify` it to write a file, `JSON.parse` to read one back.
|
|
399
|
+
* @see {@link ../../src/saves/types.ts} for the implementation.
|
|
400
|
+
*/
|
|
401
|
+
export interface SaveExport {
|
|
402
|
+
version: 1;
|
|
403
|
+
/** IFID of the story the save belongs to. Imports into other stories are rejected. */
|
|
404
|
+
ifid: string;
|
|
405
|
+
/** ISO 8601 timestamp of the export. */
|
|
406
|
+
exportedAt: string;
|
|
407
|
+
save: SaveRecord;
|
|
408
|
+
}
|
|
409
|
+
|
|
362
410
|
/**
|
|
363
411
|
* The main Story API available as `window.Story` at runtime.
|
|
364
412
|
* Provides access to variables, navigation, save/load, and visit tracking.
|
|
@@ -411,6 +459,21 @@ export interface StoryAPI {
|
|
|
411
459
|
/** Delete a save by slot name. */
|
|
412
460
|
deleteSave(slot?: string): void;
|
|
413
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Export the save in a slot as a portable object (plain JSON).
|
|
464
|
+
* Resolves to null if the slot is empty.
|
|
465
|
+
* @example const data = await Story.exportSave('slot-1'); // JSON.stringify(data) to download
|
|
466
|
+
*/
|
|
467
|
+
exportSave(slot?: string): Promise<SaveExport | null>;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Import an exported save into a slot, replacing whatever the slot held.
|
|
471
|
+
* Rejects if `data` is not a save export or belongs to a different story (IFID).
|
|
472
|
+
* Resolves to the slot's new metadata.
|
|
473
|
+
* @example await Story.importSave(JSON.parse(text), 'slot-2')
|
|
474
|
+
*/
|
|
475
|
+
importSave(data: unknown, slot?: string): Promise<SaveInfo>;
|
|
476
|
+
|
|
414
477
|
/** Return the number of times a passage has been visited. */
|
|
415
478
|
visited(name?: string): number;
|
|
416
479
|
|
|
@@ -460,10 +523,18 @@ export interface StoryAPI {
|
|
|
460
523
|
* Open a dialog rendering the given passage.
|
|
461
524
|
* @param passageName - The passage to render inside the dialog.
|
|
462
525
|
* @param options - Optional configuration for the dialog panel.
|
|
526
|
+
* @param options.panelClass - CSS class added to the dialog panel.
|
|
527
|
+
* @param options.showCloseButton - Show the default `✕` button (defaults to `dismissible`).
|
|
528
|
+
* @param options.dismissible - When `false`, backdrop clicks are ignored and the
|
|
529
|
+
* `✕` button is hidden; close the dialog with `closeDialog()`. Default: `true`.
|
|
463
530
|
*/
|
|
464
531
|
openDialog(
|
|
465
532
|
passageName: string,
|
|
466
|
-
options?: {
|
|
533
|
+
options?: {
|
|
534
|
+
panelClass?: string;
|
|
535
|
+
showCloseButton?: boolean;
|
|
536
|
+
dismissible?: boolean;
|
|
537
|
+
},
|
|
467
538
|
): void;
|
|
468
539
|
|
|
469
540
|
/** Close the topmost open dialog. */
|
|
@@ -552,6 +623,16 @@ export interface StoryAPI {
|
|
|
552
623
|
readonly config: {
|
|
553
624
|
/** Maximum number of history moments to retain. */
|
|
554
625
|
maxHistory: number;
|
|
626
|
+
/**
|
|
627
|
+
* Key that triggers a quick save (`KeyboardEvent.key`, default `'F6'`).
|
|
628
|
+
* Set to `null` to disable the shortcut.
|
|
629
|
+
*/
|
|
630
|
+
quickSaveKey: string | null;
|
|
631
|
+
/**
|
|
632
|
+
* Key that triggers a quick load (`KeyboardEvent.key`, default `'F9'`).
|
|
633
|
+
* Set to `null` to disable the shortcut.
|
|
634
|
+
*/
|
|
635
|
+
quickLoadKey: string | null;
|
|
555
636
|
};
|
|
556
637
|
|
|
557
638
|
/** Seedable pseudo-random number generator. */
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface ParameterDef {
|
|
2
|
+
name: string;
|
|
3
|
+
required?: boolean;
|
|
4
|
+
description?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface MacroMetadata {
|
|
8
|
+
name: string;
|
|
9
|
+
block: boolean;
|
|
10
|
+
subMacros: string[];
|
|
11
|
+
storeVar?: boolean;
|
|
12
|
+
interpolate?: boolean;
|
|
13
|
+
merged?: boolean;
|
|
14
|
+
source: 'builtin' | 'user';
|
|
15
|
+
description?: string;
|
|
16
|
+
parameters?: ParameterDef[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface MacroDefinition {
|
|
20
|
+
name: string;
|
|
21
|
+
subMacros?: string[];
|
|
22
|
+
block?: boolean;
|
|
23
|
+
interpolate?: boolean;
|
|
24
|
+
merged?: boolean;
|
|
25
|
+
storeVar?: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
parameters?: ParameterDef[];
|
|
28
|
+
render: (...args: any[]) => any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Metadata-only defineMacro for tooling.
|
|
33
|
+
* Captures macro metadata without creating Preact components.
|
|
34
|
+
* LSP servers call this to register user-defined macros discovered in story scripts.
|
|
35
|
+
*/
|
|
36
|
+
export declare function defineMacro(config: MacroDefinition): void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Return metadata for all registered macros (built-in + user-defined).
|
|
40
|
+
*/
|
|
41
|
+
export declare function getMacroRegistry(): MacroMetadata[];
|
|
42
|
+
|
|
43
|
+
/** Variable type inferred from a StoryVariables/StoryTransients default value. */
|
|
44
|
+
export type VarType = 'number' | 'string' | 'boolean' | 'array' | 'object';
|
|
45
|
+
|
|
46
|
+
/** Inferred shape of a declared variable (or one of its object fields). */
|
|
47
|
+
export interface FieldSchema {
|
|
48
|
+
type: VarType;
|
|
49
|
+
/** Field schemas, only present for objects. */
|
|
50
|
+
fields?: Map<string, FieldSchema>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A declared variable: its inferred schema plus its default value. */
|
|
54
|
+
export interface VariableSchema extends FieldSchema {
|
|
55
|
+
name: string;
|
|
56
|
+
default: unknown;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parse the content of a `StoryVariables` (`$name = value`) or
|
|
61
|
+
* `StoryTransients` (`%name = value`, pass `sigil: '%'`) passage into a
|
|
62
|
+
* schema map, exactly as Spindle does at boot.
|
|
63
|
+
* Throws on invalid declarations or unsupported value types (e.g. `null`).
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseStoryVariables(
|
|
66
|
+
content: string,
|
|
67
|
+
sigil?: '$' | '%',
|
|
68
|
+
): Map<string, VariableSchema>;
|