/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@editorjs/attaches@1.3.2/dist/attaches.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
(function(){"use strict";try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode(`.cdx-attaches{--color-line: #EFF0F1;--color-bg: #fff;--color-bg-secondary: #F8F8F8;--color-bg-secondary--hover: #f2f2f2;--color-text-secondary: #707684}.cdx-attaches--with-file{display:flex;align-items:center;padding:10px 12px;border:1px solid var(--color-line);border-radius:7px;background:var(--color-bg)}.cdx-attaches--with-file .cdx-attaches__file-info{display:grid;grid-gap:4px;max-width:calc(100% - 80px);margin:auto 0;flex-grow:2}.cdx-attaches--with-file .cdx-attaches__download-button{display:flex;align-items:center;background:var(--color-bg-secondary);padding:6px;border-radius:6px;margin:auto 0 auto auto;color:inherit}.cdx-attaches--with-file .cdx-attaches__download-button:hover{background:var(--color-bg-secondary--hover)}.cdx-attaches--with-file .cdx-attaches__download-button svg{width:20px;height:20px;fill:none}.cdx-attaches--with-file .cdx-attaches__file-icon{position:relative}.cdx-attaches--with-file .cdx-attaches__file-icon-background{background-color:#333;width:27px;height:30px;margin-right:12px;border-radius:8px;display:flex;align-items:center;justify-content:center}@supports (-webkit-mask-box-image: url()){.cdx-attaches--with-file .cdx-attaches__file-icon-background{border-radius:0;-webkit-mask-box-image:url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 10.3872C0 1.83334 1.83334 0 10.3872 0H13.6128C22.1667 0 24 1.83334 24 10.3872V13.6128C24 22.1667 22.1667 24 13.6128 24H10.3872C1.83334 24 0 22.1667 0 13.6128V10.3872Z' fill='black'/%3E%3C/svg%3E%0A") 48% 41% 37.9% 53.3%}}.cdx-attaches--with-file .cdx-attaches__file-icon-label{position:absolute;left:3px;top:11px;background:inherit;text-transform:uppercase;line-height:1em;color:#fff;padding:1px 2px;border-radius:3px;font-size:10px;font-weight:700;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;letter-spacing:.02em}.cdx-attaches--with-file .cdx-attaches__file-icon svg{width:20px;height:20px}.cdx-attaches--with-file .cdx-attaches__file-icon path{stroke:#fff}.cdx-attaches--with-file .cdx-attaches__size{color:var(--color-text-secondary);font-size:12px;line-height:1em}.cdx-attaches--with-file .cdx-attaches__size:after{content:attr(data-size);margin-left:.2em}.cdx-attaches--with-file .cdx-attaches__title{white-space:nowrap;text-overflow:ellipsis;overflow:hidden;outline:none;max-width:90%;font-size:14px;font-weight:500;line-height:1em}.cdx-attaches--with-file .cdx-attaches__title:empty:before{content:attr(data-placeholder);color:#7b7e89}.cdx-attaches--loading .cdx-attaches__title,.cdx-attaches--loading .cdx-attaches__file-icon,.cdx-attaches--loading .cdx-attaches__size,.cdx-attaches--loading .cdx-attaches__download-button,.cdx-attaches--loading .cdx-attaches__button{opacity:0;font-size:0}.cdx-attaches__button{display:flex;align-items:center;justify-content:center;color:#000;border-radius:7px;font-weight:500}.cdx-attaches__button svg{margin-top:0}`)),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
(function(O,x){typeof exports=="object"&&typeof module<"u"?module.exports=x():typeof define=="function"&&define.amd?define(x):(O=typeof globalThis<"u"?globalThis:O||self,O.AttachesTool=x())})(this,function(){"use strict";function O(T){return T&&T.__esModule&&Object.prototype.hasOwnProperty.call(T,"default")?T.default:T}var x={exports:{}};(function(T,h){(function(d,l){T.exports=l()})(window,function(){return function(d){var l={};function r(n){if(l[n])return l[n].exports;var o=l[n]={i:n,l:!1,exports:{}};return d[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=d,r.c=l,r.d=function(n,o,u){r.o(n,o)||Object.defineProperty(n,o,{enumerable:!0,get:u})},r.r=function(n){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,o){if(1&o&&(n=r(n)),8&o||4&o&&typeof n=="object"&&n&&n.__esModule)return n;var u=Object.create(null);if(r.r(u),Object.defineProperty(u,"default",{enumerable:!0,value:n}),2&o&&typeof n!="string")for(var w in n)r.d(u,w,(function(i){return n[i]}).bind(null,w));return u},r.n=function(n){var o=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(o,"a",o),o},r.o=function(n,o){return Object.prototype.hasOwnProperty.call(n,o)},r.p="",r(r.s=3)}([function(d,l){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch{typeof window=="object"&&(r=window)}d.exports=r},function(d,l,r){(function(n){var o=r(2),u=setTimeout;function w(){}function i(t){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if(typeof t!="function")throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],e(t,this)}function f(t,s){for(;t._state===3;)t=t._value;t._state!==0?(t._handled=!0,i._immediateFn(function(){var a=t._state===1?s.onFulfilled:s.onRejected;if(a!==null){var g;try{g=a(t._value)}catch(m){return void y(s.promise,m)}c(s.promise,g)}else(t._state===1?c:y)(s.promise,t._value)})):t._deferreds.push(s)}function c(t,s){try{if(s===t)throw new TypeError("A promise cannot be resolved with itself.");if(s&&(typeof s=="object"||typeof s=="function")){var a=s.then;if(s instanceof i)return t._state=3,t._value=s,void v(t);if(typeof a=="function")return void e((g=a,m=s,function(){g.apply(m,arguments)}),t)}t._state=1,t._value=s,v(t)}catch(p){y(t,p)}var g,m}function y(t,s){t._state=2,t._value=s,v(t)}function v(t){t._state===2&&t._deferreds.length===0&&i._immediateFn(function(){t._handled||i._unhandledRejectionFn(t._value)});for(var s=0,a=t._deferreds.length;s<a;s++)f(t,t._deferreds[s]);t._deferreds=null}function b(t,s,a){this.onFulfilled=typeof t=="function"?t:null,this.onRejected=typeof s=="function"?s:null,this.promise=a}function e(t,s){var a=!1;try{t(function(g){a||(a=!0,c(s,g))},function(g){a||(a=!0,y(s,g))})}catch(g){if(a)return;a=!0,y(s,g)}}i.prototype.catch=function(t){return this.then(null,t)},i.prototype.then=function(t,s){var a=new this.constructor(w);return f(this,new b(t,s,a)),a},i.prototype.finally=o.a,i.all=function(t){return new i(function(s,a){if(!t||t.length===void 0)throw new TypeError("Promise.all accepts an array");var g=Array.prototype.slice.call(t);if(g.length===0)return s([]);var m=g.length;function p(_,S){try{if(S&&(typeof S=="object"||typeof S=="function")){var C=S.then;if(typeof C=="function")return void C.call(S,function(L){p(_,L)},a)}g[_]=S,--m==0&&s(g)}catch(L){a(L)}}for(var E=0;E<g.length;E++)p(E,g[E])})},i.resolve=function(t){return t&&typeof t=="object"&&t.constructor===i?t:new i(function(s){s(t)})},i.reject=function(t){return new i(function(s,a){a(t)})},i.race=function(t){return new i(function(s,a){for(var g=0,m=t.length;g<m;g++)t[g].then(s,a)})},i._immediateFn=typeof n=="function"&&function(t){n(t)}||function(t){u(t,0)},i._unhandledRejectionFn=function(t){typeof console<"u"&&console&&console.warn("Possible Unhandled Promise Rejection:",t)},l.a=i}).call(this,r(5).setImmediate)},function(d,l,r){l.a=function(n){var o=this.constructor;return this.then(function(u){return o.resolve(n()).then(function(){return u})},function(u){return o.resolve(n()).then(function(){return o.reject(u)})})}},function(d,l,r){function n(e){return(n=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}r(4);var o,u,w,i,f,c,y,v=r(8),b=(u=function(e){return new Promise(function(t,s){e=i(e),(e=f(e)).beforeSend&&e.beforeSend();var a=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");a.open(e.method,e.url),a.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(e.headers).forEach(function(m){var p=e.headers[m];a.setRequestHeader(m,p)});var g=e.ratio;a.upload.addEventListener("progress",function(m){var p=Math.round(m.loaded/m.total*100),E=Math.ceil(p*g/100);e.progress(Math.min(E,100))},!1),a.addEventListener("progress",function(m){var p=Math.round(m.loaded/m.total*100),E=Math.ceil(p*(100-g)/100)+g;e.progress(Math.min(E,100))},!1),a.onreadystatechange=function(){if(a.readyState===4){var m=a.response;try{m=JSON.parse(m)}catch{}var p=v.parseHeaders(a.getAllResponseHeaders()),E={body:m,code:a.status,headers:p};y(a.status)?t(E):s(E)}},a.send(e.data)})},w=function(e){return e.method="POST",u(e)},i=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(e.url&&typeof e.url!="string")throw new Error("Url must be a string");if(e.url=e.url||"",e.method&&typeof e.method!="string")throw new Error("`method` must be a string or null");if(e.method=e.method?e.method.toUpperCase():"GET",e.headers&&n(e.headers)!=="object")throw new Error("`headers` must be an object or null");if(e.headers=e.headers||{},e.type&&(typeof e.type!="string"||!Object.values(o).includes(e.type)))throw new Error("`type` must be taken from module's «contentType» library");if(e.progress&&typeof e.progress!="function")throw new Error("`progress` must be a function or null");if(e.progress=e.progress||function(t){},e.beforeSend=e.beforeSend||function(t){},e.ratio&&typeof e.ratio!="number")throw new Error("`ratio` must be a number");if(e.ratio<0||e.ratio>100)throw new Error("`ratio` must be in a 0-100 interval");if(e.ratio=e.ratio||90,e.accept&&typeof e.accept!="string")throw new Error("`accept` must be a string with a list of allowed mime-types");if(e.accept=e.accept||"*/*",e.multiple&&typeof e.multiple!="boolean")throw new Error("`multiple` must be a true or false");if(e.multiple=e.multiple||!1,e.fieldName&&typeof e.fieldName!="string")throw new Error("`fieldName` must be a string");return e.fieldName=e.fieldName||"files",e},f=function(e){switch(e.method){case"GET":var t=c(e.data,o.URLENCODED);delete e.data,e.url=/\?/.test(e.url)?e.url+"&"+t:e.url+"?"+t;break;case"POST":case"PUT":case"DELETE":case"UPDATE":var s=function(){return(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).type||o.JSON}(e);(v.isFormData(e.data)||v.isFormElement(e.data))&&(s=o.FORM),e.data=c(e.data,s),s!==b.contentType.FORM&&(e.headers["content-type"]=s)}return e},c=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};switch(arguments.length>1?arguments[1]:void 0){case o.URLENCODED:return v.urlEncode(e);case o.JSON:return v.jsonEncode(e);case o.FORM:return v.formEncode(e);default:return e}},y=function(e){return e>=200&&e<300},{contentType:o={URLENCODED:"application/x-www-form-urlencoded; charset=utf-8",FORM:"multipart/form-data",JSON:"application/json; charset=utf-8"},request:u,get:function(e){return e.method="GET",u(e)},post:w,transport:function(e){return e=i(e),v.selectFiles(e).then(function(t){for(var s=new FormData,a=0;a<t.length;a++)s.append(e.fieldName,t[a],t[a].name);v.isObject(e.data)&&Object.keys(e.data).forEach(function(m){var p=e.data[m];s.append(m,p)});var g=e.beforeSend;return e.beforeSend=function(){return g(t)},e.data=s,w(e)})},selectFiles:function(e){return delete(e=i(e)).beforeSend,v.selectFiles(e)}});d.exports=b},function(d,l,r){r.r(l);var n=r(1);window.Promise=window.Promise||n.a},function(d,l,r){(function(n){var o=n!==void 0&&n||typeof self<"u"&&self||window,u=Function.prototype.apply;function w(i,f){this._id=i,this._clearFn=f}l.setTimeout=function(){return new w(u.call(setTimeout,o,arguments),clearTimeout)},l.setInterval=function(){return new w(u.call(setInterval,o,arguments),clearInterval)},l.clearTimeout=l.clearInterval=function(i){i&&i.close()},w.prototype.unref=w.prototype.ref=function(){},w.prototype.close=function(){this._clearFn.call(o,this._id)},l.enroll=function(i,f){clearTimeout(i._idleTimeoutId),i._idleTimeout=f},l.unenroll=function(i){clearTimeout(i._idleTimeoutId),i._idleTimeout=-1},l._unrefActive=l.active=function(i){clearTimeout(i._idleTimeoutId);var f=i._idleTimeout;f>=0&&(i._idleTimeoutId=setTimeout(function(){i._onTimeout&&i._onTimeout()},f))},r(6),l.setImmediate=typeof self<"u"&&self.setImmediate||n!==void 0&&n.setImmediate||this&&this.setImmediate,l.clearImmediate=typeof self<"u"&&self.clearImmediate||n!==void 0&&n.clearImmediate||this&&this.clearImmediate}).call(this,r(0))},function(d,l,r){(function(n,o){(function(u,w){if(!u.setImmediate){var i,f,c,y,v,b=1,e={},t=!1,s=u.document,a=Object.getPrototypeOf&&Object.getPrototypeOf(u);a=a&&a.setTimeout?a:u,{}.toString.call(u.process)==="[object process]"?i=function(p){o.nextTick(function(){m(p)})}:function(){if(u.postMessage&&!u.importScripts){var p=!0,E=u.onmessage;return u.onmessage=function(){p=!1},u.postMessage("","*"),u.onmessage=E,p}}()?(y="setImmediate$"+Math.random()+"$",v=function(p){p.source===u&&typeof p.data=="string"&&p.data.indexOf(y)===0&&m(+p.data.slice(y.length))},u.addEventListener?u.addEventListener("message",v,!1):u.attachEvent("onmessage",v),i=function(p){u.postMessage(y+p,"*")}):u.MessageChannel?((c=new MessageChannel).port1.onmessage=function(p){m(p.data)},i=function(p){c.port2.postMessage(p)}):s&&"onreadystatechange"in s.createElement("script")?(f=s.documentElement,i=function(p){var E=s.createElement("script");E.onreadystatechange=function(){m(p),E.onreadystatechange=null,f.removeChild(E),E=null},f.appendChild(E)}):i=function(p){setTimeout(m,0,p)},a.setImmediate=function(p){typeof p!="function"&&(p=new Function(""+p));for(var E=new Array(arguments.length-1),_=0;_<E.length;_++)E[_]=arguments[_+1];var S={callback:p,args:E};return e[b]=S,i(b),b++},a.clearImmediate=g}function g(p){delete e[p]}function m(p){if(t)setTimeout(m,0,p);else{var E=e[p];if(E){t=!0;try{(function(_){var S=_.callback,C=_.args;switch(C.length){case 0:S();break;case 1:S(C[0]);break;case 2:S(C[0],C[1]);break;case 3:S(C[0],C[1],C[2]);break;default:S.apply(w,C)}})(E)}finally{g(p),t=!1}}}}})(typeof self>"u"?n===void 0?this:n:self)}).call(this,r(0),r(7))},function(d,l){var r,n,o=d.exports={};function u(){throw new Error("setTimeout has not been defined")}function w(){throw new Error("clearTimeout has not been defined")}function i(a){if(r===setTimeout)return setTimeout(a,0);if((r===u||!r)&&setTimeout)return r=setTimeout,setTimeout(a,0);try{return r(a,0)}catch{try{return r.call(null,a,0)}catch{return r.call(this,a,0)}}}(function(){try{r=typeof setTimeout=="function"?setTimeout:u}catch{r=u}try{n=typeof clearTimeout=="function"?clearTimeout:w}catch{n=w}})();var f,c=[],y=!1,v=-1;function b(){y&&f&&(y=!1,f.length?c=f.concat(c):v=-1,c.length&&e())}function e(){if(!y){var a=i(b);y=!0;for(var g=c.length;g;){for(f=c,c=[];++v<g;)f&&f[v].run();v=-1,g=c.length}f=null,y=!1,function(m){if(n===clearTimeout)return clearTimeout(m);if((n===w||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(m);try{n(m)}catch{try{return n.call(null,m)}catch{return n.call(this,m)}}}(a)}}function t(a,g){this.fun=a,this.array=g}function s(){}o.nextTick=function(a){var g=new Array(arguments.length-1);if(arguments.length>1)for(var m=1;m<arguments.length;m++)g[m-1]=arguments[m];c.push(new t(a,g)),c.length!==1||y||i(e)},t.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=s,o.addListener=s,o.once=s,o.off=s,o.removeListener=s,o.removeAllListeners=s,o.emit=s,o.prependListener=s,o.prependOnceListener=s,o.listeners=function(a){return[]},o.binding=function(a){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(a){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(d,l,r){function n(u,w){for(var i=0;i<w.length;i++){var f=w[i];f.enumerable=f.enumerable||!1,f.configurable=!0,"value"in f&&(f.writable=!0),Object.defineProperty(u,f.key,f)}}var o=r(9);d.exports=function(){function u(){(function(c,y){if(!(c instanceof y))throw new TypeError("Cannot call a class as a function")})(this,u)}var w,i,f;return w=u,f=[{key:"urlEncode",value:function(c){return o(c)}},{key:"jsonEncode",value:function(c){return JSON.stringify(c)}},{key:"formEncode",value:function(c){if(this.isFormData(c))return c;if(this.isFormElement(c))return new FormData(c);if(this.isObject(c)){var y=new FormData;return Object.keys(c).forEach(function(v){var b=c[v];y.append(v,b)}),y}throw new Error("`data` must be an instance of Object, FormData or <FORM> HTMLElement")}},{key:"isObject",value:function(c){return Object.prototype.toString.call(c)==="[object Object]"}},{key:"isFormData",value:function(c){return c instanceof FormData}},{key:"isFormElement",value:function(c){return c instanceof HTMLFormElement}},{key:"selectFiles",value:function(){var c=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return new Promise(function(y,v){var b=document.createElement("INPUT");b.type="file",c.multiple&&b.setAttribute("multiple","multiple"),c.accept&&b.setAttribute("accept",c.accept),b.style.display="none",document.body.appendChild(b),b.addEventListener("change",function(e){var t=e.target.files;y(t),document.body.removeChild(b)},!1),b.click()})}},{key:"parseHeaders",value:function(c){var y=c.trim().split(/[\r\n]+/),v={};return y.forEach(function(b){var e=b.split(": "),t=e.shift(),s=e.join(": ");t&&(v[t]=s)}),v}}],(i=null)&&n(w.prototype,i),f&&n(w,f),u}()},function(d,l){var r=function(o){return encodeURIComponent(o).replace(/[!'()*]/g,escape).replace(/%20/g,"+")},n=function(o,u,w,i){return u=u||null,w=w||"&",i=i||null,o?function(f){for(var c=new Array,y=0;y<f.length;y++)f[y]&&c.push(f[y]);return c}(Object.keys(o).map(function(f){var c,y,v=f;if(i&&(v=i+"["+v+"]"),typeof o[f]=="object"&&o[f]!==null)c=n(o[f],null,w,v);else{u&&(y=v,v=!isNaN(parseFloat(y))&&isFinite(y)?u+Number(v):v);var b=o[f];b=(b=(b=(b=b===!0?"1":b)===!1?"0":b)===0?"0":b)||"",c=r(v)+"="+r(b)}return c})).join(w).replace(/[!'()*]/g,""):""};d.exports=n}])})})(x);var I=x.exports;const M=O(I);class D{constructor({config:h,onUpload:d,onError:l}){this.config=h,this.onUpload=d,this.onError=l}uploadSelectedFile({onPreview:h}){let d;this.config.uploader&&typeof this.config.uploader.uploadByFile=="function"?d=M.selectFiles({accept:this.config.types}).then(l=>{h();const r=this.config.uploader.uploadByFile(l[0]);return R(r)||console.warn("Custom uploader method uploadByFile should return a Promise"),r}):d=M.transport({url:this.config.endpoint,accept:this.config.types,beforeSend:()=>h(),fieldName:this.config.field,headers:this.config.additionalRequestHeaders||{}}).then(l=>l.body),d.then(l=>{this.onUpload(l)}).catch(l=>{const r=l.body,n=r&&r.message?r.message:this.config.errorMessage;this.onError(n)})}}function R(T){return T&&typeof T.then=="function"}function F(T,h=null,d={}){const l=document.createElement(T);Array.isArray(h)?l.classList.add(...h):h&&l.classList.add(h);for(const r in d)l[r]=d[r];return l}function P(T){const h=document.createRange(),d=window.getSelection();h.selectNodeContents(T),h.collapse(!1),d.removeAllRanges(),d.addRange(h)}function j(T){return Object.keys(T).length===0}function A(T){return T===void 0?"":T.split(".").pop()}const U='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M7 10L11.8586 14.8586C11.9367 14.9367 12.0633 14.9367 12.1414 14.8586L17 10"/></svg>',k='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.3236 8.43554L9.49533 12.1908C9.13119 12.5505 8.93118 13.043 8.9393 13.5598C8.94741 14.0767 9.163 14.5757 9.53862 14.947C9.91424 15.3182 10.4191 15.5314 10.9422 15.5397C11.4653 15.5479 11.9637 15.3504 12.3279 14.9908L16.1562 11.2355C16.8845 10.5161 17.2845 9.53123 17.2682 8.4975C17.252 7.46376 16.8208 6.46583 16.0696 5.72324C15.3184 4.98066 14.3086 4.55425 13.2624 4.53782C12.2162 4.52138 11.2193 4.91627 10.4911 5.63562L6.66277 9.39093C5.57035 10.4699 4.97032 11.9473 4.99467 13.4979C5.01903 15.0485 5.66578 16.5454 6.79264 17.6592C7.9195 18.7731 9.43417 19.4127 11.0034 19.4374C12.5727 19.462 14.068 18.8697 15.1604 17.7907L18.9887 14.0354"/></svg>',N=500;class B{constructor({data:h,config:d,api:l,readOnly:r}){this.api=l,this.readOnly=r,this.nodes={wrapper:null,button:null,title:null},this._data={file:{},title:""},this.config={endpoint:d.endpoint||"",field:d.field||"file",types:d.types||"*",buttonText:d.buttonText||"Select file to upload",errorMessage:d.errorMessage||"File upload failed",uploader:d.uploader||void 0,additionalRequestHeaders:d.additionalRequestHeaders||{}},h!==void 0&&!j(h)&&(this.data=h),this.uploader=new D({config:this.config,onUpload:n=>this.onUpload(n),onError:n=>this.uploadingFailed(n)}),this.enableFileUpload=this.enableFileUpload.bind(this)}static get toolbox(){return{icon:k,title:"Attachment"}}static get isReadOnlySupported(){return!0}get CSS(){return{baseClass:this.api.styles.block,apiButton:this.api.styles.button,loader:this.api.styles.loader,wrapper:"cdx-attaches",wrapperWithFile:"cdx-attaches--with-file",wrapperLoading:"cdx-attaches--loading",button:"cdx-attaches__button",title:"cdx-attaches__title",size:"cdx-attaches__size",downloadButton:"cdx-attaches__download-button",fileInfo:"cdx-attaches__file-info",fileIcon:"cdx-attaches__file-icon",fileIconBackground:"cdx-attaches__file-icon-background",fileIconLabel:"cdx-attaches__file-icon-label"}}get EXTENSIONS(){return{doc:"#1483E9",docx:"#1483E9",odt:"#1483E9",pdf:"#DB2F2F",rtf:"#744FDC",tex:"#5a5a5b",txt:"#5a5a5b",pptx:"#E35200",ppt:"#E35200",mp3:"#eab456",mp4:"#f676a6",xls:"#11AE3D",html:"#2988f0",htm:"#2988f0",png:"#AA2284",jpg:"#D13359",jpeg:"#D13359",gif:"#f6af76",zip:"#4f566f",rar:"#4f566f",exe:"#e26f6f",svg:"#bf5252",key:"#00B2FF",sketch:"#FFC700",ai:"#FB601D",psd:"#388ae5",dmg:"#e26f6f",json:"#2988f0",csv:"#11AE3D"}}validate(h){return!j(h.file)}save(h){if(this.pluginHasData()){const d=h.querySelector(`.${this.CSS.title}`);d&&Object.assign(this.data,{title:d.innerHTML})}return this.data}render(){const h=F("div",this.CSS.baseClass);return this.nodes.wrapper=F("div",this.CSS.wrapper),this.pluginHasData()?this.showFileData():this.prepareUploadButton(),h.appendChild(this.nodes.wrapper),h}prepareUploadButton(){this.nodes.button=F("div",[this.CSS.apiButton,this.CSS.button]),this.nodes.button.innerHTML=`${k} ${this.config.buttonText}`,this.readOnly||this.nodes.button.addEventListener("click",this.enableFileUpload),this.nodes.wrapper.appendChild(this.nodes.button)}appendCallback(){this.nodes.button.click()}pluginHasData(){return this.data.title!==""||Object.values(this.data.file).some(h=>h!==void 0)}enableFileUpload(){this.uploader.uploadSelectedFile({onPreview:()=>{this.nodes.wrapper.classList.add(this.CSS.wrapperLoading,this.CSS.loader)}})}onUpload(h){const d=h;try{d.success&&d.file!==void 0&&!j(d.file)?(this.data={file:d.file,title:d.file.title||""},this.nodes.button.remove(),this.showFileData(),P(this.nodes.title),this.removeLoader()):this.uploadingFailed(this.config.errorMessage)}catch(l){console.error("Attaches tool error:",l),this.uploadingFailed(this.config.errorMessage)}this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex()).dispatchChange()}appendFileIcon(h){const l=h.extension||A(h.name),r=this.EXTENSIONS[l],n=4,o=F("div",this.CSS.fileIcon),u=F("div",this.CSS.fileIconBackground);if(r&&(u.style.backgroundColor=r),o.appendChild(u),l){let w=l;l.length>n&&(w=l.substring(0,n)+"…");const i=F("div",this.CSS.fileIconLabel,{textContent:w,title:l});r&&(i.style.backgroundColor=r),o.appendChild(i)}else u.innerHTML=k;this.nodes.wrapper.appendChild(o)}removeLoader(){setTimeout(()=>this.nodes.wrapper.classList.remove(this.CSS.wrapperLoading,this.CSS.loader),N)}showFileData(){this.nodes.wrapper.classList.add(this.CSS.wrapperWithFile);const{file:h,title:d}=this.data;this.appendFileIcon(h);const l=F("div",this.CSS.fileInfo);if(this.nodes.title=F("div",this.CSS.title,{contentEditable:this.readOnly===!1}),this.nodes.title.dataset.placeholder=this.api.i18n.t("File title"),this.nodes.title.textContent=d||"",l.appendChild(this.nodes.title),h.size){let r,n;const o=F("div",this.CSS.size);Math.log10(+h.size)>=6?(r="MiB",n=h.size/Math.pow(2,20)):(r="KiB",n=h.size/Math.pow(2,10)),o.textContent=n.toFixed(1),o.setAttribute("data-size",r),l.appendChild(o)}if(this.nodes.wrapper.appendChild(l),h.url!==void 0){const r=F("a",this.CSS.downloadButton,{innerHTML:U,href:h.url,target:"_blank"});this.nodes.wrapper.appendChild(r)}}uploadingFailed(h){this.api.notifier.show({message:h,style:"error"}),this.removeLoader()}get data(){return this._data}set data({file:h,title:d}){this._data={file:h,title:d}}}return B});
