@vueup/vue-quill 1.0.0-beta.9 → 1.0.1

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,5 +1,5 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0-beta.9
2
+ * VueQuill @vueup/vue-quill v1.0.1
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Copyright (c) 2022 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-07-15T12:19:26.189Z
10
+ * Date: 2022-12-20T16:01:54.428Z
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 deltaHasValuesOtherThanRetain = (delta) => {
216
+ return Object.values(delta).some((v) => !v.retain);
217
+ };
218
+ // eslint-disable-next-line vue/no-setup-props-destructure
219
+ let internalModel = props.content; // Doesn't need reactivity
220
+ const internalModelEquals = (against) => {
221
+ if (typeof internalModel === typeof against) {
222
+ if (against === internalModel) {
223
+ return true;
224
+ }
225
+ // Ref/Proxy does not support instanceof, so do a loose check
226
+ if (typeof against === 'object' && typeof internalModel === 'object') {
227
+ return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
228
+ }
229
+ }
230
+ return false;
231
+ };
215
232
  const handleTextChange = (delta, oldContents, source) => {
233
+ // Quill should never be null at this point because we receive an event
234
+ // so content should not be undefined but let's make ts and eslint happy
235
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
236
+ internalModel = 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) => {
@@ -308,13 +331,17 @@ const QuillEditor = vue.defineComponent({
308
331
  initialize();
309
332
  });
310
333
  };
311
- // watch(
312
- // () => props.content,
313
- // (newContent, oldContents) => {
314
- // if (!quill || !newContent || newContent === oldContents) return
315
- // setContents(newContent)
316
- // }
317
- // )
334
+ vue.watch(() => props.content, (newContent) => {
335
+ if (!quill || !newContent || internalModelEquals(newContent))
336
+ return;
337
+ internalModel = newContent;
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
+ });
318
345
  vue.watch(() => props.enable, (newValue) => {
319
346
  if (quill)
320
347
  quill.enable(newValue);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0-beta.9
2
+ * VueQuill @vueup/vue-quill v1.0.1
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
@@ -7,6 +7,6 @@
7
7
  *
8
8
  * Copyright (c) 2022 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-07-15T12:19:26.189Z
10
+ * Date: 2022-12-20T16:01:54.428Z
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),g(e.content),l.on("text-change",b),l.on("selection-change",p),l.on("editor-change",h),"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)};let u=e.content;const c=e=>{if(typeof u==typeof e){if(e===u)return!0;if("object"==typeof e&&"object"==typeof u)return t=u.diff(e),!Object.values(t).some((e=>!e.retain))}var t;return!1},b=(o,l,n)=>{u=v(),c(e.content)||t.emit("update:content",u),t.emit("textChange",{delta:o,oldContents:l,source:n})},m=o.ref(),p=(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 h=(...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?x():"text"===e.contentType?f(t,o):null==l?void 0:l.getContents(t,o),g=(t,o="api")=>{"html"===e.contentType?T(t):"text"===e.contentType?y(t,o):null==l||l.setContents(t,o)},f=(e,t)=>{var o;return null!==(o=null==l?void 0:l.getText(e,t))&&void 0!==o?o:""},y=(e,t="api")=>{null==l||l.setText(e,t)},x=()=>{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||c(e))return;u=e;const t=l.getSelection();t&&o.nextTick((()=>null==l?void 0:l.setSelection(t))),g(e)})),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:g,getHTML:x,setHTML:T,pasteHTML:(e,t="api")=>{const o=null==l?void 0:l.clipboard.convert(e);o&&(null==l||l.setContents(o,t))},getText:f,setText:y,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,5 +1,5 @@
1
1
  /*!
2
- * VueQuill @vueup/vue-quill v1.0.0-beta.9
2
+ * VueQuill @vueup/vue-quill v1.0.1
3
3
  * https://vueup.github.io/vue-quill/
4
4
  *
5
5
  * Includes quill v1.3.7
@@ -7,9 +7,9 @@
7
7
  *
8
8
  * Copyright (c) 2022 Ahmad Luthfi Masruri
9
9
  * Released under the MIT license
10
- * Date: 2022-07-15T12:19:26.189Z
10
+ * Date: 2022-12-20T16:01:54.428Z
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 deltaHasValuesOtherThanRetain = (delta) => {
18609
+ return Object.values(delta).some((v) => !v.retain);
18610
+ };
18611
+ // eslint-disable-next-line vue/no-setup-props-destructure
18612
+ let internalModel = props.content; // Doesn't need reactivity
18613
+ const internalModelEquals = (against) => {
18614
+ if (typeof internalModel === typeof against) {
18615
+ if (against === internalModel) {
18616
+ return true;
18617
+ }
18618
+ // Ref/Proxy does not support instanceof, so do a loose check
18619
+ if (typeof against === 'object' && typeof internalModel === 'object') {
18620
+ return !deltaHasValuesOtherThanRetain(internalModel.diff(against));
18621
+ }
18622
+ }
18623
+ return false;
18624
+ };
18608
18625
  const handleTextChange = (delta, oldContents, source) => {
18626
+ // Quill should never be null at this point because we receive an event
18627
+ // so content should not be undefined but let's make ts and eslint happy
18628
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18629
+ internalModel = 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) => {
@@ -18701,13 +18724,17 @@ const QuillEditor = defineComponent({
18701
18724
  initialize();
18702
18725
  });
18703
18726
  };
18704
- // watch(
18705
- // () => props.content,
18706
- // (newContent, oldContents) => {
18707
- // if (!quill || !newContent || newContent === oldContents) return
18708
- // setContents(newContent)
18709
- // }
18710
- // )
18727
+ watch(() => props.content, (newContent) => {
18728
+ if (!quill || !newContent || internalModelEquals(newContent))
18729
+ return;
18730
+ internalModel = newContent;
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
+ });
18711
18738
  watch(() => props.enable, (newValue) => {
18712
18739
  if (quill)
18713
18740
  quill.enable(newValue);