import{r as t,c as i,h as s,H as e}from"./p-a0569a5f.js";let h=class{constructor(s){t(this,s),this.change=i(this,"change",7),this.lastBackspaceKeyDown=i(this,"lastBackspaceKeyDown",7),this.arrowDown=i(this,"arrowDown",7),this.arrowUp=i(this,"arrowUp",7),this.isContentCleared=!1,this.lastCursorPosition=void 0,this.getValue=()=>this.quill.root.innerHTML,this.onTextChange=()=>{1===this.quill.getLength()&&(setTimeout((()=>this.isContentCleared=!0),100),this.overlayMenu.hide()),this.retainPosition(),this.change.emit({id:this.id,value:{text:this.getValue()}})},this.retainPosition=()=>this.lastCursorPosition=this.quill.getSelection(),this.onTextSelectionChange=t=>{if(!t)return void this.overlayMenu.hide();if(0==t.length)return void this.overlayMenu.hide();const i=this.quill.getFormat(t);this.overlayMenu.show(t,i)}}componentDidLoad(){var t;this.quill=new Quill(`#editor-${this.id}`,{placeholder:null===(t=this.value)||void 0===t?void 0:t.placeholder}),this.quill.on("text-change",this.onTextChange),this.quill.on("selection-change",this.onTextSelectionChange),this.quill.clipboard.dangerouslyPasteHTML(this.value.text)}async focusOnInput(){this.quill.setSelection(this.lastCursorPosition||this.quill.getLength(),0,"silent")}async getRawValue(){return this.quill.getText()}render(){return s(e,{onKeyDown:t=>{"Backspace"===t.key&&this.isContentCleared?this.lastBackspaceKeyDown.emit(t):"ArrowDown"===t.key?this.quill.getSelection().index+1===this.quill.getLength()&&this.arrowDown.emit(t):"ArrowUp"===t.key?0===this.quill.getSelection().index&&this.arrowUp.emit(t):"Enter"===t.key&&this.lastCursorPosition&&(this.lastCursorPosition=Object.assign(Object.assign({},this.lastCursorPosition),{index:this.lastCursorPosition.index+1}))}},s("div",{id:`editor-${this.id}`}),s("dvn-rich-editor-overlay-menu",{enabledActions:this.editorSettings.blockSettings.text.textSelectionOptions,ref:t=>this.overlayMenu=t,onOverlayMenuAction:(t,i,s)=>{if("link"===i)this.quill.formatText(t.index,t.length,i,s);else{const s=this.quill.getFormat(t);this.quill.format(i,!(null==s?void 0:s[i]))}}}))}};h.style="dvn-rich-editor-text-block{display:block;-ms-flex:1;flex:1;position:relative}dvn-rich-editor-text-block .ql-editor{line-height:24px}dvn-rich-editor-text-block .ql-editor.ql-blank::before{color:var(--color-text-secondary);content:attr(data-placeholder);font-style:italic;left:0;pointer-events:none;position:absolute;right:15px}dvn-rich-editor-text-block .ql-editor *:first-child{margin-top:0}dvn-rich-editor-text-block .ql-editor *:last-child{margin-bottom:0}dvn-rich-editor-text-block .ql-clipboard{display:none}";export{h as dvn_rich_editor_text_block}