widgets: store disabled properties' names and disable them properly in the editor (#221)
This commit is contained in:
parent
afc82abd6e
commit
57ebd3b4a0
7 changed files with 37 additions and 16 deletions
|
|
@ -5,10 +5,11 @@ var widgetCategories = require('../widgets/').categories,
|
|||
|
||||
module.exports = function editField(editor, widget, propName, defaultValue){
|
||||
|
||||
let dynamic = widget.constructor.dynamicProps.includes(propName)
|
||||
let dynamic = widget.constructor.dynamicProps.includes(propName),
|
||||
disabled = widget.disabledProps.indexOf(propName) > -1
|
||||
|
||||
let field = DOM.create(`
|
||||
<div class="input-wrapper ${widget.errors[propName] ? 'error' : ''}">
|
||||
<div class="input-wrapper ${widget.errors[propName] ? 'error' : ''} ${disabled ? 'disabled' : ''}">
|
||||
<label ${dynamic ? 'class="dynamic"': ''} title="${widget.errors[propName] || (dynamic ? 'dynamic' : '')}">${propName}</label>
|
||||
</div>
|
||||
`)
|
||||
|
|
@ -21,7 +22,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
|
||||
if (widget.props.type == 'tab' || widget.props.type == 'root') return
|
||||
|
||||
input = DOM.create(`<select class="input" title="${propName}"/>`)
|
||||
input = DOM.create(`<select class="input" title="${propName}" ${disabled ? 'disabled' : ''}/>`)
|
||||
|
||||
for (let category in widgetCategories) {
|
||||
input.innerHTML += `<optgroup label="> ${category}">`
|
||||
|
|
@ -41,7 +42,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
var value = typeof widget.props[propName] !== 'string' ?
|
||||
JSON.stringify(widget.props[propName], null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : widget.props[propName]
|
||||
|
||||
input = DOM.create(`<textarea class="input" title="${propName}" rows="${value.split('\n').length}">${value}</textarea>`)
|
||||
input = DOM.create(`<textarea class="input" title="${propName}" rows="${value.split('\n').length}" ${disabled ? 'disabled' : ''}>${value}</textarea>`)
|
||||
|
||||
DOM.addEventListener(input, ['input', 'focus'], ()=>{
|
||||
input.setAttribute('rows',0)
|
||||
|
|
|
|||
|
|
@ -174,17 +174,6 @@ var Editor = class Editor {
|
|||
</div>
|
||||
`))
|
||||
|
||||
if (widget.props.type === 'root') {
|
||||
this.form.appendChild(DOM.create(`
|
||||
<div class="input-wrapper">
|
||||
<label>id</label>
|
||||
<input class="input" title="id" disabled value="root"/>
|
||||
</div>
|
||||
`))
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (let propName in props) {
|
||||
|
||||
let field,
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ class Widget extends EventEmitter {
|
|||
var selfLinkedOSCProps = (this.linkedPropsValue['this'] || []).filter(i => OSCProps.indexOf(i) > -1)
|
||||
this.selfLinkedOSCProps = selfLinkedOSCProps.length ? selfLinkedOSCProps : false
|
||||
|
||||
|
||||
this.disabledProps = []
|
||||
|
||||
// cache precision
|
||||
if (this.props.precision != undefined) {
|
||||
this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0))
|
||||
|
|
|
|||
|
|
@ -102,6 +102,20 @@ class Panel extends Widget {
|
|||
|
||||
}
|
||||
|
||||
if (this.getProp('tabs') && !this.getProp('tabs').length) {
|
||||
this.disabledProps.push(
|
||||
'precision', 'address', 'preArgs', 'address', 'bypass',
|
||||
'value', 'default'
|
||||
)
|
||||
}
|
||||
if (this.getProp('widgets') && !this.getProp('widgets').length) {
|
||||
this.disabledProps.push(
|
||||
'layout', 'spacing', 'scroll'
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
createNavigation() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ module.exports = class Root extends Panel {
|
|||
return {
|
||||
|
||||
type:'root',
|
||||
id: 'root',
|
||||
linkId:'',
|
||||
|
||||
_style:'style',
|
||||
|
|
@ -49,6 +50,8 @@ module.exports = class Root extends Panel {
|
|||
|
||||
this.widget.classList.add('root')
|
||||
|
||||
this.disabledProps.push('id')
|
||||
|
||||
DOM.each(this.widget, '> .navigation', (el)=>{
|
||||
el.classList.add('main')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -54,6 +54,15 @@
|
|||
&:last-child {
|
||||
margin-bottom:0;
|
||||
}
|
||||
&.disabled {
|
||||
label {
|
||||
color: var(--color-text-fade);
|
||||
}
|
||||
label + * {
|
||||
pointer-events: none;
|
||||
opacity: .75;
|
||||
}
|
||||
}
|
||||
label {
|
||||
background: var(--color-fg);
|
||||
flex-shrink: 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue