UNPKG

@ryzeup/richtexteditor

Version:

A React Rich Text Editor component

7 lines (5 loc) â€ĸ 42.8 kB
(function(A,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],t):(A=typeof globalThis!="undefined"?globalThis:A||self,t(A.RichTextEditor={},A.React,A.ReactDOM))})(this,(function(A,t,O){"use strict";var Bt=Object.defineProperty,qt=Object.defineProperties;var Rt=Object.getOwnPropertyDescriptors;var Ne=Object.getOwnPropertySymbols;var Ut=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var De=(A,t,O)=>t in A?Bt(A,t,{enumerable:!0,configurable:!0,writable:!0,value:O}):A[t]=O,re=(A,t)=>{for(var O in t||(t={}))Ut.call(t,O)&&De(A,O,t[O]);if(Ne)for(var O of Ne(t))Vt.call(t,O)&&De(A,O,t[O]);return A},oe=(A,t)=>qt(A,Rt(t));function Oe(o){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const d in o)if(d!=="default"){const u=Object.getOwnPropertyDescriptor(o,d);Object.defineProperty(c,d,u.get?u:{enumerable:!0,get:()=>o[d]})}}return c.default=o,Object.freeze(c)}const je=Oe(t);window.React=je;var le={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ae=t.createContext&&t.createContext(le),He=["attr","size","title"];function _e(o,c){if(o==null)return{};var d=Pe(o,c),u,g;if(Object.getOwnPropertySymbols){var w=Object.getOwnPropertySymbols(o);for(g=0;g<w.length;g++)u=w[g],!(c.indexOf(u)>=0)&&Object.prototype.propertyIsEnumerable.call(o,u)&&(d[u]=o[u])}return d}function Pe(o,c){if(o==null)return{};var d={};for(var u in o)if(Object.prototype.hasOwnProperty.call(o,u)){if(c.indexOf(u)>=0)continue;d[u]=o[u]}return d}function W(){return W=Object.assign?Object.assign.bind():function(o){for(var c=1;c<arguments.length;c++){var d=arguments[c];for(var u in d)Object.prototype.hasOwnProperty.call(d,u)&&(o[u]=d[u])}return o},W.apply(this,arguments)}function ie(o,c){var d=Object.keys(o);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(o);c&&(u=u.filter(function(g){return Object.getOwnPropertyDescriptor(o,g).enumerable})),d.push.apply(d,u)}return d}function K(o){for(var c=1;c<arguments.length;c++){var d=arguments[c]!=null?arguments[c]:{};c%2?ie(Object(d),!0).forEach(function(u){Fe(o,u,d[u])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(d)):ie(Object(d)).forEach(function(u){Object.defineProperty(o,u,Object.getOwnPropertyDescriptor(d,u))})}return o}function Fe(o,c,d){return c=Ie(c),c in o?Object.defineProperty(o,c,{value:d,enumerable:!0,configurable:!0,writable:!0}):o[c]=d,o}function Ie(o){var c=Be(o,"string");return typeof c=="symbol"?c:c+""}function Be(o,c){if(typeof o!="object"||!o)return o;var d=o[Symbol.toPrimitive];if(d!==void 0){var u=d.call(o,c);if(typeof u!="object")return u;throw new TypeError("@@toPrimitive must return a primitive value.")}return(c==="string"?String:Number)(o)}function se(o){return o&&o.map((c,d)=>t.createElement(c.tag,K({key:d},c.attr),se(c.child)))}function k(o){return c=>t.createElement(qe,W({attr:K({},o.attr)},c),se(o.child))}function qe(o){var c=d=>{var{attr:u,size:g,title:w}=o,S=_e(o,He),C=g||d.size||"1em",p;return d.className&&(p=d.className),o.className&&(p=(p?p+" ":"")+o.className),t.createElement("svg",W({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},d.attr,u,S,{className:p,style:K(K({color:o.color||d.color},d.style),o.style),height:C,width:C,xmlns:"http://www.w3.org/2000/svg"}),w&&t.createElement("title",null,w),o.children)};return ae!==void 0?t.createElement(ae.Consumer,null,d=>c(d)):c(le)}function Re(o){return k({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:[]}]})(o)}function Ue(o){return k({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:[]}]})(o)}function Ve(o){return k({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:[]}]})(o)}function $e(o){return k({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:[]}]})(o)}function We(o){return k({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:[]}]})(o)}function Ke(o){return k({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:[]}]})(o)}function Xe(o){return k({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:[]}]})(o)}function Ye(o){return k({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:[]}]})(o)}function Ze(o){return k({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:[]}]})(o)}function Qe(o){return k({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:[]}]})(o)}function Je(o){return k({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:[]}]})(o)}function Ge(o){return k({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:[]}]})(o)}function et(o){return k({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:[]}]})(o)}function tt(o){return k({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:[]}]})(o)}function nt(o){return k({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:[]}]})(o)}const rt=["😀","😁","😂","đŸ¤Ŗ","😃","😄","😅","😉","😊","😍","😘","😜","😎","đŸ˜ĸ","😭","😡","🤔","🙄","😇","đŸĨ°","🤩","🤗","😴","😋","đŸ˜Ŧ","🤤","đŸ˜ļ‍đŸŒĢī¸","😷","🤕","🤑","🤠","😈","đŸ‘ģ","💀","🤖","đŸļ","🐱","đŸŧ","🐸","đŸĻ„","🐷","đŸĩ","🐰","đŸ¯","đŸĻ","🐮","🌞","🌙","⭐","🌈","đŸ”Ĩ","💧","â„ī¸","⚡","â˜€ī¸","🌸","🌹","🍎","🍕","🍩","🍔","🍟","🍇","🍉","🍓","🍒","đŸĨ­","đŸĨ‘","🎉","🎂","🎁","🎈","đŸŽļ","đŸŽĩ","🏆","âšŊ","🏀","🏸","🏏","đŸ•šī¸","👋","🤚","đŸ–ī¸","✋","🖖","👍","👎","👌","🤌","🤏","✊","👊","🤛","🤜","â˜ī¸","👆","👇","👈","👉","🤟","🤘","🤙","🙌","👏","🙏","âœī¸","💅","🤲","👏","đŸĢļ","👐"],ce=({exec:o,saveSelection:c,handleFileChange:d,handleFontSizeChange:u,handleFontFamilyChange:g,insertEmoji:w,handleLink:S,removeFormatting:C,visibleActions:p,className:H,style:F})=>{var R,j;const T=t.useRef(null),P=t.useRef(null),L=t.useRef(null),[Y,$]=t.useState(!1),[q,B]=t.useState({x:0,y:0});t.useEffect(()=>{const m=b=>{!b.target.closest(".rte-emoji-popup")&&!b.target.closest("button[title='Emoji']")&&$(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);const I=m=>{var _;m.preventDefault();const b=m.currentTarget.dataset.command;if(b)switch(b){case"bold":case"italic":case"underline":case"insertUnorderedList":case"insertOrderedList":case"removeFormat":o(b);break;case"insertImage":{(_=T.current)==null||_.click();break}default:console.warn("Unknown command:",b)}},J=m=>{o("foreColor",m.target.value)},G=m=>{o("backColor",m.target.value)},[z,N]=t.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 t.useEffect(()=>{const m=()=>{N({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)},[]),t.createElement("div",{className:`rte-toolbar ${H||""}`,style:F},p.bold&&t.createElement("button",{"data-command":"bold",title:"Bold",onMouseDown:I,className:z.bold?"rte-active":""},t.createElement(Ke,null)),p.italic&&t.createElement("button",{"data-command":"italic",title:"Italic",onMouseDown:I,className:z.italic?"rte-active":""},t.createElement(Ye,null)),p.underline&&t.createElement("button",{"data-command":"underline",title:"Underline",onMouseDown:I,className:z.underline?"rte-active":""},t.createElement(et,null)),p.unorderedList&&t.createElement("button",{"data-command":"insertUnorderedList",onMouseDown:I,title:"UnorderedList",className:z.unorderedList?"rte-active":""},t.createElement(Qe,null)),p.orderedList&&t.createElement("button",{"data-command":"insertOrderedList",title:"OrderedList",onMouseDown:I,className:z.orderedList?"rte-active":""},t.createElement($e,null)),p.link&&t.createElement("button",{"data-command":"createLink",title:"Link",onClick:S,className:z.link?"rte-active":""},t.createElement(Ze,null)),p.removeFormat&&t.createElement("button",{"data-command":"Remove format",title:"removeFormat",onMouseDown:m=>{m.preventDefault(),c(),C()},className:z.removeFormat?"rte-active":""},t.createElement(nt,null)),p.image&&t.createElement("button",{"data-command":"insertImage",title:"Image",onMouseDown:I,className:z.image?"rte-active":""},t.createElement(Ve,null)),t.createElement("input",{type:"file",accept:"image/*",ref:T,style:{display:"none"},onChange:d}),p.emoji&&t.createElement("div",{style:{position:"relative"}},t.createElement("button",{title:"Emoji",onMouseDown:m=>{m.preventDefault(),c();const b=m.currentTarget.getBoundingClientRect();B({x:b.left,y:b.bottom+8}),$(_=>!_)},className:z.emoji?"rte-active":""},t.createElement(Je,null)),Y&&O.createPortal(t.createElement("div",{className:"rte-emoji-popup",style:{top:q.y,left:q.x}},rt.map((m,b)=>t.createElement("span",{key:b,style:{fontSize:"20px",cursor:"pointer",textAlign:"center"},onMouseDown:_=>{_.preventDefault(),w(m),$(!1)}},m))),document.body)),p.color&&t.createElement("div",{style:{position:"relative"}},t.createElement("button",{title:"Text Color",onMouseDown:m=>{var b;m.preventDefault(),c(),(b=P.current)==null||b.click()},style:{display:"flex",alignItems:"center",justifyContent:"center",color:((R=P.current)==null?void 0:R.value)||"#000",fontSize:"18px"},className:z.color?"rte-active":""},t.createElement(tt,null)),t.createElement("input",{ref:P,type:"color",defaultValue:"#000000",onChange:m=>{var b;J(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&&t.createElement("div",{style:{position:"relative"}},t.createElement("button",{title:"Highlight",onMouseDown:m=>{var b;m.preventDefault(),c(),(b=L.current)==null||b.click()},style:{display:"flex",alignItems:"center",justifyContent:"center",color:((j=L.current)==null?void 0:j.value)||"#000",fontSize:"18px"},className:z.highlight?"rte-active":""},t.createElement(Xe,null)),t.createElement("input",{ref:L,type:"color",onChange:m=>{var b;G(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&&t.createElement(t.Fragment,null,t.createElement("button",{title:"Align Left",onMouseDown:m=>m.preventDefault(),onClick:()=>o("justifyLeft"),className:z.alignLeft?"rte-active":""},t.createElement(We,null)),t.createElement("button",{title:"Align Center",onMouseDown:m=>m.preventDefault(),onClick:()=>o("justifyCenter"),className:z.alignCenter?"rte-active":""},t.createElement(Re,null)),t.createElement("button",{title:"Align Right",onMouseDown:m=>m.preventDefault(),onClick:()=>o("justifyRight"),className:z.alignRight?"rte-active":""},t.createElement(Ue,null))),p.table&&t.createElement("button",{title:"Insert Table",onMouseDown:m=>m.preventDefault(),onClick:()=>o("insertTable"),className:z.table?"rte-active":""},t.createElement(Ge,null)),p.fontFamily&&t.createElement("select",{className:"rte-dropdown",defaultValue:"",onMouseDown:()=>c(),onChange:g},t.createElement("option",{value:"",disabled:!0},"Font Family"),t.createElement("option",{value:"Arial"},"Arial"),t.createElement("option",{value:"Georgia"},"Georgia"),t.createElement("option",{value:"Times New Roman"},"Times New Roman"),t.createElement("option",{value:"Courier New"},"Courier New"),t.createElement("option",{value:"Verdana"},"Verdana")),p.fontSize&&t.createElement("select",{className:"rte-dropdown rte-fontsize-dropdown",defaultValue:"",onMouseDown:()=>c(),onChange:u},t.createElement("option",{value:"",disabled:!0},"Font Size"),Array.from({length:16},(m,b)=>10+b).map(m=>t.createElement("option",{key:m,value:m},m,"px"))))},ot=({show:o,position:c,filtered:d,insertMention:u,onClose:g,query:w})=>{const S=t.useRef(null);return t.useEffect(()=>{const C=p=>{S.current&&!S.current.contains(p.target)&&g()};return o&&document.addEventListener("mousedown",C),()=>{document.removeEventListener("mousedown",C)}},[o,g]),o?t.createElement("ul",{ref:S,className:"rte-popup",style:{top:c.y,left:c.x}},d.length>0?d.map(({name:C,value:p})=>{const H=C.toLowerCase(),F=w.toLowerCase(),T=H.indexOf(F);let P=C;if(T!==-1&&w.length>0){const L=T+w.length;P=C.substring(0,T)+`<span class="rte-highlight">${C.substring(T,L)}</span>`+C.substring(L)}return t.createElement("li",{key:p,onMouseDown:L=>{L.preventDefault(),u({name:C,value:p})},style:{padding:"6px 12px",cursor:"pointer",fontSize:"14px"},dangerouslySetInnerHTML:{__html:P},onMouseEnter:L=>L.currentTarget.style.background="#f0f0f0",onMouseLeave:L=>L.currentTarget.style.background="#fff"})}):t.createElement("li",{style:{padding:"6px 12px",color:"#999"}},"No matches")):null};function ue(o){return k({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:[]}]}]}]})(o)}function X(o){return k({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:[]}]}]}]})(o)}const lt=({visible:o,x:c,y:d,onAction:u,onClose:g})=>{if(!o)return null;const w={top:d,left:c};return t.createElement("div",{style:w,className:"rte-table-menu",onMouseLeave:g},t.createElement("button",{onClick:()=>u("insertRowAbove")},t.createElement(X,null)," Insert row above"),t.createElement("button",{onClick:()=>u("insertRowBelow")},t.createElement(X,null)," Insert row below"),t.createElement("button",{onClick:()=>u("insertColLeft")},t.createElement(X,null)," Insert col left"),t.createElement("button",{onClick:()=>u("insertColRight")},t.createElement(X,null)," Insert col right"),t.createElement("button",{onClick:()=>u("deleteRow")},t.createElement(ue,null)," Delete row"),t.createElement("button",{onClick:()=>u("deleteCol")},t.createElement(ue,null)," Delete column"))},de=({html:o,className:c,style:d})=>{const u=w=>{const S=w.target;if(S.tagName==="A"){w.preventDefault();const C=S.href;C&&window.open(C,"_blank","noopener,noreferrer")}},g=w=>{let S=w.replace(/{{\s*(.*?)\s*}}/g,(C,p)=>`<span style="color: blue">${p}</span>`);return S=S.replace(/#arrayData/g,""),S=S.replace(/\/arrayData/g,""),S};return t.createElement("div",{className:`rte-preview ${c||""}`,style:d,onClick:u,dangerouslySetInnerHTML:{__html:g(o)}})},at=({visible:o,linkData:c,onClose:d,onInsert:u})=>{const[g,w]=t.useState(""),[S,C]=t.useState(""),[p,H]=t.useState(""),[F,T]=t.useState("_self");if(t.useEffect(()=>{o?(w(c.url||""),C(c.text||""),H(c.title||""),T(c.target||"_self")):(w(""),C(""),H(""),T("_self"))},[o,c]),!o)return null;const P=()=>{u({url:g,text:S,title:p,target:F})};return t.createElement(t.Fragment,null,t.createElement("div",{className:"rte-link-modal-overlay",onClick:d}),t.createElement("div",{className:"rte-link-modal"},t.createElement("h4",{className:"rte-link-modal__title"},g?"Edit Link":"Insert Link"),t.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"URL",value:g,onChange:L=>w(L.target.value)}),t.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"Text to Display",value:S,onChange:L=>C(L.target.value)}),t.createElement("input",{type:"text",className:"rte-link-modal__input",placeholder:"Title",value:p,onChange:L=>H(L.target.value)}),t.createElement("select",{className:"rte-link-modal__select",value:F,onChange:L=>T(L.target.value)},t.createElement("option",{value:"_self"},"Same tab"),t.createElement("option",{value:"_blank"},"New tab")),t.createElement("div",{className:"rte-link-modal__actions"},t.createElement("button",{className:"rte-link-modal__btn",onClick:d},"Cancel"),t.createElement("button",{className:"rte-link-modal__btn rte-link-modal__btn--ok",onClick:P},"OK"))))};function me(o){return Array.from(new Map(o.map(c=>[c.value,c])).values())}const it=({atSuggestions:o=[],showOutput:c=!1,showPreview:d=!1,toolbarConfig:u={link:!1,image:!1,emoji:!1,table:!1,color:!1,fontFamily:!1,fontSize:!1,highlight:!1},classNames:g={},styles:w={},handleGetHtml:S=()=>{},onChange:C=()=>{},value:p,onMentionSelect:H=()=>{},handleAddAttributes:F=()=>{}})=>{var Ce,Se,xe,Le,Me,Ae,ze,ke;const T=t.useRef(null),[P,L]=t.useState(p!=null&&p.length?p:" "),[Y,$]=t.useState(""),[q,B]=t.useState(!1),[I,J]=t.useState({x:0,y:0}),[G,z]=t.useState([]),N=t.useRef(null),R=t.useRef(null),[j,m]=t.useState({visible:!1,x:0,y:0}),[b,_]=t.useState(!1),Z=t.useRef(null),[st,fe]=t.useState({url:"",text:"",title:"",target:"_self"}),ct={bold:!0,italic:!0,underline:!0,removeFormat:!0,unorderedList:!0,orderedList:!0,align:!0,link:(Ce=u.link)!=null?Ce:!1,image:(Se=u.image)!=null?Se:!1,emoji:(xe=u.emoji)!=null?xe:!1,table:(Le=u.table)!=null?Le:!1,color:(Me=u.color)!=null?Me:!1,fontFamily:(Ae=u.fontFamily)!=null?Ae:!1,fontSize:(ze=u.fontSize)!=null?ze:!1,highlight:(ke=u.fontSize)!=null?ke:!1},[ut,ge]=t.useState(""),[he,ee]=t.useState([]),D=()=>T.current,M=()=>{const e=dt(),n=/^<div[^>]*style=["'][^"']*font-size\s*:\s*\d+px[^"']*["'][^>]*>/.test(e.trim());let r=e;n||(r=`<div style="font-size:12px">${e}</div>`),$(r),S==null||S(r);const l=Ht(e);C(l);const s=bt(),a=me(s);JSON.stringify(a)!==JSON.stringify(he)&&(ee(a),H(a))},dt=()=>{const e=D();if(!e)return P;const n=e.cloneNode(!0);n.querySelectorAll("table div").forEach(l=>l.remove()),n.querySelectorAll(".rte-cell-highlight").forEach(l=>l.classList.remove("rte-cell-highlight"));let r=n.innerHTML;return r=mt(r),r},mt=e=>e.replace(/<tbody[^>]*>/g,"<tbody>{{#arrayData}}").replace(/<\/tbody>/g,"{{/arrayData}}</tbody>"),U=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return;const n=document.getElementById("rte-editor-body");if(!n)return;const r=e.getRangeAt(0);n.contains(r.startContainer)&&(N.current=r.cloneRange())},V=()=>{const e=window.getSelection();!e||!N.current||(e.removeAllRanges(),e.addRange(N.current))},pe=(e,n)=>{const r=window.getSelection();r&&r.rangeCount>0&&(N.current=r.getRangeAt(0)),V(),document.execCommand(e,!1,n),M()};t.useEffect(()=>{const e=D();if(!e||!p)return;const n=ft(p);e.innerHTML=n,M()},[]);const ft=e=>e.replace(/<span[^>]*data-hidden-table-start[^>]*>.*?<\/span>/g,"").replace(/<span[^>]*data-hidden-table-end[^>]*>.*?<\/span>/g,"").replace(/{{#arrayData}}/g,"").replace(/{{\/arrayData}}/g,"");t.useEffect(()=>()=>{document.removeEventListener("mousemove",null),document.removeEventListener("mouseup",null)},[]),t.useEffect(()=>{F&&F(e=>{wt(e)})},[]),t.useEffect(()=>{const e=D();if(!e)return;e.querySelectorAll("table").forEach(r=>{we(r),r.querySelectorAll("th, td").forEach(s=>Q(s))})},[]);const ve=e=>{for(;e&&e.nodeName!=="LI";)e=e.parentNode;return e},gt=e=>{let n=0,r=e.parentElement;for(;r;)(r.tagName==="UL"||r.tagName==="OL")&&n++,r=r.parentElement;return n},ht=e=>{const n=e.querySelector("li"),r=n?gt(n):1;if(e.querySelector("[data-hidden-array-start]"))return;const l=`{{#arrayData${r>1?r:""}}}`,s=`{{/arrayData${r>1?r:""}}}`,a=document.createElement("span");a.textContent=l,a.style.display="none",a.setAttribute("data-hidden-array-start","true"),e.insertBefore(a,e.firstChild);const i=document.createElement("span");i.textContent=s,i.style.display="none",i.setAttribute("data-hidden-array-end","true"),e.appendChild(i)},ye=e=>{var v;const n=window.getSelection();if(!(n!=null&&n.rangeCount))return;const r=n.getRangeAt(0),l=ve(r.startContainer);let s,a;if(l){let h=l.querySelector(e);h||(h=document.createElement(e),h.style.margin="0",h.style.paddingLeft="20px",l.appendChild(h)),a=h,s=document.createElement("li"),s.textContent="​",a.appendChild(s)}else{document.execCommand(e==="ul"?"insertUnorderedList":"insertOrderedList");const h=D();if(a=h==null?void 0:h.querySelector(`${e}:last-child`),!a)return;s=a.querySelector("li:last-child")}ht(a);const i=document.createRange();i.setStart(s,0),i.collapse(!0),n.removeAllRanges(),n.addRange(i),(v=D())==null||v.focus(),M()},te=(e,n)=>{e==="insertOrderedList"?ye("ol"):e==="insertUnorderedList"?ye("ul"):e.startsWith("justify")?Pt(e):pe(e,n),e==="insertTable"&&At()},pt=e=>{const n=document.createElement("span");n.textContent="​",e.insertNode(n),e.setStartAfter(n),e.collapse(!0);const r=n.getBoundingClientRect();n.remove(),J({x:r.left,y:r.bottom+window.scrollY}),z(o||[]),B(!0),R.current=e.cloneRange()},vt=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return null;const n=e.anchorNode;let r=e.anchorOffset;if(!n)return null;let l=n;for(l.nodeType!==Node.TEXT_NODE&&(l.childNodes&&l.childNodes[r]?l=l.childNodes[r]:l=n.previousSibling);l;){if(l.nodeType===Node.TEXT_NODE){const s=l.textContent||"",a=l===n?r:s.length,i=s.lastIndexOf("@",a-1);if(i!==-1){const v=document.createRange();return v.setStart(l,i),v.setEnd(l,a),v}}l=l.previousSibling}return null},yt=e=>{var a;const n=window.getSelection();if(!n)return;const r=vt();r?(n.removeAllRanges(),n.addRange(r)):R.current&&(n.removeAllRanges(),n.addRange(R.current));const l=document.createElement("span");l.textContent=`{{${e.name}}}`,l.style.display="inline",l.setAttribute("data-mention",e.value||e.name||"");try{const i=n.rangeCount?n.getRangeAt(0):null;if(i)i.deleteContents(),i.insertNode(l);else{const E=document.createRange(),f=D();E.selectNodeContents(f),E.collapse(!1),E.insertNode(l)}const v=document.createTextNode(" ");l.after(v);const h=document.createRange();h.setStartAfter(v),h.collapse(!0),n.removeAllRanges(),n.addRange(h)}catch(i){console.error("insertMention error:",i)}let s=me([...he,e]);ee(s),H(s),B(!1),(a=D())==null||a.focus(),M()},Et=e=>{const n=D();if(!n)return;let r=null;N.current&&n.contains(N.current.startContainer)?r=N.current.cloneRange():(r=document.createRange(),r.selectNodeContents(n),r.collapse(!1));const l=window.getSelection();if(!l)return;l.removeAllRanges(),l.addRange(r);const s=document.createElement("span");s.textContent=`{{${e.name}}}`,s.style.display="inline",s.setAttribute("data-mention",e.value||e.name),r.insertNode(s);const a=document.createTextNode(" ");s.after(a);const i=document.createRange();i.setStartAfter(a),i.collapse(!0),l.removeAllRanges(),l.addRange(i),N.current=i.cloneRange(),n.focus()},wt=e=>{e.forEach(n=>Et(n)),ee(n=>{const r=[...n,...e],l=Array.from(new Map(r.map(s=>[s.name,s])).values());return H(l),l}),M()},bt=()=>{const e=D();if(!e)return[];const n=e.querySelectorAll("span[data-mention]"),r=[];return n.forEach(l=>{const s=l.getAttribute("data-mention")||"",i=(l.textContent||"").match(/{{(.+?)}}/);i&&r.push({name:i[1],value:s})}),r},Ct=e=>{var r,l,s;const n=e.key.toLowerCase();if((e.ctrlKey||e.metaKey)&&["b","i","u"].includes(n)&&(e.preventDefault(),te(n==="b"?"bold":n==="i"?"italic":n==="u"?"underline":"")),e.shiftKey&&e.key==="2"&&e.preventDefault(),e.key==="Enter"){const a=window.getSelection(),i=a!=null&&a.anchorNode?ve(a.anchorNode):null;if(!i)return;if(((r=i.textContent)==null?void 0:r.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 />",(l=E.parentElement)==null||l.insertBefore(f,E.nextSibling);const y=document.createRange();y.setStart(f,0),y.collapse(!0),a==null||a.removeAllRanges(),a==null||a.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 x=document.createRange();x.setStart(y,0),x.collapse(!0),a==null||a.removeAllRanges(),a==null||a.addRange(x)}}M()}}},St=e=>{if(e.data==="@"){const r=window.getSelection();if(!(r!=null&&r.rangeCount))return;const l=r.anchorNode;if(xt(l))return;setTimeout(()=>{pt(r.getRangeAt(0)),ge(""),z(o),B(!0)},0);return}if(q){setTimeout(()=>Ee(),0);return}},xt=e=>{if(!e)return!1;let n=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;n;){if(n.tagName==="TH")return!0;n=n.parentElement}return!1},Ee=()=>{if(M(),!q)return;const e=window.getSelection();if(!e||!e.anchorNode)return;const r=(e.anchorNode.textContent||"").match(/@([a-zA-Z0-9_]*)$/);if(!r){B(!1);return}const l=r[1].toLowerCase();ge(l);const s=o.filter(a=>a.name.toLowerCase().includes(l));z(s)},Lt=e=>{var l;const n=(l=e.target.files)==null?void 0:l[0];if(!n)return;const r=new FileReader;r.onload=s=>{var x;const a=(x=s.target)==null?void 0:x.result;V();const i=window.getSelection();let v=i&&i.rangeCount?i.getRangeAt(0):null;const h=document.createElement("img");h.src=a,h.alt=n.name||"image",h.className="rte-inserted-image",h.contentEditable="true";const E=D();if(!v||!E){E==null||E.appendChild(h);const Te=document.createTextNode(" ");E==null||E.appendChild(Te);const ne=document.createRange();ne.setStartAfter(Te),ne.collapse(!0),i==null||i.removeAllRanges(),i==null||i.addRange(ne),E==null||E.focus(),M(),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(),M(),e.target.value=""},r.readAsDataURL(n)},Mt=e=>{var s;V();const n=window.getSelection();if(!(n!=null&&n.rangeCount))return;const r=n.getRangeAt(0),l=document.createTextNode(e);r.insertNode(l),r.setStartAfter(l),r.collapse(!0),n.removeAllRanges(),n.addRange(r),(s=D())==null||s.focus(),M()},At=()=>{var E;V();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 n=document.createElement("thead");g.thead&&n.classList.add(g.thead);const r=document.createElement("tbody");g.tbody&&r.classList.add(g.tbody);const l=document.createElement("tr");g.tr&&l.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 x=document.createElement("td");x.textContent=`Row 1 Col ${f+1}`,x.style.border="1px solid #999",x.style.padding="4px",x.style.position="relative",x.style.backgroundColor="#fff",g.td&&x.classList.add(g.td),Q(y),Q(x),l.appendChild(y),s.appendChild(x)}n.appendChild(l),r.appendChild(s),e.appendChild(n),e.appendChild(r),we(e);const a=window.getSelection();if(!(a!=null&&a.rangeCount))return;const i=a.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),a.removeAllRanges(),a.addRange(h),(E=D())==null||E.focus(),M()},we=e=>{const n=document.createElement("div");Object.assign(n.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"}),n.style.userSelect="none",n.contentEditable="false";let r=0,l=0,s=0,a=0;n.addEventListener("mousedown",i=>{i.preventDefault(),r=i.clientX,l=i.clientY;const v=e.getBoundingClientRect();s=v.width,a=v.height;const h=f=>{const y=Math.max(100,s+(f.clientX-r)),x=Math.max(60,a+(f.clientY-l));e.style.width=`${y}px`,e.style.height=`${x}px`,M()},E=()=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E),M()};document.addEventListener("mousemove",h),document.addEventListener("mouseup",E)}),e.appendChild(n)},Q=e=>{const n=document.createElement("div"),r=document.createElement("div");Object.assign(n.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"}),n.contentEditable="false",Object.assign(r.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"}),r.contentEditable="false",zt(e,n,r),e.appendChild(n),e.appendChild(r)},zt=(e,n,r)=>{let l=0,s=0,a=0,i=0;n.addEventListener("mousedown",f=>{f.preventDefault(),l=f.clientX,a=e.offsetWidth,document.addEventListener("mousemove",v),document.addEventListener("mouseup",E)}),r.addEventListener("mousedown",f=>{f.preventDefault(),s=f.clientY,i=e.offsetHeight,document.addEventListener("mousemove",h),document.addEventListener("mouseup",E)});const v=f=>{const y=a+(f.clientX-l);e.style.width=`${Math.max(30,y)}px`,M()},h=f=>{const y=i+(f.clientY-s);e.style.height=`${Math.max(20,y)}px`,M()},E=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",E),M()}},kt=e=>{const r=e.target.closest("td, th");r&&(e.preventDefault(),document.querySelectorAll(".rte-cell-highlight").forEach(l=>l.classList.remove("rte-cell-highlight")),r.classList.add("rte-cell-highlight"),m({visible:!0,x:e.clientX,y:e.clientY,cell:r}))},be=()=>{document.querySelectorAll(".rte-cell-highlight").forEach(e=>e.classList.remove("rte-cell-highlight"))},Tt=e=>{if(!j.cell)return;const n=j.cell.closest("table"),r=j.cell.cellIndex,l=j.cell.parentElement.rowIndex,s=a=>{const i=a.tagName.toLowerCase(),v=document.createElement(i);return v.textContent=a.textContent||"",v.style.cssText=a.style.cssText,Q(v),v};switch(e){case"insertRowAbove":{const a=n.rows[l],i=n.insertRow(l);Array.from(a.cells).forEach(v=>{i.appendChild(s(v))});break}case"insertRowBelow":{const a=n.rows[l],i=n.insertRow(l+1);Array.from(a.cells).forEach(v=>{i.appendChild(s(v))});break}case"insertColLeft":{Array.from(n.rows).forEach(a=>{const i=a.cells[r];a.insertBefore(s(i),i)});break}case"insertColRight":{Array.from(n.rows).forEach(a=>{const i=a.cells[r];a.insertBefore(s(i),i.nextSibling)});break}case"deleteRow":n.rows.length>1&&n.deleteRow(l);break;case"deleteCol":Array.from(n.rows).forEach(a=>{a.cells[r]&&a.deleteCell(r)});break}M(),m(oe(re({},j),{visible:!1})),be()},Nt=()=>{U(),Z.current=N.current,fe({url:"",text:"",title:"",target:"_self"}),_(!0)},Dt=e=>{const n=window.getSelection();if(!n||!Z.current)return;n.removeAllRanges(),n.addRange(Z.current);let r=e.url.trim();/^https?:\/\//i.test(r)||(r="https://"+r);const l=document.createElement("a");l.href=r,l.style.cursor="pointer",l.style.outline="none",l.textContent=e.text||r,l.title=e.title,l.target=e.target,l.contentEditable="true";const s=n.getRangeAt(0);s.deleteContents(),s.insertNode(l);const a=document.createTextNode(" ");l.after(a);const i=document.createRange();i.setStartAfter(a),i.collapse(!0),n.removeAllRanges(),n.addRange(i),_(!1),M()},Ot=e=>{const n=e.target;if(n.tagName==="A"){const r=n;if(e.ctrlKey||e.metaKey){window.open(r.href,"_blank","noopener,noreferrer");return}e.preventDefault();const l=document.createRange();l.selectNode(r),Z.current=l,fe({url:r.href,text:r.textContent||r.href,title:r.title,target:r.target}),_(!0)}},jt=()=>{const e=D();if(!e)return;const n=window.getSelection();if((!n||n.rangeCount===0)&&N.current){const f=window.getSelection();f==null||f.removeAllRanges(),f==null||f.addRange(N.current)}const r=window.getSelection();if(!r||r.rangeCount===0)return;const l=r.getRangeAt(0);V(),document.execCommand("removeFormat",!1);const s=l.cloneContents(),a=document.createElement("div");a.appendChild(s);const i=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT,null),v=[];for(;i.nextNode();){const f=i.currentNode,y=f.tagName.toUpperCase(),x=f.getAttribute&&f.getAttribute("data-mention")!==null;y!=="A"&&!x&&v.push(f)}for(let f=v.length-1;f>=0;f--){const y=v[f],x=y.parentNode;if(x){for(;y.firstChild;)x.insertBefore(y.firstChild,y);x.removeChild(y)}}a.querySelectorAll("[style]").forEach(f=>f.removeAttribute("style")),l.deleteContents();const h=document.createDocumentFragment();for(;a.firstChild;)h.appendChild(a.firstChild);l.insertNode(h);const E=document.createRange();E.setStartAfter(l.endContainer.nodeType===Node.TEXT_NODE?l.endContainer:l.startContainer),E.collapse(!0),r.removeAllRanges(),r.addRange(E),e.normalize(),M()},Ht=e=>{var l;let n=e;n=n.replace(/{{#arrayData\d*}}/g,""),n=n.replace(/{{\/arrayData\d*}}/g,"");const r=document.createElement("div");return r.innerHTML=n,r.querySelectorAll("br").forEach(s=>{s.replaceWith(` `)}),r.querySelectorAll("p, div, tr").forEach(s=>{s.insertAdjacentText("afterend",` `)}),r.querySelectorAll("table").forEach(s=>{s.insertAdjacentText("afterend",` `)}),((l=r.textContent)==null?void 0:l.replace(/\n{3,}/g,` `).trim())||""};function _t(){const e=window.getSelection();if(!e||e.rangeCount===0)return[];const n=e.getRangeAt(0),r=n.commonAncestorContainer,l=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;return Array.from(l.querySelectorAll("td, th")).filter(a=>{const i=document.createRange();return i.selectNodeContents(a),n.compareBoundaryPoints(Range.END_TO_START,i)<0&&n.compareBoundaryPoints(Range.START_TO_END,i)>0})}function Pt(e){const n=_t();if(n.length===0){pe(e);return}let r="left";e==="justifyCenter"&&(r="center"),e==="justifyRight"&&(r="right"),n.forEach(l=>{l.style.textAlign=r}),M()}const Ft=e=>{const n=e.clipboardData.items;for(let r=0;r<n.length;r++){const l=n[r];if(l.kind==="file"&&l.type.startsWith("image/")){e.preventDefault();return}l.kind==="string"&&l.getAsString(s=>{/<img\s/i.test(s)&&e.preventDefault()})}},It=e=>{V();const n=window.getSelection();if(!n||!n.rangeCount)return;const r=n.getRangeAt(0),l=document.createElement("span");l.style.fontSize=`${e}px`,l.appendChild(r.extractContents()),r.insertNode(l);const s=document.createRange();s.setStartAfter(l),s.collapse(!0),n.removeAllRanges(),n.addRange(s),M()};return t.createElement("div",{className:`rte-wrapper ${(g==null?void 0:g.wrapper)||""}`,style:w.wrapper},t.createElement("div",{style:{flex:1}},t.createElement(ce,{exec:te,saveSelection:U,handleFileChange:Lt,handleFontSizeChange:e=>It(e.target.value),handleFontFamilyChange:e=>te("fontName",e.target.value),insertEmoji:Mt,handleLink:Nt,removeFormatting:jt,visibleActions:ct,className:g.toolbar,style:w.toolbar}),t.createElement("div",{ref:T,id:"rte-editor-body",className:`rte-editor ${(g==null?void 0:g.editor)||""}`,style:w.editor,contentEditable:!0,suppressContentEditableWarning:!0,onPaste:Ft,onKeyUp:U,onMouseUp:U,onInput:()=>{Ee(),U()},onKeyDown:Ct,onBeforeInput:St,onContextMenu:kt,onClick:e=>{Ot(e),U()}}),t.createElement(ot,{show:q,position:I,filtered:G,insertMention:yt,onClose:()=>B(!1),query:ut}),c&&t.createElement("div",{className:`rte-output ${(g==null?void 0:g.output)||""}`,style:w.output},t.createElement("h4",null,"Output HTML:"),t.createElement("p",null,Y)),t.createElement(lt,{visible:j.visible,x:j.x,y:j.y,onAction:Tt,onClose:()=>{m(oe(re({},j),{visible:!1})),be()}}),t.createElement(at,{visible:b,linkData:st,onClose:()=>_(!1),onInsert:Dt})),d?t.createElement(de,{className:g.preview,style:w.preview,html:Y}):null)};A.RichTextEditor=it,A.RtePreview=de,A.RteToolbar=ce,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));