Skip to content

Commit 3353dfc

Browse files
committed
feat: add methods getEditor, getToolbar, reinit
1 parent 16e31a0 commit 3353dfc

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/components/QuillEditor.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default defineComponent({
110110
if (props.theme !== "bubble") editor.value.classList.remove("ql-bubble");
111111
if (props.theme !== "snow") editor.value.classList.remove("ql-snow");
112112
// Fix clicking the quill toolbar is detected as blur event
113-
quill.getModule("toolbar")?.container.addEventListener("mousedown", (e) => {
113+
quill.getModule("toolbar")?.container.addEventListener("mousedown", (e: MouseEvent) => {
114114
e.preventDefault();
115115
});
116116
// Emit ready event
@@ -191,6 +191,14 @@ export default defineComponent({
191191
}
192192
};
193193

194+
const getEditor = (): Element => {
195+
return editor.value as Element
196+
}
197+
198+
const getToolbar = (): Element => {
199+
return quill?.getModule("toolbar")?.container
200+
}
201+
194202
const getQuill = (): Quill => {
195203
if (quill) return quill
196204
else throw `The quill editor hasn't been instantiated yet,
@@ -206,6 +214,12 @@ export default defineComponent({
206214
quill?.clipboard.dangerouslyPasteHTML(html)
207215
}
208216

217+
const reinit = () => {
218+
if (!ctx.slots.toolbar && quill)
219+
quill.getModule("toolbar")?.container.remove();
220+
initialize();
221+
}
222+
209223
watch(
210224
() => props.content,
211225
(newContent, oldContent) => {
@@ -222,19 +236,6 @@ export default defineComponent({
222236
}
223237
);
224238

225-
watch(
226-
[
227-
() => props.options,
228-
() => props.theme,
229-
() => props.toolbar
230-
],
231-
() => {
232-
if (!ctx.slots.toolbar && quill)
233-
quill.getModule("toolbar")?.container.remove();
234-
initialize();
235-
}
236-
);
237-
238239
watch(
239240
() => props.enable,
240241
(newValue, oldValue) => {
@@ -244,9 +245,12 @@ export default defineComponent({
244245

245246
return {
246247
editor,
248+
getEditor,
249+
getToolbar,
247250
getQuill,
248251
getHTML,
249252
setHTML,
253+
reinit,
250254
};
251255
},
252256
inheritAttrs: false,

0 commit comments

Comments
 (0)