react-hook-tanstack-table 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.org +29 -0
  3. package/dist/TableContext.cjs +6 -0
  4. package/dist/TableContext.d.cts +7 -0
  5. package/dist/TableContext.d.cts.map +1 -0
  6. package/dist/TableContext.d.ts +7 -0
  7. package/dist/TableContext.d.ts.map +1 -0
  8. package/dist/TableContext.js +8 -0
  9. package/dist/TableContext.js.map +1 -0
  10. package/dist/hasTableArg-Bu3FbcSo.js +8 -0
  11. package/dist/hasTableArg-Bu3FbcSo.js.map +1 -0
  12. package/dist/hasTableArg-dMtayKWH.cjs +11 -0
  13. package/dist/index.cjs +40 -0
  14. package/dist/index.d.cts +11 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.js +11 -0
  17. package/dist/invariant-BgWq7zZS.js +12 -0
  18. package/dist/invariant-BgWq7zZS.js.map +1 -0
  19. package/dist/invariant-D8b385d_.cjs +21 -0
  20. package/dist/isShallowEqual-D6PQ041u.cjs +36 -0
  21. package/dist/isShallowEqual-Kynsoe7a.js +33 -0
  22. package/dist/isShallowEqual-Kynsoe7a.js.map +1 -0
  23. package/dist/runGetters-BfRTE7LZ.js +16 -0
  24. package/dist/runGetters-BfRTE7LZ.js.map +1 -0
  25. package/dist/runGetters-Q-UsPG2j.cjs +19 -0
  26. package/dist/types-DIWB6wdO.d.cts +11 -0
  27. package/dist/types-DIWB6wdO.d.cts.map +1 -0
  28. package/dist/types-DIWB6wdO.d.ts +11 -0
  29. package/dist/types-DIWB6wdO.d.ts.map +1 -0
  30. package/dist/useCell.cjs +53 -0
  31. package/dist/useCell.d.cts +17 -0
  32. package/dist/useCell.d.cts.map +1 -0
  33. package/dist/useCell.d.ts +17 -0
  34. package/dist/useCell.d.ts.map +1 -0
  35. package/dist/useCell.js +53 -0
  36. package/dist/useCell.js.map +1 -0
  37. package/dist/useColumn.cjs +54 -0
  38. package/dist/useColumn.d.cts +19 -0
  39. package/dist/useColumn.d.cts.map +1 -0
  40. package/dist/useColumn.d.ts +19 -0
  41. package/dist/useColumn.d.ts.map +1 -0
  42. package/dist/useColumn.js +54 -0
  43. package/dist/useColumn.js.map +1 -0
  44. package/dist/useHeader.cjs +48 -0
  45. package/dist/useHeader.d.cts +19 -0
  46. package/dist/useHeader.d.cts.map +1 -0
  47. package/dist/useHeader.d.ts +19 -0
  48. package/dist/useHeader.d.ts.map +1 -0
  49. package/dist/useHeader.js +48 -0
  50. package/dist/useHeader.js.map +1 -0
  51. package/dist/useReactTable-Y2z5JrT_.js +70 -0
  52. package/dist/useReactTable-Y2z5JrT_.js.map +1 -0
  53. package/dist/useReactTable-nxQRPiMU.cjs +95 -0
  54. package/dist/useReactTable.cjs +3 -0
  55. package/dist/useReactTable.d.cts +10 -0
  56. package/dist/useReactTable.d.cts.map +1 -0
  57. package/dist/useReactTable.d.ts +10 -0
  58. package/dist/useReactTable.d.ts.map +1 -0
  59. package/dist/useReactTable.js +2 -0
  60. package/dist/useRow.cjs +54 -0
  61. package/dist/useRow.d.cts +19 -0
  62. package/dist/useRow.d.cts.map +1 -0
  63. package/dist/useRow.d.ts +19 -0
  64. package/dist/useRow.d.ts.map +1 -0
  65. package/dist/useRow.js +54 -0
  66. package/dist/useRow.js.map +1 -0
  67. package/dist/useTable.cjs +44 -0
  68. package/dist/useTable.d.cts +11 -0
  69. package/dist/useTable.d.cts.map +1 -0
  70. package/dist/useTable.d.ts +11 -0
  71. package/dist/useTable.d.ts.map +1 -0
  72. package/dist/useTable.js +44 -0
  73. package/dist/useTable.js.map +1 -0
  74. package/dist/useTableWithSelector-Bdsf6Zxk.cjs +79 -0
  75. package/dist/useTableWithSelector-D3f689pF.js +70 -0
  76. package/dist/useTableWithSelector-D3f689pF.js.map +1 -0
  77. package/dist/useTableWithSelector.cjs +3 -0
  78. package/dist/useTableWithSelector.d.cts +8 -0
  79. package/dist/useTableWithSelector.d.cts.map +1 -0
  80. package/dist/useTableWithSelector.d.ts +8 -0
  81. package/dist/useTableWithSelector.d.ts.map +1 -0
  82. package/dist/useTableWithSelector.js +2 -0
  83. package/package.json +99 -0
  84. package/src/contexts/TableContext.ts +7 -0
  85. package/src/hooks/useCell.ts +156 -0
  86. package/src/hooks/useColumn.ts +168 -0
  87. package/src/hooks/useHeader.ts +151 -0
  88. package/src/hooks/useReactTable.ts +88 -0
  89. package/src/hooks/useRow.ts +132 -0
  90. package/src/hooks/useTable.ts +113 -0
  91. package/src/hooks/useTableWithSelector.ts +143 -0
  92. package/src/index.ts +13 -0
  93. package/src/lib/hasTableArg.ts +19 -0
  94. package/src/lib/identity.ts +1 -0
  95. package/src/lib/invariant.ts +12 -0
  96. package/src/lib/isShallowEqual.ts +77 -0
  97. package/src/lib/runGetters.ts +17 -0
  98. package/src/lib/tableRegistry.ts +3 -0
  99. package/src/lib/uncapitalize.ts +2 -0
  100. package/src/lib/useLayoutEffect.ts +3 -0
  101. package/src/lib/useShallowMemo.ts +12 -0
  102. package/src/types.ts +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xandor Schiefer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.org ADDED
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/contexts/TableContext.ts
3
+ const TableContext = (0, require("react").createContext)(null);
4
+ TableContext.displayName = "TableContext";
5
+ //#endregion
6
+ exports.TableContext = TableContext;
@@ -0,0 +1,7 @@
1
+ import { Table } from "@tanstack/table-core";
2
+
3
+ //#region src/contexts/TableContext.d.ts
4
+ declare const TableContext: React.Context<Table<any> | null>;
5
+ //#endregion
6
+ export { TableContext };
7
+ //# sourceMappingURL=TableContext.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableContext.d.cts","names":[],"sources":["../src/contexts/TableContext.ts"],"mappings":";;;cAIa,YAAA,EAAc,KAAA,CAAM,OAAA,CAAQ,KAAA"}
@@ -0,0 +1,7 @@
1
+ import { Table } from "@tanstack/table-core";
2
+
3
+ //#region src/contexts/TableContext.d.ts
4
+ declare const TableContext: React.Context<Table<any> | null>;
5
+ //#endregion
6
+ export { TableContext };
7
+ //# sourceMappingURL=TableContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableContext.d.ts","names":[],"sources":["../src/contexts/TableContext.ts"],"mappings":";;;cAIa,YAAA,EAAc,KAAA,CAAM,OAAA,CAAQ,KAAA"}
@@ -0,0 +1,8 @@
1
+ import { createContext } from "react";
2
+ //#region src/contexts/TableContext.ts
3
+ const TableContext = createContext(null);
4
+ TableContext.displayName = "TableContext";
5
+ //#endregion
6
+ export { TableContext };
7
+
8
+ //# sourceMappingURL=TableContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableContext.js","names":[],"sources":["../src/contexts/TableContext.ts"],"sourcesContent":["import { createContext } from \"react\"\n\nimport type { Table } from \"@tanstack/table-core\"\n\nexport const TableContext: React.Context<Table<any> | null> = createContext<Table<any> | null>(null)\n\nTableContext.displayName = \"TableContext\"\n"],"mappings":";;AAIA,MAAa,eAAiD,cAAiC,IAAI;AAEnG,aAAa,cAAc"}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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
+ });
package/dist/index.cjs ADDED
@@ -0,0 +1,40 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_useReactTable = require("./useReactTable-nxQRPiMU.cjs");
3
+ const require_TableContext = require("./TableContext.cjs");
4
+ const require_useTableWithSelector = require("./useTableWithSelector-Bdsf6Zxk.cjs");
5
+ const require_useTable = require("./useTable.cjs");
6
+ const require_useHeader = require("./useHeader.cjs");
7
+ const require_useColumn = require("./useColumn.cjs");
8
+ const require_useRow = require("./useRow.cjs");
9
+ const require_useCell = require("./useCell.cjs");
10
+ exports.TableContext = require_TableContext.TableContext;
11
+ exports.useCell = require_useCell.useCell;
12
+ exports.useCellʹ = require_useCell.useCellʹ;
13
+ exports.useColumn = require_useColumn.useColumn;
14
+ exports.useColumnʹ = require_useColumn.useColumnʹ;
15
+ exports.useHeader = require_useHeader.useHeader;
16
+ exports.useHeaderʹ = require_useHeader.useHeaderʹ;
17
+ exports.useReactTable = require_useReactTable.useReactTable;
18
+ exports.useRow = require_useRow.useRow;
19
+ exports.useRowʹ = require_useRow.useRowʹ;
20
+ exports.useTable = require_useTable.useTable;
21
+ exports.useTableWithSelector = require_useTableWithSelector.useTableWithSelector;
22
+ exports.useTableʹ = require_useTable.useTableʹ;
23
+ var _tanstack_table_core = require("@tanstack/table-core");
24
+ Object.keys(_tanstack_table_core).forEach(function(k) {
25
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
26
+ enumerable: true,
27
+ get: function() {
28
+ return _tanstack_table_core[k];
29
+ }
30
+ });
31
+ });
32
+ var _tanstack_react_table = require("@tanstack/react-table");
33
+ Object.keys(_tanstack_react_table).forEach(function(k) {
34
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
35
+ enumerable: true,
36
+ get: function() {
37
+ return _tanstack_react_table[k];
38
+ }
39
+ });
40
+ });
@@ -0,0 +1,11 @@
1
+ import { TableContext } from "./TableContext.cjs";
2
+ import { useColumn, useColumnʹ as columnHookʹ } from "./useColumn.cjs";
3
+ import { useRow, useRowʹ as rowHookʹ } from "./useRow.cjs";
4
+ import { useCell, useCellʹ as cellHookʹ } from "./useCell.cjs";
5
+ import { useHeader, useHeaderʹ as headerHookʹ } from "./useHeader.cjs";
6
+ import { useReactTable } from "./useReactTable.cjs";
7
+ import { useTable, useTableʹ as tableHookʹ } from "./useTable.cjs";
8
+ import { useTableWithSelector } from "./useTableWithSelector.cjs";
9
+ export * from "@tanstack/table-core";
10
+ export * from "@tanstack/react-table";
11
+ export { TableContext, useCell, cellHookʹ as useCellʹ, useColumn, columnHookʹ as useColumnʹ, useHeader, headerHookʹ as useHeaderʹ, useReactTable, useRow, rowHookʹ as useRowʹ, useTable, useTableWithSelector, tableHookʹ as useTableʹ };
@@ -0,0 +1,11 @@
1
+ import { TableContext } from "./TableContext.js";
2
+ import { useColumn, useColumnʹ as columnHookʹ } from "./useColumn.js";
3
+ import { useRow, useRowʹ as rowHookʹ } from "./useRow.js";
4
+ import { useCell, useCellʹ as cellHookʹ } from "./useCell.js";
5
+ import { useHeader, useHeaderʹ as headerHookʹ } from "./useHeader.js";
6
+ import { useReactTable } from "./useReactTable.js";
7
+ import { useTable, useTableʹ as tableHookʹ } from "./useTable.js";
8
+ import { useTableWithSelector } from "./useTableWithSelector.js";
9
+ export * from "@tanstack/table-core";
10
+ export * from "@tanstack/react-table";
11
+ export { TableContext, useCell, cellHookʹ as useCellʹ, useColumn, columnHookʹ as useColumnʹ, useHeader, headerHookʹ as useHeaderʹ, useReactTable, useRow, rowHookʹ as useRowʹ, useTable, useTableWithSelector, tableHookʹ as useTableʹ };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { TableContext } from "./TableContext.js";
2
+ import { t as useReactTable } from "./useReactTable-Y2z5JrT_.js";
3
+ import { t as useTableWithSelector } from "./useTableWithSelector-D3f689pF.js";
4
+ import { useTable, useTableʹ as tableHookʹ } from "./useTable.js";
5
+ import { useHeader, useHeaderʹ as headerHookʹ } from "./useHeader.js";
6
+ import { useColumn, useColumnʹ as columnHookʹ } from "./useColumn.js";
7
+ import { useRow, useRowʹ as rowHookʹ } from "./useRow.js";
8
+ import { useCell, useCellʹ as cellHookʹ } from "./useCell.js";
9
+ export * from "@tanstack/table-core";
10
+ export * from "@tanstack/react-table";
11
+ export { TableContext, useCell, cellHookʹ as useCellʹ, useColumn, columnHookʹ as useColumnʹ, useHeader, headerHookʹ as useHeaderʹ, useReactTable, useRow, rowHookʹ as useRowʹ, useTable, useTableWithSelector, tableHookʹ as useTableʹ };
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,21 @@
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
+ });
@@ -0,0 +1,36 @@
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
+ });
@@ -0,0 +1,33 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,19 @@
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
+ });
@@ -0,0 +1,11 @@
1
+ import { Simplify } from "type-fest";
2
+
3
+ //#region src/types.d.ts
4
+ type IsEqual<Selection> = (prev: Selection, next: Selection) => boolean;
5
+ type GetterKeys<T> = { [k in keyof T]-?: k extends `get${string}` ? T[k] extends (() => unknown) ? k : never : never }[keyof T];
6
+ type GottenKey<k extends string> = k extends `get${infer K}` ? Uncapitalize<K> : never;
7
+ type GetterReturn<T> = T extends (() => unknown) ? ReturnType<T> : never;
8
+ type RunGetters<T> = Simplify<{ [k in GetterKeys<T> as GottenKey<k>]: GetterReturn<T[k]> } & { [k in Exclude<keyof T, GetterKeys<T>>]: T[k] }>;
9
+ //#endregion
10
+ export { RunGetters as n, IsEqual as t };
11
+ //# sourceMappingURL=types-DIWB6wdO.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DIWB6wdO.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,OAAA,eAAsB,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,SAAA;AAAA,KAEpD,UAAA,oBACS,CAAA,KAAM,CAAA,0BAChB,CAAA,CAAE,CAAA,4BACA,CAAA,yBAGE,CAAA;AAAA,KAEH,SAAA,qBACH,CAAA,2BAA4B,YAAA,CAAa,CAAA;AAAA,KAEtC,YAAA,MAAkB,CAAA,2BAA0B,UAAA,CAAW,CAAA;AAAA,KAEhD,UAAA,MAAgB,QAAA,SAElB,UAAA,CAAW,CAAA,KAAM,SAAA,CAAU,CAAA,IAAK,YAAA,CAAa,CAAA,CAAE,CAAA,eAE/C,OAAA,OAAc,CAAA,EAAG,UAAA,CAAW,CAAA,KAAM,CAAA,CAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { Simplify } from "type-fest";
2
+
3
+ //#region src/types.d.ts
4
+ type IsEqual<Selection> = (prev: Selection, next: Selection) => boolean;
5
+ type GetterKeys<T> = { [k in keyof T]-?: k extends `get${string}` ? T[k] extends (() => unknown) ? k : never : never }[keyof T];
6
+ type GottenKey<k extends string> = k extends `get${infer K}` ? Uncapitalize<K> : never;
7
+ type GetterReturn<T> = T extends (() => unknown) ? ReturnType<T> : never;
8
+ type RunGetters<T> = Simplify<{ [k in GetterKeys<T> as GottenKey<k>]: GetterReturn<T[k]> } & { [k in Exclude<keyof T, GetterKeys<T>>]: T[k] }>;
9
+ //#endregion
10
+ export { RunGetters as n, IsEqual as t };
11
+ //# sourceMappingURL=types-DIWB6wdO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DIWB6wdO.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAEY,OAAA,eAAsB,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,SAAA;AAAA,KAEpD,UAAA,oBACS,CAAA,KAAM,CAAA,0BAChB,CAAA,CAAE,CAAA,4BACA,CAAA,yBAGE,CAAA;AAAA,KAEH,SAAA,qBACH,CAAA,2BAA4B,YAAA,CAAa,CAAA;AAAA,KAEtC,YAAA,MAAkB,CAAA,2BAA0B,UAAA,CAAW,CAAA;AAAA,KAEhD,UAAA,MAAgB,QAAA,SAElB,UAAA,CAAW,CAAA,KAAM,SAAA,CAAU,CAAA,IAAK,YAAA,CAAa,CAAA,CAAE,CAAA,eAE/C,OAAA,OAAc,CAAA,EAAG,UAAA,CAAW,CAAA,KAAM,CAAA,CAAE,CAAA"}
@@ -0,0 +1,53 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_isShallowEqual = require("./isShallowEqual-D6PQ041u.cjs");
3
+ const require_invariant = require("./invariant-D8b385d_.cjs");
4
+ const require_useTableWithSelector = require("./useTableWithSelector-Bdsf6Zxk.cjs");
5
+ const require_runGetters = require("./runGetters-Q-UsPG2j.cjs");
6
+ const require_hasTableArg = require("./hasTableArg-dMtayKWH.cjs");
7
+ let react = require("react");
8
+ //#region src/hooks/useCell.ts
9
+ const cellValuesCache = /* @__PURE__ */ new WeakMap();
10
+ const getCellValues = (table, rowId, columnId) => {
11
+ let cellCache = cellValuesCache.get(table.options);
12
+ if (!cellCache) {
13
+ cellCache = /* @__PURE__ */ new Map();
14
+ cellValuesCache.set(table.options, cellCache);
15
+ }
16
+ let rowCache = cellCache.get(rowId);
17
+ if (!rowCache) {
18
+ rowCache = /* @__PURE__ */ new Map();
19
+ cellCache.set(rowId, rowCache);
20
+ }
21
+ let cached = rowCache.get(columnId);
22
+ if (!cached) {
23
+ const cell = table.getRow(rowId)?.getAllCells().find((c) => c.column.id === columnId);
24
+ require_invariant.invariant(cell);
25
+ cached = require_runGetters.runGetters(cell);
26
+ rowCache.set(columnId, cached);
27
+ }
28
+ return cached;
29
+ };
30
+ const useCell = (...args) => {
31
+ const [table, cellOrCoords, selector = require_useTableWithSelector.identity, isEqual = require_isShallowEqual.isShallowEqual] = require_hasTableArg.hasTableArg(args) ? args : [void 0, ...args];
32
+ const { columnId, rowId } = "id" in cellOrCoords ? {
33
+ columnId: cellOrCoords.column.id,
34
+ rowId: cellOrCoords.row.id
35
+ } : {
36
+ columnId: typeof cellOrCoords.column === "string" ? cellOrCoords.column : cellOrCoords.column.id,
37
+ rowId: typeof cellOrCoords.row === "string" ? cellOrCoords.row : cellOrCoords.row.id
38
+ };
39
+ return require_useTableWithSelector.useTableWithSelector(table, (0, react.useCallback)((table) => selector(getCellValues(table, rowId, columnId)), [
40
+ columnId,
41
+ rowId,
42
+ selector
43
+ ]), isEqual);
44
+ };
45
+ const cellHook = useCell;
46
+ const cellHookʹ = (...args) => (selector, isEqual) => cellHook(...[
47
+ ...args,
48
+ selector,
49
+ isEqual
50
+ ]);
51
+ //#endregion
52
+ exports.useCell = useCell;
53
+ exports.useCellʹ = cellHookʹ;
@@ -0,0 +1,17 @@
1
+ import { n as RunGetters, t as IsEqual } from "./types-DIWB6wdO.cjs";
2
+ import { ColumnValues } from "./useColumn.cjs";
3
+ import { RowValues } from "./useRow.cjs";
4
+ import { Cell, Column, Row, RowData, Table } from "@tanstack/table-core";
5
+
6
+ //#region src/hooks/useCell.d.ts
7
+ interface CellValues<TData extends RowData, TValue> extends RunGetters<Cell<TData, TValue>> {}
8
+ type Selector<TData extends RowData, TValue, Selection> = (cellValues: CellValues<TData, TValue>) => Selection;
9
+ interface CellCoords<TData extends RowData, TValue> {
10
+ column: Column<TData, TValue> | ColumnValues<TData> | string;
11
+ row: Row<TData> | RowValues<TData> | string;
12
+ }
13
+ declare const useCell: <TData extends RowData, TValue, Selection = CellValues<TData, TValue>>(...args: [table: Table<TData> | undefined, cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>, selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined] | [cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>, selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined]) => Selection;
14
+ declare const cellHookʹ: <TData extends RowData, TValue>(...args: [table: Table<TData> | undefined, cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>] | [cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>]) => <Selection = CellValues<TData, TValue>>(selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined) => Selection;
15
+ //#endregion
16
+ export { CellValues, useCell, cellHookʹ as useCellʹ };
17
+ //# sourceMappingURL=useCell.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCell.d.cts","names":[],"sources":["../src/hooks/useCell.ts"],"mappings":";;;;;;UAwBiB,UAAA,eAAyB,OAAA,kBAAyB,UAAA,CACjE,IAAA,CAAK,KAAA,EAAO,MAAA;AAAA,KA2CT,QAAA,eAAuB,OAAA,wBAC1B,UAAA,EAAY,UAAA,CAAW,KAAA,EAAO,MAAA,MAC3B,SAAA;AAAA,UAEK,UAAA,eAAyB,OAAA;EACjC,MAAA,EAAQ,MAAA,CAAO,KAAA,EAAO,MAAA,IAAU,YAAA,CAAa,KAAA;EAC7C,GAAA,EAAK,GAAA,CAAI,KAAA,IAAS,SAAA,CAAU,KAAA;AAAA;AAAA,cAGjB,OAAA,iBACG,OAAA,sBAEF,UAAA,CAAW,KAAA,EAAO,MAAA,MAE3B,IAAA,GAEG,KAAA,EAAO,KAAA,CAAM,KAAA,eACb,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,GACtB,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,mBAG1B,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,GACtB,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,oBAE/B,SAAA;AAAA,cAgCG,SAAA,iBACW,OAAA,aACV,IAAA,GAEG,KAAA,EAAO,KAAA,CAAM,KAAA,eACb,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,MAGtB,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,oBAGjB,UAAA,CAAW,KAAA,EAAO,MAAA,GAC7B,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,mBACzB,SAAA"}
@@ -0,0 +1,17 @@
1
+ import { n as RunGetters, t as IsEqual } from "./types-DIWB6wdO.js";
2
+ import { ColumnValues } from "./useColumn.js";
3
+ import { RowValues } from "./useRow.js";
4
+ import { Cell, Column, Row, RowData, Table } from "@tanstack/table-core";
5
+
6
+ //#region src/hooks/useCell.d.ts
7
+ interface CellValues<TData extends RowData, TValue> extends RunGetters<Cell<TData, TValue>> {}
8
+ type Selector<TData extends RowData, TValue, Selection> = (cellValues: CellValues<TData, TValue>) => Selection;
9
+ interface CellCoords<TData extends RowData, TValue> {
10
+ column: Column<TData, TValue> | ColumnValues<TData> | string;
11
+ row: Row<TData> | RowValues<TData> | string;
12
+ }
13
+ declare const useCell: <TData extends RowData, TValue, Selection = CellValues<TData, TValue>>(...args: [table: Table<TData> | undefined, cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>, selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined] | [cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>, selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined]) => Selection;
14
+ declare const cellHookʹ: <TData extends RowData, TValue>(...args: [table: Table<TData> | undefined, cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>] | [cell: Cell<TData, TValue> | CellValues<TData, TValue> | CellCoords<TData, TValue>]) => <Selection = CellValues<TData, TValue>>(selector?: Selector<TData, TValue, Selection> | undefined, isEqual?: IsEqual<NoInfer<Selection>> | undefined) => Selection;
15
+ //#endregion
16
+ export { CellValues, useCell, cellHookʹ as useCellʹ };
17
+ //# sourceMappingURL=useCell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCell.d.ts","names":[],"sources":["../src/hooks/useCell.ts"],"mappings":";;;;;;UAwBiB,UAAA,eAAyB,OAAA,kBAAyB,UAAA,CACjE,IAAA,CAAK,KAAA,EAAO,MAAA;AAAA,KA2CT,QAAA,eAAuB,OAAA,wBAC1B,UAAA,EAAY,UAAA,CAAW,KAAA,EAAO,MAAA,MAC3B,SAAA;AAAA,UAEK,UAAA,eAAyB,OAAA;EACjC,MAAA,EAAQ,MAAA,CAAO,KAAA,EAAO,MAAA,IAAU,YAAA,CAAa,KAAA;EAC7C,GAAA,EAAK,GAAA,CAAI,KAAA,IAAS,SAAA,CAAU,KAAA;AAAA;AAAA,cAGjB,OAAA,iBACG,OAAA,sBAEF,UAAA,CAAW,KAAA,EAAO,MAAA,MAE3B,IAAA,GAEG,KAAA,EAAO,KAAA,CAAM,KAAA,eACb,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,GACtB,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,mBAG1B,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,GACtB,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,oBAE/B,SAAA;AAAA,cAgCG,SAAA,iBACW,OAAA,aACV,IAAA,GAEG,KAAA,EAAO,KAAA,CAAM,KAAA,eACb,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,MAGtB,IAAA,EACI,IAAA,CAAK,KAAA,EAAO,MAAA,IACZ,UAAA,CAAW,KAAA,EAAO,MAAA,IAClB,UAAA,CAAW,KAAA,EAAO,MAAA,oBAGjB,UAAA,CAAW,KAAA,EAAO,MAAA,GAC7B,QAAA,GAAW,QAAA,CAAS,KAAA,EAAO,MAAA,EAAQ,SAAA,eACnC,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,SAAA,mBACzB,SAAA"}
@@ -0,0 +1,53 @@
1
+ import { t as isShallowEqual } from "./isShallowEqual-Kynsoe7a.js";
2
+ import { t as invariant } from "./invariant-BgWq7zZS.js";
3
+ import { n as identity, t as useTableWithSelector } from "./useTableWithSelector-D3f689pF.js";
4
+ import { t as runGetters } from "./runGetters-BfRTE7LZ.js";
5
+ import { t as hasTableArg } from "./hasTableArg-Bu3FbcSo.js";
6
+ import { useCallback } from "react";
7
+ //#region src/hooks/useCell.ts
8
+ const cellValuesCache = /* @__PURE__ */ new WeakMap();
9
+ const getCellValues = (table, rowId, columnId) => {
10
+ let cellCache = cellValuesCache.get(table.options);
11
+ if (!cellCache) {
12
+ cellCache = /* @__PURE__ */ new Map();
13
+ cellValuesCache.set(table.options, cellCache);
14
+ }
15
+ let rowCache = cellCache.get(rowId);
16
+ if (!rowCache) {
17
+ rowCache = /* @__PURE__ */ new Map();
18
+ cellCache.set(rowId, rowCache);
19
+ }
20
+ let cached = rowCache.get(columnId);
21
+ if (!cached) {
22
+ const cell = table.getRow(rowId)?.getAllCells().find((c) => c.column.id === columnId);
23
+ invariant(cell);
24
+ cached = runGetters(cell);
25
+ rowCache.set(columnId, cached);
26
+ }
27
+ return cached;
28
+ };
29
+ const useCell = (...args) => {
30
+ const [table, cellOrCoords, selector = identity, isEqual = isShallowEqual] = hasTableArg(args) ? args : [void 0, ...args];
31
+ const { columnId, rowId } = "id" in cellOrCoords ? {
32
+ columnId: cellOrCoords.column.id,
33
+ rowId: cellOrCoords.row.id
34
+ } : {
35
+ columnId: typeof cellOrCoords.column === "string" ? cellOrCoords.column : cellOrCoords.column.id,
36
+ rowId: typeof cellOrCoords.row === "string" ? cellOrCoords.row : cellOrCoords.row.id
37
+ };
38
+ return useTableWithSelector(table, useCallback((table) => selector(getCellValues(table, rowId, columnId)), [
39
+ columnId,
40
+ rowId,
41
+ selector
42
+ ]), isEqual);
43
+ };
44
+ const cellHook = useCell;
45
+ const cellHookʹ = (...args) => (selector, isEqual) => cellHook(...[
46
+ ...args,
47
+ selector,
48
+ isEqual
49
+ ]);
50
+ //#endregion
51
+ export { useCell, cellHookʹ as useCellʹ };
52
+
53
+ //# sourceMappingURL=useCell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCell.js","names":[],"sources":["../src/hooks/useCell.ts"],"sourcesContent":["import { useCallback } from \"react\"\n\nimport type {\n Cell,\n Column,\n RequiredKeys,\n Row,\n RowData,\n Table,\n TableOptionsResolved,\n} from \"@tanstack/table-core\"\n\nimport { identity } from \"../lib/identity\"\nimport { hasTableArg } from \"../lib/hasTableArg\"\nimport { runGetters } from \"../lib/runGetters\"\nimport { isShallowEqual } from \"../lib/isShallowEqual\"\nimport { invariant } from \"../lib/invariant\"\n\nimport type { IsEqual, RunGetters } from \"../types\"\n\nimport type { ColumnValues } from \"./useColumn\"\nimport type { RowValues } from \"./useRow\"\nimport { useTableWithSelector } from \"./useTableWithSelector\"\n\nexport interface CellValues<TData extends RowData, TValue> extends RunGetters<\n Cell<TData, TValue>\n> {}\n\nconst cellValuesCache = new WeakMap<\n RequiredKeys<TableOptionsResolved<any>, \"state\">,\n Map<string, Map<string, CellValues<any, any>>>\n>()\n\nconst getCellValues = <TData extends RowData, TValue>(\n table: Table<TData>,\n rowId: string,\n columnId: string,\n): CellValues<TData, TValue> => {\n let cellCache = cellValuesCache.get(table.options)\n if (!cellCache) {\n cellCache = new Map()\n cellValuesCache.set(table.options, cellCache)\n }\n\n let rowCache = cellCache.get(rowId)\n if (!rowCache) {\n rowCache = new Map()\n cellCache.set(rowId, rowCache)\n }\n\n let cached = rowCache.get(columnId)\n\n if (!cached) {\n const cell = table\n .getRow(rowId)\n ?.getAllCells()\n .find((c) => c.column.id === columnId) as Cell<TData, TValue> | undefined\n\n invariant(cell)\n\n cached = runGetters(cell)\n\n rowCache.set(columnId, cached)\n }\n\n return cached\n}\n\ntype Selector<TData extends RowData, TValue, Selection> = (\n cellValues: CellValues<TData, TValue>,\n) => Selection\n\ninterface CellCoords<TData extends RowData, TValue> {\n column: Column<TData, TValue> | ColumnValues<TData> | string\n row: Row<TData> | RowValues<TData> | string\n}\n\nexport const useCell = <\n TData extends RowData,\n TValue,\n Selection = CellValues<TData, TValue>,\n>(\n ...args:\n | [\n table: Table<TData> | undefined,\n cell:\n | Cell<TData, TValue>\n | CellValues<TData, TValue>\n | CellCoords<TData, TValue>,\n selector?: Selector<TData, TValue, Selection> | undefined,\n isEqual?: IsEqual<NoInfer<Selection>> | undefined,\n ]\n | [\n cell:\n | Cell<TData, TValue>\n | CellValues<TData, TValue>\n | CellCoords<TData, TValue>,\n selector?: Selector<TData, TValue, Selection> | undefined,\n isEqual?: IsEqual<NoInfer<Selection>> | undefined,\n ]\n): Selection => {\n const [\n table,\n cellOrCoords,\n selector = identity as never,\n isEqual = isShallowEqual,\n ] = hasTableArg(args) ? args : [undefined, ...args]\n\n const { columnId, rowId } =\n \"id\" in cellOrCoords ?\n { columnId: cellOrCoords.column.id, rowId: cellOrCoords.row.id }\n : {\n columnId:\n typeof cellOrCoords.column === \"string\" ?\n cellOrCoords.column\n : cellOrCoords.column.id,\n rowId:\n typeof cellOrCoords.row === \"string\" ?\n cellOrCoords.row\n : cellOrCoords.row.id,\n }\n\n const getSelection = useCallback(\n (table: Table<TData>) => selector(getCellValues(table, rowId, columnId)),\n [columnId, rowId, selector],\n )\n\n return useTableWithSelector(table, getSelection, isEqual)\n}\n\nconst cellHook = useCell\n\nconst cellHookʹ =\n <TData extends RowData, TValue>(\n ...args:\n | [\n table: Table<TData> | undefined,\n cell:\n | Cell<TData, TValue>\n | CellValues<TData, TValue>\n | CellCoords<TData, TValue>,\n ]\n | [\n cell:\n | Cell<TData, TValue>\n | CellValues<TData, TValue>\n | CellCoords<TData, TValue>,\n ]\n ) =>\n <Selection = CellValues<TData, TValue>>(\n selector?: Selector<TData, TValue, Selection> | undefined,\n isEqual?: IsEqual<NoInfer<Selection>> | undefined,\n ): Selection =>\n cellHook(...[...args, selector, isEqual])\n\nexport { cellHookʹ as useCellʹ }\n"],"mappings":";;;;;;;AA4BA,MAAM,kCAAkB,IAAI,QAG1B;AAEF,MAAM,iBACJ,OACA,OACA,aAC8B;CAC9B,IAAI,YAAY,gBAAgB,IAAI,MAAM,OAAO;CACjD,IAAI,CAAC,WAAW;EACd,4BAAY,IAAI,IAAI;EACpB,gBAAgB,IAAI,MAAM,SAAS,SAAS;CAC9C;CAEA,IAAI,WAAW,UAAU,IAAI,KAAK;CAClC,IAAI,CAAC,UAAU;EACb,2BAAW,IAAI,IAAI;EACnB,UAAU,IAAI,OAAO,QAAQ;CAC/B;CAEA,IAAI,SAAS,SAAS,IAAI,QAAQ;CAElC,IAAI,CAAC,QAAQ;EACX,MAAM,OAAO,MACV,OAAO,KAAK,GACX,YAAY,EACb,MAAM,MAAM,EAAE,OAAO,OAAO,QAAQ;EAEvC,UAAU,IAAI;EAEd,SAAS,WAAW,IAAI;EAExB,SAAS,IAAI,UAAU,MAAM;CAC/B;CAEA,OAAO;AACT;AAWA,MAAa,WAKX,GAAG,SAkBW;CACd,MAAM,CACJ,OACA,cACA,WAAW,UACX,UAAU,kBACR,YAAY,IAAI,IAAI,OAAO,CAAC,KAAA,GAAW,GAAG,IAAI;CAElD,MAAM,EAAE,UAAU,UAChB,QAAQ,eACN;EAAE,UAAU,aAAa,OAAO;EAAI,OAAO,aAAa,IAAI;CAAG,IAC/D;EACE,UACE,OAAO,aAAa,WAAW,WAC7B,aAAa,SACb,aAAa,OAAO;EACxB,OACE,OAAO,aAAa,QAAQ,WAC1B,aAAa,MACb,aAAa,IAAI;CACvB;CAOJ,OAAO,qBAAqB,OALP,aAClB,UAAwB,SAAS,cAAc,OAAO,OAAO,QAAQ,CAAC,GACvE;EAAC;EAAU;EAAO;CAAQ,CAGkB,GAAG,OAAO;AAC1D;AAEA,MAAM,WAAW;AAEjB,MAAM,aAEF,GAAG,UAgBH,UACA,YAEA,SAAS,GAAG;CAAC,GAAG;CAAM;CAAU;AAAO,CAAC"}
@@ -0,0 +1,54 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_isShallowEqual = require("./isShallowEqual-D6PQ041u.cjs");
3
+ const require_invariant = require("./invariant-D8b385d_.cjs");
4
+ const require_useTableWithSelector = require("./useTableWithSelector-Bdsf6Zxk.cjs");
5
+ const require_runGetters = require("./runGetters-Q-UsPG2j.cjs");
6
+ const require_hasTableArg = require("./hasTableArg-dMtayKWH.cjs");
7
+ let react = require("react");
8
+ //#region src/hooks/useColumn.ts
9
+ const columnValuesCache = /* @__PURE__ */ new WeakMap();
10
+ const columnHandlersCache = /* @__PURE__ */ new WeakMap();
11
+ const getColumnValues = (table, columnId) => {
12
+ let columnCache = columnValuesCache.get(table.options);
13
+ if (!columnCache) {
14
+ columnCache = /* @__PURE__ */ new Map();
15
+ columnValuesCache.set(table.options, columnCache);
16
+ }
17
+ let cached = columnCache.get(columnId);
18
+ if (!cached) {
19
+ const column = table.getColumn(columnId);
20
+ require_invariant.invariant(column);
21
+ let cachedHandlers = columnHandlersCache.get(column);
22
+ if (!cachedHandlers) {
23
+ cachedHandlers = {
24
+ toggleGroupingHandler: column.getToggleGroupingHandler(),
25
+ toggleSortingHandler: column.getToggleSortingHandler(),
26
+ toggleVisibilityHandler: column.getToggleVisibilityHandler()
27
+ };
28
+ columnHandlersCache.set(column, cachedHandlers);
29
+ }
30
+ const { toggleGroupingHandler, toggleSortingHandler, toggleVisibilityHandler } = cachedHandlers;
31
+ cached = {
32
+ ...require_runGetters.runGetters(column),
33
+ toggleGroupingHandler,
34
+ toggleSortingHandler,
35
+ toggleVisibilityHandler
36
+ };
37
+ columnCache.set(columnId, cached);
38
+ }
39
+ return cached;
40
+ };
41
+ const useColumn = (...args) => {
42
+ const [table, columnOrId, selector = require_useTableWithSelector.identity, isEqual = require_isShallowEqual.isShallowEqual] = require_hasTableArg.hasTableArg(args) ? args : [void 0, ...args];
43
+ const columnId = typeof columnOrId === "string" ? columnOrId : columnOrId.id;
44
+ return require_useTableWithSelector.useTableWithSelector(table, (0, react.useCallback)((table) => selector(getColumnValues(table, columnId)), [columnId, selector]), isEqual);
45
+ };
46
+ const columnHook = useColumn;
47
+ const columnHookʹ = (...args) => (selector, isEqual) => columnHook(...[
48
+ ...args,
49
+ selector,
50
+ isEqual
51
+ ]);
52
+ //#endregion
53
+ exports.useColumn = useColumn;
54
+ exports.useColumnʹ = columnHookʹ;