Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/table-core/src/core/cells/constructCell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Row } from '../../types/Row'
Expand All @@ -13,7 +13,7 @@ import type { Cell_CoreProperties } from './coreCellsFeature.types'
function getCellPrototype<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>): object {
>(table: Table<TFeatures, TData>): object {
if (!table._cellPrototype) {
table._cellPrototype = { table }
const features = Object.values(table._features)
Expand All @@ -36,7 +36,7 @@ export function constructCell<
>(
column: Column<TFeatures, TData, TValue>,
row: Row<TFeatures, TData>,
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
): Cell<TFeatures, TData, TValue> {
// Create cell with shared prototype for memory efficiency
const cellPrototype = getCellPrototype(table)
Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/cells/coreCellsFeature.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CellData, Getter, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table, Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { Row } from '../../types/Row'
import type { Cell } from '../../types/Cell'
import type { Column } from '../../types/Column'
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface Cell_CoreProperties<
/**
* Reference to the parent table instance.
*/
table: Table_Internal<TFeatures, TData>
table: Table<TFeatures, TData>
}

export interface Cell_Cell<
Expand Down
6 changes: 3 additions & 3 deletions packages/table-core/src/core/columns/constructColumn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {} from '../../utils'
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type {
Expand All @@ -17,7 +17,7 @@ import type { Column_CoreProperties } from './coreColumnsFeature.types'
function getColumnPrototype<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>): object {
>(table: Table<TFeatures, TData>): object {
if (!table._columnPrototype) {
table._columnPrototype = { table }
const features = Object.values(table._features)
Expand All @@ -38,7 +38,7 @@ export function constructColumn<
TData extends RowData,
TValue extends CellData = CellData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
columnDef: ColumnDef<TFeatures, TData, TValue>,
depth: number,
parent?: Column<TFeatures, TData, TValue>,
Expand Down
8 changes: 7 additions & 1 deletion packages/table-core/src/core/columns/coreColumnsFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import {
} from './coreColumnsFeature.utils'
import type { TableFeature } from '../../types/TableFeatures'

type CoreColumnsFeature = Partial<{
coreColumnsFeature: TableFeature
columnOrderingFeature: TableFeature
columnGroupingFeature: TableFeature
}>

/**
* Core feature that builds the column tree and exposes table/column column APIs.
*/
export const coreColumnsFeature: TableFeature = {
export const coreColumnsFeature: TableFeature<CoreColumnsFeature> = {
assignColumnPrototype: (prototype, table) => {
assignPrototypeAPIs('coreColumnsFeature', prototype, table, {
column_getFlatColumns: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { AccessorFn, ColumnDef } from '../../types/ColumnDef'
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface Column_CoreProperties<
/**
* Reference to the parent table instance.
*/
table: Table_Internal<TFeatures, TData>
table: Table<TFeatures, TData>
}

export interface Column_Column<
Expand Down
22 changes: 8 additions & 14 deletions packages/table-core/src/core/columns/coreColumnsFeature.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { callMemoOrStaticFn } from '../../utils'
import { table_getOrderColumnsFn } from '../../features/column-ordering/columnOrderingFeature.utils'
import { constructColumn } from './constructColumn'
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type {
Expand Down Expand Up @@ -81,7 +81,7 @@ export function table_getDefaultColumnDef<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
): Partial<ColumnDef<TFeatures, TData, unknown>> {
return {
header: (props) => {
Expand Down Expand Up @@ -120,9 +120,7 @@ export function table_getDefaultColumnDef<
export function table_getAllColumns<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
): Array<Column<TFeatures, TData, unknown>> {
>(table: Table<TFeatures, TData>): Array<Column<TFeatures, TData, unknown>> {
const recurseColumns = (
colDefs: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>,
parent?: Column<TFeatures, TData, unknown>,
Expand Down Expand Up @@ -162,9 +160,7 @@ export function table_getAllColumns<
export function table_getAllFlatColumns<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
): Array<Column<TFeatures, TData, unknown>> {
>(table: Table<TFeatures, TData>): Array<Column<TFeatures, TData, unknown>> {
return table.getAllColumns().flatMap((column) => column.getFlatColumns())
}

Expand All @@ -183,7 +179,7 @@ export function table_getAllFlatColumnsById<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
): Record<string, Column<TFeatures, TData, unknown>> {
const result: Record<string, Column<TFeatures, TData, unknown>> = {}
const flatColumns = table.getAllFlatColumns()
Expand All @@ -208,9 +204,7 @@ export function table_getAllFlatColumnsById<
export function table_getAllLeafColumns<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
): Array<Column<TFeatures, TData, unknown>> {
>(table: Table<TFeatures, TData>): Array<Column<TFeatures, TData, unknown>> {
const leafColumns = table.getAllColumns().flatMap(
(c) => c.getLeafColumns(), // recursive
)
Expand All @@ -236,7 +230,7 @@ export function table_getAllLeafColumnsById<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
): Record<string, Column<TFeatures, TData, unknown>> {
const result: Record<string, Column<TFeatures, TData, unknown>> = {}
const leafColumns = table.getAllLeafColumns()
Expand All @@ -262,7 +256,7 @@ export function table_getColumn<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
columnId: string,
): Column<TFeatures, TData, unknown> | undefined {
const column = table.getAllFlatColumnsById()[columnId]
Expand Down
14 changes: 5 additions & 9 deletions packages/table-core/src/core/headers/buildHeaderGroups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { callMemoOrStaticFn } from '../../utils'
import { column_getIsVisible } from '../../features/column-visibility/columnVisibilityFeature.utils'
import { constructHeader } from './constructHeader'
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Header } from '../../types/Header'
Expand All @@ -20,7 +20,7 @@ export function buildHeaderGroups<
>(
allColumns: Array<Column<TFeatures, TData, TValue>>,
columnsToGroup: Array<Column<TFeatures, TData, TValue>>,
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
headerFamily?: 'center' | 'left' | 'right',
) {
// Find the max depth of the columns:
Expand Down Expand Up @@ -113,9 +113,7 @@ export function buildHeaderGroups<
pendingParentHeaders.push(header)
}

headerGroup.headers.push(
headerToGroup as Header<TFeatures, TData, unknown>,
)
headerGroup.headers.push(headerToGroup)
headerToGroup.headerGroup = headerGroup
})

Expand All @@ -138,7 +136,7 @@ export function buildHeaderGroups<
headerGroups.reverse()

const recurseHeadersForSpans = (
headers: Array<Header<TFeatures, TData, TValue>>,
headers: Array<Header<TFeatures, TData, unknown>>,
): Array<{ colSpan: number; rowSpan: number }> => {
const results: Array<{ colSpan: number; rowSpan: number }> = []

Expand Down Expand Up @@ -176,9 +174,7 @@ export function buildHeaderGroups<
return results
}

recurseHeadersForSpans(
(headerGroups[0]?.headers ?? []) as Array<Header<TFeatures, TData, TValue>>,
)
recurseHeadersForSpans(headerGroups[0]?.headers ?? [])

return headerGroups
}
6 changes: 3 additions & 3 deletions packages/table-core/src/core/headers/constructHeader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Header } from '../../types/Header'
Expand All @@ -12,7 +12,7 @@ import type { Header_CoreProperties } from './coreHeadersFeature.types'
function getHeaderPrototype<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>): object {
>(table: Table<TFeatures, TData>): object {
if (!table._headerPrototype) {
table._headerPrototype = { table }
const features = Object.values(table._features)
Expand All @@ -33,7 +33,7 @@ export function constructHeader<
TData extends RowData,
TValue extends CellData = CellData,
>(
table: Table_Internal<TFeatures, TData>,
table: Table<TFeatures, TData>,
column: Column<TFeatures, TData, TValue>,
options: {
id?: string
Expand Down
10 changes: 9 additions & 1 deletion packages/table-core/src/core/headers/coreHeadersFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import {
table_getLeafHeaders,
} from './coreHeadersFeature.utils'
import type { TableFeature } from '../../types/TableFeatures'
import type { CoreFeatures } from '../coreFeatures'

type CoreHeadersFeature = CoreFeatures & {
columnGroupingFeature: TableFeature
columnOrderingFeature: TableFeature
columnPinningFeature: TableFeature
columnVisibilityFeature: TableFeature
}

/**
* Core feature that builds header groups and exposes header context APIs.
*/
export const coreHeadersFeature: TableFeature = {
export const coreHeadersFeature: TableFeature<CoreHeadersFeature> = {
assignHeaderPrototype: (prototype, table) => {
assignPrototypeAPIs('coreHeadersFeature', prototype, table, {
header_getLeafHeaders: {
Expand Down
20 changes: 12 additions & 8 deletions packages/table-core/src/core/headers/coreHeadersFeature.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
} from '../../features/column-visibility/columnVisibilityFeature.utils'
import { callMemoOrStaticFn } from '../../utils'
import { buildHeaderGroups } from './buildHeaderGroups'
import type { Table_Internal } from '../../types/Table'
import type { Table } from '../../types/Table'
import type { Header } from '../../types/Header'
import type { RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type { Header_Header } from './coreHeadersFeature.types'
import type { Column } from '../../types/Column'

type HeaderFeatures = Partial<{
columnPinningFeature: TableFeature
}>

/**
* Walks a header tree and collects all descendant leaf headers.
Expand Down Expand Up @@ -78,9 +81,10 @@ export function header_getContext<
export function table_getHeaderGroups<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>) {
>(table: Table<TFeatures, TData>) {
const featureTable = table as unknown as Table<HeaderFeatures, TData>
const { left, right } =
table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState()
featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState()
const allColumns = table.getAllColumns()
const leafColumns = callMemoOrStaticFn(
table,
Expand Down Expand Up @@ -142,7 +146,7 @@ export function table_getHeaderGroups<
export function table_getFooterGroups<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>) {
>(table: Table<TFeatures, TData>) {
const headerGroups = table.getHeaderGroups()
return [...headerGroups].reverse()
}
Expand All @@ -161,7 +165,7 @@ export function table_getFooterGroups<
export function table_getFlatHeaders<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>) {
>(table: Table<TFeatures, TData>) {
const headerGroups = table.getHeaderGroups()
const result: Array<Header<TFeatures, TData, unknown>> = []
for (let i = 0; i < headerGroups.length; i++) {
Expand All @@ -187,7 +191,7 @@ export function table_getFlatHeaders<
export function table_getLeafHeaders<
TFeatures extends TableFeatures,
TData extends RowData,
>(table: Table_Internal<TFeatures, TData>) {
>(table: Table<TFeatures, TData>) {
const topHeaders = table.getHeaderGroups()[0]?.headers ?? []
const result: Array<Header<TFeatures, TData, unknown>> = []
for (let i = 0; i < topHeaders.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
table_getSortedRowModel,
} from './coreRowModelsFeature.utils'
import type { TableFeature } from '../../types/TableFeatures'
import type { CoreFeatures } from '../coreFeatures'

/**
* Core feature that wires table row-model accessors and row-model caches.
*/
export const coreRowModelsFeature: TableFeature = {
export const coreRowModelsFeature: TableFeature<CoreFeatures> = {
constructTableAPIs: (table) => {
assignTableAPIs('coreRowModelsFeature', table, {
table_getCoreRowModel: {
Expand Down
Loading
Loading