diff --git a/docs/docs/api/configOptions.md b/docs/docs/api/configOptions.md index e198517f4..a5c10cf45 100644 --- a/docs/docs/api/configOptions.md +++ b/docs/docs/api/configOptions.md @@ -115,9 +115,9 @@ config.set('enableCondition', false) ```typescript focusNodeSelector?: (rootNode: IPublicModelNode) => Node; ``` -#### supportResetFieldsGlobally - 设置所有属性支持重置 +#### supportResetGlobally - 设置所有属性支持重置 `@type {boolean}` `@default {false}` -设置所有属性支持重置, 开启后组件属性setter后会有一个重置按钮,将属性重置为初始状态。 +设置所有属性支持重置, 开启后会给组件属性增加一个resetSetter,点击后会将组件的该属性重置为默认状态(defaultValue/initialValue)。如果没有设置默认值则回到该项属性不存在于props中的状态。不能重置成snippets中定义的低代码组件属性的值 #### supportVariableGlobally - 全局变量配置 `@type {boolean}` `@default {false}` diff --git a/docs/docs/demoUsage/panels/datasource.md b/docs/docs/demoUsage/panels/datasource.md index 908c77391..9a73e1e2c 100644 --- a/docs/docs/demoUsage/panels/datasource.md +++ b/docs/docs/demoUsage/panels/datasource.md @@ -122,7 +122,7 @@ const preference = new Map(); enableCanvasLock: true, // 默认绑定变量 supportVariableGlobally: true, - supportResetFieldsGlobally: true, + supportResetGlobally: true, // simulatorUrl 在当 engine-core.js 同一个父路径下时是不需要配置的!!! // 这里因为用的是 alifd cdn,在不同 npm 包,engine-core.js 和 react-simulator-renderer.js 是不同路径 simulatorUrl: [ diff --git a/docs/docs/specs/material-spec.md b/docs/docs/specs/material-spec.md index 6e0f62a68..7d4aeeecb 100644 --- a/docs/docs/specs/material-spec.md +++ b/docs/docs/specs/material-spec.md @@ -833,7 +833,7 @@ props 数组下对象字段描述: | name | 属性名 | String | type = 'field' 生效 | | defaultValue | 默认值 | Any(视字段类型而定) | type = 'field' 生效 | | supportVariable | 是否支持配置变量 | Boolean | type = 'field' 生效 | -| supportResetFields | 是否支持配置重置属性 | Boolean | type = 'field' 生效 | +| supportReset | 是否支持配置重置属性 | Boolean | type = 'field' 生效 | | condition | 配置当前 prop 是否展示 | (target: IPublicModelSettingField) => boolean; | - | | ignoreDefaultValue | 配置当前 prop 是否忽略默认值处理逻辑,如果返回值是 true 引擎不会处理默认值 | (target: IPublicModelSettingField) => boolean; | - | | setter | 单个控件 (setter) 描述,搭建基础协议组件的描述对象,支持 JSExpression / JSFunction / JSSlot | `String\|Object\|Function` | type = 'field' 生效 | diff --git a/packages/editor-core/src/config.ts b/packages/editor-core/src/config.ts index 12e4361ca..55486ec26 100644 --- a/packages/editor-core/src/config.ts +++ b/packages/editor-core/src/config.ts @@ -116,7 +116,7 @@ const VALID_ENGINE_OPTIONS = { default: false, description: '设置所有属性支持变量配置', }, - supportResetFieldsGlobally: { + supportResetGlobally: { type: 'boolean', default: false, description: '设置所有属性支持重置', diff --git a/packages/editor-skeleton/src/components/field/fields.tsx b/packages/editor-skeleton/src/components/field/fields.tsx index 2691f88be..8be65da10 100644 --- a/packages/editor-skeleton/src/components/field/fields.tsx +++ b/packages/editor-skeleton/src/components/field/fields.tsx @@ -1,5 +1,5 @@ /* eslint-disable react/no-unused-prop-types */ -import { Component, ErrorInfo, MouseEvent } from 'react'; +import { Component, ErrorInfo, MouseEvent, ReactNode } from 'react'; import { isObject } from 'lodash'; import classNames from 'classnames'; import { Icon } from '@alifd/next'; @@ -10,7 +10,6 @@ import './index.less'; import InlineTip from './inlinetip'; import { intl } from '../../locale'; import { Logger } from '@alilc/lowcode-utils'; -import { ResetIcon } from './resetIcon'; const logger = new Logger({ level: 'warn', bizName: 'skeleton:field' }); @@ -26,7 +25,7 @@ export interface FieldProps { tip?: any; onExpandChange?: (expandState: boolean) => void; onClear?: () => void; - resetValue?: boolean; + children: ReactNode; } export class Field extends Component { @@ -144,13 +143,6 @@ export class Field extends Component { const { editor, name, title, meta } = this.props; editor?.eventBus.emit('setting.setter.field.click', { name, title, meta, event }); } - resetIconClickHandler() { - const { children } = this.props; - if (children && (children as any).props) { - const { onChange, initialValue } = (children as any).props; - onChange(initialValue); - } - } render() { const { hasError } = this.state; @@ -159,7 +151,7 @@ export class Field extends Component { } const { className, children, meta, title, valueState, - name: propName, tip, resetValue } = this.props; + name: propName, tip } = this.props; const { display, collapsed } = this.state; const isAccordion = display === 'accordion'; let hostName = ''; @@ -195,7 +187,6 @@ export class Field extends Component {
{ this.body = shell; }} className="lc-field-body"> {children}
- {display !== 'block' && resetValue && }} onClick={() => this.resetIconClickHandler()} />} </div> ); } diff --git a/packages/editor-skeleton/src/components/field/resetIcon.tsx b/packages/editor-skeleton/src/components/field/resetIcon.tsx deleted file mode 100644 index 9152528c3..000000000 --- a/packages/editor-skeleton/src/components/field/resetIcon.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { IconProps, SVGIcon } from '@alilc/lowcode-utils'; - -export function ResetIcon(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M170.666667 512a42.666667 42.666667 0 0 1-85.333334 0C85.333333 276.352 276.352 85.333333 512 85.333333a426.026667 426.026667 0 0 1 341.333333 170.624V213.333333a42.666667 42.666667 0 0 1 85.333334 0v170.666667a42.666667 42.666667 0 0 1-42.666667 42.666667h-170.666667a42.666667 42.666667 0 0 1 0-85.333334h82.346667A341.333333 341.333333 0 0 0 170.666667 512z m682.666666 0a42.666667 42.666667 0 0 1 85.333334 0c0 235.648-191.018667 426.666667-426.666667 426.666667a426.026667 426.026667 0 0 1-341.333333-170.624V810.666667a42.666667 42.666667 0 0 1-85.333334 0v-170.666667a42.666667 42.666667 0 0 1 42.666667-42.666667h170.666667a42.666667 42.666667 0 0 1 0 85.333334H216.32A341.333333 341.333333 0 0 0 853.333333 512z" /> - </SVGIcon> - ); -} \ No newline at end of file diff --git a/packages/editor-skeleton/src/components/settings/settings-pane.tsx b/packages/editor-skeleton/src/components/settings/settings-pane.tsx index ad5bf1052..e85d355d2 100644 --- a/packages/editor-skeleton/src/components/settings/settings-pane.tsx +++ b/packages/editor-skeleton/src/components/settings/settings-pane.tsx @@ -151,32 +151,32 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView } } + // 根据是否支持reset做相应的更改 + const supportReset = extraProps?.supportReset; + const supportResetGlobally = engineConfig.get('supportResetGlobally', false); + const isUseResetSetter = supportReset === false ? false : + supportReset || supportResetGlobally; + // 根据是否支持变量配置做相应的更改 const supportVariable = this.field.extraProps?.supportVariable; // supportVariableGlobally 只对标准组件生效,vc 需要单独配置 const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta); const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally); - if (isUseVariableSetter === false) { - return { - setterProps, - initialValue, - setterType, - }; - } + const shouldAddVariableSetter = isUseVariableSetter && !setterProps.setters?.includes('VariableSetter'); + const shouldAddResetSetter = isUseResetSetter && !setterProps.setters?.includes('ResetSetter'); + + if (shouldAddVariableSetter || shouldAddResetSetter) { + setterType = 'MixedSetter'; + setterProps.setters = setterProps.setters || []; + setterProps.setters.push(setter); - if (setterType === 'MixedSetter') { - // VariableSetter 不单独使用 - if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) { + if (shouldAddVariableSetter) { setterProps.setters.push('VariableSetter'); } - } else { - setterType = 'MixedSetter'; - setterProps = { - setters: [ - setter, - 'VariableSetter', - ], - }; + + if (shouldAddResetSetter) { + setterProps.setters.push('ResetSetter'); + } } return { setterProps, @@ -227,10 +227,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView let _onChange = extraProps?.onChange; let stageName = this.stageName; - const supportResetFields = extraProps?.supportResetFields; - const supportResetFieldsGlobally = engineConfig.get('supportResetFieldsGlobally', false); - const resetValue = supportResetFields === false ? false : - supportResetFields || supportResetFieldsGlobally; return createField( { meta: field?.componentMeta?.npm || field?.componentMeta?.componentName || '', @@ -244,7 +240,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView // stages, stageName, ...extraProps, - resetValue, }, !stageName && this.setters?.createSetterContent(setterType, { diff --git a/packages/types/src/shell/type/engine-options.ts b/packages/types/src/shell/type/engine-options.ts index cb8d39e6e..57060d4e2 100644 --- a/packages/types/src/shell/type/engine-options.ts +++ b/packages/types/src/shell/type/engine-options.ts @@ -121,7 +121,7 @@ export interface IPublicTypeEngineOptions { * 设置所有属性支持重置,默认值:false * */ - supportResetFieldsGlobally?: boolean; + supportResetGlobally?: boolean; /** * 设置 simulator 相关的 url,默认值:undefined diff --git a/packages/types/src/shell/type/field-extra-props.ts b/packages/types/src/shell/type/field-extra-props.ts index 9d074369c..d25ac73f0 100644 --- a/packages/types/src/shell/type/field-extra-props.ts +++ b/packages/types/src/shell/type/field-extra-props.ts @@ -66,7 +66,7 @@ export interface IPublicTypeFieldExtraProps { /** * 是否支持重置变量 */ - supportResetFields?: boolean; + supportReset?: boolean; /** * compatiable vision display