@tanstack/react-table 8.2.5 → 8.3.1

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.
@@ -20,6 +20,9 @@ import * as React from 'react';
20
20
  *
21
21
  * @license MIT
22
22
  */
23
+ // Is this type a tuple?
24
+ // If this type is a tuple, what indices are allowed?
25
+ ///
23
26
  function functionalUpdate(updater, input) {
24
27
  return typeof updater === 'function' ? updater(input) : updater;
25
28
  }
@@ -105,13 +108,27 @@ function createColumn(table, columnDef, depth, parent) {
105
108
  const resolvedColumnDef = { ...defaultColumn,
106
109
  ...columnDef
107
110
  };
108
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : resolvedColumnDef.accessorKey) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
111
+ const accessorKey = resolvedColumnDef.accessorKey;
112
+ let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
109
113
  let accessorFn;
110
114
 
111
115
  if (resolvedColumnDef.accessorFn) {
112
116
  accessorFn = resolvedColumnDef.accessorFn;
113
- } else if (resolvedColumnDef.accessorKey) {
114
- accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
117
+ } else if (accessorKey) {
118
+ // Support deep accessor keys
119
+ if (accessorKey.includes('.')) {
120
+ accessorFn = originalRow => {
121
+ let result = originalRow;
122
+
123
+ for (const key of accessorKey.split('.')) {
124
+ result = result[key];
125
+ }
126
+
127
+ return result;
128
+ };
129
+ } else {
130
+ accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
131
+ }
115
132
  }
116
133
 
117
134
  if (!id) {
@@ -1107,7 +1124,7 @@ const Filters = {
1107
1124
  var _table$getCoreRowMode, _table$getCoreRowMode2;
1108
1125
 
1109
1126
  const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null ? void 0 : (_table$getCoreRowMode2 = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode2.getValue();
1110
- return typeof value === 'string';
1127
+ return typeof value === 'string' || typeof value === 'number';
1111
1128
  }
1112
1129
  };
1113
1130
  },
@@ -2139,7 +2156,7 @@ const RowSelection = {
2139
2156
  let isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
2140
2157
 
2141
2158
  if (isAllRowsSelected) {
2142
- if (preFilteredFlatRows.some(row => !rowSelection[row.id])) {
2159
+ if (preFilteredFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
2143
2160
  isAllRowsSelected = false;
2144
2161
  }
2145
2162
  }
@@ -2162,7 +2179,8 @@ const RowSelection = {
2162
2179
  getIsSomeRowsSelected: () => {
2163
2180
  var _table$getState$rowSe;
2164
2181
 
2165
- return !table.getIsAllRowsSelected() && !!Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2182
+ const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2183
+ return totalSelected < table.getCoreRowModel().flatRows.length;
2166
2184
  },
2167
2185
  getIsSomePageRowsSelected: () => {
2168
2186
  const paginationFlatRows = table.getPaginationRowModel().flatRows;
@@ -3101,6 +3119,52 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
3101
3119
  return row;
3102
3120
  };
3103
3121
 
3122
+ // type Person = {
3123
+ // firstName: string
3124
+ // lastName: string
3125
+ // age: number
3126
+ // visits: number
3127
+ // status: string
3128
+ // progress: number
3129
+ // nested: {
3130
+ // foo: [
3131
+ // {
3132
+ // bar: 'bar'
3133
+ // }
3134
+ // ]
3135
+ // bar: { subBar: boolean }[]
3136
+ // baz: {
3137
+ // foo: 'foo'
3138
+ // bar: {
3139
+ // baz: 'baz'
3140
+ // }
3141
+ // }
3142
+ // }
3143
+ // }
3144
+ // const test: DeepKeys<Person> = 'nested.foo.0.bar'
3145
+ // const test2: DeepKeys<Person> = 'nested.bar'
3146
+ // const helper = createColumnHelper<Person>()
3147
+ // helper.accessor('nested.foo', {
3148
+ // cell: info => info.getValue(),
3149
+ // })
3150
+ // helper.accessor('nested.foo.0.bar', {
3151
+ // cell: info => info.getValue(),
3152
+ // })
3153
+ // helper.accessor('nested.bar', {
3154
+ // cell: info => info.getValue(),
3155
+ // })
3156
+ function createColumnHelper() {
3157
+ return {
3158
+ accessor: (accessor, column) => {
3159
+ return typeof accessor === 'function' ? { ...column,
3160
+ accessorFn: accessor
3161
+ } : { ...column,
3162
+ accessorKey: accessor
3163
+ };
3164
+ }
3165
+ };
3166
+ }
3167
+
3104
3168
  function getCoreRowModel() {
3105
3169
  return table => memo(() => [table.options.data], data => {
3106
3170
  const rowModel = {
@@ -3849,5 +3913,5 @@ function useReactTable(options) {
3849
3913
  return tableRef.current;
3850
3914
  }
3851
3915
 
3852
- export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, flexRender, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns, useReactTable };
3916
+ export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createColumnHelper, createRow, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, flexRender, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns, useReactTable };
3853
3917
  //# sourceMappingURL=index.js.map