3
3
import React from 'react' ;
4
4
5
5
import { cn , withRef } from '@udecode/cn' ;
6
- import { withHOC } from '@udecode/plate-common/react' ;
6
+ import { useEditorRef , withHOC } from '@udecode/plate-common/react' ;
7
+ import { useDraggable , useDraggableState } from '@udecode/plate-dnd' ;
7
8
import { Image , ImagePlugin , useMediaState } from '@udecode/plate-media/react' ;
8
9
import { ResizableProvider , useResizableStore } from '@udecode/plate-resizable' ;
9
10
@@ -20,10 +21,19 @@ export const ImageElement = withHOC(
20
21
ResizableProvider ,
21
22
withRef < typeof PlateElement > (
22
23
( { children, className, nodeProps, ...props } , ref ) => {
24
+ const editor = useEditorRef ( ) ;
25
+
23
26
const { align = 'center' , focused, readOnly, selected } = useMediaState ( ) ;
24
27
25
28
const width = useResizableStore ( ) . get . width ( ) ;
26
29
30
+ const state = editor . plugins . dnd
31
+ ? useDraggableState ( { element : props . element } )
32
+ : ( { } as any ) ;
33
+
34
+ const { isDragging } = state ;
35
+ const { handleRef } = useDraggable ( state ) ;
36
+
27
37
return (
28
38
< MediaPopover plugin = { ImagePlugin } >
29
39
< PlateElement
@@ -44,10 +54,12 @@ export const ImageElement = withHOC(
44
54
options = { { direction : 'left' } }
45
55
/>
46
56
< Image
57
+ ref = { handleRef }
47
58
className = { cn (
48
59
'block w-full max-w-full cursor-pointer object-cover px-0' ,
49
60
'rounded-sm' ,
50
- focused && selected && 'ring-2 ring-ring ring-offset-2'
61
+ focused && selected && 'ring-ring ring-2 ring-offset-2' ,
62
+ isDragging && 'opacity-50'
51
63
) }
52
64
alt = ""
53
65
{ ...nodeProps }
0 commit comments