From 10ff3ee2ec2a0b452bb169ce5059ce5f4a687d62 Mon Sep 17 00:00:00 2001
From: mostafaznv {this._updateLastFocusedEditableElement(),n?this._showBalloon():this._hideBalloon()})),e.ui.focusTracker.on("change:focusedElement",((e,t,n)=>{this._updateLastFocusedEditableElement(),n&&this._showBalloon()})),e.ui.on("update",(()=>{this._showBalloonThrottled()})))}_createBalloonView(){const e=this.editor,t=this._balloonView=new Lf,n=Xf(e),i=new Qf(e.locale,n.label);t.content.add(i),t.set({class:"ck-powered-by-balloon"}),e.ui.view.body.add(t),e.ui.focusTracker.add(t.element),this._balloonView=t}_showBalloon(){if(!this._lastFocusedEditableElement)return;const e=function(e,t){const n=Xf(e),i="right"===n.side?function(e,t){return Jf(e,t,((e,n)=>e.left+e.width-n.width-t.horizontalOffset))}(t,n):function(e,t){return Jf(e,t,(e=>e.left+t.horizontalOffset))}(t,n);return{target:t,positions:[i]}}(this.editor,this._lastFocusedEditableElement);e&&(this._balloonView||this._createBalloonView(),this._balloonView.pin(e))}_hideBalloon(){this._balloonView&&this._balloonView.unpin()}_updateLastFocusedEditableElement(){const e=this.editor,t=e.ui.focusTracker.isFocused,n=e.ui.focusTracker.focusedElement;if(!t||!n)return void(this._lastFocusedEditableElement=null);const i=Array.from(e.ui.getEditableElementsNames()).map((t=>e.ui.getEditableElement(t)));i.includes(n)?this._lastFocusedEditableElement=n:this._lastFocusedEditableElement=i[0]}}class Qf extends Qo{constructor(e,t){super(e);const n=new yr,i=this.bindTemplate;n.set({content:'\n',isColorInherited:!1}),n.extendTemplate({attributes:{style:{width:"53px",height:"10px"}}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-powered-by"],"aria-hidden":!0},children:[{tag:"a",attributes:{href:"https://ckeditor.com/?utm_source=ckeditor&utm_medium=referral&utm_campaign=701Dn000000hVgmIAE_powered_by_ckeditor_logo",target:"_blank",tabindex:"-1"},children:[...t?[{tag:"span",attributes:{class:["ck","ck-powered-by__label"]},children:[t]}]:[],n],on:{dragstart:i.to((e=>e.preventDefault()))}}]})}}function Jf(e,t,n){return(i,o)=>{const r=i.getVisible();if(!r)return Kf;if(i.width
").replace(/\r?\n/g,"
").replace(/\t/g," ").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ")).includes("
")||r.includes("
"))&&(r=`
${r}
`),e=r),o=this.editor.data.htmlProcessor.toView(e)}var r;const s=new p(this,"inputTransformation");this.fire(s,{content:o,dataTransfer:i,targetRanges:t.targetRanges,method:t.method}),s.stop.called&&e.stop(),n.scrollToTheSelection()}),{priority:"low"}),this.listenTo(this,"inputTransformation",((e,n)=>{if(n.content.isEmpty)return;const i=this.editor.data.toModel(n.content,"$clipboardHolder");0!=i.childCount&&(e.stop(),t.change((()=>{this.fire("contentInsertion",{content:i,method:n.method,dataTransfer:n.dataTransfer,targetRanges:n.targetRanges})})))}),{priority:"low"}),this.listenTo(this,"contentInsertion",((e,n)=>{n.resultRange=t.insertContent(n.content)}),{priority:"low"})}_setupCopyCut(){const e=this.editor,t=e.model.document,n=e.editing.view.document,i=(i,o)=>{const r=o.dataTransfer;o.preventDefault();const s=e.data.toView(e.model.getSelectedContent(t.selection));n.fire("clipboardOutput",{dataTransfer:r,content:s,method:i.name})};this.listenTo(n,"copy",i,{priority:"low"}),this.listenTo(n,"cut",((t,n)=>{e.model.canEditAt(e.model.document.selection)?i(t,n):n.preventDefault()}),{priority:"low"}),this.listenTo(n,"clipboardOutput",((n,i)=>{i.content.isEmpty||(i.dataTransfer.setData("text/html",this.editor.data.htmlProcessor.toData(i.content)),i.dataTransfer.setData("text/plain",$w(i.content))),"cut"==i.method&&e.model.deleteContent(t.selection)}),{priority:"low"})}}var Gw=n(3352),Kw={attributes:{"data-cke":!0}};Kw.setAttributes=$o(),Kw.insert=Zo().bind(null,"head"),Kw.domAPI=Ho(),Kw.insertStyleElement=Go();zo()(Gw.Z,Kw);Gw.Z&&Gw.Z.locals&&Gw.Z.locals;class Yw extends vs{static get pluginName(){return"DragDrop"}static get requires(){return[qw,Xp]}init(){const e=this.editor,t=e.editing.view;this._draggedRange=null,this._draggingUid="",this._draggableElement=null,this._updateDropMarkerThrottled=Wf((e=>this._updateDropMarker(e)),40),this._removeDropMarkerDelayed=Ro((()=>this._removeDropMarker()),40),this._clearDraggableAttributesDelayed=Ro((()=>this._clearDraggableAttributes()),40),e.plugins.has("DragDropExperimental")?this.forceDisabled("DragDropExperimental"):(t.addObserver(Zw),t.addObserver(Fh),this._setupDragging(),this._setupContentInsertionIntegration(),this._setupClipboardInputIntegration(),this._setupDropMarker(),this._setupDraggableAttributeHandling(),this.listenTo(e,"change:isReadOnly",((e,t,n)=>{n?this.forceDisabled("readOnlyMode"):this.clearForceDisabled("readOnlyMode")})),this.on("change:isEnabled",((e,t,n)=>{n||this._finalizeDragging(!1)})),c.isAndroid&&this.forceDisabled("noAndroidSupport"))}destroy(){return this._draggedRange&&(this._draggedRange.detach(),this._draggedRange=null),this._updateDropMarkerThrottled.cancel(),this._removeDropMarkerDelayed.cancel(),this._clearDraggableAttributesDelayed.cancel(),super.destroy()}_setupDragging(){const e=this.editor,t=e.model,n=t.document,i=e.editing.view,o=i.document;this.listenTo(o,"dragstart",((i,r)=>{const s=n.selection;if(r.target&&r.target.is("editableElement"))return void r.preventDefault();const a=r.target?Xw(r.target):null;if(a){const n=e.editing.mapper.toModelElement(a);if(this._draggedRange=gd.fromRange(t.createRangeOn(n)),e.plugins.has("WidgetToolbarRepository")){e.plugins.get("WidgetToolbarRepository").forceDisabled("dragDrop")}}else if(!o.selection.isCollapsed){const e=o.selection.getSelectedElement();e&&Op(e)||(this._draggedRange=gd.fromRange(s.getFirstRange()))}if(!this._draggedRange)return void r.preventDefault();this._draggingUid=w();const l=this.isEnabled&&e.model.canEditAt(this._draggedRange);r.dataTransfer.effectAllowed=l?"copyMove":"copy",r.dataTransfer.setData("application/ckeditor5-dragging-uid",this._draggingUid);const c=t.createSelection(this._draggedRange.toRange()),d=e.data.toView(t.getSelectedContent(c));o.fire("clipboardOutput",{dataTransfer:r.dataTransfer,content:d,method:"dragstart"}),l||(this._draggedRange.detach(),this._draggedRange=null,this._draggingUid="")}),{priority:"low"}),this.listenTo(o,"dragend",((e,t)=>{this._finalizeDragging(!t.dataTransfer.isCanceled&&"move"==t.dataTransfer.dropEffect)}),{priority:"low"}),this.listenTo(o,"dragenter",(()=>{this.isEnabled&&i.focus()})),this.listenTo(o,"dragleave",(()=>{this._removeDropMarkerDelayed()})),this.listenTo(o,"dragging",((t,n)=>{if(!this.isEnabled)return void(n.dataTransfer.dropEffect="none");this._removeDropMarkerDelayed.cancel();const i=Qw(e,n.targetRanges,n.target);e.model.canEditAt(i)?(this._draggedRange||(n.dataTransfer.dropEffect="copy"),c.isGecko||("copy"==n.dataTransfer.effectAllowed?n.dataTransfer.dropEffect="copy":["all","copyMove"].includes(n.dataTransfer.effectAllowed)&&(n.dataTransfer.dropEffect="move")),i&&this._updateDropMarkerThrottled(i)):n.dataTransfer.dropEffect="none"}),{priority:"low"})}_setupClipboardInputIntegration(){const e=this.editor,t=e.editing.view.document;this.listenTo(t,"clipboardInput",((t,n)=>{if("drop"!=n.method)return;const i=Qw(e,n.targetRanges,n.target);if(this._removeDropMarker(),!i||!e.model.canEditAt(i))return this._finalizeDragging(!1),void t.stop();this._draggedRange&&this._draggingUid!=n.dataTransfer.getData("application/ckeditor5-dragging-uid")&&(this._draggedRange.detach(),this._draggedRange=null,this._draggingUid="");if("move"==Jw(n.dataTransfer)&&this._draggedRange&&this._draggedRange.containsRange(i,!0))return this._finalizeDragging(!1),void t.stop();n.targetRanges=[e.editing.mapper.toViewRange(i)]}),{priority:"high"})}_setupContentInsertionIntegration(){const e=this.editor.plugins.get(qw);e.on("contentInsertion",((e,t)=>{if(!this.isEnabled||"drop"!==t.method)return;const n=t.targetRanges.map((e=>this.editor.editing.mapper.toModelRange(e)));this.editor.model.change((e=>e.setSelection(n)))}),{priority:"high"}),e.on("contentInsertion",((e,t)=>{if(!this.isEnabled||"drop"!==t.method)return;const n="move"==Jw(t.dataTransfer),i=!t.resultRange||!t.resultRange.isCollapsed;this._finalizeDragging(i&&n)}),{priority:"lowest"})}_setupDraggableAttributeHandling(){const e=this.editor,t=e.editing.view,n=t.document;this.listenTo(n,"mousedown",((i,o)=>{if(c.isAndroid||!o)return;this._clearDraggableAttributesDelayed.cancel();let r=Xw(o.target);if(c.isBlink&&!r&&!n.selection.isCollapsed){const e=n.selection.getSelectedElement();if(!e||!Op(e)){const e=n.selection.editableElement;e&&!e.isReadOnly&&(r=e)}}r&&(t.change((e=>{e.setAttribute("draggable","true",r)})),this._draggableElement=e.editing.mapper.toModelElement(r))})),this.listenTo(n,"mouseup",(()=>{c.isAndroid||this._clearDraggableAttributesDelayed()}))}_clearDraggableAttributes(){const e=this.editor.editing;e.view.change((t=>{this._draggableElement&&"$graveyard"!=this._draggableElement.root.rootName&&t.removeAttribute("draggable",e.mapper.toViewElement(this._draggableElement)),this._draggableElement=null}))}_setupDropMarker(){const e=this.editor;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:n})=>{if(e.model.schema.checkChild(t.markerRange.start,"$text"))return n.createUIElement("span",{class:"ck ck-clipboard-drop-target-position"},(function(e){const t=this.toDomElement(e);return t.append("",e.createElement("span"),""),t}))}})}_updateDropMarker(e){const t=this.editor,n=t.model.markers;t.model.change((t=>{n.has("drop-target")?n.get("drop-target").getRange().isEqual(e)||t.updateMarker("drop-target",{range:e}):t.addMarker("drop-target",{range:e,usingOperation:!1,affectsData:!1})}))}_removeDropMarker(){const e=this.editor.model;this._removeDropMarkerDelayed.cancel(),this._updateDropMarkerThrottled.cancel(),e.markers.has("drop-target")&&e.change((e=>{e.removeMarker("drop-target")}))}_finalizeDragging(e){const t=this.editor,n=t.model;if(this._removeDropMarker(),this._clearDraggableAttributes(),t.plugins.has("WidgetToolbarRepository")){t.plugins.get("WidgetToolbarRepository").clearForceDisabled("dragDrop")}this._draggingUid="",this._draggedRange&&(e&&this.isEnabled&&n.deleteContent(n.createSelection(this._draggedRange),{doNotAutoparagraph:!0}),this._draggedRange.detach(),this._draggedRange=null)}}function Qw(e,t,n){const i=e.model,o=e.editing.mapper;let r=null;const s=t?t[0].start:null;if(n.is("uiElement")&&(n=n.parent),r=function(e,t){const n=e.model,i=e.editing.mapper;if(Op(t))return n.createRangeOn(i.toModelElement(t));if(!t.is("editableElement")){const e=t.findAncestor((e=>Op(e)||e.is("editableElement")));if(Op(e))return n.createRangeOn(i.toModelElement(e))}return null}(e,n),r)return r;const a=function(e,t){const n=e.editing.mapper,i=e.editing.view,o=n.toModelElement(t);if(o)return o;const r=i.createPositionBefore(t),s=n.findMappedViewAncestor(r);return n.toModelElement(s)}(e,n),l=s?o.toModelPosition(s):null;return l?(r=function(e,t,n){const i=e.model;if(!i.schema.checkChild(n,"$block"))return null;const o=i.createPositionAt(n,0),r=t.path.slice(0,o.path.length),s=i.createPositionFromPath(t.root,r),a=s.nodeAfter;if(a&&i.schema.isObject(a))return i.createRangeOn(a);return null}(e,l,a),r||(r=i.schema.getNearestSelectionRange(l,c.isGecko?"forward":"backward"),r||function(e,t){const n=e.model;let i=t;for(;i;){if(n.schema.isObject(i))return n.createRangeOn(i);i=i.parent}return null}(e,l.parent))):function(e,t){const n=e.model,i=n.schema,o=n.createPositionAt(t,0);return i.getNearestSelectionRange(o,"forward")}(e,a)}function Jw(e){return c.isGecko?e.dropEffect:["all","copyMove"].includes(e.effectAllowed)?"move":"copy"}function Xw(e){if(e.is("editableElement"))return null;if(e.hasClass("ck-widget__selection-handle"))return e.findAncestor(Op);if(Op(e))return e;const t=e.findAncestor((e=>Op(e)||e.is("editableElement")));return Op(t)?t:null}class ek extends vs{static get pluginName(){return"PastePlainText"}static get requires(){return[qw]}init(){const e=this.editor,t=e.model,n=e.editing.view,i=n.document,o=t.document.selection;let r=!1;n.addObserver(Zw),this.listenTo(i,"keydown",((e,t)=>{r=t.shiftKey})),e.plugins.get(qw).on("contentInsertion",((e,n)=>{(r||function(e,t){if(e.childCount>1)return!1;const n=e.getChild(0);if(t.isObject(n))return!1;return 0==Array.from(n.getAttributeKeys()).length}(n.content,t.schema))&&t.change((e=>{const i=Array.from(o.getAttributes()).filter((([e])=>t.schema.getAttributeProperties(e).isFormatting));o.isCollapsed||t.deleteContent(o,{doNotAutoparagraph:!0}),i.push(...o.getAttributes());const r=e.createRangeIn(n.content);for(const t of r.getItems())t.is("$textProxy")&&e.setAttributes(i,t)}))}))}}class tk extends vs{static get pluginName(){return"Clipboard"}static get requires(){return[qw,Yw,ek]}}Ki("px");class nk extends As{constructor(e){super(e),this.affectsData=!1}execute(){const e=this.editor.model,t=e.document.selection;let n=e.schema.getLimitElement(t);if(t.containsEntireContent(n)||!ik(e.schema,n))do{if(n=n.parent,!n)return}while(!ik(e.schema,n));e.change((e=>{e.setSelection(n,"in")}))}}function ik(e,t){return e.isLimit(t)&&(e.checkChild(t,"$text")||e.checkChild(t,"paragraph"))}const ok=_o("Ctrl+A");class rk extends vs{static get pluginName(){return"SelectAllEditing"}init(){const e=this.editor,t=e.editing.view.document;e.commands.add("selectAll",new nk(e)),this.listenTo(t,"keydown",((t,n)=>{ko(n)===ok&&(e.execute("selectAll"),n.preventDefault())}))}}class sk extends vs{static get pluginName(){return"SelectAllUI"}init(){const e=this.editor;e.ui.componentFactory.add("selectAll",(t=>{const n=e.commands.get("selectAll"),i=new Er(t),o=t.t;return i.set({label:o("Select all"),icon:'',keystroke:"Ctrl+A",tooltip:!0}),i.bind("isEnabled").to(n,"isEnabled"),this.listenTo(i,"execute",(()=>{e.execute("selectAll"),e.editing.view.focus()})),i}))}}class ak extends vs{static get requires(){return[rk,sk]}static get pluginName(){return"SelectAll"}}class lk extends As{constructor(e){super(e),this._stack=[],this._createdBatches=new WeakSet,this.refresh(),this._isEnabledBasedOnSelection=!1,this.listenTo(e.data,"set",((e,t)=>{t[1]={...t[1]};const n=t[1];n.batchType||(n.batchType={isUndoable:!1})}),{priority:"high"}),this.listenTo(e.data,"set",((e,t)=>{t[1].batchType.isUndoable||this.clearStack()}))}refresh(){this.isEnabled=this._stack.length>0}get createdBatches(){return this._createdBatches}addBatch(e){const t=this.editor.model.document.selection,n={ranges:t.hasOwnRange?Array.from(t.getRanges()):[],isBackward:t.isBackward};this._stack.push({batch:e,selection:n}),this.refresh()}clearStack(){this._stack=[],this.refresh()}_restoreSelection(e,t,n){const i=this.editor.model,o=i.document,r=[],s=e.map((e=>e.getTransformedByOperations(n))),a=s.flat();for(const e of s){const t=e.filter((e=>e.root!=o.graveyard)).filter((e=>!dk(e,a)));t.length&&(ck(t),r.push(t[0]))}r.length&&i.change((e=>{e.setSelection(r,{backward:t})}))}_undo(e,t){const n=this.editor.model,i=n.document;this._createdBatches.add(t);const o=e.operations.slice().filter((e=>e.isDocumentOperation));o.reverse();for(const e of o){const o=e.baseVersion+1,r=Array.from(i.history.getOperations(o)),s=qu([e.getReversed()],r,{useRelations:!0,document:this.editor.model.document,padWithNoOps:!1,forceWeakRemove:!0}).operationsA;for(let o of s){const r=o.affectedSelectable;r&&!n.canEditAt(r)&&(o=new Lu(o.baseVersion)),t.addOperation(o),n.applyOperation(o),i.history.setOperationAsUndone(e,o)}}}}function ck(e){e.sort(((e,t)=>e.start.isBefore(t.start)?-1:1));for(let t=1;t