diff --git a/packages/designer/src/designer/setting/setting-field.ts b/packages/designer/src/designer/setting/setting-field.ts index ab5b8eadb..c8bdf52e8 100644 --- a/packages/designer/src/designer/setting/setting-field.ts +++ b/packages/designer/src/designer/setting/setting-field.ts @@ -1,8 +1,16 @@ -import { IPublicTypeTitleContent, IPublicTypeSetterType, IPublicTypeDynamicSetter, IPublicTypeFieldExtraProps, IPublicTypeFieldConfig, IPublicTypeCustomView, IPublicTypeSetValueOptions } from '@alilc/lowcode-types'; +import { + IPublicTypeTitleContent, + IPublicTypeSetterType, + IPublicTypeDynamicSetter, + IPublicTypeFieldExtraProps, + IPublicTypeFieldConfig, + IPublicTypeCustomView, + IPublicTypeSetValueOptions, +} from '@alilc/lowcode-types'; import { Transducer } from './utils'; import { SettingPropEntry } from './setting-prop-entry'; import { SettingEntry } from './setting-entry'; -import { computed, obx, makeObservable, action, untracked } from '@alilc/lowcode-editor-core'; +import { computed, obx, makeObservable, action, untracked, intl } from '@alilc/lowcode-editor-core'; import { cloneDeep, isCustomView, isDynamicSetter } from '@alilc/lowcode-utils'; function getSettingFieldCollectorKey(parent: SettingEntry, config: IPublicTypeFieldConfig) { @@ -26,44 +34,32 @@ export class SettingField extends SettingPropEntry implements SettingEntry { private _config: IPublicTypeFieldConfig; + private hotValue: any; + + parent: SettingEntry; + extraProps: IPublicTypeFieldExtraProps; // ==== dynamic properties ==== private _title?: IPublicTypeTitleContent; get title() { - // FIXME! intl - return this._title || (typeof this.name === 'number' ? `项目 ${this.name}` : this.name); + return ( + this._title || (typeof this.name === 'number' ? `${intl('Item')} ${this.name}` : this.name) + ); } private _setter?: IPublicTypeSetterType | IPublicTypeDynamicSetter; - @computed get setter(): IPublicTypeSetterType | null { - if (!this._setter) { - return null; - } - if (isDynamicSetter(this._setter)) { - return untracked(() => { - const shellThis = this.internalToShellPropEntry(); - return this._setter.call(shellThis, shellThis); - }); - } - return this._setter; - } - @obx.ref private _expanded = true; - get expanded(): boolean { - return this._expanded; - } + private _items: Array = []; - setExpanded(value: boolean) { - this._expanded = value; - } - - parent: SettingEntry; - - constructor(parent: SettingEntry, config: IPublicTypeFieldConfig, settingFieldCollector?: (name: string | number, field: SettingField) => void) { + constructor( + parent: SettingEntry, + config: IPublicTypeFieldConfig, + settingFieldCollector?: (name: string | number, field: SettingField) => void, + ) { super(parent, config.name, config.type); makeObservable(this); const { title, items, setter, extraProps, ...rest } = config; @@ -90,7 +86,26 @@ export class SettingField extends SettingPropEntry implements SettingEntry { this.transducer = new Transducer(this, { setter }); } - private _items: Array = []; + @computed get setter(): IPublicTypeSetterType | null { + if (!this._setter) { + return null; + } + if (isDynamicSetter(this._setter)) { + return untracked(() => { + const shellThis = this.internalToShellPropEntry(); + return this._setter.call(shellThis, shellThis); + }); + } + return this._setter; + } + + get expanded(): boolean { + return this._expanded; + } + + setExpanded(value: boolean) { + this._expanded = value; + } get items(): Array { return this._items; @@ -100,7 +115,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry { return this._config; } - private initItems(items: Array, settingFieldCollector?: { (name: string | number, field: SettingField): void; (name: string, field: SettingField): void }) { + private initItems( + items: Array, + settingFieldCollector?: { + (name: string | number, field: SettingField): void; + (name: string, field: SettingField): void; + }, + ) { this._items = items.map((item) => { if (isCustomView(item)) { return item; @@ -110,7 +131,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { } private disposeItems() { - this._items.forEach(item => isSettingField(item) && item.purge()); + this._items.forEach((item) => isSettingField(item) && item.purge()); this._items = []; } @@ -125,15 +146,19 @@ export class SettingField extends SettingPropEntry implements SettingEntry { // ======= compatibles for vision ====== - getConfig(configName?: K): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig { + getConfig( + configName?: K, + ): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig { if (configName) { return this.config[configName]; } return this._config; } - getItems(filter?: (item: SettingField | IPublicTypeCustomView) => boolean): Array { - return this._items.filter(item => { + getItems( + filter?: (item: SettingField | IPublicTypeCustomView) => boolean, + ): Array { + return this._items.filter((item) => { if (filter) { return filter(item); } @@ -141,10 +166,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry { }); } - private hotValue: any; - @action - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: IPublicTypeSetValueOptions) { + setValue( + val: any, + isHotValue?: boolean, + force?: boolean, + extraOptions?: IPublicTypeSetValueOptions, + ) { if (isHotValue) { this.setHotValue(val, extraOptions); return; @@ -189,11 +217,16 @@ export class SettingField extends SettingPropEntry implements SettingEntry { } if (this.isUseVariable()) { const oldValue = this.getValue(); - this.setValue({ - type: 'JSExpression', - value: oldValue.value, - mock: value, - }, false, false, options); + this.setValue( + { + type: 'JSExpression', + value: oldValue.value, + mock: value, + }, + false, + false, + options, + ); } else { this.setValue(value, false, false, options); } @@ -210,6 +243,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { return this.designer.autorun(action, true); } } + /** * @deprecated use same function from '@alilc/lowcode-utils' instead */ diff --git a/packages/designer/src/locale/en-US.json b/packages/designer/src/locale/en-US.json index 50fca66ca..28b489c8a 100644 --- a/packages/designer/src/locale/en-US.json +++ b/packages/designer/src/locale/en-US.json @@ -6,5 +6,6 @@ "unlock": "Unlock", "Condition Group": "Condition Group", "No opened document": "No opened document, open some document to editing", - "locked": "locked" + "locked": "locked", + "Item": "Item" } diff --git a/packages/designer/src/locale/zh-CN.json b/packages/designer/src/locale/zh-CN.json index 50d46dbf2..6ecf79786 100644 --- a/packages/designer/src/locale/zh-CN.json +++ b/packages/designer/src/locale/zh-CN.json @@ -6,5 +6,6 @@ "unlock": "解锁", "Condition Group": "条件组", "No opened document": "没有打开的页面,请选择页面打开编辑", - "locked": "已锁定" + "locked": "已锁定", + "Item": "项目" }