add more commands
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { Command } from '../Editor'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
|
||||
type SetContentCommand = (
|
||||
content: string,
|
||||
emitUpdate?: Boolean,
|
||||
parseOptions?: any,
|
||||
) => Editor
|
||||
) => Command
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
@@ -13,21 +13,19 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor) => (content: string, emitUpdate: Boolean = false, parseOptions = {}) => {
|
||||
export const setContent: SetContentCommand = (content = null, emitUpdate = false, parseOptions = {}) => ({ tr, editor }) => {
|
||||
if (content === null) {
|
||||
next()
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
const { view, state, createDocument } = editor
|
||||
const { doc, tr } = state
|
||||
const { createDocument } = editor
|
||||
const { doc } = tr
|
||||
const document = createDocument(content, parseOptions)
|
||||
const selection = TextSelection.create(doc, 0, doc.content.size)
|
||||
const transaction = tr
|
||||
.setSelection(selection)
|
||||
|
||||
tr.setSelection(selection)
|
||||
.replaceSelectionWith(document, false)
|
||||
.setMeta('preventUpdate', !emitUpdate)
|
||||
|
||||
view.dispatch(transaction)
|
||||
next()
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user