@zat-design/sisyphus-react 3.13.1 → 3.13.2-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.
Files changed (39) hide show
  1. package/dist/index.esm.css +3 -0
  2. package/dist/less.esm.css +3 -0
  3. package/es/ProForm/components/render/RenderFields.js +5 -1
  4. package/es/ProForm/components/render/propsType.d.ts +6 -1
  5. package/es/ProForm/propsType.d.ts +4 -0
  6. package/es/ProForm/utils/processDependencies.d.ts +29 -0
  7. package/es/ProForm/utils/processDependencies.js +55 -0
  8. package/es/ProIcon/index.js +7 -4
  9. package/es/ProLayout/components/ProCollapse/index.js +2 -0
  10. package/es/ProStepTab/index.js +14 -10
  11. package/es/ProTable/components/RenderColumn/index.js +28 -25
  12. package/es/ProTable/hooks/useAntdTable.js +3 -9
  13. package/es/ProTable/style/index.less +3 -0
  14. package/es/ProTable/utils/index.d.ts +2 -6
  15. package/es/ProTable/utils/index.js +20 -14
  16. package/es/ProTooltip/index.d.ts +0 -1
  17. package/es/ProTooltip/index.js +48 -59
  18. package/es/ProTooltip/propsType.d.ts +4 -4
  19. package/es/utils/index.d.ts +8 -0
  20. package/es/utils/index.js +17 -0
  21. package/lib/ProForm/components/render/RenderFields.js +5 -1
  22. package/lib/ProForm/components/render/propsType.d.ts +6 -1
  23. package/lib/ProForm/propsType.d.ts +4 -0
  24. package/lib/ProForm/utils/processDependencies.d.ts +29 -0
  25. package/lib/ProForm/utils/processDependencies.js +63 -0
  26. package/lib/ProIcon/index.js +7 -4
  27. package/lib/ProLayout/components/ProCollapse/index.js +2 -0
  28. package/lib/ProStepTab/index.js +14 -10
  29. package/lib/ProTable/components/RenderColumn/index.js +26 -23
  30. package/lib/ProTable/hooks/useAntdTable.js +3 -9
  31. package/lib/ProTable/style/index.less +3 -0
  32. package/lib/ProTable/utils/index.d.ts +2 -6
  33. package/lib/ProTable/utils/index.js +21 -15
  34. package/lib/ProTooltip/index.d.ts +0 -1
  35. package/lib/ProTooltip/index.js +47 -58
  36. package/lib/ProTooltip/propsType.d.ts +4 -4
  37. package/lib/utils/index.d.ts +8 -0
  38. package/lib/utils/index.js +18 -1
  39. package/package.json +1 -1
@@ -1848,6 +1848,9 @@
1848
1848
  .pro-table .ant-table-cell-with-append > div {
1849
1849
  display: inline-block;
1850
1850
  }
