@angular/cdk 11.1.0 → 11.1.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.
@@ -466,7 +466,7 @@
466
466
  this._pointerUp = function (event) {
467
467
  _this._endDragSequence(event);
468
468
  };
469
- this.withRootElement(element);
469
+ this.withRootElement(element).withParent(_config.parentDragRef || null);
470
470
  this._parentPositions = new ParentPositionTracker(_document, _viewportRuler);
471
471
  _dragDropRegistry.registerDragItem(this);
472
472
  }
@@ -577,6 +577,11 @@
577
577
  }
578
578
  return this;
579
579
  };
580
+ /** Sets the parent ref that the ref is nested in. */
581
+ DragRef.prototype.withParent = function (parent) {
582
+ this._parentDragRef = parent;
583
+ return this;
584
+ };
580
585
  /** Removes the dragging functionality from the DOM element. */
581
586
  DragRef.prototype.dispose = function () {
582
587
  this._removeRootElementListeners(this._rootElement);
@@ -606,7 +611,7 @@
606
611
  this._resizeSubscription.unsubscribe();
607
612
  this._parentPositions.clear();
608
613
  this._boundaryElement = this._rootElement = this._ownerSVGElement = this._placeholderTemplate =
609
- this._previewTemplate = this._anchor = null;
614
+ this._previewTemplate = this._anchor = this._parentDragRef = null;
610
615
  };
611
616
  /** Checks whether the element is currently being dragged. */
612
617
  DragRef.prototype.isDragging = function () {
@@ -794,7 +799,7 @@
794
799
  var _this = this;
795
800
  // Stop propagation if the item is inside another
796
801
  // draggable so we don't start multiple drag sequences.
797
- if (this._config.parentDragRef) {
802
+ if (this._parentDragRef) {
798
803
  event.stopPropagation();
799
804
  }
800
805
  var isDragging = this.isDragging();
@@ -3336,6 +3341,7 @@
3336
3341
  matchSize: [{ type: i0.Input }]
3337
3342
  };
3338
3343
 
3344
+ var DRAG_HOST_CLASS = 'cdk-drag';
3339
3345
  /** Element that can be moved inside a CdkDropList container. */
3340
3346
  var CdkDrag = /** @class */ (function () {
3341
3347
  function CdkDrag(
@@ -3347,7 +3353,7 @@
3347
3353
  * @deprecated `_document` parameter no longer being used and will be removed.
3348
3354
  * @breaking-change 12.0.0
3349
3355
  */
3350
- _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle, parentDrag) {
3356
+ _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle, _parentDrag) {
3351
3357
  var _this = this;
3352
3358
  this.element = element;
3353
3359
  this.dropContainer = dropContainer;
@@ -3356,6 +3362,7 @@
3356
3362
  this._dir = _dir;
3357
3363
  this._changeDetectorRef = _changeDetectorRef;
3358
3364
  this._selfHandle = _selfHandle;
3365
+ this._parentDrag = _parentDrag;
3359
3366
  this._destroyed = new rxjs.Subject();
3360
3367
  /** Emits when the user starts dragging the item. */
3361
3368
  this.started = new i0.EventEmitter();
@@ -3391,9 +3398,12 @@
3391
3398
  pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
3392
3399
  config.pointerDirectionChangeThreshold : 5,
3393
3400
  zIndex: config === null || config === void 0 ? void 0 : config.zIndex,
3394
- parentDragRef: parentDrag === null || parentDrag === void 0 ? void 0 : parentDrag._dragRef
3395
3401
  });
3396
3402
  this._dragRef.data = this;
3403
+ // We have to keep track of the drag instances in order to be able to match an element to
3404
+ // a drag instance. We can't go through the global registry of `DragRef`, because the root
3405
+ // element could be different.
3406
+ CdkDrag._dragInstances.push(this);
3397
3407
  if (config) {
3398
3408
  this._assignDefaults(config);
3399
3409
  }
@@ -3502,6 +3512,10 @@
3502
3512
  if (this.dropContainer) {
3503
3513
  this.dropContainer.removeItem(this);
3504
3514
  }
3515
+ var index = CdkDrag._dragInstances.indexOf(this);
3516
+ if (index > -1) {
3517
+ CdkDrag._dragInstances.splice(index, -1);
3518
+ }
3505
3519
  this._destroyed.next();
3506
3520
  this._destroyed.complete();
3507
3521
  this._dragRef.dispose();
@@ -3565,6 +3579,28 @@
3565
3579
  }
3566
3580
  }
3567
3581
  });
3582
+ // This only needs to be resolved once.
3583
+ ref.beforeStarted.pipe(operators.take(1)).subscribe(function () {
3584
+ var _a, _b;
3585
+ // If we managed to resolve a parent through DI, use it.
3586
+ if (_this._parentDrag) {
3587
+ ref.withParent(_this._parentDrag._dragRef);
3588
+ return;
3589
+ }
3590
+ // Otherwise fall back to resolving the parent by looking up the DOM. This can happen if
3591
+ // the item was projected into another item by something like `ngTemplateOutlet`.
3592
+ var parent = _this.element.nativeElement.parentElement;
3593
+ while (parent) {
3594
+ // `classList` needs to be null checked, because IE doesn't have it on some elements.
3595
+ if ((_a = parent.classList) === null || _a === void 0 ? void 0 : _a.contains(DRAG_HOST_CLASS)) {
3596
+ ref.withParent(((_b = CdkDrag._dragInstances.find(function (drag) {
3597
+ return drag.element.nativeElement === parent;
3598
+ })) === null || _b === void 0 ? void 0 : _b._dragRef) || null);
3599
+ break;
3600
+ }
3601
+ parent = parent.parentElement;
3602
+ }
3603
+ });
3568
3604
  };
3569
3605
  /** Handles the events from the underlying `DragRef`. */
3570
3606
  CdkDrag.prototype._handleEvents = function (ref) {
@@ -3632,12 +3668,13 @@
3632
3668
  };
3633
3669
  return CdkDrag;
3634
3670
  }());
3671
+ CdkDrag._dragInstances = [];
3635
3672
  CdkDrag.decorators = [
3636
3673
  { type: i0.Directive, args: [{
3637
3674
  selector: '[cdkDrag]',
3638
3675
  exportAs: 'cdkDrag',
3639
3676
  host: {
3640
- 'class': 'cdk-drag',
3677
+ 'class': DRAG_HOST_CLASS,
3641
3678
  '[class.cdk-drag-disabled]': 'disabled',
3642
3679
  '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
3643
3680
  },