@tanstack/react-table 8.0.0-beta.8 → 8.0.3

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.
@@ -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 createTableInstance,\n TableOptions,\n TableInstance,\n Table,\n TableGenerics,\n createTableFactory,\n Overwrite,\n PartialKeys,\n TableOptionsResolved,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> =\n | React.ReactNode\n | React.FunctionComponent<TProps>\n | React.Component<TProps>\n\nexport type Render = <TProps extends {}>(\n Comp: Renderable<TProps>,\n props: TProps\n) => React.ReactNode | JSX.Element\n\nexport type ReactTableGenerics = Overwrite<\n TableGenerics,\n { Renderer: Render; Rendered: ReturnType<Render> }\n>\n\n//\n\nexport const render: Render = (Comp, props) =>\n !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp\n\nfunction isReactComponent(component: unknown): component is React.FC {\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 const createTable = createTableFactory({ render })\n\n// const useIsomorphicLayoutEffect =\n// typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type UseTableInstanceOptions<TGenerics extends ReactTableGenerics> =\n TableOptions<TGenerics>\n\nexport function useTableInstance<TGenerics extends ReactTableGenerics>(\n table: Table<TGenerics>,\n options: UseTableInstanceOptions<TGenerics>\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TGenerics> = {\n ...table.options,\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n render,\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table instance and store it in state\n const [instanceRef] = React.useState(() => ({\n current: createTableInstance<TGenerics>(resolvedOptions),\n }))\n\n // By default, manage table state here using the instance's initial state\n const [state, setState] = React.useState(\n () => instanceRef.current.initialState\n )\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 instanceRef.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 instanceRef.current\n}\n"],"names":["render","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","createTable","createTableFactory","useTableInstance","table","options","resolvedOptions","state","onStateChange","renderFallbackValue","instanceRef","useState","current","createTableInstance","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA;AAEO,MAAMA,MAAc,GAAG,CAACC,IAAD,EAAOC,KAAP,KAC5B,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAACF,IAAD,CAAhB,gBAAyBG,gBAAA,CAAA,aAAA,CAAC,IAAD,EAAUF,KAAV,CAAzB,GAA+CD,KADzD;;AAGP,SAASE,gBAAT,CAA0BE,SAA1B,EAAqE;AACnE,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,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FmC;AAGtCE,IAAAA,KAAK,EAAE,EACL,GAAGA,KADE;AAEL,MAAA,GAAGF,OAAO,CAACE,KAAAA;AAFN,KAH+B;AAOtC;AACA;AACAC,IAAAA,aAAa,EAAEU,OAAO,IAAI;AACxBJ,MAAAA,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;AAZqC,GAAL,CAAnC,CAAA,CAAA;AAeA,EAAOR,OAAAA,WAAW,CAACE,OAAnB,CAAA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n createTableInstance,\n TableOptions,\n TableInstance,\n Table,\n TableGenerics,\n createTableFactory,\n Overwrite,\n PartialKeys,\n TableOptionsResolved,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> =\n | React.ReactNode\n | React.FunctionComponent<TProps>\n | React.Component<TProps>\n\nexport type Render = <TProps extends {}>(\n Comp: Renderable<TProps>,\n props: TProps\n) => React.ReactNode | JSX.Element\n\nexport type ReactTableGenerics = Overwrite<\n TableGenerics,\n { Renderer: Render; Rendered: ReturnType<Render> }\n>\n\n//\n\nexport const render: Render = (Comp, props) =>\n !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp\n\nfunction isReactComponent(component: unknown): component is React.FC {\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 const createTable = createTableFactory({ render })\n\n// const useIsomorphicLayoutEffect =\n// typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type UseTableInstanceOptions<TGenerics extends ReactTableGenerics> =\n TableOptions<TGenerics>\n\nexport function useTableInstance<TGenerics extends ReactTableGenerics>(\n table: Table<TGenerics>,\n options: UseTableInstanceOptions<TGenerics>\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TGenerics> = {\n ...table.options,\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n render,\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table instance and store it in state\n const [instanceRef] = React.useState(() => ({\n current: createTableInstance<TGenerics>(resolvedOptions),\n }))\n\n // By default, manage table state here using the instance's initial state\n const [state, setState] = React.useState(\n () => instanceRef.current.initialState\n )\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 instanceRef.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 instanceRef.current\n}\n"],"names":["render","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","createTable","createTableFactory","useTableInstance","table","options","resolvedOptions","state","onStateChange","renderFallbackValue","instanceRef","useState","current","createTableInstance","setState","initialState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA;AAEO,MAAMA,MAAc,GAAG,CAACC,IAAD,EAAOC,KAAP,KAC5B,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAACF,IAAD,CAAhB,gBAAyBG,gBAAA,CAAA,aAAA,CAAC,IAAD,EAAUF,KAAV,CAAzB,GAA+CD,KADz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,CAAf,CAAtB,CAZ0B;;AAiB1B,EAAA,MAAM,CAACC,KAAD,EAAQO,QAAR,CAAA,GAAoBxB,gBAAK,CAACqB,QAAN,CACxB,MAAMD,WAAW,CAACE,OAAZ,CAAoBG,YADF,CAA1B,CAjB0B;AAsB1B;;EACAL,WAAW,CAACE,OAAZ,CAAoBI,UAApB,CAA+BC,IAAI,KAAK,EACtC,GAAGA,IADmC;AAEtC,IAAA,GAAGZ,OAFmC;IAGtCE,KAAK,EAAE,EACL,GAAGA,KADE;AAEL,MAAA,GAAGF,OAAO,CAACE,KAAAA;KALyB;AAOtC;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;AAZqC,GAAL,CAAnC,CAAA,CAAA;EAeA,OAAOR,WAAW,CAACE,OAAnB,CAAA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -983,38 +983,54 @@ const Expanding = {
983
983
  };
