@angular/cdk 10.0.0-rc.3 → 10.1.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.
- package/a11y/aria-describer/aria-describer.d.ts +10 -1
- package/a11y/focus-trap/focus-trap.d.ts +4 -2
- package/a11y/index.metadata.json +1 -1
- package/a11y/interactivity-checker/interactivity-checker.d.ts +11 -1
- package/a11y/key-manager/list-key-manager.d.ts +6 -0
- package/accordion/accordion.d.ts +7 -1
- package/accordion/index.d.ts +1 -0
- package/accordion/index.metadata.json +1 -1
- package/bundles/cdk-a11y.umd.js +78 -15
- package/bundles/cdk-a11y.umd.js.map +1 -1
- package/bundles/cdk-a11y.umd.min.js +11 -11
- package/bundles/cdk-a11y.umd.min.js.map +1 -1
- package/bundles/cdk-accordion.umd.js +12 -4
- package/bundles/cdk-accordion.umd.js.map +1 -1
- package/bundles/cdk-accordion.umd.min.js +2 -2
- package/bundles/cdk-accordion.umd.min.js.map +1 -1
- package/bundles/cdk-drag-drop.umd.js +717 -641
- package/bundles/cdk-drag-drop.umd.js.map +1 -1
- package/bundles/cdk-drag-drop.umd.min.js +8 -16
- package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
- package/bundles/cdk-overlay.umd.js +199 -42
- package/bundles/cdk-overlay.umd.js.map +1 -1
- package/bundles/cdk-overlay.umd.min.js +11 -18
- package/bundles/cdk-overlay.umd.min.js.map +1 -1
- package/bundles/cdk-platform.umd.js +0 -1
- package/bundles/cdk-platform.umd.js.map +1 -1
- package/bundles/cdk-platform.umd.min.js +2 -2
- package/bundles/cdk-platform.umd.min.js.map +1 -1
- package/bundles/cdk-scrolling.umd.js +26 -4
- package/bundles/cdk-scrolling.umd.js.map +1 -1
- package/bundles/cdk-scrolling.umd.min.js +11 -4
- package/bundles/cdk-scrolling.umd.min.js.map +1 -1
- package/bundles/cdk-testing-protractor.umd.min.js +1 -1
- package/bundles/cdk-testing-protractor.umd.min.js.map +1 -1
- package/bundles/cdk-testing-testbed.umd.min.js +8 -8
- package/bundles/cdk-testing-testbed.umd.min.js.map +1 -1
- package/bundles/cdk-testing.umd.js +32 -0
- package/bundles/cdk-testing.umd.js.map +1 -1
- package/bundles/cdk-testing.umd.min.js +5 -5
- package/bundles/cdk-testing.umd.min.js.map +1 -1
- package/bundles/cdk-tree.umd.js +6 -2
- package/bundles/cdk-tree.umd.js.map +1 -1
- package/bundles/cdk-tree.umd.min.js +3 -3
- package/bundles/cdk-tree.umd.min.js.map +1 -1
- package/bundles/cdk.umd.js +1 -1
- package/bundles/cdk.umd.js.map +1 -1
- package/bundles/cdk.umd.min.js +1 -1
- package/bundles/cdk.umd.min.js.map +1 -1
- package/drag-drop/directives/drag-handle.d.ts +7 -1
- package/drag-drop/directives/drag-placeholder.d.ts +7 -1
- package/drag-drop/directives/drag-preview.d.ts +7 -1
- package/drag-drop/directives/drag.d.ts +4 -14
- package/drag-drop/directives/drop-list-group.d.ts +7 -1
- package/drag-drop/directives/drop-list.d.ts +7 -1
- package/drag-drop/drag-ref.d.ts +6 -0
- package/drag-drop/drop-list-ref.d.ts +3 -2
- package/drag-drop/index.d.ts +2 -2
- package/drag-drop/index.metadata.json +1 -1
- package/esm2015/a11y/a11y-module.js +15 -19
- package/esm2015/a11y/aria-describer/aria-describer.js +177 -167
- package/esm2015/a11y/focus-monitor/focus-monitor.js +337 -345
- package/esm2015/a11y/focus-trap/configurable-focus-trap-factory.js +30 -34
- package/esm2015/a11y/focus-trap/focus-trap-manager.js +36 -40
- package/esm2015/a11y/focus-trap/focus-trap.js +85 -82
- package/esm2015/a11y/high-contrast-mode/high-contrast-mode-detector.js +56 -60
- package/esm2015/a11y/interactivity-checker/interactivity-checker.js +113 -104
- package/esm2015/a11y/key-manager/list-key-manager.js +29 -4
- package/esm2015/a11y/live-announcer/live-announcer.js +138 -146
- package/esm2015/accordion/accordion-item.js +119 -123
- package/esm2015/accordion/accordion-module.js +9 -13
- package/esm2015/accordion/accordion.js +49 -46
- package/esm2015/accordion/index.js +2 -1
- package/esm2015/bidi/bidi-module.js +9 -13
- package/esm2015/bidi/dir.js +41 -45
- package/esm2015/bidi/directionality.js +27 -31
- package/esm2015/clipboard/clipboard-module.js +9 -13
- package/esm2015/clipboard/clipboard.js +36 -40
- package/esm2015/clipboard/copy-to-clipboard.js +71 -75
- package/esm2015/collections/unique-selection-dispatcher.js +33 -37
- package/esm2015/drag-drop/directives/drag-handle.js +42 -39
- package/esm2015/drag-drop/directives/drag-placeholder.js +24 -21
- package/esm2015/drag-drop/directives/drag-preview.js +29 -26
- package/esm2015/drag-drop/directives/drag.js +313 -319
- package/esm2015/drag-drop/directives/drop-list-group.js +32 -29
- package/esm2015/drag-drop/directives/drop-list.js +251 -250
- package/esm2015/drag-drop/drag-drop-module.js +27 -31
- package/esm2015/drag-drop/drag-drop-registry.js +139 -143
- package/esm2015/drag-drop/drag-drop.js +33 -37
- package/esm2015/drag-drop/drag-ref.js +59 -25
- package/esm2015/drag-drop/drop-list-ref.js +15 -9
- package/esm2015/drag-drop/index.js +3 -2
- package/esm2015/layout/breakpoints-observer.js +81 -85
- package/esm2015/layout/layout-module.js +6 -10
- package/esm2015/layout/media-matcher.js +28 -32
- package/esm2015/observers/observe-content.js +147 -163
- package/esm2015/overlay/dispatchers/base-overlay-dispatcher.js +51 -0
- package/esm2015/overlay/dispatchers/index.js +10 -0
- package/esm2015/overlay/dispatchers/overlay-keyboard-dispatcher.js +79 -0
- package/esm2015/overlay/dispatchers/overlay-outside-click-dispatcher.js +94 -0
- package/esm2015/overlay/fullscreen-overlay-container.js +70 -74
- package/esm2015/overlay/index.js +5 -4
- package/esm2015/overlay/overlay-config.js +5 -1
- package/esm2015/overlay/overlay-container.js +69 -73
- package/esm2015/overlay/overlay-directives.js +245 -243
- package/esm2015/overlay/overlay-module.js +15 -19
- package/esm2015/overlay/overlay-ref.js +24 -2
- package/esm2015/overlay/overlay-reference.js +1 -1
- package/esm2015/overlay/overlay.js +93 -92
- package/esm2015/overlay/position/connected-position.js +14 -18
- package/esm2015/overlay/position/overlay-position-builder.js +43 -47
- package/esm2015/overlay/public-api.js +2 -2
- package/esm2015/overlay/scroll/scroll-strategy-options.js +33 -37
- package/esm2015/platform/features/scrolling.js +1 -2
- package/esm2015/platform/platform-module.js +6 -10
- package/esm2015/platform/platform.js +48 -52
- package/esm2015/portal/portal-directives.js +181 -201
- package/esm2015/scrolling/fixed-size-virtual-scroll.js +57 -47
- package/esm2015/scrolling/public-api.js +2 -1
- package/esm2015/scrolling/scroll-dispatcher.js +139 -143
- package/esm2015/scrolling/scrollable.js +135 -139
- package/esm2015/scrolling/scrolling-module.js +32 -40
- package/esm2015/scrolling/viewport-ruler.js +105 -109
- package/esm2015/scrolling/virtual-for-of.js +264 -268
- package/esm2015/scrolling/virtual-scroll-repeater.js +8 -0
- package/esm2015/scrolling/virtual-scroll-viewport.js +318 -322
- package/esm2015/stepper/step-header.js +20 -24
- package/esm2015/stepper/step-label.js +13 -17
- package/esm2015/stepper/stepper-button.js +59 -67
- package/esm2015/stepper/stepper-module.js +24 -28
- package/esm2015/stepper/stepper.js +313 -321
- package/esm2015/table/cell.js +129 -157
- package/esm2015/table/row.js +183 -219
- package/esm2015/table/table-module.js +9 -13
- package/esm2015/table/table.js +765 -785
- package/esm2015/table/text-column.js +85 -89
- package/esm2015/testing/component-harness.js +19 -1
- package/esm2015/testing/harness-environment.js +7 -1
- package/esm2015/text-field/autofill.js +89 -97
- package/esm2015/text-field/autosize.js +225 -229
- package/esm2015/text-field/text-field-module.js +10 -14
- package/esm2015/tree/control/nested-tree-control.js +7 -3
- package/esm2015/tree/nested-node.js +79 -83
- package/esm2015/tree/node.js +17 -21
- package/esm2015/tree/outlet.js +15 -19
- package/esm2015/tree/padding.js +88 -92
- package/esm2015/tree/toggle.js +32 -36
- package/esm2015/tree/tree-module.js +10 -14
- package/esm2015/tree/tree.js +266 -274
- package/esm2015/version.js +1 -1
- package/fesm2015/a11y.js +1021 -996
- package/fesm2015/a11y.js.map +1 -1
- package/fesm2015/accordion.js +173 -175
- package/fesm2015/accordion.js.map +1 -1
- package/fesm2015/bidi.js +74 -83
- package/fesm2015/bidi.js.map +1 -1
- package/fesm2015/cdk.js +1 -1
- package/fesm2015/cdk.js.map +1 -1
- package/fesm2015/clipboard.js +113 -122
- package/fesm2015/clipboard.js.map +1 -1
- package/fesm2015/collections.js +32 -35
- package/fesm2015/collections.js.map +1 -1
- package/fesm2015/drag-drop.js +1005 -961
- package/fesm2015/drag-drop.js.map +1 -1
- package/fesm2015/layout.js +111 -120
- package/fesm2015/layout.js.map +1 -1
- package/fesm2015/observers.js +146 -158
- package/fesm2015/observers.js.map +1 -1
- package/fesm2015/overlay.js +793 -659
- package/fesm2015/overlay.js.map +1 -1
- package/fesm2015/platform.js +52 -59
- package/fesm2015/platform.js.map +1 -1
- package/fesm2015/portal.js +180 -195
- package/fesm2015/portal.js.map +1 -1
- package/fesm2015/scrolling.js +1058 -1060
- package/fesm2015/scrolling.js.map +1 -1
- package/fesm2015/stepper.js +424 -445
- package/fesm2015/stepper.js.map +1 -1
- package/fesm2015/table.js +1178 -1247
- package/fesm2015/table.js.map +1 -1
- package/fesm2015/testing.js +25 -1
- package/fesm2015/testing.js.map +1 -1
- package/fesm2015/text-field.js +318 -330
- package/fesm2015/text-field.js.map +1 -1
- package/fesm2015/tree.js +517 -537
- package/fesm2015/tree.js.map +1 -1
- package/overlay/dispatchers/base-overlay-dispatcher.d.ts +28 -0
- package/overlay/dispatchers/index.d.ts +9 -0
- package/overlay/{keyboard → dispatchers}/overlay-keyboard-dispatcher.d.ts +4 -10
- package/overlay/dispatchers/overlay-outside-click-dispatcher.d.ts +27 -0
- package/overlay/index.d.ts +4 -3
- package/overlay/index.metadata.json +1 -1
- package/overlay/overlay-config.d.ts +4 -0
- package/overlay/overlay-directives.d.ts +4 -0
- package/overlay/overlay-ref.d.ts +8 -2
- package/overlay/overlay-reference.d.ts +1 -0
- package/overlay/overlay.d.ts +4 -2
- package/overlay/public-api.d.ts +1 -1
- package/package.json +3 -3
- package/schematics/index.js +1 -1
- package/schematics/migration.json +5 -0
- package/schematics/ng-add/index.js +1 -1
- package/schematics/ng-update/data/index.js +1 -1
- package/schematics/ng-update/devkit-file-system.d.ts +5 -5
- package/schematics/ng-update/devkit-file-system.js +21 -16
- package/schematics/ng-update/devkit-migration-rule.js +13 -20
- package/schematics/ng-update/devkit-migration.d.ts +0 -2
- package/schematics/ng-update/devkit-migration.js +1 -1
- package/schematics/ng-update/find-stylesheets.d.ts +10 -0
- package/schematics/ng-update/find-stylesheets.js +31 -0
- package/schematics/ng-update/index.d.ts +2 -0
- package/schematics/ng-update/index.js +7 -2
- package/schematics/ng-update/migrations/attribute-selectors.js +3 -3
- package/schematics/ng-update/migrations/css-selectors.js +3 -3
- package/schematics/ng-update/migrations/element-selectors.js +3 -3
- package/schematics/ng-update/public-api.js +1 -1
- package/schematics/update-tool/component-resource-collector.d.ts +1 -1
- package/schematics/update-tool/component-resource-collector.js +18 -14
- package/schematics/update-tool/file-system.d.ts +19 -14
- package/schematics/update-tool/file-system.js +1 -1
- package/schematics/update-tool/index.d.ts +21 -3
- package/schematics/update-tool/index.js +29 -23
- package/schematics/update-tool/public-api.js +1 -1
- package/schematics/update-tool/target-version.d.ts +2 -1
- package/schematics/update-tool/target-version.js +5 -3
- package/schematics/update-tool/utils/parse-tsconfig.d.ts +2 -1
- package/schematics/update-tool/utils/parse-tsconfig.js +6 -10
- package/schematics/update-tool/utils/virtual-host.d.ts +34 -0
- package/schematics/update-tool/utils/virtual-host.js +62 -0
- package/schematics/update-tool/version-changes.js +4 -6
- package/schematics/utils/index.js +1 -1
- package/schematics/utils/project-tsconfig-paths.d.ts +2 -1
- package/schematics/utils/project-tsconfig-paths.js +1 -1
- package/scrolling/index.metadata.json +1 -1
- package/scrolling/public-api.d.ts +1 -0
- package/scrolling/virtual-for-of.d.ts +2 -1
- package/scrolling/virtual-scroll-repeater.d.ts +16 -0
- package/scrolling/virtual-scroll-viewport.d.ts +4 -4
- package/testing/component-harness.d.ts +12 -0
- package/testing/harness-environment.d.ts +1 -0
- package/tree/control/nested-tree-control.d.ts +7 -2
- package/tree/index.metadata.json +1 -1
- package/esm2015/overlay/keyboard/overlay-keyboard-dispatcher.js +0 -100
package/fesm2015/drag-drop.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ɵɵdefineInjectable, ɵɵinject, NgZone, Injectable, Inject, InjectionToken, Directive, ElementRef, Optional,
|
|
1
|
+
import { ɵɵdefineInjectable, ɵɵinject, NgZone, Injectable, Inject, InjectionToken, Directive, Input, EventEmitter, ElementRef, ChangeDetectorRef, Optional, SkipSelf, Output, TemplateRef, isDevMode, ViewContainerRef, Self, ContentChildren, ContentChild, NgModule } from '@angular/core';
|
|
2
2
|
import { DOCUMENT } from '@angular/common';
|
|
3
3
|
import { ViewportRuler, ScrollDispatcher, CdkScrollableModule } from '@angular/cdk/scrolling';
|
|
4
4
|
import { normalizePassiveListenerOptions, _getShadowRoot } from '@angular/cdk/platform';
|
|
5
|
-
import { coerceBooleanProperty, coerceElement,
|
|
5
|
+
import { coerceBooleanProperty, coerceElement, coerceArray, coerceNumberProperty } from '@angular/cdk/coercion';
|
|
6
6
|
import { Subject, Subscription, interval, animationFrameScheduler, Observable, merge } from 'rxjs';
|
|
7
|
-
import { takeUntil, map, take,
|
|
7
|
+
import { takeUntil, startWith, map, take, tap, switchMap } from 'rxjs/operators';
|
|
8
8
|
import { Directionality } from '@angular/cdk/bidi';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -350,9 +350,10 @@ class DragRef {
|
|
|
350
350
|
}
|
|
351
351
|
const constrainedPointerPosition = this._getConstrainedPointerPosition(pointerPosition);
|
|
352
352
|
this._hasMoved = true;
|
|
353
|
+
this._lastKnownPointerPosition = pointerPosition;
|
|
353
354
|
this._updatePointerDirectionDelta(constrainedPointerPosition);
|
|
354
355
|
if (this._dropContainer) {
|
|
355
|
-
this._updateActiveDropContainer(constrainedPointerPosition);
|
|
356
|
+
this._updateActiveDropContainer(constrainedPointerPosition, pointerPosition);
|
|
356
357
|
}
|
|
357
358
|
else {
|
|
358
359
|
const activeTransform = this._activeTransform;
|
|
@@ -460,6 +461,9 @@ class DragRef {
|
|
|
460
461
|
this._initialTransform = undefined;
|
|
461
462
|
this._rootElement = element;
|
|
462
463
|
}
|
|
464
|
+
if (typeof SVGElement !== 'undefined' && this._rootElement instanceof SVGElement) {
|
|
465
|
+
this._ownerSVGElement = this._rootElement.ownerSVGElement;
|
|
466
|
+
}
|
|
463
467
|
return this;
|
|
464
468
|
}
|
|
465
469
|
/**
|
|
@@ -503,7 +507,7 @@ class DragRef {
|
|
|
503
507
|
this._dropContainer = undefined;
|
|
504
508
|
this._resizeSubscription.unsubscribe();
|
|
505
509
|
this._parentPositions.clear();
|
|
506
|
-
this._boundaryElement = this._rootElement = this._placeholderTemplate =
|
|
510
|
+
this._boundaryElement = this._rootElement = this._ownerSVGElement = this._placeholderTemplate =
|
|
507
511
|
this._previewTemplate = this._anchor = null;
|
|
508
512
|
}
|
|
509
513
|
/** Checks whether the element is currently being dragged. */
|
|
@@ -563,9 +567,9 @@ class DragRef {
|
|
|
563
567
|
}
|
|
564
568
|
/** Updates the item's sort order based on the last-known pointer position. */
|
|
565
569
|
_sortFromLastPointerPosition() {
|
|
566
|
-
const position = this.
|
|
570
|
+
const position = this._lastKnownPointerPosition;
|
|
567
571
|
if (position && this._dropContainer) {
|
|
568
|
-
this._updateActiveDropContainer(this._getConstrainedPointerPosition(position));
|
|
572
|
+
this._updateActiveDropContainer(this._getConstrainedPointerPosition(position), position);
|
|
569
573
|
}
|
|
570
574
|
}
|
|
571
575
|
/** Unsubscribes from the global subscriptions. */
|
|
@@ -643,8 +647,6 @@ class DragRef {
|
|
|
643
647
|
}
|
|
644
648
|
/** Starts the dragging sequence. */
|
|
645
649
|
_startDragSequence(event) {
|
|
646
|
-
// Emit the event on the item before the one on the container.
|
|
647
|
-
this.started.next({ source: this });
|
|
648
650
|
if (isTouchEvent(event)) {
|
|
649
651
|
this._lastTouchEventTime = Date.now();
|
|
650
652
|
}
|
|
@@ -664,11 +666,13 @@ class DragRef {
|
|
|
664
666
|
element.style.display = 'none';
|
|
665
667
|
this._document.body.appendChild(parent.replaceChild(placeholder, element));
|
|
666
668
|
getPreviewInsertionPoint(this._document).appendChild(preview);
|
|
669
|
+
this.started.next({ source: this }); // Emit before notifying the container.
|
|
667
670
|
dropContainer.start();
|
|
668
671
|
this._initialContainer = dropContainer;
|
|
669
672
|
this._initialIndex = dropContainer.getItemIndex(this);
|
|
670
673
|
}
|
|
671
674
|
else {
|
|
675
|
+
this.started.next({ source: this });
|
|
672
676
|
this._initialContainer = this._initialIndex = undefined;
|
|
673
677
|
}
|
|
674
678
|
// Important to run after we've called `start` on the parent container
|
|
@@ -731,7 +735,8 @@ class DragRef {
|
|
|
731
735
|
this._pickupPositionInElement = previewTemplate && previewTemplate.template &&
|
|
732
736
|
!previewTemplate.matchSize ? { x: 0, y: 0 } :
|
|
733
737
|
this._getPointerPositionInElement(referenceElement, event);
|
|
734
|
-
const pointerPosition = this._pickupPositionOnPage = this.
|
|
738
|
+
const pointerPosition = this._pickupPositionOnPage = this._lastKnownPointerPosition =
|
|
739
|
+
this._getPointerPositionOnPage(event);
|
|
735
740
|
this._pointerDirectionDelta = { x: 0, y: 0 };
|
|
736
741
|
this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
|
|
737
742
|
this._dragStartTime = Date.now();
|
|
@@ -773,7 +778,7 @@ class DragRef {
|
|
|
773
778
|
* Updates the item's position in its drop container, or moves it
|
|
774
779
|
* into a new one, depending on its current drag position.
|
|
775
780
|
*/
|
|
776
|
-
_updateActiveDropContainer({ x, y }) {
|
|
781
|
+
_updateActiveDropContainer({ x, y }, { x: rawX, y: rawY }) {
|
|
777
782
|
// Drop container that draggable has been moved into.
|
|
778
783
|
let newContainer = this._initialContainer._getSiblingContainerFromPosition(this, x, y);
|
|
779
784
|
// If we couldn't find a new container to move the item into, and the item has left its
|
|
@@ -802,7 +807,7 @@ class DragRef {
|
|
|
802
807
|
});
|
|
803
808
|
});
|
|
804
809
|
}
|
|
805
|
-
this._dropContainer._startScrollingIfNecessary(
|
|
810
|
+
this._dropContainer._startScrollingIfNecessary(rawX, rawY);
|
|
806
811
|
this._dropContainer._sortItem(this, x, y, this._pointerDirectionDelta);
|
|
807
812
|
this._preview.style.transform =
|
|
808
813
|
getTransform(x - this._pickupPositionInElement.x, y - this._pickupPositionInElement.y);
|
|
@@ -946,20 +951,30 @@ class DragRef {
|
|
|
946
951
|
// breaks inside a developer tool and the value is only used for secondary information,
|
|
947
952
|
// we can get away with it. See https://bugzilla.mozilla.org/show_bug.cgi?id=1615824.
|
|
948
953
|
(event.touches[0] || event.changedTouches[0] || { pageX: 0, pageY: 0 }) : event;
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
954
|
+
const x = point.pageX - scrollPosition.left;
|
|
955
|
+
const y = point.pageY - scrollPosition.top;
|
|
956
|
+
// if dragging SVG element, try to convert from the screen coordinate system to the SVG
|
|
957
|
+
// coordinate system
|
|
958
|
+
if (this._ownerSVGElement) {
|
|
959
|
+
const svgMatrix = this._ownerSVGElement.getScreenCTM();
|
|
960
|
+
if (svgMatrix) {
|
|
961
|
+
const svgPoint = this._ownerSVGElement.createSVGPoint();
|
|
962
|
+
svgPoint.x = x;
|
|
963
|
+
svgPoint.y = y;
|
|
964
|
+
return svgPoint.matrixTransform(svgMatrix.inverse());
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return { x, y };
|
|
953
968
|
}
|
|
954
969
|
/** Gets the pointer position on the page, accounting for any position constraints. */
|
|
955
970
|
_getConstrainedPointerPosition(point) {
|
|
956
|
-
const constrainedPoint = this.constrainPosition ? this.constrainPosition(point, this) : point;
|
|
957
971
|
const dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
|
|
972
|
+
let { x, y } = this.constrainPosition ? this.constrainPosition(point, this) : point;
|
|
958
973
|
if (this.lockAxis === 'x' || dropContainerLock === 'x') {
|
|
959
|
-
|
|
974
|
+
y = this._pickupPositionOnPage.y;
|
|
960
975
|
}
|
|
961
976
|
else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
|
|
962
|
-
|
|
977
|
+
x = this._pickupPositionOnPage.x;
|
|
963
978
|
}
|
|
964
979
|
if (this._boundaryRect) {
|
|
965
980
|
const { x: pickupX, y: pickupY } = this._pickupPositionInElement;
|
|
@@ -969,10 +984,10 @@ class DragRef {
|
|
|
969
984
|
const maxY = boundaryRect.bottom - (previewRect.height - pickupY);
|
|
970
985
|
const minX = boundaryRect.left + pickupX;
|
|
971
986
|
const maxX = boundaryRect.right - (previewRect.width - pickupX);
|
|
972
|
-
|
|
973
|
-
|
|
987
|
+
x = clamp(x, minX, maxX);
|
|
988
|
+
y = clamp(y, minY, maxY);
|
|
974
989
|
}
|
|
975
|
-
return
|
|
990
|
+
return { x, y };
|
|
976
991
|
}
|
|
977
992
|
/** Updates the current drag delta, based on the user's current pointer position on the page. */
|
|
978
993
|
_updatePointerDirectionDelta(pointerPositionOnPage) {
|
|
@@ -1111,10 +1126,24 @@ class DragRef {
|
|
|
1111
1126
|
/** Updates the internal state of the draggable element when scrolling has occurred. */
|
|
1112
1127
|
_updateOnScroll(event) {
|
|
1113
1128
|
const scrollDifference = this._parentPositions.handleScroll(event);
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1129
|
+
if (scrollDifference) {
|
|
1130
|
+
const target = event.target;
|
|
1131
|
+
// ClientRect dimensions are based on the scroll position of the page and its parent node so
|
|
1132
|
+
// we have to update the cached boundary ClientRect if the user has scrolled. Check for
|
|
1133
|
+
// the `document` specifically since IE doesn't support `contains` on it.
|
|
1134
|
+
if (this._boundaryRect && (target === this._document ||
|
|
1135
|
+
(target !== this._boundaryElement && target.contains(this._boundaryElement)))) {
|
|
1136
|
+
adjustClientRect(this._boundaryRect, scrollDifference.top, scrollDifference.left);
|
|
1137
|
+
}
|
|
1138
|
+
this._pickupPositionOnPage.x += scrollDifference.left;
|
|
1139
|
+
this._pickupPositionOnPage.y += scrollDifference.top;
|
|
1140
|
+
// If we're in free drag mode, we have to update the active transform, because
|
|
1141
|
+
// it isn't relative to the viewport like the preview inside a drop list.
|
|
1142
|
+
if (!this._dropContainer) {
|
|
1143
|
+
this._activeTransform.x -= scrollDifference.left;
|
|
1144
|
+
this._activeTransform.y -= scrollDifference.top;
|
|
1145
|
+
this._applyRootElementTransform(this._activeTransform.x, this._activeTransform.y);
|
|
1146
|
+
}
|
|
1118
1147
|
}
|
|
1119
1148
|
}
|
|
1120
1149
|
/** Gets the scroll position of the viewport. */
|
|
@@ -1151,7 +1180,12 @@ function deepCloneNode(node) {
|
|
|
1151
1180
|
for (let i = 0; i < descendantCanvases.length; i++) {
|
|
1152
1181
|
const correspondingCloneContext = cloneCanvases[i].getContext('2d');
|
|
1153
1182
|
if (correspondingCloneContext) {
|
|
1154
|
-
|
|
1183
|
+
// In some cases `drawImage` can throw (e.g. if the canvas size is 0x0).
|
|
1184
|
+
// We can't do much about it so just ignore the error.
|
|
1185
|
+
try {
|
|
1186
|
+
correspondingCloneContext.drawImage(descendantCanvases[i], 0, 0);
|
|
1187
|
+
}
|
|
1188
|
+
catch (_a) { }
|
|
1155
1189
|
}
|
|
1156
1190
|
}
|
|
1157
1191
|
}
|
|
@@ -1336,10 +1370,11 @@ class DropListRef {
|
|
|
1336
1370
|
/** Cache of the dimensions of all the items inside the container. */
|
|
1337
1371
|
this._itemPositions = [];
|
|
1338
1372
|
/**
|
|
1339
|
-
* Keeps track of the item that was last swapped with the dragged item, as
|
|
1340
|
-
*
|
|
1373
|
+
* Keeps track of the item that was last swapped with the dragged item, as well as what direction
|
|
1374
|
+
* the pointer was moving in when the swap occured and whether the user's pointer continued to
|
|
1375
|
+
* overlap with the swapped item after the swapping occurred.
|
|
1341
1376
|
*/
|
|
1342
|
-
this._previousSwap = { drag: null, delta: 0 };
|
|
1377
|
+
this._previousSwap = { drag: null, delta: 0, overlaps: false };
|
|
1343
1378
|
/** Drop lists that are connected to the current one. */
|
|
1344
1379
|
this._siblings = [];
|
|
1345
1380
|
/** Direction in which the list is oriented. */
|
|
@@ -1622,8 +1657,6 @@ class DropListRef {
|
|
|
1622
1657
|
const currentPosition = siblings[currentIndex].clientRect;
|
|
1623
1658
|
const newPosition = siblingAtNewPosition.clientRect;
|
|
1624
1659
|
const delta = currentIndex > newIndex ? 1 : -1;
|
|
1625
|
-
this._previousSwap.drag = siblingAtNewPosition.drag;
|
|
1626
|
-
this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
|
|
1627
1660
|
// How many pixels the item's placeholder should be offset.
|
|
1628
1661
|
const itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
|
|
1629
1662
|
// How many pixels all the other items should be offset.
|
|
@@ -1665,6 +1698,10 @@ class DropListRef {
|
|
|
1665
1698
|
adjustClientRect(sibling.clientRect, offset, 0);
|
|
1666
1699
|
}
|
|
1667
1700
|
});
|
|
1701
|
+
// Note that it's important that we do this after the client rects have been adjusted.
|
|
1702
|
+
this._previousSwap.overlaps = isInsideClientRect(newPosition, pointerX, pointerY);
|
|
1703
|
+
this._previousSwap.drag = siblingAtNewPosition.drag;
|
|
1704
|
+
this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
|
|
1668
1705
|
}
|
|
1669
1706
|
/**
|
|
1670
1707
|
* Checks whether the user's pointer is close to the edges of either the
|
|
@@ -1755,6 +1792,7 @@ class DropListRef {
|
|
|
1755
1792
|
this._itemPositions = [];
|
|
1756
1793
|
this._previousSwap.drag = null;
|
|
1757
1794
|
this._previousSwap.delta = 0;
|
|
1795
|
+
this._previousSwap.overlaps = false;
|
|
1758
1796
|
this._stopScrolling();
|
|
1759
1797
|
this._viewportScrollSubscription.unsubscribe();
|
|
1760
1798
|
this._parentPositions.clear();
|
|
@@ -1843,9 +1881,11 @@ class DropListRef {
|
|
|
1843
1881
|
}
|
|
1844
1882
|
if (delta) {
|
|
1845
1883
|
const direction = isHorizontal ? delta.x : delta.y;
|
|
1846
|
-
// If the user is still hovering over the same item as last time,
|
|
1847
|
-
// the
|
|
1848
|
-
|
|
1884
|
+
// If the user is still hovering over the same item as last time, their cursor hasn't left
|
|
1885
|
+
// the item after we made the swap, and they didn't change the direction in which they're
|
|
1886
|
+
// dragging, we don't consider it a direction swap.
|
|
1887
|
+
if (drag === this._previousSwap.drag && this._previousSwap.overlaps &&
|
|
1888
|
+
direction === this._previousSwap.delta) {
|
|
1849
1889
|
return false;
|
|
1850
1890
|
}
|
|
1851
1891
|
}
|
|
@@ -2107,157 +2147,154 @@ const activeCapturingEventOptions = normalizePassiveListenerOptions({
|
|
|
2107
2147
|
// Note: this class is generic, rather than referencing CdkDrag and CdkDropList directly, in order
|
|
2108
2148
|
// to avoid circular imports. If we were to reference them here, importing the registry into the
|
|
2109
2149
|
// classes that are registering themselves will introduce a circular import.
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
this.
|
|
2139
|
-
|
|
2140
|
-
event.preventDefault();
|
|
2141
|
-
}
|
|
2142
|
-
};
|
|
2143
|
-
this._document = _document;
|
|
2144
|
-
}
|
|
2145
|
-
/** Adds a drop container to the registry. */
|
|
2146
|
-
registerDropContainer(drop) {
|
|
2147
|
-
if (!this._dropInstances.has(drop)) {
|
|
2148
|
-
this._dropInstances.add(drop);
|
|
2150
|
+
class DragDropRegistry {
|
|
2151
|
+
constructor(_ngZone, _document) {
|
|
2152
|
+
this._ngZone = _ngZone;
|
|
2153
|
+
/** Registered drop container instances. */
|
|
2154
|
+
this._dropInstances = new Set();
|
|
2155
|
+
/** Registered drag item instances. */
|
|
2156
|
+
this._dragInstances = new Set();
|
|
2157
|
+
/** Drag item instances that are currently being dragged. */
|
|
2158
|
+
this._activeDragInstances = new Set();
|
|
2159
|
+
/** Keeps track of the event listeners that we've bound to the `document`. */
|
|
2160
|
+
this._globalListeners = new Map();
|
|
2161
|
+
/**
|
|
2162
|
+
* Emits the `touchmove` or `mousemove` events that are dispatched
|
|
2163
|
+
* while the user is dragging a drag item instance.
|
|
2164
|
+
*/
|
|
2165
|
+
this.pointerMove = new Subject();
|
|
2166
|
+
/**
|
|
2167
|
+
* Emits the `touchend` or `mouseup` events that are dispatched
|
|
2168
|
+
* while the user is dragging a drag item instance.
|
|
2169
|
+
*/
|
|
2170
|
+
this.pointerUp = new Subject();
|
|
2171
|
+
/** Emits when the viewport has been scrolled while the user is dragging an item. */
|
|
2172
|
+
this.scroll = new Subject();
|
|
2173
|
+
/**
|
|
2174
|
+
* Event listener that will prevent the default browser action while the user is dragging.
|
|
2175
|
+
* @param event Event whose default action should be prevented.
|
|
2176
|
+
*/
|
|
2177
|
+
this._preventDefaultWhileDragging = (event) => {
|
|
2178
|
+
if (this._activeDragInstances.size) {
|
|
2179
|
+
event.preventDefault();
|
|
2149
2180
|
}
|
|
2181
|
+
};
|
|
2182
|
+
this._document = _document;
|
|
2183
|
+
}
|
|
2184
|
+
/** Adds a drop container to the registry. */
|
|
2185
|
+
registerDropContainer(drop) {
|
|
2186
|
+
if (!this._dropInstances.has(drop)) {
|
|
2187
|
+
this._dropInstances.add(drop);
|
|
2150
2188
|
}
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2189
|
+
}
|
|
2190
|
+
/** Adds a drag item instance to the registry. */
|
|
2191
|
+
registerDragItem(drag) {
|
|
2192
|
+
this._dragInstances.add(drag);
|
|
2193
|
+
// The `touchmove` event gets bound once, ahead of time, because WebKit
|
|
2194
|
+
// won't preventDefault on a dynamically-added `touchmove` listener.
|
|
2195
|
+
// See https://bugs.webkit.org/show_bug.cgi?id=184250.
|
|
2196
|
+
if (this._dragInstances.size === 1) {
|
|
2197
|
+
this._ngZone.runOutsideAngular(() => {
|
|
2198
|
+
// The event handler has to be explicitly active,
|
|
2199
|
+
// because newer browsers make it passive by default.
|
|
2200
|
+
this._document.addEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
|
|
2201
|
+
});
|
|
2164
2202
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2203
|
+
}
|
|
2204
|
+
/** Removes a drop container from the registry. */
|
|
2205
|
+
removeDropContainer(drop) {
|
|
2206
|
+
this._dropInstances.delete(drop);
|
|
2207
|
+
}
|
|
2208
|
+
/** Removes a drag item instance from the registry. */
|
|
2209
|
+
removeDragItem(drag) {
|
|
2210
|
+
this._dragInstances.delete(drag);
|
|
2211
|
+
this.stopDragging(drag);
|
|
2212
|
+
if (this._dragInstances.size === 0) {
|
|
2213
|
+
this._document.removeEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
|
|
2168
2214
|
}
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2215
|
+
}
|
|
2216
|
+
/**
|
|
2217
|
+
* Starts the dragging sequence for a drag instance.
|
|
2218
|
+
* @param drag Drag instance which is being dragged.
|
|
2219
|
+
* @param event Event that initiated the dragging.
|
|
2220
|
+
*/
|
|
2221
|
+
startDragging(drag, event) {
|
|
2222
|
+
// Do not process the same drag twice to avoid memory leaks and redundant listeners
|
|
2223
|
+
if (this._activeDragInstances.has(drag)) {
|
|
2224
|
+
return;
|
|
2176
2225
|
}
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
//
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
this.
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
// on Safari so we need to prevent the selection event as well. Alternatively this can
|
|
2212
|
-
// be done by setting `user-select: none` on the `body`, however it has causes a style
|
|
2213
|
-
// recalculation which can be expensive on pages with a lot of elements.
|
|
2214
|
-
.set('selectstart', {
|
|
2215
|
-
handler: this._preventDefaultWhileDragging,
|
|
2216
|
-
options: activeCapturingEventOptions
|
|
2217
|
-
});
|
|
2218
|
-
this._ngZone.runOutsideAngular(() => {
|
|
2219
|
-
this._globalListeners.forEach((config, name) => {
|
|
2220
|
-
this._document.addEventListener(name, config.handler, config.options);
|
|
2221
|
-
});
|
|
2226
|
+
this._activeDragInstances.add(drag);
|
|
2227
|
+
if (this._activeDragInstances.size === 1) {
|
|
2228
|
+
const isTouchEvent = event.type.startsWith('touch');
|
|
2229
|
+
const moveEvent = isTouchEvent ? 'touchmove' : 'mousemove';
|
|
2230
|
+
const upEvent = isTouchEvent ? 'touchend' : 'mouseup';
|
|
2231
|
+
// We explicitly bind __active__ listeners here, because newer browsers will default to
|
|
2232
|
+
// passive ones for `mousemove` and `touchmove`. The events need to be active, because we
|
|
2233
|
+
// use `preventDefault` to prevent the page from scrolling while the user is dragging.
|
|
2234
|
+
this._globalListeners
|
|
2235
|
+
.set(moveEvent, {
|
|
2236
|
+
handler: (e) => this.pointerMove.next(e),
|
|
2237
|
+
options: activeCapturingEventOptions
|
|
2238
|
+
})
|
|
2239
|
+
.set(upEvent, {
|
|
2240
|
+
handler: (e) => this.pointerUp.next(e),
|
|
2241
|
+
options: true
|
|
2242
|
+
})
|
|
2243
|
+
.set('scroll', {
|
|
2244
|
+
handler: (e) => this.scroll.next(e),
|
|
2245
|
+
// Use capturing so that we pick up scroll changes in any scrollable nodes that aren't
|
|
2246
|
+
// the document. See https://github.com/angular/components/issues/17144.
|
|
2247
|
+
options: true
|
|
2248
|
+
})
|
|
2249
|
+
// Preventing the default action on `mousemove` isn't enough to disable text selection
|
|
2250
|
+
// on Safari so we need to prevent the selection event as well. Alternatively this can
|
|
2251
|
+
// be done by setting `user-select: none` on the `body`, however it has causes a style
|
|
2252
|
+
// recalculation which can be expensive on pages with a lot of elements.
|
|
2253
|
+
.set('selectstart', {
|
|
2254
|
+
handler: this._preventDefaultWhileDragging,
|
|
2255
|
+
options: activeCapturingEventOptions
|
|
2256
|
+
});
|
|
2257
|
+
this._ngZone.runOutsideAngular(() => {
|
|
2258
|
+
this._globalListeners.forEach((config, name) => {
|
|
2259
|
+
this._document.addEventListener(name, config.handler, config.options);
|
|
2222
2260
|
});
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
/** Stops dragging a drag item instance. */
|
|
2226
|
-
stopDragging(drag) {
|
|
2227
|
-
this._activeDragInstances.delete(drag);
|
|
2228
|
-
if (this._activeDragInstances.size === 0) {
|
|
2229
|
-
this._clearGlobalListeners();
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
/** Gets whether a drag item instance is currently being dragged. */
|
|
2233
|
-
isDragging(drag) {
|
|
2234
|
-
return this._activeDragInstances.has(drag);
|
|
2261
|
+
});
|
|
2235
2262
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2263
|
+
}
|
|
2264
|
+
/** Stops dragging a drag item instance. */
|
|
2265
|
+
stopDragging(drag) {
|
|
2266
|
+
this._activeDragInstances.delete(drag);
|
|
2267
|
+
if (this._activeDragInstances.size === 0) {
|
|
2239
2268
|
this._clearGlobalListeners();
|
|
2240
|
-
this.pointerMove.complete();
|
|
2241
|
-
this.pointerUp.complete();
|
|
2242
2269
|
}
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2270
|
+
}
|
|
2271
|
+
/** Gets whether a drag item instance is currently being dragged. */
|
|
2272
|
+
isDragging(drag) {
|
|
2273
|
+
return this._activeDragInstances.has(drag);
|
|
2274
|
+
}
|
|
2275
|
+
ngOnDestroy() {
|
|
2276
|
+
this._dragInstances.forEach(instance => this.removeDragItem(instance));
|
|
2277
|
+
this._dropInstances.forEach(instance => this.removeDropContainer(instance));
|
|
2278
|
+
this._clearGlobalListeners();
|
|
2279
|
+
this.pointerMove.complete();
|
|
2280
|
+
this.pointerUp.complete();
|
|
2281
|
+
}
|
|
2282
|
+
/** Clears out the global event listeners from the `document`. */
|
|
2283
|
+
_clearGlobalListeners() {
|
|
2284
|
+
this._globalListeners.forEach((config, name) => {
|
|
2285
|
+
this._document.removeEventListener(name, config.handler, config.options);
|
|
2286
|
+
});
|
|
2287
|
+
this._globalListeners.clear();
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
DragDropRegistry.ɵprov = ɵɵdefineInjectable({ factory: function DragDropRegistry_Factory() { return new DragDropRegistry(ɵɵinject(NgZone), ɵɵinject(DOCUMENT)); }, token: DragDropRegistry, providedIn: "root" });
|
|
2291
|
+
DragDropRegistry.decorators = [
|
|
2292
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
2293
|
+
];
|
|
2294
|
+
DragDropRegistry.ctorParameters = () => [
|
|
2295
|
+
{ type: NgZone },
|
|
2296
|
+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
|
2297
|
+
];
|
|
2261
2298
|
|
|
2262
2299
|
/**
|
|
2263
2300
|
* @license
|
|
@@ -2274,42 +2311,39 @@ const DEFAULT_CONFIG = {
|
|
|
2274
2311
|
/**
|
|
2275
2312
|
* Service that allows for drag-and-drop functionality to be attached to DOM elements.
|
|
2276
2313
|
*/
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
];
|
|
2311
|
-
return DragDrop;
|
|
2312
|
-
})();
|
|
2314
|
+
class DragDrop {
|
|
2315
|
+
constructor(_document, _ngZone, _viewportRuler, _dragDropRegistry) {
|
|
2316
|
+
this._document = _document;
|
|
2317
|
+
this._ngZone = _ngZone;
|
|
2318
|
+
this._viewportRuler = _viewportRuler;
|
|
2319
|
+
this._dragDropRegistry = _dragDropRegistry;
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Turns an element into a draggable item.
|
|
2323
|
+
* @param element Element to which to attach the dragging functionality.
|
|
2324
|
+
* @param config Object used to configure the dragging behavior.
|
|
2325
|
+
*/
|
|
2326
|
+
createDrag(element, config = DEFAULT_CONFIG) {
|
|
2327
|
+
return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Turns an element into a drop list.
|
|
2331
|
+
* @param element Element to which to attach the drop list functionality.
|
|
2332
|
+
*/
|
|
2333
|
+
createDropList(element) {
|
|
2334
|
+
return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
DragDrop.ɵprov = ɵɵdefineInjectable({ factory: function DragDrop_Factory() { return new DragDrop(ɵɵinject(DOCUMENT), ɵɵinject(NgZone), ɵɵinject(ViewportRuler), ɵɵinject(DragDropRegistry)); }, token: DragDrop, providedIn: "root" });
|
|
2338
|
+
DragDrop.decorators = [
|
|
2339
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
2340
|
+
];
|
|
2341
|
+
DragDrop.ctorParameters = () => [
|
|
2342
|
+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
2343
|
+
{ type: NgZone },
|
|
2344
|
+
{ type: ViewportRuler },
|
|
2345
|
+
{ type: DragDropRegistry }
|
|
2346
|
+
];
|
|
2313
2347
|
|
|
2314
2348
|
/**
|
|
2315
2349
|
* @license
|
|
@@ -2327,12 +2361,42 @@ let DragDrop = /** @class */ (() => {
|
|
|
2327
2361
|
* found in the LICENSE file at https://angular.io/license
|
|
2328
2362
|
*/
|
|
2329
2363
|
/**
|
|
2330
|
-
* Injection token that can be used
|
|
2331
|
-
*
|
|
2332
|
-
*
|
|
2333
|
-
* @docs-private
|
|
2364
|
+
* Injection token that can be used to reference instances of `CdkDropListGroup`. It serves as
|
|
2365
|
+
* alternative token to the actual `CdkDropListGroup` class which could cause unnecessary
|
|
2366
|
+
* retention of the class and its directive metadata.
|
|
2334
2367
|
*/
|
|
2335
|
-
const
|
|
2368
|
+
const CDK_DROP_LIST_GROUP = new InjectionToken('CdkDropListGroup');
|
|
2369
|
+
/**
|
|
2370
|
+
* Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
|
|
2371
|
+
* elements that are placed inside a `cdkDropListGroup` will be connected to each other
|
|
2372
|
+
* automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
|
|
2373
|
+
* from `cdkDropList`.
|
|
2374
|
+
*/
|
|
2375
|
+
class CdkDropListGroup {
|
|
2376
|
+
constructor() {
|
|
2377
|
+
/** Drop lists registered inside the group. */
|
|
2378
|
+
this._items = new Set();
|
|
2379
|
+
this._disabled = false;
|
|
2380
|
+
}
|
|
2381
|
+
/** Whether starting a dragging sequence from inside this group is disabled. */
|
|
2382
|
+
get disabled() { return this._disabled; }
|
|
2383
|
+
set disabled(value) {
|
|
2384
|
+
this._disabled = coerceBooleanProperty(value);
|
|
2385
|
+
}
|
|
2386
|
+
ngOnDestroy() {
|
|
2387
|
+
this._items.clear();
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
CdkDropListGroup.decorators = [
|
|
2391
|
+
{ type: Directive, args: [{
|
|
2392
|
+
selector: '[cdkDropListGroup]',
|
|
2393
|
+
exportAs: 'cdkDropListGroup',
|
|
2394
|
+
providers: [{ provide: CDK_DROP_LIST_GROUP, useExisting: CdkDropListGroup }],
|
|
2395
|
+
},] }
|
|
2396
|
+
];
|
|
2397
|
+
CdkDropListGroup.propDecorators = {
|
|
2398
|
+
disabled: [{ type: Input, args: ['cdkDropListGroupDisabled',] }]
|
|
2399
|
+
};
|
|
2336
2400
|
|
|
2337
2401
|
/**
|
|
2338
2402
|
* @license
|
|
@@ -2341,44 +2405,11 @@ const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
|
|
|
2341
2405
|
* Use of this source code is governed by an MIT-style license that can be
|
|
2342
2406
|
* found in the LICENSE file at https://angular.io/license
|
|
2343
2407
|
*/
|
|
2344
|
-
/**
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
/** Emits when the state of the handle has changed. */
|
|
2350
|
-
this._stateChanges = new Subject();
|
|
2351
|
-
this._disabled = false;
|
|
2352
|
-
this._parentDrag = parentDrag;
|
|
2353
|
-
toggleNativeDragInteractions(element.nativeElement, false);
|
|
2354
|
-
}
|
|
2355
|
-
/** Whether starting to drag through this handle is disabled. */
|
|
2356
|
-
get disabled() { return this._disabled; }
|
|
2357
|
-
set disabled(value) {
|
|
2358
|
-
this._disabled = coerceBooleanProperty(value);
|
|
2359
|
-
this._stateChanges.next(this);
|
|
2360
|
-
}
|
|
2361
|
-
ngOnDestroy() {
|
|
2362
|
-
this._stateChanges.complete();
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
CdkDragHandle.decorators = [
|
|
2366
|
-
{ type: Directive, args: [{
|
|
2367
|
-
selector: '[cdkDragHandle]',
|
|
2368
|
-
host: {
|
|
2369
|
-
'class': 'cdk-drag-handle'
|
|
2370
|
-
}
|
|
2371
|
-
},] }
|
|
2372
|
-
];
|
|
2373
|
-
CdkDragHandle.ctorParameters = () => [
|
|
2374
|
-
{ type: ElementRef },
|
|
2375
|
-
{ type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_PARENT,] }, { type: Optional }] }
|
|
2376
|
-
];
|
|
2377
|
-
CdkDragHandle.propDecorators = {
|
|
2378
|
-
disabled: [{ type: Input, args: ['cdkDragHandleDisabled',] }]
|
|
2379
|
-
};
|
|
2380
|
-
return CdkDragHandle;
|
|
2381
|
-
})();
|
|
2408
|
+
/**
|
|
2409
|
+
* Injection token that can be used to configure the
|
|
2410
|
+
* behavior of the drag&drop-related components.
|
|
2411
|
+
*/
|
|
2412
|
+
const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG');
|
|
2382
2413
|
|
|
2383
2414
|
/**
|
|
2384
2415
|
* @license
|
|
@@ -2387,29 +2418,275 @@ let CdkDragHandle = /** @class */ (() => {
|
|
|
2387
2418
|
* Use of this source code is governed by an MIT-style license that can be
|
|
2388
2419
|
* found in the LICENSE file at https://angular.io/license
|
|
2389
2420
|
*/
|
|
2421
|
+
/** Counter used to generate unique ids for drop zones. */
|
|
2422
|
+
let _uniqueIdCounter = 0;
|
|
2390
2423
|
/**
|
|
2391
|
-
*
|
|
2392
|
-
*
|
|
2424
|
+
* Injection token that can be used to reference instances of `CdkDropList`. It serves as
|
|
2425
|
+
* alternative token to the actual `CdkDropList` class which could cause unnecessary
|
|
2426
|
+
* retention of the class and its directive metadata.
|
|
2393
2427
|
*/
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2428
|
+
const CDK_DROP_LIST = new InjectionToken('CdkDropList');
|
|
2429
|
+
const ɵ0 = undefined;
|
|
2430
|
+
/** Container that wraps a set of draggable items. */
|
|
2431
|
+
class CdkDropList {
|
|
2432
|
+
constructor(
|
|
2433
|
+
/** Element that the drop list is attached to. */
|
|
2434
|
+
element, dragDrop, _changeDetectorRef, _dir, _group,
|
|
2435
|
+
/**
|
|
2436
|
+
* @deprecated _scrollDispatcher parameter to become required.
|
|
2437
|
+
* @breaking-change 11.0.0
|
|
2438
|
+
*/
|
|
2439
|
+
_scrollDispatcher, config) {
|
|
2440
|
+
this.element = element;
|
|
2441
|
+
this._changeDetectorRef = _changeDetectorRef;
|
|
2442
|
+
this._dir = _dir;
|
|
2443
|
+
this._group = _group;
|
|
2444
|
+
this._scrollDispatcher = _scrollDispatcher;
|
|
2445
|
+
/** Emits when the list has been destroyed. */
|
|
2446
|
+
this._destroyed = new Subject();
|
|
2447
|
+
/**
|
|
2448
|
+
* Other draggable containers that this container is connected to and into which the
|
|
2449
|
+
* container's items can be transferred. Can either be references to other drop containers,
|
|
2450
|
+
* or their unique IDs.
|
|
2451
|
+
*/
|
|
2452
|
+
this.connectedTo = [];
|
|
2453
|
+
/**
|
|
2454
|
+
* Unique ID for the drop zone. Can be used as a reference
|
|
2455
|
+
* in the `connectedTo` of another `CdkDropList`.
|
|
2456
|
+
*/
|
|
2457
|
+
this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
|
|
2458
|
+
/**
|
|
2459
|
+
* Function that is used to determine whether an item
|
|
2460
|
+
* is allowed to be moved into a drop container.
|
|
2461
|
+
*/
|
|
2462
|
+
this.enterPredicate = () => true;
|
|
2463
|
+
/** Emits when the user drops an item inside the container. */
|
|
2464
|
+
this.dropped = new EventEmitter();
|
|
2465
|
+
/**
|
|
2466
|
+
* Emits when the user has moved a new drag item into this container.
|
|
2467
|
+
*/
|
|
2468
|
+
this.entered = new EventEmitter();
|
|
2469
|
+
/**
|
|
2470
|
+
* Emits when the user removes an item from the container
|
|
2471
|
+
* by dragging it into another container.
|
|
2472
|
+
*/
|
|
2473
|
+
this.exited = new EventEmitter();
|
|
2474
|
+
/** Emits as the user is swapping items while actively dragging. */
|
|
2475
|
+
this.sorted = new EventEmitter();
|
|
2476
|
+
/**
|
|
2477
|
+
* Keeps track of the items that are registered with this container. Historically we used to
|
|
2478
|
+
* do this with a `ContentChildren` query, however queries don't handle transplanted views very
|
|
2479
|
+
* well which means that we can't handle cases like dragging the headers of a `mat-table`
|
|
2480
|
+
* correctly. What we do instead is to have the items register themselves with the container
|
|
2481
|
+
* and then we sort them based on their position in the DOM.
|
|
2482
|
+
*/
|
|
2483
|
+
this._unsortedItems = new Set();
|
|
2484
|
+
this._dropListRef = dragDrop.createDropList(element);
|
|
2485
|
+
this._dropListRef.data = this;
|
|
2486
|
+
if (config) {
|
|
2487
|
+
this._assignDefaults(config);
|
|
2488
|
+
}
|
|
2489
|
+
this._dropListRef.enterPredicate = (drag, drop) => {
|
|
2490
|
+
return this.enterPredicate(drag.data, drop.data);
|
|
2491
|
+
};
|
|
2492
|
+
this._setupInputSyncSubscription(this._dropListRef);
|
|
2493
|
+
this._handleEvents(this._dropListRef);
|
|
2494
|
+
CdkDropList._dropLists.push(this);
|
|
2495
|
+
if (_group) {
|
|
2496
|
+
_group._items.add(this);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
/** Whether starting a dragging sequence from this container is disabled. */
|
|
2500
|
+
get disabled() {
|
|
2501
|
+
return this._disabled || (!!this._group && this._group.disabled);
|
|
2502
|
+
}
|
|
2503
|
+
set disabled(value) {
|
|
2504
|
+
// Usually we sync the directive and ref state right before dragging starts, in order to have
|
|
2505
|
+
// a single point of failure and to avoid having to use setters for everything. `disabled` is
|
|
2506
|
+
// a special case, because it can prevent the `beforeStarted` event from firing, which can lock
|
|
2507
|
+
// the user in a disabled state, so we also need to sync it as it's being set.
|
|
2508
|
+
this._dropListRef.disabled = this._disabled = coerceBooleanProperty(value);
|
|
2509
|
+
}
|
|
2510
|
+
/** Registers an items with the drop list. */
|
|
2511
|
+
addItem(item) {
|
|
2512
|
+
this._unsortedItems.add(item);
|
|
2513
|
+
if (this._dropListRef.isDragging()) {
|
|
2514
|
+
this._syncItemsWithRef();
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
/** Removes an item from the drop list. */
|
|
2518
|
+
removeItem(item) {
|
|
2519
|
+
this._unsortedItems.delete(item);
|
|
2520
|
+
if (this._dropListRef.isDragging()) {
|
|
2521
|
+
this._syncItemsWithRef();
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
/** Gets the registered items in the list, sorted by their position in the DOM. */
|
|
2525
|
+
getSortedItems() {
|
|
2526
|
+
return Array.from(this._unsortedItems).sort((a, b) => {
|
|
2527
|
+
const documentPosition = a._dragRef.getVisibleElement().compareDocumentPosition(b._dragRef.getVisibleElement());
|
|
2528
|
+
// `compareDocumentPosition` returns a bitmask so we have to use a bitwise operator.
|
|
2529
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
|
|
2530
|
+
// tslint:disable-next-line:no-bitwise
|
|
2531
|
+
return documentPosition & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
ngOnDestroy() {
|
|
2535
|
+
const index = CdkDropList._dropLists.indexOf(this);
|
|
2536
|
+
if (index > -1) {
|
|
2537
|
+
CdkDropList._dropLists.splice(index, 1);
|
|
2538
|
+
}
|
|
2539
|
+
if (this._group) {
|
|
2540
|
+
this._group._items.delete(this);
|
|
2541
|
+
}
|
|
2542
|
+
this._unsortedItems.clear();
|
|
2543
|
+
this._dropListRef.dispose();
|
|
2544
|
+
this._destroyed.next();
|
|
2545
|
+
this._destroyed.complete();
|
|
2546
|
+
}
|
|
2547
|
+
/** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
|
|
2548
|
+
_setupInputSyncSubscription(ref) {
|
|
2549
|
+
if (this._dir) {
|
|
2550
|
+
this._dir.change
|
|
2551
|
+
.pipe(startWith(this._dir.value), takeUntil(this._destroyed))
|
|
2552
|
+
.subscribe(value => ref.withDirection(value));
|
|
2553
|
+
}
|
|
2554
|
+
ref.beforeStarted.subscribe(() => {
|
|
2555
|
+
const siblings = coerceArray(this.connectedTo).map(drop => {
|
|
2556
|
+
return typeof drop === 'string' ?
|
|
2557
|
+
CdkDropList._dropLists.find(list => list.id === drop) : drop;
|
|
2558
|
+
});
|
|
2559
|
+
if (this._group) {
|
|
2560
|
+
this._group._items.forEach(drop => {
|
|
2561
|
+
if (siblings.indexOf(drop) === -1) {
|
|
2562
|
+
siblings.push(drop);
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
// Note that we resolve the scrollable parents here so that we delay the resolution
|
|
2567
|
+
// as long as possible, ensuring that the element is in its final place in the DOM.
|
|
2568
|
+
// @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
|
|
2569
|
+
if (!this._scrollableParentsResolved && this._scrollDispatcher) {
|
|
2570
|
+
const scrollableParents = this._scrollDispatcher
|
|
2571
|
+
.getAncestorScrollContainers(this.element)
|
|
2572
|
+
.map(scrollable => scrollable.getElementRef().nativeElement);
|
|
2573
|
+
this._dropListRef.withScrollableParents(scrollableParents);
|
|
2574
|
+
// Only do this once since it involves traversing the DOM and the parents
|
|
2575
|
+
// shouldn't be able to change without the drop list being destroyed.
|
|
2576
|
+
this._scrollableParentsResolved = true;
|
|
2577
|
+
}
|
|
2578
|
+
ref.disabled = this.disabled;
|
|
2579
|
+
ref.lockAxis = this.lockAxis;
|
|
2580
|
+
ref.sortingDisabled = coerceBooleanProperty(this.sortingDisabled);
|
|
2581
|
+
ref.autoScrollDisabled = coerceBooleanProperty(this.autoScrollDisabled);
|
|
2582
|
+
ref
|
|
2583
|
+
.connectedTo(siblings.filter(drop => drop && drop !== this).map(list => list._dropListRef))
|
|
2584
|
+
.withOrientation(this.orientation);
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
/** Handles events from the underlying DropListRef. */
|
|
2588
|
+
_handleEvents(ref) {
|
|
2589
|
+
ref.beforeStarted.subscribe(() => {
|
|
2590
|
+
this._syncItemsWithRef();
|
|
2591
|
+
this._changeDetectorRef.markForCheck();
|
|
2592
|
+
});
|
|
2593
|
+
ref.entered.subscribe(event => {
|
|
2594
|
+
this.entered.emit({
|
|
2595
|
+
container: this,
|
|
2596
|
+
item: event.item.data,
|
|
2597
|
+
currentIndex: event.currentIndex
|
|
2598
|
+
});
|
|
2599
|
+
});
|
|
2600
|
+
ref.exited.subscribe(event => {
|
|
2601
|
+
this.exited.emit({
|
|
2602
|
+
container: this,
|
|
2603
|
+
item: event.item.data
|
|
2604
|
+
});
|
|
2605
|
+
this._changeDetectorRef.markForCheck();
|
|
2606
|
+
});
|
|
2607
|
+
ref.sorted.subscribe(event => {
|
|
2608
|
+
this.sorted.emit({
|
|
2609
|
+
previousIndex: event.previousIndex,
|
|
2610
|
+
currentIndex: event.currentIndex,
|
|
2611
|
+
container: this,
|
|
2612
|
+
item: event.item.data
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
ref.dropped.subscribe(event => {
|
|
2616
|
+
this.dropped.emit({
|
|
2617
|
+
previousIndex: event.previousIndex,
|
|
2618
|
+
currentIndex: event.currentIndex,
|
|
2619
|
+
previousContainer: event.previousContainer.data,
|
|
2620
|
+
container: event.container.data,
|
|
2621
|
+
item: event.item.data,
|
|
2622
|
+
isPointerOverContainer: event.isPointerOverContainer,
|
|
2623
|
+
distance: event.distance
|
|
2624
|
+
});
|
|
2625
|
+
// Mark for check since all of these events run outside of change
|
|
2626
|
+
// detection and we're not guaranteed for something else to have triggered it.
|
|
2627
|
+
this._changeDetectorRef.markForCheck();
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
/** Assigns the default input values based on a provided config object. */
|
|
2631
|
+
_assignDefaults(config) {
|
|
2632
|
+
const { lockAxis, draggingDisabled, sortingDisabled, listAutoScrollDisabled, listOrientation } = config;
|
|
2633
|
+
this.disabled = draggingDisabled == null ? false : draggingDisabled;
|
|
2634
|
+
this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled;
|
|
2635
|
+
this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled;
|
|
2636
|
+
this.orientation = listOrientation || 'vertical';
|
|
2637
|
+
if (lockAxis) {
|
|
2638
|
+
this.lockAxis = lockAxis;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
/** Syncs up the registered drag items with underlying drop list ref. */
|
|
2642
|
+
_syncItemsWithRef() {
|
|
2643
|
+
this._dropListRef.withItems(this.getSortedItems().map(item => item._dragRef));
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
/** Keeps track of the drop lists that are currently on the page. */
|
|
2647
|
+
CdkDropList._dropLists = [];
|
|
2648
|
+
CdkDropList.decorators = [
|
|
2649
|
+
{ type: Directive, args: [{
|
|
2650
|
+
selector: '[cdkDropList], cdk-drop-list',
|
|
2651
|
+
exportAs: 'cdkDropList',
|
|
2652
|
+
providers: [
|
|
2653
|
+
// Prevent child drop lists from picking up the same group as their parent.
|
|
2654
|
+
{ provide: CDK_DROP_LIST_GROUP, useValue: ɵ0 },
|
|
2655
|
+
{ provide: CDK_DROP_LIST, useExisting: CdkDropList },
|
|
2656
|
+
],
|
|
2657
|
+
host: {
|
|
2658
|
+
'class': 'cdk-drop-list',
|
|
2659
|
+
'[id]': 'id',
|
|
2660
|
+
'[class.cdk-drop-list-disabled]': 'disabled',
|
|
2661
|
+
'[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
|
|
2662
|
+
'[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
|
|
2663
|
+
}
|
|
2664
|
+
},] }
|
|
2665
|
+
];
|
|
2666
|
+
CdkDropList.ctorParameters = () => [
|
|
2667
|
+
{ type: ElementRef },
|
|
2668
|
+
{ type: DragDrop },
|
|
2669
|
+
{ type: ChangeDetectorRef },
|
|
2670
|
+
{ type: Directionality, decorators: [{ type: Optional }] },
|
|
2671
|
+
{ type: CdkDropListGroup, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DROP_LIST_GROUP,] }, { type: SkipSelf }] },
|
|
2672
|
+
{ type: ScrollDispatcher },
|
|
2673
|
+
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] }
|
|
2674
|
+
];
|
|
2675
|
+
CdkDropList.propDecorators = {
|
|
2676
|
+
connectedTo: [{ type: Input, args: ['cdkDropListConnectedTo',] }],
|
|
2677
|
+
data: [{ type: Input, args: ['cdkDropListData',] }],
|
|
2678
|
+
orientation: [{ type: Input, args: ['cdkDropListOrientation',] }],
|
|
2679
|
+
id: [{ type: Input }],
|
|
2680
|
+
lockAxis: [{ type: Input, args: ['cdkDropListLockAxis',] }],
|
|
2681
|
+
disabled: [{ type: Input, args: ['cdkDropListDisabled',] }],
|
|
2682
|
+
sortingDisabled: [{ type: Input, args: ['cdkDropListSortingDisabled',] }],
|
|
2683
|
+
enterPredicate: [{ type: Input, args: ['cdkDropListEnterPredicate',] }],
|
|
2684
|
+
autoScrollDisabled: [{ type: Input, args: ['cdkDropListAutoScrollDisabled',] }],
|
|
2685
|
+
dropped: [{ type: Output, args: ['cdkDropListDropped',] }],
|
|
2686
|
+
entered: [{ type: Output, args: ['cdkDropListEntered',] }],
|
|
2687
|
+
exited: [{ type: Output, args: ['cdkDropListExited',] }],
|
|
2688
|
+
sorted: [{ type: Output, args: ['cdkDropListSorted',] }]
|
|
2689
|
+
};
|
|
2413
2690
|
|
|
2414
2691
|
/**
|
|
2415
2692
|
* @license
|
|
@@ -2419,33 +2696,12 @@ let CdkDragPlaceholder = /** @class */ (() => {
|
|
|
2419
2696
|
* found in the LICENSE file at https://angular.io/license
|
|
2420
2697
|
*/
|
|
2421
2698
|
/**
|
|
2422
|
-
*
|
|
2423
|
-
*
|
|
2699
|
+
* Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
|
|
2700
|
+
* drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
|
|
2701
|
+
* to avoid circular imports.
|
|
2702
|
+
* @docs-private
|
|
2424
2703
|
*/
|
|
2425
|
-
|
|
2426
|
-
class CdkDragPreview {
|
|
2427
|
-
constructor(templateRef) {
|
|
2428
|
-
this.templateRef = templateRef;
|
|
2429
|
-
this._matchSize = false;
|
|
2430
|
-
}
|
|
2431
|
-
/** Whether the preview should preserve the same size as the item that is being dragged. */
|
|
2432
|
-
get matchSize() { return this._matchSize; }
|
|
2433
|
-
set matchSize(value) { this._matchSize = coerceBooleanProperty(value); }
|
|
2434
|
-
}
|
|
2435
|
-
CdkDragPreview.decorators = [
|
|
2436
|
-
{ type: Directive, args: [{
|
|
2437
|
-
selector: 'ng-template[cdkDragPreview]'
|
|
2438
|
-
},] }
|
|
2439
|
-
];
|
|
2440
|
-
CdkDragPreview.ctorParameters = () => [
|
|
2441
|
-
{ type: TemplateRef }
|
|
2442
|
-
];
|
|
2443
|
-
CdkDragPreview.propDecorators = {
|
|
2444
|
-
data: [{ type: Input }],
|
|
2445
|
-
matchSize: [{ type: Input }]
|
|
2446
|
-
};
|
|
2447
|
-
return CdkDragPreview;
|
|
2448
|
-
})();
|
|
2704
|
+
const CDK_DRAG_PARENT = new InjectionToken('CDK_DRAG_PARENT');
|
|
2449
2705
|
|
|
2450
2706
|
/**
|
|
2451
2707
|
* @license
|
|
@@ -2455,10 +2711,47 @@ let CdkDragPreview = /** @class */ (() => {
|
|
|
2455
2711
|
* found in the LICENSE file at https://angular.io/license
|
|
2456
2712
|
*/
|
|
2457
2713
|
/**
|
|
2458
|
-
* Injection token that can be used to
|
|
2459
|
-
*
|
|
2714
|
+
* Injection token that can be used to reference instances of `CdkDragHandle`. It serves as
|
|
2715
|
+
* alternative token to the actual `CdkDragHandle` class which could cause unnecessary
|
|
2716
|
+
* retention of the class and its directive metadata.
|
|
2460
2717
|
*/
|
|
2461
|
-
const
|
|
2718
|
+
const CDK_DRAG_HANDLE = new InjectionToken('CdkDragHandle');
|
|
2719
|
+
/** Handle that can be used to drag and CdkDrag instance. */
|
|
2720
|
+
class CdkDragHandle {
|
|
2721
|
+
constructor(element, parentDrag) {
|
|
2722
|
+
this.element = element;
|
|
2723
|
+
/** Emits when the state of the handle has changed. */
|
|
2724
|
+
this._stateChanges = new Subject();
|
|
2725
|
+
this._disabled = false;
|
|
2726
|
+
this._parentDrag = parentDrag;
|
|
2727
|
+
toggleNativeDragInteractions(element.nativeElement, false);
|
|
2728
|
+
}
|
|
2729
|
+
/** Whether starting to drag through this handle is disabled. */
|
|
2730
|
+
get disabled() { return this._disabled; }
|
|
2731
|
+
set disabled(value) {
|
|
2732
|
+
this._disabled = coerceBooleanProperty(value);
|
|
2733
|
+
this._stateChanges.next(this);
|
|
2734
|
+
}
|
|
2735
|
+
ngOnDestroy() {
|
|
2736
|
+
this._stateChanges.complete();
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
CdkDragHandle.decorators = [
|
|
2740
|
+
{ type: Directive, args: [{
|
|
2741
|
+
selector: '[cdkDragHandle]',
|
|
2742
|
+
host: {
|
|
2743
|
+
'class': 'cdk-drag-handle'
|
|
2744
|
+
},
|
|
2745
|
+
providers: [{ provide: CDK_DRAG_HANDLE, useExisting: CdkDragHandle }],
|
|
2746
|
+
},] }
|
|
2747
|
+
];
|
|
2748
|
+
CdkDragHandle.ctorParameters = () => [
|
|
2749
|
+
{ type: ElementRef },
|
|
2750
|
+
{ type: undefined, decorators: [{ type: Inject, args: [CDK_DRAG_PARENT,] }, { type: Optional }, { type: SkipSelf }] }
|
|
2751
|
+
];
|
|
2752
|
+
CdkDragHandle.propDecorators = {
|
|
2753
|
+
disabled: [{ type: Input, args: ['cdkDragHandleDisabled',] }]
|
|
2754
|
+
};
|
|
2462
2755
|
|
|
2463
2756
|
/**
|
|
2464
2757
|
* @license
|
|
@@ -2468,351 +2761,32 @@ const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONFIG');
|
|
|
2468
2761
|
* found in the LICENSE file at https://angular.io/license
|
|
2469
2762
|
*/
|
|
2470
2763
|
/**
|
|
2471
|
-
* Injection token that
|
|
2472
|
-
*
|
|
2764
|
+
* Injection token that can be used to reference instances of `CdkDragPlaceholder`. It serves as
|
|
2765
|
+
* alternative token to the actual `CdkDragPlaceholder` class which could cause unnecessary
|
|
2766
|
+
* retention of the class and its directive metadata.
|
|
2473
2767
|
*/
|
|
2474
|
-
const
|
|
2475
|
-
/**
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
dropContainer, _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef) {
|
|
2483
|
-
this.element = element;
|
|
2484
|
-
this.dropContainer = dropContainer;
|
|
2485
|
-
this._document = _document;
|
|
2486
|
-
this._ngZone = _ngZone;
|
|
2487
|
-
this._viewContainerRef = _viewContainerRef;
|
|
2488
|
-
this._dir = _dir;
|
|
2489
|
-
this._changeDetectorRef = _changeDetectorRef;
|
|
2490
|
-
this._destroyed = new Subject();
|
|
2491
|
-
/** Emits when the user starts dragging the item. */
|
|
2492
|
-
this.started = new EventEmitter();
|
|
2493
|
-
/** Emits when the user has released a drag item, before any animations have started. */
|
|
2494
|
-
this.released = new EventEmitter();
|
|
2495
|
-
/** Emits when the user stops dragging an item in the container. */
|
|
2496
|
-
this.ended = new EventEmitter();
|
|
2497
|
-
/** Emits when the user has moved the item into a new container. */
|
|
2498
|
-
this.entered = new EventEmitter();
|
|
2499
|
-
/** Emits when the user removes the item its container by dragging it into another container. */
|
|
2500
|
-
this.exited = new EventEmitter();
|
|
2501
|
-
/** Emits when the user drops the item inside a container. */
|
|
2502
|
-
this.dropped = new EventEmitter();
|
|
2503
|
-
/**
|
|
2504
|
-
* Emits as the user is dragging the item. Use with caution,
|
|
2505
|
-
* because this event will fire for every pixel that the user has dragged.
|
|
2506
|
-
*/
|
|
2507
|
-
this.moved = new Observable((observer) => {
|
|
2508
|
-
const subscription = this._dragRef.moved.pipe(map(movedEvent => ({
|
|
2509
|
-
source: this,
|
|
2510
|
-
pointerPosition: movedEvent.pointerPosition,
|
|
2511
|
-
event: movedEvent.event,
|
|
2512
|
-
delta: movedEvent.delta,
|
|
2513
|
-
distance: movedEvent.distance
|
|
2514
|
-
}))).subscribe(observer);
|
|
2515
|
-
return () => {
|
|
2516
|
-
subscription.unsubscribe();
|
|
2517
|
-
};
|
|
2518
|
-
});
|
|
2519
|
-
this._dragRef = dragDrop.createDrag(element, {
|
|
2520
|
-
dragStartThreshold: config && config.dragStartThreshold != null ?
|
|
2521
|
-
config.dragStartThreshold : 5,
|
|
2522
|
-
pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
|
|
2523
|
-
config.pointerDirectionChangeThreshold : 5,
|
|
2524
|
-
zIndex: config === null || config === void 0 ? void 0 : config.zIndex
|
|
2525
|
-
});
|
|
2526
|
-
this._dragRef.data = this;
|
|
2527
|
-
if (config) {
|
|
2528
|
-
this._assignDefaults(config);
|
|
2529
|
-
}
|
|
2530
|
-
// Note that usually the container is assigned when the drop list is picks up the item, but in
|
|
2531
|
-
// some cases (mainly transplanted views with OnPush, see #18341) we may end up in a situation
|
|
2532
|
-
// where there are no items on the first change detection pass, but the items get picked up as
|
|
2533
|
-
// soon as the user triggers another pass by dragging. This is a problem, because the item would
|
|
2534
|
-
// have to switch from standalone mode to drag mode in the middle of the dragging sequence which
|
|
2535
|
-
// is too late since the two modes save different kinds of information. We work around it by
|
|
2536
|
-
// assigning the drop container both from here and the list.
|
|
2537
|
-
if (dropContainer) {
|
|
2538
|
-
this._dragRef._withDropContainer(dropContainer._dropListRef);
|
|
2539
|
-
dropContainer.addItem(this);
|
|
2540
|
-
}
|
|
2541
|
-
this._syncInputs(this._dragRef);
|
|
2542
|
-
this._handleEvents(this._dragRef);
|
|
2543
|
-
}
|
|
2544
|
-
/** Whether starting to drag this element is disabled. */
|
|
2545
|
-
get disabled() {
|
|
2546
|
-
return this._disabled || (this.dropContainer && this.dropContainer.disabled);
|
|
2547
|
-
}
|
|
2548
|
-
set disabled(value) {
|
|
2549
|
-
this._disabled = coerceBooleanProperty(value);
|
|
2550
|
-
this._dragRef.disabled = this._disabled;
|
|
2551
|
-
}
|
|
2552
|
-
/**
|
|
2553
|
-
* Returns the element that is being used as a placeholder
|
|
2554
|
-
* while the current element is being dragged.
|
|
2555
|
-
* @deprecated No longer being used to be removed.
|
|
2556
|
-
* @breaking-change 11.0.0
|
|
2557
|
-
*/
|
|
2558
|
-
getPlaceholderElement() {
|
|
2559
|
-
return this._dragRef.getPlaceholderElement();
|
|
2560
|
-
}
|
|
2561
|
-
/**
|
|
2562
|
-
* Returns the root draggable element.
|
|
2563
|
-
* @deprecated No longer being used to be removed.
|
|
2564
|
-
* @breaking-change 11.0.0
|
|
2565
|
-
*/
|
|
2566
|
-
getRootElement() {
|
|
2567
|
-
return this._dragRef.getRootElement();
|
|
2568
|
-
}
|
|
2569
|
-
/** Resets a standalone drag item to its initial position. */
|
|
2570
|
-
reset() {
|
|
2571
|
-
this._dragRef.reset();
|
|
2572
|
-
}
|
|
2573
|
-
/**
|
|
2574
|
-
* Gets the pixel coordinates of the draggable outside of a drop container.
|
|
2575
|
-
*/
|
|
2576
|
-
getFreeDragPosition() {
|
|
2577
|
-
return this._dragRef.getFreeDragPosition();
|
|
2578
|
-
}
|
|
2579
|
-
ngAfterViewInit() {
|
|
2580
|
-
// We need to wait for the zone to stabilize, in order for the reference
|
|
2581
|
-
// element to be in the proper place in the DOM. This is mostly relevant
|
|
2582
|
-
// for draggable elements inside portals since they get stamped out in
|
|
2583
|
-
// their original DOM position and then they get transferred to the portal.
|
|
2584
|
-
this._ngZone.onStable.asObservable()
|
|
2585
|
-
.pipe(take(1), takeUntil(this._destroyed))
|
|
2586
|
-
.subscribe(() => {
|
|
2587
|
-
this._updateRootElement();
|
|
2588
|
-
// Listen for any newly-added handles.
|
|
2589
|
-
this._handles.changes.pipe(startWith(this._handles),
|
|
2590
|
-
// Sync the new handles with the DragRef.
|
|
2591
|
-
tap((handles) => {
|
|
2592
|
-
const childHandleElements = handles
|
|
2593
|
-
.filter(handle => handle._parentDrag === this)
|
|
2594
|
-
.map(handle => handle.element);
|
|
2595
|
-
this._dragRef.withHandles(childHandleElements);
|
|
2596
|
-
}),
|
|
2597
|
-
// Listen if the state of any of the handles changes.
|
|
2598
|
-
switchMap((handles) => {
|
|
2599
|
-
return merge(...handles.map(item => {
|
|
2600
|
-
return item._stateChanges.pipe(startWith(item));
|
|
2601
|
-
}));
|
|
2602
|
-
}), takeUntil(this._destroyed)).subscribe(handleInstance => {
|
|
2603
|
-
// Enabled/disable the handle that changed in the DragRef.
|
|
2604
|
-
const dragRef = this._dragRef;
|
|
2605
|
-
const handle = handleInstance.element.nativeElement;
|
|
2606
|
-
handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
|
|
2607
|
-
});
|
|
2608
|
-
if (this.freeDragPosition) {
|
|
2609
|
-
this._dragRef.setFreeDragPosition(this.freeDragPosition);
|
|
2610
|
-
}
|
|
2611
|
-
});
|
|
2612
|
-
}
|
|
2613
|
-
ngOnChanges(changes) {
|
|
2614
|
-
const rootSelectorChange = changes['rootElementSelector'];
|
|
2615
|
-
const positionChange = changes['freeDragPosition'];
|
|
2616
|
-
// We don't have to react to the first change since it's being
|
|
2617
|
-
// handled in `ngAfterViewInit` where it needs to be deferred.
|
|
2618
|
-
if (rootSelectorChange && !rootSelectorChange.firstChange) {
|
|
2619
|
-
this._updateRootElement();
|
|
2620
|
-
}
|
|
2621
|
-
// Skip the first change since it's being handled in `ngAfterViewInit`.
|
|
2622
|
-
if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
|
|
2623
|
-
this._dragRef.setFreeDragPosition(this.freeDragPosition);
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
ngOnDestroy() {
|
|
2627
|
-
if (this.dropContainer) {
|
|
2628
|
-
this.dropContainer.removeItem(this);
|
|
2629
|
-
}
|
|
2630
|
-
this._destroyed.next();
|
|
2631
|
-
this._destroyed.complete();
|
|
2632
|
-
this._dragRef.dispose();
|
|
2633
|
-
}
|
|
2634
|
-
/** Syncs the root element with the `DragRef`. */
|
|
2635
|
-
_updateRootElement() {
|
|
2636
|
-
const element = this.element.nativeElement;
|
|
2637
|
-
const rootElement = this.rootElementSelector ?
|
|
2638
|
-
getClosestMatchingAncestor(element, this.rootElementSelector) : element;
|
|
2639
|
-
if (rootElement && rootElement.nodeType !== this._document.ELEMENT_NODE) {
|
|
2640
|
-
throw Error(`cdkDrag must be attached to an element node. ` +
|
|
2641
|
-
`Currently attached to "${rootElement.nodeName}".`);
|
|
2642
|
-
}
|
|
2643
|
-
this._dragRef.withRootElement(rootElement || element);
|
|
2644
|
-
}
|
|
2645
|
-
/** Gets the boundary element, based on the `boundaryElement` value. */
|
|
2646
|
-
_getBoundaryElement() {
|
|
2647
|
-
const boundary = this.boundaryElement;
|
|
2648
|
-
if (!boundary) {
|
|
2649
|
-
return null;
|
|
2650
|
-
}
|
|
2651
|
-
if (typeof boundary === 'string') {
|
|
2652
|
-
return getClosestMatchingAncestor(this.element.nativeElement, boundary);
|
|
2653
|
-
}
|
|
2654
|
-
const element = coerceElement(boundary);
|
|
2655
|
-
if (isDevMode() && !element.contains(this.element.nativeElement)) {
|
|
2656
|
-
throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
|
|
2657
|
-
}
|
|
2658
|
-
return element;
|
|
2659
|
-
}
|
|
2660
|
-
/** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
|
|
2661
|
-
_syncInputs(ref) {
|
|
2662
|
-
ref.beforeStarted.subscribe(() => {
|
|
2663
|
-
if (!ref.isDragging()) {
|
|
2664
|
-
const dir = this._dir;
|
|
2665
|
-
const dragStartDelay = this.dragStartDelay;
|
|
2666
|
-
const placeholder = this._placeholderTemplate ? {
|
|
2667
|
-
template: this._placeholderTemplate.templateRef,
|
|
2668
|
-
context: this._placeholderTemplate.data,
|
|
2669
|
-
viewContainer: this._viewContainerRef
|
|
2670
|
-
} : null;
|
|
2671
|
-
const preview = this._previewTemplate ? {
|
|
2672
|
-
template: this._previewTemplate.templateRef,
|
|
2673
|
-
context: this._previewTemplate.data,
|
|
2674
|
-
matchSize: this._previewTemplate.matchSize,
|
|
2675
|
-
viewContainer: this._viewContainerRef
|
|
2676
|
-
} : null;
|
|
2677
|
-
ref.disabled = this.disabled;
|
|
2678
|
-
ref.lockAxis = this.lockAxis;
|
|
2679
|
-
ref.dragStartDelay = (typeof dragStartDelay === 'object' && dragStartDelay) ?
|
|
2680
|
-
dragStartDelay : coerceNumberProperty(dragStartDelay);
|
|
2681
|
-
ref.constrainPosition = this.constrainPosition;
|
|
2682
|
-
ref.previewClass = this.previewClass;
|
|
2683
|
-
ref
|
|
2684
|
-
.withBoundaryElement(this._getBoundaryElement())
|
|
2685
|
-
.withPlaceholderTemplate(placeholder)
|
|
2686
|
-
.withPreviewTemplate(preview);
|
|
2687
|
-
if (dir) {
|
|
2688
|
-
ref.withDirection(dir.value);
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
});
|
|
2692
|
-
}
|
|
2693
|
-
/** Handles the events from the underlying `DragRef`. */
|
|
2694
|
-
_handleEvents(ref) {
|
|
2695
|
-
ref.started.subscribe(() => {
|
|
2696
|
-
this.started.emit({ source: this });
|
|
2697
|
-
// Since all of these events run outside of change detection,
|
|
2698
|
-
// we need to ensure that everything is marked correctly.
|
|
2699
|
-
this._changeDetectorRef.markForCheck();
|
|
2700
|
-
});
|
|
2701
|
-
ref.released.subscribe(() => {
|
|
2702
|
-
this.released.emit({ source: this });
|
|
2703
|
-
});
|
|
2704
|
-
ref.ended.subscribe(event => {
|
|
2705
|
-
this.ended.emit({ source: this, distance: event.distance });
|
|
2706
|
-
// Since all of these events run outside of change detection,
|
|
2707
|
-
// we need to ensure that everything is marked correctly.
|
|
2708
|
-
this._changeDetectorRef.markForCheck();
|
|
2709
|
-
});
|
|
2710
|
-
ref.entered.subscribe(event => {
|
|
2711
|
-
this.entered.emit({
|
|
2712
|
-
container: event.container.data,
|
|
2713
|
-
item: this,
|
|
2714
|
-
currentIndex: event.currentIndex
|
|
2715
|
-
});
|
|
2716
|
-
});
|
|
2717
|
-
ref.exited.subscribe(event => {
|
|
2718
|
-
this.exited.emit({
|
|
2719
|
-
container: event.container.data,
|
|
2720
|
-
item: this
|
|
2721
|
-
});
|
|
2722
|
-
});
|
|
2723
|
-
ref.dropped.subscribe(event => {
|
|
2724
|
-
this.dropped.emit({
|
|
2725
|
-
previousIndex: event.previousIndex,
|
|
2726
|
-
currentIndex: event.currentIndex,
|
|
2727
|
-
previousContainer: event.previousContainer.data,
|
|
2728
|
-
container: event.container.data,
|
|
2729
|
-
isPointerOverContainer: event.isPointerOverContainer,
|
|
2730
|
-
item: this,
|
|
2731
|
-
distance: event.distance
|
|
2732
|
-
});
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
/** Assigns the default input values based on a provided config object. */
|
|
2736
|
-
_assignDefaults(config) {
|
|
2737
|
-
const { lockAxis, dragStartDelay, constrainPosition, previewClass, boundaryElement, draggingDisabled, rootElementSelector } = config;
|
|
2738
|
-
this.disabled = draggingDisabled == null ? false : draggingDisabled;
|
|
2739
|
-
this.dragStartDelay = dragStartDelay || 0;
|
|
2740
|
-
if (lockAxis) {
|
|
2741
|
-
this.lockAxis = lockAxis;
|
|
2742
|
-
}
|
|
2743
|
-
if (constrainPosition) {
|
|
2744
|
-
this.constrainPosition = constrainPosition;
|
|
2745
|
-
}
|
|
2746
|
-
if (previewClass) {
|
|
2747
|
-
this.previewClass = previewClass;
|
|
2748
|
-
}
|
|
2749
|
-
if (boundaryElement) {
|
|
2750
|
-
this.boundaryElement = boundaryElement;
|
|
2751
|
-
}
|
|
2752
|
-
if (rootElementSelector) {
|
|
2753
|
-
this.rootElementSelector = rootElementSelector;
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
CdkDrag.decorators = [
|
|
2758
|
-
{ type: Directive, args: [{
|
|
2759
|
-
selector: '[cdkDrag]',
|
|
2760
|
-
exportAs: 'cdkDrag',
|
|
2761
|
-
host: {
|
|
2762
|
-
'class': 'cdk-drag',
|
|
2763
|
-
'[class.cdk-drag-disabled]': 'disabled',
|
|
2764
|
-
'[class.cdk-drag-dragging]': '_dragRef.isDragging()',
|
|
2765
|
-
},
|
|
2766
|
-
providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
|
|
2767
|
-
},] }
|
|
2768
|
-
];
|
|
2769
|
-
CdkDrag.ctorParameters = () => [
|
|
2770
|
-
{ type: ElementRef },
|
|
2771
|
-
{ type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST,] }, { type: Optional }, { type: SkipSelf }] },
|
|
2772
|
-
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
2773
|
-
{ type: NgZone },
|
|
2774
|
-
{ type: ViewContainerRef },
|
|
2775
|
-
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] },
|
|
2776
|
-
{ type: Directionality, decorators: [{ type: Optional }] },
|
|
2777
|
-
{ type: DragDrop },
|
|
2778
|
-
{ type: ChangeDetectorRef }
|
|
2779
|
-
];
|
|
2780
|
-
CdkDrag.propDecorators = {
|
|
2781
|
-
_handles: [{ type: ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
|
|
2782
|
-
_previewTemplate: [{ type: ContentChild, args: [CdkDragPreview,] }],
|
|
2783
|
-
_placeholderTemplate: [{ type: ContentChild, args: [CdkDragPlaceholder,] }],
|
|
2784
|
-
data: [{ type: Input, args: ['cdkDragData',] }],
|
|
2785
|
-
lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
|
|
2786
|
-
rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
|
|
2787
|
-
boundaryElement: [{ type: Input, args: ['cdkDragBoundary',] }],
|
|
2788
|
-
dragStartDelay: [{ type: Input, args: ['cdkDragStartDelay',] }],
|
|
2789
|
-
freeDragPosition: [{ type: Input, args: ['cdkDragFreeDragPosition',] }],
|
|
2790
|
-
disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
|
|
2791
|
-
constrainPosition: [{ type: Input, args: ['cdkDragConstrainPosition',] }],
|
|
2792
|
-
previewClass: [{ type: Input, args: ['cdkDragPreviewClass',] }],
|
|
2793
|
-
started: [{ type: Output, args: ['cdkDragStarted',] }],
|
|
2794
|
-
released: [{ type: Output, args: ['cdkDragReleased',] }],
|
|
2795
|
-
ended: [{ type: Output, args: ['cdkDragEnded',] }],
|
|
2796
|
-
entered: [{ type: Output, args: ['cdkDragEntered',] }],
|
|
2797
|
-
exited: [{ type: Output, args: ['cdkDragExited',] }],
|
|
2798
|
-
dropped: [{ type: Output, args: ['cdkDragDropped',] }],
|
|
2799
|
-
moved: [{ type: Output, args: ['cdkDragMoved',] }]
|
|
2800
|
-
};
|
|
2801
|
-
return CdkDrag;
|
|
2802
|
-
})();
|
|
2803
|
-
/** Gets the closest ancestor of an element that matches a selector. */
|
|
2804
|
-
function getClosestMatchingAncestor(element, selector) {
|
|
2805
|
-
let currentElement = element.parentElement;
|
|
2806
|
-
while (currentElement) {
|
|
2807
|
-
// IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
|
|
2808
|
-
if (currentElement.matches ? currentElement.matches(selector) :
|
|
2809
|
-
currentElement.msMatchesSelector(selector)) {
|
|
2810
|
-
return currentElement;
|
|
2811
|
-
}
|
|
2812
|
-
currentElement = currentElement.parentElement;
|
|
2768
|
+
const CDK_DRAG_PLACEHOLDER = new InjectionToken('CdkDragPlaceholder');
|
|
2769
|
+
/**
|
|
2770
|
+
* Element that will be used as a template for the placeholder of a CdkDrag when
|
|
2771
|
+
* it is being dragged. The placeholder is displayed in place of the element being dragged.
|
|
2772
|
+
*/
|
|
2773
|
+
class CdkDragPlaceholder {
|
|
2774
|
+
constructor(templateRef) {
|
|
2775
|
+
this.templateRef = templateRef;
|
|
2813
2776
|
}
|
|
2814
|
-
return null;
|
|
2815
2777
|
}
|
|
2778
|
+
CdkDragPlaceholder.decorators = [
|
|
2779
|
+
{ type: Directive, args: [{
|
|
2780
|
+
selector: 'ng-template[cdkDragPlaceholder]',
|
|
2781
|
+
providers: [{ provide: CDK_DRAG_PLACEHOLDER, useExisting: CdkDragPlaceholder }],
|
|
2782
|
+
},] }
|
|
2783
|
+
];
|
|
2784
|
+
CdkDragPlaceholder.ctorParameters = () => [
|
|
2785
|
+
{ type: TemplateRef }
|
|
2786
|
+
];
|
|
2787
|
+
CdkDragPlaceholder.propDecorators = {
|
|
2788
|
+
data: [{ type: Input }]
|
|
2789
|
+
};
|
|
2816
2790
|
|
|
2817
2791
|
/**
|
|
2818
2792
|
* @license
|
|
@@ -2822,38 +2796,37 @@ function getClosestMatchingAncestor(element, selector) {
|
|
|
2822
2796
|
* found in the LICENSE file at https://angular.io/license
|
|
2823
2797
|
*/
|
|
2824
2798
|
/**
|
|
2825
|
-
*
|
|
2826
|
-
*
|
|
2827
|
-
*
|
|
2828
|
-
* from `cdkDropList`.
|
|
2799
|
+
* Injection token that can be used to reference instances of `CdkDragPreview`. It serves as
|
|
2800
|
+
* alternative token to the actual `CdkDragPreview` class which could cause unnecessary
|
|
2801
|
+
* retention of the class and its directive metadata.
|
|
2829
2802
|
*/
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
}
|
|
2855
|
-
|
|
2856
|
-
}
|
|
2803
|
+
const CDK_DRAG_PREVIEW = new InjectionToken('CdkDragPreview');
|
|
2804
|
+
/**
|
|
2805
|
+
* Element that will be used as a template for the preview
|
|
2806
|
+
* of a CdkDrag when it is being dragged.
|
|
2807
|
+
*/
|
|
2808
|
+
class CdkDragPreview {
|
|
2809
|
+
constructor(templateRef) {
|
|
2810
|
+
this.templateRef = templateRef;
|
|
2811
|
+
this._matchSize = false;
|
|
2812
|
+
}
|
|
2813
|
+
/** Whether the preview should preserve the same size as the item that is being dragged. */
|
|
2814
|
+
get matchSize() { return this._matchSize; }
|
|
2815
|
+
set matchSize(value) { this._matchSize = coerceBooleanProperty(value); }
|
|
2816
|
+
}
|
|
2817
|
+
CdkDragPreview.decorators = [
|
|
2818
|
+
{ type: Directive, args: [{
|
|
2819
|
+
selector: 'ng-template[cdkDragPreview]',
|
|
2820
|
+
providers: [{ provide: CDK_DRAG_PREVIEW, useExisting: CdkDragPreview }],
|
|
2821
|
+
},] }
|
|
2822
|
+
];
|
|
2823
|
+
CdkDragPreview.ctorParameters = () => [
|
|
2824
|
+
{ type: TemplateRef }
|
|
2825
|
+
];
|
|
2826
|
+
CdkDragPreview.propDecorators = {
|
|
2827
|
+
data: [{ type: Input }],
|
|
2828
|
+
matchSize: [{ type: Input }]
|
|
2829
|
+
};
|
|
2857
2830
|
|
|
2858
2831
|
/**
|
|
2859
2832
|
* @license
|
|
@@ -2862,272 +2835,346 @@ let CdkDropListGroup = /** @class */ (() => {
|
|
|
2862
2835
|
* Use of this source code is governed by an MIT-style license that can be
|
|
2863
2836
|
* found in the LICENSE file at https://angular.io/license
|
|
2864
2837
|
*/
|
|
2865
|
-
/**
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
/**
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2838
|
+
/** Element that can be moved inside a CdkDropList container. */
|
|
2839
|
+
class CdkDrag {
|
|
2840
|
+
constructor(
|
|
2841
|
+
/** Element that the draggable is attached to. */
|
|
2842
|
+
element,
|
|
2843
|
+
/** Droppable container that the draggable is a part of. */
|
|
2844
|
+
dropContainer, _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef, _selfHandle) {
|
|
2845
|
+
this.element = element;
|
|
2846
|
+
this.dropContainer = dropContainer;
|
|
2847
|
+
this._document = _document;
|
|
2848
|
+
this._ngZone = _ngZone;
|
|
2849
|
+
this._viewContainerRef = _viewContainerRef;
|
|
2850
|
+
this._dir = _dir;
|
|
2851
|
+
this._changeDetectorRef = _changeDetectorRef;
|
|
2852
|
+
this._selfHandle = _selfHandle;
|
|
2853
|
+
this._destroyed = new Subject();
|
|
2854
|
+
/** Emits when the user starts dragging the item. */
|
|
2855
|
+
this.started = new EventEmitter();
|
|
2856
|
+
/** Emits when the user has released a drag item, before any animations have started. */
|
|
2857
|
+
this.released = new EventEmitter();
|
|
2858
|
+
/** Emits when the user stops dragging an item in the container. */
|
|
2859
|
+
this.ended = new EventEmitter();
|
|
2860
|
+
/** Emits when the user has moved the item into a new container. */
|
|
2861
|
+
this.entered = new EventEmitter();
|
|
2862
|
+
/** Emits when the user removes the item its container by dragging it into another container. */
|
|
2863
|
+
this.exited = new EventEmitter();
|
|
2864
|
+
/** Emits when the user drops the item inside a container. */
|
|
2865
|
+
this.dropped = new EventEmitter();
|
|
2874
2866
|
/**
|
|
2875
|
-
*
|
|
2876
|
-
*
|
|
2867
|
+
* Emits as the user is dragging the item. Use with caution,
|
|
2868
|
+
* because this event will fire for every pixel that the user has dragged.
|
|
2877
2869
|
*/
|
|
2878
|
-
|
|
2879
|
-
this.
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
* container's items can be transferred. Can either be references to other drop containers,
|
|
2889
|
-
* or their unique IDs.
|
|
2890
|
-
*/
|
|
2891
|
-
this.connectedTo = [];
|
|
2892
|
-
/**
|
|
2893
|
-
* Unique ID for the drop zone. Can be used as a reference
|
|
2894
|
-
* in the `connectedTo` of another `CdkDropList`.
|
|
2895
|
-
*/
|
|
2896
|
-
this.id = `cdk-drop-list-${_uniqueIdCounter++}`;
|
|
2897
|
-
/**
|
|
2898
|
-
* Function that is used to determine whether an item
|
|
2899
|
-
* is allowed to be moved into a drop container.
|
|
2900
|
-
*/
|
|
2901
|
-
this.enterPredicate = () => true;
|
|
2902
|
-
/** Emits when the user drops an item inside the container. */
|
|
2903
|
-
this.dropped = new EventEmitter();
|
|
2904
|
-
/**
|
|
2905
|
-
* Emits when the user has moved a new drag item into this container.
|
|
2906
|
-
*/
|
|
2907
|
-
this.entered = new EventEmitter();
|
|
2908
|
-
/**
|
|
2909
|
-
* Emits when the user removes an item from the container
|
|
2910
|
-
* by dragging it into another container.
|
|
2911
|
-
*/
|
|
2912
|
-
this.exited = new EventEmitter();
|
|
2913
|
-
/** Emits as the user is swapping items while actively dragging. */
|
|
2914
|
-
this.sorted = new EventEmitter();
|
|
2915
|
-
/**
|
|
2916
|
-
* Keeps track of the items that are registered with this container. Historically we used to
|
|
2917
|
-
* do this with a `ContentChildren` query, however queries don't handle transplanted views very
|
|
2918
|
-
* well which means that we can't handle cases like dragging the headers of a `mat-table`
|
|
2919
|
-
* correctly. What we do instead is to have the items register themselves with the container
|
|
2920
|
-
* and then we sort them based on their position in the DOM.
|
|
2921
|
-
*/
|
|
2922
|
-
this._unsortedItems = new Set();
|
|
2923
|
-
this._dropListRef = dragDrop.createDropList(element);
|
|
2924
|
-
this._dropListRef.data = this;
|
|
2925
|
-
if (config) {
|
|
2926
|
-
this._assignDefaults(config);
|
|
2927
|
-
}
|
|
2928
|
-
this._dropListRef.enterPredicate = (drag, drop) => {
|
|
2929
|
-
return this.enterPredicate(drag.data, drop.data);
|
|
2870
|
+
this.moved = new Observable((observer) => {
|
|
2871
|
+
const subscription = this._dragRef.moved.pipe(map(movedEvent => ({
|
|
2872
|
+
source: this,
|
|
2873
|
+
pointerPosition: movedEvent.pointerPosition,
|
|
2874
|
+
event: movedEvent.event,
|
|
2875
|
+
delta: movedEvent.delta,
|
|
2876
|
+
distance: movedEvent.distance
|
|
2877
|
+
}))).subscribe(observer);
|
|
2878
|
+
return () => {
|
|
2879
|
+
subscription.unsubscribe();
|
|
2930
2880
|
};
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
this.
|
|
2952
|
-
|
|
2953
|
-
this._syncItemsWithRef();
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
/** Removes an item from the drop list. */
|
|
2957
|
-
removeItem(item) {
|
|
2958
|
-
this._unsortedItems.delete(item);
|
|
2959
|
-
if (this._dropListRef.isDragging()) {
|
|
2960
|
-
this._syncItemsWithRef();
|
|
2961
|
-
}
|
|
2881
|
+
});
|
|
2882
|
+
this._dragRef = dragDrop.createDrag(element, {
|
|
2883
|
+
dragStartThreshold: config && config.dragStartThreshold != null ?
|
|
2884
|
+
config.dragStartThreshold : 5,
|
|
2885
|
+
pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
|
|
2886
|
+
config.pointerDirectionChangeThreshold : 5,
|
|
2887
|
+
zIndex: config === null || config === void 0 ? void 0 : config.zIndex
|
|
2888
|
+
});
|
|
2889
|
+
this._dragRef.data = this;
|
|
2890
|
+
if (config) {
|
|
2891
|
+
this._assignDefaults(config);
|
|
2892
|
+
}
|
|
2893
|
+
// Note that usually the container is assigned when the drop list is picks up the item, but in
|
|
2894
|
+
// some cases (mainly transplanted views with OnPush, see #18341) we may end up in a situation
|
|
2895
|
+
// where there are no items on the first change detection pass, but the items get picked up as
|
|
2896
|
+
// soon as the user triggers another pass by dragging. This is a problem, because the item would
|
|
2897
|
+
// have to switch from standalone mode to drag mode in the middle of the dragging sequence which
|
|
2898
|
+
// is too late since the two modes save different kinds of information. We work around it by
|
|
2899
|
+
// assigning the drop container both from here and the list.
|
|
2900
|
+
if (dropContainer) {
|
|
2901
|
+
this._dragRef._withDropContainer(dropContainer._dropListRef);
|
|
2902
|
+
dropContainer.addItem(this);
|
|
2962
2903
|
}
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2904
|
+
this._syncInputs(this._dragRef);
|
|
2905
|
+
this._handleEvents(this._dragRef);
|
|
2906
|
+
}
|
|
2907
|
+
/** Whether starting to drag this element is disabled. */
|
|
2908
|
+
get disabled() {
|
|
2909
|
+
return this._disabled || (this.dropContainer && this.dropContainer.disabled);
|
|
2910
|
+
}
|
|
2911
|
+
set disabled(value) {
|
|
2912
|
+
this._disabled = coerceBooleanProperty(value);
|
|
2913
|
+
this._dragRef.disabled = this._disabled;
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Returns the element that is being used as a placeholder
|
|
2917
|
+
* while the current element is being dragged.
|
|
2918
|
+
*/
|
|
2919
|
+
getPlaceholderElement() {
|
|
2920
|
+
return this._dragRef.getPlaceholderElement();
|
|
2921
|
+
}
|
|
2922
|
+
/** Returns the root draggable element. */
|
|
2923
|
+
getRootElement() {
|
|
2924
|
+
return this._dragRef.getRootElement();
|
|
2925
|
+
}
|
|
2926
|
+
/** Resets a standalone drag item to its initial position. */
|
|
2927
|
+
reset() {
|
|
2928
|
+
this._dragRef.reset();
|
|
2929
|
+
}
|
|
2930
|
+
/**
|
|
2931
|
+
* Gets the pixel coordinates of the draggable outside of a drop container.
|
|
2932
|
+
*/
|
|
2933
|
+
getFreeDragPosition() {
|
|
2934
|
+
return this._dragRef.getFreeDragPosition();
|
|
2935
|
+
}
|
|
2936
|
+
ngAfterViewInit() {
|
|
2937
|
+
// We need to wait for the zone to stabilize, in order for the reference
|
|
2938
|
+
// element to be in the proper place in the DOM. This is mostly relevant
|
|
2939
|
+
// for draggable elements inside portals since they get stamped out in
|
|
2940
|
+
// their original DOM position and then they get transferred to the portal.
|
|
2941
|
+
this._ngZone.onStable.asObservable()
|
|
2942
|
+
.pipe(take(1), takeUntil(this._destroyed))
|
|
2943
|
+
.subscribe(() => {
|
|
2944
|
+
this._updateRootElement();
|
|
2945
|
+
// Listen for any newly-added handles.
|
|
2946
|
+
this._handles.changes.pipe(startWith(this._handles),
|
|
2947
|
+
// Sync the new handles with the DragRef.
|
|
2948
|
+
tap((handles) => {
|
|
2949
|
+
const childHandleElements = handles
|
|
2950
|
+
.filter(handle => handle._parentDrag === this)
|
|
2951
|
+
.map(handle => handle.element);
|
|
2952
|
+
// Usually handles are only allowed to be a descendant of the drag element, but if
|
|
2953
|
+
// the consumer defined a different drag root, we should allow the drag element
|
|
2954
|
+
// itself to be a handle too.
|
|
2955
|
+
if (this._selfHandle && this.rootElementSelector) {
|
|
2956
|
+
childHandleElements.push(this.element);
|
|
2957
|
+
}
|
|
2958
|
+
this._dragRef.withHandles(childHandleElements);
|
|
2959
|
+
}),
|
|
2960
|
+
// Listen if the state of any of the handles changes.
|
|
2961
|
+
switchMap((handles) => {
|
|
2962
|
+
return merge(...handles.map(item => {
|
|
2963
|
+
return item._stateChanges.pipe(startWith(item));
|
|
2964
|
+
}));
|
|
2965
|
+
}), takeUntil(this._destroyed)).subscribe(handleInstance => {
|
|
2966
|
+
// Enabled/disable the handle that changed in the DragRef.
|
|
2967
|
+
const dragRef = this._dragRef;
|
|
2968
|
+
const handle = handleInstance.element.nativeElement;
|
|
2969
|
+
handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
|
|
2971
2970
|
});
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
const index = CdkDropList._dropLists.indexOf(this);
|
|
2975
|
-
if (index > -1) {
|
|
2976
|
-
CdkDropList._dropLists.splice(index, 1);
|
|
2977
|
-
}
|
|
2978
|
-
if (this._group) {
|
|
2979
|
-
this._group._items.delete(this);
|
|
2980
|
-
}
|
|
2981
|
-
this._unsortedItems.clear();
|
|
2982
|
-
this._dropListRef.dispose();
|
|
2983
|
-
this._destroyed.next();
|
|
2984
|
-
this._destroyed.complete();
|
|
2985
|
-
}
|
|
2986
|
-
/** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
|
|
2987
|
-
_setupInputSyncSubscription(ref) {
|
|
2988
|
-
if (this._dir) {
|
|
2989
|
-
this._dir.change
|
|
2990
|
-
.pipe(startWith(this._dir.value), takeUntil(this._destroyed))
|
|
2991
|
-
.subscribe(value => ref.withDirection(value));
|
|
2971
|
+
if (this.freeDragPosition) {
|
|
2972
|
+
this._dragRef.setFreeDragPosition(this.freeDragPosition);
|
|
2992
2973
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
ngOnChanges(changes) {
|
|
2977
|
+
const rootSelectorChange = changes['rootElementSelector'];
|
|
2978
|
+
const positionChange = changes['freeDragPosition'];
|
|
2979
|
+
// We don't have to react to the first change since it's being
|
|
2980
|
+
// handled in `ngAfterViewInit` where it needs to be deferred.
|
|
2981
|
+
if (rootSelectorChange && !rootSelectorChange.firstChange) {
|
|
2982
|
+
this._updateRootElement();
|
|
2983
|
+
}
|
|
2984
|
+
// Skip the first change since it's being handled in `ngAfterViewInit`.
|
|
2985
|
+
if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
|
|
2986
|
+
this._dragRef.setFreeDragPosition(this.freeDragPosition);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
ngOnDestroy() {
|
|
2990
|
+
if (this.dropContainer) {
|
|
2991
|
+
this.dropContainer.removeItem(this);
|
|
2992
|
+
}
|
|
2993
|
+
this._destroyed.next();
|
|
2994
|
+
this._destroyed.complete();
|
|
2995
|
+
this._dragRef.dispose();
|
|
2996
|
+
}
|
|
2997
|
+
/** Syncs the root element with the `DragRef`. */
|
|
2998
|
+
_updateRootElement() {
|
|
2999
|
+
const element = this.element.nativeElement;
|
|
3000
|
+
const rootElement = this.rootElementSelector ?
|
|
3001
|
+
getClosestMatchingAncestor(element, this.rootElementSelector) : element;
|
|
3002
|
+
if (rootElement && rootElement.nodeType !== this._document.ELEMENT_NODE) {
|
|
3003
|
+
throw Error(`cdkDrag must be attached to an element node. ` +
|
|
3004
|
+
`Currently attached to "${rootElement.nodeName}".`);
|
|
3005
|
+
}
|
|
3006
|
+
this._dragRef.withRootElement(rootElement || element);
|
|
3007
|
+
}
|
|
3008
|
+
/** Gets the boundary element, based on the `boundaryElement` value. */
|
|
3009
|
+
_getBoundaryElement() {
|
|
3010
|
+
const boundary = this.boundaryElement;
|
|
3011
|
+
if (!boundary) {
|
|
3012
|
+
return null;
|
|
3013
|
+
}
|
|
3014
|
+
if (typeof boundary === 'string') {
|
|
3015
|
+
return getClosestMatchingAncestor(this.element.nativeElement, boundary);
|
|
3016
|
+
}
|
|
3017
|
+
const element = coerceElement(boundary);
|
|
3018
|
+
if (isDevMode() && !element.contains(this.element.nativeElement)) {
|
|
3019
|
+
throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
|
|
3020
|
+
}
|
|
3021
|
+
return element;
|
|
3022
|
+
}
|
|
3023
|
+
/** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
|
|
3024
|
+
_syncInputs(ref) {
|
|
3025
|
+
ref.beforeStarted.subscribe(() => {
|
|
3026
|
+
if (!ref.isDragging()) {
|
|
3027
|
+
const dir = this._dir;
|
|
3028
|
+
const dragStartDelay = this.dragStartDelay;
|
|
3029
|
+
const placeholder = this._placeholderTemplate ? {
|
|
3030
|
+
template: this._placeholderTemplate.templateRef,
|
|
3031
|
+
context: this._placeholderTemplate.data,
|
|
3032
|
+
viewContainer: this._viewContainerRef
|
|
3033
|
+
} : null;
|
|
3034
|
+
const preview = this._previewTemplate ? {
|
|
3035
|
+
template: this._previewTemplate.templateRef,
|
|
3036
|
+
context: this._previewTemplate.data,
|
|
3037
|
+
matchSize: this._previewTemplate.matchSize,
|
|
3038
|
+
viewContainer: this._viewContainerRef
|
|
3039
|
+
} : null;
|
|
3017
3040
|
ref.disabled = this.disabled;
|
|
3018
3041
|
ref.lockAxis = this.lockAxis;
|
|
3019
|
-
ref.
|
|
3020
|
-
|
|
3042
|
+
ref.dragStartDelay = (typeof dragStartDelay === 'object' && dragStartDelay) ?
|
|
3043
|
+
dragStartDelay : coerceNumberProperty(dragStartDelay);
|
|
3044
|
+
ref.constrainPosition = this.constrainPosition;
|
|
3045
|
+
ref.previewClass = this.previewClass;
|
|
3021
3046
|
ref
|
|
3022
|
-
.
|
|
3023
|
-
.
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3047
|
+
.withBoundaryElement(this._getBoundaryElement())
|
|
3048
|
+
.withPlaceholderTemplate(placeholder)
|
|
3049
|
+
.withPreviewTemplate(preview);
|
|
3050
|
+
if (dir) {
|
|
3051
|
+
ref.withDirection(dir.value);
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
/** Handles the events from the underlying `DragRef`. */
|
|
3057
|
+
_handleEvents(ref) {
|
|
3058
|
+
ref.started.subscribe(() => {
|
|
3059
|
+
this.started.emit({ source: this });
|
|
3060
|
+
// Since all of these events run outside of change detection,
|
|
3061
|
+
// we need to ensure that everything is marked correctly.
|
|
3062
|
+
this._changeDetectorRef.markForCheck();
|
|
3063
|
+
});
|
|
3064
|
+
ref.released.subscribe(() => {
|
|
3065
|
+
this.released.emit({ source: this });
|
|
3066
|
+
});
|
|
3067
|
+
ref.ended.subscribe(event => {
|
|
3068
|
+
this.ended.emit({ source: this, distance: event.distance });
|
|
3069
|
+
// Since all of these events run outside of change detection,
|
|
3070
|
+
// we need to ensure that everything is marked correctly.
|
|
3071
|
+
this._changeDetectorRef.markForCheck();
|
|
3072
|
+
});
|
|
3073
|
+
ref.entered.subscribe(event => {
|
|
3074
|
+
this.entered.emit({
|
|
3075
|
+
container: event.container.data,
|
|
3076
|
+
item: this,
|
|
3077
|
+
currentIndex: event.currentIndex
|
|
3045
3078
|
});
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
item: event.item.data
|
|
3052
|
-
});
|
|
3079
|
+
});
|
|
3080
|
+
ref.exited.subscribe(event => {
|
|
3081
|
+
this.exited.emit({
|
|
3082
|
+
container: event.container.data,
|
|
3083
|
+
item: this
|
|
3053
3084
|
});
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
// Mark for check since all of these events run outside of change
|
|
3065
|
-
// detection and we're not guaranteed for something else to have triggered it.
|
|
3066
|
-
this._changeDetectorRef.markForCheck();
|
|
3085
|
+
});
|
|
3086
|
+
ref.dropped.subscribe(event => {
|
|
3087
|
+
this.dropped.emit({
|
|
3088
|
+
previousIndex: event.previousIndex,
|
|
3089
|
+
currentIndex: event.currentIndex,
|
|
3090
|
+
previousContainer: event.previousContainer.data,
|
|
3091
|
+
container: event.container.data,
|
|
3092
|
+
isPointerOverContainer: event.isPointerOverContainer,
|
|
3093
|
+
item: this,
|
|
3094
|
+
distance: event.distance
|
|
3067
3095
|
});
|
|
3096
|
+
});
|
|
3097
|
+
}
|
|
3098
|
+
/** Assigns the default input values based on a provided config object. */
|
|
3099
|
+
_assignDefaults(config) {
|
|
3100
|
+
const { lockAxis, dragStartDelay, constrainPosition, previewClass, boundaryElement, draggingDisabled, rootElementSelector } = config;
|
|
3101
|
+
this.disabled = draggingDisabled == null ? false : draggingDisabled;
|
|
3102
|
+
this.dragStartDelay = dragStartDelay || 0;
|
|
3103
|
+
if (lockAxis) {
|
|
3104
|
+
this.lockAxis = lockAxis;
|
|
3068
3105
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
const { lockAxis, draggingDisabled, sortingDisabled, listAutoScrollDisabled, listOrientation } = config;
|
|
3072
|
-
this.disabled = draggingDisabled == null ? false : draggingDisabled;
|
|
3073
|
-
this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled;
|
|
3074
|
-
this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled;
|
|
3075
|
-
this.orientation = listOrientation || 'vertical';
|
|
3076
|
-
if (lockAxis) {
|
|
3077
|
-
this.lockAxis = lockAxis;
|
|
3078
|
-
}
|
|
3106
|
+
if (constrainPosition) {
|
|
3107
|
+
this.constrainPosition = constrainPosition;
|
|
3079
3108
|
}
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
]
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
}
|
|
3129
|
-
|
|
3130
|
-
}
|
|
3109
|
+
if (previewClass) {
|
|
3110
|
+
this.previewClass = previewClass;
|
|
3111
|
+
}
|
|
3112
|
+
if (boundaryElement) {
|
|
3113
|
+
this.boundaryElement = boundaryElement;
|
|
3114
|
+
}
|
|
3115
|
+
if (rootElementSelector) {
|
|
3116
|
+
this.rootElementSelector = rootElementSelector;
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
CdkDrag.decorators = [
|
|
3121
|
+
{ type: Directive, args: [{
|
|
3122
|
+
selector: '[cdkDrag]',
|
|
3123
|
+
exportAs: 'cdkDrag',
|
|
3124
|
+
host: {
|
|
3125
|
+
'class': 'cdk-drag',
|
|
3126
|
+
'[class.cdk-drag-disabled]': 'disabled',
|
|
3127
|
+
'[class.cdk-drag-dragging]': '_dragRef.isDragging()',
|
|
3128
|
+
},
|
|
3129
|
+
providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
|
|
3130
|
+
},] }
|
|
3131
|
+
];
|
|
3132
|
+
CdkDrag.ctorParameters = () => [
|
|
3133
|
+
{ type: ElementRef },
|
|
3134
|
+
{ type: undefined, decorators: [{ type: Inject, args: [CDK_DROP_LIST,] }, { type: Optional }, { type: SkipSelf }] },
|
|
3135
|
+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
3136
|
+
{ type: NgZone },
|
|
3137
|
+
{ type: ViewContainerRef },
|
|
3138
|
+
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [CDK_DRAG_CONFIG,] }] },
|
|
3139
|
+
{ type: Directionality, decorators: [{ type: Optional }] },
|
|
3140
|
+
{ type: DragDrop },
|
|
3141
|
+
{ type: ChangeDetectorRef },
|
|
3142
|
+
{ type: CdkDragHandle, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [CDK_DRAG_HANDLE,] }] }
|
|
3143
|
+
];
|
|
3144
|
+
CdkDrag.propDecorators = {
|
|
3145
|
+
_handles: [{ type: ContentChildren, args: [CDK_DRAG_HANDLE, { descendants: true },] }],
|
|
3146
|
+
_previewTemplate: [{ type: ContentChild, args: [CDK_DRAG_PREVIEW,] }],
|
|
3147
|
+
_placeholderTemplate: [{ type: ContentChild, args: [CDK_DRAG_PLACEHOLDER,] }],
|
|
3148
|
+
data: [{ type: Input, args: ['cdkDragData',] }],
|
|
3149
|
+
lockAxis: [{ type: Input, args: ['cdkDragLockAxis',] }],
|
|
3150
|
+
rootElementSelector: [{ type: Input, args: ['cdkDragRootElement',] }],
|
|
3151
|
+
boundaryElement: [{ type: Input, args: ['cdkDragBoundary',] }],
|
|
3152
|
+
dragStartDelay: [{ type: Input, args: ['cdkDragStartDelay',] }],
|
|
3153
|
+
freeDragPosition: [{ type: Input, args: ['cdkDragFreeDragPosition',] }],
|
|
3154
|
+
disabled: [{ type: Input, args: ['cdkDragDisabled',] }],
|
|
3155
|
+
constrainPosition: [{ type: Input, args: ['cdkDragConstrainPosition',] }],
|
|
3156
|
+
previewClass: [{ type: Input, args: ['cdkDragPreviewClass',] }],
|
|
3157
|
+
started: [{ type: Output, args: ['cdkDragStarted',] }],
|
|
3158
|
+
released: [{ type: Output, args: ['cdkDragReleased',] }],
|
|
3159
|
+
ended: [{ type: Output, args: ['cdkDragEnded',] }],
|
|
3160
|
+
entered: [{ type: Output, args: ['cdkDragEntered',] }],
|
|
3161
|
+
exited: [{ type: Output, args: ['cdkDragExited',] }],
|
|
3162
|
+
dropped: [{ type: Output, args: ['cdkDragDropped',] }],
|
|
3163
|
+
moved: [{ type: Output, args: ['cdkDragMoved',] }]
|
|
3164
|
+
};
|
|
3165
|
+
/** Gets the closest ancestor of an element that matches a selector. */
|
|
3166
|
+
function getClosestMatchingAncestor(element, selector) {
|
|
3167
|
+
let currentElement = element.parentElement;
|
|
3168
|
+
while (currentElement) {
|
|
3169
|
+
// IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
|
|
3170
|
+
if (currentElement.matches ? currentElement.matches(selector) :
|
|
3171
|
+
currentElement.msMatchesSelector(selector)) {
|
|
3172
|
+
return currentElement;
|
|
3173
|
+
}
|
|
3174
|
+
currentElement = currentElement.parentElement;
|
|
3175
|
+
}
|
|
3176
|
+
return null;
|
|
3177
|
+
}
|
|
3131
3178
|
|
|
3132
3179
|
/**
|
|
3133
3180
|
* @license
|
|
@@ -3136,35 +3183,32 @@ let CdkDropList = /** @class */ (() => {
|
|
|
3136
3183
|
* Use of this source code is governed by an MIT-style license that can be
|
|
3137
3184
|
* found in the LICENSE file at https://angular.io/license
|
|
3138
3185
|
*/
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
];
|
|
3166
|
-
return DragDropModule;
|
|
3167
|
-
})();
|
|
3186
|
+
class DragDropModule {
|
|
3187
|
+
}
|
|
3188
|
+
DragDropModule.decorators = [
|
|
3189
|
+
{ type: NgModule, args: [{
|
|
3190
|
+
declarations: [
|
|
3191
|
+
CdkDropList,
|
|
3192
|
+
CdkDropListGroup,
|
|
3193
|
+
CdkDrag,
|
|
3194
|
+
CdkDragHandle,
|
|
3195
|
+
CdkDragPreview,
|
|
3196
|
+
CdkDragPlaceholder,
|
|
3197
|
+
],
|
|
3198
|
+
exports: [
|
|
3199
|
+
CdkScrollableModule,
|
|
3200
|
+
CdkDropList,
|
|
3201
|
+
CdkDropListGroup,
|
|
3202
|
+
CdkDrag,
|
|
3203
|
+
CdkDragHandle,
|
|
3204
|
+
CdkDragPreview,
|
|
3205
|
+
CdkDragPlaceholder,
|
|
3206
|
+
],
|
|
3207
|
+
providers: [
|
|
3208
|
+
DragDrop,
|
|
3209
|
+
]
|
|
3210
|
+
},] }
|
|
3211
|
+
];
|
|
3168
3212
|
|
|
3169
3213
|
/**
|
|
3170
3214
|
* @license
|
|
@@ -3178,5 +3222,5 @@ let DragDropModule = /** @class */ (() => {
|
|
|
3178
3222
|
* Generated bundle index. Do not edit.
|
|
3179
3223
|
*/
|
|
3180
3224
|
|
|
3181
|
-
export { CDK_DRAG_CONFIG,
|
|
3225
|
+
export { CDK_DRAG_CONFIG, CDK_DRAG_HANDLE, CDK_DRAG_PLACEHOLDER, CDK_DRAG_PREVIEW, CDK_DROP_LIST_GROUP, CdkDrag, CdkDragHandle, CdkDragPlaceholder, CdkDragPreview, CdkDropList, CdkDropListGroup, DragDrop, DragDropModule, DragDropRegistry, DragRef, DropListRef, copyArrayItem, moveItemInArray, transferArrayItem, CDK_DROP_LIST as ɵangular_material_src_cdk_drag_drop_drag_drop_b, CDK_DRAG_PARENT as ɵangular_material_src_cdk_drag_drop_drag_drop_c };
|
|
3182
3226
|
//# sourceMappingURL=drag-drop.js.map
|