Socket
Socket
Sign inDemoInstall

nested-sort

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.0 to 5.1.1

4

dist/main.d.ts

@@ -58,4 +58,4 @@ import DataEngine from './data-engine';

targetedNodeIsPlaceholder(): boolean;
getTargetedNodeDepth(): number;
nestingThresholdReached(): boolean;
getNodeDepth(el: HTMLElement): number;
nestingThresholdReached(el: HTMLElement, isPlaceHolderCheck?: boolean): boolean;
analysePlaceHolderSituation(): PlaceholderMaintenanceActions;

@@ -62,0 +62,0 @@ animatePlaceholderList(): void;

@@ -8,3 +8,2 @@ 'use strict';

}
function _defineProperties(target, props) {

@@ -16,13 +15,15 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {

@@ -38,18 +39,13 @@ Object.defineProperty(obj, key, {

}
return obj;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {

@@ -63,14 +59,24 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -83,18 +89,11 @@ var DataEngine = /*#__PURE__*/function () {

var data = _ref.data,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, DataEngine);
_defineProperty(this, "data", void 0);
_defineProperty(this, "sortedData", void 0);
_defineProperty(this, "sortedDataDomArray", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
this.data = data;

@@ -107,3 +106,2 @@ this.sortedData = [];

}
_createClass(DataEngine, [{

@@ -128,3 +126,2 @@ key: "maybeTransformData",

}
return prop;

@@ -141,5 +138,3 @@ }

var _this = this;
var items = _toConsumableArray(this.data);
var topLevelItems = items.filter(function (a) {

@@ -158,3 +153,2 @@ return _this.isTopLevelItem(a);

}
return groups;

@@ -175,3 +169,3 @@ }, {});

var id = item.id,
text = item.text;
text = item.text;
var el = document.createElement(nodeName);

@@ -206,3 +200,2 @@ el.dataset.id = id;

var _this2 = this;
var parent = item.parent;

@@ -215,3 +208,2 @@ var topParent = this.sortedDataDomArray.find(function (topLevelListItem) {

var directParentList = this.getDirectListParentOfItem(topParent, item);
if (!directParentList) {

@@ -225,3 +217,2 @@ // we need to create the direct parent OL and append it to the direct parent LI

}
directParentList.appendChild(listItem);

@@ -234,6 +225,4 @@ return true;

var _this3 = this;
this.sortedDataDomArray = [];
var processedItems = [];
while (processedItems.length !== this.sortListItems().length) {

@@ -244,8 +233,5 @@ processedItems = this.sortedData.reduce(function (processedItems, item) {

var itemAdded;
if (!item.parent) {
var listItem = _this3.createItemElement(item);
_this3.sortedDataDomArray.push(listItem);
itemAdded = true;

@@ -255,3 +241,2 @@ } else {

}
if (itemAdded) processedItems.push(id);

@@ -261,3 +246,2 @@ return processedItems;

}
return this.sortedDataDomArray;

@@ -269,6 +253,4 @@ }

var _this4 = this;
return Array.from((list === null || list === void 0 ? void 0 : list.querySelectorAll('li')) || []).map(function (li) {
var _ref2;
var parentListItem = li.parentNode;

@@ -292,3 +274,2 @@ var parent = parentListItem.dataset.id;

}]);
return DataEngine;

@@ -300,62 +281,38 @@ }();

var _ref$actions = _ref.actions,
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, NestedSort);
_defineProperty(this, "actions", void 0);
_defineProperty(this, "classNames", void 0);
_defineProperty(this, "cursor", void 0);
_defineProperty(this, "data", void 0);
_defineProperty(this, "dataEngine", void 0);
_defineProperty(this, "distances", void 0);
_defineProperty(this, "draggedNode", void 0);
_defineProperty(this, "initialised", void 0);
_defineProperty(this, "listClassNames", void 0);
_defineProperty(this, "listEventListeners", void 0);
_defineProperty(this, "listInterface", void 0);
_defineProperty(this, "listItemClassNames", void 0);
_defineProperty(this, "mainListClassName", void 0);
_defineProperty(this, "nestingLevels", void 0);
_defineProperty(this, "placeholderList", void 0);
_defineProperty(this, "placeholderInUse", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
_defineProperty(this, "sortableList", void 0);
_defineProperty(this, "targetedNode", void 0);
_defineProperty(this, "targetNode", void 0);
_defineProperty(this, "wrapper", void 0);
this.renderListItem = renderListItem;

@@ -392,3 +349,2 @@ var element = typeof el === 'string' ? document.querySelector(el) : el;

this.nestingLevels = isNaN(intNestingLevels) ? -1 : intNestingLevels; // values less than 0 mean infinite levels of nesting
this.listInterface = this.getListInterface();

@@ -399,3 +355,2 @@ this.maybeInitDataDom();

}
_createClass(NestedSort, [{

@@ -441,3 +396,2 @@ key: "getListInterface",

var _this$wrapper;
if (this.sortableList instanceof this.listInterface) return this.sortableList;

@@ -451,12 +405,8 @@ this.sortableList = (_this$wrapper = this.wrapper) === null || _this$wrapper === void 0 ? void 0 : _this$wrapper.querySelector(this.getListTagName());

var _list$classList,
_this = this;
_this = this;
var list = this.getSortableList();
if (!list) return;
(_list$classList = list.classList).add.apply(_list$classList, _toConsumableArray(this.listClassNames.concat(this.mainListClassName)));
list.querySelectorAll(this.getListTagName()).forEach(function (l) {
var _l$classList;
(_l$classList = l.classList).add.apply(_l$classList, _toConsumableArray(_this.listClassNames));

@@ -466,3 +416,2 @@ });

var _li$classList;
(_li$classList = li.classList).add.apply(_li$classList, _toConsumableArray(_this.listItemClassNames));

@@ -484,3 +433,2 @@ });

var _this$getSortableList;
var enable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

@@ -495,3 +443,2 @@ (_this$getSortableList = this.getSortableList()) === null || _this$getSortableList === void 0 ? void 0 : _this$getSortableList.querySelectorAll('li').forEach(function (el) {

var _this2 = this;
var remove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

@@ -538,3 +485,6 @@ var list = this.getSortableList();

if (!this.draggedNode || this.draggedNode === el) return false;
return el.nodeName === 'LI' || el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
if (el.nodeName === 'LI') {
return !this.nestingThresholdReached(el);
}
return el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
}

@@ -545,3 +495,2 @@ }, {

var _e$dataTransfer;
this.draggedNode = e.target;

@@ -555,3 +504,2 @@ this.draggedNode.classList.add(this.classNames.dragged);

e.preventDefault(); // prevent default to allow drop
this.updateCoordination(e);

@@ -584,3 +532,2 @@ this.managePlaceholderLists();

this.cleanupPlaceholderLists();
if (typeof this.actions.onDrop === 'function') {

@@ -601,3 +548,2 @@ this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()));

var _this$targetedNode;
if (((_this$targetedNode = this.targetedNode) === null || _this$targetedNode === void 0 ? void 0 : _this$targetedNode.nodeName) === 'LI') return 'before';else if (this.targetedNode instanceof this.listInterface) return 'inside';

@@ -616,3 +562,2 @@ }

var _this$targetedNode2, _this$targetedNode2$p, _this$targetedNode3;
switch (place) {

@@ -622,3 +567,2 @@ case 'before':

break;
case 'inside':

@@ -644,3 +588,2 @@ (_this$targetedNode3 = this.targetedNode) === null || _this$targetedNode3 === void 0 ? void 0 : _this$targetedNode3.appendChild(this.draggedNode);

}
var offset = this.targetedNode.getBoundingClientRect();

@@ -675,3 +618,2 @@ this.targetNode = {

var _this$distances;
if (!((_this$distances = this.distances) !== null && _this$distances !== void 0 && _this$distances.droppingEdge)) return false;

@@ -684,3 +626,2 @@ return this.cursor.Y - this.targetNode.Y < this.distances.droppingEdge;

var _this3 = this;
var actions = this.analysePlaceHolderSituation();

@@ -691,10 +632,6 @@ actions.forEach(function (action) {

_this3.cleanupPlaceholderLists();
_this3.addPlaceholderList();
break;
case 'cleanup':
_this3.cleanupPlaceholderLists();
break;

@@ -710,15 +647,11 @@ }

}, {
key: "getTargetedNodeDepth",
value: function getTargetedNodeDepth() {
key: "getNodeDepth",
value: function getNodeDepth(el) {
var depth = 0;
var el = this.targetedNode;
var list = this.getSortableList();
while (list !== ((_el = el) === null || _el === void 0 ? void 0 : _el.parentElement)) {
var _el, _el2, _el3;
if (((_el2 = el) === null || _el2 === void 0 ? void 0 : _el2.parentElement) instanceof this.listInterface) depth++;
el = (_el3 = el) === null || _el3 === void 0 ? void 0 : _el3.parentElement;
}
return depth;

@@ -728,6 +661,6 @@ }

key: "nestingThresholdReached",
value: function nestingThresholdReached() {
value: function nestingThresholdReached(el) {
var isPlaceHolderCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.nestingLevels < 0) return false;
if (this.nestingLevels === 0) return true;
return this.getTargetedNodeDepth() >= this.nestingLevels;
return isPlaceHolderCheck ? this.getNodeDepth(el) >= this.nestingLevels : this.getNodeDepth(el) > this.nestingLevels;
}

@@ -740,5 +673,3 @@ }, {

}
var actions = [];
if (!this.cursorIsIndentedEnough() || this.mouseIsTooCloseToTop()) {

@@ -748,6 +679,5 @@ if (!this.targetedNodeIsPlaceholder()) {

}
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached()) {
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached(this.targetedNode, true)) {
actions.push('add');
}
return actions;

@@ -759,3 +689,2 @@ }

var _this$draggedNode;
this.placeholderInUse.style.minHeight = '0';

@@ -769,3 +698,2 @@ this.placeholderInUse.style.transition = 'min-height ease .2s';

var _this$targetedNode4;
this.getPlaceholderList();

@@ -799,4 +727,3 @@ (_this$targetedNode4 = this.targetedNode) === null || _this$targetedNode4 === void 0 ? void 0 : _this$targetedNode4.appendChild(this.placeholderInUse);

var _this$getSortableList2,
_this4 = this;
_this4 = this;
var tag = this.getListTagName();

@@ -818,5 +745,3 @@ var listsArray = ((_this$getSortableList2 = this.getSortableList()) === null || _this$getSortableList2 === void 0 ? void 0 : _this$getSortableList2.querySelectorAll(tag)) || [];

var _this$placeholderList;
this.placeholderList = document.createElement(this.getListTagName());
(_this$placeholderList = this.placeholderList.classList).add.apply(_this$placeholderList, [this.classNames.placeholder].concat(_toConsumableArray(this.listClassNames)));

@@ -831,3 +756,2 @@ }

}]);
return NestedSort;

@@ -834,0 +758,0 @@ }();

