plots: add 'html' widget, and unify 'border' property among svg/image/html (#560)

This commit is contained in:
bordun 2019-09-11 22:02:27 +02:00
parent dca9cd9a8b
commit 0523c19b2a
6 changed files with 118 additions and 5 deletions

View file

@ -36,6 +36,7 @@ module.exports.widgets = {
text: require('./plots/text'),
image: require('./plots/image'),
svg: require('./plots/svg'),
html: require('./plots/html'),
frame: require('./plots/frame'),
// containers
@ -63,7 +64,7 @@ module.exports.categories = {
'Buttons':['toggle','push','switch', 'dropdown'],
'Pads':['xy','rgb','multixy'],
'Matrices':['matrix', 'keyboard', 'patchbay'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'frame'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'html', 'frame'],
'Containers':['panel','strip','modal', 'clone'],
'Switchers':['state', 'switcher','crossfader'],
'Inputs':['input', 'keys', 'script', 'gyroscope', 'file']

View file

@ -0,0 +1,72 @@
var Widget = require('../common/widget'),
morph = require('nanomorph'),
html = require('nanohtml'),
sanitizeHtml = require('sanitize-html')
var sanitizeOptions = {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe')
}
class Html extends Widget {
static defaults() {
return super.defaults({
_html:'html',
html: {type: 'string', value: '', help: [
'Allowed HTML tags:',
'  h1-6, blockquote, p, a, ul, ol, nl, li,',
'  b, i, strong, em, strike, code, hr, br, div,',
'  table, thead, img, caption, tbody, tr, th, td, pre'
]},
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
}, ['color', 'target', 'precision', 'bypass'], {})
}
constructor(options) {
super({...options, html: html`
<div class="html">
</div>
`})
if (!this.getProp('border')) this.container.classList.add('noborder')
}
updateHtml(){
var newHtml = html`<div class="html"></div>`
newHtml.innerHTML = sanitizeHtml(this.getProp('html'), sanitizeOptions)
morph(this.widget, newHtml)
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'html':
this.updateHtml()
return
}
}
}
Html.dynamicProps = Html.prototype.constructor.dynamicProps.concat(
'html'
)
module.exports = Html

View file

@ -15,7 +15,9 @@ class Svg extends Widget {
'Svg xml definition:',
'- will be wrapped in a `< svg />` element',
'- `<path>` commands support a special percent notation (`%x` and `%y`)'
]}
]},
border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'},
}, ['color', 'target', 'precision', 'bypass'], {})
@ -34,6 +36,8 @@ class Svg extends Widget {
this.on('resize', this.resizeHandleProxy.bind(this), {element: this.widget})
if (!this.getProp('border')) this.container.classList.add('noborder')
}
updateSvg(){