session: unwrap root widget; parser: don't parse arrays
This commit is contained in:
parent
6134d56459
commit
90a3a7880a
5 changed files with 51 additions and 59 deletions
|
|
@ -818,7 +818,7 @@ var Editor = class Editor {
|
|||
|
||||
updateWidgetFromPatch(patch, indexes) {
|
||||
|
||||
var [widget, subpatch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]),
|
||||
var [widget, subpatch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch),
|
||||
options = {}
|
||||
|
||||
if (indexes) {
|
||||
|
|
|
|||
|
|
@ -40,11 +40,9 @@ var SessionManager = class SessionManager {
|
|||
|
||||
try {
|
||||
|
||||
if (session[0].type != 'root') {
|
||||
this.session = [{type:'root', tabs:session}]
|
||||
} else if (session[0].type == 'root'){
|
||||
this.session = session
|
||||
}
|
||||
if (Array.isArray(session)) session = session[0]
|
||||
if (session.type !== 'root') throw ''
|
||||
this.session = session
|
||||
|
||||
} catch(err) {
|
||||
|
||||
|
|
@ -180,7 +178,7 @@ var SessionManager = class SessionManager {
|
|||
}
|
||||
|
||||
create() {
|
||||
this.load([{}],function(){
|
||||
this.load({type: 'root'},function(){
|
||||
require('../ui/sidepanel').open()
|
||||
editor.enable()
|
||||
editor.select(widgetManager.getWidgetById('root'))
|
||||
|
|
|
|||
|
|
@ -36,74 +36,68 @@ var Parser = class Parser {
|
|||
index
|
||||
} = options
|
||||
|
||||
if (!Array.isArray(data)) data = [data]
|
||||
var props = data
|
||||
|
||||
for (let i in data) {
|
||||
// Set default widget type
|
||||
props.type = tab ? 'tab' : props.type || 'fader'
|
||||
|
||||
var props = data[i]
|
||||
// Safe copy widget's options
|
||||
let defaults = this.widgets[props.type].defaults()._props()
|
||||
|
||||
// Set default widget type
|
||||
props.type = tab ? 'tab' : props.type || 'fader'
|
||||
// Set widget's undefined options to default
|
||||
for (let i in defaults) {
|
||||
if (i.indexOf('_')!=0 && props[i]===undefined) props[i] = defaults[i]
|
||||
}
|
||||
|
||||
// Safe copy widget's options
|
||||
let defaults = this.widgets[props.type].defaults()._props()
|
||||
|
||||
// Set widget's undefined options to default
|
||||
for (let i in defaults) {
|
||||
if (i.indexOf('_')!=0 && props[i]===undefined) props[i] = defaults[i]
|
||||
// Genrate widget's id, based on its type
|
||||
if (props.id=='auto' || !props.id ) {
|
||||
var id
|
||||
while (!id || widgetManager.getWidgetById(id).length) {
|
||||
id=props.type+'_'+this.getIterator(props.type)
|
||||
}
|
||||
props.id = id
|
||||
}
|
||||
|
||||
// Genrate widget's id, based on its type
|
||||
if (props.id=='auto' || !props.id ) {
|
||||
var id
|
||||
while (!id || widgetManager.getWidgetById(id).length) {
|
||||
id=props.type+'_'+this.getIterator(props.type)
|
||||
}
|
||||
props.id = id
|
||||
}
|
||||
// Generate default address
|
||||
props.address = props.address == 'auto' ? '/' + props.id : props.address
|
||||
|
||||
// Generate default address
|
||||
props.address = props.address == 'auto' ? '/' + props.id : props.address
|
||||
for (let j in props) {
|
||||
if (defaults[j] === undefined || j[0] === '_') delete props[j]
|
||||
}
|
||||
|
||||
for (let j in props) {
|
||||
if (defaults[j] === undefined || j[0] === '_') delete props[j]
|
||||
}
|
||||
// create widget
|
||||
var widget = new this.widgets[props.type]({
|
||||
container:true,
|
||||
props,
|
||||
parent,
|
||||
parentNode,
|
||||
reCreateOptions,
|
||||
children
|
||||
})
|
||||
|
||||
// create widget
|
||||
var widget = new this.widgets[props.type]({
|
||||
container:true,
|
||||
props,
|
||||
parent,
|
||||
parentNode,
|
||||
reCreateOptions,
|
||||
children
|
||||
})
|
||||
widgetManager.addWidget(widget)
|
||||
|
||||
widgetManager.addWidget(widget)
|
||||
widget.created(index)
|
||||
|
||||
widget.created(index)
|
||||
// set widget's initial state
|
||||
var defaultValue = widget.getProp('default'),
|
||||
currentValue = widget.getProp('value')
|
||||
|
||||
// set widget's initial state
|
||||
var defaultValue = widget.getProp('default'),
|
||||
currentValue = widget.getProp('value')
|
||||
if (currentValue !== '' && currentValue !== undefined) {
|
||||
|
||||
if (currentValue !== '' && currentValue !== undefined) {
|
||||
stateManager.pushValueNewProp(widget.getProp('id'), currentValue)
|
||||
|
||||
stateManager.pushValueNewProp(widget.getProp('id'), currentValue)
|
||||
} else if (defaultValue !== '' && defaultValue !== undefined) {
|
||||
|
||||
} else if (defaultValue !== '' && defaultValue !== undefined) {
|
||||
|
||||
widget.setValue(defaultValue)
|
||||
|
||||
}
|
||||
|
||||
|
||||
parentNode.appendChild(widget.container)
|
||||
widget.setValue(defaultValue)
|
||||
|
||||
}
|
||||
|
||||
|
||||
parentNode.appendChild(widget.container)
|
||||
|
||||
// Editor needs to get the container object
|
||||
if (data && data.length==1) return widget
|
||||
return widget
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class Root extends Panel {
|
|||
|
||||
traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
|
||||
variables: {type: '*', value: {}, help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
|
||||
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object'},
|
||||
tabs: {type: 'array', value: [{}], help: 'Each element of the array must be a tab object'},
|
||||
id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
|
||||
|
||||
value: {type: 'integer', value: '', help: [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue