2018-11-19 01:40:25 +00:00
|
|
|
import ColorInput from '../color_input/color_input.vue'
|
|
|
|
import OpacityInput from '../opacity_input/opacity_input.vue'
|
2021-03-11 14:11:44 +00:00
|
|
|
import Select from '../select/select.vue'
|
2020-01-13 00:08:39 +00:00
|
|
|
import { getCssShadow } from '../../services/style_setter/style_setter.js'
|
|
|
|
import { hex2rgb } from '../../services/color_convert/color_convert.js'
|
2020-10-20 18:03:46 +00:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import {
|
|
|
|
faTimes,
|
|
|
|
faChevronDown,
|
|
|
|
faChevronUp,
|
|
|
|
faPlus
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
library.add(
|
|
|
|
faChevronDown,
|
|
|
|
faChevronUp,
|
|
|
|
faTimes,
|
|
|
|
faPlus
|
|
|
|
)
|
2018-11-19 01:40:25 +00:00
|
|
|
|
2020-02-17 21:43:35 +00:00
|
|
|
const toModel = (object = {}) => ({
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
blur: 0,
|
|
|
|
spread: 0,
|
|
|
|
inset: false,
|
|
|
|
color: '#000000',
|
|
|
|
alpha: 1,
|
|
|
|
...object
|
|
|
|
})
|
|
|
|
|
2018-11-19 01:40:25 +00:00
|
|
|
export default {
|
2022-03-27 10:31:29 +00:00
|
|
|
// 'modelValue' and 'Fallback' can be undefined, but if they are
|
2018-11-22 00:55:45 +00:00
|
|
|
// initially vue won't detect it when they become something else
|
|
|
|
// therefore i'm using "ready" which should be passed as true when
|
|
|
|
// data becomes available
|
2018-11-19 01:40:25 +00:00
|
|
|
props: [
|
2022-03-27 10:31:29 +00:00
|
|
|
'modelValue', 'fallback', 'ready'
|
2018-11-19 01:40:25 +00:00
|
|
|
],
|
2022-03-27 10:31:29 +00:00
|
|
|
emits: ['update:modelValue'],
|
2018-11-19 01:40:25 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
selectedId: 0,
|
2018-12-02 09:56:02 +00:00
|
|
|
// TODO there are some bugs regarding display of array (it's not getting updated when deleting for some reason)
|
2022-03-27 10:31:29 +00:00
|
|
|
cValue: (this.modelValue || this.fallback || []).map(toModel)
|
2018-11-19 01:40:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ColorInput,
|
2021-03-11 14:11:44 +00:00
|
|
|
OpacityInput,
|
|
|
|
Select
|
2018-11-19 01:40:25 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
add () {
|
2020-02-17 21:43:35 +00:00
|
|
|
this.cValue.push(toModel(this.selected))
|
2018-11-19 01:40:25 +00:00
|
|
|
this.selectedId = this.cValue.length - 1
|
|
|
|
},
|
|
|
|
del () {
|
|
|
|
this.cValue.splice(this.selectedId, 1)
|
2020-02-17 21:43:35 +00:00
|
|
|
this.selectedId = this.cValue.length === 0 ? undefined : Math.max(this.selectedId - 1, 0)
|
2018-11-19 01:40:25 +00:00
|
|
|
},
|
|
|
|
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 20:25:38 +00:00
|
|
|
beforeUpdate () {
|
2022-03-27 10:31:29 +00:00
|
|
|
this.cValue = this.modelValue || this.fallback
|
2018-11-20 20:25:38 +00:00
|
|
|
},
|
2018-11-19 01:40:25 +00:00
|
|
|
computed: {
|
2020-02-17 21:43:35 +00:00
|
|
|
anyShadows () {
|
|
|
|
return this.cValue.length > 0
|
|
|
|
},
|
|
|
|
anyShadowsFallback () {
|
|
|
|
return this.fallback.length > 0
|
|
|
|
},
|
2018-11-19 01:40:25 +00:00
|
|
|
selected () {
|
2020-02-17 21:43:35 +00:00
|
|
|
if (this.ready && this.anyShadows) {
|
2018-11-22 00:55:45 +00:00
|
|
|
return this.cValue[this.selectedId]
|
|
|
|
} else {
|
2020-02-17 21:43:35 +00:00
|
|
|
return toModel({})
|
2018-11-19 01:40:25 +00:00
|
|
|
}
|
|
|
|
},
|
2020-01-19 22:34:49 +00:00
|
|
|
currentFallback () {
|
2020-02-17 21:43:35 +00:00
|
|
|
if (this.ready && this.anyShadowsFallback) {
|
2020-01-19 22:34:49 +00:00
|
|
|
return this.fallback[this.selectedId]
|
|
|
|
} else {
|
2020-02-17 21:43:35 +00:00
|
|
|
return toModel({})
|
2020-01-19 22:34:49 +00:00
|
|
|
}
|
|
|
|
},
|
2018-11-19 01:40:25 +00:00
|
|
|
moveUpValid () {
|
2018-11-22 00:55:45 +00:00
|
|
|
return this.ready && this.selectedId > 0
|
2018-11-19 01:40:25 +00:00
|
|
|
},
|
|
|
|
moveDnValid () {
|
2018-11-22 00:55:45 +00:00
|
|
|
return this.ready && this.selectedId < this.cValue.length - 1
|
2018-11-19 01:40:25 +00:00
|
|
|
},
|
|
|
|
present () {
|
2018-11-22 00:55:45 +00:00
|
|
|
return this.ready &&
|
2018-11-20 20:25:38 +00:00
|
|
|
typeof this.cValue[this.selectedId] !== 'undefined' &&
|
2018-11-19 01:40:25 +00:00
|
|
|
!this.usingFallback
|
|
|
|
},
|
|
|
|
usingFallback () {
|
2022-03-27 10:31:29 +00:00
|
|
|
return typeof this.modelValue === 'undefined'
|
2018-11-19 01:40:25 +00:00
|
|
|
},
|
|
|
|
rgb () {
|
|
|
|
return hex2rgb(this.selected.color)
|
|
|
|
},
|
|
|
|
style () {
|
2018-11-22 00:55:45 +00:00
|
|
|
return this.ready ? {
|
2020-01-20 00:00:13 +00:00
|
|
|
boxShadow: getCssShadow(this.fallback)
|
2018-11-20 20:25:38 +00:00
|
|
|
} : {}
|
2018-11-19 01:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|