@tanstack/table-core 8.0.0-alpha.85 → 8.0.0-alpha.88

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.
Files changed (40) hide show
  1. package/build/cjs/core/cell.js +9 -7
  2. package/build/cjs/core/cell.js.map +1 -1
  3. package/build/cjs/core/column.js +1 -1
  4. package/build/cjs/core/column.js.map +1 -1
  5. package/build/cjs/features/Expanding.js +6 -3
  6. package/build/cjs/features/Expanding.js.map +1 -1
  7. package/build/cjs/features/Sorting.js.map +1 -1
  8. package/build/cjs/features/Visibility.js +2 -7
  9. package/build/cjs/features/Visibility.js.map +1 -1
  10. package/build/cjs/sortingFns.js +53 -51
  11. package/build/cjs/sortingFns.js.map +1 -1
  12. package/build/cjs/utils/getCoreRowModel.js +4 -8
  13. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  14. package/build/cjs/utils/getExpandedRowModel.js +2 -2
  15. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  16. package/build/cjs/utils/getPaginationRowModel.js +1 -1
  17. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  18. package/build/esm/index.js +78 -80
  19. package/build/esm/index.js.map +1 -1
  20. package/build/stats-html.html +1 -1
  21. package/build/stats-react.json +322 -322
  22. package/build/types/features/Expanding.d.ts +0 -1
  23. package/build/types/features/Sorting.d.ts +3 -3
  24. package/build/types/features/Visibility.d.ts +5 -6
  25. package/build/types/index.d.ts +0 -2
  26. package/build/types/sortingFns.d.ts +7 -14
  27. package/build/umd/index.development.js +78 -80
  28. package/build/umd/index.development.js.map +1 -1
  29. package/build/umd/index.production.js +1 -1
  30. package/build/umd/index.production.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/core/cell.ts +4 -3
  33. package/src/core/column.ts +0 -1
  34. package/src/features/Expanding.ts +6 -4
  35. package/src/features/Sorting.ts +4 -4
  36. package/src/features/Visibility.ts +10 -25
  37. package/src/index.ts +0 -2
  38. package/src/sortingFns.ts +59 -81
  39. package/src/utils/getCoreRowModel.ts +8 -11
  40. package/src/utils/getExpandedRowModel.ts +1 -5
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.85",
5
- "description": "Hooks for building lightweight, fast and extendable datagrids for React",
4
+ "version": "8.0.0-alpha.88",
5
+ "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/tanstack/react-table#readme",
7
+ "homepage": "https://github.com/tanstack/table#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/tanstack/react-table.git"
10
+ "url": "git+https://github.com/tanstack/table.git"
11
11
  },
