Skip to content

Commit 2d1b905

Browse files
committed
feat(studio): consolidate timeline editor callbacks
1 parent 555d7f7 commit 2d1b905

14 files changed

Lines changed: 959 additions & 342 deletions

‎packages/studio/src/App.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export function StudioApp() {
401401
panelLayout.rightInspectorPanes,
402402
panelLayout.rightCollapsed,
403403
isPlaying,
404+
domEditSession.domEditSelection,
404405
gestureState === "recording",
405406
);
406407
useStudioUrlState({

‎packages/studio/src/components/editor/AnimationCard.tsx‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback, useMemo, useState } from "react";
1+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
33
import { SUPPORTED_EASES, SUPPORTED_PROPS } from "@hyperframes/core/gsap-constants";
44
import { trackStudioSegmentEaseEdit } from "../../telemetry/events";
@@ -23,13 +23,17 @@ interface AnimationCardProps extends GsapAnimationEditCallbacks {
2323
animation: GsapAnimation;
2424
defaultExpanded: boolean;
2525
flat?: boolean;
26+
focusedSegment?: { tweenPercentage: number } | null;
27+
onFocusSegmentConsumed?: () => void;
2628
}
2729

2830
// fallow-ignore-next-line complexity
2931
export const AnimationCard = memo(function AnimationCard({
3032
animation,
3133
defaultExpanded,
3234
flat,
35+
focusedSegment,
36+
onFocusSegmentConsumed,
3337
onUpdateProperty,
3438
onUpdateMeta,
3539
onDeleteAnimation,
@@ -50,6 +54,25 @@ export const AnimationCard = memo(function AnimationCard({
5054
const [addingProp, setAddingProp] = useState(false);
5155
const [addingFromProp, setAddingFromProp] = useState(false);
5256
const [expandedKfPct, setExpandedKfPct] = useState<number | null>(null);
57+
const cardRef = useRef<HTMLDivElement>(null);
58+
const pendingAutoScrollRef = useRef(false);
59+
60+
useEffect(() => {
61+
if (!focusedSegment) return;
62+
setExpanded(true);
63+
pendingAutoScrollRef.current = true;
64+
setExpandedKfPct(focusedSegment.tweenPercentage);
65+
onFocusSegmentConsumed?.();
66+
}, [focusedSegment, onFocusSegmentConsumed]);
67+
68+
useEffect(() => {
69+
if (!pendingAutoScrollRef.current || expandedKfPct === null) return;
70+
const segment = cardRef.current?.querySelector<HTMLElement>(
71+
`[data-ease-segment-pct="${expandedKfPct}"]`,
72+
);
73+
segment?.scrollIntoView({ block: "nearest", behavior: "smooth" });
74+
pendingAutoScrollRef.current = false;
75+
}, [expandedKfPct]);
5376

5477
const usedProps = useMemo(
5578
() => new Set(Object.keys(animation.properties)),
@@ -154,6 +177,7 @@ export const AnimationCard = memo(function AnimationCard({
154177

155178
return (
156179
<div
180+
ref={cardRef}
157181
data-flat-effect-card={flat ? "true" : undefined}
158182
className={
159183
flat
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { ADD_METHODS, ADD_METHOD_LABELS, METHOD_TOOLTIPS } from "./gsapAnimationConstants";
2+
3+
const STYLES = {
4+
classic: {
5+
method:
6+
"rounded-lg border border-neutral-700 bg-neutral-900 px-2.5 py-1.5 text-[11px] font-medium text-neutral-300 transition-colors hover:border-neutral-600 hover:text-white",
7+
cancel: "px-1.5 text-[11px] text-neutral-500 hover:text-neutral-300",
8+
trigger: "text-[11px] font-medium text-neutral-400 transition-colors hover:text-neutral-200",
9+
},
10+
flat: {
11+
method:
12+
"rounded-lg border border-panel-border-input bg-panel-input px-2.5 py-1.5 text-[11px] font-medium text-panel-text-2 transition-colors hover:border-panel-text-4 hover:text-panel-text-0",
13+
cancel: "px-1.5 text-[11px] text-panel-text-3 hover:text-panel-text-1",
14+
trigger: "text-[11px] font-medium text-panel-text-3 transition-colors hover:text-panel-text-1",
15+
},
16+
};
17+
18+
export function GsapAddAnimationControl({
19+
open,
20+
setOpen,
21+
onAddAnimation,
22+
track,
23+
variant,
24+
}: {
25+
open: boolean;
26+
setOpen: (open: boolean) => void;
27+
onAddAnimation: (method: "to" | "from" | "set" | "fromTo") => void;
28+
track: (control: string, name: string) => void;
29+
variant: keyof typeof STYLES;
30+
}) {
31+
const styles = STYLES[variant];
32+
33+
return (
34+
<div className="relative pt-1">
35+
{open ? (
36+
<div className="flex gap-1.5">
37+
{ADD_METHODS.map((method) => (
38+
<button
39+
key={method}
40+
type="button"
41+
title={METHOD_TOOLTIPS[method]}
42+
onClick={() => {
43+
track("button", `Add ${method} animation`);
44+
onAddAnimation(method);
45+
setOpen(false);
46+
}}
47+
className={styles.method}
48+
>
49+
{ADD_METHOD_LABELS[method] ?? method}
50+
</button>
51+
))}
52+
<button type="button" onClick={() => setOpen(false)} className={styles.cancel}>
53+
Cancel
54+
</button>
55+
</div>
56+
) : (
57+
<button
58+
type="button"
59+
onClick={() => setOpen(true)}
60+
className={styles.trigger}
61+
title="Add a new animation effect to this element"
62+
>
63+
+ Add effect
64+
</button>
65+
)}
66+
</div>
67+
);
68+
}

‎packages/studio/src/components/editor/GsapAnimationSection.tsx‎

Lines changed: 18 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { memo, useState } from "react";
22
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
33
import { Film } from "../../icons/SystemIcons";
44
import { Section } from "./propertyPanelPrimitives";
5-
import { ADD_METHODS, ADD_METHOD_LABELS, METHOD_TOOLTIPS } from "./gsapAnimationConstants";
65
import { AnimationCard } from "./AnimationCard";
76
import {
8-
trackAnimationMetaUpdate,
97
type GsapAnimationEditCallbacks,
8+
withTrackedGsapAnimationCallbacks,
109
} from "./gsapAnimationCallbacks";
1110
import { useTrackDesignInput } from "../../contexts/DesignPanelInputContext";
11+
import { usePlayerStore } from "../../player";
12+
import { GsapAddAnimationControl } from "./GsapAddAnimationControl";
1213

1314
interface GsapAnimationSectionProps extends GsapAnimationEditCallbacks {
1415
animations: GsapAnimation[];
@@ -21,41 +22,14 @@ export const GsapAnimationSection = memo(function GsapAnimationSection({
2122
animations,
2223
multipleTimelines,
2324
unsupportedTimelinePattern,
24-
onUpdateProperty,
25-
onUpdateMeta,
26-
onDeleteAnimation,
27-
onAddProperty,
28-
onRemoveProperty,
29-
onUpdateFromProperty,
30-
onAddFromProperty,
31-
onRemoveFromProperty,
3225
onAddAnimation,
33-
onLivePreview,
34-
onLivePreviewEnd,
35-
onSetArcPath,
36-
onUpdateArcSegment,
37-
onUpdateKeyframeEase,
38-
onSetAllKeyframeEases,
39-
onUnroll,
26+
...callbacks
4027
}: GsapAnimationSectionProps) {
4128
const track = useTrackDesignInput();
4229
const [addMenuOpen, setAddMenuOpen] = useState(false);
43-
const trackProperty = (property: string) => {
44-
const control =
45-
property === "visibility"
46-
? "toggle"
47-
: property === "filter" || property === "clipPath"
48-
? "text"
49-
: "metric";
50-
track(control, property);
51-
};
52-
const updateMeta = (
53-
animationId: string,
54-
updates: { duration?: number; ease?: string; position?: number },
55-
) => {
56-
trackAnimationMetaUpdate(track, updates);
57-
onUpdateMeta(animationId, updates);
58-
};
30+
const trackedCallbacks = withTrackedGsapAnimationCallbacks(callbacks, track);
31+
const focusedEaseSegment = usePlayerStore((s) => s.focusedEaseSegment);
32+
const setFocusedEaseSegment = usePlayerStore((s) => s.setFocusedEaseSegment);
5933

6034
return (
6135
<Section title="Animation" icon={<Film size={15} />}>
@@ -76,137 +50,24 @@ export const GsapAnimationSection = memo(function GsapAnimationSection({
7650
<div className="space-y-2">
7751
{animations.map((anim, index) => (
7852
<AnimationCard
53+
{...trackedCallbacks}
7954
key={anim.id}
8055
animation={anim}
8156
defaultExpanded={index === 0}
82-
onUpdateProperty={(animationId, property, value) => {
83-
trackProperty(property);
84-
onUpdateProperty(animationId, property, value);
85-
}}
86-
onUpdateMeta={updateMeta}
87-
onDeleteAnimation={(animationId) => {
88-
track("button", "Remove animation");
89-
onDeleteAnimation(animationId);
90-
}}
91-
onAddProperty={(animationId, property) => {
92-
track("select", "Add effect property");
93-
onAddProperty(animationId, property);
94-
}}
95-
onRemoveProperty={(animationId, property) => {
96-
track("button", `Remove ${property}`);
97-
onRemoveProperty(animationId, property);
98-
}}
99-
onUpdateFromProperty={
100-
onUpdateFromProperty
101-
? (animationId, property, value) => {
102-
trackProperty(property);
103-
onUpdateFromProperty(animationId, property, value);
104-
}
105-
: undefined
106-
}
107-
onAddFromProperty={
108-
onAddFromProperty
109-
? (animationId, property) => {
110-
track("select", "Add from property");
111-
onAddFromProperty(animationId, property);
112-
}
113-
: undefined
114-
}
115-
onRemoveFromProperty={
116-
onRemoveFromProperty
117-
? (animationId, property) => {
118-
track("button", `Remove from ${property}`);
119-
onRemoveFromProperty(animationId, property);
120-
}
121-
: undefined
122-
}
123-
onLivePreview={onLivePreview}
124-
onLivePreviewEnd={onLivePreviewEnd}
125-
onSetArcPath={
126-
onSetArcPath
127-
? (animationId, config) => {
128-
track(
129-
"toggle",
130-
config.autoRotate !== undefined ? "Auto rotate" : "Arc motion",
131-
);
132-
onSetArcPath(animationId, config);
133-
}
134-
: undefined
135-
}
136-
onUpdateArcSegment={
137-
onUpdateArcSegment
138-
? (animationId, segmentIndex, update) => {
139-
if (update.curviness === undefined) {
140-
track("button", `Reset arc segment ${segmentIndex + 1}`);
141-
}
142-
onUpdateArcSegment(animationId, segmentIndex, update);
143-
}
144-
: undefined
145-
}
146-
onUpdateKeyframeEase={
147-
onUpdateKeyframeEase
148-
? (animationId, percentage, ease) => {
149-
track("select", "Keyframe ease");
150-
onUpdateKeyframeEase(animationId, percentage, ease);
151-
}
152-
: undefined
153-
}
154-
onSetAllKeyframeEases={
155-
onSetAllKeyframeEases
156-
? (animationId, ease) => {
157-
track("select", "All keyframe eases");
158-
onSetAllKeyframeEases(animationId, ease);
159-
}
160-
: undefined
161-
}
162-
onUnroll={
163-
onUnroll
164-
? (animationId) => {
165-
track("button", "Unroll animation");
166-
onUnroll(animationId);
167-
}
168-
: undefined
57+
focusedSegment={
58+
focusedEaseSegment?.animationId === anim.id ? focusedEaseSegment : null
16959
}
60+
onFocusSegmentConsumed={() => setFocusedEaseSegment(null)}
17061
/>
17162
))}
17263

173-
<div className="relative pt-1">
174-
{addMenuOpen ? (
175-
<div className="flex gap-1.5">
176-
{ADD_METHODS.map((method) => (
177-
<button
178-
key={method}
179-
type="button"
180-
title={METHOD_TOOLTIPS[method]}
181-
onClick={() => {
182-
track("button", `Add ${method} animation`);
183-
onAddAnimation(method);
184-
setAddMenuOpen(false);
185-
}}
186-
className="rounded-lg border border-neutral-700 bg-neutral-900 px-2.5 py-1.5 text-[11px] font-medium text-neutral-300 transition-colors hover:border-neutral-600 hover:text-white"
187-
>
188-
{ADD_METHOD_LABELS[method] ?? method}
189-
</button>
190-
))}
191-
<button
192-
type="button"
193-
onClick={() => setAddMenuOpen(false)}
194-
className="px-1.5 text-[11px] text-neutral-500 hover:text-neutral-300"
195-
>
196-
Cancel
197-
</button>
198-
</div>
199-
) : (
200-
<button
201-
type="button"
202-
onClick={() => setAddMenuOpen(true)}
203-
className="text-[11px] font-medium text-neutral-400 transition-colors hover:text-neutral-200"
204-
title="Add a new animation effect to this element"
205-
>
206-
+ Add effect
207-
</button>
208-
)}
209-
</div>
64+
<GsapAddAnimationControl
65+
open={addMenuOpen}
66+
setOpen={setAddMenuOpen}
67+
onAddAnimation={onAddAnimation}
68+
track={track}
69+
variant="classic"
70+
/>
21071
</div>
21172
)}
21273
</Section>

0 commit comments

Comments
 (0)