@mezzanine-ui/react 0.12.9 → 0.13.1
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/Table/Table.d.ts +25 -3
- package/Table/Table.js +51 -5
- package/Table/TableBody.d.ts +1 -1
- package/Table/TableBody.js +2 -12
- package/Table/TableBodyRow.d.ts +1 -1
- package/Table/TableBodyRow.js +31 -9
- package/Table/TableCell.js +2 -2
- package/Table/TableContext.d.ts +6 -2
- package/Table/TableHeader.d.ts +1 -1
- package/Table/TableHeader.js +18 -7
- package/Table/draggable/useTableDraggable.d.ts +14 -0
- package/Table/draggable/useTableDraggable.js +63 -0
- package/Table/index.d.ts +2 -0
- package/Table/index.js +2 -0
- package/Table/sorting/useTableSorting.d.ts +2 -0
- package/Table/sorting/useTableSorting.js +1 -1
- package/Table/useTableScroll.d.ts +296 -7
- package/Table/useTableScroll.js +185 -75
- package/index.d.ts +2 -1
- package/index.js +3 -0
- package/package.json +6 -4
- package/utils/array-move.d.ts +1 -0
- package/utils/array-move.js +13 -0
package/Table/useTableScroll.js
CHANGED
|
@@ -1,141 +1,239 @@
|
|
|
1
|
-
import { useRef,
|
|
2
|
-
import { TableContext, TableDataContext } from './TableContext.js';
|
|
3
|
-
import { usePreviousValue } from '../hooks/usePreviousValue.js';
|
|
1
|
+
import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
|
|
4
2
|
|
|
3
|
+
const HEADER_DEFAULT_HEIGHT = 40; // px
|
|
4
|
+
const SCROLL_BAR_MIN_START_AT = 4; // px
|
|
5
|
+
const SCROLL_BAR_MAX_END_SPACING = 16; // px
|
|
6
|
+
const FETCH_MORE_TRIGGER_AT_BOTTOM = 46; // px
|
|
7
|
+
const SCROLL_BAR_DISPLAY_TIMES = 1500; // ms
|
|
8
|
+
const defaultScrollBarTrackStyle = {
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
right: 0,
|
|
11
|
+
top: `${HEADER_DEFAULT_HEIGHT}px`,
|
|
12
|
+
width: 12,
|
|
13
|
+
height: 0,
|
|
14
|
+
opacity: '0',
|
|
15
|
+
transition: '0.1s opacity ease-in',
|
|
16
|
+
backgroundColor: '#F2F2F2',
|
|
17
|
+
};
|
|
5
18
|
const defaultScrollBarStyle = {
|
|
6
19
|
display: 'flex',
|
|
7
20
|
justifyContent: 'center',
|
|
8
21
|
alignItems: 'flex-start',
|
|
9
22
|
position: 'absolute',
|
|
10
23
|
right: 0,
|
|
11
|
-
top:
|
|
24
|
+
top: `${SCROLL_BAR_MIN_START_AT}px`,
|
|
12
25
|
width: 10,
|
|
13
26
|
height: 0,
|
|
14
27
|
borderRadius: 10,
|
|
28
|
+
transform: 'translate3d(0, 0, 0)',
|
|
15
29
|
outline: 'none',
|
|
16
30
|
opacity: '0',
|
|
17
31
|
transition: '0.1s opacity ease-in',
|
|
18
32
|
backgroundColor: 'transparent',
|
|
19
33
|
};
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const bodyRef = useRef(null);
|
|
34
|
+
function useTableScroll(props) {
|
|
35
|
+
const { onFetchMore, loading, scrollBarSize = 4, } = props;
|
|
36
|
+
const scrollRef = useRef(null);
|
|
37
|
+
const tableRef = useRef(null);
|
|
38
|
+
const scrollBarTrackRef = useRef(null);
|
|
26
39
|
const scrollBarRef = useRef(null);
|
|
27
40
|
const scrollBarDisplayTimer = useRef();
|
|
28
|
-
const { fetchMore, loading, scrollBarSize = 4, } = useContext(TableContext) || {};
|
|
29
|
-
const { dataSource = [], } = useContext(TableDataContext) || {};
|
|
30
41
|
const [scrollBarHeight, setScrollBarHeight] = useState(0);
|
|
31
42
|
const [pointerOffset, setPointerOffset] = useState(0);
|
|
43
|
+
const [isHorizontalScrolling, toggleIsHorizontalScrolling] = useState(false);
|
|
32
44
|
/** set scroll bar callback */
|
|
33
45
|
const onSetScrollBarHeight = useCallback(() => {
|
|
34
|
-
|
|
46
|
+
/** @NOTE Scroll bar 高度為可視區域的百分比 */
|
|
47
|
+
if (!scrollRef.current)
|
|
35
48
|
return;
|
|
36
|
-
const { scrollHeight, clientHeight: tableHeight, } =
|
|
37
|
-
const
|
|
49
|
+
const { scrollHeight, clientHeight: tableHeight, } = scrollRef.current;
|
|
50
|
+
const bodyHeight = scrollHeight - HEADER_DEFAULT_HEIGHT;
|
|
51
|
+
const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
|
|
52
|
+
const nextHeight = Math.max((viewAreaHeight - (SCROLL_BAR_MAX_END_SPACING * 2)) * (viewAreaHeight / bodyHeight), tableHeight / 10);
|
|
38
53
|
setScrollBarHeight(nextHeight);
|
|
39
54
|
}, []);
|
|
40
55
|
/** display/hide scroll bar */
|
|
41
56
|
const onHideScrollBar = useCallback(() => {
|
|
42
57
|
if (!scrollBarRef.current)
|
|
43
58
|
return;
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
if (scrollBarDisplayTimer.current) {
|
|
60
|
+
window.clearTimeout(scrollBarDisplayTimer.current);
|
|
61
|
+
}
|
|
62
|
+
scrollBarDisplayTimer.current = window.setTimeout(() => {
|
|
63
|
+
if (scrollBarRef.current) {
|
|
64
|
+
scrollBarRef.current.style.opacity = '0';
|
|
65
|
+
scrollBarRef.current.style.pointerEvents = 'none';
|
|
66
|
+
}
|
|
67
|
+
if (scrollBarTrackRef.current) {
|
|
68
|
+
scrollBarTrackRef.current.style.opacity = '0';
|
|
69
|
+
scrollBarTrackRef.current.style.pointerEvents = 'none';
|
|
70
|
+
}
|
|
71
|
+
}, SCROLL_BAR_DISPLAY_TIMES);
|
|
46
72
|
}, []);
|
|
47
73
|
const onDisplayScrollBar = useCallback(() => {
|
|
48
|
-
if (!scrollBarRef.current || !
|
|
74
|
+
if (!scrollBarRef.current || !scrollRef.current || !scrollBarTrackRef.current)
|
|
75
|
+
return;
|
|
76
|
+
/** 觸控螢幕不需要 scroll bar */
|
|
77
|
+
const isTouchEnabled = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0);
|
|
78
|
+
/** firefox 的滾軸只能同時顯示 or 取消,所以乾脆就用原生的(除非能單獨關掉直向的滾軸,只顯示橫向的才行) */
|
|
79
|
+
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
80
|
+
if (isTouchEnabled || isFirefox)
|
|
49
81
|
return;
|
|
82
|
+
scrollBarRef.current.style.opacity = '1';
|
|
83
|
+
scrollBarRef.current.style.pointerEvents = 'auto';
|
|
84
|
+
scrollBarTrackRef.current.style.opacity = '1';
|
|
85
|
+
scrollBarTrackRef.current.style.pointerEvents = 'auto';
|
|
50
86
|
if (scrollBarDisplayTimer.current) {
|
|
51
87
|
window.clearTimeout(scrollBarDisplayTimer.current);
|
|
52
88
|
}
|
|
53
|
-
scrollBarRef.current.style.opacity = '1';
|
|
54
|
-
scrollBarRef.current.style.pointerEvents = 'auto';
|
|
55
|
-
scrollBarDisplayTimer.current = window.setTimeout(() => onHideScrollBar(), SCROLL_BAR_DISPLAY_TIMES);
|
|
56
89
|
}, []);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
const resetPointerOffset = useCallback(() => setPointerOffset(0), []);
|
|
91
|
+
/** scroll bar style reset when mouse leave */
|
|
92
|
+
const onScrollBarLeave = useCallback(() => {
|
|
93
|
+
if (scrollBarRef.current) {
|
|
94
|
+
scrollBarRef.current.childNodes[0].style.width = `${scrollBarSize}px`;
|
|
95
|
+
}
|
|
96
|
+
resetPointerOffset();
|
|
97
|
+
}, []);
|
|
98
|
+
/** when use mouse to drag scroll bar, get cursor position */
|
|
99
|
+
const onScrollBarMouseDown = useCallback(({ clientY }) => {
|
|
100
|
+
const { current: scrollBar } = scrollBarRef;
|
|
101
|
+
if (!scrollBar)
|
|
102
|
+
return;
|
|
103
|
+
const { top: initScrollBarTop } = scrollBar.getBoundingClientRect();
|
|
104
|
+
setPointerOffset(clientY - initScrollBarTop);
|
|
63
105
|
}, []);
|
|
106
|
+
const onScrollBarMouseUp = useCallback(() => resetPointerOffset(), []);
|
|
107
|
+
/** 偵測 table 高度是否發生變化,有的話就要重新計算 scroll bar 長度 */
|
|
64
108
|
useEffect(() => {
|
|
65
|
-
|
|
66
|
-
|
|
109
|
+
const { current: table } = tableRef;
|
|
110
|
+
function resizing() {
|
|
111
|
+
window.requestAnimationFrame(onSetScrollBarHeight);
|
|
67
112
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
113
|
+
if (table) {
|
|
114
|
+
const observer = new ResizeObserver(resizing);
|
|
115
|
+
observer.observe(table);
|
|
116
|
+
return () => {
|
|
117
|
+
observer.disconnect();
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return () => { };
|
|
74
121
|
}, []);
|
|
75
122
|
useEffect(() => {
|
|
76
|
-
const { current: body } =
|
|
123
|
+
const { current: body } = scrollRef;
|
|
77
124
|
const { current: scrollBar } = scrollBarRef;
|
|
78
|
-
|
|
125
|
+
const { current: scrollBarTrack } = scrollBarTrackRef;
|
|
126
|
+
if (!body || !scrollBar || !scrollBarTrack)
|
|
79
127
|
return;
|
|
128
|
+
/** 游標在滾軸上長按並移動 */
|
|
80
129
|
function onMouseMove({ clientY }) {
|
|
81
|
-
const {
|
|
130
|
+
const { scrollHeight, clientHeight: tableHeight, } = body;
|
|
82
131
|
if (!pointerOffset)
|
|
83
132
|
return;
|
|
84
133
|
// keep scroll bar display when moving
|
|
85
134
|
window.requestAnimationFrame(onDisplayScrollBar);
|
|
86
135
|
const { top: tableTop, } = body.getBoundingClientRect();
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
136
|
+
/** Table 最大滾動距離 */
|
|
137
|
+
const maxScrollDistance = scrollHeight - tableHeight;
|
|
138
|
+
/** 游標在 scroll bar 上的位置 */
|
|
139
|
+
const scrollBarCurrentPosition = clientY - (tableTop + HEADER_DEFAULT_HEIGHT) - pointerOffset;
|
|
140
|
+
/** 可視區域高度 */
|
|
141
|
+
const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
|
|
142
|
+
/** 最大滑動距離 */
|
|
143
|
+
const maxScrollBarDistance = viewAreaHeight - scrollBarHeight - SCROLL_BAR_MAX_END_SPACING;
|
|
144
|
+
/** 計算出來的距離 */
|
|
145
|
+
const clampScrollBarTop = Math.min(Math.max(scrollBarCurrentPosition, 0), // min boundary
|
|
146
|
+
maxScrollBarDistance);
|
|
147
|
+
scrollBar.style.setProperty('transform', `translate3d(0, ${clampScrollBarTop}px, 0)`);
|
|
148
|
+
body.scrollTop = ((clampScrollBarTop * maxScrollDistance) / maxScrollBarDistance);
|
|
149
|
+
}
|
|
150
|
+
/** 在滾軸滑軌上點擊,直接滾動到指定位置上 */
|
|
151
|
+
function onMouseClick({ clientY }) {
|
|
152
|
+
if (!scrollBar)
|
|
153
|
+
return;
|
|
154
|
+
const { scrollHeight, clientHeight: tableHeight, } = body;
|
|
155
|
+
// keep scroll bar display when moving
|
|
156
|
+
window.requestAnimationFrame(onDisplayScrollBar);
|
|
157
|
+
const { top: tableTop, } = body.getBoundingClientRect();
|
|
158
|
+
/** Table 最大滾動距離 */
|
|
159
|
+
const maxScrollDistance = scrollHeight - tableHeight;
|
|
160
|
+
/** 游標在 Track 上的位置 */
|
|
161
|
+
const scrollBarCurrentPosition = clientY - (tableTop + HEADER_DEFAULT_HEIGHT) - (scrollBarHeight / 2);
|
|
162
|
+
/** 可視區域高度 */
|
|
163
|
+
const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
|
|
164
|
+
/** 最大滑動距離 */
|
|
165
|
+
const maxScrollBarDistance = viewAreaHeight - scrollBarHeight - SCROLL_BAR_MAX_END_SPACING;
|
|
166
|
+
/** 計算出來的距離 */
|
|
167
|
+
const clampScrollBarTop = Math.min(Math.max(scrollBarCurrentPosition, 0), // min boundary
|
|
168
|
+
maxScrollBarDistance);
|
|
169
|
+
scrollBar.style.setProperty('transform', `translate3d(0, ${clampScrollBarTop}px, 0)`);
|
|
170
|
+
body.scrollTop = ((clampScrollBarTop * maxScrollDistance) / maxScrollBarDistance);
|
|
171
|
+
}
|
|
172
|
+
/** 游標移動到滾軸/滑軌上方時 */
|
|
173
|
+
function onMouseOver() {
|
|
174
|
+
scrollBar.style.setProperty('transition', '0s');
|
|
175
|
+
onDisplayScrollBar();
|
|
176
|
+
}
|
|
177
|
+
/** 游標移開滾軸/滑軌上方時 */
|
|
178
|
+
function onMouseLeave() {
|
|
179
|
+
scrollBar.style.setProperty('transition', '0.1s');
|
|
180
|
+
onHideScrollBar();
|
|
94
181
|
}
|
|
95
182
|
scrollBar.addEventListener('mousemove', onMouseMove, false);
|
|
183
|
+
scrollBar.addEventListener('mouseover', onMouseOver, false);
|
|
184
|
+
scrollBar.addEventListener('mouseleave', onMouseLeave, false);
|
|
185
|
+
scrollBarTrack.addEventListener('mousemove', onMouseMove, false);
|
|
186
|
+
scrollBarTrack.addEventListener('mouseover', onMouseOver, false);
|
|
187
|
+
scrollBarTrack.addEventListener('mouseleave', onMouseLeave, false);
|
|
188
|
+
scrollBarTrack.addEventListener('click', onMouseClick, false);
|
|
96
189
|
return () => {
|
|
97
190
|
scrollBar.removeEventListener('mousemove', onMouseMove, false);
|
|
191
|
+
scrollBar.removeEventListener('mouseover', onMouseOver, false);
|
|
192
|
+
scrollBar.removeEventListener('mouseleave', onMouseLeave, false);
|
|
193
|
+
scrollBarTrack.removeEventListener('mousemove', onMouseMove, false);
|
|
194
|
+
scrollBarTrack.removeEventListener('mouseover', onMouseOver, false);
|
|
195
|
+
scrollBarTrack.removeEventListener('mouseleave', onMouseLeave, false);
|
|
196
|
+
scrollBarTrack.removeEventListener('click', onMouseClick, false);
|
|
98
197
|
};
|
|
99
|
-
}, [scrollBarHeight, pointerOffset, onDisplayScrollBar]);
|
|
100
|
-
const resetPointerOffset = useCallback(() => setPointerOffset(0), []);
|
|
198
|
+
}, [scrollBarHeight, pointerOffset, onDisplayScrollBar, onHideScrollBar]);
|
|
101
199
|
/** scroll bar fatter when mouse enter */
|
|
102
200
|
const onScrollBarEnter = useCallback(() => {
|
|
103
201
|
if (scrollBarRef.current) {
|
|
104
202
|
scrollBarRef.current.childNodes[0].style.width = `${scrollBarSize + 6}px`;
|
|
105
203
|
}
|
|
106
204
|
}, []);
|
|
107
|
-
/** scroll bar style reset when mouse leave */
|
|
108
|
-
const onScrollBarLeave = useCallback(() => {
|
|
109
|
-
if (scrollBarRef.current) {
|
|
110
|
-
scrollBarRef.current.childNodes[0].style.width = `${scrollBarSize}px`;
|
|
111
|
-
}
|
|
112
|
-
resetPointerOffset();
|
|
113
|
-
}, []);
|
|
114
|
-
/** when use mouse to drag scroll bar, get cursor position */
|
|
115
|
-
const onScrollBarMouseDown = useCallback(({ target, clientY }) => {
|
|
116
|
-
if (!target)
|
|
117
|
-
return;
|
|
118
|
-
const { top: initScrollBarTop } = target.getBoundingClientRect();
|
|
119
|
-
setPointerOffset(clientY - initScrollBarTop);
|
|
120
|
-
}, []);
|
|
121
|
-
const onScrollBarMouseUp = useCallback(() => resetPointerOffset(), []);
|
|
122
205
|
/** scroll table directly */
|
|
123
206
|
const setScrollBarTop = useCallback(() => {
|
|
124
|
-
if (
|
|
125
|
-
const { clientHeight: tableHeight, scrollTop, scrollHeight, } =
|
|
207
|
+
if (scrollRef.current) {
|
|
208
|
+
const { clientHeight: tableHeight, scrollTop, scrollHeight, } = scrollRef.current;
|
|
126
209
|
/** @NOTE don't apply scroll change when use pointer dragging */
|
|
127
210
|
if (scrollBarRef.current && !pointerOffset) {
|
|
128
|
-
|
|
129
|
-
|
|
211
|
+
const bodyHeight = scrollHeight - HEADER_DEFAULT_HEIGHT;
|
|
212
|
+
const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
|
|
213
|
+
const distance = Math.max((viewAreaHeight * Math.max((scrollTop / bodyHeight), 0)), 0);
|
|
214
|
+
scrollBarRef.current.style.transform = `translate3d(0, ${distance}px, 0)`;
|
|
215
|
+
}
|
|
216
|
+
if (scrollBarTrackRef.current) {
|
|
217
|
+
scrollBarTrackRef.current.style.height = `${tableHeight - HEADER_DEFAULT_HEIGHT}px`;
|
|
130
218
|
}
|
|
131
219
|
}
|
|
132
220
|
}, [scrollBarHeight, pointerOffset]);
|
|
133
|
-
const onScroll = useCallback(() => {
|
|
134
|
-
|
|
221
|
+
const onScroll = useCallback((scrollTarget) => {
|
|
222
|
+
/** 使用者開始橫向滾動 */
|
|
223
|
+
if (scrollTarget.target.scrollLeft) {
|
|
224
|
+
toggleIsHorizontalScrolling(true);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
toggleIsHorizontalScrolling(false);
|
|
228
|
+
}
|
|
135
229
|
if (loading)
|
|
136
230
|
return;
|
|
137
|
-
if (
|
|
138
|
-
const { clientHeight, scrollTop, scrollHeight, } =
|
|
231
|
+
if (scrollRef.current) {
|
|
232
|
+
const { clientHeight, scrollTop, scrollHeight, } = scrollRef.current;
|
|
233
|
+
/** 如果不需要滾動,則不需要觸發 */
|
|
234
|
+
if (clientHeight >= scrollHeight)
|
|
235
|
+
return;
|
|
236
|
+
window.requestAnimationFrame(onDisplayScrollBar);
|
|
139
237
|
/** @Note safari specific bug fix for scroll bouncing */
|
|
140
238
|
const belowBottom = scrollTop > (scrollHeight - clientHeight);
|
|
141
239
|
if (belowBottom)
|
|
@@ -143,28 +241,40 @@ function useTableScroll() {
|
|
|
143
241
|
window.requestAnimationFrame(setScrollBarTop);
|
|
144
242
|
/** trigger fetchMore when scrolling */
|
|
145
243
|
if ((scrollHeight - (scrollTop + clientHeight)) < FETCH_MORE_TRIGGER_AT_BOTTOM) {
|
|
146
|
-
|
|
244
|
+
onFetchMore === null || onFetchMore === void 0 ? void 0 : onFetchMore();
|
|
147
245
|
}
|
|
148
246
|
}
|
|
149
|
-
|
|
247
|
+
window.requestAnimationFrame(onHideScrollBar);
|
|
248
|
+
}, [loading, setScrollBarTop, onDisplayScrollBar, onFetchMore, onHideScrollBar]);
|
|
150
249
|
const scrollBarStyle = useMemo(() => ({
|
|
151
250
|
...defaultScrollBarStyle,
|
|
152
251
|
height: `${scrollBarHeight}px`,
|
|
153
252
|
}), [scrollBarHeight]);
|
|
253
|
+
const scrollBarTrackStyle = useMemo(() => {
|
|
254
|
+
var _a, _b;
|
|
255
|
+
return ({
|
|
256
|
+
...defaultScrollBarTrackStyle,
|
|
257
|
+
height: `${(_b = (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) !== null && _b !== void 0 ? _b : 0}px`,
|
|
258
|
+
});
|
|
259
|
+
}, [scrollBarHeight]);
|
|
154
260
|
/** composing result */
|
|
155
|
-
const
|
|
156
|
-
ref:
|
|
261
|
+
const tableScrollContainer = {
|
|
262
|
+
ref: scrollRef,
|
|
263
|
+
target: tableRef,
|
|
157
264
|
onScroll,
|
|
158
265
|
};
|
|
159
266
|
const scrollElement = {
|
|
160
267
|
ref: scrollBarRef,
|
|
268
|
+
trackRef: scrollBarTrackRef,
|
|
269
|
+
scrollBarSize,
|
|
161
270
|
onMouseDown: onScrollBarMouseDown,
|
|
162
271
|
onMouseUp: onScrollBarMouseUp,
|
|
163
272
|
onMouseEnter: onScrollBarEnter,
|
|
164
273
|
onMouseLeave: onScrollBarLeave,
|
|
165
274
|
style: scrollBarStyle,
|
|
275
|
+
trackStyle: scrollBarTrackStyle,
|
|
166
276
|
};
|
|
167
|
-
return [
|
|
277
|
+
return [tableScrollContainer, scrollElement, isHorizontalScrolling];
|
|
168
278
|
}
|
|
169
279
|
|
|
170
280
|
export { useTableScroll as default };
|
package/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './utils/getElement';
|
|
|
4
4
|
export * from './utils/jsx-types';
|
|
5
5
|
export * from './utils/general';
|
|
6
6
|
export * from './utils/scroll-lock';
|
|
7
|
+
export * from './utils/array-move';
|
|
7
8
|
export * from './hooks/useClickAway';
|
|
8
9
|
export * from './hooks/useComposeRefs';
|
|
9
10
|
export * from './hooks/useDocumentEscapeKeyDown';
|
|
@@ -51,7 +52,7 @@ export { AccordionProps, AccordionSummaryProps, AccordionSummary, AccordionDetai
|
|
|
51
52
|
export { BadgeContainerProps, BadgeContainer, BadgeProps, default as Badge, } from './Badge';
|
|
52
53
|
export { CardProps, CardActionsProps, CardActions, default as Card, } from './Card';
|
|
53
54
|
export { EmptyProps, default as Empty, } from './Empty';
|
|
54
|
-
export { TableProps, TableRefreshProps, TableRefresh, default as Table, } from './Table';
|
|
55
|
+
export { TableProps, TableRefreshProps, TableRefresh, useTableDraggable, useTableScroll, default as Table, } from './Table';
|
|
55
56
|
export { TagSize, TagProps, default as Tag, } from './Tag';
|
|
56
57
|
export { usePagination, PaginationItemProps, PaginationItemType, PaginationItem, PaginationJumperProps, PaginationJumper, PaginationPageSizeProps, PaginationPageSize, PaginationProps, default as Pagination, } from './Pagination';
|
|
57
58
|
export { TreeNodeProp, TreeNodeData, TreeNodeEntity, TreeNodeEntities, TreeNodeRefsShape, TreeNodeRefs, TreeExpandControl, uniqueArray, toggleValue, toggleValueWithStatusControl, traverseTree, UseTreeExpandedValueProps, useTreeExpandedValue, GetTreeNodeEntitiesProps, getTreeNodeEntities, TreeNodeElementProps, TreeNodeProps, TreeNode, TreeNodeListElementProps, TreeNodeListProps, TreeNodeList, TreeProps, default as Tree, } from './Tree';
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { composeRefs } from './utils/composeRefs.js';
|
|
2
2
|
export { getElement } from './utils/getElement.js';
|
|
3
3
|
export { allowBodyScroll, lockBodyScroll } from './utils/scroll-lock.js';
|
|
4
|
+
export { arrayMove } from './utils/array-move.js';
|
|
4
5
|
export { useClickAway } from './hooks/useClickAway.js';
|
|
5
6
|
export { useComposeRefs } from './hooks/useComposeRefs.js';
|
|
6
7
|
export { useDocumentEscapeKeyDown } from './hooks/useDocumentEscapeKeyDown.js';
|
|
@@ -23,6 +24,7 @@ export { useSelectValueControl } from './Form/useSelectValueControl.js';
|
|
|
23
24
|
export { useSwitchControlValue } from './Form/useSwitchControlValue.js';
|
|
24
25
|
export { IconButton } from './Button/index.js';
|
|
25
26
|
export { default as Typography } from './Typography/Typography.js';
|
|
27
|
+
export { default as useTableScroll } from './Table/useTableScroll.js';
|
|
26
28
|
export { default as useModalContainer } from './Modal/useModalContainer.js';
|
|
27
29
|
export { default as Transition } from './Transition/Transition.js';
|
|
28
30
|
export { default as ConfigProvider } from './Provider/ConfigProvider.js';
|
|
@@ -57,6 +59,7 @@ export { default as CardActions } from './Card/CardActions.js';
|
|
|
57
59
|
export { default as Card } from './Card/Card.js';
|
|
58
60
|
export { default as Empty } from './Empty/Empty.js';
|
|
59
61
|
export { default as TableRefresh } from './Table/refresh/TableRefresh.js';
|
|
62
|
+
export { useTableDraggable } from './Table/draggable/useTableDraggable.js';
|
|
60
63
|
export { default as Table } from './Table/Table.js';
|
|
61
64
|
export { default as Tag } from './Tag/Tag.js';
|
|
62
65
|
export { usePagination } from './Pagination/usePagination.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mezzanine-ui/core": "^0.
|
|
35
|
-
"@mezzanine-ui/icons": "^0.
|
|
36
|
-
"@mezzanine-ui/system": "^0.
|
|
34
|
+
"@mezzanine-ui/core": "^0.13.1",
|
|
35
|
+
"@mezzanine-ui/icons": "^0.13.1",
|
|
36
|
+
"@mezzanine-ui/system": "^0.13.1",
|
|
37
37
|
"@popperjs/core": "^2.11.6",
|
|
38
38
|
"@types/react-transition-group": "^4.4.5",
|
|
39
39
|
"clsx": "^1.2.1",
|
|
40
40
|
"lodash": "^4.17.21",
|
|
41
|
+
"react-beautiful-dnd": "^13.1.1",
|
|
41
42
|
"react-popper": "^2.3.0",
|
|
42
43
|
"react-transition-group": "^4.4.5",
|
|
43
44
|
"tslib": "^2.4.1"
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@types/lodash": "^4.14.188",
|
|
50
51
|
"@types/moment": "^2.13.0",
|
|
51
52
|
"@types/react": "^18.0.25",
|
|
53
|
+
"@types/react-beautiful-dnd": "^13.1.4",
|
|
52
54
|
"@types/react-dom": "^18.0.8",
|
|
53
55
|
"@types/react-test-renderer": "^18.0.0",
|
|
54
56
|
"chromatic": "^6.11.4",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function arrayMove(arr: any[], old_index: number, new_index: number): any[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function arrayMove(arr, old_index, new_index) {
|
|
2
|
+
const temp = arr.slice(0);
|
|
3
|
+
if (new_index >= temp.length) {
|
|
4
|
+
let k = new_index - temp.length + 1;
|
|
5
|
+
while ((k -= 1)) {
|
|
6
|
+
temp.push();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
temp.splice(new_index, 0, temp.splice(old_index, 1)[0]);
|
|
10
|
+
return temp;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { arrayMove };
|