@rainbow-oh/yee-c 0.10.0 → 0.12.0
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/dist/cjs/Anchor/style/index.less +3 -3
- package/dist/cjs/Button/demo/icon.js +1 -1
- package/dist/cjs/Button/style/index.less +72 -52
- package/dist/cjs/DatePicker/style/mobile.less +1 -1
- package/dist/cjs/Descriptions/style/index.less +6 -6
- package/dist/cjs/FloatButton/style/index.less +2 -2
- package/dist/cjs/Form/style/index.less +21 -21
- package/dist/cjs/ImageViewer/style/index.less +13 -13
- package/dist/cjs/Input/style/index.less +1 -1
- package/dist/cjs/InputNumber/style/index.less +9 -9
- package/dist/cjs/Menu/style/index.less +1 -1
- package/dist/cjs/PickerPanel/style/index.less +5 -5
- package/dist/cjs/RangePicker/style/index.less +53 -52
- package/dist/cjs/Rate/style/index.less +1 -1
- package/dist/cjs/Search/style/index.less +10 -10
- package/dist/cjs/Segmented/style/index.less +2 -2
- package/dist/cjs/Selector/selector.js +1 -1
- package/dist/cjs/Selector/style/index.less +1 -1
- package/dist/cjs/Table/demo/resizable.d.ts +3 -0
- package/dist/cjs/Table/demo/resizable.js +143 -0
- package/dist/cjs/Table/hooks/useColumnResize.d.ts +30 -0
- package/dist/cjs/Table/hooks/useColumnResize.js +217 -0
- package/dist/cjs/Table/hooks/useColumns.d.ts +3 -1
- package/dist/cjs/Table/hooks/useColumns.js +14 -3
- package/dist/cjs/Table/interface.d.ts +49 -0
- package/dist/cjs/Table/style/index.less +43 -1
- package/dist/cjs/Table/table.js +62 -9
- package/dist/cjs/Table/theader/cell.js +46 -4
- package/dist/cjs/Table/util/index.d.ts +19 -1
- package/dist/cjs/Table/util/index.js +22 -0
- package/dist/cjs/Tabs/interface.d.ts +1 -1
- package/dist/cjs/Tabs/style/index.less +9 -9
- package/dist/cjs/Tabs/tab-header/index.js +5 -1
- package/dist/cjs/Tour/demo/indicators.js +1 -1
- package/dist/cjs/Tour/demo/placement.js +1 -1
- package/dist/cjs/Transfer/style/index.less +1 -1
- package/dist/cjs/Tree/style/index.less +3 -3
- package/dist/cjs/TreeSelect/style/index.less +1 -1
- package/dist/cjs/Upload/style/index.less +11 -12
- package/dist/cjs/WheelPicker/style/index.less +3 -3
- package/dist/cjs/locale/interface.d.ts +1 -0
- package/dist/cjs/locale/lang/en_US.js +2 -1
- package/dist/cjs/locale/lang/ja_JP.js +2 -1
- package/dist/cjs/locale/lang/zh_CN.js +2 -1
- package/dist/cjs/locale/lang/zh_TW.js +2 -1
- package/dist/cjs/message/style/index.less +4 -4
- package/dist/cjs/style/color.blue.css +254 -290
- package/dist/cjs/style/color.crimson.css +434 -471
- package/dist/cjs/style/color.css +736 -508
- package/dist/cjs/style/color.dark.css +464 -501
- package/dist/cjs/style/color.gemini.css +134 -0
- package/dist/cjs/style/color.green.css +459 -495
- package/dist/cjs/style/color.jam.css +463 -500
- package/dist/cjs/style/color.navy.css +466 -503
- package/dist/cjs/style/color.peach.css +464 -501
- package/dist/cjs/style/color.pine.css +462 -500
- package/dist/cjs/style/color.pitaya.css +465 -502
- package/dist/cjs/style/color.pumpkin.css +464 -501
- package/dist/cjs/style/color.ruby.css +466 -503
- package/dist/cjs/style/size.css +144 -2
- package/dist/cjs/style/themes.css +4999 -5268
- package/dist/cjs/style/variables.css +882 -512
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Anchor/style/index.less +3 -3
- package/dist/esm/Button/demo/icon.js +7 -4
- package/dist/esm/Button/style/index.less +72 -52
- package/dist/esm/DatePicker/style/mobile.less +1 -1
- package/dist/esm/Descriptions/style/index.less +6 -6
- package/dist/esm/FloatButton/style/index.less +2 -2
- package/dist/esm/Form/style/index.less +21 -21
- package/dist/esm/ImageViewer/style/index.less +13 -13
- package/dist/esm/Input/style/index.less +1 -1
- package/dist/esm/InputNumber/style/index.less +9 -9
- package/dist/esm/Menu/style/index.less +1 -1
- package/dist/esm/PickerPanel/style/index.less +5 -5
- package/dist/esm/RangePicker/style/index.less +53 -52
- package/dist/esm/Rate/style/index.less +1 -1
- package/dist/esm/Search/style/index.less +10 -10
- package/dist/esm/Segmented/style/index.less +2 -2
- package/dist/esm/Selector/selector.js +1 -1
- package/dist/esm/Selector/style/index.less +1 -1
- package/dist/esm/Table/demo/resizable.d.ts +3 -0
- package/dist/esm/Table/demo/resizable.js +110 -0
- package/dist/esm/Table/hooks/useColumnResize.d.ts +30 -0
- package/dist/esm/Table/hooks/useColumnResize.js +206 -0
- package/dist/esm/Table/hooks/useColumns.d.ts +3 -1
- package/dist/esm/Table/hooks/useColumns.js +9 -4
- package/dist/esm/Table/interface.d.ts +49 -0
- package/dist/esm/Table/style/index.less +43 -1
- package/dist/esm/Table/table.js +83 -13
- package/dist/esm/Table/theader/cell.js +38 -3
- package/dist/esm/Table/util/index.d.ts +19 -1
- package/dist/esm/Table/util/index.js +37 -0
- package/dist/esm/Tabs/interface.d.ts +1 -1
- package/dist/esm/Tabs/style/index.less +9 -9
- package/dist/esm/Tabs/tab-header/index.js +7 -2
- package/dist/esm/Tour/demo/indicators.js +1 -1
- package/dist/esm/Tour/demo/placement.js +1 -1
- package/dist/esm/Transfer/style/index.less +1 -1
- package/dist/esm/Tree/style/index.less +3 -3
- package/dist/esm/TreeSelect/style/index.less +1 -1
- package/dist/esm/Upload/style/index.less +11 -12
- package/dist/esm/WheelPicker/style/index.less +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/locale/interface.d.ts +1 -0
- package/dist/esm/locale/lang/en_US.js +2 -1
- package/dist/esm/locale/lang/ja_JP.js +2 -1
- package/dist/esm/locale/lang/zh_CN.js +2 -1
- package/dist/esm/locale/lang/zh_TW.js +2 -1
- package/dist/esm/message/style/index.less +4 -4
- package/dist/esm/style/color.blue.css +254 -290
- package/dist/esm/style/color.crimson.css +434 -471
- package/dist/esm/style/color.css +736 -508
- package/dist/esm/style/color.dark.css +464 -501
- package/dist/esm/style/color.gemini.css +134 -0
- package/dist/esm/style/color.green.css +459 -495
- package/dist/esm/style/color.jam.css +463 -500
- package/dist/esm/style/color.navy.css +466 -503
- package/dist/esm/style/color.peach.css +464 -501
- package/dist/esm/style/color.pine.css +462 -500
- package/dist/esm/style/color.pitaya.css +465 -502
- package/dist/esm/style/color.pumpkin.css +464 -501
- package/dist/esm/style/color.ruby.css +466 -503
- package/dist/esm/style/size.css +144 -2
- package/dist/esm/style/themes.css +4999 -5268
- package/dist/esm/style/variables.css +882 -512
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +80 -22
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +4 -2
- package/src/Anchor/style/index.less +3 -3
- package/src/Button/demo/icon.tsx +5 -3
- package/src/Button/style/index.less +72 -52
- package/src/DatePicker/style/mobile.less +1 -1
- package/src/Descriptions/style/index.less +6 -6
- package/src/FloatButton/style/index.less +2 -2
- package/src/Form/style/index.less +21 -21
- package/src/ImageViewer/style/index.less +13 -13
- package/src/Input/style/index.less +1 -1
- package/src/InputNumber/style/index.less +9 -9
- package/src/Menu/style/index.less +1 -1
- package/src/PickerPanel/style/index.less +5 -5
- package/src/RangePicker/style/index.less +53 -52
- package/src/Rate/style/index.less +1 -1
- package/src/Search/style/index.less +10 -10
- package/src/Segmented/style/index.less +2 -2
- package/src/Selector/selector.tsx +1 -1
- package/src/Selector/style/index.less +1 -1
- package/src/Table/demo/resizable.tsx +106 -0
- package/src/Table/hooks/useColumnResize.ts +224 -0
- package/src/Table/hooks/useColumns.ts +18 -3
- package/src/Table/index.en-US.md +7 -0
- package/src/Table/index.zh-CN.md +7 -0
- package/src/Table/interface.ts +52 -0
- package/src/Table/style/index.less +43 -1
- package/src/Table/table-resize.test.tsx +234 -0
- package/src/Table/table.tsx +90 -13
- package/src/Table/theader/cell.tsx +52 -2
- package/src/Table/util/index.ts +44 -1
- package/src/Tabs/interface.ts +1 -1
- package/src/Tabs/style/index.less +9 -9
- package/src/Tabs/tab-header/index.tsx +5 -1
- package/src/Tour/demo/indicators.tsx +2 -2
- package/src/Tour/demo/placement.tsx +1 -1
- package/src/Transfer/style/index.less +1 -1
- package/src/Tree/style/index.less +3 -3
- package/src/TreeSelect/style/index.less +1 -1
- package/src/Upload/style/index.less +11 -12
- package/src/WheelPicker/style/index.less +3 -3
- package/src/index.ts +1 -0
- package/src/locale/interface.ts +1 -0
- package/src/locale/lang/en_US.ts +1 -0
- package/src/locale/lang/ja_JP.ts +1 -0
- package/src/locale/lang/zh_CN.ts +1 -0
- package/src/locale/lang/zh_TW.ts +1 -0
- package/src/message/style/index.less +4 -4
- package/src/style/color.blue.css +254 -290
- package/src/style/color.crimson.css +434 -471
- package/src/style/color.css +736 -508
- package/src/style/color.dark.css +464 -501
- package/src/style/color.gemini.css +134 -0
- package/src/style/color.green.css +459 -495
- package/src/style/color.jam.css +463 -500
- package/src/style/color.navy.css +466 -503
- package/src/style/color.peach.css +464 -501
- package/src/style/color.pine.css +462 -500
- package/src/style/color.pitaya.css +465 -502
- package/src/style/color.pumpkin.css +464 -501
- package/src/style/color.ruby.css +466 -503
- package/src/style/size.css +144 -2
- package/src/version.ts +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import useLatest from "../../hooks/useLatest";
|
|
15
|
+
/** Floor for a dragged column when it declares no `minWidth` of its own. */
|
|
16
|
+
var DEFAULT_MIN_COLUMN_WIDTH = 40;
|
|
17
|
+
|
|
18
|
+
/** Width delta applied per arrow key press when a handle has focus. */
|
|
19
|
+
var KEYBOARD_STEP = 8;
|
|
20
|
+
var clampWidth = function clampWidth(width, column) {
|
|
21
|
+
var _column$minWidth;
|
|
22
|
+
var min = Math.max((_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : DEFAULT_MIN_COLUMN_WIDTH, 0);
|
|
23
|
+
var max = column.maxWidth;
|
|
24
|
+
if (width < min) return min;
|
|
25
|
+
if (max !== undefined && width > max) return max;
|
|
26
|
+
return Math.round(width);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pointer (and keyboard) driven column resizing.
|
|
31
|
+
*
|
|
32
|
+
* The table normally lets the browser distribute widths (`width: 100%` with an
|
|
33
|
+
* `auto` layout), which means writing a width onto one column would silently
|
|
34
|
+
* steal space from its neighbours. So the first resize interaction snapshots the
|
|
35
|
+
* rendered width of *every* column; from then on the table is fully px
|
|
36
|
+
* controlled and a drag only moves the column it grabbed.
|
|
37
|
+
*/
|
|
38
|
+
export default function useColumnResize(_ref) {
|
|
39
|
+
var tableRef = _ref.tableRef,
|
|
40
|
+
columnsRef = _ref.columnsRef,
|
|
41
|
+
onColumnResize = _ref.onColumnResize,
|
|
42
|
+
onColumnResizeEnd = _ref.onColumnResizeEnd;
|
|
43
|
+
var _React$useState = React.useState({}),
|
|
44
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
45
|
+
resizedWidths = _React$useState2[0],
|
|
46
|
+
setResizedWidths = _React$useState2[1];
|
|
47
|
+
var _React$useState3 = React.useState(null),
|
|
48
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
49
|
+
resizingKey = _React$useState4[0],
|
|
50
|
+
setResizingKey = _React$useState4[1];
|
|
51
|
+
|
|
52
|
+
// Callbacks are consumer supplied and usually re-created every render; reading
|
|
53
|
+
// them from a ref keeps `onResizeStart` stable.
|
|
54
|
+
var onColumnResizeRef = useLatest(onColumnResize);
|
|
55
|
+
var onColumnResizeEndRef = useLatest(onColumnResizeEnd);
|
|
56
|
+
var resizedWidthsRef = useLatest(resizedWidths);
|
|
57
|
+
var frameRef = React.useRef(0);
|
|
58
|
+
var teardownRef = React.useRef(null);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Read the rendered width of every column off the `<col>` elements. Returns
|
|
62
|
+
* null when the measurement cannot be trusted, in which case the interaction
|
|
63
|
+
* is abandoned rather than applying a partial snapshot (a partial snapshot
|
|
64
|
+
* would leave holes once the layout switches to `fixed`).
|
|
65
|
+
*/
|
|
66
|
+
var snapshotWidths = React.useCallback(function () {
|
|
67
|
+
var _tableRef$current;
|
|
68
|
+
var columns = columnsRef.current || [];
|
|
69
|
+
var colElements = (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.querySelectorAll(':scope > colgroup > col');
|
|
70
|
+
if (!colElements || colElements.length !== columns.length) return null;
|
|
71
|
+
if (!columns.length) return null;
|
|
72
|
+
var snapshot = {};
|
|
73
|
+
for (var index = 0; index < columns.length; index += 1) {
|
|
74
|
+
var _columns$index;
|
|
75
|
+
var key = (_columns$index = columns[index]) === null || _columns$index === void 0 ? void 0 : _columns$index.resizeKey;
|
|
76
|
+
var _width = Math.round(colElements[index].getBoundingClientRect().width);
|
|
77
|
+
if (!key || !Number.isFinite(_width) || _width <= 0) return null;
|
|
78
|
+
snapshot[key] = _width;
|
|
79
|
+
}
|
|
80
|
+
return snapshot;
|
|
81
|
+
}, [columnsRef, tableRef]);
|
|
82
|
+
var findColumn = React.useCallback(function (resizeKey) {
|
|
83
|
+
return (columnsRef.current || []).find(function (column) {
|
|
84
|
+
return column.resizeKey === resizeKey;
|
|
85
|
+
});
|
|
86
|
+
}, [columnsRef]);
|
|
87
|
+
var onResizeStart = React.useCallback(function (event, resizeKey) {
|
|
88
|
+
// Ignore secondary buttons, and never let the drag reach the sorter click
|
|
89
|
+
// handler or start a native text selection.
|
|
90
|
+
if (event.button !== 0) return;
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
event.stopPropagation();
|
|
93
|
+
var column = findColumn(resizeKey);
|
|
94
|
+
if (!column) return;
|
|
95
|
+
var snapshot = snapshotWidths();
|
|
96
|
+
if (!snapshot) return;
|
|
97
|
+
var startX = event.clientX;
|
|
98
|
+
var startWidth = snapshot[resizeKey];
|
|
99
|
+
var latestWidth = startWidth;
|
|
100
|
+
setResizingKey(resizeKey);
|
|
101
|
+
setResizedWidths(snapshot);
|
|
102
|
+
document.body.style.userSelect = 'none';
|
|
103
|
+
document.body.style.cursor = 'col-resize';
|
|
104
|
+
var applyWidth = function applyWidth(clientX) {
|
|
105
|
+
var _onColumnResizeRef$cu;
|
|
106
|
+
var next = clampWidth(startWidth + (clientX - startX), column);
|
|
107
|
+
if (next === latestWidth) return;
|
|
108
|
+
latestWidth = next;
|
|
109
|
+
setResizedWidths(function (current) {
|
|
110
|
+
return _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, resizeKey, next));
|
|
111
|
+
});
|
|
112
|
+
(_onColumnResizeRef$cu = onColumnResizeRef.current) === null || _onColumnResizeRef$cu === void 0 || _onColumnResizeRef$cu.call(onColumnResizeRef, next, column);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// pointermove fires far more often than the browser can paint, and every
|
|
116
|
+
// width change relayouts the whole table, so coalesce to one per frame.
|
|
117
|
+
var onPointerMove = function onPointerMove(moveEvent) {
|
|
118
|
+
var clientX = moveEvent.clientX;
|
|
119
|
+
if (frameRef.current) cancelAnimationFrame(frameRef.current);
|
|
120
|
+
frameRef.current = requestAnimationFrame(function () {
|
|
121
|
+
frameRef.current = 0;
|
|
122
|
+
applyWidth(clientX);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// Detaching listeners and restoring the document is split out from `stop`
|
|
127
|
+
// so that unmounting mid-drag can clean up without emitting a resize-end
|
|
128
|
+
// event or touching state on a gone component.
|
|
129
|
+
// Collected as closures so that `teardown` does not have to name the
|
|
130
|
+
// handlers it removes (`stop` is defined after it, and they are mutual).
|
|
131
|
+
var detachers = [];
|
|
132
|
+
var bind = function bind(type, handler) {
|
|
133
|
+
window.addEventListener(type, handler);
|
|
134
|
+
detachers.push(function () {
|
|
135
|
+
return window.removeEventListener(type, handler);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
var teardown = function teardown() {
|
|
139
|
+
if (frameRef.current) {
|
|
140
|
+
cancelAnimationFrame(frameRef.current);
|
|
141
|
+
frameRef.current = 0;
|
|
142
|
+
}
|
|
143
|
+
detachers.forEach(function (detach) {
|
|
144
|
+
return detach();
|
|
145
|
+
});
|
|
146
|
+
detachers.length = 0;
|
|
147
|
+
document.body.style.userSelect = '';
|
|
148
|
+
document.body.style.cursor = '';
|
|
149
|
+
teardownRef.current = null;
|
|
150
|
+
};
|
|
151
|
+
var stop = function stop() {
|
|
152
|
+
var _onColumnResizeEndRef;
|
|
153
|
+
teardown();
|
|
154
|
+
setResizingKey(null);
|
|
155
|
+
(_onColumnResizeEndRef = onColumnResizeEndRef.current) === null || _onColumnResizeEndRef === void 0 || _onColumnResizeEndRef.call(onColumnResizeEndRef, latestWidth, column);
|
|
156
|
+
};
|
|
157
|
+
teardownRef.current = teardown;
|
|
158
|
+
bind('pointermove', onPointerMove);
|
|
159
|
+
bind('pointerup', stop);
|
|
160
|
+
bind('pointercancel', stop);
|
|
161
|
+
}, [findColumn, snapshotWidths, onColumnResizeRef, onColumnResizeEndRef]);
|
|
162
|
+
|
|
163
|
+
/** Keyboard equivalent of a drag, so the handle is operable without a mouse. */
|
|
164
|
+
var onResizeStep = React.useCallback(function (resizeKey, direction) {
|
|
165
|
+
var _onColumnResizeRef$cu2, _onColumnResizeEndRef2;
|
|
166
|
+
var column = findColumn(resizeKey);
|
|
167
|
+
if (!column) return;
|
|
168
|
+
var base = resizedWidthsRef.current;
|
|
169
|
+
var snapshot = base[resizeKey] === undefined ? snapshotWidths() : base;
|
|
170
|
+
if (!snapshot) return;
|
|
171
|
+
var next = clampWidth(snapshot[resizeKey] + direction * KEYBOARD_STEP, column);
|
|
172
|
+
if (next === snapshot[resizeKey]) return;
|
|
173
|
+
setResizedWidths(_objectSpread(_objectSpread({}, snapshot), {}, _defineProperty({}, resizeKey, next)));
|
|
174
|
+
(_onColumnResizeRef$cu2 = onColumnResizeRef.current) === null || _onColumnResizeRef$cu2 === void 0 || _onColumnResizeRef$cu2.call(onColumnResizeRef, next, column);
|
|
175
|
+
(_onColumnResizeEndRef2 = onColumnResizeEndRef.current) === null || _onColumnResizeEndRef2 === void 0 || _onColumnResizeEndRef2.call(onColumnResizeEndRef, next, column);
|
|
176
|
+
}, [findColumn, snapshotWidths, resizedWidthsRef, onColumnResizeRef, onColumnResizeEndRef]);
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Forget the snapshot. Called when the column set changes: widths keyed to
|
|
180
|
+
* columns that no longer exist would under-report the total table width.
|
|
181
|
+
*/
|
|
182
|
+
var resetResizedWidths = React.useCallback(function () {
|
|
183
|
+
setResizedWidths(function (current) {
|
|
184
|
+
return Object.keys(current).length ? {} : current;
|
|
185
|
+
});
|
|
186
|
+
}, []);
|
|
187
|
+
|
|
188
|
+
// Unmounting mid-drag must not leave listeners or body styles behind.
|
|
189
|
+
React.useEffect(function () {
|
|
190
|
+
return function () {
|
|
191
|
+
var _teardownRef$current;
|
|
192
|
+
return (_teardownRef$current = teardownRef.current) === null || _teardownRef$current === void 0 ? void 0 : _teardownRef$current.call(teardownRef);
|
|
193
|
+
};
|
|
194
|
+
}, []);
|
|
195
|
+
|
|
196
|
+
// Not gated on any `enabled` flag: the state stays empty until something drags,
|
|
197
|
+
// and handles are only rendered for columns that opted in, so an unused Table
|
|
198
|
+
// pays nothing and a column-level `resizable` works with no table-level flag.
|
|
199
|
+
return {
|
|
200
|
+
resizedWidths: resizedWidths,
|
|
201
|
+
resizingKey: resizingKey,
|
|
202
|
+
onResizeStart: onResizeStart,
|
|
203
|
+
onResizeStep: onResizeStep,
|
|
204
|
+
resetResizedWidths: resetResizedWidths
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ColumnProps, ExpandableType, RowSelectionType, WrapedColumnProps } from '../interface';
|
|
3
|
-
export default function useColumns({ children, columns, rowSelection, expandable, measuredColumnWidths, }: {
|
|
3
|
+
export default function useColumns({ children, columns, rowSelection, expandable, measuredColumnWidths, resizable, resizedWidths, }: {
|
|
4
4
|
children?: React.ReactElement<ColumnProps> | React.ReactElement<ColumnProps>[];
|
|
5
5
|
columns: ColumnProps[];
|
|
6
6
|
rowSelection?: RowSelectionType;
|
|
7
7
|
expandable?: ExpandableType;
|
|
8
8
|
measuredColumnWidths?: number[];
|
|
9
|
+
resizable?: boolean;
|
|
10
|
+
resizedWidths?: Record<string, number>;
|
|
9
11
|
}): {
|
|
10
12
|
wrapedColumns: WrapedColumnProps[];
|
|
11
13
|
headerRows: import("../interface").HeaderCell[][];
|
|
@@ -6,7 +6,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import React, { useMemo } from 'react';
|
|
8
8
|
import deepClone from "../../utils/deepClone";
|
|
9
|
-
import { handleColumns } from "../util";
|
|
9
|
+
import { applyColumnResize, handleColumns } from "../util";
|
|
10
10
|
import { flattenLeafColumns, injectSelectionExpand, parseHeaderRows } from "../util/header";
|
|
11
11
|
var getColumnsFromChild = function getColumnsFromChild(childs) {
|
|
12
12
|
var cols = [];
|
|
@@ -22,7 +22,9 @@ export default function useColumns(_ref) {
|
|
|
22
22
|
columns = _ref.columns,
|
|
23
23
|
rowSelection = _ref.rowSelection,
|
|
24
24
|
expandable = _ref.expandable,
|
|
25
|
-
measuredColumnWidths = _ref.measuredColumnWidths
|
|
25
|
+
measuredColumnWidths = _ref.measuredColumnWidths,
|
|
26
|
+
resizable = _ref.resizable,
|
|
27
|
+
resizedWidths = _ref.resizedWidths;
|
|
26
28
|
var childColumns = useMemo(function () {
|
|
27
29
|
return children ? getColumnsFromChild(children) : null;
|
|
28
30
|
}, [children]);
|
|
@@ -34,13 +36,16 @@ export default function useColumns(_ref) {
|
|
|
34
36
|
var base = deepClone(childColumns || columns || []) || [];
|
|
35
37
|
var tree = injectSelectionExpand(base, rowSelection, expandable);
|
|
36
38
|
var leaves = flattenLeafColumns(tree);
|
|
37
|
-
|
|
39
|
+
// Resized widths are folded in before the fixed-column offsets are computed,
|
|
40
|
+
// so sticky positions follow a drag without any extra bookkeeping.
|
|
41
|
+
var resized = applyColumnResize(leaves, resizable, resizedWidths);
|
|
42
|
+
var wraped = handleColumns(resized, measuredColumnWidths);
|
|
38
43
|
var rows = parseHeaderRows(tree, wraped);
|
|
39
44
|
return {
|
|
40
45
|
wrapedColumns: wraped,
|
|
41
46
|
headerRows: rows
|
|
42
47
|
};
|
|
43
|
-
}, [childColumns, columns, rowSelection, expandable, measuredColumnWidths]),
|
|
48
|
+
}, [childColumns, columns, rowSelection, expandable, measuredColumnWidths, resizable, resizedWidths]),
|
|
44
49
|
wrapedColumns = _useMemo.wrapedColumns,
|
|
45
50
|
headerRows = _useMemo.headerRows;
|
|
46
51
|
return {
|
|
@@ -67,6 +67,18 @@ export interface HeadCellProps extends Omit<WrapedColumnProps, 'title'> {
|
|
|
67
67
|
};
|
|
68
68
|
onSort?: (dataIndex: string, sorter: any) => void;
|
|
69
69
|
onInternalFilter?: (dataIndex: string, value: string) => void;
|
|
70
|
+
/**
|
|
71
|
+
* `resizeKey` of the column currently being dragged, if any
|
|
72
|
+
*/
|
|
73
|
+
resizingKey?: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* Begin a pointer driven column resize. Injected by Table when resizing is on.
|
|
76
|
+
*/
|
|
77
|
+
onResizeStart?: (event: React.PointerEvent<HTMLElement>, resizeKey: string) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Nudge a column width by `delta` px, for keyboard driven resizing
|
|
80
|
+
*/
|
|
81
|
+
onResizeStep?: (resizeKey: string, delta: number) => void;
|
|
70
82
|
/**
|
|
71
83
|
* Horizontal span, used for grouped header cells
|
|
72
84
|
*/
|
|
@@ -227,6 +239,20 @@ export interface ColumnProps {
|
|
|
227
239
|
* Set width
|
|
228
240
|
*/
|
|
229
241
|
width?: number | string;
|
|
242
|
+
/**
|
|
243
|
+
* Whether this column can be resized by dragging the right edge of its header
|
|
244
|
+
* cell. Falls back to the table level `resizable` when not set.
|
|
245
|
+
*/
|
|
246
|
+
resizable?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Lower bound (in px) applied while resizing this column
|
|
249
|
+
* @default 40
|
|
250
|
+
*/
|
|
251
|
+
minWidth?: number;
|
|
252
|
+
/**
|
|
253
|
+
* Upper bound (in px) applied while resizing this column
|
|
254
|
+
*/
|
|
255
|
+
maxWidth?: number;
|
|
230
256
|
/**
|
|
231
257
|
* Set header display text
|
|
232
258
|
*/
|
|
@@ -261,6 +287,12 @@ export interface WrapedColumnProps extends ColumnProps, ExpandableType, Omit<Row
|
|
|
261
287
|
* Whether this is the first column fixed to the right
|
|
262
288
|
*/
|
|
263
289
|
isFixedRightFirst?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Stable identity of this leaf column, used as the key of the resized width
|
|
292
|
+
* map. Only assigned to leaf columns, so its presence also marks a column as
|
|
293
|
+
* a valid resize target (group header cells never carry one).
|
|
294
|
+
*/
|
|
295
|
+
resizeKey?: string;
|
|
264
296
|
}
|
|
265
297
|
/**
|
|
266
298
|
* A header cell resolved from the column tree, with computed span info for multi-level headers.
|
|
@@ -554,6 +586,23 @@ export interface TableProps extends FooterProps, Omit<HeaderProps, 'pageData'>,
|
|
|
554
586
|
* Set table layout
|
|
555
587
|
*/
|
|
556
588
|
tableLayout?: 'auto' | 'fixed';
|
|
589
|
+
/**
|
|
590
|
+
* Whether columns can be resized by dragging the right edge of their header
|
|
591
|
+
* cell. Individual columns can opt out with `column.resizable: false`.
|
|
592
|
+
*
|
|
593
|
+
* The first drag snapshots the rendered width of every column and switches the
|
|
594
|
+
* table to a px controlled `table-layout: fixed`, so column widths stay exactly
|
|
595
|
+
* where they are dragged instead of being redistributed by the browser.
|
|
596
|
+
*/
|
|
597
|
+
resizable?: boolean;
|
|
598
|
+
/**
|
|
599
|
+
* Fired on every width change while a column is being dragged
|
|
600
|
+
*/
|
|
601
|
+
onColumnResize?: (width: number, column: WrapedColumnProps) => void;
|
|
602
|
+
/**
|
|
603
|
+
* Fired once when a column resize interaction finishes
|
|
604
|
+
*/
|
|
605
|
+
onColumnResizeEnd?: (width: number, column: WrapedColumnProps) => void;
|
|
557
606
|
/**
|
|
558
607
|
* Whether to enable virtual list
|
|
559
608
|
*/
|
|
@@ -71,6 +71,48 @@
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// Sits inside the header cell's right padding so it never overlaps the sorter
|
|
75
|
+
// or filter controls, which are laid out against the content edge.
|
|
76
|
+
&-resize-handle {
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 0;
|
|
79
|
+
right: 0;
|
|
80
|
+
z-index: 2;
|
|
81
|
+
width: var(--yee-table-resize-handle-width);
|
|
82
|
+
height: 100%;
|
|
83
|
+
cursor: col-resize;
|
|
84
|
+
background-color: transparent;
|
|
85
|
+
touch-action: none;
|
|
86
|
+
user-select: none;
|
|
87
|
+
|
|
88
|
+
&::after {
|
|
89
|
+
position: absolute;
|
|
90
|
+
content: '';
|
|
91
|
+
top: 25%;
|
|
92
|
+
right: calc(var(--yee-table-resize-handle-width) / 2 - 1px);
|
|
93
|
+
width: 2px;
|
|
94
|
+
height: 50%;
|
|
95
|
+
background-color: transparent;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&:hover::after,
|
|
99
|
+
&:focus-visible::after,
|
|
100
|
+
&-active::after {
|
|
101
|
+
background-color: var(--yee-color-primary);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&:focus-visible {
|
|
105
|
+
outline: none;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// While dragging, the pointer leaves the handle constantly; keep the cursor and
|
|
110
|
+
// the selection lock consistent across the whole table.
|
|
111
|
+
&-resizing {
|
|
112
|
+
cursor: col-resize;
|
|
113
|
+
user-select: none;
|
|
114
|
+
}
|
|
115
|
+
|
|
74
116
|
&-filter {
|
|
75
117
|
max-height: var(--yee-table-filter-popup-height);
|
|
76
118
|
background-color: var(--yee-table-filter-list-bg-color);
|
|
@@ -158,7 +200,7 @@
|
|
|
158
200
|
margin-left: 4px;
|
|
159
201
|
|
|
160
202
|
.active {
|
|
161
|
-
color: var(--yee-primary
|
|
203
|
+
color: var(--yee-color-primary);
|
|
162
204
|
}
|
|
163
205
|
}
|
|
164
206
|
|
package/dist/esm/Table/table.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["prefixCls", "className", "style", "classNames", "styles", "components", "rowKey", "bordered", "tableLayout", "loading", "showHeader", "pagination", "columns", "dataSource", "size", "summary", "scroll", "header", "download", "footer", "children", "expandable", "rowSelection", "locale", "onChange"];
|
|
2
|
+
var _excluded = ["prefixCls", "className", "style", "classNames", "styles", "components", "rowKey", "bordered", "tableLayout", "resizable", "onColumnResize", "onColumnResizeEnd", "loading", "showHeader", "pagination", "columns", "dataSource", "size", "summary", "scroll", "header", "download", "footer", "children", "expandable", "rowSelection", "locale", "onChange"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
8
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
9
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
10
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -20,6 +21,7 @@ import Spin from "../Spin";
|
|
|
20
21
|
import ColGroup from "./col-group";
|
|
21
22
|
import Footer from "./footer";
|
|
22
23
|
import Header from "./header";
|
|
24
|
+
import useColumnResize from "./hooks/useColumnResize";
|
|
23
25
|
import useColumns from "./hooks/useColumns";
|
|
24
26
|
import useExpand from "./hooks/useExpand";
|
|
25
27
|
import useSelection from "./hooks/useSelection";
|
|
@@ -27,7 +29,6 @@ import TBody from "./tbody";
|
|
|
27
29
|
import TFooter from "./tfooter";
|
|
28
30
|
import THeader from "./theader";
|
|
29
31
|
import { GlobalContext } from "../Config-Provider";
|
|
30
|
-
import useLatest from "../hooks/useLatest";
|
|
31
32
|
import mergeContextToProps from "../utils/mergeContextToProps";
|
|
32
33
|
import omit from "../utils/omit";
|
|
33
34
|
import { pickDataAttrs } from "../utils/types";
|
|
@@ -51,6 +52,9 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
51
52
|
rowKey = _props$rowKey === void 0 ? 'key' : _props$rowKey,
|
|
52
53
|
bordered = props.bordered,
|
|
53
54
|
tableLayout = props.tableLayout,
|
|
55
|
+
resizable = props.resizable,
|
|
56
|
+
onColumnResize = props.onColumnResize,
|
|
57
|
+
onColumnResizeEnd = props.onColumnResizeEnd,
|
|
54
58
|
_props$loading = props.loading,
|
|
55
59
|
loading = _props$loading === void 0 ? false : _props$loading,
|
|
56
60
|
_props$showHeader = props.showHeader,
|
|
@@ -78,6 +82,30 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
78
82
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
79
83
|
measuredColumnWidths = _React$useState2[0],
|
|
80
84
|
setMeasuredColumnWidths = _React$useState2[1];
|
|
85
|
+
var contentRef = useRef(null);
|
|
86
|
+
var tableRef = useRef(null);
|
|
87
|
+
|
|
88
|
+
// Filled in right after `useColumns` below. The resize hook needs the latest
|
|
89
|
+
// leaf columns, but `wrapedColumns` is itself derived from the resized widths,
|
|
90
|
+
// so depending on it directly would rebuild the drag handlers mid-drag.
|
|
91
|
+
var wrapedColumnsRef = useRef([]);
|
|
92
|
+
var _useColumnResize = useColumnResize({
|
|
93
|
+
tableRef: tableRef,
|
|
94
|
+
columnsRef: wrapedColumnsRef,
|
|
95
|
+
onColumnResize: onColumnResize,
|
|
96
|
+
onColumnResizeEnd: onColumnResizeEnd
|
|
97
|
+
}),
|
|
98
|
+
resizedWidths = _useColumnResize.resizedWidths,
|
|
99
|
+
resizingKey = _useColumnResize.resizingKey,
|
|
100
|
+
onResizeStart = _useColumnResize.onResizeStart,
|
|
101
|
+
onResizeStep = _useColumnResize.onResizeStep,
|
|
102
|
+
resetResizedWidths = _useColumnResize.resetResizedWidths;
|
|
103
|
+
|
|
104
|
+
// Once a snapshot exists, every column carries an explicit px width and the
|
|
105
|
+
// table switches to `table-layout: fixed`, which makes those declared widths
|
|
106
|
+
// authoritative. The measured widths lag one frame behind a drag, so they must
|
|
107
|
+
// stop feeding the fixed-column offsets while a snapshot is in play.
|
|
108
|
+
var hasResizeSnapshot = Object.keys(resizedWidths).length > 0;
|
|
81
109
|
var getRowKey = React.useCallback(function (record) {
|
|
82
110
|
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : rowKey;
|
|
83
111
|
return typeof key === 'function' ? key(record) : record[key];
|
|
@@ -92,10 +120,48 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
92
120
|
columns: propColumns,
|
|
93
121
|
expandable: expandable,
|
|
94
122
|
rowSelection: rowSelection,
|
|
95
|
-
measuredColumnWidths: measuredColumnWidths
|
|
123
|
+
measuredColumnWidths: hasResizeSnapshot ? undefined : measuredColumnWidths,
|
|
124
|
+
resizable: resizable,
|
|
125
|
+
resizedWidths: resizedWidths
|
|
96
126
|
}),
|
|
97
127
|
wrapedColumns = _useColumns.wrapedColumns,
|
|
98
128
|
headerRows = _useColumns.headerRows;
|
|
129
|
+
wrapedColumnsRef.current = wrapedColumns;
|
|
130
|
+
|
|
131
|
+
// Total width of the px controlled layout. Deliberately `undefined` unless the
|
|
132
|
+
// snapshot covers every single column: a partial snapshot would leave a hole in
|
|
133
|
+
// the layout, so it is safer to fall back to the browser's own distribution.
|
|
134
|
+
var resizeTotalWidth = useMemo(function () {
|
|
135
|
+
if (!wrapedColumns.length) return undefined;
|
|
136
|
+
var total = 0;
|
|
137
|
+
var _iterator = _createForOfIteratorHelper(wrapedColumns),
|
|
138
|
+
_step;
|
|
139
|
+
try {
|
|
140
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
141
|
+
var column = _step.value;
|
|
142
|
+
var width = column.resizeKey ? resizedWidths[column.resizeKey] : undefined;
|
|
143
|
+
if (!width || !Number.isFinite(width)) return undefined;
|
|
144
|
+
total += width;
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
_iterator.e(err);
|
|
148
|
+
} finally {
|
|
149
|
+
_iterator.f();
|
|
150
|
+
}
|
|
151
|
+
return total;
|
|
152
|
+
}, [wrapedColumns, resizedWidths]);
|
|
153
|
+
var resizeActive = resizeTotalWidth !== undefined;
|
|
154
|
+
|
|
155
|
+
// Identity of the column set, ignoring widths. When it changes the snapshot is
|
|
156
|
+
// stale (a new column would have no width of its own), so it gets dropped.
|
|
157
|
+
var resizeKeysSignature = useMemo(function () {
|
|
158
|
+
return wrapedColumns.map(function (column) {
|
|
159
|
+
return column.resizeKey;
|
|
160
|
+
}).join('|');
|
|
161
|
+
}, [wrapedColumns]);
|
|
162
|
+
useEffect(function () {
|
|
163
|
+
resetResizedWidths();
|
|
164
|
+
}, [resizeKeysSignature, resetResizedWidths]);
|
|
99
165
|
|
|
100
166
|
// Filter
|
|
101
167
|
var _useFilter = useFilter({
|
|
@@ -171,8 +237,6 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
171
237
|
|
|
172
238
|
// Track filter changes to emit onChange after filtered data is recalculated
|
|
173
239
|
var prevFilterRecordsRef = useRef(filterRecords);
|
|
174
|
-
var contentRef = useRef(null);
|
|
175
|
-
var tableRef = useRef(null);
|
|
176
240
|
var _React$useState3 = React.useState({
|
|
177
241
|
left: false,
|
|
178
242
|
right: false
|
|
@@ -203,11 +267,10 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
203
267
|
}).join('|');
|
|
204
268
|
}, [wrapedColumns]);
|
|
205
269
|
|
|
206
|
-
//
|
|
207
|
-
// `wrapedColumns` is derived from `measuredColumnWidths`, so depending
|
|
208
|
-
// directly would recreate the callback (and the ResizeObserver) on every
|
|
270
|
+
// `wrapedColumnsRef` (assigned during render, above) keeps the measure callback
|
|
271
|
+
// stable: `wrapedColumns` is derived from `measuredColumnWidths`, so depending
|
|
272
|
+
// on it directly would recreate the callback (and the ResizeObserver) on every
|
|
209
273
|
// measurement.
|
|
210
|
-
var wrapedColumnsRef = useLatest(wrapedColumns);
|
|
211
274
|
var updateMeasuredColumnWidths = React.useCallback(function () {
|
|
212
275
|
var _tableRef$current;
|
|
213
276
|
var columns = wrapedColumnsRef.current;
|
|
@@ -302,7 +365,10 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
302
365
|
sorters: sorters,
|
|
303
366
|
onSort: handleSort,
|
|
304
367
|
onCheckAll: onCheckAll,
|
|
305
|
-
onInternalFilter: onFilterInternal
|
|
368
|
+
onInternalFilter: onFilterInternal,
|
|
369
|
+
resizingKey: resizingKey,
|
|
370
|
+
onResizeStart: onResizeStart,
|
|
371
|
+
onResizeStep: onResizeStep
|
|
306
372
|
}));
|
|
307
373
|
};
|
|
308
374
|
var renderTBody = function renderTBody() {
|
|
@@ -328,8 +394,12 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
328
394
|
var renderTable = function renderTable() {
|
|
329
395
|
var tableProps = {
|
|
330
396
|
style: _objectSpread(_objectSpread({}, styles === null || styles === void 0 ? void 0 : styles.table), {}, {
|
|
331
|
-
|
|
332
|
-
|
|
397
|
+
// An explicit total width replaces both `width: 100%` and `scroll.x`:
|
|
398
|
+
// either of those would let the browser stretch the table and redistribute
|
|
399
|
+
// the extra space across the columns, undoing the drag.
|
|
400
|
+
minWidth: resizeActive ? undefined : scroll === null || scroll === void 0 ? void 0 : scroll.x,
|
|
401
|
+
width: resizeTotalWidth,
|
|
402
|
+
tableLayout: resizeActive ? 'fixed' : pageData !== null && pageData !== void 0 && pageData.length ? tableLayout : undefined
|
|
333
403
|
}),
|
|
334
404
|
className: clsx(_defineProperty({}, "".concat(prefixCls, "-bordered"), bordered), classNames === null || classNames === void 0 ? void 0 : classNames.table)
|
|
335
405
|
};
|
|
@@ -369,7 +439,7 @@ var Table = /*#__PURE__*/React.forwardRef(function (baseprops, ref) {
|
|
|
369
439
|
});
|
|
370
440
|
};
|
|
371
441
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
372
|
-
className: clsx("".concat(prefixCls, "-box"), className),
|
|
442
|
+
className: clsx("".concat(prefixCls, "-box"), _defineProperty({}, "".concat(prefixCls, "-resizing"), !!resizingKey), className),
|
|
373
443
|
style: style,
|
|
374
444
|
ref: ref
|
|
375
445
|
}, dataAttrs), /*#__PURE__*/React.createElement(Spin, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["fixed", "isFixedLeftLast", "isFixedRightFirst", "align", "title", "dataIndex", "sorter", "filter", "sorters", "className", "styles", "classNames", "showSorterTooltip", "tableActionBarShowOnHover", "internalFilters", "style", "width", "colSpan", "rowSpan", "onHeaderCell", "onSort", "onInternalFilter"];
|
|
1
|
+
var _excluded = ["fixed", "isFixedLeftLast", "isFixedRightFirst", "align", "title", "dataIndex", "sorter", "filter", "sorters", "className", "styles", "classNames", "showSorterTooltip", "tableActionBarShowOnHover", "internalFilters", "style", "width", "colSpan", "rowSpan", "resizable", "resizeKey", "resizingKey", "onHeaderCell", "onSort", "onInternalFilter", "onResizeStart", "onResizeStep"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -37,9 +37,14 @@ var HeadCell = function HeadCell(props) {
|
|
|
37
37
|
width = props.width,
|
|
38
38
|
colSpan = props.colSpan,
|
|
39
39
|
rowSpan = props.rowSpan,
|
|
40
|
+
resizable = props.resizable,
|
|
41
|
+
resizeKey = props.resizeKey,
|
|
42
|
+
resizingKey = props.resizingKey,
|
|
40
43
|
onHeaderCell = props.onHeaderCell,
|
|
41
44
|
onSort = props.onSort,
|
|
42
45
|
onInternalFilter = props.onInternalFilter,
|
|
46
|
+
onResizeStart = props.onResizeStart,
|
|
47
|
+
onResizeStep = props.onResizeStep,
|
|
43
48
|
rest = _objectWithoutProperties(props, _excluded);
|
|
44
49
|
var _useContext = useContext(TableCtx),
|
|
45
50
|
prefixCls = _useContext.prefixCls;
|
|
@@ -125,6 +130,36 @@ var HeadCell = function HeadCell(props) {
|
|
|
125
130
|
}, renderTitle(), renderFilter());
|
|
126
131
|
};
|
|
127
132
|
var cls = clsx("".concat(prefixCls, "-cell"), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-cell-fixed-").concat(fixed), fixed), "".concat(prefixCls, "-cell-fixed-").concat(fixed, "-last"), isFixedLeftLast), "".concat(prefixCls, "-cell-fixed-").concat(fixed, "-first"), isFixedRightFirst), "".concat(prefixCls, "-cell-operate-hover"), tableActionBarShowOnHover), className);
|
|
133
|
+
|
|
134
|
+
// `resizeKey` is only stamped onto leaf columns, so it doubles as the guard that
|
|
135
|
+
// keeps handles off group header cells (whose width is the sum of their leaves).
|
|
136
|
+
var showResizeHandle = !!(resizable && resizeKey && onResizeStart);
|
|
137
|
+
var isResizing = !!resizeKey && resizingKey === resizeKey;
|
|
138
|
+
var renderResizeHandle = function renderResizeHandle() {
|
|
139
|
+
if (!showResizeHandle) return null;
|
|
140
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
141
|
+
role: "separator",
|
|
142
|
+
"aria-orientation": "vertical",
|
|
143
|
+
"aria-label": tableLocale.resizeColumn || 'Drag to resize column',
|
|
144
|
+
tabIndex: 0,
|
|
145
|
+
className: clsx("".concat(prefixCls, "-resize-handle"), _defineProperty({}, "".concat(prefixCls, "-resize-handle-active"), isResizing)),
|
|
146
|
+
onPointerDown: function onPointerDown(event) {
|
|
147
|
+
return onResizeStart === null || onResizeStart === void 0 ? void 0 : onResizeStart(event, resizeKey);
|
|
148
|
+
}
|
|
149
|
+
// The whole title area is a sort trigger, and a resize drag ends with a
|
|
150
|
+
// click on top of it; swallow it so dragging never toggles the sorter.
|
|
151
|
+
,
|
|
152
|
+
onClick: function onClick(event) {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
event.stopPropagation();
|
|
155
|
+
},
|
|
156
|
+
onKeyDown: function onKeyDown(event) {
|
|
157
|
+
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
onResizeStep === null || onResizeStep === void 0 || onResizeStep(resizeKey, event.key === 'ArrowLeft' ? -1 : 1);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
128
163
|
var getThProps = function getThProps() {
|
|
129
164
|
var styles = _objectSpread(_objectSpread({}, style), {}, {
|
|
130
165
|
width: width,
|
|
@@ -143,9 +178,9 @@ var HeadCell = function HeadCell(props) {
|
|
|
143
178
|
var thProps = getThProps();
|
|
144
179
|
var renderCell = function renderCell() {
|
|
145
180
|
if (!filter && !sorter) {
|
|
146
|
-
return /*#__PURE__*/React.createElement("th", thProps, title);
|
|
181
|
+
return /*#__PURE__*/React.createElement("th", thProps, title, renderResizeHandle());
|
|
147
182
|
}
|
|
148
|
-
return /*#__PURE__*/React.createElement("th", thProps, renderCellWithAction());
|
|
183
|
+
return /*#__PURE__*/React.createElement("th", thProps, renderCellWithAction(), renderResizeHandle());
|
|
149
184
|
};
|
|
150
185
|
var cell = renderCell();
|
|
151
186
|
return cell;
|