@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.
@@ -102,6 +102,7 @@ exports.Visibility = index.Visibility;
102
102
  exports.aggregationFns = index.aggregationFns;
103
103
  exports.buildHeaderGroups = index.buildHeaderGroups;
104
104
  exports.createColumn = index.createColumn;
105
+ exports.createColumnHelper = index.createColumnHelper;
105
106
  exports.createRow = index.createRow;
106
107
  exports.createTable = index.createTable;
107
108
  exports.defaultColumnSizing = index.defaultColumnSizing;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\nexport function useReactTable<TData extends RowData>(\n options: TableOptions<TData>\n) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n tableRef.current.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return tableRef.current\n}\n"],"names":["flexRender","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","useReactTable","options","resolvedOptions","state","onStateChange","renderFallbackValue","tableRef","useState","current","createTable","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AAEO,SAASA,UAAT,CACLC,IADK,EAELC,KAFK,EAG0B;AAC/B,EAAA,OAAO,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAASF,IAAT,CAAhB,gBACpBG,+BAAC,IAAD,EAAUF,KAAV,CADoB,GAGpBD,IAHF,CAAA;AAKD,CAAA;;AAED,SAASE,gBAAT,CACEE,SADF,EAE4C;AAC1C,EAAA,OACEC,gBAAgB,CAACD,SAAD,CAAhB,IACA,OAAOA,SAAP,KAAqB,UADrB,IAEAE,iBAAiB,CAACF,SAAD,CAHnB,CAAA;AAKD,CAAA;;AAED,SAASC,gBAAT,CAA0BD,SAA1B,EAA0C;AACxC,EAAA,OACE,OAAOA,SAAP,KAAqB,UAArB,IACA,CAAC,MAAM;AACL,IAAA,MAAMG,KAAK,GAAGC,MAAM,CAACC,cAAP,CAAsBL,SAAtB,CAAd,CAAA;IACA,OAAOG,KAAK,CAACG,SAAN,IAAmBH,KAAK,CAACG,SAAN,CAAgBR,gBAA1C,CAAA;AACD,GAHD,GAFF,CAAA;AAOD,CAAA;;AAED,SAASI,iBAAT,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\nexport function useReactTable<TData extends RowData>(\n options: TableOptions<TData>\n) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n tableRef.current.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return tableRef.current\n}\n"],"names":["flexRender","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","useReactTable","options","resolvedOptions","state","onStateChange","renderFallbackValue","tableRef","useState","current","createTable","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AAEO,SAASA,UAAT,CACLC,IADK,EAELC,KAFK,EAG0B;AAC/B,EAAA,OAAO,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAASF,IAAT,CAAhB,gBACpBG,+BAAC,IAAD,EAAUF,KAAV,CADoB,GAGpBD,IAHF,CAAA;AAKD,CAAA;;AAED,SAASE,gBAAT,CACEE,SADF,EAE4C;AAC1C,EAAA,OACEC,gBAAgB,CAACD,SAAD,CAAhB,IACA,OAAOA,SAAP,KAAqB,UADrB,IAEAE,iBAAiB,CAACF,SAAD,CAHnB,CAAA;AAKD,CAAA;;AAED,SAASC,gBAAT,CAA0BD,SAA1B,EAA0C;AACxC,EAAA,OACE,OAAOA,SAAP,KAAqB,UAArB,IACA,CAAC,MAAM;AACL,IAAA,MAAMG,KAAK,GAAGC,MAAM,CAACC,cAAP,CAAsBL,SAAtB,CAAd,CAAA;IACA,OAAOG,KAAK,CAACG,SAAN,IAAmBH,KAAK,CAACG,SAAN,CAAgBR,gBAA1C,CAAA;AACD,GAHD,GAFF,CAAA;AAOD,CAAA;;AAED,SAASI,iBAAT,CAA2BF,SAA3B,EAA2C;EACzC,OACE,OAAOA,SAAP,KAAqB,QAArB,IACA,OAAOA,SAAS,CAACO,QAAjB,KAA8B,QAD9B,IAEA,CAAC,YAAD,EAAe,mBAAf,CAAA,CAAoCC,QAApC,CAA6CR,SAAS,CAACO,QAAV,CAAmBE,WAAhE,CAHF,CAAA;AAKD,CAAA;;AAEM,SAASC,aAAT,CACLC,OADK,EAEL;AACA;AACA,EAAA,MAAMC,eAA4C,GAAG;AACnDC,IAAAA,KAAK,EAAE,EAD4C;AACxC;IACXC,aAAa,EAAE,MAAM,EAF8B;AAE1B;AACzBC,IAAAA,mBAAmB,EAAE,IAH8B;IAInD,GAAGJ,OAAAA;AAJgD,GAArD,CAFA;;AAUA,EAAA,MAAM,CAACK,QAAD,CAAA,GAAajB,gBAAK,CAACkB,QAAN,CAAe,OAAO;IACvCC,OAAO,EAAEC,iBAAW,CAAQP,eAAR,CAAA;GADY,CAAf,CAAnB,CAVA;;AAeA,EAAA,MAAM,CAACC,KAAD,EAAQO,QAAR,CAAA,GAAoBrB,gBAAK,CAACkB,QAAN,CAAe,MAAMD,QAAQ,CAACE,OAAT,CAAiBG,YAAtC,CAA1B,CAfA;AAkBA;;EACAL,QAAQ,CAACE,OAAT,CAAiBI,UAAjB,CAA4BC,IAAI,KAAK,EACnC,GAAGA,IADgC;AAEnC,IAAA,GAAGZ,OAFgC;IAGnCE,KAAK,EAAE,EACL,GAAGA,KADE;AAEL,MAAA,GAAGF,OAAO,CAACE,KAAAA;KALsB;AAOnC;AACA;IACAC,aAAa,EAAEU,OAAO,IAAI;MACxBJ,QAAQ,CAACI,OAAD,CAAR,CAAA;AACAb,MAAAA,OAAO,CAACG,aAAR,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAH,OAAO,CAACG,aAAR,CAAwBU,OAAxB,CAAA,CAAA;AACD,KAAA;AAZkC,GAAL,CAAhC,CAAA,CAAA;EAeA,OAAOR,QAAQ,CAACE,OAAhB,CAAA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -22,6 +22,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
