Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/composables/useVisibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand All @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions src/createEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface CollaborativeEditorOptions {
content?: string
readOnly?: boolean
autofocus?: boolean
noLazyImages?: boolean
readonlyBar?: ReadonlyBar
menubarLinkCustomAction?: () => void
onCreate?: ({ markdown }: { markdown: string }) => void
Expand Down Expand Up @@ -63,6 +64,7 @@ interface MarkdownContentEditorOptions {
content?: string
readOnly?: boolean
autofocus?: boolean
noLazyImages?: boolean
readonlyBar?: ReadonlyBar
menubarLinkCustomAction?: () => void
onCreate?: ({ markdown }: { markdown: string }) => void
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/views/CollaborativeEditorApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<EditorReloader
ref="editor-container"
:fileId
:noLazyImages
:relativePath="filePath"
:shareToken
mime="text/markdown"
Expand All @@ -31,13 +32,15 @@ const {
fileId = undefined,
filePath = undefined,
autofocus = false,
noLazyImages = false,
readonlyBarComponent = undefined,
readonlyBarProps = {},
shareToken = undefined,
} = defineProps<{
fileId?: number
filePath?: string
autofocus?: boolean
noLazyImages?: boolean
readonlyBarComponent?: string
readonlyBarProps?: object
shareToken?: string
Expand Down
3 changes: 3 additions & 0 deletions src/views/MarkdownContentEditorApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ref="editor-container"
:content
:fileId
:noLazyImages
:readOnly
:relativePath="filePath"
:shareToken
Expand All @@ -29,13 +30,15 @@ import MarkdownContentEditor from '../components/Editor/MarkdownContentEditor.vu
const {
fileId = undefined,
filePath = undefined,
noLazyImages = false,
readOnly = false,
readonlyBarComponent = undefined,
readonlyBarProps = {},
shareToken = undefined,
} = defineProps<{
fileId?: number
filePath?: string
noLazyImages?: boolean
content: string
readOnly?: boolean
readonlyBarComponent?: string
Expand Down
Loading