@tanstack/react-table 8.2.6 → 8.3.0

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) {
@@ -3101,6 +3118,52 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
3101
3118
  return row;
3102
3119
  };
3103
3120
 
3121
+ // type Person = {
3122
+ // firstName: string
3123
+ // lastName: string
3124
+ // age: number
3125
+ // visits: number
3126
+ // status: string
3127
+ // progress: number
3128
+ // nested: {
3129
+ // foo: [
3130
+ // {
3131
+ // bar: 'bar'
3132
+ // }
3133
+ // ]
3134
+ // bar: { subBar: boolean }[]
3135
+ // baz: {
3136
+ // foo: 'foo'
3137
+ // bar: {
3138
+ // baz: 'baz'
3139
+ // }
3140
+ // }
3141
+ // }
3142
+ // }
3143
+ // const test: DeepKeys<Person> = 'nested.foo.0.bar'
3144
+ // const test2: DeepKeys<Person> = 'nested.bar'
3145
+ // const helper = createColumnHelper<Person>()
3146
+ // helper.accessor('nested.foo', {
3147
+ // cell: info => info.getValue(),
3148
+ // })
3149
+ // helper.accessor('nested.foo.0.bar', {
3150
+ // cell: info => info.getValue(),
3151
+ // })
3152
+ // helper.accessor('nested.bar', {
3153
+ // cell: info => info.getValue(),
3154
+ // })
3155
+ function createColumnHelper() {
3156
+ return {
3157
+ accessor: (accessor, column) => {
3158
+ return typeof accessor === 'function' ? { ...column,
3159
+ accessorFn: accessor
3160
+ } : { ...column,
3161
+ accessorKey: accessor
3162
+ };
3163
+ }
3164
+ };
3165
+ }
3166
+
3104
3167
  function getCoreRowModel() {
3105
3168
  return table => memo(() => [table.options.data], data => {
3106
3169
  const rowModel = {
@@ -3849,5 +3912,5 @@ function useReactTable(options) {
3849
3912
  return tableRef.current;
3850
3913
  }
3851
3914
 
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 };
3915
+ 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
3916
  //# sourceMappingURL=index.js.map