@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
57 lines • 3.07 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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');
};
export var IntlErrorBoundary = /*#__PURE__*/function (_React$Component) {
_inherits(IntlErrorBoundary, _React$Component);
var _super = _createSuper(IntlErrorBoundary);
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 = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "state", {
missingIntlProviderInAncestry: false
});
return _this;
}
_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;
}
}]);
return IntlErrorBoundary;
}(React.Component);