1
1
/** @jsx jsx */
2
2
/** @jsxRuntime classic */
3
- import { jsx , css , SerializedStyles } from '@emotion/react' ;
4
- import { useEffect , useRef , FormEvent , KeyboardEvent } from 'react' ;
3
+ import { jsx , css } from '@emotion/react' ;
4
+ import React , {
5
+ useEffect ,
6
+ useRef ,
7
+ FormEvent ,
8
+ KeyboardEvent ,
9
+ useState ,
10
+ } from 'react' ;
5
11
import { useRecoilState , useRecoilValue } from 'recoil' ;
6
12
7
13
import {
@@ -25,10 +31,11 @@ const isGridOrColumn = (block: Block): boolean =>
25
31
block . type === BlockType . GRID || block . type === BlockType . COLUMN ;
26
32
27
33
const blockContentCSS = css `
34
+ position : relative;
28
35
display : flex;
29
36
align-items : stretch;
30
37
` ;
31
- const editableDivCSS = ( block : Block ) : SerializedStyles => css `
38
+ const editableDivCSS = ( block : Block ) => css `
32
39
margin : 5 ;
33
40
font-size : ${ fontSize [ block . type ] } ;
34
41
display : ${ ! isGridOrColumn ( block ) ? 'flex' : 'none' } ;
@@ -55,6 +62,13 @@ const editableDivCSS = (block: Block): SerializedStyles => css`
55
62
cursor : text;
56
63
}
57
64
` ;
65
+ const dragOverCss = ( ) => css `
66
+ position : absolute;
67
+ bottom : 0 ;
68
+ width : 100% ;
69
+ height : 15% ;
70
+ background-color : rgba (80 , 188 , 223 , 0.7 );
71
+ ` ;
58
72
59
73
function BlockContent ( blockDTO : Block ) {
60
74
const contentEditableRef = useRef ( null ) ;
@@ -65,6 +79,7 @@ function BlockContent(blockDTO: Block) {
65
79
const [ Dispatcher ] = useCommand ( ) ;
66
80
const draggingBlock = useRecoilValue ( draggingBlockState ) ;
67
81
const [ { blockIndex } ] = useManager ( blockDTO . id ) ;
82
+ const [ dragOverToggle , setDragOverToggle ] = useState ( false ) ;
68
83
69
84
useEffect ( ( ) => {
70
85
blockRefState [ blockDTO . id ] = contentEditableRef ;
@@ -224,7 +239,16 @@ function BlockContent(blockDTO: Block) {
224
239
}
225
240
} , [ blockDTO . value ] ) ;
226
241
227
- const dropDraggingBlockHandler = async ( ) => {
242
+ const dragOverHandler = ( event : React . DragEvent < HTMLDivElement > ) => {
243
+ event . dataTransfer . dropEffect = 'move' ;
244
+
245
+ event . preventDefault ( ) ;
246
+ } ;
247
+
248
+ const dropHandler = async ( event : React . DragEvent < HTMLDivElement > ) => {
249
+ setDragOverToggle ( false ) ;
250
+ event . dataTransfer . dropEffect = 'move' ;
251
+
228
252
const blockId = draggingBlock ?. id ;
229
253
if ( ! blockId || blockId === blockDTO . id ) {
230
254
return ;
@@ -242,10 +266,18 @@ function BlockContent(blockDTO: Block) {
242
266
next [ to . id ] = to ;
243
267
return next ;
244
268
} ) ;
269
+
270
+ event . preventDefault ( ) ;
245
271
} ;
246
272
247
273
return (
248
- < div css = { blockContentCSS } onMouseUp = { dropDraggingBlockHandler } >
274
+ < div
275
+ css = { blockContentCSS }
276
+ onDragOver = { dragOverHandler }
277
+ onDrop = { dropHandler }
278
+ onDragEnter = { ( ) => setDragOverToggle ( true ) }
279
+ onDragLeave = { ( ) => setDragOverToggle ( false ) }
280
+ >
249
281
{ listBlockType ( blockDTO , listCnt . current ) }
250
282
< div
251
283
ref = { contentEditableRef }
@@ -259,6 +291,7 @@ function BlockContent(blockDTO: Block) {
259
291
>
260
292
{ blockDTO . value }
261
293
</ div >
294
+ { dragOverToggle && < div css = { dragOverCss ( ) } /> }
262
295
</ div >
263
296
) ;
264
297
}
0 commit comments