@@ -26,6 +26,16 @@ const Messaging = (props) => {
26
26
setAttachFile ( null ) ;
27
27
} ;
28
28
29
+ const getPastedImage = ( ev ) => {
30
+ const { items } = ev . clipboardData ;
31
+ for ( let i = 0 ; i < items . length ; i += 1 ) {
32
+ if ( items [ i ] . type . indexOf ( "image" ) !== - 1 ) {
33
+ return items [ i ] . getAsFile ( ) ;
34
+ }
35
+ }
36
+ return null ;
37
+ } ;
38
+
29
39
return (
30
40
< >
31
41
{ subscription && (
@@ -35,6 +45,7 @@ const Messaging = (props) => {
35
45
onMessageChange = { setMessage }
36
46
onFilePasted = { setAttachFile }
37
47
onOpenDialogClick = { handleOpenDialogClick }
48
+ getPastedImage = { getPastedImage }
38
49
/>
39
50
) }
40
51
< PublishDialog
@@ -44,6 +55,7 @@ const Messaging = (props) => {
44
55
topic = { subscription ?. topic ?? "" }
45
56
message = { message }
46
57
attachFile = { attachFile }
58
+ getPastedImage = { getPastedImage }
47
59
onClose = { handleDialogClose }
48
60
onDragEnter = { ( ) => props . onDialogOpenModeChange ( ( prev ) => prev || PublishDialog . OPEN_MODE_DRAG ) } // Only update if not already open
49
61
onResetOpenMode = { ( ) => props . onDialogOpenModeChange ( PublishDialog . OPEN_MODE_DEFAULT ) }
@@ -67,15 +79,10 @@ const MessageBar = (props) => {
67
79
} ;
68
80
69
81
const handlePaste = ( ev ) => {
70
- const clipboardData = ev . clipboardData || window . clipboardData ;
71
- const { items } = clipboardData ;
72
- for ( let i = 0 ; i < items . length ; i += 1 ) {
73
- if ( items [ i ] . type . indexOf ( "image" ) !== - 1 ) {
74
- const blob = items [ i ] . getAsFile ( ) ;
75
- props . onFilePasted ( blob ) ;
76
- props . onOpenDialogClick ( ) ;
77
- break ;
78
- }
82
+ const blob = props . getPastedImage ( ev ) ;
83
+ if ( blob ) {
84
+ props . onFilePasted ( blob ) ;
85
+ props . onOpenDialogClick ( ) ;
79
86
}
80
87
} ;
81
88
0 commit comments