console: unified widget error, with quick edit link from the console
This commit is contained in:
parent
6000d1a67a
commit
a8e0ac344a
9 changed files with 62 additions and 22 deletions
|
|
@ -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`
|
||||
<osc-console-message class="${type}">
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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', `<span class="edit-widget" data-widget="${widget.hash}">${id}</span>.${name} ${type} error${line}: ${error}`, true)
|
||||
}
|
||||
|
||||
setContainerStyles(styles = ['geometry', 'css', 'visibility']) {
|
||||
|
||||
if (styles.includes('geometry')) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue