@hyperframes/studio 0.6.99 → 0.6.101
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/index-BITwbxi-.css +1 -0
- package/dist/assets/{index-C52IT_lp.js → index-CQ3n6Y9q.js} +1 -1
- package/dist/assets/index-CTiqZ7XQ.js +296 -0
- package/dist/assets/{index-DOh7E1uj.js → index-DvttAtOD.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +5 -4
- package/src/App.tsx +13 -13
- package/src/components/editor/PropertyPanel.tsx +24 -16
- package/src/components/editor/manualEditingAvailability.ts +12 -1
- package/src/components/nle/NLELayout.tsx +89 -1
- package/src/components/renders/useRenderQueue.ts +12 -8
- package/src/hooks/gsapScriptCommitHelpers.ts +8 -5
- package/src/hooks/gsapScriptCommitTypes.ts +3 -0
- package/src/hooks/gsapTargetCache.ts +65 -0
- package/src/hooks/useAppHotkeys.ts +10 -0
- package/src/hooks/useDomEditCommits.ts +12 -14
- package/src/hooks/useDomEditSession.ts +13 -0
- package/src/hooks/useDomGeometryCommits.ts +1 -36
- package/src/hooks/useElementLifecycleOps.ts +5 -0
- package/src/hooks/useGsapAnimationOps.ts +26 -1
- package/src/hooks/useGsapScriptCommits.ts +5 -2
- package/src/hooks/useRazorSplit.ts +3 -0
- package/src/hooks/useSdkSelectionSync.ts +25 -0
- package/src/hooks/useSdkSession.test.ts +20 -0
- package/src/hooks/useSdkSession.ts +101 -0
- package/src/hooks/useTimelineEditing.ts +23 -3
- package/src/player/components/Timeline.tsx +31 -18
- package/src/player/components/TimelineClip.tsx +3 -3
- package/src/player/components/useResolvedTimelineEditCallbacks.ts +30 -0
- package/src/player/hooks/useExpandedTimelineElements.test.ts +91 -0
- package/src/player/hooks/useExpandedTimelineElements.ts +153 -0
- package/src/player/hooks/useTimelineSyncCallbacks.ts +22 -0
- package/src/player/store/playerStore.ts +22 -8
- package/src/telemetry/events.test.ts +16 -1
- package/src/telemetry/events.ts +15 -0
- package/src/utils/blockCategories.ts +2 -2
- package/src/utils/sdkShadow.test.ts +246 -0
- package/src/utils/sdkShadow.ts +404 -0
- package/src/utils/studioHelpers.test.ts +25 -1
- package/src/utils/studioHelpers.ts +54 -28
- package/dist/assets/index-B62bDCQv.css +0 -1
- package/dist/assets/index-DrwSRbsl.js +0 -252
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
-
import { STUDIO_GSAP_DRAG_INTERCEPT_ENABLED } from "../components/editor/manualEditingAvailability";
|
|
3
2
|
import { getDomEditTargetKey, type DomEditSelection } from "../components/editor/domEditing";
|
|
4
3
|
import {
|
|
5
4
|
applyStudioPathOffset,
|
|
@@ -19,45 +18,11 @@ import {
|
|
|
19
18
|
} from "../components/editor/manualEditsDomPatches";
|
|
20
19
|
import type { DomEditGroupPathOffsetCommit } from "../components/editor/DomEditOverlay";
|
|
21
20
|
import type { PatchOperation } from "../utils/sourcePatcher";
|
|
21
|
+
import { isElementGsapTargeted } from "./gsapTargetCache";
|
|
22
22
|
|
|
23
23
|
export const GSAP_CSS_FALLBACK_BLOCKED_MESSAGE =
|
|
24
24
|
"This element is GSAP-animated — dragging via CSS would corrupt keyframes";
|
|
25
25
|
|
|
26
|
-
// ── Helpers ──
|
|
27
|
-
|
|
28
|
-
type TimelineLike = { getChildren?: (nested: boolean) => Array<{ targets?: () => Element[] }> };
|
|
29
|
-
|
|
30
|
-
// fallow-ignore-next-line complexity
|
|
31
|
-
function isElementGsapTargeted(iframe: HTMLIFrameElement | null, element: HTMLElement): boolean {
|
|
32
|
-
// When the GSAP drag intercept is disabled for debugging, treat every
|
|
33
|
-
// element as un-targeted so commits take the plain CSS persist path.
|
|
34
|
-
if (!STUDIO_GSAP_DRAG_INTERCEPT_ENABLED) return false;
|
|
35
|
-
if (!iframe?.contentWindow) return false;
|
|
36
|
-
let timelines: Record<string, TimelineLike> | undefined;
|
|
37
|
-
try {
|
|
38
|
-
timelines = (iframe.contentWindow as Window & { __timelines?: Record<string, TimelineLike> })
|
|
39
|
-
.__timelines;
|
|
40
|
-
} catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (!timelines) return false;
|
|
44
|
-
const id = element.id;
|
|
45
|
-
for (const tl of Object.values(timelines)) {
|
|
46
|
-
if (!tl?.getChildren) continue;
|
|
47
|
-
try {
|
|
48
|
-
for (const child of tl.getChildren(true)) {
|
|
49
|
-
if (!child.targets) continue;
|
|
50
|
-
for (const t of child.targets()) {
|
|
51
|
-
if (t === element || (id && t.id === id)) return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} catch {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
26
|
// ── Hook ──
|
|
62
27
|
|
|
63
28
|
interface UseDomGeometryCommitsParams {
|
|
@@ -31,6 +31,8 @@ interface UseElementLifecycleOpsParams {
|
|
|
31
31
|
patches: PatchOperation[],
|
|
32
32
|
options: { label: string; coalesceKey: string; skipRefresh?: boolean },
|
|
33
33
|
) => Promise<void>;
|
|
34
|
+
/** Stage 7 Step 3b: called after a successful server-side element delete (shadow). */
|
|
35
|
+
onElementDeleted?: (selection: DomEditSelection) => void;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export function useElementLifecycleOps({
|
|
@@ -43,6 +45,7 @@ export function useElementLifecycleOps({
|
|
|
43
45
|
reloadPreview,
|
|
44
46
|
clearDomSelection,
|
|
45
47
|
commitPositionPatchToHtml,
|
|
48
|
+
onElementDeleted,
|
|
46
49
|
}: UseElementLifecycleOpsParams) {
|
|
47
50
|
// fallow-ignore-next-line complexity
|
|
48
51
|
const handleDomEditElementDelete = useCallback(
|
|
@@ -103,6 +106,7 @@ export function useElementLifecycleOps({
|
|
|
103
106
|
clearDomSelection();
|
|
104
107
|
usePlayerStore.getState().setSelectedElementId(null);
|
|
105
108
|
reloadPreview();
|
|
109
|
+
onElementDeleted?.(selection);
|
|
106
110
|
showToast(`Deleted ${label}. Use Undo to restore it.`, "info");
|
|
107
111
|
} catch (error) {
|
|
108
112
|
const message = error instanceof Error ? error.message : "Failed to delete element";
|
|
@@ -114,6 +118,7 @@ export function useElementLifecycleOps({
|
|
|
114
118
|
clearDomSelection,
|
|
115
119
|
domEditSaveTimestampRef,
|
|
116
120
|
editHistory.recordEdit,
|
|
121
|
+
onElementDeleted,
|
|
117
122
|
projectIdRef,
|
|
118
123
|
reloadPreview,
|
|
119
124
|
showToast,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
+
import type { Composition, GsapTweenSpec } from "@hyperframes/sdk";
|
|
2
3
|
import type { DomEditSelection } from "../components/editor/domEditingTypes";
|
|
3
4
|
import { roundTo3 } from "../utils/rounding";
|
|
5
|
+
import { runShadowGsapTween } from "../utils/sdkShadow";
|
|
4
6
|
import {
|
|
5
7
|
assignGsapTargetAutoIdIfNeeded,
|
|
6
8
|
ensureElementAddressable,
|
|
@@ -13,6 +15,8 @@ interface GsapAnimationOpsParams {
|
|
|
13
15
|
commitMutation: CommitMutation;
|
|
14
16
|
commitMutationSafely: SafeGsapCommitMutation;
|
|
15
17
|
showToast: (message: string, tone?: "error" | "info") => void;
|
|
18
|
+
/** Stage 7 Step 3b: SDK session for shadow GSAP dispatch (server stays authoritative). */
|
|
19
|
+
sdkSession?: Composition | null;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
export function useGsapAnimationOps({
|
|
@@ -21,6 +25,7 @@ export function useGsapAnimationOps({
|
|
|
21
25
|
commitMutation,
|
|
22
26
|
commitMutationSafely,
|
|
23
27
|
showToast,
|
|
28
|
+
sdkSession,
|
|
24
29
|
}: GsapAnimationOpsParams) {
|
|
25
30
|
const updateGsapMeta = useCallback(
|
|
26
31
|
(
|
|
@@ -62,7 +67,10 @@ export function useGsapAnimationOps({
|
|
|
62
67
|
[commitMutation],
|
|
63
68
|
);
|
|
64
69
|
|
|
70
|
+
// Pre-existing complexity (auto-id assignment + per-method defaults); this PR
|
|
71
|
+
// adds only a guarded shadow-op construction at the tail.
|
|
65
72
|
const addGsapAnimation = useCallback(
|
|
73
|
+
// fallow-ignore-next-line complexity
|
|
66
74
|
async (
|
|
67
75
|
selection: DomEditSelection,
|
|
68
76
|
method: "to" | "from" | "set" | "fromTo",
|
|
@@ -109,8 +117,25 @@ export function useGsapAnimationOps({
|
|
|
109
117
|
},
|
|
110
118
|
{ label: `Add GSAP ${method} animation` },
|
|
111
119
|
);
|
|
120
|
+
|
|
121
|
+
// Shadow: dispatch the equivalent addGsapTween to the SDK (server stays
|
|
122
|
+
// authoritative). "set" has no SDK method, so it is not shadowed.
|
|
123
|
+
// ponytail: only add is shadowed — delete/update key on the server's
|
|
124
|
+
// animationId, which doesn't resolve in the SDK's independent id-space.
|
|
125
|
+
if (sdkSession && selection.hfId && method !== "set") {
|
|
126
|
+
const tween: GsapTweenSpec = {
|
|
127
|
+
method,
|
|
128
|
+
position,
|
|
129
|
+
duration,
|
|
130
|
+
ease: "power2.out",
|
|
131
|
+
...(method === "fromTo"
|
|
132
|
+
? { fromProperties: { opacity: 0 }, toProperties: toDefaults[method] }
|
|
133
|
+
: { properties: toDefaults[method] ?? { opacity: 1 } }),
|
|
134
|
+
};
|
|
135
|
+
runShadowGsapTween(sdkSession, { kind: "add", target: selection.hfId, tween });
|
|
136
|
+
}
|
|
112
137
|
},
|
|
113
|
-
[activeCompPath, commitMutation, projectIdRef, showToast],
|
|
138
|
+
[activeCompPath, commitMutation, projectIdRef, showToast, sdkSession],
|
|
114
139
|
);
|
|
115
140
|
|
|
116
141
|
return {
|
|
@@ -43,7 +43,10 @@ async function mutateGsapScript(
|
|
|
43
43
|
|
|
44
44
|
// oxfmt-ignore
|
|
45
45
|
// fallow-ignore-next-line complexity
|
|
46
|
-
export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIframeRef, editHistory, domEditSaveTimestampRef, reloadPreview, onCacheInvalidate, onFileContentChanged, showToast }: GsapScriptCommitsParams) {
|
|
46
|
+
export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIframeRef, editHistory, domEditSaveTimestampRef, reloadPreview, onCacheInvalidate, onFileContentChanged, showToast, sdkSession }: GsapScriptCommitsParams) {
|
|
47
|
+
// Pre-existing complexity (server mutate + history + reload branches); this PR
|
|
48
|
+
// adds only a guarded shadow-fidelity dispatch.
|
|
49
|
+
// fallow-ignore-next-line complexity
|
|
47
50
|
const commitMutation = useCallback(async (selection: DomEditSelection, mutation: Record<string, unknown>, options: CommitMutationOptions) => {
|
|
48
51
|
const pid = projectIdRef.current;
|
|
49
52
|
if (!pid) return;
|
|
@@ -81,7 +84,7 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra
|
|
|
81
84
|
const trackGsapSaveFailure = useGsapSaveFailureTelemetry(activeCompPath);
|
|
82
85
|
const commitMutationSafely = useSafeGsapCommitMutation(commitMutation, trackGsapSaveFailure, showToast);
|
|
83
86
|
const propertyOps = useGsapPropertyDebounce(commitMutationSafely);
|
|
84
|
-
const animationOps = useGsapAnimationOps({ projectIdRef, activeCompPath, commitMutation, commitMutationSafely, showToast });
|
|
87
|
+
const animationOps = useGsapAnimationOps({ projectIdRef, activeCompPath, commitMutation, commitMutationSafely, showToast, sdkSession });
|
|
85
88
|
const keyframeOps = useGsapKeyframeOps({ activeCompPath, commitMutation, commitMutationSafely, trackGsapSaveFailure });
|
|
86
89
|
const arcPathOps = useGsapArcPathOps(commitMutationSafely);
|
|
87
90
|
return { commitMutation, ...propertyOps, ...animationOps, ...keyframeOps, ...arcPathOps };
|
|
@@ -3,6 +3,7 @@ import type { TimelineElement } from "../player";
|
|
|
3
3
|
import { usePlayerStore } from "../player";
|
|
4
4
|
import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
|
|
5
5
|
import { getTimelineElementLabel, collectHtmlIds } from "../utils/studioHelpers";
|
|
6
|
+
import { trackStudioRazorSplit } from "../telemetry/events";
|
|
6
7
|
import {
|
|
7
8
|
canSplitElement,
|
|
8
9
|
buildPatchTarget,
|
|
@@ -196,6 +197,7 @@ export function useRazorSplit({
|
|
|
196
197
|
});
|
|
197
198
|
|
|
198
199
|
reloadPreview();
|
|
200
|
+
trackStudioRazorSplit({ mode: "single", count: 1 });
|
|
199
201
|
showToast(`Split ${getTimelineElementLabel(element)} at ${splitTime.toFixed(2)}s`, "info");
|
|
200
202
|
if (skippedSelectors?.length) {
|
|
201
203
|
showToast(
|
|
@@ -277,6 +279,7 @@ export function useRazorSplit({
|
|
|
277
279
|
});
|
|
278
280
|
|
|
279
281
|
reloadPreview();
|
|
282
|
+
trackStudioRazorSplit({ mode: "all", count: splitCount });
|
|
280
283
|
showToast(`Split ${splitCount} clips at ${splitTime.toFixed(2)}s`, "info");
|
|
281
284
|
} catch (error) {
|
|
282
285
|
const message = error instanceof Error ? error.message : "Failed to split clips";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import type { Composition } from "@hyperframes/sdk";
|
|
3
|
+
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
4
|
+
|
|
5
|
+
function toHfIds(group: DomEditSelection[], primary: DomEditSelection | null): string[] {
|
|
6
|
+
const source = group.length > 0 ? group : primary ? [primary] : [];
|
|
7
|
+
return source.flatMap((s) => (s.hfId ? [s.hfId] : []));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Stage 7 Step 2 — mirrors Studio canvas selection into the SDK session.
|
|
12
|
+
*
|
|
13
|
+
* Calls session.setSelection(hfIds) whenever domEditSelection or
|
|
14
|
+
* domEditGroupSelections changes. Pure effect; no existing hook modified.
|
|
15
|
+
*/
|
|
16
|
+
export function useSdkSelectionSync(
|
|
17
|
+
session: Composition | null,
|
|
18
|
+
domEditSelection: DomEditSelection | null,
|
|
19
|
+
domEditGroupSelections: DomEditSelection[],
|
|
20
|
+
): void {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!session) return;
|
|
23
|
+
session.setSelection(toHfIds(domEditGroupSelections, domEditSelection));
|
|
24
|
+
}, [session, domEditSelection, domEditGroupSelections]);
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { shouldReloadSdkSession } from "./useSdkSession";
|
|
3
|
+
|
|
4
|
+
describe("shouldReloadSdkSession", () => {
|
|
5
|
+
it("reloads when the changed file is the active composition", () => {
|
|
6
|
+
expect(shouldReloadSdkSession({ path: "scenes/intro.html" }, "scenes/intro.html")).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("ignores changes to other files", () => {
|
|
10
|
+
expect(shouldReloadSdkSession({ path: "styles/main.css" }, "scenes/intro.html")).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("ignores changes when no composition is active", () => {
|
|
14
|
+
expect(shouldReloadSdkSession({ path: "scenes/intro.html" }, null)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("ignores payloads with no resolvable path", () => {
|
|
18
|
+
expect(shouldReloadSdkSession({}, "scenes/intro.html")).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { openComposition } from "@hyperframes/sdk";
|
|
3
|
+
import { createHttpAdapter } from "@hyperframes/sdk/adapters/http";
|
|
4
|
+
import type { Composition } from "@hyperframes/sdk";
|
|
5
|
+
import { readStudioFileChangePath } from "../components/editor/manualEdits";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* True when an external file-change payload targets the active composition and
|
|
9
|
+
* the SDK session must be re-opened to pick up the new content.
|
|
10
|
+
*/
|
|
11
|
+
export function shouldReloadSdkSession(payload: unknown, activeCompPath: string | null): boolean {
|
|
12
|
+
if (!activeCompPath) return false;
|
|
13
|
+
return readStudioFileChangePath(payload) === activeCompPath;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Stage 7 Step 3a — SDK session wired to the active composition.
|
|
18
|
+
*
|
|
19
|
+
* Creates an SDK Composition backed by createHttpAdapter on every
|
|
20
|
+
* (projectId, activeCompPath) change, disposes the old one on cleanup, and
|
|
21
|
+
* re-opens it when the active composition file changes on disk (code editor,
|
|
22
|
+
* agent, or server-side patch) so the in-memory linkedom document never goes
|
|
23
|
+
* stale.
|
|
24
|
+
*
|
|
25
|
+
* Opened WITHOUT a persist queue: this session is shadow-telemetry +
|
|
26
|
+
* selection-sync only — it reads from the server but must NEVER write back.
|
|
27
|
+
* Shadow dispatch ops mutate the in-memory model and are discarded on the next
|
|
28
|
+
* reload-on-change (the studio's own authoritative write triggers it). Routing
|
|
29
|
+
* authoritative writes through this session (cutover, Step 3c+) must re-add
|
|
30
|
+
* persist TOGETHER WITH self-write suppression — without it, the SDK's
|
|
31
|
+
* serialize() output races and clobbers the studio's authoritative write.
|
|
32
|
+
*/
|
|
33
|
+
export function useSdkSession(
|
|
34
|
+
projectId: string | null,
|
|
35
|
+
activeCompPath: string | null,
|
|
36
|
+
): Composition | null {
|
|
37
|
+
const [session, setSession] = useState<Composition | null>(null);
|
|
38
|
+
const [reloadToken, setReloadToken] = useState(0);
|
|
39
|
+
|
|
40
|
+
// ── Re-open on external change to the active composition ──
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!activeCompPath) return;
|
|
43
|
+
// Pre-existing clone of the file-change reload handler (usePreviewPersistence);
|
|
44
|
+
// surfaced by this PR's adjacent edits, not introduced by it.
|
|
45
|
+
// fallow-ignore-next-line code-duplication
|
|
46
|
+
const handler = (payload?: unknown) => {
|
|
47
|
+
if (shouldReloadSdkSession(payload, activeCompPath)) {
|
|
48
|
+
setReloadToken((t) => t + 1);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (import.meta.hot) {
|
|
52
|
+
import.meta.hot.on("hf:file-change", handler);
|
|
53
|
+
return () => import.meta.hot?.off?.("hf:file-change", handler);
|
|
54
|
+
}
|
|
55
|
+
// SSE fallback for the embedded studio server.
|
|
56
|
+
const es = new EventSource("/api/events");
|
|
57
|
+
es.addEventListener("file-change", handler);
|
|
58
|
+
return () => es.close();
|
|
59
|
+
}, [activeCompPath]);
|
|
60
|
+
|
|
61
|
+
// ── Open / re-open the session ──
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!projectId || !activeCompPath) {
|
|
64
|
+
setSession(null);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let cancelled = false;
|
|
69
|
+
let comp: Composition | null = null;
|
|
70
|
+
|
|
71
|
+
const adapter = createHttpAdapter({
|
|
72
|
+
projectFilesUrl: `/api/projects/${projectId}`,
|
|
73
|
+
});
|
|
74
|
+
adapter
|
|
75
|
+
.read(activeCompPath)
|
|
76
|
+
.then(async (content) => {
|
|
77
|
+
if (cancelled || typeof content !== "string") return;
|
|
78
|
+
// No persist — shadow/selection only; see the hook docstring. The SDK
|
|
79
|
+
// must not write back to the server while it shadows the authoritative
|
|
80
|
+
// studio path.
|
|
81
|
+
comp = await openComposition(content);
|
|
82
|
+
// Cleanup may have fired while openComposition was awaited; dispose immediately.
|
|
83
|
+
if (cancelled) {
|
|
84
|
+
comp.dispose();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setSession(comp);
|
|
88
|
+
})
|
|
89
|
+
.catch(() => {
|
|
90
|
+
if (!cancelled) setSession(null);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
cancelled = true;
|
|
95
|
+
const c = comp;
|
|
96
|
+
if (c) void c.flush().finally(() => c.dispose());
|
|
97
|
+
};
|
|
98
|
+
}, [projectId, activeCompPath, reloadToken]);
|
|
99
|
+
|
|
100
|
+
return session;
|
|
101
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
// Pre-existing-complex timeline hook (DOM patch + GSAP position shift/scale +
|
|
2
|
+
// playback-start resolution); this PR adds guarded shadow-timing dispatches in
|
|
3
|
+
// the move/resize .then() chains, which nudges several callbacks over the CC
|
|
4
|
+
// threshold. The added branches are telemetry-only.
|
|
5
|
+
// fallow-ignore-file complexity
|
|
1
6
|
import { useCallback, useRef } from "react";
|
|
7
|
+
import type { Composition } from "@hyperframes/sdk";
|
|
8
|
+
import { runShadowTiming } from "../utils/sdkShadow";
|
|
2
9
|
import type { TimelineElement } from "../player";
|
|
3
10
|
import { usePlayerStore } from "../player";
|
|
4
11
|
import { useRazorSplit } from "./useRazorSplit";
|
|
@@ -33,7 +40,7 @@ import type { PersistTimelineEditInput } from "./timelineEditingHelpers";
|
|
|
33
40
|
|
|
34
41
|
// ── Types ──
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
interface RecordEditInput {
|
|
37
44
|
label: string;
|
|
38
45
|
kind: EditHistoryKind;
|
|
39
46
|
coalesceKey?: string;
|
|
@@ -53,6 +60,8 @@ interface UseTimelineEditingOptions {
|
|
|
53
60
|
pendingTimelineEditPathRef: React.MutableRefObject<Set<string>>;
|
|
54
61
|
uploadProjectFiles: (files: Iterable<File>, dir?: string) => Promise<string[]>;
|
|
55
62
|
isRecordingRef?: React.RefObject<boolean>;
|
|
63
|
+
/** Stage 7 Step 3b: SDK session for shadow timing dispatch (server stays authoritative). */
|
|
64
|
+
sdkSession?: Composition | null;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
// ── Hook ──
|
|
@@ -70,6 +79,7 @@ export function useTimelineEditing({
|
|
|
70
79
|
pendingTimelineEditPathRef,
|
|
71
80
|
uploadProjectFiles,
|
|
72
81
|
isRecordingRef,
|
|
82
|
+
sdkSession,
|
|
73
83
|
}: UseTimelineEditingOptions) {
|
|
74
84
|
const projectIdRef = useRef(projectId);
|
|
75
85
|
projectIdRef.current = projectId;
|
|
@@ -138,6 +148,11 @@ export function useTimelineEditing({
|
|
|
138
148
|
value: String(updates.track),
|
|
139
149
|
});
|
|
140
150
|
}).then(() => {
|
|
151
|
+
if (sdkSession)
|
|
152
|
+
runShadowTiming(sdkSession, element.hfId, {
|
|
153
|
+
start: updates.start,
|
|
154
|
+
trackIndex: updates.track,
|
|
155
|
+
});
|
|
141
156
|
const pid = projectIdRef.current;
|
|
142
157
|
if (delta !== 0 && element.domId && pid) {
|
|
143
158
|
return shiftGsapPositions(pid, filePath, element.domId, delta)
|
|
@@ -146,7 +161,7 @@ export function useTimelineEditing({
|
|
|
146
161
|
}
|
|
147
162
|
});
|
|
148
163
|
},
|
|
149
|
-
[previewIframeRef, enqueueEdit, activeCompPath, reloadPreview],
|
|
164
|
+
[previewIframeRef, enqueueEdit, activeCompPath, reloadPreview, sdkSession],
|
|
150
165
|
);
|
|
151
166
|
|
|
152
167
|
const handleTimelineElementResize = useCallback(
|
|
@@ -190,6 +205,11 @@ export function useTimelineEditing({
|
|
|
190
205
|
}
|
|
191
206
|
return patched;
|
|
192
207
|
}).then(() => {
|
|
208
|
+
if (sdkSession)
|
|
209
|
+
runShadowTiming(sdkSession, element.hfId, {
|
|
210
|
+
start: updates.start,
|
|
211
|
+
duration: updates.duration,
|
|
212
|
+
});
|
|
193
213
|
const pid = projectIdRef.current;
|
|
194
214
|
if (timingChanged && element.domId && pid) {
|
|
195
215
|
return scaleGsapPositions(
|
|
@@ -207,7 +227,7 @@ export function useTimelineEditing({
|
|
|
207
227
|
return reloadPreview();
|
|
208
228
|
});
|
|
209
229
|
},
|
|
210
|
-
[previewIframeRef, enqueueEdit, activeCompPath, reloadPreview],
|
|
230
|
+
[previewIframeRef, enqueueEdit, activeCompPath, reloadPreview, sdkSession],
|
|
211
231
|
);
|
|
212
232
|
|
|
213
233
|
const handleTimelineElementDelete = useCallback(
|
|
@@ -3,6 +3,7 @@ import { useMusicBeatAnalysis } from "../../hooks/useMusicBeatAnalysis";
|
|
|
3
3
|
import { isMusicTrack } from "../../utils/timelineInspector";
|
|
4
4
|
import { remapBeatAnalysisToComposition } from "../../utils/beatEditActions";
|
|
5
5
|
import { usePlayerStore, type TimelineElement } from "../store/playerStore";
|
|
6
|
+
import { useExpandedTimelineElements } from "../hooks/useExpandedTimelineElements";
|
|
6
7
|
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
7
8
|
import { EditPopover } from "./EditModal";
|
|
8
9
|
import { defaultTimelineTheme, type TimelineTheme } from "./timelineTheme";
|
|
@@ -28,7 +29,10 @@ import {
|
|
|
28
29
|
shouldShowTimelineShortcutHint,
|
|
29
30
|
} from "./timelineLayout";
|
|
30
31
|
import type { TimelineDropCallbacks } from "./timelineCallbacks";
|
|
31
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
useResolvedTimelineEditCallbacks,
|
|
34
|
+
type TimelineEditOverrides,
|
|
35
|
+
} from "./useResolvedTimelineEditCallbacks";
|
|
32
36
|
|
|
33
37
|
// Re-export pure utilities so existing imports from "./Timeline" still resolve.
|
|
34
38
|
export {
|
|
@@ -45,7 +49,7 @@ export {
|
|
|
45
49
|
getDefaultDroppedTrack,
|
|
46
50
|
} from "./timelineLayout";
|
|
47
51
|
|
|
48
|
-
interface TimelineProps extends TimelineDropCallbacks {
|
|
52
|
+
interface TimelineProps extends TimelineDropCallbacks, TimelineEditOverrides {
|
|
49
53
|
onSeek?: (time: number) => void;
|
|
50
54
|
onDrillDown?: (element: TimelineElement) => void;
|
|
51
55
|
renderClipContent?: (
|
|
@@ -67,6 +71,10 @@ export const Timeline = memo(function Timeline({
|
|
|
67
71
|
onAssetDrop,
|
|
68
72
|
onBlockDrop,
|
|
69
73
|
onDeleteElement: _onDeleteElement,
|
|
74
|
+
onMoveElement: onMoveElementOverride,
|
|
75
|
+
onResizeElement: onResizeElementOverride,
|
|
76
|
+
onBlockedEditAttempt: onBlockedEditAttemptOverride,
|
|
77
|
+
onSplitElement: onSplitElementOverride,
|
|
70
78
|
onSelectElement,
|
|
71
79
|
theme: themeOverrides,
|
|
72
80
|
}: TimelineProps = {}) {
|
|
@@ -80,14 +88,18 @@ export const Timeline = memo(function Timeline({
|
|
|
80
88
|
onDeleteAllKeyframes,
|
|
81
89
|
onChangeKeyframeEase,
|
|
82
90
|
onMoveKeyframe,
|
|
83
|
-
} =
|
|
91
|
+
} = useResolvedTimelineEditCallbacks({
|
|
92
|
+
onMoveElement: onMoveElementOverride,
|
|
93
|
+
onResizeElement: onResizeElementOverride,
|
|
94
|
+
onBlockedEditAttempt: onBlockedEditAttemptOverride,
|
|
95
|
+
onSplitElement: onSplitElementOverride,
|
|
96
|
+
});
|
|
84
97
|
const theme = useMemo(() => ({ ...defaultTimelineTheme, ...themeOverrides }), [themeOverrides]);
|
|
85
98
|
useMusicBeatAnalysis();
|
|
86
|
-
const
|
|
99
|
+
const rawElements = usePlayerStore((s) => s.elements);
|
|
100
|
+
const expandedElements = useExpandedTimelineElements();
|
|
87
101
|
const beatAnalysis = usePlayerStore((s) => s.beatAnalysis);
|
|
88
102
|
const musicElement = usePlayerStore((s) => s.elements.find(isMusicTrack) ?? null);
|
|
89
|
-
|
|
90
|
-
// Merge user edits + remap beats from audio-file → composition coordinates.
|
|
91
103
|
const beatEdits = usePlayerStore((s) => s.beatEdits);
|
|
92
104
|
const adjustedBeatAnalysis = useMemo(
|
|
93
105
|
() => remapBeatAnalysisToComposition(beatAnalysis, musicElement, beatEdits),
|
|
@@ -176,21 +188,21 @@ export const Timeline = memo(function Timeline({
|
|
|
176
188
|
|
|
177
189
|
const effectiveDuration = useMemo(() => {
|
|
178
190
|
const safeDur = Number.isFinite(duration) ? duration : 0;
|
|
179
|
-
if (
|
|
180
|
-
const maxEnd = Math.max(...
|
|
191
|
+
if (rawElements.length === 0) return safeDur;
|
|
192
|
+
const maxEnd = Math.max(...rawElements.map((el) => el.start + el.duration));
|
|
181
193
|
const result = Math.max(safeDur, maxEnd);
|
|
182
194
|
return Number.isFinite(result) ? result : safeDur;
|
|
183
|
-
}, [
|
|
195
|
+
}, [rawElements, duration]);
|
|
184
196
|
|
|
185
197
|
const tracks = useMemo(() => {
|
|
186
|
-
const map = new Map<number, typeof
|
|
187
|
-
for (const el of
|
|
198
|
+
const map = new Map<number, typeof expandedElements>();
|
|
199
|
+
for (const el of expandedElements) {
|
|
188
200
|
const list = map.get(el.track) ?? [];
|
|
189
201
|
list.push(el);
|
|
190
202
|
map.set(el.track, list);
|
|
191
203
|
}
|
|
192
204
|
return Array.from(map.entries()).sort(([a], [b]) => a - b);
|
|
193
|
-
}, [
|
|
205
|
+
}, [expandedElements]);
|
|
194
206
|
|
|
195
207
|
const trackStyles = useMemo(() => {
|
|
196
208
|
const map = new Map<number, TrackVisualStyle>();
|
|
@@ -247,8 +259,9 @@ export const Timeline = memo(function Timeline({
|
|
|
247
259
|
const toggleSelectedKeyframe = usePlayerStore((s) => s.toggleSelectedKeyframe);
|
|
248
260
|
|
|
249
261
|
const selectedElement = useMemo(
|
|
250
|
-
() =>
|
|
251
|
-
|
|
262
|
+
() =>
|
|
263
|
+
expandedElements.find((element) => (element.key ?? element.id) === selectedElementId) ?? null,
|
|
264
|
+
[expandedElements, selectedElementId],
|
|
252
265
|
);
|
|
253
266
|
const selectedElementRef = useRef<TimelineElement | null>(selectedElement);
|
|
254
267
|
selectedElementRef.current = selectedElement;
|
|
@@ -283,7 +296,7 @@ export const Timeline = memo(function Timeline({
|
|
|
283
296
|
effectiveDuration,
|
|
284
297
|
pps,
|
|
285
298
|
timelineReady,
|
|
286
|
-
elementsLength:
|
|
299
|
+
elementsLength: expandedElements.length,
|
|
287
300
|
setZoomMode,
|
|
288
301
|
setManualZoomPercent,
|
|
289
302
|
onSeek,
|
|
@@ -332,7 +345,7 @@ export const Timeline = memo(function Timeline({
|
|
|
332
345
|
|
|
333
346
|
useEffect(() => {
|
|
334
347
|
syncShortcutHintVisibility();
|
|
335
|
-
}, [syncShortcutHintVisibility, timelineReady,
|
|
348
|
+
}, [syncShortcutHintVisibility, timelineReady, expandedElements.length, totalH]);
|
|
336
349
|
|
|
337
350
|
const getPreviewElement = useCallback(
|
|
338
351
|
(element: TimelineElement): TimelineElement => {
|
|
@@ -362,7 +375,7 @@ export const Timeline = memo(function Timeline({
|
|
|
362
375
|
onBlockDrop,
|
|
363
376
|
});
|
|
364
377
|
|
|
365
|
-
if (!timelineReady ||
|
|
378
|
+
if (!timelineReady || expandedElements.length === 0) {
|
|
366
379
|
return (
|
|
367
380
|
<TimelineEmptyState
|
|
368
381
|
isDragOver={isDragOver}
|
|
@@ -482,7 +495,7 @@ export const Timeline = memo(function Timeline({
|
|
|
482
495
|
}
|
|
483
496
|
}}
|
|
484
497
|
onContextMenuKeyframe={(e, elId, pct) => {
|
|
485
|
-
const el =
|
|
498
|
+
const el = expandedElements.find((x) => (x.key ?? x.id) === elId);
|
|
486
499
|
if (el) {
|
|
487
500
|
setSelectedElementId(elId);
|
|
488
501
|
onSelectElement?.(el);
|
|
@@ -102,7 +102,7 @@ export const TimelineClip = memo(function TimelineClip({
|
|
|
102
102
|
onDoubleClick={onDoubleClick}
|
|
103
103
|
onContextMenu={onContextMenu}
|
|
104
104
|
>
|
|
105
|
-
{/* Left accent stripe */}
|
|
105
|
+
{/* Left accent stripe — wider + brighter for expanded sub-comp children */}
|
|
106
106
|
<div
|
|
107
107
|
aria-hidden="true"
|
|
108
108
|
style={{
|
|
@@ -110,9 +110,9 @@ export const TimelineClip = memo(function TimelineClip({
|
|
|
110
110
|
left: 0,
|
|
111
111
|
top: 0,
|
|
112
112
|
bottom: 0,
|
|
113
|
-
width: 3,
|
|
113
|
+
width: el.expandedParentStart !== undefined ? 4 : 3,
|
|
114
114
|
background: trackStyle.accent,
|
|
115
|
-
opacity: isSelected ? 0.7 : 0.3,
|
|
115
|
+
opacity: el.expandedParentStart !== undefined ? 0.8 : isSelected ? 0.7 : 0.3,
|
|
116
116
|
borderRadius: `${theme.clipRadius} 0 0 ${theme.clipRadius}`,
|
|
117
117
|
zIndex: 2,
|
|
118
118
|
pointerEvents: "none",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useTimelineEditContext } from "../../contexts/TimelineEditContext";
|
|
3
|
+
import type { TimelineEditCallbacks } from "./timelineCallbacks";
|
|
4
|
+
|
|
5
|
+
// Props a parent (e.g. NLELayout) may pass to <Timeline> to intercept edits —
|
|
6
|
+
// the rest of the callback bag still comes from TimelineEditContext.
|
|
7
|
+
export type TimelineEditOverrides = Pick<
|
|
8
|
+
TimelineEditCallbacks,
|
|
9
|
+
"onMoveElement" | "onResizeElement" | "onBlockedEditAttempt" | "onSplitElement"
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
// Merge any prop overrides over the context callbacks. Used so NLELayout can
|
|
13
|
+
// wrap move/resize/split (to rebase expanded sub-comp clips) while every other
|
|
14
|
+
// callback falls through to the context unchanged.
|
|
15
|
+
export function useResolvedTimelineEditCallbacks(
|
|
16
|
+
overrides: TimelineEditOverrides,
|
|
17
|
+
): TimelineEditCallbacks {
|
|
18
|
+
const ctx = useTimelineEditContext();
|
|
19
|
+
const { onMoveElement, onResizeElement, onBlockedEditAttempt, onSplitElement } = overrides;
|
|
20
|
+
return useMemo(
|
|
21
|
+
() => ({
|
|
22
|
+
...ctx,
|
|
23
|
+
onMoveElement: onMoveElement ?? ctx.onMoveElement,
|
|
24
|
+
onResizeElement: onResizeElement ?? ctx.onResizeElement,
|
|
25
|
+
onBlockedEditAttempt: onBlockedEditAttempt ?? ctx.onBlockedEditAttempt,
|
|
26
|
+
onSplitElement: onSplitElement ?? ctx.onSplitElement,
|
|
27
|
+
}),
|
|
28
|
+
[ctx, onMoveElement, onResizeElement, onBlockedEditAttempt, onSplitElement],
|
|
29
|
+
);
|
|
30
|
+
}
|