UNPKG

@recruitler/drag-drop

Version:

A forked version of Angular/'s drag-drop CDK.

131 lines (130 loc) 5.88 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Direction } from '@angular/cdk/bidi'; import { ElementRef } from '@angular/core'; import { DragDropRegistry } from '../drag-drop-registry'; import { DropListSortStrategy, DropListSortStrategyItem, SortPredicate } from './drop-list-sort-strategy'; /** * Strategy that only supports sorting along a single axis. * Items are reordered using CSS transforms which allows for sorting to be animated. * @docs-private */ export declare class SingleAxisSortStrategy<T extends DropListSortStrategyItem> implements DropListSortStrategy<T> { private _element; private _dragDropRegistry; /** Function used to determine if an item can be sorted into a specific index. */ private _sortPredicate; /** Cache of the dimensions of all the items inside the container. */ private _itemPositions; /** * Draggable items that are currently active inside the container. Includes the items * that were there at the start of the sequence, as well as any items that have been dragged * in, but haven't been dropped yet. */ private _activeDraggables; /** Direction in which the list is oriented. */ orientation: 'vertical' | 'horizontal'; /** Layout direction of the drop list. */ direction: Direction; constructor(_element: HTMLElement | ElementRef<HTMLElement>, _dragDropRegistry: DragDropRegistry<T, unknown>); /** * Keeps track of the item that was last swapped with the dragged item, as well as what direction * the pointer was moving in when the swap occurred and whether the user's pointer continued to * overlap with the swapped item after the swapping occurred. */ private _previousSwap; /** * To be called when the drag sequence starts. * @param items Items that are currently in the list. */ start(items: readonly T[]): void; /** * To be called when an item is being sorted. * @param item Item to be sorted. * @param pointerX Position of the item along the X axis. * @param pointerY Position of the item along the Y axis. * @param pointerDelta Direction in which the pointer is moving along each axis. */ sort(item: T, pointerX: number, pointerY: number, pointerDelta: { x: number; y: number; }): { previousIndex: number; currentIndex: number; }; getActiveItem(index: number): T; /** * Called when an item is being moved into the container. * @param item Item that was moved into the container. * @param pointerX Position of the item along the X axis. * @param pointerY Position of the item along the Y axis. * @param index Index at which the item entered. If omitted, the container will try to figure it * out automatically. */ enter(item: T, pointerX: number, pointerY: number, index?: number): void; /** * Called when an item is being nested into the another item. * @param item Item that was nested into the target item. * @param pointerX Position of the item along the X axis. * @param pointerY Position of the item along the Y axis. * @param nestIndex Target Index at which the item will be neste. If omitted, the container will try to figure it * out automatically. */ nest(item: T, nestIndex: number, currentNestIndex: number): void; unnest(item: T, nestIndex: number): void; /** Sets the items that are currently part of the list. */ withItems(items: readonly T[]): void; /** Assigns a sort predicate to the strategy. */ withSortPredicate(predicate: SortPredicate<T>): void; /** Resets the strategy to its initial state before dragging was started. */ reset(): void; /** * Gets a snapshot of items currently in the list. * Can include items that we dragged in from another list. */ getActiveItemsSnapshot(): readonly T[]; /** Gets the index of a specific item. */ getItemIndex(item: T): number; /** Used to notify the strategy that the scroll position has changed. */ updateOnScroll(topDifference: number, leftDifference: number): void; /** Refreshes the position cache of the items and sibling containers. */ private _cacheItemPositions; /** * Gets the offset in pixels by which the item that is being dragged should be moved. * @param currentPosition Current position of the item. * @param newPosition Position of the item where the current item should be moved. * @param delta Direction in which the user is moving. */ private _getItemOffsetPx; /** * Gets the offset in pixels by which the items that aren't being dragged should be moved. * @param currentIndex Index of the item currently being dragged. * @param siblings All of the items in the list. * @param delta Direction in which the user is moving. */ private _getSiblingOffsetPx; /** * Checks if pointer is entering in the first position * @param pointerX Position of the user's pointer along the X axis. * @param pointerY Position of the user's pointer along the Y axis. */ private _shouldEnterAsFirstChild; /** * * @returns ClientRect values of all items */ getItemBoundaries(): ClientRect[]; /** * Gets the index of an item in the drop container, based on the position of the user's pointer. * @param item Item that is being sorted. * @param pointerX Position of the user's pointer along the X axis. * @param pointerY Position of the user's pointer along the Y axis. * @param delta Direction in which the user is moving their pointer. */ private _getItemIndexFromPointerPosition; }