@chamn/render 0.0.9 → 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.
Files changed (52) hide show
  1. package/dist/commonComponent/index.d.ts +12 -0
  2. package/dist/const/index.d.ts +2 -0
  3. package/dist/core/ReactErrorBoundary.d.ts +26 -0
  4. package/dist/core/adapter.d.ts +64 -0
  5. package/dist/core/adapterReact.d.ts +108 -0
  6. package/dist/core/designReactRender.d.ts +47 -0
  7. package/dist/core/refManager.d.ts +7 -0
  8. package/dist/core/render.d.ts +32 -0
  9. package/dist/core/storeManager.d.ts +11 -0
  10. package/dist/core/type.d.ts +9 -0
  11. package/dist/{index.cjs.js → index.js} +2 -2
  12. package/dist/index.js.map +1 -0
  13. package/dist/{index.es.js → index.mjs} +94 -83
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/index.umd.js +1 -1
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/util/assetsLoader.d.ts +15 -0
  18. package/dist/util/index.d.ts +20 -0
  19. package/package.json +14 -9
  20. package/.eslintignore +0 -1
  21. package/.eslintrc.js +0 -30
  22. package/.prettierrc.json +0 -7
  23. package/CHANGELOG.md +0 -40
  24. package/__tests__/demo.test.ts +0 -3
  25. package/build.config.ts +0 -20
  26. package/dist/index.cjs.js.map +0 -1
  27. package/dist/index.es.js.map +0 -1
  28. package/index.html +0 -16
  29. package/jest.config.js +0 -196
  30. package/public/vite.svg +0 -1
  31. package/src/_dev_/components.tsx +0 -12
  32. package/src/_dev_/dev.tsx +0 -12
  33. package/src/_dev_/index.css +0 -13
  34. package/src/_dev_/page/DesignerRenderDemo.tsx +0 -65
  35. package/src/_dev_/page/RenderDemo.tsx +0 -60
  36. package/src/_dev_/router.tsx +0 -15
  37. package/src/commonComponent/index.tsx +0 -184
  38. package/src/const/index.ts +0 -5
  39. package/src/core/ReactErrorBoundary.ts +0 -91
  40. package/src/core/adapter.ts +0 -133
  41. package/src/core/adapterReact.ts +0 -734
  42. package/src/core/designReactRender.ts +0 -325
  43. package/src/core/refManager.ts +0 -18
  44. package/src/core/render.ts +0 -123
  45. package/src/core/storeManager.ts +0 -57
  46. package/src/core/type.ts +0 -10
  47. package/src/util/assetsLoader.ts +0 -73
  48. package/src/util/index.ts +0 -164
  49. package/src/vite-env.d.ts +0 -1
  50. package/stats.html +0 -6177
  51. package/tsconfig.json +0 -26
  52. /package/{src/index.ts → dist/index.d.ts} +0 -0
