UNPKG

wix-style-react

Version:
77 lines (68 loc) 2.6 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import { dragAndDropDriverFactory, changeItemDepth as _changeItemDepth } from '../utils/DragAndDrop/dragAndDropDriverFactory'; import { dataAttributes } from '../DragAndDrop/Draggable/constants'; import { dataHooks } from './constants'; var nestableListFactory = function nestableListFactory(_ref) { var element = _ref.element; var dragAndDropDriver = dragAndDropDriverFactory({ element: element.querySelector("[data-hook=\"".concat(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 _changeItemDepth({ dragAndDropDriver: dragAndDropDriver, depthLevel: depthLevel, threshold: threshold, dataHook: dataHook }); }, /** get nestable list item position */ getItemPosition: function getItemPosition(_ref5) { var dataHook = _ref5.dataHook; var draggableItems = _toConsumableArray(element.querySelectorAll("[".concat(dataAttributes.draggableTarget, "]"))); return draggableItems.findIndex(function (item) { return item.querySelectorAll("[".concat(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(dataAttributes.depth)); } }; }; export default nestableListFactory;