@@ -136,8 +136,8 @@ class SketchFieldDemo extends React.Component {
136136 canUndo : false ,
137137 canRedo : false ,
138138 controlledSize : false ,
139- sketchWidth : 800 ,
140- sketchHeight : 600 ,
139+ sketchWidth : ( window . innerWidth - 400 ) ,
140+ sketchHeight : ( window . innerHeight - 200 ) ,
141141 stretched : true ,
142142 stretchedX : false ,
143143 stretchedY : false ,
@@ -154,7 +154,9 @@ class SketchFieldDemo extends React.Component {
154154 enableCopyPaste : false ,
155155 isOpen : true ,
156156 dataJson : dataJson ,
157- url : dataUrl
157+ url : dataUrl ,
158+ maxHeight : ( window . innerHeight + 800 ) ,
159+ isCanvas : false
158160 } ;
159161 }
160162
@@ -191,6 +193,7 @@ class SketchFieldDemo extends React.Component {
191193 var url = canvas . backgroundImage . _element . src ;
192194 this . setState ( { url : url } )
193195 }
196+
194197 this . setState ( { isOpen : true , objects : objects } ) ;
195198 } ;
196199
@@ -360,19 +363,31 @@ class SketchFieldDemo extends React.Component {
360363 _addText = ( ) => this . _sketch . addText ( this . state . text ) ;
361364
362365 _readFile = ( event ) => {
363- let sketch = this . _sketch ;
364- let file = event . target . files [ 0 ]
366+
367+ this . _clear ( ) ;
368+ let file = event . target . files [ 0 ] ;
369+
365370 if ( file ) {
366371 let reader = new FileReader ( ) ;
367- reader . onload = function ( e ) {
368- let data = e . target . result ;
369- console . log ( data ) ;
370- sketch . fromJSON ( data ) ;
371- }
372+ reader . addEventListener (
373+ 'load' ,
374+ ( ) => this . _loadData ( reader . result ) , false ,
375+ ) ;
372376 reader . readAsText ( file ) ;
373377 }
374378 }
375379
380+ _loadData = ( data ) => {
381+ data = JSON . parse ( data ) ;
382+ this . setState ( { height : data . height , width : data . width } )
383+ let sketch = this . _sketch ;
384+ sketch . fromJSON ( data ) ;
385+ sketch . _backgroundColor ( data . backgroundColor ) ;
386+ if ( data . backImg ) {
387+ sketch . changeBackground ( data . backImg )
388+ }
389+ }
390+
376391 componentDidMount = ( ) => {
377392 ( function ( console ) {
378393 console . save = function ( data , filename ) {
@@ -449,6 +464,7 @@ class SketchFieldDemo extends React.Component {
449464 onClick = { this . _save } >
450465 < SaveIcon />
451466 </ IconButton >
467+
452468 < Button
453469 style = { { background : 'none' , border : 'none' , color : '#607d8b' , boxShadow : 'none' } }
454470 variant = "contained"
@@ -458,7 +474,7 @@ class SketchFieldDemo extends React.Component {
458474 < input type = "file"
459475 onChange = { ( e ) => this . _readFile ( e ) }
460476 style = { { display : "none" } } />
461- </ Button >
477+ </ Button >
462478 < IconButton
463479 color = "primary"
464480 title = "Download"
@@ -479,7 +495,6 @@ class SketchFieldDemo extends React.Component {
479495 < div className = "row" >
480496
481497 < div className = "col-xs-7 col-sm-7 col-md-9 col-lg-9" >
482-
483498 < SketchField
484499 name = "sketch"
485500 className = "canvas-area"
@@ -498,10 +513,10 @@ class SketchFieldDemo extends React.Component {
498513 : 'transparent'
499514 }
500515 width = {
501- this . state . controlledSize ? this . state . sketchWidth : null
516+ this . state . controlledSize ? this . state . sketchWidth : this . state . width
502517 }
503518 height = {
504- this . state . controlledSize ? this . state . sketchHeight : null
519+ this . state . controlledSize ? this . state . sketchHeight : this . state . height
505520 }
506521 defaultValue = { this . state . dataJson }
507522 value = { controlledValue }
@@ -510,6 +525,7 @@ class SketchFieldDemo extends React.Component {
510525 tool = { this . state . tool }
511526 />
512527 </ div >
528+
513529 < div className = "col-xs-5 col-sm-5 col-md-3 col-lg-3" >
514530 < Card style = { styles . card } >
515531 < CardHeader
0 commit comments