@hyperframes/studio 0.5.4 → 0.6.0-alpha.1
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/assets/hyperframes-player-Cd8vYWxP.js +198 -0
- package/dist/assets/index-D04_ZoMm.js +107 -0
- package/dist/assets/index-UWFaHilT.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +4 -4
- package/src/App.tsx +2621 -170
- package/src/components/LintModal.tsx +3 -4
- package/src/components/editor/DomEditOverlay.test.ts +241 -0
- package/src/components/editor/DomEditOverlay.tsx +1300 -0
- package/src/components/editor/MotionPanel.tsx +651 -0
- package/src/components/editor/PropertyPanel.test.ts +67 -0
- package/src/components/editor/PropertyPanel.tsx +2891 -207
- package/src/components/editor/TimelineLayerPanel.test.ts +42 -0
- package/src/components/editor/TimelineLayerPanel.tsx +113 -0
- package/src/components/editor/colorValue.test.ts +82 -0
- package/src/components/editor/colorValue.ts +175 -0
- package/src/components/editor/domEditing.test.ts +872 -0
- package/src/components/editor/domEditing.ts +993 -0
- package/src/components/editor/floatingPanel.test.ts +34 -0
- package/src/components/editor/floatingPanel.ts +54 -0
- package/src/components/editor/fontAssets.ts +32 -0
- package/src/components/editor/fontCatalog.ts +126 -0
- package/src/components/editor/gradientValue.test.ts +89 -0
- package/src/components/editor/gradientValue.ts +445 -0
- package/src/components/editor/manualEditingAvailability.test.ts +120 -0
- package/src/components/editor/manualEditingAvailability.ts +60 -0
- package/src/components/editor/manualEdits.test.ts +945 -0
- package/src/components/editor/manualEdits.ts +1397 -0
- package/src/components/editor/manualOffsetDrag.test.ts +140 -0
- package/src/components/editor/manualOffsetDrag.ts +307 -0
- package/src/components/editor/studioMotion.test.ts +355 -0
- package/src/components/editor/studioMotion.ts +632 -0
- package/src/components/nle/NLELayout.tsx +27 -4
- package/src/components/nle/NLEPreview.tsx +50 -5
- package/src/components/renders/RenderQueue.tsx +13 -62
- package/src/components/renders/useRenderQueue.ts +6 -30
- package/src/components/sidebar/AssetsTab.tsx +3 -4
- package/src/components/sidebar/CompositionsTab.test.ts +16 -1
- package/src/components/sidebar/CompositionsTab.tsx +117 -45
- package/src/components/sidebar/LeftSidebar.tsx +140 -125
- package/src/hooks/usePersistentEditHistory.test.ts +256 -0
- package/src/hooks/usePersistentEditHistory.ts +337 -0
- package/src/icons/SystemIcons.tsx +2 -0
- package/src/player/components/CompositionThumbnail.test.ts +19 -0
- package/src/player/components/CompositionThumbnail.tsx +50 -13
- package/src/player/components/EditModal.tsx +5 -20
- package/src/player/components/Player.tsx +18 -2
- package/src/player/components/Timeline.test.ts +20 -0
- package/src/player/components/Timeline.tsx +103 -21
- package/src/player/components/TimelineClip.test.ts +92 -0
- package/src/player/components/TimelineClip.tsx +241 -7
- package/src/player/components/timelineEditing.test.ts +16 -3
- package/src/player/components/timelineEditing.ts +10 -3
- package/src/player/hooks/useTimelinePlayer.test.ts +148 -19
- package/src/player/hooks/useTimelinePlayer.ts +287 -16
- package/src/player/store/playerStore.ts +2 -0
- package/src/utils/clipboard.test.ts +89 -0
- package/src/utils/clipboard.ts +57 -0
- package/src/utils/editHistory.test.ts +244 -0
- package/src/utils/editHistory.ts +218 -0
- package/src/utils/editHistoryStorage.test.ts +37 -0
- package/src/utils/editHistoryStorage.ts +99 -0
- package/src/utils/mediaTypes.ts +1 -1
- package/src/utils/sourcePatcher.test.ts +128 -1
- package/src/utils/sourcePatcher.ts +130 -18
- package/src/utils/studioFileHistory.test.ts +156 -0
- package/src/utils/studioFileHistory.ts +61 -0
- package/src/utils/timelineAssetDrop.test.ts +31 -11
- package/src/utils/timelineAssetDrop.ts +22 -2
- package/src/utils/timelineInspector.test.ts +79 -0
- package/src/utils/timelineInspector.ts +116 -0
- package/dist/assets/hyperframes-player-CEnWY28J.js +0 -417
- package/dist/assets/index-04Mp2wOn.css +0 -1
- package/dist/assets/index-960mgQMI.js +0 -93
|
@@ -36,6 +36,7 @@ interface LeftSidebarProps {
|
|
|
36
36
|
onLint?: () => void;
|
|
37
37
|
linting?: boolean;
|
|
38
38
|
onToggleCollapse?: () => void;
|
|
39
|
+
takeoverContent?: ReactNode;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export const LeftSidebar = memo(function LeftSidebar({
|
|
@@ -59,6 +60,7 @@ export const LeftSidebar = memo(function LeftSidebar({
|
|
|
59
60
|
onLint,
|
|
60
61
|
linting,
|
|
61
62
|
onToggleCollapse,
|
|
63
|
+
takeoverContent,
|
|
62
64
|
}: LeftSidebarProps) {
|
|
63
65
|
const [tab, setTab] = useState<SidebarTab>(getPersistedTab);
|
|
64
66
|
|
|
@@ -89,135 +91,148 @@ export const LeftSidebar = memo(function LeftSidebar({
|
|
|
89
91
|
className="flex flex-col h-full bg-neutral-950 border-r border-neutral-800/50"
|
|
90
92
|
style={{ width }}
|
|
91
93
|
>
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
className=
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
)}
|
|
162
|
-
{tab === "assets" && (
|
|
163
|
-
<AssetsTab
|
|
164
|
-
projectId={projectId}
|
|
165
|
-
assets={assets}
|
|
166
|
-
onImport={onImportFiles}
|
|
167
|
-
onDelete={onDeleteFile}
|
|
168
|
-
onRename={onRenameFile}
|
|
169
|
-
/>
|
|
170
|
-
)}
|
|
171
|
-
{tab === "code" && (
|
|
172
|
-
<div className="flex flex-1 min-h-0">
|
|
173
|
-
{(fileProp?.length ?? 0) > 0 && (
|
|
174
|
-
<div className="w-[160px] flex-shrink-0 border-r border-neutral-800 overflow-y-auto">
|
|
175
|
-
<FileTree
|
|
176
|
-
files={fileProp ?? []}
|
|
177
|
-
activeFile={editingFile?.path ?? null}
|
|
178
|
-
onSelectFile={onSelectFile ?? (() => {})}
|
|
179
|
-
onCreateFile={onCreateFile}
|
|
180
|
-
onCreateFolder={onCreateFolder}
|
|
181
|
-
onDeleteFile={onDeleteFile}
|
|
182
|
-
onRenameFile={onRenameFile}
|
|
183
|
-
onDuplicateFile={onDuplicateFile}
|
|
184
|
-
onMoveFile={onMoveFile}
|
|
185
|
-
onImportFiles={onImportFiles}
|
|
186
|
-
/>
|
|
94
|
+
{takeoverContent ? (
|
|
95
|
+
<div className="flex min-h-0 flex-1">{takeoverContent}</div>
|
|
96
|
+
) : (
|
|
97
|
+
<>
|
|
98
|
+
{/* Tabs — Code first */}
|
|
99
|
+
<div className="border-b border-neutral-800/50 px-3 py-3 flex-shrink-0">
|
|
100
|
+
<div className="flex items-center gap-2">
|
|
101
|
+
<div
|
|
102
|
+
className="grid min-w-0 flex-1 gap-1 rounded-[18px] bg-neutral-900 p-1 shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]"
|
|
103
|
+
style={{ gridTemplateColumns: "0.9fr 1.25fr 0.9fr" }}
|
|
104
|
+
>
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
onClick={() => selectTab("code")}
|
|
108
|
+
className={`rounded-[14px] px-2.5 py-2 text-[10px] font-semibold transition-all ${
|
|
109
|
+
tab === "code"
|
|
110
|
+
? "bg-neutral-800 text-white"
|
|
111
|
+
: "text-neutral-500 hover:text-neutral-200"
|
|
112
|
+
}`}
|
|
113
|
+
>
|
|
114
|
+
Code
|
|
115
|
+
</button>
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
onClick={() => selectTab("compositions")}
|
|
119
|
+
className={`rounded-[14px] px-2.5 py-2 text-[10px] font-semibold transition-all ${
|
|
120
|
+
tab === "compositions"
|
|
121
|
+
? "bg-neutral-800 text-white"
|
|
122
|
+
: "text-neutral-500 hover:text-neutral-200"
|
|
123
|
+
}`}
|
|
124
|
+
>
|
|
125
|
+
Compositions
|
|
126
|
+
</button>
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
onClick={() => selectTab("assets")}
|
|
130
|
+
className={`rounded-[14px] px-2.5 py-2 text-[10px] font-semibold transition-all ${
|
|
131
|
+
tab === "assets"
|
|
132
|
+
? "bg-neutral-800 text-white"
|
|
133
|
+
: "text-neutral-500 hover:text-neutral-200"
|
|
134
|
+
}`}
|
|
135
|
+
>
|
|
136
|
+
Assets
|
|
137
|
+
</button>
|
|
138
|
+
</div>
|
|
139
|
+
{onToggleCollapse && (
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
onClick={onToggleCollapse}
|
|
143
|
+
className="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-transparent text-neutral-500 transition-colors hover:border-neutral-800 hover:bg-neutral-900 hover:text-neutral-300"
|
|
144
|
+
title="Hide sidebar"
|
|
145
|
+
aria-label="Hide sidebar"
|
|
146
|
+
>
|
|
147
|
+
<svg
|
|
148
|
+
width="14"
|
|
149
|
+
height="14"
|
|
150
|
+
viewBox="0 0 24 24"
|
|
151
|
+
fill="none"
|
|
152
|
+
stroke="currentColor"
|
|
153
|
+
strokeWidth="1.5"
|
|
154
|
+
strokeLinecap="round"
|
|
155
|
+
strokeLinejoin="round"
|
|
156
|
+
aria-hidden="true"
|
|
157
|
+
>
|
|
158
|
+
<path d="m14 7-5 5 5 5" />
|
|
159
|
+
<path d="M19 4v16" />
|
|
160
|
+
</svg>
|
|
161
|
+
</button>
|
|
162
|
+
)}
|
|
187
163
|
</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
{/* Tab content */}
|
|
167
|
+
{tab === "compositions" && (
|
|
168
|
+
<CompositionsTab
|
|
169
|
+
projectId={projectId}
|
|
170
|
+
compositions={compositions}
|
|
171
|
+
activeComposition={activeComposition}
|
|
172
|
+
onSelect={onSelectComposition}
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
175
|
+
{tab === "assets" && (
|
|
176
|
+
<AssetsTab
|
|
177
|
+
projectId={projectId}
|
|
178
|
+
assets={assets}
|
|
179
|
+
onImport={onImportFiles}
|
|
180
|
+
onDelete={onDeleteFile}
|
|
181
|
+
onRename={onRenameFile}
|
|
182
|
+
/>
|
|
188
183
|
)}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
184
|
+
{tab === "code" && (
|
|
185
|
+
<div className="flex flex-1 min-h-0">
|
|
186
|
+
{(fileProp?.length ?? 0) > 0 && (
|
|
187
|
+
<div className="w-[160px] flex-shrink-0 border-r border-neutral-800 overflow-y-auto">
|
|
188
|
+
<FileTree
|
|
189
|
+
files={fileProp ?? []}
|
|
190
|
+
activeFile={editingFile?.path ?? null}
|
|
191
|
+
onSelectFile={onSelectFile ?? (() => {})}
|
|
192
|
+
onCreateFile={onCreateFile}
|
|
193
|
+
onCreateFolder={onCreateFolder}
|
|
194
|
+
onDeleteFile={onDeleteFile}
|
|
195
|
+
onRenameFile={onRenameFile}
|
|
196
|
+
onDuplicateFile={onDuplicateFile}
|
|
197
|
+
onMoveFile={onMoveFile}
|
|
198
|
+
onImportFiles={onImportFiles}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
)}
|
|
202
|
+
<div className="flex-1 overflow-hidden min-w-0">
|
|
203
|
+
{codeChildren ?? (
|
|
204
|
+
<div className="flex items-center justify-center h-full text-neutral-600 text-sm">
|
|
205
|
+
Select a file to edit
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
193
208
|
</div>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
</div>
|
|
197
|
-
)}
|
|
209
|
+
</div>
|
|
210
|
+
)}
|
|
198
211
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
{/* Lint button pinned at the bottom */}
|
|
213
|
+
{onLint && (
|
|
214
|
+
<div className="border-t border-neutral-800 p-2 flex-shrink-0">
|
|
215
|
+
<button
|
|
216
|
+
onClick={onLint}
|
|
217
|
+
disabled={linting}
|
|
218
|
+
className="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-[11px] font-medium text-neutral-500 hover:text-amber-300 hover:bg-neutral-800 transition-colors disabled:opacity-40"
|
|
219
|
+
>
|
|
220
|
+
<svg
|
|
221
|
+
width="12"
|
|
222
|
+
height="12"
|
|
223
|
+
viewBox="0 0 24 24"
|
|
224
|
+
fill="none"
|
|
225
|
+
stroke="currentColor"
|
|
226
|
+
strokeWidth="2"
|
|
227
|
+
>
|
|
228
|
+
<path d="M9 11l3 3L22 4" />
|
|
229
|
+
<path d="M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11" />
|
|
230
|
+
</svg>
|
|
231
|
+
{linting ? "Linting…" : "Lint"}
|
|
232
|
+
</button>
|
|
233
|
+
</div>
|
|
234
|
+
)}
|
|
235
|
+
</>
|
|
221
236
|
)}
|
|
222
237
|
</div>
|
|
223
238
|
);
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createEmptyEditHistory } from "../utils/editHistory";
|
|
3
|
+
import type { EditHistoryStorageAdapter } from "../utils/editHistoryStorage";
|
|
4
|
+
import { createMemoryEditHistoryStorage } from "../utils/editHistoryStorage";
|
|
5
|
+
import {
|
|
6
|
+
createPersistentEditHistoryController,
|
|
7
|
+
createPersistentEditHistoryStore,
|
|
8
|
+
} from "./usePersistentEditHistory";
|
|
9
|
+
|
|
10
|
+
describe("createPersistentEditHistoryController", () => {
|
|
11
|
+
it("records history and reloads it for the same project", async () => {
|
|
12
|
+
const storage = createMemoryEditHistoryStorage();
|
|
13
|
+
const first = await createPersistentEditHistoryController({
|
|
14
|
+
projectId: "project-1",
|
|
15
|
+
storage,
|
|
16
|
+
now: () => 100,
|
|
17
|
+
onChange: () => {},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await first.recordEdit({
|
|
21
|
+
label: "Move layer",
|
|
22
|
+
kind: "manual",
|
|
23
|
+
files: { "index.html": { before: "a", after: "b" } },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const second = await createPersistentEditHistoryController({
|
|
27
|
+
projectId: "project-1",
|
|
28
|
+
storage,
|
|
29
|
+
now: () => 200,
|
|
30
|
+
onChange: () => {},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(second.snapshot().canUndo).toBe(true);
|
|
34
|
+
expect(second.snapshot().undoLabel).toBe("Move layer");
|
|
35
|
+
expect(second.snapshot().undoPaths).toEqual(["index.html"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("undo applies files through the provided callback and persists redo state", async () => {
|
|
39
|
+
const storage = createMemoryEditHistoryStorage();
|
|
40
|
+
const controller = await createPersistentEditHistoryController({
|
|
41
|
+
projectId: "project-1",
|
|
42
|
+
storage,
|
|
43
|
+
now: () => 100,
|
|
44
|
+
onChange: () => {},
|
|
45
|
+
});
|
|
46
|
+
await controller.recordEdit({
|
|
47
|
+
label: "Move layer",
|
|
48
|
+
kind: "manual",
|
|
49
|
+
files: { "index.html": { before: "a", after: "b" } },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = await controller.undo({
|
|
53
|
+
readFile: async (path) => {
|
|
54
|
+
expect(path).toBe("index.html");
|
|
55
|
+
return "b";
|
|
56
|
+
},
|
|
57
|
+
writeFile: async (path, content) => {
|
|
58
|
+
expect(path).toBe("index.html");
|
|
59
|
+
expect(content).toBe("a");
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
expect(result.ok).toBe(true);
|
|
63
|
+
expect(result.paths).toEqual(["index.html"]);
|
|
64
|
+
|
|
65
|
+
expect(controller.snapshot().canUndo).toBe(false);
|
|
66
|
+
expect(controller.snapshot().canRedo).toBe(true);
|
|
67
|
+
expect(controller.snapshot().redoPaths).toEqual(["index.html"]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("keeps in-memory history when storage saves fail", async () => {
|
|
71
|
+
const storage: EditHistoryStorageAdapter = {
|
|
72
|
+
async get() {
|
|
73
|
+
return null;
|
|
74
|
+
},
|
|
75
|
+
async set() {
|
|
76
|
+
throw new Error("IndexedDB unavailable");
|
|
77
|
+
},
|
|
78
|
+
async delete() {},
|
|
79
|
+
};
|
|
80
|
+
const controller = await createPersistentEditHistoryController({
|
|
81
|
+
projectId: "project-1",
|
|
82
|
+
storage,
|
|
83
|
+
now: () => 100,
|
|
84
|
+
onChange: () => {},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await expect(
|
|
88
|
+
controller.recordEdit({
|
|
89
|
+
label: "Move layer",
|
|
90
|
+
kind: "manual",
|
|
91
|
+
files: { "index.html": { before: "a", after: "b" } },
|
|
92
|
+
}),
|
|
93
|
+
).resolves.toBeUndefined();
|
|
94
|
+
|
|
95
|
+
expect(controller.snapshot().canUndo).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("serializes concurrent record edits against the latest state", async () => {
|
|
99
|
+
const storage = createMemoryEditHistoryStorage();
|
|
100
|
+
let timestamp = 100;
|
|
101
|
+
const store = createPersistentEditHistoryStore({
|
|
102
|
+
projectId: "project-1",
|
|
103
|
+
storage,
|
|
104
|
+
initialState: createEmptyEditHistory(),
|
|
105
|
+
now: () => timestamp++,
|
|
106
|
+
onChange: () => {},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await Promise.all([
|
|
110
|
+
store.recordEdit({
|
|
111
|
+
label: "Move layer",
|
|
112
|
+
kind: "manual",
|
|
113
|
+
files: { "index.html": { before: "a", after: "b" } },
|
|
114
|
+
}),
|
|
115
|
+
store.recordEdit({
|
|
116
|
+
label: "Resize layer",
|
|
117
|
+
kind: "manual",
|
|
118
|
+
files: { "index.html": { before: "b", after: "c" } },
|
|
119
|
+
}),
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
expect(store.snapshot().state.undo.map((entry) => entry.label)).toEqual([
|
|
123
|
+
"Move layer",
|
|
124
|
+
"Resize layer",
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("still coalesces concurrent source edits that share a coalesce key", async () => {
|
|
129
|
+
const storage = createMemoryEditHistoryStorage();
|
|
130
|
+
let timestamp = 100;
|
|
131
|
+
const store = createPersistentEditHistoryStore({
|
|
132
|
+
projectId: "project-1",
|
|
133
|
+
storage,
|
|
134
|
+
initialState: createEmptyEditHistory(),
|
|
135
|
+
now: () => timestamp++,
|
|
136
|
+
onChange: () => {},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await Promise.all([
|
|
140
|
+
store.recordEdit({
|
|
141
|
+
label: "Edit source",
|
|
142
|
+
kind: "source",
|
|
143
|
+
coalesceKey: "source:index.html",
|
|
144
|
+
files: { "index.html": { before: "a", after: "b" } },
|
|
145
|
+
}),
|
|
146
|
+
store.recordEdit({
|
|
147
|
+
label: "Edit source",
|
|
148
|
+
kind: "source",
|
|
149
|
+
coalesceKey: "source:index.html",
|
|
150
|
+
files: { "index.html": { before: "b", after: "c" } },
|
|
151
|
+
}),
|
|
152
|
+
]);
|
|
153
|
+
|
|
154
|
+
expect(store.snapshot().state.undo).toHaveLength(1);
|
|
155
|
+
expect(store.snapshot().state.undo[0].files["index.html"].before).toBe("a");
|
|
156
|
+
expect(store.snapshot().state.undo[0].files["index.html"].after).toBe("c");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("reads undo hashes from the live top entry during queued undo calls", async () => {
|
|
160
|
+
const storage = createMemoryEditHistoryStorage();
|
|
161
|
+
let timestamp = 100;
|
|
162
|
+
const store = createPersistentEditHistoryStore({
|
|
163
|
+
projectId: "project-1",
|
|
164
|
+
storage,
|
|
165
|
+
initialState: createEmptyEditHistory(),
|
|
166
|
+
now: () => timestamp++,
|
|
167
|
+
onChange: () => {},
|
|
168
|
+
});
|
|
169
|
+
await store.recordEdit({
|
|
170
|
+
label: "Edit first file",
|
|
171
|
+
kind: "manual",
|
|
172
|
+
files: { "first.html": { before: "first-before", after: "first-after" } },
|
|
173
|
+
});
|
|
174
|
+
await store.recordEdit({
|
|
175
|
+
label: "Edit second file",
|
|
176
|
+
kind: "manual",
|
|
177
|
+
files: { "second.html": { before: "second-before", after: "second-after" } },
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const files: Record<string, string> = {
|
|
181
|
+
"first.html": "first-after",
|
|
182
|
+
"second.html": "second-after",
|
|
183
|
+
};
|
|
184
|
+
const readPaths: string[] = [];
|
|
185
|
+
|
|
186
|
+
await Promise.all([
|
|
187
|
+
store.undo({
|
|
188
|
+
readFile: async (path) => {
|
|
189
|
+
readPaths.push(path);
|
|
190
|
+
return files[path];
|
|
191
|
+
},
|
|
192
|
+
writeFile: async (path, content) => {
|
|
193
|
+
files[path] = content;
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
196
|
+
store.undo({
|
|
197
|
+
readFile: async (path) => {
|
|
198
|
+
readPaths.push(path);
|
|
199
|
+
return files[path];
|
|
200
|
+
},
|
|
201
|
+
writeFile: async (path, content) => {
|
|
202
|
+
files[path] = content;
|
|
203
|
+
},
|
|
204
|
+
}),
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
expect(readPaths).toEqual(["second.html", "first.html"]);
|
|
208
|
+
expect(files).toEqual({
|
|
209
|
+
"first.html": "first-before",
|
|
210
|
+
"second.html": "second-before",
|
|
211
|
+
});
|
|
212
|
+
expect(store.snapshot().canUndo).toBe(false);
|
|
213
|
+
expect(store.snapshot().canRedo).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("rolls back files when an undo write fails partway through", async () => {
|
|
217
|
+
const storage = createMemoryEditHistoryStorage();
|
|
218
|
+
const store = createPersistentEditHistoryStore({
|
|
219
|
+
projectId: "project-1",
|
|
220
|
+
storage,
|
|
221
|
+
initialState: createEmptyEditHistory(),
|
|
222
|
+
now: () => 100,
|
|
223
|
+
onChange: () => {},
|
|
224
|
+
});
|
|
225
|
+
await store.recordEdit({
|
|
226
|
+
label: "Edit files",
|
|
227
|
+
kind: "manual",
|
|
228
|
+
files: {
|
|
229
|
+
"first.html": { before: "first-before", after: "first-after" },
|
|
230
|
+
"second.html": { before: "second-before", after: "second-after" },
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const files: Record<string, string> = {
|
|
235
|
+
"first.html": "first-after",
|
|
236
|
+
"second.html": "second-after",
|
|
237
|
+
};
|
|
238
|
+
const result = store.undo({
|
|
239
|
+
readFile: async (path) => files[path],
|
|
240
|
+
writeFile: async (path, content) => {
|
|
241
|
+
if (path === "second.html" && content === "second-before") {
|
|
242
|
+
throw new Error("write failed");
|
|
243
|
+
}
|
|
244
|
+
files[path] = content;
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
await expect(result).rejects.toThrow("write failed");
|
|
249
|
+
expect(files).toEqual({
|
|
250
|
+
"first.html": "first-after",
|
|
251
|
+
"second.html": "second-after",
|
|
252
|
+
});
|
|
253
|
+
expect(store.snapshot().undoLabel).toBe("Edit files");
|
|
254
|
+
expect(store.snapshot().canRedo).toBe(false);
|
|
255
|
+
});
|
|
256
|
+
});
|