mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(studio): undo and redo show on the next frame instead of after the server answers * fix(studio): an undo pressed before the history caught up still restores in place * fix(studio): undo and redo of an edit inside a nested composition apply in place * fix(studio): undo of a nested edit reloads when its composition has a GSAP script * refactor(studio): a nested restore with a GSAP script has no in-place scope * fix(studio): an undo after an outside write shows the file the server restored
96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
import { useCallback, type MutableRefObject } from "react";
|
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
import {
|
|
deleteExternalConflictSnapshot,
|
|
loadExternalConflictSnapshot,
|
|
persistExternalConflictSnapshot,
|
|
persistExternalFailureSnapshot,
|
|
} from "../utils/externalConflictStorage";
|
|
import { notifyExternalFileReload } from "./externalFileReloadBus";
|
|
import { useExternalFileChangeCoordinator } from "./useExternalFileChangeCoordinator";
|
|
import type { useFileManager } from "./useFileManager";
|
|
import type { usePreviewPersistence } from "./usePreviewPersistence";
|
|
|
|
type FileManager = Pick<
|
|
ReturnType<typeof useFileManager>,
|
|
| "editingFile"
|
|
| "flushPendingSourceSave"
|
|
| "discardPendingSourceSave"
|
|
| "getPendingSourceCandidate"
|
|
| "overwriteExternalConflict"
|
|
| "readProjectFile"
|
|
| "updateEditingFileContent"
|
|
| "refreshFileTree"
|
|
>;
|
|
|
|
type PreviewPersistence = Pick<
|
|
ReturnType<typeof usePreviewPersistence>,
|
|
"drainPendingDomEditSaves" | "resetDomEditSaveQueueBreaker"
|
|
>;
|
|
|
|
interface UseStudioExternalFileChangesOptions {
|
|
projectId: string | null;
|
|
activeCompPath: string | null;
|
|
masterCompPath: string | null;
|
|
fileManager: FileManager;
|
|
previewPersistence: PreviewPersistence;
|
|
pendingTimelineEditPathRef: MutableRefObject<Set<string>>;
|
|
reloadPreview: () => void;
|
|
onOutsideChange?: () => void;
|
|
}
|
|
|
|
/** Connects the app's save queues, recovery storage, and reload surfaces to one owner. */
|
|
export function useStudioExternalFileChanges({
|
|
projectId,
|
|
activeCompPath,
|
|
masterCompPath,
|
|
fileManager,
|
|
previewPersistence,
|
|
pendingTimelineEditPathRef,
|
|
reloadPreview,
|
|
onOutsideChange,
|
|
}: UseStudioExternalFileChangesOptions) {
|
|
const { flushPendingSourceSave, discardPendingSourceSave } = fileManager;
|
|
const { drainPendingDomEditSaves, resetDomEditSaveQueueBreaker } = previewPersistence;
|
|
const bumpThumbnailRevisions = usePlayerStore((state) => state.bumpThumbnailRevisions);
|
|
const onAcceptedPersistedFileChange = useCallback(
|
|
(_path: string, affectedCompositions: readonly string[] | null) => {
|
|
onOutsideChange?.();
|
|
bumpThumbnailRevisions(affectedCompositions);
|
|
},
|
|
[bumpThumbnailRevisions, onOutsideChange],
|
|
);
|
|
const drainPendingChanges = useCallback(async () => {
|
|
const source = await flushPendingSourceSave();
|
|
if (source.status !== "clean") return source;
|
|
return drainPendingDomEditSaves();
|
|
}, [drainPendingDomEditSaves, flushPendingSourceSave]);
|
|
|
|
const discardPendingChanges = useCallback(() => {
|
|
discardPendingSourceSave();
|
|
resetDomEditSaveQueueBreaker();
|
|
}, [discardPendingSourceSave, resetDomEditSaveQueueBreaker]);
|
|
|
|
return useExternalFileChangeCoordinator({
|
|
projectId,
|
|
activeCompPath,
|
|
recoveryFilePath: fileManager.editingFile?.path ?? activeCompPath ?? masterCompPath,
|
|
pendingTimelineEditPathRef,
|
|
drainPendingChanges,
|
|
getPendingCandidate: fileManager.getPendingSourceCandidate,
|
|
discardPendingChanges,
|
|
reloadPreview,
|
|
reloadSdkSession: notifyExternalFileReload,
|
|
persistConflictSnapshot: persistExternalConflictSnapshot,
|
|
persistFailureSnapshot: persistExternalFailureSnapshot,
|
|
loadConflictSnapshot: loadExternalConflictSnapshot,
|
|
deleteConflictSnapshot: deleteExternalConflictSnapshot,
|
|
overwriteConflict: fileManager.overwriteExternalConflict,
|
|
readProjectFile: fileManager.readProjectFile,
|
|
onUseExternalFile: fileManager.updateEditingFileContent,
|
|
resetSaveQueues: resetDomEditSaveQueueBreaker,
|
|
onAcceptedPersistedFileChange,
|
|
refreshFileTree: fileManager.refreshFileTree,
|
|
});
|
|
}
|