diff --git a/src/client/ui/ui-console.js b/src/client/ui/ui-console.js index c65f98da..d4e8eb28 100644 --- a/src/client/ui/ui-console.js +++ b/src/client/ui/ui-console.js @@ -26,18 +26,18 @@ class UiConsole extends UiSidePanel { this.length = 0 this.maxLength = 200 - var _this = this, - log = console.log, - error = console.error + var _this = this + console._log = console.log console.log = function(message){ _this.log('log', message) - log(...arguments) + console._log(...arguments) } + console._error = console.error console.error = function(message){ _this.log('error', message) - error(...arguments) + console._error(...arguments) } // this.input.addEventListener('keydown', (event)=>{ @@ -63,7 +63,7 @@ class UiConsole extends UiSidePanel { } - log(type, message) { + log(type, message, html) { var node = this.messages.appendChild(html` @@ -81,7 +81,11 @@ class UiConsole extends UiSidePanel { } } - node.textContent = message + if (html) { + node.innerHTML = message + } else { + node.textContent = message + } if (type !== 'error' && node.textContent.match(/error/i)) node.classList.add('error') node.scrollIntoView() diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index a9ecad9a..da9c079d 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -2,6 +2,7 @@ var EventEmitter = require('../../events/event-emitter'), osc = require('../../osc'), nanoid = require('nanoid/generate'), widgetManager = require('../../managers/widgets'), + uiConsole = require('../../ui/ui-console'), {urlParser} = require('../utils'), Vm = require('../vm'), vm = new Vm(), @@ -215,6 +216,7 @@ class Widget extends EventEmitter { script: this.getProp('script'), event: 'value' }, builtIn: true, parent: this}) + this.script._not_editable = true this.on('change', (e)=>{ if (e.widget === this && this.mounted && !e.options.fromEdit) { this.script.setValue(e.options.widget ? e.options.widget.value : this.value, {...e.options, id: e.options.id || e.id}) @@ -659,9 +661,7 @@ class Widget extends EventEmitter { }) } catch (err) { - let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', - line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.error((this.getProp('id') || this.props.id) + '.' + propName + ': JS{{}} error:\n' + err + line) + this.errorProp(propName, 'JS{{}}', err) } try { @@ -680,9 +680,7 @@ class Widget extends EventEmitter { }) } catch (err) { - let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', - line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.error((this.getProp('id') || this.props.id) + '.' + propName + ': #{} error:\n' + err + line) + this.errorProp(propName, '#{}', err) } for (let k in variables) { @@ -878,6 +876,25 @@ class Widget extends EventEmitter { } + errorProp(name, type, error) { + + let stackline = error.stack ? (error.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', + line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - (type.includes('{}') ? 1 : 0)) : '', + id = this.getProp('id') || this.props.id, + widget = this // used for edit link in console + + while (widget._not_editable) { + // ignore non editable + widget = widget.parent + } + + // ignore clone wrapper + if (widget.parent !== widgetManager && widget.parent.getProp('type') === 'clone') widget = widget.parent + + console._error(`${id}.${name} ${type} error${line}: ${error}`) + uiConsole.log('error', `${id}.${name} ${type} error${line}: ${error}`, true) + } + setContainerStyles(styles = ['geometry', 'css', 'visibility']) { if (styles.includes('geometry')) { diff --git a/src/client/widgets/containers/clone.js b/src/client/widgets/containers/clone.js index 6a7b2d50..495576c9 100644 --- a/src/client/widgets/containers/clone.js +++ b/src/client/widgets/containers/clone.js @@ -27,7 +27,7 @@ class Clone extends Container() { value: null, osc: null }) - + defaults.style = {css: defaults.style.css} return defaults @@ -98,6 +98,7 @@ class Clone extends Container() { if (e.widget !== this) { e.widget.container.classList.add('not-editable') + e.widget._not_editable = true } }) diff --git a/src/client/widgets/containers/keyboard.js b/src/client/widgets/containers/keyboard.js index 00616517..73e22603 100644 --- a/src/client/widgets/containers/keyboard.js +++ b/src/client/widgets/containers/keyboard.js @@ -133,6 +133,7 @@ class Keyboard extends Panel { key._index = i - start key.container.classList.add('not-editable') + key._not_editable = true key.container.classList.add('key') if (pattern[i % 12] == 'w') { diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index e2f12132..8e2f56f2 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -80,6 +80,7 @@ class Matrix extends Panel { widget._index = i widget.container.classList.add('not-editable') + widget._not_editable = true this.value[i] = widget.getValue() @@ -152,6 +153,7 @@ class Matrix extends Panel { this.children[i].updateProps(Object.keys(data), this, options) // this.children[i] might have been recreated this.children[i].container.classList.add('not-editable') + this.children[i]._not_editable = true } diff --git a/src/client/widgets/containers/patchbay.js b/src/client/widgets/containers/patchbay.js index e2a7e429..eb810919 100644 --- a/src/client/widgets/containers/patchbay.js +++ b/src/client/widgets/containers/patchbay.js @@ -150,6 +150,7 @@ class PatchBay extends Container(Canvas) { parent: this }) w.container.classList.add('not-editable') + w._not_editable = true this.inputsWidgets.push(w) this.inputNodes.push(w.container) } diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 239fbe90..9f0ac7fa 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -271,7 +271,7 @@ class ScriptVm extends Vm { try { callback() } catch(e) { - console.log(e) + this.errorProp('script', 'setTimeout', e) } this.setWidget() this.setValueOptions() @@ -309,7 +309,7 @@ class ScriptVm extends Vm { try { callback() } catch(e) { - console.log(e) + this.errorProp('script', 'setInterval', e) } this.setWidget() this.setValueOptions() diff --git a/src/client/widgets/scripts/script.js b/src/client/widgets/scripts/script.js index 0108bdb6..fba775f3 100644 --- a/src/client/widgets/scripts/script.js +++ b/src/client/widgets/scripts/script.js @@ -89,9 +89,7 @@ class Script extends Widget { } catch(err) { - let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', - line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.error((this.getProp('id') || this.props.id) + '.script error:\n' + err + line) + this.errorProp('script', 'javascript', err) this.script = ()=>{} } @@ -108,9 +106,7 @@ class Script extends Widget { try { this.script(context, this.builtIn ? this.parent.parsersLocalScope : this.parsersLocalScope) } catch(err) { - let stackline = err.stack ? (err.stack.match(/>:([0-9]+):[0-9]+/) || '') : '', - line = stackline.length > 1 ? ' at line ' + (parseInt(stackline[1]) - 2) : '' - console.error((this.getProp('id') || this.props.id) + '.script error:\n' + err + line) + this.errorProp('script', 'javascript', err) } this.scriptLock = false diff --git a/src/scss/ui/console.scss b/src/scss/ui/console.scss index 2a7f8430..57f59991 100644 --- a/src/scss/ui/console.scss +++ b/src/scss/ui/console.scss @@ -51,9 +51,27 @@ osc-console-message { white-space: pre; &.error { color: var(--color-error); + --color-stroke: var(--color-error); } margin-bottom: 4rem; + + .edit-widget { + cursor: pointer; + display: inline-block; + padding: 2rem; + background: var(--color-ui-background); + border-radius: 2rem; + user-select: inherit; + &.editing { + --alpha-stroke: 0.75; + position: relative; + @include pseudo-stroke($z: 0); + &:before { + border-style: dashed; + } + } + } } osc-console-input {