From 8725de3e9179a52a3a085d4dfec6a84ecbd339af Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 6 Oct 2024 18:56:45 +0300 Subject: [PATCH] got it working again --- .../tabs/style_tab/style_tab.js | 148 ++++++++++-------- .../tabs/style_tab/style_tab.scss | 18 +-- .../tabs/style_tab/style_tab.vue | 61 ++++++-- src/services/export_import/export_import.js | 13 +- 4 files changed, 152 insertions(+), 88 deletions(-) diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.js b/src/components/settings_modal/tabs/style_tab/style_tab.js index 3b5dba94..4e9a3906 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.js +++ b/src/components/settings_modal/tabs/style_tab/style_tab.js @@ -60,6 +60,9 @@ export default { ContrastRatio }, setup () { + // All rules that are made by editor + const allEditedRules = reactive({}) + // ## Meta stuff const name = ref('') const author = ref('') @@ -79,6 +82,18 @@ export default { // ## Palette stuff const palettes = reactive([ + { + name: 'dark', + bg: '#121a24', + fg: '#182230', + text: '#b9b9ba', + link: '#d8a070', + accent: '#d8a070', + cRed: '#FF0000', + cBlue: '#0095ff', + cGreen: '#0fa00f', + cOrange: '#ffa500' + }, { name: 'light', bg: '#f2f6f9', @@ -91,18 +106,6 @@ export default { cGreen: '#0fa00f', cOrange: '#ffa500', border: '#d8e6f9' - }, - { - name: 'dark', - bg: '#121a24', - fg: '#182230', - text: '#b9b9ba', - link: '#d8a070', - accent: '#d8a070', - cRed: '#FF0000', - cBlue: '#0095ff', - cGreen: '#0fa00f', - cOrange: '#ffa500' } ]) const selectedPaletteId = ref(0) @@ -225,9 +228,6 @@ export default { return root }) - // All rules that are made by editor - const allEditedRules = reactive({}) - // Checkging whether component can support some "directives" which // are actually virtual subcomponents, i.e. Text, Link etc const componentHas = (subComponent) => { @@ -395,53 +395,6 @@ export default { return null } }) - const updatePreview = () => { - try { - const { name, ...paletteData } = selectedPalette.value - const rules = init({ - inputRuleset: editorFriendlyToOriginal.value, - initialStaticVars: { - ...paletteData - }, - ultimateBackgroundColor: '#000000', - rootComponentName: selectedComponentName.value, - editMode: true, - debug: true - }).eager - previewRules.splice(0, previewRules.length) - previewRules.push(...rules) - } catch (e) { - console.error('Could not compile preview theme', e) - } - } - const updateSelectedComponent = () => { - selectedVariant.value = 'normal' - selectedState.clear() - updatePreview() - } - updateSelectedComponent() - - watch( - allEditedRules, - updatePreview - ) - - watch( - palettes, - updatePreview - ) - - watch( - selectedPalette, - updatePreview - ) - - watch( - selectedComponentName, - updateSelectedComponent - ) - - // export and import const editorFriendlyToOriginal = computed(() => { const resultRules = [] @@ -481,10 +434,61 @@ export default { return resultRules }) + const updatePreview = () => { + try { + const { name, ...paletteData } = selectedPalette.value + // This normally would be handled by Root but since we pass something + // else we have to make do ourselves + paletteData.accent = paletteData.accent || paletteData.link + paletteData.link = paletteData.link || paletteData.accent + const rules = init({ + inputRuleset: editorFriendlyToOriginal.value, + initialStaticVars: { + ...paletteData + }, + ultimateBackgroundColor: '#000000', + rootComponentName: selectedComponentName.value, + editMode: true, + debug: true + }).eager + previewRules.splice(0, previewRules.length) + previewRules.push(...rules) + } catch (e) { + console.error('Could not compile preview theme', e) + } + } + + const updateSelectedComponent = () => { + selectedVariant.value = 'normal' + selectedState.clear() + updatePreview() + } + updateSelectedComponent() + + // export and import + watch( + allEditedRules, + updatePreview + ) + + watch( + palettes, + updatePreview + ) + + watch( + selectedPalette, + updatePreview + ) + + watch( + selectedComponentName, + updateSelectedComponent + ) + // ## Variables const allCustomVirtualDirectives = [...componentsMap.values()] .map(c => { - console.log(c.defaultRules.filter(c => c.component === 'Root')) return c .defaultRules .filter(c => c.component === 'Root') @@ -504,6 +508,17 @@ export default { const virtualDirectives = reactive(allCustomVirtualDirectives) const selectedVirtualDirectiveId = ref(0) const selectedVirtualDirective = computed(() => virtualDirectives[selectedVirtualDirectiveId.value]) + const selectedVirtualDirectiveParsed = computed({ + get () { + switch (selectedVirtualDirective.value.valType) { + case 'shadow': + return {} + default: + return null + } + } + }) + const getNewDirective = () => ({ name: 'newDirective', valType: 'generic', @@ -512,8 +527,10 @@ export default { // ## Export and Import const styleExporter = newExporter({ - filename: 'pleroma.palette.json', - getExportedObject: () => exportStyleData + filename: name.value || 'pleroma_theme', + mime: 'text/plain', + extension: 'piss', + getExportedObject: () => exportStyleData.value }) const exportStyleData = computed(() => { return [ @@ -591,6 +608,7 @@ export default { virtualDirectives, selectedVirtualDirective, selectedVirtualDirectiveId, + selectedVirtualDirectiveParsed, getNewDirective, // ## Export and Import diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.scss b/src/components/settings_modal/tabs/style_tab/style_tab.scss index f557b7d5..0f8540f9 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.scss +++ b/src/components/settings_modal/tabs/style_tab/style_tab.scss @@ -87,34 +87,32 @@ } } - .palette-editor { + .list-editor { display: grid; grid-template-areas: "label editor" "selector editor" - "motion editor"; + "movement editor"; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr auto; grid-gap: 0.5em; - .palette-editor-edit { + .list-edit-area { grid-area: editor; } - .palette-selector { + .list-select { + grid-area: selector; + margin: 0; + &-label { font-weight: bold; grid-area: label; margin: 0; } - } - - .palette-list { - grid-area: selector; - margin: 0; &-movement { - grid-area: motion; + grid-area: movement; margin: 0; } } diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.vue b/src/components/settings_modal/tabs/style_tab/style_tab.vue index 326db5cc..8aaa6713 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.vue +++ b/src/components/settings_modal/tabs/style_tab/style_tab.vue @@ -258,10 +258,10 @@
+
+ + + +
+ + {{ selectedVirtualDirective.valType }} +
+
diff --git a/src/services/export_import/export_import.js b/src/services/export_import/export_import.js index e1ac6a42..b8f84351 100644 --- a/src/services/export_import/export_import.js +++ b/src/services/export_import/export_import.js @@ -2,15 +2,22 @@ import utf8 from 'utf8' export const newExporter = ({ filename = 'data', + mime = 'application/json', + extension = '.json', getExportedObject }) => ({ exportData () { - const stringified = utf8.encode(JSON.stringify(getExportedObject(), null, 2)) // Pretty-print and indent with 2 spaces + let stringified + if (mime === 'application/json') { + stringified = utf8.encode(JSON.stringify(getExportedObject(), null, 2)) // Pretty-print and indent with 2 spaces + } else { + stringified = utf8.encode(getExportedObject()) // Pretty-print and indent with 2 spaces + } // Create an invisible link with a data url and simulate a click const e = document.createElement('a') - e.setAttribute('download', `${filename}.json`) - e.setAttribute('href', 'data:application/json;base64,' + window.btoa(stringified)) + e.setAttribute('download', `${filename}.${extension}`) + e.setAttribute('href', `data:${mime};base64, ${window.btoa(stringified)}`) e.style.display = 'none' document.body.appendChild(e)