@snack-uikit/list 0.22.3-preview-95d8b6b7.0 → 0.22.3-preview-a2f98ef7.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.
@@ -18,7 +18,6 @@ Object.defineProperty(exports, "__esModule", {
18
18
  });
19
19
  exports.ListPrivate = void 0;
20
20
  const jsx_runtime_1 = require("react/jsx-runtime");
21
- const react_virtual_1 = require("@tanstack/react-virtual");
22
21
  const classnames_1 = __importDefault(require("classnames"));
23
22
  const react_1 = require("react");
24
23
  const loaders_1 = require("@snack-uikit/loaders");
@@ -69,7 +68,6 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
69
68
  value,
70
69
  isSelectionSingle
71
70
  } = (0, contexts_1.useSelectionContext)();
72
- const innerScrollRef = (0, react_1.useRef)(null);
73
71
  const itemsJSX = (0, Items_1.useRenderItems)(items);
74
72
  const itemsPinTopJSX = (0, Items_1.useRenderItems)(pinTop);
75
73
  const itemsPinBottomJSX = (0, Items_1.useRenderItems)(pinBottom);
@@ -79,12 +77,6 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
79
77
  errorDataState
80
78
  });
81
79
  const hasNoItems = items.length === 0;
82
- const virtualizer = (0, react_virtual_1.useVirtualizer)({
83
- count: itemsJSX.length,
84
- getScrollElement: () => scroll ? innerScrollRef.current : null,
85
- estimateSize: () => size === 'm' ? 40 : 32
86
- });
87
- const virtualItems = virtualizer.getVirtualItems();
88
80
  const loadingJSX = (0, react_1.useMemo)(() => loading && (0, jsx_runtime_1.jsx)("div", {
89
81
  role: 'spinbutton',
90
82
  tabIndex: -1,
@@ -96,42 +88,18 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
96
88
  size: size === 'l' ? 's' : 'xs'
97
89
  })
98
90
  }), [hasNoItems, loading, size]);
