wix-style-react
Version:
213 lines (181 loc) • 7.92 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
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 { colorInputDriverFactory as publicDriverFactory } from './ColorInput.uni.driver';
import { swatchesPrivateDriverFactory } from '../Swatches/test/Swatches.private.uni.driver';
import DATA_HOOKS from './DataHooks';
import inputUniDriverFactory from '../Input/Input.uni.driver';
import { popoverDriverFactory } from '../Popover/Popover.uni.driver';
export var colorInputPrivateDriverFactory = function colorInputPrivateDriverFactory(base, body) {
var swatchesHook = "[data-hook=\"".concat(DATA_HOOKS.COLOR_PICKER_SWATCHES, "\"]");
var swatchesDriver = swatchesPrivateDriverFactory(base.$(swatchesHook));
var colorViewerPopoverHook = "[data-hook=\"".concat(DATA_HOOKS.COLOR_INPUT_POPOVER, "\"]");
var colorViewerPopoverTestkit = popoverDriverFactory(base.$(colorViewerPopoverHook), body);
var isHashDisabled = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return base.$("[data-hook=\"".concat(DATA_HOOKS.COLOR_INPUT_HASH, "\"]")).attr('data-disabled');
case 2:
_context.t0 = _context.sent;
return _context.abrupt("return", _context.t0 === 'true');
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function isHashDisabled() {
return _ref.apply(this, arguments);
};
}();
var getViewerSize = function getViewerSize() {
return base.$("[data-hook=\"".concat(DATA_HOOKS.COLOR_INPUT_VIEWER, "\"]")).attr('data-size');
};
var inputTestkit = inputUniDriverFactory(base);
return _objectSpread(_objectSpread({}, publicDriverFactory(base, body)), {}, {
isHashDisabled: isHashDisabled,
isViewerNull: function () {
var _isViewerNull = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return base.$("[data-hook=\"".concat(DATA_HOOKS.COLOR_INPUT_VIEWER_LINE, "\"]")).exists();
case 2:
return _context2.abrupt("return", _context2.sent);
case 3:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function isViewerNull() {
return _isViewerNull.apply(this, arguments);
}
return isViewerNull;
}(),
getViewerSize: getViewerSize,
getSwatch: function () {
var _getSwatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(index) {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", swatchesDriver.getSwatch(index));
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function getSwatch(_x) {
return _getSwatch.apply(this, arguments);
}
return getSwatch;
}(),
getSwatchCount: function () {
var _getSwatchCount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", swatchesDriver.getSwatchCount());
case 1:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
function getSwatchCount() {
return _getSwatchCount.apply(this, arguments);
}
return getSwatchCount;
}(),
/** Private Swatches driver function to test if swatch is transparent at given index */
isSwatchTransparentAt: function () {
var _isSwatchTransparentAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(index) {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
return _context5.abrupt("return", swatchesDriver.isSwatchTransparentAt(index));
case 1:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function isSwatchTransparentAt(_x2) {
return _isSwatchTransparentAt.apply(this, arguments);
}
return isSwatchTransparentAt;
}(),
keyDown: function () {
var _keyDown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(event) {
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
if (!(typeof event === 'string')) {
_context6.next = 5;
break;
}
_context6.next = 3;
return inputTestkit.keyDown({
key: event
});
case 3:
_context6.next = 7;
break;
case 5:
_context6.next = 7;
return inputTestkit.keyDown(event);
case 7:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function keyDown(_x3) {
return _keyDown.apply(this, arguments);
}
return keyDown;
}(),
blur: inputTestkit.blur,
focus: inputTestkit.focus,
clickOutside: function () {
var _clickOutside = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
return _context7.abrupt("return", colorViewerPopoverTestkit.clickOutside());
case 1:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function clickOutside() {
return _clickOutside.apply(this, arguments);
}
return clickOutside;
}(),
hasPrefix: inputTestkit.hasPrefix
});
};
export default colorInputPrivateDriverFactory;