@tanstack/react-table 0.0.1-alpha.6 → 8.0.0-alpha.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.
Files changed (96) 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 +493 -0
  6. package/build/cjs/core.js.map +1 -0
  7. package/build/cjs/createTable.js +103 -0
  8. package/build/cjs/createTable.js.map +1 -0
  9. package/build/cjs/features/Expanding.js +234 -0
  10. package/build/cjs/features/Expanding.js.map +1 -0
  11. package/build/cjs/features/Filters.js +396 -0
  12. package/build/cjs/features/Filters.js.map +1 -0
  13. package/build/cjs/features/Grouping.js +228 -0
  14. package/build/cjs/features/Grouping.js.map +1 -0
  15. package/build/cjs/features/Headers.js +483 -0
  16. package/build/cjs/features/Headers.js.map +1 -0
  17. package/build/cjs/features/Ordering.js +83 -0
  18. package/build/cjs/features/Ordering.js.map +1 -0
  19. package/build/cjs/features/Pinning.js +163 -0
  20. package/build/cjs/features/Pinning.js.map +1 -0
  21. package/build/cjs/features/Sorting.js +269 -0
  22. package/build/cjs/features/Sorting.js.map +1 -0
  23. package/build/cjs/features/Visibility.js +160 -0
  24. package/build/cjs/features/Visibility.js.map +1 -0
  25. package/build/cjs/filterTypes.js +172 -0
  26. package/build/cjs/filterTypes.js.map +1 -0
  27. package/build/cjs/index.js +30 -0
  28. package/build/cjs/index.js.map +1 -0
  29. package/build/cjs/sortTypes.js +121 -0
  30. package/build/cjs/sortTypes.js.map +1 -0
  31. package/build/cjs/utils/columnFilterRowsFn.js +130 -0
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
  33. package/build/cjs/utils/expandRowsFn.js +38 -0
  34. package/build/cjs/utils/expandRowsFn.js.map +1 -0
  35. package/build/cjs/utils/globalFilterRowsFn.js +100 -0
  36. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
  37. package/build/cjs/utils/groupRowsFn.js +154 -0
  38. package/build/cjs/utils/groupRowsFn.js.map +1 -0
  39. package/build/cjs/utils/sortRowsFn.js +93 -0
  40. package/build/cjs/utils/sortRowsFn.js.map +1 -0
  41. package/build/cjs/utils.js +143 -0
  42. package/build/cjs/utils.js.map +1 -0
  43. package/build/esm/index.js +3389 -0
  44. package/build/esm/index.js.map +1 -0
  45. package/build/stats-html.html +2689 -0
  46. package/build/stats-react.json +703 -0
  47. package/build/types/aggregationTypes.d.ts +22 -0
  48. package/build/types/core.d.ts +122 -0
  49. package/build/types/createTable.d.ts +35 -0
  50. package/build/types/features/Expanding.d.ts +52 -0
  51. package/build/types/features/Filters.d.ts +93 -0
  52. package/build/types/features/Grouping.d.ts +82 -0
  53. package/build/types/features/Headers.d.ts +41 -0
  54. package/build/types/features/Ordering.d.ts +19 -0
  55. package/build/types/features/Pinning.d.ts +39 -0
  56. package/build/types/features/Sorting.d.ts +75 -0
  57. package/build/types/features/Visibility.d.ts +47 -0
  58. package/build/types/filterTypes.d.ts +50 -0
  59. package/build/types/index.d.ts +7 -0
  60. package/build/types/sortTypes.d.ts +17 -0
  61. package/build/types/types.d.ts +122 -0
  62. package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
  63. package/build/types/utils/expandRowsFn.d.ts +2 -0
  64. package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
  65. package/build/types/utils/groupRowsFn.d.ts +2 -0
  66. package/build/types/utils/sortRowsFn.d.ts +2 -0
  67. package/build/types/utils.d.ts +24 -0
  68. package/{dist/react-table.development.js → build/umd/index.development.js} +11 -1
  69. package/build/umd/index.development.js.map +1 -0
  70. package/{dist/react-table.production.min.js → build/umd/index.production.js} +11 -1
  71. package/build/umd/index.production.js.map +1 -0
  72. package/package.json +9 -94
  73. package/src/features/{withColumnResizing.ts → withColumnResizing.oldts} +0 -0
  74. package/src/features/{withPagination.ts → withPagination.oldts} +0 -0
  75. package/src/features/{withRowSelection.ts → withRowSelection.oldts} +0 -0
  76. package/dist/react-table.development.js.map +0 -1
  77. package/dist/react-table.production.min.js.map +0 -1
  78. package/lib/index.js +0 -65
  79. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  80. package/src/features/notest/useBlockLayout.test.js +0 -158
  81. package/src/features/notest/useColumnOrder.test.js +0 -186
  82. package/src/features/notest/useExpanded.test.js +0 -125
  83. package/src/features/notest/useFilters.test.js +0 -393
  84. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  85. package/src/features/notest/useFlexLayout.test.js +0 -152
  86. package/src/features/notest/useGroupBy.test.js +0 -259
  87. package/src/features/notest/usePagination.test.js +0 -231
  88. package/src/features/notest/useResizeColumns.test.js +0 -229
  89. package/src/features/notest/useRowSelect.test.js +0 -250
  90. package/src/features/notest/useRowState.test.js +0 -178
  91. package/src/features/tests/Visibility.test.tsx +0 -225
  92. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  93. package/src/features/tests/withSorting.notest.tsx +0 -341
  94. package/src/test-utils/makeTestData.ts +0 -41
  95. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  96. package/src/tests/core.test.tsx +0 -241
