@zat-design/sisyphus-react 3.13.2 → 3.13.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 (38) hide show
  1. package/dist/index.esm.css +3 -0
  2. package/es/FormsProvider/index.d.ts +2 -2
  3. package/es/ProForm/components/FormFooter/index.js +14 -1
  4. package/es/ProForm/components/FormFooter/propsType.d.ts +2 -1
  5. package/es/ProForm/components/render/Render.js +4 -2
  6. package/es/ProForm/index.js +13 -3
  7. package/es/ProForm/propsType.d.ts +2 -0
  8. package/es/ProForm/utils/index.d.ts +7 -2
  9. package/es/ProForm/utils/index.js +19 -1
  10. package/es/ProForm/utils/useForm.d.ts +7 -2
  11. package/es/ProForm/utils/useForm.js +87 -20
  12. package/es/ProForm/utils/useWatch.d.ts +8 -3
  13. package/es/ProForm/utils/useWatch.js +136 -54
  14. package/es/ProTable/components/RenderTabs/index.js +7 -2
  15. package/es/ProTable/hooks/useAntdTable.js +3 -9
  16. package/es/ProTable/propsType.d.ts +6 -0
  17. package/es/ProTooltip/index.js +9 -2
  18. package/es/ProTooltip/propsType.d.ts +1 -2
  19. package/es/style/theme/antd.less +5 -0
  20. package/lib/FormsProvider/index.d.ts +2 -2
  21. package/lib/ProForm/components/FormFooter/index.js +14 -1
  22. package/lib/ProForm/components/FormFooter/propsType.d.ts +2 -1
  23. package/lib/ProForm/components/render/Render.js +4 -2
  24. package/lib/ProForm/index.js +11 -1
  25. package/lib/ProForm/propsType.d.ts +2 -0
  26. package/lib/ProForm/utils/index.d.ts +7 -2
  27. package/lib/ProForm/utils/index.js +20 -2
  28. package/lib/ProForm/utils/useForm.d.ts +7 -2
  29. package/lib/ProForm/utils/useForm.js +86 -19
  30. package/lib/ProForm/utils/useWatch.d.ts +8 -3
  31. package/lib/ProForm/utils/useWatch.js +136 -56
  32. package/lib/ProTable/components/RenderTabs/index.js +7 -2
  33. package/lib/ProTable/hooks/useAntdTable.js +3 -9
  34. package/lib/ProTable/propsType.d.ts +6 -0
  35. package/lib/ProTooltip/index.js +9 -2
  36. package/lib/ProTooltip/propsType.d.ts +1 -2
  37. package/lib/style/theme/antd.less +5 -0
  38. package/package.json +1 -1
@@ -5,83 +5,163 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- exports.getNamePath = getNamePath;
9
- exports.stringify = stringify;
10
8
  exports.toArray = toArray;
9
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
11
  var _lodash = require("lodash");
13
- var _FieldContext = require("rc-field-form/es/FieldContext");
14
12
  var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
15
13
  var _react = require("react");
14
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
16
15
  function toArray(value) {
17
16
  if (value === undefined || value === null) {
18
17
  return [];
19
18
  }
20
19
  return Array.isArray(value) ? value : [value];
21
20
  }
