Skip to content

Commit

Permalink
use ColumnInternal type more
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jan 6, 2025
1 parent 8b3ebb9 commit 188fe47
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
import type { Table_Internal } from '../../types/Table'
import type { Column } from '../../types/Column'
import type { Column_Internal } from '../../types/Column'

export function column_getFacetedMinMaxValues<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue>,
column: Column_Internal<TFeatures, TData, TValue>,
table: Table_Internal<TFeatures, TData>,
): () => [number, number] | undefined {
return (
Expand All @@ -23,7 +23,7 @@ export function column_getFacetedRowModel<
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> | undefined,
column: Column_Internal<TFeatures, TData, TValue> | undefined,
table: Table_Internal<TFeatures, TData>,
): () => RowModel<TFeatures, TData> {
return (
Expand All @@ -37,7 +37,7 @@ export function column_getFacetedUniqueValues<
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue>,
column: Column_Internal<TFeatures, TData, TValue>,
table: Table_Internal<TFeatures, TData>,
): () => Map<any, number> {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export const columnFilteringFeature: TableFeature<ColumnFilteringFeatureConstruc
},

constructRowAPIs: (row) => {
;(row as any).columnFilters = {}
;(row as any).columnFiltersMeta = {}
row.columnFilters = {}
row.columnFiltersMeta = {}
},

constructTableAPIs: (table) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { isFunction } from '../../utils'
import { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'
import type { Column_Internal } from '../../types/Column'
import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
import type { Row } from '../../types/Row'
import type { Cell } from '../../types/Cell'
import type { Column } from '../../types/Column'
import type {
AggregationFn,
ColumnDef_ColumnGrouping,
GroupingState,
Row_ColumnGrouping,
} from './columnGroupingFeature.types'
Expand All @@ -21,7 +20,7 @@ export function column_toggleGrouping<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(column: Column<TFeatures, TData, TValue>) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
table_setGrouping(column._table, (old) => {
// Find any existing grouping for this column
if (old.includes(column.id)) {
Expand All @@ -36,11 +35,7 @@ export function column_getCanGroup<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
return (
(column.columnDef.enableGrouping ?? true) &&
(column._table.options.enableGrouping ?? true) &&
Expand All @@ -52,35 +47,23 @@ export function column_getIsGrouped<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
): boolean {
>(column: Column_Internal<TFeatures, TData, TValue>): boolean {
return !!column._table.options.state?.grouping?.includes(column.id)
}

export function column_getGroupedIndex<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
): number {
>(column: Column_Internal<TFeatures, TData, TValue>): number {
return column._table.options.state?.grouping?.indexOf(column.id) ?? -1
}

export function column_getToggleGroupingHandler<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
const canGroup = column_getCanGroup(column)

return () => {
Expand All @@ -93,11 +76,7 @@ export function column_getAutoAggregationFn<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
const aggregationFns = column._table._rowModelFns.aggregationFns as
| Record<string, AggregationFn<TFeatures, TData>>
| undefined
Expand All @@ -119,11 +98,7 @@ export function column_getAggregationFn<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
const aggregationFns = column._table._rowModelFns.aggregationFns as
| Record<string, AggregationFn<TFeatures, TData>>
| undefined
Expand Down Expand Up @@ -167,12 +142,10 @@ export function row_getGroupingValue<
return row._groupingValuesCache[columnId]
}

const column = table_getColumn(row._table, columnId) as Column<
const column = table_getColumn(row._table, columnId) as Column_Internal<
TFeatures,
TData
> & {
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
}
>

if (!column.columnDef.getGroupingValue) {
return row.getValue(columnId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { GroupingState } from '../column-grouping/columnGroupingFeature.typ
import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
import type { Column } from '../../types/Column'
import type { Column_Internal } from '../../types/Column'
import type { ColumnPinningPosition } from '../column-pinning/columnPinningFeature.types'
import type { ColumnOrderState } from './columnOrderingFeature.types'

Expand All @@ -16,32 +16,32 @@ export function column_getIndex<
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue>,
column: Column_Internal<TFeatures, TData, TValue>,
position?: ColumnPinningPosition | 'center',
) {
const { _table: table } = column
const columns = table_getPinnedVisibleLeafColumns(table, position)
return columns.findIndex((d) => d.id === column.id)
}

export function column_getIsFirstColumn<
export function column_getIsFirstColumn_Internal<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue>,
column: Column_Internal<TFeatures, TData, TValue>,
position?: ColumnPinningPosition | 'center',
) {
const columns = table_getPinnedVisibleLeafColumns(column._table, position)
return columns[0]?.id === column.id
}

export function column_getIsLastColumn<
export function column_getIsLastColumn_Internal<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue>,
column: Column_Internal<TFeatures, TData, TValue>,
position?: ColumnPinningPosition | 'center',
) {
const columns = table_getPinnedVisibleLeafColumns(column._table, position)
Expand Down Expand Up @@ -71,10 +71,10 @@ export function table_getOrderColumnsFn<
>(table: Table_Internal<TFeatures, TData>) {
const { columnOrder = [] } = table.options.state ?? {}

return (columns: Array<Column<TFeatures, TData, unknown>>) => {
return (columns: Array<Column_Internal<TFeatures, TData, unknown>>) => {
// Sort grouped columns to the start of the column list
// before the headers are built
let orderedColumns: Array<Column<TFeatures, TData, unknown>> = []
let orderedColumns: Array<Column_Internal<TFeatures, TData, unknown>> = []

// If there is no order, return the normal columns
if (!columnOrder.length) {
Expand Down Expand Up @@ -109,7 +109,7 @@ export function orderColumns<
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
leafColumns: Array<Column<TFeatures, TData, unknown>>,
leafColumns: Array<Column_Internal<TFeatures, TData, unknown>>,
) {
const grouping = table.options.state?.grouping ?? ([] as GroupingState)
const { groupedColumnMode } = table.options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import type { Row } from '../../types/Row'
import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
import type { Column } from '../../types/Column'
import type { Column_Internal } from '../../types/Column'
import type {
ColumnDef_ColumnPinning,
ColumnPinningPosition,
ColumnPinningState,
} from './columnPinningFeature.types'
Expand All @@ -33,7 +32,10 @@ export function column_pin<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(column: Column<TFeatures, TData, TValue>, position: ColumnPinningPosition) {
>(
column: Column_Internal<TFeatures, TData, TValue>,
position: ColumnPinningPosition,
) {
const columnIds = column
.getLeafColumns()
.map((d) => d.id)
Expand Down Expand Up @@ -68,15 +70,9 @@ export function column_getCanPin<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: ColumnDef_ColumnPinning
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
const leafColumns = column.getLeafColumns() as Array<
Column<TFeatures, TData, TValue> & {
columnDef: ColumnDef_ColumnPinning
}
Column_Internal<TFeatures, TData, TValue>
>

return leafColumns.some(
Expand All @@ -90,7 +86,9 @@ export function column_getIsPinned<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(column: Column<TFeatures, TData, TValue>): ColumnPinningPosition | false {
>(
column: Column_Internal<TFeatures, TData, TValue>,
): ColumnPinningPosition | false {
const leafColumnIds = column.getLeafColumns().map((d) => d.id)

const { left, right } =
Expand All @@ -106,7 +104,7 @@ export function column_getPinnedIndex<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(column: Column<TFeatures, TData, TValue>) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
const position = column_getIsPinned(column)

return position
Expand Down Expand Up @@ -216,7 +214,7 @@ export function table_getLeftHeaderGroups<
table,
'getVisibleLeafColumns',
table_getVisibleLeafColumns,
) as unknown as Array<Column<TFeatures, TData, unknown>>
) as unknown as Array<Column_Internal<TFeatures, TData, unknown>>
const { left } =
table.options.state?.columnPinning ?? getDefaultColumnPinningState()

Expand All @@ -236,7 +234,7 @@ export function table_getRightHeaderGroups<
table,
'getVisibleLeafColumns',
table_getVisibleLeafColumns,
) as unknown as Array<Column<TFeatures, TData, unknown>>
) as unknown as Array<Column_Internal<TFeatures, TData, unknown>>
const { right } =
table.options.state?.columnPinning ?? getDefaultColumnPinningState()

Expand All @@ -258,7 +256,7 @@ export function table_getCenterHeaderGroups<
table,
'getVisibleLeafColumns',
table_getVisibleLeafColumns,
) as unknown as Array<Column<TFeatures, TData, unknown>>
) as unknown as Array<Column_Internal<TFeatures, TData, unknown>>
const { left, right } =
table.options.state?.columnPinning ?? getDefaultColumnPinningState()
const leftAndRight: Array<string> = [...left, ...right]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
import type { Header } from '../../types/Header'
import type { Column } from '../../types/Column'
import type { Column_Internal } from '../../types/Column'
import type { ColumnSizingState } from '../column-sizing/columnSizingFeature.types'
import type {
ColumnDef_ColumnResizing,
columnResizingState,
} from './columnResizingFeature.types'
import type { columnResizingState } from './columnResizingFeature.types'

export function getDefaultColumnResizingState(): columnResizingState {
return structuredClone({
Expand All @@ -30,11 +27,7 @@ export function column_getCanResize<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnResizing>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
return (
(column.columnDef.enableResizing ?? true) &&
(column._table.options.enableColumnResizing ?? true)
Expand All @@ -45,11 +38,7 @@ export function column_getIsResizing<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: Partial<ColumnDef_ColumnResizing>
},
) {
>(column: Column_Internal<TFeatures, TData, TValue>) {
return (
column._table.options.state?.columnResizing?.isResizingColumn === column.id
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { filterFn_includesString } from '../../fns/filterFns'
import { isFunction } from '../../utils'
import type { ColumnDefBase_All } from '../../types/ColumnDef'
import type { Column_Internal } from '../../types/Column'
import type { FilterFn } from '../column-filtering/columnFilteringFeature.types'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
import type { Column } from '../../types/Column'

export function column_getCanGlobalFilter<
TFeatures extends TableFeatures,
TData extends RowData,
TValue extends CellData = CellData,
>(
column: Column<TFeatures, TData, TValue> & {
columnDef: ColumnDefBase_All<TFeatures, TData, TValue>
},
): boolean {
>(column: Column_Internal<TFeatures, TData, TValue>): boolean {
const { _table: table } = column
return (
(column.columnDef.enableGlobalFilter ?? true) &&
Expand Down

0 comments on commit 188fe47

Please sign in to comment.