@vueup/vue-quill 1.0.0 → 1.1.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,13 +1,13 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0
2
+ * VueQuill @vueup/vue-quill v1.1.0
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
6
6
  * https://quilljs.com/
7
7
  *
8
- * Copyright (c) 2022 Ahmad Luthfi Masruri
8
+ * Copyright (c) 2023 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-10-21T15:47:50.853Z
10
+ * Date: 2023-02-04T04:01:16.430Z
11
11
  */
12
12
  'use strict';
13
13
 
@@ -212,15 +212,38 @@ const QuillEditor = vue.defineComponent({
212
212
  }
213
213
  return Object.assign({}, props.globalOptions, props.options, clientOptions);
214
214
  };
215
+ const maybeClone = (delta) => {
216
+ return typeof delta === 'object' ? 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' && typeof internalModel === 'object') {
230
+ return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
231
+ }
232
+ }
233
+ return false;
234
+ };
215
235
  const handleTextChange = (delta, oldContents, source) => {
236
+ internalModel = maybeClone(getContents());
216
237
  // Update v-model:content when text changes
217
- ctx.emit('update:content', getContents());
238
+ if (!internalModelEquals(props.content)) {
239
+ ctx.emit('update:content', internalModel);
240
+ }
218
241
  ctx.emit('textChange', { delta, oldContents, source });
219
242
  };
220
243
  const isEditorFocus = vue.ref();
221
244
  const handleSelectionChange = (range, oldRange, source) => {
222
245
  // Set isEditorFocus if quill.hasFocus()
223
- isEditorFocus.value = (quill === null || quill === void 0 ? void 0 : quill.hasFocus()) ? true : false;
246
+ isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus());
224
247
  ctx.emit('selectionChange', { range, oldRange, source });
225
248
  };
