UNPKG

wix-style-react

Version:
247 lines (217 loc) • 9.08 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _regeneratorRuntime from "@babel/runtime/regenerator"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import { dragAndDropDriverFactory, changeItemDepth as _changeItemDepth } from '../utils/DragAndDrop/dragAndDropDriverFactory'; import { baseUniDriverFactory, findByHook } from '../../test/utils/unidriver'; import { dataHooks } from './constants'; export var nestableListUniDriverFactory = function nestableListUniDriverFactory(base, body) { var dndProviderBase = findByHook(base, dataHooks.provider); return _objectSpread(_objectSpread({}, baseUniDriverFactory(dndProviderBase, body)), {}, { /** * reorder nestable list items by id * @param {ReorderIds} ids { addedId: string | number, removedId: string | number } * @return {Promise<void>} * @deprecated use reorderByDataHook */ reorder: function () { var _reorder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref, offset) { var removedId, addedId, baseEl, dragAndDropDriver; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: removedId = _ref.removedId, addedId = _ref.addedId; _context.next = 3; return dndProviderBase.getNative(); case 3: baseEl = _context.sent; dragAndDropDriver = dragAndDropDriverFactory({ base: dndProviderBase, element: baseEl }); _context.next = 7; return dragAndDropDriver.beginDrag({ id: removedId }); case 7: _context.next = 9; return dragAndDropDriver.dragOver({ id: addedId, offset: offset }); case 9: _context.next = 11; return dragAndDropDriver.endDrag({ id: addedId }); case 11: case "end": return _context.stop(); } } }, _callee); })); function reorder(_x, _x2) { return _reorder.apply(this, arguments); } return reorder; }(), /** * reorder nestable list items by data-hook * @param {ReorderDataHooks} dataHooks { from: string, to: string } * @return {Promise<void>} */ reorderByDataHook: function () { var _reorderByDataHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) { var from, to, baseEl, dragAndDropDriver; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: from = _ref2.from, to = _ref2.to; _context2.next = 3; return dndProviderBase.getNative(); case 3: baseEl = _context2.sent; dragAndDropDriver = dragAndDropDriverFactory({ base: dndProviderBase, element: baseEl }); _context2.next = 7; return dragAndDropDriver.beginDrag({ dataHook: from }); case 7: _context2.next = 9; return dragAndDropDriver.dragOver({ dataHook: to }); case 9: _context2.next = 11; return dragAndDropDriver.endDrag({ dataHook: to }); case 11: case "end": return _context2.stop(); } } }, _callee2); })); function reorderByDataHook(_x3) { return _reorderByDataHook.apply(this, arguments); } return reorderByDataHook; }(), /** * change nestable list item depth * @param {NestableItemDetails} dataHooks { dataHook: string, depthLevel: number, threshold: number } * @return {Promise<void>} */ changeItemDepth: function () { var _changeItemDepth2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) { var dataHook, depthLevel, _ref3$threshold, threshold; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: dataHook = _ref3.dataHook, depthLevel = _ref3.depthLevel, _ref3$threshold = _ref3.threshold, threshold = _ref3$threshold === void 0 ? 30 : _ref3$threshold; _context3.t0 = _changeItemDepth; _context3.t1 = dataHook; _context3.t2 = depthLevel; _context3.t3 = threshold; _context3.t4 = dragAndDropDriverFactory; _context3.t5 = dndProviderBase; _context3.next = 9; return dndProviderBase.getNative(); case 9: _context3.t6 = _context3.sent; _context3.t7 = { base: _context3.t5, element: _context3.t6 }; _context3.t8 = (0, _context3.t4)(_context3.t7); _context3.t9 = { dataHook: _context3.t1, depthLevel: _context3.t2, threshold: _context3.t3, dragAndDropDriver: _context3.t8 }; return _context3.abrupt("return", (0, _context3.t0)(_context3.t9)); case 14: case "end": return _context3.stop(); } } }, _callee3); })); function changeItemDepth(_x4) { return _changeItemDepth2.apply(this, arguments); } return changeItemDepth; }(), /** * get nestable list item position * @param {DraggableItemDetails} itemDetails { dataHook: string } * @return {Promise<void>} */ getItemPosition: function () { var _getItemPosition = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) { var dataHook; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: dataHook = _ref4.dataHook; return _context4.abrupt("return", dragAndDropDriverFactory({ base: dndProviderBase }).getItemPosition({ dataHook: dataHook })); case 2: case "end": return _context4.stop(); } } }, _callee4); })); function getItemPosition(_x5) { return _getItemPosition.apply(this, arguments); } return getItemPosition; }(), /** * get nestable list item depth * @param {DraggableItemDetails} itemDetails { dataHook: string } * @return {Promise<void>} */ getItemDepth: function () { var _getItemDepth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) { var dataHook; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: dataHook = _ref5.dataHook; return _context5.abrupt("return", dragAndDropDriverFactory({ base: dndProviderBase }).getItemDepth({ dataHook: dataHook })); case 2: case "end": return _context5.stop(); } } }, _callee5); })); function getItemDepth(_x6) { return _getItemDepth.apply(this, arguments); } return getItemDepth; }() }); }; export default nestableListUniDriverFactory;