@itwin/itwinui-react 1.44.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 +27 -0
- package/README.md +2 -2
- 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 +9 -1
- package/cjs/core/Table/Table.js +51 -6
- package/cjs/core/Table/TableRowMemoized.d.ts +10 -2
- package/cjs/core/Table/TableRowMemoized.js +23 -7
- 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/Table/cells/DefaultCell.d.ts +14 -1
- package/cjs/core/Table/cells/DefaultCell.js +10 -4
- package/cjs/core/index.d.ts +3 -1
- package/cjs/core/index.js +6 -3
- package/cjs/core/utils/components/MiddleTextTruncation.d.ts +15 -1
- package/cjs/core/utils/components/MiddleTextTruncation.js +14 -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 +9 -1
- package/esm/core/Table/Table.js +53 -8
- package/esm/core/Table/TableRowMemoized.d.ts +10 -2
- package/esm/core/Table/TableRowMemoized.js +23 -7
- 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/Table/cells/DefaultCell.d.ts +14 -1
- package/esm/core/Table/cells/DefaultCell.js +10 -4
- package/esm/core/index.d.ts +3 -1
- package/esm/core/index.js +2 -1
- package/esm/core/utils/components/MiddleTextTruncation.d.ts +15 -1
- package/esm/core/utils/components/MiddleTextTruncation.js +14 -3
- 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,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
|
/**
|