@xyo-network/react-error 2.78.0 → 2.78.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,137 @@
1
- "use strict";var E=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var F=(o,r)=>{for(var e in r)E(o,e,{get:r[e],enumerable:!0})},I=(o,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of M(r))!B.call(o,n)&&n!==e&&E(o,n,{get:()=>r[n],enumerable:!(t=S(r,n))||t.enumerable});return o};var N=o=>I(E({},"__esModule",{value:!0}),o);var k={};F(k,{ErrorAlert:()=>d,ErrorRender:()=>u,ErrorReporterProvider:()=>z,ThrownErrorBoundary:()=>h,useRollbar:()=>W});module.exports=N(k);var f=require("@xyo-network/payload-model"),v=require("react");var y=require("@mui/icons-material"),i=require("@mui/material"),C=require("@xylabs/react-button"),a=require("react/jsx-runtime"),d=({onCancel:o,error:r,errorContext:e,...t})=>(0,a.jsxs)(i.Alert,{severity:"error",...t,children:[(0,a.jsx)(i.AlertTitle,{children:"Whoops! Something went wrong"}),e?(0,a.jsx)(i.Typography,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:e}):null,(0,a.jsx)(i.Typography,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),(0,a.jsx)(i.Typography,{variant:"caption",children:r?.message}),o?(0,a.jsx)(C.ButtonEx,{variant:"outlined",size:"small",onClick:o,position:"absolute",style:{right:8,top:8},children:(0,a.jsx)(y.ExitToApp,{fontSize:"small"})}):null]});var c=require("@xylabs/react-flexbox"),b=require("react"),g=require("react-router-dom");var l=require("react/jsx-runtime"),u=({onCancel:o,error:r,noErrorDisplay:e=!1,customError:t=null,children:n,errorContext:m,...x})=>{let R=(0,g.useLocation)();return(0,b.useEffect)(()=>{R.state={from:{pathname:window.location.pathname}}},[R]),r?(0,l.jsx)(c.FlexCol,{alignItems:"stretch",...x,children:e?t:(0,l.jsx)(c.FlexCol,{alignItems:"center",...x,children:(0,l.jsx)(d,{error:r,errorContext:m,onCancel:o})})}):(0,l.jsx)(l.Fragment,{children:n})??null};var P=require("react/jsx-runtime"),h=class o extends v.Component{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:o.normalizeError(r)}}static normalizeError(r){return r.schema===f.ModuleErrorSchema?r:{message:r.message,schema:f.ModuleErrorSchema,sources:[]}}componentDidCatch(r,e){let{rethrow:t,rollbar:n}=this.props,{xyoError:m}=this.state;if(n?.error(r),console.error("Error:",m,e),t)throw r}render(){let{xyoError:r}=this.state,{children:e,boundaryName:t,errorComponent:n}=this.props;return r?n?n(r):(0,P.jsx)(u,{error:r,errorContext:`${t} Boundary`}):e}};var s=require("react");var w=require("react"),p=(0,w.createContext)({});var T=require("react/jsx-runtime"),z=({children:o,rollbar:r})=>{let[e,t]=(0,s.useState)();return(0,s.useEffect)(()=>{e&&t(e)},[r,e]),(0,T.jsx)(p.Provider,{value:{rollbar:r},children:o})};var A=require("react");var W=()=>{let o=(0,A.useContext)(p);return o===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),o??{}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ErrorAlert: () => ErrorAlert,
24
+ ErrorRender: () => ErrorRender,
25
+ ErrorReporterProvider: () => ErrorReporterProvider,
26
+ ThrownErrorBoundary: () => ThrownErrorBoundary,
27
+ useRollbar: () => useRollbar
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
32
+ var import_payload_model = require("@xyo-network/payload-model");
33
+ var import_react2 = require("react");
34
+
35
+ // src/components/ErrorRender/ErrorAlert.tsx
36
+ var import_icons_material = require("@mui/icons-material");
37
+ var import_material = require("@mui/material");
38
+ var import_react_button = require("@xylabs/react-button");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Alert, { severity: "error", ...props, children: [
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.AlertTitle, { children: "Whoops! Something went wrong" }),
43
+ errorContext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
44
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
45
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", children: error?.message }),
46
+ onCancel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_button.ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons_material.ExitToApp, { fontSize: "small" }) }) : null
47
+ ] });
48
+ };
49
+
50
+ // src/components/ErrorRender/Render.tsx
51
+ var import_react_flexbox = require("@xylabs/react-flexbox");
52
+ var import_react = require("react");
53
+ var import_react_router_dom = require("react-router-dom");
54
+ var import_jsx_runtime2 = require("react/jsx-runtime");
55
+ var ErrorRender = ({
56
+ onCancel,
57
+ error,
58
+ noErrorDisplay = false,
59
+ customError = null,
60
+ children,
61
+ errorContext,
62
+ ...props
63
+ }) => {
64
+ const location = (0, import_react_router_dom.useLocation)();
65
+ (0, import_react.useEffect)(() => {
66
+ location.state = {
67
+ from: {
68
+ pathname: window.location.pathname
69
+ }
70
+ };
71
+ }, [location]);
72
+ return error ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children }) ?? null;
73
+ };
74
+
75
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
76
+ var import_jsx_runtime3 = require("react/jsx-runtime");
77
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends import_react2.Component {
78
+ state = {
79
+ xyoError: void 0
80
+ };
81
+ static getDerivedStateFromError(error) {
82
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
83
+ }
84
+ static normalizeError(error) {
85
+ return error.schema === import_payload_model.ModuleErrorSchema ? error : { message: error.message, schema: import_payload_model.ModuleErrorSchema, sources: [] };
86
+ }
87
+ componentDidCatch(error, errorInfo) {
88
+ const { rethrow, rollbar } = this.props;
89
+ const { xyoError } = this.state;
90
+ rollbar?.error(error);
91
+ console.error("Error:", xyoError, errorInfo);
92
+ if (rethrow) {
93
+ throw error;
94
+ }
95
+ }
96
+ render() {
97
+ const { xyoError } = this.state;
98
+ const { children, boundaryName, errorComponent } = this.props;
99
+ if (xyoError) {
100
+ if (errorComponent) {
101
+ return errorComponent(xyoError);
102
+ }
103
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
104
+ }
105
+ return children;
106
+ }
107
+ };
108
+
109
+ // src/contexts/ErrorReporter/Provider.tsx
110
+ var import_react4 = require("react");
111
+
112
+ // src/contexts/ErrorReporter/Context.ts
113
+ var import_react3 = require("react");
114
+ var ErrorReporterContext = (0, import_react3.createContext)({});
115
+
116
+ // src/contexts/ErrorReporter/Provider.tsx
117
+ var import_jsx_runtime4 = require("react/jsx-runtime");
118
+ var ErrorReporterProvider = ({ children, rollbar }) => {
119
+ const [rollbarInstance, setRollBarInstance] = (0, import_react4.useState)();
120
+ (0, import_react4.useEffect)(() => {
121
+ if (rollbarInstance) {
122
+ setRollBarInstance(rollbarInstance);
123
+ }
124
+ }, [rollbar, rollbarInstance]);
125
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorReporterContext.Provider, { value: { rollbar }, children });
126
+ };
127
+
128
+ // src/contexts/ErrorReporter/useRollbar.tsx
129
+ var import_react5 = require("react");
130
+ var useRollbar = () => {
131
+ const context = (0, import_react5.useContext)(ErrorReporterContext);
132
+ if (context === void 0) {
133
+ console.warn("useRollbar must be used within a ErrorReporterContext");
134
+ }
135
+ return context ?? {};
136
+ };
2
137
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,gBAAAC,EAAA,0BAAAC,EAAA,wBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAA+C,sCAC/CC,EAAgD,iBCDhD,IAAAC,EAAsC,+BACtCC,EAA0D,yBAC1DC,EAAyB,gCAWrBC,EAAA,6BAFSC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,OAE5F,QAAC,SAAM,SAAS,QAAS,GAAGA,EAC1B,oBAAC,cAAW,wCAA4B,EACvCD,KACC,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAA,EACH,EACA,QACF,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,OAAO,kBAEzD,KACA,OAAC,cAAW,QAAQ,UAAW,SAAAD,GAAO,QAAQ,EAC7CD,KACC,OAAC,YAAS,QAAQ,WAAW,KAAK,QAAQ,QAASA,EAAU,SAAS,WAAW,MAAO,CAAE,MAAO,EAAG,IAAK,CAAE,EACzG,mBAAC,EAAAI,UAAA,CAAS,SAAS,QAAQ,EAC7B,EACA,MACJ,EC7BJ,IAAAC,EAAwB,iCACxBC,EAA0B,iBAC1BC,EAA4B,4BA6BhB,IAAAC,EAAA,6BAxBCC,EAA0C,CAAC,CACtD,SAAAC,EACA,MAAAC,EACA,eAAAC,EAAiB,GACjB,YAAAC,EAAc,KACd,SAAAC,EACA,aAAAC,EACA,GAAGC,CACL,IAAM,CACJ,IAAMC,KAAW,eAAY,EAC7B,sBAAU,IAAM,CAEdA,EAAS,MAAQ,CACf,KAAM,CACJ,SAAU,OAAO,SAAS,QAC5B,CACF,CACF,EAAG,CAACA,CAAQ,CAAC,EAENN,KACH,OAAC,WAAQ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D,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,KAEtB,OAACE,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAH,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,IAAAK,EAA2B,iBAI3B,IAAMC,EAAa,IAAM,CACvB,IAAMC,KAAU,cAAWC,CAAoB,EAC/C,OAAID,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["src_exports","__export","ErrorAlert","ErrorRender","ErrorReporterProvider","ThrownErrorBoundary","useRollbar","__toCommonJS","import_payload_model","import_react","import_icons_material","import_material","import_react_button","import_jsx_runtime","ErrorAlert","onCancel","error","errorContext","props","ExitIcon","import_react_flexbox","import_react","import_react_router_dom","import_jsx_runtime","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","ErrorAlert","import_jsx_runtime","ThrownErrorBoundary","_ThrownErrorBoundary","error","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","import_react","import_react","ErrorReporterContext","import_jsx_runtime","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","ErrorReporterContext","import_react","useRollbar","context","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\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AAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,6CAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,IAAAC,gBAA2B;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,cAAU,0BAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["import_react","ExitIcon","import_jsx_runtime","import_jsx_runtime","import_react","import_react","import_jsx_runtime","import_react"]}
@@ -1,2 +1,114 @@
1
- import{ModuleErrorSchema as f}from"@xyo-network/payload-model";import{Component as w}from"react";import{ExitToApp as x}from"@mui/icons-material";import{Alert as R,AlertTitle as y,Typography as s}from"@mui/material";import{ButtonEx as C}from"@xylabs/react-button";import{jsx as a,jsxs as b}from"react/jsx-runtime";var d=({onCancel:e,error:r,errorContext:o,...t})=>b(R,{severity:"error",...t,children:[a(y,{children:"Whoops! Something went wrong"}),o?a(s,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:o}):null,a(s,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),a(s,{variant:"caption",children:r?.message}),e?a(C,{variant:"outlined",size:"small",onClick:e,position:"absolute",style:{right:8,top:8},children:a(x,{fontSize:"small"})}):null]});import{FlexCol as c}from"@xylabs/react-flexbox";import{useEffect as g}from"react";import{useLocation as v}from"react-router-dom";import{Fragment as P,jsx as i}from"react/jsx-runtime";var u=({onCancel:e,error:r,noErrorDisplay:o=!1,customError:t=null,children:n,errorContext:p,...m})=>{let E=v();return g(()=>{E.state={from:{pathname:window.location.pathname}}},[E]),r?i(c,{alignItems:"stretch",...m,children:o?t:i(c,{alignItems:"center",...m,children:i(d,{error:r,errorContext:p,onCancel:e})})}):i(P,{children:n})??null};import{jsx as T}from"react/jsx-runtime";var h=class e extends w{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:e.normalizeError(r)}}static normalizeError(r){return r.schema===f?r:{message:r.message,schema:f,sources:[]}}componentDidCatch(r,o){let{rethrow:t,rollbar:n}=this.props,{xyoError:p}=this.state;if(n?.error(r),console.error("Error:",p,o),t)throw r}render(){let{xyoError:r}=this.state,{children:o,boundaryName:t,errorComponent:n}=this.props;return r?n?n(r):T(u,{error:r,errorContext:`${t} Boundary`}):o}};import{useEffect as S,useState as M}from"react";import{createContext as A}from"react";var l=A({});import{jsx as B}from"react/jsx-runtime";var er=({children:e,rollbar:r})=>{let[o,t]=M();return S(()=>{o&&t(o)},[r,o]),B(l.Provider,{value:{rollbar:r},children:e})};import{useContext as F}from"react";var lr=()=>{let e=F(l);return e===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),e??{}};export{d as ErrorAlert,u as ErrorRender,er as ErrorReporterProvider,h as ThrownErrorBoundary,lr as useRollbar};
1
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
2
+ import { ModuleErrorSchema } from "@xyo-network/payload-model";
3
+ import { Component } from "react";
4
+
5
+ // src/components/ErrorRender/ErrorAlert.tsx
6
+ import { ExitToApp as ExitIcon } from "@mui/icons-material";
7
+ import { Alert, AlertTitle, Typography } from "@mui/material";
8
+ import { ButtonEx } from "@xylabs/react-button";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
11
+ return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
12
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Whoops! Something went wrong" }),
13
+ errorContext ? /* @__PURE__ */ jsx(Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
14
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
15
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", children: error?.message }),
16
+ onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
17
+ ] });
18
+ };
19
+
20
+ // src/components/ErrorRender/Render.tsx
21
+ import { FlexCol } from "@xylabs/react-flexbox";
22
+ import { useEffect } from "react";
23
+ import { useLocation } from "react-router-dom";
24
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
25
+ var ErrorRender = ({
26
+ onCancel,
27
+ error,
28
+ noErrorDisplay = false,
29
+ customError = null,
30
+ children,
31
+ errorContext,
32
+ ...props
33
+ }) => {
34
+ const location = useLocation();
35
+ useEffect(() => {
36
+ location.state = {
37
+ from: {
38
+ pathname: window.location.pathname
39
+ }
40
+ };
41
+ }, [location]);
42
+ return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
43
+ };
44
+
45
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
46
+ import { jsx as jsx3 } from "react/jsx-runtime";
47
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
48
+ state = {
49
+ xyoError: void 0
50
+ };
51
+ static getDerivedStateFromError(error) {
52
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
53
+ }
54
+ static normalizeError(error) {
55
+ return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
56
+ }
57
+ componentDidCatch(error, errorInfo) {
58
+ const { rethrow, rollbar } = this.props;
59
+ const { xyoError } = this.state;
60
+ rollbar?.error(error);
61
+ console.error("Error:", xyoError, errorInfo);
62
+ if (rethrow) {
63
+ throw error;
64
+ }
65
+ }
66
+ render() {
67
+ const { xyoError } = this.state;
68
+ const { children, boundaryName, errorComponent } = this.props;
69
+ if (xyoError) {
70
+ if (errorComponent) {
71
+ return errorComponent(xyoError);
72
+ }
73
+ return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
74
+ }
75
+ return children;
76
+ }
77
+ };
78
+
79
+ // src/contexts/ErrorReporter/Provider.tsx
80
+ import { useEffect as useEffect2, useState } from "react";
81
+
82
+ // src/contexts/ErrorReporter/Context.ts
83
+ import { createContext } from "react";
84
+ var ErrorReporterContext = createContext({});
85
+
86
+ // src/contexts/ErrorReporter/Provider.tsx
87
+ import { jsx as jsx4 } from "react/jsx-runtime";
88
+ var ErrorReporterProvider = ({ children, rollbar }) => {
89
+ const [rollbarInstance, setRollBarInstance] = useState();
90
+ useEffect2(() => {
91
+ if (rollbarInstance) {
92
+ setRollBarInstance(rollbarInstance);
93
+ }
94
+ }, [rollbar, rollbarInstance]);
95
+ return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
96
+ };
97
+
98
+ // src/contexts/ErrorReporter/useRollbar.tsx
99
+ import { useContext } from "react";
100
+ var useRollbar = () => {
101
+ const context = useContext(ErrorReporterContext);
102
+ if (context === void 0) {
103
+ console.warn("useRollbar must be used within a ErrorReporterContext");
104
+ }
105
+ return context ?? {};
106
+ };
107
+ export {
108
+ ErrorAlert,
109
+ ErrorRender,
110
+ ErrorReporterProvider,
111
+ ThrownErrorBoundary,
112
+ useRollbar
113
+ };
2
114
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"AAAA,OAAsB,qBAAAA,MAAyB,6BAC/C,OAAS,aAAAC,MAAuC,QCDhD,OAAS,aAAaC,MAAgB,sBACtC,OAAS,SAAAC,EAAmB,cAAAC,EAAY,cAAAC,MAAkB,gBAC1D,OAAS,YAAAC,MAAgB,uBAWrB,OACE,OAAAC,EADF,QAAAC,MAAA,oBAFG,IAAMC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,IAE5FL,EAACL,EAAA,CAAM,SAAS,QAAS,GAAGU,EAC1B,UAAAN,EAACH,EAAA,CAAW,wCAA4B,EACvCQ,EACCL,EAACF,EAAA,CAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAO,EACH,EACA,KACFL,EAACF,EAAA,CAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,OAAO,kBAEzD,EACAE,EAACF,EAAA,CAAW,QAAQ,UAAW,SAAAM,GAAO,QAAQ,EAC7CD,EACCH,EAACD,EAAA,CAAS,QAAQ,WAAW,KAAK,QAAQ,QAASI,EAAU,SAAS,WAAW,MAAO,CAAE,MAAO,EAAG,IAAK,CAAE,EACzG,SAAAH,EAACL,EAAA,CAAS,SAAS,QAAQ,EAC7B,EACA,MACJ,EC7BJ,OAAS,WAAAY,MAAe,wBACxB,OAAS,aAAAC,MAAiB,QAC1B,OAAS,eAAAC,MAAmB,mBA6BhB,OAIN,YAAAC,EAJM,OAAAC,MAAA,oBAxBL,IAAMC,EAA0C,CAAC,CACtD,SAAAC,EACA,MAAAC,EACA,eAAAC,EAAiB,GACjB,YAAAC,EAAc,KACd,SAAAC,EACA,aAAAC,EACA,GAAGC,CACL,IA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,YAAAC,MAAgB,QCDpC,OAAS,iBAAAC,MAAqB,QAIvB,IAAMC,EAAuBD,EAAyC,CAAC,CAAC,EDetE,cAAAE,MAAA,oBATT,IAAMC,GAA4E,CAAC,CAAE,SAAAC,EAAU,QAAAC,CAAQ,IAAM,CAC3G,GAAM,CAACC,EAAiBC,CAAkB,EAAIC,EAAkB,EAEhE,OAAAC,EAAU,IAAM,CACVH,GACFC,EAAmBD,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,EAEtBJ,EAACQ,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAL,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,OAAS,cAAAO,MAAkB,QAI3B,IAAMC,GAAa,IAAM,CACvB,IAAMC,EAAUC,EAAWC,CAAoB,EAC/C,OAAIF,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["ModuleErrorSchema","Component","ExitIcon","Alert","AlertTitle","Typography","ButtonEx","jsx","jsxs","ErrorAlert","onCancel","error","errorContext","props","FlexCol","useEffect","useLocation","Fragment","jsx","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","useLocation","useEffect","FlexCol","ErrorAlert","jsx","ThrownErrorBoundary","_ThrownErrorBoundary","Component","error","ModuleErrorSchema","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","useEffect","useState","createContext","ErrorReporterContext","jsx","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","useState","useEffect","ErrorReporterContext","useContext","useRollbar","context","useContext","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":";AAAA,SAAsB,yBAAyB;AAC/C,SAAS,iBAAuC;;;ACDhD,SAAS,aAAa,gBAAgB;AACtC,SAAS,OAAmB,YAAY,kBAAkB;AAC1D,SAAS,gBAAgB;AAWrB,SACE,KADF;AAFG,IAAM,aAAwC,CAAC,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,MAAM;AACpG,SACE,qBAAC,SAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,wBAAC,cAAW,0CAA4B;AAAA,IACvC,eACC,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,KAAI,SAAQ,SAC3D,wBACH,IACA;AAAA,IACF,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,IACA,oBAAC,cAAW,SAAQ,WAAW,iBAAO,SAAQ;AAAA,IAC7C,WACC,oBAAC,YAAS,SAAQ,YAAW,MAAK,SAAQ,SAAS,UAAU,UAAS,YAAW,OAAO,EAAE,OAAO,GAAG,KAAK,EAAE,GACzG,8BAAC,YAAS,UAAS,SAAQ,GAC7B,IACA;AAAA,KACJ;AAEJ;;;AC/BA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AA6BhB,SAIN,UAJM,OAAAA,YAAA;AAxBL,IAAM,cAA0C,CAAC;AAAA,EACtD;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,WAAW,YAAY;AAC7B,YAAU,MAAM;AAEd,aAAS,QAAQ;AAAA,MACf,MA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ACDpC,SAAS,qBAAqB;AAIvB,IAAM,uBAAuB,cAAyC,CAAC,CAAC;;;ADetE,gBAAAC,YAAA;AATT,IAAM,wBAA4E,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC3G,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAkB;AAEhE,EAAAC,WAAU,MAAM;AACd,QAAI,iBAAiB;AACnB,yBAAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,gBAAAD,KAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,SAAS,kBAAkB;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,UAAU,WAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["jsx","jsx","useEffect","jsx","useEffect"]}
@@ -1,2 +1,137 @@
1
- "use strict";var E=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var F=(o,r)=>{for(var e in r)E(o,e,{get:r[e],enumerable:!0})},I=(o,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of M(r))!B.call(o,n)&&n!==e&&E(o,n,{get:()=>r[n],enumerable:!(t=S(r,n))||t.enumerable});return o};var N=o=>I(E({},"__esModule",{value:!0}),o);var k={};F(k,{ErrorAlert:()=>d,ErrorRender:()=>u,ErrorReporterProvider:()=>z,ThrownErrorBoundary:()=>h,useRollbar:()=>W});module.exports=N(k);var f=require("@xyo-network/payload-model"),v=require("react");var y=require("@mui/icons-material"),i=require("@mui/material"),C=require("@xylabs/react-button"),a=require("react/jsx-runtime"),d=({onCancel:o,error:r,errorContext:e,...t})=>(0,a.jsxs)(i.Alert,{severity:"error",...t,children:[(0,a.jsx)(i.AlertTitle,{children:"Whoops! Something went wrong"}),e?(0,a.jsx)(i.Typography,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:e}):null,(0,a.jsx)(i.Typography,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),(0,a.jsx)(i.Typography,{variant:"caption",children:r?.message}),o?(0,a.jsx)(C.ButtonEx,{variant:"outlined",size:"small",onClick:o,position:"absolute",style:{right:8,top:8},children:(0,a.jsx)(y.ExitToApp,{fontSize:"small"})}):null]});var c=require("@xylabs/react-flexbox"),b=require("react"),g=require("react-router-dom");var l=require("react/jsx-runtime"),u=({onCancel:o,error:r,noErrorDisplay:e=!1,customError:t=null,children:n,errorContext:m,...x})=>{let R=(0,g.useLocation)();return(0,b.useEffect)(()=>{R.state={from:{pathname:window.location.pathname}}},[R]),r?(0,l.jsx)(c.FlexCol,{alignItems:"stretch",...x,children:e?t:(0,l.jsx)(c.FlexCol,{alignItems:"center",...x,children:(0,l.jsx)(d,{error:r,errorContext:m,onCancel:o})})}):(0,l.jsx)(l.Fragment,{children:n})??null};var P=require("react/jsx-runtime"),h=class o extends v.Component{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:o.normalizeError(r)}}static normalizeError(r){return r.schema===f.ModuleErrorSchema?r:{message:r.message,schema:f.ModuleErrorSchema,sources:[]}}componentDidCatch(r,e){let{rethrow:t,rollbar:n}=this.props,{xyoError:m}=this.state;if(n?.error(r),console.error("Error:",m,e),t)throw r}render(){let{xyoError:r}=this.state,{children:e,boundaryName:t,errorComponent:n}=this.props;return r?n?n(r):(0,P.jsx)(u,{error:r,errorContext:`${t} Boundary`}):e}};var s=require("react");var w=require("react"),p=(0,w.createContext)({});var T=require("react/jsx-runtime"),z=({children:o,rollbar:r})=>{let[e,t]=(0,s.useState)();return(0,s.useEffect)(()=>{e&&t(e)},[r,e]),(0,T.jsx)(p.Provider,{value:{rollbar:r},children:o})};var A=require("react");var W=()=>{let o=(0,A.useContext)(p);return o===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),o??{}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ErrorAlert: () => ErrorAlert,
24
+ ErrorRender: () => ErrorRender,
25
+ ErrorReporterProvider: () => ErrorReporterProvider,
26
+ ThrownErrorBoundary: () => ThrownErrorBoundary,
27
+ useRollbar: () => useRollbar
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
32
+ var import_payload_model = require("@xyo-network/payload-model");
33
+ var import_react2 = require("react");
34
+
35
+ // src/components/ErrorRender/ErrorAlert.tsx
36
+ var import_icons_material = require("@mui/icons-material");
37
+ var import_material = require("@mui/material");
38
+ var import_react_button = require("@xylabs/react-button");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Alert, { severity: "error", ...props, children: [
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.AlertTitle, { children: "Whoops! Something went wrong" }),
43
+ errorContext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
44
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
45
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", children: error?.message }),
46
+ onCancel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_button.ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons_material.ExitToApp, { fontSize: "small" }) }) : null
47
+ ] });
48
+ };
49
+
50
+ // src/components/ErrorRender/Render.tsx
51
+ var import_react_flexbox = require("@xylabs/react-flexbox");
52
+ var import_react = require("react");
53
+ var import_react_router_dom = require("react-router-dom");
54
+ var import_jsx_runtime2 = require("react/jsx-runtime");
55
+ var ErrorRender = ({
56
+ onCancel,
57
+ error,
58
+ noErrorDisplay = false,
59
+ customError = null,
60
+ children,
61
+ errorContext,
62
+ ...props
63
+ }) => {
64
+ const location = (0, import_react_router_dom.useLocation)();
65
+ (0, import_react.useEffect)(() => {
66
+ location.state = {
67
+ from: {
68
+ pathname: window.location.pathname
69
+ }
70
+ };
71
+ }, [location]);
72
+ return error ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children }) ?? null;
73
+ };
74
+
75
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
76
+ var import_jsx_runtime3 = require("react/jsx-runtime");
77
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends import_react2.Component {
78
+ state = {
79
+ xyoError: void 0
80
+ };
81
+ static getDerivedStateFromError(error) {
82
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
83
+ }
84
+ static normalizeError(error) {
85
+ return error.schema === import_payload_model.ModuleErrorSchema ? error : { message: error.message, schema: import_payload_model.ModuleErrorSchema, sources: [] };
86
+ }
87
+ componentDidCatch(error, errorInfo) {
88
+ const { rethrow, rollbar } = this.props;
89
+ const { xyoError } = this.state;
90
+ rollbar?.error(error);
91
+ console.error("Error:", xyoError, errorInfo);
92
+ if (rethrow) {
93
+ throw error;
94
+ }
95
+ }
96
+ render() {
97
+ const { xyoError } = this.state;
98
+ const { children, boundaryName, errorComponent } = this.props;
99
+ if (xyoError) {
100
+ if (errorComponent) {
101
+ return errorComponent(xyoError);
102
+ }
103
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
104
+ }
105
+ return children;
106
+ }
107
+ };
108
+
109
+ // src/contexts/ErrorReporter/Provider.tsx
110
+ var import_react4 = require("react");
111
+
112
+ // src/contexts/ErrorReporter/Context.ts
113
+ var import_react3 = require("react");
114
+ var ErrorReporterContext = (0, import_react3.createContext)({});
115
+
116
+ // src/contexts/ErrorReporter/Provider.tsx
117
+ var import_jsx_runtime4 = require("react/jsx-runtime");
118
+ var ErrorReporterProvider = ({ children, rollbar }) => {
119
+ const [rollbarInstance, setRollBarInstance] = (0, import_react4.useState)();
120
+ (0, import_react4.useEffect)(() => {
121
+ if (rollbarInstance) {
122
+ setRollBarInstance(rollbarInstance);
123
+ }
124
+ }, [rollbar, rollbarInstance]);
125
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorReporterContext.Provider, { value: { rollbar }, children });
126
+ };
127
+
128
+ // src/contexts/ErrorReporter/useRollbar.tsx
129
+ var import_react5 = require("react");
130
+ var useRollbar = () => {
131
+ const context = (0, import_react5.useContext)(ErrorReporterContext);
132
+ if (context === void 0) {
133
+ console.warn("useRollbar must be used within a ErrorReporterContext");
134
+ }
135
+ return context ?? {};
136
+ };
2
137
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,gBAAAC,EAAA,0BAAAC,EAAA,wBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAA+C,sCAC/CC,EAAgD,iBCDhD,IAAAC,EAAsC,+BACtCC,EAA0D,yBAC1DC,EAAyB,gCAWrBC,EAAA,6BAFSC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,OAE5F,QAAC,SAAM,SAAS,QAAS,GAAGA,EAC1B,oBAAC,cAAW,wCAA4B,EACvCD,KACC,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAA,EACH,EACA,QACF,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,OAAO,kBAEzD,KACA,OAAC,cAAW,QAAQ,UAAW,SAAAD,GAAO,QAAQ,EAC7CD,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AQ,MAAM,SAAUI,EAAUH,CAAS,EACvCC,EACF,MAAMF,CAEV,CAES,QAAS,CAChB,GAAM,CAAE,SAAAI,CAAS,EAAI,KAAK,MACpB,CAAE,SAAAC,EAAU,aAAAC,EAAc,eAAAC,CAAe,EAAI,KAAK,MACxD,OAAIH,EACEG,EACKA,EAAeH,CAAQ,KAEzB,OAACI,EAAA,CAAY,MAAOJ,EAAU,aAAc,GAAGE,CAAY,YAAa,EAG1ED,CACT,CACF,EGzDA,IAAAI,EAAoC,iBCDpC,IAAAC,EAA8B,iBAIjBC,KAAuB,iBAAyC,CAAC,CAAC,EDetE,IAAAC,EAAA,6BATHC,EAA4E,CAAC,CAAE,SAAAC,EAAU,QAAAC,CAAQ,IAAM,CAC3G,GAAM,CAACC,EAAiBC,CAAkB,KAAI,YAAkB,EAEhE,sBAAU,IAAM,CACVD,GACFC,EAAmBD,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,KAEtB,OAACE,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAH,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,IAAAK,EAA2B,iBAI3B,IAAMC,EAAa,IAAM,CACvB,IAAMC,KAAU,cAAWC,CAAoB,EAC/C,OAAID,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["src_exports","__export","ErrorAlert","ErrorRender","ErrorReporterProvider","ThrownErrorBoundary","useRollbar","__toCommonJS","import_payload_model","import_react","import_icons_material","import_material","import_react_button","import_jsx_runtime","ErrorAlert","onCancel","error","errorContext","props","ExitIcon","import_react_flexbox","import_react","import_react_router_dom","import_jsx_runtime","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","ErrorAlert","import_jsx_runtime","ThrownErrorBoundary","_ThrownErrorBoundary","error","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","import_react","import_react","ErrorReporterContext","import_jsx_runtime","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","ErrorReporterContext","import_react","useRollbar","context","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAA+C;AAC/C,IAAAA,gBAAgD;;;ACDhD,4BAAsC;AACtC,sBAA0D;AAC1D,0BAAyB;AAWrB;AAFG,IAAM,aAAwC,CAAC,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,MAAM;AACpG,SACE,6CAAC,yBAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,gDAAC,8BAAW,0CAA4B;AAAA,IACvC,eACC,4CAAC,8BAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,KAAI,SAAQ,SAC3D,wBACH,IACA;AAAA,IACF,4CAAC,8BAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,IACA,4CAAC,8BAAW,SAAQ,WAAW,iBAAO,SAAQ;AAAA,IAC7C,WACC,4CAAC,gCAAS,SAAQ,YAAW,MAAK,SAAQ,SAAS,UAAU,UAAS,YAAW,OAAO,EAAE,OAAO,GAAG,KAAK,EAAE,GACzG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F;AAAA,EAES,SAAS;AAChB,UAAM,EAAE,SAAS,IAAI,KAAK;AAC1B,UAAM,EAAE,UAAU,cAAc,eAAe,IAAI,KAAK;AACxD,QAAI,UAAU;AACZ,UAAI,gBAAgB;AAClB,eAAO,eAAe,QAAQ;AAAA,MAChC;AACA,aAAO,6CAAC,eAAY,OAAO,UAAU,cAAc,GAAG,YAAY,aAAa;AAAA,IACjF;AAEA,WAAO;AAAA,EACT;AACF;;;AGzDA,IAAAC,gBAAoC;;;ACDpC,IAAAC,gBAA8B;AAIvB,IAAM,2BAAuB,6BAAyC,CAAC,CAAC;;;ADetE,IAAAC,sBAAA;AATT,IAAM,wBAA4E,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC3G,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,wBAAkB;AAEhE,+BAAU,MAAM;AACd,QAAI,iBAAiB;AACnB,yBAAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,6CAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,IAAAC,gBAA2B;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,cAAU,0BAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["import_react","ExitIcon","import_jsx_runtime","import_jsx_runtime","import_react","import_react","import_jsx_runtime","import_react"]}
@@ -1,2 +1,114 @@
1
- import{ModuleErrorSchema as f}from"@xyo-network/payload-model";import{Component as w}from"react";import{ExitToApp as x}from"@mui/icons-material";import{Alert as R,AlertTitle as y,Typography as s}from"@mui/material";import{ButtonEx as C}from"@xylabs/react-button";import{jsx as a,jsxs as b}from"react/jsx-runtime";var d=({onCancel:e,error:r,errorContext:o,...t})=>b(R,{severity:"error",...t,children:[a(y,{children:"Whoops! Something went wrong"}),o?a(s,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:o}):null,a(s,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),a(s,{variant:"caption",children:r?.message}),e?a(C,{variant:"outlined",size:"small",onClick:e,position:"absolute",style:{right:8,top:8},children:a(x,{fontSize:"small"})}):null]});import{FlexCol as c}from"@xylabs/react-flexbox";import{useEffect as g}from"react";import{useLocation as v}from"react-router-dom";import{Fragment as P,jsx as i}from"react/jsx-runtime";var u=({onCancel:e,error:r,noErrorDisplay:o=!1,customError:t=null,children:n,errorContext:p,...m})=>{let E=v();return g(()=>{E.state={from:{pathname:window.location.pathname}}},[E]),r?i(c,{alignItems:"stretch",...m,children:o?t:i(c,{alignItems:"center",...m,children:i(d,{error:r,errorContext:p,onCancel:e})})}):i(P,{children:n})??null};import{jsx as T}from"react/jsx-runtime";var h=class e extends w{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:e.normalizeError(r)}}static normalizeError(r){return r.schema===f?r:{message:r.message,schema:f,sources:[]}}componentDidCatch(r,o){let{rethrow:t,rollbar:n}=this.props,{xyoError:p}=this.state;if(n?.error(r),console.error("Error:",p,o),t)throw r}render(){let{xyoError:r}=this.state,{children:o,boundaryName:t,errorComponent:n}=this.props;return r?n?n(r):T(u,{error:r,errorContext:`${t} Boundary`}):o}};import{useEffect as S,useState as M}from"react";import{createContext as A}from"react";var l=A({});import{jsx as B}from"react/jsx-runtime";var er=({children:e,rollbar:r})=>{let[o,t]=M();return S(()=>{o&&t(o)},[r,o]),B(l.Provider,{value:{rollbar:r},children:e})};import{useContext as F}from"react";var lr=()=>{let e=F(l);return e===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),e??{}};export{d as ErrorAlert,u as ErrorRender,er as ErrorReporterProvider,h as ThrownErrorBoundary,lr as useRollbar};
1
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
2
+ import { ModuleErrorSchema } from "@xyo-network/payload-model";
3
+ import { Component } from "react";
4
+
5
+ // src/components/ErrorRender/ErrorAlert.tsx
6
+ import { ExitToApp as ExitIcon } from "@mui/icons-material";
7
+ import { Alert, AlertTitle, Typography } from "@mui/material";
8
+ import { ButtonEx } from "@xylabs/react-button";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
11
+ return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
12
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Whoops! Something went wrong" }),
13
+ errorContext ? /* @__PURE__ */ jsx(Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
14
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
15
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", children: error?.message }),
16
+ onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
17
+ ] });
18
+ };
19
+
20
+ // src/components/ErrorRender/Render.tsx
21
+ import { FlexCol } from "@xylabs/react-flexbox";
22
+ import { useEffect } from "react";
23
+ import { useLocation } from "react-router-dom";
24
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
25
+ var ErrorRender = ({
26
+ onCancel,
27
+ error,
28
+ noErrorDisplay = false,
29
+ customError = null,
30
+ children,
31
+ errorContext,
32
+ ...props
33
+ }) => {
34
+ const location = useLocation();
35
+ useEffect(() => {
36
+ location.state = {
37
+ from: {
38
+ pathname: window.location.pathname
39
+ }
40
+ };
41
+ }, [location]);
42
+ return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
43
+ };
44
+
45
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
46
+ import { jsx as jsx3 } from "react/jsx-runtime";
47
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
48
+ state = {
49
+ xyoError: void 0
50
+ };
51
+ static getDerivedStateFromError(error) {
52
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
53
+ }
54
+ static normalizeError(error) {
55
+ return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
56
+ }
57
+ componentDidCatch(error, errorInfo) {
58
+ const { rethrow, rollbar } = this.props;
59
+ const { xyoError } = this.state;
60
+ rollbar?.error(error);
61
+ console.error("Error:", xyoError, errorInfo);
62
+ if (rethrow) {
63
+ throw error;
64
+ }
65
+ }
66
+ render() {
67
+ const { xyoError } = this.state;
68
+ const { children, boundaryName, errorComponent } = this.props;
69
+ if (xyoError) {
70
+ if (errorComponent) {
71
+ return errorComponent(xyoError);
72
+ }
73
+ return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
74
+ }
75
+ return children;
76
+ }
77
+ };
78
+
79
+ // src/contexts/ErrorReporter/Provider.tsx
80
+ import { useEffect as useEffect2, useState } from "react";
81
+
82
+ // src/contexts/ErrorReporter/Context.ts
83
+ import { createContext } from "react";
84
+ var ErrorReporterContext = createContext({});
85
+
86
+ // src/contexts/ErrorReporter/Provider.tsx
87
+ import { jsx as jsx4 } from "react/jsx-runtime";
88
+ var ErrorReporterProvider = ({ children, rollbar }) => {
89
+ const [rollbarInstance, setRollBarInstance] = useState();
90
+ useEffect2(() => {
91
+ if (rollbarInstance) {
92
+ setRollBarInstance(rollbarInstance);
93
+ }
94
+ }, [rollbar, rollbarInstance]);
95
+ return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
96
+ };
97
+
98
+ // src/contexts/ErrorReporter/useRollbar.tsx
99
+ import { useContext } from "react";
100
+ var useRollbar = () => {
101
+ const context = useContext(ErrorReporterContext);
102
+ if (context === void 0) {
103
+ console.warn("useRollbar must be used within a ErrorReporterContext");
104
+ }
105
+ return context ?? {};
106
+ };
107
+ export {
108
+ ErrorAlert,
109
+ ErrorRender,
110
+ ErrorReporterProvider,
111
+ ThrownErrorBoundary,
112
+ useRollbar
113
+ };
2
114
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"AAAA,OAAsB,qBAAAA,MAAyB,6BAC/C,OAAS,aAAAC,MAAuC,QCDhD,OAAS,aAAaC,MAAgB,sBACtC,OAAS,SAAAC,EAAmB,cAAAC,EAAY,cAAAC,MAAkB,gBAC1D,OAAS,YAAAC,MAAgB,uBAWrB,OACE,OAAAC,EADF,QAAAC,MAAA,oBAFG,IAAMC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,IAE5FL,EAACL,EAAA,CAAM,SAAS,QAAS,GAAGU,EAC1B,UAAAN,EAACH,EAAA,CAAW,wCAA4B,EACvCQ,EACCL,EAACF,EAAA,CAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAO,EACH,EACA,KACFL,EAACF,EAAA,CAAW,Q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EAAM,QAAS,OAAQC,EAAmB,QAAS,CAAC,CAAE,CACvE,CAES,kBAAkBD,EAAcE,EAAsB,CAC7D,GAAM,CAAE,QAAAC,EAAS,QAAAC,CAAQ,EAAI,KAAK,MAC5B,CAAE,SAAAC,CAAS,EAAI,KAAK,MAK1B,GAHAD,GAAS,MAAMJ,CAAK,EAEpB,QAAQ,MAAM,SAAUK,EAAUH,CAAS,EACvCC,EACF,MAAMH,CAEV,CAES,QAAS,CAChB,GAAM,CAAE,SAAAK,CAAS,EAAI,KAAK,MACpB,CAAE,SAAAC,EAAU,aAAAC,EAAc,eAAAC,CAAe,EAAI,KAAK,MACxD,OAAIH,EACEG,EACKA,EAAeH,CAAQ,EAEzBT,EAACa,EAAA,CAAY,MAAOJ,EAAU,aAAc,GAAGE,CAAY,YAAa,EAG1ED,CACT,CACF,EGzDA,OAAS,aAAAI,EAAW,YAAAC,MAAgB,QCDpC,OAAS,iBAAAC,MAAqB,QAIvB,IAAMC,EAAuBD,EAAyC,CAAC,CAAC,EDetE,cAAAE,MAAA,oBATT,IAAMC,GAA4E,CAAC,CAAE,SAAAC,EAAU,QAAAC,CAAQ,IAAM,CAC3G,GAAM,CAACC,EAAiBC,CAAkB,EAAIC,EAAkB,EAEhE,OAAAC,EAAU,IAAM,CACVH,GACFC,EAAmBD,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,EAEtBJ,EAACQ,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAL,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,OAAS,cAAAO,MAAkB,QAI3B,IAAMC,GAAa,IAAM,CACvB,IAAMC,EAAUC,EAAWC,CAAoB,EAC/C,OAAIF,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["ModuleErrorSchema","Component","ExitIcon","Alert","AlertTitle","Typography","ButtonEx","jsx","jsxs","ErrorAlert","onCancel","error","errorContext","props","FlexCol","useEffect","useLocation","Fragment","jsx","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","useLocation","useEffect","FlexCol","ErrorAlert","jsx","ThrownErrorBoundary","_ThrownErrorBoundary","Component","error","ModuleErrorSchema","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","useEffect","useState","createContext","ErrorReporterContext","jsx","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","useState","useEffect","ErrorReporterContext","useContext","useRollbar","context","useContext","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":";AAAA,SAAsB,yBAAyB;AAC/C,SAAS,iBAAuC;;;ACDhD,SAAS,aAAa,gBAAgB;AACtC,SAAS,OAAmB,YAAY,kBAAkB;AAC1D,SAAS,gBAAgB;AAWrB,SACE,KADF;AAFG,IAAM,aAAwC,CAAC,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,MAAM;AACpG,SACE,qBAAC,SAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,wBAAC,cAAW,0CAA4B;AAAA,IACvC,eACC,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,KAAI,SAAQ,SAC3D,wBACH,IACA;AAAA,IACF,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEz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ES,kBAAkB,OAAc,WAAsB;AAC7D,UAAM,EAAE,SAAS,QAAQ,IAAI,KAAK;AAClC,UAAM,EAAE,SAAS,IAAI,KAAK;AAE1B,aAAS,MAAM,KAAK;AAEpB,YAAQ,MAAM,UAAU,UAAU,SAAS;AAC3C,QAAI,SAAS;AACX,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAES,SAAS;AAChB,UAAM,EAAE,SAAS,IAAI,KAAK;AAC1B,UAAM,EAAE,UAAU,cAAc,eAAe,IAAI,KAAK;AACxD,QAAI,UAAU;AACZ,UAAI,gBAAgB;AAClB,eAAO,eAAe,QAAQ;AAAA,MAChC;AACA,aAAO,gBAAAA,KAAC,eAAY,OAAO,UAAU,cAAc,GAAG,YAAY,aAAa;AAAA,IACjF;AAEA,WAAO;AAAA,EACT;AACF;;;AGzDA,SAAS,aAAAC,YAAW,gBAAgB;;;ACDpC,SAAS,qBAAqB;AAIvB,IAAM,uBAAuB,cAAyC,CAAC,CAAC;;;ADetE,gBAAAC,YAAA;AATT,IAAM,wBAA4E,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC3G,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAkB;AAEhE,EAAAC,WAAU,MAAM;AACd,QAAI,iBAAiB;AACnB,yBAAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,gBAAAD,KAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,SAAS,kBAAkB;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,UAAU,WAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["jsx","jsx","useEffect","jsx","useEffect"]}
@@ -1,2 +1,145 @@
1
- "use strict";var E=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var F=(o,r)=>{for(var e in r)E(o,e,{get:r[e],enumerable:!0})},I=(o,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of M(r))!B.call(o,t)&&t!==e&&E(o,t,{get:()=>r[t],enumerable:!(n=S(r,t))||n.enumerable});return o};var N=o=>I(E({},"__esModule",{value:!0}),o);var k={};F(k,{ErrorAlert:()=>d,ErrorRender:()=>u,ErrorReporterProvider:()=>z,ThrownErrorBoundary:()=>h,useRollbar:()=>W});module.exports=N(k);var f=require("@xyo-network/payload-model"),v=require("react");var y=require("@mui/icons-material"),i=require("@mui/material"),C=require("@xylabs/react-button"),a=require("react/jsx-runtime"),d=({onCancel:o,error:r,errorContext:e,...n})=>(0,a.jsxs)(i.Alert,{severity:"error",...n,children:[(0,a.jsx)(i.AlertTitle,{children:"Whoops! Something went wrong"}),e?(0,a.jsx)(i.Typography,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:e}):null,(0,a.jsx)(i.Typography,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),(0,a.jsx)(i.Typography,{variant:"caption",children:r==null?void 0:r.message}),o?(0,a.jsx)(C.ButtonEx,{variant:"outlined",size:"small",onClick:o,position:"absolute",style:{right:8,top:8},children:(0,a.jsx)(y.ExitToApp,{fontSize:"small"})}):null]});var c=require("@xylabs/react-flexbox"),g=require("react"),b=require("react-router-dom");var l=require("react/jsx-runtime"),u=({onCancel:o,error:r,noErrorDisplay:e=!1,customError:n=null,children:t,errorContext:m,...x})=>{let R=(0,b.useLocation)();return(0,g.useEffect)(()=>{R.state={from:{pathname:window.location.pathname}}},[R]),r?(0,l.jsx)(c.FlexCol,{alignItems:"stretch",...x,children:e?n:(0,l.jsx)(c.FlexCol,{alignItems:"center",...x,children:(0,l.jsx)(d,{error:r,errorContext:m,onCancel:o})})}):(0,l.jsx)(l.Fragment,{children:t})??null};var P=require("react/jsx-runtime"),h=class o extends v.Component{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:o.normalizeError(r)}}static normalizeError(r){return r.schema===f.ModuleErrorSchema?r:{message:r.message,schema:f.ModuleErrorSchema,sources:[]}}componentDidCatch(r,e){let{rethrow:n,rollbar:t}=this.props,{xyoError:m}=this.state;if(t==null||t.error(r),console.error("Error:",m,e),n)throw r}render(){let{xyoError:r}=this.state,{children:e,boundaryName:n,errorComponent:t}=this.props;return r?t?t(r):(0,P.jsx)(u,{error:r,errorContext:`${n} Boundary`}):e}};var s=require("react");var w=require("react"),p=(0,w.createContext)({});var T=require("react/jsx-runtime"),z=({children:o,rollbar:r})=>{let[e,n]=(0,s.useState)();return(0,s.useEffect)(()=>{e&&n(e)},[r,e]),(0,T.jsx)(p.Provider,{value:{rollbar:r},children:o})};var A=require("react");var W=()=>{let o=(0,A.useContext)(p);return o===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),o??{}};0&&(module.exports={ErrorAlert,ErrorRender,ErrorReporterProvider,ThrownErrorBoundary,useRollbar});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ErrorAlert: () => ErrorAlert,
24
+ ErrorRender: () => ErrorRender,
25
+ ErrorReporterProvider: () => ErrorReporterProvider,
26
+ ThrownErrorBoundary: () => ThrownErrorBoundary,
27
+ useRollbar: () => useRollbar
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
32
+ var import_payload_model = require("@xyo-network/payload-model");
33
+ var import_react2 = require("react");
34
+
35
+ // src/components/ErrorRender/ErrorAlert.tsx
36
+ var import_icons_material = require("@mui/icons-material");
37
+ var import_material = require("@mui/material");
38
+ var import_react_button = require("@xylabs/react-button");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Alert, { severity: "error", ...props, children: [
42
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.AlertTitle, { children: "Whoops! Something went wrong" }),
43
+ errorContext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
44
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
45
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", children: error == null ? void 0 : error.message }),
46
+ onCancel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_button.ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons_material.ExitToApp, { fontSize: "small" }) }) : null
47
+ ] });
48
+ };
49
+
50
+ // src/components/ErrorRender/Render.tsx
51
+ var import_react_flexbox = require("@xylabs/react-flexbox");
52
+ var import_react = require("react");
53
+ var import_react_router_dom = require("react-router-dom");
54
+ var import_jsx_runtime2 = require("react/jsx-runtime");
55
+ var ErrorRender = ({
56
+ onCancel,
57
+ error,
58
+ noErrorDisplay = false,
59
+ customError = null,
60
+ children,
61
+ errorContext,
62
+ ...props
63
+ }) => {
64
+ const location = (0, import_react_router_dom.useLocation)();
65
+ (0, import_react.useEffect)(() => {
66
+ location.state = {
67
+ from: {
68
+ pathname: window.location.pathname
69
+ }
70
+ };
71
+ }, [location]);
72
+ return error ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_flexbox.FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children }) ?? null;
73
+ };
74
+
75
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
76
+ var import_jsx_runtime3 = require("react/jsx-runtime");
77
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends import_react2.Component {
78
+ state = {
79
+ xyoError: void 0
80
+ };
81
+ static getDerivedStateFromError(error) {
82
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
83
+ }
84
+ static normalizeError(error) {
85
+ return error.schema === import_payload_model.ModuleErrorSchema ? error : { message: error.message, schema: import_payload_model.ModuleErrorSchema, sources: [] };
86
+ }
87
+ componentDidCatch(error, errorInfo) {
88
+ const { rethrow, rollbar } = this.props;
89
+ const { xyoError } = this.state;
90
+ rollbar == null ? void 0 : rollbar.error(error);
91
+ console.error("Error:", xyoError, errorInfo);
92
+ if (rethrow) {
93
+ throw error;
94
+ }
95
+ }
96
+ render() {
97
+ const { xyoError } = this.state;
98
+ const { children, boundaryName, errorComponent } = this.props;
99
+ if (xyoError) {
100
+ if (errorComponent) {
101
+ return errorComponent(xyoError);
102
+ }
103
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
104
+ }
105
+ return children;
106
+ }
107
+ };
108
+
109
+ // src/contexts/ErrorReporter/Provider.tsx
110
+ var import_react4 = require("react");
111
+
112
+ // src/contexts/ErrorReporter/Context.ts
113
+ var import_react3 = require("react");
114
+ var ErrorReporterContext = (0, import_react3.createContext)({});
115
+
116
+ // src/contexts/ErrorReporter/Provider.tsx
117
+ var import_jsx_runtime4 = require("react/jsx-runtime");
118
+ var ErrorReporterProvider = ({ children, rollbar }) => {
119
+ const [rollbarInstance, setRollBarInstance] = (0, import_react4.useState)();
120
+ (0, import_react4.useEffect)(() => {
121
+ if (rollbarInstance) {
122
+ setRollBarInstance(rollbarInstance);
123
+ }
124
+ }, [rollbar, rollbarInstance]);
125
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorReporterContext.Provider, { value: { rollbar }, children });
126
+ };
127
+
128
+ // src/contexts/ErrorReporter/useRollbar.tsx
129
+ var import_react5 = require("react");
130
+ var useRollbar = () => {
131
+ const context = (0, import_react5.useContext)(ErrorReporterContext);
132
+ if (context === void 0) {
133
+ console.warn("useRollbar must be used within a ErrorReporterContext");
134
+ }
135
+ return context ?? {};
136
+ };
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ ErrorAlert,
140
+ ErrorRender,
141
+ ErrorReporterProvider,
142
+ ThrownErrorBoundary,
143
+ useRollbar
144
+ });
2
145
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,gBAAAC,EAAA,0BAAAC,EAAA,wBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAA+C,sCAC/CC,EAAgD,iBCDhD,IAAAC,EAAsC,+BACtCC,EAA0D,yBAC1DC,EAAyB,gCAWrBC,EAAA,6BAFSC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,OAE5F,QAAC,SAAM,SAAS,QAAS,GAAGA,EAC1B,oBAAC,cAAW,wCAA4B,EACvCD,KACC,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAA,EACH,EACA,QACF,OAAC,cAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,OAAO,kBAEzD,KACA,OAAC,cAAW,QAAQ,UAAW,SAAAD,GAAA,YAAAA,EAAO,QAAQ,EAC7CD,KACC,OAAC,YAAS,QAAQ,WAAW,KAAK,QAAQ,QAASA,EAAU,SAAS,WAAW,MAAO,CAAE,MAAO,EAAG,IAAK,CAAE,EACzG,mBAAC,EAAAI,UAAA,CAAS,SAAS,QAAQ,EAC7B,EACA,MACJ,EC7BJ,IAAAC,EAAwB,iCACxBC,EAA0B,iBAC1BC,EAA4B,4BA6BhB,IAAAC,EAAA,6BAxBCC,EAA0C,CAAC,CACtD,SAAAC,EACA,MAAAC,EACA,eAAAC,EAAiB,GACjB,YAAAC,EAAc,KACd,SAAAC,EACA,aAAAC,EACA,GAAGC,CACL,IAAM,CACJ,IAAMC,KAAW,eAAY,EAC7B,sBAAU,IAAM,CAEdA,E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AAC,EAAU,QAAAC,CAAQ,IAAM,CAC3G,GAAM,CAACC,EAAiBC,CAAkB,KAAI,YAAkB,EAEhE,sBAAU,IAAM,CACVD,GACFC,EAAmBD,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,KAEtB,OAACE,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAH,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,IAAAK,EAA2B,iBAI3B,IAAMC,EAAa,IAAM,CACvB,IAAMC,KAAU,cAAWC,CAAoB,EAC/C,OAAID,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["src_exports","__export","ErrorAlert","ErrorRender","ErrorReporterProvider","ThrownErrorBoundary","useRollbar","__toCommonJS","import_payload_model","import_react","import_icons_material","import_material","import_react_button","import_jsx_runtime","ErrorAlert","onCancel","error","errorContext","props","ExitIcon","import_react_flexbox","import_react","import_react_router_dom","import_jsx_runtime","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","ErrorAlert","import_jsx_runtime","ThrownErrorBoundary","_ThrownErrorBoundary","error","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","import_react","import_react","ErrorReporterContext","import_jsx_runtime","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","ErrorReporterContext","import_react","useRollbar","context","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\n","import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAA+C;AAC/C,IAAAA,gBAAgD;;;ACDhD,4BAAsC;AACtC,sBAA0D;AAC1D,0BAAyB;AAWrB;AAFG,IAAM,aAAwC,CAAC,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,MAAM;AACpG,SACE,6CAAC,yBAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,gDAAC,8BAAW,0CAA4B;AAAA,IACvC,eACC,4CAAC,8BAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,KAAI,SAAQ,SAC3D,wBACH,IACA;AAAA,IACF,4CAAC,8BAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,IACA,4CAAC,8BAAW,SAAQ,WAAW,yCAAO,SAAQ;AAAA,IAC7C,WACC,4CAAC,gCAAS,SAAQ,YAAW,MAAK,SAAQ,SAAS,UAAU,UAAS,YAAW,OAAO,EAAE,OAAO,GAAG,KAAK,EAAE,GACzG,sDAAC,sBAAAC,WAAA,EAAS,UAAS,SAAQ,GAC7B,IACA;AAAA,KACJ;AAEJ;;;AC/BA,2BAAwB;AACxB,mBAA0B;AAC1B,8BAA4B;AA6BhB,IAAAC,sBAAA;AAxBL,IAAM,cAA0C,CAAC;AAAA,EACtD;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,eAAW,qCAAY;AAC7B,8BAAU,MAAM;AAEd,aAAS,QAAQ;AAAA,MACf,MAAM;AAAA,QACJ,UAAU,OAAO,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,EACF,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QAAQ,MAAM;AAC3G,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,wBAAkB;AAEhE,+BAAU,MAAM;AACd,QAAI,iBAAiB;AACnB,yBAAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,6CAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,IAAAC,gBAA2B;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,cAAU,0BAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["import_react","ExitIcon","import_jsx_runtime","import_jsx_runtime","import_react","import_react","import_jsx_runtime","import_react"]}
@@ -1,2 +1,114 @@
1
- import{ModuleErrorSchema as f}from"@xyo-network/payload-model";import{Component as w}from"react";import{ExitToApp as x}from"@mui/icons-material";import{Alert as R,AlertTitle as y,Typography as s}from"@mui/material";import{ButtonEx as C}from"@xylabs/react-button";import{jsx as a,jsxs as g}from"react/jsx-runtime";var d=({onCancel:e,error:r,errorContext:o,...t})=>g(R,{severity:"error",...t,children:[a(y,{children:"Whoops! Something went wrong"}),o?a(s,{variant:"caption",my:.5,lineHeight:"1",display:"block",children:o}):null,a(s,{variant:"caption",mr:.5,fontWeight:"bold",children:"Error:"}),a(s,{variant:"caption",children:r==null?void 0:r.message}),e?a(C,{variant:"outlined",size:"small",onClick:e,position:"absolute",style:{right:8,top:8},children:a(x,{fontSize:"small"})}):null]});import{FlexCol as c}from"@xylabs/react-flexbox";import{useEffect as b}from"react";import{useLocation as v}from"react-router-dom";import{Fragment as P,jsx as i}from"react/jsx-runtime";var u=({onCancel:e,error:r,noErrorDisplay:o=!1,customError:t=null,children:n,errorContext:p,...m})=>{let E=v();return b(()=>{E.state={from:{pathname:window.location.pathname}}},[E]),r?i(c,{alignItems:"stretch",...m,children:o?t:i(c,{alignItems:"center",...m,children:i(d,{error:r,errorContext:p,onCancel:e})})}):i(P,{children:n})??null};import{jsx as T}from"react/jsx-runtime";var h=class e extends w{state={xyoError:void 0};static getDerivedStateFromError(r){return{hasError:!0,xyoError:e.normalizeError(r)}}static normalizeError(r){return r.schema===f?r:{message:r.message,schema:f,sources:[]}}componentDidCatch(r,o){let{rethrow:t,rollbar:n}=this.props,{xyoError:p}=this.state;if(n==null||n.error(r),console.error("Error:",p,o),t)throw r}render(){let{xyoError:r}=this.state,{children:o,boundaryName:t,errorComponent:n}=this.props;return r?n?n(r):T(u,{error:r,errorContext:`${t} Boundary`}):o}};import{useEffect as S,useState as M}from"react";import{createContext as A}from"react";var l=A({});import{jsx as B}from"react/jsx-runtime";var er=({children:e,rollbar:r})=>{let[o,t]=M();return S(()=>{o&&t(o)},[r,o]),B(l.Provider,{value:{rollbar:r},children:e})};import{useContext as F}from"react";var lr=()=>{let e=F(l);return e===void 0&&console.warn("useRollbar must be used within a ErrorReporterContext"),e??{}};export{d as ErrorAlert,u as ErrorRender,er as ErrorReporterProvider,h as ThrownErrorBoundary,lr as useRollbar};
1
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
2
+ import { ModuleErrorSchema } from "@xyo-network/payload-model";
3
+ import { Component } from "react";
4
+
5
+ // src/components/ErrorRender/ErrorAlert.tsx
6
+ import { ExitToApp as ExitIcon } from "@mui/icons-material";
7
+ import { Alert, AlertTitle, Typography } from "@mui/material";
8
+ import { ButtonEx } from "@xylabs/react-button";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
11
+ return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
12
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Whoops! Something went wrong" }),
13
+ errorContext ? /* @__PURE__ */ jsx(Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
14
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
15
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", children: error == null ? void 0 : error.message }),
16
+ onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
17
+ ] });
18
+ };
19
+
20
+ // src/components/ErrorRender/Render.tsx
21
+ import { FlexCol } from "@xylabs/react-flexbox";
22
+ import { useEffect } from "react";
23
+ import { useLocation } from "react-router-dom";
24
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
25
+ var ErrorRender = ({
26
+ onCancel,
27
+ error,
28
+ noErrorDisplay = false,
29
+ customError = null,
30
+ children,
31
+ errorContext,
32
+ ...props
33
+ }) => {
34
+ const location = useLocation();
35
+ useEffect(() => {
36
+ location.state = {
37
+ from: {
38
+ pathname: window.location.pathname
39
+ }
40
+ };
41
+ }, [location]);
42
+ return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
43
+ };
44
+
45
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
46
+ import { jsx as jsx3 } from "react/jsx-runtime";
47
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
48
+ state = {
49
+ xyoError: void 0
50
+ };
51
+ static getDerivedStateFromError(error) {
52
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
53
+ }
54
+ static normalizeError(error) {
55
+ return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
56
+ }
57
+ componentDidCatch(error, errorInfo) {
58
+ const { rethrow, rollbar } = this.props;
59
+ const { xyoError } = this.state;
60
+ rollbar == null ? void 0 : rollbar.error(error);
61
+ console.error("Error:", xyoError, errorInfo);
62
+ if (rethrow) {
63
+ throw error;
64
+ }
65
+ }
66
+ render() {
67
+ const { xyoError } = this.state;
68
+ const { children, boundaryName, errorComponent } = this.props;
69
+ if (xyoError) {
70
+ if (errorComponent) {
71
+ return errorComponent(xyoError);
72
+ }
73
+ return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
74
+ }
75
+ return children;
76
+ }
77
+ };
78
+
79
+ // src/contexts/ErrorReporter/Provider.tsx
80
+ import { useEffect as useEffect2, useState } from "react";
81
+
82
+ // src/contexts/ErrorReporter/Context.ts
83
+ import { createContext } from "react";
84
+ var ErrorReporterContext = createContext({});
85
+
86
+ // src/contexts/ErrorReporter/Provider.tsx
87
+ import { jsx as jsx4 } from "react/jsx-runtime";
88
+ var ErrorReporterProvider = ({ children, rollbar }) => {
89
+ const [rollbarInstance, setRollBarInstance] = useState();
90
+ useEffect2(() => {
91
+ if (rollbarInstance) {
92
+ setRollBarInstance(rollbarInstance);
93
+ }
94
+ }, [rollbar, rollbarInstance]);
95
+ return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
96
+ };
97
+
98
+ // src/contexts/ErrorReporter/useRollbar.tsx
99
+ import { useContext } from "react";
100
+ var useRollbar = () => {
101
+ const context = useContext(ErrorReporterContext);
102
+ if (context === void 0) {
103
+ console.warn("useRollbar must be used within a ErrorReporterContext");
104
+ }
105
+ return context ?? {};
106
+ };
107
+ export {
108
+ ErrorAlert,
109
+ ErrorRender,
110
+ ErrorReporterProvider,
111
+ ThrownErrorBoundary,
112
+ useRollbar
113
+ };
2
114
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":"AAAA,OAAsB,qBAAAA,MAAyB,6BAC/C,OAAS,aAAAC,MAAuC,QCDhD,OAAS,aAAaC,MAAgB,sBACtC,OAAS,SAAAC,EAAmB,cAAAC,EAAY,cAAAC,MAAkB,gBAC1D,OAAS,YAAAC,MAAgB,uBAWrB,OACE,OAAAC,EADF,QAAAC,MAAA,oBAFG,IAAMC,EAAwC,CAAC,CAAE,SAAAC,EAAU,MAAAC,EAAO,aAAAC,EAAc,GAAGC,CAAM,IAE5FL,EAACL,EAAA,CAAM,SAAS,QAAS,GAAGU,EAC1B,UAAAN,EAACH,EAAA,CAAW,wCAA4B,EACvCQ,EACCL,EAACF,EAAA,CAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,IAAI,QAAQ,QAC3D,SAAAO,EACH,EACA,KACFL,EAACF,EAAA,CAAW,QAAQ,UAAU,GAAI,GAAK,WAAW,OAAO,kBAEzD,EACAE,EAACF,EAAA,CAAW,QAAQ,UAAW,SAAAM,GAAA,YAAAA,EAAO,QAAQ,EAC7CD,EACCH,EAACD,EAAA,CAAS,QAAQ,WAAW,KAAK,QAAQ,QAASI,EAAU,SAAS,WAAW,MAAO,CAAE,MAAO,EAAG,IAAK,CAAE,EACzG,SAAAH,EAACL,EAAA,CAAS,SAAS,QAAQ,EAC7B,EACA,MACJ,EC7BJ,OAAS,WAAAY,MAAe,wBACxB,OAAS,aAAAC,MAAiB,QAC1B,OAAS,eAAAC,MAAmB,mBA6BhB,OAIN,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,CAAe,EAAI,KAAK,MACxD,OAAIH,EACEG,EACKA,EAAeH,CAAQ,EAEzBT,EAACa,EAAA,CAAY,MAAOJ,EAAU,aAAc,GAAGE,CAAY,YAAa,EAG1ED,CACT,CACF,EGzDA,OAAS,aAAAI,EAAW,YAAAC,MAAgB,QCDpC,OAAS,iBAAAC,MAAqB,QAIvB,IAAMC,EAAuBD,EAAyC,CAAC,CAAC,EDetE,cAAAE,MAAA,oBATT,IAAMC,GAA4E,CAAC,CAAE,SAAAC,EAAU,QAAAC,CAAQ,IAAM,CAC3G,GAAM,CAACC,EAAiBC,CAAkB,EAAIC,EAAkB,EAEhE,OAAAC,EAAU,IAAM,CACVH,GACFC,EAAmBD,CAAe,CAEtC,EAAG,CAACD,EAASC,CAAe,CAAC,EAEtBJ,EAACQ,EAAqB,SAArB,CAA8B,MAAO,CAAE,QAAAL,CAAQ,EAAI,SAAAD,EAAS,CACtE,EEpBA,OAAS,cAAAO,MAAkB,QAI3B,IAAMC,GAAa,IAAM,CACvB,IAAMC,EAAUC,EAAWC,CAAoB,EAC/C,OAAIF,IAAY,QACd,QAAQ,KAAK,uDAAuD,EAG/DA,GAAW,CAAC,CACrB","names":["ModuleErrorSchema","Component","ExitIcon","Alert","AlertTitle","Typography","ButtonEx","jsx","jsxs","ErrorAlert","onCancel","error","errorContext","props","FlexCol","useEffect","useLocation","Fragment","jsx","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","props","location","useLocation","useEffect","FlexCol","ErrorAlert","jsx","ThrownErrorBoundary","_ThrownErrorBoundary","Component","error","ModuleErrorSchema","errorInfo","rethrow","rollbar","xyoError","children","boundaryName","errorComponent","ErrorRender","useEffect","useState","createContext","ErrorReporterContext","jsx","ErrorReporterProvider","children","rollbar","rollbarInstance","setRollBarInstance","useState","useEffect","ErrorReporterContext","useContext","useRollbar","context","useContext","ErrorReporterContext"]}
1
+ {"version":3,"sources":["../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useRollbar.tsx"],"sourcesContent":["import { ModuleError, ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { Component, ErrorInfo, ReactNode } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorRender } from '../ErrorRender'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nexport class ThrownErrorBoundary extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = {\n xyoError: undefined,\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ?\n error\n : { message: error.message, schema: ModuleErrorSchema, sources: [] }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const { children, boundaryName, errorComponent } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} />\n }\n\n return children\n }\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleError } from '@xyo-network/payload-model'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error\n errorContext?: string\n onCancel?: () => void\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({ onCancel, error, errorContext, ...props }) => {\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>Whoops! Something went wrong</AlertTitle>\n {errorContext ?\n <Typography variant=\"caption\" my={0.5} lineHeight=\"1\" display=\"block\">\n {errorContext}\n </Typography>\n : null}\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{error?.message}</Typography>\n {onCancel ?\n <ButtonEx variant=\"outlined\" size=\"small\" onClick={onCancel} position=\"absolute\" style={{ right: 8, top: 8 }}>\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport { useEffect } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { ErrorAlert } from './ErrorAlert'\nimport { ErrorRenderProps } from './Props'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n ...props\n}) => {\n const location = useLocation()\n useEffect(() => {\n // ensure we end up at the same place we are now after logging in\n location.state = {\n from: {\n pathname: window.location.pathname,\n },\n }\n }, [location])\n\n return error ?\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ?\n customError\n : <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n }\n </FlexCol>\n : <>{children}</> ?? null\n}\n","import { WithChildren } from '@xylabs/react-shared'\nimport { useEffect, useState } from 'react'\nimport Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar }) => {\n const [rollbarInstance, setRollBarInstance] = useState<Rollbar>()\n\n useEffect(() => {\n if (rollbarInstance) {\n setRollBarInstance(rollbarInstance)\n }\n }, [rollbar, rollbarInstance])\n\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport { ErrorReporterContextState } from './State'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context'\n\nconst useRollbar = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useRollbar must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n\nexport { useRollbar }\n"],"mappings":";AAAA,SAAsB,yBAAyB;AAC/C,SAAS,iBAAuC;;;ACDhD,SAAS,aAAa,gBAAgB;AACtC,SAAS,OAAmB,YAAY,kBAAkB;AAC1D,SAAS,gBAAgB;AAWrB,SACE,KADF;AAFG,IAAM,aAAwC,CAAC,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,MAAM;AACpG,SACE,qBAAC,SAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,wBAAC,cAAW,0CAA4B;AAAA,IACvC,eACC,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,KAAI,SAAQ,SAC3D,wBACH,IACA;AAAA,IACF,oBAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,IACA,oBAAC,cAAW,SAAQ,WAAW,yCAAO,SAAQ;AAAA,IAC7C,WACC,oBAAC,YAAS,SAAQ,YAAW,MAAK,SAAQ,SAAS,UAAU,UAAS,YAAW,OAAO,EAAE,OAAO,GAAG,KAAK,EAAE,GACzG,8BAAC,YAAS,UAAS,SAAQ,GAC7B,IACA;AAAA,KACJ;AAEJ;;;AC/BA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AA6BhB,SAIN,UAJM,OAAAA,YAAA;AAxBL,IAAM,cAA0C,CAAC;AAAA,EACtD;AAAA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Q;AAAA,MAChC;AACA,aAAO,gBAAAA,KAAC,eAAY,OAAO,UAAU,cAAc,GAAG,YAAY,aAAa;AAAA,IACjF;AAEA,WAAO;AAAA,EACT;AACF;;;AGzDA,SAAS,aAAAC,YAAW,gBAAgB;;;ACDpC,SAAS,qBAAqB;AAIvB,IAAM,uBAAuB,cAAyC,CAAC,CAAC;;;ADetE,gBAAAC,YAAA;AATT,IAAM,wBAA4E,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC3G,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAkB;AAEhE,EAAAC,WAAU,MAAM;AACd,QAAI,iBAAiB;AACnB,yBAAmB,eAAe;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,SAAS,eAAe,CAAC;AAE7B,SAAO,gBAAAD,KAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,QAAQ,GAAI,UAAS;AACtE;;;AEpBA,SAAS,kBAAkB;AAI3B,IAAM,aAAa,MAAM;AACvB,QAAM,UAAU,WAAW,oBAAoB;AAC/C,MAAI,YAAY,QAAW;AACzB,YAAQ,KAAK,uDAAuD;AAAA,EACtE;AAEA,SAAO,WAAW,CAAC;AACrB;","names":["jsx","jsx","useEffect","jsx","useEffect"]}
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@xylabs/react-button": "^3.1.7",
14
14
  "@xylabs/react-flexbox": "^3.1.7",
15
15
  "@xylabs/react-shared": "^3.1.7",
16
- "@xyo-network/payload-model": "^2.107.0",
16
+ "@xyo-network/payload-model": "^2.107.6",
17
17
  "react-router-dom": "^6.24.0"
18
18
  },
19
19
  "peerDependencies": {
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@storybook/react": "^7.6.20",
29
- "@xylabs/ts-scripts-yarn3": "^3.11.8",
30
- "@xylabs/tsconfig-react": "^3.11.8",
29
+ "@xylabs/ts-scripts-yarn3": "^3.11.12",
30
+ "@xylabs/tsconfig-react": "^3.11.12",
31
31
  "typescript": "^5.5.2"
32
32
  },
33
33
  "peerDependenciesMeta": {
@@ -86,6 +86,6 @@
86
86
  },
87
87
  "sideEffects": false,
88
88
  "types": "dist/browser/index.d.ts",
89
- "version": "2.78.0",
89
+ "version": "2.78.1",
90
90
  "type": "module"
91
91
  }