From c38bf94532b98d319f1a25849ae408ac61cb9cd7 Mon Sep 17 00:00:00 2001 From: Thibault Date: Fri, 3 Oct 2025 17:10:15 +1000 Subject: [PATCH] Fix TOC update on new heading and edit --- src/lib/nodeviews/toc/Toc.svelte | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/nodeviews/toc/Toc.svelte b/src/lib/nodeviews/toc/Toc.svelte index 575ddcb..7f5ed77 100644 --- a/src/lib/nodeviews/toc/Toc.svelte +++ b/src/lib/nodeviews/toc/Toc.svelte @@ -5,6 +5,8 @@ import TocChildren from './TocChildren.svelte'; import TocLevels from './TocLevels.svelte'; import { IconMessage } from '@hyvor/design/components'; + import { editorContent } from '../../store'; + import { getDocFromContent } from '../../helpers'; interface Props { view: EditorView; @@ -18,16 +20,16 @@ let toc = $derived(generateToc(doc, levels)); - function handleTransaction(e: any) { - doc = e.detail.doc; - } + // Subscribe to editor content changes to update the document + $effect(() => { + const unsubscribe = editorContent.subscribe((content) => { + if (content && view) { + // Parse the document from the content store to get the latest changes + doc = getDocFromContent(content); + } + }); - onMount(() => { - // TODO: change this without prosemirror:transaction - // document.addEventListener('prosemirror:transaction', handleTransaction); - return () => { - // document.removeEventListener('prosemirror:transaction', handleTransaction); - }; + return unsubscribe; }); function handleLevelsChange(e: CustomEvent) {