Skip to content

Commit 503793f

Browse files
authored
fix: supportVariable SHOULD take precedence over supportVariableGlobally (alibaba#1997)
* fix: supportVariable should take precedence over supportVariableGlobally
1 parent ecca076 commit 503793f

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

packages/editor-skeleton/src/components/settings/settings-pane.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, MouseEvent, Fragment, ReactNode } from 'react';
22
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
3-
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
3+
import { createContent, isJSSlot, isSetterConfig, shouldUseVariableSetter } from '@alilc/lowcode-utils';
44
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
55
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
66
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
@@ -155,23 +155,29 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
155155
const supportVariable = this.field.extraProps?.supportVariable;
156156
// supportVariableGlobally 只对标准组件生效,vc 需要单独配置
157157
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
158-
if (supportVariable || supportVariableGlobally) {
159-
if (setterType === 'MixedSetter') {
160-
// VariableSetter 不单独使用
161-
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
162-
setterProps.setters.push('VariableSetter');
163-
}
164-
} else {
165-
setterType = 'MixedSetter';
166-
setterProps = {
167-
setters: [
168-
setter,
169-
'VariableSetter',
170-
],
171-
};
172-
}
158+
const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally);
159+
if (isUseVariableSetter === false) {
160+
return {
161+
setterProps,
162+
initialValue,
163+
setterType,
164+
};
173165
}
174166

167+
if (setterType === 'MixedSetter') {
168+
// VariableSetter 不单独使用
169+
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
170+
setterProps.setters.push('VariableSetter');
171+
}
172+
} else {
173+
setterType = 'MixedSetter';
174+
setterProps = {
175+
setters: [
176+
setter,
177+
'VariableSetter',
178+
],
179+
};
180+
}
175181
return {
176182
setterProps,
177183
initialValue,

packages/utils/src/misc.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const stageList = [
8181
'init',
8282
'upgrade',
8383
];
84+
8485
/**
8586
* 兼容原来的数字版本的枚举对象
8687
* @param stage
@@ -108,4 +109,18 @@ export function deprecate(fail: any, message: string, alterative?: string) {
108109

109110
export function isRegExp(obj: any): obj is RegExp {
110111
return obj && obj.test && obj.exec && obj.compile;
112+
}
113+
114+
/**
115+
* The prop supportVariable SHOULD take precedence over default global supportVariable.
116+
* @param propSupportVariable prop supportVariable
117+
* @param globalSupportVariable global supportVariable
118+
* @returns
119+
*/
120+
export function shouldUseVariableSetter(
121+
propSupportVariable: boolean | undefined,
122+
globalSupportVariable: boolean,
123+
) {
124+
if (propSupportVariable === false) return false;
125+
return propSupportVariable || globalSupportVariable;
111126
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { shouldUseVariableSetter } from '../../src/misc';
2+
3+
it('shouldUseVariableSetter', () => {
4+
expect(shouldUseVariableSetter(false, true)).toBeFalsy();
5+
expect(shouldUseVariableSetter(true, true)).toBeTruthy();
6+
expect(shouldUseVariableSetter(true, false)).toBeTruthy();
7+
expect(shouldUseVariableSetter(undefined, false)).toBeFalsy();
8+
expect(shouldUseVariableSetter(undefined, true)).toBeTruthy();
9+
});

0 commit comments

Comments
 (0)