UNPKG

react-sortable-hoc-rtl

Version:

Set of higher-order components to turn any list into a sortable, touch-friendly, animated list

78 lines (63 loc) 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Manager = function () { function Manager() { _classCallCheck(this, Manager); this.refs = {}; } _createClass(Manager, [{ key: "add", value: function add(collection, ref) { if (!this.refs[collection]) { this.refs[collection] = []; } this.refs[collection].push(ref); } }, { key: "remove", value: function remove(collection, ref) { var index = this.getIndex(collection, ref); if (index !== -1) { this.refs[collection].splice(index, 1); } } }, { key: "isActive", value: function isActive() { return this.active; } }, { key: "getActive", value: function getActive() { var _this = this; return this.refs[this.active.collection].find( // eslint-disable-next-line eqeqeq function (_ref) { var node = _ref.node; return node.sortableInfo.index == _this.active.index; }); } }, { key: "getIndex", value: function getIndex(collection, ref) { return this.refs[collection].indexOf(ref); } }, { key: "getOrderedRefs", value: function getOrderedRefs() { var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.active.collection; return this.refs[collection].sort(sortByIndex); } }]); return Manager; }(); exports.default = Manager; function sortByIndex(_ref2, _ref3) { var index1 = _ref2.node.sortableInfo.index; var index2 = _ref3.node.sortableInfo.index; return index1 - index2; }