feat: add editor prop to KeyboardShortcutCommand
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
import { Plugin, Transaction } from 'prosemirror-state'
|
import { Plugin, Transaction } from 'prosemirror-state'
|
||||||
import { Command as ProseMirrorCommand } from 'prosemirror-commands'
|
|
||||||
import { InputRule } from 'prosemirror-inputrules'
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
import { Node } from './Node'
|
import { Node } from './Node'
|
||||||
import { Mark } from './Mark'
|
import { Mark } from './Mark'
|
||||||
import mergeDeep from './utilities/mergeDeep'
|
import mergeDeep from './utilities/mergeDeep'
|
||||||
import { GlobalAttributes, RawCommands, ParentConfig } from './types'
|
import {
|
||||||
|
GlobalAttributes,
|
||||||
|
RawCommands,
|
||||||
|
ParentConfig,
|
||||||
|
KeyboardShortcutCommand,
|
||||||
|
} from './types'
|
||||||
import { ExtensionConfig } from '.'
|
import { ExtensionConfig } from '.'
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
@@ -52,7 +56,7 @@ declare module '@tiptap/core' {
|
|||||||
editor: Editor,
|
editor: Editor,
|
||||||
parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
|
parent: ParentConfig<ExtensionConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: KeyboardShortcutCommand,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -190,7 +190,15 @@ export default class ExtensionManager {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (addKeyboardShortcuts) {
|
if (addKeyboardShortcuts) {
|
||||||
const keyMapPlugin = keymap(addKeyboardShortcuts())
|
const bindings = Object.fromEntries(
|
||||||
|
Object
|
||||||
|
.entries(addKeyboardShortcuts())
|
||||||
|
.map(([shortcut, method]) => {
|
||||||
|
return [shortcut, () => method({ editor: this.editor })]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const keyMapPlugin = keymap(bindings)
|
||||||
|
|
||||||
plugins.push(keyMapPlugin)
|
plugins.push(keyMapPlugin)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
MarkType,
|
MarkType,
|
||||||
} from 'prosemirror-model'
|
} from 'prosemirror-model'
|
||||||
import { Plugin, Transaction } from 'prosemirror-state'
|
import { Plugin, Transaction } from 'prosemirror-state'
|
||||||
import { Command as ProseMirrorCommand } from 'prosemirror-commands'
|
|
||||||
import { InputRule } from 'prosemirror-inputrules'
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import mergeDeep from './utilities/mergeDeep'
|
import mergeDeep from './utilities/mergeDeep'
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +12,7 @@ import {
|
|||||||
RawCommands,
|
RawCommands,
|
||||||
GlobalAttributes,
|
GlobalAttributes,
|
||||||
ParentConfig,
|
ParentConfig,
|
||||||
|
KeyboardShortcutCommand,
|
||||||
} from './types'
|
} from './types'
|
||||||
import { Node } from './Node'
|
import { Node } from './Node'
|
||||||
import { MarkConfig } from '.'
|
import { MarkConfig } from '.'
|
||||||
@@ -64,7 +64,7 @@ declare module '@tiptap/core' {
|
|||||||
type: MarkType,
|
type: MarkType,
|
||||||
parent: ParentConfig<MarkConfig<Options>>['addKeyboardShortcuts'],
|
parent: ParentConfig<MarkConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: KeyboardShortcutCommand,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
Node as ProseMirrorNode,
|
Node as ProseMirrorNode,
|
||||||
NodeType,
|
NodeType,
|
||||||
} from 'prosemirror-model'
|
} from 'prosemirror-model'
|
||||||
import { Command as ProseMirrorCommand } from 'prosemirror-commands'
|
|
||||||
import { Plugin, Transaction } from 'prosemirror-state'
|
import { Plugin, Transaction } from 'prosemirror-state'
|
||||||
import { InputRule } from 'prosemirror-inputrules'
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import mergeDeep from './utilities/mergeDeep'
|
import mergeDeep from './utilities/mergeDeep'
|
||||||
@@ -14,6 +13,7 @@ import {
|
|||||||
GlobalAttributes,
|
GlobalAttributes,
|
||||||
RawCommands,
|
RawCommands,
|
||||||
ParentConfig,
|
ParentConfig,
|
||||||
|
KeyboardShortcutCommand,
|
||||||
} from './types'
|
} from './types'
|
||||||
import { NodeConfig } from '.'
|
import { NodeConfig } from '.'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
@@ -64,7 +64,7 @@ declare module '@tiptap/core' {
|
|||||||
type: NodeType,
|
type: NodeType,
|
||||||
parent: ParentConfig<NodeConfig<Options>>['addKeyboardShortcuts'],
|
parent: ParentConfig<NodeConfig<Options>>['addKeyboardShortcuts'],
|
||||||
}) => {
|
}) => {
|
||||||
[key: string]: ProseMirrorCommand,
|
[key: string]: KeyboardShortcutCommand,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ export type Command = (props: CommandProps) => boolean
|
|||||||
|
|
||||||
export type CommandSpec = (...args: any[]) => Command
|
export type CommandSpec = (...args: any[]) => Command
|
||||||
|
|
||||||
|
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
|
||||||
|
|
||||||
export type Attribute = {
|
export type Attribute = {
|
||||||
default: any,
|
default: any,
|
||||||
rendered?: boolean,
|
rendered?: boolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user