|
1 | | -import { IPublicTypeTitleContent, IPublicTypeSetterType, IPublicTypeDynamicSetter, IPublicTypeFieldExtraProps, IPublicTypeFieldConfig, IPublicTypeCustomView, IPublicTypeSetValueOptions } from '@alilc/lowcode-types'; |
| 1 | +import { |
| 2 | + IPublicTypeTitleContent, |
| 3 | + IPublicTypeSetterType, |
| 4 | + IPublicTypeDynamicSetter, |
| 5 | + IPublicTypeFieldExtraProps, |
| 6 | + IPublicTypeFieldConfig, |
| 7 | + IPublicTypeCustomView, |
| 8 | + IPublicTypeSetValueOptions, |
| 9 | +} from '@alilc/lowcode-types'; |
2 | 10 | import { Transducer } from './utils'; |
3 | 11 | import { SettingPropEntry } from './setting-prop-entry'; |
4 | 12 | import { SettingEntry } from './setting-entry'; |
5 | | -import { computed, obx, makeObservable, action, untracked } from '@alilc/lowcode-editor-core'; |
| 13 | +import { computed, obx, makeObservable, action, untracked, intl } from '@alilc/lowcode-editor-core'; |
6 | 14 | import { cloneDeep, isCustomView, isDynamicSetter } from '@alilc/lowcode-utils'; |
7 | 15 |
|
8 | 16 | function getSettingFieldCollectorKey(parent: SettingEntry, config: IPublicTypeFieldConfig) { |
@@ -26,44 +34,32 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
26 | 34 |
|
27 | 35 | private _config: IPublicTypeFieldConfig; |
28 | 36 |
|
| 37 | + private hotValue: any; |
| 38 | + |
| 39 | + parent: SettingEntry; |
| 40 | + |
29 | 41 | extraProps: IPublicTypeFieldExtraProps; |
30 | 42 |
|
31 | 43 | // ==== dynamic properties ==== |
32 | 44 | private _title?: IPublicTypeTitleContent; |
33 | 45 |
|
34 | 46 | get title() { |
35 | | - // FIXME! intl |
36 | | - return this._title || (typeof this.name === 'number' ? `项目 ${this.name}` : this.name); |
| 47 | + return ( |
| 48 | + this._title || (typeof this.name === 'number' ? `${intl('Item')} ${this.name}` : this.name) |
| 49 | + ); |
37 | 50 | } |
38 | 51 |
|
39 | 52 | private _setter?: IPublicTypeSetterType | IPublicTypeDynamicSetter; |
40 | 53 |
|
41 | | - @computed get setter(): IPublicTypeSetterType | null { |
42 | | - if (!this._setter) { |
43 | | - return null; |
44 | | - } |
45 | | - if (isDynamicSetter(this._setter)) { |
46 | | - return untracked(() => { |
47 | | - const shellThis = this.internalToShellPropEntry(); |
48 | | - return this._setter.call(shellThis, shellThis); |
49 | | - }); |
50 | | - } |
51 | | - return this._setter; |
52 | | - } |
53 | | - |
54 | 54 | @obx.ref private _expanded = true; |
55 | 55 |
|
56 | | - get expanded(): boolean { |
57 | | - return this._expanded; |
58 | | - } |
59 | | - |
60 | | - setExpanded(value: boolean) { |
61 | | - this._expanded = value; |
62 | | - } |
63 | | - |
64 | | - parent: SettingEntry; |
| 56 | + private _items: Array<SettingField | IPublicTypeCustomView> = []; |
65 | 57 |
|
66 | | - constructor(parent: SettingEntry, config: IPublicTypeFieldConfig, settingFieldCollector?: (name: string | number, field: SettingField) => void) { |
| 58 | + constructor( |
| 59 | + parent: SettingEntry, |
| 60 | + config: IPublicTypeFieldConfig, |
| 61 | + settingFieldCollector?: (name: string | number, field: SettingField) => void, |
| 62 | + ) { |
67 | 63 | super(parent, config.name, config.type); |
68 | 64 | makeObservable(this); |
69 | 65 | const { title, items, setter, extraProps, ...rest } = config; |
@@ -90,7 +86,26 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
90 | 86 | this.transducer = new Transducer(this, { setter }); |
91 | 87 | } |
92 | 88 |
|
93 | | - private _items: Array<SettingField | IPublicTypeCustomView> = []; |
| 89 | + @computed get setter(): IPublicTypeSetterType | null { |
| 90 | + if (!this._setter) { |
| 91 | + return null; |
| 92 | + } |
| 93 | + if (isDynamicSetter(this._setter)) { |
| 94 | + return untracked(() => { |
| 95 | + const shellThis = this.internalToShellPropEntry(); |
| 96 | + return this._setter.call(shellThis, shellThis); |
| 97 | + }); |
| 98 | + } |
| 99 | + return this._setter; |
| 100 | + } |
| 101 | + |
| 102 | + get expanded(): boolean { |
| 103 | + return this._expanded; |
| 104 | + } |
| 105 | + |
| 106 | + setExpanded(value: boolean) { |
| 107 | + this._expanded = value; |
| 108 | + } |
94 | 109 |
|
95 | 110 | get items(): Array<SettingField | IPublicTypeCustomView> { |
96 | 111 | return this._items; |
@@ -100,7 +115,13 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
100 | 115 | return this._config; |
101 | 116 | } |
102 | 117 |
|
103 | | - private initItems(items: Array<IPublicTypeFieldConfig | IPublicTypeCustomView>, settingFieldCollector?: { (name: string | number, field: SettingField): void; (name: string, field: SettingField): void }) { |
| 118 | + private initItems( |
| 119 | + items: Array<IPublicTypeFieldConfig | IPublicTypeCustomView>, |
| 120 | + settingFieldCollector?: { |
| 121 | + (name: string | number, field: SettingField): void; |
| 122 | + (name: string, field: SettingField): void; |
| 123 | + }, |
| 124 | + ) { |
104 | 125 | this._items = items.map((item) => { |
105 | 126 | if (isCustomView(item)) { |
106 | 127 | return item; |
@@ -110,7 +131,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
110 | 131 | } |
111 | 132 |
|
112 | 133 | private disposeItems() { |
113 | | - this._items.forEach(item => isSettingField(item) && item.purge()); |
| 134 | + this._items.forEach((item) => isSettingField(item) && item.purge()); |
114 | 135 | this._items = []; |
115 | 136 | } |
116 | 137 |
|
@@ -125,26 +146,33 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
125 | 146 |
|
126 | 147 | // ======= compatibles for vision ====== |
127 | 148 |
|
128 | | - getConfig<K extends keyof IPublicTypeFieldConfig>(configName?: K): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig { |
| 149 | + getConfig<K extends keyof IPublicTypeFieldConfig>( |
| 150 | + configName?: K, |
| 151 | + ): IPublicTypeFieldConfig[K] | IPublicTypeFieldConfig { |
129 | 152 | if (configName) { |
130 | 153 | return this.config[configName]; |
131 | 154 | } |
132 | 155 | return this._config; |
133 | 156 | } |
134 | 157 |
|
135 | | - getItems(filter?: (item: SettingField | IPublicTypeCustomView) => boolean): Array<SettingField | IPublicTypeCustomView> { |
136 | | - return this._items.filter(item => { |
| 158 | + getItems( |
| 159 | + filter?: (item: SettingField | IPublicTypeCustomView) => boolean, |
| 160 | + ): Array<SettingField | IPublicTypeCustomView> { |
| 161 | + return this._items.filter((item) => { |
137 | 162 | if (filter) { |
138 | 163 | return filter(item); |
139 | 164 | } |
140 | 165 | return true; |
141 | 166 | }); |
142 | 167 | } |
143 | 168 |
|
144 | | - private hotValue: any; |
145 | | - |
146 | 169 | @action |
147 | | - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: IPublicTypeSetValueOptions) { |
| 170 | + setValue( |
| 171 | + val: any, |
| 172 | + isHotValue?: boolean, |
| 173 | + force?: boolean, |
| 174 | + extraOptions?: IPublicTypeSetValueOptions, |
| 175 | + ) { |
148 | 176 | if (isHotValue) { |
149 | 177 | this.setHotValue(val, extraOptions); |
150 | 178 | return; |
@@ -189,11 +217,16 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
189 | 217 | } |
190 | 218 | if (this.isUseVariable()) { |
191 | 219 | const oldValue = this.getValue(); |
192 | | - this.setValue({ |
193 | | - type: 'JSExpression', |
194 | | - value: oldValue.value, |
195 | | - mock: value, |
196 | | - }, false, false, options); |
| 220 | + this.setValue( |
| 221 | + { |
| 222 | + type: 'JSExpression', |
| 223 | + value: oldValue.value, |
| 224 | + mock: value, |
| 225 | + }, |
| 226 | + false, |
| 227 | + false, |
| 228 | + options, |
| 229 | + ); |
197 | 230 | } else { |
198 | 231 | this.setValue(value, false, false, options); |
199 | 232 | } |
@@ -210,6 +243,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { |
210 | 243 | return this.designer.autorun(action, true); |
211 | 244 | } |
212 | 245 | } |
| 246 | + |
213 | 247 | /** |
214 | 248 | * @deprecated use same function from '@alilc/lowcode-utils' instead |
215 | 249 | */ |
|