MCPcopy Create free account
hub / github.com/angular/components / _updateActiveDropContainer

Method _updateActiveDropContainer

src/cdk/drag-drop/drag-ref.ts:1107–1167  ·  view source on GitHub ↗

* Updates the item's position in its drop container, or moves it * into a new one, depending on its current drag position.

({x, y}: Point, {x: rawX, y: rawY}: Point)

Source from the content-addressed store, hash-verified

1105 * into a new one, depending on its current drag position.
1106 */
1107 private _updateActiveDropContainer({x, y}: Point, {x: rawX, y: rawY}: Point) {
1108 // Drop container that draggable has been moved into.
1109 let newContainer = this._initialContainer._getSiblingContainerFromPosition(this, x, y);
1110
1111 // If we couldn't find a new container to move the item into, and the item has left its
1112 // initial container, check whether the it's over the initial container. This handles the
1113 // case where two containers are connected one way and the user tries to undo dragging an
1114 // item into a new container.
1115 if (
1116 !newContainer &&
1117 this._dropContainer !== this._initialContainer &&
1118 this._initialContainer._isOverContainer(x, y)
1119 ) {
1120 newContainer = this._initialContainer;
1121 }
1122
1123 if (newContainer && newContainer !== this._dropContainer) {
1124 this._ngZone.run(() => {
1125 const exitIndex = this._dropContainer!.getItemIndex(this);
1126 const nextItemElement =
1127 this._dropContainer!.getItemAtIndex(exitIndex + 1)?.getVisibleElement() || null;
1128
1129 // Notify the old container that the item has left.
1130 this.exited.next({item: this, container: this._dropContainer!});
1131 this._dropContainer!.exit(this);
1132 this._conditionallyInsertAnchor(newContainer, this._dropContainer!, nextItemElement);
1133 // Notify the new container that the item has entered.
1134 this._dropContainer = newContainer!;
1135 this._dropContainer.enter(
1136 this,
1137 x,
1138 y,
1139 // If we're re-entering the initial container and sorting is disabled,
1140 // put item the into its starting index to begin with.
1141 newContainer === this._initialContainer && newContainer.sortingDisabled
1142 ? this._initialIndex
1143 : undefined,
1144 );
1145 this.entered.next({
1146 item: this,
1147 container: newContainer!,
1148 currentIndex: newContainer!.getItemIndex(this),
1149 });
1150 });
1151 }
1152
1153 // Dragging may have been interrupted as a result of the events above.
1154 if (this.isDragging()) {
1155 this._dropContainer!._startScrollingIfNecessary(rawX, rawY);
1156 this._dropContainer!._sortItem(this, x, y, this._pointerDirectionDelta);
1157
1158 if (this.constrainPosition) {
1159 this._applyPreviewTransform(x, y);
1160 } else {
1161 this._applyPreviewTransform(
1162 x - this._pickupPositionInElement.x,
1163 y - this._pickupPositionInElement.y,
1164 );

Callers 2

DragRefClass · 0.95

Calls 13

isDraggingMethod · 0.95
_isOverContainerMethod · 0.80
getVisibleElementMethod · 0.80
_sortItemMethod · 0.80
getItemIndexMethod · 0.65
getItemAtIndexMethod · 0.65
enterMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected