bzselect now clean + KVview adapted

This commit is contained in:
STEINNI
2025-10-18 18:30:02 +00:00
parent 12e72f9c7f
commit e3ca6bd6b2
5 changed files with 62 additions and 60 deletions
File diff suppressed because one or more lines are too long
+47 -34
View File
@@ -29,42 +29,41 @@ class Buildoz extends HTMLElement {
} }
attributeChangedCallback(name, oldValue, newValue) {
this.attrs[name] = newValue
}
} }
class BZselect extends Buildoz { class BZselect extends Buildoz {
constructor(){ constructor(){
super() super()
this.value = null this.value = null
this.open = false this.open = false
//defaults, can be changed by corresponding attributes this.defaultAttrs = {
this.attrs = {
label: 'Select...', label: 'Select...',
} }
} }
connectedCallback() { connectedCallback() {
super.connectedCallback() super.connectedCallback()
this.button = document.createElement('button') this.button = document.createElement('button')
this.button.textContent = this.attrs.label this.button.textContent = this.getAttribute('label') || this.defaultAttrs.label
this.prepend(this.button) this.prepend(this.button)
this.button.addEventListener('click', this.toggle.bind(this)) this.button.addEventListener('click', this.toggle.bind(this))
this.options = this.querySelectorAll('option') this.options = this.querySelectorAll('option')
for(const opt of this.options){ for(const opt of this.options){
opt.addEventListener('click',(evt) => { this.onOption(evt.target.value) }) opt.addEventListener('click', this.onClick.bind(this))
if(opt.getAttribute('selected') !== null) this.onOption(opt.value, true)
} }
} }
static get observedAttributes(){ // static get observedAttributes(){ // Only if you want actions on attr change
return([...super.observedAttributes, 'label']) // return([...super.observedAttributes, 'myattr'])
} // }
//
attributeChangedCallback(name, oldValue, newValue) { // attributeChangedCallback(name, oldValue, newValue) {
this.attrs[name] = newValue // super.attributeChangedCallback(name, oldValue, newValue)
// on the fly changes here // }
}
toggle(){ toggle(){
for(const opt of this.options){ for(const opt of this.options){
@@ -74,26 +73,40 @@ class BZselect extends Buildoz {
this.open = !this.open this.open = !this.open
} }
onOption(value){ onClick(evt){
this.value =value const opt = evt.target.closest('option')
this.toggle() if(opt && opt.value) this.onOption(opt.value)
const opt = Array.from(this.options).find(opt => opt.value==value)
this.button.textContent = opt.textContent
} }
fill(opts){ onOption(value, silent=false){
this.el.innerHTML ='' this.value = value
if(!Array.isArray(opts)) opts = [opts] if(!silent) this.toggle()
const ul = Object.assign(document.createElement('ul'), const opt = Array.from(this.options).find(opt => opt.value==value)
{ className: `bz-selector ${this.config.ulClass ? this.config.ulClass :''}`, if(value || (opt && opt.textContent)) this.button.textContent = opt.textContent
}) else this.button.textContent = this.getAttribute('label') || this.defaultAttrs.label
for(const opt of opts){ this.dispatchEvent(new Event('change', {
const li = document.createElement('li') bubbles: true,
li.innerHTML = `${opt.markup}` composed: false,
li.setAttribute('data-value', opt.value) cancelable: false
ul.append(li) }))
} }
this.el.append(ul)
addOption(value, markup){
const opt = document.createElement('option')
opt.setAttribute(value, value)
opt.innerHTML = markup
opt.addEventListener('click',this.onClick.bind(this))
this.append(opt)
this.options = this.querySelectorAll('option')
}
fillOptions(opts, erase = true){
if(erase){
this.options.forEach(node => { node.remove() })
this.options = this.querySelectorAll('option')
this.onOption('', true) // unselect last
}
for(const opt of opts) this.addOption(opt.value, opt.markup)
} }
} }
+1 -7
View File
@@ -17,13 +17,7 @@
<article eiccard class="agent-preview"> <article eiccard class="agent-preview">
<header><canvas data-output="agentSampleCanvas"></canvas></header> <header><canvas data-output="agentSampleCanvas"></canvas></header>
<section> <section>
<bz-select label="Agent type..." data-output="agentsSelector"> <bz-select label="Agent type..." data-output="agentsSelector"></bz-select>
<option value="val1">First value</option>
<option value="val2">Second value</option>
<option value="val3">Third value</option>
<option value="val4">Fourth value</option>
<option value="val5">Fifth value</option>
</bz-select>
</section> </section>
</article> </article>
<article eiccard> <article eiccard>
+8 -15
View File
@@ -21,28 +21,21 @@ class KeyframeView extends WindozDomContent {
this.setupTriggers(components) this.setupTriggers(components)
this.setupRefs(components) this.setupRefs(components)
this.agentDefs = await this.models.agents.getSprites('Basic 3D') this.agentDefs = await this.models.agents.getSprites('Basic 3D')
// for(const agentType in this.agentDefs){ this.outputs.agentsSelector.fillOptions( Object.keys(this.agentDefs).map(aname => ({ markup: `<i>${aname}</i>`, value: aname})) )
// const opt = new Option(agentType, agentType) this.outputs.agentsSelector.addEventListener('change',this.onChangeAgent.bind(this))
// this.outputs.agentsSelector.add(opt)
// }
// this.outputs.agentsSelector.addEventListener('change',this.onChangeAgent.bind(this))
// const x = new tinySelector('[data-output="agentsSelector"]',{
// selectorOptions: Object.keys(this.agentDefs).map(aname => ({ markup: aname, value: aname}))
// })
// this.agentPreview = new app.LoadedModules.AgentPreview(this.outputs.agentSampleCanvas, this.agentDefs) this.agentPreview = new app.LoadedModules.AgentPreview(this.outputs.agentSampleCanvas, this.agentDefs)
// this.onChangeAgent() this.onChangeAgent()
// this.agentPreview.startRendering() this.agentPreview.startRendering()
// this.agentPreview.animation = true this.agentPreview.animation = true
} }
onChangeAgent(event){ onChangeAgent(event){
this.agentPreview.setAgent(this.outputs.agentsSelector.value) console.log('onChangeAgent',this.outputs.agentsSelector.value)
if(this.outputs.agentsSelector.value) this.agentPreview.setAgent(this.outputs.agentsSelector.value)
} }
} }
@@ -61,11 +61,12 @@ export class AgentPreview{
return(this._animation) return(this._animation)
} }
_animate = () => { // to avoid havind to bind(this) in requestAnimationFrame, because one bound fn per frame = continuous GC load _animate = () => { // to avoid having to bind(this) in requestAnimationFrame, because one bound fn per frame = continuous GC load
if(!this.animation) return
requestAnimationFrame(this._animate) requestAnimationFrame(this._animate)
this.currentAgentObj.rotation.x += 0.005 if(this.currentAgentObj && this.animation){
this.currentAgentObj.rotation.y += 0.01 this.currentAgentObj.rotation.x += 0.005
this.currentAgentObj.rotation.y += 0.01
}
this.renderer.render(this.scene, this.camera) this.renderer.render(this.scene, this.camera)
} }
} }