package/index.html DELETED
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
- <title>Vite + React + TS</title>
9
- </head>
10
-
11
- <body>
12
- <div id="root"></div>
13
- <script type="module" src="/src/_dev_/dev.tsx"></script>
14
- </body>
15
-
16
- </html>
package/jest.config.js DELETED
@@ -1,196 +0,0 @@
1
- /* eslint-disable no-undef */
2
- /*
3
- * For a detailed explanation regarding each configuration property, visit:
4
- * https://jestjs.io/docs/configuration
5
- */
6
-
7
- module.exports = {
8
- // All imported modules in your tests should be mocked automatically
9
- // automock: false,
10
-
11
- // Stop running tests after `n` failures
12
- // bail: 0,
13
-
14
- // The directory where Jest should store its cached dependency information
15
- // cacheDirectory: "/private/var/folders/l9/th_r5d_12wxdj16859_mctjw0000gn/T/jest_dx",
16
-
17
- // Automatically clear mock calls, instances, contexts and results before every test
18
- // clearMocks: false,
19
-
20
- // Indicates whether the coverage information should be collected while executing the test
21
- // collectCoverage: false,
22
-
23
- // An array of glob patterns indicating a set of files for which coverage information should be collected
24
- // collectCoverageFrom: undefined,
25
-
26
- // The directory where Jest should output its coverage files
27
- // coverageDirectory: undefined,
28
-
29
- // An array of regexp pattern strings used to skip coverage collection
30
- // coveragePathIgnorePatterns: [
31
- // "/node_modules/"
32
- // ],
33
-
34
- // Indicates which provider should be used to instrument code for coverage
35
- // coverageProvider: "babel",
36
-
37
- // A list of reporter names that Jest uses when writing coverage reports
38
- // coverageReporters: [
39
- // "json",
40
- // "text",
41
- // "lcov",
42
- // "clover"
43
- // ],
44
-
45
- // An object that configures minimum threshold enforcement for coverage results
46
- // coverageThreshold: undefined,
47
-
48
- // A path to a custom dependency extractor
49
- // dependencyExtractor: undefined,
50
-
51
- // Make calling deprecated APIs throw helpful error messages
52
- // errorOnDeprecated: false,
53
-
54
- // The default configuration for fake timers
55
- // fakeTimers: {
56
- // "enableGlobally": false
57
- // },
58
-
59
- // Force coverage collection from ignored files using an array of glob patterns
60
- // forceCoverageMatch: [],
61
-
62
- // A path to a module which exports an async function that is triggered once before all test suites
63
- // globalSetup: undefined,
64
-
65
- // A path to a module which exports an async function that is triggered once after all test suites
66
- // globalTeardown: undefined,
67
-
68
- // A set of global variables that need to be available in all test environments
69
- // globals: {},
70
-
71
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
72
- // maxWorkers: "50%",
73
-
74
- // An array of directory names to be searched recursively up from the requiring module's location
75
- // moduleDirectories: [
76
- // "node_modules"
77
- // ],
78
-
79
- // An array of file extensions your modules use
80
- // moduleFileExtensions: [
81
- // "js",
82
- // "mjs",
83
- // "cjs",
84
- // "jsx",
85
- // "ts",
86
- // "tsx",
87
- // "json",
88
- // "node"
89
- // ],
90
-
91
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
92
- // moduleNameMapper: {},
93
-
94
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
95
- // modulePathIgnorePatterns: [],
96
-
97
- // Activates notifications for test results
98
- // notify: false,
99
-
100
- // An enum that specifies notification mode. Requires { notify: true }
101
- // notifyMode: "failure-change",
102
-
103
- // A preset that is used as a base for Jest's configuration
104
- preset: 'ts-jest',
105
-
106
- // Run tests from one or more projects
107
- // projects: undefined,
108
-
109
- // Use this configuration option to add custom reporters to Jest
110
- // reporters: undefined,
111
-
112
- // Automatically reset mock state before every test
113
- // resetMocks: false,
114
-
115
- // Reset the module registry before running each individual test
116
- // resetModules: false,
117
-
118
- // A path to a custom resolver
119
- // resolver: undefined,
120
-
121
- // Automatically restore mock state and implementation before every test
122
- // restoreMocks: false,
123
-
124
- // The root directory that Jest should scan for tests and modules within
125
- // rootDir: undefined,
126
-
127
- // A list of paths to directories that Jest should use to search for files in
128
- // roots: [
129
- // "<rootDir>"
130
- // ],
131
-
132
- // Allows you to use a custom runner instead of Jest's default test runner
133
- // runner: "jest-runner",
134
-
135
- // The paths to modules that run some code to configure or set up the testing environment before each test
136
- // setupFiles: [],
137
-
138
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
139
- // setupFilesAfterEnv: [],
140
-
141
- // The number of seconds after which a test is considered as slow and reported as such in the results.
142
- // slowTestThreshold: 5,
143
-
144
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
145
- // snapshotSerializers: [],
146
-
147
- // The test environment that will be used for testing
148
- testEnvironment: 'jsdom',
149
-
150
- // Options that will be passed to the testEnvironment
151
- // testEnvironmentOptions: {},
152
-
153
- // Adds a location field to test results
154
- // testLocationInResults: false,
155
-
156
- // The glob patterns Jest uses to detect test files
157
- // testMatch: [
158
- // "**/__tests__/**/*.[jt]s?(x)",
159
- // "**/?(*.)+(spec|test).[tj]s?(x)"
160
- // ],
161
-
162
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
163
- // testPathIgnorePatterns: [
164
- // "/node_modules/"
165
- // ],
166
-
167
- // The regexp pattern or array of patterns that Jest uses to detect test files
168
- // testRegex: [],
169
-
170
- // This option allows the use of a custom results processor
171
- // testResultsProcessor: undefined,
172
-
173
- // This option allows use of a custom test runner
174
- // testRunner: "jest-circus/runner",
175
-
176
- // A map from regular expressions to paths to transformers
177
- // transform: undefined,
178
-
179
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
180
- // transformIgnorePatterns: [
181
- // "/node_modules/",
182
- // "\\.pnp\\.[^\\/]+$"
183
- // ],
184
-
185
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
186
- // unmockedModulePathPatterns: undefined,
187
-
188
- // Indicates whether each individual test should be reported during the run
189
- // verbose: undefined,
190
-
191
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
192
- // watchPathIgnorePatterns: [],
193
-
194
- // Whether to use watchman for file crawling
195
- // watchman: true,
196
- };
package/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -1,12 +0,0 @@
1
- import * as antD from 'antd';
2
- import React from 'react';
3
-
4
- export const components = {
5
- ...antD,
6
- Page: ({ children }: any) => {
7
- return <div style={{ padding: '10px' }}>{children}</div>;
8
- },
9
- div: ({ children, ...props }: any) => {
10
- return <div {...props}>{children}</div>;
11
- },
12
- };
package/src/_dev_/dev.tsx DELETED
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom/client';
3
- import * as ReactDOMAll from 'react-dom';
4
- import { RouterProvider } from 'react-router-dom';
5
- import { router } from './router';
6
-
7
- window.React = React;
8
- (window as any).ReactDOM = ReactDOMAll;
9
-
10
- const root = ReactDOM.createRoot(document.getElementById('root')!);
11
-
12
- root.render(<RouterProvider router={router} />);
@@ -1,13 +0,0 @@
1
- * {
2
- margin: 0;
3
- padding: 0;
4
- box-sizing: border-box;
5
- }
6
-
7
- html,
8
- body,
9
- #app {
10
- width: 100%;
11
- height: 100%;
12
- overflow: auto;
13
- }
@@ -1,65 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { BasePage, SamplePage, Material, EmptyPage } from '@chamn/demo-page';
3
- import { ReactAdapter } from '../../index';
4
- import '../index.css';
5
- import { DesignRender, useDesignRender } from '../../core/designReactRender';
6
- import { CPage } from '@chamn/model';
7
- import { components } from '../components';
8
-
9
- export type AppProp = {
10
- a: string;
11
- };
12
-
13
- export function DesignerRenderDemo() {
14
- SamplePage;
15
- BasePage;
16
- EmptyPage;
17
-
18
- const [page] = useState(
19
- new CPage(BasePage, {
20
- materials: Material,
21
- })
22
- );
23
- const renderHandle = useDesignRender();
24
- (window as any).renderHandle = renderHandle;
25
- useEffect(() => {
26
- console.log('🚀 ~ file: dev.tsx ~ line 31 ~ App ~ page', page);
27
- page.getNode('5');
28
-
29
- document.documentElement.addEventListener(
30
- 'click',
31
- (e) => {
32
- const eventTargetDom = e.target;
33
- const instance = renderHandle.getInstanceByDom(eventTargetDom as any);
34
- console.log('🚀 ~ file: dev.tsx ~ line 50 ~ useEffect ~ instance', instance);
35
- const targetDom = renderHandle.getDomsById(instance?._NODE_ID || '');
36
- const targetDomRectList = renderHandle.getDomRectById(instance?._NODE_ID || '');
37
-
38
- console.log('🚀 ~ file: dev.tsx ~ line 51 ~ useEffect ~ targetDom', targetDom, targetDomRectList);
39
- },
40
- true
41
- );
42
-
43
- // setTimeout(() => {
44
- // const newNode = page.createNode({
45
- // componentName: 'Button',
46
- // children: ['动态添加的按钮'],
47
- // });
48
- // const boxNode = page.value.componentsTree.value.children[1];
49
- // const [node] = page.value.componentsTree.value.children.splice(3, 1);
50
- // page.value.componentsTree.updateValue();
51
- // boxNode.value.children.push(node, newNode);
52
- // boxNode.updateValue();
53
- // const tableNode = page.getNode('3');
54
- // console.log(tableNode);
55
- // tableNode?.props.columns.updateValue();
56
- // }, 500);
57
- page.export();
58
- }, []);
59
-
60
- return (
61
- <div className="App">
62
- <DesignRender pageModel={page} components={components} render={renderHandle} adapter={ReactAdapter} />
63
- </div>
64
- );
65
- }
@@ -1,60 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { BasePage, SamplePage, Material } from '@chamn/demo-page';
3
- import { ReactAdapter, Render, useRender } from '../../index';
4
- import '../index.css';
5
- import { CPage } from '@chamn/model';
6
- import { components } from '../components';
7
-
8
- export type AppProp = {
9
- a: string;
10
- };
11
-
12
- export function RenderDemo() {
13
- SamplePage;
14
- BasePage;
15
- const [page] = useState(
16
- new CPage(BasePage, {
17
- materials: Material,
18
- })
19
- );
20
- (window as any).__CPAGE_MODEL = page;
21
- const renderHandle = useRender();
22
- (window as any).RENDER_HANDLE = renderHandle;
23
- useEffect(() => {
24
- page.getNode('5');
25
-
26
- // setTimeout(() => {
27
- // const newNode = page.createNode({
28
- // componentName: 'Button',
29
- // children: ['动态添加的按钮'],
30
- // });
31
- // const boxNode = page.value.componentsTree.value.children[1];
32
- // const [node] = page.value.componentsTree.value.children.splice(3, 1);
33
- // page.value.componentsTree.updateValue();
34
- // console.log(
35
- // '🚀 ~ file: dev.tsx ~ line 70 ~ setTimeout ~ boxNode',
36
- // boxNode
37
- // );
38
-
39
- // boxNode.value.children.push(node, newNode);
40
-
41
- // boxNode.updateValue();
42
- // const tableNode = page.getNode('3');
43
- // console.log(tableNode);
44
- // tableNode?.props.columns.updateValue();
45
- // }, 500);
46
-
47
- console.log(page.export());
48
- console.log(page);
49
- page?.moveNodeById('999', '5', 'BEFORE');
50
- console.log(page);
51
-
52
- page.export();
53
- }, []);
54
-
55
- return (
56
- <div className="App">
57
- <Render pageModel={page} components={components} render={renderHandle as any} adapter={ReactAdapter} />
58
- </div>
59
- );
60
- }
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { createBrowserRouter } from 'react-router-dom';
3
- import { DesignerRenderDemo } from './page/DesignerRenderDemo';
4
- import { RenderDemo } from './page/RenderDemo';
5
-
6
- export const router = createBrowserRouter([
7
- {
8
- path: '/',
9
- element: <RenderDemo />,
10
- },
11
- {
12
- path: '/designer',
13
- element: <DesignerRenderDemo />,
14
- },
15
- ]);
@@ -1,184 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { htmlTagNames } from 'html-tag-names';
3
- import { BaseComponentTagList } from '@chamn/model';
4
-
5
- const transformListToObj = (list: { key: string; value: any }[]) => {
6
- const res: Record<string, any> = {};
7
- list.forEach((el) => {
8
- res[el.key] = el.value;
9
- });
10
- return res;
11
- };
12
-
13
- const HTMl_TAGS = [...htmlTagNames, ...BaseComponentTagList];
14
-
15
- const htmlNativeComponents = HTMl_TAGS.reduce((res, tag) => {
16
- res[tag] = ({ children, $$attributes = [], ...props }: any) => {
17
- let child = children;
18
- if (!Array.isArray(children)) {
19
- child = [children];
20
- }
21
- return React.createElement(
22
- tag,
23
- {
24
- ...props,
25
- ...transformListToObj($$attributes),
26
- },
27
- ...child
28
- );
29
- };
30
- return res;
31
- }, {} as Record<string, (props: any) => React.ReactNode>);
32
-
33
- const CBlock = ({ children, width, height, $$attributes = [], ...props }: any) => {
34
- let child = children;
35
- if (!Array.isArray(children)) {
36
- child = [children];
37
- }
38
- child = child.filter((el: any) => el !== undefined);
39
- const { style = {}, ...attributes } = transformListToObj($$attributes);
40
- const finalStyle = {
41
- height,
42
- width,
43
- ...style,
44
- ...(props.style || {}),
45
- };
46
- return React.createElement(
47
- 'div',
48
- {
49
- ...props,
50
- ...attributes,
51
- style: finalStyle,
52
- },
53
- ...child
54
- );
55
- };
56
-
57
- const CCanvas = ({ children, $$attributes = [], ...props }: any) => {
58
- let child = children;
59
- if (!Array.isArray(children)) {
60
- child = [children];
61
- }
62
- return React.createElement(
63
- 'canvas',
64
- {
65
- ...props,
66
- ...transformListToObj($$attributes),
67
- },
68
- ...child
69
- );
70
- };
71
-
72
- const CImage = ({ children, $$attributes = [], ...props }: any) => {
73
- let child = children;
74
- if (!Array.isArray(children)) {
75
- child = [children];
76
- }
77
- return React.createElement(
78
- 'img',
79
- {
80
- ...props,
81
- ...transformListToObj($$attributes),
82
- },
83
- ...child
84
- );
85
- };
86
-
87
- const CVideo = ({ children, $$attributes = [], ...props }: any) => {
88
- let child = children;
89
- if (!Array.isArray(children)) {
90
- child = [children];
91
- }
92
- return React.createElement(
93
- 'video',
94
- {
95
- ...props,
96
- ...transformListToObj($$attributes),
97
- },
98
- ...child
99
- );
100
- };
101
-
102
- const CAudio = ({ children, $$attributes = [], ...props }: any) => {
103
- let child = children;
104
- if (!Array.isArray(children)) {
105
- child = [children];
106
- }
107
- return React.createElement(
108
- 'video',
109
- {
110
- ...props,
111
- ...transformListToObj($$attributes),
112
- },
113
- ...child
114
- );
115
- };
116
-
117
- const CText = ({ children, $$attributes = [], content, ...props }: any) => {
118
- let child = children;
119
- if (!Array.isArray(children)) {
120
- child = [children];
121
- }
122
- return React.createElement(
123
- 'span',
124
- {
125
- ...props,
126
- ...transformListToObj($$attributes),
127
- },
128
- content
129
- );
130
- };
131
-
132
- const CContainer = ({ children, $$attributes = [], afterMount, beforeDestroy, ...props }: any) => {
133
- let child = children;
134
- if (!Array.isArray(children)) {
135
- child = [children];
136
- }
137
-
138
- useEffect(() => {
139
- afterMount?.(props);
140
- return () => {
141
- beforeDestroy?.(props);
142
- };
143
- }, []);
144
-
145
- return React.createElement(
146
- 'div',
147
- {
148
- ...props,
149
- ...transformListToObj($$attributes),
150
- },
151
- ...child
152
- );
153
- };
154
-
155
- const CNativeTag = ({ children, $$attributes = [], htmlTag = 'div', ...props }: any) => {
156
- let child = children;
157
- if (!Array.isArray(children)) {
158
- child = [children];
159
- }
160
- return React.createElement(
161
- htmlTag,
162
- {
163
- ...props,
164
- ...transformListToObj($$attributes),
165
- },
166
- ...child
167
- );
168
- };
169
-
170
- // 内置物料组件
171
- export const InnerComponent = {
172
- RootContainer: ({ children }: any) => {
173
- return children;
174
- },
175
- ...htmlNativeComponents,
176
- CContainer,
177
- CVideo,
178
- CAudio,
179
- CBlock,
180
- CImage,
181
- CText,
182
- CCanvas,
183
- CNativeTag,
184
- };
@@ -1,5 +0,0 @@
1
- // 动态运行时组件标记
2
- export const DYNAMIC_COMPONENT_TYPE = 'DYNAMIC';
3
-
4
- // 运行时辅助变量,不能传递给原始渲染组件,需在在最终渲染阶段剔除
5
- export const InnerPropList = ['$$context', '$$nodeModel'];
@@ -1,91 +0,0 @@
1
- import { CNode, CRootNode } from '@chamn/model';
2
- import React from 'react';
3
-
4
- type Props = {
5
- node: CNode | CRootNode;
6
- targetComponent: any;
7
- onError?: (error: React.ErrorInfo) => void;
8
- children?: React.ReactNode | React.ReactNode[];
9
- };
10
- class ErrorBoundary extends React.Component<
11
- Props,
12
- {
13
- error: any;
14
- hasError: boolean;
15
- }
16
- > {
17
- constructor(props: Props) {
18
- super(props);
19
- this.state = { hasError: false, error: '' };
20
- }
21
-
22
- static getDerivedStateFromError(error: any) {
23
- // Update state to enable the next render to show the degraded UI
24
- return { hasError: true, error };
25
- }
26
-
27
- componentDidCatch(_: Error, errorInfo: React.ErrorInfo): void {
28
- this.props.onError?.(errorInfo);
29
- }
30
-
31
- onDoubleClick = () => {
32
- this.setState({
33
- hasError: false,
34
- error: null,
35
- });
36
- };
37
-
38
- render() {
39
- if (this.state.hasError) {
40
- const { onDoubleClick } = this;
41
- const schema = this.props.node.value;
42
- console.error(this.props.node, this.props.children);
43
- const errorView = React.createElement(
44
- 'div',
45
- {
46
- style: {
47
- backgroundColor: 'rgb(255 206 215 / 13%)',
48
- padding: '5px',
49
- color: '#ff0000b0',
50
- textAlign: 'center',
51
- fontSize: '12px',
52
- },
53
- },
54
- 'Render error, node id: ',
55
- schema.id,
56
- ', node name:',
57
- schema.title,
58
- ' component name:',
59
- schema.title || schema.componentName,
60
- React.createElement('p', null, 'msg: ', String(this.state.error)),
61
- React.createElement(
62
- 'button',
63
- {
64
- onDoubleClick: onDoubleClick,
65
- style: {
66
- border: '1px solid rgba(100,100,100,0.1)',
67
- backgroundColor: '#fff',
68
- padding: '5px 10px',
69
- borderRadius: '2px',
70
- color: 'gray',
71
- cursor: 'pointer',
72
- marginTop: '5px',
73
- },
74
- },
75
- 'double click to refresh'
76
- ),
77
- React.createElement('div', {
78
- style: {
79
- display: 'none',
80
- },
81
- })
82
- );
83
- // return errorView; onlyRenderChild from errorView
84
- return React.createElement(this.props.targetComponent, { onlyRenderChild: true }, errorView);
85
- }
86
-
87
- return this.props.children;
88
- }
89
- }
90
-
91
- export default ErrorBoundary;