@zat-design/sisyphus-react 4.4.3-beta.2 → 4.5.0-beta.1
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/README.md +1 -42
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.d.ts +1 -14
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.js +27 -102
- package/es/ProEditTable/components/RenderField/index.js +313 -366
- package/es/ProEditTable/components/RenderField/propsType.d.ts +30 -0
- package/es/ProEditTable/components/RenderField/propsType.js +1 -0
- package/es/ProEditTable/components/RenderField/tools.d.ts +22 -0
- package/es/ProEditTable/components/RenderField/tools.js +203 -0
- package/es/ProEditTable/components/Validator/index.d.ts +9 -0
- package/es/ProEditTable/components/Validator/index.js +56 -6
- package/es/ProEditTable/index.js +16 -2
- package/es/ProEditTable/utils/config.d.ts +1 -1
- package/es/ProEditTable/utils/config.js +18 -7
- package/es/ProEditTable/utils/tools.d.ts +30 -1
- package/es/ProEditTable/utils/tools.js +95 -12
- package/es/ProEditTable/utils/validateAll.d.ts +86 -0
- package/es/ProEditTable/utils/validateAll.js +319 -0
- package/es/ProForm/components/combination/Group/utils/index.d.ts +25 -25
- package/es/ProTree/components/ProTreeSelect/index.js +3 -2
- package/es/ProTree/utils.d.ts +9 -0
- package/es/ProTree/utils.js +31 -0
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ $ yarn add @zat-design/sisyphus-react
|
|
|
48
48
|
|
|
49
49
|
### 按需加载
|
|
50
50
|
|
|
51
|
-
####
|
|
51
|
+
#### 自动 Tree-Shaking
|
|
52
52
|
|
|
53
53
|
本组件库已配置 `sideEffects`,**现代打包器(Webpack 5+、Vite、Rollup)会自动进行 tree-shaking**,无需额外配置:
|
|
54
54
|
|
|
@@ -57,47 +57,6 @@ $ yarn add @zat-design/sisyphus-react
|
|
|
57
57
|
import { ProForm } from '@zat-design/sisyphus-react';
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
#### 方式二:babel-plugin-import(兼容老项目)
|
|
61
|
-
|
|
62
|
-
如果使用 Webpack 4 或需要更精确的控制,可使用 babel-plugin-import:
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
[
|
|
66
|
-
'babel-plugin-import',
|
|
67
|
-
{
|
|
68
|
-
libraryName: '@zat-design/sisyphus-react',
|
|
69
|
-
camel2DashComponentName: false,
|
|
70
|
-
libraryDirectory: 'es',
|
|
71
|
-
style: false,
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
在 umi 框架下同时配置 antd 按需加载时,需要配置别名:
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
extraBabelPlugins: [
|
|
80
|
-
[
|
|
81
|
-
'babel-plugin-import',
|
|
82
|
-
{
|
|
83
|
-
libraryName: 'antd',
|
|
84
|
-
libraryDirectory: 'es',
|
|
85
|
-
style: true,
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
'babel-plugin-import',
|
|
90
|
-
{
|
|
91
|
-
libraryName: '@zat-design/sisyphus-react',
|
|
92
|
-
camel2DashComponentName: false,
|
|
93
|
-
libraryDirectory: 'es',
|
|
94
|
-
style: false,
|
|
95
|
-
},
|
|
96
|
-
'@zat-design/sisyphus-react',
|
|
97
|
-
],
|
|
98
|
-
];
|
|
99
|
-
```
|
|
100
|
-
|
|
101
60
|
### 使用示例
|
|
102
61
|
|
|
103
62
|
```tsx
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { NamePath } from 'antd/lib/form/interface';
|
|
4
|
-
import { DiffOriginalParams } from '../../utils/diffOriginal';
|
|
5
|
-
interface Props {
|
|
6
|
-
name?: NamePath;
|
|
7
|
-
names?: NamePath[];
|
|
8
|
-
originalName?: NamePath;
|
|
9
|
-
originalNames?: NamePath[];
|
|
10
|
-
namesStr?: NamePath;
|
|
11
|
-
originalValues?: any;
|
|
12
|
-
form: FormInstance;
|
|
13
|
-
onDiff?: DiffOriginalParams['onDiff'];
|
|
14
|
-
[name: string]: any;
|
|
15
|
-
}
|
|
2
|
+
import { Props } from './propsType';
|
|
16
3
|
declare const ListChangedWrapper: React.FC<Props>;
|
|
17
4
|
export default ListChangedWrapper;
|
|
@@ -1,80 +1,12 @@
|
|
|
1
1
|
import _omit from "lodash/omit";
|
|
2
|
-
import _get from "lodash/get";
|
|
3
2
|
import React, { useMemo } from 'react';
|
|
4
3
|
import { Space, Tooltip } from 'antd';
|
|
5
4
|
import classnames from 'classnames';
|
|
6
5
|
import { diffOriginal } from "../../utils/diffOriginal";
|
|
7
6
|
import { useProConfig } from "../../../ProConfigProvider";
|
|
8
7
|
import { isEmpty } from "../../../utils";
|
|
9
|
-
|
|
10
|
-
/** 克隆子元素时需从 props 中剔除,避免透传到 div 等 DOM 导致 React 警告 */
|
|
8
|
+
import { OMIT_FROM_DOM_KEYS, toNamePath, toNamePaths, getOriginalValue } from "./tools";
|
|
11
9
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
const OMIT_FROM_DOM_KEYS = ['disabled',
|
|
13
|
-
// div 不支持 disabled,且值可能非 string/number
|
|
14
|
-
'toCSTString', 'toISOString', 'format', 'switchValue', 'precision', 'clearNotShow', 'dependNames'];
|
|
15
|
-
const toNamePath = name => {
|
|
16
|
-
if (Array.isArray(name)) {
|
|
17
|
-
return name;
|
|
18
|
-
}
|
|
19
|
-
return [name];
|
|
20
|
-
};
|
|
21
|
-
const toNamePaths = names => {
|
|
22
|
-
return names.map(name => toNamePath(name));
|
|
23
|
-
};
|
|
24
|
-
const getOriginalValue = ({
|
|
25
|
-
namePath,
|
|
26
|
-
// 表格内变动字段的name
|
|
27
|
-
originalName,
|
|
28
|
-
// 原始值中对应值的name
|
|
29
|
-
originalNames,
|
|
30
|
-
// names时 原始值中对应值的name
|
|
31
|
-
originalValues,
|
|
32
|
-
// 原始值
|
|
33
|
-
rowKeyPath,
|
|
34
|
-
// 可编辑表格场景下需要根据rowKey对比行数据
|
|
35
|
-
form
|
|
36
|
-
}) => {
|
|
37
|
-
if (!originalValues) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
let originRecord;
|
|
41
|
-
if (rowKeyPath) {
|
|
42
|
-
const rowValueNamePath = namePath.slice(0, rowKeyPath.length - 1); // 表单中变动值所在行
|
|
43
|
-
const rowKeyName = rowKeyPath[rowKeyPath.length - 1]; // rowKey在行内的name
|
|
44
|
-
|
|
45
|
-
const rowValue = form.getFieldValue(rowValueNamePath);
|
|
46
|
-
if (!rowValue) return undefined;
|
|
47
|
-
const keyValue = rowValue[rowKeyName]; // 获取表单中rowKey值
|
|
48
|
-
if (!keyValue) return undefined;
|
|
49
|
-
const originalValueList = _get(originalValues, originalName.slice(0, rowKeyPath.length - 2));
|
|
50
|
-
originRecord = originalValueList?.find(item => {
|
|
51
|
-
return item[rowKeyPath[rowKeyPath.length - 1]] === keyValue;
|
|
52
|
-
});
|
|
53
|
-
let originalValue;
|
|
54
|
-
if (originalNames?.length) {
|
|
55
|
-
const originalNamesValue = originalNames.map(originalName => {
|
|
56
|
-
return _get(originRecord, originalName.slice(rowKeyPath.length - 1));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// 有可能出现数组中全是undefined的情况 视为没有值
|
|
60
|
-
const fillUndefined = originalNamesValue.every(valItem => valItem === undefined);
|
|
61
|
-
originalValue = fillUndefined ? undefined : originalNamesValue;
|
|
62
|
-
} else {
|
|
63
|
-
originalValue = _get(originRecord, originalName.slice(rowKeyPath.length - 1));
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
originalValue,
|
|
67
|
-
originRecord,
|
|
68
|
-
record: rowValue
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 这个方法是给editTable专用的 暂时不存在不传rowKey的情况
|
|
73
|
-
return {
|
|
74
|
-
originalValue: originalNames?.length ? originalNames.map(originalName => _get(originalValues, originalName)) : _get(originalValues, originalName),
|
|
75
|
-
originRecord
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
10
|
const ListChangedWrapper = props => {
|
|
79
11
|
const {
|
|
80
12
|
name,
|
|
@@ -102,6 +34,9 @@ const ListChangedWrapper = props => {
|
|
|
102
34
|
const {
|
|
103
35
|
scrollFollowParent = true
|
|
104
36
|
} = diffConfig || {};
|
|
37
|
+
|
|
38
|
+
// children 在各使用点均经 React.isValidElement 守卫,统一以带 props 的元素类型访问,避免 @ts-ignore
|
|
39
|
+
const childEl = children;
|
|
105
40
|
const namePath = toNamePath(namesStr || name);
|
|
106
41
|
const originalNamePath = toNamePath(originalName);
|
|
107
42
|
const originalNamePaths = originalNames && toNamePaths(originalNames);
|
|
@@ -119,19 +54,19 @@ const ListChangedWrapper = props => {
|
|
|
119
54
|
const noChange = !onDiff && (!originalValues || isDiffAll ? false : isEmpty(originalValue));
|
|
120
55
|
const diffType = useMemo(() => {
|
|
121
56
|
if (!isWatch || noChange) return 'same';
|
|
122
|
-
const
|
|
57
|
+
const normalizedValue = normalize ? normalize(props[valuePropName], undefined, undefined, true) // true 代表是值比对时的调用
|
|
123
58
|
: props[valuePropName];
|
|
124
59
|
|
|
125
60
|
// fix:修复 DatePicker时,originalValue与最新值一致时,显示为 changed的问题
|
|
126
|
-
const
|
|
61
|
+
const normalizedOriginalValue = normalize && ['DatePicker'].includes(props.type) ? normalize(originalValue, undefined, undefined, true) : originalValue;
|
|
127
62
|
|
|
128
63
|
// fix:修复 InputNumber 时,originalValue与最新值一致都为'0'时,显示为 changed的问题
|
|
129
|
-
if (['InputNumber'].includes(props.type) && normalize &&
|
|
64
|
+
if (['InputNumber'].includes(props.type) && normalize && normalizedValue === Number(originalValue)) {
|
|
130
65
|
return 'same';
|
|
131
66
|
}
|
|
132
67
|
return diffOriginal({
|
|
133
|
-
value:
|
|
134
|
-
originalValue:
|
|
68
|
+
value: normalizedValue,
|
|
69
|
+
originalValue: normalizedOriginalValue,
|
|
135
70
|
form,
|
|
136
71
|
onDiff,
|
|
137
72
|
originRecord: originalDTO?.originRecord,
|
|
@@ -146,17 +81,13 @@ const ListChangedWrapper = props => {
|
|
|
146
81
|
if (!isWatch || noChange) return undefined;
|
|
147
82
|
const orgValue = getValueProps ? getValueProps(originalValue, true)?.[valuePropName] : originalValue;
|
|
148
83
|
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
index
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
_children = viewRender;
|
|
84
|
+
// viewRender 为函数时直接返回其结果;为 Element 时落到下方 children 克隆逻辑
|
|
85
|
+
if (viewRender && ! /*#__PURE__*/React.isValidElement(viewRender)) {
|
|
86
|
+
return viewRender(orgValue, originalDTO?.originRecord || {}, {
|
|
87
|
+
form,
|
|
88
|
+
name,
|
|
89
|
+
index
|
|
90
|
+
});
|
|
160
91
|
}
|
|
161
92
|
|
|
162
93
|
// 对于ProNumberRange类型,需要将字符串数组转换为数字数组
|
|
@@ -167,9 +98,8 @@ const ListChangedWrapper = props => {
|
|
|
167
98
|
return Number.isNaN(num) ? item : num;
|
|
168
99
|
});
|
|
169
100
|
}
|
|
170
|
-
return /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(
|
|
171
|
-
...
|
|
172
|
-
// @ts-ignore
|
|
101
|
+
return /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(childEl, {
|
|
102
|
+
...childEl,
|
|
173
103
|
isView: true,
|
|
174
104
|
[valuePropName]: processedValue,
|
|
175
105
|
checked: type === 'Switch' ? originalValue : undefined
|
|
@@ -177,8 +107,8 @@ const ListChangedWrapper = props => {
|
|
|
177
107
|
}, [originalValue, children]);
|
|
178
108
|
if (!isWatch || noChange) {
|
|
179
109
|
const filteredRest = _omit(rest, OMIT_FROM_DOM_KEYS);
|
|
180
|
-
return /*#__PURE__*/React.isValidElement(children) && /*#__PURE__*/React.cloneElement(
|
|
181
|
-
...
|
|
110
|
+
return /*#__PURE__*/React.isValidElement(children) && /*#__PURE__*/React.cloneElement(childEl, {
|
|
111
|
+
...childEl.props,
|
|
182
112
|
...filteredRest
|
|
183
113
|
});
|
|
184
114
|
}
|
|
@@ -188,9 +118,7 @@ const ListChangedWrapper = props => {
|
|
|
188
118
|
// 传入undefined 鼠标移入显示移出隐藏
|
|
189
119
|
return isChanged ? undefined : false;
|
|
190
120
|
};
|
|
191
|
-
|
|
192
|
-
// @ts-ignore
|
|
193
|
-
const _showEllipse = children.props?.showEllipse || children.props?.tooltip;
|
|
121
|
+
const showEllipse = childEl.props?.showEllipse || childEl.props?.tooltip;
|
|
194
122
|
const classNames = classnames({
|
|
195
123
|
'original-value-tooltip': true,
|
|
196
124
|
'original-value-tooltip-fixed': true
|
|
@@ -215,11 +143,10 @@ const ListChangedWrapper = props => {
|
|
|
215
143
|
align: "start",
|
|
216
144
|
className: "original-value-container",
|
|
217
145
|
children: ["\u521D\u59CB\u503C\uFF1A", tipContent]
|
|
218
|
-
}),
|
|
146
|
+
}), showEllipse && /*#__PURE__*/_jsxs(Space, {
|
|
219
147
|
className: "current-value-container",
|
|
220
|
-
children: ["\u5F53\u524D\u503C\uFF1A", /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(
|
|
221
|
-
|
|
222
|
-
...children.props,
|
|
148
|
+
children: ["\u5F53\u524D\u503C\uFF1A", /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(childEl, {
|
|
149
|
+
...childEl.props,
|
|
223
150
|
..._omit(rest, OMIT_FROM_DOM_KEYS),
|
|
224
151
|
isView: true
|
|
225
152
|
}) : undefined]
|
|
@@ -227,13 +154,11 @@ const ListChangedWrapper = props => {
|
|
|
227
154
|
}),
|
|
228
155
|
children: /*#__PURE__*/_jsx("div", {
|
|
229
156
|
className: diffClassName,
|
|
230
|
-
children: /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(
|
|
231
|
-
|
|
232
|
-
...children.props,
|
|
157
|
+
children: /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(childEl, {
|
|
158
|
+
...childEl.props,
|
|
233
159
|
..._omit(rest, OMIT_FROM_DOM_KEYS),
|
|
234
160
|
otherProps: {
|
|
235
|
-
|
|
236
|
-
...children.props?.otherProps,
|
|
161
|
+
...childEl.props?.otherProps,
|
|
237
162
|
isDiffChange: isChanged
|
|
238
163
|
}
|
|
239
164
|
}) : undefined
|