@angular/cdk 17.3.5 → 17.3.7

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('17.3.5');
4
+ const VERSION = new Version('17.3.7');
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.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('17.3.5');\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.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Angular Component Development Kit. */\nexport const VERSION = new Version('17.3.7');\n"],"names":[],"mappings":";;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;;;"}
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, Inject, InjectionToken, booleanAttribute, Directive, Optional, SkipSelf, Input, EventEmitter, Self, Output, inject, NgModule } from '@angular/core';
2
+ import { Injectable, Inject, Component, ViewEncapsulation, ChangeDetectionStrategy, inject, ApplicationRef, EnvironmentInjector, createComponent, InjectionToken, booleanAttribute, Directive, Optional, SkipSelf, Input, EventEmitter, Self, Output, NgModule } from '@angular/core';
3
3
  import { DOCUMENT } from '@angular/common';
4
4
  import * as i1 from '@angular/cdk/scrolling';
5
5
  import { CdkScrollableModule } from '@angular/cdk/scrolling';
@@ -71,34 +71,25 @@ function combineTransforms(transform, initialTransform) {
71
71
  ? transform + ' ' + initialTransform
72
72
  : transform;
73
73
  }
74
-
75
- /** Parses a CSS time value to milliseconds. */
76
- function parseCssTimeUnitsToMs(value) {
77
- // Some browsers will return it in seconds, whereas others will return milliseconds.
78
- const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
79
- return parseFloat(value) * multiplier;
80
- }
81
- /** Gets the transform transition duration, including the delay, of an element in milliseconds. */
82
- function getTransformTransitionDurationInMs(element) {
83
- const computedStyle = getComputedStyle(element);
84
- const transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property');
85
- const property = transitionedProperties.find(prop => prop === 'transform' || prop === 'all');
86
- // If there's no transition for `all` or `transform`, we shouldn't do anything.
87
- if (!property) {
88
- return 0;
89
- }
90
- // Get the index of the property that we're interested in and match
91
- // it up to the same index in `transition-delay` and `transition-duration`.
92
- const propertyIndex = transitionedProperties.indexOf(property);
93
- const rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration');
94
- const rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay');
95
- return (parseCssTimeUnitsToMs(rawDurations[propertyIndex]) +
96
- parseCssTimeUnitsToMs(rawDelays[propertyIndex]));
74
+ /**
75
+ * Matches the target element's size to the source's size.
76
+ * @param target Element that needs to be resized.
77
+ * @param sourceRect Dimensions of the source element.
78
+ */
79
+ function matchElementSize(target, sourceRect) {
80
+ target.style.width = `${sourceRect.width}px`;
81
+ target.style.height = `${sourceRect.height}px`;
82
+ target.style.transform = getTransform(sourceRect.left, sourceRect.top);
97
83
  }
98
- /** Parses out multiple values from a computed style into an array. */
99
- function parseCssPropertyValue(computedStyle, name) {
100
- const value = computedStyle.getPropertyValue(name);
101
- return value.split(',').map(part => part.trim());
84
+ /**
85
+ * Gets a 3d `transform` that can be applied to an element.
86
+ * @param x Desired position of the element along the X axis.
87
+ * @param y Desired position of the element along the Y axis.
88
+ */
89
+ function getTransform(x, y) {
90
+ // Round the transforms since some browsers will
91
+ // blur the elements for sub-pixel transforms.
92
+ return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
102
93
  }
103
94
 
104
95
  /** Gets a mutable version of an element's bounding `DOMRect`. */
@@ -283,6 +274,152 @@ function transferCanvasData(source, clone) {
283
274
  }
284
275
  }
285
276
 
277
+ /**
278
+ * Gets the root HTML element of an embedded view.
279
+ * If the root is not an HTML element it gets wrapped in one.
280
+ */
281
+ function getRootNode(viewRef, _document) {
282
+ const rootNodes = viewRef.rootNodes;
283
+ if (rootNodes.length === 1 && rootNodes[0].nodeType === _document.ELEMENT_NODE) {
284
+ return rootNodes[0];
285
+ }
286
+ const wrapper = _document.createElement('div');
287
+ rootNodes.forEach(node => wrapper.appendChild(node));
288
+ return wrapper;
289
+ }
290
+
291
+ /** Parses a CSS time value to milliseconds. */
292
+ function parseCssTimeUnitsToMs(value) {
293
+ // Some browsers will return it in seconds, whereas others will return milliseconds.
294
+ const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
295
+ return parseFloat(value) * multiplier;
296
+ }
297
+ /** Gets the transform transition duration, including the delay, of an element in milliseconds. */
298
+ function getTransformTransitionDurationInMs(element) {
299
+ const computedStyle = getComputedStyle(element);
300
+ const transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property');
301
+ const property = transitionedProperties.find(prop => prop === 'transform' || prop === 'all');
302
+ // If there's no transition for `all` or `transform`, we shouldn't do anything.
303
+ if (!property) {
304
+ return 0;
305
+ }
306
+ // Get the index of the property that we're interested in and match
307
+ // it up to the same index in `transition-delay` and `transition-duration`.
308
+ const propertyIndex = transitionedProperties.indexOf(property);
309
+ const rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration');
310
+ const rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay');
311
+ return (parseCssTimeUnitsToMs(rawDurations[propertyIndex]) +
312
+ parseCssTimeUnitsToMs(rawDelays[propertyIndex]));
313
+ }
314
+ /** Parses out multiple values from a computed style into an array. */
315
+ function parseCssPropertyValue(computedStyle, name) {
316
+ const value = computedStyle.getPropertyValue(name);
317
+ return value.split(',').map(part => part.trim());
318
+ }
319
+
320
+ /** Inline styles to be set as `!important` while dragging. */
321
+ const importantProperties = new Set([
322
+ // Needs to be important, because some `mat-table` sets `position: sticky !important`. See #22781.
323
+ 'position',
324
+ ]);
325
+ class PreviewRef {
326
+ constructor(_document, _rootElement, _direction, _initialDomRect, _previewTemplate, _previewClass, _pickupPositionOnPage, _initialTransform, _zIndex) {
327
+ this._document = _document;
328
+ this._rootElement = _rootElement;
329
+ this._direction = _direction;
330
+ this._initialDomRect = _initialDomRect;
331
+ this._previewTemplate = _previewTemplate;
332
+ this._previewClass = _previewClass;
333
+ this._pickupPositionOnPage = _pickupPositionOnPage;
334
+ this._initialTransform = _initialTransform;
335
+ this._zIndex = _zIndex;
336
+ }
337
+ attach(parent) {
338
+ this._preview = this._createPreview();
339
+ parent.appendChild(this._preview);
340
+ // The null check is necessary for browsers that don't support the popover API.
341
+ // Note that we use a string access for compatibility with Closure.
342
+ if ('showPopover' in this._preview) {
343
+ this._preview['showPopover']();
344
+ }
345
+ }
346
+ destroy() {
347
+ this._preview.remove();
348
+ this._previewEmbeddedView?.destroy();
349
+ this._preview = this._previewEmbeddedView = null;
350
+ }
351
+ setTransform(value) {
352
+ this._preview.style.transform = value;
353
+ }
354
+ getBoundingClientRect() {
355
+ return this._preview.getBoundingClientRect();
356
+ }
357
+ addClass(className) {
358
+ this._preview.classList.add(className);
359
+ }
360
+ getTransitionDuration() {
361
+ return getTransformTransitionDurationInMs(this._preview);
362
+ }
363
+ addEventListener(name, handler) {
364
+ this._preview.addEventListener(name, handler);
365
+ }
366
+ removeEventListener(name, handler) {
367
+ this._preview.removeEventListener(name, handler);
368
+ }
369
+ _createPreview() {
370
+ const previewConfig = this._previewTemplate;
371
+ const previewClass = this._previewClass;
372
+ const previewTemplate = previewConfig ? previewConfig.template : null;
373
+ let preview;
374
+ if (previewTemplate && previewConfig) {
375
+ // Measure the element before we've inserted the preview
376
+ // since the insertion could throw off the measurement.
377
+ const rootRect = previewConfig.matchSize ? this._initialDomRect : null;
378
+ const viewRef = previewConfig.viewContainer.createEmbeddedView(previewTemplate, previewConfig.context);
379
+ viewRef.detectChanges();
380
+ preview = getRootNode(viewRef, this._document);
381
+ this._previewEmbeddedView = viewRef;
382
+ if (previewConfig.matchSize) {
383
+ matchElementSize(preview, rootRect);
384
+ }
385
+ else {
386
+ preview.style.transform = getTransform(this._pickupPositionOnPage.x, this._pickupPositionOnPage.y);
387
+ }
388
+ }
389
+ else {
390
+ preview = deepCloneNode(this._rootElement);
391
+ matchElementSize(preview, this._initialDomRect);
392
+ if (this._initialTransform) {
393
+ preview.style.transform = this._initialTransform;
394
+ }
395
+ }
396
+ extendStyles(preview.style, {
397
+ // It's important that we disable the pointer events on the preview, because
398
+ // it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
399
+ 'pointer-events': 'none',
400
+ // We have to reset the margin, because it can throw off positioning relative to the viewport.
401
+ 'margin': '0',
402
+ 'position': 'fixed',
403
+ 'top': '0',
404
+ 'left': '0',
405
+ 'z-index': this._zIndex + '',
406
+ }, importantProperties);
407
+ toggleNativeDragInteractions(preview, false);
408
+ preview.classList.add('cdk-drag-preview');
409
+ preview.setAttribute('popover', 'manual');
410
+ preview.setAttribute('dir', this._direction);
411
+ if (previewClass) {
412
+ if (Array.isArray(previewClass)) {
413
+ previewClass.forEach(className => preview.classList.add(className));
414
+ }
415
+ else {
416
+ preview.classList.add(previewClass);
417
+ }
418
+ }
419
+ return preview;
420
+ }
421
+ }
422
+
286
423
  /** Options that can be used to bind a passive event listener. */
287
424
  const passiveEventListenerOptions = normalizePassiveListenerOptions({ passive: true });
288
425
  /** Options that can be used to bind an active event listener. */
@@ -704,9 +841,8 @@ class DragRef {
704
841
  }
705
842
  /** Destroys the preview element and its ViewRef. */
706
843
  _destroyPreview() {
707
- this._preview?.remove();
708
- this._previewRef?.destroy();
709
- this._preview = this._previewRef = null;
844
+ this._preview?.destroy();
845
+ this._preview = null;
710
846
  }
711
847
  /** Destroys the placeholder element and its ViewRef. */
712
848
  _destroyPlaceholder() {
@@ -793,13 +929,13 @@ class DragRef {
793
929
  this._initialTransform = element.style.transform || '';
794
930
  // Create the preview after the initial transform has
795
931
  // been cached, because it can be affected by the transform.
796
- this._preview = this._createPreviewElement();
932
+ this._preview = new PreviewRef(this._document, this._rootElement, this._direction, this._initialDomRect, this._previewTemplate || null, this.previewClass || null, this._pickupPositionOnPage, this._initialTransform, this._config.zIndex || 1000);
933
+ this._preview.attach(this._getPreviewInsertionPoint(parent, shadowRoot));
797
934
  // We move the element out at the end of the body and we make it hidden, because keeping it in
798
935
  // place will throw off the consumer's `:last-child` selectors. We can't remove the element
799
936
  // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
800
937
  toggleVisibility(element, false, dragImportantProperties);
801
938
  this._document.body.appendChild(parent.replaceChild(placeholder, element));
802
- this._getPreviewInsertionPoint(parent, shadowRoot).appendChild(this._preview);
803
939
  this.started.next({ source: this, event }); // Emit before notifying the container.
804
940
  dropContainer.start();
805
941
  this._initialContainer = dropContainer;
@@ -972,61 +1108,6 @@ class DragRef {
972
1108
  }
973
1109
  }
974
1110
  }
975
- /**
976
- * Creates the element that will be rendered next to the user's pointer
977
- * and will be used as a preview of the element that is being dragged.
978
- */
979
- _createPreviewElement() {
980
- const previewConfig = this._previewTemplate;
981
- const previewClass = this.previewClass;
982
- const previewTemplate = previewConfig ? previewConfig.template : null;
983
- let preview;
984
- if (previewTemplate && previewConfig) {
985
- // Measure the element before we've inserted the preview
986
- // since the insertion could throw off the measurement.
987
- const rootRect = previewConfig.matchSize ? this._initialDomRect : null;
988
- const viewRef = previewConfig.viewContainer.createEmbeddedView(previewTemplate, previewConfig.context);
989
- viewRef.detectChanges();
990
- preview = getRootNode(viewRef, this._document);
991
- this._previewRef = viewRef;
992
- if (previewConfig.matchSize) {
993
- matchElementSize(preview, rootRect);
994
- }
995
- else {
996
- preview.style.transform = getTransform(this._pickupPositionOnPage.x, this._pickupPositionOnPage.y);
997
- }
998
- }
999
- else {
1000
- preview = deepCloneNode(this._rootElement);
1001
- matchElementSize(preview, this._initialDomRect);
1002
- if (this._initialTransform) {
1003
- preview.style.transform = this._initialTransform;
1004
- }
1005
- }
1006
- extendStyles(preview.style, {
1007
- // It's important that we disable the pointer events on the preview, because
1008
- // it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
1009
- 'pointer-events': 'none',
1010
- // We have to reset the margin, because it can throw off positioning relative to the viewport.
1011
- 'margin': '0',
1012
- 'position': 'fixed',
1013
- 'top': '0',
1014
- 'left': '0',
1015
- 'z-index': `${this._config.zIndex || 1000}`,
1016
- }, dragImportantProperties);
1017
- toggleNativeDragInteractions(preview, false);
1018
- preview.classList.add('cdk-drag-preview');
1019
- preview.setAttribute('dir', this._direction);
1020
- if (previewClass) {
1021
- if (Array.isArray(previewClass)) {
1022
- previewClass.forEach(className => preview.classList.add(className));
1023
- }
1024
- else {
1025
- preview.classList.add(previewClass);
1026
- }
1027
- }
1028
- return preview;
1029
- }
1030
1111
  /**
1031
1112
  * Animates the preview element from its current position to the location of the drop placeholder.
1032
1113
  * @returns Promise that resolves when the animation completes.
@@ -1038,14 +1119,14 @@ class DragRef {
1038
1119
  }
1039
1120
  const placeholderRect = this._placeholder.getBoundingClientRect();
1040
1121
  // Apply the class that adds a transition to the preview.
1041
- this._preview.classList.add('cdk-drag-animating');
1122
+ this._preview.addClass('cdk-drag-animating');
1042
1123
  // Move the preview to the placeholder position.
1043
1124
  this._applyPreviewTransform(placeholderRect.left, placeholderRect.top);
1044
1125
  // If the element doesn't have a `transition`, the `transitionend` event won't fire. Since
1045
1126
  // we need to trigger a style recalculation in order for the `cdk-drag-animating` class to
1046
1127
  // apply its style, we take advantage of the available info to figure out whether we need to
1047
1128
  // bind the event in the first place.
1048
- const duration = getTransformTransitionDurationInMs(this._preview);
1129
+ const duration = this._preview.getTransitionDuration();
1049
1130
  if (duration === 0) {
1050
1131
  return Promise.resolve();
1051
1132
  }
@@ -1233,7 +1314,7 @@ class DragRef {
1233
1314
  // it could be completely different and the transform might not make sense anymore.
1234
1315
  const initialTransform = this._previewTemplate?.template ? undefined : this._initialTransform;
1235
1316
  const transform = getTransform(x, y);
1236
- this._preview.style.transform = combineTransforms(transform, initialTransform);
1317
+ this._preview.setTransform(combineTransforms(transform, initialTransform));
1237
1318
  }
1238
1319
  /**
1239
1320
  * Gets the distance that the user has dragged during the current drag sequence.
@@ -1392,16 +1473,6 @@ class DragRef {
1392
1473
  });
1393
1474
  }
1394
1475
  }
1395
- /**
1396
- * Gets a 3d `transform` that can be applied to an element.
1397
- * @param x Desired position of the element along the X axis.
1398
- * @param y Desired position of the element along the Y axis.
1399
- */
1400
- function getTransform(x, y) {
1401
- // Round the transforms since some browsers will
1402
- // blur the elements for sub-pixel transforms.
1403
- return `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
1404
- }
1405
1476
  /** Clamps a value between a minimum and a maximum. */
1406
1477
  function clamp$1(value, min, max) {
1407
1478
  return Math.max(min, Math.min(max, value));
@@ -1413,29 +1484,6 @@ function isTouchEvent(event) {
1413
1484
  // that if the event's name starts with `t`, it's a touch event.
1414
1485
  return event.type[0] === 't';
1415
1486
  }
1416
- /**
1417
- * Gets the root HTML element of an embedded view.
1418
- * If the root is not an HTML element it gets wrapped in one.
1419
- */
1420
- function getRootNode(viewRef, _document) {
1421
- const rootNodes = viewRef.rootNodes;
1422
- if (rootNodes.length === 1 && rootNodes[0].nodeType === _document.ELEMENT_NODE) {
1423
- return rootNodes[0];
1424
- }
1425
- const wrapper = _document.createElement('div');
1426
- rootNodes.forEach(node => wrapper.appendChild(node));
1427
- return wrapper;
1428
- }
1429
- /**
1430
- * Matches the target element's size to the source's size.
1431
- * @param target Element that needs to be resized.
1432
- * @param sourceRect Dimensions of the source element.
1433
- */
1434
- function matchElementSize(target, sourceRect) {
1435
- target.style.width = `${sourceRect.width}px`;
1436
- target.style.height = `${sourceRect.height}px`;
1437
- target.style.transform = getTransform(sourceRect.left, sourceRect.top);
1438
- }
1439
1487
  /** Callback invoked for `selectstart` events inside the shadow DOM. */
1440
1488
  function shadowDomSelectStart(event) {
1441
1489
  event.preventDefault();
@@ -2651,6 +2699,20 @@ const DEFAULT_CONFIG = {
2651
2699
  dragStartThreshold: 5,
2652
2700
  pointerDirectionChangeThreshold: 5,
2653
2701
  };
2702
+ /** Keeps track of the apps currently containing badges. */
2703
+ const activeApps = new Set();
2704
+ /**
2705
+ * Component used to load the drag&drop reset styles.
2706
+ * @docs-private
2707
+ */
2708
+ class _ResetsLoader {
2709
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: _ResetsLoader, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2710
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.0", type: _ResetsLoader, isStandalone: true, selector: "ng-component", host: { attributes: { "cdk-drag-resets-container": "" } }, ngImport: i0, template: '', isInline: true, styles: ["@layer cdk-resets{.cdk-drag-preview{background:none;border:none;padding:0;color:inherit}}"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
2711
+ }
2712
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: _ResetsLoader, decorators: [{
2713
+ type: Component,
2714
+ args: [{ standalone: true, encapsulation: ViewEncapsulation.None, template: '', changeDetection: ChangeDetectionStrategy.OnPush, host: { 'cdk-drag-resets-container': '' }, styles: ["@layer cdk-resets{.cdk-drag-preview{background:none;border:none;padding:0;color:inherit}}"] }]
2715
+ }] });
2654
2716
  /**
2655
2717
  * Service that allows for drag-and-drop functionality to be attached to DOM elements.
2656
2718
  */
@@ -2660,6 +2722,8 @@ class DragDrop {
2660
2722
  this._ngZone = _ngZone;
2661
2723
  this._viewportRuler = _viewportRuler;
2662
2724
  this._dragDropRegistry = _dragDropRegistry;
2725
+ this._appRef = inject(ApplicationRef);
2726
+ this._environmentInjector = inject(EnvironmentInjector);
2663
2727
  }
2664
2728
  /**
2665
2729
  * Turns an element into a draggable item.
@@ -2667,6 +2731,7 @@ class DragDrop {
2667
2731
  * @param config Object used to configure the dragging behavior.
2668
2732
  */
2669
2733
  createDrag(element, config = DEFAULT_CONFIG) {
2734
+ this._loadResets();
2670
2735
  return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
2671
2736
  }
2672
2737
  /**
@@ -2676,6 +2741,22 @@ class DragDrop {
2676
2741
  createDropList(element) {
2677
2742
  return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
2678
2743
  }
2744
+ // TODO(crisbeto): abstract this away into something reusable.
2745
+ /** Loads the CSS resets needed for the module to work correctly. */
2746
+ _loadResets() {
2747
+ if (!activeApps.has(this._appRef)) {
2748
+ activeApps.add(this._appRef);
2749
+ const componentRef = createComponent(_ResetsLoader, {
2750
+ environmentInjector: this._environmentInjector,
2751
+ });
2752
+ this._appRef.onDestroy(() => {
2753
+ activeApps.delete(this._appRef);
2754
+ if (activeApps.size === 0) {
2755
+ componentRef.destroy();
2756
+ }
2757
+ });
2758
+ }
2759
+ }
2679
2760
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: DragDrop, deps: [{ token: DOCUMENT }, { token: i0.NgZone }, { token: i1.ViewportRuler }, { token: DragDropRegistry }], target: i0.ɵɵFactoryTarget.Injectable }); }
2680
2761
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: DragDrop, providedIn: 'root' }); }
2681
2762
  }