From 2b23ff3eb8dac6acc570b1aaa6e0baff72dd17ea Mon Sep 17 00:00:00 2001
From: smizrahi
").replace(/\r?\n/g,"
").replace(/\t/g," ").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ");if(t.includes("
")||t.includes("
")){t=`
${t}
`}return t}function VM(t){return t.replace(/(\s+)<\/span>/g,((t,e)=>{if(e.length==1){return" "}return e})).replace(//g,"")}const FM=["figcaption","li"];const jM=["ol","ul"];function HM(t){if(t.is("$text")||t.is("$textProxy")){return t.data}if(t.is("element","img")&&t.hasAttribute("alt")){return t.getAttribute("alt")}if(t.is("element","br")){return"\n"}let e="";let n=null;for(const i of t.getChildren()){e+=UM(i,n)+HM(i);n=i}return e}function UM(t,e){if(!e){return""}if(t.is("element","li")&&!t.isEmpty&&t.getChild(0).is("containerElement")){return"\n\n"}if(jM.includes(t.name)&&jM.includes(e.name)){return"\n\n"}if(!t.is("containerElement")&&!e.is("containerElement")){return""}if(FM.includes(t.name)||FM.includes(e.name)){return"\n"}return"\n\n"}class WM extends bh{static get pluginName(){return"ClipboardPipeline"}init(){const t=this.editor;const e=t.editing.view;e.addObserver(zM);this._setupPasteDrop();this._setupCopyCut()}_fireOutputTransformationEvent(t,e,n){const i=this.editor.model.getSelectedContent(e);this.fire("outputTransformation",{dataTransfer:t,content:i,method:n})}_setupPasteDrop(){const t=this.editor;const e=t.model;const n=t.editing.view;const i=n.document;this.listenTo(i,"clipboardInput",((e,n)=>{if(n.method=="paste"&&!t.model.canEditAt(t.model.document.selection)){e.stop()}}),{priority:"highest"});this.listenTo(i,"clipboardInput",((t,e)=>{const i=e.dataTransfer;let o;if(e.content){o=e.content}else{let t="";if(i.getData("text/html")){t=VM(i.getData("text/html"))}else if(i.getData("text/plain")){t=OM(i.getData("text/plain"))}o=this.editor.data.htmlProcessor.toView(t)}const r=new D(this,"inputTransformation");this.fire(r,{content:o,dataTransfer:i,targetRanges:e.targetRanges,method:e.method});if(r.stop.called){t.stop()}n.scrollToTheSelection()}),{priority:"low"});this.listenTo(this,"inputTransformation",((t,n)=>{if(n.content.isEmpty){return}const i=this.editor.data;const o=i.toModel(n.content,"$clipboardHolder");if(o.childCount==0){return}t.stop();e.change((()=>{this.fire("contentInsertion",{content:o,method:n.method,dataTransfer:n.dataTransfer,targetRanges:n.targetRanges})}))}),{priority:"low"});this.listenTo(this,"contentInsertion",((t,n)=>{n.resultRange=e.insertContent(n.content)}),{priority:"low"})}_setupCopyCut(){const t=this.editor;const e=t.model.document;const n=t.editing.view;const i=n.document;const o=(t,n)=>{const i=n.dataTransfer;n.preventDefault();this._fireOutputTransformationEvent(i,e.selection,t.name)};this.listenTo(i,"copy",o,{priority:"low"});this.listenTo(i,"cut",((e,n)=>{if(!t.model.canEditAt(t.model.document.selection)){n.preventDefault()}else{o(e,n)}}),{priority:"low"});this.listenTo(this,"outputTransformation",((e,n)=>{const o=t.data.toView(n.content);i.fire("clipboardOutput",{dataTransfer:n.dataTransfer,content:o,method:n.method})}),{priority:"low"});this.listenTo(i,"clipboardOutput",((n,i)=>{if(!i.content.isEmpty){i.dataTransfer.setData("text/html",this.editor.data.htmlProcessor.toData(i.content));i.dataTransfer.setData("text/plain",HM(i.content))}if(i.method=="cut"){t.model.deleteContent(e.selection)}}),{priority:"low"})}}class qM extends($()){constructor(){super(...arguments);this._stack=[]}add(t,e){const n=this._stack;const i=n[0];this._insertDescriptor(t);const o=n[0];if(i!==o&&!GM(i,o)){this.fire("change:top",{oldDescriptor:i,newDescriptor:o,writer:e})}}remove(t,e){const n=this._stack;const i=n[0];this._removeDescriptor(t);const o=n[0];if(i!==o&&!GM(i,o)){this.fire("change:top",{oldDescriptor:i,newDescriptor:o,writer:e})}}_insertDescriptor(t){const e=this._stack;const n=e.findIndex((e=>e.id===t.id));if(GM(t,e[n])){return}if(n>-1){e.splice(n,1)}let i=0;while(e[i]&&$M(e[i],t)){i++}e.splice(i,0,t)}_removeDescriptor(t){const e=this._stack;const n=e.findIndex((e=>e.id===t));if(n>-1){e.splice(n,1)}}}function GM(t,e){return t&&e&&t.priority==e.priority&&KM(t.classes)==KM(e.classes)}function $M(t,e){if(t.priority>e.priority){return true}else if(t.priority