client: integrate nanohtml in widget constructors

This commit is contained in:
bordun 2018-10-29 11:26:22 +01:00
parent db74dcc4cd
commit cfe2b122f8
26 changed files with 83 additions and 94 deletions

View file

@ -22,7 +22,7 @@ class Dropdown extends Widget {
constructor(options) {
super({...options, html: '<div class="select"></div>'})
super({...options, html: html`<div class="select"></div>`})
this.select = this.widget.appendChild(html`<select class="no-keybinding"></select>`)

View file

@ -1,5 +1,6 @@
var Widget = require('../common/widget'),
osc = require('../../osc')
osc = require('../../osc'),
html = require('nanohtml')
class Push extends Widget {
@ -26,7 +27,7 @@ class Push extends Widget {
constructor(options) {
super({...options, html: '<div class="toggle"></div>'})
super({...options, html: html`<div class="toggle"></div>`})
this.state = 0
this.active = 0

View file

@ -23,7 +23,7 @@ module.exports = class Switch extends Widget {
constructor(options) {
super({...options, html: '<div class="switch"></div>'})
super({...options, html: html`<div class="switch"></div>`})
if (this.getProp('horizontal')) this.widget.classList.add('horizontal')

View file

@ -1,5 +1,6 @@
var Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap')
doubletab = require('../mixins/double_tap'),
html = require('nanohtml')
class Toggle extends Widget {
@ -26,7 +27,7 @@ class Toggle extends Widget {
constructor(options) {
super({...options, html: '<div class="toggle"></div>'})
super({...options, html: html`<div class="toggle"></div>`})
this.state = 0
this.active = false

View file

@ -132,7 +132,7 @@ class Widget extends EventEmitter {
super()
this.widget = DOM.create(options.html)
this.widget = options.html
this.props = options.props
this.errors = {}
this.parsers = {}

View file

@ -3,7 +3,8 @@ var Container = require('../common/container'),
resize = require('../../events/resize'),
parser = require('../../parser'),
{deepCopy, deepEqual} = require('../../utils'),
{diff, diffToWidget} = require('../../editor/diff')
{diff, diffToWidget} = require('../../editor/diff'),
html = require('nanohtml')
var excludedCloneClasses = ['widget', 'absolute-position', 'ui-resizable', 'ui-draggable', 'not-editable']
@ -30,7 +31,7 @@ class Clone extends Container {
options.props.label = ''
options.props.variables = '@{parent.variables}'
super({...options, html: '<div class="clone"></div>'})
super({...options, html: html`<div class="clone"></div>`})
this.cloneLock = false
this.cloneTarget = null

View file

@ -35,7 +35,7 @@ class Panel extends Container {
constructor(options) {
super({...options, html: '<div class="panel"></div>'})
super({...options, html: html`<div class="panel"></div>`})
if (this.getProp('scroll') === false) this.widget.classList.add('noscroll')
if (this.getProp('border') === false) this.container.classList.add('noborder')

View file

@ -1,6 +1,6 @@
var Widget = require('../common/widget'),
GyroNorm = require('gyronorm/dist/gyronorm.complete.min.js'),
{iconify} = require('../../ui/utils'),
{icon} = require('../../ui/utils'),
{clip} = require('../utils')
class Gyroscope extends Widget {
@ -41,9 +41,9 @@ class Gyroscope extends Widget {
constructor(options) {
var html = `
var html = html`
<div class="gyroscope">
${iconify('^compass')}
${raw(icon('compass'))}
</div>
`

View file

@ -21,13 +21,11 @@ module.exports = class Input extends Canvas {
constructor(options) {
var htmlx = `
super({...options, html: html`
<div class="input">
<canvas></canvas>
</div>
`
super({...options, html: htmlx})
`})
this.value = ''
this.stringValue = ''

View file

@ -1,5 +1,5 @@
var Widget = require('../common/widget'),
{iconify} = require('../../ui/utils'),
{icon} = require('../../ui/utils'),
keyboardJS = require('keyboardjs'),
html = require('nanohtml')
@ -30,13 +30,11 @@ class Keys extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="keys">
${iconify('^keyboard')}
${raw(icon('keyboard'))}
</div>
`
super({...options, html: html})
`})
if (this.getProp('binding')) {

View file

@ -1,6 +1,7 @@
var Widget = require('../common/widget'),
widgetManager = require('../../managers/widgets'),
{iconify} = require('../../ui/utils')
{icon} = require('../../ui/utils'),
html = require('nanohtml')
class Script extends Widget {
@ -28,13 +29,11 @@ class Script extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="script">
${iconify('^code')}
${raw(icon('code'))}
</div>
`
super({...options, html: html})
`})
}

View file

@ -1,7 +1,8 @@
var Widget = require('../common/widget'),
widgetManager = require('../../managers/widgets'),
{math} = require('../utils'),
Input = require('../inputs/input')
Input = require('../inputs/input'),
html = require('nanohtml')
module.exports = class Formula extends Widget {
@ -22,11 +23,10 @@ module.exports = class Formula extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="formula">
</div>
`
super({...options, html: html})
`})
this.formulaString = String(this.getProp('formula'))

View file

@ -1,12 +1,13 @@
var Container = require('../common/container'),
{enableTraversingGestures} = require('../../events/drag')
{enableTraversingGestures} = require('../../events/drag'),
html = require('nanohtml')
module.exports = class _matrix_base extends Container {
constructor(options) {
super({...options, html: '<div class="matrix"></div>'})
super({...options, html: html`<div class="matrix"></div>`})
this.value = []

View file

@ -1,18 +1,17 @@
var Canvas = require('../common/canvas')
var Canvas = require('../common/canvas'),
html = require('nanohtml')
module.exports = class Pad extends Canvas {
constructor(options) {
var html = `
super({...options, html: html`
<div class="pad">
<div class="wrapper">
<canvas></canvas>
</div>
</div>
`
super({...options, html: html})
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]

View file

@ -1,17 +1,16 @@
var {mapToScale} = require('../utils'),
Canvas = require('../common/canvas')
Canvas = require('../common/canvas'),
html = require('nanohtml')
module.exports = class _plots_base extends Canvas {
constructor(options) {
var html = `
super({...options, html: html`
<div class="plot">
<canvas></canvas>
</div>
`
super({...options, html: html})
`})
this.value = []
this.rangeX = this.getProp('rangeX') || {min:0,max:1}

View file

@ -30,7 +30,7 @@ class Frame extends Widget {
constructor(options) {
super({...options, html: '<div class="frame"><iframe src=""></iframe></div>'})
super({...options, html: html`<div class="frame"><iframe src=""></iframe></div>`})
if (!this.getProp('border')) this.container.classList.add('noborder')

View file

@ -1,5 +1,6 @@
var Widget = require('../common/widget'),
ipc = require('../../ipc')
ipc = require('../../ipc'),
html = require('nanohtml')
module.exports = class Led extends Widget {
@ -31,11 +32,7 @@ module.exports = class Led extends Widget {
constructor(options) {
var html = `
<div class="image"></div>
`
super({...options, html: html})
super({...options, html: html`<div class="image"></div>`})
if (!this.getProp('border')) this.container.classList.add('noborder')

View file

@ -1,5 +1,6 @@
var {mapToScale} = require('../utils'),
Widget = require('../common/widget')
Widget = require('../common/widget'),
html = require('nanohtml')
module.exports = class Led extends Widget {
@ -24,12 +25,7 @@ module.exports = class Led extends Widget {
delete options.props.widgetId
}
var html = `
<div class="led">
</div>
`
super({...options, html: html})
super({...options, html: html`<div class="led"></div>`})
this.setValue(this.getProp('range').min)

View file

@ -1,5 +1,6 @@
var Widget = require('../common/widget'),
{clip} = require('../utils')
{clip} = require('../utils'),
html = require('nanohtml')
module.exports = class Rbgled extends Widget {
@ -25,12 +26,10 @@ module.exports = class Rbgled extends Widget {
delete options.props.widgetId
}
var html = `
super({...options, html: html`
<div class="led">
</div>
`
super({...options, html: html})
`})
this.setValue([0,0,0,0])

View file

@ -24,13 +24,11 @@ class Svg extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="svg">
<svg></svg>
</div>
`
super({...options, html: html})
`})
this.height = undefined
this.width = undefined

View file

@ -1,5 +1,6 @@
var {iconify} = require('../../ui/utils'),
Widget = require('../common/widget')
Widget = require('../common/widget'),
html = require('nanohtml')
module.exports = class Text extends Widget {
@ -27,7 +28,7 @@ module.exports = class Text extends Widget {
options.props.value = '@{' + options.props.widgetId + '}'
delete options.props.widgetId
}
super({...options, html: '<div class="text"></div>'})
super({...options, html: html`<div class="text"></div>`})
if (this.getProp('vertical')) this.widget.classList.add('vertical')
if (this.getProp('align') === 'left') this.widget.classList.add('left')

View file

@ -1,7 +1,8 @@
var {clip} = require('../utils'),
Knob = require('./knob'),
Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap')
doubletab = require('../mixins/double_tap'),
html = require('nanohtml')
@ -58,13 +59,12 @@ module.exports = class Encoder extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="encoder">
<div class="wrapper">
</div>
</div>
`
super({...options, html: html})
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.ticks = Math.abs(parseInt(this.getProp('ticks')))

View file

@ -112,26 +112,28 @@ module.exports = class Fader extends Slider {
this.widget.classList.add('has-pips')
var pips = this.wrapper.appendChild(html`<div class="pips"></div>`)
var pipTexts = {}
for (var k in this.rangeKeys) {
pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
}
var pipsInner = ''
var pips = html`<div class="pips"></div>`
for (var i=0;i<=100;i++) {
if (pipTexts[i]==undefined) continue
var pos = this.getProp('horizontal')?'left':'bottom'
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
pips.appendChild(html`
<div class="pip val" style="${pos}:${i}%">
<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>
</div>
`)
var add = `
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
`
pipsInner = pipsInner + add
}
pips.innerHTML = pipsInner
this.wrapper.appendChild(pips)
}

View file

@ -2,7 +2,8 @@ var {clip} = require('../utils'),
Widget = require('../common/widget'),
Fader = require('./fader'),
Input = require('../inputs/input'),
touchstate = require('../mixins/touch_state')
touchstate = require('../mixins/touch_state'),
html = require('nanohtml')
var faderDefaults = Fader.defaults()._props()
@ -211,13 +212,11 @@ module.exports = class Range extends Widget {
constructor(options) {
var html = `
super({...options, html: html`
<div class="range">
<div class="wrapper"></div>
</div>
`
super({...options, html: html})
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]

View file

@ -2,21 +2,20 @@ var {clip, mapToScale} = require('../utils'),
Canvas = require('../common/canvas'),
touchstate = require('../mixins/touch_state'),
doubletab = require('../mixins/double_tap'),
Input = require('../inputs/input')
Input = require('../inputs/input'),
html = require('nanohtml')
class Slider extends Canvas {
constructor(options) {
var html = `
super({...options, html: html`
<div class="slider">
<div class="wrapper">
<canvas></canvas>
</div>
</div>
`
super({...options, html: html})
`})
this.wrapper = DOM.get(this.widget, '.wrapper')[0]

View file

@ -1,5 +1,6 @@
var _switchers_base = require('./_switchers_base'),
Switch = require('../buttons/switch')
Switch = require('../buttons/switch'),
html = require('nanohtml')
var switchDefaults = Switch.defaults()._props()
@ -27,7 +28,7 @@ module.exports = class Switcher extends _switchers_base {
constructor(options) {
super({...options, html: '<div class="switcher"></div>'})
super({...options, html: html`<div class="switcher"></div>`})
if (this.getProp('horizontal')) this.widget.classList.add('horizontal')