1851
+ .pro-table .ant-table-content > table .ant-table-cell-fix-left-last:after {
1852
+ width: 8px;
1853
+ }
1851
1854
  .pro-table .ant-table-content > table .ant-table-summary {
1852
1855
  color: var(--zaui-text, #343434);
1853
1856
  font-weight: 600;
package/dist/less.esm.css CHANGED
@@ -1848,6 +1848,9 @@
1848
1848
  .pro-table .ant-table-cell-with-append > div {
1849
1849
  display: inline-block;
1850
1850
  }
1851
+ .pro-table .ant-table-content > table .ant-table-cell-fix-left-last:after {
1852
+ width: 8px;
1853
+ }
1851
1854
  .pro-table .ant-table-content > table .ant-table-summary {
1852
1855
  color: var(--zaui-text, #343434);
1853
1856
  font-weight: 600;
@@ -10,6 +10,7 @@ import * as componentMap from '../index';
10
10
  import { isSelect } from '../../utils';
11
11
  import { FieldProvider } from '../../utils/useFieldProps';
12
12
  import locale from '../../../locale';
13
+ import processDependencies from '../../utils/processDependencies';
13
14
  var RenderFields = function RenderFields(props) {
14
15
  var isView = props.isView,
15
16
  _props$columns = props.columns,
@@ -80,10 +81,13 @@ var RenderFields = function RenderFields(props) {
80
81
  var component = column.component;
81
82
  var _isView = typeof column.isView === 'boolean' ? column.isView : isView;
82
83
  var defaultProps = getDefaultProps(column);
84
+ // 处理dependencies,支持namesPaths格式
85
+ var processedDeps = processDependencies(column.dependencies);
83
86
  // 允许formItem的属性放在column最外层 并优先级高于 formItemProps 内部参数
84
87
  var _formItemProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultProps), formItemProps), otherFormItemProps), {}, {
85
88
  required: columnRequired !== null && columnRequired !== void 0 ? columnRequired : required,
86
- clearNotShow: clearNotShow
89
+ clearNotShow: clearNotShow,
90
+ dependencies: processedDeps
87
91
  });
88
92
  _formItemProps.labelWidth = _formItemProps.labelWidth || labelWidth; // 接收Form中的labelWidth
89
93
  if (type && component) {
@@ -31,6 +31,7 @@ import type { GroupType as GroupCopyProps } from '../combination/Group/propsType
31
31
  import type { ProCollapseProps } from '../../../ProLayout/components/ProCollapse/PropTypes';
32
32
  import type { DistributiveOmit, DiffConfigType } from '../../propsType';
33
33
  import type { DiffOriginalParams } from '../../utils/diffOriginal';
34
+ import { NamePathsDependencyType } from '../../utils/processDependencies';
34
35
  type ValidateKey = keyof typeof validate;
35
36
  type RegExpKey = keyof typeof regExp;
36
37
  export interface ProRule extends Omit<RuleObject, 'type'> {
@@ -230,7 +231,11 @@ export interface ProFormColumn<Values = any> extends Omit<FormItemProps<Values>,
230
231
  /** 脱敏数据位置下标 */
231
232
  desensitization?: [number, number] | ReactiveFunction<Values, [number, number]>;
232
233
  }
233
- export type ProFormColumnType<T = any> = ProFormColumn<T> & ColumnTypeMap<T, 'ProForm'>;
234
+ export interface ProFormColumnWithExtendedDeps<Values = any> extends Omit<ProFormColumn<Values>, 'dependencies'> {
235
+ /** 表单项依赖关系,扩展支持namesPaths类型 */
236
+ dependencies?: NamePath[] | (NamePath | NamePathsDependencyType)[];
237
+ }
238
+ export type ProFormColumnType<T = any> = ProFormColumnWithExtendedDeps<T> & ColumnTypeMap<T, 'ProForm'>;
234
239
  /**
235
240
  * 表单渲染类型
236
241
  */
@@ -65,6 +65,10 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
65
65
  /** 全局控制优先 */
66
66
  globalControl?: boolean;
67
67
  mode?: ModeEnum;
68
+ /**
69
+ * 如果有formKey,则会在全局中查找或创建表单实例
70
+ * 可以不需要手动传入form实例 且formKey的优先级高于form
71
+ */
68
72
  formKey?: string;
69
73
  /** 是否查看 */
70
74
  isView?: boolean;
@@ -0,0 +1,29 @@
1
+ import type { NamePath } from 'antd/es/form/interface';
2
+ /**
3
+ * 定义支持多字段依赖的类型
4
+ */
5
+ export interface NamePathsDependencyType {
6
+ type: 'namesPaths';
7
+ paths: NamePath[][];
8
+ }
9
+ /**
10
+ * dependencies支持的类型
11
+ */
12
+ export type Dependencies = NamePath[] | NamePathsDependencyType;
13
+ /**
14
+ * 处理表单依赖项
15
+ *
16
+ * 将常规的依赖项数组与namesPaths类型的依赖项进行处理
17
+ * 对于namesPaths类型,将其转换为特定格式的字符串:
18
+ * - 同一路径内的多级通过下划线(_)连接
19
+ * - 不同路径之间通过连字符(-)连接
20
+ *
21
+ * 例如:
22
+ * { type: 'namesPaths', paths: [['a', 'b'], ['c', 'd']] }
23
+ * 会被转换成: ['a_b-c_d']
24
+ *
25
+ * @param dependencies 依赖项配置
26
+ * @returns 处理后的依赖项数组
27
+ */
28
+ export declare function processDependencies(dependencies?: any): any;
29
+ export default processDependencies;
@@ -0,0 +1,55 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ /**
3
+ * 处理表单依赖项
4
+ *
5
+ * 将常规的依赖项数组与namesPaths类型的依赖项进行处理
6
+ * 对于namesPaths类型,将其转换为特定格式的字符串:
7
+ * - 同一路径内的多级通过下划线(_)连接
8
+ * - 不同路径之间通过连字符(-)连接
9
+ *
10
+ * 例如:
11
+ * { type: 'namesPaths', paths: [['a', 'b'], ['c', 'd']] }
12
+ * 会被转换成: ['a_b-c_d']
13
+ *
14
+ * @param dependencies 依赖项配置
15
+ * @returns 处理后的依赖项数组
16
+ */
17
+ export function processDependencies(dependencies) {
18
+ /**
19
+ * 1、没有 dependencies,直接返回
20
+ */
21
+ if (!dependencies) return undefined;
22
+ /**
23
+ * 2、如果是数组,处理可能包含多种类型的元素
24
+ */
25
+ if (Array.isArray(dependencies)) {
26
+ return dependencies.map(function (item) {
27
+ // 处理数组中的namesPaths类型元素
28
+ if (_typeof(item) === 'object' && item !== null && 'type' in item && item.type === 'namesPaths') {
29
+ // 安全类型转换
30
+ var itemWithPaths = item;
31
+ var paths = itemWithPaths.paths;
32
+ return paths.map(function (path) {
33
+ return Array.isArray(path) ? path.join('_') : String(path);
34
+ }).join('-');
35
+ }
36
+ // 其他类型元素保持不变
37
+ return item;
38
+ });
39
+ }
40
+ /**
41
+ * 3、如果是单个namesPaths对象,转换为特定的字符串形式
42
+ * 例如:[['a','b','c'], ['a','b','d']] => 'a_b_c-a_b_d'
43
+ */
44
+ if ('type' in dependencies && dependencies.type === 'namesPaths') {
45
+ var paths = dependencies.paths;
46
+ return [paths.map(function (path) {
47
+ return Array.isArray(path) ? path.join('_') : String(path);
48
+ }).join('-')];
49
+ }
50
+ /**
51
+ * 4、如果是普通的 dependencies,直接返回
52
+ */
53
+ return dependencies;
54
+ }
55
+ export default processDependencies;
@@ -135,6 +135,9 @@ var ProIcon = function ProIcon(props) {
135
135
  }, rotateStyle), style)
136
136
  };
