@tanstack/table-core 9.0.0-alpha.11 → 9.0.0-alpha.13

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.
@@ -50,7 +50,7 @@ export interface TableOptions_Columns<TFeatures extends TableFeatures, TData ext
50
50
  /**
51
51
  * The array of column defs to use for the table.
52
52
  */
53
- columns: Array<ColumnDef<TFeatures, TData, TValue>>;
53
+ columns: ReadonlyArray<ColumnDef<TFeatures, TData, TValue>>;
54
54
  /**
55
55
  * Default column options to use for all column defs supplied to the table.
56
56
  */
@@ -1 +1 @@
1
- {"version":3,"file":"coreColumnsFeature.utils.js","sources":["../../../../src/core/columns/coreColumnsFeature.utils.ts"],"sourcesContent":["import { callMemoOrStaticFn } from '../../utils'\nimport { table_getOrderColumnsFn } from '../../features/column-ordering/columnOrderingFeature.utils'\nimport { constructColumn } from './constructColumn'\nimport type { Table_Internal } from '../../types/Table'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type {\n ColumnDef,\n ColumnDefResolved,\n GroupColumnDef,\n} from '../../types/ColumnDef'\nimport type { Column } from '../../types/Column'\n\nexport function column_getFlatColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column<TFeatures, TData, TValue>,\n): Array<Column<TFeatures, TData, TValue>> {\n return [column, ...column.columns.flatMap((col) => col.getFlatColumns())]\n}\n\nexport function column_getLeafColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column<TFeatures, TData, TValue>,\n): Array<Column<TFeatures, TData, TValue>> {\n if (column.columns.length) {\n const leafColumns = column.columns.flatMap(\n (col) => col.getLeafColumns(), // recursive\n )\n\n return callMemoOrStaticFn(\n column.table,\n 'getOrderColumns',\n table_getOrderColumnsFn,\n )(leafColumns as any) as any\n }\n\n return [column]\n}\n\nexport function table_getDefaultColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Partial<ColumnDef<TFeatures, TData, unknown>> {\n return {\n header: (props) => {\n const resolvedColumnDef = props.header.column\n .columnDef as ColumnDefResolved<{}, TData>\n\n if (resolvedColumnDef.accessorKey) {\n return resolvedColumnDef.accessorKey\n }\n\n if (resolvedColumnDef.accessorFn) {\n return resolvedColumnDef.id\n }\n\n return null\n },\n cell: (props) => props.renderValue<any>()?.toString?.() ?? null,\n ...Object.values(table._features).reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultColumnDef?.())\n }, {}),\n ...table.options.defaultColumn,\n } as Partial<ColumnDef<TFeatures, TData, unknown>>\n}\n\nexport function table_getAllColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n const recurseColumns = (\n colDefs: Array<ColumnDef<TFeatures, TData, unknown>>,\n parent?: Column<TFeatures, TData, unknown>,\n depth = 0,\n ): Array<Column<TFeatures, TData, unknown>> => {\n return colDefs.map((columnDef) => {\n const column = constructColumn(table, columnDef, depth, parent)\n\n const groupingColumnDef = columnDef as GroupColumnDef<\n TFeatures,\n TData,\n unknown\n >\n\n column.columns = groupingColumnDef.columns\n ? recurseColumns(groupingColumnDef.columns, column, depth + 1)\n : []\n\n return column\n })\n }\n\n return recurseColumns(table.options.columns as any)\n}\n\nexport function table_getAllFlatColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n return table.getAllColumns().flatMap((column) => column.getFlatColumns())\n}\n\nexport function table_getAllFlatColumnsById<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Record<string, Column<TFeatures, TData, unknown>> {\n return table.getAllFlatColumns().reduce(\n (acc, column) => {\n acc[column.id] = column\n return acc\n },\n {} as Record<string, Column<TFeatures, TData, unknown>>,\n )\n}\n\nexport function table_getAllLeafColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n const leafColumns = table.getAllColumns().flatMap(\n (c) => c.getLeafColumns(), // recursive\n )\n return callMemoOrStaticFn(\n table,\n 'getOrderColumns',\n table_getOrderColumnsFn,\n )(leafColumns as any) as any\n}\n\nexport function table_getColumn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n): Column<TFeatures, TData, unknown> | undefined {\n const column = table.getAllFlatColumnsById()[columnId]\n\n if (process.env.NODE_ENV === 'development' && !column) {\n console.warn(`[Table] Column with id '${columnId}' does not exist.`)\n }\n\n return column\n}\n"],"names":[],"mappings":";;;AAaO,SAAS,sBAKd,QACyC;AACzC,SAAO,CAAC,QAAQ,GAAG,OAAO,QAAQ,QAAQ,CAAC,QAAQ,IAAI,eAAA,CAAgB,CAAC;AAC1E;AAEO,SAAS,sBAKd,QACyC;AACzC,MAAI,OAAO,QAAQ,QAAQ;AACzB,UAAM,cAAc,OAAO,QAAQ;AAAA,MACjC,CAAC,QAAQ,IAAI,eAAA;AAAA;AAAA,IAAe;AAG9B,WAAO;AAAA,MACL,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IAAA,EACA,WAAkB;AAAA,EACtB;AAEA,SAAO,CAAC,MAAM;AAChB;AAEO,SAAS,0BAId,OAC+C;AAC/C,SAAO;AAAA,IACL,QAAQ,CAAC,UAAU;AACjB,YAAM,oBAAoB,MAAM,OAAO,OACpC;AAEH,UAAI,kBAAkB,aAAa;AACjC,eAAO,kBAAkB;AAAA,MAC3B;AAEA,UAAI,kBAAkB,YAAY;AAChC,eAAO,kBAAkB;AAAA,MAC3B;AAEA,aAAO;AAAA,IACT;AAAA,IACA,MAAM,CAAC,UAAU,MAAM,YAAA,GAAoB,gBAAgB;AAAA,IAC3D,GAAG,OAAO,OAAO,MAAM,SAAS,EAAE,OAAO,CAAC,KAAK,YAAY;AACzD,aAAO,OAAO,OAAO,KAAK,QAAQ,uBAAuB;AAAA,IAC3D,GAAG,CAAA,CAAE;AAAA,IACL,GAAG,MAAM,QAAQ;AAAA,EAAA;AAErB;AAEO,SAAS,oBAId,OAC0C;AAC1C,QAAM,iBAAiB,CACrB,SACA,QACA,QAAQ,MACqC;AAC7C,WAAO,QAAQ,IAAI,CAAC,cAAc;AAChC,YAAM,SAAS,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAE9D,YAAM,oBAAoB;AAM1B,aAAO,UAAU,kBAAkB,UAC/B,eAAe,kBAAkB,SAAS,QAAQ,QAAQ,CAAC,IAC3D,CAAA;AAEJ,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO,eAAe,MAAM,QAAQ,OAAc;AACpD;AAEO,SAAS,wBAId,OAC0C;AAC1C,SAAO,MAAM,gBAAgB,QAAQ,CAAC,WAAW,OAAO,gBAAgB;AAC1E;AAEO,SAAS,4BAId,OACmD;AACnD,SAAO,MAAM,oBAAoB;AAAA,IAC/B,CAAC,KAAK,WAAW;AACf,UAAI,OAAO,EAAE,IAAI;AACjB,aAAO;AAAA,IACT;AAAA,IACA,CAAA;AAAA,EAAC;AAEL;AAEO,SAAS,wBAId,OAC0C;AAC1C,QAAM,cAAc,MAAM,cAAA,EAAgB;AAAA,IACxC,CAAC,MAAM,EAAE,eAAA;AAAA;AAAA,EAAe;AAE1B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EAAA,EACA,WAAkB;AACtB;AAEO,SAAS,gBAId,OACA,UAC+C;AAC/C,QAAM,SAAS,MAAM,sBAAA,EAAwB,QAAQ;AAErD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ;AACrD,YAAQ,KAAK,2BAA2B,QAAQ,mBAAmB;AAAA,EACrE;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"coreColumnsFeature.utils.js","sources":["../../../../src/core/columns/coreColumnsFeature.utils.ts"],"sourcesContent":["import { callMemoOrStaticFn } from '../../utils'\nimport { table_getOrderColumnsFn } from '../../features/column-ordering/columnOrderingFeature.utils'\nimport { constructColumn } from './constructColumn'\nimport type { Table_Internal } from '../../types/Table'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type {\n ColumnDef,\n ColumnDefResolved,\n GroupColumnDef,\n} from '../../types/ColumnDef'\nimport type { Column } from '../../types/Column'\n\nexport function column_getFlatColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column<TFeatures, TData, TValue>,\n): Array<Column<TFeatures, TData, TValue>> {\n return [column, ...column.columns.flatMap((col) => col.getFlatColumns())]\n}\n\nexport function column_getLeafColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column<TFeatures, TData, TValue>,\n): Array<Column<TFeatures, TData, TValue>> {\n if (column.columns.length) {\n const leafColumns = column.columns.flatMap(\n (col) => col.getLeafColumns(), // recursive\n )\n\n return callMemoOrStaticFn(\n column.table,\n 'getOrderColumns',\n table_getOrderColumnsFn,\n )(leafColumns as any) as any\n }\n\n return [column]\n}\n\nexport function table_getDefaultColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Partial<ColumnDef<TFeatures, TData, unknown>> {\n return {\n header: (props) => {\n const resolvedColumnDef = props.header.column\n .columnDef as ColumnDefResolved<{}, TData>\n\n if (resolvedColumnDef.accessorKey) {\n return resolvedColumnDef.accessorKey\n }\n\n if (resolvedColumnDef.accessorFn) {\n return resolvedColumnDef.id\n }\n\n return null\n },\n cell: (props) => props.renderValue<any>()?.toString?.() ?? null,\n ...Object.values(table._features).reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultColumnDef?.())\n }, {}),\n ...table.options.defaultColumn,\n } as Partial<ColumnDef<TFeatures, TData, unknown>>\n}\n\nexport function table_getAllColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n const recurseColumns = (\n colDefs: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>,\n parent?: Column<TFeatures, TData, unknown>,\n depth = 0,\n ): Array<Column<TFeatures, TData, unknown>> => {\n return colDefs.map((columnDef) => {\n const column = constructColumn(table, columnDef, depth, parent)\n\n const groupingColumnDef = columnDef as GroupColumnDef<\n TFeatures,\n TData,\n unknown\n >\n\n column.columns = groupingColumnDef.columns\n ? recurseColumns(groupingColumnDef.columns, column, depth + 1)\n : []\n\n return column\n })\n }\n\n return recurseColumns(table.options.columns as any)\n}\n\nexport function table_getAllFlatColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n return table.getAllColumns().flatMap((column) => column.getFlatColumns())\n}\n\nexport function table_getAllFlatColumnsById<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Record<string, Column<TFeatures, TData, unknown>> {\n return table.getAllFlatColumns().reduce(\n (acc, column) => {\n acc[column.id] = column\n return acc\n },\n {} as Record<string, Column<TFeatures, TData, unknown>>,\n )\n}\n\nexport function table_getAllLeafColumns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): Array<Column<TFeatures, TData, unknown>> {\n const leafColumns = table.getAllColumns().flatMap(\n (c) => c.getLeafColumns(), // recursive\n )\n return callMemoOrStaticFn(\n table,\n 'getOrderColumns',\n table_getOrderColumnsFn,\n )(leafColumns as any) as any\n}\n\nexport function table_getColumn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n): Column<TFeatures, TData, unknown> | undefined {\n const column = table.getAllFlatColumnsById()[columnId]\n\n if (process.env.NODE_ENV === 'development' && !column) {\n console.warn(`[Table] Column with id '${columnId}' does not exist.`)\n }\n\n return column\n}\n"],"names":[],"mappings":";;;AAaO,SAAS,sBAKd,QACyC;AACzC,SAAO,CAAC,QAAQ,GAAG,OAAO,QAAQ,QAAQ,CAAC,QAAQ,IAAI,eAAA,CAAgB,CAAC;AAC1E;AAEO,SAAS,sBAKd,QACyC;AACzC,MAAI,OAAO,QAAQ,QAAQ;AACzB,UAAM,cAAc,OAAO,QAAQ;AAAA,MACjC,CAAC,QAAQ,IAAI,eAAA;AAAA;AAAA,IAAe;AAG9B,WAAO;AAAA,MACL,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IAAA,EACA,WAAkB;AAAA,EACtB;AAEA,SAAO,CAAC,MAAM;AAChB;AAEO,SAAS,0BAId,OAC+C;AAC/C,SAAO;AAAA,IACL,QAAQ,CAAC,UAAU;AACjB,YAAM,oBAAoB,MAAM,OAAO,OACpC;AAEH,UAAI,kBAAkB,aAAa;AACjC,eAAO,kBAAkB;AAAA,MAC3B;AAEA,UAAI,kBAAkB,YAAY;AAChC,eAAO,kBAAkB;AAAA,MAC3B;AAEA,aAAO;AAAA,IACT;AAAA,IACA,MAAM,CAAC,UAAU,MAAM,YAAA,GAAoB,gBAAgB;AAAA,IAC3D,GAAG,OAAO,OAAO,MAAM,SAAS,EAAE,OAAO,CAAC,KAAK,YAAY;AACzD,aAAO,OAAO,OAAO,KAAK,QAAQ,uBAAuB;AAAA,IAC3D,GAAG,CAAA,CAAE;AAAA,IACL,GAAG,MAAM,QAAQ;AAAA,EAAA;AAErB;AAEO,SAAS,oBAId,OAC0C;AAC1C,QAAM,iBAAiB,CACrB,SACA,QACA,QAAQ,MACqC;AAC7C,WAAO,QAAQ,IAAI,CAAC,cAAc;AAChC,YAAM,SAAS,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAE9D,YAAM,oBAAoB;AAM1B,aAAO,UAAU,kBAAkB,UAC/B,eAAe,kBAAkB,SAAS,QAAQ,QAAQ,CAAC,IAC3D,CAAA;AAEJ,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO,eAAe,MAAM,QAAQ,OAAc;AACpD;AAEO,SAAS,wBAId,OAC0C;AAC1C,SAAO,MAAM,gBAAgB,QAAQ,CAAC,WAAW,OAAO,gBAAgB;AAC1E;AAEO,SAAS,4BAId,OACmD;AACnD,SAAO,MAAM,oBAAoB;AAAA,IAC/B,CAAC,KAAK,WAAW;AACf,UAAI,OAAO,EAAE,IAAI;AACjB,aAAO;AAAA,IACT;AAAA,IACA,CAAA;AAAA,EAAC;AAEL;AAEO,SAAS,wBAId,OAC0C;AAC1C,QAAM,cAAc,MAAM,cAAA,EAAgB;AAAA,IACxC,CAAC,MAAM,EAAE,eAAA;AAAA;AAAA,EAAe;AAE1B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EAAA,EACA,WAAkB;AACtB;AAEO,SAAS,gBAId,OACA,UAC+C;AAC/C,QAAM,SAAS,MAAM,sBAAA,EAAwB,QAAQ;AAErD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ;AACrD,YAAQ,KAAK,2BAA2B,QAAQ,mBAAmB;AAAA,EACrE;AAEA,SAAO;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createCoreRowModel.js","sources":["../../../../src/core/row-models/createCoreRowModel.ts"],"sourcesContent":["import { constructRow } from '../rows/constructRow'\nimport { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../../features/row-pagination/rowPaginationFeature.utils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { RowModel } from './coreRowModelsFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\nexport function createCoreRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'coreRowModelsFeature',\n table,\n fnName: 'table.getCoreRowModel',\n memoDeps: () => [table.options.data],\n fn: () => _createCoreRowModel(table, table.options.data),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createCoreRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n data: Array<TData>,\n): {\n rows: Array<Row<TFeatures, TData>>\n flatRows: Array<Row<TFeatures, TData>>\n rowsById: Record<string, Row<TFeatures, TData>>\n} {\n const rowModel: RowModel<TFeatures, TData> = {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n\n const accessRows = (\n originalRows: Array<TData>,\n depth = 0,\n parentRow?: Row<TFeatures, TData>,\n ): Array<Row<TFeatures, TData>> => {\n const rows = [] as Array<Row<TFeatures, TData>>\n\n for (let i = 0; i < originalRows.length; i++) {\n const originalRow = originalRows[i]!\n // Make the row\n const row = constructRow(\n table,\n table.getRowId(originalRow, i, parentRow),\n originalRow,\n i,\n depth,\n undefined,\n parentRow?.id,\n )\n\n // Keep track of every row in a flat array\n rowModel.flatRows.push(row)\n // Also keep track of every row by its ID\n rowModel.rowsById[row.id] = row\n // Push table row into parent\n rows.push(row)\n\n // Get the original subrows\n if (table.options.getSubRows) {\n row.originalSubRows = table.options.getSubRows(originalRow, i)\n\n // Then recursively access them\n if (row.originalSubRows?.length) {\n row.subRows = accessRows(row.originalSubRows, depth + 1, row)\n }\n }\n }\n\n return rows\n }\n\n rowModel.rows = accessRows(data)\n\n return rowModel\n}\n"],"names":[],"mappings":";;;AASO,SAAS,qBAG0D;AACxE,SAAO,CAAC,WAAW;AACjB,UAAM,QAAQ;AACd,WAAO,UAAU;AAAA,MACf,SAAS;AAAA,MACT;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,MAAM,CAAC,MAAM,QAAQ,IAAI;AAAA,MACnC,IAAI,MAAM,oBAAoB,OAAO,MAAM,QAAQ,IAAI;AAAA,MACvD,eAAe,MAAM,yBAAyB,KAAK;AAAA,IAAA,CACpD;AAAA,EACH;AACF;AAEA,SAAS,oBAIP,OACA,MAKA;AACA,QAAM,WAAuC;AAAA,IAC3C,MAAM,CAAA;AAAA,IACN,UAAU,CAAA;AAAA,IACV,UAAU,CAAA;AAAA,EAAC;AAGb,QAAM,aAAa,CACjB,cACA,QAAQ,GACR,cACiC;AACjC,UAAM,OAAO,CAAA;AAEb,aAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,YAAM,cAAc,aAAa,CAAC;AAElC,YAAM,MAAM;AAAA,QACV;AAAA,QACA,MAAM,SAAS,aAAa,GAAG,SAAS;AAAA,QACxC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,MAAA;AAIb,eAAS,SAAS,KAAK,GAAG;AAE1B,eAAS,SAAS,IAAI,EAAE,IAAI;AAE5B,WAAK,KAAK,GAAG;AAGb,UAAI,MAAM,QAAQ,YAAY;AAC5B,YAAI,kBAAkB,MAAM,QAAQ,WAAW,aAAa,CAAC;AAG7D,YAAI,IAAI,iBAAiB,QAAQ;AAC/B,cAAI,UAAU,WAAW,IAAI,iBAAiB,QAAQ,GAAG,GAAG;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,WAAS,OAAO,WAAW,IAAI;AAE/B,SAAO;AACT;"}
1
+ {"version":3,"file":"createCoreRowModel.js","sources":["../../../../src/core/row-models/createCoreRowModel.ts"],"sourcesContent":["import { constructRow } from '../rows/constructRow'\nimport { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../../features/row-pagination/rowPaginationFeature.utils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { RowModel } from './coreRowModelsFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\nexport function createCoreRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'coreRowModelsFeature',\n table,\n fnName: 'table.getCoreRowModel',\n memoDeps: () => [table.options.data],\n fn: () => _createCoreRowModel(table, table.options.data),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createCoreRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n data: ReadonlyArray<TData>,\n): {\n rows: Array<Row<TFeatures, TData>>\n flatRows: Array<Row<TFeatures, TData>>\n rowsById: Record<string, Row<TFeatures, TData>>\n} {\n const rowModel: RowModel<TFeatures, TData> = {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n\n const accessRows = (\n originalRows: ReadonlyArray<TData>,\n depth = 0,\n parentRow?: Row<TFeatures, TData>,\n ): Array<Row<TFeatures, TData>> => {\n const rows = [] as Array<Row<TFeatures, TData>>\n\n for (let i = 0; i < originalRows.length; i++) {\n const originalRow = originalRows[i]!\n // Make the row\n const row = constructRow(\n table,\n table.getRowId(originalRow, i, parentRow),\n originalRow,\n i,\n depth,\n undefined,\n parentRow?.id,\n )\n\n // Keep track of every row in a flat array\n rowModel.flatRows.push(row)\n // Also keep track of every row by its ID\n rowModel.rowsById[row.id] = row\n // Push table row into parent\n rows.push(row)\n\n // Get the original subrows\n if (table.options.getSubRows) {\n row.originalSubRows = table.options.getSubRows(originalRow, i)\n\n // Then recursively access them\n if (row.originalSubRows?.length) {\n row.subRows = accessRows(row.originalSubRows, depth + 1, row)\n }\n }\n }\n\n return rows\n }\n\n rowModel.rows = accessRows(data)\n\n return rowModel\n}\n"],"names":[],"mappings":";;;AASO,SAAS,qBAG0D;AACxE,SAAO,CAAC,WAAW;AACjB,UAAM,QAAQ;AACd,WAAO,UAAU;AAAA,MACf,SAAS;AAAA,MACT;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,MAAM,CAAC,MAAM,QAAQ,IAAI;AAAA,MACnC,IAAI,MAAM,oBAAoB,OAAO,MAAM,QAAQ,IAAI;AAAA,MACvD,eAAe,MAAM,yBAAyB,KAAK;AAAA,IAAA,CACpD;AAAA,EACH;AACF;AAEA,SAAS,oBAIP,OACA,MAKA;AACA,QAAM,WAAuC;AAAA,IAC3C,MAAM,CAAA;AAAA,IACN,UAAU,CAAA;AAAA,IACV,UAAU,CAAA;AAAA,EAAC;AAGb,QAAM,aAAa,CACjB,cACA,QAAQ,GACR,cACiC;AACjC,UAAM,OAAO,CAAA;AAEb,aAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,YAAM,cAAc,aAAa,CAAC;AAElC,YAAM,MAAM;AAAA,QACV;AAAA,QACA,MAAM,SAAS,aAAa,GAAG,SAAS;AAAA,QACxC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,MAAA;AAIb,eAAS,SAAS,KAAK,GAAG;AAE1B,eAAS,SAAS,IAAI,EAAE,IAAI;AAE5B,WAAK,KAAK,GAAG;AAGb,UAAI,MAAM,QAAQ,YAAY;AAC5B,YAAI,kBAAkB,MAAM,QAAQ,WAAW,aAAa,CAAC;AAG7D,YAAI,IAAI,iBAAiB,QAAQ;AAC/B,cAAI,UAAU,WAAW,IAAI,iBAAiB,QAAQ,GAAG,GAAG;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,WAAS,OAAO,WAAW,IAAI;AAE/B,SAAO;AACT;"}
@@ -25,7 +25,7 @@ export interface Row_CoreProperties<TFeatures extends TableFeatures, TData exten
25
25
  /**
26
26
  * An array of the original subRows as returned by the `options.getSubRows` option.
27
27
  */
28
- originalSubRows?: Array<TData>;
28
+ originalSubRows?: ReadonlyArray<TData>;
29
29
  /**
30
30
  * If nested, this row's parent row id.
31
31
  */
@@ -80,7 +80,7 @@ export interface TableOptions_Rows<TFeatures extends TableFeatures, TData extend
80
80
  * This optional function is used to access the sub rows for any given row. If you are using nested rows, you will need to use this function to return the sub rows object (or undefined) from the row.
81
81
  * @example getSubRows: row => row.subRows
82
82
  */
83
- getSubRows?: (originalRow: TData, index: number) => undefined | Array<TData>;
83
+ getSubRows?: (originalRow: TData, index: number) => undefined | ReadonlyArray<TData>;
84
84
  }
85
85
  export interface Table_Rows<TFeatures extends TableFeatures, TData extends RowData> {
86
86
  getRowId: (_: TData, index: number, parent?: Row<TFeatures, TData>) => string;
@@ -1,4 +1,4 @@
1
- import { Store, Derived } from "@tanstack/store";
1
+ import { createStore } from "@tanstack/store";
2
2
  import { coreFeatures } from "../coreFeatures.js";
3
3
  function getInitialTableState(features, initialState = {}) {
4
4
  Object.values(features).forEach((feature) => {
@@ -7,7 +7,7 @@ function getInitialTableState(features, initialState = {}) {
7
7
  return structuredClone(initialState);
8
8
  }
9
9
  function createTableStore(features, initialState = {}) {
10
- return new Store(getInitialTableState(features, initialState));
10
+ return createStore(getInitialTableState(features, initialState));
11
11
  }
12
12
  function constructTable(tableOptions) {
13
13
  const table = {
@@ -27,16 +27,13 @@ function constructTable(tableOptions) {
27
27
  table._features,
28
28
  table.options.initialState
29
29
  );
30
- table.baseStore = table.options.store ?? new Store(table.initialState);
31
- table.store = new Derived({
32
- deps: [table.baseStore],
33
- fn: ({ currDepVals }) => {
34
- const baseState = currDepVals[0];
35
- return {
36
- ...baseState,
37
- ...table.options.state ?? {}
38
- };
39
- }
30
+ table.baseStore = table.options.store ?? createStore(table.initialState);
31
+ table.store = createStore(() => {
32
+ const state = table.baseStore.state;
33
+ return {
34
+ ...state,
35
+ ...table.options.state ?? {}
36
+ };
40
37
  });
41
38
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
42
39
  const features = Object.keys(table._features);
@@ -44,11 +41,11 @@ function constructTable(tableOptions) {
44
41
  const states = Object.keys(table.initialState);
45
42
  console.log(
46
43
  `Constructing Table Instance
47
-
44
+
48
45
  Features: ${features.join("\n ")}
49
-
46
+
50
47
  Row Models: ${rowModels.length ? rowModels.join("\n ") : "(none)"}
51
-
48
+
52
49
  States: ${states.join("\n ")}`
53
50
  );
54
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"constructTable.js","sources":["../../../../src/core/table/constructTable.ts"],"sourcesContent":["import { Derived, Store } from '@tanstack/store'\nimport {} from '../../utils'\nimport { coreFeatures } from '../coreFeatures'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState =\n feature.getInitialState?.(initialState as TableState<TFeatures>) ??\n initialState\n })\n return structuredClone(initialState) as TableState<TFeatures>\n}\n\nexport function createTableStore<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): Store<TableState<TFeatures>> {\n return new Store(getInitialTableState(features, initialState))\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const table = {\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n table.options = {\n ...defaultOptions,\n ...tableOptions,\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n table.baseStore =\n table.options.store ?? (new Store(table.initialState) as any)\n\n // @ts-ignore - complex TFeatures type inference does not work with Derived\n table.store = new Derived({\n deps: [table.baseStore],\n fn: ({ currDepVals }) => {\n const baseState = currDepVals[0]\n // Merge base state with user-provided external state (table.options.state takes precedence)\n return {\n ...baseState,\n ...(table.options.state ?? {}),\n } as TableState<TFeatures>\n },\n })\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n \n Features: ${features.join('\\n ')}\n \n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n \n States: ${states.join('\\n ')}`,\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"names":[],"mappings":";;AASO,SAAS,qBACd,UACA,eAA2D,IACpC;AACvB,SAAO,OAAO,QAAQ,EAAE,QAAQ,CAAC,YAAY;AAC3C,mBACE,QAAQ,kBAAkB,YAAqC,KAC/D;AAAA,EACJ,CAAC;AACD,SAAO,gBAAgB,YAAY;AACrC;AAEO,SAAS,iBACd,UACA,eAA2D,IAC7B;AAC9B,SAAO,IAAI,MAAM,qBAAqB,UAAU,YAAY,CAAC;AAC/D;AAEO,SAAS,eAGd,cAAuE;AACvE,QAAM,QAAQ;AAAA,IACZ,WAAW,EAAE,GAAG,cAAc,GAAG,aAAa,UAAA;AAAA,IAC9C,YAAY,CAAA;AAAA,IACZ,cAAc,CAAA;AAAA,EAAC;AAGjB,QAAM,eAAwC,OAAO,OAAO,MAAM,SAAS;AAE3E,QAAM,iBAAiB,aAAa,OAAO,CAAC,KAAK,YAAY;AAC3D,WAAO,OAAO,OAAO,KAAK,QAAQ,yBAAyB,KAAK,CAAC;AAAA,EACnE,GAAG,CAAA,CAAE;AAEL,QAAM,UAAU;AAAA,IACd,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGL,QAAM,eAAe;AAAA,IACnB,MAAM;AAAA,IACN,MAAM,QAAQ;AAAA,EAAA;AAGhB,QAAM,YACJ,MAAM,QAAQ,SAAU,IAAI,MAAM,MAAM,YAAY;AAGtD,QAAM,QAAQ,IAAI,QAAQ;AAAA,IACxB,MAAM,CAAC,MAAM,SAAS;AAAA,IACtB,IAAI,CAAC,EAAE,kBAAkB;AACvB,YAAM,YAAY,YAAY,CAAC;AAE/B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAI,MAAM,QAAQ,SAAS,CAAA;AAAA,MAAC;AAAA,IAEhC;AAAA,EAAA,CACD;AAED,MACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;AACA,UAAM,WAAW,OAAO,KAAK,MAAM,SAAS;AAC5C,UAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE;AAC5D,UAAM,SAAS,OAAO,KAAK,MAAM,YAAY;AAE7C,YAAQ;AAAA,MACN;AAAA;AAAA,gBAEU,SAAS,KAAK,kBAAkB,CAAC;AAAA;AAAA,gBAEjC,UAAU,SAAS,UAAU,KAAK,kBAAkB,IAAI,QAAQ;AAAA;AAAA,gBAEhE,OAAO,KAAK,kBAAkB,CAAC;AAAA,IAAA;AAAA,EAE7C;AAEA,aAAW,WAAW,cAAc;AAClC,YAAQ,qBAAqB,KAAK;AAAA,EACpC;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"constructTable.js","sources":["../../../../src/core/table/constructTable.ts"],"sourcesContent":["import { createStore } from '@tanstack/store'\nimport { coreFeatures } from '../coreFeatures'\nimport type { Store } from '@tanstack/store'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState =\n feature.getInitialState?.(initialState as TableState<TFeatures>) ??\n initialState\n })\n return structuredClone(initialState) as TableState<TFeatures>\n}\n\nexport function createTableStore<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): Store<TableState<TFeatures>> {\n return createStore(getInitialTableState(features, initialState))\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const table = {\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n table.options = {\n ...defaultOptions,\n ...tableOptions,\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n table.baseStore = table.options.store ?? createStore(table.initialState)\n\n table.store = createStore(() => {\n const state = table.baseStore.state\n return {\n ...state,\n ...(table.options.state ?? {}),\n }\n })\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}`,\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"names":[],"mappings":";;AASO,SAAS,qBACd,UACA,eAA2D,IACpC;AACvB,SAAO,OAAO,QAAQ,EAAE,QAAQ,CAAC,YAAY;AAC3C,mBACE,QAAQ,kBAAkB,YAAqC,KAC/D;AAAA,EACJ,CAAC;AACD,SAAO,gBAAgB,YAAY;AACrC;AAEO,SAAS,iBACd,UACA,eAA2D,IAC7B;AAC9B,SAAO,YAAY,qBAAqB,UAAU,YAAY,CAAC;AACjE;AAEO,SAAS,eAGd,cAAuE;AACvE,QAAM,QAAQ;AAAA,IACZ,WAAW,EAAE,GAAG,cAAc,GAAG,aAAa,UAAA;AAAA,IAC9C,YAAY,CAAA;AAAA,IACZ,cAAc,CAAA;AAAA,EAAC;AAGjB,QAAM,eAAwC,OAAO,OAAO,MAAM,SAAS;AAE3E,QAAM,iBAAiB,aAAa,OAAO,CAAC,KAAK,YAAY;AAC3D,WAAO,OAAO,OAAO,KAAK,QAAQ,yBAAyB,KAAK,CAAC;AAAA,EACnE,GAAG,CAAA,CAAE;AAEL,QAAM,UAAU;AAAA,IACd,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGL,QAAM,eAAe;AAAA,IACnB,MAAM;AAAA,IACN,MAAM,QAAQ;AAAA,EAAA;AAGhB,QAAM,YAAY,MAAM,QAAQ,SAAS,YAAY,MAAM,YAAY;AAEvE,QAAM,QAAQ,YAAY,MAAM;AAC9B,UAAM,QAAQ,MAAM,UAAU;AAC9B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,MAAM,QAAQ,SAAS,CAAA;AAAA,IAAC;AAAA,EAEhC,CAAC;AAED,MACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;AACA,UAAM,WAAW,OAAO,KAAK,MAAM,SAAS;AAC5C,UAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE;AAC5D,UAAM,SAAS,OAAO,KAAK,MAAM,YAAY;AAE7C,YAAQ;AAAA,MACN;AAAA;AAAA,gBAEU,SAAS,KAAK,kBAAkB,CAAC;AAAA;AAAA,gBAEjC,UAAU,SAAS,UAAU,KAAK,kBAAkB,IAAI,QAAQ;AAAA;AAAA,gBAEhE,OAAO,KAAK,kBAAkB,CAAC;AAAA,IAAA;AAAA,EAE7C;AAEA,aAAW,WAAW,cAAc;AAClC,YAAQ,qBAAqB,KAAK;AAAA,EACpC;AAEA,SAAO;AACT;"}
@@ -1,4 +1,4 @@
1
- import { Derived, Store } from '@tanstack/store';
1
+ import { ReadonlyStore, Store } from '@tanstack/store';
2
2
  import { CoreFeatures } from '../coreFeatures.js';
3
3
  import { RowModelFns } from '../../types/RowModelFns.js';
4
4
  import { RowData, Updater } from '../../types/type-utils.js';
@@ -24,7 +24,7 @@ export interface TableOptions_Table<TFeatures extends TableFeatures, TData exten
24
24
  /**
25
25
  * The data for the table to display. When the `data` option changes reference, the table will reprocess the data.
26
26
  */
27
- data: Array<TData>;
27
+ data: ReadonlyArray<TData>;
28
28
  /**
29
29
  * Use this option to optionally pass initial state to the table. This state will be used when resetting various table states either automatically by the table (eg. `options.autoResetPageIndex`) or via functions like `table.resetRowSelection()`. Most reset function allow you optionally pass a flag to reset to a blank/default state instead of the initial state.
30
30
  * Table state will not be reset when this object changes, which also means that the initial state object does not need to be stable.
@@ -91,7 +91,7 @@ export interface Table_CoreProperties<TFeatures extends TableFeatures, TData ext
91
91
  /**
92
92
  * Where the table state is stored.
93
93
  */
94
- store: Derived<TableState<TFeatures>, [Store<TableState<TFeatures>>]>;
94
+ store: ReadonlyStore<TableState<TFeatures>>;
95
95
  }
96
96
  export interface Table_Table<TFeatures extends TableFeatures, TData extends RowData> extends Table_CoreProperties<TFeatures, TData> {
97
97
  /**
@@ -1,6 +1,6 @@
1
1
  import { functionalUpdate } from "../../utils.js";
2
2
  function table_reset(table) {
3
- table.baseStore.setState(structuredClone(table.initialState));
3
+ table.baseStore.setState(() => structuredClone(table.initialState));
4
4
  }
5
5
  function table_mergeOptions(table, newOptions) {
6
6
  if (table.options.mergeOptions) {
@@ -1 +1 @@
1
- {"version":3,"file":"coreTablesFeature.utils.js","sources":["../../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { functionalUpdate } from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\n\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n table.baseStore.setState(structuredClone(table.initialState))\n}\n\nexport function table_mergeOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n newOptions: TableOptions<TFeatures, TData>,\n) {\n if (table.options.mergeOptions) {\n return table.options.mergeOptions(table.options, newOptions)\n }\n\n return {\n ...table.options,\n ...newOptions,\n }\n}\n\nexport function table_setOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<TableOptions<TFeatures, TData>>,\n): void {\n const newOptions = functionalUpdate(updater, table.options)\n table.options = table_mergeOptions(table, newOptions)\n}\n"],"names":[],"mappings":";AAMO,SAAS,YAGd,OAA+C;AAC/C,QAAM,UAAU,SAAS,gBAAgB,MAAM,YAAY,CAAC;AAC9D;AAEO,SAAS,mBAId,OACA,YACA;AACA,MAAI,MAAM,QAAQ,cAAc;AAC9B,WAAO,MAAM,QAAQ,aAAa,MAAM,SAAS,UAAU;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,iBAId,OACA,SACM;AACN,QAAM,aAAa,iBAAiB,SAAS,MAAM,OAAO;AAC1D,QAAM,UAAU,mBAAmB,OAAO,UAAU;AACtD;"}
1
+ {"version":3,"file":"coreTablesFeature.utils.js","sources":["../../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { functionalUpdate } from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\n\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n table.baseStore.setState(() => structuredClone(table.initialState))\n}\n\nexport function table_mergeOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n newOptions: TableOptions<TFeatures, TData>,\n) {\n if (table.options.mergeOptions) {\n return table.options.mergeOptions(table.options, newOptions)\n }\n\n return {\n ...table.options,\n ...newOptions,\n }\n}\n\nexport function table_setOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<TableOptions<TFeatures, TData>>,\n): void {\n const newOptions = functionalUpdate(updater, table.options)\n table.options = table_mergeOptions(table, newOptions)\n}\n"],"names":[],"mappings":";AAMO,SAAS,YAGd,OAA+C;AAC/C,QAAM,UAAU,SAAS,MAAM,gBAAgB,MAAM,YAAY,CAAC;AACpE;AAEO,SAAS,mBAId,OACA,YACA;AACA,MAAI,MAAM,QAAQ,cAAc;AAC9B,WAAO,MAAM,QAAQ,aAAa,MAAM,SAAS,UAAU;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,iBAId,OACA,SACM;AACN,QAAM,aAAa,iBAAiB,SAAS,MAAM,OAAO;AAC1D,QAAM,UAAU,mBAAmB,OAAO,UAAU;AACtD;"}
@@ -44,7 +44,7 @@ export type IdentifiedColumnDef<TFeatures extends TableFeatures, TData extends R
44
44
  };
45
45
  export type DisplayColumnDef<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = ColumnDefBase<TFeatures, TData, TValue> & ColumnIdentifiers<TFeatures, TData, TValue>;
46
46
  type GroupColumnDefBase<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = ColumnDefBase<TFeatures, TData, TValue> & {
47
- columns?: Array<ColumnDef<TFeatures, TData, unknown>>;
47
+ columns?: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>;
48
48
  };
49
49
  export type GroupColumnDef<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = GroupColumnDefBase<TFeatures, TData, TValue> & ColumnIdentifiers<TFeatures, TData, TValue>;
50
50
  export type AccessorFnColumnDefBase<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = ColumnDefBase<TFeatures, TData, TValue> & {
@@ -1,4 +1,4 @@
1
- import { Derived, Store } from '@tanstack/store';
1
+ import { ReadonlyStore, Store } from '@tanstack/store';
2
2
  import { Table_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types';
3
3
  import { Table_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types';
4
4
  import { Table_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types';
@@ -49,5 +49,5 @@ export type Table_Internal<TFeatures extends TableFeatures, TData extends RowDat
49
49
  };
50
50
  initialState: TableState_All;
51
51
  baseStore: Store<TableState_All>;
52
- store: Derived<TableState_All>;
52
+ store: ReadonlyStore<TableState_All>;
53
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "9.0.0-alpha.11",
3
+ "version": "9.0.0-alpha.13",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "src"
46
46
  ],
47
47
  "dependencies": {
48
- "@tanstack/store": "^0.8.0"
48
+ "@tanstack/store": "^0.9.1"
49
49
  },
50
50
  "scripts": {
51
51
  "clean": "rimraf ./build && rimraf ./dist",
@@ -65,7 +65,7 @@ export interface TableOptions_Columns<
65
65
  /**
66
66
  * The array of column defs to use for the table.
67
67
  */
68
- columns: Array<ColumnDef<TFeatures, TData, TValue>>
68
+ columns: ReadonlyArray<ColumnDef<TFeatures, TData, TValue>>
69
69
  /**
70
70
  * Default column options to use for all column defs supplied to the table.
71
71
  */
@@ -79,7 +79,7 @@ export function table_getAllColumns<
79
79
  table: Table_Internal<TFeatures, TData>,
80
80
  ): Array<Column<TFeatures, TData, unknown>> {
81
81
  const recurseColumns = (
82
- colDefs: Array<ColumnDef<TFeatures, TData, unknown>>,
82
+ colDefs: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>,
83
83
  parent?: Column<TFeatures, TData, unknown>,
84
84
  depth = 0,
85
85
  ): Array<Column<TFeatures, TData, unknown>> => {
@@ -29,7 +29,7 @@ function _createCoreRowModel<
29
29
  TData extends RowData,
30
30
  >(
31
31
  table: Table_Internal<TFeatures, TData>,
32
- data: Array<TData>,
32
+ data: ReadonlyArray<TData>,
33
33
  ): {
34
34
  rows: Array<Row<TFeatures, TData>>
35
35
  flatRows: Array<Row<TFeatures, TData>>
@@ -42,7 +42,7 @@ function _createCoreRowModel<
42
42
  }
43
43
 
44
44
  const accessRows = (
45
- originalRows: Array<TData>,
45
+ originalRows: ReadonlyArray<TData>,
46
46
  depth = 0,
47
47
  parentRow?: Row<TFeatures, TData>,
48
48
  ): Array<Row<TFeatures, TData>> => {
@@ -29,7 +29,7 @@ export interface Row_CoreProperties<
29
29
  /**
30
30
  * An array of the original subRows as returned by the `options.getSubRows` option.
31
31
  */
32
- originalSubRows?: Array<TData>
32
+ originalSubRows?: ReadonlyArray<TData>
33
33
  /**
34
34
  * If nested, this row's parent row id.
35
35
  */
@@ -96,7 +96,10 @@ export interface TableOptions_Rows<
96
96
  * This optional function is used to access the sub rows for any given row. If you are using nested rows, you will need to use this function to return the sub rows object (or undefined) from the row.
97
97
  * @example getSubRows: row => row.subRows
98
98
  */
99
- getSubRows?: (originalRow: TData, index: number) => undefined | Array<TData>
99
+ getSubRows?: (
100
+ originalRow: TData,
101
+ index: number,
102
+ ) => undefined | ReadonlyArray<TData>
100
103
  }
101
104
 
102
105
  export interface Table_Rows<
@@ -1,6 +1,6 @@
1
- import { Derived, Store } from '@tanstack/store'
2
- import {} from '../../utils'
1
+ import { createStore } from '@tanstack/store'
3
2
  import { coreFeatures } from '../coreFeatures'
3
+ import type { Store } from '@tanstack/store'
4
4
  import type { RowData } from '../../types/type-utils'
5
5
  import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
6
6
  import type { Table, Table_Internal } from '../../types/Table'
@@ -23,7 +23,7 @@ export function createTableStore<TFeatures extends TableFeatures>(
23
23
  features: TFeatures,
24
24
  initialState: Partial<TableState<TFeatures>> | undefined = {},
25
25
  ): Store<TableState<TFeatures>> {
26
- return new Store(getInitialTableState(features, initialState))
26
+ return createStore(getInitialTableState(features, initialState))
27
27
  }
28
28
 
29
29
  export function constructTable<
@@ -52,20 +52,14 @@ export function constructTable<
52
52
  table.options.initialState,
53
53
  )
54
54
 
55
- table.baseStore =
56
- table.options.store ?? (new Store(table.initialState) as any)
57
-
58
- // @ts-ignore - complex TFeatures type inference does not work with Derived
59
- table.store = new Derived({
60
- deps: [table.baseStore],
61
- fn: ({ currDepVals }) => {
62
- const baseState = currDepVals[0]
63
- // Merge base state with user-provided external state (table.options.state takes precedence)
64
- return {
65
- ...baseState,
66
- ...(table.options.state ?? {}),
67
- } as TableState<TFeatures>
68
- },
55
+ table.baseStore = table.options.store ?? createStore(table.initialState)
56
+
57
+ table.store = createStore(() => {
58
+ const state = table.baseStore.state
59
+ return {
60
+ ...state,
61
+ ...(table.options.state ?? {}),
62
+ }
69
63
  })
70
64
 
71
65
  if (
@@ -78,11 +72,11 @@ export function constructTable<
78
72
 
79
73
  console.log(
80
74
  `Constructing Table Instance
81
-
75
+
82
76
  Features: ${features.join('\n ')}
83
-
77
+
84
78
  Row Models: ${rowModels.length ? rowModels.join('\n ') : '(none)'}
85
-
79
+
86
80
  States: ${states.join('\n ')}`,
87
81
  )
88
82
  }
@@ -1,4 +1,4 @@
1
- import type { Derived, Store } from '@tanstack/store'
1
+ import type { ReadonlyStore, Store } from '@tanstack/store'
2
2
  import type { CoreFeatures } from '../coreFeatures'
3
3
  import type { RowModelFns } from '../../types/RowModelFns'
4
4
  import type { RowData, Updater } from '../../types/type-utils'
@@ -31,7 +31,7 @@ export interface TableOptions_Table<
31
31
  /**
32
32
  * The data for the table to display. When the `data` option changes reference, the table will reprocess the data.
33
33
  */
34
- data: Array<TData>
34
+ data: ReadonlyArray<TData>
35
35
  /**
36
36
  * Use this option to optionally pass initial state to the table. This state will be used when resetting various table states either automatically by the table (eg. `options.autoResetPageIndex`) or via functions like `table.resetRowSelection()`. Most reset function allow you optionally pass a flag to reset to a blank/default state instead of the initial state.
37
37
  * Table state will not be reset when this object changes, which also means that the initial state object does not need to be stable.
@@ -105,7 +105,7 @@ export interface Table_CoreProperties<
105
105
  /**
106
106
  * Where the table state is stored.
107
107
  */
108
- store: Derived<TableState<TFeatures>, [Store<TableState<TFeatures>>]>
108
+ store: ReadonlyStore<TableState<TFeatures>>
109
109
  }
110
110
 
111
111
  export interface Table_Table<
@@ -8,7 +8,7 @@ export function table_reset<
8
8
  TFeatures extends TableFeatures,
9
9
  TData extends RowData,
10
10
  >(table: Table_Internal<TFeatures, TData>): void {
11
- table.baseStore.setState(structuredClone(table.initialState))
11
+ table.baseStore.setState(() => structuredClone(table.initialState))
12
12
  }
13
13
 
14
14
  export function table_mergeOptions<
@@ -150,7 +150,7 @@ type GroupColumnDefBase<
150
150
  TData extends RowData,
151
151
  TValue extends CellData = CellData,
152
152
  > = ColumnDefBase<TFeatures, TData, TValue> & {
153
- columns?: Array<ColumnDef<TFeatures, TData, unknown>>
153
+ columns?: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>
154
154
  }
155
155
 
156
156
  export type GroupColumnDef<
@@ -1,4 +1,4 @@
1
- import type { Derived, Store } from '@tanstack/store'
1
+ import type { ReadonlyStore, Store } from '@tanstack/store'
2
2
  import type { Table_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types'
3
3
  import type { Table_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types'
4
4
  import type { Table_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
@@ -121,5 +121,5 @@ export type Table_Internal<
121
121
  }
122
122
  initialState: TableState_All
123
123
  baseStore: Store<TableState_All>
124
- store: Derived<TableState_All>
124
+ store: ReadonlyStore<TableState_All>
125
125
  }