@ckeditor/ckeditor5-ckbox 0.0.0-nightly-20240625.0 → 0.0.0-nightly-20240626.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ckbox.js +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/dist/types/ckboxcommand.d.ts +13 -1
- package/dist/types/ckboxconfig.d.ts +105 -0
- package/dist/types/ckboxediting.d.ts +0 -4
- package/package.json +2 -2
- package/src/ckboxcommand.d.ts +13 -1
- package/src/ckboxcommand.js +36 -4
- package/src/ckboxconfig.d.ts +105 -0
- package/src/ckboxediting.d.ts +0 -4
package/build/ckbox.js
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
/*!
|
3
3
|
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
4
4
|
* For licensing, see LICENSE.md.
|
5
|
-
*/(()=>{var e={957:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(935),o=r.n(n)()((function(e){return e[1]}));o.push([e.id,':root{--ck-image-processing-highlight-color:#f9fafa;--ck-image-processing-background-color:#e3e5e8}.ck.ck-editor__editable .image.image-processing{position:relative}.ck.ck-editor__editable .image.image-processing:before{animation:ck-image-processing-animation 2s linear infinite;background:linear-gradient(90deg,var(--ck-image-processing-background-color),var(--ck-image-processing-highlight-color),var(--ck-image-processing-background-color));background-size:200% 100%;content:"";height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.ck.ck-editor__editable .image.image-processing img{height:100%}@keyframes ck-image-processing-animation{0%{background-position:200% 0}to{background-position:-200% 0}}',""]);const i=o},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var r=e(t);return t[2]?"@media ".concat(t[2]," {").concat(r,"}"):r})).join("")},t.i=function(e,r,n){"string"==typeof e&&(e=[[null,e,""]]);var o={};if(n)for(var i=0;i<this.length;i++){var a=this[i][0];null!=a&&(o[a]=!0)}for(var s=0;s<e.length;s++){var c=[].concat(e[s]);n&&o[c[0]]||(r&&(c[2]?c[2]="".concat(r," and ").concat(c[2]):c[2]=r),t.push(c))}},t}},591:(e,t,r)=>{"use strict";var n,o=function(){return void 0===n&&(n=Boolean(window&&document&&document.all&&!window.atob)),n},i=function(){var e={};return function(t){if(void 0===e[t]){var r=document.querySelector(t);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}e[t]=r}return e[t]}}(),a=[];function s(e){for(var t=-1,r=0;r<a.length;r++)if(a[r].identifier===e){t=r;break}return t}function c(e,t){for(var r={},n=[],o=0;o<e.length;o++){var i=e[o],c=t.base?i[0]+t.base:i[0],l=r[c]||0,u="".concat(c," ").concat(l);r[c]=l+1;var d=s(u),g={css:i[1],media:i[2],sourceMap:i[3]};-1!==d?(a[d].references++,a[d].updater(g)):a.push({identifier:u,updater:m(g,t),references:1}),n.push(u)}return n}function l(e){var t=document.createElement("style"),n=e.attributes||{};if(void 0===n.nonce){var o=r.nc;o&&(n.nonce=o)}if(Object.keys(n).forEach((function(e){t.setAttribute(e,n[e])})),"function"==typeof e.insert)e.insert(t);else{var a=i(e.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(t)}return t}var u,d=(u=[],function(e,t){return u[e]=t,u.filter(Boolean).join("\n")});function g(e,t,r,n){var o=r?"":n.media?"@media ".concat(n.media," {").concat(n.css,"}"):n.css;if(e.styleSheet)e.styleSheet.cssText=d(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function h(e,t,r){var n=r.css,o=r.media,i=r.sourceMap;if(o?e.setAttribute("media",o):e.removeAttribute("media"),i&&"undefined"!=typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}var p=null,f=0;function m(e,t){var r,n,o;if(t.singleton){var i=f++;r=p||(p=l(t)),n=g.bind(null,r,i,!1),o=g.bind(null,r,i,!0)}else r=l(t),n=h.bind(null,r,t),o=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(r)};return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else o()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=o());var r=c(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var n=0;n<r.length;n++){var o=s(r[n]);a[o].references--}for(var i=c(e,t),l=0;l<r.length;l++){var u=s(r[l]);0===a[u].references&&(a[u].updater(),a.splice(u,1))}r=i}}}},782:(e,t,r)=>{e.exports=r(237)("./src/core.js")},783:(e,t,r)=>{e.exports=r(237)("./src/engine.js")},311:(e,t,r)=>{e.exports=r(237)("./src/ui.js")},260:(e,t,r)=>{e.exports=r(237)("./src/upload.js")},584:(e,t,r)=>{e.exports=r(237)("./src/utils.js")},237:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={id:n,exports:{}};return e[n](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.nc=void 0;var n={};(()=>{"use strict";r.r(n),r.d(n,{CKBox:()=>U,CKBoxEditing:()=>O,CKBoxImageEdit:()=>Cr,CKBoxImageEditEditing:()=>kr,CKBoxImageEditUI:()=>xr,CKBoxUI:()=>o});var e=r(782),t=r(311);class o extends e.Plugin{static get pluginName(){return"CKBoxUI"}afterInit(){const e=this.editor;e.commands.get("ckbox")&&(e.ui.componentFactory.add("ckbox",(()=>this._createFileToolbarButton())),e.ui.componentFactory.add("menuBar:ckbox",(()=>this._createFileMenuBarButton())),e.plugins.has("ImageInsertUI")&&e.plugins.get("ImageInsertUI").registerIntegration({name:"assetManager",observable:()=>e.commands.get("ckbox"),buttonViewCreator:()=>this._createImageToolbarButton(),formViewCreator:()=>this._createImageDropdownButton(),menuBarButtonViewCreator:e=>this._createImageMenuBarButton(e?"insertOnly":"insertNested")}))}_createButton(e){const t=this.editor,r=t.locale,n=new e(r),o=t.commands.get("ckbox");r.t;return n.bind("isOn","isEnabled").to(o,"value","isEnabled"),n.on("execute",(()=>{t.execute("ckbox")})),n}_createFileToolbarButton(){const r=this.editor.locale.t,n=this._createButton(t.ButtonView);return n.icon=e.icons.browseFiles,n.label=r("Open file manager"),n.tooltip=!0,n}_createImageToolbarButton(){const r=this.editor.locale.t,n=this.editor.plugins.get("ImageInsertUI"),o=this._createButton(t.ButtonView);return o.icon=e.icons.imageAssetManager,o.bind("label").to(n,"isImageSelected",(e=>r(e?"Replace image with file manager":"Insert image with file manager"))),o.tooltip=!0,o}_createImageDropdownButton(){const r=this.editor.locale.t,n=this.editor.plugins.get("ImageInsertUI"),o=this._createButton(t.ButtonView);return o.icon=e.icons.imageAssetManager,o.withText=!0,o.bind("label").to(n,"isImageSelected",(e=>r(e?"Replace with file manager":"Insert with file manager"))),o.on("execute",(()=>{n.dropdownView.isOpen=!1})),o}_createFileMenuBarButton(){const r=this.editor.locale.t,n=this._createButton(t.MenuBarMenuListItemButtonView);return n.icon=e.icons.browseFiles,n.withText=!0,n.label=r("File"),n}_createImageMenuBarButton(r){const n=this.editor.locale.t,o=this._createButton(t.MenuBarMenuListItemButtonView);switch(o.icon=e.icons.imageAssetManager,o.withText=!0,r){case"insertOnly":o.label=n("Image");break;case"insertNested":o.label=n("With file manager")}return o}}var i=r(783),a=r(584),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],c=e=>{let t=0;for(let r=0;r<e.length;r++){let n=e[r];t=83*t+s.indexOf(n)}return t},l=e=>{let t=e/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},u=e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(12.92*t*255+.5):Math.trunc(255*(1.055*Math.pow(t,.4166666666666667)-.055)+.5)},d=(e,t)=>(e=>e<0?-1:1)(e)*Math.pow(Math.abs(e),t),g=class extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}},h=e=>{if(!e||e.length<6)throw new g("The blurhash string must be at least 6 characters");let t=c(e[0]),r=Math.floor(t/9)+1,n=t%9+1;if(e.length!==4+2*n*r)throw new g(`blurhash length mismatch: length is ${e.length} but it should be ${4+2*n*r}`)},p=e=>{let t=e>>8&255,r=255&e;return[l(e>>16),l(t),l(r)]},f=(e,t)=>{let r=Math.floor(e/361),n=Math.floor(e/19)%19,o=e%19;return[d((r-9)/9,2)*t,d((n-9)/9,2)*t,d((o-9)/9,2)*t]},m=(e,t,r,n)=>{h(e),n|=1;let o=c(e[0]),i=Math.floor(o/9)+1,a=o%9+1,s=(c(e[1])+1)/166,l=new Array(a*i);for(let t=0;t<l.length;t++)if(0===t){let r=c(e.substring(2,6));l[t]=p(r)}else{let r=c(e.substring(4+2*t,6+2*t));l[t]=f(r,s*n)}let d=4*t,g=new Uint8ClampedArray(d*r);for(let e=0;e<r;e++)for(let n=0;n<t;n++){let o=0,s=0,c=0;for(let u=0;u<i;u++)for(let i=0;i<a;i++){let d=Math.cos(Math.PI*n*i/t)*Math.cos(Math.PI*e*u/r),g=l[i+u*a];o+=g[0]*d,s+=g[1]*d,c+=g[2]*d}let h=u(o),p=u(s),f=u(c);g[4*n+0+e*d]=h,g[4*n+1+e*d]=p,g[4*n+2+e*d]=f,g[4*n+3+e*d]=255}return g};function b(e){const t=[];let r=0;for(const n in e){const o=parseInt(n,10);isNaN(o)||(o>r&&(r=o),t.push(`${e[n]} ${n}w`))}const n=[{srcset:t.join(","),sizes:`(max-width: ${r}px) 100vw, ${r}px`,type:"image/webp"}];return{imageFallbackUrl:e.default,imageSources:n}}const v=32;function _({url:e,method:t="GET",data:r,onUploadProgress:n,signal:o,authorization:i}){const a=new XMLHttpRequest;a.open(t,e.toString()),a.setRequestHeader("Authorization",i),a.setRequestHeader("CKBox-Version","CKEditor 5"),a.responseType="json";const s=()=>{a.abort()};return new Promise(((e,t)=>{o.throwIfAborted(),o.addEventListener("abort",s),a.addEventListener("loadstart",(()=>{o.addEventListener("abort",s)})),a.addEventListener("loadend",(()=>{o.removeEventListener("abort",s)})),a.addEventListener("error",(()=>{t()})),a.addEventListener("abort",(()=>{t()})),a.addEventListener("load",(()=>{const r=a.response;if(!r||r.statusCode>=400)return t(r&&r.message);e(r)})),n&&a.upload.addEventListener("progress",(e=>{n(e)})),a.send(r)}))}const w={"image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp","image/bmp":"bmp","image/tiff":"tiff"};class y extends e.Command{constructor(e){super(e),this._chosenAssets=new Set,this._wrapper=null,this._initListeners()}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(){this.fire("ckbox:open")}_getValue(){return null!==this._wrapper}_checkEnabled(){const e=this.editor.commands.get("insertImage"),t=this.editor.commands.get("link");return!(!e.isEnabled&&!t.isEnabled)}_prepareOptions(){const e=this.editor.config.get("ckbox");return{theme:e.theme,language:e.language,tokenUrl:e.tokenUrl,serviceOrigin:e.serviceOrigin,forceDemoLabel:e.forceDemoLabel,dialog:{onClose:()=>this.fire("ckbox:close")},assets:{onChoose:e=>this.fire("ckbox:choose",e)}}}_initListeners(){const e=this.editor,t=e.model,r=!e.config.get("ckbox.ignoreDataId");this.on("ckbox",(()=>{this.refresh()}),{priority:"low"}),this.on("ckbox:open",(()=>{this.isEnabled&&!this.value&&(this._wrapper=(0,a.createElement)(document,"div",{class:"ck ckbox-wrapper"}),document.body.appendChild(this._wrapper),window.CKBox.mount(this._wrapper,this._prepareOptions()))})),this.on("ckbox:close",(()=>{this.value&&(this._wrapper.remove(),this._wrapper=null,e.editing.view.focus())})),this.on("ckbox:choose",((n,o)=>{if(!this.isEnabled)return;const i=e.commands.get("insertImage"),a=e.commands.get("link"),s=function({assets:e,isImageAllowed:t,isLinkAllowed:r}){return e.map((e=>function(e){const t=e.data.metadata;if(!t)return!1;return t.width&&t.height}(e)?{id:e.data.id,type:"image",attributes:k(e)}:{id:e.data.id,type:"link",attributes:x(e)})).filter((e=>"image"===e.type?t:r))}({assets:o,isImageAllowed:i.isEnabled,isLinkAllowed:a.isEnabled}),c=s.length;0!==c&&(t.change((e=>{for(const t of s){const n=t===s[c-1],o=1===c;this._insertAsset(t,n,e,o),r&&(setTimeout((()=>this._chosenAssets.delete(t)),1e3),this._chosenAssets.add(t))}})),e.editing.view.focus())})),this.listenTo(e,"destroy",(()=>{this.fire("ckbox:close"),this._chosenAssets.clear()}))}_insertAsset(e,t,r,n){const o=this.editor.model.document.selection;r.removeSelectionAttribute("linkHref"),"image"===e.type?this._insertImage(e):this._insertLink(e,r,n),t||r.setSelection(o.getLastPosition())}_insertImage(e){const t=this.editor,{imageFallbackUrl:r,imageSources:n,imageTextAlternative:o,imageWidth:i,imageHeight:a,imagePlaceholder:s}=e.attributes;t.execute("insertImage",{source:{src:r,sources:n,alt:o,width:i,height:a,...s?{placeholder:s}:null}})}_insertLink(e,t,r){const n=this.editor,o=n.model,i=o.document.selection,{linkName:s,linkHref:c}=e.attributes;if(i.isCollapsed){const e=(0,a.toMap)(i.getAttributes()),l=t.createText(s,e);if(!r){const e=i.getLastPosition(),r=e.parent;"paragraph"===r.name&&r.isEmpty||n.execute("insertParagraph",{position:e});const a=o.insertContent(l);return t.setSelection(a),void n.execute("link",c)}const u=o.insertContent(l);t.setSelection(u)}n.execute("link",c)}}function k(e){const{imageFallbackUrl:t,imageSources:r}=b(e.data.imageUrls),{description:n,width:o,height:i,blurHash:a}=e.data.metadata,s=function(e){if(e)try{const t=`${v}px`,r=document.createElement("canvas");r.setAttribute("width",t),r.setAttribute("height",t);const n=r.getContext("2d");if(!n)return;const o=n.createImageData(v,v),i=m(e,v,v);return o.data.set(i),n.putImageData(o,0,0),r.toDataURL()}catch(e){return}}(a);return{imageFallbackUrl:t,imageSources:r,imageTextAlternative:n||"",imageWidth:o,imageHeight:i,...s?{imagePlaceholder:s}:null}}function x(e){return{linkName:e.data.name,linkHref:I(e)}}function I(e){const t=new URL(e.data.url);return t.searchParams.set("download","true"),t.toString()}var A=r(260);class E extends e.Plugin{static get pluginName(){return"CKBoxUtils"}static get requires(){return["CloudServices"]}async init(){const e=this.editor,t=!!e.config.get("ckbox"),r=!!window.CKBox;if(!t&&!r)return;e.config.define("ckbox",{serviceOrigin:"https://api.ckbox.io",defaultUploadCategories:null,ignoreDataId:!1,language:e.locale.uiLanguage,theme:"lark",tokenUrl:e.config.get("cloudServices.tokenUrl")});const n=e.plugins.get("CloudServices"),o=e.config.get("cloudServices.tokenUrl"),i=e.config.get("ckbox.tokenUrl");if(!i)throw new a.CKEditorError("ckbox-plugin-missing-token-url",this);this._token=i==o?n.token:await n.registerTokenUrl(i)}getToken(){return this._token}getWorkspaceId(){const e=(0,this.editor.t)("Cannot access default workspace."),t=this.editor.config.get("ckbox.defaultUploadWorkspaceId"),r=function(e,t){const[,r]=e.value.split("."),n=JSON.parse(atob(r)),o=n.auth&&n.auth.ckbox&&n.auth.ckbox.workspaces||[n.aud];return t?"superadmin"==(n.auth&&n.auth.ckbox&&n.auth.ckbox.role)||o.includes(t)?t:null:o[0]}(this._token,t);if(null==r)throw(0,a.logError)("ckbox-access-default-workspace-error"),e;return r}async getCategoryIdForFile(e,t){const r=(0,this.editor.t)("Cannot determine a category for the uploaded file."),n=this.editor.config.get("ckbox.defaultUploadCategories"),o=this._getAvailableCategories(t),i="string"==typeof e?(a=await async function(e,t){try{const r=await fetch(e,{method:"HEAD",cache:"force-cache",...t});return r.ok&&r.headers.get("content-type")||""}catch{return""}}(e,t),w[a]):e.name.match(/\.(?<ext>[^.]+)$/).groups.ext.toLowerCase();var a;const s=await o;if(!s)throw r;if(n){const e=Object.keys(n).find((e=>n[e].find((e=>e.toLowerCase()==i))));if(e){const t=s.find((t=>t.id===e||t.name===e));if(!t)throw r;return t.id}}const c=s.find((e=>e.extensions.find((e=>e.toLowerCase()==i))));if(!c)throw r;return c.id}async _getAvailableCategories(e){const t=this.editor,r=this._token,{signal:n}=e,o=t.config.get("ckbox.serviceOrigin"),i=this.getWorkspaceId();try{const e=[];let t,r=0;do{const n=await s(r);e.push(...n.items),t=n.totalCount-(r+50),r+=50}while(t>0);return e}catch{return n.throwIfAborted(),void(0,a.logError)("ckbox-fetch-category-http-error")}function s(e){const t=new URL("categories",o);return t.searchParams.set("limit",50..toString()),t.searchParams.set("offset",e.toString()),t.searchParams.set("workspaceId",i),_({url:t,signal:n,authorization:r.value})}}}class j extends e.Plugin{static get requires(){return["ImageUploadEditing","ImageUploadProgress",A.FileRepository,O]}static get pluginName(){return"CKBoxUploadAdapter"}async afterInit(){const e=this.editor,t=!!e.config.get("ckbox"),r=!!window.CKBox;if(!t&&!r)return;const n=e.plugins.get(A.FileRepository),o=e.plugins.get(E);n.createUploadAdapter=t=>new C(t,e,o);const i=!e.config.get("ckbox.ignoreDataId"),a=e.plugins.get("ImageUploadEditing");i&&a.on("uploadComplete",((t,{imageElement:r,data:n})=>{e.model.change((e=>{e.setAttribute("ckboxImageId",n.ckboxImageId,r)}))}))}}class C{constructor(e,t,r){this.loader=e,this.token=r.getToken(),this.ckboxUtils=r,this.editor=t,this.controller=new AbortController,this.serviceOrigin=t.config.get("ckbox.serviceOrigin")}async upload(){const e=this.ckboxUtils,t=this.editor.t,r=await this.loader.file,n=await e.getCategoryIdForFile(r,{signal:this.controller.signal}),o=new URL("assets",this.serviceOrigin),i=new FormData;o.searchParams.set("workspaceId",e.getWorkspaceId()),i.append("categoryId",n),i.append("file",r);return _({method:"POST",url:o,data:i,onUploadProgress:e=>{e.lengthComputable&&(this.loader.uploadTotal=e.total,this.loader.uploaded=e.loaded)},signal:this.controller.signal,authorization:this.token.value}).then((async e=>{const t=b(e.imageUrls);return{ckboxImageId:e.id,default:t.imageFallbackUrl,sources:t.imageSources}})).catch((()=>{const e=t("Cannot upload file:")+` ${r.name}.`;return Promise.reject(e)}))}abort(){this.controller.abort()}}class O extends e.Plugin{static get pluginName(){return"CKBoxEditing"}static get requires(){return["LinkEditing","PictureEditing",j,E]}init(){const e=this.editor;this._shouldBeInitialised()&&(this._checkImagePlugins(),L()&&e.commands.add("ckbox",new y(e)))}afterInit(){const e=this.editor;this._shouldBeInitialised()&&(e.config.get("ckbox.ignoreDataId")||(this._initSchema(),this._initConversion(),this._initFixers()))}_shouldBeInitialised(){return!!this.editor.config.get("ckbox")||L()}_checkImagePlugins(){const e=this.editor;e.plugins.has("ImageBlockEditing")||e.plugins.has("ImageInlineEditing")||(0,a.logError)("ckbox-plugin-image-feature-missing",e)}_initSchema(){const e=this.editor.model.schema;e.extend("$text",{allowAttributes:"ckboxLinkId"}),e.isRegistered("imageBlock")&&e.extend("imageBlock",{allowAttributes:["ckboxImageId","ckboxLinkId"]}),e.isRegistered("imageInline")&&e.extend("imageInline",{allowAttributes:["ckboxImageId","ckboxLinkId"]}),e.addAttributeCheck(((e,t)=>{if(!!!e.last.getAttribute("linkHref")&&"ckboxLinkId"===t)return!1}))}_initConversion(){const e=this.editor;e.conversion.for("downcast").add((e=>{e.on("attribute:ckboxLinkId:imageBlock",((e,t,r)=>{const{writer:n,mapper:o,consumable:i}=r;if(!i.consume(t.item,e.name))return;const a=[...o.toViewElement(t.item).getChildren()].find((e=>"a"===e.name));a&&(t.item.hasAttribute("ckboxLinkId")?n.setAttribute("data-ckbox-resource-id",t.item.getAttribute("ckboxLinkId"),a):n.removeAttribute("data-ckbox-resource-id",a))}),{priority:"low"}),e.on("attribute:ckboxLinkId",((e,t,r)=>{const{writer:n,mapper:o,consumable:i}=r;if(i.consume(t.item,e.name)){if(t.attributeOldValue){const e=B(n,t.attributeOldValue);n.unwrap(o.toViewRange(t.range),e)}if(t.attributeNewValue){const e=B(n,t.attributeNewValue);if(t.item.is("selection")){const t=n.document.selection;n.wrap(t.getFirstRange(),e)}else n.wrap(o.toViewRange(t.range),e)}}}),{priority:"low"})})),e.conversion.for("upcast").add((e=>{e.on("element:a",((e,t,r)=>{const{writer:n,consumable:o}=r;if(!t.viewItem.getAttribute("href"))return;if(!o.consume(t.viewItem,{attributes:["data-ckbox-resource-id"]}))return;const i=t.viewItem.getAttribute("data-ckbox-resource-id");if(i)if(t.modelRange)for(let e of t.modelRange.getItems())e.is("$textProxy")&&(e=e.textNode),P(e)&&n.setAttribute("ckboxLinkId",i,e);else{const e=t.modelCursor.nodeBefore||t.modelCursor.parent;n.setAttribute("ckboxLinkId",i,e)}}),{priority:"low"})})),e.conversion.for("downcast").attributeToAttribute({model:"ckboxImageId",view:"data-ckbox-resource-id"}),e.conversion.for("upcast").elementToAttribute({model:{key:"ckboxImageId",value:e=>e.getAttribute("data-ckbox-resource-id")},view:{attributes:{"data-ckbox-resource-id":/[\s\S]+/}}});const t=e.commands.get("replaceImageSource");t&&this.listenTo(t,"cleanupImage",((e,[t,r])=>{t.removeAttribute("ckboxImageId",r)}))}_initFixers(){const e=this.editor,t=e.model,r=t.document.selection;t.document.registerPostFixer(function(e){return t=>{let r=!1;const n=e.model,o=e.commands.get("ckbox");if(!o)return r;for(const e of n.document.differ.getChanges()){if("insert"!==e.type&&"attribute"!==e.type)continue;const n="insert"===e.type?new i.Range(e.position,e.position.getShiftedBy(e.length)):e.range,a="attribute"===e.type&&"linkHref"===e.attributeKey&&null===e.attributeNewValue;for(const e of n.getItems()){if(a&&e.hasAttribute("ckboxLinkId")){t.removeAttribute("ckboxLinkId",e),r=!0;continue}const n=S(e,o._chosenAssets);for(const o of n){const n="image"===o.type?"ckboxImageId":"ckboxLinkId";o.id!==e.getAttribute(n)&&(t.setAttribute(n,o.id,e),r=!0)}}}return r}}(e)),t.document.registerPostFixer(function(e){return t=>!(e.hasAttribute("linkHref")||!e.hasAttribute("ckboxLinkId"))&&(t.removeSelectionAttribute("ckboxLinkId"),!0)}(r))}}function S(e,t){const r=e.is("element","imageInline")||e.is("element","imageBlock"),n=e.hasAttribute("linkHref");return[...t].filter((t=>"image"===t.type&&r?t.attributes.imageFallbackUrl===e.getAttribute("src"):"link"===t.type&&n?t.attributes.linkHref===e.getAttribute("linkHref"):void 0))}function B(e,t){const r=e.createAttributeElement("a",{"data-ckbox-resource-id":t},{priority:5});return e.setCustomProperty("link",!0,r),r}function P(e){return!!e.is("$text")||!(!e.is("element","imageInline")&&!e.is("element","imageBlock"))}function L(){return!!window.CKBox}class U extends e.Plugin{static get pluginName(){return"CKBox"}static get requires(){return[O,o]}}const T=function(){this.__data__=[],this.size=0};const F=function(e,t){return e===t||e!=e&&t!=t};const M=function(e,t){for(var r=e.length;r--;)if(F(e[r][0],t))return r;return-1};var N=Array.prototype.splice;const R=function(e){var t=this.__data__,r=M(t,e);return!(r<0)&&(r==t.length-1?t.pop():N.call(t,r,1),--this.size,!0)};const V=function(e){var t=this.__data__,r=M(t,e);return r<0?void 0:t[r][1]};const z=function(e){return M(this.__data__,e)>-1};const K=function(e,t){var r=this.__data__,n=M(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};function D(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}D.prototype.clear=T,D.prototype.delete=R,D.prototype.get=V,D.prototype.has=z,D.prototype.set=K;const $=D;const H=function(){this.__data__=new $,this.size=0};const q=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r};const W=function(e){return this.__data__.get(e)};const Z=function(e){return this.__data__.has(e)};const G="object"==typeof global&&global&&global.Object===Object&&global;var J="object"==typeof self&&self&&self.Object===Object&&self;const X=G||J||Function("return this")();const Q=X.Symbol;var Y=Object.prototype,ee=Y.hasOwnProperty,te=Y.toString,re=Q?Q.toStringTag:void 0;const ne=function(e){var t=ee.call(e,re),r=e[re];try{e[re]=void 0;var n=!0}catch(e){}var o=te.call(e);return n&&(t?e[re]=r:delete e[re]),o};var oe=Object.prototype.toString;const ie=function(e){return oe.call(e)};var ae=Q?Q.toStringTag:void 0;const se=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":ae&&ae in Object(e)?ne(e):ie(e)};const ce=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};const le=function(e){if(!ce(e))return!1;var t=se(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t};const ue=X["__core-js_shared__"];var de,ge=(de=/[^.]+$/.exec(ue&&ue.keys&&ue.keys.IE_PROTO||""))?"Symbol(src)_1."+de:"";const he=function(e){return!!ge&&ge in e};var pe=Function.prototype.toString;const fe=function(e){if(null!=e){try{return pe.call(e)}catch(e){}try{return e+""}catch(e){}}return""};var me=/^\[object .+?Constructor\]$/,be=Function.prototype,ve=Object.prototype,_e=be.toString,we=ve.hasOwnProperty,ye=RegExp("^"+_e.call(we).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");const ke=function(e){return!(!ce(e)||he(e))&&(le(e)?ye:me).test(fe(e))};const xe=function(e,t){return null==e?void 0:e[t]};const Ie=function(e,t){var r=xe(e,t);return ke(r)?r:void 0};const Ae=Ie(X,"Map");const Ee=Ie(Object,"create");const je=function(){this.__data__=Ee?Ee(null):{},this.size=0};const Ce=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t};var Oe=Object.prototype.hasOwnProperty;const Se=function(e){var t=this.__data__;if(Ee){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return Oe.call(t,e)?t[e]:void 0};var Be=Object.prototype.hasOwnProperty;const Pe=function(e){var t=this.__data__;return Ee?void 0!==t[e]:Be.call(t,e)};const Le=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Ee&&void 0===t?"__lodash_hash_undefined__":t,this};function Ue(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Ue.prototype.clear=je,Ue.prototype.delete=Ce,Ue.prototype.get=Se,Ue.prototype.has=Pe,Ue.prototype.set=Le;const Te=Ue;const Fe=function(){this.size=0,this.__data__={hash:new Te,map:new(Ae||$),string:new Te}};const Me=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};const Ne=function(e,t){var r=e.__data__;return Me(t)?r["string"==typeof t?"string":"hash"]:r.map};const Re=function(e){var t=Ne(this,e).delete(e);return this.size-=t?1:0,t};const Ve=function(e){return Ne(this,e).get(e)};const ze=function(e){return Ne(this,e).has(e)};const Ke=function(e,t){var r=Ne(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function De(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}De.prototype.clear=Fe,De.prototype.delete=Re,De.prototype.get=Ve,De.prototype.has=ze,De.prototype.set=Ke;const $e=De;const He=function(e,t){var r=this.__data__;if(r instanceof $){var n=r.__data__;if(!Ae||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new $e(n)}return r.set(e,t),this.size=r.size,this};function qe(e){var t=this.__data__=new $(e);this.size=t.size}qe.prototype.clear=H,qe.prototype.delete=q,qe.prototype.get=W,qe.prototype.has=Z,qe.prototype.set=He;const We=qe;const Ze=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this};const Ge=function(e){return this.__data__.has(e)};function Je(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new $e;++t<r;)this.add(e[t])}Je.prototype.add=Je.prototype.push=Ze,Je.prototype.has=Ge;const Xe=Je;const Qe=function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1};const Ye=function(e,t){return e.has(t)};const et=function(e,t,r,n,o,i){var a=1&r,s=e.length,c=t.length;if(s!=c&&!(a&&c>s))return!1;var l=i.get(e),u=i.get(t);if(l&&u)return l==t&&u==e;var d=-1,g=!0,h=2&r?new Xe:void 0;for(i.set(e,t),i.set(t,e);++d<s;){var p=e[d],f=t[d];if(n)var m=a?n(f,p,d,t,e,i):n(p,f,d,e,t,i);if(void 0!==m){if(m)continue;g=!1;break}if(h){if(!Qe(t,(function(e,t){if(!Ye(h,t)&&(p===e||o(p,e,r,n,i)))return h.push(t)}))){g=!1;break}}else if(p!==f&&!o(p,f,r,n,i)){g=!1;break}}return i.delete(e),i.delete(t),g};const tt=X.Uint8Array;const rt=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r};const nt=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r};var ot=Q?Q.prototype:void 0,it=ot?ot.valueOf:void 0;const at=function(e,t,r,n,o,i,a){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!i(new tt(e),new tt(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return F(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var s=rt;case"[object Set]":var c=1&n;if(s||(s=nt),e.size!=t.size&&!c)return!1;var l=a.get(e);if(l)return l==t;n|=2,a.set(e,t);var u=et(s(e),s(t),n,o,i,a);return a.delete(e),u;case"[object Symbol]":if(it)return it.call(e)==it.call(t)}return!1};const st=function(e,t){for(var r=-1,n=t.length,o=e.length;++r<n;)e[o+r]=t[r];return e};const ct=Array.isArray;const lt=function(e,t,r){var n=t(e);return ct(e)?n:st(n,r(e))};const ut=function(e,t){for(var r=-1,n=null==e?0:e.length,o=0,i=[];++r<n;){var a=e[r];t(a,r,e)&&(i[o++]=a)}return i};const dt=function(){return[]};var gt=Object.prototype.propertyIsEnumerable,ht=Object.getOwnPropertySymbols;const pt=ht?function(e){return null==e?[]:(e=Object(e),ut(ht(e),(function(t){return gt.call(e,t)})))}:dt;const ft=function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n};const mt=function(e){return null!=e&&"object"==typeof e};const bt=function(e){return mt(e)&&"[object Arguments]"==se(e)};var vt=Object.prototype,_t=vt.hasOwnProperty,wt=vt.propertyIsEnumerable;const yt=bt(function(){return arguments}())?bt:function(e){return mt(e)&&_t.call(e,"callee")&&!wt.call(e,"callee")};const kt=function(){return!1};var xt="object"==typeof exports&&exports&&!exports.nodeType&&exports,It=xt&&"object"==typeof module&&module&&!module.nodeType&&module,At=It&&It.exports===xt?X.Buffer:void 0;const Et=(At?At.isBuffer:void 0)||kt;var jt=/^(?:0|[1-9]\d*)$/;const Ct=function(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&jt.test(e))&&e>-1&&e%1==0&&e<t};const Ot=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991};var St={};St["[object Float32Array]"]=St["[object Float64Array]"]=St["[object Int8Array]"]=St["[object Int16Array]"]=St["[object Int32Array]"]=St["[object Uint8Array]"]=St["[object Uint8ClampedArray]"]=St["[object Uint16Array]"]=St["[object Uint32Array]"]=!0,St["[object Arguments]"]=St["[object Array]"]=St["[object ArrayBuffer]"]=St["[object Boolean]"]=St["[object DataView]"]=St["[object Date]"]=St["[object Error]"]=St["[object Function]"]=St["[object Map]"]=St["[object Number]"]=St["[object Object]"]=St["[object RegExp]"]=St["[object Set]"]=St["[object String]"]=St["[object WeakMap]"]=!1;const Bt=function(e){return mt(e)&&Ot(e.length)&&!!St[se(e)]};const Pt=function(e){return function(t){return e(t)}};var Lt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ut=Lt&&"object"==typeof module&&module&&!module.nodeType&&module,Tt=Ut&&Ut.exports===Lt&&G.process,Ft=function(){try{var e=Ut&&Ut.require&&Ut.require("util").types;return e||Tt&&Tt.binding&&Tt.binding("util")}catch(e){}}();var Mt=Ft&&Ft.isTypedArray;const Nt=Mt?Pt(Mt):Bt;var Rt=Object.prototype.hasOwnProperty;const Vt=function(e,t){var r=ct(e),n=!r&&yt(e),o=!r&&!n&&Et(e),i=!r&&!n&&!o&&Nt(e),a=r||n||o||i,s=a?ft(e.length,String):[],c=s.length;for(var l in e)!t&&!Rt.call(e,l)||a&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Ct(l,c))||s.push(l);return s};var zt=Object.prototype;const Kt=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||zt)};const Dt=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object);var $t=Object.prototype.hasOwnProperty;const Ht=function(e){if(!Kt(e))return Dt(e);var t=[];for(var r in Object(e))$t.call(e,r)&&"constructor"!=r&&t.push(r);return t};const qt=function(e){return null!=e&&Ot(e.length)&&!le(e)};const Wt=function(e){return qt(e)?Vt(e):Ht(e)};const Zt=function(e){return lt(e,Wt,pt)};var Gt=Object.prototype.hasOwnProperty;const Jt=function(e,t,r,n,o,i){var a=1&r,s=Zt(e),c=s.length;if(c!=Zt(t).length&&!a)return!1;for(var l=c;l--;){var u=s[l];if(!(a?u in t:Gt.call(t,u)))return!1}var d=i.get(e),g=i.get(t);if(d&&g)return d==t&&g==e;var h=!0;i.set(e,t),i.set(t,e);for(var p=a;++l<c;){var f=e[u=s[l]],m=t[u];if(n)var b=a?n(m,f,u,t,e,i):n(f,m,u,e,t,i);if(!(void 0===b?f===m||o(f,m,r,n,i):b)){h=!1;break}p||(p="constructor"==u)}if(h&&!p){var v=e.constructor,_=t.constructor;v==_||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof _&&_ instanceof _||(h=!1)}return i.delete(e),i.delete(t),h};const Xt=Ie(X,"DataView");const Qt=Ie(X,"Promise");const Yt=Ie(X,"Set");const er=Ie(X,"WeakMap");var tr="[object Map]",rr="[object Promise]",nr="[object Set]",or="[object WeakMap]",ir="[object DataView]",ar=fe(Xt),sr=fe(Ae),cr=fe(Qt),lr=fe(Yt),ur=fe(er),dr=se;(Xt&&dr(new Xt(new ArrayBuffer(1)))!=ir||Ae&&dr(new Ae)!=tr||Qt&&dr(Qt.resolve())!=rr||Yt&&dr(new Yt)!=nr||er&&dr(new er)!=or)&&(dr=function(e){var t=se(e),r="[object Object]"==t?e.constructor:void 0,n=r?fe(r):"";if(n)switch(n){case ar:return ir;case sr:return tr;case cr:return rr;case lr:return nr;case ur:return or}return t});const gr=dr;var hr="[object Arguments]",pr="[object Array]",fr="[object Object]",mr=Object.prototype.hasOwnProperty;const br=function(e,t,r,n,o,i){var a=ct(e),s=ct(t),c=a?pr:gr(e),l=s?pr:gr(t),u=(c=c==hr?fr:c)==fr,d=(l=l==hr?fr:l)==fr,g=c==l;if(g&&Et(e)){if(!Et(t))return!1;a=!0,u=!1}if(g&&!u)return i||(i=new We),a||Nt(e)?et(e,t,r,n,o,i):at(e,t,c,r,n,o,i);if(!(1&r)){var h=u&&mr.call(e,"__wrapped__"),p=d&&mr.call(t,"__wrapped__");if(h||p){var f=h?e.value():e,m=p?t.value():t;return i||(i=new We),o(f,m,r,n,i)}}return!!g&&(i||(i=new We),Jt(e,t,r,n,o,i))};const vr=function e(t,r,n,o,i){return t===r||(null==t||null==r||!mt(t)&&!mt(r)?t!=t&&r!=r:br(t,r,n,o,e,i))};const _r=function(e,t){return vr(e,t)};function wr(e){if(Array.isArray(e)){const t=e.map(wr);return e=>t.some((t=>t(e)))}if("origin"==e){const e=a.global.window.location.origin;return t=>new URL(t,a.global.document.baseURI).origin==e}if("function"==typeof e)return e;if(e instanceof RegExp)return t=>!(!t.match(e)&&!t.replace(/^https?:\/\//,"").match(e));return()=>!1}class yr extends e.Command{constructor(e){super(e),this._wrapper=null,this._processInProgress=new Set,this._updateUiDelayed=(0,a.delay)((()=>this.editor.ui.update()),0),this.value=!1,this._canEdit=function(e){const t=wr(e);return e=>!(!e.is("element","imageInline")&&!e.is("element","imageBlock"))&&(!!e.hasAttribute("ckboxImageId")||!!e.hasAttribute("src")&&t(e.getAttribute("src")))}(e.config.get("ckbox.allowExternalImagesEditing")),this._prepareOptions=(0,a.abortableDebounce)(((e,t)=>this._prepareOptionsAbortable(e,t))),this._prepareListeners()}refresh(){const e=this.editor;this.value=this._getValue();const t=e.model.document.selection.getSelectedElement();this.isEnabled=!!t&&this._canEdit(t)&&!this._checkIfElementIsBeingProcessed(t)}execute(){if(this._getValue())return;const e=(0,a.createElement)(document,"div",{class:"ck ckbox-wrapper"});this._wrapper=e,this.value=!0,document.body.appendChild(this._wrapper);const r={element:this.editor.model.document.selection.getSelectedElement(),controller:new AbortController};this._prepareOptions(r).then((t=>window.CKBox.mountImageEditor(e,t)),(e=>{const r=this.editor,n=r.t;r.plugins.get(t.Notification).showWarning(n("Failed to determine category of edited image."),{namespace:"ckbox"}),console.error(e),this._handleImageEditorClose()}))}destroy(){this._handleImageEditorClose(),this._prepareOptions.abort(),this._updateUiDelayed.cancel();for(const e of this._processInProgress.values())e.controller.abort();super.destroy()}_getValue(){return null!==this._wrapper}async _prepareOptionsAbortable(e,t){const r=this.editor,n=r.config.get("ckbox"),o=r.plugins.get(E),{element:i}=t;let a;const s=i.getAttribute("ckboxImageId");if(s)a={assetId:s};else{const t=new URL(i.getAttribute("src"),document.baseURI).href;a={imageUrl:t,uploadCategoryId:await o.getCategoryIdForFile(t,{signal:e})}}return{...a,imageEditing:{allowOverwrite:!1},tokenUrl:n.tokenUrl,...n.serviceOrigin&&{serviceOrigin:n.serviceOrigin},onClose:()=>this._handleImageEditorClose(),onSave:e=>this._handleImageEditorSave(t,e)}}_prepareListeners(){this.listenTo(this.editor.model.document,"change:data",(()=>{this._getProcessingStatesOfDeletedImages().forEach((e=>{e.controller.abort()}))}))}_getProcessingStatesOfDeletedImages(){const e=[];for(const t of this._processInProgress.values())"$graveyard"==t.element.root.rootName&&e.push(t);return e}_checkIfElementIsBeingProcessed(e){for(const{element:t}of this._processInProgress)if(_r(t,e))return!0;return!1}_handleImageEditorClose(){this._wrapper&&(this._wrapper.remove(),this._wrapper=null,this.editor.editing.view.focus(),this._updateUiDelayed(),this.refresh())}_handleImageEditorSave(r,n){const o=this.editor.locale.t,i=this.editor.plugins.get(t.Notification),s=this.editor.plugins.get(e.PendingActions),c=s.add(o("Processing the edited image."));this._processInProgress.add(r),this._showImageProcessingIndicator(r.element,n),this.refresh(),this._waitForAssetProcessed(n.data.id,r.controller.signal).then((e=>{this._replaceImage(r.element,e)}),(e=>{this.editor.editing.reconvertItem(r.element),r.controller.signal.aborted||(!e||e instanceof a.CKEditorError?i.showWarning(o("Server failed to process the image."),{namespace:"ckbox"}):console.error(e))})).finally((()=>{this._processInProgress.delete(r),s.remove(c),this.refresh()}))}async _getAssetStatusFromServer(e,t){const r=this.editor.plugins.get(E),n=new URL("assets/"+e,this.editor.config.get("ckbox.serviceOrigin")),o=await _({url:n,signal:t,authorization:r.getToken().value}),i=o.metadata.metadataProcessingStatus;if(!i||"queued"==i)throw new a.CKEditorError("ckbox-image-not-processed");return{data:{...o}}}async _waitForAssetProcessed(e,t){const r=await(0,a.retry)((()=>this._getAssetStatusFromServer(e,t)),{signal:t,maxAttempts:5});if("success"!=r.data.metadata.metadataProcessingStatus)throw new a.CKEditorError("ckbox-image-processing-failed");return r}_showImageProcessingIndicator(e,t){const r=this.editor;r.editing.view.change((n=>{const o=r.editing.mapper.toViewElement(e),i=this.editor.plugins.get("ImageUtils").findViewImgElement(o);n.removeStyle("aspect-ratio",i),n.setAttribute("width",t.data.metadata.width,i),n.setAttribute("height",t.data.metadata.height,i),n.setStyle("width",`${t.data.metadata.width}px`,i),n.setStyle("height",`${t.data.metadata.height}px`,i),n.addClass("image-processing",o)}))}_replaceImage(e,t){const r=this.editor,{imageFallbackUrl:n,imageSources:o,imageWidth:i,imageHeight:a,imagePlaceholder:s}=k(t),c=Array.from(r.model.document.selection.getRanges());r.model.change((l=>{l.setSelection(e,"on"),r.execute("insertImage",{source:{src:n,sources:o,width:i,height:a,...s?{placeholder:s}:null,...e.hasAttribute("alt")?{alt:e.getAttribute("alt")}:null}});const u=e.getChildren();e=r.model.document.selection.getSelectedElement();for(const t of u)l.append(l.cloneElement(t),e);l.setAttribute("ckboxImageId",t.data.id,e),l.setSelection(c)}))}}class kr extends e.Plugin{static get pluginName(){return"CKBoxImageEditEditing"}static get requires(){return[O,E,e.PendingActions,t.Notification,"ImageUtils","ImageEditing"]}init(){const{editor:e}=this;e.commands.add("ckboxImageEdit",new yr(e))}}class xr extends e.Plugin{static get pluginName(){return"CKBoxImageEditUI"}init(){const e=this.editor;e.ui.componentFactory.add("ckboxImageEdit",(r=>{const n=e.commands.get("ckboxImageEdit"),o=new t.ButtonView(r),i=r.t;return o.set({label:i("Edit image"),icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M1.201 1C.538 1 0 1.47 0 2.1v14.363c0 .64.534 1.037 1.186 1.037H5.06l5.058-5.078L6.617 9.15a.696.696 0 0 0-.957-.033L1.5 13.6V2.5h15v4.354a3.478 3.478 0 0 1 1.5.049V2.1c0-.63-.547-1.1-1.2-1.1H1.202Zm11.713 2.803a2.147 2.147 0 0 0-2.049 1.992 2.14 2.14 0 0 0 1.28 2.096 2.13 2.13 0 0 0 2.642-3.11 2.129 2.129 0 0 0-1.873-.978ZM8.089 17.635v2.388h2.389l7.046-7.046-2.39-2.39-7.045 7.048Zm11.282-6.507a.637.637 0 0 0 .139-.692.603.603 0 0 0-.139-.205l-1.49-1.488a.63.63 0 0 0-.899 0l-1.166 1.163 2.39 2.39 1.165-1.168Z"/></svg>',tooltip:!0}),o.bind("isOn").to(n,"value",n,"isEnabled",((e,t)=>e&&t)),o.bind("isEnabled").to(n),this.listenTo(o,"execute",(()=>{e.execute("ckboxImageEdit"),e.editing.view.focus()})),o}))}}var Ir=r(591),Ar=r.n(Ir),Er=r(957),jr={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};Ar()(Er.A,jr);Er.A.locals;class Cr extends e.Plugin{static get pluginName(){return"CKBoxImageEdit"}static get requires(){return[kr,xr]}}})(),(window.CKEditor5=window.CKEditor5||{}).ckbox=n})();
|
5
|
+
*/(()=>{var e={957:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(935),o=n.n(r)()((function(e){return e[1]}));o.push([e.id,':root{--ck-image-processing-highlight-color:#f9fafa;--ck-image-processing-background-color:#e3e5e8}.ck.ck-editor__editable .image.image-processing{position:relative}.ck.ck-editor__editable .image.image-processing:before{animation:ck-image-processing-animation 2s linear infinite;background:linear-gradient(90deg,var(--ck-image-processing-background-color),var(--ck-image-processing-highlight-color),var(--ck-image-processing-background-color));background-size:200% 100%;content:"";height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.ck.ck-editor__editable .image.image-processing img{height:100%}@keyframes ck-image-processing-animation{0%{background-position:200% 0}to{background-position:-200% 0}}',""]);const i=o},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=e(t);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n})).join("")},t.i=function(e,n,r){"string"==typeof e&&(e=[[null,e,""]]);var o={};if(r)for(var i=0;i<this.length;i++){var a=this[i][0];null!=a&&(o[a]=!0)}for(var s=0;s<e.length;s++){var c=[].concat(e[s]);r&&o[c[0]]||(n&&(c[2]?c[2]="".concat(n," and ").concat(c[2]):c[2]=n),t.push(c))}},t}},591:(e,t,n)=>{"use strict";var r,o=function(){return void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r},i=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),a=[];function s(e){for(var t=-1,n=0;n<a.length;n++)if(a[n].identifier===e){t=n;break}return t}function c(e,t){for(var n={},r=[],o=0;o<e.length;o++){var i=e[o],c=t.base?i[0]+t.base:i[0],l=n[c]||0,u="".concat(c," ").concat(l);n[c]=l+1;var d=s(u),g={css:i[1],media:i[2],sourceMap:i[3]};-1!==d?(a[d].references++,a[d].updater(g)):a.push({identifier:u,updater:m(g,t),references:1}),r.push(u)}return r}function l(e){var t=document.createElement("style"),r=e.attributes||{};if(void 0===r.nonce){var o=n.nc;o&&(r.nonce=o)}if(Object.keys(r).forEach((function(e){t.setAttribute(e,r[e])})),"function"==typeof e.insert)e.insert(t);else{var a=i(e.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(t)}return t}var u,d=(u=[],function(e,t){return u[e]=t,u.filter(Boolean).join("\n")});function g(e,t,n,r){var o=n?"":r.media?"@media ".concat(r.media," {").concat(r.css,"}"):r.css;if(e.styleSheet)e.styleSheet.cssText=d(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function h(e,t,n){var r=n.css,o=n.media,i=n.sourceMap;if(o?e.setAttribute("media",o):e.removeAttribute("media"),i&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}var p=null,f=0;function m(e,t){var n,r,o;if(t.singleton){var i=f++;n=p||(p=l(t)),r=g.bind(null,n,i,!1),o=g.bind(null,n,i,!0)}else n=l(t),r=h.bind(null,n,t),o=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=o());var n=c(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var r=0;r<n.length;r++){var o=s(n[r]);a[o].references--}for(var i=c(e,t),l=0;l<n.length;l++){var u=s(n[l]);0===a[u].references&&(a[u].updater(),a.splice(u,1))}n=i}}}},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")},311:(e,t,n)=>{e.exports=n(237)("./src/ui.js")},260:(e,t,n)=>{e.exports=n(237)("./src/upload.js")},584:(e,t,n)=>{e.exports=n(237)("./src/utils.js")},237:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={id:r,exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nc=void 0;var r={};(()=>{"use strict";n.r(r),n.d(r,{CKBox:()=>U,CKBoxEditing:()=>O,CKBoxImageEdit:()=>On,CKBoxImageEditEditing:()=>xn,CKBoxImageEditUI:()=>In,CKBoxUI:()=>o});var e=n(782),t=n(311);class o extends e.Plugin{static get pluginName(){return"CKBoxUI"}afterInit(){const e=this.editor;e.commands.get("ckbox")&&(e.ui.componentFactory.add("ckbox",(()=>this._createFileToolbarButton())),e.ui.componentFactory.add("menuBar:ckbox",(()=>this._createFileMenuBarButton())),e.plugins.has("ImageInsertUI")&&e.plugins.get("ImageInsertUI").registerIntegration({name:"assetManager",observable:()=>e.commands.get("ckbox"),buttonViewCreator:()=>this._createImageToolbarButton(),formViewCreator:()=>this._createImageDropdownButton(),menuBarButtonViewCreator:e=>this._createImageMenuBarButton(e?"insertOnly":"insertNested")}))}_createButton(e){const t=this.editor,n=t.locale,r=new e(n),o=t.commands.get("ckbox");n.t;return r.bind("isOn","isEnabled").to(o,"value","isEnabled"),r.on("execute",(()=>{t.execute("ckbox")})),r}_createFileToolbarButton(){const n=this.editor.locale.t,r=this._createButton(t.ButtonView);return r.icon=e.icons.browseFiles,r.label=n("Open file manager"),r.tooltip=!0,r}_createImageToolbarButton(){const n=this.editor.locale.t,r=this.editor.plugins.get("ImageInsertUI"),o=this._createButton(t.ButtonView);return o.icon=e.icons.imageAssetManager,o.bind("label").to(r,"isImageSelected",(e=>n(e?"Replace image with file manager":"Insert image with file manager"))),o.tooltip=!0,o}_createImageDropdownButton(){const n=this.editor.locale.t,r=this.editor.plugins.get("ImageInsertUI"),o=this._createButton(t.ButtonView);return o.icon=e.icons.imageAssetManager,o.withText=!0,o.bind("label").to(r,"isImageSelected",(e=>n(e?"Replace with file manager":"Insert with file manager"))),o.on("execute",(()=>{r.dropdownView.isOpen=!1})),o}_createFileMenuBarButton(){const n=this.editor.locale.t,r=this._createButton(t.MenuBarMenuListItemButtonView);return r.icon=e.icons.browseFiles,r.withText=!0,r.label=n("File"),r}_createImageMenuBarButton(n){const r=this.editor.locale.t,o=this._createButton(t.MenuBarMenuListItemButtonView);switch(o.icon=e.icons.imageAssetManager,o.withText=!0,n){case"insertOnly":o.label=r("Image");break;case"insertNested":o.label=r("With file manager")}return o}}var i=n(783),a=n(584),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],c=e=>{let t=0;for(let n=0;n<e.length;n++){let r=e[n];t=83*t+s.indexOf(r)}return t},l=e=>{let t=e/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},u=e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(12.92*t*255+.5):Math.trunc(255*(1.055*Math.pow(t,.4166666666666667)-.055)+.5)},d=(e,t)=>(e=>e<0?-1:1)(e)*Math.pow(Math.abs(e),t),g=class extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}},h=e=>{if(!e||e.length<6)throw new g("The blurhash string must be at least 6 characters");let t=c(e[0]),n=Math.floor(t/9)+1,r=t%9+1;if(e.length!==4+2*r*n)throw new g(`blurhash length mismatch: length is ${e.length} but it should be ${4+2*r*n}`)},p=e=>{let t=e>>8&255,n=255&e;return[l(e>>16),l(t),l(n)]},f=(e,t)=>{let n=Math.floor(e/361),r=Math.floor(e/19)%19,o=e%19;return[d((n-9)/9,2)*t,d((r-9)/9,2)*t,d((o-9)/9,2)*t]},m=(e,t,n,r)=>{h(e),r|=1;let o=c(e[0]),i=Math.floor(o/9)+1,a=o%9+1,s=(c(e[1])+1)/166,l=new Array(a*i);for(let t=0;t<l.length;t++)if(0===t){let n=c(e.substring(2,6));l[t]=p(n)}else{let n=c(e.substring(4+2*t,6+2*t));l[t]=f(n,s*r)}let d=4*t,g=new Uint8ClampedArray(d*n);for(let e=0;e<n;e++)for(let r=0;r<t;r++){let o=0,s=0,c=0;for(let u=0;u<i;u++)for(let i=0;i<a;i++){let d=Math.cos(Math.PI*r*i/t)*Math.cos(Math.PI*e*u/n),g=l[i+u*a];o+=g[0]*d,s+=g[1]*d,c+=g[2]*d}let h=u(o),p=u(s),f=u(c);g[4*r+0+e*d]=h,g[4*r+1+e*d]=p,g[4*r+2+e*d]=f,g[4*r+3+e*d]=255}return g};function b(e){const t=[];let n=0;for(const r in e){const o=parseInt(r,10);isNaN(o)||(o>n&&(n=o),t.push(`${e[r]} ${r}w`))}const r=[{srcset:t.join(","),sizes:`(max-width: ${n}px) 100vw, ${n}px`,type:"image/webp"}];return{imageFallbackUrl:e.default,imageSources:r}}const v=32;function _({url:e,method:t="GET",data:n,onUploadProgress:r,signal:o,authorization:i}){const a=new XMLHttpRequest;a.open(t,e.toString()),a.setRequestHeader("Authorization",i),a.setRequestHeader("CKBox-Version","CKEditor 5"),a.responseType="json";const s=()=>{a.abort()};return new Promise(((e,t)=>{o.throwIfAborted(),o.addEventListener("abort",s),a.addEventListener("loadstart",(()=>{o.addEventListener("abort",s)})),a.addEventListener("loadend",(()=>{o.removeEventListener("abort",s)})),a.addEventListener("error",(()=>{t()})),a.addEventListener("abort",(()=>{t()})),a.addEventListener("load",(()=>{const n=a.response;if(!n||n.statusCode>=400)return t(n&&n.message);e(n)})),r&&a.upload.addEventListener("progress",(e=>{r(e)})),a.send(n)}))}const w={"image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp","image/bmp":"bmp","image/tiff":"tiff"};class y extends e.Command{constructor(e){super(e),this._chosenAssets=new Set,this._wrapper=null,this._initListeners()}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(){this.fire("ckbox:open")}_getValue(){return null!==this._wrapper}_checkEnabled(){const e=this.editor.commands.get("insertImage"),t=this.editor.commands.get("link");return!(!e.isEnabled&&!t.isEnabled)}_prepareOptions(){const e=this.editor.config.get("ckbox"),t=e.dialog,n=e.categories,r=e.view,o=e.upload;return{theme:e.theme,language:e.language,tokenUrl:e.tokenUrl,serviceOrigin:e.serviceOrigin,forceDemoLabel:e.forceDemoLabel,choosableFileExtensions:e.choosableFileExtensions,assets:{onChoose:e=>this.fire("ckbox:choose",e)},dialog:{onClose:()=>this.fire("ckbox:close"),width:t&&t.width,height:t&&t.height},categories:n&&{icons:n.icons},view:r&&{openLastView:r.openLastView,startupFolderId:r.startupFolderId,startupCategoryId:r.startupCategoryId,hideMaximizeButton:r.hideMaximizeButton},upload:o&&{componentsHideTimeout:o.componentsHideTimeout,dialogMinimizeTimeout:o.dialogMinimizeTimeout}}}_initListeners(){const e=this.editor,t=e.model,n=!e.config.get("ckbox.ignoreDataId");this.on("ckbox",(()=>{this.refresh()}),{priority:"low"}),this.on("ckbox:open",(()=>{this.isEnabled&&!this.value&&(this._wrapper=(0,a.createElement)(document,"div",{class:"ck ckbox-wrapper"}),document.body.appendChild(this._wrapper),window.CKBox.mount(this._wrapper,this._prepareOptions()))})),this.on("ckbox:close",(()=>{this.value&&(this._wrapper.remove(),this._wrapper=null,e.editing.view.focus())})),this.on("ckbox:choose",((r,o)=>{if(!this.isEnabled)return;const i=e.commands.get("insertImage"),a=e.commands.get("link"),s=function({assets:e,isImageAllowed:t,isLinkAllowed:n}){return e.map((e=>function(e){const t=e.data.metadata;if(!t)return!1;return t.width&&t.height}(e)?{id:e.data.id,type:"image",attributes:k(e)}:{id:e.data.id,type:"link",attributes:x(e)})).filter((e=>"image"===e.type?t:n))}({assets:o,isImageAllowed:i.isEnabled,isLinkAllowed:a.isEnabled}),c=s.length;0!==c&&(t.change((e=>{for(const t of s){const r=t===s[c-1],o=1===c;this._insertAsset(t,r,e,o),n&&(setTimeout((()=>this._chosenAssets.delete(t)),1e3),this._chosenAssets.add(t))}})),e.editing.view.focus())})),this.listenTo(e,"destroy",(()=>{this.fire("ckbox:close"),this._chosenAssets.clear()}))}_insertAsset(e,t,n,r){const o=this.editor.model.document.selection;n.removeSelectionAttribute("linkHref"),"image"===e.type?this._insertImage(e):this._insertLink(e,n,r),t||n.setSelection(o.getLastPosition())}_insertImage(e){const t=this.editor,{imageFallbackUrl:n,imageSources:r,imageTextAlternative:o,imageWidth:i,imageHeight:a,imagePlaceholder:s}=e.attributes;t.execute("insertImage",{source:{src:n,sources:r,alt:o,width:i,height:a,...s?{placeholder:s}:null}})}_insertLink(e,t,n){const r=this.editor,o=r.model,i=o.document.selection,{linkName:s,linkHref:c}=e.attributes;if(i.isCollapsed){const e=(0,a.toMap)(i.getAttributes()),l=t.createText(s,e);if(!n){const e=i.getLastPosition(),n=e.parent;"paragraph"===n.name&&n.isEmpty||r.execute("insertParagraph",{position:e});const a=o.insertContent(l);return t.setSelection(a),void r.execute("link",c)}const u=o.insertContent(l);t.setSelection(u)}r.execute("link",c)}}function k(e){const{imageFallbackUrl:t,imageSources:n}=b(e.data.imageUrls),{description:r,width:o,height:i,blurHash:a}=e.data.metadata,s=function(e){if(e)try{const t=`${v}px`,n=document.createElement("canvas");n.setAttribute("width",t),n.setAttribute("height",t);const r=n.getContext("2d");if(!r)return;const o=r.createImageData(v,v),i=m(e,v,v);return o.data.set(i),r.putImageData(o,0,0),n.toDataURL()}catch(e){return}}(a);return{imageFallbackUrl:t,imageSources:n,imageTextAlternative:r||"",imageWidth:o,imageHeight:i,...s?{imagePlaceholder:s}:null}}function x(e){return{linkName:e.data.name,linkHref:I(e)}}function I(e){const t=new URL(e.data.url);return t.searchParams.set("download","true"),t.toString()}var A=n(260);class E extends e.Plugin{static get pluginName(){return"CKBoxUtils"}static get requires(){return["CloudServices"]}async init(){const e=this.editor,t=!!e.config.get("ckbox"),n=!!window.CKBox;if(!t&&!n)return;e.config.define("ckbox",{serviceOrigin:"https://api.ckbox.io",defaultUploadCategories:null,ignoreDataId:!1,language:e.locale.uiLanguage,theme:"lark",tokenUrl:e.config.get("cloudServices.tokenUrl")});const r=e.plugins.get("CloudServices"),o=e.config.get("cloudServices.tokenUrl"),i=e.config.get("ckbox.tokenUrl");if(!i)throw new a.CKEditorError("ckbox-plugin-missing-token-url",this);this._token=i==o?r.token:await r.registerTokenUrl(i)}getToken(){return this._token}getWorkspaceId(){const e=(0,this.editor.t)("Cannot access default workspace."),t=this.editor.config.get("ckbox.defaultUploadWorkspaceId"),n=function(e,t){const[,n]=e.value.split("."),r=JSON.parse(atob(n)),o=r.auth&&r.auth.ckbox&&r.auth.ckbox.workspaces||[r.aud];return t?"superadmin"==(r.auth&&r.auth.ckbox&&r.auth.ckbox.role)||o.includes(t)?t:null:o[0]}(this._token,t);if(null==n)throw(0,a.logError)("ckbox-access-default-workspace-error"),e;return n}async getCategoryIdForFile(e,t){const n=(0,this.editor.t)("Cannot determine a category for the uploaded file."),r=this.editor.config.get("ckbox.defaultUploadCategories"),o=this._getAvailableCategories(t),i="string"==typeof e?(a=await async function(e,t){try{const n=await fetch(e,{method:"HEAD",cache:"force-cache",...t});return n.ok&&n.headers.get("content-type")||""}catch{return""}}(e,t),w[a]):e.name.match(/\.(?<ext>[^.]+)$/).groups.ext.toLowerCase();var a;const s=await o;if(!s)throw n;if(r){const e=Object.keys(r).find((e=>r[e].find((e=>e.toLowerCase()==i))));if(e){const t=s.find((t=>t.id===e||t.name===e));if(!t)throw n;return t.id}}const c=s.find((e=>e.extensions.find((e=>e.toLowerCase()==i))));if(!c)throw n;return c.id}async _getAvailableCategories(e){const t=this.editor,n=this._token,{signal:r}=e,o=t.config.get("ckbox.serviceOrigin"),i=this.getWorkspaceId();try{const e=[];let t,n=0;do{const r=await s(n);e.push(...r.items),t=r.totalCount-(n+50),n+=50}while(t>0);return e}catch{return r.throwIfAborted(),void(0,a.logError)("ckbox-fetch-category-http-error")}function s(e){const t=new URL("categories",o);return t.searchParams.set("limit",50..toString()),t.searchParams.set("offset",e.toString()),t.searchParams.set("workspaceId",i),_({url:t,signal:r,authorization:n.value})}}}class j extends e.Plugin{static get requires(){return["ImageUploadEditing","ImageUploadProgress",A.FileRepository,O]}static get pluginName(){return"CKBoxUploadAdapter"}async afterInit(){const e=this.editor,t=!!e.config.get("ckbox"),n=!!window.CKBox;if(!t&&!n)return;const r=e.plugins.get(A.FileRepository),o=e.plugins.get(E);r.createUploadAdapter=t=>new C(t,e,o);const i=!e.config.get("ckbox.ignoreDataId"),a=e.plugins.get("ImageUploadEditing");i&&a.on("uploadComplete",((t,{imageElement:n,data:r})=>{e.model.change((e=>{e.setAttribute("ckboxImageId",r.ckboxImageId,n)}))}))}}class C{constructor(e,t,n){this.loader=e,this.token=n.getToken(),this.ckboxUtils=n,this.editor=t,this.controller=new AbortController,this.serviceOrigin=t.config.get("ckbox.serviceOrigin")}async upload(){const e=this.ckboxUtils,t=this.editor.t,n=await this.loader.file,r=await e.getCategoryIdForFile(n,{signal:this.controller.signal}),o=new URL("assets",this.serviceOrigin),i=new FormData;o.searchParams.set("workspaceId",e.getWorkspaceId()),i.append("categoryId",r),i.append("file",n);return _({method:"POST",url:o,data:i,onUploadProgress:e=>{e.lengthComputable&&(this.loader.uploadTotal=e.total,this.loader.uploaded=e.loaded)},signal:this.controller.signal,authorization:this.token.value}).then((async e=>{const t=b(e.imageUrls);return{ckboxImageId:e.id,default:t.imageFallbackUrl,sources:t.imageSources}})).catch((()=>{const e=t("Cannot upload file:")+` ${n.name}.`;return Promise.reject(e)}))}abort(){this.controller.abort()}}class O extends e.Plugin{static get pluginName(){return"CKBoxEditing"}static get requires(){return["LinkEditing","PictureEditing",j,E]}init(){const e=this.editor;this._shouldBeInitialised()&&(this._checkImagePlugins(),L()&&e.commands.add("ckbox",new y(e)))}afterInit(){const e=this.editor;this._shouldBeInitialised()&&(e.config.get("ckbox.ignoreDataId")||(this._initSchema(),this._initConversion(),this._initFixers()))}_shouldBeInitialised(){return!!this.editor.config.get("ckbox")||L()}_checkImagePlugins(){const e=this.editor;e.plugins.has("ImageBlockEditing")||e.plugins.has("ImageInlineEditing")||(0,a.logError)("ckbox-plugin-image-feature-missing",e)}_initSchema(){const e=this.editor.model.schema;e.extend("$text",{allowAttributes:"ckboxLinkId"}),e.isRegistered("imageBlock")&&e.extend("imageBlock",{allowAttributes:["ckboxImageId","ckboxLinkId"]}),e.isRegistered("imageInline")&&e.extend("imageInline",{allowAttributes:["ckboxImageId","ckboxLinkId"]}),e.addAttributeCheck(((e,t)=>{if(!!!e.last.getAttribute("linkHref")&&"ckboxLinkId"===t)return!1}))}_initConversion(){const e=this.editor;e.conversion.for("downcast").add((e=>{e.on("attribute:ckboxLinkId:imageBlock",((e,t,n)=>{const{writer:r,mapper:o,consumable:i}=n;if(!i.consume(t.item,e.name))return;const a=[...o.toViewElement(t.item).getChildren()].find((e=>"a"===e.name));a&&(t.item.hasAttribute("ckboxLinkId")?r.setAttribute("data-ckbox-resource-id",t.item.getAttribute("ckboxLinkId"),a):r.removeAttribute("data-ckbox-resource-id",a))}),{priority:"low"}),e.on("attribute:ckboxLinkId",((e,t,n)=>{const{writer:r,mapper:o,consumable:i}=n;if(i.consume(t.item,e.name)){if(t.attributeOldValue){const e=B(r,t.attributeOldValue);r.unwrap(o.toViewRange(t.range),e)}if(t.attributeNewValue){const e=B(r,t.attributeNewValue);if(t.item.is("selection")){const t=r.document.selection;r.wrap(t.getFirstRange(),e)}else r.wrap(o.toViewRange(t.range),e)}}}),{priority:"low"})})),e.conversion.for("upcast").add((e=>{e.on("element:a",((e,t,n)=>{const{writer:r,consumable:o}=n;if(!t.viewItem.getAttribute("href"))return;if(!o.consume(t.viewItem,{attributes:["data-ckbox-resource-id"]}))return;const i=t.viewItem.getAttribute("data-ckbox-resource-id");if(i)if(t.modelRange)for(let e of t.modelRange.getItems())e.is("$textProxy")&&(e=e.textNode),P(e)&&r.setAttribute("ckboxLinkId",i,e);else{const e=t.modelCursor.nodeBefore||t.modelCursor.parent;r.setAttribute("ckboxLinkId",i,e)}}),{priority:"low"})})),e.conversion.for("downcast").attributeToAttribute({model:"ckboxImageId",view:"data-ckbox-resource-id"}),e.conversion.for("upcast").elementToAttribute({model:{key:"ckboxImageId",value:e=>e.getAttribute("data-ckbox-resource-id")},view:{attributes:{"data-ckbox-resource-id":/[\s\S]+/}}});const t=e.commands.get("replaceImageSource");t&&this.listenTo(t,"cleanupImage",((e,[t,n])=>{t.removeAttribute("ckboxImageId",n)}))}_initFixers(){const e=this.editor,t=e.model,n=t.document.selection;t.document.registerPostFixer(function(e){return t=>{let n=!1;const r=e.model,o=e.commands.get("ckbox");if(!o)return n;for(const e of r.document.differ.getChanges()){if("insert"!==e.type&&"attribute"!==e.type)continue;const r="insert"===e.type?new i.Range(e.position,e.position.getShiftedBy(e.length)):e.range,a="attribute"===e.type&&"linkHref"===e.attributeKey&&null===e.attributeNewValue;for(const e of r.getItems()){if(a&&e.hasAttribute("ckboxLinkId")){t.removeAttribute("ckboxLinkId",e),n=!0;continue}const r=S(e,o._chosenAssets);for(const o of r){const r="image"===o.type?"ckboxImageId":"ckboxLinkId";o.id!==e.getAttribute(r)&&(t.setAttribute(r,o.id,e),n=!0)}}}return n}}(e)),t.document.registerPostFixer(function(e){return t=>!(e.hasAttribute("linkHref")||!e.hasAttribute("ckboxLinkId"))&&(t.removeSelectionAttribute("ckboxLinkId"),!0)}(n))}}function S(e,t){const n=e.is("element","imageInline")||e.is("element","imageBlock"),r=e.hasAttribute("linkHref");return[...t].filter((t=>"image"===t.type&&n?t.attributes.imageFallbackUrl===e.getAttribute("src"):"link"===t.type&&r?t.attributes.linkHref===e.getAttribute("linkHref"):void 0))}function B(e,t){const n=e.createAttributeElement("a",{"data-ckbox-resource-id":t},{priority:5});return e.setCustomProperty("link",!0,n),n}function P(e){return!!e.is("$text")||!(!e.is("element","imageInline")&&!e.is("element","imageBlock"))}function L(){return!!window.CKBox}class U extends e.Plugin{static get pluginName(){return"CKBox"}static get requires(){return[O,o]}}const T=function(){this.__data__=[],this.size=0};const F=function(e,t){return e===t||e!=e&&t!=t};const M=function(e,t){for(var n=e.length;n--;)if(F(e[n][0],t))return n;return-1};var z=Array.prototype.splice;const N=function(e){var t=this.__data__,n=M(t,e);return!(n<0)&&(n==t.length-1?t.pop():z.call(t,n,1),--this.size,!0)};const R=function(e){var t=this.__data__,n=M(t,e);return n<0?void 0:t[n][1]};const V=function(e){return M(this.__data__,e)>-1};const K=function(e,t){var n=this.__data__,r=M(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};function D(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}D.prototype.clear=T,D.prototype.delete=N,D.prototype.get=R,D.prototype.has=V,D.prototype.set=K;const H=D;const $=function(){this.__data__=new H,this.size=0};const q=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n};const W=function(e){return this.__data__.get(e)};const Z=function(e){return this.__data__.has(e)};const G="object"==typeof global&&global&&global.Object===Object&&global;var J="object"==typeof self&&self&&self.Object===Object&&self;const X=G||J||Function("return this")();const Q=X.Symbol;var Y=Object.prototype,ee=Y.hasOwnProperty,te=Y.toString,ne=Q?Q.toStringTag:void 0;const re=function(e){var t=ee.call(e,ne),n=e[ne];try{e[ne]=void 0;var r=!0}catch(e){}var o=te.call(e);return r&&(t?e[ne]=n:delete e[ne]),o};var oe=Object.prototype.toString;const ie=function(e){return oe.call(e)};var ae=Q?Q.toStringTag:void 0;const se=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":ae&&ae in Object(e)?re(e):ie(e)};const ce=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};const le=function(e){if(!ce(e))return!1;var t=se(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t};const ue=X["__core-js_shared__"];var de,ge=(de=/[^.]+$/.exec(ue&&ue.keys&&ue.keys.IE_PROTO||""))?"Symbol(src)_1."+de:"";const he=function(e){return!!ge&&ge in e};var pe=Function.prototype.toString;const fe=function(e){if(null!=e){try{return pe.call(e)}catch(e){}try{return e+""}catch(e){}}return""};var me=/^\[object .+?Constructor\]$/,be=Function.prototype,ve=Object.prototype,_e=be.toString,we=ve.hasOwnProperty,ye=RegExp("^"+_e.call(we).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");const ke=function(e){return!(!ce(e)||he(e))&&(le(e)?ye:me).test(fe(e))};const xe=function(e,t){return null==e?void 0:e[t]};const Ie=function(e,t){var n=xe(e,t);return ke(n)?n:void 0};const Ae=Ie(X,"Map");const Ee=Ie(Object,"create");const je=function(){this.__data__=Ee?Ee(null):{},this.size=0};const Ce=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t};var Oe=Object.prototype.hasOwnProperty;const Se=function(e){var t=this.__data__;if(Ee){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return Oe.call(t,e)?t[e]:void 0};var Be=Object.prototype.hasOwnProperty;const Pe=function(e){var t=this.__data__;return Ee?void 0!==t[e]:Be.call(t,e)};const Le=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Ee&&void 0===t?"__lodash_hash_undefined__":t,this};function Ue(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ue.prototype.clear=je,Ue.prototype.delete=Ce,Ue.prototype.get=Se,Ue.prototype.has=Pe,Ue.prototype.set=Le;const Te=Ue;const Fe=function(){this.size=0,this.__data__={hash:new Te,map:new(Ae||H),string:new Te}};const Me=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};const ze=function(e,t){var n=e.__data__;return Me(t)?n["string"==typeof t?"string":"hash"]:n.map};const Ne=function(e){var t=ze(this,e).delete(e);return this.size-=t?1:0,t};const Re=function(e){return ze(this,e).get(e)};const Ve=function(e){return ze(this,e).has(e)};const Ke=function(e,t){var n=ze(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function De(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}De.prototype.clear=Fe,De.prototype.delete=Ne,De.prototype.get=Re,De.prototype.has=Ve,De.prototype.set=Ke;const He=De;const $e=function(e,t){var n=this.__data__;if(n instanceof H){var r=n.__data__;if(!Ae||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new He(r)}return n.set(e,t),this.size=n.size,this};function qe(e){var t=this.__data__=new H(e);this.size=t.size}qe.prototype.clear=$,qe.prototype.delete=q,qe.prototype.get=W,qe.prototype.has=Z,qe.prototype.set=$e;const We=qe;const Ze=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this};const Ge=function(e){return this.__data__.has(e)};function Je(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new He;++t<n;)this.add(e[t])}Je.prototype.add=Je.prototype.push=Ze,Je.prototype.has=Ge;const Xe=Je;const Qe=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1};const Ye=function(e,t){return e.has(t)};const et=function(e,t,n,r,o,i){var a=1&n,s=e.length,c=t.length;if(s!=c&&!(a&&c>s))return!1;var l=i.get(e),u=i.get(t);if(l&&u)return l==t&&u==e;var d=-1,g=!0,h=2&n?new Xe:void 0;for(i.set(e,t),i.set(t,e);++d<s;){var p=e[d],f=t[d];if(r)var m=a?r(f,p,d,t,e,i):r(p,f,d,e,t,i);if(void 0!==m){if(m)continue;g=!1;break}if(h){if(!Qe(t,(function(e,t){if(!Ye(h,t)&&(p===e||o(p,e,n,r,i)))return h.push(t)}))){g=!1;break}}else if(p!==f&&!o(p,f,n,r,i)){g=!1;break}}return i.delete(e),i.delete(t),g};const tt=X.Uint8Array;const nt=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n};const rt=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n};var ot=Q?Q.prototype:void 0,it=ot?ot.valueOf:void 0;const at=function(e,t,n,r,o,i,a){switch(n){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!i(new tt(e),new tt(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return F(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var s=nt;case"[object Set]":var c=1&r;if(s||(s=rt),e.size!=t.size&&!c)return!1;var l=a.get(e);if(l)return l==t;r|=2,a.set(e,t);var u=et(s(e),s(t),r,o,i,a);return a.delete(e),u;case"[object Symbol]":if(it)return it.call(e)==it.call(t)}return!1};const st=function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e};const ct=Array.isArray;const lt=function(e,t,n){var r=t(e);return ct(e)?r:st(r,n(e))};const ut=function(e,t){for(var n=-1,r=null==e?0:e.length,o=0,i=[];++n<r;){var a=e[n];t(a,n,e)&&(i[o++]=a)}return i};const dt=function(){return[]};var gt=Object.prototype.propertyIsEnumerable,ht=Object.getOwnPropertySymbols;const pt=ht?function(e){return null==e?[]:(e=Object(e),ut(ht(e),(function(t){return gt.call(e,t)})))}:dt;const ft=function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r};const mt=function(e){return null!=e&&"object"==typeof e};const bt=function(e){return mt(e)&&"[object Arguments]"==se(e)};var vt=Object.prototype,_t=vt.hasOwnProperty,wt=vt.propertyIsEnumerable;const yt=bt(function(){return arguments}())?bt:function(e){return mt(e)&&_t.call(e,"callee")&&!wt.call(e,"callee")};const kt=function(){return!1};var xt="object"==typeof exports&&exports&&!exports.nodeType&&exports,It=xt&&"object"==typeof module&&module&&!module.nodeType&&module,At=It&&It.exports===xt?X.Buffer:void 0;const Et=(At?At.isBuffer:void 0)||kt;var jt=/^(?:0|[1-9]\d*)$/;const Ct=function(e,t){var n=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==n||"symbol"!=n&&jt.test(e))&&e>-1&&e%1==0&&e<t};const Ot=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991};var St={};St["[object Float32Array]"]=St["[object Float64Array]"]=St["[object Int8Array]"]=St["[object Int16Array]"]=St["[object Int32Array]"]=St["[object Uint8Array]"]=St["[object Uint8ClampedArray]"]=St["[object Uint16Array]"]=St["[object Uint32Array]"]=!0,St["[object Arguments]"]=St["[object Array]"]=St["[object ArrayBuffer]"]=St["[object Boolean]"]=St["[object DataView]"]=St["[object Date]"]=St["[object Error]"]=St["[object Function]"]=St["[object Map]"]=St["[object Number]"]=St["[object Object]"]=St["[object RegExp]"]=St["[object Set]"]=St["[object String]"]=St["[object WeakMap]"]=!1;const Bt=function(e){return mt(e)&&Ot(e.length)&&!!St[se(e)]};const Pt=function(e){return function(t){return e(t)}};var Lt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ut=Lt&&"object"==typeof module&&module&&!module.nodeType&&module,Tt=Ut&&Ut.exports===Lt&&G.process,Ft=function(){try{var e=Ut&&Ut.require&&Ut.require("util").types;return e||Tt&&Tt.binding&&Tt.binding("util")}catch(e){}}();var Mt=Ft&&Ft.isTypedArray;const zt=Mt?Pt(Mt):Bt;var Nt=Object.prototype.hasOwnProperty;const Rt=function(e,t){var n=ct(e),r=!n&&yt(e),o=!n&&!r&&Et(e),i=!n&&!r&&!o&&zt(e),a=n||r||o||i,s=a?ft(e.length,String):[],c=s.length;for(var l in e)!t&&!Nt.call(e,l)||a&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Ct(l,c))||s.push(l);return s};var Vt=Object.prototype;const Kt=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Vt)};const Dt=function(e,t){return function(n){return e(t(n))}}(Object.keys,Object);var Ht=Object.prototype.hasOwnProperty;const $t=function(e){if(!Kt(e))return Dt(e);var t=[];for(var n in Object(e))Ht.call(e,n)&&"constructor"!=n&&t.push(n);return t};const qt=function(e){return null!=e&&Ot(e.length)&&!le(e)};const Wt=function(e){return qt(e)?Rt(e):$t(e)};const Zt=function(e){return lt(e,Wt,pt)};var Gt=Object.prototype.hasOwnProperty;const Jt=function(e,t,n,r,o,i){var a=1&n,s=Zt(e),c=s.length;if(c!=Zt(t).length&&!a)return!1;for(var l=c;l--;){var u=s[l];if(!(a?u in t:Gt.call(t,u)))return!1}var d=i.get(e),g=i.get(t);if(d&&g)return d==t&&g==e;var h=!0;i.set(e,t),i.set(t,e);for(var p=a;++l<c;){var f=e[u=s[l]],m=t[u];if(r)var b=a?r(m,f,u,t,e,i):r(f,m,u,e,t,i);if(!(void 0===b?f===m||o(f,m,n,r,i):b)){h=!1;break}p||(p="constructor"==u)}if(h&&!p){var v=e.constructor,_=t.constructor;v==_||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof _&&_ instanceof _||(h=!1)}return i.delete(e),i.delete(t),h};const Xt=Ie(X,"DataView");const Qt=Ie(X,"Promise");const Yt=Ie(X,"Set");const en=Ie(X,"WeakMap");var tn="[object Map]",nn="[object Promise]",rn="[object Set]",on="[object WeakMap]",an="[object DataView]",sn=fe(Xt),cn=fe(Ae),ln=fe(Qt),un=fe(Yt),dn=fe(en),gn=se;(Xt&&gn(new Xt(new ArrayBuffer(1)))!=an||Ae&&gn(new Ae)!=tn||Qt&&gn(Qt.resolve())!=nn||Yt&&gn(new Yt)!=rn||en&&gn(new en)!=on)&&(gn=function(e){var t=se(e),n="[object Object]"==t?e.constructor:void 0,r=n?fe(n):"";if(r)switch(r){case sn:return an;case cn:return tn;case ln:return nn;case un:return rn;case dn:return on}return t});const hn=gn;var pn="[object Arguments]",fn="[object Array]",mn="[object Object]",bn=Object.prototype.hasOwnProperty;const vn=function(e,t,n,r,o,i){var a=ct(e),s=ct(t),c=a?fn:hn(e),l=s?fn:hn(t),u=(c=c==pn?mn:c)==mn,d=(l=l==pn?mn:l)==mn,g=c==l;if(g&&Et(e)){if(!Et(t))return!1;a=!0,u=!1}if(g&&!u)return i||(i=new We),a||zt(e)?et(e,t,n,r,o,i):at(e,t,c,n,r,o,i);if(!(1&n)){var h=u&&bn.call(e,"__wrapped__"),p=d&&bn.call(t,"__wrapped__");if(h||p){var f=h?e.value():e,m=p?t.value():t;return i||(i=new We),o(f,m,n,r,i)}}return!!g&&(i||(i=new We),Jt(e,t,n,r,o,i))};const _n=function e(t,n,r,o,i){return t===n||(null==t||null==n||!mt(t)&&!mt(n)?t!=t&&n!=n:vn(t,n,r,o,e,i))};const wn=function(e,t){return _n(e,t)};function yn(e){if(Array.isArray(e)){const t=e.map(yn);return e=>t.some((t=>t(e)))}if("origin"==e){const e=a.global.window.location.origin;return t=>new URL(t,a.global.document.baseURI).origin==e}if("function"==typeof e)return e;if(e instanceof RegExp)return t=>!(!t.match(e)&&!t.replace(/^https?:\/\//,"").match(e));return()=>!1}class kn extends e.Command{constructor(e){super(e),this._wrapper=null,this._processInProgress=new Set,this._updateUiDelayed=(0,a.delay)((()=>this.editor.ui.update()),0),this.value=!1,this._canEdit=function(e){const t=yn(e);return e=>!(!e.is("element","imageInline")&&!e.is("element","imageBlock"))&&(!!e.hasAttribute("ckboxImageId")||!!e.hasAttribute("src")&&t(e.getAttribute("src")))}(e.config.get("ckbox.allowExternalImagesEditing")),this._prepareOptions=(0,a.abortableDebounce)(((e,t)=>this._prepareOptionsAbortable(e,t))),this._prepareListeners()}refresh(){const e=this.editor;this.value=this._getValue();const t=e.model.document.selection.getSelectedElement();this.isEnabled=!!t&&this._canEdit(t)&&!this._checkIfElementIsBeingProcessed(t)}execute(){if(this._getValue())return;const e=(0,a.createElement)(document,"div",{class:"ck ckbox-wrapper"});this._wrapper=e,this.value=!0,document.body.appendChild(this._wrapper);const n={element:this.editor.model.document.selection.getSelectedElement(),controller:new AbortController};this._prepareOptions(n).then((t=>window.CKBox.mountImageEditor(e,t)),(e=>{const n=this.editor,r=n.t;n.plugins.get(t.Notification).showWarning(r("Failed to determine category of edited image."),{namespace:"ckbox"}),console.error(e),this._handleImageEditorClose()}))}destroy(){this._handleImageEditorClose(),this._prepareOptions.abort(),this._updateUiDelayed.cancel();for(const e of this._processInProgress.values())e.controller.abort();super.destroy()}_getValue(){return null!==this._wrapper}async _prepareOptionsAbortable(e,t){const n=this.editor,r=n.config.get("ckbox"),o=n.plugins.get(E),{element:i}=t;let a;const s=i.getAttribute("ckboxImageId");if(s)a={assetId:s};else{const t=new URL(i.getAttribute("src"),document.baseURI).href;a={imageUrl:t,uploadCategoryId:await o.getCategoryIdForFile(t,{signal:e})}}return{...a,imageEditing:{allowOverwrite:!1},tokenUrl:r.tokenUrl,...r.serviceOrigin&&{serviceOrigin:r.serviceOrigin},onClose:()=>this._handleImageEditorClose(),onSave:e=>this._handleImageEditorSave(t,e)}}_prepareListeners(){this.listenTo(this.editor.model.document,"change:data",(()=>{this._getProcessingStatesOfDeletedImages().forEach((e=>{e.controller.abort()}))}))}_getProcessingStatesOfDeletedImages(){const e=[];for(const t of this._processInProgress.values())"$graveyard"==t.element.root.rootName&&e.push(t);return e}_checkIfElementIsBeingProcessed(e){for(const{element:t}of this._processInProgress)if(wn(t,e))return!0;return!1}_handleImageEditorClose(){this._wrapper&&(this._wrapper.remove(),this._wrapper=null,this.editor.editing.view.focus(),this._updateUiDelayed(),this.refresh())}_handleImageEditorSave(n,r){const o=this.editor.locale.t,i=this.editor.plugins.get(t.Notification),s=this.editor.plugins.get(e.PendingActions),c=s.add(o("Processing the edited image."));this._processInProgress.add(n),this._showImageProcessingIndicator(n.element,r),this.refresh(),this._waitForAssetProcessed(r.data.id,n.controller.signal).then((e=>{this._replaceImage(n.element,e)}),(e=>{this.editor.editing.reconvertItem(n.element),n.controller.signal.aborted||(!e||e instanceof a.CKEditorError?i.showWarning(o("Server failed to process the image."),{namespace:"ckbox"}):console.error(e))})).finally((()=>{this._processInProgress.delete(n),s.remove(c),this.refresh()}))}async _getAssetStatusFromServer(e,t){const n=this.editor.plugins.get(E),r=new URL("assets/"+e,this.editor.config.get("ckbox.serviceOrigin")),o=await _({url:r,signal:t,authorization:n.getToken().value}),i=o.metadata.metadataProcessingStatus;if(!i||"queued"==i)throw new a.CKEditorError("ckbox-image-not-processed");return{data:{...o}}}async _waitForAssetProcessed(e,t){const n=await(0,a.retry)((()=>this._getAssetStatusFromServer(e,t)),{signal:t,maxAttempts:5});if("success"!=n.data.metadata.metadataProcessingStatus)throw new a.CKEditorError("ckbox-image-processing-failed");return n}_showImageProcessingIndicator(e,t){const n=this.editor;n.editing.view.change((r=>{const o=n.editing.mapper.toViewElement(e),i=this.editor.plugins.get("ImageUtils").findViewImgElement(o);r.removeStyle("aspect-ratio",i),r.setAttribute("width",t.data.metadata.width,i),r.setAttribute("height",t.data.metadata.height,i),r.setStyle("width",`${t.data.metadata.width}px`,i),r.setStyle("height",`${t.data.metadata.height}px`,i),r.addClass("image-processing",o)}))}_replaceImage(e,t){const n=this.editor,{imageFallbackUrl:r,imageSources:o,imageWidth:i,imageHeight:a,imagePlaceholder:s}=k(t),c=Array.from(n.model.document.selection.getRanges());n.model.change((l=>{l.setSelection(e,"on"),n.execute("insertImage",{source:{src:r,sources:o,width:i,height:a,...s?{placeholder:s}:null,...e.hasAttribute("alt")?{alt:e.getAttribute("alt")}:null}});const u=e.getChildren();e=n.model.document.selection.getSelectedElement();for(const t of u)l.append(l.cloneElement(t),e);l.setAttribute("ckboxImageId",t.data.id,e),l.setSelection(c)}))}}class xn extends e.Plugin{static get pluginName(){return"CKBoxImageEditEditing"}static get requires(){return[O,E,e.PendingActions,t.Notification,"ImageUtils","ImageEditing"]}init(){const{editor:e}=this;e.commands.add("ckboxImageEdit",new kn(e))}}class In extends e.Plugin{static get pluginName(){return"CKBoxImageEditUI"}init(){const e=this.editor;e.ui.componentFactory.add("ckboxImageEdit",(n=>{const r=e.commands.get("ckboxImageEdit"),o=new t.ButtonView(n),i=n.t;return o.set({label:i("Edit image"),icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M1.201 1C.538 1 0 1.47 0 2.1v14.363c0 .64.534 1.037 1.186 1.037H5.06l5.058-5.078L6.617 9.15a.696.696 0 0 0-.957-.033L1.5 13.6V2.5h15v4.354a3.478 3.478 0 0 1 1.5.049V2.1c0-.63-.547-1.1-1.2-1.1H1.202Zm11.713 2.803a2.147 2.147 0 0 0-2.049 1.992 2.14 2.14 0 0 0 1.28 2.096 2.13 2.13 0 0 0 2.642-3.11 2.129 2.129 0 0 0-1.873-.978ZM8.089 17.635v2.388h2.389l7.046-7.046-2.39-2.39-7.045 7.048Zm11.282-6.507a.637.637 0 0 0 .139-.692.603.603 0 0 0-.139-.205l-1.49-1.488a.63.63 0 0 0-.899 0l-1.166 1.163 2.39 2.39 1.165-1.168Z"/></svg>',tooltip:!0}),o.bind("isOn").to(r,"value",r,"isEnabled",((e,t)=>e&&t)),o.bind("isEnabled").to(r),this.listenTo(o,"execute",(()=>{e.execute("ckboxImageEdit"),e.editing.view.focus()})),o}))}}var An=n(591),En=n.n(An),jn=n(957),Cn={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};En()(jn.A,Cn);jn.A.locals;class On extends e.Plugin{static get pluginName(){return"CKBoxImageEdit"}static get requires(){return[xn,In]}}})(),(window.CKEditor5=window.CKEditor5||{}).ckbox=r})();
|
package/dist/index.js
CHANGED
@@ -369,22 +369,54 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
369
369
|
* - tokenUrl The token endpoint URL.
|
370
370
|
* - serviceOrigin The base URL of the API service.
|
371
371
|
* - forceDemoLabel Whether to force "Powered by CKBox" link.
|
372
|
-
* - dialog.onClose The callback function invoked after closing the CKBox dialog.
|
373
372
|
* - assets.onChoose The callback function invoked after choosing the assets.
|
373
|
+
* - dialog.onClose The callback function invoked after closing the CKBox dialog.
|
374
|
+
* - dialog.width The dialog width in pixels.
|
375
|
+
* - dialog.height The dialog height in pixels.
|
376
|
+
* - categories.icons Allows setting custom icons for categories.
|
377
|
+
* - view.openLastView Sets if the last view visited by the user will be reopened
|
378
|
+
* on the next startup.
|
379
|
+
* - view.startupFolderId Sets the ID of the folder that will be opened on startup.
|
380
|
+
* - view.startupCategoryId Sets the ID of the category that will be opened on startup.
|
381
|
+
* - view.hideMaximizeButton Sets whether to hide the ‘Maximize’ button.
|
382
|
+
* - view.componentsHideTimeout Sets timeout after which upload components are hidden
|
383
|
+
* after completed upload.
|
384
|
+
* - view.dialogMinimizeTimeout Sets timeout after which upload dialog is minimized
|
385
|
+
* after completed upload.
|
374
386
|
*/ _prepareOptions() {
|
375
387
|
const editor = this.editor;
|
376
388
|
const ckboxConfig = editor.config.get('ckbox');
|
389
|
+
const dialog = ckboxConfig.dialog;
|
390
|
+
const categories = ckboxConfig.categories;
|
391
|
+
const view = ckboxConfig.view;
|
392
|
+
const upload = ckboxConfig.upload;
|
377
393
|
return {
|
378
394
|
theme: ckboxConfig.theme,
|
379
395
|
language: ckboxConfig.language,
|
380
396
|
tokenUrl: ckboxConfig.tokenUrl,
|
381
397
|
serviceOrigin: ckboxConfig.serviceOrigin,
|
382
398
|
forceDemoLabel: ckboxConfig.forceDemoLabel,
|
383
|
-
|
384
|
-
onClose: ()=>this.fire('ckbox:close')
|
385
|
-
},
|
399
|
+
choosableFileExtensions: ckboxConfig.choosableFileExtensions,
|
386
400
|
assets: {
|
387
401
|
onChoose: (assets)=>this.fire('ckbox:choose', assets)
|
402
|
+
},
|
403
|
+
dialog: {
|
404
|
+
onClose: ()=>this.fire('ckbox:close'),
|
405
|
+
width: dialog && dialog.width,
|
406
|
+
height: dialog && dialog.height
|
407
|
+
},
|
408
|
+
categories: categories && {
|
409
|
+
icons: categories.icons
|
410
|
+
},
|
411
|
+
view: view && {
|
412
|
+
openLastView: view.openLastView,
|
413
|
+
startupFolderId: view.startupFolderId,
|
414
|
+
startupCategoryId: view.startupCategoryId,
|
415
|
+
hideMaximizeButton: view.hideMaximizeButton
|
416
|
+
},
|
417
|
+
upload: upload && {
|
418
|
+
componentsHideTimeout: upload.componentsHideTimeout,
|
419
|
+
dialogMinimizeTimeout: upload.dialogMinimizeTimeout
|
388
420
|
}
|
389
421
|
};
|
390
422
|
}
|
@@ -901,9 +933,6 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
901
933
|
* The CKBox editing feature. It introduces the {@link module:ckbox/ckboxcommand~CKBoxCommand CKBox command} and
|
902
934
|
* {@link module:ckbox/ckboxuploadadapter~CKBoxUploadAdapter CKBox upload adapter}.
|
903
935
|
*/ class CKBoxEditing extends Plugin {
|
904
|
-
/**
|
905
|
-
* CKEditor Cloud Services access token.
|
906
|
-
*/ _token;
|
907
936
|
/**
|
908
937
|
* @inheritDoc
|
909
938
|
*/ static get pluginName() {
|