client: continue nanohtml integration and avoid some innerHTML calls
This commit is contained in:
parent
bf074ff810
commit
7312e2db98
3 changed files with 28 additions and 20 deletions
|
|
@ -4,7 +4,8 @@ var widgetCategories = require('../widgets/').categories,
|
|||
{deepCopy} = require('../utils'),
|
||||
{icon, Popup} = require('../ui/utils'),
|
||||
locales = require('../locales'),
|
||||
html = require('nanohtml')
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw')
|
||||
|
||||
module.exports = function editField(editor, widget, propName, defaultValue){
|
||||
|
||||
|
|
@ -31,16 +32,18 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
}
|
||||
|
||||
input = html`<select class="input no-keybinding"/>`
|
||||
var innerHTML = ''
|
||||
|
||||
for (let category in widgetCategories) {
|
||||
innerHTML += `<optgroup label="> ${category}">`
|
||||
var optGroup = html`<optgroup label="> ${category}"></optgroups>`
|
||||
for (let type of widgetCategories[category]) {
|
||||
innerHTML += `<option ${type == widget.props.type ? 'selected' : ''} value="${type}">${type}</option>`
|
||||
optGroup.appendChild(html`
|
||||
<option ${type == widget.props.type ? 'selected' : ''} value="${type}">
|
||||
${type}
|
||||
</option>
|
||||
`)
|
||||
}
|
||||
innerHTML += '</optgroup>'
|
||||
input.appendChild(optGroup)
|
||||
}
|
||||
input.innerHTML = innerHTML
|
||||
|
||||
var wrapper = html`<div class="select-wrapper"></div>`
|
||||
wrapper.appendChild(input)
|
||||
|
|
@ -70,7 +73,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
|
||||
let toggle = html`
|
||||
<span class="checkbox ${widget.getProp(propName) ? 'on' : ''}">
|
||||
${icon('check')}
|
||||
${raw(icon('check'))}
|
||||
</span>
|
||||
`
|
||||
|
||||
|
|
@ -193,10 +196,10 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
label.addEventListener('fast-click', ()=>{
|
||||
|
||||
var htmlHelp = Array.isArray(defaultValue.help) ? defaultValue.help.join('<br/><br/>').replace(/<br\/>-/g, '-') : defaultValue.help
|
||||
htmlHelp = htmlHelp ? '<p class="help">' + htmlHelp.replace(/`([^`]*)`/g, '<code>$1</code>') + '</p>' : ''
|
||||
htmlHelp = htmlHelp ? html`<p class="help">${raw(htmlHelp.replace(/`([^`]*)`/g, '<code>$1</code>'))}</p>` : ''
|
||||
|
||||
|
||||
var htmlError = error ? `<p class="error">${error}</p>` : '',
|
||||
var htmlError = error ? html`<p class="error">${error}</p>` : '',
|
||||
computedValue = propName !== 'tabs' && propName !== 'widgets' ? widget.getProp(propName) : ['...']
|
||||
|
||||
if (typeof computedValue === 'string') {
|
||||
|
|
@ -207,7 +210,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
computedValue = JSON.stringify(computedValue, null, ' ')
|
||||
}
|
||||
|
||||
new Popup({closable: true, title: `<span class="editor-help-title">${propName}</span>`, content: `
|
||||
new Popup({closable: true, title: html`<span class="editor-help-title">${propName}</span>`, content: html`
|
||||
<div class="editor-help">
|
||||
|
||||
<p>Type: <code>${defaultValue.type}</code></p>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
var Widget = require('../common/widget'),
|
||||
{iconify} = require('../../ui/utils'),
|
||||
html = require('nanohtml')
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw')
|
||||
|
||||
class Dropdown extends Widget {
|
||||
|
||||
|
|
@ -44,25 +45,27 @@ class Dropdown extends Widget {
|
|||
parseValues() {
|
||||
|
||||
var i = 0,
|
||||
values = this.getProp('values'),
|
||||
html = ''
|
||||
values = this.getProp('values')
|
||||
|
||||
if (!Array.isArray(values) && !(typeof values === 'object' && values !== null)) {
|
||||
values = values !== '' ? [values] : []
|
||||
}
|
||||
|
||||
html += '<option value=""></option>'
|
||||
this.select.innerHTML = ''
|
||||
this.select.appendChild(html`<option value=""></option>`)
|
||||
|
||||
this.values = []
|
||||
|
||||
for (var k in values) {
|
||||
this.values.push(values[k])
|
||||
html += `<option value="${i}">${iconify(parseFloat(k) != k ? k : values[k])}</option>`
|
||||
this.select.appendChild(html`
|
||||
<option value="${i}">
|
||||
${raw(iconify(parseFloat(k) != k ? k : values[k]))}
|
||||
</option>
|
||||
`)
|
||||
i++
|
||||
}
|
||||
|
||||
this.select.innerHTML = html
|
||||
|
||||
}
|
||||
|
||||
setValue(v,options={}) {
|
||||
|
|
|
|||
|
|
@ -129,18 +129,20 @@ class Panel extends Container {
|
|||
this.navigation.innerHTML = ''
|
||||
this.tabs = []
|
||||
|
||||
var html = ''
|
||||
DOM.each(this.wrapper, '> .widget', (tab)=>{
|
||||
|
||||
let widget = widgetManager.getWidgetByElement(tab),
|
||||
style = widget.getProp('color') == 'auto' ? '' : `style="--color-custom:${widget.getProp('color')}"`
|
||||
|
||||
this.tabs.push(widget)
|
||||
html += `<li class="tablink" data-widget="${widget.hash}" ${style}><a><span>${DOM.get(tab, '> .label')[0].innerHTML}</span></a></li>`
|
||||
this.navigation.appendChild(html`
|
||||
<li class="tablink" data-widget="${widget.hash}" ${style}>
|
||||
<a><span>${DOM.get(tab, '> .label')[0].innerHTML}</span></a>
|
||||
</li>
|
||||
`)
|
||||
|
||||
})
|
||||
|
||||
this.navigation.innerHTML = html
|
||||
|
||||
this.setValue(this.value)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue