UNPKG

quill-uploader

Version:

Quill custom Uploader, supports images, videos, and attachments, with customizable loading indicators.

5 lines 27.1 kB
/*! * Quill Uploader Module v1.1.0 * https://github.com/mudoo/quill-uploader */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("Quill")):"function"==typeof define&&define.amd?define(["Quill"],e):"object"==typeof exports?exports.QuillUploader=e(require("Quill")):t.QuillUploader=e(t.Quill)}(self,(t=>(()=>{"use strict";var e=[,e=>{e.exports=t}],r={};function n(t){var o=r[t];if(void 0!==o)return o.exports;var i=r[t]={exports:{}};return e[t](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>X});var i=n(1),a=n.n(i);function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?c(Object(r),!0).forEach((function(e){v(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,m(n.key),n)}}function f(t,e,r){return e=d(e),function(t,e){if(e&&("object"==u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,p()?Reflect.construct(e,r||[],d(t).constructor):e.apply(t,r))}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=d(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},h.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function y(t,e){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},y(t,e)}function v(t,e,r){return(e=m(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function m(t){var e=function(t,e){if("object"!=u(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==u(e)?e:e+""}var b=window.Quill||a(),g=b.import("formats/image"),w=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),f(this,e,arguments)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&y(t,e)}(e,t),r=e,o=[{key:"create",value:function(t){var r,n,o,i,a,u=(r=e,n="create",o=this,a=h(d(1&(i=2)?r.prototype:r),n,o),2&i&&"function"==typeof a?function(t){return a.apply(o,t)}:a)([t]);if(!0===t)return u;if("string"==typeof t&&(t={url:t}),t.url){var c=document.createElement("img");c.setAttribute("src",t.url),c.setAttribute("alt",t.label||t.name||""),u.appendChild(c)}var s=l({},t);return delete s.url,Object.assign(u.dataset,s),u.setAttribute("contenteditable",!1),u}},{key:"formats",value:function(t){return l({},t.dataset)}},{key:"value",value:function(){}},{key:"register",value:function(){b.import("blots/block").allowedChildren.push(e)}}],(n=null)&&s(r.prototype,n),o&&s(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(b.import("blots/embed"));v(w,"blotName","loadingBlot"),v(w,"className","ql-uploading"),v(w,"tagName","span"),v(w,"allowedChildren",[g]);const O=w;function j(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function A(t,e,r){return(e=E(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function P(t){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P(t)}function x(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,E(n.key),n)}}function E(t){var e=function(t,e){if("object"!=P(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=P(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==P(e)?e:e+""}function k(t,e,r){return e=T(e),function(t,e){if(e&&("object"==P(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,S()?Reflect.construct(e,r||[],T(t).constructor):e.apply(t,r))}function S(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(S=function(){return!!t})()}function L(t,e,r,n){var o=q(T(1&n?t.prototype:t),e,r);return 2&n&&"function"==typeof o?function(t){return o.apply(r,t)}:o}function q(){return q="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=T(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},q.apply(null,arguments)}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function D(t,e){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},D(t,e)}var _=window.Quill||a();const R=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),k(this,e,arguments)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&D(t,e)}(e,t),r=e,o=[{key:"create",value:function(t){"string"==typeof t&&(t={url:t});var r=L(e,"create",this,2)([t.url]);return t.download&&(r.setAttribute("download",t.download),delete t.download),delete t.url,Object.assign(r.dataset,t),r}},{key:"formats",value:function(t){var e=function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?j(Object(r),!0).forEach((function(e){A(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):j(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({},t.dataset);return e.url||(e.url=t.getAttribute("href")),e}},{key:"register",value:function(){_.import("blots/block").allowedChildren.push(e)}}],(n=[{key:"format",value:function(t,r){r&&"object"===P(r)?L(e,"format",this,3)([t,r.url]):L(e,"format",this,3)([t,r])}}])&&x(r.prototype,n),o&&x(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(_.import("formats/link"));function C(t,e){return e=Object.assign({time:3},e),new Promise((function(r,n){var o=document.createElement("video"),i={autoplay:!0,loop:!0,muted:!0,playsinline:!0,"webkit-playsinline":!0,preload:"auto",crossOrigin:"anonymous"};for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&o.setAttribute(a,i[a]);var u=t instanceof File;u&&(t=URL.createObjectURL(t)),o.addEventListener("loadedmetadata",(function(){if(e.time){var t=e.time;t<1&&(t=this.duration*t),this.currentTime=t}})),o.addEventListener("loadeddata",(function(){var n=function(t,e){e=Object.assign({quality:.8,type:"image/jpeg"},e);var r=document.createElement("canvas");return r.width=t.videoWidth,r.height=t.videoHeight,r.getContext("2d").drawImage(t,0,0,r.width,r.height),r.toDataURL(e.type,e.quality)}(o,e),i={thumb:n,duration:Math.round(this.duration),width:this.videoWidth,height:this.videoHeight};u&&URL.revokeObjectURL(t),r(i),o=null})),o.addEventListener("play",(function(){this.pause()})),o.addEventListener("error",(function(t){n(t),o=null})),o.src=t}))}function N(t){return N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},N(t)}function F(t){return function(t){if(Array.isArray(t))return t}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return U(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?U(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function Q(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Q=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),u=new q(n||[]);return o(a,"_invoke",{value:E(t,r,u)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var p="suspendedStart",h="suspendedYield",d="executing",y="completed",v={};function m(){}function b(){}function g(){}var w={};l(w,a,(function(){return this}));var O=Object.getPrototypeOf,j=O&&O(O(T([])));j&&j!==r&&n.call(j,a)&&(w=j);var A=g.prototype=m.prototype=Object.create(w);function P(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==N(s)&&n.call(s,"__await")?e.resolve(s.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(s).then((function(t){l.value=t,a(l)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function E(e,r,n){var o=p;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=k(u,n);if(c){if(c===v)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var l=f(e,r,n);if("normal"===l.type){if(o=n.done?y:h,l.arg===v)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(o=y,n.method="throw",n.arg=l.arg)}}}function k(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,k(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=f(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function q(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function T(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(N(e)+" is not iterable")}return b.prototype=g,o(A,"constructor",{value:g,configurable:!0}),o(g,"constructor",{value:b,configurable:!0}),b.displayName=l(g,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,l(t,c,"GeneratorFunction")),t.prototype=Object.create(A),t},e.awrap=function(t){return{__await:t}},P(x.prototype),l(x.prototype,u,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},P(A),l(A,c,"Generator"),l(A,a,(function(){return this})),l(A,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,q.prototype={constructor:q,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(L),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(c&&l){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:T(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function M(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function I(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?M(Object(r),!0).forEach((function(e){V(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):M(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function B(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function G(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){B(i,n,o,a,u,"next",t)}function u(t){B(i,n,o,a,u,"throw",t)}a(void 0)}))}}function Y(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,K(n.key),n)}}function V(t,e,r){return(e=K(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function K(t){var e=function(t,e){if("object"!=N(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=N(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==N(e)?e:e+""}var H=window.Quill||a(),W=function(){return t=function t(e,r){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.quill=e,this.quill.customUploader=this,this.options=Object.assign({handler:null,upload:null,accepts:this.constructor.Accepts,imagePreload:!0,focusOnDone:!1},r);var o=Object.keys(this.options.accepts).reduce((function(t,e){return t.concat(n.options.accepts[e])}),[]);this.quill.uploader.options.mimetypes=o,"function"!=typeof this.options.upload&&console.error("[Missing config] upload function that returns a promise is required");var i=this.quill.getModule("toolbar");i&&Object.keys(this.options.accepts).forEach((function(t){i.addHandler(t,(function(){return n.pickFile(t)}))})),this.clipboardInit()},e=[{key:"clipboardInit",value:function(){var t,e=this,r=[],n=function(){r.forEach((function(t){var r=e.getLoadingDomRange(t.name);e.uploadFiles(r,[t])})),r=[]};this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,(function(e,o){var a;if("img"===e.tagName.toLowerCase()&&e.src.startsWith("data:")){var u=function(t,e){var r=t.split(","),n=r[0].match(/:(.*?);/)[1],o=atob(r[1]),i=o.length,a=new Uint8Array(i);if(!e){var u=n.split("/")[1].replace("jpeg","jpg");e=Math.random().toString().substr(3)+"."+u}for(;i--;)a[i]=o.charCodeAt(i);return new File([a],e,{type:n})}(e.src,"");u.base64=e.src;var c=(new i.Delta).insert(V({},O.blotName,{name:u.name,url:u.base64,key:u.name}));return a=u,r.push(a),clearTimeout(t),t=setTimeout(n,100),c}return o}))}},{key:"pickFile",value:function(t){var e,r=this,n=this.quill.container.querySelector("input.ql-uploader[type=file]");null==n&&((n=document.createElement("input")).setAttribute("type","file"),n.classList.add("ql-uploader"),n.setAttribute("style","visibility:hidden"),n.addEventListener("change",(function(){var t=r.quill.getSelection(!0);r.uploadFiles(t,n.files),n.value=""})),this.quill.container.appendChild(n));var o=(null===(e=this.options.accepts[t]||this.options.accepts.image)||void 0===e?void 0:e.join(", "))||"image/*";n.setAttribute("accept",o),n.click()}},{key:"insertPlaceholder",value:function(t,e){var r=t.index;t.index++,this.quill.history.ignoreChange=!0,t.length&&this.quill.deleteText(r,t.length,"api");var n=this.quill.insertEmbed(r,O.blotName,e,"api");return this.quill.history.ignoreChange=!1,n}},{key:"insertFilePlaceholder",value:function(t,e){var r=this,n=this.constructor.findType(e.type);e.key||(e.key=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";return Array.from({length:t},(function(){return e[Math.floor(62*Math.random())]})).join("")}());var o=e.key,i=this.getLoadingDomRange(o);return i.delta?Promise.resolve(i.delta):new Promise((function(i){var a,u;"attachment"===n?i(r.insertPlaceholder(t,{label:e.name,url:r.constructor.DefaultAttachmentPlaceholder,key:o})):e.thumb||e.base64?i(r.insertPlaceholder(t,{name:e.name,url:e.thumb||e.base64,key:o})):null!==(a=r.options.accepts)&&void 0!==a&&null!==(a=a.image)&&void 0!==a&&a.includes(e.type)?function(t){return new Promise((function(e,r){var n=new FileReader;n.onload=function(t){n=null,e(t.target.result)},n.onerror=r,n.readAsDataURL(t)}))}(e).then((function(n){i(r.insertPlaceholder(t,{name:e.name,url:n,key:o}))})):null!==(u=r.options.accepts)&&void 0!==u&&null!==(u=u.video)&&void 0!==u&&u.includes(e.type)?C(e).then((function(n){i(r.insertPlaceholder(t,{name:e.name,url:n.thumb,key:o}))})):i(r.insertPlaceholder(t,{url:r.constructor.DefaultFilePlaceholder,key:o}))}))}},{key:"calculatePlaceholderInsertLength",value:function(t){return t.ops.reduce((function(t,e){return Object.prototype.hasOwnProperty.call(e,"insert")&&t++,t}),0)}},{key:"getLoadingDomRange",value:function(t){var e=this.quill.container.querySelector('.ql-uploading[data-key="'.concat(t,'"]'));if(!e)return{index:0,length:0};var r=this.quill.constructor.find(e),n=this.quill.getIndex(r),o=this.quill.getContents(n,1);return{blot:r,delta:o,index:n,length:this.calculatePlaceholderInsertLength(o)}}},{key:"loadImage",value:function(t){var e=this;return new Promise((function(r){var n,o=e.getLoadingDomRange(t.key),i=null===(n=o.blot)||void 0===n?void 0:n.domNode.querySelector("img");i?(i.addEventListener("load",(function(){return r(o)})),i.src=t.url):r(o)}))}},{key:"insertToEditor",value:(o=G(Q().mark((function t(e){var r,n,o;return Q().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("image"!==(r=this.constructor.findType(e.type))||!this.options.imagePreload){t.next=4;break}return t.next=4,this.loadImage(e);case 4:return n=this.getLoadingDomRange(e.key),o=n.length,this.quill.history.ignoreChange=!0,this.quill.deleteText(n.index,o,"api"),this.quill.history.ignoreChange=!1,"attachment"===r?(o+=e.name.length-1,this.quill.insertText(n.index,e.name,{link:Object.assign({key:e.key,download:e.name,url:e.url,ext:e.name.slice(e.name.lastIndexOf(".")+1)},e.delta)},"user")):this.quill.insertEmbed(n.index,r,e.delta||e.url,"user"),t.abrupt("return",I(I({},n),{},{length:o}));case 11:case"end":return t.stop()}}),t,this)}))),function(t){return o.apply(this,arguments)})},{key:"removePlaceholder",value:function(t){this.quill.history.ignoreChange=!0;var e=this.getLoadingDomRange(t.key);this.quill.deleteText(e.index,e.length,"api"),this.quill.history.ignoreChange=!1}},{key:"uploadFiles",value:(n=G(Q().mark((function t(e,r){var n,o,i,a,u=this;return Q().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=F(r),o=n.slice(0),this.quill.emitter.emit(this.constructor.Events.start,o),!this.options.handler){t.next=6;break}return t.next=5,this.options.handler(o);case 5:o=t.sent;case 6:return t.next=8,Promise.all(o.map((function(t){return u.insertFilePlaceholder(e,t)})));case 8:return t.next=10,this.options.upload(e,o,function(){var t=G(Q().mark((function t(e,r){return Q().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=6;break}return t.next=3,u.insertToEditor(r);case 3:i=t.sent,t.next=7;break;case 6:u.removePlaceholder(r);case 7:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}());case 10:if(a=t.sent){t.next=14;break}return this.done(i,a),t.abrupt("return");case 14:return t.next=16,Promise.allSettled(a.map(function(){var t=G(Q().mark((function t(e){return Q().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.url){t.next=6;break}return t.next=3,u.insertToEditor(e);case 3:i=t.sent,t.next=7;break;case 6:u.removePlaceholder(e);case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 16:this.done(i,a);case 17:case"end":return t.stop()}}),t,this)}))),function(t,e){return n.apply(this,arguments)})},{key:"done",value:function(t,e){var r=this;t&&this.options.focusOnDone&&(this.quill.setSelection(t.index+t.length,"user"),setTimeout((function(){return r.quill.focus()}),16)),this.quill.emitter.emit(this.constructor.Events.done,e)}}],r=[{key:"findType",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.Accepts,r=Object.keys(e);return r.includes(t)?t:r.find((function(r){return e[r].includes(t)}))||r[0]}},{key:"register",value:function(){H.register(O,!0),H.register(R,!0)}}],e&&Y(t.prototype,e),r&&Y(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r,n,o}();V(W,"DefaultFilePlaceholder","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAC0AQMAAADfKmdSAAAAA1BMVEX19fWwaZ+KAAAAHklEQVRYw+3BMQEAAADCIPuntsYOYAAAAAAAAABhBxzUAAEYBjd2AAAAAElFTkSuQmCC"),V(W,"DefaultAttachmentPlaceholder","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYAQMAAADaua+7AAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAAtJREFUCNdjoDEAAABgAAGVQESKAAAAAElFTkSuQmCC"),V(W,"Accepts",{image:["image/jpeg","image/png","image/gif"],video:["video/mp4"],attachment:["text/plain","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/zip","application/vnd.rar","application/x-7z-compressed"]}),V(W,"Events",{start:"uploader-start",done:"uploader-done"});const z=W;window.Quill&&window.Quill.register("modules/customUploader",W);const X=z;return o})()));