@chamn/render 0.2.4 → 0.3.0

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.
@@ -1,2 +1,7 @@
1
1
  export declare const DYNAMIC_COMPONENT_TYPE = "DYNAMIC";
2
2
  export declare const InnerPropList: string[];
3
+ /** 内部事件,组件渲染之后 */
4
+ export declare const ON_DID_RENDER = "ON_DID_RENDER";
5
+ /** 组件销毁之前 */
6
+ export declare const ON_WILL_DESTROY = "ON_WILL_DESTROY";
7
+ export declare const INNER_EVENT_LIST: string[];
@@ -0,0 +1,7 @@
1
+ import { CNode, CRootNode } from '@chamn/model';
2
+ import { ContextType } from '../adapter';
3
+ import { TRenderBaseOption } from './type';
4
+ export declare const buildComponent: (node: CNode | CRootNode | string, option: {
5
+ $$context: ContextType;
6
+ idx?: number;
7
+ } & TRenderBaseOption) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | undefined;
@@ -0,0 +1,75 @@
1
+ import { CNode, CRootNode } from '@chamn/model';
2
+ import { ContextType } from '../adapter';
3
+ import React from 'react';
4
+ import { StoreApi } from 'zustand';
5
+ import { TRenderBaseOption } from './type';
6
+ type PropsType = {
7
+ $$context: ContextType;
8
+ $$nodeModel: CNode | CRootNode;
9
+ };
10
+ export declare const convertModelToComponent: (originalComponent: any, nodeModel: CNode | CRootNode, options: TRenderBaseOption) => {
11
+ new (props: PropsType): {
12
+ _CONDITION: boolean;
13
+ _DESIGN_BOX: boolean;
14
+ _NODE_MODEL: CNode | CRootNode;
15
+ _NODE_ID: string;
16
+ UNIQUE_ID: string;
17
+ targetComponentRef: React.MutableRefObject<any>;
18
+ listenerHandle: (() => void)[];
19
+ storeState: StoreApi<any>;
20
+ storeListenDisposeList: (() => void)[];
21
+ /** save dom and media css */
22
+ domHeader: HTMLHeadElement | undefined;
23
+ mediaStyleDomMap: Record<string, HTMLStyleElement>;
24
+ /** 存储当前节点的一些变量和方法,不具有响应性 */
25
+ variableSpace: {
26
+ staticVar: Record<any, any>;
27
+ methods: Record<any, (...args: any) => any>;
28
+ };
29
+ nodeName: any;
30
+ updateState: (newState: any) => void;
31
+ connectStore(): void;
32
+ getStyleDomById: (id: string) => HTMLStyleElement;
33
+ addMediaCSS: () => void;
34
+ removeMediaCSS: () => void;
35
+ rebuildNode: () => void;
36
+ componentDidMount(): void;
37
+ componentWillUnmount(): void;
38
+ /** 转换节点的 methods */
39
+ transformMethods(option: {
40
+ context: ContextType;
41
+ }): void;
42
+ /** 处理根节点的 context */
43
+ processRootContext(context: ContextType): void;
44
+ processNodeClassName(className: string, context: ContextType): string;
45
+ processNodeStyle(newContext: ContextType): Record<string, string>;
46
+ processNodeChild(children: any, newContext: ContextType): React.ReactNode[];
47
+ processNodeConditionAndConfigHook(newProps: any, newChildren: any, newContext: ContextType): string | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
48
+ processNodeEventListener(newContext: ContextType): any;
49
+ createCurrentNodeCtx(): ContextType;
50
+ renderCore(): React.ReactNode;
51
+ renderLoop(): React.ReactNode;
52
+ render(): React.ReactNode;
53
+ context: unknown;
54
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<PropsType>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
55
+ forceUpdate(callback?: (() => void) | undefined): void;
56
+ readonly props: Readonly<PropsType>;
57
+ state: Readonly<{}>;
58
+ refs: {
59
+ [key: string]: React.ReactInstance;
60
+ };
61
+ shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<{}>, nextContext: any): boolean;
62
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
63
+ getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>): any;
64
+ componentDidUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>, snapshot?: any): void;
65
+ componentWillMount?(): void;
66
+ UNSAFE_componentWillMount?(): void;
67
+ componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
68
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
69
+ componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<{}>, nextContext: any): void;
70
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<{}>, nextContext: any): void;
71
+ };
72
+ __CP_TYPE__: string;
73
+ contextType?: React.Context<any> | undefined;
74
+ };
75
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { ContextType } from '../adapter';
3
+ export declare const getContext: (data: ContextType, ctx?: ContextType | null) => ContextType;
4
+ export declare const renderComponent: (originalComponent: React.ComponentClass<any> | React.FunctionComponent | string, props?: Record<any, any>, ...children: React.ReactNode[]) => string | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
5
+ export declare const collectSpecialProps: (originalProps: Record<string, unknown> | undefined, isValidate: (val: unknown) => boolean) => {
6
+ keyPath: string[];
7
+ val: any;
8
+ }[];
@@ -0,0 +1,34 @@
1
+ import { CNode, CPage, CRootNode } from '@chamn/model';
2
+ import { AdapterOptionType } from '../adapter';
3
+ import { StoreManager } from '../storeManager';
4
+ import { VariableManager } from '../variableManager';
5
+ import { RefManager } from '../refManager';
6
+ export declare class DefineReactAdapter {
7
+ renderMode: AdapterOptionType['renderMode'];
8
+ components: AdapterOptionType['components'];
9
+ storeManager: StoreManager;
10
+ variableManager: VariableManager;
11
+ runtimeComponentCache: Map<string, {
12
+ component: any;
13
+ }>;
14
+ onGetRef?: AdapterOptionType['onGetRef'];
15
+ onGetComponent: AdapterOptionType['onGetComponent'];
16
+ onComponentMount: AdapterOptionType['onComponentMount'];
17
+ refManager: RefManager;
18
+ onComponentDestroy: AdapterOptionType['onComponentDestroy'];
19
+ /**
20
+ * 处理 props 钩子, 可以统一拦截 node 的处理,并修改其值
21
+ */
22
+ processNodeConfigHook?: AdapterOptionType['processNodeConfigHook'];
23
+ /**
24
+ * 根据 node 获取对应渲染的组件
25
+ * @param currentNode
26
+ * @returns
27
+ */
28
+ getComponent(currentNode: CNode | CRootNode): any;
29
+ pageRender(pageModel: CPage, { components, onGetRef, refManager, $$context, onGetComponent, onComponentMount, onComponentDestroy, renderMode, processNodeConfigHook, requestAPI, }: AdapterOptionType): string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
30
+ /** 请求 API */
31
+ requestAPI: AdapterOptionType['requestAPI'];
32
+ clear(): void;
33
+ }
34
+ export declare const ReactAdapter: import("../adapter").AdapterType;
@@ -0,0 +1,12 @@
1
+ import { TActionLogicItem } from '@chamn/model';
2
+ import { ContextType } from '../../adapter';
3
+ import { StoreManager } from '../../storeManager';
4
+ type CommonOption = {
5
+ context: ContextType;
6
+ storeManager: StoreManager;
7
+ $$response?: any;
8
+ /** 当前 action 上下文的变量空间 */
9
+ actionVariableSpace: Record<string, string>;
10
+ };
11
+ export declare const transformActionNode: (propVal: TActionLogicItem, options: CommonOption) => (...args: any[]) => Promise<void>;
12
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ContextType } from '../../adapter';
2
+ import { TRenderBaseOption } from '../type';
3
+ export declare const transformProps: (originalProps: Record<string, any> | undefined, option: {
4
+ $$context: ContextType;
5
+ } & TRenderBaseOption) => Record<string, any>;
@@ -0,0 +1,40 @@
1
+ import { CNode, CRootNode } from '@chamn/model';
2
+ import { AdapterOptionType } from '../adapter';
3
+ import { StoreManager } from '../storeManager';
4
+ import { VariableManager } from '../variableManager';
5
+ import { StoreApi } from 'zustand';
6
+ export type TRenderBaseOption = {
7
+ storeManager: StoreManager;
8
+ variableManager: VariableManager;
9
+ runtimeComponentCache: Map<string, {
10
+ component: any;
11
+ }>;
12
+ getComponent: (currentNode: CNode | CRootNode) => any;
13
+ } & Pick<Required<AdapterOptionType>, 'onGetRef' | 'processNodeConfigHook' | 'refManager' | 'onComponentDestroy' | 'onComponentMount' | 'renderMode'> & Pick<AdapterOptionType, 'requestAPI'>;
14
+ export interface IDynamicComponent {
15
+ _CONDITION: boolean;
16
+ _DESIGN_BOX: boolean;
17
+ _NODE_MODEL: CNode | CRootNode;
18
+ _NODE_ID: string;
19
+ UNIQUE_ID: string;
20
+ targetComponentRef: React.MutableRefObject<any>;
21
+ listenerHandle: (() => void)[];
22
+ storeState: StoreApi<any>;
23
+ storeListenDisposeList: (() => void)[];
24
+ domHeader?: HTMLHeadElement;
25
+ mediaStyleDomMap: Record<string, HTMLStyleElement>;
26
+ variableSpace: {
27
+ staticVar: Record<any, any>;
28
+ methods: Record<any, (...args: any) => any>;
29
+ };
30
+ nodeName: string;
31
+ updateState(newState: any): void;
32
+ connectStore(): void;
33
+ addMediaCSS(): void;
34
+ removeMediaCSS(): void;
35
+ getStyleDomById(id: string): HTMLStyleElement;
36
+ rebuildNode(): void;
37
+ componentDidMount(): void;
38
+ componentWillUnmount(): void;
39
+ render(): React.ReactNode;
40
+ }
@@ -38,10 +38,11 @@ export type ContextType = {
38
38
  /** 循环数据 */
39
39
  loopData?: Record<any, any>;
40
40
  /** 组件节点的 Ref */
41
- refs?: RefManager;
41
+ nodeRefs?: RefManager;
42
42
  storeManager?: StoreManager;
43
43
  /** 第三方辅助库 */
44
44
  thirdLibs?: Record<string, any>;
45
+ requestAPI?: AdapterOptionType['requestAPI'];
45
46
  };
