react-mail-inbox 1.0.10 → 1.0.13
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/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {createContext,useContext,useState,useEffect,useRef,useCallback,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {AutoFocusPlugin}from'@lexical/react/LexicalAutoFocusPlugin';import {LexicalComposer}from'@lexical/react/LexicalComposer';import {RichTextPlugin}from'@lexical/react/LexicalRichTextPlugin';import {ContentEditable}from'@lexical/react/LexicalContentEditable';import {HistoryPlugin}from'@lexical/react/LexicalHistoryPlugin';import {LexicalErrorBoundary}from'@lexical/react/LexicalErrorBoundary';import {createPortal}from'react-dom';import {MdClose,MdEdit,MdTextFields,MdCheck,MdImage,MdLink,MdAttachFile,MdTextFormat,MdArrowDropDown,MdFormatQuote,MdStrikethroughS,MdFormatClear,MdOutlineFormatIndentIncrease,MdFormatIndentDecrease,MdFormatListNumbered,MdFormatListBulleted,MdFormatAlignCenter,MdFormatAlignRight,MdFormatAlignLeft,MdFormatUnderlined,MdFormatItalic,MdFormatBold,MdRedo,MdUndo}from'react-icons/md';import po from'reactjs-popup';import {useLexicalComposerContext}from'@lexical/react/LexicalComposerContext';import {$getRoot,$getSelection,$isRangeSelection,SELECTION_CHANGE_COMMAND,REDO_COMMAND,UNDO_COMMAND,FORMAT_ELEMENT_COMMAND,FORMAT_TEXT_COMMAND,OUTDENT_CONTENT_COMMAND,INDENT_CONTENT_COMMAND}from'lexical';import {ListNode,ListItemNode,$isListNode,INSERT_UNORDERED_LIST_COMMAND,REMOVE_LIST_COMMAND,INSERT_ORDERED_LIST_COMMAND}from'@lexical/list';import {LinkNode,AutoLinkNode,$isLinkNode,TOGGLE_LINK_COMMAND}from'@lexical/link';import {$getNearestNodeOfType,mergeRegister}from'@lexical/utils';import {$isAtNodeEnd,$patchStyleText}from'@lexical/selection';import {useDropzone}from'react-dropzone';import Uo from'heic2any';import {ListPlugin}from'@lexical/react/LexicalListPlugin';import {LinkPlugin}from'@lexical/react/LexicalLinkPlugin';import {$generateNodesFromDOM,$generateHtmlFromNodes}from'@lexical/html';var Ae=createContext(void 0),te=()=>{let e=useContext(Ae);if(!e)throw new Error("useTheme must be used within a ThemeProvider");return e},Ie=({children:e,initialTheme:o="dark",onThemeChange:n})=>{let[r,t]=useState(o);useEffect(()=>{n&&n(r);},[r,n]);let i=()=>{t(l=>l==="light"?"dark":"light");};return jsx(Ae.Provider,{value:{theme:r,toggleTheme:i},children:e})};var De=createContext(void 0),B=()=>{let e=useContext(De);if(!e)throw new Error("useEmailContext must be used within an EmailProvider");return e},ze=({children:e})=>{let[o,n]=useState({to:[],cc:[],bcc:[]}),[r,t]=useState(false),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(false),[a,m]=useState([]);return useEffect(()=>{console.log("EmailProvider emails updated:",o);},[o]),jsx(De.Provider,{value:{emails:o,setEmails:n,subject:i,setSubject:l,showCC:d,setShowCC:h,showBCC:u,setShowBCC:x,attachments:a,setAttachments:m,isReply:r,setIsReply:t},children:e})};var s={undo:"undo",redo:"redo",bold:"bold",italic:"italic",underline:"underline",color:{base:"colors"},code:"code",link:"link",listNumber:"listNumber",listBullet:"listBullet",align:{base:"align"},indent:"indent",indentDecrease:"indentDecrease",strike:"strike",attachFile:"attachFile",fontSize:"fontSize",fontFamily:"fontFamily"},y={styling:"styling",divider:"divider",component:"component"},Be=[{type:y.styling,icon:"Styling",id:"4bc66ea9-2e35-4a7b-a674-be7e4ee163c5",options:[{name:s.undo,type:y.component,icon:"Undo",id:"29cf5eb3-37cd-482f-9a15-c358faf19cc2"},{name:s.redo,type:y.component,icon:"Redo",id:"8744f7ab-5818-46ce-9417-2fec87123afe"},{type:y.divider,id:"ed0104fd-3507-43f6-80c1-813fbdf04479"},{name:s.fontFamily,type:y.component,id:"1c12d7e2-aa6a-42b4-b25c-b55fe3bcf524"},{type:y.divider,id:"d0f67d01-0731-411a-b448-e1dca47014f4"},{name:s.fontSize,type:y.component,id:"82e31b62-5441-4052-887c-faa02d0b7075"},{type:y.divider,id:"2e3558e4-3ad4-422b-8502-ea3c58fb8c2e"},{name:s.bold,type:y.component,icon:"Bold",id:"ac2b5b54-7323-44a4-bc6d-8bae6e48efe2"},{name:s.italic,type:y.component,icon:"Italic",id:"6a927c2a-2230-4dc7-af71-47fbe9fb784d"},{name:s.underline,type:y.component,icon:"Underline",id:"f07b3a6f-ffaa-4153-beae-79a36acb6a08"},{name:s.color.base,type:y.component,icon:"Color",id:"e14ec25f-3dd3-4ed5-b33a-a033684d248b"},{type:y.divider,id:"93e60297-206f-4f31-bc29-11daff2052bd"},{name:s.align.base,type:y.component,id:"30da93ea-efa6-4642-bfa5-28fd4dc9c5b3"},{type:y.divider,id:"9bad0563-6118-4855-9286-402bf98e00ad"},{name:s.listNumber,type:y.component,icon:"OrderedList",id:"d37865e1-ff54-4118-a5cc-fa147d222471"},{name:s.listBullet,type:y.component,icon:"UnOrderedList",id:"ed77e7c9-b89c-41c5-a749-e68ea0b30497"},{type:y.divider,id:"e5ecd77b-44cc-42fe-badb-48cadf3ddfb1"},{name:s.indentDecrease,type:y.component,icon:"IndentLess",id:"2dc6a5e4-b1b5-47d1-ac2f-5d0becb02d33"},{name:s.indent,type:y.component,icon:"IndentMore",id:"6903a3d1-a83f-4bc6-9bd9-f673feffe84f"}]},{type:"component",name:s.attachFile,icon:"Attach",id:"f43a284e-113e-4095-b001-9d00a1dddc4c"},{type:"component",name:s.link,icon:"Link",id:"580db61e-7939-4efe-914c-304b271998ec"}];var ao={Undo:MdUndo,Redo:MdRedo,Bold:MdFormatBold,Italic:MdFormatItalic,Underline:MdFormatUnderlined,Color:MdTextFormat,LeftAlign:MdFormatAlignLeft,RightAlign:MdFormatAlignRight,CenterAlign:MdFormatAlignCenter,UnOrderedList:MdFormatListBulleted,OrderedList:MdFormatListNumbered,IndentLess:MdFormatIndentDecrease,IndentMore:MdOutlineFormatIndentIncrease,RemoveFormat:MdFormatClear,StrikeThrough:MdStrikethroughS,CodeQuote:MdFormatQuote,DownArrow:MdArrowDropDown,Styling:MdTextFormat,Attach:MdAttachFile,Link:MdLink,Image:MdImage,Check:MdCheck,TextFields:MdTextFields,Edit:MdEdit,Close:MdClose},Ue=ao;var lo=({name:e,size:o=24,color:n,className:r})=>{let t=Ue[e];return t?jsx(t,{size:o,color:n,className:r}):(console.warn(`Icon "${e}" not found.`),null)},k=lo;var mo=({trigger:e,children:o,popUpDirection:n="top center"})=>{let r=useRef(null),t=()=>{r.current&&typeof r.current.close=="function"&&r.current.close();};return jsx(po,{ref:r,trigger:e,closeOnDocumentClick:true,repositionOnResize:true,position:n,className:"filter-popup",children:l=>o({close:()=>{l?.(),t();}})})},_=mo;var uo=[{label:"Sans Serif",value:"sans-serif",style:{fontFamily:"sans-serif"}},{label:"Serif",value:"serif",style:{fontFamily:"serif"}},{label:"Fixed Width",value:"monospace",style:{fontFamily:"monospace"}},{label:"Wide",value:"wide",style:{fontWeight:"bold",letterSpacing:"0.05em"}},{label:"Narrow",value:"narrow",style:{fontStretch:"condensed"}},{label:"Comic Sans MS",value:"Comic Sans MS",style:{fontFamily:"Comic Sans MS, cursive"}},{label:"Garamond",value:"Garamond",style:{fontFamily:"Garamond, serif"}},{label:"Georgia",value:"Georgia",style:{fontFamily:"Georgia, serif"}},{label:"Tahoma",value:"Tahoma",style:{fontFamily:"Tahoma, sans-serif"}},{label:"Trebuchet MS",value:"Trebuchet MS",style:{fontFamily:"Trebuchet MS, sans-serif"}},{label:"Verdana",value:"Verdana",style:{fontFamily:"Verdana, sans-serif"}}],oe=[{key:"small",label:"Small",sizePx:12},{key:"normal",label:"Normal",sizePx:18},{key:"large",label:"Large",sizePx:28},{key:"huge",label:"Huge",sizePx:56}],me=["#000000","#3a3a3a","#5a5a5a","#8a8a8a","#bfbfbf","#dedede","#f3f3f3","#ffffff"],fe=["#e53935","#fb8c00","#ffee58","#66ff66","#4dd0e1","#1e88e5","#9c27b0","#ff3bd6"],ue=[["#f7d7d7","#f3d0c8","#f0c5c5","#efc9d8","#f7e6e9","#f3edf7","#f0eaf6","#f8f0f6"],["#f0b9b9","#f0d4c2","#e6f0d2","#e4f7e8","#d8eef8","#dbe1ff","#e9d9f6","#f5d9f7"],["#e69a9a","#e6caa3","#d7e6b0","#c8f0e6","#bfe3ff","#cbd8ff","#d6c3f3","#f0c2f3"],["#d16464","#d09a6a","#a8cf7b","#7fd6c0","#73b7ff","#7a9cff","#b483f1","#f08cf2"],["#b23a3a","#b26a3a","#7aa04a","#3fb092","#296f94","#2a4177","#452a68","#6e1f4d"],["#7a1d1d","#7a4a1e","#556a2a","#195b47","#123f5a","#182840","#2a1836","#3a1026"]],ge=uo;function be({value:e="serif",onChange:o}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[ge?.find(n=>n.value===e)?.label,jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:ge.map(r=>jsx("button",{className:"btn-mail-editor",onClick:()=>{o(r.value),n();},style:{...r.style},children:jsxs("div",{className:"font-option",children:[e===r.value&&jsx(k,{name:"Check"}),r.label]})},r.value))})})})})}function he({value:e="normal",onChange:o=()=>{}}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"TextFields"}),jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:oe.map(r=>jsx("button",{className:"btn-mail-editor",onClick:()=>{o(r.key),n();},style:{fontSize:`${r.sizePx}px`},children:jsxs("div",{className:"font-option",children:[e===r.key&&jsx(k,{name:"Check"}),r.label]})},r.key))})})})})}function Y({color:e,selected:o,onClick:n,label:r}){return jsx("button",{className:"swatch",title:r||e,"aria-pressed":o,onClick:()=>n(e),style:{background:e},children:o&&jsx("svg",{className:"check",viewBox:"0 0 24 24","aria-hidden":true,children:jsx("path",{d:"M20 6L9 17l-5-5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}function xe({value:e={background:"#ffffff",text:"#000000"},onChange:o=()=>{}}){function n(r,t){o({...e,[r]:t});}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"Styling"}),jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"color-popover",role:"dialog","aria-label":"Choose colors",children:jsxs("div",{className:"color-columns",children:[jsxs("section",{className:"color-column","aria-labelledby":"bg-label",children:[jsx("h4",{id:"bg-label",children:"Background color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{n("background",i),r();},label:t},t+"bg"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{n("background",i),r();},label:t},t+"bgacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.background===l,onClick:d=>{n("background",d),r();},label:l},l+"bgp"+i))},"row"+i))})]}),jsxs("section",{className:"color-column","aria-labelledby":"text-label",children:[jsx("h4",{id:"text-label",children:"Text color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{n("text",i),r();},label:t},t+"tx"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{n("text",i),r();},label:t},t+"txacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.text===l,onClick:d=>{n("text",d),r();},label:l},l+"txp"+i))},"txrow"+i))})]})]})})})})}var Ge=[{key:"left",iconName:"LeftAlign",label:"Left align"},{key:"center",iconName:"CenterAlign",label:"Center align"},{key:"right",iconName:"RightAlign",label:"Right align"}];function ve({value:e="left",onChange:o=()=>{}}){function n(r){o(r);}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:Ge?.find(r=>r.key===e)?.iconName||"LeftAlign"}),jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"wrapper-alignment",children:Ge.map(t=>{let i=t.key===e;return jsxs("button",{role:"menuitemradio","aria-checked":i,tabIndex:0,className:`alignment-option ${i?"active":""}`,onClick:()=>{n(t.key),r();},children:[jsx("div",{className:"option-icon",children:jsx(k,{name:t.iconName,size:20})}),jsx("div",{className:`option-check ${i?"":"hidden"}`,"aria-hidden":true,children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",children:jsx("path",{d:"M20 6L9 17l-5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]},t.key)})})})})}var Oo=1;function Xe(e){if(!e||e.startsWith("#"))return e;if(e.startsWith("rgba")){let n=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)/);if(n){let[,r,t,i,l]=n;return l==="0"?"transparent":"#"+[r,t,i].map(d=>{let h=parseInt(d).toString(16);return h.length===1?"0"+h:h}).join("")}}let o=e.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(o){let[,n,r,t]=o;return "#"+[n,r,t].map(i=>{let l=parseInt(i).toString(16);return l.length===1?"0"+l:l}).join("")}return e}function Po(){let[e]=useLexicalComposerContext(),[o,n]=useState("paragraph"),[r,t]=useState({[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"}),[i,l]=useState(false),d=useCallback(()=>{let f=$getSelection(),b={[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"};if($isRangeSelection(f)){let F=f.anchor.getNode(),c=F.getKey()==="root"?F:F.getTopLevelElementOrThrow(),p=c.getKey(),g=e.getElementByKey(p);if(g!==null)if($isListNode(c)){let L=$getNearestNodeOfType(F,ListNode),ee=L?L.getTag():c.getTag();n(ee);}else {let L=c.getType();n(L);}b[s.bold]=f.hasFormat("bold"),b[s.italic]=f.hasFormat("italic"),b[s.underline]=f.hasFormat("underline"),b[s.strike]=f.hasFormat("strikethrough"),b[s.code]=f.hasFormat("code");let H=O(f),P=H.getParent();$isLinkNode(P)||$isLinkNode(H)?(b[s.link]=true,l(true)):(b[s.link]=false,l(false));let D=e.getElementByKey(H.getKey()),T=e.getElementByKey(P.getKey()),S=D||T||g;if(S){let L=window.getComputedStyle(S),ee=L.getPropertyValue("font-family");if(ee){let G=ee.split(",")[0].trim().replace(/['"]/g,"");(G==="-apple-system"||G==="BlinkMacSystemFont"||G==="system-ui")&&(G="sans-serif"),b[s.fontFamily]=G;}let Le=L.getPropertyValue("font-size");if(Le){let G=parseInt(Le,10);b[s.fontSize]=G||16;}let W=null,z=null;S instanceof HTMLElement&&S.style&&(W=S.style.color||null,z=S.style.backgroundColor||null),W||(W=L.getPropertyValue("color")),z||(z=L.getPropertyValue("background-color")),console.log("\u{1F3A8} Color detection:",{inlineColor:S instanceof HTMLElement?S.style.color:"N/A",inlineBg:S instanceof HTMLElement?S.style.backgroundColor:"N/A",computedColor:W,computedBg:z,element:S});let Te=W?Xe(W):null,Me=z&&z!=="rgba(0, 0, 0, 0)"&&z!=="transparent"?Xe(z):null;(Te||Me)&&(b[s.color.base]={text:Te||"#000000",background:Me||"#ffffff"});let pe=L.getPropertyValue("text-align")||"left";pe==="start"&&(pe="left"),b[s.align.base]=pe;}t(b);}},[e]);useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:f})=>{f.read(()=>{d();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(d(),false),Oo)),[e,d]);function h(f,b){switch(f){case s.bold:e.dispatchCommand(FORMAT_TEXT_COMMAND,"bold");break;case s.italic:e.dispatchCommand(FORMAT_TEXT_COMMAND,"italic");break;case s.underline:e.dispatchCommand(FORMAT_TEXT_COMMAND,"underline");break;case s.align.base:e.dispatchCommand(FORMAT_ELEMENT_COMMAND,b);break;case s.undo:e.dispatchCommand(UNDO_COMMAND,void 0);break;case s.redo:e.dispatchCommand(REDO_COMMAND,void 0);break;case s.listNumber:w();break;case s.listBullet:v();break;case s.indent:u();break;case s.indentDecrease:N();break;case s.color.base:m(b);break;case s.fontFamily:x(b);break;case s.fontSize:a(b);break;case s.link:E();break;}}let u=()=>{e.dispatchCommand(INDENT_CONTENT_COMMAND,void 0);},x=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"font-family":f});});},a=f=>{let b=oe.find(F=>F.key===f)?.sizePx??16;e.update(()=>{let F=$getSelection();$isRangeSelection(F)&&$patchStyleText(F,{"font-size":`${b}px`});});},m=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"background-color":f.background,color:f.text});});},E=useCallback(()=>{i?e.dispatchCommand(TOGGLE_LINK_COMMAND,null):e.dispatchCommand(TOGGLE_LINK_COMMAND,"https://");},[e,i]),N=()=>{e.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0);},v=()=>{o!=="ul"?e.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);},w=()=>{o!=="ol"?e.dispatchCommand(INSERT_ORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);};function O(f){let b=f.anchor,F=f.focus,c=f.anchor.getNode(),p=f.focus.getNode();return c===p?c:f.isBackward()?$isAtNodeEnd(F)?c:p:$isAtNodeEnd(b)?p:c}return {onChange:h,isLink:i,editor:e,selectedEventTypes:r,blockType:o}}var Qe=Po;function Do({editor:e}){let o=useRef(null),n=useRef(null),r=useRef(false),[t,i]=useState(""),[l,d]=useState(false),[h,u]=useState(null),x=useCallback(()=>{let a=window.getSelection(),m=$getSelection();if($isRangeSelection(m)){let w=zo(m),O=w.getParent();$isLinkNode(O)?i(O.getURL()):$isLinkNode(w)?i(w.getURL()):i("");}let E=o.current,N=document.activeElement;if(!E)return;let v=e.getRootElement();if(m&&a&&!a.isCollapsed&&v&&v.contains(a.anchorNode)){let w=a.getRangeAt(0),O;if(a.anchorNode===v){let f=v;for(;f.firstElementChild!=null;)f=f.firstElementChild;O=f.getBoundingClientRect();}else O=w.getBoundingClientRect();r.current||tt(E,O),u(m);}else (!N||N.className!=="link-input")&&(tt(E,null),u(null),d(false),i(""));return true},[e]);return useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:a})=>{a.read(()=>{x();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(x(),true),1)),[e,x]),useEffect(()=>{e.getEditorState().read(()=>{x();});},[e,x]),useEffect(()=>{l&&n.current&&n.current.focus();},[l]),jsxs("div",{className:"floating-link-editor",ref:o,children:[l?jsx("input",{ref:n,className:"link-input",value:t,onChange:a=>i(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),h&&t!==""&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(false)):a.key==="Escape"&&(a.preventDefault(),d(false));},placeholder:"Enter link..."}):jsx("div",{className:"link-display",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:t||"No link selected"})}),jsx("button",{className:"link-button",onMouseDown:a=>a.preventDefault(),onClick:()=>{console.log("floating link editor",l),l&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(a=>!a);},children:jsx(k,{name:l?"Check":"Edit"})})]})}function zo(e){let o=e.anchor.getNode(),n=e.focus.getNode();return o===n?o:e.isBackward()?$isAtNodeEnd(e.focus)?o:n:$isAtNodeEnd(e.anchor)?n:o}function tt(e,o){if(!o){e.style.opacity="0",e.style.top="-1000px",e.style.left="-1000px";return}let n=e.offsetWidth,r=e.offsetHeight,t=window.innerWidth,i=window.innerHeight,l=o.top+o.height+window.pageYOffset+10,d=o.left+window.pageXOffset-n/2+o.width/2;d<8&&(d=8),d+n>t-8&&(d=t-n-8),l+r>i-8&&(l=o.top+window.pageYOffset-r-10),l<8&&(l=8),e.style.opacity="1",e.style.top=`${l}px`,e.style.left=`${d}px`;}var ot=Do;var $={FILE_INVALID_TYPE:"file-invalid-type",FILE_TOO_LARGE:"file-too-large",TOO_MANY_FILES:"too-many-files",HEIC_CONVERSION_ERROR:"heic-conversion-error"},$o=10,Ho=10,it=()=>Math.random().toString(36).substring(2,10)+Date.now().toString(36),Go=e=>{if(e<1024)return {value:e.toString(),type:"bytes"};let o=e/1024;if(o<1024)return {value:o.toFixed(1),type:"KB"};let n=o/1024;return n<1024?{value:n.toFixed(1),type:"MB"}:{value:(n/1024).toFixed(1),type:"GB"}},at=({accept:e={"image/*":[".png",".gif",".jpeg",".jpg"],"application/pdf":[".pdf"]},maxSize:o=Ho*1024*1024,maxFiles:n=$o,multiple:r=true,isDisabled:t=false,replaceAfterUpload:i=false,files:l=[],handleFileChange:d=()=>{}})=>{let[h,u]=useState(false),[x,a]=useState(l??[]),[m,E]=useState([]),N=c=>{switch(c){case $.FILE_INVALID_TYPE:return "Invalid file type. Please upload a supported format.";case $.FILE_TOO_LARGE:{let{value:p,type:g}=Go(o);return `File too large. Maximum allowed size is ${p} ${g}.`}case $.TOO_MANY_FILES:return `Too many files selected. Maximum allowed: ${n}.`;case $.HEIC_CONVERSION_ERROR:return "Failed to convert HEIC image. Please upload a JPEG or PNG instead.";default:return "An unknown file error occurred."}};useEffect(()=>{d(x);},[x]);let{getRootProps:v,getInputProps:w,isDragActive:O,open:f}=useDropzone({accept:e,maxSize:o,multiple:r,maxFiles:n,disabled:t,noClick:true,onFileDialogCancel:()=>u(false),onFileDialogOpen:()=>{t||u(true);},onDrop:async(c,p)=>{let H=(await Promise.all(c.map(async P=>{if(!P)return null;if(P.type==="image/heic")try{let D=await Uo({blob:P,toType:"image/jpeg"}),T=Array.isArray(D)?D[0]:D,S=new File([T],`${P.name.replace(/\.heic$/i,"")}.jpeg`,{type:"image/jpeg"});return Object.assign(S,{uuid:it(),preview:URL.createObjectURL(S)})}catch(D){console.error("HEIC conversion error:",D);let T=N($.HEIC_CONVERSION_ERROR);return E(S=>[...S,{file:P,preview:URL.createObjectURL(P),readableErrors:[T],errors:[{code:$.HEIC_CONVERSION_ERROR,message:T}]}]),null}return Object.assign(P,{uuid:it(),preview:URL.createObjectURL(P)})}))).filter(Boolean);if(!t){let P=i?[]:[...x];P=[...P,...H];let D=p.map(T=>{let S=T.errors.map(L=>N(L.code));return {file:T.file,errors:T.errors.map(L=>({code:L.code,message:L.message})),preview:URL.createObjectURL(T.file),readableErrors:S}});return E(T=>[...T,...D]),a(P),P}return x},validator:c=>{let{name:p,type:g}=c;if(p){let H=p.split(".").pop()?.toLowerCase();if(e&&e?.[g]&&e?.[g].length&&!e?.[g].includes(`.${H}`))return {code:$.FILE_INVALID_TYPE,message:N($.FILE_INVALID_TYPE)}}return null}}),b=useCallback(c=>{a(p=>p.filter(g=>g.uuid!==c));},[a]),F=useCallback(()=>{E([]);},[]);return useEffect(()=>()=>{x.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview)),m.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview));},[]),{getRootProps:v,getInputProps:w,isDragActive:O,isFileDialogOpen:h,rejectedFiles:m,openFileDialog:f,removeFile:b,clearRejectedFiles:F}};var jo=({handleFileChange:e})=>{let{getRootProps:o,getInputProps:n,openFileDialog:r}=at({multiple:true,maxFiles:5,maxSize:5242880,handleFileChange:t=>{e(t);}});return jsx("div",{className:"uploader-container",children:jsxs("div",{...o(),children:[jsx("input",{...n()}),jsx("button",{onClick:r,children:jsx(k,{className:"upload-icon",name:"Attach"})})]})})},lt=jo;function Se({file:e,index:o,onRemove:n,onView:r}){if(!e)return null;let t=e?.name??"unknown",i=e instanceof File||"size"in e&&e.size!==void 0?e.size:"bytes"in e&&e.bytes!==void 0?e.bytes:null,l=("url"in e?e?.url:null)??null,d=useMemo(()=>{if(l)return l;if(typeof window<"u"&&e instanceof File)try{return URL.createObjectURL(e)}catch{return null}return null},[e,l]),h=a=>{if(!a&&a!==0)return "";let m=Math.round(a/1024);return m<1024?`${m}K`:`${Math.round(a/1024/1024*10)/10}M`},u=a=>{if(a.preventDefault(),r)return r(d??null);d&&window.open(d,"_blank","noopener");},x=a=>{n&&n(a);};return jsxs("div",{className:"fps-row",role:"group","aria-label":`Attachment ${t}`,children:[jsxs("div",{className:"fps-left",children:[jsx("a",{href:d??"#",className:"fps-filename",onClick:u,title:t,target:"_blank",rel:"noopener noreferrer",children:t}),i!=null&&jsxs("span",{className:"fps-size",children:["\xA0(",h(i),")"]})]}),jsx("button",{type:"button",className:"fps-close","aria-label":`Remove ${t}`,onClick:()=>x(o),children:"\xD7"})]})}var dt=(e,{onChange:o,state:n,setState:r,selectedEventTypes:t,blockType:i,setAttachments:l})=>{switch(e.name){case s.undo:case s.redo:case s.bold:case s.italic:case s.underline:case s.indentDecrease:case s.indent:case s.link:return jsx("button",{className:`tool-bar-button ${t?.[e.name]?"active-btn-toolbar":""}`,onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listNumber:return jsx("button",{className:i==="ol"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listBullet:return jsx("button",{className:i==="ul"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.attachFile:return jsx(lt,{value:n?.[e.name],handleFileChange:d=>{console.log("\u{1F680} ~ getToolbarComponent ~ e:",d),r(h=>({...h,[e.name]:d})),l(d);}});case s.fontFamily:return jsx(be,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.fontSize:return jsx(he,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.color.base:return jsx(xe,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.align.base:return jsx(ve,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});}return e.type===y.divider?jsx("span",{className:"divider"}):"-"},Yo=(e,{setToggle:o,toggle:n,onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})=>{switch(e.type){case y.divider:return jsx("div",{className:"divider"},`divider-${e.type}-${e.icon}`);case y.component:return dt(e,{onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h});case y.styling:return jsxs("div",{className:"styling-toolbar",children:[n?jsx("div",{className:"styling-options",children:e.options?.length&&Array.isArray(e.options)?e.options?.map(u=>dt(u,{onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})):null}):null,jsx("button",{onClick:()=>o(u=>!u),children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})})]},`divider-${e.type}-${e.icon}`);}return "-"};function qo({rightChildren:e,leftChildren:o}){let[n,r]=useState(true),[t,i]=useState({}),{setAttachments:l}=B(),{onChange:d,isLink:h,editor:u,selectedEventTypes:x,blockType:a}=Qe();return console.log("\u{1F680} ~ ToolBar ~ selectedEventTypes:",x),jsxs("div",{className:"toolbar-container",children:[t[s.attachFile]?.length?jsx("div",{className:"file-upload-container",children:t[s.attachFile]?.map((m,E)=>jsx(Se,{file:m,index:E,onRemove:N=>{i(v=>{let w=v[s.attachFile].filter((O,f)=>f!==N);return l(w),{...v,[s.attachFile]:w}});}},E))}):null,jsxs("div",{className:"toolbar-wrapper",children:[o,Be?.map(m=>Yo(m,{setToggle:r,state:t,setState:i,toggle:n,onChange:d,selectedEventTypes:x,blockType:a,setAttachments:l})),e,h?createPortal(jsx(ot,{editor:u}),document.body):null]})]})}var pt=qo;var Xo={ltr:"ltr",rtl:"rtl",placeholder:"editor-placeholder",paragraph:"editor-paragraph",quote:"editor-quote",heading:{h1:"editor-heading-h1",h2:"editor-heading-h2",h3:"editor-heading-h3",h4:"editor-heading-h4",h5:"editor-heading-h5"},list:{nested:{listitem:"editor-nested-listitem"},ol:"editor-list-ol",ul:"editor-list-ul",listitem:"editor-listitem"},image:"editor-image",link:"editor-link",text:{bold:"editor-text-bold",italic:"editor-text-italic",overflowed:"editor-text-overflowed",hashtag:"editor-text-hashtag",underline:"editor-text-underline",strikethrough:"editor-text-strikethrough",underlineStrikethrough:"editor-text-underlineStrikethrough",code:"editor-text-code"},code:"editor-code",codeHighlight:{atrule:"editor-tokenAttr",attr:"editor-tokenAttr",boolean:"editor-tokenProperty",builtin:"editor-tokenSelector",cdata:"editor-tokenComment",char:"editor-tokenSelector",class:"editor-tokenFunction","class-name":"editor-tokenFunction",comment:"editor-tokenComment",constant:"editor-tokenProperty",deleted:"editor-tokenProperty",doctype:"editor-tokenComment",entity:"editor-tokenOperator",function:"editor-tokenFunction",important:"editor-tokenVariable",inserted:"editor-tokenSelector",keyword:"editor-tokenAttr",namespace:"editor-tokenVariable",number:"editor-tokenProperty",operator:"editor-tokenOperator",prolog:"editor-tokenComment",property:"editor-tokenProperty",punctuation:"editor-tokenPunctuation",regex:"editor-tokenVariable",selector:"editor-tokenSelector",string:"editor-tokenSelector",symbol:"editor-tokenProperty",tag:"editor-tokenProperty",url:"editor-tokenOperator",variable:"editor-tokenVariable"}},mt=Xo;function tr({initialHTML:e}){let[o]=useLexicalComposerContext();return useEffect(()=>{o.update(()=>{let r=new DOMParser().parseFromString(e,"text/html"),t=$generateNodesFromDOM(o,r),i=$getRoot();i.clear(),i.append(...t);});},[o,e]),null}var ft=tr;function Pe({onChange:e}){let[o]=useLexicalComposerContext();return useEffect(()=>o.registerUpdateListener(({editorState:n})=>{n.read(()=>{let r=$generateHtmlFromNodes(o,null);e(r);});}),[o,e]),null}function hr(e){console.error(e);}function xr({placeholder:e="Enter some text here",initialHTML:o="",rightChildren:n,leftChildren:r,minHeight:t="",onChange:i,editorChildren:l,isEditorVisible:d=true}){return jsx("div",{className:"my-editor-wrapper",children:jsxs(LexicalComposer,{initialConfig:{namespace:"MyEditor",theme:mt,nodes:[LinkNode,ListNode,ListItemNode,AutoLinkNode],onError:hr},children:[d?jsx(RichTextPlugin,{contentEditable:jsx(ContentEditable,{style:{minHeight:t},className:"my-editor-content","aria-placeholder":e,placeholder:jsx("div",{className:"my-editor-placeholder",children:e})}),ErrorBoundary:LexicalErrorBoundary}):l,jsx(pt,{rightChildren:n,leftChildren:r}),jsx(HistoryPlugin,{}),jsx(ft,{initialHTML:o}),jsx(AutoFocusPlugin,{}),jsx(ListPlugin,{}),jsx(LinkPlugin,{}),i&&jsx(Pe,{onChange:i})]})})}var ut=xr;function X(e){return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function kr({emails:e=[],setEmails:o,fetchOptions:n}){let r=useRef(null),t=useRef(null),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(-1),[a,m]=useState([]),[E,N]=useState(false),v=useRef([]),w=useRef([]);useEffect(()=>{v.current=v.current.slice(0,e.length);},[e.length]),useEffect(()=>{w.current=w.current.slice(0,a.length);},[a.length]),useEffect(()=>{X(i)?(async()=>{N(true);try{let p=await n(i);m(p);}catch(p){console.error("Error fetching email options:",p),m([]);}finally{N(false);}})():(m([]),N(false));},[i,n]),useEffect(()=>{d||x(-1);},[d]),useEffect(()=>{u>=0&&u<w.current.length&&w.current[u]?.scrollIntoView({block:"nearest",behavior:"smooth"});},[u]);let O=()=>{t.current?.focus();},f=c=>{r.current?.close(),l(""),o(p=>[...p,c]),x(-1),requestAnimationFrame(()=>t.current?.focus());},b=c=>{if(d&&X(i)&&a.length>0){if(c.key==="ArrowDown"){c.preventDefault(),x(p=>p<a.length-1?p+1:p);return}if(c.key==="ArrowUp"){c.preventDefault(),x(p=>p>0?p-1:-1);return}if(c.key==="Enter"&&u>=0){c.preventDefault(),f(a[u]);return}if(c.key==="Escape"){c.preventDefault(),r.current?.close(),x(-1);return}}if(c.key==="Backspace"&&i===""){let p=e.length-1,g=v.current[p];g&&(g.focus(),c.preventDefault());}},F=c=>{o(p=>{let g=[...p];return g.splice(c,1),g}),requestAnimationFrame(()=>{let p=Math.min(Math.max(0,c-1),e.length-2),g=v.current[p];g?g.focus():O();});};return jsx(Fragment,{children:jsx(po,{ref:r,trigger:jsxs("div",{className:"container-receipts",children:[e?.length?jsx("div",{className:"emails-container",children:e.map((c,p)=>jsxs("div",{className:"emails",tabIndex:0,ref:g=>{v.current[p]=g;},onKeyDown:g=>{g.key==="Backspace"&&(g.preventDefault(),F(p)),g.key==="Enter"&&(g.preventDefault(),F(p),O());},role:"button","aria-label":`Email ${c.email}`,children:[jsx("span",{style:{marginRight:8},children:c.email}),jsx("button",{className:"emails-close",onClick:g=>{g.stopPropagation(),F(p);},"aria-label":`Remove ${c.email}`,children:jsx(k,{name:"Close"})})]},c.email??p))}):null,jsx("input",{ref:t,type:"text",className:"input-header",value:i,autoFocus:true,onKeyDown:b,onChange:c=>{let p=c.target.value;X(p)&&r.current?.open(),l(p);}})]}),closeOnDocumentClick:true,repositionOnResize:true,position:"bottom left",className:"filter-popup",onOpen:()=>{h(true),requestAnimationFrame(()=>t.current?.focus());},onClose:()=>{h(false);},children:X(i)?jsx("div",{className:"options-dropdown",children:E?jsx(Fragment,{children:[1,2,3].map(c=>jsxs("div",{className:"option-dropdown skeleton-loader",children:[jsx("div",{className:"skeleton-line skeleton-name"}),jsx("div",{className:"skeleton-line skeleton-email"})]},c))}):a.length>0?a.map((c,p)=>jsxs("button",{ref:g=>{w.current[p]=g;},className:`option-dropdown ${u===p?"selected":""}`,onBlur:g=>{g.stopPropagation();},onFocus:g=>{g.stopPropagation();},onMouseEnter:()=>x(p),onMouseLeave:()=>x(-1),onClick:g=>{g.stopPropagation(),f(c);},"aria-selected":u===p,children:[jsx("h4",{children:c.name}),c.email]},p)):null}):null})})}var bt=kr;function Cr({name:e,needCCAndBCC:o,setShowCC:n,setShowBCC:r,showBCC:t,showCC:i,emails:l,handleChange:d,fetchOptions:h}){return jsxs("div",{className:"container-receipts",children:[jsx("label",{className:"block text-sm font-medium text-gray-700",children:e}),jsx(bt,{emails:l,setEmails:d,fetchOptions:h}),o&&!i?jsx("button",{className:"btn-mail-editor",onClick:()=>n?.(u=>!u),children:"CC"}):null,o&&!t?jsx("button",{className:"btn-mail-editor",onClick:()=>r?.(u=>!u),children:"BCC"}):null]})}var de=Cr;function Fr({fetchEmailOptions:e}){let[o,n]=useState(false),r=useRef(null),{emails:t,setEmails:i,showCC:l,setShowCC:d,showBCC:h,setShowBCC:u}=B();return useEffect(()=>{o&&(d(t.cc.length>0),u(t.bcc.length>0));},[o,t.cc.length,t.bcc.length]),useEffect(()=>{let a=r.current;if(!a)return;let m=()=>{n(true);},E=N=>{console.log("\u{1F680} ~ handleFocusOut ~ e:",N);let v=N.relatedTarget;v&&v.classList&&v.classList.contains("option-dropdown")||v&&a.contains(v)||(console.log("why this ",v?.classList),n(false));};return a.addEventListener("focusin",m),a.addEventListener("focusout",E),()=>{a.removeEventListener("focusin",m),a.removeEventListener("focusout",E);}},[]),jsx("div",{ref:r,tabIndex:-1,className:"relative",children:o?jsxs("div",{children:[jsx(de,{name:"To",needCCAndBCC:true,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.to,handleChange:a=>{i(m=>({...m,to:typeof a=="function"?a(m.to):a}));},fetchOptions:e}),l?jsx(de,{name:"CC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.cc,handleChange:a=>{i(m=>({...m,cc:typeof a=="function"?a(m.cc):a}));},fetchOptions:e}):null,h?jsx(de,{name:"BCC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.bcc,handleChange:a=>{i(m=>({...m,bcc:typeof a=="function"?a(m.bcc):a}));},fetchOptions:e}):null]}):jsx("input",{type:"text",placeholder:"Recipients",className:"input-header",value:(()=>{if(t.to.length===0&&t.cc.length===0&&t.bcc.length===0)return "Recipients";let a=[];return t.to.length>0&&a.push(t.to.map(m=>m.email).join(", ")),t.cc.length>0&&a.push(t.cc.map(m=>m.email).join(", ")),t.bcc.length>0&&a.push("bcc: "+t.bcc.map(m=>m.email).join(", ")),a.join(", ")})(),readOnly:true})})}var xt=Fr;function Sr({fetchEmailOptions:e}){let{subject:o,setSubject:n,isReply:r}=B();return jsxs("div",{className:"gmail-header",children:[jsx(xt,{fetchEmailOptions:e}),jsx("input",{type:"text",placeholder:"Subject",className:"input-header",value:r&&!o.startsWith("Re: ")?`Re: ${o}`:o,onChange:t=>n(t.target.value)})]})}var yt=Sr;function Pr({initialData:e,isReply:o,fetchEmailOptions:n,handleChange:r,leftChildren:t,rightChildren:i,editorChildren:l,isEditorVisible:d=true}){let{emails:h,subject:u,attachments:x,setEmails:a,setSubject:m,setAttachments:E,setIsReply:N}=B(),{theme:v}=te(),[w,O]=useState(e?.body||""),[f,b]=useState({to:e?.to||[],cc:e?.cc||[],bcc:e?.bcc||[],subject:e?.subject||"",body:e?.body||"",attachments:e?.attachments||[],isReply:o||false});useEffect(()=>{e&&((e.to||e.cc||e.bcc)&&a({to:e.to||[],cc:e.cc||[],bcc:e.bcc||[]}),e.subject&&m(e.subject),e.attachments&&E(e.attachments),e.body&&O(e.body)),o!==void 0&&N(o);},[]);let F=c=>{O(c);};return useEffect(()=>{b(c=>({...c,to:h.to,cc:h.cc,bcc:h.bcc}));},[h]),useEffect(()=>{b(c=>({...c,subject:u}));},[u]),useEffect(()=>{b(c=>({...c,body:w}));},[w]),useEffect(()=>{b(c=>({...c,attachments:x}));},[x]),useEffect(()=>{b(c=>({...c,isReply:o}));},[o]),useEffect(()=>{r(f);},[f,r]),jsxs("div",{className:"react-mail-inbox-root gmail-wrapper","data-theme":v,children:[t,jsx(yt,{fetchEmailOptions:n}),jsx(ut,{initialHTML:e?.body,onChange:F,editorChildren:l,isEditorVisible:d}),i]})}var wt=Pr;function Tr({fetchEmailOptions:e,handleChange:o,initialData:n,leftChildren:r,rightChildren:t,isReply:i}){return jsx(ze,{children:jsx(wt,{fetchEmailOptions:e,handleChange:o,initialData:n,isReply:i,leftChildren:r,rightChildren:t})})}var Nt=Tr;function Mr({fetchEmailOptions:e,handleChange:o,initialData:n,initialTheme:r="dark",onThemeChange:t,leftChildren:i,rightChildren:l}){return jsx(Ie,{initialTheme:r,onThemeChange:t,children:jsx(Nt,{fetchEmailOptions:e,handleChange:o,initialData:n,leftChildren:i,rightChildren:l})})}var Rt=Mr;var Ba=Rt;
|
|
1
|
+
import {createContext,useContext,useState,useEffect,useRef,useCallback,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {AutoFocusPlugin}from'@lexical/react/LexicalAutoFocusPlugin';import {LexicalComposer}from'@lexical/react/LexicalComposer';import {RichTextPlugin}from'@lexical/react/LexicalRichTextPlugin';import {ContentEditable}from'@lexical/react/LexicalContentEditable';import {HistoryPlugin}from'@lexical/react/LexicalHistoryPlugin';import {LexicalErrorBoundary}from'@lexical/react/LexicalErrorBoundary';import {createPortal}from'react-dom';import {MdClose,MdEdit,MdTextFields,MdCheck,MdImage,MdLink,MdAttachFile,MdTextFormat,MdArrowDropDown,MdFormatQuote,MdStrikethroughS,MdFormatClear,MdOutlineFormatIndentIncrease,MdFormatIndentDecrease,MdFormatListNumbered,MdFormatListBulleted,MdFormatAlignCenter,MdFormatAlignRight,MdFormatAlignLeft,MdFormatUnderlined,MdFormatItalic,MdFormatBold,MdRedo,MdUndo}from'react-icons/md';import po from'reactjs-popup';import {useLexicalComposerContext}from'@lexical/react/LexicalComposerContext';import {$getRoot,$getSelection,$isRangeSelection,SELECTION_CHANGE_COMMAND,REDO_COMMAND,UNDO_COMMAND,FORMAT_ELEMENT_COMMAND,FORMAT_TEXT_COMMAND,OUTDENT_CONTENT_COMMAND,INDENT_CONTENT_COMMAND}from'lexical';import {ListNode,ListItemNode,$isListNode,INSERT_UNORDERED_LIST_COMMAND,REMOVE_LIST_COMMAND,INSERT_ORDERED_LIST_COMMAND}from'@lexical/list';import {LinkNode,AutoLinkNode,$isLinkNode,TOGGLE_LINK_COMMAND}from'@lexical/link';import {$getNearestNodeOfType,mergeRegister}from'@lexical/utils';import {$isAtNodeEnd,$patchStyleText}from'@lexical/selection';import {useDropzone}from'react-dropzone';import Uo from'heic2any';import {ListPlugin}from'@lexical/react/LexicalListPlugin';import {LinkPlugin}from'@lexical/react/LexicalLinkPlugin';import {$generateNodesFromDOM,$generateHtmlFromNodes}from'@lexical/html';var Ae=createContext(void 0),te=()=>{let e=useContext(Ae);if(!e)throw new Error("useTheme must be used within a ThemeProvider");return e},Ie=({children:e,initialTheme:o="dark",onThemeChange:r})=>{let[n,t]=useState(o);useEffect(()=>{r&&r(n);},[n,r]);let i=()=>{t(l=>l==="light"?"dark":"light");};return jsx(Ae.Provider,{value:{theme:n,toggleTheme:i},children:e})};var De=createContext(void 0),B=()=>{let e=useContext(De);if(!e)throw new Error("useEmailContext must be used within an EmailProvider");return e},ze=({children:e})=>{let[o,r]=useState({to:[],cc:[],bcc:[]}),[n,t]=useState(false),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(false),[a,m]=useState([]);return useEffect(()=>{console.log("EmailProvider emails updated:",o);},[o]),jsx(De.Provider,{value:{emails:o,setEmails:r,subject:i,setSubject:l,showCC:d,setShowCC:h,showBCC:u,setShowBCC:x,attachments:a,setAttachments:m,isReply:n,setIsReply:t},children:e})};var s={undo:"undo",redo:"redo",bold:"bold",italic:"italic",underline:"underline",color:{base:"colors"},code:"code",link:"link",listNumber:"listNumber",listBullet:"listBullet",align:{base:"align"},indent:"indent",indentDecrease:"indentDecrease",strike:"strike",attachFile:"attachFile",fontSize:"fontSize",fontFamily:"fontFamily"},y={styling:"styling",divider:"divider",component:"component"},Be=[{type:y.styling,icon:"Styling",id:"4bc66ea9-2e35-4a7b-a674-be7e4ee163c5",options:[{name:s.undo,type:y.component,icon:"Undo",id:"29cf5eb3-37cd-482f-9a15-c358faf19cc2"},{name:s.redo,type:y.component,icon:"Redo",id:"8744f7ab-5818-46ce-9417-2fec87123afe"},{type:y.divider,id:"ed0104fd-3507-43f6-80c1-813fbdf04479"},{name:s.fontFamily,type:y.component,id:"1c12d7e2-aa6a-42b4-b25c-b55fe3bcf524"},{type:y.divider,id:"d0f67d01-0731-411a-b448-e1dca47014f4"},{name:s.fontSize,type:y.component,id:"82e31b62-5441-4052-887c-faa02d0b7075"},{type:y.divider,id:"2e3558e4-3ad4-422b-8502-ea3c58fb8c2e"},{name:s.bold,type:y.component,icon:"Bold",id:"ac2b5b54-7323-44a4-bc6d-8bae6e48efe2"},{name:s.italic,type:y.component,icon:"Italic",id:"6a927c2a-2230-4dc7-af71-47fbe9fb784d"},{name:s.underline,type:y.component,icon:"Underline",id:"f07b3a6f-ffaa-4153-beae-79a36acb6a08"},{name:s.color.base,type:y.component,icon:"Color",id:"e14ec25f-3dd3-4ed5-b33a-a033684d248b"},{type:y.divider,id:"93e60297-206f-4f31-bc29-11daff2052bd"},{name:s.align.base,type:y.component,id:"30da93ea-efa6-4642-bfa5-28fd4dc9c5b3"},{type:y.divider,id:"9bad0563-6118-4855-9286-402bf98e00ad"},{name:s.listNumber,type:y.component,icon:"OrderedList",id:"d37865e1-ff54-4118-a5cc-fa147d222471"},{name:s.listBullet,type:y.component,icon:"UnOrderedList",id:"ed77e7c9-b89c-41c5-a749-e68ea0b30497"},{type:y.divider,id:"e5ecd77b-44cc-42fe-badb-48cadf3ddfb1"},{name:s.indentDecrease,type:y.component,icon:"IndentLess",id:"2dc6a5e4-b1b5-47d1-ac2f-5d0becb02d33"},{name:s.indent,type:y.component,icon:"IndentMore",id:"6903a3d1-a83f-4bc6-9bd9-f673feffe84f"}]},{type:"component",name:s.attachFile,icon:"Attach",id:"f43a284e-113e-4095-b001-9d00a1dddc4c"},{type:"component",name:s.link,icon:"Link",id:"580db61e-7939-4efe-914c-304b271998ec"}];var ao={Undo:MdUndo,Redo:MdRedo,Bold:MdFormatBold,Italic:MdFormatItalic,Underline:MdFormatUnderlined,Color:MdTextFormat,LeftAlign:MdFormatAlignLeft,RightAlign:MdFormatAlignRight,CenterAlign:MdFormatAlignCenter,UnOrderedList:MdFormatListBulleted,OrderedList:MdFormatListNumbered,IndentLess:MdFormatIndentDecrease,IndentMore:MdOutlineFormatIndentIncrease,RemoveFormat:MdFormatClear,StrikeThrough:MdStrikethroughS,CodeQuote:MdFormatQuote,DownArrow:MdArrowDropDown,Styling:MdTextFormat,Attach:MdAttachFile,Link:MdLink,Image:MdImage,Check:MdCheck,TextFields:MdTextFields,Edit:MdEdit,Close:MdClose},Ue=ao;var lo=({name:e,size:o=24,color:r,className:n})=>{let t=Ue[e];return t?jsx(t,{size:o,color:r,className:n}):(console.warn(`Icon "${e}" not found.`),null)},k=lo;var mo=({trigger:e,children:o,popUpDirection:r="top center"})=>{let n=useRef(null),t=()=>{n.current&&typeof n.current.close=="function"&&n.current.close();};return jsx(po,{ref:n,trigger:e,closeOnDocumentClick:true,repositionOnResize:true,position:r,className:"mail-inbox-popup",children:l=>o({close:()=>{l?.(),t();}})})},_=mo;var uo=[{label:"Sans Serif",value:"sans-serif",style:{fontFamily:"sans-serif"}},{label:"Serif",value:"serif",style:{fontFamily:"serif"}},{label:"Fixed Width",value:"monospace",style:{fontFamily:"monospace"}},{label:"Wide",value:"wide",style:{fontWeight:"bold",letterSpacing:"0.05em"}},{label:"Narrow",value:"narrow",style:{fontStretch:"condensed"}},{label:"Comic Sans MS",value:"Comic Sans MS",style:{fontFamily:"Comic Sans MS, cursive"}},{label:"Garamond",value:"Garamond",style:{fontFamily:"Garamond, serif"}},{label:"Georgia",value:"Georgia",style:{fontFamily:"Georgia, serif"}},{label:"Tahoma",value:"Tahoma",style:{fontFamily:"Tahoma, sans-serif"}},{label:"Trebuchet MS",value:"Trebuchet MS",style:{fontFamily:"Trebuchet MS, sans-serif"}},{label:"Verdana",value:"Verdana",style:{fontFamily:"Verdana, sans-serif"}}],oe=[{key:"small",label:"Small",sizePx:12},{key:"normal",label:"Normal",sizePx:18},{key:"large",label:"Large",sizePx:28},{key:"huge",label:"Huge",sizePx:56}],me=["#000000","#3a3a3a","#5a5a5a","#8a8a8a","#bfbfbf","#dedede","#f3f3f3","#ffffff"],fe=["#e53935","#fb8c00","#ffee58","#66ff66","#4dd0e1","#1e88e5","#9c27b0","#ff3bd6"],ue=[["#f7d7d7","#f3d0c8","#f0c5c5","#efc9d8","#f7e6e9","#f3edf7","#f0eaf6","#f8f0f6"],["#f0b9b9","#f0d4c2","#e6f0d2","#e4f7e8","#d8eef8","#dbe1ff","#e9d9f6","#f5d9f7"],["#e69a9a","#e6caa3","#d7e6b0","#c8f0e6","#bfe3ff","#cbd8ff","#d6c3f3","#f0c2f3"],["#d16464","#d09a6a","#a8cf7b","#7fd6c0","#73b7ff","#7a9cff","#b483f1","#f08cf2"],["#b23a3a","#b26a3a","#7aa04a","#3fb092","#296f94","#2a4177","#452a68","#6e1f4d"],["#7a1d1d","#7a4a1e","#556a2a","#195b47","#123f5a","#182840","#2a1836","#3a1026"]],ge=uo;function be({value:e="serif",onChange:o}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[ge?.find(r=>r.value===e)?.label,jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:ge.map(n=>jsx("button",{className:"btn-mail-editor",onClick:()=>{o(n.value),r();},style:{...n.style},children:jsxs("div",{className:"font-option",children:[e===n.value&&jsx(k,{name:"Check"}),n.label]})},n.value))})})})})}function he({value:e="normal",onChange:o=()=>{}}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"TextFields"}),jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:oe.map(n=>jsx("button",{className:"btn-mail-editor",onClick:()=>{o(n.key),r();},style:{fontSize:`${n.sizePx}px`},children:jsxs("div",{className:"font-option",children:[e===n.key&&jsx(k,{name:"Check"}),n.label]})},n.key))})})})})}function Y({color:e,selected:o,onClick:r,label:n}){return jsx("button",{className:"swatch",title:n||e,"aria-pressed":o,onClick:()=>r(e),style:{background:e},children:o&&jsx("svg",{className:"check",viewBox:"0 0 24 24","aria-hidden":true,children:jsx("path",{d:"M20 6L9 17l-5-5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}function xe({value:e={background:"#ffffff",text:"#000000"},onChange:o=()=>{}}){function r(n,t){o({...e,[n]:t});}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"Styling"}),jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"color-popover",role:"dialog","aria-label":"Choose colors",children:jsxs("div",{className:"color-columns",children:[jsxs("section",{className:"color-column","aria-labelledby":"bg-label",children:[jsx("h4",{id:"bg-label",children:"Background color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{r("background",i),n();},label:t},t+"bg"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{r("background",i),n();},label:t},t+"bgacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.background===l,onClick:d=>{r("background",d),n();},label:l},l+"bgp"+i))},"row"+i))})]}),jsxs("section",{className:"color-column","aria-labelledby":"text-label",children:[jsx("h4",{id:"text-label",children:"Text color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{r("text",i),n();},label:t},t+"tx"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{r("text",i),n();},label:t},t+"txacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.text===l,onClick:d=>{r("text",d),n();},label:l},l+"txp"+i))},"txrow"+i))})]})]})})})})}var Ge=[{key:"left",iconName:"LeftAlign",label:"Left align"},{key:"center",iconName:"CenterAlign",label:"Center align"},{key:"right",iconName:"RightAlign",label:"Right align"}];function ve({value:e="left",onChange:o=()=>{}}){function r(n){o(n);}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:Ge?.find(n=>n.key===e)?.iconName||"LeftAlign"}),jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"wrapper-alignment",children:Ge.map(t=>{let i=t.key===e;return jsxs("button",{role:"menuitemradio","aria-checked":i,tabIndex:0,className:`alignment-option ${i?"active":""}`,onClick:()=>{r(t.key),n();},children:[jsx("div",{className:"option-icon",children:jsx(k,{name:t.iconName,size:20})}),jsx("div",{className:`option-check ${i?"":"hidden"}`,"aria-hidden":true,children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",children:jsx("path",{d:"M20 6L9 17l-5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]},t.key)})})})})}var Oo=1;function Xe(e){if(!e||e.startsWith("#"))return e;if(e.startsWith("rgba")){let r=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)/);if(r){let[,n,t,i,l]=r;return l==="0"?"transparent":"#"+[n,t,i].map(d=>{let h=parseInt(d).toString(16);return h.length===1?"0"+h:h}).join("")}}let o=e.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(o){let[,r,n,t]=o;return "#"+[r,n,t].map(i=>{let l=parseInt(i).toString(16);return l.length===1?"0"+l:l}).join("")}return e}function Po(){let[e]=useLexicalComposerContext(),[o,r]=useState("paragraph"),[n,t]=useState({[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"}),[i,l]=useState(false),d=useCallback(()=>{let f=$getSelection(),b={[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"};if($isRangeSelection(f)){let F=f.anchor.getNode(),c=F.getKey()==="root"?F:F.getTopLevelElementOrThrow(),p=c.getKey(),g=e.getElementByKey(p);if(g!==null)if($isListNode(c)){let L=$getNearestNodeOfType(F,ListNode),ee=L?L.getTag():c.getTag();r(ee);}else {let L=c.getType();r(L);}b[s.bold]=f.hasFormat("bold"),b[s.italic]=f.hasFormat("italic"),b[s.underline]=f.hasFormat("underline"),b[s.strike]=f.hasFormat("strikethrough"),b[s.code]=f.hasFormat("code");let H=O(f),P=H.getParent();$isLinkNode(P)||$isLinkNode(H)?(b[s.link]=true,l(true)):(b[s.link]=false,l(false));let D=e.getElementByKey(H.getKey()),T=e.getElementByKey(P.getKey()),S=D||T||g;if(S){let L=window.getComputedStyle(S),ee=L.getPropertyValue("font-family");if(ee){let G=ee.split(",")[0].trim().replace(/['"]/g,"");(G==="-apple-system"||G==="BlinkMacSystemFont"||G==="system-ui")&&(G="sans-serif"),b[s.fontFamily]=G;}let Le=L.getPropertyValue("font-size");if(Le){let G=parseInt(Le,10);b[s.fontSize]=G||16;}let W=null,z=null;S instanceof HTMLElement&&S.style&&(W=S.style.color||null,z=S.style.backgroundColor||null),W||(W=L.getPropertyValue("color")),z||(z=L.getPropertyValue("background-color")),console.log("\u{1F3A8} Color detection:",{inlineColor:S instanceof HTMLElement?S.style.color:"N/A",inlineBg:S instanceof HTMLElement?S.style.backgroundColor:"N/A",computedColor:W,computedBg:z,element:S});let Te=W?Xe(W):null,Me=z&&z!=="rgba(0, 0, 0, 0)"&&z!=="transparent"?Xe(z):null;(Te||Me)&&(b[s.color.base]={text:Te||"#000000",background:Me||"#ffffff"});let pe=L.getPropertyValue("text-align")||"left";pe==="start"&&(pe="left"),b[s.align.base]=pe;}t(b);}},[e]);useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:f})=>{f.read(()=>{d();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(d(),false),Oo)),[e,d]);function h(f,b){switch(f){case s.bold:e.dispatchCommand(FORMAT_TEXT_COMMAND,"bold");break;case s.italic:e.dispatchCommand(FORMAT_TEXT_COMMAND,"italic");break;case s.underline:e.dispatchCommand(FORMAT_TEXT_COMMAND,"underline");break;case s.align.base:e.dispatchCommand(FORMAT_ELEMENT_COMMAND,b);break;case s.undo:e.dispatchCommand(UNDO_COMMAND,void 0);break;case s.redo:e.dispatchCommand(REDO_COMMAND,void 0);break;case s.listNumber:w();break;case s.listBullet:v();break;case s.indent:u();break;case s.indentDecrease:N();break;case s.color.base:m(b);break;case s.fontFamily:x(b);break;case s.fontSize:a(b);break;case s.link:E();break;}}let u=()=>{e.dispatchCommand(INDENT_CONTENT_COMMAND,void 0);},x=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"font-family":f});});},a=f=>{let b=oe.find(F=>F.key===f)?.sizePx??16;e.update(()=>{let F=$getSelection();$isRangeSelection(F)&&$patchStyleText(F,{"font-size":`${b}px`});});},m=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"background-color":f.background,color:f.text});});},E=useCallback(()=>{i?e.dispatchCommand(TOGGLE_LINK_COMMAND,null):e.dispatchCommand(TOGGLE_LINK_COMMAND,"https://");},[e,i]),N=()=>{e.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0);},v=()=>{o!=="ul"?e.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);},w=()=>{o!=="ol"?e.dispatchCommand(INSERT_ORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);};function O(f){let b=f.anchor,F=f.focus,c=f.anchor.getNode(),p=f.focus.getNode();return c===p?c:f.isBackward()?$isAtNodeEnd(F)?c:p:$isAtNodeEnd(b)?p:c}return {onChange:h,isLink:i,editor:e,selectedEventTypes:n,blockType:o}}var Qe=Po;function Do({editor:e}){let o=useRef(null),r=useRef(null),n=useRef(false),[t,i]=useState(""),[l,d]=useState(false),[h,u]=useState(null),x=useCallback(()=>{let a=window.getSelection(),m=$getSelection();if($isRangeSelection(m)){let w=zo(m),O=w.getParent();$isLinkNode(O)?i(O.getURL()):$isLinkNode(w)?i(w.getURL()):i("");}let E=o.current,N=document.activeElement;if(!E)return;let v=e.getRootElement();if(m&&a&&!a.isCollapsed&&v&&v.contains(a.anchorNode)){let w=a.getRangeAt(0),O;if(a.anchorNode===v){let f=v;for(;f.firstElementChild!=null;)f=f.firstElementChild;O=f.getBoundingClientRect();}else O=w.getBoundingClientRect();n.current||tt(E,O),u(m);}else (!N||N.className!=="link-input")&&(tt(E,null),u(null),d(false),i(""));return true},[e]);return useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:a})=>{a.read(()=>{x();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(x(),true),1)),[e,x]),useEffect(()=>{e.getEditorState().read(()=>{x();});},[e,x]),useEffect(()=>{l&&r.current&&r.current.focus();},[l]),jsxs("div",{className:"floating-link-editor",ref:o,children:[l?jsx("input",{ref:r,className:"link-input",value:t,onChange:a=>i(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),h&&t!==""&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(false)):a.key==="Escape"&&(a.preventDefault(),d(false));},placeholder:"Enter link..."}):jsx("div",{className:"link-display",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:t||"No link selected"})}),jsx("button",{className:"link-button",onMouseDown:a=>a.preventDefault(),onClick:()=>{console.log("floating link editor",l),l&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(a=>!a);},children:jsx(k,{name:l?"Check":"Edit"})})]})}function zo(e){let o=e.anchor.getNode(),r=e.focus.getNode();return o===r?o:e.isBackward()?$isAtNodeEnd(e.focus)?o:r:$isAtNodeEnd(e.anchor)?r:o}function tt(e,o){if(!o){e.style.opacity="0",e.style.top="-1000px",e.style.left="-1000px";return}let r=e.offsetWidth,n=e.offsetHeight,t=window.innerWidth,i=window.innerHeight,l=o.top+o.height+window.pageYOffset+10,d=o.left+window.pageXOffset-r/2+o.width/2;d<8&&(d=8),d+r>t-8&&(d=t-r-8),l+n>i-8&&(l=o.top+window.pageYOffset-n-10),l<8&&(l=8),e.style.opacity="1",e.style.top=`${l}px`,e.style.left=`${d}px`;}var ot=Do;var $={FILE_INVALID_TYPE:"file-invalid-type",FILE_TOO_LARGE:"file-too-large",TOO_MANY_FILES:"too-many-files",HEIC_CONVERSION_ERROR:"heic-conversion-error"},$o=10,Ho=10,it=()=>Math.random().toString(36).substring(2,10)+Date.now().toString(36),Go=e=>{if(e<1024)return {value:e.toString(),type:"bytes"};let o=e/1024;if(o<1024)return {value:o.toFixed(1),type:"KB"};let r=o/1024;return r<1024?{value:r.toFixed(1),type:"MB"}:{value:(r/1024).toFixed(1),type:"GB"}},at=({accept:e={"image/*":[".png",".gif",".jpeg",".jpg"],"application/pdf":[".pdf"]},maxSize:o=Ho*1024*1024,maxFiles:r=$o,multiple:n=true,isDisabled:t=false,replaceAfterUpload:i=false,files:l=[],handleFileChange:d=()=>{}})=>{let[h,u]=useState(false),[x,a]=useState(l??[]),[m,E]=useState([]),N=c=>{switch(c){case $.FILE_INVALID_TYPE:return "Invalid file type. Please upload a supported format.";case $.FILE_TOO_LARGE:{let{value:p,type:g}=Go(o);return `File too large. Maximum allowed size is ${p} ${g}.`}case $.TOO_MANY_FILES:return `Too many files selected. Maximum allowed: ${r}.`;case $.HEIC_CONVERSION_ERROR:return "Failed to convert HEIC image. Please upload a JPEG or PNG instead.";default:return "An unknown file error occurred."}};useEffect(()=>{d(x);},[x]);let{getRootProps:v,getInputProps:w,isDragActive:O,open:f}=useDropzone({accept:e,maxSize:o,multiple:n,maxFiles:r,disabled:t,noClick:true,onFileDialogCancel:()=>u(false),onFileDialogOpen:()=>{t||u(true);},onDrop:async(c,p)=>{let H=(await Promise.all(c.map(async P=>{if(!P)return null;if(P.type==="image/heic")try{let D=await Uo({blob:P,toType:"image/jpeg"}),T=Array.isArray(D)?D[0]:D,S=new File([T],`${P.name.replace(/\.heic$/i,"")}.jpeg`,{type:"image/jpeg"});return Object.assign(S,{uuid:it(),preview:URL.createObjectURL(S)})}catch(D){console.error("HEIC conversion error:",D);let T=N($.HEIC_CONVERSION_ERROR);return E(S=>[...S,{file:P,preview:URL.createObjectURL(P),readableErrors:[T],errors:[{code:$.HEIC_CONVERSION_ERROR,message:T}]}]),null}return Object.assign(P,{uuid:it(),preview:URL.createObjectURL(P)})}))).filter(Boolean);if(!t){let P=i?[]:[...x];P=[...P,...H];let D=p.map(T=>{let S=T.errors.map(L=>N(L.code));return {file:T.file,errors:T.errors.map(L=>({code:L.code,message:L.message})),preview:URL.createObjectURL(T.file),readableErrors:S}});return E(T=>[...T,...D]),a(P),P}return x},validator:c=>{let{name:p,type:g}=c;if(p){let H=p.split(".").pop()?.toLowerCase();if(e&&e?.[g]&&e?.[g].length&&!e?.[g].includes(`.${H}`))return {code:$.FILE_INVALID_TYPE,message:N($.FILE_INVALID_TYPE)}}return null}}),b=useCallback(c=>{a(p=>p.filter(g=>g.uuid!==c));},[a]),F=useCallback(()=>{E([]);},[]);return useEffect(()=>()=>{x.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview)),m.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview));},[]),{getRootProps:v,getInputProps:w,isDragActive:O,isFileDialogOpen:h,rejectedFiles:m,openFileDialog:f,removeFile:b,clearRejectedFiles:F}};var jo=({handleFileChange:e})=>{let{getRootProps:o,getInputProps:r,openFileDialog:n}=at({multiple:true,maxFiles:5,maxSize:5242880,handleFileChange:t=>{e(t);}});return jsx("div",{className:"uploader-container",children:jsxs("div",{...o(),children:[jsx("input",{...r()}),jsx("button",{onClick:n,children:jsx(k,{className:"upload-icon",name:"Attach"})})]})})},lt=jo;function Se({file:e,index:o,onRemove:r,onView:n}){if(!e)return null;let t=e?.name??"unknown",i=e instanceof File||"size"in e&&e.size!==void 0?e.size:"bytes"in e&&e.bytes!==void 0?e.bytes:null,l=("url"in e?e?.url:null)??null,d=useMemo(()=>{if(l)return l;if(typeof window<"u"&&e instanceof File)try{return URL.createObjectURL(e)}catch{return null}return null},[e,l]),h=a=>{if(!a&&a!==0)return "";let m=Math.round(a/1024);return m<1024?`${m}K`:`${Math.round(a/1024/1024*10)/10}M`},u=a=>{if(a.preventDefault(),n)return n(d??null);d&&window.open(d,"_blank","noopener");},x=a=>{r&&r(a);};return jsxs("div",{className:"fps-row",role:"group","aria-label":`Attachment ${t}`,children:[jsxs("div",{className:"fps-left",children:[jsx("a",{href:d??"#",className:"fps-filename",onClick:u,title:t,target:"_blank",rel:"noopener noreferrer",children:t}),i!=null&&jsxs("span",{className:"fps-size",children:["\xA0(",h(i),")"]})]}),jsx("button",{type:"button",className:"fps-close","aria-label":`Remove ${t}`,onClick:()=>x(o),children:"\xD7"})]})}var dt=(e,{onChange:o,state:r,setState:n,selectedEventTypes:t,blockType:i,setAttachments:l})=>{switch(e.name){case s.undo:case s.redo:case s.bold:case s.italic:case s.underline:case s.indentDecrease:case s.indent:case s.link:return jsx("button",{className:`tool-bar-button ${t?.[e.name]?"active-btn-toolbar":""}`,onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listNumber:return jsx("button",{className:i==="ol"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listBullet:return jsx("button",{className:i==="ul"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.attachFile:return jsx(lt,{value:r?.[e.name],handleFileChange:d=>{console.log("\u{1F680} ~ getToolbarComponent ~ e:",d),n(h=>({...h,[e.name]:d})),l(d);}});case s.fontFamily:return jsx(be,{value:t?.[e.name]||r?.[e.name],onChange:d=>{o(e.name,d);}});case s.fontSize:return jsx(he,{value:t?.[e.name]||r?.[e.name],onChange:d=>{o(e.name,d);}});case s.color.base:return jsx(xe,{value:t?.[e.name]||r?.[e.name],onChange:d=>{o(e.name,d);}});case s.align.base:return jsx(ve,{value:t?.[e.name]||r?.[e.name],onChange:d=>{o(e.name,d);}});}return e.type===y.divider?jsx("span",{className:"divider"}):"-"},Yo=(e,{setToggle:o,toggle:r,onChange:n,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})=>{switch(e.type){case y.divider:return jsx("div",{className:"divider"},`divider-${e.type}-${e.icon}`);case y.component:return dt(e,{onChange:n,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h});case y.styling:return jsxs("div",{className:"styling-toolbar",children:[r?jsx("div",{className:"styling-options",children:e.options?.length&&Array.isArray(e.options)?e.options?.map(u=>dt(u,{onChange:n,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})):null}):null,jsx("button",{onClick:()=>o(u=>!u),children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})})]},`divider-${e.type}-${e.icon}`);}return "-"};function qo({rightChildren:e,leftChildren:o}){let[r,n]=useState(true),[t,i]=useState({}),{setAttachments:l}=B(),{onChange:d,isLink:h,editor:u,selectedEventTypes:x,blockType:a}=Qe();return console.log("\u{1F680} ~ ToolBar ~ selectedEventTypes:",x),jsxs("div",{className:"toolbar-container",children:[t[s.attachFile]?.length?jsx("div",{className:"file-upload-container",children:t[s.attachFile]?.map((m,E)=>jsx(Se,{file:m,index:E,onRemove:N=>{i(v=>{let w=v[s.attachFile].filter((O,f)=>f!==N);return l(w),{...v,[s.attachFile]:w}});}},E))}):null,jsxs("div",{className:"toolbar-wrapper",children:[o,Be?.map(m=>Yo(m,{setToggle:n,state:t,setState:i,toggle:r,onChange:d,selectedEventTypes:x,blockType:a,setAttachments:l})),e,h?createPortal(jsx(ot,{editor:u}),document.body):null]})]})}var pt=qo;var Xo={ltr:"ltr",rtl:"rtl",placeholder:"editor-placeholder",paragraph:"editor-paragraph",quote:"editor-quote",heading:{h1:"editor-heading-h1",h2:"editor-heading-h2",h3:"editor-heading-h3",h4:"editor-heading-h4",h5:"editor-heading-h5"},list:{nested:{listitem:"editor-nested-listitem"},ol:"editor-list-ol",ul:"editor-list-ul",listitem:"editor-listitem"},image:"editor-image",link:"editor-link",text:{bold:"editor-text-bold",italic:"editor-text-italic",overflowed:"editor-text-overflowed",hashtag:"editor-text-hashtag",underline:"editor-text-underline",strikethrough:"editor-text-strikethrough",underlineStrikethrough:"editor-text-underlineStrikethrough",code:"editor-text-code"},code:"editor-code",codeHighlight:{atrule:"editor-tokenAttr",attr:"editor-tokenAttr",boolean:"editor-tokenProperty",builtin:"editor-tokenSelector",cdata:"editor-tokenComment",char:"editor-tokenSelector",class:"editor-tokenFunction","class-name":"editor-tokenFunction",comment:"editor-tokenComment",constant:"editor-tokenProperty",deleted:"editor-tokenProperty",doctype:"editor-tokenComment",entity:"editor-tokenOperator",function:"editor-tokenFunction",important:"editor-tokenVariable",inserted:"editor-tokenSelector",keyword:"editor-tokenAttr",namespace:"editor-tokenVariable",number:"editor-tokenProperty",operator:"editor-tokenOperator",prolog:"editor-tokenComment",property:"editor-tokenProperty",punctuation:"editor-tokenPunctuation",regex:"editor-tokenVariable",selector:"editor-tokenSelector",string:"editor-tokenSelector",symbol:"editor-tokenProperty",tag:"editor-tokenProperty",url:"editor-tokenOperator",variable:"editor-tokenVariable"}},mt=Xo;function tn({initialHTML:e}){let[o]=useLexicalComposerContext();return useEffect(()=>{o.update(()=>{let n=new DOMParser().parseFromString(e,"text/html"),t=$generateNodesFromDOM(o,n),i=$getRoot();i.clear(),i.append(...t);});},[o,e]),null}var ft=tn;function Pe({onChange:e}){let[o]=useLexicalComposerContext();return useEffect(()=>o.registerUpdateListener(({editorState:r})=>{r.read(()=>{let n=$generateHtmlFromNodes(o,null);e(n);});}),[o,e]),null}function xn(e){console.error(e);}function vn({placeholder:e="",initialHTML:o="",rightChildren:r,leftChildren:n,minHeight:t="",onChange:i,editorChildren:l,isEditorVisible:d=true}){return jsx("div",{className:"my-editor-wrapper",children:jsxs(LexicalComposer,{initialConfig:{namespace:"MyEditor",theme:mt,nodes:[LinkNode,ListNode,ListItemNode,AutoLinkNode],onError:xn},children:[d?jsx(RichTextPlugin,{contentEditable:jsx(ContentEditable,{style:{minHeight:t},className:"my-editor-content","aria-placeholder":e,placeholder:jsx("div",{className:"my-editor-placeholder",children:e})}),ErrorBoundary:LexicalErrorBoundary}):l,jsx(pt,{rightChildren:r,leftChildren:n}),jsx(HistoryPlugin,{}),jsx(ft,{initialHTML:o}),jsx(AutoFocusPlugin,{}),jsx(ListPlugin,{}),jsx(LinkPlugin,{}),i&&jsx(Pe,{onChange:i})]})})}var ut=vn;function X(e){return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Cn({emails:e=[],setEmails:o,fetchOptions:r}){let n=useRef(null),t=useRef(null),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(-1),[a,m]=useState([]),[E,N]=useState(false),v=useRef([]),w=useRef([]);useEffect(()=>{v.current=v.current.slice(0,e.length);},[e.length]),useEffect(()=>{w.current=w.current.slice(0,a.length);},[a.length]),useEffect(()=>{X(i)?(async()=>{N(true);try{let p=await r(i);m(p);}catch(p){console.error("Error fetching email options:",p),m([]);}finally{N(false);}})():(m([]),N(false));},[i,r]),useEffect(()=>{d||x(-1);},[d]),useEffect(()=>{u>=0&&u<w.current.length&&w.current[u]?.scrollIntoView({block:"nearest",behavior:"smooth"});},[u]);let O=()=>{t.current?.focus();},f=c=>{n.current?.close(),l(""),o(p=>[...p,c]),x(-1),requestAnimationFrame(()=>t.current?.focus());},b=c=>{if(d&&X(i)&&a.length>0){if(c.key==="ArrowDown"){c.preventDefault(),x(p=>p<a.length-1?p+1:p);return}if(c.key==="ArrowUp"){c.preventDefault(),x(p=>p>0?p-1:-1);return}if(c.key==="Enter"&&u>=0){c.preventDefault(),f(a[u]);return}if(c.key==="Escape"){c.preventDefault(),n.current?.close(),x(-1);return}}if(c.key==="Backspace"&&i===""){let p=e.length-1,g=v.current[p];g&&(g.focus(),c.preventDefault());}},F=c=>{o(p=>{let g=[...p];return g.splice(c,1),g}),requestAnimationFrame(()=>{let p=Math.min(Math.max(0,c-1),e.length-2),g=v.current[p];g?g.focus():O();});};return jsx(Fragment,{children:jsx(po,{ref:n,trigger:jsxs("div",{className:"container-receipts",children:[e?.length?jsx("div",{className:"emails-container",children:e.map((c,p)=>jsxs("div",{className:"emails",tabIndex:0,ref:g=>{v.current[p]=g;},onKeyDown:g=>{g.key==="Backspace"&&(g.preventDefault(),F(p)),g.key==="Enter"&&(g.preventDefault(),F(p),O());},role:"button","aria-label":`Email ${c.email}`,children:[jsx("span",{style:{marginRight:8},children:c.email}),jsx("button",{className:"emails-close",onClick:g=>{g.stopPropagation(),F(p);},"aria-label":`Remove ${c.email}`,children:jsx(k,{name:"Close"})})]},c.email??p))}):null,jsx("input",{ref:t,type:"text",className:"input-header",value:i,autoFocus:true,onKeyDown:b,onChange:c=>{let p=c.target.value;X(p)&&n.current?.open(),l(p);}})]}),closeOnDocumentClick:true,repositionOnResize:true,position:"bottom left",className:"mail-inbox-popup",onOpen:()=>{h(true),requestAnimationFrame(()=>t.current?.focus());},onClose:()=>{h(false);},children:X(i)?jsx("div",{className:"options-dropdown",children:E?jsx(Fragment,{children:[1,2,3].map(c=>jsxs("div",{className:"option-dropdown skeleton-loader",children:[jsx("div",{className:"skeleton-line skeleton-name"}),jsx("div",{className:"skeleton-line skeleton-email"})]},c))}):a.length>0?a.map((c,p)=>jsxs("button",{ref:g=>{w.current[p]=g;},className:`option-dropdown ${u===p?"selected":""}`,onBlur:g=>{g.stopPropagation();},onFocus:g=>{g.stopPropagation();},onMouseEnter:()=>x(p),onMouseLeave:()=>x(-1),onClick:g=>{g.stopPropagation(),f(c);},"aria-selected":u===p,children:[jsx("h4",{children:c.name}),c.email]},p)):null}):null})})}var bt=Cn;function wn({name:e,needCCAndBCC:o,setShowCC:r,setShowBCC:n,showBCC:t,showCC:i,emails:l,handleChange:d,fetchOptions:h}){return jsxs("div",{className:"container-receipts",children:[jsx("label",{className:"block text-sm font-medium text-gray-700",children:e}),jsx(bt,{emails:l,setEmails:d,fetchOptions:h}),o&&!i?jsx("button",{className:"btn-mail-editor",onClick:()=>r?.(u=>!u),children:"CC"}):null,o&&!t?jsx("button",{className:"btn-mail-editor",onClick:()=>n?.(u=>!u),children:"BCC"}):null]})}var de=wn;function Rn({fetchEmailOptions:e}){let[o,r]=useState(false),n=useRef(null),{emails:t,setEmails:i,showCC:l,setShowCC:d,showBCC:h,setShowBCC:u}=B();return useEffect(()=>{o&&(d(t.cc.length>0),u(t.bcc.length>0));},[o,t.cc.length,t.bcc.length]),useEffect(()=>{let a=n.current;if(!a)return;let m=()=>{r(true);},E=N=>{console.log("\u{1F680} ~ handleFocusOut ~ e:",N);let v=N.relatedTarget;v&&v.classList&&v.classList.contains("option-dropdown")||v&&a.contains(v)||(console.log("why this ",v?.classList),r(false));};return a.addEventListener("focusin",m),a.addEventListener("focusout",E),()=>{a.removeEventListener("focusin",m),a.removeEventListener("focusout",E);}},[]),jsx("div",{ref:n,tabIndex:-1,className:"relative",children:o?jsxs("div",{children:[jsx(de,{name:"To",needCCAndBCC:true,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.to,handleChange:a=>{i(m=>({...m,to:typeof a=="function"?a(m.to):a}));},fetchOptions:e}),l?jsx(de,{name:"CC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.cc,handleChange:a=>{i(m=>({...m,cc:typeof a=="function"?a(m.cc):a}));},fetchOptions:e}):null,h?jsx(de,{name:"BCC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.bcc,handleChange:a=>{i(m=>({...m,bcc:typeof a=="function"?a(m.bcc):a}));},fetchOptions:e}):null]}):jsx("input",{type:"text",placeholder:"Recipients",className:"input-header",value:(()=>{if(t.to.length===0&&t.cc.length===0&&t.bcc.length===0)return "Recipients";let a=[];return t.to.length>0&&a.push(t.to.map(m=>m.email).join(", ")),t.cc.length>0&&a.push(t.cc.map(m=>m.email).join(", ")),t.bcc.length>0&&a.push("bcc: "+t.bcc.map(m=>m.email).join(", ")),a.join(", ")})(),readOnly:true})})}var xt=Rn;function On({fetchEmailOptions:e}){let{subject:o,setSubject:r,isReply:n}=B();return jsxs("div",{className:"gmail-header",children:[jsx(xt,{fetchEmailOptions:e}),jsx("input",{type:"text",placeholder:"Subject",className:"input-header",value:n&&!o.startsWith("Re: ")?`Re: ${o}`:o,onChange:t=>r(t.target.value)})]})}var yt=On;function Ln({initialData:e,isReply:o,fetchEmailOptions:r,handleChange:n,leftChildren:t,rightChildren:i,editorChildren:l,isEditorVisible:d=true}){let{emails:h,subject:u,attachments:x,setEmails:a,setSubject:m,setAttachments:E,setIsReply:N}=B(),{theme:v}=te(),[w,O]=useState(e?.body||""),[f,b]=useState({to:e?.to||[],cc:e?.cc||[],bcc:e?.bcc||[],subject:e?.subject||"",body:e?.body||"",attachments:e?.attachments||[],isReply:o||false});useEffect(()=>{e&&((e.to||e.cc||e.bcc)&&a({to:e.to||[],cc:e.cc||[],bcc:e.bcc||[]}),e.subject&&m(e.subject),e.attachments&&E(e.attachments),e.body&&O(e.body)),o!==void 0&&N(o);},[]);let F=c=>{O(c);};return useEffect(()=>{b(c=>({...c,to:h.to,cc:h.cc,bcc:h.bcc}));},[h]),useEffect(()=>{b(c=>({...c,subject:u}));},[u]),useEffect(()=>{b(c=>({...c,body:w}));},[w]),useEffect(()=>{b(c=>({...c,attachments:x}));},[x]),useEffect(()=>{b(c=>({...c,isReply:o}));},[o]),useEffect(()=>{n(f);},[f,n]),jsxs("div",{className:"react-mail-inbox-root gmail-wrapper","data-theme":v,children:[t,jsx(yt,{fetchEmailOptions:r}),jsx(ut,{initialHTML:e?.body,onChange:F,editorChildren:l,isEditorVisible:d}),i]})}var wt=Ln;function Mn({fetchEmailOptions:e,handleChange:o,initialData:r,leftChildren:n,rightChildren:t,isReply:i}){return jsx(ze,{children:jsx(wt,{fetchEmailOptions:e,handleChange:o,initialData:r,isReply:i,leftChildren:n,rightChildren:t})})}var Nt=Mn;function An({fetchEmailOptions:e,handleChange:o,initialData:r,initialTheme:n="dark",onThemeChange:t,leftChildren:i,rightChildren:l}){return jsx(Ie,{initialTheme:n,onThemeChange:t,children:jsx(Nt,{fetchEmailOptions:e,handleChange:o,initialData:r,leftChildren:i,rightChildren:l})})}var Rt=An;var Ba=Rt;
|
|
2
2
|
export{Rt as GmailInbox,Ba as default,te as useTheme};//# sourceMappingURL=index.mjs.map
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|