@rohal12/spindle 0.51.4 → 0.52.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/headless.js +4313 -1640
- package/dist/pkg/macro-registry.json +7 -7
- package/dist/pkg/story-variables.js +1636 -177
- package/package.json +5 -2
- package/src/automation/runner.ts +2 -1
- package/src/class-registry.ts +214 -103
- package/src/components/Passage.tsx +2 -2
- package/src/components/PassageDialog.tsx +2 -5
- package/src/components/StoryInterface.tsx +2 -4
- package/src/components/macros/Button.tsx +5 -31
- package/src/components/macros/Checkbox.tsx +7 -4
- package/src/components/macros/Computed.tsx +19 -13
- package/src/components/macros/For.tsx +29 -3
- package/src/components/macros/If.tsx +8 -0
- package/src/components/macros/Include.tsx +7 -6
- package/src/components/macros/MacroError.tsx +2 -1
- package/src/components/macros/MacroLink.tsx +12 -45
- package/src/components/macros/Meter.tsx +11 -3
- package/src/components/macros/Nobr.tsx +1 -0
- package/src/components/macros/PassageDisplay.tsx +3 -0
- package/src/components/macros/Print.tsx +4 -0
- package/src/components/macros/Radiobutton.tsx +5 -2
- package/src/components/macros/SaveManager.tsx +25 -8
- package/src/components/macros/Span.tsx +1 -0
- package/src/components/macros/StoryTitle.tsx +1 -0
- package/src/components/macros/Switch.tsx +13 -0
- package/src/components/macros/Unset.tsx +30 -10
- package/src/components/macros/VarDisplay.tsx +21 -4
- package/src/components/macros/Widget.tsx +20 -1
- package/src/components/macros/WidgetInvocation.tsx +17 -75
- package/src/components/macros/arg-utils.ts +107 -1
- package/src/components/macros/detached-body.tsx +68 -0
- package/src/components/macros/option-utils.ts +3 -2
- package/src/define-macro.ts +32 -5
- package/src/execute-mutation.ts +270 -67
- package/src/expression.ts +86 -55
- package/src/hooks/use-action.ts +18 -3
- package/src/hooks/use-interpolate.ts +36 -5
- package/src/index.tsx +10 -1
- package/src/interpolation.ts +394 -96
- package/src/js-lexer.ts +1231 -97
- package/src/markup/code-attributes.ts +64 -0
- package/src/markup/markdown.ts +188 -9
- package/src/markup/render.tsx +430 -49
- package/src/markup/tokenizer.ts +578 -110
- package/src/prng.ts +8 -8
- package/src/registry.ts +35 -0
- package/src/saves/save-manager.ts +339 -158
- package/src/saves/storage.ts +16 -7
- package/src/saves/types.ts +2 -1
- package/src/store.ts +521 -154
- package/src/story-api.ts +31 -67
- package/src/story-init.ts +1 -1
- package/src/story-variables.ts +98 -102
- package/src/triggers.ts +6 -5
- package/src/utils/error-message.ts +12 -0
- package/src/utils/live-locals.ts +10 -3
- package/src/utils/namespace.ts +71 -0
- package/src/utils/object-path.ts +99 -14
- package/src/utils/stable-key.ts +14 -9
- package/src/widgets/widget-registry.ts +9 -0
- package/types/index.d.ts +43 -7
- package/types/tooling.d.ts +1 -0
package/src/saves/storage.ts
CHANGED
|
@@ -4,7 +4,13 @@ import type { SaveRecord, PlaythroughRecord, StorageBackend } from './types';
|
|
|
4
4
|
// Memory backend
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* In-memory storage. Like the other backends it stores copies: records and
|
|
9
|
+
* values go in and come out cloned, so changing a record after storing it,
|
|
10
|
+
* or one that was read, changes nothing stored.
|
|
11
|
+
*/
|
|
7
12
|
export function createMemoryBackend(): StorageBackend {
|
|
13
|
+
const copy = <T>(value: T): T => structuredClone(value);
|
|
8
14
|
const saves = new Map<string, SaveRecord>();
|
|
9
15
|
const playthroughs = new Map<string, PlaythroughRecord>();
|
|
10
16
|
const meta = new Map<string, unknown>();
|
|
@@ -13,11 +19,12 @@ export function createMemoryBackend(): StorageBackend {
|
|
|
13
19
|
type: 'memory',
|
|
14
20
|
|
|
15
21
|
async putSave(record: SaveRecord): Promise<void> {
|
|
16
|
-
saves.set(record.meta.id, record);
|
|
22
|
+
saves.set(record.meta.id, copy(record));
|
|
17
23
|
},
|
|
18
24
|
|
|
19
25
|
async getSave(id: string): Promise<SaveRecord | undefined> {
|
|
20
|
-
|
|
26
|
+
const record = saves.get(id);
|
|
27
|
+
return record && copy(record);
|
|
21
28
|
},
|
|
22
29
|
|
|
23
30
|
async deleteSave(id: string): Promise<void> {
|
|
@@ -25,7 +32,7 @@ export function createMemoryBackend(): StorageBackend {
|
|
|
25
32
|
},
|
|
26
33
|
|
|
27
34
|
async getSavesByIfid(ifid: string): Promise<SaveRecord[]> {
|
|
28
|
-
return [...saves.values()].filter((s) => s.meta.ifid === ifid);
|
|
35
|
+
return [...saves.values()].filter((s) => s.meta.ifid === ifid).map(copy);
|
|
29
36
|
},
|
|
30
37
|
|
|
31
38
|
async deleteSavesByIfid(ifid: string): Promise<void> {
|
|
@@ -48,11 +55,13 @@ export function createMemoryBackend(): StorageBackend {
|
|
|
48
55
|
},
|
|
49
56
|
|
|
50
57
|
async putPlaythrough(record: PlaythroughRecord): Promise<void> {
|
|
51
|
-
playthroughs.set(record.id, record);
|
|
58
|
+
playthroughs.set(record.id, copy(record));
|
|
52
59
|
},
|
|
53
60
|
|
|
54
61
|
async getPlaythroughsByIfid(ifid: string): Promise<PlaythroughRecord[]> {
|
|
55
|
-
return [...playthroughs.values()]
|
|
62
|
+
return [...playthroughs.values()]
|
|
63
|
+
.filter((p) => p.ifid === ifid)
|
|
64
|
+
.map(copy);
|
|
56
65
|
},
|
|
57
66
|
|
|
58
67
|
async deletePlaythroughsByIfid(ifid: string): Promise<void> {
|
|
@@ -67,11 +76,11 @@ export function createMemoryBackend(): StorageBackend {
|
|
|
67
76
|
},
|
|
68
77
|
|
|
69
78
|
async getMeta<T = unknown>(key: string): Promise<T | undefined> {
|
|
70
|
-
return meta.get(key) as T | undefined;
|
|
79
|
+
return copy(meta.get(key)) as T | undefined;
|
|
71
80
|
},
|
|
72
81
|
|
|
73
82
|
async setMeta(key: string, value: unknown): Promise<void> {
|
|
74
|
-
meta.set(key, value);
|
|
83
|
+
meta.set(key, copy(value));
|
|
75
84
|
},
|
|
76
85
|
|
|
77
86
|
async deleteMeta(key: string): Promise<void> {
|
package/src/saves/types.ts
CHANGED
|
@@ -133,7 +133,8 @@ function isImportablePayload(value: unknown): value is SavePayload {
|
|
|
133
133
|
|
|
134
134
|
const { history, historyIndex } = value;
|
|
135
135
|
if (!Array.isArray(history) || history.length === 0) return false;
|
|
136
|
-
|
|
136
|
+
// Array.from: every() skips the holes of a sparse array
|
|
137
|
+
if (!Array.from(history).every(isSaveHistoryMoment)) return false;
|
|
137
138
|
if (
|
|
138
139
|
typeof historyIndex !== 'number' ||
|
|
139
140
|
!Number.isInteger(historyIndex) ||
|