From 2ad822a20b08d4e1b40c5b8514ff77d1c29f9718 Mon Sep 17 00:00:00 2001 From: Owen Kriz Date: Fri, 13 Dec 2024 11:13:59 +0800 Subject: [PATCH] feat: update toc style & toc jump --- example/src/App.svelte | 4 +- example/src/components/TableOfContents.svelte | 129 ++++++++++-------- example/src/components/ToggleToc.svelte | 19 +++ example/src/locales/zh_CN.json | 2 + example/src/states/global.svelte.ts | 3 +- 5 files changed, 99 insertions(+), 58 deletions(-) create mode 100644 example/src/components/ToggleToc.svelte diff --git a/example/src/App.svelte b/example/src/App.svelte index d46e2c0..654d6d4 100644 --- a/example/src/App.svelte +++ b/example/src/App.svelte @@ -5,14 +5,15 @@ import htmlRaw from "@/assets/explain.html?raw" import ExportContent from "@/components/ExportContent.svelte" + import TableOfContents from "@/components/TableOfContents.svelte" import ToggleLocale from "@/components/ToggleLocale.svelte" import ToggleSparkLine from "@/components/ToggleSparkLine.svelte" import ThemeMode from "@/components/ToggleTheme.svelte" + import ToggleToc from "@/components/ToggleToc.svelte" import Toolbar from "@/components/Toolbar.svelte" 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" /* @@ -78,6 +79,7 @@
+ diff --git a/example/src/components/TableOfContents.svelte b/example/src/components/TableOfContents.svelte index f04c1ed..08e9da5 100644 --- a/example/src/components/TableOfContents.svelte +++ b/example/src/components/TableOfContents.svelte @@ -1,92 +1,109 @@ - + -
-

Table of Contents

-
    +
    +

    Table of Contents

    +
    +
      {#each headings as heading} -
    • - {heading.text} +
    • +
    • {/each}
    - diff --git a/example/src/components/ToggleToc.svelte b/example/src/components/ToggleToc.svelte new file mode 100644 index 0000000..4f125f9 --- /dev/null +++ b/example/src/components/ToggleToc.svelte @@ -0,0 +1,19 @@ + + + diff --git a/example/src/locales/zh_CN.json b/example/src/locales/zh_CN.json index 5ee042c..4374c17 100644 --- a/example/src/locales/zh_CN.json +++ b/example/src/locales/zh_CN.json @@ -1,6 +1,8 @@ { "en_US": "English", "zh_CN": "简体中文", + "Open Toc": "打开目录", + "Close Toc": "关闭目录", "Undo": "撤销", "Redo": "重做", "Confirm": "确认", diff --git a/example/src/states/global.svelte.ts b/example/src/states/global.svelte.ts index 40dc4fd..d818ec7 100644 --- a/example/src/states/global.svelte.ts +++ b/example/src/states/global.svelte.ts @@ -1,3 +1,4 @@ export const globalState = $state({ - viewSparkLines: localStorage.getItem("toolbar-spark-line") === "1" + viewSparkLines: localStorage.getItem("toolbar-spark-line") === "1", + viewToc: false })