@snack-uikit/table 0.25.13-preview-03091779.0 → 0.25.13
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 +11 -0
- package/README.md +0 -6
- package/dist/cjs/components/Table/Table.d.ts +2 -2
- package/dist/cjs/components/Table/Table.js +23 -44
- package/dist/cjs/components/Table/styles.module.css +0 -3
- package/dist/cjs/components/Table/utils.d.ts +0 -10
- package/dist/cjs/components/Table/utils.js +0 -19
- package/dist/cjs/components/types.d.ts +1 -5
- package/dist/cjs/helperComponents/Rows/BodyRow.d.ts +2 -3
- package/dist/cjs/helperComponents/Rows/BodyRow.js +9 -20
- package/dist/cjs/helperComponents/Rows/Row.d.ts +5 -4
- package/dist/cjs/helperComponents/Rows/Row.js +3 -5
- package/dist/esm/components/Table/Table.d.ts +2 -2
- package/dist/esm/components/Table/Table.js +10 -24
- package/dist/esm/components/Table/styles.module.css +0 -3
- package/dist/esm/components/Table/utils.d.ts +0 -10
- package/dist/esm/components/Table/utils.js +0 -14
- package/dist/esm/components/types.d.ts +1 -5
- package/dist/esm/helperComponents/Rows/BodyRow.d.ts +2 -3
- package/dist/esm/helperComponents/Rows/BodyRow.js +4 -17
- package/dist/esm/helperComponents/Rows/Row.d.ts +5 -4
- package/dist/esm/helperComponents/Rows/Row.js +3 -4
- package/package.json +5 -7
- package/src/components/Table/Table.tsx +14 -44
- package/src/components/Table/styles.module.scss +0 -5
- package/src/components/Table/{utils.tsx → utils.ts} +0 -18
- package/src/components/types.ts +1 -9
- package/src/helperComponents/Rows/BodyRow.tsx +47 -53
- package/src/helperComponents/Rows/Row.tsx +9 -8
- package/dist/cjs/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
- package/dist/cjs/components/Table/hooks/useRowVirtualizer.js +0 -45
- package/dist/cjs/helperComponents/Rows/VirtualRow.d.ts +0 -7
- package/dist/cjs/helperComponents/Rows/VirtualRow.js +0 -40
- package/dist/esm/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
- package/dist/esm/components/Table/hooks/useRowVirtualizer.js +0 -29
- package/dist/esm/helperComponents/Rows/VirtualRow.d.ts +0 -7
- package/dist/esm/helperComponents/Rows/VirtualRow.js +0 -28
- package/src/components/Table/hooks/useRowVirtualizer.ts +0 -51
- package/src/helperComponents/Rows/VirtualRow.tsx +0 -31
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
2
|
-
import { useReducer } from 'react';
|
|
3
|
-
import { useLayoutEffect } from '@snack-uikit/utils';
|
|
4
|
-
/**
|
|
5
|
-
* If virtualization is disabled
|
|
6
|
-
*/
|
|
7
|
-
const useNoopVirtualizerFn = () => undefined;
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
export function useRowVirtualizer(table, enabled) {
|
|
10
|
-
var _a;
|
|
11
|
-
const { getRowModel, options } = table;
|
|
12
|
-
const { rowVirtualizerInstanceRef, rowVirtualizerOptions, tableContainerRef } = ((_a = options.meta) !== null && _a !== void 0 ? _a : {});
|
|
13
|
-
// TODO
|
|
14
|
-
const [_, forceUpdate] = useReducer(x => x + 1, 0);
|
|
15
|
-
const useVirtualizerFn = enabled ? useVirtualizer : useNoopVirtualizerFn;
|
|
16
|
-
const normalRowHeight = 40;
|
|
17
|
-
const rowVirtualizer = useVirtualizerFn(Object.assign({ count: getRowModel().rows.length, estimateSize: () => normalRowHeight, getScrollElement: () => tableContainerRef.current, measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1
|
|
18
|
-
? element => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height
|
|
19
|
-
: undefined, overscan: 28 }, rowVirtualizerOptions));
|
|
20
|
-
// TODO
|
|
21
|
-
useLayoutEffect(() => {
|
|
22
|
-
if (enabled)
|
|
23
|
-
forceUpdate();
|
|
24
|
-
}, [enabled]);
|
|
25
|
-
if ((rowVirtualizerInstanceRef === null || rowVirtualizerInstanceRef === void 0 ? void 0 : rowVirtualizerInstanceRef.current) && rowVirtualizer) {
|
|
26
|
-
rowVirtualizerInstanceRef.current = rowVirtualizer;
|
|
27
|
-
}
|
|
28
|
-
return rowVirtualizer;
|
|
29
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { VirtualItem } from '@tanstack/react-virtual';
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
3
|
-
export declare const VirtualRow: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
virtualRow?: VirtualItem;
|
|
5
|
-
} & {
|
|
6
|
-
children?: import("react").ReactNode | undefined;
|
|
7
|
-
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { forwardRef } from 'react';
|
|
14
|
-
export const VirtualRow = forwardRef((_a, ref) => {
|
|
15
|
-
var { virtualRow, children } = _a, attributes = __rest(_a, ["virtualRow", "children"]);
|
|
16
|
-
if (!virtualRow) {
|
|
17
|
-
return _jsx(_Fragment, { children: children });
|
|
18
|
-
}
|
|
19
|
-
return (_jsx("div", Object.assign({ ref: ref, style: virtualRow
|
|
20
|
-
? {
|
|
21
|
-
position: 'absolute',
|
|
22
|
-
top: 0,
|
|
23
|
-
left: 0,
|
|
24
|
-
width: '100%',
|
|
25
|
-
transform: `translateY(${virtualRow.start}px)`,
|
|
26
|
-
}
|
|
27
|
-
: undefined }, attributes, { children: children })));
|
|
28
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Table } from '@tanstack/react-table';
|
|
2
|
-
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
3
|
-
import { MutableRefObject, useReducer } from 'react';
|
|
4
|
-
|
|
5
|
-
import { useLayoutEffect } from '@snack-uikit/utils';
|
|
6
|
-
|
|
7
|
-
import { TableProps } from '../../types';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* If virtualization is disabled
|
|
11
|
-
*/
|
|
12
|
-
const useNoopVirtualizerFn = () => undefined;
|
|
13
|
-
|
|
14
|
-
type MetaParams = Pick<TableProps<never>, 'rowVirtualizerInstanceRef' | 'rowVirtualizerOptions'> & {
|
|
15
|
-
tableContainerRef: MutableRefObject<HTMLElement | null>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
export function useRowVirtualizer(table: Table<any>, enabled: boolean) {
|
|
20
|
-
const { getRowModel, options } = table;
|
|
21
|
-
const { rowVirtualizerInstanceRef, rowVirtualizerOptions, tableContainerRef } = (options.meta ?? {}) as MetaParams;
|
|
22
|
-
|
|
23
|
-
// TODO
|
|
24
|
-
const [_, forceUpdate] = useReducer(x => x + 1, 0);
|
|
25
|
-
|
|
26
|
-
const useVirtualizerFn = enabled ? useVirtualizer : useNoopVirtualizerFn;
|
|
27
|
-
const normalRowHeight = 40;
|
|
28
|
-
|
|
29
|
-
const rowVirtualizer = useVirtualizerFn({
|
|
30
|
-
count: getRowModel().rows.length,
|
|
31
|
-
estimateSize: () => normalRowHeight,
|
|
32
|
-
getScrollElement: () => tableContainerRef.current,
|
|
33
|
-
measureElement:
|
|
34
|
-
typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1
|
|
35
|
-
? element => element?.getBoundingClientRect().height
|
|
36
|
-
: undefined,
|
|
37
|
-
overscan: 28,
|
|
38
|
-
...rowVirtualizerOptions,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// TODO
|
|
42
|
-
useLayoutEffect(() => {
|
|
43
|
-
if (enabled) forceUpdate();
|
|
44
|
-
}, [enabled]);
|
|
45
|
-
|
|
46
|
-
if (rowVirtualizerInstanceRef?.current && rowVirtualizer) {
|
|
47
|
-
rowVirtualizerInstanceRef.current = rowVirtualizer;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return rowVirtualizer;
|
|
51
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { VirtualItem } from '@tanstack/react-virtual';
|
|
2
|
-
import { forwardRef, HTMLAttributes, PropsWithChildren } from 'react';
|
|
3
|
-
|
|
4
|
-
export const VirtualRow = forwardRef<
|
|
5
|
-
HTMLDivElement,
|
|
6
|
-
PropsWithChildren<HTMLAttributes<HTMLDivElement> & { virtualRow?: VirtualItem }>
|
|
7
|
-
>(({ virtualRow, children, ...attributes }, ref) => {
|
|
8
|
-
if (!virtualRow) {
|
|
9
|
-
return <>{children}</>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<div
|
|
14
|
-
ref={ref}
|
|
15
|
-
style={
|
|
16
|
-
virtualRow
|
|
17
|
-
? {
|
|
18
|
-
position: 'absolute',
|
|
19
|
-
top: 0,
|
|
20
|
-
left: 0,
|
|
21
|
-
width: '100%',
|
|
22
|
-
transform: `translateY(${virtualRow.start}px)`,
|
|
23
|
-
}
|
|
24
|
-
: undefined
|
|
25
|
-
}
|
|
26
|
-
{...attributes}
|
|
27
|
-
>
|
|
28
|
-
{children}
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
});
|