UNPKG

@flatbiz/antd

Version:
93 lines (89 loc) 3.11 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { e as _inherits, f as _createClass, g as _classCallCheck, h as _callSuper, i as _defineProperty } from './_rollupPluginBabelHelpers-BspM60Sw.js'; import { Fragment, Component } from 'react'; import { Alert, Button } from 'antd'; import { isUndefinedOrNull } from '@flatbiz/utils'; import { F as FlexLayout } from './flex-layout-BGtMe7zr.js'; import { jsx, jsxs } from 'react/jsx-runtime'; var ErrorBoundary = /*#__PURE__*/function (_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", { error: undefined, info: { componentStack: '' } }); return _this; } _inherits(ErrorBoundary, _Component); return _createClass(ErrorBoundary, [{ key: "componentDidCatch", value: function componentDidCatch(error, info) { this.setState({ error: error, info: info }); } }, { key: "render", value: function render() { var _this$props = this.props, message = _this$props.message, description = _this$props.description, children = _this$props.children, onRenderReset = _this$props.onRenderReset; var _this$state = this.state, error = _this$state.error, info = _this$state.info; var componentStack = info && info.componentStack ? info.componentStack : null; var errorMessage = typeof message === 'undefined' ? (error || '').toString() : message; var errorDescription = typeof description === 'undefined' ? componentStack : description; var stackMaxHeight = isUndefinedOrNull(this.props.stackMaxHeight) ? 200 : this.props.stackMaxHeight; if (error) { return /*#__PURE__*/jsx(Alert, { type: "error", message: /*#__PURE__*/jsxs(FlexLayout, { fullIndex: 0, direction: "horizontal", children: [/*#__PURE__*/jsx("span", { children: errorMessage }), /*#__PURE__*/jsx(Button, { type: "primary", ghost: true, size: "small", onClick: onRenderReset, children: "\u91CD\u7F6E" })] }), description: /*#__PURE__*/jsx(Fragment, { children: /*#__PURE__*/jsx("div", { style: { maxHeight: stackMaxHeight, overflow: 'auto' }, children: /*#__PURE__*/jsx("pre", { style: { fontSize: '0.9em' }, children: errorDescription }) }) }) }); } return children; } }]); }(Component); /** * react 异常拦截 */ var ErrorBoundaryWrapper = ErrorBoundary; export { ErrorBoundaryWrapper as E }; //# sourceMappingURL=error-boundary-D6RX4EQZ.js.map