@@ -18,9 +18,6 @@ class ImageEditor extends Component {
1818 enableEditor : false
1919 } ;
2020
21- this . canvasData = null ;
22- this . cropBoxData = null ;
23- this . croppedData = null ;
2421 this . cropper = null ;
2522 }
2623
@@ -40,20 +37,6 @@ class ImageEditor extends Component {
4037 dragMode : 'move' ,
4138 background : false ,
4239
43- ready : ( ) => {
44- if ( this . croppedData ) {
45- this . cropper
46- . crop ( )
47- . setData ( this . croppedData )
48- . setCanvasData ( this . canvasData )
49- . setCropBoxData ( this . cropBoxData ) ;
50-
51- this . croppedData = null ;
52- this . canvasData = null ;
53- this . cropBoxData = null ;
54- }
55- } ,
56-
5740 crop : ( { detail } ) => {
5841 if ( detail . width > 0 && detail . height > 0 && ! this . state . cropping ) {
5942 this . update ( {
@@ -69,9 +52,6 @@ class ImageEditor extends Component {
6952 const { cropping, url, type } = this . state ;
7053
7154 if ( cropping ) {
72- this . croppedData = cropper . getData ( ) ;
73- this . canvasData = cropper . getCanvasData ( ) ;
74- this . cropBoxData = cropper . getCropBoxData ( ) ;
7555 this . update ( {
7656 cropped : true ,
7757 cropping : false ,
@@ -89,19 +69,13 @@ class ImageEditor extends Component {
8969 const { url, type } = this . state ;
9070
9171 if ( cropper ) {
92- this . croppedData = cropper . getData ( ) ;
93- this . canvasData = cropper . getCanvasData ( ) ;
94- this . cropBoxData = cropper . getCropBoxData ( ) ;
9572 this . update ( {
9673 previousUrl : url ,
9774 url : cropper . getCroppedCanvas ( type === 'image/png' ? { } : {
9875 fillColor : '#fff' ,
9976 } ) . toDataURL ( type ) ,
10077 } ) ;
10178 cropper . clear ( ) ;
102- this . canvasData = null ;
103- this . cropBoxData = null ;
104- this . croppedData = null ;
10579 }
10680 }
10781
@@ -138,21 +112,15 @@ class ImageEditor extends Component {
138112 } , ( ) => {
139113 if ( this . state . cropped ) {
140114 this . updateCropper ( ) ;
141- this . setState ( {
142- ...this . state ,
143- cropped : false ,
144- cropping : false
145- } )
115+ this . props . setMediaSource ( this . state . url ) ;
116+ this . props . onClose ( ) ;
146117 }
147118 } ) ;
148119 }
149120
150121 updateCropper = ( ) => {
151122 if ( this . cropper )
152123 this . cropper . destroy ( ) ;
153- this . canvasData = null ;
154- this . cropBoxData = null ;
155- this . croppedData = null ;
156124 this . cropper = null ;
157125 this . cropperSetup ( ) ;
158126 }
@@ -237,9 +205,12 @@ class ImageEditor extends Component {
237205 { this . state . enableEditor &&
238206 < div >
239207 < button onClick = { ( ) => {
208+ if ( this . state . cropping ) {
240209 this . crop ( ) ;
210+ } else {
241211 this . props . setMediaSource ( this . state . url ) ;
242212 this . props . onClose ( ) ;
213+ }
243214 } }
244215 id = 'save-button'
245216 className = "modal-save-button" >
0 commit comments