99
- const content = (0, react_1.useMemo)(() => {
100
- var _a, _b;
101
- return (0, jsx_runtime_1.jsxs)("div", {
102
- className: styles_module_scss_2.default.content,
103
- children: [(0, jsx_runtime_1.jsx)("div", {
104
- style: {
105
- height: virtualizer.getTotalSize(),
106
- width: '100%',
107
- position: 'relative'
108
- },
109
- children: (0, jsx_runtime_1.jsx)("div", {
110
- style: {
111
- position: 'absolute',
112
- top: 0,
113
- left: 0,
114
- width: '100%',
115
- transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`
116
- },
117
- children: virtualItems.map(virtualRow => (0, jsx_runtime_1.jsx)("div", {
118
- "data-index": virtualRow.index,
119
- ref: virtualizer.measureElement,
120
- children: itemsJSX[virtualRow.index]
121
- }, virtualRow.key))
122
- })
123
- }), loadingJSX, (0, jsx_runtime_1.jsx)(helperComponents_1.ListEmptyState, {
124
- loading: loading,
125
- dataError: dataError,
126
- emptyStates: emptyStates,
127
- hasNoItems: hasNoItems,
128
- dataFiltered: dataFiltered !== null && dataFiltered !== void 0 ? dataFiltered : Boolean(search === null || search === void 0 ? void 0 : search.value)
129
- })]
130
- });
131
- }, [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search === null || search === void 0 ? void 0 : search.value, virtualItems, virtualizer]);
91
+ const content = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsxs)("div", {
92
+ className: styles_module_scss_2.default.content,
93
+ children: [itemsJSX, loadingJSX, (0, jsx_runtime_1.jsx)(helperComponents_1.ListEmptyState, {
94
+ loading: loading,
95
+ dataError: dataError,
96
+ emptyStates: emptyStates,
97
+ hasNoItems: hasNoItems,
98
+ dataFiltered: dataFiltered !== null && dataFiltered !== void 0 ? dataFiltered : Boolean(search === null || search === void 0 ? void 0 : search.value)
99
+ })]
100
+ }), [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search === null || search === void 0 ? void 0 : search.value]);
132
101
  const onScrollInitialized = () => {
133
102
  var _a, _b;
134
- virtualizer.measure();
135
103
  if (scrollToSelectedItem) {
136
104
  if (!value) {
137
105
  return;
@@ -168,10 +136,7 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
168
136
  }, scrollContainerClassName),
169
137
  barHideStrategy: 'never',
170
138
  size: size === 's' ? 's' : 'm',
171
- ref: ref => {
172
- innerScrollRef.current = ref;
173
- if (scrollContainerRef) scrollContainerRef.current = ref;
174
- },
139
+ ref: scrollContainerRef,
175
140
  untouchableScrollbars: untouchableScrollbars,
176
141
  onScroll: onScroll,
177
142
  onInitialized: onScrollInitialized,
@@ -10,9 +10,8 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
- import { useVirtualizer } from '@tanstack/react-virtual';
14
13
  import cn from 'classnames';
15
- import { forwardRef, useMemo, useRef } from 'react';
14
+ import { forwardRef, useMemo } from 'react';
16
15
  import { Spinner } from '@snack-uikit/loaders';
17
16
  import { Scroll } from '@snack-uikit/scroll';
18
17
  import { extractSupportProps } from '@snack-uikit/utils';
@@ -25,47 +24,15 @@ export const ListPrivate = forwardRef((_a, ref) => {
25
24
  var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, searchItem, scrollRef, scrollContainerRef, onScroll, footer, loading, limitedScrollHeight, untouchableScrollbars, className, noDataState, noResultsState, errorDataState, dataError, dataFiltered, scrollToSelectedItem = false, scrollContainerClassName } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "searchItem", "scrollRef", "scrollContainerRef", "onScroll", "footer", "loading", "limitedScrollHeight", "untouchableScrollbars", "className", "noDataState", "noResultsState", "errorDataState", "dataError", "dataFiltered", "scrollToSelectedItem", "scrollContainerClassName"]);
26
25
  const { size = 's', flattenItems, focusFlattenItems } = useNewListContext();
27
26
  const { value, isSelectionSingle } = useSelectionContext();
28
- const innerScrollRef = useRef(null);
29
27
  const itemsJSX = useRenderItems(items);
30
28
  const itemsPinTopJSX = useRenderItems(pinTop);
31
29
  const itemsPinBottomJSX = useRenderItems(pinBottom);
32
30
  const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
33
31
  const hasNoItems = items.length === 0;
34
- const virtualizer = useVirtualizer({
35
- count: itemsJSX.length,
36
- getScrollElement: () => (scroll ? innerScrollRef.current : null),
37
- estimateSize: () => (size === 'm' ? 40 : 32),
38
- });
39
- const virtualItems = virtualizer.getVirtualItems();
40
32
  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]);
41
- const content = useMemo(() => {
42
- var _a, _b;
43
- return (_jsxs("div", { className: styles.content, children: [_jsx("div", { style: {
44
- height: virtualizer.getTotalSize(),
45
- width: '100%',
46
- position: 'relative',
47
- }, children: _jsx("div", { style: {
48
- position: 'absolute',
49
- top: 0,
50
- left: 0,
51
- width: '100%',
52
- transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`,
53
- }, children: virtualItems.map(virtualRow => (_jsx("div", { "data-index": virtualRow.index, ref: virtualizer.measureElement, children: itemsJSX[virtualRow.index] }, virtualRow.key))) }) }), 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) })] }));
54
- }, [
55
- dataError,
56
- dataFiltered,
57
- emptyStates,
58
- hasNoItems,
59
- itemsJSX,
60
- loading,
61
- loadingJSX,
62
- search === null || search === void 0 ? void 0 : search.value,
63
- virtualItems,
64
- virtualizer,
65
- ]);
33
+ const content = useMemo(() => (_jsxs("div", { className: styles.content, children: [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) })] })), [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search === null || search === void 0 ? void 0 : search.value]);
66
34
  const onScrollInitialized = () => {
67
35
  var _a, _b;
68
- virtualizer.measure();
69
36
  if (scrollToSelectedItem) {
70
37
  if (!value) {
71
38
  return;
@@ -82,11 +49,7 @@ export const ListPrivate = forwardRef((_a, ref) => {
82
49
  [commonStyles.scrollContainerS]: scroll && limitedScrollHeight && size === 's',
83
50
  [commonStyles.scrollContainerM]: scroll && limitedScrollHeight && size === 'm',
84
51
  [commonStyles.scrollContainerL]: scroll && limitedScrollHeight && size === 'l',
85
- }, scrollContainerClassName), barHideStrategy: 'never', size: size === 's' ? 's' : 'm', ref: ref => {
86
- innerScrollRef.current = ref;
87
- if (scrollContainerRef)
88
- scrollContainerRef.current = ref;
89
- }, 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: e => e.stopPropagation(), children: footer }))] })));
52
+ }, scrollContainerClassName), barHideStrategy: 'never', size: size === 's' ? 's' : 'm', ref: scrollContainerRef, 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: e => e.stopPropagation(), children: footer }))] })));
90
53
  if (!nested) {
91
54
  return listJSX;
92
55
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.22.3-preview-95d8b6b7.0",
7
+ "version": "0.22.3-preview-a2f98ef7.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -36,23 +36,22 @@
36
36
  "license": "Apache-2.0",
37
37
  "scripts": {},
38
38
  "dependencies": {
39
- "@snack-uikit/button": "0.19.5",
39
+ "@snack-uikit/button": "0.19.6-preview-a2f98ef7.0",
40
40
  "@snack-uikit/divider": "3.2.2",
41
41
  "@snack-uikit/dropdown": "0.4.2",
42
42
  "@snack-uikit/icons": "0.24.1",
43
- "@snack-uikit/info-block": "0.6.7",
43
+ "@snack-uikit/info-block": "0.6.8-preview-a2f98ef7.0",
44
44
  "@snack-uikit/loaders": "0.9.0",
45
45
  "@snack-uikit/scroll": "0.9.2",
46
46
  "@snack-uikit/search-private": "0.4.8",
47
47
  "@snack-uikit/toggles": "0.13.3",
48
48
  "@snack-uikit/truncate-string": "0.6.4",
49
49
  "@snack-uikit/utils": "3.6.0",
50
- "@tanstack/react-virtual": "3.11.2",
51
50
  "classnames": "2.5.1",
52
51
  "merge-refs": "1.3.0"
53
52
  },
54
53
  "peerDependencies": {
55
54
  "@snack-uikit/locale": "*"
56
55
  },
57
- "gitHead": "6a944145de1357fd92b0c64a10f37a3122e54915"
56
+ "gitHead": "16999df080b0b870c1a90ba74aa6c296cd4d480b"
58
57
  }
