'use client' import { useState, type MouseEvent } from 'react' import Link from 'next/link' import { useTranslation } from 'react-i18next' import { ArrowLeft, Bookmark, Check, ChevronRight, CornerUpRight, FileDown, FileText, MoreHorizontal, PanelLeft, Pin, PinOff, Sparkles, } from 'lucide-react' import Tooltip from '@/shared/ui/Tooltip' import { useMenuPopover } from '@/shared/ui/useMenuPopover' import { FeatureCrumb, InstanceCrumb } from '@/components/layout/LocationCrumbs' import { useShelfFeature } from '@/components/sidebar/PageBar' import type { NotePage, NoteSummary } from '@/lib/notes-api' import { pageHasFlashcards } from '../model/flashcards' export type NoteSaveStatus = 'Saved' | 'Saving…' | 'Unsaved changes' | 'Save failed' function Crumb({ page, onNavigate, }: { page: Pick onNavigate: (event: MouseEvent, id: string) => void }) { const { t } = useTranslation() return ( onNavigate(event, page.id)} > {page.icon && {page.icon}} {page.title || t('Untitled')} ) } export default function NoteTopBar({ page, pages, invalidParents, status, busy, embedded, treeOpen, companionOpen, onToggleTree, onToggleCompanion, onNavigate, onOpenPage, onCreatePage, onMetadata, onInsertFavorite, onExport, }: { page: NotePage | null pages: NoteSummary[] invalidParents: Set status: NoteSaveStatus busy: boolean embedded: boolean treeOpen: boolean companionOpen: boolean onToggleTree: () => void onToggleCompanion: () => void onNavigate: (event: MouseEvent, id: string) => void /** Opens another page from the page switcher, saving this one first. */ onOpenPage: (id: string) => void onCreatePage: () => void onMetadata: (patch: Partial) => void onInsertFavorite: () => void onExport: (format: 'md' | 'docx' | 'anki') => void }) { const { t } = useTranslation() const feature = useShelfFeature('/co-writer') const [open, setOpenState] = useState(false) const [moving, setMoving] = useState(false) const [query, setQuery] = useState('') const setOpen = (value: boolean | ((current: boolean) => boolean)) => { const next = typeof value === 'function' ? value(open) : value setOpenState(next) if (!next) { setMoving(false) setQuery('') } } const menu = useMenuPopover(open, setOpen) const byId = new Map(pages.map(p => [p.id, p])) const ancestors: NoteSummary[] = [] for ( let parent = page?.parent_id ? byId.get(page.parent_id) : undefined, guard = 0; parent && guard < 12; parent = parent.parent_id ? byId.get(parent.parent_id) : undefined, guard++ ) ancestors.unshift(parent) // Deep pages keep their first and last ancestor; the middle folds away. const shown = ancestors.length > 2 ? [ancestors[0], null, ancestors.at(-1)!] : ancestors const targets = pages .filter(p => p.id !== page?.id && !invalidParents.has(p.id)) .filter(p => (p.title || '').toLowerCase().includes(query.trim().toLowerCase())) const move = (parent_id: string | null) => { setOpen(false) onMetadata({ parent_id }) } return (
{/* 「笔记本 / … / this page」: the feature opens onto the home shelf, the page onto every other page of the notebook. */} {t(status)}
{open && page && (
{moving ? ( <> setQuery(e.target.value)} />
{!query.trim() && ( )} {targets.map(target => ( ))} {!targets.length && query.trim() && (

{t('No matching pages')}

)}
) : ( <>
{pageHasFlashcards(page.blocks) && ( )}

{t('Word export keeps text and source links; interactive blocks become static.')}

)}
)}
) }