@angular/cdk 19.2.0-next.2 → 19.2.0-next.4

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/fesm2022/cdk.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Version } from '@angular/core';
2
2
 
3
3
  /** Current version of the Angular Component Development Kit. */
4
- const VERSION = new Version('19.2.0-next.2');
4
+ const VERSION = new Version('19.2.0-next.4');
5
5
 
6
6
  export { VERSION };
7
7
  //# sourceMappingURL=cdk.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cdk.mjs","sources":["../../../../../../src/cdk/version.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('19.2.0-next.2');\n"],"names":[],"mappings":";;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;;;"}
1
+ {"version":3,"file":"cdk.mjs","sources":["../../../../../../src/cdk/version.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('19.2.0-next.4');\n"],"names":[],"mappings":";;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;;;"}
@@ -745,6 +745,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImpor
745
745
  args: [{ providedIn: 'root' }]
746
746
  }], ctorParameters: () => [] });
747
747
 
748
+ /** Encapsulates the logic for attaching and detaching a backdrop. */
749
+ class BackdropRef {
750
+ _renderer;
751
+ _ngZone;
752
+ element;
753
+ _cleanupClick;
754
+ _cleanupTransitionEnd;
755
+ _fallbackTimeout;
756
+ constructor(document, _renderer, _ngZone, onClick) {
757
+ this._renderer = _renderer;
758
+ this._ngZone = _ngZone;
759
+ this.element = document.createElement('div');
760
+ this.element.classList.add('cdk-overlay-backdrop');
761
+ this._cleanupClick = _renderer.listen(this.element, 'click', onClick);
762
+ }
763
+ detach() {
764
+ this._ngZone.runOutsideAngular(() => {
765
+ const element = this.element;
766
+ clearTimeout(this._fallbackTimeout);
767
+ this._cleanupTransitionEnd?.();
768
+ this._cleanupTransitionEnd = this._renderer.listen(element, 'transitionend', this.dispose);
769
+ this._fallbackTimeout = setTimeout(this.dispose, 500);
770
+ // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
771
+ // In this case we make it unclickable and we try to remove it after a delay.
772
+ element.style.pointerEvents = 'none';
773
+ element.classList.remove('cdk-overlay-backdrop-showing');
774
+ });
775
+ }
776
+ dispose = () => {
777
+ clearTimeout(this._fallbackTimeout);
778
+ this._cleanupClick?.();
779
+ this._cleanupTransitionEnd?.();
780
+ this._cleanupClick = this._cleanupTransitionEnd = this._fallbackTimeout = undefined;
781
+ this.element.remove();
782
+ };
783
+ }
784
+
748
785
  /**
749
786
  * Reference to an overlay that has been created with the Overlay service.
750
787
  * Used to manipulate or dispose of said overlay.
@@ -762,16 +799,13 @@ class OverlayRef {
762
799
  _animationsDisabled;
763
800
  _injector;
764
801
  _renderer;
765
- _backdropElement = null;
766
- _backdropTimeout;
767
802
  _backdropClick = new Subject();
768
803
  _attachments = new Subject();
769
804
  _detachments = new Subject();
770
805
  _positionStrategy;
771
806
  _scrollStrategy;
772
807
  _locationChanges = Subscription.EMPTY;
773
- _cleanupBackdropClick;
774
- _cleanupBackdropTransitionEnd;
808
+ _backdropRef = null;
775
809
  /**
776
810
  * Reference to the parent of the `_host` at the time it was detached. Used to restore
777
811
  * the `_host` to its original position in the DOM when it gets re-attached.
@@ -816,7 +850,7 @@ class OverlayRef {
816
850
  }
817
851
  /** The overlay's backdrop HTML element. */
818
852
  get backdropElement() {
819
- return this._backdropElement;
853
+ return this._backdropRef?.element || null;
820
854
  }
821
855
  /**
822
856
  * Wrapper around the panel element. Can be used for advanced
@@ -935,7 +969,7 @@ class OverlayRef {
935
969
  this._positionStrategy.dispose();
936
970
  }
937
971
  this._disposeScrollStrategy();
938
- this._disposeBackdrop(this._backdropElement);
972
+ this._backdropRef?.dispose();
939
973
  this._locationChanges.unsubscribe();
940
974
  this._keyboardDispatcher.remove(this);
941
975
  this._portalOutlet.dispose();
@@ -946,7 +980,7 @@ class OverlayRef {
946
980
  this._outsideClickDispatcher.remove(this);
947
981
  this._host?.remove();
948
982
  this._afterNextRenderRef?.destroy();
949
- this._previousHostParent = this._pane = this._host = null;
983
+ this._previousHostParent = this._pane = this._host = this._backdropRef = null;
950
984
  if (isAttached) {
951
985
  this._detachments.next();
952
986
  }
@@ -1070,33 +1104,27 @@ class OverlayRef {
1070
1104
  /** Attaches a backdrop for this overlay. */
