@tanstack/table-core 9.0.0-alpha.34 → 9.0.0-alpha.37

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 (145) hide show
  1. package/dist/core/columns/constructColumn.cjs.map +1 -1
  2. package/dist/core/columns/constructColumn.js.map +1 -1
  3. package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
  4. package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
  5. package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
  6. package/dist/core/headers/buildHeaderGroups.js.map +1 -1
  7. package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
  8. package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
  9. package/dist/core/row-models/createCoreRowModel.cjs.map +1 -1
  10. package/dist/core/row-models/createCoreRowModel.js.map +1 -1
  11. package/dist/core/rows/constructRow.cjs.map +1 -1
  12. package/dist/core/rows/constructRow.js.map +1 -1
  13. package/dist/core/table/constructTable.cjs +2 -1
  14. package/dist/core/table/constructTable.cjs.map +1 -1
  15. package/dist/core/table/constructTable.js +2 -1
  16. package/dist/core/table/constructTable.js.map +1 -1
  17. package/dist/core/table/coreTablesFeature.utils.cjs +1 -1
  18. package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
  19. package/dist/core/table/coreTablesFeature.utils.js +2 -2
  20. package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
  21. package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
  22. package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
  23. package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
  24. package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
  25. package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
  26. package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
  27. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +2 -2
  28. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
  29. package/dist/features/column-filtering/columnFilteringFeature.utils.js +3 -3
  30. package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
  31. package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
  32. package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
  33. package/dist/features/column-filtering/filterRowsUtils.cjs.map +1 -1
  34. package/dist/features/column-filtering/filterRowsUtils.js.map +1 -1
  35. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +2 -2
  36. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  37. package/dist/features/column-grouping/columnGroupingFeature.utils.js +3 -3
  38. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  39. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  40. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  41. package/dist/features/column-ordering/columnOrderingFeature.utils.cjs +3 -2
  42. package/dist/features/column-ordering/columnOrderingFeature.utils.cjs.map +1 -1
  43. package/dist/features/column-ordering/columnOrderingFeature.utils.js +3 -2
  44. package/dist/features/column-ordering/columnOrderingFeature.utils.js.map +1 -1
  45. package/dist/features/column-pinning/columnPinningFeature.utils.cjs +3 -3
  46. package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
  47. package/dist/features/column-pinning/columnPinningFeature.utils.js +4 -4
  48. package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
  49. package/dist/features/column-resizing/columnResizingFeature.utils.cjs +4 -3
  50. package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
  51. package/dist/features/column-resizing/columnResizingFeature.utils.js +4 -3
  52. package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
  53. package/dist/features/column-sizing/columnSizingFeature.utils.cjs +4 -4
  54. package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
  55. package/dist/features/column-sizing/columnSizingFeature.utils.js +5 -5
  56. package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
  57. package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +2 -2
  58. package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
  59. package/dist/features/column-visibility/columnVisibilityFeature.utils.js +3 -3
  60. package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
  61. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
  62. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  63. package/dist/features/global-filtering/globalFilteringFeature.utils.js +2 -2
  64. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  65. package/dist/features/row-expanding/createExpandedRowModel.cjs.map +1 -1
  66. package/dist/features/row-expanding/createExpandedRowModel.js.map +1 -1
  67. package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +3 -2
  68. package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
  69. package/dist/features/row-expanding/rowExpandingFeature.utils.js +4 -2
  70. package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
  71. package/dist/features/row-pagination/createPaginatedRowModel.cjs.map +1 -1
  72. package/dist/features/row-pagination/createPaginatedRowModel.js.map +1 -1
  73. package/dist/features/row-pagination/rowPaginationFeature.utils.cjs +19 -13
  74. package/dist/features/row-pagination/rowPaginationFeature.utils.cjs.map +1 -1
  75. package/dist/features/row-pagination/rowPaginationFeature.utils.js +20 -14
  76. package/dist/features/row-pagination/rowPaginationFeature.utils.js.map +1 -1
  77. package/dist/features/row-pinning/rowPinningFeature.utils.cjs +3 -3
  78. package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
  79. package/dist/features/row-pinning/rowPinningFeature.utils.js +4 -4
  80. package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
  81. package/dist/features/row-selection/rowSelectionFeature.utils.cjs +3 -2
  82. package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
  83. package/dist/features/row-selection/rowSelectionFeature.utils.js +4 -2
  84. package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
  85. package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
  86. package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
  87. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +2 -2
  88. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  89. package/dist/features/row-sorting/rowSortingFeature.utils.js +3 -3
  90. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  91. package/dist/flex-render.cjs +19 -0
  92. package/dist/flex-render.cjs.map +1 -0
  93. package/dist/flex-render.d.cts +24 -0
  94. package/dist/flex-render.d.ts +24 -0
  95. package/dist/flex-render.js +16 -0
  96. package/dist/flex-render.js.map +1 -0
  97. package/dist/fns/filterFns.cjs.map +1 -1
  98. package/dist/fns/filterFns.js.map +1 -1
  99. package/dist/index.cjs +1 -2
  100. package/dist/index.d.cts +2 -3
  101. package/dist/index.d.ts +2 -3
  102. package/dist/index.js +2 -3
  103. package/dist/utils.cjs +12 -0
  104. package/dist/utils.cjs.map +1 -1
  105. package/dist/utils.d.cts +2 -1
  106. package/dist/utils.d.ts +2 -1
  107. package/dist/utils.js +12 -1
  108. package/dist/utils.js.map +1 -1
  109. package/package.json +5 -1
  110. package/src/core/columns/coreColumnsFeature.utils.ts +1 -1
  111. package/src/core/row-models/createCoreRowModel.ts +1 -1
  112. package/src/core/rows/constructRow.ts +1 -1
  113. package/src/core/table/constructTable.ts +4 -5
  114. package/src/core/table/coreTablesFeature.utils.ts +2 -2
  115. package/src/features/column-faceting/createFacetedMinMaxValues.ts +1 -1
  116. package/src/features/column-faceting/createFacetedRowModel.ts +1 -1
  117. package/src/features/column-faceting/createFacetedUniqueValues.ts +1 -1
  118. package/src/features/column-filtering/columnFilteringFeature.utils.ts +8 -13
  119. package/src/features/column-filtering/createFilteredRowModel.ts +1 -1
  120. package/src/features/column-grouping/columnGroupingFeature.utils.ts +7 -7
  121. package/src/features/column-grouping/createGroupedRowModel.ts +1 -1
  122. package/src/features/column-ordering/columnOrderingFeature.utils.ts +3 -2
  123. package/src/features/column-pinning/columnPinningFeature.utils.ts +6 -4
  124. package/src/features/column-resizing/columnResizingFeature.utils.ts +6 -3
  125. package/src/features/column-sizing/columnSizingFeature.utils.ts +5 -5
  126. package/src/features/column-visibility/columnVisibilityFeature.utils.ts +3 -3
  127. package/src/features/global-filtering/globalFilteringFeature.utils.ts +4 -5
  128. package/src/features/row-expanding/createExpandedRowModel.ts +1 -1
  129. package/src/features/row-expanding/rowExpandingFeature.utils.ts +4 -3
  130. package/src/features/row-pagination/createPaginatedRowModel.ts +1 -1
  131. package/src/features/row-pagination/rowPaginationFeature.utils.ts +20 -16
  132. package/src/features/row-pinning/rowPinningFeature.utils.ts +6 -4
  133. package/src/features/row-selection/rowSelectionFeature.utils.ts +5 -6
  134. package/src/features/row-sorting/createSortedRowModel.ts +3 -4
  135. package/src/features/row-sorting/rowSortingFeature.utils.ts +7 -9
  136. package/src/flex-render.ts +60 -0
  137. package/src/index.ts +0 -1
  138. package/src/utils.ts +24 -0
  139. package/dist/helpers/tableHelper.cjs +0 -21
  140. package/dist/helpers/tableHelper.cjs.map +0 -1
  141. package/dist/helpers/tableHelper.d.cts +0 -30
  142. package/dist/helpers/tableHelper.d.ts +0 -30
  143. package/dist/helpers/tableHelper.js +0 -21
  144. package/dist/helpers/tableHelper.js.map +0 -1
  145. package/src/helpers/tableHelper.ts +0 -61
