fix(editor): don't crash when the component isn't completely mounted
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2023-11-21 13:25:55 +01:00
parent f45303c2e3
commit 0c58ea1ade
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 8 additions and 5 deletions

View File

@ -494,8 +494,8 @@ function setLink() {
onMounted(() => {
internalMode.value = initialMode
nextTick(() => {
const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0]
input.addEventListener('paste', handleImagePaste)
const input = tiptapInstanceRef.value?.querySelectorAll('.tiptap__editor')[0]?.children[0]
input?.addEventListener('paste', handleImagePaste)
})
if (editShortcut !== '') {
document.addEventListener('keydown', setFocusToEditor)
@ -504,8 +504,8 @@ onMounted(() => {
onBeforeUnmount(() => {
nextTick(() => {
const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0]
input.removeEventListener('paste', handleImagePaste)
const input = tiptapInstanceRef.value?.querySelectorAll('.tiptap__editor')[0]?.children[0]
input?.removeEventListener('paste', handleImagePaste)
})
if (editShortcut !== '') {
document.removeEventListener('keydown', setFocusToEditor)
@ -554,7 +554,10 @@ watch(
() => isEditing.value,
editing => {
nextTick(() => {
const checkboxes = tiptapInstanceRef.value.querySelectorAll('[data-checked]')
const checkboxes = tiptapInstanceRef.value?.querySelectorAll('[data-checked]')
if (typeof checkboxes === 'undefined' || checkboxes.length === 0) {
return
}
if (editing) {
checkboxes.forEach(check => {
if (check.children.length < 2) {