2024-06-26 17:05:59 +03:00
|
|
|
import { set, clone } 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'
|
2024-06-26 17:05:59 +03:00
|
|
|
import {
|
|
|
|
|
faExclamationTriangle,
|
|
|
|
|
faKeyboard,
|
|
|
|
|
faFont
|
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
2024-06-26 14:17:22 +03:00
|
|
|
|
|
|
|
|
library.add(
|
2024-06-26 17:05:59 +03:00
|
|
|
faExclamationTriangle,
|
|
|
|
|
faKeyboard,
|
|
|
|
|
faFont
|
2024-06-26 14:17:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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 17:05:59 +03:00
|
|
|
manualEntry: true,
|
|
|
|
|
localValue: clone(this.modelValue),
|
|
|
|
|
familyCustomLocal: null,
|
2018-12-11 00:56:15 +03:00
|
|
|
availableOptions: [
|
|
|
|
|
this.noInherit ? '' : 'inherit',
|
|
|
|
|
'serif',
|
2024-06-26 17:05:59 +03:00
|
|
|
'sans-serif',
|
2018-12-11 00:56:15 +03:00
|
|
|
'monospace',
|
2024-06-26 17:05:59 +03:00
|
|
|
'local',
|
|
|
|
|
...(this.options || [])
|
2018-12-11 00:56:15 +03:00
|
|
|
].filter(_ => _)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeUpdate () {
|
2024-06-26 17:05:59 +03:00
|
|
|
this.localValue = clone(this.modelValue)
|
|
|
|
|
if (this.familyCustomLocal === null && !this.isInvalidFamily(this.modelValue?.family)) {
|
|
|
|
|
this.familyCustomLocal = this.modelValue?.family
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
lookupLocalFonts () {
|
|
|
|
|
if (!this.fontsList) {
|
|
|
|
|
this.$store.dispatch('queryLocalFonts')
|
|
|
|
|
}
|
|
|
|
|
this.toggleManualEntry()
|
|
|
|
|
},
|
|
|
|
|
isInvalidFamily (value) {
|
|
|
|
|
return PRESET_FONTS.has(value) || (value === '')
|
|
|
|
|
},
|
|
|
|
|
toggleManualEntry () {
|
|
|
|
|
this.manualEntry = !this.manualEntry
|
|
|
|
|
}
|
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
|
|
|
},
|
2024-06-26 17:05:59 +03:00
|
|
|
fontsListCapable () {
|
|
|
|
|
return this.$store.state.interface.browserSupport.localFonts
|
|
|
|
|
},
|
|
|
|
|
fontsList () {
|
|
|
|
|
return this.$store.state.interface.localFonts
|
|
|
|
|
},
|
2018-12-11 00:56:15 +03:00
|
|
|
family: {
|
|
|
|
|
get () {
|
2024-06-26 14:17:22 +03:00
|
|
|
return this.defaultValue.family
|
|
|
|
|
},
|
|
|
|
|
set (v) {
|
2024-06-26 17:05:59 +03:00
|
|
|
this.familyCustomLocal = ''
|
2024-06-26 14:17:22 +03:00
|
|
|
set(this.localValue, 'family', v)
|
|
|
|
|
this.$emit('update:modelValue', this.localValue)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
familyCustom: {
|
|
|
|
|
get () {
|
2024-06-26 17:05:59 +03:00
|
|
|
return this.familyCustomLocal
|
2018-12-11 00:56:15 +03:00
|
|
|
},
|
|
|
|
|
set (v) {
|
2024-06-26 17:05:59 +03:00
|
|
|
this.familyCustomLocal = v
|
|
|
|
|
if (!this.isInvalidFamily(v)) {
|
2024-06-26 14:17:22 +03:00
|
|
|
set(this.localValue, 'family', v)
|
2024-06-26 17:05:59 +03:00
|
|
|
this.$emit('update:modelValue', this.localValue)
|
2024-06-26 14:17:22 +03:00
|
|
|
}
|
2018-12-11 00:56:15 +03:00
|
|
|
}
|
|
|
|
|
},
|
2024-06-26 14:17:22 +03:00
|
|
|
invalidCustom () {
|
2024-06-26 17:05:59 +03:00
|
|
|
return this.isInvalidFamily(this.familyCustomLocal)
|
2024-06-26 14:17:22 +03:00
|
|
|
},
|
2018-12-11 00:56:15 +03:00
|
|
|
isCustom () {
|
2024-06-26 17:05:59 +03:00
|
|
|
return !PRESET_FONTS.has(this.defaultValue.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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|