2018-11-18 17:40:25 -08:00
|
|
|
import ColorInput from '../color_input/color_input.vue'
|
|
|
|
import OpacityInput from '../opacity_input/opacity_input.vue'
|
2018-11-19 09:22:46 -08:00
|
|
|
import { getCssShadow } from '../../services/style_setter/style_setter.js'
|
2018-11-18 17:40:25 -08:00
|
|
|
import { hex2rgb } from '../../services/color_convert/color_convert.js'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: [
|
|
|
|
'value', 'fallback'
|
|
|
|
],
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
selectedId: 0,
|
|
|
|
cValue: this.value || this.fallback
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ColorInput,
|
|
|
|
OpacityInput
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
add () {
|
|
|
|
this.cValue.push(Object.assign({}, this.selected))
|
|
|
|
this.selectedId = this.cValue.length - 1
|
|
|
|
},
|
|
|
|
del () {
|
|
|
|
this.cValue.splice(this.selectedId, 1)
|
|
|
|
this.selectedId = this.cValue.length === 0 ? undefined : this.selectedId - 1
|
|
|
|
},
|
|
|
|
moveUp () {
|
|
|
|
const movable = this.cValue.splice(this.selectedId, 1)[0]
|
|
|
|
this.cValue.splice(this.selectedId - 1, 0, movable)
|
|
|
|
this.selectedId -= 1
|
|
|
|
},
|
|
|
|
moveDn () {
|
|
|
|
const movable = this.cValue.splice(this.selectedId, 1)[0]
|
|
|
|
this.cValue.splice(this.selectedId + 1, 0, movable)
|
|
|
|
this.selectedId += 1
|
|
|
|
}
|
|
|
|
},
|
2018-11-20 12:25:38 -08:00
|
|
|
beforeUpdate () {
|
|
|
|
this.cValue = this.value || this.fallback
|
|
|
|
},
|
2018-11-18 17:40:25 -08:00
|
|
|
computed: {
|
|
|
|
selected () {
|
2018-11-20 12:25:38 -08:00
|
|
|
return this.isReady && this.cValue[this.selectedId] || {
|
2018-11-18 17:40:25 -08:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
blur: 0,
|
|
|
|
spread: 0,
|
|
|
|
inset: false,
|
|
|
|
color: '#000000',
|
|
|
|
alpha: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveUpValid () {
|
2018-11-20 12:25:38 -08:00
|
|
|
return this.isReady && this.selectedId > 0
|
2018-11-18 17:40:25 -08:00
|
|
|
},
|
|
|
|
moveDnValid () {
|
2018-11-20 12:25:38 -08:00
|
|
|
return this.isReady && this.selectedId < this.cValue.length - 1
|
|
|
|
},
|
|
|
|
isReady () {
|
|
|
|
return typeof this.cValue !== 'undefined'
|
2018-11-18 17:40:25 -08:00
|
|
|
},
|
|
|
|
present () {
|
2018-11-20 12:25:38 -08:00
|
|
|
return this.isReady &&
|
|
|
|
typeof this.cValue[this.selectedId] !== 'undefined' &&
|
2018-11-18 17:40:25 -08:00
|
|
|
!this.usingFallback
|
|
|
|
},
|
|
|
|
usingFallback () {
|
|
|
|
return typeof this.value === 'undefined'
|
|
|
|
},
|
|
|
|
rgb () {
|
|
|
|
return hex2rgb(this.selected.color)
|
|
|
|
},
|
|
|
|
style () {
|
2018-11-20 12:25:38 -08:00
|
|
|
return this.isReady ? {
|
2018-11-19 09:22:46 -08:00
|
|
|
boxShadow: getCssShadow(this.cValue)
|
2018-11-20 12:25:38 -08:00
|
|
|
} : {}
|
2018-11-18 17:40:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|