@zat-design/sisyphus-react 4.0.0-beta.7 → 4.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProEditTable/components/RenderField/index.js +44 -9
- package/es/ProEditTable/index.js +11 -9
- package/es/ProEditTable/propsType.d.ts +6 -0
- package/es/ProEditTable/utils/useShouldUpdateForTable.d.ts +15 -0
- package/es/ProEditTable/utils/useShouldUpdateForTable.js +132 -0
- package/es/ProForm/components/render/RenderFields.js +2 -1
- package/es/ProForm/index.js +1 -1
- package/es/ProForm/propsType.d.ts +1 -0
- package/es/ProForm/utils/useShouldUpdate.js +1 -2
- package/es/ProTabs/style/index.less +5 -1
- package/es/utils/index.js +13 -1
- package/lib/ProEditTable/components/RenderField/index.js +44 -9
- package/lib/ProEditTable/index.js +11 -9
- package/lib/ProEditTable/propsType.d.ts +6 -0
- package/lib/ProEditTable/utils/useShouldUpdateForTable.d.ts +15 -0
- package/lib/ProEditTable/utils/useShouldUpdateForTable.js +139 -0
- package/lib/ProForm/components/render/RenderFields.js +2 -1
- package/lib/ProForm/index.js +1 -1
- package/lib/ProForm/propsType.d.ts +1 -0
- package/lib/ProForm/utils/useShouldUpdate.js +1 -2
- package/lib/ProTabs/style/index.less +5 -1
- package/lib/utils/index.js +13 -1
- package/package.json +1 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface UseShouldUpdateForTableProps {
|
|
2
|
+
rowParams: any[];
|
|
3
|
+
column: any;
|
|
4
|
+
shouldUpdateDebounce: number;
|
|
5
|
+
}
|
|
6
|
+
interface Result {
|
|
7
|
+
isEditable: any;
|
|
8
|
+
required: any;
|
|
9
|
+
rules: any;
|
|
10
|
+
fieldProps: any;
|
|
11
|
+
desensitization: any;
|
|
12
|
+
valueType: any;
|
|
13
|
+
}
|
|
14
|
+
declare const useShouldUpdateForTable: (props: UseShouldUpdateForTableProps) => Result;
|
|
15
|
+
export default useShouldUpdateForTable;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _lodash = require("lodash");
|
|
11
|
+
var _utils = require("../../utils");
|
|
12
|
+
var useShouldUpdateForTable = props => {
|
|
13
|
+
var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current;
|
|
14
|
+
var rowParams = props.rowParams,
|
|
15
|
+
column = props.column,
|
|
16
|
+
shouldUpdateDebounce = props.shouldUpdateDebounce;
|
|
17
|
+
|
|
18
|
+
// refs 存储当前值
|
|
19
|
+
var isEditableRef = (0, _react.useRef)();
|
|
20
|
+
var requiredRef = (0, _react.useRef)();
|
|
21
|
+
var rulesRef = (0, _react.useRef)();
|
|
22
|
+
var fieldPropsRef = (0, _react.useRef)();
|
|
23
|
+
var desensitizationRef = (0, _react.useRef)();
|
|
24
|
+
var valueTypeRef = (0, _react.useRef)();
|
|
25
|
+
var _useState = (0, _react.useState)({}),
|
|
26
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
27
|
+
reRender = _useState2[1];
|
|
28
|
+
var debouncedUpdateRef = (0, _react.useRef)(null);
|
|
29
|
+
var pendingParamsRef = (0, _react.useRef)(null);
|
|
30
|
+
|
|
31
|
+
// 统一处理所有动态属性的更新
|
|
32
|
+
var processUpdate = params => {
|
|
33
|
+
var hasChange = false;
|
|
34
|
+
|
|
35
|
+
// isEditable 处理
|
|
36
|
+
if ((0, _lodash.isFunction)(column.isEditable)) {
|
|
37
|
+
var newIsEditable = column.isEditable(...params);
|
|
38
|
+
if (isEditableRef.current !== newIsEditable) {
|
|
39
|
+
isEditableRef.current = newIsEditable;
|
|
40
|
+
hasChange = true;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
isEditableRef.current = column.isEditable;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// required 处理
|
|
47
|
+
if ((0, _lodash.isFunction)(column.required)) {
|
|
48
|
+
var newRequired = column.required(...params);
|
|
49
|
+
if (requiredRef.current !== newRequired) {
|
|
50
|
+
requiredRef.current = newRequired;
|
|
51
|
+
hasChange = true;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
requiredRef.current = column.required;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// rules 处理
|
|
58
|
+
if ((0, _lodash.isFunction)(column.rules)) {
|
|
59
|
+
var newRules = column.rules(...params);
|
|
60
|
+
if (!(0, _lodash.isEqualWith)(rulesRef.current, newRules, _utils.customEqualForFunction)) {
|
|
61
|
+
rulesRef.current = newRules;
|
|
62
|
+
hasChange = true;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
rulesRef.current = column.rules;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// fieldProps 处理
|
|
69
|
+
if ((0, _lodash.isFunction)(column.fieldProps)) {
|
|
70
|
+
var newFieldProps = column.fieldProps(...params);
|
|
71
|
+
if (!(0, _lodash.isEqualWith)(fieldPropsRef.current, newFieldProps, _utils.customEqualForFunction)) {
|
|
72
|
+
fieldPropsRef.current = newFieldProps;
|
|
73
|
+
hasChange = true;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
fieldPropsRef.current = column.fieldProps;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// desensitization 处理
|
|
80
|
+
if ((0, _lodash.isFunction)(column.desensitization)) {
|
|
81
|
+
var newDesensitization = column.desensitization(...params);
|
|
82
|
+
if (!(0, _lodash.isEqualWith)(desensitizationRef.current, newDesensitization)) {
|
|
83
|
+
desensitizationRef.current = newDesensitization;
|
|
84
|
+
hasChange = true;
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
desensitizationRef.current = column.desensitization;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// valueType 处理
|
|
91
|
+
if ((0, _lodash.isFunction)(column.valueType)) {
|
|
92
|
+
var newValueType = column.valueType(...params);
|
|
93
|
+
if (valueTypeRef.current !== newValueType) {
|
|
94
|
+
valueTypeRef.current = newValueType;
|
|
95
|
+
hasChange = true;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
valueTypeRef.current = column.valueType;
|
|
99
|
+
}
|
|
100
|
+
if (hasChange) {
|
|
101
|
+
reRender({});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// 创建防抖函数(统一处理所有动态属性)
|
|
106
|
+
(0, _react.useEffect)(() => {
|
|
107
|
+
if (shouldUpdateDebounce > 0 && ((0, _lodash.isFunction)(column.isEditable) || (0, _lodash.isFunction)(column.required) || (0, _lodash.isFunction)(column.rules) || (0, _lodash.isFunction)(column.fieldProps) || (0, _lodash.isFunction)(column.desensitization) || (0, _lodash.isFunction)(column.valueType))) {
|
|
108
|
+
debouncedUpdateRef.current = (0, _lodash.debounce)(() => {
|
|
109
|
+
if (pendingParamsRef.current) {
|
|
110
|
+
processUpdate(pendingParamsRef.current);
|
|
111
|
+
pendingParamsRef.current = null;
|
|
112
|
+
}
|
|
113
|
+
}, shouldUpdateDebounce);
|
|
114
|
+
}
|
|
115
|
+
return () => {
|
|
116
|
+
var _debouncedUpdateRef$c;
|
|
117
|
+
(_debouncedUpdateRef$c = debouncedUpdateRef.current) === null || _debouncedUpdateRef$c === void 0 || _debouncedUpdateRef$c.cancel();
|
|
118
|
+
};
|
|
119
|
+
}, [shouldUpdateDebounce, column]);
|
|
120
|
+
|
|
121
|
+
// 统一的属性处理逻辑
|
|
122
|
+
if (shouldUpdateDebounce > 0 && debouncedUpdateRef.current) {
|
|
123
|
+
// 使用防抖延迟更新
|
|
124
|
+
pendingParamsRef.current = rowParams;
|
|
125
|
+
debouncedUpdateRef.current();
|
|
126
|
+
} else {
|
|
127
|
+
// 立即更新(shouldUpdateDebounce = 0 或无防抖函数)
|
|
128
|
+
processUpdate(rowParams);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
isEditable: (_isEditableRef$curren = isEditableRef.current) !== null && _isEditableRef$curren !== void 0 ? _isEditableRef$curren : column.isEditable,
|
|
132
|
+
required: (_requiredRef$current = requiredRef.current) !== null && _requiredRef$current !== void 0 ? _requiredRef$current : column.required,
|
|
133
|
+
rules: (_rulesRef$current = rulesRef.current) !== null && _rulesRef$current !== void 0 ? _rulesRef$current : column.rules,
|
|
134
|
+
fieldProps: (_fieldPropsRef$curren = fieldPropsRef.current) !== null && _fieldPropsRef$curren !== void 0 ? _fieldPropsRef$curren : column.fieldProps,
|
|
135
|
+
desensitization: (_desensitizationRef$c = desensitizationRef.current) !== null && _desensitizationRef$c !== void 0 ? _desensitizationRef$c : column.desensitization,
|
|
136
|
+
valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
var _default = exports.default = useShouldUpdateForTable;
|
|
@@ -216,7 +216,8 @@ var RenderFields = props => {
|
|
|
216
216
|
listName: column.listName,
|
|
217
217
|
globalControl,
|
|
218
218
|
formDisabled,
|
|
219
|
-
diffConfig
|
|
219
|
+
diffConfig,
|
|
220
|
+
shouldUpdateDebounce
|
|
220
221
|
};
|
|
221
222
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_useFieldProps.FieldProvider, {
|
|
222
223
|
value: otherProps,
|
package/lib/ProForm/index.js
CHANGED
|
@@ -73,7 +73,7 @@ var ProForm = (props, ref) => {
|
|
|
73
73
|
_props$stopOnFirstErr = props.stopOnFirstError,
|
|
74
74
|
stopOnFirstError = _props$stopOnFirstErr === void 0 ? false : _props$stopOnFirstErr,
|
|
75
75
|
_props$shouldUpdateDe = props.shouldUpdateDebounce,
|
|
76
|
-
shouldUpdateDebounce = _props$shouldUpdateDe === void 0 ?
|
|
76
|
+
shouldUpdateDebounce = _props$shouldUpdateDe === void 0 ? 200 : _props$shouldUpdateDe,
|
|
77
77
|
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
78
78
|
var config = (0, _ProConfigProvider.useProConfig)('ProForm');
|
|
79
79
|
// source: 用于区分是哪个组件调用,用于错误提示
|
|
@@ -31,8 +31,7 @@ var useShouldUpdate = props => {
|
|
|
31
31
|
originComponent = props.originComponent,
|
|
32
32
|
type = props.type,
|
|
33
33
|
desensitization = props.desensitization,
|
|
34
|
-
|
|
35
|
-
shouldUpdateDebounce = _props$shouldUpdateDe === void 0 ? 500 : _props$shouldUpdateDe;
|
|
34
|
+
shouldUpdateDebounce = props.shouldUpdateDebounce;
|
|
36
35
|
var _shouldUpdate = formItemProps.shouldUpdate,
|
|
37
36
|
name = formItemProps.name,
|
|
38
37
|
clearNotShow = formItemProps.clearNotShow,
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
.pro-tabs-card-left {
|
|
7
7
|
width: 84px !important;
|
|
8
8
|
}
|
|
9
|
+
.pro-tabs-card-right {
|
|
10
|
+
width: 24px !important;
|
|
11
|
+
}
|
|
9
12
|
.pro-tabs-card-right img {
|
|
10
13
|
width: 24px !important;
|
|
11
14
|
}
|
|
@@ -94,7 +97,7 @@
|
|
|
94
97
|
|
|
95
98
|
.pro-tabs-card-right {
|
|
96
99
|
display: flex;
|
|
97
|
-
|
|
100
|
+
width: 48px;
|
|
98
101
|
img {
|
|
99
102
|
width: 48px;
|
|
100
103
|
}
|
|
@@ -123,6 +126,7 @@
|
|
|
123
126
|
width: 200px;
|
|
124
127
|
padding: calc(9px * var(--zaui-size; 1)) 16px calc(9px * var(--zaui-size; 1)) 24px;
|
|
125
128
|
border: 1px solid var(--zaui-line, #dddddd);
|
|
129
|
+
border-radius: var(--zaui-border-radius, 8px);
|
|
126
130
|
|
|
127
131
|
.pro-tabs-card-left {
|
|
128
132
|
width: 104px;
|
package/lib/utils/index.js
CHANGED
|
@@ -13,10 +13,22 @@ var _lodash = require("lodash");
|
|
|
13
13
|
var EMPTY_VALUE = [undefined, null, ''];
|
|
14
14
|
|
|
15
15
|
// 自定义深比对 如果两边都是函数类型则认为相等
|
|
16
|
+
// 对于 React 元素,不直接认为相等,而是让 lodash 继续进行深度比较
|
|
16
17
|
var customEqualForFunction = (value, other) => {
|
|
17
|
-
|
|
18
|
+
// 只有当两边都是函数时才认为相等
|
|
19
|
+
if ((0, _lodash.isFunction)(value) && (0, _lodash.isFunction)(other)) {
|
|
18
20
|
return true;
|
|
19
21
|
}
|
|
22
|
+
// 对于 React 元素,返回 undefined 让 isEqualWith 继续使用默认比较逻辑
|
|
23
|
+
// 这样会比较 React 元素的 type、props 等属性
|
|
24
|
+
if ( /*#__PURE__*/_react.default.isValidElement(value) && /*#__PURE__*/_react.default.isValidElement(other)) {
|
|
25
|
+
// 比较 React 元素的类型和关键 props
|
|
26
|
+
if (value.type !== other.type) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
// 对于相同类型的 React 元素,返回 undefined 让 isEqualWith 继续深度比较 props
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
20
32
|
};
|
|
21
33
|
|
|
22
34
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zat-design/sisyphus-react",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -135,7 +135,6 @@
|
|
|
135
135
|
"lint-staged": "^10.0.0",
|
|
136
136
|
"mini-css-extract-plugin": "^2.9.4",
|
|
137
137
|
"mockjs": "^1.0.0",
|
|
138
|
-
"moment": "^2.30.1",
|
|
139
138
|
"prettier": "^2.5.0",
|
|
140
139
|
"pretty-quick": "^3.1.3",
|
|
141
140
|
"react": "^18.2.0",
|