builtin script 1st try
This commit is contained in:
parent
fd3e0df986
commit
3ce0a0e6af
4 changed files with 37 additions and 5 deletions
|
|
@ -216,7 +216,7 @@ var StateManager = class StateManager {
|
|||
for (let id in this.valueStateQueue) {
|
||||
if (this.valueStateQueue[id] !== undefined) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
w.setValue(this.valueStateQueue[id], {sync: true, fromState:true})
|
||||
w.setValue(this.valueStateQueue[id], {sync: true, fromState:true, fromEdit: true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ var EventEmitter = require('../../events/event-emitter'),
|
|||
OscReceiver = require('./osc-receiver'),
|
||||
{deepCopy, deepEqual, isJSON} = require('../../utils'),
|
||||
html = require('nanohtml'),
|
||||
updateWidget = ()=>{}
|
||||
updateWidget = ()=>{},
|
||||
Script
|
||||
|
||||
|
||||
var oscReceiverState = {}
|
||||
|
|
@ -98,7 +99,7 @@ class Widget extends EventEmitter {
|
|||
'When prefixed with >>, the `linkId` will make the widget act as a master (sending but not receiving)',
|
||||
'When prefixed with <<, the `linkId` will make the widget act as a slave (receiving but not sending)'
|
||||
]},
|
||||
|
||||
script: {type: 'script', value: '', help: ''},
|
||||
|
||||
_osc: 'osc',
|
||||
|
||||
|
|
@ -192,6 +193,18 @@ class Widget extends EventEmitter {
|
|||
this.decimals = Math.min(20, Math.max(this.getProp('decimals'), 0))
|
||||
}
|
||||
|
||||
Script = Script || require('../scripts/script')
|
||||
if (this.getProp('script') && !(this instanceof Script)) {
|
||||
this.script = new Script({props:{
|
||||
id: this.getProp('id') + '/script',
|
||||
script: this.getProp('script'),
|
||||
event: 'value'
|
||||
}, builtIn: true, parent: this})
|
||||
this.on('change', (e)=>{
|
||||
if (e.widget === this && this.mounted && !e.options.fromEdit) this.script.setValue(this.value, {...e.options, id: e.id})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
this.container = html`
|
||||
<div class="widget ${options.props.type}-container" id="${this.hash}" data-widget="${this.hash}"></div>
|
||||
|
|
@ -208,7 +221,6 @@ class Widget extends EventEmitter {
|
|||
this.setCssVariables()
|
||||
this.setVisibility()
|
||||
|
||||
|
||||
}
|
||||
|
||||
contains(widget) {
|
||||
|
|
@ -1009,6 +1021,10 @@ class Widget extends EventEmitter {
|
|||
|
||||
onRemove(){
|
||||
|
||||
if (this.getProp('script') && !(this instanceof Script)) {
|
||||
this.script.onRemove()
|
||||
}
|
||||
|
||||
this.removed = true
|
||||
widgetManager.off(undefined, undefined, this)
|
||||
this.removeOscReceivers()
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ class ScriptVm extends Vm {
|
|||
|
||||
if (target) overrides.target = Array.isArray(target) ? target : [target]
|
||||
|
||||
this.getWidget().sendValue(overrides)
|
||||
var widget = this.getWidget()
|
||||
if (widget.buildIn) widget = widget.parent
|
||||
widget.sendValue(overrides)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -164,6 +166,12 @@ class ScriptVm extends Vm {
|
|||
|
||||
this.sandbox.contentWindow.setTimeout = (id, callback, timeout)=>{
|
||||
|
||||
if (typeof id === 'function') {
|
||||
timeout = callback
|
||||
callback = id
|
||||
id = undefined
|
||||
}
|
||||
|
||||
var widget = this.getWidget()
|
||||
|
||||
if (widget.timeouts[id] !== undefined) {
|
||||
|
|
@ -187,6 +195,12 @@ class ScriptVm extends Vm {
|
|||
|
||||
this.sandbox.contentWindow.setInterval = (id, callback, timeout)=>{
|
||||
|
||||
if (typeof id === 'function') {
|
||||
timeout = callback
|
||||
callback = id
|
||||
id = undefined
|
||||
}
|
||||
|
||||
var widget = this.getWidget()
|
||||
|
||||
if (widget.intervals[id] !== undefined) clearTimeout(widget.intervals[id])
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ class Script extends Widget {
|
|||
|
||||
super({...options, html: null})
|
||||
|
||||
this.builtIn = options.builtIn
|
||||
|
||||
this.scriptLock = false
|
||||
|
||||
this.timeouts = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue