@tanstack/react-table 9.0.0-alpha.4 → 9.0.0-alpha.40

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 (65) hide show
  1. package/README.md +117 -0
  2. package/dist/FlexRender.cjs +61 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +51 -0
  5. package/dist/FlexRender.d.ts +51 -0
  6. package/dist/FlexRender.js +58 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/Subscribe.cjs +14 -0
  9. package/dist/Subscribe.cjs.map +1 -0
  10. package/dist/Subscribe.d.cts +103 -0
  11. package/dist/Subscribe.d.ts +103 -0
  12. package/dist/Subscribe.js +13 -0
  13. package/dist/Subscribe.js.map +1 -0
  14. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  15. package/dist/createTableHook.cjs +313 -0
  16. package/dist/createTableHook.cjs.map +1 -0
  17. package/dist/createTableHook.d.cts +358 -0
  18. package/dist/createTableHook.d.ts +358 -0
  19. package/dist/createTableHook.js +311 -0
  20. package/dist/createTableHook.js.map +1 -0
  21. package/dist/flex-render.cjs +5 -0
  22. package/dist/flex-render.d.cts +2 -0
  23. package/dist/flex-render.d.ts +2 -0
  24. package/dist/flex-render.js +3 -0
  25. package/dist/index.cjs +18 -0
  26. package/dist/index.d.cts +6 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +8 -0
  29. package/dist/legacy.cjs +14 -0
  30. package/dist/legacy.d.cts +2 -0
  31. package/dist/legacy.d.ts +2 -0
  32. package/dist/legacy.js +3 -0
  33. package/dist/static-functions.cjs +9 -0
  34. package/dist/static-functions.d.cts +1 -0
  35. package/dist/static-functions.d.ts +1 -0
  36. package/dist/static-functions.js +3 -0
  37. package/dist/useLegacyTable.cjs +193 -0
  38. package/dist/useLegacyTable.cjs.map +1 -0
  39. package/dist/useLegacyTable.d.cts +234 -0
  40. package/dist/useLegacyTable.d.ts +234 -0
  41. package/dist/useLegacyTable.js +182 -0
  42. package/dist/useLegacyTable.js.map +1 -0
  43. package/dist/useTable.cjs +41 -0
  44. package/dist/useTable.cjs.map +1 -0
  45. package/dist/useTable.d.cts +92 -0
  46. package/dist/useTable.d.ts +92 -0
  47. package/dist/useTable.js +40 -0
  48. package/dist/useTable.js.map +1 -0
  49. package/package.json +37 -20
  50. package/src/FlexRender.tsx +147 -0
  51. package/src/Subscribe.ts +199 -0
  52. package/src/createTableHook.tsx +1118 -0
  53. package/src/flex-render.ts +1 -0
  54. package/src/index.ts +6 -0
  55. package/src/legacy.ts +3 -0
  56. package/src/static-functions.ts +1 -0
  57. package/src/useLegacyTable.ts +489 -0
  58. package/src/useTable.ts +160 -0
  59. package/dist/cjs/index.cjs +0 -78
  60. package/dist/cjs/index.cjs.map +0 -1
  61. package/dist/cjs/index.d.cts +0 -9
  62. package/dist/esm/index.d.ts +0 -9
  63. package/dist/esm/index.js +0 -55
  64. package/dist/esm/index.js.map +0 -1
  65. package/src/index.tsx +0 -94
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLegacyTable.js","names":[],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return () => () => undefined\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return () => () => new Map()\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\nexport type RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\nexport type FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\nexport type FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\nexport type FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n // Build the _rowModels object based on which legacy options were provided\n const _rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Map v8 row model factories to v9 _rowModels\n // Note: getCoreRowModel is handled automatically in v9, so we ignore it\n\n if (getFilteredRowModel) {\n _rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n _rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n _rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n _rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n _rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n _rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n _rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n },\n (state) => state,\n )\n\n const getState = useCallback(() => {\n // all state except for columns and data\n return {\n ...table.state,\n columns: undefined,\n data: undefined,\n }\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () => ({\n ...table,\n getState,\n setState,\n }),\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,oBAAmB;;;;;;;;AASrB,SAAgB,yBAEuB;AACrC,oCAAmB,IAAI,KAAK;;;;;;;;AAS9B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,QAAO,oBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAGJ,MAAM,aAAwD,EAAE;AAKhE,KAAI,oBACF,YAAW,mBAAmB,uBAAuB;EACnD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,kBACF,YAAW,iBAAiB,qBAAqB;EAC/C,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,sBACF,YAAW,oBAAoB,yBAAyB;AAG1D,KAAI,oBACF,YAAW,mBAAmB,wBAAwB;AAGxD,KAAI,mBACF,YAAW,kBAAkB,sBAAsB;EACjD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,mBACF,YAAW,kBAAkB,uBAAuB;AAGtD,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;AAG9D,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;CAI9D,MAAM,QAAQ,SACZ;EACE,GAAG;EACH,WAAW;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,WAAW,kBAAkB;AAEjC,SAAO;GACL,GAAG,MAAM;GACT,SAAS;GACT,MAAM;GACP;IACA,CAAC,MAAM,CAAC;CAEX,MAAM,WAAW,aACd,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,QAAO,eACE;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAU;EAAS,CAC5B"}
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+
3
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
4
+ const require_FlexRender = require('./FlexRender.cjs');
5
+ const require_Subscribe = require('./Subscribe.cjs');
6
+ let _tanstack_table_core = require("@tanstack/table-core");
7
+ let react = require("react");
8
+ let _tanstack_react_store = require("@tanstack/react-store");
9
+
10
+ //#region src/useTable.ts
11
+ function useTable(tableOptions, selector = () => ({})) {
12
+ const [table] = (0, react.useState)(() => {
13
+ const tableInstance = (0, _tanstack_table_core.constructTable)(tableOptions);
14
+ tableInstance.Subscribe = ((props) => {
15
+ return require_Subscribe.Subscribe({
16
+ ...props,
17
+ table: tableInstance
18
+ });
19
+ });
20
+ tableInstance.FlexRender = require_FlexRender.FlexRender;
21
+ return tableInstance;
22
+ });
23
+ table.setOptions((prev) => ({
24
+ ...prev,
25
+ ...tableOptions
26
+ }));
27
+ const state = (0, _tanstack_react_store.useSelector)(table.store, selector, { compare: _tanstack_react_store.shallow });
28
+ return (0, react.useMemo)(() => ({
29
+ ...table,
30
+ options: tableOptions,
31
+ state
32
+ }), [
33
+ table,
34
+ tableOptions,
35
+ state
36
+ ]);
37
+ }
38
+
39
+ //#endregion
40
+ exports.useTable = useTable;
41
+ //# sourceMappingURL=useTable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AAiHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAOA,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,+CAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,+BAAS,CAAC;AAItE,kCACS;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
@@ -0,0 +1,92 @@
1
+ import { FlexRenderProps } from "./FlexRender.cjs";
2
+ import { SubscribePropsWithStore } from "./Subscribe.cjs";
3
+ import { FunctionComponent, ReactNode } from "react";
4
+ import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
5
+ import { Atom, ReadonlyAtom } from "@tanstack/react-store";
6
+
7
+ //#region src/useTable.d.ts
8
+ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
9
+ /**
10
+ * A React HOC (Higher Order Component) that allows you to subscribe to the table state.
11
+ *
12
+ * This is useful for opting into state re-renders for specific parts of the table state.
13
+ *
14
+ * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
15
+ * or `table.optionsStore`) instead of the full `table.store`.
16
+ *
17
+ * @example
18
+ * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
19
+ * {({ rowSelection }) => (
20
+ * <tr key={row.id}>...</tr>
21
+ * )}
22
+ * </table.Subscribe>
23
+ *
24
+ * @example
25
+ * <table.Subscribe source={table.atoms.rowSelection}>
26
+ * {(rowSelection) => <div>...</div>}
27
+ * </table.Subscribe>
28
+ *
29
+ * @example
30
+ * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
31
+ * {() => <tr key={row.id}>...</tr>}
32
+ * </table.Subscribe>
33
+ */
34
+ /**
35
+ * Overloads (not a single union) so `selector` callbacks get correct contextual
36
+ * types in JSX; a union of two `selector` signatures degrades to implicit `any`.
37
+ *
38
+ * Source **without** `selector` is a separate overload so children receive `TSourceValue`
39
+ * (identity projection). If `selector` were optional on one overload, `TSubSelected`
40
+ * would default to `unknown` instead of inferring from the source.
41
+ *
42
+ * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
43
+ */
44
+ Subscribe: {
45
+ <TSourceValue>(props: {
46
+ source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
47
+ selector?: undefined;
48
+ children: ((state: TSourceValue) => ReactNode) | ReactNode;
49
+ }): ReturnType<FunctionComponent>;
50
+ <TSourceValue, TSubSelected>(props: {
51
+ source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
52
+ selector: (state: TSourceValue) => TSubSelected;
53
+ children: ((state: TSubSelected) => ReactNode) | ReactNode;
54
+ }): ReturnType<FunctionComponent>;
55
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
56
+ };
57
+ /**
58
+ * A React component that renders headers, cells, or footers with custom markup.
59
+ * Use this utility component instead of manually calling flexRender.
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * <table.FlexRender cell={cell} />
64
+ * <table.FlexRender header={header} />
65
+ * <table.FlexRender footer={footer} />
66
+ * ```
67
+ *
68
+ * This replaces calling `flexRender` directly like this:
69
+ * ```tsx
70
+ * flexRender(cell.column.columnDef.cell, cell.getContext())
71
+ * flexRender(header.column.columnDef.header, header.getContext())
72
+ * flexRender(footer.column.columnDef.footer, footer.getContext())
73
+ * ```
74
+ */
75
+ FlexRender: <TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>) => ReactNode;
76
+ /**
77
+ * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.
78
+ *
79
+ * @example
80
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
81
+ *
82
+ * console.log(table.state.globalFilter)
83
+ */
84
+ readonly state: Readonly<TSelected> & {
85
+ columns: TableOptions<TFeatures, TData>['columns'];
86
+ data: TableOptions<TFeatures, TData>['data'];
87
+ };
88
+ };
89
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): ReactTable<TFeatures, TData, TSelected>;
90
+ //#endregion
91
+ export { ReactTable, useTable };
92
+ //# sourceMappingURL=useTable.d.cts.map
@@ -0,0 +1,92 @@
1
+ import { FlexRenderProps } from "./FlexRender.js";
2
+ import { SubscribePropsWithStore } from "./Subscribe.js";
3
+ import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
4
+ import { FunctionComponent, ReactNode } from "react";
5
+ import { Atom, ReadonlyAtom } from "@tanstack/react-store";
6
+
7
+ //#region src/useTable.d.ts
8
+ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
9
+ /**
10
+ * A React HOC (Higher Order Component) that allows you to subscribe to the table state.
11
+ *
12
+ * This is useful for opting into state re-renders for specific parts of the table state.
13
+ *
14
+ * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
15
+ * or `table.optionsStore`) instead of the full `table.store`.
16
+ *
17
+ * @example
18
+ * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
19
+ * {({ rowSelection }) => (
20
+ * <tr key={row.id}>...</tr>
21
+ * )}
22
+ * </table.Subscribe>
23
+ *
24
+ * @example
25
+ * <table.Subscribe source={table.atoms.rowSelection}>
26
+ * {(rowSelection) => <div>...</div>}
27
+ * </table.Subscribe>
28
+ *
29
+ * @example
30
+ * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
31
+ * {() => <tr key={row.id}>...</tr>}
32
+ * </table.Subscribe>
33
+ */
34
+ /**
35
+ * Overloads (not a single union) so `selector` callbacks get correct contextual
36
+ * types in JSX; a union of two `selector` signatures degrades to implicit `any`.
37
+ *
38
+ * Source **without** `selector` is a separate overload so children receive `TSourceValue`
39
+ * (identity projection). If `selector` were optional on one overload, `TSubSelected`
40
+ * would default to `unknown` instead of inferring from the source.
41
+ *
42
+ * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
43
+ */
44
+ Subscribe: {
45
+ <TSourceValue>(props: {
46
+ source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
47
+ selector?: undefined;
48
+ children: ((state: TSourceValue) => ReactNode) | ReactNode;
49
+ }): ReturnType<FunctionComponent>;
50
+ <TSourceValue, TSubSelected>(props: {
51
+ source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
52
+ selector: (state: TSourceValue) => TSubSelected;
53
+ children: ((state: TSubSelected) => ReactNode) | ReactNode;
54
+ }): ReturnType<FunctionComponent>;
55
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
56
+ };
57
+ /**
58
+ * A React component that renders headers, cells, or footers with custom markup.
59
+ * Use this utility component instead of manually calling flexRender.
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * <table.FlexRender cell={cell} />
64
+ * <table.FlexRender header={header} />
65
+ * <table.FlexRender footer={footer} />
66
+ * ```
67
+ *
68
+ * This replaces calling `flexRender` directly like this:
69
+ * ```tsx
70
+ * flexRender(cell.column.columnDef.cell, cell.getContext())
71
+ * flexRender(header.column.columnDef.header, header.getContext())
72
+ * flexRender(footer.column.columnDef.footer, footer.getContext())
73
+ * ```
74
+ */
75
+ FlexRender: <TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>) => ReactNode;
76
+ /**
77
+ * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.
78
+ *
79
+ * @example
80
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
81
+ *
82
+ * console.log(table.state.globalFilter)
83
+ */
84
+ readonly state: Readonly<TSelected> & {
85
+ columns: TableOptions<TFeatures, TData>['columns'];
86
+ data: TableOptions<TFeatures, TData>['data'];
87
+ };
88
+ };
89
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): ReactTable<TFeatures, TData, TSelected>;
90
+ //#endregion
91
+ export { ReactTable, useTable };
92
+ //# sourceMappingURL=useTable.d.ts.map
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+
3
+ import { FlexRender } from "./FlexRender.js";
4
+ import { Subscribe } from "./Subscribe.js";
5
+ import { constructTable } from "@tanstack/table-core";
6
+ import { useMemo, useState } from "react";
7
+ import { shallow, useSelector } from "@tanstack/react-store";
8
+
9
+ //#region src/useTable.ts
10
+ function useTable(tableOptions, selector = () => ({})) {
11
+ const [table] = useState(() => {
12
+ const tableInstance = constructTable(tableOptions);
13
+ tableInstance.Subscribe = ((props) => {
14
+ return Subscribe({
15
+ ...props,
16
+ table: tableInstance
17
+ });
18
+ });
19
+ tableInstance.FlexRender = FlexRender;
20
+ return tableInstance;
21
+ });
22
+ table.setOptions((prev) => ({
23
+ ...prev,
24
+ ...tableOptions
25
+ }));
26
+ const state = useSelector(table.store, selector, { compare: shallow });
27
+ return useMemo(() => ({
28
+ ...table,
29
+ options: tableOptions,
30
+ state
31
+ }), [
32
+ table,
33
+ tableOptions,
34
+ state
35
+ ]);
36
+ }
37
+
38
+ //#endregion
39
+ export { useTable };
40
+ //# sourceMappingURL=useTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;AAiHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAItE,QAAO,eACE;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
- "version": "9.0.0-alpha.4",
3
+ "version": "9.0.0-alpha.40",
4
4
  "description": "Headless UI for building powerful tables & datagrids for React.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -21,41 +21,58 @@
21
21
  "datagrid"
22
22
  ],
23
23
  "type": "module",
24
- "types": "dist/esm/index.d.ts",
25
- "main": "dist/cjs/index.cjs",
26
- "module": "dist/esm/index.js",
24
+ "types": "./dist/index.d.cts",
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.js",
27
27
  "exports": {
28
28
  ".": {
29
- "import": {
30
- "types": "./dist/esm/index.d.ts",
31
- "default": "./dist/esm/index.js"
32
- },
33
- "require": {
34
- "types": "./dist/cjs/index.d.cts",
35
- "default": "./dist/cjs/index.cjs"
36
- }
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
31
+ },
32
+ "./flex-render": {
33
+ "import": "./dist/flex-render.js",
34
+ "require": "./dist/flex-render.cjs"
35
+ },
36
+ "./legacy": {
37
+ "import": "./dist/legacy.js",
38
+ "require": "./dist/legacy.cjs"
39
+ },
40
+ "./static-functions": {
41
+ "import": "./dist/static-functions.js",
42
+ "require": "./dist/static-functions.cjs"
37
43
  },
38
44
  "./package.json": "./package.json"
39
45
  },
40
46
  "sideEffects": false,
41
47
  "engines": {
42
- "node": ">=12"
48
+ "node": ">=16"
43
49
  },
44
50
  "files": [
45
51
  "dist",
46
52
  "src"
47
53
  ],
48
54
  "dependencies": {
49
- "@tanstack/table-core": "9.0.0-alpha.4"
55
+ "@tanstack/react-store": "^0.11.0",
56
+ "@tanstack/table-core": "9.0.0-alpha.39"
50
57
  },
51
58
  "devDependencies": {
52
- "@types/react": "^18.3.0",
53
- "@vitejs/plugin-react": "^4.2.1",
54
- "react": "^18.3.0"
59
+ "@eslint-react/eslint-plugin": "^4.2.3",
60
+ "@types/react": "^19.2.14",
61
+ "@vitejs/plugin-react": "^6.0.1",
62
+ "eslint-plugin-react-compiler": "19.1.0-rc.2",
63
+ "eslint-plugin-react-hooks": "^7.1.1",
64
+ "react": "^19.2.5"
55
65
  },
56
66
  "peerDependencies": {
57
- "react": ">=16.8",
58
- "react-dom": ">=16.8"
67
+ "react": ">=18"
59
68
  },
60
- "scripts": {}
69
+ "scripts": {
70
+ "clean": "rimraf ./build && rimraf ./dist",
71
+ "test:eslint": "eslint ./src",
72
+ "test:lib": "vitest --passWithNoTests",
73
+ "test:lib:dev": "pnpm test:lib --watch",
74
+ "test:types": "tsc",
75
+ "test:build": "publint --strict",
76
+ "build": "tsdown"
77
+ }
61
78
  }
