@tanstack/react-table 0.0.1-alpha.8 → 8.0.0-alpha.2

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 (107) 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 +519 -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/ColumnSizing.js +331 -0
  10. package/build/cjs/features/ColumnSizing.js.map +1 -0
  11. package/build/cjs/features/Expanding.js +234 -0
  12. package/build/cjs/features/Expanding.js.map +1 -0
  13. package/build/cjs/features/Filters.js +396 -0
  14. package/build/cjs/features/Filters.js.map +1 -0
  15. package/build/cjs/features/Grouping.js +228 -0
  16. package/build/cjs/features/Grouping.js.map +1 -0
  17. package/build/cjs/features/Headers.js +486 -0
  18. package/build/cjs/features/Headers.js.map +1 -0
  19. package/build/cjs/features/Ordering.js +83 -0
  20. package/build/cjs/features/Ordering.js.map +1 -0
  21. package/build/cjs/features/Pinning.js +163 -0
  22. package/build/cjs/features/Pinning.js.map +1 -0
  23. package/build/cjs/features/Sorting.js +269 -0
  24. package/build/cjs/features/Sorting.js.map +1 -0
  25. package/build/cjs/features/Visibility.js +160 -0
  26. package/build/cjs/features/Visibility.js.map +1 -0
  27. package/build/cjs/filterTypes.js +172 -0
  28. package/build/cjs/filterTypes.js.map +1 -0
  29. package/build/cjs/index.js +30 -0
  30. package/build/cjs/index.js.map +1 -0
  31. package/build/cjs/sortTypes.js +121 -0
  32. package/build/cjs/sortTypes.js.map +1 -0
  33. package/build/cjs/utils/columnFilterRowsFn.js +130 -0
  34. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
  35. package/build/cjs/utils/expandRowsFn.js +38 -0
  36. package/build/cjs/utils/expandRowsFn.js.map +1 -0
  37. package/build/cjs/utils/globalFilterRowsFn.js +100 -0
  38. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
  39. package/build/cjs/utils/groupRowsFn.js +154 -0
  40. package/build/cjs/utils/groupRowsFn.js.map +1 -0
  41. package/build/cjs/utils/sortRowsFn.js +93 -0
  42. package/build/cjs/utils/sortRowsFn.js.map +1 -0
  43. package/build/cjs/utils.js +143 -0
  44. package/build/cjs/utils.js.map +1 -0
  45. package/build/esm/index.js +3722 -0
  46. package/build/esm/index.js.map +1 -0
  47. package/build/stats-html.html +2689 -0
  48. package/build/stats-react.json +747 -0
  49. package/build/types/aggregationTypes.d.ts +22 -0
  50. package/build/types/core.d.ts +126 -0
  51. package/build/types/createTable.d.ts +35 -0
  52. package/build/types/features/ColumnSizing.d.ts +73 -0
  53. package/build/types/features/Expanding.d.ts +52 -0
  54. package/build/types/features/Filters.d.ts +93 -0
  55. package/build/types/features/Grouping.d.ts +82 -0
  56. package/build/types/features/Headers.d.ts +41 -0
  57. package/build/types/features/Ordering.d.ts +19 -0
  58. package/build/types/features/Pinning.d.ts +39 -0
  59. package/build/types/features/Sorting.d.ts +75 -0
  60. package/build/types/features/Visibility.d.ts +47 -0
  61. package/build/types/filterTypes.d.ts +50 -0
  62. package/build/types/index.d.ts +7 -0
  63. package/build/types/sortTypes.d.ts +17 -0
  64. package/build/types/types.d.ts +124 -0
  65. package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
  66. package/build/types/utils/expandRowsFn.d.ts +2 -0
  67. package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
  68. package/build/types/utils/groupRowsFn.d.ts +2 -0
  69. package/build/types/utils/sortRowsFn.d.ts +2 -0
  70. package/build/types/utils.d.ts +24 -0
  71. package/{dist/react-table.development.js → build/umd/index.development.js} +372 -29
  72. package/build/umd/index.development.js.map +1 -0
  73. package/build/umd/index.production.js +12 -0
  74. package/build/umd/index.production.js.map +1 -0
  75. package/package.json +9 -94
  76. package/src/core.tsx +43 -5
  77. package/src/createTable.tsx +1 -1
  78. package/src/features/ColumnSizing.ts +482 -0
  79. package/src/features/Filters.ts +1 -1
  80. package/src/features/Headers.ts +43 -6
  81. package/src/features/{withPagination.ts → withPagination.oldts} +0 -0
  82. package/src/features/{withRowSelection.ts → withRowSelection.oldts} +0 -0
  83. package/src/types.ts +35 -6
  84. package/src/utils.tsx +8 -2
  85. package/dist/react-table.development.js.map +0 -1
  86. package/dist/react-table.production.min.js +0 -2
  87. package/dist/react-table.production.min.js.map +0 -1
  88. package/lib/index.js +0 -65
  89. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  90. package/src/features/notest/useBlockLayout.test.js +0 -158
  91. package/src/features/notest/useColumnOrder.test.js +0 -186
  92. package/src/features/notest/useExpanded.test.js +0 -125
  93. package/src/features/notest/useFilters.test.js +0 -393
  94. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  95. package/src/features/notest/useFlexLayout.test.js +0 -152
  96. package/src/features/notest/useGroupBy.test.js +0 -259
  97. package/src/features/notest/usePagination.test.js +0 -231
  98. package/src/features/notest/useResizeColumns.test.js +0 -229
  99. package/src/features/notest/useRowSelect.test.js +0 -250
  100. package/src/features/notest/useRowState.test.js +0 -178
  101. package/src/features/tests/Visibility.test.tsx +0 -225
  102. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  103. package/src/features/tests/withSorting.notest.tsx +0 -341
  104. package/src/features/withColumnResizing.ts +0 -281
  105. package/src/test-utils/makeTestData.ts +0 -41
  106. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  107. 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,281 +0,0 @@
1
- import React, {
2
- ComponentProps,
3
- MouseEvent as ReactMouseEvent,
4
- PropsWithoutRef,
5
- PropsWithRef,
6
- TouchEvent as ReactTouchEvent,
7
- } from 'react'
8
-
9
- import { getLeafHeaders, makeStateUpdater } from '../utils'
10
-
11
- import { withColumnResizing as name, withColumnVisibility } from '../Constants'
12
- import {
13
- ColumnId,
14
- ColumnResizing,
15
- ReduceColumn,
16
- ReduceHeader,
17
- Header,
18
- MakeInstance,
19
- GetDefaultOptions,
20
- } from '../types'
21
-
22
- let passiveSupported: boolean | null = null
23
-
24
- export function passiveEventSupported() {
25
- // memoize support to avoid adding multiple test events
26
- if (typeof passiveSupported === 'boolean') return passiveSupported
27
-
28
- let supported = false
29
- try {
30
- const options = {
31
- get passive() {
32
- supported = true
33
- return false
34
- },
35
- }
36
-
37
- window.addEventListener('test', noop, options)
38
- window.removeEventListener('test', noop)
39
- } catch (err) {
40
- supported = false
41
- }
42
- passiveSupported = supported
43
- return passiveSupported
44
- }
45
-
46
- const getDefaultOptions: GetDefaultOptions = options => {
47
- return {
48
- onColumnResizingChange: React.useCallback(
49
- makeStateUpdater('columnResizing'),
50
- []
51
- ),
52
- ...options,
53
- initialState: {
54
- columnResizing: {
55
- columnWidths: {},
56
- },
57
- ...options.initialState,
58
- },
59
- }
60
- }
61
-
62
- const extendInstance: MakeInstance = instance => {
63
- instance.setColumnResizing = React.useCallback(
64
- updater => instance.options.onColumnResizingChange?.(updater, instance),
65
- [instance]
66
- )
67
-
68
- instance.getColumnCanResize = React.useCallback(
69
- columnId => {
70
- const column = instance.allColumns.find(d => d.id === columnId)
71
-
72
- if (!column) return false
73
-
74
- return (
75
- (column.disableResizing ? false : undefined) ??
76
- (instance.options?.disableResizing ? false : undefined) ??
77
- column.defaultCanResize ??
78
- true
79
- )
80
- },
81
- [instance.allColumns, instance.options.disableResizing]
82
- )
83
-
84
- instance.getColumnWidth = React.useCallback(
85
- columnId => {
86
- if (!columnId) return 0
87
- const { allColumns } = instance
88
- const column = allColumns.find(d => d.id === columnId)
89
- const columnWidths = instance.state.columnResizing?.columnWidths
90
-
91
- if (!column) return 0
92
-
93
- return Math.min(
94
- Math.max(
95
- column?.minWidth ?? 0,
96
- (columnWidths?.[columnId] ?? 0) || (column.width ?? 0)
97
- ),
98
- column.maxWidth ?? 0
99
- )
100
- },
101
- [instance]
102
- )
103
-
104
- const isResizingColumn = instance.state.columnResizing?.isResizingColumn
105
- instance.getColumnIsResizing = React.useCallback(
106
- columnId => {
107
- return isResizingColumn === columnId
108
- },
109
- [isResizingColumn]
110
- )
111
-
112
- return instance
113
- }
114
-
115
- const reduceColumn: ReduceColumn = (column, { instance }) => {
116
- column.getIsResizing = () => instance.getColumnIsResizing(column.id)
117
- column.getCanResize = () => instance.getColumnCanResize(column.id)
118
-
119
- return column
120
- }
121
-
122
- const reduceHeader: ReduceHeader = (header, { instance }) => {
123
- header.getIsResizing = () =>
124
- header?.column?.getIsResizing ? header.column.getIsResizing() : true
125
- header.getCanResize = () =>
126
- header?.column?.getCanResize ? header.column.getCanResize() : true
127
-
128
- function isTouchStartEvent(
129
- e: ReactTouchEvent | ReactMouseEvent
130
- ): e is ReactTouchEvent {
131
- return e.type === 'touchstart'
132
- }
133
-
134
- header.getResizerProps = (props = {}) => {
135
- const onResizeStart = (
136
- e: ReactMouseEvent | ReactTouchEvent,
137
- header: Header
138
- ) => {
139
- if (isTouchStartEvent(e)) {
140
- // lets not respond to multiple touches (e.g. 2 or 3 fingers)
141
- if (e.touches && e.touches.length > 1) {
142
- return
143
- }
144
- }
145
- const headersToResize = getLeafHeaders(header)
146
- const headerIdWidths: [ColumnId, number][] = headersToResize.map(d => [
147
- d.id,
148
- d.getWidth(),
149
- ])
150
-
151
- const clientX = isTouchStartEvent(e)
152
- ? Math.round(e.touches[0].clientX)
153
- : e.clientX
154
-
155
- const onMove = (clientXPos?: number) => {
156
- if (typeof clientXPos !== 'number') {
157
- return
158
- }
159
-
160
- return instance.setColumnResizing(old => {
161
- const deltaX = clientXPos - (old?.startX ?? 0)
162
- const percentageDeltaX = Math.max(
163
- deltaX / (old?.columnWidth ?? 0),
164
- -0.999999
165
- )
166
-
167
- const newColumnWidths: ColumnResizing['columnWidths'] = {}
168
- ;(old?.headerIdWidths ?? []).forEach(([headerId, headerWidth]) => {
169
- newColumnWidths[headerId] = Math.max(
170
- headerWidth + headerWidth * percentageDeltaX,
171
- 0
172
- )
173
- })
174
-
175
- return {
176
- ...old,
177
- columnWidths: {
178
- ...(old?.columnWidths ?? {}),
179
- ...newColumnWidths,
180
- },
181
- }
182
- })
183
- }
184
-
185
- const onEnd = () =>
186
- instance.setColumnResizing(old => ({
187
- ...old,
188
- startX: null,
189
- isResizingColumn: false,
190
- }))
191
-
192
- const mouseEvents = {
193
- moveHandler: (e: MouseEvent) => onMove(e.clientX),
194
- upHandler: () => {
195
- document.removeEventListener('mousemove', mouseEvents.moveHandler)
196
- document.removeEventListener('mouseup', mouseEvents.upHandler)
197
- onEnd()
198
- },
199
- }
200
-
201
- const touchEvents = {
202
- moveHandler: (e: TouchEvent) => {
203
- if (e.cancelable) {
204
- e.preventDefault()
205
- e.stopPropagation()
206
- }
207
- onMove(e.touches[0].clientX)
208
- return false
209
- },
210
- upHandler: () => {
211
- document.removeEventListener('touchmove', touchEvents.moveHandler)
212
- document.removeEventListener('touchend', touchEvents.upHandler)
213
- onEnd()
214
- },
215
- }
216
-
217
- const passiveIfSupported = passiveEventSupported()
218
- ? { passive: false }
219
- : false
220
-
221
- if (isTouchStartEvent(e)) {
222
- document.addEventListener(
223
- 'touchmove',
224
- touchEvents.moveHandler,
225
- passiveIfSupported
226
- )
227
- document.addEventListener(
228
- 'touchend',
229
- touchEvents.upHandler,
230
- passiveIfSupported
231
- )
232
- } else {
233
- document.addEventListener(
234
- 'mousemove',
235
- mouseEvents.moveHandler,
236
- passiveIfSupported
237
- )
238
- document.addEventListener(
239
- 'mouseup',
240
- mouseEvents.upHandler,
241
- passiveIfSupported
242
- )
243
- }
244
-
245
- instance.setColumnResizing(old => ({
246
- ...old,
247
- startX: clientX,
248
- headerIdWidths,
249
- columnWidth: header.getWidth(),
250
- isResizingColumn: header.id,
251
- }))
252
- }
253
-
254
- return {
255
- onMouseDown: (e: ReactMouseEvent) => {
256
- e.persist()
257
- onResizeStart(e, header)
258
- },
259
- onTouchStart: (e: ReactTouchEvent) => {
260
- e.persist()
261
- onResizeStart(e, header)
262
- },
263
- draggable: false,
264
- role: 'separator',
265
- ...props,
266
- }
267
- }
268
-
269
- return header
270
- }
271
-
272
- export const withColumnResizing = {
273
- name,
274
- after: [withColumnVisibility],
275
- plugs: {
276
- getDefaultOptions,
277
- extendInstance,
278
- reduceColumn,
279
- reduceHeader,
280
- },
281
- }
@@ -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
- }