mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-02-28 12:50:38 +00:00
feat: get SettingField instead of SettingPropEntry for compatibility
This commit is contained in:
parent
8961cfcb89
commit
2787a12d83
@ -37,7 +37,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
|
||||
this._expanded = value;
|
||||
}
|
||||
|
||||
constructor(readonly parent: SettingEntry, config: FieldConfig) {
|
||||
constructor(readonly parent: SettingEntry, config: FieldConfig, settingFieldCollector?: (name: string | number, field: SettingField) => void) {
|
||||
super(parent, config.name, config.type);
|
||||
|
||||
const { title, items, setter, extraProps, ...rest } = config;
|
||||
@ -52,7 +52,9 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
|
||||
|
||||
// initial items
|
||||
if (this.type === 'group' && items) {
|
||||
this.initItems(items);
|
||||
this.initItems(items, settingFieldCollector);
|
||||
} else if (settingFieldCollector && config.name) {
|
||||
settingFieldCollector(config.name, this);
|
||||
}
|
||||
|
||||
// compatiable old config
|
||||
@ -65,12 +67,12 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
|
||||
return this._items;
|
||||
}
|
||||
|
||||
private initItems(items: Array<FieldConfig | CustomView>) {
|
||||
private initItems(items: Array<FieldConfig | CustomView>, settingFieldCollector?: { (name: string | number, field: SettingField): void; (name: string, field: SettingField): void; }) {
|
||||
this._items = items.map((item) => {
|
||||
if (isCustomView(item)) {
|
||||
return item;
|
||||
}
|
||||
return new SettingField(this, item);
|
||||
return new SettingField(this, item, settingFieldCollector);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ export class SettingTopEntry implements SettingEntry {
|
||||
private _items: Array<SettingField | CustomView> = [];
|
||||
private _componentMeta: ComponentMeta | null = null;
|
||||
private _isSame: boolean = true;
|
||||
private _settingFieldMap: { [prop: string]: SettingField } = {};
|
||||
readonly path = [];
|
||||
readonly top = this;
|
||||
readonly parent = this;
|
||||
@ -95,13 +96,19 @@ export class SettingTopEntry implements SettingEntry {
|
||||
}
|
||||
|
||||
private setupItems() {
|
||||
console.log('set')
|
||||
if (this.componentMeta) {
|
||||
const settingFieldMap: { [prop: string]: SettingField } = {};
|
||||
const settingFieldCollector = (name: string | number, field: SettingField) => {
|
||||
settingFieldMap[name] = field;
|
||||
}
|
||||
this._items = this.componentMeta.configure.map((item) => {
|
||||
if (isCustomView(item)) {
|
||||
return item;
|
||||
}
|
||||
return new SettingField(this, item as any);
|
||||
return new SettingField(this, item as any, settingFieldCollector);
|
||||
});
|
||||
this._settingFieldMap = settingFieldMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,14 +131,7 @@ export class SettingTopEntry implements SettingEntry {
|
||||
* 获取子项
|
||||
*/
|
||||
get(propName: string | number): SettingPropEntry {
|
||||
const matched = this.items.find(item => {
|
||||
if (isSettingField(item)) {
|
||||
// TODO: thinkof use name or path?
|
||||
return item.name === propName;
|
||||
}
|
||||
return false;
|
||||
}) as SettingPropEntry;
|
||||
return matched || (new SettingPropEntry(this, propName));
|
||||
return this._settingFieldMap[propName] || (new SettingPropEntry(this, propName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user