@@ -0,0 +1,147 @@
1
+ import React from 'react'
2
+ import type {
3
+ Cell,
4
+ CellData,
5
+ Header,
6
+ RowData,
7
+ TableFeatures,
8
+ } from '@tanstack/table-core'
9
+ import type { ComponentType, JSX, ReactNode } from 'react'
10
+
11
+ export type Renderable<TProps> = ReactNode | ComponentType<TProps>
12
+
13
+ function isReactComponent<TProps>(
14
+ component: unknown,
15
+ ): component is ComponentType<TProps> {
16
+ return (
17
+ isClassComponent(component) ||
18
+ typeof component === 'function' ||
19
+ isExoticComponent(component)
20
+ )
21
+ }
22
+
23
+ function isClassComponent(component: any) {
24
+ return (
25
+ typeof component === 'function' &&
26
+ (() => {
27
+ const proto = Object.getPrototypeOf(component)
28
+ return proto.prototype && proto.prototype.isReactComponent
29
+ })()
30
+ )
31
+ }
32
+
33
+ function isExoticComponent(component: any) {
34
+ return (
35
+ typeof component === 'object' &&
36
+ typeof component.$$typeof === 'symbol' &&
37
+ ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
38
+ )
39
+ }
40
+
41
+ /**
42
+ * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
43
+ * @example flexRender(cell.column.columnDef.cell, cell.getContext())
44
+ */
45
+ export function flexRender<TProps extends object>(
46
+ Comp: Renderable<TProps>,
47
+ props: TProps,
48
+ ): ReactNode | JSX.Element {
49
+ return !Comp ? null : isReactComponent<TProps>(Comp) ? (
50
+ <Comp {...props} />
51
+ ) : (
52
+ Comp
53
+ )
54
+ }
55
+
56
+ /**
57
+ * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
58
+ * Only one prop (`cell`, `header`, or `footer`) may be passed.
59
+ * @example <FlexRender cell={cell} />
60
+ * @example <FlexRender header={header} />
61
+ * @example <FlexRender footer={footer} />
62
+ */
63
+ export type FlexRenderProps<
64
+ TFeatures extends TableFeatures,
65
+ TData extends RowData,
66
+ TValue extends CellData = CellData,
67
+ > =
68
+ | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }
69
+ | {
70
+ header: Header<TFeatures, TData, TValue>
71
+ cell?: never
72
+ footer?: never
73
+ }
74
+ | {
75
+ footer: Header<TFeatures, TData, TValue>
76
+ cell?: never
77
+ header?: never
78
+ }
79
+
80
+ /**
81
+ * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
82
+ * Only one prop (`cell`, `header`, or `footer`) may be passed.
83
+ * @example
84
+ * ```tsx
85
+ * <FlexRender cell={cell} />
86
+ * <FlexRender header={header} />
87
+ * <FlexRender footer={footer} />
88
+ * ```
89
+ *
90
+ * This replaces calling `flexRender` directly like this:
91
+ * ```tsx
92
+ * flexRender(cell.column.columnDef.cell, cell.getContext())
93
+ * flexRender(header.column.columnDef.header, header.getContext())
94
+ * flexRender(footer.column.columnDef.footer, footer.getContext())
95
+ * ```
96
+ */
97
+ export function FlexRender<
98
+ TFeatures extends TableFeatures,
99
+ TData extends RowData,
100
+ TValue extends CellData = CellData,
101
+ >(props: FlexRenderProps<TFeatures, TData, TValue>) {
102
+ if ('cell' in props && props.cell) {
103
+ const cell = props.cell
104
+ const def = cell.column.columnDef
105
+ // When the column-grouping feature is registered, a cell can be in one of
106
+ // three special modes that should not render `columnDef.cell` directly:
107
+ // - aggregated: render `columnDef.aggregatedCell` (falling back to
108
+ // `columnDef.cell` if the column did not define one)
109
+ // - placeholder: a duplicate value within a group — render nothing
110
+ // - grouped: the group header cell — let the consumer render this; we
111
+ // fall through to `columnDef.cell` so the existing behavior is
112
+ // preserved (consumers that want a custom group header typically
113
+ // branch on `cell.getIsGrouped()` themselves before calling FlexRender)
114
+ // The optional-chaining + cast keeps this safe when the grouping feature
115
+ // is not registered (the methods are absent at the type level then).
116
+ const groupingCell = cell as typeof cell & {
117
+ getIsAggregated?: () => boolean
118
+ getIsPlaceholder?: () => boolean
119
+ }
120
+ const groupingDef = def as typeof def & {
121
+ aggregatedCell?: typeof def.cell
122
+ }
123
+ if (groupingCell.getIsAggregated?.()) {
124
+ return flexRender(
125
+ groupingDef.aggregatedCell ?? def.cell,
126
+ cell.getContext(),
127
+ )
128
+ }
129
+ if (groupingCell.getIsPlaceholder?.()) {
130
+ return null
131
+ }
132
+ return flexRender(def.cell, cell.getContext())
133
+ }
134
+ if ('header' in props && props.header) {
135
+ return flexRender(
136
+ props.header.column.columnDef.header,
137
+ props.header.getContext(),
138
+ )
139
+ }
140
+ if ('footer' in props && props.footer) {
141
+ return flexRender(
142
+ props.footer.column.columnDef.footer,
143
+ props.footer.getContext(),
144
+ )
145
+ }
146
+ return null
147
+ }