wix-style-react
Version:
wix-style-react
58 lines (56 loc) • 2.29 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.getContent = exports.focusOnRichEditor = exports.enterRichTextValue = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));
var _ReactBase = require("./ReactBase");
var _actCompat = require("./actCompat");
/** Receives a unidriver of container that wraps a DraftJS input
* and returns the input content element */
var getContent = base => base.$('.public-DraftEditor-content');
/** Receives a unidriver of container (base) that wraps a DraftJS input,
* and a `value` to add to the input
* adds the value to the current input value */
exports.getContent = getContent;
var enterRichTextValue = exports.enterRichTextValue = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)(function* (base, value) {
var contentElement = getContent(base);
var nativeElement = yield contentElement.getNative(); // eslint-disable-line no-restricted-properties
if (contentElement.type === 'react') {
yield (0, _actCompat.act)(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
_testUtils.default.Simulate.beforeInput(nativeElement, {
data: value
});
}));
} else if (contentElement.type === 'puppeteer') {
yield contentElement.enterValue(value, {
shouldClear: false
});
} else {
throw new Error('unsupported adapter');
}
});
return function enterRichTextValue(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
var focusOnRichEditor = exports.focusOnRichEditor = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2.default)(function* (base) {
switch (base.type) {
case 'react':
return (0, _ReactBase.ReactBase)(getContent(base)).focus();
case 'puppeteer':
var {
element
} = yield getContent(base).getNative();
return element.focus();
default:
throw new Error('unsupported adapter');
}
});
return function focusOnRichEditor(_x3) {
return _ref3.apply(this, arguments);
};
}();
//# sourceMappingURL=DraftJS.js.map