@@ -285,31 +285,42 @@ export class Controls {
285285 for ( let i = groups . length - 1 ; i >= 0 ; i -- ) {
286286 const storeID = `formeo-controls-${ groups [ i ] } `
287287 if ( ! this . options . sortable ) {
288- window . localStorage . removeItem ( storeID )
288+ globalThis . localStorage . removeItem ( storeID )
289289 }
290290 Sortable . create ( groups [ i ] , {
291291 animation : 150 ,
292- forceFallback : true ,
293292 fallbackClass : 'control-moving' ,
294293 fallbackOnBody : true ,
294+ forceFallback : true ,
295+ fallbackTolerance : 5 ,
295296 group : {
296297 name : 'controls' ,
297298 pull : 'clone' ,
298299 put : false ,
300+ revertClone : true ,
299301 } ,
300- onStart : async ( { item } ) => {
301- const { controlData } = this . get ( item . id )
302+ onClone : ( { clone, item } ) => {
303+ // Copy the item's id to the clone so we can identify what control it represents
304+ clone . id = item . id
305+
302306 if ( this . options . ghostPreview ) {
307+ const { controlData } = this . get ( item . id )
303308 // Dynamically import Field to avoid circular dependency
304- const { default : Field } = await import ( '../fields/field.js' )
305- item . innerHTML = ''
306- item . appendChild ( new Field ( controlData ) . preview )
309+ import ( '../fields/field.js' ) . then ( ( { default : Field } ) => {
310+ clone . innerHTML = ''
311+ clone . appendChild ( new Field ( controlData ) . preview )
312+ } )
307313 }
308314 } ,
309- onEnd : ( { from, item, clone } ) => {
310- if ( from . contains ( clone ) ) {
311- from . replaceChild ( item , clone )
312- }
315+ onStart : ( ) => {
316+ // Prevent scrollbar flashing during drag by hiding overflow
317+ this . originalDocumentOverflow = document . documentElement . style . overflow
318+ document . documentElement . style . overflow = 'hidden'
319+ } ,
320+ onEnd : ( ) => {
321+ // Restore overflow after drag completes
322+ document . documentElement . style . overflow = this . originalDocumentOverflow
323+ this . originalDocumentOverflow = null
313324 } ,
314325 sort : this . options . sortable ,
315326 store : {
@@ -319,7 +330,7 @@ export class Controls {
319330 * @return {Array }
320331 */
321332 get : ( ) => {
322- const order = window . localStorage . getItem ( storeID )
333+ const order = globalThis . localStorage . getItem ( storeID )
323334 return order ? order . split ( '|' ) : [ ]
324335 } ,
325336
@@ -329,7 +340,7 @@ export class Controls {
329340 */
330341 set : sortable => {
331342 const order = sortable . toArray ( )
332- window . localStorage . setItem ( storeID , order . join ( '|' ) )
343+ globalThis . localStorage . setItem ( storeID , order . join ( '|' ) )
333344 } ,
334345 } ,
335346 } )
0 commit comments