984
984
 
985
985
  const includesString = (row, columnId, filterValue) => {
986
+ var _row$getValue;
987
+
986
988
  const search = filterValue.toLowerCase();
987
- return row.getValue(columnId).toLowerCase().includes(search);
989
+ return (_row$getValue = row.getValue(columnId)) == null ? void 0 : _row$getValue.toLowerCase().includes(search);
988
990
  };
989
991
 
990
992
  includesString.autoRemove = val => testFalsey(val);
991
993
 
992
994
  const includesStringSensitive = (row, columnId, filterValue) => {
993
- return row.getValue(columnId).includes(filterValue);
995
+ var _row$getValue2;
996
+
997
+ return (_row$getValue2 = row.getValue(columnId)) == null ? void 0 : _row$getValue2.includes(filterValue);
994
998
  };
995
999
 
996
1000
  includesStringSensitive.autoRemove = val => testFalsey(val);
997
1001
 
998
1002
  const equalsString = (row, columnId, filterValue) => {
999
- return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase();
1003
+ var _row$getValue3;
1004
+
1005
+ return ((_row$getValue3 = row.getValue(columnId)) == null ? void 0 : _row$getValue3.toLowerCase()) === filterValue.toLowerCase();
1000
1006
  };
1001
1007
 
1002
1008
  equalsString.autoRemove = val => testFalsey(val);
1003
1009
 
1004
1010
  const arrIncludes = (row, columnId, filterValue) => {
1005
- return row.getValue(columnId).includes(filterValue);
1011
+ var _row$getValue4;
1012
+
1013
+ return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
1006
1014
  };
1007
1015
 
1008
1016
  arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
1009
1017
 
1010
1018
  const arrIncludesAll = (row, columnId, filterValue) => {
1011
- return !filterValue.some(val => !row.getValue(columnId).includes(val));
1019
+ return !filterValue.some(val => {
1020
+ var _row$getValue5;
1021
+
1022
+ return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
1023
+ });
1012
1024
  };
1013
1025
 
1014
1026
  arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
1015
1027
 
1016
1028
  const arrIncludesSome = (row, columnId, filterValue) => {
1017
- return filterValue.some(val => row.getValue(columnId).includes(val));
1029
+ return filterValue.some(val => {
1030
+ var _row$getValue6;
1031
+
1032
+ return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
1033
+ });
1018
1034
  };
1019
1035
 
1020
1036
  arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
