react-sortable-hoc
Advanced tools
Comparing version 0.0.7 to 0.0.8
Changelog | ||
------------ | ||
### 0.0.8 | ||
- Added `distance` prop ([#35](https://github.com/clauderic/react-sortable-hoc/issues/35)) | ||
- Added a `shouldCancelStart` ([#47](https://github.com/clauderic/react-sortable-hoc/issues/47), [#36](https://github.com/clauderic/react-sortable-hoc/issues/36), [#41](https://github.com/clauderic/react-sortable-hoc/issues/41)) prop to programatically cancel sorting before it begins. | ||
- Prevent right click from causing sort start ([#46](https://github.com/clauderic/react-sortable-hoc/issues/46)) | ||
### 0.0.7 | ||
@@ -4,0 +9,0 @@ Fixes server-side rendering (window undefined) ([#39](https://github.com/clauderic/react-sortable-hoc/issues/39)) |
@@ -52,3 +52,3 @@ 'use strict'; | ||
function _class() { | ||
function _class(props) { | ||
_classCallCheck(this, _class); | ||
@@ -61,2 +61,17 @@ | ||
_this.handleStart = function (e) { | ||
var _this$props = _this.props; | ||
var distance = _this$props.distance; | ||
var shouldCancelStart = _this$props.shouldCancelStart; | ||
if (e.button === 2 || shouldCancelStart(e)) { | ||
return false; | ||
} | ||
_this._touched = true; | ||
_this._pos = { | ||
x: e.clientX, | ||
y: e.clientY | ||
}; | ||
var node = (0, _utils.closest)(e.target, function (el) { | ||
@@ -78,8 +93,41 @@ return el.sortableInfo != null; | ||
_this.manager.active = { index: index, collection: collection }; | ||
_this.pressTimer = setTimeout(function () { | ||
return _this.handlePress(e); | ||
}, _this.props.pressDelay); | ||
if (!distance) { | ||
_this.pressTimer = setTimeout(function () { | ||
return _this.handlePress(e); | ||
}, _this.props.pressDelay); | ||
} | ||
} | ||
}; | ||
_this.handleMove = function (e) { | ||
var distance = _this.props.distance; | ||
if (!_this.state.sorting && _this._touched) { | ||
_this._delta = { | ||
x: _this._pos.x - e.clientX, | ||
y: _this._pos.y - e.clientY | ||
}; | ||
var delta = Math.abs(_this._delta.x) + Math.abs(_this._delta.y); | ||
if (!distance) { | ||
_this.cancel(); | ||
} else if (delta >= distance) { | ||
_this.handlePress(e); | ||
} | ||
} | ||
}; | ||
_this.handleEnd = function () { | ||
var distance = _this.props.distance; | ||
_this._touched = false; | ||
if (!distance) { | ||
_this.cancel(); | ||
} | ||
}; | ||
_this.cancel = function () { | ||
@@ -96,8 +144,8 @@ if (!_this.state.sorting) { | ||
if (active) { | ||
var _this$props = _this.props; | ||
var axis = _this$props.axis; | ||
var onSortStart = _this$props.onSortStart; | ||
var helperClass = _this$props.helperClass; | ||
var hideSortableGhost = _this$props.hideSortableGhost; | ||
var useWindowAsScrollContainer = _this$props.useWindowAsScrollContainer; | ||
var _this$props2 = _this.props; | ||
var axis = _this$props2.axis; | ||
var onSortStart = _this$props2.onSortStart; | ||
var helperClass = _this$props2.helperClass; | ||
var hideSortableGhost = _this$props2.hideSortableGhost; | ||
var useWindowAsScrollContainer = _this$props2.useWindowAsScrollContainer; | ||
var node = active.node; | ||
@@ -184,5 +232,5 @@ var collection = active.collection; | ||
_this.handleSortEnd = function (e) { | ||
var _this$props2 = _this.props; | ||
var hideSortableGhost = _this$props2.hideSortableGhost; | ||
var onSortEnd = _this$props2.onSortEnd; | ||
var _this$props3 = _this.props; | ||
var hideSortableGhost = _this$props3.hideSortableGhost; | ||
var onSortEnd = _this$props3.onSortEnd; | ||
var collection = _this.manager.active.collection; | ||
@@ -239,2 +287,4 @@ | ||
}); | ||
_this._touched = false; | ||
}; | ||
@@ -276,5 +326,7 @@ | ||
start: _this.handleStart, | ||
move: _this.cancel, | ||
end: _this.cancel | ||
move: _this.handleMove, | ||
end: _this.handleEnd | ||
}; | ||
(0, _invariant2.default)(!(props.distance && props.pressDelay), 'Attempted to set both `pressDelay` and `distance` on SortableContainer, you may only use one or the other, not both at the same time.'); | ||
return _this; | ||
@@ -528,5 +580,11 @@ } | ||
pressDelay: 0, | ||
distance: 0, | ||
useWindowAsScrollContainer: false, | ||
hideSortableGhost: true, | ||
contentWindow: typeof window !== 'undefined' ? window : null, | ||
shouldCancelStart: function shouldCancelStart(e) { | ||
if (['input', 'textarea', 'select', 'option'].indexOf(e.target.tagName.toLowerCase()) !== -1) { | ||
return true; | ||
} | ||
}, | ||
lockToContainerEdges: false, | ||
@@ -536,2 +594,3 @@ lockOffset: '50%' | ||
axis: _react.PropTypes.oneOf(['x', 'y']), | ||
distance: _react.PropTypes.number, | ||
lockAxis: _react.PropTypes.string, | ||
@@ -544,2 +603,3 @@ helperClass: _react.PropTypes.string, | ||
onSortEnd: _react.PropTypes.func, | ||
shouldCancelStart: _react.PropTypes.func, | ||
pressDelay: _react.PropTypes.number, | ||
@@ -546,0 +606,0 @@ useDragHandle: _react.PropTypes.bool, |
@@ -16,3 +16,3 @@ import React, { Component, PropTypes } from 'react'; | ||
function _class() { | ||
function _class(props) { | ||
babelHelpers.classCallCheck(this, _class); | ||
@@ -25,2 +25,17 @@ | ||
_this.handleStart = function (e) { | ||
var _this$props = _this.props; | ||
var distance = _this$props.distance; | ||
var shouldCancelStart = _this$props.shouldCancelStart; | ||
if (e.button === 2 || shouldCancelStart(e)) { | ||
return false; | ||
} | ||
_this._touched = true; | ||
_this._pos = { | ||
x: e.clientX, | ||
y: e.clientY | ||
}; | ||
var node = closest(e.target, function (el) { | ||
@@ -42,8 +57,41 @@ return el.sortableInfo != null; | ||
_this.manager.active = { index: index, collection: collection }; | ||
_this.pressTimer = setTimeout(function () { | ||
return _this.handlePress(e); | ||
}, _this.props.pressDelay); | ||
if (!distance) { | ||
_this.pressTimer = setTimeout(function () { | ||
return _this.handlePress(e); | ||
}, _this.props.pressDelay); | ||
} | ||
} | ||
}; | ||
_this.handleMove = function (e) { | ||
var distance = _this.props.distance; | ||
if (!_this.state.sorting && _this._touched) { | ||
_this._delta = { | ||
x: _this._pos.x - e.clientX, | ||
y: _this._pos.y - e.clientY | ||
}; | ||
var delta = Math.abs(_this._delta.x) + Math.abs(_this._delta.y); | ||
if (!distance) { | ||
_this.cancel(); | ||
} else if (delta >= distance) { | ||
_this.handlePress(e); | ||
} | ||
} | ||
}; | ||
_this.handleEnd = function () { | ||
var distance = _this.props.distance; | ||
_this._touched = false; | ||
if (!distance) { | ||
_this.cancel(); | ||
} | ||
}; | ||
_this.cancel = function () { | ||
@@ -60,8 +108,8 @@ if (!_this.state.sorting) { | ||
if (active) { | ||
var _this$props = _this.props; | ||
var axis = _this$props.axis; | ||
var onSortStart = _this$props.onSortStart; | ||
var helperClass = _this$props.helperClass; | ||
var hideSortableGhost = _this$props.hideSortableGhost; | ||
var useWindowAsScrollContainer = _this$props.useWindowAsScrollContainer; | ||
var _this$props2 = _this.props; | ||
var axis = _this$props2.axis; | ||
var onSortStart = _this$props2.onSortStart; | ||
var helperClass = _this$props2.helperClass; | ||
var hideSortableGhost = _this$props2.hideSortableGhost; | ||
var useWindowAsScrollContainer = _this$props2.useWindowAsScrollContainer; | ||
var node = active.node; | ||
@@ -148,5 +196,5 @@ var collection = active.collection; | ||
_this.handleSortEnd = function (e) { | ||
var _this$props2 = _this.props; | ||
var hideSortableGhost = _this$props2.hideSortableGhost; | ||
var onSortEnd = _this$props2.onSortEnd; | ||
var _this$props3 = _this.props; | ||
var hideSortableGhost = _this$props3.hideSortableGhost; | ||
var onSortEnd = _this$props3.onSortEnd; | ||
var collection = _this.manager.active.collection; | ||
@@ -203,2 +251,4 @@ | ||
}); | ||
_this._touched = false; | ||
}; | ||
@@ -240,5 +290,7 @@ | ||
start: _this.handleStart, | ||
move: _this.cancel, | ||
end: _this.cancel | ||
move: _this.handleMove, | ||
end: _this.handleEnd | ||
}; | ||
invariant(!(props.distance && props.pressDelay), 'Attempted to set both `pressDelay` and `distance` on SortableContainer, you may only use one or the other, not both at the same time.'); | ||
return _this; | ||
@@ -491,5 +543,11 @@ } | ||
pressDelay: 0, | ||
distance: 0, | ||
useWindowAsScrollContainer: false, | ||
hideSortableGhost: true, | ||
contentWindow: typeof window !== 'undefined' ? window : null, | ||
shouldCancelStart: function shouldCancelStart(e) { | ||
if (['input', 'textarea', 'select', 'option'].indexOf(e.target.tagName.toLowerCase()) !== -1) { | ||
return true; | ||
} | ||
}, | ||
lockToContainerEdges: false, | ||
@@ -499,2 +557,3 @@ lockOffset: '50%' | ||
axis: PropTypes.oneOf(['x', 'y']), | ||
distance: PropTypes.number, | ||
lockAxis: PropTypes.string, | ||
@@ -507,2 +566,3 @@ helperClass: PropTypes.string, | ||
onSortEnd: PropTypes.func, | ||
shouldCancelStart: PropTypes.func, | ||
pressDelay: PropTypes.number, | ||
@@ -509,0 +569,0 @@ useDragHandle: PropTypes.bool, |
{ | ||
"name": "react-sortable-hoc", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Set of higher-order components to turn any list into a sortable, touch-friendly, animated list", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -5,3 +5,3 @@ # React Sortable (HOC) | ||
[![npm version](https://img.shields.io/npm/v/react-sortable-hoc.svg)](https://www.npmjs.com/package/react-sortable-hoc) | ||
![npm downloads](https://img.shields.io/npm/dm/react-sortable-hoc.svg) | ||
[![npm downloads](https://img.shields.io/npm/dm/react-sortable-hoc.svg)](https://www.npmjs.com/package/react-sortable-hoc) | ||
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/clauderic/react-sortable-hoc/blob/master/LICENSE) | ||
@@ -93,21 +93,23 @@ [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
#### SortableContainer HOC | ||
| Property | Type | Default | Description | | ||
|:---------------------------|:---------|:--------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| axis | String | `y` | The axis you want to sort on, either 'x' or 'y' | | ||
| lockAxis | String | | If you'd like, you can lock movement to an axis while sorting. This is not something that is possible with HTML5 Drag & Drop | | ||
| helperClass | String | | You can provide a class you'd like to add to the sortable helper to add some styles to it | | ||
| transitionDuration | Number | `300` | The duration of the transition when elements shift positions. Set this to `0` if you'd like to disable transitions | | ||
| 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` | | ||
| onSortStart | Function | | Callback that get's invoked when sorting begins. `function({node, index, collection}, event)` | | ||
| onSortMove | Function | | Callback that get's invoked during sorting as the cursor moves. `function(event)` | | ||
| onSortEnd | Function | | Callback that get's invoked when sortin ends. `function({oldIndex, newIndex, collection}, e)` | | ||
| useDragHandle | Boolean | `false` | If you're using the `SortableHandle` HOC, set this to `true` | | ||
| useWindowAsScrollContainer | Boolean | `false` | If you want, you can set the `window` as the scrolling container | | ||
| 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. | | ||
| lockToContainerEdges | Boolean | `false` | You can lock movement of the sortable element to it's parent `SortableContainer` | | ||
| 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%"]`). | | ||
| 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. | | ||
| Property | Type | Default | Description | | ||
|:---------------------------|:------------------|:-----------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| axis | String | `y` | The axis you want to sort on, either 'x' or 'y' | | ||
| lockAxis | String | | If you'd like, you can lock movement to an axis while sorting. This is not something that is possible with HTML5 Drag & Drop | | ||
| helperClass | String | | You can provide a class you'd like to add to the sortable helper to add some styles to it | | ||
| transitionDuration | Number | `300` | The duration of the transition when elements shift positions. Set this to `0` if you'd like to disable transitions | | ||
| 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. | | ||
| 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. | | ||
| shouldCancelStart | Function | [Function](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L34) | This function get's 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` or `option`. | | ||
| onSortStart | Function | | Callback that get's invoked when sorting begins. `function({node, index, collection}, event)` | | ||
| onSortMove | Function | | Callback that get's invoked during sorting as the cursor moves. `function(event)` | | ||
| onSortEnd | Function | | Callback that get's invoked when sorting ends. `function({oldIndex, newIndex, collection}, e)` | | ||
| useDragHandle | Boolean | `false` | If you're using the `SortableHandle` HOC, set this to `true` | | ||
| useWindowAsScrollContainer | Boolean | `false` | If you want, you can set the `window` as the scrolling container | | ||
| 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. | | ||
| lockToContainerEdges | Boolean | `false` | You can lock movement of the sortable element to it's parent `SortableContainer` | | ||
| 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%"]`). | | ||
| 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. | | ||
\* `OffsetValue` is either a finite `Number` or a `String` made-up of a number and a unit (`px` or `%`). | ||
Examples: `10` (is the same as `"10px"`), `"50%"` | ||
\* `OffsetValue` can either be a finite `Number` or a `String` made up of a number and a unit (`px` or `%`). | ||
Examples: `10` (which is the same as `"10px"`), `"50%"` | ||
@@ -120,3 +122,4 @@ #### SortableElement HOC | ||
| disabled | Boolean | `false` | | Whether the element should be sortable or not | | ||
Why shoud I use this? | ||
Why should I use this? | ||
-------------------- | ||
@@ -127,3 +130,3 @@ There are already a number of great Drag & Drop libraries out there (for instance, [react-dnd](https://github.com/gaearon/react-dnd/) is fantastic). If those libraries fit your needs, you should definitely give them a try first. However, most of those libraries rely on the HTML5 Drag & Drop API, which has some severe limitations. For instance, things rapidly become tricky if you need to support touch devices, if you need to lock dragging to an axis, or want to animate the nodes as they're being sorted. React Sortable HOC aims to provide a simple set of higher-order components to fill those gaps. If you're looking for a dead-simple, mobile-friendly way to add sortable functionality to your lists, then you're in the right place. | ||
------------ | ||
React Sortable List has very few dependencies. It depends on `invariant` and a couple `lodash` functions. It has the following peerDependencies: `react`, `react-dom` | ||
React Sortable List has very few dependencies. It depends on `invariant` and a handful of `lodash` helpers. It has the following peerDependencies: `react`, `react-dom` | ||
@@ -134,2 +137,6 @@ Reporting Issues | ||
Asking for help | ||
---------------- | ||
Please do not use the issue tracker for personal support requests. Instead, use [Gitter](https://gitter.im/clauderic/react-sortable-hoc) or StackOverflow. | ||
Contributions | ||
@@ -136,0 +143,0 @@ ------------ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
715954
6546
149