/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{b as c}from"./HVT2WBVC.js";import{G as n,h as r,i as s,q as i,t as o}from"./FFF5HUPM.js";import"./EXBEKVP5.js";var p=`
  .ck.ck-reset.ck-editor.ck-rounded-corners {
    margin-top: 10px !important;
    margin-left: 55px !important;
  }
  .ck-editor__editable {
    height: 70px !important;
    font-size: 0.875rem !important;
    line-height: 	1.375 !important;
    color: var(--calcite-color-text-1) !important;
  }

  .ck.ck-editor__editable_inline>:first-child,
  .ck.ck-editor__editable_inline>:last-child {
    --ck-spacing-large: 0.5rem !important;
  }

  .ck.ck-balloon-panel.ck-powered-by-balloon {
    --ck-z-modal: 700;
    z-index: 700;
  }

  .calcite-mode-dark .ck-editor__editable {
    color: var(--calcite-color-text-inverse) !important;
  }
`,h=r`@layer{:host{display:block}}`,d="instant-apps-components__ckeditor-wrapper",a=class extends n{constructor(){super(...arguments),this.dataChanged=i(),this.isFocused=i()}static{this.properties={value:1,editorInstance:0,config:0}}static{this.styles=h}static{this.shadowRootOptions=o}willUpdate(t){!t.has("value")||!this.editorInstance||this.syncEditorData()}loaded(){this.init()}init(){this.applyStyles(),this.initEditor()}applyStyles(){if(document.getElementById(d))return;let t=document.createElement("style");t.id=d,t.innerHTML=p,document.head.prepend(t)}async initEditor(){let t=await this.createEditor();t&&(this.editorInstance=t,this.syncEditorData(),t.editing.view.document.on("change:isFocused",this.getEditorFocusedCallback(t)))}async createEditor(){try{let t;return this.config?t=await ClassicEditor.create(this.el,this.config):t=await ClassicEditor.create(this.el),this.editorInstance=t,t}catch(t){return console.error(t),await Promise.reject(new Error("Failed to create editor"))}}getEditorFocusedCallback(t){return(u,k,l)=>{if(l)this.isFocused.emit();else{let e=t.getData();this.value!==e&&(this.value=e,this.dataChanged.emit(e))}}}syncEditorData(){if(!this.editorInstance)return;let t=this.value??"";this.editorInstance.getData()!==t&&this.editorInstance.setData(t)}render(){return s`<div></div>`}};c("instant-apps-ckeditor-wrapper",a);export{a as InstantAppsCkeditorWrapper};
