@@ -39,6 +39,7 @@ import {
3939 transformCoordToPoint ,
4040 getCellRangeValue ,
4141 getCellValue ,
42+ shouldHandleClipboardEvent ,
4243} from "./util" ;
4344import "./Spreadsheet.css" ;
4445
@@ -286,42 +287,33 @@ const Spreadsheet = <CellType extends Types.CellBase>(
286287 [ store ]
287288 ) ;
288289
289- const isFocused = React . useCallback ( ( ) => {
290- const root = rootRef . current ;
291- const { activeElement } = document ;
292-
293- return mode === "view" && root
294- ? root === activeElement || root . contains ( activeElement )
295- : false ;
296- } , [ rootRef , mode ] ) ;
297-
298290 const handleCut = React . useCallback (
299291 ( event : ClipboardEvent ) => {
300- if ( isFocused ( ) ) {
292+ if ( shouldHandleClipboardEvent ( rootRef . current , mode ) ) {
301293 event . preventDefault ( ) ;
302294 event . stopPropagation ( ) ;
303295 clip ( event ) ;
304296 cut ( ) ;
305297 }
306298 } ,
307- [ isFocused , clip , cut ]
299+ [ mode , clip , cut ]
308300 ) ;
309301
310302 const handleCopy = React . useCallback (
311303 ( event : ClipboardEvent ) => {
312- if ( isFocused ( ) ) {
304+ if ( shouldHandleClipboardEvent ( rootRef . current , mode ) ) {
313305 event . preventDefault ( ) ;
314306 event . stopPropagation ( ) ;
315307 clip ( event ) ;
316308 copy ( ) ;
317309 }
318310 } ,
319- [ isFocused , clip , copy ]
311+ [ mode , clip , copy ]
320312 ) ;
321313
322314 const handlePaste = React . useCallback (
323- async ( event : ClipboardEvent ) => {
324- if ( mode === "view" && isFocused ( ) ) {
315+ ( event : ClipboardEvent ) => {
316+ if ( shouldHandleClipboardEvent ( rootRef . current , mode ) ) {
325317 event . preventDefault ( ) ;
326318 event . stopPropagation ( ) ;
327319 if ( event . clipboardData ) {
@@ -330,7 +322,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
330322 }
331323 }
332324 } ,
333- [ mode , isFocused , paste ]
325+ [ mode , paste ]
334326 ) ;
335327
336328 const handleKeyDown = React . useCallback (
0 commit comments