@angular/cdk 12.2.0-rc.0 → 12.2.3

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.
@@ -3610,43 +3610,22 @@
3610
3610
  };
3611
3611
  CdkDrag.prototype.ngAfterViewInit = function () {
3612
3612
  var _this = this;
3613
- // We need to wait for the zone to stabilize, in order for the reference
3614
- // element to be in the proper place in the DOM. This is mostly relevant
3615
- // for draggable elements inside portals since they get stamped out in
3616
- // their original DOM position and then they get transferred to the portal.
3617
- this._ngZone.onStable
3618
- .pipe(operators.take(1), operators.takeUntil(this._destroyed))
3619
- .subscribe(function () {
3620
- _this._updateRootElement();
3621
- // Listen for any newly-added handles.
3622
- _this._handles.changes.pipe(operators.startWith(_this._handles),
3623
- // Sync the new handles with the DragRef.
3624
- operators.tap(function (handles) {
3625
- var childHandleElements = handles
3626
- .filter(function (handle) { return handle._parentDrag === _this; })
3627
- .map(function (handle) { return handle.element; });
3628
- // Usually handles are only allowed to be a descendant of the drag element, but if
3629
- // the consumer defined a different drag root, we should allow the drag element
3630
- // itself to be a handle too.
3631
- if (_this._selfHandle && _this.rootElementSelector) {
3632
- childHandleElements.push(_this.element);
3613
+ // Normally this isn't in the zone, but it can cause major performance regressions for apps
3614
+ // using `zone-patch-rxjs` because it'll trigger a change detection when it unsubscribes.
3615
+ this._ngZone.runOutsideAngular(function () {
3616
+ // We need to wait for the zone to stabilize, in order for the reference
3617
+ // element to be in the proper place in the DOM. This is mostly relevant
3618
+ // for draggable elements inside portals since they get stamped out in
3619
+ // their original DOM position and then they get transferred to the portal.
3620
+ _this._ngZone.onStable
3621
+ .pipe(operators.take(1), operators.takeUntil(_this._destroyed))
3622
+ .subscribe(function () {
3623
+ _this._updateRootElement();
3624
+ _this._setupHandlesListener();
3625
+ if (_this.freeDragPosition) {
3626
+ _this._dragRef.setFreeDragPosition(_this.freeDragPosition);
3633
3627
  }
3634
- _this._dragRef.withHandles(childHandleElements);
3635
- }),
3636
- // Listen if the state of any of the handles changes.
3637
- operators.switchMap(function (handles) {
3638
- return rxjs.merge.apply(void 0, __spreadArray([], __read(handles.map(function (item) {
3639
- return item._stateChanges.pipe(operators.startWith(item));
3640
- }))));
3641
- }), operators.takeUntil(_this._destroyed)).subscribe(function (handleInstance) {
3642
- // Enabled/disable the handle that changed in the DragRef.
3643
- var dragRef = _this._dragRef;
3644
- var handle = handleInstance.element.nativeElement;
3645
- handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
3646
3628
  });
3647
- if (_this.freeDragPosition) {
3648
- _this._dragRef.setFreeDragPosition(_this.freeDragPosition);
3649
- }
3650
3629
  });
3651
3630
  };
3652
3631
  CdkDrag.prototype.ngOnChanges = function (changes) {
@@ -3663,6 +3642,7 @@
3663
3642
  }
3664
3643
  };
3665
3644
  CdkDrag.prototype.ngOnDestroy = function () {
3645
+ var _this = this;
3666
3646
  if (this.dropContainer) {
3667
3647
  this.dropContainer.removeItem(this);
3668
3648
  }
@@ -3670,9 +3650,12 @@
3670
3650
  if (index > -1) {
3671
3651
  CdkDrag._dragInstances.splice(index, 1);
3672
3652
  }
3673
- this._destroyed.next();
3674
- this._destroyed.complete();
3675
- this._dragRef.dispose();
3653
+ // Unnecessary in most cases, but used to avoid extra change detections with `zone-paths-rxjs`.
3654
+ this._ngZone.runOutsideAngular(function () {
3655
+ _this._destroyed.next();
3656
+ _this._destroyed.complete();
3657
+ _this._dragRef.dispose();
3658
+ });
3676
3659
  };
3677
3660
  /** Syncs the root element with the `DragRef`. */
3678
3661
  CdkDrag.prototype._updateRootElement = function () {
@@ -3829,6 +3812,36 @@
3829
3812
  this.previewContainer = previewContainer;
3830
3813
  }
3831
3814
  };
3815
+ /** Sets up the listener that syncs the handles with the drag ref. */
3816
+ CdkDrag.prototype._setupHandlesListener = function () {
3817
+ var _this = this;
3818
+ // Listen for any newly-added handles.
3819
+ this._handles.changes.pipe(operators.startWith(this._handles),
3820
+ // Sync the new handles with the DragRef.
3821
+ operators.tap(function (handles) {
3822
+ var childHandleElements = handles
3823
+ .filter(function (handle) { return handle._parentDrag === _this; })
3824
+ .map(function (handle) { return handle.element; });
3825
+ // Usually handles are only allowed to be a descendant of the drag element, but if
3826
+ // the consumer defined a different drag root, we should allow the drag element
3827
+ // itself to be a handle too.
3828
+ if (_this._selfHandle && _this.rootElementSelector) {
3829
+ childHandleElements.push(_this.element);
3830
+ }
3831
+ _this._dragRef.withHandles(childHandleElements);
3832
+ }),
3833
+ // Listen if the state of any of the handles changes.
3834
+ operators.switchMap(function (handles) {
3835
+ return rxjs.merge.apply(void 0, __spreadArray([], __read(handles.map(function (item) {
3836
+ return item._stateChanges.pipe(operators.startWith(item));
3837
+ }))));
3838
+ }), operators.takeUntil(this._destroyed)).subscribe(function (handleInstance) {
3839
+ // Enabled/disable the handle that changed in the DragRef.
3840
+ var dragRef = _this._dragRef;
3841
+ var handle = handleInstance.element.nativeElement;
3842
+ handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
3843
+ });
3844
+ };
3832
3845
  return CdkDrag;
3833
3846
  }());
3834
3847
  CdkDrag._dragInstances = [];