22
- function getNamePath(path) {
23
- return toArray(path);
21
+ // 从一个对象或Form值中获取特定路径的值
22
+ function get(source, path) {
23
+ if (!source || path.length === 0) {
24
+ return source;
25
+ }
26
+ var current = source;
27
+ for (var i = 0; i < path.length; i++) {
28
+ if (current === undefined || current === null) {
29
+ return undefined;
30
+ }
31
+ current = current[path[i]];
32
+ }
33
+ return current;
24
34
  }
25
- function stringify(value) {
26
- try {
27
- return JSON.stringify(value);
28
- } catch (err) {
29
- return Math.random();
35
+ /**
36
+ * 将值设置到指定路径的嵌套对象中
37
+ * @param obj 目标对象
38
+ * @param path 路径数组
39
+ * @param value 要设置的值
40
+ */
41
+ function setValueByPath(obj, path, value) {
42
+ if (path.length === 0) return;
43
+ // 处理单层路径
44
+ if (path.length === 1) {
45
+ obj[path[0]] = value;
46
+ return;
47
+ }
48
+ // 处理多层嵌套路径
49
+ var current = obj;
50
+ for (var i = 0; i < path.length - 1; i++) {
51
+ var key = path[i];
52
+ if (!current[key]) {
53
+ current[key] = {};
54
+ }
55
+ current = current[key];
30
56
  }
57
+ current[path[path.length - 1]] = value;
31
58
  }
32
- // 创建之后namepath就不可变
33
- var useWatchWarning = process.env.NODE_ENV !== 'production' ? function (namePath) {
34
- var fullyStr = JSON.stringify(namePath);
35
- var nameStrRef = (0, _react.useRef)(fullyStr);
36
- (0, _warning.default)(nameStrRef.current === fullyStr, '`useWatch` is not support dynamic `namePath`. Please provide static instead.');
59
+ // 创建之后namepath就不可变的警告
60
+ var useWatchWarning = process.env.NODE_ENV !== 'production' ? function (dependencies) {
61
+ var depsStr = JSON.stringify(dependencies);
62
+ var depsStrRef = (0, _react.useRef)(depsStr);
63
+ (0, _warning.default)(depsStrRef.current === depsStr, '`useWatch` is not support dynamic `namePath`. Please provide static instead.');
37
64
  } : function () {};
65
+ /**
66
+ * ProForm的useWatch hook,用于监听表单字段变化
67
+ * @param dependencies 监听的字段路径
68
+ * @param form 表单实例
69
+ * @param wait 防抖等待时间
70
+ * @returns 表单值
71
+ */
38
72
  function useWatch(dependencies, form, wait) {
39
- var isSingle = typeof dependencies === 'string';
73
+ // 处理开发环境警告
74
+ useWatchWarning(dependencies);
75
+ // 获取表单实例
76
+ var formInstance = form;
77
+ // 用于存储最终结果
40
78
  var _useState = (0, _react.useState)({}),
41
79
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
- value = _useState2[0],
43
- setValue = _useState2[1];
44
- var valueStr = (0, _react.useMemo)(function () {
45
- return stringify(value);
46
- }, [value]);
47
- var valueStrRef = (0, _react.useRef)(valueStr);
48
- valueStrRef.current = valueStr;
49
- var formInstance = form;
50
- var isValidForm = formInstance && formInstance._init;
51
- var _dependencies = isSingle ? [dependencies] : dependencies;
52
- var namePaths = _dependencies === null || _dependencies === void 0 ? void 0 : _dependencies.map(function (item) {
53
- return getNamePath(item);
54
- });
55
- var namePathsRef = (0, _react.useRef)(namePaths);
56
- namePathsRef.current = namePaths;
57
- useWatchWarning(namePaths);
80
+ state = _useState2[0],
81
+ setState = _useState2[1];
82
+ // 使用ref存储中间状态,避免不必要的渲染
83
+ var valueRef = (0, _react.useRef)({});
84
+ var prevStateRef = (0, _react.useRef)({});
85
+ // 标准化依赖为路径数组的数组
86
+ var namePaths = (0, _react.useMemo)(function () {
87
+ // 将依赖标准化为数组的数组形式
88
+ var paths = [];
89
+ // 字符串形式: 'fieldName'
90
+ if (typeof dependencies === 'string') {
91
+ paths.push(dependencies);
92
+ // 数组形式
93
+ } else if (Array.isArray(dependencies)) {
94
+ // 检查是否是路径数组的集合,例如:[['a', 'number'], 'fieldName']
95
+ var isPathsCollection = dependencies.length > 0 && (typeof dependencies[0] === 'string' || Array.isArray(dependencies[0]));
96
+ if (isPathsCollection) {
97
+ // 每个元素都是一个路径
98
+ dependencies.forEach(function (path) {
99
+ paths.push(path);
100
+ });
101
+ } else {
102
+ // 整个数组是一个单一路径
103
+ paths.push(dependencies);
104
+ }
105
+ }
106
+ return paths;
107
+ }, [/* dependencies 故意忽略,与原实现一致 */]);
108
+ // 保存防抖函数引用,避免重复创建
109
+ var debouncedFn = (0, _react.useMemo)(function () {
110
+ if (wait) {
111
+ return (0, _lodash.debounce)(function (value) {
112
+ // 只在值真正变化时才更新状态
113
+ if (!(0, _isEqual.default)(prevStateRef.current, value)) {
114
+ prevStateRef.current = (0, _objectSpread2.default)({}, value);
115
+ setState(value);
116
+ }
117
+ }, wait);
118
+ }
119
+ // 非防抖版本
120
+ return function (value) {
121
+ if (!(0, _isEqual.default)(prevStateRef.current, value)) {
122
+ prevStateRef.current = (0, _objectSpread2.default)({}, value);
123
+ setState(value);
124
+ }
125
+ };
126
+ }, [wait]);
58
127
  (0, _react.useEffect)(function () {
59
- if (!isValidForm) return;
60
- var getFieldsValue = formInstance.getFieldsValue,
61
- getInternalHooks = formInstance.getInternalHooks;
62
- var _getInternalHooks = getInternalHooks(_FieldContext.HOOK_MARK),
128
+ if (!formInstance) return undefined;
129
+ // 创建更新状态的函数
130
+ var updateState = function updateState() {
131
+ var values = formInstance.getFieldsValue(true);
132
+ var newState = {};
133
+ // 处理每个监听路径
134
+ namePaths.forEach(function (path) {
135
+ // 将路径转换为数组形式
136
+ var namePath = toArray(path);
137
+ // 获取路径对应的值
138
+ var value = get(values, namePath);
139
+ // 将值设置到正确的嵌套结构中
140
+ setValueByPath(newState, namePath, value);
141
+ });
142
+ // 存储并更新状态
143
+ valueRef.current = newState;
144
+ debouncedFn(newState);
145
+ };
146
+ // 初始调用一次
147
+ updateState();
148
+ // 注册表单变化监听
149
+ var getInternalHooks = formInstance.getInternalHooks;
150
+ var _getInternalHooks = getInternalHooks('RC_FORM_INTERNAL_HOOKS'),
63
151
  registerWatch = _getInternalHooks.registerWatch;
64
- var callback = function callback() {
65
- var newValue = getFieldsValue(_dependencies);
66
- var nextValueStr = stringify(newValue);
67
- // Compare stringify in case it's nest object
68
- if (valueStrRef.current !== nextValueStr) {
69
- valueStrRef.current = nextValueStr;
70
- setValue(getFieldsValue(_dependencies));
152
+ var cancelWatch = registerWatch(function (values) {
153
+ if (values) {
154
+ updateState();
155
+ }
156
+ });
157
+ // 清理订阅
158
+ return function () {
159
+ if (wait) {
160
+ debouncedFn.cancel();
71
161
  }
162
+ cancelWatch();
72
163
  };
73
- // 增加防抖
74
- if (wait) {
75
- callback = (0, _lodash.debounce)(callback, wait);
76
- }
77
- var cancelRegister = registerWatch(callback);
78
- var initialValue = getFieldsValue(_dependencies);
79
- setValue(initialValue);
80
- return cancelRegister;
81
- },
82
- // We do not need re-register since namePath content is the same
83
- // eslint-disable-next-line react-hooks/exhaustive-deps
84
- [isValidForm]);
85
- return value;
164
+ }, [formInstance, namePaths, debouncedFn, wait]);
165
+ return state;
86
166
  }
87
167
  var _default = exports.default = useWatch;
@@ -20,7 +20,8 @@ var RenderTabs = function RenderTabs(props) {
20
20
  transformResponse = props.transformResponse,
21
21
  tabsProps = props.tabsProps,
22
22
  name = props.name,
23
- formTableProps = props.formTableProps;
23
+ formTableProps = props.formTableProps,
24
+ transformParams = props.transformParams;
24
25
  var _ref = formTableProps || {},
25
26
  form = _ref.form,
26
27
  onSearch = _ref.onSearch;
@@ -71,7 +72,11 @@ var RenderTabs = function RenderTabs(props) {
71
72
  var fieldsValues = (form === null || form === void 0 ? void 0 : form.getFieldsValue()) || {};
72
73
  setActiveKey(key);
73
74
  form.setFieldValue(name, key);
74
- onSearch === null || onSearch === void 0 ? void 0 : onSearch((0, _objectSpread3.default)((0, _objectSpread3.default)({}, fieldsValues), {}, (0, _defineProperty2.default)({}, name, key)));
75
+ var params = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, fieldsValues), {}, (0, _defineProperty2.default)({}, name, key));
76
+ if (transformParams && typeof transformParams === 'function') {
77
+ params = transformParams(params);
78
+ }
79
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(params);
75
80
  },
76
81
  type: "card"
77
82
  }, tabsProps), {}, {
@@ -33,7 +33,7 @@ var useDefaultOptions = function useDefaultOptions(options) {
33
33
  };
34
34
  var previousSearchValues = null;
35
35
  function useAntdTable(service, options, useRequestOptions) {
36
- var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5;
36
+ var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5, _result$params;
37
37
  var _useSetState = (0, _ahooks.useSetState)({
38
38
  data: [],
39
39
  total: 0,
@@ -110,12 +110,6 @@ function useAntdTable(service, options, useRequestOptions) {
110
110
  allSelected: false
111
111
  }, values));
112
112
  };
113
- var params = (0, _react.useMemo)(function () {
114
- var newQueryBean = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, searchValues), extraFilter);
115
- return getTransformParams((0, _objectSpread2.default)({
116
- page: page
117
- }, newQueryBean));
118
- }, [page, searchValues, extraFilter]);
119
113
  var curService = (0, _react.useMemo)(function () {
120
114
  return service.toString();
121
115
  }, [service]);
