@@ -292,9 +292,6 @@ class Handler implements HandlerOptions {
292292 this . init ( options ) ;
293293 this . initCallback ( options ) ;
294294 this . initHandler ( options ) ;
295- if ( this . onLoad ) {
296- this . onLoad ( this , this . canvas ) ;
297- }
298295 }
299296
300297 /**
@@ -348,6 +345,7 @@ class Handler implements HandlerOptions {
348345 * @param {HandlerOptions } options
349346 */
350347 public initHandler = ( _options : HandlerOptions ) => {
348+ this . workareaHandler = new WorkareaHandler ( this ) ;
351349 this . imageHandler = new ImageHandler ( this ) ;
352350 this . chartHandler = new ChartHandler ( this ) ;
353351 this . elementHandler = new ElementHandler ( this ) ;
@@ -356,7 +354,6 @@ class Handler implements HandlerOptions {
356354 this . contextmenuHandler = new ContextmenuHandler ( this ) ;
357355 this . tooltipHandler = new TooltipHandler ( this ) ;
358356 this . zoomHandler = new ZoomHandler ( this ) ;
359- this . workareaHandler = new WorkareaHandler ( this ) ;
360357 this . interactionHandler = new InteractionHandler ( this ) ;
361358 this . transactionHandler = new TransactionHandler ( this ) ;
362359 this . gridHandler = new GridHandler ( this ) ;
@@ -580,7 +577,7 @@ class Handler implements HandlerOptions {
580577 * @param {(File | string) } [source]
581578 * @returns
582579 */
583- public setImage = ( obj : FabricImage , source ?: File | string ) => {
580+ public setImage = ( obj : FabricImage , source ?: File | string ) => {
584581 if ( ! source ) {
585582 this . loadImage ( obj , null ) ;
586583 obj . set ( 'file' , null ) ;
@@ -707,7 +704,9 @@ class Handler implements HandlerOptions {
707704 if ( obj . type === 'image' ) {
708705 createdObj = this . addImage ( newOption ) ;
709706 } else if ( obj . type === 'group' ) {
710- const objects = this . addGroup ( newOption , centered , loaded ) ;
707+ // TODO...
708+ // Group add function needs to be fixed
709+ const objects = this . addGroup ( newOption , centered , loaded , transaction ) ;
711710 const groupOption = Object . assign ( { } , newOption , { objects, name : 'New Group' } ) ;
712711 createdObj = this . fabricObjects [ obj . type ] . create ( groupOption ) ;
713712 } else {
@@ -762,9 +761,9 @@ class Handler implements HandlerOptions {
762761 * @param {boolean } [loaded=false]
763762 * @returns
764763 */
765- public addGroup = ( obj : FabricGroup , centered = true , loaded = false ) => {
764+ public addGroup = ( obj : FabricGroup , centered = true , loaded = false , transaction = true ) => {
766765 return obj . objects . map ( child => {
767- return this . add ( child , centered , loaded ) ;
766+ return this . add ( child , centered , loaded , transaction ) ;
768767 } ) ;
769768 } ;
770769
@@ -1535,7 +1534,7 @@ class Handler implements HandlerOptions {
15351534 * @param {* } json
15361535 * @param {(canvas: FabricCanvas) => void } [callback]
15371536 */
1538- public importJSON = ( json : any , callback ?: ( canvas : FabricCanvas ) => void ) => {
1537+ public importJSON = async ( json : any , callback ?: ( canvas : FabricCanvas ) => void ) => {
15391538 if ( typeof json === 'string' ) {
15401539 json = JSON . parse ( json ) ;
15411540 }
@@ -1556,42 +1555,39 @@ class Handler implements HandlerOptions {
15561555 prevLeft = workarea . left ;
15571556 prevTop = workarea . top ;
15581557 this . workarea . set ( workarea ) ;
1559- this . canvas . centerObject ( this . workarea ) ;
1560- this . workareaHandler . setImage ( workarea . src , true ) ;
1558+ await this . workareaHandler . setImage ( workarea . src , true ) ;
15611559 this . workarea . setCoords ( ) ;
15621560 }
1563- setTimeout ( ( ) => {
1564- json . forEach ( ( obj : FabricObjectOption ) => {
1565- if ( obj . id === 'workarea' ) {
1566- return ;
1567- }
1568- const canvasWidth = this . canvas . getWidth ( ) ;
1569- const canvasHeight = this . canvas . getHeight ( ) ;
1570- const { width, height, scaleX, scaleY, layout, left, top } = this . workarea ;
1571- if ( layout === 'fullscreen' ) {
1572- const leftRatio = canvasWidth / ( width * scaleX ) ;
1573- const topRatio = canvasHeight / ( height * scaleY ) ;
1574- obj . left *= leftRatio ;
1575- obj . top *= topRatio ;
1576- obj . scaleX *= leftRatio ;
1577- obj . scaleY *= topRatio ;
1578- } else {
1579- const diffLeft = left - prevLeft ;
1580- const diffTop = top - prevTop ;
1581- obj . left += diffLeft ;
1582- obj . top += diffTop ;
1583- }
1584- if ( obj . superType === 'element' ) {
1585- obj . id = v4 ( ) ;
1586- }
1587- this . add ( obj , false , true , false ) ;
1588- this . canvas . renderAll ( ) ;
1589- } ) ;
1590- if ( callback ) {
1591- callback ( this . canvas ) ;
1561+ json . forEach ( ( obj : FabricObjectOption ) => {
1562+ if ( obj . id === 'workarea' ) {
1563+ return ;
1564+ }
1565+ const canvasWidth = this . canvas . getWidth ( ) ;
1566+ const canvasHeight = this . canvas . getHeight ( ) ;
1567+ const { width, height, scaleX, scaleY, layout, left, top } = this . workarea ;
1568+ if ( layout === 'fullscreen' ) {
1569+ const leftRatio = canvasWidth / ( width * scaleX ) ;
1570+ const topRatio = canvasHeight / ( height * scaleY ) ;
1571+ obj . left *= leftRatio ;
1572+ obj . top *= topRatio ;
1573+ obj . scaleX *= leftRatio ;
1574+ obj . scaleY *= topRatio ;
1575+ } else {
1576+ const diffLeft = left - prevLeft ;
1577+ const diffTop = top - prevTop ;
1578+ obj . left += diffLeft ;
1579+ obj . top += diffTop ;
1580+ }
1581+ if ( obj . superType === 'element' ) {
1582+ obj . id = v4 ( ) ;
15921583 }
1593- } , 300 ) ;
1594- this . canvas . setZoom ( 1 ) ;
1584+ this . add ( obj , false , true , false ) ;
1585+ this . canvas . renderAll ( ) ;
1586+ } ) ;
1587+ if ( callback ) {
1588+ callback ( this . canvas ) ;
1589+ }
1590+ return Promise . resolve ( this . canvas ) ;
15951591 } ;
15961592
15971593 /**
0 commit comments