@hh.ru/magritte-ui-table 4.2.10 → 4.2.11
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/BaseTable.d.ts +1 -1
- package/BaseTable.js +266 -145
- package/BaseTable.js.map +1 -1
- package/FullPageContainer.js +27 -22
- package/FullPageContainer.js.map +1 -1
- package/SimpleTable.d.ts +1 -1
- package/SimpleTable.js +4 -4
- package/SimpleTable.js.map +1 -1
- package/StickyTableHeader.js +43 -37
- package/StickyTableHeader.js.map +1 -1
- package/Table.d.ts +1 -1
- package/Table.js +8 -8
- package/Table.js.map +1 -1
- package/TableBody.js +7 -4
- package/TableBody.js.map +1 -1
- package/TableCell.d.ts +1 -1
- package/TableCell.js +84 -60
- package/TableCell.js.map +1 -1
- package/TableHeader.d.ts +1 -1
- package/TableHeader.js +37 -11
- package/TableHeader.js.map +1 -1
- package/TableRow.d.ts +1 -1
- package/TableRow.js +108 -32
- package/TableRow.js.map +1 -1
- package/VirtualizedList/VirtualizedList.js +43 -32
- package/VirtualizedList/VirtualizedList.js.map +1 -1
- package/VirtualizedList/VirtualizedListWrapper.js +41 -15
- package/VirtualizedList/VirtualizedListWrapper.js.map +1 -1
- package/VirtualizedList/VirtualizedPanel.js +13 -7
- package/VirtualizedList/VirtualizedPanel.js.map +1 -1
- package/VirtualizedList/context.js +1 -1
- package/VirtualizedList/context.js.map +1 -1
- package/VirtualizedList/index.d.ts +3 -3
- package/VirtualizedList/index.js +1 -1
- package/VirtualizedList/useVirtualizedList.js +29 -33
- package/VirtualizedList/useVirtualizedList.js.map +1 -1
- package/cell-7-Eiwyn4.js +5 -0
- package/cell-7-Eiwyn4.js.map +1 -0
- package/context.js +3 -3
- package/context.js.map +1 -1
- package/index.css +1318 -1318
- package/index.d.ts +9 -9
- package/index.js +4 -4
- package/index.mock.d.ts +1 -1
- package/index.mock.js +11 -11
- package/index.mock.js.map +1 -1
- package/package.json +5 -5
- package/table-CQ76yrLp.js +5 -0
- package/table-CQ76yrLp.js.map +1 -0
- package/useTableResize.js +35 -37
- package/useTableResize.js.map +1 -1
- package/virtualized-list-DZqJXIA7.js +5 -0
- package/virtualized-list-DZqJXIA7.js.map +1 -0
- package/cell-C283JD07.js +0 -5
- package/cell-C283JD07.js.map +0 -1
- package/table-C-jo_Mjg.js +0 -5
- package/table-C-jo_Mjg.js.map +0 -1
- package/virtualized-list-CrBJZfKI.js +0 -5
- package/virtualized-list-CrBJZfKI.js.map +0 -1
package/TableRow.js
CHANGED
|
@@ -4,39 +4,115 @@ import { forwardRef, useContext, useRef, useEffect } from 'react';
|
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
|
|
6
6
|
import { TableContext } from './context.js';
|
|
7
|
-
import { c as cellStyles } from './cell-
|
|
8
|
-
import { s as styles } from './table-
|
|
7
|
+
import { c as cellStyles } from './cell-7-Eiwyn4.js';
|
|
8
|
+
import { s as styles } from './table-CQ76yrLp.js';
|
|
9
9
|
|
|
10
|
-
const TableRowComponent = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
const TableRowComponent = ({
|
|
11
|
+
style,
|
|
12
|
+
styleHighlighted,
|
|
13
|
+
action,
|
|
14
|
+
showAction,
|
|
15
|
+
animated,
|
|
16
|
+
onClick,
|
|
17
|
+
panel,
|
|
18
|
+
showPanel,
|
|
19
|
+
children,
|
|
20
|
+
measure,
|
|
21
|
+
align,
|
|
22
|
+
hoverEnabled,
|
|
23
|
+
verticalAlign = "top",
|
|
24
|
+
"data-qa": dataQa = "table-row",
|
|
25
|
+
...rest
|
|
26
|
+
}, ref) => {
|
|
27
|
+
const { paddingLeft, paddingRight, hoverEnabled: _tableHoverEnabled } = useContext(TableContext);
|
|
28
|
+
const _hoverEnabled = hoverEnabled ?? _tableHoverEnabled;
|
|
29
|
+
const highlightedColor = styleHighlighted || style;
|
|
30
|
+
const wasPanelShown = useRef(null);
|
|
31
|
+
const rowRef = useRef(null);
|
|
32
|
+
const multiRef = useMultipleRefs(ref, rowRef);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (wasPanelShown.current === null) {
|
|
35
|
+
wasPanelShown.current = !!(panel && showPanel);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (wasPanelShown.current !== !!(panel && showPanel)) {
|
|
39
|
+
wasPanelShown.current = !!(panel && showPanel);
|
|
40
|
+
rowRef.current && measure?.(rowRef.current);
|
|
41
|
+
}
|
|
42
|
+
}, [panel, showPanel, measure]);
|
|
43
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
44
|
+
/* @__PURE__ */ jsxs(
|
|
45
|
+
"tr",
|
|
46
|
+
{
|
|
47
|
+
...rest,
|
|
48
|
+
className: classnames(styles.row, {
|
|
49
|
+
[styles.active]: !!onClick,
|
|
50
|
+
[styles.hoverEnabled]: _hoverEnabled,
|
|
51
|
+
[styles.animated]: animated,
|
|
52
|
+
[styles.withPanel]: showPanel && panel,
|
|
53
|
+
[styles[`style-${style}`]]: style,
|
|
54
|
+
[styles[`style-highlighted-${highlightedColor}`]]: highlightedColor
|
|
55
|
+
}),
|
|
56
|
+
onClick,
|
|
57
|
+
ref: multiRef,
|
|
58
|
+
"data-qa": dataQa,
|
|
59
|
+
style: {
|
|
60
|
+
textAlign: align,
|
|
61
|
+
verticalAlign
|
|
62
|
+
},
|
|
63
|
+
children: [
|
|
64
|
+
!!paddingLeft && /* @__PURE__ */ jsx(
|
|
65
|
+
"td",
|
|
66
|
+
{
|
|
67
|
+
className: classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td),
|
|
68
|
+
"data-qa": "table-row-left-space",
|
|
69
|
+
style: { width: paddingLeft },
|
|
70
|
+
children: showAction && action && /* @__PURE__ */ jsx("div", { className: cellStyles.control, children: action })
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
children,
|
|
74
|
+
!!paddingRight && /* @__PURE__ */ jsx(
|
|
75
|
+
"td",
|
|
76
|
+
{
|
|
77
|
+
className: classnames(cellStyles.spaceCell, styles.td),
|
|
78
|
+
"data-qa": "table-row-right-space",
|
|
79
|
+
style: { width: paddingRight }
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
panel && showPanel && /* @__PURE__ */ jsxs(
|
|
86
|
+
"tr",
|
|
87
|
+
{
|
|
88
|
+
"data-qa": `${dataQa}-panel`,
|
|
89
|
+
"data-magritte-table-row-panel": true,
|
|
90
|
+
className: classnames(styles.row, styles.rowPanel, styles.animated),
|
|
91
|
+
style: {
|
|
92
|
+
textAlign: align
|
|
93
|
+
},
|
|
94
|
+
children: [
|
|
95
|
+
!!paddingLeft && /* @__PURE__ */ jsx(
|
|
96
|
+
"td",
|
|
97
|
+
{
|
|
98
|
+
className: classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td),
|
|
99
|
+
"data-qa": "table-row-left-space",
|
|
100
|
+
style: { width: paddingLeft }
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
panel,
|
|
104
|
+
!!paddingRight && /* @__PURE__ */ jsx(
|
|
105
|
+
"td",
|
|
106
|
+
{
|
|
107
|
+
className: classnames(cellStyles.spaceCell, styles.td),
|
|
108
|
+
"data-qa": "table-row-right-space",
|
|
109
|
+
style: { width: paddingRight }
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
] });
|
|
40
116
|
};
|
|
41
117
|
const TableRow = forwardRef(TableRowComponent);
|
|
42
118
|
|
package/TableRow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRow.js","sources":["src/TableRow.tsx"],"sourcesContent":["import React, { type ForwardedRef, forwardRef, useContext, useEffect, useRef } from 'react';\nimport classnames from 'classnames';\n\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { TableContext } from '@hh.ru/magritte-ui-table/context';\nimport { TableRowProps } from '@hh.ru/magritte-ui-table/types';\n\nimport cellStyles from './cell.less';\nimport styles from './table.less';\n\nconst TableRowComponent = (\n {\n style,\n styleHighlighted,\n action,\n showAction,\n animated,\n onClick,\n panel,\n showPanel,\n children,\n measure,\n align,\n hoverEnabled,\n verticalAlign = 'top',\n 'data-qa': dataQa = 'table-row',\n ...rest\n }: TableRowProps,\n ref: ForwardedRef<HTMLTableRowElement>\n) => {\n const { paddingLeft, paddingRight, hoverEnabled: _tableHoverEnabled } = useContext(TableContext);\n const _hoverEnabled = hoverEnabled ?? _tableHoverEnabled;\n const highlightedColor = styleHighlighted || style;\n const wasPanelShown = useRef<boolean | null>(null);\n const rowRef = useRef(null);\n const multiRef = useMultipleRefs(ref, rowRef);\n\n useEffect(() => {\n if (wasPanelShown.current === null) {\n wasPanelShown.current = !!(panel && showPanel);\n return;\n }\n\n if (wasPanelShown.current !== !!(panel && showPanel)) {\n wasPanelShown.current = !!(panel && showPanel);\n rowRef.current && measure?.(rowRef.current);\n }\n }, [panel, showPanel, measure]);\n\n return (\n <>\n <tr\n {...rest}\n className={classnames(styles.row, {\n [styles.active]: !!onClick,\n [styles.hoverEnabled]: _hoverEnabled,\n [styles.animated]: animated,\n [styles.withPanel]: showPanel && panel,\n [styles[`style-${style}`]]: style,\n [styles[`style-highlighted-${highlightedColor}`]]: highlightedColor,\n })}\n onClick={onClick}\n ref={multiRef}\n data-qa={dataQa}\n style={{\n textAlign: align,\n verticalAlign,\n }}\n >\n {!!paddingLeft && (\n <td\n className={classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td)}\n data-qa=\"table-row-left-space\"\n style={{ width: paddingLeft }}\n >\n {showAction && action && <div className={cellStyles.control}>{action}</div>}\n </td>\n )}\n {children}\n {!!paddingRight && (\n <td\n className={classnames(cellStyles.spaceCell, styles.td)}\n data-qa=\"table-row-right-space\"\n style={{ width: paddingRight }}\n ></td>\n )}\n </tr>\n {panel && showPanel && (\n <tr\n data-qa={`${dataQa}-panel`}\n data-magritte-table-row-panel\n className={classnames(styles.row, styles.rowPanel, styles.animated)}\n style={{\n textAlign: align,\n }}\n >\n {!!paddingLeft && (\n <td\n className={classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td)}\n data-qa=\"table-row-left-space\"\n style={{ width: paddingLeft }}\n ></td>\n )}\n {panel}\n {!!paddingRight && (\n <td\n className={classnames(cellStyles.spaceCell, styles.td)}\n data-qa=\"table-row-right-space\"\n style={{ width: paddingRight }}\n ></td>\n )}\n </tr>\n )}\n </>\n );\n};\n\nexport const TableRow = forwardRef(TableRowComponent);\n"],"names":[
|
|
1
|
+
{"version":3,"file":"TableRow.js","sources":["src/TableRow.tsx"],"sourcesContent":["import React, { type ForwardedRef, forwardRef, useContext, useEffect, useRef } from 'react';\nimport classnames from 'classnames';\n\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { TableContext } from '@hh.ru/magritte-ui-table/context';\nimport { TableRowProps } from '@hh.ru/magritte-ui-table/types';\n\nimport cellStyles from './cell.less';\nimport styles from './table.less';\n\nconst TableRowComponent = (\n {\n style,\n styleHighlighted,\n action,\n showAction,\n animated,\n onClick,\n panel,\n showPanel,\n children,\n measure,\n align,\n hoverEnabled,\n verticalAlign = 'top',\n 'data-qa': dataQa = 'table-row',\n ...rest\n }: TableRowProps,\n ref: ForwardedRef<HTMLTableRowElement>\n) => {\n const { paddingLeft, paddingRight, hoverEnabled: _tableHoverEnabled } = useContext(TableContext);\n const _hoverEnabled = hoverEnabled ?? _tableHoverEnabled;\n const highlightedColor = styleHighlighted || style;\n const wasPanelShown = useRef<boolean | null>(null);\n const rowRef = useRef(null);\n const multiRef = useMultipleRefs(ref, rowRef);\n\n useEffect(() => {\n if (wasPanelShown.current === null) {\n wasPanelShown.current = !!(panel && showPanel);\n return;\n }\n\n if (wasPanelShown.current !== !!(panel && showPanel)) {\n wasPanelShown.current = !!(panel && showPanel);\n rowRef.current && measure?.(rowRef.current);\n }\n }, [panel, showPanel, measure]);\n\n return (\n <>\n <tr\n {...rest}\n className={classnames(styles.row, {\n [styles.active]: !!onClick,\n [styles.hoverEnabled]: _hoverEnabled,\n [styles.animated]: animated,\n [styles.withPanel]: showPanel && panel,\n [styles[`style-${style}`]]: style,\n [styles[`style-highlighted-${highlightedColor}`]]: highlightedColor,\n })}\n onClick={onClick}\n ref={multiRef}\n data-qa={dataQa}\n style={{\n textAlign: align,\n verticalAlign,\n }}\n >\n {!!paddingLeft && (\n <td\n className={classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td)}\n data-qa=\"table-row-left-space\"\n style={{ width: paddingLeft }}\n >\n {showAction && action && <div className={cellStyles.control}>{action}</div>}\n </td>\n )}\n {children}\n {!!paddingRight && (\n <td\n className={classnames(cellStyles.spaceCell, styles.td)}\n data-qa=\"table-row-right-space\"\n style={{ width: paddingRight }}\n ></td>\n )}\n </tr>\n {panel && showPanel && (\n <tr\n data-qa={`${dataQa}-panel`}\n data-magritte-table-row-panel\n className={classnames(styles.row, styles.rowPanel, styles.animated)}\n style={{\n textAlign: align,\n }}\n >\n {!!paddingLeft && (\n <td\n className={classnames(cellStyles.spaceCell, cellStyles.pinned, styles.td)}\n data-qa=\"table-row-left-space\"\n style={{ width: paddingLeft }}\n ></td>\n )}\n {panel}\n {!!paddingRight && (\n <td\n className={classnames(cellStyles.spaceCell, styles.td)}\n data-qa=\"table-row-right-space\"\n style={{ width: paddingRight }}\n ></td>\n )}\n </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;AAAA,OAAA;AAAA,KAET;AAAA,GAER,EAAA,CAAA,CAAA;AAER,CAAA,CAAA;AAEa,MAAA,QAAA,GAAW,WAAW,iBAAiB;;;;"}
|
|
@@ -4,44 +4,55 @@ import { forwardRef, useContext, Children, isValidElement, useRef, cloneElement
|
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
import { VirtualizedListContext } from './context.js';
|
|
6
6
|
import { useVirtualizedList } from './useVirtualizedList.js';
|
|
7
|
-
import { s as styles } from '../virtualized-list-
|
|
7
|
+
import { s as styles } from '../virtualized-list-DZqJXIA7.js';
|
|
8
8
|
import '@tanstack/react-virtual';
|
|
9
9
|
|
|
10
|
-
const ActivatedVirtualizedList = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
const ActivatedVirtualizedList = ({
|
|
11
|
+
ElementItem = "div",
|
|
12
|
+
Element = "div",
|
|
13
|
+
className,
|
|
14
|
+
children,
|
|
15
|
+
...rest
|
|
16
|
+
}) => {
|
|
17
|
+
const childArray = Children.toArray(children).filter((e) => isValidElement(e));
|
|
18
|
+
const contentRef = useRef(null);
|
|
19
|
+
const virtualizer = useVirtualizedList({
|
|
20
|
+
count: childArray.length,
|
|
21
|
+
contentRef
|
|
22
|
+
});
|
|
23
|
+
const additionalProps = { ...rest };
|
|
24
|
+
additionalProps.ref = contentRef;
|
|
25
|
+
const items = virtualizer.getVirtualItems();
|
|
26
|
+
const [paddingTop, paddingBottom] = items.length > 0 ? [
|
|
27
|
+
Math.max(0, items[0].start - virtualizer.options.scrollMargin),
|
|
28
|
+
Math.max(
|
|
29
|
+
0,
|
|
30
|
+
virtualizer.getTotalSize() - (items[items.length - 1].end - virtualizer.options.scrollMargin)
|
|
31
|
+
)
|
|
32
|
+
] : [0, 0];
|
|
33
|
+
return /* @__PURE__ */ jsxs(Element, { ...additionalProps, className: classnames(styles.virtualizedList, className), children: [
|
|
34
|
+
paddingTop > 0 && /* @__PURE__ */ jsx(ElementItem, { style: { height: paddingTop } }),
|
|
35
|
+
virtualizer.getVirtualItems().map((virtualItem) => {
|
|
36
|
+
return cloneElement(childArray[virtualItem.index], {
|
|
37
|
+
key: virtualItem.key,
|
|
38
|
+
"data-index": virtualItem.index,
|
|
39
|
+
ref: virtualItem.measureElement,
|
|
40
|
+
measure: virtualItem.measureElement
|
|
41
|
+
});
|
|
42
|
+
}),
|
|
43
|
+
paddingBottom > 0 && /* @__PURE__ */ jsx(ElementItem, { style: { height: paddingBottom } })
|
|
44
|
+
] });
|
|
34
45
|
};
|
|
35
46
|
const VirtualizedList = (props) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
const { Element = "div", className, ElementItem, children, ...rest } = props;
|
|
48
|
+
const { virtualized } = useContext(VirtualizedListContext);
|
|
49
|
+
if (!virtualized) {
|
|
50
|
+
return /* @__PURE__ */ jsx(Element, { ...rest, className: classnames(styles.virtualizedList, className), children });
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsx(ActivatedVirtualizedList, { ...props });
|
|
42
53
|
};
|
|
43
54
|
const VirtualizedItemComponent = ({ measure, ...rest }, ref) => {
|
|
44
|
-
|
|
55
|
+
return /* @__PURE__ */ jsx("div", { ...rest, ref });
|
|
45
56
|
};
|
|
46
57
|
const VirtualizedItem = forwardRef(VirtualizedItemComponent);
|
|
47
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedList.js","sources":["src/VirtualizedList/VirtualizedList.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n FC,\n type ForwardedRef,\n forwardRef,\n HTMLAttributes,\n isValidElement,\n PropsWithChildren,\n ReactElement,\n useContext,\n useRef,\n} from 'react';\nimport { VirtualItem } from '@tanstack/virtual-core';\nimport classnames from 'classnames';\n\nimport { VirtualizedListContext } from '@hh.ru/magritte-ui-table/VirtualizedList/context';\nimport { useVirtualizedList } from '@hh.ru/magritte-ui-table/VirtualizedList/useVirtualizedList';\n\nimport styles from './virtualized-list.less';\n\ninterface VirtualizedListProps extends PropsWithChildren<HTMLAttributes<HTMLElement>> {\n ElementItem?: keyof JSX.IntrinsicElements & keyof HTMLElementTagNameMap;\n Element?: keyof JSX.IntrinsicElements & keyof HTMLElementTagNameMap;\n}\n\nconst ActivatedVirtualizedList: FC<VirtualizedListProps> = ({\n ElementItem = 'div',\n Element = 'div',\n className,\n children,\n ...rest\n}) => {\n const childArray = Children.toArray(children).filter<ReactElement>((e): e is ReactElement => isValidElement(e));\n const contentRef = useRef<HTMLElement>(null);\n\n const virtualizer = useVirtualizedList({\n count: childArray.length,\n contentRef,\n });\n\n const additionalProps: Record<string, unknown> = { ...rest };\n\n additionalProps.ref = contentRef;\n\n const items = virtualizer.getVirtualItems();\n const [paddingTop, paddingBottom] =\n items.length > 0\n ? [\n Math.max(0, items[0].start - virtualizer.options.scrollMargin),\n Math.max(\n 0,\n virtualizer.getTotalSize() - (items[items.length - 1].end - virtualizer.options.scrollMargin)\n ),\n ]\n : [0, 0];\n\n return (\n <Element {...additionalProps} className={classnames(styles.virtualizedList, className)}>\n {paddingTop > 0 && <ElementItem style={{ height: paddingTop }}></ElementItem>}\n {virtualizer.getVirtualItems().map((virtualItem) => {\n return cloneElement(childArray[virtualItem.index], {\n key: virtualItem.key,\n 'data-index': virtualItem.index,\n ref: virtualItem.measureElement,\n measure: virtualItem.measureElement,\n });\n })}\n {paddingBottom > 0 && <ElementItem style={{ height: paddingBottom }}></ElementItem>}\n </Element>\n );\n};\n\nexport const VirtualizedList: FC<VirtualizedListProps> = (props) => {\n const { Element = 'div', className, ElementItem, children, ...rest } = props;\n\n const { virtualized } = useContext(VirtualizedListContext);\n\n if (!virtualized) {\n return (\n <Element {...rest} className={classnames(styles.virtualizedList, className)}>\n {children}\n </Element>\n );\n }\n\n return <ActivatedVirtualizedList {...props} />;\n};\n\ninterface VirtualizedItemProps extends PropsWithChildren<HTMLAttributes<HTMLElement>> {\n measure?: VirtualItem<Element>['measureElement'];\n}\n\nconst VirtualizedItemComponent = ({ measure, ...rest }: VirtualizedItemProps, ref: ForwardedRef<HTMLDivElement>) => {\n return <div {...rest} ref={ref} />;\n};\n\nexport const VirtualizedItem = forwardRef(VirtualizedItemComponent);\n"],"names":[
|
|
1
|
+
{"version":3,"file":"VirtualizedList.js","sources":["src/VirtualizedList/VirtualizedList.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n FC,\n type ForwardedRef,\n forwardRef,\n HTMLAttributes,\n isValidElement,\n PropsWithChildren,\n ReactElement,\n useContext,\n useRef,\n} from 'react';\nimport { VirtualItem } from '@tanstack/virtual-core';\nimport classnames from 'classnames';\n\nimport { VirtualizedListContext } from '@hh.ru/magritte-ui-table/VirtualizedList/context';\nimport { useVirtualizedList } from '@hh.ru/magritte-ui-table/VirtualizedList/useVirtualizedList';\n\nimport styles from './virtualized-list.less';\n\ninterface VirtualizedListProps extends PropsWithChildren<HTMLAttributes<HTMLElement>> {\n ElementItem?: keyof JSX.IntrinsicElements & keyof HTMLElementTagNameMap;\n Element?: keyof JSX.IntrinsicElements & keyof HTMLElementTagNameMap;\n}\n\nconst ActivatedVirtualizedList: FC<VirtualizedListProps> = ({\n ElementItem = 'div',\n Element = 'div',\n className,\n children,\n ...rest\n}) => {\n const childArray = Children.toArray(children).filter<ReactElement>((e): e is ReactElement => isValidElement(e));\n const contentRef = useRef<HTMLElement>(null);\n\n const virtualizer = useVirtualizedList({\n count: childArray.length,\n contentRef,\n });\n\n const additionalProps: Record<string, unknown> = { ...rest };\n\n additionalProps.ref = contentRef;\n\n const items = virtualizer.getVirtualItems();\n const [paddingTop, paddingBottom] =\n items.length > 0\n ? [\n Math.max(0, items[0].start - virtualizer.options.scrollMargin),\n Math.max(\n 0,\n virtualizer.getTotalSize() - (items[items.length - 1].end - virtualizer.options.scrollMargin)\n ),\n ]\n : [0, 0];\n\n return (\n <Element {...additionalProps} className={classnames(styles.virtualizedList, className)}>\n {paddingTop > 0 && <ElementItem style={{ height: paddingTop }}></ElementItem>}\n {virtualizer.getVirtualItems().map((virtualItem) => {\n return cloneElement(childArray[virtualItem.index], {\n key: virtualItem.key,\n 'data-index': virtualItem.index,\n ref: virtualItem.measureElement,\n measure: virtualItem.measureElement,\n });\n })}\n {paddingBottom > 0 && <ElementItem style={{ height: paddingBottom }}></ElementItem>}\n </Element>\n );\n};\n\nexport const VirtualizedList: FC<VirtualizedListProps> = (props) => {\n const { Element = 'div', className, ElementItem, children, ...rest } = props;\n\n const { virtualized } = useContext(VirtualizedListContext);\n\n if (!virtualized) {\n return (\n <Element {...rest} className={classnames(styles.virtualizedList, className)}>\n {children}\n </Element>\n );\n }\n\n return <ActivatedVirtualizedList {...props} />;\n};\n\ninterface VirtualizedItemProps extends PropsWithChildren<HTMLAttributes<HTMLElement>> {\n measure?: VirtualItem<Element>['measureElement'];\n}\n\nconst VirtualizedItemComponent = ({ measure, ...rest }: VirtualizedItemProps, ref: ForwardedRef<HTMLDivElement>) => {\n return <div {...rest} ref={ref} />;\n};\n\nexport const VirtualizedItem = forwardRef(VirtualizedItemComponent);\n"],"names":[],"mappings":";;;;;;;;AA0BA,MAAM,2BAAqD,CAAC;AAAA,EACxD,WAAc,GAAA,KAAA;AAAA,EACd,OAAU,GAAA,KAAA;AAAA,EACV,SAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAG,IAAA;AACP,CAAM,KAAA;AACF,EAAM,MAAA,UAAA,GAAa,QAAS,CAAA,OAAA,CAAQ,QAAQ,CAAA,CAAE,OAAqB,CAAC,CAAA,KAAyB,cAAe,CAAA,CAAC,CAAC,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AAA,QACjB,cAAc,WAAY,CAAA,KAAA;AAAA,QAC1B,KAAK,WAAY,CAAA,cAAA;AAAA,QACjB,SAAS,WAAY,CAAA,cAAA;AAAA,OACxB,CAAA,CAAA;AAAA,KACJ,CAAA;AAAA,IACA,aAAA,GAAgB,qBAAM,GAAA,CAAA,WAAA,EAAA,EAAY,OAAO,EAAE,MAAA,EAAQ,eAAiB,EAAA,CAAA;AAAA,GACzE,EAAA,CAAA,CAAA;AAER,CAAA,CAAA;AAEa,MAAA,eAAA,GAA4C,CAAC,KAAU,KAAA;AAChE,EAAM,MAAA,EAAE,UAAU,KAAO,EAAA,SAAA,EAAW,aAAa,QAAU,EAAA,GAAG,MAAS,GAAA,KAAA,CAAA;AAEvE,EAAA,MAAM,EAAE,WAAA,EAAgB,GAAA,UAAA,CAAW,sBAAsB,CAAA,CAAA;AAEzD,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IACI,uBAAA,GAAA,CAAC,OAAS,EAAA,EAAA,GAAG,IAAM,EAAA,SAAA,EAAW,WAAW,MAAO,CAAA,eAAA,EAAiB,SAAS,CAAA,EACrE,QACL,EAAA,CAAA,CAAA;AAAA,GAER;AAEA,EAAO,uBAAA,GAAA,CAAC,wBAA0B,EAAA,EAAA,GAAG,KAAO,EAAA,CAAA,CAAA;AAChD,EAAA;AAMA,MAAM,2BAA2B,CAAC,EAAE,SAAS,GAAG,IAAA,IAA8B,GAAsC,KAAA;AAChH,EAAA,uBAAQ,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,IAAA,EAAM,GAAU,EAAA,CAAA,CAAA;AACpC,CAAA,CAAA;AAEa,MAAA,eAAA,GAAkB,WAAW,wBAAwB;;;;"}
|
|
@@ -5,22 +5,48 @@ import classnames from 'classnames';
|
|
|
5
5
|
import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
|
|
6
6
|
import { useScrollbar, Scrollbar } from '@hh.ru/magritte-ui-scrollbar';
|
|
7
7
|
import { VirtualizedListContext, DEFAULT_ITEM_HEIGHT } from './context.js';
|
|
8
|
-
import { s as styles } from '../virtualized-list-
|
|
8
|
+
import { s as styles } from '../virtualized-list-DZqJXIA7.js';
|
|
9
9
|
|
|
10
|
-
const VirtualizedListWrapperComponent = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const VirtualizedListWrapperComponent = ({
|
|
11
|
+
fixedSize,
|
|
12
|
+
topPanel,
|
|
13
|
+
bottomPanel,
|
|
14
|
+
virtualized = true,
|
|
15
|
+
measureElement,
|
|
16
|
+
estimateSize = DEFAULT_ITEM_HEIGHT,
|
|
17
|
+
children
|
|
18
|
+
}, ref) => {
|
|
19
|
+
const { hasVerticalScroll, verticalScrollbarProps, ...vScrollbar } = useScrollbar({
|
|
20
|
+
axis: fixedSize ? "vertical" : "none"
|
|
21
|
+
});
|
|
22
|
+
const contentRef = useRef(null);
|
|
23
|
+
const wrapperRefCallback = useMultipleRefs(ref, vScrollbar.scrollContainerRef);
|
|
24
|
+
const contentRefCallback = useMultipleRefs(contentRef, vScrollbar.contentWrapperRef);
|
|
25
|
+
const value = useMemo(
|
|
26
|
+
() => ({
|
|
27
|
+
fixedSize,
|
|
28
|
+
virtualized,
|
|
29
|
+
measureElement,
|
|
30
|
+
estimateSize
|
|
31
|
+
}),
|
|
32
|
+
[fixedSize, virtualized, measureElement, estimateSize]
|
|
33
|
+
);
|
|
34
|
+
return /* @__PURE__ */ jsxs("div", { className: classnames(styles.virtualizedWrapper, vScrollbar.hoverContainerCssClass), children: [
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
"div",
|
|
37
|
+
{
|
|
38
|
+
className: classnames({ [styles.scrollWrapper]: fixedSize }),
|
|
39
|
+
"data-virtualized-list-wrapper": true,
|
|
40
|
+
ref: wrapperRefCallback,
|
|
41
|
+
children: /* @__PURE__ */ jsxs(VirtualizedListContext.Provider, { value, children: [
|
|
42
|
+
topPanel,
|
|
43
|
+
/* @__PURE__ */ jsx("div", { ref: contentRefCallback, "data-virtualized-list-content": true, children }),
|
|
44
|
+
bottomPanel
|
|
45
|
+
] })
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
hasVerticalScroll && /* @__PURE__ */ jsx(Scrollbar, { className: styles.verticalScrollbar, ...verticalScrollbarProps })
|
|
49
|
+
] });
|
|
24
50
|
};
|
|
25
51
|
const VirtualizedListWrapper = forwardRef(VirtualizedListWrapperComponent);
|
|
26
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedListWrapper.js","sources":["src/VirtualizedList/VirtualizedListWrapper.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, PropsWithChildren, ReactNode, useMemo, useRef } from 'react';\nimport { VirtualizerOptions } from '@tanstack/virtual-core';\nimport classnames from 'classnames';\n\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { Scrollbar, useScrollbar } from '@hh.ru/magritte-ui-scrollbar';\nimport { VirtualizedListContext, DEFAULT_ITEM_HEIGHT } from '@hh.ru/magritte-ui-table/VirtualizedList/context';\n\nimport styles from './virtualized-list.less';\n\ninterface VirtualizedListWrapperProps extends PropsWithChildren {\n /** Находится ли список в блоке ограниченной высоты */\n fixedSize?: boolean;\n /** Верхняя панель */\n topPanel?: ReactNode;\n /** Нижняя панель */\n bottomPanel?: ReactNode;\n /** Включена ли виртуализация */\n virtualized?: boolean;\n /** Функция для замера размеров айтема списка (по умолчанию используется getBoundingClientRect.height) */\n measureElement?: VirtualizerOptions<HTMLElement, Element>['measureElement'];\n /** Предполагаемая высота айтема (по умолчанию 80px) */\n estimateSize?: number;\n}\n\nconst VirtualizedListWrapperComponent = (\n {\n fixedSize,\n topPanel,\n bottomPanel,\n virtualized = true,\n measureElement,\n estimateSize = DEFAULT_ITEM_HEIGHT,\n children,\n }: VirtualizedListWrapperProps,\n ref: ForwardedRef<HTMLDivElement>\n) => {\n const { hasVerticalScroll, verticalScrollbarProps, ...vScrollbar } = useScrollbar({\n axis: fixedSize ? 'vertical' : 'none',\n });\n const contentRef = useRef<HTMLDivElement>(null);\n const wrapperRefCallback = useMultipleRefs(ref, vScrollbar.scrollContainerRef);\n const contentRefCallback = useMultipleRefs(contentRef, vScrollbar.contentWrapperRef);\n\n const value = useMemo(\n () => ({\n fixedSize,\n virtualized,\n measureElement,\n estimateSize,\n }),\n [fixedSize, virtualized, measureElement, estimateSize]\n );\n\n return (\n <div className={classnames(styles.virtualizedWrapper, vScrollbar.hoverContainerCssClass)}>\n <div\n className={classnames({ [styles.scrollWrapper]: fixedSize })}\n data-virtualized-list-wrapper\n ref={wrapperRefCallback}\n >\n <VirtualizedListContext.Provider value={value}>\n {topPanel}\n <div ref={contentRefCallback} data-virtualized-list-content>\n {children}\n </div>\n {bottomPanel}\n </VirtualizedListContext.Provider>\n </div>\n {hasVerticalScroll && <Scrollbar className={styles.verticalScrollbar} {...verticalScrollbarProps} />}\n </div>\n );\n};\n\nexport const VirtualizedListWrapper = forwardRef(VirtualizedListWrapperComponent);\n"],"names":[
|
|
1
|
+
{"version":3,"file":"VirtualizedListWrapper.js","sources":["src/VirtualizedList/VirtualizedListWrapper.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, PropsWithChildren, ReactNode, useMemo, useRef } from 'react';\nimport { VirtualizerOptions } from '@tanstack/virtual-core';\nimport classnames from 'classnames';\n\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { Scrollbar, useScrollbar } from '@hh.ru/magritte-ui-scrollbar';\nimport { VirtualizedListContext, DEFAULT_ITEM_HEIGHT } from '@hh.ru/magritte-ui-table/VirtualizedList/context';\n\nimport styles from './virtualized-list.less';\n\ninterface VirtualizedListWrapperProps extends PropsWithChildren {\n /** Находится ли список в блоке ограниченной высоты */\n fixedSize?: boolean;\n /** Верхняя панель */\n topPanel?: ReactNode;\n /** Нижняя панель */\n bottomPanel?: ReactNode;\n /** Включена ли виртуализация */\n virtualized?: boolean;\n /** Функция для замера размеров айтема списка (по умолчанию используется getBoundingClientRect.height) */\n measureElement?: VirtualizerOptions<HTMLElement, Element>['measureElement'];\n /** Предполагаемая высота айтема (по умолчанию 80px) */\n estimateSize?: number;\n}\n\nconst VirtualizedListWrapperComponent = (\n {\n fixedSize,\n topPanel,\n bottomPanel,\n virtualized = true,\n measureElement,\n estimateSize = DEFAULT_ITEM_HEIGHT,\n children,\n }: VirtualizedListWrapperProps,\n ref: ForwardedRef<HTMLDivElement>\n) => {\n const { hasVerticalScroll, verticalScrollbarProps, ...vScrollbar } = useScrollbar({\n axis: fixedSize ? 'vertical' : 'none',\n });\n const contentRef = useRef<HTMLDivElement>(null);\n const wrapperRefCallback = useMultipleRefs(ref, vScrollbar.scrollContainerRef);\n const contentRefCallback = useMultipleRefs(contentRef, vScrollbar.contentWrapperRef);\n\n const value = useMemo(\n () => ({\n fixedSize,\n virtualized,\n measureElement,\n estimateSize,\n }),\n [fixedSize, virtualized, measureElement, estimateSize]\n );\n\n return (\n <div className={classnames(styles.virtualizedWrapper, vScrollbar.hoverContainerCssClass)}>\n <div\n className={classnames({ [styles.scrollWrapper]: fixedSize })}\n data-virtualized-list-wrapper\n ref={wrapperRefCallback}\n >\n <VirtualizedListContext.Provider value={value}>\n {topPanel}\n <div ref={contentRefCallback} data-virtualized-list-content>\n {children}\n </div>\n {bottomPanel}\n </VirtualizedListContext.Provider>\n </div>\n {hasVerticalScroll && <Scrollbar className={styles.verticalScrollbar} {...verticalScrollbarProps} />}\n </div>\n );\n};\n\nexport const VirtualizedListWrapper = forwardRef(VirtualizedListWrapperComponent);\n"],"names":[],"mappings":";;;;;;;;AAyBA,MAAM,kCAAkC,CACpC;AAAA,EACI,SAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAc,GAAA,IAAA;AAAA,EACd,cAAA;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AA,SACL,EAAA,CAAA;AAAA,OAAA;AAAA,KACJ;AAAA,IACC,qCAAsB,GAAA,CAAA,SAAA,EAAA,EAAU,WAAW,MAAO,CAAA,iBAAA,EAAoB,GAAG,sBAAwB,EAAA,CAAA;AAAA,GACtG,EAAA,CAAA,CAAA;AAER,CAAA,CAAA;AAEa,MAAA,sBAAA,GAAyB,WAAW,+BAA+B;;;;"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import './../index.css';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
|
-
import { s as styles } from '../virtualized-list-
|
|
4
|
+
import { s as styles } from '../virtualized-list-DZqJXIA7.js';
|
|
5
5
|
|
|
6
|
-
const VirtualizedPanel = ({ stickyTop, stickyBottom, style =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
6
|
+
const VirtualizedPanel = ({ stickyTop, stickyBottom, style = "primary", children }) => {
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
|
+
"div",
|
|
9
|
+
{
|
|
10
|
+
className: classnames(styles.panelContainer, styles.topPanel, {
|
|
11
|
+
[styles[`panel-style-${style}`]]: style,
|
|
12
|
+
[styles.stickyTop]: stickyTop,
|
|
13
|
+
[styles.stickyBottom]: stickyBottom
|
|
14
|
+
}),
|
|
15
|
+
children: /* @__PURE__ */ jsx("div", { className: classnames(styles.panel), children })
|
|
16
|
+
}
|
|
17
|
+
);
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
export { VirtualizedPanel };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedPanel.js","sources":["src/VirtualizedList/VirtualizedPanel.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport classnames from 'classnames';\n\nimport { TokenColorBackground } from '@hh.ru/magritte-design-tokens/types';\n\nimport styles from './virtualized-list.less';\n\ninterface PanelProps extends PropsWithChildren {\n /** Прилипает ли панель сверху */\n stickyTop?: boolean;\n /** Прилипает ли панель снизу */\n stickyBottom?: boolean;\n /** Цвет фона */\n style?: TokenColorBackground;\n}\n\nexport const VirtualizedPanel: FC<PanelProps> = ({ stickyTop, stickyBottom, style = 'primary', children }) => {\n return (\n <div\n className={classnames(styles.panelContainer, styles.topPanel, {\n [styles[`panel-style-${style}`]]: style,\n [styles.stickyTop]: stickyTop,\n [styles.stickyBottom]: stickyBottom,\n })}\n >\n <div className={classnames(styles.panel)}>{children}</div>\n </div>\n );\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"VirtualizedPanel.js","sources":["src/VirtualizedList/VirtualizedPanel.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport classnames from 'classnames';\n\nimport { TokenColorBackground } from '@hh.ru/magritte-design-tokens/types';\n\nimport styles from './virtualized-list.less';\n\ninterface PanelProps extends PropsWithChildren {\n /** Прилипает ли панель сверху */\n stickyTop?: boolean;\n /** Прилипает ли панель снизу */\n stickyBottom?: boolean;\n /** Цвет фона */\n style?: TokenColorBackground;\n}\n\nexport const VirtualizedPanel: FC<PanelProps> = ({ stickyTop, stickyBottom, style = 'primary', children }) => {\n return (\n <div\n className={classnames(styles.panelContainer, styles.topPanel, {\n [styles[`panel-style-${style}`]]: style,\n [styles.stickyTop]: stickyTop,\n [styles.stickyBottom]: stickyBottom,\n })}\n >\n <div className={classnames(styles.panel)}>{children}</div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;AAgBa,MAAA,gBAAA,GAAmC,CAAC,EAAE,SAAA,EAAW,cAAc,KAAQ,GAAA,SAAA,EAAW,UAAe,KAAA;AAC1G,EACI,uBAAA,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACG,SAAW,EAAA,UAAA,CAAW,MAAO,CAAA,cAAA,EAAgB,OAAO,QAAU,EAAA;AAAA,QAC1D,CAAC,MAAO,CAAA,CAAA,YAAA,EAAe,KAAK,CAAA,CAAE,CAAC,GAAG,KAAA;AAAA,QAClC,CAAC,MAAO,CAAA,SAAS,GAAG,SAAA;AAAA,QACpB,CAAC,MAAO,CAAA,YAAY,GAAG,YAAA;AAAA,OAC1B,CAAA;AAAA,MAED,8BAAC,KAAI,EAAA,EAAA,SAAA,EAAW,WAAW,MAAO,CAAA,KAAK,GAAI,QAAS,EAAA,CAAA;AAAA,KAAA;AAAA,GACxD,CAAA;AAER;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["src/VirtualizedList/context.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport { VirtualizerOptions } from '@tanstack/virtual-core';\n\nexport const DEFAULT_ITEM_HEIGHT = 80;\n\nexport interface VirtualizedListContextProps {\n fixedSize?: boolean;\n virtualized?: boolean;\n measureElement?: VirtualizerOptions<HTMLElement, Element>['measureElement'];\n estimateSize: number;\n}\n\nexport const VirtualizedListContext = createContext<VirtualizedListContextProps>({\n estimateSize: DEFAULT_ITEM_HEIGHT,\n});\n"],"names":[],"mappings":";;AAGO,MAAM,
|
|
1
|
+
{"version":3,"file":"context.js","sources":["src/VirtualizedList/context.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport { VirtualizerOptions } from '@tanstack/virtual-core';\n\nexport const DEFAULT_ITEM_HEIGHT = 80;\n\nexport interface VirtualizedListContextProps {\n fixedSize?: boolean;\n virtualized?: boolean;\n measureElement?: VirtualizerOptions<HTMLElement, Element>['measureElement'];\n estimateSize: number;\n}\n\nexport const VirtualizedListContext = createContext<VirtualizedListContextProps>({\n estimateSize: DEFAULT_ITEM_HEIGHT,\n});\n"],"names":[],"mappings":";;AAGO,MAAM,mBAAsB,GAAA,GAAA;AAS5B,MAAM,yBAAyB,aAA2C,CAAA;AAAA,EAC7E,YAAc,EAAA,mBAAA;AAClB,CAAC;;;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
1
|
+
export * from '../VirtualizedList/VirtualizedListWrapper';
|
|
2
|
+
export * from '../VirtualizedList/VirtualizedList';
|
|
3
|
+
export * from '../VirtualizedList/VirtualizedPanel';
|
package/VirtualizedList/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import 'classnames';
|
|
|
8
8
|
import '@hh.ru/magritte-common-use-multiple-refs';
|
|
9
9
|
import '@hh.ru/magritte-ui-scrollbar';
|
|
10
10
|
import './context.js';
|
|
11
|
-
import '../virtualized-list-
|
|
11
|
+
import '../virtualized-list-DZqJXIA7.js';
|
|
12
12
|
import './useVirtualizedList.js';
|
|
13
13
|
import '@tanstack/react-virtual';
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,39 +4,35 @@ import { useVirtualizer, useWindowVirtualizer } from '@tanstack/react-virtual';
|
|
|
4
4
|
import { VirtualizedListContext } from './context.js';
|
|
5
5
|
|
|
6
6
|
const useVirtualizedList = ({ count, contentRef }) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
: {}),
|
|
38
|
-
});
|
|
39
|
-
return virtualizer;
|
|
7
|
+
const { fixedSize, measureElement, estimateSize } = useContext(VirtualizedListContext);
|
|
8
|
+
const getScrollMargin = () => {
|
|
9
|
+
if (!contentRef.current) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
if (fixedSize) {
|
|
13
|
+
const containerElement = contentRef.current.closest("[data-virtualized-list-content]");
|
|
14
|
+
return contentRef?.current.offsetTop + (containerElement?.offsetTop ?? 0);
|
|
15
|
+
}
|
|
16
|
+
return contentRef.current ? document.documentElement.scrollTop + contentRef.current.getBoundingClientRect().top : 0;
|
|
17
|
+
};
|
|
18
|
+
const virtualizerOptions = {
|
|
19
|
+
count,
|
|
20
|
+
estimateSize: () => estimateSize,
|
|
21
|
+
overscan: 5,
|
|
22
|
+
measureElement,
|
|
23
|
+
scrollMargin: getScrollMargin(),
|
|
24
|
+
initialRect: { width: 0, height: 5 * estimateSize }
|
|
25
|
+
};
|
|
26
|
+
const virtualizerHook = fixedSize ? useVirtualizer : useWindowVirtualizer;
|
|
27
|
+
const virtualizer = virtualizerHook({
|
|
28
|
+
...virtualizerOptions,
|
|
29
|
+
...fixedSize ? {
|
|
30
|
+
getScrollElement: () => {
|
|
31
|
+
return contentRef.current?.closest("[data-virtualized-list-wrapper]") || null;
|
|
32
|
+
}
|
|
33
|
+
} : {}
|
|
34
|
+
});
|
|
35
|
+
return virtualizer;
|
|
40
36
|
};
|
|
41
37
|
|
|
42
38
|
export { useVirtualizedList };
|