Skip to content

Commit

Permalink
feat(editor): Use initial content and accept parsed json
Browse files Browse the repository at this point in the history
  • Loading branch information
larvanitis committed Aug 4, 2020
1 parent d2cd6f7 commit 9e40200
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/components/QuasarTiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ export default {
return {
// editor
editor: null,
json: {},
html: '',
selectedCellSize: 0
}
},
props: {
content: {
type: String,
type: [String, Object],
default: ''
},
editable: {
Expand Down Expand Up @@ -196,7 +194,7 @@ export default {
extensions: extensions,
autoFocus: true,
editable: this.editable,
content: '',
content: this.getContent(),
onInit: ({ state, view }) => {
this.$emit('init', { state, view })
},
Expand Down Expand Up @@ -263,22 +261,21 @@ export default {
return extensions
},
// content
setContent () {
try {
this.json = JSON.parse(this.content)
this.html = ''
} catch (e) {
this.html = this.content
this.json = {}
}
// From JSON
if (this.json && this.json.type) {
this.editor.setContent(this.json, true)
getContent () {
let content = this.content || '';
if (content && content.type) {
return content; // parsed json
}
if (this.html) {
this.editor.setContent(this.html, true)
if (typeof content === 'string') {
try {
return JSON.parse(content) // json
} catch (e) {
return content; // html
}
}
},
setContent () {
this.editor.setContent(this.getContent(), true)
// Focus
this.editor.focus()
Expand All @@ -304,9 +301,6 @@ export default {
},
mounted: function () {
this.initEditor()
// set content
this.setContent()
},
deactivated () {
},
Expand Down

0 comments on commit 9e40200

Please sign in to comment.