@contember/react-devbar 2.1.0-alpha.37 → 2.1.0-alpha.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/development/index.cjs +17 -0
  2. package/dist/development/index.cjs.map +1 -0
  3. package/dist/development/index.js +17 -0
  4. package/dist/development/index.js.map +1 -0
  5. package/dist/development/src/DevErrorManager.cjs +110 -0
  6. package/dist/development/src/DevErrorManager.cjs.map +1 -0
  7. package/dist/development/src/DevErrorManager.js +110 -0
  8. package/dist/development/src/DevErrorManager.js.map +1 -0
  9. package/dist/development/src/errorHandling.cjs +55 -0
  10. package/dist/development/src/errorHandling.cjs.map +1 -0
  11. package/dist/development/src/errorHandling.js +55 -0
  12. package/dist/development/src/errorHandling.js.map +1 -0
  13. package/dist/development/src/hooks/useCopyErrorMarkdown.cjs +101 -0
  14. package/dist/development/src/hooks/useCopyErrorMarkdown.cjs.map +1 -0
  15. package/dist/development/src/hooks/useCopyErrorMarkdown.js +101 -0
  16. package/dist/development/src/hooks/useCopyErrorMarkdown.js.map +1 -0
  17. package/dist/development/src/hooks/useParsedStacktrace.cjs +67 -0
  18. package/dist/development/src/hooks/useParsedStacktrace.cjs.map +1 -0
  19. package/dist/development/src/hooks/useParsedStacktrace.js +45 -0
  20. package/dist/development/src/hooks/useParsedStacktrace.js.map +1 -0
  21. package/dist/development/src/ui/DevBar/DevBar.cjs +193 -0
  22. package/dist/development/src/ui/DevBar/DevBar.cjs.map +1 -0
  23. package/dist/development/src/ui/DevBar/DevBar.js +193 -0
  24. package/dist/development/src/ui/DevBar/DevBar.js.map +1 -0
  25. package/dist/development/src/ui/DevError/DevError.cjs +33 -0
  26. package/dist/development/src/ui/DevError/DevError.cjs.map +1 -0
  27. package/dist/development/src/ui/DevError/DevError.js +33 -0
  28. package/dist/development/src/ui/DevError/DevError.js.map +1 -0
  29. package/dist/development/src/ui/DevError/DevErrorBadge.cjs +21 -0
  30. package/dist/development/src/ui/DevError/DevErrorBadge.cjs.map +1 -0
  31. package/dist/development/src/ui/DevError/DevErrorBadge.js +21 -0
  32. package/dist/development/src/ui/DevError/DevErrorBadge.js.map +1 -0
  33. package/dist/development/src/ui/DevError/DevErrorCopy.cjs +36 -0
  34. package/dist/development/src/ui/DevError/DevErrorCopy.cjs.map +1 -0
  35. package/dist/development/src/ui/DevError/DevErrorCopy.js +36 -0
  36. package/dist/development/src/ui/DevError/DevErrorCopy.js.map +1 -0
  37. package/dist/development/src/ui/DevError/DevErrorInner.cjs +79 -0
  38. package/dist/development/src/ui/DevError/DevErrorInner.cjs.map +1 -0
  39. package/dist/development/src/ui/DevError/DevErrorInner.js +79 -0
  40. package/dist/development/src/ui/DevError/DevErrorInner.js.map +1 -0
  41. package/dist/development/src/ui/DevError/DevErrorList.cjs +119 -0
  42. package/dist/development/src/ui/DevError/DevErrorList.cjs.map +1 -0
  43. package/dist/development/src/ui/DevError/DevErrorList.js +119 -0
  44. package/dist/development/src/ui/DevError/DevErrorList.js.map +1 -0
  45. package/dist/development/src/ui/DevError/StackTrace.cjs +82 -0
  46. package/dist/development/src/ui/DevError/StackTrace.cjs.map +1 -0
  47. package/dist/development/src/ui/DevError/StackTrace.js +82 -0
  48. package/dist/development/src/ui/DevError/StackTrace.js.map +1 -0
  49. package/dist/production/index.cjs +17 -0
  50. package/dist/production/index.cjs.map +1 -0
  51. package/dist/production/index.js +17 -0
  52. package/dist/production/index.js.map +1 -0
  53. package/dist/production/src/errorHandling.cjs +39 -0
  54. package/dist/production/src/errorHandling.cjs.map +1 -0
  55. package/dist/production/src/errorHandling.js +39 -0
  56. package/dist/production/src/errorHandling.js.map +1 -0
  57. package/dist/production/src/hooks/useCopyErrorMarkdown.cjs +101 -0
  58. package/dist/production/src/hooks/useCopyErrorMarkdown.cjs.map +1 -0
  59. package/dist/production/src/hooks/useCopyErrorMarkdown.js +101 -0
  60. package/dist/production/src/hooks/useCopyErrorMarkdown.js.map +1 -0
  61. package/dist/production/src/hooks/useParsedStacktrace.cjs +67 -0
  62. package/dist/production/src/hooks/useParsedStacktrace.cjs.map +1 -0
  63. package/dist/production/src/hooks/useParsedStacktrace.js +45 -0
  64. package/dist/production/src/hooks/useParsedStacktrace.js.map +1 -0
  65. package/dist/production/src/ui/DevBar/DevBar.cjs +125 -0
  66. package/dist/production/src/ui/DevBar/DevBar.cjs.map +1 -0
  67. package/dist/production/src/ui/DevBar/DevBar.js +125 -0
  68. package/dist/production/src/ui/DevBar/DevBar.js.map +1 -0
  69. package/dist/production/src/ui/DevError/DevError.cjs +13 -0
  70. package/dist/production/src/ui/DevError/DevError.cjs.map +1 -0
  71. package/dist/production/src/ui/DevError/DevError.js +13 -0
  72. package/dist/production/src/ui/DevError/DevError.js.map +1 -0
  73. package/dist/production/src/ui/DevError/DevErrorBadge.cjs +13 -0
  74. package/dist/production/src/ui/DevError/DevErrorBadge.cjs.map +1 -0
  75. package/dist/production/src/ui/DevError/DevErrorBadge.js +13 -0
  76. package/dist/production/src/ui/DevError/DevErrorBadge.js.map +1 -0
  77. package/dist/production/src/ui/DevError/DevErrorCopy.cjs +28 -0
  78. package/dist/production/src/ui/DevError/DevErrorCopy.cjs.map +1 -0
  79. package/dist/production/src/ui/DevError/DevErrorCopy.js +28 -0
  80. package/dist/production/src/ui/DevError/DevErrorCopy.js.map +1 -0
  81. package/dist/production/src/ui/DevError/DevErrorInner.cjs +23 -0
  82. package/dist/production/src/ui/DevError/DevErrorInner.cjs.map +1 -0
  83. package/dist/production/src/ui/DevError/DevErrorInner.js +23 -0
  84. package/dist/production/src/ui/DevError/DevErrorInner.js.map +1 -0
  85. package/dist/production/src/ui/DevError/DevErrorList.cjs +51 -0
  86. package/dist/production/src/ui/DevError/DevErrorList.cjs.map +1 -0
  87. package/dist/production/src/ui/DevError/DevErrorList.js +51 -0
  88. package/dist/production/src/ui/DevError/DevErrorList.js.map +1 -0
  89. package/dist/production/src/ui/DevError/StackTrace.cjs +39 -0
  90. package/dist/production/src/ui/DevError/StackTrace.cjs.map +1 -0
  91. package/dist/production/src/ui/DevError/StackTrace.js +39 -0
  92. package/dist/production/src/ui/DevError/StackTrace.js.map +1 -0
  93. package/dist/types/DevErrorManager.d.ts +15 -0
  94. package/dist/types/DevErrorManager.d.ts.map +1 -0
  95. package/dist/types/errorHandling.d.ts +6 -0
  96. package/dist/types/errorHandling.d.ts.map +1 -0
  97. package/dist/types/hooks/useCopyErrorMarkdown.d.ts +12 -0
  98. package/dist/types/hooks/useCopyErrorMarkdown.d.ts.map +1 -0
  99. package/dist/types/hooks/useParsedStacktrace.d.ts +10 -0
  100. package/dist/types/hooks/useParsedStacktrace.d.ts.map +1 -0
  101. package/dist/types/index.d.ts +5 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/types/tsconfig.tsbuildinfo +1 -0
  104. package/dist/types/ui/DevBar/DevBar.d.ts +13 -0
  105. package/dist/types/ui/DevBar/DevBar.d.ts.map +1 -0
  106. package/dist/types/ui/DevBar/index.d.ts +2 -0
  107. package/dist/types/ui/DevBar/index.d.ts.map +1 -0
  108. package/dist/types/ui/DevError/DevError.d.ts +6 -0
  109. package/dist/types/ui/DevError/DevError.d.ts.map +1 -0
  110. package/dist/types/ui/DevError/DevErrorBadge.d.ts +7 -0
  111. package/dist/types/ui/DevError/DevErrorBadge.d.ts.map +1 -0
  112. package/dist/types/ui/DevError/DevErrorCopy.d.ts +6 -0
  113. package/dist/types/ui/DevError/DevErrorCopy.d.ts.map +1 -0
  114. package/dist/types/ui/DevError/DevErrorInner.d.ts +7 -0
  115. package/dist/types/ui/DevError/DevErrorInner.d.ts.map +1 -0
  116. package/dist/types/ui/DevError/DevErrorList.d.ts +13 -0
  117. package/dist/types/ui/DevError/DevErrorList.d.ts.map +1 -0
  118. package/dist/types/ui/DevError/StackTrace.d.ts +5 -0
  119. package/dist/types/ui/DevError/StackTrace.d.ts.map +1 -0
  120. package/dist/types/ui/DevError/index.d.ts +5 -0
  121. package/dist/types/ui/DevError/index.d.ts.map +1 -0
  122. package/dist/types/ui/DevError/types.d.ts +15 -0
  123. package/dist/types/ui/DevError/types.d.ts.map +1 -0
  124. package/package.json +10 -10
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const errorHandling = require("./src/errorHandling.cjs");
4
+ const useParsedStacktrace = require("./src/hooks/useParsedStacktrace.cjs");
5
+ const DevBar = require("./src/ui/DevBar/DevBar.cjs");
6
+ const DevError = require("./src/ui/DevError/DevError.cjs");
7
+ const DevErrorBadge = require("./src/ui/DevError/DevErrorBadge.cjs");
8
+ const DevErrorList = require("./src/ui/DevError/DevErrorList.cjs");
9
+ exports.createErrorHandler = errorHandling.createErrorHandler;
10
+ exports.parseStacktrace = useParsedStacktrace.parseStacktrace;
11
+ exports.useProcessedError = useParsedStacktrace.useProcessedError;
12
+ exports.DevBar = DevBar.DevBar;
13
+ exports.DevPanel = DevBar.DevPanel;
14
+ exports.DevError = DevError.DevError;
15
+ exports.DevErrorBadge = DevErrorBadge.DevErrorBadge;
16
+ exports.DevErrorList = DevErrorList.DevErrorList;
17
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -0,0 +1,17 @@
1
+ import { createErrorHandler } from "./src/errorHandling.js";
2
+ import { parseStacktrace, useProcessedError } from "./src/hooks/useParsedStacktrace.js";
3
+ import { DevBar, DevPanel } from "./src/ui/DevBar/DevBar.js";
4
+ import { DevError } from "./src/ui/DevError/DevError.js";
5
+ import { DevErrorBadge } from "./src/ui/DevError/DevErrorBadge.js";
6
+ import { DevErrorList } from "./src/ui/DevError/DevErrorList.js";
7
+ export {
8
+ DevBar,
9
+ DevError,
10
+ DevErrorBadge,
11
+ DevErrorList,
12
+ DevPanel,
13
+ createErrorHandler,
14
+ parseStacktrace,
15
+ useProcessedError
16
+ };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxDevRuntime = require("react/jsx-dev-runtime");
4
+ const React = require("react");
5
+ const useParsedStacktrace = require("./hooks/useParsedStacktrace.cjs");
6
+ const DevErrorBadge = require("./ui/DevError/DevErrorBadge.cjs");
7
+ const DevErrorList = require("./ui/DevError/DevErrorList.cjs");
8
+ var __defProp = Object.defineProperty;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ class ErrorBus {
12
+ constructor() {
13
+ __publicField(this, "queue", []);
14
+ __publicField(this, "listener", null);
15
+ }
16
+ async handleError(source, error) {
17
+ const boxedError = { error, source };
18
+ if (!this.listener) {
19
+ this.queue.push(boxedError);
20
+ } else {
21
+ this.listener(boxedError);
22
+ }
23
+ }
24
+ register(listener) {
25
+ this.listener = listener;
26
+ this.queue.forEach(listener);
27
+ this.queue = [];
28
+ return () => {
29
+ this.listener = null;
30
+ };
31
+ }
32
+ }
33
+ const compareErrors = (a, b) => {
34
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
35
+ return false;
36
+ }
37
+ if (!("stack" in a) || !("stack" in b) || !("message" in a) || !("message" in b)) {
38
+ return false;
39
+ }
40
+ if (a.message !== b.message) {
41
+ return false;
42
+ }
43
+ if (a.stack !== b.stack) {
44
+ return false;
45
+ }
46
+ return true;
47
+ };
48
+ function DevErrorManager(props) {
49
+ const [errors, setErrors] = React.useState([]);
50
+ const [errIndex, setErrorIndex] = React.useState(0);
51
+ const [open, setOpen] = React.useState(false);
52
+ React.useEffect(
53
+ () => {
54
+ return props.bus.register((err) => {
55
+ setTimeout(
56
+ () => {
57
+ setErrors((errors2) => {
58
+ return !errors2.find((it) => compareErrors(it.error, err.error)) ? [err, ...errors2] : errors2;
59
+ });
60
+ setOpen(true);
61
+ },
62
+ 0
63
+ );
64
+ });
65
+ },
66
+ [props.bus]
67
+ );
68
+ const currentError = errors[errIndex];
69
+ const processedError = useParsedStacktrace.useProcessedError(currentError?.error);
70
+ React.useEffect(() => {
71
+ }, []);
72
+ if (!currentError) {
73
+ return null;
74
+ }
75
+ const onPrevious = () => setErrorIndex((it) => Math.max(0, it - 1));
76
+ const onNext = () => setErrorIndex((it) => Math.min(errors.length - 1, it + 1));
77
+ const onClose = () => setOpen(false);
78
+ const onClear = () => setErrors([]);
79
+ if (!open) {
80
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(DevErrorBadge.DevErrorBadge, { errorCount: errors.length, onOpen: () => setOpen(true), onClear }, void 0, false, {
81
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/DevErrorManager.tsx",
82
+ lineNumber: 94,
83
+ columnNumber: 10
84
+ }, this);
85
+ }
86
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(
87
+ DevErrorList.DevErrorList,
88
+ {
89
+ currentError: processedError,
90
+ currentErrorSource: currentError.source,
91
+ currentErrorIndex: errIndex,
92
+ errorCount: errors.length,
93
+ onPrevious,
94
+ onNext,
95
+ onClose,
96
+ onClear
97
+ },
98
+ void 0,
99
+ false,
100
+ {
101
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/DevErrorManager.tsx",
102
+ lineNumber: 97,
103
+ columnNumber: 3
104
+ },
105
+ this
106
+ );
107
+ }
108
+ exports.DevErrorManager = DevErrorManager;
109
+ exports.ErrorBus = ErrorBus;
110
+ //# sourceMappingURL=DevErrorManager.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevErrorManager.cjs","sources":["../../../../packages/react-devbar/src/DevErrorManager.tsx"],"sourcesContent":["import { DevErrorBadge, DevErrorList, ErrorType } from './ui/DevError'\nimport { useEffect, useState } from 'react'\nimport { useProcessedError } from './hooks/useParsedStacktrace'\n\nexport class ErrorBus {\n\tprivate queue: { error: ErrorType; source: string }[] = []\n\tprivate listener: null | ((error: { error: ErrorType; source: string }) => void) = null\n\n\tasync handleError(source: string, error: ErrorType) {\n\t\tconst boxedError = { error, source }\n\n\t\tif (!this.listener) {\n\t\t\tthis.queue.push(boxedError)\n\t\t} else {\n\t\t\tthis.listener(boxedError)\n\t\t}\n\t}\n\n\tregister(listener: (error: { error: ErrorType; source: string }) => void): () => void {\n\t\tthis.listener = listener\n\t\tthis.queue.forEach(listener)\n\t\tthis.queue = []\n\t\treturn () => {\n\t\t\tthis.listener = null\n\t\t}\n\t}\n}\n\nexport interface DevErrorManagerProps {\n\tbus: ErrorBus\n}\n\nconst compareErrors = (a: ErrorType, b: ErrorType) => {\n\tif (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n\t\treturn false\n\t}\n\tif (!('stack' in a) || !('stack' in b) || !('message' in a) || !('message' in b)) {\n\t\treturn false\n\t}\n\tif (a.message !== b.message) {\n\t\treturn false\n\t}\n\tif (a.stack !== b.stack) {\n\t\treturn false\n\t}\n\treturn true\n}\n\nexport function DevErrorManager(props: DevErrorManagerProps) {\n\tconst [errors, setErrors] = useState<{ error: ErrorType; source: string }[]>([])\n\tconst [errIndex, setErrorIndex] = useState(0)\n\tconst [open, setOpen] = useState(false)\n\n\tuseEffect(\n\t\t() => {\n\t\t\treturn props.bus.register(err => {\n\t\t\t\tsetTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetErrors(errors => {\n\t\t\t\t\t\t\treturn !errors.find(it => compareErrors(it.error, err.error)) ? [err, ...errors] : errors\n\t\t\t\t\t\t})\n\t\t\t\t\t\tsetOpen(true)\n\t\t\t\t\t},\n\t\t\t\t\t0,\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[props.bus],\n\t)\n\n\tconst currentError = errors[errIndex]\n\tconst processedError = useProcessedError(currentError?.error)\n\n\tuseEffect(() => {\n\t\tif (import.meta.hot) {\n\t\t\tconst cb = () => {\n\t\t\t\tsetOpen(false)\n\t\t\t}\n\t\t\timport.meta.hot.on('vite:afterUpdate', cb)\n\t\t\treturn () => {\n\t\t\t\timport.meta.hot?.off('vite:afterUpdate', cb)\n\t\t\t}\n\t\t}\n\t}, [])\n\n\tif (!currentError) {\n\t\treturn null\n\t}\n\tconst onPrevious = () => setErrorIndex(it => Math.max(0, it - 1))\n\tconst onNext = () => setErrorIndex(it => Math.min(errors.length - 1, it + 1))\n\tconst onClose = () => setOpen(false)\n\tconst onClear = () => setErrors([])\n\tif (!open) {\n\t\treturn <DevErrorBadge errorCount={errors.length} onOpen={() => setOpen(true)} onClear={onClear} />\n\t}\n\treturn (\n\t\t<DevErrorList\n\t\t\tcurrentError={processedError}\n\t\t\tcurrentErrorSource={currentError.source}\n\t\t\tcurrentErrorIndex={errIndex}\n\t\t\terrorCount={errors.length}\n\t\t\tonPrevious={onPrevious}\n\t\t\tonNext={onNext}\n\t\t\tonClose={onClose}\n\t\t\tonClear={onClear}\n\t\t/>\n\t)\n}\n"],"names":["useState","useEffect","errors","useProcessedError","jsxDEV","DevErrorBadge","DevErrorList"],"mappings":";;;;;;;;;;AAIO,MAAM,SAAS;AAAA,EAAf,cAAA;AACN,kBAAA,MAAQ,SAAgD,EAAC;AACzD,kBAAA,MAAQ,YAA2E,IAAA;AAAA,EAAA;AAAA,EAEnF,MAAM,YAAY,QAAgB,OAAkB;AACnD,UAAM,aAAa,EAAE,OAAO,OAAA;AAE5B,QAAI,CAAC,KAAK,UAAU;AACnB,WAAK,MAAM,KAAK,UAAU;AAAA,IAC3B,OAAO;AACN,WAAK,SAAS,UAAU;AAAA,IACzB;AAAA,EACD;AAAA,EAEA,SAAS,UAA6E;AACrF,SAAK,WAAW;AAChB,SAAK,MAAM,QAAQ,QAAQ;AAC3B,SAAK,QAAQ,CAAA;AACb,WAAO,MAAM;AACZ,WAAK,WAAW;AAAA,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AG,KAAK,CAAC,CAAC;AAChE,QAAM,SAAS,MAAM,cAAc,CAAA,OAAM,KAAK,IAAI,OAAO,SAAS,GAAG,KAAK,CAAC,CAAC;AAC5E,QAAM,UAAU,MAAM,QAAQ,KAAK;AACnC,QAAM,UAAU,MAAM,UAAU,EAAE;AAClC,MAAI,CAAC,MAAM;AACV,WAAOG,8BAAAA,OAACC,cAAAA,eAAA,EAAc,YAAY,OAAO,QAAQ,QAAQ,MAAM,QAAQ,IAAI,GAAG,QAAA,GAAvE,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAA,IAAyF;AAAA,EACjG;AACA,SACCD,8BAAAA;AAAAA,IAACE,aAAAA;AAAAA,IAAA;AAAA,MACA,cAAc;AAAA,MACd,oBAAoB,aAAa;AAAA,MACjC,mBAAmB;AAAA,MACnB,YAAY,OAAO;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IARD;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAA;AAAA,EAAA;AAWF;;;"}
@@ -0,0 +1,110 @@
1
+ import { jsxDEV } from "react/jsx-dev-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { useProcessedError } from "./hooks/useParsedStacktrace.js";
4
+ import { DevErrorBadge } from "./ui/DevError/DevErrorBadge.js";
5
+ import { DevErrorList } from "./ui/DevError/DevErrorList.js";
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ class ErrorBus {
10
+ constructor() {
11
+ __publicField(this, "queue", []);
12
+ __publicField(this, "listener", null);
13
+ }
14
+ async handleError(source, error) {
15
+ const boxedError = { error, source };
16
+ if (!this.listener) {
17
+ this.queue.push(boxedError);
18
+ } else {
19
+ this.listener(boxedError);
20
+ }
21
+ }
22
+ register(listener) {
23
+ this.listener = listener;
24
+ this.queue.forEach(listener);
25
+ this.queue = [];
26
+ return () => {
27
+ this.listener = null;
28
+ };
29
+ }
30
+ }
31
+ const compareErrors = (a, b) => {
32
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
33
+ return false;
34
+ }
35
+ if (!("stack" in a) || !("stack" in b) || !("message" in a) || !("message" in b)) {
36
+ return false;
37
+ }
38
+ if (a.message !== b.message) {
39
+ return false;
40
+ }
41
+ if (a.stack !== b.stack) {
42
+ return false;
43
+ }
44
+ return true;
45
+ };
46
+ function DevErrorManager(props) {
47
+ const [errors, setErrors] = useState([]);
48
+ const [errIndex, setErrorIndex] = useState(0);
49
+ const [open, setOpen] = useState(false);
50
+ useEffect(
51
+ () => {
52
+ return props.bus.register((err) => {
53
+ setTimeout(
54
+ () => {
55
+ setErrors((errors2) => {
56
+ return !errors2.find((it) => compareErrors(it.error, err.error)) ? [err, ...errors2] : errors2;
57
+ });
58
+ setOpen(true);
59
+ },
60
+ 0
61
+ );
62
+ });
63
+ },
64
+ [props.bus]
65
+ );
66
+ const currentError = errors[errIndex];
67
+ const processedError = useProcessedError(currentError?.error);
68
+ useEffect(() => {
69
+ }, []);
70
+ if (!currentError) {
71
+ return null;
72
+ }
73
+ const onPrevious = () => setErrorIndex((it) => Math.max(0, it - 1));
74
+ const onNext = () => setErrorIndex((it) => Math.min(errors.length - 1, it + 1));
75
+ const onClose = () => setOpen(false);
76
+ const onClear = () => setErrors([]);
77
+ if (!open) {
78
+ return /* @__PURE__ */ jsxDEV(DevErrorBadge, { errorCount: errors.length, onOpen: () => setOpen(true), onClear }, void 0, false, {
79
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/DevErrorManager.tsx",
80
+ lineNumber: 94,
81
+ columnNumber: 10
82
+ }, this);
83
+ }
84
+ return /* @__PURE__ */ jsxDEV(
85
+ DevErrorList,
86
+ {
87
+ currentError: processedError,
88
+ currentErrorSource: currentError.source,
89
+ currentErrorIndex: errIndex,
90
+ errorCount: errors.length,
91
+ onPrevious,
92
+ onNext,
93
+ onClose,
94
+ onClear
95
+ },
96
+ void 0,
97
+ false,
98
+ {
99
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/DevErrorManager.tsx",
100
+ lineNumber: 97,
101
+ columnNumber: 3
102
+ },
103
+ this
104
+ );
105
+ }
106
+ export {
107
+ DevErrorManager,
108
+ ErrorBus
109
+ };
110
+ //# sourceMappingURL=DevErrorManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevErrorManager.js","sources":["../../../../packages/react-devbar/src/DevErrorManager.tsx"],"sourcesContent":["import { DevErrorBadge, DevErrorList, ErrorType } from './ui/DevError'\nimport { useEffect, useState } from 'react'\nimport { useProcessedError } from './hooks/useParsedStacktrace'\n\nexport class ErrorBus {\n\tprivate queue: { error: ErrorType; source: string }[] = []\n\tprivate listener: null | ((error: { error: ErrorType; source: string }) => void) = null\n\n\tasync handleError(source: string, error: ErrorType) {\n\t\tconst boxedError = { error, source }\n\n\t\tif (!this.listener) {\n\t\t\tthis.queue.push(boxedError)\n\t\t} else {\n\t\t\tthis.listener(boxedError)\n\t\t}\n\t}\n\n\tregister(listener: (error: { error: ErrorType; source: string }) => void): () => void {\n\t\tthis.listener = listener\n\t\tthis.queue.forEach(listener)\n\t\tthis.queue = []\n\t\treturn () => {\n\t\t\tthis.listener = null\n\t\t}\n\t}\n}\n\nexport interface DevErrorManagerProps {\n\tbus: ErrorBus\n}\n\nconst compareErrors = (a: ErrorType, b: ErrorType) => {\n\tif (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n\t\treturn false\n\t}\n\tif (!('stack' in a) || !('stack' in b) || !('message' in a) || !('message' in b)) {\n\t\treturn false\n\t}\n\tif (a.message !== b.message) {\n\t\treturn false\n\t}\n\tif (a.stack !== b.stack) {\n\t\treturn false\n\t}\n\treturn true\n}\n\nexport function DevErrorManager(props: DevErrorManagerProps) {\n\tconst [errors, setErrors] = useState<{ error: ErrorType; source: string }[]>([])\n\tconst [errIndex, setErrorIndex] = useState(0)\n\tconst [open, setOpen] = useState(false)\n\n\tuseEffect(\n\t\t() => {\n\t\t\treturn props.bus.register(err => {\n\t\t\t\tsetTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetErrors(errors => {\n\t\t\t\t\t\t\treturn !errors.find(it => compareErrors(it.error, err.error)) ? [err, ...errors] : errors\n\t\t\t\t\t\t})\n\t\t\t\t\t\tsetOpen(true)\n\t\t\t\t\t},\n\t\t\t\t\t0,\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[props.bus],\n\t)\n\n\tconst currentError = errors[errIndex]\n\tconst processedError = useProcessedError(currentError?.error)\n\n\tuseEffect(() => {\n\t\tif (import.meta.hot) {\n\t\t\tconst cb = () => {\n\t\t\t\tsetOpen(false)\n\t\t\t}\n\t\t\timport.meta.hot.on('vite:afterUpdate', cb)\n\t\t\treturn () => {\n\t\t\t\timport.meta.hot?.off('vite:afterUpdate', cb)\n\t\t\t}\n\t\t}\n\t}, [])\n\n\tif (!currentError) {\n\t\treturn null\n\t}\n\tconst onPrevious = () => setErrorIndex(it => Math.max(0, it - 1))\n\tconst onNext = () => setErrorIndex(it => Math.min(errors.length - 1, it + 1))\n\tconst onClose = () => setOpen(false)\n\tconst onClear = () => setErrors([])\n\tif (!open) {\n\t\treturn <DevErrorBadge errorCount={errors.length} onOpen={() => setOpen(true)} onClear={onClear} />\n\t}\n\treturn (\n\t\t<DevErrorList\n\t\t\tcurrentError={processedError}\n\t\t\tcurrentErrorSource={currentError.source}\n\t\t\tcurrentErrorIndex={errIndex}\n\t\t\terrorCount={errors.length}\n\t\t\tonPrevious={onPrevious}\n\t\t\tonNext={onNext}\n\t\t\tonClose={onClose}\n\t\t\tonClear={onClear}\n\t\t/>\n\t)\n}\n"],"names":["errors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Runtime = require("react/jsx-dev-runtime");
4
+ const buffer = require("buffer");
5
+ const DevErrorManager = require("./DevErrorManager.cjs");
6
+ const getErrorContainer = () => {
7
+ const errorElementId = "__contember__dev__error__container__element";
8
+ let errorContainer = document.getElementById(errorElementId);
9
+ if (!errorContainer) {
10
+ errorContainer = document.createElement("div");
11
+ errorContainer.id = errorElementId;
12
+ document.body.appendChild(errorContainer);
13
+ }
14
+ return errorContainer;
15
+ };
16
+ const devErrorHandler = (renderer) => {
17
+ const errorBus = new DevErrorManager.ErrorBus();
18
+ window.Buffer = buffer.Buffer;
19
+ window.addEventListener("error", (e) => {
20
+ if (e.message.startsWith("ResizeObserver")) {
21
+ return;
22
+ }
23
+ errorBus.handleError("Unhandled error", e.error);
24
+ });
25
+ window.addEventListener("unhandledrejection", (e) => errorBus.handleError("Unhandled promise rejection", e.reason));
26
+ const origOnError = console.error;
27
+ console.error = (...args) => {
28
+ origOnError(...args);
29
+ for (const arg of args) {
30
+ if (arg instanceof Error) {
31
+ errorBus.handleError("Logged error", arg);
32
+ }
33
+ }
34
+ };
35
+ renderer(getErrorContainer(), /* @__PURE__ */ jsxDevRuntime.jsxDEV(DevErrorManager.DevErrorManager, { bus: errorBus }, void 0, false, {
36
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/errorHandling.tsx",
37
+ lineNumber: 42,
38
+ columnNumber: 32
39
+ }, void 0), () => {
40
+ });
41
+ return async (cb) => {
42
+ try {
43
+ await cb((e) => errorBus.handleError("Recoverable React error", e));
44
+ } catch (e) {
45
+ errorBus.handleError("Entrypoint crash", e);
46
+ }
47
+ };
48
+ };
49
+ const createErrorHandler = (renderer) => {
50
+ {
51
+ return devErrorHandler(renderer);
52
+ }
53
+ };
54
+ exports.createErrorHandler = createErrorHandler;
55
+ //# sourceMappingURL=errorHandling.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandling.cjs","sources":["../../../../packages/react-devbar/src/errorHandling.tsx"],"sourcesContent":["import { Buffer } from 'buffer'\nimport { DevErrorManager, ErrorBus } from './DevErrorManager'\nimport { ReactElement } from 'react'\n\nexport type ErrorReactRenderer = (domElement: Element, reactElement: ReactElement, onRecoverableError: (e: any) => void) => void\n\nconst getErrorContainer = () => {\n\tconst errorElementId = '__contember__dev__error__container__element'\n\tlet errorContainer = document.getElementById(errorElementId)\n\n\tif (!errorContainer) {\n\t\terrorContainer = document.createElement('div')\n\t\terrorContainer.id = errorElementId\n\t\tdocument.body.appendChild(errorContainer)\n\t}\n\n\treturn errorContainer\n}\n\nconst devErrorHandler = (renderer: ErrorReactRenderer): TryRun => {\n\tconst errorBus = new ErrorBus()\n\t;(window as any).Buffer = Buffer\n\twindow.addEventListener('error', e => {\n\t\tif (e.message.startsWith('ResizeObserver')) {\n\t\t\t// Apparently, this can be ignored: https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded\n\t\t\treturn\n\t\t}\n\t\terrorBus.handleError('Unhandled error', e.error)\n\t})\n\n\twindow.addEventListener('unhandledrejection', e => errorBus.handleError('Unhandled promise rejection', e.reason))\n\n\tconst origOnError = console.error\n\tconsole.error = (...args) => {\n\t\torigOnError(...args)\n\t\tfor (const arg of args) {\n\t\t\tif (arg instanceof Error) {\n\t\t\t\terrorBus.handleError('Logged error', arg)\n\t\t\t}\n\t\t}\n\t}\n\trenderer(getErrorContainer(), <DevErrorManager bus={errorBus} />, () => {})\n\n\treturn async cb => {\n\t\ttry {\n\t\t\tawait cb(e => errorBus.handleError('Recoverable React error', e))\n\t\t} catch (e) {\n\t\t\terrorBus.handleError('Entrypoint crash', e)\n\t\t}\n\t}\n}\n\ntype TryRun = <T>(cb: (onRecoverableError: (e: any) => void) => T | Promise<T>) => void\nconst prodErrorHandler = (renderer: ErrorReactRenderer): TryRun => {\n\tconst renderError = () => {\n\t\trenderer(getErrorContainer(), <h1>Fatal error</h1>, () => {})\n\t}\n\n\twindow.addEventListener('error', renderError)\n\twindow.addEventListener('unhandledrejection', renderError)\n\n\treturn async cb => {\n\t\ttry {\n\t\t\tawait cb(e => {\n\t\t\t\tconsole.warn(e)\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\trenderError()\n\t\t}\n\t}\n}\n\nexport const createErrorHandler = (renderer: ErrorReactRenderer) => {\n\tif (import.meta.env.DEV) {\n\t\treturn devErrorHandler(renderer)\n\t} else {\n\t\treturn prodErrorHandler(renderer)\n\t}\n}\n"],"names":["ErrorBus","Buffer","jsxDEV","DevErrorManager"],"mappings":";;;;;AAMA,MAAM,oBAAoB,MAAM;AAC/B,QAAM,iBAAiB;AACvB,MAAI,iBAAiB,SAAS,eAAe,cAAc;AAE3D,MAAI,CAAC,gBAAgB;AACpB,qBAAiB,SAAS,cAAc,KAAK;AAC7C,mBAAe,KAAK;AACpB,aAAS,KAAK,YAAY,cAAc;AAAA,EACzC;AAEA,SAAO;AACR;AAEA,MAAM,kBAAkB,CAAC,aAAyC;AACjE,QAAM,WAAW,IAAIA,yBAAA;AACnB,SAAe,SAASC,OAAAA;AAC1B,SAAO,iBAAiB,SAAS,CAAA,MAAK;AACrC,QAAI,EAAE,QAAQ,WAAW,gBAAgB,GAAG;AAE3C;AAAA,IACD;AACA,aAAS,YAAY,mBAAmB,EAAE,KAAK;AAAA,EAChD,CAAC;AAED,SAAO,iBAAiB,sBAAsB,CAAA,MAAK,SAAS,YAAY,+BAA+B,EAAE,MAAM,CAAC;AAEhH,QAAM,cAAc,QAAQ;AAC5B,UAAQ,QAAQ,IAAI,SAAS;AAC5B,gBAAY,GAAG,IAAI;AACnB,eAAW,OAAO,MAAM;AACvB,UAAI,eAAe,OAAO;AACzB,iBAAS,YAAY,gBAAgB,GAAG;AAAA,MACzC;AAAA,IACD;AAAA,EACD;AACA,WAAS,qBAAqBC,8BAAAA,OAACC,gBAAAA,iBAAA,EAAgB,KAAK,SAAA,GAAtB,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAA,MAAgC,GAAI,MAAM;AAAA,EAAC,CAAC;AAE1E,SAAO,OAAM,OAAM;AAClB,QAAI;AACH,YAAM,GAAG,CAAA,MAAK,SAAS,YAAY,2BAA2B,CAAC,CAAC;AAAA,IACjE,SAAS,GAAG;AACX,eAAS,YAAY,oBAAoB,CAAC;AAAA,IAC3C;AAAA,EACD;AACD;AAuBO,MAAM,qBAAqB,CAAC,aAAiC;AAC1C;AACxB,WAAO,gBAAgB,QAAQ;AAAA,EAChC;AAGD;;"}
@@ -0,0 +1,55 @@
1
+ import { jsxDEV } from "react/jsx-dev-runtime";
2
+ import { Buffer } from "buffer";
3
+ import { ErrorBus, DevErrorManager } from "./DevErrorManager.js";
4
+ const getErrorContainer = () => {
5
+ const errorElementId = "__contember__dev__error__container__element";
6
+ let errorContainer = document.getElementById(errorElementId);
7
+ if (!errorContainer) {
8
+ errorContainer = document.createElement("div");
9
+ errorContainer.id = errorElementId;
10
+ document.body.appendChild(errorContainer);
11
+ }
12
+ return errorContainer;
13
+ };
14
+ const devErrorHandler = (renderer) => {
15
+ const errorBus = new ErrorBus();
16
+ window.Buffer = Buffer;
17
+ window.addEventListener("error", (e) => {
18
+ if (e.message.startsWith("ResizeObserver")) {
19
+ return;
20
+ }
21
+ errorBus.handleError("Unhandled error", e.error);
22
+ });
23
+ window.addEventListener("unhandledrejection", (e) => errorBus.handleError("Unhandled promise rejection", e.reason));
24
+ const origOnError = console.error;
25
+ console.error = (...args) => {
26
+ origOnError(...args);
27
+ for (const arg of args) {
28
+ if (arg instanceof Error) {
29
+ errorBus.handleError("Logged error", arg);
30
+ }
31
+ }
32
+ };
33
+ renderer(getErrorContainer(), /* @__PURE__ */ jsxDEV(DevErrorManager, { bus: errorBus }, void 0, false, {
34
+ fileName: "/home/runner/work/contember/contember/packages/react-devbar/src/errorHandling.tsx",
35
+ lineNumber: 42,
36
+ columnNumber: 32
37
+ }, void 0), () => {
38
+ });
39
+ return async (cb) => {
40
+ try {
41
+ await cb((e) => errorBus.handleError("Recoverable React error", e));
42
+ } catch (e) {
43
+ errorBus.handleError("Entrypoint crash", e);
44
+ }
45
+ };
46
+ };
47
+ const createErrorHandler = (renderer) => {
48
+ {
49
+ return devErrorHandler(renderer);
50
+ }
51
+ };
52
+ export {
53
+ createErrorHandler
54
+ };
55
+ //# sourceMappingURL=errorHandling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandling.js","sources":["../../../../packages/react-devbar/src/errorHandling.tsx"],"sourcesContent":["import { Buffer } from 'buffer'\nimport { DevErrorManager, ErrorBus } from './DevErrorManager'\nimport { ReactElement } from 'react'\n\nexport type ErrorReactRenderer = (domElement: Element, reactElement: ReactElement, onRecoverableError: (e: any) => void) => void\n\nconst getErrorContainer = () => {\n\tconst errorElementId = '__contember__dev__error__container__element'\n\tlet errorContainer = document.getElementById(errorElementId)\n\n\tif (!errorContainer) {\n\t\terrorContainer = document.createElement('div')\n\t\terrorContainer.id = errorElementId\n\t\tdocument.body.appendChild(errorContainer)\n\t}\n\n\treturn errorContainer\n}\n\nconst devErrorHandler = (renderer: ErrorReactRenderer): TryRun => {\n\tconst errorBus = new ErrorBus()\n\t;(window as any).Buffer = Buffer\n\twindow.addEventListener('error', e => {\n\t\tif (e.message.startsWith('ResizeObserver')) {\n\t\t\t// Apparently, this can be ignored: https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded\n\t\t\treturn\n\t\t}\n\t\terrorBus.handleError('Unhandled error', e.error)\n\t})\n\n\twindow.addEventListener('unhandledrejection', e => errorBus.handleError('Unhandled promise rejection', e.reason))\n\n\tconst origOnError = console.error\n\tconsole.error = (...args) => {\n\t\torigOnError(...args)\n\t\tfor (const arg of args) {\n\t\t\tif (arg instanceof Error) {\n\t\t\t\terrorBus.handleError('Logged error', arg)\n\t\t\t}\n\t\t}\n\t}\n\trenderer(getErrorContainer(), <DevErrorManager bus={errorBus} />, () => {})\n\n\treturn async cb => {\n\t\ttry {\n\t\t\tawait cb(e => errorBus.handleError('Recoverable React error', e))\n\t\t} catch (e) {\n\t\t\terrorBus.handleError('Entrypoint crash', e)\n\t\t}\n\t}\n}\n\ntype TryRun = <T>(cb: (onRecoverableError: (e: any) => void) => T | Promise<T>) => void\nconst prodErrorHandler = (renderer: ErrorReactRenderer): TryRun => {\n\tconst renderError = () => {\n\t\trenderer(getErrorContainer(), <h1>Fatal error</h1>, () => {})\n\t}\n\n\twindow.addEventListener('error', renderError)\n\twindow.addEventListener('unhandledrejection', renderError)\n\n\treturn async cb => {\n\t\ttry {\n\t\t\tawait cb(e => {\n\t\t\t\tconsole.warn(e)\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\trenderError()\n\t\t}\n\t}\n}\n\nexport const createErrorHandler = (renderer: ErrorReactRenderer) => {\n\tif (import.meta.env.DEV) {\n\t\treturn devErrorHandler(renderer)\n\t} else {\n\t\treturn prodErrorHandler(renderer)\n\t}\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,oBAAoB,MAAM;AAC/B,QAAM,iBAAiB;AACvB,MAAI,iBAAiB,SAAS,eAAe,cAAc;AAE3D,MAAI,CAAC,gBAAgB;AACpB,qBAAiB,SAAS,cAAc,KAAK;AAC7C,mBAAe,KAAK;AACpB,aAAS,KAAK,YAAY,cAAc;AAAA,EACzC;AAEA,SAAO;AACR;AAEA,MAAM,kBAAkB,CAAC,aAAyC;AACjE,QAAM,WAAW,IAAI,SAAA;AACnB,SAAe,SAAS;AAC1B,SAAO,iBAAiB,SAAS,CAAA,MAAK;AACrC,QAAI,EAAE,QAAQ,WAAW,gBAAgB,GAAG;AAE3C;AAAA,IACD;AACA,aAAS,YAAY,mBAAmB,EAAE,KAAK;AAAA,EAChD,CAAC;AAED,SAAO,iBAAiB,sBAAsB,CAAA,MAAK,SAAS,YAAY,+BAA+B,EAAE,MAAM,CAAC;AAEhH,QAAM,cAAc,QAAQ;AAC5B,UAAQ,QAAQ,IAAI,SAAS;AAC5B,gBAAY,GAAG,IAAI;AACnB,eAAW,OAAO,MAAM;AACvB,UAAI,eAAe,OAAO;AACzB,iBAAS,YAAY,gBAAgB,GAAG;AAAA,MACzC;AAAA,IACD;AAAA,EACD;AACA,WAAS,qBAAqB,uBAAC,iBAAA,EAAgB,KAAK,SAAA,GAAtB,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAA,MAAgC,GAAI,MAAM;AAAA,EAAC,CAAC;AAE1E,SAAO,OAAM,OAAM;AAClB,QAAI;AACH,YAAM,GAAG,CAAA,MAAK,SAAS,YAAY,2BAA2B,CAAC,CAAC;AAAA,IACjE,SAAS,GAAG;AACX,eAAS,YAAY,oBAAoB,CAAC;AAAA,IAC3C;AAAA,EACD;AACD;AAuBO,MAAM,qBAAqB,CAAC,aAAiC;AAC1C;AACxB,WAAO,gBAAgB,QAAQ;AAAA,EAChC;AAGD;"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const convertStackTraceToMarkdown = (stackTrace, lines) => {
5
+ stackTrace.forEach((frame, index) => {
6
+ lines.push(`**Frame ${index + 1}:**`);
7
+ lines.push("");
8
+ lines.push(`- **File:** ${frame.filename}${frame.line ? `:${frame.line}` : ""}`);
9
+ if (frame.callee) {
10
+ lines.push(`- **Function:** ${frame.callee}`);
11
+ }
12
+ lines.push("");
13
+ if (frame.line !== void 0 && frame.sourceCodeLines) {
14
+ lines.push("**Source Code:**");
15
+ lines.push("");
16
+ lines.push("```typescript");
17
+ frame.sourceCodeLines.forEach((codeLine, lineIndex) => {
18
+ const lineNumber = lineIndex + 1;
19
+ if (frame.line && lineNumber + 5 >= frame.line && lineNumber - 3 <= frame.line) {
20
+ const isErrorLine = lineNumber === frame.line;
21
+ const marker = isErrorLine ? ">>> " : " ";
22
+ lines.push(`${marker}${lineNumber.toString().padStart(3)}: ${codeLine}`);
23
+ }
24
+ });
25
+ lines.push("```");
26
+ lines.push("");
27
+ }
28
+ lines.push("---");
29
+ lines.push("");
30
+ });
31
+ };
32
+ const convertErrorToMarkdownRecursive = (error, lines, level) => {
33
+ const errorObject = error.error instanceof Error ? error.error : void 0;
34
+ const prefix = "#".repeat(level + 1);
35
+ if (errorObject) {
36
+ lines.push(`${prefix} ${errorObject.name}`);
37
+ lines.push("");
38
+ if (errorObject.message) {
39
+ lines.push(`**Message:** ${errorObject.message}`);
40
+ lines.push("");
41
+ }
42
+ if ("details" in errorObject && errorObject.details) {
43
+ lines.push(`**Details:** ${errorObject.details}`);
44
+ lines.push("");
45
+ }
46
+ } else {
47
+ lines.push(`${prefix} Unknown Error`);
48
+ lines.push("");
49
+ }
50
+ if (error.parsedStackStrace) {
51
+ lines.push(`${"#".repeat(level + 2)} Stack Trace`);
52
+ lines.push("");
53
+ convertStackTraceToMarkdown(error.parsedStackStrace, lines);
54
+ } else if (errorObject?.stack) {
55
+ lines.push(`${"#".repeat(level + 2)} Stack Trace`);
56
+ lines.push("");
57
+ lines.push("```");
58
+ lines.push(errorObject.stack);
59
+ lines.push("```");
60
+ lines.push("");
61
+ }
62
+ if (error.cause) {
63
+ lines.push(`${"#".repeat(level + 2)} Caused By`);
64
+ lines.push("");
65
+ convertErrorToMarkdownRecursive(error.cause, lines, level + 1);
66
+ }
67
+ };
68
+ const convertErrorToMarkdown = (error, source) => {
69
+ const lines = [];
70
+ lines.push("# Contember Error Report");
71
+ lines.push("");
72
+ lines.push(`**Source:** ${source}`);
73
+ lines.push("");
74
+ convertErrorToMarkdownRecursive(error, lines, 1);
75
+ return lines.join("\n");
76
+ };
77
+ const useCopyErrorMarkdown = ({ currentError, currentErrorSource }) => {
78
+ const [copyStatus, setCopyStatus] = React.useState("idle");
79
+ React.useEffect(() => {
80
+ setCopyStatus("idle");
81
+ }, [currentError]);
82
+ const handleCopyMarkdown = async () => {
83
+ setCopyStatus("copying");
84
+ try {
85
+ const markdown = convertErrorToMarkdown(currentError, currentErrorSource);
86
+ await navigator.clipboard.writeText(markdown);
87
+ setCopyStatus("success");
88
+ } catch (err) {
89
+ console.error("Failed to copy markdown:", err);
90
+ setCopyStatus("error");
91
+ }
92
+ };
93
+ const isClipboardSupported = !!navigator?.clipboard;
94
+ return {
95
+ copyStatus,
96
+ handleCopyMarkdown,
97
+ isClipboardSupported
98
+ };
99
+ };
100
+ exports.useCopyErrorMarkdown = useCopyErrorMarkdown;
101
+ //# sourceMappingURL=useCopyErrorMarkdown.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCopyErrorMarkdown.cjs","sources":["../../../../../packages/react-devbar/src/hooks/useCopyErrorMarkdown.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\nimport type { ParsedStackTrace, ProcessedError } from '../ui/DevError/types'\n\nconst convertStackTraceToMarkdown = (stackTrace: ParsedStackTrace, lines: string[]) => {\n\tstackTrace.forEach((frame, index) => {\n\t\tlines.push(`**Frame ${index + 1}:**`)\n\t\tlines.push('')\n\t\tlines.push(`- **File:** ${frame.filename}${frame.line ? `:${frame.line}` : ''}`)\n\n\t\tif (frame.callee) {\n\t\t\tlines.push(`- **Function:** ${frame.callee}`)\n\t\t}\n\n\t\tlines.push('')\n\n\t\tif (frame.line !== undefined && frame.sourceCodeLines) {\n\t\t\tlines.push('**Source Code:**')\n\t\t\tlines.push('')\n\t\t\tlines.push('```typescript')\n\n\t\t\tframe.sourceCodeLines.forEach((codeLine, lineIndex) => {\n\t\t\t\tconst lineNumber = lineIndex + 1\n\t\t\t\t// Show context around the error line (similar to the UI logic)\n\t\t\t\tif (frame.line && lineNumber + 5 >= frame.line && lineNumber - 3 <= frame.line) {\n\t\t\t\t\tconst isErrorLine = lineNumber === frame.line\n\t\t\t\t\tconst marker = isErrorLine ? '>>> ' : ' '\n\t\t\t\t\tlines.push(`${marker}${lineNumber.toString().padStart(3)}: ${codeLine}`)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlines.push('```')\n\t\t\tlines.push('')\n\t\t}\n\n\t\tlines.push('---')\n\t\tlines.push('')\n\t})\n}\n\nconst convertErrorToMarkdownRecursive = (error: ProcessedError, lines: string[], level: number) => {\n\tconst errorObject = error.error instanceof Error ? error.error : undefined\n\tconst prefix = '#'.repeat(level + 1)\n\n\tif (errorObject) {\n\t\tlines.push(`${prefix} ${errorObject.name}`)\n\t\tlines.push('')\n\n\t\tif (errorObject.message) {\n\t\t\tlines.push(`**Message:** ${errorObject.message}`)\n\t\t\tlines.push('')\n\t\t}\n\n\t\tif ('details' in errorObject && (errorObject as Error & { details?: unknown }).details) {\n\t\t\tlines.push(`**Details:** ${(errorObject as Error & { details: string }).details}`)\n\t\t\tlines.push('')\n\t\t}\n\t} else {\n\t\tlines.push(`${prefix} Unknown Error`)\n\t\tlines.push('')\n\t}\n\n\tif (error.parsedStackStrace) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Stack Trace`)\n\t\tlines.push('')\n\t\tconvertStackTraceToMarkdown(error.parsedStackStrace, lines)\n\t} else if (errorObject?.stack) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Stack Trace`)\n\t\tlines.push('')\n\t\tlines.push('```')\n\t\tlines.push(errorObject.stack)\n\t\tlines.push('```')\n\t\tlines.push('')\n\t}\n\n\tif (error.cause) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Caused By`)\n\t\tlines.push('')\n\t\tconvertErrorToMarkdownRecursive(error.cause, lines, level + 1)\n\t}\n}\n\nconst convertErrorToMarkdown = (error: ProcessedError, source: string): string => {\n\tconst lines: string[] = []\n\n\tlines.push('# Contember Error Report')\n\tlines.push('')\n\tlines.push(`**Source:** ${source}`)\n\tlines.push('')\n\n\tconvertErrorToMarkdownRecursive(error, lines, 1)\n\n\treturn lines.join('\\n')\n}\n\ntype CopyMarkdownProps = {\n\tcurrentError: ProcessedError\n\tcurrentErrorSource: string\n}\n\nexport const useCopyErrorMarkdown = ({ currentError, currentErrorSource }: CopyMarkdownProps) => {\n\tconst [copyStatus, setCopyStatus] = useState<'idle' | 'copying' | 'success' | 'error'>('idle')\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\n\tuseEffect(() => {\n\t\tsetCopyStatus('idle')\n\t}, [currentError])\n\n\tconst handleCopyMarkdown = async () => {\n\t\tsetCopyStatus('copying')\n\t\ttry {\n\t\t\tconst markdown = convertErrorToMarkdown(currentError, currentErrorSource)\n\t\t\tawait navigator.clipboard.writeText(markdown)\n\t\t\tsetCopyStatus('success')\n\t\t} catch (err) {\n\t\t\tconsole.error('Failed to copy markdown:', err)\n\t\t\tsetCopyStatus('error')\n\t\t}\n\t}\n\n\tconst isClipboardSupported = !!navigator?.clipboard\n\n\treturn {\n\t\tcopyStatus,\n\t\thandleCopyMarkdown,\n\t\tisClipboardSupported,\n\t}\n}\n"],"names":["useState","useEffect"],"mappings":";;;AAGA,MAAM,8BAA8B,CAAC,YAA8B,UAAoB;AACtF,aAAW,QAAQ,CAAC,OAAO,UAAU;AACpC,UAAM,KAAK,WAAW,QAAQ,CAAC,KAAK;AACpC,UAAM,KAAK,EAAE;AACb,UAAM,KAAK,eAAe,MAAM,QAAQ,GAAG,MAAM,OAAO,IAAI,MAAM,IAAI,KAAK,EAAE,EAAE;AAE/E,QAAI,MAAM,QAAQ;AACjB,YAAM,KAAK,mBAAmB,MAAM,MAAM,EAAE;AAAA,IAC7C;AAEA,UAAM,KAAK,EAAE;AAEb,QAAI,MAAM,SAAS,UAAa,MAAM,iBAAiB;AACtD,YAAM,KAAK,kBAAkB;AAC7B,YAAM,KAAK,EAAE;AACb,YAAM,KAAK,eAAe;AAE1B,YAAM,gBAAgB,QAAQ,CAAC,UAAU,cAAc;AACtD,cAAM,aAAa,YAAY;AAE/B,YAAI,MAAM,QAAQ,aAAa,KAAK,MAAM,QAAQ,aAAa,KAAK,MAAM,MAAM;AAC/E,gBAAM,cAAc,eAAe,MAAM;AACzC,gBAAM,SAAS,cAAc,SAAS;AACtC,gBAAM,KAAK,GAAG,MAAM,GAAG,WAAW,WAAW,SAAS,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ACb,oCAAgC,MAAM,OAAO,OAAO,QAAQ,CAAC;AAAA,EAC9D;AACD;AAEA,MAAM,yBAAyB,CAAC,OAAuB,WAA2B;AACjF,QAAM,QAAkB,CAAA;AAExB,QAAM,KAAK,0BAA0B;AACrC,QAAM,KAAK,EAAE;AACb,QAAM,KAAK,eAAe,MAAM,EAAE;AAClC,QAAM,KAAK,EAAE;AAEb,kCAAgC,OAAO,OAAO,CAAC;AAE/C,SAAO,MAAM,KAAK,IAAI;AACvB;AAOO,MAAM,uBAAuB,CAAC,EAAE,cAAc,yBAA4C;AAChG,QAAM,CAAC,YAAY,aAAa,IAAIA,MAAAA,SAAmD,MAAM;AAG7FC,QAAAA,UAAU,MAAM;AACf,kBAAc,MAAM;AAAA,EACrB,GAAG,CAAC,YAAY,CAAC;AAEjB,QAAM,qBAAqB,YAAY;AACtC,kBAAc,SAAS;AACvB,QAAI;AACH,YAAM,WAAW,uBAAuB,cAAc,kBAAkB;AACxE,YAAM,UAAU,UAAU,UAAU,QAAQ;AAC5C,oBAAc,SAAS;AAAA,IACxB,SAAS,KAAK;AACb,cAAQ,MAAM,4BAA4B,GAAG;AAC7C,oBAAc,OAAO;AAAA,IACtB;AAAA,EACD;AAEA,QAAM,uBAAuB,CAAC,CAAC,WAAW;AAE1C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
@@ -0,0 +1,101 @@
1
+ import { useState, useEffect } from "react";
2
+ const convertStackTraceToMarkdown = (stackTrace, lines) => {
3
+ stackTrace.forEach((frame, index) => {
4
+ lines.push(`**Frame ${index + 1}:**`);
5
+ lines.push("");
6
+ lines.push(`- **File:** ${frame.filename}${frame.line ? `:${frame.line}` : ""}`);
7
+ if (frame.callee) {
8
+ lines.push(`- **Function:** ${frame.callee}`);
9
+ }
10
+ lines.push("");
11
+ if (frame.line !== void 0 && frame.sourceCodeLines) {
12
+ lines.push("**Source Code:**");
13
+ lines.push("");
14
+ lines.push("```typescript");
15
+ frame.sourceCodeLines.forEach((codeLine, lineIndex) => {
16
+ const lineNumber = lineIndex + 1;
17
+ if (frame.line && lineNumber + 5 >= frame.line && lineNumber - 3 <= frame.line) {
18
+ const isErrorLine = lineNumber === frame.line;
19
+ const marker = isErrorLine ? ">>> " : " ";
20
+ lines.push(`${marker}${lineNumber.toString().padStart(3)}: ${codeLine}`);
21
+ }
22
+ });
23
+ lines.push("```");
24
+ lines.push("");
25
+ }
26
+ lines.push("---");
27
+ lines.push("");
28
+ });
29
+ };
30
+ const convertErrorToMarkdownRecursive = (error, lines, level) => {
31
+ const errorObject = error.error instanceof Error ? error.error : void 0;
32
+ const prefix = "#".repeat(level + 1);
33
+ if (errorObject) {
34
+ lines.push(`${prefix} ${errorObject.name}`);
35
+ lines.push("");
36
+ if (errorObject.message) {
37
+ lines.push(`**Message:** ${errorObject.message}`);
38
+ lines.push("");
39
+ }
40
+ if ("details" in errorObject && errorObject.details) {
41
+ lines.push(`**Details:** ${errorObject.details}`);
42
+ lines.push("");
43
+ }
44
+ } else {
45
+ lines.push(`${prefix} Unknown Error`);
46
+ lines.push("");
47
+ }
48
+ if (error.parsedStackStrace) {
49
+ lines.push(`${"#".repeat(level + 2)} Stack Trace`);
50
+ lines.push("");
51
+ convertStackTraceToMarkdown(error.parsedStackStrace, lines);
52
+ } else if (errorObject?.stack) {
53
+ lines.push(`${"#".repeat(level + 2)} Stack Trace`);
54
+ lines.push("");
55
+ lines.push("```");
56
+ lines.push(errorObject.stack);
57
+ lines.push("```");
58
+ lines.push("");
59
+ }
60
+ if (error.cause) {
61
+ lines.push(`${"#".repeat(level + 2)} Caused By`);
62
+ lines.push("");
63
+ convertErrorToMarkdownRecursive(error.cause, lines, level + 1);
64
+ }
65
+ };
66
+ const convertErrorToMarkdown = (error, source) => {
67
+ const lines = [];
68
+ lines.push("# Contember Error Report");
69
+ lines.push("");
70
+ lines.push(`**Source:** ${source}`);
71
+ lines.push("");
72
+ convertErrorToMarkdownRecursive(error, lines, 1);
73
+ return lines.join("\n");
74
+ };
75
+ const useCopyErrorMarkdown = ({ currentError, currentErrorSource }) => {
76
+ const [copyStatus, setCopyStatus] = useState("idle");
77
+ useEffect(() => {
78
+ setCopyStatus("idle");
79
+ }, [currentError]);
80
+ const handleCopyMarkdown = async () => {
81
+ setCopyStatus("copying");
82
+ try {
83
+ const markdown = convertErrorToMarkdown(currentError, currentErrorSource);
84
+ await navigator.clipboard.writeText(markdown);
85
+ setCopyStatus("success");
86
+ } catch (err) {
87
+ console.error("Failed to copy markdown:", err);
88
+ setCopyStatus("error");
89
+ }
90
+ };
91
+ const isClipboardSupported = !!navigator?.clipboard;
92
+ return {
93
+ copyStatus,
94
+ handleCopyMarkdown,
95
+ isClipboardSupported
96
+ };
97
+ };
98
+ export {
99
+ useCopyErrorMarkdown
100
+ };
101
+ //# sourceMappingURL=useCopyErrorMarkdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCopyErrorMarkdown.js","sources":["../../../../../packages/react-devbar/src/hooks/useCopyErrorMarkdown.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\nimport type { ParsedStackTrace, ProcessedError } from '../ui/DevError/types'\n\nconst convertStackTraceToMarkdown = (stackTrace: ParsedStackTrace, lines: string[]) => {\n\tstackTrace.forEach((frame, index) => {\n\t\tlines.push(`**Frame ${index + 1}:**`)\n\t\tlines.push('')\n\t\tlines.push(`- **File:** ${frame.filename}${frame.line ? `:${frame.line}` : ''}`)\n\n\t\tif (frame.callee) {\n\t\t\tlines.push(`- **Function:** ${frame.callee}`)\n\t\t}\n\n\t\tlines.push('')\n\n\t\tif (frame.line !== undefined && frame.sourceCodeLines) {\n\t\t\tlines.push('**Source Code:**')\n\t\t\tlines.push('')\n\t\t\tlines.push('```typescript')\n\n\t\t\tframe.sourceCodeLines.forEach((codeLine, lineIndex) => {\n\t\t\t\tconst lineNumber = lineIndex + 1\n\t\t\t\t// Show context around the error line (similar to the UI logic)\n\t\t\t\tif (frame.line && lineNumber + 5 >= frame.line && lineNumber - 3 <= frame.line) {\n\t\t\t\t\tconst isErrorLine = lineNumber === frame.line\n\t\t\t\t\tconst marker = isErrorLine ? '>>> ' : ' '\n\t\t\t\t\tlines.push(`${marker}${lineNumber.toString().padStart(3)}: ${codeLine}`)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlines.push('```')\n\t\t\tlines.push('')\n\t\t}\n\n\t\tlines.push('---')\n\t\tlines.push('')\n\t})\n}\n\nconst convertErrorToMarkdownRecursive = (error: ProcessedError, lines: string[], level: number) => {\n\tconst errorObject = error.error instanceof Error ? error.error : undefined\n\tconst prefix = '#'.repeat(level + 1)\n\n\tif (errorObject) {\n\t\tlines.push(`${prefix} ${errorObject.name}`)\n\t\tlines.push('')\n\n\t\tif (errorObject.message) {\n\t\t\tlines.push(`**Message:** ${errorObject.message}`)\n\t\t\tlines.push('')\n\t\t}\n\n\t\tif ('details' in errorObject && (errorObject as Error & { details?: unknown }).details) {\n\t\t\tlines.push(`**Details:** ${(errorObject as Error & { details: string }).details}`)\n\t\t\tlines.push('')\n\t\t}\n\t} else {\n\t\tlines.push(`${prefix} Unknown Error`)\n\t\tlines.push('')\n\t}\n\n\tif (error.parsedStackStrace) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Stack Trace`)\n\t\tlines.push('')\n\t\tconvertStackTraceToMarkdown(error.parsedStackStrace, lines)\n\t} else if (errorObject?.stack) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Stack Trace`)\n\t\tlines.push('')\n\t\tlines.push('```')\n\t\tlines.push(errorObject.stack)\n\t\tlines.push('```')\n\t\tlines.push('')\n\t}\n\n\tif (error.cause) {\n\t\tlines.push(`${'#'.repeat(level + 2)} Caused By`)\n\t\tlines.push('')\n\t\tconvertErrorToMarkdownRecursive(error.cause, lines, level + 1)\n\t}\n}\n\nconst convertErrorToMarkdown = (error: ProcessedError, source: string): string => {\n\tconst lines: string[] = []\n\n\tlines.push('# Contember Error Report')\n\tlines.push('')\n\tlines.push(`**Source:** ${source}`)\n\tlines.push('')\n\n\tconvertErrorToMarkdownRecursive(error, lines, 1)\n\n\treturn lines.join('\\n')\n}\n\ntype CopyMarkdownProps = {\n\tcurrentError: ProcessedError\n\tcurrentErrorSource: string\n}\n\nexport const useCopyErrorMarkdown = ({ currentError, currentErrorSource }: CopyMarkdownProps) => {\n\tconst [copyStatus, setCopyStatus] = useState<'idle' | 'copying' | 'success' | 'error'>('idle')\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: intentional\n\tuseEffect(() => {\n\t\tsetCopyStatus('idle')\n\t}, [currentError])\n\n\tconst handleCopyMarkdown = async () => {\n\t\tsetCopyStatus('copying')\n\t\ttry {\n\t\t\tconst markdown = convertErrorToMarkdown(currentError, currentErrorSource)\n\t\t\tawait navigator.clipboard.writeText(markdown)\n\t\t\tsetCopyStatus('success')\n\t\t} catch (err) {\n\t\t\tconsole.error('Failed to copy markdown:', err)\n\t\t\tsetCopyStatus('error')\n\t\t}\n\t}\n\n\tconst isClipboardSupported = !!navigator?.clipboard\n\n\treturn {\n\t\tcopyStatus,\n\t\thandleCopyMarkdown,\n\t\tisClipboardSupported,\n\t}\n}\n"],"names":[],"mappings":";AAGA,MAAM,8BAA8B,CAAC,YAA8B,UAAoB;AACtF,aAAW,QAAQ,CAAC,OAAO,UAAU;AACpC,UAAM,KAAK,WAAW,QAAQ,CAAC,KAAK;AACpC,UAAM,KAAK,EAAE;AACb,UAAM,KAAK,eAAe,MAAM,QAAQ,GAAG,MAAM,OAAO,IAAI,MAAM,IAAI,KAAK,EAAE,EAAE;AAE/E,QAAI,MAAM,QAAQ;AACjB,YAAM,KAAK,mBAAmB,MAAM,MAAM,EAAE;AAAA,IAC7C;AAEA,UAAM,KAAK,EAAE;AAEb,QAAI,MAAM,SAAS,UAAa,MAAM,iBAAiB;AACtD,YAAM,KAAK,kBAAkB;AAC7B,YAAM,KAAK,EAAE;AACb,YAAM,KAAK,eAAe;AAE1B,YAAM,gBAAgB,QAAQ,CAAC,UAAU,cAAc;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