@@ -2,13 +2,14 @@ import { memo, useState } from "react";
22import type { GsapAnimation } from "@hyperframes/core/gsap-parser" ;
33import { Film } from "../../icons/SystemIcons" ;
44import { Section } from "./propertyPanelPrimitives" ;
5- import { ADD_METHODS , ADD_METHOD_LABELS , METHOD_TOOLTIPS } from "./gsapAnimationConstants" ;
65import { AnimationCard } from "./AnimationCard" ;
76import {
8- trackAnimationMetaUpdate ,
97 type GsapAnimationEditCallbacks ,
8+ withTrackedGsapAnimationCallbacks ,
109} from "./gsapAnimationCallbacks" ;
1110import { useTrackDesignInput } from "../../contexts/DesignPanelInputContext" ;
11+ import { usePlayerStore } from "../../player" ;
12+ import { GsapAddAnimationControl } from "./GsapAddAnimationControl" ;
1213
1314interface 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