@hyperframes/studio 0.9.55 → 0.9.58
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-BroIQA4E.js → hyperframes-player-B78JDyI_.js} +1 -1
- package/dist/assets/{index-Be7DZynj.js → index-D7ICtobF.js} +190 -190
- package/dist/assets/{index-CiF0D62S.js → index-ww7-RmuM.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-RXcvblHS.js → pausedVideoDecoder-Dbe8Cmab.js} +1 -1
- package/dist/{chunk-JMM2CSEL.js → chunk-5EEM5WO4.js} +5 -1
- package/dist/index.d.ts +87 -3
- package/dist/index.html +1 -1
- package/dist/index.js +872 -778
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +35 -3
- package/src/components/nle/NLEPreview.tsx +5 -4
- package/src/hooks/gsapRuntimePatch.ts +2 -3
- package/src/hooks/gsapRuntimeReaders.test.ts +5 -40
- package/src/hooks/gsapRuntimeReaders.ts +3 -27
- package/src/hooks/useExternalFileChangeCoordinator.test.tsx +20 -0
- package/src/hooks/useExternalFileChangeCoordinator.ts +1 -1
- package/src/index.ts +17 -0
- package/src/player/components/Player.test.ts +10 -0
- package/src/player/components/Player.tsx +2 -2
- package/src/player/components/studioShortcuts.ts +3 -2
- package/src/player/hooks/previewMessageRouter.manifest.test.ts +1 -0
- package/src/player/hooks/previewMessageRouter.test.ts +90 -12
- package/src/player/hooks/previewMessageRouter.ts +6 -4
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -0
- package/src/player/hooks/timelineSyncHydration.test.ts +28 -2
- package/src/player/hooks/timelineSyncHydration.ts +3 -7
- package/src/player/hooks/usePlaybackKeyboard.test.ts +107 -2
- package/src/player/hooks/usePlaybackKeyboard.ts +38 -1
- package/src/player/hooks/useShadowPreviewReload.ts +131 -14
- package/src/player/hooks/useTimelinePlayer.metadata.test.ts +1 -0
- package/src/player/hooks/useTimelinePlayer.play.test.ts +1 -0
- package/src/player/hooks/useTimelinePlayer.reloadStill.test.ts +241 -0
- package/src/player/hooks/useTimelinePlayer.seek.test.ts +3 -0
- package/src/player/hooks/useTimelinePlayer.ts +13 -1
- package/src/player/hooks/useTimelineSyncCallbacks.ts +4 -0
- package/src/player/lib/bridgePlayback.ts +7 -1
- package/src/player/lib/previewChannel.test.ts +13 -0
- package/src/sealedPreviewExports.test.ts +20 -0
- package/src/utils/externalConflictStorage.test.ts +66 -14
- package/src/utils/externalConflictStorage.ts +36 -82
- package/src/utils/gsapSoftReload.ts +2 -14
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// fails without the fix: a reload kept the live page beside its own until promotion, so a heavy project held two whole
|
|
3
|
+
// pages (1.7x the app's resident memory) and ran out of memory. A host that can show the live
|
|
4
|
+
// frame as a still now gets one page at a time.
|
|
5
|
+
|
|
6
|
+
import { act } from "react";
|
|
7
|
+
import { createRoot } from "react-dom/client";
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
import { SHADOW_READY_BUDGETS, SHADOW_READY_TIMEOUT_MS } from "./useShadowPreviewReload";
|
|
10
|
+
import { usePlayerStore } from "../store/playerStore";
|
|
11
|
+
import {
|
|
12
|
+
makeAdapterWindow,
|
|
13
|
+
makeFakeIframe,
|
|
14
|
+
renderTimelinePlayerHarness,
|
|
15
|
+
resetPlayerStore,
|
|
16
|
+
} from "./timelinePlayerTestHarness";
|
|
17
|
+
|
|
18
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
vi.mock("../../utils/gsapSoftReload", async (importOriginal) => ({
|
|
21
|
+
...(await importOriginal<typeof import("../../utils/gsapSoftReload")>()),
|
|
22
|
+
ensureMotionPathPluginLoaded: vi.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
vi.restoreAllMocks();
|
|
28
|
+
document.body.innerHTML = "";
|
|
29
|
+
resetPlayerStore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const unmount = (root: ReturnType<typeof createRoot>) => act(() => root.unmount());
|
|
33
|
+
|
|
34
|
+
/** A loaded live preview at 3 s, and a reload asked for with `hold` as the host's still. */
|
|
35
|
+
async function reloadWithStill(
|
|
36
|
+
hold: (live: HTMLIFrameElement) => Promise<(() => void) | null>,
|
|
37
|
+
{ playing = false } = {},
|
|
38
|
+
) {
|
|
39
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: hold });
|
|
40
|
+
const { adapter, win } = makeAdapterWindow();
|
|
41
|
+
adapter.getTime = vi.fn(() => 3);
|
|
42
|
+
const live = makeFakeIframe(win);
|
|
43
|
+
act(() => {
|
|
44
|
+
harness.getApi().iframeRef.current = live;
|
|
45
|
+
harness.getApi().onIframeLoad();
|
|
46
|
+
});
|
|
47
|
+
if (playing) act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
48
|
+
await act(async () => {
|
|
49
|
+
harness.getApi().refreshPlayer();
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
});
|
|
52
|
+
return { ...harness, live, liveAdapter: adapter };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe("a reload behind the host's still", () => {
|
|
56
|
+
it("drops the live page before the reload's page loads, and the still once the new page shows the live time", async () => {
|
|
57
|
+
const release = vi.fn();
|
|
58
|
+
const hold = vi.fn(async () => release);
|
|
59
|
+
const { getApi, root, live } = await reloadWithStill(hold);
|
|
60
|
+
|
|
61
|
+
expect(hold).toHaveBeenCalledWith(live);
|
|
62
|
+
const slots = getApi().previewSlots;
|
|
63
|
+
expect(slots.map((slot) => slot.role)).toEqual(["shadow"]);
|
|
64
|
+
expect(release).not.toHaveBeenCalled();
|
|
65
|
+
|
|
66
|
+
const { adapter, win } = makeAdapterWindow();
|
|
67
|
+
adapter.seek = vi.fn(adapter.seek);
|
|
68
|
+
const next = makeFakeIframe(win);
|
|
69
|
+
const gen = slots[0]!.gen;
|
|
70
|
+
act(() => {
|
|
71
|
+
getApi().setShadowIframeNode(next);
|
|
72
|
+
getApi().onShadowIframeLoad(gen);
|
|
73
|
+
getApi().onShadowReadyChange(gen, true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(getApi().previewSlots).toEqual([{ gen, role: "live", url: slots[0]!.url }]);
|
|
77
|
+
expect(getApi().iframeRef.current).toBe(next);
|
|
78
|
+
expect(adapter.seek).toHaveBeenCalledWith(3);
|
|
79
|
+
await vi.waitFor(() => expect(release).toHaveBeenCalledTimes(1));
|
|
80
|
+
unmount(root);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("resumes a playing preview from where the still was taken", async () => {
|
|
84
|
+
const { getApi, root } = await reloadWithStill(async () => () => {}, { playing: true });
|
|
85
|
+
const gen = getApi().previewSlots[0]!.gen;
|
|
86
|
+
const { adapter, win } = makeAdapterWindow();
|
|
87
|
+
adapter.getDuration = vi.fn(() => 10);
|
|
88
|
+
adapter.seek = vi.fn(adapter.seek);
|
|
89
|
+
adapter.play = vi.fn(adapter.play);
|
|
90
|
+
act(() => {
|
|
91
|
+
getApi().setShadowIframeNode(makeFakeIframe(win));
|
|
92
|
+
getApi().onShadowIframeLoad(gen);
|
|
93
|
+
getApi().onShadowReadyChange(gen, true);
|
|
94
|
+
});
|
|
95
|
+
expect(adapter.seek).toHaveBeenCalledWith(3);
|
|
96
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
97
|
+
unmount(root);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("brings the live page back at its time when the reload gives up, and drops the still once it loads", async () => {
|
|
101
|
+
vi.useFakeTimers();
|
|
102
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
103
|
+
const release = vi.fn();
|
|
104
|
+
const onPreviewReloadFailed = vi.fn();
|
|
105
|
+
const harness = renderTimelinePlayerHarness({
|
|
106
|
+
holdPreviewStill: async () => release,
|
|
107
|
+
onPreviewReloadFailed,
|
|
108
|
+
});
|
|
109
|
+
const { adapter, win } = makeAdapterWindow();
|
|
110
|
+
adapter.getTime = vi.fn(() => 3);
|
|
111
|
+
const live = makeFakeIframe(win);
|
|
112
|
+
act(() => {
|
|
113
|
+
harness.getApi().iframeRef.current = live;
|
|
114
|
+
harness.getApi().onIframeLoad();
|
|
115
|
+
});
|
|
116
|
+
await act(async () => {
|
|
117
|
+
harness.getApi().refreshPlayer();
|
|
118
|
+
await Promise.resolve();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS * SHADOW_READY_BUDGETS));
|
|
122
|
+
expect(onPreviewReloadFailed).toHaveBeenCalledWith(expect.stringContaining("too long"));
|
|
123
|
+
expect(harness.getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);
|
|
124
|
+
expect(release).not.toHaveBeenCalled();
|
|
125
|
+
|
|
126
|
+
// The live slot mounts again and loads at once, as a cached page does: that load drops the still.
|
|
127
|
+
act(() => {
|
|
128
|
+
harness.getApi().iframeRef.current = makeFakeIframe(makeAdapterWindow().win);
|
|
129
|
+
harness.getApi().onIframeLoad();
|
|
130
|
+
vi.advanceTimersByTime(3_000);
|
|
131
|
+
});
|
|
132
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
133
|
+
unmount(harness.root);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("drops a still kept for a give-up even if the live page never loads again", async () => {
|
|
137
|
+
vi.useFakeTimers();
|
|
138
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
139
|
+
const release = vi.fn();
|
|
140
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: async () => release });
|
|
141
|
+
act(() => {
|
|
142
|
+
harness.getApi().iframeRef.current = makeFakeIframe(makeAdapterWindow().win);
|
|
143
|
+
harness.getApi().onIframeLoad();
|
|
144
|
+
});
|
|
145
|
+
await act(async () => {
|
|
146
|
+
harness.getApi().refreshPlayer();
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
});
|
|
149
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS * SHADOW_READY_BUDGETS));
|
|
150
|
+
expect(release).not.toHaveBeenCalled();
|
|
151
|
+
act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS));
|
|
152
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
153
|
+
unmount(harness.root);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("drops a still that answers after the composition switched, and starts no reload for the old one", async () => {
|
|
157
|
+
let answer: (release: () => void) => void = () => {};
|
|
158
|
+
const release = vi.fn();
|
|
159
|
+
const harness = renderTimelinePlayerHarness({
|
|
160
|
+
holdPreviewStill: () => new Promise((resolve) => (answer = resolve)),
|
|
161
|
+
});
|
|
162
|
+
const live = makeFakeIframe(makeAdapterWindow().win);
|
|
163
|
+
act(() => {
|
|
164
|
+
harness.getApi().iframeRef.current = live;
|
|
165
|
+
harness.getApi().onIframeLoad();
|
|
166
|
+
});
|
|
167
|
+
act(() => harness.getApi().refreshPlayer());
|
|
168
|
+
act(() => harness.getApi().resetPreviewSlots());
|
|
169
|
+
await act(async () => {
|
|
170
|
+
answer(release);
|
|
171
|
+
await Promise.resolve();
|
|
172
|
+
});
|
|
173
|
+
expect(release).toHaveBeenCalledTimes(1);
|
|
174
|
+
expect(harness.getApi().previewSlots).toEqual([{ gen: 0, role: "live" }]);
|
|
175
|
+
unmount(harness.root);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("keeps both pages for a reload when the host has no still to show, and a playing preview plays on", async () => {
|
|
179
|
+
const harness = renderTimelinePlayerHarness({ holdPreviewStill: async () => null });
|
|
180
|
+
const { adapter, win } = makeAdapterWindow();
|
|
181
|
+
adapter.play = vi.fn(adapter.play);
|
|
182
|
+
act(() => {
|
|
183
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
184
|
+
harness.getApi().onIframeLoad();
|
|
185
|
+
});
|
|
186
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
187
|
+
await act(async () => {
|
|
188
|
+
harness.getApi().refreshPlayer();
|
|
189
|
+
await Promise.resolve();
|
|
190
|
+
});
|
|
191
|
+
expect(harness.getApi().previewSlots.map((slot) => slot.role)).toEqual(["live", "shadow"]);
|
|
192
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
193
|
+
unmount(harness.root);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("a host that throws while taking the still keeps both pages and a playing preview plays on", async () => {
|
|
197
|
+
const harness = renderTimelinePlayerHarness({
|
|
198
|
+
holdPreviewStill: () => {
|
|
199
|
+
throw new Error("capture unavailable");
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const { adapter, win } = makeAdapterWindow();
|
|
203
|
+
adapter.play = vi.fn(adapter.play);
|
|
204
|
+
act(() => {
|
|
205
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
206
|
+
harness.getApi().onIframeLoad();
|
|
207
|
+
});
|
|
208
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
209
|
+
await act(async () => {
|
|
210
|
+
expect(() => harness.getApi().refreshPlayer()).not.toThrow();
|
|
211
|
+
await Promise.resolve();
|
|
212
|
+
await Promise.resolve();
|
|
213
|
+
});
|
|
214
|
+
expect(harness.getApi().previewSlots.map((slot) => slot.role)).toEqual(["live", "shadow"]);
|
|
215
|
+
expect(adapter.play).toHaveBeenCalled();
|
|
216
|
+
unmount(harness.root);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("pauses a playing preview before the still is taken, so the reload resumes from the frame it shows", async () => {
|
|
220
|
+
const order: string[] = [];
|
|
221
|
+
const harness = renderTimelinePlayerHarness({
|
|
222
|
+
holdPreviewStill: async () => {
|
|
223
|
+
order.push("still");
|
|
224
|
+
return () => {};
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
const { adapter, win } = makeAdapterWindow();
|
|
228
|
+
act(() => {
|
|
229
|
+
harness.getApi().iframeRef.current = makeFakeIframe(win);
|
|
230
|
+
harness.getApi().onIframeLoad();
|
|
231
|
+
});
|
|
232
|
+
act(() => usePlayerStore.getState().setIsPlaying(true));
|
|
233
|
+
adapter.pause = vi.fn(() => void order.push("pause"));
|
|
234
|
+
await act(async () => {
|
|
235
|
+
harness.getApi().refreshPlayer();
|
|
236
|
+
await Promise.resolve();
|
|
237
|
+
});
|
|
238
|
+
expect(order).toEqual(["pause", "still"]);
|
|
239
|
+
unmount(harness.root);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -87,6 +87,7 @@ describe("useTimelinePlayer seek hydration", () => {
|
|
|
87
87
|
window.dispatchEvent(
|
|
88
88
|
new MessageEvent("message", {
|
|
89
89
|
source: iframeWindow,
|
|
90
|
+
origin: window.location.origin,
|
|
90
91
|
data: {
|
|
91
92
|
source: "hf-preview",
|
|
92
93
|
type: "timeline",
|
|
@@ -164,6 +165,7 @@ describe("useTimelinePlayer seek hydration", () => {
|
|
|
164
165
|
window.dispatchEvent(
|
|
165
166
|
new MessageEvent("message", {
|
|
166
167
|
source: iframeWindow as unknown as Window,
|
|
168
|
+
origin: window.location.origin,
|
|
167
169
|
data: { source: "hf-preview", type: "state", protocolVersion: 999 },
|
|
168
170
|
}),
|
|
169
171
|
);
|
|
@@ -174,6 +176,7 @@ describe("useTimelinePlayer seek hydration", () => {
|
|
|
174
176
|
window.dispatchEvent(
|
|
175
177
|
new MessageEvent("message", {
|
|
176
178
|
source: iframeWindow as unknown as Window,
|
|
179
|
+
origin: window.location.origin,
|
|
177
180
|
data: { source: "hf-preview", type: "state" },
|
|
178
181
|
}),
|
|
179
182
|
);
|
|
@@ -51,6 +51,7 @@ export interface UseTimelinePlayerOptions {
|
|
|
51
51
|
onShadowPromoted?: () => void;
|
|
52
52
|
/** A reload was abandoned (cause in the message); the previous preview is still showing. */
|
|
53
53
|
onPreviewReloadFailed?: (message: string) => void;
|
|
54
|
+
holdPreviewStill?: (live: HTMLIFrameElement) => Promise<(() => void) | null>;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
const publishSeek = (time: number, options?: { follow?: boolean }) =>
|
|
@@ -60,6 +61,7 @@ const publishSeek = (time: number, options?: { follow?: boolean }) =>
|
|
|
60
61
|
export function useTimelinePlayer({
|
|
61
62
|
onShadowPromoted,
|
|
62
63
|
onPreviewReloadFailed,
|
|
64
|
+
holdPreviewStill,
|
|
63
65
|
}: UseTimelinePlayerOptions = {}) {
|
|
64
66
|
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
65
67
|
const rafRef = useRef<number>(0);
|
|
@@ -420,6 +422,7 @@ export function useTimelinePlayer({
|
|
|
420
422
|
beginShadowReload,
|
|
421
423
|
resetPreviewSlots,
|
|
422
424
|
previewGeneration,
|
|
425
|
+
onLiveLoaded,
|
|
423
426
|
} = useShadowPreviewReload({
|
|
424
427
|
iframeRef,
|
|
425
428
|
getAdapter,
|
|
@@ -434,6 +437,7 @@ export function useTimelinePlayer({
|
|
|
434
437
|
applyPreviewAudioState,
|
|
435
438
|
onPromoted: onShadowPromoted,
|
|
436
439
|
onReloadFailed: onPreviewReloadFailed,
|
|
440
|
+
holdStill: holdPreviewStill,
|
|
437
441
|
handOverPlayback: (time, playing) => {
|
|
438
442
|
// keepPlaying: move the playhead without the paused-seek audio scrub.
|
|
439
443
|
seek(time, { keepPlaying: true, follow: false });
|
|
@@ -566,13 +570,21 @@ export function useTimelinePlayer({
|
|
|
566
570
|
});
|
|
567
571
|
}, [applyPlaybackRate, applyPreviewAudioState]);
|
|
568
572
|
|
|
573
|
+
const onLiveIframeLoad = useCallback(
|
|
574
|
+
(context?: number) => {
|
|
575
|
+
onIframeLoad(context);
|
|
576
|
+
onLiveLoaded();
|
|
577
|
+
},
|
|
578
|
+
[onIframeLoad, onLiveLoaded],
|
|
579
|
+
);
|
|
580
|
+
|
|
569
581
|
return {
|
|
570
582
|
iframeRef,
|
|
571
583
|
play,
|
|
572
584
|
pause,
|
|
573
585
|
togglePlay,
|
|
574
586
|
seek,
|
|
575
|
-
onIframeLoad,
|
|
587
|
+
onIframeLoad: onLiveIframeLoad,
|
|
576
588
|
refreshPlayer,
|
|
577
589
|
saveSeekPosition,
|
|
578
590
|
resetPlayer,
|
|
@@ -111,6 +111,10 @@ export function planShadowReload(
|
|
|
111
111
|
return live ? [live, { gen: nextGen, role: "shadow", url }] : [{ gen: nextGen, role: "live" }];
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
export function planShadowAlone(nextGen: number, url: string): PreviewIframeSlot[] {
|
|
115
|
+
return [{ gen: nextGen, role: "shadow", url }];
|
|
116
|
+
}
|
|
117
|
+
|
|
114
118
|
/** Drop any pending shadow; the live slot (and its key) is untouched. */
|
|
115
119
|
export function planShadowDiscard(slots: PreviewIframeSlot[]): PreviewIframeSlot[] {
|
|
116
120
|
return slots.filter((slot) => slot.role === "live");
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// because a runtime posts its first `timeline` while it boots.
|
|
4
4
|
import type { PlaybackAdapter } from "./playbackTypes";
|
|
5
5
|
import { inspectStudioRuntimeMessage, postRuntimeControlMessage } from "./runtimeProtocol";
|
|
6
|
+
import { previewFrameOpaque } from "./previewChannel";
|
|
6
7
|
|
|
7
8
|
interface PlaybackMirror {
|
|
8
9
|
iframe: HTMLIFrameElement;
|
|
@@ -56,10 +57,15 @@ export function previewStageSize(
|
|
|
56
57
|
return (frame && mirrors.get(frame)?.stageSize) ?? null;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/** The origins a post from this frame can carry
|
|
60
|
+
/** The origins a post from this frame can carry; a page its server sandboxed posts as `null` without the attribute. */
|
|
60
61
|
export function frameOrigins(iframe: HTMLIFrameElement): string[] {
|
|
61
62
|
const sandbox = iframe.getAttribute("sandbox")?.toLowerCase().split(/\s+/);
|
|
62
63
|
if (sandbox && !sandbox.includes("allow-same-origin")) return ["null"];
|
|
64
|
+
const loaded = loadedOrigins(iframe);
|
|
65
|
+
return previewFrameOpaque(iframe) && !loaded.includes("null") ? [...loaded, "null"] : loaded;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function loadedOrigins(iframe: HTMLIFrameElement): string[] {
|
|
63
69
|
const src = iframe.getAttribute("src");
|
|
64
70
|
if (iframe.hasAttribute("srcdoc") || !src) return [window.location.origin];
|
|
65
71
|
try {
|
|
@@ -219,6 +219,19 @@ describe("bridge playback for a frame Studio cannot script", () => {
|
|
|
219
219
|
expect(own.getTime()).toBe(5);
|
|
220
220
|
});
|
|
221
221
|
|
|
222
|
+
it("accepts a frame its server sandboxed, which posts as null though its frame has no sandbox", () => {
|
|
223
|
+
const { iframe, frame } = opaqueFrame();
|
|
224
|
+
iframe.removeAttribute("sandbox");
|
|
225
|
+
iframe.setAttribute("src", "/api/projects/demo/preview");
|
|
226
|
+
watchPreviewFrame(iframe);
|
|
227
|
+
const adapter = bridgePlaybackAdapter(iframe)!;
|
|
228
|
+
fromFrame(frame, { type: "state", currentTime: 6, isPlaying: false }, "https://example.com");
|
|
229
|
+
fromFrame({}, { type: "state", currentTime: 7, isPlaying: false }, "null");
|
|
230
|
+
expect(adapter.getTime()).toBe(0);
|
|
231
|
+
fromFrame(frame, { type: "state", currentTime: 6, isPlaying: false }, "null");
|
|
232
|
+
expect(adapter.getTime()).toBe(6);
|
|
233
|
+
});
|
|
234
|
+
|
|
222
235
|
it.each([
|
|
223
236
|
["srcdoc", (f: HTMLIFrameElement) => f.setAttribute("srcdoc", "<p>x</p>"), location.origin],
|
|
224
237
|
[
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as studio from "@hyperframes/studio";
|
|
3
|
+
import * as elements from "./player/lib/previewElements";
|
|
4
|
+
import * as selection from "./components/editor/previewSelection";
|
|
5
|
+
|
|
6
|
+
it("exports a sealed preview's checked element reads and stand-ins as the ones Studio uses", () => {
|
|
7
|
+
expect(studio.describePreviewElements).toBe(elements.describePreviewElements);
|
|
8
|
+
expect(studio.previewAncestors).toBe(elements.previewAncestors);
|
|
9
|
+
expect(studio.previewElementsAtPoint).toBe(elements.previewElementsAtPoint);
|
|
10
|
+
expect(studio.previewGeometry).toBe(elements.previewGeometry);
|
|
11
|
+
expect(studio.previewLayers).toBe(elements.previewLayers);
|
|
12
|
+
expect(studio.previewPointerTargets).toBe(elements.previewPointerTargets);
|
|
13
|
+
expect(studio.queryPreviewElements).toBe(elements.queryPreviewElements);
|
|
14
|
+
expect(studio.findPreviewElementForSelection).toBe(selection.findPreviewElementForSelection);
|
|
15
|
+
expect(studio.findPreviewElementForTimelineElement).toBe(
|
|
16
|
+
selection.findPreviewElementForTimelineElement,
|
|
17
|
+
);
|
|
18
|
+
expect(studio.readable).toBe(selection.readable);
|
|
19
|
+
expect(studio.standInFor).toBe(selection.standInFor);
|
|
20
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { createStudioApi } from "@hyperframes/studio-server";
|
|
1
2
|
import { IDBFactory } from "fake-indexeddb";
|
|
3
|
+
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
2
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
7
|
import {
|
|
4
8
|
createMemoryExternalConflictStorage,
|
|
@@ -9,6 +13,27 @@ import {
|
|
|
9
13
|
} from "./externalConflictStorage";
|
|
10
14
|
import { StudioFileConflictError } from "./studioSaveDiagnostics";
|
|
11
15
|
|
|
16
|
+
const made: string[] = [];
|
|
17
|
+
|
|
18
|
+
/** Studio's real API for one project, "demo", answering the store's fetches. */
|
|
19
|
+
function serveProject(): string {
|
|
20
|
+
const dir = mkdtempSync(join(tmpdir(), "hf-drafts-"));
|
|
21
|
+
made.push(dir);
|
|
22
|
+
const api = createStudioApi({
|
|
23
|
+
listProjects: () => [],
|
|
24
|
+
resolveProject: async (id: string) => (id === "demo" ? { id, dir, title: "Demo" } : null),
|
|
25
|
+
bundle: async () => null,
|
|
26
|
+
lint: async () => ({ findings: [] }),
|
|
27
|
+
runtimeUrl: "/api/runtime.js",
|
|
28
|
+
rendersDir: () => join(dir, "renders"),
|
|
29
|
+
startRender: () => ({ id: "job", status: "rendering", progress: 0, outputPath: "" }),
|
|
30
|
+
});
|
|
31
|
+
vi.stubGlobal("fetch", (input: string, init?: RequestInit) =>
|
|
32
|
+
api.fetch(new Request(`http://localhost${input.replace(/^\/api/, "")}`, init)),
|
|
33
|
+
);
|
|
34
|
+
return dir;
|
|
35
|
+
}
|
|
36
|
+
|
|
12
37
|
describe("external conflict snapshots", () => {
|
|
13
38
|
beforeEach(() => {
|
|
14
39
|
vi.stubGlobal("indexedDB", new IDBFactory());
|
|
@@ -17,6 +42,7 @@ describe("external conflict snapshots", () => {
|
|
|
17
42
|
afterEach(() => {
|
|
18
43
|
vi.restoreAllMocks();
|
|
19
44
|
vi.unstubAllGlobals();
|
|
45
|
+
for (const dir of made.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
20
46
|
});
|
|
21
47
|
|
|
22
48
|
it("durably records both complete file versions before resolution", async () => {
|
|
@@ -54,8 +80,8 @@ describe("external conflict snapshots", () => {
|
|
|
54
80
|
expect(await storage.get("project-a", "index.html")).toEqual(snapshot);
|
|
55
81
|
});
|
|
56
82
|
|
|
57
|
-
it("persists, loads, and deletes a
|
|
58
|
-
|
|
83
|
+
it("persists, loads, and deletes a draft through the project's own server", async () => {
|
|
84
|
+
const project = serveProject();
|
|
59
85
|
const conflict = new StudioFileConflictError({
|
|
60
86
|
filePath: "index.html",
|
|
61
87
|
currentVersion: "v2",
|
|
@@ -63,24 +89,50 @@ describe("external conflict snapshots", () => {
|
|
|
63
89
|
attemptedContent: "studio full file",
|
|
64
90
|
});
|
|
65
91
|
|
|
66
|
-
await persistExternalConflictSnapshot("
|
|
67
|
-
|
|
92
|
+
await persistExternalConflictSnapshot("demo", conflict);
|
|
93
|
+
expect(readdirSync(join(project, ".hyperframes", "recovery"))).toHaveLength(1);
|
|
94
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toMatchObject({
|
|
68
95
|
kind: "conflict",
|
|
69
|
-
projectId: "
|
|
96
|
+
projectId: "demo",
|
|
70
97
|
filePath: "index.html",
|
|
71
98
|
externalVersion: "v2",
|
|
72
99
|
externalContent: "external full file",
|
|
73
100
|
studioContent: "studio full file",
|
|
74
|
-
createdAt: 1234,
|
|
75
101
|
});
|
|
76
|
-
await deleteExternalConflictSnapshot("
|
|
77
|
-
await expect(
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
await deleteExternalConflictSnapshot("demo", "index.html");
|
|
103
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toBeNull();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Every project previewed on a port shares the origin's IndexedDB, and so does each one's composition code.
|
|
107
|
+
it("never offers a draft another project's code planted in the browser's shared IndexedDB", async () => {
|
|
108
|
+
serveProject();
|
|
109
|
+
const open = indexedDB.open("hyperframes-studio-external-conflicts", 1);
|
|
110
|
+
open.onupgradeneeded = () => open.result.createObjectStore("file-conflicts");
|
|
111
|
+
const db = await new Promise<IDBDatabase>(
|
|
112
|
+
(resolve) => (open.onsuccess = () => resolve(open.result)),
|
|
113
|
+
);
|
|
114
|
+
const planted = db.transaction("file-conflicts", "readwrite");
|
|
115
|
+
planted.objectStore("file-conflicts").put(
|
|
116
|
+
{
|
|
117
|
+
kind: "failed",
|
|
118
|
+
projectId: "demo",
|
|
119
|
+
filePath: "index.html",
|
|
120
|
+
externalVersion: null,
|
|
121
|
+
externalContent: null,
|
|
122
|
+
studioContent: "<script>planted</script>",
|
|
123
|
+
failureMessage: "Recovered draft",
|
|
124
|
+
createdAt: Date.now(),
|
|
125
|
+
},
|
|
126
|
+
"demo\0index.html",
|
|
127
|
+
);
|
|
128
|
+
await new Promise((resolve) => (planted.oncomplete = resolve));
|
|
129
|
+
db.close();
|
|
130
|
+
|
|
131
|
+
await expect(loadExternalConflictSnapshot("demo", "index.html")).resolves.toBeNull();
|
|
80
132
|
});
|
|
81
133
|
|
|
82
|
-
it("rejects persistence when
|
|
83
|
-
vi.stubGlobal("
|
|
134
|
+
it("rejects persistence when the server cannot keep the draft", async () => {
|
|
135
|
+
vi.stubGlobal("fetch", async () => new Response("{}", { status: 500 }));
|
|
84
136
|
const conflict = new StudioFileConflictError({
|
|
85
137
|
filePath: "index.html",
|
|
86
138
|
currentVersion: "v2",
|
|
@@ -88,8 +140,8 @@ describe("external conflict snapshots", () => {
|
|
|
88
140
|
attemptedContent: "studio",
|
|
89
141
|
});
|
|
90
142
|
|
|
91
|
-
await expect(persistExternalConflictSnapshot("
|
|
92
|
-
"
|
|
143
|
+
await expect(persistExternalConflictSnapshot("demo", conflict)).rejects.toThrow(
|
|
144
|
+
"Recovery draft storage failed (500)",
|
|
93
145
|
);
|
|
94
146
|
});
|
|
95
147
|
});
|