UNPKG

@ryzeup/richtexteditor

Version:

A React Rich Text Editor component

7 lines (5 loc) â€ĸ 42.5 kB
"use strict";var st=Object.defineProperty,ut=Object.defineProperties;var dt=Object.getOwnPropertyDescriptors;var be=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var Ce=(a,c,u)=>c in a?st(a,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[c]=u,te=(a,c)=>{for(var u in c||(c={}))mt.call(c,u)&&Ce(a,u,c[u]);if(be)for(var u of be(c))ft.call(c,u)&&Ce(a,u,c[u]);return a},ne=(a,c)=>ut(a,dt(c));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),gt=require("react-dom");function ht(a){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const u in a)if(u!=="default"){const d=Object.getOwnPropertyDescriptor(a,u);Object.defineProperty(c,u,d.get?d:{enumerable:!0,get:()=>a[u]})}}return c.default=a,Object.freeze(c)}const pt=ht(r);window.React=pt;var Me={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Re=r.createContext&&r.createContext(Me),vt=["attr","size","title"];function yt(a,c){if(a==null)return{};var u=Et(a,c),d,g;if(Object.getOwnPropertySymbols){var w=Object.getOwnPropertySymbols(a);for(g=0;g<w.length;g++)d=w[g],!(c.indexOf(d)>=0)&&Object.prototype.propertyIsEnumerable.call(a,d)&&(u[d]=a[d])}return u}function Et(a,c){if(a==null)return{};var u={};for(var d in a)if(Object.prototype.hasOwnProperty.call(a,d)){if(c.indexOf(d)>=0)continue;u[d]=a[d]}return u}function X(){return X=Object.assign?Object.assign.bind():function(a){for(var c=1;c<arguments.length;c++){var u=arguments[c];for(var d in u)Object.prototype.hasOwnProperty.call(u,d)&&(a[d]=u[d])}return a},X.apply(this,arguments)}function Se(a,c){var u=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);c&&(d=d.filter(function(g){return Object.getOwnPropertyDescriptor(a,g).enumerable})),u.push.apply(u,d)}return u}function Y(a){for(var c=1;c<arguments.length;c++){var u=arguments[c]!=null?arguments[c]:{};c%2?Se(Object(u),!0).forEach(function(d){wt(a,d,u[d])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(u)):Se(Object(u)).forEach(function(d){Object.defineProperty(a,d,Object.getOwnPropertyDescriptor(u,d))})}return a}function wt(a,c,u){return c=bt(c),c in a?Object.defineProperty(a,c,{value:u,enumerable:!0,configurable:!0,writable:!0}):a[c]=u,a}function bt(a){var c=Ct(a,"string");return typeof c=="symbol"?c:c+""}function Ct(a,c){if(typeof a!="object"||!a)return a;var u=a[Symbol.toPrimitive];if(u!==void 0){var d=u.call(a,c);if(typeof d!="object")return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return(c==="string"?String:Number)(a)}function Ae(a){return a&&a.map((c,u)=>r.createElement(c.tag,Y({key:u},c.attr),Ae(c.child)))}function A(a){return c=>r.createElement(Rt,X({attr:Y({},a.attr)},c),Ae(a.child))}function Rt(a){var c=u=>{var{attr:d,size:g,title:w}=a,R=yt(a,vt),C=g||u.size||"1em",p;return u.className&&(p=u.className),a.className&&(p=(p?p+" ":"")+a.className),r.createElement("svg",X({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},u.attr,d,R,{className:p,style:Y(Y({color:a.color||u.color},u.style),a.style),height:C,width:C,xmlns:"http://www.w3.org/2000/svg"}),w&&r.createElement("title",null,w),a.children)};return Re!==void 0?r.createElement(Re.Consumer,null,u=>c(u)):c(Me)}function St(a){return A({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M352 64c0-17.7-14.3-32-32-32L128 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32zm96 128c0-17.7-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 448c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32zM352 320c0-17.7-14.3-32-32-32l-192 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32z"},child:[]}]})(a)}function xt(a){return A({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M448 64c0 17.7-14.3 32-32 32L192 96c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32l-224 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},child:[]}]})(a)}function Lt(a){return A({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M0 96C0 60.7 28.7 32 64 32l384 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 480c-35.3 0-64-28.7-64-64L0 96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6l96 0 32 0 208 0c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"},child:[]}]})(a)}function Mt(a){return A({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M24 56c0-13.3 10.7-24 24-24l32 0c13.3 0 24 10.7 24 24l0 120 16 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-80 0c-13.3 0-24-10.7-24-24s10.7-24 24-24l16 0 0-96-8 0C34.7 80 24 69.3 24 56zM86.7 341.2c-6.5-7.4-18.3-6.9-24 1.2L51.5 357.9c-7.7 10.8-22.7 13.3-33.5 5.6s-13.3-22.7-5.6-33.5l11.1-15.6c23.7-33.2 72.3-35.6 99.2-4.9c21.3 24.4 20.8 60.9-1.1 84.7L86.8 432l33.2 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-88 0c-9.5 0-18.2-5.6-22-14.4s-2.1-18.9 4.3-25.9l72-78c5.3-5.8 5.4-14.6 .3-20.5zM224 64l256 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-256 0c-17.7 0-32-14.3-32-32s14.3-32 32-32zm0 160l256 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-256 0c-17.7 0-32-14.3-32-32s14.3-32 32-32zm0 160l256 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-256 0c-17.7 0-32-14.3-32-32s14.3-32 32-32z"},child:[]}]})(a)}function At(a){return A({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M12.83 352h262.34A12.82 12.82 0 0 0 288 339.17v-38.34A12.82 12.82 0 0 0 275.17 288H12.83A12.82 12.82 0 0 0 0 300.83v38.34A12.82 12.82 0 0 0 12.83 352zm0-256h262.34A12.82 12.82 0 0 0 288 83.17V44.83A12.82 12.82 0 0 0 275.17 32H12.83A12.82 12.82 0 0 0 0 44.83v38.34A12.82 12.82 0 0 0 12.83 96zM432 160H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0 256H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z"},child:[]}]})(a)}function zt(a){return A({attr:{viewBox:"0 0 384 512"},child:[{tag:"path",attr:{d:"M333.49 238a122 122 0 0 0 27-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h31.87v288H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 0 1 0 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 0 1 0 112z"},child:[]}]})(a)}function kt(a){return A({attr:{viewBox:"0 0 544 512"},child:[{tag:"path",attr:{d:"M0 479.98L99.92 512l35.45-35.45-67.04-67.04L0 479.98zm124.61-240.01a36.592 36.592 0 0 0-10.79 38.1l13.05 42.83-50.93 50.94 96.23 96.23 50.86-50.86 42.74 13.08c13.73 4.2 28.65-.01 38.15-10.78l35.55-41.64-173.34-173.34-41.52 35.44zm403.31-160.7l-63.2-63.2c-20.49-20.49-53.38-21.52-75.12-2.35L190.55 183.68l169.77 169.78L530.27 154.4c19.18-21.74 18.15-54.63-2.35-75.13z"},child:[]}]})(a)}function Nt(a){return A({attr:{viewBox:"0 0 320 512"},child:[{tag:"path",attr:{d:"M320 48v32a16 16 0 0 1-16 16h-62.76l-80 320H208a16 16 0 0 1 16 16v32a16 16 0 0 1-16 16H16a16 16 0 0 1-16-16v-32a16 16 0 0 1 16-16h62.76l80-320H112a16 16 0 0 1-16-16V48a16 16 0 0 1 16-16h192a16 16 0 0 1 16 16z"},child:[]}]})(a)}function Tt(a){return A({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"},child:[]}]})(a)}function Dt(a){return A({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M80 368H16a16 16 0 0 0-16 16v64a16 16 0 0 0 16 16h64a16 16 0 0 0 16-16v-64a16 16 0 0 0-16-16zm0-320H16A16 16 0 0 0 0 64v64a16 16 0 0 0 16 16h64a16 16 0 0 0 16-16V64a16 16 0 0 0-16-16zm0 160H16a16 16 0 0 0-16 16v64a16 16 0 0 0 16 16h64a16 16 0 0 0 16-16v-64a16 16 0 0 0-16-16zm416 176H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-320H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 160H176a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h320a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z"},child:[]}]})(a)}function Ot(a){return A({attr:{viewBox:"0 0 496 512"},child:[{tag:"path",attr:{d:"M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm80 168c17.7 0 32 14.3 32 32s-14.3 32-32 32-32-14.3-32-32 14.3-32 32-32zm-160 0c17.7 0 32 14.3 32 32s-14.3 32-32 32-32-14.3-32-32 14.3-32 32-32zm194.8 170.2C334.3 380.4 292.5 400 248 400s-86.3-19.6-114.8-53.8c-13.6-16.3 11-36.7 24.6-20.5 22.4 26.9 55.2 42.2 90.2 42.2s67.8-15.4 90.2-42.2c13.4-16.2 38.1 4.2 24.6 20.5z"},child:[]}]})(a)}function Ht(a){return A({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M464 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM224 416H64v-96h160v96zm0-160H64v-96h160v96zm224 160H288v-96h160v96zm0-160H288v-96h160v96z"},child:[]}]})(a)}function jt(a){return A({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M32 64h32v160c0 88.22 71.78 160 160 160s160-71.78 160-160V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H272a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h32v160a80 80 0 0 1-160 0V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H32a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16zm400 384H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z"},child:[]}]})(a)}function _t(a){return A({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M2 20h20v4H2v-4zm3.49-3h2.42l1.27-3.58h5.65L16.09 17h2.42L13.25 3h-2.5L5.49 17zm4.42-5.61 2.03-5.79h.12l2.03 5.79H9.91z"},child:[]}]})(a)}function Pt(a){return A({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"},child:[]},{tag:"path",attr:{d:"M20 8V5H6.39l3 3h1.83l-.55 1.28 2.09 2.1L14.21 8zM3.41 4.86 2 6.27l6.97 6.97L6.5 19h3l1.57-3.66L16.73 21l1.41-1.41z"},child:[]}]})(a)}const Ft=["😀","😁","😂","đŸ¤Ŗ","😃","😄","😅","😉","😊","😍","😘","😜","😎","đŸ˜ĸ","😭","😡","🤔","🙄","😇","đŸĨ°","🤩","🤗","😴","😋","đŸ˜Ŧ","🤤","đŸ˜ļ‍đŸŒĢī¸","😷","🤕","🤑","🤠","😈","đŸ‘ģ","💀","🤖","đŸļ","🐱","đŸŧ","🐸","đŸĻ„","🐷","đŸĩ","🐰","đŸ¯","đŸĻ","🐮","🌞","🌙","⭐","🌈","đŸ”Ĩ","💧","â„ī¸","⚡","â˜€ī¸","🌸","🌹","🍎","🍕","🍩","🍔","🍟","🍇","🍉","🍓","🍒","đŸĨ­","đŸĨ‘","🎉","🎂","🎁","🎈","đŸŽļ","đŸŽĩ","🏆","âšŊ","🏀","🏸","🏏","đŸ•šī¸","👋","🤚","đŸ–ī¸","✋","🖖","👍","👎","👌","🤌","🤏","✊","👊","🤛","🤜","â˜ī¸","👆","👇","👈","👉","🤟","🤘","🤙","🙌","👏","🙏","âœī¸","💅","🤲","👏","đŸĢļ","👐"],ze=({exec:a,saveSelection:c,handleFileChange:u,handleFontSizeChange:d,handleFontFamilyChange:g,insertEmoji:w,handleLink:R,removeFormatting:C,visibleActions:p,className:D,style:j})=>{var I,T;const z=r.useRef(null),H=r.useRef(null),x=r.useRef(null),[V,U]=r.useState(!1),[F,P]=r.useState({x:0,y:0});r.useEffect(()=>{const m=b=>{!b.target.closest(".rte-emoji-popup")&&!b.target.closest("button[title='Emoji']")&&U(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);const _=m=>{var O;m.preventDefault();const b=m.currentTarget.dataset.command;if(b)switch(b){case"bold":case"italic":case"underline":case"insertUnorderedList":case"insertOrderedList":case"removeFormat":a(b);break;case"insertImage":{(O=z.current)==null||O.click();break}default:console.warn("Unknown command:",b)}},Z=m=>{a("foreColor",m.target.value)},Q=m=>{a("backColor",m.target.value)},[M,k]=r.useState({bold:!1,italic:!1,underline:!1,unorderedList:!1,orderedList:!1,alignLeft:!1,alignCenter:!1,alignRight:!1,removeFormat:!1,link:!1,image:!1,emoji:!1,table:!1,color:!1,highlight:!1});return r.useEffect(()=>{const m=()=>{k({bold:document.queryCommandState("bold"),italic:document.queryCommandState("italic"),underline:document.queryCommandState("underline"),unorderedList:document.queryCommandState("insertUnorderedList"),orderedList:document.queryCommandState("insertOrderedList"),alignLeft:document.queryCommandState("justifyLeft"),alignCenter:document.queryCommandState("justifyCenter"),alignRight:document.queryCommandState("justifyRight"),removeFormat:document.queryCommandState("removeFormat"),link:document.queryCommandState("createLink"),image:document.queryCommandState("insertImage"),emoji:document.queryCommandState("insertEmoji"),table:document.queryCommandState("insertTable"),color:document.queryCommandState("foreColor"),highlight:document.queryCommandState("backColor")})};return document.addEventListener("selectionchange",m),()=>document.removeEventListener("selectionchange",m)},[]),r.createElement("div",{className:`rte-toolbar ${D||""}`,style:j},p.bold&&r.createElement("button",{"data-command":"bold",title:"Bold",onMouseDown:_,className:M.bold?"rte-active":""},r.createElement(zt,null)),p.italic&&r.createElement("button",{"data-command":"italic",title:"Italic",onMouseDown:_,className:M.italic?"rte-active":""},r.createElement(Nt,null)),p.underline&&r.createElement("button",{"data-command":"underline",title:"Underline",onMouseDown:_,className:M.underline?"rte-active":""},r.createElement(jt,null)),p.unorderedList&&r.createElement("button",{"data-command":"insertUnorderedList",onMouseDown:_,title:"UnorderedList",className:M.unorderedList?"rte-active":""},r.createElement(Dt,null)),p.orderedList&&r.createElement("button",{"data-command":"insertOrderedList",title:"OrderedList",onMouseDown:_,className:M.orderedList?"rte-active":""},r.createElement(Mt,null)),p.link&&r.createElement("button",{"data-command":"createLink",title:"Link",onClick:R,className:M.link?"rte-active":""},r.createElement(Tt,null)),p.removeFormat&&r.createElement("button",{"data-command":"Remove format",title:"removeFormat",onMouseDown:m=>{m.preventDefault(),c(),C()},className:M.removeFormat?"rte-active":""},r.createElement(Pt,null)),p.image&&r.createElement("button",{"data-command":"insertImage",title:"Image",onMouseDown:_,className:M.image?"rte-active":""},r.createElement(Lt,null)),r.createElement("input",{type:"file",accept:"image/*",ref:z,style:{display:"none"},onChange:u}),p.emoji&&r.createElement("div",{style:{position:"relative"}},r.createElement("button",{title:"Emoji",onMouseDown:m=>{m.preventDefault(),c();const b=m.currentTarget.getBoundingClientRect();P({x:b.left,y:b.bottom+8}),U(O=>!O)},className:M.emoji?"rte-active":""},r.createElement(Ot,null)),V&&gt.createPortal(r.createElement("div",{className:"rte-emoji-popup",style:{top:F.y,left:F.x}},Ft.map((m,b)=>r.createElement("span",{key:b,style:{fontSize:"20px",cursor:"pointer",textAlign:"center"},onMouseDown:O=>{O.preventDefault(),w(m),U(!1)}},m))),document.body)),p.color&&r.createElement("div",{style:{position:"relative"}},r.createElement("button",{title:"Text Color",onMouseDown:m=>{var b;m.preventDefault(),c(),(b=H.current)==null||b.click()},style:{display:"flex",alignItems:"center",justifyContent:"center",color:((I=H.current)==null?void 0:I.value)||"#000",fontSize:"18px"},className:M.color?"rte-active":""},r.createElement(_t,null)),r.createElement("input",{ref:H,type:"color",defaultValue:"#000000",onChange:m=>{var b;Z(m),((b=m.target.parentElement)==null?void 0:b.querySelector("button")).style.color=m.target.value},style:{position:"absolute",opacity:0,width:0,height:0,pointerEvents:"none"}})),p.highlight&&r.createElement("div",{style:{position:"relative"}},r.createElement("button",{title:"Highlight",onMouseDown:m=>{var b;m.preventDefault(),c(),(b=x.current)==null||b.click()},style:{display:"flex",alignItems:"center",justifyContent:"center",color:((T=x.current)==null?void 0:T.value)||"#000",fontSize:"18px"},className:M.highlight?"rte-active":""},r.createElement(kt,null)),r.createElement("input",{ref:x,type:"color",onChange:m=>{var b;Q(m),((b=m.target.parentElement)==null?void 0:b.querySelector("button")).style.color=m.target.value},defaultValue:"#000000",style:{position:"absolute",opacity:0,width:0,height:0,pointerEvents:"none"}})),p.align&&r.createElement(r.Fragment,null,r.createElement("button",{title:"Align Left",onMouseDown:m=>m.preventDefault(),onClick:()=>a("justifyLeft"),className:M.alignLeft?"rte-active":""},r.createElement(At,null)),r.createElement("button",{title:"Align Center",onMouseDown:m=>m.preventDefault(),onClick:()=>a("justifyCenter"),className:M.alignCenter?"rte-active":""},r.createElement(St,null)),r.createElement("button",{title:"Align Right",onMouseDown:m=>m.preventDefault(),onClick:()=>a("justifyRight"),className:M.alignRight?"rte-active":""},r.createElement(xt,null))),p.table&&r.createElement("button",{title:"Insert Table",onMouseDown:m=>m.preventDefault(),onClick:()=>a("insertTable"),className:M.table?"rte-active":""},r.createElement(Ht,null)),p.fontFamily&&r.createElement("select",{className:"rte-dropdown",defaultValue:"",onMouseDown:()=>c(),onChange:g},r.createElement("option",{value:"",disabled:!0},"Font Family"),r.createElement("option",{value:"Arial"},"Arial"),r.createElement("option",{value:"Georgia"},"Georgia"),r.createElement("option",{value:"Times New Roman"},"Times New Roman"),r.createElement("option",{value:"Courier New"},"Courier New"),r.createElement("option",{value:"Verdana"},"Verdana")),p.fontSize&&r.createElement("select",{className:"rte-dropdown rte-fontsize-dropdown",defaultValue:"",onMouseDown:()=>c(),onChange:d},r.createElement("option",{value:"",disabled:!0},"Font Size"),Array.from({length:16},(m,b)=>10+b).map(m=>r.createElement("option",{key:m,value:m},m,"px"))))},It=({show:a,position:c,filtered:u,insertMention:d,onClose:g,query:w})=>{const R=r.useRef(null);return r.useEffect(()=>{const C=p=>{R.current&&!R.current.contains(p.target)&&g()};return a&&document.addEventListener("mousedown",C),()=>{document.removeEventListener("mousedown",C)}},[a,g]),a?r.createElement("ul",{ref:R,className:"rte-popup",style:{top:c.y,left:c.x}},u.length>0?u.map(({name:C,value:p})=>{const D=C.toLowerCase(),j=w.toLowerCase(),z=D.indexOf(j);let H=C;if(z!==-1&&w.length>0){const x=z+w.length;H=C.substring(0,z)+`<span class="rte-highlight">${C.substring(z,x)}</span>`+C.substring(x)}return r.createElement("li",{key:p,onMouseDown:x=>{x.preventDefault(),d({name:C,value:p})},style:{padding:"6px 12px",cursor:"pointer",fontSize:"14px"},dangerouslySetInnerHTML:{__html:H},onMouseEnter:x=>x.currentTarget.style.background="#f0f0f0",onMouseLeave:x=>x.currentTarget.style.background="#fff"})}):r.createElement("li",{style:{padding:"6px 12px",color:"#999"}},"No matches")):null};function xe(a){return A({attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Circle_Minus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M15,11.5h0a.5.5,0,0,1,0,1H9a.5.5,0,0,1,0-1Z"},child:[]},{tag:"path",attr:{d:"M12,21.934A9.933,9.933,0,1,1,21.932,12,9.945,9.945,0,0,1,12,21.934ZM12,3.068A8.933,8.933,0,1,0,20.932,12,8.944,8.944,0,0,0,12,3.068Z"},child:[]}]}]}]})(a)}function K(a){return A({attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Circle_Plus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M15,12.5H12.5V15a.5.5,0,0,1-1,0V12.5H9a.5.5,0,0,1,0-1h2.5V9a.5.5,0,0,1,1,0v2.5H15A.5.5,0,0,1,15,12.5Z"},child:[]},{tag:"path",attr:{d:"M12,21.932A9.934,9.934,0,1,1,21.932,12,9.944,9.944,0,0,1,12,21.932ZM12,3.065A8.934,8.934,0,1,0,20.932,12,8.944,8.944,0,0,0,12,3.065Z"},child:[]}]}]}]})(a)}const Bt=({visible:a,x:c,y:u,onAction:d,onClose:g})=>{if(!a)return null;const w={top:u,left:c};return r.createElement("div",{style:w,className:"rte-table-menu",onMouseLeave:g},r.createElement("button",{onClick:()=>d("insertRowAbove")},r.createElement(K,null)," Insert row above"),r.createElement("button",{onClick:()=>d("insertRowBelow")},r.createElement(K,null)," Insert row below"),r.createElement("button",{onClick:()=>d("insertColLeft")},r.createElement(K,null)," Insert col left"),r.createElement("button",{onClick:()=>d("insertColRight")},r.createElement(K,null)," Insert col right"),r.createElement("button",{onClick:()=>d("deleteRow")},r.createElement(xe,null)," Delete row"),r.createElement("button",{onClick:()=>d("deleteCol")},r.createElement(xe,null)," Delete column"))},ke=({html:a,className:c,style:u})=>{const d=w=>{const R=w.target;if(R.tagName==="A"){w.preventDefault();const C=R.href;C&&window.open(C,"_blank","noopener,noreferrer")}},g=w=>{let R=w.replace(/{{\s*(.*?)\s*}}/g,(C,p)=>`<span style="color: blue">${p}</span>`);return R=R.replace(/#arrayData/g,""),R=R.replace(/\/arrayData/g,""),R};return r.createElement("div",{className:`rte-preview ${c||""}`,style:u,onClick:d,dangerouslySetInnerHTML:{__html:g(a)}})},qt=({visible:a,linkData:c,onClose:u,onInsert:d})=>{const[g,w]=r.useState(""),[R,C]=r.useState(""),[p,D]=r.useState(""),[j,z]=r.useState("_self");if(r.useEffect(()=>{a?(w(c.url||""),C(c.text||""),D(c.title||""),z(c.target||"_self")):(w(""),C(""),D(""),z("_self"))},[a,c]),!a)return null;const H=()=>{d({url:g,text:R,title:p,target:j})};return r.createElement(r.Fragment,null,r.createElement("div",{className:"rte-link-modal-overlay",onClick:u}),r.createElement("div",{className:"rte-link-modal"},r.createElement("h4",{className:"rte-link-modal__title"},g?"Edit Link":"Insert Link"),r.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"URL",value:g,onChange:x=>w(x.target.value)}),r.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"Text to Display",value:R,onChange:x=>C(x.target.value)}),r.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"Title",value:p,onChange:x=>D(x.target.value)}),r.createElement("select",{className:"rte-link-modal__select",value:j,onChange:x=>z(x.target.value)},r.createElement("option",{value:"_self"},"Same tab"),r.createElement("option",{value:"_blank"},"New tab")),r.createElement("div",{className:"rte-link-modal__actions"},r.createElement("button",{className:"rte-link-modal__btn",onClick:u},"Cancel"),r.createElement("button",{className:"rte-link-modal__btn rte-link-modal__btn--ok",onClick:H},"OK"))))};function Le(a){return Array.from(new Map(a.map(c=>[c.value,c])).values())}const Ut=({atSuggestions:a=[],showOutput:c=!1,showPreview:u=!1,toolbarConfig:d={link:!1,image:!1,emoji:!1,table:!1,color:!1,fontFamily:!1,fontSize:!1,highlight:!1},classNames:g={},styles:w={},handleGetHtml:R=()=>{},onChange:C=()=>{},value:p,onMentionSelect:D=()=>{},handleAddAttributes:j=()=>{}})=>{var me,fe,ge,he,pe,ve,ye,Ee;const z=r.useRef(null),[H,x]=r.useState(p!=null&&p.length?p:" "),[V,U]=r.useState(""),[F,P]=r.useState(!1),[_,Z]=r.useState({x:0,y:0}),[Q,M]=r.useState([]),k=r.useRef(null),I=r.useRef(null),[T,m]=r.useState({visible:!1,x:0,y:0}),[b,O]=r.useState(!1),$=r.useRef(null),[Ne,re]=r.useState({url:"",text:"",title:"",target:"_self"}),Te={bold:!0,italic:!0,underline:!0,removeFormat:!0,unorderedList:!0,orderedList:!0,align:!0,link:(me=d.link)!=null?me:!1,image:(fe=d.image)!=null?fe:!1,emoji:(ge=d.emoji)!=null?ge:!1,table:(he=d.table)!=null?he:!1,color:(pe=d.color)!=null?pe:!1,fontFamily:(ve=d.fontFamily)!=null?ve:!1,fontSize:(ye=d.fontSize)!=null?ye:!1,highlight:(Ee=d.fontSize)!=null?Ee:!1},[De,ae]=r.useState(""),[oe,J]=r.useState([]),N=()=>z.current,L=()=>{const e=Oe(),t=/^<div[^>]*style=["'][^"']*font-size\s*:\s*\d+px[^"']*["'][^>]*>/.test(e.trim());let n=e;t||(n=`<div style="font-size:12px">${e}</div>`),U(n),R==null||R(n);const o=at(e);C(o);const s=Ve(),l=Le(s);JSON.stringify(l)!==JSON.stringify(oe)&&(J(l),D(l))},Oe=()=>{const e=N();if(!e)return H;const t=e.cloneNode(!0);t.querySelectorAll("table div").forEach(o=>o.remove()),t.querySelectorAll(".rte-cell-highlight").forEach(o=>o.classList.remove("rte-cell-highlight"));let n=t.innerHTML;return n=He(n),n},He=e=>e.replace(/<tbody[^>]*>/g,"<tbody>{{#arrayData}}").replace(/<\/tbody>/g,"{{/arrayData}}</tbody>"),B=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return;const t=document.getElementById("rte-editor-body");if(!t)return;const n=e.getRangeAt(0);t.contains(n.startContainer)&&(k.current=n.cloneRange())},q=()=>{const e=window.getSelection();!e||!k.current||(e.removeAllRanges(),e.addRange(k.current))},le=(e,t)=>{const n=window.getSelection();n&&n.rangeCount>0&&(k.current=n.getRangeAt(0)),q(),document.execCommand(e,!1,t),L()};r.useEffect(()=>{const e=N();if(!e||!p)return;const t=je(p);e.innerHTML=t,L()},[]);const je=e=>e.replace(/<span[^>]*data-hidden-table-start[^>]*>.*?<\/span>/g,"").replace(/<span[^>]*data-hidden-table-end[^>]*>.*?<\/span>/g,"").replace(/{{#arrayData}}/g,"").replace(/{{\/arrayData}}/g,"");r.useEffect(()=>()=>{document.removeEventListener("mousemove",null),document.removeEventListener("mouseup",null)},[]),r.useEffect(()=>{j&&j(e=>{Ue(e)})},[]),r.useEffect(()=>{const e=N();if(!e)return;e.querySelectorAll("table").forEach(n=>{ue(n),n.querySelectorAll("th, td").forEach(s=>W(s))})},[]);const ce=e=>{for(;e&&e.nodeName!=="LI";)e=e.parentNode;return e},_e=e=>{let t=0,n=e.parentElement;for(;n;)(n.tagName==="UL"||n.tagName==="OL")&&t++,n=n.parentElement;return t},Pe=e=>{const t=e.querySelector("li"),n=t?_e(t):1;if(e.querySelector("[data-hidden-array-start]"))return;const o=`{{#arrayData${n>1?n:""}}}`,s=`{{/arrayData${n>1?n:""}}}`,l=document.createElement("span");l.textContent=o,l.style.display="none",l.setAttribute("data-hidden-array-start","true"),e.insertBefore(l,e.firstChild);const i=document.createElement("span");i.textContent=s,i.style.display="none",i.setAttribute("data-hidden-array-end","true"),e.appendChild(i)},ie=e=>{var v;const t=window.getSelection();if(!(t!=null&&t.rangeCount))return;const n=t.getRangeAt(0),o=ce(n.startContainer);let s,l;if(o){let h=o.querySelector(e);h||(h=document.createElement(e),h.style.margin="0",h.style.paddingLeft="20px",o.appendChild(h)),l=h,s=document.createElement("li"),s.textContent="​",l.appendChild(s)}else{document.execCommand(e==="ul"?"insertUnorderedList":"insertOrderedList");const h=N();if(l=h==null?void 0:h.querySelector(`${e}:last-child`),!l)return;s=l.querySelector("li:last-child")}Pe(l);const i=document.createRange();i.setStart(s,0),i.collapse(!0),t.removeAllRanges(),t.addRange(i),(v=N())==null||v.focus(),L()},G=(e,t)=>{e==="insertOrderedList"?ie("ol"):e==="insertUnorderedList"?ie("ul"):e.startsWith("justify")?lt(e):le(e,t),e==="insertTable"&&Ze()},Fe=e=>{const t=document.createElement("span");t.textContent="​",e.insertNode(t),e.setStartAfter(t),e.collapse(!0);const n=t.getBoundingClientRect();t.remove(),Z({x:n.left,y:n.bottom+window.scrollY}),M(a||[]),P(!0),I.current=e.cloneRange()},Ie=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.anchorNode;let n=e.anchorOffset;if(!t)return null;let o=t;for(o.nodeType!==Node.TEXT_NODE&&(o.childNodes&&o.childNodes[n]?o=o.childNodes[n]:o=t.previousSibling);o;){if(o.nodeType===Node.TEXT_NODE){const s=o.textContent||"",l=o===t?n:s.length,i=s.lastIndexOf("@",l-1);if(i!==-1){const v=document.createRange();return v.setStart(o,i),v.setEnd(o,l),v}}o=o.previousSibling}return null},Be=e=>{var l;const t=window.getSelection();if(!t)return;const n=Ie();n?(t.removeAllRanges(),t.addRange(n)):I.current&&(t.removeAllRanges(),t.addRange(I.current));const o=document.createElement("span");o.textContent=`{{${e.name}}}`,o.style.display="inline",o.setAttribute("data-mention",e.value||e.name||"");try{const i=t.rangeCount?t.getRangeAt(0):null;if(i)i.deleteContents(),i.insertNode(o);else{const E=document.createRange(),f=N();E.selectNodeContents(f),E.collapse(!1),E.insertNode(o)}const v=document.createTextNode(" ");o.after(v);const h=document.createRange();h.setStartAfter(v),h.collapse(!0),t.removeAllRanges(),t.addRange(h)}catch(i){console.error("insertMention error:",i)}let s=Le([...oe,e]);J(s),D(s),P(!1),(l=N())==null||l.focus(),L()},qe=e=>{const t=N();if(!t)return;let n=null;k.current&&t.contains(k.current.startContainer)?n=k.current.cloneRange():(n=document.createRange(),n.selectNodeContents(t),n.collapse(!1));const o=window.getSelection();if(!o)return;o.removeAllRanges(),o.addRange(n);const s=document.createElement("span");s.textContent=`{{${e.name}}}`,s.style.display="inline",s.setAttribute("data-mention",e.value||e.name),n.insertNode(s);const l=document.createTextNode(" ");s.after(l);const i=document.createRange();i.setStartAfter(l),i.collapse(!0),o.removeAllRanges(),o.addRange(i),k.current=i.cloneRange(),t.focus()},Ue=e=>{e.forEach(t=>qe(t)),J(t=>{const n=[...t,...e],o=Array.from(new Map(n.map(s=>[s.name,s])).values());return D(o),o}),L()},Ve=()=>{const e=N();if(!e)return[];const t=e.querySelectorAll("span[data-mention]"),n=[];return t.forEach(o=>{const s=o.getAttribute("data-mention")||"",i=(o.textContent||"").match(/{{(.+?)}}/);i&&n.push({name:i[1],value:s})}),n},$e=e=>{var n,o,s;const t=e.key.toLowerCase();if((e.ctrlKey||e.metaKey)&&["b","i","u"].includes(t)&&(e.preventDefault(),G(t==="b"?"bold":t==="i"?"italic":t==="u"?"underline":"")),e.shiftKey&&e.key==="2"&&e.preventDefault(),e.key==="Enter"){const l=window.getSelection(),i=l!=null&&l.anchorNode?ce(l.anchorNode):null;if(!i)return;if(((n=i.textContent)==null?void 0:n.replace(/\u200B/g,"").trim())===""){e.preventDefault();const h=i.parentElement,E=h==null?void 0:h.closest("li");if(E){h==null||h.removeChild(i);const f=document.createElement("p");f.innerHTML="<br />",(o=E.parentElement)==null||o.insertBefore(f,E.nextSibling);const y=document.createRange();y.setStart(f,0),y.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(y)}else{const f=i.closest("ul, ol");if(f){const y=document.createElement("p");y.innerHTML="<br />",(s=f.parentElement)==null||s.insertBefore(y,f.nextSibling),f.removeChild(i);const S=document.createRange();S.setStart(y,0),S.collapse(!0),l==null||l.removeAllRanges(),l==null||l.addRange(S)}}L()}}},We=e=>{if(e.data==="@"){const n=window.getSelection();if(!(n!=null&&n.rangeCount))return;const o=n.anchorNode;if(Ke(o))return;setTimeout(()=>{Fe(n.getRangeAt(0)),ae(""),M(a),P(!0)},0);return}if(F){setTimeout(()=>se(),0);return}},Ke=e=>{if(!e)return!1;let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;t;){if(t.tagName==="TH")return!0;t=t.parentElement}return!1},se=()=>{if(L(),!F)return;const e=window.getSelection();if(!e||!e.anchorNode)return;const n=(e.anchorNode.textContent||"").match(/@([a-zA-Z0-9_]*)$/);if(!n){P(!1);return}const o=n[1].toLowerCase();ae(o);const s=a.filter(l=>l.name.toLowerCase().includes(o));M(s)},Xe=e=>{var o;const t=(o=e.target.files)==null?void 0:o[0];if(!t)return;const n=new FileReader;n.onload=s=>{var S;const l=(S=s.target)==null?void 0:S.result;q();const i=window.getSelection();let v=i&&i.rangeCount?i.getRangeAt(0):null;const h=document.createElement("img");h.src=l,h.alt=t.name||"image",h.className="rte-inserted-image",h.contentEditable="true";const E=N();if(!v||!E){E==null||E.appendChild(h);const we=document.createTextNode(" ");E==null||E.appendChild(we);const ee=document.createRange();ee.setStartAfter(we),ee.collapse(!0),i==null||i.removeAllRanges(),i==null||i.addRange(ee),E==null||E.focus(),L(),e.target.value="";return}v.deleteContents(),v.insertNode(h);const f=document.createTextNode(" ");h.after(f);const y=document.createRange();y.setStartAfter(f),y.collapse(!0),i.removeAllRanges(),i.addRange(y),E.focus(),L(),e.target.value=""},n.readAsDataURL(t)},Ye=e=>{var s;q();const t=window.getSelection();if(!(t!=null&&t.rangeCount))return;const n=t.getRangeAt(0),o=document.createTextNode(e);n.insertNode(o),n.setStartAfter(o),n.collapse(!0),t.removeAllRanges(),t.addRange(n),(s=N())==null||s.focus(),L()},Ze=()=>{var E;q();const e=document.createElement("table");e.style.borderCollapse="collapse",e.style.width="100%",e.style.border="1px solid #ccc",e.style.margin="8px 0",e.style.position="relative",e.style.textAlign="center",g.table&&e.classList.add(g.table);const t=document.createElement("thead");g.thead&&t.classList.add(g.thead);const n=document.createElement("tbody");g.tbody&&n.classList.add(g.tbody);const o=document.createElement("tr");g.tr&&o.classList.add(g.tr);const s=document.createElement("tr");g.tr&&s.classList.add(g.tr);for(let f=0;f<2;f++){const y=document.createElement("th");y.textContent=`Header ${f+1}`,y.style.border="1px solid #999",y.style.padding="4px",y.style.position="relative",y.style.backgroundColor="lightgray",g.th&&y.classList.add(g.th);const S=document.createElement("td");S.textContent=`Row 1 Col ${f+1}`,S.style.border="1px solid #999",S.style.padding="4px",S.style.position="relative",S.style.backgroundColor="#fff",g.td&&S.classList.add(g.td),W(y),W(S),o.appendChild(y),s.appendChild(S)}t.appendChild(o),n.appendChild(s),e.appendChild(t),e.appendChild(n),ue(e);const l=window.getSelection();if(!(l!=null&&l.rangeCount))return;const i=l.getRangeAt(0);i.collapse(!1),i.insertNode(e);const v=document.createElement("p");v.innerHTML="<br/>",e.after(v);const h=document.createRange();h.setStart(v,0),h.collapse(!0),l.removeAllRanges(),l.addRange(h),(E=N())==null||E.focus(),L()},ue=e=>{const t=document.createElement("div");Object.assign(t.style,{position:"absolute",width:"14px",height:"14px",right:"0",bottom:"0",background:"rgba(0,0,0,0.25)",cursor:"nwse-resize",zIndex:"20",borderRadius:"2px"}),t.style.userSelect="none",t.contentEditable="false";let n=0,o=0,s=0,l=0;t.addEventListener("mousedown",i=>{i.preventDefault(),n=i.clientX,o=i.clientY;const v=e.getBoundingClientRect();s=v.width,l=v.height;const h=f=>{const y=Math.max(100,s+(f.clientX-n)),S=Math.max(60,l+(f.clientY-o));e.style.width=`${y}px`,e.style.height=`${S}px`,L()},E=()=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E),L()};document.addEventListener("mousemove",h),document.addEventListener("mouseup",E)}),e.appendChild(t)},W=e=>{const t=document.createElement("div"),n=document.createElement("div");Object.assign(t.style,{position:"absolute",right:"0",top:"0",width:"6px",height:"100%",cursor:"col-resize",background:"rgba(0,0,0,0.15)",zIndex:"10",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none",pointerEvents:"auto"}),t.contentEditable="false",Object.assign(n.style,{position:"absolute",bottom:"0",left:"0",width:"100%",height:"6px",cursor:"row-resize",background:"rgba(0,0,0,0.15)",zIndex:"10",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none",pointerEvents:"auto"}),n.contentEditable="false",Qe(e,t,n),e.appendChild(t),e.appendChild(n)},Qe=(e,t,n)=>{let o=0,s=0,l=0,i=0;t.addEventListener("mousedown",f=>{f.preventDefault(),o=f.clientX,l=e.offsetWidth,document.addEventListener("mousemove",v),document.addEventListener("mouseup",E)}),n.addEventListener("mousedown",f=>{f.preventDefault(),s=f.clientY,i=e.offsetHeight,document.addEventListener("mousemove",h),document.addEventListener("mouseup",E)});const v=f=>{const y=l+(f.clientX-o);e.style.width=`${Math.max(30,y)}px`,L()},h=f=>{const y=i+(f.clientY-s);e.style.height=`${Math.max(20,y)}px`,L()},E=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E),L()}},Je=e=>{const n=e.target.closest("td, th");n&&(e.preventDefault(),document.querySelectorAll(".rte-cell-highlight").forEach(o=>o.classList.remove("rte-cell-highlight")),n.classList.add("rte-cell-highlight"),m({visible:!0,x:e.clientX,y:e.clientY,cell:n}))},de=()=>{document.querySelectorAll(".rte-cell-highlight").forEach(e=>e.classList.remove("rte-cell-highlight"))},Ge=e=>{if(!T.cell)return;const t=T.cell.closest("table"),n=T.cell.cellIndex,o=T.cell.parentElement.rowIndex,s=l=>{const i=l.tagName.toLowerCase(),v=document.createElement(i);return v.textContent=l.textContent||"",v.style.cssText=l.style.cssText,W(v),v};switch(e){case"insertRowAbove":{const l=t.rows[o],i=t.insertRow(o);Array.from(l.cells).forEach(v=>{i.appendChild(s(v))});break}case"insertRowBelow":{const l=t.rows[o],i=t.insertRow(o+1);Array.from(l.cells).forEach(v=>{i.appendChild(s(v))});break}case"insertColLeft":{Array.from(t.rows).forEach(l=>{const i=l.cells[n];l.insertBefore(s(i),i)});break}case"insertColRight":{Array.from(t.rows).forEach(l=>{const i=l.cells[n];l.insertBefore(s(i),i.nextSibling)});break}case"deleteRow":t.rows.length>1&&t.deleteRow(o);break;case"deleteCol":Array.from(t.rows).forEach(l=>{l.cells[n]&&l.deleteCell(n)});break}L(),m(ne(te({},T),{visible:!1})),de()},et=()=>{B(),$.current=k.current,re({url:"",text:"",title:"",target:"_self"}),O(!0)},tt=e=>{const t=window.getSelection();if(!t||!$.current)return;t.removeAllRanges(),t.addRange($.current);let n=e.url.trim();/^https?:\/\//i.test(n)||(n="https://"+n);const o=document.createElement("a");o.href=n,o.style.cursor="pointer",o.style.outline="none",o.textContent=e.text||n,o.title=e.title,o.target=e.target,o.contentEditable="true";const s=t.getRangeAt(0);s.deleteContents(),s.insertNode(o);const l=document.createTextNode(" ");o.after(l);const i=document.createRange();i.setStartAfter(l),i.collapse(!0),t.removeAllRanges(),t.addRange(i),O(!1),L()},nt=e=>{const t=e.target;if(t.tagName==="A"){const n=t;if(e.ctrlKey||e.metaKey){window.open(n.href,"_blank","noopener,noreferrer");return}e.preventDefault();const o=document.createRange();o.selectNode(n),$.current=o,re({url:n.href,text:n.textContent||n.href,title:n.title,target:n.target}),O(!0)}},rt=()=>{const e=N();if(!e)return;const t=window.getSelection();if((!t||t.rangeCount===0)&&k.current){const f=window.getSelection();f==null||f.removeAllRanges(),f==null||f.addRange(k.current)}const n=window.getSelection();if(!n||n.rangeCount===0)return;const o=n.getRangeAt(0);q(),document.execCommand("removeFormat",!1);const s=o.cloneContents(),l=document.createElement("div");l.appendChild(s);const i=document.createTreeWalker(l,NodeFilter.SHOW_ELEMENT,null),v=[];for(;i.nextNode();){const f=i.currentNode,y=f.tagName.toUpperCase(),S=f.getAttribute&&f.getAttribute("data-mention")!==null;y!=="A"&&!S&&v.push(f)}for(let f=v.length-1;f>=0;f--){const y=v[f],S=y.parentNode;if(S){for(;y.firstChild;)S.insertBefore(y.firstChild,y);S.removeChild(y)}}l.querySelectorAll("[style]").forEach(f=>f.removeAttribute("style")),o.deleteContents();const h=document.createDocumentFragment();for(;l.firstChild;)h.appendChild(l.firstChild);o.insertNode(h);const E=document.createRange();E.setStartAfter(o.endContainer.nodeType===Node.TEXT_NODE?o.endContainer:o.startContainer),E.collapse(!0),n.removeAllRanges(),n.addRange(E),e.normalize(),L()},at=e=>{var o;let t=e;t=t.replace(/{{#arrayData\d*}}/g,""),t=t.replace(/{{\/arrayData\d*}}/g,"");const n=document.createElement("div");return n.innerHTML=t,n.querySelectorAll("br").forEach(s=>{s.replaceWith(` `)}),n.querySelectorAll("p, div, tr").forEach(s=>{s.insertAdjacentText("afterend",` `)}),n.querySelectorAll("table").forEach(s=>{s.insertAdjacentText("afterend",` `)}),((o=n.textContent)==null?void 0:o.replace(/\n{3,}/g,` `).trim())||""};function ot(){const e=window.getSelection();if(!e||e.rangeCount===0)return[];const t=e.getRangeAt(0),n=t.commonAncestorContainer,o=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return Array.from(o.querySelectorAll("td, th")).filter(l=>{const i=document.createRange();return i.selectNodeContents(l),t.compareBoundaryPoints(Range.END_TO_START,i)<0&&t.compareBoundaryPoints(Range.START_TO_END,i)>0})}function lt(e){const t=ot();if(t.length===0){le(e);return}let n="left";e==="justifyCenter"&&(n="center"),e==="justifyRight"&&(n="right"),t.forEach(o=>{o.style.textAlign=n}),L()}const ct=e=>{const t=e.clipboardData.items;for(let n=0;n<t.length;n++){const o=t[n];if(o.kind==="file"&&o.type.startsWith("image/")){e.preventDefault();return}o.kind==="string"&&o.getAsString(s=>{/<img\s/i.test(s)&&e.preventDefault()})}},it=e=>{q();const t=window.getSelection();if(!t||!t.rangeCount)return;const n=t.getRangeAt(0),o=document.createElement("span");o.style.fontSize=`${e}px`,o.appendChild(n.extractContents()),n.insertNode(o);const s=document.createRange();s.setStartAfter(o),s.collapse(!0),t.removeAllRanges(),t.addRange(s),L()};return r.createElement("div",{className:`rte-wrapper ${(g==null?void 0:g.wrapper)||""}`,style:w.wrapper},r.createElement("div",{style:{flex:1}},r.createElement(ze,{exec:G,saveSelection:B,handleFileChange:Xe,handleFontSizeChange:e=>it(e.target.value),handleFontFamilyChange:e=>G("fontName",e.target.value),insertEmoji:Ye,handleLink:et,removeFormatting:rt,visibleActions:Te,className:g.toolbar,style:w.toolbar}),r.createElement("div",{ref:z,id:"rte-editor-body",className:`rte-editor ${(g==null?void 0:g.editor)||""}`,style:w.editor,contentEditable:!0,suppressContentEditableWarning:!0,onPaste:ct,onKeyUp:B,onMouseUp:B,onInput:()=>{se(),B()},onKeyDown:$e,onBeforeInput:We,onContextMenu:Je,onClick:e=>{nt(e),B()}}),r.createElement(It,{show:F,position:_,filtered:Q,insertMention:Be,onClose:()=>P(!1),query:De}),c&&r.createElement("div",{className:`rte-output ${(g==null?void 0:g.output)||""}`,style:w.output},r.createElement("h4",null,"Output HTML:"),r.createElement("p",null,V)),r.createElement(Bt,{visible:T.visible,x:T.x,y:T.y,onAction:Ge,onClose:()=>{m(ne(te({},T),{visible:!1})),de()}}),r.createElement(qt,{visible:b,linkData:Ne,onClose:()=>O(!1),onInsert:tt})),u?r.createElement(ke,{className:g.preview,style:w.preview,html:V}):null)};exports.RichTextEditor=Ut;exports.RtePreview=ke;exports.RteToolbar=ze;