ckeditor5-1.0.x-dev/js/build/drupal/drupalImage.js
js/build/drupal/drupalImage.js
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.drupalImage=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.drupalImage=e())}(window,(function(){return function(t){var e={};function i(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(r,n,function(e){return t[e]}.bind(null,n));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s="./src/drupalImage/src/index.js")}({"./src/drupalImage/src/index.js":function(t,e,i){"use strict";i.r(e);var r=i("ckeditor5/src/core.js");class n extends r.Plugin{static get pluginName(){return"DrupalImageEditing"}init(){const t=this.editor,e=t.conversion,{schema:i}=t.model;i.isRegistered("imageInline")&&i.extend("imageInline",{allowAttributes:["dataEntityUuid","dataEntityType","width","height"]}),i.isRegistered("imageBlock")&&i.extend("imageBlock",{allowAttributes:["dataEntityUuid","dataEntityType","width","height"]}),e.for("upcast").add(function(t){return t=>{t.on("element:img",e,{priority:"high"})};function e(e,i,r){const{viewItem:n}=i,{writer:a,consumable:o,safeInsert:s,updateConversionResult:u,schema:l}=r,d=[];let c;if(o.test(n,{name:!0,attributes:"src"})){if(c=l.checkChild(i.modelCursor,"imageInline")?a.createElement("imageInline",{src:n.getAttribute("src")}):a.createElement("imageBlock",{src:n.getAttribute("src")}),t.plugins.has("ImageStyleEditing")&&o.test(n,{name:!0,attributes:"data-align"})){const t={left:"alignBlockLeft",center:"alignCenter",right:"alignBlockRight"},e={left:"alignLeft",right:"alignRight"},i=n.getAttribute("data-align"),r=c.is("element","imageBlock")?t[i]:e[i];a.setAttribute("imageStyle",r,c),d.push("data-align")}if(c.is("element","imageBlock")&&o.test(n,{name:!0,attributes:"data-caption"})){const t=a.createElement("caption");a.insertText(n.getAttribute("data-caption"),t),a.append(t,c),d.push("data-caption")}o.test(n,{name:!0,attributes:"data-entity-uuid"})&&(a.setAttribute("dataEntityUuid",n.getAttribute("data-entity-uuid"),c),d.push("data-entity-uuid")),o.test(n,{name:!0,attributes:"data-entity-type"})&&(a.setAttribute("dataEntityFile",n.getAttribute("data-entity-type"),c),d.push("data-entity-type")),s(c,i.modelCursor)&&(o.consume(n,{name:!0,attributes:d}),u(c,i))}}}(t)).attributeToAttribute({view:{name:"img",key:"width"},model:{key:"width",value:t=>t.getAttribute("width")+"px"}}).attributeToAttribute({view:{name:"img",key:"height"},model:{key:"height",value:t=>t.getAttribute("height")+"px"}}),e.for("downcast").add(function(){return e=>{e.on("attribute:dataEntityUuid",t)};function t(t,e,i){const{item:r}=e,{consumable:n,writer:a}=i;if(!n.consume(r,t.name))return;const o=i.mapper.toViewElement(r),s=Array.from(o.getChildren()).find(t=>"img"===t.name);a.setAttribute("data-entity-uuid",e.attributeNewValue,s||o)}}()).add(function(){return e=>{e.on("attribute:dataEntityType",t)};function t(t,e,i){const{item:r}=e,{consumable:n,writer:a}=i;if(!n.consume(r,t.name))return;const o=i.mapper.toViewElement(r),s=Array.from(o.getChildren()).find(t=>"img"===t.name);a.setAttribute("data-entity-type",e.attributeNewValue,s||o)}}()),e.for("dataDowncast").add(e=>{e.on("insert:caption",(e,i,r)=>{if(!r.consumable.consume(i.item,"insert"))return;let n="";for(const{item:e}of t.model.createRangeIn(i.item))r.consumable.consume(e,"insert")&&e.is("$textProxy")&&(n+=e.data);if(n){const t=r.mapper.toViewElement(i.item.parent);r.writer.setAttribute("data-caption",n,t)}},{priority:"high"})}).add(t=>{t.on("insert:$text",(t,e)=>{const{parent:i}=e.item;i.is("element","caption")&&i.parent.is("element","imageBlock")&&t.stop()},{priority:"highest"})}).elementToElement({model:"imageBlock",view:(t,{writer:e})=>a(e),converterPriority:"high"}).elementToElement({model:"imageInline",view:(t,{writer:e})=>a(e),converterPriority:"high"}).add(function(){return e=>{e.on("attribute:imageStyle",t,{priority:"high"})};function t(t,e,i){const{item:r}=e,{consumable:n,writer:a}=i,o={alignLeft:"left",alignRight:"right",alignCenter:"center",alignBlockRight:"right",alignBlockLeft:"left"};if(!o[e.attributeNewValue]||!n.consume(r,t.name))return;const s=i.mapper.toViewElement(r),u=Array.from(s.getChildren()).find(t=>"img"===t.name);a.setAttribute("data-align",o[e.attributeNewValue],u||s)}}()).add(function(){return e=>{e.on("attribute:width:imageInline",t,{priority:"high"}),e.on("attribute:width:imageBlock",t,{priority:"high"})};function t(t,e,i){const{item:r}=e,{consumable:n,writer:a}=i;if(!n.consume(r,t.name))return;const o=i.mapper.toViewElement(r),s=Array.from(o.getChildren()).find(t=>"img"===t.name);a.setAttribute("width",e.attributeNewValue.replace("px",""),s||o)}}()).add(function(){return e=>{e.on("attribute:height:imageInline",t,{priority:"high"}),e.on("attribute:height:imageBlock",t,{priority:"high"})};function t(t,e,i){const{item:r}=e,{consumable:n,writer:a}=i;if(!n.consume(r,t.name))return;const o=i.mapper.toViewElement(r),s=Array.from(o.getChildren()).find(t=>"img"===t.name);a.setAttribute("height",e.attributeNewValue.replace("px",""),s||o)}}())}}function a(t){return t.createEmptyElement("img")}class o extends r.Plugin{static get requires(){return[n]}static get pluginName(){return"DrupalImage"}}var s=o;class u extends r.Plugin{init(){const{editor:t}=this;t.plugins.get("ImageUploadEditing").on("uploadComplete",(e,{data:i,imageElement:r})=>{t.model.change(t=>{t.setAttribute("dataEntityUuid",i.dataEntityUuid,r),t.setAttribute("dataEntityType",i.dataEntityType,r)})})}static get pluginName(){return"DrupalImageUploadEditing"}}var l=i("ckeditor5/src/upload.js"),d=i("ckeditor5/src/utils.js");class c extends r.Plugin{static get requires(){return[l.FileRepository]}static get pluginName(){return"DrupalImageUploadAdapter"}init(){const t=this.editor.config.get("drupalImageUpload");t&&(t.uploadUrl?this.editor.plugins.get(l.FileRepository).createUploadAdapter=e=>new m(e,t):Object(d.logWarning)("simple-upload-adapter-missing-uploadurl"))}}class m{constructor(t,e){this.loader=t,this.options=e}upload(){return this.loader.file.then(t=>new Promise((e,i)=>{this._initRequest(),this._initListeners(e,i,t),this._sendRequest(t)}))}abort(){this.xhr&&this.xhr.abort()}_initRequest(){const t=this.xhr=new XMLHttpRequest;t.open("POST",this.options.uploadUrl,!0),t.responseType="json"}_initListeners(t,e,i){const r=this.xhr,n=this.loader,a=`Couldn't upload file: ${i.name}.`;r.addEventListener("error",()=>e(a)),r.addEventListener("abort",()=>e()),r.addEventListener("load",()=>{const i=r.response;if(!i||i.error)return e(i&&i.error&&i.error.message?i.error.message:a);t({urls:{default:i.url},dataEntityUuid:i.uuid?i.uuid:"",dataEntityType:i.entity_type?i.entity_type:""})}),r.upload&&r.upload.addEventListener("progress",t=>{t.lengthComputable&&(n.uploadTotal=t.total,n.uploaded=t.loaded)})}_sendRequest(t){const e=this.options.headers||{},i=this.options.withCredentials||!1;for(const t of Object.keys(e))this.xhr.setRequestHeader(t,e[t]);this.xhr.withCredentials=i;const r=new FormData;r.append("upload",t),this.xhr.send(r)}}class p extends r.Plugin{static get requires(){return[c,u]}static get pluginName(){return"DrupalImageUpload"}}var g=p;e.default={DrupalImage:s,DrupalImageUpload:g}},"ckeditor5/src/core.js":function(t,e,i){t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/upload.js":function(t,e,i){t.exports=i("dll-reference CKEditor5.dll")("./src/upload.js")},"ckeditor5/src/utils.js":function(t,e,i){t.exports=i("dll-reference CKEditor5.dll")("./src/utils.js")},"dll-reference CKEditor5.dll":function(t,e){t.exports=CKEditor5.dll}}).default}));