fix: add createcomponents and add doc

This commit is contained in:
hufeixiong
2022-08-12 18:10:52 +08:00
parent 929b3a39f5
commit 90a84f033e
8 changed files with 204 additions and 30 deletions

View File

@@ -21,3 +21,30 @@ export class ComponentItemFactory implements ComponentItem {
public remoteConfig: ComponentItem['remoteConfig'] = {}
) {}
}
export interface IPluginConfig {
name: ComponentItemFactory['name'];
display: ComponentItemFactory['display'];
props: ComponentItemFactory['props'];
initData: ComponentItemFactory['initData'];
render: ComponentItem['render'];
resize?: ComponentItem['resize'];
needPosition?: ComponentItem['needPosition'];
init?: ComponentItem['init'];
destroy?: ComponentItem['destroy'];
remoteConfig?: ComponentItem['remoteConfig'];
}
export function createComponent(config: IPluginConfig) {
return new ComponentItemFactory(
config.name,
config.display,
config.props,
config.initData,
config.render,
config.resize,
config.needPosition,
config.init,
config.destroy,
config.remoteConfig
);
}

View File

@@ -7,20 +7,6 @@ import { specialCoList } from './special';
import deepCopys from 'deepcopy';
import { FunctionDataMap } from '../functionCenter/config';
import UserConfig from '../../config';
import { IPluginConfig } from './types';
import { ComponentItemFactory } from '../components/abstract';
// 创建插件
export const createPlugin = (config: IPluginConfig) => {
return new ComponentItemFactory(
config.key,
config.name,
{},
config.attr,
config.render,
config.attr.resize
);
};
export function deepCopy<T = any>(obj: T): T {
return deepCopys(obj);

View File

@@ -1,7 +0,0 @@
export interface IPluginConfig {
key: string;
name: string;
attr: any;
render: (props: any) => JSX.Element;
resize?: boolean;
}

View File

@@ -40,7 +40,7 @@ export { scaleFn } from './core/scale/index';
// 以下导出用于制作插件
// 用于制作组件的函数
export { ComponentItemFactory } from './core/components/abstract';
export { ComponentItemFactory, createComponent } from './core/components/abstract';
// 用于菜单拖拽的函数
export { dragEventResolve } from './core/crossDrag/index';
// 用于制作组件配置项的函数