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(){

View file

@ -138,7 +138,6 @@
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
@extend .glass-effect;
svg {
flex: 1 1 100%;
}
@ -150,12 +149,46 @@
background: transparent;
padding: 0!important;
.svg {
background: transparent;
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
&:not(.noborder) .svg {
@extend .glass-effect;
}
}
.html-container {
width:100rem;
height:100rem;
padding:1rem;
.html {
display: flex;
flex-direction: row;
flex: 1 1 100%;
background: var(--color-track);
border:1rem solid var(--color-bg);
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.html {
background: transparent;
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
&:not(.noborder) .html {
@extend .glass-effect;
}
}
.frame-container {
@ -213,10 +246,11 @@
.panel:not(.tab) > .plot-container,
.panel:not(.tab) > .image-container,
.panel:not(.tab) > .frame-container,
.panel:not(.tab) > .svg-container {
.panel:not(.tab) > .svg-container,
.panel:not(.tab) > .html-container {
--color-border:transparent;
padding: 0rem;
.plot, .text, .led, .image, .svg, .frame {
.plot, .text, .led, .image, .svg, .html, .frame {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);