fix(designer): fix i18n

This commit is contained in:
haoziqaq 2023-02-06 18:13:17 +08:00 committed by 林熠
parent 69ab81a147
commit 59cb9ef30a
3 changed files with 79 additions and 43 deletions

View File

@ -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<SettingField | IPublicTypeCustomView> = [];
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<SettingField | IPublicTypeCustomView> = [];
@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<SettingField | IPublicTypeCustomView> {
return this._items;
@ -100,7 +115,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
return this._config;
}
private initItems(items: Array<IPublicTypeFieldConfig | IPublicTypeCustomView>, settingFieldCollector?: { (name: string | number, field: SettingField): void; (name: string, field: SettingField): void }) {
private initItems(
items: Array<IPublicTypeFieldConfig | IPublicTypeCustomView>,
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<K extends keyof IPublicTypeFieldConfig>(configName?: K): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig {
getConfig<K extends keyof IPublicTypeFieldConfig>(
configName?: K,
): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig {
if (configName) {
return this.config[configName];
}
return this._config;
}
getItems(filter?: (item: SettingField | IPublicTypeCustomView) => boolean): Array<SettingField | IPublicTypeCustomView> {
return this._items.filter(item => {
getItems(
filter?: (item: SettingField | IPublicTypeCustomView) => boolean,
): Array<SettingField | IPublicTypeCustomView> {
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
*/

View File

@ -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"
}

View File

@ -6,5 +6,6 @@
"unlock": "解锁",
"Condition Group": "条件组",
"No opened document": "没有打开的页面,请选择页面打开编辑",
"locked": "已锁定"
"locked": "已锁定",
"Item": "项目"
}