@zat-design/sisyphus-react 3.8.2-beta.17 → 3.8.2-beta.18

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ProTableColumn } from '../../propsType';
3
- export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey, diffToolTip, wrapToolTipProps, scroll, }: {
3
+ export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey, diffToolTip, wrapToolTipProps, scroll, onUpdateMinWidth, }: {
4
4
  column: ProTableColumn;
5
5
  originalObj: any;
6
6
  dataSourceObj: any;
@@ -8,6 +8,7 @@ export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey
8
8
  diffToolTip?: boolean;
9
9
  wrapToolTipProps?: any;
10
10
  scroll?: any;
11
+ onUpdateMinWidth?: any;
11
12
  }) => void;
12
13
  /**
13
14
  * 查找最近的父级className
@@ -5,6 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
5
5
  import { isValidElement } from 'react';
6
6
  import moment from 'moment';
7
7
  import classnames from 'classnames';
8
+ import ReactDOM from 'react-dom';
8
9
  import { isEqual, isFunction, isString, isObject } from 'lodash';
9
10
  import { tools } from '@zat-design/utils';
10
11
  import TooltipTitle from '../TooltipTitle';
@@ -12,22 +13,35 @@ import RenderColumn from '../RenderColumn';
12
13
  import { getDecimalDigits, getOriginalValue } from '../../utils';
13
14
  import getEnumLabel from '../../../ProEnum/utils/getEnumLabel';
14
15
  import ProForm from '../../../ProForm';
16
+ var isReactElement = function isReactElement(element) {
17
+ return /*#__PURE__*/isValidElement(element);
18
+ };
15
19
  var calcMinWidth = function calcMinWidth(_ref) {
16
20
  var minWidth = _ref.minWidth,
17
21
  width = _ref.width,
18
22
  title = _ref.title,
19
- isMaxContentOverFlow = _ref.isMaxContentOverFlow;
20
- var resultMinWidth = minWidth;
23
+ isMaxContentOverFlow = _ref.isMaxContentOverFlow,
24
+ callback = _ref.callback;
21
25
  if (!minWidth && !width && isMaxContentOverFlow) {
22
26
  var tempEl = document.createElement('div');
23
- tempEl.innerHTML = title;
24
- tempEl.style.display = 'inline-block'; // 确保元素有宽度
25
- document.body.appendChild(tempEl); // 将元素添加到 DOM 中
26
- var _width = tempEl.offsetWidth;
27
- tempEl.remove();
28
- resultMinWidth = _width;
27
+ tempEl.style.display = 'inline-block';
28
+ document.body.appendChild(tempEl);
29
+ if (isFunction(title)) {
30
+ var component = title();
31
+ ReactDOM.render(component, tempEl);
32
+ } else if (isReactElement(title)) {
33
+ ReactDOM.render(title, tempEl);
34
+ } else {
35
+ tempEl.innerHTML = title;
36
+ }
37
+ // 使用 requestAnimationFrame 确保在下一个浏览器重绘周期中获取宽度
38
+ requestAnimationFrame(function () {
39
+ var _width = tempEl.offsetWidth;
40
+ ReactDOM.unmountComponentAtNode(tempEl);
41
+ tempEl.remove();
42
+ callback(_width);
43
+ });
29
44
  }
30
- return resultMinWidth;
31
45
  };
