var __awaiter=this&&this.__awaiter||function(t,e,i,n){function o(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,r){function l(t){try{s(n.next(t))}catch(t){r(t)}}function a(t){try{s(n["throw"](t))}catch(t){r(t)}}function s(t){t.done?i(t.value):o(t.value).then(l,a)}s((n=n.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,o,r,l;return l={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(l[Symbol.iterator]=function(){return this}),l;function a(t){return function(e){return s([t,e])}}function s(l){if(n)throw new TypeError("Generator is already executing.");while(i)try{if(n=1,o&&(r=l[0]&2?o["return"]:l[0]?o["throw"]||((r=o["return"])&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;if(o=0,r)l=[l[0]&2,r.value];switch(l[0]){case 0:case 1:r=l;break;case 4:i.label++;return{value:l[1],done:false};case 5:i.label++;o=l[1];l=[0];continue;case 7:l=i.ops.pop();i.trys.pop();continue;default:if(!(r=i.trys,r=r.length>0&&r[r.length-1])&&(l[0]===6||l[0]===2)){i=0;continue}if(l[0]===3&&(!r||l[1]>r[0]&&l[1]<r[3])){i.label=l[1];break}if(l[0]===6&&i.label<r[1]){i.label=r[1];r=l;break}if(r&&i.label<r[2]){i.label=r[2];i.ops.push(l);break}if(r[2])i.ops.pop();i.trys.pop();continue}l=e.call(t,i)}catch(t){l=[6,t];o=0}finally{n=r=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:true}}};import{r as registerInstance,c as createEvent,h,H as Host}from"./index-55faf181.js";var dvnRichEditorTextBlockCss="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:rgba(0, 0, 0, 0.6);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}";var DvnRichEditor=function(){function t(t){var e=this;registerInstance(this,t);this.change=createEvent(this,"change",7);this.lastBackspaceKeyDown=createEvent(this,"lastBackspaceKeyDown",7);this.arrowDown=createEvent(this,"arrowDown",7);this.arrowUp=createEvent(this,"arrowUp",7);this.isContentCleared=false;this.lastCursorPosition=undefined;this.getValue=function(){return e.quill.root.innerHTML};this.onTextChange=function(){if(e.quill.getLength()===1){setTimeout((function(){return e.isContentCleared=true}),100);e.overlayMenu.hide()}e.retainPosition();e.change.emit({id:e.id,value:{text:e.getValue()}})};this.retainPosition=function(){return e.lastCursorPosition=e.quill.getSelection()};this.onTextSelectionChange=function(t){if(!t){e.overlayMenu.hide();return}if(t.length==0){e.overlayMenu.hide();return}var i=e.quill.getFormat(t);e.overlayMenu.show(t,i)}}t.prototype.componentDidLoad=function(){var t;this.quill=new Quill("#editor-"+this.id,{placeholder:(t=this.value)===null||t===void 0?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)};t.prototype.focusOnInput=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.quill.setSelection(this.lastCursorPosition||this.quill.getLength(),0,"silent");return[2]}))}))};t.prototype.getRawValue=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.quill.getText()]}))}))};t.prototype.render=function(){var t=this;return h(Host,{onKeyDown:function(e){if(e.key==="Backspace"&&t.isContentCleared){t.lastBackspaceKeyDown.emit(e)}else if(e.key==="ArrowDown"){if(t.quill.getSelection().index+1===t.quill.getLength()){t.arrowDown.emit(e)}}else if(e.key==="ArrowUp"){if(t.quill.getSelection().index===0){t.arrowUp.emit(e)}}else if(e.key==="Enter"&&t.lastCursorPosition){t.lastCursorPosition=Object.assign(Object.assign({},t.lastCursorPosition),{index:t.lastCursorPosition.index+1})}}},h("div",{id:"editor-"+this.id}),h("dvn-rich-editor-overlay-menu",{enabledActions:this.editorSettings.blockSettings.text.textSelectionOptions,ref:function(e){return t.overlayMenu=e},onOverlayMenuAction:function(e,i,n){if(i==="link"){t.quill.formatText(e.index,e.length,i,n)}else{var o=t.quill.getFormat(e);t.quill.format(i,!((o===null||o===void 0?void 0:o[i])||false))}}}))};return t}();DvnRichEditor.style=dvnRichEditorTextBlockCss;export{DvnRichEditor as dvn_rich_editor_text_block};