@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,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Resizer = void 0;
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
9
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
var react_1 = __importDefault(require("react"));
|
|
12
|
+
var functions_1 = require("../functions");
|
|
13
|
+
/**
|
|
14
|
+
* Component that allows to resize parent element.
|
|
15
|
+
* Parent must have `position: relative`.
|
|
16
|
+
* @private
|
|
17
|
+
* @example
|
|
18
|
+
* const ref = React.useRef<HTMLDivElement>(null);
|
|
19
|
+
* return (
|
|
20
|
+
* <div ref={ref} style={{ position: 'relative' }}>
|
|
21
|
+
* <Resizer elementRef={ref} />
|
|
22
|
+
* </div>
|
|
23
|
+
* );
|
|
24
|
+
*/
|
|
25
|
+
var Resizer = function (props) {
|
|
26
|
+
var elementRef = props.elementRef, containerRef = props.containerRef, onResizeEnd = props.onResizeEnd;
|
|
27
|
+
var onResizePointerDown = function (event) {
|
|
28
|
+
if (!elementRef.current || event.button !== 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var initialPointerX = event.clientX;
|
|
32
|
+
var initialPointerY = event.clientY;
|
|
33
|
+
var _a = (0, functions_1.getTranslateValues)(elementRef.current), initialTranslateX = _a[0], initialTranslateY = _a[1];
|
|
34
|
+
var _b = elementRef.current.getBoundingClientRect(), initialWidth = _b.width, initialHeight = _b.height;
|
|
35
|
+
var width = "".concat(initialWidth, "px");
|
|
36
|
+
var height = "".concat(initialHeight, "px");
|
|
37
|
+
var translateX = initialTranslateX;
|
|
38
|
+
var translateY = initialTranslateY;
|
|
39
|
+
var minWidth = parseFloat(getComputedStyle(elementRef.current).minWidth);
|
|
40
|
+
var minHeight = parseFloat(getComputedStyle(elementRef.current).minHeight);
|
|
41
|
+
var resizer = event.currentTarget.dataset.iuiResizer;
|
|
42
|
+
var originalUserSelect = elementRef.current.ownerDocument.body.style.userSelect;
|
|
43
|
+
elementRef.current.ownerDocument.body.style.userSelect = 'none';
|
|
44
|
+
var onResizePointerMove = function (event) {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
46
|
+
if (!elementRef.current) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
50
|
+
var clientX = (0, functions_1.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);
|
|
51
|
+
var clientY = (0, functions_1.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);
|
|
52
|
+
var diffX = initialPointerX - clientX;
|
|
53
|
+
var diffY = initialPointerY - clientY;
|
|
54
|
+
switch (resizer) {
|
|
55
|
+
case 'top-left': {
|
|
56
|
+
var newHeight = initialHeight + diffY;
|
|
57
|
+
if (newHeight >= minHeight) {
|
|
58
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
59
|
+
translateY = initialTranslateY - diffY;
|
|
60
|
+
}
|
|
61
|
+
var newWidth = initialWidth + diffX;
|
|
62
|
+
if (newWidth >= minWidth) {
|
|
63
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
64
|
+
translateX = initialTranslateX - diffX;
|
|
65
|
+
}
|
|
66
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'top': {
|
|
70
|
+
var newHeight = initialHeight + diffY;
|
|
71
|
+
if (newHeight < minHeight) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
75
|
+
translateY = initialTranslateY - diffY;
|
|
76
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'top-right': {
|
|
80
|
+
var newHeight = initialHeight + diffY;
|
|
81
|
+
if (newHeight >= minHeight) {
|
|
82
|
+
height = elementRef.current.style.height = "".concat(newHeight, "px");
|
|
83
|
+
translateY = initialTranslateY - diffY;
|
|
84
|
+
}
|
|
85
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
86
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'right': {
|
|
90
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case 'bottom-right': {
|
|
94
|
+
width = elementRef.current.style.width = "".concat(initialWidth - diffX, "px");
|
|
95
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'bottom': {
|
|
99
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'bottom-left': {
|
|
103
|
+
var newWidth = initialWidth + diffX;
|
|
104
|
+
if (newWidth >= minWidth) {
|
|
105
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
106
|
+
translateX = initialTranslateX - diffX;
|
|
107
|
+
}
|
|
108
|
+
height = elementRef.current.style.height = "".concat(initialHeight - diffY, "px");
|
|
109
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 'left': {
|
|
113
|
+
var newWidth = initialWidth + diffX;
|
|
114
|
+
if (newWidth < minWidth) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
width = elementRef.current.style.width = "".concat(newWidth, "px");
|
|
118
|
+
translateX = initialTranslateX - diffX;
|
|
119
|
+
elementRef.current.style.transform = "translate(".concat(translateX, "px, ").concat(translateY, "px)");
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
elementRef.current.ownerDocument.addEventListener('pointermove', onResizePointerMove);
|
|
127
|
+
elementRef.current.ownerDocument.addEventListener('pointerup', function () {
|
|
128
|
+
document.removeEventListener('pointermove', onResizePointerMove);
|
|
129
|
+
if (elementRef.current) {
|
|
130
|
+
elementRef.current.ownerDocument.body.style.userSelect = originalUserSelect;
|
|
131
|
+
onResizeEnd === null || onResizeEnd === void 0 ? void 0 : onResizeEnd({
|
|
132
|
+
width: width,
|
|
133
|
+
height: height,
|
|
134
|
+
transform: "translate(".concat(translateX, "px, ").concat(translateY, "px)"),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}, { once: true });
|
|
138
|
+
};
|
|
139
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
140
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'top-left', onPointerDown: onResizePointerDown, style: {
|
|
141
|
+
position: 'absolute',
|
|
142
|
+
top: -4,
|
|
143
|
+
left: -4,
|
|
144
|
+
width: 12,
|
|
145
|
+
height: 12,
|
|
146
|
+
cursor: 'nw-resize',
|
|
147
|
+
} }),
|
|
148
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'top', onPointerDown: onResizePointerDown, style: {
|
|
149
|
+
position: 'absolute',
|
|
150
|
+
top: -4,
|
|
151
|
+
left: 8,
|
|
152
|
+
right: 8,
|
|
153
|
+
height: 8,
|
|
154
|
+
cursor: 'n-resize',
|
|
155
|
+
} }),
|
|
156
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'top-right', onPointerDown: onResizePointerDown, style: {
|
|
157
|
+
position: 'absolute',
|
|
158
|
+
top: -4,
|
|
159
|
+
right: -4,
|
|
160
|
+
width: 12,
|
|
161
|
+
height: 12,
|
|
162
|
+
cursor: 'ne-resize',
|
|
163
|
+
} }),
|
|
164
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'right', onPointerDown: onResizePointerDown, style: {
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
top: 8,
|
|
167
|
+
right: -4,
|
|
168
|
+
bottom: 8,
|
|
169
|
+
width: 8,
|
|
170
|
+
cursor: 'e-resize',
|
|
171
|
+
} }),
|
|
172
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'bottom-right', onPointerDown: onResizePointerDown, style: {
|
|
173
|
+
position: 'absolute',
|
|
174
|
+
bottom: -4,
|
|
175
|
+
right: -4,
|
|
176
|
+
width: 12,
|
|
177
|
+
height: 12,
|
|
178
|
+
cursor: 'se-resize',
|
|
179
|
+
} }),
|
|
180
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'bottom', onPointerDown: onResizePointerDown, style: {
|
|
181
|
+
position: 'absolute',
|
|
182
|
+
bottom: -4,
|
|
183
|
+
left: 8,
|
|
184
|
+
right: 8,
|
|
185
|
+
height: 8,
|
|
186
|
+
cursor: 's-resize',
|
|
187
|
+
} }),
|
|
188
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'bottom-left', onPointerDown: onResizePointerDown, style: {
|
|
189
|
+
position: 'absolute',
|
|
190
|
+
bottom: -4,
|
|
191
|
+
left: -4,
|
|
192
|
+
width: 12,
|
|
193
|
+
height: 12,
|
|
194
|
+
cursor: 'sw-resize',
|
|
195
|
+
} }),
|
|
196
|
+
react_1.default.createElement("div", { "data-iui-resizer": 'left', onPointerDown: onResizePointerDown, style: {
|
|
197
|
+
position: 'absolute',
|
|
198
|
+
top: 8,
|
|
199
|
+
left: -4,
|
|
200
|
+
bottom: 8,
|
|
201
|
+
width: 8,
|
|
202
|
+
cursor: 'w-resize',
|
|
203
|
+
} })));
|
|
204
|
+
};
|
|
205
|
+
exports.Resizer = Resizer;
|
|
206
|
+
exports.default = exports.Resizer;
|
|
@@ -136,28 +136,6 @@ var useVirtualization = function (props) {
|
|
|
136
136
|
// Used to mark when scroll container has height (updated by resize observer)
|
|
137
137
|
// because before that calculations are not right
|
|
138
138
|
var _e = react_1.default.useState(false), isMounted = _e[0], setIsMounted = _e[1];
|
|
139
|
-
var onResize = react_1.default.useCallback(function (_a) {
|
|
140
|
-
var height = _a.height;
|
|
141
|
-
// Initial value returned by resize observer is 0
|
|
142
|
-
// So wait for the next one
|
|
143
|
-
if (height > 0) {
|
|
144
|
-
setIsMounted(true);
|
|
145
|
-
}
|
|
146
|
-
setScrollContainerHeight(height);
|
|
147
|
-
}, []);
|
|
148
|
-
var _f = (0, useResizeObserver_1.useResizeObserver)(onResize), resizeRef = _f[0], resizeObserver = _f[1];
|
|
149
|
-
// Find scrollable parent
|
|
150
|
-
// Needed only on init
|
|
151
|
-
react_1.default.useLayoutEffect(function () {
|
|
152
|
-
var _a;
|
|
153
|
-
var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
|
|
154
|
-
scrollContainer.current = scrollableParent;
|
|
155
|
-
resizeRef(scrollableParent);
|
|
156
|
-
}, [resizeRef]);
|
|
157
|
-
// Stop watching resize, when virtual scroll is unmounted
|
|
158
|
-
react_1.default.useLayoutEffect(function () {
|
|
159
|
-
return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
|
|
160
|
-
}, [resizeObserver]);
|
|
161
139
|
var getScrollableContainer = function () {
|
|
162
140
|
var _a, _b;
|
|
163
141
|
return (_a = scrollContainer.current) !== null && _a !== void 0 ? _a : (_b = parentRef.current) === null || _b === void 0 ? void 0 : _b.ownerDocument.scrollingElement;
|
|
@@ -170,8 +148,7 @@ var useVirtualization = function (props) {
|
|
|
170
148
|
}
|
|
171
149
|
return arr;
|
|
172
150
|
}, [itemsLength, itemRenderer, bufferSize, startNode, visibleNodeCount]);
|
|
173
|
-
|
|
174
|
-
react_1.default.useLayoutEffect(function () {
|
|
151
|
+
var updateChildHeight = react_1.default.useCallback(function () {
|
|
175
152
|
var _a, _b, _c, _d, _e, _f;
|
|
176
153
|
if (!parentRef.current || !visibleChildren.length) {
|
|
177
154
|
return;
|
|
@@ -186,6 +163,31 @@ var useVirtualization = function (props) {
|
|
|
186
163
|
last: Number((_f = (_e = getElementHeightWithMargins(lastChild)) === null || _e === void 0 ? void 0 : _e.toFixed(2)) !== null && _f !== void 0 ? _f : firstChildHeight),
|
|
187
164
|
};
|
|
188
165
|
}, [visibleChildren.length]);
|
|
166
|
+
var onResize = react_1.default.useCallback(function (_a) {
|
|
167
|
+
var height = _a.height;
|
|
168
|
+
// Initial value returned by resize observer is 0
|
|
169
|
+
// So wait for the next one
|
|
170
|
+
if (height > 0) {
|
|
171
|
+
setIsMounted(true);
|
|
172
|
+
}
|
|
173
|
+
setScrollContainerHeight(height);
|
|
174
|
+
updateChildHeight();
|
|
175
|
+
}, [updateChildHeight]);
|
|
176
|
+
var _f = (0, useResizeObserver_1.useResizeObserver)(onResize), resizeRef = _f[0], resizeObserver = _f[1];
|
|
177
|
+
// Find scrollable parent
|
|
178
|
+
// Needed only on init
|
|
179
|
+
react_1.default.useLayoutEffect(function () {
|
|
180
|
+
var _a;
|
|
181
|
+
var scrollableParent = getScrollableParent(parentRef.current, (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument);
|
|
182
|
+
scrollContainer.current = scrollableParent;
|
|
183
|
+
resizeRef(scrollableParent);
|
|
184
|
+
}, [resizeRef]);
|
|
185
|
+
// Stop watching resize, when virtual scroll is unmounted
|
|
186
|
+
react_1.default.useLayoutEffect(function () {
|
|
187
|
+
return function () { return resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect(); };
|
|
188
|
+
}, [resizeObserver]);
|
|
189
|
+
// Get child height when children available
|
|
190
|
+
react_1.default.useLayoutEffect(function () { return updateChildHeight(); }, [updateChildHeight]);
|
|
189
191
|
var updateVirtualScroll = react_1.default.useCallback(function () {
|
|
190
192
|
var scrollableContainer = getScrollableContainer();
|
|
191
193
|
if (!scrollableContainer) {
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
20
20
|
*--------------------------------------------------------------------------------------------*/
|
|
21
21
|
__exportStar(require("./Popover"), exports);
|
|
22
|
+
__exportStar(require("./Resizer"), exports);
|
|
22
23
|
__exportStar(require("./FocusTrap"), exports);
|
|
23
24
|
__exportStar(require("./InputContainer"), exports);
|
|
24
25
|
__exportStar(require("./icons"), exports);
|
|
@@ -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,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getTranslateValues = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Returns translate values as an array of a given element.
|
|
10
|
+
* @param element HTML element you want to get translate value of
|
|
11
|
+
* @returns Translate values in pixels in a array `[translateX, translateY]`
|
|
12
|
+
*/
|
|
13
|
+
var getTranslateValues = function (element) {
|
|
14
|
+
if (!element) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
var transformValue = getComputedStyle(element).getPropertyValue('transform');
|
|
18
|
+
var matrix = new DOMMatrix(transformValue);
|
|
19
|
+
return [matrix.m41, matrix.m42];
|
|
20
|
+
};
|
|
21
|
+
exports.getTranslateValues = getTranslateValues;
|
|
@@ -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,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useDragAndDrop = void 0;
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
9
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
var react_1 = __importDefault(require("react"));
|
|
12
|
+
var functions_1 = require("../functions");
|
|
13
|
+
var useEventListener_1 = require("./useEventListener");
|
|
14
|
+
var useResizeObserver_1 = require("./useResizeObserver");
|
|
15
|
+
var getContainerRect = function (containerRef) {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
17
|
+
var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
18
|
+
return {
|
|
19
|
+
top: (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _b !== void 0 ? _b : 0,
|
|
20
|
+
right: (_e = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : (_d = (0, functions_1.getWindow)()) === null || _d === void 0 ? void 0 : _d.innerWidth) !== null && _e !== void 0 ? _e : 0,
|
|
21
|
+
bottom: (_h = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : (_g = (0, functions_1.getWindow)()) === null || _g === void 0 ? void 0 : _g.innerHeight) !== null && _h !== void 0 ? _h : 0,
|
|
22
|
+
left: (_j = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _j !== void 0 ? _j : 0,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Helper hook that handles elements drag logic.
|
|
27
|
+
* @param elementRef Element ref that is draggable.
|
|
28
|
+
* @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
|
|
29
|
+
* @returns
|
|
30
|
+
* `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
|
|
31
|
+
* `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
|
|
32
|
+
*/
|
|
33
|
+
var useDragAndDrop = function (elementRef, containerRef, enabled) {
|
|
34
|
+
if (enabled === void 0) { enabled = true; }
|
|
35
|
+
var grabOffsetX = react_1.default.useRef(0);
|
|
36
|
+
var grabOffsetY = react_1.default.useRef(0);
|
|
37
|
+
var translateX = react_1.default.useRef();
|
|
38
|
+
var translateY = react_1.default.useRef();
|
|
39
|
+
var containerRectRef = react_1.default.useRef(getContainerRect(containerRef));
|
|
40
|
+
var adjustTransform = react_1.default.useCallback(function () {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!elementRef.current || !enabled) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
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;
|
|
46
|
+
var _c = (0, functions_1.getTranslateValues)(elementRef.current), newTranslateX = _c[0], newTranslateY = _c[1];
|
|
47
|
+
containerRectRef.current = getContainerRect(containerRef);
|
|
48
|
+
if (bottom > containerRectRef.current.bottom) {
|
|
49
|
+
newTranslateY -= bottom - containerRectRef.current.bottom;
|
|
50
|
+
}
|
|
51
|
+
if (top < containerRectRef.current.top) {
|
|
52
|
+
newTranslateY += containerRectRef.current.top - top;
|
|
53
|
+
}
|
|
54
|
+
if (right > containerRectRef.current.right) {
|
|
55
|
+
newTranslateX -= right - containerRectRef.current.right;
|
|
56
|
+
}
|
|
57
|
+
if (left < containerRectRef.current.left) {
|
|
58
|
+
newTranslateX += containerRectRef.current.left - left;
|
|
59
|
+
}
|
|
60
|
+
translateX.current = newTranslateX;
|
|
61
|
+
translateY.current = newTranslateY;
|
|
62
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
63
|
+
}, [containerRef, elementRef, enabled]);
|
|
64
|
+
var _a = (0, useResizeObserver_1.useResizeObserver)(adjustTransform), resizeRef = _a[0], resizeObserver = _a[1];
|
|
65
|
+
resizeRef(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current);
|
|
66
|
+
react_1.default.useEffect(function () {
|
|
67
|
+
return function () {
|
|
68
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
69
|
+
};
|
|
70
|
+
}, [resizeObserver]);
|
|
71
|
+
(0, useEventListener_1.useEventListener)('resize', function () {
|
|
72
|
+
adjustTransform();
|
|
73
|
+
if (translateX.current != null && translateY.current != null) {
|
|
74
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
75
|
+
}
|
|
76
|
+
}, (0, functions_1.getWindow)());
|
|
77
|
+
var _b = react_1.default.useState(''), transform = _b[0], setTransform = _b[1];
|
|
78
|
+
var onPointerMove = react_1.default.useRef(function (event) {
|
|
79
|
+
if (!elementRef.current) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var newTranslateX = event.clientX - grabOffsetX.current;
|
|
83
|
+
var newTranslateY = event.clientY - grabOffsetY.current;
|
|
84
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
85
|
+
adjustTransform();
|
|
86
|
+
});
|
|
87
|
+
var originalUserSelect = react_1.default.useRef('');
|
|
88
|
+
var onPointerDown = react_1.default.useCallback(function (e) {
|
|
89
|
+
if (!elementRef.current || e.button !== 0 || !enabled) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var _a = (0, functions_1.getTranslateValues)(elementRef.current), x = _a[0], y = _a[1];
|
|
93
|
+
grabOffsetX.current = e.clientX - x;
|
|
94
|
+
grabOffsetY.current = e.clientY - y;
|
|
95
|
+
originalUserSelect.current = elementRef.current.style.userSelect;
|
|
96
|
+
// Prevents from selecting inner content when dragging.
|
|
97
|
+
elementRef.current.style.userSelect = 'none';
|
|
98
|
+
elementRef.current.ownerDocument.addEventListener('pointermove', onPointerMove.current);
|
|
99
|
+
elementRef.current.ownerDocument.addEventListener('pointerup', function () {
|
|
100
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
101
|
+
document.removeEventListener('pointermove', onPointerMove.current);
|
|
102
|
+
if (elementRef.current) {
|
|
103
|
+
elementRef.current.style.userSelect = originalUserSelect.current;
|
|
104
|
+
}
|
|
105
|
+
}, { once: true });
|
|
106
|
+
}, [elementRef, enabled]);
|
|
107
|
+
return { onPointerDown: onPointerDown, transform: transform };
|
|
108
|
+
};
|
|
109
|
+
exports.useDragAndDrop = useDragAndDrop;
|
|
110
|
+
exports.default = exports.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
|
/**
|
|
@@ -16,6 +16,64 @@ export declare type BreadcrumbsProps = {
|
|
|
16
16
|
* Defaults to the `SvgChevronRight` icon.
|
|
17
17
|
*/
|
|
18
18
|
separator?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* If specified, this prop will be used to show a custom button when overflow happens,
|
|
21
|
+
* i.e. when there is not enough space to fit all the breadcrumbs.
|
|
22
|
+
*
|
|
23
|
+
* Expects a function that takes the number of items that are visible
|
|
24
|
+
* and returns the `ReactNode` to render.
|
|
25
|
+
*
|
|
26
|
+
* @example <caption>Uses the overflow button to redirect to the previous breadcrumb</caption>
|
|
27
|
+
* <Breadcrumbs
|
|
28
|
+
* overflowButton={(visibleCount: number) => {
|
|
29
|
+
* const previousBreadcrumb = visibleCount > 1 ? items.length - visibleCount : items.length - 2;
|
|
30
|
+
* return (
|
|
31
|
+
* <Tooltip content={`Item ${previousBreadcrumb}`} placement='bottom'>
|
|
32
|
+
* <IconButton
|
|
33
|
+
* onClick={() => {
|
|
34
|
+
* // click on "previousBreadcrumb"
|
|
35
|
+
* }}
|
|
36
|
+
* >
|
|
37
|
+
* <SvgMoreSmall />
|
|
38
|
+
* </IconButton>
|
|
39
|
+
* </Tooltip>
|
|
40
|
+
* );
|
|
41
|
+
* }}
|
|
42
|
+
* >
|
|
43
|
+
* {items}
|
|
44
|
+
* </Breadcrumbs>
|
|
45
|
+
*
|
|
46
|
+
* @example <caption>Uses the overflow button to add a dropdown that contains hidden breadcrumbs</caption>
|
|
47
|
+
* <Breadcrumbs
|
|
48
|
+
* overflowButton={(visibleCount) => (
|
|
49
|
+
* <DropdownMenu
|
|
50
|
+
* menuItems={(close) =>
|
|
51
|
+
* Array(items.length - visibleCount)
|
|
52
|
+
* .fill(null)
|
|
53
|
+
* .map((_, _index) => {
|
|
54
|
+
* const index = visibleCount > 1 ? _index + 1 : _index;
|
|
55
|
+
* const onClick = () => {
|
|
56
|
+
* // click on "index" breadcrumb
|
|
57
|
+
* close();
|
|
58
|
+
* };
|
|
59
|
+
* return (
|
|
60
|
+
* <MenuItem key={index} onClick={onClick}>
|
|
61
|
+
* Item {index}
|
|
62
|
+
* </MenuItem>
|
|
63
|
+
* );
|
|
64
|
+
* })
|
|
65
|
+
* }
|
|
66
|
+
* >
|
|
67
|
+
* <IconButton>
|
|
68
|
+
* <SvgMoreSmall />
|
|
69
|
+
* </IconButton>
|
|
70
|
+
* </DropdownMenu>
|
|
71
|
+
* )}
|
|
72
|
+
* >
|
|
73
|
+
* {items}
|
|
74
|
+
* </Breadcrumbs>
|
|
75
|
+
*/
|
|
76
|
+
overflowButton?: (visibleCount: number) => React.ReactNode;
|
|
19
77
|
} & Omit<CommonProps, 'title'>;
|
|
20
78
|
/**
|
|
21
79
|
* A breadcrumb trail is used as a navigational aid to help users keep track
|
|
@@ -54,5 +112,63 @@ export declare const Breadcrumbs: React.ForwardRefExoticComponent<{
|
|
|
54
112
|
* Defaults to the `SvgChevronRight` icon.
|
|
55
113
|
*/
|
|
56
114
|
separator?: React.ReactNode;
|
|
115
|
+
/**
|
|
116
|
+
* If specified, this prop will be used to show a custom button when overflow happens,
|
|
117
|
+
* i.e. when there is not enough space to fit all the breadcrumbs.
|
|
118
|
+
*
|
|
119
|
+
* Expects a function that takes the number of items that are visible
|
|
120
|
+
* and returns the `ReactNode` to render.
|
|
121
|
+
*
|
|
122
|
+
* @example <caption>Uses the overflow button to redirect to the previous breadcrumb</caption>
|
|
123
|
+
* <Breadcrumbs
|
|
124
|
+
* overflowButton={(visibleCount: number) => {
|
|
125
|
+
* const previousBreadcrumb = visibleCount > 1 ? items.length - visibleCount : items.length - 2;
|
|
126
|
+
* return (
|
|
127
|
+
* <Tooltip content={`Item ${previousBreadcrumb}`} placement='bottom'>
|
|
128
|
+
* <IconButton
|
|
129
|
+
* onClick={() => {
|
|
130
|
+
* // click on "previousBreadcrumb"
|
|
131
|
+
* }}
|
|
132
|
+
* >
|
|
133
|
+
* <SvgMoreSmall />
|
|
134
|
+
* </IconButton>
|
|
135
|
+
* </Tooltip>
|
|
136
|
+
* );
|
|
137
|
+
* }}
|
|
138
|
+
* >
|
|
139
|
+
* {items}
|
|
140
|
+
* </Breadcrumbs>
|
|
141
|
+
*
|
|
142
|
+
* @example <caption>Uses the overflow button to add a dropdown that contains hidden breadcrumbs</caption>
|
|
143
|
+
* <Breadcrumbs
|
|
144
|
+
* overflowButton={(visibleCount) => (
|
|
145
|
+
* <DropdownMenu
|
|
146
|
+
* menuItems={(close) =>
|
|
147
|
+
* Array(items.length - visibleCount)
|
|
148
|
+
* .fill(null)
|
|
149
|
+
* .map((_, _index) => {
|
|
150
|
+
* const index = visibleCount > 1 ? _index + 1 : _index;
|
|
151
|
+
* const onClick = () => {
|
|
152
|
+
* // click on "index" breadcrumb
|
|
153
|
+
* close();
|
|
154
|
+
* };
|
|
155
|
+
* return (
|
|
156
|
+
* <MenuItem key={index} onClick={onClick}>
|
|
157
|
+
* Item {index}
|
|
158
|
+
* </MenuItem>
|
|
159
|
+
* );
|
|
160
|
+
* })
|
|
161
|
+
* }
|
|
162
|
+
* >
|
|
163
|
+
* <IconButton>
|
|
164
|
+
* <SvgMoreSmall />
|
|
165
|
+
* </IconButton>
|
|
166
|
+
* </DropdownMenu>
|
|
167
|
+
* )}
|
|
168
|
+
* >
|
|
169
|
+
* {items}
|
|
170
|
+
* </Breadcrumbs>
|
|
171
|
+
*/
|
|
172
|
+
overflowButton?: ((visibleCount: number) => React.ReactNode) | undefined;
|
|
57
173
|
} & Omit<CommonProps, "title"> & React.RefAttributes<HTMLElement>>;
|
|
58
174
|
export default Breadcrumbs;
|