@moneko/react 2.0.8 → 2.0.9
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.
- package/lib/error-boundary.d.ts +3 -0
- package/lib/error-boundary.js +2 -2
- package/package.json +2 -2
package/lib/error-boundary.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ declare function parseStackFrame(frame: string);
|
|
|
14
14
|
declare const __webpack_require__: {
|
|
15
15
|
m: Record<string, string>;
|
|
16
16
|
};
|
|
17
|
+
declare function extractSourceMapURL(str: string);
|
|
18
|
+
declare function parseJson<T>(str: string): T | null;
|
|
19
|
+
declare function getSourceCode(moduleId: string);
|
|
17
20
|
declare function getSourceFromWebpack(file: string): string | null;
|
|
18
21
|
declare const ErrorStack: ({ stack, heading }: {
|
|
19
22
|
stack?: string;
|
package/lib/error-boundary.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as e,jsxs as r,Fragment as t}from"react/jsx-runtime";import*as n from"react";let o=({stack:o,heading:i})=>{let[a,s]=n.useState(null);if(!o)return null;let l=o.split("\n");return r(t,{children:[i&&r("strong",{children:["🛑 ",i]}),l.map((o,i)=>{let l=function(e){let r=e.match(/webpack-internal:\/\/\/(.*?):(\d+):(\d+)/);if(r){let[e,t,n,o]=r;return{prefix:r.input?.substring(0,r.index),file:t,fileName:t.split("/").pop(),line:parseInt(n,10),column:parseInt(o,10),suffix:r.input?.substring((r.index??0)+e.length)}}let t=e.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))/);if(t){let[e,r,n,o,i]=t;return{prefix:t.input?.substring(0,t.index),func:r,file:n,fileName:n.split("/").pop(),line:parseInt(o,10),column:parseInt(i,10),suffix:t.input?.substring((t.index??0)+e.length)}}return null}(o);return r(n.Fragment,{children:[" ",l?r(t,{children:[l.prefix,r("a",{style:{color:"var(--link-color, #1677ff)",textDecoration:"none"},onClick:()=>{l.file===a?.file?s(null):s({file:l.file,source:function(e){try{let r=__webpack_require__.m,t=Object.keys(r).find(r=>r.includes(e));if(t)return function(e){let r=__webpack_require__.m[e].toString(),t=function(e){let r="//# sourceMappingURL=data:application/json;charset=utf-8;base64,",t=e.indexOf(r)+r.length,n="";if(-1!==t){let r=e.indexOf("\\n//#",t);n=e.substring(t,r)}return n}(r);if(t){let e=new TextDecoder("utf-8"),r=atob(t);if(r){let t=function(e){try{return JSON.parse(e)}catch{return null}}(e.decode(new Uint8Array(r.split("").map(e=>e.charCodeAt(0)))));if(t?.sourcesContent)return t.sourcesContent[0]}}return r}(t);return null}catch(e){return e.message}}(l.file)})},children:[l.fileName,":",l.line,":",l.column]}),l.suffix]}):o,e("br",{})]},o+i)}),a&&r("div",{style:{marginBlockStart:16,border:"1px solid var(--warning-border, #ffe58f)",borderRadius:"var(--border-radius, 8px)",padding:16,backgroundColor:"var(--warning-bg, #fffbe6)"},children:[r("strong",{children:["Source: ",a.file]}),e("pre",{style:{whiteSpace:"pre-wrap"},children:a.source})]})]})};class i extends n.Component{constructor(e){super(e),this.componentNameRegex=/at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))/,this.state={}}componentDidCatch(e,r){this.setState({error:e,errorInfo:r})}getComponentName(e){let r=e?.trim().split("\n")?.[0].match(this.componentNameRegex)?.[1];return r?`The above error occurred in the <${r}> component.
|
|
2
2
|
|
|
3
3
|
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
|
|
4
|
-
Error Component Stack`:null}render(){if(this.state.errorInfo){let n=this.props.fallback;return n?
|
|
4
|
+
Error Component Stack`:null}render(){if(this.state.errorInfo){let n=this.props.fallback;return n?e(n,{error:this.state.error,errorInfo:this.state.errorInfo}):e("pre",{className:"error-boundary-component-stack",style:{display:"block",maxInlineSize:"100%",maxBlockSize:"100%",overflow:"auto",margin:24,border:"1px solid var(--error-border, #ffccc7)",borderRadius:"var(--border-radius, 8px)",padding:20,backgroundColor:"var(--error-bg, #fff2f0)",whiteSpace:"pre-wrap",fontSize:12,color:"var(--error-color, rgb(0 0 0 / 75%))",fontFamily:"var(--font-family, inherit)"},children:this.state.error&&r(t,{children:[e(o,{stack:this.state.error.stack?.replace(`${this.state.error.name}: ${this.state.error.message}`,""),heading:`${this.state.error.name}: ${this.state.error.message}`}),e("br",{}),e(o,{stack:this.state.errorInfo.componentStack,heading:this.getComponentName(this.state.errorInfo.componentStack)})]})})}return this.props.children}}export default i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "react",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.
|
|
19
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.6.0",
|
|
20
20
|
"react-refresh": "0.17.0",
|
|
21
21
|
"react-refresh-typescript": "2.0.10",
|
|
22
22
|
"react-router": "6.3.0",
|