@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.
- package/dist/commonComponent/index.d.ts +12 -0
- package/dist/const/index.d.ts +2 -0
- package/dist/core/ReactErrorBoundary.d.ts +26 -0
- package/dist/core/adapter.d.ts +64 -0
- package/dist/core/adapterReact.d.ts +108 -0
- package/dist/core/designReactRender.d.ts +47 -0
- package/dist/core/refManager.d.ts +7 -0
- package/dist/core/render.d.ts +32 -0
- package/dist/core/storeManager.d.ts +11 -0
- package/dist/core/type.d.ts +9 -0
- package/dist/{index.cjs.js → index.js} +2 -2
- package/dist/index.js.map +1 -0
- package/dist/{index.es.js → index.mjs} +94 -83
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/util/assetsLoader.d.ts +15 -0
- package/dist/util/index.d.ts +20 -0
- package/package.json +14 -9
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -30
- package/.prettierrc.json +0 -7
- package/CHANGELOG.md +0 -40
- package/__tests__/demo.test.ts +0 -3
- package/build.config.ts +0 -20
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es.js.map +0 -1
- package/index.html +0 -16
- package/jest.config.js +0 -196
- package/public/vite.svg +0 -1
- package/src/_dev_/components.tsx +0 -12
- package/src/_dev_/dev.tsx +0 -12
- package/src/_dev_/index.css +0 -13
- package/src/_dev_/page/DesignerRenderDemo.tsx +0 -65
- package/src/_dev_/page/RenderDemo.tsx +0 -60
- package/src/_dev_/router.tsx +0 -15
- package/src/commonComponent/index.tsx +0 -184
- package/src/const/index.ts +0 -5
- package/src/core/ReactErrorBoundary.ts +0 -91
- package/src/core/adapter.ts +0 -133
- package/src/core/adapterReact.ts +0 -734
- package/src/core/designReactRender.ts +0 -325
- package/src/core/refManager.ts +0 -18
- package/src/core/render.ts +0 -123
- package/src/core/storeManager.ts +0 -57
- package/src/core/type.ts +0 -10
- package/src/util/assetsLoader.ts +0 -73
- package/src/util/index.ts +0 -164
- package/src/vite-env.d.ts +0 -1
- package/stats.html +0 -6177
- package/tsconfig.json +0 -26
- /package/{src/index.ts → dist/index.d.ts} +0 -0
package/src/core/adapter.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { CPage, CNode, CRootNode } from '@chamn/model';
|
|
2
|
-
import { ReactInstance } from 'react';
|
|
3
|
-
import { RefManager } from './refManager';
|
|
4
|
-
import { RenderInstance } from './type';
|
|
5
|
-
|
|
6
|
-
export type ContextType = {
|
|
7
|
-
params?: Record<any, any>;
|
|
8
|
-
globalState?: Record<any, any>;
|
|
9
|
-
updateGlobalState?: (newState: any) => void;
|
|
10
|
-
staticState?: Record<string | number, any>;
|
|
11
|
-
state?: Record<any, any>;
|
|
12
|
-
updateState?: (newState: any) => void;
|
|
13
|
-
refs?: RefManager;
|
|
14
|
-
loopData?: Record<any, any>;
|
|
15
|
-
// 用于访访问和管理页面被注册为全局的局部 state
|
|
16
|
-
stateManager?: Record<string, any>;
|
|
17
|
-
methods?: Record<string, (...arg: any) => any>;
|
|
18
|
-
// 第三方辅助库
|
|
19
|
-
thirdLibs?: Record<string, any>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type RuntimeRenderHelper = {
|
|
23
|
-
renderComponent: (
|
|
24
|
-
node: CNode | CRootNode,
|
|
25
|
-
options: {
|
|
26
|
-
$$context: ContextType;
|
|
27
|
-
idx?: number;
|
|
28
|
-
}
|
|
29
|
-
) => any;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type ComponentsType = Record<any, any>;
|
|
33
|
-
|
|
34
|
-
export type AdapterOptionType = {
|
|
35
|
-
libs: Record<string, any>;
|
|
36
|
-
components: ComponentsType;
|
|
37
|
-
$$context: ContextType;
|
|
38
|
-
onGetRef?: (ref: React.RefObject<React.ReactInstance>, nodeMode: CNode | CRootNode, instance: RenderInstance) => void;
|
|
39
|
-
onGetComponent?: (component: (...args: any) => any, currentNode: CNode | CRootNode) => void;
|
|
40
|
-
onComponentMount?: (instance: ReactInstance, node: CNode | CRootNode) => void;
|
|
41
|
-
onComponentDestroy?: (instance: ReactInstance, node: CNode | CRootNode) => void;
|
|
42
|
-
processNodeConfigHook?: (
|
|
43
|
-
config: {
|
|
44
|
-
condition: boolean;
|
|
45
|
-
props: Record<string, any>;
|
|
46
|
-
},
|
|
47
|
-
node: CNode
|
|
48
|
-
) => {
|
|
49
|
-
condition: boolean;
|
|
50
|
-
props: Record<string, any>;
|
|
51
|
-
};
|
|
52
|
-
renderMode?: 'design' | 'normal';
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// TODO: 后续考虑去掉
|
|
56
|
-
export interface AdapterType {
|
|
57
|
-
renderMode?: AdapterOptionType['renderMode'];
|
|
58
|
-
customPageRootRender?: (pageModel: CPage, options: AdapterOptionType) => any;
|
|
59
|
-
// 页面渲染
|
|
60
|
-
pageRender: (pageModel: CPage, options: AdapterOptionType) => any;
|
|
61
|
-
// 将一个 组件 model 节点 转换为一个可被运行的渲染函数
|
|
62
|
-
convertModelToComponent: (
|
|
63
|
-
originalComponent: any,
|
|
64
|
-
nodeModal: CNode | CRootNode,
|
|
65
|
-
options: {
|
|
66
|
-
pageModel: CPage;
|
|
67
|
-
idx?: number;
|
|
68
|
-
} & AdapterOptionType
|
|
69
|
-
) => any;
|
|
70
|
-
// 渲染一个组件
|
|
71
|
-
render: (originalComponent: any, props?: Record<any, any>, ...children: any[]) => any;
|
|
72
|
-
// find target component render function
|
|
73
|
-
getComponent: (currentNode: CNode | CRootNode, components: ComponentsType) => void;
|
|
74
|
-
getContext: (data: Record<any, any>, ctx: ContextType | null) => ContextType;
|
|
75
|
-
getUtils: () => void;
|
|
76
|
-
// 获取数据域链
|
|
77
|
-
getDataLink: () => void;
|
|
78
|
-
createDataLink: () => void;
|
|
79
|
-
transformProps: (originalProps: Record<any, any>, options: { $$context: Record<any, any> }) => Record<any, any>;
|
|
80
|
-
transformData: () => void;
|
|
81
|
-
transformGlobalData: () => void;
|
|
82
|
-
errorCatch: () => void;
|
|
83
|
-
// clear memory
|
|
84
|
-
clear: () => void;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const notImplements = (msg: string) => {
|
|
88
|
-
return () => {
|
|
89
|
-
console.warn(`${msg} need to be implement getComponent`);
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// 高级的 render 渲染器,可以完全自定义
|
|
94
|
-
const CustomAdvanceAdapter = ['customPageRootRender'] as const;
|
|
95
|
-
|
|
96
|
-
const AdapterMethodList = [
|
|
97
|
-
// 页面渲染
|
|
98
|
-
'pageRender',
|
|
99
|
-
// 渲染一个组件
|
|
100
|
-
'render',
|
|
101
|
-
// 将一个 组件 model 节点 转换为一个可被运行的渲染函数
|
|
102
|
-
'convertModelToComponent',
|
|
103
|
-
'getComponent',
|
|
104
|
-
'getContext',
|
|
105
|
-
'getUtils',
|
|
106
|
-
'getDataLink',
|
|
107
|
-
'createDataLink',
|
|
108
|
-
'transformProps',
|
|
109
|
-
'transformData',
|
|
110
|
-
'transformGlobalData',
|
|
111
|
-
'errorCatch',
|
|
112
|
-
'clear',
|
|
113
|
-
] as const;
|
|
114
|
-
|
|
115
|
-
type CustomAdvanceAdapterMethodListType = typeof CustomAdvanceAdapter[number];
|
|
116
|
-
|
|
117
|
-
// 必须实现的方法
|
|
118
|
-
type AdapterMethodListType = typeof AdapterMethodList[number];
|
|
119
|
-
|
|
120
|
-
export const getAdapter = (defineAdapter: Partial<AdapterType>): AdapterType => {
|
|
121
|
-
const adapter: AdapterType = [...AdapterMethodList, ...CustomAdvanceAdapter].reduce<Record<AdapterMethodListType, any>>((res, funcName) => {
|
|
122
|
-
if (defineAdapter?.[funcName]) {
|
|
123
|
-
res[funcName as AdapterMethodListType] = defineAdapter[funcName]?.bind(defineAdapter);
|
|
124
|
-
} else {
|
|
125
|
-
if (AdapterMethodList.includes(funcName as AdapterMethodListType)) {
|
|
126
|
-
res[funcName as AdapterMethodListType] = notImplements;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return res;
|
|
130
|
-
}, {} as any);
|
|
131
|
-
|
|
132
|
-
return adapter;
|
|
133
|
-
};
|