@@ -1,341 +0,0 @@
1
- import React from 'react'
2
- import { renderHook, act } from '@testing-library/react-hooks'
3
- import { getHeaderIds, getRowValues } from '../../test-utils'
4
- import { useTable } from '../../core/useTable'
5
- import { noop } from '../../utils'
6
- import { withSorting } from '../withSorting'
7
- import type { Column, TableState } from '../../types'
8
-
9
- const data = [
10
- {
11
- firstName: 'tanner',
12
- lastName: 'linsley',
13
- age: 29,
14
- visits: 100,
15
- status: 'In Relationship',
16
- progress: 80,
17
- },
18
- {
19
- firstName: 'derek',
20
- lastName: 'perkins',
21
- age: 40,
22
- visits: 40,
23
- status: 'Single',
24
- progress: 80,
25
- },
26
- {
27
- firstName: 'joe',
28
- lastName: 'bergevin',
29
- age: 45,
30
- visits: 20,
31
- status: 'Complicated',
32
- progress: 10,
33
- },
34
- ]
35
-
36
- const columns: Column[] = [
37
- {
38
- Header: 'Name',
39
- columns: [
40
- {
41
- Header: 'First Name',
42
- accessor: 'firstName',
43
- },
44
- {
45
- Header: 'Last Name',
46
- accessor: 'lastName',
47
- },
48
- ],
49
- },
50
- {
51
- Header: 'Info',
52
- columns: [
53
- {
54
- Header: 'Age',
55
- accessor: 'age',
56
- },
57
- {
58
- Header: 'Visits',
59
- accessor: 'visits',
60
- },
61
- {
62
- Header: 'Status',
63
- accessor: 'status',
64
- },
65
- {
66
- Header: 'Profile Progress',
67
- accessor: 'progress',
68
- },
69
- ],
70
- },
71
- ]
72
-
73
- describe('withSorting', () => {
74
- it('renders a sortable table', () => {
75
- const { result } = renderHook(
76
- options => {
77
- const instance = useTable(options, [withCore, withSorting])
78
-
79
- return instance
80
- },
81
- {
82
- initialProps: {
83
- data,
84
- columns,
85
- },
86
- }
87
- )
88
-
89
- expect(getHeaderIds(result.current)).toEqual([
90
- ['Name', 'Info'],
91
- ['firstName', 'lastName', 'age', 'visits', 'status', 'progress'],
92
- ])
93
-
94
- expect(getRowValues(result.current)).toEqual([
95
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
96
- ['derek', 'perkins', 40, 40, 'Single', 80],
97
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
98
- ])
99
-
100
- act(() => {
101
- result.current.flatHeaders
102
- .find(d => d.id === 'firstName')
103
- ?.getToggleSortingProps?.()
104
- .onClick({
105
- persist: noop,
106
- })
107
- })
108
-
109
- expect(getRowValues(result.current)).toEqual([
110
- ['derek', 'perkins', 40, 40, 'Single', 80],
111
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
112
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
113
- ])
114
-
115
- act(() => {
116
- result.current.flatHeaders
117
- .find(d => d.id === 'firstName')
118
- ?.getToggleSortingProps?.()
119
- .onClick({
120
- persist: noop,
121
- })
122
- })
123
-
124
- expect(getRowValues(result.current)).toEqual([
125
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
126
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
127
- ['derek', 'perkins', 40, 40, 'Single', 80],
128
- ])
129
-
130
- act(() => {
131
- result.current.flatHeaders
132
- .find(d => d.id === 'progress')
133
- ?.getToggleSortingProps?.()
134
- .onClick({
135
- persist: noop,
136
- })
137
- })
138
-
139
- expect(getRowValues(result.current)).toEqual([
140
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
141
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
142
- ['derek', 'perkins', 40, 40, 'Single', 80],
143
- ])
144
-
145
- act(() => {
146
- result.current.flatHeaders
147
- .find(d => d.id === 'firstName')
148
- ?.getToggleSortingProps?.()
149
- .onClick({
150
- persist: noop,
151
- shiftKey: true,
152
- })
153
- })
154
-
155
- expect(getRowValues(result.current)).toEqual([
156
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
157
- ['derek', 'perkins', 40, 40, 'Single', 80],
158
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
159
- ])
160
- })
161
-
162
- it('renders a controlled sorted table', () => {
163
- const { result, rerender } = renderHook(
164
- options => {
165
- const instance = useTable(options, [withSorting])
166
-
167
- return instance
168
- },
169
- {
170
- initialProps: {
171
- data,
172
- columns,
173
- state: {},
174
- },
175
- }
176
- )
177
-
178
- expect(getHeaderIds(result.current)).toEqual([
179
- ['Name', 'Info'],
180
- ['firstName', 'lastName', 'age', 'visits', 'status', 'progress'],
181
- ])
182
-
183
- expect(getRowValues(result.current)).toEqual([
184
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
185
- ['derek', 'perkins', 40, 40, 'Single', 80],
186
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
187
- ])
188
-
189
- rerender({
190
- data,
191
- columns,
192
- state: { sorting: [{ id: 'firstName', desc: false }] },
193
- })
194
-
195
- expect(getRowValues(result.current)).toEqual([
196
- ['derek', 'perkins', 40, 40, 'Single', 80],
197
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
198
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
199
- ])
200
-
201
- rerender({
202
- data,
203
- columns,
204
- state: { sorting: [{ id: 'firstName', desc: true }] },
205
- })
206
-
207
- expect(getRowValues(result.current)).toEqual([
208
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
209
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
210
- ['derek', 'perkins', 40, 40, 'Single', 80],
211
- ])
212
-
213
- rerender({
214
- data,
215
- columns,
216
- state: { sorting: [{ id: 'progress', desc: false }] },
217
- })
218
-
219
- expect(getRowValues(result.current)).toEqual([
220
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
221
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
222
- ['derek', 'perkins', 40, 40, 'Single', 80],
223
- ])
224
-
225
- rerender({
226
- data,
227
- columns,
228
- state: {
229
- sorting: [
230
- { id: 'progress', desc: false },
231
- { id: 'firstName', desc: false },
232
- ],
233
- },
234
- })
235
-
236
- expect(getRowValues(result.current)).toEqual([
237
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
238
- ['derek', 'perkins', 40, 40, 'Single', 80],
239
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
240
- ])
241
- })
242
-
243
- it('renders a hoisted state sorted table', () => {
244
- const { result } = renderHook(
245
- options => {
246
- const [sorting, setSorting] = React.useState<TableState['sorting']>([])
247
-
248
- const instance = useTable(
249
- {
250
- ...options,
251
- state: {
252
- sorting,
253
- },
254
- onSortingChange: setSorting,
255
- },
256
- [withSorting]
257
- )
258
-
259
- return instance
260
- },
261
- {
262
- initialProps: {
263
- data,
264
- columns,
265
- },
266
- }
267
- )
268
-
269
- expect(getHeaderIds(result.current)).toEqual([
270
- ['Name', 'Info'],
271
- ['firstName', 'lastName', 'age', 'visits', 'status', 'progress'],
272
- ])
273
-
274
- expect(getRowValues(result.current)).toEqual([
275
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
276
- ['derek', 'perkins', 40, 40, 'Single', 80],
277
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
278
- ])
279
-
280
- act(() => {
281
- result.current.flatHeaders
282
- .find(d => d.id === 'firstName')
283
- ?.getToggleSortingProps?.()
284
- .onClick({
285
- persist: noop,
286
- })
287
- })
288
-
289
- expect(getRowValues(result.current)).toEqual([
290
- ['derek', 'perkins', 40, 40, 'Single', 80],
291
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
292
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
293
- ])
294
-
295
- act(() => {
296
- result.current.flatHeaders
297
- .find(d => d.id === 'firstName')
298
- ?.getToggleSortingProps?.()
299
- .onClick({
300
- persist: noop,
301
- })
302
- })
303
-
304
- expect(getRowValues(result.current)).toEqual([
305
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
306
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
307
- ['derek', 'perkins', 40, 40, 'Single', 80],
308
- ])
309
-
310
- act(() => {
311
- result.current.flatHeaders
312
- .find(d => d.id === 'progress')
313
- ?.getToggleSortingProps?.()
314
- .onClick({
315
- persist: noop,
316
- })
317
- })
318
-
319
- expect(getRowValues(result.current)).toEqual([
320
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
321
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
322
- ['derek', 'perkins', 40, 40, 'Single', 80],
323
- ])
324
-
325
- act(() => {
326
- result.current.flatHeaders
327
- .find(d => d.id === 'firstName')
328
- ?.getToggleSortingProps?.()
329
- .onClick({
330
- persist: noop,
331
- shiftKey: true,
332
- })
333
- })
334
-
335
- expect(getRowValues(result.current)).toEqual([
336
- ['joe', 'bergevin', 45, 20, 'Complicated', 10],
337
- ['derek', 'perkins', 40, 40, 'Single', 80],
338
- ['tanner', 'linsley', 29, 100, 'In Relationship', 80],
339
- ])
340
- })
341
- })
@@ -1,41 +0,0 @@
1
- const range = len => {
2
- const arr = []
3
- for (let i = 0; i < len; i++) {
4
- arr.push(i)
5
- }
6
- return arr
7
- }
8
-
9
- const newPerson = (depth, index, total) => {
10
- const age = (depth + 1) * (index + 1)
11
- const visits = age * 10
12
- const progress = (index + 1) / total
13
-
14
- return {
15
- firstName: `${depth} ${index} firstName`,
16
- lastName: `${depth} ${index} lastName`,
17
- age,
18
- visits,
19
- progress,
20
- status:
21
- progress > 0.66
22
- ? 'relationship'
23
- : progress > 0.33
24
- ? 'complicated'
25
- : 'single',
26
- }
27
- }
28
-
29
- export default function makeTestData(...lens) {
30
- const makeDataLevel = (depth = 0) => {
31
- const len = lens[depth]
32
- return range(len).map(d => {
33
- return {
34
- ...newPerson(depth, d, len),
35
- subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined,
36
- }
37
- })
38
- }
39
-
40
- return makeDataLevel()
41
- }
@@ -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
- `;