@zat-design/sisyphus-react 4.4.2 → 4.4.3

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.
Files changed (55) hide show
  1. package/README.md +1 -42
  2. package/dist/index.esm.css +1 -1
  3. package/dist/less.esm.css +1 -1
  4. package/es/FormsProvider/index.d.ts +1 -1
  5. package/es/ProEditTable/components/RenderField/ListChangedWrapper.d.ts +1 -14
  6. package/es/ProEditTable/components/RenderField/ListChangedWrapper.js +27 -102
  7. package/es/ProEditTable/components/RenderField/index.js +269 -364
  8. package/es/ProEditTable/components/RenderField/propsType.d.ts +30 -0
  9. package/es/ProEditTable/components/RenderField/propsType.js +1 -0
  10. package/es/ProEditTable/components/RenderField/tools.d.ts +22 -0
  11. package/es/ProEditTable/components/RenderField/tools.js +203 -0
  12. package/es/ProEditTable/utils/config.js +5 -2
  13. package/es/ProEditTable/utils/index.js +11 -6
  14. package/es/ProEditTable/utils/tools.js +3 -2
  15. package/es/ProEnum/index.js +1 -1
  16. package/es/ProForm/components/FormFooter/propsType.d.ts +1 -1
  17. package/es/ProForm/components/base/DatePicker/index.js +3 -2
  18. package/es/ProForm/components/combination/Group/component/ComRender.js +1 -1
  19. package/es/ProForm/components/combination/Group/component/FlexibleGroup.js +4 -11
  20. package/es/ProForm/components/combination/Group/hooks/index.js +1 -2
  21. package/es/ProForm/components/combination/Group/utils/index.d.ts +16 -16
  22. package/es/ProForm/components/render/Render.js +149 -180
  23. package/es/ProForm/components/render/RenderFields.js +13 -38
  24. package/es/ProForm/components/render/propsType.d.ts +1 -18
  25. package/es/ProForm/components/render/propsType.js +0 -26
  26. package/es/ProForm/hooks/useControlled.d.ts +1 -0
  27. package/es/ProForm/hooks/useControlled.js +14 -0
  28. package/es/ProForm/hooks/useForm.d.ts +8 -0
  29. package/es/ProForm/{utils → hooks}/useForm.js +1 -1
  30. package/es/ProForm/{utils → hooks}/useRules.js +2 -2
  31. package/es/ProForm/{utils → hooks}/useShouldUpdate.d.ts +5 -1
  32. package/es/ProForm/{utils → hooks}/useShouldUpdate.js +30 -77
  33. package/es/ProForm/{utils → hooks}/useWatch.js +1 -1
  34. package/es/ProForm/index.js +5 -4
  35. package/es/ProForm/propsType.d.ts +13 -1
  36. package/es/ProForm/utils/buildFormItemProps.d.ts +25 -0
  37. package/es/ProForm/utils/buildFormItemProps.js +90 -0
  38. package/es/ProForm/utils/index.d.ts +2 -6
  39. package/es/ProForm/utils/index.js +3 -30
  40. package/es/ProForm/utils/reactiveValues.d.ts +34 -0
  41. package/es/ProForm/utils/reactiveValues.js +45 -0
  42. package/es/ProSelect/index.js +8 -7
  43. package/es/ProTree/components/ProTreeSelect/index.js +3 -2
  44. package/es/ProTree/utils.d.ts +9 -0
  45. package/es/ProTree/utils.js +31 -0
  46. package/es/ProTreeModal/components/Trigger.js +13 -12
  47. package/es/ProTreeModal/style/index.less +12 -1
  48. package/package.json +1 -2
  49. package/es/ProForm/utils/useForm.d.ts +0 -22
  50. /package/es/ProForm/{utils → hooks}/useDeepCompareMemo.d.ts +0 -0
  51. /package/es/ProForm/{utils → hooks}/useDeepCompareMemo.js +0 -0
  52. /package/es/ProForm/{utils → hooks}/useFieldProps.d.ts +0 -0
  53. /package/es/ProForm/{utils → hooks}/useFieldProps.js +0 -0
  54. /package/es/ProForm/{utils → hooks}/useRules.d.ts +0 -0
  55. /package/es/ProForm/{utils → hooks}/useWatch.d.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ModifiedFormInstanceType } from '../ProForm/utils/useForm';
2
+ import type { ModifiedFormInstanceType } from '../ProForm/propsType';
3
3
  type Forms = Record<string, ModifiedFormInstanceType<any>>;
4
4
  export declare const FormsContext: React.Context<Forms>;
5
5
  /**
@@ -1,17 +1,4 @@
1
1
  import React from 'react';
2
- import { FormInstance } from 'antd';
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 _value = normalize ? normalize(props[valuePropName], undefined, undefined, true) // true 代表是值比对时的调用
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 _originalValue = normalize && ['DatePicker'].includes(props.type) ? normalize(originalValue, undefined, undefined, true) : originalValue;
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 && _value === Number(originalValue)) {
64
+ if (['InputNumber'].includes(props.type) && normalize && normalizedValue === Number(originalValue)) {
130
65
  return 'same';
131
66
  }
132
67
  return diffOriginal({
133
- value: _value,
134
- originalValue: _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
- // 兼容viewRender函数和Element场景
150
- let _children = children;
151
- if (viewRender) {
152
- if (! /*#__PURE__*/React.isValidElement(viewRender)) {
153
- return viewRender(orgValue, originalDTO?.originRecord || {}, {
154
- form,
155
- name,
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(children, {
171
- ...children,
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(children, {
181
- ...children.props,
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
- }), _showEllipse && /*#__PURE__*/_jsxs(Space, {
146
+ }), showEllipse && /*#__PURE__*/_jsxs(Space, {
219
147
  className: "current-value-container",
220
- children: ["\u5F53\u524D\u503C\uFF1A", /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(children, {
221
- // @ts-ignore
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(children, {
231
- // @ts-ignore
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
- // @ts-ignore
236
- ...children.props?.otherProps,
161
+ ...childEl.props?.otherProps,
237
162
  isDiffChange: isChanged
238
163
  }
239
164
  }) : undefined