From 3353dfcef534ee9807cc35e8eed47c1c991af6f6 Mon Sep 17 00:00:00 2001 From: Ahmad Luthfi Masruri Date: Mon, 22 Mar 2021 11:34:24 +0700 Subject: [PATCH 1/3] feat: add methods getEditor, getToolbar, reinit --- src/components/QuillEditor.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/components/QuillEditor.ts b/src/components/QuillEditor.ts index a0d386de..dc06ef34 100644 --- a/src/components/QuillEditor.ts +++ b/src/components/QuillEditor.ts @@ -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 @@ -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, @@ -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) => { @@ -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) => { @@ -244,9 +245,12 @@ export default defineComponent({ return { editor, + getEditor, + getToolbar, getQuill, getHTML, setHTML, + reinit, }; }, inheritAttrs: false, From ee6f74d9d7ee23771914538e23f5c54a46bc93c0 Mon Sep 17 00:00:00 2001 From: Ahmad Luthfi Masruri Date: Mon, 22 Mar 2021 11:35:31 +0700 Subject: [PATCH 2/3] perf: add import Quill from quill/core --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index f1893524..d8b6f8c9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,7 @@ */ import QuillEditor from "./components/QuillEditor" -import Quill from "quill" +import Quill from "quill/core" export { QuillEditor as default, From 8f71f8a68793d2b56bcfe5894475ad7ac34acfaf Mon Sep 17 00:00:00 2001 From: Ahmad Luthfi Masruri Date: Mon, 22 Mar 2021 11:35:42 +0700 Subject: [PATCH 3/3] docs: update docs --- docs/content/api/methods.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/content/api/methods.md b/docs/content/api/methods.md index 94ceec5f..18b97e1b 100644 --- a/docs/content/api/methods.md +++ b/docs/content/api/methods.md @@ -1,5 +1,21 @@ # Methods +::: warning +We highly recommend to call method when the quill editor ready, use @ready event +::: + +## getEditor() + +- **Return:** `editor: Element` + + Returns the Editor Element. + +## getToolbar() + +- **Return:** `toolbar: Element` + + Returns the Toolbar Element. + ## getQuill() - **Return:** `quill: Quill`