refactoring
This commit is contained in:
@@ -11,9 +11,6 @@ export const FocusEvents = Extension.create({
|
||||
new Plugin({
|
||||
key: new PluginKey('focusEvents'),
|
||||
props: {
|
||||
attributes: {
|
||||
tabindex: '0',
|
||||
},
|
||||
handleDOMEvents: {
|
||||
focus: (view, event) => {
|
||||
editor.isFocused = true
|
||||
|
||||
@@ -3,3 +3,4 @@ export { Commands } from './commands'
|
||||
export { Editable } from './editable'
|
||||
export { FocusEvents } from './focusEvents'
|
||||
export { Keymap } from './keymap'
|
||||
export { Tabindex } from './tabindex'
|
||||
|
||||
19
packages/core/src/extensions/tabindex.ts
Normal file
19
packages/core/src/extensions/tabindex.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { Extension } from '../Extension'
|
||||
|
||||
export const Tabindex = Extension.create({
|
||||
name: 'tabindex',
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
new Plugin({
|
||||
key: new PluginKey('tabindex'),
|
||||
props: {
|
||||
attributes: {
|
||||
tabindex: '0',
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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), {})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export default function mergeAttributes(...objects: Record<string, any>[]): Reco
|
||||
|
||||
if (!exists) {
|
||||
mergedAttributes[key] = value
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default function removeElement(element: HTMLElement): void {
|
||||
if (element && element.parentNode) {
|
||||
if (element?.parentNode) {
|
||||
element.parentNode.removeChild(element)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user