From 9ec3d82d129c7d85a7c793c614ca2a6561dd087c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 22 Oct 2018 08:43:48 +0200 Subject: [PATCH] fix basic example --- examples/Components/Routes/Basic/index.vue | 369 +++++++-------------- packages/tiptap/src/utils/Editor.js | 26 +- 2 files changed, 128 insertions(+), 267 deletions(-) diff --git a/examples/Components/Routes/Basic/index.vue b/examples/Components/Routes/Basic/index.vue index 5a343837..ffe89462 100644 --- a/examples/Components/Routes/Basic/index.vue +++ b/examples/Components/Routes/Basic/index.vue @@ -1,257 +1,116 @@ @@ -305,18 +164,28 @@ export default { new UnderlineMark(), new HistoryExtension(), ], - content: { - type: 'doc', - content: [{ - type: 'paragraph', - content: [ - { - type: 'text', - text: 'This is some inserted text. 👋', - }, - ], - }], - }, + content: ` +

+ Hi there, +

+

+ this is a very basic example of tiptap. +

+
body { display: none; }
+ +
+ It's amazing 👏 +
+ – mom +
+ `, }), } }, diff --git a/packages/tiptap/src/utils/Editor.js b/packages/tiptap/src/utils/Editor.js index f7a642e3..8825a5ff 100644 --- a/packages/tiptap/src/utils/Editor.js +++ b/packages/tiptap/src/utils/Editor.js @@ -133,7 +133,14 @@ export default class Editor { return this.schema.nodeFromJSON(content) } - // return DOMParser.fromSchema(this.schema).parse(this.contentNode.elm) + if (typeof content === 'string') { + const element = document.createElement('div') + element.innerHTML = content.trim() + + return DOMParser.fromSchema(this.schema).parse(element) + } + + return false } createView() { @@ -187,25 +194,10 @@ export default class Editor { return this.state.doc.toJSON() } - 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.getDocFromContent(content), + doc: this.createDocument(content), plugins: this.state.plugins, })