@@ -1319,7 +1335,10 @@ function shouldAutoRemoveFilter(filterFn, value, column) {
1319
1335
  const sum = (columnId, _leafRows, childRows) => {
1320
1336
  // It's faster to just add the aggregations together instead of
1321
1337
  // process leaf nodes individually
1322
- return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1338
+ return childRows.reduce((sum, next) => {
1339
+ const nextValue = next.getValue(columnId);
1340
+ return sum + (typeof nextValue === 'number' ? nextValue : 0);
1341
+ }, 0);
1323
1342
  };
1324
1343
 
1325
1344
  const min = (columnId, _leafRows, childRows) => {
@@ -1699,7 +1718,7 @@ const Pagination = {
1699
1718
  setPageIndex: updater => {
1700
1719
  instance.setPagination(old => {
1701
1720
  let pageIndex = functionalUpdate(updater, old.pageIndex);
1702
- const maxPageIndex = typeof instance.options.pageCount !== 'undefined' ? instance.options.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1721
+ const maxPageIndex = typeof instance.options.pageCount === 'undefined' || instance.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : instance.options.pageCount - 1;
1703
1722
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
1704
1723
  return { ...old,
1705
1724
  pageIndex
@@ -2292,9 +2311,6 @@ function selectRowsFn(instance, rowModel) {
2292
2311
  const newSelectedRowsById = {}; // Filters top level and nested rows
2293
2312
 
2294
2313
  const recurseRows = function (rows, depth) {
2295
- if (depth === void 0) {
2296
- depth = 0;
2297
- }
2298
2314
 
2299
2315
  return rows.map(row => {
2300
2316
  var _row$subRows2;
@@ -2308,7 +2324,7 @@ function selectRowsFn(instance, rowModel) {
2308
2324
 
2309
2325
  if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2310
2326
  row = { ...row,
2311
- subRows: recurseRows(row.subRows, depth + 1)
2327
+ subRows: recurseRows(row.subRows)
2312
2328
  };
2313
2329
  }
2314
2330
 
@@ -3231,25 +3247,20 @@ function filterRows(rows, filterRowImpl, instance) {
3231
3247
  function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
3232
3248
  const newFilteredFlatRows = [];
3233
3249
  const newFilteredRowsById = {};
3234
- let row;
3235
- let newRow;
3236
3250
 
3237
3251
  const recurseFilterRows = function (rowsToFilter, depth) {
3238
- if (depth === void 0) {
3239
- depth = 0;
3240
- }
3241
3252
 
3242
3253
  const rows = []; // Filter from children up first
3243
3254
 
3244
3255
  for (let i = 0; i < rowsToFilter.length; i++) {
3245
3256
  var _row$subRows;
3246
3257
 
3247
- row = rowsToFilter[i];
3258
+ let row = rowsToFilter[i];
3248
3259
 
3249
3260
  if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3250
- newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3261
+ const newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3251
3262
  newRow.columnFilters = row.columnFilters;
3252
- newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3263
+ newRow.subRows = recurseFilterRows(row.subRows);
3253
3264
 
3254
3265
  if (!newRow.subRows.length) {
3255
3266
  continue;
@@ -3276,29 +3287,23 @@ function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
3276
3287
  }
3277
3288
  function filterRowModelFromRoot(rowsToFilter, filterRow, instance) {
3278
3289
  const newFilteredFlatRows = [];
3279
- const newFilteredRowsById = {};
3280
- let rows;
3281
- let row;
3282
- let newRow; // Filters top level and nested rows
3290
+ const newFilteredRowsById = {}; // Filters top level and nested rows
3283
3291
 
3284
3292
  const recurseFilterRows = function (rowsToFilter, depth) {
3285
- if (depth === void 0) {
3286
- depth = 0;
3287
- }
3288
3293
 
3289
3294
  // Filter from parents downward first
3290
- rows = []; // Apply the filter to any subRows
3295
+ const rows = []; // Apply the filter to any subRows
3291
3296
 
3292
3297
  for (let i = 0; i < rowsToFilter.length; i++) {
3293
- row = rowsToFilter[i];
3298
+ let row = rowsToFilter[i];
3294
3299
  const pass = filterRow(row);
3295
3300
 
3296
3301
  if (pass) {
3297
3302
  var _row$subRows2;
3298
3303
 
3299
3304
  if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
3300
- newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3301
- newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3305
+ const newRow = createRow(instance, row.id, row.original, row.index, row.depth);
3306
+ newRow.subRows = recurseFilterRows(row.subRows);
3302
3307
  row = newRow;
3303
3308
  }
3304
3309