refactoring
This commit is contained in:
@@ -11,9 +11,6 @@ export const FocusEvents = Extension.create({
|
|||||||
new Plugin({
|
new Plugin({
|
||||||
key: new PluginKey('focusEvents'),
|
key: new PluginKey('focusEvents'),
|
||||||
props: {
|
props: {
|
||||||
attributes: {
|
|
||||||
tabindex: '0',
|
|
||||||
},
|
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
focus: (view, event) => {
|
focus: (view, event) => {
|
||||||
editor.isFocused = true
|
editor.isFocused = true
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ export { Commands } from './commands'
|
|||||||
export { Editable } from './editable'
|
export { Editable } from './editable'
|
||||||
export { FocusEvents } from './focusEvents'
|
export { FocusEvents } from './focusEvents'
|
||||||
export { Keymap } from './keymap'
|
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)
|
const mark = marks.find(markItem => markItem.type.name === type.name)
|
||||||
|
|
||||||
if (mark) {
|
if (!mark) {
|
||||||
return { ...mark.attrs }
|
|
||||||
}
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { ...mark.attrs }
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ export default function getNodeAttributes(state: EditorState, typeOrName: string
|
|||||||
.reverse()
|
.reverse()
|
||||||
.find(nodeItem => nodeItem.type.name === type.name)
|
.find(nodeItem => nodeItem.type.name === type.name)
|
||||||
|
|
||||||
if (node) {
|
if (!node) {
|
||||||
return { ...node.attrs }
|
|
||||||
}
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { ...node.attrs }
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,5 @@ export default function getRenderedAttributes(nodeOrMark: Node | Mark, extension
|
|||||||
|
|
||||||
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
||||||
})
|
})
|
||||||
.reduce((attributes, attribute) => {
|
.reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})
|
||||||
return mergeAttributes(attributes, attribute)
|
|
||||||
}, {})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import { MarkType, NodeType, Schema } from 'prosemirror-model'
|
import { MarkType, NodeType, Schema } from 'prosemirror-model'
|
||||||
|
|
||||||
export default function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
|
export default function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
|
||||||
if (schema.nodes[name]) {
|
return schema.nodes[name] || schema.marks[name] || null
|
||||||
return schema.nodes[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (schema.marks[name]) {
|
|
||||||
return schema.marks[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default function mergeAttributes(...objects: Record<string, any>[]): Reco
|
|||||||
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
mergedAttributes[key] = value
|
mergedAttributes[key] = value
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export default function removeElement(element: HTMLElement): void {
|
export default function removeElement(element: HTMLElement): void {
|
||||||
if (element && element.parentNode) {
|
if (element?.parentNode) {
|
||||||
element.parentNode.removeChild(element)
|
element.parentNode.removeChild(element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user