@purr-react-core/components.error-boundary 0.0.11
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/LICENSE +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dinh Thien Phuc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var o=require('react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var o__default=/*#__PURE__*/_interopDefault(o);var t=class extends o.Component{constructor(r){super(r),this.state={error:null,errorInfo:null};}componentDidCatch(r,e){this.setState({error:r,errorInfo:e});}render(){if(this.state.error){if(this.props.FallbackComponent){let r=this.props.FallbackComponent;return o__default.default.createElement(r,null)}return o__default.default.createElement("div",null,o__default.default.createElement("h1",null,"Whoops!"),o__default.default.createElement("p",null,"Stuck in a blind spot. Reload to see the magic!"),o__default.default.createElement("button",{onClick:this.props.onReset},"Reload"))}return this.props.children}};exports.ErrorBoundary=t;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { ReactNode, ComponentType, Component } from 'react';
|
|
2
|
+
import { TAny } from '@purr-react-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The props for the ErrorBoundary component.
|
|
6
|
+
*
|
|
7
|
+
* @interface IErrorBoundaryProps
|
|
8
|
+
* @property {function} onReset - The function to reset the error.
|
|
9
|
+
* @property {ReactNode} children - The children of the component.
|
|
10
|
+
* @property {ComponentType | null} [FallbackComponent] - The fallback component.
|
|
11
|
+
*/
|
|
12
|
+
interface IErrorBoundaryProps {
|
|
13
|
+
onReset: () => void;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
FallbackComponent?: ComponentType | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The state for the ErrorBoundary component.
|
|
19
|
+
*
|
|
20
|
+
* @interface IErrorBoundaryState
|
|
21
|
+
* @property {TAny} error - The error.
|
|
22
|
+
* @property {TAny} errorInfo - The error info.
|
|
23
|
+
*/
|
|
24
|
+
interface IErrorBoundaryState {
|
|
25
|
+
error: TAny;
|
|
26
|
+
errorInfo: TAny;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The ErrorBoundary component.
|
|
31
|
+
*
|
|
32
|
+
* @param {IErrorBoundaryProps} props - The props for the component.
|
|
33
|
+
* @param {IErrorBoundaryState} state - The state for the component.
|
|
34
|
+
* @returns {ReactNode} The component.
|
|
35
|
+
*/
|
|
36
|
+
declare class ErrorBoundary extends Component<IErrorBoundaryProps, IErrorBoundaryState> {
|
|
37
|
+
constructor(props: IErrorBoundaryProps);
|
|
38
|
+
componentDidCatch(error: any, errorInfo: any): void;
|
|
39
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { ErrorBoundary, type IErrorBoundaryProps, type IErrorBoundaryState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { ReactNode, ComponentType, Component } from 'react';
|
|
2
|
+
import { TAny } from '@purr-react-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The props for the ErrorBoundary component.
|
|
6
|
+
*
|
|
7
|
+
* @interface IErrorBoundaryProps
|
|
8
|
+
* @property {function} onReset - The function to reset the error.
|
|
9
|
+
* @property {ReactNode} children - The children of the component.
|
|
10
|
+
* @property {ComponentType | null} [FallbackComponent] - The fallback component.
|
|
11
|
+
*/
|
|
12
|
+
interface IErrorBoundaryProps {
|
|
13
|
+
onReset: () => void;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
FallbackComponent?: ComponentType | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The state for the ErrorBoundary component.
|
|
19
|
+
*
|
|
20
|
+
* @interface IErrorBoundaryState
|
|
21
|
+
* @property {TAny} error - The error.
|
|
22
|
+
* @property {TAny} errorInfo - The error info.
|
|
23
|
+
*/
|
|
24
|
+
interface IErrorBoundaryState {
|
|
25
|
+
error: TAny;
|
|
26
|
+
errorInfo: TAny;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The ErrorBoundary component.
|
|
31
|
+
*
|
|
32
|
+
* @param {IErrorBoundaryProps} props - The props for the component.
|
|
33
|
+
* @param {IErrorBoundaryState} state - The state for the component.
|
|
34
|
+
* @returns {ReactNode} The component.
|
|
35
|
+
*/
|
|
36
|
+
declare class ErrorBoundary extends Component<IErrorBoundaryProps, IErrorBoundaryState> {
|
|
37
|
+
constructor(props: IErrorBoundaryProps);
|
|
38
|
+
componentDidCatch(error: any, errorInfo: any): void;
|
|
39
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { ErrorBoundary, type IErrorBoundaryProps, type IErrorBoundaryState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o,{Component}from'react';var t=class extends Component{constructor(r){super(r),this.state={error:null,errorInfo:null};}componentDidCatch(r,e){this.setState({error:r,errorInfo:e});}render(){if(this.state.error){if(this.props.FallbackComponent){let r=this.props.FallbackComponent;return o.createElement(r,null)}return o.createElement("div",null,o.createElement("h1",null,"Whoops!"),o.createElement("p",null,"Stuck in a blind spot. Reload to see the magic!"),o.createElement("button",{onClick:this.props.onReset},"Reload"))}return this.props.children}};export{t as ErrorBoundary};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purr-react-core/components.error-boundary",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
25
|
+
},
|
|
26
|
+
"author": "@DinhThienPhuc",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"description": "",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@purr-react-core/utils.definitions": "0.0.14"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "vite build --watch",
|
|
35
|
+
"build": "tsc && vite build",
|
|
36
|
+
"build:vite": "tsc && vite build",
|
|
37
|
+
"build:tsup": "tsup",
|
|
38
|
+
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
39
|
+
}
|
|
40
|
+
}
|