add heading keyboard shortcuts

This commit is contained in:
Hans Pagel
2020-09-25 17:17:54 +02:00
parent f71e4df72e
commit 6a78cc602f
2 changed files with 11 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ export interface HeadingOptions {
levels: Level[],
}
export type HeadingCommand = (level: Level) => Command
export type HeadingCommand = (options: { level: Level }) => Command
declare module '@tiptap/core/src/Editor' {
interface Commands {
@@ -38,11 +38,18 @@ export default new Node<HeadingOptions>()
toDOM: node => [`h${node.attrs.level}`, 0],
}))
.commands(({ name }) => ({
[name]: attrs => ({ commands }) => {
heading: attrs => ({ commands }) => {
return commands.toggleBlockType(name, 'paragraph', attrs)
},
}))
// TODO: Keyboard Shortcuts
.keys(({ name, options, editor }) => {
return options.levels.reduce((items, level) => ({
...items,
...{
[`Mod-Alt-${level}`]: () => editor.setBlockType(name, { level }),
},
}), {})
})
.inputRules(({ options, type }) => {
return options.levels.map((level: Level) => {
return textblockTypeInputRule(new RegExp(`^(#{1,${level}})\\s$`), type, { level })