html-wysiwyg-editor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -0
- package/dist/index.d.ts +107 -0
- package/dist/wysiwyg-editor.css +1 -0
- package/dist/wysiwyg-editor.js +2450 -0
- package/dist/wysiwyg-editor.js.map +1 -0
- package/dist/wysiwyg-editor.umd.cjs +15 -0
- package/dist/wysiwyg-editor.umd.cjs.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
(function(te,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(te=typeof globalThis<"u"?globalThis:te||self,n(te.WysiwygEditor={},te.jsxRuntime,te.React))})(this,(function(te,n,s){"use strict";const{entries:bt,setPrototypeOf:Et,isFrozen:en,getPrototypeOf:tn,getOwnPropertyDescriptor:nn}=Object;let{freeze:Q,seal:se,create:tt}=Object,{apply:nt,construct:ot}=typeof Reflect<"u"&&Reflect;Q||(Q=function(o){return o}),se||(se=function(o){return o}),nt||(nt=function(o,r){for(var u=arguments.length,f=new Array(u>2?u-2:0),h=2;h<u;h++)f[h-2]=arguments[h];return o.apply(r,f)}),ot||(ot=function(o){for(var r=arguments.length,u=new Array(r>1?r-1:0),f=1;f<r;f++)u[f-1]=arguments[f];return new o(...u)});const Ke=ee(Array.prototype.forEach),on=ee(Array.prototype.lastIndexOf),yt=ee(Array.prototype.pop),Be=ee(Array.prototype.push),sn=ee(Array.prototype.splice),qe=ee(String.prototype.toLowerCase),st=ee(String.prototype.toString),rt=ee(String.prototype.match),We=ee(String.prototype.replace),rn=ee(String.prototype.indexOf),ln=ee(String.prototype.trim),ie=ee(Object.prototype.hasOwnProperty),J=ee(RegExp.prototype.test),Ge=an(TypeError);function ee(t){return function(o){o instanceof RegExp&&(o.lastIndex=0);for(var r=arguments.length,u=new Array(r>1?r-1:0),f=1;f<r;f++)u[f-1]=arguments[f];return nt(t,o,u)}}function an(t){return function(){for(var o=arguments.length,r=new Array(o),u=0;u<o;u++)r[u]=arguments[u];return ot(t,r)}}function w(t,o){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:qe;Et&&Et(t,null);let u=o.length;for(;u--;){let f=o[u];if(typeof f=="string"){const h=r(f);h!==f&&(en(o)||(o[u]=h),f=h)}t[f]=!0}return t}function cn(t){for(let o=0;o<t.length;o++)ie(t,o)||(t[o]=null);return t}function me(t){const o=tt(null);for(const[r,u]of bt(t))ie(t,r)&&(Array.isArray(u)?o[r]=cn(u):u&&typeof u=="object"&&u.constructor===Object?o[r]=me(u):o[r]=u);return o}function $e(t,o){for(;t!==null;){const u=nn(t,o);if(u){if(u.get)return ee(u.get);if(typeof u.value=="function")return ee(u.value)}t=tn(t)}function r(){return null}return r}const Tt=Q(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),lt=Q(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),it=Q(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),un=Q(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),at=Q(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),dn=Q(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),vt=Q(["#text"]),kt=Q(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),ct=Q(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Ct=Q(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Ve=Q(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),fn=se(/\{\{[\w\W]*|[\w\W]*\}\}/gm),mn=se(/<%[\w\W]*|[\w\W]*%>/gm),pn=se(/\$\{[\w\W]*/gm),hn=se(/^data-[\-\w.\u00B7-\uFFFF]+$/),gn=se(/^aria-[\-\w]+$/),Nt=se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),bn=se(/^(?:\w+script|data):/i),En=se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),At=se(/^html$/i),yn=se(/^[a-z][.\w]*(-[.\w]+)+$/i);var St=Object.freeze({__proto__:null,ARIA_ATTR:gn,ATTR_WHITESPACE:En,CUSTOM_ELEMENT:yn,DATA_ATTR:hn,DOCTYPE_NAME:At,ERB_EXPR:mn,IS_ALLOWED_URI:Nt,IS_SCRIPT_OR_DATA:bn,MUSTACHE_EXPR:fn,TMPLIT_EXPR:pn});const Ye={element:1,text:3,progressingInstruction:7,comment:8,document:9},Tn=function(){return typeof window>"u"?null:window},vn=function(o,r){if(typeof o!="object"||typeof o.createPolicy!="function")return null;let u=null;const f="data-tt-policy-suffix";r&&r.hasAttribute(f)&&(u=r.getAttribute(f));const h="dompurify"+(u?"#"+u:"");try{return o.createPolicy(h,{createHTML(d){return d},createScriptURL(d){return d}})}catch{return console.warn("TrustedTypes policy "+h+" could not be created."),null}},wt=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function _t(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Tn();const o=E=>_t(E);if(o.version="3.3.1",o.removed=[],!t||!t.document||t.document.nodeType!==Ye.document||!t.Element)return o.isSupported=!1,o;let{document:r}=t;const u=r,f=u.currentScript,{DocumentFragment:h,HTMLTemplateElement:d,Node:y,Element:b,NodeFilter:p,NamedNodeMap:k=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:T,DOMParser:L,trustedTypes:C}=t,a=b.prototype,l=$e(a,"cloneNode"),v=$e(a,"remove"),F=$e(a,"nextSibling"),R=$e(a,"childNodes"),U=$e(a,"parentNode");if(typeof d=="function"){const E=r.createElement("template");E.content&&E.content.ownerDocument&&(r=E.content.ownerDocument)}let _,H="";const{implementation:K,createNodeIterator:B,createDocumentFragment:q,getElementsByTagName:ae}=r,{importNode:ce}=u;let I=wt();o.isSupported=typeof bt=="function"&&typeof U=="function"&&K&&K.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:V,ERB_EXPR:re,TMPLIT_EXPR:he,DATA_ATTR:Ae,ARIA_ATTR:ge,IS_SCRIPT_OR_DATA:c,ATTR_WHITESPACE:m,CUSTOM_ELEMENT:D}=St;let{IS_ALLOWED_URI:x}=St,A=null;const G=w({},[...Tt,...lt,...it,...at,...vt]);let W=null;const Pe=w({},[...kt,...ct,...Ct,...Ve]);let M=Object.seal(tt(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ye=null,_e=null;const ue=Object.seal(tt(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Le=!0,De=!0,Fe=!1,xe=!0,de=!1,Te=!0,N=!1,O=!1,j=!1,fe=!1,le=!1,Se=!1,Me=!0,be=!1;const Oe="user-content-";let ve=!0,oe=!1,we={},S=null;const P=w({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Re=null;const ut=w({},["audio","video","img","source","image","track"]);let dt=null;const Wt=w({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ze="http://www.w3.org/1998/Math/MathML",Qe="http://www.w3.org/2000/svg",ke="http://www.w3.org/1999/xhtml";let ze=ke,ft=!1,mt=null;const Fn=w({},[Ze,Qe,ke],st);let Je=w({},["mi","mo","mn","ms","mtext"]),et=w({},["annotation-xml"]);const zn=w({},["title","style","font","a","script"]);let Xe=null;const Un=["application/xhtml+xml","text/html"],Hn="text/html";let Y=null,Ue=null;const Bn=r.createElement("form"),Gt=function(e){return e instanceof RegExp||e instanceof Function},pt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Ue&&Ue===e)){if((!e||typeof e!="object")&&(e={}),e=me(e),Xe=Un.indexOf(e.PARSER_MEDIA_TYPE)===-1?Hn:e.PARSER_MEDIA_TYPE,Y=Xe==="application/xhtml+xml"?st:qe,A=ie(e,"ALLOWED_TAGS")?w({},e.ALLOWED_TAGS,Y):G,W=ie(e,"ALLOWED_ATTR")?w({},e.ALLOWED_ATTR,Y):Pe,mt=ie(e,"ALLOWED_NAMESPACES")?w({},e.ALLOWED_NAMESPACES,st):Fn,dt=ie(e,"ADD_URI_SAFE_ATTR")?w(me(Wt),e.ADD_URI_SAFE_ATTR,Y):Wt,Re=ie(e,"ADD_DATA_URI_TAGS")?w(me(ut),e.ADD_DATA_URI_TAGS,Y):ut,S=ie(e,"FORBID_CONTENTS")?w({},e.FORBID_CONTENTS,Y):P,ye=ie(e,"FORBID_TAGS")?w({},e.FORBID_TAGS,Y):me({}),_e=ie(e,"FORBID_ATTR")?w({},e.FORBID_ATTR,Y):me({}),we=ie(e,"USE_PROFILES")?e.USE_PROFILES:!1,Le=e.ALLOW_ARIA_ATTR!==!1,De=e.ALLOW_DATA_ATTR!==!1,Fe=e.ALLOW_UNKNOWN_PROTOCOLS||!1,xe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,de=e.SAFE_FOR_TEMPLATES||!1,Te=e.SAFE_FOR_XML!==!1,N=e.WHOLE_DOCUMENT||!1,fe=e.RETURN_DOM||!1,le=e.RETURN_DOM_FRAGMENT||!1,Se=e.RETURN_TRUSTED_TYPE||!1,j=e.FORCE_BODY||!1,Me=e.SANITIZE_DOM!==!1,be=e.SANITIZE_NAMED_PROPS||!1,ve=e.KEEP_CONTENT!==!1,oe=e.IN_PLACE||!1,x=e.ALLOWED_URI_REGEXP||Nt,ze=e.NAMESPACE||ke,Je=e.MATHML_TEXT_INTEGRATION_POINTS||Je,et=e.HTML_INTEGRATION_POINTS||et,M=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&Gt(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(M.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&Gt(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(M.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(M.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),de&&(De=!1),le&&(fe=!0),we&&(A=w({},vt),W=[],we.html===!0&&(w(A,Tt),w(W,kt)),we.svg===!0&&(w(A,lt),w(W,ct),w(W,Ve)),we.svgFilters===!0&&(w(A,it),w(W,ct),w(W,Ve)),we.mathMl===!0&&(w(A,at),w(W,Ct),w(W,Ve))),e.ADD_TAGS&&(typeof e.ADD_TAGS=="function"?ue.tagCheck=e.ADD_TAGS:(A===G&&(A=me(A)),w(A,e.ADD_TAGS,Y))),e.ADD_ATTR&&(typeof e.ADD_ATTR=="function"?ue.attributeCheck=e.ADD_ATTR:(W===Pe&&(W=me(W)),w(W,e.ADD_ATTR,Y))),e.ADD_URI_SAFE_ATTR&&w(dt,e.ADD_URI_SAFE_ATTR,Y),e.FORBID_CONTENTS&&(S===P&&(S=me(S)),w(S,e.FORBID_CONTENTS,Y)),e.ADD_FORBID_CONTENTS&&(S===P&&(S=me(S)),w(S,e.ADD_FORBID_CONTENTS,Y)),ve&&(A["#text"]=!0),N&&w(A,["html","head","body"]),A.table&&(w(A,["tbody"]),delete ye.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!="function")throw Ge('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Ge('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');_=e.TRUSTED_TYPES_POLICY,H=_.createHTML("")}else _===void 0&&(_=vn(C,f)),_!==null&&typeof H=="string"&&(H=_.createHTML(""));Q&&Q(e),Ue=e}},$t=w({},[...lt,...it,...un]),Yt=w({},[...at,...dn]),Wn=function(e){let i=U(e);(!i||!i.tagName)&&(i={namespaceURI:ze,tagName:"template"});const g=qe(e.tagName),z=qe(i.tagName);return mt[e.namespaceURI]?e.namespaceURI===Qe?i.namespaceURI===ke?g==="svg":i.namespaceURI===Ze?g==="svg"&&(z==="annotation-xml"||Je[z]):!!$t[g]:e.namespaceURI===Ze?i.namespaceURI===ke?g==="math":i.namespaceURI===Qe?g==="math"&&et[z]:!!Yt[g]:e.namespaceURI===ke?i.namespaceURI===Qe&&!et[z]||i.namespaceURI===Ze&&!Je[z]?!1:!Yt[g]&&(zn[g]||!$t[g]):!!(Xe==="application/xhtml+xml"&&mt[e.namespaceURI]):!1},Ee=function(e){Be(o.removed,{element:e});try{U(e).removeChild(e)}catch{v(e)}},Ie=function(e,i){try{Be(o.removed,{attribute:i.getAttributeNode(e),from:i})}catch{Be(o.removed,{attribute:null,from:i})}if(i.removeAttribute(e),e==="is")if(fe||le)try{Ee(i)}catch{}else try{i.setAttribute(e,"")}catch{}},Rt=function(e){let i=null,g=null;if(j)e="<remove></remove>"+e;else{const $=rt(e,/^[\r\n\t ]+/);g=$&&$[0]}Xe==="application/xhtml+xml"&&ze===ke&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const z=_?_.createHTML(e):e;if(ze===ke)try{i=new L().parseFromString(z,Xe)}catch{}if(!i||!i.documentElement){i=K.createDocument(ze,"template",null);try{i.documentElement.innerHTML=ft?H:z}catch{}}const Z=i.body||i.documentElement;return e&&g&&Z.insertBefore(r.createTextNode(g),Z.childNodes[0]||null),ze===ke?ae.call(i,N?"html":"body")[0]:N?i.documentElement:Z},Xt=function(e){return B.call(e.ownerDocument||e,e,p.SHOW_ELEMENT|p.SHOW_COMMENT|p.SHOW_TEXT|p.SHOW_PROCESSING_INSTRUCTION|p.SHOW_CDATA_SECTION,null)},ht=function(e){return e instanceof T&&(typeof e.nodeName!="string"||typeof e.textContent!="string"||typeof e.removeChild!="function"||!(e.attributes instanceof k)||typeof e.removeAttribute!="function"||typeof e.setAttribute!="function"||typeof e.namespaceURI!="string"||typeof e.insertBefore!="function"||typeof e.hasChildNodes!="function")},Kt=function(e){return typeof y=="function"&&e instanceof y};function Ce(E,e,i){Ke(E,g=>{g.call(o,e,i,Ue)})}const qt=function(e){let i=null;if(Ce(I.beforeSanitizeElements,e,null),ht(e))return Ee(e),!0;const g=Y(e.nodeName);if(Ce(I.uponSanitizeElement,e,{tagName:g,allowedTags:A}),Te&&e.hasChildNodes()&&!Kt(e.firstElementChild)&&J(/<[/\w!]/g,e.innerHTML)&&J(/<[/\w!]/g,e.textContent)||e.nodeType===Ye.progressingInstruction||Te&&e.nodeType===Ye.comment&&J(/<[/\w]/g,e.data))return Ee(e),!0;if(!(ue.tagCheck instanceof Function&&ue.tagCheck(g))&&(!A[g]||ye[g])){if(!ye[g]&&jt(g)&&(M.tagNameCheck instanceof RegExp&&J(M.tagNameCheck,g)||M.tagNameCheck instanceof Function&&M.tagNameCheck(g)))return!1;if(ve&&!S[g]){const z=U(e)||e.parentNode,Z=R(e)||e.childNodes;if(Z&&z){const $=Z.length;for(let ne=$-1;ne>=0;--ne){const Ne=l(Z[ne],!0);Ne.__removalCount=(e.__removalCount||0)+1,z.insertBefore(Ne,F(e))}}}return Ee(e),!0}return e instanceof b&&!Wn(e)||(g==="noscript"||g==="noembed"||g==="noframes")&&J(/<\/no(script|embed|frames)/i,e.innerHTML)?(Ee(e),!0):(de&&e.nodeType===Ye.text&&(i=e.textContent,Ke([V,re,he],z=>{i=We(i,z," ")}),e.textContent!==i&&(Be(o.removed,{element:e.cloneNode()}),e.textContent=i)),Ce(I.afterSanitizeElements,e,null),!1)},Vt=function(e,i,g){if(Me&&(i==="id"||i==="name")&&(g in r||g in Bn))return!1;if(!(De&&!_e[i]&&J(Ae,i))){if(!(Le&&J(ge,i))){if(!(ue.attributeCheck instanceof Function&&ue.attributeCheck(i,e))){if(!W[i]||_e[i]){if(!(jt(e)&&(M.tagNameCheck instanceof RegExp&&J(M.tagNameCheck,e)||M.tagNameCheck instanceof Function&&M.tagNameCheck(e))&&(M.attributeNameCheck instanceof RegExp&&J(M.attributeNameCheck,i)||M.attributeNameCheck instanceof Function&&M.attributeNameCheck(i,e))||i==="is"&&M.allowCustomizedBuiltInElements&&(M.tagNameCheck instanceof RegExp&&J(M.tagNameCheck,g)||M.tagNameCheck instanceof Function&&M.tagNameCheck(g))))return!1}else if(!dt[i]){if(!J(x,We(g,m,""))){if(!((i==="src"||i==="xlink:href"||i==="href")&&e!=="script"&&rn(g,"data:")===0&&Re[e])){if(!(Fe&&!J(c,We(g,m,"")))){if(g)return!1}}}}}}}return!0},jt=function(e){return e!=="annotation-xml"&&rt(e,D)},Zt=function(e){Ce(I.beforeSanitizeAttributes,e,null);const{attributes:i}=e;if(!i||ht(e))return;const g={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:W,forceKeepAttr:void 0};let z=i.length;for(;z--;){const Z=i[z],{name:$,namespaceURI:ne,value:Ne}=Z,He=Y($),gt=Ne;let X=$==="value"?gt:ln(gt);if(g.attrName=He,g.attrValue=X,g.keepAttr=!0,g.forceKeepAttr=void 0,Ce(I.uponSanitizeAttribute,e,g),X=g.attrValue,be&&(He==="id"||He==="name")&&(Ie($,e),X=Oe+X),Te&&J(/((--!?|])>)|<\/(style|title|textarea)/i,X)){Ie($,e);continue}if(He==="attributename"&&rt(X,"href")){Ie($,e);continue}if(g.forceKeepAttr)continue;if(!g.keepAttr){Ie($,e);continue}if(!xe&&J(/\/>/i,X)){Ie($,e);continue}de&&Ke([V,re,he],Jt=>{X=We(X,Jt," ")});const Qt=Y(e.nodeName);if(!Vt(Qt,He,X)){Ie($,e);continue}if(_&&typeof C=="object"&&typeof C.getAttributeType=="function"&&!ne)switch(C.getAttributeType(Qt,He)){case"TrustedHTML":{X=_.createHTML(X);break}case"TrustedScriptURL":{X=_.createScriptURL(X);break}}if(X!==gt)try{ne?e.setAttributeNS(ne,$,X):e.setAttribute($,X),ht(e)?Ee(e):yt(o.removed)}catch{Ie($,e)}}Ce(I.afterSanitizeAttributes,e,null)},Gn=function E(e){let i=null;const g=Xt(e);for(Ce(I.beforeSanitizeShadowDOM,e,null);i=g.nextNode();)Ce(I.uponSanitizeShadowNode,i,null),qt(i),Zt(i),i.content instanceof h&&E(i.content);Ce(I.afterSanitizeShadowDOM,e,null)};return o.sanitize=function(E){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,g=null,z=null,Z=null;if(ft=!E,ft&&(E="<!-->"),typeof E!="string"&&!Kt(E))if(typeof E.toString=="function"){if(E=E.toString(),typeof E!="string")throw Ge("dirty is not a string, aborting")}else throw Ge("toString is not a function");if(!o.isSupported)return E;if(O||pt(e),o.removed=[],typeof E=="string"&&(oe=!1),oe){if(E.nodeName){const Ne=Y(E.nodeName);if(!A[Ne]||ye[Ne])throw Ge("root node is forbidden and cannot be sanitized in-place")}}else if(E instanceof y)i=Rt("<!---->"),g=i.ownerDocument.importNode(E,!0),g.nodeType===Ye.element&&g.nodeName==="BODY"||g.nodeName==="HTML"?i=g:i.appendChild(g);else{if(!fe&&!de&&!N&&E.indexOf("<")===-1)return _&&Se?_.createHTML(E):E;if(i=Rt(E),!i)return fe?null:Se?H:""}i&&j&&Ee(i.firstChild);const $=Xt(oe?E:i);for(;z=$.nextNode();)qt(z),Zt(z),z.content instanceof h&&Gn(z.content);if(oe)return E;if(fe){if(le)for(Z=q.call(i.ownerDocument);i.firstChild;)Z.appendChild(i.firstChild);else Z=i;return(W.shadowroot||W.shadowrootmode)&&(Z=ce.call(u,Z,!0)),Z}let ne=N?i.outerHTML:i.innerHTML;return N&&A["!doctype"]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&J(At,i.ownerDocument.doctype.name)&&(ne="<!DOCTYPE "+i.ownerDocument.doctype.name+`>
|
|
2
|
+
`+ne),de&&Ke([V,re,he],Ne=>{ne=We(ne,Ne," ")}),_&&Se?_.createHTML(ne):ne},o.setConfig=function(){let E=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};pt(E),O=!0},o.clearConfig=function(){Ue=null,O=!1},o.isValidAttribute=function(E,e,i){Ue||pt({});const g=Y(E),z=Y(e);return Vt(g,z,i)},o.addHook=function(E,e){typeof e=="function"&&Be(I[E],e)},o.removeHook=function(E,e){if(e!==void 0){const i=on(I[E],e);return i===-1?void 0:sn(I[E],i,1)[0]}return yt(I[E])},o.removeHooks=function(E){I[E]=[]},o.removeAllHooks=function(){I=wt()},o}var Lt=_t();const Dt=["p","br","span","div","strong","b","em","i","u","s","strike","del","ins","sub","sup","mark","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","source","picture","figure","figcaption","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col","blockquote","pre","code","hr","address","article","aside","details","summary","section","nav","header","footer","main"],xt=["id","class","style","title","lang","dir","href","target","rel","src","alt","width","height","loading","srcset","sizes","controls","autoplay","loop","muted","poster","preload","colspan","rowspan","scope","headers","data-*"];function je(t){return Lt.sanitize(t,{ALLOWED_TAGS:Dt,ALLOWED_ATTR:xt,ALLOW_DATA_ATTR:!0,ALLOWED_URI_REGEXP:/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i})}function Mt(t){return Lt.sanitize(t,{ALLOWED_TAGS:Dt,ALLOWED_ATTR:xt.filter(r=>!r.startsWith("data-")),ALLOW_DATA_ATTR:!1}).replace(/<p>\s*<\/p>/gi,"").replace(/<br\s*\/?>\s*$/gi,"").trim()}function Ot(t){return[/<script\b/i,/javascript:/i,/on\w+\s*=/i,/<iframe\b/i,/<object\b/i,/<embed\b/i,/data:text\/html/i].some(r=>r.test(t))}function It({editorRef:t,onContentChange:o}){const r=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand(c,!1),o()},[t,o]),u=s.useCallback(c=>document.queryCommandState(c),[]),f=s.useCallback(()=>{const c=window.getSelection();if(!c||!c.rangeCount)return"p";let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE){const D=m.tagName.toLowerCase();if(["h1","h2","h3","h4","h5","h6","p"].includes(D))return D}m=m.parentNode}return"p"},[t]),h=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("formatBlock",!1,c),o()},[t,o]),d=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand(c,!1),o()},[t,o]),y=s.useCallback(c=>{const m=window.getSelection();if(!m||!m.rangeCount)return!1;let D=m.anchorNode;for(;D&&D!==t.current;){if(D.nodeType===Node.ELEMENT_NODE&&D.tagName.toLowerCase()===c)return!0;D=D.parentNode}return!1},[t]),b=s.useCallback(()=>{const c=window.getSelection();if(!c||!c.rangeCount)return null;let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE&&m.tagName==="A")return m.href;m=m.parentNode}return null},[t]),p=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("createLink",!1,c),o()},[t,o]),k=s.useCallback(()=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("unlink",!1),o()},[t,o]),T=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),c?document.execCommand("foreColor",!1,c):document.execCommand("removeFormat",!1),o()},[t,o]),L=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),c?document.execCommand("hiliteColor",!1,c):document.execCommand("removeFormat",!1),o()},[t,o]),C=s.useCallback(()=>{const c=document.queryCommandValue("foreColor");if(c.startsWith("rgb")){const m=c.match(/\d+/g);if(m){const[D,x,A]=m.map(Number);return`#${((1<<24)+(D<<16)+(x<<8)+A).toString(16).slice(1)}`}}return c||""},[]),a=s.useCallback(()=>{const c=document.queryCommandValue("backColor");if(c.startsWith("rgb")){const m=c.match(/\d+/g);if(m){const[D,x,A]=m.map(Number);return`#${((1<<24)+(D<<16)+(x<<8)+A).toString(16).slice(1)}`}}return c||""},[]),l=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),c&&document.execCommand("fontName",!1,c),o()},[t,o]),v=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus();const m=window.getSelection();if(m&&m.rangeCount>0&&!m.isCollapsed){const D=m.getRangeAt(0),x=document.createElement("span");x.style.fontSize=c;try{D.surroundContents(x),m.removeAllRanges();const A=document.createRange();A.selectNodeContents(x),m.addRange(A)}catch{const A=parseInt(c);let G=3;A<=12?G=1:A<=14?G=2:A<=16?G=3:A<=18?G=4:A<=24?G=5:A<=32?G=6:G=7,document.execCommand("fontSize",!1,String(G))}}o()},[t,o]),F=s.useCallback(()=>document.queryCommandValue("fontName")||"",[]),R=s.useCallback(()=>{const c=window.getSelection();if(c&&c.rangeCount>0){let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE){const x=window.getComputedStyle(m).fontSize;if(x)return x}m=m.parentNode}}return""},[t]),U=s.useCallback(c=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("justify"+c.charAt(0).toUpperCase()+c.slice(1),!1),o()},[t,o]),_=s.useCallback(()=>{const c=window.getSelection();if(c&&c.rangeCount>0){let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE){const x=window.getComputedStyle(m).textAlign;if(x==="center"||x==="right"||x==="justify")return x;if(x==="start"||x==="left")return"left"}m=m.parentNode}}return"left"},[t]),H=s.useCallback(()=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("formatBlock",!1,"blockquote"),o()},[t,o]),K=s.useCallback(()=>{t.current&&document.activeElement!==t.current&&t.current.focus();const c=window.getSelection();if(c&&c.rangeCount>0){const m=c.getRangeAt(0),D=document.createElement("pre"),x=document.createElement("code"),A=m.toString()||"Code here...";x.textContent=A,D.appendChild(x),m.deleteContents(),m.insertNode(D);const G=document.createRange();G.selectNodeContents(x),c.removeAllRanges(),c.addRange(G)}o()},[t,o]),B=s.useCallback(()=>{t.current&&document.activeElement!==t.current&&t.current.focus(),document.execCommand("insertHorizontalRule",!1),o()},[t,o]),q=s.useCallback(()=>{const c=window.getSelection();if(!c||!c.rangeCount)return!1;let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE&&m.tagName==="BLOCKQUOTE")return!0;m=m.parentNode}return!1},[t]),ae=s.useCallback(()=>{const c=window.getSelection();if(!c||!c.rangeCount)return!1;let m=c.anchorNode;for(;m&&m!==t.current;){if(m.nodeType===Node.ELEMENT_NODE){const D=m.tagName;if(D==="PRE"||D==="CODE")return!0}m=m.parentNode}return!1},[t]),ce=s.useCallback(()=>r("bold"),[r]),I=s.useCallback(()=>r("italic"),[r]),V=s.useCallback(()=>r("underline"),[r]),re=s.useCallback(()=>r("strikeThrough"),[r]),he=s.useCallback(()=>d("insertUnorderedList"),[d]),Ae=s.useCallback(()=>d("insertOrderedList"),[d]),ge=s.useCallback(c=>{if(!(!t.current?.contains(document.activeElement)||!(navigator.platform.toUpperCase().includes("MAC")?c.metaKey:c.ctrlKey))){switch(c.key.toLowerCase()){case"b":c.preventDefault(),ce();break;case"i":c.preventDefault(),I();break;case"u":c.preventDefault(),V();break}c.shiftKey&&/^[1-6]$/.test(c.key)&&(c.preventDefault(),h(`h${c.key}`)),c.shiftKey&&c.key==="0"&&(c.preventDefault(),h("p"))}},[t,ce,I,V,h]);return s.useEffect(()=>(document.addEventListener("keydown",ge),()=>document.removeEventListener("keydown",ge)),[ge]),{toggleBold:ce,toggleItalic:I,toggleUnderline:V,toggleStrikethrough:re,toggleBulletList:he,toggleNumberedList:Ae,setBlockType:h,getCurrentBlockType:f,isFormatActive:u,isInList:y,insertLink:p,removeLink:k,getCurrentLink:b,setTextColor:T,setBackgroundColor:L,getCurrentTextColor:C,getCurrentBackgroundColor:a,setFontFamily:l,setFontSize:v,getCurrentFontFamily:F,getCurrentFontSize:R,setAlignment:U,getCurrentAlignment:_,insertBlockquote:H,insertCodeBlock:K,insertHorizontalRule:B,isInBlockquote:q,isInCodeBlock:ae}}function Pt(t,o={}){const{maxHistory:r=50,debounceMs:u=500}=o,f=s.useRef([]),h=s.useRef([]),d=s.useRef(t),y=s.useRef(null),b=s.useRef(t),[p,k]=s.useState({canUndo:!1,canRedo:!1}),T=s.useCallback(()=>{k({canUndo:f.current.length>0,canRedo:h.current.length>0})},[]),L=s.useCallback(v=>{d.current=v,y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{v!==b.current&&(f.current.push(b.current),f.current.length>r&&f.current.shift(),h.current=[],b.current=v,T())},u)},[r,u,T]),C=s.useCallback(()=>{if(f.current.length===0)return null;const v=f.current.pop();return h.current.push(b.current),d.current=v,b.current=v,T(),v},[T]),a=s.useCallback(()=>{if(h.current.length===0)return null;const v=h.current.pop();return f.current.push(b.current),d.current=v,b.current=v,T(),v},[T]),l=s.useCallback(v=>{f.current=[],h.current=[],d.current=v,b.current=v,T()},[T]);return s.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]),{pushToHistory:L,undo:C,redo:a,reset:l,canUndo:p.canUndo,canRedo:p.canRedo}}const Ft="p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, pre, figure, img, video, hr, table";function zt({editorRef:t,onContentChange:o}){const[r,u]=s.useState({isDragging:!1,draggedElement:null,dropIndicatorY:null,dropTarget:null,dropPosition:null}),f=s.useRef(null),h=s.useCallback(a=>{if(!t.current)return null;let l=a;for(;l&&l!==t.current;){if(l.parentElement===t.current&&l.matches(Ft))return l;l=l.parentElement}return null},[t]),d=s.useCallback(()=>t.current?Array.from(t.current.querySelectorAll(`:scope > ${Ft}`)):[],[t]),y=s.useCallback(a=>{const l=document.createElement("div");return l.className="drag-ghost",l.innerHTML=a.outerHTML,l.style.cssText=`
|
|
3
|
+
position: fixed;
|
|
4
|
+
pointer-events: none;
|
|
5
|
+
z-index: 9999;
|
|
6
|
+
opacity: 0.8;
|
|
7
|
+
transform: scale(0.95);
|
|
8
|
+
max-width: 400px;
|
|
9
|
+
background: var(--color-surface);
|
|
10
|
+
border: 1px solid var(--color-accent);
|
|
11
|
+
border-radius: 8px;
|
|
12
|
+
padding: 12px;
|
|
13
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
|
|
14
|
+
`,document.body.appendChild(l),f.current=l,l},[]),b=s.useCallback(()=>{f.current&&(f.current.remove(),f.current=null)},[]),p=s.useCallback((a,l)=>{f.current&&(f.current.style.left=`${a+10}px`,f.current.style.top=`${l+10}px`)},[]),k=s.useCallback((a,l,v)=>{let F=null,R=null,U=null;for(const _ of l){if(_===v)continue;const H=_.getBoundingClientRect(),K=H.top+H.height/2;if(a<K){F=_,R="before",U=H.top;break}else F=_,R="after",U=H.bottom}return{dropTarget:F,dropPosition:R,indicatorY:U}},[]),T=s.useCallback((a,l)=>{const v=h(a);v&&(l.preventDefault(),y(v),p(l.clientX,l.clientY),v.classList.add("dragging"),u({isDragging:!0,draggedElement:v,dropIndicatorY:null,dropTarget:null,dropPosition:null}))},[h,y,p]),L=s.useCallback(a=>{if(!r.isDragging||!r.draggedElement)return;p(a.clientX,a.clientY);const l=d(),{dropTarget:v,dropPosition:F,indicatorY:R}=k(a.clientY,l,r.draggedElement);u(U=>({...U,dropTarget:v,dropPosition:F,dropIndicatorY:R}))},[r.isDragging,r.draggedElement,p,d,k]),C=s.useCallback(()=>{if(!r.isDragging)return;const{draggedElement:a,dropTarget:l,dropPosition:v}=r;a&&a.classList.remove("dragging"),b(),a&&l&&v&&t.current&&(v==="before"?l.parentElement?.insertBefore(a,l):l.parentElement?.insertBefore(a,l.nextSibling),o()),u({isDragging:!1,draggedElement:null,dropIndicatorY:null,dropTarget:null,dropPosition:null})},[r,b,t,o]);return s.useEffect(()=>{if(r.isDragging){const a=v=>L(v),l=()=>C();return document.addEventListener("mousemove",a),document.addEventListener("mouseup",l),()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",l)}}},[r.isDragging,L,C]),{dragState:r,handleDragStart:T,findBlockParent:h}}function kn({isOpen:t,position:o,initialUrl:r="",onSubmit:u,onRemove:f,onClose:h}){const[d,y]=s.useState(r),b=s.useRef(null);s.useEffect(()=>{t&&b.current&&(y(r),setTimeout(()=>b.current?.focus(),50))},[t,r]);const p=T=>{if(T.preventDefault(),d.trim()){let L=d.trim();!/^https?:\/\//i.test(L)&&!L.startsWith("mailto:")&&(L="https://"+L),u(L)}},k=T=>{T.key==="Escape"&&h()};return t?n.jsx("div",{className:"link-popover",style:{left:o.x,top:o.y},onMouseDown:T=>T.stopPropagation(),children:n.jsxs("form",{onSubmit:p,className:"link-form",children:[n.jsx("input",{ref:b,type:"text",value:d,onChange:T=>y(T.target.value),onKeyDown:k,placeholder:"Enter URL...",className:"link-input"}),n.jsxs("div",{className:"link-actions",children:[n.jsxs("button",{type:"submit",className:"link-btn link-btn-primary",disabled:!d.trim(),children:[r?"Update":"Add"," Link"]}),r&&n.jsx("button",{type:"button",className:"link-btn link-btn-danger",onClick:f,children:"Remove"}),n.jsx("button",{type:"button",className:"link-btn",onClick:h,children:"Cancel"})]})]})}):null}const Cn=[["#000000","#374151","#6b7280","#9ca3af","#d1d5db","#f3f4f6","#ffffff"],["#7f1d1d","#b91c1c","#dc2626","#ef4444","#f87171","#fca5a5","#fee2e2"],["#78350f","#b45309","#d97706","#f59e0b","#fbbf24","#fcd34d","#fef3c7"],["#14532d","#166534","#16a34a","#22c55e","#4ade80","#86efac","#dcfce7"],["#1e3a8a","#1d4ed8","#2563eb","#3b82f6","#60a5fa","#93c5fd","#dbeafe"],["#4c1d95","#6d28d9","#7c3aed","#8b5cf6","#a78bfa","#c4b5fd","#ede9fe"],["#831843","#be185d","#db2777","#ec4899","#f472b6","#f9a8d4","#fce7f3"]];function Ut({isOpen:t,position:o,currentColor:r,type:u,onSelect:f,onClose:h}){const[d,y]=s.useState(r||"#000000"),b=s.useRef(null);if(s.useEffect(()=>{const C=a=>{b.current&&!b.current.contains(a.target)&&h()};if(t)return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[t,h]),!t)return null;const p=C=>{f(C),h()},k=C=>{y(C.target.value)},T=()=>{f(d),h()},L=()=>{f(""),h()};return n.jsxs("div",{ref:b,className:"color-picker",style:{left:o.x,top:o.y},onMouseDown:C=>C.preventDefault(),children:[n.jsxs("div",{className:"color-picker-header",children:[n.jsx("span",{className:"color-picker-title",children:u==="text"?"Text Color":"Background Color"}),n.jsx("button",{className:"color-picker-close",onClick:h,children:"✕"})]}),n.jsx("div",{className:"color-presets",children:Cn.map((C,a)=>n.jsx("div",{className:"color-row",children:C.map(l=>n.jsx("button",{type:"button",className:`color-swatch ${l===r?"active":""} ${l==="#ffffff"?"white":""}`,style:{backgroundColor:l},onClick:()=>p(l),title:l},l))},a))}),n.jsxs("div",{className:"color-custom",children:[n.jsx("input",{type:"color",value:d,onChange:k,className:"color-input-native"}),n.jsx("input",{type:"text",value:d,onChange:C=>y(C.target.value),className:"color-input-text",placeholder:"#000000"}),n.jsx("button",{type:"button",className:"color-apply-btn",onClick:T,children:"Apply"})]}),n.jsxs("button",{type:"button",className:"color-remove-btn",onClick:L,children:["Remove ",u==="text"?"text":"background"," color"]})]})}const Nn=[{value:"",label:"Default"},{value:"Arial, sans-serif",label:"Arial"},{value:"Georgia, serif",label:"Georgia"},{value:"Times New Roman, serif",label:"Times New Roman"},{value:"Courier New, monospace",label:"Courier New"},{value:"Verdana, sans-serif",label:"Verdana"},{value:"Trebuchet MS, sans-serif",label:"Trebuchet MS"},{value:"Impact, sans-serif",label:"Impact"},{value:"Comic Sans MS, cursive",label:"Comic Sans"}],An=[{value:"12px",label:"Small"},{value:"14px",label:"Normal"},{value:"16px",label:"Medium"},{value:"18px",label:"Large"},{value:"24px",label:"XL"},{value:"32px",label:"2XL"},{value:"48px",label:"3XL"}];function Sn({isOpen:t,position:o,currentFont:r,currentSize:u,onFontChange:f,onSizeChange:h,onClose:d}){const[y,b]=s.useState("font"),p=s.useRef(null);return s.useEffect(()=>{const k=T=>{p.current&&!p.current.contains(T.target)&&d()};if(t)return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[t,d]),t?n.jsxs("div",{ref:p,className:"font-picker",style:{left:o.x,top:o.y},onMouseDown:k=>k.preventDefault(),children:[n.jsxs("div",{className:"font-picker-header",children:[n.jsx("button",{className:`font-tab ${y==="font"?"active":""}`,onClick:()=>b("font"),children:"Font"}),n.jsx("button",{className:`font-tab ${y==="size"?"active":""}`,onClick:()=>b("size"),children:"Size"}),n.jsx("button",{className:"font-picker-close",onClick:d,children:"✕"})]}),n.jsx("div",{className:"font-picker-content",children:y==="font"?n.jsx("div",{className:"font-list",children:Nn.map(({value:k,label:T})=>n.jsx("button",{type:"button",className:`font-item ${r===k?"active":""}`,style:{fontFamily:k||"inherit"},onClick:()=>{f(k),d()},children:T},T))}):n.jsx("div",{className:"size-list",children:An.map(({value:k,label:T})=>n.jsxs("button",{type:"button",className:`size-item ${u===k?"active":""}`,onClick:()=>{h(k),d()},children:[n.jsx("span",{className:"size-preview",style:{fontSize:k},children:"Aa"}),n.jsx("span",{className:"size-label",children:T}),n.jsx("span",{className:"size-value",children:k})]},k))})})]}):null}function wn({isOpen:t,position:o,onInsertBlockquote:r,onInsertCodeBlock:u,onInsertHorizontalRule:f,onClose:h}){const d=s.useRef(null);if(s.useEffect(()=>{const b=p=>{d.current&&!d.current.contains(p.target)&&h()};if(t)return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[t,h]),!t)return null;const y=b=>{b(),h()};return n.jsxs("div",{ref:d,className:"insert-menu",style:{left:o.x,top:o.y},onMouseDown:b=>b.preventDefault(),children:[n.jsx("div",{className:"insert-menu-header",children:"Insert Block"}),n.jsxs("button",{type:"button",className:"insert-menu-item",onClick:()=>y(r),children:[n.jsx("span",{className:"insert-icon",children:"❝"}),n.jsxs("div",{className:"insert-info",children:[n.jsx("span",{className:"insert-label",children:"Blockquote"}),n.jsx("span",{className:"insert-desc",children:"Add a quote block"})]})]}),n.jsxs("button",{type:"button",className:"insert-menu-item",onClick:()=>y(u),children:[n.jsx("span",{className:"insert-icon",children:"</>"}),n.jsxs("div",{className:"insert-info",children:[n.jsx("span",{className:"insert-label",children:"Code Block"}),n.jsx("span",{className:"insert-desc",children:"Add code snippet"})]})]}),n.jsxs("button",{type:"button",className:"insert-menu-item",onClick:()=>y(f),children:[n.jsx("span",{className:"insert-icon",children:"―"}),n.jsxs("div",{className:"insert-info",children:[n.jsx("span",{className:"insert-label",children:"Divider"}),n.jsx("span",{className:"insert-desc",children:"Horizontal line"})]})]})]})}const Ht=[{value:"p",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"}];function _n({editorRef:t,formatState:o,onBold:r,onItalic:u,onUnderline:f,onStrikethrough:h,onBlockType:d,onBulletList:y,onNumberedList:b,onInsertLink:p,onRemoveLink:k,onTextColor:T,onBackgroundColor:L,onFontFamily:C,onFontSize:a,onAlignment:l,onInsertBlockquote:v,onInsertCodeBlock:F,onInsertHorizontalRule:R}){const[U,_]=s.useState({x:0,y:0,visible:!1}),[H,K]=s.useState(!1),[B,q]=s.useState(!1),[ae,ce]=s.useState(!1),[I,V]=s.useState(!1),[re,he]=s.useState(!1),[Ae,ge]=s.useState(!1),[c,m]=s.useState({x:0,y:0}),[D,x]=s.useState({x:0,y:0}),[A,G]=s.useState({x:0,y:0}),[W,Pe]=s.useState({x:0,y:0}),M=s.useCallback(()=>{const N=window.getSelection();if(!N||N.isCollapsed||!N.rangeCount||!t.current){_(oe=>({...oe,visible:!1})),K(!1);return}const O=N.getRangeAt(0);if(!t.current.contains(O.commonAncestorContainer)){_(oe=>({...oe,visible:!1})),K(!1);return}const j=O.getBoundingClientRect(),fe=t.current.getBoundingClientRect(),le=450,Se=44,Me=8;let be=j.left+j.width/2-le/2,Oe=j.top-Se-Me;const ve=8;be=Math.max(ve,Math.min(be,window.innerWidth-le-ve)),Oe<ve&&(Oe=j.bottom+Me),j.top>=fe.top-50&&j.bottom<=fe.bottom+50?_({x:be,y:Oe,visible:!0}):_(oe=>({...oe,visible:!1}))},[t]);s.useEffect(()=>{const N=()=>{!B&&!ae&&!I&&!re&&requestAnimationFrame(M)},O=()=>{!B&&!ae&&!I&&!re&&setTimeout(M,10)};return document.addEventListener("selectionchange",N),document.addEventListener("mouseup",O),()=>{document.removeEventListener("selectionchange",N),document.removeEventListener("mouseup",O)}},[M,B,ae,I]),s.useEffect(()=>{const N=()=>{M()};return window.addEventListener("scroll",N,!0),()=>window.removeEventListener("scroll",N,!0)},[M]),s.useEffect(()=>{const N=O=>{const j=O.target;j.closest(".block-menu-wrapper")||K(!1),!j.closest(".link-popover")&&!j.closest(".link-btn-toolbar")&&q(!1)};if(H||B)return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[H,B]);const ye=N=>{const O=N.target.getBoundingClientRect();m({x:O.left,y:O.bottom+8}),q(!0)},_e=N=>{const O=N.target.getBoundingClientRect();x({x:Math.max(8,O.left-100),y:O.bottom+8}),ce(!0),V(!1)},ue=N=>{const O=N.target.getBoundingClientRect();x({x:Math.max(8,O.left-100),y:O.bottom+8}),V(!0),ce(!1)},Le=N=>{const O=N.target.getBoundingClientRect();G({x:Math.max(8,O.left-50),y:O.bottom+8}),he(!0)},De=N=>{const O=N.target.getBoundingClientRect();Pe({x:Math.max(8,O.left-50),y:O.bottom+8}),ge(!0)},Fe=N=>{p(N),q(!1)},xe=()=>{k(),q(!1)};if(!U.visible)return null;const de=Ht.find(N=>N.value===o.blockType)?.label||"Paragraph",Te=!!o.currentLink;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"floating-toolbar",style:{left:U.x,top:U.y},onMouseDown:N=>N.preventDefault(),children:[n.jsxs("div",{className:"block-menu-wrapper",children:[n.jsxs("button",{type:"button",className:"floating-btn block-btn",onClick:()=>K(!H),title:"Text style",children:[de,n.jsx("span",{className:"dropdown-arrow",children:"▾"})]}),H&&n.jsx("div",{className:"block-menu",children:Ht.map(({value:N,label:O})=>n.jsx("button",{type:"button",className:`block-menu-item ${o.blockType===N?"active":""}`,onClick:()=>{d(N),K(!1)},children:O},N))})]}),n.jsx("button",{type:"button",className:`floating-btn font-btn ${re?"active":""}`,onClick:Le,title:"Font & Size",children:"Aa"}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:`floating-btn ${o.bold?"active":""}`,onClick:r,title:"Bold (Ctrl+B)",children:n.jsx("strong",{children:"B"})}),n.jsx("button",{type:"button",className:`floating-btn ${o.italic?"active":""}`,onClick:u,title:"Italic (Ctrl+I)",children:n.jsx("em",{children:"I"})}),n.jsx("button",{type:"button",className:`floating-btn ${o.underline?"active":""}`,onClick:f,title:"Underline (Ctrl+U)",children:n.jsx("u",{children:"U"})}),n.jsx("button",{type:"button",className:"floating-btn",onClick:h,title:"Strikethrough",children:n.jsx("s",{children:"S"})}),n.jsx("div",{className:"toolbar-divider"}),n.jsxs("button",{type:"button",className:`floating-btn color-btn ${ae?"active":""}`,onClick:_e,title:"Text color",children:[n.jsx("span",{className:"color-icon",children:"A"}),n.jsx("span",{className:"color-bar",style:{backgroundColor:o.textColor||"#000000"}})]}),n.jsxs("button",{type:"button",className:`floating-btn color-btn ${I?"active":""}`,onClick:ue,title:"Background color",children:[n.jsx("span",{className:"color-icon bg-icon",children:"A"}),n.jsx("span",{className:"color-bar",style:{backgroundColor:o.backgroundColor||"transparent"}})]}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:`floating-btn link-btn-toolbar ${Te?"active":""}`,onClick:ye,title:Te?"Edit link (Ctrl+K)":"Add link (Ctrl+K)",children:"🔗"}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:`floating-btn ${o.bulletList?"active":""}`,onClick:y,title:"Bullet list",children:"•≡"}),n.jsx("button",{type:"button",className:`floating-btn ${o.numberedList?"active":""}`,onClick:b,title:"Numbered list",children:"1."}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:`floating-btn align-btn ${o.alignment==="left"?"active":""}`,onClick:()=>l("left"),title:"Align left",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[n.jsx("rect",{x:"1",y:"2",width:"14",height:"2",rx:"0.5"}),n.jsx("rect",{x:"1",y:"7",width:"10",height:"2",rx:"0.5"}),n.jsx("rect",{x:"1",y:"12",width:"12",height:"2",rx:"0.5"})]})}),n.jsx("button",{type:"button",className:`floating-btn align-btn ${o.alignment==="center"?"active":""}`,onClick:()=>l("center"),title:"Align center",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[n.jsx("rect",{x:"1",y:"2",width:"14",height:"2",rx:"0.5"}),n.jsx("rect",{x:"3",y:"7",width:"10",height:"2",rx:"0.5"}),n.jsx("rect",{x:"2",y:"12",width:"12",height:"2",rx:"0.5"})]})}),n.jsx("button",{type:"button",className:`floating-btn align-btn ${o.alignment==="right"?"active":""}`,onClick:()=>l("right"),title:"Align right",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[n.jsx("rect",{x:"1",y:"2",width:"14",height:"2",rx:"0.5"}),n.jsx("rect",{x:"5",y:"7",width:"10",height:"2",rx:"0.5"}),n.jsx("rect",{x:"3",y:"12",width:"12",height:"2",rx:"0.5"})]})}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:`floating-btn insert-btn ${Ae?"active":""}`,onClick:De,title:"Insert block",children:"+"})]}),n.jsx(kn,{isOpen:B,position:c,initialUrl:o.currentLink||"",onSubmit:Fe,onRemove:xe,onClose:()=>q(!1)}),n.jsx(Ut,{isOpen:ae,position:D,currentColor:o.textColor,type:"text",onSelect:T,onClose:()=>ce(!1)}),n.jsx(Ut,{isOpen:I,position:D,currentColor:o.backgroundColor,type:"background",onSelect:L,onClose:()=>V(!1)}),n.jsx(Sn,{isOpen:re,position:A,currentFont:o.fontFamily,currentSize:o.fontSize,onFontChange:C,onSizeChange:a,onClose:()=>he(!1)}),n.jsx(wn,{isOpen:Ae,position:W,onInsertBlockquote:v,onInsertCodeBlock:F,onInsertHorizontalRule:R,onClose:()=>ge(!1)})]})}function Ln({selectedElement:t,assets:o,onReplace:r,onDelete:u,onUpload:f}){const[h,d]=s.useState({x:0,y:0,visible:!1}),[y,b]=s.useState(!1),[p,k]=s.useState(!1),T=s.useCallback(()=>{if(!t){d(H=>({...H,visible:!1}));return}const l=t.getBoundingClientRect(),v=44,F=8;let R=l.left+l.width/2-100,U=l.top-v-F;const _=8;R=Math.max(_,Math.min(R,window.innerWidth-200-_)),U<_&&(U=l.bottom+F),d({x:R,y:U,visible:!0})},[t]);s.useEffect(()=>{T();const l=()=>T();return window.addEventListener("scroll",l,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",T)}},[T]),s.useEffect(()=>{const l=v=>{const F=v.target;!F.closest(".asset-picker")&&!F.closest(".media-toolbar")&&b(!1)};if(y)return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[y]);const L=async l=>{const v=l.target.files?.[0];if(!(!v||!f)){k(!0);try{const F=await f(v);r(F),b(!1)}catch(F){console.error("Upload failed:",F)}finally{k(!1)}}};if(!h.visible)return null;const C=t?.tagName==="IMG",a=t?.getAttribute("src")||"";return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"media-toolbar",style:{left:h.x,top:h.y},onMouseDown:l=>l.preventDefault(),children:[n.jsx("button",{type:"button",className:"media-btn",onClick:()=>b(!y),title:"Replace media",children:"🔄 Replace"}),n.jsx("div",{className:"toolbar-divider"}),n.jsx("button",{type:"button",className:"media-btn media-btn-danger",onClick:u,title:"Delete media",children:"🗑️"})]}),y&&n.jsxs("div",{className:"asset-picker",style:{left:h.x,top:h.y+52},children:[n.jsxs("div",{className:"asset-picker-header",children:[n.jsx("span",{className:"asset-picker-title",children:C?"Replace Image":"Replace Video"}),n.jsx("button",{type:"button",className:"asset-picker-close",onClick:()=>b(!1),children:"✕"})]}),f&&n.jsx("div",{className:"asset-upload",children:n.jsxs("label",{className:"upload-btn",children:[p?"Uploading...":"📤 Upload new",n.jsx("input",{type:"file",accept:C?"image/*":"video/*",onChange:L,disabled:p,hidden:!0})]})}),o.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"asset-divider",children:"or choose from library"}),n.jsx("div",{className:"asset-grid",children:o.filter(l=>C?l.type==="image":l.type==="video").map(l=>n.jsx("button",{type:"button",className:`asset-item ${l.url===a?"active":""}`,onClick:()=>{r(l.url),b(!1)},title:l.name,children:l.type==="image"?n.jsx("img",{src:l.url,alt:l.name}):n.jsx("video",{src:l.url})},l.id))})]}),o.length===0&&!f&&n.jsx("div",{className:"asset-empty",children:"No assets available"})]})]})}function Dn({editorRef:t,onDragStart:o,findBlockParent:r}){const[u,f]=s.useState({x:0,y:0,visible:!1,targetElement:null}),h=s.useRef(null),d=s.useRef(null),y=s.useRef(!1),b=s.useCallback(a=>{if(!t.current)return;d.current&&(clearTimeout(d.current),d.current=null);const l=a.getBoundingClientRect(),v=t.current.getBoundingClientRect();f({x:v.left-36,y:l.top+l.height/2-12,visible:!0,targetElement:a})},[t]),p=s.useCallback((a=150)=>{y.current||(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{y.current||f(l=>({...l,visible:!1,targetElement:null}))},a))},[]),k=s.useCallback(a=>{if(!t.current)return;const l=a.target;if(l.closest(".drag-handle"))return;const v=r(l);v?b(v):p()},[t,r,b,p]);s.useEffect(()=>{const a=t.current;if(!a)return;const l=F=>{k(F)},v=()=>{p(300)};return a.addEventListener("mousemove",l),a.addEventListener("mouseleave",v),()=>{a.removeEventListener("mousemove",l),a.removeEventListener("mouseleave",v),d.current&&clearTimeout(d.current)}},[t,k,p]);const T=s.useCallback(()=>{y.current=!0,d.current&&(clearTimeout(d.current),d.current=null)},[]),L=s.useCallback(()=>{y.current=!1,p(300)},[p]),C=s.useCallback(a=>{a.preventDefault(),u.targetElement&&o(u.targetElement,a.nativeEvent)},[u.targetElement,o]);return u.visible?n.jsx("div",{ref:h,className:"drag-handle",style:{left:u.x,top:u.y},onMouseEnter:T,onMouseLeave:L,onMouseDown:C,title:"Drag to reorder",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:[n.jsx("circle",{cx:"5",cy:"4",r:"1.5"}),n.jsx("circle",{cx:"11",cy:"4",r:"1.5"}),n.jsx("circle",{cx:"5",cy:"8",r:"1.5"}),n.jsx("circle",{cx:"11",cy:"8",r:"1.5"}),n.jsx("circle",{cx:"5",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"11",cy:"12",r:"1.5"})]})}):null}function xn({y:t}){return t===null?null:n.jsxs("div",{className:"drop-indicator",style:{top:t},children:[n.jsx("div",{className:"drop-indicator-dot"}),n.jsx("div",{className:"drop-indicator-line"}),n.jsx("div",{className:"drop-indicator-dot"})]})}function Mn({selectedImage:t,onResize:o}){const[r,u]=s.useState({x:0,y:0,width:0,height:0,visible:!1}),[f,h]=s.useState({isResizing:!1,handle:null,startX:0,startY:0,startWidth:0,startHeight:0}),d=s.useRef(1),y=s.useCallback(()=>{if(!t){u(k=>({...k,visible:!1}));return}const p=t.getBoundingClientRect();u({x:p.left,y:p.top,width:p.width,height:p.height,visible:!0}),d.current=p.width/p.height},[t]);s.useEffect(()=>{y();const p=()=>y(),k=()=>y();return window.addEventListener("scroll",p,!0),window.addEventListener("resize",k),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",k)}},[y]);const b=s.useCallback((p,k)=>{if(p.preventDefault(),p.stopPropagation(),!t)return;const T=t.getBoundingClientRect();h({isResizing:!0,handle:k,startX:p.clientX,startY:p.clientY,startWidth:T.width,startHeight:T.height})},[t]);return s.useEffect(()=>{if(!f.isResizing||!t)return;const p=T=>{const L=T.clientX-f.startX;let C=f.startWidth,a=f.startHeight;switch(f.handle){case"se":C=Math.max(50,f.startWidth+L),a=C/d.current;break;case"sw":C=Math.max(50,f.startWidth-L),a=C/d.current;break;case"ne":C=Math.max(50,f.startWidth+L),a=C/d.current;break;case"nw":C=Math.max(50,f.startWidth-L),a=C/d.current;break}t.style.width=`${C}px`,t.style.height=`${a}px`,u(l=>({...l,width:C,height:a}))},k=()=>{const T=parseInt(t.style.width),L=parseInt(t.style.height);!isNaN(T)&&!isNaN(L)&&o(T,L),h({isResizing:!1,handle:null,startX:0,startY:0,startWidth:0,startHeight:0})};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",k),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",k)}},[f,t,o]),r.visible?n.jsxs("div",{className:`image-resizer ${f.isResizing?"resizing":""}`,style:{left:r.x,top:r.y,width:r.width,height:r.height},children:[n.jsx("div",{className:"resize-handle nw",onMouseDown:p=>b(p,"nw")}),n.jsx("div",{className:"resize-handle ne",onMouseDown:p=>b(p,"ne")}),n.jsx("div",{className:"resize-handle sw",onMouseDown:p=>b(p,"sw")}),n.jsx("div",{className:"resize-handle se",onMouseDown:p=>b(p,"se")}),f.isResizing&&n.jsxs("div",{className:"size-indicator",children:[Math.round(r.width)," × ",Math.round(r.height)]})]}):null}const Bt=typeof navigator<"u"&&navigator.platform.toUpperCase().includes("MAC"),pe=Bt?"⌘":"Ctrl",On=[{category:"Text Formatting",items:[{keys:[`${pe}`,"B"],description:"Bold"},{keys:[`${pe}`,"I"],description:"Italic"},{keys:[`${pe}`,"U"],description:"Underline"},{keys:[`${pe}`,"K"],description:"Insert link"}]},{category:"Headings",items:[{keys:[`${pe}`,"Shift","1"],description:"Heading 1"},{keys:[`${pe}`,"Shift","2"],description:"Heading 2"},{keys:[`${pe}`,"Shift","3"],description:"Heading 3"},{keys:[`${pe}`,"Shift","0"],description:"Paragraph"}]},{category:"History",items:[{keys:[`${pe}`,"Z"],description:"Undo"},{keys:[`${pe}`,"Shift","Z"],description:"Redo"},...Bt?[]:[{keys:["Ctrl","Y"],description:"Redo (Alt)"}]]},{category:"Selection",items:[{keys:["Esc"],description:"Deselect / Close menu"},{keys:["Delete"],description:"Delete selected element"}]}];function In({isOpen:t,onClose:o}){const r=s.useCallback(u=>{u.key==="Escape"&&o()},[o]);return s.useEffect(()=>{if(t)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[t,r]),t?n.jsx("div",{className:"shortcuts-overlay",onClick:o,children:n.jsxs("div",{className:"shortcuts-modal",onClick:u=>u.stopPropagation(),children:[n.jsxs("div",{className:"shortcuts-header",children:[n.jsx("h2",{className:"shortcuts-title",children:"Keyboard Shortcuts"}),n.jsx("button",{className:"shortcuts-close",onClick:o,children:"✕"})]}),n.jsx("div",{className:"shortcuts-content",children:On.map(({category:u,items:f})=>n.jsxs("div",{className:"shortcuts-section",children:[n.jsx("h3",{className:"shortcuts-category",children:u}),n.jsx("div",{className:"shortcuts-list",children:f.map(({keys:h,description:d})=>n.jsxs("div",{className:"shortcut-item",children:[n.jsx("span",{className:"shortcut-desc",children:d}),n.jsx("span",{className:"shortcut-keys",children:h.map((y,b)=>n.jsxs("span",{children:[n.jsx("kbd",{className:"shortcut-key",children:y}),b<h.length-1&&n.jsx("span",{className:"shortcut-plus",children:"+"})]},b))})]},d))})]},u))}),n.jsxs("div",{className:"shortcuts-footer",children:["Press ",n.jsx("kbd",{children:"Esc"})," or click outside to close"]})]})}):null}function Pn({html:t,onChange:o,placeholder:r="Start typing...",debounceMs:u=300,assets:f=[],onUpload:h}){const d=s.useRef(null),y=s.useRef(!1),b=s.useRef(!1),p=s.useRef(void 0),[k,T]=s.useState(!1),[L,C]=s.useState(!1),[a,l]=s.useState(null),[v,F]=s.useState({bold:!1,italic:!1,underline:!1,blockType:"p",bulletList:!1,numberedList:!1,currentLink:null,textColor:"",backgroundColor:"",fontFamily:"",fontSize:"",alignment:"left"}),{pushToHistory:R,undo:U,redo:_,canUndo:H,canRedo:K}=Pt(t,{maxHistory:50,debounceMs:500}),B=s.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{if(d.current){y.current=!0;const S=d.current.innerHTML,P=Mt(S);b.current||R(P),b.current=!1,o(P)}},u)},[o,u,R]),{dragState:q,handleDragStart:ae,findBlockParent:ce}=zt({editorRef:d,onContentChange:B}),I=s.useCallback(()=>{const S=U();S!==null&&d.current&&(b.current=!0,y.current=!0,d.current.innerHTML=je(S),o(S))},[U,o]),V=s.useCallback(()=>{const S=_();S!==null&&d.current&&(b.current=!0,y.current=!0,d.current.innerHTML=je(S),o(S))},[_,o]),{toggleBold:re,toggleItalic:he,toggleUnderline:Ae,toggleStrikethrough:ge,toggleBulletList:c,toggleNumberedList:m,setBlockType:D,getCurrentBlockType:x,isFormatActive:A,isInList:G,insertLink:W,removeLink:Pe,getCurrentLink:M,setTextColor:ye,setBackgroundColor:_e,getCurrentTextColor:ue,getCurrentBackgroundColor:Le,setFontFamily:De,setFontSize:Fe,getCurrentFontFamily:xe,getCurrentFontSize:de,setAlignment:Te,getCurrentAlignment:N,insertBlockquote:O,insertCodeBlock:j,insertHorizontalRule:fe}=It({editorRef:d,onContentChange:B}),le=s.useCallback(()=>{F({bold:A("bold"),italic:A("italic"),underline:A("underline"),blockType:x(),bulletList:G("ul"),numberedList:G("ol"),currentLink:M(),textColor:ue(),backgroundColor:Le(),fontFamily:xe(),fontSize:de(),alignment:N()})},[A,x,G,M,ue,Le,xe,de,N]),Se=s.useCallback(S=>{const P=S.target;P.tagName==="IMG"||P.tagName==="VIDEO"?(S.preventDefault(),l(P),P.classList.add("media-selected")):a&&(a.classList.remove("media-selected"),l(null))},[a]),Me=s.useCallback(S=>{a&&(a.setAttribute("src",S),a.classList.remove("media-selected"),l(null),B())},[a,B]),be=s.useCallback(()=>{a&&(a.classList.remove("media-selected"),a.remove(),l(null),B())},[a,B]),Oe=s.useCallback((S,P)=>{a&&a.tagName==="IMG"&&(a.setAttribute("width",String(S)),a.setAttribute("height",String(P)),a.style.width=`${S}px`,a.style.height=`${P}px`,B())},[a,B]);s.useEffect(()=>{const S=P=>{if(a&&(P.key==="Delete"||P.key==="Backspace")){P.preventDefault(),be();return}if(a&&P.key==="Escape"){a.classList.remove("media-selected"),l(null);return}if(!d.current?.contains(document.activeElement))return;const Re=navigator.platform.toUpperCase().includes("MAC");(Re?P.metaKey:P.ctrlKey)&&((P.key==="z"||P.key==="Z")&&(P.preventDefault(),P.shiftKey?V():I()),P.key==="y"&&!Re&&(P.preventDefault(),V()))};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[I,V,a,be]),s.useEffect(()=>{if(d.current&&!y.current){Ot(t)&&(T(!0),setTimeout(()=>T(!1),3e3));const S=je(t);d.current.innerHTML!==S&&(d.current.innerHTML=S)}y.current=!1},[t]);const ve=s.useCallback(()=>{B(),le()},[B,le]);s.useEffect(()=>{const S=()=>{d.current?.contains(document.activeElement)&&le()};return document.addEventListener("selectionchange",S),()=>document.removeEventListener("selectionchange",S)},[le]),s.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const oe=s.useCallback(S=>{S.preventDefault()},[]),we=!t||t==="<br>"||t==="<p><br></p>";return n.jsxs("div",{className:`wysiwyg-editor-wrapper ${q.isDragging?"is-dragging":""}`,children:[k&&n.jsx("div",{className:"wysiwyg-warning",children:"⚠️ Potentially unsafe content was sanitized"}),!q.isDragging&&n.jsx(_n,{editorRef:d,formatState:v,onBold:re,onItalic:he,onUnderline:Ae,onStrikethrough:ge,onBlockType:D,onBulletList:c,onNumberedList:m,onInsertLink:W,onRemoveLink:Pe,onTextColor:ye,onBackgroundColor:_e,onFontFamily:De,onFontSize:Fe,onAlignment:Te,onInsertBlockquote:O,onInsertCodeBlock:j,onInsertHorizontalRule:fe}),!q.isDragging&&n.jsx(Ln,{selectedElement:a,assets:f,onReplace:Me,onDelete:be,onUpload:h}),!q.isDragging&&a?.tagName==="IMG"&&n.jsx(Mn,{selectedImage:a,onResize:Oe}),!q.isDragging&&n.jsx(Dn,{editorRef:d,onDragStart:ae,findBlockParent:ce}),n.jsx(xn,{y:q.dropIndicatorY}),n.jsxs("div",{className:"wysiwyg-hint-bar",children:[n.jsxs("div",{className:"history-buttons",children:[n.jsx("button",{type:"button",className:`history-btn ${H?"":"disabled"}`,onClick:I,disabled:!H,title:"Undo (Ctrl+Z)",children:"↶ Undo"}),n.jsx("button",{type:"button",className:`history-btn ${K?"":"disabled"}`,onClick:V,disabled:!K,title:"Redo (Ctrl+Shift+Z)",children:"↷ Redo"})]}),n.jsx("span",{className:"hint-text",children:"Drag ⋮⋮ to reorder • Select text to format"}),n.jsx("button",{type:"button",className:"shortcuts-btn",onClick:()=>C(!0),title:"Keyboard shortcuts",children:"⌨️"})]}),n.jsx(In,{isOpen:L,onClose:()=>C(!1)}),n.jsx("div",{ref:d,className:`wysiwyg-editor ${we?"wysiwyg-editor--empty":""}`,contentEditable:!0,suppressContentEditableWarning:!0,onInput:ve,onClick:Se,onDragStart:oe,"data-placeholder":r,spellCheck:!0,role:"textbox","aria-multiline":"true","aria-label":"Rich text editor","aria-placeholder":r})]})}te.WysiwygEditor=Pn,te.containsDangerousContent=Ot,te.sanitizeForOutput=Mt,te.sanitizeHtml=je,te.useDragAndDrop=zt,te.useHistory=Pt,te.useTextFormatting=It,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|
|
15
|
+
//# sourceMappingURL=wysiwyg-editor.umd.cjs.map
|