dom: batch dom operations that trigger layout calculation
panel: store raw scroll when scrolling and use that value when the editor needs it (avoids many layout trashing)
This commit is contained in:
parent
2225a3f760
commit
876c3277b2
8 changed files with 137 additions and 98 deletions
|
|
@ -1,6 +1,7 @@
|
|||
var UiWidget = require('./ui-widget'),
|
||||
keyboardJS = require('keyboardjs/dist/keyboard.min.js'),
|
||||
html = require('nanohtml'),
|
||||
fastdom = require('fastdom'),
|
||||
Tab, Root
|
||||
|
||||
class UiDragResize extends UiWidget {
|
||||
|
|
@ -154,9 +155,10 @@ class UiDragResize extends UiWidget {
|
|||
this.initWidth = this.width
|
||||
this.initHeight = this.height
|
||||
|
||||
this.widgets[0].parentNode.appendChild(this.container)
|
||||
this.mounted = true
|
||||
|
||||
fastdom.mutate(()=>{
|
||||
this.widgets[0].parentNode.appendChild(this.container)
|
||||
this.mounted = true
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -172,24 +174,33 @@ class UiDragResize extends UiWidget {
|
|||
]
|
||||
handlesVisibility.push(handlesVisibility[1] && handlesVisibility[2]) // se
|
||||
|
||||
for (var i in handlesVisibility) {
|
||||
this.handles[i].style.display = handlesVisibility[i] ? '' : 'none'
|
||||
}
|
||||
fastdom.measure(()=>{
|
||||
|
||||
var lefts = widgets.map(w => w.container.offsetLeft),
|
||||
tops = widgets.map(w => w.container.offsetTop),
|
||||
rights = widgets.map(w => w.container.offsetLeft + w.container.offsetWidth),
|
||||
bottoms = widgets.map(w => w.container.offsetTop + w.container.offsetHeight)
|
||||
var lefts = widgets.map(w => w.container.offsetLeft),
|
||||
tops = widgets.map(w => w.container.offsetTop),
|
||||
rights = widgets.map(w => w.container.offsetLeft + w.container.offsetWidth),
|
||||
bottoms = widgets.map(w => w.container.offsetTop + w.container.offsetHeight)
|
||||
|
||||
this.left = Math.min(...lefts) / PXSCALE
|
||||
this.top = Math.min(...tops) / PXSCALE
|
||||
this.width = (Math.max(...rights) - Math.min(...lefts)) / PXSCALE
|
||||
this.height = (Math.max(...bottoms) - Math.min(...tops)) / PXSCALE
|
||||
this.left = Math.min(...lefts) / PXSCALE
|
||||
this.top = Math.min(...tops) / PXSCALE
|
||||
this.width = (Math.max(...rights) - Math.min(...lefts)) / PXSCALE
|
||||
this.height = (Math.max(...bottoms) - Math.min(...tops)) / PXSCALE
|
||||
|
||||
// this.cssTransform = widget.cssTransform || 'none'
|
||||
// this.cssTransformOrigin = widget.cssTransformOrigin
|
||||
fastdom.mutate(()=>{
|
||||
|
||||
for (var i in handlesVisibility) {
|
||||
this.handles[i].style.display = handlesVisibility[i] ? '' : 'none'
|
||||
}
|
||||
|
||||
this.updateCss()
|
||||
|
||||
// this.cssTransform = widget.cssTransform || 'none'
|
||||
// this.cssTransformOrigin = widget.cssTransformOrigin
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
this.updateCss()
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ var UiWidget = require('./ui-widget'),
|
|||
scriptGlobals = ScriptVm.globals,
|
||||
editors = {}, editorModes = {
|
||||
javascript: require('brace/mode/javascript')
|
||||
}
|
||||
},
|
||||
fastdom = require('fastdom')
|
||||
|
||||
function createEditor(name, language, syntaxChecker) {
|
||||
var el = html`<div id="#editor${name}"></div>`
|
||||
|
|
@ -156,23 +157,34 @@ class UiInspectorField extends UiWidget {
|
|||
colorData = this.widget.constructor.cssVariables.find(x=>x.js === this.name),
|
||||
val = 'transparent'
|
||||
|
||||
try {
|
||||
val = chroma(style.getPropertyValue(colorData.css).trim()).hex('rgba')
|
||||
} catch(e) {}
|
||||
fastdom.measure(()=>{
|
||||
try {
|
||||
val = chroma(style.getPropertyValue(colorData.css).trim()).hex('rgba')
|
||||
} catch(e) {}
|
||||
fastdom.mutate(()=>{
|
||||
this.container.appendChild(html`
|
||||
<osc-inspector-color type="text" name="${this.name}" value="${val}" style="--color-picker-value: ${val}"></osc-inspector-color>
|
||||
`)
|
||||
})
|
||||
|
||||
let picker = html`<osc-inspector-color type="text" name="${this.name}" value="${val}" style="--color-picker-value: ${val}"></osc-inspector-color>`
|
||||
|
||||
this.container.appendChild(picker)
|
||||
})
|
||||
|
||||
} else if (stringValue === 'auto' && this.widget.constructor.cssVariables.some(x=>x.js === this.name)) {
|
||||
|
||||
let style = window.getComputedStyle(this.widget.container),
|
||||
data = this.widget.constructor.cssVariables.find(x=>x.js === this.name),
|
||||
val = style.getPropertyValue(data.css).trim()
|
||||
fastdom.measure(()=>{
|
||||
let style = window.getComputedStyle(this.widget.container),
|
||||
data = this.widget.constructor.cssVariables.find(x=>x.js === this.name),
|
||||
val = style.getPropertyValue(data.css).trim()
|
||||
|
||||
if (data.toJs) val = data.toJs(val)
|
||||
if (data.toJs) val = data.toJs(val)
|
||||
fastdom.mutate(()=>{
|
||||
this.container.appendChild(html`
|
||||
<div class="computed-value">${val}</div>
|
||||
`)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
this.container.appendChild(html`<div class="computed-value">${val}</div>`)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ var UiWidget = require('./ui-widget'),
|
|||
morph = require('nanomorph'),
|
||||
{defaults} = require('../widgets/'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw')
|
||||
raw = require('nanohtml/raw'),
|
||||
fastdom = require('fastdom')
|
||||
|
||||
|
||||
|
||||
|
|
@ -56,10 +57,16 @@ class UiInspector extends UiWidget {
|
|||
|
||||
var name = node.getAttribute('name')
|
||||
|
||||
|
||||
var textarea = DOM.get(this.container, `textarea[name="${name}"]`)
|
||||
if (textarea) {
|
||||
textarea[0].value = !node.classList.contains('on')
|
||||
DOM.dispatchEvent(textarea[0], 'change')
|
||||
fastdom.measure(()=>{
|
||||
var bool = !node.classList.contains('on')
|
||||
fastdom.mutate(()=>{
|
||||
textarea[0].value = bool
|
||||
DOM.dispatchEvent(textarea[0], 'change')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
} else if (node.tagName === 'OSC-INSPECTOR-COLOR') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue