11import { extend } from 'tui-code-snippet' ;
22import Imagetracer from '@/helper/imagetracer' ;
33import { isSupportFileApi , base64ToBlob , toInteger , isEmptyCropzone } from '@/util' ;
4+ import { eventNames , historyNames } from '@/consts' ;
45
56export default {
67 /**
@@ -20,6 +21,7 @@ export default {
2021 draw : this . _drawAction ( ) ,
2122 icon : this . _iconAction ( ) ,
2223 filter : this . _filterAction ( ) ,
24+ history : this . _historyAction ( ) ,
2325 } ;
2426 } ,
2527
@@ -60,6 +62,7 @@ export default {
6062 this . ui . initializeImgUrl = imagePath ;
6163 this . ui . resizeEditor ( { imageSize : sizeValue } ) ;
6264 this . clearUndoStack ( ) ;
65+ this . _invoker . fire ( eventNames . EXECUTE_COMMAND , historyNames . LOAD_IMAGE ) ;
6366 } ) ,
6467 undo : ( ) => {
6568 if ( ! this . isEmptyUndoStack ( ) ) {
@@ -81,6 +84,7 @@ export default {
8184 exitCropOnAction ( ) ;
8285 this . ui . resizeEditor ( { imageSize : sizeValue } ) ;
8386 this . clearUndoStack ( ) ;
87+ this . _initHistory ( ) ;
8488 } ) ;
8589 } ,
8690 delete : ( ) => {
@@ -107,6 +111,8 @@ export default {
107111 this . clearUndoStack ( ) ;
108112 this . ui . activeMenuEvent ( ) ;
109113 this . ui . resizeEditor ( { imageSize : sizeValue } ) ;
114+ this . _clearHistory ( ) ;
115+ this . _invoker . fire ( eventNames . EXECUTE_COMMAND , historyNames . LOAD_IMAGE ) ;
110116 } )
111117 [ 'catch' ] ( ( message ) => Promise . reject ( message ) ) ;
112118 } ,
@@ -127,6 +133,9 @@ export default {
127133 w . document . body . innerHTML = `<img src='${ dataURL } '>` ;
128134 }
129135 } ,
136+ history : ( event ) => {
137+ this . ui . toggleHistoryMenu ( event ) ;
138+ } ,
130139 } ,
131140 this . _commonAction ( )
132141 ) ;
@@ -216,12 +225,14 @@ export default {
216225 _maskAction ( ) {
217226 return extend (
218227 {
219- loadImageFromURL : ( imgUrl , file ) =>
220- this . loadImageFromURL ( this . toDataURL ( ) , 'FilterImage' ) . then ( ( ) => {
228+ loadImageFromURL : ( imgUrl , file ) => {
229+ return this . loadImageFromURL ( this . toDataURL ( ) , 'FilterImage' ) . then ( ( ) => {
221230 this . addImageObject ( imgUrl ) . then ( ( ) => {
222231 URL . revokeObjectURL ( file ) ;
223232 } ) ;
224- } ) ,
233+ this . _invoker . fire ( eventNames . EXECUTE_COMMAND , historyNames . LOAD_MASK_IMAGE ) ;
234+ } ) ;
235+ } ,
225236 applyFilter : ( ) => {
226237 this . applyFilter ( 'mask' , {
227238 maskObjId : this . activeObjectId ,
@@ -310,6 +321,7 @@ export default {
310321 this . stopDrawingMode ( ) ;
311322 this . ui . resizeEditor ( ) ;
312323 this . ui . changeMenu ( 'crop' ) ;
324+ this . _invoker . fire ( eventNames . EXECUTE_COMMAND , historyNames . CROP ) ;
313325 } )
314326 [ 'catch' ] ( ( message ) => Promise . reject ( message ) ) ;
315327 }
@@ -493,6 +505,18 @@ export default {
493505 } ) ;
494506 } ,
495507
508+ /**
509+ * History Action
510+ * @returns {Object } history actions for ui
511+ * @private
512+ */
513+ _historyAction ( ) {
514+ return {
515+ undo : ( count ) => this . undo ( count ) ,
516+ redo : ( count ) => this . redo ( count ) ,
517+ } ;
518+ } ,
519+
496520 /**
497521 * Common Action
498522 * @returns {Object } common actions for ui
0 commit comments