diff --git a/CHANGELOG.md b/CHANGELOG.md index 4838b840..a914306d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,17 @@ # Changelog -## 0.23.2 +## 0.24.0 - bug fixes - regression preventing dropdown to display no option selected - crossfaders display issue on iOS - restored compatibility options for server-client communications - - prevent client to load multiple sessions simultaneously + - prevent client to load multiple sessions simultaneously - widgets - switch: wrap non-array `values` property in an array - dropdown: wrap non-array `values` property in an array; allow setting value by its key/index; add `sendKey` option; + - property inheritance: added shorthand default to `_value` when no property is specified (`@{widgetId}`); some properties can now be dynamically changed without recreating the widget entirely + - property maths: added support for math expressions everywhere via `#{}` - input: add glass effect when `editable` is `false` ## 0.23.1 diff --git a/resources/docs/extras/property-inheritance.md b/resources/docs/extras/property-inheritance.md index f4da6a55..e56bb148 100644 --- a/resources/docs/extras/property-inheritance.md +++ b/resources/docs/extras/property-inheritance.md @@ -22,6 +22,8 @@ If the retreived property is an object (`[] / {}`), a subset can be defined by a The special property name `_value`flash_on refers to a widget's value, as opposed to its `value` property. +When omitted, the property name defaults to `_value` : `@{widgetId}` => `@{widgetId._value}` + ## Dynamic properties Some properties, when changed, trigger a complete widget recreation that ends any ongoing user interaction. Also, updating these properties continuously (e.g. when linked to a slider's dynamic value) can be very cpu expensive. diff --git a/resources/docs/extras/property-maths b/resources/docs/extras/property-maths new file mode 100644 index 00000000..e4cecae2 --- /dev/null +++ b/resources/docs/extras/property-maths @@ -0,0 +1,19 @@ +# Property maths + +The following syntax allow writing mathematical formulas in widgets' properties: + +``` +#{ FORMULA } +``` + +Where FORMULA is a valid [MathJS](http://mathjs.org/docs/expressions/syntax.html) expression: + +- [syntax documentation](http://mathjs.org/docs/expressions/syntax.html) +- [available functions](http://mathjs.org/docs/reference/functions.html) +- [available constants](http://mathjs.org/docs/reference/constants.html) +- property inheritance calls (`@{...}`) are always resolved before formulas +- arrays / matrices indexes are **zero-based** (ie `['a','b'][0]` returns `'a'`) + +Additionnal functions: + +- `unpack`: remove an array's brackets (`unpack([1,2])` returns `'1, 2'`) diff --git a/src/browser/js/app/widgets/common/_widgets_base.js b/src/browser/js/app/widgets/common/_widgets_base.js index 9b3679a3..2acada88 100644 --- a/src/browser/js/app/widgets/common/_widgets_base.js +++ b/src/browser/js/app/widgets/common/_widgets_base.js @@ -208,15 +208,27 @@ module.exports = class _widgets_base extends EventEmitter { if (typeof propValue == 'string') { propValue = propValue.replace(/@\{([^\}]+)\}/g, (m)=>{ let id = m.substr(2, m.length - 3).split('.'), - k = id.pop(), - subk = undefined + k, subk if (id.length > 1) { - subk = k + k = id.pop() + subk = undefined + + if (id.length > 1) { + subk = k + k = id.pop() + } + + id = id.join('.') + + } else { + + id = id[0] + k = '_value' + } - id = id.join('.') var widgets = id == 'parent' && this.parent ? [this.parent] : id == 'this' ? [this] :