11/** @jsx jsx */
22/** @jsxRuntime classic */
33import { jsx , css } from '@emotion/react' ;
4- import React from 'react' ;
5- import { useRecoilState , useRecoilValue , useSetRecoilState } from 'recoil' ;
4+ import React , { useRef } from 'react' ;
5+ import { useRecoilState , useRecoilValue } from 'recoil' ;
66
77import { BlockContent } from '@atoms/index' ;
88import { BlockHandler , HoverArea } from '@components/molecules' ;
@@ -12,7 +12,6 @@ import {
1212 focusState ,
1313 blockRefState ,
1414 blockMapState ,
15- draggingBlockState ,
1615} from '@stores/page' ;
1716
1817const isGridOrColumn = ( block : Block ) : boolean =>
@@ -45,18 +44,10 @@ function BlockComponent({ blockDTO }: Props): JSX.Element {
4544 const [ focusId , setFocusId ] = useRecoilState < string > ( focusState ) ;
4645 const [ hoverId , setHoverId ] = useRecoilState ( hoverState ) ;
4746 const blockRef : any = blockRefState [ blockDTO . id ] ;
48- const setDraggingBlock = useSetRecoilState ( draggingBlockState ) ;
49-
50- const dragStartHandler = ( event : React . DragEvent < HTMLDivElement > ) => {
51- event . dataTransfer . effectAllowed = 'move' ;
52- event . dataTransfer . dropEffect = 'move' ;
53- event . dataTransfer . setData ( 'text/html' , event . currentTarget . innerHTML ) ;
54-
55- setDraggingBlock ( blockDTO ) ;
56- } ;
47+ const blockComponentRef = useRef ( null ) ;
5748
5849 return (
59- < div css = { blockCss } draggable = "true" onDragStart = { dragStartHandler } >
50+ < div css = { blockCss } ref = { blockComponentRef } >
6051 < div
6152 css = { { position : 'relative' } }
6253 onMouseEnter = { ( ) => setHoverId ( blockDTO . id ) }
@@ -67,7 +58,12 @@ function BlockComponent({ blockDTO }: Props): JSX.Element {
6758 >
6859 < BlockContent { ...blockDTO } />
6960 < HoverArea clickHandler = { ( ) => blockRef . current . focus ( ) } />
70- { hoverId === blockDTO . id && < BlockHandler /> }
61+ { hoverId === blockDTO . id && (
62+ < BlockHandler
63+ blockDTO = { blockDTO }
64+ blockComponentRef = { blockComponentRef }
65+ />
66+ ) }
7167 </ div >
7268 { blockDTO . childIdList . length ? (
7369 < div css = { descendantsCss ( blockDTO ) } >
0 commit comments