From 22a04bfcaa1324bf94ad81bbd8c1387eb772a964 Mon Sep 17 00:00:00 2001 From: maxlkatze Date: Sat, 27 Jul 2024 11:10:24 +0200 Subject: [PATCH] fix(katzencore): Added mobile / desktop view switch --- src/runtime/assets/icons/desktop.svg | 15 + src/runtime/assets/icons/phone.svg | 15 + src/runtime/components/views/EditView.vue | 507 +++++++++++++--------- 3 files changed, 321 insertions(+), 216 deletions(-) create mode 100644 src/runtime/assets/icons/desktop.svg create mode 100644 src/runtime/assets/icons/phone.svg diff --git a/src/runtime/assets/icons/desktop.svg b/src/runtime/assets/icons/desktop.svg new file mode 100644 index 0000000..2eb34a2 --- /dev/null +++ b/src/runtime/assets/icons/desktop.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/runtime/assets/icons/phone.svg b/src/runtime/assets/icons/phone.svg new file mode 100644 index 0000000..ac464a2 --- /dev/null +++ b/src/runtime/assets/icons/phone.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/runtime/components/views/EditView.vue b/src/runtime/components/views/EditView.vue index b05b64d..b2495e5 100644 --- a/src/runtime/components/views/EditView.vue +++ b/src/runtime/components/views/EditView.vue @@ -7,7 +7,7 @@ import { Extension } from '@tiptap/core' import type { RouteComponent } from 'vue-router' import { ComponentType, type KatzenUIComponent, useUiStore } from '../../stores/UiStore' import type { ImageContent } from '../../composables/useUiComponents' -import { computed, defineAsyncComponent, onMounted, ref, shallowRef, useCookie, watch } from '#imports' +import { computed, defineAsyncComponent, onMounted, onUnmounted, ref, shallowRef, useCookie, watch } from '#imports' import { useAsyncData, useRouter } from '#app' const DisableEnter = Extension.create({ @@ -137,9 +137,20 @@ onMounted( childList: true, subtree: true, }) + + window.addEventListener('resize', resizeListener) }, ) +const resizeListener = () => { + viewPortHeight.value = window.innerHeight + viewPortWidth.value = window.innerWidth +} + +onUnmounted(() => { + window.removeEventListener('resize', resizeListener) +}) + watch(hoveredElement, () => { const updatePosition = () => { if (hoverPosition.value && hoveredElement.value) { @@ -385,6 +396,41 @@ watch(selectedImage, () => { }) } }) + +const mobileView = ref(false) +const viewPortHeight = ref(0) +const viewPortWidth = ref(0) + +watch(mobileView, () => { + if (mobileView.value) { + // set meta viewport width to 768px + // find if meta[name=viewport] exists if not create it + const metaViewport = document.querySelector('meta[name=viewport]') + if (metaViewport) { + metaViewport.setAttribute('content', 'width=768, initial-scale=1') + } + else { + const meta = document.createElement('meta') + meta.name = 'viewport' + meta.content = 'width=768' + document.head.appendChild(meta) + } + } + else { + // set meta viewport width to device-width + // find if meta[name=viewport] exists if not create it + const metaViewport = document.querySelector('meta[name=viewport]') + if (metaViewport) { + metaViewport.setAttribute('content', 'width=device-width, initial-scale=1') + } + else { + const meta = document.createElement('meta') + meta.name = 'viewport' + meta.content = 'width=device-width' + document.head.appendChild(meta) + } + } +})