refactoring

This commit is contained in:
Philipp Kühn
2021-01-23 22:48:34 +01:00
parent 71376f6de7
commit 56417a44a7
7 changed files with 34 additions and 25 deletions

View File

@@ -57,7 +57,9 @@ export const Table = Node.create({
group: 'block',
parseHTML() {
return [{ tag: 'table' }]
return [
{ tag: 'table' },
]
},
renderHTML({ HTMLAttributes }) {
@@ -66,14 +68,14 @@ export const Table = Node.create({
addCommands() {
return {
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true }): Command => ({ state, dispatch }) => {
const offset = state.tr.selection.anchor + 1
const nodes = createTable(this.editor.schema, rows, cols, withHeaderRow)
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
const resolvedPos = tr.doc.resolve(offset)
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true }): Command => ({ tr, dispatch, editor }) => {
const offset = tr.selection.anchor + 1
const node = createTable(editor.schema, rows, cols, withHeaderRow)
if (dispatch) {
tr.setSelection(TextSelection.near(resolvedPos))
tr.replaceSelectionWith(node)
.scrollIntoView()
.setSelection(TextSelection.near(tr.doc.resolve(offset)))
}
return true