widgets: store disabled properties' names and disable them properly in the editor (#221)

This commit is contained in:
jean-emmanuel 2018-05-05 10:49:56 +02:00
parent bcda3d3a06
commit 7dbc21a12d
7 changed files with 37 additions and 16 deletions

View file

@ -5,7 +5,9 @@
- widgets
- `target` and `preArgs` properties are no longer coerced to arrays and can be written as single string values
- `linkId` supports master and slave mode with `>>` and `>>` prefixes
- the special `target` token `null` can now be used in conjunction with regular targets, it disables the default global targets set via the `--send` option
- the special `target` token `null` can now be used in conjunction with regular targets, it disables the default global targets set via the `--send` option
- editor
- disabled widget properties are now greyed out
## 0.29.2

View file

@ -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)

View file

@ -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,

View file

@ -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))

View file

@ -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() {

View file

@ -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')
})

View file

@ -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;