@itwin/itwinui-react 1.45.0 → 1.46.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/CHANGELOG.md +20 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/cjs/core/ButtonGroup/ButtonGroup.js +1 -1
- package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/cjs/core/DatePicker/DatePicker.d.ts +24 -4
- package/cjs/core/DatePicker/DatePicker.js +116 -19
- package/cjs/core/Dialog/Dialog.d.ts +5 -5
- package/cjs/core/Dialog/Dialog.js +38 -6
- package/cjs/core/Dialog/DialogBackdrop.d.ts +2 -2
- package/cjs/core/Dialog/DialogBackdrop.js +2 -2
- package/cjs/core/Dialog/DialogContext.d.ts +31 -0
- package/cjs/core/Dialog/DialogDragContext.d.ts +8 -0
- package/cjs/core/Dialog/DialogDragContext.js +28 -0
- package/cjs/core/Dialog/DialogMain.d.ts +2 -2
- package/cjs/core/Dialog/DialogMain.js +46 -6
- package/cjs/core/Dialog/DialogTitleBar.d.ts +2 -2
- package/cjs/core/Dialog/DialogTitleBar.js +12 -2
- package/cjs/core/Modal/Modal.js +1 -1
- package/cjs/core/Table/Table.d.ts +6 -0
- package/cjs/core/Table/Table.js +51 -6
- package/cjs/core/Table/actionHandlers/index.d.ts +1 -1
- package/cjs/core/Table/actionHandlers/index.js +2 -1
- package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/cjs/core/Table/actionHandlers/selectHandler.d.ts +5 -0
- package/cjs/core/Table/actionHandlers/selectHandler.js +35 -2
- package/cjs/core/index.d.ts +3 -1
- package/cjs/core/index.js +6 -3
- package/cjs/core/utils/components/Resizer.d.ts +31 -0
- package/cjs/core/utils/components/Resizer.js +206 -0
- package/cjs/core/utils/components/VirtualScroll.js +26 -24
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- package/cjs/core/utils/functions/index.d.ts +1 -0
- package/cjs/core/utils/functions/index.js +1 -0
- package/cjs/core/utils/functions/styles.d.ts +6 -0
- package/cjs/core/utils/functions/styles.js +21 -0
- package/cjs/core/utils/hooks/useContainerWidth.d.ts +1 -1
- package/cjs/core/utils/hooks/useDragAndDrop.d.ts +14 -0
- package/cjs/core/utils/hooks/useDragAndDrop.js +110 -0
- package/cjs/core/utils/hooks/useEventListener.d.ts +1 -1
- package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
- package/cjs/core/utils/hooks/useResizeObserver.d.ts +1 -1
- package/cjs/types/react-table-config.d.ts +2 -1
- package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
- package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/esm/core/ButtonGroup/ButtonGroup.js +1 -1
- package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/esm/core/DatePicker/DatePicker.d.ts +24 -4
- package/esm/core/DatePicker/DatePicker.js +116 -19
- package/esm/core/Dialog/Dialog.d.ts +5 -5
- package/esm/core/Dialog/Dialog.js +37 -5
- package/esm/core/Dialog/DialogBackdrop.d.ts +2 -2
- package/esm/core/Dialog/DialogBackdrop.js +2 -2
- package/esm/core/Dialog/DialogContext.d.ts +31 -0
- package/esm/core/Dialog/DialogDragContext.d.ts +8 -0
- package/esm/core/Dialog/DialogDragContext.js +21 -0
- package/esm/core/Dialog/DialogMain.d.ts +2 -2
- package/esm/core/Dialog/DialogMain.js +47 -7
- package/esm/core/Dialog/DialogTitleBar.d.ts +2 -2
- package/esm/core/Dialog/DialogTitleBar.js +12 -2
- package/esm/core/Modal/Modal.js +1 -1
- package/esm/core/Table/Table.d.ts +6 -0
- package/esm/core/Table/Table.js +53 -8
- package/esm/core/Table/actionHandlers/index.d.ts +1 -1
- package/esm/core/Table/actionHandlers/index.js +1 -1
- package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/esm/core/Table/actionHandlers/selectHandler.d.ts +5 -0
- package/esm/core/Table/actionHandlers/selectHandler.js +33 -1
- package/esm/core/index.d.ts +3 -1
- package/esm/core/index.js +2 -1
- package/esm/core/utils/components/Resizer.d.ts +31 -0
- package/esm/core/utils/components/Resizer.js +199 -0
- package/esm/core/utils/components/VirtualScroll.js +26 -24
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- package/esm/core/utils/functions/index.d.ts +1 -0
- package/esm/core/utils/functions/index.js +1 -0
- package/esm/core/utils/functions/styles.d.ts +6 -0
- package/esm/core/utils/functions/styles.js +17 -0
- package/esm/core/utils/hooks/useContainerWidth.d.ts +1 -1
- package/esm/core/utils/hooks/useDragAndDrop.d.ts +14 -0
- package/esm/core/utils/hooks/useDragAndDrop.js +103 -0
- package/esm/core/utils/hooks/useEventListener.d.ts +1 -1
- package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
- package/esm/core/utils/hooks/useResizeObserver.d.ts +1 -1
- package/esm/types/react-table-config.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { getBoundedValue, getTranslateValues } from '../functions';
|
|
7
|
+
/**
|
|
8
|
+
* Component that allows to resize parent element.
|
|
9
|
+
* Parent must have `position: relative`.
|
|
10
|
+
* @private
|
|
11
|
+
* @example
|
|
12
|
+
* const ref = React.useRef<HTMLDivElement>(null);
|
|
13
|
+
* return (
|
|
14
|
+
* <div ref={ref} style={{ position: 'relative' }}>
|
|
15
|
+
* <Resizer elementRef={ref} />
|
|
16
|
+
* </div>
|
|
17
|
+
* );
|
|
18
|
+
*/
|
|
19
|
+
export var Resizer = function (props) {
|
|
20
|
+
var elementRef = props.elementRef, containerRef = props.containerRef, onResizeEnd = props.onResizeEnd;
|
|
21
|
+
var onResizePointerDown = function (event) {
|
|
22
|
+
if (!elementRef.current || event.button !== 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var initialPointerX = event.clientX;
|
|
26
|
+
var initialPointerY = event.clientY;
|
|
27
|
+
var _a = getTranslateValues(elementRef.current), initialTranslateX = _a[0], initialTranslateY = _a[1];
|
|
28
|
+
var _b = elementRef.current.getBoundingClientRect(), initialWidth = _b.width, initialHeight = _b.height;
|
|
29
|
+
var width = "".concat(initialWidth, "px");
|
|
30
|
+
var height = "".concat(initialHeight, "px");
|
|
31
|
+
var translateX = initialTranslateX;
|
|
32
|
+
var translateY = initialTranslateY;
|
|
33
|
+
var minWidth = parseFloat(getComputedStyle(elementRef.current).minWidth);
|
|
34
|
+
var minHeight = parseFloat(getComputedStyle(elementRef.current).minHeight);
|
|
35
|
+
var resizer = event.currentTarget.dataset.iuiResizer;
|
|
36
|
+
var originalUserSelect = elementRef.current.ownerDocument.body.style.userSelect;
|
|
37
|
+
elementRef.current.ownerDocument.body.style.userSelect = 'none';
|
|
38
|
+
var onResizePointerMove = function (event) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
40
|
+
if (!elementRef.current) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
44
|
+
var clientX = getBoundedValue(event.clientX, (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _b !== void 0 ? _b : 0, (_d = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : elementRef.current.ownerDocument.documentElement.clientWidth) !== null && _d !== void 0 ? _d : 0);
|
|
45
|
+
var clientY = getBoundedValue(event.clientY, (_e = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _e !== void 0 ? _e : 0, (_g = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : elementRef.current.ownerDocument.documentElement.clientHeight) !== null && _g !== void 0 ? _g : 0);
|
|
46
|
+
var diffX = initialPointerX - clientX;
|
|
47
|
+
var diffY = initialPointerY - clientY;
|
|
48
|
+
switch (resizer) {
|
|
49
|
+
case 'top-left': {
|
|
50
|
+
var newHeight = initialHeight + diffY;
|
|
51
|
+
if (newHeight >= minHeight) {
|
|
52
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
53
|
+
translateY = initialTranslateY - diffY;
|
|
54
|
+
}
|
|
55
|
+
var newWidth = initialWidth + diffX;
|
|
56
|
+
if (newWidth >= minWidth) {
|
|
57
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
58
|
+
translateX = initialTranslateX - diffX;
|
|
59
|
+
}
|
|
60
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'top': {
|
|
64
|
+
var newHeight = initialHeight + diffY;
|
|
65
|
+
if (newHeight < minHeight) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
69
|
+
translateY = initialTranslateY - diffY;
|
|
70
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case 'top-right': {
|
|
74
|
+
var newHeight = initialHeight + diffY;
|
|
75
|
+
if (newHeight >= minHeight) {
|
|
76
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
77
|
+
translateY = initialTranslateY - diffY;
|
|
78
|
+
}
|
|
79
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
80
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'right': {
|
|
84
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'bottom-right': {
|
|
88
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
89
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'bottom': {
|
|
93
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'bottom-left': {
|
|
97
|
+
var newWidth = initialWidth + diffX;
|
|
98
|
+
if (newWidth >= minWidth) {
|
|
99
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
100
|
+
translateX = initialTranslateX - diffX;
|
|
101
|
+
}
|
|
102
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
103
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'left': {
|
|
107
|
+
var newWidth = initialWidth + diffX;
|
|
108
|
+
if (newWidth < minWidth) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
112
|
+
translateX = initialTranslateX - diffX;
|
|
113
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
elementRef.current.ownerDocument.addEventListener('pointermove', onResizePointerMove);
|
|
121
|
+
elementRef.current.ownerDocument.addEventListener('pointerup', function () {
|
|
122
|
+
document.removeEventListener('pointermove', onResizePointerMove);
|
|
123
|
+
if (elementRef.current) {
|
|
124
|
+
elementRef.current.ownerDocument.body.style.userSelect = originalUserSelect;
|
|
125
|
+
onResizeEnd === null || onResizeEnd === void 0 ? void 0 : onResizeEnd({
|
|
126
|
+
width: width,
|
|
127
|
+
height: height,
|
|
128
|
+
transform: "translate(".concat(translateX, "px, ").concat(translateY, "px)"),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, { once: true });
|
|
132
|
+
};
|
|
133
|
+
return (React.createElement(React.Fragment, null,
|
|
134
|
+
React.createElement("div", { "data-iui-resizer": 'top-left', onPointerDown: onResizePointerDown, style: {
|
|
135
|
+
position: 'absolute',
|
|
136
|
+
top: -4,
|
|
137
|
+
left: -4,
|
|
138
|
+
width: 12,
|
|
139
|
+
height: 12,
|
|
140
|
+
cursor: 'nw-resize',
|
|
141
|
+
} }),
|
|
142
|
+
React.createElement("div", { "data-iui-resizer": 'top', onPointerDown: onResizePointerDown, style: {
|
|
143
|
+
position: 'absolute',
|
|
144
|
+
top: -4,
|
|
145
|
+
left: 8,
|
|
146
|
+
right: 8,
|
|
147
|
+
height: 8,
|
|
148
|
+
cursor: 'n-resize',
|
|
149
|
+
} }),
|
|
150
|
+
React.createElement("div", { "data-iui-resizer": 'top-right', onPointerDown: onResizePointerDown, style: {
|
|
151
|
+
position: 'absolute',
|
|
152
|
+
top: -4,
|
|
153
|
+
right: -4,
|
|
154
|
+
width: 12,
|
|
155
|
+
height: 12,
|
|
156
|
+
cursor: 'ne-resize',
|
|
157
|
+
} }),
|
|
158
|
+
React.createElement("div", { "data-iui-resizer": 'right', onPointerDown: onResizePointerDown, style: {
|
|
159
|
+
position: 'absolute',
|
|
160
|
+
top: 8,
|
|
161
|
+
right: -4,
|
|
162
|
+
bottom: 8,
|
|
163
|
+
width: 8,
|
|
164
|
+
cursor: 'e-resize',
|
|
165
|
+
} }),
|
|
166
|
+
React.createElement("div", { "data-iui-resizer": 'bottom-right', onPointerDown: onResizePointerDown, style: {
|
|
167
|
+
position: 'absolute',
|
|
168
|
+
bottom: -4,
|
|
169
|
+
right: -4,
|
|
170
|
+
width: 12,
|
|
171
|
+
height: 12,
|
|
172
|
+
cursor: 'se-resize',
|
|
173
|
+
} }),
|
|
174
|
+
React.createElement("div", { "data-iui-resizer": 'bottom', onPointerDown: onResizePointerDown, style: {
|
|
175
|
+
position: 'absolute',
|
|
176
|
+
bottom: -4,
|
|
177
|
+
left: 8,
|
|
178
|
+
right: 8,
|
|
179
|
+
height: 8,
|
|
180
|
+
cursor: 's-resize',
|
|
181
|
+
} }),
|
|
182
|
+
React.createElement("div", { "data-iui-resizer": 'bottom-left', onPointerDown: onResizePointerDown, style: {
|
|
183
|
+
position: 'absolute',
|
|
184
|
+
bottom: -4,
|
|
185
|
+
left: -4,
|
|
186
|
+
width: 12,
|
|
187
|
+
height: 12,
|
|
188
|
+
cursor: 'sw-resize',
|
|
189
|
+
} }),
|
|
190
|
+
React.createElement("div", { "data-iui-resizer": 'left', onPointerDown: onResizePointerDown, style: {
|
|
191
|
+
position: 'absolute',
|
|
192
|
+
top: 8,
|
|
193
|
+
left: -4,
|
|
194
|
+
bottom: 8,
|
|
195
|
+
width: 8,
|
|
196
|
+
cursor: 'w-resize',
|
|
197
|
+
} })));
|
|
198
|
+
};
|
|
199
|
+
export default Resizer;
|
|
@@ -130,28 +130,6 @@ export var useVirtualization = function (props) {
|
|
|
130
130
|
// Used to mark when scroll container has height (updated by resize observer)
|
|
131
131
|
// because before that calculations are not right
|
|
132
132
|
var _e = React.useState(false), isMounted = _e[0], setIsMounted = _e[1];
|
|
133
|
-
var onResize = React.useCallback(function (_a) {
|
|
134
|
-
var height = _a.height;
|
|
135
|
-
// Initial value returned by resize observer is 0
|
|
136
|
-
// So wait for the next one
|
|
137
|
-
if (height > 0) {
|
|
138
|
-
setIsMounted(true);
|
|
139
|
-
}
|
|
140
|
-
setScrollContainerHeight(height);
|
|
141
|
-
}, []);
|
|
142
|
-
var _f = useResizeObserver(onResize), resizeRef = _f[0], resizeObserver = _f[1];
|
|
143
|
-
// Find scrollable parent
|
|
144
|
-
// Needed only on init
|
|
145
|
-
React.useLayoutEffect(function () {
|
|
146
|
-
var _a;
|
|
147
|
-
var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
|
|
148
|
-
scrollContainer.current = scrollableParent;
|
|
149
|
-
resizeRef(scrollableParent);
|
|
150
|
-
}, [resizeRef]);
|
|
151
|
-
// Stop watching resize, when virtual scroll is unmounted
|
|
152
|
-
React.useLayoutEffect(function () {
|
|
153
|
-
return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
|
|
154
|
-
}, [resizeObserver]);
|
|
155
133
|
var getScrollableContainer = function () {
|
|
156
134
|
var _a, _b;
|
|
157
135
|
return (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
|
|
@@ -164,8 +142,7 @@ export var useVirtualization = function (props) {
|
|
|
164
142
|
}
|
|
165
143
|
return arr;
|
|
166
144
|
}, [itemsLength, itemRenderer, bufferSize, startNode, visibleNodeCount]);
|
|
167
|
-
|
|
168
|
-
React.useLayoutEffect(function () {
|
|
145
|
+
var updateChildHeight = React.useCallback(function () {
|
|
169
146
|
var _a, _b, _c, _d, _e, _f;
|
|
170
147
|
if (!parentRef.current || !visibleChildren.length) {
|
|
171
148
|
return;
|
|
@@ -180,6 +157,31 @@ export var useVirtualization = function (props) {
|
|
|
180
157
|
last: Number((_f = (_e = getElementHeightWithMargins(lastChild)) === null || _e === void 0 ? void 0 : _e.toFixed(2)) !== null && _f !== void 0 ? _f : firstChildHeight),
|
|
181
158
|
};
|
|
182
159
|
}, [visibleChildren.length]);
|
|
160
|
+
var onResize = React.useCallback(function (_a) {
|
|
161
|
+
var height = _a.height;
|
|
162
|
+
// Initial value returned by resize observer is 0
|
|
163
|
+
// So wait for the next one
|
|
164
|
+
if (height > 0) {
|
|
165
|
+
setIsMounted(true);
|
|
166
|
+
}
|
|
167
|
+
setScrollContainerHeight(height);
|
|
168
|
+
updateChildHeight();
|
|
169
|
+
}, [updateChildHeight]);
|
|
170
|
+
var _f = useResizeObserver(onResize), resizeRef = _f[0], resizeObserver = _f[1];
|
|
171
|
+
// Find scrollable parent
|
|
172
|
+
// Needed only on init
|
|
173
|
+
React.useLayoutEffect(function () {
|
|
174
|
+
var _a;
|
|
175
|
+
var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
|
|
176
|
+
scrollContainer.current = scrollableParent;
|
|
177
|
+
resizeRef(scrollableParent);
|
|
178
|
+
}, [resizeRef]);
|
|
179
|
+
// Stop watching resize, when virtual scroll is unmounted
|
|
180
|
+
React.useLayoutEffect(function () {
|
|
181
|
+
return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
|
|
182
|
+
}, [resizeObserver]);
|
|
183
|
+
// Get child height when children available
|
|
184
|
+
React.useLayoutEffect(function () { return updateChildHeight(); }, [updateChildHeight]);
|
|
183
185
|
var updateVirtualScroll = React.useCallback(function () {
|
|
184
186
|
var scrollableContainer = getScrollableContainer();
|
|
185
187
|
if (!scrollableContainer) {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
export * from './Popover';
|
|
6
|
+
export * from './Resizer';
|
|
6
7
|
export * from './FocusTrap';
|
|
7
8
|
export * from './InputContainer';
|
|
8
9
|
export * from './icons';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns translate values as an array of a given element.
|
|
3
|
+
* @param element HTML element you want to get translate value of
|
|
4
|
+
* @returns Translate values in pixels in a array `[translateX, translateY]`
|
|
5
|
+
*/
|
|
6
|
+
export declare const getTranslateValues: (element: HTMLElement | null | undefined) => number[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns translate values as an array of a given element.
|
|
7
|
+
* @param element HTML element you want to get translate value of
|
|
8
|
+
* @returns Translate values in pixels in a array `[translateX, translateY]`
|
|
9
|
+
*/
|
|
10
|
+
export var getTranslateValues = function (element) {
|
|
11
|
+
if (!element) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
var transformValue = getComputedStyle(element).getPropertyValue('transform');
|
|
15
|
+
var matrix = new DOMMatrix(transformValue);
|
|
16
|
+
return [matrix.m41, matrix.m42];
|
|
17
|
+
};
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* ... // do something with width
|
|
14
14
|
* return <div ref={ref}>...</div>;
|
|
15
15
|
*/
|
|
16
|
-
export declare const useContainerWidth: <T extends HTMLElement>(watchResizes?: boolean) => readonly [(instance: HTMLElement | null) => void, number];
|
|
16
|
+
export declare const useContainerWidth: <T extends HTMLElement>(watchResizes?: boolean) => readonly [(instance: HTMLElement | null | undefined) => void, number];
|
|
17
17
|
export default useContainerWidth;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Helper hook that handles elements drag logic.
|
|
4
|
+
* @param elementRef Element ref that is draggable.
|
|
5
|
+
* @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
|
|
6
|
+
* @returns
|
|
7
|
+
* `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
|
|
8
|
+
* `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useDragAndDrop: (elementRef: React.RefObject<HTMLElement>, containerRef?: React.RefObject<HTMLElement>, enabled?: boolean) => {
|
|
11
|
+
onPointerDown: (e: React.PointerEvent<HTMLElement>) => void;
|
|
12
|
+
transform: string;
|
|
13
|
+
};
|
|
14
|
+
export default useDragAndDrop;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { getTranslateValues, getWindow } from '../functions';
|
|
7
|
+
import { useEventListener } from './useEventListener';
|
|
8
|
+
import { useResizeObserver } from './useResizeObserver';
|
|
9
|
+
var getContainerRect = function (containerRef) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
12
|
+
return {
|
|
13
|
+
top: (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _b !== void 0 ? _b : 0,
|
|
14
|
+
right: (_e = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : (_d = getWindow()) === null || _d === void 0 ? void 0 : _d.innerWidth) !== null && _e !== void 0 ? _e : 0,
|
|
15
|
+
bottom: (_h = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : (_g = getWindow()) === null || _g === void 0 ? void 0 : _g.innerHeight) !== null && _h !== void 0 ? _h : 0,
|
|
16
|
+
left: (_j = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _j !== void 0 ? _j : 0,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Helper hook that handles elements drag logic.
|
|
21
|
+
* @param elementRef Element ref that is draggable.
|
|
22
|
+
* @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
|
|
23
|
+
* @returns
|
|
24
|
+
* `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
|
|
25
|
+
* `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
|
|
26
|
+
*/
|
|
27
|
+
export var useDragAndDrop = function (elementRef, containerRef, enabled) {
|
|
28
|
+
if (enabled === void 0) { enabled = true; }
|
|
29
|
+
var grabOffsetX = React.useRef(0);
|
|
30
|
+
var grabOffsetY = React.useRef(0);
|
|
31
|
+
var translateX = React.useRef();
|
|
32
|
+
var translateY = React.useRef();
|
|
33
|
+
var containerRectRef = React.useRef(getContainerRect(containerRef));
|
|
34
|
+
var adjustTransform = React.useCallback(function () {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!elementRef.current || !enabled) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var _b = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(), top = _b.top, right = _b.right, bottom = _b.bottom, left = _b.left;
|
|
40
|
+
var _c = getTranslateValues(elementRef.current), newTranslateX = _c[0], newTranslateY = _c[1];
|
|
41
|
+
containerRectRef.current = getContainerRect(containerRef);
|
|
42
|
+
if (bottom > containerRectRef.current.bottom) {
|
|
43
|
+
newTranslateY -= bottom - containerRectRef.current.bottom;
|
|
44
|
+
}
|
|
45
|
+
if (top < containerRectRef.current.top) {
|
|
46
|
+
newTranslateY += containerRectRef.current.top - top;
|
|
47
|
+
}
|
|
48
|
+
if (right > containerRectRef.current.right) {
|
|
49
|
+
newTranslateX -= right - containerRectRef.current.right;
|
|
50
|
+
}
|
|
51
|
+
if (left < containerRectRef.current.left) {
|
|
52
|
+
newTranslateX += containerRectRef.current.left - left;
|
|
53
|
+
}
|
|
54
|
+
translateX.current = newTranslateX;
|
|
55
|
+
translateY.current = newTranslateY;
|
|
56
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
57
|
+
}, [containerRef, elementRef, enabled]);
|
|
58
|
+
var _a = useResizeObserver(adjustTransform), resizeRef = _a[0], resizeObserver = _a[1];
|
|
59
|
+
resizeRef(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current);
|
|
60
|
+
React.useEffect(function () {
|
|
61
|
+
return function () {
|
|
62
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
63
|
+
};
|
|
64
|
+
}, [resizeObserver]);
|
|
65
|
+
useEventListener('resize', function () {
|
|
66
|
+
adjustTransform();
|
|
67
|
+
if (translateX.current != null && translateY.current != null) {
|
|
68
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
69
|
+
}
|
|
70
|
+
}, getWindow());
|
|
71
|
+
var _b = React.useState(''), transform = _b[0], setTransform = _b[1];
|
|
72
|
+
var onPointerMove = React.useRef(function (event) {
|
|
73
|
+
if (!elementRef.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
var newTranslateX = event.clientX - grabOffsetX.current;
|
|
77
|
+
var newTranslateY = event.clientY - grabOffsetY.current;
|
|
78
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
79
|
+
adjustTransform();
|
|
80
|
+
});
|
|
81
|
+
var originalUserSelect = React.useRef('');
|
|
82
|
+
var onPointerDown = React.useCallback(function (e) {
|
|
83
|
+
if (!elementRef.current || e.button !== 0 || !enabled) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var _a = getTranslateValues(elementRef.current), x = _a[0], y = _a[1];
|
|
87
|
+
grabOffsetX.current = e.clientX - x;
|
|
88
|
+
grabOffsetY.current = e.clientY - y;
|
|
89
|
+
originalUserSelect.current = elementRef.current.style.userSelect;
|
|
90
|
+
// Prevents from selecting inner content when dragging.
|
|
91
|
+
elementRef.current.style.userSelect = 'none';
|
|
92
|
+
elementRef.current.ownerDocument.addEventListener('pointermove', onPointerMove.current);
|
|
93
|
+
elementRef.current.ownerDocument.addEventListener('pointerup', function () {
|
|
94
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
95
|
+
document.removeEventListener('pointermove', onPointerMove.current);
|
|
96
|
+
if (elementRef.current) {
|
|
97
|
+
elementRef.current.style.userSelect = originalUserSelect.current;
|
|
98
|
+
}
|
|
99
|
+
}, { once: true });
|
|
100
|
+
}, [elementRef, enabled]);
|
|
101
|
+
return { onPointerDown: onPointerDown, transform: transform };
|
|
102
|
+
};
|
|
103
|
+
export default useDragAndDrop;
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* containerRef.current?.ownerDocument,
|
|
8
8
|
* );
|
|
9
9
|
*/
|
|
10
|
-
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | undefined) => void;
|
|
10
|
+
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | Window | undefined) => void;
|
|
@@ -21,4 +21,4 @@ import React from 'react';
|
|
|
21
21
|
* </div>
|
|
22
22
|
* );
|
|
23
23
|
*/
|
|
24
|
-
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => readonly [(instance: T | null) => void, number];
|
|
24
|
+
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => readonly [(instance: T | null | undefined) => void, number];
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* ...
|
|
11
11
|
* return <div ref={ref}>...</div>;
|
|
12
12
|
*/
|
|
13
|
-
export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null) => void, ResizeObserver | undefined];
|
|
13
|
+
export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null | undefined) => void, ResizeObserver | undefined];
|
|
@@ -19,7 +19,7 @@ declare module 'react-table' {
|
|
|
19
19
|
*/
|
|
20
20
|
isDisabled?: (rowData: D) => boolean;
|
|
21
21
|
};
|
|
22
|
-
interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
|
|
22
|
+
interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, UseGlobalFiltersOptions<D>, UseGlobalFiltersColumnOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
|
|
23
23
|
/**
|
|
24
24
|
* Table data list.
|
|
25
25
|
* Must be memoized.
|
|
@@ -50,6 +50,7 @@ declare module 'react-table' {
|
|
|
50
50
|
isScrolledToRight?: boolean;
|
|
51
51
|
isScrolledToLeft?: boolean;
|
|
52
52
|
};
|
|
53
|
+
lastSelectedRowId?: string;
|
|
53
54
|
}
|
|
54
55
|
interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
|
|
55
56
|
/**
|