overall preview + layout changes

This commit is contained in:
Henry Jameson 2024-10-08 22:13:15 +03:00
parent 57d84a3cc6
commit 707ed633e4
6 changed files with 147 additions and 57 deletions

View file

@ -5,6 +5,7 @@
> >
<label <label
:for="path" :for="path"
class="setting-label"
:class="{ 'faint': shouldBeDisabled }" :class="{ 'faint': shouldBeDisabled }"
> >
<template v-if="backendDescriptionLabel"> <template v-if="backendDescriptionLabel">

View file

@ -13,9 +13,13 @@ import OpacityInput from 'src/components/opacity_input/opacity_input.vue'
import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'
import Tooltip from 'src/components/tooltip/tooltip.vue' import Tooltip from 'src/components/tooltip/tooltip.vue'
import ContrastRatio from 'src/components/contrast_ratio/contrast_ratio.vue' import ContrastRatio from 'src/components/contrast_ratio/contrast_ratio.vue'
import Preview from '../theme_tab/theme_preview.vue'
import { init } from 'src/services/theme_data/theme_data_3.service.js' import { init } from 'src/services/theme_data/theme_data_3.service.js'
import { getCssRules } from 'src/services/theme_data/css_utils.js' import {
getCssRules,
getScopedVersion
} from 'src/services/theme_data/css_utils.js'
import { serialize } from 'src/services/theme_data/iss_serializer.js' import { serialize } from 'src/services/theme_data/iss_serializer.js'
import { parseShadow /* , deserialize */ } from 'src/services/theme_data/iss_deserializer.js' import { parseShadow /* , deserialize */ } from 'src/services/theme_data/iss_deserializer.js'
import { import {
@ -29,7 +33,7 @@ import {
} from 'src/services/export_import/export_import.js' } from 'src/services/export_import/export_import.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { faFloppyDisk, faFolderOpen, faFile } from '@fortawesome/free-solid-svg-icons' import { faFloppyDisk, faFolderOpen, faFile, faArrowsRotate } from '@fortawesome/free-solid-svg-icons'
// helper for debugging // helper for debugging
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -41,7 +45,8 @@ const normalizeStates = (states) => ['normal', ...(states?.filter(x => x !== 'no
library.add( library.add(
faFile, faFile,
faFloppyDisk, faFloppyDisk,
faFolderOpen faFolderOpen,
faArrowsRotate
) )
export default { export default {
@ -57,7 +62,8 @@ export default {
ColorInput, ColorInput,
PaletteEditor, PaletteEditor,
OpacityInput, OpacityInput,
ContrastRatio ContrastRatio,
Preview
}, },
setup () { setup () {
// All rules that are made by editor // All rules that are made by editor
@ -549,6 +555,40 @@ export default {
value: 'foobar' value: 'foobar'
}) })
const overallPreviewRules = ref()
const updateOverallPreview = () => {
try {
// This normally would be handled by Root but since we pass something
// else we have to make do ourselves
const { name, ...rest } = selectedPalette.value
const paletteRule = {
component: 'Root',
directives: Object
.entries(rest)
.map(([k, v]) => ['--' + k, v])
.reduce((acc, [k, v]) => ({ ...acc, [k]: `color | ${v}` }), {})
}
const rules = init({
inputRuleset: [
...editorFriendlyToOriginal.value,
paletteRule
],
ultimateBackgroundColor: '#000000',
liteMode: true,
debug: true
}).eager
overallPreviewRules.value = getScopedVersion(
getCssRules(rules),
'#edited-style-preview'
).join('\n')
} catch (e) {
console.error('Could not compile preview theme', e)
}
}
// ## Export and Import // ## Export and Import
const styleExporter = newExporter({ const styleExporter = newExporter({
filename: name.value || 'pleroma_theme', filename: name.value || 'pleroma_theme',
@ -628,6 +668,10 @@ export default {
previewCss, previewCss,
previewClass, previewClass,
// overall preview
overallPreviewRules,
updateOverallPreview,
// ## Variables // ## Variables
virtualDirectives, virtualDirectives,
selectedVirtualDirective, selectedVirtualDirective,

View file

@ -65,24 +65,56 @@
&.heading { &.heading {
display: grid; display: grid;
align-items: baseline; grid-template:
grid-template-columns: 1fr auto auto auto; "meta meta preview"
"meta meta preview"
"meta meta preview"
"meta meta preview"
"new new preview"
"load save refresh";
grid-gap: 0.5em; grid-gap: 0.5em;
grid-template-columns: min-content min-content 6fr;
grid-template-rows: repeat(4, min-content) repeat(2, 2em);
h2 { ul.setting-list {
flex: 1 0 auto; padding: 0;
margin: 0;
display: grid;
grid-template-rows: subgrid;
grid-area: meta;
> li {
margin: 0;
}
.meta-field {
margin: 0;
.setting-label {
display: inline-block;
margin-bottom: 0.5em;
}
} }
} }
&.metadata { #edited-style-preview {
display: flex; grid-area: preview;
.setting-item {
flex: 2 0 auto;
} }
li { .button-save {
text-align: right; grid-area: save;
}
.button-load {
grid-area: load;
}
.button-new {
grid-area: new;
}
.button-refresh {
grid-area: refresh;
} }
} }
} }
@ -119,7 +151,9 @@
} }
} }
.palettes-editor { .palette-editor {
width: min-content;
.list-edit-area { .list-edit-area {
align-self: baseline; align-self: baseline;
} }

View file

@ -4,49 +4,59 @@
<template> <template>
<div class="StyleTab"> <div class="StyleTab">
<div class="setting-item heading"> <div class="setting-item heading">
<!-- TODO: This needs to go --> <!-- eslint-disable vue/no-v-text-v-html-on-component -->
<h2>{{ $t('settings.style.themes3.editor.title') }}</h2> <component
:is="'style'"
v-html="overallPreviewRules"
/>
<!-- eslint-enable vue/no-v-text-v-html-on-component -->
<Preview id="edited-style-preview" />
<button <button
class="btn button-default" class="btn button-default button-new"
@click="clearTheme" @click="clearTheme"
> >
<FAIcon icon="file" /> <FAIcon icon="file" />
{{ $t('settings.style.themes3.editor.new_style') }} {{ $t('settings.style.themes3.editor.new_style') }}
</button> </button>
<button <button
class="btn button-default" class="btn button-default button-load"
@click="importStyle" @click="importStyle"
> >
<FAIcon icon="folder-open" /> <FAIcon icon="folder-open" />
{{ $t('settings.style.themes3.editor.load_style') }} {{ $t('settings.style.themes3.editor.load_style') }}
</button> </button>
<button <button
class="btn button-default" class="btn button-default button-save"
@click="exportStyle" @click="exportStyle"
> >
<FAIcon icon="floppy-disk" /> <FAIcon icon="floppy-disk" />
{{ $t('settings.style.themes3.editor.save_style') }} {{ $t('settings.style.themes3.editor.save_style') }}
</button> </button>
</div> <button
<div class="setting-item metadata"> class="btn button-default button-refresh"
<ul class="setting-list"> @click="updateOverallPreview"
>
<FAIcon icon="arrows-rotate" />
{{ $t('settings.style.themes3.editor.refresh_preview') }}
</button>
<ul class="setting-list style-metadata">
<li> <li>
<StringSetting v-model="name"> <StringSetting class="meta-field" v-model="name">
{{ $t('settings.style.themes3.editor.style_name') }} {{ $t('settings.style.themes3.editor.style_name') }}
</StringSetting> </StringSetting>
</li> </li>
<li> <li>
<StringSetting v-model="author"> <StringSetting class="meta-field" v-model="author">
{{ $t('settings.style.themes3.editor.style_author') }} {{ $t('settings.style.themes3.editor.style_author') }}
</StringSetting> </StringSetting>
</li> </li>
<li> <li>
<StringSetting v-model="license"> <StringSetting class="meta-field" v-model="license">
{{ $t('settings.style.themes3.editor.style_license') }} {{ $t('settings.style.themes3.editor.style_license') }}
</StringSetting> </StringSetting>
</li> </li>
<li> <li>
<StringSetting v-model="website"> <StringSetting class="meta-field" v-model="website">
{{ $t('settings.style.themes3.editor.style_website') }} {{ $t('settings.style.themes3.editor.style_website') }}
</StringSetting> </StringSetting>
</li> </li>

View file

@ -112,7 +112,7 @@
.shadow-preview { .shadow-preview {
grid-area: preview; grid-area: preview;
min-width: 10em; min-width: 25em;
margin-left: 0.125em; margin-left: 0.125em;
align-self: start; align-self: start;
justify-self: center; justify-self: center;

View file

@ -799,6 +799,7 @@
"link_color": "Link color", "link_color": "Link color",
"include_in_rule": "Add to rule", "include_in_rule": "Add to rule",
"test_string": "TEST", "test_string": "TEST",
"refresh_preview": "Refresh preview",
"text_auto": { "text_auto": {
"label": "Auto-contrast", "label": "Auto-contrast",
"no-preserve": "Black or White", "no-preserve": "Black or White",