!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.ai_balloon_menu=t())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/ui.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/utils.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/utils.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(o){var l=t[o];if(void 0!==l)return l.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,i),n.exports}i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var o={};return(()=>{"use strict";i.d(o,{default:()=>s});var e=i("ckeditor5/src/core.js"),t=i("ckeditor5/src/ui.js");var l=i("ckeditor5/src/utils.js");class n extends e.Plugin{static get requires(){return[t.ContextualBalloon]}init(){this.editor.config.get("ai_ckeditor_ai")&&(this._balloon=this.editor.plugins.get(t.ContextualBalloon),this._createMenuView(),this._enableBalloonMenuOnSelection())}_createMenuView(){const e=this.editor,i=this.editor.config.get("ai_ckeditor_ai"),o=e.locale,n=new l.Collection;void 0!==i.plugins&&Object.keys(i.plugins).forEach((function(e){i.plugins[e].enabled&&n.add({type:"button",model:{isEnabled:i.plugins[e].enabled,label:i.plugins[e].meta.label,withText:!0,command:"AiDrupalDialog",group:"ai_ckeditor_ai",plugin_id:e}})})),this.menuView=(0,t.createDropdown)(o),this.menuView.buttonView.set({label:"AI Assistant",withText:!0,tooltip:!1,icon:'<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">\n  <g fill="#000000">\n    <path d="m121.59 60.83-13.93-4.49c-8.91-2.94-14.13-10.15-16.58-19.21l-6.13-29.86c-.16-.59-.55-1.38-1.75-1.38-1.01 0-1.59.79-1.75 1.38l-6.13 29.87c-2.46 9.06-7.67 16.27-16.58 19.21l-13.93 4.49c-1.97.64-2 3.42-.04 4.09l14.03 4.83c8.88 2.95 14.06 10.15 16.52 19.17l6.14 29.53c.16.59.49 1.65 1.75 1.65 1.33 0 1.59-1.06 1.75-1.65l6.14-29.53c2.46-9.03 7.64-16.23 16.52-19.17l14.03-4.83c1.94-.68 1.91-3.46-.06-4.1z"/>\n    <path d="m41.81 86.81c-8.33-2.75-9.09-5.85-10.49-11.08l-3.49-12.24c-.21-.79-2.27-.79-2.49 0l-2.37 11.31c-1.41 5.21-4.41 9.35-9.53 11.04l-8.16 3.54c-1.13.37-1.15 1.97-.02 2.35l8.22 2.91c5.1 1.69 8.08 5.83 9.5 11.02l2.37 10.82c.22.79 2.27.79 2.48 0l2.78-10.77c1.41-5.22 3.57-9.37 10.5-11.07l7.72-2.91c1.13-.39 1.12-1.99-.02-2.36z"/>\n    <path d="m59.74 28.14c.56-.19.54-.99-.03-1.15l-7.72-2.08c-1.62-.44-2.88-1.69-3.34-3.3l-3.04-12.55c-.15-.61-1.02-.61-1.17.01l-2.86 12.5c-.44 1.66-1.74 2.94-3.4 3.37l-7.67 1.99c-.57.15-.61.95-.05 1.15l8.09 2.8c1.45.5 2.57 1.68 3.01 3.15l2.89 11.59c.15.6 1.01.61 1.16 0l2.99-11.63c.45-1.47 1.58-2.64 3.04-3.13z"/>\n  </g>\n</svg>\n'}),(0,t.addListToDropdown)(this.menuView,n),this.listenTo(this.menuView,"execute",(e=>{this.editor.execute(e.source.command,e.source.group,e.source.plugin_id,e.source.label),this._hideMenu()})),(0,t.clickOutsideHandler)({emitter:this.menuView,activator:()=>this._balloon.visibleView===this.menuView,contextElements:[this._balloon.view.element],callback:()=>this._hideMenu()})}_enableBalloonMenuOnSelection(){const e=this.editor,t=e.model.document.selection;this.listenTo(t,"change:range",(()=>{const i=e.commands.get("AiDrupalDialog");t.hasOwnRange&&!t.isCollapsed&&i.isEnabled?setTimeout((()=>{t.hasOwnRange&&!t.isCollapsed&&this._showMenu()}),200):this._hideMenu()}))}_showMenu(){if(this._balloon.hasView(this.menuView))return;const e=this.editor.model.document.selection;e.hasOwnRange&&!e.isCollapsed&&this._balloon.add({view:this.menuView,position:this._getBalloonPositionData()})}_hideMenu(){this._balloon.hasView(this.menuView)&&this._balloon.remove(this.menuView)}_getBalloonPositionData(){const e=this.editor.editing.view,t=e.document;return{target:e.domConverter.viewRangeToDom(t.selection.getFirstRange())}}}const s={AiBalloonMenu:n}})(),o=o.default})()));