@vueup/vue-quill
Advanced tools
Comparing version 1.0.0 to 1.0.1
/*! | ||
* VueQuill @vueup/vue-quill v1.0.0 | ||
* VueQuill @vueup/vue-quill v1.0.1 | ||
* https://vueup.github.io/vue-quill/ | ||
@@ -10,3 +10,3 @@ * | ||
* Released under the MIT license | ||
* Date: 2022-10-21T15:47:50.853Z | ||
* Date: 2022-12-20T16:01:54.428Z | ||
*/ | ||
@@ -216,5 +216,28 @@ 'use strict'; | ||
}; | ||
const deltaHasValuesOtherThanRetain = (delta) => { | ||
return Object.values(delta).some((v) => !v.retain); | ||
}; | ||
// eslint-disable-next-line vue/no-setup-props-destructure | ||
let internalModel = props.content; // Doesn't need reactivity | ||
const internalModelEquals = (against) => { | ||
if (typeof internalModel === typeof against) { | ||
if (against === internalModel) { | ||
return true; | ||
} | ||
// Ref/Proxy does not support instanceof, so do a loose check | ||
if (typeof against === 'object' && typeof internalModel === 'object') { | ||
return !deltaHasValuesOtherThanRetain(internalModel.diff(against)); | ||
} | ||
} | ||
return false; | ||
}; | ||
const handleTextChange = (delta, oldContents, source) => { | ||
// Quill should never be null at this point because we receive an event | ||
// so content should not be undefined but let's make ts and eslint happy | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
internalModel = getContents(); | ||
// Update v-model:content when text changes | ||
ctx.emit('update:content', getContents()); | ||
if (!internalModelEquals(props.content)) { | ||
ctx.emit('update:content', internalModel); | ||
} | ||
ctx.emit('textChange', { delta, oldContents, source }); | ||
@@ -225,3 +248,3 @@ }; | ||
// Set isEditorFocus if quill.hasFocus() | ||
isEditorFocus.value = (quill === null || quill === void 0 ? void 0 : quill.hasFocus()) ? true : false; | ||
isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus()); | ||
ctx.emit('selectionChange', { range, oldRange, source }); | ||
@@ -314,9 +337,13 @@ }; | ||
}; | ||
// watch( | ||
// () => props.content, | ||
// (newContent, oldContents) => { | ||
// if (!quill || !newContent || newContent === oldContents) return | ||
// setContents(newContent) | ||
// } | ||
// ) | ||
vue.watch(() => props.content, (newContent) => { | ||
if (!quill || !newContent || internalModelEquals(newContent)) | ||
return; | ||
internalModel = newContent; | ||
// Restore the selection and cursor position after updating the content | ||
const selection = quill.getSelection(); | ||
if (selection) { | ||
vue.nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection)); | ||
} | ||
setContents(newContent); | ||
}); | ||
vue.watch(() => props.enable, (newValue) => { | ||
@@ -323,0 +350,0 @@ if (quill) |
/*! | ||
* VueQuill @vueup/vue-quill v1.0.0 | ||
* VueQuill @vueup/vue-quill v1.0.1 | ||
* https://vueup.github.io/vue-quill/ | ||
@@ -10,4 +10,4 @@ * | ||
* Released under the MIT license | ||
* Date: 2022-10-21T15:47:50.853Z | ||
* Date: 2022-12-20T16:01:54.428Z | ||
*/ | ||
"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; | ||
"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; |
@@ -18,3 +18,3 @@ import { AllowedComponentProps } from 'vue'; | ||
name: string; | ||
module: any; | ||
module: unknown; | ||
options?: object; | ||
@@ -21,0 +21,0 @@ }; |
/*! | ||
* VueQuill @vueup/vue-quill v1.0.0 | ||
* VueQuill @vueup/vue-quill v1.0.1 | ||
* https://vueup.github.io/vue-quill/ | ||
@@ -10,3 +10,3 @@ * | ||
* Released under the MIT license | ||
* Date: 2022-10-21T15:47:50.853Z | ||
* Date: 2022-12-20T16:01:54.428Z | ||
*/ | ||
@@ -16,3 +16,3 @@ import Quill from 'quill'; | ||
export { default as Delta } from 'quill-delta'; | ||
import { defineComponent, onMounted, onBeforeUnmount, ref, watch, h, nextTick } from 'vue'; | ||
import { defineComponent, onMounted, onBeforeUnmount, ref, watch, nextTick, h } from 'vue'; | ||
@@ -209,5 +209,28 @@ const toolbarOptions = { | ||
}; | ||
const deltaHasValuesOtherThanRetain = (delta) => { | ||
return Object.values(delta).some((v) => !v.retain); | ||
}; | ||
// eslint-disable-next-line vue/no-setup-props-destructure | ||
let internalModel = props.content; // Doesn't need reactivity | ||
const internalModelEquals = (against) => { | ||
if (typeof internalModel === typeof against) { | ||
if (against === internalModel) { | ||
return true; | ||
} | ||
// Ref/Proxy does not support instanceof, so do a loose check | ||
if (typeof against === 'object' && typeof internalModel === 'object') { | ||
return !deltaHasValuesOtherThanRetain(internalModel.diff(against)); | ||
} | ||
} | ||
return false; | ||
}; | ||
const handleTextChange = (delta, oldContents, source) => { | ||
// Quill should never be null at this point because we receive an event | ||
// so content should not be undefined but let's make ts and eslint happy | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
internalModel = getContents(); | ||
// Update v-model:content when text changes | ||
ctx.emit('update:content', getContents()); | ||
if (!internalModelEquals(props.content)) { | ||
ctx.emit('update:content', internalModel); | ||
} | ||
ctx.emit('textChange', { delta, oldContents, source }); | ||
@@ -218,3 +241,3 @@ }; | ||
// Set isEditorFocus if quill.hasFocus() | ||
isEditorFocus.value = (quill === null || quill === void 0 ? void 0 : quill.hasFocus()) ? true : false; | ||
isEditorFocus.value = !!(quill === null || quill === void 0 ? void 0 : quill.hasFocus()); | ||
ctx.emit('selectionChange', { range, oldRange, source }); | ||
@@ -307,9 +330,13 @@ }; | ||
}; | ||
// watch( | ||
// () => props.content, | ||
// (newContent, oldContents) => { | ||
// if (!quill || !newContent || newContent === oldContents) return | ||
// setContents(newContent) | ||
// } | ||
// ) | ||
watch(() => props.content, (newContent) => { | ||
if (!quill || !newContent || internalModelEquals(newContent)) | ||
return; | ||
internalModel = newContent; | ||
// Restore the selection and cursor position after updating the content | ||
const selection = quill.getSelection(); | ||
if (selection) { | ||
nextTick(() => quill === null || quill === void 0 ? void 0 : quill.setSelection(selection)); | ||
} | ||
setContents(newContent); | ||
}); | ||
watch(() => props.enable, (newValue) => { | ||
@@ -316,0 +343,0 @@ if (quill) |
/*! | ||
* VueQuill @vueup/vue-quill v1.0.0 | ||
* VueQuill @vueup/vue-quill v1.0.1 | ||
* https://vueup.github.io/vue-quill/ | ||
@@ -10,4 +10,4 @@ * | ||
* Released under the MIT license | ||
* Date: 2022-10-21T15:47:50.853Z | ||
* Date: 2022-12-20T16:01:54.428Z | ||
*/ | ||
import e from"quill";export{default as Quill}from"quill";export{default as Delta}from"quill-delta";import{defineComponent as t,onMounted as o,onBeforeUnmount as l,ref as n,watch as r,h as a,nextTick as i}from"vue";const d={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"]]},s=t({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(d).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:(t,a)=>{let s,u;o((()=>{m()})),l((()=>{s=null}));const c=n(),m=()=>{var o;if(c.value){if(u=b(),t.modules)if(Array.isArray(t.modules))for(const o of t.modules)e.register(`modules/${o.name}`,o.module);else e.register(`modules/${t.modules.name}`,t.modules.module);s=new e(c.value,u),f(t.content),s.on("text-change",g),s.on("selection-change",h),s.on("editor-change",v),"bubble"!==t.theme&&c.value.classList.remove("ql-bubble"),"snow"!==t.theme&&c.value.classList.remove("ql-snow"),null===(o=s.getModule("toolbar"))||void 0===o||o.container.addEventListener("mousedown",(e=>{e.preventDefault()})),a.emit("ready",s)}},b=()=>{const e={};if(""!==t.theme&&(e.theme=t.theme),t.readOnly&&(e.readOnly=t.readOnly),t.placeholder&&(e.placeholder=t.placeholder),t.toolbar&&""!==t.toolbar&&(e.modules={toolbar:(()=>{if("object"==typeof t.toolbar)return t.toolbar;if("string"==typeof t.toolbar){return"#"===t.toolbar.charAt(0)?t.toolbar:d[t.toolbar]}})()}),t.modules){const o=(()=>{var e,o;const l={};if(Array.isArray(t.modules))for(const n of t.modules)l[n.name]=null!==(e=n.options)&&void 0!==e?e:{};else l[t.modules.name]=null!==(o=t.modules.options)&&void 0!==o?o:{};return l})();e.modules=Object.assign({},e.modules,o)}return Object.assign({},t.globalOptions,t.options,e)},g=(e,t,o)=>{a.emit("update:content",y()),a.emit("textChange",{delta:e,oldContents:t,source:o})},p=n(),h=(e,t,o)=>{p.value=!!(null==s?void 0:s.hasFocus()),a.emit("selectionChange",{range:e,oldRange:t,source:o})};r(p,(e=>{a.emit(e?"focus":"blur",c)}));const v=(...e)=>{"text-change"===e[0]&&a.emit("editorChange",{name:e[0],delta:e[1],oldContents:e[2],source:e[3]}),"selection-change"===e[0]&&a.emit("editorChange",{name:e[0],range:e[1],oldRange:e[2],source:e[3]})},y=(e,o)=>"html"===t.contentType?O():"text"===t.contentType?T(e,o):null==s?void 0:s.getContents(e,o),f=(e,o="api")=>{"html"===t.contentType?q(e):"text"===t.contentType?x(e,o):null==s||s.setContents(e,o)},T=(e,t)=>{var o;return null!==(o=null==s?void 0:s.getText(e,t))&&void 0!==o?o:""},x=(e,t="api")=>{null==s||s.setText(e,t)},O=()=>{var e;return null!==(e=null==s?void 0:s.root.innerHTML)&&void 0!==e?e:""},q=e=>{s&&(s.root.innerHTML=e)};return r((()=>t.enable),(e=>{s&&s.enable(e)})),{editor:c,getEditor:()=>c.value,getToolbar:()=>{var e;return null===(e=null==s?void 0:s.getModule("toolbar"))||void 0===e?void 0:e.container},getQuill:()=>{if(s)return s;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:y,setContents:f,getHTML:O,setHTML:q,pasteHTML:(e,t="api")=>{const o=null==s?void 0:s.clipboard.convert(e);o&&(null==s||s.setContents(o,t))},getText:T,setText:x,reinit:()=>{i((()=>{var e;!a.slots.toolbar&&s&&(null===(e=s.getModule("toolbar"))||void 0===e||e.container.remove()),m()}))}}},render(){var e,t;return[null===(t=(e=this.$slots).toolbar)||void 0===t?void 0:t.call(e),a("div",{ref:"editor",...this.$attrs})]}});export{s as QuillEditor}; | ||
import e from"quill";export{default as Quill}from"quill";export{default as Delta}from"quill-delta";import{defineComponent as t,onMounted as o,onBeforeUnmount as l,ref as n,watch as r,nextTick as i,h as a}from"vue";const d={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"]]},s=t({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(d).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:(t,a)=>{let s,u;o((()=>{m()})),l((()=>{s=null}));const c=n(),m=()=>{var o;if(c.value){if(u=b(),t.modules)if(Array.isArray(t.modules))for(const o of t.modules)e.register(`modules/${o.name}`,o.module);else e.register(`modules/${t.modules.name}`,t.modules.module);s=new e(c.value,u),T(t.content),s.on("text-change",v),s.on("selection-change",f),s.on("editor-change",y),"bubble"!==t.theme&&c.value.classList.remove("ql-bubble"),"snow"!==t.theme&&c.value.classList.remove("ql-snow"),null===(o=s.getModule("toolbar"))||void 0===o||o.container.addEventListener("mousedown",(e=>{e.preventDefault()})),a.emit("ready",s)}},b=()=>{const e={};if(""!==t.theme&&(e.theme=t.theme),t.readOnly&&(e.readOnly=t.readOnly),t.placeholder&&(e.placeholder=t.placeholder),t.toolbar&&""!==t.toolbar&&(e.modules={toolbar:(()=>{if("object"==typeof t.toolbar)return t.toolbar;if("string"==typeof t.toolbar){return"#"===t.toolbar.charAt(0)?t.toolbar:d[t.toolbar]}})()}),t.modules){const o=(()=>{var e,o;const l={};if(Array.isArray(t.modules))for(const n of t.modules)l[n.name]=null!==(e=n.options)&&void 0!==e?e:{};else l[t.modules.name]=null!==(o=t.modules.options)&&void 0!==o?o:{};return l})();e.modules=Object.assign({},e.modules,o)}return Object.assign({},t.globalOptions,t.options,e)};let p=t.content;const g=e=>{if(typeof p==typeof e){if(e===p)return!0;if("object"==typeof e&&"object"==typeof p)return t=p.diff(e),!Object.values(t).some((e=>!e.retain))}var t;return!1},v=(e,o,l)=>{p=O(),g(t.content)||a.emit("update:content",p),a.emit("textChange",{delta:e,oldContents:o,source:l})},h=n(),f=(e,t,o)=>{h.value=!!(null==s?void 0:s.hasFocus()),a.emit("selectionChange",{range:e,oldRange:t,source:o})};r(h,(e=>{a.emit(e?"focus":"blur",c)}));const y=(...e)=>{"text-change"===e[0]&&a.emit("editorChange",{name:e[0],delta:e[1],oldContents:e[2],source:e[3]}),"selection-change"===e[0]&&a.emit("editorChange",{name:e[0],range:e[1],oldRange:e[2],source:e[3]})},O=(e,o)=>"html"===t.contentType?C():"text"===t.contentType?x(e,o):null==s?void 0:s.getContents(e,o),T=(e,o="api")=>{"html"===t.contentType?j(e):"text"===t.contentType?q(e,o):null==s||s.setContents(e,o)},x=(e,t)=>{var o;return null!==(o=null==s?void 0:s.getText(e,t))&&void 0!==o?o:""},q=(e,t="api")=>{null==s||s.setText(e,t)},C=()=>{var e;return null!==(e=null==s?void 0:s.root.innerHTML)&&void 0!==e?e:""},j=e=>{s&&(s.root.innerHTML=e)};return r((()=>t.content),(e=>{if(!s||!e||g(e))return;p=e;const t=s.getSelection();t&&i((()=>null==s?void 0:s.setSelection(t))),T(e)})),r((()=>t.enable),(e=>{s&&s.enable(e)})),{editor:c,getEditor:()=>c.value,getToolbar:()=>{var e;return null===(e=null==s?void 0:s.getModule("toolbar"))||void 0===e?void 0:e.container},getQuill:()=>{if(s)return s;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:O,setContents:T,getHTML:C,setHTML:j,pasteHTML:(e,t="api")=>{const o=null==s?void 0:s.clipboard.convert(e);o&&(null==s||s.setContents(o,t))},getText:x,setText:q,reinit:()=>{i((()=>{var e;!a.slots.toolbar&&s&&(null===(e=s.getModule("toolbar"))||void 0===e||e.container.remove()),m()}))}}},render(){var e,t;return[null===(t=(e=this.$slots).toolbar)||void 0===t?void 0:t.call(e),a("div",{ref:"editor",...this.$attrs})]}});export{s as QuillEditor}; |
{ | ||
"name": "@vueup/vue-quill", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Vue 3 rich text editor based on Quill.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2226325
38377