@@ -1,5 +1,5 @@
1
1
  import { filterFn_includesString } from '../../fns/filterFns'
2
- import { isFunction } from '../../utils'
2
+ import { cloneState, isFunction } from '../../utils'
3
3
  import type { Column_Internal } from '../../types/Column'
4
4
  import type { FilterFn } from '../column-filtering/columnFilteringFeature.types'
5
5
  import type { CellData, RowData } from '../../types/type-utils'
@@ -31,9 +31,8 @@ export function table_getGlobalFilterFn<
31
31
  table: Table_Internal<TFeatures, TData>,
32
32
  ): FilterFn<TFeatures, TData> | FilterFn<TFeatures, TData> | undefined {
33
33
  const { globalFilterFn: globalFilterFn } = table.options
34
- const filterFns = table._rowModelFns.filterFns as
35
- | Record<string, FilterFn<TFeatures, TData>>
36
- | undefined
34
+ const filterFns: Record<string, FilterFn<TFeatures, TData>> | undefined =
35
+ table._rowModelFns.filterFns
37
36
 
38
37
  return isFunction(globalFilterFn)
39
38
  ? globalFilterFn
@@ -55,6 +54,6 @@ export function table_resetGlobalFilter<
55
54
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
56
55
  table_setGlobalFilter(
57
56
  table,
58
- defaultState ? undefined : table.initialState.globalFilter,
57
+ defaultState ? undefined : cloneState(table.initialState.globalFilter),
59
58
  )
60
59
  }
