@hyperframes/studio 0.9.65 → 0.9.67
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-DHYu0XuV.js +573 -0
- package/dist/assets/{index-tvLrzMBv.js → index-BBKHfua5.js} +180 -180
- package/dist/assets/{index-CAjz3b83.js → index-DqND4rHq.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-xC5IGkfB.js → pausedVideoDecoder-B1FNXBMe.js} +1 -1
- package/dist/{chunk-VDDEXNVX.js → chunk-LR3VT3EF.js} +20 -0
- package/dist/index.html +1 -1
- package/dist/index.js +396 -160
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
- package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
- package/src/components/editor/domEditOverlayCrop.ts +78 -15
- package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
- package/src/components/editor/gsapLivePreview.sealed.test.ts +35 -0
- package/src/components/editor/gsapLivePreview.ts +6 -2
- package/src/components/editor/gsapMoveSealedPreview.test.ts +3 -23
- package/src/components/editor/previewDrafts.test.ts +13 -39
- package/src/components/editor/previewDrafts.ts +2 -0
- package/src/components/editor/previewGestureStartRead.test.ts +59 -21
- package/src/components/editor/previewGestureStartRead.ts +9 -0
- package/src/components/editor/previewLayers.test.ts +3 -20
- package/src/components/editor/previewOverlayRects.test.ts +3 -20
- package/src/components/editor/previewPointerTargets.test.ts +3 -20
- package/src/components/editor/previewSelection.test.ts +51 -35
- package/src/components/editor/previewSelection.ts +17 -0
- package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
- package/src/components/editor/useMotionPathData.sealed.test.ts +2 -29
- package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
- package/src/components/nle/NLEContext.tsx +21 -23
- package/src/components/nle/NLEPreview.test.ts +18 -3
- package/src/components/nle/NLEPreview.tsx +10 -1
- package/src/components/nle/audioSealedPreview.test.ts +5 -32
- package/src/hooks/appHotkeysDispatch.ts +38 -1
- package/src/hooks/domEditCommits.sealed.test.ts +191 -0
- package/src/hooks/domStyleCommit.ts +18 -7
- package/src/hooks/gsapMutationClient.test.ts +32 -0
- package/src/hooks/gsapMutationClient.ts +6 -3
- package/src/hooks/gsapResizeIntercept.ts +7 -2
- package/src/hooks/timelineTimingSync.test.ts +1 -1
- package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
- package/src/hooks/useAppHotkeys.ts +36 -1
- package/src/hooks/useDomEditAttributeCommits.ts +43 -19
- package/src/hooks/useEnableKeyframes.sealed.test.ts +2 -29
- package/src/hooks/useFreezeFrame.test.ts +3 -2
- package/src/hooks/useFreezeFrame.ts +2 -2
- package/src/hooks/useGroupCommits.ts +7 -2
- package/src/hooks/useSlideshowTabState.test.ts +47 -3
- package/src/hooks/useSlideshowTabState.ts +32 -16
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
- package/src/player/hooks/usePreviewFirstFrameTelemetry.sealed.test.ts +43 -0
- package/src/player/hooks/usePreviewFirstFrameTelemetry.ts +11 -7
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +39 -31
- package/src/player/hooks/useTimelineSyncCallbacks.ts +21 -11
- package/src/player/lib/previewChannel.test.ts +10 -0
- package/src/player/lib/previewChannel.ts +21 -0
- package/src/player/lib/previewElements.test.ts +34 -1
- package/src/player/lib/previewElements.ts +99 -16
- package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
- package/src/player/lib/timelineIframeHelpers.ts +1 -1
- package/src/utils/blockInstaller.test.ts +82 -48
- package/src/utils/blockInstaller.ts +6 -14
- package/src/utils/previewCompositionSize.test.ts +61 -0
- package/src/utils/previewCompositionSize.ts +21 -1
- package/src/utils/studioSaveDiagnostics.ts +2 -0
- package/dist/assets/hyperframes-player-Dscc6yHD.js +0 -573
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from "../utils/elementGsap";
|
|
20
20
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
21
21
|
import { readGsapProperty } from "./gsapRuntimeReaders";
|
|
22
|
+
import { gestureStartLayout } from "../components/editor/previewGestureStartRead";
|
|
22
23
|
import {
|
|
23
24
|
commitStaticGsapPosition,
|
|
24
25
|
commitStaticGsapSize,
|
|
@@ -321,8 +322,12 @@ export async function tryGsapResizeIntercept(
|
|
|
321
322
|
// sent almost every element to the fallback below: a 630px chip scaled by
|
|
322
323
|
// 630/200, landing over three times the size it was dropped at, and worse
|
|
323
324
|
// on the next drag because the wrong scale then counted as its live one.
|
|
324
|
-
|
|
325
|
-
const
|
|
325
|
+
// A sealed preview has no element here: its gesture started from the box the frame measured.
|
|
326
|
+
const started = selection.handle ? gestureStartLayout(selection.handle) : null;
|
|
327
|
+
const cssW =
|
|
328
|
+
originalBoxSize(el, STUDIO_ORIGINAL_BOX_WIDTH_ATTR, "width") ?? (started?.width || 200);
|
|
329
|
+
const cssH =
|
|
330
|
+
originalBoxSize(el, STUDIO_ORIGINAL_BOX_HEIGHT_ATTR, "height") ?? (started?.height || cssW);
|
|
326
331
|
// `size` is the draft's CSS box; on screen it is multiplied by the element's
|
|
327
332
|
// LIVE scale (the draft divides the cursor delta by it — see
|
|
328
333
|
// resolveDomEditResizeGesture). The committed keyframe REPLACES that live
|
|
@@ -778,7 +778,7 @@ describe("foldGsapMutationIntoHistory — owned GSAP transaction", () => {
|
|
|
778
778
|
expect(reloadPreview).toHaveBeenCalledTimes(1);
|
|
779
779
|
expect(consoleError).toHaveBeenCalledWith(
|
|
780
780
|
expect.stringContaining("GSAP"),
|
|
781
|
-
expect.objectContaining({ message: "Failed to restore index.html" }),
|
|
781
|
+
expect.objectContaining({ message: "Failed to restore index.html (503)" }),
|
|
782
782
|
);
|
|
783
783
|
});
|
|
784
784
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
3
4
|
import React, { act, useRef } from "react";
|
|
4
5
|
import type { Root } from "react-dom/client";
|
|
5
6
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
@@ -8,6 +9,14 @@ import { usePlayerStore } from "../player/store/playerStore";
|
|
|
8
9
|
import { useAppHotkeys } from "./useAppHotkeys";
|
|
9
10
|
import { mountReactHarness } from "./domSelectionTestHarness";
|
|
10
11
|
import { trackStudioEvent } from "../utils/studioTelemetry";
|
|
12
|
+
import { APP_HOTKEY_ACTIONS } from "./appHotkeysDispatch";
|
|
13
|
+
import { PLAYBACK_ACTIONS } from "../player/hooks/usePlaybackKeyboard";
|
|
14
|
+
import { DEFAULT_STUDIO_KEYS } from "../player/components/studioShortcuts";
|
|
15
|
+
import {
|
|
16
|
+
detachedFakeIframe,
|
|
17
|
+
serveEditingRequests,
|
|
18
|
+
} from "../player/hooks/timelinePlayerTestHarness";
|
|
19
|
+
import { previewRequest } from "../player/lib/previewChannel";
|
|
11
20
|
|
|
12
21
|
vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
|
|
13
22
|
|
|
@@ -167,4 +176,129 @@ describe("preview iframe hotkey forwarding", () => {
|
|
|
167
176
|
expect(add).toHaveBeenCalled();
|
|
168
177
|
expect(remove.mock.calls).toEqual(add.mock.calls);
|
|
169
178
|
});
|
|
179
|
+
|
|
180
|
+
describe("a sealed preview", () => {
|
|
181
|
+
const closers: Array<() => void> = [];
|
|
182
|
+
afterEach(() => closers.splice(0).forEach((close) => close()));
|
|
183
|
+
|
|
184
|
+
// A frame whose document refuses Studio, reached only over the editing port it hands out per connect.
|
|
185
|
+
function sealedFrame(focus = { inPreview: true }) {
|
|
186
|
+
const frame: Record<string, unknown> = {};
|
|
187
|
+
const iframe = detachedFakeIframe(frame);
|
|
188
|
+
const hasFocus = vi.spyOn(document, "hasFocus").mockImplementation(() => focus.inPreview);
|
|
189
|
+
Object.defineProperty(document, "activeElement", {
|
|
190
|
+
configurable: true,
|
|
191
|
+
get: () => (focus.inPreview ? iframe : document.body),
|
|
192
|
+
});
|
|
193
|
+
closers.push(() => {
|
|
194
|
+
hasFocus.mockRestore();
|
|
195
|
+
delete (document as { activeElement?: unknown }).activeElement;
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
198
|
+
Object.defineProperty(frame, "document", {
|
|
199
|
+
get: () => {
|
|
200
|
+
throw new DOMException("blocked", "SecurityError");
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
const watched: string[][] = [];
|
|
204
|
+
const ports: MessagePort[] = [];
|
|
205
|
+
closers.push(
|
|
206
|
+
serveEditingRequests(
|
|
207
|
+
frame,
|
|
208
|
+
(kind, params) => {
|
|
209
|
+
if (kind === "max-z-index") return { zIndex: 7 };
|
|
210
|
+
if (kind !== "watch-keys") return null;
|
|
211
|
+
watched.push((params as { combos: string[] }).combos);
|
|
212
|
+
return { watching: watched.at(-1)!.length };
|
|
213
|
+
},
|
|
214
|
+
(port) => ports.push(port),
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
const keyDown = (key: string, code: string) =>
|
|
218
|
+
ports.at(-1)!.postMessage({
|
|
219
|
+
v: 1,
|
|
220
|
+
event: "key",
|
|
221
|
+
key: {
|
|
222
|
+
type: "keydown",
|
|
223
|
+
key,
|
|
224
|
+
code,
|
|
225
|
+
altKey: false,
|
|
226
|
+
ctrlKey: false,
|
|
227
|
+
metaKey: false,
|
|
228
|
+
shiftKey: false,
|
|
229
|
+
repeat: false,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
return { iframe, watched, ports, keyDown, hasFocus };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
it("leaves Studio's own reads of the preview answered while it forwards keys", async () => {
|
|
236
|
+
root = mountReactHarness(<Harness />);
|
|
237
|
+
const { iframe, watched } = sealedFrame();
|
|
238
|
+
let read: Promise<unknown> | undefined;
|
|
239
|
+
act(() => {
|
|
240
|
+
sync?.(iframe);
|
|
241
|
+
read = previewRequest(iframe, "max-z-index", {}, 1_000);
|
|
242
|
+
});
|
|
243
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
244
|
+
await expect(read).resolves.toEqual({ zIndex: 7 });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("deletes the selection on a Delete pressed inside the preview", async () => {
|
|
248
|
+
root = mountReactHarness(<Harness />);
|
|
249
|
+
const { iframe, watched, keyDown } = sealedFrame();
|
|
250
|
+
act(() => sync?.(iframe));
|
|
251
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
252
|
+
expect(new Set(watched[0])).toEqual(
|
|
253
|
+
new Set(APP_HOTKEY_ACTIONS.map((action) => DEFAULT_STUDIO_KEYS[action])),
|
|
254
|
+
);
|
|
255
|
+
keyDown("Delete", "Delete");
|
|
256
|
+
await vi.waitFor(() => expect(domDelete).toHaveBeenCalledTimes(1));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("ignores a key the preview reports while the person is not in the preview", async () => {
|
|
260
|
+
root = mountReactHarness(<Harness />);
|
|
261
|
+
const focus = { inPreview: false };
|
|
262
|
+
const { iframe, watched, keyDown, hasFocus } = sealedFrame(focus);
|
|
263
|
+
act(() => sync?.(iframe));
|
|
264
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
265
|
+
keyDown("Delete", "Delete");
|
|
266
|
+
await vi.waitFor(() => expect(hasFocus).toHaveBeenCalledTimes(1));
|
|
267
|
+
focus.inPreview = true;
|
|
268
|
+
keyDown("Delete", "Delete");
|
|
269
|
+
await vi.waitFor(() => expect(domDelete).toHaveBeenCalledTimes(1));
|
|
270
|
+
expect(hasFocus).toHaveBeenCalledTimes(2);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("stops watching on the preview's next load, from a new port", async () => {
|
|
274
|
+
root = mountReactHarness(<Harness />);
|
|
275
|
+
const { iframe, watched, ports } = sealedFrame();
|
|
276
|
+
act(() => sync?.(iframe));
|
|
277
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
278
|
+
act(() => sync?.(iframe));
|
|
279
|
+
await vi.waitFor(() => expect(watched).toHaveLength(3));
|
|
280
|
+
expect(watched.slice(1)).toContainEqual([]);
|
|
281
|
+
expect(ports).toHaveLength(2);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("watches every action the app's key dispatchers answer, so none is dead in a sealed preview", () => {
|
|
285
|
+
const read = (file: string) => readFileSync(new URL(file, import.meta.url), "utf8");
|
|
286
|
+
const answered = new Set([
|
|
287
|
+
...[...read("./appHotkeysDispatch.ts").matchAll(/matchesKey\(\w+, "(\w+)"\)/g)].map(
|
|
288
|
+
(m) => m[1],
|
|
289
|
+
),
|
|
290
|
+
...[...read("./linkShortcuts.ts").matchAll(/\["(\w+)", "\w+"\]/g)].map((m) => m[1]),
|
|
291
|
+
]);
|
|
292
|
+
expect(answered.size).toBeGreaterThan(20);
|
|
293
|
+
expect(new Set(APP_HOTKEY_ACTIONS)).toEqual(answered);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("watches no key the playback keys also watch, so the frame forwards each press once", () => {
|
|
297
|
+
const app = new Set(APP_HOTKEY_ACTIONS.map((action) => DEFAULT_STUDIO_KEYS[action]));
|
|
298
|
+
const shared = PLAYBACK_ACTIONS.map((action) => DEFAULT_STUDIO_KEYS[action]).filter((combo) =>
|
|
299
|
+
app.has(combo),
|
|
300
|
+
);
|
|
301
|
+
expect(shared).toEqual([]);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
170
304
|
});
|
|
@@ -8,13 +8,21 @@ import {
|
|
|
8
8
|
applyCaptionModelToIframe,
|
|
9
9
|
isCaptionPreviewVisible,
|
|
10
10
|
} from "../captions/components/CaptionOverlayUtils";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
APP_HOTKEY_ACTIONS,
|
|
13
|
+
type HotkeyCallbacks,
|
|
14
|
+
dispatchModifierKey,
|
|
15
|
+
dispatchPlainKey,
|
|
16
|
+
} from "./appHotkeysDispatch";
|
|
12
17
|
import {
|
|
13
18
|
useEditHistoryActions,
|
|
14
19
|
type EditHistoryHandle,
|
|
15
20
|
type UseEditHistoryActionsOptions,
|
|
16
21
|
} from "./useEditHistoryActions";
|
|
17
22
|
import { useStableHandlers } from "./useStableHandlers";
|
|
23
|
+
import { createEditingPortClient } from "@hyperframes/core/runtime/editing-port";
|
|
24
|
+
import { previewFrameOpaque } from "../player/lib/previewChannel";
|
|
25
|
+
import { getStudioKey, subscribeStudioKeys } from "../player/components/studioShortcuts";
|
|
18
26
|
|
|
19
27
|
function iframeContentWindow(iframe: HTMLIFrameElement | null): Window | null {
|
|
20
28
|
try {
|
|
@@ -24,6 +32,29 @@ function iframeContentWindow(iframe: HTMLIFrameElement | null): Window | null {
|
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
|
|
35
|
+
// A port of its own: watch-keys replaces a port's whole list, and playback watches its keys on the shared one.
|
|
36
|
+
function forwardSealedFrameKeys(iframe: HTMLIFrameElement, onKeyDown: (e: KeyboardEvent) => void) {
|
|
37
|
+
const client = createEditingPortClient({ iframe });
|
|
38
|
+
const watch = (combos: string[]) => void client.request("watch-keys", { combos }).catch(() => {});
|
|
39
|
+
const watchApp = () => watch(APP_HOTKEY_ACTIONS.map(getStudioKey));
|
|
40
|
+
watchApp();
|
|
41
|
+
const stopRebinds = subscribeStudioKeys(watchApp);
|
|
42
|
+
// The frame can report keys nobody pressed: act only while the person is in the preview.
|
|
43
|
+
const focused = () =>
|
|
44
|
+
iframe.ownerDocument.hasFocus() && iframe.ownerDocument.activeElement === iframe;
|
|
45
|
+
const stopKeys = client.onKey((key) => {
|
|
46
|
+
if (key.type === "keydown" && focused()) onKeyDown(new KeyboardEvent(key.type, key));
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
stopRebinds();
|
|
50
|
+
stopKeys();
|
|
51
|
+
void client
|
|
52
|
+
.request("watch-keys", { combos: [] })
|
|
53
|
+
.catch(() => {})
|
|
54
|
+
.finally(() => client.dispose());
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
function safeAddListener(t: EventTarget | null, type: string, h: EventListener, capture = false) {
|
|
28
59
|
try {
|
|
29
60
|
t?.addEventListener(type, h, capture);
|
|
@@ -247,6 +278,10 @@ export function useAppHotkeys({
|
|
|
247
278
|
(iframe: HTMLIFrameElement | null) => {
|
|
248
279
|
previewHistoryCleanupRef.current?.();
|
|
249
280
|
previewHistoryCleanupRef.current = null;
|
|
281
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
282
|
+
previewHistoryCleanupRef.current = forwardSealedFrameKeys(iframe, handleAppKeyDown);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
250
285
|
const win = iframeContentWindow(iframe);
|
|
251
286
|
if (!win) return;
|
|
252
287
|
const appHandler = handleAppKeyDown as EventListener;
|
|
@@ -14,6 +14,8 @@ import { bumpDomEditCommitMapVersion, runDomEditCommit } from "./domEditCommitRu
|
|
|
14
14
|
import { syncStoredAutomationFromPreview } from "../player/lib/automationStoreSync";
|
|
15
15
|
import { HF_AUDIO_GROUP_ATTR, HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
|
|
16
16
|
import { invalidateGroupInfoCache } from "../player/lib/timelineGroupInfo";
|
|
17
|
+
import { editSealedSelection } from "../components/editor/previewSelection";
|
|
18
|
+
import { afterSealedDraw, type PreviewElementEdit } from "../player/lib/previewElements";
|
|
17
19
|
|
|
18
20
|
// ── Types ──
|
|
19
21
|
|
|
@@ -161,6 +163,7 @@ export function useDomEditAttributeCommits({
|
|
|
161
163
|
const op: PatchOperation = { type: "attribute", property: attr, value };
|
|
162
164
|
let editedElement: HTMLElement | null = null;
|
|
163
165
|
let previousValue: string | null = null;
|
|
166
|
+
let sealedEdit: PreviewElementEdit | null = null;
|
|
164
167
|
|
|
165
168
|
await runDomEditCommit({
|
|
166
169
|
capture: () => {
|
|
@@ -175,20 +178,27 @@ export function useDomEditAttributeCommits({
|
|
|
175
178
|
previousValue = captured.previousValue;
|
|
176
179
|
},
|
|
177
180
|
apply: () => {
|
|
178
|
-
if (!editedElement) return;
|
|
179
181
|
const nextValue = value === null || value === "" ? null : value;
|
|
182
|
+
if (!editedElement) {
|
|
183
|
+
const attributes: Array<[string, string | null]> = [[fullAttr, nextValue]];
|
|
184
|
+
sealedEdit = editSealedSelection(iframe, domEditSelection, { attributes });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
180
187
|
setOrRemovePreviewAttribute(editedElement, fullAttr, nextValue);
|
|
181
188
|
},
|
|
182
189
|
persist: options.previewOnly
|
|
183
190
|
? async () => {}
|
|
184
191
|
: () =>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
afterSealedDraw(sealedEdit, (drawn) =>
|
|
193
|
+
persistDomEditOperations(domEditSelection, [op], {
|
|
194
|
+
label: options.label,
|
|
195
|
+
coalesceKey: commitKey,
|
|
196
|
+
skipRefresh: options.skipRefresh && drawn,
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
190
199
|
shouldRevert: () => isLatestCommit(),
|
|
191
200
|
revert: () => {
|
|
201
|
+
sealedEdit?.restore();
|
|
192
202
|
if (!editedElement) return;
|
|
193
203
|
setOrRemovePreviewAttribute(editedElement, fullAttr, previousValue);
|
|
194
204
|
},
|
|
@@ -256,6 +266,7 @@ export function useDomEditAttributeCommits({
|
|
|
256
266
|
commitKey,
|
|
257
267
|
);
|
|
258
268
|
let captured: CapturedMultiAttributeElement | null = null;
|
|
269
|
+
let sealedEdit: PreviewElementEdit | null = null;
|
|
259
270
|
let landed = false;
|
|
260
271
|
|
|
261
272
|
await runDomEditCommit({
|
|
@@ -268,21 +279,31 @@ export function useDomEditAttributeCommits({
|
|
|
268
279
|
);
|
|
269
280
|
},
|
|
270
281
|
apply: () => {
|
|
271
|
-
if (!captured)
|
|
282
|
+
if (!captured) {
|
|
283
|
+
const attributes = entries.map(({ fullAttr, value }): [string, string | null] => [
|
|
284
|
+
fullAttr,
|
|
285
|
+
value,
|
|
286
|
+
]);
|
|
287
|
+
sealedEdit = editSealedSelection(iframe, selection, { attributes });
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
272
290
|
for (const entry of entries) {
|
|
273
291
|
setOrRemovePreviewAttribute(captured.element, entry.fullAttr, entry.value);
|
|
274
292
|
}
|
|
275
293
|
},
|
|
276
294
|
persist: () =>
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
295
|
+
afterSealedDraw(sealedEdit, (drawn) =>
|
|
296
|
+
persistDomEditOperations(selection, ops, {
|
|
297
|
+
label: options.label,
|
|
298
|
+
coalesceKey: commitKey,
|
|
299
|
+
skipRefresh: options.skipRefresh && drawn,
|
|
300
|
+
prepareContent: options.prepareContent,
|
|
301
|
+
}),
|
|
302
|
+
),
|
|
283
303
|
shouldRevert: (error) =>
|
|
284
304
|
isLatestCommit() && !(error instanceof DomEditPersistPreparedWriteError),
|
|
285
305
|
revert: () => {
|
|
306
|
+
sealedEdit?.restore();
|
|
286
307
|
if (!captured) return;
|
|
287
308
|
for (const entry of entries) {
|
|
288
309
|
setOrRemovePreviewAttribute(
|
|
@@ -413,6 +434,7 @@ export function useDomEditAttributeCommits({
|
|
|
413
434
|
const op: PatchOperation = { type: "html-attribute", property: attr, value };
|
|
414
435
|
let editedElement: HTMLElement | null = null;
|
|
415
436
|
let previousValue: string | null = null;
|
|
437
|
+
let sealedEdit: PreviewElementEdit | null = null;
|
|
416
438
|
|
|
417
439
|
await runDomEditCommit({
|
|
418
440
|
capture: () => {
|
|
@@ -427,12 +449,13 @@ export function useDomEditAttributeCommits({
|
|
|
427
449
|
previousValue = captured.previousValue;
|
|
428
450
|
},
|
|
429
451
|
apply: () => {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
452
|
+
const optimistic = resolveOptimisticAttributeValue(attr, value);
|
|
453
|
+
if (!editedElement) {
|
|
454
|
+
const attributes: Array<[string, string | null]> = [[attr, optimistic]];
|
|
455
|
+
sealedEdit = editSealedSelection(iframe, domEditSelection, { attributes });
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
setOrRemovePreviewAttribute(editedElement, attr, optimistic);
|
|
436
459
|
},
|
|
437
460
|
persist: () =>
|
|
438
461
|
persistDomEditOperations(domEditSelection, [op], {
|
|
@@ -442,6 +465,7 @@ export function useDomEditAttributeCommits({
|
|
|
442
465
|
}),
|
|
443
466
|
shouldRevert: () => isLatestCommit(),
|
|
444
467
|
revert: () => {
|
|
468
|
+
sealedEdit?.restore();
|
|
445
469
|
if (!editedElement) return;
|
|
446
470
|
setOrRemovePreviewAttribute(editedElement, attr, previousValue);
|
|
447
471
|
},
|
|
@@ -2,46 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { afterEach, expect, it, vi } from "vitest";
|
|
4
4
|
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
|
|
5
|
-
// The frame's real runtime agent, serving the opaque frame from this document as Studio's marked preview page.
|
|
6
|
-
import { installMarkedEditingAgent } from "../../../core/src/runtime/editingAgent.test-helpers";
|
|
7
|
-
import { detachedFakeIframe } from "../player/hooks/timelinePlayerTestHarness";
|
|
8
5
|
import { describePreviewElements, queryPreviewElements } from "../player/lib/previewElements";
|
|
9
6
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
10
7
|
import { standInFor } from "../components/editor/previewSelection";
|
|
11
8
|
import type { DomEditSelection } from "../components/editor/domEditingTypes";
|
|
12
9
|
import { applyKeyframeAtPlayhead, type EnableKeyframesSession } from "./useEnableKeyframes";
|
|
10
|
+
import { sealedPreviewFrame } from "../player/lib/sealedPreviewFrame.test-helpers";
|
|
13
11
|
|
|
14
|
-
const closers: Array<() => void> = [];
|
|
15
12
|
afterEach(() => {
|
|
16
|
-
closers.splice(0).forEach((close) => close());
|
|
17
13
|
usePlayerStore.setState({ currentTime: 0, isPlaying: false });
|
|
18
14
|
document.body.innerHTML = "";
|
|
19
15
|
for (const name of ["gsap", "__timelines", "__player"]) Reflect.deleteProperty(window, name);
|
|
20
16
|
});
|
|
21
17
|
|
|
22
|
-
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
23
|
-
function opaqueFrame() {
|
|
24
|
-
const frame: Record<string, unknown> = {};
|
|
25
|
-
const iframe = detachedFakeIframe(frame);
|
|
26
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
27
|
-
Object.defineProperty(frame, "document", {
|
|
28
|
-
get: () => {
|
|
29
|
-
throw new DOMException("blocked", "SecurityError");
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
const parent = {
|
|
33
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
34
|
-
window.dispatchEvent(
|
|
35
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
36
|
-
),
|
|
37
|
-
} as unknown as Window;
|
|
38
|
-
const agent = installMarkedEditingAgent(parent);
|
|
39
|
-
frame.postMessage = (data: unknown) =>
|
|
40
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
41
|
-
closers.push(() => agent.dispose());
|
|
42
|
-
return iframe;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
18
|
/** The frame's GSAP: one keyframed tween moving #box, paused half way where GSAP has it at 120, 40. */
|
|
46
19
|
function frameGsapAt(seconds: number) {
|
|
47
20
|
const box = document.getElementById("box")!;
|
|
@@ -81,7 +54,7 @@ it("adds a keyframe at the playhead with the sealed preview's GSAP values there"
|
|
|
81
54
|
document.body.innerHTML = `<main data-composition-id="main"><div id="box"></div></main>`;
|
|
82
55
|
frameGsapAt(0.5);
|
|
83
56
|
usePlayerStore.setState({ currentTime: 0.5, isPlaying: false });
|
|
84
|
-
const iframe =
|
|
57
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
85
58
|
const [match] = (await queryPreviewElements(iframe, "#box"))!.matches;
|
|
86
59
|
const [described] = (await describePreviewElements(iframe, [match!.handle]))!;
|
|
87
60
|
const sel = { id: "box", selector: "#box", element: standInFor(iframe, described!) };
|
|
@@ -51,11 +51,12 @@ describe("requestFreezeFrame", () => {
|
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// fails without the fix: the server's words came through without its status, so the failure could not be named.
|
|
55
|
+
it("surfaces the server's error with its status", async () => {
|
|
55
56
|
stubFetch({ status: 400, body: { error: "Move the playhead inside a video clip to freeze" } });
|
|
56
57
|
await expect(
|
|
57
58
|
requestFreezeFrame({ projectId: "p", path: "index.html", element, playhead: 7 }),
|
|
58
|
-
).rejects.toThrow("Move the playhead inside a video clip to freeze");
|
|
59
|
+
).rejects.toThrow("Move the playhead inside a video clip to freeze (400)");
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
it("names the file and why when the file is read-only", async () => {
|
|
@@ -7,7 +7,7 @@ import { markStudioWriteToken } from "../utils/studioFileVersion";
|
|
|
7
7
|
import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinator";
|
|
8
8
|
import type { RecordEditInput } from "../utils/studioFileHistory";
|
|
9
9
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
10
|
-
import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
|
|
10
|
+
import { heldFileWordsOf, withStatus } from "../utils/studioSaveDiagnostics";
|
|
11
11
|
|
|
12
12
|
type ProjectFileWriter = (path: string, content: string, expectedContent?: string) => Promise<void>;
|
|
13
13
|
|
|
@@ -77,7 +77,7 @@ export async function requestFreezeFrame(input: {
|
|
|
77
77
|
const held = response.ok ? null : await heldFileWordsOf(response, input.path);
|
|
78
78
|
const body: unknown = await response.json().catch(() => null);
|
|
79
79
|
if (!response.ok || !isFreezeFrameResponse(body)) {
|
|
80
|
-
throw new Error(held ?? errorOf(body) ??
|
|
80
|
+
throw new Error(held ?? withStatus(errorOf(body) ?? "Freeze frame failed", response));
|
|
81
81
|
}
|
|
82
82
|
return body;
|
|
83
83
|
}
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "../utils/studioHelpers";
|
|
18
18
|
import type { TimelineElement } from "../player";
|
|
19
19
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
20
|
-
import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
|
|
20
|
+
import { heldFileWordsOf, withStatus } from "../utils/studioSaveDiagnostics";
|
|
21
21
|
|
|
22
22
|
interface UseGroupCommitsParams extends DomEditCommitBaseParams {
|
|
23
23
|
/** Resync the SDK session after a server-side write (the wrapper/unwrap changes
|
|
@@ -148,7 +148,12 @@ async function commitStructuralMutation(
|
|
|
148
148
|
const errBody = (await mutateResponse.json().catch(() => null)) as {
|
|
149
149
|
error?: string;
|
|
150
150
|
} | null;
|
|
151
|
-
throw new Error(
|
|
151
|
+
throw new Error(
|
|
152
|
+
withStatus(
|
|
153
|
+
errBody?.error ?? `Failed to ${label.toLowerCase()} in ${targetPath}`,
|
|
154
|
+
mutateResponse,
|
|
155
|
+
),
|
|
156
|
+
);
|
|
152
157
|
}
|
|
153
158
|
result = (await mutateResponse.json()) as { content?: string; groupId?: string };
|
|
154
159
|
return { disk: typeof result.content === "string" ? result.content : originalContent };
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { act } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { previewClipManifest } from "../player/lib/previewChannel";
|
|
6
7
|
import { useSlideshowTabState } from "./useSlideshowTabState";
|
|
7
8
|
|
|
9
|
+
vi.mock("../player/lib/previewChannel", async (importOriginal) => {
|
|
10
|
+
const actual = await importOriginal<typeof import("../player/lib/previewChannel")>();
|
|
11
|
+
return { ...actual, previewClipManifest: vi.fn(async () => null) };
|
|
12
|
+
});
|
|
13
|
+
|
|
8
14
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
9
15
|
|
|
10
16
|
const SLIDESHOW_HTML = `<html><body><script type="application/hyperframes-slideshow+json">{"slides":[]}</script></body></html>`;
|
|
@@ -14,16 +20,21 @@ afterEach(() => {
|
|
|
14
20
|
document.body.innerHTML = "";
|
|
15
21
|
});
|
|
16
22
|
|
|
17
|
-
function renderHook(params: {
|
|
23
|
+
function renderHook(params: {
|
|
24
|
+
editingFileContent: string | null | undefined;
|
|
25
|
+
iframe?: HTMLIFrameElement | null;
|
|
26
|
+
}) {
|
|
18
27
|
const host = document.createElement("div");
|
|
19
28
|
document.body.append(host);
|
|
20
29
|
const root = createRoot(host);
|
|
21
30
|
let current: ReturnType<typeof useSlideshowTabState> | null = null;
|
|
31
|
+
// One ref for every render, as Studio's useRef gives.
|
|
32
|
+
const previewIframeRef = { current: params.iframe ?? null };
|
|
22
33
|
|
|
23
34
|
function Harness() {
|
|
24
35
|
current = useSlideshowTabState({
|
|
25
36
|
editingFileContent: params.editingFileContent,
|
|
26
|
-
previewIframeRef
|
|
37
|
+
previewIframeRef,
|
|
27
38
|
refreshKey: 0,
|
|
28
39
|
slideshowVisible: false,
|
|
29
40
|
});
|
|
@@ -71,4 +82,37 @@ describe("useSlideshowTabState", () => {
|
|
|
71
82
|
expect(harness.getState().isSlideshowComposition).toBe(true);
|
|
72
83
|
harness.unmount();
|
|
73
84
|
});
|
|
85
|
+
|
|
86
|
+
it("lists the scenes of a sealed preview, read over its editing port", async () => {
|
|
87
|
+
// A cross-origin frame's window refuses every property read.
|
|
88
|
+
const sealedWindow = new Proxy(
|
|
89
|
+
{},
|
|
90
|
+
{
|
|
91
|
+
get() {
|
|
92
|
+
throw new DOMException(
|
|
93
|
+
"Blocked a frame from accessing a cross-origin frame.",
|
|
94
|
+
"SecurityError",
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
const iframe = document.createElement("iframe");
|
|
100
|
+
Object.defineProperty(iframe, "contentWindow", { value: sealedWindow });
|
|
101
|
+
vi.mocked(previewClipManifest).mockResolvedValueOnce({
|
|
102
|
+
clips: [],
|
|
103
|
+
durationInFrames: 300,
|
|
104
|
+
scenes: [
|
|
105
|
+
null,
|
|
106
|
+
{ id: "s1", label: "Intro", start: 0, duration: 4 },
|
|
107
|
+
{ id: 2, label: "Bad id", start: 4, duration: 4 },
|
|
108
|
+
{ id: "s3", label: "No time", start: null, duration: 4 },
|
|
109
|
+
],
|
|
110
|
+
} as unknown as Awaited<ReturnType<typeof previewClipManifest>>);
|
|
111
|
+
const harness = renderHook({ editingFileContent: SLIDESHOW_HTML, iframe });
|
|
112
|
+
await act(async () => {});
|
|
113
|
+
expect(harness.getState().slideshowScenes).toEqual([
|
|
114
|
+
{ id: "s1", label: "Intro", start: 0, duration: 4 },
|
|
115
|
+
]);
|
|
116
|
+
harness.unmount();
|
|
117
|
+
});
|
|
74
118
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useMemo, type MutableRefObject } from "react";
|
|
1
|
+
import { useEffect, useMemo, useState, type MutableRefObject } from "react";
|
|
2
2
|
import { SLIDESHOW_ISLAND_TYPE, slideshowIslandRegex } from "@hyperframes/core/slideshow";
|
|
3
3
|
import type { SceneInfo } from "../components/panels/SlideshowPanel";
|
|
4
|
-
import
|
|
4
|
+
import { previewClipManifest } from "../player/lib/previewChannel";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Derives whether the currently-edited composition is a slideshow (carries
|
|
@@ -10,6 +10,18 @@ import type { IframeWindow } from "../player/lib/playbackTypes";
|
|
|
10
10
|
* for the Slideshow panel. Extracted from StudioRightPanels to keep that file
|
|
11
11
|
* under the 600-LOC gate.
|
|
12
12
|
*/
|
|
13
|
+
/** The manifest is frame data: a scene entry must carry a string id and label and finite times. */
|
|
14
|
+
function isSceneEntry(value: unknown): value is SceneInfo {
|
|
15
|
+
if (!value || typeof value !== "object") return false;
|
|
16
|
+
const s = value as Record<string, unknown>;
|
|
17
|
+
return (
|
|
18
|
+
typeof s.id === "string" &&
|
|
19
|
+
typeof s.label === "string" &&
|
|
20
|
+
Number.isFinite(s.start) &&
|
|
21
|
+
Number.isFinite(s.duration)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
export function useSlideshowTabState(params: {
|
|
14
26
|
editingFileContent: string | null | undefined;
|
|
15
27
|
previewIframeRef: MutableRefObject<HTMLIFrameElement | null>;
|
|
@@ -28,20 +40,24 @@ export function useSlideshowTabState(params: {
|
|
|
28
40
|
return slideshowIslandRegex("i").test(editingFileContent);
|
|
29
41
|
}, [editingFileContent]);
|
|
30
42
|
|
|
31
|
-
//
|
|
32
|
-
const slideshowScenes =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// The scene list from the preview's live clip manifest, read over its editing port.
|
|
44
|
+
const [slideshowScenes, setSlideshowScenes] = useState<SceneInfo[]>([]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const iframe = previewIframeRef.current;
|
|
47
|
+
if (!iframe) return setSlideshowScenes([]);
|
|
48
|
+
let current = true;
|
|
49
|
+
void previewClipManifest(iframe).then((manifest) => {
|
|
50
|
+
if (!current) return;
|
|
51
|
+
const scenes: unknown[] = Array.isArray(manifest?.scenes) ? manifest.scenes : [];
|
|
52
|
+
setSlideshowScenes(
|
|
53
|
+
scenes
|
|
54
|
+
.filter(isSceneEntry)
|
|
55
|
+
.map((s) => ({ id: s.id, label: s.label, start: s.start, duration: s.duration })),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
current = false;
|
|
60
|
+
};
|
|
45
61
|
}, [previewIframeRef, slideshowVisible, refreshKey]);
|
|
46
62
|
|
|
47
63
|
return { isSlideshowComposition, slideshowScenes };
|
|
@@ -171,7 +171,8 @@ export function serveEditingRequests(
|
|
|
171
171
|
};
|
|
172
172
|
const handoff = { source: "hf-preview", type: "editing-port", v: 1 };
|
|
173
173
|
const source = frame as unknown as Window;
|
|
174
|
-
|
|
174
|
+
const init = { source, data: handoff, ports: [port2] };
|
|
175
|
+
setTimeout(() => window.dispatchEvent(new MessageEvent("message", init)));
|
|
175
176
|
};
|
|
176
177
|
return () => ports.forEach((port) => port.close());
|
|
177
178
|
}
|