@snack-uikit/list 0.29.6-preview-d65ce031.0 → 0.29.6
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
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.29.6 (2025-06-19)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/info-block@0.6.25](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/info-block/CHANGELOG.md)
|
|
10
|
+
* [@snack-uikit/truncate-string@0.6.21](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/truncate-string/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
6
16
|
## 0.29.5 (2025-06-16)
|
|
7
17
|
|
|
8
18
|
### Only dependencies have been changed
|
|
@@ -20,7 +20,6 @@ exports.ListPrivate = void 0;
|
|
|
20
20
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
21
|
const react_virtual_1 = require("@tanstack/react-virtual");
|
|
22
22
|
const classnames_1 = __importDefault(require("classnames"));
|
|
23
|
-
const merge_refs_1 = __importDefault(require("merge-refs"));
|
|
24
23
|
const react_1 = require("react");
|
|
25
24
|
const loaders_1 = require("@snack-uikit/loaders");
|
|
26
25
|
const scroll_1 = require("@snack-uikit/scroll");
|
|
@@ -84,47 +83,16 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
84
83
|
errorDataState
|
|
85
84
|
});
|
|
86
85
|
const hasNoItems = items.length === 0;
|
|
87
|
-
const memoizedFocusFlattenItems = (0, react_1.useMemo)(() => Object.values(focusFlattenItems), [focusFlattenItems]);
|
|
88
|
-
const selectedItemIndex = (0, react_1.useMemo)(() => {
|
|
89
|
-
if (!scrollToSelectedItem || !value) {
|
|
90
|
-
return -1;
|
|
91
|
-
}
|
|
92
|
-
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
93
|
-
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
94
|
-
return -1;
|
|
95
|
-
}
|
|
96
|
-
return memoizedFocusFlattenItems.findIndex(item => item.originalId === selectedItem.id);
|
|
97
|
-
}, [flattenItems, memoizedFocusFlattenItems, isSelectionSingle, scrollToSelectedItem, value]);
|
|
98
86
|
const virtualizer = (0, react_virtual_1.useVirtualizer)({
|
|
99
87
|
count: itemsJSX.length,
|
|
100
88
|
getScrollElement: () => scroll ? innerScrollRef.current : null,
|
|
101
89
|
estimateSize: () => constants_1.ALL_SIZES[size],
|
|
102
|
-
enabled: virtualized
|
|
103
|
-
overscan: 5 // Amount of elements in DOM before/after visible ones
|
|
90
|
+
enabled: virtualized
|
|
104
91
|
});
|
|
105
92
|
const virtualItems = virtualizer.getVirtualItems();
|
|
106
93
|
(0, react_1.useEffect)(() => {
|
|
107
94
|
virtualizer.measure();
|
|
108
95
|
}, [virtualizer]);
|
|
109
|
-
(0, react_1.useEffect)(() => {
|
|
110
|
-
if (scroll && scrollToSelectedItem && virtualized) {
|
|
111
|
-
if (selectedItemIndex < 0) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
requestAnimationFrame(() => {
|
|
115
|
-
virtualizer.scrollToIndex(selectedItemIndex, {
|
|
116
|
-
align: 'center'
|
|
117
|
-
});
|
|
118
|
-
requestAnimationFrame(() => {
|
|
119
|
-
var _a, _b;
|
|
120
|
-
const itemToScrollTo = memoizedFocusFlattenItems[selectedItemIndex];
|
|
121
|
-
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({
|
|
122
|
-
block: 'center'
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}, [selectedItemIndex, scroll, scrollToSelectedItem, virtualized, virtualizer, memoizedFocusFlattenItems]);
|
|
128
96
|
const loadingJSX = (0, react_1.useMemo)(() => loading && (0, jsx_runtime_1.jsx)("div", {
|
|
129
97
|
role: 'spinbutton',
|
|
130
98
|
tabIndex: -1,
|
|
@@ -136,43 +104,55 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
136
104
|
size: size === 'l' ? 's' : 'xs'
|
|
137
105
|
})
|
|
138
106
|
}), [hasNoItems, loading, size]);
|
|
139
|
-
const content = (0, react_1.useMemo)(() =>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
tabIndex: -1,
|
|
146
|
-
children: virtualItems.map(virtualRow => (0, jsx_runtime_1.jsx)("div", {
|
|
147
|
-
"data-index": virtualRow.index,
|
|
148
|
-
ref: virtualizer.measureElement,
|
|
149
|
-
tabIndex: -1,
|
|
150
|
-
className: styles_module_scss_2.default.virtualizedPositionBox,
|
|
107
|
+
const content = (0, react_1.useMemo)(() => {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
return (0, jsx_runtime_1.jsxs)("div", {
|
|
110
|
+
className: styles_module_scss_2.default.content,
|
|
111
|
+
children: [virtualized ? (0, jsx_runtime_1.jsx)("div", {
|
|
112
|
+
className: styles_module_scss_2.default.virtualizedContainer,
|
|
151
113
|
style: {
|
|
152
|
-
height:
|
|
153
|
-
transform: `translateY(${virtualRow.start}px)`
|
|
114
|
+
height: virtualizer.getTotalSize()
|
|
154
115
|
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
116
|
+
tabIndex: -1,
|
|
117
|
+
children: (0, jsx_runtime_1.jsx)("div", {
|
|
118
|
+
className: styles_module_scss_2.default.virtualizedPositionBox,
|
|
119
|
+
style: {
|
|
120
|
+
transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`
|
|
121
|
+
},
|
|
122
|
+
tabIndex: -1,
|
|
123
|
+
children: virtualItems.map(virtualRow => (0, jsx_runtime_1.jsx)("div", {
|
|
124
|
+
"data-index": virtualRow.index,
|
|
125
|
+
ref: virtualizer.measureElement,
|
|
126
|
+
tabIndex: -1,
|
|
127
|
+
children: itemsJSX[virtualRow.index]
|
|
128
|
+
}, virtualRow.key))
|
|
129
|
+
})
|
|
130
|
+
}) : itemsJSX, loadingJSX, (0, jsx_runtime_1.jsx)(helperComponents_1.ListEmptyState, {
|
|
131
|
+
loading: loading,
|
|
132
|
+
dataError: dataError,
|
|
133
|
+
emptyStates: emptyStates,
|
|
134
|
+
hasNoItems: hasNoItems,
|
|
135
|
+
dataFiltered: dataFiltered !== null && dataFiltered !== void 0 ? dataFiltered : Boolean(search === null || search === void 0 ? void 0 : search.value),
|
|
136
|
+
size: size
|
|
137
|
+
})]
|
|
138
|
+
});
|
|
139
|
+
}, [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search === null || search === void 0 ? void 0 : search.value, size, virtualItems, virtualized, virtualizer]);
|
|
140
|
+
const onScrollInitialized = () => {
|
|
167
141
|
var _a, _b;
|
|
168
|
-
if (
|
|
169
|
-
|
|
142
|
+
if (scrollToSelectedItem) {
|
|
143
|
+
if (!value) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
147
|
+
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
151
|
+
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({
|
|
152
|
+
block: 'center'
|
|
153
|
+
});
|
|
170
154
|
}
|
|
171
|
-
|
|
172
|
-
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({
|
|
173
|
-
block: 'center'
|
|
174
|
-
});
|
|
175
|
-
}, [memoizedFocusFlattenItems, selectedItemIndex]);
|
|
155
|
+
};
|
|
176
156
|
const listJSX = (0, jsx_runtime_1.jsxs)("ul", Object.assign({
|
|
177
157
|
className: (0, classnames_1.default)(styles_module_scss_1.default.listContainer, className),
|
|
178
158
|
ref: ref,
|
|
@@ -195,7 +175,10 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
195
175
|
}, scrollContainerClassName),
|
|
196
176
|
barHideStrategy: barHideStrategy,
|
|
197
177
|
size: size === 's' ? 's' : 'm',
|
|
198
|
-
ref:
|
|
178
|
+
ref: ref => {
|
|
179
|
+
innerScrollRef.current = ref;
|
|
180
|
+
if (scrollContainerRef) scrollContainerRef.current = ref;
|
|
181
|
+
},
|
|
199
182
|
untouchableScrollbars: untouchableScrollbars,
|
|
200
183
|
onScroll: onScroll,
|
|
201
184
|
onInitialized: onScrollInitialized,
|
|
@@ -9,11 +9,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx,
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
14
14
|
import cn from 'classnames';
|
|
15
|
-
import
|
|
16
|
-
import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
15
|
+
import { forwardRef, useEffect, useMemo, useRef } from 'react';
|
|
17
16
|
import { Spinner } from '@snack-uikit/loaders';
|
|
18
17
|
import { Scroll } from '@snack-uikit/scroll';
|
|
19
18
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
@@ -34,48 +33,21 @@ export const ListPrivate = forwardRef((_a, ref) => {
|
|
|
34
33
|
const itemsPinBottomJSX = useRenderItems(pinBottom);
|
|
35
34
|
const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
|
|
36
35
|
const hasNoItems = items.length === 0;
|
|
37
|
-
const memoizedFocusFlattenItems = useMemo(() => Object.values(focusFlattenItems), [focusFlattenItems]);
|
|
38
|
-
const selectedItemIndex = useMemo(() => {
|
|
39
|
-
if (!scrollToSelectedItem || !value) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
43
|
-
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
44
|
-
return -1;
|
|
45
|
-
}
|
|
46
|
-
return memoizedFocusFlattenItems.findIndex(item => item.originalId === selectedItem.id);
|
|
47
|
-
}, [flattenItems, memoizedFocusFlattenItems, isSelectionSingle, scrollToSelectedItem, value]);
|
|
48
36
|
const virtualizer = useVirtualizer({
|
|
49
37
|
count: itemsJSX.length,
|
|
50
38
|
getScrollElement: () => (scroll ? innerScrollRef.current : null),
|
|
51
39
|
estimateSize: () => ALL_SIZES[size],
|
|
52
40
|
enabled: virtualized,
|
|
53
|
-
overscan: 5, // Amount of elements in DOM before/after visible ones
|
|
54
41
|
});
|
|
55
42
|
const virtualItems = virtualizer.getVirtualItems();
|
|
56
43
|
useEffect(() => {
|
|
57
44
|
virtualizer.measure();
|
|
58
45
|
}, [virtualizer]);
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (scroll && scrollToSelectedItem && virtualized) {
|
|
61
|
-
if (selectedItemIndex < 0) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
requestAnimationFrame(() => {
|
|
65
|
-
virtualizer.scrollToIndex(selectedItemIndex, { align: 'center' });
|
|
66
|
-
requestAnimationFrame(() => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const itemToScrollTo = memoizedFocusFlattenItems[selectedItemIndex];
|
|
69
|
-
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ block: 'center' });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}, [selectedItemIndex, scroll, scrollToSelectedItem, virtualized, virtualizer, memoizedFocusFlattenItems]);
|
|
74
46
|
const loadingJSX = useMemo(() => loading && (_jsx("div", { role: 'spinbutton', tabIndex: -1, className: styles.loader, "data-size": size, "data-no-items": hasNoItems || undefined, "data-test-id": 'list__loader', children: _jsx(Spinner, { size: size === 'l' ? 's' : 'xs' }) })), [hasNoItems, loading, size]);
|
|
75
|
-
const content = useMemo(() =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
47
|
+
const content = useMemo(() => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return (_jsxs("div", { className: styles.content, children: [virtualized ? (_jsx("div", { className: styles.virtualizedContainer, style: { height: virtualizer.getTotalSize() }, tabIndex: -1, children: _jsx("div", { className: styles.virtualizedPositionBox, style: { transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)` }, tabIndex: -1, children: virtualItems.map(virtualRow => (_jsx("div", { "data-index": virtualRow.index, ref: virtualizer.measureElement, tabIndex: -1, children: itemsJSX[virtualRow.index] }, virtualRow.key))) }) })) : (itemsJSX), loadingJSX, _jsx(ListEmptyState, { loading: loading, dataError: dataError, emptyStates: emptyStates, hasNoItems: hasNoItems, dataFiltered: dataFiltered !== null && dataFiltered !== void 0 ? dataFiltered : Boolean(search === null || search === void 0 ? void 0 : search.value), size: size })] }));
|
|
50
|
+
}, [
|
|
79
51
|
dataError,
|
|
80
52
|
dataFiltered,
|
|
81
53
|
emptyStates,
|
|
@@ -89,19 +61,29 @@ export const ListPrivate = forwardRef((_a, ref) => {
|
|
|
89
61
|
virtualized,
|
|
90
62
|
virtualizer,
|
|
91
63
|
]);
|
|
92
|
-
const onScrollInitialized =
|
|
64
|
+
const onScrollInitialized = () => {
|
|
93
65
|
var _a, _b;
|
|
94
|
-
if (
|
|
95
|
-
|
|
66
|
+
if (scrollToSelectedItem) {
|
|
67
|
+
if (!value) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
71
|
+
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
75
|
+
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ block: 'center' });
|
|
96
76
|
}
|
|
97
|
-
|
|
98
|
-
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ block: 'center' });
|
|
99
|
-
}, [memoizedFocusFlattenItems, selectedItemIndex]);
|
|
77
|
+
};
|
|
100
78
|
const listJSX = (_jsxs("ul", Object.assign({ className: cn(commonStyles.listContainer, className), ref: ref, onKeyDown: onKeyDown, tabIndex: tabIndex, onFocus: onFocus, onBlur: onBlur, "data-active": active || undefined, role: 'menu' }, extractSupportProps(props), { children: [(Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 || search) && (_jsxs(PinTopGroupItem, { children: [search && _jsx(SearchItem, Object.assign({ search: search }, searchItem)), Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 && itemsPinTopJSX] })), scroll ? (_jsxs(Scroll, { className: cn({
|
|
101
79
|
[commonStyles.scrollContainerS]: scroll && limitedScrollHeight && size === 's',
|
|
102
80
|
[commonStyles.scrollContainerM]: scroll && limitedScrollHeight && size === 'm',
|
|
103
81
|
[commonStyles.scrollContainerL]: scroll && limitedScrollHeight && size === 'l',
|
|
104
|
-
}, scrollContainerClassName), barHideStrategy: barHideStrategy, size: size === 's' ? 's' : 'm', ref:
|
|
82
|
+
}, scrollContainerClassName), barHideStrategy: barHideStrategy, size: size === 's' ? 's' : 'm', ref: ref => {
|
|
83
|
+
innerScrollRef.current = ref;
|
|
84
|
+
if (scrollContainerRef)
|
|
85
|
+
scrollContainerRef.current = ref;
|
|
86
|
+
}, untouchableScrollbars: untouchableScrollbars, onScroll: onScroll, onInitialized: onScrollInitialized, children: [content, _jsx("div", { className: styles.scrollStub, ref: scrollRef })] })) : (_jsx(_Fragment, { children: content })), Number(pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) > 0 && _jsx(PinBottomGroupItem, { children: itemsPinBottomJSX }), footer && (_jsx("div", { className: styles.footer, onFocus: stopPropagation, children: footer }))] })));
|
|
105
87
|
if (!nested) {
|
|
106
88
|
return listJSX;
|
|
107
89
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.29.6
|
|
7
|
+
"version": "0.29.6",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"@snack-uikit/divider": "3.2.6",
|
|
41
41
|
"@snack-uikit/dropdown": "0.4.8",
|
|
42
42
|
"@snack-uikit/icons": "0.26.4",
|
|
43
|
-
"@snack-uikit/info-block": "0.6.
|
|
43
|
+
"@snack-uikit/info-block": "0.6.25",
|
|
44
44
|
"@snack-uikit/loaders": "0.9.5",
|
|
45
45
|
"@snack-uikit/scroll": "0.10.1",
|
|
46
46
|
"@snack-uikit/search-private": "0.4.21",
|
|
47
47
|
"@snack-uikit/toggles": "0.13.15",
|
|
48
|
-
"@snack-uikit/truncate-string": "0.6.
|
|
48
|
+
"@snack-uikit/truncate-string": "0.6.21",
|
|
49
49
|
"@snack-uikit/utils": "3.8.2",
|
|
50
50
|
"@tanstack/react-virtual": "3.11.2",
|
|
51
51
|
"classnames": "2.5.1",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@snack-uikit/locale": "*"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "30ce13048847439dad862be32ab65379adc107c0"
|
|
58
58
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import
|
|
4
|
-
import { ForwardedRef, forwardRef, RefObject, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { ForwardedRef, forwardRef, RefObject, useEffect, useMemo, useRef } from 'react';
|
|
5
4
|
|
|
6
5
|
import { Spinner } from '@snack-uikit/loaders';
|
|
7
6
|
import { Scroll } from '@snack-uikit/scroll';
|
|
@@ -63,27 +62,11 @@ export const ListPrivate = forwardRef(
|
|
|
63
62
|
const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
|
|
64
63
|
const hasNoItems = items.length === 0;
|
|
65
64
|
|
|
66
|
-
const memoizedFocusFlattenItems = useMemo(() => Object.values(focusFlattenItems), [focusFlattenItems]);
|
|
67
|
-
|
|
68
|
-
const selectedItemIndex = useMemo(() => {
|
|
69
|
-
if (!scrollToSelectedItem || !value) {
|
|
70
|
-
return -1;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
74
|
-
if (!selectedItem?.id) {
|
|
75
|
-
return -1;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return memoizedFocusFlattenItems.findIndex(item => item.originalId === selectedItem.id);
|
|
79
|
-
}, [flattenItems, memoizedFocusFlattenItems, isSelectionSingle, scrollToSelectedItem, value]);
|
|
80
|
-
|
|
81
65
|
const virtualizer = useVirtualizer({
|
|
82
66
|
count: itemsJSX.length,
|
|
83
67
|
getScrollElement: () => (scroll ? innerScrollRef.current : null),
|
|
84
68
|
estimateSize: () => ALL_SIZES[size],
|
|
85
69
|
enabled: virtualized,
|
|
86
|
-
overscan: 5, // Amount of elements in DOM before/after visible ones
|
|
87
70
|
});
|
|
88
71
|
const virtualItems = virtualizer.getVirtualItems();
|
|
89
72
|
|
|
@@ -91,23 +74,6 @@ export const ListPrivate = forwardRef(
|
|
|
91
74
|
virtualizer.measure();
|
|
92
75
|
}, [virtualizer]);
|
|
93
76
|
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (scroll && scrollToSelectedItem && virtualized) {
|
|
96
|
-
if (selectedItemIndex < 0) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
requestAnimationFrame(() => {
|
|
101
|
-
virtualizer.scrollToIndex(selectedItemIndex, { align: 'center' });
|
|
102
|
-
|
|
103
|
-
requestAnimationFrame(() => {
|
|
104
|
-
const itemToScrollTo = memoizedFocusFlattenItems[selectedItemIndex];
|
|
105
|
-
itemToScrollTo?.itemRef?.current?.scrollIntoView({ block: 'center' });
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}, [selectedItemIndex, scroll, scrollToSelectedItem, virtualized, virtualizer, memoizedFocusFlattenItems]);
|
|
110
|
-
|
|
111
77
|
const loadingJSX = useMemo(
|
|
112
78
|
() =>
|
|
113
79
|
loading && (
|
|
@@ -127,24 +93,25 @@ export const ListPrivate = forwardRef(
|
|
|
127
93
|
|
|
128
94
|
const content = useMemo(
|
|
129
95
|
() => (
|
|
130
|
-
|
|
96
|
+
<div className={styles.content}>
|
|
131
97
|
{virtualized ? (
|
|
132
98
|
<div className={styles.virtualizedContainer} style={{ height: virtualizer.getTotalSize() }} tabIndex={-1}>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
99
|
+
<div
|
|
100
|
+
className={styles.virtualizedPositionBox}
|
|
101
|
+
style={{ transform: `translateY(${virtualItems[0]?.start ?? 0}px)` }}
|
|
102
|
+
tabIndex={-1}
|
|
103
|
+
>
|
|
104
|
+
{virtualItems.map(virtualRow => (
|
|
105
|
+
<div
|
|
106
|
+
key={virtualRow.key}
|
|
107
|
+
data-index={virtualRow.index}
|
|
108
|
+
ref={virtualizer.measureElement}
|
|
109
|
+
tabIndex={-1}
|
|
110
|
+
>
|
|
111
|
+
{itemsJSX[virtualRow.index]}
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</div>
|
|
148
115
|
</div>
|
|
149
116
|
) : (
|
|
150
117
|
itemsJSX
|
|
@@ -159,7 +126,7 @@ export const ListPrivate = forwardRef(
|
|
|
159
126
|
dataFiltered={dataFiltered ?? Boolean(search?.value)}
|
|
160
127
|
size={size}
|
|
161
128
|
/>
|
|
162
|
-
|
|
129
|
+
</div>
|
|
163
130
|
),
|
|
164
131
|
[
|
|
165
132
|
dataError,
|
|
@@ -177,14 +144,22 @@ export const ListPrivate = forwardRef(
|
|
|
177
144
|
],
|
|
178
145
|
);
|
|
179
146
|
|
|
180
|
-
const onScrollInitialized =
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
147
|
+
const onScrollInitialized = () => {
|
|
148
|
+
if (scrollToSelectedItem) {
|
|
149
|
+
if (!value) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
184
152
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
153
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
154
|
+
|
|
155
|
+
if (!selectedItem?.id) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
160
|
+
itemToScrollTo?.itemRef?.current?.scrollIntoView({ block: 'center' });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
188
163
|
|
|
189
164
|
const listJSX = (
|
|
190
165
|
<ul
|
|
@@ -218,7 +193,10 @@ export const ListPrivate = forwardRef(
|
|
|
218
193
|
)}
|
|
219
194
|
barHideStrategy={barHideStrategy}
|
|
220
195
|
size={size === 's' ? 's' : 'm'}
|
|
221
|
-
ref={
|
|
196
|
+
ref={ref => {
|
|
197
|
+
innerScrollRef.current = ref;
|
|
198
|
+
if (scrollContainerRef) (scrollContainerRef as React.MutableRefObject<HTMLElement | null>).current = ref;
|
|
199
|
+
}}
|
|
222
200
|
untouchableScrollbars={untouchableScrollbars}
|
|
223
201
|
onScroll={onScroll}
|
|
224
202
|
onInitialized={onScrollInitialized}
|