import{__extends as e,__awaiter as r,__generator as t}from"../../node_modules/tslib/tslib.es6.js";import n,{forwardRef as o,useRef as l,useMemo as i,useImperativeHandle as a,useState as s,useEffect as u}from"react";import c from"../../node_modules/react-modal-promise/lib/index.es.js";import{UrlPickerModal as d}from"./UrlPicker/UrlPicker.js";import{ColorPickerModal as p}from"./ColorPicker/ColorPicker.js";var m=o((function(o,b){var f=null,x=l(null),h=function(e){return r(void 0,void 0,void 0,(function(){var r,n,l,i;return t(this,(function(t){switch(t.label){case 0:return r=x.current.getEditor(),e?(n=r.getSelection(),o.setIsCustomHandlerFired&&o.setIsCustomHandlerFired(!0),[4,d().then((function(e){return e}))]):[3,2];case 1:return l=t.sent(),o.setIsCustomHandlerFired&&o.setIsCustomHandlerFired(!1),null==n||0===n.length?[2]:(null!=l&&null!=l.url&&(i=l.url,r.format("link",i)),[3,3]);case 2:r.format("link",!1),t.label=3;case 3:return[2]}}))}))},g=function(e){return r(void 0,void 0,void 0,(function(){var r,n,l;return t(this,(function(t){switch(t.label){case 0:return r=x.current.getEditor(),e?(o.setIsCustomHandlerFired&&o.setIsCustomHandlerFired(!0),[4,p({}).then((function(e){return e}))]):[3,2];case 1:return null!=(n=t.sent())&&null!=n.color&&(l=n.color,r.format("color",l)),o.setIsCustomHandlerFired&&o.setIsCustomHandlerFired(!1),[3,3];case 2:r.format("color",!1),t.label=3;case 3:return[2]}}))}))},v=i((function(){return{toolbar:{container:[[{header:"1"},{header:"2"},{font:[]}],[{size:[]}],["bold","italic","underline","color","strike","blockquote"],[{list:"ordered"},{list:"bullet"},{indent:"-1"},{indent:"+1"}],["link","image","video"],["clean"]],handlers:{link:h,color:g}},clipboard:{matchVisual:!1}}}),[]),k=function(e){for(var r=[],t=0,n=e.split("</p>");t<n.length;t++){var o=n[t];o&&r.push(o)}for(var l="",i=0,a=0,s=r;a<s.length;a++){var u=s[a];""!==u&&(l+=u,i<r.length-1&&(l+="<br>")),i++}return l&&l.startsWith("<p>")&&(l+="</p>"),l};a(b,(function(){return{forwardChangedText:function(){if(o.onTextEditorChange){var e=k(C);o.onTextEditorChange(e)}}}}));var q=s(o.content||""),C=q[0],E=q[1];if(u((function(){C&&"string"==typeof C&&E(C.replaceAll("<br><br>","<br>"))}),[C]),document){(f=require("react-quill")).Quill.debug("error");var F=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return e(t,r),t.create=function(e){var t=r.create.call(this,e);return e=this.sanitize(e),t.setAttribute("href",e),e.startsWith("/")&&t.removeAttribute("target"),t},t}(f.Quill.import("formats/link"));f.Quill.register(F)}var w=f;return w?n.createElement("div",{className:o.type,lumo:o.lumo||""},n.createElement(c,null),n.createElement(w,{ref:x,theme:o.theme?o.theme:"bubble",onChange:function(e){if(E(e),!o.liveEdit){var r=k(e);o.onTextEditorChange(r)}},style:o.style,defaultValue:C,modules:v,formats:m.formats,bounds:document.body,placeholder:"Replace this text"}),n.createElement("style",{global:!0,jsx:!0},"\n          .ql-tooltip {\n            border-radius: 4px !important;\n            background: #fff !important;\n            box-shadow: rgb(50 50 93 / 1%) 0px 0px 0px 1px, rgb(50 50 93 / 10%) 0px 7px 14px 0px,\n              rgb(0 0 0 / 2%) 0px 3px 6px 0px;\n          }\n          .ql-toolbar {\n            color: rgb(100, 108, 116) !important;\n          }\n          .ql-bubble .ql-stroke {\n            stroke: #16324c !important;\n            stroke-width: 1px !important;\n          }\n          .ql-toolbar .ql-picker-label {\n            color: rgb(100, 108, 116) !important;\n          }\n          .ql-toolbar .ql-fill {\n            fill: #0c9ccb !important;\n          }\n\n          .ql-bubble .ql-picker-options {\n            border: 1px solid #e3e8ee;\n            background: #fff !important;\n            border-radius: 4px;\n          }\n          .ql-bubble .ql-picker-options .ql-picker-item {\n            color: #16324c !important;\n          }\n\n          .ql-editor {\n            overflow: visible;\n            padding: 0 !important;\n          }\n\n          .ql-container.ql-bubble:not(.ql-disabled) a::before {\n            border-radius: 4px !important;\n            background: #fff !important;\n            color: #525f7f !important;\n            font-family: JetBrainsMono, Menlo, 'Bitstream Vera Sans Mono', 'Ubuntu Mono', Consolas, 'Courier New',\n              Courier, monospace;\n            box-shadow: rgb(50 50 93 / 1%) 0px 0px 0px 1px, rgb(50 50 93 / 10%) 0px 7px 14px 0px,\n              rgb(0 0 0 / 2%) 0px 3px 6px 0px;\n          }\n        ")):n.createElement(n.Fragment,null)}));m.formats=["header","font","size","bold","italic","underline","color","strike","blockquote","list","bullet","indent","link","image","video"];export default m;
//# sourceMappingURL=TextEditorQuill.js.map
