diff --git a/src/components/font_control/font_control.js b/src/components/font_control/font_control.js index 1e33338fa..f6f45c8cc 100644 --- a/src/components/font_control/font_control.js +++ b/src/components/font_control/font_control.js @@ -1,4 +1,3 @@ -import { set, clone } from 'lodash' import Select from '../select/select.vue' import Checkbox from 'src/components/checkbox/checkbox.vue' import Popover from 'src/components/popover/popover.vue' @@ -16,8 +15,6 @@ library.add( faFont ) -const PRESET_FONTS = new Set(['serif', 'sans-serif', 'monospace', 'inherit']) - export default { components: { Select, @@ -27,94 +24,36 @@ export default { props: [ 'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit' ], + mounted () { + this.$store.dispatch('queryLocalFonts') + }, emits: ['update:modelValue'], data () { return { manualEntry: true, - localValue: clone(this.modelValue), - familyCustomLocal: null, availableOptions: [ this.noInherit ? '' : 'inherit', 'serif', 'sans-serif', 'monospace', - 'local', ...(this.options || []) ].filter(_ => _) } }, - beforeUpdate () { - 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 } }, computed: { present () { - return typeof this.localValue !== 'undefined' - }, - defaultValue () { - return this.localValue || this.fallback || {} - }, - fontsListCapable () { - return this.$store.state.interface.browserSupport.localFonts - }, - fontsList () { - return this.$store.state.interface.localFonts - }, - family: { - get () { - return this.defaultValue.family - }, - set (v) { - this.familyCustomLocal = '' - set(this.localValue, 'family', v) - this.$emit('update:modelValue', this.localValue) - } - }, - familyCustom: { - get () { - return this.familyCustomLocal - }, - set (v) { - this.familyCustomLocal = v - if (!this.isInvalidFamily(v)) { - set(this.localValue, 'family', v) - this.$emit('update:modelValue', this.localValue) - } - } - }, - invalidCustom () { - return this.isInvalidFamily(this.familyCustomLocal) + return typeof this.modelValue !== 'undefined' }, - isCustom () { - return !PRESET_FONTS.has(this.defaultValue.family) + localFontsList () { + return this.$store.state.interface.localFonts?.values() }, - preset: { - get () { - if (PRESET_FONTS.has(this.family)) { - return this.family - } else { - return 'local' - } - }, - set (v) { - this.family = v === 'local' ? '' : v - } + localFontsSize () { + return this.$store.state.interface.localFonts?.size } } } diff --git a/src/components/font_control/font_control.vue b/src/components/font_control/font_control.vue index f1b126be0..f3ab41a25 100644 --- a/src/components/font_control/font_control.vue +++ b/src/components/font_control/font_control.vue @@ -10,42 +10,18 @@ > {{ label }} -

- - {{ ' ' }} - - {{ $t('settings.style.themes3.define') }} - -

-

- + {{ ' ' }} + + {{ $t('settings.style.themes3.define') }} + +

+ {{ ' ' }} - + - + - + - - - - - -

diff --git a/src/i18n/en.json b/src/i18n/en.json index 4b2161651..d995163a8 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -748,17 +748,21 @@ "themes3": { "define": "Override", "font": { - "local": "Local font (must be installed on computer)", - "serif": "Serif (browser default)", - "sans-serif": "Sans-serif (browser default)", - "monospace": "Monospace (browser default)", - "inherit": "Same as parent component", - "invalid_custom_reserved": "Empty or reserved font name, it will not be saved as custom font - use dropdown instead", + "group-builtin": "Browser default fonts", + "builtin" : { + "serif": "Serif", + "sans-serif": "Sans-serif", + "monospace": "Monospace", + "inherit": "Unchanged" + }, + "group-local": "Locally installed fonts", + "local-unavailable1": "List of locally installed fonts unavailalbe", + "local-unavailable2": "Use manual entry to specify custom font", "font_list_unavailable": "Couldn't get locally installed fonts: {error}", "lookup_local_fonts": "Load list of fonts installed on this computer", "enter_manually": "Enter font name family manually", - "entry": "Font's {fontFamily}", - "select": "Select local font" + "entry": "Enter {fontFamily}", + "select": "Select font" } }, "switcher": { diff --git a/src/modules/interface.js b/src/modules/interface.js index bee503c59..2ccfeef35 100644 --- a/src/modules/interface.js +++ b/src/modules/interface.js @@ -108,7 +108,6 @@ const interfaceMod = { state.lastTimeline = value }, setFontsList (state, value) { - console.log(value) state.localFonts = new Set(value.map(font => font.family)) } }, @@ -184,10 +183,16 @@ const interfaceMod = { commit('setLayoutType', wideLayout ? 'wide' : normalOrMobile) } }, - queryLocalFonts ({ commit, dispatch }) { + queryLocalFonts ({ commit, dispatch, state }) { + if (state.localFonts !== null) return + commit('setFontsList', []) + if (!state.browserSupport.localFonts) { + return + } window .queryLocalFonts() .then((fonts) => { + console.log(fonts) commit('setFontsList', fonts) }) .catch((e) => {