@jetbrains/ring-ui-built 8.0.0-beta.13 → 8.0.0-beta.14
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/components/_helpers/table.js +1 -1
- package/components/column-resize/column-group.js +69 -0
- package/components/column-resize/column-resize-drag.js +147 -0
- package/components/column-resize/column-resize-handle.js +86 -0
- package/components/column-resize/column-sizing-context.js +200 -0
- package/components/internal/column-indicator-vertical-span.js +23 -0
- package/components/internal/drag-auto-scroll.js +118 -0
- package/components/internal/reorder-handle.js +198 -210
- package/components/internal/table-header.js +152 -113
- package/components/style.css +1 -1
- package/components/table/default-item-renderer.js +6 -4
- package/components/table/internal/column-indicator-vertical-span.d.ts +8 -0
- package/components/table/internal/column-resize/column-group.d.ts +8 -0
- package/components/table/internal/column-resize/column-resize-drag.d.ts +27 -0
- package/components/table/internal/column-resize/column-resize-handle.d.ts +5 -0
- package/components/table/internal/column-resize/column-sizing-context.d.ts +27 -0
- package/components/table/internal/drag-auto-scroll.d.ts +18 -0
- package/components/table/item-virtualization.d.ts +2 -1
- package/components/table/table-const.d.ts +6 -0
- package/components/table/table-const.js +7 -1
- package/components/table/table-primitives.js +2 -0
- package/components/table/table-props.d.ts +39 -0
- package/components/table/table.d.ts +8 -0
- package/components/table/table.js +239 -165
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var styles = {"headerCell":"ring-table-headerCell","columnReorderHandleMirror":"ring-table-columnReorderHandleMirror","columnReorderHandle":"ring-table-columnReorderHandle","table":"ring-table-table","
|
|
1
|
+
var styles = {"headerCell":"ring-table-headerCell","columnReorderHandleMirror":"ring-table-columnReorderHandleMirror","columnReorderHandle":"ring-table-columnReorderHandle","table":"ring-table-table","fixedLayout":"ring-table-fixedLayout","cell":"ring-table-cell","sortAndHeader":"ring-table-sortAndHeader","rightButtons":"ring-table-rightButtons","columnResizeHandle":"ring-table-columnResizeHandle","theadColumnEditing":"ring-table-theadColumnEditing","columnResizeIndicator":"ring-table-columnResizeIndicator","resizableHeaderCell":"ring-table-resizableHeaderCell","stickyHeader":"ring-table-stickyHeader","reorderAnimationInitial":"ring-table-reorderAnimationInitial","reorderAnimationFadeOut":"ring-table-reorderAnimationFadeOut","headerCellInnerWrapper":"ring-table-headerCellInnerWrapper","tableButton":"ring-table-tableButton","deleteColumnButton":"ring-table-deleteColumnButton","itemReorderHandle":"ring-table-itemReorderHandle","editColumnsButton":"ring-table-editColumnsButton","dragFrame":"ring-table-dragFrame","insertionIndicator":"ring-table-insertionIndicator","spacerRow":"ring-table-spacerRow","spacerCell":"ring-table-spacerCell","row":"ring-table-row","clickableRow":"ring-table-clickableRow","selectedRow":"ring-table-selectedRow"};
|
|
2
2
|
|
|
3
3
|
export { styles as s };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { c } from 'react/compiler-runtime';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sets the column widths. In fixed layout, header and body cells follow them.
|
|
6
|
+
*/
|
|
7
|
+
function ColumnGroup(t0) {
|
|
8
|
+
const $ = c(11);
|
|
9
|
+
if ($[0] !== "373c0340ef06cfc859ce14446d651c19d65a3cfee64152dac1a4c3f84c47e38b") {
|
|
10
|
+
for (let $i = 0; $i < 11; $i += 1) {
|
|
11
|
+
$[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
12
|
+
}
|
|
13
|
+
$[0] = "373c0340ef06cfc859ce14446d651c19d65a3cfee64152dac1a4c3f84c47e38b";
|
|
14
|
+
}
|
|
15
|
+
const {
|
|
16
|
+
columns,
|
|
17
|
+
widths
|
|
18
|
+
} = t0;
|
|
19
|
+
let t1;
|
|
20
|
+
if ($[1] !== columns || $[2] !== widths) {
|
|
21
|
+
let t2;
|
|
22
|
+
if ($[4] !== widths) {
|
|
23
|
+
t2 = (column, index) => /*#__PURE__*/jsx("col", {
|
|
24
|
+
style: {
|
|
25
|
+
width: widths[index]
|
|
26
|
+
}
|
|
27
|
+
}, column.key);
|
|
28
|
+
$[4] = widths;
|
|
29
|
+
$[5] = t2;
|
|
30
|
+
} else {
|
|
31
|
+
t2 = $[5];
|
|
32
|
+
}
|
|
33
|
+
t1 = columns.map(t2);
|
|
34
|
+
$[1] = columns;
|
|
35
|
+
$[2] = widths;
|
|
36
|
+
$[3] = t1;
|
|
37
|
+
} else {
|
|
38
|
+
t1 = $[3];
|
|
39
|
+
}
|
|
40
|
+
let t2;
|
|
41
|
+
if ($[6] !== columns) {
|
|
42
|
+
t2 = columns.some(_temp) && /*#__PURE__*/jsx("col", {
|
|
43
|
+
style: {
|
|
44
|
+
width: 0
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
$[6] = columns;
|
|
48
|
+
$[7] = t2;
|
|
49
|
+
} else {
|
|
50
|
+
t2 = $[7];
|
|
51
|
+
}
|
|
52
|
+
let t3;
|
|
53
|
+
if ($[8] !== t1 || $[9] !== t2) {
|
|
54
|
+
t3 = /*#__PURE__*/jsxs("colgroup", {
|
|
55
|
+
children: [t1, t2]
|
|
56
|
+
});
|
|
57
|
+
$[8] = t1;
|
|
58
|
+
$[9] = t2;
|
|
59
|
+
$[10] = t3;
|
|
60
|
+
} else {
|
|
61
|
+
t3 = $[10];
|
|
62
|
+
}
|
|
63
|
+
return t3;
|
|
64
|
+
}
|
|
65
|
+
function _temp(column_0) {
|
|
66
|
+
return column_0.resizable;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { ColumnGroup };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { getColumnIndicatorVerticalSpan } from '../internal/column-indicator-vertical-span.js';
|
|
2
|
+
import { s as styles } from '../_helpers/table.js';
|
|
3
|
+
|
|
4
|
+
const defaultMinColumnWidth = 40;
|
|
5
|
+
/**
|
|
6
|
+
* Lets the user resize a column by dragging its handle.
|
|
7
|
+
*
|
|
8
|
+
* The width is previewed by writing directly to the `<col>` elements, without
|
|
9
|
+
* rendering. On release, the DOM is restored and `onCommit` is called, so that
|
|
10
|
+
* React renders the new width. Escape, pointer cancellation, and lost pointer
|
|
11
|
+
* capture cancel the drag.
|
|
12
|
+
*
|
|
13
|
+
* Everything is captured when the drag starts, so re-renders don't affect it.
|
|
14
|
+
* Returns a function that cancels the drag.
|
|
15
|
+
*/
|
|
16
|
+
function startColumnResizeDrag({
|
|
17
|
+
handle,
|
|
18
|
+
pointerId,
|
|
19
|
+
clientX: startClientX,
|
|
20
|
+
columnIndex,
|
|
21
|
+
startWidths,
|
|
22
|
+
minWidth: columnMinWidth = defaultMinColumnWidth,
|
|
23
|
+
maxWidth: columnMaxWidth = Infinity,
|
|
24
|
+
onCommit,
|
|
25
|
+
onEnd
|
|
26
|
+
}) {
|
|
27
|
+
const elements = findDragElements(handle, columnIndex);
|
|
28
|
+
if (!elements) {
|
|
29
|
+
onEnd();
|
|
30
|
+
return () => {};
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
th,
|
|
34
|
+
table,
|
|
35
|
+
column,
|
|
36
|
+
filler
|
|
37
|
+
} = elements;
|
|
38
|
+
const startWidth = startWidths[columnIndex];
|
|
39
|
+
const startTotalWidth = startWidths.reduce((sum, width) => sum + width, 0);
|
|
40
|
+
// The bounds never make the column jump: a column that is already outside of them can only be resized towards them
|
|
41
|
+
const minWidth = Math.min(columnMinWidth, startWidth);
|
|
42
|
+
const maxWidth = Math.max(columnMaxWidth, startWidth);
|
|
43
|
+
// Where the user grabbed the handle, relative to the column edge
|
|
44
|
+
const grabOffset = startClientX - th.getBoundingClientRect().right;
|
|
45
|
+
let width = startWidth;
|
|
46
|
+
let lastClientX = startClientX;
|
|
47
|
+
const indicator = document.createElement('div');
|
|
48
|
+
indicator.className = styles.columnResizeIndicator;
|
|
49
|
+
document.body.appendChild(indicator);
|
|
50
|
+
const previousBodyCursor = document.body.style.cursor;
|
|
51
|
+
const previousBodyUserSelect = document.body.style.userSelect;
|
|
52
|
+
document.body.style.cursor = 'col-resize';
|
|
53
|
+
document.body.style.userSelect = 'none';
|
|
54
|
+
function setDomWidths(columnWidth, fillerWidth) {
|
|
55
|
+
column.style.width = `${columnWidth}px`;
|
|
56
|
+
filler.style.width = `${fillerWidth}px`;
|
|
57
|
+
table.style.width = `${startTotalWidth - startWidth + columnWidth + fillerWidth}px`;
|
|
58
|
+
}
|
|
59
|
+
function positionIndicator(columnRight) {
|
|
60
|
+
const span = getColumnIndicatorVerticalSpan(th);
|
|
61
|
+
if (span) {
|
|
62
|
+
indicator.style.top = `${span.top}px`;
|
|
63
|
+
indicator.style.height = span.height;
|
|
64
|
+
}
|
|
65
|
+
indicator.style.left = `${columnRight - 1}px`;
|
|
66
|
+
}
|
|
67
|
+
// Uses the column's current position rather than the pointer delta,
|
|
68
|
+
// so the edge stays under the pointer when the table scrolls mid-drag.
|
|
69
|
+
function update(clientX) {
|
|
70
|
+
lastClientX = clientX;
|
|
71
|
+
const {
|
|
72
|
+
left
|
|
73
|
+
} = th.getBoundingClientRect();
|
|
74
|
+
width = Math.round(Math.min(maxWidth, Math.max(minWidth, clientX - grabOffset - left)));
|
|
75
|
+
setDomWidths(width, Math.max(0, startWidth - width));
|
|
76
|
+
positionIndicator(left + width);
|
|
77
|
+
}
|
|
78
|
+
function end(commit) {
|
|
79
|
+
handle.removeEventListener('pointermove', handlePointerMove);
|
|
80
|
+
handle.removeEventListener('pointerup', handlePointerUp);
|
|
81
|
+
handle.removeEventListener('pointercancel', cancel);
|
|
82
|
+
handle.removeEventListener('lostpointercapture', cancel);
|
|
83
|
+
window.removeEventListener('keydown', handleKeyDown, {
|
|
84
|
+
capture: true
|
|
85
|
+
});
|
|
86
|
+
document.removeEventListener('scroll', handleScroll, {
|
|
87
|
+
capture: true
|
|
88
|
+
});
|
|
89
|
+
if (handle.hasPointerCapture(pointerId)) handle.releasePointerCapture(pointerId);
|
|
90
|
+
indicator.remove();
|
|
91
|
+
document.body.style.cursor = previousBodyCursor;
|
|
92
|
+
document.body.style.userSelect = previousBodyUserSelect;
|
|
93
|
+
setDomWidths(startWidth, 0);
|
|
94
|
+
if (commit) onCommit(width);
|
|
95
|
+
onEnd();
|
|
96
|
+
}
|
|
97
|
+
function cancel() {
|
|
98
|
+
end(false);
|
|
99
|
+
}
|
|
100
|
+
function handlePointerMove(e) {
|
|
101
|
+
if (e.pointerId === pointerId) update(e.clientX);
|
|
102
|
+
}
|
|
103
|
+
function handlePointerUp(e) {
|
|
104
|
+
if (e.pointerId === pointerId) end(true);
|
|
105
|
+
}
|
|
106
|
+
function handleKeyDown(e) {
|
|
107
|
+
if (e.key !== 'Escape') return;
|
|
108
|
+
// Capture phase on `window`, so that e.g. a surrounding dialog doesn't close
|
|
109
|
+
e.stopPropagation();
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
cancel();
|
|
112
|
+
}
|
|
113
|
+
function handleScroll() {
|
|
114
|
+
update(lastClientX);
|
|
115
|
+
}
|
|
116
|
+
handle.setPointerCapture(pointerId);
|
|
117
|
+
handle.addEventListener('pointermove', handlePointerMove);
|
|
118
|
+
handle.addEventListener('pointerup', handlePointerUp);
|
|
119
|
+
handle.addEventListener('pointercancel', cancel);
|
|
120
|
+
handle.addEventListener('lostpointercapture', cancel);
|
|
121
|
+
window.addEventListener('keydown', handleKeyDown, {
|
|
122
|
+
capture: true
|
|
123
|
+
});
|
|
124
|
+
document.addEventListener('scroll', handleScroll, {
|
|
125
|
+
capture: true,
|
|
126
|
+
passive: true
|
|
127
|
+
});
|
|
128
|
+
positionIndicator(th.getBoundingClientRect().right);
|
|
129
|
+
return cancel;
|
|
130
|
+
}
|
|
131
|
+
function findDragElements(handle, columnIndex) {
|
|
132
|
+
const th = handle.closest('th');
|
|
133
|
+
const table = th?.closest('table');
|
|
134
|
+
const cols = table?.querySelectorAll(':scope > colgroup > col');
|
|
135
|
+
const column = cols?.[columnIndex];
|
|
136
|
+
// The last `<col>` keeps the table width while shrinking (see `ColumnGroup`). Otherwise,
|
|
137
|
+
// a container scrolled to the end reduces its scroll position and the content shifts under the pointer.
|
|
138
|
+
const filler = cols?.[cols.length - 1];
|
|
139
|
+
return th && table && column && filler ? {
|
|
140
|
+
th,
|
|
141
|
+
table,
|
|
142
|
+
column,
|
|
143
|
+
filler
|
|
144
|
+
} : undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { startColumnResizeDrag };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { c } from 'react/compiler-runtime';
|
|
2
|
+
import { use, useRef, useEffect } from 'react';
|
|
3
|
+
import { flushSync } from 'react-dom';
|
|
4
|
+
import { ColumnSizingContext } from './column-sizing-context.js';
|
|
5
|
+
import { startColumnResizeDrag } from './column-resize-drag.js';
|
|
6
|
+
import { s as styles } from '../_helpers/table.js';
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
8
|
+
import '../internal/column-indicator-vertical-span.js';
|
|
9
|
+
|
|
10
|
+
function ColumnResizeHandle(t0) {
|
|
11
|
+
const $ = c(8);
|
|
12
|
+
if ($[0] !== "724b466c3bc637c3ae26bf1fabf5e7e4ac8862a86000b5b36fac6c2ff1e52da4") {
|
|
13
|
+
for (let $i = 0; $i < 8; $i += 1) {
|
|
14
|
+
$[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
15
|
+
}
|
|
16
|
+
$[0] = "724b466c3bc637c3ae26bf1fabf5e7e4ac8862a86000b5b36fac6c2ff1e52da4";
|
|
17
|
+
}
|
|
18
|
+
const {
|
|
19
|
+
column,
|
|
20
|
+
columnIndex
|
|
21
|
+
} = t0;
|
|
22
|
+
const {
|
|
23
|
+
freezeWidths,
|
|
24
|
+
commitWidth
|
|
25
|
+
} = use(ColumnSizingContext);
|
|
26
|
+
const cancelDragRef = useRef(null);
|
|
27
|
+
let t1;
|
|
28
|
+
let t2;
|
|
29
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
30
|
+
t1 = () => () => cancelDragRef.current?.();
|
|
31
|
+
t2 = [];
|
|
32
|
+
$[1] = t1;
|
|
33
|
+
$[2] = t2;
|
|
34
|
+
} else {
|
|
35
|
+
t1 = $[1];
|
|
36
|
+
t2 = $[2];
|
|
37
|
+
}
|
|
38
|
+
useEffect(t1, t2);
|
|
39
|
+
let t3;
|
|
40
|
+
if ($[3] !== column || $[4] !== columnIndex || $[5] !== commitWidth || $[6] !== freezeWidths) {
|
|
41
|
+
const handlePointerDown = function handlePointerDown(e) {
|
|
42
|
+
if (e.button !== 0 || !e.isPrimary || cancelDragRef.current) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const startWidths = flushSync(freezeWidths);
|
|
46
|
+
if (!startWidths) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
cancelDragRef.current = startColumnResizeDrag({
|
|
52
|
+
handle: e.currentTarget,
|
|
53
|
+
pointerId: e.pointerId,
|
|
54
|
+
clientX: e.clientX,
|
|
55
|
+
columnIndex,
|
|
56
|
+
startWidths,
|
|
57
|
+
minWidth: column.minWidth,
|
|
58
|
+
maxWidth: column.maxWidth,
|
|
59
|
+
onCommit: newWidth => commitWidth(column.key, newWidth),
|
|
60
|
+
onEnd: () => {
|
|
61
|
+
cancelDragRef.current = null;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
t3 = /*#__PURE__*/jsx("div", {
|
|
66
|
+
"aria-hidden": true,
|
|
67
|
+
"data-test": "ring-table-column-resize-handle",
|
|
68
|
+
className: styles.columnResizeHandle,
|
|
69
|
+
onPointerDown: handlePointerDown,
|
|
70
|
+
onClick: _temp
|
|
71
|
+
});
|
|
72
|
+
$[3] = column;
|
|
73
|
+
$[4] = columnIndex;
|
|
74
|
+
$[5] = commitWidth;
|
|
75
|
+
$[6] = freezeWidths;
|
|
76
|
+
$[7] = t3;
|
|
77
|
+
} else {
|
|
78
|
+
t3 = $[7];
|
|
79
|
+
}
|
|
80
|
+
return t3;
|
|
81
|
+
}
|
|
82
|
+
function _temp(e_0) {
|
|
83
|
+
return e_0.stopPropagation();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { ColumnResizeHandle };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { c } from 'react/compiler-runtime';
|
|
2
|
+
import { createContext, useState, useRef, useLayoutEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const ColumnSizingContext = /*#__PURE__*/createContext({
|
|
5
|
+
freezeWidths: () => undefined,
|
|
6
|
+
commitWidth: () => {}
|
|
7
|
+
});
|
|
8
|
+
function useColumnSizing(t0) {
|
|
9
|
+
const $ = c(35);
|
|
10
|
+
if ($[0] !== "9878f9692d75268d2886c87a6f32578e0dcf9f4921a401f30e432eec4f6a74f8") {
|
|
11
|
+
for (let $i = 0; $i < 35; $i += 1) {
|
|
12
|
+
$[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
13
|
+
}
|
|
14
|
+
$[0] = "9878f9692d75268d2886c87a6f32578e0dcf9f4921a401f30e432eec4f6a74f8";
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
columns,
|
|
18
|
+
onColumnResize,
|
|
19
|
+
tableRef
|
|
20
|
+
} = t0;
|
|
21
|
+
const [internalWidths, setInternalWidths] = useState(_temp);
|
|
22
|
+
let t1;
|
|
23
|
+
if ($[1] !== columns) {
|
|
24
|
+
t1 = columns.some(_temp2);
|
|
25
|
+
$[1] = columns;
|
|
26
|
+
$[2] = t1;
|
|
27
|
+
} else {
|
|
28
|
+
t1 = $[2];
|
|
29
|
+
}
|
|
30
|
+
const hasColgroup = t1;
|
|
31
|
+
let t2;
|
|
32
|
+
if ($[3] !== columns || $[4] !== internalWidths) {
|
|
33
|
+
let t3;
|
|
34
|
+
if ($[6] !== internalWidths) {
|
|
35
|
+
t3 = column_0 => {
|
|
36
|
+
var _column_0$width;
|
|
37
|
+
return (_column_0$width = column_0.width) !== null && _column_0$width !== void 0 ? _column_0$width : internalWidths.get(column_0.key);
|
|
38
|
+
};
|
|
39
|
+
$[6] = internalWidths;
|
|
40
|
+
$[7] = t3;
|
|
41
|
+
} else {
|
|
42
|
+
t3 = $[7];
|
|
43
|
+
}
|
|
44
|
+
t2 = columns.map(t3);
|
|
45
|
+
$[3] = columns;
|
|
46
|
+
$[4] = internalWidths;
|
|
47
|
+
$[5] = t2;
|
|
48
|
+
} else {
|
|
49
|
+
t2 = $[5];
|
|
50
|
+
}
|
|
51
|
+
const widths = t2;
|
|
52
|
+
let t3;
|
|
53
|
+
if ($[8] !== columns || $[9] !== onColumnResize || $[10] !== widths) {
|
|
54
|
+
t3 = {
|
|
55
|
+
columns,
|
|
56
|
+
widths,
|
|
57
|
+
onColumnResize
|
|
58
|
+
};
|
|
59
|
+
$[8] = columns;
|
|
60
|
+
$[9] = onColumnResize;
|
|
61
|
+
$[10] = widths;
|
|
62
|
+
$[11] = t3;
|
|
63
|
+
} else {
|
|
64
|
+
t3 = $[11];
|
|
65
|
+
}
|
|
66
|
+
const latestRef = useRef(t3);
|
|
67
|
+
let t4;
|
|
68
|
+
if ($[12] !== columns || $[13] !== onColumnResize || $[14] !== widths) {
|
|
69
|
+
t4 = () => {
|
|
70
|
+
latestRef.current = {
|
|
71
|
+
columns,
|
|
72
|
+
widths,
|
|
73
|
+
onColumnResize
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
$[12] = columns;
|
|
77
|
+
$[13] = onColumnResize;
|
|
78
|
+
$[14] = widths;
|
|
79
|
+
$[15] = t4;
|
|
80
|
+
} else {
|
|
81
|
+
t4 = $[15];
|
|
82
|
+
}
|
|
83
|
+
useLayoutEffect(t4);
|
|
84
|
+
let t5;
|
|
85
|
+
if ($[16] !== widths) {
|
|
86
|
+
t5 = widths.every(_temp3);
|
|
87
|
+
$[16] = widths;
|
|
88
|
+
$[17] = t5;
|
|
89
|
+
} else {
|
|
90
|
+
t5 = $[17];
|
|
91
|
+
}
|
|
92
|
+
const allWidthsKnown = t5;
|
|
93
|
+
const fixedLayout = hasColgroup && allWidthsKnown;
|
|
94
|
+
let t6;
|
|
95
|
+
if ($[18] !== fixedLayout || $[19] !== widths) {
|
|
96
|
+
t6 = fixedLayout ? widths.reduce(_temp4, 0) : undefined;
|
|
97
|
+
$[18] = fixedLayout;
|
|
98
|
+
$[19] = widths;
|
|
99
|
+
$[20] = t6;
|
|
100
|
+
} else {
|
|
101
|
+
t6 = $[20];
|
|
102
|
+
}
|
|
103
|
+
const totalWidth = t6;
|
|
104
|
+
let t7;
|
|
105
|
+
if ($[21] !== columns || $[22] !== fixedLayout || $[23] !== tableRef || $[24] !== widths) {
|
|
106
|
+
t7 = function freezeWidths() {
|
|
107
|
+
const headerCells = tableRef.current?.tHead?.rows[0]?.cells;
|
|
108
|
+
if (!headerCells) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const frozenWidths = columns.map((_column, index) => {
|
|
112
|
+
var _ref, _widths$index;
|
|
113
|
+
return (_ref = (_widths$index = widths[index]) !== null && _widths$index !== void 0 ? _widths$index : headerCells[index]?.getBoundingClientRect().width) !== null && _ref !== void 0 ? _ref : 0;
|
|
114
|
+
});
|
|
115
|
+
if (!fixedLayout) {
|
|
116
|
+
setInternalWidths(new Map(columns.map((column_1, index_0) => [column_1.key, frozenWidths[index_0]])));
|
|
117
|
+
}
|
|
118
|
+
return frozenWidths;
|
|
119
|
+
};
|
|
120
|
+
$[21] = columns;
|
|
121
|
+
$[22] = fixedLayout;
|
|
122
|
+
$[23] = tableRef;
|
|
123
|
+
$[24] = widths;
|
|
124
|
+
$[25] = t7;
|
|
125
|
+
} else {
|
|
126
|
+
t7 = $[25];
|
|
127
|
+
}
|
|
128
|
+
const freezeWidths = t7;
|
|
129
|
+
let t8;
|
|
130
|
+
if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
|
|
131
|
+
t8 = function commitWidth(columnKey, width_1) {
|
|
132
|
+
const {
|
|
133
|
+
columns: latestColumns,
|
|
134
|
+
widths: latestWidths,
|
|
135
|
+
onColumnResize: latestOnColumnResize
|
|
136
|
+
} = latestRef.current;
|
|
137
|
+
const columnIndex = latestColumns.findIndex(column_2 => column_2.key === columnKey);
|
|
138
|
+
if (columnIndex === -1) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setInternalWidths(prev => new Map(prev).set(columnKey, width_1));
|
|
142
|
+
const newColumns = latestColumns.map((column_3, index_1) => {
|
|
143
|
+
const newWidth = index_1 === columnIndex ? width_1 : latestWidths[index_1];
|
|
144
|
+
return newWidth === column_3.width ? column_3 : {
|
|
145
|
+
...column_3,
|
|
146
|
+
width: newWidth
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
latestOnColumnResize?.(latestColumns[columnIndex], columnIndex, width_1, newColumns);
|
|
150
|
+
};
|
|
151
|
+
$[26] = t8;
|
|
152
|
+
} else {
|
|
153
|
+
t8 = $[26];
|
|
154
|
+
}
|
|
155
|
+
const commitWidth = t8;
|
|
156
|
+
let t9;
|
|
157
|
+
if ($[27] !== freezeWidths) {
|
|
158
|
+
t9 = {
|
|
159
|
+
freezeWidths,
|
|
160
|
+
commitWidth
|
|
161
|
+
};
|
|
162
|
+
$[27] = freezeWidths;
|
|
163
|
+
$[28] = t9;
|
|
164
|
+
} else {
|
|
165
|
+
t9 = $[28];
|
|
166
|
+
}
|
|
167
|
+
let t10;
|
|
168
|
+
if ($[29] !== fixedLayout || $[30] !== hasColgroup || $[31] !== t9 || $[32] !== totalWidth || $[33] !== widths) {
|
|
169
|
+
t10 = {
|
|
170
|
+
hasColgroup,
|
|
171
|
+
fixedLayout,
|
|
172
|
+
totalWidth,
|
|
173
|
+
widths,
|
|
174
|
+
contextValue: t9
|
|
175
|
+
};
|
|
176
|
+
$[29] = fixedLayout;
|
|
177
|
+
$[30] = hasColgroup;
|
|
178
|
+
$[31] = t9;
|
|
179
|
+
$[32] = totalWidth;
|
|
180
|
+
$[33] = widths;
|
|
181
|
+
$[34] = t10;
|
|
182
|
+
} else {
|
|
183
|
+
t10 = $[34];
|
|
184
|
+
}
|
|
185
|
+
return t10;
|
|
186
|
+
}
|
|
187
|
+
function _temp4(sum, width_0) {
|
|
188
|
+
return sum + width_0;
|
|
189
|
+
}
|
|
190
|
+
function _temp3(width) {
|
|
191
|
+
return width != null;
|
|
192
|
+
}
|
|
193
|
+
function _temp2(column) {
|
|
194
|
+
return column.resizable || column.width != null;
|
|
195
|
+
}
|
|
196
|
+
function _temp() {
|
|
197
|
+
return new Map();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { ColumnSizingContext, useColumnSizing };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the vertical position of an indicator that spans the visible part
|
|
3
|
+
* of the table, starting at the header top. Client coordinates.
|
|
4
|
+
*/
|
|
5
|
+
function getColumnIndicatorVerticalSpan(elementInHeader) {
|
|
6
|
+
const thead = elementInHeader.closest('thead');
|
|
7
|
+
const table = thead?.closest('table');
|
|
8
|
+
if (!thead || !table) return null;
|
|
9
|
+
const {
|
|
10
|
+
top: headerTop
|
|
11
|
+
} = thead.getBoundingClientRect();
|
|
12
|
+
const {
|
|
13
|
+
bottom: tableBottom
|
|
14
|
+
} = table.getBoundingClientRect();
|
|
15
|
+
const distanceToTableEnd = tableBottom - headerTop;
|
|
16
|
+
const distanceToViewportEnd = window.innerHeight - headerTop;
|
|
17
|
+
return {
|
|
18
|
+
top: headerTop,
|
|
19
|
+
height: `min(${distanceToTableEnd}px, calc(${distanceToViewportEnd}px - .5rem))`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getColumnIndicatorVerticalSpan };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const edgeAreaPx = 100;
|
|
2
|
+
// Keeps the middle of a small scroller free from auto scroll
|
|
3
|
+
const maxEdgeAreaFraction = 0.3;
|
|
4
|
+
const maxStepPx = 16;
|
|
5
|
+
/**
|
|
6
|
+
* The nearest ancestor which scrolls along `axis`, or `null` for the document
|
|
7
|
+
*/
|
|
8
|
+
function getScroller(table, axis) {
|
|
9
|
+
for (let el = table.parentElement; el && el !== document.scrollingElement; el = el.parentElement) {
|
|
10
|
+
// `overflow` of <body> propagates to the viewport unless <html> has its own
|
|
11
|
+
if (el === document.body && window.getComputedStyle(document.documentElement).overflow === 'visible') continue;
|
|
12
|
+
const {
|
|
13
|
+
overflowX,
|
|
14
|
+
overflowY
|
|
15
|
+
} = window.getComputedStyle(el);
|
|
16
|
+
const isScrollable = /auto|scroll/.test(axis === 'x' ? overflowX : overflowY);
|
|
17
|
+
// Ignores sub-pixel overflow
|
|
18
|
+
const overflowPx = axis === 'x' ? el.scrollWidth - el.clientWidth : el.scrollHeight - el.clientHeight;
|
|
19
|
+
if (isScrollable && overflowPx > 1) return el;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The visible part of the scroller along `axis`, without borders and scrollbars
|
|
25
|
+
*/
|
|
26
|
+
function getVisibleRange(scroller, axis) {
|
|
27
|
+
const isX = axis === 'x';
|
|
28
|
+
if (!scroller) {
|
|
29
|
+
const root = document.documentElement;
|
|
30
|
+
return {
|
|
31
|
+
start: 0,
|
|
32
|
+
end: isX ? root.clientWidth : root.clientHeight
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const rect = scroller.getBoundingClientRect();
|
|
36
|
+
const start = isX ? rect.left + scroller.clientLeft : rect.top + scroller.clientTop;
|
|
37
|
+
const end = start + (isX ? scroller.clientWidth : scroller.clientHeight);
|
|
38
|
+
return {
|
|
39
|
+
start: Math.max(start, 0),
|
|
40
|
+
end: Math.min(end, isX ? window.innerWidth : window.innerHeight)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getRange(rect, axis) {
|
|
44
|
+
return axis === 'x' ? {
|
|
45
|
+
start: rect.left,
|
|
46
|
+
end: rect.right
|
|
47
|
+
} : {
|
|
48
|
+
start: rect.top,
|
|
49
|
+
end: rect.bottom
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Grows from 1px at the inner boundary of the edge area to `maxStepPx` at the edge.
|
|
54
|
+
* A pointer beyond the edge (negative distance) scrolls at `maxStepPx`.
|
|
55
|
+
*/
|
|
56
|
+
function getSpeed(distanceToEdge, edgeArea) {
|
|
57
|
+
const closeness = Math.min(1 - distanceToEdge / edgeArea, 1);
|
|
58
|
+
return Math.ceil(maxStepPx * closeness);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* While the drag is active, scrolls the nearest scroller of `table` along `axis`
|
|
62
|
+
* when the pointer is near the scroller edge, until the table edge becomes visible.
|
|
63
|
+
* The closer the pointer is to the edge, the faster the scroll.
|
|
64
|
+
*
|
|
65
|
+
* `preferredScroller` is used instead of the nearest scroller when set, e.g. `TableProps.scrollerRef` for `y`.
|
|
66
|
+
*
|
|
67
|
+
* `onScroll` is called with the last pointer position on every frame after the pointer has moved,
|
|
68
|
+
* so that the caller can update anything which depends on the scroll position,
|
|
69
|
+
* including after the user's wheel scroll.
|
|
70
|
+
*/
|
|
71
|
+
function startDragAutoScroll(axis, table, preferredScroller, onScroll) {
|
|
72
|
+
const isX = axis === 'x';
|
|
73
|
+
const scroller = preferredScroller !== null && preferredScroller !== void 0 ? preferredScroller : getScroller(table, axis);
|
|
74
|
+
let pointer = null;
|
|
75
|
+
let rafId = requestAnimationFrame(function tick() {
|
|
76
|
+
let step = 0;
|
|
77
|
+
if (pointer) {
|
|
78
|
+
const visible = getVisibleRange(scroller, axis);
|
|
79
|
+
const edgeArea = Math.min(edgeAreaPx, (visible.end - visible.start) * maxEdgeAreaFraction);
|
|
80
|
+
// The scroller is out of the viewport
|
|
81
|
+
if (edgeArea > 0) {
|
|
82
|
+
const pointerOffset = isX ? pointer.clientX : pointer.clientY;
|
|
83
|
+
const distanceToStart = pointerOffset - visible.start;
|
|
84
|
+
const distanceToEnd = visible.end - pointerOffset;
|
|
85
|
+
const tableRange = getRange(table.getBoundingClientRect(), axis);
|
|
86
|
+
const isTableHiddenAtStart = tableRange.start < visible.start;
|
|
87
|
+
const isTableHiddenAtEnd = tableRange.end > visible.end;
|
|
88
|
+
if (distanceToStart < edgeArea && isTableHiddenAtStart) {
|
|
89
|
+
step = -getSpeed(distanceToStart, edgeArea);
|
|
90
|
+
}
|
|
91
|
+
if (distanceToEnd < edgeArea && isTableHiddenAtEnd) {
|
|
92
|
+
step = getSpeed(distanceToEnd, edgeArea);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Not `smooth` even if the page sets `scroll-behavior: smooth`: each frame would restart the animation
|
|
97
|
+
if (step) (scroller !== null && scroller !== void 0 ? scroller : window).scrollBy({
|
|
98
|
+
[isX ? 'left' : 'top']: step,
|
|
99
|
+
behavior: 'instant'
|
|
100
|
+
});
|
|
101
|
+
if (pointer) onScroll(pointer.clientX, pointer.clientY);
|
|
102
|
+
rafId = requestAnimationFrame(tick);
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
update(clientX, clientY) {
|
|
106
|
+
pointer = {
|
|
107
|
+
clientX,
|
|
108
|
+
clientY
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
stop() {
|
|
112
|
+
cancelAnimationFrame(rafId);
|
|
113
|
+
pointer = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { startDragAutoScroll };
|