@tanstack/react-table 0.0.1-alpha.9 → 8.0.0-alpha.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.
Files changed (129) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +112 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/aggregationTypes.js +130 -0
  4. package/build/cjs/aggregationTypes.js.map +1 -0
  5. package/build/cjs/core.js +552 -0
  6. package/build/cjs/core.js.map +1 -0
  7. package/build/cjs/createTable.js +108 -0
  8. package/build/cjs/createTable.js.map +1 -0
  9. package/build/cjs/features/ColumnSizing.js +317 -0
  10. package/build/cjs/features/ColumnSizing.js.map +1 -0
  11. package/build/cjs/features/Expanding.js +255 -0
  12. package/build/cjs/features/Expanding.js.map +1 -0
  13. package/build/cjs/features/Filters.js +445 -0
  14. package/build/cjs/features/Filters.js.map +1 -0
  15. package/build/cjs/features/Grouping.js +249 -0
  16. package/build/cjs/features/Grouping.js.map +1 -0
  17. package/build/cjs/features/Headers.js +549 -0
  18. package/build/cjs/features/Headers.js.map +1 -0
  19. package/build/cjs/features/Ordering.js +86 -0
  20. package/build/cjs/features/Ordering.js.map +1 -0
  21. package/build/cjs/features/Pagination.js +194 -0
  22. package/build/cjs/features/Pagination.js.map +1 -0
  23. package/build/cjs/features/Pinning.js +149 -0
  24. package/build/cjs/features/Pinning.js.map +1 -0
  25. package/build/cjs/features/RowSelection.js +541 -0
  26. package/build/cjs/features/RowSelection.js.map +1 -0
  27. package/build/cjs/features/Sorting.js +327 -0
  28. package/build/cjs/features/Sorting.js.map +1 -0
  29. package/build/cjs/features/Visibility.js +166 -0
  30. package/build/cjs/features/Visibility.js.map +1 -0
  31. package/build/cjs/filterTypes.js +172 -0
  32. package/build/cjs/filterTypes.js.map +1 -0
  33. package/build/cjs/index.js +30 -0
  34. package/build/cjs/index.js.map +1 -0
  35. package/build/cjs/sortTypes.js +122 -0
  36. package/build/cjs/sortTypes.js.map +1 -0
  37. package/build/cjs/utils/columnFilterRowsFn.js +131 -0
  38. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
  39. package/build/cjs/utils/expandRowsFn.js +38 -0
  40. package/build/cjs/utils/expandRowsFn.js.map +1 -0
  41. package/build/cjs/utils/globalFilterRowsFn.js +101 -0
  42. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
  43. package/build/cjs/utils/groupRowsFn.js +155 -0
  44. package/build/cjs/utils/groupRowsFn.js.map +1 -0
  45. package/build/cjs/utils/sortRowsFn.js +94 -0
  46. package/build/cjs/utils/sortRowsFn.js.map +1 -0
  47. package/build/cjs/utils.js +146 -0
  48. package/build/cjs/utils.js.map +1 -0
  49. package/build/esm/index.js +4747 -0
  50. package/build/esm/index.js.map +1 -0
  51. package/build/stats-html.html +2689 -0
  52. package/build/stats-react.json +817 -0
  53. package/build/types/aggregationTypes.d.ts +22 -0
  54. package/build/types/core.d.ts +111 -0
  55. package/build/types/createTable.d.ts +53 -0
  56. package/build/types/features/ColumnSizing.d.ts +67 -0
  57. package/build/types/features/Expanding.d.ts +53 -0
  58. package/build/types/features/Filters.d.ts +98 -0
  59. package/build/types/features/Grouping.d.ts +82 -0
  60. package/build/types/features/Headers.d.ts +41 -0
  61. package/build/types/features/Ordering.d.ts +19 -0
  62. package/build/types/features/Pagination.d.ts +43 -0
  63. package/build/types/features/Pinning.d.ts +39 -0
  64. package/build/types/features/RowSelection.d.ts +66 -0
  65. package/build/types/features/Sorting.d.ts +78 -0
  66. package/build/types/features/Visibility.d.ts +47 -0
  67. package/build/types/filterTypes.d.ts +50 -0
  68. package/build/types/index.d.ts +7 -0
  69. package/build/types/sortTypes.d.ts +18 -0
  70. package/build/types/types.d.ts +127 -0
  71. package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
  72. package/build/types/utils/expandRowsFn.d.ts +2 -0
  73. package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
  74. package/build/types/utils/groupRowsFn.d.ts +2 -0
  75. package/build/types/utils/paginateRowsFn.d.ts +2 -0
  76. package/build/types/utils/sortRowsFn.d.ts +2 -0
  77. package/build/types/utils.d.ts +28 -0
  78. package/{dist/react-table.development.js → build/umd/index.development.js} +1617 -249
  79. package/build/umd/index.development.js.map +1 -0
  80. package/build/umd/index.production.js +12 -0
  81. package/build/umd/index.production.js.map +1 -0
  82. package/package.json +9 -94
  83. package/src/core.tsx +252 -264
  84. package/src/createTable.tsx +69 -9
  85. package/src/features/ColumnSizing.ts +453 -0
  86. package/src/features/Expanding.ts +27 -11
  87. package/src/features/Filters.ts +75 -20
  88. package/src/features/Grouping.ts +27 -12
  89. package/src/features/Headers.ts +55 -50
  90. package/src/features/Ordering.ts +2 -3
  91. package/src/features/Pagination.ts +314 -0
  92. package/src/features/Pinning.ts +3 -16
  93. package/src/features/RowSelection.ts +831 -0
  94. package/src/features/Sorting.ts +82 -22
  95. package/src/features/Visibility.ts +2 -4
  96. package/src/sortTypes.ts +1 -1
  97. package/src/types.ts +55 -9
  98. package/src/utils/columnFilterRowsFn.ts +5 -12
  99. package/src/utils/expandRowsFn.ts +2 -5
  100. package/src/utils/globalFilterRowsFn.ts +3 -10
  101. package/src/utils/groupRowsFn.ts +3 -5
  102. package/src/utils/paginateRowsFn.ts +34 -0
  103. package/src/utils/sortRowsFn.ts +5 -5
  104. package/src/utils.tsx +20 -6
  105. package/dist/react-table.development.js.map +0 -1
  106. package/dist/react-table.production.min.js +0 -2
  107. package/dist/react-table.production.min.js.map +0 -1
  108. package/lib/index.js +0 -65
  109. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  110. package/src/features/notest/useBlockLayout.test.js +0 -158
  111. package/src/features/notest/useColumnOrder.test.js +0 -186
  112. package/src/features/notest/useExpanded.test.js +0 -125
  113. package/src/features/notest/useFilters.test.js +0 -393
  114. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  115. package/src/features/notest/useFlexLayout.test.js +0 -152
  116. package/src/features/notest/useGroupBy.test.js +0 -259
  117. package/src/features/notest/usePagination.test.js +0 -231
  118. package/src/features/notest/useResizeColumns.test.js +0 -229
  119. package/src/features/notest/useRowSelect.test.js +0 -250
  120. package/src/features/notest/useRowState.test.js +0 -178
  121. package/src/features/tests/Visibility.test.tsx +0 -225
  122. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  123. package/src/features/tests/withSorting.notest.tsx +0 -341
  124. package/src/features/withColumnResizing.ts +0 -281
  125. package/src/features/withPagination.ts +0 -208
  126. package/src/features/withRowSelection.ts +0 -467
  127. package/src/test-utils/makeTestData.ts +0 -41
  128. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  129. package/src/tests/core.test.tsx +0 -241
