inspector: color picker overhaul (#771)
This commit is contained in:
parent
05aa6bf998
commit
e4846688c8
7 changed files with 123 additions and 57 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## 1.14.4
|
||||
|
||||
- inspector
|
||||
- the color picker is no longer in a modal and now shows changes on the fly (the new color is not saved unless "confirm" is clicked)
|
||||
|
||||
## 1.14.3
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Editor {
|
|||
this.inspector = new UiInspector({selector: '#osc-inspector'})
|
||||
this.inspector.on('update', (event)=>{
|
||||
|
||||
var {propName, value} = event,
|
||||
var {propName, value, preventHistory} = event,
|
||||
newWidgets = [],
|
||||
error = false
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ class Editor {
|
|||
|
||||
if (error) return
|
||||
|
||||
this.pushHistory()
|
||||
if (!preventHistory) this.pushHistory()
|
||||
|
||||
if (newWidgets.length > 1) this.select(newWidgets)
|
||||
|
||||
|
|
@ -484,6 +484,7 @@ class Editor {
|
|||
|
||||
disable() {
|
||||
|
||||
if (this.inspector.colorPicker.opened) this.inspector.colorPicker.cancel()
|
||||
|
||||
this.unselect()
|
||||
this.selectedWidgets = []
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ module.exports = {
|
|||
|
||||
// inspector
|
||||
inspector_color_confirm: 'Confirm',
|
||||
inspector_color_apply: 'Apply',
|
||||
inspector_color_cancel: 'Cancel',
|
||||
inspector_error: 'An error just occured, open the console to read more.',
|
||||
|
||||
// nosleep
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ module.exports = {
|
|||
|
||||
// inspector
|
||||
inspector_color_confirm: 'Confirmer',
|
||||
inspector_color_apply: 'Appliquer',
|
||||
inspector_color_cancel: 'Annuler',
|
||||
inspector_error: 'Une erreur vient de survenir, ouvrez la console pour en savoir plus.',
|
||||
|
||||
// nosleep
|
||||
|
|
|
|||
|
|
@ -27,63 +27,58 @@ class ColorPicker extends UiWidget {
|
|||
}, parent: this})
|
||||
this.rgb.container.classList.add('not-editable')
|
||||
|
||||
this.modal = new UiModal({
|
||||
width: 280,
|
||||
height: 320,
|
||||
closable: true,
|
||||
title: '',
|
||||
hide: true,
|
||||
html: true,
|
||||
content: html`
|
||||
<div class="color-picker-modal">
|
||||
${this.rgb.container}
|
||||
<div class="actions">
|
||||
<div class="btn color-apply">${locales('inspector_color_apply')}</div>
|
||||
<div class="btn color-confirm">${locales('inspector_color_confirm')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
enterKey: this.confirm.bind(this)
|
||||
})
|
||||
this.container = html`
|
||||
<div class="color-picker">
|
||||
${this.rgb.container}
|
||||
<div class="actions">
|
||||
<div class="btn color-confirm">${locales('inspector_color_confirm')}</div>
|
||||
<div class="btn color-cancel">${locales('inspector_color_cancel')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
DOM.get(this.modal.container, '.color-confirm')[0].addEventListener('click', this.confirm.bind(this))
|
||||
DOM.get(this.modal.container, '.color-apply')[0].addEventListener('click', this.apply.bind(this))
|
||||
DOM.get(this.container, '.color-confirm')[0].addEventListener('click', this.confirm.bind(this))
|
||||
DOM.get(this.container, '.color-cancel')[0].addEventListener('click', this.cancel.bind(this))
|
||||
|
||||
this.rgb.on('change', (e)=>{
|
||||
e.stopPropagation = true
|
||||
this.value = chroma(this.rgb.value).hex()
|
||||
this.trigger('change', {preventHistory: true})
|
||||
})
|
||||
// this.rgb.on('dragend', (e)=>{
|
||||
// this.value = chroma(this.rgb.value).hex()
|
||||
// this.trigger('change')
|
||||
// })
|
||||
|
||||
this.opened = 0
|
||||
this.label = DOM.get(this.modal.container, '.title')[0]
|
||||
|
||||
this.cancelValue = '#00000000'
|
||||
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.cancel()
|
||||
}).bind(this)
|
||||
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.confirm()
|
||||
}).bind(this)
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
this.label.innerHTML = this.name
|
||||
this.modal.open()
|
||||
this.parentNode.appendChild(this.container)
|
||||
resize.check(this.rgb.container)
|
||||
this.opened = 1
|
||||
|
||||
document.addEventListener('keydown', this.escKeyHandler)
|
||||
document.addEventListener('keydown', this.enterKeyHandler)
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
this.modal.close()
|
||||
if (this.parentNode.contains(this.container)) {
|
||||
this.parentNode.removeChild(this.container)
|
||||
}
|
||||
this.setName()
|
||||
this.opened = 0
|
||||
|
||||
}
|
||||
|
||||
apply() {
|
||||
|
||||
this.value = chroma(this.rgb.getValue(true)).css('rgba')
|
||||
this.trigger('change')
|
||||
|
||||
document.removeEventListener('keydown', this.escKeyHandler)
|
||||
document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
}
|
||||
|
||||
confirm() {
|
||||
|
|
@ -94,6 +89,16 @@ class ColorPicker extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
||||
if (this.value !== this.cancelValue) {
|
||||
this.value = this.cancelValue
|
||||
this.trigger('change', {preventHistory: true})
|
||||
}
|
||||
this.close()
|
||||
|
||||
}
|
||||
|
||||
isVisible() {
|
||||
|
||||
return true
|
||||
|
|
@ -114,6 +119,19 @@ class ColorPicker extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
setCancelValue(v) {
|
||||
|
||||
this.cancelValue = v
|
||||
|
||||
}
|
||||
|
||||
setParent(node) {
|
||||
|
||||
if (this.opened && node !== this.parentNode) this.close()
|
||||
this.parentNode = node
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ColorPicker
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ class UiInspector extends UiWidget {
|
|||
this.parentContainer = DOM.get('osc-panel-container.right osc-panel-inner')[0]
|
||||
|
||||
this.colorPicker = new UiColorPicker()
|
||||
this.colorPicker.on('change', ()=>{
|
||||
this.colorPicker.on('change', (event)=>{
|
||||
var textarea = DOM.get(this.container, `textarea[name="${this.colorPicker.name}"]`)
|
||||
if (textarea) {
|
||||
textarea[0].value = this.colorPicker.value
|
||||
DOM.dispatchEvent(textarea[0], 'change')
|
||||
DOM.dispatchEvent(textarea[0], 'change', event)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -64,9 +64,19 @@ class UiInspector extends UiWidget {
|
|||
|
||||
} else if (node.tagName === 'OSC-INSPECTOR-COLOR') {
|
||||
|
||||
this.colorPicker.setName(node.getAttribute('name'))
|
||||
this.colorPicker.setValue(node.getAttribute('value'))
|
||||
this.colorPicker.open()
|
||||
var name = node.getAttribute('name'),
|
||||
textarea = DOM.get(this.container, `textarea[name="${name}"]`)
|
||||
|
||||
if (this.colorPicker.name === name) {
|
||||
this.colorPicker.cancel()
|
||||
} else {
|
||||
if (this.colorPicker.opened) this.colorPicker.cancel()
|
||||
this.colorPicker.setParent(node.parentNode)
|
||||
this.colorPicker.setName(name)
|
||||
this.colorPicker.setValue(node.getAttribute('value'))
|
||||
this.colorPicker.setCancelValue(textarea[0].value)
|
||||
this.colorPicker.open()
|
||||
}
|
||||
|
||||
} else if (node.tagName === 'LABEL') {
|
||||
|
||||
|
|
@ -192,6 +202,7 @@ class UiInspector extends UiWidget {
|
|||
var picker = DOM.get(this.container, `osc-inspector-color[name="${this.colorPicker.name}"]`)
|
||||
if (picker && picker[0]) {
|
||||
this.colorPicker.setValue(picker[0].getAttribute('value'))
|
||||
this.colorPicker.open()
|
||||
} else {
|
||||
this.colorPicker.close()
|
||||
}
|
||||
|
|
@ -227,7 +238,8 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.trigger('update', {
|
||||
propName: input.name,
|
||||
value: v
|
||||
value: v,
|
||||
preventHistory: event.detail && event.detail.preventHistory
|
||||
})
|
||||
|
||||
// this may not be reached if an error is thrown
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
$header-height: 28rem;
|
||||
$field-height: 24rem;
|
||||
$label-width: 94rem;
|
||||
$padding: 8rem;
|
||||
$radius: 3rem;
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ osc-inspector-field {
|
|||
&:after {
|
||||
content:"";
|
||||
position: absolute;
|
||||
left:94rem;
|
||||
left:$label-width;
|
||||
top:0;
|
||||
right: 1rem;
|
||||
border-top:1rem solid var(--color-ui-background);
|
||||
|
|
@ -35,7 +36,7 @@ osc-inspector-field {
|
|||
--widget-padding: -1rem;
|
||||
|
||||
> label {
|
||||
width: 94rem;
|
||||
width: $label-width;
|
||||
text-transform: none;
|
||||
padding-left: 4rem;
|
||||
padding-right: 4rem;
|
||||
|
|
@ -457,6 +458,9 @@ osc-inspector-category {
|
|||
}
|
||||
border-top-left-radius: $radius;
|
||||
border-top-right-radius: $radius;
|
||||
.color-picker {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
}
|
||||
osc-inspector-field.last-child,
|
||||
osc-inspector-field:last-child {
|
||||
|
|
@ -595,17 +599,43 @@ osc-inspector-color {
|
|||
}
|
||||
}
|
||||
|
||||
.color-picker-modal {
|
||||
|
||||
flex: 1;
|
||||
.color-picker {
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
height: 180rem;
|
||||
top: 0;
|
||||
right: 22rem;
|
||||
left: $label-width;
|
||||
margin: 3rem 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
$padding: 2rem;
|
||||
border: 1rem solid var(--color-ui-button);
|
||||
overflow: hidden;
|
||||
|
||||
.widget {
|
||||
background: var(--color-background);
|
||||
background: var(--color-ui-background);
|
||||
flex: 1;
|
||||
width: auto;
|
||||
--widget-padding: #{$padding};
|
||||
--widget-padding: 0rem;
|
||||
inner {
|
||||
padding: 1rem;
|
||||
}
|
||||
.hue {
|
||||
margin-left: 1rem;
|
||||
width: 16rem;
|
||||
--knob-size: 1rem;
|
||||
}
|
||||
.alpha {
|
||||
margin-top: 0.5rem;
|
||||
left:0;
|
||||
margin-left: 0;
|
||||
border:0;
|
||||
}
|
||||
.hue:after {
|
||||
left:0;
|
||||
right:0;
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
|
|
@ -613,17 +643,17 @@ osc-inspector-color {
|
|||
flex-direction: row;
|
||||
align-items: flex-end;
|
||||
justify-content: stretch;
|
||||
height: 42rem + $padding * 2;
|
||||
line-height: 38rem;
|
||||
// height: 24rem + $padding * 2;
|
||||
line-height: $field-height;
|
||||
flex-shrink: 0;
|
||||
background: var(--color-ui-foreground);
|
||||
padding: $padding;
|
||||
// padding: $padding;
|
||||
.btn {
|
||||
flex: 1;
|
||||
text-overflow: clip;
|
||||
min-width: 0;
|
||||
background: var(--color-ui-button);
|
||||
margin-right: $padding;
|
||||
margin-right: 1rem;
|
||||
&:last-child {
|
||||
margin: 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue