diff --git a/bzGraflow.js b/bzGraflow.js index 3682346..665faeb 100644 --- a/bzGraflow.js +++ b/bzGraflow.js @@ -109,24 +109,32 @@ class BZgraflow extends Buildoz{ } async loadFlow(source){ - let buf + let buf, flowObj if(source instanceof Blob){ buf = await source.text() - } else { + try{ + flowObj = JSON.parse(buf) + } catch(err){ + this.error('Could not parse flow JSON!?', err) + return + } + } else if(typeof source == 'string') { const url = source const fetchUrl = (typeof url === 'string' && !url.startsWith('blob:') && !url.startsWith('data:')) ? (url + '?' + crypto.randomUUID()) : url const res = await fetch(fetchUrl) buf = await res.text() + try{ + flowObj = JSON.parse(buf) + } catch(err){ + this.error('Could not parse flow JSON!?', err) + return + } + } else if(typeof source == 'object') { + flowObj = source } - let flowObj - try{ - flowObj = JSON.parse(buf) - } catch(err){ - this.error('Could not parse flow JSON!?', err) - return - } + if(!flowObj.nodesFile){ this.error('No nodesFile in JSON!?') return @@ -264,7 +272,7 @@ class BZgraflow extends Buildoz{ } } - childEl.autoPlace(this.currentOrientation, 60, 60) + childEl.autoPlace(this.currentOrientation, parseInt(this.getBZAttribute('gapx')) || 80, parseInt(this.getBZAttribute('gapy')) || 80) }, { once:true }) // Fade out the current (host) graflow while the child scales up @@ -442,11 +450,15 @@ class BZgraflow extends Buildoz{ this.addWire(link) } if(!this.currentOrientation) { - const bb=this.getBoundingClientRect() - if(bb.width > bb.height) this.currentOrientation = 'horizontal' - else this.currentOrientation = 'vertical' + if(this.getBZAttribute('orientation')) { + this.currentOrientation = this.getBZAttribute('orientation') + } else { + const bb=this.getBoundingClientRect() + if(bb.width > bb.height) this.currentOrientation = 'horizontal' + else this.currentOrientation = 'vertical' + } } - if(forceAutoplace) this.autoPlace(this.currentOrientation) + if(forceAutoplace) this.autoPlace(this.currentOrientation, parseInt(this.getBZAttribute('gapx')) || 80, parseInt(this.getBZAttribute('gapy')) || 80) this.fireEvent('refreshed', { }) }