@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
57 lines (56 loc) • 2.77 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React from 'react';
import { IntlProvider } from 'react-intl-next';
export var REACT_INTL_ERROR_MESSAGE = '<IntlProvider> needs to exist in the component ancestry';
var isMissingIntlProviderInAncestryError = function isMissingIntlProviderInAncestryError(err) {
var _err$toString;
return err === null || err === void 0 || (_err$toString = err.toString()) === null || _err$toString === void 0 ? void 0 : _err$toString.includes('<IntlProvider> needs to exist in the component ancestry');
};
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/react/no-class-components
export var IntlErrorBoundary = /*#__PURE__*/function (_React$Component) {
function IntlErrorBoundary() {
var _this;
_classCallCheck(this, IntlErrorBoundary);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, IntlErrorBoundary, [].concat(args));
_defineProperty(_this, "state", {
missingIntlProviderInAncestry: false
});
return _this;
}
_inherits(IntlErrorBoundary, _React$Component);
return _createClass(IntlErrorBoundary, [{
key: "componentDidCatch",
value: function componentDidCatch(error, errorInfo) {
// if missing IntlProvider in ancestry, we setup a fallback IntlProvider ourselves
if (isMissingIntlProviderInAncestryError(error)) {
this.setState({
missingIntlProviderInAncestry: true
});
} else {
// else we re-propagate the non-react-intl-next error
throw error;
}
}
}, {
key: "render",
value: function render() {
if (this.state.missingIntlProviderInAncestry) {
return /*#__PURE__*/React.createElement(IntlProvider, {
locale: "en"
}, this.props.children);
}
return this.props.children;
}
}]);
}(React.Component);