@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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { previewRequest } from "../../player/lib/previewChannel";
|
|
5
|
+
import { hostCompositionSrc } from "./NLEContext";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../player/lib/previewChannel", async (importOriginal) => {
|
|
8
|
+
const actual = await importOriginal<typeof import("../../player/lib/previewChannel")>();
|
|
9
|
+
return { ...actual, previewRequest: vi.fn(async () => null) };
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => vi.mocked(previewRequest).mockReset());
|
|
13
|
+
|
|
14
|
+
const HANDLE = "0123456789abcdef:1";
|
|
15
|
+
const NO_SOURCE = { file: null, compositionId: null, originalCompositionId: null };
|
|
16
|
+
|
|
17
|
+
function sealedPreview(): HTMLIFrameElement {
|
|
18
|
+
const iframe = document.createElement("iframe");
|
|
19
|
+
Object.defineProperty(iframe, "contentDocument", {
|
|
20
|
+
get() {
|
|
21
|
+
throw new DOMException(
|
|
22
|
+
"Blocked a frame from accessing a cross-origin frame.",
|
|
23
|
+
"SecurityError",
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return iframe;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function preview(attributes: unknown) {
|
|
31
|
+
vi.mocked(previewRequest).mockImplementation((async (_frame: HTMLIFrameElement, kind: string) =>
|
|
32
|
+
kind === "query"
|
|
33
|
+
? { matches: [{ handle: HANDLE, source: NO_SOURCE }], truncated: false }
|
|
34
|
+
: {
|
|
35
|
+
elements: [
|
|
36
|
+
{
|
|
37
|
+
handle: HANDLE,
|
|
38
|
+
parent: null,
|
|
39
|
+
tag: "div",
|
|
40
|
+
id: "intro",
|
|
41
|
+
selector: null,
|
|
42
|
+
matchesBefore: null,
|
|
43
|
+
source: NO_SOURCE,
|
|
44
|
+
locked: false,
|
|
45
|
+
attributes,
|
|
46
|
+
inlineStyles: {},
|
|
47
|
+
text: "",
|
|
48
|
+
children: [],
|
|
49
|
+
rect: { x: 0, y: 0, width: 1, height: 1 },
|
|
50
|
+
truncated: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
}) as unknown as typeof previewRequest);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("hostCompositionSrc", () => {
|
|
57
|
+
it("reads a sealed preview's host for the composition over its editing port", async () => {
|
|
58
|
+
const iframe = sealedPreview();
|
|
59
|
+
preview([
|
|
60
|
+
["data-composition-id", "intro"],
|
|
61
|
+
["data-composition-src", "compositions/intro.html"],
|
|
62
|
+
]);
|
|
63
|
+
await expect(hostCompositionSrc(iframe, 'in"tro')).resolves.toBe("compositions/intro.html");
|
|
64
|
+
expect(vi.mocked(previewRequest)).toHaveBeenCalledWith(iframe, "query", {
|
|
65
|
+
selector: `[data-composition-id="in\\"tro"][data-composition-src]`,
|
|
66
|
+
});
|
|
67
|
+
expect(vi.mocked(previewRequest)).toHaveBeenCalledWith(iframe, "describe", {
|
|
68
|
+
handles: [HANDLE],
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("answers nothing for a reply the frame got wrong, rather than passing it on", async () => {
|
|
73
|
+
preview([["data-composition-src", { evil: 1 }]]);
|
|
74
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
75
|
+
preview("x");
|
|
76
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("answers nothing when the preview has no such host or cannot answer", async () => {
|
|
80
|
+
vi.mocked(previewRequest).mockResolvedValue(null);
|
|
81
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
82
|
+
vi.mocked(previewRequest).mockResolvedValue({ matches: [], truncated: false });
|
|
83
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -11,6 +11,19 @@ import { useAssetPreviewStore } from "../../utils/assetPreviewStore";
|
|
|
11
11
|
import { createStableContext } from "../../utils/hmrStableContext";
|
|
12
12
|
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
13
13
|
import { previewReloadBegun } from "../../player/previewReloading";
|
|
14
|
+
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
15
|
+
|
|
16
|
+
/** The `data-composition-src` of the preview's host for composition `compId`, read over its editing port. */
|
|
17
|
+
export async function hostCompositionSrc(
|
|
18
|
+
iframe: HTMLIFrameElement,
|
|
19
|
+
compId: string,
|
|
20
|
+
): Promise<string | undefined> {
|
|
21
|
+
const selector = `[data-composition-id="${CSS.escape(compId)}"][data-composition-src]`;
|
|
22
|
+
const handle = (await queryPreviewElements(iframe, selector))?.matches[0]?.handle;
|
|
23
|
+
if (!handle) return undefined;
|
|
24
|
+
const [host] = (await describePreviewElements(iframe, [handle])) ?? [];
|
|
25
|
+
return host?.attributes.find(([name]) => name === "data-composition-src")?.[1] || undefined;
|
|
26
|
+
}
|
|
14
27
|
|
|
15
28
|
export function shouldDisableTimelineWhileCompositionLoading(compositionLoading: boolean): boolean {
|
|
16
29
|
return compositionLoading;
|
|
@@ -171,35 +184,20 @@ export function NLEProvider({
|
|
|
171
184
|
onCompositionChange,
|
|
172
185
|
});
|
|
173
186
|
|
|
174
|
-
//
|
|
187
|
+
// Drill into a sub-composition: its src from compIdToSrc, else from its host in the preview, else the clip's own.
|
|
175
188
|
const iframeRef_ = iframeRef;
|
|
176
189
|
const handleDrillDown = useCallback(
|
|
177
190
|
(element: TimelineElement) => {
|
|
178
191
|
if (!element.compositionSrc) return;
|
|
179
192
|
usePlayerStore.getState().setSelectedElementId(null);
|
|
180
|
-
// Check compIdToSrc map first; then scan iframe DOM; then fall through to drillDown
|
|
181
193
|
const compId = element.id;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
);
|
|
190
|
-
if (host) {
|
|
191
|
-
resolvedPath = host.getAttribute("data-composition-src") || undefined;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
} catch {
|
|
195
|
-
/* cross-origin */
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Delegate with the resolved compositionSrc (may be same as original)
|
|
199
|
-
drillDown({
|
|
200
|
-
id: compId,
|
|
201
|
-
compositionSrc: resolvedPath ?? element.compositionSrc,
|
|
202
|
-
});
|
|
194
|
+
const known = compIdToSrc.get(compId);
|
|
195
|
+
const iframe = iframeRef_.current;
|
|
196
|
+
const resolve =
|
|
197
|
+
known || !iframe ? Promise.resolve(known) : hostCompositionSrc(iframe, compId);
|
|
198
|
+
void resolve.then((resolvedPath) =>
|
|
199
|
+
drillDown({ id: compId, compositionSrc: resolvedPath ?? element.compositionSrc }),
|
|
200
|
+
);
|
|
203
201
|
},
|
|
204
202
|
[compIdToSrc, drillDown, iframeRef_],
|
|
205
203
|
);
|
|
@@ -34,9 +34,8 @@ vi.mock("../../player", async () => {
|
|
|
34
34
|
ref: React.ForwardedRef<HTMLIFrameElement>,
|
|
35
35
|
) {
|
|
36
36
|
if (!props.suppressLoadingOverlay) livePlayerProps = props;
|
|
37
|
-
React.
|
|
38
|
-
|
|
39
|
-
}, [props]);
|
|
37
|
+
const onLoad = React.useRef(props.onLoad);
|
|
38
|
+
React.useEffect(() => onLoad.current?.(), []);
|
|
40
39
|
React.useState(() => playerMounts.push(props.suppressLoadingOverlay ? "shadow" : "live"));
|
|
41
40
|
|
|
42
41
|
return React.createElement("div", {
|
|
@@ -556,6 +555,22 @@ describe("NLEPreview", () => {
|
|
|
556
555
|
}
|
|
557
556
|
});
|
|
558
557
|
|
|
558
|
+
it("takes a sealed preview's size once its film is ready to show, after the frame has loaded", () => {
|
|
559
|
+
const box = { width: 800, height: 600 };
|
|
560
|
+
const sealed = renderPreview(undefined, { box, sandboxOrigin: "opaque" });
|
|
561
|
+
try {
|
|
562
|
+
expect([sealed.stage.style.width, sealed.stage.style.height]).toEqual(["784px", "441px"]);
|
|
563
|
+
measured.size = { width: 1080, height: 1920 };
|
|
564
|
+
act(() => livePlayerProps.onReadyToShowChange?.(true));
|
|
565
|
+
const shape = parseFloat(sealed.stage.style.width) / parseFloat(sealed.stage.style.height);
|
|
566
|
+
expect(shape).toBeCloseTo(1080 / 1920, 3);
|
|
567
|
+
expect(sealed.stage.style.height).toBe("584px");
|
|
568
|
+
} finally {
|
|
569
|
+
measured.size = null;
|
|
570
|
+
sealed.cleanup();
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
559
574
|
it("clips a shadow reload so its own loading overlay cannot paint over the live frame", () => {
|
|
560
575
|
const view = renderPreview([
|
|
561
576
|
{ gen: 0, role: "live" },
|
|
@@ -180,6 +180,15 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
180
180
|
onCompositionSizeChangeRef.current?.(compositionSize);
|
|
181
181
|
}, [compositionSize]);
|
|
182
182
|
|
|
183
|
+
const showLive = poster.onLiveReadyToShowChange;
|
|
184
|
+
const onLiveReadyToShowChange = useCallback(
|
|
185
|
+
(ready: boolean) => {
|
|
186
|
+
showLive(ready);
|
|
187
|
+
if (ready) updateCompositionSizeFromPreview();
|
|
188
|
+
},
|
|
189
|
+
[showLive, updateCompositionSizeFromPreview],
|
|
190
|
+
);
|
|
191
|
+
|
|
183
192
|
const setPreviewIframeRef = useCallback(
|
|
184
193
|
(node: HTMLIFrameElement | null) => {
|
|
185
194
|
previewIframeRef.current = node;
|
|
@@ -503,7 +512,7 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
503
512
|
applyInitialZoom();
|
|
504
513
|
}}
|
|
505
514
|
onCompositionLoadingChange={onCompositionLoadingChange}
|
|
506
|
-
onReadyToShowChange={
|
|
515
|
+
onReadyToShowChange={onLiveReadyToShowChange}
|
|
507
516
|
onPreviewError={poster.onPreviewError}
|
|
508
517
|
onPainted={(details) => reportPreviewFirstFrame(slot, details)}
|
|
509
518
|
portrait={portrait}
|
|
@@ -3,25 +3,22 @@
|
|
|
3
3
|
import { act, createElement } from "react";
|
|
4
4
|
import { createRoot, type Root } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
6
|
-
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
6
|
import { usePlayerStore, type TimelineElement } from "../../player";
|
|
9
7
|
import { ClipMenuAudioItems } from "../../player/components/clipMenuAudioItems";
|
|
10
8
|
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
9
|
import { TimelineEditProvider } from "../../contexts/TimelineEditContext";
|
|
12
10
|
import { createAudioGroupAndAssignMembers } from "../../hooks/timelineAudioGroupCreate";
|
|
13
11
|
import { mintGroupId } from "../editor/useFxCarveGrouping";
|
|
14
|
-
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
15
12
|
import { useAudioMetersVisible } from "../../utils/audioMeterVisibility";
|
|
16
13
|
import { useSetAudioGroupAttribute } from "../../hooks/timelineAudioGroupVolume";
|
|
17
14
|
import { previewDocumentCopy } from "../../player/lib/previewChannel";
|
|
18
15
|
import { AudioMeterStrip } from "./AudioMeterStrip";
|
|
16
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
19
17
|
|
|
20
18
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
21
19
|
|
|
22
20
|
type MeterWindow = Window & { __hf?: Record<string, unknown> };
|
|
23
21
|
|
|
24
|
-
const closers: Array<() => void> = [];
|
|
25
22
|
const roots: Root[] = [];
|
|
26
23
|
let frames: FrameRequestCallback[] = [];
|
|
27
24
|
const tick = () => {
|
|
@@ -38,7 +35,6 @@ beforeEach(() => {
|
|
|
38
35
|
});
|
|
39
36
|
afterEach(() => {
|
|
40
37
|
act(() => roots.splice(0).forEach((root) => root.unmount()));
|
|
41
|
-
closers.splice(0).forEach((close) => close());
|
|
42
38
|
delete (window as MeterWindow).__hf;
|
|
43
39
|
vi.unstubAllGlobals();
|
|
44
40
|
usePlayerStore.getState().reset();
|
|
@@ -46,29 +42,6 @@ afterEach(() => {
|
|
|
46
42
|
document.body.innerHTML = "";
|
|
47
43
|
});
|
|
48
44
|
|
|
49
|
-
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
50
|
-
function opaqueFrame() {
|
|
51
|
-
const frame: Record<string, unknown> = {};
|
|
52
|
-
const iframe = detachedFakeIframe(frame);
|
|
53
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
54
|
-
Object.defineProperty(frame, "document", {
|
|
55
|
-
get: () => {
|
|
56
|
-
throw new DOMException("blocked", "SecurityError");
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const parent = {
|
|
60
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
61
|
-
window.dispatchEvent(
|
|
62
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
63
|
-
),
|
|
64
|
-
} as unknown as Window;
|
|
65
|
-
const agent = installMarkedEditingAgent(parent);
|
|
66
|
-
frame.postMessage = (data: unknown) =>
|
|
67
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
68
|
-
closers.push(() => agent.dispose());
|
|
69
|
-
return iframe;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
45
|
const member = (domId: string): TimelineElement => ({
|
|
73
46
|
id: domId,
|
|
74
47
|
key: `compositions/voices.html#${domId}`,
|
|
@@ -112,7 +85,7 @@ it("meter moves + group volume sealed", async () => {
|
|
|
112
85
|
};
|
|
113
86
|
(window as MeterWindow).__hf = { audioMeter: meter };
|
|
114
87
|
usePlayerStore.getState().setElements([member("voice-1")]);
|
|
115
|
-
const iframe =
|
|
88
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
116
89
|
|
|
117
90
|
const host = document.createElement("div");
|
|
118
91
|
document.body.append(host);
|
|
@@ -168,7 +141,7 @@ it("groups clips in a sealed preview, and unwinds the preview when the save fail
|
|
|
168
141
|
document.body.innerHTML = `<main data-composition-id="root">
|
|
169
142
|
<audio id="voice-1" data-audio-group="old"></audio><audio id="voice-2"></audio>
|
|
170
143
|
</main>`;
|
|
171
|
-
const iframe =
|
|
144
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
172
145
|
const files = new Map([["index.html", document.body.innerHTML]]);
|
|
173
146
|
stubProjectFiles(files);
|
|
174
147
|
const elements = ["voice-1", "voice-2"].map((domId) => ({
|
|
@@ -210,7 +183,7 @@ it("groups clips in a sealed preview, and unwinds the preview when the save fail
|
|
|
210
183
|
|
|
211
184
|
it("reads a sealed preview's groups and ids off an inert copy", async () => {
|
|
212
185
|
document.body.innerHTML = `<audio id="voiceover"></audio><audio id="music" src="bed.wav"></audio>`;
|
|
213
|
-
const copy = await previewDocumentCopy(
|
|
186
|
+
const copy = await previewDocumentCopy(sealedPreviewFrame().iframe);
|
|
214
187
|
expect(copy).not.toBeNull();
|
|
215
188
|
expect(copy).not.toBe(document);
|
|
216
189
|
expect(mintGroupId(copy!)).toBe("voiceover-2");
|
|
@@ -222,7 +195,7 @@ it("offers Duck under voice for a bed in a sealed preview", async () => {
|
|
|
222
195
|
<audio id="music" src="bed.wav" data-start="0" data-duration="10"></audio>
|
|
223
196
|
<audio id="voiceover" src="vo.wav" data-start="1" data-duration="2"></audio>
|
|
224
197
|
</main>`;
|
|
225
|
-
const iframe =
|
|
198
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
226
199
|
usePreviewIframeStore.setState({ iframe });
|
|
227
200
|
usePlayerStore.getState().beginTimelineSession("project-1");
|
|
228
201
|
const bed: TimelineElement = {
|
|
@@ -9,7 +9,12 @@ import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
|
|
|
9
9
|
import { canSplitElement } from "../utils/timelineElementSplit";
|
|
10
10
|
import { trackStudioEvent } from "../utils/studioTelemetry";
|
|
11
11
|
import { razorClaimsKey } from "../player/lib/playbackShortcuts";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
getStudioKeys,
|
|
14
|
+
keyHint,
|
|
15
|
+
matchesKey,
|
|
16
|
+
type StudioKeyAction,
|
|
17
|
+
} from "../player/components/studioShortcuts";
|
|
13
18
|
import { zoomTimelineToSelectedClips } from "../player/components/timelineZoomInput";
|
|
14
19
|
import { openAudioGainDialog } from "../player/components/audioGainDialogStore";
|
|
15
20
|
import type { LinkShortcutCallbacks } from "./linkShortcuts";
|
|
@@ -119,6 +124,38 @@ function dispatchClipboardKey(event: KeyboardEvent, cb: HotkeyCallbacks): boolea
|
|
|
119
124
|
return true;
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
/** Every action the dispatchers here and dispatchLinkShortcut answer: what a sealed preview forwards to them. */
|
|
128
|
+
export const APP_HOTKEY_ACTIONS = [
|
|
129
|
+
"undo",
|
|
130
|
+
"redo",
|
|
131
|
+
"redoAlt",
|
|
132
|
+
"tabCompositions",
|
|
133
|
+
"tabAssets",
|
|
134
|
+
"group",
|
|
135
|
+
"ungroup",
|
|
136
|
+
"copy",
|
|
137
|
+
"paste",
|
|
138
|
+
"cut",
|
|
139
|
+
"duplicate",
|
|
140
|
+
"zoomSelection",
|
|
141
|
+
"fullscreen",
|
|
142
|
+
"split",
|
|
143
|
+
"audioGain",
|
|
144
|
+
"razorTool",
|
|
145
|
+
"selectTool",
|
|
146
|
+
"selectLeftward",
|
|
147
|
+
"selectRightward",
|
|
148
|
+
"cancel",
|
|
149
|
+
"deleteSelected",
|
|
150
|
+
"deleteSelectedAlt",
|
|
151
|
+
"resetKeyframes",
|
|
152
|
+
"record",
|
|
153
|
+
"linkToggle",
|
|
154
|
+
"detachAudio",
|
|
155
|
+
"deleteLinked",
|
|
156
|
+
"deleteLinkedAlt",
|
|
157
|
+
] as const satisfies readonly StudioKeyAction[];
|
|
158
|
+
|
|
122
159
|
/** Exported for tests: the shortcuts that act on the editor, each read as a combo at event time. */
|
|
123
160
|
export function dispatchModifierKey(
|
|
124
161
|
event: KeyboardEvent,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act, createElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
|
+
import { detachedFakeIframe } from "../player/hooks/timelinePlayerTestHarness";
|
|
9
|
+
import {
|
|
10
|
+
findPreviewElementForSelection,
|
|
11
|
+
resolvePreviewSelection,
|
|
12
|
+
} from "../components/editor/previewSelection";
|
|
13
|
+
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
14
|
+
import type { PersistDomEditOperations } from "./domEditCommitTypes";
|
|
15
|
+
import { commitDomStyles } from "./domStyleCommit";
|
|
16
|
+
import { useDomEditAttributeCommits } from "./useDomEditAttributeCommits";
|
|
17
|
+
|
|
18
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
const closers: Array<() => void> = [];
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
closers.splice(0).forEach((close) => close());
|
|
23
|
+
document.body.innerHTML = "";
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
27
|
+
function opaqueFrame(): HTMLIFrameElement {
|
|
28
|
+
const frame: Record<string, unknown> = {};
|
|
29
|
+
const iframe = detachedFakeIframe(frame);
|
|
30
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
31
|
+
Object.defineProperty(frame, "document", {
|
|
32
|
+
get: () => {
|
|
33
|
+
throw new DOMException("blocked", "SecurityError");
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const parent = {
|
|
37
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
38
|
+
window.dispatchEvent(
|
|
39
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
40
|
+
),
|
|
41
|
+
} as unknown as Window;
|
|
42
|
+
const agent = installMarkedEditingAgent(parent);
|
|
43
|
+
frame.postMessage = (data: unknown) =>
|
|
44
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
45
|
+
closers.push(() => agent.dispose());
|
|
46
|
+
return iframe;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const PATH = "index.html";
|
|
50
|
+
|
|
51
|
+
async function sealedCard(markup: string) {
|
|
52
|
+
document.body.innerHTML = markup;
|
|
53
|
+
const card = document.getElementById("card")!;
|
|
54
|
+
const iframe = opaqueFrame();
|
|
55
|
+
const target = { id: "card", sourceFile: PATH };
|
|
56
|
+
const found = await findPreviewElementForSelection(iframe, target, PATH);
|
|
57
|
+
const selection = await resolvePreviewSelection(iframe, found!, {
|
|
58
|
+
activeCompositionPath: PATH,
|
|
59
|
+
isMasterView: false,
|
|
60
|
+
skipSourceProbe: true,
|
|
61
|
+
});
|
|
62
|
+
return { card, iframe, selection: selection! };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Lets the port's request and the frame's reply land. */
|
|
66
|
+
const settle = () => act(() => new Promise((resolve) => setTimeout(resolve, 20)));
|
|
67
|
+
|
|
68
|
+
function styleContext(iframe: HTMLIFrameElement, persist: PersistDomEditOperations) {
|
|
69
|
+
return {
|
|
70
|
+
activeCompPath: PATH,
|
|
71
|
+
previewIframeRef: { current: iframe },
|
|
72
|
+
persistDomEditOperations: persist,
|
|
73
|
+
showToast: vi.fn(),
|
|
74
|
+
versions: new Map<string, symbol>(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function attributeCommits(
|
|
79
|
+
iframe: HTMLIFrameElement,
|
|
80
|
+
selection: DomEditSelection,
|
|
81
|
+
persist: PersistDomEditOperations,
|
|
82
|
+
) {
|
|
83
|
+
let commits: ReturnType<typeof useDomEditAttributeCommits> | undefined;
|
|
84
|
+
function Harness() {
|
|
85
|
+
commits = useDomEditAttributeCommits({
|
|
86
|
+
activeCompPath: PATH,
|
|
87
|
+
previewIframeRef: { current: iframe },
|
|
88
|
+
showToast: vi.fn(),
|
|
89
|
+
domEditSelection: selection,
|
|
90
|
+
refreshDomEditSelectionFromPreview: vi.fn(),
|
|
91
|
+
persistDomEditOperations: persist,
|
|
92
|
+
});
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
act(() => createRoot(document.createElement("div")).render(createElement(Harness)));
|
|
96
|
+
return commits!;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
describe("DOM edit commits in a sealed preview", () => {
|
|
100
|
+
it("draws a style commit on the frame's element and saves it without a reload", async () => {
|
|
101
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
102
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
103
|
+
const outcome = await commitDomStyles(styleContext(iframe, persist), selection, {
|
|
104
|
+
opacity: "0.5",
|
|
105
|
+
});
|
|
106
|
+
await settle();
|
|
107
|
+
expect(outcome.ok).toBe(true);
|
|
108
|
+
expect(card.style.opacity).toBe("0.5");
|
|
109
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: true });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("puts the frame's style back when the save fails", async () => {
|
|
113
|
+
const { card, iframe, selection } = await sealedCard(
|
|
114
|
+
`<div id="card" style="color: red">Hi</div>`,
|
|
115
|
+
);
|
|
116
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
117
|
+
throw new Error("disk full");
|
|
118
|
+
});
|
|
119
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { color: "blue" });
|
|
120
|
+
await settle();
|
|
121
|
+
expect(card.style.color).toBe("red");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("reloads a sealed frame for a font change, which it cannot load from Studio", async () => {
|
|
125
|
+
const { iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
126
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
127
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { "font-family": "Inter" });
|
|
128
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("reloads when the frame no longer has the element to draw on", async () => {
|
|
132
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
133
|
+
card.remove();
|
|
134
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
135
|
+
await commitDomStyles(styleContext(iframe, persist), selection, { opacity: "0.5" });
|
|
136
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("reloads when the frame refuses the edit", async () => {
|
|
140
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card">Hi</div>`);
|
|
141
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
142
|
+
const tooLong = `"${"x".repeat(200_001)}"`;
|
|
143
|
+
await commitDomStyles(styleContext(iframe, persist), selection, {
|
|
144
|
+
"font-feature-settings": tooLong,
|
|
145
|
+
});
|
|
146
|
+
expect(persist.mock.calls[0]?.[2]).toMatchObject({ skipRefresh: false });
|
|
147
|
+
expect(card.style.fontFeatureSettings).toBe("");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("draws data and HTML attribute commits on the frame's element", async () => {
|
|
151
|
+
const { card, iframe, selection } = await sealedCard(`<div id="card" data-volume="1">Hi</div>`);
|
|
152
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => undefined);
|
|
153
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
154
|
+
await act(() => commits.handleDomAttributeQuietCommit("volume", "0.25"));
|
|
155
|
+
await act(() => commits.handleDomHtmlAttributeCommit("title", "Card"));
|
|
156
|
+
await settle();
|
|
157
|
+
expect(card.dataset.volume).toBe("0.25");
|
|
158
|
+
expect(card.getAttribute("title")).toBe("Card");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("never puts back a value over a newer edit that saved", async () => {
|
|
162
|
+
const { card, iframe, selection } = await sealedCard(
|
|
163
|
+
`<div id="card" title="original">Hi</div>`,
|
|
164
|
+
);
|
|
165
|
+
let saves = 0;
|
|
166
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
167
|
+
if (saves++ === 0) throw new Error("disk full");
|
|
168
|
+
});
|
|
169
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
170
|
+
await act(async () => {
|
|
171
|
+
const first = commits.handleDomHtmlAttributeCommit("title", "first");
|
|
172
|
+
for (let i = 0; i < 5; i++) await Promise.resolve();
|
|
173
|
+
await Promise.all([first, commits.handleDomHtmlAttributeCommit("title", "second")]);
|
|
174
|
+
});
|
|
175
|
+
await settle();
|
|
176
|
+
expect(card.getAttribute("title")).toBe("second");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("puts the frame's attributes back when a batch save fails", async () => {
|
|
180
|
+
const { card, iframe, selection } = await sealedCard(
|
|
181
|
+
`<div id="card" data-start="1" data-duration="2">Hi</div>`,
|
|
182
|
+
);
|
|
183
|
+
const persist = vi.fn<PersistDomEditOperations>(async () => {
|
|
184
|
+
throw new Error("disk full");
|
|
185
|
+
});
|
|
186
|
+
const commits = attributeCommits(iframe, selection, persist);
|
|
187
|
+
await act(() => commits.handleDomAttributesCommit(selection, { start: "3", duration: "4" }));
|
|
188
|
+
await settle();
|
|
189
|
+
expect([card.dataset.start, card.dataset.duration]).toEqual(["1", "2"]);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
type DomEditSelection,
|
|
14
14
|
} from "../components/editor/domEditing";
|
|
15
15
|
import type { ImportedFontAsset } from "../components/editor/fontAssets";
|
|
16
|
+
import { editSealedSelection } from "../components/editor/previewSelection";
|
|
17
|
+
import { afterSealedDraw, type PreviewElementEdit } from "../player/lib/previewElements";
|
|
16
18
|
import type { PersistDomEditOperations } from "./domEditCommitTypes";
|
|
17
19
|
import { reportDomEditPersistFailure } from "./domEditPersistFailure";
|
|
18
20
|
import {
|
|
@@ -86,6 +88,7 @@ export async function commitDomStyles(
|
|
|
86
88
|
}
|
|
87
89
|
let editedElement: HTMLElement | null = null;
|
|
88
90
|
const previousInline = new Map<string, string>();
|
|
91
|
+
let sealedEdit: PreviewElementEdit | null = null;
|
|
89
92
|
|
|
90
93
|
return runReportedDomEditCommit({
|
|
91
94
|
capture: () => {
|
|
@@ -96,7 +99,12 @@ export async function commitDomStyles(
|
|
|
96
99
|
previousInline.set(property, el.style.getPropertyValue(property));
|
|
97
100
|
},
|
|
98
101
|
apply: () => {
|
|
99
|
-
if (!editedElement)
|
|
102
|
+
if (!editedElement) {
|
|
103
|
+
sealedEdit = editSealedSelection(previewIframeRef.current, selection, {
|
|
104
|
+
styles: liveStyles,
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
100
108
|
for (const [property, value] of liveStyles) editedElement.style.setProperty(property, value);
|
|
101
109
|
if (fontFamily !== undefined && doc) {
|
|
102
110
|
injectPreviewGoogleFont(doc, fontFamily);
|
|
@@ -104,14 +112,17 @@ export async function commitDomStyles(
|
|
|
104
112
|
}
|
|
105
113
|
},
|
|
106
114
|
persist: () =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
afterSealedDraw(sealedEdit, (drawn) =>
|
|
116
|
+
persistDomEditOperations(selection, operations, {
|
|
117
|
+
label: "Edit layer style",
|
|
118
|
+
// Live styles skip the reload; a sealed frame reloads to load a new font.
|
|
119
|
+
skipRefresh: drawn && !(sealedEdit && fontFamily !== undefined),
|
|
120
|
+
importedFont: importedFont ?? undefined,
|
|
121
|
+
}),
|
|
122
|
+
),
|
|
113
123
|
shouldRevert: ownsAny,
|
|
114
124
|
revert: () => {
|
|
125
|
+
sealedEdit?.restore(owned.filter(({ isLatest }) => isLatest()).map((o) => o.property));
|
|
115
126
|
const el = editedElement;
|
|
116
127
|
if (!el) return;
|
|
117
128
|
// ponytail: background-image fit styles are not reverted here.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { GsapPreviewConvergenceError, postGsapMutation } from "./gsapMutationClient";
|
|
3
|
+
|
|
4
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
5
|
+
|
|
6
|
+
const refuse = (status: number, body: unknown) =>
|
|
7
|
+
vi.stubGlobal(
|
|
8
|
+
"fetch",
|
|
9
|
+
vi.fn(async () => new Response(JSON.stringify(body), { status })),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
describe("postGsapMutation", () => {
|
|
13
|
+
// fails without the fix: a refused mutation threw the server's words without its status.
|
|
14
|
+
it("a refused mutation keeps the server's words and its status", async () => {
|
|
15
|
+
refuse(400, { error: "No tween at that index" });
|
|
16
|
+
const refused = postGsapMutation(
|
|
17
|
+
"p",
|
|
18
|
+
"index.html",
|
|
19
|
+
{ op: "update" },
|
|
20
|
+
"Couldn't save animation",
|
|
21
|
+
);
|
|
22
|
+
await expect(refused).rejects.toBeInstanceOf(GsapPreviewConvergenceError);
|
|
23
|
+
await expect(refused).rejects.toThrow("No tween at that index (400)");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("a refusal with no words of its own keeps the fallback and the status", async () => {
|
|
27
|
+
refuse(500, {});
|
|
28
|
+
await expect(
|
|
29
|
+
postGsapMutation("p", "index.html", { op: "update" }, "Couldn't save animation"),
|
|
30
|
+
).rejects.toThrow("Couldn't save animation (500)");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { studioWriteHeaders } from "../utils/studioFileVersion";
|
|
2
2
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
3
|
-
import { heldFileWordsOf } from "../utils/studioSaveDiagnostics";
|
|
3
|
+
import { heldFileWordsOf, withStatus } from "../utils/studioSaveDiagnostics";
|
|
4
4
|
|
|
5
5
|
export class GsapPreviewConvergenceError extends Error {}
|
|
6
6
|
export class GsapOwnershipProtocolError extends GsapPreviewConvergenceError {}
|
|
@@ -43,7 +43,8 @@ export async function rollbackOwnedMutation(
|
|
|
43
43
|
);
|
|
44
44
|
if (!response.ok) {
|
|
45
45
|
throw new Error(
|
|
46
|
-
(await heldFileWordsOf(response, targetPath)) ??
|
|
46
|
+
(await heldFileWordsOf(response, targetPath)) ??
|
|
47
|
+
withStatus(`Failed to restore ${targetPath}`, response),
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
const result = (await response.json()) as { restored?: unknown; conflict?: unknown };
|
|
@@ -127,7 +128,9 @@ async function postOwnedGsapMutation(
|
|
|
127
128
|
const held = response.ok ? null : await heldFileWordsOf(response, filePath);
|
|
128
129
|
const payload: unknown = await response.json().catch(() => null);
|
|
129
130
|
if (!response.ok) {
|
|
130
|
-
throw new GsapPreviewConvergenceError(
|
|
131
|
+
throw new GsapPreviewConvergenceError(
|
|
132
|
+
held ?? withStatus(readMutationError(payload, fallback), response),
|
|
133
|
+
);
|
|
131
134
|
}
|
|
132
135
|
return readMutationStatus(payload);
|
|
133
136
|
}
|