@acorex/cdk 20.1.7 → 20.1.8
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/drag-drop/index.d.ts
CHANGED
|
@@ -35,9 +35,12 @@ declare class AXDragDirective implements OnInit, OnDestroy {
|
|
|
35
35
|
transitionDuration: _angular_core.WritableSignal<number>;
|
|
36
36
|
readonly element: _angular_core.WritableSignal<HTMLElement>;
|
|
37
37
|
private isMoving;
|
|
38
|
+
private dragStartTime;
|
|
38
39
|
private isDragging;
|
|
39
40
|
private elementOpacity;
|
|
40
41
|
private isDelayStarted;
|
|
42
|
+
private movedAfterDelay;
|
|
43
|
+
private activePointerId;
|
|
41
44
|
private prevDropZone;
|
|
42
45
|
private dragStartOffset;
|
|
43
46
|
private clonePointerOffset;
|
|
@@ -58,11 +61,11 @@ declare class AXDragDirective implements OnInit, OnDestroy {
|
|
|
58
61
|
private setElementTransition;
|
|
59
62
|
private removeElementTransition;
|
|
60
63
|
private handlePointerDown;
|
|
64
|
+
private handleDblClick;
|
|
65
|
+
private handlePointerMove;
|
|
61
66
|
private startDrag;
|
|
62
67
|
private handlePointerUp;
|
|
63
68
|
private preventClicking;
|
|
64
|
-
private handleDblClick;
|
|
65
|
-
private handlePointerMove;
|
|
66
69
|
private handleDropListInteractions;
|
|
67
70
|
private canDropInList;
|
|
68
71
|
private dropZoneHoverHandler;
|
|
@@ -80,7 +80,7 @@ class AXDropListDirective extends NXComponent {
|
|
|
80
80
|
* @param dragItem The item that is being dragged.
|
|
81
81
|
*/
|
|
82
82
|
prepareSort(dragItem) {
|
|
83
|
-
if (this.sortingDisabled() || this._activeDragItem())
|
|
83
|
+
if (this.sortingDisabled() || this._activeDragItem() || dragItem.dragDisabled())
|
|
84
84
|
return;
|
|
85
85
|
this._activeDragItem.set(dragItem);
|
|
86
86
|
this.element.classList.add('ax-drop-list-sorting-active');
|
|
@@ -214,7 +214,11 @@ class AXDropListDirective extends NXComponent {
|
|
|
214
214
|
_calculatePlaceholderIndex(pointerPosition) {
|
|
215
215
|
const activeItem = this._activeDragItem();
|
|
216
216
|
const listRect = this._listInitialRect();
|
|
217
|
-
|
|
217
|
+
if (!activeItem || !listRect)
|
|
218
|
+
return -1;
|
|
219
|
+
const cachedItems = this._cachedItems();
|
|
220
|
+
const originalIndex = cachedItems.findIndex((d) => d.item === activeItem);
|
|
221
|
+
const siblings = cachedItems.filter((d) => d.item !== activeItem);
|
|
218
222
|
const scrollDelta = this._orientation() === 'vertical'
|
|
219
223
|
? this.element.getBoundingClientRect().top - listRect.top
|
|
220
224
|
: this.element.getBoundingClientRect().left - listRect.left;
|
|
@@ -232,9 +236,28 @@ class AXDropListDirective extends NXComponent {
|
|
|
232
236
|
if (newIndexInSiblings === -1) {
|
|
233
237
|
newIndexInSiblings = siblings.length;
|
|
234
238
|
}
|
|
235
|
-
const originalIndex = this._cachedItems().findIndex((d) => d.item === activeItem);
|
|
236
239
|
// Map the index from the 'siblings' array back to the original `_cachedItems` array.
|
|
237
|
-
|
|
240
|
+
const potentialPlaceholderIndex = originalIndex > -1 && newIndexInSiblings >= originalIndex ? newIndexInSiblings + 1 : newIndexInSiblings;
|
|
241
|
+
// A drag starting from outside the list doesn't have an original index.
|
|
242
|
+
if (originalIndex === -1) {
|
|
243
|
+
return potentialPlaceholderIndex;
|
|
244
|
+
}
|
|
245
|
+
// --- New logic: Prevent crossing disabled items ---
|
|
246
|
+
const start = Math.min(originalIndex, potentialPlaceholderIndex);
|
|
247
|
+
const end = Math.max(originalIndex, potentialPlaceholderIndex);
|
|
248
|
+
for (let i = start; i < end; i++) {
|
|
249
|
+
const itemData = cachedItems[i];
|
|
250
|
+
if (itemData.item !== activeItem && itemData.item.dragDisabled()) {
|
|
251
|
+
// We've hit a disabled "wall". Stop the placeholder at the boundary.
|
|
252
|
+
if (potentialPlaceholderIndex > originalIndex) {
|
|
253
|
+
return i; // Dragging down/right: stop *before* the wall.
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return i + 1; // Dragging up/left: stop *after* the wall.
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return potentialPlaceholderIndex;
|
|
238
261
|
}
|
|
239
262
|
/** Applies `transform` styles to all items to create the visual sorting effect. */
|
|
240
263
|
_applyVisualShifts() {
|
|
@@ -249,7 +272,7 @@ class AXDropListDirective extends NXComponent {
|
|
|
249
272
|
if (isIntraListDrag) {
|
|
250
273
|
draggedItemSize = getItemSpace(this._cachedItems()[originalIndex]);
|
|
251
274
|
}
|
|
252
|
-
else {
|
|
275
|
+
else if (activeItem) {
|
|
253
276
|
const rect = activeItem.elementRect();
|
|
254
277
|
if (rect) {
|
|
255
278
|
const style = window.getComputedStyle(activeItem.element());
|
|
@@ -260,6 +283,11 @@ class AXDropListDirective extends NXComponent {
|
|
|
260
283
|
}
|
|
261
284
|
}
|
|
262
285
|
this._cachedItems().forEach((data, index) => {
|
|
286
|
+
// --- New logic: Do not transform disabled items ---
|
|
287
|
+
if (data.item.dragDisabled()) {
|
|
288
|
+
this._renderer.removeStyle(data.element, 'transform');
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
263
291
|
const transform = this._calculateTransform(index, originalIndex, draggedItemSize, getItemSpace);
|
|
264
292
|
this._renderer.setStyle(data.element, 'transform', transform ? `${this._orientation() === 'vertical' ? 'translateY' : 'translateX'}(${transform}px)` : '');
|
|
265
293
|
});
|
|
@@ -378,9 +406,12 @@ class AXDragDirective {
|
|
|
378
406
|
this.transitionDuration = linkedSignal(() => this.dragTransitionDuration());
|
|
379
407
|
this.element = signal(this.el.nativeElement);
|
|
380
408
|
this.isMoving = signal(false);
|
|
409
|
+
this.dragStartTime = signal(0);
|
|
381
410
|
this.isDragging = signal(false);
|
|
382
411
|
this.elementOpacity = signal('1');
|
|
383
412
|
this.isDelayStarted = signal(false);
|
|
413
|
+
this.movedAfterDelay = signal(false);
|
|
414
|
+
this.activePointerId = signal(null);
|
|
384
415
|
this.prevDropZone = signal(null);
|
|
385
416
|
this.dragStartOffset = signal({ x: 0, y: 0 });
|
|
386
417
|
this.clonePointerOffset = signal({ x: 0, y: 0 });
|
|
@@ -467,9 +498,10 @@ class AXDragDirective {
|
|
|
467
498
|
handlePointerDown(e) {
|
|
468
499
|
if (!isPlatformBrowser(this.platformId))
|
|
469
500
|
return;
|
|
470
|
-
if (this.dragDisabled() || e.button !== 0)
|
|
501
|
+
if (this.dragDisabled() || e.button !== 0 || this._parentDropList?.sortingDisabled())
|
|
471
502
|
return;
|
|
472
503
|
this.isDragging.set(true);
|
|
504
|
+
this.movedAfterDelay.set(false);
|
|
473
505
|
if (this.dragCursor() === 'move') {
|
|
474
506
|
this.renderer.setStyle(this.handle(), 'cursor', 'move');
|
|
475
507
|
}
|
|
@@ -479,20 +511,50 @@ class AXDragDirective {
|
|
|
479
511
|
e.stopPropagation();
|
|
480
512
|
this.dragStartOffset.set({ x: e.clientX - this.currentAxis().x, y: e.clientY - this.currentAxis().y });
|
|
481
513
|
this.renderer.setStyle(this.handle(), 'userSelect', 'none');
|
|
482
|
-
this.
|
|
514
|
+
this.activePointerId.set(e.pointerId);
|
|
483
515
|
this.addDocumentListeners();
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
516
|
+
this.dragStartTime.set(Date.now());
|
|
517
|
+
}
|
|
518
|
+
handleDblClick() {
|
|
519
|
+
if (!this.dragResetOnDblClick() || this.dragDisabled())
|
|
520
|
+
return;
|
|
521
|
+
this.setPosition(0, 0);
|
|
522
|
+
}
|
|
523
|
+
handlePointerMove(e) {
|
|
524
|
+
if (this.movedAfterDelay() ||
|
|
525
|
+
!this.isDragging() ||
|
|
526
|
+
this.isDelayStarted() ||
|
|
527
|
+
!isPlatformBrowser(this.platformId) ||
|
|
528
|
+
e.pointerId !== this.activePointerId()) {
|
|
529
|
+
return;
|
|
492
530
|
}
|
|
493
|
-
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
if (!this.isMoving()) {
|
|
533
|
+
const delay = this.dragStartDelay() ?? 0;
|
|
534
|
+
if (Date.now() - this.dragStartTime() < delay) {
|
|
535
|
+
this.movedAfterDelay.set(true);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
this.isMoving.set(true);
|
|
539
|
+
this.handle().setPointerCapture(e.pointerId);
|
|
494
540
|
this.startDrag(e);
|
|
495
541
|
}
|
|
542
|
+
if (this.createCloneElement()) {
|
|
543
|
+
const newCloneX = e.clientX - this.clonePointerOffset().x;
|
|
544
|
+
const newCloneY = e.clientY - this.clonePointerOffset().y;
|
|
545
|
+
this.setClonePosition(newCloneX, newCloneY);
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
const newX = e.clientX - this.dragStartOffset().x;
|
|
549
|
+
const newY = e.clientY - this.dragStartOffset().y;
|
|
550
|
+
this.setPosition(newX, newY);
|
|
551
|
+
}
|
|
552
|
+
if (this._parentDropList) {
|
|
553
|
+
this.handleDropListInteractions(e);
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
this.dropZoneHoverHandler(e);
|
|
557
|
+
}
|
|
496
558
|
}
|
|
497
559
|
startDrag(e) {
|
|
498
560
|
if (this._parentDropList) {
|
|
@@ -512,24 +574,29 @@ class AXDragDirective {
|
|
|
512
574
|
}
|
|
513
575
|
}
|
|
514
576
|
handlePointerUp(e) {
|
|
515
|
-
|
|
516
|
-
let x = 0;
|
|
517
|
-
let y = 0;
|
|
518
|
-
if (transform) {
|
|
519
|
-
x = Number(transform.split('translateX(')[1]?.split('px)')[0]);
|
|
520
|
-
y = Number(transform.split('translateY(')[1]?.split('px)')[0]);
|
|
521
|
-
}
|
|
522
|
-
if (!isPlatformBrowser(this.platformId))
|
|
523
|
-
return;
|
|
524
|
-
if (!this.isDragging())
|
|
577
|
+
if (e.pointerId !== this.activePointerId() || !isPlatformBrowser(this.platformId) || !this.isDragging()) {
|
|
525
578
|
return;
|
|
579
|
+
}
|
|
526
580
|
if (this.dragCursor() === 'grab') {
|
|
527
581
|
this.renderer.setStyle(this.handle(), 'cursor', 'grab');
|
|
528
582
|
}
|
|
529
583
|
const wasMoving = this.isMoving();
|
|
584
|
+
this.isMoving.set(false);
|
|
530
585
|
this.isDragging.set(false);
|
|
531
|
-
if (wasMoving) {
|
|
532
|
-
this.
|
|
586
|
+
if (!wasMoving) {
|
|
587
|
+
this.activePointerId.set(null);
|
|
588
|
+
this.removeDocumentListeners();
|
|
589
|
+
this._currentDropList.set(null);
|
|
590
|
+
this.renderer.removeStyle(this.handle(), 'userSelect');
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this.preventClicking();
|
|
594
|
+
const transform = this.element().style.transform;
|
|
595
|
+
let x = 0;
|
|
596
|
+
let y = 0;
|
|
597
|
+
if (transform) {
|
|
598
|
+
x = Number(transform.split('translateX(')[1]?.split('px)')[0]);
|
|
599
|
+
y = Number(transform.split('translateY(')[1]?.split('px)')[0]);
|
|
533
600
|
}
|
|
534
601
|
const droppedIntoList = this._currentDropList();
|
|
535
602
|
if (droppedIntoList && this._parentDropList) {
|
|
@@ -541,13 +608,10 @@ class AXDragDirective {
|
|
|
541
608
|
else {
|
|
542
609
|
this.dropZoneDropHandler(e);
|
|
543
610
|
}
|
|
611
|
+
this.activePointerId.set(null);
|
|
612
|
+
this.removeDocumentListeners();
|
|
544
613
|
this._currentDropList.set(null);
|
|
545
|
-
this.isMoving.set(false);
|
|
546
614
|
this.renderer.removeStyle(this.handle(), 'userSelect');
|
|
547
|
-
if (this.handle().hasPointerCapture(e.pointerId)) {
|
|
548
|
-
this.handle().releasePointerCapture(e.pointerId);
|
|
549
|
-
}
|
|
550
|
-
this.removeDocumentListeners();
|
|
551
615
|
if (this.createCloneElement()) {
|
|
552
616
|
const listUnderPointer = this.getDropListFromPoint(e.clientX, e.clientY);
|
|
553
617
|
this.removeCloneElementWithAnimation(x || 0, y || 0, listUnderPointer);
|
|
@@ -563,35 +627,6 @@ class AXDragDirective {
|
|
|
563
627
|
};
|
|
564
628
|
this.document.addEventListener('click', blockClick, { capture: true, once: true });
|
|
565
629
|
}
|
|
566
|
-
handleDblClick() {
|
|
567
|
-
if (!this.dragResetOnDblClick() || this.dragDisabled())
|
|
568
|
-
return;
|
|
569
|
-
this.setPosition(0, 0);
|
|
570
|
-
}
|
|
571
|
-
handlePointerMove(e) {
|
|
572
|
-
if (!isPlatformBrowser(this.platformId) || !this.isDragging() || this.isDelayStarted())
|
|
573
|
-
return;
|
|
574
|
-
e.preventDefault();
|
|
575
|
-
if (!this.isMoving()) {
|
|
576
|
-
this.isMoving.set(true);
|
|
577
|
-
}
|
|
578
|
-
if (this.createCloneElement()) {
|
|
579
|
-
const newCloneX = e.clientX - this.clonePointerOffset().x;
|
|
580
|
-
const newCloneY = e.clientY - this.clonePointerOffset().y;
|
|
581
|
-
this.setClonePosition(newCloneX, newCloneY);
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
const newX = e.clientX - this.dragStartOffset().x;
|
|
585
|
-
const newY = e.clientY - this.dragStartOffset().y;
|
|
586
|
-
this.setPosition(newX, newY);
|
|
587
|
-
}
|
|
588
|
-
if (this._parentDropList) {
|
|
589
|
-
this.handleDropListInteractions(e);
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
this.dropZoneHoverHandler(e);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
630
|
handleDropListInteractions(e) {
|
|
596
631
|
const listUnderPointer = this.getDropListFromPoint(e.clientX, e.clientY);
|
|
597
632
|
const previousList = this._currentDropList();
|