@tanstack/react-table 9.0.0-alpha.21 → 9.0.0-alpha.23
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.
- package/dist/FlexRender.cjs +52 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +51 -0
- package/dist/FlexRender.d.ts +51 -0
- package/dist/FlexRender.js +49 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/Subscribe.cjs +39 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +49 -0
- package/dist/Subscribe.d.ts +49 -0
- package/dist/Subscribe.js +38 -0
- package/dist/Subscribe.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/createTableHook.cjs +313 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +358 -0
- package/dist/createTableHook.d.ts +358 -0
- package/dist/createTableHook.js +311 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/{esm/index.js → index.js} +5 -10
- package/dist/legacy.cjs +14 -0
- package/dist/legacy.d.cts +2 -0
- package/dist/legacy.d.ts +2 -0
- package/dist/legacy.js +3 -0
- package/dist/useLegacyTable.cjs +167 -0
- package/dist/useLegacyTable.cjs.map +1 -0
- package/dist/useLegacyTable.d.cts +214 -0
- package/dist/{esm/useLegacyTable.d.ts → useLegacyTable.d.ts} +79 -74
- package/dist/useLegacyTable.js +156 -0
- package/dist/useLegacyTable.js.map +1 -0
- package/dist/useTable.cjs +41 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +60 -0
- package/dist/useTable.d.ts +60 -0
- package/dist/useTable.js +40 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +16 -20
- package/src/createTableHook.tsx +6 -7
- package/src/useTable.ts +12 -19
- package/dist/esm/FlexRender.d.ts +0 -46
- package/dist/esm/FlexRender.js +0 -39
- package/dist/esm/FlexRender.js.map +0 -1
- package/dist/esm/Subscribe.d.ts +0 -44
- package/dist/esm/Subscribe.js +0 -10
- package/dist/esm/Subscribe.js.map +0 -1
- package/dist/esm/createTableHook.d.ts +0 -349
- package/dist/esm/createTableHook.js +0 -130
- package/dist/esm/createTableHook.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/legacy.d.ts +0 -1
- package/dist/esm/legacy.js +0 -15
- package/dist/esm/legacy.js.map +0 -1
- package/dist/esm/useLegacyTable.js +0 -111
- package/dist/esm/useLegacyTable.js.map +0 -1
- package/dist/esm/useTable.d.ts +0 -52
- package/dist/esm/useTable.js +0 -47
- package/dist/esm/useTable.js.map +0 -1
package/dist/useTable.js
ADDED
|
@@ -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, useStore } 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 = function SubscribeBound(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 selectorWithDataAndColumns = (state) => ({
|
|
27
|
+
columns: tableOptions.columns,
|
|
28
|
+
data: tableOptions.data,
|
|
29
|
+
...selector(state)
|
|
30
|
+
});
|
|
31
|
+
const state = useStore(table.store, selectorWithDataAndColumns, shallow);
|
|
32
|
+
return useMemo(() => ({
|
|
33
|
+
...table,
|
|
34
|
+
state
|
|
35
|
+
}), [state, table]);
|
|
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, useStore } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribeProps } 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 * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax\n * <tr key={row.id}>\n // render the row\n * </tr>\n * ))}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n }) => ReturnType<FunctionComponent>\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 = function SubscribeBound<TSelected>(\n props: Omit<SubscribeProps<TFeatures, TData, TSelected>, 'table'>,\n ) {\n return Subscribe({ ...props, table: tableInstance })\n }\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 selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useStore(table.store, selectorWithDataAndColumns, shallow)\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;AA8EA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe,aAAa;AAMlD,gBAAc,YAAY,SAAS,eACjC,OACA;AACA,UAAO,UAAU;IAAE,GAAG;IAAO,OAAO;IAAe,CAAC;;AAGtD,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,QAAQ,SAAS,MAAM,OAAO,4BAA4B,QAAQ;AAExE,QAAO,eACE;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.23",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for React.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,23 +21,19 @@
|
|
|
21
21
|
"datagrid"
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
|
-
"types": "dist/
|
|
25
|
-
"main": "dist/
|
|
26
|
-
"module": "dist/
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
-
"default": "./dist/esm/index.js"
|
|
32
|
-
}
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
33
31
|
},
|
|
34
|
-
"./package.json": "./package.json",
|
|
35
32
|
"./legacy": {
|
|
36
|
-
"import":
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
33
|
+
"import": "./dist/legacy.js",
|
|
34
|
+
"require": "./dist/legacy.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
41
37
|
},
|
|
42
38
|
"sideEffects": false,
|
|
43
39
|
"engines": {
|
|
@@ -48,13 +44,13 @@
|
|
|
48
44
|
"src"
|
|
49
45
|
],
|
|
50
46
|
"dependencies": {
|
|
51
|
-
"@tanstack/react-store": "^0.9.
|
|
52
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
47
|
+
"@tanstack/react-store": "^0.9.3",
|
|
48
|
+
"@tanstack/table-core": "9.0.0-alpha.23"
|
|
53
49
|
},
|
|
54
50
|
"devDependencies": {
|
|
55
|
-
"@eslint-react/eslint-plugin": "^2.
|
|
56
|
-
"@types/react": "^19.2.
|
|
57
|
-
"@vitejs/plugin-react": "^
|
|
51
|
+
"@eslint-react/eslint-plugin": "^4.2.1",
|
|
52
|
+
"@types/react": "^19.2.14",
|
|
53
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
58
54
|
"eslint-plugin-react-compiler": "19.1.0-rc.2",
|
|
59
55
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
60
56
|
"react": "^19.2.4"
|
|
@@ -69,6 +65,6 @@
|
|
|
69
65
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
70
66
|
"test:types": "tsc",
|
|
71
67
|
"test:build": "publint --strict",
|
|
72
|
-
"build": "
|
|
68
|
+
"build": "tsdown"
|
|
73
69
|
}
|
|
74
70
|
}
|
package/src/createTableHook.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
/* eslint-disable @eslint-react/no-context-provider */
|
|
3
|
-
// eslint-disable-next-line @eslint-react/no-use-context -- intentional useContext for older React support
|
|
4
3
|
import React, { createContext, useContext, useMemo } from 'react'
|
|
5
4
|
import { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'
|
|
6
5
|
import { useTable } from './useTable'
|
|
@@ -675,8 +674,8 @@ export function createTableHook<
|
|
|
675
674
|
TFeatures,
|
|
676
675
|
TData
|
|
677
676
|
> {
|
|
678
|
-
// useContext
|
|
679
|
-
// eslint-disable-next-line @eslint-react/no-use-context -- intentional
|
|
677
|
+
// `useContext` keeps React 18 support; `use(Context)` is React 19+ only.
|
|
678
|
+
// eslint-disable-next-line @eslint-react/no-use-context -- intentional for React 18
|
|
680
679
|
const table = useContext(TableContext)
|
|
681
680
|
|
|
682
681
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -709,8 +708,8 @@ export function createTableHook<
|
|
|
709
708
|
* ```
|
|
710
709
|
*/
|
|
711
710
|
function useCellContext<TValue extends CellData = CellData>() {
|
|
712
|
-
// useContext
|
|
713
|
-
// eslint-disable-next-line @eslint-react/no-use-context -- intentional
|
|
711
|
+
// `useContext` keeps React 18 support; `use(Context)` is React 19+ only.
|
|
712
|
+
// eslint-disable-next-line @eslint-react/no-use-context -- intentional for React 18
|
|
714
713
|
const cell = useContext(CellContext)
|
|
715
714
|
|
|
716
715
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -751,8 +750,8 @@ export function createTableHook<
|
|
|
751
750
|
* ```
|
|
752
751
|
*/
|
|
753
752
|
function useHeaderContext<TValue extends CellData = CellData>() {
|
|
754
|
-
// useContext
|
|
755
|
-
// eslint-disable-next-line @eslint-react/no-use-context -- intentional
|
|
753
|
+
// `useContext` keeps React 18 support; `use(Context)` is React 19+ only.
|
|
754
|
+
// eslint-disable-next-line @eslint-react/no-use-context -- intentional for React 18
|
|
756
755
|
const header = useContext(HeaderContext)
|
|
757
756
|
|
|
758
757
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
package/src/useTable.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useMemo, useState } from 'react'
|
|
4
4
|
import { constructTable } from '@tanstack/table-core'
|
|
5
5
|
import { shallow, useStore } from '@tanstack/react-store'
|
|
6
6
|
import { FlexRender } from './FlexRender'
|
|
@@ -18,9 +18,6 @@ import type { FunctionComponent, ReactNode } from 'react'
|
|
|
18
18
|
import type { FlexRenderProps } from './FlexRender'
|
|
19
19
|
import type { SubscribeProps } from './Subscribe'
|
|
20
20
|
|
|
21
|
-
const useIsomorphicLayoutEffect =
|
|
22
|
-
typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
23
|
-
|
|
24
21
|
export type ReactTable<
|
|
25
22
|
TFeatures extends TableFeatures,
|
|
26
23
|
TData extends RowData,
|
|
@@ -73,7 +70,10 @@ export type ReactTable<
|
|
|
73
70
|
*
|
|
74
71
|
* console.log(table.state.globalFilter)
|
|
75
72
|
*/
|
|
76
|
-
readonly state: Readonly<TSelected>
|
|
73
|
+
readonly state: Readonly<TSelected> & {
|
|
74
|
+
columns: TableOptions<TFeatures, TData>['columns']
|
|
75
|
+
data: TableOptions<TFeatures, TData>['data']
|
|
76
|
+
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function useTable<
|
|
@@ -109,20 +109,13 @@ export function useTable<
|
|
|
109
109
|
...tableOptions,
|
|
110
110
|
}))
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}))
|
|
118
|
-
})
|
|
119
|
-
}, [
|
|
120
|
-
table.options.columns, // re-render when columns change
|
|
121
|
-
table.options.data, // re-render when data changes
|
|
122
|
-
table.options.state, // sync react state to the table store
|
|
123
|
-
])
|
|
112
|
+
const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({
|
|
113
|
+
columns: tableOptions.columns,
|
|
114
|
+
data: tableOptions.data,
|
|
115
|
+
...selector(state),
|
|
116
|
+
})
|
|
124
117
|
|
|
125
|
-
const state = useStore(table.store,
|
|
118
|
+
const state = useStore(table.store, selectorWithDataAndColumns, shallow)
|
|
126
119
|
|
|
127
120
|
return useMemo(
|
|
128
121
|
() => ({
|
|
@@ -130,5 +123,5 @@ export function useTable<
|
|
|
130
123
|
state,
|
|
131
124
|
}),
|
|
132
125
|
[state, table],
|
|
133
|
-
)
|
|
126
|
+
) as ReactTable<TFeatures, TData, TSelected>
|
|
134
127
|
}
|
package/dist/esm/FlexRender.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { default as React, ComponentType, JSX, ReactNode } from 'react';
|
|
2
|
-
import { Cell, CellData, Header, RowData, TableFeatures } from '@tanstack/table-core';
|
|
3
|
-
export type Renderable<TProps> = ReactNode | ComponentType<TProps>;
|
|
4
|
-
/**
|
|
5
|
-
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
6
|
-
* @example flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
7
|
-
*/
|
|
8
|
-
export declare function flexRender<TProps extends object>(Comp: Renderable<TProps>, props: TProps): ReactNode | JSX.Element;
|
|
9
|
-
/**
|
|
10
|
-
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
11
|
-
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
12
|
-
* @example <FlexRender cell={cell} />
|
|
13
|
-
* @example <FlexRender header={header} />
|
|
14
|
-
* @example <FlexRender footer={footer} />
|
|
15
|
-
*/
|
|
16
|
-
export type FlexRenderProps<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = {
|
|
17
|
-
cell: Cell<TFeatures, TData, TValue>;
|
|
18
|
-
header?: never;
|
|
19
|
-
footer?: never;
|
|
20
|
-
} | {
|
|
21
|
-
header: Header<TFeatures, TData, TValue>;
|
|
22
|
-
cell?: never;
|
|
23
|
-
footer?: never;
|
|
24
|
-
} | {
|
|
25
|
-
footer: Header<TFeatures, TData, TValue>;
|
|
26
|
-
cell?: never;
|
|
27
|
-
header?: never;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
31
|
-
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* <FlexRender cell={cell} />
|
|
35
|
-
* <FlexRender header={header} />
|
|
36
|
-
* <FlexRender footer={footer} />
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* This replaces calling `flexRender` directly like this:
|
|
40
|
-
* ```tsx
|
|
41
|
-
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
42
|
-
* flexRender(header.column.columnDef.header, header.getContext())
|
|
43
|
-
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function FlexRender<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | JSX.Element | null | undefined;
|
package/dist/esm/FlexRender.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
function isReactComponent(component) {
|
|
3
|
-
return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
|
|
4
|
-
}
|
|
5
|
-
function isClassComponent(component) {
|
|
6
|
-
return typeof component === "function" && (() => {
|
|
7
|
-
const proto = Object.getPrototypeOf(component);
|
|
8
|
-
return proto.prototype && proto.prototype.isReactComponent;
|
|
9
|
-
})();
|
|
10
|
-
}
|
|
11
|
-
function isExoticComponent(component) {
|
|
12
|
-
return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
|
|
13
|
-
}
|
|
14
|
-
function flexRender(Comp, props) {
|
|
15
|
-
return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ jsx(Comp, { ...props }) : Comp;
|
|
16
|
-
}
|
|
17
|
-
function FlexRender(props) {
|
|
18
|
-
if ("cell" in props && props.cell) {
|
|
19
|
-
return flexRender(props.cell.column.columnDef.cell, props.cell.getContext());
|
|
20
|
-
}
|
|
21
|
-
if ("header" in props && props.header) {
|
|
22
|
-
return flexRender(
|
|
23
|
-
props.header.column.columnDef.header,
|
|
24
|
-
props.header.getContext()
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
if ("footer" in props && props.footer) {
|
|
28
|
-
return flexRender(
|
|
29
|
-
props.footer.column.columnDef.footer,
|
|
30
|
-
props.footer.getContext()
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
FlexRender,
|
|
37
|
-
flexRender
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=FlexRender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlexRender.js","sources":["../../src/FlexRender.tsx"],"sourcesContent":["import React from 'react'\nimport type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentType, JSX, ReactNode } from 'react'\n\nexport type Renderable<TProps> = ReactNode | ComponentType<TProps>\n\nfunction isReactComponent<TProps>(\n component: unknown,\n): component is ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps,\n): ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <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 */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n return flexRender(props.cell.column.columnDef.cell, props.cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"names":[],"mappings":";AAYA,SAAS,iBACP,WACoC;AACpC,SACE,iBAAiB,SAAS,KAC1B,OAAO,cAAc,cACrB,kBAAkB,SAAS;AAE/B;AAEA,SAAS,iBAAiB,WAAgB;AACxC,SACE,OAAO,cAAc,eACpB,MAAM;AACL,UAAM,QAAQ,OAAO,eAAe,SAAS;AAC7C,WAAO,MAAM,aAAa,MAAM,UAAU;AAAA,EAC5C,GAAA;AAEJ;AAEA,SAAS,kBAAkB,WAAgB;AACzC,SACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,cAAc,mBAAmB,EAAE,SAAS,UAAU,SAAS,WAAW;AAE/E;AAMO,SAAS,WACd,MACA,OACyB;AACzB,SAAO,CAAC,OAAO,OAAO,iBAAyB,IAAI,IACjD,oBAAC,MAAA,EAAM,GAAG,MAAA,CAAO,IAEjB;AAEJ;AA2CO,SAAS,WAId,OAAkD;AAClD,MAAI,UAAU,SAAS,MAAM,MAAM;AACjC,WAAO,WAAW,MAAM,KAAK,OAAO,UAAU,MAAM,MAAM,KAAK,YAAY;AAAA,EAC7E;AACA,MAAI,YAAY,SAAS,MAAM,QAAQ;AACrC,WAAO;AAAA,MACL,MAAM,OAAO,OAAO,UAAU;AAAA,MAC9B,MAAM,OAAO,WAAA;AAAA,IAAW;AAAA,EAE5B;AACA,MAAI,YAAY,SAAS,MAAM,QAAQ;AACrC,WAAO;AAAA,MACL,MAAM,OAAO,OAAO,UAAU;AAAA,MAC9B,MAAM,OAAO,WAAA;AAAA,IAAW;AAAA,EAE5B;AACA,SAAO;AACT;"}
|
package/dist/esm/Subscribe.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { NoInfer, RowData, Table, TableFeatures, TableState } from '@tanstack/table-core';
|
|
2
|
-
import { FunctionComponent, ReactNode } from 'react';
|
|
3
|
-
export type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = {
|
|
4
|
-
/**
|
|
5
|
-
* The table instance to subscribe to. Required when using as a standalone component.
|
|
6
|
-
* Not needed when using as `table.Subscribe`.
|
|
7
|
-
*/
|
|
8
|
-
table: Table<TFeatures, TData>;
|
|
9
|
-
/**
|
|
10
|
-
* A selector function that selects the part of the table state to subscribe to.
|
|
11
|
-
* This allows for fine-grained reactivity by only re-rendering when the selected state changes.
|
|
12
|
-
*/
|
|
13
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
|
|
14
|
-
/**
|
|
15
|
-
* The children to render. Can be a function that receives the selected state, or a React node.
|
|
16
|
-
*/
|
|
17
|
-
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A React component that allows you to subscribe to the table state.
|
|
21
|
-
*
|
|
22
|
-
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* // As a standalone component
|
|
27
|
-
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
28
|
-
* {({ rowSelection }) => (
|
|
29
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
30
|
-
* )}
|
|
31
|
-
* </Subscribe>
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* // As table.Subscribe (table instance method)
|
|
37
|
-
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
38
|
-
* {({ rowSelection }) => (
|
|
39
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
40
|
-
* )}
|
|
41
|
-
* </table.Subscribe>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(props: SubscribeProps<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
package/dist/esm/Subscribe.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useStore, shallow } from "@tanstack/react-store";
|
|
3
|
-
function Subscribe(props) {
|
|
4
|
-
const selected = useStore(props.table.store, props.selector, shallow);
|
|
5
|
-
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
6
|
-
}
|
|
7
|
-
export {
|
|
8
|
-
Subscribe
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=Subscribe.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Subscribe.js","sources":["../../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useStore } from '@tanstack/react-store'\nimport type {\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = {\n /**\n * The table instance to subscribe to. Required when using as a standalone component.\n * Not needed when using as `table.Subscribe`.\n */\n table: Table<TFeatures, TData>\n /**\n * A selector function that selects the part of the table state to subscribe to.\n * This allows for fine-grained reactivity by only re-rendering when the selected state changes.\n */\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n /**\n * The children to render. Can be a function that receives the selected state, or a React node.\n */\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * A React 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 * @example\n * ```tsx\n * // As a standalone component\n * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // As table.Subscribe (table instance method)\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </table.Subscribe>\n * ```\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n props: SubscribeProps<TFeatures, TData, TSelected>,\n): ReturnType<FunctionComponent> {\n const selected = useStore(props.table.store, props.selector, shallow)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n}\n"],"names":[],"mappings":";;AA0DO;AAOL;AAEA;AAGF;;;;"}
|