diff --git a/docs/src/demos/Examples/Simple/index.vue b/docs/src/demos/Examples/Simple/index.vue
index ab5a70f8..cba3febe 100644
--- a/docs/src/demos/Examples/Simple/index.vue
+++ b/docs/src/demos/Examples/Simple/index.vue
@@ -2,8 +2,9 @@
-
-
+
+
+
diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts
index ffe18b02..3815fb7f 100644
--- a/packages/core/src/commands/blur.ts
+++ b/packages/core/src/commands/blur.ts
@@ -1,6 +1,6 @@
-import { Editor } from '../Editor'
+import { Command } from '../Editor'
-type BlurCommand = () => Editor
+type BlurCommand = () => Command
declare module '../Editor' {
interface Editor {
@@ -8,9 +8,10 @@ declare module '../Editor' {
}
}
-export default (next: Function, { view }: Editor) => () => {
- const element = view.dom as HTMLElement
+export const blur: BlurCommand = () => ({ editor }) => {
+ const element = editor.view.dom as HTMLElement
element.blur()
- next()
+
+ return true
}
diff --git a/packages/core/src/commands/clearContent.ts b/packages/core/src/commands/clearContent.ts
index e93325e7..64e75a3c 100644
--- a/packages/core/src/commands/clearContent.ts
+++ b/packages/core/src/commands/clearContent.ts
@@ -1,6 +1,6 @@
-import { Editor } from '../Editor'
+import { Command } from '../Editor'
-type ClearContentCommand = (emitUpdate?: Boolean) => Editor
+type ClearContentCommand = (emitUpdate?: Boolean) => Command
declare module '../Editor' {
interface Editor {
@@ -8,7 +8,9 @@ declare module '../Editor' {
}
}
-export default (next: Function, editor: Editor) => (emitUpdate = false) => {
+export const clearContent: ClearContentCommand = (emitUpdate = false) => ({ editor }) => {
+ // TODO: doesn’t work, we have to re-use `tr`
editor.setContent('', emitUpdate)
- next()
+
+ return true
}
diff --git a/packages/core/src/commands/index.ts b/packages/core/src/commands/index.ts
index 5d41397e..46cd18ac 100644
--- a/packages/core/src/commands/index.ts
+++ b/packages/core/src/commands/index.ts
@@ -1,5 +1,5 @@
-// export { default as blur } from './blur'
-// export { default as clearContent } from './clearContent'
+export { blur } from './blur'
+export { clearContent } from './clearContent'
// export { default as deleteSelection } from './deleteSelection'
export { focus } from './focus'
export { insertHTML } from './insertHTML'
@@ -10,7 +10,7 @@ export { insertText } from './insertText'
// export { default as replaceWithNode } from './replaceWithNode'
// export { default as selectAll } from './selectAll'
// export { default as selectParentNode } from './selectParentNode'
-// export { default as setContent } from './setContent'
+export { setContent } from './setContent'
// export { default as sinkListItem } from './sinkListItem'
// export { default as splitListItem } from './splitListItem'
// export { default as toggleMark } from './toggleMark'
diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts
index a53c3877..bec1e0ad 100644
--- a/packages/core/src/commands/insertHTML.ts
+++ b/packages/core/src/commands/insertHTML.ts
@@ -25,14 +25,12 @@ function selectionToInsertionEnd(tr, startLen, bias) {
}
export const insertHTML: InsertHTMLCommand = value => ({ tr, editor }) => {
- console.log({tr })
const { state } = editor
const { selection } = tr
const element = elementFromString(value)
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
tr.insert(selection.anchor, slice.content)
- // TODO: set correct bias by content
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
return true
diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts
index 7c18b726..bc9717bd 100644
--- a/packages/core/src/commands/setContent.ts
+++ b/packages/core/src/commands/setContent.ts
@@ -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
}