@@ -6,3 +6,2 @@ function _classCallCheck(instance, Constructor) {

}
function _defineProperties(target, props) {

@@ -14,13 +13,15 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {

@@ -36,18 +37,13 @@ Object.defineProperty(obj, key, {

}
return obj;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {

@@ -61,14 +57,24 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -81,18 +87,11 @@ var DataEngine = /*#__PURE__*/function () {

var data = _ref.data,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, DataEngine);
_defineProperty(this, "data", void 0);
_defineProperty(this, "sortedData", void 0);
_defineProperty(this, "sortedDataDomArray", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
this.data = data;

@@ -105,3 +104,2 @@ this.sortedData = [];

}
_createClass(DataEngine, [{

@@ -126,3 +124,2 @@ key: "maybeTransformData",

}
return prop;

@@ -139,5 +136,3 @@ }

var _this = this;
var items = _toConsumableArray(this.data);
var topLevelItems = items.filter(function (a) {

@@ -156,3 +151,2 @@ return _this.isTopLevelItem(a);

}
return groups;

@@ -173,3 +167,3 @@ }, {});

var id = item.id,
text = item.text;
text = item.text;
var el = document.createElement(nodeName);

@@ -204,3 +198,2 @@ el.dataset.id = id;

var _this2 = this;
var parent = item.parent;

@@ -213,3 +206,2 @@ var topParent = this.sortedDataDomArray.find(function (topLevelListItem) {

var directParentList = this.getDirectListParentOfItem(topParent, item);
if (!directParentList) {

@@ -223,3 +215,2 @@ // we need to create the direct parent OL and append it to the direct parent LI

}
directParentList.appendChild(listItem);

@@ -232,6 +223,4 @@ return true;

var _this3 = this;
this.sortedDataDomArray = [];
var processedItems = [];
while (processedItems.length !== this.sortListItems().length) {

@@ -242,8 +231,5 @@ processedItems = this.sortedData.reduce(function (processedItems, item) {

var itemAdded;
if (!item.parent) {
var listItem = _this3.createItemElement(item);
_this3.sortedDataDomArray.push(listItem);
itemAdded = true;

@@ -253,3 +239,2 @@ } else {

}
if (itemAdded) processedItems.push(id);

@@ -259,3 +244,2 @@ return processedItems;

}
return this.sortedDataDomArray;

@@ -267,6 +251,4 @@ }

var _this4 = this;
return Array.from((list === null || list === void 0 ? void 0 : list.querySelectorAll('li')) || []).map(function (li) {
var _ref2;
var parentListItem = li.parentNode;

@@ -290,3 +272,2 @@ var parent = parentListItem.dataset.id;

}]);
return DataEngine;

@@ -298,62 +279,38 @@ }();

var _ref$actions = _ref.actions,
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, NestedSort);
_defineProperty(this, "actions", void 0);
_defineProperty(this, "classNames", void 0);
_defineProperty(this, "cursor", void 0);
_defineProperty(this, "data", void 0);
_defineProperty(this, "dataEngine", void 0);
_defineProperty(this, "distances", void 0);
_defineProperty(this, "draggedNode", void 0);
_defineProperty(this, "initialised", void 0);
_defineProperty(this, "listClassNames", void 0);
_defineProperty(this, "listEventListeners", void 0);
_defineProperty(this, "listInterface", void 0);
_defineProperty(this, "listItemClassNames", void 0);
_defineProperty(this, "mainListClassName", void 0);
_defineProperty(this, "nestingLevels", void 0);
_defineProperty(this, "placeholderList", void 0);
_defineProperty(this, "placeholderInUse", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
_defineProperty(this, "sortableList", void 0);
_defineProperty(this, "targetedNode", void 0);
_defineProperty(this, "targetNode", void 0);
_defineProperty(this, "wrapper", void 0);
this.renderListItem = renderListItem;

@@ -390,3 +347,2 @@ var element = typeof el === 'string' ? document.querySelector(el) : el;

this.nestingLevels = isNaN(intNestingLevels) ? -1 : intNestingLevels; // values less than 0 mean infinite levels of nesting
this.listInterface = this.getListInterface();

@@ -397,3 +353,2 @@ this.maybeInitDataDom();

}
_createClass(NestedSort, [{

@@ -439,3 +394,2 @@ key: "getListInterface",

var _this$wrapper;
if (this.sortableList instanceof this.listInterface) return this.sortableList;

@@ -449,12 +403,8 @@ this.sortableList = (_this$wrapper = this.wrapper) === null || _this$wrapper === void 0 ? void 0 : _this$wrapper.querySelector(this.getListTagName());

var _list$classList,
_this = this;
_this = this;
var list = this.getSortableList();
if (!list) return;
(_list$classList = list.classList).add.apply(_list$classList, _toConsumableArray(this.listClassNames.concat(this.mainListClassName)));
list.querySelectorAll(this.getListTagName()).forEach(function (l) {
var _l$classList;
(_l$classList = l.classList).add.apply(_l$classList, _toConsumableArray(_this.listClassNames));

@@ -464,3 +414,2 @@ });

var _li$classList;
(_li$classList = li.classList).add.apply(_li$classList, _toConsumableArray(_this.listItemClassNames));

@@ -482,3 +431,2 @@ });

var _this$getSortableList;
var enable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

@@ -493,3 +441,2 @@ (_this$getSortableList = this.getSortableList()) === null || _this$getSortableList === void 0 ? void 0 : _this$getSortableList.querySelectorAll('li').forEach(function (el) {

var _this2 = this;
var remove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

@@ -536,3 +483,6 @@ var list = this.getSortableList();

if (!this.draggedNode || this.draggedNode === el) return false;
return el.nodeName === 'LI' || el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
if (el.nodeName === 'LI') {
return !this.nestingThresholdReached(el);
}
return el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
}

@@ -543,3 +493,2 @@ }, {

var _e$dataTransfer;
this.draggedNode = e.target;

@@ -553,3 +502,2 @@ this.draggedNode.classList.add(this.classNames.dragged);

e.preventDefault(); // prevent default to allow drop
this.updateCoordination(e);

@@ -582,3 +530,2 @@ this.managePlaceholderLists();

this.cleanupPlaceholderLists();
if (typeof this.actions.onDrop === 'function') {

@@ -599,3 +546,2 @@ this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()));

var _this$targetedNode;
if (((_this$targetedNode = this.targetedNode) === null || _this$targetedNode === void 0 ? void 0 : _this$targetedNode.nodeName) === 'LI') return 'before';else if (this.targetedNode instanceof this.listInterface) return 'inside';

@@ -614,3 +560,2 @@ }

var _this$targetedNode2, _this$targetedNode2$p, _this$targetedNode3;
switch (place) {

@@ -620,3 +565,2 @@ case 'before':

break;
case 'inside':

@@ -642,3 +586,2 @@ (_this$targetedNode3 = this.targetedNode) === null || _this$targetedNode3 === void 0 ? void 0 : _this$targetedNode3.appendChild(this.draggedNode);

}
var offset = this.targetedNode.getBoundingClientRect();

@@ -673,3 +616,2 @@ this.targetNode = {

var _this$distances;
if (!((_this$distances = this.distances) !== null && _this$distances !== void 0 && _this$distances.droppingEdge)) return false;

@@ -682,3 +624,2 @@ return this.cursor.Y - this.targetNode.Y < this.distances.droppingEdge;

var _this3 = this;
var actions = this.analysePlaceHolderSituation();

@@ -689,10 +630,6 @@ actions.forEach(function (action) {

_this3.cleanupPlaceholderLists();
_this3.addPlaceholderList();
break;
case 'cleanup':
_this3.cleanupPlaceholderLists();
break;

@@ -708,15 +645,11 @@ }

}, {
key: "getTargetedNodeDepth",
value: function getTargetedNodeDepth() {
key: "getNodeDepth",
value: function getNodeDepth(el) {
var depth = 0;
var el = this.targetedNode;
var list = this.getSortableList();
while (list !== ((_el = el) === null || _el === void 0 ? void 0 : _el.parentElement)) {
var _el, _el2, _el3;
if (((_el2 = el) === null || _el2 === void 0 ? void 0 : _el2.parentElement) instanceof this.listInterface) depth++;
el = (_el3 = el) === null || _el3 === void 0 ? void 0 : _el3.parentElement;
}
return depth;

@@ -726,6 +659,6 @@ }

key: "nestingThresholdReached",
value: function nestingThresholdReached() {
value: function nestingThresholdReached(el) {
var isPlaceHolderCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.nestingLevels < 0) return false;
if (this.nestingLevels === 0) return true;
return this.getTargetedNodeDepth() >= this.nestingLevels;
return isPlaceHolderCheck ? this.getNodeDepth(el) >= this.nestingLevels : this.getNodeDepth(el) > this.nestingLevels;
}

@@ -738,5 +671,3 @@ }, {

}
var actions = [];
if (!this.cursorIsIndentedEnough() || this.mouseIsTooCloseToTop()) {

@@ -746,6 +677,5 @@ if (!this.targetedNodeIsPlaceholder()) {

}
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached()) {
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached(this.targetedNode, true)) {
actions.push('add');
}
return actions;

@@ -757,3 +687,2 @@ }

var _this$draggedNode;
this.placeholderInUse.style.minHeight = '0';

@@ -767,3 +696,2 @@ this.placeholderInUse.style.transition = 'min-height ease .2s';

var _this$targetedNode4;
this.getPlaceholderList();

@@ -797,4 +725,3 @@ (_this$targetedNode4 = this.targetedNode) === null || _this$targetedNode4 === void 0 ? void 0 : _this$targetedNode4.appendChild(this.placeholderInUse);

var _this$getSortableList2,
_this4 = this;
_this4 = this;
var tag = this.getListTagName();

@@ -816,5 +743,3 @@ var listsArray = ((_this$getSortableList2 = this.getSortableList()) === null || _this$getSortableList2 === void 0 ? void 0 : _this$getSortableList2.querySelectorAll(tag)) || [];

var _this$placeholderList;
this.placeholderList = document.createElement(this.getListTagName());
(_this$placeholderList = this.placeholderList.classList).add.apply(_this$placeholderList, [this.classNames.placeholder].concat(_toConsumableArray(this.listClassNames)));

@@ -829,3 +754,2 @@ }

}]);
return NestedSort;

@@ -832,0 +756,0 @@ }();

