chore: add newlines before/after table if required

This commit is contained in:
Aman Harwara
2023-12-05 19:07:55 +05:30
parent 6af36431e2
commit 94413018f6

View File

@@ -7,7 +7,7 @@
*/
import { INSERT_TABLE_COMMAND, TableNode, TableRowNode } from '@lexical/table'
import { LexicalEditor } from 'lexical'
import { $createParagraphNode, LexicalEditor } from 'lexical'
import { useEffect, useState } from 'react'
import Button from '../Lexical/UI/Button'
import { DialogActions } from '../Lexical/UI/Dialog'
@@ -62,6 +62,13 @@ export function RemoveBrokenTablesPlugin() {
if (!node.getFirstChild()) {
node.remove()
}
const hasNextSibling = !!node.getNextSibling()
const hasPreviousSibling = !!node.getPreviousSibling()
if (!hasNextSibling) {
node.insertAfter($createParagraphNode())
} else if (!hasPreviousSibling) {
node.insertBefore($createParagraphNode())
}
}),
)
}, [editor])