From 2c8d85fbd1245416fac88001a5edaf0625ff926b Mon Sep 17 00:00:00 2001
From: mostafaznv
").replace(/\r?\n/g,"
").replace(/\t/g," ").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ")).includes("
")||o.includes("
"))&&(o=`
${o}
`),e=o),n=this.editor.data.htmlProcessor.toView(e)}var o;const s=new f(this,"inputTransformation");this.fire(s,{content:n,dataTransfer:r,targetRanges:t.targetRanges,method:t.method}),s.stop.called&&e.stop(),i.scrollToTheSelection()}),{priority:"low"}),this.listenTo(this,"inputTransformation",((e,i)=>{if(i.content.isEmpty)return;const r=this.editor.data.toModel(i.content,"$clipboardHolder");0!=r.childCount&&(e.stop(),t.change((()=>{this.fire("contentInsertion",{content:r,method:i.method,dataTransfer:i.dataTransfer,targetRanges:i.targetRanges})})))}),{priority:"low"}),this.listenTo(this,"contentInsertion",((e,i)=>{i.resultRange=t.insertContent(i.content)}),{priority:"low"})}_setupCopyCut(){const e=this.editor,t=e.model.document,i=e.editing.view.document,r=(e,i)=>{const r=i.dataTransfer;i.preventDefault(),this._fireOutputTransformationEvent(r,t.selection,e.name)};this.listenTo(i,"copy",r,{priority:"low"}),this.listenTo(i,"cut",((t,i)=>{e.model.canEditAt(e.model.document.selection)?r(t,i):i.preventDefault()}),{priority:"low"}),this.listenTo(this,"outputTransformation",((t,r)=>{const n=e.data.toView(r.content);i.fire("clipboardOutput",{dataTransfer:r.dataTransfer,content:n,method:r.method})}),{priority:"low"}),this.listenTo(i,"clipboardOutput",((i,r)=>{r.content.isEmpty||(r.dataTransfer.setData("text/html",this.editor.data.htmlProcessor.toData(r.content)),r.dataTransfer.setData("text/plain",Lk(r.content))),"cut"==r.method&&e.model.deleteContent(t.selection)}),{priority:"low"})}}const jk=qr("px");class zk extends Kn{constructor(){super();const e=this.bindTemplate;this.set({isVisible:!1,left:null,top:null,width:null}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-clipboard-drop-target-line",e.if("isVisible","ck-hidden",(e=>!e))],style:{left:e.to("left",(e=>jk(e))),top:e.to("top",(e=>jk(e))),width:e.to("width",(e=>jk(e)))}}})}}class Hk extends xs{constructor(){super(...arguments),this.removeDropMarkerDelayed=In((()=>this.removeDropMarker()),40),this._updateDropMarkerThrottled=rp((e=>this._updateDropMarker(e)),40),this._reconvertMarkerThrottled=rp((()=>{this.editor.model.markers.has("drop-target")&&this.editor.editing.reconvertMarker("drop-target")}),0),this._dropTargetLineView=new zk,this._domEmitter=new(Pr()),this._scrollables=new Map}static get pluginName(){return"DragDropTarget"}init(){this._setupDropMarker()}destroy(){this._domEmitter.stopListening();for(const{resizeObserver:e}of this._scrollables.values())e.destroy();return this._updateDropMarkerThrottled.cancel(),this.removeDropMarkerDelayed.cancel(),this._reconvertMarkerThrottled.cancel(),super.destroy()}updateDropMarker(e,t,i,r,n,o){this.removeDropMarkerDelayed.cancel();const s=Uk(this.editor,e,t,i,r,n,o);if(s)return o&&o.containsRange(s)?this.removeDropMarker():void this._updateDropMarkerThrottled(s)}getFinalDropRange(e,t,i,r,n,o){const s=Uk(this.editor,e,t,i,r,n,o);return this.removeDropMarker(),s}removeDropMarker(){const e=this.editor.model;this.removeDropMarkerDelayed.cancel(),this._updateDropMarkerThrottled.cancel(),this._dropTargetLineView.isVisible=!1,e.markers.has("drop-target")&&e.change((e=>{e.removeMarker("drop-target")}))}_setupDropMarker(){const e=this.editor;e.ui.view.body.add(this._dropTargetLineView),e.conversion.for("editingDowncast").markerToHighlight({model:"drop-target",view:{classes:["ck-clipboard-drop-target-range"]}}),e.conversion.for("editingDowncast").markerToElement({model:"drop-target",view:(t,{writer:i})=>{if(e.model.schema.checkChild(t.markerRange.start,"$text"))return this._dropTargetLineView.isVisible=!1,this._createDropTargetPosition(i);t.markerRange.isCollapsed?this._updateDropTargetLine(t.markerRange):this._dropTargetLineView.isVisible=!1}})}_updateDropMarker(e){const t=this.editor,i=t.model.markers;t.model.change((t=>{i.has("drop-target")?i.get("drop-target").getRange().isEqual(e)||t.updateMarker("drop-target",{range:e}):t.addMarker("drop-target",{range:e,usingOperation:!1,affectsData:!1})}))}_createDropTargetPosition(e){return e.createUIElement("span",{class:"ck ck-clipboard-drop-target-position"},(function(e){const t=this.toDomElement(e);return t.append("",e.createElement("span"),""),t}))}_updateDropTargetLine(e){const t=this.editor.editing,i=e.start.nodeBefore,r=e.start.nodeAfter,n=e.start.parent,o=i?t.mapper.toViewElement(i):null,s=o?t.view.domConverter.mapViewToDom(o):null,a=r?t.mapper.toViewElement(r):null,c=a?t.view.domConverter.mapViewToDom(a):null,l=t.mapper.toViewElement(n),d=t.view.domConverter.mapViewToDom(l),u=this._getScrollableRect(l),{scrollX:h,scrollY:m}=Nr.window,g=s?new Fr(s):null,p=c?new Fr(c):null,f=new Fr(d).excludeScrollbarsAndBorders(),b=g?g.bottom:f.top,w=p?p.top:f.bottom,k=Nr.window.getComputedStyle(d),v=b<=w?(b+w)/2:w;if(u.top