From 7f9d2ba5837364489d26ab10c612099b3421f490 Mon Sep 17 00:00:00 2001
From: yuepeng
").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ");if(t.indexOf("
")>-1){t=`
${t}
`}return t}function DA(t){return t.replace(/(\s+)<\/span>/g,(t,e)=>{if(e.length==1){return" "}return e})}const VA=["figcaption","li"];function jA(t){let e="";if(t.is("text")||t.is("textProxy")){e=t.data}else if(t.is("img")&&t.hasAttribute("alt")){e=t.getAttribute("alt")}else{let n=null;for(const i of t.getChildren()){const t=jA(i);if(n&&(n.is("containerElement")||i.is("containerElement"))){if(VA.includes(n.name)||VA.includes(i.name)){e+="\n"}else{e+="\n\n"}}e+=t;n=i}}return e}class zA extends ww{static get pluginName(){return"Clipboard"}init(){const t=this.editor;const e=t.model.document;const n=t.editing.view;const i=n.document;this._htmlDataProcessor=new bp;n.addObserver(OA);this.listenTo(i,"clipboardInput",e=>{if(t.isReadOnly){e.stop()}},{priority:"highest"});this.listenTo(i,"clipboardInput",(t,e)=>{const i=e.dataTransfer;let o="";if(i.getData("text/html")){o=DA(i.getData("text/html"))}else if(i.getData("text/plain")){o=LA(i.getData("text/plain"))}o=this._htmlDataProcessor.toView(o);this.fire("inputTransformation",{content:o,dataTransfer:i});n.scrollToTheSelection()},{priority:"low"});this.listenTo(this,"inputTransformation",(t,e)=>{if(!e.content.isEmpty){const t=this.editor.data;const n=this.editor.model;const i=t.toModel(e.content,"$clipboardHolder");if(i.childCount==0){return}n.insertContent(i)}},{priority:"low"});function o(n,o){const s=o.dataTransfer;o.preventDefault();const r=t.data.toView(t.model.getSelectedContent(e.selection));i.fire("clipboardOutput",{dataTransfer:s,content:r,method:n.name})}this.listenTo(i,"copy",o,{priority:"low"});this.listenTo(i,"cut",(e,n)=>{if(t.isReadOnly){n.preventDefault()}else{o(e,n)}},{priority:"low"});this.listenTo(i,"clipboardOutput",(n,i)=>{if(!i.content.isEmpty){i.dataTransfer.setData("text/html",this._htmlDataProcessor.toData(i.content));i.dataTransfer.setData("text/plain",jA(i.content))}if(i.method=="cut"){t.model.deleteContent(e.selection)}},{priority:"low"})}}class BA{createDocumentFragment(t){return new Wl(t)}createElement(t,e,n){return new Vc(t,e,n)}createText(t){return new jr(t)}clone(t,e=false){return t._clone(e)}appendChild(t,e){return e._appendChild(t)}insertChild(t,e,n){return n._insertChild(t,e)}removeChildren(t,e,n){return n._removeChildren(t,e)}remove(t){const e=t.parent;if(e){return this.removeChildren(e.getChildIndex(t),1,e)}return[]}replace(t,e){const n=t.parent;if(n){const i=n.getChildIndex(t);this.removeChildren(i,1,n);this.insertChild(i,e,n);return true}return false}unwrapElement(t){const e=t.parent;if(e){const n=e.getChildIndex(t);this.remove(t);this.insertChild(n,t.getChildren(),e)}}rename(t,e){const n=new Vc(t,e.getAttributes(),e.getChildren());return this.replace(e,n)?n:null}setAttribute(t,e,n){n._setAttribute(t,e)}removeAttribute(t,e){e._removeAttribute(t)}addClass(t,e){e._addClass(t)}removeClass(t,e){e._removeClass(t)}setStyle(t,e,n){if(R(t)&&n===undefined){n=e}n._setStyle(t,e)}removeStyle(t,e){e._removeStyle(t)}setCustomProperty(t,e,n){n._setCustomProperty(t,e)}removeCustomProperty(t,e){return e._removeCustomProperty(t)}createPositionAt(t,e){return dl._createAt(t,e)}createPositionAfter(t){return dl._createAfter(t)}createPositionBefore(t){return dl._createBefore(t)}createRange(t,e){return new hl(t,e)}createRangeOn(t){return hl._createOn(t)}createRangeIn(t){return hl._createIn(t)}createSelection(t,e,n){return new ml(t,e,n)}}class FA extends _w{refresh(){this.isEnabled=Lk(this.editor.model)}execute(t){const e=this.editor;const n=e.model;const i=e.plugins.get(dv);n.change(e=>{const o=Array.isArray(t.file)?t.file:[t.file];for(const t of o){UA(e,n,i,t)}})}}function UA(t,e,n,i){const o=n.createLoader(i);if(!o){return}Rk(t,e,{uploadId:o.id})}class HA extends ww{static get requires(){return[dv,sv,zA]}static get pluginName(){return"ImageUploadEditing"}constructor(t){super(t);t.config.define("image",{upload:{types:["jpeg","png","gif","bmp","webp","tiff"]}})}init(){const t=this.editor;const e=t.model.document;const n=t.model.schema;const i=t.conversion;const o=t.plugins.get(dv);const s=cA(t.config.get("image.upload.types"));n.extend("image",{allowAttributes:["uploadId","uploadStatus"]});t.commands.add("imageUpload",new FA(t));i.for("upcast").attributeToAttribute({view:{name:"img",key:"uploadId"},model:"uploadId"});this.listenTo(t.editing.view.document,"clipboardInput",(e,n)=>{if(qA(n.dataTransfer)){return}const i=Array.from(n.dataTransfer.files).filter(t=>{if(!t){return false}return s.test(t.type)});const o=n.targetRanges.map(e=>t.editing.mapper.toModelRange(e));t.model.change(n=>{n.setSelection(o);if(i.length){e.stop();t.model.enqueueChange("default",()=>{t.execute("imageUpload",{file:i})})}})});this.listenTo(t.plugins.get(zA),"inputTransformation",(e,n)=>{const i=Array.from(t.editing.view.createRangeIn(n.content)).filter(t=>uA(t.item)&&!t.item.getAttribute("uploadProcessed")).map(t=>({promise:lA(t.item),imageElement:t.item}));if(!i.length){return}const s=new BA;for(const t of i){s.setAttribute("uploadProcessed",true,t.imageElement);const e=o.createLoader(t.promise);if(e){s.setAttribute("src","",t.imageElement);s.setAttribute("uploadId",e.id,t.imageElement)}}});t.editing.view.document.on("dragover",(t,e)=>{e.preventDefault()});e.on("change",()=>{const n=e.differ.getChanges({includeChangesInGraveyard:true});for(const e of n){if(e.type=="insert"&&e.name!="$text"){const n=e.position.nodeAfter;const i=e.position.root.rootName=="$graveyard";for(const e of WA(t,n)){const t=e.getAttribute("uploadId");if(!t){continue}const n=o.loaders.get(t);if(!n){continue}if(i){n.abort()}else if(n.status=="idle"){this._readAndUpload(n,e)}}}}})}_readAndUpload(t,e){const n=this.editor;const i=n.model;const o=n.locale.t;const s=n.plugins.get(dv);const r=n.plugins.get(sv);i.enqueueChange("transparent",t=>{t.setAttribute("uploadStatus","reading",e)});return t.read().then(()=>{const o=t.upload();if(Tl.isSafari){const t=n.editing.mapper.toViewElement(e);const i=t.getChild(0);n.editing.view.once("render",()=>{if(!i.parent){return}const t=n.editing.view.domConverter.mapViewToDom(i.parent);if(!t){return}const e=t.style.display;t.style.display="none";t._ckHack=t.offsetHeight;t.style.display=e})}i.enqueueChange("transparent",t=>{t.setAttribute("uploadStatus","uploading",e)});return o}).then(t=>{i.enqueueChange("transparent",n=>{n.setAttributes({uploadStatus:"complete",src:t.default},e);this._parseAndSetSrcsetAttributeOnImage(t,e,n)});a()}).catch(n=>{if(t.status!=="error"&&t.status!=="aborted"){throw n}if(t.status=="error"&&n){r.showWarning(n,{title:o("ay"),namespace:"upload"})}a();i.enqueueChange("transparent",t=>{t.remove(e)})});function a(){i.enqueueChange("transparent",t=>{t.removeAttribute("uploadId",e);t.removeAttribute("uploadStatus",e)});s.destroyLoader(t)}}_parseAndSetSrcsetAttributeOnImage(t,e,n){let i=0;const o=Object.keys(t).filter(t=>{const e=parseInt(t,10);if(!isNaN(e)){i=Math.max(i,e);return true}}).map(e=>`${t[e]} ${e}w`).join(", ");if(o!=""){n.setAttribute("srcset",{data:o,width:i},e)}}}function qA(t){return Array.from(t.types).includes("text/html")&&t.getData("text/html")!==""}function WA(t,e){return Array.from(t.model.createRangeOn(e)).filter(t=>t.item.is("image")).map(t=>t.item)}class $A extends ww{static get pluginName(){return"ImageUpload"}static get requires(){return[HA,fA,wA]}}class YA extends _w{constructor(t){super(t);this._childCommands=[]}refresh(){}execute(...t){const e=this._getFirstEnabledCommand();e.execute(t)}registerChildCommand(t){this._childCommands.push(t);t.on("change:isEnabled",()=>this._checkEnabled());this._checkEnabled()}_checkEnabled(){this.isEnabled=!!this._getFirstEnabledCommand()}_getFirstEnabledCommand(){return this._childCommands.find(t=>t.isEnabled)}}class GA extends ww{static get pluginName(){return"IndentEditing"}init(){const t=this.editor;t.commands.add("indent",new YA(t));t.commands.add("outdent",new YA(t))}}var QA='';var KA='';class JA extends ww{static get pluginName(){return"IndentUI"}init(){const t=this.editor;const e=t.locale;const n=t.t;const i=e.uiLanguageDirection=="ltr"?QA:KA;const o=e.uiLanguageDirection=="ltr"?KA:QA;this._defineButton("indent",n("y"),i);this._defineButton("outdent",n("z"),o)}_defineButton(t,e,n){const i=this.editor;i.ui.componentFactory.add(t,o=>{const s=i.commands.get(t);const r=new Fb(o);r.set({label:e,icon:n,tooltip:true});r.bind("isOn","isEnabled").to(s,"value","isEnabled");this.listenTo(r,"execute",()=>{i.execute(t);i.editing.view.focus()});return r})}}class ZA extends ww{static get pluginName(){return"Indent"}static get requires(){return[GA,JA]}}class XA extends _w{constructor(t,e){super(t);this._indentBehavior=e}refresh(){const t=this.editor;const e=t.model;const n=yw(e.document.selection.getSelectedBlocks());if(!n||!e.schema.checkAttribute(n,"blockIndent")){this.isEnabled=false;return}this.isEnabled=this._indentBehavior.checkEnabled(n.getAttribute("blockIndent"))}execute(){const t=this.editor.model;const e=tC(t);t.change(t=>{for(const n of e){const e=n.getAttribute("blockIndent");const i=this._indentBehavior.getNextIndent(e);if(i){t.setAttribute("blockIndent",i,n)}else{t.removeAttribute("blockIndent",n)}}})}}function tC(t){const e=t.document.selection;const n=t.schema;const i=Array.from(e.getSelectedBlocks());return i.filter(t=>n.checkAttribute(t,"blockIndent"))}class eC{constructor(t){this.isForward=t.direction==="forward";this.offset=t.offset;this.unit=t.unit}checkEnabled(t){const e=parseFloat(t||0);return this.isForward||e>0}getNextIndent(t){const e=parseFloat(t||0);const n=!t||t.endsWith(this.unit);if(!n){return this.isForward?this.offset+this.unit:undefined}const i=this.isForward?this.offset:-this.offset;const o=e+i;return o>0?o+this.unit:undefined}}class nC{constructor(t){this.isForward=t.direction==="forward";this.classes=t.classes}checkEnabled(t){const e=this.classes.indexOf(t);if(this.isForward){return e