46
47
  export type RuntimeRenderHelper = {
47
48
  renderComponent: (node: CNode | CRootNode, options: {
@@ -54,6 +55,7 @@ export type AdapterOptionType = {
54
55
  libs: Record<string, any>;
55
56
  components: ComponentsType;
56
57
  $$context: ContextType;
58
+ refManager: RefManager;
57
59
  onGetRef?: (ref: React.RefObject<React.ReactInstance>, nodeMode: CNode | CRootNode, instance: RenderInstance) => void;
58
60
  onGetComponent?: (component: (...args: any) => any, currentNode: CNode | CRootNode) => void;
59
61
  onComponentMount?: (instance: ReactInstance, node: CNode | CRootNode) => void;
@@ -66,6 +68,14 @@ export type AdapterOptionType = {
66
68
  props: Record<string, any>;
67
69
  };
68
70
  renderMode?: 'design' | 'normal';
71
+ /** 请求 API */
72
+ requestAPI?: (params: {
73
+ url: string;
74
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
75
+ header: Record<any, any>;
76
+ body?: Record<any, any>;
77
+ query?: Record<any, any>;
78
+ }) => Promise<any>;
69
79
  };
70
80
  export interface AdapterType {
71
81
  renderMode?: AdapterOptionType['renderMode'];
@@ -75,17 +85,15 @@ export interface AdapterType {
75
85
  pageModel: CPage;
76
86
  idx?: number;
77
87
  } & AdapterOptionType) => any;
88
+ /** 请求 API */
89
+ requestAPI?: AdapterOptionType['requestAPI'];
78
90
  render: (originalComponent: any, props?: Record<any, any>, ...children: any[]) => any;
79
91
  getComponent: (currentNode: CNode | CRootNode, components: ComponentsType) => void;
80
92
  getContext: (data: Record<any, any>, ctx: ContextType | null) => ContextType;
81
93
  getUtils: () => void;
82
- getDataLink: () => void;
83
- createDataLink: () => void;
84
94
  transformProps: (originalProps: Record<any, any>, options: {
85
95
  $$context: Record<any, any>;
86
96
  }) => Record<any, any>;
87
- transformData: () => void;
88
- transformGlobalData: () => void;
89
97
  errorCatch: () => void;
90
98
  clear: () => void;
91
99
  }
@@ -1,3 +1,4 @@
1
+ /** 变量空间,没有响应性 */
1
2
  export declare class VariableManager {
2
3
  private varSpace;
3
4
  get(id: string): any;