feat(editor): propsService添加fillConfig方法,支持扩展

This commit is contained in:
roymondchen 2022-08-23 20:32:48 +08:00 committed by jia000
parent 3cdcca3b0b
commit 31029bc8f1
2 changed files with 9 additions and 7 deletions

View File

@ -24,7 +24,7 @@ import type { MComponent, MNode } from '@tmagic/schema';
import { toLine } from '@tmagic/utils'; import { toLine } from '@tmagic/utils';
import type { PropsState } from '../type'; import type { PropsState } from '../type';
import { DEFAULT_CONFIG, fillConfig } from '../utils/props'; import { fillConfig } from '../utils/props';
import BaseService from './BaseService'; import BaseService from './BaseService';
@ -42,6 +42,7 @@ class Props extends BaseService {
'getPropsValue', 'getPropsValue',
'createId', 'createId',
'setNewItemId', 'setNewItemId',
'fillConfig',
'getDefaultPropsValue', 'getDefaultPropsValue',
]); ]);
} }
@ -53,13 +54,17 @@ class Props extends BaseService {
this.emit('props-configs-change'); this.emit('props-configs-change');
} }
public async fillConfig(config: FormConfig) {
return fillConfig(config);
}
/** /**
* *
* @param type * @param type
* @param config * @param config
*/ */
public setPropsConfig(type: string, config: FormConfig) { public async setPropsConfig(type: string, config: FormConfig) {
this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]); this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
} }
/** /**
@ -72,7 +77,7 @@ class Props extends BaseService {
return await this.getPropsConfig('button'); return await this.getPropsConfig('button');
} }
return cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG); return cloneDeep(this.state.propsConfigMap[type] || this.fillConfig([]));
} }
public setPropsValues(values: Record<string, MNode>) { public setPropsValues(values: Record<string, MNode>) {

View File

@ -234,6 +234,3 @@ export const fillConfig = (config: FormConfig = []) => [
], ],
}, },
]; ];
// 默认组件属性表单配置
export const DEFAULT_CONFIG: FormConfig = fillConfig([]);