From 9b3cb190912bbb827fb3879aabdfd98b8432f45d Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 30 Aug 2018 11:26:06 +0200 Subject: [PATCH] refactor: widget props ok --- .../js/app/widgets/containers/panel.js | 7 +-- src/browser/js/app/widgets/plots/meter.js | 4 +- src/browser/js/app/widgets/plots/plot.js | 2 +- src/browser/js/app/widgets/plots/rgbled.js | 2 +- src/browser/js/app/widgets/plots/text.js | 2 +- src/browser/js/app/widgets/sliders/fader.js | 52 +++++++++++++------ src/browser/js/app/widgets/sliders/knob.js | 36 +++++++++---- src/browser/js/app/widgets/sliders/range.js | 33 ++++++++---- .../js/app/widgets/switchers/crossfader.js | 16 ++++-- .../js/app/widgets/switchers/switcher.js | 20 +++---- 10 files changed, 110 insertions(+), 64 deletions(-) diff --git a/src/browser/js/app/widgets/containers/panel.js b/src/browser/js/app/widgets/containers/panel.js index f6a4904b..9360948d 100644 --- a/src/browser/js/app/widgets/containers/panel.js +++ b/src/browser/js/app/widgets/containers/panel.js @@ -1,11 +1,6 @@ var Widget = require('../common/widget'), widgetManager = require('../../managers/widgets'), - parser = require('../../parser'), - editor - -setTimeout(()=>{ - editor = require('../../editor/') -}) + parser = require('../../parser') class Panel extends Widget { diff --git a/src/browser/js/app/widgets/plots/meter.js b/src/browser/js/app/widgets/plots/meter.js index 150e2b98..2965eca5 100644 --- a/src/browser/js/app/widgets/plots/meter.js +++ b/src/browser/js/app/widgets/plots/meter.js @@ -16,12 +16,12 @@ module.exports = class Meter extends Fader { horizontal: {type: 'boolean', value: false, help: 'See fader\'s `horizontal`'}, pips: {type: 'boolean', value: false, help: 'See fader\'s `pips`'}, dashed: {type: 'boolean', value: false, help: 'See fader\'s `dashed`'}, - gradient: {type: 'array', value: [], help: 'When set, the meter\'s gauge will be filled with a linear color gradient : each item must be a CSS color string. Example: `["blue", "red"]`'}, + gradient: {type: 'array', value: [], help: 'When set, the meter\'s gauge will be filled with a linear color gradient : each item must be a CSS color string. Example: `[\'blue\', \'red\']`'}, }, ['target', 'precision', 'bypass'], { css: {type: 'string', value: '', help: [ - 'Available CSS variables:' + 'Available CSS variables:', `- '--color-gauge: color;'`, '- `--color-knob: color;`', `- '--color-pips: color;'`, diff --git a/src/browser/js/app/widgets/plots/plot.js b/src/browser/js/app/widgets/plots/plot.js index 00fb7942..927337af 100644 --- a/src/browser/js/app/widgets/plots/plot.js +++ b/src/browser/js/app/widgets/plots/plot.js @@ -21,7 +21,7 @@ module.exports = class Plot extends _plots_base { }, ['target', 'precision', 'bypass'], { - value: {type: 'array|string', help: [ + value: {type: 'array|string', help: [ '- `Array` of `y` values', '- `Array` of `[x, y]` `array` values', '- `String` `array`', diff --git a/src/browser/js/app/widgets/plots/rgbled.js b/src/browser/js/app/widgets/plots/rgbled.js index fbf06441..c1a300b6 100644 --- a/src/browser/js/app/widgets/plots/rgbled.js +++ b/src/browser/js/app/widgets/plots/rgbled.js @@ -7,7 +7,7 @@ module.exports = class Rbgled extends Widget { return super.defaults({}, ['color', 'target', 'precision', 'bypass'], { - value: {type: 'array|string', help: [ + value: {type: 'array|string', help: [ '- `Array`: `[r, g, b]` (`r`, `g` and `b` between `0` and `255`)', '- `Array`: `[r, g, b, alpha]` (`alpha` between `0` and `255`)', '- `String`: CSS color', diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index 4282d37a..dd8335d0 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -12,7 +12,7 @@ module.exports = class Text extends Widget { vertical: {type: 'boolean', value: false, help: 'Set to `true` to display the text vertically'}, wrap: {type: 'boolean', value: false, help: [ 'Set to `true` to wrap long lines automatically.', - 'This will not break overflowing words by default, word-breaking can be enabled by adding `word-break: break-all;` to the `css` property'}, + 'This will not break overflowing words by default, word-breaking can be enabled by adding `word-break: break-all;` to the `css` property', ]}, align: {type: 'string', value: '', help: 'Set to `left` or `right` to change text alignment (otherwise center)'}, diff --git a/src/browser/js/app/widgets/sliders/fader.js b/src/browser/js/app/widgets/sliders/fader.js index 35dacbca..8cff8c94 100644 --- a/src/browser/js/app/widgets/sliders/fader.js +++ b/src/browser/js/app/widgets/sliders/fader.js @@ -10,26 +10,44 @@ module.exports = class Fader extends Slider { _fader:'fader', - horizontal:false, - alignRight:false, - pips:true, - input: true, - meter:false, - compact:false, - dashed:false, - snap:false, - spring:false, - doubleTap:false, - range:{min:0,max:1}, - logScale:false, - unit:'', - origin: 'auto' + horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display the fader horizontally'}, + alignRight: {type: 'boolean', value: false, help: 'Set to `true` to invert the pip\'s and fader\'s position'}, + pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, + input: {type: 'boolean', value: true, help: 'Set to `false` to hide the built-in input'}, + meter: {type: 'boolean', value: false, help: [ + 'Set to true to display a vu-meter next in the fader', + '- the meter\'s `id` will be the same as the widget\'s with `/meter` appended to it', + '- the meter\'s `id` will be the same as the widget\'s with `/meter` appended to it' + ]}, + compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. Disables default mouse/touch focusing on the value display.'}, + dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, + 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'}, + spring: {type: 'boolean', value: false, help: 'When set to `true`, the widget will go back to its `default` value when released'}, + 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 (`/ `)' + ]}, + range: {type: 'object', value: {min:0,max:1}, help: [ + 'Defines the breakpoints of the fader\'s scale:', + '- keys can be percentages and/or `min` / `max`', + '- values can be `number` or `object` if a custom label is needed', + 'Example: (`{min:{"-inf": 0}, "50%": 0.25, max: {"+inf": 1}}`)' + ]}, + logScale: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis'}, + unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, + origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the fader\'s gauge'}, }, [], { - touchAddress:'', - meterAddress:'' - + touchAddress: {type: 'string', value:'', help: 'OSC address for touched state messages: `/touchAddress [preArgs] 0/1`'}, + 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;' + ]} }) } diff --git a/src/browser/js/app/widgets/sliders/knob.js b/src/browser/js/app/widgets/sliders/knob.js index 4b3559c4..92e83910 100644 --- a/src/browser/js/app/widgets/sliders/knob.js +++ b/src/browser/js/app/widgets/sliders/knob.js @@ -9,21 +9,35 @@ module.exports = class Knob extends Slider { _knob:'knob', - pips:true, - input: true, - dashed:false, + pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, + input: {type: 'boolean', value: true, help: 'Set to `false` to hide the built-in input'}, + dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, angle:270, - snap:false, - spring:false, - doubleTap:false, - range:{min:0,max:1}, - logScale:false, - unit:'', - origin: 'auto' + 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'}, + spring: {type: 'boolean', value: false, help: 'When set to `true`, the widget will go back to its `default` value when released'}, + doubleTap: {type: 'boolean', value: false, help: [ + 'Set to `true` to make the knob 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 (`/ `)' + ]}, + range: {type: 'object', value: {min:0,max:1}, help: [ + 'Defines the breakpoints of the fader\'s scale:', + '- keys can be percentages and/or `min` / `max`', + '- values can be `number` or `object` if a custom label is needed', + 'Example: (`{min:{"-inf": 0}, "50%": 0.25, max: {"+inf": 1}}`)' + ]}, + logScale: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis'}, + unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, + origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the knob\'s gauge'}, }, [], { - touchAddress:'' + 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;' + ]} }) diff --git a/src/browser/js/app/widgets/sliders/range.js b/src/browser/js/app/widgets/sliders/range.js index c8b1336a..76b9fba3 100644 --- a/src/browser/js/app/widgets/sliders/range.js +++ b/src/browser/js/app/widgets/sliders/range.js @@ -179,20 +179,31 @@ module.exports = class Range extends Widget { _range:'range', - horizontal:false, - alignRight:false, - input: true, - compact:false, - pips:true, - snap:false, - spring:false, - range:{min:0,max:1}, - logScale:false, + range: {type: 'object', value: {min:0,max:1}, help: 'See fader\'s `range`'}, + horizontal: {type: 'boolean', value: false, help: 'See fader\'s `horizontal`'}, + alignRight: {type: 'boolean', value: false, help: 'See fader\'s `alignRight`'}, + input: {type: 'boolean', value: true, help: 'See fader\'s `input`'}, + compact: {type: 'boolean', value: false, help: 'See fader\'s `compact`'}, + pips: {type: 'boolean', value: true, help: 'See fader\'s `pips`'}, + snap: {type: 'boolean', value: false, help: 'See fader\'s `snap`'}, + spring: {type: 'boolean', value: false, help: 'See fader\'s `spring`'}, + logScale: {type: 'boolean', value: false, help: 'See fader\'s `logScale`'}, }, [], { - touchAddress:'', - split:false + touchAddress: {type: 'string', value: '', help: 'See fader\'s `touchAddress`'}, + split: {type: 'boolean|object', value: false, help: [ + 'Set to `true` to send separate osc messages for `low` and `high` handles. The `address` will be the same as the widget\'s with `/low` or `/high` appended to it', + 'Can be set as an object to specify a different `address` : `[\'/osc_address_low\', \'/osc_address_high\']`', + 'Note: the widget will only respond to its original osc address, not to the splitted version' + ]}, + css: {type: 'string', value: '', help: [ + 'Available CSS variables:', + '- --color-gauge:color;', + '- --color-knob:color;', + '- --color-pips:color;', + '- --gauge-opacity:number;' + ]} }) diff --git a/src/browser/js/app/widgets/switchers/crossfader.js b/src/browser/js/app/widgets/switchers/crossfader.js index 560a3740..fd3faacd 100644 --- a/src/browser/js/app/widgets/switchers/crossfader.js +++ b/src/browser/js/app/widgets/switchers/crossfader.js @@ -9,12 +9,20 @@ module.exports = class Crossfader extends Switcher { static defaults(){ - var o = super.defaults() - o.type = 'crossfader' - delete o.values + return super.defaults({ - return o + _crossfader: 'crossfader', + linkedWidgets: {type: 'string|array', value: '', help: [ + '- `String`: a widget\'s `id` whose state changes will be stored', + '- `Array`: a list of widget `id` string' + ]}, + horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display values horizontally'}, + values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ + '`Array` of possible values to switch between : `[1,2,3]`', + '`Object` of `"label":value` pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept', + ]} + }) } constructor(options) { diff --git a/src/browser/js/app/widgets/switchers/switcher.js b/src/browser/js/app/widgets/switchers/switcher.js index 32e78f79..2a99ad89 100644 --- a/src/browser/js/app/widgets/switchers/switcher.js +++ b/src/browser/js/app/widgets/switchers/switcher.js @@ -9,17 +9,17 @@ module.exports = class Switcher extends _switchers_base { return super.defaults({ - _switcher:'switcher', - - horizontal:false, - linkedWidgets:'', - values:['A', 'B'], - - }, [], { - - touchAddress:'', - split:false + _switcher: 'switcher', + linkedWidgets: {type: 'string|array', value: '', help: [ + '- `String`: a widget\'s `id` whose state changes will be stored', + '- `Array`: a list of widget `id` string' + ]}, + horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display values horizontally'}, + values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ + '`Array` of possible values to switch between : `[1,2,3]`', + '`Object` of `"label":value` pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept', + ]} }) }