22
22
  *
23
23
  * @license MIT
24
24
  */
25
+ // Is this type a tuple?
26
+ // If this type is a tuple, what indices are allowed?
27
+ ///
25
28
  function functionalUpdate(updater, input) {
26
29
  return typeof updater === 'function' ? updater(input) : updater;
27
30
  }
@@ -107,13 +110,27 @@ function createColumn(table, columnDef, depth, parent) {
107
110
  const resolvedColumnDef = { ...defaultColumn,
108
111
  ...columnDef
109
112
  };
110
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : resolvedColumnDef.accessorKey) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
113
+ const accessorKey = resolvedColumnDef.accessorKey;
114
+ let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
111
115
  let accessorFn;
112
116
 
113
117
  if (resolvedColumnDef.accessorFn) {
114
118
  accessorFn = resolvedColumnDef.accessorFn;
115
- } else if (resolvedColumnDef.accessorKey) {
116
- accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
119
+ } else if (accessorKey) {
120
+ // Support deep accessor keys
121
+ if (accessorKey.includes('.')) {
122
+ accessorFn = originalRow => {
123
+ let result = originalRow;
124
+
125
+ for (const key of accessorKey.split('.')) {
126
+ result = result[key];
127
+ }
128
+
129
+ return result;
130
+ };
131
+ } else {
132
+ accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
133
+ }
117
134
  }
118
135
 
119
136
  if (!id) {
@@ -1109,7 +1126,7 @@ const Filters = {
1109
1126
  var _table$getCoreRowMode, _table$getCoreRowMode2;
1110
1127
 
1111
1128
  const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null ? void 0 : (_table$getCoreRowMode2 = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode2.getValue();
1112
- return typeof value === 'string';
1129
+ return typeof value === 'string' || typeof value === 'number';
1113
1130
  }
1114
1131
  };
1115
1132
  },
@@ -2141,7 +2158,7 @@ const RowSelection = {
2141
2158
  let isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
2142
2159
 
2143
2160
  if (isAllRowsSelected) {
2144
- if (preFilteredFlatRows.some(row => !rowSelection[row.id])) {
2161
+ if (preFilteredFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
2145
2162
  isAllRowsSelected = false;
2146
2163
  }
2147
2164
  }
@@ -2164,7 +2181,8 @@ const RowSelection = {
2164
2181
  getIsSomeRowsSelected: () => {
2165
2182
  var _table$getState$rowSe;
2166
2183
 
2167
- return !table.getIsAllRowsSelected() && !!Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2184
+ const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2185
+ return totalSelected < table.getCoreRowModel().flatRows.length;
2168
2186
  },
2169
2187
  getIsSomePageRowsSelected: () => {
2170
2188
  const paginationFlatRows = table.getPaginationRowModel().flatRows;
@@ -3103,6 +3121,52 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
3103
3121
  return row;
3104
3122
  };
3105
3123
 
3124
+ // type Person = {
3125
+ // firstName: string
3126
+ // lastName: string
3127
+ // age: number
3128
+ // visits: number
3129
+ // status: string
3130
+ // progress: number
3131
+ // nested: {
3132
+ // foo: [
3133
+ // {
3134
+ // bar: 'bar'
3135
+ // }
3136
+ // ]
3137
+ // bar: { subBar: boolean }[]
3138
+ // baz: {
3139
+ // foo: 'foo'
3140
+ // bar: {
3141
+ // baz: 'baz'
3142
+ // }
3143
+ // }
3144
+ // }
3145
+ // }
3146
+ // const test: DeepKeys<Person> = 'nested.foo.0.bar'
3147
+ // const test2: DeepKeys<Person> = 'nested.bar'
3148
+ // const helper = createColumnHelper<Person>()
3149
+ // helper.accessor('nested.foo', {
3150
+ // cell: info => info.getValue(),
3151
+ // })
3152
+ // helper.accessor('nested.foo.0.bar', {
3153
+ // cell: info => info.getValue(),
3154
+ // })
3155
+ // helper.accessor('nested.bar', {
3156
+ // cell: info => info.getValue(),
3157
+ // })
3158
+ function createColumnHelper() {
3159
+ return {
3160
+ accessor: (accessor, column) => {
3161
+ return typeof accessor === 'function' ? { ...column,
3162
+ accessorFn: accessor
3163
+ } : { ...column,
3164
+ accessorKey: accessor
3165
+ };
3166
+ }
3167
+ };
3168
+ }
3169
+
3106
3170
  function getCoreRowModel() {
3107
3171
  return table => memo(() => [table.options.data], data => {
3108
3172
  const rowModel = {
@@ -3812,6 +3876,7 @@ exports.Visibility = Visibility;
3812
3876
  exports.aggregationFns = aggregationFns;
3813
3877
  exports.buildHeaderGroups = buildHeaderGroups;
3814
3878
  exports.createColumn = createColumn;
3879
+ exports.createColumnHelper = createColumnHelper;
3815
3880
  exports.createRow = createRow;
3816
3881
  exports.createTable = createTable;
3817
3882
  exports.defaultColumnSizing = defaultColumnSizing;