widgets: add linkId option where missing, ⚠️ remove plot/input widgetId option
This commit is contained in:
parent
85d255d5a4
commit
6840dc00d0
22 changed files with 54 additions and 246 deletions
|
|
@ -59,11 +59,6 @@ var Parser = class Parser {
|
|||
// Generate default address
|
||||
props.address = props.address == 'auto' ? '/' + props.id : props.address
|
||||
|
||||
// Delete unrecognized options
|
||||
for (let i in props) {
|
||||
if (defaults[i]===undefined && i!='type') {delete props[i]}
|
||||
}
|
||||
|
||||
// create container
|
||||
var widgetContainer = DOM.create(`
|
||||
<div class="widget ${props.type}-container">
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ module.exports = {
|
|||
open() {
|
||||
if (this.state) return
|
||||
this.state = 1
|
||||
|
||||
|
||||
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.appendChild(this.html)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ module.exports = class Modal extends Panel {
|
|||
return {
|
||||
type:'modal',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Panel extends Widget {
|
|||
return {
|
||||
type:'panel',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ module.exports = class Root extends Panel {
|
|||
return {
|
||||
|
||||
type:'root',
|
||||
linkId:'',
|
||||
|
||||
_style:'style',
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ module.exports = class Strip extends Panel {
|
|||
return {
|
||||
type:'strip',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_style:'style',
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ module.exports = class Tab extends Panel {
|
|||
return {
|
||||
type:'tab',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_style:'style',
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ module.exports = class Input extends Canvas {
|
|||
|
||||
vertical:false,
|
||||
unit: '',
|
||||
widgetId:'',
|
||||
editable:true,
|
||||
value:'',
|
||||
|
||||
|
|
@ -76,12 +75,6 @@ module.exports = class Input extends Canvas {
|
|||
this.widget.classList.add('not-editable')
|
||||
}
|
||||
|
||||
if (this.getProp('widgetId').length) {
|
||||
|
||||
widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
focus() {
|
||||
|
|
@ -114,14 +107,6 @@ module.exports = class Input extends Canvas {
|
|||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length || !e.widget) return
|
||||
|
||||
this.setValue(e.widget.getValue(), {...e.options, internal:true})
|
||||
|
||||
}
|
||||
|
||||
resizeHandle(event){
|
||||
|
||||
super.resizeHandle(event)
|
||||
|
|
@ -149,19 +134,6 @@ module.exports = class Input extends Canvas {
|
|||
this.value = v
|
||||
}
|
||||
|
||||
if (!options.internal && this.getProp('widgetId').length) {
|
||||
var widget = widgetManager.getWidgetById(this.getProp('widgetId'))
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].setValue) {
|
||||
widget[i].setValue(this.value, options)
|
||||
this.setValue(widget[i].getValue(), {...options, internal:true, sentOnce:options.send})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.sentOnce) options.send = false
|
||||
|
||||
this.stringValue = this.getStringValue()
|
||||
this.batchDraw()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ module.exports = class Keys extends Widget {
|
|||
return {
|
||||
type:'led',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -88,7 +89,6 @@ module.exports = class Keys extends Widget {
|
|||
var widget = this.getLinkedWidget()
|
||||
|
||||
if (widget) {
|
||||
|
||||
var v = this.keydownMath.eval({
|
||||
value: widget.getValue(),
|
||||
key: e.key,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ module.exports = class _plots_base extends Canvas {
|
|||
super({...options, html: html})
|
||||
|
||||
this.data = []
|
||||
this.linkedWidgets = []
|
||||
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
|
||||
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
|
||||
this.logScaleX = this.getProp('logScaleX')
|
||||
|
|
@ -33,24 +32,6 @@ module.exports = class _plots_base extends Canvas {
|
|||
}
|
||||
this.smooth = this.getProp('smooth') === true ? 0.25 : this.getProp('smooth') === false ? 0 : parseFloat(this.getProp('smooth')) || 0
|
||||
|
||||
|
||||
|
||||
widgetManager.on(`change.${this.hash}`, this.syncHandleProxy.bind(this), this)
|
||||
|
||||
}
|
||||
|
||||
syncHandleProxy() {
|
||||
|
||||
this.syncHandle(...arguments)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return
|
||||
this.updateData()
|
||||
this.batchDraw()
|
||||
|
||||
}
|
||||
|
||||
resizeHandle() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ module.exports = class Eq extends _plots_base {
|
|||
return {
|
||||
type:'eq',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -27,12 +28,12 @@ module.exports = class Eq extends _plots_base {
|
|||
_eq:'eq',
|
||||
|
||||
pips:true,
|
||||
filters:[],
|
||||
resolution:128,
|
||||
rangeY: {min:-20,max:20},
|
||||
origin: 'auto',
|
||||
logScaleX: false,
|
||||
smooth: false,
|
||||
value: '',
|
||||
|
||||
_osc:'osc',
|
||||
|
||||
|
|
@ -45,6 +46,9 @@ module.exports = class Eq extends _plots_base {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.filters && options.props.filters.length) options.props.value = options.props.filters
|
||||
|
||||
super(options)
|
||||
|
||||
this.rangeX = {min:20,max:22050}
|
||||
|
|
@ -53,45 +57,12 @@ module.exports = class Eq extends _plots_base {
|
|||
|
||||
this.resolution = clip(this.getProp('resolution'),[64,1024])
|
||||
|
||||
for (let i in this.getProp('filters')) {
|
||||
|
||||
for (let j in this.getProp('filters')[i]) {
|
||||
if (typeof this.getProp('filters')[i][j]=='string' && !(j=='type' && this.getProp('filters')[i][j].match(/peak|notch|highpass|highshelf|lowpass|lowshelf/))) {
|
||||
this.linkedWidgets.push(this.getProp('filters')[i][j])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateData() {
|
||||
setValue(v, options={}) {
|
||||
|
||||
var filters = [],
|
||||
eqResponse = []
|
||||
|
||||
|
||||
for (let i in this.getProp('filters')) {
|
||||
var filter = this.getProp('filters')[i]
|
||||
|
||||
filters[i] = {}
|
||||
|
||||
for (let j in filter) {
|
||||
let widget = widgetManager.getWidgetById(filter[j])
|
||||
|
||||
if (typeof filter[j]=='string' && widget.length) {
|
||||
|
||||
filters[i][j] = widget[widget.length-1].getValue()
|
||||
|
||||
} else {
|
||||
|
||||
filters[i][j] = filter[j]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var filters = v,
|
||||
eqResponse = []
|
||||
|
||||
for (let i in filters) {
|
||||
|
||||
|
|
@ -115,7 +86,7 @@ module.exports = class Eq extends _plots_base {
|
|||
|
||||
}
|
||||
|
||||
if (eqResponse.length) this.data = eqResponse
|
||||
if (eqResponse.length) super.setValue(eqResponse, options)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ module.exports = class Led extends Widget {
|
|||
return {
|
||||
type:'image',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ module.exports = class Led extends Widget {
|
|||
return {
|
||||
type:'led',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -25,7 +26,6 @@ module.exports = class Led extends Widget {
|
|||
|
||||
_led:'led',
|
||||
|
||||
widgetId:'',
|
||||
range:{min:0,max:1},
|
||||
logScale:false,
|
||||
value:'',
|
||||
|
|
@ -41,6 +41,9 @@ module.exports = class Led extends Widget {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
|
||||
|
||||
var html = `
|
||||
<div class="led">
|
||||
</div>
|
||||
|
|
@ -48,28 +51,14 @@ module.exports = class Led extends Widget {
|
|||
|
||||
super({...options, html: html})
|
||||
|
||||
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
|
||||
|
||||
this.setValue(this.getProp('range').min)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setValue(v, options={}) {
|
||||
|
||||
if (typeof v != 'number') return
|
||||
|
||||
this.value = v
|
||||
this.widget.style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ module.exports = class Meter extends Fader {
|
|||
return {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -26,7 +27,6 @@ module.exports = class Meter extends Fader {
|
|||
|
||||
_meter:'meter',
|
||||
|
||||
widgetId:'',
|
||||
range:{min:0,max:1},
|
||||
logScale:false,
|
||||
origin:'auto',
|
||||
|
|
@ -47,6 +47,9 @@ module.exports = class Meter extends Fader {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
|
||||
|
||||
options.props.compact = true
|
||||
options.props.input = false
|
||||
|
||||
|
|
@ -56,23 +59,6 @@ module.exports = class Meter extends Fader {
|
|||
|
||||
this.off(/drag(.*)?/)
|
||||
|
||||
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sendValue() {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ module.exports = class Plot extends _plots_base {
|
|||
return {
|
||||
type:'plot',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -25,7 +26,6 @@ module.exports = class Plot extends _plots_base {
|
|||
|
||||
_plot:'plot',
|
||||
|
||||
points:[],
|
||||
rangeX: {min:0,max:1},
|
||||
rangeY: {min:0,max:1},
|
||||
origin: 'auto',
|
||||
|
|
@ -35,6 +35,7 @@ module.exports = class Plot extends _plots_base {
|
|||
logScaleY: false,
|
||||
smooth: false,
|
||||
pips:true,
|
||||
value: '',
|
||||
|
||||
_osc:'osc',
|
||||
|
||||
|
|
@ -47,56 +48,11 @@ module.exports = class Plot extends _plots_base {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.points && options.props.points.length) options.props.value = options.props.points
|
||||
|
||||
super(options)
|
||||
|
||||
if (typeof this.getProp('points')=='string') {
|
||||
|
||||
this.linkedWidgets.push(this.getProp('points'))
|
||||
|
||||
} else if (typeof this.getProp('points')=='object') {
|
||||
|
||||
for (let i in this.getProp('points')) {
|
||||
for (let j in this.getProp('points')[i]) {
|
||||
if (typeof this.getProp('points')[i][j] == 'string') {
|
||||
this.linkedWidgets.push(this.getProp('points')[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateData() {
|
||||
|
||||
var data = [],
|
||||
points = this.getProp('points'),
|
||||
widget = widgetManager.getWidgetById(points)
|
||||
|
||||
if (typeof points=='string' && widget.length) {
|
||||
|
||||
data = widget[widget.length-1].getValue()
|
||||
|
||||
} else if (typeof points=='object') {
|
||||
|
||||
for (let i in points) {
|
||||
|
||||
data[i] = []
|
||||
|
||||
for (var k in [0,1]) {
|
||||
let widget = widgetManager.getWidgetById(points[i][k])
|
||||
if (typeof points[i][k] == 'string' && widget.length) {
|
||||
data[i][k] = widget[widget.length-1].getValue()
|
||||
} else {
|
||||
data[i][k] = points[i][k]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (data.length) this.data = data
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ module.exports = class Rbgled extends Widget {
|
|||
return {
|
||||
type:'rgbled',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -25,7 +26,6 @@ module.exports = class Rbgled extends Widget {
|
|||
|
||||
_rgbled:'rgbled',
|
||||
|
||||
widgetId:'',
|
||||
value:'',
|
||||
|
||||
_osc:'osc',
|
||||
|
|
@ -39,6 +39,10 @@ module.exports = class Rbgled extends Widget {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
|
||||
|
||||
|
||||
var html = `
|
||||
<div class="led">
|
||||
</div>
|
||||
|
|
@ -46,27 +50,11 @@ module.exports = class Rbgled extends Widget {
|
|||
|
||||
super({...options, html: html})
|
||||
|
||||
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
this.setValue([0,0,0,0])
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setValue(v, options={}) {
|
||||
|
||||
var c = ''
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ module.exports = class Text extends Widget {
|
|||
return {
|
||||
type:'text',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -25,7 +26,6 @@ module.exports = class Text extends Widget {
|
|||
|
||||
_text: 'text',
|
||||
|
||||
widgetId:'',
|
||||
vertical:false,
|
||||
value:'',
|
||||
|
||||
|
|
@ -39,6 +39,9 @@ module.exports = class Text extends Widget {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
|
||||
|
||||
super({...options, html: '<div class="text"></div>'})
|
||||
|
||||
if (this.getProp('vertical')) this.widget.classList.add('vertical')
|
||||
|
|
@ -51,25 +54,10 @@ module.exports = class Text extends Widget {
|
|||
|
||||
this.value = this.defaultValue
|
||||
|
||||
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
this.setValue(this.value)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue(true), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setValue(v, options={}) {
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
return {
|
||||
type:'visualizer',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
|
|
@ -25,7 +26,6 @@ module.exports = class Visualizer extends _plots_base {
|
|||
|
||||
_visualizer:'visualizer',
|
||||
|
||||
widgetId:'',
|
||||
duration:1,
|
||||
range: {min:0,max:1},
|
||||
origin: 'auto',
|
||||
|
|
@ -44,6 +44,9 @@ module.exports = class Visualizer extends _plots_base {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
// backward compat
|
||||
if (options.props.widgetId) options.props.value = '@{' + options.props.widgetId + '}'
|
||||
|
||||
super(options)
|
||||
|
||||
this.fps = 30
|
||||
|
|
@ -64,13 +67,6 @@ module.exports = class Visualizer extends _plots_base {
|
|||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length || !e.widget) return
|
||||
this.setValue(e.widget.getValue(), {sync: e.options.sync})
|
||||
|
||||
}
|
||||
|
||||
startLoop() {
|
||||
|
||||
this.clock = new Date().getTime()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue