@@ -25,6 +25,12 @@ export class ImageContainer extends Component {
2525 dragEnabled : true ,
2626 dropzoneActive : false ,
2727 } ;
28+ this . fakeImageHandler = {
29+ cancel : ( ) => { } ,
30+ done : ( a , url ) => this . props . onImageUpload ( url ) ,
31+ fileChosen : ( ) => { } ,
32+ progress : ( ) => { } ,
33+ } ;
2834 }
2935
3036 componentDidMount ( ) {
@@ -39,12 +45,19 @@ export class ImageContainer extends Component {
3945 }
4046
4147 handleFileRead = ( file ) => {
42- const { onImageUpload } = this . props ;
48+ const { onImageUpload, insertImage } = this . props ;
4349 const reader = new FileReader ( ) ;
44- reader . onloadend = ( ) => {
45- onImageUpload ( reader . result ) ;
46- } ;
50+
51+ reader . onloadend = ( ) => onImageUpload ( reader . result ) ;
4752 reader . readAsDataURL ( file ) ;
53+
54+ if ( insertImage ) {
55+ insertImage ( {
56+ ...this . fakeImageHandler ,
57+ getChosenFile : ( ) => file ,
58+ isPasted : true ,
59+ } ) ;
60+ }
4861 } ;
4962
5063 handleUploadImage = ( e ) => {
@@ -89,7 +102,13 @@ export class ImageContainer extends Component {
89102
90103 handleEnableDrag = ( ) => this . setState ( { dragEnabled : true } ) ;
91104 handleDisableDrag = ( ) => this . setState ( { dragEnabled : false } ) ;
92- handleInputClick = ( ) => this . input . click ( ) ;
105+ handleInputClick = ( ) => {
106+ const { insertImage } = this . props ;
107+
108+ if ( insertImage ) {
109+ insertImage ( this . fakeImageHandler ) ;
110+ }
111+ } ;
93112
94113 handleOnImageLoad = ( { target : { offsetHeight, offsetWidth, naturalHeight, naturalWidth } } ) => {
95114 const { onUpdateImageDimension, imageDimensions } = this . props ;
@@ -295,6 +314,7 @@ ImageContainer.propTypes = {
295314 imageUrl : PropTypes . string . isRequired ,
296315 onImageUpload : PropTypes . func . isRequired ,
297316 onUpdateImageDimension : PropTypes . func . isRequired ,
317+ insertImage : PropTypes . func ,
298318} ;
299319
300320export default withStyles ( styles ) ( ImageContainer ) ;
0 commit comments