-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow v-model #133
Comments
This is probably better done one level higher. Lets say you have a component setting up the TipTap editor. There in the
More at https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components |
Hi Dirk, Thank you for your answer. Anyway my idea was make the editor more user-friendly and following the best Vue component building practice. v-model is a one of these practices. Making component that not supported this out of the box is quite weird. |
I see. This is certainly a good idea following the best practice. While working with TipTap I came to the point to decide in which format the editor state should be stored. Instead of serializing to HTML in my case it was better to wrap it into an object like this;
Therefore I would love to see a dual implementation: 1. The current BTW, keep up the great work. This is an awesome project! |
@holtwick's solution worked well for me. Ofcourse I had to create a prop called
|
EDIT: There's a better solution #133 (comment) Here's how I did it. props: [ 'value' ],
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [ ],
content: this.value,
onUpdate: ({ getHTML }) => {
this.$emit('input', getHTML())
},
})
this.editor.setContent(this.value)
},
beforeDestroy() {
if (this.editor) {
this.editor.destroy()
}
},
watch: {
value (val) {
// so cursor doesn't jump to start on typing
if (this.editor && val !== this.value) {
this.editor.setContent(val, true)
}
}
} I use it on its parent like this
Works fine for me. PS: might have some issue with performance (on 100,000 characters or more) |
This comment was marked as spam.
This comment was marked as spam.
Any suggestions how I can improve that? |
This comment was marked as spam.
This comment was marked as spam.
@laurensiusadi props: ["value"],
data() {
return {
editor: null,
editorChange: false
};
},
mounted() {
this.editor = new Editor({
onUpdate: ({ getHTML }) => {
this.editorChange = true;
this.$emit("input", getHTML());
},
content: this.value,
extensions: [/* ... */]
});
},
beforeDestroy() {
if (this.editor) this.editor.destroy();
},
watch: {
value(val) {
if (this.editor && !this.editorChange) {
this.editor.setContent(val, true);
}
this.editorChange = false;
}
} Not sure if there's a better way, but this works with vuex |
Is there a way to use |
I just came across this library and I must say that it's amazing. I was just going through all the issues to see if I can use it in my project and this issues seems very critical to me. I just wanted to confirm if there is anyone working on this issue. I could start looking into it if no one else is already working on it. Once again, thanks for this awesome editor. |
@Ravikc I'm not sure if this is a big issue, since it works okay for me now. But if you want to start looking into it, that would be awesome! |
https://www.npmjs.com/package/tiptap-vuetify worked this out |
I'm gonna rewrite the code from tiptap-vuetify here in JS (they're in TS) props: ["value"],
data() {
return {
editor: null,
emitAfterOnUpdate: false
};
},
mounted() {
this.editor = new Editor({
onUpdate: ({ getHTML }) => {
this.emitAfterOnUpdate = true;
this.$emit("input", getHTML());
},
content: this.value,
extensions: [/* ... */]
});
},
beforeDestroy() {
if (this.editor) this.editor.destroy();
},
watch: {
value(val) {
if (this.emitAfterOnUpdate) {
this.emitAfterOnUpdate = false
return
}
if (this.editor) this.editor.setContent(val)
}
} Pretty similar to @estani code Haven't test this yet EDIT: This works best for me |
You must set |
With that i get problem with carret position lag,anyone get same? or how to resolve it better? |
Thanks for sharing the solutions! ❤️ I’m closing this here. I think we’ll provide support for it in tiptap 2 (or provide a wrapper component). |
to use custom editor wrapper like this, write this in the parent component <custom-editor :value="detail" v-on:input="detail = $event" /> detail as props in value |
@alloself
How to use: <editor
:key="id"
v-model="noteContent"
/> Editor component: props: ["value"],
data() {
return {
editor: null
};
},
mounted() {
this.editor = new Editor({
content: this.value,
onUpdate: ({ getHTML }) => {
this.$emit("input", getHTML());
},
extensions: [/* ... */]
});
},
beforeDestroy() {
if (this.editor) this.editor.destroy();
} I removed Note: This won't work 2 ways (real-time) since you only emit data and not watching to receive and update editor content. |
You can also just use the key attribute on your component, that way when the editor opens it will detect a different key and force an update. |
I should've done that! Thanks! |
I'm getting getHTML is not a function error constantly by this way |
Are you using tiptap 1 or 2? Here is an example for tiptap v2: https://www.tiptap.dev/installation/vue2#5-use-v-model-optional |
@hanspagel I'm using tiptap 2 |
Realized editor is a ref re "getHTML is not a function error" - here is the code that works for me:
(deleted original post of code that didn't work) |
That worked for me like this
|
ok now how do you do this in react... Edit: Never mind I found out how this solution works for react and if the code is the same should work for vue. The white spaces are set to false by default in the setContent options so you just need to turn them on by doing either true or "full" for all white spacing. onUpdate: ({editor}) => {
const cleanText = profanity.clean(editor.getHTML());
editor.commands.setContent(cleanText, false, {preserveWhitespace: "full"});
} |
Please allow using of v-model in editor
The text was updated successfully, but these errors were encountered: