@vueup/vue-quill 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,385 +1,447 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.2.1
2
+ * VueQuill @vueup/vue-quill v1.4.0
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
- * Includes quill v1.3.7
5
+ * Includes quill v2.0.2 || >=2.0.4 <3
6
6
  * https://quilljs.com/
7
7
  *
8
8
  * Copyright (c) 2026 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2026-06-01T03:41:54.233Z
10
+ * Date: 2026-06-02T00:10:10.011Z
11
11
  */
12
- import Quill from 'quill';
13
- export { default as Quill } from 'quill';
14
12
  import Delta from 'quill-delta';
15
13
  export { default as Delta } from 'quill-delta';
16
- import { defineComponent, onMounted, onBeforeUnmount, ref, watch, nextTick, h } from 'vue';
14
+ import { defineComponent, h, onMounted, onBeforeUnmount, ref, watch, nextTick } from 'vue';
17
15
 
18
- const toolbarOptions = {
19
- essential: [
20
- [{ header: [1, 2, 3, 4, 5, 6, false] }],
21
- ['bold', 'italic', 'underline'],
22
- [{ list: 'ordered' }, { list: 'bullet' }, { align: [] }],
23
- ['blockquote', 'code-block', 'link'],
24
- [{ color: [] }, 'clean'],
25
- ],
26
- minimal: [
27
- [{ header: 1 }, { header: 2 }],
28
- ['bold', 'italic', 'underline'],
29
- [{ list: 'ordered' }, { list: 'bullet' }, { align: [] }],
30
- ],
31
- full: [
32
- ['bold', 'italic', 'underline', 'strike'],
33
- ['blockquote', 'code-block'],
34
- [{ header: 1 }, { header: 2 }],
35
- [{ list: 'ordered' }, { list: 'bullet' }],
36
- [{ script: 'sub' }, { script: 'super' }],
37
- [{ indent: '-1' }, { indent: '+1' }],
38
- [{ direction: 'rtl' }],
39
- [{ size: ['small', false, 'large', 'huge'] }],
40
- [{ header: [1, 2, 3, 4, 5, 6, false] }],
41
- [{ color: [] }, { background: [] }],
42
- [{ font: [] }],
43
- [{ align: [] }],
44
- ['link', 'video', 'image'],
45
- ['clean'], // remove formatting button
46
- ],
16
+ const toolbarOptions = {
17
+ essential: [
18
+ [{ header: [1, 2, 3, 4, 5, 6, false] }],
19
+ ['bold', 'italic', 'underline'],
20
+ [{ list: 'ordered' }, { list: 'bullet' }, { align: [] }],
21
+ ['blockquote', 'code-block', 'link'],
22
+ [{ color: [] }, 'clean'],
23
+ ],
24
+ minimal: [
25
+ [{ header: 1 }, { header: 2 }],
26
+ ['bold', 'italic', 'underline'],
27
+ [{ list: 'ordered' }, { list: 'bullet' }, { align: [] }],
28
+ ],
29
+ full: [
30
+ ['bold', 'italic', 'underline', 'strike'], // toggled buttons
31
+ ['blockquote', 'code-block'],
32
+ [{ header: 1 }, { header: 2 }], // custom button values
33
+ [{ list: 'ordered' }, { list: 'bullet' }],
34
+ [{ script: 'sub' }, { script: 'super' }], // superscript/subscript
35
+ [{ indent: '-1' }, { indent: '+1' }], // outdent/indent
36
+ [{ direction: 'rtl' }], // text direction
37
+ [{ size: ['small', false, 'large', 'huge'] }], // custom dropdown
38
+ [{ header: [1, 2, 3, 4, 5, 6, false] }],
39
+ [{ color: [] }, { background: [] }], // dropdown with defaults from theme
40
+ [{ font: [] }],
41
+ [{ align: [] }],
42
+ ['link', 'video', 'image'],
43
+ ['clean'], // remove formatting button
44
+ ],
47
45
  };
48
46
 
49
- const QuillEditor = defineComponent({
50
- name: 'QuillEditor',
51
- inheritAttrs: false,
52
- props: {
53
- content: {
54
- type: [String, Object],
55
- },
56
- contentType: {
57
- type: String,
58
- default: 'delta',
59
- validator: (value) => {
60
- return ['delta', 'html', 'text'].includes(value);
61
- },
62
- },
63
- enable: {
64
- type: Boolean,
65
- default: true,
66
- },
67
- readOnly: {
68
- type: Boolean,
69
- default: false,
70
- },
71
- placeholder: {
72
- type: String,
73
- required: false,
74
- },
75
- theme: {
76
- type: String,
77
- default: 'snow',
78
- validator: (value) => {
79
- return ['snow', 'bubble', ''].includes(value);
80
- },
81
- },
82
- toolbar: {
83
- type: [String, Array, Object],
84
- required: false,
85
- validator: (value) => {
86
- if (typeof value === 'string' && value !== '') {
87
- return value.charAt(0) === '#'
88
- ? true
89
- : Object.keys(toolbarOptions).indexOf(value) !== -1;
90
- }
91
- return true;
92
- },
93
- },
94
- modules: {
95
- type: Object,
96
- required: false,
97
- },
98
- options: {
99
- type: Object,
100
- required: false,
101
- },
102
- globalOptions: {
103
- type: Object,
104
- required: false,
105
- },
106
- },
107
- emits: [
108
- 'textChange',
109
- 'selectionChange',
110
- 'editorChange',
111
- 'update:content',
112
- 'focus',
113
- 'blur',
114
- 'ready',
115
- ],
116
- setup: (props, ctx) => {
117
- onMounted(() => {
118
- initialize();
119
- });
120
- onBeforeUnmount(() => {
121
- quill = null;
122
- });
123
- let quill;
124
- let options;
125
- const editor = ref();
126
- // Register Module if not already registered
127
- const registerModule = (moduleName, module) => {
128
- const quillImports = Quill.imports;
129
- if (quillImports && moduleName in quillImports) {
130
- return;
131
- }
132
- Quill.register(moduleName, module);
133
- };
134
- // Initialize Quill
135
- const initialize = () => {
136
- var _a;
137
- if (!editor.value)
138
- return;
139
- options = composeOptions();
140
- // Register modules
141
- if (props.modules) {
142
- if (Array.isArray(props.modules)) {
143
- for (const module of props.modules) {
144
- registerModule(`modules/${module.name}`, module.module);
145
- }
146
- }
147
- else {
148
- registerModule(`modules/${props.modules.name}`, props.modules.module);
149
- }
150
- }
151
- // Create new Quill instance
152
- quill = new Quill(editor.value, options);
153
- // Set editor content
154
- setContents(props.content);
155
- // Set event handlers
156
- quill.on('text-change', handleTextChange);
157
- quill.on('selection-change', handleSelectionChange);
158
- quill.on('editor-change', handleEditorChange);
159
- // Remove editor class when theme changes
160
- if (props.theme !== 'bubble')
161
- editor.value.classList.remove('ql-bubble');
162
- if (props.theme !== 'snow')
163
- editor.value.classList.remove('ql-snow');
164
- // Fix clicking the quill toolbar is detected as blur event
165
- (_a = quill
166
- .getModule('toolbar')) === null || _a === void 0 ? void 0 : _a.container.addEventListener('mousedown', (e) => {
167
- e.preventDefault();
168
- });
169
- // Emit ready event
170
- ctx.emit('ready', quill);
171
- };
172
- // Compose Options
173
- const composeOptions = () => {
174
- const clientOptions = {};
175
- if (props.theme !== '')
176
- clientOptions.theme = props.theme;
177
- if (props.readOnly)
178
- clientOptions.readOnly = props.readOnly;
179
- if (props.placeholder)
180
- clientOptions.placeholder = props.placeholder;
181
- if (props.toolbar && props.toolbar !== '') {
182
- clientOptions.modules = {
183
- toolbar: (() => {
184
- if (typeof props.toolbar === 'object') {
185
- return props.toolbar;
186
- }
187
- else if (typeof props.toolbar === 'string') {
188
- const str = props.toolbar;
189
- return str.charAt(0) === '#'
190
- ? props.toolbar
191
- : toolbarOptions[props.toolbar];
192
- }
193
- return;
194
- })(),
195
- };
196
- }
197
- if (props.modules) {
198
- const modules = (() => {
199
- var _a, _b;
200
- const modulesOption = {};
201
- if (Array.isArray(props.modules)) {
202
- for (const module of props.modules) {
203
- modulesOption[module.name] = (_a = module.options) !== null && _a !== void 0 ? _a : {};
204
- }
205
- }
206
- else {
207
- modulesOption[props.modules.name] = (_b = props.modules.options) !== null && _b !== void 0 ? _b : {};
208
- }
209
- return modulesOption;
210
- })();
211
- clientOptions.modules = Object.assign({}, clientOptions.modules, modules);
212
- }
213
- return Object.assign({}, props.globalOptions, props.options, clientOptions);
214
- };
215
- const maybeClone = (delta) => {
216
- return typeof delta === 'object' && delta ? delta.slice() : delta;
217
- };
218
- const deltaHasValuesOtherThanRetain = (delta) => {
219
- return Object.values(delta.ops).some((v) => !v.retain || Object.keys(v).length !== 1);
220
- };
221
- // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
222
- let internalModel;
223
- const internalModelEquals = (against) => {
224
- if (typeof internalModel === typeof against) {
225
- if (against === internalModel) {
226
- return true;
227
- }
228
- // Ref/Proxy does not support instanceof, so do a loose check
229
- if (typeof against === 'object' &&
230
- against &&
231
- typeof internalModel === 'object' &&
232
- internalModel) {
233
- return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
234
- }
235
- }
236
- return false;
237
- };
238
- const handleTextChange = (delta, oldContents, source) => {
239
- internalModel = maybeClone(getContents());
240
- // Update v-model:content when text changes
241
- if (!internalModelEquals(props.content)) {
242
- ctx.emit('update:content', internalModel);
243
- }
244
- ctx.emit('textChange', { delta, oldContents, source });
245
- };
246
- const isEditorFocus = ref();
247
- const handleSelectionChange = (range, oldRange, source) => {
248
- // Set isEditorFocus if quill.hasFocus()
249
- isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus());
250
- ctx.emit('selectionChange', { range, oldRange, source });
251
- };
252
- watch(isEditorFocus, (focus) => {
253
- if (focus)
254
- ctx.emit('focus', editor);
255
- else
256
- ctx.emit('blur', editor);
257
- });
258
- const handleEditorChange = (...args) => {
259
- if (args[0] === 'text-change')
260
- ctx.emit('editorChange', {
261
- name: args[0],
262
- delta: args[1],
263
- oldContents: args[2],
264
- source: args[3],
265
- });
266
- if (args[0] === 'selection-change')
267
- ctx.emit('editorChange', {
268
- name: args[0],
269
- range: args[1],
270
- oldRange: args[2],
271
- source: args[3],
272
- });
273
- };
274
- const getEditor = () => {
275
- return editor.value;
276
- };
277
- const getToolbar = () => {
278
- var _a;
279
- return (_a = quill === null || quill === void 0 ? void 0 : quill.getModule('toolbar')) === null || _a === void 0 ? void 0 : _a.container;
280
- };
281
- const getQuill = () => {
282
- if (quill)
283
- return quill;
284
- else
47
+ let loadedQuill;
48
+ let quillLoadPromise;
49
+ let pendingRegistrations = [];
50
+ const isBrowser = () => typeof document !== 'undefined';
51
+ const replayPendingRegistrations = (Quill) => {
52
+ const registrations = pendingRegistrations;
53
+ pendingRegistrations = [];
54
+ for (const args of registrations) {
55
+ Quill.register(...args);
56
+ }
57
+ };
58
+ const loadQuill = async () => {
59
+ if (loadedQuill)
60
+ return loadedQuill;
61
+ if (!isBrowser()) {
62
+ throw new Error('@vueup/vue-quill: Quill can only be loaded in a browser environment.');
63
+ }
64
+ quillLoadPromise !== null && quillLoadPromise !== void 0 ? quillLoadPromise : (quillLoadPromise = import('quill').then(({ default: Quill }) => {
65
+ loadedQuill = Quill;
66
+ replayPendingRegistrations(Quill);
67
+ return Quill;
68
+ }));
69
+ return quillLoadPromise;
70
+ };
71
+ const getLoadedQuill = () => loadedQuill;
72
+ const getQuillOrThrow = () => {
73
+ if (loadedQuill)
74
+ return loadedQuill;
75
+ throw new Error('@vueup/vue-quill: Quill is not loaded yet. Use loadQuill() in a browser-only lifecycle hook, or access the Quill instance from the ready event.');
76
+ };
77
+ const Quill = new Proxy(function QuillProxy() { }, {
78
+ get(_target, property) {
79
+ if (property === 'register') {
80
+ return (...args) => {
81
+ if (loadedQuill) {
82
+ return loadedQuill.register(...args);
83
+ }
84
+ pendingRegistrations.push(args);
85
+ if (isBrowser())
86
+ void loadQuill();
87
+ };
88
+ }
89
+ const Quill = getQuillOrThrow();
90
+ const value = Quill[property];
91
+ return typeof value === 'function' ? value.bind(Quill) : value;
92
+ },
93
+ construct(_target, args) {
94
+ const Quill = getQuillOrThrow();
95
+ return new Quill(...args);
96
+ },
97
+ });
98
+
99
+ const QuillEditor = defineComponent({
100
+ name: 'QuillEditor',
101
+ inheritAttrs: false,
102
+ props: {
103
+ content: {
104
+ type: [String, Object],
105
+ },
106
+ contentType: {
107
+ type: String,
108
+ default: 'delta',
109
+ validator: (value) => {
110
+ return ['delta', 'html', 'text'].includes(value);
111
+ },
112
+ },
113
+ enable: {
114
+ type: Boolean,
115
+ default: true,
116
+ },
117
+ readOnly: {
118
+ type: Boolean,
119
+ default: false,
120
+ },
121
+ placeholder: {
122
+ type: String,
123
+ required: false,
124
+ },
125
+ theme: {
126
+ type: String,
127
+ default: 'snow',
128
+ validator: (value) => {
129
+ return ['snow', 'bubble', ''].includes(value);
130
+ },
131
+ },
132
+ toolbar: {
133
+ type: [String, Array, Object],
134
+ required: false,
135
+ validator: (value) => {
136
+ if (typeof value === 'string' && value !== '') {
137
+ return value.charAt(0) === '#'
138
+ ? true
139
+ : Object.keys(toolbarOptions).indexOf(value) !== -1;
140
+ }
141
+ return true;
142
+ },
143
+ },
144
+ modules: {
145
+ type: Object,
146
+ required: false,
147
+ },
148
+ options: {
149
+ type: Object,
150
+ required: false,
151
+ },
152
+ globalOptions: {
153
+ type: Object,
154
+ required: false,
155
+ },
156
+ },
157
+ emits: [
158
+ 'textChange',
159
+ 'selectionChange',
160
+ 'editorChange',
161
+ 'update:content',
162
+ 'focus',
163
+ 'blur',
164
+ 'ready',
165
+ ],
166
+ setup: (props, ctx) => {
167
+ onMounted(() => {
168
+ isUnmounted = false;
169
+ void initialize();
170
+ });
171
+ onBeforeUnmount(() => {
172
+ quill = null;
173
+ isUnmounted = true;
174
+ });
175
+ let isUnmounted = false;
176
+ let quill;
177
+ let options;
178
+ const editor = ref();
179
+ // Register Module if not already registered
180
+ const registerModule = (Quill, moduleName, module) => {
181
+ const quillImports = Quill.imports;
182
+ if (quillImports && moduleName in quillImports) {
183
+ return;
184
+ }
185
+ Quill.register(moduleName, module);
186
+ };
187
+ // Initialize Quill
188
+ const initialize = async () => {
189
+ var _a, _b;
190
+ if (!editor.value)
191
+ return;
192
+ const editorElement = editor.value;
193
+ const Quill = await loadQuill();
194
+ if (isUnmounted || !editor.value || editor.value !== editorElement)
195
+ return;
196
+ options = composeOptions();
197
+ // Register modules
198
+ if (props.modules) {
199
+ if (Array.isArray(props.modules)) {
200
+ for (const module of props.modules) {
201
+ registerModule(Quill, `modules/${module.name}`, module.module);
202
+ }
203
+ }
204
+ else {
205
+ registerModule(Quill, `modules/${props.modules.name}`, props.modules.module);
206
+ }
207
+ }
208
+ // Create new Quill instance
209
+ quill = new Quill(editor.value, options);
210
+ // Set editor content
211
+ setContents(props.content);
212
+ // Set event handlers
213
+ quill.on('text-change', handleTextChange);
214
+ quill.on('selection-change', handleSelectionChange);
215
+ quill.on('editor-change', handleEditorChange);
216
+ // Remove editor class when theme changes
217
+ if (props.theme !== 'bubble')
218
+ editor.value.classList.remove('ql-bubble');
219
+ if (props.theme !== 'snow')
220
+ editor.value.classList.remove('ql-snow');
221
+ // Fix clicking the quill toolbar is detected as blur event
222
+ (_b = (_a = getToolbarModule()) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.addEventListener('mousedown', (e) => {
223
+ e.preventDefault();
224
+ });
225
+ // Emit ready event
226
+ ctx.emit('ready', quill);
227
+ };
228
+ // Compose Options
229
+ const composeOptions = () => {
230
+ const clientOptions = {};
231
+ if (props.theme !== '')
232
+ clientOptions.theme = props.theme;
233
+ if (props.readOnly)
234
+ clientOptions.readOnly = props.readOnly;
235
+ if (props.placeholder)
236
+ clientOptions.placeholder = props.placeholder;
237
+ if (props.toolbar && props.toolbar !== '') {
238
+ clientOptions.modules = {
239
+ toolbar: (() => {
240
+ if (typeof props.toolbar === 'object') {
241
+ return props.toolbar;
242
+ }
243
+ else if (typeof props.toolbar === 'string') {
244
+ const str = props.toolbar;
245
+ return str.charAt(0) === '#'
246
+ ? props.toolbar
247
+ : toolbarOptions[props.toolbar];
248
+ }
249
+ return;
250
+ })(),
251
+ };
252
+ }
253
+ if (props.modules) {
254
+ const modules = (() => {
255
+ var _a, _b;
256
+ const modulesOption = {};
257
+ if (Array.isArray(props.modules)) {
258
+ for (const module of props.modules) {
259
+ modulesOption[module.name] = (_a = module.options) !== null && _a !== void 0 ? _a : {};
260
+ }
261
+ }
262
+ else {
263
+ modulesOption[props.modules.name] = (_b = props.modules.options) !== null && _b !== void 0 ? _b : {};
264
+ }
265
+ return modulesOption;
266
+ })();
267
+ clientOptions.modules = Object.assign({}, clientOptions.modules, modules);
268
+ }
269
+ return Object.assign({}, props.globalOptions, props.options, clientOptions);
270
+ };
271
+ const maybeClone = (delta) => {
272
+ return typeof delta === 'object' && delta ? delta.slice() : delta;
273
+ };
274
+ const getToolbarModule = () => {
275
+ return quill === null || quill === void 0 ? void 0 : quill.getModule('toolbar');
276
+ };
277
+ const deltaHasValuesOtherThanRetain = (delta) => {
278
+ return Object.values(delta.ops).some((v) => !v.retain || Object.keys(v).length !== 1);
279
+ };
280
+ // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
281
+ let internalModel;
282
+ const internalModelEquals = (against) => {
283
+ if (typeof internalModel === typeof against) {
284
+ if (against === internalModel) {
285
+ return true;
286
+ }
287
+ // Ref/Proxy does not support instanceof, so do a loose check
288
+ if (typeof against === 'object' &&
289
+ against &&
290
+ typeof internalModel === 'object' &&
291
+ internalModel) {
292
+ return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
293
+ }
294
+ }
295
+ return false;
296
+ };
297
+ const handleTextChange = (delta, oldContents, source) => {
298
+ internalModel = maybeClone(getContents());
299
+ // Update v-model:content when text changes
300
+ if (!internalModelEquals(props.content)) {
301
+ ctx.emit('update:content', internalModel);
302
+ }
303
+ ctx.emit('textChange', { delta, oldContents, source });
304
+ };
305
+ const isEditorFocus = ref();
306
+ const handleSelectionChange = (range, oldRange, source) => {
307
+ // Set isEditorFocus if quill.hasFocus()
308
+ isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus());
309
+ ctx.emit('selectionChange', { range, oldRange, source });
310
+ };
311
+ watch(isEditorFocus, (focus) => {
312
+ // Focus and blur events document the editor ref as their payload.
313
+ // eslint-disable-next-line vue/no-ref-as-operand
314
+ if (focus)
315
+ ctx.emit('focus', editor);
316
+ // eslint-disable-next-line vue/no-ref-as-operand
317
+ else
318
+ ctx.emit('blur', editor);
319
+ });
320
+ const handleEditorChange = (...args) => {
321
+ if (args[0] === 'text-change')
322
+ ctx.emit('editorChange', {
323
+ name: args[0],
324
+ delta: args[1],
325
+ oldContents: args[2],
326
+ source: args[3],
327
+ });
328
+ if (args[0] === 'selection-change')
329
+ ctx.emit('editorChange', {
330
+ name: args[0],
331
+ range: args[1],
332
+ oldRange: args[2],
333
+ source: args[3],
334
+ });
335
+ };
336
+ const getEditor = () => {
337
+ return editor.value;
338
+ };
339
+ const getToolbar = () => {
340
+ var _a;
341
+ return (_a = getToolbarModule()) === null || _a === void 0 ? void 0 : _a.container;
342
+ };
343
+ const getQuill = () => {
344
+ if (quill)
345
+ return quill;
346
+ else
285
347
  throw `The quill editor hasn't been instantiated yet,
286
348
  make sure to call this method when the editor ready
287
- or use v-on:ready="onReady(quill)" event instead.`;
288
- };
289
- const getContents = (index, length) => {
290
- if (props.contentType === 'html') {
291
- return getHTML();
292
- }
293
- else if (props.contentType === 'text') {
294
- return getText(index, length);
295
- }
296
- return quill === null || quill === void 0 ? void 0 : quill.getContents(index, length);
297
- };
298
- const setContents = (content, source = 'api') => {
299
- const normalizedContent = !content
300
- ? props.contentType === 'delta'
301
- ? new Delta()
302
- : ''
303
- : content;
304
- if (props.contentType === 'html') {
305
- setHTML(normalizedContent);
306
- }
307
- else if (props.contentType === 'text') {
308
- setText(normalizedContent, source);
309
- }
310
- else {
311
- quill === null || quill === void 0 ? void 0 : quill.setContents(normalizedContent, source);
312
- }
313
- internalModel = maybeClone(normalizedContent);
314
- };
315
- const getText = (index, length) => {
316
- var _a;
317
- return (_a = quill === null || quill === void 0 ? void 0 : quill.getText(index, length)) !== null && _a !== void 0 ? _a : '';
318
- };
319
- const setText = (text, source = 'api') => {
320
- quill === null || quill === void 0 ? void 0 : quill.setText(text, source);
321
- };
322
- const getHTML = () => {
323
- var _a;
324
- return (_a = quill === null || quill === void 0 ? void 0 : quill.root.innerHTML) !== null && _a !== void 0 ? _a : '';
325
- };
326
- const setHTML = (html) => {
327
- if (quill)
328
- quill.root.innerHTML = html;
329
- };
330
- const pasteHTML = (html, source = 'api') => {
331
- const delta = quill === null || quill === void 0 ? void 0 : quill.clipboard.convert(html);
332
- if (delta)
333
- quill === null || quill === void 0 ? void 0 : quill.setContents(delta, source);
334
- };
335
- const focus = () => {
336
- quill === null || quill === void 0 ? void 0 : quill.focus();
337
- };
338
- const reinit = () => {
339
- nextTick(() => {
340
- var _a;
341
- if (!ctx.slots.toolbar && quill)
342
- (_a = quill.getModule('toolbar')) === null || _a === void 0 ? void 0 : _a.container.remove();
343
- initialize();
344
- });
345
- };
346
- watch(() => props.content, (newContent) => {
347
- if (!quill || !newContent || internalModelEquals(newContent))
348
- return;
349
- // Restore the selection and cursor position after updating the content
350
- const selection = quill.getSelection();
351
- if (selection) {
352
- nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection));
353
- }
354
- setContents(newContent);
355
- }, { deep: true });
356
- watch(() => props.enable, (newValue) => {
357
- if (quill)
358
- quill.enable(newValue);
359
- });
360
- return {
361
- editor,
362
- getEditor,
363
- getToolbar,
364
- getQuill,
365
- getContents,
366
- setContents,
367
- getHTML,
368
- setHTML,
369
- pasteHTML,
370
- focus,
371
- getText,
372
- setText,
373
- reinit,
374
- };
375
- },
376
- render() {
377
- var _a, _b;
378
- return [
379
- (_b = (_a = this.$slots).toolbar) === null || _b === void 0 ? void 0 : _b.call(_a),
380
- h('div', { ref: 'editor', ...this.$attrs }),
381
- ];
382
- },
349
+ or use v-on:ready="onReady(quill)" event instead.`;
350
+ };
351
+ const getContents = (index, length) => {
352
+ if (props.contentType === 'html') {
353
+ return getHTML();
354
+ }
355
+ else if (props.contentType === 'text') {
356
+ return getText(index, length);
357
+ }
358
+ return quill === null || quill === void 0 ? void 0 : quill.getContents(index, length);
359
+ };
360
+ const setContents = (content, source = 'api') => {
361
+ const normalizedContent = !content
362
+ ? props.contentType === 'delta'
363
+ ? new Delta()
364
+ : ''
365
+ : content;
366
+ if (props.contentType === 'html') {
367
+ setHTML(normalizedContent);
368
+ }
369
+ else if (props.contentType === 'text') {
370
+ setText(normalizedContent, source);
371
+ }
372
+ else {
373
+ quill === null || quill === void 0 ? void 0 : quill.setContents(normalizedContent, source);
374
+ }
375
+ internalModel = maybeClone(normalizedContent);
376
+ };
377
+ const getText = (index, length) => {
378
+ var _a;
379
+ return (_a = quill === null || quill === void 0 ? void 0 : quill.getText(index, length)) !== null && _a !== void 0 ? _a : '';
380
+ };
381
+ const setText = (text, source = 'api') => {
382
+ quill === null || quill === void 0 ? void 0 : quill.setText(text, source);
383
+ };
384
+ const getHTML = () => {
385
+ var _a;
386
+ return (_a = quill === null || quill === void 0 ? void 0 : quill.root.innerHTML) !== null && _a !== void 0 ? _a : '';
387
+ };
388
+ const setHTML = (html) => {
389
+ if (quill)
390
+ quill.root.innerHTML = html;
391
+ };
392
+ const pasteHTML = (html, source = 'api') => {
393
+ const delta = quill === null || quill === void 0 ? void 0 : quill.clipboard.convert({ html });
394
+ if (delta)
395
+ quill === null || quill === void 0 ? void 0 : quill.setContents(delta, source);
396
+ };
397
+ const focus = () => {
398
+ quill === null || quill === void 0 ? void 0 : quill.focus();
399
+ };
400
+ const reinit = () => {
401
+ nextTick(() => {
402
+ var _a, _b;
403
+ if (!ctx.slots.toolbar && quill)
404
+ (_b = (_a = getToolbarModule()) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.remove();
405
+ void initialize();
406
+ });
407
+ };
408
+ watch(() => props.content, (newContent) => {
409
+ if (!quill || !newContent || internalModelEquals(newContent))
410
+ return;
411
+ // Restore the selection and cursor position after updating the content
412
+ const selection = quill.getSelection();
413
+ if (selection) {
414
+ nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection));
415
+ }
416
+ setContents(newContent);
417
+ }, { deep: true });
418
+ watch(() => props.enable, (newValue) => {
419
+ if (quill)
420
+ quill.enable(newValue);
421
+ });
422
+ return {
423
+ editor,
424
+ getEditor,
425
+ getToolbar,
426
+ getQuill,
427
+ getContents,
428
+ setContents,
429
+ getHTML,
430
+ setHTML,
431
+ pasteHTML,
432
+ focus,
433
+ getText,
434
+ setText,
435
+ reinit,
436
+ };
437
+ },
438
+ render() {
439
+ var _a, _b;
440
+ return [
441
+ (_b = (_a = this.$slots).toolbar) === null || _b === void 0 ? void 0 : _b.call(_a),
442
+ h('div', { ref: 'editor', ...this.$attrs }),
443
+ ];
444
+ },
383
445
  });
384
446
 
385
- export { QuillEditor };
447
+ export { Quill, QuillEditor, getLoadedQuill, loadQuill };