editor: embed prop docs
This commit is contained in:
parent
3bdd4c04c6
commit
d43c8e90e1
10 changed files with 81 additions and 31 deletions
|
|
@ -2,16 +2,17 @@ var widgetCategories = require('../widgets/').categories,
|
|||
{updateWidget} = require('./data-workers'),
|
||||
widgetManager = require('../managers/widgets'),
|
||||
{deepCopy} = require('../utils'),
|
||||
{icon} = require('../ui/utils')
|
||||
{icon, Popup} = require('../ui/utils')
|
||||
|
||||
module.exports = function editField(editor, widget, propName, defaultValue){
|
||||
|
||||
let dynamic = widget.constructor.dynamicProps.includes(propName),
|
||||
disabled = widget.disabledProps.indexOf(propName) > -1
|
||||
disabled = widget.disabledProps.indexOf(propName) > -1,
|
||||
error = widget.errors[propName]
|
||||
|
||||
let field = DOM.create(`
|
||||
<div class="input-wrapper ${widget.errors[propName] ? 'error' : ''} ${disabled ? 'disabled' : ''}">
|
||||
<label ${dynamic ? 'class="dynamic"': ''} title="${widget.errors[propName] || (dynamic ? 'dynamic' : '')}">${propName}</label>
|
||||
<label class="${error ? 'error' : ''}">${propName}</label>
|
||||
</div>
|
||||
`)
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
}
|
||||
})
|
||||
|
||||
if (typeof defaultValue === 'boolean') {
|
||||
if (defaultValue.type.includes('boolean')) {
|
||||
|
||||
var toggle = DOM.create(`
|
||||
<span class="checkbox ${widget.props[propName] ? 'on' : ''}">
|
||||
|
|
@ -92,7 +93,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
|
||||
var newWidgets = []
|
||||
for (var w of editor.selectedWidgets) {
|
||||
w.props[propName] = v !== '' ? v : deepCopy(defaultValue)
|
||||
w.props[propName] = v !== '' ? v : deepCopy(defaultValue.value)
|
||||
newWidgets.push(updateWidget(w, {preventSelect: editor.selectedWidgets.length > 1}))
|
||||
}
|
||||
editor.pushHistory()
|
||||
|
|
@ -178,8 +179,31 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
|
||||
}
|
||||
|
||||
var label = DOM.get(field, 'label')[0]
|
||||
label.addEventListener('fast-click', ()=>{
|
||||
|
||||
var htmlHelp = Array.isArray(defaultValue.help) ? defaultValue.help.join('<br/>') : defaultValue.help
|
||||
htmlHelp = htmlHelp.replace(/`([^`]*)`/g, '<pre>$1</pre>')
|
||||
|
||||
var htmlError = error ? `<p class="error">${error}</p><br/></br>` : ''
|
||||
|
||||
new Popup({closable: true, title: propName, content: `
|
||||
<div class="editor-help">
|
||||
|
||||
Type: <pre>${defaultValue.type}</pre><br/>
|
||||
Default: <pre>${defaultValue.value}</pre><br/><br/>
|
||||
Dynamic: <pre>${dynamic ? 'true' : 'false'}</pre><br/><br/>
|
||||
|
||||
${htmlError}
|
||||
|
||||
<div class="usage">${htmlHelp}</div>
|
||||
</div>
|
||||
`})
|
||||
})
|
||||
|
||||
if (input) {
|
||||
return field
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ var Editor = class Editor {
|
|||
|
||||
this.defaults = {}
|
||||
for (var k in widgets) {
|
||||
this.defaults[k] = widgets[k].defaults()._props()
|
||||
this.defaults[k] = widgets[k].defaults()
|
||||
}
|
||||
|
||||
this.selectedWidgets = []
|
||||
|
|
@ -273,7 +273,7 @@ var Editor = class Editor {
|
|||
|
||||
if (!shared) continue
|
||||
|
||||
if (propName.indexOf('_') == 0) {
|
||||
if (propName.indexOf('_') === 0 && propName !== '_props') {
|
||||
|
||||
field = DOM.create(`<div class="separator"><span>${props[propName]}</span></div>`)
|
||||
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
for (var i in widgets) {
|
||||
|
||||
if (widget[i] === widgetManager) continue
|
||||
if (widgets[i] === widgetManager) continue
|
||||
|
||||
if (widgets[i].props[k] !== undefined || k === 'value') {
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ module.exports = class Led extends Widget {
|
|||
|
||||
_image:'image',
|
||||
|
||||
size: 'cover',
|
||||
position: 'center',
|
||||
repeat: 'no-repeat',
|
||||
size: {type: 'string', value: 'cover', help: 'CSS background-size'},
|
||||
position: {type: 'string', value: 'center', help: 'CSS background-position'},
|
||||
repeat: {type: 'string', value: 'no-repear', help: 'CSS background-repeat'},
|
||||
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
|
||||
cache: {type: 'boolean', value: true, help: [
|
||||
'Set to false to disable image caching (forces file reload when updating or editing the widget).',
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ module.exports = class Meter extends Fader {
|
|||
|
||||
css: {type: 'string', value: '', help: [
|
||||
'Available CSS variables:',
|
||||
`- '--color-gauge: color;'`,
|
||||
'- `--color-gauge: color;`',
|
||||
'- `--color-knob: color;`',
|
||||
`- '--color-pips: color;'`,
|
||||
'- `--color-pips: color;`',
|
||||
`- '--gauge-opacity: number;'`
|
||||
]},
|
||||
|
||||
|
|
|
|||
|
|
@ -34,16 +34,23 @@ module.exports = class Encoder extends Widget {
|
|||
|
||||
_encoder: 'encoder',
|
||||
|
||||
ticks:360,
|
||||
back:-1,
|
||||
forth:1,
|
||||
release:'',
|
||||
snap:false,
|
||||
doubleTap:false,
|
||||
ticks: {type: 'number', value: 'auto', help: 'defines the granularity / verbosity of the encoder (number of step for a 360° arc)'},
|
||||
back: {type: '*', value: -1, help: 'Defines which value is sent when rotating the encoder anticlockwise'},
|
||||
forth: {type: '*', value: 1, help: 'Defines which value is sent when rotating the encoder clockwise'},
|
||||
release: {type: 'number', value: 'auto', help: [
|
||||
'Defines which value is sent when releasing the encoder:',
|
||||
'- Set to `null` to send send no argument in the osc message',
|
||||
'- Can be an `object` if the type needs to be specified'
|
||||
]},
|
||||
snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'},
|
||||
doubleTap: {type: 'boolean', value: false, help: [
|
||||
'Set to `true` to make the fader reset to its `default` value when receiving a double tap.',
|
||||
'Can also be an osc address, in which case the widget will just send an osc message (`/<doubleTap> <preArgs>`)'
|
||||
]},
|
||||
|
||||
}, [], {
|
||||
|
||||
touchAddress:''
|
||||
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
|
||||
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ module.exports = class Fader extends Slider {
|
|||
meterAddress: {type: 'string', value:'', help: 'OSC address for the built-in meter'},
|
||||
css: {type: 'string', value: '', help: [
|
||||
'Available CSS variables:',
|
||||
'- --color-gauge:color;',
|
||||
'- --color-knob:color;',
|
||||
'- --color-pips:color;',
|
||||
'- --gauge-opacity:number;'
|
||||
'- `--color-gauge: color;`',
|
||||
'- `--color-knob: color;`',
|
||||
'- `--color-pips: color;`',
|
||||
'- `--gauge-opacity: number;`'
|
||||
]}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ module.exports = class Knob extends Slider {
|
|||
touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'},
|
||||
css: {type: 'string', value: '', help: [
|
||||
'Available CSS variables:',
|
||||
'- --color-gauge:color;',
|
||||
'- --color-knob:color;',
|
||||
'- --color-pips:color;'
|
||||
'- `--color-gauge: color;`',
|
||||
'- `--color-knob: color;`',
|
||||
'- `--color-pips: color;`'
|
||||
]}
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -199,10 +199,10 @@ module.exports = class Range extends Widget {
|
|||
]},
|
||||
css: {type: 'string', value: '', help: [
|
||||
'Available CSS variables:',
|
||||
'- --color-gauge:color;',
|
||||
'- --color-knob:color;',
|
||||
'- --color-pips:color;',
|
||||
'- --gauge-opacity:number;'
|
||||
'- `--color-gauge: color;`',
|
||||
'- `--color-knob: color;`',
|
||||
'- `--color-pips: color;`',
|
||||
'- `--gauge-opacity: number;`'
|
||||
]}
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -458,3 +458,22 @@
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Help popup
|
||||
|
||||
.editor-help {
|
||||
.error {
|
||||
color: red
|
||||
}
|
||||
em {
|
||||
font-style: italic;
|
||||
}
|
||||
pre {
|
||||
color: var(--color-accent);
|
||||
padding: 2rem 3rem;
|
||||
background: rgba(black, 0.2);
|
||||
display: inline-block;
|
||||
}
|
||||
.usage {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue