@@ -117,14 +117,8 @@ function mountGroupHandler({
117117 makeFetchFallback,
118118 trackGsapInteractionFailure = vi . fn ( ) ,
119119 stageElementPositionOffset = vi . fn ( ) ,
120- commitPositionPatchToHtml = vi . fn ( ) ,
121120} : Pick < AwareEditingParams , "gsapCommitMutation" | "makeFetchFallback" > &
122- Partial <
123- Pick <
124- AwareEditingParams ,
125- "trackGsapInteractionFailure" | "stageElementPositionOffset" | "commitPositionPatchToHtml"
126- >
127- > ) {
121+ Partial < Pick < AwareEditingParams , "trackGsapInteractionFailure" | "stageElementPositionOffset" > > ) {
128122 let groupCommit ! : ( updates : DomEditGroupPathOffsetCommit [ ] ) => Promise < void > ;
129123 let pathOffsetCommit ! : (
130124 selection : DomEditSelection ,
@@ -142,7 +136,7 @@ function mountGroupHandler({
142136 trackGsapInteractionFailure,
143137 stageElementPositionOffset,
144138 handleDomBoxSizeCommit : vi . fn ( ) ,
145- commitPositionPatchToHtml,
139+ commitPositionPatchToHtml : vi . fn ( ) ,
146140 addGsapAnimation : vi . fn ( ) ,
147141 convertToKeyframes : vi . fn ( ) ,
148142 setArcPath : vi . fn ( ) ,
@@ -162,72 +156,25 @@ function mountGroupHandler({
162156}
163157
164158describe ( "useGsapAwareEditing moves of an element GSAP does not position" , ( ) => {
165- const translatePatch = ( value : string ) => [ { type : "inline-style" , property : "translate" , value } ] ;
166-
167- it ( "writes its inline translate as drawn, with no GSAP write and no animation read" , async ( ) => {
168- const commitPositionPatchToHtml = vi . fn ( ) . mockResolvedValue ( undefined ) ;
159+ it ( "saves the move on the element itself, with no GSAP write and no animation read" , async ( ) => {
160+ const save = vi . fn ( ) . mockResolvedValue ( undefined ) ;
161+ const stageElementPositionOffset = vi . fn ( ( ) => ( { save, rollback : vi . fn ( ) } ) ) ;
169162 const gsapCommitMutation = vi . fn ( ) ;
170163 const makeFetchFallback = vi . fn ( ) ;
171164 const { pathOffsetCommit, root } = mountGroupHandler ( {
172165 gsapCommitMutation,
173166 makeFetchFallback,
174- commitPositionPatchToHtml ,
167+ stageElementPositionOffset ,
175168 } ) ;
176169 const box = { element : document . createElement ( "div" ) , id : "box" , selector : "#box" } ;
177170 await act ( ( ) => pathOffsetCommit ( box as unknown as DomEditSelection , { x : 130.25 , y : 90 } ) ) ;
178- expect ( box . element . style . getPropertyValue ( "translate" ) ) . toBe ( "130.25px 90px" ) ;
179- expect ( commitPositionPatchToHtml ) . toHaveBeenCalledWith (
180- box ,
181- translatePatch ( "130.25px 90px" ) ,
182- expect . objectContaining ( { label : "Move layer" } ) ,
183- ) ;
171+ expect ( stageElementPositionOffset ) . toHaveBeenCalledWith ( box , { x : 130.25 , y : 90 } ) ;
172+ expect ( save ) . toHaveBeenCalledTimes ( 1 ) ;
184173 expect ( gsapCommitMutation ) . not . toHaveBeenCalled ( ) ;
185174 expect ( makeFetchFallback ) . not . toHaveBeenCalled ( ) ;
186175 expect ( mocks . drag ) . not . toHaveBeenCalled ( ) ;
187176 act ( ( ) => root . unmount ( ) ) ;
188177 } ) ;
189-
190- it ( "puts the live translate back when the save fails" , async ( ) => {
191- const commitPositionPatchToHtml = vi . fn ( ) . mockRejectedValue ( new Error ( "offline" ) ) ;
192- const gsapCommitMutation = vi . fn ( ) ;
193- const { pathOffsetCommit, root } = mountGroupHandler ( {
194- gsapCommitMutation,
195- makeFetchFallback : vi . fn ( ) ,
196- commitPositionPatchToHtml,
197- } ) ;
198- const box = { element : document . createElement ( "div" ) , id : "box" , selector : "#box" } ;
199- box . element . style . setProperty ( "translate" , "40px 30px" ) ;
200- await expect ( pathOffsetCommit ( box as unknown as DomEditSelection , { x : 1 , y : 2 } ) ) . rejects . toThrow (
201- "offline" ,
202- ) ;
203- expect ( box . element . style . getPropertyValue ( "translate" ) ) . toBe ( "40px 30px" ) ;
204- act ( ( ) => root . unmount ( ) ) ;
205- } ) ;
206-
207- it ( "writes a GSAP-free group member by translate under the group key, the rest through GSAP" , async ( ) => {
208- mocks . drag . mockResolvedValue ( { status : "persisted" } ) ;
209- const commitPositionPatchToHtml = vi . fn ( ) . mockResolvedValue ( undefined ) ;
210- const { groupCommit, root } = mountGroupHandler ( {
211- gsapCommitMutation : vi . fn ( ) . mockResolvedValue ( undefined ) ,
212- makeFetchFallback : ( ) => vi . fn ( ) . mockResolvedValue ( [ ] ) ,
213- commitPositionPatchToHtml,
214- } ) ;
215- const plain = { element : document . createElement ( "div" ) , id : "plain" , selector : "#plain" } ;
216- const animated = { element : gsapPositioned ( "div" ) , id : "anim" , selector : "#anim" } ;
217- await act ( ( ) =>
218- groupCommit ( [
219- { selection : plain , next : { x : 10 , y : 20 } } ,
220- { selection : animated , next : { x : 10 , y : 20 } } ,
221- ] as unknown as DomEditGroupPathOffsetCommit [ ] ) ,
222- ) ;
223- expect ( commitPositionPatchToHtml ) . toHaveBeenCalledWith (
224- plain ,
225- translatePatch ( "10px 20px" ) ,
226- expect . objectContaining ( { coalesceKey : expect . stringMatching ( / ^ g r o u p - d r a g : \d + $ / ) } ) ,
227- ) ;
228- expect ( mocks . drag . mock . calls . map ( ( call ) => call [ 0 ] ) ) . toEqual ( [ animated , animated ] ) ;
229- act ( ( ) => root . unmount ( ) ) ;
230- } ) ;
231178} ) ;
232179
233180describe ( "useGsapAwareEditing shared-tween moves" , ( ) => {
@@ -249,7 +196,7 @@ describe("useGsapAwareEditing shared-tween moves", () => {
249196 act ( ( ) => root . unmount ( ) ) ;
250197 } ) ;
251198
252- it ( "saves a group member that shares a tween through its own offset , under the group key" , async ( ) => {
199+ it ( "saves shared-tween and GSAP-free group members on themselves , under the group key" , async ( ) => {
253200 mocks . drag . mockImplementation ( async ( selection , _next , _a , _i , commit , _f , options ) => {
254201 if ( selection . hfId === "w0" ) return { status : "element-offset" } ;
255202 if ( ! options ?. preflightOnly ) await commit ( selection , { type : "move" } , { label : "Move" } ) ;
@@ -264,17 +211,18 @@ describe("useGsapAwareEditing shared-tween moves", () => {
264211 } ) ;
265212 const word = { element : gsapPositioned ( "span" ) , hfId : "w0" , selector : ".w" } ;
266213 const box = { element : gsapPositioned ( "div" ) , id : "box" , selector : "#box" } ;
214+ const plain = { element : document . createElement ( "div" ) , id : "plain" , selector : "#plain" } ;
267215 await act ( ( ) =>
268216 groupCommit ( [
269217 { selection : word , next : { x : 40 , y : 20 } } ,
270218 { selection : box , next : { x : 40 , y : 20 } } ,
219+ { selection : plain , next : { x : 40 , y : 20 } } ,
271220 ] as unknown as DomEditGroupPathOffsetCommit [ ] ) ,
272221 ) ;
273- expect ( stageElementPositionOffset ) . toHaveBeenCalledWith (
274- word ,
275- { x : 40 , y : 20 } ,
276- expect . stringMatching ( / ^ g r o u p - d r a g : \d + $ / ) ,
277- ) ;
222+ const groupKey = expect . stringMatching ( / ^ g r o u p - d r a g : \d + $ / ) ;
223+ expect ( stageElementPositionOffset ) . toHaveBeenCalledWith ( word , { x : 40 , y : 20 } , groupKey ) ;
224+ expect ( stageElementPositionOffset ) . toHaveBeenCalledWith ( plain , { x : 40 , y : 20 } , groupKey ) ;
225+ expect ( mocks . drag . mock . calls . some ( ( call ) => call [ 0 ] === plain ) ) . toBe ( false ) ;
278226 act ( ( ) => root . unmount ( ) ) ;
279227 } ) ;
280228} ) ;
0 commit comments