refactoring

This commit is contained in:
Philipp Kühn
2021-09-22 22:45:27 +02:00
parent f4e3b07672
commit e5c765c8e4
9 changed files with 30 additions and 22 deletions

View File

@@ -17,9 +17,9 @@ export default function getMarkAttributes(state: EditorState, typeOrName: string
const mark = marks.find(markItem => markItem.type.name === type.name)
if (mark) {
return { ...mark.attrs }
if (!mark) {
return {}
}
return {}
return { ...mark.attrs }
}

View File

@@ -15,9 +15,9 @@ export default function getNodeAttributes(state: EditorState, typeOrName: string
.reverse()
.find(nodeItem => nodeItem.type.name === type.name)
if (node) {
return { ...node.attrs }
if (!node) {
return {}
}
return {}
return { ...node.attrs }
}

View File

@@ -14,7 +14,5 @@ export default function getRenderedAttributes(nodeOrMark: Node | Mark, extension
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
})
.reduce((attributes, attribute) => {
return mergeAttributes(attributes, attribute)
}, {})
.reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})
}

View File

@@ -1,13 +1,5 @@
import { MarkType, NodeType, Schema } from 'prosemirror-model'
export default function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
if (schema.nodes[name]) {
return schema.nodes[name]
}
if (schema.marks[name]) {
return schema.marks[name]
}
return null
return schema.nodes[name] || schema.marks[name] || null
}