wix-style-react
Version:
1,376 lines (1,149 loc) • 45.9 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
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 _regeneratorRuntime from "@babel/runtime/regenerator";
import { baseUniDriverFactory, ReactBase, findByHook, getDataAttributeValue } from '../../test/utils/unidriver';
import { DATA_OPTION, DATA_HOOKS, DATA_DIRECTION, DATA_SHOWN, DROPDOWN_LAYOUT_DIRECTIONS, OPTION_DATA_HOOKS, DATA_SELECTED_OPTION_ID } from './DataAttr';
export var dropdownLayoutDriverFactory = function dropdownLayoutDriverFactory(base) {
var reactBase = ReactBase(base);
var contentContainer = function contentContainer() {
return findByHook(base, DATA_HOOKS.CONTENT_CONTAINER);
};
var infiniteScrollContainer = function infiniteScrollContainer() {
return findByHook(base, DATA_HOOKS.INFINITE_SCROLL_CONTAINER);
};
var optionsElement = function optionsElement() {
return findByHook(base, DATA_HOOKS.DROPDOWN_LAYOUT_OPTIONS);
};
function getOptionsContainerDataHook() {
return _getOptionsContainerDataHook.apply(this, arguments);
}
function _getOptionsContainerDataHook() {
_getOptionsContainerDataHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33() {
return _regeneratorRuntime.wrap(function _callee33$(_context33) {
while (1) {
switch (_context33.prev = _context33.next) {
case 0:
_context33.next = 2;
return infiniteScrollContainer().exists();
case 2:
if (!_context33.sent) {
_context33.next = 6;
break;
}
_context33.t0 = DATA_HOOKS.INFINITE_SCROLL_CONTAINER;
_context33.next = 7;
break;
case 6:
_context33.t0 = DATA_HOOKS.DROPDOWN_LAYOUT_OPTIONS;
case 7:
return _context33.abrupt("return", _context33.t0);
case 8:
case "end":
return _context33.stop();
}
}
}, _callee33);
}));
return _getOptionsContainerDataHook.apply(this, arguments);
}
var optionElementAt = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(position) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.t0 = base;
_context.t1 = "[data-hook=";
_context.next = 4;
return getOptionsContainerDataHook();
case 4:
_context.t2 = _context.sent;
_context.t3 = _context.t1.concat.call(_context.t1, _context.t2, "] > *:nth-child(").concat(position + 1, ")");
_context.next = 8;
return _context.t0.$.call(_context.t0, _context.t3);
case 8:
return _context.abrupt("return", _context.sent);
case 9:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function optionElementAt(_x) {
return _ref.apply(this, arguments);
};
}();
var optionElementByDataHook = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(dataHook) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.t0 = base;
_context2.t1 = "[data-hook=";
_context2.next = 4;
return getOptionsContainerDataHook();
case 4:
_context2.t2 = _context2.sent;
_context2.t3 = _context2.t1.concat.call(_context2.t1, _context2.t2, "] [data-hook=\"").concat(dataHook, "\"]");
_context2.next = 8;
return _context2.t0.$.call(_context2.t0, _context2.t3);
case 8:
return _context2.abrupt("return", _context2.sent);
case 9:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function optionElementByDataHook(_x2) {
return _ref2.apply(this, arguments);
};
}();
var options = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.t0 = base;
_context3.t1 = "[data-hook=";
_context3.next = 4;
return getOptionsContainerDataHook();
case 4:
_context3.t2 = _context3.sent;
_context3.t3 = _context3.t1.concat.call(_context3.t1, _context3.t2, "] > *");
return _context3.abrupt("return", _context3.t0.$$.call(_context3.t0, _context3.t3).map(function (i) {
return i;
}));
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return function options() {
return _ref3.apply(this, arguments);
};
}();
var optionsLength = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return options();
case 2:
return _context4.abrupt("return", _context4.sent.length);
case 3:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
return function optionsLength() {
return _ref4.apply(this, arguments);
};
}();
var doIfOptionExists = function doIfOptionExists(position, onSuccess) {
if (optionsLength() <= position) {
throw new Error("index out of bounds, try to get option ".concat(position, " while only ").concat(optionsLength(), " options exists"));
}
return onSuccess();
};
var getOptionDriver = function getOptionDriver(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.t0 = createOptionDriver;
_context5.next = 3;
return optionElementAt(position);
case 3:
_context5.t1 = _context5.sent;
return _context5.abrupt("return", (0, _context5.t0)(_context5.t1));
case 5:
case "end":
return _context5.stop();
}
}
}, _callee5);
})));
};
return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, {
/** @deprecated should be private */
classes: function classes() {
return optionsElement()._prop('className');
},
/** Clicks on an option at a specific index
* @param {number} option index
* @return {Promise<void>}
*/
clickAtOption: function () {
var _clickAtOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(index) {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return getOptionDriver(index);
case 2:
optionDriver = _context6.sent;
return _context6.abrupt("return", optionDriver.click());
case 4:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function clickAtOption(_x3) {
return _clickAtOption.apply(this, arguments);
}
return clickAtOption;
}(),
/** Clicks on an option with a specific dataHook
* @param {string} dataHook
* @return {Promise<void>}
*/
clickAtOptionByDataHook: function () {
var _clickAtOptionByDataHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(dataHook) {
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return optionElementByDataHook(dataHook);
case 2:
return _context7.abrupt("return", _context7.sent.click());
case 3:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function clickAtOptionByDataHook(_x4) {
return _clickAtOptionByDataHook.apply(this, arguments);
}
return clickAtOptionByDataHook;
}(),
/** Clicks on an option with a specific value
* @param {string} value
* @return {Promise<void>}
*/
clickAtOptionWithValue: function () {
var _clickAtOptionWithValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(value) {
var _iterator, _step, _option, optionDriver;
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.t0 = _createForOfIteratorHelper;
_context8.next = 3;
return options();
case 3:
_context8.t1 = _context8.sent;
_iterator = (0, _context8.t0)(_context8.t1);
_context8.prev = 5;
_iterator.s();
case 7:
if ((_step = _iterator.n()).done) {
_context8.next = 20;
break;
}
_option = _step.value;
_context8.next = 11;
return createOptionDriver(_option);
case 11:
optionDriver = _context8.sent;
_context8.next = 14;
return optionDriver.content();
case 14:
_context8.t2 = _context8.sent;
_context8.t3 = value;
if (!(_context8.t2 === _context8.t3)) {
_context8.next = 18;
break;
}
return _context8.abrupt("return", optionDriver.click());
case 18:
_context8.next = 7;
break;
case 20:
_context8.next = 25;
break;
case 22:
_context8.prev = 22;
_context8.t4 = _context8["catch"](5);
_iterator.e(_context8.t4);
case 25:
_context8.prev = 25;
_iterator.f();
return _context8.finish(25);
case 28:
case "end":
return _context8.stop();
}
}
}, _callee8, null, [[5, 22, 25, 28]]);
}));
function clickAtOptionWithValue(_x5) {
return _clickAtOptionWithValue.apply(this, arguments);
}
return clickAtOptionWithValue;
}(),
/** @deprecated deprecated prop */
hasTopArrow: function () {
var _hasTopArrow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return findByHook(base, DATA_HOOKS.TOP_ARROW);
case 2:
_context9.next = 4;
return _context9.sent.exists();
case 4:
return _context9.abrupt("return", _context9.sent);
case 5:
case "end":
return _context9.stop();
}
}
}, _callee9);
}));
function hasTopArrow() {
return _hasTopArrow.apply(this, arguments);
}
return hasTopArrow;
}(),
/** @deprecated deprecated prop */
isDown: function () {
var _isDown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return contentContainer();
case 2:
_context10.next = 4;
return _context10.sent.attr(DATA_DIRECTION);
case 4:
_context10.t0 = _context10.sent;
_context10.t1 = DROPDOWN_LAYOUT_DIRECTIONS.DOWN;
return _context10.abrupt("return", _context10.t0 === _context10.t1);
case 7:
case "end":
return _context10.stop();
}
}
}, _callee10);
}));
function isDown() {
return _isDown.apply(this, arguments);
}
return isDown;
}(),
/** @deprecated deprecated prop */
isUp: function () {
var _isUp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
_context11.next = 2;
return contentContainer();
case 2:
_context11.next = 4;
return _context11.sent.attr(DATA_DIRECTION);
case 4:
_context11.t0 = _context11.sent;
_context11.t1 = DROPDOWN_LAYOUT_DIRECTIONS.UP;
return _context11.abrupt("return", _context11.t0 === _context11.t1);
case 7:
case "end":
return _context11.stop();
}
}
}, _callee11);
}));
function isUp() {
return _isUp.apply(this, arguments);
}
return isUp;
}(),
isLinkOption: function () {
var _isLinkOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(position) {
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
return _context13.abrupt("return", doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return getOptionDriver(position);
case 2:
optionDriver = _context12.sent;
return _context12.abrupt("return", optionDriver.isLink());
case 4:
case "end":
return _context12.stop();
}
}
}, _callee12);
}))));
case 1:
case "end":
return _context13.stop();
}
}
}, _callee13);
}));
function isLinkOption(_x6) {
return _isLinkOption.apply(this, arguments);
}
return isLinkOption;
}(),
isOptionADivider: function isOptionADivider(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.next = 2;
return getOptionDriver(position);
case 2:
optionDriver = _context14.sent;
return _context14.abrupt("return", optionDriver.isDivider());
case 4:
case "end":
return _context14.stop();
}
}
}, _callee14);
})));
},
isOptionExists: function () {
var _isOptionExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(optionText) {
var _iterator2, _step2, _option;
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_context15.t0 = _createForOfIteratorHelper;
_context15.next = 3;
return options();
case 3:
_context15.t1 = _context15.sent;
_iterator2 = (0, _context15.t0)(_context15.t1);
_context15.prev = 5;
_iterator2.s();
case 7:
if ((_step2 = _iterator2.n()).done) {
_context15.next = 17;
break;
}
_option = _step2.value;
_context15.next = 11;
return _option.text();
case 11:
_context15.t2 = _context15.sent;
_context15.t3 = optionText;
if (!(_context15.t2 === _context15.t3)) {
_context15.next = 15;
break;
}
return _context15.abrupt("return", true);
case 15:
_context15.next = 7;
break;
case 17:
_context15.next = 22;
break;
case 19:
_context15.prev = 19;
_context15.t4 = _context15["catch"](5);
_iterator2.e(_context15.t4);
case 22:
_context15.prev = 22;
_iterator2.f();
return _context15.finish(22);
case 25:
return _context15.abrupt("return", false);
case 26:
case "end":
return _context15.stop();
}
}
}, _callee15, null, [[5, 19, 22, 25]]);
}));
function isOptionExists(_x7) {
return _isOptionExists.apply(this, arguments);
}
return isOptionExists;
}(),
isOptionHovered: function () {
var _isOptionHovered = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(index) {
return _regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context17.prev = _context17.next) {
case 0:
return _context17.abrupt("return", doIfOptionExists(index, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
_context16.next = 2;
return getOptionDriver(index);
case 2:
optionDriver = _context16.sent;
return _context16.abrupt("return", optionDriver.isHovered());
case 4:
case "end":
return _context16.stop();
}
}
}, _callee16);
}))));
case 1:
case "end":
return _context17.stop();
}
}
}, _callee17);
}));
function isOptionHovered(_x8) {
return _isOptionHovered.apply(this, arguments);
}
return isOptionHovered;
}(),
isOptionSelected: function () {
var _isOptionSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(index) {
return _regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {
switch (_context19.prev = _context19.next) {
case 0:
return _context19.abrupt("return", doIfOptionExists(index, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) {
switch (_context18.prev = _context18.next) {
case 0:
_context18.next = 2;
return getOptionDriver(index);
case 2:
optionDriver = _context18.sent;
return _context18.abrupt("return", optionDriver.isSelected());
case 4:
case "end":
return _context18.stop();
}
}
}, _callee18);
}))));
case 1:
case "end":
return _context19.stop();
}
}
}, _callee19);
}));
function isOptionSelected(_x9) {
return _isOptionSelected.apply(this, arguments);
}
return isOptionSelected;
}(),
/** @deprecated */
isOptionHeightSmall: function isOptionHeightSmall(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
return _regeneratorRuntime.wrap(function _callee20$(_context20) {
while (1) {
switch (_context20.prev = _context20.next) {
case 0:
_context20.next = 2;
return optionElementAt(position);
case 2:
_context20.next = 4;
return _context20.sent.attr(DATA_OPTION.SIZE);
case 4:
_context20.t0 = _context20.sent;
return _context20.abrupt("return", _context20.t0 === 'small');
case 6:
case "end":
return _context20.stop();
}
}
}, _callee20);
})));
},
/** @deprecated */
isOptionHeightBig: function isOptionHeightBig(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
return _regeneratorRuntime.wrap(function _callee21$(_context21) {
while (1) {
switch (_context21.prev = _context21.next) {
case 0:
_context21.next = 2;
return optionElementAt(position);
case 2:
_context21.next = 4;
return _context21.sent.attr(DATA_OPTION.SIZE);
case 4:
_context21.t0 = _context21.sent;
return _context21.abrupt("return", _context21.t0 === 'big');
case 6:
case "end":
return _context21.stop();
}
}
}, _callee21);
})));
},
isShown: function () {
var _isShown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() {
return _regeneratorRuntime.wrap(function _callee22$(_context22) {
while (1) {
switch (_context22.prev = _context22.next) {
case 0:
_context22.next = 2;
return contentContainer();
case 2:
_context22.next = 4;
return _context22.sent.attr(DATA_SHOWN);
case 4:
return _context22.abrupt("return", !!_context22.sent);
case 5:
case "end":
return _context22.stop();
}
}
}, _callee22);
}));
function isShown() {
return _isShown.apply(this, arguments);
}
return isShown;
}(),
mouseEnter: function mouseEnter() {
return base.hover();
},
mouseEnterAtOption: function mouseEnterAtOption(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee23$(_context23) {
while (1) {
switch (_context23.prev = _context23.next) {
case 0:
_context23.next = 2;
return getOptionDriver(position);
case 2:
optionDriver = _context23.sent;
return _context23.abrupt("return", optionDriver.mouseEnter());
case 4:
case "end":
return _context23.stop();
}
}
}, _callee23);
})));
},
mouseLeave: function () {
var _mouseLeave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24() {
var _yield$baseUniDriverF, element;
return _regeneratorRuntime.wrap(function _callee24$(_context24) {
while (1) {
switch (_context24.prev = _context24.next) {
case 0:
_context24.t0 = base.type;
_context24.next = _context24.t0 === 'react' ? 3 : _context24.t0 === 'puppeteer' ? 5 : 11;
break;
case 3:
reactBase.mouseLeave();
return _context24.abrupt("return");
case 5:
_context24.next = 7;
return baseUniDriverFactory(base).element();
case 7:
_yield$baseUniDriverF = _context24.sent;
element = _yield$baseUniDriverF.element;
page.evaluate(function (element) {
element.dispatchEvent(new MouseEvent('mouseout', {
bubbles: true,
view: window,
cancelable: true
}));
}, element);
return _context24.abrupt("return");
case 11:
return _context24.abrupt("return");
case 12:
case "end":
return _context24.stop();
}
}
}, _callee24);
}));
function mouseLeave() {
return _mouseLeave.apply(this, arguments);
}
return mouseLeave;
}(),
/** @deprecated deprecated prop */
mouseClickOutside: function mouseClickOutside() {
return ReactBase.clickBody();
},
mouseLeaveAtOption: function mouseLeaveAtOption(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee25$(_context25) {
while (1) {
switch (_context25.prev = _context25.next) {
case 0:
_context25.next = 2;
return getOptionDriver(position);
case 2:
optionDriver = _context25.sent;
return _context25.abrupt("return", optionDriver.mouseLeave());
case 4:
case "end":
return _context25.stop();
}
}
}, _callee25);
})));
},
/** @deprecated Use optionDriver*/
optionAt: function optionAt() {
return optionElementAt.getNative(); // eslint-disable-line no-restricted-properties
},
// This should be a private method since the hook include internal parts ('dropdown-divider-{id}, dropdown-item-{id})') */
/** @deprecated */
optionByHook: function () {
var _optionByHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(hook) {
var option;
return _regeneratorRuntime.wrap(function _callee26$(_context26) {
while (1) {
switch (_context26.prev = _context26.next) {
case 0:
option = optionsElement().$("[data-hook=".concat(hook, "]"));
_context26.next = 3;
return option.exists();
case 3:
if (_context26.sent) {
_context26.next = 5;
break;
}
throw new Error("an option with data-hook ".concat(hook, " was not found"));
case 5:
return _context26.abrupt("return", createOptionDriver(option));
case 6:
case "end":
return _context26.stop();
}
}
}, _callee26);
}));
function optionByHook(_x10) {
return _optionByHook.apply(this, arguments);
}
return optionByHook;
}(),
/**
* Get Option by id
* @returns {Promise<any>}
*/
optionById: function optionById(optionId) {
return this.optionByHook("dropdown-item-".concat(optionId));
},
optionContentAt: function optionContentAt(position) {
return doIfOptionExists(position, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27() {
var optionDriver;
return _regeneratorRuntime.wrap(function _callee27$(_context27) {
while (1) {
switch (_context27.prev = _context27.next) {
case 0:
_context27.next = 2;
return getOptionDriver(position);
case 2:
optionDriver = _context27.sent;
return _context27.abrupt("return", optionDriver.content());
case 4:
case "end":
return _context27.stop();
}
}
}, _callee27);
})));
},
optionDriver: createOptionDriver,
/** Get Options drivers */
options: function () {
var _options = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28() {
var drivers, position;
return _regeneratorRuntime.wrap(function _callee28$(_context28) {
while (1) {
switch (_context28.prev = _context28.next) {
case 0:
drivers = [];
position = 0;
case 2:
_context28.t0 = position;
_context28.next = 5;
return optionsLength();
case 5:
_context28.t1 = _context28.sent;
if (!(_context28.t0 < _context28.t1)) {
_context28.next = 15;
break;
}
_context28.t2 = drivers;
_context28.next = 10;
return getOptionDriver(position);
case 10:
_context28.t3 = _context28.sent;
_context28.t2.push.call(_context28.t2, _context28.t3);
case 12:
position++;
_context28.next = 2;
break;
case 15:
return _context28.abrupt("return", drivers);
case 16:
case "end":
return _context28.stop();
}
}
}, _callee28);
}));
function options() {
return _options.apply(this, arguments);
}
return options;
}(),
optionsContent: function () {
var _optionsContent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29() {
var contentArray, _iterator3, _step3, option, optionDriver;
return _regeneratorRuntime.wrap(function _callee29$(_context29) {
while (1) {
switch (_context29.prev = _context29.next) {
case 0:
contentArray = [];
_context29.t0 = _createForOfIteratorHelper;
_context29.next = 4;
return options();
case 4:
_context29.t1 = _context29.sent;
_iterator3 = (0, _context29.t0)(_context29.t1);
_context29.prev = 6;
_iterator3.s();
case 8:
if ((_step3 = _iterator3.n()).done) {
_context29.next = 20;
break;
}
option = _step3.value;
_context29.next = 12;
return createOptionDriver(option);
case 12:
optionDriver = _context29.sent;
_context29.t2 = contentArray;
_context29.next = 16;
return optionDriver.content();
case 16:
_context29.t3 = _context29.sent;
_context29.t2.push.call(_context29.t2, _context29.t3);
case 18:
_context29.next = 8;
break;
case 20:
_context29.next = 25;
break;
case 22:
_context29.prev = 22;
_context29.t4 = _context29["catch"](6);
_iterator3.e(_context29.t4);
case 25:
_context29.prev = 25;
_iterator3.f();
return _context29.finish(25);
case 28:
return _context29.abrupt("return", contentArray);
case 29:
case "end":
return _context29.stop();
}
}
}, _callee29, null, [[6, 22, 25, 28]]);
}));
function optionsContent() {
return _optionsContent.apply(this, arguments);
}
return optionsContent;
}(),
markedOption: function () {
var _markedOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31() {
var allOptions, optionsWithHovered, hoveredOptions;
return _regeneratorRuntime.wrap(function _callee31$(_context31) {
while (1) {
switch (_context31.prev = _context31.next) {
case 0:
_context31.next = 2;
return options();
case 2:
allOptions = _context31.sent;
_context31.next = 5;
return Promise.all(allOptions.map( /*#__PURE__*/function () {
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30(option) {
return _regeneratorRuntime.wrap(function _callee30$(_context30) {
while (1) {
switch (_context30.prev = _context30.next) {
case 0:
_context30.t0 = option;
_context30.next = 3;
return option.attr(DATA_OPTION.HOVERED);
case 3:
_context30.t1 = !!_context30.sent;
return _context30.abrupt("return", {
option: _context30.t0,
hovered: _context30.t1
});
case 5:
case "end":
return _context30.stop();
}
}
}, _callee30);
}));
return function (_x11) {
return _ref15.apply(this, arguments);
};
}()));
case 5:
optionsWithHovered = _context31.sent;
hoveredOptions = optionsWithHovered.filter(function (option) {
return option.hovered;
}).map(function (option) {
return option.option;
});
return _context31.abrupt("return", hoveredOptions.length && createOptionDriver(hoveredOptions[0]).content() || null);
case 8:
case "end":
return _context31.stop();
}
}
}, _callee31);
}));
function markedOption() {
return _markedOption.apply(this, arguments);
}
return markedOption;
}(),
getSelectedOptionId: function () {
var _getSelectedOptionId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32() {
return _regeneratorRuntime.wrap(function _callee32$(_context32) {
while (1) {
switch (_context32.prev = _context32.next) {
case 0:
_context32.t0 = getDataAttributeValue;
_context32.next = 3;
return contentContainer();
case 3:
_context32.t1 = _context32.sent;
_context32.t2 = DATA_SELECTED_OPTION_ID;
_context32.next = 7;
return (0, _context32.t0)(_context32.t1, _context32.t2);
case 7:
return _context32.abrupt("return", _context32.sent);
case 8:
case "end":
return _context32.stop();
}
}
}, _callee32);
}));
function getSelectedOptionId() {
return _getSelectedOptionId.apply(this, arguments);
}
return getSelectedOptionId;
}(),
optionsLength: optionsLength,
/** @deprecated should be private */
optionsScrollTop: function optionsScrollTop() {
return optionsElement()._prop('scrollTop');
},
pressDownKey: function pressDownKey() {
return base.pressKey('ArrowDown');
},
pressUpKey: function pressUpKey() {
return base.pressKey('ArrowUp');
},
pressEnterKey: function pressEnterKey() {
return base.pressKey('Enter');
},
pressSpaceKey: function pressSpaceKey() {
return base.pressKey(' ');
},
pressTabKey: function pressTabKey() {
return base.pressKey('Tab');
},
pressEscKey: function pressEscKey() {
return base.pressKey('Escape');
},
tabIndex: function tabIndex() {
return base._prop('tabIndex');
}
});
};
var createOptionDriver = function createOptionDriver(option) {
return {
element: function element() {
return option;
},
mouseEnter: function mouseEnter() {
return option.hover();
},
mouseLeave: function mouseLeave() {
return ReactBase(option).mouseLeave();
},
isHovered: function () {
var _isHovered = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34() {
return _regeneratorRuntime.wrap(function _callee34$(_context34) {
while (1) {
switch (_context34.prev = _context34.next) {
case 0:
_context34.next = 2;
return option.attr(DATA_OPTION.HOVERED);
case 2:
return _context34.abrupt("return", !!_context34.sent);
case 3:
case "end":
return _context34.stop();
}
}
}, _callee34);
}));
function isHovered() {
return _isHovered.apply(this, arguments);
}
return isHovered;
}(),
isSelected: function () {
var _isSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee35() {
return _regeneratorRuntime.wrap(function _callee35$(_context35) {
while (1) {
switch (_context35.prev = _context35.next) {
case 0:
_context35.next = 2;
return option.attr(DATA_OPTION.SELECTED);
case 2:
return _context35.abrupt("return", !!_context35.sent);
case 3:
case "end":
return _context35.stop();
}
}
}, _callee35);
}));
function isSelected() {
return _isSelected.apply(this, arguments);
}
return isSelected;
}(),
content: function content() {
return option.text();
},
click: function click() {
return option.click();
},
isDivider: function () {
var _isDivider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee36() {
var divider;
return _regeneratorRuntime.wrap(function _callee36$(_context36) {
while (1) {
switch (_context36.prev = _context36.next) {
case 0:
_context36.next = 2;
return findByHook(option, OPTION_DATA_HOOKS.DIVIDER);
case 2:
divider = _context36.sent;
return _context36.abrupt("return", divider.exists());
case 4:
case "end":
return _context36.stop();
}
}
}, _callee36);
}));
function isDivider() {
return _isDivider.apply(this, arguments);
}
return isDivider;
}(),
isDisabled: function () {
var _isDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee37() {
return _regeneratorRuntime.wrap(function _callee37$(_context37) {
while (1) {
switch (_context37.prev = _context37.next) {
case 0:
_context37.next = 2;
return option.attr(DATA_OPTION.DISABLED);
case 2:
return _context37.abrupt("return", !!_context37.sent);
case 3:
case "end":
return _context37.stop();
}
}
}, _callee37);
}));
function isDisabled() {
return _isDisabled.apply(this, arguments);
}
return isDisabled;
}(),
isLink: function () {
var _isLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee38() {
return _regeneratorRuntime.wrap(function _callee38$(_context38) {
while (1) {
switch (_context38.prev = _context38.next) {
case 0:
_context38.next = 2;
return option._prop('tagName');
case 2:
_context38.t0 = _context38.sent.toLowerCase();
return _context38.abrupt("return", _context38.t0 === 'a');
case 4:
case "end":
return _context38.stop();
}
}
}, _callee38);
}));
function isLink() {
return _isLink.apply(this, arguments);
}
return isLink;
}()
};
};