@hyperframes/studio 0.9.59 → 0.9.63
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-bya4hgms.js → hyperframes-player-CUQxAJaE.js} +1 -1
- package/dist/assets/{index--dcfSUzI.js → index-D3rdYBVx.js} +1 -1
- package/dist/assets/{index-Bxh5lW0C.js → index-DSrTQv-k.js} +204 -204
- package/dist/assets/{pausedVideoDecoder-BKym1jA6.js → pausedVideoDecoder-BWllfjF-.js} +1 -1
- package/dist/{chunk-G6FJSL7X.js → chunk-JTUKMELR.js} +34 -6
- package/dist/{chunk-5EEM5WO4.js → chunk-ZUDVUI7K.js} +11 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.html +1 -1
- package/dist/index.js +1815 -1104
- package/dist/player.js +2 -2
- package/dist/ui.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +273 -0
- package/src/captions/components/CaptionOverlay.tsx +112 -57
- package/src/captions/components/CaptionOverlayUtils.ts +319 -33
- package/src/captions/components/CaptionPropertyPanel.tsx +17 -0
- package/src/components/editor/LayersPanel.opaque.test.ts +2 -2
- package/src/components/editor/previewDrafts.test.ts +2 -2
- package/src/components/editor/previewGestureStartRead.test.ts +2 -2
- package/src/components/editor/previewLayers.test.ts +2 -2
- package/src/components/editor/previewOverlayRects.test.ts +2 -2
- package/src/components/editor/previewPointerTargets.test.ts +2 -2
- package/src/components/editor/previewSelection.test.ts +2 -2
- package/src/components/editor/useColorGradingController.sealed.test.ts +165 -0
- package/src/components/editor/useColorGradingController.ts +20 -1
- package/src/components/editor/useColorGradingPreviews.ts +127 -43
- package/src/components/nle/AudioMeterStrip.tsx +63 -2
- package/src/components/nle/NLEPreview.test.ts +24 -0
- package/src/components/nle/NLEPreview.tsx +2 -6
- package/src/components/nle/audioSealedPreview.test.ts +254 -0
- package/src/components/nle/previewStage.ts +11 -1
- package/src/components/nle/zLaneGesture.test.ts +67 -0
- package/src/components/nle/zLaneGesture.ts +4 -0
- package/src/components/panels/VariablesPanel.test.tsx +90 -1
- package/src/components/panels/VariablesPanel.tsx +41 -17
- package/src/components/panels/renderHandoff.test.ts +86 -0
- package/src/components/panels/renderHandoff.ts +28 -0
- package/src/components/ui/Menu.test.tsx +77 -0
- package/src/components/ui/Menu.tsx +47 -4
- package/src/components/ui/Popover.tsx +5 -2
- package/src/elementAnimations.test.ts +13 -0
- package/src/hooks/timelineAudioGroupCreate.ts +57 -7
- package/src/hooks/timelineAudioGroupVolume.ts +110 -34
- package/src/hooks/useCaptionDetection.ts +175 -54
- package/src/hooks/usePersistentEditHistory.test.ts +84 -0
- package/src/hooks/usePersistentEditHistory.ts +36 -3
- package/src/index.ts +1 -0
- package/src/main.tsx +14 -11
- package/src/player/components/Timeline.newTrack.test.tsx +106 -0
- package/src/player/components/TimelineLanes.tsx +4 -2
- package/src/player/components/TimelineTrackHeader.tsx +12 -4
- package/src/player/components/clipMenuAudioItems.tsx +46 -3
- package/src/player/components/timelineRowKeys.test.ts +28 -0
- package/src/player/components/timelineRowKeys.ts +27 -0
- package/src/player/hooks/useShadowPreviewReload.ts +7 -0
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +20 -0
- package/src/player/lib/previewChannel.ts +10 -0
- package/src/utils/gsapUndoRestore.sealed.test.ts +73 -0
- package/src/utils/gsapUndoRestore.ts +66 -0
- package/src/utils/studioPendingEdits.test.ts +20 -0
- package/src/utils/studioPendingEdits.ts +11 -4
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { HF_AUDIO_GROUP_ATTR } from "@hyperframes/core/audio-groups";
|
|
1
3
|
import type { TimelineElement } from "../store/timelineElement";
|
|
4
|
+
import type { TimelineEditCallbacks } from "./timelineCallbacks";
|
|
2
5
|
import { useTimelineEditContextOptional } from "../../contexts/TimelineEditContext";
|
|
3
6
|
import { useStudioShellContextOptional } from "../../contexts/StudioContext";
|
|
4
7
|
import { usePlayerStore } from "../store/playerStore";
|
|
5
8
|
import { useLivePreviewIframe } from "../store/previewIframeStore";
|
|
6
9
|
import { clipHasSound, throwUnlessSaved, TimelineSaveError } from "./clipMenuNormalize";
|
|
7
10
|
import { openAudioGainDialog } from "./audioGainDialogStore";
|
|
8
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
offersDuck,
|
|
13
|
+
readBedCarve,
|
|
14
|
+
setDuckUnderVoice,
|
|
15
|
+
type DuckOutcome,
|
|
16
|
+
type GroupClips,
|
|
17
|
+
} from "./clipMenuDuck";
|
|
18
|
+
import { previewDocumentCopy, previewFrameOpaque } from "../lib/previewChannel";
|
|
9
19
|
|
|
10
20
|
const ITEM_CLASS =
|
|
11
21
|
"w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden text-neutral-300 hover:bg-neutral-800 focus-visible:bg-neutral-800 cursor-pointer";
|
|
@@ -17,6 +27,38 @@ const DUCK_TOAST: Record<DuckOutcome, string> = {
|
|
|
17
27
|
aborted: "Could not group the voices to duck under.",
|
|
18
28
|
};
|
|
19
29
|
|
|
30
|
+
type Copy = { iframe: HTMLIFrameElement; doc: Document | null };
|
|
31
|
+
|
|
32
|
+
function usePreviewDocument(iframe: HTMLIFrameElement | null): {
|
|
33
|
+
doc: Document | null;
|
|
34
|
+
copy: Document | null;
|
|
35
|
+
} {
|
|
36
|
+
const sealed = iframe !== null && previewFrameOpaque(iframe);
|
|
37
|
+
const [read, setRead] = useState<Copy | null>(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!iframe || !sealed) return;
|
|
40
|
+
let current = true;
|
|
41
|
+
void previewDocumentCopy(iframe).then((doc) => current && setRead({ iframe, doc }));
|
|
42
|
+
return () => {
|
|
43
|
+
current = false;
|
|
44
|
+
};
|
|
45
|
+
}, [iframe, sealed]);
|
|
46
|
+
if (!sealed) return { doc: iframe?.contentDocument ?? null, copy: null };
|
|
47
|
+
const copy = read?.iframe === iframe ? read.doc : null;
|
|
48
|
+
return { doc: copy, copy };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function voiceGrouper(
|
|
52
|
+
onGroupClips: NonNullable<TimelineEditCallbacks["onGroupClips"]>,
|
|
53
|
+
copy: Document | null,
|
|
54
|
+
): GroupClips {
|
|
55
|
+
if (!copy) return (ids, groupId) => onGroupClips(ids, groupId, "Voice");
|
|
56
|
+
return async (ids, groupId) => {
|
|
57
|
+
await onGroupClips(ids, groupId, "Voice");
|
|
58
|
+
for (const id of ids) copy.getElementById(id)?.setAttribute(HF_AUDIO_GROUP_ATTR, groupId);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
20
62
|
/** Audio Gain… (opens the G dialog) or Duck under voice (toggle), placed separately in the sound group. */
|
|
21
63
|
export function ClipMenuAudioItems({
|
|
22
64
|
part,
|
|
@@ -33,7 +75,8 @@ export function ClipMenuAudioItems({
|
|
|
33
75
|
const sessionProjectId = usePlayerStore((s) => s.timelineProjectId);
|
|
34
76
|
const projectId = shell?.projectId ?? sessionProjectId;
|
|
35
77
|
const showToast = shell?.showToast ?? onNotice;
|
|
36
|
-
const
|
|
78
|
+
const iframe = shell?.previewIframeRef.current ?? liveIframe;
|
|
79
|
+
const { doc, copy } = usePreviewDocument(iframe);
|
|
37
80
|
const bed = doc?.getElementById(element.domId ?? element.id) ?? null;
|
|
38
81
|
const ducked = bed ? readBedCarve(bed)?.enabled === true : false;
|
|
39
82
|
if (!clipHasSound(element) || !projectId || !showToast || !onSetElementAttributeQuiet) {
|
|
@@ -52,7 +95,7 @@ export function ClipMenuAudioItems({
|
|
|
52
95
|
await onSetElementAttributeQuiet(element, attr, value, "Duck under voice"),
|
|
53
96
|
);
|
|
54
97
|
},
|
|
55
|
-
onGroupClips
|
|
98
|
+
onGroupClips && voiceGrouper(onGroupClips, copy),
|
|
56
99
|
).catch((error: unknown): DuckOutcome | TimelineSaveError =>
|
|
57
100
|
error instanceof TimelineSaveError ? error : "aborted",
|
|
58
101
|
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
3
|
+
import { timelineRows } from "./timelineRowKeys";
|
|
4
|
+
|
|
5
|
+
const el = (id: string, track: number, authoredTrack?: number, tag = "div"): TimelineElement => ({
|
|
6
|
+
id,
|
|
7
|
+
tag,
|
|
8
|
+
start: 0,
|
|
9
|
+
duration: 1,
|
|
10
|
+
track,
|
|
11
|
+
...(authoredTrack === undefined ? {} : { authoredTrack }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("keys rows by zone and authored track, numbering repeats and empty lanes apart, and finds each row's clips", () => {
|
|
15
|
+
const rows = timelineRows([
|
|
16
|
+
[0, [el("a", 0, 3)]],
|
|
17
|
+
[1, [el("b", 1, 3)]],
|
|
18
|
+
[2, [el("c", 2, 3, "audio")]],
|
|
19
|
+
[3, []],
|
|
20
|
+
]);
|
|
21
|
+
expect([0, 1, 2, 3, 9].map(rows.reactKey)).toEqual([
|
|
22
|
+
"visual:3",
|
|
23
|
+
"visual:3#1",
|
|
24
|
+
"audio:3",
|
|
25
|
+
"lane:3",
|
|
26
|
+
"lane:9",
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
2
|
+
import { resolveElementTrack } from "../../utils/studioHelpers";
|
|
3
|
+
import { classifyZone } from "./timelineZones";
|
|
4
|
+
|
|
5
|
+
type Tracks = readonly (readonly [number, readonly TimelineElement[]])[];
|
|
6
|
+
const NO_CLIPS: readonly TimelineElement[] = [];
|
|
7
|
+
|
|
8
|
+
/** Each row's clips, and its React key: the clips' zone and authored track, which adding a track does not renumber
|
|
9
|
+
* as it does display lanes. Rows sharing one (overlap sub-lanes, expanded children) take a #n suffix in row order. */
|
|
10
|
+
export function timelineRows(tracks: Tracks) {
|
|
11
|
+
const seen = new Map<string, number>();
|
|
12
|
+
const keys = new Map<number, string>();
|
|
13
|
+
const clips = new Map<number, readonly TimelineElement[]>();
|
|
14
|
+
for (const [track, els] of tracks) {
|
|
15
|
+
const base = els[0]
|
|
16
|
+
? `${classifyZone(els[0])}:${resolveElementTrack(els[0])}`
|
|
17
|
+
: `lane:${track}`;
|
|
18
|
+
const repeat = seen.get(base) ?? 0;
|
|
19
|
+
seen.set(base, repeat + 1);
|
|
20
|
+
keys.set(track, repeat ? `${base}#${repeat}` : base);
|
|
21
|
+
clips.set(track, els);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
reactKey: (track: number) => keys.get(track) ?? `lane:${track}`,
|
|
25
|
+
clips: (track: number) => clips.get(track) ?? NO_CLIPS,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -86,6 +86,11 @@ function shadowPagePhase(iframe: HTMLIFrameElement | null): string {
|
|
|
86
86
|
const pageGotTo = (iframe: HTMLIFrameElement | null) =>
|
|
87
87
|
shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
|
|
88
88
|
|
|
89
|
+
function hyperframesPlayerOf(iframe: HTMLIFrameElement): Element | null {
|
|
90
|
+
const root = iframe.getRootNode();
|
|
91
|
+
return root instanceof ShadowRoot ? root.host : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
89
94
|
function isDocumentHidden(): boolean {
|
|
90
95
|
return typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
91
96
|
}
|
|
@@ -293,6 +298,7 @@ export function useShadowPreviewReload({
|
|
|
293
298
|
// The store takes the new document's timeline only now that it is the one on screen, and reads it there.
|
|
294
299
|
const retired = iframeRef.current;
|
|
295
300
|
iframeRef.current = shadow;
|
|
301
|
+
hyperframesPlayerOf(shadow)?.toggleAttribute("inert", false);
|
|
296
302
|
pending.commit();
|
|
297
303
|
shadowIframeRef.current = null;
|
|
298
304
|
attachIframeShortcutListeners();
|
|
@@ -403,6 +409,7 @@ export function useShadowPreviewReload({
|
|
|
403
409
|
|
|
404
410
|
const setShadowIframeNode = useCallback((node: HTMLIFrameElement | null) => {
|
|
405
411
|
shadowIframeRef.current = node;
|
|
412
|
+
if (node) hyperframesPlayerOf(node)?.toggleAttribute("inert", true);
|
|
406
413
|
const gen = budgetGenRef.current;
|
|
407
414
|
if (!node || !shadowFrameLeftPageRef.current || gen == null || gen !== shadowGenRef.current)
|
|
408
415
|
return;
|
|
@@ -227,6 +227,26 @@ describe("shadow reload readiness and failure", () => {
|
|
|
227
227
|
unmount(root);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
// The player turns pointer events back on for its frame, so a reload's frame would take the live one's clicks.
|
|
231
|
+
it("keeps a reload's player out of clicks and focus until it is promoted, then gives them back", () => {
|
|
232
|
+
const { getApi, gen, root } = beginReload();
|
|
233
|
+
const shadow = makeShadowWithSpies();
|
|
234
|
+
const player = document.createElement("hyperframes-player");
|
|
235
|
+
player.attachShadow({ mode: "open" }).append(shadow.iframe);
|
|
236
|
+
document.body.append(player);
|
|
237
|
+
|
|
238
|
+
act(() => getApi().setShadowIframeNode(shadow.iframe));
|
|
239
|
+
expect(player.hasAttribute("inert")).toBe(true);
|
|
240
|
+
|
|
241
|
+
act(() => {
|
|
242
|
+
getApi().onShadowIframeLoad(gen);
|
|
243
|
+
getApi().onShadowReadyChange(gen, true);
|
|
244
|
+
});
|
|
245
|
+
expect(getApi().iframeRef.current).toBe(shadow.iframe);
|
|
246
|
+
expect(player.hasAttribute("inert")).toBe(false);
|
|
247
|
+
unmount(root);
|
|
248
|
+
});
|
|
249
|
+
|
|
230
250
|
it("keeps a playing film playing through a reload, from where the live frame had reached", () => {
|
|
231
251
|
const { getApi, root } = renderTimelinePlayerHarness();
|
|
232
252
|
const { adapter: liveAdapter, win } = makeAdapterWindow();
|
|
@@ -124,3 +124,13 @@ export async function previewComputedStyles(
|
|
|
124
124
|
}
|
|
125
125
|
return read;
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
export async function previewDocumentCopy(iframe: HTMLIFrameElement): Promise<Document | null> {
|
|
129
|
+
const reply = await previewRequest(iframe, "document-markup", {});
|
|
130
|
+
if (typeof reply?.html !== "string" || typeof reply.baseURI !== "string") return null;
|
|
131
|
+
const doc = new DOMParser().parseFromString(reply.html, "text/html");
|
|
132
|
+
const base = doc.createElement("base");
|
|
133
|
+
base.setAttribute("href", reply.baseURI);
|
|
134
|
+
doc.head.prepend(base);
|
|
135
|
+
return doc;
|
|
136
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const channel = vi.hoisted(() => ({ request: vi.fn() }));
|
|
6
|
+
vi.mock("../player/lib/previewChannel", () => ({
|
|
7
|
+
previewFrameOpaque: () => true,
|
|
8
|
+
previewRequest: channel.request,
|
|
9
|
+
}));
|
|
10
|
+
import { applyUndoRestoreToPreview } from "./gsapUndoRestore";
|
|
11
|
+
|
|
12
|
+
const page = (body: string) => `<html><body>${body}</body></html>`;
|
|
13
|
+
const box = (left: number) => `<div data-hf-id="box" style="left: ${left}px">t</div>`;
|
|
14
|
+
const script = (text: string) => `<script>gsap.timeline().to("#t", ${text});</script>`;
|
|
15
|
+
|
|
16
|
+
function undo(previous: string, restored: string) {
|
|
17
|
+
const reload = vi.fn();
|
|
18
|
+
const iframe = document.createElement("iframe");
|
|
19
|
+
const files = { "index.html": { previous: page(previous), restored: page(restored) } };
|
|
20
|
+
return { reload, strategy: applyUndoRestoreToPreview(iframe, null, files, 2, reload), iframe };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
24
|
+
|
|
25
|
+
beforeEach(() => channel.request.mockReset());
|
|
26
|
+
|
|
27
|
+
describe("undo on a sealed preview", () => {
|
|
28
|
+
it("sends the restored attributes to the frame instead of reloading", async () => {
|
|
29
|
+
channel.request.mockResolvedValue({ applied: true });
|
|
30
|
+
const { reload, strategy, iframe } = undo(box(90), box(0));
|
|
31
|
+
expect(strategy).toBe("soft");
|
|
32
|
+
expect(channel.request).toHaveBeenCalledWith(iframe, "restore-attributes", {
|
|
33
|
+
scopes: [
|
|
34
|
+
{
|
|
35
|
+
file: null,
|
|
36
|
+
elements: [
|
|
37
|
+
{
|
|
38
|
+
key: "hf:box",
|
|
39
|
+
attributes: [
|
|
40
|
+
["data-hf-id", "box"],
|
|
41
|
+
["style", "left: 0px"],
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
scripted: false,
|
|
48
|
+
time: 2,
|
|
49
|
+
});
|
|
50
|
+
await settled();
|
|
51
|
+
expect(reload).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("reloads when the frame refuses or does not answer", async () => {
|
|
55
|
+
for (const reply of [{ applied: false }, null]) {
|
|
56
|
+
channel.request.mockResolvedValue(reply);
|
|
57
|
+
const { reload } = undo(box(90), box(0));
|
|
58
|
+
await settled();
|
|
59
|
+
expect(reload).toHaveBeenCalledOnce();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("says the files keep a GSAP script, and reloads at once when the script itself changed", () => {
|
|
64
|
+
channel.request.mockResolvedValue({ applied: true });
|
|
65
|
+
undo(box(90) + script("{ x: 1 }"), box(0) + script("{ x: 1 }"));
|
|
66
|
+
expect(channel.request.mock.calls[0]![2]).toMatchObject({ scripted: true });
|
|
67
|
+
channel.request.mockReset();
|
|
68
|
+
const { reload, strategy } = undo(box(90) + script("{ x: 1 }"), box(0) + script("{ x: 2 }"));
|
|
69
|
+
expect(strategy).toBe("full");
|
|
70
|
+
expect(reload).toHaveBeenCalledOnce();
|
|
71
|
+
expect(channel.request).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -15,6 +15,8 @@ import { ensureHfIds, isCompositionTemplate } from "@hyperframes/parsers/hf-ids"
|
|
|
15
15
|
import { findAuthoredElement, parseSavedSource } from "./authoredSource";
|
|
16
16
|
import { STUDIO_EDIT_ATTRS } from "../components/editor/manualEditsSeekReapply";
|
|
17
17
|
import { markScenesStale } from "../player/sceneSwap";
|
|
18
|
+
import { previewFrameOpaque, previewRequest } from "../player/lib/previewChannel";
|
|
19
|
+
import type { EditingParams } from "@hyperframes/core/runtime/editing-port";
|
|
18
20
|
import { STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR } from "../components/editor/manualEditsTypes";
|
|
19
21
|
import { countStudioPreviewChange, studioGestureDraws } from "../components/editor/manualEditsDom";
|
|
20
22
|
|
|
@@ -356,6 +358,68 @@ function repaintWhileReloading(win: PreviewWindow, doc: Document, restored?: str
|
|
|
356
358
|
);
|
|
357
359
|
}
|
|
358
360
|
|
|
361
|
+
type SealedRestore = Omit<EditingParams<"restore-attributes">, "time">;
|
|
362
|
+
|
|
363
|
+
const restoredAttributes = (el: Element): [string, string][] =>
|
|
364
|
+
el.getAttributeNames().map((name) => [name, el.getAttribute(name) ?? ""]);
|
|
365
|
+
|
|
366
|
+
// The preview server stamps data-hf-id on every page it serves.
|
|
367
|
+
const stamped = (html: string) => (html.includes("data-hf-id") ? html : ensureHfIds(html));
|
|
368
|
+
|
|
369
|
+
type SealedFile = { scripted: boolean; elements: SealedRestore["scopes"][number]["elements"] };
|
|
370
|
+
|
|
371
|
+
/** One file's changed elements with their restored attributes, or null when it needs a reload. */
|
|
372
|
+
function sealedFile(file: UndoRestoreFile, isActive: boolean): SealedFile | null {
|
|
373
|
+
// A changed script is re-run in the frame, which a sealed preview cannot be asked to do yet.
|
|
374
|
+
if (extractGsapScriptText(file.restored) !== extractGsapScriptText(file.previous)) return null;
|
|
375
|
+
const prevDoc = parseRestoreSource(stamped(file.previous));
|
|
376
|
+
const nextDoc = parseRestoreSource(stamped(file.restored));
|
|
377
|
+
const scripted = restoreScripted(prevDoc, nextDoc, isActive);
|
|
378
|
+
const keys = diffRestoreDocs(prevDoc, nextDoc);
|
|
379
|
+
const restoredByKey = identityElementMap(nextDoc);
|
|
380
|
+
if (scripted === null || !keys || !restoredByKey) return null;
|
|
381
|
+
const elements = keys.map((key) => ({
|
|
382
|
+
key,
|
|
383
|
+
attributes: restoredAttributes(restoredByKey.get(key)!),
|
|
384
|
+
}));
|
|
385
|
+
return { scripted, elements };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** A sealed preview's in-place restore from the files alone, or null when it needs a reload. */
|
|
389
|
+
function sealedRestore(activeDocPath: string, files: RestoreFiles): SealedRestore | null {
|
|
390
|
+
const restore: SealedRestore = { scopes: [], scripted: false };
|
|
391
|
+
for (const [path, file] of Object.entries(files)) {
|
|
392
|
+
const isActive = path === activeDocPath;
|
|
393
|
+
const found = sealedFile(file, isActive);
|
|
394
|
+
if (!found) return null;
|
|
395
|
+
restore.scripted ||= found.scripted;
|
|
396
|
+
if (found.elements.length)
|
|
397
|
+
restore.scopes.push({ file: isActive ? null : path, elements: found.elements });
|
|
398
|
+
}
|
|
399
|
+
return restore.scopes.length ? restore : null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Sends the restore to a sealed preview; a refusal, or no answer, reloads it. */
|
|
403
|
+
function applySealedRestore(
|
|
404
|
+
iframe: HTMLIFrameElement,
|
|
405
|
+
activeDocPath: string,
|
|
406
|
+
files: RestoreFiles,
|
|
407
|
+
currentTime: number,
|
|
408
|
+
reloadPreview: () => void,
|
|
409
|
+
): "soft" | "full" {
|
|
410
|
+
const restore = sealedRestore(activeDocPath, files);
|
|
411
|
+
if (!restore) {
|
|
412
|
+
reloadPreview();
|
|
413
|
+
return "full";
|
|
414
|
+
}
|
|
415
|
+
void previewRequest(iframe, "restore-attributes", { ...restore, time: currentTime }).then(
|
|
416
|
+
(reply) => {
|
|
417
|
+
if (!reply?.applied) reloadPreview();
|
|
418
|
+
},
|
|
419
|
+
);
|
|
420
|
+
return "soft";
|
|
421
|
+
}
|
|
422
|
+
|
|
359
423
|
/**
|
|
360
424
|
* Soft-apply an undo/redo restore to the live preview WITHOUT a full iframe
|
|
361
425
|
* remount (which blanks the frame black and re-flashes the WebGL context). Eligible
|
|
@@ -402,6 +466,8 @@ export function applyUndoRestoreToPreview(
|
|
|
402
466
|
markScenesStale(iframe, paths);
|
|
403
467
|
reload();
|
|
404
468
|
};
|
|
469
|
+
if (iframe && files && previewFrameOpaque(iframe))
|
|
470
|
+
return applySealedRestore(iframe, activeDocPath, files, currentTime, reloadPreview);
|
|
405
471
|
const doc = iframe?.contentDocument;
|
|
406
472
|
const win = iframe?.contentWindow as PreviewWindow | null;
|
|
407
473
|
const plan = doc && files && win ? planRestoreTargets(doc, activeDocPath, files) : null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
import {
|
|
4
|
+
setStudioPendingEditsSettled,
|
|
4
5
|
addStudioPendingEditFlushListener,
|
|
5
6
|
adoptingStudioPendingEdit,
|
|
6
7
|
beginStudioPendingEdit,
|
|
@@ -514,3 +515,22 @@ it("counts an edit whose later write failed as saved once an earlier write lande
|
|
|
514
515
|
const shown = paintBackNewestStudioPendingEdit()!;
|
|
515
516
|
await expect(shown.landed()).resolves.toBe(true);
|
|
516
517
|
});
|
|
518
|
+
|
|
519
|
+
describe("every pending edit settled", () => {
|
|
520
|
+
it("is told once, when the last of two overlapping edits settles", async () => {
|
|
521
|
+
const told = vi.fn();
|
|
522
|
+
setStudioPendingEditsSettled(told);
|
|
523
|
+
try {
|
|
524
|
+
const first = beginStudioPendingEdit(null);
|
|
525
|
+
const second = beginStudioPendingEdit(null);
|
|
526
|
+
first.settle();
|
|
527
|
+
await Promise.resolve();
|
|
528
|
+
await Promise.resolve();
|
|
529
|
+
expect(told).not.toHaveBeenCalled();
|
|
530
|
+
second.settle();
|
|
531
|
+
await vi.waitFor(() => expect(told).toHaveBeenCalledOnce());
|
|
532
|
+
} finally {
|
|
533
|
+
setStudioPendingEditsSettled(null);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
});
|
|
@@ -33,6 +33,12 @@ let historyClaims: () => number = () => 0;
|
|
|
33
33
|
export function setStudioPendingEditClaimClock(read: (() => number) | null): void {
|
|
34
34
|
historyClaims = read ?? (() => 0);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
let allSettled: (() => void) | null = null;
|
|
38
|
+
|
|
39
|
+
export function setStudioPendingEditsSettled(run: (() => void) | null): void {
|
|
40
|
+
allSettled = run;
|
|
41
|
+
}
|
|
36
42
|
const NOT_SAVED = () => Promise.resolve(false);
|
|
37
43
|
let cancelWaitingPress: (() => boolean) | null = null;
|
|
38
44
|
|
|
@@ -119,10 +125,11 @@ export function trackStudioPendingEdit(
|
|
|
119
125
|
showAgain: null,
|
|
120
126
|
claimsAtBegin: historyClaims(),
|
|
121
127
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
()
|
|
125
|
-
|
|
128
|
+
const done = () => {
|
|
129
|
+
pendingEdits.delete(promise);
|
|
130
|
+
if (!pendingEdits.size) allSettled?.();
|
|
131
|
+
};
|
|
132
|
+
promise.then(done, done);
|
|
126
133
|
return promise;
|
|
127
134
|
}
|
|
128
135
|
|