wix-style-react
Version:
264 lines (225 loc) • 9.79 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.nestableListUniDriverFactory = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _dragAndDropDriverFactory = require("../utils/DragAndDrop/dragAndDropDriverFactory");
var _unidriver = require("../../test/utils/unidriver");
var _constants = require("./constants");
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) { (0, _defineProperty2["default"])(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; }
var nestableListUniDriverFactory = function nestableListUniDriverFactory(base, body) {
var dndProviderBase = (0, _unidriver.findByHook)(base, _constants.dataHooks.provider);
return _objectSpread(_objectSpread({}, (0, _unidriver.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref, offset) {
var removedId, addedId, baseEl, dragAndDropDriver;
return _regenerator["default"].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 = (0, _dragAndDropDriverFactory.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(_ref2) {
var from, to, baseEl, dragAndDropDriver;
return _regenerator["default"].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 = (0, _dragAndDropDriverFactory.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(_ref3) {
var dataHook, depthLevel, _ref3$threshold, threshold;
return _regenerator["default"].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 = _dragAndDropDriverFactory.changeItemDepth;
_context3.t1 = dataHook;
_context3.t2 = depthLevel;
_context3.t3 = threshold;
_context3.t4 = _dragAndDropDriverFactory.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(_ref4) {
var dataHook;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
dataHook = _ref4.dataHook;
return _context4.abrupt("return", (0, _dragAndDropDriverFactory.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_ref5) {
var dataHook;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
dataHook = _ref5.dataHook;
return _context5.abrupt("return", (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
base: dndProviderBase
}).getItemDepth({
dataHook: dataHook
}));
case 2:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function getItemDepth(_x6) {
return _getItemDepth.apply(this, arguments);
}
return getItemDepth;
}()
});
};
exports.nestableListUniDriverFactory = nestableListUniDriverFactory;
var _default = nestableListUniDriverFactory;
exports["default"] = _default;