mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-13 20:36:34 +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 { Component, MouseEvent, Fragment, ReactNode } from 'react';
|
||||||
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
|
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 { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
|
||||||
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
|
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
|
||||||
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
|
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
|
||||||
@ -155,7 +155,15 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
const supportVariable = this.field.extraProps?.supportVariable;
|
const supportVariable = this.field.extraProps?.supportVariable;
|
||||||
// supportVariableGlobally 只对标准组件生效,vc 需要单独配置
|
// supportVariableGlobally 只对标准组件生效,vc 需要单独配置
|
||||||
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
|
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
|
||||||
if (supportVariable || supportVariableGlobally) {
|
const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally);
|
||||||
|
if (isUseVariableSetter === false) {
|
||||||
|
return {
|
||||||
|
setterProps,
|
||||||
|
initialValue,
|
||||||
|
setterType,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (setterType === 'MixedSetter') {
|
if (setterType === 'MixedSetter') {
|
||||||
// VariableSetter 不单独使用
|
// VariableSetter 不单独使用
|
||||||
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
|
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
|
||||||
@ -170,8 +178,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setterProps,
|
setterProps,
|
||||||
initialValue,
|
initialValue,
|
||||||
|
|||||||
@ -81,6 +81,7 @@ const stageList = [
|
|||||||
'init',
|
'init',
|
||||||
'upgrade',
|
'upgrade',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 兼容原来的数字版本的枚举对象
|
* 兼容原来的数字版本的枚举对象
|
||||||
* @param stage
|
* @param stage
|
||||||
@ -109,3 +110,17 @@ export function deprecate(fail: any, message: string, alterative?: string) {
|
|||||||
export function isRegExp(obj: any): obj is RegExp {
|
export function isRegExp(obj: any): obj is RegExp {
|
||||||
return obj && obj.test && obj.exec && obj.compile;
|
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