add heading command
This commit is contained in:
@@ -71,6 +71,7 @@ export class Editor extends EventEmitter {
|
||||
this.registerCommand('setContent', require('./commands/setContent').default)
|
||||
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||
this.registerCommand('removeMarks', require('./commands/removeMarks').default)
|
||||
this.registerCommand('toggleBlockType', require('./commands/toggleBlockType').default)
|
||||
|
||||
if (this.options.injectCSS) {
|
||||
require('./style.css')
|
||||
|
||||
30
packages/core/src/commands/toggleBlockType.ts
Normal file
30
packages/core/src/commands/toggleBlockType.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { setBlockType } from 'prosemirror-commands'
|
||||
import { Editor } from '../Editor'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
toggleBlockType(type: NodeType, toggleType: NodeType, attrs?: {}): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
export default function toggleBlockType(
|
||||
next: Function,
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
toggleType: NodeType,
|
||||
attrs?: {},
|
||||
): void {
|
||||
const { view, state } = editor
|
||||
const isActive = nodeIsActive(state, type, attrs)
|
||||
|
||||
if (isActive) {
|
||||
setBlockType(toggleType)(view.state, view.dispatch)
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
setBlockType(type, attrs)(view.state, view.dispatch)
|
||||
next()
|
||||
}
|
||||
Reference in New Issue
Block a user