import { useEditor } from "novel"; import { motion } from "framer-motion"; type tContent = { id: string; textContent: string; level: number; isActive: boolean; itemIndex: number; isScrolledOver: boolean; pos: number; }; export const ToCItem = ({ item, onItemClick, }: { item: tContent; onItemClick: (pos: number) => void; }) => { return (
onItemClick(item.pos)} className={`cursor-pointer text-base font-medium py-1 px-2 w-full hover:bg-[#2b3238] transition-colors rounded-sm ${item.isActive && "text-blue-500"}`} > {item.textContent}
); }; export const ToC = ({ items }: { items: tContent[] }) => { if (items.length < 2) { return; } return (
{items.map((item, i) => ( ))}
); }; function Container({ items }: { items: tContent[] }) { const { editor } = useEditor(); const onItemClick = (pos: number) => { console.log(pos); if (editor) { editor.commands.focus(pos ? pos : 1, { scrollIntoView: true }); } }; return (
{items.map((item, i) => ( ))}
); } export function ToCItemStick({ item }: { item: tContent }) { return (
); }