Skip to content

Commit

Permalink
feat: add methods getEditor, getToolbar, reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
luthfimasruri committed Mar 22, 2021
1 parent 16e31a0 commit 3353dfc
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/components/QuillEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default defineComponent({
if (props.theme !== "bubble") editor.value.classList.remove("ql-bubble");
if (props.theme !== "snow") editor.value.classList.remove("ql-snow");
// Fix clicking the quill toolbar is detected as blur event
quill.getModule("toolbar")?.container.addEventListener("mousedown", (e) => {
quill.getModule("toolbar")?.container.addEventListener("mousedown", (e: MouseEvent) => {
e.preventDefault();
});
// Emit ready event
Expand Down Expand Up @@ -191,6 +191,14 @@ export default defineComponent({
}
};

const getEditor = (): Element => {
return editor.value as Element
}

const getToolbar = (): Element => {
return quill?.getModule("toolbar")?.container
}

const getQuill = (): Quill => {
if (quill) return quill
else throw `The quill editor hasn't been instantiated yet,
Expand All @@ -206,6 +214,12 @@ export default defineComponent({
quill?.clipboard.dangerouslyPasteHTML(html)
}

const reinit = () => {
if (!ctx.slots.toolbar && quill)
quill.getModule("toolbar")?.container.remove();
initialize();
}

watch(
() => props.content,
(newContent, oldContent) => {
Expand All @@ -222,19 +236,6 @@ export default defineComponent({
}
);

watch(
[
() => props.options,
() => props.theme,
() => props.toolbar
],
() => {
if (!ctx.slots.toolbar && quill)
quill.getModule("toolbar")?.container.remove();
initialize();
}
);

watch(
() => props.enable,
(newValue, oldValue) => {
Expand All @@ -244,9 +245,12 @@ export default defineComponent({

return {
editor,
getEditor,
getToolbar,
getQuill,
getHTML,
setHTML,
reinit,
};
},
inheritAttrs: false,
Expand Down

0 comments on commit 3353dfc

Please sign in to comment.