@xyo-network/react-error 2.61.0 → 2.61.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. package/dist/components/ErrorBoundary/ThrownErrorBoundary.d.mts.map +1 -0
  2. package/dist/components/ErrorBoundary/ThrownErrorBoundary.d.ts +21 -0
  3. package/dist/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +1 -0
  4. package/dist/components/ErrorBoundary/ThrownErrorBoundary.stories.d.mts +7 -0
  5. package/dist/components/ErrorBoundary/ThrownErrorBoundary.stories.d.mts.map +1 -0
  6. package/dist/components/ErrorBoundary/ThrownErrorBoundary.stories.d.ts +7 -0
  7. package/dist/components/ErrorBoundary/ThrownErrorBoundary.stories.d.ts.map +1 -0
  8. package/dist/components/ErrorBoundary/index.d.mts.map +1 -0
  9. package/dist/{esm/components/ErrorBoundary/index.js → components/ErrorBoundary/index.d.ts} +1 -1
  10. package/dist/components/ErrorBoundary/index.d.ts.map +1 -0
  11. package/dist/components/ErrorRender/ErrorAlert.d.mts.map +1 -0
  12. package/dist/components/ErrorRender/ErrorAlert.d.ts +10 -0
  13. package/dist/components/ErrorRender/ErrorAlert.d.ts.map +1 -0
  14. package/dist/components/ErrorRender/Props.d.mts.map +1 -0
  15. package/dist/components/ErrorRender/Props.d.ts +12 -0
  16. package/dist/components/ErrorRender/Props.d.ts.map +1 -0
  17. package/dist/components/ErrorRender/Render.d.mts.map +1 -0
  18. package/dist/components/ErrorRender/Render.d.ts +4 -0
  19. package/dist/components/ErrorRender/Render.d.ts.map +1 -0
  20. package/dist/components/ErrorRender/index.d.mts.map +1 -0
  21. package/dist/{esm/components/ErrorRender/index.js → components/ErrorRender/index.d.ts} +1 -1
  22. package/dist/components/ErrorRender/index.d.ts.map +1 -0
  23. package/dist/components/index.d.mts.map +1 -0
  24. package/dist/{esm/components/index.js → components/index.d.ts} +1 -1
  25. package/dist/components/index.d.ts.map +1 -0
  26. package/dist/contexts/ErrorReporter/Context.d.mts.map +1 -0
  27. package/dist/contexts/ErrorReporter/Context.d.ts +4 -0
  28. package/dist/contexts/ErrorReporter/Context.d.ts.map +1 -0
  29. package/dist/contexts/ErrorReporter/Provider.d.mts.map +1 -0
  30. package/dist/contexts/ErrorReporter/Provider.d.ts +9 -0
  31. package/dist/contexts/ErrorReporter/Provider.d.ts.map +1 -0
  32. package/dist/contexts/ErrorReporter/Provider.stories.d.mts +10 -0
  33. package/dist/contexts/ErrorReporter/Provider.stories.d.mts.map +1 -0
  34. package/dist/contexts/ErrorReporter/Provider.stories.d.ts +10 -0
  35. package/dist/contexts/ErrorReporter/Provider.stories.d.ts.map +1 -0
  36. package/dist/contexts/ErrorReporter/State.d.mts.map +1 -0
  37. package/dist/contexts/ErrorReporter/State.d.ts +5 -0
  38. package/dist/contexts/ErrorReporter/State.d.ts.map +1 -0
  39. package/dist/contexts/ErrorReporter/index.d.mts.map +1 -0
  40. package/dist/{esm/contexts/ErrorReporter/index.js → contexts/ErrorReporter/index.d.ts} +1 -1
  41. package/dist/contexts/ErrorReporter/index.d.ts.map +1 -0
  42. package/dist/contexts/ErrorReporter/useRollbar.d.mts.map +1 -0
  43. package/dist/contexts/ErrorReporter/useRollbar.d.ts +3 -0
  44. package/dist/contexts/ErrorReporter/useRollbar.d.ts.map +1 -0
  45. package/dist/contexts/index.d.mts.map +1 -0
  46. package/dist/contexts/index.d.ts +2 -0
  47. package/dist/contexts/index.d.ts.map +1 -0
  48. package/dist/docs.json +25215 -0
  49. package/dist/index.d.mts.map +1 -0
  50. package/dist/{esm/index.js → index.d.ts} +1 -1
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +159 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/index.mjs +118 -0
  55. package/dist/index.mjs.map +1 -0
  56. package/package.json +28 -20
  57. package/dist/cjs/components/ErrorBoundary/ThrownErrorBoundary.js +0 -43
  58. package/dist/cjs/components/ErrorBoundary/ThrownErrorBoundary.js.map +0 -1
  59. package/dist/cjs/components/ErrorBoundary/index.js +0 -5
  60. package/dist/cjs/components/ErrorBoundary/index.js.map +0 -1
  61. package/dist/cjs/components/ErrorRender/ErrorAlert.js +0 -14
  62. package/dist/cjs/components/ErrorRender/ErrorAlert.js.map +0 -1
  63. package/dist/cjs/components/ErrorRender/Props.js +0 -3
  64. package/dist/cjs/components/ErrorRender/Props.js.map +0 -1
  65. package/dist/cjs/components/ErrorRender/Render.js +0 -30
  66. package/dist/cjs/components/ErrorRender/Render.js.map +0 -1
  67. package/dist/cjs/components/ErrorRender/index.js +0 -7
  68. package/dist/cjs/components/ErrorRender/index.js.map +0 -1
  69. package/dist/cjs/components/index.js +0 -6
  70. package/dist/cjs/components/index.js.map +0 -1
  71. package/dist/cjs/contexts/ErrorReporter/Context.js +0 -6
  72. package/dist/cjs/contexts/ErrorReporter/Context.js.map +0 -1
  73. package/dist/cjs/contexts/ErrorReporter/Provider.js +0 -17
  74. package/dist/cjs/contexts/ErrorReporter/Provider.js.map +0 -1
  75. package/dist/cjs/contexts/ErrorReporter/State.js +0 -3
  76. package/dist/cjs/contexts/ErrorReporter/State.js.map +0 -1
  77. package/dist/cjs/contexts/ErrorReporter/index.js +0 -7
  78. package/dist/cjs/contexts/ErrorReporter/index.js.map +0 -1
  79. package/dist/cjs/contexts/ErrorReporter/useRollbar.js +0 -14
  80. package/dist/cjs/contexts/ErrorReporter/useRollbar.js.map +0 -1
  81. package/dist/cjs/contexts/index.js +0 -5
  82. package/dist/cjs/contexts/index.js.map +0 -1
  83. package/dist/cjs/index.js +0 -6
  84. package/dist/cjs/index.js.map +0 -1
  85. package/dist/esm/components/ErrorBoundary/ThrownErrorBoundary.js +0 -36
  86. package/dist/esm/components/ErrorBoundary/ThrownErrorBoundary.js.map +0 -1
  87. package/dist/esm/components/ErrorBoundary/index.js.map +0 -1
  88. package/dist/esm/components/ErrorRender/ErrorAlert.js +0 -8
  89. package/dist/esm/components/ErrorRender/ErrorAlert.js.map +0 -1
  90. package/dist/esm/components/ErrorRender/Props.js +0 -2
  91. package/dist/esm/components/ErrorRender/Props.js.map +0 -1
  92. package/dist/esm/components/ErrorRender/Render.js +0 -23
  93. package/dist/esm/components/ErrorRender/Render.js.map +0 -1
  94. package/dist/esm/components/ErrorRender/index.js.map +0 -1
  95. package/dist/esm/components/index.js.map +0 -1
  96. package/dist/esm/contexts/ErrorReporter/Context.js +0 -3
  97. package/dist/esm/contexts/ErrorReporter/Context.js.map +0 -1
  98. package/dist/esm/contexts/ErrorReporter/Provider.js +0 -14
  99. package/dist/esm/contexts/ErrorReporter/Provider.js.map +0 -1
  100. package/dist/esm/contexts/ErrorReporter/State.js +0 -2
  101. package/dist/esm/contexts/ErrorReporter/State.js.map +0 -1
  102. package/dist/esm/contexts/ErrorReporter/index.js.map +0 -1
  103. package/dist/esm/contexts/ErrorReporter/useRollbar.js +0 -11
  104. package/dist/esm/contexts/ErrorReporter/useRollbar.js.map +0 -1
  105. package/dist/esm/contexts/index.js +0 -2
  106. package/dist/esm/contexts/index.js.map +0 -1
  107. package/dist/esm/index.js.map +0 -1
  108. package/dist/types/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +0 -1
  109. package/dist/types/components/ErrorBoundary/index.d.ts.map +0 -1
  110. package/dist/types/components/ErrorRender/ErrorAlert.d.ts.map +0 -1
  111. package/dist/types/components/ErrorRender/Props.d.ts.map +0 -1
  112. package/dist/types/components/ErrorRender/Render.d.ts.map +0 -1
  113. package/dist/types/components/ErrorRender/index.d.ts.map +0 -1
  114. package/dist/types/components/index.d.ts.map +0 -1
  115. package/dist/types/contexts/ErrorReporter/Context.d.ts.map +0 -1
  116. package/dist/types/contexts/ErrorReporter/Provider.d.ts.map +0 -1
  117. package/dist/types/contexts/ErrorReporter/State.d.ts.map +0 -1
  118. package/dist/types/contexts/ErrorReporter/index.d.ts.map +0 -1
  119. package/dist/types/contexts/ErrorReporter/useRollbar.d.ts.map +0 -1
  120. package/dist/types/contexts/index.d.ts.map +0 -1
  121. package/dist/types/index.d.ts.map +0 -1
  122. /package/dist/{types/components/ErrorBoundary/ThrownErrorBoundary.d.ts → components/ErrorBoundary/ThrownErrorBoundary.d.mts} +0 -0
  123. /package/dist/{types/components/ErrorBoundary/index.d.ts → components/ErrorBoundary/index.d.mts} +0 -0
  124. /package/dist/{types/components/ErrorRender/ErrorAlert.d.ts → components/ErrorRender/ErrorAlert.d.mts} +0 -0
  125. /package/dist/{types/components/ErrorRender/Props.d.ts → components/ErrorRender/Props.d.mts} +0 -0
  126. /package/dist/{types/components/ErrorRender/Render.d.ts → components/ErrorRender/Render.d.mts} +0 -0
  127. /package/dist/{types/components/ErrorRender/index.d.ts → components/ErrorRender/index.d.mts} +0 -0
  128. /package/dist/{types/components/index.d.ts → components/index.d.mts} +0 -0
  129. /package/dist/{types/contexts/ErrorReporter/Context.d.ts → contexts/ErrorReporter/Context.d.mts} +0 -0
  130. /package/dist/{types/contexts/ErrorReporter/Provider.d.ts → contexts/ErrorReporter/Provider.d.mts} +0 -0
  131. /package/dist/{types/contexts/ErrorReporter/State.d.ts → contexts/ErrorReporter/State.d.mts} +0 -0
  132. /package/dist/{types/contexts/ErrorReporter/index.d.ts → contexts/ErrorReporter/index.d.mts} +0 -0
  133. /package/dist/{types/contexts/ErrorReporter/useRollbar.d.ts → contexts/ErrorReporter/useRollbar.d.mts} +0 -0
  134. /package/dist/{types/contexts/index.d.ts → contexts/index.d.mts} +0 -0
  135. /package/dist/{types/index.d.ts → index.d.mts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
@@ -1,3 +1,3 @@
1
1
  export * from './components';
2
2
  export * from './contexts';
3
- //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ErrorAlert: () => ErrorAlert,
34
+ ErrorRender: () => ErrorRender,
35
+ ErrorReporterProvider: () => ErrorReporterProvider,
36
+ ThrownErrorBoundary: () => ThrownErrorBoundary,
37
+ useRollbar: () => useRollbar
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
42
+ var import_payload_model = require("@xyo-network/payload-model");
43
+ var import_react2 = require("react");
44
+
45
+ // src/components/ErrorRender/ErrorAlert.tsx
46
+ var import_ExitToApp = __toESM(require("@mui/icons-material/ExitToApp"));
47
+ var import_material = require("@mui/material");
48
+ var import_react_button = require("@xylabs/react-button");
49
+ var import_jsx_runtime = require("react/jsx-runtime");
50
+ var ErrorAlert = ({ onCancel, error, errorContext, ...props }) => {
51
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Alert, { severity: "error", ...props, children: [
52
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.AlertTitle, { children: "Whoops! Something went wrong" }),
53
+ errorContext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", my: 0.5, lineHeight: "1", display: "block", children: errorContext }) : null,
54
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
55
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, { variant: "caption", children: error?.message }),
56
+ 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_ExitToApp.default, { fontSize: "small" }) }) : null
57
+ ] });
58
+ };
59
+
60
+ // src/components/ErrorRender/Render.tsx
61
+ var import_react_flexbox = require("@xylabs/react-flexbox");
62
+ var import_react = require("react");
63
+ var import_react_router_dom = require("react-router-dom");
64
+ var import_jsx_runtime2 = require("react/jsx-runtime");
65
+ var ErrorRender = ({
66
+ onCancel,
67
+ error,
68
+ noErrorDisplay = false,
69
+ customError = null,
70
+ children,
71
+ errorContext,
72
+ ...props
73
+ }) => {
74
+ const location = (0, import_react_router_dom.useLocation)();
75
+ (0, import_react.useEffect)(() => {
76
+ location.state = {
77
+ from: {
78
+ pathname: window.location.pathname
79
+ }
80
+ };
81
+ }, [location]);
82
+ if (error) {
83
+ return /* @__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 }) }) });
84
+ } else {
85
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children }) ?? null;
86
+ }
87
+ };
88
+
89
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
90
+ var import_jsx_runtime3 = require("react/jsx-runtime");
91
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends import_react2.Component {
92
+ state = {
93
+ xyoError: void 0
94
+ };
95
+ static getDerivedStateFromError(error) {
96
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
97
+ }
98
+ static normalizeError(error) {
99
+ return error.schema === import_payload_model.ModuleErrorSchema ? error : { message: error.message, schema: import_payload_model.ModuleErrorSchema, sources: [] };
100
+ }
101
+ componentDidCatch(error, errorInfo) {
102
+ const { rethrow, rollbar } = this.props;
103
+ const { xyoError } = this.state;
104
+ rollbar?.error(error);
105
+ console.error("Error:", xyoError, errorInfo);
106
+ if (rethrow) {
107
+ throw error;
108
+ }
109
+ }
110
+ render() {
111
+ const { xyoError } = this.state;
112
+ const { children, boundaryName, errorComponent } = this.props;
113
+ if (xyoError) {
114
+ if (errorComponent) {
115
+ return errorComponent(xyoError);
116
+ }
117
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
118
+ }
119
+ return children;
120
+ }
121
+ };
122
+
123
+ // src/contexts/ErrorReporter/Provider.tsx
124
+ var import_react4 = require("react");
125
+
126
+ // src/contexts/ErrorReporter/Context.ts
127
+ var import_react3 = require("react");
128
+ var ErrorReporterContext = (0, import_react3.createContext)({});
129
+
130
+ // src/contexts/ErrorReporter/Provider.tsx
131
+ var import_jsx_runtime4 = require("react/jsx-runtime");
132
+ var ErrorReporterProvider = ({ children, rollbar }) => {
133
+ const [rollbarInstance, setRollBarInstance] = (0, import_react4.useState)();
134
+ (0, import_react4.useEffect)(() => {
135
+ if (rollbarInstance) {
136
+ setRollBarInstance(rollbarInstance);
137
+ }
138
+ }, [rollbar, rollbarInstance]);
139
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorReporterContext.Provider, { value: { rollbar }, children });
140
+ };
141
+
142
+ // src/contexts/ErrorReporter/useRollbar.tsx
143
+ var import_react5 = require("react");
144
+ var useRollbar = () => {
145
+ const context = (0, import_react5.useContext)(ErrorReporterContext);
146
+ if (context === void 0) {
147
+ console.warn("useRollbar must be used within a ErrorReporterContext");
148
+ }
149
+ return context ?? {};
150
+ };
151
+ // Annotate the CommonJS export names for ESM import in node:
152
+ 0 && (module.exports = {
153
+ ErrorAlert,
154
+ ErrorRender,
155
+ ErrorReporterProvider,
156
+ ThrownErrorBoundary,
157
+ useRollbar
158
+ });
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 public 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 public static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] }\n ) as ModuleError\n }\n\n public 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 public 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 ExitIcon from '@mui/icons-material/ExitToApp'\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 if (error) {\n return (\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ? (\n customError\n ) : (\n <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n )}\n </FlexCol>\n )\n } else {\n return <>{children}</> ?? null\n }\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":";;;;;;;;;;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;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"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,118 @@
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 ExitIcon from "@mui/icons-material/ExitToApp";
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
+ if (error) {
43
+ return /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel }) }) });
44
+ } else {
45
+ return /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
46
+ }
47
+ };
48
+
49
+ // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
50
+ import { jsx as jsx3 } from "react/jsx-runtime";
51
+ var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
52
+ state = {
53
+ xyoError: void 0
54
+ };
55
+ static getDerivedStateFromError(error) {
56
+ return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
57
+ }
58
+ static normalizeError(error) {
59
+ return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
60
+ }
61
+ componentDidCatch(error, errorInfo) {
62
+ const { rethrow, rollbar } = this.props;
63
+ const { xyoError } = this.state;
64
+ rollbar?.error(error);
65
+ console.error("Error:", xyoError, errorInfo);
66
+ if (rethrow) {
67
+ throw error;
68
+ }
69
+ }
70
+ render() {
71
+ const { xyoError } = this.state;
72
+ const { children, boundaryName, errorComponent } = this.props;
73
+ if (xyoError) {
74
+ if (errorComponent) {
75
+ return errorComponent(xyoError);
76
+ }
77
+ return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
78
+ }
79
+ return children;
80
+ }
81
+ };
82
+
83
+ // src/contexts/ErrorReporter/Provider.tsx
84
+ import { useEffect as useEffect2, useState } from "react";
85
+
86
+ // src/contexts/ErrorReporter/Context.ts
87
+ import { createContext } from "react";
88
+ var ErrorReporterContext = createContext({});
89
+
90
+ // src/contexts/ErrorReporter/Provider.tsx
91
+ import { jsx as jsx4 } from "react/jsx-runtime";
92
+ var ErrorReporterProvider = ({ children, rollbar }) => {
93
+ const [rollbarInstance, setRollBarInstance] = useState();
94
+ useEffect2(() => {
95
+ if (rollbarInstance) {
96
+ setRollBarInstance(rollbarInstance);
97
+ }
98
+ }, [rollbar, rollbarInstance]);
99
+ return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
100
+ };
101
+
102
+ // src/contexts/ErrorReporter/useRollbar.tsx
103
+ import { useContext } from "react";
104
+ var useRollbar = () => {
105
+ const context = useContext(ErrorReporterContext);
106
+ if (context === void 0) {
107
+ console.warn("useRollbar must be used within a ErrorReporterContext");
108
+ }
109
+ return context ?? {};
110
+ };
111
+ export {
112
+ ErrorAlert,
113
+ ErrorRender,
114
+ ErrorReporterProvider,
115
+ ThrownErrorBoundary,
116
+ useRollbar
117
+ };
118
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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 public 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 public static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] }\n ) as ModuleError\n }\n\n public 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 public 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 ExitIcon from '@mui/icons-material/ExitToApp'\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 if (error) {\n return (\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay ? (\n customError\n ) : (\n <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} />\n </FlexCol>\n )}\n </FlexCol>\n )\n } else {\n return <>{children}</> ?? null\n }\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,OAAO,cAAc;AACrB,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,IACE;AAAA,IACJ,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,IACE;AAAA,KACN;AAEJ;;;AC/BA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AA+BhB,SAMD,UANC,OAAAA,YAAA;AA1BL,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,MAAM;AAAA,QACJ,UAAU,OAAO,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,MAAI,OAAO;A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AC;;;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
@@ -10,10 +10,10 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/react-button": "~2.17.15",
14
- "@xylabs/react-flexbox": "~2.17.15",
15
- "@xylabs/react-shared": "~2.17.15",
16
- "@xyo-network/payload-model": "^2.73.3"
13
+ "@xylabs/react-button": "~2.18.4",
14
+ "@xylabs/react-flexbox": "~2.18.4",
15
+ "@xylabs/react-shared": "~2.18.4",
16
+ "@xyo-network/payload-model": "^2.74.1"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "@mui/icons-material": "^5",
@@ -25,9 +25,9 @@
25
25
  "rollbar": "^2"
26
26
  },
27
27
  "devDependencies": {
28
- "@storybook/react": "^7.4.0",
29
- "@xylabs/ts-scripts-yarn3": "^2.19.5",
30
- "@xylabs/tsconfig-react": "^2.19.5",
28
+ "@storybook/react": "^7.4.3",
29
+ "@xylabs/ts-scripts-yarn3": "^3.0.28",
30
+ "@xylabs/tsconfig-react": "^3.0.28",
31
31
  "typescript": "^5.2.2"
32
32
  },
33
33
  "peerDependenciesMeta": {
@@ -36,27 +36,35 @@
36
36
  }
37
37
  },
38
38
  "description": "Common React library for all XYO projects that use React",
39
- "browser": "dist/esm/index.js",
40
39
  "docs": "dist/docs.json",
41
40
  "exports": {
42
41
  ".": {
43
42
  "node": {
44
- "import": "./dist/esm/index.js",
45
- "require": "./dist/cjs/index.js"
43
+ "import": {
44
+ "types": "./dist/index.d.mts",
45
+ "default": "./dist/index.mjs"
46
+ },
47
+ "require": {
48
+ "types": "./dist/index.d.ts",
49
+ "default": "./dist/index.js"
50
+ }
46
51
  },
47
52
  "browser": {
48
- "import": "./dist/esm/index.js",
49
- "require": "./dist/cjs/index.js"
53
+ "import": {
54
+ "types": "./dist/index.d.mts",
55
+ "default": "./dist/index.mjs"
56
+ },
57
+ "require": {
58
+ "types": "./dist/index.d.ts",
59
+ "default": "./dist/index.js"
60
+ }
50
61
  },
51
- "default": "./dist/esm/index.js"
52
- },
53
- "./dist/docs.json": {
54
- "default": "./dist/docs.json"
62
+ "default": "./dist/index.mjs"
55
63
  },
56
64
  "./package.json": "./package.json"
57
65
  },
58
- "main": "dist/cjs/index.js",
59
- "module": "dist/esm/index.js",
66
+ "main": "dist/index.js",
67
+ "module": "dist/index.mjs",
60
68
  "homepage": "https://xyo.network",
61
69
  "keywords": [
62
70
  "xyo",
@@ -77,6 +85,6 @@
77
85
  "license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
78
86
  },
79
87
  "sideEffects": false,
80
- "types": "dist/types/index.d.ts",
81
- "version": "2.61.0"
88
+ "types": "dist/index.d.ts",
89
+ "version": "2.61.1"
82
90
  }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ThrownErrorBoundary = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const payload_model_1 = require("@xyo-network/payload-model");
6
- const react_1 = require("react");
7
- const ErrorRender_1 = require("../ErrorRender");
8
- class ThrownErrorBoundary extends react_1.Component {
9
- constructor() {
10
- super(...arguments);
11
- this.state = {
12
- xyoError: undefined,
13
- };
14
- }
15
- static getDerivedStateFromError(error) {
16
- return { hasError: true, xyoError: ThrownErrorBoundary.normalizeError(error) };
17
- }
18
- static normalizeError(error) {
19
- return (error.schema === payload_model_1.ModuleErrorSchema ? error : { message: error.message, schema: payload_model_1.ModuleErrorSchema, sources: [] });
20
- }
21
- componentDidCatch(error, errorInfo) {
22
- const { rethrow, rollbar } = this.props;
23
- const { xyoError } = this.state;
24
- rollbar === null || rollbar === void 0 ? void 0 : rollbar.error(error);
25
- console.error('Error:', xyoError, errorInfo);
26
- if (rethrow) {
27
- throw error;
28
- }
29
- }
30
- render() {
31
- const { xyoError } = this.state;
32
- const { children, boundaryName, errorComponent } = this.props;
33
- if (xyoError) {
34
- if (errorComponent) {
35
- return errorComponent(xyoError);
36
- }
37
- return (0, jsx_runtime_1.jsx)(ErrorRender_1.ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary` });
38
- }
39
- return children;
40
- }
41
- }
42
- exports.ThrownErrorBoundary = ThrownErrorBoundary;
43
- //# sourceMappingURL=ThrownErrorBoundary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThrownErrorBoundary.js","sourceRoot":"","sources":["../../../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx"],"names":[],"mappings":";;;;AAAA,8DAA2E;AAC3E,iCAAuD;AAGvD,gDAA4C;AAc5C,MAAa,mBAAoB,SAAQ,iBAA6D;IAAtG;;QACkB,UAAK,GAA6B;YAChD,QAAQ,EAAE,SAAS;SACpB,CAAA;IAoCH,CAAC;IAlCC,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,EAA8B,CAAA;IAC5G,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,KAA0B;QACrD,OAAO,CACJ,KAAqB,CAAC,MAAM,KAAK,iCAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,iCAAiB,EAAE,OAAO,EAAE,EAAE,EAAE,CAClH,CAAA;IAClB,CAAC;IAEe,iBAAiB,CAAC,KAAY,EAAE,SAAoB;QAClE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAE/B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QAErB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC5C,IAAI,OAAO,EAAE;YACX,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;IAEe,MAAM;QACpB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC7D,IAAI,QAAQ,EAAE;YACZ,IAAI,cAAc,EAAE;gBAClB,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAA;aAChC;YACD,OAAO,uBAAC,yBAAW,IAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,WAAW,GAAI,CAAA;SAClF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAvCD,kDAuCC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ThrownErrorBoundary"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ErrorBoundary/index.ts"],"names":[],"mappings":";;;AAAA,gEAAqC"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorAlert = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const ExitToApp_1 = tslib_1.__importDefault(require("@mui/icons-material/ExitToApp"));
7
- const material_1 = require("@mui/material");
8
- const react_button_1 = require("@xylabs/react-button");
9
- const ErrorAlert = (_a) => {
10
- var { onCancel, error, errorContext } = _a, props = tslib_1.__rest(_a, ["onCancel", "error", "errorContext"]);
11
- return ((0, jsx_runtime_1.jsxs)(material_1.Alert, Object.assign({ severity: "error" }, props, { children: [(0, jsx_runtime_1.jsx)(material_1.AlertTitle, { children: "Whoops! Something went wrong" }), errorContext ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "caption", my: 0.5, lineHeight: "1", display: "block" }, { children: errorContext }))) : null, (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "caption", mr: 0.5, fontWeight: "bold" }, { children: "Error:" })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "caption" }, { children: error === null || error === void 0 ? void 0 : error.message })), onCancel ? ((0, jsx_runtime_1.jsx)(react_button_1.ButtonEx, Object.assign({ variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 } }, { children: (0, jsx_runtime_1.jsx)(ExitToApp_1.default, { fontSize: "small" }) }))) : null] })));
12
- };
13
- exports.ErrorAlert = ErrorAlert;
14
- //# sourceMappingURL=ErrorAlert.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorAlert.js","sourceRoot":"","sources":["../../../../src/components/ErrorRender/ErrorAlert.tsx"],"names":[],"mappings":";;;;;AAAA,sFAAoD;AACpD,4CAAyE;AACzE,uDAA+C;AASxC,MAAM,UAAU,GAA8B,CAAC,EAA2C,EAAE,EAAE;QAA/C,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,OAAY,EAAP,KAAK,sBAAzC,qCAA2C,CAAF;IAC7F,OAAO,CACL,wBAAC,gBAAK,kBAAC,QAAQ,EAAC,OAAO,IAAK,KAAK,eAC/B,uBAAC,qBAAU,+CAA0C,EACpD,YAAY,CAAC,CAAC,CAAC,CACd,uBAAC,qBAAU,kBAAC,OAAO,EAAC,SAAS,EAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAC,GAAG,EAAC,OAAO,EAAC,OAAO,gBAClE,YAAY,IACF,CACd,CAAC,CAAC,CAAC,IAAI,EACR,uBAAC,qBAAU,kBAAC,OAAO,EAAC,SAAS,EAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAC,MAAM,4BAE3C,EACb,uBAAC,qBAAU,kBAAC,OAAO,EAAC,SAAS,gBAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,IAAc,EAC1D,QAAQ,CAAC,CAAC,CAAC,CACV,uBAAC,uBAAQ,kBAAC,OAAO,EAAC,UAAU,EAAC,IAAI,EAAC,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAC,UAAU,EAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,gBAC1G,uBAAC,mBAAQ,IAAC,QAAQ,EAAC,OAAO,GAAG,IACpB,CACZ,CAAC,CAAC,CAAC,IAAI,KACF,CACT,CAAA;AACH,CAAC,CAAA;AApBY,QAAA,UAAU,cAoBtB"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=Props.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Props.js","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Props.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorRender = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_flexbox_1 = require("@xylabs/react-flexbox");
7
- const react_1 = require("react");
8
- const react_router_dom_1 = require("react-router-dom");
9
- const ErrorAlert_1 = require("./ErrorAlert");
10
- const ErrorRender = (_a) => {
11
- var _b;
12
- var { onCancel, error, noErrorDisplay = false, customError = null, children, errorContext } = _a, props = tslib_1.__rest(_a, ["onCancel", "error", "noErrorDisplay", "customError", "children", "errorContext"]);
13
- const location = (0, react_router_dom_1.useLocation)();
14
- (0, react_1.useEffect)(() => {
15
- // ensure we end up at the same place we are now after logging in
16
- location.state = {
17
- from: {
18
- pathname: window.location.pathname,
19
- },
20
- };
21
- }, [location]);
22
- if (error) {
23
- return ((0, jsx_runtime_1.jsx)(react_flexbox_1.FlexCol, Object.assign({ alignItems: "stretch" }, props, { children: noErrorDisplay ? (customError) : ((0, jsx_runtime_1.jsx)(react_flexbox_1.FlexCol, Object.assign({ alignItems: "center" }, props, { children: (0, jsx_runtime_1.jsx)(ErrorAlert_1.ErrorAlert, { error: error, errorContext: errorContext, onCancel: onCancel }) }))) })));
24
- }
25
- else {
26
- return (_b = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children })) !== null && _b !== void 0 ? _b : null;
27
- }
28
- };
29
- exports.ErrorRender = ErrorRender;
30
- //# sourceMappingURL=Render.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Render.js","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Render.tsx"],"names":[],"mappings":";;;;;AAAA,yDAA+C;AAC/C,iCAAiC;AACjC,uDAA8C;AAE9C,6CAAyC;AAGlC,MAAM,WAAW,GAA+B,CAAC,EAQvD,EAAE,EAAE;;QARmD,EACtD,QAAQ,EACR,KAAK,EACL,cAAc,GAAG,KAAK,EACtB,WAAW,GAAG,IAAI,EAClB,QAAQ,EACR,YAAY,OAEb,EADI,KAAK,sBAP8C,kFAQvD,CADS;IAER,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAA;IAC9B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,iEAAiE;QACjE,QAAQ,CAAC,KAAK,GAAG;YACf,IAAI,EAAE;gBACJ,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;aACnC;SACF,CAAA;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,IAAI,KAAK,EAAE;QACT,OAAO,CACL,uBAAC,uBAAO,kBAAC,UAAU,EAAC,SAAS,IAAK,KAAK,cACpC,cAAc,CAAC,CAAC,CAAC,CAChB,WAAW,CACZ,CAAC,CAAC,CAAC,CACF,uBAAC,uBAAO,kBAAC,UAAU,EAAC,QAAQ,IAAK,KAAK,cACpC,uBAAC,uBAAU,IAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,GAAI,IACpE,CACX,IACO,CACX,CAAA;KACF;SAAM;QACL,OAAO,MAAA,2DAAG,QAAQ,GAAI,mCAAI,IAAI,CAAA;KAC/B;AACH,CAAC,CAAA;AAlCY,QAAA,WAAW,eAkCvB"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ErrorAlert"), exports);
5
- tslib_1.__exportStar(require("./Props"), exports);
6
- tslib_1.__exportStar(require("./Render"), exports);
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ErrorRender/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,kDAAuB;AACvB,mDAAwB"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ErrorBoundary"), exports);
5
- tslib_1.__exportStar(require("./ErrorRender"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";;;AAAA,0DAA+B;AAC/B,wDAA6B"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorReporterContext = void 0;
4
- const react_1 = require("react");
5
- exports.ErrorReporterContext = (0, react_1.createContext)({});
6
- //# sourceMappingURL=Context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Context.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AAIxB,QAAA,oBAAoB,GAAG,IAAA,qBAAa,EAA4B,EAAE,CAAC,CAAA"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorReporterProvider = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const Context_1 = require("./Context");
7
- const ErrorReporterProvider = ({ children, rollbar }) => {
8
- const [rollbarInstance, setRollBarInstance] = (0, react_1.useState)();
9
- (0, react_1.useEffect)(() => {
10
- if (rollbarInstance) {
11
- setRollBarInstance(rollbarInstance);
12
- }
13
- }, [rollbar, rollbarInstance]);
14
- return (0, jsx_runtime_1.jsx)(Context_1.ErrorReporterContext.Provider, Object.assign({ value: { rollbar } }, { children: children }));
15
- };
16
- exports.ErrorReporterProvider = ErrorReporterProvider;
17
- //# sourceMappingURL=Provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Provider.tsx"],"names":[],"mappings":";;;;AACA,iCAA2C;AAG3C,uCAAgD;AAMhD,MAAM,qBAAqB,GAAuD,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;IAC1G,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,GAAW,CAAA;IAEjE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,eAAe,EAAE;YACnB,kBAAkB,CAAC,eAAe,CAAC,CAAA;SACpC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAA;IAE9B,OAAO,uBAAC,8BAAoB,CAAC,QAAQ,kBAAC,KAAK,EAAE,EAAE,OAAO,EAAE,gBAAG,QAAQ,IAAiC,CAAA;AACtG,CAAC,CAAA;AAEQ,sDAAqB"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=State.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/State.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./Provider"), exports);
5
- tslib_1.__exportStar(require("./State"), exports);
6
- tslib_1.__exportStar(require("./useRollbar"), exports);
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,kDAAuB;AACvB,uDAA4B"}