@innoviatech/lexical-text-editor 1.0.3 → 1.0.4

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.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposer"),i=require("react"),n=require("@lexical/rich-text"),o=require("@lexical/code"),r=require("@lexical/react/LexicalRichTextPlugin"),s=require("@lexical/react/LexicalContentEditable"),a=require("@lexical/react/LexicalErrorBoundary"),l=require("@lexical/react/LexicalHistoryPlugin"),c=require("@lexical/react/LexicalListPlugin"),d=require("@lexical/list"),u=require("react-icons/rx"),h=require("react-icons/tb"),g=require("react-icons/bs"),p=require("react-icons/ai"),m=require("react-icons/io5"),x=require("react-icons/pi"),f=require("@lexical/react/LexicalComposerContext"),b=require("lexical"),v=require("@lexical/link"),N=require("@radix-ui/react-slot"),y=require("class-variance-authority"),j=require("clsx"),C=require("tailwind-merge"),w=require("@radix-ui/react-tooltip"),_=require("@radix-ui/react-popover"),k=require("react-icons/hi2"),T=require("react-icons/io"),A=require("lucide-react"),S=require("react-icons/ti"),E=require("react-color"),O=require("react-dom"),M=require("@radix-ui/react-dialog"),L=require("react-icons/fa"),D=require("react-icons/vsc"),R=require("@lexical/react/LexicalLinkPlugin"),$=require("@lexical/react/LexicalOnChangePlugin");function z(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,n.get?n:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var F,B,I=z(i),H=z(w),P=z(_),q=z(M);!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(F||(F={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(B||(B={}));const U=[{id:F.Lowercase,icon:e.jsx(u.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:F.Uppercase,icon:e.jsx(u.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:F.Capitalize,icon:e.jsx(u.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:F.Strikethrough,icon:e.jsx(p.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:F.Highlight,icon:e.jsx(x.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:F.Superscript,icon:e.jsx(g.BsSuperscript,{}),label:"Superscript"},{id:F.Subscript,icon:e.jsx(g.BsSubscript,{}),label:"Subscript"}],K=[{id:F.Bold,icon:e.jsx(h.TbBold,{}),label:"Bold"},{id:F.Italics,icon:e.jsx(h.TbItalic,{}),label:"Italics"},{id:F.Underline,icon:e.jsx(h.TbUnderline,{}),label:"Underline"},{id:F.Divider},{id:F.Quote,icon:e.jsx(g.BsChatSquareQuote,{}),label:"Quote"},{id:F.Code,icon:e.jsx(m.IoCodeSlashOutline,{}),label:"Code"}],W=[{id:F.Undo,icon:e.jsx(g.BsArrowCounterclockwise,{}),label:"Undo"},{id:F.Redo,icon:e.jsx(g.BsArrowClockwise,{}),label:"Redo"},{id:F.Divider}],J=[{id:F.LeftAlign,icon:e.jsx(g.BsJustifyLeft,{}),label:"Left Align"},{id:F.CenterAlign,icon:e.jsx(g.BsTextCenter,{}),label:"Center Align"},{id:F.RightAlign,icon:e.jsx(g.BsJustifyRight,{}),label:"Right Align"},{id:F.JustifyAlign,icon:e.jsx(g.BsJustify,{}),label:"Justify Align"}],X=[{id:"normal",label:"Normal",icon:e.jsx(g.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:e.jsx(g.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:e.jsx(g.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:e.jsx(g.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:e.jsx(g.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:e.jsx(g.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:e.jsx(g.BsTypeH6,{})}];function G(e,...t){const i=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of t)n.append("v",e);throw i.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${i.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Q=new Map;function V(e){let t=Q.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const i=e.split(";");for(const e of i)if(""!==e){const[i,n]=e.split(/:([^]+)/);i&&n&&(t[i.trim()]=n.trim())}return t}(e),Q.set(e,t)),t}function Y(e,t){(b.$isRangeSelection(e)?e.isCollapsed():b.$isTextNode(e)||b.$isElementNode(e))||G(280);const i=V(b.$isRangeSelection(e)?e.style:b.$isTextNode(e)?e.getStyle():e.getTextStyle()),n=Object.entries(t).reduce((t,[n,o])=>("function"==typeof o?t[n]=o(i[n],e):null===o?delete t[n]:t[n]=o,t),{...i}),o=function(e){let t="";for(const i in e)i&&(t+=`${i}: ${e[i]};`);return t}(n);b.$isRangeSelection(e)||b.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),Q.set(o,n)}function Z(e,t){if(b.$isRangeSelection(e)&&e.isCollapsed()){Y(e,t);const i=e.anchor.getNode();b.$isElementNode(i)&&i.isEmpty()&&Y(i,t)}!function(e){const t=b.$getSelection();if(!t)return;const i=new Map,n=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(b.$isRangeSelection(t))for(const e of b.$caretRangeFromSelection(t).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!b.$isTextNode(t)||!t.canHaveFormat())continue;const[i,o]=n(t);o!==i&&(b.$isTokenOrSegmented(t)||0===i&&o===t.getTextContentSize()?e(t):e(t.splitText(i,o)[0===i?0:1]))}b.$isRangeSelection(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:i}=e,{key:n,offset:o,type:r}=t;t.set(i.key,i.offset,i.type),i.set(n,o,r)}}(t)}(e=>{Y(e,t)})}function ee(e,t){const i=e.getFormatType(),n=e.getIndent();i!==t.getFormatType()&&t.setFormat(i),n!==t.getIndent()&&t.setIndent(n)}function te(e){return e.getNode().isAttached()}function ie(e){let t=e;for(;null!==t&&!b.$isRootOrShadowRoot(t);){const e=t.getLatest(),i=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=i}}function ne(e,t,i=null){const n=e.getStartEndPoints(),o=n?n[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),n=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),n.forEach(e=>r.append(e)),i&&(r=i.append(r)),void e.replace(r)}let a=null,l=[];for(let n=0;n<s;n++){const o=r[n];b.$isRootOrShadowRoot(o)?(oe(e,l,l.length,t,i),l=[],a=o):null===a||null!==a&&b.$hasAncestor(o,a)?l.push(o):(oe(e,l,l.length,t,i),l=[o])}oe(e,l,l.length,t,i)}function oe(e,t,i,n,o=null){if(0===t.length)return;const r=t[0],s=new Map,a=[];let l=b.$isElementNode(r)?r:r.getParentOrThrow();l.isInline()&&(l=l.getParentOrThrow());let c=!1;for(;null!==l;){const e=l.getPreviousSibling();if(null!==e){l=e,c=!0;break}if(l=l.getParentOrThrow(),b.$isRootOrShadowRoot(l))break}const d=new Set;for(let e=0;e<i;e++){const i=t[e];b.$isElementNode(i)&&0===i.getChildrenSize()&&d.add(i.getKey())}const u=new Set;for(let e=0;e<i;e++){const i=t[e];let o=i.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&b.$isLeafNode(i)&&!u.has(i.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=n();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),a.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),b.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),ie(o)}}else if(d.has(i.getKey())){b.$isElementNode(i)||G(179);const e=n();e.setFormat(i.getFormatType()),e.setIndent(i.getIndent()),a.push(e),i.remove(!0)}}if(null!==o)for(let e=0;e<a.length;e++){const t=a[e];o.append(t)}let h=null;if(b.$isRootOrShadowRoot(l))if(c)if(null!==o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t)}else{const e=l.getFirstChild();if(b.$isElementNode(e)&&(l=e),null===e)if(o)l.append(o);else for(let e=0;e<a.length;e++){const t=a[e];l.append(t),h=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<a.length;t++){const i=a[t];e.insertBefore(i),h=i}}else if(o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t),h=t}const g=b.$getPreviousSelection();b.$isRangeSelection(g)&&te(g.anchor)&&te(g.focus)?b.$setSelection(g.clone()):null!==h?h.selectEnd():e.dirty=!0}function re(e,t,i){const n=V(e.getStyle());return null!==n&&n[t]||i}function se(e,t,i=""){let n=null;const o=e.getNodes(),r=e.anchor,s=e.focus,a=e.isBackward(),l=a?s.offset:r.offset,c=a?s.getNode():r.getNode();if(b.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const i=V(e.style);if(null!==i&&t in i)return i[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==l||!r.is(c))&&b.$isTextNode(r)){const e=re(r,t,i);if(null===n)n=e;else if(n!==e){n="";break}}}return null===n?i:n}const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,le=ae&&"documentMode"in document?document.documentMode:null;function ce(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function de(...e){return C.twMerge(j.clsx(e))}ae&&"InputEvent"in window&&!le&&new window.InputEvent("input");const ue=y.cva("cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",toolbar:"bg-transparent hover:bg-slate-100/80 text-gray-600",toolbarActive:"bg-slate-100 text-gray-900 ",destructive:"bg-destructive text-white hover:bg-destructive/90",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-2",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}}),he=I.forwardRef(({className:t,variant:i,size:n,asChild:o=!1,...r},s)=>{const a=o?N.Slot:"button";return e.jsx(a,{"data-slot":"button",className:de(ue({variant:i,size:n,className:t})),ref:s,...r})});function ge({delayDuration:t=0,...i}){return e.jsx(H.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...i})}function pe({...t}){return e.jsx(ge,{children:e.jsx(H.Root,{"data-slot":"tooltip",...t})})}function me({...t}){return e.jsx(H.Trigger,{"data-slot":"tooltip-trigger",...t})}function xe({className:t,sideOffset:i=0,children:n,...o}){return e.jsx(H.Portal,{children:e.jsxs(H.Content,{"data-slot":"tooltip-content",sideOffset:i,className:de("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",t),...o,children:[n,e.jsx(H.Arrow,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function fe({...t}){return e.jsx(P.Root,{"data-slot":"popover",...t})}function be({...t}){return e.jsx(P.Trigger,{"data-slot":"popover-trigger",...t})}function ve({className:t,align:i="center",sideOffset:n=4,...o}){return e.jsx(P.Portal,{children:e.jsx(P.Content,{"data-slot":"popover-content",align:i,sideOffset:n,className:de("bg-[#ffffff] text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...o})})}function Ne({onAction:t,selectionMap:n}){const[o,r]=i.useState(!1);return e.jsxs(fe,{open:o,onOpenChange:e=>r(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",onClick:()=>r(!o),size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx("span",{children:"Aa"})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(o?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{className:"p-2 w-fit flex flex-col items-start gap-1",children:U.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ye(){return e.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function je({updateHeading:t,headingSelectionMap:n}){const o=X.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[130px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:X.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function Ce({className:t,type:i,...n}){return e.jsx("input",{type:i,"data-slot":"input",className:de("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",t),...n})}function we({linkUrl:t,setLinkUrl:n,onConfirm:o,onCancel:r,removeLink:s}){const[a,l]=i.useState(!1),c=i.useRef(null),d=i.useRef(null);return i.useEffect(()=>{"https://"===t&&l(!0)},[t]),i.useEffect(()=>{a&&d.current?.focus()},[a]),i.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]),e.jsxs("div",{ref:c,className:de("absolute z-[9999] bottom-[-50px] sm:bottom-[-60px] right-[20px]","bg-white shadow-lg rounded-xl px-1.5 py-1 sm:px-3 sm:py-2 flex items-center space-x-2","border border-gray-200"),children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:a?e.jsx(Ce,{ref:d,className:"h-8 text-sm",value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o(t),l(!1)):"Escape"===e.key&&(e.preventDefault(),l(!1),r())}}):e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 text-sm underline truncate block max-w-full text-start",children:t})}),e.jsxs("div",{children:[e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:()=>{a?(o(t),l(!1)):l(!0)},className:"h-8 w-8",children:a?e.jsx(A.Check,{className:"h-4 w-4"}):e.jsx(A.Pencil,{className:"h-4 w-4"})}),e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:s,className:"h-8 w-8",children:e.jsx(S.TiDeleteOutline,{className:"h-4 w-4"})})]})]})}function _e({onAction:t,alignmentSelectionMap:n}){const o=J.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[145px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:J.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ke({color:t,onChange:n,icon:o}){const[r,s]=i.useState(!1),a=i.useRef(null),l=i.useRef(null);i.useEffect(()=>{const e=e=>{l.current&&!l.current.contains(e.target)&&a.current&&!a.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return e.jsxs("div",{className:"relative inline-block",children:[e.jsx(he,{ref:a,variant:"ghost",size:"icon",className:"rounded-md text-gray-700 hover:bg-gray-200","aria-label":"Change Color",onClick:()=>s(e=>!e),children:o}),r&&O.createPortal(e.jsx("div",{ref:l,className:"\n absolute z-50 p-2 bg-transparent rounded-md select-none\n transition-all duration-200\n origin-top-left w-fit\n "+(r?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"),style:{top:a.current?.getBoundingClientRect().bottom,left:a.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e.jsx(E.SketchPicker,{color:t,onChangeComplete:e=>{n(e.hex)}})}),document.body)]})}function Te(){const[t]=f.useLexicalComposerContext(),[{color:n,bgColor:o},r]=i.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=se(e,"color","#000"),i=se(e,"background","#fff");r({color:t,bgColor:i})}};i.useEffect(()=>ce(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),t.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[t]);const a=({property:e,color:i})=>{t.update(()=>{const t=b.$getSelection();t&&Z(t,{[e]:i})})};return e.jsxs(e.Fragment,{children:[e.jsx(ke,{color:n,onChange:e=>{a({property:"color",color:e})},icon:e.jsx(p.AiOutlineFontColors,{})}),e.jsx(ke,{color:o,onChange:e=>{a({property:"background",color:e})},icon:e.jsx(p.AiOutlineBgColors,{})})]})}function Ae({blockType:t}){const[i]=f.useLexicalComposerContext();return e.jsxs(e.Fragment,{children:[e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ol"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add ordered list",onClick:()=>{"ol"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_ORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListOl,{})})}),e.jsx(xe,{side:"bottom",children:"Ordered list"})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ul"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add unordered list",onClick:()=>{"ul"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListUl,{})})}),e.jsx(xe,{side:"bottom",children:"Unordered list"})]})]})}he.displayName="Button";const Se=({src:t,altText:n,nodeKey:o,width:r,height:s,maxWidth:a})=>{const[l]=f.useLexicalComposerContext(),[c,d]=i.useState({width:"number"==typeof r?r:a,height:"number"==typeof s?s:"auto"}),u=i.useRef(null),h=i.useRef(null),g=e=>{if(!h.current)return;const t=e.clientX-h.current.x,i=Math.min(a,Math.max(50,h.current.width+t)),n=i/h.current.width*h.current.height||"auto";d({width:i,height:n})},p=()=>{h.current&&(l.update(()=>{const e=b.$getNodeByKey(o);e&&"function"==typeof e.updateDimensions&&e.updateDimensions(c.width,c.height)}),window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",p))};return e.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:a},children:[e.jsx("img",{src:t,alt:n,style:{width:c.width,height:c.height,maxWidth:"100%",display:"block"}}),e.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),h.current={x:e.clientX,y:e.clientY,width:c.width,height:u.current?.offsetHeight??0},window.addEventListener("mousemove",g),window.addEventListener("mouseup",p)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Ee=e=>b.$applyNodeReplacement(new Me(e)),Oe=e=>{if(e instanceof HTMLImageElement){const{src:t,alt:i}=e;return{node:Ee({src:t,altText:i})}}return null};class Me extends b.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:i=1080,width:n,height:o,key:r}={}){super(r),this.__altText=t,this.__src=e,this.__maxWidth=i,this.__height=o,this.__width=n}static getType(){return"image"}static clone(e){return new Me({altText:e.__altText,src:e.__src,height:e.__height,width:e.__width,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}exportDOM(){const e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__altText),this.__width&&"inherit"!==this.__width&&e.setAttribute("width",String(this.__width)),this.__height&&"inherit"!==this.__height&&e.setAttribute("height",String(this.__height)),{element:e}}static importDOM(){return{img:()=>({conversion:Oe,priority:0})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height}}static importJSON(e){return new Me({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const i=this.getWritable();i.__width=e,i.__height=t}updateDOM(){return!1}decorate(){return e.jsx(Se,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function Le({...t}){return e.jsx(q.Root,{"data-slot":"dialog",...t})}function De({...t}){return e.jsx(q.Trigger,{"data-slot":"dialog-trigger",...t})}function Re({...t}){return e.jsx(q.Portal,{"data-slot":"dialog-portal",...t})}function $e({className:t,...i}){return e.jsx(q.Overlay,{"data-slot":"dialog-overlay",className:de("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",t),...i})}function ze({className:t,children:i,showCloseButton:n=!0,...o}){return e.jsxs(Re,{"data-slot":"dialog-portal",children:[e.jsx($e,{}),e.jsxs(q.Content,{"data-slot":"dialog-content","aria-describedby":"",className:de("bg-[#ffffff] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",t),...o,children:[i,n&&e.jsxs(q.Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(A.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Fe({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-header",className:de("flex flex-col gap-2 text-center sm:text-left",t),...i})}function Be({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-footer",className:de("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...i})}function Ie({className:t,...i}){return e.jsx(q.Title,{"data-slot":"dialog-title",className:de("text-lg leading-none font-semibold",t),...i})}function He(){const[t,n]=i.useState(!1),[o,r]=i.useState(""),[s,a]=i.useState(""),[l,c]=i.useState(),d=i.useRef(null),[u]=f.useLexicalComposerContext();return e.jsxs("div",{children:[e.jsx("input",{type:"file",ref:d,accept:"image/*",className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&c(t),e.target.value=""}}),e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(m.IoImageOutline,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Add Image"})}),e.jsx("div",{className:"flex flex-col gap-4 py-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Alt text"}),e.jsx(Ce,{value:o,onChange:e=>r(e.target.value),placeholder:"Add Image by URL"}),e.jsxs("div",{className:"flex items-center w-full text-gray-500 text-sm",children:[e.jsx("div",{className:"flex-grow border-t border-gray-300"}),e.jsx("span",{className:"mx-2",children:"or"}),e.jsx("div",{className:"flex-grow border-t border-gray-300"})]}),e.jsxs("div",{className:"flex flex-col gap-2 w-fit",children:[e.jsxs(he,{variant:"outline",className:"flex items-center gap-2 bg-gray-50 hover:bg-gray-100",onClick:()=>d.current?.click(),children:[e.jsx(A.Upload,{className:"h-4 w-4"})," Upload Image"]}),l&&e.jsx("span",{className:"text-sm text-gray-600",children:l.name})]})]})}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{let e="";o&&(e=o),l&&(e=URL.createObjectURL(l)),u.update(()=>{const t=Ee({src:e,altText:s});b.$insertNodes([t])}),c(void 0),a(""),r(""),n(!1)},disabled:!o&&!l,className:"!bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Add Image"})})]})]})]})}const Pe=({id:e,provider:t})=>new Ge({id:e,provider:t}),qe="data-lexical-video",Ue="data-provider",Ke="315px",We="560px",Je=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,Xe=e=>{const t=e?.getAttribute(qe),i=e?.getAttribute(Ue)??"youtube";if(!t)return null;return{node:Pe({id:t,provider:i})}};class Ge extends b.DecoratorNode{constructor({id:e,provider:t,key:i}){super(i),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new Ge({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Pe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e.jsx("iframe",{height:Ke,width:We,src:Je(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(qe,this.__id),e.setAttribute(Ue,this.__provider),e.setAttribute("height",Ke),e.setAttribute("width",We),e.setAttribute("src",Je(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Xe,priority:0})}}}function Qe(){const[t,n]=i.useState(!1),[o,r]=i.useState(!1),[s,a]=i.useState(""),[l]=f.useLexicalComposerContext();return i.useEffect(()=>{t||(a(""),r(!1))},[t]),e.jsx("div",{children:e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(L.FaYoutube,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Embed Video"})}),e.jsxs("div",{className:"py-2",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Add YouTube or Google Drive URL"}),o&&e.jsx("p",{className:"mt-1.5 text-red-800/80 text-[0.8rem]",children:"It's not a valid youtube or google drive URL"})]}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{if(!s)return;let e=null,t=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);i&&11===i[2]?.length&&(e="youtube",t=i[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",t=o[1]),t&&e?(l.update(()=>{const i=Pe({id:t,provider:e});b.$insertNodes([i])}),a(""),r(!1),n(!1)):r(!0)},disabled:!s,className:"bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Embed"})})]})]})})}function Ve({value:t}){return e.jsx("div",{className:"prose max-w-none",dangerouslySetInnerHTML:{__html:t}})}function Ye({value:t,triggerLabel:n="Preview"}){const[o,r]=i.useState(!1);return e.jsxs(Le,{open:o,onOpenChange:r,children:[e.jsx(De,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx(D.VscPreview,{})," ",n]})}),e.jsxs(ze,{className:"w-[90vw] md:w-[80vw] lg:w-[70vw] max-w-4xl max-h-[90vh] sm:max-w-[1000px] overflow-y-auto bg-white",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-xl",children:"Content Preview"})}),e.jsxs("div",{className:" p-[2vw] rounded-lg border min-h-[400px] w-full text-start bg-white",children:[e.jsx("div",{className:"py-1 border-b-2 mb-4 font-medium",children:"CONTENT"}),e.jsx(Ve,{value:t})]})]})]})}const Ze=({value:t})=>{const[o]=f.useLexicalComposerContext(),[r,s]=i.useState({[F.Undo]:!0,[F.Redo]:!0}),[a,l]=i.useState(!1),[c,u]=i.useState({[F.LeftAlign]:!0}),[h,g]=i.useState({[B.Normal]:!0}),[p,m]=i.useState("paragraph"),[x,N]=i.useState("https://");let y=!0;const j=()=>{if(y){const e=o.getRootElement();e&&(e.scrollTop=0,y=!1)}const e=b.$getSelection();if(b.$isRangeSelection(e)){const t={[F.Bold]:e.hasFormat("bold"),[F.Italics]:e.hasFormat("italic"),[F.Underline]:e.hasFormat("underline"),[F.Uppercase]:e.hasFormat("uppercase"),[F.Lowercase]:e.hasFormat("lowercase"),[F.Capitalize]:e.hasFormat("capitalize"),[F.Strikethrough]:e.hasFormat("strikethrough"),[F.Superscript]:e.hasFormat("superscript"),[F.Subscript]:e.hasFormat("subscript"),[F.Code]:e.hasFormat("code"),[F.Highlight]:e.hasFormat("highlight")};u(t);const i=e.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),s=r.getKey();if(!o.getElementByKey(s))return;if(d.$isListNode(r)){const e=function(e,t){let i=e;for(;null!=i;){if(i instanceof t)return i;i=i.getParent()}return null}(i,d.ListNode),t=e?e.getTag():r.getTag();m(t)}else if("paragraph"===r.getType()||n.$isHeadingNode(r)){let e=null;n.$isHeadingNode(r)&&(e=r.getTag());const t={[B.H1]:"h1"===e,[B.H2]:"h2"===e,[B.H3]:"h3"===e,[B.H4]:"h4"===e,[B.H5]:"h5"===e,[B.H6]:"h6"===e,[B.Normal]:"paragraph"===r.getType()};g(t)}else m(r.getType());const a=(b.$isElementNode(i)?i:r).getFormat();u(e=>({...e,[F.LeftAlign]:0===a||1===a,[F.CenterAlign]:2===a,[F.RightAlign]:3===a,[F.JustifyAlign]:4===a})),"quote"===r.getType()?u(e=>({...e,[F.Quote]:!0})):u(e=>({...e,[F.Quote]:!1}));const c=e.anchor.getNode(),h=c.getParent();v.$isLinkNode(h)?(u(e=>({...e,[F.Link]:!0})),N(h.getURL()),l(!0)):v.$isLinkNode(c)?(u(e=>({...e,[F.Link]:!0})),N(c.getURL()),l(!0)):(u(e=>({...e,[F.Link]:!1})),N("https://"),l(!1))}};i.useEffect(()=>ce(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{j()})}),o.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(j(),!1),1),o.registerCommand(b.CAN_UNDO_COMMAND,e=>(s(t=>({...t,undo:!e})),!1),1),o.registerCommand(b.CAN_REDO_COMMAND,e=>(s(t=>({...t,redo:!e})),!1),1)),[]);const C=e=>{switch(e){case F.Bold:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"bold");break;case F.Italics:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"italic");break;case F.Underline:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"underline");break;case F.Lowercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"lowercase");break;case F.Uppercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"uppercase");break;case F.Capitalize:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"capitalize");break;case F.Strikethrough:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"strikethrough");break;case F.Superscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"superscript");break;case F.Subscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"subscript");break;case F.Highlight:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"highlight");break;case F.Code:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"code");break;case F.Quote:o.update(()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&n.$isQuoteNode(t)?function(e,t,i=ee){if(null===e)return;const n=e.getStartEndPoints(),o=new Map;let r=null;if(n){const[e,t]=n;r=b.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const i=b.$findMatchingParent(e.getNode(),b.INTERNAL_$isBlock),s=b.$findMatchingParent(t.getNode(),b.INTERNAL_$isBlock);b.$isElementNode(i)&&o.set(i.getKey(),i),b.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(b.$isElementNode(t)&&b.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===n){const e=b.$findMatchingParent(t,b.INTERNAL_$isBlock);b.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,n]of o){const o=t();i(n,o),n.replace(o,!0),r&&(e===r.anchor.key&&r.anchor.set(o.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(o.getKey(),r.focus.offset,r.focus.type))}r&&e.is(b.$getSelection())&&b.$setSelection(r)}(e,()=>b.$createParagraphNode()):ne(e,()=>n.$createQuoteNode())}});break;case F.Link:w(),l(!0);break;case F.LeftAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"left");break;case F.RightAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"right");break;case F.CenterAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"center");break;case F.JustifyAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"justify");break;case F.Undo:o.dispatchCommand(b.UNDO_COMMAND,void 0);break;case F.Redo:o.dispatchCommand(b.REDO_COMMAND,void 0)}},w=i.useCallback(()=>{console.log("insertlink"),a?o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null):""!==x&&o.dispatchCommand(v.TOGGLE_LINK_COMMAND,x)},[o,a]),_=i.useCallback(()=>{N(""),o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null),l(!1)},[o]);return e.jsxs("div",{className:"relative flex gap-1.5 flex-wrap justify-center items-center p-1.5 pb-2 mb-1 border-b-[1px]",children:[W.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(je,{updateHeading:e=>{o.update(()=>{const t=b.$getSelection();b.$isRangeSelection(t)&&ne(t,"normal"===e?()=>b.$createParagraphNode():()=>n.$createHeadingNode(e))})},headingSelectionMap:h}),e.jsx(ye,{})]}),K.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(Ae,{blockType:p}),e.jsx(ye,{})]}),e.jsx(Te,{}),e.jsx(Ne,{onAction:C,selectionMap:c}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(_e,{onAction:C,alignmentSelectionMap:c}),e.jsx(ye,{})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[F.Link]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(F.Link),disabled:!!r[F.Link],children:e.jsx(T.IoIosLink,{})})}),e.jsx(xe,{side:"bottom",children:"Link"})]}),a&&e.jsx(we,{linkUrl:x,setLinkUrl:N,removeLink:_,onConfirm:e=>{o.dispatchCommand(v.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),N(e),l(!1)},onCancel:()=>{N(""),l(!1)}}),e.jsx(He,{}),e.jsx(Qe,{}),e.jsx(Ye,{value:t})]})};function et(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const i=document.createElement("div"),n=b.$getRoot().getChildren();for(let o=0;o<n.length;o++)tt(e,n[o],i,t);return i.innerHTML}function tt(e,t,i,n=null){let o=null===n||t.isSelected(n);const r=b.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==n){let e=b.$cloneWithProperties(t);e=b.$isTextNode(e)&&null!==n?function(e,t){const i=e.getStartEndPoints();if(t.isSelected(e)&&!b.$isTokenOrSegmented(t)&&null!==i){const[n,o]=i,r=e.isBackward(),s=n.getNode(),a=o.getNode(),l=t.is(s),c=t.is(a);if(l||c){const[i,n]=b.$getCharacterOffsets(e),o=s.is(a),l=t.is(r?a:s),c=t.is(r?s:a);let d,u=0;o?(u=i>n?n:i,d=i>n?i:n):l?(u=r?n:i,d=void 0):c&&(u=0,d=r?i:n),t.__text=t.__text.slice(u,d)}}return t}(n,e):e,s=e}const a=b.$isElementNode(s)?s.getChildren():[],l=b.getRegisteredNode(e,s.getType());let c;c=l&&void 0!==l.exportDOM?l.exportDOM(e,s):s.exportDOM(e);const{element:d,after:u}=c;if(!d)return!1;const h=document.createDocumentFragment();for(let i=0;i<a.length;i++){const r=a[i],s=tt(e,r,h,n);!o&&b.$isElementNode(t)&&s&&t.extractWithChild(r,n,"html")&&(o=!0)}if(o&&!r){if((b.isHTMLElement(d)||b.isDocumentFragment(d))&&d.append(h),i.append(d),u){const e=u.call(s,d);e&&(b.isDocumentFragment(d)?d.replaceChildren(e):d.replaceWith(e))}}else i.append(h);return o}const it=new Set(["STYLE","SCRIPT"]);function nt(e,t,i,n,o=new Map,r){let s=[];if(it.has(e.nodeName))return s;let a=null;const l=function(e,t){const{nodeName:i}=e,n=t._htmlConversions.get(i.toLowerCase());let o=null;if(void 0!==n)for(const t of n){const i=t(e);null!==i&&(null===o||(o.priority||0)<=(i.priority||0))&&(o=i)}return null!==o?o.conversion:null}(e,t),c=l?l(e):null;let d=null;if(null!==c){d=c.after;const t=c.node;if(a=Array.isArray(t)?t[t.length-1]:t,null!==a){for(const[,e]of o)if(a=e(a,r),!a)break;a&&s.push(...Array.isArray(t)?t:[a])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const u=e.childNodes;let h=[];const g=(null==a||!b.$isRootOrShadowRoot(a))&&(null!=a&&b.$isBlockElementNode(a)||n);for(let e=0;e<u.length;e++)h.push(...nt(u[e],t,i,g,new Map(o),a));return null!=d&&(h=d(h)),b.isBlockDomNode(e)&&(h=function(e,t,i){const n=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(b.$isBlockElementNode(s))n&&!s.getFormat()&&s.setFormat(n),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&b.$isBlockElementNode(t[e+1])){const e=i();e.setFormat(n),e.append(...r),o.push(e),r=[]}}return o}(e,h,g?()=>{const e=new b.ArtificialNode__DO_NOT_USE;return i.push(e),e}:b.$createParagraphNode)),null==a?h.length>0?s=s.concat(h):b.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(b.isInlineDomNode(e.nextSibling)&&b.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(b.$createLineBreakNode())):b.$isElementNode(a)&&a.append(...h),s}function ot({value:t,onChange:n}){const[o]=f.useLexicalComposerContext(),[r,s]=i.useState(!0);return i.useEffect(()=>{t&&r&&(s(!1),o.update(()=>{if(et(o)!==t){b.$getRoot().clear();const e=(new DOMParser).parseFromString(t,"text/html"),i=function(e,t){const i=b.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let n=[];const o=[];for(const t of i)if(!it.has(t.nodeName)){const i=nt(t,e,o,!1);null!==i&&(n=n.concat(i))}return function(e){for(const t of e)t.getNextSibling()instanceof b.ArtificialNode__DO_NOT_USE&&t.insertAfter(b.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const i of e)t.insertBefore(i);t.remove()}}(o),n}(o,e);b.$insertNodes(i)}}))},[o,t,r]),i.useEffect(()=>{s(!0)},[t]),e.jsx($.OnChangePlugin,{onChange:e=>{e.read(()=>{n(et(o))})}})}const rt=({id:e})=>new ut({id:e}),st="data-lexical-youtube",at="315px",lt="560px",ct=e=>`https://www.youtube-nocookie.com/embed/${e}`,dt=e=>{const t=e?.getAttribute(st);if(!t)return null;return{node:rt({id:t})}};class ut extends b.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new ut({id:e.__id,key:e.getKey()})}static importJSON(e){return rt({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e.jsx("iframe",{height:at,width:lt,src:ct(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(st,this.__id),e.setAttribute("height",at),e.setAttribute("width",lt),e.setAttribute("src",ct(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:dt,priority:0})}}}const ht={text:{bold:"font-bold",underline:"underline",italic:"italic",strikethrough:"line-through",underlineStrikethrough:"underline line-through",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize",code:"bg-gray-100 border border-gray-300 px-1 rounded text-sm font-mono text-black"},paragraph:"mb-2",list:{ul:"list-disc list-inside pl-6",ol:"list-decimal list-inside pl-6",listitem:"mb-1"},quote:"border-l-4 border-gray-400 pl-4 italic text-gray-800 bg-gray-50 py-2 rounded-r",link:"text-blue-600 underline hover:text-blue-800"},gt=i.memo(function({name:u,value:h,onChange:g,placeholder:p,width:m=null,height:x=null}){const f=i.useMemo(()=>({namespace:u,theme:ht,onError:e=>{console.error("Lexical error:",e)},nodes:[n.HeadingNode,o.CodeHighlightNode,o.CodeNode,d.ListNode,d.ListItemNode,n.QuoteNode,v.LinkNode,Me,ut,Ge]}),[u]);return e.jsx("div",{className:"lexical-text-editor border-[1px] rounded-lg pb-2 scrollbar-thin",style:{width:m||"",maxWidth:m?"":"1090px"},children:e.jsxs(t.LexicalComposer,{initialConfig:f,children:[e.jsx("div",{className:"px-2",children:e.jsx(Ze,{value:h})}),e.jsx("div",{className:"relative",children:e.jsx(r.RichTextPlugin,{contentEditable:e.jsx(s.ContentEditable,{className:"text-start w-full text-[14px] p-[8px] overflow-auto outline-0",style:{height:x||"500px"}}),placeholder:e.jsx("div",{className:"absolute text-[#999] top-[8px] left-[10px] text-[14px]",children:p||"Some Text"}),ErrorBoundary:a.LexicalErrorBoundary})}),e.jsx(l.HistoryPlugin,{}),e.jsx(c.ListPlugin,{}),e.jsx(R.LinkPlugin,{}),e.jsx(ot,{value:h,onChange:g})]})})});exports.LexicalTextEditor=gt;
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposer"),i=require("react"),n=require("@lexical/rich-text"),o=require("@lexical/code"),r=require("@lexical/react/LexicalRichTextPlugin"),s=require("@lexical/react/LexicalContentEditable"),a=require("@lexical/react/LexicalErrorBoundary"),l=require("@lexical/react/LexicalHistoryPlugin"),c=require("@lexical/react/LexicalListPlugin"),d=require("@lexical/list"),u=require("react-icons/rx"),h=require("react-icons/tb"),g=require("react-icons/bs"),p=require("react-icons/ai"),m=require("react-icons/io5"),x=require("react-icons/pi"),f=require("@lexical/react/LexicalComposerContext"),b=require("lexical"),v=require("@lexical/link"),N=require("@radix-ui/react-slot"),y=require("class-variance-authority"),j=require("clsx"),C=require("tailwind-merge"),w=require("@radix-ui/react-tooltip"),_=require("@radix-ui/react-popover"),k=require("react-icons/hi2"),T=require("react-icons/io"),A=require("lucide-react"),S=require("react-icons/ti"),E=require("react-color"),O=require("react-dom"),M=require("@radix-ui/react-dialog"),L=require("react-icons/fa"),D=require("react-icons/vsc"),R=require("@lexical/react/LexicalLinkPlugin"),$=require("@lexical/react/LexicalOnChangePlugin");function z(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,n.get?n:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var F,B,I=z(i),H=z(w),P=z(_),q=z(M);!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(F||(F={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(B||(B={}));const U=[{id:F.Lowercase,icon:e.jsx(u.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:F.Uppercase,icon:e.jsx(u.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:F.Capitalize,icon:e.jsx(u.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:F.Strikethrough,icon:e.jsx(p.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:F.Highlight,icon:e.jsx(x.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:F.Superscript,icon:e.jsx(g.BsSuperscript,{}),label:"Superscript"},{id:F.Subscript,icon:e.jsx(g.BsSubscript,{}),label:"Subscript"}],K=[{id:F.Bold,icon:e.jsx(h.TbBold,{}),label:"Bold"},{id:F.Italics,icon:e.jsx(h.TbItalic,{}),label:"Italics"},{id:F.Underline,icon:e.jsx(h.TbUnderline,{}),label:"Underline"},{id:F.Divider},{id:F.Quote,icon:e.jsx(g.BsChatSquareQuote,{}),label:"Quote"},{id:F.Code,icon:e.jsx(m.IoCodeSlashOutline,{}),label:"Code"}],W=[{id:F.Undo,icon:e.jsx(g.BsArrowCounterclockwise,{}),label:"Undo"},{id:F.Redo,icon:e.jsx(g.BsArrowClockwise,{}),label:"Redo"},{id:F.Divider}],J=[{id:F.LeftAlign,icon:e.jsx(g.BsJustifyLeft,{}),label:"Left Align"},{id:F.CenterAlign,icon:e.jsx(g.BsTextCenter,{}),label:"Center Align"},{id:F.RightAlign,icon:e.jsx(g.BsJustifyRight,{}),label:"Right Align"},{id:F.JustifyAlign,icon:e.jsx(g.BsJustify,{}),label:"Justify Align"}],X=[{id:"normal",label:"Normal",icon:e.jsx(g.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:e.jsx(g.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:e.jsx(g.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:e.jsx(g.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:e.jsx(g.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:e.jsx(g.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:e.jsx(g.BsTypeH6,{})}];function G(e,...t){const i=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of t)n.append("v",e);throw i.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${i.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Q=new Map;function V(e){let t=Q.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const i=e.split(";");for(const e of i)if(""!==e){const[i,n]=e.split(/:([^]+)/);i&&n&&(t[i.trim()]=n.trim())}return t}(e),Q.set(e,t)),t}function Y(e,t){(b.$isRangeSelection(e)?e.isCollapsed():b.$isTextNode(e)||b.$isElementNode(e))||G(280);const i=V(b.$isRangeSelection(e)?e.style:b.$isTextNode(e)?e.getStyle():e.getTextStyle()),n=Object.entries(t).reduce((t,[n,o])=>("function"==typeof o?t[n]=o(i[n],e):null===o?delete t[n]:t[n]=o,t),{...i}),o=function(e){let t="";for(const i in e)i&&(t+=`${i}: ${e[i]};`);return t}(n);b.$isRangeSelection(e)||b.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),Q.set(o,n)}function Z(e,t){if(b.$isRangeSelection(e)&&e.isCollapsed()){Y(e,t);const i=e.anchor.getNode();b.$isElementNode(i)&&i.isEmpty()&&Y(i,t)}!function(e){const t=b.$getSelection();if(!t)return;const i=new Map,n=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(b.$isRangeSelection(t))for(const e of b.$caretRangeFromSelection(t).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!b.$isTextNode(t)||!t.canHaveFormat())continue;const[i,o]=n(t);o!==i&&(b.$isTokenOrSegmented(t)||0===i&&o===t.getTextContentSize()?e(t):e(t.splitText(i,o)[0===i?0:1]))}b.$isRangeSelection(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:i}=e,{key:n,offset:o,type:r}=t;t.set(i.key,i.offset,i.type),i.set(n,o,r)}}(t)}(e=>{Y(e,t)})}function ee(e,t){const i=e.getFormatType(),n=e.getIndent();i!==t.getFormatType()&&t.setFormat(i),n!==t.getIndent()&&t.setIndent(n)}function te(e){return e.getNode().isAttached()}function ie(e){let t=e;for(;null!==t&&!b.$isRootOrShadowRoot(t);){const e=t.getLatest(),i=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=i}}function ne(e,t,i=null){const n=e.getStartEndPoints(),o=n?n[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),n=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),n.forEach(e=>r.append(e)),i&&(r=i.append(r)),void e.replace(r)}let a=null,l=[];for(let n=0;n<s;n++){const o=r[n];b.$isRootOrShadowRoot(o)?(oe(e,l,l.length,t,i),l=[],a=o):null===a||null!==a&&b.$hasAncestor(o,a)?l.push(o):(oe(e,l,l.length,t,i),l=[o])}oe(e,l,l.length,t,i)}function oe(e,t,i,n,o=null){if(0===t.length)return;const r=t[0],s=new Map,a=[];let l=b.$isElementNode(r)?r:r.getParentOrThrow();l.isInline()&&(l=l.getParentOrThrow());let c=!1;for(;null!==l;){const e=l.getPreviousSibling();if(null!==e){l=e,c=!0;break}if(l=l.getParentOrThrow(),b.$isRootOrShadowRoot(l))break}const d=new Set;for(let e=0;e<i;e++){const i=t[e];b.$isElementNode(i)&&0===i.getChildrenSize()&&d.add(i.getKey())}const u=new Set;for(let e=0;e<i;e++){const i=t[e];let o=i.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&b.$isLeafNode(i)&&!u.has(i.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=n();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),a.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),b.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),ie(o)}}else if(d.has(i.getKey())){b.$isElementNode(i)||G(179);const e=n();e.setFormat(i.getFormatType()),e.setIndent(i.getIndent()),a.push(e),i.remove(!0)}}if(null!==o)for(let e=0;e<a.length;e++){const t=a[e];o.append(t)}let h=null;if(b.$isRootOrShadowRoot(l))if(c)if(null!==o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t)}else{const e=l.getFirstChild();if(b.$isElementNode(e)&&(l=e),null===e)if(o)l.append(o);else for(let e=0;e<a.length;e++){const t=a[e];l.append(t),h=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<a.length;t++){const i=a[t];e.insertBefore(i),h=i}}else if(o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t),h=t}const g=b.$getPreviousSelection();b.$isRangeSelection(g)&&te(g.anchor)&&te(g.focus)?b.$setSelection(g.clone()):null!==h?h.selectEnd():e.dirty=!0}function re(e,t,i){const n=V(e.getStyle());return null!==n&&n[t]||i}function se(e,t,i=""){let n=null;const o=e.getNodes(),r=e.anchor,s=e.focus,a=e.isBackward(),l=a?s.offset:r.offset,c=a?s.getNode():r.getNode();if(b.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const i=V(e.style);if(null!==i&&t in i)return i[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==l||!r.is(c))&&b.$isTextNode(r)){const e=re(r,t,i);if(null===n)n=e;else if(n!==e){n="";break}}}return null===n?i:n}const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,le=ae&&"documentMode"in document?document.documentMode:null;function ce(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function de(...e){return C.twMerge(j.clsx(e))}ae&&"InputEvent"in window&&!le&&new window.InputEvent("input");const ue=y.cva("cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",toolbar:"bg-transparent hover:bg-slate-100/80 text-gray-600",toolbarActive:"bg-slate-100 text-gray-900 ",destructive:"bg-destructive text-white hover:bg-destructive/90",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-2",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}}),he=I.forwardRef(({className:t,variant:i,size:n,asChild:o=!1,...r},s)=>{const a=o?N.Slot:"button";return e.jsx(a,{"data-slot":"button",className:de(ue({variant:i,size:n,className:t})),ref:s,...r})});function ge({delayDuration:t=0,...i}){return e.jsx(H.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...i})}function pe({...t}){return e.jsx(ge,{children:e.jsx(H.Root,{"data-slot":"tooltip",...t})})}function me({...t}){return e.jsx(H.Trigger,{"data-slot":"tooltip-trigger",...t})}function xe({className:t,sideOffset:i=0,children:n,...o}){return e.jsx(H.Portal,{children:e.jsxs(H.Content,{"data-slot":"tooltip-content",sideOffset:i,className:de("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",t),...o,children:[n,e.jsx(H.Arrow,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function fe({...t}){return e.jsx(P.Root,{"data-slot":"popover",...t})}function be({...t}){return e.jsx(P.Trigger,{"data-slot":"popover-trigger",...t})}function ve({className:t,align:i="center",sideOffset:n=4,...o}){return e.jsx(P.Portal,{children:e.jsx(P.Content,{"data-slot":"popover-content",align:i,sideOffset:n,className:de("bg-[#ffffff] text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...o})})}function Ne({onAction:t,selectionMap:n}){const[o,r]=i.useState(!1);return e.jsxs(fe,{open:o,onOpenChange:e=>r(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",onClick:()=>r(!o),size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx("span",{children:"Aa"})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(o?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{className:"p-2 w-fit flex flex-col items-start gap-1",children:U.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ye(){return e.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function je({updateHeading:t,headingSelectionMap:n}){const o=X.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[130px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:X.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function Ce({className:t,type:i,...n}){return e.jsx("input",{type:i,"data-slot":"input",className:de("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",t),...n})}function we({linkUrl:t,setLinkUrl:n,onConfirm:o,onCancel:r,removeLink:s}){const[a,l]=i.useState(!1),c=i.useRef(null),d=i.useRef(null);return i.useEffect(()=>{"https://"===t&&l(!0)},[t]),i.useEffect(()=>{a&&d.current?.focus()},[a]),i.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]),e.jsxs("div",{ref:c,className:de("absolute z-[9999] top-[100px] right-[20px]","bg-white shadow-lg rounded-xl px-1.5 py-1 sm:px-3 sm:py-2 flex items-center space-x-2","border border-gray-200"),children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:a?e.jsx(Ce,{ref:d,className:"h-8 text-sm",value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o(t),l(!1)):"Escape"===e.key&&(e.preventDefault(),l(!1),r())}}):e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 text-sm underline truncate block max-w-full text-start",children:t})}),e.jsxs("div",{children:[e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:()=>{a?(o(t),l(!1)):l(!0)},className:"h-8 w-8",children:a?e.jsx(A.Check,{className:"h-4 w-4"}):e.jsx(A.Pencil,{className:"h-4 w-4"})}),e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:s,className:"h-8 w-8",children:e.jsx(S.TiDeleteOutline,{className:"h-4 w-4"})})]})]})}function _e({onAction:t,alignmentSelectionMap:n}){const o=J.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[145px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:J.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ke({color:t,onChange:n,icon:o}){const[r,s]=i.useState(!1),a=i.useRef(null),l=i.useRef(null);i.useEffect(()=>{const e=e=>{l.current&&!l.current.contains(e.target)&&a.current&&!a.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return e.jsxs("div",{className:"relative inline-block",children:[e.jsx(he,{ref:a,variant:"ghost",size:"icon",className:"rounded-md text-gray-700 hover:bg-gray-200","aria-label":"Change Color",onClick:()=>s(e=>!e),children:o}),r&&O.createPortal(e.jsx("div",{ref:l,className:"\n absolute z-50 p-2 bg-transparent rounded-md select-none\n transition-all duration-200\n origin-top-left w-fit\n "+(r?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"),style:{top:a.current?.getBoundingClientRect().bottom,left:a.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e.jsx(E.SketchPicker,{color:t,onChangeComplete:e=>{n(e.hex)}})}),document.body)]})}function Te(){const[t]=f.useLexicalComposerContext(),[{color:n,bgColor:o},r]=i.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=se(e,"color","#000"),i=se(e,"background","#fff");r({color:t,bgColor:i})}};i.useEffect(()=>ce(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),t.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[t]);const a=({property:e,color:i})=>{t.update(()=>{const t=b.$getSelection();t&&Z(t,{[e]:i})})};return e.jsxs(e.Fragment,{children:[e.jsx(ke,{color:n,onChange:e=>{a({property:"color",color:e})},icon:e.jsx(p.AiOutlineFontColors,{})}),e.jsx(ke,{color:o,onChange:e=>{a({property:"background",color:e})},icon:e.jsx(p.AiOutlineBgColors,{})})]})}function Ae({blockType:t}){const[i]=f.useLexicalComposerContext();return e.jsxs(e.Fragment,{children:[e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ol"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add ordered list",onClick:()=>{"ol"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_ORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListOl,{})})}),e.jsx(xe,{side:"bottom",children:"Ordered list"})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ul"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add unordered list",onClick:()=>{"ul"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListUl,{})})}),e.jsx(xe,{side:"bottom",children:"Unordered list"})]})]})}he.displayName="Button";const Se=({src:t,altText:n,nodeKey:o,width:r,height:s,maxWidth:a})=>{const[l]=f.useLexicalComposerContext(),[c,d]=i.useState({width:"number"==typeof r?r:a,height:"number"==typeof s?s:"auto"}),u=i.useRef(null),h=i.useRef(null),g=e=>{if(!h.current)return;const t=e.clientX-h.current.x,i=Math.min(a,Math.max(50,h.current.width+t)),n=i/h.current.width*h.current.height||"auto";d({width:i,height:n})},p=()=>{h.current&&(l.update(()=>{const e=b.$getNodeByKey(o);e&&"function"==typeof e.updateDimensions&&e.updateDimensions(c.width,c.height)}),window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",p))};return e.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:a},children:[e.jsx("img",{src:t,alt:n,style:{width:c.width,height:c.height,maxWidth:"100%",display:"block"}}),e.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),h.current={x:e.clientX,y:e.clientY,width:c.width,height:u.current?.offsetHeight??0},window.addEventListener("mousemove",g),window.addEventListener("mouseup",p)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Ee=e=>b.$applyNodeReplacement(new Me(e)),Oe=e=>{if(e instanceof HTMLImageElement){const{src:t,alt:i}=e;return{node:Ee({src:t,altText:i})}}return null};class Me extends b.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:i=1080,width:n,height:o,key:r}={}){super(r),this.__altText=t,this.__src=e,this.__maxWidth=i,this.__height=o,this.__width=n}static getType(){return"image"}static clone(e){return new Me({altText:e.__altText,src:e.__src,height:e.__height,width:e.__width,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}exportDOM(){const e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__altText),this.__width&&"inherit"!==this.__width&&e.setAttribute("width",String(this.__width)),this.__height&&"inherit"!==this.__height&&e.setAttribute("height",String(this.__height)),{element:e}}static importDOM(){return{img:()=>({conversion:Oe,priority:0})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height}}static importJSON(e){return new Me({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const i=this.getWritable();i.__width=e,i.__height=t}updateDOM(){return!1}decorate(){return e.jsx(Se,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function Le({...t}){return e.jsx(q.Root,{"data-slot":"dialog",...t})}function De({...t}){return e.jsx(q.Trigger,{"data-slot":"dialog-trigger",...t})}function Re({...t}){return e.jsx(q.Portal,{"data-slot":"dialog-portal",...t})}function $e({className:t,...i}){return e.jsx(q.Overlay,{"data-slot":"dialog-overlay",className:de("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",t),...i})}function ze({className:t,children:i,showCloseButton:n=!0,...o}){return e.jsxs(Re,{"data-slot":"dialog-portal",children:[e.jsx($e,{}),e.jsxs(q.Content,{"data-slot":"dialog-content","aria-describedby":"",className:de("bg-[#ffffff] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",t),...o,children:[i,n&&e.jsxs(q.Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(A.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Fe({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-header",className:de("flex flex-col gap-2 text-center sm:text-left",t),...i})}function Be({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-footer",className:de("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...i})}function Ie({className:t,...i}){return e.jsx(q.Title,{"data-slot":"dialog-title",className:de("text-lg leading-none font-semibold",t),...i})}function He(){const[t,n]=i.useState(!1),[o,r]=i.useState(""),[s,a]=i.useState(""),[l,c]=i.useState(),d=i.useRef(null),[u]=f.useLexicalComposerContext();return e.jsxs("div",{children:[e.jsx("input",{type:"file",ref:d,accept:"image/*",className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&c(t),e.target.value=""}}),e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(m.IoImageOutline,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Add Image"})}),e.jsx("div",{className:"flex flex-col gap-4 py-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Alt text"}),e.jsx(Ce,{value:o,onChange:e=>r(e.target.value),placeholder:"Add Image by URL"}),e.jsxs("div",{className:"flex items-center w-full text-gray-500 text-sm",children:[e.jsx("div",{className:"flex-grow border-t border-gray-300"}),e.jsx("span",{className:"mx-2",children:"or"}),e.jsx("div",{className:"flex-grow border-t border-gray-300"})]}),e.jsxs("div",{className:"flex flex-col gap-2 w-fit",children:[e.jsxs(he,{variant:"outline",className:"flex items-center gap-2 bg-gray-50 hover:bg-gray-100",onClick:()=>d.current?.click(),children:[e.jsx(A.Upload,{className:"h-4 w-4"})," Upload Image"]}),l&&e.jsx("span",{className:"text-sm text-gray-600",children:l.name})]})]})}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{let e="";o&&(e=o),l&&(e=URL.createObjectURL(l)),u.update(()=>{const t=Ee({src:e,altText:s});b.$insertNodes([t])}),c(void 0),a(""),r(""),n(!1)},disabled:!o&&!l,className:"!bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Add Image"})})]})]})]})}const Pe=({id:e,provider:t})=>new Ge({id:e,provider:t}),qe="data-lexical-video",Ue="data-provider",Ke="315px",We="560px",Je=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,Xe=e=>{const t=e?.getAttribute(qe),i=e?.getAttribute(Ue)??"youtube";if(!t)return null;return{node:Pe({id:t,provider:i})}};class Ge extends b.DecoratorNode{constructor({id:e,provider:t,key:i}){super(i),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new Ge({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Pe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e.jsx("iframe",{height:Ke,width:We,src:Je(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(qe,this.__id),e.setAttribute(Ue,this.__provider),e.setAttribute("height",Ke),e.setAttribute("width",We),e.setAttribute("src",Je(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Xe,priority:0})}}}function Qe(){const[t,n]=i.useState(!1),[o,r]=i.useState(!1),[s,a]=i.useState(""),[l]=f.useLexicalComposerContext();return i.useEffect(()=>{t||(a(""),r(!1))},[t]),e.jsx("div",{children:e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(L.FaYoutube,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Embed Video"})}),e.jsxs("div",{className:"py-2",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Add YouTube or Google Drive URL"}),o&&e.jsx("p",{className:"mt-1.5 text-red-800/80 text-[0.8rem]",children:"It's not a valid youtube or google drive URL"})]}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{if(!s)return;let e=null,t=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);i&&11===i[2]?.length&&(e="youtube",t=i[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",t=o[1]),t&&e?(l.update(()=>{const i=Pe({id:t,provider:e});b.$insertNodes([i])}),a(""),r(!1),n(!1)):r(!0)},disabled:!s,className:"bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Embed"})})]})]})})}function Ve({value:t}){return e.jsx("div",{className:"prose max-w-none",dangerouslySetInnerHTML:{__html:t}})}function Ye({value:t,triggerLabel:n="Preview"}){const[o,r]=i.useState(!1);return e.jsxs(Le,{open:o,onOpenChange:r,children:[e.jsx(De,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx(D.VscPreview,{})," ",n]})}),e.jsxs(ze,{className:"w-[90vw] md:w-[80vw] lg:w-[70vw] max-w-4xl max-h-[90vh] sm:max-w-[1000px] overflow-y-auto bg-white",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-xl",children:"Content Preview"})}),e.jsxs("div",{className:" p-[2vw] rounded-lg border min-h-[400px] w-full text-start bg-white",children:[e.jsx("div",{className:"py-1 border-b-2 mb-4 font-medium",children:"CONTENT"}),e.jsx(Ve,{value:t})]})]})]})}const Ze=({value:t})=>{const[o]=f.useLexicalComposerContext(),[r,s]=i.useState({[F.Undo]:!0,[F.Redo]:!0}),[a,l]=i.useState(!1),[c,u]=i.useState({[F.LeftAlign]:!0}),[h,g]=i.useState({[B.Normal]:!0}),[p,m]=i.useState("paragraph"),[x,N]=i.useState("https://");let y=!0;const j=()=>{if(y){const e=o.getRootElement();e&&(e.scrollTop=0,y=!1)}const e=b.$getSelection();if(b.$isRangeSelection(e)){const t={[F.Bold]:e.hasFormat("bold"),[F.Italics]:e.hasFormat("italic"),[F.Underline]:e.hasFormat("underline"),[F.Uppercase]:e.hasFormat("uppercase"),[F.Lowercase]:e.hasFormat("lowercase"),[F.Capitalize]:e.hasFormat("capitalize"),[F.Strikethrough]:e.hasFormat("strikethrough"),[F.Superscript]:e.hasFormat("superscript"),[F.Subscript]:e.hasFormat("subscript"),[F.Code]:e.hasFormat("code"),[F.Highlight]:e.hasFormat("highlight")};u(t);const i=e.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),s=r.getKey();if(!o.getElementByKey(s))return;if(d.$isListNode(r)){const e=function(e,t){let i=e;for(;null!=i;){if(i instanceof t)return i;i=i.getParent()}return null}(i,d.ListNode),t=e?e.getTag():r.getTag();m(t)}else if("paragraph"===r.getType()||n.$isHeadingNode(r)){let e=null;n.$isHeadingNode(r)&&(e=r.getTag());const t={[B.H1]:"h1"===e,[B.H2]:"h2"===e,[B.H3]:"h3"===e,[B.H4]:"h4"===e,[B.H5]:"h5"===e,[B.H6]:"h6"===e,[B.Normal]:"paragraph"===r.getType()};g(t)}else m(r.getType());const a=(b.$isElementNode(i)?i:r).getFormat();u(e=>({...e,[F.LeftAlign]:0===a||1===a,[F.CenterAlign]:2===a,[F.RightAlign]:3===a,[F.JustifyAlign]:4===a})),"quote"===r.getType()?u(e=>({...e,[F.Quote]:!0})):u(e=>({...e,[F.Quote]:!1}));const c=e.anchor.getNode(),h=c.getParent();v.$isLinkNode(h)?(u(e=>({...e,[F.Link]:!0})),N(h.getURL()),l(!0)):v.$isLinkNode(c)?(u(e=>({...e,[F.Link]:!0})),N(c.getURL()),l(!0)):(u(e=>({...e,[F.Link]:!1})),N("https://"),l(!1))}};i.useEffect(()=>ce(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{j()})}),o.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(j(),!1),1),o.registerCommand(b.CAN_UNDO_COMMAND,e=>(s(t=>({...t,undo:!e})),!1),1),o.registerCommand(b.CAN_REDO_COMMAND,e=>(s(t=>({...t,redo:!e})),!1),1)),[]);const C=e=>{switch(e){case F.Bold:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"bold");break;case F.Italics:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"italic");break;case F.Underline:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"underline");break;case F.Lowercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"lowercase");break;case F.Uppercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"uppercase");break;case F.Capitalize:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"capitalize");break;case F.Strikethrough:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"strikethrough");break;case F.Superscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"superscript");break;case F.Subscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"subscript");break;case F.Highlight:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"highlight");break;case F.Code:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"code");break;case F.Quote:o.update(()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&n.$isQuoteNode(t)?function(e,t,i=ee){if(null===e)return;const n=e.getStartEndPoints(),o=new Map;let r=null;if(n){const[e,t]=n;r=b.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const i=b.$findMatchingParent(e.getNode(),b.INTERNAL_$isBlock),s=b.$findMatchingParent(t.getNode(),b.INTERNAL_$isBlock);b.$isElementNode(i)&&o.set(i.getKey(),i),b.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(b.$isElementNode(t)&&b.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===n){const e=b.$findMatchingParent(t,b.INTERNAL_$isBlock);b.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,n]of o){const o=t();i(n,o),n.replace(o,!0),r&&(e===r.anchor.key&&r.anchor.set(o.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(o.getKey(),r.focus.offset,r.focus.type))}r&&e.is(b.$getSelection())&&b.$setSelection(r)}(e,()=>b.$createParagraphNode()):ne(e,()=>n.$createQuoteNode())}});break;case F.Link:w(),l(!0);break;case F.LeftAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"left");break;case F.RightAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"right");break;case F.CenterAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"center");break;case F.JustifyAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"justify");break;case F.Undo:o.dispatchCommand(b.UNDO_COMMAND,void 0);break;case F.Redo:o.dispatchCommand(b.REDO_COMMAND,void 0)}},w=i.useCallback(()=>{console.log("insertlink"),a?o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null):""!==x&&o.dispatchCommand(v.TOGGLE_LINK_COMMAND,x)},[o,a]),_=i.useCallback(()=>{N(""),o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null),l(!1)},[o]);return e.jsxs("div",{className:"relative flex gap-1.5 flex-wrap justify-center items-center p-1.5 pb-2 mb-1 border-b-[1px]",children:[W.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(je,{updateHeading:e=>{o.update(()=>{const t=b.$getSelection();b.$isRangeSelection(t)&&ne(t,"normal"===e?()=>b.$createParagraphNode():()=>n.$createHeadingNode(e))})},headingSelectionMap:h}),e.jsx(ye,{})]}),K.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(Ae,{blockType:p}),e.jsx(ye,{})]}),e.jsx(Te,{}),e.jsx(Ne,{onAction:C,selectionMap:c}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(_e,{onAction:C,alignmentSelectionMap:c}),e.jsx(ye,{})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[F.Link]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(F.Link),disabled:!!r[F.Link],children:e.jsx(T.IoIosLink,{})})}),e.jsx(xe,{side:"bottom",children:"Link"})]}),a&&e.jsx(we,{linkUrl:x,setLinkUrl:N,removeLink:_,onConfirm:e=>{o.dispatchCommand(v.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),N(e),l(!1)},onCancel:()=>{N(""),l(!1)}}),e.jsx(He,{}),e.jsx(Qe,{}),e.jsx(Ye,{value:t})]})};function et(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const i=document.createElement("div"),n=b.$getRoot().getChildren();for(let o=0;o<n.length;o++)tt(e,n[o],i,t);return i.innerHTML}function tt(e,t,i,n=null){let o=null===n||t.isSelected(n);const r=b.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==n){let e=b.$cloneWithProperties(t);e=b.$isTextNode(e)&&null!==n?function(e,t){const i=e.getStartEndPoints();if(t.isSelected(e)&&!b.$isTokenOrSegmented(t)&&null!==i){const[n,o]=i,r=e.isBackward(),s=n.getNode(),a=o.getNode(),l=t.is(s),c=t.is(a);if(l||c){const[i,n]=b.$getCharacterOffsets(e),o=s.is(a),l=t.is(r?a:s),c=t.is(r?s:a);let d,u=0;o?(u=i>n?n:i,d=i>n?i:n):l?(u=r?n:i,d=void 0):c&&(u=0,d=r?i:n),t.__text=t.__text.slice(u,d)}}return t}(n,e):e,s=e}const a=b.$isElementNode(s)?s.getChildren():[],l=b.getRegisteredNode(e,s.getType());let c;c=l&&void 0!==l.exportDOM?l.exportDOM(e,s):s.exportDOM(e);const{element:d,after:u}=c;if(!d)return!1;const h=document.createDocumentFragment();for(let i=0;i<a.length;i++){const r=a[i],s=tt(e,r,h,n);!o&&b.$isElementNode(t)&&s&&t.extractWithChild(r,n,"html")&&(o=!0)}if(o&&!r){if((b.isHTMLElement(d)||b.isDocumentFragment(d))&&d.append(h),i.append(d),u){const e=u.call(s,d);e&&(b.isDocumentFragment(d)?d.replaceChildren(e):d.replaceWith(e))}}else i.append(h);return o}const it=new Set(["STYLE","SCRIPT"]);function nt(e,t,i,n,o=new Map,r){let s=[];if(it.has(e.nodeName))return s;let a=null;const l=function(e,t){const{nodeName:i}=e,n=t._htmlConversions.get(i.toLowerCase());let o=null;if(void 0!==n)for(const t of n){const i=t(e);null!==i&&(null===o||(o.priority||0)<=(i.priority||0))&&(o=i)}return null!==o?o.conversion:null}(e,t),c=l?l(e):null;let d=null;if(null!==c){d=c.after;const t=c.node;if(a=Array.isArray(t)?t[t.length-1]:t,null!==a){for(const[,e]of o)if(a=e(a,r),!a)break;a&&s.push(...Array.isArray(t)?t:[a])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const u=e.childNodes;let h=[];const g=(null==a||!b.$isRootOrShadowRoot(a))&&(null!=a&&b.$isBlockElementNode(a)||n);for(let e=0;e<u.length;e++)h.push(...nt(u[e],t,i,g,new Map(o),a));return null!=d&&(h=d(h)),b.isBlockDomNode(e)&&(h=function(e,t,i){const n=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(b.$isBlockElementNode(s))n&&!s.getFormat()&&s.setFormat(n),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&b.$isBlockElementNode(t[e+1])){const e=i();e.setFormat(n),e.append(...r),o.push(e),r=[]}}return o}(e,h,g?()=>{const e=new b.ArtificialNode__DO_NOT_USE;return i.push(e),e}:b.$createParagraphNode)),null==a?h.length>0?s=s.concat(h):b.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(b.isInlineDomNode(e.nextSibling)&&b.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(b.$createLineBreakNode())):b.$isElementNode(a)&&a.append(...h),s}function ot({value:t,onChange:n}){const[o]=f.useLexicalComposerContext(),[r,s]=i.useState(!0);return i.useEffect(()=>{t&&r&&(s(!1),o.update(()=>{if(et(o)!==t){b.$getRoot().clear();const e=(new DOMParser).parseFromString(t,"text/html"),i=function(e,t){const i=b.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let n=[];const o=[];for(const t of i)if(!it.has(t.nodeName)){const i=nt(t,e,o,!1);null!==i&&(n=n.concat(i))}return function(e){for(const t of e)t.getNextSibling()instanceof b.ArtificialNode__DO_NOT_USE&&t.insertAfter(b.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const i of e)t.insertBefore(i);t.remove()}}(o),n}(o,e);b.$insertNodes(i)}}))},[o,t,r]),i.useEffect(()=>{s(!0)},[t]),e.jsx($.OnChangePlugin,{onChange:e=>{e.read(()=>{n(et(o))})}})}const rt=({id:e})=>new ut({id:e}),st="data-lexical-youtube",at="315px",lt="560px",ct=e=>`https://www.youtube-nocookie.com/embed/${e}`,dt=e=>{const t=e?.getAttribute(st);if(!t)return null;return{node:rt({id:t})}};class ut extends b.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new ut({id:e.__id,key:e.getKey()})}static importJSON(e){return rt({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e.jsx("iframe",{height:at,width:lt,src:ct(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(st,this.__id),e.setAttribute("height",at),e.setAttribute("width",lt),e.setAttribute("src",ct(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:dt,priority:0})}}}const ht={text:{bold:"font-bold",underline:"underline",italic:"italic",strikethrough:"line-through",underlineStrikethrough:"underline line-through",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize",code:"bg-gray-100 border border-gray-300 px-1 rounded text-sm font-mono text-black"},paragraph:"mb-2",list:{ul:"list-disc list-inside pl-6",ol:"list-decimal list-inside pl-6",listitem:"mb-1"},quote:"border-l-4 border-gray-400 pl-4 italic text-gray-800 bg-gray-50 py-2 rounded-r",link:"text-blue-600 underline hover:text-blue-800"},gt=i.memo(function({name:u,value:h,onChange:g,placeholder:p}){const m=i.useMemo(()=>({namespace:u,theme:ht,onError:e=>{console.error("Lexical error:",e)},nodes:[n.HeadingNode,o.CodeHighlightNode,o.CodeNode,d.ListNode,d.ListItemNode,n.QuoteNode,v.LinkNode,Me,ut,Ge]}),[u]);return e.jsx("div",{className:"lexical-text-editor border-[1px] rounded-lg w-full max-w-[900px] pb-2 scrollbar-thin",children:e.jsxs(t.LexicalComposer,{initialConfig:m,children:[e.jsx("div",{className:"px-2",children:e.jsx(Ze,{value:h})}),e.jsx("div",{className:"relative",children:e.jsx(r.RichTextPlugin,{contentEditable:e.jsx(s.ContentEditable,{className:"h-[400px] text-start w-full text-[14px] p-[8px] overflow-auto outline-0"}),placeholder:e.jsx("div",{className:"absolute text-[#999] top-[8px] left-[10px] text-[14px]",children:p||"Some Text"}),ErrorBoundary:a.LexicalErrorBoundary})}),e.jsx(l.HistoryPlugin,{}),e.jsx(c.ListPlugin,{}),e.jsx(R.LinkPlugin,{}),e.jsx(ot,{value:h,onChange:g})]})})});exports.LexicalTextEditor=gt;
2
2
  //# sourceMappingURL=index.js.map