@@ -1,148 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`core renders a table with markup 1`] = `
4
- [
5
- [
6
- [
7
- "Name",
8
- "2",
9
- ],
10
- [
11
- "Info",
12
- "4",
13
- ],
14
- ],
15
- [
16
- [
17
- "",
18
- "1",
19
- ],
20
- [
21
- "",
22
- "1",
23
- ],
24
- [
25
- "",
26
- "1",
27
- ],
28
- [
29
- "More Info",
30
- "3",
31
- ],
32
- ],
33
- [
34
- [
35
- "firstName",
36
- "1",
37
- ],
38
- [
39
- "<span>Last Name</span>",
40
- "1",
41
- ],
42
- [
43
- "Age",
44
- "1",
45
- ],
46
- [
47
- "<span>Visits</span>",
48
- "1",
49
- ],
50
- [
51
- "Status",
52
- "1",
53
- ],
54
- [
55
- "Profile Progress",
56
- "1",
57
- ],
58
- ],
59
- ]
60
- `;
61
-
62
- exports[`core renders a table with markup 2`] = `
63
- [
64
- [
65
- "tanner",
66
- "linsley",
67
- "29",
68
- "100",
69
- "In Relationship",
70
- "50",
71
- ],
72
- [
73
- "derek",
74
- "perkins",
75
- "40",
76
- "40",
77
- "Single",
78
- "80",
79
- ],
80
- [
81
- "joe",
82
- "bergevin",
83
- "45",
84
- "20",
85
- "Complicated",
86
- "10",
87
- ],
88
- ]
89
- `;
90
-
91
- exports[`core renders a table with markup 3`] = `
92
- [
93
- [
94
- [
95
- "firstName",
96
- "1",
97
- ],
98
- [
99
- "lastName",
100
- "1",
101
- ],
102
- [
103
- "age",
104
- "1",
105
- ],
106
- [
107
- "visits",
108
- "1",
109
- ],
110
- [
111
- "status",
112
- "1",
113
- ],
114
- [
115
- "progress",
116
- "1",
117
- ],
118
- ],
119
- [
120
- [
121
- "",
122
- "1",
123
- ],
124
- [
125
- "",
126
- "1",
127
- ],
128
- [
129
- "",
130
- "1",
131
- ],
132
- [
133
- "More Info",
134
- "3",
135
- ],
136
- ],
137
- [
138
- [
139
- "Name",
140
- "2",
141
- ],
142
- [
143
- "Info",
144
- "4",
145
- ],
146
- ],
147
- ]
148
- `;
@@ -1,241 +0,0 @@
1
- import * as React from 'react'
2
-
3
- // import { renderHook } from '@testing-library/react-hooks'
4
- import * as RTL from '@testing-library/react'
5
- import { createTable } from 'react-table'
6
- import { act, renderHook } from '@testing-library/react-hooks'
7
-
8
- type Row = {
9
- firstName: string
10
- lastName: string
11
- age: number
12
- visits: number
13
- status: string
14
- progress: number
15
- }
16
-
17
- const table = createTable().RowType<Row>()
18
-
19
- const defaultData: Row[] = [
20
- {
21
- firstName: 'tanner',
22
- lastName: 'linsley',
23
- age: 29,
24
- visits: 100,
25
- status: 'In Relationship',
26
- progress: 50,
27
- },
28
- {
29
- firstName: 'derek',
30
- lastName: 'perkins',
31
- age: 40,
32
- visits: 40,
33
- status: 'Single',
34
- progress: 80,
35
- },
36
- {
37
- firstName: 'joe',
38
- lastName: 'bergevin',
39
- age: 45,
40
- visits: 20,
41
- status: 'Complicated',
42
- progress: 10,
43
- },
44
- ]
45
-
46
- const defaultColumns = table.createColumns([
47
- table.createGroup({
48
- header: 'Name',
49
- footer: props => props.column.id,
50
- columns: [
51
- table.createColumn('firstName', {
52
- cell: info => info.value,
53
- footer: props => props.column.id,
54
- }),
55
- table.createColumn(row => row.lastName, {
56
- id: 'lastName',
57
- cell: info => info.value,
58
- header: <span>Last Name</span>,
59
- footer: props => props.column.id,
60
- }),
61
- ],
62
- }),
63
- table.createGroup({
64
- header: 'Info',
65
- footer: props => props.column.id,
66
- columns: [
67
- table.createColumn('age', {
68
- header: () => 'Age',
69
- footer: props => props.column.id,
70
- }),
71
- table.createGroup({
72
- header: 'More Info',
73
- columns: [
74
- table.createColumn('visits', {
75
- header: () => <span>Visits</span>,
76
- footer: props => props.column.id,
77
- }),
78
- table.createColumn('status', {
79
- header: 'Status',
80
- footer: props => props.column.id,
81
- }),
82
- table.createColumn('progress', {
83
- header: 'Profile Progress',
84
- footer: props => props.column.id,
85
- }),
86
- ],
87
- }),
88
- ],
89
- }),
90
- ])
91
-
92
- describe('core', () => {
93
- it('renders a table with markup', () => {
94
- const Table = () => {
95
- const [data] = React.useState<Row[]>(() => [...defaultData])
96
- const [columns] = React.useState<typeof defaultColumns>(() => [
97
- ...defaultColumns,
98
- ])
99
- const [columnVisibility, setColumnVisibility] = React.useState({})
100
-
101
- const rerender = React.useReducer(() => ({}), {})[1]
102
-
103
- const instance = table.useTable({
104
- data,
105
- columns,
106
- onColumnVisibilityChange: setColumnVisibility,
107
- state: {
108
- columnVisibility,
109
- },
110
- // debug: true,
111
- })
112
-
113
- return (
114
- <div className="p-2">
115
- <table {...instance.getTableProps()}>
116
- <thead>
117
- {instance.getHeaderGroups().map(headerGroup => (
118
- <tr {...headerGroup.getHeaderGroupProps()}>
119
- {headerGroup.headers.map(header => (
120
- <th {...header.getHeaderProps()}>
121
- {header.isPlaceholder ? null : header.renderHeader()}
122
- </th>
123
- ))}
124
- </tr>
125
- ))}
126
- </thead>
127
- <tbody {...instance.getTableBodyProps()}>
128
- {instance.getRows().map(row => (
129
- <tr {...row.getRowProps()}>
130
- {row.getVisibleCells().map(cell => (
131
- <td {...cell.getCellProps()}>{cell.renderCell()}</td>
132
- ))}
133
- </tr>
134
- ))}
135
- </tbody>
136
- <tfoot>
137
- {instance.getFooterGroups().map(footerGroup => (
138
- <tr {...footerGroup.getFooterGroupProps()}>
139
- {footerGroup.headers.map(header => (
140
- <th {...header.getFooterProps()}>
141
- {header.isPlaceholder ? null : header.renderFooter()}
142
- </th>
143
- ))}
144
- </tr>
145
- ))}
146
- </tfoot>
147
- </table>
148
- <div className="h-4" />
149
- <button onClick={() => rerender()} className="border p-2">
150
- Rerender
151
- </button>
152
- </div>
153
- )
154
- }
155
-
156
- // let api: any;
157
-
158
- const rendered = RTL.render(<Table />)
159
-
160
- // RTL.screen.logTestingPlaygroundURL();
161
-
162
- RTL.screen.getByRole('table')
163
- expect(RTL.screen.getAllByRole('rowgroup').length).toEqual(3)
164
- expect(RTL.screen.getAllByRole('row').length).toEqual(9)
165
- expect(RTL.screen.getAllByRole('columnheader').length).toEqual(12)
166
- expect(RTL.screen.getAllByRole('columnfooter').length).toEqual(12)
167
- expect(RTL.screen.getAllByRole('gridcell').length).toEqual(18)
168
-
169
- expect(
170
- Array.from(rendered.container.querySelectorAll('thead > tr')).map(d =>
171
- Array.from(d.querySelectorAll('th')).map(d => [
172
- d.innerHTML,
173
- d.getAttribute('colspan'),
174
- ])
175
- )
176
- ).toMatchSnapshot()
177
-
178
- expect(
179
- Array.from(rendered.container.querySelectorAll('tbody > tr')).map(d =>
180
- Array.from(d.querySelectorAll('td')).map(d => d.innerHTML)
181
- )
182
- ).toMatchSnapshot()
183
-
184
- expect(
185
- Array.from(rendered.container.querySelectorAll('tfoot > tr')).map(d =>
186
- Array.from(d.querySelectorAll('th')).map(d => [
187
- d.innerHTML,
188
- d.getAttribute('colspan'),
189
- ])
190
- )
191
- ).toMatchSnapshot()
192
- })
193
-
194
- it('has a stable api', () => {
195
- const { result } = renderHook(() => {
196
- const rerender = React.useReducer(() => ({}), {})[1]
197
-
198
- const instance = table.useTable({
199
- data: defaultData,
200
- columns: defaultColumns,
201
- })
202
-
203
- return {
204
- instance,
205
- rerender,
206
- }
207
- })
208
-
209
- const prev = result.current
210
-
211
- act(() => {
212
- result.current.rerender()
213
- })
214
-
215
- const next = result.current
216
-
217
- expect(prev).toStrictEqual(next)
218
- })
219
-
220
- it('can return the rowModel', () => {
221
- const { result } = renderHook(() => {
222
- const rerender = React.useReducer(() => ({}), {})[1]
223
-
224
- const instance = table.useTable({
225
- data: defaultData,
226
- columns: defaultColumns,
227
- })
228
-
229
- return {
230
- instance,
231
- rerender,
232
- }
233
- })
234
-
235
- const rowModel = result.current.instance.getRowModel()
236
-
237
- expect(rowModel.rows.length).toEqual(3)
238
- expect(rowModel.flatRows.length).toEqual(3)
239
- expect(rowModel.rowsById['2']?.original).toEqual(defaultData[2])
240
- })
241
- })