@osdk/react-components 0.1.0-beta.0 → 0.1.0-beta.2

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 (145) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +56 -6
  3. package/build/browser/object-table/CellContextMenu.js +48 -0
  4. package/build/browser/object-table/CellContextMenu.js.map +1 -0
  5. package/build/browser/object-table/ObjectTable.js +114 -0
  6. package/build/browser/object-table/ObjectTable.js.map +1 -0
  7. package/build/browser/object-table/ObjectTableApi.js.map +1 -1
  8. package/build/browser/object-table/SelectionCells.js +67 -0
  9. package/build/browser/object-table/SelectionCells.js.map +1 -0
  10. package/build/browser/object-table/Table.js +81 -0
  11. package/build/browser/object-table/Table.js.map +1 -0
  12. package/build/browser/object-table/TableBody.js +56 -0
  13. package/build/browser/object-table/TableBody.js.map +1 -0
  14. package/build/browser/object-table/TableCell.js +51 -0
  15. package/build/browser/object-table/TableCell.js.map +1 -0
  16. package/build/browser/object-table/TableHeader.js +63 -0
  17. package/build/browser/object-table/TableHeader.js.map +1 -0
  18. package/build/browser/object-table/TableRow.js +42 -0
  19. package/build/browser/object-table/TableRow.js.map +1 -0
  20. package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
  21. package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
  22. package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
  23. package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
  24. package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
  25. package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
  26. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js +229 -0
  27. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
  28. package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
  29. package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
  30. package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
  31. package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
  32. package/build/browser/object-table/hooks/useCellContextMenu.js +48 -0
  33. package/build/browser/object-table/hooks/useCellContextMenu.js.map +1 -0
  34. package/build/browser/object-table/hooks/useColumnDefs.js +87 -0
  35. package/build/browser/object-table/hooks/useColumnDefs.js.map +1 -0
  36. package/build/browser/object-table/hooks/useDefaultTableStates.js +43 -0
  37. package/build/browser/object-table/hooks/useDefaultTableStates.js.map +1 -0
  38. package/build/browser/object-table/hooks/useObjectTableData.js +49 -0
  39. package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -0
  40. package/build/browser/object-table/hooks/useRowSelection.js +180 -0
  41. package/build/browser/object-table/hooks/useRowSelection.js.map +1 -0
  42. package/build/browser/object-table/hooks/useSelectionColumn.js +51 -0
  43. package/build/browser/object-table/hooks/useSelectionColumn.js.map +1 -0
  44. package/build/browser/{junk.test.js → object-table/utils/getRowId.js} +6 -8
  45. package/build/browser/object-table/utils/getRowId.js.map +1 -0
  46. package/build/browser/public/experimental.js +18 -1
  47. package/build/browser/public/experimental.js.map +1 -1
  48. package/build/cjs/public/experimental.cjs +4256 -0
  49. package/build/cjs/public/experimental.cjs.map +1 -1
  50. package/build/cjs/public/experimental.d.cts +39 -17
  51. package/build/esm/object-table/CellContextMenu.js +48 -0
  52. package/build/esm/object-table/CellContextMenu.js.map +1 -0
  53. package/build/esm/object-table/ObjectTable.js +114 -0
  54. package/build/esm/object-table/ObjectTable.js.map +1 -0
  55. package/build/esm/object-table/ObjectTableApi.js.map +1 -1
  56. package/build/esm/object-table/SelectionCells.js +67 -0
  57. package/build/esm/object-table/SelectionCells.js.map +1 -0
  58. package/build/esm/object-table/Table.js +81 -0
  59. package/build/esm/object-table/Table.js.map +1 -0
  60. package/build/esm/object-table/TableBody.js +56 -0
  61. package/build/esm/object-table/TableBody.js.map +1 -0
  62. package/build/esm/object-table/TableCell.js +51 -0
  63. package/build/esm/object-table/TableCell.js.map +1 -0
  64. package/build/esm/object-table/TableHeader.js +63 -0
  65. package/build/esm/object-table/TableHeader.js.map +1 -0
  66. package/build/esm/object-table/TableRow.js +42 -0
  67. package/build/esm/object-table/TableRow.js.map +1 -0
  68. package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
  69. package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
  70. package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
  71. package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
  72. package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
  73. package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
  74. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js +229 -0
  75. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
  76. package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
  77. package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
  78. package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
  79. package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
  80. package/build/esm/object-table/hooks/useCellContextMenu.js +48 -0
  81. package/build/esm/object-table/hooks/useCellContextMenu.js.map +1 -0
  82. package/build/esm/object-table/hooks/useColumnDefs.js +87 -0
  83. package/build/esm/object-table/hooks/useColumnDefs.js.map +1 -0
  84. package/build/esm/object-table/hooks/useDefaultTableStates.js +43 -0
  85. package/build/esm/object-table/hooks/useDefaultTableStates.js.map +1 -0
  86. package/build/esm/object-table/hooks/useObjectTableData.js +49 -0
  87. package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -0
  88. package/build/esm/object-table/hooks/useRowSelection.js +180 -0
  89. package/build/esm/object-table/hooks/useRowSelection.js.map +1 -0
  90. package/build/esm/object-table/hooks/useSelectionColumn.js +51 -0
  91. package/build/esm/object-table/hooks/useSelectionColumn.js.map +1 -0
  92. package/build/esm/{junk.test.js → object-table/utils/getRowId.js} +6 -8
  93. package/build/esm/object-table/utils/getRowId.js.map +1 -0
  94. package/build/esm/public/experimental.js +18 -1
  95. package/build/esm/public/experimental.js.map +1 -1
  96. package/build/types/object-table/CellContextMenu.d.ts +11 -0
  97. package/build/types/object-table/CellContextMenu.d.ts.map +1 -0
  98. package/build/types/object-table/ObjectTable.d.ts +16 -0
  99. package/build/types/object-table/ObjectTable.d.ts.map +1 -0
  100. package/build/types/object-table/ObjectTableApi.d.ts +30 -20
  101. package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
  102. package/build/types/object-table/SelectionCells.d.ts +14 -0
  103. package/build/types/object-table/SelectionCells.d.ts.map +1 -0
  104. package/build/types/object-table/Table.d.ts +12 -0
  105. package/build/types/object-table/Table.d.ts.map +1 -0
  106. package/build/types/object-table/TableBody.d.ts +11 -0
  107. package/build/types/object-table/TableBody.d.ts.map +1 -0
  108. package/build/types/object-table/TableCell.d.ts +8 -0
  109. package/build/types/object-table/TableCell.d.ts.map +1 -0
  110. package/build/types/object-table/TableHeader.d.ts +7 -0
  111. package/build/types/object-table/TableHeader.d.ts.map +1 -0
  112. package/build/types/object-table/TableRow.d.ts +11 -0
  113. package/build/types/object-table/TableRow.d.ts.map +1 -0
  114. package/build/types/object-table/hooks/__tests__/useCellContextMenu.test.d.ts.map +1 -0
  115. package/build/types/object-table/hooks/__tests__/useColumnDefs.test.d.ts +1 -0
  116. package/build/types/object-table/hooks/__tests__/useColumnDefs.test.d.ts.map +1 -0
  117. package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts +1 -0
  118. package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts.map +1 -0
  119. package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts +1 -0
  120. package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts.map +1 -0
  121. package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts +1 -0
  122. package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts.map +1 -0
  123. package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts +1 -0
  124. package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts.map +1 -0
  125. package/build/types/object-table/hooks/useCellContextMenu.d.ts +17 -0
  126. package/build/types/object-table/hooks/useCellContextMenu.d.ts.map +1 -0
  127. package/build/types/object-table/hooks/useColumnDefs.d.ts +20 -0
  128. package/build/types/object-table/hooks/useColumnDefs.d.ts.map +1 -0
  129. package/build/types/object-table/hooks/useDefaultTableStates.d.ts +19 -0
  130. package/build/types/object-table/hooks/useDefaultTableStates.d.ts.map +1 -0
  131. package/build/types/object-table/hooks/useObjectTableData.d.ts +13 -0
  132. package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -0
  133. package/build/types/object-table/hooks/useRowSelection.d.ts +22 -0
  134. package/build/types/object-table/hooks/useRowSelection.d.ts.map +1 -0
  135. package/build/types/object-table/hooks/useSelectionColumn.d.ts +15 -0
  136. package/build/types/object-table/hooks/useSelectionColumn.d.ts.map +1 -0
  137. package/build/types/object-table/utils/getRowId.d.ts +6 -0
  138. package/build/types/object-table/utils/getRowId.d.ts.map +1 -0
  139. package/build/types/public/experimental.d.ts +2 -1
  140. package/build/types/public/experimental.d.ts.map +1 -1
  141. package/package.json +11 -4
  142. package/build/browser/junk.test.js.map +0 -1
  143. package/build/esm/junk.test.js.map +0 -1
  144. package/build/types/junk.test.d.ts.map +0 -1
  145. /package/build/types/{junk.test.d.ts → object-table/hooks/__tests__/useCellContextMenu.test.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  import { ObjectTypeDefinition, PropertyKeys, WirePropertyTypes, CompileTimeMetadata, ObjectSet, WhereClause, SimplePropertyDef, QueryDefinition, DerivedProperty, Osdk, PrimaryKeyType } from '@osdk/api';
2
2
  import * as React from 'react';
3
+ import React__default from 'react';
3
4
 
4
5
  /**
5
6
  * Props for a single filter list item component
@@ -173,9 +174,15 @@ interface FilterListProps<Q extends ObjectTypeDefinition> {
173
174
  type FilterKey<Q extends ObjectTypeDefinition> = FilterDefinition<Q>["key"];
174
175
  type FilterState<Q extends ObjectTypeDefinition> = FilterDefinition<Q>["filterState"];
175
176
 
176
- type ColumnDefinition<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef>, FunctionColumns extends Record<string, QueryDefinition<{}>>> = {
177
+ type ColumnDefinition<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = Record<string, never>, FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<string, never>> = {
177
178
  locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>;
179
+ /**
180
+ * @default true
181
+ */
178
182
  isVisible?: boolean;
183
+ /**
184
+ * @default none
185
+ */
179
186
  pinned?: "left" | "right" | "none";
180
187
  width?: number;
181
188
  minWidth?: number;
@@ -183,12 +190,12 @@ type ColumnDefinition<Q extends ObjectTypeDefinition, RDPs extends Record<string
183
190
  resizable?: boolean;
184
191
  orderable?: boolean;
185
192
  filterable?: boolean;
186
- renderCell?: (object: Osdk.Instance<Q>, locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>) => React.ReactNode;
193
+ renderCell?: (object: Osdk.Instance<Q, "$allBaseProperties", PropertyKeys<Q>, RDPs>, locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>) => React.ReactNode;
187
194
  renderHeader?: () => React.ReactNode;
188
195
  };
