mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
fix: supportVariable SHOULD take precedence over supportVariableGlobally (#1997)
* fix: supportVariable should take precedence over supportVariableGlobally
This commit is contained in:
parent
ecca076d50
commit
503793fdfc
@ -1,6 +1,6 @@
|
||||
import { Component, MouseEvent, Fragment, ReactNode } from 'react';
|
||||
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
|
||||
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
|
||||
import { createContent, isJSSlot, isSetterConfig, shouldUseVariableSetter } from '@alilc/lowcode-utils';
|
||||
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
|
||||
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
|
||||
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
|
||||
@ -155,23 +155,29 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
||||
const supportVariable = this.field.extraProps?.supportVariable;
|
||||
// supportVariableGlobally 只对标准组件生效,vc 需要单独配置
|
||||
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
|
||||
if (supportVariable || supportVariableGlobally) {
|
||||
if (setterType === 'MixedSetter') {
|
||||
// VariableSetter 不单独使用
|
||||
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
|
||||
setterProps.setters.push('VariableSetter');
|
||||
}
|
||||
} else {
|
||||
setterType = 'MixedSetter';
|
||||
setterProps = {
|
||||
setters: [
|
||||
setter,
|
||||
'VariableSetter',
|
||||
],
|
||||
};
|
||||
}
|
||||
const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally);
|
||||
if (isUseVariableSetter === false) {
|
||||
return {
|
||||
setterProps,
|
||||
initialValue,
|
||||
setterType,
|
||||
};
|
||||
}
|
||||
|
||||
if (setterType === 'MixedSetter') {
|
||||
// VariableSetter 不单独使用
|
||||
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
|
||||
setterProps.setters.push('VariableSetter');
|
||||
}
|
||||
} else {
|
||||
setterType = 'MixedSetter';
|
||||
setterProps = {
|
||||
setters: [
|
||||
setter,
|
||||
'VariableSetter',
|
||||
],
|
||||
};
|
||||
}
|
||||
return {
|
||||
setterProps,
|
||||
initialValue,
|
||||
|
||||
@ -81,6 +81,7 @@ const stageList = [
|
||||
'init',
|
||||
'upgrade',
|
||||
];
|
||||
|
||||
/**
|
||||
* 兼容原来的数字版本的枚举对象
|
||||
* @param stage
|
||||
@ -108,4 +109,18 @@ export function deprecate(fail: any, message: string, alterative?: string) {
|
||||
|
||||
export function isRegExp(obj: any): obj is RegExp {
|
||||
return obj && obj.test && obj.exec && obj.compile;
|
||||
}
|
||||
|
||||
/**
|
||||
* The prop supportVariable SHOULD take precedence over default global supportVariable.
|
||||
* @param propSupportVariable prop supportVariable
|
||||
* @param globalSupportVariable global supportVariable
|
||||
* @returns
|
||||
*/
|
||||
export function shouldUseVariableSetter(
|
||||
propSupportVariable: boolean | undefined,
|
||||
globalSupportVariable: boolean,
|
||||
) {
|
||||
if (propSupportVariable === false) return false;
|
||||
return propSupportVariable || globalSupportVariable;
|
||||
}
|
||||
9
packages/utils/test/src/misc.test.ts
Normal file
9
packages/utils/test/src/misc.test.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { shouldUseVariableSetter } from '../../src/misc';
|
||||
|
||||
it('shouldUseVariableSetter', () => {
|
||||
expect(shouldUseVariableSetter(false, true)).toBeFalsy();
|
||||
expect(shouldUseVariableSetter(true, true)).toBeTruthy();
|
||||
expect(shouldUseVariableSetter(true, false)).toBeTruthy();
|
||||
expect(shouldUseVariableSetter(undefined, false)).toBeFalsy();
|
||||
expect(shouldUseVariableSetter(undefined, true)).toBeTruthy();
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user