uimodal tweak, inspector help modal

This commit is contained in:
bordun 2020-03-06 20:18:40 +01:00
parent b090657b69
commit 2c86691bb8
14 changed files with 148 additions and 188 deletions

View file

@ -21,15 +21,16 @@ class ColorPicker extends UiWidget {
...Rgb.defaults()._props(),
type: 'rgb',
label: false,
width: 250,
height: 200,
width: 'auto',
height: 'auto',
alphaStroke: 0,
snap: true
// height: '100%',
snap: true,
}, parent: this})
this.rgb.container.classList.add('not-editable')
this.modal = new UiModal({
width: 280,
height: 280,
closable: true,
title: '',
hide: true,

View file

@ -15,6 +15,7 @@ module.exports = function UiFilebrowser(options, callback) {
previousKbContext = keyboardJS.getContext()
var popup = new UiModal({
height: 360,
closable: true,
title: locales(save ? 'remotesave_save' : 'remotesave_open'),
hide: true

View file

@ -1,10 +1,12 @@
var UiWidget = require('./ui-widget'),
UiInspectorField = require('./ui-inspector-field'),
UiColorPicker = require('./ui-colorpicker'),
UiModal = require('./ui-modal'),
morph = require('nanomorph'),
{widgets, defaults} = require('../widgets/'),
{deepCopy} = require('../utils'),
html = require('nanohtml')
html = require('nanohtml'),
raw = require('nanohtml/raw')
@ -19,6 +21,8 @@ class UiInspector extends UiWidget {
this.foldedCategories = []
this.widget = null
this.container.addEventListener('fast-click', (e)=>{
if (e.target.classList.contains('category-header')) {
@ -64,6 +68,10 @@ class UiInspector extends UiWidget {
this.colorPicker.setValue(node.getAttribute('value'))
this.colorPicker.open()
} else if (node.tagName === 'LABEL') {
this.help(node.textContent)
}
})
@ -83,6 +91,7 @@ class UiInspector extends UiWidget {
clear() {
this.clearTimeout = setTimeout(()=>{
this.widget = null
this.container.innerHTML = ''
this.mounted = false
this.clearTimeout = null
@ -105,6 +114,8 @@ class UiInspector extends UiWidget {
multi = widgets.length > 1,
tabIndex = 1000
this.widget = widget
// this.form.appendChild(html`
// <div class="separator">
// <span class="${this.selectedWidgets.length > 1 ? 'accent' : ''}">
@ -241,6 +252,45 @@ class UiInspector extends UiWidget {
}
help(name) {
var defaultValue = defaults[this.widget.getProp('type')][name],
dynamic = this.widget.isDynamicProp(name),
htmlHelp = Array.isArray(defaultValue.help) ? defaultValue.help.join('<br/><br/>').replace(/<br\/>-/g, '-') : defaultValue.help
htmlHelp = htmlHelp ? html`<p class="help">${raw(htmlHelp.replace(/`([^`]*)`/g, '<code>$1</code>'))}</p>` : ''
DOM.each(htmlHelp, 'a', (el)=>{
el.target = '_blank'
})
var htmlError = false ? html`<p class="error">${error}</p>` : '',
computedValue = this.widget.getProp(name)
if (typeof computedValue === 'string') {
try {
computedValue = JSON.stringify(JSON.parse(computedValue), null, ' ')
} catch(e) {}
} else {
computedValue = JSON.stringify(computedValue, null, ' ')
}
new UiModal({closable: true, title: html`<span class="editor-help-title">${name}</span>`, content: html`
<div class="inspector-help">
<p>Type: <code>${defaultValue.type}</code></p>
<p>Default: <code>${JSON.stringify(defaultValue.value)}</code></p>
<p>Dynamic: <code>${dynamic ? 'true' : 'false'}</code></p>
<p>Computed: <code class="pre">${computedValue}</code></p>
${htmlError}
${htmlHelp}
</div>
`})
}
}
module.exports = UiInspector

View file

@ -4,7 +4,7 @@ var UiWidget = require('./ui-widget'),
raw = require('nanohtml/raw'),
MODAL_SINGLETON = null,
MODAL_CONTAINER = null
class UiModal extends UiWidget {
constructor(options) {
@ -41,6 +41,9 @@ class UiModal extends UiWidget {
</div>
`
if (options.width) this.container.style.setProperty('--width', options.width + 'rem')
if (options.height) this.container.style.setProperty('--height', options.height + 'rem')
if (options.closable) {
var closer = DOM.get(this.container, '.popup-title .closer')[0]
this.container.addEventListener('fast-click',(e)=>{

View file

@ -765,7 +765,8 @@ class Widget extends EventEmitter {
case 'visible':
this.setVisibility()
resize.check(this.container)
var container = this.parent !== widgetManager && this.parent.getProp('layout') !== 'default' ? this.parent.container : this.container
resize.check(container)
return
case 'interaction':