189
- type ColumnDefinitionLocator<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef>, FunctionColumns extends Record<string, QueryDefinition<{}>> = {}> = {
196
+ type ColumnDefinitionLocator<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = Record<string, never>, FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<string, never>> = {
190
197
  type: "property";
191
- propertyKey: PropertyKeys<Q>;
198
+ id: PropertyKeys<Q>;
192
199
  } | {
193
200
  type: "function";
194
201
  id: keyof FunctionColumns;
@@ -197,11 +204,15 @@ type ColumnDefinitionLocator<Q extends ObjectTypeDefinition, RDPs extends Record
197
204
  id: keyof RDPs;
198
205
  creator: DerivedProperty.Creator<Q, RDPs[keyof RDPs]>;
199
206
  };
200
- interface ObjectTableProps<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = {}, FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<string, never>> {
207
+ interface ObjectTableProps<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = Record<string, never>, FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<string, never>> {
201
208
  /**
202
209
  * The set of objects to show in the table
203
210
  */
204
211
  objectSet: ObjectSet<Q>;
212
+ /**
213
+ * The object type of the object
214
+ */
215
+ objectType: Q;
205
216
  /**
206
217
  * Ordered list of column definitions to show in the table
207
218
  *
@@ -279,24 +290,19 @@ interface ObjectTableProps<Q extends ObjectTypeDefinition, RDPs extends Record<s
279
290
  * @param newWidth The new width of the column
280
291
  */
281
292
  onColumnResize?: (columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns, newWidth: number) => void;
282
- /**
283
- * Called when a cell is clicked.
284
- *
285
- * @param object The object representing the row
286
- * @param columnDefinition The column definition for the clicked cell
287
- */
288
- onCellClick?: (object: Osdk.Instance<Q>, locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>) => void;
289
293
  /**
290
294
  * Called when a row is clicked.
291
295
  *
292
296
  * @param object The object representing the clicked row
293
297
  */
294
- onRowClick?: (object: Osdk.Instance<Q>) => void;
298
+ onRowClick?: (object: Osdk.Instance<Q, "$allBaseProperties", PropertyKeys<Q>, RDPs>) => void;
295
299
  /**
296
300
  * Selection mode for the table rows.
297
301
  *
298
302
  * If multiple, a checkbox will be shown for each row to allow selecting multiple rows
299
303
  * as well as a top-level checkbox in the header to select all rows.
304
+ *
305
+ * @default "none"
300
306
  */
301
307
  selectionMode?: "single" | "multiple" | "none";
302
308
  /**
@@ -308,13 +314,29 @@ interface ObjectTableProps<Q extends ObjectTypeDefinition, RDPs extends Record<s
308
314
  * Called when the row selection changes.
309
315
  * Required when row selection is controlled.
310
316
  *
311
- * @param objects The currently selected objects
317
+ * @param selectedRowIds The primary keys of currently selected rows
312
318
  */
313
- onRowSelection?: (objects: PrimaryKeyType<Q>[]) => void;
319
+ onRowSelection?: (selectedRowIds: PrimaryKeyType<Q>[]) => void;
314
320
  /**
315
321
  * If provided, will render this context menu when right clicking on a cell
316
322
  */
317
- renderCellContextMenu?: (object: Osdk.Instance<Q>, locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>) => React.ReactNode;
323
+ renderCellContextMenu?: (row: Osdk.Instance<Q, "$allBaseProperties", PropertyKeys<Q>, RDPs>, cellValue: unknown) => React.ReactNode;
324
+ /**
325
+ * The height of each row in pixels.
326
+ *
327
+ * @default 40
328
+ */
329
+ rowHeight?: number;
318
330
  }
319
331
 
320
- export type { FilterListItemProps, FilterListProps, ObjectTableProps };
332
+ /**
333
+ * ObjectTable - A headless table component for displaying OSDK object sets
334
+ *
335
+ * @example
336
+ * ```tsx
337
+ * <ObjectTable objectSet={myObjectSet} objectType={MyObjectType} />
338
+ * ```
339
+ */
340
+ declare function ObjectTable<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = Record<string, never>, FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<string, never>>({ objectSet, objectType, columnDefinitions, filter, onRowSelection, renderCellContextMenu, selectionMode, selectedRows, ...props }: ObjectTableProps<Q, RDPs, FunctionColumns>): React__default.ReactElement;
341
+
342
+ export { type ColumnDefinition, type ColumnDefinitionLocator, type FilterListItemProps, type FilterListProps, ObjectTable, type ObjectTableProps };
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import React, { useEffect, useRef } from "react";
18
+ import { createPortal } from "react-dom";
19
+ export function CellContextMenu({
20
+ cell,
21
+ position,
22
+ onClose,
23
+ renderContent
24
+ }) {
25
+ const ref = useRef(null);
26
+ useEffect(() => {
27
+ const handleClickOutside = event => {
28
+ if (ref.current && !ref.current.contains(event.target)) {
29
+ onClose();
30
+ }
31
+ };
32
+ document.addEventListener("mousedown", handleClickOutside);
33
+ return () => {
34
+ document.removeEventListener("mousedown", handleClickOutside);
35
+ };
36
+ }, [onClose]);
37
+ return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", {
38
+ ref: ref,
39
+ style: {
40
+ position: "fixed",
41
+ zIndex: 9999,
42
+ left: position.left,
43
+ top: position.top,
44
+ minWidth: position.width
45
+ }
46
+ }, renderContent(cell.row.original, cell)), document.body);
47
+ }
48
+ //# sourceMappingURL=CellContextMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CellContextMenu.js","names":["React","useEffect","useRef","createPortal","CellContextMenu","cell","position","onClose","renderContent","ref","handleClickOutside","event","current","contains","target","document","addEventListener","removeEventListener","createElement","style","zIndex","left","top","minWidth","width","row","original","body"],"sources":["CellContextMenu.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cell, RowData } from \"@tanstack/react-table\";\nimport React, { useEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { PopoverPosition } from \"./hooks/useCellContextMenu.js\";\n\ninterface CellContextMenuProps<TData extends RowData> {\n cell: Cell<TData, unknown>;\n position: PopoverPosition;\n onClose: () => void;\n renderContent: (row: TData, cell: Cell<TData, unknown>) => React.ReactNode;\n}\n\nexport function CellContextMenu<TData extends RowData>({\n cell,\n position,\n onClose,\n renderContent,\n}: CellContextMenuProps<TData>): React.ReactElement {\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n onClose();\n }\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [onClose]);\n\n return createPortal(\n <div\n ref={ref}\n style={{\n position: \"fixed\",\n zIndex: 9999,\n left: position.left,\n top: position.top,\n minWidth: position.width,\n }}\n >\n {renderContent(cell.row.original, cell)}\n </div>,\n document.body,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,YAAY,QAAQ,WAAW;AAUxC,OAAO,SAASC,eAAeA,CAAwB;EACrDC,IAAI;EACJC,QAAQ;EACRC,OAAO;EACPC;AAC2B,CAAC,EAAsB;EAClD,MAAMC,GAAG,GAAGP,MAAM,CAAiB,IAAI,CAAC;EAExCD,SAAS,CAAC,MAAM;IACd,MAAMS,kBAAkB,GAAIC,KAAiB,IAAK;MAChD,IAAIF,GAAG,CAACG,OAAO,IAAI,CAACH,GAAG,CAACG,OAAO,CAACC,QAAQ,CAACF,KAAK,CAACG,MAAc,CAAC,EAAE;QAC9DP,OAAO,CAAC,CAAC;MACX;IACF,CAAC;IAEDQ,QAAQ,CAACC,gBAAgB,CAAC,WAAW,EAAEN,kBAAkB,CAAC;IAE1D,OAAO,MAAM;MACXK,QAAQ,CAACE,mBAAmB,CAAC,WAAW,EAAEP,kBAAkB,CAAC;IAC/D,CAAC;EACH,CAAC,EAAE,CAACH,OAAO,CAAC,CAAC;EAEb,oBAAOJ,YAAY,cACjBH,KAAA,CAAAkB,aAAA;IACET,GAAG,EAAEA,GAAI;IACTU,KAAK,EAAE;MACLb,QAAQ,EAAE,OAAO;MACjBc,MAAM,EAAE,IAAI;MACZC,IAAI,EAAEf,QAAQ,CAACe,IAAI;MACnBC,GAAG,EAAEhB,QAAQ,CAACgB,GAAG;MACjBC,QAAQ,EAAEjB,QAAQ,CAACkB;IACrB;EAAE,GAEDhB,aAAa,CAACH,IAAI,CAACoB,GAAG,CAACC,QAAQ,EAAErB,IAAI,CACnC,CAAC,EACNU,QAAQ,CAACY,IACX,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,114 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { getCoreRowModel, useReactTable } from "@tanstack/react-table";
18
+ import React, { useCallback, useMemo, useState } from "react";
19
+ import { useColumnDefs } from "./hooks/useColumnDefs.js";
20
+ import { useDefaultTableStates } from "./hooks/useDefaultTableStates.js";
21
+ import { useObjectTableData } from "./hooks/useObjectTableData.js";
22
+ import { useRowSelection } from "./hooks/useRowSelection.js";
23
+ import { useSelectionColumn } from "./hooks/useSelectionColumn.js";
24
+ import { Table } from "./Table.js";
25
+ import { getRowId } from "./utils/getRowId.js";
26
+
27
+ /**
28
+ * ObjectTable - A headless table component for displaying OSDK object sets
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * <ObjectTable objectSet={myObjectSet} objectType={MyObjectType} />
33
+ * ```
34
+ */
35
+
36
+ export function ObjectTable({
37
+ objectSet,
38
+ objectType,
39
+ columnDefinitions,
40
+ filter,
41
+ onRowSelection,
42
+ renderCellContextMenu,
43
+ selectionMode = "none",
44
+ selectedRows,
45
+ ...props
46
+ }) {
47
+ const {
48
+ data,
49
+ fetchMore,
50
+ isLoading
51
+ } = useObjectTableData(objectSet, columnDefinitions, filter);
52
+ const {
53
+ columns,
54
+ loading: isColumnsLoading
55
+ } = useColumnDefs(objectType, columnDefinitions);
56
+ const {
57
+ columnVisibility
58
+ } = useDefaultTableStates({
59
+ columnDefinitions
60
+ });
61
+ const [columnSizing, setColumnSizing] = useState({});
62
+ const {
63
+ rowSelection,
64
+ isAllSelected,
65
+ hasSelection,
66
+ onToggleAll,
67
+ onToggleRow
68
+ } = useRowSelection({
69
+ selectionMode,
70
+ selectedRows,
71
+ onRowSelection,
72
+ data
73
+ });
74
+ const selectionColumn = useSelectionColumn({
75
+ selectionMode,
76
+ isAllSelected,
77
+ hasSelection,
78
+ onToggleAll,
79
+ onToggleRow
80
+ });
81
+ const allColumns = useMemo(() => {
82
+ return selectionColumn ? [selectionColumn, ...columns] : columns;
83
+ }, [selectionColumn, columns]);
84
+ const table = useReactTable({
85
+ data: data ?? [],
86
+ columns: allColumns,
87
+ getCoreRowModel: getCoreRowModel(),
88
+ state: {
89
+ columnVisibility,
90
+ rowSelection,
91
+ columnSizing
92
+ },
93
+ onColumnSizingChange: setColumnSizing,
94
+ enableRowSelection: selectionMode !== "none",
95
+ columnResizeMode: "onChange",
96
+ columnResizeDirection: "ltr",
97
+ defaultColumn: {
98
+ minSize: 80
99
+ },
100
+ getRowId
101
+ });
102
+ const onRenderCellContextMenu = useCallback((row, cell) => {
103
+ return renderCellContextMenu?.(row, cell.getValue());
104
+ }, [renderCellContextMenu]);
105
+ return /*#__PURE__*/React.createElement(Table, {
106
+ table: table,
107
+ isLoading: isLoading || isColumnsLoading,
108
+ fetchNextPage: fetchMore,
109
+ onRowClick: props.onRowClick,
110
+ rowHeight: props.rowHeight,
111
+ renderCellContextMenu: onRenderCellContextMenu
112
+ });
113
+ }
114
+ //# sourceMappingURL=ObjectTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectTable.js","names":["getCoreRowModel","useReactTable","React","useCallback","useMemo","useState","useColumnDefs","useDefaultTableStates","useObjectTableData","useRowSelection","useSelectionColumn","Table","getRowId","ObjectTable","objectSet","objectType","columnDefinitions","filter","onRowSelection","renderCellContextMenu","selectionMode","selectedRows","props","data","fetchMore","isLoading","columns","loading","isColumnsLoading","columnVisibility","columnSizing","setColumnSizing","rowSelection","isAllSelected","hasSelection","onToggleAll","onToggleRow","selectionColumn","allColumns","table","state","onColumnSizingChange","enableRowSelection","columnResizeMode","columnResizeDirection","defaultColumn","minSize","onRenderCellContextMenu","row","cell","getValue","createElement","fetchNextPage","onRowClick","rowHeight"],"sources":["ObjectTable.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport {\n type Cell,\n type ColumnSizingState,\n getCoreRowModel,\n useReactTable,\n} from \"@tanstack/react-table\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { useColumnDefs } from \"./hooks/useColumnDefs.js\";\nimport { useDefaultTableStates } from \"./hooks/useDefaultTableStates.js\";\nimport { useObjectTableData } from \"./hooks/useObjectTableData.js\";\nimport { useRowSelection } from \"./hooks/useRowSelection.js\";\nimport { useSelectionColumn } from \"./hooks/useSelectionColumn.js\";\nimport type { ObjectTableProps } from \"./ObjectTableApi.js\";\nimport { Table } from \"./Table.js\";\nimport { getRowId } from \"./utils/getRowId.js\";\n\n/**\n * ObjectTable - A headless table component for displaying OSDK object sets\n *\n * @example\n * ```tsx\n * <ObjectTable objectSet={myObjectSet} objectType={MyObjectType} />\n * ```\n */\n\nexport function ObjectTable<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectSet,\n objectType,\n columnDefinitions,\n filter,\n onRowSelection,\n renderCellContextMenu,\n selectionMode = \"none\",\n selectedRows,\n ...props\n}: ObjectTableProps<Q, RDPs, FunctionColumns>): React.ReactElement {\n const { data, fetchMore, isLoading } = useObjectTableData<\n Q,\n RDPs,\n FunctionColumns\n >(\n objectSet,\n columnDefinitions,\n filter,\n );\n\n const { columns, loading: isColumnsLoading } = useColumnDefs<\n Q,\n RDPs,\n FunctionColumns\n >(\n objectType,\n columnDefinitions,\n );\n\n const { columnVisibility } = useDefaultTableStates({ columnDefinitions });\n\n const [columnSizing, setColumnSizing] = useState<ColumnSizingState>({});\n\n const {\n rowSelection,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n } = useRowSelection<Q, RDPs>({\n selectionMode,\n selectedRows,\n onRowSelection,\n data,\n });\n\n const selectionColumn = useSelectionColumn<Q, RDPs>(\n { selectionMode, isAllSelected, hasSelection, onToggleAll, onToggleRow },\n );\n\n const allColumns = useMemo(() => {\n return selectionColumn ? [selectionColumn, ...columns] : columns;\n }, [selectionColumn, columns]);\n\n const table = useReactTable<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >({\n data: data ?? [],\n columns: allColumns,\n getCoreRowModel: getCoreRowModel(),\n state: {\n columnVisibility,\n rowSelection,\n columnSizing,\n },\n onColumnSizingChange: setColumnSizing,\n enableRowSelection: selectionMode !== \"none\",\n columnResizeMode: \"onChange\",\n columnResizeDirection: \"ltr\",\n defaultColumn: {\n minSize: 80,\n },\n getRowId,\n });\n\n const onRenderCellContextMenu = useCallback(\n (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cell: Cell<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => {\n return renderCellContextMenu?.(row, cell.getValue());\n },\n [renderCellContextMenu],\n );\n\n const isTableLoading = isLoading || isColumnsLoading;\n\n return (\n <Table\n table={table}\n isLoading={isTableLoading}\n fetchNextPage={fetchMore}\n onRowClick={props.onRowClick}\n rowHeight={props.rowHeight}\n renderCellContextMenu={onRenderCellContextMenu}\n />\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAGEA,eAAe,EACfC,aAAa,QACR,uBAAuB;AAC9B,OAAOC,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAC7D,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,kBAAkB,QAAQ,+BAA+B;AAElE,SAASC,KAAK,QAAQ,YAAY;AAClC,SAASC,QAAQ,QAAQ,qBAAqB;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,WAAWA,CAUzB;EACAC,SAAS;EACTC,UAAU;EACVC,iBAAiB;EACjBC,MAAM;EACNC,cAAc;EACdC,qBAAqB;EACrBC,aAAa,GAAG,MAAM;EACtBC,YAAY;EACZ,GAAGC;AACuC,CAAC,EAAsB;EACjE,MAAM;IAAEC,IAAI;IAAEC,SAAS;IAAEC;EAAU,CAAC,GAAGjB,kBAAkB,CAKvDM,SAAS,EACTE,iBAAiB,EACjBC,MACF,CAAC;EAED,MAAM;IAAES,OAAO;IAAEC,OAAO,EAAEC;EAAiB,CAAC,GAAGtB,aAAa,CAK1DS,UAAU,EACVC,iBACF,CAAC;EAED,MAAM;IAAEa;EAAiB,CAAC,GAAGtB,qBAAqB,CAAC;IAAES;EAAkB,CAAC,CAAC;EAEzE,MAAM,CAACc,YAAY,EAAEC,eAAe,CAAC,GAAG1B,QAAQ,CAAoB,CAAC,CAAC,CAAC;EAEvE,MAAM;IACJ2B,YAAY;IACZC,aAAa;IACbC,YAAY;IACZC,WAAW;IACXC;EACF,CAAC,GAAG3B,eAAe,CAAU;IAC3BW,aAAa;IACbC,YAAY;IACZH,cAAc;IACdK;EACF,CAAC,CAAC;EAEF,MAAMc,eAAe,GAAG3B,kBAAkB,CACxC;IAAEU,aAAa;IAAEa,aAAa;IAAEC,YAAY;IAAEC,WAAW;IAAEC;EAAY,CACzE,CAAC;EAED,MAAME,UAAU,GAAGlC,OAAO,CAAC,MAAM;IAC/B,OAAOiC,eAAe,GAAG,CAACA,eAAe,EAAE,GAAGX,OAAO,CAAC,GAAGA,OAAO;EAClE,CAAC,EAAE,CAACW,eAAe,EAAEX,OAAO,CAAC,CAAC;EAE9B,MAAMa,KAAK,GAAGtC,aAAa,CAEzB;IACAsB,IAAI,EAAEA,IAAI,IAAI,EAAE;IAChBG,OAAO,EAAEY,UAAU;IACnBtC,eAAe,EAAEA,eAAe,CAAC,CAAC;IAClCwC,KAAK,EAAE;MACLX,gBAAgB;MAChBG,YAAY;MACZF;IACF,CAAC;IACDW,oBAAoB,EAAEV,eAAe;IACrCW,kBAAkB,EAAEtB,aAAa,KAAK,MAAM;IAC5CuB,gBAAgB,EAAE,UAAU;IAC5BC,qBAAqB,EAAE,KAAK;IAC5BC,aAAa,EAAE;MACbC,OAAO,EAAE;IACX,CAAC;IACDlC;EACF,CAAC,CAAC;EAEF,MAAMmC,uBAAuB,GAAG5C,WAAW,CACzC,CACE6C,GAAkE,EAClEC,IAGC,KACE;IACH,OAAO9B,qBAAqB,GAAG6B,GAAG,EAAEC,IAAI,CAACC,QAAQ,CAAC,CAAC,CAAC;EACtD,CAAC,EACD,CAAC/B,qBAAqB,CACxB,CAAC;EAID,oBACEjB,KAAA,CAAAiD,aAAA,CAACxC,KAAK;IACJ4B,KAAK,EAAEA,KAAM;IACbd,SAAS,EALUA,SAAS,IAAIG,gBAKN;IAC1BwB,aAAa,EAAE5B,SAAU;IACzB6B,UAAU,EAAE/B,KAAK,CAAC+B,UAAW;IAC7BC,SAAS,EAAEhC,KAAK,CAACgC,SAAU;IAC3BnC,qBAAqB,EAAE4B;EAAwB,CAChD,CAAC;AAEN","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectTableApi.js","names":[],"sources":["ObjectTableApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type * as React from \"react\";\n\nexport type ColumnDefinition<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n FunctionColumns extends Record<string, QueryDefinition<{}>>,\n> = {\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>;\n isVisible?: boolean;\n pinned?: \"left\" | \"right\" | \"none\";\n width?: number;\n minWidth?: number;\n maxWidth?: number;\n resizable?: boolean;\n orderable?: boolean;\n filterable?: boolean;\n renderCell?: (\n object: Osdk.Instance<Q>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => React.ReactNode;\n renderHeader?: () => React.ReactNode;\n};\n\ntype ColumnDefinitionLocator<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = {},\n> =\n | {\n type: \"property\";\n propertyKey: PropertyKeys<Q>;\n }\n | {\n type: \"function\";\n id: keyof FunctionColumns;\n }\n | {\n type: \"rdp\";\n id: keyof RDPs;\n creator: DerivedProperty.Creator<Q, RDPs[keyof RDPs]>;\n };\n\nexport interface ObjectTableProps<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * The set of objects to show in the table\n */\n objectSet: ObjectSet<Q>;\n\n /**\n * Ordered list of column definitions to show in the table\n *\n * If not provided, all of the properties of the object type will be shown in default order.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n\n /**\n * Whether the table is filterable by the user.\n *\n * @default true\n */\n filterable?: boolean;\n\n /**\n * The current where clause to filter the objects in the table.\n * If provided, the filter is controlled.\n */\n filter?: WhereClause<Q, RDPs>;\n\n /**\n * Called when the where clause is changed.\n * Required when filter is controlled.\n *\n * @param newWhere The new where clause\n */\n onFilterChanged?: (newWhere: WhereClause<Q, RDPs>) => void;\n\n /**\n * Whether the table is sortable by the user.\n *\n * @default true\n */\n orderable?: boolean;\n\n /**\n * The current order by clause to sort the objects in the table.\n * If provided, the sorting is controlled.\n */\n orderBy?: Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * Called when the order by clause is changed.\n * Required when sorting is controlled.\n *\n * @param newOrderBy The new order by clause\n */\n onOrderByChanged?: (\n newOrderBy: Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n }>,\n ) => void;\n\n /**\n * Called when the visible columns change.\n *\n * If provided, the table will allow the user to show/hide columns.\n *\n * @param newStates The new list of column visibility states\n */\n onColumnVisibilityChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n isVisible: boolean;\n }>,\n ) => void;\n\n /**\n * Called when the pinned columns change.\n *\n * If provided, the table will allow the user to pin/unpin columns.\n *\n * @param newStates The new list of column pin states\n */\n onColumnsPinnedChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n pinned: \"left\" | \"right\" | \"none\";\n }>,\n ) => void;\n\n /**\n * Called when a column is resized.\n *\n * @param columnId The ID of the resized column\n * @param newWidth The new width of the column\n */\n onColumnResize?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n newWidth: number,\n ) => void;\n\n /**\n * Called when a cell is clicked.\n *\n * @param object The object representing the row\n * @param columnDefinition The column definition for the clicked cell\n */\n onCellClick?: (\n object: Osdk.Instance<Q>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => void;\n\n /**\n * Called when a row is clicked.\n *\n * @param object The object representing the clicked row\n */\n onRowClick?: (object: Osdk.Instance<Q>) => void;\n\n /**\n * Selection mode for the table rows.\n *\n * If multiple, a checkbox will be shown for each row to allow selecting multiple rows\n * as well as a top-level checkbox in the header to select all rows.\n */\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n\n /**\n * The currently selected rows in the table.\n * If provided, the row selection is controlled.\n */\n selectedRows?: PrimaryKeyType<Q>[];\n\n /**\n * Called when the row selection changes.\n * Required when row selection is controlled.\n *\n * @param objects The currently selected objects\n */\n onRowSelection?: (objects: PrimaryKeyType<Q>[]) => void;\n\n /**\n * If provided, will render this context menu when right clicking on a cell\n */\n renderCellContextMenu?: (\n object: Osdk.Instance<Q>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => React.ReactNode;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"ObjectTableApi.js","names":[],"sources":["ObjectTableApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type * as React from \"react\";\n\nexport type ColumnDefinition<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = {\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>;\n\n /**\n * @default true\n */\n isVisible?: boolean;\n\n /**\n * @default none\n */\n pinned?: \"left\" | \"right\" | \"none\";\n width?: number;\n minWidth?: number;\n maxWidth?: number;\n resizable?: boolean;\n orderable?: boolean;\n filterable?: boolean;\n renderCell?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => React.ReactNode;\n renderHeader?: () => React.ReactNode;\n};\n\nexport type ColumnDefinitionLocator<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n | {\n type: \"property\";\n id: PropertyKeys<Q>;\n }\n | {\n type: \"function\";\n id: keyof FunctionColumns;\n }\n | {\n type: \"rdp\";\n id: keyof RDPs;\n creator: DerivedProperty.Creator<Q, RDPs[keyof RDPs]>;\n };\n\nexport interface ObjectTableProps<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * The set of objects to show in the table\n */\n objectSet: ObjectSet<Q>;\n\n /**\n * The object type of the object\n */\n objectType: Q;\n\n /**\n * Ordered list of column definitions to show in the table\n *\n * If not provided, all of the properties of the object type will be shown in default order.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n\n /**\n * Whether the table is filterable by the user.\n *\n * @default true\n */\n filterable?: boolean;\n\n /**\n * The current where clause to filter the objects in the table.\n * If provided, the filter is controlled.\n */\n filter?: WhereClause<Q, RDPs>;\n\n /**\n * Called when the where clause is changed.\n * Required when filter is controlled.\n *\n * @param newWhere The new where clause\n */\n onFilterChanged?: (newWhere: WhereClause<Q, RDPs>) => void;\n\n /**\n * Whether the table is sortable by the user.\n *\n * @default true\n */\n orderable?: boolean;\n\n /**\n * The current order by clause to sort the objects in the table.\n * If provided, the sorting is controlled.\n */\n orderBy?: Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * Called when the order by clause is changed.\n * Required when sorting is controlled.\n *\n * @param newOrderBy The new order by clause\n */\n onOrderByChanged?: (\n newOrderBy: Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n }>,\n ) => void;\n\n /**\n * Called when the visible columns change.\n *\n * If provided, the table will allow the user to show/hide columns.\n *\n * @param newStates The new list of column visibility states\n */\n onColumnVisibilityChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n isVisible: boolean;\n }>,\n ) => void;\n\n /**\n * Called when the pinned columns change.\n *\n * If provided, the table will allow the user to pin/unpin columns.\n *\n * @param newStates The new list of column pin states\n */\n onColumnsPinnedChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n pinned: \"left\" | \"right\" | \"none\";\n }>,\n ) => void;\n\n /**\n * Called when a column is resized.\n *\n * @param columnId The ID of the resized column\n * @param newWidth The new width of the column\n */\n onColumnResize?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n newWidth: number,\n ) => void;\n\n /**\n * Called when a row is clicked.\n *\n * @param object The object representing the clicked row\n */\n onRowClick?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => void;\n\n /**\n * Selection mode for the table rows.\n *\n * If multiple, a checkbox will be shown for each row to allow selecting multiple rows\n * as well as a top-level checkbox in the header to select all rows.\n *\n * @default \"none\"\n */\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n\n /**\n * The currently selected rows in the table.\n * If provided, the row selection is controlled.\n */\n selectedRows?: PrimaryKeyType<Q>[];\n\n /**\n * Called when the row selection changes.\n * Required when row selection is controlled.\n *\n * @param selectedRowIds The primary keys of currently selected rows\n */\n\n onRowSelection?: (selectedRowIds: PrimaryKeyType<Q>[]) => void;\n\n /**\n * If provided, will render this context menu when right clicking on a cell\n */\n renderCellContextMenu?: (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cellValue: unknown,\n ) => React.ReactNode;\n\n /**\n * The height of each row in pixels.\n *\n * @default 40\n */\n rowHeight?: number;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import React, { useCallback } from "react";
18
+ export function SelectionHeaderCell({
19
+ isAllSelected,
20
+ hasSelection,
21
+ onToggleAll
22
+ }) {
23
+ return /*#__PURE__*/React.createElement("div", {
24
+ style: {
25
+ display: "flex",
26
+ alignItems: "center",
27
+ justifyContent: "center",
28
+ width: "100%"
29
+ }
30
+ }, /*#__PURE__*/React.createElement("input", {
31
+ type: "checkbox",
32
+ checked: isAllSelected,
33
+ ref: input => {
34
+ if (input) input.indeterminate = hasSelection && !isAllSelected;
35
+ },
36
+ onChange: onToggleAll,
37
+ "aria-label": "Select all rows"
38
+ }));
39
+ }
40
+ const noop = () => {};
41
+ export function SelectionCell({
42
+ row,
43
+ onToggleRow
44
+ }) {
45
+ const isSelected = row.getIsSelected();
46
+ const handleClick = useCallback(e => {
47
+ // Prevent onRowClick call
48
+ e.stopPropagation();
49
+ onToggleRow(row.id, row.index, e.shiftKey);
50
+ }, [row, onToggleRow]);
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ style: {
53
+ display: "flex",
54
+ alignItems: "center",
55
+ justifyContent: "center",
56
+ width: "100%"
57
+ }
58
+ }, /*#__PURE__*/React.createElement("input", {
59
+ type: "checkbox",
60
+ checked: isSelected,
61
+ onClick: handleClick,
62
+ onChange: noop // Using onClick here
63
+ ,
64
+ "aria-label": `Select row ${row.index + 1}`
65
+ }));
66
+ }
67
+ //# sourceMappingURL=SelectionCells.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectionCells.js","names":["React","useCallback","SelectionHeaderCell","isAllSelected","hasSelection","onToggleAll","createElement","style","display","alignItems","justifyContent","width","type","checked","ref","input","indeterminate","onChange","noop","SelectionCell","row","onToggleRow","isSelected","getIsSelected","handleClick","e","stopPropagation","id","index","shiftKey","onClick"],"sources":["SelectionCells.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Row, RowData } from \"@tanstack/react-table\";\nimport React, { useCallback } from \"react\";\n\ninterface SelectionHeaderCellProps {\n isAllSelected: boolean;\n hasSelection: boolean;\n onToggleAll: () => void;\n}\n\nexport function SelectionHeaderCell({\n isAllSelected,\n hasSelection,\n onToggleAll,\n}: SelectionHeaderCellProps): React.ReactElement {\n return (\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: \"100%\",\n }}\n >\n <input\n type=\"checkbox\"\n checked={isAllSelected}\n ref={(input) => {\n if (input) input.indeterminate = hasSelection && !isAllSelected;\n }}\n onChange={onToggleAll}\n aria-label=\"Select all rows\"\n />\n </div>\n );\n}\n\ninterface SelectionCellProps<TData extends RowData> {\n row: Row<TData>;\n onToggleRow: (rowId: string, rowIndex: number, isShiftClick: boolean) => void;\n}\n\nconst noop = () => {};\nexport function SelectionCell<TData extends RowData>({\n row,\n onToggleRow,\n}: SelectionCellProps<TData>): React.ReactElement {\n const isSelected = row.getIsSelected();\n\n const handleClick = useCallback(\n (e: React.MouseEvent<HTMLInputElement>) => {\n // Prevent onRowClick call\n e.stopPropagation();\n\n onToggleRow(row.id, row.index, e.shiftKey);\n },\n [row, onToggleRow],\n );\n\n return (\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: \"100%\",\n }}\n >\n <input\n type=\"checkbox\"\n checked={isSelected}\n onClick={handleClick}\n onChange={noop} // Using onClick here\n aria-label={`Select row ${row.index + 1}`}\n />\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAQ1C,OAAO,SAASC,mBAAmBA,CAAC;EAClCC,aAAa;EACbC,YAAY;EACZC;AACwB,CAAC,EAAsB;EAC/C,oBACEL,KAAA,CAAAM,aAAA;IACEC,KAAK,EAAE;MACLC,OAAO,EAAE,MAAM;MACfC,UAAU,EAAE,QAAQ;MACpBC,cAAc,EAAE,QAAQ;MACxBC,KAAK,EAAE;IACT;EAAE,gBAEFX,KAAA,CAAAM,aAAA;IACEM,IAAI,EAAC,UAAU;IACfC,OAAO,EAAEV,aAAc;IACvBW,GAAG,EAAGC,KAAK,IAAK;MACd,IAAIA,KAAK,EAAEA,KAAK,CAACC,aAAa,GAAGZ,YAAY,IAAI,CAACD,aAAa;IACjE,CAAE;IACFc,QAAQ,EAAEZ,WAAY;IACtB,cAAW;EAAiB,CAC7B,CACE,CAAC;AAEV;AAOA,MAAMa,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,OAAO,SAASC,aAAaA,CAAwB;EACnDC,GAAG;EACHC;AACyB,CAAC,EAAsB;EAChD,MAAMC,UAAU,GAAGF,GAAG,CAACG,aAAa,CAAC,CAAC;EAEtC,MAAMC,WAAW,GAAGvB,WAAW,CAC5BwB,CAAqC,IAAK;IACzC;IACAA,CAAC,CAACC,eAAe,CAAC,CAAC;IAEnBL,WAAW,CAACD,GAAG,CAACO,EAAE,EAAEP,GAAG,CAACQ,KAAK,EAAEH,CAAC,CAACI,QAAQ,CAAC;EAC5C,CAAC,EACD,CAACT,GAAG,EAAEC,WAAW,CACnB,CAAC;EAED,oBACErB,KAAA,CAAAM,aAAA;IACEC,KAAK,EAAE;MACLC,OAAO,EAAE,MAAM;MACfC,UAAU,EAAE,QAAQ;MACpBC,cAAc,EAAE,QAAQ;MACxBC,KAAK,EAAE;IACT;EAAE,gBAEFX,KAAA,CAAAM,aAAA;IACEM,IAAI,EAAC,UAAU;IACfC,OAAO,EAAES,UAAW;IACpBQ,OAAO,EAAEN,WAAY;IACrBP,QAAQ,EAAEC,IAAK,CAAC;IAAA;IAChB,cAAY,cAAcE,GAAG,CAACQ,KAAK,GAAG,CAAC;EAAG,CAC3C,CACE,CAAC;AAEV","ignoreList":[]}
@@ -0,0 +1,81 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import React, { useCallback, useRef } from "react";
18
+ import { TableBody } from "./TableBody.js";
19
+ import { TableHeader } from "./TableHeader.js";
20
+ export function Table({
21
+ table,
22
+ isLoading,
23
+ fetchNextPage,
24
+ onRowClick,
25
+ rowHeight,
26
+ renderCellContextMenu
27
+ }) {
28
+ const tableContainerRef = useRef(null);
29
+
30
+ // Using a ref to prevent duplicate fetches from rapid scroll events while a fetch is in-flight
31
+ const fetchingRef = useRef(false);
32
+ const fetchMoreOnEndReached = useCallback(async containerRefElement => {
33
+ if (containerRefElement && !fetchingRef.current) {
34
+ const {
35
+ scrollHeight,
36
+ scrollTop,
37
+ clientHeight
38
+ } = containerRefElement;
39
+ if (scrollHeight - scrollTop - clientHeight < 100 && !isLoading) {
40
+ fetchingRef.current = true;
41
+ try {
42
+ await fetchNextPage?.();
43
+ } finally {
44
+ fetchingRef.current = false;
45
+ }
46
+ }
47
+ }
48
+ }, [fetchNextPage, isLoading]);
49
+ const handleScroll = useCallback(async e => {
50
+ await fetchMoreOnEndReached(e.currentTarget);
51
+ }, [fetchMoreOnEndReached]);
52
+
53
+ // TODO: Handle error, loading and empty states
54
+
55
+ return /*#__PURE__*/React.createElement("div", {
56
+ ref: tableContainerRef,
57
+ style: {
58
+ position: "relative",
59
+ // needed for sticky header
60
+ height: "100%",
61
+ // needed for scrolling
62
+ overflow: "auto",
63
+ cursor: table.getState().columnSizingInfo?.isResizingColumn ? "col-resize" : "default",
64
+ userSelect: table.getState().columnSizingInfo?.isResizingColumn ? "none" : "auto"
65
+ },
66
+ onScroll: handleScroll
67
+ }, /*#__PURE__*/React.createElement("table", {
68
+ style: {
69
+ display: "grid"
70
+ }
71
+ }, /*#__PURE__*/React.createElement(TableHeader, {
72
+ table: table
73
+ }), /*#__PURE__*/React.createElement(TableBody, {
74
+ rows: table.getRowModel().rows,
75
+ tableContainerRef: tableContainerRef,
76
+ onRowClick: onRowClick,
77
+ rowHeight: rowHeight,
78
+ renderCellContextMenu: renderCellContextMenu
79
+ })));
80
+ }
81
+ //# sourceMappingURL=Table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Table.js","names":["React","useCallback","useRef","TableBody","TableHeader","Table","table","isLoading","fetchNextPage","onRowClick","rowHeight","renderCellContextMenu","tableContainerRef","fetchingRef","fetchMoreOnEndReached","containerRefElement","current","scrollHeight","scrollTop","clientHeight","handleScroll","e","currentTarget","createElement","ref","style","position","height","overflow","cursor","getState","columnSizingInfo","isResizingColumn","userSelect","onScroll","display","rows","getRowModel"],"sources":["Table.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cell, RowData, Table } from \"@tanstack/react-table\";\nimport React, { type ReactElement, useCallback, useRef } from \"react\";\nimport { TableBody } from \"./TableBody.js\";\nimport { TableHeader } from \"./TableHeader.js\";\n\ninterface TableProps<TData extends RowData> {\n table: Table<TData>;\n isLoading?: boolean;\n fetchNextPage?: () => Promise<void>;\n onRowClick?: (row: TData) => void;\n rowHeight?: number;\n renderCellContextMenu?: (\n row: TData,\n cell: Cell<TData, unknown>,\n ) => React.ReactNode;\n}\n\nexport function Table<TData extends RowData>(\n {\n table,\n isLoading,\n fetchNextPage,\n onRowClick,\n rowHeight,\n renderCellContextMenu,\n }: TableProps<TData>,\n): ReactElement {\n const tableContainerRef = useRef<HTMLDivElement>(null);\n\n // Using a ref to prevent duplicate fetches from rapid scroll events while a fetch is in-flight\n const fetchingRef = useRef(false);\n\n const fetchMoreOnEndReached = useCallback(\n async (containerRefElement?: HTMLDivElement | null) => {\n if (containerRefElement && !fetchingRef.current) {\n const { scrollHeight, scrollTop, clientHeight } = containerRefElement;\n if (\n scrollHeight - scrollTop - clientHeight < 100\n && !isLoading\n ) {\n fetchingRef.current = true;\n try {\n await fetchNextPage?.();\n } finally {\n fetchingRef.current = false;\n }\n }\n }\n },\n [fetchNextPage, isLoading],\n );\n\n const handleScroll = useCallback(\n async (e: React.UIEvent<HTMLDivElement>) => {\n await fetchMoreOnEndReached(e.currentTarget);\n },\n [fetchMoreOnEndReached],\n );\n\n // TODO: Handle error, loading and empty states\n\n return (\n <div\n ref={tableContainerRef}\n style={{\n position: \"relative\", // needed for sticky header\n height: \"100%\", // needed for scrolling\n overflow: \"auto\",\n cursor: table.getState().columnSizingInfo?.isResizingColumn\n ? \"col-resize\"\n : \"default\",\n userSelect: table.getState().columnSizingInfo?.isResizingColumn\n ? \"none\"\n : \"auto\",\n }}\n onScroll={handleScroll}\n >\n <table\n style={{ display: \"grid\" }}\n >\n <TableHeader table={table} />\n <TableBody\n rows={table.getRowModel().rows}\n tableContainerRef={tableContainerRef}\n onRowClick={onRowClick}\n rowHeight={rowHeight}\n renderCellContextMenu={renderCellContextMenu}\n />\n </table>\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,KAAK,IAAuBC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AACrE,SAASC,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,WAAW,QAAQ,kBAAkB;AAc9C,OAAO,SAASC,KAAKA,CACnB;EACEC,KAAK;EACLC,SAAS;EACTC,aAAa;EACbC,UAAU;EACVC,SAAS;EACTC;AACiB,CAAC,EACN;EACd,MAAMC,iBAAiB,GAAGV,MAAM,CAAiB,IAAI,CAAC;;EAEtD;EACA,MAAMW,WAAW,GAAGX,MAAM,CAAC,KAAK,CAAC;EAEjC,MAAMY,qBAAqB,GAAGb,WAAW,CACvC,MAAOc,mBAA2C,IAAK;IACrD,IAAIA,mBAAmB,IAAI,CAACF,WAAW,CAACG,OAAO,EAAE;MAC/C,MAAM;QAAEC,YAAY;QAAEC,SAAS;QAAEC;MAAa,CAAC,GAAGJ,mBAAmB;MACrE,IACEE,YAAY,GAAGC,SAAS,GAAGC,YAAY,GAAG,GAAG,IAC1C,CAACZ,SAAS,EACb;QACAM,WAAW,CAACG,OAAO,GAAG,IAAI;QAC1B,IAAI;UACF,MAAMR,aAAa,GAAG,CAAC;QACzB,CAAC,SAAS;UACRK,WAAW,CAACG,OAAO,GAAG,KAAK;QAC7B;MACF;IACF;EACF,CAAC,EACD,CAACR,aAAa,EAAED,SAAS,CAC3B,CAAC;EAED,MAAMa,YAAY,GAAGnB,WAAW,CAC9B,MAAOoB,CAAgC,IAAK;IAC1C,MAAMP,qBAAqB,CAACO,CAAC,CAACC,aAAa,CAAC;EAC9C,CAAC,EACD,CAACR,qBAAqB,CACxB,CAAC;;EAED;;EAEA,oBACEd,KAAA,CAAAuB,aAAA;IACEC,GAAG,EAAEZ,iBAAkB;IACvBa,KAAK,EAAE;MACLC,QAAQ,EAAE,UAAU;MAAE;MACtBC,MAAM,EAAE,MAAM;MAAE;MAChBC,QAAQ,EAAE,MAAM;MAChBC,MAAM,EAAEvB,KAAK,CAACwB,QAAQ,CAAC,CAAC,CAACC,gBAAgB,EAAEC,gBAAgB,GACvD,YAAY,GACZ,SAAS;MACbC,UAAU,EAAE3B,KAAK,CAACwB,QAAQ,CAAC,CAAC,CAACC,gBAAgB,EAAEC,gBAAgB,GAC3D,MAAM,GACN;IACN,CAAE;IACFE,QAAQ,EAAEd;EAAa,gBAEvBpB,KAAA,CAAAuB,aAAA;IACEE,KAAK,EAAE;MAAEU,OAAO,EAAE;IAAO;EAAE,gBAE3BnC,KAAA,CAAAuB,aAAA,CAACnB,WAAW;IAACE,KAAK,EAAEA;EAAM,CAAE,CAAC,eAC7BN,KAAA,CAAAuB,aAAA,CAACpB,SAAS;IACRiC,IAAI,EAAE9B,KAAK,CAAC+B,WAAW,CAAC,CAAC,CAACD,IAAK;IAC/BxB,iBAAiB,EAAEA,iBAAkB;IACrCH,UAAU,EAAEA,UAAW;IACvBC,SAAS,EAAEA,SAAU;IACrBC,qBAAqB,EAAEA;EAAsB,CAC9C,CACI,CACJ,CAAC;AAEV","ignoreList":[]}
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { useVirtualizer } from "@tanstack/react-virtual";
18
+ import React, { useLayoutEffect } from "react";
19
+ import { TableRow } from "./TableRow.js";
20
+ export function TableBody({
21
+ rows,
22
+ tableContainerRef,
23
+ onRowClick,
24
+ renderCellContextMenu,
25
+ rowHeight = 40
26
+ }) {
27
+ // Important: Keep the row virtualizer in the lowest component possible to avoid unnecessary re-renders.
28
+ const rowVirtualizer = useVirtualizer({
29
+ count: rows.length,
30
+ estimateSize: () => rowHeight,
31
+ getScrollElement: () => tableContainerRef.current,
32
+ overscan: 5
33
+ });
34
+
35
+ // Measure the virtualizer after the DOM has been laid out to ensure proper dimensions
36
+ useLayoutEffect(() => {
37
+ rowVirtualizer.measure();
38
+ }, [rowVirtualizer, rows.length]);
39
+ return /*#__PURE__*/React.createElement("tbody", {
40
+ style: {
41
+ display: "grid",
42
+ position: "relative",
43
+ height: `${rowVirtualizer.getTotalSize()}px`
44
+ }
45
+ }, rowVirtualizer.getVirtualItems().map(virtualRow => {
46
+ const row = rows[virtualRow.index];
47
+ return /*#__PURE__*/React.createElement(TableRow, {
48
+ key: row.id,
49
+ row: row,
50
+ virtualRow: virtualRow,
51
+ onRowClick: onRowClick,
52
+ renderCellContextMenu: renderCellContextMenu
53
+ });
54
+ }));
55
+ }
56
+ //# sourceMappingURL=TableBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableBody.js","names":["useVirtualizer","React","useLayoutEffect","TableRow","TableBody","rows","tableContainerRef","onRowClick","renderCellContextMenu","rowHeight","rowVirtualizer","count","length","estimateSize","getScrollElement","current","overscan","measure","createElement","style","display","position","height","getTotalSize","getVirtualItems","map","virtualRow","row","index","key","id"],"sources":["TableBody.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cell, Row, RowData } from \"@tanstack/react-table\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport React, { useLayoutEffect } from \"react\";\nimport { TableRow } from \"./TableRow.js\";\n\ninterface TableBodyProps<TData extends RowData> {\n rows: Array<Row<TData>>;\n tableContainerRef: React.RefObject<HTMLDivElement>;\n onRowClick?: (row: TData) => void;\n rowHeight?: number;\n renderCellContextMenu?: (\n row: TData,\n cell: Cell<TData, unknown>,\n ) => React.ReactNode;\n}\n\nexport function TableBody<TData extends RowData>({\n rows,\n tableContainerRef,\n onRowClick,\n renderCellContextMenu,\n rowHeight = 40,\n}: TableBodyProps<TData>): React.ReactElement {\n // Important: Keep the row virtualizer in the lowest component possible to avoid unnecessary re-renders.\n const rowVirtualizer = useVirtualizer<HTMLDivElement, HTMLTableRowElement>({\n count: rows.length,\n estimateSize: () => rowHeight,\n getScrollElement: () => tableContainerRef.current,\n overscan: 5,\n });\n\n // Measure the virtualizer after the DOM has been laid out to ensure proper dimensions\n useLayoutEffect(() => {\n rowVirtualizer.measure();\n }, [rowVirtualizer, rows.length]);\n\n return (\n <tbody\n style={{\n display: \"grid\",\n position: \"relative\",\n height: `${rowVirtualizer.getTotalSize()}px`,\n }}\n >\n {rowVirtualizer.getVirtualItems().map((virtualRow) => {\n const row = rows[virtualRow.index];\n\n return (\n <TableRow\n key={row.id}\n row={row}\n virtualRow={virtualRow}\n onRowClick={onRowClick}\n renderCellContextMenu={renderCellContextMenu}\n />\n );\n })}\n </tbody>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,cAAc,QAAQ,yBAAyB;AACxD,OAAOC,KAAK,IAAIC,eAAe,QAAQ,OAAO;AAC9C,SAASC,QAAQ,QAAQ,eAAe;AAaxC,OAAO,SAASC,SAASA,CAAwB;EAC/CC,IAAI;EACJC,iBAAiB;EACjBC,UAAU;EACVC,qBAAqB;EACrBC,SAAS,GAAG;AACS,CAAC,EAAsB;EAC5C;EACA,MAAMC,cAAc,GAAGV,cAAc,CAAsC;IACzEW,KAAK,EAAEN,IAAI,CAACO,MAAM;IAClBC,YAAY,EAAEA,CAAA,KAAMJ,SAAS;IAC7BK,gBAAgB,EAAEA,CAAA,KAAMR,iBAAiB,CAACS,OAAO;IACjDC,QAAQ,EAAE;EACZ,CAAC,CAAC;;EAEF;EACAd,eAAe,CAAC,MAAM;IACpBQ,cAAc,CAACO,OAAO,CAAC,CAAC;EAC1B,CAAC,EAAE,CAACP,cAAc,EAAEL,IAAI,CAACO,MAAM,CAAC,CAAC;EAEjC,oBACEX,KAAA,CAAAiB,aAAA;IACEC,KAAK,EAAE;MACLC,OAAO,EAAE,MAAM;MACfC,QAAQ,EAAE,UAAU;MACpBC,MAAM,EAAE,GAAGZ,cAAc,CAACa,YAAY,CAAC,CAAC;IAC1C;EAAE,GAEDb,cAAc,CAACc,eAAe,CAAC,CAAC,CAACC,GAAG,CAAEC,UAAU,IAAK;IACpD,MAAMC,GAAG,GAAGtB,IAAI,CAACqB,UAAU,CAACE,KAAK,CAAC;IAElC,oBACE3B,KAAA,CAAAiB,aAAA,CAACf,QAAQ;MACP0B,GAAG,EAAEF,GAAG,CAACG,EAAG;MACZH,GAAG,EAAEA,GAAI;MACTD,UAAU,EAAEA,UAAW;MACvBnB,UAAU,EAAEA,UAAW;MACvBC,qBAAqB,EAAEA;IAAsB,CAC9C,CAAC;EAEN,CAAC,CACI,CAAC;AAEZ","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { flexRender } from "@tanstack/react-table";
18
+ import React, { useRef } from "react";
19
+ import { CellContextMenu } from "./CellContextMenu.js";
20
+ import { useCellContextMenu } from "./hooks/useCellContextMenu.js";
21
+ import { SELECTION_COLUMN_ID } from "./hooks/useSelectionColumn.js";
22
+ export function TableCell({
23
+ cell,
24
+ renderCellContextMenu
25
+ }) {
26
+ const tdRef = useRef(null);
27
+ const isSelectColumn = cell.column.id === SELECTION_COLUMN_ID;
28
+ const {
29
+ isContextMenuOpen,
30
+ handleOpenContextMenu,
31
+ handleCloseContextMenu,
32
+ popoverPosition
33
+ } = useCellContextMenu({
34
+ tdRef
35
+ });
36
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("td", {
37
+ ref: tdRef,
38
+ style: {
39
+ display: "flex",
40
+ alignItems: "center",
41
+ width: cell.column.getSize()
42
+ },
43
+ onContextMenu: handleOpenContextMenu
44
+ }, flexRender(cell.column.columnDef.cell, cell.getContext())), !isSelectColumn && isContextMenuOpen && !!popoverPosition && !!renderCellContextMenu && /*#__PURE__*/React.createElement(CellContextMenu, {
45
+ cell: cell,
46
+ position: popoverPosition,
47
+ onClose: handleCloseContextMenu,
48
+ renderContent: renderCellContextMenu
49
+ }));
50
+ }
51
+ //# sourceMappingURL=TableCell.js.map