├── .travis.yml ├── .codesandbox └── ci.json ├── src ├── .stories │ ├── grouping-items │ │ ├── Item │ │ │ ├── index.js │ │ │ ├── Item.js │ │ │ └── Item.scss │ │ ├── List │ │ │ ├── index.js │ │ │ ├── List.scss │ │ │ └── List.js │ │ ├── utils.js │ │ └── index.js │ ├── interactive-elements-stress-test │ │ ├── Item │ │ │ ├── index.js │ │ │ ├── Item.js │ │ │ └── Item.scss │ │ ├── List.js │ │ └── index.js │ ├── Storybook.scss │ └── index.js ├── SortableContainer │ ├── defaultGetHelperDimensions.js │ ├── defaultShouldCancelStart.js │ ├── props.js │ └── index.js ├── index.js ├── Manager │ └── index.js ├── SortableHandle │ └── index.js ├── AutoScroller │ └── index.js ├── SortableElement │ └── index.js └── utils.js ├── .npmignore ├── .gitignore ├── .prettierrc ├── .github └── assets │ └── react-sortable-hoc-logo.png ├── examples ├── .eslintrc.json ├── basic.js ├── drag-handle.js ├── react-infinite.js ├── collections.js ├── react-virtualized-table-columns.js └── react-virtualized.js ├── .storybook ├── config.js ├── webpack.config.js ├── theme.js └── manager-head.html ├── .editorconfig ├── .eslintrc.json ├── LICENSE ├── rollup.config.js ├── package.json ├── types └── index.d.ts ├── CHANGELOG.md └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 10 4 | -------------------------------------------------------------------------------- /.codesandbox/ci.json: -------------------------------------------------------------------------------- 1 | { 2 | "sandboxes": ["react", "o104x95y86"] 3 | } 4 | -------------------------------------------------------------------------------- /src/.stories/grouping-items/Item/index.js: -------------------------------------------------------------------------------- 1 | import Item from './Item'; 2 | 3 | export default Item; 4 | -------------------------------------------------------------------------------- /src/.stories/grouping-items/List/index.js: -------------------------------------------------------------------------------- 1 | import List from './List'; 2 | 3 | export default List; 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github 2 | .babelrc 3 | coverage 4 | src 5 | test 6 | .* 7 | *.md 8 | codecov.yml 9 | .travis.yml 10 | -------------------------------------------------------------------------------- /src/.stories/interactive-elements-stress-test/Item/index.js: -------------------------------------------------------------------------------- 1 | import Item from './Item'; 2 | 3 | export default Item; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | node_modules 3 | dist 4 | styles.min.css 5 | styles.min.css.map 6 | coverage 7 | npm-debug.log 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "bracketSpacing": false, 4 | "singleQuote": true, 5 | "trailingComma": "all" 6 | } 7 | -------------------------------------------------------------------------------- /.github/assets/react-sortable-hoc-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clauderic/react-sortable-hoc/HEAD/.github/assets/react-sortable-hoc-logo.png -------------------------------------------------------------------------------- /src/.stories/grouping-items/utils.js: -------------------------------------------------------------------------------- 1 | export function generateItems(length) { 2 | return Array.from(Array(length), (_, index) => index.toString()); 3 | } 4 | -------------------------------------------------------------------------------- /examples/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "import/no-unresolved": "off", 4 | "react/prop-types": "off", 5 | "react/no-array-index-key": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/SortableContainer/defaultGetHelperDimensions.js: -------------------------------------------------------------------------------- 1 | export default function defaultGetHelperDimensions({node}) { 2 | return { 3 | height: node.offsetHeight, 4 | width: node.offsetWidth, 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import {addParameters, configure} from '@storybook/react'; 2 | import theme from './theme'; 3 | 4 | addParameters({ 5 | options: { 6 | showAddonPanel: false, 7 | theme, 8 | }, 9 | }); 10 | 11 | function loadStories() { 12 | require('../src/.stories/index.js'); 13 | } 14 | 15 | configure(loadStories, module); 16 | -------------------------------------------------------------------------------- /src/.stories/interactive-elements-stress-test/Item/Item.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {sortableElement} from '../../../../src'; 3 | 4 | import styles from './Item.scss'; 5 | 6 | function Item(props) { 7 | const {children} = props; 8 | 9 | return ( 10 |
= (props: P) => JSX.Element; 105 | 106 | export type WrappedComponent
= 107 | | React.ComponentClass
108 | | React.SFC
109 | | WrappedComponentFactory
; 110 | 111 | export function SortableContainer
( 112 | wrappedComponent: WrappedComponent
, 113 | config?: Config, 114 | ): React.ComponentClass
; 115 | 116 | export function SortableElement
( 117 | wrappedComponent: WrappedComponent
, 118 | config?: Config, 119 | ): React.ComponentClass
; 120 | 121 | export function SortableHandle
( 122 | wrappedComponent: WrappedComponent
, 123 | config?: Config, 124 | ): React.ComponentClass
;
125 |
126 | export function arrayMove items[index].height}
316 | estimatedRowSize={itemHeight}
317 | rowRenderer={({index, style}) => {
318 | const {value, height} = items[index];
319 | return (
320 |
9 |
10 | #
11 |
12 | > A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list
13 |
14 | [](https://www.npmjs.com/package/react-sortable-hoc)
15 | [](https://www.npmjs.com/package/react-sortable-hoc)
16 | [](https://github.com/clauderic/react-sortable-hoc/blob/master/LICENSE)
17 | [](https://gitter.im/clauderic/react-sortable-hoc)
18 | 
19 |
20 | ### Examples available here: http://clauderic.github.io/react-sortable-hoc/
21 |
22 | ## Features
23 |
24 | - **Higher Order Components** – Integrates with your existing components
25 | - **Drag handle, auto-scrolling, locked axis, events, and more!**
26 | - **Suuuper smooth animations** – Chasing the 60FPS dream 🌈
27 | - **Works with virtualization libraries: [react-virtualized](https://github.com/bvaughn/react-virtualized/), [react-tiny-virtual-list](https://github.com/clauderic/react-tiny-virtual-list), [react-infinite](https://github.com/seatgeek/react-infinite), etc.**
28 | - **Horizontal lists, vertical lists, or a grid** ↔ ↕ ⤡
29 | - **Touch support** 👌
30 | - **Accessible: supports keyboard sorting**
31 |
32 | ## Installation
33 |
34 | Using [npm](https://www.npmjs.com/package/react-sortable-hoc):
35 |
36 | $ npm install react-sortable-hoc --save
37 |
38 | Then, using a module bundler that supports either CommonJS or ES2015 modules, such as [webpack](https://github.com/webpack/webpack):
39 |
40 | ```js
41 | // Using an ES6 transpiler like Babel
42 | import {SortableContainer, SortableElement} from 'react-sortable-hoc';
43 |
44 | // Not using an ES6 transpiler
45 | var Sortable = require('react-sortable-hoc');
46 | var SortableContainer = Sortable.SortableContainer;
47 | var SortableElement = Sortable.SortableElement;
48 | ```
49 |
50 | Alternatively, an UMD build is also available:
51 |
52 | ```html
53 |
54 | ```
55 |
56 | ## Usage
57 |
58 | ### Basic Example
59 |
60 | ```js
61 | import React, {Component} from 'react';
62 | import {render} from 'react-dom';
63 | import {SortableContainer, SortableElement} from 'react-sortable-hoc';
64 | import arrayMove from 'array-move';
65 |
66 | const SortableItem = SortableElement(({value}) =>
71 | {items.map((value, index) => (
72 |
75 | );
76 | });
77 |
78 | class SortableComponent extends Component {
79 | state = {
80 | items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6'],
81 | };
82 | onSortEnd = ({oldIndex, newIndex}) => {
83 | this.setState(({items}) => ({
84 | items: arrayMove(items, oldIndex, newIndex),
85 | }));
86 | };
87 | render() {
88 | return
`lift: [32],`
`drop: [32],`
`cancel: [27],`
`up: [38, 37],`
`down: [40, 39]`
`}` | An object containing an array of keycodes for each keyboard-accessible action. |
115 | | pressDelay | Number | `0` | If you'd like elements to only become sortable after being pressed for a certain time, change this property. A good sensible default value for mobile is `200`. Cannot be used in conjunction with the `distance` prop. |
116 | | pressThreshold | Number | `5` | Number of pixels of movement to tolerate before ignoring a press event. |
117 | | distance | Number | `0` | If you'd like elements to only become sortable after being dragged a certain number of pixels. Cannot be used in conjunction with the `pressDelay` prop. |
118 | | shouldCancelStart | Function | [Function](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L48) | This function is invoked before sorting begins, and can be used to programatically cancel sorting before it begins. By default, it will cancel sorting if the event target is either an `input`, `textarea`, `select`, `option`, or `button`. |
119 | | updateBeforeSortStart | Function | | This function is invoked before sorting begins. It can return a promise, allowing you to run asynchronous updates (such as `setState`) before sorting begins. `function({node, index, collection, isKeySorting}, event)` |
120 | | onSortStart | Function | | Callback that is invoked when sorting begins. `function({node, index, collection, isKeySorting}, event)` |
121 | | onSortMove | Function | | Callback that is invoked during sorting as the cursor moves. `function(event)` |
122 | | onSortOver | Function | | Callback that is invoked when moving over an item. `function({index, oldIndex, newIndex, collection, isKeySorting}, e)` |
123 | | onSortEnd | Function | | Callback that is invoked when sorting ends. `function({oldIndex, newIndex, collection, isKeySorting}, e)` |
124 | | useDragHandle | Boolean | `false` | If you're using the `SortableHandle` HOC, set this to `true` |
125 | | useWindowAsScrollContainer | Boolean | `false` | If you want, you can set the `window` as the scrolling container |
126 | | hideSortableGhost | Boolean | `true` | Whether to auto-hide the ghost element. By default, as a convenience, React Sortable List will automatically hide the element that is currently being sorted. Set this to false if you would like to apply your own styling. |
127 | | lockToContainerEdges | Boolean | `false` | You can lock movement of the sortable element to it's parent `SortableContainer` |
128 | | lockOffset | `OffsetValue`\* | [`OffsetValue`\*, `OffsetValue`\*] | `"50%"` | When`lockToContainerEdges`is set to`true`, this controls the offset distance between the sortable helper and the top/bottom edges of it's parent`SortableContainer`. Percentage values are relative to the height of the item currently being sorted. If you wish to specify different behaviours for locking to the _top_ of the container vs the _bottom_, you may also pass in an`array`(For example:`["0%", "100%"]`). |
129 | | getContainer | Function | | Optional function to return the scrollable container element. This property defaults to the `SortableContainer` element itself or (if `useWindowAsScrollContainer` is true) the window. Use this function to specify a custom container object (eg this is useful for integrating with certain 3rd party components such as `FlexTable`). This function is passed a single parameter (the `wrappedInstance` React element) and it is expected to return a DOM element. |
130 | | getHelperDimensions | Function | [Function](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L74-L77) | Optional `function({node, index, collection})` that should return the computed dimensions of the SortableHelper. See [default implementation](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/defaultGetHelperDimensions.js) for more details |
131 | | helperContainer | HTMLElement | Function | `document.body` | By default, the cloned sortable helper is appended to the document body. Use this prop to specify a different container for the sortable clone to be appended to. Accepts an `HTMLElement` or a function returning an `HTMLElement` that will be invoked before right before sorting begins |
132 | | disableAutoscroll | Boolean | `false` | Disables autoscrolling while dragging |
133 |
134 | \* `OffsetValue` can either be a finite `Number` or a `String` made up of a number and a unit (`px` or `%`).
135 | Examples: `10` (which is the same as `"10px"`), `"50%"`
136 |
137 | #### SortableElement HOC
138 |
139 | | Property | Type | Default | Required? | Description |
140 | | :--------- | :--------------- | :------ | :-------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
141 | | index | Number | | ✓ | This is the element's sortableIndex within it's collection. This prop is required. |
142 | | collection | Number or String | `0` | | The collection the element is part of. This is useful if you have multiple groups of sortable elements within the same `SortableContainer`. [Example](http://clauderic.github.io/react-sortable-hoc/#/basic-configuration/multiple-lists) |
143 | | disabled | Boolean | `false` | | Whether the element should be sortable or not |
144 |
145 | ## FAQ
146 |
147 | ### Running Examples
148 |
149 | In root folder, run the following commands to launch React Storybook:
150 |
151 | ```
152 | $ npm install
153 | $ npm start
154 | ```
155 |
156 | ### Accessibility
157 |
158 | React Sortable HOC supports keyboard sorting out of the box. To enable it, make sure your `SortableElement` or `SortableHandle` is focusable. This can be done by setting `tabIndex={0}` on the outermost HTML node rendered by the component you're enhancing with `SortableElement` or `SortableHandle`.
159 |
160 | Once an item is focused/tabbed to, pressing `SPACE` picks it up, `ArrowUp` or `ArrowLeft` moves it one place backward in the list, `ArrowDown` or `ArrowRight` moves items one place forward in the list, pressing `SPACE` again drops the item in its new position. Pressing `ESC` before the item is dropped will cancel the sort operations.
161 |
162 | ### Grid support
163 |
164 | Need to sort items in a grid? We've got you covered! Just set the `axis` prop to `xy`. Grid support is currently limited to a setup where all the cells in the grid have the same width and height, though we're working hard to get variable width support in the near future.
165 |
166 | ### Item disappearing when sorting / CSS issues
167 |
168 | Upon sorting, `react-sortable-hoc` creates a clone of the element you are sorting (the _sortable-helper_) and appends it to the end of the `` tag. The original element will still be in-place to preserve its position in the DOM until the end of the drag (with inline-styling to make it invisible). If the _sortable-helper_ gets messed up from a CSS standpoint, consider that maybe your selectors to the draggable item are dependent on a parent element which isn't present anymore (again, since the _sortable-helper_ is at the end of the ``). This can also be a `z-index` issue, for example, when using `react-sortable-hoc` within a Bootstrap modal, you'll need to increase the `z-index` of the SortableHelper so it is displayed on top of the modal (see [#87](https://github.com/clauderic/react-sortable-hoc/issues/87) for more details).
169 |
170 | ### Click events being swallowed
171 |
172 | By default, `react-sortable-hoc` is triggered immediately on `mousedown`. If you'd like to prevent this behaviour, there are a number of strategies readily available. You can use the `distance` prop to set a minimum distance (in pixels) to be dragged before sorting is enabled. You can also use the `pressDelay` prop to add a delay before sorting is enabled. Alternatively, you can also use the [SortableHandle](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableHandle/index.js) HOC.
173 |
174 | ### Wrapper props not passed down to wrapped Component
175 |
176 | All props for `SortableContainer` and `SortableElement` listed above are intentionally consumed by the wrapper component and are **not** passed down to the wrapped component. To make them available pass down the desired prop again with a different name. E.g.:
177 |
178 | ```js
179 | const SortableItem = SortableElement(({value, sortIndex}) => (
180 |
188 | {items.map((value, index) => (
189 |
197 | );
198 | });
199 | ```
200 |
201 | ## Dependencies
202 |
203 | React Sortable HOC only depends on [invariant](https://github.com/zertosh/invariant). It has the following peerDependencies: `react`, `react-dom`
204 |
205 | ## Reporting Issues
206 |
207 | If believe you've found an issue, please [report it](https://github.com/clauderic/react-sortable-hoc/issues) along with any relevant details to reproduce it. The easiest way to do so is to fork the `react-sortable-hoc` basic setup sandbox on [CodeSandbox](https://codesandbox.io/s/o104x95y86):
208 |
209 | [](https://codesandbox.io/s/react-sortable-hoc-starter-o104x95y86)
210 |
211 | ## Asking for help
212 |
213 | Please do not use the issue tracker for personal support requests. Instead, use [Gitter](https://gitter.im/clauderic/react-sortable-hoc) or StackOverflow.
214 |
215 | ## Contributions
216 |
217 | Yes please! Feature requests / pull requests are welcome.
218 |
--------------------------------------------------------------------------------
/src/SortableContainer/index.js:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import {findDOMNode} from 'react-dom';
3 | import invariant from 'invariant';
4 |
5 | import Manager from '../Manager';
6 | import {isSortableHandle} from '../SortableHandle';
7 |
8 | import {
9 | cloneNode,
10 | closest,
11 | events,
12 | getScrollingParent,
13 | getContainerGridGap,
14 | getEdgeOffset,
15 | getElementMargin,
16 | getLockPixelOffsets,
17 | getPosition,
18 | isTouchEvent,
19 | limit,
20 | NodeType,
21 | omit,
22 | provideDisplayName,
23 | setInlineStyles,
24 | setTransitionDuration,
25 | setTranslate3d,
26 | getTargetIndex,
27 | getScrollAdjustedBoundingClientRect,
28 | } from '../utils';
29 |
30 | import AutoScroller from '../AutoScroller';
31 | import {
32 | defaultProps,
33 | omittedProps,
34 | propTypes,
35 | validateProps,
36 | defaultKeyCodes,
37 | } from './props';
38 |
39 | export const SortableContext = React.createContext({
40 | manager: {},
41 | });
42 |
43 | export default function sortableContainer(
44 | WrappedComponent,
45 | config = {withRef: false},
46 | ) {
47 | return class WithSortableContainer extends React.Component {
48 | constructor(props) {
49 | super(props);
50 | const manager = new Manager();
51 |
52 | validateProps(props);
53 |
54 | this.manager = manager;
55 | this.wrappedInstance = React.createRef();
56 | this.sortableContextValue = {manager};
57 | this.events = {
58 | end: this.handleEnd,
59 | move: this.handleMove,
60 | start: this.handleStart,
61 | };
62 | }
63 |
64 | state = {};
65 |
66 | static displayName = provideDisplayName('sortableList', WrappedComponent);
67 | static defaultProps = defaultProps;
68 | static propTypes = propTypes;
69 |
70 | componentDidMount() {
71 | const {useWindowAsScrollContainer} = this.props;
72 | const container = this.getContainer();
73 |
74 | Promise.resolve(container).then((containerNode) => {
75 | this.container = containerNode;
76 | this.document = this.container.ownerDocument || document;
77 |
78 | /*
79 | * Set our own default rather than using defaultProps because Jest
80 | * snapshots will serialize window, causing a RangeError
81 | * https://github.com/clauderic/react-sortable-hoc/issues/249
82 | */
83 | const contentWindow =
84 | this.props.contentWindow || this.document.defaultView || window;
85 |
86 | this.contentWindow =
87 | typeof contentWindow === 'function' ? contentWindow() : contentWindow;
88 |
89 | this.scrollContainer = useWindowAsScrollContainer
90 | ? this.document.scrollingElement || this.document.documentElement
91 | : getScrollingParent(this.container) || this.container;
92 |
93 | this.autoScroller = new AutoScroller(
94 | this.scrollContainer,
95 | this.onAutoScroll,
96 | );
97 |
98 | Object.keys(this.events).forEach((key) =>
99 | events[key].forEach((eventName) =>
100 | this.container.addEventListener(eventName, this.events[key], false),
101 | ),
102 | );
103 |
104 | this.container.addEventListener('keydown', this.handleKeyDown);
105 | });
106 | }
107 |
108 | componentWillUnmount() {
109 | if (this.helper && this.helper.parentNode) {
110 | this.helper.parentNode.removeChild(this.helper);
111 | }
112 | if (!this.container) {
113 | return;
114 | }
115 |
116 | Object.keys(this.events).forEach((key) =>
117 | events[key].forEach((eventName) =>
118 | this.container.removeEventListener(eventName, this.events[key]),
119 | ),
120 | );
121 | this.container.removeEventListener('keydown', this.handleKeyDown);
122 | }
123 |
124 | handleStart = (event) => {
125 | const {distance, shouldCancelStart} = this.props;
126 |
127 | if (event.button === 2 || shouldCancelStart(event)) {
128 | return;
129 | }
130 |
131 | this.touched = true;
132 | this.position = getPosition(event);
133 |
134 | const node = closest(event.target, (el) => el.sortableInfo != null);
135 |
136 | if (
137 | node &&
138 | node.sortableInfo &&
139 | this.nodeIsChild(node) &&
140 | !this.state.sorting
141 | ) {
142 | const {useDragHandle} = this.props;
143 | const {index, collection, disabled} = node.sortableInfo;
144 |
145 | if (disabled) {
146 | return;
147 | }
148 |
149 | if (useDragHandle && !closest(event.target, isSortableHandle)) {
150 | return;
151 | }
152 |
153 | this.manager.active = {collection, index};
154 |
155 | /*
156 | * Fixes a bug in Firefox where the :active state of anchor tags
157 | * prevent subsequent 'mousemove' events from being fired
158 | * (see https://github.com/clauderic/react-sortable-hoc/issues/118)
159 | */
160 | if (!isTouchEvent(event) && event.target.tagName === NodeType.Anchor) {
161 | event.preventDefault();
162 | }
163 |
164 | if (!distance) {
165 | if (this.props.pressDelay === 0) {
166 | this.handlePress(event);
167 | } else {
168 | this.pressTimer = setTimeout(
169 | () => this.handlePress(event),
170 | this.props.pressDelay,
171 | );
172 | }
173 | }
174 | }
175 | };
176 |
177 | nodeIsChild = (node) => {
178 | return node.sortableInfo.manager === this.manager;
179 | };
180 |
181 | handleMove = (event) => {
182 | const {distance, pressThreshold} = this.props;
183 |
184 | if (
185 | !this.state.sorting &&
186 | this.touched &&
187 | !this._awaitingUpdateBeforeSortStart
188 | ) {
189 | const position = getPosition(event);
190 | const delta = {
191 | x: this.position.x - position.x,
192 | y: this.position.y - position.y,
193 | };
194 | const combinedDelta = Math.abs(delta.x) + Math.abs(delta.y);
195 |
196 | this.delta = delta;
197 |
198 | if (!distance && (!pressThreshold || combinedDelta >= pressThreshold)) {
199 | clearTimeout(this.cancelTimer);
200 | this.cancelTimer = setTimeout(this.cancel, 0);
201 | } else if (
202 | distance &&
203 | combinedDelta >= distance &&
204 | this.manager.isActive()
205 | ) {
206 | this.handlePress(event);
207 | }
208 | }
209 | };
210 |
211 | handleEnd = () => {
212 | this.touched = false;
213 | this.cancel();
214 | };
215 |
216 | cancel = () => {
217 | const {distance} = this.props;
218 | const {sorting} = this.state;
219 |
220 | if (!sorting) {
221 | if (!distance) {
222 | clearTimeout(this.pressTimer);
223 | }
224 | this.manager.active = null;
225 | }
226 | };
227 |
228 | handlePress = async (event) => {
229 | const active = this.manager.getActive();
230 |
231 | if (active) {
232 | const {
233 | axis,
234 | getHelperDimensions,
235 | helperClass,
236 | hideSortableGhost,
237 | updateBeforeSortStart,
238 | onSortStart,
239 | useWindowAsScrollContainer,
240 | } = this.props;
241 | const {node, collection} = active;
242 | const {isKeySorting} = this.manager;
243 |
244 | if (typeof updateBeforeSortStart === 'function') {
245 | this._awaitingUpdateBeforeSortStart = true;
246 |
247 | try {
248 | const {index} = node.sortableInfo;
249 | await updateBeforeSortStart(
250 | {collection, index, node, isKeySorting},
251 | event,
252 | );
253 | } finally {
254 | this._awaitingUpdateBeforeSortStart = false;
255 | }
256 | }
257 |
258 | // Need to get the latest value for `index` in case it changes during `updateBeforeSortStart`
259 | const {index} = node.sortableInfo;
260 | const margin = getElementMargin(node);
261 | const gridGap = getContainerGridGap(this.container);
262 | const containerBoundingRect = this.scrollContainer.getBoundingClientRect();
263 | const dimensions = getHelperDimensions({index, node, collection});
264 |
265 | this.node = node;
266 | this.margin = margin;
267 | this.gridGap = gridGap;
268 | this.width = dimensions.width;
269 | this.height = dimensions.height;
270 | this.marginOffset = {
271 | x: this.margin.left + this.margin.right + this.gridGap.x,
272 | y: Math.max(this.margin.top, this.margin.bottom, this.gridGap.y),
273 | };
274 | this.boundingClientRect = node.getBoundingClientRect();
275 | this.containerBoundingRect = containerBoundingRect;
276 | this.index = index;
277 | this.newIndex = index;
278 |
279 | this.axis = {
280 | x: axis.indexOf('x') >= 0,
281 | y: axis.indexOf('y') >= 0,
282 | };
283 | this.offsetEdge = getEdgeOffset(node, this.container);
284 |
285 | if (isKeySorting) {
286 | this.initialOffset = getPosition({
287 | ...event,
288 | pageX: this.boundingClientRect.left,
289 | pageY: this.boundingClientRect.top,
290 | });
291 | } else {
292 | this.initialOffset = getPosition(event);
293 | }
294 |
295 | this.initialScroll = {
296 | left: this.scrollContainer.scrollLeft,
297 | top: this.scrollContainer.scrollTop,
298 | };
299 |
300 | this.initialWindowScroll = {
301 | left: window.pageXOffset,
302 | top: window.pageYOffset,
303 | };
304 |
305 | this.helper = this.helperContainer.appendChild(cloneNode(node));
306 |
307 | setInlineStyles(this.helper, {
308 | boxSizing: 'border-box',
309 | height: `${this.height}px`,
310 | left: `${this.boundingClientRect.left - margin.left}px`,
311 | pointerEvents: 'none',
312 | position: 'fixed',
313 | top: `${this.boundingClientRect.top - margin.top}px`,
314 | width: `${this.width}px`,
315 | });
316 |
317 | if (isKeySorting) {
318 | this.helper.focus();
319 | }
320 |
321 | if (hideSortableGhost) {
322 | this.sortableGhost = node;
323 |
324 | setInlineStyles(node, {
325 | opacity: 0,
326 | visibility: 'hidden',
327 | });
328 | }
329 |
330 | this.minTranslate = {};
331 | this.maxTranslate = {};
332 |
333 | if (isKeySorting) {
334 | const {
335 | top: containerTop,
336 | left: containerLeft,
337 | width: containerWidth,
338 | height: containerHeight,
339 | } = useWindowAsScrollContainer
340 | ? {
341 | top: 0,
342 | left: 0,
343 | width: this.contentWindow.innerWidth,
344 | height: this.contentWindow.innerHeight,
345 | }
346 | : this.containerBoundingRect;
347 | const containerBottom = containerTop + containerHeight;
348 | const containerRight = containerLeft + containerWidth;
349 |
350 | if (this.axis.x) {
351 | this.minTranslate.x = containerLeft - this.boundingClientRect.left;
352 | this.maxTranslate.x =
353 | containerRight - (this.boundingClientRect.left + this.width);
354 | }
355 |
356 | if (this.axis.y) {
357 | this.minTranslate.y = containerTop - this.boundingClientRect.top;
358 | this.maxTranslate.y =
359 | containerBottom - (this.boundingClientRect.top + this.height);
360 | }
361 | } else {
362 | if (this.axis.x) {
363 | this.minTranslate.x =
364 | (useWindowAsScrollContainer ? 0 : containerBoundingRect.left) -
365 | this.boundingClientRect.left -
366 | this.width / 2;
367 | this.maxTranslate.x =
368 | (useWindowAsScrollContainer
369 | ? this.contentWindow.innerWidth
370 | : containerBoundingRect.left + containerBoundingRect.width) -
371 | this.boundingClientRect.left -
372 | this.width / 2;
373 | }
374 |
375 | if (this.axis.y) {
376 | this.minTranslate.y =
377 | (useWindowAsScrollContainer ? 0 : containerBoundingRect.top) -
378 | this.boundingClientRect.top -
379 | this.height / 2;
380 | this.maxTranslate.y =
381 | (useWindowAsScrollContainer
382 | ? this.contentWindow.innerHeight
383 | : containerBoundingRect.top + containerBoundingRect.height) -
384 | this.boundingClientRect.top -
385 | this.height / 2;
386 | }
387 | }
388 |
389 | if (helperClass) {
390 | helperClass
391 | .split(' ')
392 | .forEach((className) => this.helper.classList.add(className));
393 | }
394 |
395 | this.listenerNode = event.touches ? event.target : this.contentWindow;
396 |
397 | if (isKeySorting) {
398 | this.listenerNode.addEventListener('wheel', this.handleKeyEnd, true);
399 | this.listenerNode.addEventListener(
400 | 'mousedown',
401 | this.handleKeyEnd,
402 | true,
403 | );
404 | this.listenerNode.addEventListener('keydown', this.handleKeyDown);
405 | } else {
406 | events.move.forEach((eventName) =>
407 | this.listenerNode.addEventListener(
408 | eventName,
409 | this.handleSortMove,
410 | false,
411 | ),
412 | );
413 | events.end.forEach((eventName) =>
414 | this.listenerNode.addEventListener(
415 | eventName,
416 | this.handleSortEnd,
417 | false,
418 | ),
419 | );
420 | }
421 |
422 | this.setState({
423 | sorting: true,
424 | sortingIndex: index,
425 | });
426 |
427 | if (onSortStart) {
428 | onSortStart(
429 | {
430 | node,
431 | index,
432 | collection,
433 | isKeySorting,
434 | nodes: this.manager.getOrderedRefs(),
435 | helper: this.helper,
436 | },
437 | event,
438 | );
439 | }
440 |
441 | if (isKeySorting) {
442 | // Readjust positioning in case re-rendering occurs onSortStart
443 | this.keyMove(0);
444 | }
445 | }
446 | };
447 |
448 | handleSortMove = (event) => {
449 | const {onSortMove} = this.props;
450 |
451 | // Prevent scrolling on mobile
452 | if (typeof event.preventDefault === 'function' && event.cancelable) {
453 | event.preventDefault();
454 | }
455 |
456 | this.updateHelperPosition(event);
457 | this.animateNodes();
458 | this.autoscroll();
459 |
460 | if (onSortMove) {
461 | onSortMove(event);
462 | }
463 | };
464 |
465 | handleSortEnd = (event) => {
466 | const {hideSortableGhost, onSortEnd} = this.props;
467 | const {
468 | active: {collection},
469 | isKeySorting,
470 | } = this.manager;
471 | const nodes = this.manager.getOrderedRefs();
472 |
473 | // Remove the event listeners if the node is still in the DOM
474 | if (this.listenerNode) {
475 | if (isKeySorting) {
476 | this.listenerNode.removeEventListener(
477 | 'wheel',
478 | this.handleKeyEnd,
479 | true,
480 | );
481 | this.listenerNode.removeEventListener(
482 | 'mousedown',
483 | this.handleKeyEnd,
484 | true,
485 | );
486 | this.listenerNode.removeEventListener('keydown', this.handleKeyDown);
487 | } else {
488 | events.move.forEach((eventName) =>
489 | this.listenerNode.removeEventListener(
490 | eventName,
491 | this.handleSortMove,
492 | ),
493 | );
494 | events.end.forEach((eventName) =>
495 | this.listenerNode.removeEventListener(
496 | eventName,
497 | this.handleSortEnd,
498 | ),
499 | );
500 | }
501 | }
502 |
503 | // Remove the helper from the DOM
504 | this.helper.parentNode.removeChild(this.helper);
505 |
506 | if (hideSortableGhost && this.sortableGhost) {
507 | setInlineStyles(this.sortableGhost, {
508 | opacity: '',
509 | visibility: '',
510 | });
511 | }
512 |
513 | for (let i = 0, len = nodes.length; i < len; i++) {
514 | const node = nodes[i];
515 | const el = node.node;
516 |
517 | // Clear the cached offset/boundingClientRect
518 | node.edgeOffset = null;
519 | node.boundingClientRect = null;
520 |
521 | // Remove the transforms / transitions
522 | setTranslate3d(el, null);
523 | setTransitionDuration(el, null);
524 | node.translate = null;
525 | }
526 |
527 | // Stop autoscroll
528 | this.autoScroller.clear();
529 |
530 | // Update manager state
531 | this.manager.active = null;
532 | this.manager.isKeySorting = false;
533 |
534 | this.setState({
535 | sorting: false,
536 | sortingIndex: null,
537 | });
538 |
539 | if (typeof onSortEnd === 'function') {
540 | onSortEnd(
541 | {
542 | collection,
543 | newIndex: this.newIndex,
544 | oldIndex: this.index,
545 | isKeySorting,
546 | nodes,
547 | },
548 | event,
549 | );
550 | }
551 |
552 | this.touched = false;
553 | };
554 |
555 | updateHelperPosition(event) {
556 | const {
557 | lockAxis,
558 | lockOffset,
559 | lockToContainerEdges,
560 | transitionDuration,
561 | keyboardSortingTransitionDuration = transitionDuration,
562 | } = this.props;
563 | const {isKeySorting} = this.manager;
564 | const {ignoreTransition} = event;
565 |
566 | const offset = getPosition(event);
567 | const translate = {
568 | x: offset.x - this.initialOffset.x,
569 | y: offset.y - this.initialOffset.y,
570 | };
571 |
572 | // Adjust for window scroll
573 | translate.y -= window.pageYOffset - this.initialWindowScroll.top;
574 | translate.x -= window.pageXOffset - this.initialWindowScroll.left;
575 |
576 | this.translate = translate;
577 |
578 | if (lockToContainerEdges) {
579 | const [minLockOffset, maxLockOffset] = getLockPixelOffsets({
580 | height: this.height,
581 | lockOffset,
582 | width: this.width,
583 | });
584 | const minOffset = {
585 | x: this.width / 2 - minLockOffset.x,
586 | y: this.height / 2 - minLockOffset.y,
587 | };
588 | const maxOffset = {
589 | x: this.width / 2 - maxLockOffset.x,
590 | y: this.height / 2 - maxLockOffset.y,
591 | };
592 |
593 | translate.x = limit(
594 | this.minTranslate.x + minOffset.x,
595 | this.maxTranslate.x - maxOffset.x,
596 | translate.x,
597 | );
598 | translate.y = limit(
599 | this.minTranslate.y + minOffset.y,
600 | this.maxTranslate.y - maxOffset.y,
601 | translate.y,
602 | );
603 | }
604 |
605 | if (lockAxis === 'x') {
606 | translate.y = 0;
607 | } else if (lockAxis === 'y') {
608 | translate.x = 0;
609 | }
610 |
611 | if (
612 | isKeySorting &&
613 | keyboardSortingTransitionDuration &&
614 | !ignoreTransition
615 | ) {
616 | setTransitionDuration(this.helper, keyboardSortingTransitionDuration);
617 | }
618 |
619 | setTranslate3d(this.helper, translate);
620 | }
621 |
622 | animateNodes() {
623 | const {transitionDuration, hideSortableGhost, onSortOver} = this.props;
624 | const {containerScrollDelta, windowScrollDelta} = this;
625 | const nodes = this.manager.getOrderedRefs();
626 | const sortingOffset = {
627 | left:
628 | this.offsetEdge.left + this.translate.x + containerScrollDelta.left,
629 | top: this.offsetEdge.top + this.translate.y + containerScrollDelta.top,
630 | };
631 | const {isKeySorting} = this.manager;
632 |
633 | const prevIndex = this.newIndex;
634 | this.newIndex = null;
635 |
636 | for (let i = 0, len = nodes.length; i < len; i++) {
637 | const {node} = nodes[i];
638 | const {index} = node.sortableInfo;
639 | const width = node.offsetWidth;
640 | const height = node.offsetHeight;
641 | const offset = {
642 | height: this.height > height ? height / 2 : this.height / 2,
643 | width: this.width > width ? width / 2 : this.width / 2,
644 | };
645 |
646 | // For keyboard sorting, we want user input to dictate the position of the nodes
647 | const mustShiftBackward =
648 | isKeySorting && (index > this.index && index <= prevIndex);
649 | const mustShiftForward =
650 | isKeySorting && (index < this.index && index >= prevIndex);
651 |
652 | const translate = {
653 | x: 0,
654 | y: 0,
655 | };
656 | let {edgeOffset} = nodes[i];
657 |
658 | // If we haven't cached the node's offsetTop / offsetLeft value
659 | if (!edgeOffset) {
660 | edgeOffset = getEdgeOffset(node, this.container);
661 | nodes[i].edgeOffset = edgeOffset;
662 | // While we're at it, cache the boundingClientRect, used during keyboard sorting
663 | if (isKeySorting) {
664 | nodes[i].boundingClientRect = getScrollAdjustedBoundingClientRect(
665 | node,
666 | containerScrollDelta,
667 | );
668 | }
669 | }
670 |
671 | // Get a reference to the next and previous node
672 | const nextNode = i < nodes.length - 1 && nodes[i + 1];
673 | const prevNode = i > 0 && nodes[i - 1];
674 |
675 | // Also cache the next node's edge offset if needed.
676 | // We need this for calculating the animation in a grid setup
677 | if (nextNode && !nextNode.edgeOffset) {
678 | nextNode.edgeOffset = getEdgeOffset(nextNode.node, this.container);
679 | if (isKeySorting) {
680 | nextNode.boundingClientRect = getScrollAdjustedBoundingClientRect(
681 | nextNode.node,
682 | containerScrollDelta,
683 | );
684 | }
685 | }
686 |
687 | // If the node is the one we're currently animating, skip it
688 | if (index === this.index) {
689 | if (hideSortableGhost) {
690 | /*
691 | * With windowing libraries such as `react-virtualized`, the sortableGhost
692 | * node may change while scrolling down and then back up (or vice-versa),
693 | * so we need to update the reference to the new node just to be safe.
694 | */
695 | this.sortableGhost = node;
696 |
697 | setInlineStyles(node, {
698 | opacity: 0,
699 | visibility: 'hidden',
700 | });
701 | }
702 | continue;
703 | }
704 |
705 | if (transitionDuration) {
706 | setTransitionDuration(node, transitionDuration);
707 | }
708 |
709 | if (this.axis.x) {
710 | if (this.axis.y) {
711 | // Calculations for a grid setup
712 | if (
713 | mustShiftForward ||
714 | (index < this.index &&
715 | ((sortingOffset.left + windowScrollDelta.left - offset.width <=
716 | edgeOffset.left &&
717 | sortingOffset.top + windowScrollDelta.top <=
718 | edgeOffset.top + offset.height) ||
719 | sortingOffset.top + windowScrollDelta.top + offset.height <=
720 | edgeOffset.top))
721 | ) {
722 | // If the current node is to the left on the same row, or above the node that's being dragged
723 | // then move it to the right
724 | translate.x = this.width + this.marginOffset.x;
725 | if (
726 | edgeOffset.left + translate.x >
727 | this.containerBoundingRect.width - offset.width * 2
728 | ) {
729 | // If it moves passed the right bounds, then animate it to the first position of the next row.
730 | // We just use the offset of the next node to calculate where to move, because that node's original position
731 | // is exactly where we want to go
732 | if (nextNode) {
733 | translate.x = nextNode.edgeOffset.left - edgeOffset.left;
734 | translate.y = nextNode.edgeOffset.top - edgeOffset.top;
735 | }
736 | }
737 | if (this.newIndex === null) {
738 | this.newIndex = index;
739 | }
740 | } else if (
741 | mustShiftBackward ||
742 | (index > this.index &&
743 | ((sortingOffset.left + windowScrollDelta.left + offset.width >=
744 | edgeOffset.left &&
745 | sortingOffset.top + windowScrollDelta.top + offset.height >=
746 | edgeOffset.top) ||
747 | sortingOffset.top + windowScrollDelta.top + offset.height >=
748 | edgeOffset.top + height))
749 | ) {
750 | // If the current node is to the right on the same row, or below the node that's being dragged
751 | // then move it to the left
752 | translate.x = -(this.width + this.marginOffset.x);
753 | if (
754 | edgeOffset.left + translate.x <
755 | this.containerBoundingRect.left + offset.width
756 | ) {
757 | // If it moves passed the left bounds, then animate it to the last position of the previous row.
758 | // We just use the offset of the previous node to calculate where to move, because that node's original position
759 | // is exactly where we want to go
760 | if (prevNode) {
761 | translate.x = prevNode.edgeOffset.left - edgeOffset.left;
762 | translate.y = prevNode.edgeOffset.top - edgeOffset.top;
763 | }
764 | }
765 | this.newIndex = index;
766 | }
767 | } else {
768 | if (
769 | mustShiftBackward ||
770 | (index > this.index &&
771 | sortingOffset.left + windowScrollDelta.left + offset.width >=
772 | edgeOffset.left)
773 | ) {
774 | translate.x = -(this.width + this.marginOffset.x);
775 | this.newIndex = index;
776 | } else if (
777 | mustShiftForward ||
778 | (index < this.index &&
779 | sortingOffset.left + windowScrollDelta.left <=
780 | edgeOffset.left + offset.width)
781 | ) {
782 | translate.x = this.width + this.marginOffset.x;
783 |
784 | if (this.newIndex == null) {
785 | this.newIndex = index;
786 | }
787 | }
788 | }
789 | } else if (this.axis.y) {
790 | if (
791 | mustShiftBackward ||
792 | (index > this.index &&
793 | sortingOffset.top + windowScrollDelta.top + offset.height >=
794 | edgeOffset.top)
795 | ) {
796 | translate.y = -(this.height + this.marginOffset.y);
797 | this.newIndex = index;
798 | } else if (
799 | mustShiftForward ||
800 | (index < this.index &&
801 | sortingOffset.top + windowScrollDelta.top <=
802 | edgeOffset.top + offset.height)
803 | ) {
804 | translate.y = this.height + this.marginOffset.y;
805 | if (this.newIndex == null) {
806 | this.newIndex = index;
807 | }
808 | }
809 | }
810 |
811 | setTranslate3d(node, translate);
812 | nodes[i].translate = translate;
813 | }
814 |
815 | if (this.newIndex == null) {
816 | this.newIndex = this.index;
817 | }
818 |
819 | if (isKeySorting) {
820 | // If keyboard sorting, we want the user input to dictate index, not location of the helper
821 | this.newIndex = prevIndex;
822 | }
823 |
824 | const oldIndex = isKeySorting ? this.prevIndex : prevIndex;
825 | if (onSortOver && this.newIndex !== oldIndex) {
826 | onSortOver({
827 | collection: this.manager.active.collection,
828 | index: this.index,
829 | newIndex: this.newIndex,
830 | oldIndex,
831 | isKeySorting,
832 | nodes,
833 | helper: this.helper,
834 | });
835 | }
836 | }
837 |
838 | autoscroll = () => {
839 | const {disableAutoscroll} = this.props;
840 | const {isKeySorting} = this.manager;
841 |
842 | if (disableAutoscroll) {
843 | this.autoScroller.clear();
844 | return;
845 | }
846 |
847 | if (isKeySorting) {
848 | const translate = {...this.translate};
849 | let scrollX = 0;
850 | let scrollY = 0;
851 |
852 | if (this.axis.x) {
853 | translate.x = Math.min(
854 | this.maxTranslate.x,
855 | Math.max(this.minTranslate.x, this.translate.x),
856 | );
857 | scrollX = this.translate.x - translate.x;
858 | }
859 |
860 | if (this.axis.y) {
861 | translate.y = Math.min(
862 | this.maxTranslate.y,
863 | Math.max(this.minTranslate.y, this.translate.y),
864 | );
865 | scrollY = this.translate.y - translate.y;
866 | }
867 |
868 | this.translate = translate;
869 | setTranslate3d(this.helper, this.translate);
870 | this.scrollContainer.scrollLeft += scrollX;
871 | this.scrollContainer.scrollTop += scrollY;
872 |
873 | return;
874 | }
875 |
876 | this.autoScroller.update({
877 | height: this.height,
878 | maxTranslate: this.maxTranslate,
879 | minTranslate: this.minTranslate,
880 | translate: this.translate,
881 | width: this.width,
882 | });
883 | };
884 |
885 | onAutoScroll = (offset) => {
886 | this.translate.x += offset.left;
887 | this.translate.y += offset.top;
888 |
889 | this.animateNodes();
890 | };
891 |
892 | getWrappedInstance() {
893 | invariant(
894 | config.withRef,
895 | 'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call',
896 | );
897 |
898 | return this.wrappedInstance.current;
899 | }
900 |
901 | getContainer() {
902 | const {getContainer} = this.props;
903 |
904 | if (typeof getContainer !== 'function') {
905 | return findDOMNode(this);
906 | }
907 |
908 | return getContainer(
909 | config.withRef ? this.getWrappedInstance() : undefined,
910 | );
911 | }
912 |
913 | handleKeyDown = (event) => {
914 | const {keyCode} = event;
915 | const {shouldCancelStart, keyCodes: customKeyCodes = {}} = this.props;
916 |
917 | const keyCodes = {
918 | ...defaultKeyCodes,
919 | ...customKeyCodes,
920 | };
921 |
922 | if (
923 | (this.manager.active && !this.manager.isKeySorting) ||
924 | (!this.manager.active &&
925 | (!keyCodes.lift.includes(keyCode) ||
926 | shouldCancelStart(event) ||
927 | !this.isValidSortingTarget(event)))
928 | ) {
929 | return;
930 | }
931 |
932 | event.stopPropagation();
933 | event.preventDefault();
934 |
935 | if (keyCodes.lift.includes(keyCode) && !this.manager.active) {
936 | this.keyLift(event);
937 | } else if (keyCodes.drop.includes(keyCode) && this.manager.active) {
938 | this.keyDrop(event);
939 | } else if (keyCodes.cancel.includes(keyCode)) {
940 | this.newIndex = this.manager.active.index;
941 | this.keyDrop(event);
942 | } else if (keyCodes.up.includes(keyCode)) {
943 | this.keyMove(-1);
944 | } else if (keyCodes.down.includes(keyCode)) {
945 | this.keyMove(1);
946 | }
947 | };
948 |
949 | keyLift = (event) => {
950 | const {target} = event;
951 | const node = closest(target, (el) => el.sortableInfo != null);
952 | const {index, collection} = node.sortableInfo;
953 |
954 | this.initialFocusedNode = target;
955 |
956 | this.manager.isKeySorting = true;
957 | this.manager.active = {
958 | index,
959 | collection,
960 | };
961 |
962 | this.handlePress(event);
963 | };
964 |
965 | keyMove = (shift) => {
966 | const nodes = this.manager.getOrderedRefs();
967 | const {index: lastIndex} = nodes[nodes.length - 1].node.sortableInfo;
968 | const newIndex = this.newIndex + shift;
969 | const prevIndex = this.newIndex;
970 |
971 | if (newIndex < 0 || newIndex > lastIndex) {
972 | return;
973 | }
974 |
975 | this.prevIndex = prevIndex;
976 | this.newIndex = newIndex;
977 |
978 | const targetIndex = getTargetIndex(
979 | this.newIndex,
980 | this.prevIndex,
981 | this.index,
982 | );
983 | const target = nodes.find(
984 | ({node}) => node.sortableInfo.index === targetIndex,
985 | );
986 | const {node: targetNode} = target;
987 |
988 | const scrollDelta = this.containerScrollDelta;
989 | const targetBoundingClientRect =
990 | target.boundingClientRect ||
991 | getScrollAdjustedBoundingClientRect(targetNode, scrollDelta);
992 | const targetTranslate = target.translate || {x: 0, y: 0};
993 |
994 | const targetPosition = {
995 | top: targetBoundingClientRect.top + targetTranslate.y - scrollDelta.top,
996 | left:
997 | targetBoundingClientRect.left + targetTranslate.x - scrollDelta.left,
998 | };
999 |
1000 | const shouldAdjustForSize = prevIndex < newIndex;
1001 | const sizeAdjustment = {
1002 | x:
1003 | shouldAdjustForSize && this.axis.x
1004 | ? targetNode.offsetWidth - this.width
1005 | : 0,
1006 | y:
1007 | shouldAdjustForSize && this.axis.y
1008 | ? targetNode.offsetHeight - this.height
1009 | : 0,
1010 | };
1011 |
1012 | this.handleSortMove({
1013 | pageX: targetPosition.left + sizeAdjustment.x,
1014 | pageY: targetPosition.top + sizeAdjustment.y,
1015 | ignoreTransition: shift === 0,
1016 | });
1017 | };
1018 |
1019 | keyDrop = (event) => {
1020 | this.handleSortEnd(event);
1021 |
1022 | if (this.initialFocusedNode) {
1023 | this.initialFocusedNode.focus();
1024 | }
1025 | };
1026 |
1027 | handleKeyEnd = (event) => {
1028 | if (this.manager.active) {
1029 | this.keyDrop(event);
1030 | }
1031 | };
1032 |
1033 | isValidSortingTarget = (event) => {
1034 | const {useDragHandle} = this.props;
1035 | const {target} = event;
1036 | const node = closest(target, (el) => el.sortableInfo != null);
1037 |
1038 | return (
1039 | node &&
1040 | node.sortableInfo &&
1041 | !node.sortableInfo.disabled &&
1042 | (useDragHandle ? isSortableHandle(target) : target.sortableInfo)
1043 | );
1044 | };
1045 |
1046 | render() {
1047 | const ref = config.withRef ? this.wrappedInstance : null;
1048 |
1049 | return (
1050 |