Skip to content

Commit 9f34bdf

Browse files
committed
wip
1 parent 380e800 commit 9f34bdf

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

packages/dflex-dnd/src/Mechanism/DFlexMechanismController.ts

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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";
29

310
import { DFLEX_EVENTS, scheduler, store } from "../LayoutManager";
411
import type DraggableInteractive from "../Draggable";
@@ -152,7 +159,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
152159
// If it has solo empty id then there's no need to move down. Because it's
153160
// empty branch.
154161
if (hasToMoveSiblingsDown && !isEmpty) {
155-
this._moveDown(insertAt);
162+
this._moveDown(insertAt, "y");
156163
}
157164

158165
draggedElm.removeAttribute(this.draggable.draggedDOM, "OUT_CONTAINER");
@@ -274,7 +281,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
274281
}
275282
}
276283

277-
private _switchElementPosition(isIncrease: boolean): void {
284+
private _switchElementPosition(axis: Axis, isIncrease: boolean): void {
278285
const { draggedElm } = this.draggable;
279286
const { SK, index, cycleID } = store.migration.latest();
280287

@@ -294,14 +301,14 @@ class DFlexMechanismController extends DFlexScrollableElement {
294301
if (isIDEligible(id, draggedElm.id)) {
295302
this.draggable.setDraggedTempIndex(elmIndex);
296303

297-
this.updateElement(id, siblings, cycleID, isIncrease);
304+
this.updateElement(axis, id, siblings, cycleID, isIncrease);
298305
}
299306
}
300307

301308
/**
302309
* Filling the space when the head of the list is leaving the list.
303310
*/
304-
private _fillHeadUp(): void {
311+
private _fillHeadUp(axis: Axis): void {
305312
const { occupiedPosition, draggedElm, events } = this.draggable;
306313
const { migration } = store;
307314

@@ -363,7 +370,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
363370
const id = siblings[i];
364371

365372
if (isIDEligible(id, draggedElm.id)) {
366-
this.updateElement(id, siblings, cycleID, true);
373+
this.updateElement(axis, id, siblings, cycleID, true);
367374
}
368375
}
369376
}
@@ -372,7 +379,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
372379
*
373380
* @param to - index
374381
*/
375-
private _moveDown(to: number): void {
382+
private _moveDown(axis: Axis, to: number): void {
376383
const { events, draggedElm } = this.draggable;
377384
const { migration } = store;
378385

@@ -390,7 +397,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
390397
const id = siblings[i];
391398

392399
if (isIDEligible(id, draggedElm.id)) {
393-
this.updateElement(id, siblings, cycleID, false);
400+
this.updateElement(axis, id, siblings, cycleID, false);
394401
}
395402
}
396403
}
@@ -407,12 +414,16 @@ class DFlexMechanismController extends DFlexScrollableElement {
407414

408415
const { grid: siblingsGrid } = store.containers.get(SK)!;
409416

417+
let axis: Axis;
418+
410419
// Check if top or bottom.
411420
if (isOut[id].isOneTruthyByAxis("y")) {
412421
const newRow = isOut[id].bottom
413422
? gridPlaceholder.y + 1
414423
: gridPlaceholder.y - 1;
415424

425+
axis = AXIS.Y;
426+
416427
if (__DEV__) {
417428
if (featureFlags.enableMechanismDebugger) {
418429
// eslint-disable-next-line no-console
@@ -427,7 +438,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
427438
// lock the parent
428439
this._lockParent(true);
429440

430-
this._fillHeadUp();
441+
this._fillHeadUp(axis);
431442

432443
return;
433444
}
@@ -440,7 +451,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
440451
return;
441452
}
442453

443-
this._switchElementPosition(isOut[id].bottom);
454+
this._switchElementPosition(axis, isOut[id].bottom);
444455

445456
return;
446457
}
@@ -449,6 +460,8 @@ class DFlexMechanismController extends DFlexScrollableElement {
449460
? gridPlaceholder.x + 1
450461
: gridPlaceholder.x - 1;
451462

463+
axis = AXIS.X;
464+
452465
if (__DEV__) {
453466
if (featureFlags.enableMechanismDebugger) {
454467
// eslint-disable-next-line no-console
@@ -462,12 +475,12 @@ class DFlexMechanismController extends DFlexScrollableElement {
462475
// lock the parent
463476
this._lockParent(true);
464477

465-
this._fillHeadUp();
478+
this._fillHeadUp(axis);
466479

467480
return;
468481
}
469482

470-
this._switchElementPosition(isOut[id].right);
483+
this._switchElementPosition(axis, isOut[id].right);
471484
}
472485

473486
private _lockParent(isOut: boolean) {
@@ -504,7 +517,8 @@ class DFlexMechanismController extends DFlexScrollableElement {
504517
if (!(isOutSiblingsContainer || this.isParentLocked)) {
505518
this._lockParent(true);
506519

507-
this._fillHeadUp();
520+
// TODO: FIx this.
521+
this._fillHeadUp(AXIS.Y);
508522
}
509523
},
510524
});

packages/dflex-dnd/src/Mechanism/DFlexPositionUpdater.ts

+1-25
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ class DFlexPositionUpdater {
436436
* invokes for each eligible element in the parent container.
437437
*/
438438
protected updateElement(
439+
axis: Axis,
439440
id: string,
440441
siblings: Siblings,
441442
cycleID: string,
@@ -448,31 +449,6 @@ class DFlexPositionUpdater {
448449

449450
const [element, DOM] = store.getElmWithDOM(id);
450451

451-
const {
452-
keys: { SK },
453-
} = element;
454-
455-
const { grid: siblingsGrid } = store.containers.get(SK)!;
456-
457-
const isContainerHasCol =
458-
this.draggable.gridPlaceholder.x + 1 <= siblingsGrid.x;
459-
460-
let axis: Axis;
461-
462-
if (isContainerHasCol) {
463-
axis = "x";
464-
} else {
465-
axis = "y";
466-
467-
// const isContainerHasRowAbove =
468-
// this.draggable.gridPlaceholder.y + 1 <= siblingsGrid.y;
469-
470-
// if (isContainerHasRowAbove) {
471-
// // Bi-directional
472-
// axis = "z";
473-
// }
474-
}
475-
476452
if (__DEV__) {
477453
if (featureFlags.enableMechanismDebugger) {
478454
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)