diff --git a/src/composables/useVisibility.ts b/src/composables/useVisibility.ts index a748ddc4bae..2ab970f2f67 100644 --- a/src/composables/useVisibility.ts +++ b/src/composables/useVisibility.ts @@ -68,12 +68,13 @@ export function useVisibility(id: string) { const { editor } = useEditor() const intersectionObserver = inject(intersectionObserverKey)! const visibleIds = inject(visibleIdsKey)! + let observedEl: Element | null = null onMounted(() => { nextTick(() => { - const el = editor.view.dom.querySelector(`#${id}`) - if (el) { - intersectionObserver.observe(el) + observedEl = editor.view.dom.querySelector(`#${id}`) + if (observedEl) { + intersectionObserver.observe(observedEl) } else { logger.warn(`Could not find element with id ${id}`) } @@ -83,9 +84,9 @@ export function useVisibility(id: string) { onUnmounted(() => { visibleIds.value.delete(id) visibleIds.value = new Set(visibleIds.value) // trigger reactivity - const el = editor.view.dom.querySelector(`#${id}`) - if (el) { - intersectionObserver.unobserve(el) + if (observedEl) { + intersectionObserver.unobserve(observedEl) + observedEl = null } }) const visible = computed(() => visibleIds.value.has(id)) diff --git a/src/createEditor.ts b/src/createEditor.ts index dd1b44a4818..31280673c05 100644 --- a/src/createEditor.ts +++ b/src/createEditor.ts @@ -36,6 +36,7 @@ interface CollaborativeEditorOptions { content?: string readOnly?: boolean autofocus?: boolean + noLazyImages?: boolean readonlyBar?: ReadonlyBar menubarLinkCustomAction?: () => void onCreate?: ({ markdown }: { markdown: string }) => void @@ -63,6 +64,7 @@ interface MarkdownContentEditorOptions { content?: string readOnly?: boolean autofocus?: boolean + noLazyImages?: boolean readonlyBar?: ReadonlyBar menubarLinkCustomAction?: () => void onCreate?: ({ markdown }: { markdown: string }) => void @@ -116,12 +118,12 @@ export async function createCollaborativeEditor(options: CollaborativeEditorOpti const app = createApp( CollaborativeEditorApp, { - ref: 'editor-container', ...data, active: true, fileId: options.fileId, mime: 'text/markdown', autofocus: options.autofocus ?? true, + noLazyImages: options.noLazyImages ?? false, readonlyBarComponent: options.readonlyBar?.component, relativePath: options.filePath, shareToken: options.shareToken, @@ -146,9 +148,9 @@ export async function createMarkdownContentEditor(options: MarkdownContentEditor const app = createApp( MarkdownContentEditorApp, { - ref: 'editor-container', ...data, fileId: options.fileId, + noLazyImages: options.noLazyImages ?? false, readonlyBarComponent: options.readonlyBar?.component, relativePath: options.filePath, shareToken: options.shareToken, diff --git a/src/views/CollaborativeEditorApp.vue b/src/views/CollaborativeEditorApp.vue index 91a5e29bebc..8049e35774d 100644 --- a/src/views/CollaborativeEditorApp.vue +++ b/src/views/CollaborativeEditorApp.vue @@ -7,6 +7,7 @@