From 3e20386a3663b35fa67797662273bc6d3a68edf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 25 Sep 2018 08:08:51 +0200 Subject: [PATCH 1/2] allow passing html strings to setContent --- examples/Components/Routes/Export/index.vue | 9 +++++++-- packages/tiptap/src/components/editor.js | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/Components/Routes/Export/index.vue b/examples/Components/Routes/Export/index.vue index 3a47159dc..547718a91 100644 --- a/examples/Components/Routes/Export/index.vue +++ b/examples/Components/Routes/Export/index.vue @@ -171,10 +171,11 @@ export default { this.html = getHTML() }, clearContent() { - this.$refs.editor.clearContent() + this.$refs.editor.clearContent(true) this.$refs.editor.focus() }, setContent() { + // you can pass a json document this.$refs.editor.setContent({ type: 'doc', content: [{ @@ -186,7 +187,11 @@ export default { }, ], }], - }) + }, true) + + // HTML string is also supported + // this.$refs.editor.setContent('

This is some inserted text. 👋

') + this.$refs.editor.focus() }, }, diff --git a/packages/tiptap/src/components/editor.js b/packages/tiptap/src/components/editor.js index 0cb0dcf26..da268c4cb 100644 --- a/packages/tiptap/src/components/editor.js +++ b/packages/tiptap/src/components/editor.js @@ -255,10 +255,25 @@ export default { }) }, + getDocFromContent(content) { + if (typeof content === 'object') { + return this.schema.nodeFromJSON(content) + } + + if (typeof content === 'string') { + const element = document.createElement('div') + element.innerHTML = content.trim() + + return DOMParser.fromSchema(this.schema).parse(element) + } + + return false + }, + setContent(content = {}, emitUpdate = false) { this.state = EditorState.create({ schema: this.state.schema, - doc: this.schema.nodeFromJSON(content), + doc: this.getDocFromContent(content), plugins: this.state.plugins, }) From 19da299b0ab49bdfaace07a53d75f7c93cc4fde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 25 Sep 2018 08:09:37 +0200 Subject: [PATCH 2/2] Publish - tiptap-extensions@0.15.0 - tiptap@0.13.0 --- packages/tiptap-extensions/package.json | 4 ++-- packages/tiptap/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tiptap-extensions/package.json b/packages/tiptap-extensions/package.json index e30def550..2124aaaa6 100644 --- a/packages/tiptap-extensions/package.json +++ b/packages/tiptap-extensions/package.json @@ -1,6 +1,6 @@ { "name": "tiptap-extensions", - "version": "0.14.1", + "version": "0.15.0", "description": "Extensions for tiptap", "homepage": "https://tiptap.scrumpy.io", "license": "MIT", @@ -24,7 +24,7 @@ "lowlight": "^1.10.0", "prosemirror-history": "^1.0.2", "prosemirror-view": "^1.5.1", - "tiptap": "^0.12.1", + "tiptap": "^0.13.0", "tiptap-commands": "^0.3.0" } } diff --git a/packages/tiptap/package.json b/packages/tiptap/package.json index 992e6819c..446029bf8 100644 --- a/packages/tiptap/package.json +++ b/packages/tiptap/package.json @@ -1,6 +1,6 @@ { "name": "tiptap", - "version": "0.12.1", + "version": "0.13.0", "description": "A rich-text editor for Vue.js", "homepage": "https://tiptap.scrumpy.io", "license": "MIT",