12
12
  "publishConfig": {
13
13
  "registry": "https://registry.npmjs.org/"
package/src/core/cell.ts CHANGED
@@ -19,8 +19,8 @@ export function createCell<TGenerics extends TableGenerics>(
19
19
  row,
20
20
  column,
21
21
  getValue: () => row.getValue(columnId),
22
- renderCell: () =>
23
- column.columnDef.cell
22
+ renderCell: () => {
23
+ return column.columnDef.cell
24
24
  ? instance._render(column.columnDef.cell, {
25
25
  instance,
26
26
  column,
@@ -28,7 +28,8 @@ export function createCell<TGenerics extends TableGenerics>(
28
28
  cell: cell as Cell<TGenerics>,
29
29
  getValue: cell.getValue,
30
30
  })
31
- : null,
31
+ : null
32
+ },
32
33
  }
33
34
 
34
35
  instance._features.forEach(feature => {
@@ -98,7 +98,6 @@ export function createColumn<TGenerics extends TableGenerics>(
98
98
  }
99
99
 
100
100
  let column: CoreColumn<TGenerics> = {
101
- ...columnDef,
102
101
  id: `${id}`,
103
102
  accessorFn,
104
103
  parent: parent as any,
@@ -30,7 +30,6 @@ export type ExpandedOptions<TGenerics extends TableGenerics> = {
30
30
  getExpandedRowModel?: (
31
31
  instance: TableInstance<TGenerics>
32
32
  ) => () => RowModel<TGenerics>
33
- expandSubRows?: boolean
34
33
  getIsRowExpanded?: (row: Row<TGenerics>) => boolean
35
34
  getRowCanExpand?: (row: Row<TGenerics>) => boolean
36
35
  paginateExpandedRows?: boolean
@@ -67,7 +66,6 @@ export const Expanding: TableFeature = {
67
66
  return {
68
67
  onExpandedChange: makeStateUpdater('expanded', instance),
69
68
  autoResetExpanded: true,
70
- expandSubRows: true,
71
69
  paginateExpandedRows: true,
72
70
  }
73
71
  },
@@ -133,8 +131,12 @@ export const Expanding: TableFeature = {
133
131
  const expanded = instance.getState().expanded
134
132
 
135
133
  // If expanded is true, save some cycles and return true
136
- if (expanded === true) {
137
- return true
134
+ if (typeof expanded === 'boolean') {
135
+ return expanded === true
136
+ }
137
+
138
+ if (!Object.keys(expanded).length) {
139
+ return false
138
140
  }
139
141
 
140
142
  // If any row is not expanded, return false
@@ -26,6 +26,10 @@ export type ColumnSort = {
26
26
 
27
27
  export type SortingState = ColumnSort[]
28
28
 
29
+ export type SortingTableState = {
30
+ sorting: SortingState
31
+ }
32
+
29
33
  export type SortingFn<TGenerics extends TableGenerics> = {
30
34
  (rowA: Row<TGenerics>, rowB: Row<TGenerics>, columnId: string): number
31
35
  }
@@ -35,10 +39,6 @@ export type CustomSortingFns<TGenerics extends TableGenerics> = Record<
35
39
  SortingFn<TGenerics>
36
40
  >
37
41
 
38
- export type SortingTableState = {
39
- sorting: SortingState
40
- }
41
-
42
42
  export type SortingFnOption<TGenerics extends TableGenerics> =
43
43
  | 'auto'
44
44
  | BuiltInSortingFn
@@ -10,6 +10,12 @@ import {
10
10
  } from '../types'
11
11
  import { makeStateUpdater, memo } from '../utils'
12
12
 
13
+ export type VisibilityState = Record<string, boolean>
14
+
15
+ export type VisibilityTableState = {
16
+ columnVisibility: VisibilityState
17
+ }
18
+
13
19
  export type VisibilityOptions = {
14
20
  onColumnVisibilityChange?: OnChangeFn<VisibilityState>
15
21
  enableHiding?: boolean
@@ -19,12 +25,6 @@ export type VisibilityDefaultOptions = {
19
25
  onColumnVisibilityChange: OnChangeFn<VisibilityState>
20
26
  }
21
27
 
22
- export type VisibilityState = Record<string, boolean>
23
-
24
- export type VisibilityTableState = {
25
- columnVisibility: VisibilityState
26
- }
27
-
28
28
  export type VisibilityInstance<TGenerics extends TableGenerics> = {
29
29
  getVisibleFlatColumns: () => Column<TGenerics>[]
30
30
  getVisibleLeafColumns: () => Column<TGenerics>[]
@@ -36,14 +36,11 @@ export type VisibilityInstance<TGenerics extends TableGenerics> = {
36
36
  toggleAllColumnsVisible: (value?: boolean) => void
37
37
  getIsAllColumnsVisible: () => boolean
38
38
  getIsSomeColumnsVisible: () => boolean
39
- getToggleAllColumnsVisibilityHandler: () =>
40
- | undefined
41
- | ((event: unknown) => void)
39
+ getToggleAllColumnsVisibilityHandler: () => (event: unknown) => void
42
40
  }
43
41
 
44
42
  export type VisibilityColumnDef = {
45
43
  enableHiding?: boolean
46
- defaultIsVisible?: boolean
47
44
  }
48
45
 
49
46
  export type VisibilityRow<TGenerics extends TableGenerics> = {
@@ -76,12 +73,6 @@ export const Visibility: TableFeature = {
76
73
  }
77
74
  },
78
75
 
79
- getDefaultColumnDef: () => {
80
- return {
81
- defaultIsVisible: true,
82
- }
83
- },
84
-
85
76
  createColumn: <TGenerics extends TableGenerics>(
86
77
  column: Column<TGenerics>,
87
78
  instance: TableInstance<TGenerics>
@@ -121,15 +112,9 @@ export const Visibility: TableFeature = {
121
112
  ): VisibilityRow<TGenerics> => {
122
113
  return {
123
114
  _getAllVisibleCells: memo(
124
- () => [
125
- row
126
- .getAllCells()
127
- .filter(cell => cell.column.getIsVisible())
128
- .map(d => d.id)
129
- .join('_'),
130
- ],
131
- _ => {
132
- return row.getAllCells().filter(cell => cell.column.getIsVisible())
115
+ () => [row.getAllCells(), instance.getState().columnVisibility],
116
+ cells => {
117
+ return cells.filter(cell => cell.column.getIsVisible())
133
118
  },
134
119
  {
135
120
  key:
package/src/index.ts CHANGED
@@ -5,7 +5,6 @@ export * from './core/column'
5
5
  export * from './core/headers'
6
6
  export * from './core/row'
7
7
  export * from './features/ColumnSizing'
8
- export * from './features/ColumnSizing'
9
8
  export * from './features/Expanding'
10
9
  export * from './features/Filters'
11
10
  export * from './features/Grouping'
@@ -15,7 +14,6 @@ export * from './features/Pinning'
15
14
  export * from './features/RowSelection'
16
15
  export * from './features/Sorting'
17
16
  export * from './features/Visibility'
18
- export * from './features/Expanding'
19
17
  export * from './filterFns'
20
18
  export * from './sortingFns'
21
19
  export * from './aggregationFns'
package/src/sortingFns.ts CHANGED
@@ -1,40 +1,69 @@
1
- import { TableGenerics, Row } from './types'
1
+ import { SortingFn } from './features/Sorting'
2
2
 
3
3
  export const reSplitAlphaNumeric = /([0-9]+)/gm
4
4
 
5
- export const sortingFns = {
6
- alphanumeric,
7
- alphanumericCaseSensitive,
8
- text,
9
- textCaseSensitive,
10
- datetime,
11
- basic,
5
+ const alphanumeric: SortingFn<any> = (rowA, rowB, columnId) => {
6
+ return compareAlphanumeric(
7
+ toString(rowA.getValue(columnId)).toLowerCase(),
8
+ toString(rowB.getValue(columnId)).toLowerCase()
9
+ )
12
10
  }
13
11
 
14
- export type BuiltInSortingFn = keyof typeof sortingFns
15
-
16
- function alphanumeric<TGenerics extends TableGenerics>(
17
- rowA: Row<TGenerics>,
18
- rowB: Row<TGenerics>,
19
- columnId: string
20
- ) {
12
+ const alphanumericCaseSensitive: SortingFn<any> = (rowA, rowB, columnId) => {
21
13
  return compareAlphanumeric(
14
+ toString(rowA.getValue(columnId)),
15
+ toString(rowB.getValue(columnId))
16
+ )
17
+ }
18
+
19
+ // The text filter is more basic (less numeric support)
20
+ // but is much faster
21
+ const text: SortingFn<any> = (rowA, rowB, columnId) => {
22
+ return compareBasic(
22
23
  toString(rowA.getValue(columnId)).toLowerCase(),
23
24
  toString(rowB.getValue(columnId)).toLowerCase()
24
25
  )
25
26
  }
26
27
 
27
- function alphanumericCaseSensitive<TGenerics extends TableGenerics>(
28
- rowA: Row<TGenerics>,
29
- rowB: Row<TGenerics>,
30
- columnId: string
31
- ) {
32
- return compareAlphanumeric(
28
+ // The text filter is more basic (less numeric support)
29
+ // but is much faster
30
+ const textCaseSensitive: SortingFn<any> = (rowA, rowB, columnId) => {
31
+ return compareBasic(
33
32
  toString(rowA.getValue(columnId)),
34
33
  toString(rowB.getValue(columnId))
35
34
  )
36
35
  }
37
36
 
37
+ const datetime: SortingFn<any> = (rowA, rowB, columnId) => {
38
+ return compareBasic(
39
+ (rowA.getValue(columnId) as Date).getTime(),
40
+ (rowB.getValue(columnId) as Date).getTime()
41
+ )
42
+ }
43
+
44
+ const basic: SortingFn<any> = (rowA, rowB, columnId) => {
45
+ return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
46
+ }
47
+
48
+ // Utils
49
+
50
+ function compareBasic(a: any, b: any) {
51
+ return a === b ? 0 : a > b ? 1 : -1
52
+ }
53
+
54
+ function toString(a: any) {
55
+ if (typeof a === 'number') {
56
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
57
+ return ''
58
+ }
59
+ return String(a)
60
+ }
61
+ if (typeof a === 'string') {
62
+ return a
63
+ }
64
+ return ''
65
+ }
66
+
38
67
  // Mixed sorting is slow, but very inclusive of many edge cases.
39
68
  // It handles numbers, mixed alphanumeric combinations, and even
40
69
  // null, undefined, and Infinity
@@ -82,66 +111,15 @@ function compareAlphanumeric(aStr: string, bStr: string) {
82
111
  return a.length - b.length
83
112
  }
84
113
 
85
- // The text filter is more basic (less numeric support)
86
- // but is much faster
87
- function text<TGenerics extends TableGenerics>(
88
- rowA: Row<TGenerics>,
89
- rowB: Row<TGenerics>,
90
- columnId: string
91
- ) {
92
- return compareBasic(
93
- toString(rowA.getValue(columnId)).toLowerCase(),
94
- toString(rowB.getValue(columnId)).toLowerCase()
95
- )
96
- }
97
-
98
- // The text filter is more basic (less numeric support)
99
- // but is much faster
100
- function textCaseSensitive<TGenerics extends TableGenerics>(
101
- rowA: Row<TGenerics>,
102
- rowB: Row<TGenerics>,
103
- columnId: string
104
- ) {
105
- return compareBasic(
106
- toString(rowA.getValue(columnId)),
107
- toString(rowB.getValue(columnId))
108
- )
109
- }
110
-
111
- function datetime<TGenerics extends TableGenerics>(
112
- rowA: Row<TGenerics>,
113
- rowB: Row<TGenerics>,
114
- columnId: string
115
- ) {
116
- return compareBasic(
117
- (rowA.getValue(columnId) as Date).getTime(),
118
- (rowB.getValue(columnId) as Date).getTime()
119
- )
120
- }
121
-
122
- function basic<TGenerics extends TableGenerics>(
123
- rowA: Row<TGenerics>,
124
- rowB: Row<TGenerics>,
125
- columnId: string
126
- ) {
127
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
128
- }
129
-
130
- // Utils
114
+ // Exports
131
115
 
132
- function compareBasic(a: any, b: any) {
133
- return a === b ? 0 : a > b ? 1 : -1
116
+ export const sortingFns = {
117
+ alphanumeric,
118
+ alphanumericCaseSensitive,
119
+ text,
120
+ textCaseSensitive,
121
+ datetime,
122
+ basic,
134
123
  }
135
124
 
136
- function toString(a: any) {
137
- if (typeof a === 'number') {
138
- if (isNaN(a) || a === Infinity || a === -Infinity) {
139
- return ''
140
- }
141
- return String(a)
142
- }
143
- if (typeof a === 'string') {
144
- return a
145
- }
146
- return ''
147
- }
125
+ export type BuiltInSortingFn = keyof typeof sortingFns
@@ -21,20 +21,14 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
21
21
  rowsById: {},
22
22
  }
23
23
 
24
- let rows
25
- let row
26
- let originalRow
27
-
28
24
  const accessRows = (
29
25
  originalRows: TGenerics['Row'][],
30
26
  depth = 0,
31
27
  parent?: Row<TGenerics>
32
28
  ): Row<TGenerics>[] => {
33
- rows = []
29
+ const rows = [] as Row<TGenerics>[]
34
30
 
35
31
  for (let i = 0; i < originalRows.length; i++) {
36
- originalRow = originalRows[i]
37
-
38
32
  // This could be an expensive check at scale, so we should move it somewhere else, but where?
39
33
  // if (!id) {
40
34
  // if (process.env.NODE_ENV !== 'production') {
@@ -43,10 +37,10 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
43
37
  // }
44
38
 
45
39
  // Make the row
46
- row = createRow(
40
+ const row = createRow(
47
41
  instance,
48
- instance._getRowId(originalRow, i, parent),
49
- originalRow,
42
+ instance._getRowId(originalRows[i], i, parent),
43
+ originalRows[i],
50
44
  i,
51
45
  depth
52
46
  )
@@ -60,7 +54,10 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
60
54
 
61
55
  // Get the original subrows
62
56
  if (instance.options.getSubRows) {
63
- row.originalSubRows = instance.options.getSubRows(originalRow, i)
57
+ row.originalSubRows = instance.options.getSubRows(
58
+ originalRows[i],
59
+ i
60
+ )
64
61
 
65
62
  // Then recursively access them
66
63
  if (row.originalSubRows?.length) {
@@ -39,11 +39,7 @@ export function expandRows<TGenerics extends TableGenerics>(
39
39
  const handleRow = (row: Row<TGenerics>) => {
40
40
  expandedRows.push(row)
41
41
 
42
- if (
43
- instance.options.expandSubRows &&
44
- row.subRows?.length &&
45
- row.getIsExpanded()
46
- ) {
42
+ if (row.subRows?.length && row.getIsExpanded()) {
47
43
  row.subRows.forEach(handleRow)
48
44
  }
49
45
  }