137
137
  var icon = !src ? _jsx("svg", _objectSpread(_objectSpread({}, svgProps), {}, {
138
+ style: _objectSpread({
139
+ color: color
140
+ }, svgProps === null || svgProps === void 0 ? void 0 : svgProps.style),
138
141
  onClick: onClick,
139
142
  "aria-hidden": "true",
140
143
  children: _jsx("use", {
@@ -151,13 +154,13 @@ var ProIcon = function ProIcon(props) {
151
154
  actionMap: actionMap,
152
155
  primaryColor: isQiankun ? qiankunPrimaryColor : primaryColor
153
156
  });
157
+ if (color) {
158
+ svg.setAttribute('fill', color);
159
+ }
154
160
  }
155
161
  }));
156
162
  var RenderIcon = _jsx("span", _objectSpread(_objectSpread({
157
- className: "anticon",
158
- style: {
159
- color: color
160
- }
163
+ className: "anticon"
161
164
  }, reset), {}, {
162
165
  children: _jsx(_Tooltip, {
163
166
  title: iconText,
@@ -139,6 +139,8 @@ var ProCollapse = function ProCollapse(props) {
139
139
  var rect = proCollapseNoTitles[0].getBoundingClientRect();
140
140
  if ((rect === null || rect === void 0 ? void 0 : rect.height) < window.innerHeight - rect.top) {
141
141
  proCollapseNoTitles[0].style.minHeight = "calc(100vh - ".concat(rect.top + 16, "px)");
142
+ } else {
143
+ proCollapseNoTitles[0].style.minHeight = 'auto';
142
144
  }
143
145
  if (proFooterNode) {
144
146
  proCollapseNoTitles[0].style.minHeight = "calc(100vh - ".concat(rect.top + proFooterNode.offsetHeight + 16, "px)");
@@ -247,7 +247,7 @@ export function useStepTab() {
247
247
  case 0:
248
248
  handler = handlesState[activeKey];
249
249
  if (!handler) {
250
- _context4.next = 14;
250
+ _context4.next = 15;
251
251
  break;
252
252
  }
253
253
  _context4.next = 4;
@@ -255,29 +255,33 @@ export function useStepTab() {
255
255
  case 4:
256
256
  result = _context4.sent;
257
257
  if (!(result && autoNext)) {
258
- _context4.next = 11;
258
+ _context4.next = 12;
259
259
  break;
260
260
  }
261
261
  // 只有当activeKey能转换为数字时才执行自动跳转
262
262
  currentKeyNum = Number(activeKey);
263
263
  if (isNaN(currentKeyNum)) {
264
- _context4.next = 11;
264
+ _context4.next = 12;
265
265
  break;
266
266
  }
267
- nextKey = String(currentKeyNum + 1); // 自动跳转到下一个tab
268
- _context4.next = 11;
267
+ nextKey = String(currentKeyNum + 1);
268
+ if (Number(nextKey) > queueSteps) {
269
+ nextKey = String(queueSteps);
270
+ }
271
+ // 自动跳转到下一个tab
272
+ _context4.next = 12;
269
273
  return setCheckActiveKey(nextKey, false);
270
- case 11:
274
+ case 12:
271
275
  if (!(result === false)) {
272
- _context4.next = 13;
276
+ _context4.next = 14;
273
277
  break;
274
278
  }
275
279
  return _context4.abrupt("return", Promise.reject());
276
- case 13:
277
- return _context4.abrupt("return", result);
278
280
  case 14:
279
- return _context4.abrupt("return", Promise.resolve(true));
281
+ return _context4.abrupt("return", result);
280
282
  case 15:
283
+ return _context4.abrupt("return", Promise.resolve(true));
284
+ case 16:
281
285
  case "end":
282
286
  return _context4.stop();
283
287
  }
@@ -7,13 +7,14 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
7
  import "antd/es/typography/style";
8
8
  import _Typography from "antd/es/typography";
9
9
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
10
+ import { useRef } from 'react';
10
11
  import { useSetState } from 'ahooks';
11
12
  import { isBoolean } from 'lodash';
12
13
  import classNames from 'classnames';
13
14
  import { CheckOutlined } from '@ant-design/icons';
14
15
  import { ReactSVG } from 'react-svg';
15
- import { getPadding } from '../../utils';
16
- import { isEmpty } from '../../../utils';
16
+ import { parseWidth } from '../../utils';
17
+ import { isEmpty, isEllipsisActive } from '../../../utils';
17
18
  import copySvg from '../../../assets/copy.svg';
18
19
  var Paragraph = _Typography.Paragraph,
19
20
  Text = _Typography.Text;
@@ -32,35 +33,33 @@ var RenderColumn = function RenderColumn(props) {
32
33
  minWidth = props.minWidth,
33
34
  isInNewRowFlag = props.isInNewRowFlag,
34
35
  scroll = props.scroll;
36
+ var textRef = useRef(null);
35
37
  var _useSetState = useSetState({
36
38
  tooltip: false
37
39
  }),
38
40
  _useSetState2 = _slicedToArray(_useSetState, 2),
39
41
  tooltip = _useSetState2[0].tooltip,
40
42
  setState = _useSetState2[1];
43
+ // 计算并更新宽度
44
+ var updateCalculatedWidth = function updateCalculatedWidth(element) {
45
+ if (!element) return null;
46
+ if (!textRef.current) return;
47
+ // 使用closest方法查找最近的tr
48
+ var tr = element.closest('tr');
49
+ if (!tr) return;
50
+ // 获取tr的宽度
51
+ var trWidth = tr.getBoundingClientRect().width;
52
+ // 计算实际宽度
53
+ var newWidth = parseWidth(width, trWidth);
54
+ return newWidth;
55
+ };
41
56
  var cellDiffCls = classNames({
42
57
  'varied-cell': props === null || props === void 0 ? void 0 : props.isChanged,
43
58
  'add-cell': props === null || props === void 0 ? void 0 : props.isAddCell
44
59
  });
45
- var checkEllipsis = function checkEllipsis(box) {
46
- var range = document.createRange();
47
- range.setStart(box, 0);
48
- range.setEnd(box, box.childNodes.length);
49
- var rangeWidth = range.getBoundingClientRect().width;
50
- var _getPadding = getPadding(box),
51
- pLeft = _getPadding.pLeft,
52
- pRight = _getPadding.pRight,
53
- pTop = _getPadding.pTop,
54
- pBottom = _getPadding.pBottom;
55
- var horizontalPadding = pLeft + pRight;
56
- if (rangeWidth + horizontalPadding > box.clientWidth) {
57
- return true;
58
- }
59
- return false;
60
- };
61
60
  var handleMouseOver = function handleMouseOver(e) {
62
61
  setState({
63
- tooltip: checkEllipsis(e.target)
62
+ tooltip: isEllipsisActive(e.target)
64
63
  });
65
64
  };
66
65
  var tooltipProps = _objectSpread({
@@ -133,6 +132,7 @@ var RenderColumn = function RenderColumn(props) {
133
132
  minWidth: minWidth
134
133
  },
135
134
  overlayClassName: "original-value-tooltip",
135
+ destroyTooltipOnHide: true,
136
136
  placement: "topLeft",
137
137
  autoAdjustOverflow: false,
138
138
  title: _jsx(_Space, {
@@ -150,10 +150,7 @@ var RenderColumn = function RenderColumn(props) {
150
150
  }) : null
151
151
  })]
152
152
  }) : node
153
- }),
154
- getPopupContainer: function getPopupContainer(triggerNode) {
155
- return triggerNode.parentNode;
156
- }
153
+ })
157
154
  }, toolTipProps), {}, {
158
155
  children: renderNode
159
156
  }));
