"+(r.trim()?r:n)+"
");const a=Object.keys(this.toolsTags).reduce((p,h)=>(p[h.toLowerCase()]=this.toolsTags[h].sanitizationConfig??{},p),{}),l=Object.assign({},a,e.getAllInlineToolsSanitizeConfig(),{br:{}}),c=Z(r,l);!c.trim()||c.trim()===n||!d.isHTMLString(c)?await this.processText(n):await this.processText(c,!0)}async processText(s,t=!1){const{Caret:e,BlockManager:o}=this.Editor,i=t?this.processHTML(s):this.processPlain(s);if(!i.length)return;if(i.length===1){i[0].isBlock?this.processSingleBlock(i.pop()):this.processInlinePaste(i.pop());return}const n=o.currentBlock&&o.currentBlock.tool.isDefault&&o.currentBlock.isEmpty;i.map(async(r,a)=>this.insertBlock(r,a===0&&n)),o.currentBlock&&e.setToBlock(o.currentBlock,e.positions.END)}setCallback(){this.listeners.on(this.Editor.UI.nodes.holder,"paste",this.handlePasteEvent)}unsetCallback(){this.listeners.off(this.Editor.UI.nodes.holder,"paste",this.handlePasteEvent)}processTools(){const s=this.Editor.Tools.blockTools;Array.from(s.values()).forEach(this.processTool)}collectTagNames(s){return J(s)?[s]:z(s)?Object.keys(s):[]}getTagsConfig(s){if(s.pasteConfig===!1)return;const t=s.pasteConfig.tags||[],e=[];t.forEach(o=>{const i=this.collectTagNames(o);e.push(...i),i.forEach(n=>{if(Object.prototype.hasOwnProperty.call(this.toolsTags,n)){T(`Paste handler for «${s.name}» Tool on «${n}» tag is skipped because it is already used by «${this.toolsTags[n].tool.name}» Tool.`,"warn");return}const r=z(o)?o[n]:null;this.toolsTags[n.toUpperCase()]={tool:s,sanitizationConfig:r}})}),this.tagsByTool[s.name]=e.map(o=>o.toUpperCase())}getFilesConfig(s){if(s.pasteConfig===!1)return;const{files:t={}}=s.pasteConfig;let{extensions:e,mimeTypes:o}=t;!e&&!o||(e&&!Array.isArray(e)&&(T(`«extensions» property of the onDrop config for «${s.name}» Tool should be an array`),e=[]),o&&!Array.isArray(o)&&(T(`«mimeTypes» property of the onDrop config for «${s.name}» Tool should be an array`),o=[]),o&&(o=o.filter(i=>Ye(i)?!0:(T(`MIME type value «${i}» for the «${s.name}» Tool is not a valid MIME type`,"warn"),!1))),this.toolsFiles[s.name]={extensions:e||[],mimeTypes:o||[]})}getPatternsConfig(s){s.pasteConfig===!1||!s.pasteConfig.patterns||V(s.pasteConfig.patterns)||Object.entries(s.pasteConfig.patterns).forEach(([t,e])=>{e instanceof RegExp||T(`Pattern ${e} for «${s.name}» Tool is skipped because it should be a Regexp instance.`,"warn"),this.toolsPatterns.push({key:t,pattern:e,tool:s})})}isNativeBehaviour(s){return d.isNativeInput(s)}async processFiles(s){const{BlockManager:t}=this.Editor;let e;e=await Promise.all(Array.from(s).map(i=>this.processFile(i))),e=e.filter(i=>!!i);const o=t.currentBlock.tool.isDefault&&t.currentBlock.isEmpty;e.forEach((i,n)=>{t.paste(i.type,i.event,n===0&&o)})}async processFile(s){const t=$e(s),e=Object.entries(this.toolsFiles).find(([i,{mimeTypes:n,extensions:r}])=>{const[a,l]=s.type.split("/"),c=r.find(h=>h.toLowerCase()===t.toLowerCase()),p=n.find(h=>{const[f,k]=h.split("/");return f===a&&(k===l||k==="*")});return!!c||!!p});if(!e)return;const[o]=e;return{event:this.composePasteEvent("file",{file:s}),type:o}}processHTML(s){const{Tools:t}=this.Editor,e=d.make("DIV");return e.innerHTML=s,this.getNodes(e).map(o=>{let i,n=t.defaultTool,r=!1;switch(o.nodeType){case Node.DOCUMENT_FRAGMENT_NODE:i=d.make("div"),i.appendChild(o);break;case Node.ELEMENT_NODE:i=o,r=!0,this.toolsTags[i.tagName]&&(n=this.toolsTags[i.tagName].tool);break}const{tags:a}=n.pasteConfig||{tags:[]},l=a.reduce((h,f)=>(this.collectTagNames(f).forEach(k=>{const u=z(f)?f[k]:null;h[k.toLowerCase()]=u||{}}),h),{}),c=Object.assign({},l,n.baseSanitizeConfig);if(i.tagName.toLowerCase()==="table"){const h=Z(i.outerHTML,c);i=d.make("div",void 0,{innerHTML:h}).firstChild}else i.innerHTML=Z(i.innerHTML,c);const p=this.composePasteEvent("tag",{data:i});return{content:i,isBlock:r,tool:n.name,event:p}}).filter(o=>{const i=d.isEmpty(o.content),n=d.isSingleTag(o.content);return!i||n})}processPlain(s){const{defaultBlock:t}=this.config;if(!s)return[];const e=t;return s.split(/\r?\n/).filter(o=>o.trim()).map(o=>{const i=d.make("div");i.textContent=o;const n=this.composePasteEvent("tag",{data:i});return{content:i,tool:e,isBlock:!1,event:n}})}async processSingleBlock(s){const{Caret:t,BlockManager:e}=this.Editor,{currentBlock:o}=e;if(!o||s.tool!==o.name||!d.containsOnlyInlineElements(s.content.innerHTML)){this.insertBlock(s,(o==null?void 0:o.tool.isDefault)&&o.isEmpty);return}t.insertContentAtCaretPosition(s.content.innerHTML)}async processInlinePaste(s){const{BlockManager:t,Caret:e}=this.Editor,{content:o}=s;if(t.currentBlock&&t.currentBlock.tool.isDefault&&o.textContent.length