From 67261dd09c526a9f39e358a92fbc14ef2aa5e005 Mon Sep 17 00:00:00 2001 From: Owen Kriz Date: Fri, 13 Dec 2024 10:45:33 +0800 Subject: [PATCH] Add Table of Contents component Implement a fixed Table of Contents (TOC) for the current editing document. * **App.svelte** - Import the new `TableOfContents` component. - Add the `TableOfContents` component to the DOM. * **TableOfContents.svelte** - Create a new Svelte component for the Table of Contents. - Use the `getEditorContext` function to access the editor state. - Render a list of headings from the current document. - Add styles for the Table of Contents to be fixed on the side of the editor. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/aolyang/tiptap-contentful?shareId=XXXX-XXXX-XXXX-XXXX). --- example/src/App.svelte | 2 + example/src/components/TableOfContents.svelte | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 example/src/components/TableOfContents.svelte diff --git a/example/src/App.svelte b/example/src/App.svelte index f3ce692..d46e2c0 100644 --- a/example/src/App.svelte +++ b/example/src/App.svelte @@ -12,6 +12,7 @@ import { setEditorContext } from "@/states/toolbar" import { createEditor } from "@/utils/editor" import { aligns, headingLevels } from "@/utils/editor-presets" + import TableOfContents from "@/components/TableOfContents.svelte" import { onMount } from "svelte" /* @@ -88,5 +89,6 @@
+
diff --git a/example/src/components/TableOfContents.svelte b/example/src/components/TableOfContents.svelte new file mode 100644 index 0000000..f04c1ed --- /dev/null +++ b/example/src/components/TableOfContents.svelte @@ -0,0 +1,92 @@ + + + + +
+

Table of Contents

+ +
+ +