@zat-design/sisyphus-react 3.13.1-beta.4 → 3.13.1-beta.5

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.
@@ -7,12 +7,13 @@ 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 { getPadding, parseWidth } from '../../utils';
16
17
  import { isEmpty } from '../../../utils';
17
18
  import copySvg from '../../../assets/copy.svg';
18
19
  var Paragraph = _Typography.Paragraph,
@@ -32,12 +33,26 @@ 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
@@ -96,6 +111,9 @@ var RenderColumn = function RenderColumn(props) {
96
111
  if (ellipsis) {
97
112
  return _jsx(_Tooltip, _objectSpread(_objectSpread({
98
113
  title: currentValue,
114
+ getTooltipContainer: function getTooltipContainer() {
115
+ return document.body;
116
+ },
99
117
  onOpenChange: function onOpenChange(open) {
100
118
  setState({
101
119
  tooltip: false
@@ -198,9 +216,13 @@ var RenderColumn = function RenderColumn(props) {
198
216
  children: "-"
199
217
  });
200
218
  }
219
+ var calculatedWidth = updateCalculatedWidth(textRef.current);
201
220
  return _jsx(_Tooltip, _objectSpread(_objectSpread({
202
221
  title: value,
203
- onOpenChange: function onOpenChange(open) {
222
+ getTooltipContainer: function getTooltipContainer() {
223
+ return document.body;
224
+ },
225
+ onOpenChange: function onOpenChange() {
204
226
  setState({
205
227
  tooltip: false
206
228
  });
@@ -208,8 +230,9 @@ var RenderColumn = function RenderColumn(props) {
208
230
  open: tooltip
209
231
  }, tooltipProps), {}, {
210
232
  children: _jsx(Text, {
233
+ ref: textRef,
211
234
  style: {
212
- width: width,
235
+ width: calculatedWidth,
213
236
  minWidth: minWidth
214
237
  },
215
238
  ellipsis: true,
@@ -41,3 +41,5 @@ export declare const getPadding: (el: HTMLElement) => {
41
41
  };
42
42
  /** 判断是有值的对象 */
43
43
  export declare const isNonEmptyObject: (obj: any) => obj is Record<string, any>;
44
+ /** 解析宽度值 */
45
+ export declare const parseWidth: (widthValue: number | string | undefined, trWidth: number) => number;
@@ -105,4 +105,24 @@ export var getPadding = function getPadding(el) {
105
105
  /** 判断是有值的对象 */
106
106
  export var isNonEmptyObject = function isNonEmptyObject(obj) {
107
107
  return obj !== null && _typeof(obj) === 'object' && !Array.isArray(obj) && Object.keys(obj).length > 0;
108
+ };
109
+ /** 解析宽度值 */
110
+ export var parseWidth = function parseWidth(widthValue, trWidth) {
111
+ // 如果是数字,直接返回
112
+ if (typeof widthValue === 'number') return widthValue;
113
+ // 如果是字符串,检查是否是百分比
114
+ if (typeof widthValue === 'string') {
115
+ if (widthValue.endsWith('%')) {
116
+ // 计算百分比
117
+ var percentage = parseFloat(widthValue) / 100;
118
+ return Math.max(trWidth * percentage, 0);
119
+ }
120
+ // 尝试解析为数字(处理如'300px'这样的情况)
121
+ var numericValue = parseFloat(widthValue);
122
+ if (!Number.isNaN(numericValue)) {
123
+ return numericValue;
124
+ }
125
+ }
126
+ // 所有其他情况,返回默认值
127
+ return null;
108
128
  };
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _jsxRuntime = require("react/jsx-runtime");
11
+ var _react = require("react");
11
12
  var _antd = require("antd");
12
13
  var _ahooks = require("ahooks");
13
14
  var _lodash = require("lodash");
@@ -34,12 +35,26 @@ var RenderColumn = function RenderColumn(props) {
34
35
  minWidth = props.minWidth,
35
36
  isInNewRowFlag = props.isInNewRowFlag,
36
37
  scroll = props.scroll;
38
+ var textRef = (0, _react.useRef)(null);
37
39
  var _useSetState = (0, _ahooks.useSetState)({
38
40
  tooltip: false
39
41
  }),
40
42
  _useSetState2 = (0, _slicedToArray2.default)(_useSetState, 2),
41
43
  tooltip = _useSetState2[0].tooltip,
42
44
  setState = _useSetState2[1];
45
+ // 计算并更新宽度
46
+ var updateCalculatedWidth = function updateCalculatedWidth(element) {
47
+ if (!element) return null;
48
+ if (!textRef.current) return;
49
+ // 使用closest方法查找最近的tr
50
+ var tr = element.closest('tr');
51
+ if (!tr) return;
52
+ // 获取tr的宽度
53
+ var trWidth = tr.getBoundingClientRect().width;
54
+ // 计算实际宽度
55
+ var newWidth = (0, _utils.parseWidth)(width, trWidth);
56
+ return newWidth;
57
+ };
43
58
  var cellDiffCls = (0, _classnames.default)({
44
59
  'varied-cell': props === null || props === void 0 ? void 0 : props.isChanged,
45
60
  'add-cell': props === null || props === void 0 ? void 0 : props.isAddCell
@@ -98,6 +113,9 @@ var RenderColumn = function RenderColumn(props) {
98
113
  if (ellipsis) {
99
114
  return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
100
115
  title: currentValue,
116
+ getTooltipContainer: function getTooltipContainer() {
117
+ return document.body;
118
+ },
101
119
  onOpenChange: function onOpenChange(open) {
102
120
  setState({
103
121
  tooltip: false
@@ -200,9 +218,13 @@ var RenderColumn = function RenderColumn(props) {
200
218
  children: "-"
201
219
  });
202
220
  }
221
+ var calculatedWidth = updateCalculatedWidth(textRef.current);
203
222
  return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
204
223
  title: value,
205
- onOpenChange: function onOpenChange(open) {
224
+ getTooltipContainer: function getTooltipContainer() {
225
+ return document.body;
226
+ },
227
+ onOpenChange: function onOpenChange() {
206
228
  setState({
207
229
  tooltip: false
208
230
  });
@@ -210,8 +232,9 @@ var RenderColumn = function RenderColumn(props) {
210
232
  open: tooltip
211
233
  }, tooltipProps), {}, {
212
234
  children: (0, _jsxRuntime.jsx)(Text, {
235
+ ref: textRef,
213
236
  style: {
214
- width: width,
237
+ width: calculatedWidth,
215
238
  minWidth: minWidth
216
239
  },
217
240
  ellipsis: true,
@@ -41,3 +41,5 @@ export declare const getPadding: (el: HTMLElement) => {
41
41
  };
42
42
  /** 判断是有值的对象 */
43
43
  export declare const isNonEmptyObject: (obj: any) => obj is Record<string, any>;
44
+ /** 解析宽度值 */
45
+ export declare const parseWidth: (widthValue: number | string | undefined, trWidth: number) => number;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.removeEmptyKeys = exports.isNonEmptyObject = exports.isListResult = exports.getRowKey = exports.getPadding = exports.getOriginalValue = exports.getDecimalDigits = exports.getColumnDataIndex = void 0;
7
+ exports.removeEmptyKeys = exports.parseWidth = exports.isNonEmptyObject = exports.isListResult = exports.getRowKey = exports.getPadding = exports.getOriginalValue = exports.getDecimalDigits = exports.getColumnDataIndex = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _lodash = require("lodash");
@@ -112,4 +112,24 @@ var getPadding = exports.getPadding = function getPadding(el) {
112
112
  /** 判断是有值的对象 */
113
113
  var isNonEmptyObject = exports.isNonEmptyObject = function isNonEmptyObject(obj) {
114
114
  return obj !== null && (0, _typeof2.default)(obj) === 'object' && !Array.isArray(obj) && Object.keys(obj).length > 0;
115
+ };
116
+ /** 解析宽度值 */
117
+ var parseWidth = exports.parseWidth = function parseWidth(widthValue, trWidth) {
118
+ // 如果是数字,直接返回
119
+ if (typeof widthValue === 'number') return widthValue;
120
+ // 如果是字符串,检查是否是百分比
121
+ if (typeof widthValue === 'string') {
122
+ if (widthValue.endsWith('%')) {
123
+ // 计算百分比
124
+ var percentage = parseFloat(widthValue) / 100;
125
+ return Math.max(trWidth * percentage, 0);
126
+ }
127
+ // 尝试解析为数字(处理如'300px'这样的情况)
128
+ var numericValue = parseFloat(widthValue);
129
+ if (!Number.isNaN(numericValue)) {
130
+ return numericValue;
131
+ }
132
+ }
133
+ // 所有其他情况,返回默认值
134
+ return null;
115
135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.13.1-beta.4",
3
+ "version": "3.13.1-beta.5",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",