@mk-drag-and-drop/dom 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +232 -478
- package/dist/controller/create-drag-controller.d.ts +1 -0
- package/dist/controller/create-drag-controller.js +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/input/keyboard-drag.d.ts +1 -1
- package/dist/input/keyboard-drag.js +3 -3
- package/dist/input/pointer-activation.js +10 -8
- package/dist/input/pointer-drag-state.d.ts +2 -0
- package/dist/input/pointer-drag-state.js +32 -0
- package/dist/integration/index.d.ts +2 -1
- package/dist/integration/index.js +1 -0
- package/dist/runtime/drag-runtime-scope.d.ts +2 -0
- package/dist/runtime/drag-runtime-scope.js +2 -0
- package/dist/runtime/drag-runtime.d.ts +7 -1
- package/dist/runtime/drag-runtime.js +214 -90
- package/dist/runtime/drop-target-registry.d.ts +3 -10
- package/dist/runtime/drop-target-registry.js +52 -96
- package/dist/runtime/lifecycle.d.ts +15 -0
- package/dist/runtime/sortable-coordinator.d.ts +32 -0
- package/dist/runtime/sortable-coordinator.js +11 -0
- package/dist/runtime/types.d.ts +1 -0
- package/dist/sortable/create-sortable.js +1 -0
- package/dist/sortable/sortable-preview.d.ts +3 -2
- package/dist/sortable/sortable-preview.js +48 -43
- package/dist/sortable/sortable-registry.d.ts +10 -54
- package/dist/sortable/sortable-registry.js +59 -46
- package/package.json +3 -3
|
@@ -200,14 +200,8 @@ export class DropTargetRegistry {
|
|
|
200
200
|
}
|
|
201
201
|
return dropTargets;
|
|
202
202
|
}
|
|
203
|
-
|
|
204
|
-
if (input.
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
const dropTarget = this.findRegistration(input.dropTargetId, {
|
|
208
|
-
group: input.group,
|
|
209
|
-
});
|
|
210
|
-
if (!dropTarget) {
|
|
203
|
+
normalizeSortablePlacement(input) {
|
|
204
|
+
if (input.group === null) {
|
|
211
205
|
return null;
|
|
212
206
|
}
|
|
213
207
|
const itemRegistration = this.findRegistration(input.draggableId, {
|
|
@@ -216,36 +210,45 @@ export class DropTargetRegistry {
|
|
|
216
210
|
if (!itemRegistration?.capabilities.sortable) {
|
|
217
211
|
return null;
|
|
218
212
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
const previewContainer = dropTarget.id === input.draggableId
|
|
224
|
-
? this.findContainerRegistrationForElement({
|
|
225
|
-
element: itemRegistration?.element.parentElement ?? null,
|
|
213
|
+
const activeTarget = input.activeDropTargetId
|
|
214
|
+
? this.findRegistration(input.activeDropTargetId, {
|
|
226
215
|
group: input.group,
|
|
227
216
|
})
|
|
228
217
|
: null;
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
dropTarget,
|
|
236
|
-
containerElement,
|
|
237
|
-
});
|
|
238
|
-
const targetPlacement = this.getTargetPlacement({
|
|
239
|
-
draggableId: input.draggableId,
|
|
218
|
+
const validActiveTarget = activeTarget?.capabilities.sortable ||
|
|
219
|
+
activeTarget?.capabilities.container
|
|
220
|
+
? activeTarget
|
|
221
|
+
: null;
|
|
222
|
+
const currentContainer = this.findContainerRegistrationForElement({
|
|
223
|
+
element: itemRegistration.element.parentElement,
|
|
240
224
|
group: input.group,
|
|
241
|
-
itemElement: itemRegistration.element,
|
|
242
|
-
dropTarget,
|
|
243
225
|
});
|
|
226
|
+
const previousDraggableId = this.getNearestSortableSiblingDraggableId(itemRegistration.element.previousElementSibling, input.group, "previous", input.draggableId);
|
|
227
|
+
const nextDraggableId = this.getNearestSortableSiblingDraggableId(itemRegistration.element.nextElementSibling, input.group, "next", input.draggableId);
|
|
228
|
+
const adjacentRegistration = previousDraggableId
|
|
229
|
+
? this.findRegistration(previousDraggableId, { group: input.group })
|
|
230
|
+
: nextDraggableId
|
|
231
|
+
? this.findRegistration(nextDraggableId, { group: input.group })
|
|
232
|
+
: null;
|
|
233
|
+
const activeTargetSharesParent = validActiveTarget?.element.parentElement ===
|
|
234
|
+
itemRegistration.element.parentElement;
|
|
235
|
+
const containerId = currentContainer?.id ??
|
|
236
|
+
adjacentRegistration?.containerId ??
|
|
237
|
+
(activeTargetSharesParent ? validActiveTarget.containerId : null) ??
|
|
238
|
+
itemRegistration.containerId;
|
|
239
|
+
const targetPlacement = validActiveTarget
|
|
240
|
+
? this.getNormalizedTargetPlacement({
|
|
241
|
+
draggableId: input.draggableId,
|
|
242
|
+
group: input.group,
|
|
243
|
+
itemElement: itemRegistration.element,
|
|
244
|
+
activeTarget: validActiveTarget,
|
|
245
|
+
})
|
|
246
|
+
: { targetDraggableId: null, side: null };
|
|
244
247
|
return {
|
|
245
248
|
sourceContainerId: input.sourceContainerId,
|
|
246
249
|
containerId,
|
|
247
|
-
previousDraggableId
|
|
248
|
-
nextDraggableId
|
|
250
|
+
previousDraggableId,
|
|
251
|
+
nextDraggableId,
|
|
249
252
|
targetDraggableId: targetPlacement.targetDraggableId,
|
|
250
253
|
side: targetPlacement.side,
|
|
251
254
|
};
|
|
@@ -264,7 +267,6 @@ export class DropTargetRegistry {
|
|
|
264
267
|
containerId: registration.containerId,
|
|
265
268
|
previousDraggableId,
|
|
266
269
|
nextDraggableId,
|
|
267
|
-
exactAnchors: this.getExactSortableItemAnchors(element, itemGroup),
|
|
268
270
|
};
|
|
269
271
|
}
|
|
270
272
|
getOrCreateGroupTargets(group) {
|
|
@@ -327,9 +329,9 @@ export class DropTargetRegistry {
|
|
|
327
329
|
}
|
|
328
330
|
findEntry(id, input = {}) {
|
|
329
331
|
if (input.group !== undefined) {
|
|
330
|
-
return
|
|
332
|
+
return input.group === null
|
|
331
333
|
? null
|
|
332
|
-
: this.targetsByGroup.get(input.group)?.get(id) ?? null
|
|
334
|
+
: this.targetsByGroup.get(input.group)?.get(id) ?? null;
|
|
333
335
|
}
|
|
334
336
|
for (const groupTargets of this.targetsByGroup.values()) {
|
|
335
337
|
const entry = groupTargets.get(id);
|
|
@@ -517,50 +519,24 @@ export class DropTargetRegistry {
|
|
|
517
519
|
if (!input.element) {
|
|
518
520
|
return null;
|
|
519
521
|
}
|
|
520
|
-
const
|
|
521
|
-
if (!
|
|
522
|
+
const target = this.targetElements.get(input.element);
|
|
523
|
+
if (!target || target.group !== input.group) {
|
|
522
524
|
return null;
|
|
523
525
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return {
|
|
530
|
-
...entry,
|
|
531
|
-
element,
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
getSiblingPlacement(input) {
|
|
538
|
-
if (input.itemElement.parentElement &&
|
|
539
|
-
input.itemElement.parentElement === input.containerElement) {
|
|
540
|
-
return {
|
|
541
|
-
previousDraggableId: this.getNearestSortableSiblingDraggableId(input.itemElement.previousElementSibling, input.group, "previous", input.draggableId),
|
|
542
|
-
nextDraggableId: this.getNearestSortableSiblingDraggableId(input.itemElement.nextElementSibling, input.group, "next", input.draggableId),
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
if (input.dropTarget.capabilities.container) {
|
|
546
|
-
return {
|
|
547
|
-
previousDraggableId: this.getNearestSortableSiblingDraggableId(input.dropTarget.element.lastElementChild, input.group, "previous", input.draggableId),
|
|
548
|
-
nextDraggableId: null,
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
return {
|
|
552
|
-
previousDraggableId: this.getNearestSortableSiblingDraggableId(input.dropTarget.element.previousElementSibling, input.group, "previous", input.draggableId),
|
|
553
|
-
nextDraggableId: input.dropTarget.id,
|
|
554
|
-
};
|
|
526
|
+
const entry = this.targetsByGroup.get(input.group)?.get(target.id);
|
|
527
|
+
const element = entry ? this.resolveEntry(entry) : null;
|
|
528
|
+
return entry?.capabilities.container && element === input.element
|
|
529
|
+
? { ...entry, element }
|
|
530
|
+
: null;
|
|
555
531
|
}
|
|
556
|
-
|
|
557
|
-
if (!input.
|
|
532
|
+
getNormalizedTargetPlacement(input) {
|
|
533
|
+
if (!input.activeTarget.capabilities.sortable) {
|
|
558
534
|
return {
|
|
559
535
|
targetDraggableId: null,
|
|
560
536
|
side: null,
|
|
561
537
|
};
|
|
562
538
|
}
|
|
563
|
-
if (input.
|
|
539
|
+
if (input.activeTarget.id === input.draggableId) {
|
|
564
540
|
return this.getPreviewDomTargetPlacement({
|
|
565
541
|
draggableId: input.draggableId,
|
|
566
542
|
group: input.group,
|
|
@@ -568,31 +544,13 @@ export class DropTargetRegistry {
|
|
|
568
544
|
});
|
|
569
545
|
}
|
|
570
546
|
return {
|
|
571
|
-
targetDraggableId: input.
|
|
547
|
+
targetDraggableId: input.activeTarget.id,
|
|
572
548
|
side: getSortableTargetSide({
|
|
573
549
|
itemElement: input.itemElement,
|
|
574
|
-
targetElement: input.
|
|
550
|
+
targetElement: input.activeTarget.element,
|
|
575
551
|
}),
|
|
576
552
|
};
|
|
577
553
|
}
|
|
578
|
-
getExactSortableItemAnchors(element, group) {
|
|
579
|
-
const anchors = [];
|
|
580
|
-
const previousDraggableId = this.getSortableDraggableId(element.previousElementSibling, group);
|
|
581
|
-
const nextDraggableId = this.getSortableDraggableId(element.nextElementSibling, group);
|
|
582
|
-
if (previousDraggableId) {
|
|
583
|
-
anchors.push({
|
|
584
|
-
targetDraggableId: previousDraggableId,
|
|
585
|
-
side: "after",
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
if (nextDraggableId) {
|
|
589
|
-
anchors.push({
|
|
590
|
-
targetDraggableId: nextDraggableId,
|
|
591
|
-
side: "before",
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
return anchors;
|
|
595
|
-
}
|
|
596
554
|
getPreviewDomTargetPlacement(input) {
|
|
597
555
|
const previousElement = input.itemElement.previousElementSibling;
|
|
598
556
|
const nextElement = input.itemElement.nextElementSibling;
|
|
@@ -687,11 +645,6 @@ function toPublicRegistration(registration) {
|
|
|
687
645
|
capabilities: registration.capabilities,
|
|
688
646
|
};
|
|
689
647
|
}
|
|
690
|
-
function getDropTargetContainerElement(dropTarget) {
|
|
691
|
-
return dropTarget.capabilities.container
|
|
692
|
-
? dropTarget.element
|
|
693
|
-
: dropTarget.element.parentElement;
|
|
694
|
-
}
|
|
695
648
|
function getSortableTargetSide(input) {
|
|
696
649
|
if (input.itemElement === input.targetElement ||
|
|
697
650
|
input.itemElement.parentElement !== input.targetElement.parentElement) {
|
|
@@ -803,7 +756,8 @@ function getNearestSortableAxisIndex(candidates, axisCoordinate) {
|
|
|
803
756
|
if (!previous || !next) {
|
|
804
757
|
return low;
|
|
805
758
|
}
|
|
806
|
-
return axisCoordinate - previous.axisCenter <=
|
|
759
|
+
return axisCoordinate - previous.axisCenter <=
|
|
760
|
+
next.axisCenter - axisCoordinate
|
|
807
761
|
? low - 1
|
|
808
762
|
: low;
|
|
809
763
|
}
|
|
@@ -829,7 +783,9 @@ function findSortableAxisCandidateContainingCoordinate(candidatesByStart, axisCo
|
|
|
829
783
|
return undefined;
|
|
830
784
|
}
|
|
831
785
|
const candidate = candidatesByStart[lastStartBeforeCoordinate];
|
|
832
|
-
return candidate && candidate.axisEnd >= axisCoordinate
|
|
786
|
+
return candidate && candidate.axisEnd >= axisCoordinate
|
|
787
|
+
? candidate
|
|
788
|
+
: undefined;
|
|
833
789
|
}
|
|
834
790
|
function hasOverlappingSortableAxisRanges(candidatesByStart) {
|
|
835
791
|
let previousAxisEnd = Number.NEGATIVE_INFINITY;
|
|
@@ -4,20 +4,24 @@ export type DragSource = "pointer" | "keyboard";
|
|
|
4
4
|
export type DragEndResult = "dropped" | "no-target" | "invalid-target" | "canceled";
|
|
5
5
|
export type DragStartEvent = {
|
|
6
6
|
draggableId: string;
|
|
7
|
+
group: string;
|
|
7
8
|
source: DragSource;
|
|
8
9
|
pointerPosition: DragPoint;
|
|
9
10
|
sourceRect: DragRect;
|
|
10
11
|
};
|
|
11
12
|
export type DragUpdateEvent = {
|
|
12
13
|
draggableId: string;
|
|
14
|
+
group: string;
|
|
13
15
|
source: DragSource;
|
|
14
16
|
pointerPosition: DragPoint;
|
|
15
17
|
overlayRect: DragRect | null;
|
|
16
18
|
activeDropTargetId: string | null;
|
|
17
19
|
previousDropTargetId: string | null;
|
|
20
|
+
sortablePreview: SortablePreview;
|
|
18
21
|
};
|
|
19
22
|
export type DragEndEvent = {
|
|
20
23
|
draggableId: string;
|
|
24
|
+
group: string;
|
|
21
25
|
source: DragSource;
|
|
22
26
|
result: DragEndResult;
|
|
23
27
|
overlayRect: DragRect | null;
|
|
@@ -25,14 +29,25 @@ export type DragEndEvent = {
|
|
|
25
29
|
};
|
|
26
30
|
export type DropEvent = {
|
|
27
31
|
draggableId: string;
|
|
32
|
+
group: string;
|
|
28
33
|
source: DragSource;
|
|
29
34
|
dropTargetId: string;
|
|
30
35
|
sortablePlacement?: SortableDropPlacement;
|
|
31
36
|
};
|
|
32
37
|
export type ActiveDragResetEvent = {
|
|
33
38
|
draggableId: string;
|
|
39
|
+
group: string;
|
|
34
40
|
source: DragSource;
|
|
35
41
|
};
|
|
42
|
+
export type SortablePreview = {
|
|
43
|
+
status: "inactive";
|
|
44
|
+
} | {
|
|
45
|
+
status: "source";
|
|
46
|
+
placement: SortableDropPlacement;
|
|
47
|
+
} | {
|
|
48
|
+
status: "projected";
|
|
49
|
+
placement: SortableDropPlacement;
|
|
50
|
+
};
|
|
36
51
|
export type DragLifecycleHelpers = {
|
|
37
52
|
getDropTargetRect: (dropTargetId: string) => DragRect | null;
|
|
38
53
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DragSource } from "./lifecycle.js";
|
|
2
|
+
export type SortableCoordinatorStartInput = {
|
|
3
|
+
draggableId: string;
|
|
4
|
+
group: string;
|
|
5
|
+
source: DragSource;
|
|
6
|
+
pointerPosition: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
placementPosition: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
14
|
+
movementPosition: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type SortableCoordinatorUpdateInput = SortableCoordinatorStartInput & {
|
|
20
|
+
activeDropTargetId: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type SortableCoordinator = {
|
|
23
|
+
start: (input: SortableCoordinatorStartInput) => void;
|
|
24
|
+
update: (input: SortableCoordinatorUpdateInput) => void;
|
|
25
|
+
release: (input: {
|
|
26
|
+
draggableId: string;
|
|
27
|
+
group: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
};
|
|
30
|
+
export declare function linkSortableCoordinatorHost(publicRuntime: object, coordinatorHost: object): void;
|
|
31
|
+
export declare function setSortableCoordinator(runtime: object, coordinator: SortableCoordinator): void;
|
|
32
|
+
export declare function getSortableCoordinator(runtime: object): SortableCoordinator | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const coordinatorHosts = new WeakMap();
|
|
2
|
+
const coordinators = new WeakMap();
|
|
3
|
+
export function linkSortableCoordinatorHost(publicRuntime, coordinatorHost) {
|
|
4
|
+
coordinatorHosts.set(publicRuntime, coordinatorHost);
|
|
5
|
+
}
|
|
6
|
+
export function setSortableCoordinator(runtime, coordinator) {
|
|
7
|
+
coordinators.set(coordinatorHosts.get(runtime) ?? runtime, coordinator);
|
|
8
|
+
}
|
|
9
|
+
export function getSortableCoordinator(runtime) {
|
|
10
|
+
return coordinators.get(coordinatorHosts.get(runtime) ?? runtime) ?? null;
|
|
11
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type SortablePreviewPlacementDecision = {
|
|
|
23
23
|
placement: SortablePlacementSide;
|
|
24
24
|
movementDirection: SortableAxisMovementDirection;
|
|
25
25
|
};
|
|
26
|
-
export declare function snapshotSortableElement(registry: SortableRegistry, draggableId: string): void;
|
|
26
|
+
export declare function snapshotSortableElement(registry: SortableRegistry, draggableId: string, group: string): void;
|
|
27
27
|
export declare function isSortablePreviewTarget(input: {
|
|
28
28
|
activeDropTargetId: string | null;
|
|
29
29
|
}): boolean;
|
|
@@ -47,6 +47,7 @@ export declare function moveSortablePreview(input: {
|
|
|
47
47
|
registry: SortableRegistry;
|
|
48
48
|
runtime: DomSortableRuntime;
|
|
49
49
|
draggedDraggableId: string;
|
|
50
|
+
draggedGroup: string;
|
|
50
51
|
activeDropTargetId: string | null;
|
|
51
52
|
placementPosition: {
|
|
52
53
|
x: number;
|
|
@@ -80,7 +81,7 @@ export declare function isSortablePreviewAlreadyPlaced(input: {
|
|
|
80
81
|
placement: SortablePlacementSide;
|
|
81
82
|
}): boolean;
|
|
82
83
|
export declare function restoreSortableSnapshot(registry: SortableRegistry, draggableId: string): boolean;
|
|
83
|
-
export declare function clearSortableDraggedState(registry: SortableRegistry, draggableId: string): void;
|
|
84
|
+
export declare function clearSortableDraggedState(registry: SortableRegistry, draggableId: string, group: string): void;
|
|
84
85
|
export declare function getAxisPosition(pointerPosition: {
|
|
85
86
|
x: number;
|
|
86
87
|
y: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getRegisteredSortableElement, restoreSortableDraggedAttribute, } from "./sortable-registry.js";
|
|
1
|
+
import { getSortableRegistrationKey, getRegisteredSortableElement, restoreSortableDraggedAttribute, } from "./sortable-registry.js";
|
|
2
2
|
const neutralPlacementBoundaryRatio = 0.5;
|
|
3
|
-
export function snapshotSortableElement(registry, draggableId) {
|
|
4
|
-
const element = getRegisteredSortableElement(registry, draggableId);
|
|
3
|
+
export function snapshotSortableElement(registry, draggableId, group) {
|
|
4
|
+
const element = getRegisteredSortableElement(registry, draggableId, group);
|
|
5
5
|
if (!element?.parentElement) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -43,37 +43,37 @@ export function moveSortablePreview(input) {
|
|
|
43
43
|
if (input.activeDropTargetId === null) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
const draggedElement = getRegisteredSortableElement(input.registry, input.draggedDraggableId);
|
|
47
|
-
|
|
48
|
-
if (!draggedElement || !draggedGroup) {
|
|
46
|
+
const draggedElement = getRegisteredSortableElement(input.registry, input.draggedDraggableId, input.draggedGroup);
|
|
47
|
+
if (!draggedElement) {
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
50
|
const activeDropTargetId = input.activeDropTargetId === input.draggedDraggableId
|
|
52
51
|
? input.registry.activeDrag.previewPlacement?.activeDropTargetId
|
|
53
52
|
: input.activeDropTargetId;
|
|
54
|
-
if (!activeDropTargetId ||
|
|
55
|
-
activeDropTargetId === input.draggedDraggableId) {
|
|
53
|
+
if (!activeDropTargetId || activeDropTargetId === input.draggedDraggableId) {
|
|
56
54
|
refreshSortableDropTargetMeasurements({
|
|
57
55
|
registry: input.registry,
|
|
58
56
|
runtime: input.runtime,
|
|
59
|
-
group: draggedGroup,
|
|
57
|
+
group: input.draggedGroup,
|
|
60
58
|
dropTargetIds: getSortablePreviewMeasurementIds({
|
|
61
59
|
registry: input.registry,
|
|
60
|
+
group: input.draggedGroup,
|
|
62
61
|
draggedElement,
|
|
63
62
|
}),
|
|
64
63
|
});
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
67
|
-
const target = input.runtime.getDropTargetRegistration(activeDropTargetId, draggedGroup);
|
|
66
|
+
const target = input.runtime.getDropTargetRegistration(activeDropTargetId, input.draggedGroup);
|
|
68
67
|
if (!target) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
70
|
const measurementIds = getSortablePreviewMeasurementIds({
|
|
72
71
|
registry: input.registry,
|
|
72
|
+
group: input.draggedGroup,
|
|
73
73
|
draggedElement,
|
|
74
74
|
targetElement: target.element,
|
|
75
75
|
});
|
|
76
|
-
const draggedRegistration = input.runtime.getDropTargetRegistration(input.draggedDraggableId, draggedGroup);
|
|
76
|
+
const draggedRegistration = input.runtime.getDropTargetRegistration(input.draggedDraggableId, input.draggedGroup);
|
|
77
77
|
addRegistrationContainerId(measurementIds, draggedRegistration);
|
|
78
78
|
addRegistrationContainerId(measurementIds, target);
|
|
79
79
|
if (target.capabilities.container) {
|
|
@@ -102,16 +102,16 @@ export function moveSortablePreview(input) {
|
|
|
102
102
|
}),
|
|
103
103
|
});
|
|
104
104
|
if (sourceListElement && sourceListElement !== target.element) {
|
|
105
|
-
addSortableMeasurementIdsInContainer(measurementIds, input.registry, sourceListElement);
|
|
106
|
-
addSortableMeasurementIdsInContainer(measurementIds, input.registry, target.element);
|
|
105
|
+
addSortableMeasurementIdsInContainer(measurementIds, input.registry, sourceListElement, input.draggedGroup);
|
|
106
|
+
addSortableMeasurementIdsInContainer(measurementIds, input.registry, target.element, input.draggedGroup);
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, draggedElement);
|
|
109
|
+
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, draggedElement, input.draggedGroup);
|
|
110
110
|
}
|
|
111
111
|
refreshSortableDropTargetMeasurements({
|
|
112
112
|
registry: input.registry,
|
|
113
113
|
runtime: input.runtime,
|
|
114
|
-
group: draggedGroup,
|
|
114
|
+
group: input.draggedGroup,
|
|
115
115
|
dropTargetIds: measurementIds,
|
|
116
116
|
});
|
|
117
117
|
return;
|
|
@@ -132,7 +132,7 @@ export function moveSortablePreview(input) {
|
|
|
132
132
|
if (!target.capabilities.sortable) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
const targetDraggableId = getSortableDraggableId(input.registry, targetElement);
|
|
135
|
+
const targetDraggableId = getSortableDraggableId(input.registry, targetElement, input.draggedGroup);
|
|
136
136
|
if (targetDraggableId !== activeDropTargetId) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -169,17 +169,17 @@ export function moveSortablePreview(input) {
|
|
|
169
169
|
targetElement.before(draggedElement);
|
|
170
170
|
}
|
|
171
171
|
if (sourceListElement && sourceListElement !== listElement) {
|
|
172
|
-
addSortableMeasurementIdsInContainer(measurementIds, input.registry, sourceListElement);
|
|
173
|
-
addSortableMeasurementIdsInContainer(measurementIds, input.registry, listElement);
|
|
172
|
+
addSortableMeasurementIdsInContainer(measurementIds, input.registry, sourceListElement, input.draggedGroup);
|
|
173
|
+
addSortableMeasurementIdsInContainer(measurementIds, input.registry, listElement, input.draggedGroup);
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
|
-
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, draggedElement);
|
|
177
|
-
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, targetElement);
|
|
176
|
+
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, draggedElement, input.draggedGroup);
|
|
177
|
+
addSortableMeasurementIdsAroundElement(measurementIds, input.registry, targetElement, input.draggedGroup);
|
|
178
178
|
}
|
|
179
179
|
refreshSortableDropTargetMeasurements({
|
|
180
180
|
registry: input.registry,
|
|
181
181
|
runtime: input.runtime,
|
|
182
|
-
group: draggedGroup,
|
|
182
|
+
group: input.draggedGroup,
|
|
183
183
|
dropTargetIds: measurementIds,
|
|
184
184
|
});
|
|
185
185
|
}
|
|
@@ -296,7 +296,9 @@ function getOptimisticPlacement(input) {
|
|
|
296
296
|
}
|
|
297
297
|
function getPlacementSideFromTargetMidpoint(input) {
|
|
298
298
|
const targetStart = input.axis === "horizontal" ? input.targetRect.left : input.targetRect.top;
|
|
299
|
-
const targetSize = input.axis === "horizontal"
|
|
299
|
+
const targetSize = input.axis === "horizontal"
|
|
300
|
+
? input.targetRect.width
|
|
301
|
+
: input.targetRect.height;
|
|
300
302
|
const midpoint = targetStart + targetSize / 2;
|
|
301
303
|
return input.axisPosition < midpoint ? "before" : "after";
|
|
302
304
|
}
|
|
@@ -325,48 +327,50 @@ export function restoreSortableSnapshot(registry, draggableId) {
|
|
|
325
327
|
snapshot.parent.insertBefore(snapshot.element, getSnapshotRestoreReferenceNode(snapshot));
|
|
326
328
|
return true;
|
|
327
329
|
}
|
|
328
|
-
export function clearSortableDraggedState(registry, draggableId) {
|
|
329
|
-
const element = getRegisteredSortableElement(registry, draggableId) ??
|
|
330
|
+
export function clearSortableDraggedState(registry, draggableId, group) {
|
|
331
|
+
const element = getRegisteredSortableElement(registry, draggableId, group) ??
|
|
330
332
|
registry.activeDrag.snapshots.get(draggableId)?.element;
|
|
331
333
|
if (element) {
|
|
332
334
|
restoreSortableDraggedAttribute({
|
|
333
335
|
registry,
|
|
334
336
|
draggableId,
|
|
337
|
+
group,
|
|
335
338
|
element,
|
|
336
339
|
});
|
|
337
340
|
}
|
|
338
341
|
}
|
|
339
|
-
function getSortableDraggableId(registry, element) {
|
|
340
|
-
const
|
|
341
|
-
return
|
|
342
|
-
registry.registration.sortableElementRefs
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
function getSortableDraggableId(registry, element, group) {
|
|
343
|
+
const identity = registry.registration.sortableElementIds.get(element);
|
|
344
|
+
return identity?.group === group &&
|
|
345
|
+
registry.registration.sortableElementRefs
|
|
346
|
+
.get(getSortableRegistrationKey(identity.draggableId, group))
|
|
347
|
+
?.deref() === element
|
|
348
|
+
? identity.draggableId
|
|
345
349
|
: null;
|
|
346
350
|
}
|
|
347
351
|
function getSortablePreviewMeasurementIds(input) {
|
|
348
352
|
const dropTargetIds = new Set();
|
|
349
|
-
addSortableMeasurementIdsAroundElement(dropTargetIds, input.registry, input.draggedElement);
|
|
353
|
+
addSortableMeasurementIdsAroundElement(dropTargetIds, input.registry, input.draggedElement, input.group);
|
|
350
354
|
if (input.targetElement) {
|
|
351
|
-
addSortableMeasurementIdsAroundElement(dropTargetIds, input.registry, input.targetElement);
|
|
355
|
+
addSortableMeasurementIdsAroundElement(dropTargetIds, input.registry, input.targetElement, input.group);
|
|
352
356
|
}
|
|
353
357
|
return dropTargetIds;
|
|
354
358
|
}
|
|
355
|
-
function addSortableMeasurementIdsAroundElement(dropTargetIds, registry, element) {
|
|
356
|
-
addSortableMeasurementId(dropTargetIds, registry, element);
|
|
357
|
-
addSortableMeasurementId(dropTargetIds, registry, element.previousElementSibling);
|
|
358
|
-
addSortableMeasurementId(dropTargetIds, registry, element.nextElementSibling);
|
|
359
|
+
function addSortableMeasurementIdsAroundElement(dropTargetIds, registry, element, group) {
|
|
360
|
+
addSortableMeasurementId(dropTargetIds, registry, element, group);
|
|
361
|
+
addSortableMeasurementId(dropTargetIds, registry, element.previousElementSibling, group);
|
|
362
|
+
addSortableMeasurementId(dropTargetIds, registry, element.nextElementSibling, group);
|
|
359
363
|
}
|
|
360
|
-
function addSortableMeasurementIdsInContainer(dropTargetIds, registry, containerElement) {
|
|
364
|
+
function addSortableMeasurementIdsInContainer(dropTargetIds, registry, containerElement, group) {
|
|
361
365
|
for (let index = 0; index < containerElement.children.length; index += 1) {
|
|
362
|
-
addSortableMeasurementId(dropTargetIds, registry, containerElement.children.item(index));
|
|
366
|
+
addSortableMeasurementId(dropTargetIds, registry, containerElement.children.item(index), group);
|
|
363
367
|
}
|
|
364
368
|
}
|
|
365
|
-
function addSortableMeasurementId(dropTargetIds, registry, element) {
|
|
369
|
+
function addSortableMeasurementId(dropTargetIds, registry, element, group) {
|
|
366
370
|
if (!(element instanceof HTMLElement)) {
|
|
367
371
|
return;
|
|
368
372
|
}
|
|
369
|
-
const draggableId = getSortableDraggableId(registry, element);
|
|
373
|
+
const draggableId = getSortableDraggableId(registry, element, group);
|
|
370
374
|
if (draggableId) {
|
|
371
375
|
dropTargetIds.add(draggableId);
|
|
372
376
|
}
|
|
@@ -389,8 +393,7 @@ function refreshSortableDropTargetMeasurements(input) {
|
|
|
389
393
|
input.runtime.registerDropTarget(registration.id, registration.element, registration.group, {
|
|
390
394
|
containerId: registration.containerId,
|
|
391
395
|
sortable: registration.capabilities.sortable,
|
|
392
|
-
sortableAxis: input.registry.registration.sortableOptions.get(registration.id)
|
|
393
|
-
?.axis ?? "vertical",
|
|
396
|
+
sortableAxis: input.registry.registration.sortableOptions.get(getSortableRegistrationKey(registration.id, input.group))?.axis ?? "vertical",
|
|
394
397
|
});
|
|
395
398
|
}
|
|
396
399
|
}
|
|
@@ -435,7 +438,9 @@ export function getAxisMovementDirection(previousAxisPosition, currentAxisPositi
|
|
|
435
438
|
}
|
|
436
439
|
export function getPlacementBoundary(input) {
|
|
437
440
|
const targetStart = input.axis === "horizontal" ? input.targetRect.left : input.targetRect.top;
|
|
438
|
-
const targetSize = input.axis === "horizontal"
|
|
441
|
+
const targetSize = input.axis === "horizontal"
|
|
442
|
+
? input.targetRect.width
|
|
443
|
+
: input.targetRect.height;
|
|
439
444
|
const boundaryRatio = input.direction === "forward"
|
|
440
445
|
? input.startRatio
|
|
441
446
|
: input.direction === "backward"
|