Skip to content

Commit

Permalink
getMouseArgsForPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHung authored Jun 10, 2024
1 parent 5983dca commit 8c5821c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
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
15 changes: 15 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
}

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

const args = gridRef.current.getMouseArgsForPosition(posX, posY, ev);
return {
...args, // FIXME: Mutate
location: [args.location[0] - rowMarkerOffset, args.location[1]] as any,
};
}
}),
[appendRow, normalSizeColumn, scrollRef, onCopy, onKeyDown, onPasteInternal, rowMarkerOffset, scrollTo]
);
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/internal/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,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

0 comments on commit 8c5821c

Please sign in to comment.