2022-03-17 08:35:19 +02:00
|
|
|
import { set } from 'lodash'
|
2021-03-11 16:11:44 +02:00
|
|
|
import Select from '../select/select.vue'
|
2024-06-26 14:17:22 +03:00
|
|
|
import Checkbox from 'src/components/checkbox/checkbox.vue'
|
|
|
|
|
import Popover from 'src/components/popover/popover.vue'
|
|
|
|
|
|
|
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
|
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
|
|
library.add(
|
|
|
|
|
faExclamationTriangle
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const PRESET_FONTS = new Set(['serif', 'sans-serif', 'monospace', 'inherit'])
|
2018-12-11 00:56:15 +03:00
|
|
|
|
|
|
|
|
export default {
|
2021-03-11 16:11:44 +02:00
|
|
|
components: {
|
2024-06-26 14:17:22 +03:00
|
|
|
Select,
|
|
|
|
|
Checkbox,
|
|
|
|
|
Popover
|
2021-03-11 16:11:44 +02:00
|
|
|
},
|
2018-12-11 00:56:15 +03:00
|
|
|
props: [
|
2022-03-27 14:16:23 +03:00
|
|
|
'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit'
|
2018-12-11 00:56:15 +03:00
|
|
|
],
|
2022-03-27 14:16:23 +03:00
|
|
|
emits: ['update:modelValue'],
|
2018-12-11 00:56:15 +03:00
|
|
|
data () {
|
|
|
|
|
return {
|
2024-06-26 14:17:22 +03:00
|
|
|
localValue: this.modelValue,
|
|
|
|
|
customFamily: '',
|
2018-12-11 00:56:15 +03:00
|
|
|
availableOptions: [
|
|
|
|
|
this.noInherit ? '' : 'inherit',
|
2024-06-26 14:17:22 +03:00
|
|
|
'local',
|
2018-12-11 00:56:15 +03:00
|
|
|
...(this.options || []),
|
|
|
|
|
'serif',
|
|
|
|
|
'monospace',
|
|
|
|
|
'sans-serif'
|
|
|
|
|
].filter(_ => _)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeUpdate () {
|
2024-06-26 14:17:22 +03:00
|
|
|
this.localValue = this.modelValue
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
present () {
|
2024-06-26 14:17:22 +03:00
|
|
|
return typeof this.localValue !== 'undefined'
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
2024-06-26 14:17:22 +03:00
|
|
|
defaultValue () {
|
|
|
|
|
return this.localValue || this.fallback || {}
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
|
|
|
|
family: {
|
|
|
|
|
get () {
|
2024-06-26 14:17:22 +03:00
|
|
|
return this.defaultValue.family
|
|
|
|
|
},
|
|
|
|
|
set (v) {
|
|
|
|
|
set(this.localValue, 'family', v)
|
|
|
|
|
this.$emit('update:modelValue', this.localValue)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
familyCustom: {
|
|
|
|
|
get () {
|
|
|
|
|
return this.customFamily
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
|
|
|
|
set (v) {
|
2024-06-26 14:17:22 +03:00
|
|
|
this.customFamily = v
|
|
|
|
|
if (!PRESET_FONTS.has(this.customFamily)) {
|
|
|
|
|
set(this.localValue, 'family', v)
|
|
|
|
|
this.$emit('update:modelValue', this.customFamily)
|
|
|
|
|
}
|
2018-12-11 00:56:15 +03:00
|
|
|
}
|
|
|
|
|
},
|
2024-06-26 14:17:22 +03:00
|
|
|
invalidCustom () {
|
|
|
|
|
return PRESET_FONTS.has(this.customFamily)
|
|
|
|
|
},
|
2018-12-11 00:56:15 +03:00
|
|
|
isCustom () {
|
2024-06-26 14:17:22 +03:00
|
|
|
return !PRESET_FONTS.has(this.family)
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
|
|
|
|
preset: {
|
|
|
|
|
get () {
|
2024-06-26 14:17:22 +03:00
|
|
|
if (PRESET_FONTS.has(this.family)) {
|
2018-12-11 00:56:15 +03:00
|
|
|
return this.family
|
|
|
|
|
} else {
|
2024-06-26 14:17:22 +03:00
|
|
|
return 'local'
|
2018-12-11 00:56:15 +03:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
set (v) {
|
2024-06-26 14:17:22 +03:00
|
|
|
this.family = v === 'local' ? '' : v
|
2018-12-11 00:56:15 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|