@tanstack/table-core 8.0.0-alpha.83 → 8.0.0-alpha.84

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 (93) hide show
  1. package/build/cjs/core/cell.js +38 -0
  2. package/build/cjs/core/cell.js.map +1 -0
  3. package/build/cjs/core/column.js +88 -0
  4. package/build/cjs/core/column.js.map +1 -0
  5. package/build/cjs/{features/Headers.js → core/headers.js} +54 -66
  6. package/build/cjs/core/headers.js.map +1 -0
  7. package/build/cjs/core/instance.js +255 -0
  8. package/build/cjs/core/instance.js.map +1 -0
  9. package/build/cjs/core/row.js +77 -0
  10. package/build/cjs/core/row.js.map +1 -0
  11. package/build/cjs/features/ColumnSizing.js.map +1 -1
  12. package/build/cjs/features/Expanding.js.map +1 -1
  13. package/build/cjs/features/Filters.js +1 -1
  14. package/build/cjs/features/Filters.js.map +1 -1
  15. package/build/cjs/features/Grouping.js.map +1 -1
  16. package/build/cjs/features/Ordering.js.map +1 -1
  17. package/build/cjs/features/Pagination.js.map +1 -1
  18. package/build/cjs/features/Pinning.js +3 -3
  19. package/build/cjs/features/Pinning.js.map +1 -1
  20. package/build/cjs/features/RowSelection.js.map +1 -1
  21. package/build/cjs/features/Sorting.js.map +1 -1
  22. package/build/cjs/features/Visibility.js.map +1 -1
  23. package/build/cjs/index.js +9 -5
  24. package/build/cjs/index.js.map +1 -1
  25. package/build/cjs/utils/filterRowsUtils.js +23 -21
  26. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  27. package/build/cjs/utils/getCoreRowModel.js +9 -8
  28. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  29. package/build/cjs/utils/getGroupedRowModel.js +12 -11
  30. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  31. package/build/esm/index.js +656 -761
  32. package/build/esm/index.js.map +1 -1
  33. package/build/stats-html.html +1 -1
  34. package/build/stats-react.json +391 -368
  35. package/build/types/core/cell.d.ts +9 -0
  36. package/build/types/{features/Columns.d.ts → core/column.d.ts} +3 -17
  37. package/build/types/{features/Headers.d.ts → core/headers.d.ts} +26 -11
  38. package/build/types/core/instance.d.ts +57 -0
  39. package/build/types/core/row.d.ts +15 -0
  40. package/build/types/features/ColumnSizing.d.ts +2 -1
  41. package/build/types/features/Expanding.d.ts +2 -1
  42. package/build/types/features/Filters.d.ts +2 -1
  43. package/build/types/features/Grouping.d.ts +2 -1
  44. package/build/types/features/Ordering.d.ts +2 -1
  45. package/build/types/features/Pagination.d.ts +2 -1
  46. package/build/types/features/Pinning.d.ts +2 -1
  47. package/build/types/features/RowSelection.d.ts +2 -1
  48. package/build/types/features/Sorting.d.ts +2 -1
  49. package/build/types/features/Visibility.d.ts +2 -1
  50. package/build/types/index.d.ts +4 -2
  51. package/build/types/sortingFns.d.ts +4 -4
  52. package/build/types/types.d.ts +10 -53
  53. package/build/umd/index.development.js +660 -759
  54. package/build/umd/index.development.js.map +1 -1
  55. package/build/umd/index.production.js +1 -1
  56. package/build/umd/index.production.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/core/cell.ts +47 -0
  59. package/src/core/column.ts +148 -0
  60. package/src/{features/Headers.ts → core/headers.ts} +98 -99
  61. package/src/core/instance.ts +361 -0
  62. package/src/core/row.ts +85 -0
  63. package/src/features/ColumnSizing.ts +1 -1
  64. package/src/features/Expanding.ts +1 -2
  65. package/src/features/Filters.ts +2 -2
  66. package/src/features/Grouping.ts +1 -1
  67. package/src/features/Ordering.ts +1 -1
  68. package/src/features/Pagination.ts +1 -1
  69. package/src/features/Pinning.ts +8 -4
  70. package/src/features/RowSelection.ts +1 -1
  71. package/src/features/Sorting.ts +1 -1
  72. package/src/features/Visibility.ts +1 -1
  73. package/src/index.ts +4 -8
  74. package/src/types.ts +9 -61
  75. package/src/utils/filterRowsUtils.ts +4 -2
  76. package/src/utils/getCoreRowModel.ts +4 -2
  77. package/src/utils/getGroupedRowModel.ts +6 -6
  78. package/build/cjs/core.js +0 -168
  79. package/build/cjs/core.js.map +0 -1
  80. package/build/cjs/features/Cells.js +0 -101
  81. package/build/cjs/features/Cells.js.map +0 -1
  82. package/build/cjs/features/Columns.js +0 -191
  83. package/build/cjs/features/Columns.js.map +0 -1
  84. package/build/cjs/features/Headers.js.map +0 -1
  85. package/build/cjs/features/Rows.js +0 -94
  86. package/build/cjs/features/Rows.js.map +0 -1
  87. package/build/types/core.d.ts +0 -30
  88. package/build/types/features/Cells.d.ts +0 -13
  89. package/build/types/features/Rows.d.ts +0 -28
  90. package/src/core.ts +0 -246
  91. package/src/features/Cells.ts +0 -128
  92. package/src/features/Columns.ts +0 -293
  93. package/src/features/Rows.ts +0 -142
package/src/core.ts DELETED
@@ -1,246 +0,0 @@
1
- import { functionalUpdate, RequiredKeys } from './utils'
2
-
3
- import {
4
- Updater,
5
- TableOptionsResolved,
6
- TableState,
7
- TableInstance,
8
- Renderable,
9
- TableFeature,
10
- TableGenerics,
11
- InitialTableState,
12
- } from './types'
13
-
14
- import { Columns } from './features/Columns'
15
- import { Rows } from './features/Rows'
16
- import { Cells } from './features/Cells'
17
- import { ColumnSizing } from './features/ColumnSizing'
18
- import { Expanding } from './features/Expanding'
19
- import { Filters } from './features/Filters'
20
- import { Grouping } from './features/Grouping'
21
- import { Ordering } from './features/Ordering'
22
- import { Pagination } from './features/Pagination'
23
- import { Pinning } from './features/Pinning'
24
- import { RowSelection } from './features/RowSelection'
25
- import { Sorting } from './features/Sorting'
26
- import { Visibility } from './features/Visibility'
27
- import { Headers } from './features/Headers'
28
- //
29
-
30
- export type CoreTableState = {
31
- // coreProgress: number
32
- }
33
-
34
- export type CoreOptions<TGenerics extends TableGenerics> = {
35
- data: TGenerics['Row'][]
36
- state: Partial<TableState>
37
- onStateChange: (updater: Updater<TableState>) => void
38
- render: TGenerics['Renderer']
39
- debugAll?: boolean
40
- debugTable?: boolean
41
- debugHeaders?: boolean
42
- debugColumns?: boolean
43
- debugRows?: boolean
44
- initialState?: InitialTableState
45
- autoResetAll?: boolean
46
- mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
47
- meta?: TGenerics['TableMeta']
48
- // keepPreviousData?: boolean
49
- }
50
-
51
- export type CoreInstance<TGenerics extends TableGenerics> = {
52
- // generics: TGenerics
53
- initialState: TableState
54
- reset: () => void
55
- options: RequiredKeys<TableOptionsResolved<TGenerics>, 'state'>
56
- setOptions: (newOptions: Updater<TableOptionsResolved<TGenerics>>) => void
57
- getState: () => TableState
58
- setState: (updater: Updater<TableState>) => void
59
- _queue: (cb: () => void) => void
60
- _render: <TProps>(
61
- template: Renderable<TGenerics, TProps>,
62
- props: TProps
63
- ) => string | null | TGenerics['Rendered']
64
- _features: readonly TableFeature[]
65
- // getOverallProgress: () => number
66
- // getProgressStage: () =>
67
- // | undefined
68
- // | 'coreRowModel'
69
- // | 'filteredRowModel'
70
- // | 'facetedRowModel'
71
- // createBatch: (priority: keyof CoreBatches) => Batch
72
- // init: () => void
73
- // willUpdate: () => void
74
- // destroy: () => void
75
- // batches: CoreBatches
76
- }
77
-
78
- // export type Batch = {
79
- // id: number
80
- // priority: keyof CoreBatches
81
- // tasks: (() => void)[]
82
- // schedule: (cb: () => void) => void
83
- // cancel: () => void
84
- // }
85
-
86
- // type CoreBatches = {
87
- // data: Batch[]
88
- // facets: Batch[]
89
- // }
90
-
91
- export function createTableInstance<TGenerics extends TableGenerics>(
92
- options: TableOptionsResolved<TGenerics>
93
- ): TableInstance<TGenerics> {
94
- if (options.debugAll || options.debugTable) {
95
- console.info('Creating Table Instance...')
96
- }
97
-
98
- let instance = {
99
- _features: [
100
- Columns,
101
- Rows,
102
- Cells,
103
- Headers,
104
- Visibility,
105
- Ordering,
106
- Pinning,
107
- Filters,
108
- Sorting,
109
- Grouping,
110
- Expanding,
111
- Pagination,
112
- RowSelection,
113
- ColumnSizing,
114
- ] as const,
115
- } as unknown as CoreInstance<TGenerics>
116
-
117
- const defaultOptions = instance._features.reduce((obj, feature) => {
118
- return Object.assign(obj, feature.getDefaultOptions?.(instance))
119
- }, {}) as TableOptionsResolved<TGenerics>
120
-
121
- const mergeOptions = (options: TableOptionsResolved<TGenerics>) => {
122
- if (instance.options.mergeOptions) {
123
- return instance.options.mergeOptions(defaultOptions, options)
124
- }
125
-
126
- return {
127
- ...defaultOptions,
128
- ...options,
129
- }
130
- }
131
-
132
- const coreInitialState: CoreTableState = {
133
- // coreProgress: 1,
134
- }
135
-
136
- let initialState = {
137
- ...coreInitialState,
138
- ...(options.initialState ?? {}),
139
- } as TableState
140
-
141
- instance._features.forEach(feature => {
142
- initialState = feature.getInitialState?.(initialState) ?? initialState
143
- })
144
-
145
- const queued: (() => void)[] = []
146
- let queuedTimeout = false
147
-
148
- const midInstance: CoreInstance<TGenerics> = {
149
- ...instance,
150
- // init: () => {
151
- // startWork()
152
- // },
153
- // willUpdate: () => {
154
- // startWork()
155
- // },
156
- // destroy: () => {
157
- // stopWork()
158
- // },
159
- options: {
160
- ...defaultOptions,
161
- ...options,
162
- },
163
- initialState,
164
- _queue: cb => {
165
- queued.push(cb)
166
-
167
- if (!queuedTimeout) {
168
- queuedTimeout = true
169
-
170
- // Schedule a microtask to run the queued callbacks after
171
- // the current call stack (render, etc) has finished.
172
- Promise.resolve()
173
- .then(() => {
174
- while (queued.length) {
175
- queued.shift()!()
176
- }
177
- queuedTimeout = false
178
- })
179
- .catch(error =>
180
- setTimeout(() => {
181
- throw error
182
- })
183
- )
184
- }
185
- },
186
- reset: () => {
187
- instance.setState(instance.initialState)
188
- },
189
- setOptions: updater => {
190
- const newOptions = functionalUpdate(updater, instance.options)
191
- instance.options = mergeOptions(newOptions)
192
- },
193
- _render: (template, props) => {
194
- if (typeof instance.options.render === 'function') {
195
- return instance.options.render(template, props)
196
- }
197
-
198
- if (typeof template === 'function') {
199
- return (template as Function)(props)
200
- }
201
-
202
- return template
203
- },
204
-
205
- getState: () => {
206
- return instance.options.state as TableState
207
- },
208
-
209
- setState: (updater: Updater<TableState>) => {
210
- instance.options.onStateChange?.(updater)
211
- },
212
-
213
- // getOverallProgress: () => {
214
- // const { coreProgress, filtersProgress, facetProgress } =
215
- // instance.getState()
216
-
217
- // return mean(() =>
218
- // [coreProgress, filtersProgress].filter(d => d < 1)
219
- // ) as number
220
- // },
221
- // getProgressStage: () => {
222
- // const { coreProgress, filtersProgress, facetProgress } =
223
- // instance.getState()
224
-
225
- // if (coreProgress < 1) {
226
- // return 'coreRowModel'
227
- // }
228
-
229
- // if (filtersProgress < 1) {
230
- // return 'filteredRowModel'
231
- // }
232
-
233
- // if (Object.values(facetProgress).some(d => d < 1)) {
234
- // return 'facetedRowModel'
235
- // }
236
- // },
237
- }
238
-
239
- instance = Object.assign(instance, midInstance)
240
-
241
- instance._features.forEach(feature => {
242
- return Object.assign(instance, feature.createInstance?.(instance))
243
- })
244
-
245
- return instance as TableInstance<TGenerics>
246
- }
@@ -1,128 +0,0 @@
1
- import {
2
- Cell,
3
- TableGenerics,
4
- TableInstance,
5
- Row,
6
- Column,
7
- CoreCell,
8
- } from '../types'
9
- import { memo } from '../utils'
10
-
11
- export type CellsRow<TGenerics extends TableGenerics> = {
12
- getAllCells: () => Cell<TGenerics>[]
13
- getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
14
- }
15
-
16
- export type CellsInstance<TGenerics extends TableGenerics> = {
17
- createCell: (
18
- row: Row<TGenerics>,
19
- column: Column<TGenerics>,
20
- columnId: string
21
- ) => Cell<TGenerics>
22
- getCell: (rowId: string, columnId: string) => Cell<TGenerics>
23
- }
24
-
25
- //
26
-
27
- export const Cells = {
28
- createRow: <TGenerics extends TableGenerics>(
29
- row: Row<TGenerics>,
30
- instance: TableInstance<TGenerics>
31
- ): CellsRow<TGenerics> => {
32
- return {
33
- getAllCells: memo(
34
- () => [instance.getAllLeafColumns()],
35
- leafColumns => {
36
- return leafColumns.map(column => {
37
- return instance.createCell(row as Row<TGenerics>, column, column.id)
38
- })
39
- },
40
- {
41
- key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
42
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
43
- }
44
- ),
45
-
46
- getAllCellsByColumnId: memo(
47
- () => [row.getAllCells()],
48
- allCells => {
49
- return allCells.reduce((acc, cell) => {
50
- acc[cell.columnId] = cell
51
- return acc
52
- }, {} as Record<string, Cell<TGenerics>>)
53
- },
54
- {
55
- key:
56
- process.env.NODE_ENV === 'production' &&
57
- 'row.getAllCellsByColumnId',
58
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
59
- }
60
- ),
61
- }
62
- },
63
-
64
- createInstance: <TGenerics extends TableGenerics>(
65
- instance: TableInstance<TGenerics>
66
- ): CellsInstance<TGenerics> => {
67
- return {
68
- createCell: (row, column, columnId) => {
69
- const cell: CoreCell<TGenerics> = {
70
- id: `${row.id}_${column.id}`,
71
- rowId: row.id,
72
- columnId,
73
- row,
74
- column,
75
- getValue: () => row.getValue(columnId),
76
- renderCell: () =>
77
- column.columnDef.cell
78
- ? instance._render(column.columnDef.cell, {
79
- instance,
80
- column,
81
- row,
82
- cell: cell as Cell<TGenerics>,
83
- getValue: cell.getValue,
84
- })
85
- : null,
86
- }
87
-
88
- instance._features.forEach(feature => {
89
- Object.assign(
90
- cell,
91
- feature.createCell?.(
92
- cell as Cell<TGenerics>,
93
- column,
94
- row as Row<TGenerics>,
95
- instance
96
- )
97
- )
98
- }, {})
99
-
100
- return cell as Cell<TGenerics>
101
- },
102
-
103
- getCell: (rowId: string, columnId: string) => {
104
- const row = instance.getRow(rowId)
105
-
106
- if (!row) {
107
- if (process.env.NODE_ENV !== 'production') {
108
- throw new Error(`[Table] could not find row with id ${rowId}`)
109
- }
110
- throw new Error()
111
- }
112
-
113
- const cell = row.getAllCellsByColumnId()[columnId]
114
-
115
- if (!cell) {
116
- if (process.env.NODE_ENV !== 'production') {
117
- throw new Error(
118
- `[Table] could not find cell ${columnId} in row ${rowId}`
119
- )
120
- }
121
- throw new Error()
122
- }
123
-
124
- return cell
125
- },
126
- }
127
- },
128
- }
@@ -1,293 +0,0 @@
1
- import {
2
- Cell,
3
- Column,
4
- Header,
5
- TableGenerics,
6
- TableInstance,
7
- Row,
8
- AccessorFn,
9
- ColumnDef,
10
- Renderable,
11
- } from '../types'
12
- import { memo } from '../utils'
13
-
14
- export type CoreColumnDefType = 'data' | 'display' | 'group'
15
-
16
- export type CoreColumnDef<TGenerics extends TableGenerics> = {
17
- id: string
18
- accessorKey?: string & keyof TGenerics['Row']
19
- accessorFn?: AccessorFn<TGenerics['Row']>
20
- columns?: ColumnDef<TGenerics>[]
21
- header?: Renderable<
22
- TGenerics,
23
- {
24
- instance: TableInstance<TGenerics>
25
- header: Header<TGenerics>
26
- column: Column<TGenerics>
27
- }
28
- >
29
- footer?: Renderable<
30
- TGenerics,
31
- {
32
- instance: TableInstance<TGenerics>
33
- header: Header<TGenerics>
34
- column: Column<TGenerics>
35
- }
36
- >
37
- cell?: Renderable<
38
- TGenerics,
39
- {
40
- instance: TableInstance<TGenerics>
41
- row: Row<TGenerics>
42
- column: Column<TGenerics>
43
- cell: Cell<TGenerics>
44
- getValue: () => TGenerics['Value']
45
- }
46
- >
47
- meta?: TGenerics['ColumnMeta']
48
- }
49
-
50
- export type CoreColumn<TGenerics extends TableGenerics> = {
51
- id: string
52
- depth: number
53
- accessorFn?: AccessorFn<TGenerics['Row']>
54
- columnDef: ColumnDef<TGenerics>
55
- columnDefType: CoreColumnDefType
56
- columns: Column<TGenerics>[]
57
- parent?: Column<TGenerics>
58
- getFlatColumns: () => Column<TGenerics>[]
59
- getLeafColumns: () => Column<TGenerics>[]
60
- }
61
-
62
- export type ColumnsOptions<TGenerics extends TableGenerics> = {
63
- columns: ColumnDef<TGenerics>[]
64
- defaultColumnDef?: Partial<ColumnDef<TGenerics>>
65
- }
66
-
67
- export type ColumnsInstance<TGenerics extends TableGenerics> = {
68
- getDefaultColumnDef: () => Partial<ColumnDef<TGenerics>>
69
- getColumnDefs: () => ColumnDef<TGenerics>[]
70
- createColumn: (
71
- columnDef: ColumnDef<TGenerics>,
72
- depth: number,
73
- parent?: Column<TGenerics>
74
- ) => Column<TGenerics>
75
- getAllColumns: () => Column<TGenerics>[]
76
- getAllFlatColumns: () => Column<TGenerics>[]
77
- getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
78
- getAllLeafColumns: () => Column<TGenerics>[]
79
- getColumn: (columnId: string) => Column<TGenerics>
80
- }
81
-
82
- //
83
-
84
- export const Columns = {
85
- createInstance: <TGenerics extends TableGenerics>(
86
- instance: TableInstance<TGenerics>
87
- ): ColumnsInstance<TGenerics> => {
88
- return {
89
- getDefaultColumnDef: memo(
90
- () => [instance.options.defaultColumnDef],
91
- defaultColumn => {
92
- defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
93
-
94
- return {
95
- header: props => props.header.column.id,
96
- footer: props => props.header.column.id,
97
- cell: props => props.getValue().toString?.() ?? null,
98
- ...instance._features.reduce((obj, feature) => {
99
- return Object.assign(obj, feature.getDefaultColumnDef?.())
100
- }, {}),
101
- ...defaultColumn,
102
- } as Partial<ColumnDef<TGenerics>>
103
- },
104
- {
105
- debug: () =>
106
- instance.options.debugAll ?? instance.options.debugColumns,
107
- key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef',
108
- }
109
- ),
110
-
111
- getColumnDefs: () => instance.options.columns,
112
-
113
- createColumn: (
114
- columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
115
- depth: number,
116
- parent
117
- ) => {
118
- const defaultColumnDef = instance.getDefaultColumnDef()
119
-
120
- columnDef = {
121
- ...defaultColumnDef,
122
- ...columnDef,
123
- }
124
-
125
- let id =
126
- columnDef.id ??
127
- columnDef.accessorKey ??
128
- (typeof columnDef.header === 'string' ? columnDef.header : undefined)
129
-
130
- let accessorFn: AccessorFn<TGenerics['Row']> | undefined
131
-
132
- if (columnDef.accessorFn) {
133
- accessorFn = columnDef.accessorFn
134
- } else if (columnDef.accessorKey) {
135
- accessorFn = (originalRow?: TGenerics['Row']) =>
136
- (originalRow as any)[columnDef.accessorKey]
137
- }
138
-
139
- if (!id) {
140
- if (process.env.NODE_ENV !== 'production') {
141
- throw new Error(
142
- columnDef.accessorFn
143
- ? `Columns require an id when using an accessorFn`
144
- : `Columns require an id when using a non-string header`
145
- )
146
- }
147
- throw new Error()
148
- }
149
-
150
- let column: CoreColumn<TGenerics> = {
151
- ...columnDef,
152
- id: `${id}`,
153
- accessorFn,
154
- parent: parent as any,
155
- depth,
156
- columnDef,
157
- columnDefType: columnDef.columnDefType as CoreColumnDefType,
158
- columns: [],
159
- getFlatColumns: memo(
160
- () => [true],
161
- () => {
162
- return [
163
- column as Column<TGenerics>,
164
- ...column.columns?.flatMap(d => d.getFlatColumns()),
165
- ]
166
- },
167
- {
168
- key:
169
- process.env.NODE_ENV === 'production' &&
170
- 'column.getFlatColumns',
171
- debug: () =>
172
- instance.options.debugAll ?? instance.options.debugColumns,
173
- }
174
- ),
175
- getLeafColumns: memo(
176
- () => [instance._getOrderColumnsFn()],
177
- orderColumns => {
178
- if (column.columns?.length) {
179
- let leafColumns = column.columns.flatMap(column =>
180
- column.getLeafColumns()
181
- )
182
-
183
- return orderColumns(leafColumns)
184
- }
185
-
186
- return [column as Column<TGenerics>]
187
- },
188
- {
189
- key:
190
- process.env.NODE_ENV === 'production' &&
191
- 'column.getLeafColumns',
192
- debug: () =>
193
- instance.options.debugAll ?? instance.options.debugColumns,
194
- }
195
- ),
196
- }
197
-
198
- column = instance._features.reduce((obj, feature) => {
199
- return Object.assign(obj, feature.createColumn?.(column, instance))
200
- }, column)
201
-
202
- // Yes, we have to convert instance to uknown, because we know more than the compiler here.
203
- return column as Column<TGenerics>
204
- },
205
-
206
- getAllColumns: memo(
207
- () => [instance.getColumnDefs()],
208
- columnDefs => {
209
- const recurseColumns = (
210
- columnDefs: ColumnDef<TGenerics>[],
211
- parent?: Column<TGenerics>,
212
- depth = 0
213
- ): Column<TGenerics>[] => {
214
- return columnDefs.map(columnDef => {
215
- const column = instance.createColumn(columnDef, depth, parent)
216
-
217
- column.columns = columnDef.columns
218
- ? recurseColumns(columnDef.columns, column, depth + 1)
219
- : []
220
-
221
- return column
222
- })
223
- }
224
-
225
- return recurseColumns(columnDefs)
226
- },
227
- {
228
- key: process.env.NODE_ENV === 'development' && 'getAllColumns',
229
- debug: () =>
230
- instance.options.debugAll ?? instance.options.debugColumns,
231
- }
232
- ),
233
-
234
- getAllFlatColumns: memo(
235
- () => [instance.getAllColumns()],
236
- allColumns => {
237
- return allColumns.flatMap(column => {
238
- return column.getFlatColumns()
239
- })
240
- },
241
- {
242
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
243
- debug: () =>
244
- instance.options.debugAll ?? instance.options.debugColumns,
245
- }
246
- ),
247
-
248
- getAllFlatColumnsById: memo(
249
- () => [instance.getAllFlatColumns()],
250
- flatColumns => {
251
- return flatColumns.reduce((acc, column) => {
252
- acc[column.id] = column
253
- return acc
254
- }, {} as Record<string, Column<TGenerics>>)
255
- },
256
- {
257
- key:
258
- process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
259
- debug: () =>
260
- instance.options.debugAll ?? instance.options.debugColumns,
261
- }
262
- ),
263
-
264
- getAllLeafColumns: memo(
265
- () => [instance.getAllColumns(), instance._getOrderColumnsFn()],
266
- (allColumns, orderColumns) => {
267
- let leafColumns = allColumns.flatMap(column =>
268
- column.getLeafColumns()
269
- )
270
- return orderColumns(leafColumns)
271
- },
272
- {
273
- key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
274
- debug: () =>
275
- instance.options.debugAll ?? instance.options.debugColumns,
276
- }
277
- ),
278
-
279
- getColumn: columnId => {
280
- const column = instance.getAllFlatColumnsById()[columnId]
281
-
282
- if (!column) {
283
- if (process.env.NODE_ENV !== 'production') {
284
- console.warn(`[Table] Column with id ${columnId} does not exist.`)
285
- }
286
- throw new Error()
287
- }
288
-
289
- return column
290
- },
291
- }
292
- },
293
- }