32
46
  export var formatColumn = function formatColumn(_ref2) {
33
47
  var column = _ref2.column,
@@ -36,7 +50,8 @@ export var formatColumn = function formatColumn(_ref2) {
36
50
  rowKey = _ref2.rowKey,
37
51
  diffToolTip = _ref2.diffToolTip,
38
52
  wrapToolTipProps = _ref2.wrapToolTipProps,
39
- scroll = _ref2.scroll;
53
+ scroll = _ref2.scroll,
54
+ onUpdateMinWidth = _ref2.onUpdateMinWidth;
40
55
  var title = column.title,
41
56
  valueType = column.valueType,
42
57
  _column$format = column.format,
@@ -56,14 +71,15 @@ export var formatColumn = function formatColumn(_ref2) {
56
71
  originalDiffTip = _column$originalDiffT === void 0 ? true : _column$originalDiffT,
57
72
  _column$toolTipProps = column.toolTipProps,
58
73
  toolTipProps = _column$toolTipProps === void 0 ? {} : _column$toolTipProps,
59
- _minWidth = column.minWidth;
74
+ minWidth = column.minWidth;
60
75
  // 仅在 {x: 'max-content', y: 300 } 且 column无指定 width minWidth 情况下 才开启 minWidth的自动计算
61
76
  var isMaxContentOverFlow = isObject(scroll) ? (scroll === null || scroll === void 0 ? void 0 : scroll.x) === 'max-content' && Reflect.ownKeys(scroll).includes('y') : false;
62
- var minWidth = calcMinWidth({
63
- minWidth: _minWidth,
77
+ calcMinWidth({
78
+ minWidth: minWidth,
64
79
  width: width,
65
80
  title: title,
66
- isMaxContentOverFlow: isMaxContentOverFlow
81
+ isMaxContentOverFlow: isMaxContentOverFlow,
82
+ callback: onUpdateMinWidth
67
83
  });
68
84
  var _toolTipProps = _objectSpread(_objectSpread({}, toolTipProps), wrapToolTipProps);
69
85
  var _originalDiffTip = diffToolTip !== null && diffToolTip !== void 0 ? diffToolTip : originalDiffTip;
@@ -204,7 +204,7 @@ function ProTable(props) {
204
204
  }).filter(function (item) {
205
205
  return !(item === null || item === void 0 ? void 0 : item.delete);
206
206
  });
207
- newColumns === null || newColumns === void 0 ? void 0 : newColumns.forEach(function (item) {
207
+ newColumns === null || newColumns === void 0 ? void 0 : newColumns.forEach(function (item, index) {
208
208
  formatColumn({
209
209
  column: item,
210
210
  originalObj: originalObj,
@@ -212,7 +212,10 @@ function ProTable(props) {
212
212
  rowKey: 'rowKey',
213
213
  diffToolTip: toolTip,
214
214
  wrapToolTipProps: wrapToolTipProps,
215
- scroll: _scroll
215
+ scroll: _scroll,
216
+ onUpdateMinWidth: function onUpdateMinWidth(w) {
217
+ curColumns[index].minWidth = w;
218
+ }
216
219
  });
217
220
  });
218
221
  return newColumns;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ProTableColumn } from '../../propsType';
3
- export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey, diffToolTip, wrapToolTipProps, scroll, }: {
3
+ export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey, diffToolTip, wrapToolTipProps, scroll, onUpdateMinWidth, }: {
4
4
  column: ProTableColumn;
5
5
  originalObj: any;
6
6
  dataSourceObj: any;
@@ -8,6 +8,7 @@ export declare const formatColumn: ({ column, originalObj, dataSourceObj, rowKey
8
8
  diffToolTip?: boolean;
9
9
  wrapToolTipProps?: any;
10
10
  scroll?: any;
11
+ onUpdateMinWidth?: any;
11
12
  }) => void;
12
13
  /**
13
14
  * 查找最近的父级className
@@ -10,6 +10,7 @@ var _jsxRuntime = require("react/jsx-runtime");
10
10
  var _react = require("react");
11
11
  var _moment15 = _interopRequireDefault(require("moment"));
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
+ var _reactDom = _interopRequireDefault(require("react-dom"));
13
14
  var _antd = require("antd");
14
15
  var _lodash = require("lodash");
15
16
  var _utils = require("@zat-design/utils");
@@ -18,22 +19,35 @@ var _RenderColumn = _interopRequireDefault(require("../RenderColumn"));
18
19
  var _utils2 = require("../../utils");
19
20
  var _getEnumLabel = _interopRequireDefault(require("../../../ProEnum/utils/getEnumLabel"));
20
21
  var _ProForm = _interopRequireDefault(require("../../../ProForm"));
22
+ var isReactElement = function isReactElement(element) {
23
+ return /*#__PURE__*/(0, _react.isValidElement)(element);
24
+ };
21
25
  var calcMinWidth = function calcMinWidth(_ref) {
22
26
  var minWidth = _ref.minWidth,
23
27
  width = _ref.width,
24
28
  title = _ref.title,
25
- isMaxContentOverFlow = _ref.isMaxContentOverFlow;
26
- var resultMinWidth = minWidth;
29
+ isMaxContentOverFlow = _ref.isMaxContentOverFlow,
30
+ callback = _ref.callback;
27
31
  if (!minWidth && !width && isMaxContentOverFlow) {
28
32
  var tempEl = document.createElement('div');
29
- tempEl.innerHTML = title;
30
- tempEl.style.display = 'inline-block'; // 确保元素有宽度
31
- document.body.appendChild(tempEl); // 将元素添加到 DOM 中
32
- var _width = tempEl.offsetWidth;
33
- tempEl.remove();
34
- resultMinWidth = _width;
33
+ tempEl.style.display = 'inline-block';
34
+ document.body.appendChild(tempEl);
35
+ if ((0, _lodash.isFunction)(title)) {
36
+ var component = title();
37
+ _reactDom.default.render(component, tempEl);
38
+ } else if (isReactElement(title)) {
39
+ _reactDom.default.render(title, tempEl);
40
+ } else {
41
+ tempEl.innerHTML = title;
42
+ }
43
+ // 使用 requestAnimationFrame 确保在下一个浏览器重绘周期中获取宽度
44
+ requestAnimationFrame(function () {
45
+ var _width = tempEl.offsetWidth;
46
+ _reactDom.default.unmountComponentAtNode(tempEl);
47
+ tempEl.remove();
48
+ callback(_width);
49
+ });
35
50
  }
36
- return resultMinWidth;
37
51
  };
38
52
  var formatColumn = exports.formatColumn = function formatColumn(_ref2) {
39
53
  var column = _ref2.column,
@@ -42,7 +56,8 @@ var formatColumn = exports.formatColumn = function formatColumn(_ref2) {
42
56
  rowKey = _ref2.rowKey,
43
57
  diffToolTip = _ref2.diffToolTip,
44
58
  wrapToolTipProps = _ref2.wrapToolTipProps,
45
- scroll = _ref2.scroll;
59
+ scroll = _ref2.scroll,
60
+ onUpdateMinWidth = _ref2.onUpdateMinWidth;
46
61
  var title = column.title,
47
62
  valueType = column.valueType,
48
63
  _column$format = column.format,
@@ -62,14 +77,15 @@ var formatColumn = exports.formatColumn = function formatColumn(_ref2) {
62
77
  originalDiffTip = _column$originalDiffT === void 0 ? true : _column$originalDiffT,
63
78
  _column$toolTipProps = column.toolTipProps,
64
79
  toolTipProps = _column$toolTipProps === void 0 ? {} : _column$toolTipProps,
65
- _minWidth = column.minWidth;
80
+ minWidth = column.minWidth;
66
81
  // 仅在 {x: 'max-content', y: 300 } 且 column无指定 width minWidth 情况下 才开启 minWidth的自动计算
67
82
  var isMaxContentOverFlow = (0, _lodash.isObject)(scroll) ? (scroll === null || scroll === void 0 ? void 0 : scroll.x) === 'max-content' && Reflect.ownKeys(scroll).includes('y') : false;
68
- var minWidth = calcMinWidth({
69
- minWidth: _minWidth,
83
+ calcMinWidth({
84
+ minWidth: minWidth,
70
85
  width: width,
71
86
  title: title,
72
- isMaxContentOverFlow: isMaxContentOverFlow
87
+ isMaxContentOverFlow: isMaxContentOverFlow,
88
+ callback: onUpdateMinWidth
73
89
  });
74
90
  var _toolTipProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, toolTipProps), wrapToolTipProps);
75
91
  var _originalDiffTip = diffToolTip !== null && diffToolTip !== void 0 ? diffToolTip : originalDiffTip;
@@ -211,7 +211,7 @@ function ProTable(props) {
211
211
  }).filter(function (item) {
212
212
  return !(item === null || item === void 0 ? void 0 : item.delete);
213
213
  });
214
- newColumns === null || newColumns === void 0 ? void 0 : newColumns.forEach(function (item) {
214
+ newColumns === null || newColumns === void 0 ? void 0 : newColumns.forEach(function (item, index) {
215
215
  (0, _FormatColumn.formatColumn)({
216
216
  column: item,
217
217
  originalObj: originalObj,
@@ -219,7 +219,10 @@ function ProTable(props) {
219
219
  rowKey: 'rowKey',
220
220
  diffToolTip: toolTip,
221
221
  wrapToolTipProps: wrapToolTipProps,
222
- scroll: _scroll
222
+ scroll: _scroll,
223
+ onUpdateMinWidth: function onUpdateMinWidth(w) {
224
+ curColumns[index].minWidth = w;
225
+ }
223
226
  });
224
227
  });
225
228
  return newColumns;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.8.2-beta.17",
3
+ "version": "3.8.2-beta.18",
4
4
  "license": "Apache-2.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",