@acorex/cdk 22.1.8 → 22.2.0

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.
@@ -3,6 +3,7 @@ import { inject, ElementRef, signal, Directive, NgZone, Renderer2, ChangeDetecto
3
3
  import { isPlatformBrowser } from '@angular/common';
4
4
  import { clamp } from 'lodash-es';
5
5
  import { NXComponent } from '@acorex/cdk/common';
6
+ import { AXHtmlUtil } from '@acorex/core/utils';
6
7
 
7
8
  class AXDragHandleDirective {
8
9
  constructor() {
@@ -52,6 +53,8 @@ class AXDropListDirective extends NXComponent {
52
53
  ...(ngDevMode ? [{ debugName: "dropListOrientation" }] : /* istanbul ignore next */ []));
53
54
  /** Emits when an item is dropped into the list. */
54
55
  this.dropListDropped = output();
56
+ /** Emits when the sort preview transforms change during an active drag. */
57
+ this.sortPreviewChanged = output();
55
58
  /** The `axDrag` directives that are direct children of this list. */
56
59
  this._draggableItems = contentChildren(AXDragDirective, { ...(ngDevMode ? { debugName: "_draggableItems" } : /* istanbul ignore next */ {}), descendants: false });
57
60
  // --- Internal State Management ---
@@ -72,6 +75,9 @@ class AXDropListDirective extends NXComponent {
72
75
  /** The detected `gap` of the list for the current orientation. */
73
76
  this._listGap = signal(0, /* @ts-ignore */
74
77
  ...(ngDevMode ? [{ debugName: "_listGap" }] : /* istanbul ignore next */ []));
78
+ /** Whether the list is in RTL direction (cached at drag start). */
79
+ this._isRtl = signal(false, /* @ts-ignore */
80
+ ...(ngDevMode ? [{ debugName: "_isRtl" }] : /* istanbul ignore next */ []));
75
81
  /** Internal orientation state; can be overridden programmatically by host components. */
76
82
  this.orientation = linkedSignal(() => this.dropListOrientation(), /* @ts-ignore */
77
83
  ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
@@ -101,6 +107,10 @@ class AXDropListDirective extends NXComponent {
101
107
  isDragActiveForThisList(dragItem) {
102
108
  return this._activeDragItem() === dragItem;
103
109
  }
110
+ /** Whether the list is horizontal and in RTL direction. */
111
+ isHorizontalRtl() {
112
+ return this.orientation() === 'horizontal' && this._isRtl();
113
+ }
104
114
  /**
105
115
  * Prepares the list for sorting when a drag operation starts from within this list.
106
116
  * @param dragItem The item that is being dragged.
@@ -201,6 +211,7 @@ class AXDropListDirective extends NXComponent {
201
211
  /** Caches the geometry of the list and its items at the start of a drag. */
202
212
  _cacheGeometry() {
203
213
  this._listInitialRect.set(this.element.getBoundingClientRect());
214
+ this._isRtl.set(AXHtmlUtil.isRtl(this.element));
204
215
  this._detectAndCacheListGap();
205
216
  const items = [...this._draggableItems()]
206
217
  .sort((a, b) => a.element().compareDocumentPosition(b.element()) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1)
@@ -261,7 +272,10 @@ class AXDropListDirective extends NXComponent {
261
272
  const itemMidPoint = (this.orientation() === 'vertical' ? sibling.initialRect.top : sibling.initialRect.left) +
262
273
  scrollDelta +
263
274
  (this.orientation() === 'vertical' ? sibling.height : sibling.width) / 2;
264
- if (pointerPosition < itemMidPoint) {
275
+ const isBeforeSibling = this.isHorizontalRtl()
276
+ ? pointerPosition > itemMidPoint
277
+ : pointerPosition < itemMidPoint;
278
+ if (isBeforeSibling) {
265
279
  newIndexInSiblings = i;
266
280
  break;
267
281
  }
@@ -311,15 +325,20 @@ class AXDropListDirective extends NXComponent {
311
325
  ? itemData.height + itemData.margins.top + itemData.margins.bottom
312
326
  : itemData.width + itemData.margins.left + itemData.margins.right;
313
327
  const draggedItemSize = isIntraListDrag ? getItemSpace(this._cachedItems()[originalIndex]) : 0;
328
+ const axisSign = this.isHorizontalRtl() ? -1 : 1;
314
329
  this._cachedItems().forEach((data, index) => {
315
330
  if (data.item.isDragDisabled()) {
316
331
  this._renderer.removeStyle(data.element, 'transform');
317
332
  return;
318
333
  }
319
334
  const transform = this._calculateTransform(index, originalIndex, draggedItemSize, getItemSpace);
320
- this._renderer.setStyle(data.element, 'transform', transform ? `${this.orientation() === 'vertical' ? 'translateY' : 'translateX'}(${transform}px)` : '');
335
+ const signedTransform = transform * axisSign;
336
+ this._renderer.setStyle(data.element, 'transform', transform
337
+ ? `${this.orientation() === 'vertical' ? 'translateY' : 'translateX'}(${signedTransform}px)`
338
+ : '');
321
339
  });
322
340
  }
341
+ this.sortPreviewChanged.emit();
323
342
  }
324
343
  /** Creates or moves the placeholder element for inter-list drags */
325
344
  _updatePlaceholderElement(activeItem, targetIndex) {
@@ -429,6 +448,7 @@ class AXDropListDirective extends NXComponent {
429
448
  _resetAllTransforms() {
430
449
  this._cachedItems().forEach((data) => this._renderer.setStyle(data.element, 'transform', ''));
431
450
  this._removePlaceholderElement(); // Clean up inter-list placeholder
451
+ this.sortPreviewChanged.emit();
432
452
  }
433
453
  /** Resets the internal state of the directive to its initial values. */
434
454
  resetSortState() {
@@ -440,7 +460,7 @@ class AXDropListDirective extends NXComponent {
440
460
  this._listGap.set(0);
441
461
  }
442
462
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: AXDropListDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
443
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.0.8", type: AXDropListDirective, isStandalone: true, selector: "[axDropList]", inputs: { axDropList: { classPropertyName: "axDropList", publicName: "axDropList", isSignal: true, isRequired: false, transformFunction: null }, sortingDisabled: { classPropertyName: "sortingDisabled", publicName: "sortingDisabled", isSignal: true, isRequired: false, transformFunction: null }, dropListGroup: { classPropertyName: "dropListGroup", publicName: "dropListGroup", isSignal: true, isRequired: false, transformFunction: null }, dropListOrientation: { classPropertyName: "dropListOrientation", publicName: "dropListOrientation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dropListDropped: "dropListDropped" }, queries: [{ propertyName: "_draggableItems", predicate: AXDragDirective, isSignal: true }], exportAs: ["axDropList"], usesInheritance: true, ngImport: i0 }); }
463
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.0.8", type: AXDropListDirective, isStandalone: true, selector: "[axDropList]", inputs: { axDropList: { classPropertyName: "axDropList", publicName: "axDropList", isSignal: true, isRequired: false, transformFunction: null }, sortingDisabled: { classPropertyName: "sortingDisabled", publicName: "sortingDisabled", isSignal: true, isRequired: false, transformFunction: null }, dropListGroup: { classPropertyName: "dropListGroup", publicName: "dropListGroup", isSignal: true, isRequired: false, transformFunction: null }, dropListOrientation: { classPropertyName: "dropListOrientation", publicName: "dropListOrientation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dropListDropped: "dropListDropped", sortPreviewChanged: "sortPreviewChanged" }, queries: [{ propertyName: "_draggableItems", predicate: AXDragDirective, isSignal: true }], exportAs: ["axDropList"], usesInheritance: true, ngImport: i0 }); }
444
464
  }
445
465
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: AXDropListDirective, decorators: [{
446
466
  type: Directive,
@@ -448,7 +468,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImpor
448
468
  selector: '[axDropList]',
449
469
  exportAs: 'axDropList',
450
470
  }]
451
- }], propDecorators: { axDropList: [{ type: i0.Input, args: [{ isSignal: true, alias: "axDropList", required: false }] }], sortingDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "sortingDisabled", required: false }] }], dropListGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropListGroup", required: false }] }], dropListOrientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropListOrientation", required: false }] }], dropListDropped: [{ type: i0.Output, args: ["dropListDropped"] }], _draggableItems: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => AXDragDirective), { ...{ descendants: false }, isSignal: true }] }] } });
471
+ }], propDecorators: { axDropList: [{ type: i0.Input, args: [{ isSignal: true, alias: "axDropList", required: false }] }], sortingDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "sortingDisabled", required: false }] }], dropListGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropListGroup", required: false }] }], dropListOrientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "dropListOrientation", required: false }] }], dropListDropped: [{ type: i0.Output, args: ["dropListDropped"] }], sortPreviewChanged: [{ type: i0.Output, args: ["sortPreviewChanged"] }], _draggableItems: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => AXDragDirective), { ...{ descendants: false }, isSignal: true }] }] } });
452
472
 
453
473
  // Zone detection constants for nested drop lists (tree nodes)
454
474
  const ZONE_TOP_THRESHOLD = 0.3; // Top 30% triggers reorder BEFORE