import Head from 'next/head'; import Link from 'next/link'; import {useEffect,useRef,useState} from 'react'; import {useRouter} from 'next/router'; import {X,ChevronLeft,ChevronRight,Link as LinkIcon,FileText,Pencil} from 'lucide-react'; import type {ExploreEntry} from '@/lib/explore'; import {previewUrl,exploreUrl} from '@/content/page-links'; import {Shell} from './Shell'; import {ExploreFeed} from './ExploreFeed'; import {NoteMarkdown} from './NoteMarkdown'; import {NoteEditor} from './NoteEditor'; export function ExploreDetail({entry:initial,background}:{entry:ExploreEntry;background:ExploreEntry[]}){ const [entry,setEntry]=useState(initial),[index,setIndex]=useState(0),[copied,setCopied]=useState(''),[editing,setEditing]=useState(false),[copyError,setCopyError]=useState(''); const router=useRouter();const closeRef=useRef(null),detailRef=useRef(null);const media=entry.media[index]; useEffect(()=>{setEntry(initial);setIndex(0);setCopied('');setEditing(false)},[initial]); const close=()=>{if(editing){setEditing(false);return;}void router.push('/')}; useEffect(()=>{ const previous=document.activeElement as HTMLElement|null;if(!editing)closeRef.current?.focus();const old=document.body.style.overflow;document.body.style.overflow='hidden'; function key(e:KeyboardEvent){ if(e.key==='Escape'){e.preventDefault();close();return;} const typing=e.target instanceof HTMLElement&&!!e.target.closest('input,textarea,select,[contenteditable="true"]'); if(!editing&&!typing&&e.key==='ArrowLeft')setIndex(n=>Math.max(0,n-1)); if(!editing&&!typing&&e.key==='ArrowRight')setIndex(n=>Math.max(0,Math.min(entry.media.length-1,n+1))); if(e.key==='Tab'){const items=Array.from(detailRef.current?.querySelectorAll('a[href],button:not(:disabled),input:not(:disabled),textarea:not(:disabled),select:not(:disabled),summary,video,audio')||[]).filter(el=>el.getClientRects().length);if(!items.length)return;const first=items[0],last=items[items.length-1];if(e.shiftKey&&document.activeElement===first){e.preventDefault();last.focus()}else if(!e.shiftKey&&document.activeElement===last){e.preventDefault();first.focus()}} } window.addEventListener('keydown',key);return()=>{document.body.style.overflow=old;window.removeEventListener('keydown',key);previous?.focus()}; },[entry.id,editing]); async function copy(mode:'web'|'agent'){ try{const url=window.location.origin+exploreUrl(entry.id)+(mode==='agent'?'?agent_mode=True':''); if(navigator.clipboard)await navigator.clipboard.writeText(url);else{const input=document.createElement('textarea');input.value=url;document.body.appendChild(input);input.select();const success=document.execCommand('copy');input.remove();if(!success)throw Error('Copy failed');} setCopied(mode);setCopyError(''); }catch{setCopied('');setCopyError('复制失败,请重试。')} } return {entry.title} · waterfall-wiki
{if(!editing)close()}}>
e.stopPropagation()}>
{media?.kind==='image'?{media.title}:media?.kind==='video'?
{editing?setEditing(false)} onSaved={updated=>{setEntry(updated);setEditing(false);setCopied('')}}/>:<>

{entry.title}

{entry.description}

{entry.categories.map(c=>#{c} )}
内容 ID · {entry.id}
}
{!editing&&}
; }