add allowGapCursor option

This commit is contained in:
Philipp Kühn
2021-02-19 11:17:27 +01:00
parent b06b368621
commit 46501ee226

View File

@@ -1,6 +1,15 @@
import { Extension } from '@tiptap/core' import { Extension, callOrReturn } from '@tiptap/core'
import { gapCursor } from 'prosemirror-gapcursor' import { gapCursor } from 'prosemirror-gapcursor'
declare module '@tiptap/core' {
interface NodeConfig<Options> {
/**
* Allow gap cursor
*/
allowGapCursor?: boolean | ((this: { options: Options }) => boolean),
}
}
export const Gapcursor = Extension.create({ export const Gapcursor = Extension.create({
name: 'gapCursor', name: 'gapCursor',
@@ -9,4 +18,12 @@ export const Gapcursor = Extension.create({
gapCursor(), gapCursor(),
] ]
}, },
extendNodeSchema(extension) {
const context = { options: extension.options }
return {
allowGapCursor: callOrReturn(extension.config.allowGapCursor, context) ?? null,
}
},
}) })