@trackunit/react-table 0.0.457 → 0.0.459
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 +51 -73
- package/index.esm.js +46 -62
- package/package.json +5 -4
- package/src/ActionSheet/ActionContainerAndOverflow.d.ts +1 -1
- package/src/ActionSheet/ActionSheet.d.ts +1 -2
- package/src/ActionSheet/ActionSheetElementUtils.d.ts +3 -3
- package/src/ActionSheet/Actions.d.ts +0 -1
- package/src/Table.d.ts +1 -2
- package/src/menus/ColumnFilter.d.ts +1 -2
- package/src/menus/RowSpacing.d.ts +1 -2
- package/src/menus/Sorting.d.ts +0 -1
- package/src/translation.d.ts +1 -2
- package/src/useTableSelection.demo.d.ts +1 -2
- package/translation.cjs.js +1 -1
- package/translation.cjs10.js +1 -1
- package/translation.cjs11.js +1 -1
- package/translation.cjs12.js +1 -1
- package/translation.cjs13.js +1 -1
- package/translation.cjs14.js +1 -1
- package/translation.cjs15.js +1 -1
- package/translation.cjs16.js +1 -1
- package/translation.cjs17.js +1 -1
- package/translation.cjs2.js +1 -1
- package/translation.cjs3.js +1 -1
- package/translation.cjs4.js +1 -1
- package/translation.cjs5.js +1 -1
- package/translation.cjs6.js +1 -1
- package/translation.cjs7.js +1 -1
- package/translation.cjs8.js +1 -1
- package/translation.cjs9.js +1 -1
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
5
|
var reactComponents = require('@trackunit/react-components');
|
|
@@ -19,10 +17,7 @@ var reactDnd = require('react-dnd');
|
|
|
19
17
|
var reactDndHtml5Backend = require('react-dnd-html5-backend');
|
|
20
18
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
21
19
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function _interopNamespace(e) {
|
|
25
|
-
if (e && e.__esModule) return e;
|
|
20
|
+
function _interopNamespaceDefault(e) {
|
|
26
21
|
var n = Object.create(null);
|
|
27
22
|
if (e) {
|
|
28
23
|
Object.keys(e).forEach(function (k) {
|
|
@@ -35,12 +30,11 @@ function _interopNamespace(e) {
|
|
|
35
30
|
}
|
|
36
31
|
});
|
|
37
32
|
}
|
|
38
|
-
n
|
|
33
|
+
n.default = e;
|
|
39
34
|
return Object.freeze(n);
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
var React__namespace = /*#__PURE__*/
|
|
43
|
-
var update__default = /*#__PURE__*/_interopDefaultLegacy(update);
|
|
37
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
44
38
|
|
|
45
39
|
var defaultTranslations = {
|
|
46
40
|
"layout.actions.reset": "Reset",
|
|
@@ -149,38 +143,6 @@ const cvaActionContainerAndOverflow = cssClassVarianceUtilities.cvaMerge([
|
|
|
149
143
|
"sm:flex-row",
|
|
150
144
|
]);
|
|
151
145
|
|
|
152
|
-
/******************************************************************************
|
|
153
|
-
Copyright (c) Microsoft Corporation.
|
|
154
|
-
|
|
155
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
156
|
-
purpose with or without fee is hereby granted.
|
|
157
|
-
|
|
158
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
159
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
160
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
161
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
162
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
163
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
164
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
165
|
-
***************************************************************************** */
|
|
166
|
-
|
|
167
|
-
function __rest(s, e) {
|
|
168
|
-
var t = {};
|
|
169
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
170
|
-
t[p] = s[p];
|
|
171
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
172
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
173
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
174
|
-
t[p[i]] = s[p[i]];
|
|
175
|
-
}
|
|
176
|
-
return t;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
180
|
-
var e = new Error(message);
|
|
181
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
146
|
/**
|
|
185
147
|
* The button to show in the ActionSheet.
|
|
186
148
|
* Should not be used outside the ActionSheet component.
|
|
@@ -192,12 +154,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
192
154
|
* @param {...any} [props.rest] - Any additional button properties.
|
|
193
155
|
* @returns {JSX.Element} - The action button component.
|
|
194
156
|
*/
|
|
195
|
-
const ActionButton = (
|
|
196
|
-
var { action, children, id } = _a, rest = __rest(_a, ["action", "children", "id"]);
|
|
157
|
+
const ActionButton = ({ action, children, id, ...rest }) => {
|
|
197
158
|
if (action.type === "route") {
|
|
198
|
-
return (jsxRuntime.jsx(reactComponents.Button,
|
|
159
|
+
return (jsxRuntime.jsx(reactComponents.Button, { asChild: true, id: id, variant: "ghost-neutral", ...rest, children: jsxRuntime.jsx(reactRouter.Link, { to: action.url, children: children }) }));
|
|
199
160
|
}
|
|
200
|
-
return (jsxRuntime.jsx(reactComponents.Button,
|
|
161
|
+
return (jsxRuntime.jsx(reactComponents.Button, { id: id, onClick: action.method, variant: "ghost-neutral", ...rest, children: children }));
|
|
201
162
|
};
|
|
202
163
|
/**
|
|
203
164
|
* Converts an action model to a MenuItem component.
|
|
@@ -290,9 +251,8 @@ const ActionSheet = ({ actions, moreActions = [], selections, resetSelection, cl
|
|
|
290
251
|
* @returns {JSX.Element} Table component
|
|
291
252
|
*/
|
|
292
253
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
293
|
-
const Table = (
|
|
294
|
-
var _b, _c
|
|
295
|
-
var { rowHeight = 75 } = _a, props = __rest(_a, ["rowHeight"]);
|
|
254
|
+
const Table = ({ rowHeight = 75, ...props }) => {
|
|
255
|
+
var _a, _b, _c;
|
|
296
256
|
//we need a reference to the scrolling element for logic down below
|
|
297
257
|
const tableContainerRef = React.useRef(null);
|
|
298
258
|
const [t] = useTranslation();
|
|
@@ -341,20 +301,19 @@ const Table = (_a) => {
|
|
|
341
301
|
transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
|
|
342
302
|
}, children: row.getVisibleCells().map(cell => {
|
|
343
303
|
var _a, _b;
|
|
344
|
-
return (jsxRuntime.jsx(reactTableBaseComponents.Td, {
|
|
345
|
-
style: {
|
|
304
|
+
return (jsxRuntime.jsx(reactTableBaseComponents.Td, { style: {
|
|
346
305
|
width: cell.column.getSize(),
|
|
347
306
|
minWidth: cell.column.columnDef.minSize,
|
|
348
307
|
maxWidth: cell.column.columnDef.maxSize,
|
|
349
308
|
textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
|
|
350
309
|
flexGrow: ((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.shouldGrow) ? 1 : 0,
|
|
351
|
-
}, children: jsxRuntime.jsx("div", { className: "grid h-full items-center", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
|
|
310
|
+
}, children: jsxRuntime.jsx("div", { className: "grid h-full items-center", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }) }, cell.id));
|
|
352
311
|
}) }, row.id));
|
|
353
312
|
}
|
|
354
313
|
}) })) : (jsxRuntime.jsx("tbody", { className: "min-h-[400px]", children: jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { className: "b-0", children: props.loading ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : props.noDataMessage ? (props.noDataMessage) : (jsxRuntime.jsx(reactComponents.EmptyState, { className: "absolute inset-0", description: t("table.noResults"), image: "SEARCH_DOCUMENT" })) }) }) }))] }) }), props.hideFooter ? null : (jsxRuntime.jsxs("div", { className: "flex items-center p-2", children: [jsxRuntime.jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
|
|
355
314
|
count: props.getRowModel().rows.length,
|
|
356
|
-
total: ((
|
|
357
|
-
}) }), ((
|
|
315
|
+
total: ((_b = (_a = props.pagination) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.count) || 0,
|
|
316
|
+
}) }), ((_c = props.pagination) === null || _c === void 0 ? void 0 : _c.isLoading) ? (jsxRuntime.jsx("span", { className: "ml-2", children: jsxRuntime.jsx(reactComponents.Spinner, { size: "small" }) })) : null, props.footerRightActions ? jsxRuntime.jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions }) : null] }))] }));
|
|
358
317
|
};
|
|
359
318
|
const cvaTableRow = cssClassVarianceUtilities.cvaMerge(["hover:bg-neutral-100"], {
|
|
360
319
|
variants: {
|
|
@@ -423,7 +382,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
423
382
|
var _a;
|
|
424
383
|
const dragColumn = localColumns[dragIndex];
|
|
425
384
|
if (dragColumn) {
|
|
426
|
-
setLocalColumns(
|
|
385
|
+
setLocalColumns(update(localColumns, {
|
|
427
386
|
$splice: [
|
|
428
387
|
[dragIndex, 1],
|
|
429
388
|
[hoverIndex, 0, dragColumn],
|
|
@@ -566,9 +525,8 @@ const Sorting = ({ columns, }) => {
|
|
|
566
525
|
* @param {TableOptionsProps<TData>} props - The props object containing configuration options.
|
|
567
526
|
* @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
|
|
568
527
|
*/
|
|
569
|
-
const useTable = (
|
|
570
|
-
var _b, _c, _d
|
|
571
|
-
var { onTableStateChange, initialState, columns } = _a, reactTableProps = __rest(_a, ["onTableStateChange", "initialState", "columns"]);
|
|
528
|
+
const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
|
|
529
|
+
var _a, _b, _c, _d;
|
|
572
530
|
const updatedInitialColumnVisibility = React.useMemo(() => {
|
|
573
531
|
const initialStateColumnVisibility = initialState === null || initialState === void 0 ? void 0 : initialState.columnVisibility;
|
|
574
532
|
const resultFromInitialState = initialStateColumnVisibility
|
|
@@ -599,10 +557,10 @@ const useTable = (_a) => {
|
|
|
599
557
|
});
|
|
600
558
|
return resultFromInitialState;
|
|
601
559
|
}, [columns, initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder]);
|
|
602
|
-
const [columnVisibility, setColumnVisibility] = React.useState(((
|
|
603
|
-
const [columnOrder, setColumnOrder] = React.useState(((
|
|
604
|
-
const [sorting, setSorting] = React.useState(((
|
|
605
|
-
const [columnSizing, setColumnSizing] = React.useState(((
|
|
560
|
+
const [columnVisibility, setColumnVisibility] = React.useState(((_a = reactTableProps.state) === null || _a === void 0 ? void 0 : _a.columnVisibility) || updatedInitialColumnVisibility || {});
|
|
561
|
+
const [columnOrder, setColumnOrder] = React.useState(((_b = reactTableProps.state) === null || _b === void 0 ? void 0 : _b.columnOrder) || updatedInitialColumnOrder);
|
|
562
|
+
const [sorting, setSorting] = React.useState(((_c = reactTableProps.state) === null || _c === void 0 ? void 0 : _c.sorting) || (initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || []);
|
|
563
|
+
const [columnSizing, setColumnSizing] = React.useState(((_d = reactTableProps.state) === null || _d === void 0 ? void 0 : _d.columnSizing) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing) || {});
|
|
606
564
|
React.useEffect(() => {
|
|
607
565
|
if (initialState && sharedUtils.objectKeys(initialState).length > 0) {
|
|
608
566
|
setColumnVisibility(initialState.columnVisibility || updatedInitialColumnVisibility || {});
|
|
@@ -619,29 +577,43 @@ const useTable = (_a) => {
|
|
|
619
577
|
initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing,
|
|
620
578
|
]);
|
|
621
579
|
const state = React.useMemo(() => {
|
|
622
|
-
return
|
|
580
|
+
return {
|
|
581
|
+
sorting,
|
|
623
582
|
columnVisibility,
|
|
624
583
|
columnOrder,
|
|
625
|
-
columnSizing
|
|
584
|
+
columnSizing,
|
|
585
|
+
...reactTableProps.state,
|
|
586
|
+
};
|
|
626
587
|
}, [sorting, columnVisibility, columnOrder, columnSizing, reactTableProps.state]);
|
|
627
|
-
const table = reactTable.useReactTable(
|
|
588
|
+
const table = reactTable.useReactTable({
|
|
589
|
+
manualSorting: true,
|
|
590
|
+
columnResizeMode: "onChange",
|
|
591
|
+
getSortedRowModel: reactTable.getSortedRowModel(),
|
|
592
|
+
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
593
|
+
...reactTableProps,
|
|
594
|
+
onColumnVisibilityChange: value => {
|
|
628
595
|
var _a;
|
|
629
596
|
setColumnVisibility(value);
|
|
630
597
|
(_a = reactTableProps.onColumnVisibilityChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
631
|
-
},
|
|
598
|
+
},
|
|
599
|
+
onColumnSizingChange: value => {
|
|
632
600
|
var _a;
|
|
633
601
|
setColumnSizing(value);
|
|
634
602
|
(_a = reactTableProps.onColumnSizingChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
635
|
-
},
|
|
603
|
+
},
|
|
604
|
+
onColumnOrderChange: value => {
|
|
636
605
|
var _a;
|
|
637
606
|
setColumnOrder(value);
|
|
638
607
|
(_a = reactTableProps.onColumnOrderChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
639
|
-
},
|
|
608
|
+
},
|
|
609
|
+
onSortingChange: value => {
|
|
640
610
|
var _a;
|
|
641
611
|
setSorting(value);
|
|
642
612
|
(_a = reactTableProps.onSortingChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
643
|
-
},
|
|
644
|
-
|
|
613
|
+
},
|
|
614
|
+
columns,
|
|
615
|
+
state,
|
|
616
|
+
});
|
|
645
617
|
React.useEffect(() => {
|
|
646
618
|
if (onTableStateChange) {
|
|
647
619
|
onTableStateChange(state);
|
|
@@ -687,10 +659,13 @@ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true
|
|
|
687
659
|
defaultSelectedIds === null || defaultSelectedIds === void 0 ? void 0 : defaultSelectedIds.forEach(id => {
|
|
688
660
|
initialSelection[id] = true;
|
|
689
661
|
});
|
|
690
|
-
setRowSelection(() => (
|
|
662
|
+
setRowSelection(() => ({ ...initialSelection }));
|
|
691
663
|
}, [defaultSelectedIds]);
|
|
692
664
|
const toggleRowSelectionState = React.useCallback((id) => {
|
|
693
|
-
setRowSelection(prevRowSelection => (
|
|
665
|
+
setRowSelection(prevRowSelection => ({
|
|
666
|
+
...prevRowSelection,
|
|
667
|
+
[id]: !prevRowSelection[id],
|
|
668
|
+
}));
|
|
694
669
|
}, []);
|
|
695
670
|
const selectedIds = React.useMemo(() => sharedUtils.objectEntries(rowSelection)
|
|
696
671
|
.filter(([_, selected]) => selected)
|
|
@@ -754,7 +729,10 @@ const fromTUSortToTanStack = (input) => {
|
|
|
754
729
|
*/
|
|
755
730
|
const fromTanStackToTUSort = (input) => {
|
|
756
731
|
var _a, _b;
|
|
757
|
-
return
|
|
732
|
+
return {
|
|
733
|
+
...reactCoreContextsApi.validateStringAsAssetSortByProperty((_a = input[0]) === null || _a === void 0 ? void 0 : _a.id),
|
|
734
|
+
order: ((_b = input[0]) === null || _b === void 0 ? void 0 : _b.desc) ? reactCoreContextsApi.SortOrder.Desc : reactCoreContextsApi.SortOrder.Asc,
|
|
735
|
+
};
|
|
758
736
|
};
|
|
759
737
|
|
|
760
738
|
/*
|
|
@@ -766,7 +744,7 @@ const fromTanStackToTUSort = (input) => {
|
|
|
766
744
|
*/
|
|
767
745
|
setupLibraryTranslations();
|
|
768
746
|
|
|
769
|
-
Object.defineProperty(exports,
|
|
747
|
+
Object.defineProperty(exports, "createColumnHelper", {
|
|
770
748
|
enumerable: true,
|
|
771
749
|
get: function () { return reactTable.createColumnHelper; }
|
|
772
750
|
});
|
package/index.esm.js
CHANGED
|
@@ -124,38 +124,6 @@ const cvaActionContainerAndOverflow = cvaMerge([
|
|
|
124
124
|
"sm:flex-row",
|
|
125
125
|
]);
|
|
126
126
|
|
|
127
|
-
/******************************************************************************
|
|
128
|
-
Copyright (c) Microsoft Corporation.
|
|
129
|
-
|
|
130
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
131
|
-
purpose with or without fee is hereby granted.
|
|
132
|
-
|
|
133
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
134
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
135
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
136
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
137
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
138
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
139
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
140
|
-
***************************************************************************** */
|
|
141
|
-
|
|
142
|
-
function __rest(s, e) {
|
|
143
|
-
var t = {};
|
|
144
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
145
|
-
t[p] = s[p];
|
|
146
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
147
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
148
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
149
|
-
t[p[i]] = s[p[i]];
|
|
150
|
-
}
|
|
151
|
-
return t;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
155
|
-
var e = new Error(message);
|
|
156
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
127
|
/**
|
|
160
128
|
* The button to show in the ActionSheet.
|
|
161
129
|
* Should not be used outside the ActionSheet component.
|
|
@@ -167,12 +135,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
167
135
|
* @param {...any} [props.rest] - Any additional button properties.
|
|
168
136
|
* @returns {JSX.Element} - The action button component.
|
|
169
137
|
*/
|
|
170
|
-
const ActionButton = (
|
|
171
|
-
var { action, children, id } = _a, rest = __rest(_a, ["action", "children", "id"]);
|
|
138
|
+
const ActionButton = ({ action, children, id, ...rest }) => {
|
|
172
139
|
if (action.type === "route") {
|
|
173
|
-
return (jsx(Button,
|
|
140
|
+
return (jsx(Button, { asChild: true, id: id, variant: "ghost-neutral", ...rest, children: jsx(Link, { to: action.url, children: children }) }));
|
|
174
141
|
}
|
|
175
|
-
return (jsx(Button,
|
|
142
|
+
return (jsx(Button, { id: id, onClick: action.method, variant: "ghost-neutral", ...rest, children: children }));
|
|
176
143
|
};
|
|
177
144
|
/**
|
|
178
145
|
* Converts an action model to a MenuItem component.
|
|
@@ -265,9 +232,8 @@ const ActionSheet = ({ actions, moreActions = [], selections, resetSelection, cl
|
|
|
265
232
|
* @returns {JSX.Element} Table component
|
|
266
233
|
*/
|
|
267
234
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
|
-
const Table = (
|
|
269
|
-
var _b, _c
|
|
270
|
-
var { rowHeight = 75 } = _a, props = __rest(_a, ["rowHeight"]);
|
|
235
|
+
const Table = ({ rowHeight = 75, ...props }) => {
|
|
236
|
+
var _a, _b, _c;
|
|
271
237
|
//we need a reference to the scrolling element for logic down below
|
|
272
238
|
const tableContainerRef = useRef(null);
|
|
273
239
|
const [t] = useTranslation();
|
|
@@ -316,20 +282,19 @@ const Table = (_a) => {
|
|
|
316
282
|
transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
|
|
317
283
|
}, children: row.getVisibleCells().map(cell => {
|
|
318
284
|
var _a, _b;
|
|
319
|
-
return (jsx(Td, {
|
|
320
|
-
style: {
|
|
285
|
+
return (jsx(Td, { style: {
|
|
321
286
|
width: cell.column.getSize(),
|
|
322
287
|
minWidth: cell.column.columnDef.minSize,
|
|
323
288
|
maxWidth: cell.column.columnDef.maxSize,
|
|
324
289
|
textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
|
|
325
290
|
flexGrow: ((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.shouldGrow) ? 1 : 0,
|
|
326
|
-
}, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
|
|
291
|
+
}, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }, cell.id));
|
|
327
292
|
}) }, row.id));
|
|
328
293
|
}
|
|
329
294
|
}) })) : (jsx("tbody", { className: "min-h-[400px]", children: jsx("tr", { children: jsx("td", { className: "b-0", children: props.loading ? (jsx(Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : props.noDataMessage ? (props.noDataMessage) : (jsx(EmptyState, { className: "absolute inset-0", description: t("table.noResults"), image: "SEARCH_DOCUMENT" })) }) }) }))] }) }), props.hideFooter ? null : (jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
|
|
330
295
|
count: props.getRowModel().rows.length,
|
|
331
|
-
total: ((
|
|
332
|
-
}) }), ((
|
|
296
|
+
total: ((_b = (_a = props.pagination) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.count) || 0,
|
|
297
|
+
}) }), ((_c = props.pagination) === null || _c === void 0 ? void 0 : _c.isLoading) ? (jsx("span", { className: "ml-2", children: jsx(Spinner, { size: "small" }) })) : null, props.footerRightActions ? jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions }) : null] }))] }));
|
|
333
298
|
};
|
|
334
299
|
const cvaTableRow = cvaMerge(["hover:bg-neutral-100"], {
|
|
335
300
|
variants: {
|
|
@@ -541,9 +506,8 @@ const Sorting = ({ columns, }) => {
|
|
|
541
506
|
* @param {TableOptionsProps<TData>} props - The props object containing configuration options.
|
|
542
507
|
* @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
|
|
543
508
|
*/
|
|
544
|
-
const useTable = (
|
|
545
|
-
var _b, _c, _d
|
|
546
|
-
var { onTableStateChange, initialState, columns } = _a, reactTableProps = __rest(_a, ["onTableStateChange", "initialState", "columns"]);
|
|
509
|
+
const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
|
|
510
|
+
var _a, _b, _c, _d;
|
|
547
511
|
const updatedInitialColumnVisibility = useMemo(() => {
|
|
548
512
|
const initialStateColumnVisibility = initialState === null || initialState === void 0 ? void 0 : initialState.columnVisibility;
|
|
549
513
|
const resultFromInitialState = initialStateColumnVisibility
|
|
@@ -574,10 +538,10 @@ const useTable = (_a) => {
|
|
|
574
538
|
});
|
|
575
539
|
return resultFromInitialState;
|
|
576
540
|
}, [columns, initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder]);
|
|
577
|
-
const [columnVisibility, setColumnVisibility] = useState(((
|
|
578
|
-
const [columnOrder, setColumnOrder] = useState(((
|
|
579
|
-
const [sorting, setSorting] = useState(((
|
|
580
|
-
const [columnSizing, setColumnSizing] = useState(((
|
|
541
|
+
const [columnVisibility, setColumnVisibility] = useState(((_a = reactTableProps.state) === null || _a === void 0 ? void 0 : _a.columnVisibility) || updatedInitialColumnVisibility || {});
|
|
542
|
+
const [columnOrder, setColumnOrder] = useState(((_b = reactTableProps.state) === null || _b === void 0 ? void 0 : _b.columnOrder) || updatedInitialColumnOrder);
|
|
543
|
+
const [sorting, setSorting] = useState(((_c = reactTableProps.state) === null || _c === void 0 ? void 0 : _c.sorting) || (initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || []);
|
|
544
|
+
const [columnSizing, setColumnSizing] = useState(((_d = reactTableProps.state) === null || _d === void 0 ? void 0 : _d.columnSizing) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing) || {});
|
|
581
545
|
useEffect(() => {
|
|
582
546
|
if (initialState && objectKeys(initialState).length > 0) {
|
|
583
547
|
setColumnVisibility(initialState.columnVisibility || updatedInitialColumnVisibility || {});
|
|
@@ -594,29 +558,43 @@ const useTable = (_a) => {
|
|
|
594
558
|
initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing,
|
|
595
559
|
]);
|
|
596
560
|
const state = useMemo(() => {
|
|
597
|
-
return
|
|
561
|
+
return {
|
|
562
|
+
sorting,
|
|
598
563
|
columnVisibility,
|
|
599
564
|
columnOrder,
|
|
600
|
-
columnSizing
|
|
565
|
+
columnSizing,
|
|
566
|
+
...reactTableProps.state,
|
|
567
|
+
};
|
|
601
568
|
}, [sorting, columnVisibility, columnOrder, columnSizing, reactTableProps.state]);
|
|
602
|
-
const table = useReactTable(
|
|
569
|
+
const table = useReactTable({
|
|
570
|
+
manualSorting: true,
|
|
571
|
+
columnResizeMode: "onChange",
|
|
572
|
+
getSortedRowModel: getSortedRowModel(),
|
|
573
|
+
getCoreRowModel: getCoreRowModel(),
|
|
574
|
+
...reactTableProps,
|
|
575
|
+
onColumnVisibilityChange: value => {
|
|
603
576
|
var _a;
|
|
604
577
|
setColumnVisibility(value);
|
|
605
578
|
(_a = reactTableProps.onColumnVisibilityChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
606
|
-
},
|
|
579
|
+
},
|
|
580
|
+
onColumnSizingChange: value => {
|
|
607
581
|
var _a;
|
|
608
582
|
setColumnSizing(value);
|
|
609
583
|
(_a = reactTableProps.onColumnSizingChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
610
|
-
},
|
|
584
|
+
},
|
|
585
|
+
onColumnOrderChange: value => {
|
|
611
586
|
var _a;
|
|
612
587
|
setColumnOrder(value);
|
|
613
588
|
(_a = reactTableProps.onColumnOrderChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
614
|
-
},
|
|
589
|
+
},
|
|
590
|
+
onSortingChange: value => {
|
|
615
591
|
var _a;
|
|
616
592
|
setSorting(value);
|
|
617
593
|
(_a = reactTableProps.onSortingChange) === null || _a === void 0 ? void 0 : _a.call(reactTableProps, value);
|
|
618
|
-
},
|
|
619
|
-
|
|
594
|
+
},
|
|
595
|
+
columns,
|
|
596
|
+
state,
|
|
597
|
+
});
|
|
620
598
|
useEffect(() => {
|
|
621
599
|
if (onTableStateChange) {
|
|
622
600
|
onTableStateChange(state);
|
|
@@ -662,10 +640,13 @@ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true
|
|
|
662
640
|
defaultSelectedIds === null || defaultSelectedIds === void 0 ? void 0 : defaultSelectedIds.forEach(id => {
|
|
663
641
|
initialSelection[id] = true;
|
|
664
642
|
});
|
|
665
|
-
setRowSelection(() => (
|
|
643
|
+
setRowSelection(() => ({ ...initialSelection }));
|
|
666
644
|
}, [defaultSelectedIds]);
|
|
667
645
|
const toggleRowSelectionState = useCallback((id) => {
|
|
668
|
-
setRowSelection(prevRowSelection => (
|
|
646
|
+
setRowSelection(prevRowSelection => ({
|
|
647
|
+
...prevRowSelection,
|
|
648
|
+
[id]: !prevRowSelection[id],
|
|
649
|
+
}));
|
|
669
650
|
}, []);
|
|
670
651
|
const selectedIds = useMemo(() => objectEntries(rowSelection)
|
|
671
652
|
.filter(([_, selected]) => selected)
|
|
@@ -729,7 +710,10 @@ const fromTUSortToTanStack = (input) => {
|
|
|
729
710
|
*/
|
|
730
711
|
const fromTanStackToTUSort = (input) => {
|
|
731
712
|
var _a, _b;
|
|
732
|
-
return
|
|
713
|
+
return {
|
|
714
|
+
...validateStringAsAssetSortByProperty((_a = input[0]) === null || _a === void 0 ? void 0 : _a.id),
|
|
715
|
+
order: ((_b = input[0]) === null || _b === void 0 ? void 0 : _b.desc) ? SortOrder.Desc : SortOrder.Asc,
|
|
716
|
+
};
|
|
733
717
|
};
|
|
734
718
|
|
|
735
719
|
/*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.459",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@trackunit/react-components": "*",
|
|
11
|
-
"react": "
|
|
11
|
+
"react": "18.3.1",
|
|
12
12
|
"@tanstack/react-table": "^8.10.7",
|
|
13
13
|
"@trackunit/react-table-base-components": "*",
|
|
14
14
|
"@trackunit/react-table-pagination": "*",
|
|
@@ -26,5 +26,6 @@
|
|
|
26
26
|
"tailwind-merge": "^2.0.0"
|
|
27
27
|
},
|
|
28
28
|
"module": "./index.esm.js",
|
|
29
|
-
"main": "./index.cjs.js"
|
|
30
|
-
|
|
29
|
+
"main": "./index.cjs.js",
|
|
30
|
+
"types": "./index.esm.d.ts"
|
|
31
|
+
}
|
|
@@ -15,5 +15,5 @@ interface ActionContainerAndOverflowProps extends CommonProps {
|
|
|
15
15
|
* @param {string} [props.dataTestId] - Data test id for the component, useful in testing.
|
|
16
16
|
* @returns {ReactElement} The rendered component.
|
|
17
17
|
*/
|
|
18
|
-
export declare const ActionContainerAndOverflow: ({ actions, moreActions, dataTestId }: ActionContainerAndOverflowProps) => JSX.Element;
|
|
18
|
+
export declare const ActionContainerAndOverflow: ({ actions, moreActions, dataTestId }: ActionContainerAndOverflowProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
19
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
3
2
|
import { ActionModel } from "./Actions";
|
|
4
3
|
export interface ActionSheetProps extends CommonProps {
|
|
@@ -27,4 +26,4 @@ export interface ActionSheetProps extends CommonProps {
|
|
|
27
26
|
* @param {ActionSheetProps} props - The props for the ActionSheet component
|
|
28
27
|
* @returns {JSX.Element} ActionSheet component
|
|
29
28
|
*/
|
|
30
|
-
export declare const ActionSheet: ({ actions, moreActions, selections, resetSelection, className, dataTestId, }: ActionSheetProps) => JSX.Element;
|
|
29
|
+
export declare const ActionSheet: ({ actions, moreActions, selections, resetSelection, className, dataTestId, }: ActionSheetProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -22,7 +22,7 @@ interface ActionButtonProps extends ButtonCommonProps {
|
|
|
22
22
|
* @param {...any} [props.rest] - Any additional button properties.
|
|
23
23
|
* @returns {JSX.Element} - The action button component.
|
|
24
24
|
*/
|
|
25
|
-
export declare const ActionButton: ({ action, children, id, ...rest }: ActionButtonProps) => JSX.Element;
|
|
25
|
+
export declare const ActionButton: ({ action, children, id, ...rest }: ActionButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
26
26
|
/**
|
|
27
27
|
* Converts an action model to a MenuItem component.
|
|
28
28
|
* These should be shown in the more menu.
|
|
@@ -32,7 +32,7 @@ export declare const ActionButton: ({ action, children, id, ...rest }: ActionBut
|
|
|
32
32
|
* @param {string} [dataTestId] - Optional data test ID.
|
|
33
33
|
* @returns {JSX.Element} - The MenuItem component for the given action.
|
|
34
34
|
*/
|
|
35
|
-
export declare const actionDataToMenuItem: (action: ActionModel, dataTestId?: string) => JSX.Element;
|
|
35
|
+
export declare const actionDataToMenuItem: (action: ActionModel, dataTestId?: string) => import("react/jsx-runtime").JSX.Element;
|
|
36
36
|
/**
|
|
37
37
|
* Converts an action model to an ActionButton component.
|
|
38
38
|
* These should be shown in the ActionSheet.
|
|
@@ -42,5 +42,5 @@ export declare const actionDataToMenuItem: (action: ActionModel, dataTestId?: st
|
|
|
42
42
|
* @param {string} [dataTestId] - Optional data test ID.
|
|
43
43
|
* @returns {JSX.Element} - The ActionButton component for the given action.
|
|
44
44
|
*/
|
|
45
|
-
export declare const actionDataToActionButton: (action: ActionModel, dataTestId?: string) => JSX.Element;
|
|
45
|
+
export declare const actionDataToActionButton: (action: ActionModel, dataTestId?: string) => import("react/jsx-runtime").JSX.Element;
|
|
46
46
|
export {};
|
package/src/Table.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Table as ReactTable, Row } from "@tanstack/react-table";
|
|
3
2
|
import { CommonProps } from "@trackunit/react-components";
|
|
4
3
|
import { RelayPagination } from "@trackunit/react-table-pagination";
|
|
@@ -19,4 +18,4 @@ export interface TableProps<TData extends object> extends ReactTable<TData>, Com
|
|
|
19
18
|
* @param {ReactTable} props - The props for the Table component
|
|
20
19
|
* @returns {JSX.Element} Table component
|
|
21
20
|
*/
|
|
22
|
-
export declare const Table: <TData extends object>({ rowHeight, ...props }: TableProps<TData>) => JSX.Element;
|
|
21
|
+
export declare const Table: <TData extends object>({ rowHeight, ...props }: TableProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Column, ColumnOrderState, Updater } from "@tanstack/react-table";
|
|
3
2
|
export interface ColumnFilterProps<TColumnFilter extends object, TColumnFilterValue> {
|
|
4
3
|
columns: Column<TColumnFilter, TColumnFilterValue>[];
|
|
@@ -15,7 +14,7 @@ export interface ColumnFilterProps<TColumnFilter extends object, TColumnFilterVa
|
|
|
15
14
|
* @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
|
|
16
15
|
* @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
|
|
17
16
|
*/
|
|
18
|
-
export declare const ColumnFilter: <TColumnFilter extends object, TColumnFilterValue>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: ColumnFilterProps<TColumnFilter, TColumnFilterValue>) => JSX.Element;
|
|
17
|
+
export declare const ColumnFilter: <TColumnFilter extends object, TColumnFilterValue>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: ColumnFilterProps<TColumnFilter, TColumnFilterValue>) => import("react/jsx-runtime").JSX.Element;
|
|
19
18
|
export interface ColumnFiltersDragAndDropProps<TColumnFiltersDragAndDrop extends object, TColumnFiltersDragAndDropValue> {
|
|
20
19
|
columns: Column<TColumnFiltersDragAndDrop, TColumnFiltersDragAndDropValue>[];
|
|
21
20
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export type Density = "spacious" | "compact";
|
|
3
2
|
interface RowDensityProps {
|
|
4
3
|
density: Density;
|
|
@@ -11,5 +10,5 @@ interface RowDensityProps {
|
|
|
11
10
|
* @param {RowDensityProps} props - The props object containing row density properties.
|
|
12
11
|
* @returns {JSX.Element} A React JSX element representing the RowSpacing component.
|
|
13
12
|
*/
|
|
14
|
-
export declare const RowSpacing: ({ density, setRowDensity, onUserEvent }: RowDensityProps) => JSX.Element;
|
|
13
|
+
export declare const RowSpacing: ({ density, setRowDensity, onUserEvent }: RowDensityProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
14
|
export {};
|
package/src/menus/Sorting.d.ts
CHANGED
package/src/translation.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { NamespaceTransProps, TransForLibs, TranslationResource } from "@trackunit/i18n-library-translation";
|
|
3
2
|
import defaultTranslations from "./locales/en/translation.json";
|
|
4
3
|
/** A type for all available translation keys in this library */
|
|
@@ -27,7 +26,7 @@ export type TranslationFunction = TransForLibs<TranslationKeys>;
|
|
|
27
26
|
/**
|
|
28
27
|
* Trans for this specific library.
|
|
29
28
|
*/
|
|
30
|
-
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => JSX.Element;
|
|
29
|
+
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => import("react/jsx-runtime").JSX.Element;
|
|
31
30
|
/**
|
|
32
31
|
* Registers the translations for this library
|
|
33
32
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { TableSelectionProps, selectableTableData } from "./useTableSelection";
|
|
3
2
|
export interface UseTableSelectionDemoComponentProps<TData extends selectableTableData> extends TableSelectionProps<TData> {
|
|
4
3
|
}
|
|
@@ -9,4 +8,4 @@ export interface UseTableSelectionDemoComponentProps<TData extends selectableTab
|
|
|
9
8
|
*
|
|
10
9
|
* It Also returns a `selectionColumn` object that can be used as a column definition in a table.
|
|
11
10
|
*/
|
|
12
|
-
export declare const UseTableSelectionDemoComponent: <TData extends selectableTableData>(props: UseTableSelectionDemoComponentProps<TData>) => JSX.Element;
|
|
11
|
+
export declare const UseTableSelectionDemoComponent: <TData extends selectableTableData>(props: UseTableSelectionDemoComponentProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
package/translation.cjs.js
CHANGED
package/translation.cjs10.js
CHANGED
package/translation.cjs11.js
CHANGED
package/translation.cjs12.js
CHANGED
package/translation.cjs13.js
CHANGED
package/translation.cjs14.js
CHANGED
package/translation.cjs15.js
CHANGED
package/translation.cjs16.js
CHANGED
package/translation.cjs17.js
CHANGED
package/translation.cjs2.js
CHANGED
package/translation.cjs3.js
CHANGED
package/translation.cjs4.js
CHANGED
package/translation.cjs5.js
CHANGED
package/translation.cjs6.js
CHANGED
package/translation.cjs7.js
CHANGED
package/translation.cjs8.js
CHANGED
package/translation.cjs9.js
CHANGED