wix-style-react
Version:
253 lines (209 loc) • 8.11 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.swatchesDriverFactory = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _FillPreviewUni = require("../FillPreview/FillPreview.uni.driver");
var _constants = require("./constants");
var swatchesDriverFactory = function swatchesDriverFactory(base) {
var _getSwatch = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(index) {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", base.$$('[data-hook="color-swatches-swatch"]').get(index));
case 1:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function getSwatch(_x) {
return _ref.apply(this, arguments);
};
}();
var getEmptySwatch = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", base.$("[data-hook=\"".concat(_constants.dataHooks.empty, "\"]")));
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function getEmptySwatch() {
return _ref2.apply(this, arguments);
};
}();
return {
exists: function () {
var _exists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", base.exists());
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function exists() {
return _exists.apply(this, arguments);
}
return exists;
}(),
/** Get swatch count */
getSwatchCount: function () {
var _getSwatchCount = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", base.$$('[data-hook="color-swatches-swatch"]').count());
case 1:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
function getSwatchCount() {
return _getSwatchCount.apply(this, arguments);
}
return getSwatchCount;
}(),
/** Get swatch at given index */
getSwatch: function () {
var _getSwatch2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(index) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.t0 = _FillPreviewUni.fillPreviewDriverFactory;
_context5.next = 3;
return _getSwatch(index);
case 3:
_context5.t1 = _context5.sent;
return _context5.abrupt("return", (0, _context5.t0)(_context5.t1));
case 5:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function getSwatch(_x2) {
return _getSwatch2.apply(this, arguments);
}
return getSwatch;
}(),
/** Click empty swatch */
clickEmptySwatch: function () {
var _clickEmptySwatch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.t0 = _FillPreviewUni.fillPreviewDriverFactory;
_context6.next = 3;
return getEmptySwatch();
case 3:
_context6.t1 = _context6.sent;
return _context6.abrupt("return", (0, _context6.t0)(_context6.t1).click());
case 5:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function clickEmptySwatch() {
return _clickEmptySwatch.apply(this, arguments);
}
return clickEmptySwatch;
}(),
/** Test if swatch is selected at given index */
isSwatchSelectedAt: function () {
var _isSwatchSelectedAt = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(index) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.t0 = _FillPreviewUni.fillPreviewDriverFactory;
_context7.next = 3;
return _getSwatch(index);
case 3:
_context7.t1 = _context7.sent;
return _context7.abrupt("return", (0, _context7.t0)(_context7.t1).isSelected());
case 5:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function isSwatchSelectedAt(_x3) {
return _isSwatchSelectedAt.apply(this, arguments);
}
return isSwatchSelectedAt;
}(),
/** Test if empty swatch is selected */
isEmptySwatchSelected: function () {
var _isEmptySwatchSelected = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.t0 = _FillPreviewUni.fillPreviewDriverFactory;
_context8.next = 3;
return getEmptySwatch();
case 3:
_context8.t1 = _context8.sent;
return _context8.abrupt("return", (0, _context8.t0)(_context8.t1).isSelected());
case 5:
case "end":
return _context8.stop();
}
}
}, _callee8);
}));
function isEmptySwatchSelected() {
return _isEmptySwatchSelected.apply(this, arguments);
}
return isEmptySwatchSelected;
}(),
addButtonExists: function () {
var _addButtonExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
return _context9.abrupt("return", base.$$('[data-hook="color-preview-add-button"]').count() === 1);
case 1:
case "end":
return _context9.stop();
}
}
}, _callee9);
}));
function addButtonExists() {
return _addButtonExists.apply(this, arguments);
}
return addButtonExists;
}()
};
};
exports.swatchesDriverFactory = swatchesDriverFactory;