inspector: better layout for editor
This commit is contained in:
parent
661b2d60b0
commit
58872c2814
7 changed files with 92 additions and 84 deletions
|
|
@ -7,39 +7,39 @@ var UiWidget = require('./ui-widget'),
|
|||
ace = require('brace'),
|
||||
ScriptVm = require('../widgets/scripts/script-vm'),
|
||||
scriptGlobals = ScriptVm.globals,
|
||||
editors = {}
|
||||
editors = {}, editorModes = {
|
||||
javascript: require('brace/mode/javascript')
|
||||
}
|
||||
|
||||
// require('brace/mode/html')
|
||||
require('brace/mode/javascript')
|
||||
// require('brace/ext/searchbox')
|
||||
// require('brace/ext/keybinding_menu')
|
||||
|
||||
for (var name of ['script', 'draw', 'touch']) {
|
||||
editors[name] = ace.edit('editor-' + name)
|
||||
editors[name].getSession().setMode('ace/mode/javascript')
|
||||
editors[name].setOption('autoScrollEditorIntoView', true)
|
||||
editors[name].setOption('maxLines', 40)
|
||||
editors[name].setOption('blockScrolling', Infinity)
|
||||
editors[name].commands.bindKeys({'ctrl-l':null, 'ctrl-f': null,'cmd-l':null, 'cmd-f': null})
|
||||
editors[name].renderer.setScrollMargin(4, 4, 0, 4)
|
||||
editors[name].element = DOM.get('#editor-' + name)[0]
|
||||
editors[name].element.classList.add('ace_dark')
|
||||
editors[name].$mouseHandler.setOption('dragEnabled', false)
|
||||
editors[name].textarea = DOM.get('#editor-' + name + ' .ace_text-input')[0]
|
||||
editors[name].textarea.name = name
|
||||
editors[name].textarea._ace = true
|
||||
editors[name].setHighlightActiveLine(false)
|
||||
editors[name].setHighlightGutterLine(false)
|
||||
editors[name].getSession().$worker.send('setOptions', [{
|
||||
asi: true, // no semicolon
|
||||
esversion: 6,
|
||||
strict: 'implied',
|
||||
node: false,
|
||||
browser: true,
|
||||
validthis: true,
|
||||
undef: true,
|
||||
globals: {}
|
||||
}])
|
||||
function createEditor(name, language) {
|
||||
var el = html`<div id="#editor${name}"></div>`
|
||||
var editor = editors[name] = ace.edit(el)
|
||||
if (editorModes[language]) editor.getSession().setMode('ace/mode/' + language)
|
||||
editor.setOption('autoScrollEditorIntoView', true)
|
||||
editor.setOption('maxLines', 40)
|
||||
editor.setOption('blockScrolling', Infinity)
|
||||
editor.commands.bindKeys({'ctrl-l':null, 'ctrl-f': null,'cmd-l':null, 'cmd-f': null})
|
||||
editor.renderer.setScrollMargin(4, 4, 0, 4)
|
||||
editor.element = el
|
||||
editor.element.classList.add('ace_dark')
|
||||
editor.$mouseHandler.setOption('dragEnabled', false)
|
||||
editor.textarea = DOM.get(el, '.ace_text-input')[0]
|
||||
editor.textarea.name = name
|
||||
editor.textarea._ace = true
|
||||
editor.setHighlightActiveLine(false)
|
||||
editor.setHighlightGutterLine(false)
|
||||
if (language === 'javascript') {
|
||||
editor.getSession().$worker.send('setOptions', [{
|
||||
asi: true, // no semicolon
|
||||
esversion: 6,
|
||||
strict: 'implied',
|
||||
node: false,
|
||||
browser: true,
|
||||
validthis: true,
|
||||
undef: true,
|
||||
globals: {}
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -166,7 +166,9 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
if (['script', 'touch', 'draw'].includes(this.name)) {
|
||||
if (this.default.editor) {
|
||||
this.container.classList.add('has-editor')
|
||||
if (!editors[this.name]) createEditor(this.name, this.default.editor)
|
||||
let editor = editors[this.name]
|
||||
input.style.display = 'none'
|
||||
input._ace_input = editor.textarea
|
||||
|
|
@ -193,26 +195,28 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
})
|
||||
})
|
||||
let globals = {}
|
||||
if (this.name === 'script') {
|
||||
if (this.widget.type !== 'script' || this.widget.getProp('event') === 'value') {
|
||||
globals = {id: true, value: true, touch: true}
|
||||
} else if (this.widget.getProp('event') === 'keyboard') {
|
||||
globals = {type: true, key: true, code: true, ctrl: true, shift: true, alt: true, meta: true}
|
||||
if (this.default.editor === 'javascript') {
|
||||
let globals = {}
|
||||
if (this.name === 'script') {
|
||||
if (this.widget.type !== 'script' || this.widget.getProp('event') === 'value') {
|
||||
globals = {id: true, value: true, touch: true}
|
||||
} else if (this.widget.getProp('event') === 'keyboard') {
|
||||
globals = {type: true, key: true, code: true, ctrl: true, shift: true, alt: true, meta: true}
|
||||
}
|
||||
} else if (this.name === 'draw') {
|
||||
globals = {value: true, height: true, width: true, ctx: true, cssVars: true}
|
||||
} else if (this.name === 'touch') {
|
||||
globals = {value: true, height: true, width: true, event: true}
|
||||
}
|
||||
} else if (this.name === 'draw') {
|
||||
globals = {value: true, height: true, width: true, ctx: true, cssVars: true}
|
||||
} else if (this.name === 'touch') {
|
||||
globals = {value: true, height: true, width: true, event: true}
|
||||
}
|
||||
globals.locals = true
|
||||
globals.console = true
|
||||
globals.JS = true
|
||||
globals.this = false
|
||||
globals.locals = true
|
||||
globals.console = true
|
||||
globals.JS = true
|
||||
globals.this = false
|
||||
|
||||
editor.getSession().$worker.send('changeOptions', [{
|
||||
globals: {...scriptGlobals, ...globals}
|
||||
}])
|
||||
editor.getSession().$worker.send('changeOptions', [{
|
||||
globals: {...scriptGlobals, ...globals}
|
||||
}])
|
||||
}
|
||||
|
||||
this.container.appendChild(editor.element)
|
||||
setTimeout(()=>{
|
||||
|
|
|
|||
|
|
@ -148,13 +148,15 @@ class UiInspector extends UiWidget {
|
|||
if (field) field.classList.add('last-child')
|
||||
field = html`<div class="separator">${props[categoryName][propName]}</div>`
|
||||
} else {
|
||||
var def = defaults[widget.props.type][categoryName][propName]
|
||||
if (field && def.editor) field.classList.add('last-child')
|
||||
var first = !field || field.classList.contains('separator')
|
||||
field = new UiInspectorField({
|
||||
parent: this,
|
||||
widget: widget,
|
||||
name: propName,
|
||||
value: widget.props[propName],
|
||||
default: defaults[widget.props.type][categoryName][propName],
|
||||
default: def,
|
||||
tabIndex: tabIndex++
|
||||
}).container
|
||||
if (first) field.classList.add('first-child')
|
||||
|
|
@ -238,7 +240,7 @@ class UiInspector extends UiWidget {
|
|||
|
||||
if (event.keyCode === 13 &&
|
||||
((!event.shiftKey && !event.target._ace) ||
|
||||
(event.shiftKey && event.target._ace))
|
||||
(event.ctrlKey && event.target._ace))
|
||||
) {
|
||||
|
||||
event.preventDefault()
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class Widget extends EventEmitter {
|
|||
bypass: {type: 'boolean', value: false, help: 'Set to `true` to prevent the widget from sending any osc message'}
|
||||
},
|
||||
scripting: {
|
||||
script: {type: 'script', value: '', help: ['Script executed whenever the widget\'s value updates. See <a href="https://openstagecontrol.ammd.net/docs/widgets/scripting/">documentation</a>.']},
|
||||
script: {type: 'script', value: '', editor: 'javascript', help: ['Script executed whenever the widget\'s value updates. See <a href="https://openstagecontrol.ammd.net/docs/widgets/scripting/">documentation</a>.']},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ class CanvasWidget extends Canvas {
|
|||
'If set to `true`, `draw` will be called at each frame, otherwise it will be called only when the widget is touched and when it receives a value.',
|
||||
'Can be a number between 1 and 60 to specify the framerate (default: 30 fps).'
|
||||
]},
|
||||
touch: {type: 'string', value: '', help: [
|
||||
touch: {type: 'string', value: '', editor:'javascript', help: [
|
||||
'Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',
|
||||
]},
|
||||
draw: {type: 'string', value: '', help: [
|
||||
draw: {type: 'string', value: '', editor:'javascript', help: [
|
||||
'Script executed when the widget is redrawn. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.'
|
||||
]},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,28 +14,26 @@ class Script extends Widget {
|
|||
|
||||
static defaults() {
|
||||
|
||||
return super.defaults().extend({
|
||||
widget: {
|
||||
visible: null,
|
||||
interaction: null
|
||||
},
|
||||
geometry: null,
|
||||
style: null,
|
||||
scripting: {
|
||||
event: {type: 'string', value: 'value', choices: ['value', 'keyboard', 'once'], help: 'Define which events trigger the script\'s execution.'},
|
||||
var defaults = super.defaults()
|
||||
delete defaults.widget.visible
|
||||
delete defaults.widget.interaction
|
||||
delete defaults.geometry
|
||||
delete defaults.style
|
||||
defaults.scripting = {
|
||||
event: {type: 'string', value: 'value', choices: ['value', 'keyboard', 'once'], help: 'Define which events trigger the script\'s execution.'},
|
||||
script: {type: 'script', value: '', editor:'javascript', help: 'Script executed whenever the widget receives the defined event. See <a href="https://openstagecontrol.ammd.net/docs/widgets/scripting/">documentation</a>.'},
|
||||
|
||||
_separator: 'event: keyboard',
|
||||
_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).',
|
||||
'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'},
|
||||
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'},
|
||||
|
||||
script: {type: 'script', value: '', help: 'Script executed whenever the widget receives the defined event. See <a href="https://openstagecontrol.ammd.net/docs/widgets/scripting/">documentation</a>.'},
|
||||
}
|
||||
})
|
||||
}
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue