UNPKG

@wordpress/editor

Version:
95 lines (78 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _i18n = require("@wordpress/i18n"); var _components = require("@wordpress/components"); var _data = require("@wordpress/data"); var _blockEditor = require("@wordpress/block-editor"); var _compose = require("@wordpress/compose"); /** * WordPress dependencies */ function CopyButton({ text, children }) { const ref = (0, _compose.useCopyToClipboard)(text); return (0, _element.createElement)(_components.Button, { isSecondary: true, ref: ref }, children); } class ErrorBoundary extends _element.Component { constructor() { super(...arguments); this.reboot = this.reboot.bind(this); this.getContent = this.getContent.bind(this); this.state = { error: null }; } componentDidCatch(error) { this.setState({ error }); } reboot() { this.props.onError(); } getContent() { try { // While `select` in a component is generally discouraged, it is // used here because it (a) reduces the chance of data loss in the // case of additional errors by performing a direct retrieval and // (b) avoids the performance cost associated with unnecessary // content serialization throughout the lifetime of a non-erroring // application. return (0, _data.select)('core/editor').getEditedPostContent(); } catch (error) {} } render() { const { error } = this.state; if (!error) { return this.props.children; } return (0, _element.createElement)(_blockEditor.Warning, { className: "editor-error-boundary", actions: [(0, _element.createElement)(_components.Button, { key: "recovery", onClick: this.reboot, isSecondary: true }, (0, _i18n.__)('Attempt Recovery')), (0, _element.createElement)(CopyButton, { key: "copy-post", text: this.getContent }, (0, _i18n.__)('Copy Post Text')), (0, _element.createElement)(CopyButton, { key: "copy-error", text: error.stack }, (0, _i18n.__)('Copy Error'))] }, (0, _i18n.__)('The editor has encountered an unexpected error.')); } } var _default = ErrorBoundary; exports.default = _default; //# sourceMappingURL=index.js.map