1071
1105
  _attachBackdrop() {
1072
1106
  const showingClass = 'cdk-overlay-backdrop-showing';
1073
- this._backdropElement = this._document.createElement('div');
1074
- this._backdropElement.classList.add('cdk-overlay-backdrop');
1107
+ this._backdropRef?.dispose();
1108
+ this._backdropRef = new BackdropRef(this._document, this._renderer, this._ngZone, event => {
1109
+ this._backdropClick.next(event);
1110
+ });
1075
1111
  if (this._animationsDisabled) {
1076
- this._backdropElement.classList.add('cdk-overlay-backdrop-noop-animation');
1112
+ this._backdropRef.element.classList.add('cdk-overlay-backdrop-noop-animation');
1077
1113
  }
1078
1114
  if (this._config.backdropClass) {
1079
- this._toggleClasses(this._backdropElement, this._config.backdropClass, true);
1115
+ this._toggleClasses(this._backdropRef.element, this._config.backdropClass, true);
1080
1116
  }
1081
1117
  // Insert the backdrop before the pane in the DOM order,
1082
1118
  // in order to handle stacked overlays properly.
1083
- this._host.parentElement.insertBefore(this._backdropElement, this._host);
1084
- // Forward backdrop clicks such that the consumer of the overlay can perform whatever
1085
- // action desired when such a click occurs (usually closing the overlay).
1086
- this._cleanupBackdropClick?.();
1087
- this._cleanupBackdropClick = this._renderer.listen(this._backdropElement, 'click', (event) => this._backdropClick.next(event));
1119
+ this._host.parentElement.insertBefore(this._backdropRef.element, this._host);
1088
1120
  // Add class to fade-in the backdrop after one frame.
1089
1121
  if (!this._animationsDisabled && typeof requestAnimationFrame !== 'undefined') {
1090
1122
  this._ngZone.runOutsideAngular(() => {
1091
- requestAnimationFrame(() => {
1092
- if (this._backdropElement) {
1093
- this._backdropElement.classList.add(showingClass);
1094
- }
1095
- });
1123
+ requestAnimationFrame(() => this._backdropRef?.element.classList.add(showingClass));
1096
1124
  });
1097
1125
  }
1098
1126
  else {
1099
- this._backdropElement.classList.add(showingClass);
1127
+ this._backdropRef.element.classList.add(showingClass);
1100
1128
  }
1101
1129
  }
1102
1130
  /**
@@ -1113,30 +1141,13 @@ class OverlayRef {
1113
1141
  }
1114
1142
  /** Detaches the backdrop (if any) associated with the overlay. */
1115
1143
  detachBackdrop() {
1116
- const backdropToDetach = this._backdropElement;
1117
- if (!backdropToDetach) {
1118
- return;
1119
- }
1120
1144
  if (this._animationsDisabled) {
1121
- this._disposeBackdrop(backdropToDetach);
1122
- return;
1145
+ this._backdropRef?.dispose();
1146
+ this._backdropRef = null;
1147
+ }
1148
+ else {
1149
+ this._backdropRef?.detach();
1123
1150
  }
1124
- backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
1125
- this._ngZone.runOutsideAngular(() => {
1126
- this._cleanupBackdropTransitionEnd?.();
1127
- this._cleanupBackdropTransitionEnd = this._renderer.listen(backdropToDetach, 'transitionend', (event) => {
1128
- this._disposeBackdrop(event.target);
1129
- });
1130
- });
1131
- // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
1132
- // In this case we make it unclickable and we try to remove it after a delay.
1133
- backdropToDetach.style.pointerEvents = 'none';
1134
- // Run this outside the Angular zone because there's nothing that Angular cares about.
1135
- // If it were to run inside the Angular zone, every test that used Overlay would have to be
1136
- // either async or fakeAsync.
1137
- this._backdropTimeout = this._ngZone.runOutsideAngular(() => setTimeout(() => {
1138
- this._disposeBackdrop(backdropToDetach);
1139
- }, 500));
1140
1151
  }
1141
1152
  /** Toggles a single CSS class or an array of classes on an element. */
1142
1153
  _toggleClasses(element, cssClasses, isAdd) {
@@ -1175,30 +1186,8 @@ class OverlayRef {
1175
1186
  /** Disposes of a scroll strategy. */
1176
1187
  _disposeScrollStrategy() {
1177
1188
  const scrollStrategy = this._scrollStrategy;
1178
- if (scrollStrategy) {
1179
- scrollStrategy.disable();
1180
- if (scrollStrategy.detach) {
1181
- scrollStrategy.detach();
1182
- }
1183
- }
1184
- }
1185
- /** Removes a backdrop element from the DOM. */
1186
- _disposeBackdrop(backdrop) {
1187
- this._cleanupBackdropClick?.();
1188
- this._cleanupBackdropTransitionEnd?.();
1189
- if (backdrop) {
1190
- backdrop.remove();
1191
- // It is possible that a new portal has been attached to this overlay since we started
1192
- // removing the backdrop. If that is the case, only clear the backdrop reference if it
1193
- // is still the same instance that we started to remove.
1194
- if (this._backdropElement === backdrop) {
1195
- this._backdropElement = null;
1196
- }
1197
- }
1198
- if (this._backdropTimeout) {
1199
- clearTimeout(this._backdropTimeout);
1200
- this._backdropTimeout = undefined;
1201
- }
1189
+ scrollStrategy?.disable();
1190
+ scrollStrategy?.detach?.();
1202
1191
  }
1203
1192
  }
1204
1193