This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
</div>
|
||||
|
||||
<div v-if="showMenu" v-on-click-outside="() => showMenu = false" class="absolute right-0 top-8 z-50 w-40 bg-white dark:bg-gray-800 rounded-md shadow-lg border border-gray-100 dark:border-gray-700 py-1 text-xs text-gray-700 dark:text-gray-200 animate-in fade-in slide-in-from-top-1 duration-100">
|
||||
|
||||
<template v-if="item.isFolder">
|
||||
<button @click.stop="triggerCreate(false)" class="w-full text-left px-3 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-plus" class="w-3 h-3" /> Neue Seite
|
||||
@@ -41,7 +40,6 @@
|
||||
</button>
|
||||
<div class="h-px bg-gray-100 dark:bg-gray-700 my-1"></div>
|
||||
</template>
|
||||
|
||||
<button @click.stop="triggerDelete" class="w-full text-left px-3 py-1.5 hover:bg-red-50 dark:hover:bg-red-900/30 text-red-600 flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-trash" class="w-3 h-3" /> Löschen
|
||||
</button>
|
||||
@@ -59,15 +57,12 @@
|
||||
import { vOnClickOutside } from '@vueuse/components'
|
||||
import type { WikiPageItem } from '~/composables/useWikiTree'
|
||||
|
||||
// Rekursiver Component Name (wichtig für Nuxt Auto-Import, oft automatisch 'WikiTreeItem')
|
||||
// Falls Recursion Issues auftreten: defineOptions({ name: 'WikiTreeItem' })
|
||||
|
||||
const props = defineProps<{ item: WikiPageItem; depth?: number }>()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
// NEU: searchQuery importieren für Auto-Expand
|
||||
const { searchQuery } = useWikiTree()
|
||||
|
||||
// --- INJECT ---
|
||||
// Wir holen uns die Funktion zum Öffnen des Modals von der Hauptseite
|
||||
const openWikiAction = inject('openWikiAction') as (action: 'create' | 'delete', contextItem: WikiPageItem | null, isFolder?: boolean) => void
|
||||
|
||||
const depth = props.depth ?? 0
|
||||
@@ -76,11 +71,18 @@ const isOpen = ref(false)
|
||||
const showMenu = ref(false)
|
||||
const isActive = computed(() => route.params.id === props.item.id)
|
||||
|
||||
// Auto-Open Logic (Ordner öffnen, wenn Kind aktiv ist)
|
||||
// Auto-Open Logic 1: Aktive Seite
|
||||
watch(() => route.params.id, (newId) => {
|
||||
if (props.item.isFolder && hasActiveChild(props.item, newId as string)) isOpen.value = true
|
||||
}, { immediate: true })
|
||||
|
||||
// NEU: Auto-Open Logic 2: Suche aktiv -> Alles aufklappen
|
||||
watch(searchQuery, (newVal) => {
|
||||
if (newVal.trim().length > 0 && props.item.isFolder) {
|
||||
isOpen.value = true
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
function hasActiveChild(node: WikiPageItem, targetId: string): boolean {
|
||||
if (node.id === targetId) return true
|
||||
return node.children?.some(c => hasActiveChild(c, targetId)) ?? false
|
||||
@@ -89,17 +91,12 @@ function hasActiveChild(node: WikiPageItem, targetId: string): boolean {
|
||||
function handleClick() {
|
||||
props.item.isFolder ? (isOpen.value = !isOpen.value) : router.push(`/wiki/${props.item.id}`)
|
||||
}
|
||||
|
||||
function toggleFolder() { isOpen.value = !isOpen.value }
|
||||
|
||||
// --- ACTIONS ---
|
||||
|
||||
function triggerCreate(isFolder: boolean) {
|
||||
showMenu.value = false
|
||||
isOpen.value = true // Ordner aufklappen
|
||||
isOpen.value = true
|
||||
openWikiAction('create', props.item, isFolder)
|
||||
}
|
||||
|
||||
function triggerDelete() {
|
||||
showMenu.value = false
|
||||
openWikiAction('delete', props.item)
|
||||
|
||||
Reference in New Issue
Block a user