editor_advanced_image-8.x-2.x-dev/js/build/editorAdvancedImage.js
js/build/editorAdvancedImage.js
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CKEditor5=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.editorAdvancedImage=e())}(self,(()=>(()=>{var t={"ckeditor5/src/core.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/icons.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/icons.js")},"ckeditor5/src/ui.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/utils.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/utils.js")},"dll-reference CKEditor5.dll":t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(s){var o=e[s];if(void 0!==o)return o.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};return(()=>{"use strict";i.d(s,{default:()=>h});var t=i("ckeditor5/src/core.js");class e extends t.Command{constructor(t,e){super(t),this.options=e}refresh(){const t=this.editor.plugins.get("ImageUtils").getClosestSelectedImageElement(this.editor.model.document.selection);this.isEnabled=!!t,this.attributes={title:!1,id:!1,class:!1},this.isEnabled&&(t.hasAttribute("title")&&(this.attributes.title=t.getAttribute("title")),t.hasAttribute("class")&&(this.attributes.class=t.getAttribute("class")),t.hasAttribute("id")&&(this.attributes.id=t.getAttribute("id")),!1===this.attributes.class&&void 0!==this.options&&void 0!==this.options.defaults.class&&(this.attributes.class=this.options.defaults.class),this.execute(this.attributes))}execute(t){const e=this.editor,i=e.plugins.get("ImageUtils"),s=e.model,o=i.getClosestSelectedImageElement(s.document.selection);!1!==t.title&&s.change((e=>e.setAttribute("title",t.title,o))),!1!==t.id&&s.change((e=>e.setAttribute("id",t.id,o))),!1!==t.class&&s.change((e=>e.setAttribute("class",t.class,o)))}}class o extends t.Plugin{static get requires(){return["ImageUtils"]}static get pluginName(){return"EditorAdvancedImageEditing"}init(){const t=this.editor,i=t.config.get("editorAdvancedImageOptions");this._defineSchema(),this._defineConverters(),t.commands.add("EditorAdvancedImageCmd",new e(t,i))}_defineSchema(){const{editor:t}=this,{schema:e}=t.model;e.isRegistered("imageInline")&&e.extend("imageInline",{allowAttributes:["title","class","id"]}),e.isRegistered("imageBlock")&&e.extend("imageBlock",{allowAttributes:["title","class","id"]})}_defineConverters(){const{editor:t}=this,{conversion:e}=this.editor,{schema:i}=t.model;e.for("upcast").attributeToAttribute({model:"title",view:"title"}),e.for("upcast").attributeToAttribute({model:"id",view:"id"}),e.for("upcast").attributeToAttribute({model:"class",view:"class"}),e.for("downcast").add(function(){function t(t,e,i){const{item:s,attributeKey:o}=e,{consumable:r,writer:l}=i;if(!r.consume(s,t.name))return;const a=i.mapper.toViewElement(s),n=Array.from(a.getChildren()).find((t=>"img"===t.name));l.setAttribute(o,e.attributeNewValue,n||a)}return e=>{e.on("attribute:title",t),e.on("attribute:class",t),e.on("attribute:id",t)}}())}}var r=i("ckeditor5/src/ui.js");function l(t){const e=t.editing.view,i=r.BalloonPanelView.defaultPositions,s=t.plugins.get("ImageUtils");return{target:e.domConverter.mapViewToDom(s.getClosestSelectedImageWidget(e.document.selection)),positions:[i.northArrowSouth,i.northArrowSouthWest,i.northArrowSouthEast,i.southArrowNorth,i.southArrowNorthWest,i.southArrowNorthEast,i.viewportStickyNorth]}}var a=i("ckeditor5/src/utils.js"),n=i("ckeditor5/src/icons.js");class d extends r.View{constructor(t,e){super(t),this.options=e,this.children=this.createCollection(),this.keystrokes=new a.KeystrokeHandler,this.classAttrInput=this._createLabeledInputView("CSS classes","List of CSS classes to be added to the image, separated by spaces."),this.titleAttrInput=this._createLabeledInputView("Title","Populates the title attribute of the image, usually shown as a small tooltip on hover."),this.idAttrInput=this._createLabeledInputView("ID","Usually used to linking to this content using a https://en.wikipedia.org/wiki/Fragment_identifier. Must be unique on the page."),this.saveButtonView=this._createButton(Drupal.t("Save"),n.IconCheck,"ck-button-save","save"),this.cancelButtonView=this._createButton(Drupal.t("Cancel"),n.IconCancel,"ck-button-cancel","cancel"),this.children.add(new r.FormHeaderView(t,{label:this.t("Editor Advanced Image")})),this.children.add(this._createRowView([this._createLabelView("Properties")])),this.options.allowedAttributes.includes("class")&&this.children.add(this._createRowView([this.classAttrInput])),this.options.allowedAttributes.includes("title")&&this.children.add(this._createRowView([this.titleAttrInput])),this.options.allowedAttributes.includes("id")&&this.children.add(this._createRowView([this.idAttrInput])),this.children.add(this._createRowView([this.saveButtonView,this.cancelButtonView],["ck-table-form__action-row"])),this.setTemplate({tag:"form",attributes:{class:["ck","ck-form","ck-editor-advanced-image"],tabindex:"-1"},children:this.children})}destroy(){super.destroy(),this.keystrokes.destroy()}_createLabelView(t){const e=new r.LabelView(this.locale);return e.text=Drupal.t(t),e}_createButton(t,e,i,s){const o=new r.ButtonView(this.locale);return o.set({label:t,icon:e,withText:!0}),o.extendTemplate({attributes:{class:i}}),s&&o.delegate("execute").to(this,s),o}_createLabeledInputView(t,e){const i=new r.LabeledFieldView(this.locale,r.createLabeledInputText);return i.label=Drupal.t(t),i.infoText=Drupal.t(e),i}_createRowView(t,e){const i=new r.View;return i.setTemplate({tag:"div",attributes:{class:["ck","ck-form__row",void 0!==e?e:""]},children:t}),i}}class c extends t.Plugin{static get requires(){return[r.ContextualBalloon]}init(){const t=this.editor.config.get("editorAdvancedImageOptions");void 0!==t&&void 0!==t.disable_balloon&&t.disable_balloon||(this._createButton(),this._createForm())}destroy(){super.destroy(),this._form.destroy()}_createButton(){const t=this.editor;t.ui.componentFactory.add("editorAdvancedImageButton",(e=>{const i=t.commands.get("EditorAdvancedImageCmd"),s=new r.ButtonView(e);return s.set({label:Drupal.t("Editor Advanced Image"),icon:n.IconThreeVerticalDots,tooltip:!0}),s.bind("isVisible").to(i,"isEnabled"),this.listenTo(s,"execute",(()=>{this._showForm()})),s}))}_createForm(){const t=this.editor,e=t.config.get("editorAdvancedImageOptions");this._balloon=this.editor.plugins.get("ContextualBalloon"),this._form=new d(t.locale,e),this._form.render(),this.listenTo(this._form,"save",(()=>{t.execute("EditorAdvancedImageCmd",{title:!!e.allowedAttributes.includes("title")&&this._form.titleAttrInput.fieldView.element.value,class:!!e.allowedAttributes.includes("class")&&this._form.classAttrInput.fieldView.element.value,id:!!e.allowedAttributes.includes("id")&&this._form.idAttrInput.fieldView.element.value}),this._hideForm(!0)})),this.listenTo(this._form,"cancel",(()=>{this._hideForm(!0)})),this._form.keystrokes.set("Esc",((t,e)=>{this._hideForm(!0),e()})),(0,r.clickOutsideHandler)({emitter:this._form,activator:()=>this._isVisible,contextElements:[this._balloon.view.element],callback:()=>this._hideForm()})}_showForm(){if(this._isVisible)return;const t=this.editor,e=t.commands.get("EditorAdvancedImageCmd"),i=t.config.get("editorAdvancedImageOptions");this._isInBalloon||this._balloon.add({view:this._form,position:l(t)}),i.allowedAttributes.includes("title")&&(this._form.titleAttrInput.fieldView.element.value=e.attributes.title||"",this._form.titleAttrInput.fieldView.value=this._form.titleAttrInput.fieldView.element.value),i.allowedAttributes.includes("class")&&(this._form.classAttrInput.fieldView.element.value=e.attributes.class||"",this._form.classAttrInput.fieldView.value=this._form.classAttrInput.fieldView.element.value),i.allowedAttributes.includes("id")&&(this._form.idAttrInput.fieldView.element.value=e.attributes.id||"",this._form.idAttrInput.fieldView.value=this._form.idAttrInput.fieldView.element.value)}_hideForm(t){this._isInBalloon&&(this._balloon.remove(this._form),t&&this.editor.editing.view.focus())}get _isVisible(){return this._balloon.visibleView===this._form}get _isInBalloon(){return this._balloon.hasView(this._form)}}class u extends t.Plugin{static get requires(){return[o,c,e]}static get pluginName(){return"EditorAdvancedImage"}}const h={EditorAdvancedImage:u}})(),s=s.default})()));