@chamn/render 0.0.8 → 0.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chamn/render",
3
3
  "private": false,
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -18,7 +18,7 @@
18
18
  "test": "jest"
19
19
  },
20
20
  "dependencies": {
21
- "@chamn/model": "0.0.8",
21
+ "@chamn/model": "0.0.9",
22
22
  "cross-env": "^7.0.3",
23
23
  "html-tag-names": "^2.0.1",
24
24
  "loadjs": "4.3.0-rc1",
@@ -29,9 +29,9 @@
29
29
  "zustand": "^4.1.5"
30
30
  },
31
31
  "devDependencies": {
32
- "@chamn/build-script": "0.0.8",
33
- "@chamn/demo-page": "0.0.8",
34
- "@chamn/material": "0.0.8",
32
+ "@chamn/build-script": "0.0.9",
33
+ "@chamn/demo-page": "0.0.9",
34
+ "@chamn/material": "0.0.9",
35
35
  "@types/loadjs": "^4.0.1",
36
36
  "@types/lodash-es": "^4.17.6",
37
37
  "@types/react": "^18.0.15",
@@ -40,5 +40,5 @@
40
40
  "react-router-dom": "^6.6.1"
41
41
  },
42
42
  "config": {},
43
- "gitHead": "9437e0937841d2b99709a6e95f6c1a07445bcf2e"
43
+ "gitHead": "f073439ea704830a6f62146c916c2f0348c2e531"
44
44
  }
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './core/adapterReact';
3
3
  export * from './core/render';
4
4
  export * from './core/designReactRender';
5
5
  export * from './util/assetsLoader';
6
+ export * from './util';
@@ -45,19 +45,20 @@ export class AssetLoader {
45
45
  this._onSuccessList.forEach((el) => el());
46
46
  return;
47
47
  }
48
- // 在下一个事件循环执行,确保 onSuccess 和 onError 被注册
49
- setTimeout(() => {
48
+
49
+ return new Promise((resolve, reject) => {
50
+ // 在下一个事件循环执行,确保 onSuccess 和 onError 被注册
50
51
  loadjs.ready(ids, {
51
52
  success: () => {
52
53
  this._onSuccessList.forEach((el) => el());
54
+ resolve('');
53
55
  },
54
56
  error: (depsNotFound) => {
55
57
  this._onErrorList.forEach((el) => el(depsNotFound));
58
+ reject(depsNotFound);
56
59
  },
57
60
  });
58
- }, 0);
59
-
60
- return this;
61
+ });
61
62
  }
62
63
 
