@zat-design/sisyphus-react 3.13.1-beta.4 → 3.13.1-beta.6
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/es/ProTable/components/RenderColumn/index.js +29 -7
- package/es/ProTable/utils/index.d.ts +2 -0
- package/es/ProTable/utils/index.js +20 -0
- package/lib/ProTable/components/RenderColumn/index.js +28 -6
- package/lib/ProTable/utils/index.d.ts +2 -0
- package/lib/ProTable/utils/index.js +21 -1
- package/package.json +1 -1
@@ -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
|
@@ -133,6 +151,7 @@ var RenderColumn = function RenderColumn(props) {
|
|
133
151
|
minWidth: minWidth
|
134
152
|
},
|
135
153
|
overlayClassName: "original-value-tooltip",
|
154
|
+
destroyTooltipOnHide: true,
|
136
155
|
placement: "topLeft",
|
137
156
|
autoAdjustOverflow: false,
|
138
157
|
title: _jsx(_Space, {
|
@@ -150,10 +169,7 @@ var RenderColumn = function RenderColumn(props) {
|
|
150
169
|
}) : null
|
151
170
|
})]
|
152
171
|
}) : node
|
153
|
-
})
|
154
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
155
|
-
return triggerNode.parentNode;
|
156
|
-
}
|
172
|
+
})
|
157
173
|
}, toolTipProps), {}, {
|
158
174
|
children: renderNode
|
159
175
|
}));
|
@@ -198,18 +214,24 @@ var RenderColumn = function RenderColumn(props) {
|
|
198
214
|
children: "-"
|
199
215
|
});
|
200
216
|
}
|
217
|
+
var calculatedWidth = updateCalculatedWidth(textRef.current);
|
201
218
|
return _jsx(_Tooltip, _objectSpread(_objectSpread({
|
202
219
|
title: value,
|
203
|
-
|
220
|
+
destroyTooltipOnHide: true,
|
221
|
+
onOpenChange: function onOpenChange() {
|
204
222
|
setState({
|
205
223
|
tooltip: false
|
206
224
|
});
|
207
225
|
},
|
208
226
|
open: tooltip
|
209
227
|
}, tooltipProps), {}, {
|
228
|
+
getPopupContainer: function getPopupContainer() {
|
229
|
+
return document.body;
|
230
|
+
},
|
210
231
|
children: _jsx(Text, {
|
232
|
+
ref: textRef,
|
211
233
|
style: {
|
212
|
-
width:
|
234
|
+
width: calculatedWidth,
|
213
235
|
minWidth: minWidth
|
214
236
|
},
|
215
237
|
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
|
@@ -135,6 +153,7 @@ var RenderColumn = function RenderColumn(props) {
|
|
135
153
|
minWidth: minWidth
|
136
154
|
},
|
137
155
|
overlayClassName: "original-value-tooltip",
|
156
|
+
destroyTooltipOnHide: true,
|
138
157
|
placement: "topLeft",
|
139
158
|
autoAdjustOverflow: false,
|
140
159
|
title: (0, _jsxRuntime.jsx)(_antd.Space, {
|
@@ -152,10 +171,7 @@ var RenderColumn = function RenderColumn(props) {
|
|
152
171
|
}) : null
|
153
172
|
})]
|
154
173
|
}) : node
|
155
|
-
})
|
156
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
157
|
-
return triggerNode.parentNode;
|
158
|
-
}
|
174
|
+
})
|
159
175
|
}, toolTipProps), {}, {
|
160
176
|
children: renderNode
|
161
177
|
}));
|
@@ -200,18 +216,24 @@ var RenderColumn = function RenderColumn(props) {
|
|
200
216
|
children: "-"
|
201
217
|
});
|
202
218
|
}
|
219
|
+
var calculatedWidth = updateCalculatedWidth(textRef.current);
|
203
220
|
return (0, _jsxRuntime.jsx)(_antd.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
204
221
|
title: value,
|
205
|
-
|
222
|
+
destroyTooltipOnHide: true,
|
223
|
+
onOpenChange: function onOpenChange() {
|
206
224
|
setState({
|
207
225
|
tooltip: false
|
208
226
|
});
|
209
227
|
},
|
210
228
|
open: tooltip
|
211
229
|
}, tooltipProps), {}, {
|
230
|
+
getPopupContainer: function getPopupContainer() {
|
231
|
+
return document.body;
|
232
|
+
},
|
212
233
|
children: (0, _jsxRuntime.jsx)(Text, {
|
234
|
+
ref: textRef,
|
213
235
|
style: {
|
214
|
-
width:
|
236
|
+
width: calculatedWidth,
|
215
237
|
minWidth: minWidth
|
216
238
|
},
|
217
239
|
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
|
};
|