UNPKG

alinea

Version:
112 lines (106 loc) 4.52 kB
import { dist_default } from "../../chunks/chunk-A5O3N2GS.js"; import "../../chunks/chunk-NZLE2WMY.js"; // src/dashboard/view/ErrorBoundary.tsx import { Head } from "alinea/dashboard/util/Head"; import { Button, HStack, Icon, Typo, VStack } from "alinea/ui"; import { IcRoundClose } from "alinea/ui/icons/IcRoundClose"; import { IcRoundOpenInNew } from "alinea/ui/icons/IcRoundOpenInNew"; import { IcRoundWarning } from "alinea/ui/icons/IcRoundWarning"; import { useEffect } from "react"; // node_modules/use-error-boundary/lib/index.module.js import r, { PureComponent as t, useReducer as e, useRef as n, useCallback as o } from "react"; var c = function(r2) { var t2, e2; function n2(t3) { var e3; return (e3 = r2.call(this, t3) || this).state = { hasError: false, error: null }, e3; } e2 = r2, (t2 = n2).prototype = Object.create(e2.prototype), t2.prototype.constructor = t2, t2.__proto__ = e2, n2.getDerivedStateFromError = function(r3) { return { hasError: true, error: r3 }; }; var o2 = n2.prototype; return o2.componentDidCatch = function(r3, t3) { return this.props.onDidCatch(r3, t3); }, o2.render = function() { var r3 = this.state, t3 = this.props, e3 = t3.render, n3 = t3.children, o3 = t3.renderError; return r3.hasError ? o3 ? o3({ error: r3.error }) : null : e3 ? e3() : n3 || null; }, n2; }(t); var u = function(r2, t2) { switch (t2.type) { case "catch": return { didCatch: true, error: t2.error }; case "reset": return { didCatch: false, error: null }; default: return r2; } }; function a(t2) { var a2 = e(u, { didCatch: false, error: null }), i = a2[0], d = a2[1], h = n(null); function l() { return e2 = function(r2, e3) { d({ type: "catch", error: r2 }), t2 && t2.onDidCatch && t2.onDidCatch(r2, e3); }, function(t3) { return r.createElement(c, { onDidCatch: e2, children: t3.children, render: t3.render, renderError: t3.renderError }); }; var e2; } var p, s = o(function() { h.current = l(), d({ type: "reset" }); }, []); return { ErrorBoundary: (p = h.current, null !== p ? p : (h.current = l(), h.current)), didCatch: i.didCatch, error: i.error, reset: s }; } var index_module_default = a; // src/dashboard/view/ErrorBoundary.tsx import { useLocation } from "../util/HashRouter.js"; // src/dashboard/view/ErrorBoundary.module.scss var ErrorBoundary_module_default = { "root": "alinea-ErrorBoundary", "root-inner": "alinea-ErrorBoundary-inner", "rootInner": "alinea-ErrorBoundary-inner", "root-mesage": "alinea-ErrorBoundary-mesage", "rootMesage": "alinea-ErrorBoundary-mesage" }; // src/dashboard/view/ErrorBoundary.tsx import { Fragment, jsx, jsxs } from "react/jsx-runtime"; var styles = dist_default(ErrorBoundary_module_default); function ErrorBoundary({ children, dependencies }) { const { ErrorBoundary: ErrorBoundary2, didCatch, error, reset } = index_module_default(); const location = useLocation(); useEffect(() => { if (error) reset(); }, [location]); useEffect(() => { if (error) reset(); }, dependencies || []); return /* @__PURE__ */ jsx(Fragment, { children: didCatch ? /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx(Head, { children: /* @__PURE__ */ jsx("title", { children: "Error" }) }), /* @__PURE__ */ jsx("div", { className: styles.root(), children: /* @__PURE__ */ jsxs(VStack, { gap: 16, className: styles.root.inner(), children: [ /* @__PURE__ */ jsxs(HStack, { gap: 8, center: true, children: [ /* @__PURE__ */ jsx(Icon, { icon: IcRoundWarning, size: 20 }), /* @__PURE__ */ jsx(Typo.H3, { flat: true, children: "Oops, something went wrong" }) ] }), /* @__PURE__ */ jsx("div", { className: styles.root.mesage(), children: error.message }), /* @__PURE__ */ jsxs(HStack, { gap: 16, center: true, children: [ /* @__PURE__ */ jsx(Button, { onClick: reset, icon: IcRoundClose, children: "Close error" }), /* @__PURE__ */ jsx( Typo.Link, { href: "https://github.com/alineacms/alinea/issues", target: "_blank", children: /* @__PURE__ */ jsxs(HStack, { gap: 8, center: true, children: [ /* @__PURE__ */ jsx("span", { children: "Create an issue" }), /* @__PURE__ */ jsx(Icon, { icon: IcRoundOpenInNew }) ] }) } ) ] }) ] }) }) ] }) : /* @__PURE__ */ jsx(ErrorBoundary2, { children }) }); } export { ErrorBoundary };