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 { Transducer } from './utils';
import { SettingPropEntry } from './setting-prop-entry'; import { SettingPropEntry } from './setting-prop-entry';
import { SettingEntry } from './setting-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'; import { cloneDeep, isCustomView, isDynamicSetter } from '@alilc/lowcode-utils';
function getSettingFieldCollectorKey(parent: SettingEntry, config: IPublicTypeFieldConfig) { function getSettingFieldCollectorKey(parent: SettingEntry, config: IPublicTypeFieldConfig) {
@ -26,44 +34,32 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
private _config: IPublicTypeFieldConfig; private _config: IPublicTypeFieldConfig;
private hotValue: any;
parent: SettingEntry;
extraProps: IPublicTypeFieldExtraProps; extraProps: IPublicTypeFieldExtraProps;
// ==== dynamic properties ==== // ==== dynamic properties ====
private _title?: IPublicTypeTitleContent; private _title?: IPublicTypeTitleContent;
get title() { get title() {
// FIXME! intl return (
return this._title || (typeof this.name === 'number' ? `项目 ${this.name}` : this.name); this._title || (typeof this.name === 'number' ? `${intl('Item')} ${this.name}` : this.name)
);
} }
private _setter?: IPublicTypeSetterType | IPublicTypeDynamicSetter; 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; @obx.ref private _expanded = true;
get expanded(): boolean { private _items: Array<SettingField | IPublicTypeCustomView> = [];
return this._expanded;
}
setExpanded(value: boolean) { constructor(
this._expanded = value; parent: SettingEntry,
} config: IPublicTypeFieldConfig,
settingFieldCollector?: (name: string | number, field: SettingField) => void,
parent: SettingEntry; ) {
constructor(parent: SettingEntry, config: IPublicTypeFieldConfig, settingFieldCollector?: (name: string | number, field: SettingField) => void) {
super(parent, config.name, config.type); super(parent, config.name, config.type);
makeObservable(this); makeObservable(this);
const { title, items, setter, extraProps, ...rest } = config; const { title, items, setter, extraProps, ...rest } = config;
@ -90,7 +86,26 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
this.transducer = new Transducer(this, { setter }); 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> { get items(): Array<SettingField | IPublicTypeCustomView> {
return this._items; return this._items;
@ -100,7 +115,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
return this._config; 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) => { this._items = items.map((item) => {
if (isCustomView(item)) { if (isCustomView(item)) {
return item; return item;
@ -110,7 +131,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
} }
private disposeItems() { private disposeItems() {
this._items.forEach(item => isSettingField(item) && item.purge()); this._items.forEach((item) => isSettingField(item) && item.purge());
this._items = []; this._items = [];
} }
@ -125,15 +146,19 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
// ======= compatibles for vision ====== // ======= 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) { if (configName) {
return this.config[configName]; return this.config[configName];
} }
return this._config; return this._config;
} }
getItems(filter?: (item: SettingField | IPublicTypeCustomView) => boolean): Array<SettingField | IPublicTypeCustomView> { getItems(
return this._items.filter(item => { filter?: (item: SettingField | IPublicTypeCustomView) => boolean,
): Array<SettingField | IPublicTypeCustomView> {
return this._items.filter((item) => {
if (filter) { if (filter) {
return filter(item); return filter(item);
} }
@ -141,10 +166,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
}); });
} }
private hotValue: any;
@action @action
setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: IPublicTypeSetValueOptions) { setValue(
val: any,
isHotValue?: boolean,
force?: boolean,
extraOptions?: IPublicTypeSetValueOptions,
) {
if (isHotValue) { if (isHotValue) {
this.setHotValue(val, extraOptions); this.setHotValue(val, extraOptions);
return; return;
@ -189,11 +217,16 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
} }
if (this.isUseVariable()) { if (this.isUseVariable()) {
const oldValue = this.getValue(); const oldValue = this.getValue();
this.setValue({ this.setValue(
type: 'JSExpression', {
value: oldValue.value, type: 'JSExpression',
mock: value, value: oldValue.value,
}, false, false, options); mock: value,
},
false,
false,
options,
);
} else { } else {
this.setValue(value, false, false, options); this.setValue(value, false, false, options);
} }
@ -210,6 +243,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
return this.designer.autorun(action, true); return this.designer.autorun(action, true);
} }
} }
/** /**
* @deprecated use same function from '@alilc/lowcode-utils' instead * @deprecated use same function from '@alilc/lowcode-utils' instead
*/ */

View File

@ -6,5 +6,6 @@
"unlock": "Unlock", "unlock": "Unlock",
"Condition Group": "Condition Group", "Condition Group": "Condition Group",
"No opened document": "No opened document, open some document to editing", "No opened document": "No opened document, open some document to editing",
"locked": "locked" "locked": "locked",
"Item": "Item"
} }

View File

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