@@ -11,7 +11,7 @@ export function createExpandedRowModel<
11
11
  TData extends RowData = any,
12
12
  >(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {
13
13
  return (_table) => {
14
- const table = _table as Table_Internal<TFeatures, TData>
14
+ const table: Table_Internal<TFeatures, TData> = _table
15
15
  return tableMemo({
16
16
  feature: 'rowExpandingFeature',
17
17
  table,
@@ -1,3 +1,4 @@
1
+ import { cloneState } from '../../utils'
1
2
  import type { RowData, Updater } from '../../types/type-utils'
2
3
  import type { TableFeatures } from '../../types/TableFeatures'
3
4
  import type { Table_Internal } from '../../types/Table'
@@ -8,7 +9,7 @@ import type {
8
9
  } from './rowExpandingFeature.types'
9
10
 
10
11
  export function getDefaultExpandedState(): ExpandedState {
11
- return structuredClone({})
12
+ return {}
12
13
  }
13
14
 
14
15
  export function table_autoResetExpanded<
@@ -48,7 +49,7 @@ export function table_resetExpanded<
48
49
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
49
50
  table_setExpanded(
50
51
  table,
51
- defaultState ? {} : (table.initialState.expanded ?? {}),
52
+ defaultState ? {} : cloneState(table.initialState.expanded ?? {}),
52
53
  )
53
54
  }
54
55
 
@@ -161,7 +162,7 @@ export function row_getIsExpanded<
161
162
  TFeatures extends TableFeatures,
162
163
  TData extends RowData,
163
164
  >(row: Row<TFeatures, TData>) {
164
- const expanded = row.table.atoms.expanded?.get() ?? ({} as ExpandedState)
165
+ const expanded: ExpandedState = row.table.atoms.expanded?.get() ?? {}
165
166
 
166
167
  return !!(
167
168
  row.table.options.getIsRowExpanded?.(row) ??
@@ -12,7 +12,7 @@ export function createPaginatedRowModel<
12
12
  TData extends RowData = any,
13
13
  >(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {
14
14
  return (_table) => {
15
- const table = _table as Table_Internal<TFeatures, TData>
15
+ const table: Table_Internal<TFeatures, TData> = _table
16
16
  return tableMemo({
17
17
  feature: 'rowPaginationFeature',
18
18
  table,
@@ -1,4 +1,4 @@
1
- import { functionalUpdate } from '../../utils'
1
+ import { cloneState, functionalUpdate } from '../../utils'
2
2
  import type { RowData, Updater } from '../../types/type-utils'
3
3
  import type { TableFeatures } from '../../types/TableFeatures'
4
4
  import type { Table_Internal } from '../../types/Table'
@@ -8,10 +8,10 @@ const defaultPageIndex = 0
8
8
  const defaultPageSize = 10
9
9
 
10
10
  export function getDefaultPaginationState(): PaginationState {
11
- return structuredClone({
11
+ return {
12
12
  pageIndex: defaultPageIndex,
13
13
  pageSize: defaultPageSize,
14
- })
14
+ }
15
15
  }
16
16
 
17
17
  export function table_autoResetPageIndex<
@@ -48,7 +48,9 @@ export function table_resetPagination<
48
48
  table,
49
49
  defaultState
50
50
  ? getDefaultPaginationState()
51
- : (table.initialState.pagination ?? getDefaultPaginationState()),
51
+ : cloneState(
52
+ table.initialState.pagination ?? getDefaultPaginationState(),
53
+ ),
52
54
  )
53
55
  }
54
56
 
@@ -78,24 +80,26 @@ export function table_resetPageIndex<
78
80
  TFeatures extends TableFeatures,
79
81
  TData extends RowData,
80
82
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
81
- table_setPageIndex(
82
- table,
83
- defaultState
84
- ? defaultPageIndex
85
- : (table.initialState.pagination?.pageIndex ?? defaultPageIndex),
86
- )
83
+ const currentPageIndex =
84
+ table.atoms.pagination?.get()?.pageIndex ?? defaultPageIndex
85
+ const newPageIndex = defaultState
86
+ ? defaultPageIndex
87
+ : (table.initialState.pagination?.pageIndex ?? defaultPageIndex)
88
+ if (newPageIndex === currentPageIndex) return
89
+ table_setPageIndex(table, newPageIndex)
87
90
  }
88
91
 
89
92
  export function table_resetPageSize<
90
93
  TFeatures extends TableFeatures,
91
94
  TData extends RowData,
92
95
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
93
- table_setPageSize(
94
- table,
95
- defaultState
96
- ? defaultPageSize
97
- : (table.initialState.pagination?.pageSize ?? defaultPageSize),
98
- )
96
+ const currentPageSize =
97
+ table.atoms.pagination?.get()?.pageSize ?? defaultPageSize
98
+ const newPageSize = defaultState
99
+ ? defaultPageSize
100
+ : (table.initialState.pagination?.pageSize ?? defaultPageSize)
101
+ if (newPageSize === currentPageSize) return
102
+ table_setPageSize(table, newPageSize)
99
103
  }
100
104
 
101
105
  export function table_setPageSize<
@@ -1,5 +1,5 @@
1
1
  import { row_getIsAllParentsExpanded } from '../row-expanding/rowExpandingFeature.utils'
2
- import { callMemoOrStaticFn } from '../../utils'
2
+ import { callMemoOrStaticFn, cloneState } from '../../utils'
3
3
  import type { RowData, Updater } from '../../types/type-utils'
4
4
  import type { TableFeatures } from '../../types/TableFeatures'
5
5
  import type { Table_Internal } from '../../types/Table'
@@ -12,10 +12,10 @@ import type {
12
12
  // State Utils
13
13
 
14
14
  export function getDefaultRowPinningState(): RowPinningState {
15
- return structuredClone({
15
+ return {
16
16
  top: [],
17
17
  bottom: [],
18
- })
18
+ }
19
19
  }
20
20
 
21
21
  export function table_setRowPinning<
@@ -36,7 +36,9 @@ export function table_resetRowPinning<
36
36
  table,
37
37
  defaultState
38
38
  ? getDefaultRowPinningState()
39
- : (table.initialState.rowPinning ?? getDefaultRowPinningState()),
39
+ : cloneState(
40
+ table.initialState.rowPinning ?? getDefaultRowPinningState(),
41
+ ),
40
42
  )
41
43
  }
42
44
 
@@ -1,3 +1,4 @@
1
+ import { cloneState } from '../../utils'
1
2
  import type { RowData, Updater } from '../../types/type-utils'
2
3
  import type { TableFeatures } from '../../types/TableFeatures'
3
4
  import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
@@ -8,7 +9,7 @@ import type { RowSelectionState } from './rowSelectionFeature.types'
8
9
  // State APIs
9
10
 
10
11
  export function getDefaultRowSelectionState(): RowSelectionState {
11
- return structuredClone({})
12
+ return {}
12
13
  }
13
14
 
14
15
  export function table_setRowSelection<
@@ -27,7 +28,7 @@ export function table_resetRowSelection<
27
28
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
28
29
  table_setRowSelection(
29
30
  table,
30
- defaultState ? {} : (table.initialState.rowSelection ?? {}),
31
+ defaultState ? {} : cloneState(table.initialState.rowSelection ?? {}),
31
32
  )
32
33
  }
33
34
 
@@ -147,8 +148,7 @@ export function table_getIsAllRowsSelected<
147
148
  TData extends RowData,
148
149
  >(table: Table_Internal<TFeatures, TData>) {
149
150
  const preGroupedFlatRows = table.getFilteredRowModel().flatRows
150
- const rowSelection =
151
- table.atoms.rowSelection?.get() ?? ({} as RowSelectionState)
151
+ const rowSelection: RowSelectionState = table.atoms.rowSelection?.get() ?? {}
152
152
 
153
153
  let isAllRowsSelected = Boolean(
154
154
  preGroupedFlatRows.length && Object.keys(rowSelection).length,
@@ -174,8 +174,7 @@ export function table_getIsAllPageRowsSelected<
174
174
  const paginationFlatRows = table
175
175
  .getPaginatedRowModel()
176
176
  .flatRows.filter((row) => row_getCanSelect(row))
177
- const rowSelection =
178
- table.atoms.rowSelection?.get() ?? ({} as RowSelectionState)
177
+ const rowSelection: RowSelectionState = table.atoms.rowSelection?.get() ?? {}
179
178
 
180
179
  let isAllPageRowsSelected = !!paginationFlatRows.length
181
180
 
@@ -16,7 +16,7 @@ export function createSortedRowModel<
16
16
  sortFns: Record<keyof SortFns, SortFn<TFeatures, TData>>,
17
17
  ): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {
18
18
  return (_table) => {
19
- const table = _table as Table_Internal<TFeatures, TData>
19
+ const table: Table_Internal<TFeatures, TData> = _table
20
20
  if (!table._rowModelFns.sortFns) table._rowModelFns.sortFns = sortFns
21
21
  return tableMemo({
22
22
  feature: 'rowSortingFeature',
@@ -62,9 +62,8 @@ function _createSortedRowModel<
62
62
  > = {}
63
63
 
64
64
  availableSorting.forEach((sortEntry) => {
65
- const column = table.getColumn(sortEntry.id) as
66
- | Column_Internal<TFeatures, TData>
67
- | undefined
65
+ const column: Column_Internal<TFeatures, TData> | undefined =
66
+ table.getColumn(sortEntry.id)
68
67
  if (!column) return
69
68
 
70
69
  columnInfoById[sortEntry.id] = {
@@ -1,5 +1,5 @@
1
1
  import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'
2
- import { isFunction } from '../../utils'
2
+ import { cloneState, isFunction } from '../../utils'
3
3
  import type { CellData, RowData, Updater } from '../../types/type-utils'
4
4
  import type { TableFeatures } from '../../types/TableFeatures'
5
5
  import type { Table_Internal } from '../../types/Table'
@@ -13,7 +13,7 @@ import type {
13
13
  // State Utils
14
14
 
15
15
  export function getDefaultSortingState(): SortingState {
16
- return structuredClone([])
16
+ return []
17
17
  }
18
18
 
19
19
  export function table_setSorting<
@@ -29,7 +29,7 @@ export function table_resetSorting<
29
29
  >(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {
30
30
  table_setSorting(
31
31
  table,
32
- defaultState ? [] : (table.initialState.sorting ?? []),
32
+ defaultState ? [] : cloneState(table.initialState.sorting ?? []),
33
33
  )
34
34
  }
35
35
 
@@ -40,9 +40,8 @@ export function column_getAutoSortFn<
40
40
  TData extends RowData,
41
41
  TValue extends CellData = CellData,
42
42
  >(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {
43
- const sortFns = column.table._rowModelFns.sortFns as
44
- | Record<string, SortFn<TFeatures, TData>>
45
- | undefined
43
+ const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =
44
+ column.table._rowModelFns.sortFns
46
45
 
47
46
  let sortFn: SortFn<TFeatures, TData> | undefined
48
47
 
@@ -94,9 +93,8 @@ export function column_getSortFn<
94
93
  TData extends RowData,
95
94
  TValue extends CellData = CellData,
96
95
  >(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {
97
- const sortFns = column.table._rowModelFns.sortFns as
98
- | Record<string, SortFn<TFeatures, TData>>
99
- | undefined
96
+ const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =
97
+ column.table._rowModelFns.sortFns
100
98
 
101
99
  return isFunction(column.columnDef.sortFn)
102
100
  ? column.columnDef.sortFn
@@ -0,0 +1,60 @@
1
+ import type { Cell } from './types/Cell'
2
+ import type { Header } from './types/Header'
3
+ import type { TableFeatures } from './types/TableFeatures'
4
+ import type { CellData, RowData } from './types/type-utils'
5
+
6
+ export function flexRender<TProps extends object>(
7
+ comp: unknown,
8
+ props: TProps,
9
+ ): unknown | null {
10
+ if (comp == null) return null
11
+
12
+ if (typeof comp === 'function') {
13
+ return comp(props)
14
+ }
15
+
16
+ return comp
17
+ }
18
+
19
+ export type FlexRenderProps<
20
+ TFeatures extends TableFeatures,
21
+ TData extends RowData,
22
+ TValue extends CellData = CellData,
23
+ > =
24
+ | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }
25
+ | {
26
+ header: Header<TFeatures, TData, TValue>
27
+ cell?: never
28
+ footer?: never
29
+ }
30
+ | {
31
+ footer: Header<TFeatures, TData, TValue>
32
+ cell?: never
33
+ header?: never
34
+ }
35
+
36
+ export function FlexRender<
37
+ TFeatures extends TableFeatures,
38
+ TData extends RowData,
39
+ TValue extends CellData = CellData,
40
+ >(props: FlexRenderProps<TFeatures, TData, TValue>): unknown | null {
41
+ if ('cell' in props && props.cell) {
42
+ return flexRender(props.cell.column.columnDef.cell, props.cell.getContext())
43
+ }
44
+
45
+ if ('header' in props && props.header) {
46
+ return flexRender(
47
+ props.header.column.columnDef.header,
48
+ props.header.getContext(),
49
+ )
50
+ }
51
+
52
+ if ('footer' in props && props.footer) {
53
+ return flexRender(
54
+ props.footer.column.columnDef.footer,
55
+ props.footer.getContext(),
56
+ )
57
+ }
58
+
59
+ return null
60
+ }
package/src/index.ts CHANGED
@@ -23,7 +23,6 @@ export * from './types/type-utils'
23
23
  export * from './core/coreFeatures'
24
24
  export * from './helpers/columnHelper'
25
25
  export * from './helpers/tableFeatures'
26
- export * from './helpers/tableHelper'
27
26
  export * from './helpers/tableOptions'
28
27
  export * from './utils'
29
28
 
package/src/utils.ts CHANGED
@@ -9,6 +9,30 @@ export function functionalUpdate<T>(updater: Updater<T>, input: T): T {
9
9
  : updater
10
10
  }
11
11
 
12
+ export function cloneState<T>(value: T): T {
13
+ if (Array.isArray(value)) {
14
+ return value.map(cloneState) as T
15
+ }
16
+
17
+ if (value && typeof value === 'object') {
18
+ const proto = Object.getPrototypeOf(value)
19
+
20
+ if (proto !== Object.prototype && proto !== null) {
21
+ return value
22
+ }
23
+
24
+ const copy: Record<string, unknown> = {}
25
+
26
+ for (const key of Object.keys(value)) {
27
+ copy[key] = cloneState((value as Record<string, unknown>)[key])
28
+ }
29
+
30
+ return copy as T
31
+ }
32
+
33
+ return value
34
+ }
35
+
12
36
  export function noop() {}
13
37
 
14
38
  export function makeStateUpdater<
@@ -1,21 +0,0 @@
1
- const require_columnHelper = require('./columnHelper.cjs');
2
-
3
- //#region src/helpers/tableHelper.ts
4
- /**
5
- * Internal function to create a table helper that each adapter package will use to create their own table helper
6
- */
7
- function constructTableHelper(tableCreator, tableHelperOptions) {
8
- return {
9
- createColumnHelper: require_columnHelper.createColumnHelper,
10
- features: tableHelperOptions._features,
11
- options: tableHelperOptions,
12
- tableCreator: (tableOptions, selector) => tableCreator({
13
- ...tableHelperOptions,
14
- ...tableOptions
15
- }, selector)
16
- };
17
- }
18
-
19
- //#endregion
20
- exports.constructTableHelper = constructTableHelper;
21
- //# sourceMappingURL=tableHelper.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tableHelper.cjs","names":[],"sources":["../../src/helpers/tableHelper.ts"],"sourcesContent":["import { createColumnHelper } from './columnHelper'\nimport type { ColumnHelper } from './columnHelper'\nimport type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Table } from '../types/Table'\nimport type { TableOptions } from '../types/TableOptions'\n\n/**\n * Options for creating a table helper to share common options across multiple tables\n * coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions\n */\nexport type TableHelperOptions<TFeatures extends TableFeatures> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n _features: TFeatures\n}\n\n/**\n * Internal type that each adapter package will build off of to create a table helper\n */\nexport type TableHelper_Core<TFeatures extends TableFeatures> = {\n createColumnHelper: <TData extends RowData>() => ColumnHelper<\n TFeatures,\n TData\n >\n features: TFeatures\n options: Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n >\n tableCreator: <TData extends RowData>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: any,\n ) => Table<TFeatures, TData>\n}\n\n/**\n * Internal function to create a table helper that each adapter package will use to create their own table helper\n */\nexport function constructTableHelper<TFeatures extends TableFeatures>(\n tableCreator: <TData extends RowData>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: any,\n ) => Table<TFeatures, TData>,\n tableHelperOptions: TableHelperOptions<TFeatures>,\n): TableHelper_Core<TFeatures> {\n return {\n createColumnHelper,\n features: tableHelperOptions._features,\n options: tableHelperOptions,\n tableCreator: (tableOptions, selector) =>\n tableCreator({ ...tableHelperOptions, ...tableOptions }, selector),\n }\n}\n"],"mappings":";;;;;;AA2CA,SAAgB,qBACd,cAOA,oBAC6B;AAC7B,QAAO;EACL;EACA,UAAU,mBAAmB;EAC7B,SAAS;EACT,eAAe,cAAc,aAC3B,aAAa;GAAE,GAAG;GAAoB,GAAG;GAAc,EAAE,SAAS;EACrE"}
@@ -1,30 +0,0 @@
1
- import { RowData } from "../types/type-utils.cjs";
2
- import { TableOptions } from "../types/TableOptions.cjs";
3
- import { TableFeatures } from "../types/TableFeatures.cjs";
4
- import { Table } from "../types/Table.cjs";
5
- import { ColumnHelper } from "./columnHelper.cjs";
6
-
7
- //#region src/helpers/tableHelper.d.ts
8
- /**
9
- * Options for creating a table helper to share common options across multiple tables
10
- * coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions
11
- */
12
- type TableHelperOptions<TFeatures extends TableFeatures> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'> & {
13
- _features: TFeatures;
14
- };
15
- /**
16
- * Internal type that each adapter package will build off of to create a table helper
17
- */
18
- type TableHelper_Core<TFeatures extends TableFeatures> = {
19
- createColumnHelper: <TData extends RowData>() => ColumnHelper<TFeatures, TData>;
20
- features: TFeatures;
21
- options: Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'>;
22
- tableCreator: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, '_features' | '_rowModels'>, selector?: any) => Table<TFeatures, TData>;
23
- };
24
- /**
25
- * Internal function to create a table helper that each adapter package will use to create their own table helper
26
- */
27
- declare function constructTableHelper<TFeatures extends TableFeatures>(tableCreator: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, '_features' | '_rowModels'>, selector?: any) => Table<TFeatures, TData>, tableHelperOptions: TableHelperOptions<TFeatures>): TableHelper_Core<TFeatures>;
28
- //#endregion
29
- export { TableHelperOptions, TableHelper_Core, constructTableHelper };
30
- //# sourceMappingURL=tableHelper.d.cts.map
@@ -1,30 +0,0 @@
1
- import { RowData } from "../types/type-utils.js";
2
- import { TableOptions } from "../types/TableOptions.js";
3
- import { TableFeatures } from "../types/TableFeatures.js";
4
- import { Table } from "../types/Table.js";
5
- import { ColumnHelper } from "./columnHelper.js";
6
-
7
- //#region src/helpers/tableHelper.d.ts
8
- /**
9
- * Options for creating a table helper to share common options across multiple tables
10
- * coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions
11
- */
12
- type TableHelperOptions<TFeatures extends TableFeatures> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'> & {
13
- _features: TFeatures;
14
- };
15
- /**
16
- * Internal type that each adapter package will build off of to create a table helper
17
- */
18
- type TableHelper_Core<TFeatures extends TableFeatures> = {
19
- createColumnHelper: <TData extends RowData>() => ColumnHelper<TFeatures, TData>;
20
- features: TFeatures;
21
- options: Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'>;
22
- tableCreator: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, '_features' | '_rowModels'>, selector?: any) => Table<TFeatures, TData>;
23
- };
24
- /**
25
- * Internal function to create a table helper that each adapter package will use to create their own table helper
26
- */
27
- declare function constructTableHelper<TFeatures extends TableFeatures>(tableCreator: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, '_features' | '_rowModels'>, selector?: any) => Table<TFeatures, TData>, tableHelperOptions: TableHelperOptions<TFeatures>): TableHelper_Core<TFeatures>;
28
- //#endregion
29
- export { TableHelperOptions, TableHelper_Core, constructTableHelper };
30
- //# sourceMappingURL=tableHelper.d.ts.map
@@ -1,21 +0,0 @@
1
- import { createColumnHelper } from "./columnHelper.js";
2
-
3
- //#region src/helpers/tableHelper.ts
4
- /**
5
- * Internal function to create a table helper that each adapter package will use to create their own table helper
6
- */
7
- function constructTableHelper(tableCreator, tableHelperOptions) {
8
- return {
9
- createColumnHelper,
10
- features: tableHelperOptions._features,
11
- options: tableHelperOptions,
12
- tableCreator: (tableOptions, selector) => tableCreator({
13
- ...tableHelperOptions,
14
- ...tableOptions
15
- }, selector)
16
- };
17
- }
18
-
19
- //#endregion
20
- export { constructTableHelper };
21
- //# sourceMappingURL=tableHelper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tableHelper.js","names":[],"sources":["../../src/helpers/tableHelper.ts"],"sourcesContent":["import { createColumnHelper } from './columnHelper'\nimport type { ColumnHelper } from './columnHelper'\nimport type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Table } from '../types/Table'\nimport type { TableOptions } from '../types/TableOptions'\n\n/**\n * Options for creating a table helper to share common options across multiple tables\n * coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions\n */\nexport type TableHelperOptions<TFeatures extends TableFeatures> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n _features: TFeatures\n}\n\n/**\n * Internal type that each adapter package will build off of to create a table helper\n */\nexport type TableHelper_Core<TFeatures extends TableFeatures> = {\n createColumnHelper: <TData extends RowData>() => ColumnHelper<\n TFeatures,\n TData\n >\n features: TFeatures\n options: Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n >\n tableCreator: <TData extends RowData>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: any,\n ) => Table<TFeatures, TData>\n}\n\n/**\n * Internal function to create a table helper that each adapter package will use to create their own table helper\n */\nexport function constructTableHelper<TFeatures extends TableFeatures>(\n tableCreator: <TData extends RowData>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: any,\n ) => Table<TFeatures, TData>,\n tableHelperOptions: TableHelperOptions<TFeatures>,\n): TableHelper_Core<TFeatures> {\n return {\n createColumnHelper,\n features: tableHelperOptions._features,\n options: tableHelperOptions,\n tableCreator: (tableOptions, selector) =>\n tableCreator({ ...tableHelperOptions, ...tableOptions }, selector),\n }\n}\n"],"mappings":";;;;;;AA2CA,SAAgB,qBACd,cAOA,oBAC6B;AAC7B,QAAO;EACL;EACA,UAAU,mBAAmB;EAC7B,SAAS;EACT,eAAe,cAAc,aAC3B,aAAa;GAAE,GAAG;GAAoB,GAAG;GAAc,EAAE,SAAS;EACrE"}
@@ -1,61 +0,0 @@
1
- import { createColumnHelper } from './columnHelper'
2
- import type { ColumnHelper } from './columnHelper'
3
- import type { RowData } from '../types/type-utils'
4
- import type { TableFeatures } from '../types/TableFeatures'
5
- import type { Table } from '../types/Table'
6
- import type { TableOptions } from '../types/TableOptions'
7
-
8
- /**
9
- * Options for creating a table helper to share common options across multiple tables
10
- * coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions
11
- */
12
- export type TableHelperOptions<TFeatures extends TableFeatures> = Omit<
13
- TableOptions<TFeatures, any>,
14
- 'columns' | 'data' | 'store' | 'state' | 'initialState'
15
- > & {
16
- _features: TFeatures
17
- }
18
-
19
- /**
20
- * Internal type that each adapter package will build off of to create a table helper
21
- */
22
- export type TableHelper_Core<TFeatures extends TableFeatures> = {
23
- createColumnHelper: <TData extends RowData>() => ColumnHelper<
24
- TFeatures,
25
- TData
26
- >
27
- features: TFeatures
28
- options: Omit<
29
- TableOptions<TFeatures, any>,
30
- 'columns' | 'data' | 'store' | 'state' | 'initialState'
31
- >
32
- tableCreator: <TData extends RowData>(
33
- tableOptions: Omit<
34
- TableOptions<TFeatures, TData>,
35
- '_features' | '_rowModels'
36
- >,
37
- selector?: any,
38
- ) => Table<TFeatures, TData>
39
- }
40
-
41
- /**
42
- * Internal function to create a table helper that each adapter package will use to create their own table helper
43
- */
44
- export function constructTableHelper<TFeatures extends TableFeatures>(
45
- tableCreator: <TData extends RowData>(
46
- tableOptions: Omit<
47
- TableOptions<TFeatures, TData>,
48
- '_features' | '_rowModels'
49
- >,
50
- selector?: any,
51
- ) => Table<TFeatures, TData>,
52
- tableHelperOptions: TableHelperOptions<TFeatures>,
53
- ): TableHelper_Core<TFeatures> {
54
- return {
55
- createColumnHelper,
56
- features: tableHelperOptions._features,
57
- options: tableHelperOptions,
58
- tableCreator: (tableOptions, selector) =>
59
- tableCreator({ ...tableHelperOptions, ...tableOptions }, selector),
60
- }
61
- }