@dbcdk/react-components 0.0.197 → 0.0.199
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/dist/components/json-viewer/JsonViewer.module.css +53 -0
- package/dist/components/json-viewer/JsonViewerShell.cjs +147 -143
- package/dist/components/json-viewer/JsonViewerShell.js +149 -145
- package/dist/components/line-viewer/LineViewer.cjs +15 -21
- package/dist/components/line-viewer/LineViewer.d.ts +1 -1
- package/dist/components/line-viewer/LineViewer.js +16 -22
- package/dist/components/line-viewer/LineViewer.module.css +58 -3
- package/dist/components/page-layout/PageLayout.module.css +1 -1
- package/dist/components/scroll-fade/ScrollFade.cjs +42 -0
- package/dist/components/scroll-fade/ScrollFade.d.ts +18 -0
- package/dist/components/scroll-fade/ScrollFade.js +36 -0
- package/dist/components/scroll-fade/ScrollFade.module.css +71 -0
- package/dist/components/search-box/SearchBox.cjs +39 -35
- package/dist/components/search-box/SearchBox.d.ts +2 -0
- package/dist/components/search-box/SearchBox.js +39 -35
- package/dist/components/table/Table.cjs +52 -23
- package/dist/components/table/Table.d.ts +1 -1
- package/dist/components/table/Table.js +53 -24
- package/dist/components/table/Table.module.css +4 -0
- package/dist/components/table/Table.types.d.ts +27 -0
- package/dist/components/table/TanstackTable.cjs +63 -106
- package/dist/components/table/TanstackTable.d.ts +5 -0
- package/dist/components/table/TanstackTable.js +66 -106
- package/dist/components/table/columnLayout.utils.cjs +146 -0
- package/dist/components/table/columnLayout.utils.d.ts +44 -0
- package/dist/components/table/columnLayout.utils.js +141 -0
- package/dist/components/table/components/TableHeader.cjs +3 -1
- package/dist/components/table/components/TableHeader.d.ts +2 -1
- package/dist/components/table/components/TableHeader.js +3 -1
- package/dist/components/table/components/TableHeaderCell.cjs +29 -19
- package/dist/components/table/components/TableHeaderCell.d.ts +2 -1
- package/dist/components/table/components/TableHeaderCell.js +29 -19
- package/dist/components/table/hooks/useClientPagination.cjs +66 -0
- package/dist/components/table/hooks/useClientPagination.d.ts +32 -0
- package/dist/components/table/hooks/useClientPagination.js +64 -0
- package/dist/components/table/hooks/useDistributedLayout.cjs +44 -0
- package/dist/components/table/hooks/useDistributedLayout.d.ts +16 -0
- package/dist/components/table/hooks/useDistributedLayout.js +42 -0
- package/dist/components/table/hooks/useElementWidth.cjs +40 -0
- package/dist/components/table/hooks/useElementWidth.d.ts +7 -0
- package/dist/components/table/hooks/useElementWidth.js +38 -0
- package/dist/components/table/hooks/useResizeHeaderExtras.cjs +87 -0
- package/dist/components/table/hooks/useResizeHeaderExtras.d.ts +17 -0
- package/dist/components/table/hooks/useResizeHeaderExtras.js +62 -0
- package/dist/components/table/hooks/useUiSorting.cjs +18 -0
- package/dist/components/table/hooks/useUiSorting.d.ts +3 -0
- package/dist/components/table/hooks/useUiSorting.js +16 -0
- package/dist/components/table/table.utils.cjs +24 -2
- package/dist/components/table/table.utils.d.ts +40 -2
- package/dist/components/table/table.utils.js +20 -2
- package/dist/components/table/tanstackTable.utils.cjs +33 -97
- package/dist/components/table/tanstackTable.utils.d.ts +24 -8
- package/dist/components/table/tanstackTable.utils.js +34 -99
- package/dist/components/xml-viewer/XmlViewer.cjs +15 -21
- package/dist/components/xml-viewer/XmlViewer.d.ts +1 -1
- package/dist/components/xml-viewer/XmlViewer.js +16 -22
- package/dist/components/xml-viewer/XmlViewer.module.css +58 -3
- package/dist/hooks/useScrollOverflow.cjs +71 -0
- package/dist/hooks/useScrollOverflow.d.ts +23 -0
- package/dist/hooks/useScrollOverflow.js +69 -0
- package/dist/hooks/useTableSettings.cjs +2 -1
- package/dist/hooks/useTableSettings.d.ts +1 -0
- package/dist/hooks/useTableSettings.js +2 -1
- package/dist/index.css +1 -0
- package/dist/utils/refs.utils.cjs +13 -0
- package/dist/utils/refs.utils.d.ts +7 -0
- package/dist/utils/refs.utils.js +11 -0
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ function TableHeaderCell({
|
|
|
14
14
|
column,
|
|
15
15
|
index,
|
|
16
16
|
reserveInlineEnd = false,
|
|
17
|
+
compactHeaderActionReserve = false,
|
|
17
18
|
sortById,
|
|
18
19
|
sortDirection,
|
|
19
20
|
onSortChange,
|
|
@@ -39,27 +40,36 @@ function TableHeaderCell({
|
|
|
39
40
|
"data-divider": column.divider,
|
|
40
41
|
"data-column-index": index,
|
|
41
42
|
children: [
|
|
42
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: alignClasses.inner, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
43
|
-
"
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: alignClasses.inner, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
"div",
|
|
44
45
|
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
className: table_classes.cx(
|
|
47
|
+
alignClasses.main,
|
|
48
|
+
reserveInlineEnd && (compactHeaderActionReserve ? styles__default.default.thMainWithHeaderActionsReserve : styles__default.default.thMainWithActionsReserve)
|
|
49
|
+
),
|
|
50
|
+
children: column.sortable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
51
|
+
"button",
|
|
52
|
+
{
|
|
53
|
+
type: "button",
|
|
54
|
+
className: alignClasses.button,
|
|
55
|
+
onClick: handleToggleSort,
|
|
56
|
+
onKeyDown: (e) => {
|
|
57
|
+
if (!table_utils.shouldToggleOnKey(e.key)) return;
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
handleToggleSort();
|
|
60
|
+
},
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: alignClasses.label, children: table_utils.getHeaderLabel(column.header) }),
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles__default.default.sortIndicator, "aria-hidden": "true", children: [
|
|
64
|
+
active && sortDirection === "asc" && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: styles__default.default.activeSort }),
|
|
65
|
+
active && sortDirection === "desc" && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDown, { className: styles__default.default.activeSort }),
|
|
66
|
+
!active && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDown, { className: styles__default.default.inActiveSort })
|
|
67
|
+
] })
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: alignClasses.label, children: table_utils.getHeaderLabel(column.header) })
|
|
61
71
|
}
|
|
62
|
-
)
|
|
72
|
+
) }),
|
|
63
73
|
extraContent != null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.thOverlayExtras, children: extraContent }) : null,
|
|
64
74
|
endAction != null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.thEndAction, children: endAction }) : null
|
|
65
75
|
]
|
|
@@ -4,6 +4,7 @@ type Props<T> = {
|
|
|
4
4
|
column: ColumnItem<T>;
|
|
5
5
|
index: number;
|
|
6
6
|
reserveInlineEnd?: boolean;
|
|
7
|
+
compactHeaderActionReserve?: boolean;
|
|
7
8
|
sortById?: string;
|
|
8
9
|
sortDirection?: SortDirection;
|
|
9
10
|
onSortChange?: (column: ColumnItem<T>, direction: SortDirection) => void;
|
|
@@ -11,5 +12,5 @@ type Props<T> = {
|
|
|
11
12
|
/** Rendered at the cell's inline end, in the space kept free by `reserveInlineEnd`. */
|
|
12
13
|
endAction?: ReactNode;
|
|
13
14
|
};
|
|
14
|
-
export declare function TableHeaderCell<T>({ column, index, reserveInlineEnd, sortById, sortDirection, onSortChange, extraContent, endAction, }: Props<T>): ReactNode;
|
|
15
|
+
export declare function TableHeaderCell<T>({ column, index, reserveInlineEnd, compactHeaderActionReserve, sortById, sortDirection, onSortChange, extraContent, endAction, }: Props<T>): ReactNode;
|
|
15
16
|
export {};
|
|
@@ -8,6 +8,7 @@ function TableHeaderCell({
|
|
|
8
8
|
column,
|
|
9
9
|
index,
|
|
10
10
|
reserveInlineEnd = false,
|
|
11
|
+
compactHeaderActionReserve = false,
|
|
11
12
|
sortById,
|
|
12
13
|
sortDirection,
|
|
13
14
|
onSortChange,
|
|
@@ -33,27 +34,36 @@ function TableHeaderCell({
|
|
|
33
34
|
"data-divider": column.divider,
|
|
34
35
|
"data-column-index": index,
|
|
35
36
|
children: [
|
|
36
|
-
/* @__PURE__ */ jsx("div", { className: alignClasses.inner, children: /* @__PURE__ */ jsx(
|
|
37
|
-
"
|
|
37
|
+
/* @__PURE__ */ jsx("div", { className: alignClasses.inner, children: /* @__PURE__ */ jsx(
|
|
38
|
+
"div",
|
|
38
39
|
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
className: cx(
|
|
41
|
+
alignClasses.main,
|
|
42
|
+
reserveInlineEnd && (compactHeaderActionReserve ? styles.thMainWithHeaderActionsReserve : styles.thMainWithActionsReserve)
|
|
43
|
+
),
|
|
44
|
+
children: column.sortable ? /* @__PURE__ */ jsxs(
|
|
45
|
+
"button",
|
|
46
|
+
{
|
|
47
|
+
type: "button",
|
|
48
|
+
className: alignClasses.button,
|
|
49
|
+
onClick: handleToggleSort,
|
|
50
|
+
onKeyDown: (e) => {
|
|
51
|
+
if (!shouldToggleOnKey(e.key)) return;
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
handleToggleSort();
|
|
54
|
+
},
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ jsx("span", { className: alignClasses.label, children: getHeaderLabel(column.header) }),
|
|
57
|
+
/* @__PURE__ */ jsxs("span", { className: styles.sortIndicator, "aria-hidden": "true", children: [
|
|
58
|
+
active && sortDirection === "asc" && /* @__PURE__ */ jsx(ArrowUp, { className: styles.activeSort }),
|
|
59
|
+
active && sortDirection === "desc" && /* @__PURE__ */ jsx(ArrowDown, { className: styles.activeSort }),
|
|
60
|
+
!active && /* @__PURE__ */ jsx(ArrowDown, { className: styles.inActiveSort })
|
|
61
|
+
] })
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
) : /* @__PURE__ */ jsx("span", { className: alignClasses.label, children: getHeaderLabel(column.header) })
|
|
55
65
|
}
|
|
56
|
-
)
|
|
66
|
+
) }),
|
|
57
67
|
extraContent != null ? /* @__PURE__ */ jsx("div", { className: styles.thOverlayExtras, children: extraContent }) : null,
|
|
58
68
|
endAction != null ? /* @__PURE__ */ jsx("div", { className: styles.thEndAction, children: endAction }) : null
|
|
59
69
|
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var reactTable = require('@tanstack/react-table');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_CLIENT_PAGE_SIZE = 20;
|
|
8
|
+
function useClientPagination({
|
|
9
|
+
enabled,
|
|
10
|
+
rowCount,
|
|
11
|
+
take,
|
|
12
|
+
skip,
|
|
13
|
+
totalItemsCount,
|
|
14
|
+
onPageChange
|
|
15
|
+
}) {
|
|
16
|
+
const [uiSkip, setUiSkip] = react.useState(skip != null ? skip : 0);
|
|
17
|
+
const [prevSkip, setPrevSkip] = react.useState(skip);
|
|
18
|
+
const [uiTake, setUiTake] = react.useState(take != null ? take : DEFAULT_CLIENT_PAGE_SIZE);
|
|
19
|
+
const [prevTake, setPrevTake] = react.useState(take);
|
|
20
|
+
if (skip !== prevSkip) {
|
|
21
|
+
setPrevSkip(skip);
|
|
22
|
+
if (skip != null) setUiSkip(skip);
|
|
23
|
+
}
|
|
24
|
+
if (take !== prevTake) {
|
|
25
|
+
setPrevTake(take);
|
|
26
|
+
setUiTake(take != null ? take : DEFAULT_CLIENT_PAGE_SIZE);
|
|
27
|
+
}
|
|
28
|
+
const pageSize = Math.max(1, uiTake);
|
|
29
|
+
const lastPageIndex = Math.max(0, Math.ceil(rowCount / pageSize) - 1);
|
|
30
|
+
const pageIndex = Math.min(Math.floor(uiSkip / pageSize), lastPageIndex);
|
|
31
|
+
const handlePageChange = react.useCallback(
|
|
32
|
+
(e) => {
|
|
33
|
+
if (enabled) {
|
|
34
|
+
setUiSkip(e.skip);
|
|
35
|
+
setUiTake(e.take);
|
|
36
|
+
}
|
|
37
|
+
onPageChange == null ? void 0 : onPageChange(e);
|
|
38
|
+
},
|
|
39
|
+
[enabled, onPageChange]
|
|
40
|
+
);
|
|
41
|
+
const resetPage = react.useCallback(() => {
|
|
42
|
+
if (!enabled || uiSkip === 0) return;
|
|
43
|
+
setUiSkip(0);
|
|
44
|
+
onPageChange == null ? void 0 : onPageChange({
|
|
45
|
+
page: 1,
|
|
46
|
+
take: pageSize,
|
|
47
|
+
skip: 0,
|
|
48
|
+
totalPages: Math.max(1, Math.ceil(rowCount / pageSize))
|
|
49
|
+
});
|
|
50
|
+
}, [enabled, uiSkip, pageSize, rowCount, onPageChange]);
|
|
51
|
+
const paginationState = enabled ? { pageIndex, pageSize } : void 0;
|
|
52
|
+
const tableOptions = enabled ? {
|
|
53
|
+
getPaginationRowModel: reactTable.getPaginationRowModel(),
|
|
54
|
+
// Page changes go through handlePageChange; a new `data` reference must not reset the page.
|
|
55
|
+
autoResetPageIndex: false
|
|
56
|
+
} : {};
|
|
57
|
+
const tableProps = {
|
|
58
|
+
take: enabled ? pageSize : take,
|
|
59
|
+
skip: enabled ? pageIndex * pageSize : skip,
|
|
60
|
+
totalItemsCount: enabled ? rowCount : totalItemsCount,
|
|
61
|
+
onPageChange: enabled || onPageChange ? handlePageChange : void 0
|
|
62
|
+
};
|
|
63
|
+
return { paginationState, tableOptions, tableProps, resetPage };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.useClientPagination = useClientPagination;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type PaginationState } from '@tanstack/react-table';
|
|
2
|
+
import type { PageChangeEvent } from '../../pagination/Pagination';
|
|
3
|
+
type Args = {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
rowCount: number;
|
|
6
|
+
take?: number;
|
|
7
|
+
skip?: number;
|
|
8
|
+
totalItemsCount?: number;
|
|
9
|
+
onPageChange?: (e: PageChangeEvent) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Page state for TanstackTable. When disabled, the pagination props pass
|
|
13
|
+
* through untouched, for data that is already one page from a server.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useClientPagination({ enabled, rowCount, take, skip, totalItemsCount, onPageChange, }: Args): {
|
|
16
|
+
paginationState: PaginationState | undefined;
|
|
17
|
+
tableOptions: {
|
|
18
|
+
getPaginationRowModel: (table: import("@tanstack/table-core").Table<unknown>) => () => import("@tanstack/table-core").RowModel<unknown>;
|
|
19
|
+
autoResetPageIndex: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
getPaginationRowModel?: undefined;
|
|
22
|
+
autoResetPageIndex?: undefined;
|
|
23
|
+
};
|
|
24
|
+
tableProps: {
|
|
25
|
+
take: number | undefined;
|
|
26
|
+
skip: number | undefined;
|
|
27
|
+
totalItemsCount: number | undefined;
|
|
28
|
+
onPageChange: ((e: PageChangeEvent) => void) | undefined;
|
|
29
|
+
};
|
|
30
|
+
resetPage: () => void;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { getPaginationRowModel } from '@tanstack/react-table';
|
|
3
|
+
import { useState, useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_CLIENT_PAGE_SIZE = 20;
|
|
6
|
+
function useClientPagination({
|
|
7
|
+
enabled,
|
|
8
|
+
rowCount,
|
|
9
|
+
take,
|
|
10
|
+
skip,
|
|
11
|
+
totalItemsCount,
|
|
12
|
+
onPageChange
|
|
13
|
+
}) {
|
|
14
|
+
const [uiSkip, setUiSkip] = useState(skip != null ? skip : 0);
|
|
15
|
+
const [prevSkip, setPrevSkip] = useState(skip);
|
|
16
|
+
const [uiTake, setUiTake] = useState(take != null ? take : DEFAULT_CLIENT_PAGE_SIZE);
|
|
17
|
+
const [prevTake, setPrevTake] = useState(take);
|
|
18
|
+
if (skip !== prevSkip) {
|
|
19
|
+
setPrevSkip(skip);
|
|
20
|
+
if (skip != null) setUiSkip(skip);
|
|
21
|
+
}
|
|
22
|
+
if (take !== prevTake) {
|
|
23
|
+
setPrevTake(take);
|
|
24
|
+
setUiTake(take != null ? take : DEFAULT_CLIENT_PAGE_SIZE);
|
|
25
|
+
}
|
|
26
|
+
const pageSize = Math.max(1, uiTake);
|
|
27
|
+
const lastPageIndex = Math.max(0, Math.ceil(rowCount / pageSize) - 1);
|
|
28
|
+
const pageIndex = Math.min(Math.floor(uiSkip / pageSize), lastPageIndex);
|
|
29
|
+
const handlePageChange = useCallback(
|
|
30
|
+
(e) => {
|
|
31
|
+
if (enabled) {
|
|
32
|
+
setUiSkip(e.skip);
|
|
33
|
+
setUiTake(e.take);
|
|
34
|
+
}
|
|
35
|
+
onPageChange == null ? void 0 : onPageChange(e);
|
|
36
|
+
},
|
|
37
|
+
[enabled, onPageChange]
|
|
38
|
+
);
|
|
39
|
+
const resetPage = useCallback(() => {
|
|
40
|
+
if (!enabled || uiSkip === 0) return;
|
|
41
|
+
setUiSkip(0);
|
|
42
|
+
onPageChange == null ? void 0 : onPageChange({
|
|
43
|
+
page: 1,
|
|
44
|
+
take: pageSize,
|
|
45
|
+
skip: 0,
|
|
46
|
+
totalPages: Math.max(1, Math.ceil(rowCount / pageSize))
|
|
47
|
+
});
|
|
48
|
+
}, [enabled, uiSkip, pageSize, rowCount, onPageChange]);
|
|
49
|
+
const paginationState = enabled ? { pageIndex, pageSize } : void 0;
|
|
50
|
+
const tableOptions = enabled ? {
|
|
51
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
52
|
+
// Page changes go through handlePageChange; a new `data` reference must not reset the page.
|
|
53
|
+
autoResetPageIndex: false
|
|
54
|
+
} : {};
|
|
55
|
+
const tableProps = {
|
|
56
|
+
take: enabled ? pageSize : take,
|
|
57
|
+
skip: enabled ? pageIndex * pageSize : skip,
|
|
58
|
+
totalItemsCount: enabled ? rowCount : totalItemsCount,
|
|
59
|
+
onPageChange: enabled || onPageChange ? handlePageChange : void 0
|
|
60
|
+
};
|
|
61
|
+
return { paginationState, tableOptions, tableProps, resetPage };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { useClientPagination };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var tanstackTable_utils = require('../tanstackTable.utils');
|
|
6
|
+
|
|
7
|
+
function useDistributedLayout({
|
|
8
|
+
table,
|
|
9
|
+
columns,
|
|
10
|
+
columnVisibility,
|
|
11
|
+
columnSizing,
|
|
12
|
+
availableWidth,
|
|
13
|
+
hasSelection,
|
|
14
|
+
actionReservePx
|
|
15
|
+
}) {
|
|
16
|
+
const distributedLayout = react.useMemo(() => {
|
|
17
|
+
if (availableWidth == null) return null;
|
|
18
|
+
return tanstackTable_utils.buildDistributedColumnWidths({
|
|
19
|
+
table,
|
|
20
|
+
hasSelection,
|
|
21
|
+
hasContextMenu: actionReservePx > 0,
|
|
22
|
+
contextMenuReservePx: actionReservePx,
|
|
23
|
+
defaultMinPx: 80,
|
|
24
|
+
columnSizing,
|
|
25
|
+
availableWidth
|
|
26
|
+
});
|
|
27
|
+
}, [table, hasSelection, actionReservePx, columnSizing, availableWidth]);
|
|
28
|
+
const resolvedLayout = react.useMemo(() => {
|
|
29
|
+
const next = {};
|
|
30
|
+
table.getVisibleLeafColumns().forEach((column) => {
|
|
31
|
+
next[column.id] = {
|
|
32
|
+
width: distributedLayout == null ? void 0 : distributedLayout.widths[column.id]
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
return next;
|
|
36
|
+
}, [table, distributedLayout]);
|
|
37
|
+
const columnItems = react.useMemo(
|
|
38
|
+
() => tanstackTable_utils.mapDefsToColumnItems(columns, columnVisibility, resolvedLayout),
|
|
39
|
+
[columns, columnVisibility, resolvedLayout]
|
|
40
|
+
);
|
|
41
|
+
return { distributedLayout, columnItems };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.useDistributedLayout = useDistributedLayout;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ColumnDef, ColumnSizingState, Table, VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
type Args<T> = {
|
|
3
|
+
table: Table<T>;
|
|
4
|
+
columns: ReadonlyArray<ColumnDef<T, any>>;
|
|
5
|
+
columnVisibility: VisibilityState;
|
|
6
|
+
columnSizing: ColumnSizingState;
|
|
7
|
+
availableWidth: number | undefined;
|
|
8
|
+
hasSelection: boolean;
|
|
9
|
+
actionReservePx: number;
|
|
10
|
+
};
|
|
11
|
+
/** Column widths that fill the measured container, mapped to Table column items. */
|
|
12
|
+
export declare function useDistributedLayout<T extends Record<string, any>>({ table, columns, columnVisibility, columnSizing, availableWidth, hasSelection, actionReservePx, }: Args<T>): {
|
|
13
|
+
distributedLayout: import("../columnLayout.utils").DistributedColumnWidths | null;
|
|
14
|
+
columnItems: import("../Table.types").ColumnItem<T>[];
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { buildDistributedColumnWidths, mapDefsToColumnItems } from '../tanstackTable.utils';
|
|
4
|
+
|
|
5
|
+
function useDistributedLayout({
|
|
6
|
+
table,
|
|
7
|
+
columns,
|
|
8
|
+
columnVisibility,
|
|
9
|
+
columnSizing,
|
|
10
|
+
availableWidth,
|
|
11
|
+
hasSelection,
|
|
12
|
+
actionReservePx
|
|
13
|
+
}) {
|
|
14
|
+
const distributedLayout = useMemo(() => {
|
|
15
|
+
if (availableWidth == null) return null;
|
|
16
|
+
return buildDistributedColumnWidths({
|
|
17
|
+
table,
|
|
18
|
+
hasSelection,
|
|
19
|
+
hasContextMenu: actionReservePx > 0,
|
|
20
|
+
contextMenuReservePx: actionReservePx,
|
|
21
|
+
defaultMinPx: 80,
|
|
22
|
+
columnSizing,
|
|
23
|
+
availableWidth
|
|
24
|
+
});
|
|
25
|
+
}, [table, hasSelection, actionReservePx, columnSizing, availableWidth]);
|
|
26
|
+
const resolvedLayout = useMemo(() => {
|
|
27
|
+
const next = {};
|
|
28
|
+
table.getVisibleLeafColumns().forEach((column) => {
|
|
29
|
+
next[column.id] = {
|
|
30
|
+
width: distributedLayout == null ? void 0 : distributedLayout.widths[column.id]
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return next;
|
|
34
|
+
}, [table, distributedLayout]);
|
|
35
|
+
const columnItems = useMemo(
|
|
36
|
+
() => mapDefsToColumnItems(columns, columnVisibility, resolvedLayout),
|
|
37
|
+
[columns, columnVisibility, resolvedLayout]
|
|
38
|
+
);
|
|
39
|
+
return { distributedLayout, columnItems };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useDistributedLayout };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
function measureContentWidth(el) {
|
|
7
|
+
const style = getComputedStyle(el);
|
|
8
|
+
const width = parseFloat(style.width);
|
|
9
|
+
if (!Number.isFinite(width)) return el.clientWidth;
|
|
10
|
+
const px = (value) => parseFloat(value) || 0;
|
|
11
|
+
const borders = px(style.borderLeftWidth) + px(style.borderRightWidth);
|
|
12
|
+
const padding = px(style.paddingLeft) + px(style.paddingRight);
|
|
13
|
+
const scrollbar = Math.max(0, el.offsetWidth - el.clientWidth - borders);
|
|
14
|
+
const borderBox = style.boxSizing === "border-box" ? width : width + padding + borders;
|
|
15
|
+
const widthExcludesScrollbar = el.offsetWidth - borderBox > scrollbar / 2;
|
|
16
|
+
const contentWidth = (style.boxSizing === "border-box" ? width - borders - padding : width) - (widthExcludesScrollbar ? 0 : scrollbar);
|
|
17
|
+
return Math.floor(contentWidth);
|
|
18
|
+
}
|
|
19
|
+
function useElementWidth(ref, enabled = true) {
|
|
20
|
+
const [width, setWidth] = react.useState(void 0);
|
|
21
|
+
react.useLayoutEffect(() => {
|
|
22
|
+
const el = ref.current;
|
|
23
|
+
if (!enabled || !el) return;
|
|
24
|
+
const updateWidth = () => {
|
|
25
|
+
const next = measureContentWidth(el);
|
|
26
|
+
setWidth(next > 0 ? next : void 0);
|
|
27
|
+
};
|
|
28
|
+
updateWidth();
|
|
29
|
+
if (typeof ResizeObserver === "undefined") {
|
|
30
|
+
window.addEventListener("resize", updateWidth);
|
|
31
|
+
return () => window.removeEventListener("resize", updateWidth);
|
|
32
|
+
}
|
|
33
|
+
const observer = new ResizeObserver(updateWidth);
|
|
34
|
+
observer.observe(el);
|
|
35
|
+
return () => observer.disconnect();
|
|
36
|
+
}, [ref, enabled]);
|
|
37
|
+
return enabled ? width : void 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.useElementWidth = useElementWidth;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks the content width of `ref`'s element. Stays `undefined` until the
|
|
4
|
+
* first client measurement (and while `enabled` is false), so callers can hide
|
|
5
|
+
* layout that depends on it instead of rendering a wrong first frame.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useElementWidth(ref: RefObject<HTMLElement | null>, enabled?: boolean): number | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState, useLayoutEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function measureContentWidth(el) {
|
|
5
|
+
const style = getComputedStyle(el);
|
|
6
|
+
const width = parseFloat(style.width);
|
|
7
|
+
if (!Number.isFinite(width)) return el.clientWidth;
|
|
8
|
+
const px = (value) => parseFloat(value) || 0;
|
|
9
|
+
const borders = px(style.borderLeftWidth) + px(style.borderRightWidth);
|
|
10
|
+
const padding = px(style.paddingLeft) + px(style.paddingRight);
|
|
11
|
+
const scrollbar = Math.max(0, el.offsetWidth - el.clientWidth - borders);
|
|
12
|
+
const borderBox = style.boxSizing === "border-box" ? width : width + padding + borders;
|
|
13
|
+
const widthExcludesScrollbar = el.offsetWidth - borderBox > scrollbar / 2;
|
|
14
|
+
const contentWidth = (style.boxSizing === "border-box" ? width - borders - padding : width) - (widthExcludesScrollbar ? 0 : scrollbar);
|
|
15
|
+
return Math.floor(contentWidth);
|
|
16
|
+
}
|
|
17
|
+
function useElementWidth(ref, enabled = true) {
|
|
18
|
+
const [width, setWidth] = useState(void 0);
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
const el = ref.current;
|
|
21
|
+
if (!enabled || !el) return;
|
|
22
|
+
const updateWidth = () => {
|
|
23
|
+
const next = measureContentWidth(el);
|
|
24
|
+
setWidth(next > 0 ? next : void 0);
|
|
25
|
+
};
|
|
26
|
+
updateWidth();
|
|
27
|
+
if (typeof ResizeObserver === "undefined") {
|
|
28
|
+
window.addEventListener("resize", updateWidth);
|
|
29
|
+
return () => window.removeEventListener("resize", updateWidth);
|
|
30
|
+
}
|
|
31
|
+
const observer = new ResizeObserver(updateWidth);
|
|
32
|
+
observer.observe(el);
|
|
33
|
+
return () => observer.disconnect();
|
|
34
|
+
}, [ref, enabled]);
|
|
35
|
+
return enabled ? width : void 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { useElementWidth };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var ColumnResizer = require('../components/column-resizer/ColumnResizer');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
var ColumnResizer__default = /*#__PURE__*/_interopDefault(ColumnResizer);
|
|
30
|
+
|
|
31
|
+
function useResizeHeaderExtras({
|
|
32
|
+
table,
|
|
33
|
+
widths,
|
|
34
|
+
actionReservePx,
|
|
35
|
+
neighborResizeRef,
|
|
36
|
+
setColumnSizing
|
|
37
|
+
}) {
|
|
38
|
+
return React__namespace.useCallback(
|
|
39
|
+
({ index }) => {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
const headerGroups = table.getHeaderGroups();
|
|
42
|
+
const leafHeaders = headerGroups.length > 0 ? headerGroups[headerGroups.length - 1].headers : [];
|
|
43
|
+
const header = leafHeaders[index];
|
|
44
|
+
const neighbor = leafHeaders[index + 1];
|
|
45
|
+
if (!header || !neighbor) return null;
|
|
46
|
+
const canResize = (_c = (_b = (_a = header.column).getCanResize) == null ? void 0 : _b.call(_a)) != null ? _c : false;
|
|
47
|
+
const handler = (_d = header.getResizeHandler) == null ? void 0 : _d.call(header);
|
|
48
|
+
if (!canResize || !handler) return null;
|
|
49
|
+
const handleResizeStart = (event) => {
|
|
50
|
+
var _a2, _b2, _c2, _d2;
|
|
51
|
+
const startWidth = widths == null ? void 0 : widths[header.column.id];
|
|
52
|
+
const neighborStartWidth = widths == null ? void 0 : widths[neighbor.column.id];
|
|
53
|
+
if (startWidth == null || neighborStartWidth == null) return;
|
|
54
|
+
const neighborReserve = index + 1 === leafHeaders.length - 1 ? actionReservePx : 0;
|
|
55
|
+
const { columnDef } = header.column;
|
|
56
|
+
const neighborDef = neighbor.column.columnDef;
|
|
57
|
+
neighborResizeRef.current = {
|
|
58
|
+
columnId: header.column.id,
|
|
59
|
+
neighborId: neighbor.column.id,
|
|
60
|
+
// TanStack drags from its own size (columnDef.size), not the width on
|
|
61
|
+
// screen; applyNeighborResize only uses its offset from this.
|
|
62
|
+
tanstackStartWidth: header.getSize(),
|
|
63
|
+
startWidth,
|
|
64
|
+
neighborStartWidth,
|
|
65
|
+
min: (_a2 = columnDef.minSize) != null ? _a2 : 0,
|
|
66
|
+
max: (_b2 = columnDef.maxSize) != null ? _b2 : Infinity,
|
|
67
|
+
neighborMin: ((_c2 = neighborDef.minSize) != null ? _c2 : 0) + neighborReserve,
|
|
68
|
+
neighborMax: ((_d2 = neighborDef.maxSize) != null ? _d2 : Infinity) + neighborReserve
|
|
69
|
+
};
|
|
70
|
+
const displayedWidths = widths != null ? widths : {};
|
|
71
|
+
setColumnSizing(
|
|
72
|
+
(prev) => Object.fromEntries(
|
|
73
|
+
Object.entries(prev).map(([id, width]) => {
|
|
74
|
+
var _a3;
|
|
75
|
+
return [id, (_a3 = displayedWidths[id]) != null ? _a3 : width];
|
|
76
|
+
})
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
handler(event);
|
|
80
|
+
};
|
|
81
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ColumnResizer__default.default, { id: header.column.id, handler: handleResizeStart });
|
|
82
|
+
},
|
|
83
|
+
[table, widths, actionReservePx, neighborResizeRef, setColumnSizing]
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.useResizeHeaderExtras = useResizeHeaderExtras;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ColumnSizingState, Table } from '@tanstack/react-table';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { DistributedColumnWidths } from '../columnLayout.utils';
|
|
4
|
+
import type { NeighborResize } from '../tanstackTable.utils';
|
|
5
|
+
type Args<T> = {
|
|
6
|
+
table: Table<T>;
|
|
7
|
+
widths: DistributedColumnWidths['widths'] | undefined;
|
|
8
|
+
actionReservePx: number;
|
|
9
|
+
neighborResizeRef: React.MutableRefObject<NeighborResize | null>;
|
|
10
|
+
setColumnSizing: React.Dispatch<React.SetStateAction<ColumnSizingState>>;
|
|
11
|
+
};
|
|
12
|
+
/** Renders a resize handle between each column and its right neighbour. */
|
|
13
|
+
export declare function useResizeHeaderExtras<T>({ table, widths, actionReservePx, neighborResizeRef, setColumnSizing, }: Args<T>): ({ index }: {
|
|
14
|
+
column: any;
|
|
15
|
+
index: number;
|
|
16
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
17
|
+
export {};
|