63
64
  onSuccess(cb: () => void) {
package/src/util/index.ts CHANGED
@@ -2,6 +2,7 @@ import { capitalize } from 'lodash-es';
2
2
  import { Component, createElement } from 'react';
3
3
  import { ContextType } from '../core/adapter';
4
4
  import { StoreManager } from '../core/storeManager';
5
+ import { AssetPackage } from '@chamn/model';
5
6
 
6
7
  export const isClass = function (val: any) {
7
8
  if (!val) {
@@ -127,3 +128,37 @@ export const getCSSTextValue = (cssObj: Record<string, string>) => {
127
128
  });
128
129
  return res;
129
130
  };
131
+
132
+ export const collectVariable = (assetPackages: AssetPackage[], win: Window) => {
133
+ const res: Record<string, any> = {};
134
+ assetPackages.forEach((el) => {
135
+ if (el.globalName) {
136
+ const target = (win as any)[el.globalName];
137
+ if (target) {
138
+ res[el.globalName] = target;
139
+ }
140
+ }
141
+ });
142
+ return res;
143
+ };
144
+
145
+ export const flatObject = (obj: Record<string, any>, level = 1) => {
146
+ let count = 0;
147
+ let currentObj = obj;
148
+ let newObj: Record<string, any> = {};
149
+ let res = {};
150
+ while (count < level) {
151
+ Object.keys(currentObj).forEach((key) => {
152
+ newObj = {
153
+ ...newObj,
154
+ ...currentObj[key],
155
+ };
156
+ });
157
+ res = newObj;
158
+ currentObj = newObj;
159
+ newObj = {};
160
+ count += 1;
161
+ }
162
+
163
+ return res;
164
+ };
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- export declare const InnerComponent: {
3
- CContainer: ({ children, $$attributes, afterMount, beforeDestroy, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
4
- CVideo: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
5
- CAudio: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
6
- CBlock: ({ children, width, height, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
7
- CImage: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
8
- CText: ({ children, $$attributes, content, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
9
- CCanvas: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
10
- CNativeTag: ({ children, $$attributes, htmlTag, ...props }: any) => React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
11
- RootContainer: ({ children }: any) => any;
12
- };
@@ -1,2 +0,0 @@
1
- export declare const DYNAMIC_COMPONENT_TYPE = "DYNAMIC";
2
- export declare const InnerPropList: string[];
@@ -1,26 +0,0 @@
1
- import { CNode, CRootNode } from '@chamn/model';
2
- import React from 'react';
3
- type Props = {
4
- node: CNode | CRootNode;
5
- targetComponent: any;
6
- onError?: (error: React.ErrorInfo) => void;
7
- children?: React.ReactNode | React.ReactNode[];
8
- };
9
- declare class ErrorBoundary extends React.Component<Props, {
10
- error: any;
11
- hasError: boolean;
12
- }> {
13
- constructor(props: Props);
14
- static getDerivedStateFromError(error: any): {
15
- hasError: boolean;
16
- error: any;
17
- };
18
- componentDidCatch(_: Error, errorInfo: React.ErrorInfo): void;
19
- onDoubleClick: () => void;
20
- render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | React.CElement<{
21
- onlyRenderChild: boolean;
22
- }, React.Component<{
23
- onlyRenderChild: boolean;
24
- }, any, any>> | null | undefined;
25
- }
26
- export default ErrorBoundary;
@@ -1,64 +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
- export type ContextType = {
6
- params?: Record<any, any>;
7
- globalState?: Record<any, any>;
8
- updateGlobalState?: (newState: any) => void;
9
- staticState?: Record<string | number, any>;
10
- state?: Record<any, any>;
11
- updateState?: (newState: any) => void;
12
- refs?: RefManager;
13
- loopData?: Record<any, any>;
14
- stateManager?: Record<string, any>;
15
- methods?: Record<string, (...arg: any) => any>;
16
- thirdLibs?: Record<string, any>;
17
- };
18
- export type RuntimeRenderHelper = {
19
- renderComponent: (node: CNode | CRootNode, options: {
20
- $$context: ContextType;
21
- idx?: number;
22
- }) => any;
23
- };
24
- export type ComponentsType = Record<any, any>;
25
- export type AdapterOptionType = {
26
- libs: Record<string, any>;
27
- components: ComponentsType;
28
- $$context: ContextType;
29
- onGetRef?: (ref: React.RefObject<React.ReactInstance>, nodeMode: CNode | CRootNode, instance: RenderInstance) => void;
30
- onGetComponent?: (component: (...args: any) => any, currentNode: CNode | CRootNode) => void;
31
- onComponentMount?: (instance: ReactInstance, node: CNode | CRootNode) => void;
32
- onComponentDestroy?: (instance: ReactInstance, node: CNode | CRootNode) => void;
33
- processNodeConfigHook?: (config: {
34
- condition: boolean;
35
- props: Record<string, any>;
36
- }, node: CNode) => {
37
- condition: boolean;
38
- props: Record<string, any>;
39
- };
40
- renderMode?: 'design' | 'normal';
41
- };
42
- export interface AdapterType {
43
- renderMode?: AdapterOptionType['renderMode'];
44
- customPageRootRender?: (pageModel: CPage, options: AdapterOptionType) => any;
45
- pageRender: (pageModel: CPage, options: AdapterOptionType) => any;
46
- convertModelToComponent: (originalComponent: any, nodeModal: CNode | CRootNode, options: {
47
- pageModel: CPage;
48
- idx?: number;
49
- } & AdapterOptionType) => any;
50
- render: (originalComponent: any, props?: Record<any, any>, ...children: any[]) => any;
51
- getComponent: (currentNode: CNode | CRootNode, components: ComponentsType) => void;
52
- getContext: (data: Record<any, any>, ctx: ContextType | null) => ContextType;
53
- getUtils: () => void;
54
- getDataLink: () => void;
55
- createDataLink: () => void;
56
- transformProps: (originalProps: Record<any, any>, options: {
57
- $$context: Record<any, any>;
58
- }) => Record<any, any>;
59
- transformData: () => void;
60
- transformGlobalData: () => void;
61
- errorCatch: () => void;
62
- clear: () => void;
63
- }
64
- export declare const getAdapter: (defineAdapter: Partial<AdapterType>) => AdapterType;
@@ -1,108 +0,0 @@
1
- import React from 'react';
2
- import { CNode, CPage, CRootNode } from '@chamn/model';
3
- import { AdapterOptionType, ContextType } from './adapter';
4
- import { StoreApi } from 'zustand/vanilla';
5
- import { StoreManager } from './storeManager';
6
- export declare class DefineReactAdapter {
7
- renderMode: AdapterOptionType['renderMode'];
8
- components: AdapterOptionType['components'];
9
- storeManager: StoreManager;
10
- runtimeComponentCache: Map<any, any>;
11
- onGetRef?: AdapterOptionType['onGetRef'];
12
- onGetComponent: AdapterOptionType['onGetComponent'];
13
- onComponentMount: AdapterOptionType['onComponentMount'];
14
- onComponentDestroy: AdapterOptionType['onComponentDestroy'];
15
- processNodeConfigHook?: AdapterOptionType['processNodeConfigHook'];
16
- getComponent(currentNode: CNode | CRootNode): any;
17
- getContext(data?: ContextType, ctx?: ContextType | null): ContextType;
18
- pageRender(pageModel: CPage, { components, onGetRef, $$context, onGetComponent, onComponentMount, onComponentDestroy, renderMode, processNodeConfigHook, }: AdapterOptionType): string | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
19
- transformProps(originalProps: Record<string, any> | undefined, { $$context: parentContext, }: {
20
- $$context: ContextType;
21
- }): Record<string, any>;
22
- collectSpecialProps(originalProps: Record<string, unknown> | undefined, isValidate: (val: unknown) => boolean): {
23
- keyPath: string[];
24
- val: any;
25
- }[];
26
- convertModelToComponent(originalComponent: any, nodeModel: CNode | CRootNode): {
27
- new (props: {
28
- $$context: ContextType;
29
- $$nodeModel: CNode | CRootNode;
30
- }): {
31
- _CONDITION: boolean;
32
- _DESIGN_BOX: boolean;
33
- _NODE_MODEL: CNode | CRootNode;
34
- _NODE_ID: string;
35
- UNIQUE_ID: string;
36
- targetComponentRef: React.MutableRefObject<any>;
37
- listenerHandle: (() => void)[];
38
- storeState: StoreApi<any>;
39
- staticState: Record<string, any>;
40
- storeListenDisposeLint: (() => void)[];
41
- domHeader: HTMLHeadElement | undefined;
42
- mediaStyleDomMap: Record<string, HTMLStyleElement>;
43
- updateState: (newState: any) => void;
44
- connectStore(): void;
45
- getStyleDomById: (id: string) => HTMLStyleElement;
46
- addMediaCSS: () => void;
47
- removeMediaCSS: () => void;
48
- componentDidMount(): void;
49
- rebuildNode: () => void;
50
- componentWillUnmount(): void;
51
- render(): React.ReactNode;
52
- context: unknown;
53
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{
54
- $$context: ContextType;
55
- $$nodeModel: CNode | CRootNode;
56
- }>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
57
- forceUpdate(callback?: (() => void) | undefined): void;
58
- readonly props: Readonly<{
59
- $$context: ContextType;
60
- $$nodeModel: CNode | CRootNode;
61
- }>;
62
- state: Readonly<{}>;
63
- refs: {
64
- [key: string]: React.ReactInstance;
65
- };
66
- shouldComponentUpdate?(nextProps: Readonly<{
67
- $$context: ContextType;
68
- $$nodeModel: CNode | CRootNode;
69
- }>, nextState: Readonly<{}>, nextContext: any): boolean;
70
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
71
- getSnapshotBeforeUpdate?(prevProps: Readonly<{
72
- $$context: ContextType;
73
- $$nodeModel: CNode | CRootNode;
74
- }>, prevState: Readonly<{}>): any;
75
- componentDidUpdate?(prevProps: Readonly<{
76
- $$context: ContextType;
77
- $$nodeModel: CNode | CRootNode;
78
- }>, prevState: Readonly<{}>, snapshot?: any): void;
79
- componentWillMount?(): void;
80
- UNSAFE_componentWillMount?(): void;
81
- componentWillReceiveProps?(nextProps: Readonly<{
82
- $$context: ContextType;
83
- $$nodeModel: CNode | CRootNode;
84
- }>, nextContext: any): void;
85
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
86
- $$context: ContextType;
87
- $$nodeModel: CNode | CRootNode;
88
- }>, nextContext: any): void;
89
- componentWillUpdate?(nextProps: Readonly<{
90
- $$context: ContextType;
91
- $$nodeModel: CNode | CRootNode;
92
- }>, nextState: Readonly<{}>, nextContext: any): void;
93
- UNSAFE_componentWillUpdate?(nextProps: Readonly<{
94
- $$context: ContextType;
95
- $$nodeModel: CNode | CRootNode;
96
- }>, nextState: Readonly<{}>, nextContext: any): void;
97
- };
98
- __CP_TYPE__: string;
99
- contextType?: React.Context<any> | undefined;
100
- };
101
- buildComponent(node: CNode | CRootNode | string, { $$context, }: {
102
- $$context: ContextType;
103
- idx?: number;
104
- }): string | React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
105
- render(originalComponent: React.ComponentClass<any> | React.FunctionComponent | string, props?: Record<any, any>, ...children: React.ReactNode[]): string | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
106
- clear(): void;
107
- }
108
- export declare const ReactAdapter: import("./adapter").AdapterType;
@@ -1,47 +0,0 @@
1
- import { CNode, CPage, CPageDataType, CRootNode } from '@chamn/model';
2
- import React from 'react';
3
- import { RenderPropsType, Render, UseRenderReturnType } from './render';
4
- import { RenderInstance } from './type';
5
- export declare class ComponentInstanceManager {
6
- private instanceMap;
7
- get(id: string): RenderInstance[] | undefined;
8
- add(id: string, handle: any): void;
9
- remove(id: string, val?: any): void;
10
- destroy(): void;
11
- }
12
- export type DesignRenderProp = Omit<RenderPropsType, 'ref' | 'render'> & {
13
- ref?: React.MutableRefObject<DesignRender | null>;
14
- render?: UseDesignRenderReturnType;
15
- onMount?: (instance: DesignRender) => void;
16
- dropPlaceholder?: React.ComponentClass<{
17
- node: CNode | CRootNode;
18
- }> | React.FunctionComponent<{
19
- node: CNode | CRootNode;
20
- }> | string;
21
- };
22
- export declare const DefaultDropPlaceholder: React.FC<{
23
- node: CNode | CRootNode;
24
- }>;
25
- export declare class DesignRender extends React.Component<DesignRenderProp> {
26
- instanceManager: ComponentInstanceManager;
27
- renderRef: React.MutableRefObject<Render | null>;
28
- dropPlaceholder: Required<DesignRenderProp>['dropPlaceholder'];
29
- constructor(props: DesignRenderProp);
30
- componentDidMount(): void;
31
- getPageModel(): CPage | undefined;
32
- onGetComponent: (comp: any, node: CNode | CRootNode) => React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<unknown>>;
33
- rerender(newPage?: CPageDataType | CPage): void | undefined;
34
- getInstancesById(id: string, uniqueId?: string): RenderInstance[];
35
- getInstanceByDom(el: HTMLHtmlElement | Element): RenderInstance | null;
36
- getDomsById(id: string, selector?: string): HTMLElement[];
37
- getDomRectById(id: string, selector?: string): DOMRect[];
38
- render(): React.CElement<RenderPropsType, Render>;
39
- }
40
- export type UseDesignRenderReturnType = Pick<UseRenderReturnType, 'rerender'> & {
41
- ref: React.MutableRefObject<DesignRender | null>;
42
- getInstancesById: (id: string, uid?: string) => RenderInstance[];
43
- getInstanceByDom: (dom: HTMLHtmlElement | Element) => RenderInstance | null;
44
- getDomsById: (id: string, selector?: string) => HTMLElement[];
45
- getDomRectById: (id: string, selector?: string) => DOMRect | DOMRect[];
46
- };
47
- export declare const useDesignRender: () => UseDesignRenderReturnType;
@@ -1,7 +0,0 @@
1
- export declare class RefManager {
2
- private refMap;
3
- get(id: string): any;
4
- add(id: string, handle: any): void;
5
- remove(id: string): void;
6
- destroy(): void;
7
- }
@@ -1,32 +0,0 @@
1
- import { CPage, CPageDataType } from '@chamn/model';
2
- import React from 'react';
3
- import { AdapterOptionType, AdapterType } from './adapter';
4
- import { RefManager } from './refManager';
5
- import { RenderInstance } from './type';
6
- export type RenderPropsType = {
7
- page?: CPageDataType;
8
- pageModel?: CPage;
9
- adapter: AdapterType;
10
- render?: UseRenderReturnType;
11
- ref?: React.MutableRefObject<Render | null>;
12
- renderMode?: 'design' | 'normal';
13
- } & Partial<AdapterOptionType>;
14
- export declare class Render extends React.Component<RenderPropsType, {
15
- pageModel: CPage;
16
- }> {
17
- refManager: RefManager;
18
- dynamicComponentInstanceMap: Map<string, RenderInstance>;
19
- constructor(props: RenderPropsType);
20
- getPageModel(): CPage;
21
- componentDidMount(): void;
22
- componentWillUnmount(): void;
23
- onGetRef: AdapterOptionType['onGetRef'];
24
- render(): any;
25
- rerender: (newPage?: CPageDataType | CPage) => void;
26
- }
27
- export type UseRenderReturnType = {
28
- ref: React.MutableRefObject<Render | null>;
29
- rerender: (newPage: CPageDataType) => void;
30
- };
31
- export declare const useRender: () => UseRenderReturnType;
32
- export * from './type';
@@ -1,11 +0,0 @@
1
- import { StateCreator, StoreApi } from 'zustand/vanilla';
2
- export declare class StoreManager {
3
- storeMap: Map<string, StoreApi<any>>;
4
- addStore(storeName: string, storeState: StateCreator<any>): StoreApi<any>;
5
- setStore(storeName: string, store: StoreApi<any>): void;
6
- removeStore(storeName: string): void;
7
- getStore(storeName: string): StoreApi<any> | undefined;
8
- connect<T extends Record<any, any> = any>(name: string, cb: (newState: T) => void): () => void;
9
- getStateSnapshot(): Record<string, any>;
10
- destroy(): void;
11
- }
@@ -1,9 +0,0 @@
1
- import { CNode, CRootNode } from '@chamn/model';
2
- export type RenderInstance = React.ReactInstance & {
3
- _DESIGN_BOX: boolean;
4
- _NODE_MODEL: CNode | CRootNode;
5
- _NODE_ID: string;
6
- _UNIQUE_ID: string;
7
- _STATUS?: 'DESTROY';
8
- _CONDITION?: boolean;
9
- };
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './core/adapter';
2
- export * from './core/adapterReact';
3
- export * from './core/render';
4
- export * from './core/designReactRender';
5
- export * from './util/assetsLoader';
@@ -1,15 +0,0 @@
1
- import { AssetPackage } from '@chamn/model';
2
- export type Asset = AssetPackage;
3
- export declare class AssetLoader {
4
- assets: Asset[];
5
- loadStatus: 'INIT' | 'SUCCESS' | 'ERROR';
6
- win: Window;
7
- private _onSuccessList;
8
- private _onErrorList;
9
- constructor(assets: Asset[], options?: {
10
- window?: Window;
11
- });
12
- load(): this | undefined;
13
- onSuccess(cb: () => void): this;
14
- onError(cb: () => void): this;
15
- }
@@ -1,17 +0,0 @@
1
- import { ContextType } from '../core/adapter';
2
- import { StoreManager } from '../core/storeManager';
3
- export declare const isClass: (val: any) => boolean;
4
- export declare function shouldConstruct(Component: Function): boolean;
5
- export declare function canAcceptsRef(Comp: any): any;
6
- export declare function compWrapper(Comp: any): any;
7
- export declare const runExpression: (expStr: string, context: any) => any;
8
- export declare const convertCodeStringToFunction: (functionStr: string, $$context: ContextType, storeManager: StoreManager) => (...args: any[]) => void;
9
- /**
10
- *
11
- * @param args 对象的值
12
- * @param argsName 对因位置的 名称
13
- * @returns
14
- */
15
- export declare const getObjFromArrayMap: (args: any[], argsName: string[]) => Record<any, any>;
16
- export declare const formatSourceStylePropertyName: (style: Record<string, string>) => Record<string, string>;
17
- export declare const getCSSTextValue: (cssObj: Record<string, string>) => string;