@datazymes/dz-rich-text-editor
Version:
A comprehensive React rich text editor component with image upload, resize functionality, and standalone CSS. Ready for NPM publishing.
58 lines (55 loc) • 51.9 kB
JavaScript
(function(c,ge){typeof exports=="object"&&typeof module<"u"?module.exports=ge(require("react")):typeof define=="function"&&define.amd?define(["react"],ge):(c=typeof globalThis<"u"?globalThis:c||self,c.DZRichTextEditor=ge(c.React))})(this,function(c){"use strict";var ge={exports:{}},Fe={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Dt;function Ht(){if(Dt)return Fe;Dt=1;var M=c,k=Symbol.for("react.element"),$=Symbol.for("react.fragment"),A=Object.prototype.hasOwnProperty,_=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ee={key:!0,ref:!0,__self:!0,__source:!0};function W(T,y,z){var R,D={},X=null,g=null;z!==void 0&&(X=""+z),y.key!==void 0&&(X=""+y.key),y.ref!==void 0&&(g=y.ref);for(R in y)A.call(y,R)&&!ee.hasOwnProperty(R)&&(D[R]=y[R]);if(T&&T.defaultProps)for(R in y=T.defaultProps,y)D[R]===void 0&&(D[R]=y[R]);return{$$typeof:k,type:T,key:X,ref:g,props:D,_owner:_.current}}return Fe.Fragment=$,Fe.jsx=W,Fe.jsxs=W,Fe}var Ue={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Pt;function Ot(){return Pt||(Pt=1,process.env.NODE_ENV!=="production"&&function(){var M=c,k=Symbol.for("react.element"),$=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),ee=Symbol.for("react.profiler"),W=Symbol.for("react.provider"),T=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),z=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),D=Symbol.for("react.memo"),X=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),Re=Symbol.iterator,Ye="@@iterator";function vt(t){if(t===null||typeof t!="object")return null;var s=Re&&t[Re]||t[Ye];return typeof s=="function"?s:null}var ie=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function j(t){{for(var s=arguments.length,o=new Array(s>1?s-1:0),u=1;u<s;u++)o[u-1]=arguments[u];Ve("error",t,o)}}function Ve(t,s,o){{var u=ie.ReactDebugCurrentFrame,p=u.getStackAddendum();p!==""&&(s+="%s",o=o.concat([p]));var b=o.map(function(f){return String(f)});b.unshift("Warning: "+s),Function.prototype.apply.call(console[t],console,b)}}var Ne=!1,Xe=!1,Je=!1,Le=!1,ct=!1,ce;ce=Symbol.for("react.module.reference");function yt(t){return!!(typeof t=="string"||typeof t=="function"||t===A||t===ee||ct||t===_||t===z||t===R||Le||t===g||Ne||Xe||Je||typeof t=="object"&&t!==null&&(t.$$typeof===X||t.$$typeof===D||t.$$typeof===W||t.$$typeof===T||t.$$typeof===y||t.$$typeof===ce||t.getModuleId!==void 0))}function Ke(t,s,o){var u=t.displayName;if(u)return u;var p=s.displayName||s.name||"";return p!==""?o+"("+p+")":o}function _e(t){return t.displayName||"Context"}function B(t){if(t==null)return null;if(typeof t.tag=="number"&&j("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case A:return"Fragment";case $:return"Portal";case ee:return"Profiler";case _:return"StrictMode";case z:return"Suspense";case R:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case T:var s=t;return _e(s)+".Consumer";case W:var o=t;return _e(o._context)+".Provider";case y:return Ke(t,t.render,"ForwardRef");case D:var u=t.displayName||null;return u!==null?u:B(t.type)||"Memo";case X:{var p=t,b=p._payload,f=p._init;try{return B(f(b))}catch{return null}}}return null}var te=Object.assign,re=0,Ge,Ze,dt,Ae,be,ut,ve;function ft(){}ft.__reactDisabledLog=!0;function Qe(){{if(re===0){Ge=console.log,Ze=console.info,dt=console.warn,Ae=console.error,be=console.group,ut=console.groupCollapsed,ve=console.groupEnd;var t={configurable:!0,enumerable:!0,value:ft,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}re++}}function qe(){{if(re--,re===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:te({},t,{value:Ge}),info:te({},t,{value:Ze}),warn:te({},t,{value:dt}),error:te({},t,{value:Ae}),group:te({},t,{value:be}),groupCollapsed:te({},t,{value:ut}),groupEnd:te({},t,{value:ve})})}re<0&&j("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var I=ie.ReactCurrentDispatcher,$e;function De(t,s,o){{if($e===void 0)try{throw Error()}catch(p){var u=p.stack.trim().match(/\n( *(at )?)/);$e=u&&u[1]||""}return`
`+$e+t}}var Pe=!1,J;{var ze=typeof WeakMap=="function"?WeakMap:Map;J=new ze}function xt(t,s){if(!t||Pe)return"";{var o=J.get(t);if(o!==void 0)return o}var u;Pe=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var b;b=I.current,I.current=null,Qe();try{if(s){var f=function(){throw Error()};if(Object.defineProperty(f.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(f,[])}catch(L){u=L}Reflect.construct(t,[],f)}else{try{f.call()}catch(L){u=L}t.call(f.prototype)}}else{try{throw Error()}catch(L){u=L}t()}}catch(L){if(L&&u&&typeof L.stack=="string"){for(var m=L.stack.split(`
`),E=u.stack.split(`
`),C=m.length-1,w=E.length-1;C>=1&&w>=0&&m[C]!==E[w];)w--;for(;C>=1&&w>=0;C--,w--)if(m[C]!==E[w]){if(C!==1||w!==1)do if(C--,w--,w<0||m[C]!==E[w]){var N=`
`+m[C].replace(" at new "," at ");return t.displayName&&N.includes("<anonymous>")&&(N=N.replace("<anonymous>",t.displayName)),typeof t=="function"&&J.set(t,N),N}while(C>=1&&w>=0);break}}}finally{Pe=!1,I.current=b,qe(),Error.prepareStackTrace=p}var K=t?t.displayName||t.name:"",O=K?De(K):"";return typeof t=="function"&&J.set(t,O),O}function Be(t,s,o){return xt(t,!1)}function P(t){var s=t.prototype;return!!(s&&s.isReactComponent)}function ae(t,s,o){if(t==null)return"";if(typeof t=="function")return xt(t,P(t));if(typeof t=="string")return De(t);switch(t){case z:return De("Suspense");case R:return De("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case y:return Be(t.render);case D:return ae(t.type,s,o);case X:{var u=t,p=u._payload,b=u._init;try{return ae(b(p),s,o)}catch{}}}return""}var F=Object.prototype.hasOwnProperty,Ie={},ye=ie.ReactDebugCurrentFrame;function ne(t){if(t){var s=t._owner,o=ae(t.type,t._source,s?s.type:null);ye.setExtraStackFrame(o)}else ye.setExtraStackFrame(null)}function le(t,s,o,u,p){{var b=Function.call.bind(F);for(var f in t)if(b(t,f)){var m=void 0;try{if(typeof t[f]!="function"){var E=Error((u||"React class")+": "+o+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw E.name="Invariant Violation",E}m=t[f](s,f,u,o,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(C){m=C}m&&!(m instanceof Error)&&(ne(p),j("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",u||"React class",o,f,typeof m),ne(null)),m instanceof Error&&!(m.message in Ie)&&(Ie[m.message]=!0,ne(p),j("Failed %s type: %s",o,m.message),ne(null))}}}var He=Array.isArray;function et(t){return He(t)}function de(t){{var s=typeof Symbol=="function"&&Symbol.toStringTag,o=s&&t[Symbol.toStringTag]||t.constructor.name||"Object";return o}}function mt(t){try{return se(t),!1}catch{return!0}}function se(t){return""+t}function tt(t){if(mt(t))return j("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",de(t)),se(t)}var ue=ie.ReactCurrentOwner,zt={key:!0,ref:!0,__self:!0,__source:!0},rt,wt,Oe;Oe={};function Ct(t){if(F.call(t,"ref")){var s=Object.getOwnPropertyDescriptor(t,"ref").get;if(s&&s.isReactWarning)return!1}return t.ref!==void 0}function Me(t){if(F.call(t,"key")){var s=Object.getOwnPropertyDescriptor(t,"key").get;if(s&&s.isReactWarning)return!1}return t.key!==void 0}function at(t,s){if(typeof t.ref=="string"&&ue.current&&s&&ue.current.stateNode!==s){var o=B(ue.current.type);Oe[o]||(j('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',B(ue.current.type),t.ref),Oe[o]=!0)}}function St(t,s){{var o=function(){rt||(rt=!0,j("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",s))};o.isReactWarning=!0,Object.defineProperty(t,"key",{get:o,configurable:!0})}}function U(t,s){{var o=function(){wt||(wt=!0,j("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",s))};o.isReactWarning=!0,Object.defineProperty(t,"ref",{get:o,configurable:!0})}}var kt=function(t,s,o,u,p,b,f){var m={$$typeof:k,type:t,key:s,ref:o,props:f,_owner:b};return m._store={},Object.defineProperty(m._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(m,"_self",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.defineProperty(m,"_source",{configurable:!1,enumerable:!1,writable:!1,value:p}),Object.freeze&&(Object.freeze(m.props),Object.freeze(m)),m};function fe(t,s,o,u,p){{var b,f={},m=null,E=null;o!==void 0&&(tt(o),m=""+o),Me(s)&&(tt(s.key),m=""+s.key),Ct(s)&&(E=s.ref,at(s,p));for(b in s)F.call(s,b)&&!zt.hasOwnProperty(b)&&(f[b]=s[b]);if(t&&t.defaultProps){var C=t.defaultProps;for(b in C)f[b]===void 0&&(f[b]=C[b])}if(m||E){var w=typeof t=="function"?t.displayName||t.name||"Unknown":t;m&&St(f,w),E&&U(f,w)}return kt(t,m,E,p,u,ue.current,f)}}var nt=ie.ReactCurrentOwner,lt=ie.ReactDebugCurrentFrame;function me(t){if(t){var s=t._owner,o=ae(t.type,t._source,s?s.type:null);lt.setExtraStackFrame(o)}else lt.setExtraStackFrame(null)}var S;S=!1;function xe(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}function pe(){{if(nt.current){var t=B(nt.current.type);if(t)return`
Check the render method of \``+t+"`."}return""}}function st(t){{if(t!==void 0){var s=t.fileName.replace(/^.*[\\\/]/,""),o=t.lineNumber;return`
Check your code at `+s+":"+o+"."}return""}}var we={};function We(t){{var s=pe();if(!s){var o=typeof t=="string"?t:t.displayName||t.name;o&&(s=`
Check the top-level render call using <`+o+">.")}return s}}function Ce(t,s){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var o=We(s);if(we[o])return;we[o]=!0;var u="";t&&t._owner&&t._owner!==nt.current&&(u=" It was passed a child from "+B(t._owner.type)+"."),me(t),j('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',o,u),me(null)}}function Se(t,s){{if(typeof t!="object")return;if(et(t))for(var o=0;o<t.length;o++){var u=t[o];xe(u)&&Ce(u,s)}else if(xe(t))t._store&&(t._store.validated=!0);else if(t){var p=vt(t);if(typeof p=="function"&&p!==t.entries)for(var b=p.call(t),f;!(f=b.next()).done;)xe(f.value)&&Ce(f.value,s)}}}function ot(t){{var s=t.type;if(s==null||typeof s=="string")return;var o;if(typeof s=="function")o=s.propTypes;else if(typeof s=="object"&&(s.$$typeof===y||s.$$typeof===D))o=s.propTypes;else return;if(o){var u=B(s);le(o,t.props,"prop",u,t)}else if(s.PropTypes!==void 0&&!S){S=!0;var p=B(s);j("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",p||"Unknown")}typeof s.getDefaultProps=="function"&&!s.getDefaultProps.isReactClassApproved&&j("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function v(t){{for(var s=Object.keys(t.props),o=0;o<s.length;o++){var u=s[o];if(u!=="children"&&u!=="key"){me(t),j("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",u),me(null);break}}t.ref!==null&&(me(t),j("Invalid attribute `ref` supplied to `React.Fragment`."),me(null))}}var H={};function pt(t,s,o,u,p,b){{var f=yt(t);if(!f){var m="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var E=st(p);E?m+=E:m+=pe();var C;t===null?C="null":et(t)?C="array":t!==void 0&&t.$$typeof===k?(C="<"+(B(t.type)||"Unknown")+" />",m=" Did you accidentally export a JSX literal instead of a component?"):C=typeof t,j("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,m)}var w=fe(t,s,o,p,b);if(w==null)return w;if(f){var N=s.children;if(N!==void 0)if(u)if(et(N)){for(var K=0;K<N.length;K++)Se(N[K],t);Object.freeze&&Object.freeze(N)}else j("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Se(N,t)}if(F.call(s,"key")){var O=B(t),L=Object.keys(s).filter(function(Lt){return Lt!=="key"}),Y=L.length>0?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}";if(!H[O+Y]){var Nt=L.length>0?"{"+L.join(": ..., ")+": ...}":"{}";j(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,Y,O,Nt,O),H[O+Y]=!0}}return t===A?v(w):ot(w),w}}function jt(t,s,o){return pt(t,s,o,!0)}function Et(t,s,o){return pt(t,s,o,!1)}var Tt=Et,Rt=jt;Ue.Fragment=A,Ue.jsx=Tt,Ue.jsxs=Rt}()),Ue}process.env.NODE_ENV==="production"?ge.exports=Ht():ge.exports=Ot();var a=ge.exports;const bt=async(M,k={})=>{var $;if(!M)throw new Error("No file provided for upload.");try{const{uploadApiUrl:A="~/upload",clientId:_="00",clientSecret:ee="00"}=k;if(!A)throw new Error("Upload API URL is required in configuration");const W=new FormData;W.append("image",M),_&&W.append("client_id",_),ee&&W.append("client_secret",ee);const T=await fetch(A,{method:"POST",body:W,headers:{accept:"application/json"}});if(!T.ok)throw new Error(`Upload failed: ${T.status} ${T.statusText}`);const z=($=(await T.json()).data)==null?void 0:$.authenticatedUrl;if(!z)throw new Error("No authenticatedUrl received from server");return z}catch(A){throw console.error("Upload failed:",A),A}};return({value:M="",onChange:k,toolbarOptions:$=["bold","italic","underline","strikethrough","highlight","fontColor","headings","fontFamily","lineSpacing","alignLeft","alignCenter","alignRight","alignJustify","unorderedList","orderedList","todoList","increaseIndent","decreaseIndent","link","insertImage","blockquote","codeBlock","pageBreak","caseChange","insertTable"],placeholder:A="Start typing...",readOnly:_=!1,height:ee="h-64",width:W="w-full",toolbarPosition:T="top",stickyToolbar:y=!1,stickyOffset:z=0,debounceTime:R=300,customClasses:D={},uploadConfig:X={}})=>{const g=c.useRef(null),Re=c.useRef(null),Ye=c.useRef(null),[vt,ie]=c.useState({}),[j,Ve]=c.useState(!1),[Ne,Xe]=c.useState(""),[Je,Le]=c.useState(""),[ct,ce]=c.useState(null),[yt,Ke]=c.useState(!1),[_e,B]=c.useState("#000000"),[te,re]=c.useState(!1),[Ge,Ze]=c.useState("#ffff00"),[dt,Ae]=c.useState(!1),[be,ut]=c.useState(3),[ve,ft]=c.useState(3),[Qe,qe]=c.useState({}),[I,$e]=c.useState(!1),[De,Pe]=c.useState(0),[J,ze]=c.useState(!1),[xt,Be]=c.useState(null),[P,ae]=c.useState(null),[F,Ie]=c.useState(null),[ye,ne]=c.useState({x:0,y:0}),[le,He]=c.useState(null),[et,de]=c.useState(!1),mt=c.useRef(null),se=c.useRef(!1),[tt,ue]=c.useState(null),[zt,rt]=c.useState(!1),[wt,Oe]=c.useState(null),[Ct,Me]=c.useState(!1),[at,St]=c.useState(null),[U,kt]=c.useState(null),[fe,nt]=c.useState([]),[lt,me]=c.useState({x:0,y:0}),[S,xe]=c.useState({tableBackground:"#ffffff",tableBorderColor:"#cccccc",tableBorderWidth:"1",tableBorderStyle:"solid",tableAlignment:"left",cellPadding:"8",cellSpacing:"0",cellBackground:"#ffffff",cellTextAlign:"left",cellVerticalAlign:"middle",cellBorderColor:"#cccccc",cellBorderWidth:"1",cellBorderStyle:"solid"}),pe=c.useRef(null),st=c.useCallback(e=>{pe.current&&clearTimeout(pe.current),pe.current=setTimeout(()=>{k==null||k(e)},R)},[k,R]),we={wrapper:`editor-wrapper ${W}`,toolbar:"editor-toolbar",contentArea:`editor-content ${ee}`,button:"toolbar-btn"},We={wrapper:`${we.wrapper} ${D.wrapper||""}`,toolbar:`${we.toolbar} ${D.toolbar||""} ${y?"editor-toolbar-sticky":""}`,contentArea:`${we.contentArea} ${D.contentArea||""}`,button:`${we.button} ${D.button||""}`};c.useEffect(()=>{if(!y||!Re.current||!Ye.current)return;const e=Re.current,n=Ye.current;Pe(e.offsetHeight);const r=()=>{const i=n.getBoundingClientRect().top<=z;i!==I&&$e(i)},l=()=>{Pe(e.offsetHeight)};return window.addEventListener("scroll",r),window.addEventListener("resize",l),r(),()=>{window.removeEventListener("scroll",r),window.removeEventListener("resize",l)}},[y,z,I]);const Ce=()=>{const e=window.getSelection();e.rangeCount>0&&ce(e.getRangeAt(0).cloneRange())},Se=()=>{if(ct){const e=window.getSelection();e.removeAllRanges(),e.addRange(ct)}},ot=()=>{const e={};$.forEach(n=>{switch(n){case"bold":e.bold=document.queryCommandState("bold");break;case"italic":e.italic=document.queryCommandState("italic");break;case"underline":e.underline=document.queryCommandState("underline");break;case"strikethrough":e.strikethrough=document.queryCommandState("strikeThrough");break;case"unorderedList":e.unorderedList=document.queryCommandState("insertUnorderedList");break;case"orderedList":e.orderedList=document.queryCommandState("insertOrderedList");break}}),ie(e)},v=(e,n=null)=>{var r;_||((r=g.current)==null||r.focus(),document.execCommand(e,!1,n),ot(),Y())},H=(e,n=null)=>{if(!_)switch(e){case"bold":v("bold");break;case"italic":v("italic");break;case"underline":v("underline");break;case"strikethrough":v("strikeThrough");break;case"highlight":n?v("hiliteColor",n):(re(!0),Ce());break;case"fontColor":n?v("foreColor",n):(Ke(!0),Ce());break;case"alignLeft":v("justifyLeft");break;case"alignCenter":v("justifyCenter");break;case"alignRight":v("justifyRight");break;case"alignJustify":v("justifyFull");break;case"unorderedList":v("insertUnorderedList");break;case"orderedList":v("insertOrderedList");break;case"todoList":Et();break;case"increaseIndent":v("indent");break;case"decreaseIndent":v("outdent");break;case"blockquote":v("formatBlock","<blockquote>");break;case"codeBlock":v("formatBlock","<pre>");break;case"pageBreak":Tt();break;case"caseChange":Rt();break;case"insertTable":Ae(!0),Ce();break;case"lineSpacing":break;case"link":pt();break;case"insertImage":er();break}},pt=()=>{const e=window.getSelection();e.toString()?(Le(e.toString()),Ce(),Ve(!0)):alert("Please select text to create a link")},jt=()=>{Ne&&Je&&(Se(),v("createLink",Ne)),Ve(!1),Xe(""),Le(""),ce(null)},Et=()=>{v("insertHTML",`
<ul style="list-style: none; padding-left: 0;">
<li style="margin: 8px 0;">
<input type="checkbox" style="margin-right: 8px;" /> Todo item 1
</li>
<li style="margin: 8px 0;">
<input type="checkbox" style="margin-right: 8px;" /> Todo item 2
</li>
</ul>
`)},Tt=()=>{v("insertHTML",'<div style="page-break-after: always; border-bottom: 2px dashed #ccc; margin: 20px 0; padding-bottom: 20px;"><br></div>')},Rt=()=>{const e=window.getSelection();if(e.toString()){const n=e.toString();let r;n===n.toUpperCase()?r=n.toLowerCase():n===n.toLowerCase()?r=n.replace(/\w\S*/g,l=>l.charAt(0).toUpperCase()+l.substr(1).toLowerCase()):r=n.toUpperCase(),v("insertText",r)}},t=e=>{e==="p"?v("formatBlock","<p>"):v("formatBlock",`<${e}>`)},s=e=>{v("fontName",e)},o=e=>{const n=window.getSelection(),r=n.rangeCount>0?n.getRangeAt(0):null;if(r&&!r.collapsed){const l=document.createElement("span");l.style.lineHeight=e.lineHeight,l.style.marginBottom=e.paragraphSpacing,l.style.display="block";try{r.surroundContents(l)}catch{const i=r.extractContents();l.appendChild(i),r.insertNode(l)}}else{const l=g.current;l&&(l.style.lineHeight=e.lineHeight,l.querySelectorAll("p, div, h1, h2, h3, h4, h5, h6").forEach(i=>{i.style.marginBottom=e.paragraphSpacing}))}Y()},u=e=>{Se(),v("foreColor",e),Ke(!1),B(e),ce(null)},p=e=>{Se(),v("hiliteColor",e),re(!1),Ze(e),ce(null)},b=()=>{let n=`<table id="${`table_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}" class="resizable-table" style="border-collapse: collapse; width: 100%; margin: 10px 0; position: relative;"><tbody>`;for(let r=0;r<be;r++){n+="<tr>";for(let l=0;l<ve;l++)n+='<td style="border: 1px solid #ccc; padding: 8px; min-width: 100px; min-height: 30px; position: relative;"> </td>';n+="</tr>"}n+="</tbody></table>",Se(),v("insertHTML",n),Ae(!1),ce(null),setTimeout(()=>{f()},100)},f=()=>{if(!g.current)return;g.current.querySelectorAll("table").forEach(r=>{r.classList.contains("resizable-table")||(r.classList.add("resizable-table"),r.style.position||(r.style.position="relative"))}),g.current.querySelectorAll("table.resizable-table").forEach(r=>{r.querySelectorAll(".resize-handle").forEach(x=>x.remove());const l=document.createElement("div");l.className="resize-handle table-resize-handle",l.title="Drag to resize table",l.addEventListener("mousedown",x=>m(x,r)),r.appendChild(l);const d=r.querySelector("tr");if(d){const x=d.querySelectorAll("td, th");x.forEach((G,V)=>{if(V<x.length-1){const h=document.createElement("div");h.className="resize-handle column-resize-handle",h.title="Drag to resize column",h.addEventListener("mousedown",Z=>E(Z,r,V)),G.appendChild(h)}})}const i=r.querySelectorAll("tr");i.forEach((x,G)=>{if(G<i.length-1){const V=x.querySelector("td, th");if(V){const h=document.createElement("div");h.className="resize-handle row-resize-handle",h.title="Drag to resize row",h.addEventListener("mousedown",Z=>C(Z,r,G)),V.appendChild(h)}}})})},m=(e,n)=>{e.preventDefault(),e.stopPropagation();const r=n.getBoundingClientRect();ze(!0),Be("table"),ae(n),ne({x:e.clientX,y:e.clientY}),He({width:r.width,height:r.height}),n.classList.add("resizing"),document.body.classList.add("resizing"),document.addEventListener("mousemove",w),document.addEventListener("mouseup",O),document.body.style.cursor="nw-resize"},E=(e,n,r)=>{e.preventDefault(),e.stopPropagation();const l=Array.from(n.querySelectorAll("tr")).map(d=>d.querySelectorAll("td, th")[r]).filter(Boolean);ze(!0),Be("column"),ae(n),Ie({columnIndex:r,cells:l}),ne({x:e.clientX,y:e.clientY}),He({width:l[0]?l[0].getBoundingClientRect().width:100}),n.classList.add("resizing"),document.body.classList.add("resizing"),document.addEventListener("mousemove",N),document.addEventListener("mouseup",O),document.body.style.cursor="col-resize"},C=(e,n,r)=>{e.preventDefault(),e.stopPropagation();const l=n.querySelectorAll("tr")[r];l&&(ze(!0),Be("row"),ae(n),Ie({rowIndex:r,row:l}),ne({x:e.clientX,y:e.clientY}),He({height:l.getBoundingClientRect().height}),n.classList.add("resizing"),document.body.classList.add("resizing"),document.addEventListener("mousemove",K),document.addEventListener("mouseup",O),document.body.style.cursor="row-resize")},w=e=>{if(!J||!P||!le)return;const n=e.clientX-ye.x,r=e.clientY-ye.y,l=Math.max(200,le.width+n),d=Math.max(100,le.height+r);P.style.width=`${l}px`,P.style.height=`${d}px`,P.style.transform="scale(1.02)",P.style.transition="none"},N=e=>{if(!J||!F||!le)return;const n=e.clientX-ye.x,r=Math.max(50,le.width+n);F.cells.forEach(l=>{l&&(l.style.width=`${r}px`,l.style.minWidth=`${r}px`,l.style.maxWidth=`${r}px`)})},K=e=>{if(!J||!F||!le)return;const n=e.clientY-ye.y,r=Math.max(30,le.height+n);F.row&&(F.row.style.height=`${r}px`,F.row.querySelectorAll("td, th").forEach(d=>{d.style.height=`${r}px`,d.style.minHeight=`${r}px`}))},O=()=>{P&&(P.classList.remove("resizing"),P.classList.add("resize-complete"),P.style.transform="",P.style.transition="",setTimeout(()=>{P&&P.classList.remove("resize-complete")},600)),document.body.classList.remove("resizing"),ze(!1),Be(null),ae(null),Ie(null),ne({x:0,y:0}),He(null),document.removeEventListener("mousemove",w),document.removeEventListener("mousemove",N),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",O),document.body.style.cursor="default",Y()};c.useEffect(()=>()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mousemove",N),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",O)},[]),c.useEffect(()=>{g.current&&setTimeout(()=>{f()},100)},[M]);const L=e=>{const n=document.createElement("div");return n.innerHTML=e,n.querySelectorAll(".image-resize-wrapper").forEach(i=>{const x=i.querySelector("img");x&&(x.removeAttribute("data-resize-enabled"),x.removeAttribute("data-original-cursor"),x.style.cursor==="pointer"&&x.style.removeProperty("cursor"),i.parentNode.insertBefore(x,i)),i.remove()}),n.querySelectorAll("img").forEach(i=>{i.removeAttribute("data-resize-enabled"),i.removeAttribute("data-original-cursor"),i.style.cursor==="pointer"&&i.style.removeProperty("cursor")}),n.querySelectorAll(".resize-handle").forEach(i=>i.remove()),n.innerHTML},Y=()=>{if(g.current){const e=g.current.innerHTML;if(se.current){st(e);return}if(e.includes("image-resize-wrapper")||e.includes("resize-handle")){const r=L(e);st(r)}else st(e)}},Nt=()=>{se.current=!0,Y(),ot(),setTimeout(()=>{f()},50),setTimeout(()=>{se.current=!1},100)},Lt=e=>{if(_){e.preventDefault();return}if(e.key==="Tab"){e.preventDefault(),e.shiftKey?H("decreaseIndent"):H("increaseIndent");return}if(e.ctrlKey||e.metaKey)switch(e.key){case"b":e.preventDefault(),H("bold");break;case"i":e.preventDefault(),H("italic");break;case"u":e.preventDefault(),H("underline");break;case"l":e.preventDefault(),H("alignLeft");break;case"e":e.preventDefault(),H("alignCenter");break;case"r":e.preventDefault(),H("alignRight");break;case"j":e.preventDefault(),H("alignJustify");break;case"1":e.preventDefault(),o(ht[0]);break;case"2":e.preventDefault(),o(ht[3]);break;case"5":e.preventDefault(),o(ht[2]);break}};c.useEffect(()=>{if(g.current&&M!==g.current.innerHTML){const e=se.current;se.current=!1,g.current.innerHTML=M,se.current=e}},[M]),c.useEffect(()=>{const e=()=>{document.activeElement===g.current&&ot()};return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[]),c.useEffect(()=>()=>{pe.current&&clearTimeout(pe.current)},[]),c.useEffect(()=>{const e=n=>{if(!Object.values(Qe).some(i=>i))return;const l=document.querySelectorAll(".dropdown-container");let d=!0;l.forEach(i=>{i.contains(n.target)&&(d=!1)}),d&&qe({})};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[Qe]),c.useEffect(()=>{const e=r=>{J||Qt(r)},n=r=>{const l=document.querySelector(".table-style-menu"),d=l&&l.contains(r.target),i=r.target.closest("table.resizable-table");!d&&!i&&Me(!1)};return g.current&&g.current.addEventListener("click",e),document.addEventListener("click",n),()=>{g.current&&g.current.removeEventListener("click",e),document.removeEventListener("click",n)}},[J]);const Mt={bold:{label:"B",title:"Bold (Ctrl+B)",className:"font-bold"},italic:{label:"I",title:"Italic (Ctrl+I)",className:"italic"},underline:{label:"U",title:"Underline (Ctrl+U)",className:"underline"},strikethrough:{label:"S",title:"Strikethrough",className:"line-through"},highlight:{label:"🖍️",title:"Highlight Text",className:""},fontColor:{label:"🎨",title:"Font Color",className:""},headings:{label:"H",title:"Headings",className:"font-bold",isDropdown:!0},fontFamily:{label:"Font",title:"Font Family",className:"",isDropdown:!0},lineSpacing:{label:"⫽",title:"Line & Paragraph Spacing (Ctrl+1/2/5)",className:"",isDropdown:!0},alignLeft:{label:"⬅️",title:"Align Left",className:""},alignCenter:{label:"⬆️",title:"Align Center",className:""},alignRight:{label:"➡️",title:"Align Right",className:""},alignJustify:{label:"↔️",title:"Justify",className:""},unorderedList:{label:"•",title:"Bullet List",className:""},orderedList:{label:"1.",title:"Numbered List",className:""},todoList:{label:"☑️",title:"Todo List",className:""},increaseIndent:{label:"→",title:"Increase Indent",className:""},decreaseIndent:{label:"←",title:"Decrease Indent",className:""},link:{label:"🔗",title:"Insert Link",className:""},insertImage:{label:"🖼️",title:"Insert Image",className:""},blockquote:{label:"❝",title:"Quote",className:""},codeBlock:{label:"<>",title:"Code Block",className:"font-mono"},pageBreak:{label:"📄",title:"Page Break",className:""},caseChange:{label:"Aa",title:"Change Case",className:""},insertTable:{label:"⊞",title:"Insert Table",className:""}},Wt=[{value:"p",label:"Normal"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],Ft=[{value:"Arial",label:"Arial"},{value:"Georgia",label:"Georgia"},{value:"Times New Roman",label:"Times New Roman"},{value:"Courier New",label:"Courier New"},{value:"Verdana",label:"Verdana"},{value:"Helvetica",label:"Helvetica"}],ht=[{value:"1.0",label:"Single (1.0)",lineHeight:"1.0",paragraphSpacing:"0"},{value:"1.15",label:"1.15",lineHeight:"1.15",paragraphSpacing:"0.2em"},{value:"1.5",label:"1.5",lineHeight:"1.5",paragraphSpacing:"0.5em"},{value:"2.0",label:"Double (2.0)",lineHeight:"2.0",paragraphSpacing:"1em"},{value:"2.5",label:"2.5",lineHeight:"2.5",paragraphSpacing:"1.2em"},{value:"3.0",label:"Triple (3.0)",lineHeight:"3.0",paragraphSpacing:"1.5em"}],Ut=["#000000","#333333","#666666","#999999","#cccccc","#ffffff","#ff0000","#ff9900","#ffff00","#00ff00","#0099ff","#6600ff","#ff00ff","#ff3366","#33ff99","#3366ff","#9933ff","#ff6633"],Yt=["#ffff00","#ffcc00","#ff9900","#ff6600","#ff3300","#ff0066","#ff00cc","#cc00ff","#6600ff","#0066ff","#00ccff","#00ffcc","#00ff66","#66ff00","#ccff00","#ffff66","#ffcccc","#ccffcc"],Vt=e=>{const n=Mt[e];if(!n)return null;if(n.isDropdown)return Xt(e,n);const r=vt[e],l=`${We.button} ${n.className} ${r?"toolbar-btn-active":""}`;return a.jsx("button",{type:"button",className:l,title:n.title,onClick:()=>H(e),disabled:_,children:n.label},e)},Xt=(e,n)=>{const r=Qe[e]||!1,l=()=>{qe(i=>({...i,[e]:!r}))},d=()=>{qe(i=>({...i,[e]:!1}))};return a.jsxs("div",{className:"dropdown-container",children:[a.jsxs("button",{type:"button",className:`dropdown-trigger ${r?"active":""}`,title:n.title,onClick:l,disabled:_,children:[a.jsx("span",{children:n.label}),a.jsx("span",{className:"dropdown-arrow",children:"▼"})]}),r&&a.jsxs("div",{className:"dropdown-menu",children:[e==="headings"&&Wt.map(i=>a.jsx("button",{type:"button",className:"dropdown-item",onClick:()=>{t(i.value),d()},style:{fontFamily:(i.value==="h1","inherit"),fontSize:i.value==="h1"?"1.1rem":i.value==="h2"?"1.05rem":i.value==="h3"?"1rem":"0.875rem",fontWeight:i.value.startsWith("h")?"600":"400"},children:i.label},i.value)),e==="fontFamily"&&Ft.map(i=>a.jsx("button",{type:"button",className:"dropdown-item font-preview",style:{"--font-family":i.value,fontFamily:i.value},onClick:()=>{s(i.value),d()},children:i.label},i.value)),e==="lineSpacing"&&ht.map(i=>a.jsx("button",{type:"button",className:"dropdown-item",onClick:()=>{o(i),d()},children:a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[a.jsx("span",{children:i.label}),a.jsx("span",{style:{fontSize:"0.75rem",opacity:.6},children:i.lineHeight})]})},i.value))]})]},e)},Bt=()=>a.jsx("div",{ref:Re,className:We.toolbar,style:{position:y&&I?"fixed":"relative",top:y&&I?`${z}px`:"auto",left:y&&I?"0":"auto",right:y&&I?"0":"auto",zIndex:y&&I?"1000":"auto",width:y&&I?"100%":"auto",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)"},children:$.map(e=>Vt(e))}),Jt=()=>j?a.jsx("div",{className:"modal-backdrop",children:a.jsxs("div",{className:"compact-modal",children:[a.jsx("h3",{children:"🔗 Insert Link"}),a.jsxs("div",{className:"compact-form",children:[a.jsx("input",{type:"text",value:Je,onChange:e=>Le(e.target.value),className:"compact-input",placeholder:"Link text",autoFocus:!0}),a.jsx("input",{type:"url",value:Ne,onChange:e=>Xe(e.target.value),className:"compact-input",placeholder:"https://example.com"})]}),a.jsxs("div",{className:"compact-actions",children:[a.jsx("button",{type:"button",onClick:()=>{Ve(!1),Xe(""),Le("")},className:"btn-compact-secondary",children:"Cancel"}),a.jsx("button",{type:"button",onClick:jt,className:"btn-compact-primary",disabled:!Ne||!Je,children:"Insert"})]})]})}):null,Kt=()=>yt?a.jsx("div",{className:"modal-backdrop",children:a.jsxs("div",{className:"compact-modal color-modal",children:[a.jsx("h3",{children:"🎨 Text Color"}),a.jsxs("div",{className:"compact-color-section",children:[a.jsx("div",{className:"compact-color-grid",children:Ut.slice(0,12).map(e=>a.jsx("button",{type:"button",className:`compact-color-btn ${_e===e?"selected":""}`,style:{backgroundColor:e},onClick:()=>u(e),title:e},e))}),a.jsxs("div",{className:"compact-custom-color",children:[a.jsx("input",{type:"color",value:_e,onChange:e=>B(e.target.value),className:"compact-color-input"}),a.jsx("button",{type:"button",onClick:()=>u(_e),className:"btn-compact-accent",children:"Custom"})]})]}),a.jsx("div",{className:"compact-actions",children:a.jsx("button",{type:"button",onClick:()=>Ke(!1),className:"btn-compact-secondary",children:"Cancel"})})]})}):null,Gt=()=>te?a.jsx("div",{className:"modal-backdrop",children:a.jsxs("div",{className:"compact-modal color-modal",children:[a.jsx("h3",{children:"🖍️ Highlight"}),a.jsxs("div",{className:"compact-color-section",children:[a.jsx("div",{className:"compact-color-grid",children:Yt.slice(0,12).map(e=>a.jsx("button",{type:"button",className:`compact-color-btn ${Ge===e?"selected":""}`,style:{backgroundColor:e},onClick:()=>p(e),title:e},e))}),a.jsxs("div",{className:"compact-custom-color",children:[a.jsx("input",{type:"color",value:Ge,onChange:e=>Ze(e.target.value),className:"compact-color-input"}),a.jsx("button",{type:"button",onClick:()=>p("transparent"),className:"btn-compact-danger",children:"Remove"})]})]}),a.jsxs("div",{className:"compact-actions",children:[a.jsx("button",{type:"button",onClick:()=>p("transparent"),className:"btn-compact-danger",children:"Remove"}),a.jsx("button",{type:"button",onClick:()=>re(!1),className:"btn-compact-secondary",children:"Cancel"})]})]})}):null,Zt=()=>dt?a.jsx("div",{className:"modal-backdrop",children:a.jsxs("div",{className:"compact-modal table-modal",children:[a.jsx("h3",{children:"⊞ Insert Table"}),a.jsxs("div",{className:"compact-table-controls",children:[a.jsxs("div",{className:"table-dimension-control",children:[a.jsx("label",{children:"Rows"}),a.jsx("input",{type:"number",min:"1",max:"10",value:be,onChange:e=>ut(parseInt(e.target.value)||1),className:"compact-number-input"})]}),a.jsxs("div",{className:"table-dimension-control",children:[a.jsx("label",{children:"Columns"}),a.jsx("input",{type:"number",min:"1",max:"10",value:ve,onChange:e=>ft(parseInt(e.target.value)||1),className:"compact-number-input"})]})]}),a.jsxs("div",{className:"table-preview",children:[be," × ",ve," table"]}),a.jsxs("div",{className:"compact-actions",children:[a.jsx("button",{type:"button",onClick:()=>Ae(!1),className:"btn-compact-secondary",children:"Cancel"}),a.jsx("button",{type:"button",onClick:b,className:"btn-compact-primary",disabled:be<1||ve<1,children:"Insert"})]})]})}):null,Qt=e=>{const n=e.target,r=n.closest("table"),l=n.closest("td, th");if(r&&r.classList.contains("resizable-table")){let d="table",i=r,x=[];if(l){d="cell",i=l,x=[l];const it=window.getSelection();if(it.rangeCount>0){const Te=it.getRangeAt(0),Q=[];if(Te.startContainer!==Te.endContainer){const oe=Te.commonAncestorContainer;oe.nodeType===Node.ELEMENT_NODE&&(oe.querySelectorAll("td, th").forEach(q=>{Te.intersectsNode(q)&&Q.push(q)}),Q.length>1&&(x=Q))}}}St(i),kt(d),nt(x);const G=qt(i,d);xe(G);const V=i.getBoundingClientRect(),h={x:V.right+10,y:V.top},Z={width:window.innerWidth,height:window.innerHeight};h.x+320>Z.width&&(h.x=V.left-330),h.y+400>Z.height&&(h.y=Math.max(10,Z.height-410)),me(h),Me(!0)}else Me(!1)},qt=(e,n)=>{const r={...S};if(n==="table"){const l=window.getComputedStyle(e);r.tableBackground=gt(l.backgroundColor)||"#ffffff",r.tableBorderColor=gt(l.borderColor)||"#cccccc",r.tableBorderWidth=l.borderWidth.replace("px","")||"1",r.tableBorderStyle=l.borderStyle||"solid",r.tableAlignment=l.marginLeft==="auto"&&l.marginRight==="auto"?"center":l.marginRight==="auto"?"left":"right"}else if(n==="cell"){const l=window.getComputedStyle(e);r.cellBackground=gt(l.backgroundColor)||"#ffffff",r.cellTextAlign=l.textAlign||"left",r.cellVerticalAlign=l.verticalAlign||"middle",r.cellBorderColor=gt(l.borderColor)||"#cccccc",r.cellBorderWidth=l.borderWidth.replace("px","")||"1",r.cellBorderStyle=l.borderStyle||"solid",r.cellPadding=l.padding.replace("px","")||"8"}return r},gt=e=>{if(!e||e==="rgba(0, 0, 0, 0)"||e==="transparent")return"#ffffff";const n=e.match(/\d+/g);if(!n)return"#ffffff";const r=parseInt(n[0]),l=parseInt(n[1]),d=parseInt(n[2]);return"#"+((1<<24)+(r<<16)+(l<<8)+d).toString(16).slice(1)},ke=(e,n)=>{if(!at||U!=="table")return;const r=at;switch(e){case"tableBackground":r.style.backgroundColor=n;break;case"tableBorderColor":r.style.borderColor=n;break;case"tableBorderWidth":r.style.borderWidth=`${n}px`;break;case"tableBorderStyle":r.style.borderStyle=n;break;case"tableAlignment":n==="center"?(r.style.marginLeft="auto",r.style.marginRight="auto"):n==="right"?(r.style.marginLeft="auto",r.style.marginRight="0"):(r.style.marginLeft="0",r.style.marginRight="auto");break;case"cellPadding":r.querySelectorAll("td, th").forEach(d=>{d.style.padding=`${n}px`});break;case"cellSpacing":r.style.borderSpacing=`${n}px`;break}xe(l=>({...l,[e]:n})),Y()},je=(e,n)=>{fe.length!==0&&(fe.forEach(r=>{switch(e){case"cellBackground":r.style.backgroundColor=n;break;case"cellTextAlign":r.style.textAlign=n;break;case"cellVerticalAlign":r.style.verticalAlign=n;break;case"cellBorderColor":r.style.borderColor=n;break;case"cellBorderWidth":r.style.borderWidth=`${n}px`;break;case"cellBorderStyle":r.style.borderStyle=n;break;case"cellPadding":r.style.padding=`${n}px`;break}}),xe(r=>({...r,[e]:n})),Y())},$t=()=>{if(!Ct||!at)return null;const e=U==="table",n=U==="cell"||U==="row"||U==="column";return a.jsx("div",{className:"table-style-menu",style:{position:"fixed",left:`${lt.x}px`,top:`${lt.y}px`,zIndex:1e3},children:a.jsxs("div",{className:"table-style-panel",children:[a.jsxs("div",{className:"table-style-header",children:[a.jsx("h3",{children:e?"📊 Table Styles":U==="row"?"📏 Row Styles":U==="column"?"📋 Column Styles":"🔲 Cell Styles"}),a.jsx("button",{className:"table-style-close",onClick:()=>Me(!1),title:"Close",children:"✕"})]}),a.jsxs("div",{className:"table-style-content",children:[e&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"style-section",children:[a.jsx("h4",{children:"🎨 Table Appearance"}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Background:"}),a.jsx("input",{type:"color",value:S.tableBackground,onChange:r=>ke("tableBackground",r.target.value),className:"color-input"})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Alignment:"}),a.jsxs("select",{value:S.tableAlignment,onChange:r=>ke("tableAlignment",r.target.value),className:"style-select",children:[a.jsx("option",{value:"left",children:"Left"}),a.jsx("option",{value:"center",children:"Center"}),a.jsx("option",{value:"right",children:"Right"})]})]})]}),a.jsxs("div",{className:"style-section",children:[a.jsx("h4",{children:"🔲 Border & Spacing"}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Color:"}),a.jsx("input",{type:"color",value:S.tableBorderColor,onChange:r=>ke("tableBorderColor",r.target.value),className:"color-input"})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Width:"}),a.jsxs("select",{value:S.tableBorderWidth,onChange:r=>ke("tableBorderWidth",r.target.value),className:"style-select",children:[a.jsx("option",{value:"0",children:"None"}),a.jsx("option",{value:"1",children:"Thin (1px)"}),a.jsx("option",{value:"2",children:"Medium (2px)"}),a.jsx("option",{value:"3",children:"Thick (3px)"}),a.jsx("option",{value:"4",children:"Extra Thick (4px)"})]})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Style:"}),a.jsxs("select",{value:S.tableBorderStyle,onChange:r=>ke("tableBorderStyle",r.target.value),className:"style-select",children:[a.jsx("option",{value:"solid",children:"Solid"}),a.jsx("option",{value:"dashed",children:"Dashed"}),a.jsx("option",{value:"dotted",children:"Dotted"}),a.jsx("option",{value:"double",children:"Double"})]})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Cell Padding:"}),a.jsx("input",{type:"range",min:"0",max:"20",value:S.cellPadding,onChange:r=>ke("cellPadding",r.target.value),className:"style-range"}),a.jsxs("span",{className:"range-value",children:[S.cellPadding,"px"]})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Cell Spacing:"}),a.jsx("input",{type:"range",min:"0",max:"10",value:S.cellSpacing,onChange:r=>ke("cellSpacing",r.target.value),className:"style-range"}),a.jsxs("span",{className:"range-value",children:[S.cellSpacing,"px"]})]})]})]}),n&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"style-section",children:[a.jsx("h4",{children:"🎨 Cell Appearance"}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Background:"}),a.jsx("input",{type:"color",value:S.cellBackground,onChange:r=>je("cellBackground",r.target.value),className:"color-input"})]})]}),a.jsxs("div",{className:"style-section",children:[a.jsx("h4",{children:"📝 Text Alignment"}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Horizontal:"}),a.jsx("div",{className:"alignment-buttons",children:["left","center","right","justify"].map(r=>a.jsx("button",{className:`alignment-btn ${S.cellTextAlign===r?"active":""}`,onClick:()=>je("cellTextAlign",r),title:`Align ${r}`,children:r==="left"?"⬅️":r==="center"?"⬆️":r==="right"?"➡️":"↔️"},r))})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Vertical:"}),a.jsx("div",{className:"alignment-buttons",children:[{value:"top",icon:"⬆️",label:"Top"},{value:"middle",icon:"◾",label:"Middle"},{value:"bottom",icon:"⬇️",label:"Bottom"}].map(r=>a.jsx("button",{className:`alignment-btn ${S.cellVerticalAlign===r.value?"active":""}`,onClick:()=>je("cellVerticalAlign",r.value),title:r.label,children:r.icon},r.value))})]})]}),a.jsxs("div",{className:"style-section",children:[a.jsx("h4",{children:"🔲 Cell Border"}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Color:"}),a.jsx("input",{type:"color",value:S.cellBorderColor,onChange:r=>je("cellBorderColor",r.target.value),className:"color-input"})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Width:"}),a.jsxs("select",{value:S.cellBorderWidth,onChange:r=>je("cellBorderWidth",r.target.value),className:"style-select",children:[a.jsx("option",{value:"0",children:"None"}),a.jsx("option",{value:"1",children:"Thin (1px)"}),a.jsx("option",{value:"2",children:"Medium (2px)"}),a.jsx("option",{value:"3",children:"Thick (3px)"})]})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Border Style:"}),a.jsxs("select",{value:S.cellBorderStyle,onChange:r=>je("cellBorderStyle",r.target.value),className:"style-select",children:[a.jsx("option",{value:"solid",children:"Solid"}),a.jsx("option",{value:"dashed",children:"Dashed"}),a.jsx("option",{value:"dotted",children:"Dotted"}),a.jsx("option",{value:"double",children:"Double"})]})]}),a.jsxs("div",{className:"style-row",children:[a.jsx("label",{children:"Padding:"}),a.jsx("input",{type:"range",min:"0",max:"20",value:S.cellPadding,onChange:r=>je("cellPadding",r.target.value),className:"style-range"}),a.jsxs("span",{className:"range-value",children:[S.cellPadding,"px"]})]})]})]}),a.jsx("div",{className:"style-section",children:a.jsx("div",{className:"selection-info",children:a.jsx("small",{children:U==="table"?"Entire table selected":U==="row"?`Row selected (${fe.length} cells)`:U==="column"?`Column selected (${fe.length} cells)`:`${fe.length} cell${fe.length>1?"s":""} selected`})})})]})]})})},er=()=>{var e;_||(e=mt.current)==null||e.click()},tr=async e=>{var r;const n=e.target.files;if(n&&n.length>0){const l=n[0];if(!l.type.startsWith("image/")){alert("Please select an image file.");return}const d=10*1024*1024;if(l.size>d){alert("Image file is too large. Please select an image smaller than 10MB.");return}try{de(!0);const i=await bt(l,X);(r=g.current)==null||r.focus(),document.execCommand("insertHTML",!1,`<img src="${i}" alt="${l.name}" style="max-width: 100%; height: auto; margin: 5px 0;" />`),setTimeout(()=>{Ee()},100),Y()}catch(i){console.error("Image upload failed:",i),alert("Failed to upload image. Please try again.")}finally{de(!1),e.target.value=""}}},rr=async e=>{const r=(e.clipboardData||window.clipboardData).items;let l=null;for(let d=0;d<r.length;d++)if(r[d].type.indexOf("image")!==-1){l=r[d].getAsFile();break}if(l){e.preventDefault(),de(!0);try{const d=await bt(l,X);document.execCommand("insertHTML",!1,`<img src="${d}" alt="${l.name}" />`),setTimeout(()=>{Ee()},100)}catch(d){console.error("Image upload failed:",d)}finally{de(!1)}}},ar=e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.style.backgroundColor="#f0f8ff",e.currentTarget.style.border="2px dashed #007acc"},nr=e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.style.backgroundColor="",e.currentTarget.style.border=""},lr=async e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.style.backgroundColor="",e.currentTarget.style.border="";const r=Array.from(e.dataTransfer.files).filter(l=>l.type.startsWith("image/"));if(r.length>0){de(!0);try{for(const l of r){const d=await bt(l,X);document.execCommand("insertHTML",!1,`<img src="${d}" alt="${l.name}" style="max-width: 100%; height: auto; margin: 5px 0;" />`)}setTimeout(()=>{Ee()},100)}catch(l){console.error("Image upload failed:",l)}finally{de(!1)}}},Ee=c.useCallback(()=>{if(!g.current)return;g.current.querySelectorAll("img").forEach(n=>{var r;if(!n.dataset.resizeEnabled){if((r=n.parentElement)!=null&&r.classList.contains("image-resize-wrapper")){const l=n.parentElement;l.parentNode.insertBefore(n,l),l.remove()}n.dataset.resizeEnabled="true",n.dataset.originalCursor||(n.dataset.originalCursor=n.style.cursor||""),n.style.cursor="pointer",n.addEventListener("click",l=>{l.preventDefault(),l.stopPropagation(),sr(n)})}})},[]),sr=c.useCallback(e=>{_t();const n=e.style.cursor;e.dataset.originalCursor=n;const r=document.createElement("div");r.className="image-resize-wrapper",r.style.cssText=`
position: relative;
display: inline-block;
border: 2px solid #007acc;
box-sizing: border-box;
margin: 5px;
z-index: 1000000;
isolation: isolate;
`,e.parentNode.insertBefore(r,e),r.appendChild(e),["nw","ne","sw","se","n","s","e","w"].forEach(d=>{const i=document.createElement("div");i.className=`resize-handle resize-${d}`,i.style.cssText=`
position: absolute;
width: 8px;
height: 8px;
background: #007acc;
border: 1px solid white;
cursor: ${It(d)};
z-index: 1000000;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
`,or(i,d),i.addEventListener("mousedown",x=>ir(x,e,d)),r.appendChild(i)}),ue(e)},[]),It=e=>({nw:"nw-resize",ne:"ne-resize",sw:"sw-resize",se:"se-resize",n:"n-resize",s:"s-resize",e:"e-resize",w:"w-resize"})[e],or=(e,n)=>{switch(n){case"nw":e.style.top="-4px",e.style.left="-4px";break;case"ne":e.style.top="-4px",e.style.right="-4px";break;case"sw":e.style.bottom="-4px",e.style.left="-4px";break;case"se":e.style.bottom="-4px",e.style.right="-4px";break;case"n":e.style.top="-4px",e.style.left="50%",e.style.transform="translateX(-50%)";break;case"s":e.style.bottom="-4px",e.style.left="50%",e.style.transform="translateX(-50%)";break;case"e":e.style.right="-4px",e.style.top="50%",e.style.transform="translateY(-50%)";break;case"w":e.style.left="-4px",e.style.top="50%",e.style.transform="translateY(-50%)";break}},ir=c.useCallback((e,n,r)=>{e.preventDefault(),e.stopPropagation();const l=n.getBoundingClientRect(),d=e.clientX,i=e.clientY,x=l.width,G=l.height,V=x/G;rt(!0),Oe({img:n,position:r,startX:d,startY:i,startWidth:x,startHeight:G,aspectRatio:V});const h={img:n,position:r,startX:d,startY:i,startWidth:x,startHeight:G,aspectRatio:V},Z=Te=>{const Q=Te.clientX-h.startX,oe=Te.clientY-h.startY;let he=h.startWidth,q=h.startHeight;switch(h.position){case"se":he=Math.max(50,h.startWidth+Q),q=Math.max(30,h.startHeight+oe);break;case"sw":he=Math.max(50,h.startWidth-Q),q=Math.max(30,h.startHeight+oe);break;case"ne":he=Math.max(50,h.startWidth+Q),q=Math.max(30,h.startHeight-oe);break;case"nw":he=Math.max(50,h.startWidth-Q),q=Math.max(30,h.startHeight-oe);break;case"e":he=Math.max(50,h.startWidth+Q);break;case"w":he=Math.max(50,h.startWidth-Q);break;case"s":q=Math.max(30,h.startHeight+oe);break;case"n":q=Math.max(30,h.startHeight-oe);break}h.img.style.width=`${he}px`,h.img.style.height=`${q}px`},it=()=>{rt(!1),Oe(null),document.removeEventListener("mousemove",Z),document.removeEventListener("mouseup",it),document.body.style.cursor="default",document.bo