@indico-data/design-system 2.60.10 → 2.60.12
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/lib/components/tanstackTable/docs/internalSorting/InternalClientSideSorting.stories.d.ts +7 -0
- package/lib/index.css +3 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.css +3 -0
- package/lib/index.esm.js +91 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +94 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/tanstackTable/TanstackTable.tsx +12 -2
- package/src/components/tanstackTable/docs/internalSorting/InternalClientSideSorting.mdx +31 -0
- package/src/components/tanstackTable/docs/internalSorting/InternalClientSideSorting.stories.tsx +71 -0
- package/src/components/tanstackTable/styles/table.scss +8 -0
- package/src/index.ts +10 -0
package/lib/index.js
CHANGED
|
@@ -24003,6 +24003,92 @@ function getCoreRowModel() {
|
|
|
24003
24003
|
}, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
|
|
24004
24004
|
}
|
|
24005
24005
|
|
|
24006
|
+
function getSortedRowModel() {
|
|
24007
|
+
return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
|
|
24008
|
+
if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
|
|
24009
|
+
return rowModel;
|
|
24010
|
+
}
|
|
24011
|
+
const sortingState = table.getState().sorting;
|
|
24012
|
+
const sortedFlatRows = [];
|
|
24013
|
+
|
|
24014
|
+
// Filter out sortings that correspond to non existing columns
|
|
24015
|
+
const availableSorting = sortingState.filter(sort => {
|
|
24016
|
+
var _table$getColumn;
|
|
24017
|
+
return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
|
|
24018
|
+
});
|
|
24019
|
+
const columnInfoById = {};
|
|
24020
|
+
availableSorting.forEach(sortEntry => {
|
|
24021
|
+
const column = table.getColumn(sortEntry.id);
|
|
24022
|
+
if (!column) return;
|
|
24023
|
+
columnInfoById[sortEntry.id] = {
|
|
24024
|
+
sortUndefined: column.columnDef.sortUndefined,
|
|
24025
|
+
invertSorting: column.columnDef.invertSorting,
|
|
24026
|
+
sortingFn: column.getSortingFn()
|
|
24027
|
+
};
|
|
24028
|
+
});
|
|
24029
|
+
const sortData = rows => {
|
|
24030
|
+
// This will also perform a stable sorting using the row index
|
|
24031
|
+
// if needed.
|
|
24032
|
+
const sortedData = rows.map(row => ({
|
|
24033
|
+
...row
|
|
24034
|
+
}));
|
|
24035
|
+
sortedData.sort((rowA, rowB) => {
|
|
24036
|
+
for (let i = 0; i < availableSorting.length; i += 1) {
|
|
24037
|
+
var _sortEntry$desc;
|
|
24038
|
+
const sortEntry = availableSorting[i];
|
|
24039
|
+
const columnInfo = columnInfoById[sortEntry.id];
|
|
24040
|
+
const sortUndefined = columnInfo.sortUndefined;
|
|
24041
|
+
const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
|
|
24042
|
+
let sortInt = 0;
|
|
24043
|
+
|
|
24044
|
+
// All sorting ints should always return in ascending order
|
|
24045
|
+
if (sortUndefined) {
|
|
24046
|
+
const aValue = rowA.getValue(sortEntry.id);
|
|
24047
|
+
const bValue = rowB.getValue(sortEntry.id);
|
|
24048
|
+
const aUndefined = aValue === undefined;
|
|
24049
|
+
const bUndefined = bValue === undefined;
|
|
24050
|
+
if (aUndefined || bUndefined) {
|
|
24051
|
+
if (sortUndefined === 'first') return aUndefined ? -1 : 1;
|
|
24052
|
+
if (sortUndefined === 'last') return aUndefined ? 1 : -1;
|
|
24053
|
+
sortInt = aUndefined && bUndefined ? 0 : aUndefined ? sortUndefined : -sortUndefined;
|
|
24054
|
+
}
|
|
24055
|
+
}
|
|
24056
|
+
if (sortInt === 0) {
|
|
24057
|
+
sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
24058
|
+
}
|
|
24059
|
+
|
|
24060
|
+
// If sorting is non-zero, take care of desc and inversion
|
|
24061
|
+
if (sortInt !== 0) {
|
|
24062
|
+
if (isDesc) {
|
|
24063
|
+
sortInt *= -1;
|
|
24064
|
+
}
|
|
24065
|
+
if (columnInfo.invertSorting) {
|
|
24066
|
+
sortInt *= -1;
|
|
24067
|
+
}
|
|
24068
|
+
return sortInt;
|
|
24069
|
+
}
|
|
24070
|
+
}
|
|
24071
|
+
return rowA.index - rowB.index;
|
|
24072
|
+
});
|
|
24073
|
+
|
|
24074
|
+
// If there are sub-rows, sort them
|
|
24075
|
+
sortedData.forEach(row => {
|
|
24076
|
+
var _row$subRows;
|
|
24077
|
+
sortedFlatRows.push(row);
|
|
24078
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
|
|
24079
|
+
row.subRows = sortData(row.subRows);
|
|
24080
|
+
}
|
|
24081
|
+
});
|
|
24082
|
+
return sortedData;
|
|
24083
|
+
};
|
|
24084
|
+
return {
|
|
24085
|
+
rows: sortData(rowModel.rows),
|
|
24086
|
+
flatRows: sortedFlatRows,
|
|
24087
|
+
rowsById: rowModel.rowsById
|
|
24088
|
+
};
|
|
24089
|
+
}, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
|
|
24090
|
+
}
|
|
24091
|
+
|
|
24006
24092
|
/**
|
|
24007
24093
|
* react-table
|
|
24008
24094
|
*
|
|
@@ -41406,6 +41492,8 @@ function TanstackTable(_a) {
|
|
|
41406
41492
|
setRowSelection, formattedColumns, setFormattedColumns, } = useTanstackTable({
|
|
41407
41493
|
defaultColumns,
|
|
41408
41494
|
});
|
|
41495
|
+
// handles internal sorting state.
|
|
41496
|
+
const [sorting, setSorting] = React.useState([]);
|
|
41409
41497
|
const thRefs = React.useRef({});
|
|
41410
41498
|
// Auto-compute column widths based on current table header cell widths for columns without a defined size.
|
|
41411
41499
|
React.useEffect(() => {
|
|
@@ -41420,7 +41508,8 @@ function TanstackTable(_a) {
|
|
|
41420
41508
|
}, [data, columns, windowWidth]);
|
|
41421
41509
|
const table = useReactTable(Object.assign(Object.assign({}, rest), { data: data !== null && data !== void 0 ? data : defaultData, columns: formattedColumns, state: {
|
|
41422
41510
|
rowSelection,
|
|
41423
|
-
|
|
41511
|
+
sorting,
|
|
41512
|
+
}, enableRowSelection, onRowSelectionChange: setRowSelection, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), onSortingChange: setSorting, manualPagination: true, getRowId: (row) => row === null || row === void 0 ? void 0 : row.id, initialState: {
|
|
41424
41513
|
columnPinning: {
|
|
41425
41514
|
left: defaultPinnedColumns,
|
|
41426
41515
|
},
|
|
@@ -43157,8 +43246,11 @@ exports.autoPlacement = autoPlacement;
|
|
|
43157
43246
|
exports.autoUpdate = autoUpdate$1;
|
|
43158
43247
|
exports.computePosition = computePosition$2;
|
|
43159
43248
|
exports.detectOverflow = detectOverflow$1;
|
|
43249
|
+
exports.flexRender = flexRender;
|
|
43160
43250
|
exports.flip = flip$2;
|
|
43251
|
+
exports.getCoreRowModel = getCoreRowModel;
|
|
43161
43252
|
exports.getOverflowAncestors = getOverflowAncestors$1;
|
|
43253
|
+
exports.getSortedRowModel = getSortedRowModel;
|
|
43162
43254
|
exports.hide = hide$1;
|
|
43163
43255
|
exports.inline = inline;
|
|
43164
43256
|
exports.limitShift = limitShift;
|
|
@@ -43169,4 +43261,5 @@ exports.shift = shift$2;
|
|
|
43169
43261
|
exports.size = size;
|
|
43170
43262
|
exports.toast = y;
|
|
43171
43263
|
exports.useFloating = useFloating$1;
|
|
43264
|
+
exports.useReactTable = useReactTable;
|
|
43172
43265
|
//# sourceMappingURL=index.js.map
|