@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
72 lines • 2.83 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 { ACTION, EVENT_TYPE } from '../../analytics';
import { logException } from '../../monitoring/error';
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/react/no-class-components
export var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
function ErrorBoundary() {
var _this;
_classCallCheck(this, ErrorBoundary);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, ErrorBoundary, [].concat(args));
_defineProperty(_this, "state", {
errorCaptured: false
});
return _this;
}
_inherits(ErrorBoundary, _React$Component);
return _createClass(ErrorBoundary, [{
key: "hasFallback",
value: function hasFallback() {
return typeof this.props.fallbackComponent !== 'undefined';
}
}, {
key: "shouldRecover",
value: function shouldRecover() {
return this.hasFallback() && this.state.errorCaptured;
}
}, {
key: "componentDidCatch",
value: function componentDidCatch(error, errorInfo) {
if (this.props.dispatchAnalyticsEvent) {
this.props.dispatchAnalyticsEvent({
action: ACTION.EDITOR_CRASHED,
actionSubject: this.props.component,
actionSubjectId: this.props.componentId,
eventType: EVENT_TYPE.OPERATIONAL,
attributes: {
error: error,
errorInfo: errorInfo,
errorRethrown: !this.hasFallback()
}
});
}
logException(error, {
location: 'editor-common'
});
if (this.hasFallback()) {
this.setState({
errorCaptured: true
});
}
}
}, {
key: "render",
value: function render() {
if (this.shouldRecover()) {
return this.props.fallbackComponent;
}
return this.props.children;
}
}]);
}(React.Component);