From eba75d87a51b8fbcb67c02461b5513bbbe35b74f Mon Sep 17 00:00:00 2001 From: Jeff Watson Date: Fri, 8 Dec 2023 15:03:31 -0600 Subject: [PATCH 1/2] Expose updated full list of items in confirmChange function Signed-off-by: Jeff Watson --- README.md | 44 +++++++++++++++++------------------ dist/Nestable/Nestable.js | 4 ++-- dist/Nestable/Nestable.js.map | 2 +- dist/example/example.js | 4 ++-- dist/types.d.ts | 1 + src/Nestable/Nestable.tsx | 2 +- src/types.ts | 1 + 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index e5f2cda..8254af2 100644 --- a/README.md +++ b/README.md @@ -53,31 +53,31 @@ const Example = () => ( ## Options -| Property | Type | Default | Description | -|----------|------|---------|-------------| -| childrenProp | string | `"children"` | Name of a property for children. | -| className | string | `undefined` | Extra class name which can be passed to a root element. | -| collapsed | boolean | `false` | Makes groups collapsed by default. | -| confirmChange | function | `() => true` | Callback which has a single parameter with keys: `dragItem` - item which is being dragged, `destinationParent` - item where dragItem is about to land (or `null` if moving to root). Let function return `false` if this movement should not happen. | -| disableCollapse | boolean | `false` | Disable toggling a collapsed state of items with children. If you need to set a specific initial state, then it is still possible to do so with the public method `collapse`. | -| disableDrag | boolean or function | `false` | Disable dragging. Pass boolean to apply to all items. Pass a callback to target individual items. It has a single parameter with keys: `item` - item from your array, `index` - number, index of the item, `depth` - number, depth of the item. | -| group | string or number | `random string` | Different group names may be passed if you have more than one nestable component on a page and want some extra styles for portal instances. | -| handler | node | `undefined` | If you pass it, it will get wrapped with drag handlers and you may use it in your render method. | -| idProp | string | `"id"` | Name of a property for id. | -| items | array | `[]` | Array of items. Every item must be of shape `{id: @uniq}` to distinguish elements. | -| maxDepth | number | `10` | Maximum available level of nesting. | -| onChange | function | `() => {}` | Callback which has a single parameter with keys: `items` - new array after position was changed, `dragItem` - item which has been moved, `targetPath` - array of numbers, those numbers are indices and they make path to a location, to where item has been moved. | -| onCollapseChange | function | `() => {}` | Callback which has a single parameter with one of two possible keys: `openIds` - array of ids which are open if `collapsed` is set to `ture`, or `closedIds` - array of ids which are closed if `collapsed` is set to `false`. **Note:** this callback is triggered not only when user explicitly opens or closes an item, but when implicit events happen as well, like when the only child of open item is moved out. | -| onDragEnd | function | `() => {}` | Callback which has no parameters. It is invoked when dragging ends via drop or cancel. | -| onDragStart | function | `() => {}` | Callback which has a single parameter with keys: `dragItem` - item which has been moved. | -| renderCollapseIcon | function | `() => ` | Function for rendering collapse icon. Has a single parameter with keys: `isCollapsed` - boolean, true if this group has children and is collapsed. | -| renderItem | function | `({item}) => String(item)` | Function for rendering every item. Has a single parameter with keys: `item` - item from your array, `index` - number, index of the item, `depth` - number, depth of the item, `collapseIcon` - node, icon for items with children (allows you to collapse the group), `handler` - node, which you have passed via the same property, but wrapped with some additional events, `isDraggable` - boolean, tells if dragging is allowed for this item (see `disableDrag` prop for details). | -| threshold | number | `30` | Amount of pixels which mouse should move horizontally before increasing/decreasing level (nesting) of current element. | +| Property | Type | Default | Description | +|--------------------|---------------------|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| childrenProp | string | `"children"` | Name of a property for children. | +| className | string | `undefined` | Extra class name which can be passed to a root element. | +| collapsed | boolean | `false` | Makes groups collapsed by default. | +| confirmChange | function | `() => true` | Callback which has a single parameter with keys: `dragItem` - item which is being dragged, `destinationParent` - item where dragItem is about to land (or `null` if moving to root), `items` - new array after position change. Let function return `false` if this movement should not happen. | +| disableCollapse | boolean | `false` | Disable toggling a collapsed state of items with children. If you need to set a specific initial state, then it is still possible to do so with the public method `collapse`. | +| disableDrag | boolean or function | `false` | Disable dragging. Pass boolean to apply to all items. Pass a callback to target individual items. It has a single parameter with keys: `item` - item from your array, `index` - number, index of the item, `depth` - number, depth of the item. | +| group | string or number | `random string` | Different group names may be passed if you have more than one nestable component on a page and want some extra styles for portal instances. | +| handler | node | `undefined` | If you pass it, it will get wrapped with drag handlers and you may use it in your render method. | +| idProp | string | `"id"` | Name of a property for id. | +| items | array | `[]` | Array of items. Every item must be of shape `{id: @uniq}` to distinguish elements. | +| maxDepth | number | `10` | Maximum available level of nesting. | +| onChange | function | `() => {}` | Callback which has a single parameter with keys: `items` - new array after position was changed, `dragItem` - item which has been moved, `targetPath` - array of numbers, those numbers are indices and they make path to a location, to where item has been moved. | +| onCollapseChange | function | `() => {}` | Callback which has a single parameter with one of two possible keys: `openIds` - array of ids which are open if `collapsed` is set to `ture`, or `closedIds` - array of ids which are closed if `collapsed` is set to `false`. **Note:** this callback is triggered not only when user explicitly opens or closes an item, but when implicit events happen as well, like when the only child of open item is moved out. | +| onDragEnd | function | `() => {}` | Callback which has no parameters. It is invoked when dragging ends via drop or cancel. | +| onDragStart | function | `() => {}` | Callback which has a single parameter with keys: `dragItem` - item which has been moved. | +| renderCollapseIcon | function | `() => ` | Function for rendering collapse icon. Has a single parameter with keys: `isCollapsed` - boolean, true if this group has children and is collapsed. | +| renderItem | function | `({item}) => String(item)` | Function for rendering every item. Has a single parameter with keys: `item` - item from your array, `index` - number, index of the item, `depth` - number, depth of the item, `collapseIcon` - node, icon for items with children (allows you to collapse the group), `handler` - node, which you have passed via the same property, but wrapped with some additional events, `isDraggable` - boolean, tells if dragging is allowed for this item (see `disableDrag` prop for details). | +| threshold | number | `30` | Amount of pixels which mouse should move horizontally before increasing/decreasing level (nesting) of current element. | #### Public methods -| Method | Accepts | Description | -|--------|---------|-------------| +| Method | Accepts | Description | +|----------|-----------------|--------------------------------------------------------------------------------------------------------------------| | collapse | string or array | `"NONE"` - expand all groups; `"ALL"` - collapse all groups; `[]` - collapse all groups with ids from given array. | ## Todo diff --git a/dist/Nestable/Nestable.js b/dist/Nestable/Nestable.js index e5f2183..341dfe6 100644 --- a/dist/Nestable/Nestable.js +++ b/dist/Nestable/Nestable.js @@ -294,8 +294,6 @@ var Nestable = /** @class */ (function (_super) { ? pathTo : pathTo.slice(0, -1); var destinationParent = this.getItemByPath(destinationPath); - if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent })) - return; var removePath = this.getSplicePath(pathFrom, { numToRemove: 1, childrenProp: childrenProp, @@ -307,6 +305,8 @@ var Nestable = /** @class */ (function (_super) { }); items = (0, react_addons_update_1.default)(items, removePath); items = (0, react_addons_update_1.default)(items, insertPath); + if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent, items: items })) + return; this.setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { items: items, isDirty: true }), extraProps)); }); if (extraProps.collapsedItems !== this.state.collapsedItems) { this.onCollapseChange(extraProps.collapsedItems); diff --git a/dist/Nestable/Nestable.js.map b/dist/Nestable/Nestable.js.map index 47e361d..760371d 100644 --- a/dist/Nestable/Nestable.js.map +++ b/dist/Nestable/Nestable.js.map @@ -1 +1 @@ -{"version":3,"file":"Nestable.js","sourceRoot":"","sources":["../../src/Nestable/Nestable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAoF;AACpF,8FAA0D;AAC1D,4EAAyC;AACzC,0DAA4B;AAE5B,kCAQkB;AAGlB,gEAA0C;AAE1C;IAAuB,4BAAuC;IAQ5D,kBAAY,KAAoB;QAAhC,YACE,kBAAM,KAAK,CAAC,SAQb;QAhBD,QAAE,GAAmB,IAAI,CAAC;QAC1B,kBAAY,GAAyB,IAAI,CAAC;QAC1C,WAAK,GAAG;YACN,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;YACd,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;SAChB,CAAC;QAqEF,uCAAuC;QACvC,iBAAiB;QACjB,uCAAuC;QACvC,cAAQ,GAAa,UAAC,OAAO;YACrB,IAAA,KAAsC,KAAI,CAAC,KAAK,EAA9C,MAAM,YAAA,EAAE,YAAY,kBAAA,EAAE,SAAS,eAAe,CAAC;YAC/C,IAAA,KAAK,GAAK,KA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AE,OAAO,GAChB,CACH,CAAC;YACJ,CAAC,CAAC,CACC;YAEJ,QAAQ,IAAI,IAAI,CAAC,eAAe,EAAE,CAC/B,CACP,CAAC;IACJ,CAAC;IAvlBM,qBAAY,GAA2B;QAC5C,YAAY,EAAE,UAAU;QACxB,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;QACzB,eAAe,EAAE,KAAK;QACtB,WAAW,EAAE,KAAK;QAClB,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,cAAO,CAAC;QAClB,gBAAgB,EAAE,cAAO,CAAC;QAC1B,SAAS,EAAE,cAAO,CAAC;QACnB,WAAW,EAAE,cAAO,CAAC;QACrB,UAAU,EAAE,UAAC,EAAQ;gBAAN,IAAI,UAAA;YAAO,OAAA,MAAM,CAAC,IAAI,CAAC;QAAZ,CAAY;QACtC,SAAS,EAAE,EAAE;KACd,AAhBkB,CAgBjB;IAwkBJ,eAAC;CAAA,AA3mBD,CAAuB,iBAAS,GA2mB/B;AAED,kBAAe,QAAQ,CAAC"} \ No newline at end of file diff --git a/dist/example/example.js b/dist/example/example.js index 680a4a7..94189c0 100644 --- a/dist/example/example.js +++ b/dist/example/example.js @@ -279,7 +279,7 @@ eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) { /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; -eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar react_1 = __importStar(__webpack_require__(/*! react */ \"./node_modules/react/index.js\"));\nvar react_addons_shallow_compare_1 = __importDefault(__webpack_require__(/*! react-addons-shallow-compare */ \"./node_modules/react-addons-shallow-compare/index.js\"));\nvar react_addons_update_1 = __importDefault(__webpack_require__(/*! react-addons-update */ \"./node_modules/react-addons-update/index.js\"));\nvar classnames_1 = __importDefault(__webpack_require__(/*! classnames */ \"./node_modules/classnames/index.js\"));\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nvar NestableItem_1 = __importDefault(__webpack_require__(/*! ./NestableItem */ \"./src/Nestable/NestableItem.tsx\"));\nvar Nestable = /** @class */ (function (_super) {\n __extends(Nestable, _super);\n function Nestable(props) {\n var _this = _super.call(this, props) || this;\n _this.el = null;\n _this.elCopyStyles = null;\n _this.mouse = {\n last: { x: 0 },\n shift: { x: 0 },\n };\n // ––––––––––––––––––––––––––––––––––––\n // Public Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.collapse = function (itemIds) {\n var _a = _this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var items = _this.state.items;\n if (itemIds === 'NONE') {\n _this.setState({\n collapsedItems: collapsed\n ? (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n : [],\n });\n }\n else if (itemIds === 'ALL') {\n _this.setState({\n collapsedItems: collapsed\n ? []\n : (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp }),\n });\n }\n else if ((0, utils_1.isArray)(itemIds)) {\n _this.setState({\n collapsedItems: (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n .filter(function (id) { return (itemIds.indexOf(id) > -1) !== collapsed; }),\n });\n }\n };\n // ––––––––––––––––––––––––––––––––––––\n // Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.startTrackMouse = function () {\n document.addEventListener('mousemove', _this.onMouseMove);\n document.addEventListener('mouseup', _this.onDragEnd);\n document.addEventListener('keydown', _this.onKeyDown);\n };\n _this.stopTrackMouse = function () {\n document.removeEventListener('mousemove', _this.onMouseMove);\n document.removeEventListener('mouseup', _this.onDragEnd);\n document.removeEventListener('keydown', _this.onKeyDown);\n _this.elCopyStyles = null;\n };\n _this.getItemDepth = function (item) {\n var childrenProp = _this.props.childrenProp;\n var level = 1;\n if (item[childrenProp].length > 0) {\n var childrenDepths = item[childrenProp].map(_this.getItemDepth);\n level += Math.max.apply(Math, childrenDepths);\n }\n return level;\n };\n _this.checkIfCollapsed = function (item) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n return !!((collapsedItems.indexOf(item[idProp]) > -1) !== collapsed);\n };\n // ––––––––––––––––––––––––––––––––––––\n // Click handlers or event handlers\n // ––––––––––––––––––––––––––––––––––––\n _this.onDragStart = function (e, item) {\n var onDragStart = _this.props.onDragStart;\n e.preventDefault();\n e.stopPropagation();\n if (!(e.target instanceof Element))\n return;\n _this.el = (0, utils_1.closest)(e.target, '.nestable-item');\n _this.startTrackMouse();\n _this.onMouseMove(e);\n onDragStart({ dragItem: item });\n _this.setState({\n dragItem: item,\n itemsOld: _this.state.items,\n });\n };\n _this.onDragEnd = function (e, isCancel) {\n var onDragEnd = _this.props.onDragEnd;\n e === null || e === void 0 ? void 0 : e.preventDefault();\n _this.stopTrackMouse();\n _this.el = null;\n onDragEnd();\n isCancel\n ? _this.dragRevert()\n : _this.dragApply();\n };\n _this.onMouseMove = function (e) {\n var _a = _this.props, group = _a.group, threshold = _a.threshold;\n var dragItem = _this.state.dragItem;\n var clientX = e.clientX, clientY = e.clientY;\n var transformProps = (0, utils_1.getTransformProps)(clientX, clientY);\n var elCopy = document.querySelector(\".nestable-\".concat(group, \" .nestable-drag-layer > .nestable-list\"));\n if (!_this.elCopyStyles) {\n var offset = (0, utils_1.getOffsetRect)(_this.el);\n var scroll_1 = (0, utils_1.getTotalScroll)(_this.el);\n _this.elCopyStyles = __assign({ marginTop: offset.top - clientY - scroll_1.top, marginLeft: offset.left - clientX - scroll_1.left }, transformProps);\n }\n else {\n _this.elCopyStyles = __assign(__assign({}, _this.elCopyStyles), transformProps);\n Object.keys(transformProps).forEach(function (key) {\n elCopy.style[key] = transformProps[key];\n });\n var diffX = clientX - _this.mouse.last.x;\n if ((diffX >= 0 && _this.mouse.shift.x >= 0) ||\n (diffX <= 0 && _this.mouse.shift.x <= 0)) {\n _this.mouse.shift.x += diffX;\n }\n else {\n _this.mouse.shift.x = 0;\n }\n _this.mouse.last.x = clientX;\n if (Math.abs(_this.mouse.shift.x) > threshold) {\n if (_this.mouse.shift.x > 0) {\n _this.tryIncreaseDepth(dragItem);\n }\n else {\n _this.tryDecreaseDepth(dragItem);\n }\n _this.mouse.shift.x = 0;\n }\n }\n };\n _this.onMouseEnter = function (e, item) {\n e.preventDefault();\n e.stopPropagation();\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = _this.state.dragItem;\n if (dragItem[idProp] === item[idProp])\n return;\n var pathFrom = _this.getPathById(dragItem[idProp]);\n var pathTo = _this.getPathById(item[idProp]);\n // if collapsed by default\n // and move out the only child\n // remove parent node from list of open nodes\n var collapseProps = {};\n if (collapsed && pathFrom.length > 1) {\n var parent_1 = _this.getItemByPath(pathFrom.slice(0, -1));\n if (parent_1[childrenProp].length === 1) {\n collapseProps = _this.onToggleCollapse(parent_1, true);\n }\n }\n _this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n };\n _this.onToggleCollapse = function (item, isGetter) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n var isCollapsed = _this.checkIfCollapsed(item);\n var newState = {\n collapsedItems: (isCollapsed !== collapsed)\n ? collapsedItems.filter(function (id) { return id !== item[idProp]; })\n : collapsedItems.concat(item[idProp]),\n };\n if (isGetter) {\n return newState;\n }\n else {\n _this.setState(newState);\n _this.onCollapseChange(newState.collapsedItems);\n }\n };\n _this.onCollapseChange = function (ids) {\n var _a = _this.props, collapsed = _a.collapsed, onCollapseChange = _a.onCollapseChange;\n onCollapseChange(collapsed ? { openIds: ids } : { closedIds: ids });\n };\n _this.onKeyDown = function (e) {\n if (e.which === 27) {\n // ESC\n _this.onDragEnd(null, true);\n }\n };\n _this.state = {\n items: [],\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n collapsedItems: [],\n };\n return _this;\n }\n Nestable.prototype.componentDidMount = function () {\n var _a = this.props, items = _a.items, childrenProp = _a.childrenProp;\n // make sure every item has property 'children'\n items = (0, utils_1.listWithChildren)(items, childrenProp);\n this.setState({ items: items });\n };\n Nestable.prototype.componentDidUpdate = function (prevProps) {\n var _this = this;\n var _a = this, _b = _a.props, itemsNew = _b.items, childrenProp = _b.childrenProp, state = _a.state;\n var isPropsChanged = (0, react_addons_shallow_compare_1.default)(__assign(__assign({}, this), { props: prevProps, state: state }), this.props, state);\n if (isPropsChanged) {\n this.stopTrackMouse();\n this.setState(function (prevState) {\n var newState = __assign(__assign({}, prevState), { items: (0, utils_1.listWithChildren)(itemsNew, childrenProp), dragItem: null, isDirty: false });\n if (prevProps.collapsed !== _this.props.collapsed) {\n newState.collapsedItems = [];\n _this.onCollapseChange(newState.collapsedItems);\n }\n return newState;\n });\n }\n };\n Nestable.prototype.componentWillUnmount = function () {\n this.stopTrackMouse();\n };\n Nestable.prototype.moveItem = function (_a, extraProps) {\n var dragItem = _a.dragItem, pathFrom = _a.pathFrom, pathTo = _a.pathTo;\n if (extraProps === void 0) { extraProps = {}; }\n var _b = this.props, childrenProp = _b.childrenProp, confirmChange = _b.confirmChange;\n var dragItemSize = this.getItemDepth(dragItem);\n var items = this.state.items;\n // the remove action might affect the next position,\n // so update next coordinates accordingly\n var realPathTo = this.getRealNextPath(pathFrom, pathTo, dragItemSize);\n if (realPathTo.length === 0)\n return;\n // user can validate every movement\n var destinationPath = realPathTo.length > pathTo.length\n ? pathTo\n : pathTo.slice(0, -1);\n var destinationParent = this.getItemByPath(destinationPath);\n if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent }))\n return;\n var removePath = this.getSplicePath(pathFrom, {\n numToRemove: 1,\n childrenProp: childrenProp,\n });\n var insertPath = this.getSplicePath(realPathTo, {\n numToRemove: 0,\n itemsToInsert: [dragItem],\n childrenProp: childrenProp,\n });\n items = (0, react_addons_update_1.default)(items, removePath);\n items = (0, react_addons_update_1.default)(items, insertPath);\n this.setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { items: items, isDirty: true }), extraProps)); });\n if (extraProps.collapsedItems !== this.state.collapsedItems) {\n this.onCollapseChange(extraProps.collapsedItems);\n }\n };\n Nestable.prototype.tryIncreaseDepth = function (dragItem) {\n var _a = this.props, maxDepth = _a.maxDepth, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n var newDepth = pathFrom.length + this.getItemDepth(dragItem);\n // has previous sibling and isn't at max depth\n if (itemIndex > 0 && newDepth <= maxDepth) {\n var prevSibling = this.getItemByPath(pathFrom.slice(0, -1).concat(itemIndex - 1));\n // previous sibling is not collapsed\n if (!prevSibling[childrenProp].length || !this.checkIfCollapsed(prevSibling)) {\n var pathTo = pathFrom\n .slice(0, -1)\n .concat(itemIndex - 1)\n .concat(prevSibling[childrenProp].length);\n // if collapsed by default\n // and was no children here\n // open this node\n var collapseProps = {};\n if (collapsed && !prevSibling[childrenProp].length) {\n collapseProps = this.onToggleCollapse(prevSibling, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.tryDecreaseDepth = function (dragItem) {\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n // has parent\n if (pathFrom.length > 1) {\n var parent_2 = this.getItemByPath(pathFrom.slice(0, -1));\n // is last (by order) item in array\n if (itemIndex + 1 === parent_2[childrenProp].length) {\n var pathTo = pathFrom.slice(0, -1);\n pathTo[pathTo.length - 1] += 1;\n // if collapsed by default\n // and is last (by count) item in array\n // remove this node from list of open nodes\n var collapseProps = {};\n if (collapsed && parent_2[childrenProp].length === 1) {\n collapseProps = this.onToggleCollapse(parent_2, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.dragApply = function () {\n var _a = this.props, onChange = _a.onChange, idProp = _a.idProp;\n var _b = this.state, items = _b.items, isDirty = _b.isDirty, dragItem = _b.dragItem;\n this.setState({\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n if (onChange && isDirty) {\n var targetPath = this.getPathById(dragItem[idProp], items);\n onChange({ items: items, dragItem: dragItem, targetPath: targetPath });\n }\n };\n Nestable.prototype.dragRevert = function () {\n var itemsOld = this.state.itemsOld;\n this.setState({\n items: itemsOld,\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n };\n // ––––––––––––––––––––––––––––––––––––\n // Getter methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.getPathById = function (id, items) {\n var _this = this;\n if (items === void 0) { items = this.state.items; }\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var path = [];\n items.every(function (item, i) {\n if (item[idProp] === id) {\n path.push(i);\n }\n else if (item[childrenProp]) {\n var childrenPath = _this.getPathById(id, item[childrenProp]);\n if (childrenPath.length) {\n path = path.concat(i).concat(childrenPath);\n }\n }\n return path.length === 0;\n });\n return path;\n };\n Nestable.prototype.getItemByPath = function (path, items) {\n if (items === void 0) { items = this.state.items; }\n var childrenProp = this.props.childrenProp;\n var item = null;\n path.forEach(function (index) {\n var list = item ? item[childrenProp] : items;\n item = list[index];\n });\n return item;\n };\n Nestable.prototype.getSplicePath = function (path, options) {\n if (options === void 0) { options = {}; }\n var splicePath = {};\n var numToRemove = options.numToRemove || 0;\n var itemsToInsert = options.itemsToInsert || [];\n var lastIndex = path.length - 1;\n var currentPath = splicePath;\n path.forEach(function (index, i) {\n var _a;\n if (i === lastIndex) {\n currentPath.$splice = [__spreadArray([index, numToRemove], itemsToInsert, true)];\n }\n else {\n var nextPath = {};\n currentPath[index] = (_a = {}, _a[options.childrenProp] = nextPath, _a);\n currentPath = nextPath;\n }\n });\n return splicePath;\n };\n Nestable.prototype.getRealNextPath = function (prevPath, nextPath, dragItemSize) {\n var _a = this.props, childrenProp = _a.childrenProp, maxDepth = _a.maxDepth;\n var ppLastIndex = prevPath.length - 1;\n var npLastIndex = nextPath.length - 1;\n var newDepth = nextPath.length + dragItemSize - 1;\n if (prevPath.length < nextPath.length) {\n // move into depth\n var wasShifted_1 = false;\n // if new depth exceeds max, try to put after item instead of into item\n if (newDepth > maxDepth && nextPath.length) {\n return this.getRealNextPath(prevPath, nextPath.slice(0, -1), dragItemSize);\n }\n return nextPath.map(function (nextIndex, i) {\n if (wasShifted_1) {\n return i === npLastIndex\n ? nextIndex + 1\n : nextIndex;\n }\n if (typeof prevPath[i] !== 'number') {\n return nextIndex;\n }\n if (nextPath[i] > prevPath[i] && i === ppLastIndex) {\n wasShifted_1 = true;\n return nextIndex - 1;\n }\n return nextIndex;\n });\n }\n else if (prevPath.length === nextPath.length) {\n // if move bottom + move to item with children --> make it a first child instead of swap\n if (nextPath[npLastIndex] > prevPath[npLastIndex]) {\n var target = this.getItemByPath(nextPath);\n if (newDepth < maxDepth &&\n target[childrenProp] &&\n target[childrenProp].length &&\n !this.checkIfCollapsed(target)) {\n return nextPath\n .slice(0, -1)\n .concat(nextPath[npLastIndex] - 1)\n .concat(0);\n }\n }\n }\n return nextPath;\n };\n Nestable.prototype.getItemOptions = function () {\n var _a = this.props, renderItem = _a.renderItem, renderCollapseIcon = _a.renderCollapseIcon, handler = _a.handler, disableCollapse = _a.disableCollapse, disableDrag = _a.disableDrag, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = this.state.dragItem;\n return {\n dragItem: dragItem,\n idProp: idProp,\n childrenProp: childrenProp,\n disableCollapse: disableCollapse,\n disableDrag: disableDrag,\n renderItem: renderItem,\n renderCollapseIcon: renderCollapseIcon,\n handler: handler,\n checkIfCollapsed: this.checkIfCollapsed,\n onDragStart: this.onDragStart,\n onMouseEnter: this.onMouseEnter,\n onToggleCollapse: this.onToggleCollapse,\n };\n };\n // ––––––––––––––––––––––––––––––––––––\n // Render methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.renderDragLayer = function () {\n var _a = this.props, group = _a.group, idProp = _a.idProp;\n var dragItem = this.state.dragItem;\n var el = document.querySelector(\".nestable-\".concat(group, \" .nestable-item-\").concat(dragItem[idProp]));\n var listStyles = {};\n if (el) {\n listStyles.width = el.clientWidth;\n }\n if (this.elCopyStyles) {\n listStyles = __assign(__assign({}, listStyles), this.elCopyStyles);\n }\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: \"nestable-drag-layer\" },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\", style: listStyles },\n react_1.default.createElement(NestableItem_1.default, { item: dragItem, options: options, isCopy: true }))));\n };\n Nestable.prototype.render = function () {\n var _a = this.props, group = _a.group, className = _a.className, idProp = _a.idProp;\n var _b = this.state, items = _b.items, dragItem = _b.dragItem;\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: (0, classnames_1.default)(className, 'nestable', \"nestable-\".concat(group), { 'is-drag-active': dragItem }) },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\" }, items.map(function (item, i) {\n return (react_1.default.createElement(NestableItem_1.default, { key: item[idProp], index: i, item: item, options: options }));\n })),\n dragItem && this.renderDragLayer()));\n };\n Nestable.defaultProps = {\n childrenProp: 'children',\n collapsed: false,\n confirmChange: function () { return true; },\n disableCollapse: false,\n disableDrag: false,\n group: Math.random().toString(36).slice(2),\n idProp: 'id',\n items: [],\n maxDepth: 10,\n onChange: function () { },\n onCollapseChange: function () { },\n onDragEnd: function () { },\n onDragStart: function () { },\n renderItem: function (_a) {\n var item = _a.item;\n return String(item);\n },\n threshold: 30,\n };\n return Nestable;\n}(react_1.Component));\nexports[\"default\"] = Nestable;\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvTmVzdGFibGUvTmVzdGFibGUudHN4IiwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQT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biAgICAgICAgICAgIGlmIChpdGVtSWRzID09PSAnTk9ORScpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiBjb2xsYXBzZWRcbiAgICAgICAgICAgICAgICAgICAgICAgID8gKDAsIHV0aWxzXzEuZ2V0QWxsTm9uRW1wdHlOb2Rlc0lkcykoaXRlbXMsIHsgaWRQcm9wOiBpZFByb3AsIGNoaWxkcmVuUHJvcDogY2hpbGRyZW5Qcm9wIH0pXG4gICAgICAgICAgICAgICAgICAgICAgICA6IFtdLFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSBpZiAoaXRlbUlkcyA9PT0gJ0FMTCcpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiBjb2xsYXBzZWRcbiAgICAgICAgICAgICAgICAgICAgICAgID8gW11cbiAgICAgICAgICAgICAgICAgICAgICAgIDogKDAsIHV0aWxzXzEuZ2V0QWxsTm9uRW1wdHlOb2Rlc0lkcykoaXRlbXMsIHsgaWRQcm9wOiBpZFByb3AsIGNoaWxkcmVuUHJvcDogY2hpbGRyZW5Qcm9wIH0pLFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSBpZiAoKDAsIHV0aWxzXzEuaXNBcnJheSkoaXRlbUlkcykpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiAoMCwgdXRpbHNfMS5nZXRBbGxOb25FbXB0eU5vZGVzSWRzKShpdGVtcywgeyBpZFByb3A6IGlkUHJvcCwgY2hpbGRyZW5Qcm9wOiBjaGlsZHJlblByb3AgfSlcbiAgICAgICAgICAgICA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nQueCA8PSAwKSkge1xuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ICs9IGRpZmZYO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXMubW91c2Uuc2hpZnQueCA9IDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIF90aGlzLm1vdXNlLmxhc3QueCA9IGNsaWVudFg7XG4gICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKF90aGlzLm1vdXNlLnNoaWZ0LngpID4gdGhyZXNob2xkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpcy5tb3VzZS5zaGlmdC54ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMudHJ5SW5jcmVhc2VEZXB0aChkcmFnSXRlbSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy50cnlEZWNyZWFzZURlcHRoKGRyYWdJdGVtKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIF90aGlzLm9uTW91c2VFbnRlciA9IGZ1bmN0aW9uIChlLCBpdGVtKSB7XG4gICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMucHJvcHMsIGNvbGxhcHNlZCA9IF9hLmNvbGxhcHNlZCwgaWRQcm9wID0gX2EuaWRQcm9wLCBjaGlsZHJlblByb3AgPSBfYS5jaGlsZHJlblByb3A7XG4gICAgICAgICAgICB2YXIgZHJhZ0l0ZW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ICBfdGhpcy5vblRvZ2dsZUNvbGxhcHNlID0gZnVuY3Rpb24gKGl0ZW0sIGlzR2V0dGVyKSB7XG4gICAgICAgICAgICB2YXIgX2EgPSBfdGhpcy5wcm9wcywgY29sbGFwc2VkID0gX2EuY29sbGFwc2VkLCBpZFByb3AgPSBfYS5pZFByb3A7XG4gICAgICAgICAgICB2YXIgY29sbGFwc2VkSXRlbXMgPSBfdGhpcy5zdGF0ZS5jb2xsYXBzZWRJdGVtcztcbiAgICAgICAgICAgIHZhciBpc0NvbGxhcHNlZCA9IF90aGlzLmNoZWNrSWZDb2xsYXBzZWQoaXRlbSk7XG4gICAgICAgICAgICB2YXIgbmV3U3RhdGUgPSB7XG4gICAgICAgICAgICAgICAgY29sbGFwc2VkSXRlbXM6IChpc0NvbGxhcHNlZCAhPT0gY29sbGFwc2VkKVxuICAgICAgICAgICAgICAgICAgICA/IGNvbGxhcHNlZEl0ZW1zLmZpbHRlcihmdW5jdGlvbiAoaWQpIHsgcmV0dXJuIGlkICE9PSBpdGVtW2lkUHJvcF07IH0pXG4gICAgICAgICAgICAgICAgICAgIDogY29sbGFwc2VkSXRlbXMuY29uY2F0KGl0ZW1baWRQcm9wXSksXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKGlzR2V0dGVyKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ld1N0YXRlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgX3RoaXMuc2V0U3RhdGUobmV3U3RhdGUpO1xuICAgICAgICAgICAgICAgIF90aGlzLm9uQ29sbGFwc2VDaGFuZ2UobmV3U3RhdGUuY29sbGFwc2VkSXRlbXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBfdGhpcy5vbkNvbGxhcHNlQ2hhbmdlID0gZnVuY3Rpb24gKGlkcykge1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMucHJvcHMsIGNvbGxhcHNl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RGVwdGggPD0gbWF4RGVwdGgpIHtcbiAgICAgICAgICAgIHZhciBwcmV2U2libGluZyA9IHRoaXMuZ2V0SXRlbUJ5UGF0aChwYXRoRnJvbS5zbGljZSgwLCAtMSkuY29uY2F0KGl0ZW1JbmRleCAtIDEpKTtcbiAgICAgICAgICAgIC8vIHByZXZpb3VzIHNpYmxpbmcgaXMgbm90IGNvbGxhcHNlZFxuICAgICAgICAgICAgaWYgKCFwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCB8fCAhdGhpcy5jaGVja0lmQ29sbGFwc2VkKHByZXZTaWJsaW5nKSkge1xuICAgICAgICAgICAgICAgIHZhciBwYXRoVG8gPSBwYXRoRnJvbVxuICAgICAgICAgICAgICAgICAgICAuc2xpY2UoMCwgLTEpXG4gICAgICAgICAgICAgICAgICAgIC5jb25jYXQoaXRlbUluZGV4IC0gMSlcbiAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCk7XG4gICAgICAgICAgICAgICAgLy8gaWYgY29sbGFwc2VkIGJ5IGRlZmF1bHRcbiAgICAgICAgICAgICAgICAvLyBhbmQgd2FzIG5vIGNoaWxkcmVuIGhlcmVcbiAgICAgICAgICAgICAgICAvLyBvcGVuIHRoaXMgbm9kZVxuICAgICAgICAgICAgICAgIHZhciBjb2xsYXBzZVByb3BzID0ge307XG4gICAgICAgICAgICAgICAgaWYgKGNvbGxhcHNlZCAmJiAhcHJldlNpYmxpbmdbY2hpbGRyZW5Qcm9wXS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgY29sbGFwc2VQcm9wcyA9IHRoaXMub25Ub2dnbGVDb2xsYXBzZShwcmV2U2libGluZywgdHJ1ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMubW92ZUl0ZW0oeyBkcmFnSXRlbTogZHJhZ0l0ZW0sIHBhdGhGcm9tOiBwYXRoRnJvbSw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gICAgICAgICAgICAgIGlmICh3YXNTaGlmdGVkXzEpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGkgPT09IG5wTGFzdEluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICA/IG5leHRJbmRleCArIDFcbiAgICAgICAgICAgICAgICAgICAgICAgIDogbmV4dEluZGV4O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHByZXZQYXRoW2ldICE9PSAnbnVtYmVyJykge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAobmV4dFBhdGhbaV0gPiBwcmV2UGF0aFtpXSAmJiBpID09PSBwcExhc3RJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICB3YXNTaGlmdGVkXzEgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4IC0gMTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIG5leHRJbmRleDtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHByZXZQYXRoLmxlbmd0aCA9PT0gbmV4dFBhdGgubGVuZ3RoKSB7XG4gICAgICAgICAgICAvLyBpZiBtb3ZlIGJvdHRvbSArIG1vdmUgdG8gaXRlbSB3aXRoIGNoaWxkcmVuIC0tPiBtYWtlIGl0IGEgZmlyc3QgY2hpbGQgaW5zdGVhZCBvZiBzd2FwXG4gICAgICAgICAgICBpZiAobmV4dFBhdGhbbnBMYXN0SW5kZXhdID4gcHJldlBhdGhbbnBMYXN0SW5kZXhdKSB7XG4gICAgICAgICAgICAgICAgdmFyIHRhcmdldCA9IHRoaXMuZ2V0SXRlbUJ5UGF0aChuZXh0UGF0aCk7XG4gICAgICAgICAgICAgICAgaWYgKG5ld0RlcHRoIDwgbWF4RGVwdGggJiZcbiAgICAgICAgIC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Y2hpbGRyZW5Qcm9wLFxuICAgICAgICAgICAgZGlzYWJsZUNvbGxhcHNlOiBkaXNhYmxlQ29sbGFwc2UsXG4gICAgICAgICAgICBkaXNhYmxlRHJhZzogZGlzYWJsZURyYWcsXG4gICAgICAgICAgICByZW5kZXJJdGVtOiByZW5kZXJJdGVtLFxuICAgICAgICAgICAgcmVuZGVyQ29sbGFwc2VJY29uOiByZW5kZXJDb2xsYXBzZUljb24sXG4gICAgICAgICAgICBoYW5kbGVyOiBoYW5kbGVyLFxuICAgICAgICAgICAgY2hlY2tJZkNvbGxhcHNlZDogdGhpcy5jaGVja0lmQ29sbGFwc2VkLFxuICAgICAgICAgICAgb25EcmFnU3RhcnQ6IHRoaXMub25EcmFnU3RhcnQsXG4gICAgICAgICAgICBvbk1vdXNlRW50ZXI6IHRoaXMub25Nb3VzZUVudGVyLFxuICAgICAgICAgICAgb25Ub2dnbGVDb2xsYXBzZTogdGhpcy5vblRvZ2dsZUNvbGxhcHNlLFxuICAgICAgICB9O1xuICAgIH07XG4gICAgLy8g4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCTXG4gICAgLy8gUmVuZGVyIG1ldGhvZHNcbiAgICAvLyDigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJNcbiAgICBOZXN0YWJsZS5wcm90b3R5cGUucmVuZGVyRHJhZ0xheWVyID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgX2EgPSB0aGlzLnByb3BzLCBncm91cCA9IF9hLmdyb3VwLCBpZFByb3AgPSBfYS5pZFByb3A7XG4gICAgICAgIHZhciBkcmFnSXRlbSA9IHRoaXMuc3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cm1DaGFuZ2U6IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHRydWU7IH0sXG4gICAgICAgIGRpc2FibGVDb2xsYXBzZTogZmFsc2UsXG4gICAgICAgIGRpc2FibGVEcmFnOiBmYWxzZSxcbiAgICAgICAgZ3JvdXA6IE1hdGgucmFuZG9tKCkudG9TdHJpbmcoMzYpLnNsaWNlKDIpLFxuICAgICAgICBpZFByb3A6ICdpZCcsXG4gICAgICAgIGl0ZW1zOiBbXSxcbiAgICAgICAgbWF4RGVwdGg6IDEwLFxuICAgICAgICBvbkNoYW5nZTogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICBvbkNvbGxhcHNlQ2hhbmdlOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uRHJhZ0VuZDogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICBvbkRyYWdTdGFydDogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICByZW5kZXJJdGVtOiBmdW5jdGlvbiAoX2EpIHtcbiAgICAgICAgICAgIHZhciBpdGVtID0gX2EuaXRlbTtcbiAgICAgICAgICAgIHJldHVybiBTdHJpbmcoaXRlbSk7XG4gICAgICAgIH0sXG4gICAgICAgIHRocmVzaG9sZDogMzAsXG4gICAgfTtcbiAgICByZXR1cm4gTmVzdGFibGU7XG59KHJlYWN0XzEuQ29tcG9uZW50KSk7XG5leHBvcnRzLmRlZmF1bHQgPSBOZXN0YWJsZTtcbiJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///./src/Nestable/Nestable.tsx\n"); +eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar react_1 = __importStar(__webpack_require__(/*! react */ \"./node_modules/react/index.js\"));\nvar react_addons_shallow_compare_1 = __importDefault(__webpack_require__(/*! react-addons-shallow-compare */ \"./node_modules/react-addons-shallow-compare/index.js\"));\nvar react_addons_update_1 = __importDefault(__webpack_require__(/*! react-addons-update */ \"./node_modules/react-addons-update/index.js\"));\nvar classnames_1 = __importDefault(__webpack_require__(/*! classnames */ \"./node_modules/classnames/index.js\"));\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nvar NestableItem_1 = __importDefault(__webpack_require__(/*! ./NestableItem */ \"./src/Nestable/NestableItem.tsx\"));\nvar Nestable = /** @class */ (function (_super) {\n __extends(Nestable, _super);\n function Nestable(props) {\n var _this = _super.call(this, props) || this;\n _this.el = null;\n _this.elCopyStyles = null;\n _this.mouse = {\n last: { x: 0 },\n shift: { x: 0 },\n };\n // ––––––––––––––––––––––––––––––––––––\n // Public Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.collapse = function (itemIds) {\n var _a = _this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var items = _this.state.items;\n if (itemIds === 'NONE') {\n _this.setState({\n collapsedItems: collapsed\n ? (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n : [],\n });\n }\n else if (itemIds === 'ALL') {\n _this.setState({\n collapsedItems: collapsed\n ? []\n : (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp }),\n });\n }\n else if ((0, utils_1.isArray)(itemIds)) {\n _this.setState({\n collapsedItems: (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n .filter(function (id) { return (itemIds.indexOf(id) > -1) !== collapsed; }),\n });\n }\n };\n // ––––––––––––––––––––––––––––––––––––\n // Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.startTrackMouse = function () {\n document.addEventListener('mousemove', _this.onMouseMove);\n document.addEventListener('mouseup', _this.onDragEnd);\n document.addEventListener('keydown', _this.onKeyDown);\n };\n _this.stopTrackMouse = function () {\n document.removeEventListener('mousemove', _this.onMouseMove);\n document.removeEventListener('mouseup', _this.onDragEnd);\n document.removeEventListener('keydown', _this.onKeyDown);\n _this.elCopyStyles = null;\n };\n _this.getItemDepth = function (item) {\n var childrenProp = _this.props.childrenProp;\n var level = 1;\n if (item[childrenProp].length > 0) {\n var childrenDepths = item[childrenProp].map(_this.getItemDepth);\n level += Math.max.apply(Math, childrenDepths);\n }\n return level;\n };\n _this.checkIfCollapsed = function (item) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n return !!((collapsedItems.indexOf(item[idProp]) > -1) !== collapsed);\n };\n // ––––––––––––––––––––––––––––––––––––\n // Click handlers or event handlers\n // ––––––––––––––––––––––––––––––––––––\n _this.onDragStart = function (e, item) {\n var onDragStart = _this.props.onDragStart;\n e.preventDefault();\n e.stopPropagation();\n if (!(e.target instanceof Element))\n return;\n _this.el = (0, utils_1.closest)(e.target, '.nestable-item');\n _this.startTrackMouse();\n _this.onMouseMove(e);\n onDragStart({ dragItem: item });\n _this.setState({\n dragItem: item,\n itemsOld: _this.state.items,\n });\n };\n _this.onDragEnd = function (e, isCancel) {\n var onDragEnd = _this.props.onDragEnd;\n e === null || e === void 0 ? void 0 : e.preventDefault();\n _this.stopTrackMouse();\n _this.el = null;\n onDragEnd();\n isCancel\n ? _this.dragRevert()\n : _this.dragApply();\n };\n _this.onMouseMove = function (e) {\n var _a = _this.props, group = _a.group, threshold = _a.threshold;\n var dragItem = _this.state.dragItem;\n var clientX = e.clientX, clientY = e.clientY;\n var transformProps = (0, utils_1.getTransformProps)(clientX, clientY);\n var elCopy = document.querySelector(\".nestable-\".concat(group, \" .nestable-drag-layer > .nestable-list\"));\n if (!_this.elCopyStyles) {\n var offset = (0, utils_1.getOffsetRect)(_this.el);\n var scroll_1 = (0, utils_1.getTotalScroll)(_this.el);\n _this.elCopyStyles = __assign({ marginTop: offset.top - clientY - scroll_1.top, marginLeft: offset.left - clientX - scroll_1.left }, transformProps);\n }\n else {\n _this.elCopyStyles = __assign(__assign({}, _this.elCopyStyles), transformProps);\n Object.keys(transformProps).forEach(function (key) {\n elCopy.style[key] = transformProps[key];\n });\n var diffX = clientX - _this.mouse.last.x;\n if ((diffX >= 0 && _this.mouse.shift.x >= 0) ||\n (diffX <= 0 && _this.mouse.shift.x <= 0)) {\n _this.mouse.shift.x += diffX;\n }\n else {\n _this.mouse.shift.x = 0;\n }\n _this.mouse.last.x = clientX;\n if (Math.abs(_this.mouse.shift.x) > threshold) {\n if (_this.mouse.shift.x > 0) {\n _this.tryIncreaseDepth(dragItem);\n }\n else {\n _this.tryDecreaseDepth(dragItem);\n }\n _this.mouse.shift.x = 0;\n }\n }\n };\n _this.onMouseEnter = function (e, item) {\n e.preventDefault();\n e.stopPropagation();\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = _this.state.dragItem;\n if (dragItem[idProp] === item[idProp])\n return;\n var pathFrom = _this.getPathById(dragItem[idProp]);\n var pathTo = _this.getPathById(item[idProp]);\n // if collapsed by default\n // and move out the only child\n // remove parent node from list of open nodes\n var collapseProps = {};\n if (collapsed && pathFrom.length > 1) {\n var parent_1 = _this.getItemByPath(pathFrom.slice(0, -1));\n if (parent_1[childrenProp].length === 1) {\n collapseProps = _this.onToggleCollapse(parent_1, true);\n }\n }\n _this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n };\n _this.onToggleCollapse = function (item, isGetter) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n var isCollapsed = _this.checkIfCollapsed(item);\n var newState = {\n collapsedItems: (isCollapsed !== collapsed)\n ? collapsedItems.filter(function (id) { return id !== item[idProp]; })\n : collapsedItems.concat(item[idProp]),\n };\n if (isGetter) {\n return newState;\n }\n else {\n _this.setState(newState);\n _this.onCollapseChange(newState.collapsedItems);\n }\n };\n _this.onCollapseChange = function (ids) {\n var _a = _this.props, collapsed = _a.collapsed, onCollapseChange = _a.onCollapseChange;\n onCollapseChange(collapsed ? { openIds: ids } : { closedIds: ids });\n };\n _this.onKeyDown = function (e) {\n if (e.which === 27) {\n // ESC\n _this.onDragEnd(null, true);\n }\n };\n _this.state = {\n items: [],\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n collapsedItems: [],\n };\n return _this;\n }\n Nestable.prototype.componentDidMount = function () {\n var _a = this.props, items = _a.items, childrenProp = _a.childrenProp;\n // make sure every item has property 'children'\n items = (0, utils_1.listWithChildren)(items, childrenProp);\n this.setState({ items: items });\n };\n Nestable.prototype.componentDidUpdate = function (prevProps) {\n var _this = this;\n var _a = this, _b = _a.props, itemsNew = _b.items, childrenProp = _b.childrenProp, state = _a.state;\n var isPropsChanged = (0, react_addons_shallow_compare_1.default)(__assign(__assign({}, this), { props: prevProps, state: state }), this.props, state);\n if (isPropsChanged) {\n this.stopTrackMouse();\n this.setState(function (prevState) {\n var newState = __assign(__assign({}, prevState), { items: (0, utils_1.listWithChildren)(itemsNew, childrenProp), dragItem: null, isDirty: false });\n if (prevProps.collapsed !== _this.props.collapsed) {\n newState.collapsedItems = [];\n _this.onCollapseChange(newState.collapsedItems);\n }\n return newState;\n });\n }\n };\n Nestable.prototype.componentWillUnmount = function () {\n this.stopTrackMouse();\n };\n Nestable.prototype.moveItem = function (_a, extraProps) {\n var dragItem = _a.dragItem, pathFrom = _a.pathFrom, pathTo = _a.pathTo;\n if (extraProps === void 0) { extraProps = {}; }\n var _b = this.props, childrenProp = _b.childrenProp, confirmChange = _b.confirmChange;\n var dragItemSize = this.getItemDepth(dragItem);\n var items = this.state.items;\n // the remove action might affect the next position,\n // so update next coordinates accordingly\n var realPathTo = this.getRealNextPath(pathFrom, pathTo, dragItemSize);\n if (realPathTo.length === 0)\n return;\n // user can validate every movement\n var destinationPath = realPathTo.length > pathTo.length\n ? pathTo\n : pathTo.slice(0, -1);\n var destinationParent = this.getItemByPath(destinationPath);\n var removePath = this.getSplicePath(pathFrom, {\n numToRemove: 1,\n childrenProp: childrenProp,\n });\n var insertPath = this.getSplicePath(realPathTo, {\n numToRemove: 0,\n itemsToInsert: [dragItem],\n childrenProp: childrenProp,\n });\n items = (0, react_addons_update_1.default)(items, removePath);\n items = (0, react_addons_update_1.default)(items, insertPath);\n if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent, items: items }))\n return;\n this.setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { items: items, isDirty: true }), extraProps)); });\n if (extraProps.collapsedItems !== this.state.collapsedItems) {\n this.onCollapseChange(extraProps.collapsedItems);\n }\n };\n Nestable.prototype.tryIncreaseDepth = function (dragItem) {\n var _a = this.props, maxDepth = _a.maxDepth, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n var newDepth = pathFrom.length + this.getItemDepth(dragItem);\n // has previous sibling and isn't at max depth\n if (itemIndex > 0 && newDepth <= maxDepth) {\n var prevSibling = this.getItemByPath(pathFrom.slice(0, -1).concat(itemIndex - 1));\n // previous sibling is not collapsed\n if (!prevSibling[childrenProp].length || !this.checkIfCollapsed(prevSibling)) {\n var pathTo = pathFrom\n .slice(0, -1)\n .concat(itemIndex - 1)\n .concat(prevSibling[childrenProp].length);\n // if collapsed by default\n // and was no children here\n // open this node\n var collapseProps = {};\n if (collapsed && !prevSibling[childrenProp].length) {\n collapseProps = this.onToggleCollapse(prevSibling, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.tryDecreaseDepth = function (dragItem) {\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n // has parent\n if (pathFrom.length > 1) {\n var parent_2 = this.getItemByPath(pathFrom.slice(0, -1));\n // is last (by order) item in array\n if (itemIndex + 1 === parent_2[childrenProp].length) {\n var pathTo = pathFrom.slice(0, -1);\n pathTo[pathTo.length - 1] += 1;\n // if collapsed by default\n // and is last (by count) item in array\n // remove this node from list of open nodes\n var collapseProps = {};\n if (collapsed && parent_2[childrenProp].length === 1) {\n collapseProps = this.onToggleCollapse(parent_2, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.dragApply = function () {\n var _a = this.props, onChange = _a.onChange, idProp = _a.idProp;\n var _b = this.state, items = _b.items, isDirty = _b.isDirty, dragItem = _b.dragItem;\n this.setState({\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n if (onChange && isDirty) {\n var targetPath = this.getPathById(dragItem[idProp], items);\n onChange({ items: items, dragItem: dragItem, targetPath: targetPath });\n }\n };\n Nestable.prototype.dragRevert = function () {\n var itemsOld = this.state.itemsOld;\n this.setState({\n items: itemsOld,\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n };\n // ––––––––––––––––––––––––––––––––––––\n // Getter methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.getPathById = function (id, items) {\n var _this = this;\n if (items === void 0) { items = this.state.items; }\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var path = [];\n items.every(function (item, i) {\n if (item[idProp] === id) {\n path.push(i);\n }\n else if (item[childrenProp]) {\n var childrenPath = _this.getPathById(id, item[childrenProp]);\n if (childrenPath.length) {\n path = path.concat(i).concat(childrenPath);\n }\n }\n return path.length === 0;\n });\n return path;\n };\n Nestable.prototype.getItemByPath = function (path, items) {\n if (items === void 0) { items = this.state.items; }\n var childrenProp = this.props.childrenProp;\n var item = null;\n path.forEach(function (index) {\n var list = item ? item[childrenProp] : items;\n item = list[index];\n });\n return item;\n };\n Nestable.prototype.getSplicePath = function (path, options) {\n if (options === void 0) { options = {}; }\n var splicePath = {};\n var numToRemove = options.numToRemove || 0;\n var itemsToInsert = options.itemsToInsert || [];\n var lastIndex = path.length - 1;\n var currentPath = splicePath;\n path.forEach(function (index, i) {\n var _a;\n if (i === lastIndex) {\n currentPath.$splice = [__spreadArray([index, numToRemove], itemsToInsert, true)];\n }\n else {\n var nextPath = {};\n currentPath[index] = (_a = {}, _a[options.childrenProp] = nextPath, _a);\n currentPath = nextPath;\n }\n });\n return splicePath;\n };\n Nestable.prototype.getRealNextPath = function (prevPath, nextPath, dragItemSize) {\n var _a = this.props, childrenProp = _a.childrenProp, maxDepth = _a.maxDepth;\n var ppLastIndex = prevPath.length - 1;\n var npLastIndex = nextPath.length - 1;\n var newDepth = nextPath.length + dragItemSize - 1;\n if (prevPath.length < nextPath.length) {\n // move into depth\n var wasShifted_1 = false;\n // if new depth exceeds max, try to put after item instead of into item\n if (newDepth > maxDepth && nextPath.length) {\n return this.getRealNextPath(prevPath, nextPath.slice(0, -1), dragItemSize);\n }\n return nextPath.map(function (nextIndex, i) {\n if (wasShifted_1) {\n return i === npLastIndex\n ? nextIndex + 1\n : nextIndex;\n }\n if (typeof prevPath[i] !== 'number') {\n return nextIndex;\n }\n if (nextPath[i] > prevPath[i] && i === ppLastIndex) {\n wasShifted_1 = true;\n return nextIndex - 1;\n }\n return nextIndex;\n });\n }\n else if (prevPath.length === nextPath.length) {\n // if move bottom + move to item with children --> make it a first child instead of swap\n if (nextPath[npLastIndex] > prevPath[npLastIndex]) {\n var target = this.getItemByPath(nextPath);\n if (newDepth < maxDepth &&\n target[childrenProp] &&\n target[childrenProp].length &&\n !this.checkIfCollapsed(target)) {\n return nextPath\n .slice(0, -1)\n .concat(nextPath[npLastIndex] - 1)\n .concat(0);\n }\n }\n }\n return nextPath;\n };\n Nestable.prototype.getItemOptions = function () {\n var _a = this.props, renderItem = _a.renderItem, renderCollapseIcon = _a.renderCollapseIcon, handler = _a.handler, disableCollapse = _a.disableCollapse, disableDrag = _a.disableDrag, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = this.state.dragItem;\n return {\n dragItem: dragItem,\n idProp: idProp,\n childrenProp: childrenProp,\n disableCollapse: disableCollapse,\n disableDrag: disableDrag,\n renderItem: renderItem,\n renderCollapseIcon: renderCollapseIcon,\n handler: handler,\n checkIfCollapsed: this.checkIfCollapsed,\n onDragStart: this.onDragStart,\n onMouseEnter: this.onMouseEnter,\n onToggleCollapse: this.onToggleCollapse,\n };\n };\n // ––––––––––––––––––––––––––––––––––––\n // Render methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.renderDragLayer = function () {\n var _a = this.props, group = _a.group, idProp = _a.idProp;\n var dragItem = this.state.dragItem;\n var el = document.querySelector(\".nestable-\".concat(group, \" .nestable-item-\").concat(dragItem[idProp]));\n var listStyles = {};\n if (el) {\n listStyles.width = el.clientWidth;\n }\n if (this.elCopyStyles) {\n listStyles = __assign(__assign({}, listStyles), this.elCopyStyles);\n }\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: \"nestable-drag-layer\" },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\", style: listStyles },\n react_1.default.createElement(NestableItem_1.default, { item: dragItem, options: options, isCopy: true }))));\n };\n Nestable.prototype.render = function () {\n var _a = this.props, group = _a.group, className = _a.className, idProp = _a.idProp;\n var _b = this.state, items = _b.items, dragItem = _b.dragItem;\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: (0, classnames_1.default)(className, 'nestable', \"nestable-\".concat(group), { 'is-drag-active': dragItem }) },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\" }, items.map(function (item, i) {\n return (react_1.default.createElement(NestableItem_1.default, { key: item[idProp], index: i, item: item, options: options }));\n })),\n dragItem && this.renderDragLayer()));\n };\n Nestable.defaultProps = {\n childrenProp: 'children',\n collapsed: false,\n confirmChange: function () { return true; },\n disableCollapse: false,\n disableDrag: false,\n group: Math.random().toString(36).slice(2),\n idProp: 'id',\n items: [],\n maxDepth: 10,\n onChange: function () { },\n onCollapseChange: function () { },\n onDragEnd: function () { },\n onDragStart: function () { },\n renderItem: function (_a) {\n var item = _a.item;\n return String(item);\n },\n threshold: 30,\n };\n return Nestable;\n}(react_1.Component));\nexports[\"default\"] = Nestable;\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvTmVzdGFibGUvTmVzdGFibGUudHN4IiwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0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IGlmIChpdGVtSWRzID09PSAnTk9ORScpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiBjb2xsYXBzZWRcbiAgICAgICAgICAgICAgICAgICAgICAgID8gKDAsIHV0aWxzXzEuZ2V0QWxsTm9uRW1wdHlOb2Rlc0lkcykoaXRlbXMsIHsgaWRQcm9wOiBpZFByb3AsIGNoaWxkcmVuUHJvcDogY2hpbGRyZW5Qcm9wIH0pXG4gICAgICAgICAgICAgICAgICAgICAgICA6IFtdLFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSBpZiAoaXRlbUlkcyA9PT0gJ0FMTCcpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiBjb2xsYXBzZWRcbiAgICAgICAgICAgICAgICAgICAgICAgID8gW11cbiAgICAgICAgICAgICAgICAgICAgICAgIDogKDAsIHV0aWxzXzEuZ2V0QWxsTm9uRW1wdHlOb2Rlc0lkcykoaXRlbXMsIHsgaWRQcm9wOiBpZFByb3AsIGNoaWxkcmVuUHJvcDogY2hpbGRyZW5Qcm9wIH0pLFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSBpZiAoKDAsIHV0aWxzXzEuaXNBcnJheSkoaXRlbUlkcykpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5zZXRTdGF0ZSh7XG4gICAgICAgICAgICAgICAgICAgIGNvbGxhcHNlZEl0ZW1zOiAoMCwgdXRpbHNfMS5nZXRBbGxOb25FbXB0eU5vZGVzSWRzKShpdGVtcywgeyBpZFByb3A6IGlkUHJvcCwgY2hpbGRyZW5Qcm9wOiBjaGlsZHJlblByb3AgfSlcbiAgICAgICAgICAgICAgICAgICAgICAgIC5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ge1xuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ICs9IGRpZmZYO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXMubW91c2Uuc2hpZnQueCA9IDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIF90aGlzLm1vdXNlLmxhc3QueCA9IGNsaWVudFg7XG4gICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKF90aGlzLm1vdXNlLnNoaWZ0LngpID4gdGhyZXNob2xkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpcy5tb3VzZS5zaGlmdC54ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMudHJ5SW5jcmVhc2VEZXB0aChkcmFnSXRlbSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy50cnlEZWNyZWFzZURlcHRoKGRyYWdJdGVtKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIF90aGlzLm9uTW91c2VFbnRlciA9IGZ1bmN0aW9uIChlLCBpdGVtKSB7XG4gICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMucHJvcHMsIGNvbGxhcHNlZCA9IF9hLmNvbGxhcHNlZCwgaWRQcm9wID0gX2EuaWRQcm9wLCBjaGlsZHJlblByb3AgPSBfYS5jaGlsZHJlblByb3A7XG4gICAgICAgICAgICB2YXIgZHJhZ0l0ZW0gPSBfdGhpcy5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XdEZXB0aCA8PSBtYXhEZXB0aCkge1xuICAgICAgICAgICAgdmFyIHByZXZTaWJsaW5nID0gdGhpcy5nZXRJdGVtQnlQYXRoKHBhdGhGcm9tLnNsaWNlKDAsIC0xKS5jb25jYXQoaXRlbUluZGV4IC0gMSkpO1xuICAgICAgICAgICAgLy8gcHJldmlvdXMgc2libGluZyBpcyBub3QgY29sbGFwc2VkXG4gICAgICAgICAgICBpZiAoIXByZXZTaWJsaW5nW2NoaWxkcmVuUHJvcF0ubGVuZ3RoIHx8ICF0aGlzLmNoZWNrSWZDb2xsYXBzZWQocHJldlNpYmxpbmcpKSB7XG4gICAgICAgICAgICAgICAgdmFyIHBhdGhUbyA9IHBhdGhGcm9tXG4gICAgICAgICAgICAgICAgICAgIC5zbGljZSgwLCAtMSlcbiAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChpdGVtSW5kZXggLSAxKVxuICAgICAgICAgICAgICAgICAgICAuY29uY2F0KHByZXZTaWJsaW5nW2NoaWxkcmVuUHJvcF0ubGVuZ3RoKTtcbiAgICAgICAgICAgICAgICAvLyBpZiBjb2xsYXBzZWQgYnkgZGVmYXVsdFxuICAgICAgICAgICAgICAgIC8vIGFuZCB3YXMgbm8gY2hpbGRyZW4gaGVyZVxuICAgICAgICAgICAgICAgIC8vIG9wZW4gdGhpcyBub2RlXG4gICAgICAgICAgICAgICAgdmFyIGNvbGxhcHNlUHJvcHMgPSB7fTtcbiAgICAgICAgICAgICAgICBpZiAoY29sbGFwc2VkICYmICFwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICBjb2xsYXBzZVByb3BzID0gdGhpcy5vblRvZ2dsZUNvbGxhcHNlKHByZXZTaWJsaW5nLCB0cnVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5tb3ZlSXRlbSh7IGRyYWdJdGVtOiBkcmFnSXRlbSwgcGF0aEZyb206IHBhdGhGcm9tL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ICAgICAgICAgICBpdGVtID0gbGlzdFtpbmRleF07XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gaXRlbTtcbiAgICB9O1xuICAgIE5lc3RhYmxlLnByb3RvdHlwZS5nZXRTcGxpY2VQYXRoID0gZnVuY3Rpb24gKHBhdGgsIG9wdGlvbnMpIHtcbiAgICAgICAgaWYgKG9wdGlvbnMgPT09IHZvaWQgMCkgeyBvcHRpb25zID0ge307IH1cbiAgICAgICAgdmFyIHNwbGljZVBhdGggPSB7fTtcbiAgICAgICAgdmFyIG51bVRvUmVtb3ZlID0gb3B0aW9ucy5udW1Ub1JlbW92ZSB8fCAwO1xuICAgICAgICB2YXIgaXRlbXNUb0luc2VydCA9IG9wdGlvbnMuaXRlbXNUb0luc2VydCB8fCBbXTtcbiAgICAgICAgdmFyIGxhc3RJbmRleCA9IHBhdGgubGVuZ3RoIC0gMTtcbiAgICAgICAgdmFyIGN1cnJlbnRQYXRoID0gc3BsaWNlUGF0aDtcbiAgICAgICAgcGF0aC5mb3JFYWNoKGZ1bmN0aW9uIChpbmRleCwgaSkge1xuICAgICAgICAgICAgdmFyIF9hO1xuICAgICAgICAgICAgaWYgKGkgPT09IGxhc3RJbmRleCkge1xuICAgICAgICAgICAgICAgIGN1cnJlbnRQYXRoLiRzcGxpY2UgPSBbX19zcHJlYWRBcnJheShbaW5kZXgsIG51bVRvUmVtb3ZlXSwgaXRlbXNUb0luc2VydCwgdHJ1ZSldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgdmFyIG5leHRQYXRoID0ge307XG4gICAgICAgICAgICAgICAgY3VycmVudFBhdGhbaW5kZXhdID0gKF9hID0ge30sIF9hW29wdGlvbnMuY2hpbGRyZW5Qcm9wXSA9IG5leHRQYXRoLCBfYSk7XG4gICAgICAgICAgICAgICAgY3VycmVudFBhdGggPSBuZXh0UGF0aDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICA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gICAgICAgICAgICAgICByZXR1cm4gaSA9PT0gbnBMYXN0SW5kZXhcbiAgICAgICAgICAgICAgICAgICAgICAgID8gbmV4dEluZGV4ICsgMVxuICAgICAgICAgICAgICAgICAgICAgICAgOiBuZXh0SW5kZXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgcHJldlBhdGhbaV0gIT09ICdudW1iZXInKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0SW5kZXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChuZXh0UGF0aFtpXSA+IHByZXZQYXRoW2ldICYmIGkgPT09IHBwTGFzdEluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgIHdhc1NoaWZ0ZWRfMSA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0SW5kZXggLSAxO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4O1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAocHJldlBhdGgubGVuZ3RoID09PSBuZXh0UGF0aC5sZW5ndGgpIHtcbiAgICAgICAgICAgIC8vIGlmIG1vdmUgYm90dG9tICsgbW92ZSB0byBpdGVtIHdpdGggY2hpbGRyZW4gLS0+IG1ha2UgaXQgYSBmaXJzdCBjaGlsZCBpbnN0ZWFkIG9mIHN3YXBcbiAgICAgICAgICAgIGlmIChuZXh0UGF0aFtucExhc3RJbmRleF0gPiBwcmV2UGF0aFtucExhc3RJbmRleF0pIHtcbiAgICAgICAgICAgICAgICB2YXIgdGFyZ2V0ID0gdGhpcy5nZXRJdGVtQnlQYXRoKG5leHRQYXRoKTtcbiAgICAgICAgICAgICAgICBpZiAobmV3RGVwdGggPCBtYXhEZXB0aCAmJlxuICAgICAgICAgICAgICAgICAgICB0YXJnZXRbY2hpbGRyZW5Qcm9wXSAmJlxuICAgICAgICAgICAgICAgICAgICB0YXJnZXRbY2hpbGRyZW5Qcm9wXS5sZW5ndGggJiZcbiAgICAgICAgICAgICAgICAgICAgIXRoaXMuY2hlY2tJZkNvbGxhcHNlZCh0YXJnZXQpKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0UGF0aFxuICAgICAgICAgICAgICAgICAgICAgICAgLnNsaWNlKDAsIC0xKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChuZXh0UGF0aFtucExhc3RJbmRleF0gLSAxKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmNvbmNhdCgwKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIG5leHRQYXRoO1xuICAgIH07XG4gICAgTmVzdGFibGUucHJvdG90eXBlLmdldEl0ZW1PcHRpb25zID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgX2EgPSB0aGlzLnByb3BzLCByZW5kZXJJdGVtID0gX2EucmVuZGVySXRlbSwgcmVuZGVyQ29sbGFwc2VJY29uID0gX2EucmVuZGVyQ29sbGFwc2VJY29uLCBoYW5kbGVyID0gX2EuaGFuZGxlciwgZGlzYWJsZUNvbGxhcHNlID0gX2EuZGlzYWJsZUNvbGxhcHNlLCBkaXNhYmxlRHJhZyA9IF9hLmRpc2FibGVEcmFnLCBpZFByb3AgPSBfYS5pZFByb3AsIGNoaWxkcmVuUHJvcCA9IF9hLmNoaWxkcmVuUHJvcDtcbiAgICAgICAgdmFyIGRyYWdJdGVtID0gdGhpcy5zdGF0ZS5kcmFnSXRlbTtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIGRyYWdJdGVtOiBkcmFnSXRlbSxcbiAgICAgICAgICAgIGlkUHJvcDogaWRQcm9wLFxuICAgICAgICAgICAgY2hpbGRyZW5Qcm9wOiBjaGlsZHJlblByb3AsXG4gICAgICAgICAgICBkaXNhYmxlQ29sbGFwc2U6IG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4gdHJ1ZTsgfSxcbiAgICAgICAgZGlzYWJsZUNvbGxhcHNlOiBmYWxzZSxcbiAgICAgICAgZGlzYWJsZURyYWc6IGZhbHNlLFxuICAgICAgICBncm91cDogTWF0aC5yYW5kb20oKS50b1N0cmluZygzNikuc2xpY2UoMiksXG4gICAgICAgIGlkUHJvcDogJ2lkJyxcbiAgICAgICAgaXRlbXM6IFtdLFxuICAgICAgICBtYXhEZXB0aDogMTAsXG4gICAgICAgIG9uQ2hhbmdlOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uQ29sbGFwc2VDaGFuZ2U6IGZ1bmN0aW9uICgpIHsgfSxcbiAgICAgICAgb25EcmFnRW5kOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uRHJhZ1N0YXJ0OiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIHJlbmRlckl0ZW06IGZ1bmN0aW9uIChfYSkge1xuICAgICAgICAgICAgdmFyIGl0ZW0gPSBfYS5pdGVtO1xuICAgICAgICAgICAgcmV0dXJuIFN0cmluZyhpdGVtKTtcbiAgICAgICAgfSxcbiAgICAgICAgdGhyZXNob2xkOiAzMCxcbiAgICB9O1xuICAgIHJldHVybiBOZXN0YWJsZTtcbn0ocmVhY3RfMS5Db21wb25lbnQpKTtcbmV4cG9ydHMuZGVmYXVsdCA9IE5lc3RhYmxlO1xuIl0sIm5hbWVzIjpbXSwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///./src/Nestable/Nestable.tsx\n"); /***/ }), @@ -459,7 +459,7 @@ module.exports = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGlu /******/ /******/ /* webpack/runtime/getFullHash */ /******/ (() => { -/******/ __webpack_require__.h = () => ("cdb2482319946aafcd82") +/******/ __webpack_require__.h = () => ("610d98a9912d7f0a78f3") /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ diff --git a/dist/types.d.ts b/dist/types.d.ts index 2c26ad4..7acf9d3 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -30,6 +30,7 @@ export type Item = Record; export type ConfirmChange = (options: { dragItem: Item; destinationParent: Item | null; + items: Item[]; }) => boolean; export type DisableDragFn = (options: { item: Item; diff --git a/src/Nestable/Nestable.tsx b/src/Nestable/Nestable.tsx index babc473..ec4c773 100644 --- a/src/Nestable/Nestable.tsx +++ b/src/Nestable/Nestable.tsx @@ -155,7 +155,6 @@ class Nestable extends Component { ? pathTo : pathTo.slice(0, -1); const destinationParent = this.getItemByPath(destinationPath); - if (!confirmChange({dragItem, destinationParent})) return; const removePath = this.getSplicePath(pathFrom, { numToRemove: 1, @@ -170,6 +169,7 @@ class Nestable extends Component { items = update(items, removePath); items = update(items, insertPath); + if (!confirmChange({dragItem, destinationParent, items})) return; this.setState(prevState => ({ ...prevState, diff --git a/src/types.ts b/src/types.ts index 969b4e7..2356612 100644 --- a/src/types.ts +++ b/src/types.ts @@ -38,6 +38,7 @@ export type ConfirmChange = ( options: { dragItem: Item; destinationParent: Item | null; + items: Item[]; } ) => boolean; From defcc69401848950ca7adf5f01eaa47e01182a8b Mon Sep 17 00:00:00 2001 From: Jeff Watson Date: Wed, 13 Dec 2023 09:24:30 -0600 Subject: [PATCH 2/2] rebuild after merge Signed-off-by: Jeff Watson --- dist/example/example.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/example/example.js b/dist/example/example.js index 445be19..865d7b6 100644 --- a/dist/example/example.js +++ b/dist/example/example.js @@ -279,7 +279,7 @@ eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) { /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; -eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar react_1 = __importStar(__webpack_require__(/*! react */ \"./node_modules/react/index.js\"));\nvar react_addons_shallow_compare_1 = __importDefault(__webpack_require__(/*! react-addons-shallow-compare */ \"./node_modules/react-addons-shallow-compare/index.js\"));\nvar react_addons_update_1 = __importDefault(__webpack_require__(/*! react-addons-update */ \"./node_modules/react-addons-update/index.js\"));\nvar classnames_1 = __importDefault(__webpack_require__(/*! classnames */ \"./node_modules/classnames/index.js\"));\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nvar NestableItem_1 = __importDefault(__webpack_require__(/*! ./NestableItem */ \"./src/Nestable/NestableItem.tsx\"));\nvar Nestable = /** @class */ (function (_super) {\n __extends(Nestable, _super);\n function Nestable(props) {\n var _this = _super.call(this, props) || this;\n _this.el = null;\n _this.elCopyStyles = null;\n _this.mouse = {\n last: { x: 0 },\n shift: { x: 0 },\n };\n // ––––––––––––––––––––––––––––––––––––\n // Public Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.collapse = function (itemIds) {\n var _a = _this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var items = _this.state.items;\n if (itemIds === 'NONE') {\n _this.setState({\n collapsedItems: collapsed\n ? (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n : [],\n });\n }\n else if (itemIds === 'ALL') {\n _this.setState({\n collapsedItems: collapsed\n ? []\n : (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp }),\n });\n }\n else if ((0, utils_1.isArray)(itemIds)) {\n _this.setState({\n collapsedItems: (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n .filter(function (id) { return (itemIds.indexOf(id) > -1) !== collapsed; }),\n });\n }\n };\n // ––––––––––––––––––––––––––––––––––––\n // Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.startTrackMouse = function () {\n document.addEventListener('mousemove', _this.onMouseMove);\n document.addEventListener('mouseup', _this.onDragEnd);\n document.addEventListener('keydown', _this.onKeyDown);\n };\n _this.stopTrackMouse = function () {\n document.removeEventListener('mousemove', _this.onMouseMove);\n document.removeEventListener('mouseup', _this.onDragEnd);\n document.removeEventListener('keydown', _this.onKeyDown);\n _this.elCopyStyles = null;\n };\n _this.getItemDepth = function (item) {\n var childrenProp = _this.props.childrenProp;\n var level = 1;\n if (item[childrenProp].length > 0) {\n var childrenDepths = item[childrenProp].map(_this.getItemDepth);\n level += Math.max.apply(Math, childrenDepths);\n }\n return level;\n };\n _this.checkIfCollapsed = function (item) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n return !!((collapsedItems.indexOf(item[idProp]) > -1) !== collapsed);\n };\n // ––––––––––––––––––––––––––––––––––––\n // Click handlers or event handlers\n // ––––––––––––––––––––––––––––––––––––\n _this.onDragStart = function (e, item) {\n var onDragStart = _this.props.onDragStart;\n e.preventDefault();\n e.stopPropagation();\n if (!(e.target instanceof Element))\n return;\n _this.el = (0, utils_1.closest)(e.target, '.nestable-item');\n _this.startTrackMouse();\n _this.onMouseMove(e);\n onDragStart({ dragItem: item });\n _this.setState({\n dragItem: item,\n itemsOld: _this.state.items,\n });\n };\n _this.onDragEnd = function (e, isCancel) {\n var onDragEnd = _this.props.onDragEnd;\n e === null || e === void 0 ? void 0 : e.preventDefault();\n _this.stopTrackMouse();\n _this.el = null;\n onDragEnd();\n isCancel\n ? _this.dragRevert()\n : _this.dragApply();\n };\n _this.onMouseMove = function (e) {\n var _a = _this.props, group = _a.group, threshold = _a.threshold;\n var dragItem = _this.state.dragItem;\n var clientX = e.clientX, clientY = e.clientY;\n var transformProps = (0, utils_1.getTransformProps)(clientX, clientY);\n var elCopy = document.querySelector(\".nestable-\".concat(group, \" .nestable-drag-layer > .nestable-list\"));\n if (!_this.elCopyStyles) {\n var offset = (0, utils_1.getOffsetRect)(_this.el);\n var scroll_1 = (0, utils_1.getTotalScroll)(_this.el);\n _this.elCopyStyles = __assign({ marginTop: offset.top - clientY - scroll_1.top, marginLeft: offset.left - clientX - scroll_1.left }, transformProps);\n }\n else {\n _this.elCopyStyles = __assign(__assign({}, _this.elCopyStyles), transformProps);\n Object.keys(transformProps).forEach(function (key) {\n elCopy.style[key] = transformProps[key];\n });\n var diffX = clientX - _this.mouse.last.x;\n if ((diffX >= 0 && _this.mouse.shift.x >= 0) ||\n (diffX <= 0 && _this.mouse.shift.x <= 0)) {\n _this.mouse.shift.x += diffX;\n }\n else {\n _this.mouse.shift.x = 0;\n }\n _this.mouse.last.x = clientX;\n if (Math.abs(_this.mouse.shift.x) > threshold) {\n if (_this.mouse.shift.x > 0) {\n _this.tryIncreaseDepth(dragItem);\n }\n else {\n _this.tryDecreaseDepth(dragItem);\n }\n _this.mouse.shift.x = 0;\n }\n }\n };\n _this.onMouseEnter = function (e, item) {\n e.preventDefault();\n e.stopPropagation();\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = _this.state.dragItem;\n if (dragItem[idProp] === item[idProp])\n return;\n var pathFrom = _this.getPathById(dragItem[idProp]);\n var pathTo = _this.getPathById(item[idProp]);\n // if collapsed by default\n // and move out the only child\n // remove parent node from list of open nodes\n var collapseProps = {};\n if (collapsed && pathFrom.length > 1) {\n var parent_1 = _this.getItemByPath(pathFrom.slice(0, -1));\n if (parent_1[childrenProp].length === 1) {\n collapseProps = _this.onToggleCollapse(parent_1, true);\n }\n }\n _this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n };\n _this.onToggleCollapse = function (item, isGetter) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n var isCollapsed = _this.checkIfCollapsed(item);\n var newState = {\n collapsedItems: (isCollapsed !== collapsed)\n ? collapsedItems.filter(function (id) { return id !== item[idProp]; })\n : collapsedItems.concat(item[idProp]),\n };\n if (isGetter) {\n return newState;\n }\n else {\n _this.setState(newState);\n _this.onCollapseChange(newState.collapsedItems);\n }\n };\n _this.onCollapseChange = function (ids) {\n var _a = _this.props, collapsed = _a.collapsed, onCollapseChange = _a.onCollapseChange;\n onCollapseChange(collapsed ? { openIds: ids } : { closedIds: ids });\n };\n _this.onKeyDown = function (e) {\n if (e.which === 27) {\n // ESC\n _this.onDragEnd(null, true);\n }\n };\n _this.state = {\n items: [],\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n collapsedItems: [],\n };\n return _this;\n }\n Nestable.prototype.componentDidMount = function () {\n var _a = this.props, items = _a.items, childrenProp = _a.childrenProp;\n // make sure every item has property 'children'\n items = (0, utils_1.listWithChildren)(items, childrenProp);\n this.setState({ items: items });\n };\n Nestable.prototype.componentDidUpdate = function (prevProps) {\n var _this = this;\n var _a = this, _b = _a.props, itemsNew = _b.items, childrenProp = _b.childrenProp, state = _a.state;\n var isPropsChanged = (0, react_addons_shallow_compare_1.default)(__assign(__assign({}, this), { props: prevProps, state: state }), this.props, state);\n if (isPropsChanged) {\n this.stopTrackMouse();\n this.setState(function (prevState) {\n var newState = __assign(__assign({}, prevState), { items: (0, utils_1.listWithChildren)(itemsNew, childrenProp), dragItem: null, isDirty: false });\n if (prevProps.collapsed !== _this.props.collapsed) {\n newState.collapsedItems = [];\n _this.onCollapseChange(newState.collapsedItems);\n }\n return newState;\n });\n }\n };\n Nestable.prototype.componentWillUnmount = function () {\n this.stopTrackMouse();\n };\n Nestable.prototype.moveItem = function (_a, extraProps) {\n var dragItem = _a.dragItem, pathFrom = _a.pathFrom, pathTo = _a.pathTo;\n if (extraProps === void 0) { extraProps = {}; }\n var _b = this.props, childrenProp = _b.childrenProp, confirmChange = _b.confirmChange;\n var dragItemSize = this.getItemDepth(dragItem);\n var items = this.state.items;\n // the remove action might affect the next position,\n // so update next coordinates accordingly\n var realPathTo = this.getRealNextPath(pathFrom, pathTo, dragItemSize);\n if (realPathTo.length === 0)\n return;\n // user can validate every movement\n var destinationPath = realPathTo.length > pathTo.length\n ? pathTo\n : pathTo.slice(0, -1);\n var destinationParent = this.getItemByPath(destinationPath);\n if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent }))\n return;\n var removePath = this.getSplicePath(pathFrom, {\n numToRemove: 1,\n childrenProp: childrenProp,\n });\n var insertPath = this.getSplicePath(realPathTo, {\n numToRemove: 0,\n itemsToInsert: [dragItem],\n childrenProp: childrenProp,\n });\n items = (0, react_addons_update_1.default)(items, removePath);\n items = (0, react_addons_update_1.default)(items, insertPath);\n this.setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { items: items, isDirty: true }), extraProps)); });\n if (extraProps.collapsedItems !== this.state.collapsedItems) {\n this.onCollapseChange(extraProps.collapsedItems);\n }\n };\n Nestable.prototype.tryIncreaseDepth = function (dragItem) {\n var _a = this.props, maxDepth = _a.maxDepth, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n var newDepth = pathFrom.length + this.getItemDepth(dragItem);\n // has previous sibling and isn't at max depth\n if (itemIndex > 0 && newDepth <= maxDepth) {\n var prevSibling = this.getItemByPath(pathFrom.slice(0, -1).concat(itemIndex - 1));\n // previous sibling is not collapsed\n if (!prevSibling[childrenProp].length || !this.checkIfCollapsed(prevSibling)) {\n var pathTo = pathFrom\n .slice(0, -1)\n .concat(itemIndex - 1)\n .concat(prevSibling[childrenProp].length);\n // if collapsed by default\n // and was no children here\n // open this node\n var collapseProps = {};\n if (collapsed && !prevSibling[childrenProp].length) {\n collapseProps = this.onToggleCollapse(prevSibling, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.tryDecreaseDepth = function (dragItem) {\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n // has parent\n if (pathFrom.length > 1) {\n var parent_2 = this.getItemByPath(pathFrom.slice(0, -1));\n // is last (by order) item in array\n if (itemIndex + 1 === parent_2[childrenProp].length) {\n var pathTo = pathFrom.slice(0, -1);\n pathTo[pathTo.length - 1] += 1;\n // if collapsed by default\n // and is last (by count) item in array\n // remove this node from list of open nodes\n var collapseProps = {};\n if (collapsed && parent_2[childrenProp].length === 1) {\n collapseProps = this.onToggleCollapse(parent_2, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.dragApply = function () {\n var _a = this.props, onChange = _a.onChange, idProp = _a.idProp;\n var _b = this.state, items = _b.items, isDirty = _b.isDirty, dragItem = _b.dragItem;\n this.setState({\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n if (onChange && isDirty) {\n var targetPath = this.getPathById(dragItem[idProp], items);\n onChange({ items: items, dragItem: dragItem, targetPath: targetPath });\n }\n };\n Nestable.prototype.dragRevert = function () {\n var itemsOld = this.state.itemsOld;\n this.setState({\n items: itemsOld,\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n };\n // ––––––––––––––––––––––––––––––––––––\n // Getter methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.getPathById = function (id, items) {\n var _this = this;\n if (items === void 0) { items = this.state.items; }\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var path = [];\n items.every(function (item, i) {\n if (item[idProp] === id) {\n path.push(i);\n }\n else if (item[childrenProp]) {\n var childrenPath = _this.getPathById(id, item[childrenProp]);\n if (childrenPath.length) {\n path = path.concat(i).concat(childrenPath);\n }\n }\n return path.length === 0;\n });\n return path;\n };\n Nestable.prototype.getItemByPath = function (path, items) {\n if (items === void 0) { items = this.state.items; }\n var childrenProp = this.props.childrenProp;\n var item = null;\n path.forEach(function (index) {\n var list = item ? item[childrenProp] : items;\n item = list[index];\n });\n return item;\n };\n Nestable.prototype.getSplicePath = function (path, options) {\n if (options === void 0) { options = {}; }\n var splicePath = {};\n var numToRemove = options.numToRemove || 0;\n var itemsToInsert = options.itemsToInsert || [];\n var lastIndex = path.length - 1;\n var currentPath = splicePath;\n path.forEach(function (index, i) {\n var _a;\n if (i === lastIndex) {\n currentPath.$splice = [__spreadArray([index, numToRemove], itemsToInsert, true)];\n }\n else {\n var nextPath = {};\n currentPath[index] = (_a = {}, _a[options.childrenProp] = nextPath, _a);\n currentPath = nextPath;\n }\n });\n return splicePath;\n };\n Nestable.prototype.getRealNextPath = function (prevPath, nextPath, dragItemSize) {\n var _a = this.props, childrenProp = _a.childrenProp, maxDepth = _a.maxDepth;\n var ppLastIndex = prevPath.length - 1;\n var npLastIndex = nextPath.length - 1;\n var newDepth = nextPath.length + dragItemSize - 1;\n if (prevPath.length < nextPath.length) {\n // move into depth\n var wasShifted_1 = false;\n // if new depth exceeds max, try to put after item instead of into item\n if (newDepth > maxDepth && nextPath.length) {\n return this.getRealNextPath(prevPath, nextPath.slice(0, -1), dragItemSize);\n }\n return nextPath.map(function (nextIndex, i) {\n if (wasShifted_1) {\n return i === npLastIndex\n ? nextIndex + 1\n : nextIndex;\n }\n if (typeof prevPath[i] !== 'number') {\n return nextIndex;\n }\n if (nextPath[i] > prevPath[i] && i === ppLastIndex) {\n wasShifted_1 = true;\n return nextIndex - 1;\n }\n return nextIndex;\n });\n }\n else if (prevPath.length === nextPath.length) {\n // if move bottom + move to item with children --> make it a first child instead of swap\n if (nextPath[npLastIndex] > prevPath[npLastIndex]) {\n var target = this.getItemByPath(nextPath);\n if (newDepth < maxDepth &&\n target[childrenProp] &&\n target[childrenProp].length &&\n !this.checkIfCollapsed(target)) {\n return nextPath\n .slice(0, -1)\n .concat(nextPath[npLastIndex] - 1)\n .concat(0);\n }\n }\n }\n return nextPath;\n };\n Nestable.prototype.getItemOptions = function () {\n var _a = this.props, renderItem = _a.renderItem, renderCollapseIcon = _a.renderCollapseIcon, handler = _a.handler, disableCollapse = _a.disableCollapse, disableDrag = _a.disableDrag, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = this.state.dragItem;\n return {\n dragItem: dragItem,\n idProp: idProp,\n childrenProp: childrenProp,\n disableCollapse: disableCollapse,\n disableDrag: disableDrag,\n renderItem: renderItem,\n renderCollapseIcon: renderCollapseIcon,\n handler: handler,\n checkIfCollapsed: this.checkIfCollapsed,\n onDragStart: this.onDragStart,\n onMouseEnter: this.onMouseEnter,\n onToggleCollapse: this.onToggleCollapse,\n };\n };\n // ––––––––––––––––––––––––––––––––––––\n // Render methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.renderDragLayer = function () {\n var _a = this.props, group = _a.group, idProp = _a.idProp;\n var dragItem = this.state.dragItem;\n var el = document.querySelector(\".nestable-\".concat(group, \" .nestable-item-\").concat(dragItem[idProp]));\n var listStyles = {};\n if (el) {\n listStyles.width = el.clientWidth;\n }\n if (this.elCopyStyles) {\n listStyles = __assign(__assign({}, listStyles), this.elCopyStyles);\n }\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: \"nestable-drag-layer\" },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\", style: listStyles },\n react_1.default.createElement(NestableItem_1.default, { item: dragItem, options: options, isCopy: true }))));\n };\n Nestable.prototype.render = function () {\n var _a = this.props, group = _a.group, className = _a.className, idProp = _a.idProp;\n var _b = this.state, items = _b.items, dragItem = _b.dragItem;\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: (0, classnames_1.default)(className, 'nestable', \"nestable-\".concat(group), { 'is-drag-active': dragItem }) },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\" }, items.map(function (item, i) {\n return (react_1.default.createElement(NestableItem_1.default, { key: item[idProp], index: i, item: item, options: options }));\n })),\n dragItem && this.renderDragLayer()));\n };\n Nestable.defaultProps = {\n childrenProp: 'children',\n collapsed: false,\n confirmChange: function () { return true; },\n disableCollapse: false,\n disableDrag: false,\n group: Math.random().toString(36).slice(2),\n idProp: 'id',\n items: [],\n maxDepth: 10,\n onChange: function () { },\n onCollapseChange: function () { },\n onDragEnd: function () { },\n onDragStart: function () { },\n renderItem: function (_a) {\n var item = _a.item;\n return String(item);\n },\n threshold: 30,\n };\n return Nestable;\n}(react_1.Component));\nexports[\"default\"] = Nestable;\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvTmVzdGFibGUvTmVzdGFibGUudHN4IiwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FB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IDw9IDAgJiYgX3RoaXMubW91c2Uuc2hpZnQueCA8PSAwKSkge1xuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ICs9IGRpZmZYO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXMubW91c2Uuc2hpZnQueCA9IDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIF90aGlzLm1vdXNlLmxhc3QueCA9IGNsaWVudFg7XG4gICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKF90aGlzLm1vdXNlLnNoaWZ0LngpID4gdGhyZXNob2xkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpcy5tb3VzZS5zaGlmdC54ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMudHJ5SW5jcmVhc2VEZXB0aChkcmFnSXRlbSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy50cnlEZWNyZWFzZURlcHRoKGRyYWdJdGVtKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIF90aGlzLm9uTW91c2VFbnRlciA9IGZ1bmN0aW9uIChlLCBpdGVtKSB7XG4gICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMucHJvcHMsIGNvbGxhcHNlZCA9IF9hLmNvbGxhcHNlZCwgaWRQcm9wID0gX2EuaWRQcm9wLCBjaGlsZHJlblByb3AgPSBfYS5jaGlsZHJlblByb3A7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lUHJvcHMpO1xuICAgICAgICB9O1xuICAgICAgICBfdGhpcy5vblRvZ2dsZUNvbGxhcHNlID0gZnVuY3Rpb24gKGl0ZW0sIGlzR2V0dGVyKSB7XG4gICAgICAgICAgICB2YXIgX2EgPSBfdGhpcy5wcm9wcywgY29sbGFwc2VkID0gX2EuY29sbGFwc2VkLCBpZFByb3AgPSBfYS5pZFByb3A7XG4gICAgICAgICAgICB2YXIgY29sbGFwc2VkSXRlbXMgPSBfdGhpcy5zdGF0ZS5jb2xsYXBzZWRJdGVtcztcbiAgICAgICAgICAgIHZhciBpc0NvbGxhcHNlZCA9IF90aGlzLmNoZWNrSWZDb2xsYXBzZWQoaXRlbSk7XG4gICAgICAgICAgICB2YXIgbmV3U3RhdGUgPSB7XG4gICAgICAgICAgICAgICAgY29sbGFwc2VkSXRlbXM6IChpc0NvbGxhcHNlZCAhPT0gY29sbGFwc2VkKVxuICAgICAgICAgICAgICAgICAgICA/IGNvbGxhcHNlZEl0ZW1zLmZpbHRlcihmdW5jdGlvbiAoaWQpIHsgcmV0dXJuIGlkICE9PSBpdGVtW2lkUHJvcF07IH0pXG4gICAgICAgICAgICAgICAgICAgIDogY29sbGFwc2VkSXRlbXMuY29uY2F0KGl0ZW1baWRQcm9wXSksXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKGlzR2V0dGVyKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ld1N0YXRlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgX3RoaXMuc2V0U3RhdGUobmV3U3RhdGUpO1xuICAgICAgICAgICAgICAgIF90aGlzLm9uQ29sbGFwc2VDaGFuZ2UobmV3U3RhdGUuY29sbGFwc2VkSXRlbXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBfdGhpcy5vbkNvbGxhcHNlQ2hhbmdlID0gZnVuY3Rpb24gKGlkcykge1xuICAgICAgICAgICAgdmFyIF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aWYgKGl0ZW1JbmRleCA+IDAgJiYgbmV3RGVwdGggPD0gbWF4RGVwdGgpIHtcbiAgICAgICAgICAgIHZhciBwcmV2U2libGluZyA9IHRoaXMuZ2V0SXRlbUJ5UGF0aChwYXRoRnJvbS5zbGljZSgwLCAtMSkuY29uY2F0KGl0ZW1JbmRleCAtIDEpKTtcbiAgICAgICAgICAgIC8vIHByZXZpb3VzIHNpYmxpbmcgaXMgbm90IGNvbGxhcHNlZFxuICAgICAgICAgICAgaWYgKCFwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCB8fCAhdGhpcy5jaGVja0lmQ29sbGFwc2VkKHByZXZTaWJsaW5nKSkge1xuICAgICAgICAgICAgICAgIHZhciBwYXRoVG8gPSBwYXRoRnJvbVxuICAgICAgICAgICAgICAgICAgICAuc2xpY2UoMCwgLTEpXG4gICAgICAgICAgICAgICAgICAgIC5jb25jYXQoaXRlbUluZGV4IC0gMSlcbiAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCk7XG4gICAgICAgICAgICAgICAgLy8gaWYgY29sbGFwc2VkIGJ5IGRlZmF1bHRcbiAgICAgICAgICAgICAgICAvLyBhbmQgd2FzIG5vIGNoaWxkcmVuIGhlcmVcbiAgICAgICAgICAgICAgICAvLyBvcGVuIHRoaXMgbm9kZVxuICAgICAgICAgICAgICAgIHZhciBjb2xsYXBzZVByb3BzID0ge307XG4gICAgICAgICAgICAgICAgaWYgKGNvbGxhcHNlZCAmJiAhcHJldlNpYmxpbmdbY2hpbGRyZW5Qcm9wXS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgY29sbGFwc2VQcm9wcyA9IHRoaXMub25Ub2dnbGVDb2xsYXBzZShwcmV2U2libGluZywgdHJ1ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMubW92ZUl0ZW0oeyBkcmFnSXRlbTogZHJhZ0l0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uY3Rpb24gKG5leHRJbmRleCwgaSkge1xuICAgICAgICAgICAgICAgIGlmICh3YXNTaGlmdGVkXzEpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGkgPT09IG5wTGFzdEluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICA/IG5leHRJbmRleCArIDFcbiAgICAgICAgICAgICAgICAgICAgICAgIDogbmV4dEluZGV4O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHByZXZQYXRoW2ldICE9PSAnbnVtYmVyJykge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAobmV4dFBhdGhbaV0gPiBwcmV2UGF0aFtpXSAmJiBpID09PSBwcExhc3RJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICB3YXNTaGlmdGVkXzEgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4IC0gMTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIG5leHRJbmRleDtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHByZXZQYXRoLmxlbmd0aCA9PT0gbmV4dFBhdGgubGVuZ3RoKSB7XG4gICAgICAgICAgICAvLyBpZiBtb3ZlIGJvdHRvbSArIG1vdmUgdG8gaXRlbSB3aXRoIGNoaWxkcmVuIC0tPiBtYWtlIGl0IGEgZmlyc3QgY2hpbGQgaW5zdGVhZCBvZiBzd2FwXG4gICAgICAgICAgICBpZiAobmV4dFBhdGhbbnBMYXN0SW5kZXhdID4gcHJldlBhdGhbbnBMYXN0SW5kZXhdKSB7XG4gICAgICAgICAgICAgICAgdmFyIHRhcmdldCA9IHRoaXMuZ2V0SXRlbUJ5UGF0aChuZXh0UGF0aCk7XG4gICAgICAgICAgICAgICAgaWYgKG5ld0RlcH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biAgICAgICAgICAgIGNoaWxkcmVuUHJvcDogY2hpbGRyZW5Qcm9wLFxuICAgICAgICAgICAgZGlzYWJsZUNvbGxhcHNlOiBkaXNhYmxlQ29sbGFwc2UsXG4gICAgICAgICAgICBkaXNhYmxlRHJhZzogZGlzYWJsZURyYWcsXG4gICAgICAgICAgICByZW5kZXJJdGVtOiByZW5kZXJJdGVtLFxuICAgICAgICAgICAgcmVuZGVyQ29sbGFwc2VJY29uOiByZW5kZXJDb2xsYXBzZUljb24sXG4gICAgICAgICAgICBoYW5kbGVyOiBoYW5kbGVyLFxuICAgICAgICAgICAgY2hlY2tJZkNvbGxhcHNlZDogdGhpcy5jaGVja0lmQ29sbGFwc2VkLFxuICAgICAgICAgICAgb25EcmFnU3RhcnQ6IHRoaXMub25EcmFnU3RhcnQsXG4gICAgICAgICAgICBvbk1vdXNlRW50ZXI6IHRoaXMub25Nb3VzZUVudGVyLFxuICAgICAgICAgICAgb25Ub2dnbGVDb2xsYXBzZTogdGhpcy5vblRvZ2dsZUNvbGxhcHNlLFxuICAgICAgICB9O1xuICAgIH07XG4gICAgLy8g4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCT4oCTXG4gICAgLy8gUmVuZGVyIG1ldGhvZHNcbiAgICAvLyDigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJPigJNcbiAgICBOZXN0YWJsZS5wcm90b3R5cGUucmVuZGVyRHJhZ0xheWVyID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgX2EgPSB0aGlzLnByb3BzLCBncm91cCA9IF9hLmdyb3VwLCBpZFByb3AgPSBfYS5pZFByb3A7XG4gICAg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HNlZDogZmFsc2UsXG4gICAgICAgIGNvbmZpcm1DaGFuZ2U6IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHRydWU7IH0sXG4gICAgICAgIGRpc2FibGVDb2xsYXBzZTogZmFsc2UsXG4gICAgICAgIGRpc2FibGVEcmFnOiBmYWxzZSxcbiAgICAgICAgZ3JvdXA6IE1hdGgucmFuZG9tKCkudG9TdHJpbmcoMzYpLnNsaWNlKDIpLFxuICAgICAgICBpZFByb3A6ICdpZCcsXG4gICAgICAgIGl0ZW1zOiBbXSxcbiAgICAgICAgbWF4RGVwdGg6IDEwLFxuICAgICAgICBvbkNoYW5nZTogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICBvbkNvbGxhcHNlQ2hhbmdlOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uRHJhZ0VuZDogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICBvbkRyYWdTdGFydDogZnVuY3Rpb24gKCkgeyB9LFxuICAgICAgICByZW5kZXJJdGVtOiBmdW5jdGlvbiAoX2EpIHtcbiAgICAgICAgICAgIHZhciBpdGVtID0gX2EuaXRlbTtcbiAgICAgICAgICAgIHJldHVybiBTdHJpbmcoaXRlbSk7XG4gICAgICAgIH0sXG4gICAgICAgIHRocmVzaG9sZDogMzAsXG4gICAgfTtcbiAgICByZXR1cm4gTmVzdGFibGU7XG59KHJlYWN0XzEuQ29tcG9uZW50KSk7XG5leHBvcnRzLmRlZmF1bHQgPSBOZXN0YWJsZTtcbiJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///./src/Nestable/Nestable.tsx\n"); +eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar react_1 = __importStar(__webpack_require__(/*! react */ \"./node_modules/react/index.js\"));\nvar react_addons_shallow_compare_1 = __importDefault(__webpack_require__(/*! react-addons-shallow-compare */ \"./node_modules/react-addons-shallow-compare/index.js\"));\nvar react_addons_update_1 = __importDefault(__webpack_require__(/*! react-addons-update */ \"./node_modules/react-addons-update/index.js\"));\nvar classnames_1 = __importDefault(__webpack_require__(/*! classnames */ \"./node_modules/classnames/index.js\"));\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nvar NestableItem_1 = __importDefault(__webpack_require__(/*! ./NestableItem */ \"./src/Nestable/NestableItem.tsx\"));\nvar Nestable = /** @class */ (function (_super) {\n __extends(Nestable, _super);\n function Nestable(props) {\n var _this = _super.call(this, props) || this;\n _this.el = null;\n _this.elCopyStyles = null;\n _this.mouse = {\n last: { x: 0 },\n shift: { x: 0 },\n };\n // ––––––––––––––––––––––––––––––––––––\n // Public Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.collapse = function (itemIds) {\n var _a = _this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var items = _this.state.items;\n if (itemIds === 'NONE') {\n _this.setState({\n collapsedItems: collapsed\n ? (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n : [],\n });\n }\n else if (itemIds === 'ALL') {\n _this.setState({\n collapsedItems: collapsed\n ? []\n : (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp }),\n });\n }\n else if ((0, utils_1.isArray)(itemIds)) {\n _this.setState({\n collapsedItems: (0, utils_1.getAllNonEmptyNodesIds)(items, { idProp: idProp, childrenProp: childrenProp })\n .filter(function (id) { return (itemIds.indexOf(id) > -1) !== collapsed; }),\n });\n }\n };\n // ––––––––––––––––––––––––––––––––––––\n // Methods\n // ––––––––––––––––––––––––––––––––––––\n _this.startTrackMouse = function () {\n document.addEventListener('mousemove', _this.onMouseMove);\n document.addEventListener('mouseup', _this.onDragEnd);\n document.addEventListener('keydown', _this.onKeyDown);\n };\n _this.stopTrackMouse = function () {\n document.removeEventListener('mousemove', _this.onMouseMove);\n document.removeEventListener('mouseup', _this.onDragEnd);\n document.removeEventListener('keydown', _this.onKeyDown);\n _this.elCopyStyles = null;\n };\n _this.getItemDepth = function (item) {\n var childrenProp = _this.props.childrenProp;\n var level = 1;\n if (item[childrenProp].length > 0) {\n var childrenDepths = item[childrenProp].map(_this.getItemDepth);\n level += Math.max.apply(Math, childrenDepths);\n }\n return level;\n };\n _this.checkIfCollapsed = function (item) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n return !!((collapsedItems.indexOf(item[idProp]) > -1) !== collapsed);\n };\n // ––––––––––––––––––––––––––––––––––––\n // Click handlers or event handlers\n // ––––––––––––––––––––––––––––––––––––\n _this.onDragStart = function (e, item) {\n var onDragStart = _this.props.onDragStart;\n e.preventDefault();\n e.stopPropagation();\n if (!(e.target instanceof Element))\n return;\n _this.el = (0, utils_1.closest)(e.target, '.nestable-item');\n _this.startTrackMouse();\n _this.onMouseMove(e);\n onDragStart({ dragItem: item });\n _this.setState({\n dragItem: item,\n itemsOld: _this.state.items,\n });\n };\n _this.onDragEnd = function (e, isCancel) {\n var onDragEnd = _this.props.onDragEnd;\n e === null || e === void 0 ? void 0 : e.preventDefault();\n _this.stopTrackMouse();\n _this.el = null;\n onDragEnd();\n isCancel\n ? _this.dragRevert()\n : _this.dragApply();\n };\n _this.onMouseMove = function (e) {\n var _a = _this.props, group = _a.group, threshold = _a.threshold;\n var dragItem = _this.state.dragItem;\n var clientX = e.clientX, clientY = e.clientY;\n var transformProps = (0, utils_1.getTransformProps)(clientX, clientY);\n var elCopy = document.querySelector(\".nestable-\".concat(group, \" .nestable-drag-layer > .nestable-list\"));\n if (!_this.elCopyStyles) {\n var offset = (0, utils_1.getOffsetRect)(_this.el);\n var scroll_1 = (0, utils_1.getTotalScroll)(_this.el);\n _this.elCopyStyles = __assign({ marginTop: offset.top - clientY - scroll_1.top, marginLeft: offset.left - clientX - scroll_1.left }, transformProps);\n }\n else {\n _this.elCopyStyles = __assign(__assign({}, _this.elCopyStyles), transformProps);\n Object.keys(transformProps).forEach(function (key) {\n elCopy.style[key] = transformProps[key];\n });\n var diffX = clientX - _this.mouse.last.x;\n if ((diffX >= 0 && _this.mouse.shift.x >= 0) ||\n (diffX <= 0 && _this.mouse.shift.x <= 0)) {\n _this.mouse.shift.x += diffX;\n }\n else {\n _this.mouse.shift.x = 0;\n }\n _this.mouse.last.x = clientX;\n if (Math.abs(_this.mouse.shift.x) > threshold) {\n if (_this.mouse.shift.x > 0) {\n _this.tryIncreaseDepth(dragItem);\n }\n else {\n _this.tryDecreaseDepth(dragItem);\n }\n _this.mouse.shift.x = 0;\n }\n }\n };\n _this.onMouseEnter = function (e, item) {\n e.preventDefault();\n e.stopPropagation();\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = _this.state.dragItem;\n if (dragItem[idProp] === item[idProp])\n return;\n var pathFrom = _this.getPathById(dragItem[idProp]);\n var pathTo = _this.getPathById(item[idProp]);\n // if collapsed by default\n // and move out the only child\n // remove parent node from list of open nodes\n var collapseProps = {};\n if (collapsed && pathFrom.length > 1) {\n var parent_1 = _this.getItemByPath(pathFrom.slice(0, -1));\n if (parent_1[childrenProp].length === 1) {\n collapseProps = _this.onToggleCollapse(parent_1, true);\n }\n }\n _this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n };\n _this.onToggleCollapse = function (item, isGetter) {\n var _a = _this.props, collapsed = _a.collapsed, idProp = _a.idProp;\n var collapsedItems = _this.state.collapsedItems;\n var isCollapsed = _this.checkIfCollapsed(item);\n var newState = {\n collapsedItems: (isCollapsed !== collapsed)\n ? collapsedItems.filter(function (id) { return id !== item[idProp]; })\n : collapsedItems.concat(item[idProp]),\n };\n if (isGetter) {\n return newState;\n }\n else {\n _this.setState(newState);\n _this.onCollapseChange(newState.collapsedItems);\n }\n };\n _this.onCollapseChange = function (ids) {\n var _a = _this.props, collapsed = _a.collapsed, onCollapseChange = _a.onCollapseChange;\n onCollapseChange(collapsed ? { openIds: ids } : { closedIds: ids });\n };\n _this.onKeyDown = function (e) {\n if (e.which === 27) {\n // ESC\n _this.onDragEnd(null, true);\n }\n };\n _this.state = {\n items: [],\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n collapsedItems: [],\n };\n return _this;\n }\n Nestable.prototype.componentDidMount = function () {\n var _a = this.props, items = _a.items, childrenProp = _a.childrenProp;\n // make sure every item has property 'children'\n items = (0, utils_1.listWithChildren)(items, childrenProp);\n this.setState({ items: items });\n };\n Nestable.prototype.componentDidUpdate = function (prevProps) {\n var _this = this;\n var _a = this, _b = _a.props, itemsNew = _b.items, childrenProp = _b.childrenProp, state = _a.state;\n var isPropsChanged = (0, react_addons_shallow_compare_1.default)(__assign(__assign({}, this), { props: prevProps, state: state }), this.props, state);\n if (isPropsChanged) {\n this.stopTrackMouse();\n this.setState(function (prevState) {\n var newState = __assign(__assign({}, prevState), { items: (0, utils_1.listWithChildren)(itemsNew, childrenProp), dragItem: null, isDirty: false });\n if (prevProps.collapsed !== _this.props.collapsed) {\n newState.collapsedItems = [];\n _this.onCollapseChange(newState.collapsedItems);\n }\n return newState;\n });\n }\n };\n Nestable.prototype.componentWillUnmount = function () {\n this.stopTrackMouse();\n };\n Nestable.prototype.moveItem = function (_a, extraProps) {\n var dragItem = _a.dragItem, pathFrom = _a.pathFrom, pathTo = _a.pathTo;\n if (extraProps === void 0) { extraProps = {}; }\n var _b = this.props, childrenProp = _b.childrenProp, confirmChange = _b.confirmChange;\n var dragItemSize = this.getItemDepth(dragItem);\n var items = this.state.items;\n // the remove action might affect the next position,\n // so update next coordinates accordingly\n var realPathTo = this.getRealNextPath(pathFrom, pathTo, dragItemSize);\n if (realPathTo.length === 0)\n return;\n // user can validate every movement\n var destinationPath = realPathTo.length > pathTo.length\n ? pathTo\n : pathTo.slice(0, -1);\n var destinationParent = this.getItemByPath(destinationPath);\n var removePath = this.getSplicePath(pathFrom, {\n numToRemove: 1,\n childrenProp: childrenProp,\n });\n var insertPath = this.getSplicePath(realPathTo, {\n numToRemove: 0,\n itemsToInsert: [dragItem],\n childrenProp: childrenProp,\n });\n items = (0, react_addons_update_1.default)(items, removePath);\n items = (0, react_addons_update_1.default)(items, insertPath);\n if (!confirmChange({ dragItem: dragItem, destinationParent: destinationParent, items: items }))\n return;\n this.setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { items: items, isDirty: true }), extraProps)); });\n if (extraProps.collapsedItems !== this.state.collapsedItems) {\n this.onCollapseChange(extraProps.collapsedItems);\n }\n };\n Nestable.prototype.tryIncreaseDepth = function (dragItem) {\n var _a = this.props, maxDepth = _a.maxDepth, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n var newDepth = pathFrom.length + this.getItemDepth(dragItem);\n // has previous sibling and isn't at max depth\n if (itemIndex > 0 && newDepth <= maxDepth) {\n var prevSibling = this.getItemByPath(pathFrom.slice(0, -1).concat(itemIndex - 1));\n // previous sibling is not collapsed\n if (!prevSibling[childrenProp].length || !this.checkIfCollapsed(prevSibling)) {\n var pathTo = pathFrom\n .slice(0, -1)\n .concat(itemIndex - 1)\n .concat(prevSibling[childrenProp].length);\n // if collapsed by default\n // and was no children here\n // open this node\n var collapseProps = {};\n if (collapsed && !prevSibling[childrenProp].length) {\n collapseProps = this.onToggleCollapse(prevSibling, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.tryDecreaseDepth = function (dragItem) {\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp, collapsed = _a.collapsed;\n var pathFrom = this.getPathById(dragItem[idProp]);\n var itemIndex = pathFrom[pathFrom.length - 1];\n // has parent\n if (pathFrom.length > 1) {\n var parent_2 = this.getItemByPath(pathFrom.slice(0, -1));\n // is last (by order) item in array\n if (itemIndex + 1 === parent_2[childrenProp].length) {\n var pathTo = pathFrom.slice(0, -1);\n pathTo[pathTo.length - 1] += 1;\n // if collapsed by default\n // and is last (by count) item in array\n // remove this node from list of open nodes\n var collapseProps = {};\n if (collapsed && parent_2[childrenProp].length === 1) {\n collapseProps = this.onToggleCollapse(parent_2, true);\n }\n this.moveItem({ dragItem: dragItem, pathFrom: pathFrom, pathTo: pathTo }, collapseProps);\n }\n }\n };\n Nestable.prototype.dragApply = function () {\n var _a = this.props, onChange = _a.onChange, idProp = _a.idProp;\n var _b = this.state, items = _b.items, isDirty = _b.isDirty, dragItem = _b.dragItem;\n this.setState({\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n if (onChange && isDirty) {\n var targetPath = this.getPathById(dragItem[idProp], items);\n onChange({ items: items, dragItem: dragItem, targetPath: targetPath });\n }\n };\n Nestable.prototype.dragRevert = function () {\n var itemsOld = this.state.itemsOld;\n this.setState({\n items: itemsOld,\n itemsOld: null,\n dragItem: null,\n isDirty: false,\n });\n };\n // ––––––––––––––––––––––––––––––––––––\n // Getter methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.getPathById = function (id, items) {\n var _this = this;\n if (items === void 0) { items = this.state.items; }\n var _a = this.props, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var path = [];\n items.every(function (item, i) {\n if (item[idProp] === id) {\n path.push(i);\n }\n else if (item[childrenProp]) {\n var childrenPath = _this.getPathById(id, item[childrenProp]);\n if (childrenPath.length) {\n path = path.concat(i).concat(childrenPath);\n }\n }\n return path.length === 0;\n });\n return path;\n };\n Nestable.prototype.getItemByPath = function (path, items) {\n if (items === void 0) { items = this.state.items; }\n var childrenProp = this.props.childrenProp;\n var item = null;\n path.forEach(function (index) {\n var list = item ? item[childrenProp] : items;\n item = list[index];\n });\n return item;\n };\n Nestable.prototype.getSplicePath = function (path, options) {\n if (options === void 0) { options = {}; }\n var splicePath = {};\n var numToRemove = options.numToRemove || 0;\n var itemsToInsert = options.itemsToInsert || [];\n var lastIndex = path.length - 1;\n var currentPath = splicePath;\n path.forEach(function (index, i) {\n var _a;\n if (i === lastIndex) {\n currentPath.$splice = [__spreadArray([index, numToRemove], itemsToInsert, true)];\n }\n else {\n var nextPath = {};\n currentPath[index] = (_a = {}, _a[options.childrenProp] = nextPath, _a);\n currentPath = nextPath;\n }\n });\n return splicePath;\n };\n Nestable.prototype.getRealNextPath = function (prevPath, nextPath, dragItemSize) {\n var _a = this.props, childrenProp = _a.childrenProp, maxDepth = _a.maxDepth;\n var ppLastIndex = prevPath.length - 1;\n var npLastIndex = nextPath.length - 1;\n var newDepth = nextPath.length + dragItemSize - 1;\n if (prevPath.length < nextPath.length) {\n // move into depth\n var wasShifted_1 = false;\n // if new depth exceeds max, try to put after item instead of into item\n if (newDepth > maxDepth && nextPath.length) {\n return this.getRealNextPath(prevPath, nextPath.slice(0, -1), dragItemSize);\n }\n return nextPath.map(function (nextIndex, i) {\n if (wasShifted_1) {\n return i === npLastIndex\n ? nextIndex + 1\n : nextIndex;\n }\n if (typeof prevPath[i] !== 'number') {\n return nextIndex;\n }\n if (nextPath[i] > prevPath[i] && i === ppLastIndex) {\n wasShifted_1 = true;\n return nextIndex - 1;\n }\n return nextIndex;\n });\n }\n else if (prevPath.length === nextPath.length) {\n // if move bottom + move to item with children --> make it a first child instead of swap\n if (nextPath[npLastIndex] > prevPath[npLastIndex]) {\n var target = this.getItemByPath(nextPath);\n if (newDepth < maxDepth &&\n target[childrenProp] &&\n target[childrenProp].length &&\n !this.checkIfCollapsed(target)) {\n return nextPath\n .slice(0, -1)\n .concat(nextPath[npLastIndex] - 1)\n .concat(0);\n }\n }\n }\n return nextPath;\n };\n Nestable.prototype.getItemOptions = function () {\n var _a = this.props, renderItem = _a.renderItem, renderCollapseIcon = _a.renderCollapseIcon, handler = _a.handler, disableCollapse = _a.disableCollapse, disableDrag = _a.disableDrag, idProp = _a.idProp, childrenProp = _a.childrenProp;\n var dragItem = this.state.dragItem;\n return {\n dragItem: dragItem,\n idProp: idProp,\n childrenProp: childrenProp,\n disableCollapse: disableCollapse,\n disableDrag: disableDrag,\n renderItem: renderItem,\n renderCollapseIcon: renderCollapseIcon,\n handler: handler,\n checkIfCollapsed: this.checkIfCollapsed,\n onDragStart: this.onDragStart,\n onMouseEnter: this.onMouseEnter,\n onToggleCollapse: this.onToggleCollapse,\n };\n };\n // ––––––––––––––––––––––––––––––––––––\n // Render methods\n // ––––––––––––––––––––––––––––––––––––\n Nestable.prototype.renderDragLayer = function () {\n var _a = this.props, group = _a.group, idProp = _a.idProp;\n var dragItem = this.state.dragItem;\n var el = document.querySelector(\".nestable-\".concat(group, \" .nestable-item-\").concat(dragItem[idProp]));\n var listStyles = {};\n if (el) {\n listStyles.width = el.clientWidth;\n }\n if (this.elCopyStyles) {\n listStyles = __assign(__assign({}, listStyles), this.elCopyStyles);\n }\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: \"nestable-drag-layer\" },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\", style: listStyles },\n react_1.default.createElement(NestableItem_1.default, { item: dragItem, options: options, isCopy: true }))));\n };\n Nestable.prototype.render = function () {\n var _a = this.props, group = _a.group, className = _a.className, idProp = _a.idProp;\n var _b = this.state, items = _b.items, dragItem = _b.dragItem;\n var options = this.getItemOptions();\n return (react_1.default.createElement(\"div\", { className: (0, classnames_1.default)(className, 'nestable', \"nestable-\".concat(group), { 'is-drag-active': dragItem }) },\n react_1.default.createElement(\"ol\", { className: \"nestable-list\" }, items.map(function (item, i) {\n return (react_1.default.createElement(NestableItem_1.default, { key: item[idProp], index: i, item: item, options: options }));\n })),\n dragItem && this.renderDragLayer()));\n };\n Nestable.defaultProps = {\n childrenProp: 'children',\n collapsed: false,\n confirmChange: function () { return true; },\n disableCollapse: false,\n disableDrag: false,\n group: Math.random().toString(36).slice(2),\n idProp: 'id',\n items: [],\n maxDepth: 10,\n onChange: function () { },\n onCollapseChange: function () { },\n onDragEnd: function () { },\n onDragStart: function () { },\n renderItem: function (_a) {\n var item = _a.item;\n return String(item);\n },\n threshold: 30,\n };\n return Nestable;\n}(react_1.Component));\nexports[\"default\"] = Nestable;\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvTmVzdGFibGUvTmVzdGFibGUudHN4IiwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtB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3RoaXMubW91c2Uuc2hpZnQueCA8PSAwKSkge1xuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ICs9IGRpZmZYO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXMubW91c2Uuc2hpZnQueCA9IDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIF90aGlzLm1vdXNlLmxhc3QueCA9IGNsaWVudFg7XG4gICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKF90aGlzLm1vdXNlLnNoaWZ0LngpID4gdGhyZXNob2xkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpcy5tb3VzZS5zaGlmdC54ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMudHJ5SW5jcmVhc2VEZXB0aChkcmFnSXRlbSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy50cnlEZWNyZWFzZURlcHRoKGRyYWdJdGVtKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBfdGhpcy5tb3VzZS5zaGlmdC54ID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIF90aGlzLm9uTW91c2VFbnRlciA9IGZ1bmN0aW9uIChlLCBpdGVtKSB7XG4gICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMucHJvcHMsIGNvbGxhcHNlZCA9IF9hLmNvbGxhcHNlZCwgaWRQcm9wID0gX2EuaWRQcm9wLCBjaGlsZHJlblByb3AgPSBfYS5jaGlsZHJlblByb3A7XG4gICAgICAgICAg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ICAgICAgICB9O1xuICAgICAgICBfdGhpcy5vblRvZ2dsZUNvbGxhcHNlID0gZnVuY3Rpb24gKGl0ZW0sIGlzR2V0dGVyKSB7XG4gICAgICAgICAgICB2YXIgX2EgPSBfdGhpcy5wcm9wcywgY29sbGFwc2VkID0gX2EuY29sbGFwc2VkLCBpZFByb3AgPSBfYS5pZFByb3A7XG4gICAgICAgICAgICB2YXIgY29sbGFwc2VkSXRlbXMgPSBfdGhpcy5zdGF0ZS5jb2xsYXBzZWRJdGVtcztcbiAgICAgICAgICAgIHZhciBpc0NvbGxhcHNlZCA9IF90aGlzLmNoZWNrSWZDb2xsYXBzZWQoaXRlbSk7XG4gICAgICAgICAgICB2YXIgbmV3U3RhdGUgPSB7XG4gICAgICAgICAgICAgICAgY29sbGFwc2VkSXRlbXM6IChpc0NvbGxhcHNlZCAhPT0gY29sbGFwc2VkKVxuICAgICAgICAgICAgICAgICAgICA/IGNvbGxhcHNlZEl0ZW1zLmZpbHRlcihmdW5jdGlvbiAoaWQpIHsgcmV0dXJuIGlkICE9PSBpdGVtW2lkUHJvcF07IH0pXG4gICAgICAgICAgICAgICAgICAgIDogY29sbGFwc2VkSXRlbXMuY29uY2F0KGl0ZW1baWRQcm9wXSksXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKGlzR2V0dGVyKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ld1N0YXRlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgX3RoaXMuc2V0U3RhdGUobmV3U3RhdGUpO1xuICAgICAgICAgICAgICAgIF90aGlzLm9uQ29sbGFwc2VDaGFuZ2UobmV3U3RhdGUuY29sbGFwc2VkSXRlbXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBfdGhpcy5vbkNvbGxhcHNlQ2hhbmdlID0gZnVuY3Rpb24gKGlkcykge1xuICAgICAgICAgICAgdmFyIF9hID0gX3RoaXMuc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gICBpZiAoaXRlbUluZGV4ID4gMCAmJiBuZXdEZXB0aCA8PSBtYXhEZXB0aCkge1xuICAgICAgICAgICAgdmFyIHByZXZTaWJsaW5nID0gdGhpcy5nZXRJdGVtQnlQYXRoKHBhdGhGcm9tLnNsaWNlKDAsIC0xKS5jb25jYXQoaXRlbUluZGV4IC0gMSkpO1xuICAgICAgICAgICAgLy8gcHJldmlvdXMgc2libGluZyBpcyBub3QgY29sbGFwc2VkXG4gICAgICAgICAgICBpZiAoIXByZXZTaWJsaW5nW2NoaWxkcmVuUHJvcF0ubGVuZ3RoIHx8ICF0aGlzLmNoZWNrSWZDb2xsYXBzZWQocHJldlNpYmxpbmcpKSB7XG4gICAgICAgICAgICAgICAgdmFyIHBhdGhUbyA9IHBhdGhGcm9tXG4gICAgICAgICAgICAgICAgICAgIC5zbGljZSgwLCAtMSlcbiAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChpdGVtSW5kZXggLSAxKVxuICAgICAgICAgICAgICAgICAgICAuY29uY2F0KHByZXZTaWJsaW5nW2NoaWxkcmVuUHJvcF0ubGVuZ3RoKTtcbiAgICAgICAgICAgICAgICAvLyBpZiBjb2xsYXBzZWQgYnkgZGVmYXVsdFxuICAgICAgICAgICAgICAgIC8vIGFuZCB3YXMgbm8gY2hpbGRyZW4gaGVyZVxuICAgICAgICAgICAgICAgIC8vIG9wZW4gdGhpcyBub2RlXG4gICAgICAgICAgICAgICAgdmFyIGNvbGxhcHNlUHJvcHMgPSB7fTtcbiAgICAgICAgICAgICAgICBpZiAoY29sbGFwc2VkICYmICFwcmV2U2libGluZ1tjaGlsZHJlblByb3BdLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICBjb2xsYXBzZVByb3BzID0gdGhpcy5vblRvZ2dsZUNvbGxhcHNlKHByZXZTaWJsaW5nLCB0cnVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5tb3ZlSXRlbSh7IGRyYWdJdGVtOiBkcmF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VtjaGlsZHJlblByb3BdIDogaXRlbXM7XG4gICAgICAgICAgICBpdGVtID0gbGlzdFtpbmRleF07XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gaXRlbTtcbiAgICB9O1xuICAgIE5lc3RhYmxlLnByb3RvdHlwZS5nZXRTcGxpY2VQYXRoID0gZnVuY3Rpb24gKHBhdGgsIG9wdGlvbnMpIHtcbiAgICAgICAgaWYgKG9wdGlvbnMgPT09IHZvaWQgMCkgeyBvcHRpb25zID0ge307IH1cbiAgICAgICAgdmFyIHNwbGljZVBhdGggPSB7fTtcbiAgICAgICAgdmFyIG51bVRvUmVtb3ZlID0gb3B0aW9ucy5udW1Ub1JlbW92ZSB8fCAwO1xuICAgICAgICB2YXIgaXRlbXNUb0luc2VydCA9IG9wdGlvbnMuaXRlbXNUb0luc2VydCB8fCBbXTtcbiAgICAgICAgdmFyIGxhc3RJbmRleCA9IHBhdGgubGVuZ3RoIC0gMTtcbiAgICAgICAgdmFyIGN1cnJlbnRQYXRoID0gc3BsaWNlUGF0aDtcbiAgICAgICAgcGF0aC5mb3JFYWNoKGZ1bmN0aW9uIChpbmRleCwgaSkge1xuICAgICAgICAgICAgdmFyIF9hO1xuICAgICAgICAgICAgaWYgKGkgPT09IGxhc3RJbmRleCkge1xuICAgICAgICAgICAgICAgIGN1cnJlbnRQYXRoLiRzcGxpY2UgPSBbX19zcHJlYWRBcnJheShbaW5kZXgsIG51bVRvUmVtb3ZlXSwgaXRlbXNUb0luc2VydCwgdHJ1ZSldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgdmFyIG5leHRQYXRoID0ge307XG4gICAgICAgICAgICAgICAgY3VycmVudFBhdGhbaW5kZXhdID0gKF9hID0ge30sIF9hW29wdGlvbnMuY2hpbGRyZW5Qcm9wXSA9IG5leHRQYXRoLCBfYSk7XG4gICAgICAgICAgICAgICAgY3VycmVudFBhdGggPSBuZXh0UGF0aDtcbiAgICAgIC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YgKHdhc1NoaWZ0ZWRfMSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaSA9PT0gbnBMYXN0SW5kZXhcbiAgICAgICAgICAgICAgICAgICAgICAgID8gbmV4dEluZGV4ICsgMVxuICAgICAgICAgICAgICAgICAgICAgICAgOiBuZXh0SW5kZXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgcHJldlBhdGhbaV0gIT09ICdudW1iZXInKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0SW5kZXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChuZXh0UGF0aFtpXSA+IHByZXZQYXRoW2ldICYmIGkgPT09IHBwTGFzdEluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgIHdhc1NoaWZ0ZWRfMSA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0SW5kZXggLSAxO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gbmV4dEluZGV4O1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAocHJldlBhdGgubGVuZ3RoID09PSBuZXh0UGF0aC5sZW5ndGgpIHtcbiAgICAgICAgICAgIC8vIGlmIG1vdmUgYm90dG9tICsgbW92ZSB0byBpdGVtIHdpdGggY2hpbGRyZW4gLS0+IG1ha2UgaXQgYSBmaXJzdCBjaGlsZCBpbnN0ZWFkIG9mIHN3YXBcbiAgICAgICAgICAgIGlmIChuZXh0UGF0aFtucExhc3RJbmRleF0gPiBwcmV2UGF0aFtucExhc3RJbmRleF0pIHtcbiAgICAgICAgICAgICAgICB2YXIgdGFyZ2V0ID0gdGhpcy5nZXRJdGVtQnlQYXRoKG5leHRQYXRoKTtcbiAgICAgICAgICAgICAgICBpZiAobmV3RGVwdGggPCBtYXhEZXB0aCAmJlxuICAgICAgICAgICAgICAgICAgICB0YXJnZXRbY2hpbGRyZW5Qcm9wXSAmJlxuICAgICAgICAgICAgICAgICAgICB0YXJnZXRbY2hpbGRyZW5Qcm9wXS5sZW5ndGggJiZcbiAgICAgICAgICAgICAgICAgICAgIXRoaXMuY2hlY2tJZkNvbGxhcHNlZCh0YXJnZXQpKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXh0UGF0aFxuICAgICAgICAgICAgICAgICAgICAgICAgLnNsaWNlKDAsIC0xKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmNvbmNhdChuZXh0UGF0aFtucExhc3RJbmRleF0gLSAxKVxuICAgICAgICAgICAgICAgICAgICAgICAgLmNvbmNhdCgwKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIG5leHRQYXRoO1xuICAgIH07XG4gICAgTmVzdGFibGUucHJvdG90eXBlLmdldEl0ZW1PcHRpb25zID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgX2EgPSB0aGlzLnByb3BzLCByZW5kZXJJdGVtID0gX2EucmVuZGVySXRlbSwgcmVuZGVyQ29sbGFwc2VJY29uID0gX2EucmVuZGVyQ29sbGFwc2VJY29uLCBoYW5kbGVyID0gX2EuaGFuZGxlciwgZGlzYWJsZUNvbGxhcHNlID0gX2EuZGlzYWJsZUNvbGxhcHNlLCBkaXNhYmxlRHJhZyA9IF9hLmRpc2FibGVEcmFnLCBpZFByb3AgPSBfYS5pZFByb3AsIGNoaWxkcmVuUHJvcCA9IF9hLmNoaWxkcmVuUHJvcDtcbiAgICAgICAgdmFyIGRyYWdJdGVtID0gdGhpcy5zdGF0ZS5kcmFnSXRlbTtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIGRyYWdJdGVtOiBkcmFnSXRlbSxcbiAgICAgICAgICAgIGlkUHJvcDogaWRQcm9wLFxuICAgICAgICAgICAgY2hpbGRyZW5Qcm9wOiBjaGlsZHJlblByb3AsXG4gICA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YW5nZTogZnVuY3Rpb24gKCkgeyByZXR1cm4gdHJ1ZTsgfSxcbiAgICAgICAgZGlzYWJsZUNvbGxhcHNlOiBmYWxzZSxcbiAgICAgICAgZGlzYWJsZURyYWc6IGZhbHNlLFxuICAgICAgICBncm91cDogTWF0aC5yYW5kb20oKS50b1N0cmluZygzNikuc2xpY2UoMiksXG4gICAgICAgIGlkUHJvcDogJ2lkJyxcbiAgICAgICAgaXRlbXM6IFtdLFxuICAgICAgICBtYXhEZXB0aDogMTAsXG4gICAgICAgIG9uQ2hhbmdlOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uQ29sbGFwc2VDaGFuZ2U6IGZ1bmN0aW9uICgpIHsgfSxcbiAgICAgICAgb25EcmFnRW5kOiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIG9uRHJhZ1N0YXJ0OiBmdW5jdGlvbiAoKSB7IH0sXG4gICAgICAgIHJlbmRlckl0ZW06IGZ1bmN0aW9uIChfYSkge1xuICAgICAgICAgICAgdmFyIGl0ZW0gPSBfYS5pdGVtO1xuICAgICAgICAgICAgcmV0dXJuIFN0cmluZyhpdGVtKTtcbiAgICAgICAgfSxcbiAgICAgICAgdGhyZXNob2xkOiAzMCxcbiAgICB9O1xuICAgIHJldHVybiBOZXN0YWJsZTtcbn0ocmVhY3RfMS5Db21wb25lbnQpKTtcbmV4cG9ydHMuZGVmYXVsdCA9IE5lc3RhYmxlO1xuIl0sIm5hbWVzIjpbXSwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///./src/Nestable/Nestable.tsx\n"); /***/ }), @@ -459,7 +459,7 @@ module.exports = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGlu /******/ /******/ /* webpack/runtime/getFullHash */ /******/ (() => { -/******/ __webpack_require__.h = () => ("ad0b346140837f3ebe5e") +/******/ __webpack_require__.h = () => ("eed37ffcec21b8e07583") /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */