add clearContent command
This commit is contained in:
@@ -54,6 +54,7 @@ export class Editor extends EventEmitter {
|
|||||||
this.registerCommand('insertText', require('./commands/insertText').default)
|
this.registerCommand('insertText', require('./commands/insertText').default)
|
||||||
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
||||||
this.registerCommand('setContent', require('./commands/setContent').default)
|
this.registerCommand('setContent', require('./commands/setContent').default)
|
||||||
|
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||||
|
|
||||||
if (this.options.injectCSS) {
|
if (this.options.injectCSS) {
|
||||||
injectCSS(require('./style.css'))
|
injectCSS(require('./style.css'))
|
||||||
@@ -84,7 +85,7 @@ export class Editor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.commands[name] = this.chainCommand((...args: any) => {
|
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
|
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' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Editor {
|
||||||
setContent(content: string, emitUpdate: Boolean, parseOptions: any): Editor,
|
setContent(content: string, emitUpdate?: Boolean, parseOptions?: any): Editor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export default function setContent(
|
|||||||
next: Function,
|
next: Function,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
content = null,
|
content = null,
|
||||||
emitUpdate = true,
|
emitUpdate = false,
|
||||||
parseOptions = {},
|
parseOptions = {},
|
||||||
): void {
|
): void {
|
||||||
if (content === null) {
|
if (content === null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user