226
249
  vue.watch(isEditorFocus, (focus) => {
@@ -279,6 +302,7 @@ const QuillEditor = vue.defineComponent({
279
302
  else {
280
303
  quill === null || quill === void 0 ? void 0 : quill.setContents(content, source);
281
304
  }
305
+ internalModel = maybeClone(content);
282
306
  };
283
307
  const getText = (index, length) => {
284
308
  var _a;
@@ -308,13 +332,16 @@ const QuillEditor = vue.defineComponent({
308
332
  initialize();
309
333
  });
310
334
  };
311
- // watch(
312
- // () => props.content,
313
- // (newContent, oldContents) => {
314
- // if (!quill || !newContent || newContent === oldContents) return
315
- // setContents(newContent)
316
- // }
317
- // )
335
+ vue.watch(() => props.content, (newContent) => {
336
+ if (!quill || !newContent || internalModelEquals(newContent))
337
+ return;
338
+ // Restore the selection and cursor position after updating the content
339
+ const selection = quill.getSelection();
340
+ if (selection) {
341
+ vue.nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection));
342
+ }
343
+ setContents(newContent);
344
+ }, { deep: true });
318
345
  vue.watch(() => props.enable, (newValue) => {
319
346
  if (quill)
320
347
  quill.enable(newValue);
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0
2
+ * VueQuill @vueup/vue-quill v1.1.0
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
6
6
  * https://quilljs.com/
7
7
  *
8
- * Copyright (c) 2022 Ahmad Luthfi Masruri
8
+ * Copyright (c) 2023 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-10-21T15:47:50.853Z
10
+ * Date: 2023-02-04T04:01:16.430Z
11
11
  */
12
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("quill"),t=require("quill-delta"),o=require("vue");function l(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=l(e),r=l(t);const i={essential:[[{header:[1,2,3,4,5,6,!1]}],["bold","italic","underline"],[{list:"ordered"},{list:"bullet"},{align:[]}],["blockquote","code-block","link"],[{color:[]},"clean"]],minimal:[[{header:1},{header:2}],["bold","italic","underline"],[{list:"ordered"},{list:"bullet"},{align:[]}]],full:[["bold","italic","underline","strike"],["blockquote","code-block"],[{header:1},{header:2}],[{list:"ordered"},{list:"bullet"}],[{script:"sub"},{script:"super"}],[{indent:"-1"},{indent:"+1"}],[{direction:"rtl"}],[{size:["small",!1,"large","huge"]}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{font:[]}],[{align:[]}],["link","video","image"],["clean"]]},a=o.defineComponent({name:"QuillEditor",inheritAttrs:!1,props:{content:{type:[String,Object],default:()=>{}},contentType:{type:String,default:"delta",validator:e=>["delta","html","text"].includes(e)},enable:{type:Boolean,default:!0},readOnly:{type:Boolean,default:!1},placeholder:{type:String,required:!1},theme:{type:String,default:"snow",validator:e=>["snow","bubble",""].includes(e)},toolbar:{type:[String,Array,Object],required:!1,validator:e=>"string"!=typeof e||""===e||("#"===e.charAt(0)||-1!==Object.keys(i).indexOf(e))},modules:{type:Object,required:!1},options:{type:Object,required:!1},globalOptions:{type:Object,required:!1}},emits:["textChange","selectionChange","editorChange","update:content","focus","blur","ready"],setup:(e,t)=>{let l,r;o.onMounted((()=>{d()})),o.onBeforeUnmount((()=>{l=null}));const a=o.ref(),d=()=>{var o;if(a.value){if(r=s(),e.modules)if(Array.isArray(e.modules))for(const t of e.modules)n.register(`modules/${t.name}`,t.module);else n.register(`modules/${e.modules.name}`,e.modules.module);l=new n(a.value,r),h(e.content),l.on("text-change",u),l.on("selection-change",b),l.on("editor-change",m),"bubble"!==e.theme&&a.value.classList.remove("ql-bubble"),"snow"!==e.theme&&a.value.classList.remove("ql-snow"),null===(o=l.getModule("toolbar"))||void 0===o||o.container.addEventListener("mousedown",(e=>{e.preventDefault()})),t.emit("ready",l)}},s=()=>{const t={};if(""!==e.theme&&(t.theme=e.theme),e.readOnly&&(t.readOnly=e.readOnly),e.placeholder&&(t.placeholder=e.placeholder),e.toolbar&&""!==e.toolbar&&(t.modules={toolbar:(()=>{if("object"==typeof e.toolbar)return e.toolbar;if("string"==typeof e.toolbar){return"#"===e.toolbar.charAt(0)?e.toolbar:i[e.toolbar]}})()}),e.modules){const o=(()=>{var t,o;const l={};if(Array.isArray(e.modules))for(const n of e.modules)l[n.name]=null!==(t=n.options)&&void 0!==t?t:{};else l[e.modules.name]=null!==(o=e.modules.options)&&void 0!==o?o:{};return l})();t.modules=Object.assign({},t.modules,o)}return Object.assign({},e.globalOptions,e.options,t)},u=(e,o,l)=>{t.emit("update:content",p()),t.emit("textChange",{delta:e,oldContents:o,source:l})},c=o.ref(),b=(e,o,n)=>{c.value=!!(null==l?void 0:l.hasFocus()),t.emit("selectionChange",{range:e,oldRange:o,source:n})};o.watch(c,(e=>{t.emit(e?"focus":"blur",a)}));const m=(...e)=>{"text-change"===e[0]&&t.emit("editorChange",{name:e[0],delta:e[1],oldContents:e[2],source:e[3]}),"selection-change"===e[0]&&t.emit("editorChange",{name:e[0],range:e[1],oldRange:e[2],source:e[3]})},p=(t,o)=>"html"===e.contentType?f():"text"===e.contentType?g(t,o):null==l?void 0:l.getContents(t,o),h=(t,o="api")=>{"html"===e.contentType?y(t):"text"===e.contentType?v(t,o):null==l||l.setContents(t,o)},g=(e,t)=>{var o;return null!==(o=null==l?void 0:l.getText(e,t))&&void 0!==o?o:""},v=(e,t="api")=>{null==l||l.setText(e,t)},f=()=>{var e;return null!==(e=null==l?void 0:l.root.innerHTML)&&void 0!==e?e:""},y=e=>{l&&(l.root.innerHTML=e)};return o.watch((()=>e.enable),(e=>{l&&l.enable(e)})),{editor:a,getEditor:()=>a.value,getToolbar:()=>{var e;return null===(e=null==l?void 0:l.getModule("toolbar"))||void 0===e?void 0:e.container},getQuill:()=>{if(l)return l;throw'The quill editor hasn\'t been instantiated yet, \n make sure to call this method when the editor ready\n or use v-on:ready="onReady(quill)" event instead.'},getContents:p,setContents:h,getHTML:f,setHTML:y,pasteHTML:(e,t="api")=>{const o=null==l?void 0:l.clipboard.convert(e);o&&(null==l||l.setContents(o,t))},getText:g,setText:v,reinit:()=>{o.nextTick((()=>{var e;!t.slots.toolbar&&l&&(null===(e=l.getModule("toolbar"))||void 0===e||e.container.remove()),d()}))}}},render(){var e,t;return[null===(t=(e=this.$slots).toolbar)||void 0===t?void 0:t.call(e),o.h("div",{ref:"editor",...this.$attrs})]}});exports.Quill=n,exports.Delta=r,exports.QuillEditor=a;
12
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("quill"),t=require("quill-delta"),o=require("vue");function l(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=l(e),r=l(t);const i={essential:[[{header:[1,2,3,4,5,6,!1]}],["bold","italic","underline"],[{list:"ordered"},{list:"bullet"},{align:[]}],["blockquote","code-block","link"],[{color:[]},"clean"]],minimal:[[{header:1},{header:2}],["bold","italic","underline"],[{list:"ordered"},{list:"bullet"},{align:[]}]],full:[["bold","italic","underline","strike"],["blockquote","code-block"],[{header:1},{header:2}],[{list:"ordered"},{list:"bullet"}],[{script:"sub"},{script:"super"}],[{indent:"-1"},{indent:"+1"}],[{direction:"rtl"}],[{size:["small",!1,"large","huge"]}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{font:[]}],[{align:[]}],["link","video","image"],["clean"]]},a=o.defineComponent({name:"QuillEditor",inheritAttrs:!1,props:{content:{type:[String,Object],default:()=>{}},contentType:{type:String,default:"delta",validator:e=>["delta","html","text"].includes(e)},enable:{type:Boolean,default:!0},readOnly:{type:Boolean,default:!1},placeholder:{type:String,required:!1},theme:{type:String,default:"snow",validator:e=>["snow","bubble",""].includes(e)},toolbar:{type:[String,Array,Object],required:!1,validator:e=>"string"!=typeof e||""===e||("#"===e.charAt(0)||-1!==Object.keys(i).indexOf(e))},modules:{type:Object,required:!1},options:{type:Object,required:!1},globalOptions:{type:Object,required:!1}},emits:["textChange","selectionChange","editorChange","update:content","focus","blur","ready"],setup:(e,t)=>{let l,r;o.onMounted((()=>{d()})),o.onBeforeUnmount((()=>{l=null}));const a=o.ref(),d=()=>{var o;if(a.value){if(r=s(),e.modules)if(Array.isArray(e.modules))for(const t of e.modules)n.register(`modules/${t.name}`,t.module);else n.register(`modules/${e.modules.name}`,e.modules.module);l=new n(a.value,r),f(e.content),l.on("text-change",p),l.on("selection-change",h),l.on("editor-change",g),"bubble"!==e.theme&&a.value.classList.remove("ql-bubble"),"snow"!==e.theme&&a.value.classList.remove("ql-snow"),null===(o=l.getModule("toolbar"))||void 0===o||o.container.addEventListener("mousedown",(e=>{e.preventDefault()})),t.emit("ready",l)}},s=()=>{const t={};if(""!==e.theme&&(t.theme=e.theme),e.readOnly&&(t.readOnly=e.readOnly),e.placeholder&&(t.placeholder=e.placeholder),e.toolbar&&""!==e.toolbar&&(t.modules={toolbar:(()=>{if("object"==typeof e.toolbar)return e.toolbar;if("string"==typeof e.toolbar){return"#"===e.toolbar.charAt(0)?e.toolbar:i[e.toolbar]}})()}),e.modules){const o=(()=>{var t,o;const l={};if(Array.isArray(e.modules))for(const n of e.modules)l[n.name]=null!==(t=n.options)&&void 0!==t?t:{};else l[e.modules.name]=null!==(o=e.modules.options)&&void 0!==o?o:{};return l})();t.modules=Object.assign({},t.modules,o)}return Object.assign({},e.globalOptions,e.options,t)},u=e=>"object"==typeof e?e.slice():e;let c;const b=e=>{if(typeof c==typeof e){if(e===c)return!0;if("object"==typeof e&&"object"==typeof c)return t=c.diff(e),!Object.values(t.ops).some((e=>!e.retain||1!==Object.keys(e).length))}var t;return!1},p=(o,l,n)=>{c=u(v()),b(e.content)||t.emit("update:content",c),t.emit("textChange",{delta:o,oldContents:l,source:n})},m=o.ref(),h=(e,o,n)=>{m.value=!!(null==l?void 0:l.hasFocus()),t.emit("selectionChange",{range:e,oldRange:o,source:n})};o.watch(m,(e=>{t.emit(e?"focus":"blur",a)}));const g=(...e)=>{"text-change"===e[0]&&t.emit("editorChange",{name:e[0],delta:e[1],oldContents:e[2],source:e[3]}),"selection-change"===e[0]&&t.emit("editorChange",{name:e[0],range:e[1],oldRange:e[2],source:e[3]})},v=(t,o)=>"html"===e.contentType?O():"text"===e.contentType?y(t,o):null==l?void 0:l.getContents(t,o),f=(t,o="api")=>{"html"===e.contentType?T(t):"text"===e.contentType?x(t,o):null==l||l.setContents(t,o),c=u(t)},y=(e,t)=>{var o;return null!==(o=null==l?void 0:l.getText(e,t))&&void 0!==o?o:""},x=(e,t="api")=>{null==l||l.setText(e,t)},O=()=>{var e;return null!==(e=null==l?void 0:l.root.innerHTML)&&void 0!==e?e:""},T=e=>{l&&(l.root.innerHTML=e)};return o.watch((()=>e.content),(e=>{if(!l||!e||b(e))return;const t=l.getSelection();t&&o.nextTick((()=>null==l?void 0:l.setSelection(t))),f(e)}),{deep:!0}),o.watch((()=>e.enable),(e=>{l&&l.enable(e)})),{editor:a,getEditor:()=>a.value,getToolbar:()=>{var e;return null===(e=null==l?void 0:l.getModule("toolbar"))||void 0===e?void 0:e.container},getQuill:()=>{if(l)return l;throw'The quill editor hasn\'t been instantiated yet, \n make sure to call this method when the editor ready\n or use v-on:ready="onReady(quill)" event instead.'},getContents:v,setContents:f,getHTML:O,setHTML:T,pasteHTML:(e,t="api")=>{const o=null==l?void 0:l.clipboard.convert(e);o&&(null==l||l.setContents(o,t))},getText:y,setText:x,reinit:()=>{o.nextTick((()=>{var e;!t.slots.toolbar&&l&&(null===(e=l.getModule("toolbar"))||void 0===e||e.container.remove()),d()}))}}},render(){var e,t;return[null===(t=(e=this.$slots).toolbar)||void 0===t?void 0:t.call(e),o.h("div",{ref:"editor",...this.$attrs})]}});exports.Quill=n,exports.Delta=r,exports.QuillEditor=a;
@@ -15,7 +15,7 @@ export { Delta }
15
15
 
16
16
  declare type Module = {
17
17
  name: string;
18
- module: any;
18
+ module: unknown;
19
19
  options?: object;
20
20
  };
21
21
 
@@ -1,15 +1,15 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0
2
+ * VueQuill @vueup/vue-quill v1.1.0
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
6
6
  * https://quilljs.com/
7
7
  *
8
- * Copyright (c) 2022 Ahmad Luthfi Masruri
8
+ * Copyright (c) 2023 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-10-21T15:47:50.853Z
10
+ * Date: 2023-02-04T04:01:16.430Z
11
11
  */
12
- import { defineComponent, onMounted, onBeforeUnmount, ref, watch, h, nextTick } from 'vue';
12
+ import { defineComponent, onMounted, onBeforeUnmount, ref, watch, nextTick, h } from 'vue';
13
13
 
14
14
  var global$1 = (typeof global !== "undefined" ? global :
15
15
  typeof self !== "undefined" ? self :
@@ -18605,15 +18605,38 @@ const QuillEditor = defineComponent({
18605
18605
  }
18606
18606
  return Object.assign({}, props.globalOptions, props.options, clientOptions);
18607
18607
  };
18608
+ const maybeClone = (delta) => {
18609
+ return typeof delta === 'object' ? delta.slice() : delta;
18610
+ };
18611
+ const deltaHasValuesOtherThanRetain = (delta) => {
18612
+ return Object.values(delta.ops).some((v) => !v.retain || Object.keys(v).length !== 1);
18613
+ };
18614
+ // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
18615
+ let internalModel;
18616
+ const internalModelEquals = (against) => {
18617
+ if (typeof internalModel === typeof against) {
18618
+ if (against === internalModel) {
18619
+ return true;
18620
+ }
18621
+ // Ref/Proxy does not support instanceof, so do a loose check
18622
+ if (typeof against === 'object' && typeof internalModel === 'object') {
18623
+ return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
18624
+ }
18625
+ }
18626
+ return false;
18627
+ };
18608
18628
  const handleTextChange = (delta, oldContents, source) => {
18629
+ internalModel = maybeClone(getContents());
18609
18630
  // Update v-model:content when text changes
18610
- ctx.emit('update:content', getContents());
18631
+ if (!internalModelEquals(props.content)) {
18632
+ ctx.emit('update:content', internalModel);
18633
+ }
18611
18634
  ctx.emit('textChange', { delta, oldContents, source });
18612
18635
  };
18613
18636
  const isEditorFocus = ref();
18614
18637
  const handleSelectionChange = (range, oldRange, source) => {
18615
18638
  // Set isEditorFocus if quill.hasFocus()
18616
- isEditorFocus.value = (quill === null || quill === void 0 ? void 0 : quill.hasFocus()) ? true : false;
18639
+ isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus());
18617
18640
  ctx.emit('selectionChange', { range, oldRange, source });
18618
18641
  };
18619
18642
  watch(isEditorFocus, (focus) => {
@@ -18672,6 +18695,7 @@ const QuillEditor = defineComponent({
18672
18695
  else {
18673
18696
  quill === null || quill === void 0 ? void 0 : quill.setContents(content, source);
18674
18697
  }
18698
+ internalModel = maybeClone(content);
18675
18699
  };
18676
18700
  const getText = (index, length) => {
18677
18701
  var _a;
@@ -18701,13 +18725,16 @@ const QuillEditor = defineComponent({
18701
18725
  initialize();
18702
18726
  });
18703
18727
  };
18704
- // watch(
18705
- // () => props.content,
18706
- // (newContent, oldContents) => {
18707
- // if (!quill || !newContent || newContent === oldContents) return
18708
- // setContents(newContent)
18709
- // }
18710
- // )
18728
+ watch(() => props.content, (newContent) => {
18729
+ if (!quill || !newContent || internalModelEquals(newContent))
18730
+ return;
18731
+ // Restore the selection and cursor position after updating the content
18732
+ const selection = quill.getSelection();
18733
+ if (selection) {
18734
+ nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection));
18735
+ }
18736
+ setContents(newContent);
18737
+ }, { deep: true });
18711
18738
  watch(() => props.enable, (newValue) => {
18712
18739
  if (quill)
18713
18740
  quill.enable(newValue);