wix-style-react
Version:
wix-style-react
64 lines (63 loc) • 2.08 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _dragAndDropDriverFactory = require("../utils/DragAndDrop/dragAndDropDriverFactory");
var _constants = require("../DragAndDrop/Draggable/constants");
var _constants2 = require("./constants");
var nestableListBaseFactory = _ref => {
var {
element
} = _ref;
var dragAndDropDriver = (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
element: element.querySelector("[data-hook=\"".concat(_constants2.dataHooks.provider, "\"]"))
});
return {
/** checks if exists */
exists: () => !!element,
/** reorder nestable list items */
reorder: _ref2 => {
var {
dataHookFrom,
dataHookTo
} = _ref2;
dragAndDropDriver.beginDrag({
dataHook: "".concat(dataHookFrom)
});
dragAndDropDriver.dragOver({
dataHook: "".concat(dataHookTo)
});
dragAndDropDriver.endDrag();
},
/** change nestable list item depth */
changeItemDepth: _ref3 => {
var {
dataHook,
depthLevel,
threshold = 30
} = _ref3;
return (0, _dragAndDropDriverFactory.changeItemDepth)({
dragAndDropDriver,
depthLevel,
threshold,
dataHook: "".concat(dataHook)
});
},
/** get nestable list item position */
getItemPosition: _ref4 => {
var {
dataHook
} = _ref4;
var draggableItems = [...element.querySelectorAll("[".concat(_constants.dataAttributes.draggableTarget, "]"))];
return draggableItems.findIndex(item => item.querySelectorAll("[".concat(_constants.dataAttributes.draggableSource, "]"))[0].getAttribute('data-hook') === "".concat(dataHook));
},
/** get nestable list item depth */
getItemDepth: _ref5 => {
var {
dataHook
} = _ref5;
return parseInt(element.querySelector("[data-hook=".concat(dataHook, "]")).getAttribute(_constants.dataAttributes.depth));
}
};
};
var _default = exports.default = nestableListBaseFactory;
//# sourceMappingURL=NestableListBase.driver.js.map