@@ -198,18 +195,24 @@ var RenderColumn = function RenderColumn(props) {
198
195
  children: "-"
199
196
  });
200
197
  }
198
+ var calculatedWidth = updateCalculatedWidth(textRef.current);
201
199
  return _jsx(_Tooltip, _objectSpread(_objectSpread({
202
200
  title: value,
203
- onOpenChange: function onOpenChange(open) {
201
+ destroyTooltipOnHide: true,
202
+ onOpenChange: function onOpenChange() {
204
203
  setState({
205
204
  tooltip: false
206
205
  });
207
206
  },
208
207
  open: tooltip
209
208
  }, tooltipProps), {}, {
209
+ getPopupContainer: function getPopupContainer() {
210
+ return document.body;
211
+ },
210
212
  children: _jsx(Text, {
213
+ ref: textRef,
211
214
  style: {
212
- width: width,
215
+ width: calculatedWidth,
213
216
  minWidth: minWidth
214
217
  },
215
218
  ellipsis: true,
@@ -26,7 +26,7 @@ var useDefaultOptions = function useDefaultOptions(options) {
26
26
  };
27
27
  var previousSearchValues = null;
28
28
  function useAntdTable(service, options, useRequestOptions) {
29
- var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5;
29
+ var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5, _result$params;
30
30
  var _useSetState = useSetState({
31
31
  data: [],
32
32
  total: 0,
@@ -103,12 +103,6 @@ function useAntdTable(service, options, useRequestOptions) {
103
103
  allSelected: false
104
104
  }, values));
105
105
  };
106
- var params = useMemo(function () {
107
- var newQueryBean = _objectSpread(_objectSpread({}, searchValues), extraFilter);
108
- return getTransformParams(_objectSpread({
109
- page: page
110
- }, newQueryBean));
111
- }, [page, searchValues, extraFilter]);
112
106
  var curService = useMemo(function () {
113
107
  return service.toString();
114
108
  }, [service]);
@@ -247,7 +241,7 @@ function useAntdTable(service, options, useRequestOptions) {
247
241
  onPageChange(newPage);
248
242
  }
249
243
  // 减少查询按钮的渲染,只有需要重置值时才需要调用
250
- if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || isNonEmptyObject(_values) && !isEqual(previousSearchValues, _values)) {
244
+ if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || isNonEmptyObject(_values) || !isEqual(previousSearchValues, _values)) {
251
245
  previousSearchValues = _values;
252
246
  setState({
253
247
  searchValues: _values,
@@ -477,7 +471,7 @@ function useAntdTable(service, options, useRequestOptions) {
477
471
  };
478
472
  var useAntdTableProps = _objectSpread(_objectSpread({}, result), {}, {
479
473
  data: data,
480
- params: params,
474
+ params: (result === null || result === void 0 ? void 0 : (_result$params = result.params) === null || _result$params === void 0 ? void 0 : _result$params[0]) || {},
481
475
  rowSelection: rowSelection,
482
476
  searchValues: searchValues,
483
477
  allSelected: allSelected,
@@ -28,6 +28,9 @@
28
28
 
29
29
  .@{ant-prefix}-table-content {
30
30
  > table {
31
+ .@{ant-prefix}-table-cell-fix-left-last:after{
32
+ width: 8px;
33
+ }
31
34
  .@{ant-prefix}-table-summary {
32
35
  color: var(--zaui-text, #343434);
33
36
  font-weight: 600;
@@ -33,11 +33,7 @@ export declare const getRowKey: (rowKey: any, record: any) => any;
33
33
  export declare const removeEmptyKeys: (obj?: Record<string, any>) => {
34
34
  [k: string]: any;
35
35
  };
36
- export declare const getPadding: (el: HTMLElement) => {
37
- pLeft: number;
38
- pRight: number;
39
- pTop: number;
40
- pBottom: number;
41
- };
42
36
  /** 判断是有值的对象 */
43
37
  export declare const isNonEmptyObject: (obj: any) => obj is Record<string, any>;
38
+ /** 解析宽度值 */
39
+ export declare const parseWidth: (widthValue: number | string | undefined, trWidth: number) => number;
@@ -88,21 +88,27 @@ export var removeEmptyKeys = function removeEmptyKeys(obj) {
88
88
  // 使用 Object.fromEntries() 将过滤后的键值对数组转换回对象
89
89
  return Object.fromEntries(filteredEntries);
90
90
  };
91
- /* 获取边距 */
92
- export var getPadding = function getPadding(el) {
93
- var style = window.getComputedStyle(el, null);
94
- var paddingLeft = Number.parseInt(style.paddingLeft, 10) || 0;
95
- var paddingRight = Number.parseInt(style.paddingRight, 10) || 0;
96
- var paddingTop = Number.parseInt(style.paddingTop, 10) || 0;
97
- var paddingBottom = Number.parseInt(style.paddingBottom, 10) || 0;
98
- return {
99
- pLeft: paddingLeft,
100
- pRight: paddingRight,
101
- pTop: paddingTop,
102
- pBottom: paddingBottom
103
- };
104
- };
105
91
  /** 判断是有值的对象 */
106
92
  export var isNonEmptyObject = function isNonEmptyObject(obj) {
107
93
  return obj !== null && _typeof(obj) === 'object' && !Array.isArray(obj) && Object.keys(obj).length > 0;
94
+ };
95
+ /** 解析宽度值 */
96
+ export var parseWidth = function parseWidth(widthValue, trWidth) {
97
+ // 如果是数字,直接返回
98
+ if (typeof widthValue === 'number') return widthValue;
99
+ // 如果是字符串,检查是否是百分比
100
+ if (typeof widthValue === 'string') {
101
+ if (widthValue.endsWith('%')) {
102
+ // 计算百分比
103
+ var percentage = parseFloat(widthValue) / 100;
104
+ return Math.max(trWidth * percentage, 0);
105
+ }
106
+ // 尝试解析为数字(处理如'300px'这样的情况)
107
+ var numericValue = parseFloat(widthValue);
108
+ if (!Number.isNaN(numericValue)) {
109
+ return numericValue;
110
+ }
111
+ }
112
+ // 所有其他情况,返回默认值
113
+ return null;
108
114
  };
@@ -1,4 +1,3 @@
1
1
  import type { ProTooltipType } from './propsType';
2
- import './style/index.less';
3
2
  declare const ProTooltip: (props: ProTooltipType) => import("react/jsx-runtime").JSX.Element;
4
3
  export default ProTooltip;
@@ -4,32 +4,31 @@ import "antd/es/tooltip/style";
4
4
  import _Tooltip from "antd/es/tooltip";
5
5
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
6
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
7
- var _excluded = ["text", "mode", "width", "line", "isResponsiveWidth", "className", "style", "lineHeight"];
7
+ var _excluded = ["text", "mode", "width", "line", "className", "style", "lineHeight", "scrollFollowParent"];
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
- import { useSize, useSetState, useDebounce, useDebounceEffect } from 'ahooks';
9
+ import { useSize, useSetState, useDebounce } from 'ahooks';
10
10
  import { useEffect, useRef } from 'react';
11
11
  import classnames from 'classnames';
12
- import './style/index.less';
12
+ import { isEllipsisActive } from '../utils';
13
13
  var ProTooltip = function ProTooltip(props) {
14
- var _useSize;
14
+ var _useSize, _parentElement$tagNam;
15
15
  var ref = useRef();
16
16
  var childRef = useRef();
17
17
  var contentWrapRef = useRef();
18
18
  var text = props.text,
19
19
  _props$mode = props.mode,
20
20
  mode = _props$mode === void 0 ? 'default' : _props$mode,
21
- _props$width = props.width,
22
- width = _props$width === void 0 ? '120px' : _props$width,
21
+ width = props.width,
23
22
  _props$line = props.line,
24
23
  line = _props$line === void 0 ? 1 : _props$line,
25
- _props$isResponsiveWi = props.isResponsiveWidth,
26
- isResponsiveWidth = _props$isResponsiveWi === void 0 ? false : _props$isResponsiveWi,
27
24
  _props$className = props.className,
28
25
  className = _props$className === void 0 ? '' : _props$className,
29
26
  _props$style = props.style,
30
27
  style = _props$style === void 0 ? {} : _props$style,
31
28
  _props$lineHeight = props.lineHeight,
32
29
  lineHeight = _props$lineHeight === void 0 ? 22 : _props$lineHeight,
30
+ _props$scrollFollowPa = props.scrollFollowParent,
31
+ scrollFollowParent = _props$scrollFollowPa === void 0 ? true : _props$scrollFollowPa,
33
32
  restProps = _objectWithoutProperties(props, _excluded);
34
33
  var _width = mode === 'auto' ? 'auto' : width;
35
34
  var content = text !== null && text !== void 0 ? text : '-';
@@ -59,6 +58,7 @@ var ProTooltip = function ProTooltip(props) {
59
58
  });
60
59
  var _ref = (_useSize = useSize(localElement)) !== null && _useSize !== void 0 ? _useSize : {},
61
60
  _localSizeWidth = _ref.width;
61
+ var isTable = (parentElement === null || parentElement === void 0 ? void 0 : (_parentElement$tagNam = parentElement.tagName) === null || _parentElement$tagNam === void 0 ? void 0 : _parentElement$tagNam.toLowerCase()) === 'td';
62
62
  var overlayStyle = mode === 'auto' ? {
63
63
  maxWidth: _localSizeWidth
64
64
  } : {};
@@ -141,23 +141,6 @@ var ProTooltip = function ProTooltip(props) {
141
141
  }
142
142
  return line > 1 ? _jsx(AutoMixinMulti, {}) : _jsx(AutoMixinSingle, {});
143
143
  };
144
- useDebounceEffect(function () {
145
- if (isResponsiveWidth && parentElement) {
146
- var cWidth = parentElement.clientWidth - 32;
147
- var contentDom = childRef.current;
148
- setState({
149
- isShowToolTip: contentDom.scrollWidth > contentDom.offsetWidth,
150
- localWidth: cWidth
151
- });
152
- }
153
- if (!isResponsiveWidth) {
154
- setState({
155
- localWidth: _width
156
- });
157
- }
158
- }, [isResponsiveWidth, size], {
159
- wait: 300
160
- });
161
144
  useEffect(function () {
162
145
  if (mode === 'auto' && line === 1) {
163
146
  var localDom = ref.current;
@@ -237,57 +220,63 @@ var ProTooltip = function ProTooltip(props) {
237
220
  }, [debouncedValue]);
238
221
  useEffect(function () {
239
222
  var localDom = ref.current;
240
- var contentDom = childRef.current;
223
+ var isEllipsis = isEllipsisActive(childRef === null || childRef === void 0 ? void 0 : childRef.current);
241
224
  setState({
242
225
  parentElement: localDom.parentElement,
243
- isShowToolTip: contentDom.scrollWidth > contentDom.offsetWidth
226
+ isShowToolTip: isEllipsis
244
227
  });
245
228
  }, []);
246
229
  var cls = classnames(_defineProperty({
247
230
  'pro-tooltip': true
248
231
  }, "".concat(className), className));
249
- return _jsx("div", {
250
- className: cls,
251
- ref: ref,
252
- style: _objectSpread(_objectSpread(_objectSpread({}, style), multiStyle), {}, {
253
- width: localWidth
254
- }),
255
- children: isResponsiveWidth && isShowToolTip ? _jsx(_Tooltip, _objectSpread(_objectSpread({
256
- title: text,
257
- getPopupContainer: function getPopupContainer(triggerNode) {
258
- return triggerNode.parentNode;
259
- }
260
- }, restProps), {}, {
261
- children: _jsx("div", {
262
- className: isMultiLine ? 'multiLine' : 'singleLine',
263
- style: _objectSpread(_objectSpread({}, multiStyle), {}, {
264
- width: localWidth
265
- }),
266
- ref: childRef,
267
- children: content
268
- })
269
- })) : isResponsiveWidth ? _jsx("div", {
232
+ var renderContentBox = function renderContentBox() {
233
+ return _jsx("div", {
270
234
  className: isMultiLine ? 'multiLine' : 'singleLine',
271
235
  style: _objectSpread(_objectSpread({}, multiStyle), {}, {
272
236
  width: localWidth
273
237
  }),
274
238
  ref: childRef,
275
239
  children: content
276
- }) : mode === 'default' ? _jsx(_Tooltip, _objectSpread(_objectSpread({
240
+ });
241
+ };
242
+ var renderTooltipContent = function renderTooltipContent() {
243
+ return _jsx(_Tooltip, _objectSpread(_objectSpread({
277
244
  title: text,
278
245
  getPopupContainer: function getPopupContainer(triggerNode) {
279
- return triggerNode.parentNode;
246
+ // 修复scrollFollowParent为false时tooltip不显示的问题
247
+ // 当scrollFollowParent为false时,应该返回document.body而不是triggerNode本身
248
+ return scrollFollowParent ? triggerNode.parentNode : document.body;
280
249
  }
281
250
  }, restProps), {}, {
282
- children: _jsx("div", {
283
- className: isMultiLine ? 'multiLine' : 'singleLine',
284
- style: _objectSpread(_objectSpread({}, multiStyle), {}, {
285
- width: localWidth
286
- }),
287
- ref: childRef,
288
- children: content
289
- })
290
- })) : _jsx(AutoMixin, {})
251
+ overlayStyle: mode === 'auto' ? overlayStyle : {},
252
+ children: renderContentBox()
253
+ }));
254
+ };
255
+ var renderContent = function renderContent() {
256
+ // 自动模式使用专门的渲染逻辑
257
+ if (mode === 'auto') {
258
+ return _jsx(AutoMixin, {});
259
+ }
260
+ // 响应式宽度模式,根据是否需要显示tooltip决定渲染内容 且 父元素为table
261
+ if (isTable) {
262
+ if (isShowToolTip) {
263
+ return renderTooltipContent();
264
+ }
265
+ return renderContentBox();
266
+ }
267
+ // 默认模式始终显示tooltip
268
+ if (mode === 'default') {
269
+ return renderTooltipContent();
270
+ }
271
+ return renderContentBox();
272
+ };
273
+ return _jsx("div", {
274
+ className: cls,
275
+ ref: ref,
276
+ style: _objectSpread(_objectSpread(_objectSpread({}, style), multiStyle), {}, {
277
+ width: localWidth
278
+ }),
279
+ children: renderContent()
291
280
  });
292
281
  };
293
282
  export default ProTooltip;
@@ -19,11 +19,11 @@ export interface ProTooltipType {
19
19
  */
20
20
  line?: number;
21
21
  /**
22
- * 是否响应式宽度
23
- * @description 启用后提示框宽度将根据内容自适应
24
- * @default false
22
+ * 是否跟随父元素滚动
23
+ * @description 启用后,提示框将跟随父元素滚动
24
+ * @default true
25
25
  */
26
- isResponsiveWidth?: Boolean;
26
+ scrollFollowParent?: boolean;
27
27
  /**
28
28
  * 自定义类名
29
29
  * @description 额外的CSS类名