From 8ebde9ccfbbdf293bd05fcecc33576c611e90353 Mon Sep 17 00:00:00 2001 From: lukasmasuch Date: Thu, 5 Oct 2023 16:37:54 +0200 Subject: [PATCH 1/6] Support returning bounds of entire scroll area --- packages/core/src/data-editor/data-editor.tsx | 12 +++++++++++- packages/core/src/data-grid/data-grid.tsx | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 157dccdad..6d630ad29 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -3440,7 +3440,17 @@ const DataEditorImpl: React.ForwardRefRenderFunction { - return gridRef.current?.getBounds(col + rowMarkerOffset, row); + if (col === undefined && row === undefined && scrollRef.current && canvasRef.current) { + // Return the bounds of the entire scroll area: + const rect = canvasRef.current.getBoundingClientRect() + return { + x: rect.x - scrollRef.current.scrollLeft, + y: rect.y - scrollRef.current.scrollTop, + width: scrollRef.current.scrollWidth, + height: scrollRef.current.scrollHeight, + }; + } + return gridRef.current?.getBounds(col !== undefined ? col + rowMarkerOffset : undefined, row); }, focus: () => gridRef.current?.focus(), emit: async e => { diff --git a/packages/core/src/data-grid/data-grid.tsx b/packages/core/src/data-grid/data-grid.tsx index 85e3f5686..ff36b07f0 100644 --- a/packages/core/src/data-grid/data-grid.tsx +++ b/packages/core/src/data-grid/data-grid.tsx @@ -283,7 +283,7 @@ type DamageUpdateList = readonly { export interface DataGridRef { focus: () => void; - getBounds: (col: number, row?: number) => Rectangle | undefined; + getBounds: (col?: number, row?: number) => Rectangle | undefined; damage: (cells: DamageUpdateList) => void; } @@ -1499,12 +1499,12 @@ const DataGrid: React.ForwardRefRenderFunction = (p, }); } }, - getBounds: (col: number, row?: number) => { + getBounds: (col?: number, row?: number) => { if (canvasRef === undefined || canvasRef.current === null) { return undefined; } - return getBoundsForItem(canvasRef.current, col, row ?? -1); + return getBoundsForItem(canvasRef.current, col ?? 0, row ?? -1); }, damage, }), From be7055713aeccc66af8dd31cf59b3920df5f8b5c Mon Sep 17 00:00:00 2001 From: lukasmasuch Date: Thu, 5 Oct 2023 17:04:13 +0200 Subject: [PATCH 2/6] Add scale to calculation --- packages/core/src/data-editor/data-editor.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 6d630ad29..0b97a1b5d 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -3443,11 +3443,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction Date: Thu, 5 Oct 2023 18:53:18 +0200 Subject: [PATCH 3/6] Apply PR feedback --- packages/core/API.md | 4 ++-- packages/core/src/data-editor/data-editor.tsx | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/API.md b/packages/core/API.md index f24b41d12..99a03145a 100644 --- a/packages/core/API.md +++ b/packages/core/API.md @@ -368,10 +368,10 @@ Causes the data grid to rerender these specific cells. Rerendering a single cell ## getBounds ```ts -getBounds: (col: number, row?: number) => Rectangle | undefined; +getBounds: (col?: number, row?: number) => Rectangle | undefined; ``` -`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell. +`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell. If called with `col` and `row` as undefined, the bounds of the entire data grid scroll area are returned. --- diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 0b97a1b5d..8e6066092 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -3440,7 +3440,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction { - if (col === undefined && row === undefined && scrollRef.current && canvasRef.current) { + + if (canvasRef.current == undefined || scrollRef.current == undefined) { + return undefined + } + + if (col === undefined && row === undefined) { // Return the bounds of the entire scroll area: const rect = canvasRef.current.getBoundingClientRect() const scale = rect.width / scrollRef.current.clientWidth @@ -3451,7 +3456,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction gridRef.current?.focus(), emit: async e => { From bbdde7707d65094ea62f50c3915868323d787e01 Mon Sep 17 00:00:00 2001 From: lukasmasuch Date: Thu, 5 Oct 2023 18:56:18 +0200 Subject: [PATCH 4/6] Fix check --- packages/core/src/data-editor/data-editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 8e6066092..0edf4018c 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -3441,7 +3441,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction { - if (canvasRef.current == undefined || scrollRef.current == undefined) { + if (canvasRef.current === null || scrollRef.current === null) { return undefined } From 20c15d08b580e9e3e8f68a18c5abe7d7cf7b51ec Mon Sep 17 00:00:00 2001 From: lukasmasuch Date: Thu, 5 Oct 2023 18:57:40 +0200 Subject: [PATCH 5/6] Additional fix --- packages/core/src/data-editor/data-editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 0edf4018c..3ae8d71d8 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -3441,7 +3441,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction { - if (canvasRef.current === null || scrollRef.current === null) { + if (canvasRef?.current === null || scrollRef?.current === null) { return undefined } From 9f8c1ab22e782e2de44cf38ed81f43aefa1e037e Mon Sep 17 00:00:00 2001 From: lukasmasuch Date: Thu, 5 Oct 2023 18:59:26 +0200 Subject: [PATCH 6/6] Fix docs --- packages/core/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/API.md b/packages/core/API.md index 99a03145a..6012f1fe6 100644 --- a/packages/core/API.md +++ b/packages/core/API.md @@ -371,7 +371,7 @@ Causes the data grid to rerender these specific cells. Rerendering a single cell getBounds: (col?: number, row?: number) => Rectangle | undefined; ``` -`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell. If called with `col` and `row` as undefined, the bounds of the entire data grid scroll area are returned. +`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell. If called with `col` and `row` as undefined, the bounding box of the entire data grid scroll area is returned. ---