improve types

This commit is contained in:
Philipp Kühn
2021-01-28 09:50:17 +01:00
parent a9c14fbddd
commit 4407d9a3d1
20 changed files with 58 additions and 47 deletions

View File

@@ -1,22 +1,8 @@
import { InputRule } from 'prosemirror-inputrules'
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarksBetween from '../helpers/getMarksBetween'
function getMarksBetween(start: number, end: number, state: EditorState) {
let marks: any[] = []
state.doc.nodesBetween(start, end, (node, pos) => {
marks = [...marks, ...node.marks.map(mark => ({
start: pos,
end: pos + node.nodeSize,
mark,
}))]
})
return marks
}
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function) {
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function): InputRule {
return new InputRule(regexp, (state, match, start, end) => {
const attributes = getAttributes instanceof Function
? getAttributes(match)
@@ -33,6 +19,8 @@ export default function (regexp: RegExp, markType: MarkType, getAttributes?: Fun
const excludedMarks = getMarksBetween(start, end, state)
.filter(item => {
// TODO: PR to add excluded to MarkType
// @ts-ignore
const { excluded } = item.mark.type
return excluded.find((type: MarkType) => type.name === markType.name)
})