1
- import { AxesPoint , featureFlags , PointNum , Tracker } from "@dflex/utils" ;
1
+ import {
2
+ AxesPoint ,
3
+ AXIS ,
4
+ Axis ,
5
+ featureFlags ,
6
+ PointNum ,
7
+ Tracker ,
8
+ } from "@dflex/utils" ;
2
9
3
10
import { DFLEX_EVENTS , scheduler , store } from "../LayoutManager" ;
4
11
import type DraggableInteractive from "../Draggable" ;
@@ -152,7 +159,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
152
159
// If it has solo empty id then there's no need to move down. Because it's
153
160
// empty branch.
154
161
if ( hasToMoveSiblingsDown && ! isEmpty ) {
155
- this . _moveDown ( insertAt ) ;
162
+ this . _moveDown ( insertAt , "y" ) ;
156
163
}
157
164
158
165
draggedElm . removeAttribute ( this . draggable . draggedDOM , "OUT_CONTAINER" ) ;
@@ -274,7 +281,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
274
281
}
275
282
}
276
283
277
- private _switchElementPosition ( isIncrease : boolean ) : void {
284
+ private _switchElementPosition ( axis : Axis , isIncrease : boolean ) : void {
278
285
const { draggedElm } = this . draggable ;
279
286
const { SK , index, cycleID } = store . migration . latest ( ) ;
280
287
@@ -294,14 +301,14 @@ class DFlexMechanismController extends DFlexScrollableElement {
294
301
if ( isIDEligible ( id , draggedElm . id ) ) {
295
302
this . draggable . setDraggedTempIndex ( elmIndex ) ;
296
303
297
- this . updateElement ( id , siblings , cycleID , isIncrease ) ;
304
+ this . updateElement ( axis , id , siblings , cycleID , isIncrease ) ;
298
305
}
299
306
}
300
307
301
308
/**
302
309
* Filling the space when the head of the list is leaving the list.
303
310
*/
304
- private _fillHeadUp ( ) : void {
311
+ private _fillHeadUp ( axis : Axis ) : void {
305
312
const { occupiedPosition, draggedElm, events } = this . draggable ;
306
313
const { migration } = store ;
307
314
@@ -363,7 +370,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
363
370
const id = siblings [ i ] ;
364
371
365
372
if ( isIDEligible ( id , draggedElm . id ) ) {
366
- this . updateElement ( id , siblings , cycleID , true ) ;
373
+ this . updateElement ( axis , id , siblings , cycleID , true ) ;
367
374
}
368
375
}
369
376
}
@@ -372,7 +379,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
372
379
*
373
380
* @param to - index
374
381
*/
375
- private _moveDown ( to : number ) : void {
382
+ private _moveDown ( axis : Axis , to : number ) : void {
376
383
const { events, draggedElm } = this . draggable ;
377
384
const { migration } = store ;
378
385
@@ -390,7 +397,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
390
397
const id = siblings [ i ] ;
391
398
392
399
if ( isIDEligible ( id , draggedElm . id ) ) {
393
- this . updateElement ( id , siblings , cycleID , false ) ;
400
+ this . updateElement ( axis , id , siblings , cycleID , false ) ;
394
401
}
395
402
}
396
403
}
@@ -407,12 +414,16 @@ class DFlexMechanismController extends DFlexScrollableElement {
407
414
408
415
const { grid : siblingsGrid } = store . containers . get ( SK ) ! ;
409
416
417
+ let axis : Axis ;
418
+
410
419
// Check if top or bottom.
411
420
if ( isOut [ id ] . isOneTruthyByAxis ( "y" ) ) {
412
421
const newRow = isOut [ id ] . bottom
413
422
? gridPlaceholder . y + 1
414
423
: gridPlaceholder . y - 1 ;
415
424
425
+ axis = AXIS . Y ;
426
+
416
427
if ( __DEV__ ) {
417
428
if ( featureFlags . enableMechanismDebugger ) {
418
429
// eslint-disable-next-line no-console
@@ -427,7 +438,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
427
438
// lock the parent
428
439
this . _lockParent ( true ) ;
429
440
430
- this . _fillHeadUp ( ) ;
441
+ this . _fillHeadUp ( axis ) ;
431
442
432
443
return ;
433
444
}
@@ -440,7 +451,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
440
451
return ;
441
452
}
442
453
443
- this . _switchElementPosition ( isOut [ id ] . bottom ) ;
454
+ this . _switchElementPosition ( axis , isOut [ id ] . bottom ) ;
444
455
445
456
return ;
446
457
}
@@ -449,6 +460,8 @@ class DFlexMechanismController extends DFlexScrollableElement {
449
460
? gridPlaceholder . x + 1
450
461
: gridPlaceholder . x - 1 ;
451
462
463
+ axis = AXIS . X ;
464
+
452
465
if ( __DEV__ ) {
453
466
if ( featureFlags . enableMechanismDebugger ) {
454
467
// eslint-disable-next-line no-console
@@ -462,12 +475,12 @@ class DFlexMechanismController extends DFlexScrollableElement {
462
475
// lock the parent
463
476
this . _lockParent ( true ) ;
464
477
465
- this . _fillHeadUp ( ) ;
478
+ this . _fillHeadUp ( axis ) ;
466
479
467
480
return ;
468
481
}
469
482
470
- this . _switchElementPosition ( isOut [ id ] . right ) ;
483
+ this . _switchElementPosition ( axis , isOut [ id ] . right ) ;
471
484
}
472
485
473
486
private _lockParent ( isOut : boolean ) {
@@ -504,7 +517,8 @@ class DFlexMechanismController extends DFlexScrollableElement {
504
517
if ( ! ( isOutSiblingsContainer || this . isParentLocked ) ) {
505
518
this . _lockParent ( true ) ;
506
519
507
- this . _fillHeadUp ( ) ;
520
+ // TODO: FIx this.
521
+ this . _fillHeadUp ( AXIS . Y ) ;
508
522
}
509
523
} ,
510
524
} ) ;
0 commit comments