@hyperframes/studio 0.8.81 → 0.8.82
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-C68UawR3.js → hyperframes-player-zGIbZhLJ.js} +1 -1
- package/dist/assets/{index-CMzPGv9P.js → index-BiLCTunu.js} +1 -1
- package/dist/assets/{index-hNVM9Pd2.js → index-DSazIt7R.js} +189 -189
- package/dist/assets/{index-CS5SImRT.js → index-DStmfnpZ.js} +1 -1
- package/dist/index.d.ts +172 -7
- package/dist/index.html +1 -1
- package/dist/index.js +2414 -2172
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/components/TimelineHistoryButtons.dom.test.tsx +38 -1
- package/src/components/TimelineHistoryButtons.tsx +26 -14
- package/src/components/TimelineToolbar.test.tsx +9 -1
- package/src/components/TimelineToolbar.tsx +13 -5
- package/src/components/editor/BlockParamsPanel.tsx +14 -10
- package/src/components/editor/anchoredResizeReleaseShift.test.ts +2 -6
- package/src/components/editor/manualEdits.test.ts +24 -0
- package/src/components/editor/manualEdits.ts +6 -2
- package/src/components/editor/manualEditsDom.ts +0 -65
- package/src/components/editor/manualEditsSeekReapply.ts +136 -0
- package/src/components/editor/propertyPanelAudioFxGroup.test.tsx +71 -32
- package/src/components/editor/propertyPanelFlatMediaSection.test.tsx +62 -0
- package/src/components/editor/propertyPanelFlatMediaSection.tsx +4 -6
- package/src/components/editor/propertyPanelHelpers.ts +15 -0
- package/src/components/editor/propertyPanelMediaSection.tsx +3 -5
- package/src/components/editor/reapplyBoxSizeAfterSeek.test.ts +1 -1
- package/src/components/editor/reapplyPositionEditsAfterSeek.test.ts +117 -0
- package/src/components/editor/useFxLevelling.ts +35 -10
- package/src/components/nle/AudioMeterStrip.test.tsx +26 -3
- package/src/components/nle/AudioMeterStrip.tsx +23 -12
- package/src/components/pointerTargetSize.test.tsx +1 -1
- package/src/components/studioColorGradingScope.ts +12 -36
- package/src/contexts/TimelineEditContext.test.tsx +49 -0
- package/src/contexts/TimelineEditContext.tsx +27 -23
- package/src/hooks/canvasQuickSaves.test.tsx +195 -0
- package/src/hooks/gsapMutationClient.ts +116 -0
- package/src/hooks/resizeObserverTestUtils.ts +14 -0
- package/src/hooks/timelineAudioGroupCreate.ts +18 -40
- package/src/hooks/timelineEditingHelpers.test.ts +21 -0
- package/src/hooks/timelineEditingHelpers.ts +66 -61
- package/src/hooks/timelineQuickSaves.test.ts +195 -0
- package/src/hooks/timelineTimingSync.test.ts +12 -0
- package/src/hooks/timelineTimingSync.ts +31 -123
- package/src/hooks/timelineTrackVisibility.ts +15 -29
- package/src/hooks/useAskAgentModal.test.tsx +78 -0
- package/src/hooks/useAskAgentModal.ts +3 -1
- package/src/hooks/useClipboard.source.test.ts +32 -0
- package/src/hooks/useClipboard.ts +21 -20
- package/src/hooks/useDomEditCommits.test.tsx +13 -9
- package/src/hooks/useDomEditCommits.ts +88 -97
- package/src/hooks/useDomEditCommitsHelpers.ts +69 -6
- package/src/hooks/useEditorSave.ts +1 -1
- package/src/hooks/useElementLifecycleOps.ts +36 -37
- package/src/hooks/useFileManager.projectOwnership.test.tsx +51 -4
- package/src/hooks/useFileManager.ts +21 -12
- package/src/hooks/useGroupCommits.ts +23 -24
- package/src/hooks/useGsapAnimationOps.ts +26 -8
- package/src/hooks/useGsapScriptCommits.ts +1 -0
- package/src/hooks/useThumbnailStripSize.test.tsx +47 -0
- package/src/hooks/useThumbnailStripSize.ts +31 -0
- package/src/hooks/useTimelineAssetDropOps.ts +38 -35
- package/src/hooks/useTimelineDeleteOps.ts +53 -56
- package/src/hooks/useTimelineEditing.ts +3 -1
- package/src/hooks/useTimelineGroupEditing.ts +5 -1
- package/src/index.ts +8 -0
- package/src/player/components/CompositionThumbnail.test.ts +40 -6
- package/src/player/components/CompositionThumbnail.tsx +6 -21
- package/src/player/components/ImageThumbnail.test.tsx +27 -6
- package/src/player/components/ImageThumbnail.tsx +4 -18
- package/src/player/components/PlayerControls.test.tsx +52 -0
- package/src/player/components/PlayerControls.tsx +2 -1
- package/src/player/components/Timeline.test.ts +28 -3
- package/src/player/components/TimelineCanvas.tsx +5 -3
- package/src/player/components/VideoThumbnail.test.tsx +33 -11
- package/src/player/components/VideoThumbnail.tsx +7 -29
- package/src/player/components/thumbnailUtils.test.ts +16 -20
- package/src/player/components/thumbnailUtils.ts +6 -7
- package/src/player/components/timelineEditing.test.ts +55 -0
- package/src/player/components/timelineGroupEditing.ts +13 -6
- package/src/player/components/timelinePlayheadTransform.test.ts +33 -0
- package/src/player/components/timelinePlayheadTransform.ts +17 -0
- package/src/player/components/useTimelinePlayhead.ts +26 -8
- package/src/player/hooks/timelinePlayerSync.test.ts +20 -0
- package/src/player/hooks/timelinePlayerSync.ts +18 -8
- package/src/player/hooks/useShadowPreviewReload.ts +15 -4
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +19 -0
- package/src/player/hooks/useTimelinePlayer.test.ts +93 -1
- package/src/player/lib/playbackShortcuts.ts +18 -0
- package/src/player/lib/playbackTypes.ts +1 -0
- package/src/player/lib/timelineDOM.test.ts +92 -0
- package/src/player/lib/timelineDOM.ts +0 -2
- package/src/player/lib/timelineElementHelpers.ts +47 -10
- package/src/player/lib/timelineViewportBudgets.ts +1 -1
- package/src/player/store/timelineElement.ts +2 -1
- package/src/timelineChromeExports.test.tsx +79 -0
- package/src/utils/authoredSource.ts +15 -0
- package/src/utils/blockInstaller.ts +32 -27
- package/src/utils/studioFileHistory.test.ts +14 -14
- package/src/utils/studioFileHistory.ts +31 -2
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
serializeStudioFileMutation,
|
|
4
|
+
type StudioProjectFileWriter,
|
|
5
|
+
} from "../utils/studioFileMutationCoordinator";
|
|
2
6
|
import type { Composition } from "@hyperframes/sdk";
|
|
3
7
|
import type { DomEditSelection } from "../components/editor/domEditingTypes";
|
|
4
8
|
import { roundTo3 } from "../utils/rounding";
|
|
@@ -27,6 +31,7 @@ interface GsapAnimationOpsParams extends SdkAnimationDeps {
|
|
|
27
31
|
commitMutation: CommitMutation;
|
|
28
32
|
commitMutationSafely: SafeGsapCommitMutation;
|
|
29
33
|
showToast: (message: string, tone?: "error" | "info") => void;
|
|
34
|
+
writeProjectFile?: StudioProjectFileWriter;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
export function useGsapAnimationOps({
|
|
@@ -37,6 +42,7 @@ export function useGsapAnimationOps({
|
|
|
37
42
|
showToast,
|
|
38
43
|
sdkSession,
|
|
39
44
|
sdkDeps,
|
|
45
|
+
writeProjectFile,
|
|
40
46
|
}: GsapAnimationOpsParams) {
|
|
41
47
|
const updateGsapMeta = useCallback(
|
|
42
48
|
async (
|
|
@@ -122,13 +128,17 @@ export function useGsapAnimationOps({
|
|
|
122
128
|
const pid = projectIdRef.current;
|
|
123
129
|
const targetPath = selection.sourceFile || activeCompPath || "index.html";
|
|
124
130
|
if (!pid) return;
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
const assign = () =>
|
|
132
|
+
assignGsapTargetAutoIdIfNeeded({
|
|
133
|
+
projectId: pid,
|
|
134
|
+
targetPath,
|
|
135
|
+
selection,
|
|
136
|
+
autoId,
|
|
137
|
+
showToast,
|
|
138
|
+
});
|
|
139
|
+
const assigned = await (writeProjectFile
|
|
140
|
+
? serializeStudioFileMutation(writeProjectFile, targetPath, assign)
|
|
141
|
+
: assign());
|
|
132
142
|
if (!assigned) return;
|
|
133
143
|
}
|
|
134
144
|
|
|
@@ -181,7 +191,15 @@ export function useGsapAnimationOps({
|
|
|
181
191
|
{ label: `Add GSAP ${method} animation`, softReload: true },
|
|
182
192
|
);
|
|
183
193
|
},
|
|
184
|
-
[
|
|
194
|
+
[
|
|
195
|
+
activeCompPath,
|
|
196
|
+
commitMutation,
|
|
197
|
+
projectIdRef,
|
|
198
|
+
showToast,
|
|
199
|
+
sdkSession,
|
|
200
|
+
sdkDeps,
|
|
201
|
+
writeProjectFile,
|
|
202
|
+
],
|
|
185
203
|
);
|
|
186
204
|
|
|
187
205
|
type KeyframeEntry = {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { MockResizeObserver, reportResize } from "./resizeObserverTestUtils";
|
|
6
|
+
import { useThumbnailStripSize } from "./useThumbnailStripSize";
|
|
7
|
+
|
|
8
|
+
Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
|
|
9
|
+
|
|
10
|
+
it("does not re-render the strip when the observer reports the size it already holds", () => {
|
|
11
|
+
const originalResizeObserver = globalThis.ResizeObserver;
|
|
12
|
+
globalThis.ResizeObserver = MockResizeObserver as unknown as typeof ResizeObserver;
|
|
13
|
+
const host = document.createElement("div");
|
|
14
|
+
document.body.append(host);
|
|
15
|
+
Object.defineProperty(host, "clientWidth", { configurable: true, value: 300 });
|
|
16
|
+
Object.defineProperty(host, "clientHeight", { configurable: true, value: 40 });
|
|
17
|
+
const root = createRoot(host);
|
|
18
|
+
let stripRenders = 0;
|
|
19
|
+
function Strip({ label }: { label: string }) {
|
|
20
|
+
stripRenders += 1;
|
|
21
|
+
return label;
|
|
22
|
+
}
|
|
23
|
+
function Harness() {
|
|
24
|
+
const [size, ref] = useThumbnailStripSize();
|
|
25
|
+
return (
|
|
26
|
+
<div ref={ref}>
|
|
27
|
+
<Strip label={`${size.width}x${size.height}`} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
act(() => root.render(<Harness />));
|
|
33
|
+
expect(host.textContent).toBe("300x40");
|
|
34
|
+
const settled = stripRenders;
|
|
35
|
+
|
|
36
|
+
act(() => reportResize(300, 40));
|
|
37
|
+
expect(stripRenders).toBe(settled);
|
|
38
|
+
|
|
39
|
+
act(() => reportResize(320, 40));
|
|
40
|
+
expect(stripRenders).toBe(settled + 1);
|
|
41
|
+
expect(host.textContent).toBe("320x40");
|
|
42
|
+
} finally {
|
|
43
|
+
act(() => root.unmount());
|
|
44
|
+
host.remove();
|
|
45
|
+
globalThis.ResizeObserver = originalResizeObserver;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
import { useMountEffect } from "./useMountEffect";
|
|
3
|
+
|
|
4
|
+
interface StripSize {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const resize = (width: number, height: number) => (prev: StripSize) =>
|
|
10
|
+
prev.width === width && prev.height === height ? prev : { width, height };
|
|
11
|
+
|
|
12
|
+
/** Size of the thumbnail's parent, kept current by a ResizeObserver; 0x0 until measured. */
|
|
13
|
+
export function useThumbnailStripSize() {
|
|
14
|
+
const [size, setSize] = useState<StripSize>({ width: 0, height: 0 });
|
|
15
|
+
const observerRef = useRef<ResizeObserver | null>(null);
|
|
16
|
+
|
|
17
|
+
const ref = useCallback((element: HTMLDivElement | null) => {
|
|
18
|
+
observerRef.current?.disconnect();
|
|
19
|
+
if (!element) return;
|
|
20
|
+
const target = element.parentElement ?? element;
|
|
21
|
+
setSize(resize(target.clientWidth, target.clientHeight));
|
|
22
|
+
observerRef.current = new ResizeObserver(([entry]) =>
|
|
23
|
+
setSize(resize(entry.contentRect.width, entry.contentRect.height)),
|
|
24
|
+
);
|
|
25
|
+
observerRef.current.observe(target);
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
useMountEffect(() => () => observerRef.current?.disconnect());
|
|
29
|
+
|
|
30
|
+
return [size, ref] as const;
|
|
31
|
+
}
|
|
@@ -109,8 +109,6 @@ export function useTimelineAssetDropOps({
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
try {
|
|
112
|
-
const originalContent = await readFileContent(pid, targetPath);
|
|
113
|
-
|
|
114
112
|
const normalizedStart = Number(formatTimelineAttributeNumber(placement.start));
|
|
115
113
|
const duration =
|
|
116
114
|
Number.isFinite(durationOverride) && durationOverride != null && durationOverride > 0
|
|
@@ -120,7 +118,6 @@ export function useTimelineAssetDropOps({
|
|
|
120
118
|
// A video with an audio stream lands audible; the mixer only hears a
|
|
121
119
|
// <video> marked data-has-audio, and a muted drop was losing the sound.
|
|
122
120
|
const hasAudio = await resolveDroppedAssetHasAudio(pid, assetPath, kind);
|
|
123
|
-
const newId = buildTimelineAssetId(assetPath, collectHtmlIds(originalContent));
|
|
124
121
|
const resolvedAssetSrc = resolveTimelineAssetSrc(targetPath, assetPath);
|
|
125
122
|
|
|
126
123
|
const resolvedTargetPath = targetPath || "index.html";
|
|
@@ -129,45 +126,51 @@ export function useTimelineAssetDropOps({
|
|
|
129
126
|
);
|
|
130
127
|
const newElementZIndex = Math.max(1, relevantElements.length + 1);
|
|
131
128
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
const patchedContent = extendRootDurationInSource(
|
|
145
|
-
insertTimelineAssetIntoSource(
|
|
146
|
-
sourceWithRoom,
|
|
147
|
-
buildTimelineAssetInsertHtml({
|
|
129
|
+
let newId = "";
|
|
130
|
+
let track = 0;
|
|
131
|
+
const insertAsset = (originalContent: string) => {
|
|
132
|
+
newId = buildTimelineAssetId(assetPath, collectHtmlIds(originalContent));
|
|
133
|
+
const resolved = resolveDropTrack({
|
|
134
|
+
source: originalContent,
|
|
135
|
+
// insertRow counts the rows the timeline shows, so plan against those.
|
|
136
|
+
elements: relevantElements,
|
|
137
|
+
placement,
|
|
138
|
+
dropped: {
|
|
148
139
|
id: newId,
|
|
149
|
-
|
|
150
|
-
assetPath: resolvedAssetSrc,
|
|
151
|
-
kind,
|
|
140
|
+
tag: kind === "image" ? "img" : kind,
|
|
152
141
|
start: normalizedStart,
|
|
153
142
|
duration: normalizedDuration,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
track = resolved.track;
|
|
146
|
+
return extendRootDurationInSource(
|
|
147
|
+
insertTimelineAssetIntoSource(
|
|
148
|
+
resolved.source,
|
|
149
|
+
buildTimelineAssetInsertHtml({
|
|
150
|
+
id: newId,
|
|
151
|
+
hfId: `hf-${generateId()}`,
|
|
152
|
+
assetPath: resolvedAssetSrc,
|
|
153
|
+
kind,
|
|
154
|
+
start: normalizedStart,
|
|
155
|
+
duration: normalizedDuration,
|
|
156
|
+
track,
|
|
157
|
+
zIndex: newElementZIndex,
|
|
158
|
+
hasAudio,
|
|
159
|
+
geometry: fitTimelineAssetGeometry(
|
|
160
|
+
null,
|
|
161
|
+
resolveTimelineAssetCompositionSize(originalContent),
|
|
162
|
+
),
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
normalizedStart + normalizedDuration,
|
|
166
|
+
);
|
|
167
|
+
};
|
|
165
168
|
|
|
166
169
|
await saveProjectFilesWithHistory({
|
|
167
170
|
projectId: pid,
|
|
168
171
|
label: "Add timeline asset",
|
|
169
|
-
files: { [targetPath]:
|
|
170
|
-
readFile:
|
|
172
|
+
files: { [targetPath]: insertAsset },
|
|
173
|
+
readFile: (path) => readFileContent(pid, path),
|
|
171
174
|
writeFile: writeProjectFile,
|
|
172
175
|
recordEdit,
|
|
173
176
|
});
|
|
@@ -5,11 +5,11 @@ import { buildProjectApiPath } from "../utils/projectRouting";
|
|
|
5
5
|
import { useCallback, useRef, type MutableRefObject, type RefObject } from "react";
|
|
6
6
|
import type { TimelineElement } from "../player";
|
|
7
7
|
import { usePlayerStore } from "../player";
|
|
8
|
-
import {
|
|
8
|
+
import { saveServerRewriteWithHistory, type RecordEditInput } from "../utils/studioFileHistory";
|
|
9
9
|
import { studioWriteHeaders } from "../utils/studioFileVersion";
|
|
10
10
|
import { getTimelineElementLabel } from "../utils/studioHelpers";
|
|
11
11
|
import { buildPatchTarget, removeIframeTimelineElements } from "./timelineEditingHelpers";
|
|
12
|
-
import { captureDurationRollback
|
|
12
|
+
import { captureDurationRollback } from "./timelineTimingSync";
|
|
13
13
|
import { setCompositionDurationToContent } from "../utils/timelineAssetDrop";
|
|
14
14
|
import { furthestClipEndFromSource } from "../player/lib/timelineElementHelpers";
|
|
15
15
|
import {
|
|
@@ -100,71 +100,68 @@ export function useTimelineDeleteOps({
|
|
|
100
100
|
(candidate) => (candidate.sourceFile || activeCompPath || "index.html") === targetPath,
|
|
101
101
|
);
|
|
102
102
|
try {
|
|
103
|
-
const originalContent = await readFileContent(pid, targetPath);
|
|
104
|
-
|
|
105
|
-
// Remove every selected element before saving once. The server rewrites
|
|
106
|
-
// the file per call, so `removedContent` after the last one holds them
|
|
107
|
-
// all — which is what makes this a single history entry, and a single
|
|
108
|
-
// undo, rather than one per clip.
|
|
109
|
-
let removedContent = originalContent;
|
|
110
|
-
for (const target of sameFile) {
|
|
111
|
-
const patchTarget = buildPatchTarget(target);
|
|
112
|
-
if (!patchTarget) {
|
|
113
|
-
throw new Error(`Timeline element ${target.id} is missing a patchable target`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const removeResponse = await fetch(
|
|
117
|
-
buildProjectApiPath(
|
|
118
|
-
pid,
|
|
119
|
-
`/file-mutations/remove-element/${encodeURIComponent(targetPath)}`,
|
|
120
|
-
),
|
|
121
|
-
{
|
|
122
|
-
method: "POST",
|
|
123
|
-
headers: { "Content-Type": "application/json", ...studioWriteHeaders() },
|
|
124
|
-
body: JSON.stringify({ target: patchTarget }),
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
if (!removeResponse.ok) {
|
|
128
|
-
throw new Error(`Failed to delete ${target.id} from ${targetPath}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const removeData = (await removeResponse.json()) as {
|
|
132
|
-
changed?: boolean;
|
|
133
|
-
content?: string;
|
|
134
|
-
};
|
|
135
|
-
if (typeof removeData.content === "string") removedContent = removeData.content;
|
|
136
|
-
}
|
|
137
|
-
// Content-driven duration: shrink the composition to the furthest
|
|
138
|
-
// remaining clip end, read from the post-removal SOURCE (raw
|
|
139
|
-
// data-duration), so deleting the last/longest clip removes trailing
|
|
140
|
-
// empty space. Measured from the source, not the store, whose
|
|
141
|
-
// durations are runtime-truncated.
|
|
142
|
-
const deleteContentEnd = furthestClipEndFromSource(removedContent);
|
|
143
|
-
const patchedContent = setCompositionDurationToContent(removedContent, deleteContentEnd);
|
|
144
|
-
// Optimistically reflect the shrunk length in the readout/seek bar,
|
|
145
|
-
// rolling it back if the persist below fails (see captureDurationRollback).
|
|
146
|
-
const rollbackDuration = captureDurationRollback(previewIframeRef.current);
|
|
147
|
-
if (deleteContentEnd > 0 && targetPath === (activeCompPath || "index.html")) {
|
|
148
|
-
usePlayerStore.getState().setDuration(deleteContentEnd);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
103
|
// Shared with the ripple move below so a folded ripple is one undo
|
|
152
104
|
// step with the delete, not two (editHistory.ts coalesces by key +
|
|
153
105
|
// window across separate recordEdit calls, not by label).
|
|
154
106
|
const coalesceKey = `main-track-ripple-delete:${deleteGestureSeq++}`;
|
|
155
107
|
const deleteHistoryLabel = "Delete timeline clip";
|
|
108
|
+
let rollbackDuration = () => {};
|
|
156
109
|
try {
|
|
157
|
-
await
|
|
110
|
+
await saveServerRewriteWithHistory({
|
|
158
111
|
projectId: pid,
|
|
112
|
+
path: targetPath,
|
|
159
113
|
label: deleteHistoryLabel,
|
|
160
114
|
coalesceKey,
|
|
161
|
-
files: { [targetPath]: patchedContent },
|
|
162
|
-
readFile: async () => originalContent,
|
|
163
|
-
// remove-element already wrote the removal, so disk holds THAT — not the
|
|
164
|
-
// content read at the top. Undo still goes back to the original.
|
|
165
|
-
diskContent: { [targetPath]: removedContent },
|
|
166
115
|
writeFile: writeProjectFile,
|
|
167
116
|
recordEdit,
|
|
117
|
+
rewrite: async (originalContent) => {
|
|
118
|
+
// Remove every selected element before saving once. The server rewrites
|
|
119
|
+
// the file per call, so `removedContent` after the last one holds them
|
|
120
|
+
// all — which is what makes this a single history entry, and a single
|
|
121
|
+
// undo, rather than one per clip.
|
|
122
|
+
let removedContent = originalContent;
|
|
123
|
+
for (const target of sameFile) {
|
|
124
|
+
const patchTarget = buildPatchTarget(target);
|
|
125
|
+
if (!patchTarget) {
|
|
126
|
+
throw new Error(`Timeline element ${target.id} is missing a patchable target`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const removeResponse = await fetch(
|
|
130
|
+
buildProjectApiPath(
|
|
131
|
+
pid,
|
|
132
|
+
`/file-mutations/remove-element/${encodeURIComponent(targetPath)}`,
|
|
133
|
+
),
|
|
134
|
+
{
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "Content-Type": "application/json", ...studioWriteHeaders() },
|
|
137
|
+
body: JSON.stringify({ target: patchTarget }),
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
if (!removeResponse.ok) {
|
|
141
|
+
throw new Error(`Failed to delete ${target.id} from ${targetPath}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const removeData = (await removeResponse.json()) as {
|
|
145
|
+
changed?: boolean;
|
|
146
|
+
content?: string;
|
|
147
|
+
};
|
|
148
|
+
if (typeof removeData.content === "string") removedContent = removeData.content;
|
|
149
|
+
}
|
|
150
|
+
// Shrink to the furthest remaining clip end, read from the post-removal source:
|
|
151
|
+
// store durations are runtime-truncated.
|
|
152
|
+
const deleteContentEnd = furthestClipEndFromSource(removedContent);
|
|
153
|
+
const patchedContent = setCompositionDurationToContent(
|
|
154
|
+
removedContent,
|
|
155
|
+
deleteContentEnd,
|
|
156
|
+
);
|
|
157
|
+
// Optimistically reflect the shrunk length in the readout/seek bar,
|
|
158
|
+
// rolling it back if the persist below fails (see captureDurationRollback).
|
|
159
|
+
rollbackDuration = captureDurationRollback(previewIframeRef.current);
|
|
160
|
+
if (deleteContentEnd > 0 && targetPath === (activeCompPath || "index.html")) {
|
|
161
|
+
usePlayerStore.getState().setDuration(deleteContentEnd);
|
|
162
|
+
}
|
|
163
|
+
return { disk: removedContent, after: patchedContent };
|
|
164
|
+
},
|
|
168
165
|
});
|
|
169
166
|
} catch (error) {
|
|
170
167
|
rollbackDuration();
|
|
@@ -8,7 +8,6 @@ import { useTimelineAssetDropOps } from "./useTimelineAssetDropOps";
|
|
|
8
8
|
import {
|
|
9
9
|
applyTimelineStackingReorder,
|
|
10
10
|
patchIframeDomTiming,
|
|
11
|
-
playbackStartAttributeForElement,
|
|
12
11
|
persistTimelineEdit,
|
|
13
12
|
formatTimelineAttributeNumber,
|
|
14
13
|
formatTimelineMediaOffset,
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
buildTimelineMoveTimingPatch,
|
|
17
16
|
buildTimelineResizeTimingPatch,
|
|
18
17
|
} from "./timelineEditingHelpers";
|
|
18
|
+
import { playbackStartAttributeForElement } from "../player/lib/timelineElementHelpers";
|
|
19
19
|
import {
|
|
20
20
|
captureDurationRollback,
|
|
21
21
|
finishClipTimingFallback,
|
|
@@ -243,6 +243,7 @@ export function useTimelineEditing({
|
|
|
243
243
|
label: "Move timeline clip",
|
|
244
244
|
coalesceKey,
|
|
245
245
|
recordEdit,
|
|
246
|
+
writeProjectFile,
|
|
246
247
|
edit: { kind: "shift", delta: updates.start - element.start },
|
|
247
248
|
}).finally(() => invalidateGsapCache?.());
|
|
248
249
|
const moveFallback = () =>
|
|
@@ -346,6 +347,7 @@ export function useTimelineEditing({
|
|
|
346
347
|
label: "Resize timeline clip",
|
|
347
348
|
coalesceKey,
|
|
348
349
|
recordEdit,
|
|
350
|
+
writeProjectFile,
|
|
349
351
|
edit: {
|
|
350
352
|
kind: "scale",
|
|
351
353
|
from: { start: element.start, duration: element.duration },
|
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
formatTimelineAttributeNumber,
|
|
16
16
|
formatTimelineMediaOffset,
|
|
17
17
|
patchIframeDomTiming,
|
|
18
|
-
playbackStartAttributeForElement,
|
|
19
18
|
persistTimelineBatchEdit,
|
|
20
19
|
type PersistTimelineBatchChange,
|
|
21
20
|
type RecordEditInput,
|
|
22
21
|
} from "./timelineEditingHelpers";
|
|
22
|
+
import { playbackStartAttributeForElement } from "../player/lib/timelineElementHelpers";
|
|
23
23
|
import {
|
|
24
24
|
captureDurationRollback,
|
|
25
25
|
finishGroupTimingGsapFallback,
|
|
@@ -330,6 +330,7 @@ export function useTimelineGroupEditing({
|
|
|
330
330
|
errorLabel: "Failed to shift GSAP positions",
|
|
331
331
|
coalesceKey,
|
|
332
332
|
recordEdit,
|
|
333
|
+
writeProjectFile,
|
|
333
334
|
activeCompPath,
|
|
334
335
|
changes,
|
|
335
336
|
resolveChangePath: (element) => targetPathFor(element, activeCompPath),
|
|
@@ -365,6 +366,7 @@ export function useTimelineGroupEditing({
|
|
|
365
366
|
trySdkBatchPersist,
|
|
366
367
|
showToast,
|
|
367
368
|
invalidateGsapCache,
|
|
369
|
+
writeProjectFile,
|
|
368
370
|
],
|
|
369
371
|
);
|
|
370
372
|
|
|
@@ -437,6 +439,7 @@ export function useTimelineGroupEditing({
|
|
|
437
439
|
errorLabel: "Failed to scale GSAP positions",
|
|
438
440
|
coalesceKey,
|
|
439
441
|
recordEdit,
|
|
442
|
+
writeProjectFile,
|
|
440
443
|
activeCompPath,
|
|
441
444
|
changes,
|
|
442
445
|
resolveChangePath: (element) => targetPathFor(element, activeCompPath),
|
|
@@ -478,6 +481,7 @@ export function useTimelineGroupEditing({
|
|
|
478
481
|
trySdkBatchPersist,
|
|
479
482
|
showToast,
|
|
480
483
|
invalidateGsapCache,
|
|
484
|
+
writeProjectFile,
|
|
481
485
|
],
|
|
482
486
|
);
|
|
483
487
|
|
package/src/index.ts
CHANGED
|
@@ -184,6 +184,14 @@ export type { TimelinePaneProps } from "./components/nle/TimelinePane";
|
|
|
184
184
|
export { TimelineEditProvider } from "./contexts/TimelineEditContext";
|
|
185
185
|
export type { TimelineEditCallbacks } from "./player/components/timelineCallbacks";
|
|
186
186
|
export type { BlockedTimelineEditIntent } from "./player/components/timelineEditing";
|
|
187
|
+
export { TimelineToolbar } from "./components/TimelineToolbar";
|
|
188
|
+
export type { TimelineToolbarProps } from "./components/TimelineToolbar";
|
|
189
|
+
export { TimelineHistoryButtons } from "./components/TimelineHistoryButtons";
|
|
190
|
+
export type { TimelineHistoryButtonsProps } from "./components/TimelineHistoryButtons";
|
|
191
|
+
export { AudioMeterStrip } from "./components/nle/AudioMeterStrip";
|
|
192
|
+
export type { AudioMeterStripProps } from "./components/nle/AudioMeterStrip";
|
|
193
|
+
export { useClipboard } from "./hooks/useClipboard";
|
|
194
|
+
export type { UseClipboardOptions } from "./hooks/useClipboard";
|
|
187
195
|
|
|
188
196
|
export {
|
|
189
197
|
playSeamTransitionLoop,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import React, { act } from "react";
|
|
4
4
|
import { createRoot, type Root } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { MockResizeObserver, reportResize } from "../../hooks/resizeObserverTestUtils";
|
|
6
7
|
import { thumbnailScheduler } from "../lib/thumbnailScheduler";
|
|
7
8
|
import { buildCompositionThumbnailUrl, CompositionThumbnail } from "./CompositionThumbnail";
|
|
8
9
|
|
|
@@ -11,12 +12,6 @@ Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", {
|
|
|
11
12
|
value: true,
|
|
12
13
|
});
|
|
13
14
|
|
|
14
|
-
class MockResizeObserver {
|
|
15
|
-
observe() {}
|
|
16
|
-
disconnect() {}
|
|
17
|
-
unobserve() {}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
class MockImage {
|
|
21
16
|
static instances: MockImage[] = [];
|
|
22
17
|
onload: (() => void) | null = null;
|
|
@@ -146,6 +141,45 @@ describe("CompositionThumbnail", () => {
|
|
|
146
141
|
);
|
|
147
142
|
});
|
|
148
143
|
|
|
144
|
+
it.each([
|
|
145
|
+
{ name: "a wide", width: 2700, height: 1000, tileWidth: 108 },
|
|
146
|
+
{ name: "a square", width: 1000, height: 1000, tileWidth: 48 },
|
|
147
|
+
{ name: "a portrait", width: 1080, height: 1920, tileWidth: 48 },
|
|
148
|
+
])(
|
|
149
|
+
"shows $name picture whole at the clip's measured height",
|
|
150
|
+
async ({ width, height, tileWidth }) => {
|
|
151
|
+
Object.defineProperty(host, "clientWidth", { configurable: true, value: 500 });
|
|
152
|
+
Object.defineProperty(host, "clientHeight", { configurable: true, value: 40 });
|
|
153
|
+
const probe = await renderThumbnail();
|
|
154
|
+
|
|
155
|
+
await act(async () => {
|
|
156
|
+
probe.naturalWidth = width;
|
|
157
|
+
probe.naturalHeight = height;
|
|
158
|
+
probe.onload?.();
|
|
159
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const img = host.querySelector("img")!;
|
|
163
|
+
expect(img.parentElement?.style.width).toBe(`${tileWidth}px`);
|
|
164
|
+
// A tile held at its minimum width letterboxes the picture instead of cropping it.
|
|
165
|
+
expect(img.classList.contains("object-contain")).toBe(true);
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
it("re-tiles at the height the resize observer reports", async () => {
|
|
170
|
+
const probe = await renderThumbnail();
|
|
171
|
+
await act(async () => {
|
|
172
|
+
probe.naturalWidth = 2700;
|
|
173
|
+
probe.naturalHeight = 1000;
|
|
174
|
+
probe.onload?.();
|
|
175
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
act(() => reportResize(500, 40));
|
|
179
|
+
|
|
180
|
+
expect(host.querySelector("img")?.parentElement?.style.width).toBe("108px");
|
|
181
|
+
});
|
|
182
|
+
|
|
149
183
|
it("aborts its scheduled off-DOM image probe when unmounted", async () => {
|
|
150
184
|
const probe = await renderThumbnail();
|
|
151
185
|
expect(host.querySelector("img")).toBeNull();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { memo,
|
|
2
|
-
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
1
|
+
import { memo, useMemo, type CSSProperties } from "react";
|
|
3
2
|
import { useThumbnailLease } from "../../hooks/useThumbnailLease";
|
|
3
|
+
import { useThumbnailStripSize } from "../../hooks/useThumbnailStripSize";
|
|
4
4
|
import { createThumbnailKey, type ThumbnailPriority } from "../lib/thumbnailScheduler";
|
|
5
5
|
import { TIMELINE_VIEWPORT_BUDGETS } from "../lib/timelineViewportBudgets";
|
|
6
6
|
import { computeThumbnailStrip, probeImageAspect } from "./thumbnailUtils";
|
|
@@ -22,7 +22,6 @@ interface CompositionThumbnailProps {
|
|
|
22
22
|
rich?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const CLIP_HEIGHT = 66;
|
|
26
25
|
const THUMBNAIL_URL_VERSION = "v3";
|
|
27
26
|
export const THUMBNAIL_SEEK_TIME_SECONDS = 3;
|
|
28
27
|
|
|
@@ -122,8 +121,7 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
|
|
|
122
121
|
contentRevision = 0,
|
|
123
122
|
priority = "visible",
|
|
124
123
|
}: CompositionThumbnailProps) {
|
|
125
|
-
const [
|
|
126
|
-
const observerRef = useRef<ResizeObserver | null>(null);
|
|
124
|
+
const [container, setContainerRef] = useThumbnailStripSize();
|
|
127
125
|
const url = buildCompositionThumbnailUrl({
|
|
128
126
|
previewUrl,
|
|
129
127
|
seekTime,
|
|
@@ -149,25 +147,12 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
|
|
|
149
147
|
const value =
|
|
150
148
|
snapshot.status === "ready" && snapshot.value.kind === "image" ? snapshot.value : null;
|
|
151
149
|
const { frameW, frameCount } = computeThumbnailStrip(
|
|
152
|
-
|
|
150
|
+
container.width,
|
|
153
151
|
value?.aspect ?? 16 / 9,
|
|
154
|
-
|
|
152
|
+
container.height,
|
|
155
153
|
48,
|
|
156
154
|
);
|
|
157
155
|
|
|
158
|
-
const setContainerRef = useCallback((element: HTMLDivElement | null) => {
|
|
159
|
-
observerRef.current?.disconnect();
|
|
160
|
-
if (!element) return;
|
|
161
|
-
const target = element.parentElement ?? element;
|
|
162
|
-
setContainerWidth(target.clientWidth);
|
|
163
|
-
observerRef.current = new ResizeObserver(([entry]) =>
|
|
164
|
-
setContainerWidth(entry.contentRect.width),
|
|
165
|
-
);
|
|
166
|
-
observerRef.current.observe(target);
|
|
167
|
-
}, []);
|
|
168
|
-
|
|
169
|
-
useMountEffect(() => () => observerRef.current?.disconnect());
|
|
170
|
-
|
|
171
156
|
return (
|
|
172
157
|
<div ref={setContainerRef} className="absolute inset-0 overflow-hidden">
|
|
173
158
|
{value && (
|
|
@@ -189,7 +174,7 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
|
|
|
189
174
|
src={value.url}
|
|
190
175
|
alt=""
|
|
191
176
|
draggable={false}
|
|
192
|
-
className="absolute inset-0 h-full w-full object-
|
|
177
|
+
className="absolute inset-0 h-full w-full object-contain"
|
|
193
178
|
style={{ opacity: "var(--timeline-composition-thumbnail-opacity)" }}
|
|
194
179
|
/>
|
|
195
180
|
</div>
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import React, { act } from "react";
|
|
4
4
|
import { createRoot, type Root } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { MockResizeObserver, reportResize } from "../../hooks/resizeObserverTestUtils";
|
|
6
7
|
import { thumbnailScheduler } from "../lib/thumbnailScheduler";
|
|
7
8
|
import { ImageThumbnail } from "./ImageThumbnail";
|
|
8
9
|
|
|
@@ -30,12 +31,6 @@ class MockIntersectionObserver {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
class MockResizeObserver {
|
|
34
|
-
observe() {}
|
|
35
|
-
disconnect() {}
|
|
36
|
-
unobserve() {}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
34
|
// --- Image stub: captures instances so tests fire load/error deterministically ---
|
|
40
35
|
class MockImage {
|
|
41
36
|
static instances: MockImage[] = [];
|
|
@@ -171,6 +166,32 @@ describe("ImageThumbnail", () => {
|
|
|
171
166
|
expect(host.querySelector(".animate-pulse")).toBeNull();
|
|
172
167
|
});
|
|
173
168
|
|
|
169
|
+
it("tiles a wide picture at the clip's measured height, whole", async () => {
|
|
170
|
+
Object.defineProperty(host, "clientWidth", { configurable: true, value: 500 });
|
|
171
|
+
Object.defineProperty(host, "clientHeight", { configurable: true, value: 40 });
|
|
172
|
+
render({ imageSrc: "/api/projects/p/preview/assets/wide.png" });
|
|
173
|
+
await resolveProbe((probe) => {
|
|
174
|
+
probe.naturalWidth = 2700;
|
|
175
|
+
probe.naturalHeight = 1000;
|
|
176
|
+
probe.onload?.();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(host.querySelector("img")?.parentElement?.style.width).toBe("108px");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("re-tiles at the height the resize observer reports", async () => {
|
|
183
|
+
render({ imageSrc: "/api/projects/p/preview/assets/wide.png" });
|
|
184
|
+
await resolveProbe((probe) => {
|
|
185
|
+
probe.naturalWidth = 2700;
|
|
186
|
+
probe.naturalHeight = 1000;
|
|
187
|
+
probe.onload?.();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
act(() => reportResize(500, 40));
|
|
191
|
+
|
|
192
|
+
expect(host.querySelector("img")?.parentElement?.style.width).toBe("108px");
|
|
193
|
+
});
|
|
194
|
+
|
|
174
195
|
it("renders the label above the strip when provided", async () => {
|
|
175
196
|
render({ imageSrc: "/x.png", label: "hero", labelColor: "#abc" });
|
|
176
197
|
await resolveProbe((probe) => {
|