UNPKG

wix-style-react

Version:
155 lines (130 loc) • 6 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.draggableUniDriverFactory = 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"); 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 draggableUniDriverFactory = function draggableUniDriverFactory(base, body) { return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base, body)), {}, { /** * fire dragstart event for the provided draggable item * @param {DraggableItemDetails} itemDetails { id: string, dataHook: string } * @return {Promise<void>} */ beginDrag: function () { var _beginDrag = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) { var dataHook, id; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: dataHook = _ref.dataHook, id = _ref.id; _context.t0 = _dragAndDropDriverFactory.dragAndDropDriverFactory; _context.t1 = base; _context.next = 5; return base.getNative(); case 5: _context.t2 = _context.sent; _context.t3 = { base: _context.t1, element: _context.t2 }; return _context.abrupt("return", (0, _context.t0)(_context.t3).beginDrag({ dataHook: dataHook, id: id })); case 8: case "end": return _context.stop(); } } }, _callee); })); function beginDrag(_x) { return _beginDrag.apply(this, arguments); } return beginDrag; }(), /** * fire dragover event for the provided draggable item * @param {DraggableItemDetails} itemDetails { id: string, dataHook: string } * @return {Promise<void>} */ dragOver: function () { var _dragOver = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(_ref2) { var dataHook, id; return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: dataHook = _ref2.dataHook, id = _ref2.id; _context2.t0 = _dragAndDropDriverFactory.dragAndDropDriverFactory; _context2.t1 = base; _context2.next = 5; return base.getNative(); case 5: _context2.t2 = _context2.sent; _context2.t3 = { base: _context2.t1, element: _context2.t2 }; return _context2.abrupt("return", (0, _context2.t0)(_context2.t3).dragOver({ dataHook: dataHook, id: id })); case 8: case "end": return _context2.stop(); } } }, _callee2); })); function dragOver(_x2) { return _dragOver.apply(this, arguments); } return dragOver; }(), /** * fire drop and dragend events for the provided draggable item * @param {DraggableItemDetails} itemDetails { id: string, dataHook: string } * @return {Promise<void>} */ endDrag: function () { var _endDrag = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(draggableItemDetails) { return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.t0 = _dragAndDropDriverFactory.dragAndDropDriverFactory; _context3.t1 = base; _context3.next = 4; return base.getNative(); case 4: _context3.t2 = _context3.sent; _context3.t3 = { base: _context3.t1, element: _context3.t2 }; return _context3.abrupt("return", (0, _context3.t0)(_context3.t3).endDrag(draggableItemDetails)); case 7: case "end": return _context3.stop(); } } }, _callee3); })); function endDrag(_x3) { return _endDrag.apply(this, arguments); } return endDrag; }() }); }; exports.draggableUniDriverFactory = draggableUniDriverFactory;