@acorex/cdk 22.3.6 → 22.3.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.
@@ -1,15 +1,24 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, signal, Directive, NgZone, Renderer2, ChangeDetectorRef, PLATFORM_ID, input, output, contentChildren, linkedSignal, DOCUMENT, ViewContainerRef, contentChild, computed, effect, RendererStyleFlags2, NgModule } from '@angular/core';
2
+ import { InjectionToken, inject, ElementRef, signal, DestroyRef, Directive, NgZone, Renderer2, ChangeDetectorRef, PLATFORM_ID, input, output, contentChildren, linkedSignal, DOCUMENT, ViewContainerRef, computed, effect, RendererStyleFlags2, NgModule } from '@angular/core';
3
3
  import { isPlatformBrowser } from '@angular/common';
4
4
  import { clamp } from 'lodash-es';
5
5
  import { NXComponent } from '@acorex/cdk/common';
6
6
  import { AXHtmlUtil } from '@acorex/core/utils';
7
7
 
8
+ /**
9
+ * Parent drag instance that nested `axDragHandle` directives register with.
10
+ * Provided by `AXDragDirective` so handles work inside dynamically created content.
11
+ */
12
+ const AX_DRAG_PARENT = new InjectionToken('AX_DRAG_PARENT');
13
+
8
14
  class AXDragHandleDirective {
9
15
  constructor() {
10
- this.el = inject(ElementRef);
16
+ this.el = inject((ElementRef));
17
+ this.parent = inject(AX_DRAG_PARENT, { optional: true });
11
18
  this.element = signal(this.el.nativeElement, /* @ts-ignore */
12
19
  ...(ngDevMode ? [{ debugName: "element" }] : /* istanbul ignore next */ []));
20
+ this.parent?.registerHandle(this);
21
+ inject(DestroyRef).onDestroy(() => this.parent?.unregisterHandle(this));
13
22
  }
14
23
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXDragHandleDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
15
24
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.6", type: AXDragHandleDirective, isStandalone: true, selector: "[axDragHandle]", ngImport: i0 }); }
@@ -19,7 +28,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
19
28
  args: [{
20
29
  selector: '[axDragHandle]',
21
30
  }]
22
- }] });
31
+ }], ctorParameters: () => [] });
23
32
 
24
33
  /**
25
34
  * @Directive axDropList
@@ -483,8 +492,8 @@ class AXDragDirective {
483
492
  this.platformId = inject(PLATFORM_ID);
484
493
  this.viewContainerRef = inject(ViewContainerRef);
485
494
  this.el = inject(ElementRef);
486
- this.handleDirective = contentChild(AXDragHandleDirective, /* @ts-ignore */
487
- ...(ngDevMode ? [{ debugName: "handleDirective" }] : /* istanbul ignore next */ []));
495
+ this.registeredHandleElements = signal([], /* @ts-ignore */
496
+ ...(ngDevMode ? [{ debugName: "registeredHandleElements" }] : /* istanbul ignore next */ []));
488
497
  this.axDrag = input(true, { ...(ngDevMode ? { debugName: "axDrag" } : /* istanbul ignore next */ {}), transform: (value) => value === '' || value === true });
489
498
  this.dragData = input(/* @ts-ignore */
490
499
  ...(ngDevMode ? [undefined, { debugName: "dragData" }] : /* istanbul ignore next */ []));
@@ -591,59 +600,97 @@ class AXDragDirective {
591
600
  return this.boundaryElement()?.getBoundingClientRect();
592
601
  }, /* @ts-ignore */
593
602
  ...(ngDevMode ? [{ debugName: "boundaryRect" }] : /* istanbul ignore next */ []));
