User palette editor

This commit is contained in:
Henry Jameson 2024-11-14 21:42:45 +02:00
parent 4c68009ae0
commit 454aa695ab
5 changed files with 102 additions and 36 deletions

View file

@ -1,5 +1,8 @@
<template> <template>
<div class="PaletteEditor"> <div
class="PaletteEditor"
:class="{ '-compact': compact, '-apply': apply }"
>
<ColorInput <ColorInput
v-for="key in paletteKeys" v-for="key in paletteKeys"
:key="key" :key="key"
@ -22,6 +25,13 @@
<FAIcon icon="file-export" /> <FAIcon icon="file-export" />
{{ $t('settings.style.themes3.palette.export') }} {{ $t('settings.style.themes3.palette.export') }}
</button> </button>
<button
v-if="apply"
class="btn button-default palette-apply-button"
@click="applyPalette"
>
{{ $t('settings.style.themes3.palette.apply') }}
</button>
</div> </div>
</template> </template>
@ -43,12 +53,34 @@ library.add(
faFileExport faFileExport
) )
const props = defineProps(['modelValue']) const paletteKeys = [
const emit = defineEmits(['update:modelValue']) 'bg',
'fg',
'text',
'link',
'accent',
'cRed',
'cBlue',
'cGreen',
'cOrange',
'wallpaper'
]
const props = defineProps(['modelValue', 'compact', 'apply'])
const emit = defineEmits(['update:modelValue', 'applyPalette'])
const getExportedObject = () => paletteKeys.reduce((acc, key) => {
const value = props.modelValue[key]
if (value == null) {
return acc
} else {
return { ...acc, [key]: props.modelValue[key] }
}
}, {})
const paletteExporter = newExporter({ const paletteExporter = newExporter({
filename: 'pleroma_palette', filename: 'pleroma_palette',
extension: 'json', extension: 'json',
getExportedObject: () => props.modelValue getExportedObject
}) })
const paletteImporter = newImporter({ const paletteImporter = newImporter({
accept: '.json', accept: '.json',
@ -65,18 +97,9 @@ const importPalette = () => {
paletteImporter.importData() paletteImporter.importData()
} }
const paletteKeys = [ const applyPalette = (data) => {
'bg', emit('applyPalette', getExportedObject())
'fg', }
'text',
'link',
'accent',
'cRed',
'cBlue',
'cGreen',
'cOrange',
'wallpaper'
]
const fallback = (key) => { const fallback = (key) => {
if (key === 'accent') { if (key === 'accent') {
@ -118,8 +141,33 @@ const updatePalette = (paletteKey, value) => {
grid-column: 3 / span 2; grid-column: 3 / span 2;
} }
.palette-apply-button {
grid-column: 1 / span 2;
}
.color-input.style-control { .color-input.style-control {
margin: 0; margin: 0;
} }
&.-compact {
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(5, 1fr) auto;
.palette-import-button {
grid-column: 1;
}
.palette-export-button {
grid-column: 2;
}
&.-apply {
grid-template-rows: repeat(5, 1fr) auto auto;
.palette-apply-button {
grid-column: 1 / span 2;
}
}
}
} }
</style> </style>

View file

@ -3,6 +3,7 @@ import ChoiceSetting from '../helpers/choice_setting.vue'
import IntegerSetting from '../helpers/integer_setting.vue' import IntegerSetting from '../helpers/integer_setting.vue'
import FloatSetting from '../helpers/float_setting.vue' import FloatSetting from '../helpers/float_setting.vue'
import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue' import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue'
import PaletteEditor from 'src/components/palette_editor/palette_editor.vue'
import FontControl from 'src/components/font_control/font_control.vue' import FontControl from 'src/components/font_control/font_control.vue'
@ -50,6 +51,7 @@ const AppearanceTab = {
'cBlue', 'cBlue',
'cOrange' 'cOrange'
], ],
userPalette: {},
intersectionObserver: null, intersectionObserver: null,
thirdColumnModeOptions: ['none', 'notifications', 'postform'].map(mode => ({ thirdColumnModeOptions: ['none', 'notifications', 'postform'].map(mode => ({
key: mode, key: mode,
@ -76,7 +78,8 @@ const AppearanceTab = {
UnitSetting, UnitSetting,
ProfileSettingIndicator, ProfileSettingIndicator,
FontControl, FontControl,
Preview Preview,
PaletteEditor
}, },
mounted () { mounted () {
const updateIndex = (resource) => { const updateIndex = (resource) => {
@ -105,6 +108,7 @@ const AppearanceTab = {
updateIndex('palette').then(bundledPalettes => { updateIndex('palette').then(bundledPalettes => {
bundledPalettes.forEach(([key, palettePromise]) => palettePromise.then(v => { bundledPalettes.forEach(([key, palettePromise]) => palettePromise.then(v => {
let palette
if (Array.isArray(v)) { if (Array.isArray(v)) {
const [ const [
name, name,
@ -117,9 +121,15 @@ const AppearanceTab = {
cBlue = '#0000FF', cBlue = '#0000FF',
cOrange = '#E3FF00' cOrange = '#E3FF00'
] = v ] = v
this.bundledPalettes.push({ key, name, bg, fg, text, link, cRed, cBlue, cGreen, cOrange }) palette = { key, name, bg, fg, text, link, cRed, cBlue, cGreen, cOrange }
this.bundledPalettes.push()
} else { } else {
this.bundledPalettes.push({ key, ...v }) palette = { key, ...v }
}
this.bundledPalettes.push(palette)
if (this.isPaletteActive(key)) {
this.userPalette = palette
} }
})) }))
}) })
@ -292,15 +302,18 @@ const AppearanceTab = {
this.$store.dispatch('setTheme', name) this.$store.dispatch('setTheme', name)
this.$store.dispatch('applyTheme') this.$store.dispatch('applyTheme')
}, },
setPalette (name) { setPalette (name, data) {
this.$store.dispatch('resetThemeV2') this.$store.dispatch('resetThemeV2')
this.$store.dispatch('setPalette', name) this.$store.dispatch('setPalette', name)
this.$store.dispatch('applyTheme') this.$store.dispatch('applyTheme')
this.userPalette = data
}, },
setPaletteCustom (p) { setPaletteCustom (data) {
console.log('APPLY CUSTOM', data)
this.$store.dispatch('resetThemeV2') this.$store.dispatch('resetThemeV2')
this.$store.dispatch('setPaletteCustom', p) this.$store.dispatch('setPaletteCustom', data)
this.$store.dispatch('applyTheme') this.$store.dispatch('applyTheme')
this.userPalette = data
}, },
resetTheming (name) { resetTheming (name) {
this.$store.dispatch('resetThemeV2') this.$store.dispatch('resetThemeV2')

View file

@ -26,7 +26,8 @@
grid-gap: 0.5em; grid-gap: 0.5em;
h4, h4,
.unsupported-theme-v2 { .unsupported-theme-v2,
.userPalette {
grid-column: 1 / span 2; grid-column: 1 / span 2;
} }
} }
@ -71,6 +72,7 @@
border-radius: var(--roundness); border-radius: var(--roundness);
border: 1px solid var(--border); border: 1px solid var(--border);
padding: 0; padding: 0;
margin-bottom: 1em;
.theme-preview { .theme-preview {
font-size: 1rem; // fix for firefox font-size: 1rem; // fix for firefox

View file

@ -5,15 +5,6 @@
> >
<div class="setting-item"> <div class="setting-item">
<h2>{{ $t('settings.theme') }}</h2> <h2>{{ $t('settings.theme') }}</h2>
<button
class="btn button-default"
@click="importFile"
>
<FAIcon icon="folder-open" />
{{ $t('settings.style.themes3.editor.load_style') }}
</button>
</div>
<div class="setting-item">
<ul <ul
ref="themeList" ref="themeList"
class="theme-list" class="theme-list"
@ -88,7 +79,7 @@
:key="p.name" :key="p.name"
class="btn button-default palette-entry" class="btn button-default palette-entry"
:class="{ toggled: isPaletteActive(p.key) }" :class="{ toggled: isPaletteActive(p.key) }"
@click="() => setPalette(p.key)" @click="() => setPalette(p.key, p)"
> >
<label> <label>
{{ p.name }} {{ p.name }}
@ -120,6 +111,16 @@
:style="{ backgroundColor: p[c], border: '1px solid ' + (p[c] ?? 'var(--text)') }" :style="{ backgroundColor: p[c], border: '1px solid ' + (p[c] ?? 'var(--text)') }"
/> />
</button> </button>
<h4>
{{ $t('settings.style.themes3.palette.user') }}
</h4>
<PaletteEditor
class="userPalette"
v-model="userPalette"
:compact="true"
:apply="true"
@applyPalette="data => setPaletteCustom(data)"
/>
</template> </template>
<template v-else-if="customThemeVersion === 'v2'"> <template v-else-if="customThemeVersion === 'v2'">
<div class="alert neutral theme-notice unsupported-theme-v2"> <div class="alert neutral theme-notice unsupported-theme-v2">

View file

@ -759,8 +759,9 @@
"palette": { "palette": {
"label": "Color schemes", "label": "Color schemes",
"name_label": "Color scheme name", "name_label": "Color scheme name",
"import": "Import", "import": "Import palette",
"export": "Export", "export": "Export palette",
"apply": "Apply palette",
"bg": "Panel background", "bg": "Panel background",
"fg": "Buttons etc.", "fg": "Buttons etc.",
"text": "Text", "text": "Text",
@ -773,7 +774,8 @@
"wallpaper": "Wallpaper", "wallpaper": "Wallpaper",
"v2_unsupported": "Older v2 themes don't support palettes. Switch to v3 theme to make use of palettes", "v2_unsupported": "Older v2 themes don't support palettes. Switch to v3 theme to make use of palettes",
"bundled": "Bundled palettes", "bundled": "Bundled palettes",
"style": "Palettes provided by selected style" "style": "Palettes provided by selected style",
"user": "Custom palette"
}, },
"editor": { "editor": {
"title": "Style", "title": "Style",