Compare commits

...

6 Commits

9 changed files with 47 additions and 13 deletions
+39 -5
View File
@@ -30,6 +30,7 @@ class BZgraflow extends Buildoz{
this.stagedNodes = { } this.stagedNodes = { }
this.stagedWires = { } this.stagedWires = { }
this.arrowDefs = null this.arrowDefs = null
this.arrowMarkerId = `arrow-${crypto.randomUUID()}`
this.currentOrientation = null this.currentOrientation = null
} }
@@ -98,6 +99,28 @@ class BZgraflow extends Buildoz{
else this.initFlow() else this.initFlow()
} }
static get observedAttributes(){
return([...super.observedAttributes, 'disabled'])
}
attributeChangedCallback(name, oldValue, newValue) {
super.attributeChangedCallback(name, oldValue, newValue)
if(name == 'disabled'){
if(newValue === null) {
this.disabled = false
this.style.opacity = 1
this.style.pointerEvents = 'auto'
} else {
this.disabled = true
this.style.opacity = 0.5
this.style.pointerEvents = 'none'
}
this.querySelectorAll('.bzgf-zoom-in, .bzgf-zoom-out').forEach((btn) => {
btn.disabled = this.disabled
})
}
}
error(msg, err){ error(msg, err){
this.querySelector('.graflow-error')?.remove() this.querySelector('.graflow-error')?.remove()
const errorEl = document.createElement('div') const errorEl = document.createElement('div')
@@ -142,7 +165,10 @@ class BZgraflow extends Buildoz{
await this.loadNodes(flowObj.nodesFile) await this.loadNodes(flowObj.nodesFile)
this.flow = flowObj.flow this.flow = flowObj.flow
this.refresh() this.refresh()
this.fireEvent('flowLoaded', { url: source instanceof Blob ? null : source, blob: source instanceof Blob ? source : null }) this.fireEvent('flowLoaded', {
parentNodeId: null,
component: this,
})
} }
initFlow(){ initFlow(){
@@ -159,6 +185,8 @@ class BZgraflow extends Buildoz{
for(const tpl of doc.querySelectorAll('template')){ for(const tpl of doc.querySelectorAll('template')){
if(tpl.id=='svg-arrows'){ if(tpl.id=='svg-arrows'){
this.arrowDefs = tpl.querySelector('defs').cloneNode(true) this.arrowDefs = tpl.querySelector('defs').cloneNode(true)
const defaultArrow = this.arrowDefs.querySelector('#arrow')
if(defaultArrow) defaultArrow.id = this.arrowMarkerId
this.wiresContainer.appendChild(this.arrowDefs) this.wiresContainer.appendChild(this.arrowDefs)
} else { } else {
const rootEl = tpl.content.querySelector('.bzgf-node') const rootEl = tpl.content.querySelector('.bzgf-node')
@@ -224,6 +252,7 @@ class BZgraflow extends Buildoz{
} }
enterSubflow(id){ enterSubflow(id){
if(this.disabled || this.hasAttribute('disabled')) return
const nodeEl = this.stagedNodes[id] const nodeEl = this.stagedNodes[id]
if(!nodeEl) return if(!nodeEl) return
@@ -325,7 +354,10 @@ class BZgraflow extends Buildoz{
childEl.style.transform = 'none' // Important for nested subflows to position correctly childEl.style.transform = 'none' // Important for nested subflows to position correctly
childEl.style.willChange = '' childEl.style.willChange = ''
childEl.style.overflow = 'auto' childEl.style.overflow = 'auto'
this.fireEvent('subflowLoaded', { parentNodeId: id, subflow: childEl }) this.fireEvent('subflowLoaded', {
parentNodeId: id,
component: childEl
})
}, { once:true }) }, { once:true })
} }
@@ -400,7 +432,9 @@ class BZgraflow extends Buildoz{
this.hostContainer.style.opacity = '1' this.hostContainer.style.opacity = '1'
this.hostContainer.style.visibility = 'visible' this.hostContainer.style.visibility = 'visible'
childEl.style.willChange = '' childEl.style.willChange = ''
this.fireEvent('subflowExited', { subflow: childEl }) this.fireEvent('subflowExited', {
component: this
})
}, { once:true }) }, { once:true })
} }
@@ -432,8 +466,8 @@ class BZgraflow extends Buildoz{
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path') this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
this.stagedWires[id].setAttribute('d', path) this.stagedWires[id].setAttribute('d', path)
this.stagedWires[id].setAttribute('fill', 'none') this.stagedWires[id].setAttribute('fill', 'none')
if(this.arrowDefs && link.endArrow) this.stagedWires[id].setAttribute('marker-end','url(#arrow)') if(this.arrowDefs && link.endArrow) this.stagedWires[id].setAttribute('marker-end',`url(#${this.arrowMarkerId})`)
if(this.arrowDefs && link.startArrow) this.stagedWires[id].setAttribute('marker-start','url(#arrow)') if(this.arrowDefs && link.startArrow) this.stagedWires[id].setAttribute('marker-start',`url(#${this.arrowMarkerId})`)
this.stagedWires[id].classList.add('bzgf-wire') this.stagedWires[id].classList.add('bzgf-wire')
this.stagedWires[id].dataset.id = id this.stagedWires[id].dataset.id = id
this.stagedWires[id].link = link this.stagedWires[id].link = link
+1 -1
View File
@@ -54,7 +54,7 @@
window.addEventListener('load',()=>{ window.addEventListener('load',()=>{
let grflw1 = document.querySelector('bz-graflow.compunet') let grflw1 = document.querySelector('bz-graflow.compunet')
grflw1.addEventListener('bz:graflow:subflowLoaded', grflw1.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw1 = evt.detail.subflow } (evt) => { grflw1 = evt.detail.component }
) )
grflw1.addEventListener('bz:graflow:subflowExited', grflw1.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw1 = evt.target } (evt) => { grflw1 = evt.target }
+1 -1
View File
@@ -54,7 +54,7 @@
window.addEventListener('load',()=>{ window.addEventListener('load',()=>{
let grflw3 = document.querySelector('bz-graflow.organi') let grflw3 = document.querySelector('bz-graflow.organi')
grflw3.addEventListener('bz:graflow:subflowLoaded', grflw3.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw3 = evt.detail.subflow } (evt) => { grflw3 = evt.detail.component }
) )
grflw3.addEventListener('bz:graflow:subflowExited', grflw3.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw3 = evt.target } (evt) => { grflw3 = evt.target }
+1 -1
View File
@@ -57,7 +57,7 @@
grflw2.setAttribute('align', document.querySelector('select[name="align"]').value) grflw2.setAttribute('align', document.querySelector('select[name="align"]').value)
grflw2.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value) grflw2.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value)
grflw2.addEventListener('bz:graflow:subflowLoaded', grflw2.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw2 = evt.detail.subflow } (evt) => { grflw2 = evt.detail.component }
) )
grflw2.addEventListener('bz:graflow:subflowExited', grflw2.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw2 = evt.target } (evt) => { grflw2 = evt.target }
+1 -1
View File
@@ -57,7 +57,7 @@
grflw4.setAttribute('align', document.querySelector('select[name="align"]').value) grflw4.setAttribute('align', document.querySelector('select[name="align"]').value)
grflw4.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value) grflw4.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value)
grflw4.addEventListener('bz:graflow:subflowLoaded', grflw4.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw4 = evt.detail.subflow } (evt) => { grflw4 = evt.detail.component }
) )
grflw4.addEventListener('bz:graflow:subflowExited', grflw4.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw4 = evt.target } (evt) => { grflw4 = evt.target }
+1 -1
View File
@@ -83,7 +83,7 @@
let grflw4 = document.querySelector('bz-graflow.icmp') let grflw4 = document.querySelector('bz-graflow.icmp')
grflw4.addEventListener('bz:graflow:subflowLoaded', grflw4.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw4 = evt.detail.subflow } (evt) => { grflw4 = evt.detail.component }
) )
grflw4.addEventListener('bz:graflow:subflowExited', grflw4.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw4 = evt.target } (evt) => { grflw4 = evt.target }
+1 -1
View File
@@ -54,7 +54,7 @@
window.addEventListener('load',()=>{ window.addEventListener('load',()=>{
let grflw1 = document.querySelector('bz-graflow.compunet') let grflw1 = document.querySelector('bz-graflow.compunet')
grflw1.addEventListener('bz:graflow:subflowLoaded', grflw1.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw1 = evt.detail.subflow } (evt) => { grflw1 = evt.detail.component }
) )
grflw1.addEventListener('bz:graflow:subflowExited', grflw1.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw1 = evt.target } (evt) => { grflw1 = evt.target }
+1 -1
View File
@@ -57,7 +57,7 @@
grflw1.setAttribute('align', document.querySelector('select[name="align"]').value) grflw1.setAttribute('align', document.querySelector('select[name="align"]').value)
grflw1.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value) grflw1.setAttribute('wiretype', document.querySelector('select[name="wiretype"]').value)
grflw1.addEventListener('bz:graflow:subflowLoaded', grflw1.addEventListener('bz:graflow:subflowLoaded',
(evt) => { grflw1 = evt.detail.subflow } (evt) => { grflw1 = evt.detail.component }
) )
grflw1.addEventListener('bz:graflow:subflowExited', grflw1.addEventListener('bz:graflow:subflowExited',
(evt) => { grflw1 = evt.target } (evt) => { grflw1 = evt.target }