UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

354 lines (353 loc) 14.8 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var ErrorBoundary_web_exports = {}; __export(ErrorBoundary_web_exports, { ErrorBoundary: () => ErrorBoundary }); module.exports = __toCommonJS(ErrorBoundary_web_exports); var import_react = __toESM(require("react"), 1), import_jsx_runtime = require("react/jsx-runtime"); function ErrorBoundary({ error, retry, route }) { const isDev = process.env.NODE_ENV === "development"; return import_react.default.useEffect(() => { typeof window < "u" && window.dispatchEvent( new CustomEvent("one-error", { detail: { error: { message: error.message, stack: error.stack, name: error.name }, route: route || {}, timestamp: Date.now(), type: "render" } }) ); }, [error, route]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { style: { minHeight: "100vh", display: "flex", alignItems: "center", justifyContent: "center", backgroundColor: "#0a0a0f", fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif', color: "#e8e8e8", padding: "24px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { style: { maxWidth: "600px", width: "100%", backgroundColor: "#1a1a2e", borderRadius: "12px", boxShadow: "0 8px 32px rgba(0, 0, 0, 0.4)", overflow: "hidden" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { style: { padding: "16px 20px", backgroundColor: "#ef4444", display: "flex", alignItems: "center", gap: "12px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "2", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" }) ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontWeight: 600, fontSize: "16px", color: "white" }, children: "Something went wrong" }), route?.pathname && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { style: { fontSize: "13px", color: "rgba(255,255,255,0.8)", marginTop: "2px" }, children: [ "on ", route.pathname ] } ) ] }) ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "20px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { style: { backgroundColor: "#2a2a4a", borderRadius: "8px", padding: "16px", marginBottom: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { style: { fontFamily: "monospace", fontSize: "14px", lineHeight: "1.5", color: "#f87171", wordBreak: "break-word" }, children: error.message || "An unexpected error occurred" } ) } ), isDev && error.stack && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "details", { style: { marginBottom: "16px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "summary", { style: { cursor: "pointer", fontSize: "13px", color: "#888", marginBottom: "8px" }, children: "Stack trace" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { style: { backgroundColor: "#16162a", borderRadius: "8px", padding: "12px", maxHeight: "200px", overflow: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "pre", { style: { fontFamily: "monospace", fontSize: "11px", lineHeight: "1.6", color: "#a0a0a0", margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: error.stack } ) } ) ] } ), isDev && route && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "details", { style: { marginBottom: "16px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "summary", { style: { cursor: "pointer", fontSize: "13px", color: "#888", marginBottom: "8px" }, children: "Route info" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { style: { backgroundColor: "#16162a", borderRadius: "8px", padding: "12px", display: "grid", gridTemplateColumns: "auto 1fr", gap: "8px", fontFamily: "monospace", fontSize: "12px" }, children: [ route.pathname && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#888" }, children: "pathname" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#e8e8e8" }, children: route.pathname }) ] }), route.routeName && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#888" }, children: "route" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#e8e8e8" }, children: route.routeName }) ] }), route.params && Object.keys(route.params).length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#888" }, children: "params" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#e8e8e8" }, children: JSON.stringify(route.params) }) ] }) ] } ) ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "12px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "button", { onClick: () => retry(), style: { flex: 1, padding: "12px 20px", backgroundColor: "#3b82f6", color: "white", border: "none", borderRadius: "8px", fontSize: "14px", fontWeight: 500, cursor: "pointer", transition: "background-color 0.15s" }, onMouseOver: (e) => { e.currentTarget.style.backgroundColor = "#2563eb"; }, onMouseOut: (e) => { e.currentTarget.style.backgroundColor = "#3b82f6"; }, children: "Try Again" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "button", { onClick: () => { typeof window < "u" && (window.location.href = "/"); }, style: { padding: "12px 20px", backgroundColor: "transparent", color: "#888", border: "1px solid #3a3a5a", borderRadius: "8px", fontSize: "14px", fontWeight: 500, cursor: "pointer", transition: "all 0.15s" }, onMouseOver: (e) => { e.currentTarget.style.backgroundColor = "#2a2a4a", e.currentTarget.style.color = "#e8e8e8"; }, onMouseOut: (e) => { e.currentTarget.style.backgroundColor = "transparent", e.currentTarget.style.color = "#888"; }, children: "Go Home" } ) ] }) ] }), isDev && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { style: { padding: "12px 20px", backgroundColor: "#16162a", borderTop: "1px solid #2a2a4a", fontSize: "11px", color: "#666", display: "flex", alignItems: "center", gap: "8px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "#666", strokeWidth: "2", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 16v-4" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 8h.01" }) ] } ), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [ "Press", " ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "kbd", { style: { padding: "2px 6px", backgroundColor: "#2a2a4a", borderRadius: "4px" }, children: "Alt+E" } ), " ", "to open Error Panel" ] }) ] } ) ] } ) } ); } //# sourceMappingURL=ErrorBoundary.web.js.map