@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.
- package/CHANGELOG.md +31 -0
- package/README.md +56 -6
- package/build/browser/object-table/CellContextMenu.js +48 -0
- package/build/browser/object-table/CellContextMenu.js.map +1 -0
- package/build/browser/object-table/ObjectTable.js +114 -0
- package/build/browser/object-table/ObjectTable.js.map +1 -0
- package/build/browser/object-table/ObjectTableApi.js.map +1 -1
- package/build/browser/object-table/SelectionCells.js +67 -0
- package/build/browser/object-table/SelectionCells.js.map +1 -0
- package/build/browser/object-table/Table.js +81 -0
- package/build/browser/object-table/Table.js.map +1 -0
- package/build/browser/object-table/TableBody.js +56 -0
- package/build/browser/object-table/TableBody.js.map +1 -0
- package/build/browser/object-table/TableCell.js +51 -0
- package/build/browser/object-table/TableCell.js.map +1 -0
- package/build/browser/object-table/TableHeader.js +63 -0
- package/build/browser/object-table/TableHeader.js.map +1 -0
- package/build/browser/object-table/TableRow.js +42 -0
- package/build/browser/object-table/TableRow.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
- package/build/browser/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
- package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
- package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js +229 -0
- package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
- package/build/browser/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
- package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
- package/build/browser/object-table/hooks/useCellContextMenu.js +48 -0
- package/build/browser/object-table/hooks/useCellContextMenu.js.map +1 -0
- package/build/browser/object-table/hooks/useColumnDefs.js +87 -0
- package/build/browser/object-table/hooks/useColumnDefs.js.map +1 -0
- package/build/browser/object-table/hooks/useDefaultTableStates.js +43 -0
- package/build/browser/object-table/hooks/useDefaultTableStates.js.map +1 -0
- package/build/browser/object-table/hooks/useObjectTableData.js +49 -0
- package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -0
- package/build/browser/object-table/hooks/useRowSelection.js +180 -0
- package/build/browser/object-table/hooks/useRowSelection.js.map +1 -0
- package/build/browser/object-table/hooks/useSelectionColumn.js +51 -0
- package/build/browser/object-table/hooks/useSelectionColumn.js.map +1 -0
- package/build/browser/{junk.test.js → object-table/utils/getRowId.js} +6 -8
- package/build/browser/object-table/utils/getRowId.js.map +1 -0
- package/build/browser/public/experimental.js +18 -1
- package/build/browser/public/experimental.js.map +1 -1
- package/build/cjs/public/experimental.cjs +4256 -0
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +39 -17
- package/build/esm/object-table/CellContextMenu.js +48 -0
- package/build/esm/object-table/CellContextMenu.js.map +1 -0
- package/build/esm/object-table/ObjectTable.js +114 -0
- package/build/esm/object-table/ObjectTable.js.map +1 -0
- package/build/esm/object-table/ObjectTableApi.js.map +1 -1
- package/build/esm/object-table/SelectionCells.js +67 -0
- package/build/esm/object-table/SelectionCells.js.map +1 -0
- package/build/esm/object-table/Table.js +81 -0
- package/build/esm/object-table/Table.js.map +1 -0
- package/build/esm/object-table/TableBody.js +56 -0
- package/build/esm/object-table/TableBody.js.map +1 -0
- package/build/esm/object-table/TableCell.js +51 -0
- package/build/esm/object-table/TableCell.js.map +1 -0
- package/build/esm/object-table/TableHeader.js +63 -0
- package/build/esm/object-table/TableHeader.js.map +1 -0
- package/build/esm/object-table/TableRow.js +42 -0
- package/build/esm/object-table/TableRow.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js +147 -0
- package/build/esm/object-table/hooks/__tests__/useCellContextMenu.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
- package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
- package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js +229 -0
- package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js +548 -0
- package/build/esm/object-table/hooks/__tests__/useRowSelection.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js +274 -0
- package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -0
- package/build/esm/object-table/hooks/useCellContextMenu.js +48 -0
- package/build/esm/object-table/hooks/useCellContextMenu.js.map +1 -0
- package/build/esm/object-table/hooks/useColumnDefs.js +87 -0
- package/build/esm/object-table/hooks/useColumnDefs.js.map +1 -0
- package/build/esm/object-table/hooks/useDefaultTableStates.js +43 -0
- package/build/esm/object-table/hooks/useDefaultTableStates.js.map +1 -0
- package/build/esm/object-table/hooks/useObjectTableData.js +49 -0
- package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -0
- package/build/esm/object-table/hooks/useRowSelection.js +180 -0
- package/build/esm/object-table/hooks/useRowSelection.js.map +1 -0
- package/build/esm/object-table/hooks/useSelectionColumn.js +51 -0
- package/build/esm/object-table/hooks/useSelectionColumn.js.map +1 -0
- package/build/esm/{junk.test.js → object-table/utils/getRowId.js} +6 -8
- package/build/esm/object-table/utils/getRowId.js.map +1 -0
- package/build/esm/public/experimental.js +18 -1
- package/build/esm/public/experimental.js.map +1 -1
- package/build/types/object-table/CellContextMenu.d.ts +11 -0
- package/build/types/object-table/CellContextMenu.d.ts.map +1 -0
- package/build/types/object-table/ObjectTable.d.ts +16 -0
- package/build/types/object-table/ObjectTable.d.ts.map +1 -0
- package/build/types/object-table/ObjectTableApi.d.ts +30 -20
- package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
- package/build/types/object-table/SelectionCells.d.ts +14 -0
- package/build/types/object-table/SelectionCells.d.ts.map +1 -0
- package/build/types/object-table/Table.d.ts +12 -0
- package/build/types/object-table/Table.d.ts.map +1 -0
- package/build/types/object-table/TableBody.d.ts +11 -0
- package/build/types/object-table/TableBody.d.ts.map +1 -0
- package/build/types/object-table/TableCell.d.ts +8 -0
- package/build/types/object-table/TableCell.d.ts.map +1 -0
- package/build/types/object-table/TableHeader.d.ts +7 -0
- package/build/types/object-table/TableHeader.d.ts.map +1 -0
- package/build/types/object-table/TableRow.d.ts +11 -0
- package/build/types/object-table/TableRow.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useCellContextMenu.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useColumnDefs.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useColumnDefs.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useRowSelection.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useSelectionColumn.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/useCellContextMenu.d.ts +17 -0
- package/build/types/object-table/hooks/useCellContextMenu.d.ts.map +1 -0
- package/build/types/object-table/hooks/useColumnDefs.d.ts +20 -0
- package/build/types/object-table/hooks/useColumnDefs.d.ts.map +1 -0
- package/build/types/object-table/hooks/useDefaultTableStates.d.ts +19 -0
- package/build/types/object-table/hooks/useDefaultTableStates.d.ts.map +1 -0
- package/build/types/object-table/hooks/useObjectTableData.d.ts +13 -0
- package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -0
- package/build/types/object-table/hooks/useRowSelection.d.ts +22 -0
- package/build/types/object-table/hooks/useRowSelection.d.ts.map +1 -0
- package/build/types/object-table/hooks/useSelectionColumn.d.ts +15 -0
- package/build/types/object-table/hooks/useSelectionColumn.d.ts.map +1 -0
- package/build/types/object-table/utils/getRowId.d.ts +6 -0
- package/build/types/object-table/utils/getRowId.d.ts.map +1 -0
- package/build/types/public/experimental.d.ts +2 -1
- package/build/types/public/experimental.d.ts.map +1 -1
- package/package.json +11 -4
- package/build/browser/junk.test.js.map +0 -1
- package/build/esm/junk.test.js.map +0 -1
- package/build/types/junk.test.d.ts.map +0 -1
- /package/build/types/{junk.test.d.ts → object-table/hooks/__tests__/useCellContextMenu.test.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @osdk/react-components
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9c9fb9b: Row selection, column resize, filter clause
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [6b27d8a]
|
|
12
|
+
- Updated dependencies [ba3159c]
|
|
13
|
+
- Updated dependencies [0395d4b]
|
|
14
|
+
- @osdk/client@2.7.0-beta.9
|
|
15
|
+
- @osdk/react@0.9.0-beta.6
|
|
16
|
+
- @osdk/api@2.7.0-beta.9
|
|
17
|
+
|
|
18
|
+
## 0.1.0-beta.1
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 139913d: ObjectTable first impl
|
|
23
|
+
- 800103e: Update README
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [c9ca08d]
|
|
28
|
+
- Updated dependencies [c332598]
|
|
29
|
+
- Updated dependencies [0b2cd91]
|
|
30
|
+
- @osdk/api@2.7.0-beta.6
|
|
31
|
+
- @osdk/client@2.7.0-beta.6
|
|
32
|
+
- @osdk/react@0.9.0-beta.4
|
|
33
|
+
|
|
3
34
|
## 0.1.0-beta.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,17 +1,67 @@
|
|
|
1
1
|
# @osdk/react-components
|
|
2
2
|
|
|
3
|
-
React components
|
|
3
|
+
React components for building Foundry applications. These components are Ontology-aware — pass in OSDK entities, and they handle data loading, caching, and state management automatically.
|
|
4
|
+
|
|
5
|
+
Built on top of [@osdk/react](../react), these components use OSDK hooks internally to provide ready-to-use UI elements. While @osdk/react gives you low-level hooks for data fetching, @osdk/react-components provides UI widgets for common patterns like tables and forms.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
|
-
npm install @osdk/react-components
|
|
10
|
+
npm install @osdk/react-components @osdk/react
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
**Prerequisites:**
|
|
14
|
+
|
|
15
|
+
- React 18
|
|
16
|
+
- A configured OSDK client
|
|
17
|
+
- An OsdkProvider wrapping your application
|
|
18
|
+
|
|
19
|
+
## Components
|
|
20
|
+
|
|
21
|
+
> **Note:** This package is under active development. Not all components listed below are available yet.
|
|
22
|
+
|
|
23
|
+
The components that this package will provide are:
|
|
24
|
+
|
|
25
|
+
| Component | Description |
|
|
26
|
+
| ------------- | ---------------------------------------------------------------------------------- |
|
|
27
|
+
| `ObjectTable` | Displays an Object Set as a sortable, paginated table |
|
|
28
|
+
| `FilterList` | Visualize a high-level summary of objects data to allow users to filter that data. |
|
|
29
|
+
| `ActionForm` | Auto-generated form for executing Ontology Actions |
|
|
30
|
+
|
|
31
|
+
## Example Usage
|
|
32
|
+
|
|
33
|
+
### Object Table
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { ObjectTable } from "@osdk/react-components";
|
|
37
|
+
import { $, Employee } from "@your-osdk-package";
|
|
12
38
|
|
|
13
|
-
|
|
39
|
+
function EmployeeDirectory() {
|
|
40
|
+
const employeeObjectSet = $(Employee).where({ department: "Engineering" });
|
|
14
41
|
|
|
15
|
-
|
|
16
|
-
|
|
42
|
+
return (
|
|
43
|
+
<ObjectTable
|
|
44
|
+
objectSet={employeeObjectSet}
|
|
45
|
+
objectType={Employee}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
17
49
|
```
|
|
50
|
+
|
|
51
|
+
## Why this package?
|
|
52
|
+
|
|
53
|
+
**OSDK-native.** These components understand Foundry concepts like Objects, Object Sets, and Actions. They are purpose-built for Ontology data.
|
|
54
|
+
|
|
55
|
+
**Best practices included.** Loading states, error handling, caching, and data freshness are handled for you — no need to reimplement these patterns for each component.
|
|
56
|
+
|
|
57
|
+
**Fully customizable.** Supports custom styling for any design system.
|
|
58
|
+
|
|
59
|
+
## What this package is (and isn't)
|
|
60
|
+
|
|
61
|
+
**Included:** Components that consume OSDK entities directly — tables, forms, filtering patterns.
|
|
62
|
+
|
|
63
|
+
**Not included:** Generic UI primitives (buttons, inputs, modals). Use [Blueprint.js](blueprintjs.com) or your preferred component library for those.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
Apache 2.0
|
|
@@ -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<{}
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableCell.js","names":["flexRender","React","useRef","CellContextMenu","useCellContextMenu","SELECTION_COLUMN_ID","TableCell","cell","renderCellContextMenu","tdRef","isSelectColumn","column","id","isContextMenuOpen","handleOpenContextMenu","handleCloseContextMenu","popoverPosition","createElement","Fragment","ref","style","display","alignItems","width","getSize","onContextMenu","columnDef","getContext","position","onClose","renderContent"],"sources":["TableCell.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 { flexRender } from \"@tanstack/react-table\";\nimport React, { useRef } from \"react\";\nimport { CellContextMenu } from \"./CellContextMenu.js\";\nimport { useCellContextMenu } from \"./hooks/useCellContextMenu.js\";\nimport { SELECTION_COLUMN_ID } from \"./hooks/useSelectionColumn.js\";\n\ninterface TableCellProps<TData extends RowData> {\n cell: Cell<TData, unknown>;\n renderCellContextMenu?: (\n row: TData,\n cell: Cell<TData, unknown>,\n ) => React.ReactNode;\n}\n\nexport function TableCell<TData extends RowData>(\n { cell, renderCellContextMenu }: TableCellProps<TData>,\n): React.ReactElement {\n const tdRef = useRef<HTMLTableCellElement>(null);\n const isSelectColumn = cell.column.id === SELECTION_COLUMN_ID;\n\n const {\n isContextMenuOpen,\n handleOpenContextMenu,\n handleCloseContextMenu,\n popoverPosition,\n } = useCellContextMenu({\n tdRef,\n });\n\n const shouldRenderContextMenu = !isSelectColumn && isContextMenuOpen\n && !!popoverPosition\n && !!renderCellContextMenu;\n\n return (\n <>\n <td\n ref={tdRef}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n width: cell.column.getSize(),\n }}\n onContextMenu={handleOpenContextMenu}\n >\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </td>\n {shouldRenderContextMenu\n && (\n <CellContextMenu\n cell={cell}\n position={popoverPosition}\n onClose={handleCloseContextMenu}\n renderContent={renderCellContextMenu}\n />\n )}\n </>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,OAAOC,KAAK,IAAIC,MAAM,QAAQ,OAAO;AACrC,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,mBAAmB,QAAQ,+BAA+B;AAUnE,OAAO,SAASC,SAASA,CACvB;EAAEC,IAAI;EAAEC;AAA6C,CAAC,EAClC;EACpB,MAAMC,KAAK,GAAGP,MAAM,CAAuB,IAAI,CAAC;EAChD,MAAMQ,cAAc,GAAGH,IAAI,CAACI,MAAM,CAACC,EAAE,KAAKP,mBAAmB;EAE7D,MAAM;IACJQ,iBAAiB;IACjBC,qBAAqB;IACrBC,sBAAsB;IACtBC;EACF,CAAC,GAAGZ,kBAAkB,CAAC;IACrBK;EACF,CAAC,CAAC;EAMF,oBACER,KAAA,CAAAgB,aAAA,CAAAhB,KAAA,CAAAiB,QAAA,qBACEjB,KAAA,CAAAgB,aAAA;IACEE,GAAG,EAAEV,KAAM;IACXW,KAAK,EAAE;MACLC,OAAO,EAAE,MAAM;MACfC,UAAU,EAAE,QAAQ;MACpBC,KAAK,EAAEhB,IAAI,CAACI,MAAM,CAACa,OAAO,CAAC;IAC7B,CAAE;IACFC,aAAa,EAAEX;EAAsB,GAEpCd,UAAU,CAACO,IAAI,CAACI,MAAM,CAACe,SAAS,CAACnB,IAAI,EAAEA,IAAI,CAACoB,UAAU,CAAC,CAAC,CACvD,CAAC,EAhBuB,CAACjB,cAAc,IAAIG,iBAAiB,IAC/D,CAAC,CAACG,eAAe,IACjB,CAAC,CAACR,qBAAqB,iBAiBpBP,KAAA,CAAAgB,aAAA,CAACd,eAAe;IACdI,IAAI,EAAEA,IAAK;IACXqB,QAAQ,EAAEZ,eAAgB;IAC1Ba,OAAO,EAAEd,sBAAuB;IAChCe,aAAa,EAAEtB;EAAsB,CACtC,CAEL,CAAC;AAEP","ignoreList":[]}
|