Skip to content

Commit

Permalink
fix(reset): 基于ext中的ResetSetter实现
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiZng committed Dec 30, 2023
1 parent 786cc22 commit 67dca52
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 51 deletions.
4 changes: 2 additions & 2 deletions docs/docs/api/configOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/demoUsage/panels/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/specs/material-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' 生效 |
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const VALID_ENGINE_OPTIONS = {
default: false,
description: '设置所有属性支持变量配置',
},
supportResetFieldsGlobally: {
supportResetGlobally: {
type: 'boolean',
default: false,
description: '设置所有属性支持重置',
Expand Down
15 changes: 3 additions & 12 deletions packages/editor-skeleton/src/components/field/fields.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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' });

Expand All @@ -26,7 +25,7 @@ export interface FieldProps {
tip?: any;
onExpandChange?: (expandState: boolean) => void;
onClear?: () => void;
resetValue?: boolean;
children: ReactNode;
}

export class Field extends Component<FieldProps> {
Expand Down Expand Up @@ -144,13 +143,6 @@ export class Field extends Component<FieldProps> {
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;
Expand All @@ -159,7 +151,7 @@ export class Field extends Component<FieldProps> {
}

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 = '';
Expand Down Expand Up @@ -195,7 +187,6 @@ export class Field extends Component<FieldProps> {
<div key="body" ref={(shell) => { this.body = shell; }} className="lc-field-body">
{children}
</div>
{display !== 'block' && resetValue && <Title className="lc-reseticon" title={{ tip: '重置属性', icon: <ResetIcon fill="#8f9bb3" /> }} onClick={() => this.resetIconClickHandler()} />}
</div>
);
}
Expand Down
9 changes: 0 additions & 9 deletions packages/editor-skeleton/src/components/field/resetIcon.tsx

This file was deleted.

41 changes: 18 additions & 23 deletions packages/editor-skeleton/src/components/settings/settings-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 || '',
Expand All @@ -244,7 +240,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
// stages,
stageName,
...extraProps,
resetValue,
},
!stageName &&
this.setters?.createSetterContent(setterType, {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/shell/type/engine-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface IPublicTypeEngineOptions {
* 设置所有属性支持重置,默认值:false
*
*/
supportResetFieldsGlobally?: boolean;
supportResetGlobally?: boolean;

/**
* 设置 simulator 相关的 url,默认值:undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/shell/type/field-extra-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export interface IPublicTypeFieldExtraProps {
/**
* 是否支持重置变量
*/
supportResetFields?: boolean;
supportReset?: boolean;

/**
* compatiable vision display
Expand Down

0 comments on commit 67dca52

Please sign in to comment.