@@ -705,9 +705,6 @@ class Handler implements HandlerOptions {
705705 if ( obj . superType === 'link' ) {
706706 return this . linkHandler . create ( newOption , loaded ) ;
707707 }
708- if ( obj . type === 'svg' ) {
709- return this . addSVG ( newOption , centered , loaded ) ;
710- }
711708 let createdObj ;
712709 // Create canvas object
713710 if ( obj . type === 'image' ) {
@@ -800,51 +797,6 @@ class Handler implements HandlerOptions {
800797 return createdObj ;
801798 } ;
802799
803- /**
804- * Add svg object
805- * @param {* } obj
806- * @param {boolean } [centered=true]
807- * @param {boolean } [loaded=false]
808- * @returns
809- */
810- public addSVG = ( obj : any , centered = true , loaded = false ) => {
811- const { objectOption } = this ;
812- return new Promise ( ( resolve : any ) => {
813- const getSVGElements = ( object : any , objects : any , options : any ) => {
814- const createdObj = fabric . util . groupSVGElements ( objects , options ) as FabricObject ;
815- createdObj . set ( { ...objectOption , ...object } ) ;
816- this . canvas . add ( createdObj ) ;
817- this . objects = this . getObjects ( ) ;
818- const { onAdd, editable } = this ;
819- if ( ! editable && ! ( obj . superType === 'element' ) ) {
820- createdObj . on ( 'mousedown' , this . eventHandler . object . mousedown ) ;
821- }
822- if ( createdObj . dblclick ) {
823- createdObj . on ( 'mousedblclick' , this . eventHandler . object . mousedblclick ) ;
824- }
825- if ( editable && ! loaded ) {
826- this . centerObject ( createdObj , centered ) ;
827- }
828- if ( ! editable && createdObj . animation && createdObj . animation . autoplay ) {
829- this . animationHandler . play ( createdObj . id ) ;
830- }
831- if ( onAdd && ! loaded && editable ) {
832- onAdd ( createdObj ) ;
833- }
834- return createdObj ;
835- } ;
836- if ( obj . loadType === 'svg' ) {
837- fabric . loadSVGFromString ( obj . svg , ( objects , options ) => {
838- resolve ( getSVGElements ( obj , objects , options ) ) ;
839- } ) ;
840- } else {
841- fabric . loadSVGFromURL ( obj . svg , ( objects , options ) => {
842- resolve ( getSVGElements ( obj , objects , options ) ) ;
843- } ) ;
844- }
845- } ) ;
846- } ;
847-
848800 /**
849801 * Remove object
850802 * @param {FabricObject } target
@@ -1148,7 +1100,7 @@ class Handler implements HandlerOptions {
11481100 return true ;
11491101 }
11501102 }
1151- activeObject . clone ( ( cloned : any ) => {
1103+ activeObject . clone ( ( cloned : FabricObject ) => {
11521104 if ( this . keyEvent . clipboard ) {
11531105 if ( cloned . superType === 'node' ) {
11541106 const node = {
@@ -1166,12 +1118,12 @@ class Handler implements HandlerOptions {
11661118 } ;
11671119 const objects = [ node ] ;
11681120 this . copyToClipboard ( JSON . stringify ( objects , null , '\t' ) ) ;
1169- return ;
1121+ } else {
1122+ this . copyToClipboard ( JSON . stringify ( cloned . toObject ( propertiesToInclude ) , null , '\t' ) ) ;
11701123 }
1171- this . copyToClipboard ( JSON . stringify ( cloned . toObject ( propertiesToInclude ) , null , '\t' ) ) ;
1172- return ;
1124+ } else {
1125+ this . clipboard = cloned ;
11731126 }
1174- this . clipboard = cloned ;
11751127 } , propertiesToInclude ) ;
11761128 }
11771129 return true ;
@@ -1269,11 +1221,11 @@ class Handler implements HandlerOptions {
12691221 } else {
12701222 this . clipboard = activeSelection ;
12711223 }
1272- this . canvas . setActiveObject ( activeSelection ) ;
1273- this . canvas . renderAll ( ) ;
12741224 if ( ! this . transactionHandler . active ) {
12751225 this . transactionHandler . save ( 'paste' ) ;
12761226 }
1227+ this . canvas . setActiveObject ( activeSelection ) ;
1228+ this . canvas . renderAll ( ) ;
12771229 return true ;
12781230 }
12791231 }
@@ -1282,7 +1234,7 @@ class Handler implements HandlerOptions {
12821234 clonedObj . set ( {
12831235 left : clonedObj . left + padding ,
12841236 top : clonedObj . top + padding ,
1285- id : isCut ? clonedObj . id : v4 ( ) ,
1237+ id : isCut ? clipboard . id : v4 ( ) ,
12861238 evented : true ,
12871239 } ) ;
12881240 if ( clonedObj . type === 'activeSelection' ) {
@@ -1293,12 +1245,7 @@ class Handler implements HandlerOptions {
12931245 if ( obj . dblclick ) {
12941246 obj . on ( 'mousedblclick' , this . eventHandler . object . mousedblclick ) ;
12951247 }
1296- this . objects = this . getObjects ( ) ;
12971248 } ) ;
1298- if ( onAdd ) {
1299- onAdd ( clonedObj ) ;
1300- }
1301- clonedObj . setCoords ( ) ;
13021249 } else {
13031250 if ( clonedObj . superType === 'node' ) {
13041251 clonedObj = clonedObj . duplicate ( ) ;
@@ -1307,10 +1254,6 @@ class Handler implements HandlerOptions {
13071254 if ( clonedObj . dblclick ) {
13081255 clonedObj . on ( 'mousedblclick' , this . eventHandler . object . mousedblclick ) ;
13091256 }
1310- this . objects = this . getObjects ( ) ;
1311- if ( onAdd ) {
1312- onAdd ( clonedObj ) ;
1313- }
13141257 }
13151258 const newClipboard = clipboard . set ( {
13161259 top : clonedObj . top ,
@@ -1321,12 +1264,21 @@ class Handler implements HandlerOptions {
13211264 } else {
13221265 this . clipboard = newClipboard ;
13231266 }
1324- this . canvas . setActiveObject ( clonedObj ) ;
1325- this . portHandler . create ( clonedObj ) ;
1326- this . canvas . requestRenderAll ( ) ;
1267+ if ( clonedObj . superType === 'node' ) {
1268+ this . portHandler . create ( clonedObj ) ;
1269+ }
13271270 if ( ! this . transactionHandler . active ) {
13281271 this . transactionHandler . save ( 'paste' ) ;
13291272 }
1273+ // TODO...
1274+ // After toGroup svg elements not rendered.
1275+ this . objects = this . getObjects ( ) ;
1276+ if ( onAdd ) {
1277+ onAdd ( clonedObj ) ;
1278+ }
1279+ clonedObj . setCoords ( ) ;
1280+ this . canvas . setActiveObject ( clonedObj ) ;
1281+ this . canvas . requestRenderAll ( ) ;
13301282 } , propertiesToInclude ) ;
13311283 return true ;
13321284 } ;
@@ -1594,6 +1546,7 @@ class Handler implements HandlerOptions {
15941546 this . add ( obj , false , true ) ;
15951547 this . canvas . renderAll ( ) ;
15961548 } ) ;
1549+ this . objects = this . getObjects ( ) ;
15971550 if ( callback ) {
15981551 callback ( this . canvas ) ;
15991552 }
@@ -1612,12 +1565,12 @@ class Handler implements HandlerOptions {
16121565 public toGroup = ( target ?: FabricObject ) => {
16131566 const activeObject = target || ( this . canvas . getActiveObject ( ) as fabric . ActiveSelection ) ;
16141567 if ( ! activeObject ) {
1615- return ;
1568+ return null ;
16161569 }
16171570 if ( activeObject . type !== 'activeSelection' ) {
1618- return ;
1571+ return null ;
16191572 }
1620- const group = activeObject . toGroup ( ) as any ;
1573+ const group = activeObject . toGroup ( ) as FabricObject < fabric . Group > ;
16211574 group . set ( {
16221575 id : v4 ( ) ,
16231576 name : 'New group' ,
0 commit comments