@trackunit/react-table 1.7.20 → 1.7.22
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/index.cjs.js +9 -10
- package/index.esm.js +9 -10
- package/package.json +10 -11
- package/src/Table.d.ts +1 -2
package/index.cjs.js
CHANGED
|
@@ -13,7 +13,6 @@ var reactDnd = require('react-dnd');
|
|
|
13
13
|
var reactDndHtml5Backend = require('react-dnd-html5-backend');
|
|
14
14
|
var reactTable = require('@tanstack/react-table');
|
|
15
15
|
var reactTableBaseComponents = require('@trackunit/react-table-base-components');
|
|
16
|
-
var reactTablePagination = require('@trackunit/react-table-pagination');
|
|
17
16
|
var tailwindMerge = require('tailwind-merge');
|
|
18
17
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
19
18
|
|
|
@@ -868,11 +867,11 @@ const ColumnSorting = ({ canSort, sortingState = false }) => {
|
|
|
868
867
|
*/
|
|
869
868
|
const Table = ({ rowHeight = 50, ...props }) => {
|
|
870
869
|
//we need a reference to the scrolling element for logic down below
|
|
871
|
-
const
|
|
870
|
+
const tableScrollElementRef = react.useRef(null);
|
|
872
871
|
const [t] = useTranslation();
|
|
873
|
-
const
|
|
874
|
-
pagination: props.pagination ||
|
|
875
|
-
|
|
872
|
+
const virtualizer = reactComponents.useInfiniteScroll({
|
|
873
|
+
pagination: props.pagination || reactComponents.noPagination,
|
|
874
|
+
scrollElementRef: tableScrollElementRef,
|
|
876
875
|
count: props.getRowModel().rows.length,
|
|
877
876
|
estimateSize: () => rowHeight, // TODO: we should probably move from rowHeight -> estimateSize callback api to match Tanstack Virtual
|
|
878
877
|
});
|
|
@@ -888,8 +887,8 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
888
887
|
const [containWholeTable, setContainWholeTable] = react.useState(false);
|
|
889
888
|
react.useEffect(() => {
|
|
890
889
|
const updateContainWholeTable = () => {
|
|
891
|
-
if (
|
|
892
|
-
const containerWidth =
|
|
890
|
+
if (tableScrollElementRef.current) {
|
|
891
|
+
const containerWidth = tableScrollElementRef.current.offsetWidth;
|
|
893
892
|
setContainWholeTable(totalVisibleColumnsWidth > containerWidth);
|
|
894
893
|
}
|
|
895
894
|
};
|
|
@@ -941,7 +940,7 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
941
940
|
header.column.getToggleSortingHandler()?.(event);
|
|
942
941
|
}
|
|
943
942
|
}, [props]);
|
|
944
|
-
return (jsxRuntime.jsxs(reactComponents.Card, { className: tailwindMerge.twMerge("table-compact flex flex-col overflow-hidden", props.className), dataTestId: props.dataTestId, children: [props.headerLeftActions || props.headerRightActions ? (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: props.headerRightActions })] })) : null, jsxRuntime.jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-neutral-200", ref:
|
|
943
|
+
return (jsxRuntime.jsxs(reactComponents.Card, { className: tailwindMerge.twMerge("table-compact flex flex-col overflow-hidden", props.className), dataTestId: props.dataTestId, children: [props.headerLeftActions || props.headerRightActions ? (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: props.headerRightActions })] })) : null, jsxRuntime.jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-neutral-200", ref: tableScrollElementRef, children: jsxRuntime.jsxs(reactTableBaseComponents.TableRoot, { style: {
|
|
945
944
|
height: hasResults ? "auto" : "100%",
|
|
946
945
|
width: "100%",
|
|
947
946
|
position: "relative",
|
|
@@ -975,9 +974,9 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
975
974
|
!header.column.columnDef.meta?.shouldGrow && header.column.getCanResize() ? (jsxRuntime.jsx(reactTableBaseComponents.ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null));
|
|
976
975
|
}) }, headerGroup.id));
|
|
977
976
|
}) }), hasResults ? (jsxRuntime.jsx(reactTableBaseComponents.Tbody, { className: "text-sm font-normal", style: {
|
|
978
|
-
height: `${getTotalSize()}px`,
|
|
977
|
+
height: `${virtualizer.getTotalSize()}px`,
|
|
979
978
|
flexGrow: 1,
|
|
980
|
-
}, children: getVirtualItems().map((virtualRow, index) => {
|
|
979
|
+
}, children: virtualizer.getVirtualItems().map((virtualRow, index) => {
|
|
981
980
|
const row = props.getRowModel().rows[virtualRow.index];
|
|
982
981
|
if (!row) {
|
|
983
982
|
return null;
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { MenuItem, Icon, Button, Tooltip, useOverflowItems, MoreMenu, MenuList, Spacer, cvaInteractableItem, Text, Popover, PopoverTrigger, IconButton, PopoverContent, Card, Spinner, EmptyState } from '@trackunit/react-components';
|
|
3
|
+
import { MenuItem, Icon, Button, Tooltip, useOverflowItems, MoreMenu, MenuList, Spacer, cvaInteractableItem, Text, Popover, PopoverTrigger, IconButton, PopoverContent, useInfiniteScroll, noPagination, Card, Spinner, EmptyState } from '@trackunit/react-components';
|
|
4
4
|
import { objectValues, nonNullable, objectKeys, objectEntries } from '@trackunit/shared-utils';
|
|
5
5
|
import { useMemo, Children, cloneElement, useRef, useState, useEffect, useCallback, createElement } from 'react';
|
|
6
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
@@ -12,7 +12,6 @@ import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
|
12
12
|
import { flexRender, createColumnHelper, useReactTable, getSortedRowModel, getCoreRowModel } from '@tanstack/react-table';
|
|
13
13
|
export { createColumnHelper } from '@tanstack/react-table';
|
|
14
14
|
import { TableRoot, Thead, Tr, Th, ResizeHandle, Tbody, Td } from '@trackunit/react-table-base-components';
|
|
15
|
-
import { useInfiniteScroll, noPagination } from '@trackunit/react-table-pagination';
|
|
16
15
|
import { twMerge } from 'tailwind-merge';
|
|
17
16
|
import { SortOrder, validateStringAsAssetSortByProperty } from '@trackunit/react-core-contexts-api';
|
|
18
17
|
|
|
@@ -867,11 +866,11 @@ const ColumnSorting = ({ canSort, sortingState = false }) => {
|
|
|
867
866
|
*/
|
|
868
867
|
const Table = ({ rowHeight = 50, ...props }) => {
|
|
869
868
|
//we need a reference to the scrolling element for logic down below
|
|
870
|
-
const
|
|
869
|
+
const tableScrollElementRef = useRef(null);
|
|
871
870
|
const [t] = useTranslation();
|
|
872
|
-
const
|
|
871
|
+
const virtualizer = useInfiniteScroll({
|
|
873
872
|
pagination: props.pagination || noPagination,
|
|
874
|
-
|
|
873
|
+
scrollElementRef: tableScrollElementRef,
|
|
875
874
|
count: props.getRowModel().rows.length,
|
|
876
875
|
estimateSize: () => rowHeight, // TODO: we should probably move from rowHeight -> estimateSize callback api to match Tanstack Virtual
|
|
877
876
|
});
|
|
@@ -887,8 +886,8 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
887
886
|
const [containWholeTable, setContainWholeTable] = useState(false);
|
|
888
887
|
useEffect(() => {
|
|
889
888
|
const updateContainWholeTable = () => {
|
|
890
|
-
if (
|
|
891
|
-
const containerWidth =
|
|
889
|
+
if (tableScrollElementRef.current) {
|
|
890
|
+
const containerWidth = tableScrollElementRef.current.offsetWidth;
|
|
892
891
|
setContainWholeTable(totalVisibleColumnsWidth > containerWidth);
|
|
893
892
|
}
|
|
894
893
|
};
|
|
@@ -940,7 +939,7 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
940
939
|
header.column.getToggleSortingHandler()?.(event);
|
|
941
940
|
}
|
|
942
941
|
}, [props]);
|
|
943
|
-
return (jsxs(Card, { className: twMerge("table-compact flex flex-col overflow-hidden", props.className), dataTestId: props.dataTestId, children: [props.headerLeftActions || props.headerRightActions ? (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex items-center gap-2", children: props.headerLeftActions }), jsx("div", { className: "flex items-center gap-2", children: props.headerRightActions })] })) : null, jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-neutral-200", ref:
|
|
942
|
+
return (jsxs(Card, { className: twMerge("table-compact flex flex-col overflow-hidden", props.className), dataTestId: props.dataTestId, children: [props.headerLeftActions || props.headerRightActions ? (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex items-center gap-2", children: props.headerLeftActions }), jsx("div", { className: "flex items-center gap-2", children: props.headerRightActions })] })) : null, jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-neutral-200", ref: tableScrollElementRef, children: jsxs(TableRoot, { style: {
|
|
944
943
|
height: hasResults ? "auto" : "100%",
|
|
945
944
|
width: "100%",
|
|
946
945
|
position: "relative",
|
|
@@ -974,9 +973,9 @@ const Table = ({ rowHeight = 50, ...props }) => {
|
|
|
974
973
|
!header.column.columnDef.meta?.shouldGrow && header.column.getCanResize() ? (jsx(ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null));
|
|
975
974
|
}) }, headerGroup.id));
|
|
976
975
|
}) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", style: {
|
|
977
|
-
height: `${getTotalSize()}px`,
|
|
976
|
+
height: `${virtualizer.getTotalSize()}px`,
|
|
978
977
|
flexGrow: 1,
|
|
979
|
-
}, children: getVirtualItems().map((virtualRow, index) => {
|
|
978
|
+
}, children: virtualizer.getVirtualItems().map((virtualRow, index) => {
|
|
980
979
|
const row = props.getRowModel().rows[virtualRow.index];
|
|
981
980
|
if (!row) {
|
|
982
981
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.22",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -15,16 +15,15 @@
|
|
|
15
15
|
"jest-fetch-mock": "^3.0.3",
|
|
16
16
|
"@tanstack/react-router": "1.114.29",
|
|
17
17
|
"tailwind-merge": "^2.0.0",
|
|
18
|
-
"@trackunit/react-components": "1.9.
|
|
19
|
-
"@trackunit/shared-utils": "1.9.
|
|
20
|
-
"@trackunit/css-class-variance-utilities": "1.7.
|
|
21
|
-
"@trackunit/ui-icons": "1.7.
|
|
22
|
-
"@trackunit/react-table-base-components": "1.7.
|
|
23
|
-
"@trackunit/react-
|
|
24
|
-
"@trackunit/
|
|
25
|
-
"@trackunit/
|
|
26
|
-
"@trackunit/react-
|
|
27
|
-
"@trackunit/react-test-setup": "1.4.11"
|
|
18
|
+
"@trackunit/react-components": "1.9.21",
|
|
19
|
+
"@trackunit/shared-utils": "1.9.12",
|
|
20
|
+
"@trackunit/css-class-variance-utilities": "1.7.12",
|
|
21
|
+
"@trackunit/ui-icons": "1.7.14",
|
|
22
|
+
"@trackunit/react-table-base-components": "1.7.21",
|
|
23
|
+
"@trackunit/react-form-components": "1.8.21",
|
|
24
|
+
"@trackunit/i18n-library-translation": "1.7.16",
|
|
25
|
+
"@trackunit/react-core-contexts-api": "1.8.14",
|
|
26
|
+
"@trackunit/react-test-setup": "1.4.12"
|
|
28
27
|
},
|
|
29
28
|
"module": "./index.esm.js",
|
|
30
29
|
"main": "./index.cjs.js",
|
package/src/Table.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Table as ReactTable, Row } from "@tanstack/react-table";
|
|
2
|
-
import { CommonProps, EmptyStateProps } from "@trackunit/react-components";
|
|
3
|
-
import { RelayPagination } from "@trackunit/react-table-pagination";
|
|
2
|
+
import { CommonProps, EmptyStateProps, RelayPagination } from "@trackunit/react-components";
|
|
4
3
|
import { ReactElement, ReactNode } from "react";
|
|
5
4
|
import "./table-animations.css";
|
|
6
5
|
export interface TableProps<TData extends object> extends ReactTable<TData>, CommonProps {
|