@@ -254,7 +248,7 @@ function useAntdTable(service, options, useRequestOptions) {
254
248
  onPageChange(newPage);
255
249
  }
256
250
  // 减少查询按钮的渲染,只有需要重置值时才需要调用
257
- if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || (0, _utils.isNonEmptyObject)(_values) && !(0, _lodash.isEqual)(previousSearchValues, _values)) {
251
+ if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || (0, _utils.isNonEmptyObject)(_values) || !(0, _lodash.isEqual)(previousSearchValues, _values)) {
258
252
  previousSearchValues = _values;
259
253
  setState({
260
254
  searchValues: _values,
@@ -484,7 +478,7 @@ function useAntdTable(service, options, useRequestOptions) {
484
478
  };
485
479
  var useAntdTableProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, result), {}, {
486
480
  data: data,
487
- params: params,
481
+ params: (result === null || result === void 0 ? void 0 : (_result$params = result.params) === null || _result$params === void 0 ? void 0 : _result$params[0]) || {},
488
482
  rowSelection: rowSelection,
489
483
  searchValues: searchValues,
490
484
  allSelected: allSelected,
@@ -337,6 +337,12 @@ export interface ProTableTabsType {
337
337
  label: string;
338
338
  value: string;
339
339
  }[];
340
+ /**
341
+ * 转换查询参数
342
+ * @description 转换查询参数
343
+ * @default undefined
344
+ */
345
+ transformParams?: (params: any) => any;
340
346
  /**
341
347
  * 枚举数据源转换
342
348
  * @description 枚举数据源转换
@@ -16,8 +16,15 @@ var _react = require("react");
16
16
  var _classnames2 = _interopRequireDefault(require("classnames"));
17
17
  var _utils = require("../utils");
18
18
  var _excluded = ["text", "mode", "width", "line", "className", "style", "lineHeight", "scrollFollowParent"];
19
+ var _findTableParent = function findTableParent(element) {
20
+ var _element$tagName;
21
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
22
+ if (!element || depth >= 3) return false;
23
+ if (((_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase()) === 'td') return true;
24
+ return _findTableParent(element.parentElement, depth + 1);
25
+ };
19
26
  var ProTooltip = function ProTooltip(props) {
20
- var _useSize, _parentElement$tagNam;
27
+ var _useSize;
21
28
  var ref = (0, _react.useRef)();
22
29
  var childRef = (0, _react.useRef)();
23
30
  var contentWrapRef = (0, _react.useRef)();
@@ -64,7 +71,7 @@ var ProTooltip = function ProTooltip(props) {
64
71
  });
65
72
  var _ref = (_useSize = (0, _ahooks.useSize)(localElement)) !== null && _useSize !== void 0 ? _useSize : {},
66
73
  _localSizeWidth = _ref.width;
67
- var isTable = (parentElement === null || parentElement === void 0 ? void 0 : (_parentElement$tagNam = parentElement.tagName) === null || _parentElement$tagNam === void 0 ? void 0 : _parentElement$tagNam.toLowerCase()) === 'td';
74
+ var isTable = _findTableParent(ref.current);
68
75
  var overlayStyle = mode === 'auto' ? {
69
76
  maxWidth: _localSizeWidth
70
77
  } : {};
@@ -9,9 +9,8 @@ export interface ProTooltipType {
9
9
  /**
10
10
  * 提示框宽度
11
11
  * @description 设置提示框的宽度,支持各种CSS宽度单位
12
- * @default 'auto'
13
12
  */
14
- width?: string;
13
+ width?: string | number;
15
14
  /**
16
15
  * 显示的行数
17
16
  * @description 当内容超过设定行数时将截断显示
@@ -107,6 +107,11 @@
107
107
  .@{ant-prefix}-empty-normal {
108
108
  margin: calc(var(--zaui-space-size-lg; 32px) * var(--zaui-size; 1)) 0;
109
109
  }
110
+ .@{ant-prefix}-table-tbody{
111
+ .@{ant-prefix}-table-cell-fix-left-last:after{
112
+ width: 8px;
113
+ }
114
+ }
110
115
  &.pro-table-no-stripe {
111
116
  .@{ant-prefix}-table-tbody {
112
117
  .@{ant-prefix}-table-row {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.13.2",
3
+ "version": "3.13.3",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",