From 938beb2c62f184ce4871fbdef966829ad03bf393 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Tue, 12 Nov 2024 12:56:37 +0300 Subject: [PATCH] Add initial download option --- .../components/layout/AppDesigner.vue | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/showcase/components/layout/AppDesigner.vue b/apps/showcase/components/layout/AppDesigner.vue index 931600def..27cc4ae1e 100644 --- a/apps/showcase/components/layout/AppDesigner.vue +++ b/apps/showcase/components/layout/AppDesigner.vue @@ -54,8 +54,8 @@ @@ -85,6 +85,38 @@ export default { methods: { apply() { updatePreset(this.preset); + }, + download() { + const theme = JSON.stringify(this.preset, null, 4).replace(/"([^"]+)":/g, '$1:'); + const textContent = `import { createApp } from "vue"; +import PrimeVue from "primevue/config"; +import Aura from "@primevue/themes/aura"; +import { definePreset } from "@primevue/themes"; + +const app = createApp(App); + +const MyPreset = definePreset(Aura, ${theme}); + +app.use(PrimeVue, { + theme: { + preset: MyPreset + }, +}); +app.mount("#app"); +`; + const blob = new Blob([textContent], { type: 'text/plain' }); + + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + + a.href = url; + a.download = 'mytheme.js'; + document.body.appendChild(a); + a.click(); + + document.body.removeChild(a); + URL.revokeObjectURL(url); } } };