@@ -12,3 +12,2 @@ (function (global, factory) {

}
function _defineProperties(target, props) {

@@ -20,13 +19,15 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {

@@ -42,18 +43,13 @@ Object.defineProperty(obj, key, {

}
return obj;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {

@@ -67,14 +63,24 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -87,18 +93,11 @@ var DataEngine = /*#__PURE__*/function () {

var data = _ref.data,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, DataEngine);
_defineProperty(this, "data", void 0);
_defineProperty(this, "sortedData", void 0);
_defineProperty(this, "sortedDataDomArray", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
this.data = data;

@@ -111,3 +110,2 @@ this.sortedData = [];

}
_createClass(DataEngine, [{

@@ -132,3 +130,2 @@ key: "maybeTransformData",

}
return prop;

@@ -145,5 +142,3 @@ }

var _this = this;
var items = _toConsumableArray(this.data);
var topLevelItems = items.filter(function (a) {

@@ -162,3 +157,2 @@ return _this.isTopLevelItem(a);

}
return groups;

@@ -179,3 +173,3 @@ }, {});

var id = item.id,
text = item.text;
text = item.text;
var el = document.createElement(nodeName);

@@ -210,3 +204,2 @@ el.dataset.id = id;

var _this2 = this;
var parent = item.parent;

@@ -219,3 +212,2 @@ var topParent = this.sortedDataDomArray.find(function (topLevelListItem) {

var directParentList = this.getDirectListParentOfItem(topParent, item);
if (!directParentList) {

@@ -229,3 +221,2 @@ // we need to create the direct parent OL and append it to the direct parent LI

}
directParentList.appendChild(listItem);

@@ -238,6 +229,4 @@ return true;

var _this3 = this;
this.sortedDataDomArray = [];
var processedItems = [];
while (processedItems.length !== this.sortListItems().length) {

@@ -248,8 +237,5 @@ processedItems = this.sortedData.reduce(function (processedItems, item) {

var itemAdded;
if (!item.parent) {
var listItem = _this3.createItemElement(item);
_this3.sortedDataDomArray.push(listItem);
itemAdded = true;

@@ -259,3 +245,2 @@ } else {

}
if (itemAdded) processedItems.push(id);

@@ -265,3 +250,2 @@ return processedItems;

}
return this.sortedDataDomArray;

@@ -273,6 +257,4 @@ }

var _this4 = this;
return Array.from((list === null || list === void 0 ? void 0 : list.querySelectorAll('li')) || []).map(function (li) {
var _ref2;
var parentListItem = li.parentNode;

@@ -296,3 +278,2 @@ var parent = parentListItem.dataset.id;

}]);
return DataEngine;

@@ -304,62 +285,38 @@ }();

var _ref$actions = _ref.actions,
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
actions = _ref$actions === void 0 ? {} : _ref$actions,
data = _ref.data,
_ref$droppingEdge = _ref.droppingEdge,
droppingEdge = _ref$droppingEdge === void 0 ? 15 : _ref$droppingEdge,
el = _ref.el,
_ref$init = _ref.init,
init = _ref$init === void 0 ? true : _ref$init,
listClassNames = _ref.listClassNames,
listItemClassNames = _ref.listItemClassNames,
nestingLevels = _ref.nestingLevels,
_ref$propertyMap = _ref.propertyMap,
propertyMap = _ref$propertyMap === void 0 ? {} : _ref$propertyMap,
renderListItem = _ref.renderListItem;
_classCallCheck(this, NestedSort);
_defineProperty(this, "actions", void 0);
_defineProperty(this, "classNames", void 0);
_defineProperty(this, "cursor", void 0);
_defineProperty(this, "data", void 0);
_defineProperty(this, "dataEngine", void 0);
_defineProperty(this, "distances", void 0);
_defineProperty(this, "draggedNode", void 0);
_defineProperty(this, "initialised", void 0);
_defineProperty(this, "listClassNames", void 0);
_defineProperty(this, "listEventListeners", void 0);
_defineProperty(this, "listInterface", void 0);
_defineProperty(this, "listItemClassNames", void 0);
_defineProperty(this, "mainListClassName", void 0);
_defineProperty(this, "nestingLevels", void 0);
_defineProperty(this, "placeholderList", void 0);
_defineProperty(this, "placeholderInUse", void 0);
_defineProperty(this, "propertyMap", void 0);
_defineProperty(this, "renderListItem", void 0);
_defineProperty(this, "sortableList", void 0);
_defineProperty(this, "targetedNode", void 0);
_defineProperty(this, "targetNode", void 0);
_defineProperty(this, "wrapper", void 0);
this.renderListItem = renderListItem;

@@ -396,3 +353,2 @@ var element = typeof el === 'string' ? document.querySelector(el) : el;

this.nestingLevels = isNaN(intNestingLevels) ? -1 : intNestingLevels; // values less than 0 mean infinite levels of nesting
this.listInterface = this.getListInterface();

@@ -403,3 +359,2 @@ this.maybeInitDataDom();

}
_createClass(NestedSort, [{

@@ -445,3 +400,2 @@ key: "getListInterface",

var _this$wrapper;
if (this.sortableList instanceof this.listInterface) return this.sortableList;

@@ -455,12 +409,8 @@ this.sortableList = (_this$wrapper = this.wrapper) === null || _this$wrapper === void 0 ? void 0 : _this$wrapper.querySelector(this.getListTagName());

var _list$classList,
_this = this;
_this = this;
var list = this.getSortableList();
if (!list) return;
(_list$classList = list.classList).add.apply(_list$classList, _toConsumableArray(this.listClassNames.concat(this.mainListClassName)));
list.querySelectorAll(this.getListTagName()).forEach(function (l) {
var _l$classList;
(_l$classList = l.classList).add.apply(_l$classList, _toConsumableArray(_this.listClassNames));

@@ -470,3 +420,2 @@ });

var _li$classList;
(_li$classList = li.classList).add.apply(_li$classList, _toConsumableArray(_this.listItemClassNames));

@@ -488,3 +437,2 @@ });

var _this$getSortableList;
var enable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

@@ -499,3 +447,2 @@ (_this$getSortableList = this.getSortableList()) === null || _this$getSortableList === void 0 ? void 0 : _this$getSortableList.querySelectorAll('li').forEach(function (el) {

var _this2 = this;
var remove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

@@ -542,3 +489,6 @@ var list = this.getSortableList();

if (!this.draggedNode || this.draggedNode === el) return false;
return el.nodeName === 'LI' || el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
if (el.nodeName === 'LI') {
return !this.nestingThresholdReached(el);
}
return el instanceof this.listInterface && el.classList.contains(this.classNames.placeholder);
}

@@ -549,3 +499,2 @@ }, {

var _e$dataTransfer;
this.draggedNode = e.target;

@@ -559,3 +508,2 @@ this.draggedNode.classList.add(this.classNames.dragged);

e.preventDefault(); // prevent default to allow drop
this.updateCoordination(e);

@@ -588,3 +536,2 @@ this.managePlaceholderLists();

this.cleanupPlaceholderLists();
if (typeof this.actions.onDrop === 'function') {

@@ -605,3 +552,2 @@ this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()));

var _this$targetedNode;
if (((_this$targetedNode = this.targetedNode) === null || _this$targetedNode === void 0 ? void 0 : _this$targetedNode.nodeName) === 'LI') return 'before';else if (this.targetedNode instanceof this.listInterface) return 'inside';

@@ -620,3 +566,2 @@ }

var _this$targetedNode2, _this$targetedNode2$p, _this$targetedNode3;
switch (place) {

@@ -626,3 +571,2 @@ case 'before':

break;
case 'inside':

@@ -648,3 +592,2 @@ (_this$targetedNode3 = this.targetedNode) === null || _this$targetedNode3 === void 0 ? void 0 : _this$targetedNode3.appendChild(this.draggedNode);

}
var offset = this.targetedNode.getBoundingClientRect();

@@ -679,3 +622,2 @@ this.targetNode = {

var _this$distances;
if (!((_this$distances = this.distances) !== null && _this$distances !== void 0 && _this$distances.droppingEdge)) return false;

@@ -688,3 +630,2 @@ return this.cursor.Y - this.targetNode.Y < this.distances.droppingEdge;

var _this3 = this;
var actions = this.analysePlaceHolderSituation();

@@ -695,10 +636,6 @@ actions.forEach(function (action) {

_this3.cleanupPlaceholderLists();
_this3.addPlaceholderList();
break;
case 'cleanup':
_this3.cleanupPlaceholderLists();
break;

@@ -714,15 +651,11 @@ }

}, {
key: "getTargetedNodeDepth",
value: function getTargetedNodeDepth() {
key: "getNodeDepth",
value: function getNodeDepth(el) {
var depth = 0;
var el = this.targetedNode;
var list = this.getSortableList();
while (list !== ((_el = el) === null || _el === void 0 ? void 0 : _el.parentElement)) {
var _el, _el2, _el3;
if (((_el2 = el) === null || _el2 === void 0 ? void 0 : _el2.parentElement) instanceof this.listInterface) depth++;
el = (_el3 = el) === null || _el3 === void 0 ? void 0 : _el3.parentElement;
}
return depth;

@@ -732,6 +665,6 @@ }

key: "nestingThresholdReached",
value: function nestingThresholdReached() {
value: function nestingThresholdReached(el) {
var isPlaceHolderCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.nestingLevels < 0) return false;
if (this.nestingLevels === 0) return true;
return this.getTargetedNodeDepth() >= this.nestingLevels;
return isPlaceHolderCheck ? this.getNodeDepth(el) >= this.nestingLevels : this.getNodeDepth(el) > this.nestingLevels;
}

@@ -744,5 +677,3 @@ }, {

}
var actions = [];
if (!this.cursorIsIndentedEnough() || this.mouseIsTooCloseToTop()) {

@@ -752,6 +683,5 @@ if (!this.targetedNodeIsPlaceholder()) {

}
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached()) {
} else if (this.targetedNode !== this.draggedNode && this.targetedNode.nodeName === 'LI' && !this.targetedNode.querySelectorAll(this.getListTagName()).length && !this.nestingThresholdReached(this.targetedNode, true)) {
actions.push('add');
}
return actions;

@@ -763,3 +693,2 @@ }

var _this$draggedNode;
this.placeholderInUse.style.minHeight = '0';

@@ -773,3 +702,2 @@ this.placeholderInUse.style.transition = 'min-height ease .2s';

var _this$targetedNode4;
this.getPlaceholderList();

@@ -803,4 +731,3 @@ (_this$targetedNode4 = this.targetedNode) === null || _this$targetedNode4 === void 0 ? void 0 : _this$targetedNode4.appendChild(this.placeholderInUse);

var _this$getSortableList2,
_this4 = this;
_this4 = this;
var tag = this.getListTagName();

@@ -822,5 +749,3 @@ var listsArray = ((_this$getSortableList2 = this.getSortableList()) === null || _this$getSortableList2 === void 0 ? void 0 : _this$getSortableList2.querySelectorAll(tag)) || [];

var _this$placeholderList;
this.placeholderList = document.createElement(this.getListTagName());
(_this$placeholderList = this.placeholderList.classList).add.apply(_this$placeholderList, [this.classNames.placeholder].concat(_toConsumableArray(this.listClassNames)));

@@ -835,3 +760,2 @@ }

}]);
return NestedSort;

@@ -838,0 +762,0 @@ }();

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).NestedSort=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function i(e,i,s){return i&&t(e.prototype,i),s&&t(e,s),e}function s(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function a(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return r(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,s=new Array(t);i<t;i++)s[i]=e[i];return s}var n=function(){function t(i){var a=i.data,r=i.propertyMap,n=void 0===r?{}:r,o=i.renderListItem;e(this,t),s(this,"data",void 0),s(this,"sortedData",void 0),s(this,"sortedDataDomArray",void 0),s(this,"propertyMap",void 0),s(this,"renderListItem",void 0),this.data=a,this.sortedData=[],this.sortedDataDomArray=[],this.propertyMap=n,this.renderListItem=o,this.maybeTransformData()}return i(t,[{key:"maybeTransformData",value:function(){if(Object.keys(this.propertyMap).length&&Array.isArray(this.data)){var e=this.getItemPropProxyName.bind(this);this.data=this.data.map((function(t){return new Proxy(t,{get:function(t,i,s){return Reflect.get(t,e(i),s)}})}))}}},{key:"getItemPropProxyName",value:function(e){return Object.prototype.hasOwnProperty.call(this.propertyMap,e)?this.propertyMap[e]:e}},{key:"isTopLevelItem",value:function(e){return!e.parent}},{key:"sortListItems",value:function(){var e=this,t=a(this.data),i=t.filter((function(t){return e.isTopLevelItem(t)})).sort((function(e,t){return e.order&&t.order?e.order-t.order:0})),s=t.filter((function(t){return!e.isTopLevelItem(t)})).reduce((function(e,t){return Object.prototype.hasOwnProperty.call(e,t.parent)?e[t.parent].push(t):e[t.parent]=[t],e}),{});return Object.keys(s).forEach((function(e){s[e].sort((function(e,t){return e.order&&t.order?e.order-t.order:0}))})),this.sortedData=[].concat(a(i),a(Object.values(s).flat())),this.sortedData}},{key:"createItemElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"li",i=e.id,s=e.text,a=document.createElement(t);return a.dataset.id=i,"li"===t&&s&&(a.innerHTML=s),"li"===t&&"function"==typeof this.renderListItem?this.renderListItem(a,e):a}},{key:"elementIsParentOfItem",value:function(e,t){return e.dataset.id==="".concat(t.parent)}},{key:"getParentNodeOfItem",value:function(e,t,i){return e.querySelector("".concat(i,'[data-id="').concat(t.parent,'"]'))}},{key:"elementIsAncestorOfItem",value:function(e,t){return!!this.getParentNodeOfItem(e,t,"li")}},{key:"getDirectListParentOfItem",value:function(e,t){return this.getParentNodeOfItem(e,t,"ol")}},{key:"maybeAppendItemToParentDom",value:function(e){var t=this,i=e.parent,s=this.sortedDataDomArray.find((function(i){return t.elementIsParentOfItem(i,e)||t.elementIsAncestorOfItem(i,e)}));if(!s)return!1;var a=this.createItemElement(e),r=this.getDirectListParentOfItem(s,e);r||(r=this.createItemElement({id:i},"ol"),(this.getParentNodeOfItem(s,e,"li")||s).appendChild(r));return r.appendChild(a),!0}},{key:"getListItemsDom",value:function(){var e=this;this.sortedDataDomArray=[];for(var t=[];t.length!==this.sortListItems().length;)t=this.sortedData.reduce((function(t,i){var s,a=i.id.toString();if(t.includes(a))return t;if(i.parent)s=e.maybeAppendItemToParentDom(i);else{var r=e.createItemElement(i);e.sortedDataDomArray.push(r),s=!0}return s&&t.push(a),t}),t);return this.sortedDataDomArray}},{key:"convertDomToData",value:function(e){var t=this;return Array.from((null==e?void 0:e.querySelectorAll("li"))||[]).map((function(e){var i,a=e.parentNode,r=a.dataset.id,n=Array.from(a.children).findIndex((function(t){return t===e}))+1;return s(i={},t.getItemPropProxyName("id"),e.dataset.id),s(i,t.getItemPropProxyName("parent"),r),s(i,t.getItemPropProxyName("order"),n),i}))}},{key:"render",value:function(){var e=document.createElement("ol");return this.getListItemsDom().forEach((function(t){return e.appendChild(t)})),e}}]),t}();return function(){function t(i){var a=i.actions,r=void 0===a?{}:a,n=i.data,o=i.droppingEdge,d=void 0===o?15:o,l=i.el,h=i.init,c=void 0===h||h,u=i.listClassNames,g=i.listItemClassNames,f=i.nestingLevels,v=i.propertyMap,p=void 0===v?{}:v,m=i.renderListItem;e(this,t),s(this,"actions",void 0),s(this,"classNames",void 0),s(this,"cursor",void 0),s(this,"data",void 0),s(this,"dataEngine",void 0),s(this,"distances",void 0),s(this,"draggedNode",void 0),s(this,"initialised",void 0),s(this,"listClassNames",void 0),s(this,"listEventListeners",void 0),s(this,"listInterface",void 0),s(this,"listItemClassNames",void 0),s(this,"mainListClassName",void 0),s(this,"nestingLevels",void 0),s(this,"placeholderList",void 0),s(this,"placeholderInUse",void 0),s(this,"propertyMap",void 0),s(this,"renderListItem",void 0),s(this,"sortableList",void 0),s(this,"targetedNode",void 0),s(this,"targetNode",void 0),s(this,"wrapper",void 0),this.renderListItem=m;var y="string"==typeof l?document.querySelector(l):l,L=y instanceof HTMLOListElement||y instanceof HTMLUListElement;this.wrapper=L?void 0:y,this.sortableList=L?y:null,this.data=n,this.listClassNames=this.createListClassNamesArray(u),this.mainListClassName=this.listClassNames[0]||"nested-sort",this.listItemClassNames=this.createListClassNamesArray(g),this.propertyMap=p,this.actions={onDrop:r.onDrop},this.initialised=!1,this.distances={droppingEdge:d},this.classNames={dragged:"ns-dragged",placeholder:"ns-placeholder",targeted:"ns-targeted"},this.listEventListeners={dragover:this.onDragOver.bind(this),dragstart:this.onDragStart.bind(this),dragenter:this.onDragEnter.bind(this),dragend:this.onDragEnd.bind(this),drop:this.onDrop.bind(this)};var N=parseInt(f);this.nestingLevels=isNaN(N)?-1:N,this.listInterface=this.getListInterface(),this.maybeInitDataDom(),this.addListAttributes(),c&&this.initDragAndDrop()}return i(t,[{key:"getListInterface",value:function(){return Array.isArray(this.data)&&this.data.length||this.sortableList instanceof HTMLOListElement?HTMLOListElement:HTMLUListElement}},{key:"getDataEngine",value:function(){return this.dataEngine||(this.dataEngine=new n({data:this.data,propertyMap:this.propertyMap,renderListItem:this.renderListItem})),this.dataEngine}},{key:"createListClassNamesArray",value:function(e){return e?Array.isArray(e)?e:e.split(" "):[]}},{key:"maybeInitDataDom",value:function(){if(Array.isArray(this.data)&&this.data.length&&this.wrapper){var e=this.getDataEngine().render();this.wrapper.innerHTML="",this.wrapper.appendChild(e)}}},{key:"getListTagName",value:function(){return this.listInterface===HTMLOListElement?"ol":"ul"}},{key:"getSortableList",value:function(){var e;return this.sortableList instanceof this.listInterface||(this.sortableList=null===(e=this.wrapper)||void 0===e?void 0:e.querySelector(this.getListTagName())),this.sortableList}},{key:"addListAttributes",value:function(){var e,t=this,i=this.getSortableList();i&&((e=i.classList).add.apply(e,a(this.listClassNames.concat(this.mainListClassName))),i.querySelectorAll(this.getListTagName()).forEach((function(e){var i;(i=e.classList).add.apply(i,a(t.listClassNames))})),i.querySelectorAll("li").forEach((function(e){var i;(i=e.classList).add.apply(i,a(t.listItemClassNames))})))}},{key:"toggleMainListLifeCycleClassName",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=this.getSortableList();if(t){var i="".concat(this.mainListClassName,"--enabled");e?t.classList.add(i):t.classList.remove(i)}}},{key:"toggleListItemAttributes",value:function(){var e,t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];null===(e=this.getSortableList())||void 0===e||e.querySelectorAll("li").forEach((function(e){e.setAttribute("draggable",t.toString())}))}},{key:"toggleListEventListeners",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this.getSortableList();i&&Object.keys(this.listEventListeners).forEach((function(s){t?i.removeEventListener(s,e.listEventListeners[s]):i.addEventListener(s,e.listEventListeners[s],!1)}))}},{key:"initDragAndDrop",value:function(){this.initialised||(this.toggleListEventListeners(),this.initPlaceholderList(),this.toggleListItemAttributes(),this.toggleMainListLifeCycleClassName(),this.initialised=!0)}},{key:"init",value:function(){this.initDragAndDrop()}},{key:"destroy",value:function(){this.toggleListEventListeners(!0),this.toggleListItemAttributes(!1),this.toggleMainListLifeCycleClassName(!1),this.initialised=!1}},{key:"removeClassFromEl",value:function(e,t){t&&t.classList.contains(e)&&t.classList.remove(e)}},{key:"canBeTargeted",value:function(e){return!(!this.draggedNode||this.draggedNode===e)&&("LI"===e.nodeName||e instanceof this.listInterface&&e.classList.contains(this.classNames.placeholder))}},{key:"onDragStart",value:function(e){var t;this.draggedNode=e.target,this.draggedNode.classList.add(this.classNames.dragged),null===(t=e.dataTransfer)||void 0===t||t.setData("text","Drag started!")}},{key:"onDragOver",value:function(e){e.preventDefault(),this.updateCoordination(e),this.managePlaceholderLists()}},{key:"onDragEnter",value:function(e){this.canBeTargeted(e.target)&&(this.removeClassFromEl(this.classNames.targeted,this.targetedNode),this.targetedNode=e.target,this.targetedNode.classList.add(this.classNames.targeted))}},{key:"onDragEnd",value:function(e){e.stopPropagation(),this.removeClassFromEl(this.classNames.dragged,this.draggedNode),this.removeClassFromEl(this.classNames.targeted,this.targetedNode),this.cleanupPlaceholderLists(),delete this.draggedNode,delete this.targetedNode}},{key:"onDrop",value:function(e){e.stopPropagation(),this.maybeDrop(),this.cleanupPlaceholderLists(),"function"==typeof this.actions.onDrop&&this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()))}},{key:"updateCoordination",value:function(e){this.calcMouseCoords(e),this.calcMouseToTargetedElDist()}},{key:"getDropLocation",value:function(){if(this.canBeDropped()){var e;if("LI"===(null===(e=this.targetedNode)||void 0===e?void 0:e.nodeName))return"before";if(this.targetedNode instanceof this.listInterface)return"inside"}}},{key:"maybeDrop",value:function(){var e=this.getDropLocation();e&&this.dropTheItem(e)}},{key:"dropTheItem",value:function(e){var t,i,s;switch(e){case"before":null===(t=this.targetedNode)||void 0===t||null===(i=t.parentNode)||void 0===i||i.insertBefore(this.draggedNode,this.targetedNode);break;case"inside":null===(s=this.targetedNode)||void 0===s||s.appendChild(this.draggedNode)}}},{key:"calcMouseCoords",value:function(e){this.cursor={X:e.clientX,Y:e.clientY}}},{key:"calcMouseToTargetedElDist",value:function(){if(this.targetedNode){var e=this.targetedNode.getBoundingClientRect();this.targetNode={X:e.left,Y:e.top};var t=this.targetNode.Y-this.cursor.Y,i=Math.abs(t);this.distances.mouseTo={targetedElTop:t,targetedElTopAbs:i,targetedElBot:i-this.targetedNode.clientHeight}}}},{key:"areNested",value:function(e,t){return!!e&&!!t&&Array.from(null==t?void 0:t.querySelectorAll("li")).some((function(t){return t===e}))}},{key:"cursorIsIndentedEnough",value:function(){return this.cursor.X-this.targetNode.X>50}},{key:"mouseIsTooCloseToTop",value:function(){var e;return!(null===(e=this.distances)||void 0===e||!e.droppingEdge)&&this.cursor.Y-this.targetNode.Y<this.distances.droppingEdge}},{key:"managePlaceholderLists",value:function(){var e=this;this.analysePlaceHolderSituation().forEach((function(t){switch(t){case"add":e.cleanupPlaceholderLists(),e.addPlaceholderList();break;case"cleanup":e.cleanupPlaceholderLists()}}))}},{key:"targetedNodeIsPlaceholder",value:function(){return this.targetedNode instanceof this.listInterface&&this.targetedNode.classList.contains(this.classNames.placeholder)}},{key:"getTargetedNodeDepth",value:function(){for(var e=0,t=this.targetedNode,i=this.getSortableList();i!==(null===(s=t)||void 0===s?void 0:s.parentElement);){var s,a,r;(null===(a=t)||void 0===a?void 0:a.parentElement)instanceof this.listInterface&&e++,t=null===(r=t)||void 0===r?void 0:r.parentElement}return e}},{key:"nestingThresholdReached",value:function(){return!(this.nestingLevels<0)&&(0===this.nestingLevels||this.getTargetedNodeDepth()>=this.nestingLevels)}},{key:"analysePlaceHolderSituation",value:function(){if(!this.targetedNode||this.areNested(this.targetedNode,this.draggedNode))return[];var e=[];return!this.cursorIsIndentedEnough()||this.mouseIsTooCloseToTop()?this.targetedNodeIsPlaceholder()||e.push("cleanup"):this.targetedNode===this.draggedNode||"LI"!==this.targetedNode.nodeName||this.targetedNode.querySelectorAll(this.getListTagName()).length||this.nestingThresholdReached()||e.push("add"),e}},{key:"animatePlaceholderList",value:function(){var e;this.placeholderInUse.style.minHeight="0",this.placeholderInUse.style.transition="min-height ease .2s",this.placeholderInUse.style.minHeight="".concat(null===(e=this.draggedNode)||void 0===e?void 0:e.offsetHeight,"px")}},{key:"addPlaceholderList",value:function(){var e;this.getPlaceholderList(),null===(e=this.targetedNode)||void 0===e||e.appendChild(this.placeholderInUse),this.animatePlaceholderList()}},{key:"targetNodeIsIdentified",value:function(){return!!this.targetedNode}},{key:"targetNodeIsBeingDragged",value:function(){return this.targetNodeIsIdentified()&&this.targetedNode===this.draggedNode}},{key:"targetNodeIsListWithItems",value:function(){return this.targetNodeIsIdentified()&&this.targetedNode instanceof this.listInterface&&!!this.targetedNode.querySelectorAll("li").length}},{key:"canBeDropped",value:function(){return this.targetNodeIsIdentified()&&!this.targetNodeIsBeingDragged()&&!this.targetNodeIsListWithItems()&&!this.areNested(this.targetedNode,this.draggedNode)}},{key:"cleanupPlaceholderLists",value:function(){var e,t=this,i=this.getListTagName(),s=(null===(e=this.getSortableList())||void 0===e?void 0:e.querySelectorAll(i))||[];Array.from(s).forEach((function(e){e.querySelectorAll("li").length?e.classList.contains(t.classNames.placeholder)&&(e.classList.remove(t.classNames.placeholder),e.style.minHeight="auto",e.dataset.id=e.parentNode.dataset.id):e.remove()}))}},{key:"initPlaceholderList",value:function(){var e;this.placeholderList=document.createElement(this.getListTagName()),(e=this.placeholderList.classList).add.apply(e,[this.classNames.placeholder].concat(a(this.listClassNames)))}},{key:"getPlaceholderList",value:function(){return this.placeholderInUse=this.placeholderList.cloneNode(!0),this.placeholderInUse}}]),t}()}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).NestedSort=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,n(s.key),s)}}function i(e,i,s){return i&&t(e.prototype,i),s&&t(e,s),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t,i){return(t=n(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function r(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,s=new Array(t);i<t;i++)s[i]=e[i];return s}function n(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var s=i.call(e,t||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var o=function(){function t(i){var r=i.data,a=i.propertyMap,n=void 0===a?{}:a,o=i.renderListItem;e(this,t),s(this,"data",void 0),s(this,"sortedData",void 0),s(this,"sortedDataDomArray",void 0),s(this,"propertyMap",void 0),s(this,"renderListItem",void 0),this.data=r,this.sortedData=[],this.sortedDataDomArray=[],this.propertyMap=n,this.renderListItem=o,this.maybeTransformData()}return i(t,[{key:"maybeTransformData",value:function(){if(Object.keys(this.propertyMap).length&&Array.isArray(this.data)){var e=this.getItemPropProxyName.bind(this);this.data=this.data.map((function(t){return new Proxy(t,{get:function(t,i,s){return Reflect.get(t,e(i),s)}})}))}}},{key:"getItemPropProxyName",value:function(e){return Object.prototype.hasOwnProperty.call(this.propertyMap,e)?this.propertyMap[e]:e}},{key:"isTopLevelItem",value:function(e){return!e.parent}},{key:"sortListItems",value:function(){var e=this,t=r(this.data),i=t.filter((function(t){return e.isTopLevelItem(t)})).sort((function(e,t){return e.order&&t.order?e.order-t.order:0})),s=t.filter((function(t){return!e.isTopLevelItem(t)})).reduce((function(e,t){return Object.prototype.hasOwnProperty.call(e,t.parent)?e[t.parent].push(t):e[t.parent]=[t],e}),{});return Object.keys(s).forEach((function(e){s[e].sort((function(e,t){return e.order&&t.order?e.order-t.order:0}))})),this.sortedData=[].concat(r(i),r(Object.values(s).flat())),this.sortedData}},{key:"createItemElement",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"li",i=e.id,s=e.text,r=document.createElement(t);return r.dataset.id=i,"li"===t&&s&&(r.innerHTML=s),"li"===t&&"function"==typeof this.renderListItem?this.renderListItem(r,e):r}},{key:"elementIsParentOfItem",value:function(e,t){return e.dataset.id==="".concat(t.parent)}},{key:"getParentNodeOfItem",value:function(e,t,i){return e.querySelector("".concat(i,'[data-id="').concat(t.parent,'"]'))}},{key:"elementIsAncestorOfItem",value:function(e,t){return!!this.getParentNodeOfItem(e,t,"li")}},{key:"getDirectListParentOfItem",value:function(e,t){return this.getParentNodeOfItem(e,t,"ol")}},{key:"maybeAppendItemToParentDom",value:function(e){var t=this,i=e.parent,s=this.sortedDataDomArray.find((function(i){return t.elementIsParentOfItem(i,e)||t.elementIsAncestorOfItem(i,e)}));if(!s)return!1;var r=this.createItemElement(e),a=this.getDirectListParentOfItem(s,e);a||(a=this.createItemElement({id:i},"ol"),(this.getParentNodeOfItem(s,e,"li")||s).appendChild(a));return a.appendChild(r),!0}},{key:"getListItemsDom",value:function(){var e=this;this.sortedDataDomArray=[];for(var t=[];t.length!==this.sortListItems().length;)t=this.sortedData.reduce((function(t,i){var s,r=i.id.toString();if(t.includes(r))return t;if(i.parent)s=e.maybeAppendItemToParentDom(i);else{var a=e.createItemElement(i);e.sortedDataDomArray.push(a),s=!0}return s&&t.push(r),t}),t);return this.sortedDataDomArray}},{key:"convertDomToData",value:function(e){var t=this;return Array.from((null==e?void 0:e.querySelectorAll("li"))||[]).map((function(e){var i,r=e.parentNode,a=r.dataset.id,n=Array.from(r.children).findIndex((function(t){return t===e}))+1;return s(i={},t.getItemPropProxyName("id"),e.dataset.id),s(i,t.getItemPropProxyName("parent"),a),s(i,t.getItemPropProxyName("order"),n),i}))}},{key:"render",value:function(){var e=document.createElement("ol");return this.getListItemsDom().forEach((function(t){return e.appendChild(t)})),e}}]),t}(),d=function(){function t(i){var r=i.actions,a=void 0===r?{}:r,n=i.data,o=i.droppingEdge,d=void 0===o?15:o,l=i.el,h=i.init,c=void 0===h||h,u=i.listClassNames,g=i.listItemClassNames,f=i.nestingLevels,v=i.propertyMap,p=void 0===v?{}:v,m=i.renderListItem;e(this,t),s(this,"actions",void 0),s(this,"classNames",void 0),s(this,"cursor",void 0),s(this,"data",void 0),s(this,"dataEngine",void 0),s(this,"distances",void 0),s(this,"draggedNode",void 0),s(this,"initialised",void 0),s(this,"listClassNames",void 0),s(this,"listEventListeners",void 0),s(this,"listInterface",void 0),s(this,"listItemClassNames",void 0),s(this,"mainListClassName",void 0),s(this,"nestingLevels",void 0),s(this,"placeholderList",void 0),s(this,"placeholderInUse",void 0),s(this,"propertyMap",void 0),s(this,"renderListItem",void 0),s(this,"sortableList",void 0),s(this,"targetedNode",void 0),s(this,"targetNode",void 0),s(this,"wrapper",void 0),this.renderListItem=m;var y="string"==typeof l?document.querySelector(l):l,L=y instanceof HTMLOListElement||y instanceof HTMLUListElement;this.wrapper=L?void 0:y,this.sortableList=L?y:null,this.data=n,this.listClassNames=this.createListClassNamesArray(u),this.mainListClassName=this.listClassNames[0]||"nested-sort",this.listItemClassNames=this.createListClassNamesArray(g),this.propertyMap=p,this.actions={onDrop:a.onDrop},this.initialised=!1,this.distances={droppingEdge:d},this.classNames={dragged:"ns-dragged",placeholder:"ns-placeholder",targeted:"ns-targeted"},this.listEventListeners={dragover:this.onDragOver.bind(this),dragstart:this.onDragStart.bind(this),dragenter:this.onDragEnter.bind(this),dragend:this.onDragEnd.bind(this),drop:this.onDrop.bind(this)};var N=parseInt(f);this.nestingLevels=isNaN(N)?-1:N,this.listInterface=this.getListInterface(),this.maybeInitDataDom(),this.addListAttributes(),c&&this.initDragAndDrop()}return i(t,[{key:"getListInterface",value:function(){return Array.isArray(this.data)&&this.data.length||this.sortableList instanceof HTMLOListElement?HTMLOListElement:HTMLUListElement}},{key:"getDataEngine",value:function(){return this.dataEngine||(this.dataEngine=new o({data:this.data,propertyMap:this.propertyMap,renderListItem:this.renderListItem})),this.dataEngine}},{key:"createListClassNamesArray",value:function(e){return e?Array.isArray(e)?e:e.split(" "):[]}},{key:"maybeInitDataDom",value:function(){if(Array.isArray(this.data)&&this.data.length&&this.wrapper){var e=this.getDataEngine().render();this.wrapper.innerHTML="",this.wrapper.appendChild(e)}}},{key:"getListTagName",value:function(){return this.listInterface===HTMLOListElement?"ol":"ul"}},{key:"getSortableList",value:function(){var e;return this.sortableList instanceof this.listInterface||(this.sortableList=null===(e=this.wrapper)||void 0===e?void 0:e.querySelector(this.getListTagName())),this.sortableList}},{key:"addListAttributes",value:function(){var e,t=this,i=this.getSortableList();i&&((e=i.classList).add.apply(e,r(this.listClassNames.concat(this.mainListClassName))),i.querySelectorAll(this.getListTagName()).forEach((function(e){var i;(i=e.classList).add.apply(i,r(t.listClassNames))})),i.querySelectorAll("li").forEach((function(e){var i;(i=e.classList).add.apply(i,r(t.listItemClassNames))})))}},{key:"toggleMainListLifeCycleClassName",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=this.getSortableList();if(t){var i="".concat(this.mainListClassName,"--enabled");e?t.classList.add(i):t.classList.remove(i)}}},{key:"toggleListItemAttributes",value:function(){var e,t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];null===(e=this.getSortableList())||void 0===e||e.querySelectorAll("li").forEach((function(e){e.setAttribute("draggable",t.toString())}))}},{key:"toggleListEventListeners",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this.getSortableList();i&&Object.keys(this.listEventListeners).forEach((function(s){t?i.removeEventListener(s,e.listEventListeners[s]):i.addEventListener(s,e.listEventListeners[s],!1)}))}},{key:"initDragAndDrop",value:function(){this.initialised||(this.toggleListEventListeners(),this.initPlaceholderList(),this.toggleListItemAttributes(),this.toggleMainListLifeCycleClassName(),this.initialised=!0)}},{key:"init",value:function(){this.initDragAndDrop()}},{key:"destroy",value:function(){this.toggleListEventListeners(!0),this.toggleListItemAttributes(!1),this.toggleMainListLifeCycleClassName(!1),this.initialised=!1}},{key:"removeClassFromEl",value:function(e,t){t&&t.classList.contains(e)&&t.classList.remove(e)}},{key:"canBeTargeted",value:function(e){return!(!this.draggedNode||this.draggedNode===e)&&("LI"===e.nodeName?!this.nestingThresholdReached(e):e instanceof this.listInterface&&e.classList.contains(this.classNames.placeholder))}},{key:"onDragStart",value:function(e){var t;this.draggedNode=e.target,this.draggedNode.classList.add(this.classNames.dragged),null===(t=e.dataTransfer)||void 0===t||t.setData("text","Drag started!")}},{key:"onDragOver",value:function(e){e.preventDefault(),this.updateCoordination(e),this.managePlaceholderLists()}},{key:"onDragEnter",value:function(e){this.canBeTargeted(e.target)&&(this.removeClassFromEl(this.classNames.targeted,this.targetedNode),this.targetedNode=e.target,this.targetedNode.classList.add(this.classNames.targeted))}},{key:"onDragEnd",value:function(e){e.stopPropagation(),this.removeClassFromEl(this.classNames.dragged,this.draggedNode),this.removeClassFromEl(this.classNames.targeted,this.targetedNode),this.cleanupPlaceholderLists(),delete this.draggedNode,delete this.targetedNode}},{key:"onDrop",value:function(e){e.stopPropagation(),this.maybeDrop(),this.cleanupPlaceholderLists(),"function"==typeof this.actions.onDrop&&this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()))}},{key:"updateCoordination",value:function(e){this.calcMouseCoords(e),this.calcMouseToTargetedElDist()}},{key:"getDropLocation",value:function(){if(this.canBeDropped()){var e;if("LI"===(null===(e=this.targetedNode)||void 0===e?void 0:e.nodeName))return"before";if(this.targetedNode instanceof this.listInterface)return"inside"}}},{key:"maybeDrop",value:function(){var e=this.getDropLocation();e&&this.dropTheItem(e)}},{key:"dropTheItem",value:function(e){var t,i,s;switch(e){case"before":null===(t=this.targetedNode)||void 0===t||null===(i=t.parentNode)||void 0===i||i.insertBefore(this.draggedNode,this.targetedNode);break;case"inside":null===(s=this.targetedNode)||void 0===s||s.appendChild(this.draggedNode)}}},{key:"calcMouseCoords",value:function(e){this.cursor={X:e.clientX,Y:e.clientY}}},{key:"calcMouseToTargetedElDist",value:function(){if(this.targetedNode){var e=this.targetedNode.getBoundingClientRect();this.targetNode={X:e.left,Y:e.top};var t=this.targetNode.Y-this.cursor.Y,i=Math.abs(t);this.distances.mouseTo={targetedElTop:t,targetedElTopAbs:i,targetedElBot:i-this.targetedNode.clientHeight}}}},{key:"areNested",value:function(e,t){return!!e&&!!t&&Array.from(null==t?void 0:t.querySelectorAll("li")).some((function(t){return t===e}))}},{key:"cursorIsIndentedEnough",value:function(){return this.cursor.X-this.targetNode.X>50}},{key:"mouseIsTooCloseToTop",value:function(){var e;return!(null===(e=this.distances)||void 0===e||!e.droppingEdge)&&this.cursor.Y-this.targetNode.Y<this.distances.droppingEdge}},{key:"managePlaceholderLists",value:function(){var e=this;this.analysePlaceHolderSituation().forEach((function(t){switch(t){case"add":e.cleanupPlaceholderLists(),e.addPlaceholderList();break;case"cleanup":e.cleanupPlaceholderLists()}}))}},{key:"targetedNodeIsPlaceholder",value:function(){return this.targetedNode instanceof this.listInterface&&this.targetedNode.classList.contains(this.classNames.placeholder)}},{key:"getNodeDepth",value:function(e){for(var t=0,i=this.getSortableList();i!==(null===(s=e)||void 0===s?void 0:s.parentElement);){var s,r,a;(null===(r=e)||void 0===r?void 0:r.parentElement)instanceof this.listInterface&&t++,e=null===(a=e)||void 0===a?void 0:a.parentElement}return t}},{key:"nestingThresholdReached",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!(this.nestingLevels<0)&&(t?this.getNodeDepth(e)>=this.nestingLevels:this.getNodeDepth(e)>this.nestingLevels)}},{key:"analysePlaceHolderSituation",value:function(){if(!this.targetedNode||this.areNested(this.targetedNode,this.draggedNode))return[];var e=[];return!this.cursorIsIndentedEnough()||this.mouseIsTooCloseToTop()?this.targetedNodeIsPlaceholder()||e.push("cleanup"):this.targetedNode===this.draggedNode||"LI"!==this.targetedNode.nodeName||this.targetedNode.querySelectorAll(this.getListTagName()).length||this.nestingThresholdReached(this.targetedNode,!0)||e.push("add"),e}},{key:"animatePlaceholderList",value:function(){var e;this.placeholderInUse.style.minHeight="0",this.placeholderInUse.style.transition="min-height ease .2s",this.placeholderInUse.style.minHeight="".concat(null===(e=this.draggedNode)||void 0===e?void 0:e.offsetHeight,"px")}},{key:"addPlaceholderList",value:function(){var e;this.getPlaceholderList(),null===(e=this.targetedNode)||void 0===e||e.appendChild(this.placeholderInUse),this.animatePlaceholderList()}},{key:"targetNodeIsIdentified",value:function(){return!!this.targetedNode}},{key:"targetNodeIsBeingDragged",value:function(){return this.targetNodeIsIdentified()&&this.targetedNode===this.draggedNode}},{key:"targetNodeIsListWithItems",value:function(){return this.targetNodeIsIdentified()&&this.targetedNode instanceof this.listInterface&&!!this.targetedNode.querySelectorAll("li").length}},{key:"canBeDropped",value:function(){return this.targetNodeIsIdentified()&&!this.targetNodeIsBeingDragged()&&!this.targetNodeIsListWithItems()&&!this.areNested(this.targetedNode,this.draggedNode)}},{key:"cleanupPlaceholderLists",value:function(){var e,t=this,i=this.getListTagName(),s=(null===(e=this.getSortableList())||void 0===e?void 0:e.querySelectorAll(i))||[];Array.from(s).forEach((function(e){e.querySelectorAll("li").length?e.classList.contains(t.classNames.placeholder)&&(e.classList.remove(t.classNames.placeholder),e.style.minHeight="auto",e.dataset.id=e.parentNode.dataset.id):e.remove()}))}},{key:"initPlaceholderList",value:function(){var e;this.placeholderList=document.createElement(this.getListTagName()),(e=this.placeholderList.classList).add.apply(e,[this.classNames.placeholder].concat(r(this.listClassNames)))}},{key:"getPlaceholderList",value:function(){return this.placeholderInUse=this.placeholderList.cloneNode(!0),this.placeholderInUse}}]),t}();return d}));
{
"name": "nested-sort",
"version": "5.1.0",
"version": "5.1.1",
"author": "Hesam Bahrami (hesamurai)",

@@ -17,16 +17,16 @@ "description": "A JavaScript library for sorting a nested list of items via drag and drop.",

"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.16.0",
"@rollup/plugin-babel": "^5.3.0",
"@babel/core": "^7.21.8",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-eslint": "^8.0.1",
"@rollup/plugin-eslint": "^8.0.5",
"@rollup/plugin-node-resolve": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-jest": "^27.3.1",
"concurrently": "^6.4.0",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"babel-jest": "^27.5.1",
"concurrently": "^6.5.1",
"eslint": "^7.32.0",

@@ -36,6 +36,6 @@ "husky": "^4.3.8",

"jsdom": "^16.7.0",
"rollup": "^2.60.0",
"rollup": "^2.79.1",
"rollup-plugin-terser": "^7.0.2",
"serve": "^13.0.2",
"typescript": "^4.4.4"
"serve": "^14.2.0",
"typescript": "^5.0.4"
},

@@ -42,0 +42,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc