@xyo-network/react-error 2.81.10 → 2.82.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.cts +2 -2
  2. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.cts.map +1 -1
  3. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.mts +2 -2
  4. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.mts.map +1 -1
  5. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.ts +2 -2
  6. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +1 -1
  7. package/dist/browser/components/ErrorBoundary/index.d.cts +1 -1
  8. package/dist/browser/components/ErrorBoundary/index.d.cts.map +1 -1
  9. package/dist/browser/components/ErrorBoundary/index.d.mts +1 -1
  10. package/dist/browser/components/ErrorBoundary/index.d.mts.map +1 -1
  11. package/dist/browser/components/ErrorBoundary/index.d.ts +1 -1
  12. package/dist/browser/components/ErrorBoundary/index.d.ts.map +1 -1
  13. package/dist/browser/components/ErrorRender/ErrorAlert.d.cts +1 -0
  14. package/dist/browser/components/ErrorRender/ErrorAlert.d.cts.map +1 -1
  15. package/dist/browser/components/ErrorRender/ErrorAlert.d.mts +1 -0
  16. package/dist/browser/components/ErrorRender/ErrorAlert.d.mts.map +1 -1
  17. package/dist/browser/components/ErrorRender/ErrorAlert.d.ts +1 -0
  18. package/dist/browser/components/ErrorRender/ErrorAlert.d.ts.map +1 -1
  19. package/dist/browser/components/ErrorRender/Render.d.cts +2 -1
  20. package/dist/browser/components/ErrorRender/Render.d.cts.map +1 -1
  21. package/dist/browser/components/ErrorRender/Render.d.mts +2 -1
  22. package/dist/browser/components/ErrorRender/Render.d.mts.map +1 -1
  23. package/dist/browser/components/ErrorRender/Render.d.ts +2 -1
  24. package/dist/browser/components/ErrorRender/Render.d.ts.map +1 -1
  25. package/dist/browser/components/ErrorRender/index.d.cts +3 -3
  26. package/dist/browser/components/ErrorRender/index.d.cts.map +1 -1
  27. package/dist/browser/components/ErrorRender/index.d.mts +3 -3
  28. package/dist/browser/components/ErrorRender/index.d.mts.map +1 -1
  29. package/dist/browser/components/ErrorRender/index.d.ts +3 -3
  30. package/dist/browser/components/ErrorRender/index.d.ts.map +1 -1
  31. package/dist/browser/components/index.d.cts +2 -2
  32. package/dist/browser/components/index.d.mts +2 -2
  33. package/dist/browser/components/index.d.ts +2 -2
  34. package/dist/browser/contexts/ErrorReporter/Context.d.cts +1 -1
  35. package/dist/browser/contexts/ErrorReporter/Context.d.mts +1 -1
  36. package/dist/browser/contexts/ErrorReporter/Context.d.ts +1 -1
  37. package/dist/browser/contexts/ErrorReporter/Provider.d.cts +1 -0
  38. package/dist/browser/contexts/ErrorReporter/Provider.d.cts.map +1 -1
  39. package/dist/browser/contexts/ErrorReporter/Provider.d.mts +1 -0
  40. package/dist/browser/contexts/ErrorReporter/Provider.d.mts.map +1 -1
  41. package/dist/browser/contexts/ErrorReporter/Provider.d.ts +1 -0
  42. package/dist/browser/contexts/ErrorReporter/Provider.d.ts.map +1 -1
  43. package/dist/browser/contexts/ErrorReporter/index.d.cts +3 -3
  44. package/dist/browser/contexts/ErrorReporter/index.d.cts.map +1 -1
  45. package/dist/browser/contexts/ErrorReporter/index.d.mts +3 -3
  46. package/dist/browser/contexts/ErrorReporter/index.d.mts.map +1 -1
  47. package/dist/browser/contexts/ErrorReporter/index.d.ts +3 -3
  48. package/dist/browser/contexts/ErrorReporter/index.d.ts.map +1 -1
  49. package/dist/browser/contexts/ErrorReporter/useRollbar.d.cts +1 -1
  50. package/dist/browser/contexts/ErrorReporter/useRollbar.d.mts +1 -1
  51. package/dist/browser/contexts/ErrorReporter/useRollbar.d.ts +1 -1
  52. package/dist/browser/contexts/index.d.cts +1 -1
  53. package/dist/browser/contexts/index.d.mts +1 -1
  54. package/dist/browser/contexts/index.d.ts +1 -1
  55. package/dist/browser/index.cjs +100 -59
  56. package/dist/browser/index.cjs.map +1 -1
  57. package/dist/browser/index.d.cts +2 -2
  58. package/dist/browser/index.d.mts +2 -2
  59. package/dist/browser/index.d.ts +2 -2
  60. package/dist/browser/index.mjs +163 -0
  61. package/dist/browser/index.mjs.map +1 -0
  62. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.cts +2 -2
  63. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.cts.map +1 -1
  64. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.mts +2 -2
  65. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.mts.map +1 -1
  66. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.ts +2 -2
  67. package/dist/neutral/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +1 -1
  68. package/dist/neutral/components/ErrorBoundary/index.d.cts +1 -1
  69. package/dist/neutral/components/ErrorBoundary/index.d.cts.map +1 -1
  70. package/dist/neutral/components/ErrorBoundary/index.d.mts +1 -1
  71. package/dist/neutral/components/ErrorBoundary/index.d.mts.map +1 -1
  72. package/dist/neutral/components/ErrorBoundary/index.d.ts +1 -1
  73. package/dist/neutral/components/ErrorBoundary/index.d.ts.map +1 -1
  74. package/dist/neutral/components/ErrorRender/ErrorAlert.d.cts +1 -0
  75. package/dist/neutral/components/ErrorRender/ErrorAlert.d.cts.map +1 -1
  76. package/dist/neutral/components/ErrorRender/ErrorAlert.d.mts +1 -0
  77. package/dist/neutral/components/ErrorRender/ErrorAlert.d.mts.map +1 -1
  78. package/dist/neutral/components/ErrorRender/ErrorAlert.d.ts +1 -0
  79. package/dist/neutral/components/ErrorRender/ErrorAlert.d.ts.map +1 -1
  80. package/dist/neutral/components/ErrorRender/Render.d.cts +2 -1
  81. package/dist/neutral/components/ErrorRender/Render.d.cts.map +1 -1
  82. package/dist/neutral/components/ErrorRender/Render.d.mts +2 -1
  83. package/dist/neutral/components/ErrorRender/Render.d.mts.map +1 -1
  84. package/dist/neutral/components/ErrorRender/Render.d.ts +2 -1
  85. package/dist/neutral/components/ErrorRender/Render.d.ts.map +1 -1
  86. package/dist/neutral/components/ErrorRender/index.d.cts +3 -3
  87. package/dist/neutral/components/ErrorRender/index.d.cts.map +1 -1
  88. package/dist/neutral/components/ErrorRender/index.d.mts +3 -3
  89. package/dist/neutral/components/ErrorRender/index.d.mts.map +1 -1
  90. package/dist/neutral/components/ErrorRender/index.d.ts +3 -3
  91. package/dist/neutral/components/ErrorRender/index.d.ts.map +1 -1
  92. package/dist/neutral/components/index.d.cts +2 -2
  93. package/dist/neutral/components/index.d.mts +2 -2
  94. package/dist/neutral/components/index.d.ts +2 -2
  95. package/dist/neutral/contexts/ErrorReporter/Context.d.cts +1 -1
  96. package/dist/neutral/contexts/ErrorReporter/Context.d.mts +1 -1
  97. package/dist/neutral/contexts/ErrorReporter/Context.d.ts +1 -1
  98. package/dist/neutral/contexts/ErrorReporter/Provider.d.cts +1 -0
  99. package/dist/neutral/contexts/ErrorReporter/Provider.d.cts.map +1 -1
  100. package/dist/neutral/contexts/ErrorReporter/Provider.d.mts +1 -0
  101. package/dist/neutral/contexts/ErrorReporter/Provider.d.mts.map +1 -1
  102. package/dist/neutral/contexts/ErrorReporter/Provider.d.ts +1 -0
  103. package/dist/neutral/contexts/ErrorReporter/Provider.d.ts.map +1 -1
  104. package/dist/neutral/contexts/ErrorReporter/index.d.cts +3 -3
  105. package/dist/neutral/contexts/ErrorReporter/index.d.cts.map +1 -1
  106. package/dist/neutral/contexts/ErrorReporter/index.d.mts +3 -3
  107. package/dist/neutral/contexts/ErrorReporter/index.d.mts.map +1 -1
  108. package/dist/neutral/contexts/ErrorReporter/index.d.ts +3 -3
  109. package/dist/neutral/contexts/ErrorReporter/index.d.ts.map +1 -1
  110. package/dist/neutral/contexts/ErrorReporter/useRollbar.d.cts +1 -1
  111. package/dist/neutral/contexts/ErrorReporter/useRollbar.d.mts +1 -1
  112. package/dist/neutral/contexts/ErrorReporter/useRollbar.d.ts +1 -1
  113. package/dist/neutral/contexts/index.d.cts +1 -1
  114. package/dist/neutral/contexts/index.d.mts +1 -1
  115. package/dist/neutral/contexts/index.d.ts +1 -1
  116. package/dist/neutral/index.cjs +100 -59
  117. package/dist/neutral/index.cjs.map +1 -1
  118. package/dist/neutral/index.d.cts +2 -2
  119. package/dist/neutral/index.d.mts +2 -2
  120. package/dist/neutral/index.d.ts +2 -2
  121. package/dist/neutral/index.mjs +163 -0
  122. package/dist/neutral/index.mjs.map +1 -0
  123. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.cts +2 -2
  124. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.cts.map +1 -1
  125. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.mts +2 -2
  126. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.mts.map +1 -1
  127. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.ts +2 -2
  128. package/dist/node/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +1 -1
  129. package/dist/node/components/ErrorBoundary/index.d.cts +1 -1
  130. package/dist/node/components/ErrorBoundary/index.d.cts.map +1 -1
  131. package/dist/node/components/ErrorBoundary/index.d.mts +1 -1
  132. package/dist/node/components/ErrorBoundary/index.d.mts.map +1 -1
  133. package/dist/node/components/ErrorBoundary/index.d.ts +1 -1
  134. package/dist/node/components/ErrorBoundary/index.d.ts.map +1 -1
  135. package/dist/node/components/ErrorRender/ErrorAlert.d.cts +1 -0
  136. package/dist/node/components/ErrorRender/ErrorAlert.d.cts.map +1 -1
  137. package/dist/node/components/ErrorRender/ErrorAlert.d.mts +1 -0
  138. package/dist/node/components/ErrorRender/ErrorAlert.d.mts.map +1 -1
  139. package/dist/node/components/ErrorRender/ErrorAlert.d.ts +1 -0
  140. package/dist/node/components/ErrorRender/ErrorAlert.d.ts.map +1 -1
  141. package/dist/node/components/ErrorRender/Render.d.cts +2 -1
  142. package/dist/node/components/ErrorRender/Render.d.cts.map +1 -1
  143. package/dist/node/components/ErrorRender/Render.d.mts +2 -1
  144. package/dist/node/components/ErrorRender/Render.d.mts.map +1 -1
  145. package/dist/node/components/ErrorRender/Render.d.ts +2 -1
  146. package/dist/node/components/ErrorRender/Render.d.ts.map +1 -1
  147. package/dist/node/components/ErrorRender/index.d.cts +3 -3
  148. package/dist/node/components/ErrorRender/index.d.cts.map +1 -1
  149. package/dist/node/components/ErrorRender/index.d.mts +3 -3
  150. package/dist/node/components/ErrorRender/index.d.mts.map +1 -1
  151. package/dist/node/components/ErrorRender/index.d.ts +3 -3
  152. package/dist/node/components/ErrorRender/index.d.ts.map +1 -1
  153. package/dist/node/components/index.d.cts +2 -2
  154. package/dist/node/components/index.d.mts +2 -2
  155. package/dist/node/components/index.d.ts +2 -2
  156. package/dist/node/contexts/ErrorReporter/Context.d.cts +1 -1
  157. package/dist/node/contexts/ErrorReporter/Context.d.mts +1 -1
  158. package/dist/node/contexts/ErrorReporter/Context.d.ts +1 -1
  159. package/dist/node/contexts/ErrorReporter/Provider.d.cts +1 -0
  160. package/dist/node/contexts/ErrorReporter/Provider.d.cts.map +1 -1
  161. package/dist/node/contexts/ErrorReporter/Provider.d.mts +1 -0
  162. package/dist/node/contexts/ErrorReporter/Provider.d.mts.map +1 -1
  163. package/dist/node/contexts/ErrorReporter/Provider.d.ts +1 -0
  164. package/dist/node/contexts/ErrorReporter/Provider.d.ts.map +1 -1
  165. package/dist/node/contexts/ErrorReporter/index.d.cts +3 -3
  166. package/dist/node/contexts/ErrorReporter/index.d.cts.map +1 -1
  167. package/dist/node/contexts/ErrorReporter/index.d.mts +3 -3
  168. package/dist/node/contexts/ErrorReporter/index.d.mts.map +1 -1
  169. package/dist/node/contexts/ErrorReporter/index.d.ts +3 -3
  170. package/dist/node/contexts/ErrorReporter/index.d.ts.map +1 -1
  171. package/dist/node/contexts/ErrorReporter/useRollbar.d.cts +1 -1
  172. package/dist/node/contexts/ErrorReporter/useRollbar.d.mts +1 -1
  173. package/dist/node/contexts/ErrorReporter/useRollbar.d.ts +1 -1
  174. package/dist/node/contexts/index.d.cts +1 -1
  175. package/dist/node/contexts/index.d.mts +1 -1
  176. package/dist/node/contexts/index.d.ts +1 -1
  177. package/dist/node/index.cjs +99 -59
  178. package/dist/node/index.cjs.map +1 -1
  179. package/dist/node/index.d.cts +2 -2
  180. package/dist/node/index.d.mts +2 -2
  181. package/dist/node/index.d.ts +2 -2
  182. package/dist/node/index.mjs +162 -0
  183. package/dist/node/index.mjs.map +1 -0
  184. package/package.json +13 -13
  185. package/src/components/ErrorBoundary/ThrownErrorBoundary.stories.tsx +8 -4
  186. package/src/components/ErrorBoundary/ThrownErrorBoundary.tsx +5 -5
  187. package/src/components/ErrorBoundary/index.ts +1 -1
  188. package/src/components/ErrorRender/ErrorAlert.stories.tsx +1 -2
  189. package/src/components/ErrorRender/ErrorAlert.tsx +18 -14
  190. package/src/components/ErrorRender/Render.tsx +15 -12
  191. package/src/components/ErrorRender/index.ts +3 -3
  192. package/src/components/index.ts +2 -2
  193. package/src/contexts/ErrorReporter/Context.ts +1 -1
  194. package/src/contexts/ErrorReporter/Provider.stories.tsx +11 -4
  195. package/src/contexts/ErrorReporter/Provider.tsx +3 -2
  196. package/src/contexts/ErrorReporter/index.ts +3 -3
  197. package/src/contexts/ErrorReporter/useRollbar.tsx +1 -1
  198. package/src/contexts/index.ts +1 -1
  199. package/src/index.ts +2 -2
  200. package/dist/browser/index.js +0 -130
  201. package/dist/browser/index.js.map +0 -1
  202. package/dist/neutral/index.js +0 -130
  203. package/dist/neutral/index.js.map +0 -1
  204. package/dist/node/index.js +0 -130
  205. package/dist/node/index.js.map +0 -1
@@ -2,6 +2,7 @@ import { ExitToApp as ExitIcon } from '@mui/icons-material'
2
2
  import { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'
3
3
  import { ButtonEx } from '@xylabs/react-button'
4
4
  import { ModuleError } from '@xyo-network/payload-model'
5
+ import React from 'react'
5
6
 
6
7
  export interface ErrorAlertProps extends AlertProps {
7
8
  error?: ModuleError | Error | string
@@ -11,7 +12,6 @@ export interface ErrorAlertProps extends AlertProps {
11
12
  scope?: string
12
13
  }
13
14
 
14
- // eslint-disable-next-line deprecation/deprecation
15
15
  export const ErrorAlert: React.FC<ErrorAlertProps> = ({
16
16
  title = 'Whoops! Something went wrong',
17
17
  onCancel,
@@ -24,25 +24,29 @@ export const ErrorAlert: React.FC<ErrorAlertProps> = ({
24
24
  return (
25
25
  <Alert severity="error" {...props}>
26
26
  <AlertTitle>{title}</AlertTitle>
27
- {finalScope ?
28
- <div>
29
- <Typography variant="caption" mr={0.5} fontWeight="bold">
30
- Scope:
31
- </Typography>
32
- <Typography variant="caption">{finalScope}</Typography>
33
- </div>
34
- : null}
27
+ {finalScope
28
+ ? (
29
+ <div>
30
+ <Typography variant="caption" mr={0.5} fontWeight="bold">
31
+ Scope:
32
+ </Typography>
33
+ <Typography variant="caption">{finalScope}</Typography>
34
+ </div>
35
+ )
36
+ : null}
35
37
  <div>
36
38
  <Typography variant="caption" mr={0.5} fontWeight="bold">
37
39
  Error:
38
40
  </Typography>
39
41
  <Typography variant="caption">{typeof error === 'string' ? error : error?.message}</Typography>
40
42
  </div>
41
- {onCancel ?
42
- <ButtonEx variant="outlined" size="small" onClick={onCancel} position="absolute" style={{ right: 8, top: 8 }}>
43
- <ExitIcon fontSize="small" />
44
- </ButtonEx>
45
- : null}
43
+ {onCancel
44
+ ? (
45
+ <ButtonEx variant="outlined" size="small" onClick={onCancel} position="absolute" style={{ right: 8, top: 8 }}>
46
+ <ExitIcon fontSize="small" />
47
+ </ButtonEx>
48
+ )
49
+ : null}
46
50
  </Alert>
47
51
  )
48
52
  }
@@ -1,8 +1,8 @@
1
1
  import { FlexCol } from '@xylabs/react-flexbox'
2
- import { useEffect } from 'react'
2
+ import React, { useEffect } from 'react'
3
3
 
4
- import { ErrorAlert } from './ErrorAlert.js'
5
- import { ErrorRenderProps } from './Props.js'
4
+ import { ErrorAlert } from './ErrorAlert.tsx'
5
+ import { ErrorRenderProps } from './Props.ts'
6
6
 
7
7
  export const ErrorRender: React.FC<ErrorRenderProps> = ({
8
8
  onCancel,
@@ -27,14 +27,17 @@ export const ErrorRender: React.FC<ErrorRenderProps> = ({
27
27
  }
28
28
  }, [location])
29
29
 
30
- return error ?
31
- <FlexCol alignItems="stretch" {...props}>
32
- {noErrorDisplay ?
33
- customError
34
- : <FlexCol alignItems="center" {...props}>
35
- <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} scope={scope} />
36
- </FlexCol>
37
- }
38
- </FlexCol>
30
+ return error
31
+ ? (
32
+ <FlexCol alignItems="stretch" {...props}>
33
+ {noErrorDisplay
34
+ ? customError
35
+ : (
36
+ <FlexCol alignItems="center" {...props}>
37
+ <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} scope={scope} />
38
+ </FlexCol>
39
+ )}
40
+ </FlexCol>
41
+ )
39
42
  : (<>{children}</> ?? null)
40
43
  }
@@ -1,3 +1,3 @@
1
- export * from './ErrorAlert.js'
2
- export * from './Props.js'
3
- export * from './Render.js'
1
+ export * from './ErrorAlert.tsx'
2
+ export * from './Props.ts'
3
+ export * from './Render.tsx'
@@ -1,2 +1,2 @@
1
- export * from './ErrorBoundary/index.js'
2
- export * from './ErrorRender/index.js'
1
+ export * from './ErrorBoundary/index.ts'
2
+ export * from './ErrorRender/index.ts'
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react'
2
2
 
3
- import { ErrorReporterContextState } from './State.js'
3
+ import { ErrorReporterContextState } from './State.ts'
4
4
 
5
5
  export const ErrorReporterContext = createContext<ErrorReporterContextState>({})
@@ -1,9 +1,10 @@
1
1
  import { Typography } from '@mui/material'
2
2
  import { Meta, StoryFn } from '@storybook/react'
3
+ import React from 'react'
3
4
  import Rollbar from 'rollbar'
4
5
 
5
- import { ErrorReporterProvider } from './Provider.js'
6
- import { useRollbar } from './useRollbar.js'
6
+ import { ErrorReporterProvider } from './Provider.tsx'
7
+ import { useRollbar } from './useRollbar.tsx'
7
8
 
8
9
  const StorybookEntry = {
9
10
  argTypes: {},
@@ -20,7 +21,14 @@ const RollbarComponent = () => {
20
21
  const { rollbar } = useRollbar()
21
22
  const rollbarFound = typeof rollbar?.error === 'function'
22
23
 
23
- return <Typography color={rollbarFound ? 'green' : 'red'}>Rollbar instance {rollbarFound ? '' : 'NOT'} found from context!</Typography>
24
+ return (
25
+ <Typography color={rollbarFound ? 'green' : 'red'}>
26
+ Rollbar instance
27
+ {rollbarFound ? '' : 'NOT'}
28
+ {' '}
29
+ found from context!
30
+ </Typography>
31
+ )
24
32
  }
25
33
 
26
34
  const Template: StoryFn<typeof ErrorReporterProvider> = () => {
@@ -36,5 +44,4 @@ const Default = Template.bind({})
36
44
 
37
45
  export { Default }
38
46
 
39
- // eslint-disable-next-line import/no-default-export
40
47
  export default StorybookEntry
@@ -1,8 +1,8 @@
1
1
  import { WithChildren } from '@xylabs/react-shared'
2
- import { useEffect, useState } from 'react'
2
+ import React, { useEffect, useState } from 'react'
3
3
  import Rollbar from 'rollbar'
4
4
 
5
- import { ErrorReporterContext } from './Context.js'
5
+ import { ErrorReporterContext } from './Context.ts'
6
6
 
7
7
  export interface ErrorReporterProviderProps {
8
8
  rollbar: Rollbar
@@ -17,6 +17,7 @@ const ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>>
17
17
  }
18
18
  }, [rollbar, rollbarInstance])
19
19
 
20
+ // eslint-disable-next-line @eslint-react/no-unstable-context-value
20
21
  return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>
21
22
  }
22
23
 
@@ -1,3 +1,3 @@
1
- export * from './Provider.js'
2
- export * from './State.js'
3
- export * from './useRollbar.js'
1
+ export * from './Provider.tsx'
2
+ export * from './State.ts'
3
+ export * from './useRollbar.tsx'
@@ -1,6 +1,6 @@
1
1
  import { useContext } from 'react'
2
2
 
3
- import { ErrorReporterContext } from './Context.js'
3
+ import { ErrorReporterContext } from './Context.ts'
4
4
 
5
5
  const useRollbar = () => {
6
6
  const context = useContext(ErrorReporterContext)
@@ -1 +1 @@
1
- export * from './ErrorReporter/index.js'
1
+ export * from './ErrorReporter/index.ts'
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './components/index.js'
2
- export * from './contexts/index.js'
1
+ export * from './components/index.ts'
2
+ export * from './contexts/index.ts'
@@ -1,130 +0,0 @@
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 = ({
11
- title = "Whoops! Something went wrong",
12
- onCancel,
13
- error = "An unknown error occurred",
14
- errorContext,
15
- scope,
16
- ...props
17
- }) => {
18
- const finalScope = scope ?? errorContext;
19
- return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
20
- /* @__PURE__ */ jsx(AlertTitle, { children: title }),
21
- finalScope ? /* @__PURE__ */ jsxs("div", { children: [
22
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Scope:" }),
23
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: finalScope })
24
- ] }) : null,
25
- /* @__PURE__ */ jsxs("div", { children: [
26
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
27
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: typeof error === "string" ? error : error?.message })
28
- ] }),
29
- onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
30
- ] });
31
- };
32
-
33
- // src/components/ErrorRender/Render.tsx
34
- import { FlexCol } from "@xylabs/react-flexbox";
35
- import { useEffect } from "react";
36
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
37
- var ErrorRender = ({
38
- onCancel,
39
- error,
40
- noErrorDisplay = false,
41
- customError = null,
42
- children,
43
- errorContext,
44
- scope,
45
- useLocation,
46
- ...props
47
- }) => {
48
- const location = useLocation?.();
49
- useEffect(() => {
50
- if (location) {
51
- location.state = {
52
- from: {
53
- pathname: window.location.pathname
54
- }
55
- };
56
- }
57
- }, [location]);
58
- return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel, scope }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
59
- };
60
-
61
- // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
62
- import { jsx as jsx3 } from "react/jsx-runtime";
63
- var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
64
- state = {
65
- xyoError: void 0
66
- };
67
- static getDerivedStateFromError(error) {
68
- return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
69
- }
70
- static normalizeError(error) {
71
- return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
72
- }
73
- componentDidCatch(error, errorInfo) {
74
- const { rethrow, rollbar } = this.props;
75
- const { xyoError } = this.state;
76
- rollbar?.error(error);
77
- console.error("Error:", xyoError, errorInfo);
78
- if (rethrow) {
79
- throw error;
80
- }
81
- }
82
- render() {
83
- const { xyoError } = this.state;
84
- const { children, boundaryName, errorComponent, scope, title } = this.props;
85
- if (xyoError) {
86
- if (errorComponent) {
87
- return errorComponent(xyoError);
88
- }
89
- return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary`, scope, title });
90
- }
91
- return children;
92
- }
93
- };
94
-
95
- // src/contexts/ErrorReporter/Provider.tsx
96
- import { useEffect as useEffect2, useState } from "react";
97
-
98
- // src/contexts/ErrorReporter/Context.ts
99
- import { createContext } from "react";
100
- var ErrorReporterContext = createContext({});
101
-
102
- // src/contexts/ErrorReporter/Provider.tsx
103
- import { jsx as jsx4 } from "react/jsx-runtime";
104
- var ErrorReporterProvider = ({ children, rollbar }) => {
105
- const [rollbarInstance, setRollBarInstance] = useState();
106
- useEffect2(() => {
107
- if (rollbarInstance) {
108
- setRollBarInstance(rollbarInstance);
109
- }
110
- }, [rollbar, rollbarInstance]);
111
- return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
112
- };
113
-
114
- // src/contexts/ErrorReporter/useRollbar.tsx
115
- import { useContext } from "react";
116
- var useRollbar = () => {
117
- const context = useContext(ErrorReporterContext);
118
- if (context === void 0) {
119
- console.warn("useRollbar must be used within a ErrorReporterContext");
120
- }
121
- return context ?? {};
122
- };
123
- export {
124
- ErrorAlert,
125
- ErrorRender,
126
- ErrorReporterProvider,
127
- ThrownErrorBoundary,
128
- useRollbar
129
- };
130
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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/index.js'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n scope?: string\n title?: string\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, scope, title } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />\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 | string\n /** @deprecated use scope instead */\n errorContext?: string\n onCancel?: () => void\n scope?: string\n}\n\n// eslint-disable-next-line deprecation/deprecation\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({\n title = 'Whoops! Something went wrong',\n onCancel,\n error = 'An unknown error occurred',\n errorContext,\n scope,\n ...props\n}) => {\n const finalScope = scope ?? errorContext\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>{title}</AlertTitle>\n {finalScope ?\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Scope:\n </Typography>\n <Typography variant=\"caption\">{finalScope}</Typography>\n </div>\n : null}\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{typeof error === 'string' ? error : error?.message}</Typography>\n </div>\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'\n\nimport { ErrorAlert } from './ErrorAlert.js'\nimport { ErrorRenderProps } from './Props.js'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n scope,\n useLocation,\n ...props\n}) => {\n const location = useLocation?.()\n useEffect(() => {\n if (location) {\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 }\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} scope={scope} />\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.js'\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.js'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context.js'\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;AAuBnB,cAEE,YAFF;AAXC,IAAM,aAAwC,CAAC;AAAA,EACpD,QAAQ;AAAA,EACR;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,aAAa,SAAS;AAC5B,SACE,qBAAC,SAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,wBAAC,cAAY,iBAAM;AAAA,IAClB,aACC,qBAAC,SACC;AAAA,0BAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,MACA,oBAAC,cAAW,SAAQ,WAAW,sBAAW;AAAA,OAC5C,IACA;AAAA,IACF,qBAAC,SACC;AAAA,0BAAC,cAAW,SAAQ,WAAU,IAAI,KAAK,YAAW,QAAO,oBAEzD;AAAA,MACA,oBAAC,cAAW,SAAQ,WAAW,iBAAO,UAAU,WAAW,QAAQ,OAAO,SAAQ;AAAA,OACpF;AAAA,IACC,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/CA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAiCd,SAIL,UAJK,OAAAA,YAAA;AA5BL,IAAM,cAA0C,CAAC;AAAA,EACtD;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd;AAAA,EAC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eAAO,eAAe,QAAQ;AAAA,MAChC;AACA,aAAO,gBAAAA,KAAC,eAAY,OAAO,UAAU,cAAc,GAAG,YAAY,aAAa,OAAc,OAAc;AAAA,IAC7G;AAEA,WAAO;AAAA,EACT;AACF;;;AG3DA,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,130 +0,0 @@
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 = ({
11
- title = "Whoops! Something went wrong",
12
- onCancel,
13
- error = "An unknown error occurred",
14
- errorContext,
15
- scope,
16
- ...props
17
- }) => {
18
- const finalScope = scope ?? errorContext;
19
- return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
20
- /* @__PURE__ */ jsx(AlertTitle, { children: title }),
21
- finalScope ? /* @__PURE__ */ jsxs("div", { children: [
22
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Scope:" }),
23
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: finalScope })
24
- ] }) : null,
25
- /* @__PURE__ */ jsxs("div", { children: [
26
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
27
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: typeof error === "string" ? error : error?.message })
28
- ] }),
29
- onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
30
- ] });
31
- };
32
-
33
- // src/components/ErrorRender/Render.tsx
34
- import { FlexCol } from "@xylabs/react-flexbox";
35
- import { useEffect } from "react";
36
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
37
- var ErrorRender = ({
38
- onCancel,
39
- error,
40
- noErrorDisplay = false,
41
- customError = null,
42
- children,
43
- errorContext,
44
- scope,
45
- useLocation,
46
- ...props
47
- }) => {
48
- const location = useLocation?.();
49
- useEffect(() => {
50
- if (location) {
51
- location.state = {
52
- from: {
53
- pathname: window.location.pathname
54
- }
55
- };
56
- }
57
- }, [location]);
58
- return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel, scope }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
59
- };
60
-
61
- // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
62
- import { jsx as jsx3 } from "react/jsx-runtime";
63
- var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
64
- state = {
65
- xyoError: void 0
66
- };
67
- static getDerivedStateFromError(error) {
68
- return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
69
- }
70
- static normalizeError(error) {
71
- return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
72
- }
73
- componentDidCatch(error, errorInfo) {
74
- const { rethrow, rollbar } = this.props;
75
- const { xyoError } = this.state;
76
- rollbar?.error(error);
77
- console.error("Error:", xyoError, errorInfo);
78
- if (rethrow) {
79
- throw error;
80
- }
81
- }
82
- render() {
83
- const { xyoError } = this.state;
84
- const { children, boundaryName, errorComponent, scope, title } = this.props;
85
- if (xyoError) {
86
- if (errorComponent) {
87
- return errorComponent(xyoError);
88
- }
89
- return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary`, scope, title });
90
- }
91
- return children;
92
- }
93
- };
94
-
95
- // src/contexts/ErrorReporter/Provider.tsx
96
- import { useEffect as useEffect2, useState } from "react";
97
-
98
- // src/contexts/ErrorReporter/Context.ts
99
- import { createContext } from "react";
100
- var ErrorReporterContext = createContext({});
101
-
102
- // src/contexts/ErrorReporter/Provider.tsx
103
- import { jsx as jsx4 } from "react/jsx-runtime";
104
- var ErrorReporterProvider = ({ children, rollbar }) => {
105
- const [rollbarInstance, setRollBarInstance] = useState();
106
- useEffect2(() => {
107
- if (rollbarInstance) {
108
- setRollBarInstance(rollbarInstance);
109
- }
110
- }, [rollbar, rollbarInstance]);
111
- return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
112
- };
113
-
114
- // src/contexts/ErrorReporter/useRollbar.tsx
115
- import { useContext } from "react";
116
- var useRollbar = () => {
117
- const context = useContext(ErrorReporterContext);
118
- if (context === void 0) {
119
- console.warn("useRollbar must be used within a ErrorReporterContext");
120
- }
121
- return context ?? {};
122
- };
123
- export {
124
- ErrorAlert,
125
- ErrorRender,
126
- ErrorReporterProvider,
127
- ThrownErrorBoundary,
128
- useRollbar
129
- };
130
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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/index.js'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n scope?: string\n title?: string\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, scope, title } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />\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 | string\n /** @deprecated use scope instead */\n errorContext?: string\n onCancel?: () => void\n scope?: string\n}\n\n// eslint-disable-next-line deprecation/deprecation\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({\n title = 'Whoops! Something went wrong',\n onCancel,\n error = 'An unknown error occurred',\n errorContext,\n scope,\n ...props\n}) => {\n const finalScope = scope ?? errorContext\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>{title}</AlertTitle>\n {finalScope ?\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Scope:\n </Typography>\n <Typography variant=\"caption\">{finalScope}</Typography>\n </div>\n : null}\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{typeof error === 'string' ? error : error?.message}</Typography>\n </div>\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'\n\nimport { ErrorAlert } from './ErrorAlert.js'\nimport { ErrorRenderProps } from './Props.js'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n scope,\n useLocation,\n ...props\n}) => {\n const location = useLocation?.()\n useEffect(() => {\n if (location) {\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 }\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} scope={scope} />\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.js'\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.js'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context.js'\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;AAuBnB,cAEE,YAFF;AAXC,IAAM,aAAwC,CAAC;AAAA,EACpD,QAAQ;AAAA,EACR;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,aAAa,SAAS;AAC5B,SACE,qBAAC,SAAM,UAAS,SAAS,GAAG,OAC1B;AAAA,wBAAC,cAAY,iBAAM;AAAA,IAClB,aACC,qBAAC,SACC;AAAA,0BAAC,cAAW,SAAQ,WAAU,IAAI,KAAK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B,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,130 +0,0 @@
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 = ({
11
- title = "Whoops! Something went wrong",
12
- onCancel,
13
- error = "An unknown error occurred",
14
- errorContext,
15
- scope,
16
- ...props
17
- }) => {
18
- const finalScope = scope ?? errorContext;
19
- return /* @__PURE__ */ jsxs(Alert, { severity: "error", ...props, children: [
20
- /* @__PURE__ */ jsx(AlertTitle, { children: title }),
21
- finalScope ? /* @__PURE__ */ jsxs("div", { children: [
22
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Scope:" }),
23
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: finalScope })
24
- ] }) : null,
25
- /* @__PURE__ */ jsxs("div", { children: [
26
- /* @__PURE__ */ jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
27
- /* @__PURE__ */ jsx(Typography, { variant: "caption", children: typeof error === "string" ? error : error == null ? void 0 : error.message })
28
- ] }),
29
- onCancel ? /* @__PURE__ */ jsx(ButtonEx, { variant: "outlined", size: "small", onClick: onCancel, position: "absolute", style: { right: 8, top: 8 }, children: /* @__PURE__ */ jsx(ExitIcon, { fontSize: "small" }) }) : null
30
- ] });
31
- };
32
-
33
- // src/components/ErrorRender/Render.tsx
34
- import { FlexCol } from "@xylabs/react-flexbox";
35
- import { useEffect } from "react";
36
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
37
- var ErrorRender = ({
38
- onCancel,
39
- error,
40
- noErrorDisplay = false,
41
- customError = null,
42
- children,
43
- errorContext,
44
- scope,
45
- useLocation,
46
- ...props
47
- }) => {
48
- const location = useLocation == null ? void 0 : useLocation();
49
- useEffect(() => {
50
- if (location) {
51
- location.state = {
52
- from: {
53
- pathname: window.location.pathname
54
- }
55
- };
56
- }
57
- }, [location]);
58
- return error ? /* @__PURE__ */ jsx2(FlexCol, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx2(FlexCol, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx2(ErrorAlert, { error, errorContext, onCancel, scope }) }) }) : /* @__PURE__ */ jsx2(Fragment, { children }) ?? null;
59
- };
60
-
61
- // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
62
- import { jsx as jsx3 } from "react/jsx-runtime";
63
- var ThrownErrorBoundary = class _ThrownErrorBoundary extends Component {
64
- state = {
65
- xyoError: void 0
66
- };
67
- static getDerivedStateFromError(error) {
68
- return { hasError: true, xyoError: _ThrownErrorBoundary.normalizeError(error) };
69
- }
70
- static normalizeError(error) {
71
- return error.schema === ModuleErrorSchema ? error : { message: error.message, schema: ModuleErrorSchema, sources: [] };
72
- }
73
- componentDidCatch(error, errorInfo) {
74
- const { rethrow, rollbar } = this.props;
75
- const { xyoError } = this.state;
76
- rollbar == null ? void 0 : rollbar.error(error);
77
- console.error("Error:", xyoError, errorInfo);
78
- if (rethrow) {
79
- throw error;
80
- }
81
- }
82
- render() {
83
- const { xyoError } = this.state;
84
- const { children, boundaryName, errorComponent, scope, title } = this.props;
85
- if (xyoError) {
86
- if (errorComponent) {
87
- return errorComponent(xyoError);
88
- }
89
- return /* @__PURE__ */ jsx3(ErrorRender, { error: xyoError, errorContext: `${boundaryName} Boundary`, scope, title });
90
- }
91
- return children;
92
- }
93
- };
94
-
95
- // src/contexts/ErrorReporter/Provider.tsx
96
- import { useEffect as useEffect2, useState } from "react";
97
-
98
- // src/contexts/ErrorReporter/Context.ts
99
- import { createContext } from "react";
100
- var ErrorReporterContext = createContext({});
101
-
102
- // src/contexts/ErrorReporter/Provider.tsx
103
- import { jsx as jsx4 } from "react/jsx-runtime";
104
- var ErrorReporterProvider = ({ children, rollbar }) => {
105
- const [rollbarInstance, setRollBarInstance] = useState();
106
- useEffect2(() => {
107
- if (rollbarInstance) {
108
- setRollBarInstance(rollbarInstance);
109
- }
110
- }, [rollbar, rollbarInstance]);
111
- return /* @__PURE__ */ jsx4(ErrorReporterContext.Provider, { value: { rollbar }, children });
112
- };
113
-
114
- // src/contexts/ErrorReporter/useRollbar.tsx
115
- import { useContext } from "react";
116
- var useRollbar = () => {
117
- const context = useContext(ErrorReporterContext);
118
- if (context === void 0) {
119
- console.warn("useRollbar must be used within a ErrorReporterContext");
120
- }
121
- return context ?? {};
122
- };
123
- export {
124
- ErrorAlert,
125
- ErrorRender,
126
- ErrorReporterProvider,
127
- ThrownErrorBoundary,
128
- useRollbar
129
- };
130
- //# sourceMappingURL=index.js.map