add clearContent command
This commit is contained in:
@@ -54,7 +54,8 @@ export class Editor extends EventEmitter {
|
||||
this.registerCommand('insertText', require('./commands/insertText').default)
|
||||
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
||||
this.registerCommand('setContent', require('./commands/setContent').default)
|
||||
|
||||
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||
|
||||
if (this.options.injectCSS) {
|
||||
injectCSS(require('./style.css'))
|
||||
}
|
||||
@@ -84,7 +85,7 @@ export class Editor extends EventEmitter {
|
||||
}
|
||||
|
||||
this.commands[name] = this.chainCommand((...args: any) => {
|
||||
return new Promise(resolve => callback(resolve, this, ...args))
|
||||
return new Promise(resolve => callback(resolve, this.proxy, ...args))
|
||||
})
|
||||
|
||||
return this.proxy
|
||||
|
||||
13
packages/tiptap-core/src/commands/clearContent.ts
Normal file
13
packages/tiptap-core/src/commands/clearContent.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
clearContent(emitUpdate?: Boolean): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
export default function clearContent(next: Function, editor: Editor, emitUpdate = false): void {
|
||||
editor.setContent('', emitUpdate)
|
||||
next()
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { TextSelection } from 'prosemirror-state'
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
setContent(content: string, emitUpdate: Boolean, parseOptions: any): Editor,
|
||||
setContent(content: string, emitUpdate?: Boolean, parseOptions?: any): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ export default function setContent(
|
||||
next: Function,
|
||||
editor: Editor,
|
||||
content = null,
|
||||
emitUpdate = true,
|
||||
emitUpdate = false,
|
||||
parseOptions = {},
|
||||
): void {
|
||||
if (content === null) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const { view, state, createDocument } = editor
|
||||
const { doc, tr } = state
|
||||
const document = createDocument(content, parseOptions)
|
||||
|
||||
Reference in New Issue
Block a user