@@ -1,6 +1,5 @@
1
- import { useVirtualizer } from '@tanstack/react-virtual';
2
1
  import cn from 'classnames';
3
- import { ForwardedRef, forwardRef, RefObject, useMemo, useRef } from 'react';
2
+ import { ForwardedRef, forwardRef, RefObject, useMemo } from 'react';
4
3
 
5
4
  import { Spinner } from '@snack-uikit/loaders';
6
5
  import { Scroll } from '@snack-uikit/scroll';
@@ -49,7 +48,6 @@ export const ListPrivate = forwardRef(
49
48
  ) => {
50
49
  const { size = 's', flattenItems, focusFlattenItems } = useNewListContext();
51
50
  const { value, isSelectionSingle } = useSelectionContext();
52
- const innerScrollRef = useRef<HTMLElement | null>(null);
53
51
 
54
52
  const itemsJSX = useRenderItems(items);
55
53
  const itemsPinTopJSX = useRenderItems(pinTop);
@@ -58,13 +56,6 @@ export const ListPrivate = forwardRef(
58
56
  const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
59
57
  const hasNoItems = items.length === 0;
60
58
 
61
- const virtualizer = useVirtualizer({
62
- count: itemsJSX.length,
63
- getScrollElement: () => (scroll ? innerScrollRef.current : null),
64
- estimateSize: () => (size === 'm' ? 40 : 32),
65
- });
66
- const virtualItems = virtualizer.getVirtualItems();
67
-
68
59
  const loadingJSX = useMemo(
69
60
  () =>
70
61
  loading && (
@@ -85,29 +76,7 @@ export const ListPrivate = forwardRef(
85
76
  const content = useMemo(
86
77
  () => (
87
78
  <div className={styles.content}>
88
- <div
89
- style={{
90
- height: virtualizer.getTotalSize(),
91
- width: '100%',
92
- position: 'relative',
93
- }}
94
- >
95
- <div
96
- style={{
97
- position: 'absolute',
98
- top: 0,
99
- left: 0,
100
- width: '100%',
101
- transform: `translateY(${virtualItems[0]?.start ?? 0}px)`,
102
- }}
103
- >
104
- {virtualItems.map(virtualRow => (
105
- <div key={virtualRow.key} data-index={virtualRow.index} ref={virtualizer.measureElement}>
106
- {itemsJSX[virtualRow.index]}
107
- </div>
108
- ))}
109
- </div>
110
- </div>
79
+ {itemsJSX}
111
80
  {loadingJSX}
112
81
 
113
82
  <ListEmptyState
@@ -119,23 +88,10 @@ export const ListPrivate = forwardRef(
119
88
  />
120
89
  </div>
121
90
  ),
122
- [
123
- dataError,
124
- dataFiltered,
125
- emptyStates,
126
- hasNoItems,
127
- itemsJSX,
128
- loading,
129
- loadingJSX,
130
- search?.value,
131
- virtualItems,
132
- virtualizer,
133
- ],
91
+ [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search?.value],
134
92
  );
135
93
 
136
94
  const onScrollInitialized = () => {
137
- virtualizer.measure();
138
-
139
95
  if (scrollToSelectedItem) {
140
96
  if (!value) {
141
97
  return;
@@ -184,10 +140,7 @@ export const ListPrivate = forwardRef(
184
140
  )}
185
141
  barHideStrategy='never'
186
142
  size={size === 's' ? 's' : 'm'}
187
- ref={ref => {
188
- innerScrollRef.current = ref;
189
- if (scrollContainerRef) (scrollContainerRef as React.MutableRefObject<HTMLElement | null>).current = ref;
190
- }}
143
+ ref={scrollContainerRef}
191
144
  untouchableScrollbars={untouchableScrollbars}
192
145
  onScroll={onScroll}
193
146
  onInitialized={onScrollInitialized}