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