Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMouseArgsForPosition ref API #961

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"@storybook/react": "^7.6.12",
"@storybook/react-vite": "^7.6.12",
"@storybook/react-webpack5": "^7.6.12",
"@testing-library/react": "^12.1.2",
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^16.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.1",
"@types/cheerio": "^0.22.30",
Expand Down Expand Up @@ -85,11 +86,12 @@
"marked": "^4.0.10",
"mini-css-extract-plugin": "^2.6.1",
"prettier": "^3.0.2",
"react": "^16.12.0 || 17.x",
"react-dom": "^16.12.0 || 17.x",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-laag": "^2.0.3",
"react-responsive-carousel": "^3.2.7",
"react-syntax-highlighter": "^15.4.5",
"react-test-renderer": "^18.3.1",
"resolve-typescript-plugin": "^2.0.1",
"storybook": "^7.6.12",
"tsc-esm-fix": "^2.7.8",
Expand Down
19 changes: 10 additions & 9 deletions packages/core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ Details of each property can be found by clicking on it.

## Ref Methods

| Name | Description |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [appendRow](#appendrow) | Append a row to the data grid. |
| [emit](#emit) | Used to emit commands normally emitted by keyboard shortcuts. |
| [focus](#focus) | Focuses the data grid. |
| [getBounds](#getbounds) | Gets the current screen-space bounds of a desired cell. |
| [remeasureColumns](#remeasureColumns) | Causes the columns in the selection to have their natural sizes recomputed and re-emitted as a resize event. |
| [scrollTo](#scrollto) | Tells the data-grid to scroll to a particular location. |
| [updateCells](#updatecells) | Invalidates the rendering of a list of passed cells. |
| Name | Description |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [appendRow](#appendrow) | Append a row to the data grid. |
| [emit](#emit) | Used to emit commands normally emitted by keyboard shortcuts. |
| [focus](#focus) | Focuses the data grid. |
| [getBounds](#getbounds) | Gets the current screen-space bounds of a desired cell. |
| [remeasureColumns](#remeasureColumns) | Causes the columns in the selection to have their natural sizes recomputed and re-emitted as a resize event. |
| [scrollTo](#scrollto) | Tells the data-grid to scroll to a particular location. |
| [updateCells](#updatecells) | Invalidates the rendering of a list of passed cells. |
| [getMouseArgsForPosition](#getMouseArgsForPosition) | Gets the mouse args from pointer event position. |

## Required Props

Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ export interface DataEditorRef {
* Causes the columns in the selection to have their natural size recomputed and re-emitted as a resize event.
*/
remeasureColumns: (cols: CompactSelection) => void;
/**
* Gets the mouse args from pointer event position.
*/
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent) => GridMouseEventArgs | undefined
}

const loadingCell: GridCell = {
Expand Down Expand Up @@ -3912,6 +3916,21 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
void normalSizeColumn(col + rowMarkerOffset);
}
},
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent): GridMouseEventArgs | undefined => {
if (gridRef?.current === null) {
return undefined;
}

const args = gridRef.current.getMouseArgsForPosition(posX, posY, ev);
if (args === undefined) {
return undefined;
}

return {
...args, // FIXME: Mutate
location: [args.location[0] - rowMarkerOffset, args.location[1]] as any,
};
}
}),
[appendRow, normalSizeColumn, scrollRef, onCopy, onKeyDown, onPasteInternal, rowMarkerOffset, scrollTo]
);
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/internal/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export interface DataGridRef {
focus: () => void;
getBounds: (col?: number, row?: number) => Rectangle | undefined;
damage: (cells: DamageUpdateList) => void;
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent) => GridMouseEventArgs | undefined;
}

const getRowData = (cell: InnerGridCell, getCellRenderer?: GetCellRendererCallback) => {
Expand Down Expand Up @@ -1708,6 +1709,13 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
return getBoundsForItem(canvasRef.current, col ?? 0, row ?? -1);
},
damage,
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent) => {
if (canvasRef === undefined || canvasRef.current === null) {
return undefined;
}

return getMouseArgsForPosition(canvasRef.current, posX, posY, ev);
}
}),
[canvasRef, damage, getBoundsForItem]
);
Expand Down
Loading