diff --git a/apps/client/src/widgets/sidebar/TableOfContents.tsx b/apps/client/src/widgets/sidebar/TableOfContents.tsx index 14378248b..b4391b678 100644 --- a/apps/client/src/widgets/sidebar/TableOfContents.tsx +++ b/apps/client/src/widgets/sidebar/TableOfContents.tsx @@ -2,15 +2,22 @@ import { CKTextEditor, ModelElement } from "@triliumnext/ckeditor5"; import { useEffect, useState } from "preact/hooks"; import { t } from "../../services/i18n"; -import { useActiveNoteContext, useIsNoteReadOnly, useNoteProperty, useTextEditor, useTriliumEvent } from "../react/hooks"; +import { useActiveNoteContext, useIsNoteReadOnly, useNoteProperty, useTextEditor } from "../react/hooks"; import RightPanelWidget from "./RightPanelWidget"; -interface CKHeading { +interface RawHeading { level: number; text: string; +} + +interface CKHeading extends RawHeading { element: ModelElement; } +interface HeadingsWithNesting extends RawHeading { + children: HeadingsWithNesting[]; +} + export default function TableOfContents() { const { note, noteContext } = useActiveNoteContext(); const noteType = useNoteProperty(note, "type"); @@ -56,16 +63,48 @@ function EditableTextTableOfContents() { } function AbstractTableOfContents({ headings }: { - headings: { - level: number; - text: string; - }[]; + headings: RawHeading[]; }) { - return headings.map(heading => ( -