v1 on fire
This commit is contained in:
parent
be693864ab
commit
2edccfbb79
27 changed files with 279 additions and 115 deletions
|
|
@ -2,7 +2,8 @@ var UiWidget = require('./ui-widget'),
|
|||
{categories} = require('../widgets/'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
{icon, Popup} = require('../ui/utils')
|
||||
{icon, Popup} = require('../ui/utils'),
|
||||
chroma = require('chroma-js')
|
||||
|
||||
|
||||
class UiInspectorField extends UiWidget {
|
||||
|
|
@ -15,6 +16,7 @@ class UiInspectorField extends UiWidget {
|
|||
this.widget = options.widget
|
||||
this.value = options.value
|
||||
this.default = options.default
|
||||
this.tabIndex = options.tabIndex
|
||||
|
||||
this.container = html`<osc-inspector-field></osc-inspector-field>`
|
||||
this.label = this.container.appendChild(html`<label>${this.name}</label>`)
|
||||
|
|
@ -29,14 +31,14 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
if (this.widget.props.type == 'tab' || this.widget.props.type == 'root') {
|
||||
this.container.appendChild(html`
|
||||
<textarea class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
|
||||
<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
|
||||
`)
|
||||
return
|
||||
}
|
||||
|
||||
this.createInput()
|
||||
|
||||
var select = html`<select class="no-keybinding" name="${this.name}"/>`
|
||||
var select = html`<select tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}"/>`
|
||||
|
||||
for (let cname in categories) {
|
||||
|
||||
|
|
@ -63,7 +65,7 @@ class UiInspectorField extends UiWidget {
|
|||
JSON.stringify(this.value, null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : this.value
|
||||
|
||||
|
||||
var input = html`<textarea class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}">${stringValue}</textarea>`
|
||||
var input = html`<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}">${stringValue}</textarea>`
|
||||
|
||||
|
||||
this.container.appendChild(input)
|
||||
|
|
@ -83,7 +85,10 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
if (this.name.includes('color')) {
|
||||
|
||||
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${this.value}"/>`
|
||||
let style = window.getComputedStyle(this.widget.container)
|
||||
let val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb')
|
||||
|
||||
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${val}"/>`
|
||||
|
||||
this.container.appendChild(picker)
|
||||
|
||||
|
|
@ -92,22 +97,11 @@ class UiInspectorField extends UiWidget {
|
|||
if (this.default.type.includes('boolean')) {
|
||||
|
||||
let toggle = html`
|
||||
<osc-inspector-checkbox class="${this.widget.getProp(this.name) ? 'on' : ''}">
|
||||
<osc-inspector-checkbox name="${this.name}" class="${this.widget.getProp(this.name) ? 'on' : ''}">
|
||||
${raw(icon('check'))}
|
||||
</osc-inspector-checkbox>
|
||||
`
|
||||
|
||||
toggle.addEventListener('click', ()=>{
|
||||
if (this.name === 'label' && !this.widget.getProp(this.name) === true) {
|
||||
// special case
|
||||
input.value = 'auto'
|
||||
} else {
|
||||
input.value = !this.widget.getProp(this.name)
|
||||
}
|
||||
DOM.dispatchEvent(input, 'change')
|
||||
})
|
||||
|
||||
|
||||
this.container.appendChild(toggle)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,25 @@ class UiInspector extends UiWidget {
|
|||
|
||||
})
|
||||
|
||||
this.container.addEventListener('click', (e)=>{
|
||||
|
||||
var node = e.target
|
||||
|
||||
if (node.tagName === 'OSC-INSPECTOR-CHECKBOX') {
|
||||
|
||||
var name = node.getAttribute('name')
|
||||
|
||||
var textarea = DOM.get(this.container, `textarea[name="${name}"]`)
|
||||
if (textarea) {
|
||||
textarea[0].value = !node.classList.contains('on')
|
||||
DOM.dispatchEvent(textarea[0], 'change')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
this.container.addEventListener('change', this.onChange.bind(this))
|
||||
this.container.addEventListener('keydown', this.onKeydown.bind(this))
|
||||
this.container.addEventListener('input', this.textAutoHeight.bind(this))
|
||||
|
|
@ -38,23 +57,33 @@ class UiInspector extends UiWidget {
|
|||
|
||||
|
||||
this.lock = false
|
||||
this.clearTimeout = null
|
||||
|
||||
}
|
||||
|
||||
clear() {
|
||||
|
||||
this.container.innerHTML = ''
|
||||
this.mounted = false
|
||||
this.clearTimeout = setTimeout(()=>{
|
||||
this.container.innerHTML = ''
|
||||
this.mounted = false
|
||||
this.clearTimeout = null
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
inspect(widgets) {
|
||||
|
||||
if (this.clearTimeout) {
|
||||
clearTimeout(this.clearTimeout)
|
||||
this.clearTimeout = null
|
||||
}
|
||||
|
||||
var content = html`<div></div>`
|
||||
|
||||
var widget = widgets[0],
|
||||
props = defaults[widget.props.type],
|
||||
multi = widgets.length > 1
|
||||
multi = widgets.length > 1,
|
||||
tabIndex = 1000
|
||||
|
||||
// this.form.appendChild(html`
|
||||
// <div class="separator">
|
||||
|
|
@ -105,7 +134,8 @@ class UiInspector extends UiWidget {
|
|||
widget: widget,
|
||||
name: propName,
|
||||
value: widget.props[propName],
|
||||
default: defaults[w.props.type][propName]
|
||||
default: defaults[w.props.type][propName],
|
||||
tabIndex: tabIndex++
|
||||
}).container
|
||||
if (!field) continue
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue