feat: fix prop module issue and ts type definition

This commit is contained in:
liujuping 2023-02-21 17:41:03 +08:00 committed by 林熠
parent 7c2ebf3c02
commit 7c16bb1f9c
4 changed files with 22 additions and 7 deletions

View File

@ -58,7 +58,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
constructor( constructor(
parent: SettingEntry, parent: SettingEntry,
config: IPublicTypeFieldConfig, config: IPublicTypeFieldConfig,
settingFieldCollector?: (name: string | number, field: SettingField) => void, private settingFieldCollector?: (name: string | number, field: SettingField) => void,
) { ) {
super(parent, config.name, config.type); super(parent, config.name, config.type);
makeObservable(this); makeObservable(this);
@ -137,7 +137,8 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
// 创建子配置项,通常用于 object/array 类型数据 // 创建子配置项,通常用于 object/array 类型数据
createField(config: IPublicTypeFieldConfig): SettingField { createField(config: IPublicTypeFieldConfig): SettingField {
return new SettingField(this, config); this.settingFieldCollector?.(getSettingFieldCollectorKey(this.parent, config), this);
return new SettingField(this, config, this.settingFieldCollector);
} }
purge() { purge() {

View File

@ -1,11 +1,12 @@
import { obx, computed, makeObservable, runInAction, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import { obx, computed, makeObservable, runInAction, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { GlobalEvent, IPublicModelEditor, IPublicTypeSetValueOptions } from '@alilc/lowcode-types'; import { GlobalEvent, IPublicModelEditor, IPublicTypeSetValueOptions } from '@alilc/lowcode-types';
import { uniqueId, isJSExpression, isSettingField } from '@alilc/lowcode-utils'; import { uniqueId, isJSExpression, isSettingField } from '@alilc/lowcode-utils';
import { Setters } from '@alilc/lowcode-shell';
import { SettingEntry } from './setting-entry'; import { SettingEntry } from './setting-entry';
import { INode } from '../../document'; import { INode } from '../../document';
import { IComponentMeta } from '../../component-meta'; import { IComponentMeta } from '../../component-meta';
import { Designer } from '../designer'; import { Designer } from '../designer';
import { Setters } from '@alilc/lowcode-shell'; import { SettingField } from './setting-field';
export class SettingPropEntry implements SettingEntry { export class SettingPropEntry implements SettingEntry {
// === static properties === // === static properties ===
@ -52,7 +53,7 @@ export class SettingPropEntry implements SettingEntry {
extraProps: any = {}; extraProps: any = {};
constructor(readonly parent: SettingEntry, name: string | number, type?: 'field' | 'group') { constructor(readonly parent: SettingEntry | SettingField, name: string | number, type?: 'field' | 'group') {
makeObservable(this); makeObservable(this);
if (type == null) { if (type == null) {
const c = typeof name === 'string' ? name.slice(0, 1) : ''; const c = typeof name === 'string' ? name.slice(0, 1) : '';

View File

@ -303,7 +303,7 @@ export class Prop implements IProp, IPropParent {
return this._value; return this._value;
} }
const values = this.items!.map((prop) => { const values = this.items!.map((prop) => {
return prop.export(stage); return prop?.export(stage);
}); });
if (values.every((val) => val === undefined)) { if (values.every((val) => val === undefined)) {
return undefined; return undefined;

View File

@ -1,59 +1,72 @@
import { IPublicModelSettingTarget } from '../model'; import { IPublicModelSettingPropEntry, IPublicModelSettingTarget } from '../model';
import { IPublicTypeLiveTextEditingConfig } from './'; import { IPublicTypeLiveTextEditingConfig } from './';
/** /**
* extra props for field * extra props for field
*/ */
export interface IPublicTypeFieldExtraProps { export interface IPublicTypeFieldExtraProps {
/** /**
* *
*/ */
isRequired?: boolean; isRequired?: boolean;
/** /**
* default value of target prop for setter use * default value of target prop for setter use
*/ */
defaultValue?: any; defaultValue?: any;
/** /**
* get value for field * get value for field
*/ */
getValue?: (target: IPublicModelSettingTarget, fieldValue: any) => any; getValue?: (target: IPublicModelSettingTarget, fieldValue: any) => any;
/** /**
* set value for field * set value for field
*/ */
setValue?: (target: IPublicModelSettingTarget, value: any) => void; setValue?: (target: IPublicModelSettingTarget, value: any) => void;
/** /**
* the field conditional show, is not set always true * the field conditional show, is not set always true
* @default undefined * @default undefined
*/ */
condition?: (target: IPublicModelSettingTarget) => boolean; condition?: (target: IPublicModelSettingPropEntry) => boolean;
/** /**
* autorun when something change * autorun when something change
*/ */
autorun?: (target: IPublicModelSettingTarget) => void; autorun?: (target: IPublicModelSettingTarget) => void;
/** /**
* is this field is a virtual field that not save to schema * is this field is a virtual field that not save to schema
*/ */
virtual?: (target: IPublicModelSettingTarget) => boolean; virtual?: (target: IPublicModelSettingTarget) => boolean;
/** /**
* default collapsed when display accordion * default collapsed when display accordion
*/ */
defaultCollapsed?: boolean; defaultCollapsed?: boolean;
/** /**
* important field * important field
*/ */
important?: boolean; important?: boolean;
/** /**
* internal use * internal use
*/ */
forceInline?: number; forceInline?: number;
/** /**
* *
*/ */
supportVariable?: boolean; supportVariable?: boolean;
/** /**
* compatiable vision display * compatiable vision display
*/ */
display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'; display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry';
// @todo 这个 omit 是否合理? // @todo 这个 omit 是否合理?
/** /**
* @todo * @todo