wix-style-react
Version:
88 lines (75 loc) • 2.94 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _dragAndDropDriverFactory = require("../utils/DragAndDrop/dragAndDropDriverFactory");
var _constants = require("../DragAndDrop/Draggable/constants");
var _constants2 = require("./constants");
var nestableListFactory = function nestableListFactory(_ref) {
var element = _ref.element;
var dragAndDropDriver = (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
element: element.querySelector("[data-hook=\"".concat(_constants2.dataHooks.provider, "\"]"))
});
return {
/** checks if exists */
exists: function exists() {
return !!element;
},
/** reorder nestable list items by id */
reorder: function reorder(_ref2, offset) {
var removedId = _ref2.removedId,
addedId = _ref2.addedId;
dragAndDropDriver.beginDrag({
id: removedId
});
dragAndDropDriver.dragOver({
id: addedId,
offset: offset
});
dragAndDropDriver.endDrag();
},
/** reorder nestable list items by data-hook */
reorderByDataHook: function reorderByDataHook(_ref3) {
var from = _ref3.from,
to = _ref3.to;
dragAndDropDriver.beginDrag({
dataHook: from
});
dragAndDropDriver.dragOver({
dataHook: to
});
dragAndDropDriver.endDrag();
},
/** change nestable list item depth */
changeItemDepth: function changeItemDepth(_ref4) {
var dataHook = _ref4.dataHook,
depthLevel = _ref4.depthLevel,
_ref4$threshold = _ref4.threshold,
threshold = _ref4$threshold === void 0 ? 30 : _ref4$threshold;
return (0, _dragAndDropDriverFactory.changeItemDepth)({
dragAndDropDriver: dragAndDropDriver,
depthLevel: depthLevel,
threshold: threshold,
dataHook: dataHook
});
},
/** get nestable list item position */
getItemPosition: function getItemPosition(_ref5) {
var dataHook = _ref5.dataHook;
var draggableItems = (0, _toConsumableArray2["default"])(element.querySelectorAll("[".concat(_constants.dataAttributes.draggableTarget, "]")));
return draggableItems.findIndex(function (item) {
return item.querySelectorAll("[".concat(_constants.dataAttributes.draggableSource, "]"))[0].getAttribute('data-hook') === dataHook;
});
},
/** get nestable list item depth */
getItemDepth: function getItemDepth(_ref6) {
var dataHook = _ref6.dataHook;
return parseInt(element.querySelector("[data-hook=".concat(dataHook, "]")).getAttribute(_constants.dataAttributes.depth));
}
};
};
var _default = nestableListFactory;
exports["default"] = _default;