Skip to content

Commit c1836eb

Browse files
committed
fix: named the events arguments
1 parent 3b792c3 commit c1836eb

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/components/QuillEditor.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import {
33
SelectionChangeHandler,
44
EditorChangeHandler,
55
QuillOptionsStatic,
6+
RangeStatic,
7+
Sources,
68
} from "quill";
79
import { Quill } from "../main"
8-
import { Delta } from "types-quill-delta";
10+
import Delta from "quill-delta";
911
import {
1012
defineComponent,
1113
onBeforeUnmount,
@@ -140,26 +142,46 @@ export default defineComponent({
140142
);
141143
}
142144

143-
const handleTextChange: TextChangeHandler = (...args) => {
145+
const handleTextChange: TextChangeHandler = (delta: Delta, oldContents: Delta, source: Sources) => {
144146
// Update v-model:content when text changes
145147
ctx.emit("update:content", quill?.getContents());
146-
ctx.emit("textChange", { ...args });
148+
ctx.emit("textChange", { delta, oldContents, source });
147149
};
148150

149151
const isEditorFocus = ref<boolean>()
150-
const handleSelectionChange: SelectionChangeHandler = (...args) => {
152+
const handleSelectionChange: SelectionChangeHandler = (range: RangeStatic, oldRange: RangeStatic, source: Sources) => {
151153
// Mark model as touched if editor lost focus
152154
isEditorFocus.value = quill?.hasFocus() ? true : false
153-
ctx.emit("selectionChange", { ...args });
155+
ctx.emit("selectionChange", { range, oldRange, source });
154156
};
155157

156158
watch(isEditorFocus, (focus) => {
157159
if (focus) ctx.emit("focus", editor)
158160
else ctx.emit("blur", editor);
159161
})
160162

161-
const handleEditorChange: EditorChangeHandler = (...args) => {
162-
ctx.emit("editorChange", { ...args });
163+
const handleEditorChange: EditorChangeHandler = (name: "text-change" | "selection-change", ...args) => {
164+
if (name === "text-change") {
165+
ctx.emit(
166+
"editorChange",
167+
{
168+
name,
169+
delta: args[0] as Delta,
170+
oldContents: args[1] as Delta,
171+
source: args[2] as Sources
172+
}
173+
);
174+
} else if (name === "selection-change") {
175+
ctx.emit(
176+
"editorChange",
177+
{
178+
name,
179+
range: args[0] as RangeStatic,
180+
oldRange: args[1] as RangeStatic,
181+
source: args[2] as Sources
182+
}
183+
);
184+
}
163185
};
164186

165187
const getQuill = (): Quill => {

0 commit comments

Comments
 (0)