@easy-editor/renderer-core 1.0.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.
@@ -0,0 +1,22 @@
1
+ import type { NodeSchema } from '@easy-editor/core';
2
+ /**
3
+ * Minimal framework-agnostic component interface
4
+ * Contains only essential shared properties across frameworks
5
+ */
6
+ export interface GeneralComponent<P = Record<string, unknown>, S = Record<string, unknown>, SS = any> {
7
+ readonly props: Readonly<P> & Readonly<{
8
+ children?: any | undefined;
9
+ }>;
10
+ state: Readonly<S>;
11
+ refs: Record<string, any>;
12
+ context: any;
13
+ setState<K extends keyof S>(state: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | S | null) | (Pick<S, K> | S | null), callback?: () => void): void;
14
+ forceUpdate(callback?: () => void): void;
15
+ render?(): any;
16
+ }
17
+ export interface FaultComponentProps extends NodeSchema {
18
+ error?: Error | string;
19
+ }
20
+ export interface NotFoundComponentProps extends NodeSchema {
21
+ enableStrictNotFoundMode?: boolean;
22
+ }
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './renderer';
3
+ export * from './setting-renderer';
@@ -0,0 +1,220 @@
1
+ import type { ComponentType, DesignMode, JSExpression, JSONObject, Node, NodeSchema, RootSchema, Simulator, SimulatorRenderer } from '@easy-editor/core';
2
+ import type { FaultComponentProps, GeneralComponent, NotFoundComponentProps } from './components';
3
+ export type Schema = NodeSchema | RootSchema;
4
+ export interface RendererState {
5
+ engineRenderError?: boolean;
6
+ error?: Error;
7
+ }
8
+ export interface RendererProps {
9
+ /** 符合低代码搭建协议的数据 */
10
+ schema: RootSchema | NodeSchema;
11
+ /** 组件依赖的实例 */
12
+ components: Record<string, ComponentType<any>>;
13
+ /** CSS 类名 */
14
+ className?: string;
15
+ /** style */
16
+ style?: Record<string, any>;
17
+ /** id */
18
+ id?: string | number;
19
+ /** 当前文档的 id */
20
+ documentId?: string;
21
+ /** 主要用于设置渲染模块的全局上下文,里面定义的内容可以在低代码中通过 this 来访问,比如 this.utils */
22
+ appHelper?: RendererAppHelper;
23
+ /**
24
+ * 配置规范参见《低代码搭建组件描述协议》https://lowcode-engine.cn/lowcode
25
+ * 主要在搭建场景中使用,用于提升用户搭建体验。
26
+ *
27
+ * > 在生产环境下不需要设置
28
+ */
29
+ componentsMap?: Record<string, any>;
30
+ /** 设计模式,可选值:live、design */
31
+ designMode?: DesignMode;
32
+ /** 渲染模块是否挂起,当设置为 true 时,渲染模块最外层容器的 shouldComponentUpdate 将始终返回false,在下钻编辑或者多引擎渲染的场景会用到该参数。 */
33
+ suspended?: boolean;
34
+ /** 组件获取 ref 时触发的钩子 */
35
+ onCompGetRef?: (schema: NodeSchema, ref: any) => void;
36
+ /** 组件 ctx 更新回调 */
37
+ onCompGetCtx?: (schema: NodeSchema, ref: any) => void;
38
+ /** 传入的 schema 是否有变更 */
39
+ getSchemaChangedSymbol?: () => boolean;
40
+ /** 设置 schema 是否有变更 */
41
+ setSchemaChangedSymbol?: (symbol: boolean) => void;
42
+ /** 自定义创建 element 的钩子 */
43
+ customCreateElement?: (Component: any, props: any, children: any) => any;
44
+ /** 渲染类型,标识当前模块是以什么类型进行渲染的 */
45
+ rendererName?: 'LowCodeRenderer' | 'PageRenderer' | string;
46
+ /** 当找不到组件时,显示的组件 */
47
+ notFoundComponent?: ComponentType<NotFoundComponentProps>;
48
+ /** 当组件渲染异常时,显示的组件 */
49
+ faultComponent?: ComponentType<FaultComponentProps>;
50
+ /** 设备信息 */
51
+ device?: 'default' | 'pc' | 'mobile' | string;
52
+ /**
53
+ * 当开启组件未找到严格模式时,渲染模块不会默认给一个容器组件
54
+ * @default false
55
+ */
56
+ enableStrictNotFoundMode?: boolean;
57
+ /** 获取节点的方法 */
58
+ getNode?: (id: string) => Node;
59
+ /** 渲染模块的 host */
60
+ __host?: Simulator;
61
+ /** 渲染模块的 container */
62
+ __container?: SimulatorRenderer;
63
+ /**
64
+ * 是否在设计模式下执行生命周期方法
65
+ * @default false
66
+ */
67
+ excuteLifeCycleInDesignMode?: boolean;
68
+ }
69
+ export interface RendererComponent<C = GeneralComponent<RendererProps, RendererState>> {
70
+ displayName: string;
71
+ defaultProps: RendererProps;
72
+ new (props: RendererProps): RendererComponentInstance<C>;
73
+ }
74
+ export type RendererComponentInstance<C = GeneralComponent<RendererProps, RendererState>> = C & {
75
+ __getRef: (ref: any) => void;
76
+ componentDidMount(): Promise<void> | void;
77
+ componentDidUpdate(): Promise<void> | void;
78
+ componentWillUnmount(): Promise<void> | void;
79
+ componentDidCatch(e: any): Promise<void> | void;
80
+ shouldComponentUpdate(nextProps: RendererProps): boolean;
81
+ isValidComponent(Component: any): boolean;
82
+ createElement(Component: any, props: any, children?: any): any;
83
+ getNotFoundComponent(): any;
84
+ getFaultComponent(): any;
85
+ };
86
+ /**
87
+ * duck-typed History
88
+ *
89
+ * @see https://github.com/ReactTraining/history/tree/master/docs/api-reference.md
90
+ */
91
+ interface HistoryLike {
92
+ readonly action: any;
93
+ readonly location: LocationLike;
94
+ createHref: (to: any) => string;
95
+ push: (to: any, state?: any) => void;
96
+ replace: (to: any, state?: any) => void;
97
+ go: (delta: any) => void;
98
+ back: () => void;
99
+ forward: () => void;
100
+ listen: (listener: any) => () => void;
101
+ block: (blocker: any) => () => void;
102
+ }
103
+ /**
104
+ * duck-typed History.Location
105
+ *
106
+ * @see https://github.com/remix-run/history/blob/dev/docs/api-reference.md#location
107
+ */
108
+ export interface LocationLike {
109
+ pathname: any;
110
+ search: any;
111
+ state: any;
112
+ hash: any;
113
+ key?: any;
114
+ }
115
+ export interface RendererAppHelper {
116
+ /** 全局公共函数 */
117
+ utils?: Record<string, any>;
118
+ /** 全局常量 */
119
+ constants?: Record<string, any>;
120
+ /** react-router 的 location 实例 */
121
+ location?: LocationLike;
122
+ /** react-router 的 history 实例 */
123
+ history?: HistoryLike;
124
+ /** 数据源引擎 */
125
+ dataSourceEngine?: {
126
+ createDataSourceEngine: (dataSource: DataSource, engine: any) => {
127
+ dataSourceMap: Record<string, any>;
128
+ reloadDataSource: () => Promise<void>;
129
+ };
130
+ [key: string]: any;
131
+ };
132
+ }
133
+ export interface NodeInfo {
134
+ schema?: NodeSchema;
135
+ Comp: any;
136
+ componentInfo?: any;
137
+ componentChildren?: any;
138
+ }
139
+ export interface DataSourceItem {
140
+ id: string;
141
+ isInit?: boolean | JSExpression;
142
+ type?: string;
143
+ options?: {
144
+ uri: string | JSExpression;
145
+ params?: JSONObject | JSExpression;
146
+ method?: string | JSExpression;
147
+ shouldFetch?: string;
148
+ willFetch?: string;
149
+ fit?: string;
150
+ didFetch?: string;
151
+ };
152
+ dataHandler?: JSExpression;
153
+ }
154
+ export interface DataSource {
155
+ list?: DataSourceItem[];
156
+ dataHandler?: JSExpression;
157
+ }
158
+ export interface BaseRendererProps extends RendererProps {
159
+ __appHelper?: RendererAppHelper;
160
+ __components: Record<string, ComponentType<any>>;
161
+ __ctx?: Record<string, any>;
162
+ __schema: RootSchema;
163
+ __designMode?: DesignMode;
164
+ __host?: Simulator;
165
+ __container?: SimulatorRenderer;
166
+ config?: Record<string, any>;
167
+ designMode?: DesignMode;
168
+ className?: string;
169
+ style?: Record<string, any>;
170
+ id?: string | number;
171
+ getSchemaChangedSymbol?: () => boolean;
172
+ setSchemaChangedSymbol?: (symbol: boolean) => void;
173
+ documentId?: string;
174
+ getNode?: any;
175
+ /**
176
+ * 设备类型,默认值:'default'
177
+ */
178
+ device?: 'default' | 'pc' | 'mobile' | string;
179
+ componentName?: string;
180
+ }
181
+ export interface BaseRendererContext<C = GeneralComponent<BaseRendererProps, Record<string, any>, any>> {
182
+ appHelper: RendererAppHelper;
183
+ components: Record<string, ComponentType<any>>;
184
+ engine: RendererComponentInstance<C>;
185
+ pageContext?: BaseRendererComponent<C>;
186
+ compContext?: BaseRendererComponent<C>;
187
+ }
188
+ export type BaseRendererInstance<C = GeneralComponent<BaseRendererProps, Record<string, any>, any>> = C & {
189
+ reloadDataSource(): Promise<any>;
190
+ __beforeInit(props: BaseRendererProps): void;
191
+ __init(props: BaseRendererProps): void;
192
+ __afterInit(props: BaseRendererProps): void;
193
+ __executeLifeCycleMethod(method: string, args?: any[]): void;
194
+ __getComponentView(): ComponentType<any> | undefined;
195
+ __bindCustomMethods(props: BaseRendererProps): void;
196
+ __generateCtx(ctx: Record<string, any>): void;
197
+ __parseData(data: any, ctx?: any): any;
198
+ __initDataSource(props: BaseRendererProps): void;
199
+ __writeCss(props: BaseRendererProps): void;
200
+ __render(): void;
201
+ __getRef(ref: any): void;
202
+ __getSchemaChildrenVirtualDom(schema: NodeSchema | undefined, Comp: any, nodeChildrenMap?: any): any;
203
+ __getComponentProps(schema: NodeSchema | undefined, scope: any, Comp: any, componentInfo?: any): any;
204
+ __createDom(): any;
205
+ __createVirtualDom(schema: any, self: any, parentInfo: NodeInfo, idx: string | number): any;
206
+ __createLoopVirtualDom(schema: any, self: any, parentInfo: NodeInfo, idx: number | string): any;
207
+ __parseProps(props: any, self: any, path: string, info: NodeInfo): any;
208
+ __renderContextProvider(customProps?: object, children?: any): any;
209
+ __renderContextConsumer(children: any): any;
210
+ __renderContent(children: any): any;
211
+ __checkSchema(schema: NodeSchema | undefined, extraComponents?: string | string[]): any;
212
+ __renderComp(Comp: any, ctxProps: object): any;
213
+ $(id: string, instance?: any): any;
214
+ context: BaseRendererContext<C>;
215
+ __designModeIsDesign?: boolean;
216
+ };
217
+ export interface BaseRendererComponent<C = GeneralComponent<BaseRendererProps, Record<string, any>, any>> {
218
+ new (props: BaseRendererProps): BaseRendererInstance<C>;
219
+ }
220
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { Component, Designer, SettingField } from '@easy-editor/core';
2
+ export interface SettingRendererProps {
3
+ designer: Designer;
4
+ /** 自定义渲染 Field Item */
5
+ customFieldItem?: (field: SettingField, setter: Component) => Component;
6
+ /** 自定义渲染 Field Group */
7
+ customFieldGroup?: (field: SettingField, setters: Component) => Component;
8
+ [extra: string]: any;
9
+ }
@@ -0,0 +1 @@
1
+ export declare const classnames: (...args: any[]) => string;
@@ -0,0 +1,56 @@
1
+ import { type NodeSchema } from '@easy-editor/core';
2
+ export declare const inSameDomain: () => boolean;
3
+ /**
4
+ * get css styled name from schema`s fileName
5
+ * FileName -> lce-file-name
6
+ * @returns string
7
+ */
8
+ export declare const getFileCssName: (fileName: string) => string | undefined;
9
+ export declare const isSchema: (schema: any) => schema is NodeSchema;
10
+ export declare const getValue: (obj: any, path: string, defaultValue?: {}) => any;
11
+ export declare const transformArrayToMap: (arr: any[], key: string, overwrite?: boolean) => any;
12
+ interface IParseOptions {
13
+ logScope?: string;
14
+ }
15
+ export declare const parseData: (schema: unknown, self: any, options?: IParseOptions) => any;
16
+ export declare const isUseLoop: (loop: null | any[], isDesignMode: boolean) => boolean;
17
+ export declare const checkPropTypes: (value: any, name: string, rule: any, componentName: string) => boolean;
18
+ /**
19
+ * transform string to a function
20
+ * @param str function in string form
21
+ * @returns funtion
22
+ */
23
+ export declare const transformStringToFunction: (str: string) => any;
24
+ /**
25
+ * 对象类型JSExpression,支持省略this
26
+ * @param str expression in string form
27
+ * @param self scope object
28
+ * @returns funtion
29
+ */
30
+ declare function parseExpression(options: {
31
+ str: any;
32
+ self: any;
33
+ thisRequired?: boolean;
34
+ logScope?: string;
35
+ }): any;
36
+ declare function parseExpression(str: any, self: any, thisRequired?: boolean): any;
37
+ export { parseExpression };
38
+ export declare const parseThisRequiredExpression: (str: any, self: any) => any;
39
+ /**
40
+ * check str passed in is a string type of not
41
+ * @param str obj to be checked
42
+ * @returns boolean
43
+ */
44
+ export declare const isString: (str: any) => boolean;
45
+ /**
46
+ * capitalize first letter
47
+ * @param word string to be proccessed
48
+ * @returns string capitalized string
49
+ */
50
+ export declare const capitalizeFirstLetter: (word: string) => string;
51
+ /**
52
+ * process params for using in a url query
53
+ * @param obj params to be processed
54
+ * @returns string
55
+ */
56
+ export declare const serializeParams: (obj: any) => any;
@@ -0,0 +1,83 @@
1
+ import { type DataSource } from '@easy-editor/core';
2
+ import type { RendererAppHelper } from '../types';
3
+ type DataSourceType = 'fetch';
4
+ /**
5
+ * do request for standard DataSourceType
6
+ * @param {DataSourceType} type type of DataSourceItem
7
+ * @param {any} options
8
+ */
9
+ export declare const doRequest: (type: DataSourceType, options: any) => Promise<unknown> | undefined;
10
+ export declare class DataHelper {
11
+ /**
12
+ * host object that will be "this" object when excuting dataHandler
13
+ *
14
+ * @type {*}
15
+ * @memberof DataHelper
16
+ */
17
+ host: any;
18
+ /**
19
+ * data source config
20
+ *
21
+ * @type {DataSource}
22
+ * @memberof DataHelper
23
+ */
24
+ config: DataSource;
25
+ /**
26
+ * a parser function which will be called to process config data
27
+ * which eventually will call common/utils.processData() to process data
28
+ * (originalConfig) => parsedConfig
29
+ * @type {*}
30
+ * @memberof DataHelper
31
+ */
32
+ parser: any;
33
+ /**
34
+ * config.list
35
+ *
36
+ * @type {any[]}
37
+ * @memberof DataHelper
38
+ */
39
+ ajaxList: any[];
40
+ /**
41
+ * dataHandler
42
+ *
43
+ * @type {*}
44
+ * @memberof DataHelper
45
+ */
46
+ dataHandler: any;
47
+ ajaxMap: any;
48
+ dataSourceMap: any;
49
+ appHelper: RendererAppHelper;
50
+ constructor(comp: any, config: DataSource, appHelper: RendererAppHelper, parser: any);
51
+ updateConfig(config?: {}): any;
52
+ generateDataSourceMap(): any;
53
+ updateDataSourceMap(id: string, data: any, error: any): void;
54
+ /**
55
+ * get all dataSourceItems which marked as isInit === true
56
+ * @private
57
+ * @returns
58
+ * @memberof DataHelper
59
+ */
60
+ getInitDataSourseConfigs(): any;
61
+ /**
62
+ * process all dataSourceItems which marked as isInit === true, and get dataSource request results.
63
+ * @public
64
+ * @returns
65
+ * @memberof DataHelper
66
+ */
67
+ getInitData(): Promise<any>;
68
+ reloadDataSource(): Promise<void>;
69
+ getDataSource(id: string, params: any, otherOptions: any, callback: any): Promise<any> | undefined;
70
+ asyncDataHandler(asyncDataList: any[]): Promise<unknown>;
71
+ /**
72
+ * process data using dataHandler
73
+ *
74
+ * @param {(string | null)} id request id, will be used in error message, can be null
75
+ * @param {*} dataHandler
76
+ * @param {*} data
77
+ * @param {*} error
78
+ * @returns
79
+ * @memberof DataHelper
80
+ */
81
+ handleData(id: string | null, dataHandler: any, data: any, error: any): any;
82
+ }
83
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './classnames';
2
+ export * from './common';
3
+ export * from './data-helper';
4
+ export * from './logger';
5
+ export * from './request';
@@ -0,0 +1 @@
1
+ export declare const logger: import("@easy-editor/core").Logger;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * this is a private method, export for testing purposes only.
3
+ *
4
+ * @export
5
+ * @param {*} dataAPI
6
+ * @param {*} params
7
+ * @returns
8
+ */
9
+ export declare const buildUrl: (dataAPI: any, params: any) => any;
10
+ /**
11
+ * do Get request
12
+ *
13
+ * @export
14
+ * @param {*} dataAPI
15
+ * @param {*} [params={}]
16
+ * @param {*} [headers={}]
17
+ * @param {*} [otherProps={}]
18
+ * @returns
19
+ */
20
+ export declare const get: (dataAPI: any, params?: {}, headers?: {}, otherProps?: {}) => Promise<unknown>;
21
+ /**
22
+ * do Post request
23
+ *
24
+ * @export
25
+ * @param {*} dataAPI
26
+ * @param {*} [params={}]
27
+ * @param {*} [headers={}]
28
+ * @param {*} [otherProps={}]
29
+ * @returns
30
+ */
31
+ export declare const post: (dataAPI: any, params?: {}, headers?: any, otherProps?: {}) => Promise<unknown>;
32
+ /**
33
+ * do request
34
+ *
35
+ * @export
36
+ * @param {*} dataAPI
37
+ * @param {string} [method='GET']
38
+ * @param {*} data
39
+ * @param {*} [headers={}]
40
+ * @param {*} [otherProps={}]
41
+ * @returns
42
+ */
43
+ export declare const request: (dataAPI: any, method: string | undefined, data: any, headers?: {}, otherProps?: any) => Promise<unknown>;
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@easy-editor/renderer-core",
3
+ "version": "1.0.0",
4
+ "description": "Renderer Core package for EasyEditor",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "LICENSE",
18
+ "README.md"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "homepage": "https://github.com/Easy-Editor/EasyEditor",
24
+ "license": "MIT",
25
+ "author": "JinSo <kimjinso@qq.com>",
26
+ "contributors": [
27
+ {
28
+ "name": "NoahCodeGG",
29
+ "email": "noahcodegg@gmail.com",
30
+ "url": "https://github.com/NoahCodeGG"
31
+ }
32
+ ],
33
+ "keywords": [
34
+ "@easy-editor",
35
+ "easyeditor",
36
+ "low-code",
37
+ "editor",
38
+ "engine",
39
+ "renderer"
40
+ ],
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/Easy-Editor/EasyEditor"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/Easy-Editor/EasyEditor/issues"
47
+ },
48
+ "peerDependencies": {
49
+ "@easy-editor/core": "^1.0.0"
50
+ },
51
+ "dependencies": {
52
+ "lodash-es": "^4.17.21"
53
+ },
54
+ "devDependencies": {
55
+ "@types/lodash-es": "^4.17.12"
56
+ },
57
+ "scripts": {
58
+ "dev": "deno run --watch ./src/index.ts",
59
+ "format": "biome format --write .",
60
+ "lint": "biome check .",
61
+ "build": "npm-run-all -nl build:*",
62
+ "build:clean": "rimraf dist/",
63
+ "build:js": "rollup -c",
64
+ "types": "npm-run-all -nl types:*",
65
+ "types:src": "tsc --project tsconfig.build.json",
66
+ "test-types": "tsc --project tsconfig.test.json"
67
+ },
68
+ "module": "dist/index.js",
69
+ "unpkg": "dist/index.js"
70
+ }