Added more text functions

This commit is contained in:
2026-01-26 21:11:16 +01:00
parent c87212d54a
commit ca2020b9c6
7 changed files with 335 additions and 286 deletions

View File

@@ -1,86 +1,60 @@
<template>
<div class="flex h-full w-full bg-white overflow-hidden relative">
<div class="flex h-full w-full bg-white dark:bg-gray-900 overflow-hidden relative">
<aside
class="flex flex-col border-r border-gray-200 bg-gray-50/50 transition-all duration-300 ease-in-out overflow-hidden whitespace-nowrap h-full"
class="flex flex-col border-r border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-900/50 transition-all duration-300 ease-in-out overflow-hidden whitespace-nowrap h-full"
:class="[isSidebarOpen ? 'w-80 min-w-[20rem] translate-x-0' : 'w-0 min-w-0 -translate-x-full opacity-0 border-none']"
>
<div class="flex items-center justify-between border-b border-gray-200 px-4 py-3 bg-white h-14 shrink-0 relative z-20">
<h2 class="font-semibold text-gray-800 flex items-center gap-2">
<div class="flex items-center justify-between border-b border-gray-200 dark:border-gray-800 px-4 py-3 bg-white dark:bg-gray-900 h-14 shrink-0 relative z-20">
<h2 class="font-semibold text-gray-800 dark:text-gray-100 flex items-center gap-2">
<span class="text-primary-600">📚</span> Wiki
</h2>
<div class="flex items-center gap-1">
<UDropdown :items="rootMenuItems" :popper="{ placement: 'bottom-end' }">
<UButton color="gray" variant="ghost" icon="i-heroicons-plus" size="sm" />
</UDropdown>
<div class="relative">
<button
@click.stop="showRootMenu = !showRootMenu"
class="p-1.5 text-gray-500 hover:text-primary-600 rounded hover:bg-gray-100 transition-colors"
:class="{ 'bg-gray-100 text-primary-600': showRootMenu }"
title="Neu..."
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"><path d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z" /></svg>
</button>
<div v-if="showRootMenu" v-on-click-outside="() => showRootMenu = false" class="absolute right-0 top-full mt-1 w-40 bg-white rounded-md shadow-lg border border-gray-100 py-1 text-xs text-gray-700 animate-in fade-in slide-in-from-top-1 duration-100 origin-top-right">
<button @click="createRootItem(false)" class="w-full text-left px-3 py-2 hover:bg-gray-50 flex items-center gap-2">
<svg class="w-3 h-3 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>
Neue Seite
</button>
<button @click="createRootItem(true)" class="w-full text-left px-3 py-2 hover:bg-gray-50 flex items-center gap-2">
<svg class="w-3 h-3 text-yellow-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" /></svg>
Neuer Ordner
</button>
</div>
</div>
<button
@click="isSidebarOpen = false"
class="p-1.5 text-gray-400 hover:text-gray-700 rounded hover:bg-gray-100 transition-colors ml-1"
title="Sidebar einklappen"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"><path fill-rule="evenodd" d="M15.79 14.77a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L11.832 10l3.938 3.71a.75.75 0 01.02 1.06zm-6 0a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L5.832 10l3.938 3.71a.75.75 0 01.02 1.06z" clip-rule="evenodd" /></svg>
</button>
<UButton @click="isSidebarOpen = false" color="gray" variant="ghost" icon="i-heroicons-chevron-double-left" size="sm" />
</div>
</div>
<div class="flex-1 overflow-y-auto px-2 py-3 custom-scrollbar">
<div v-if="isLoadingTree && !tree.length" class="space-y-2 px-2 mt-2">
<div class="h-4 w-3/4 bg-gray-200 animate-pulse rounded"></div>
<div class="h-4 w-1/2 bg-gray-200 animate-pulse rounded"></div>
<USkeleton class="h-4 w-3/4" />
<USkeleton class="h-4 w-1/2" />
</div>
<div v-else>
<WikiTreeItem v-for="node in tree" :key="node.id" :item="node" />
<div v-if="!tree.length" class="text-center text-sm text-gray-400 mt-10 px-4">
Keine Seiten.<br>Erstelle den ersten Ordner oben rechts!
Keine Seiten vorhanden.<br>Erstelle den ersten Eintrag oben rechts.
</div>
</div>
</div>
</aside>
<main class="flex-1 overflow-hidden relative bg-white h-full flex flex-col min-w-0">
<main class="flex-1 overflow-hidden relative bg-white dark:bg-gray-900 h-full flex flex-col min-w-0">
<div v-if="pageId && page" class="flex flex-col h-full">
<header class="px-8 pt-8 pb-4 flex flex-col gap-2 shrink-0">
<div class="flex items-center gap-3 w-full">
<button
<UButton
v-show="!isSidebarOpen"
@click="isSidebarOpen = true"
class="p-2 -ml-2 text-gray-400 hover:text-primary-600 hover:bg-gray-100 rounded transition-colors shrink-0"
title="Sidebar öffnen"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-6 h-6"><path fill-rule="evenodd" d="M4 10a.75.75 0 01.75-.75h7.5a.75.75 0 010 1.5h-7.5A.75.75 0 014 10z" clip-rule="evenodd" /><path fill-rule="evenodd" d="M4 6a.75.75 0 01.75-.75h11.5a.75.75 0 010 1.5H4.75A.75.75 0 014 6z" clip-rule="evenodd" /><path fill-rule="evenodd" d="M4 14a.75.75 0 01.75-.75h11.5a.75.75 0 010 1.5H4.75A.75.75 0 014 14z" clip-rule="evenodd" /></svg>
</button>
icon="i-heroicons-bars-3"
color="gray"
variant="ghost"
class="-ml-2 shrink-0"
/>
<input
v-model="page.title"
@blur="saveTitle"
@keydown.enter="($event.target as HTMLInputElement).blur()"
class="text-4xl font-bold text-gray-900 w-full outline-none placeholder-gray-300 bg-transparent min-w-0"
class="text-4xl font-bold text-gray-900 dark:text-white w-full outline-none placeholder-gray-300 bg-transparent min-w-0"
placeholder="Unbenannte Seite"
/>
</div>
@@ -89,65 +63,98 @@
<span>{{ new Date(page.createdAt).toLocaleDateString() }}</span>
<transition name="fade">
<span v-if="isSaving" class="text-primary-600 flex items-center gap-1">
<svg class="animate-spin h-3 w-3" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>
Speichert...
<UIcon name="i-heroicons-arrow-path" class="w-3 h-3 animate-spin" /> Speichert...
</span>
<span v-else-if="lastSaved" class="text-green-600">Gespeichert</span>
</transition>
</div>
</header>
<div class="flex-1 overflow-hidden border-t border-gray-100">
<div class="flex-1 overflow-hidden border-t border-gray-100 dark:border-gray-800">
<WikiEditor v-model="contentBuffer" @update:modelValue="handleContentChange" />
</div>
</div>
<div v-else-if="pageId && pendingPage" class="flex h-full items-center justify-center text-gray-400">
<div class="flex flex-col items-center gap-2">
<svg class="animate-spin h-8 w-8 text-gray-300" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>
<UIcon name="i-heroicons-arrow-path" class="w-8 h-8 animate-spin text-gray-300" />
<span>Lade Seite...</span>
</div>
</div>
<div v-else class="flex h-full flex-col items-center justify-center text-gray-400 bg-gray-50/30">
<button
v-if="!isSidebarOpen"
@click="isSidebarOpen = true"
class="absolute left-4 top-4 p-2 bg-white border shadow-sm rounded-md hover:bg-gray-50"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"><path fill-rule="evenodd" d="M4 10a.75.75 0 01.75-.75h7.5a.75.75 0 010 1.5h-7.5A.75.75 0 014 10z" clip-rule="evenodd" /><path fill-rule="evenodd" d="M4 6a.75.75 0 01.75-.75h11.5a.75.75 0 010 1.5H4.75A.75.75 0 014 6z" clip-rule="evenodd" /><path fill-rule="evenodd" d="M4 14a.75.75 0 01.75-.75h11.5a.75.75 0 010 1.5H4.75A.75.75 0 014 14z" clip-rule="evenodd" /></svg>
</button>
<div v-else class="flex h-full flex-col items-center justify-center text-gray-400 bg-gray-50/30 dark:bg-gray-800/30">
<UButton v-if="!isSidebarOpen" @click="isSidebarOpen = true" icon="i-heroicons-bars-3" color="white" class="absolute left-4 top-4" />
<div class="bg-gray-100 p-6 rounded-full mb-4">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-12 h-12 text-gray-400"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25" /></svg>
<div class="bg-gray-100 dark:bg-gray-800 p-6 rounded-full mb-4">
<UIcon name="i-heroicons-document" class="w-12 h-12 text-gray-400" />
</div>
<p class="text-lg font-medium text-gray-600">Keine Seite ausgewählt</p>
<p class="text-lg font-medium text-gray-600 dark:text-gray-300">Keine Seite ausgewählt</p>
<p class="text-sm mt-1">Wähle eine Notiz aus der Navigation.</p>
</div>
</main>
<UModal v-model="isModalOpen">
<UCard :ui="{ ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
{{ modalTitle }}
</h3>
<UButton color="gray" variant="ghost" icon="i-heroicons-x-mark-20-solid" class="-my-1" @click="isModalOpen = false" />
</div>
</template>
<div v-if="modalState.type === 'create'" class="space-y-4">
<UFormGroup label="Titel" name="title">
<UInput v-model="modalState.inputValue" autofocus placeholder="z.B. Meeting Notes" @keyup.enter="handleModalConfirm" />
</UFormGroup>
</div>
<div v-else-if="modalState.type === 'delete'">
<p class="text-sm text-gray-500 dark:text-gray-300">
Möchtest du <strong>"{{ modalState.targetItem?.title }}"</strong> wirklich löschen?
<br><span v-if="modalState.targetItem?.isFolder" class="text-red-500 font-medium">Alle Unterseiten werden ebenfalls gelöscht.</span>
</p>
</div>
<template #footer>
<div class="flex justify-end gap-2">
<UButton color="gray" variant="ghost" @click="isModalOpen = false">Abbrechen</UButton>
<UButton
:color="modalState.type === 'delete' ? 'red' : 'primary'"
:loading="modalLoading"
@click="handleModalConfirm"
>
{{ modalState.type === 'delete' ? 'Löschen' : 'Erstellen' }}
</UButton>
</div>
</template>
</UCard>
</UModal>
</div>
</template>
<script setup lang="ts">
import { vOnClickOutside } from '@vueuse/components' // Import für Click-Outside
import WikiTreeItem from '~/components/wiki/TreeItem.vue'
import WikiEditor from '~/components/wiki/WikiEditor.vue'
import type { WikiPageItem } from '~/composables/useWikiTree'
// --- SETUP ---
const route = useRoute()
const router = useRouter()
const { $api } = useNuxtApp()
const { tree, isLoading: isLoadingTree, loadTree, isSidebarOpen, createItem } = useWikiTree()
const { tree, isLoading: isLoadingTree, loadTree, isSidebarOpen, createItem, deleteItem } = useWikiTree()
// --- EDITOR LOGIC ---
const pageId = computed(() => route.params.id as string | undefined)
// UI States
const showRootMenu = ref(false)
const isSaving = ref(false)
const lastSaved = ref(false)
const saveTimeout = ref<any>(null)
const contentBuffer = ref(null)
// Init Load
onMounted(() => loadTree())
watch(pageId, () => {
@@ -167,24 +174,91 @@ const { data: page, pending: pendingPage } = await useAsyncData(
{ watch: [pageId], immediate: true }
)
// --- ACTIONS ---
// --- MODAL LOGIC (Zentralisiert) ---
async function createRootItem(isFolder: boolean) {
showRootMenu.value = false // Menü schließen
const type = isFolder ? "Ordner" : "Seite"
const title = prompt(`Name für neuen Root-${type}:`, `Neuer ${type}`)
if (!title) return
const isModalOpen = ref(false)
const modalLoading = ref(false)
const newItem = await createItem(title, null, isFolder)
const modalState = reactive({
type: 'create' as 'create' | 'delete',
targetItem: null as WikiPageItem | null, // Bei Create: Parent. Bei Delete: Das Item selbst.
isFolderCreation: false,
inputValue: ''
})
// Nur bei Seiten navigieren wir, Ordner bleiben in der Struktur
// @ts-ignore
if (newItem && !isFolder) {
// @ts-ignore
router.push(`/wiki/${newItem.id}`)
const modalTitle = computed(() => {
if (modalState.type === 'delete') return 'Eintrag löschen'
return modalState.isFolderCreation ? 'Neuen Ordner erstellen' : 'Neue Seite erstellen'
})
// Diese Funktion wird an Kinder via Inject weitergegeben
function openWikiAction(type: 'create' | 'delete', contextItem: WikiPageItem | null, isFolder = false) {
modalState.type = type
modalState.targetItem = contextItem
modalState.isFolderCreation = isFolder
modalState.inputValue = '' // Reset
if (type === 'create') {
// Optional: Prefix generieren
}
isModalOpen.value = true
}
// Bereitstellen für TreeItems
provide('openWikiAction', openWikiAction)
async function handleModalConfirm() {
modalLoading.value = true
try {
if (modalState.type === 'create') {
if (!modalState.inputValue.trim()) return
const parentId = modalState.targetItem ? modalState.targetItem.id : null
const newItem = await createItem(modalState.inputValue, parentId, modalState.isFolderCreation)
// Wenn Seite erstellt wurde -> hin navigieren
if (newItem && !modalState.isFolderCreation) {
// @ts-ignore
router.push(`/wiki/${newItem.id}`)
}
}
else if (modalState.type === 'delete' && modalState.targetItem) {
const success = await deleteItem(modalState.targetItem.id)
// Falls wir die aktuelle Seite löschen, ab zum Root
if (success && pageId.value === modalState.targetItem.id) {
router.push('/wiki')
}
}
isModalOpen.value = false
} catch (e) {
console.error(e)
// Hier könnte man einen UNotification Toast anzeigen
} finally {
modalLoading.value = false
}
}
// --- ROOT MENU ---
// Konfiguration für UDropdown
const rootMenuItems = [
[{
label: 'Neue Seite',
icon: 'i-heroicons-document-plus',
click: () => openWikiAction('create', null, false)
}],
[{
label: 'Neuer Ordner',
icon: 'i-heroicons-folder-plus',
click: () => openWikiAction('create', null, true)
}]
]
// --- EDITOR ACTIONS ---
async function saveTitle() {
if (!page.value || !pageId.value) return
isSaving.value = true
@@ -219,6 +293,7 @@ function showSavedFeedback() {
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background-color: #e5e7eb; border-radius: 10px; }
:deep(.dark) .custom-scrollbar::-webkit-scrollbar-thumb { background-color: #374151; }
.fade-enter-active, .fade-leave-active { transition: opacity 0.5s; }
.fade-enter-from, .fade-leave-to { opacity: 0; }