Merge branch 'master' of github.com:jean-emmanuel/open-stage-control

This commit is contained in:
jean-emmanuel 2021-05-09 18:34:59 +02:00
commit b033ddec40
13 changed files with 111 additions and 67 deletions

View file

@ -60,7 +60,11 @@ class Input extends Canvas {
this.blur(true)
})
if (this.getProp('numeric')) this.input.type = 'number'
if (this.getProp('numeric')) {
this.input.type = 'number'
this.input.pattern = '[0-9\.]*'
this.input.inputMode = 'decimal'
}
var asYouType = this.getProp('asYouType')

View file

@ -122,7 +122,7 @@ class Widget extends EventEmitter {
'Defines the osc argument types, one letter per argument (including preArgs)',
'- If empty, the types are infered automatically from the values (with numbers casted to floats by default)',
'- If there are more arguments than type letters, the last type is used for the extra arguments',
'See <a href="http://opensoundcontrol.org/spec-1_0">http://opensoundcontrol.org/spec-1_0</a> for existing typetags'
'See <a href="http://opensoundcontrol.org/">OSC 1.0 specification</a> for existing typetags'
]},
decimals: {type: 'integer', value: 2, help: [
'Defines the number of decimals to send.',
@ -638,6 +638,18 @@ class Widget extends EventEmitter {
return typeof variables[m] === 'string' ? variables[m] : JSON.stringify(variables[m])
}))
if (typeof value === 'string' && isJSON(value)) {
try {
value = JSON.parseFlex(value)
} catch (err) {}
}
if (
// remove quotes
(name[0] === '"' && name[name.length - 1] === '"') ||
(name[0] === '\'' && name[name.length - 1] === '\'')
) name = name.slice(1, name.length - 1)
if (!this.variables[name]) {
this.variables[name] = {default: value, value: value, propNames: [propName]}
@ -729,7 +741,7 @@ class Widget extends EventEmitter {
})
} catch (err) {
this.errorProp(propName, 'JS{{}}', err)
this.errorProp(propName, 'JS{}', err)
}
try {

View file

@ -17,12 +17,12 @@ class Matrix extends Panel {
class_specific: {
widgetType: {type: 'string', value: 'button', help: 'Defines the type of the widgets in the matrix'},
quantity: {type: 'number', value: 4, help: 'Defines the number of widgets in the matrix'},
start: {type: 'integer', value: 0, help: 'First widget\'s index'},
props: {type: 'object', value: {}, help: [
'Defines a set of property to override the widgets\' defaults.',
'JS{{}} and #{} blocks in this field are resolved with an extra variable representing each widget\'s index: `$` (e.g. `#{$}`)',
'Advanced syntax blocks (@{}, OSC{}, JS{{}} and #{}) are resolved at the matrix\' scope (ie @{this.variables} returns the matrix\' variables property)',
'Note: by default, the widgets inherit from the matrix\' `id` and osc properties (`id` and `address` are appended with `/$`)'
'JS{} and #{} blocks in this field are resolved with an extra variable representing each widget\'s index: `$` (e.g. `#{$}`)',
'Advanced syntax blocks (@{}, OSC{}, JS{}, VAR{} and #{}) are resolved at the matrix\' scope (ie @{this.variables} returns the matrix\' variables property)',
'Advanced syntax blocks can be passed to children without being resolved at the matrix\' scope by adding an underscore before the opening bracket.',
'Note: unless overridden, children inherit from the matrix\' `id` and osc properties (`id` and `address` are appended with `/$`)'
]},
},
style: {
@ -60,19 +60,19 @@ class Matrix extends Panel {
this.start = parseInt(this.getProp('start'))
if (parser.widgets[this.getProp('widgetType')]) {
for (let i = 0; i < this.getProp('quantity'); i++) {
var props = this.resolveProp('props', undefined, false, false, false, {'$':i + this.start})
var data = this.defaultProps(i + this.start)
var props = this.resolveProp('props', undefined, false, false, false, {'$':i})
var data = this.defaultProps(i)
if (typeof props === 'object' && props !== null) {
Object.assign(data, props)
}
data = JSON.parse(JSON.stringify(data).replace(/(JS|#|OSC|@|VAR)_\{/g, '$1{'))
var widget = parser.parse({
data: data,
parentNode: this.widget,
@ -126,12 +126,14 @@ class Matrix extends Panel {
for (let i = this.children.length - 1; i >= 0; i--) {
let data = this.resolveProp('props', undefined, false, false, false, {'$': i + this.start})
let data = this.resolveProp('props', undefined, false, false, false, {'$': i})
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
data = {}
}
data = JSON.parse(JSON.stringify(data).replace(/(JS|#|OSC|@|VAR)_\{/g, '$1{'))
if (typeof oldPropValue === 'object' && oldPropValue !== null) {
// if an overridden default props is removed, set it back to default
let overriddenDefaults,
@ -139,7 +141,7 @@ class Matrix extends Panel {
for (var k in oldPropValue) {
if (data[k] === undefined) {
if (Matrix.overriddenDefaults.indexOf(k) !== -1) {
overriddenDefaults = overriddenDefaults || this.defaultProps(i + this.start)
overriddenDefaults = overriddenDefaults || this.defaultProps(i)
data[k] = overriddenDefaults[k]
} else {
widgetDefaults = widgetDefaults || parser.defaults[data.type || this.getProp('widgetType')]

View file

@ -20,8 +20,8 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true, inte
style: {
_separator_text_style: 'Text style',
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.',
wrap: {type: 'boolean|string', value: false, choices: [false, true, 'soft'], help: [
'Set to `true` to wrap long lines automatically. Set to `soft` to avoid breaking words.',
]},
align: {type: 'string', value: 'center', choices: ['center', 'left', 'right', 'top', 'bottom', 'left top', 'left bottom', 'right top', 'right bottom'], help: 'Text alignment.'},
},
@ -46,7 +46,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true, inte
if (this.getProp('align').includes('top')) this.text.classList.add('top')
if (this.getProp('align').includes('bottom')) this.text.classList.add('bottom')
if (this.getProp('wrap')) this.text.classList.add('wrap')
if (this.getProp('wrap') === 'soft') this.text.classList.add('wrap-soft')
this.setValue(this.getProp('default'))

View file

@ -26,7 +26,10 @@ class Script extends Widget {
_separator: 'event: keyboard',
keyBinding: {type: 'string|array', value: '', help: 'Key combo `string` or `array` of strings (see <a href="https://github.com/RobertWHurst/KeyboardJS">KeyboardJS</a> documentation)'},
keyBinding: {type: 'string|array', value: '', help: [
'Key combo `string` or `array` of strings (see <a href="https://github.com/RobertWHurst/KeyboardJS">KeyboardJS</a> documentation).',
'If the editor is enabled, some keys / combos will not work.'
]},
keyRepeat: {type: 'boolean', value: true, help: 'Set to `false` to prevent keydown repeats when holding the key combo pressed'},
keyType: {type: 'string', value: 'keydown', choices: ['keydown', 'keyup', 'both'], help: 'Determines which key event trigger the script\'s execution'},
@ -145,6 +148,8 @@ class Script extends Widget {
keyboardCallback(e) {
if (e.catchedByEditor) return
if (e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT')) return
if (this.getProp('keyType') !== 'both' && e.type !== this.getProp('keyType')) return