react-hook-tanstack-table 0.0.1 → 0.0.3
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/README.md +78 -0
- package/dist/TableContext.cjs +1 -6
- package/dist/TableContext.js +1 -7
- package/dist/TableContext.js.map +1 -1
- package/dist/index.cjs +1 -40
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -11
- package/dist/invariant-BzSvgtnX.cjs +1 -0
- package/dist/invariant-DhtaPrYv.js +2 -0
- package/dist/invariant-DhtaPrYv.js.map +1 -0
- package/dist/useCell.cjs +1 -53
- package/dist/useCell.d.cts +9 -9
- package/dist/useCell.d.cts.map +1 -1
- package/dist/useCell.d.ts +9 -9
- package/dist/useCell.d.ts.map +1 -1
- package/dist/useCell.js +1 -52
- package/dist/useCell.js.map +1 -1
- package/dist/useColumn.cjs +1 -54
- package/dist/useColumn.d.cts +8 -8
- package/dist/useColumn.d.cts.map +1 -1
- package/dist/useColumn.d.ts +8 -8
- package/dist/useColumn.d.ts.map +1 -1
- package/dist/useColumn.js +1 -53
- package/dist/useColumn.js.map +1 -1
- package/dist/useHeader.cjs +1 -48
- package/dist/useHeader.d.cts +8 -8
- package/dist/useHeader.d.cts.map +1 -1
- package/dist/useHeader.d.ts +8 -8
- package/dist/useHeader.d.ts.map +1 -1
- package/dist/useHeader.js +1 -47
- package/dist/useHeader.js.map +1 -1
- package/dist/useReactTable-2xEFEdvR.js +2 -0
- package/dist/{useReactTable-Y2z5JrT_.js.map → useReactTable-2xEFEdvR.js.map} +1 -1
- package/dist/useReactTable-BnYobIs-.cjs +1 -0
- package/dist/useReactTable.cjs +1 -3
- package/dist/useReactTable.js +1 -2
- package/dist/useRow.cjs +1 -54
- package/dist/useRow.d.cts +8 -8
- package/dist/useRow.d.cts.map +1 -1
- package/dist/useRow.d.ts +8 -8
- package/dist/useRow.d.ts.map +1 -1
- package/dist/useRow.js +1 -53
- package/dist/useRow.js.map +1 -1
- package/dist/useTable.cjs +1 -44
- package/dist/useTable.d.cts +5 -5
- package/dist/useTable.d.cts.map +1 -1
- package/dist/useTable.d.ts +5 -5
- package/dist/useTable.d.ts.map +1 -1
- package/dist/useTable.js +1 -43
- package/dist/useTable.js.map +1 -1
- package/dist/useTableBase-BLBisaqE.cjs +1 -0
- package/dist/useTableBase-CgF6IzQm.js +2 -0
- package/dist/useTableBase-CgF6IzQm.js.map +1 -0
- package/package.json +1 -5
- package/src/hooks/useCell.ts +41 -30
- package/src/hooks/useColumn.ts +32 -22
- package/src/hooks/useHeader.ts +32 -22
- package/src/hooks/useRow.ts +20 -14
- package/src/hooks/useTable.ts +33 -18
- package/src/index.ts +0 -1
- package/src/lib/hasTableArg.ts +1 -1
- package/src/{hooks/useTableWithSelector.ts → lib/useTableBase.ts} +5 -5
- package/README.org +0 -29
- package/dist/hasTableArg-Bu3FbcSo.js +0 -8
- package/dist/hasTableArg-Bu3FbcSo.js.map +0 -1
- package/dist/hasTableArg-dMtayKWH.cjs +0 -11
- package/dist/invariant-BgWq7zZS.js +0 -12
- package/dist/invariant-BgWq7zZS.js.map +0 -1
- package/dist/invariant-D8b385d_.cjs +0 -21
- package/dist/isShallowEqual-D6PQ041u.cjs +0 -36
- package/dist/isShallowEqual-Kynsoe7a.js +0 -33
- package/dist/isShallowEqual-Kynsoe7a.js.map +0 -1
- package/dist/runGetters-BfRTE7LZ.js +0 -16
- package/dist/runGetters-BfRTE7LZ.js.map +0 -1
- package/dist/runGetters-Q-UsPG2j.cjs +0 -19
- package/dist/useReactTable-Y2z5JrT_.js +0 -70
- package/dist/useReactTable-nxQRPiMU.cjs +0 -95
- package/dist/useTableWithSelector-Bdsf6Zxk.cjs +0 -79
- package/dist/useTableWithSelector-D3f689pF.js +0 -70
- package/dist/useTableWithSelector-D3f689pF.js.map +0 -1
- package/dist/useTableWithSelector.cjs +0 -3
- package/dist/useTableWithSelector.d.cts +0 -8
- package/dist/useTableWithSelector.d.cts.map +0 -1
- package/dist/useTableWithSelector.d.ts +0 -8
- package/dist/useTableWithSelector.d.ts.map +0 -1
- package/dist/useTableWithSelector.js +0 -2
package/src/hooks/useRow.ts
CHANGED
|
@@ -15,15 +15,15 @@ import { isShallowEqual } from "../lib/isShallowEqual"
|
|
|
15
15
|
|
|
16
16
|
import type { IsEqual, RunGetters } from "../types"
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { useTableBase } from "../lib/useTableBase"
|
|
19
19
|
|
|
20
|
-
export interface
|
|
20
|
+
export interface RowSnapshot<TData extends RowData> extends RunGetters<
|
|
21
21
|
Row<TData>
|
|
22
22
|
> {}
|
|
23
23
|
|
|
24
24
|
const hookRowCache = new WeakMap<
|
|
25
25
|
RequiredKeys<TableOptionsResolved<any>, "state">,
|
|
26
|
-
Map<string,
|
|
26
|
+
Map<string, RowSnapshot<any>>
|
|
27
27
|
>()
|
|
28
28
|
|
|
29
29
|
const rowHandlersCache = new WeakMap<
|
|
@@ -34,10 +34,10 @@ const rowHandlersCache = new WeakMap<
|
|
|
34
34
|
}
|
|
35
35
|
>()
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const getRowSnapshot = <TData extends RowData>(
|
|
38
38
|
table: Table<TData>,
|
|
39
39
|
rowId: string,
|
|
40
|
-
):
|
|
40
|
+
): RowSnapshot<TData> => {
|
|
41
41
|
let rowCache = hookRowCache.get(table.options)
|
|
42
42
|
if (!rowCache) {
|
|
43
43
|
rowCache = new Map()
|
|
@@ -78,19 +78,21 @@ const getRowValues = <TData extends RowData>(
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
type Selector<TData extends RowData, Selection> = (
|
|
81
|
-
|
|
81
|
+
rowSnapshot: RowSnapshot<TData>,
|
|
82
|
+
row: Row<TData>,
|
|
83
|
+
table: Table<TData>
|
|
82
84
|
) => Selection
|
|
83
85
|
|
|
84
|
-
export const useRow = <TData extends RowData, Selection =
|
|
86
|
+
export const useRow = <TData extends RowData, Selection = RowSnapshot<TData>>(
|
|
85
87
|
...args:
|
|
86
88
|
| [
|
|
87
89
|
table: Table<TData> | undefined,
|
|
88
|
-
row: Row<TData> |
|
|
90
|
+
row: Row<TData> | RowSnapshot<TData> | { id: string } | string,
|
|
89
91
|
selector?: Selector<TData, Selection> | undefined,
|
|
90
92
|
isEqual?: IsEqual<NoInfer<Selection>> | undefined,
|
|
91
93
|
]
|
|
92
94
|
| [
|
|
93
|
-
row: Row<TData> |
|
|
95
|
+
row: Row<TData> | RowSnapshot<TData> | { id: string } | string,
|
|
94
96
|
selector?: Selector<TData, Selection> | undefined,
|
|
95
97
|
isEqual?: IsEqual<NoInfer<Selection>> | undefined,
|
|
96
98
|
]
|
|
@@ -105,11 +107,15 @@ export const useRow = <TData extends RowData, Selection = RowValues<TData>>(
|
|
|
105
107
|
const rowId = typeof rowOrId === "string" ? rowOrId : rowOrId.id
|
|
106
108
|
|
|
107
109
|
const getSelection = useCallback(
|
|
108
|
-
(table: Table<TData>) => selector(
|
|
110
|
+
(table: Table<TData>) => selector(
|
|
111
|
+
getRowSnapshot(table, rowId),
|
|
112
|
+
table.getRow(rowId),
|
|
113
|
+
table
|
|
114
|
+
),
|
|
109
115
|
[rowId, selector],
|
|
110
116
|
)
|
|
111
117
|
|
|
112
|
-
return
|
|
118
|
+
return useTableBase(table, getSelection, isEqual)
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
const rowHook = useRow
|
|
@@ -119,11 +125,11 @@ const rowHookʹ =
|
|
|
119
125
|
...args:
|
|
120
126
|
| [
|
|
121
127
|
table: Table<TData> | undefined,
|
|
122
|
-
row: Row<TData> |
|
|
128
|
+
row: Row<TData> | RowSnapshot<TData> | { id: string } | string,
|
|
123
129
|
]
|
|
124
|
-
| [row: Row<TData> |
|
|
130
|
+
| [row: Row<TData> | RowSnapshot<TData> | { id: string } | string]
|
|
125
131
|
) =>
|
|
126
|
-
<Selection =
|
|
132
|
+
<Selection = RowSnapshot<TData>>(
|
|
127
133
|
selector?: Selector<TData, Selection> | undefined,
|
|
128
134
|
isEqual?: IsEqual<NoInfer<Selection>> | undefined,
|
|
129
135
|
): Selection =>
|
package/src/hooks/useTable.ts
CHANGED
|
@@ -10,18 +10,19 @@ import type {
|
|
|
10
10
|
import { identity } from "../lib/identity"
|
|
11
11
|
import { runGetters } from "../lib/runGetters"
|
|
12
12
|
import { isShallowEqual } from "../lib/isShallowEqual"
|
|
13
|
+
import { hasTableArg } from "../lib/hasTableArg"
|
|
13
14
|
|
|
14
15
|
import type { IsEqual, RunGetters } from "../types"
|
|
15
16
|
|
|
16
|
-
import {
|
|
17
|
+
import { useTableBase } from "../lib/useTableBase"
|
|
17
18
|
|
|
18
|
-
export interface
|
|
19
|
+
export interface TableSnapshot<TData extends RowData> extends RunGetters<
|
|
19
20
|
Table<TData>
|
|
20
21
|
> {}
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const tableSnapshotCache = new WeakMap<
|
|
23
24
|
RequiredKeys<TableOptionsResolved<any>, "state">,
|
|
24
|
-
|
|
25
|
+
TableSnapshot<any>
|
|
25
26
|
>()
|
|
26
27
|
|
|
27
28
|
const tableHandlersCache = new WeakMap<
|
|
@@ -42,10 +43,10 @@ const tableHandlersCache = new WeakMap<
|
|
|
42
43
|
}
|
|
43
44
|
>()
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
+
const getTableSnapshot = <TData extends RowData>(
|
|
46
47
|
table: Table<TData>,
|
|
47
|
-
):
|
|
48
|
-
let cached =
|
|
48
|
+
): TableSnapshot<TData> => {
|
|
49
|
+
let cached = tableSnapshotCache.get(table.options)
|
|
49
50
|
if (!cached) {
|
|
50
51
|
let cachedHandlers = tableHandlersCache.get(table)
|
|
51
52
|
if (!cachedHandlers) {
|
|
@@ -78,35 +79,49 @@ const getTableValues = <TData extends RowData>(
|
|
|
78
79
|
toggleAllRowsExpandedHandler,
|
|
79
80
|
toggleAllRowsSelectedHandler,
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
tableSnapshotCache.set(table.options, cached)
|
|
82
83
|
}
|
|
83
84
|
return cached
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
type Selector<TData extends RowData, Selection> = (
|
|
87
|
-
|
|
88
|
+
tableSnapshot: TableSnapshot<TData>,
|
|
89
|
+
table: Table<TData>
|
|
88
90
|
) => Selection
|
|
89
91
|
|
|
90
|
-
export const useTable = <TData extends RowData, Selection =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
export const useTable = <TData extends RowData, Selection = TableSnapshot<TData>>(
|
|
93
|
+
...args:
|
|
94
|
+
| [
|
|
95
|
+
table: Table<TData> | undefined,
|
|
96
|
+
selector?: Selector<TData, Selection> | undefined,
|
|
97
|
+
isEqual?: IsEqual<NoInfer<Selection>> | undefined,
|
|
98
|
+
]
|
|
99
|
+
| [
|
|
100
|
+
selector?: Selector<TData, Selection> | undefined,
|
|
101
|
+
isEqual?: IsEqual<NoInfer<Selection>> | undefined,
|
|
102
|
+
]
|
|
94
103
|
): Selection => {
|
|
104
|
+
const [
|
|
105
|
+
table,
|
|
106
|
+
selector = identity as never,
|
|
107
|
+
isEqual = isShallowEqual,
|
|
108
|
+
] = hasTableArg(args) ? args : [undefined, ...args]
|
|
109
|
+
|
|
95
110
|
const getSelection = useCallback(
|
|
96
|
-
(table: Table<TData>) => selector(
|
|
111
|
+
(table: Table<TData>) => selector(getTableSnapshot(table), table),
|
|
97
112
|
[selector],
|
|
98
113
|
)
|
|
99
114
|
|
|
100
|
-
return
|
|
115
|
+
return useTableBase(table, getSelection, isEqual)
|
|
101
116
|
}
|
|
102
117
|
|
|
103
118
|
const tableHook = useTable
|
|
104
119
|
|
|
105
120
|
const tableHookʹ =
|
|
106
121
|
<TData extends RowData>(table?: Table<TData> | undefined) =>
|
|
107
|
-
<Selection =
|
|
108
|
-
selector
|
|
109
|
-
isEqual
|
|
122
|
+
<Selection = TableSnapshot<TData>>(
|
|
123
|
+
selector?: Selector<TData, Selection> | undefined,
|
|
124
|
+
isEqual?: IsEqual<NoInfer<Selection>> | undefined
|
|
110
125
|
): Selection =>
|
|
111
126
|
tableHook(table, selector, isEqual)
|
|
112
127
|
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { TableContext } from "./contexts/TableContext"
|
|
|
5
5
|
|
|
6
6
|
export { useReactTable } from "./hooks/useReactTable"
|
|
7
7
|
|
|
8
|
-
export { useTableWithSelector } from './hooks/useTableWithSelector'
|
|
9
8
|
export { useTable, useTableʹ } from "./hooks/useTable"
|
|
10
9
|
export { useHeader, useHeaderʹ } from "./hooks/useHeader"
|
|
11
10
|
export { useColumn, useColumnʹ } from "./hooks/useColumn"
|
package/src/lib/hasTableArg.ts
CHANGED
|
@@ -12,7 +12,7 @@ const isTable = <TData extends RowData>(
|
|
|
12
12
|
|
|
13
13
|
export const hasTableArg = <
|
|
14
14
|
TData extends RowData,
|
|
15
|
-
Rest extends [
|
|
15
|
+
Rest extends [unknown?, ...unknown[]],
|
|
16
16
|
>(
|
|
17
17
|
args: [Table<TData> | undefined, ...Rest] | Rest,
|
|
18
18
|
): args is [Table<TData> | undefined, ...Rest] =>
|
|
@@ -16,13 +16,13 @@ import type {
|
|
|
16
16
|
|
|
17
17
|
import { TableContext } from "../contexts/TableContext"
|
|
18
18
|
|
|
19
|
-
import { identity } from "
|
|
20
|
-
import { tableRegistry } from "
|
|
21
|
-
import { invariant } from "
|
|
19
|
+
import { identity } from "./identity"
|
|
20
|
+
import { tableRegistry } from "./tableRegistry"
|
|
21
|
+
import { invariant } from "./invariant"
|
|
22
22
|
|
|
23
23
|
import type { IsEqual } from "../types"
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const useTableBase = <
|
|
26
26
|
TData extends RowData,
|
|
27
27
|
Selection = Table<TData>,
|
|
28
28
|
>(
|
|
@@ -36,7 +36,7 @@ export const useTableWithSelector = <
|
|
|
36
36
|
|
|
37
37
|
invariant(
|
|
38
38
|
resolvedTable,
|
|
39
|
-
"`
|
|
39
|
+
"`useTableBase` must be used as a descendent of `TableContext` or provided with a `Table` as an argument!",
|
|
40
40
|
)
|
|
41
41
|
|
|
42
42
|
const listeners = useMemo(
|
package/README.org
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
* React Hook TanStack Table
|
|
2
|
-
|
|
3
|
-
[[https://react.dev/reference/rules][Rules of React]] respecting bindings for [[https://tanstack.com/table][TanStack Table]].
|
|
4
|
-
|
|
5
|
-
** Development
|
|
6
|
-
|
|
7
|
-
- Install dependencies:
|
|
8
|
-
|
|
9
|
-
#+begin_src shell
|
|
10
|
-
yarn install
|
|
11
|
-
#+end_src
|
|
12
|
-
|
|
13
|
-
- Run the playground:
|
|
14
|
-
|
|
15
|
-
#+begin_src shell
|
|
16
|
-
yarn run play
|
|
17
|
-
#+end_src
|
|
18
|
-
|
|
19
|
-
- Run the unit tests:
|
|
20
|
-
|
|
21
|
-
#+begin_src shell
|
|
22
|
-
yarn run test
|
|
23
|
-
#+end_src
|
|
24
|
-
|
|
25
|
-
- Build the library:
|
|
26
|
-
|
|
27
|
-
#+begin_src shell
|
|
28
|
-
yarn run build
|
|
29
|
-
#+end_src
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { n as tableRegistry } from "./invariant-BgWq7zZS.js";
|
|
2
|
-
//#region src/lib/hasTableArg.ts
|
|
3
|
-
const isTable = (x) => typeof x === "object" && x !== null && tableRegistry.has(x);
|
|
4
|
-
const hasTableArg = (args) => isTable(args[0]) || args[0] === void 0;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { hasTableArg as t };
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=hasTableArg-Bu3FbcSo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasTableArg-Bu3FbcSo.js","names":[],"sources":["../src/lib/hasTableArg.ts"],"sourcesContent":["import type {\n RowData,\n Table,\n} from \"@tanstack/table-core\"\n\nimport { tableRegistry } from \"./tableRegistry\"\n\nconst isTable = <TData extends RowData>(\n x: unknown | Table<TData>,\n): x is Table<TData> =>\n typeof x === \"object\" && x !== null && tableRegistry.has(x as Table<TData>)\n\nexport const hasTableArg = <\n TData extends RowData,\n Rest extends [{}, ...unknown[]],\n>(\n args: [Table<TData> | undefined, ...Rest] | Rest,\n): args is [Table<TData> | undefined, ...Rest] =>\n isTable(args[0]) || args[0] === undefined\n"],"mappings":";;AAOA,MAAM,WACJ,MAEA,OAAO,MAAM,YAAY,MAAM,QAAQ,cAAc,IAAI,CAAiB;AAE5E,MAAa,eAIX,SAEA,QAAQ,KAAK,EAAE,KAAK,KAAK,OAAO,KAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const require_invariant = require("./invariant-D8b385d_.cjs");
|
|
2
|
-
//#region src/lib/hasTableArg.ts
|
|
3
|
-
const isTable = (x) => typeof x === "object" && x !== null && require_invariant.tableRegistry.has(x);
|
|
4
|
-
const hasTableArg = (args) => isTable(args[0]) || args[0] === void 0;
|
|
5
|
-
//#endregion
|
|
6
|
-
Object.defineProperty(exports, "hasTableArg", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return hasTableArg;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/lib/tableRegistry.ts
|
|
2
|
-
const tableRegistry = /* @__PURE__ */ new WeakMap();
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/lib/invariant.ts
|
|
5
|
-
function invariant(condition, message) {
|
|
6
|
-
if (condition) return;
|
|
7
|
-
throw new Error(["Invariant failed", typeof message === "function" ? message() : message].filter(Boolean).join(": "));
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { tableRegistry as n, invariant as t };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=invariant-BgWq7zZS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invariant-BgWq7zZS.js","names":[],"sources":["../src/lib/tableRegistry.ts","../src/lib/invariant.ts"],"sourcesContent":["import type { Table } from \"@tanstack/table-core\"\n\nexport const tableRegistry: WeakMap<Table<any>, { listeners: Set<() => void> }> = new WeakMap()\n","export function invariant(\n\tcondition: any,\n\tmessage?: string | (() => string) | undefined\n): asserts condition {\n if (condition) return\n throw new Error(\n\t\t[\n\t\t\t'Invariant failed',\n\t\t\ttypeof message === 'function' ? message() : message\n\t\t].filter(Boolean).join(': ')\n\t);\n}\n"],"mappings":";AAEA,MAAa,gCAAqE,IAAI,QAAQ;;;ACF9F,SAAgB,UACf,WACA,SACoB;CACnB,IAAI,WAAW;CACf,MAAM,IAAI,MACV,CACC,oBACA,OAAO,YAAY,aAAa,QAAQ,IAAI,OAC7C,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI,CAC5B;AACD"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region src/lib/tableRegistry.ts
|
|
2
|
-
const tableRegistry = /* @__PURE__ */ new WeakMap();
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/lib/invariant.ts
|
|
5
|
-
function invariant(condition, message) {
|
|
6
|
-
if (condition) return;
|
|
7
|
-
throw new Error(["Invariant failed", typeof message === "function" ? message() : message].filter(Boolean).join(": "));
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
Object.defineProperty(exports, "invariant", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return invariant;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "tableRegistry", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function() {
|
|
19
|
-
return tableRegistry;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region src/lib/isShallowEqual.ts
|
|
2
|
-
const isMapShallowEqual = (a, b) => {
|
|
3
|
-
if (a.size !== b.size) return false;
|
|
4
|
-
for (const [key, value] of a) {
|
|
5
|
-
const valueB = b.get(key);
|
|
6
|
-
if (value !== valueB || !Object.is(value, valueB)) return false;
|
|
7
|
-
}
|
|
8
|
-
return true;
|
|
9
|
-
};
|
|
10
|
-
const isSetShallowEqual = (a, b) => {
|
|
11
|
-
if (a.size !== b.size) return false;
|
|
12
|
-
for (const value of a) if (!b.has(value)) return false;
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
15
|
-
const isShallowEqual = (a, b) => {
|
|
16
|
-
if (a === b || Object.is(a, b)) return true;
|
|
17
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) return false;
|
|
18
|
-
if (a instanceof Map && b instanceof Map) return isMapShallowEqual(a, b);
|
|
19
|
-
if (a instanceof Set && b instanceof Set) return isSetShallowEqual(a, b);
|
|
20
|
-
const keys = Object.keys(a);
|
|
21
|
-
if (keys.length !== Object.keys(b).length) return false;
|
|
22
|
-
for (const key of keys) {
|
|
23
|
-
if (!Object.hasOwn(b, key)) return false;
|
|
24
|
-
const { [key]: valueA } = a;
|
|
25
|
-
const { [key]: valueB } = b;
|
|
26
|
-
if (valueA !== valueB || !Object.is(valueA, valueB)) return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
Object.defineProperty(exports, "isShallowEqual", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function() {
|
|
34
|
-
return isShallowEqual;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region src/lib/isShallowEqual.ts
|
|
2
|
-
const isMapShallowEqual = (a, b) => {
|
|
3
|
-
if (a.size !== b.size) return false;
|
|
4
|
-
for (const [key, value] of a) {
|
|
5
|
-
const valueB = b.get(key);
|
|
6
|
-
if (value !== valueB || !Object.is(value, valueB)) return false;
|
|
7
|
-
}
|
|
8
|
-
return true;
|
|
9
|
-
};
|
|
10
|
-
const isSetShallowEqual = (a, b) => {
|
|
11
|
-
if (a.size !== b.size) return false;
|
|
12
|
-
for (const value of a) if (!b.has(value)) return false;
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
15
|
-
const isShallowEqual = (a, b) => {
|
|
16
|
-
if (a === b || Object.is(a, b)) return true;
|
|
17
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) return false;
|
|
18
|
-
if (a instanceof Map && b instanceof Map) return isMapShallowEqual(a, b);
|
|
19
|
-
if (a instanceof Set && b instanceof Set) return isSetShallowEqual(a, b);
|
|
20
|
-
const keys = Object.keys(a);
|
|
21
|
-
if (keys.length !== Object.keys(b).length) return false;
|
|
22
|
-
for (const key of keys) {
|
|
23
|
-
if (!Object.hasOwn(b, key)) return false;
|
|
24
|
-
const { [key]: valueA } = a;
|
|
25
|
-
const { [key]: valueB } = b;
|
|
26
|
-
if (valueA !== valueB || !Object.is(valueA, valueB)) return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
export { isShallowEqual as t };
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=isShallowEqual-Kynsoe7a.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isShallowEqual-Kynsoe7a.js","names":[],"sources":["../src/lib/isShallowEqual.ts"],"sourcesContent":["const isMapShallowEqual = (\n a: ReadonlyMap<unknown, unknown>,\n b: ReadonlyMap<unknown, unknown>,\n): boolean => {\n if (a.size !== b.size) {\n return false;\n }\n\n for (const [key, value] of a) {\n const valueB = b.get(key);\n if (value !== valueB || !Object.is(value, valueB)) {\n return false;\n }\n }\n\n return true;\n}\n\nconst isSetShallowEqual = (\n a: ReadonlySet<unknown>,\n b: ReadonlySet<unknown>,\n): boolean => {\n if (a.size !== b.size) {\n return false;\n }\n\n for (const value of a) {\n if (!b.has(value)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport const isShallowEqual = <T> (a: T, b: T): boolean => {\n if (a === b || Object.is(a, b)) {\n return true;\n }\n\n if (\n typeof a !== \"object\" ||\n a === null ||\n typeof b !== \"object\" ||\n b === null\n ) {\n return false;\n }\n\n if (a instanceof Map && b instanceof Map) {\n return isMapShallowEqual(a, b);\n }\n\n if (a instanceof Set && b instanceof Set) {\n return isSetShallowEqual(a, b);\n }\n\n const keys = Object.keys(a);\n if (keys.length !== Object.keys(b).length) {\n return false;\n }\n\n for (const key of keys) {\n if (!Object.hasOwn(b, key)) {\n return false;\n }\n\n const { [key as keyof T]: valueA } = a;\n const { [key as keyof T]: valueB } = b;\n\n if (valueA !== valueB || !Object.is(valueA, valueB)) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";AAAA,MAAM,qBACJ,GACA,MACY;CACZ,IAAI,EAAE,SAAS,EAAE,MACf,OAAO;CAGT,KAAK,MAAM,CAAC,KAAK,UAAU,GAAG;EAC5B,MAAM,SAAS,EAAE,IAAI,GAAG;EACxB,IAAI,UAAU,UAAU,CAAC,OAAO,GAAG,OAAO,MAAM,GAC9C,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,MAAM,qBACJ,GACA,MACY;CACZ,IAAI,EAAE,SAAS,EAAE,MACf,OAAO;CAGT,KAAK,MAAM,SAAS,GAClB,IAAI,CAAC,EAAE,IAAI,KAAK,GACd,OAAO;CAIX,OAAO;AACT;AAEA,MAAa,kBAAsB,GAAM,MAAkB;CACzD,IAAI,MAAM,KAAK,OAAO,GAAG,GAAG,CAAC,GAC3B,OAAO;CAGT,IACE,OAAO,MAAM,YACb,MAAM,QACN,OAAO,MAAM,YACb,MAAM,MAEN,OAAO;CAGT,IAAI,aAAa,OAAO,aAAa,KACnC,OAAO,kBAAkB,GAAG,CAAC;CAG/B,IAAI,aAAa,OAAO,aAAa,KACnC,OAAO,kBAAkB,GAAG,CAAC;CAG/B,MAAM,OAAO,OAAO,KAAK,CAAC;CAC1B,IAAI,KAAK,WAAW,OAAO,KAAK,CAAC,EAAE,QACjC,OAAO;CAGT,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,CAAC,OAAO,OAAO,GAAG,GAAG,GACvB,OAAO;EAGT,MAAM,GAAG,MAAiB,WAAW;EACrC,MAAM,GAAG,MAAiB,WAAW;EAErC,IAAI,WAAW,UAAU,CAAC,OAAO,GAAG,QAAQ,MAAM,GAChD,OAAO;CAEX;CAEA,OAAO;AACT"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/lib/uncapitalize.ts
|
|
2
|
-
const uncapitalize = (str) => str.slice(0, 1).toLowerCase() + str.slice(1);
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/lib/runGetters.ts
|
|
5
|
-
const runGetters = (x) => Object.fromEntries(Object.entries(x).map(([key, value]) => {
|
|
6
|
-
if (typeof value === "function" && key.startsWith("get")) try {
|
|
7
|
-
return [uncapitalize(key.replace(/^get/, "")), value()];
|
|
8
|
-
} catch {
|
|
9
|
-
return [key, value];
|
|
10
|
-
}
|
|
11
|
-
return [key, value];
|
|
12
|
-
}));
|
|
13
|
-
//#endregion
|
|
14
|
-
export { runGetters as t };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=runGetters-BfRTE7LZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runGetters-BfRTE7LZ.js","names":[],"sources":["../src/lib/uncapitalize.ts","../src/lib/runGetters.ts"],"sourcesContent":["export const uncapitalize = (str: string): string =>\n str.slice(0, 1).toLowerCase() + str.slice(1)\n","import type { RunGetters } from \"../types\"\nimport { uncapitalize } from \"./uncapitalize\"\n\nexport const runGetters = <T extends object>(x: T): RunGetters<T> =>\n Object.fromEntries(\n Object.entries(x).map(([key, value]) => {\n if (typeof value === \"function\" && key.startsWith(\"get\")) {\n try {\n return [uncapitalize(key.replace(/^get/, \"\")), value()]\n } catch {\n return [key, value]\n }\n }\n\n return [key, value]\n }),\n ) as RunGetters<T>\n"],"mappings":";AAAA,MAAa,gBAAgB,QAC3B,IAAI,MAAM,GAAG,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;;;ACE7C,MAAa,cAAgC,MAC3C,OAAO,YACL,OAAO,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,WAAW;CACtC,IAAI,OAAO,UAAU,cAAc,IAAI,WAAW,KAAK,GACrD,IAAI;EACF,OAAO,CAAC,aAAa,IAAI,QAAQ,QAAQ,EAAE,CAAC,GAAG,MAAM,CAAC;CACxD,QAAQ;EACN,OAAO,CAAC,KAAK,KAAK;CACpB;CAGF,OAAO,CAAC,KAAK,KAAK;AACpB,CAAC,CACH"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/lib/uncapitalize.ts
|
|
2
|
-
const uncapitalize = (str) => str.slice(0, 1).toLowerCase() + str.slice(1);
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/lib/runGetters.ts
|
|
5
|
-
const runGetters = (x) => Object.fromEntries(Object.entries(x).map(([key, value]) => {
|
|
6
|
-
if (typeof value === "function" && key.startsWith("get")) try {
|
|
7
|
-
return [uncapitalize(key.replace(/^get/, "")), value()];
|
|
8
|
-
} catch {
|
|
9
|
-
return [key, value];
|
|
10
|
-
}
|
|
11
|
-
return [key, value];
|
|
12
|
-
}));
|
|
13
|
-
//#endregion
|
|
14
|
-
Object.defineProperty(exports, "runGetters", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function() {
|
|
17
|
-
return runGetters;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { t as isShallowEqual } from "./isShallowEqual-Kynsoe7a.js";
|
|
2
|
-
import { n as tableRegistry, t as invariant } from "./invariant-BgWq7zZS.js";
|
|
3
|
-
import { createTable } from "@tanstack/table-core";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { useCallback, useState } from "react";
|
|
6
|
-
//#region src/lib/useShallowMemo.ts
|
|
7
|
-
const useShallowMemo = (next) => {
|
|
8
|
-
const [current, setCurrent] = useState(next);
|
|
9
|
-
if (!isShallowEqual(current, next)) setCurrent(next);
|
|
10
|
-
return current;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/lib/useLayoutEffect.ts
|
|
14
|
-
const useLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : () => {};
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/hooks/useReactTable.ts
|
|
17
|
-
const useReactTable = ({ state, ...options }) => {
|
|
18
|
-
const memoOptions = useShallowMemo(options);
|
|
19
|
-
const memoState = useShallowMemo(state);
|
|
20
|
-
const [internalState, setInternalState] = useState(null);
|
|
21
|
-
const onStateChange = useCallback((updater) => {
|
|
22
|
-
setInternalState(updater);
|
|
23
|
-
memoOptions.onStateChange?.call(void 0, updater);
|
|
24
|
-
}, [memoOptions.onStateChange]);
|
|
25
|
-
const [table] = useState(() => {
|
|
26
|
-
const table = createTable({
|
|
27
|
-
state: {},
|
|
28
|
-
onStateChange: () => {},
|
|
29
|
-
renderFallbackValue: null,
|
|
30
|
-
...memoOptions
|
|
31
|
-
});
|
|
32
|
-
table.setOptions((prev) => ({
|
|
33
|
-
...prev,
|
|
34
|
-
...memoOptions,
|
|
35
|
-
state: {
|
|
36
|
-
...table.initialState,
|
|
37
|
-
...memoState
|
|
38
|
-
},
|
|
39
|
-
onStateChange
|
|
40
|
-
}));
|
|
41
|
-
tableRegistry.set(table, { listeners: /* @__PURE__ */ new Set() });
|
|
42
|
-
return table;
|
|
43
|
-
});
|
|
44
|
-
if (!internalState) setInternalState(table.initialState);
|
|
45
|
-
useLayoutEffect(() => {
|
|
46
|
-
table.setOptions((prev) => ({
|
|
47
|
-
...prev,
|
|
48
|
-
...memoOptions,
|
|
49
|
-
state: {
|
|
50
|
-
...internalState,
|
|
51
|
-
...memoState
|
|
52
|
-
},
|
|
53
|
-
onStateChange
|
|
54
|
-
}));
|
|
55
|
-
const { listeners } = tableRegistry.get(table) ?? {};
|
|
56
|
-
invariant(listeners);
|
|
57
|
-
for (const listener of listeners) listener();
|
|
58
|
-
}, [
|
|
59
|
-
memoOptions,
|
|
60
|
-
memoState,
|
|
61
|
-
onStateChange,
|
|
62
|
-
table,
|
|
63
|
-
internalState
|
|
64
|
-
]);
|
|
65
|
-
return table;
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
export { useReactTable as t };
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=useReactTable-Y2z5JrT_.js.map
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
const require_isShallowEqual = require("./isShallowEqual-D6PQ041u.cjs");
|
|
24
|
-
const require_invariant = require("./invariant-D8b385d_.cjs");
|
|
25
|
-
let _tanstack_table_core = require("@tanstack/table-core");
|
|
26
|
-
let react = require("react");
|
|
27
|
-
react = __toESM(react, 1);
|
|
28
|
-
//#region src/lib/useShallowMemo.ts
|
|
29
|
-
const useShallowMemo = (next) => {
|
|
30
|
-
const [current, setCurrent] = (0, react.useState)(next);
|
|
31
|
-
if (!require_isShallowEqual.isShallowEqual(current, next)) setCurrent(next);
|
|
32
|
-
return current;
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/lib/useLayoutEffect.ts
|
|
36
|
-
const useLayoutEffect = typeof document !== "undefined" ? react.useLayoutEffect : () => {};
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/hooks/useReactTable.ts
|
|
39
|
-
const useReactTable = ({ state, ...options }) => {
|
|
40
|
-
const memoOptions = useShallowMemo(options);
|
|
41
|
-
const memoState = useShallowMemo(state);
|
|
42
|
-
const [internalState, setInternalState] = (0, react.useState)(null);
|
|
43
|
-
const onStateChange = (0, react.useCallback)((updater) => {
|
|
44
|
-
setInternalState(updater);
|
|
45
|
-
memoOptions.onStateChange?.call(void 0, updater);
|
|
46
|
-
}, [memoOptions.onStateChange]);
|
|
47
|
-
const [table] = (0, react.useState)(() => {
|
|
48
|
-
const table = (0, _tanstack_table_core.createTable)({
|
|
49
|
-
state: {},
|
|
50
|
-
onStateChange: () => {},
|
|
51
|
-
renderFallbackValue: null,
|
|
52
|
-
...memoOptions
|
|
53
|
-
});
|
|
54
|
-
table.setOptions((prev) => ({
|
|
55
|
-
...prev,
|
|
56
|
-
...memoOptions,
|
|
57
|
-
state: {
|
|
58
|
-
...table.initialState,
|
|
59
|
-
...memoState
|
|
60
|
-
},
|
|
61
|
-
onStateChange
|
|
62
|
-
}));
|
|
63
|
-
require_invariant.tableRegistry.set(table, { listeners: /* @__PURE__ */ new Set() });
|
|
64
|
-
return table;
|
|
65
|
-
});
|
|
66
|
-
if (!internalState) setInternalState(table.initialState);
|
|
67
|
-
useLayoutEffect(() => {
|
|
68
|
-
table.setOptions((prev) => ({
|
|
69
|
-
...prev,
|
|
70
|
-
...memoOptions,
|
|
71
|
-
state: {
|
|
72
|
-
...internalState,
|
|
73
|
-
...memoState
|
|
74
|
-
},
|
|
75
|
-
onStateChange
|
|
76
|
-
}));
|
|
77
|
-
const { listeners } = require_invariant.tableRegistry.get(table) ?? {};
|
|
78
|
-
require_invariant.invariant(listeners);
|
|
79
|
-
for (const listener of listeners) listener();
|
|
80
|
-
}, [
|
|
81
|
-
memoOptions,
|
|
82
|
-
memoState,
|
|
83
|
-
onStateChange,
|
|
84
|
-
table,
|
|
85
|
-
internalState
|
|
86
|
-
]);
|
|
87
|
-
return table;
|
|
88
|
-
};
|
|
89
|
-
//#endregion
|
|
90
|
-
Object.defineProperty(exports, "useReactTable", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function() {
|
|
93
|
-
return useReactTable;
|
|
94
|
-
}
|
|
95
|
-
});
|