react-hook-tanstack-table 0.0.2 → 0.0.4
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 +4 -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 +14 -13
- package/src/index.ts +0 -1
- package/src/{hooks/useTableWithSelector.ts → lib/useTableBase.ts} +5 -5
- 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/useTable.ts
CHANGED
|
@@ -14,15 +14,15 @@ import { hasTableArg } from "../lib/hasTableArg"
|
|
|
14
14
|
|
|
15
15
|
import type { IsEqual, RunGetters } from "../types"
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { useTableBase } from "../lib/useTableBase"
|
|
18
18
|
|
|
19
|
-
export interface
|
|
19
|
+
export interface TableSnapshot<TData extends RowData> extends RunGetters<
|
|
20
20
|
Table<TData>
|
|
21
21
|
> {}
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const tableSnapshotCache = new WeakMap<
|
|
24
24
|
RequiredKeys<TableOptionsResolved<any>, "state">,
|
|
25
|
-
|
|
25
|
+
TableSnapshot<any>
|
|
26
26
|
>()
|
|
27
27
|
|
|
28
28
|
const tableHandlersCache = new WeakMap<
|
|
@@ -43,10 +43,10 @@ const tableHandlersCache = new WeakMap<
|
|
|
43
43
|
}
|
|
44
44
|
>()
|
|
45
45
|
|
|
46
|
-
const
|
|
46
|
+
const getTableSnapshot = <TData extends RowData>(
|
|
47
47
|
table: Table<TData>,
|
|
48
|
-
):
|
|
49
|
-
let cached =
|
|
48
|
+
): TableSnapshot<TData> => {
|
|
49
|
+
let cached = tableSnapshotCache.get(table.options)
|
|
50
50
|
if (!cached) {
|
|
51
51
|
let cachedHandlers = tableHandlersCache.get(table)
|
|
52
52
|
if (!cachedHandlers) {
|
|
@@ -79,16 +79,17 @@ const getTableValues = <TData extends RowData>(
|
|
|
79
79
|
toggleAllRowsExpandedHandler,
|
|
80
80
|
toggleAllRowsSelectedHandler,
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
tableSnapshotCache.set(table.options, cached)
|
|
83
83
|
}
|
|
84
84
|
return cached
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
type Selector<TData extends RowData, Selection> = (
|
|
88
|
-
|
|
88
|
+
tableSnapshot: TableSnapshot<TData>,
|
|
89
|
+
table: Table<TData>
|
|
89
90
|
) => Selection
|
|
90
91
|
|
|
91
|
-
export const useTable = <TData extends RowData, Selection =
|
|
92
|
+
export const useTable = <TData extends RowData, Selection = TableSnapshot<TData>>(
|
|
92
93
|
...args:
|
|
93
94
|
| [
|
|
94
95
|
table: Table<TData> | undefined,
|
|
@@ -107,18 +108,18 @@ export const useTable = <TData extends RowData, Selection = TableValues<TData>>(
|
|
|
107
108
|
] = hasTableArg(args) ? args : [undefined, ...args]
|
|
108
109
|
|
|
109
110
|
const getSelection = useCallback(
|
|
110
|
-
(table: Table<TData>) => selector(
|
|
111
|
+
(table: Table<TData>) => selector(getTableSnapshot(table), table),
|
|
111
112
|
[selector],
|
|
112
113
|
)
|
|
113
114
|
|
|
114
|
-
return
|
|
115
|
+
return useTableBase(table, getSelection, isEqual)
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
const tableHook = useTable
|
|
118
119
|
|
|
119
120
|
const tableHookʹ =
|
|
120
121
|
<TData extends RowData>(table?: Table<TData> | undefined) =>
|
|
121
|
-
<Selection =
|
|
122
|
+
<Selection = TableSnapshot<TData>>(
|
|
122
123
|
selector?: Selector<TData, Selection> | undefined,
|
|
123
124
|
isEqual?: IsEqual<NoInfer<Selection>> | undefined
|
|
124
125
|
): Selection =>
|
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"
|
|
@@ -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(
|
|
@@ -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
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const require_TableContext = require("./TableContext.cjs");
|
|
2
|
-
const require_invariant = require("./invariant-D8b385d_.cjs");
|
|
3
|
-
let react = require("react");
|
|
4
|
-
//#region src/lib/identity.ts
|
|
5
|
-
const identity = (x, ..._) => x;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/hooks/useTableWithSelector.ts
|
|
8
|
-
const useTableWithSelector = (table, selector = identity, isEqual) => {
|
|
9
|
-
"use no memo";
|
|
10
|
-
const resolvedTable = table ?? (0, react.use)(require_TableContext.TableContext);
|
|
11
|
-
require_invariant.invariant(resolvedTable, "`useTableWithSelector` must be used as a descendent of `TableContext` or provided with a `Table` as an argument!");
|
|
12
|
-
const listeners = (0, react.useMemo)(() => (require_invariant.tableRegistry.get(resolvedTable) ?? {}).listeners, [resolvedTable]);
|
|
13
|
-
require_invariant.invariant(listeners, "The provided/found `Table` instance cannot be subscribed to. Was it created by the correct `useReactTable` hook?");
|
|
14
|
-
const subscribe = (0, react.useCallback)((onTableChange) => {
|
|
15
|
-
listeners.add(onTableChange);
|
|
16
|
-
return () => {
|
|
17
|
-
listeners.delete(onTableChange);
|
|
18
|
-
};
|
|
19
|
-
}, [listeners]);
|
|
20
|
-
const instRef = (0, react.useRef)({
|
|
21
|
-
hasValue: false,
|
|
22
|
-
value: null
|
|
23
|
-
});
|
|
24
|
-
const value = (0, react.useSyncExternalStore)(subscribe, (0, react.useMemo)(() => {
|
|
25
|
-
let hasMemo = false, memoizedTableOptions, memoizedSelection;
|
|
26
|
-
return () => {
|
|
27
|
-
const nextTableOptions = resolvedTable.options;
|
|
28
|
-
if (!hasMemo) {
|
|
29
|
-
hasMemo = true;
|
|
30
|
-
memoizedTableOptions = nextTableOptions;
|
|
31
|
-
const nextSelection = selector(resolvedTable);
|
|
32
|
-
if (isEqual !== void 0) {
|
|
33
|
-
if (instRef.current.hasValue) {
|
|
34
|
-
const currentSelection = instRef.current.value;
|
|
35
|
-
if (isEqual(currentSelection, nextSelection)) {
|
|
36
|
-
memoizedSelection = currentSelection;
|
|
37
|
-
return currentSelection;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
memoizedSelection = nextSelection;
|
|
42
|
-
return nextSelection;
|
|
43
|
-
}
|
|
44
|
-
const prevTableOptions = memoizedTableOptions;
|
|
45
|
-
const prevSelection = memoizedSelection;
|
|
46
|
-
if (Object.is(prevTableOptions, nextTableOptions)) return prevSelection;
|
|
47
|
-
const nextSelection = selector(resolvedTable);
|
|
48
|
-
if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
|
|
49
|
-
memoizedTableOptions = nextTableOptions;
|
|
50
|
-
return prevSelection;
|
|
51
|
-
}
|
|
52
|
-
memoizedTableOptions = nextTableOptions;
|
|
53
|
-
memoizedSelection = nextSelection;
|
|
54
|
-
return nextSelection;
|
|
55
|
-
};
|
|
56
|
-
}, [
|
|
57
|
-
selector,
|
|
58
|
-
resolvedTable,
|
|
59
|
-
isEqual
|
|
60
|
-
]));
|
|
61
|
-
(0, react.useInsertionEffect)(() => {
|
|
62
|
-
instRef.current.hasValue = true;
|
|
63
|
-
instRef.current.value = value;
|
|
64
|
-
}, [value]);
|
|
65
|
-
return value;
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
Object.defineProperty(exports, "identity", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function() {
|
|
71
|
-
return identity;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(exports, "useTableWithSelector", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
get: function() {
|
|
77
|
-
return useTableWithSelector;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { TableContext } from "./TableContext.js";
|
|
2
|
-
import { n as tableRegistry, t as invariant } from "./invariant-BgWq7zZS.js";
|
|
3
|
-
import { use, useCallback, useInsertionEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
4
|
-
//#region src/lib/identity.ts
|
|
5
|
-
const identity = (x, ..._) => x;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/hooks/useTableWithSelector.ts
|
|
8
|
-
const useTableWithSelector = (table, selector = identity, isEqual) => {
|
|
9
|
-
"use no memo";
|
|
10
|
-
const resolvedTable = table ?? use(TableContext);
|
|
11
|
-
invariant(resolvedTable, "`useTableWithSelector` must be used as a descendent of `TableContext` or provided with a `Table` as an argument!");
|
|
12
|
-
const listeners = useMemo(() => (tableRegistry.get(resolvedTable) ?? {}).listeners, [resolvedTable]);
|
|
13
|
-
invariant(listeners, "The provided/found `Table` instance cannot be subscribed to. Was it created by the correct `useReactTable` hook?");
|
|
14
|
-
const subscribe = useCallback((onTableChange) => {
|
|
15
|
-
listeners.add(onTableChange);
|
|
16
|
-
return () => {
|
|
17
|
-
listeners.delete(onTableChange);
|
|
18
|
-
};
|
|
19
|
-
}, [listeners]);
|
|
20
|
-
const instRef = useRef({
|
|
21
|
-
hasValue: false,
|
|
22
|
-
value: null
|
|
23
|
-
});
|
|
24
|
-
const value = useSyncExternalStore(subscribe, useMemo(() => {
|
|
25
|
-
let hasMemo = false, memoizedTableOptions, memoizedSelection;
|
|
26
|
-
return () => {
|
|
27
|
-
const nextTableOptions = resolvedTable.options;
|
|
28
|
-
if (!hasMemo) {
|
|
29
|
-
hasMemo = true;
|
|
30
|
-
memoizedTableOptions = nextTableOptions;
|
|
31
|
-
const nextSelection = selector(resolvedTable);
|
|
32
|
-
if (isEqual !== void 0) {
|
|
33
|
-
if (instRef.current.hasValue) {
|
|
34
|
-
const currentSelection = instRef.current.value;
|
|
35
|
-
if (isEqual(currentSelection, nextSelection)) {
|
|
36
|
-
memoizedSelection = currentSelection;
|
|
37
|
-
return currentSelection;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
memoizedSelection = nextSelection;
|
|
42
|
-
return nextSelection;
|
|
43
|
-
}
|
|
44
|
-
const prevTableOptions = memoizedTableOptions;
|
|
45
|
-
const prevSelection = memoizedSelection;
|
|
46
|
-
if (Object.is(prevTableOptions, nextTableOptions)) return prevSelection;
|
|
47
|
-
const nextSelection = selector(resolvedTable);
|
|
48
|
-
if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
|
|
49
|
-
memoizedTableOptions = nextTableOptions;
|
|
50
|
-
return prevSelection;
|
|
51
|
-
}
|
|
52
|
-
memoizedTableOptions = nextTableOptions;
|
|
53
|
-
memoizedSelection = nextSelection;
|
|
54
|
-
return nextSelection;
|
|
55
|
-
};
|
|
56
|
-
}, [
|
|
57
|
-
selector,
|
|
58
|
-
resolvedTable,
|
|
59
|
-
isEqual
|
|
60
|
-
]));
|
|
61
|
-
useInsertionEffect(() => {
|
|
62
|
-
instRef.current.hasValue = true;
|
|
63
|
-
instRef.current.value = value;
|
|
64
|
-
}, [value]);
|
|
65
|
-
return value;
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
export { identity as n, useTableWithSelector as t };
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=useTableWithSelector-D3f689pF.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTableWithSelector-D3f689pF.js","names":[],"sources":["../src/lib/identity.ts","../src/hooks/useTableWithSelector.ts"],"sourcesContent":["export const identity = <T>(x: T, ..._: any[]): T => x\n","import {\n use,\n useCallback,\n useInsertionEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\"\n\nimport type {\n RequiredKeys,\n RowData,\n Table,\n TableOptionsResolved,\n} from \"@tanstack/table-core\"\n\nimport { TableContext } from \"../contexts/TableContext\"\n\nimport { identity } from \"../lib/identity\"\nimport { tableRegistry } from \"../lib/tableRegistry\"\nimport { invariant } from \"../lib/invariant\"\n\nimport type { IsEqual } from \"../types\"\n\nexport const useTableWithSelector = <\n TData extends RowData,\n Selection = Table<TData>,\n>(\n table?: Table<TData> | undefined,\n selector: (table: Table<TData>) => Selection = identity as never,\n isEqual?: IsEqual<NoInfer<Selection>> | undefined,\n): Selection => {\n \"use no memo\"\n\n const resolvedTable = table ?? use<Table<TData> | null>(TableContext)\n\n invariant(\n resolvedTable,\n \"`useTableWithSelector` must be used as a descendent of `TableContext` or provided with a `Table` as an argument!\",\n )\n\n const listeners = useMemo(\n () => (tableRegistry.get(resolvedTable) ?? {}).listeners,\n [resolvedTable],\n )\n\n invariant(\n listeners,\n \"The provided/found `Table` instance cannot be subscribed to. Was it created by the correct `useReactTable` hook?\",\n )\n\n const subscribe = useCallback(\n (onTableChange: () => void) => {\n listeners.add(onTableChange)\n return () => {\n listeners.delete(onTableChange)\n }\n },\n [listeners],\n )\n\n // Use this to track the rendered snapshot.\n const instRef = useRef<\n | {\n hasValue: false\n value: null\n }\n | { hasValue: true; value: Selection }\n >({\n hasValue: false,\n value: null,\n })\n\n // eslint-disable-next-line react-hooks/immutability\n const getSnapshot = useMemo(() => {\n let hasMemo = false,\n memoizedTableOptions: RequiredKeys<TableOptionsResolved<TData>, \"state\">,\n memoizedSelection: Selection\n\n return () => {\n const nextTableOptions = resolvedTable.options\n if (!hasMemo) {\n // The first time the hook is called, there is no memoized result.\n // eslint-disable-next-line react-hooks/immutability -- should be fine 😅 this is how it is in the upstream, too\n hasMemo = true\n memoizedTableOptions = nextTableOptions\n const nextSelection = selector(resolvedTable)\n\n if (isEqual !== undefined) {\n // Even if the selector has changed, the currently rendered selection\n // may be equal to the new selection. We should attempt to reuse the\n // current value if possible, to preserve downstream memoizations.\n if (instRef.current.hasValue) {\n const currentSelection = instRef.current.value\n if (isEqual(currentSelection, nextSelection)) {\n memoizedSelection = currentSelection\n return currentSelection\n }\n }\n }\n\n memoizedSelection = nextSelection\n return nextSelection\n }\n\n const prevTableOptions = memoizedTableOptions\n // eslint-disable-next-line react-hooks/memo-dependencies\n const prevSelection = memoizedSelection\n\n if (Object.is(prevTableOptions, nextTableOptions)) {\n // The snapshot is the same as last time. Reuse the previous selection.\n return prevSelection\n }\n\n // The snapshot has changed, so we need to compute a new selection.\n const nextSelection = selector(resolvedTable)\n\n // If a custom isEqual function is provided, use that to check if the data\n // has changed. If it hasn't, return the previous selection. That signals\n // to React that the selections are conceptually equal, and we can bail\n // out of rendering.\n if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {\n // The snapshot still has changed, so make sure to update to not keep\n // old references alive\n memoizedTableOptions = nextTableOptions\n return prevSelection\n }\n\n memoizedTableOptions = nextTableOptions\n memoizedSelection = nextSelection\n return nextSelection\n }\n }, [selector, resolvedTable, isEqual])\n\n const value = useSyncExternalStore(subscribe, getSnapshot)\n\n useInsertionEffect(() => {\n instRef.current.hasValue = true\n instRef.current.value = value\n }, [value])\n\n return value\n}\n"],"mappings":";;;;AAAA,MAAa,YAAe,GAAM,GAAG,MAAgB;;;ACwBrD,MAAa,wBAIX,OACA,WAA+C,UAC/C,YACc;CACd;CAEA,MAAM,gBAAgB,SAAS,IAAyB,YAAY;CAEpE,UACE,eACA,kHACF;CAEA,MAAM,YAAY,eACT,cAAc,IAAI,aAAa,KAAK,CAAC,GAAG,WAC/C,CAAC,aAAa,CAChB;CAEA,UACE,WACA,kHACF;CAEA,MAAM,YAAY,aACf,kBAA8B;EAC7B,UAAU,IAAI,aAAa;EAC3B,aAAa;GACX,UAAU,OAAO,aAAa;EAChC;CACF,GACA,CAAC,SAAS,CACZ;CAGA,MAAM,UAAU,OAMd;EACA,UAAU;EACV,OAAO;CACT,CAAC;CA+DD,MAAM,QAAQ,qBAAqB,WA5Df,cAAc;EAChC,IAAI,UAAU,OACZ,sBACA;EAEF,aAAa;GACX,MAAM,mBAAmB,cAAc;GACvC,IAAI,CAAC,SAAS;IAGZ,UAAU;IACV,uBAAuB;IACvB,MAAM,gBAAgB,SAAS,aAAa;IAE5C,IAAI,YAAY,KAAA;SAIV,QAAQ,QAAQ,UAAU;MAC5B,MAAM,mBAAmB,QAAQ,QAAQ;MACzC,IAAI,QAAQ,kBAAkB,aAAa,GAAG;OAC5C,oBAAoB;OACpB,OAAO;MACT;KACF;;IAGF,oBAAoB;IACpB,OAAO;GACT;GAEA,MAAM,mBAAmB;GAEzB,MAAM,gBAAgB;GAEtB,IAAI,OAAO,GAAG,kBAAkB,gBAAgB,GAE9C,OAAO;GAIT,MAAM,gBAAgB,SAAS,aAAa;GAM5C,IAAI,YAAY,KAAA,KAAa,QAAQ,eAAe,aAAa,GAAG;IAGlE,uBAAuB;IACvB,OAAO;GACT;GAEA,uBAAuB;GACvB,oBAAoB;GACpB,OAAO;EACT;CACF,GAAG;EAAC;EAAU;EAAe;CAAO,CAEoB,CAAC;CAEzD,yBAAyB;EACvB,QAAQ,QAAQ,WAAW;EAC3B,QAAQ,QAAQ,QAAQ;CAC1B,GAAG,CAAC,KAAK,CAAC;CAEV,OAAO;AACT"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as IsEqual } from "./types-DIWB6wdO.cjs";
|
|
2
|
-
import { RowData, Table } from "@tanstack/table-core";
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/useTableWithSelector.d.ts
|
|
5
|
-
declare const useTableWithSelector: <TData extends RowData, Selection = Table<TData>>(table?: Table<TData> | undefined, selector?: (table: Table<TData>) => Selection, isEqual?: IsEqual<NoInfer<Selection>> | undefined) => Selection;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { useTableWithSelector };
|
|
8
|
-
//# sourceMappingURL=useTableWithSelector.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTableWithSelector.d.cts","names":[],"sources":["../src/hooks/useTableWithSelector.ts"],"mappings":";;;;cAwBa,oBAAA,iBACG,OAAA,cACF,KAAA,CAAM,KAAA,GAElB,KAAA,GAAQ,KAAA,CAAM,KAAA,eACd,QAAA,IAAW,KAAA,EAAO,KAAA,CAAM,KAAA,MAAW,SAAA,EACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,mBACzB,SAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as IsEqual } from "./types-DIWB6wdO.js";
|
|
2
|
-
import { RowData, Table } from "@tanstack/table-core";
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/useTableWithSelector.d.ts
|
|
5
|
-
declare const useTableWithSelector: <TData extends RowData, Selection = Table<TData>>(table?: Table<TData> | undefined, selector?: (table: Table<TData>) => Selection, isEqual?: IsEqual<NoInfer<Selection>> | undefined) => Selection;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { useTableWithSelector };
|
|
8
|
-
//# sourceMappingURL=useTableWithSelector.d.ts.map
|