594
- this.handle = computed(() => this.handleDirective()?.element() ?? this.element(), /* @ts-ignore */
603
+ this.handleElements = computed(() => {
604
+ const registered = this.registeredHandleElements().filter(Boolean);
605
+ return registered.length ? registered : [this.element()];
606
+ }, /* @ts-ignore */
607
+ ...(ngDevMode ? [{ debugName: "handleElements" }] : /* istanbul ignore next */ []));
608
+ this.handle = computed(() => this.activeHandleElement() ?? this.handleElements()[0] ?? this.element(), /* @ts-ignore */
595
609
  ...(ngDevMode ? [{ debugName: "handle" }] : /* istanbul ignore next */ []));
596
610
  this.boundHandleDblClick = this.handleDblClick.bind(this);
597
611
  this.boundHandlePointerUp = this.handlePointerUp.bind(this);
598
612
  this.boundHandlePointerDown = this.handlePointerDown.bind(this);
599
613
  this.boundHandlePointerMove = this.handlePointerMove.bind(this);
600
- this.listenersAttached = signal(null, /* @ts-ignore */
601
- ...(ngDevMode ? [{ debugName: "listenersAttached" }] : /* istanbul ignore next */ []));
614
+ this.attachedHandleElements = [];
615
+ this.styledHandleElements = [];
616
+ this.activeHandleElement = signal(null, /* @ts-ignore */
617
+ ...(ngDevMode ? [{ debugName: "activeHandleElement" }] : /* istanbul ignore next */ []));
602
618
  this.#dragDisabledEffect = effect(() => {
603
619
  const cursor = this.dragCursorOverride();
604
620
  const disabled = this.isDragDisabled();
605
- const handle = this.handle();
606
- if (disabled || cursor === 'none' || cursor === 'grab-on-drag') {
607
- if (!this.isMoving() && !this.holdDelayReady()) {
608
- this.renderer.removeStyle(handle, 'cursor');
621
+ const handles = this.handleElements();
622
+ const moving = this.isMoving();
623
+ const holdReady = this.holdDelayReady();
624
+ for (const previous of this.styledHandleElements) {
625
+ if (!handles.includes(previous)) {
626
+ this.renderer.removeStyle(previous, 'cursor');
627
+ this.renderer.removeStyle(previous, 'touch-action');
609
628
  }
610
- if (disabled) {
611
- this.renderer.removeStyle(handle, 'touch-action');
629
+ }
630
+ this.styledHandleElements = handles;
631
+ for (const handle of handles) {
632
+ if (disabled || cursor === 'none' || cursor === 'grab-on-drag') {
633
+ if (!moving && !holdReady) {
634
+ this.renderer.removeStyle(handle, 'cursor');
635
+ }
636
+ if (disabled) {
637
+ this.renderer.removeStyle(handle, 'touch-action');
638
+ }
639
+ else {
640
+ this.renderer.setStyle(handle, 'touch-action', this.dragTouchAction());
641
+ }
642
+ continue;
612
643
  }
613
- else {
614
- this.renderer.setStyle(handle, 'touch-action', this.dragTouchAction());
644
+ if (!moving && !holdReady) {
645
+ this.renderer.setStyle(handle, 'cursor', cursor);
615
646
  }
616
- return;
617
- }
618
- if (!this.isMoving() && !this.holdDelayReady()) {
619
- this.renderer.setStyle(handle, 'cursor', cursor);
647
+ this.renderer.setStyle(handle, 'touch-action', this.dragTouchAction());
620
648
  }
621
- this.renderer.setStyle(handle, 'touch-action', this.dragTouchAction());
622
649
  }, /* @ts-ignore */
623
650
  ...(ngDevMode ? [{ debugName: "#dragDisabledEffect" }] : /* istanbul ignore next */ []));
624
651
  this.#handleChangeEffect = effect(() => {
625
652
  if (!isPlatformBrowser(this.platformId))
626
653
  return;
627
- const currentHandle = this.handle();
628
- const previousHandle = this.listenersAttached();
629
- // Remove listeners from previous handle if it changed
630
- if (previousHandle && previousHandle !== currentHandle) {
631
- previousHandle.removeEventListener('dblclick', this.boundHandleDblClick);
632
- previousHandle.removeEventListener('pointerdown', this.boundHandlePointerDown);
633
- }
634
- // Attach listeners to new handle
635
- if (currentHandle && currentHandle !== previousHandle) {
636
- this.zone.runOutsideAngular(() => {
637
- currentHandle.addEventListener('dblclick', this.boundHandleDblClick);
638
- currentHandle.addEventListener('pointerdown', this.boundHandlePointerDown, { passive: false });
639
- });
640
- this.listenersAttached.set(currentHandle);
654
+ const currentHandles = this.handleElements();
655
+ const previousHandles = this.attachedHandleElements;
656
+ for (const previous of previousHandles) {
657
+ if (!currentHandles.includes(previous)) {
658
+ previous.removeEventListener('dblclick', this.boundHandleDblClick);
659
+ previous.removeEventListener('pointerdown', this.boundHandlePointerDown);
660
+ }
641
661
  }
662
+ this.zone.runOutsideAngular(() => {
663
+ for (const current of currentHandles) {
664
+ if (!previousHandles.includes(current)) {
665
+ current.addEventListener('dblclick', this.boundHandleDblClick);
666
+ current.addEventListener('pointerdown', this.boundHandlePointerDown, { passive: false });
667
+ }
668
+ }
669
+ });
670
+ this.attachedHandleElements = currentHandles;
642
671
  }, /* @ts-ignore */
643
672
  ...(ngDevMode ? [{ debugName: "#handleChangeEffect" }] : /* istanbul ignore next */ []));
644
673
  }
645
674
  #dragDisabledEffect;
646
675
  #handleChangeEffect;
676
+ registerHandle(handle) {
677
+ const element = this.resolveHandleElement(handle);
678
+ if (!element)
679
+ return;
680
+ this.registeredHandleElements.update((handles) => (handles.includes(element) ? handles : [...handles, element]));
681
+ }
682
+ unregisterHandle(handle) {
683
+ const element = this.resolveHandleElement(handle);
684
+ if (!element)
685
+ return;
686
+ this.registeredHandleElements.update((handles) => handles.filter((item) => item !== element));
687
+ if (this.activeHandleElement() === element) {
688
+ this.activeHandleElement.set(null);
689
+ }
690
+ }
691
+ resolveHandleElement(handle) {
692
+ return handle instanceof HTMLElement ? handle : handle.element();
693
+ }
647
694
  ngOnInit() {
648
695
  if (isPlatformBrowser(this.platformId)) {
649
696
  if (this._parentDropList) {
@@ -654,11 +701,11 @@ class AXDragDirective {
654
701
  }
655
702
  ngOnDestroy() {
656
703
  if (isPlatformBrowser(this.platformId)) {
657
- const handle = this.listenersAttached();
658
- if (handle) {
704
+ for (const handle of this.attachedHandleElements) {
659
705
  handle.removeEventListener('dblclick', this.boundHandleDblClick);
660
706
  handle.removeEventListener('pointerdown', this.boundHandlePointerDown);
661
707
  }
708
+ this.attachedHandleElements = [];
662
709
  this.removeDocumentListeners();
663
710
  if (this.createCloneElement()) {
664
711
  this.removeCloneElement();
@@ -736,14 +783,16 @@ class AXDragDirective {
736
783
  return;
737
784
  if (!this.axDrag() || this.isDragDisabled() || e.button !== 0 || this._parentDropList?.isSortingDisabled())
738
785
  return;
786
+ const handle = e.currentTarget instanceof HTMLElement ? e.currentTarget : this.handle();
787
+ this.activeHandleElement.set(handle);
739
788
  this.isDragging.set(true);
740
789
  this.movedAfterDelay.set(false);
741
790
  if (this.dragCursorOverride() === 'move') {
742
- this.renderer.setStyle(this.handle(), 'cursor', 'move');
791
+ this.renderer.setStyle(handle, 'cursor', 'move');
743
792
  }
744
793
  this.dragStartOffset.set({ x: e.clientX - this.currentAxis().x, y: e.clientY - this.currentAxis().y });
745
794
  this.pointerDownPosition.set({ x: e.clientX, y: e.clientY });
746
- this.renderer.setStyle(this.handle(), 'userSelect', 'none');
795
+ this.renderer.setStyle(handle, 'userSelect', 'none');
747
796
  this.activePointerId.set(e.pointerId);
748
797
  this.addDocumentListeners();
749
798
  this.dragStartTime.set(Date.now());
@@ -817,6 +866,7 @@ class AXDragDirective {
817
866
  this.renderer.removeStyle(this.handle(), 'userSelect');
818
867
  this.resetHandleCursorAfterDrag();
819
868
  this.clearActiveDragCursor();
869
+ this.activeHandleElement.set(null);
820
870
  }
821
871
  resetHandleCursorAfterDrag() {
822
872
  const cursorMode = this.dragCursorOverride();
@@ -874,6 +924,7 @@ class AXDragDirective {
874
924
  this.removeDocumentListeners();
875
925
  this._currentDropList.set(null);
876
926
  this.renderer.removeStyle(this.handle(), 'userSelect');
927
+ this.activeHandleElement.set(null);
877
928
  return;
878
929
  }
879
930
  this.renderer.removeStyle(this.element(), 'z-index');
@@ -905,6 +956,7 @@ class AXDragDirective {
905
956
  this.removeDocumentListeners();
906
957
  this._currentDropList.set(null);
907
958
  this.renderer.removeStyle(this.handle(), 'userSelect');
959
+ this.activeHandleElement.set(null);
908
960
  if (this.createCloneElement()) {
909
961
  const listUnderPointer = this.getDropListFromPoint(e.clientX, e.clientY);
910
962
  this.removeCloneElementWithAnimation(x || 0, y || 0, listUnderPointer);
@@ -1357,14 +1409,15 @@ class AXDragDirective {
1357
1409
  });
1358
1410
  }
1359
1411
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXDragDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1360
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.1.6", type: AXDragDirective, isStandalone: true, selector: "[axDrag]", inputs: { axDrag: { classPropertyName: "axDrag", publicName: "axDrag", isSignal: true, isRequired: false, transformFunction: null }, dragData: { classPropertyName: "dragData", publicName: "dragData", isSignal: true, isRequired: false, transformFunction: null }, dragDisabled: { classPropertyName: "dragDisabled", publicName: "dragDisabled", isSignal: true, isRequired: false, transformFunction: null }, dragTransition: { classPropertyName: "dragTransition", publicName: "dragTransition", isSignal: true, isRequired: false, transformFunction: null }, dragElementClone: { classPropertyName: "dragElementClone", publicName: "dragElementClone", isSignal: true, isRequired: false, transformFunction: null }, dropZoneGroup: { classPropertyName: "dropZoneGroup", publicName: "dropZoneGroup", isSignal: true, isRequired: false, transformFunction: null }, dragStartDelay: { classPropertyName: "dragStartDelay", publicName: "dragStartDelay", isSignal: true, isRequired: false, transformFunction: null }, dragResetOnDblClick: { classPropertyName: "dragResetOnDblClick", publicName: "dragResetOnDblClick", isSignal: true, isRequired: false, transformFunction: null }, dragLockAxis: { classPropertyName: "dragLockAxis", publicName: "dragLockAxis", isSignal: true, isRequired: false, transformFunction: null }, dragClonedTemplate: { classPropertyName: "dragClonedTemplate", publicName: "dragClonedTemplate", isSignal: true, isRequired: false, transformFunction: null }, dragCursor: { classPropertyName: "dragCursor", publicName: "dragCursor", isSignal: true, isRequired: false, transformFunction: null }, dragBoundary: { classPropertyName: "dragBoundary", publicName: "dragBoundary", isSignal: true, isRequired: false, transformFunction: null }, dragTransitionDuration: { classPropertyName: "dragTransitionDuration", publicName: "dragTransitionDuration", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dragPositionChanged: "dragPositionChanged" }, queries: [{ propertyName: "handleDirective", first: true, predicate: AXDragHandleDirective, descendants: true, isSignal: true }], ngImport: i0 }); }
1412
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.6", type: AXDragDirective, isStandalone: true, selector: "[axDrag]", inputs: { axDrag: { classPropertyName: "axDrag", publicName: "axDrag", isSignal: true, isRequired: false, transformFunction: null }, dragData: { classPropertyName: "dragData", publicName: "dragData", isSignal: true, isRequired: false, transformFunction: null }, dragDisabled: { classPropertyName: "dragDisabled", publicName: "dragDisabled", isSignal: true, isRequired: false, transformFunction: null }, dragTransition: { classPropertyName: "dragTransition", publicName: "dragTransition", isSignal: true, isRequired: false, transformFunction: null }, dragElementClone: { classPropertyName: "dragElementClone", publicName: "dragElementClone", isSignal: true, isRequired: false, transformFunction: null }, dropZoneGroup: { classPropertyName: "dropZoneGroup", publicName: "dropZoneGroup", isSignal: true, isRequired: false, transformFunction: null }, dragStartDelay: { classPropertyName: "dragStartDelay", publicName: "dragStartDelay", isSignal: true, isRequired: false, transformFunction: null }, dragResetOnDblClick: { classPropertyName: "dragResetOnDblClick", publicName: "dragResetOnDblClick", isSignal: true, isRequired: false, transformFunction: null }, dragLockAxis: { classPropertyName: "dragLockAxis", publicName: "dragLockAxis", isSignal: true, isRequired: false, transformFunction: null }, dragClonedTemplate: { classPropertyName: "dragClonedTemplate", publicName: "dragClonedTemplate", isSignal: true, isRequired: false, transformFunction: null }, dragCursor: { classPropertyName: "dragCursor", publicName: "dragCursor", isSignal: true, isRequired: false, transformFunction: null }, dragBoundary: { classPropertyName: "dragBoundary", publicName: "dragBoundary", isSignal: true, isRequired: false, transformFunction: null }, dragTransitionDuration: { classPropertyName: "dragTransitionDuration", publicName: "dragTransitionDuration", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dragPositionChanged: "dragPositionChanged" }, providers: [{ provide: AX_DRAG_PARENT, useExisting: AXDragDirective }], ngImport: i0 }); }
1361
1413
  }
1362
1414
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXDragDirective, decorators: [{
1363
1415
  type: Directive,
1364
1416
  args: [{
1365
1417
  selector: '[axDrag]',
1418
+ providers: [{ provide: AX_DRAG_PARENT, useExisting: AXDragDirective }],
1366
1419
  }]
1367
- }], propDecorators: { handleDirective: [{ type: i0.ContentChild, args: [i0.forwardRef(() => AXDragHandleDirective), { isSignal: true }] }], axDrag: [{ type: i0.Input, args: [{ isSignal: true, alias: "axDrag", required: false }] }], dragData: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragData", required: false }] }], dragDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragDisabled", required: false }] }], dragTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragTransition", required: false }] }], dragElementClone: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragElementClone", required: false }] }], dropZoneGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropZoneGroup", required: false }] }], dragStartDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragStartDelay", required: false }] }], dragResetOnDblClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragResetOnDblClick", required: false }] }], dragLockAxis: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragLockAxis", required: false }] }], dragClonedTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragClonedTemplate", required: false }] }], dragCursor: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragCursor", required: false }] }], dragBoundary: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragBoundary", required: false }] }], dragTransitionDuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragTransitionDuration", required: false }] }], dragPositionChanged: [{ type: i0.Output, args: ["dragPositionChanged"] }] } });
1420
+ }], propDecorators: { axDrag: [{ type: i0.Input, args: [{ isSignal: true, alias: "axDrag", required: false }] }], dragData: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragData", required: false }] }], dragDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragDisabled", required: false }] }], dragTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragTransition", required: false }] }], dragElementClone: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragElementClone", required: false }] }], dropZoneGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropZoneGroup", required: false }] }], dragStartDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragStartDelay", required: false }] }], dragResetOnDblClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragResetOnDblClick", required: false }] }], dragLockAxis: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragLockAxis", required: false }] }], dragClonedTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragClonedTemplate", required: false }] }], dragCursor: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragCursor", required: false }] }], dragBoundary: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragBoundary", required: false }] }], dragTransitionDuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragTransitionDuration", required: false }] }], dragPositionChanged: [{ type: i0.Output, args: ["dragPositionChanged"] }] } });
1368
1421
 
1369
1422
  class AXDropZoneDirective extends NXComponent {
1370
1423
  constructor() {
@@ -1445,5 +1498,5 @@ function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex)
1445
1498
  * Generated bundle index. Do not edit.
1446
1499
  */
1447
1500
 
1448
- export { AXDragDirective, AXDragDropModule, AXDragHandleDirective, AXDropListDirective, AXDropZoneDirective, moveItemInArray, transferArrayItem };
1501
+ export { AXDragDirective, AXDragDropModule, AXDragHandleDirective, AXDropListDirective, AXDropZoneDirective, AX_DRAG_PARENT, moveItemInArray, transferArrayItem };
1449
1502
  //# sourceMappingURL=acorex-cdk-drag-drop.mjs.map