@innoviatech/lexical-text-editor 2.0.3 → 2.0.5

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,t,n=require("react/jsx-runtime"),i=require("@lexical/react/LexicalComposer"),o=require("react"),r=require("@lexical/rich-text"),s=require("@lexical/code"),l=require("@lexical/react/LexicalRichTextPlugin"),a=require("@lexical/react/LexicalContentEditable"),c=require("@lexical/react/LexicalErrorBoundary"),d=require("lexical"),u=require("@lexical/react/LexicalHistoryPlugin"),h=require("@lexical/react/LexicalListPlugin"),p=require("@lexical/list"),g=require("react-icons/rx"),m=require("react-icons/tb"),x=require("react-icons/bs"),f=require("react-icons/ai"),b=require("react-icons/io5"),N=require("react-icons/pi"),y=require("@lexical/react/LexicalComposerContext"),v=require("@lexical/link"),C=require("react-icons/hi2"),_=require("react-icons/io"),j=require("react-icons/md"),w=require("react-icons/bi"),k=require("react-color"),T=require("react-dom"),S=require("react-icons/lu"),E=require("react-icons/fa"),A=require("react-icons/vsc"),L=require("@lexical/react/LexicalLinkPlugin"),M=require("@lexical/react/LexicalOnChangePlugin");!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"}(e||(e={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(t||(t={}));const R=[{id:e.Lowercase,icon:n.jsx(g.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:e.Uppercase,icon:n.jsx(g.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:e.Capitalize,icon:n.jsx(g.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:e.Strikethrough,icon:n.jsx(f.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:e.Highlight,icon:n.jsx(N.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:e.Superscript,icon:n.jsx(x.BsSuperscript,{}),label:"Superscript"},{id:e.Subscript,icon:n.jsx(x.BsSubscript,{}),label:"Subscript"}],$=[{id:e.Bold,icon:n.jsx(m.TbBold,{}),label:"Bold"},{id:e.Italics,icon:n.jsx(m.TbItalic,{}),label:"Italics"},{id:e.Underline,icon:n.jsx(m.TbUnderline,{}),label:"Underline"},{id:e.Divider},{id:e.Quote,icon:n.jsx(x.BsChatSquareQuote,{}),label:"Quote"},{id:e.Code,icon:n.jsx(b.IoCodeSlashOutline,{}),label:"Code"}],O=[{id:e.Undo,icon:n.jsx(x.BsArrowCounterclockwise,{}),label:"Undo"},{id:e.Redo,icon:n.jsx(x.BsArrowClockwise,{}),label:"Redo"},{id:e.Divider}],D=[{id:e.LeftAlign,icon:n.jsx(x.BsJustifyLeft,{}),label:"Left Align"},{id:e.CenterAlign,icon:n.jsx(x.BsTextCenter,{}),label:"Center Align"},{id:e.RightAlign,icon:n.jsx(x.BsJustifyRight,{}),label:"Right Align"},{id:e.JustifyAlign,icon:n.jsx(x.BsJustify,{}),label:"Justify Align"}],F=[{id:"normal",label:"Normal",icon:n.jsx(x.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:n.jsx(x.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:n.jsx(x.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:n.jsx(x.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:n.jsx(x.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:n.jsx(x.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:n.jsx(x.BsTypeH6,{})}];function B(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const I=new Map;function H(e){let t=I.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,i]=e.split(/:([^]+)/);n&&i&&(t[n.trim()]=i.trim())}return t}(e),I.set(e,t)),t}function P(e,t){(d.$isRangeSelection(e)?e.isCollapsed():d.$isTextNode(e)||d.$isElementNode(e))||B(280);const n=H(d.$isRangeSelection(e)?e.style:d.$isTextNode(e)?e.getStyle():e.getTextStyle()),i=Object.entries(t).reduce((t,[i,o])=>("function"==typeof o?t[i]=o(n[i],e):null===o?delete t[i]:t[i]=o,t),{...n}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(i);d.$isRangeSelection(e)||d.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),I.set(o,i)}function U(e,t){if(d.$isRangeSelection(e)&&e.isCollapsed()){P(e,t);const n=e.anchor.getNode();d.$isElementNode(n)&&n.isEmpty()&&P(n,t)}!function(e){const t=d.$getSelection();if(!t)return;const n=new Map,i=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(d.$isRangeSelection(t))for(const e of d.$caretRangeFromSelection(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!d.$isTextNode(t)||!t.canHaveFormat())continue;const[n,o]=i(t);o!==n&&(d.$isTokenOrSegmented(t)||0===n&&o===t.getTextContentSize()?e(t):e(t.splitText(n,o)[0===n?0:1]))}d.$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:n}=e,{key:i,offset:o,type:r}=t;t.set(n.key,n.offset,n.type),n.set(i,o,r)}}(t)}(e=>{P(e,t)})}function q(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function z(e){return e.getNode().isAttached()}function K(e){let t=e;for(;null!==t&&!d.$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function W(e,t,n=null){const i=e.getStartEndPoints(),o=i?i[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(),i=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),i.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let l=null,a=[];for(let i=0;i<s;i++){const o=r[i];d.$isRootOrShadowRoot(o)?(J(e,a,a.length,t,n),a=[],l=o):null===l||null!==l&&d.$hasAncestor(o,l)?a.push(o):(J(e,a,a.length,t,n),a=[o])}J(e,a,a.length,t,n)}function J(e,t,n,i,o=null){if(0===t.length)return;const r=t[0],s=new Map,l=[];let a=d.$isElementNode(r)?r:r.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let c=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,c=!0;break}if(a=a.getParentOrThrow(),d.$isRootOrShadowRoot(a))break}const u=new Set;for(let e=0;e<n;e++){const n=t[e];d.$isElementNode(n)&&0===n.getChildrenSize()&&u.add(n.getKey())}const h=new Set;for(let e=0;e<n;e++){const n=t[e];let o=n.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&d.$isLeafNode(n)&&!h.has(n.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=i();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),l.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),h.add(e.getKey()),d.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>h.add(e))}),K(o)}}else if(u.has(n.getKey())){d.$isElementNode(n)||B(179);const e=i();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),l.push(e),n.remove(!0)}}if(null!==o)for(let e=0;e<l.length;e++){const t=l[e];o.append(t)}let p=null;if(d.$isRootOrShadowRoot(a))if(c)if(null!==o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(d.$isElementNode(e)&&(a=e),null===e)if(o)a.append(o);else for(let e=0;e<l.length;e++){const t=l[e];a.append(t),p=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<l.length;t++){const n=l[t];e.insertBefore(n),p=n}}else if(o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t),p=t}const g=d.$getPreviousSelection();d.$isRangeSelection(g)&&z(g.anchor)&&z(g.focus)?d.$setSelection(g.clone()):null!==p?p.selectEnd():e.dirty=!0}function X(e,t,n){const i=H(e.getStyle());return null!==i&&i[t]||n}function G(e,t,n=""){let i=null;const o=e.getNodes(),r=e.anchor,s=e.focus,l=e.isBackward(),a=l?s.offset:r.offset,c=l?s.getNode():r.getNode();if(d.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const n=H(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==a||!r.is(c))&&d.$isTextNode(r)){const e=X(r,t,n);if(null===i)i=e;else if(i!==e){i="";break}}}return null===i?n:i}const Q="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Y=Q&&"documentMode"in document?document.documentMode:null;function V(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Z({open:e,onOpenChange:t,children:i}){const r=o.useRef(null),s=o.useRef(null);return o.useEffect(()=>{function n(e){r.current?.contains(e.target)||s.current?.contains(e.target)||t(!1)}return e&&document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[e,t]),n.jsx("div",{className:"popover-root",children:o.Children.map(i,e=>e&&"object"==typeof e?e.type===ee?o.cloneElement(e,{triggerRef:r}):e.type===te?o.cloneElement(e,{contentRef:s}):e:e)})}function ee({children:e,triggerRef:t}){return n.jsx("div",{className:"popover-trigger",ref:t,children:e})}function te({open:e,align:t="start",children:i,contentRef:o}){return e?n.jsx("div",{ref:o,className:`popover-content align-${t}`,children:i}):null}function ne({onAction:e,selectionMap:t}){const[i,r]=o.useState(!1),s=o.useRef(null),l=o.useRef(null);return n.jsxs(Z,{open:i,onOpenChange:r,children:[n.jsx(ee,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx("span",{children:"Aa"}),n.jsx(C.HiChevronDown,{className:"chevron "+(i?"rotated":"")})]})}),n.jsx(te,{open:i,align:"start",onClose:()=>r(!1),contentRef:l,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:R.map(({id:i,label:o,icon:s})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),r(!1)},style:{minWidth:130},children:[s,n.jsx("span",{className:"label",children:o})]},i))})})]})}function ie(){return n.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function oe({updateHeading:e,headingSelectionMap:t}){const i=F.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return n.jsxs(Z,{open:r,onOpenChange:s,children:[n.jsx(ee,{triggerRef:l,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:132},children:[i?.icon,n.jsx("span",{children:i?.label}),n.jsx(C.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),n.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:F.map(({id:i,label:o,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),s(!1)},children:[r,n.jsx("span",{className:"label",children:o})]},i))})})]})}function re({linkUrl:e,setLinkUrl:t,onConfirm:i,onCancel:r,removeLink:s}){const[l,a]=o.useState(!1),c=o.useRef(null),d=o.useRef(null);return o.useEffect(()=>{"https://"===e&&a(!0)},[e]),o.useEffect(()=>{l&&d.current?.focus()},[l]),o.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]),n.jsxs("div",{ref:c,className:"lexical-text-editor-link link-editor-container",children:[n.jsx("div",{className:"link-editor-input-wrapper",children:l?n.jsx("input",{ref:d,className:"link-editor-input",value:e,onChange:e=>t(e.target.value),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),i(e),a(!1)):"Escape"===t.key&&(t.preventDefault(),a(!1),r())}}):n.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:e})}),n.jsxs("div",{className:"link-editor-buttons",children:[n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{l?(i(e),a(!1)):a(!0)},children:l?n.jsx(j.MdCheck,{size:18}):n.jsx(x.BsPencilSquare,{size:14})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:n.jsx(w.BiUnlink,{size:14,style:{stroke:"black"}})})]})]})}function se({onAction:e,alignmentSelectionMap:t}){const i=D.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return n.jsxs(Z,{open:r,onOpenChange:s,children:[n.jsx(ee,{triggerRef:l,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:146},children:[i?.icon,n.jsx("span",{children:i?.label}),n.jsx(C.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),n.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:D.map(({id:i,label:o,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),s(!1)},children:[r,n.jsx("span",{className:"label",children:o})]},i))})})]})}function le({color:e,onChange:t,icon:i}){const[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);o.useEffect(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&l.current&&!l.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return n.jsxs("div",{className:"color-picker-wrapper",children:[n.jsx("button",{type:"button",ref:l,className:`size-8 lexical-btn ${r?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:i}),r&&T.createPortal(n.jsx("div",{ref:a,className:"lexical-color-popover "+(r?"open":""),style:{top:l.current?.getBoundingClientRect().bottom,left:l.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:n.jsx(k.SketchPicker,{color:e,onChangeComplete:e=>{t(e.hex)}})}),document.body)]})}Q&&"InputEvent"in window&&!Y&&new window.InputEvent("input");const ae=({content:e,direction:t="top",delay:i=400,children:r})=>{const[s,l]=o.useState(!1),a=o.useRef(null);return n.jsxs("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{a.current=window.setTimeout(()=>{l(!0)},i)},onMouseLeave:()=>{a.current&&clearTimeout(a.current),l(!1)},children:[r,s&&n.jsx("div",{className:`Lexical-Tooltip-Tip ${t}`,children:e})]})};function ce(){const[e]=y.useLexicalComposerContext(),[{color:t,bgColor:i},r]=o.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=G(e,"color","#000"),n=G(e,"background","#fff");r({color:t,bgColor:n})}};o.useEffect(()=>V(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[e]);const l=({property:t,color:n})=>{e.update(()=>{const e=d.$getSelection();e&&U(e,{[t]:n})})};return n.jsxs(n.Fragment,{children:[n.jsx(ae,{content:"Font Color",direction:"bottom",children:n.jsx(le,{color:t,onChange:e=>{l({property:"color",color:e})},icon:n.jsx(f.AiOutlineFontColors,{})})}),n.jsx(ae,{content:"Background Color",direction:"bottom",children:n.jsx(le,{color:i,onChange:e=>{l({property:"background",color:e})},icon:n.jsx(f.AiOutlineBgColors,{})})})]})}function de({blockType:e}){const[t]=y.useLexicalComposerContext();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{content:"Ordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${"ol"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===e?t.dispatchCommand(p.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(p.INSERT_ORDERED_LIST_COMMAND,void 0)},children:n.jsx(x.BsListOl,{})})}),n.jsx(ae,{content:"Unordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${"ul"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===e?t.dispatchCommand(p.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(p.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:n.jsx(x.BsListUl,{})})})]})}const ue=({src:e,altText:t,nodeKey:i,width:r,height:s,maxWidth:l})=>{const[a]=y.useLexicalComposerContext(),c=o.useRef(null),u=o.useRef(null),h=o.useRef(null),p=e=>{if(!h.current||!c.current)return;const t=e.clientX-h.current.x,n=Math.min(l,Math.max(50,h.current.width+t)),i=n*c.current.ratio;c.current.width=n,c.current.height=i;const o=u.current?.querySelector("img");o&&(o.style.width=n+"px",o.style.height=i+"px")},g=()=>{if(!c.current)return;const{width:e,height:t}=c.current;a.update(()=>{const n=d.$getNodeByKey(i);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),c.current=null,h.current=null,window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",g)};return n.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:l},children:[n.jsx("img",{src:e,alt:t,width:"inherit"===r?void 0:r,height:"inherit"===s?void 0:s,style:{maxWidth:"100%",display:"block"}}),n.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=u.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,i=t.naturalHeight/t.naturalWidth,o=n*i;h.current={x:e.clientX,y:e.clientY,width:n,height:o},c.current={width:n,height:o,ratio:i},window.addEventListener("mousemove",p),window.addEventListener("mouseup",g)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},he=e=>d.$applyNodeReplacement(new ge(e)),pe=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let i,o;e.width&&(i=e.width),e.height&&(o=e.height);const r=e.style;if((!i||0===i)&&r.width){const e=parseInt(r.width,10);Number.isNaN(e)||(i=e)}if((!o||0===o)&&r.height){const e=parseInt(r.height,10);Number.isNaN(e)||(o=e)}return{node:he({src:t,altText:n,width:i??"inherit",height:o??"inherit"})}};class ge extends d.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:n=1080,width:i="inherit",height:o="inherit",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=i,this.__height=o}static getType(){return"image"}static clone(e){return new ge({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}exportDOM(){const e=document.createElement("img");return e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),{element:e}}static importDOM(){return{img:()=>({conversion:pe,priority:1})}}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 ge({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}decorate(){return n.jsx(ue,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function me({open:e,onClose:t,forPreview:i=!1,children:r}){const s=o.useRef(null);return o.useEffect(()=>{if(!e)return;const n=e=>{s.current&&!s.current.contains(e.target)&&t()},i=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",i)}},[e,t]),e?n.jsx("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:n.jsxs("div",{ref:s,className:"lte-dialog "+(i?"preview":""),children:[n.jsx("button",{type:"button",className:"lte-dialog-close",onClick:t,children:"×"}),r]})}):null}function xe(){const[e]=y.useLexicalComposerContext(),t=o.useRef(null),[i,r]=o.useState(!1),[s,l]=o.useState(""),[a,c]=o.useState(""),[u,h]=o.useState();return n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("input",{type:"file",ref:t,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&h(t),e.target.value=""}}),n.jsx("button",{type:"button",className:`size-8 lexical-btn ${i?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:n.jsx(b.IoImageOutline,{size:18})}),n.jsxs(me,{open:i,onClose:()=>r(!1),children:[n.jsx("div",{className:"lte-dialog-header",children:"Add Image"}),n.jsxs("div",{className:"lte-dialog-body",children:[n.jsx("input",{className:"lte-input",placeholder:"Alt text",value:a,onChange:e=>c(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Add image by URL",value:s,onChange:e=>l(e.target.value)}),n.jsx("div",{className:"lte-divider",children:n.jsx("span",{children:"or"})}),n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>t.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[n.jsx(S.LuUpload,{size:20}),n.jsx("span",{children:"Upload Image"})]}),u&&n.jsx("div",{className:"lte-file-name",children:u.name})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s&&!u,onClick:()=>{let t=s;u&&(t=URL.createObjectURL(u)),e.update(()=>{const e=he({src:t,altText:a});d.$insertNodes([e])}),h(void 0),c(""),l(""),r(!1)},children:"Add Image"})})]})]})}const fe=({id:e,provider:t})=>new je({id:e,provider:t}),be="data-lexical-video",Ne="data-provider",ye="315px",ve="560px",Ce=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,_e=e=>{const t=e?.getAttribute(be),n=e?.getAttribute(Ne)??"youtube";if(!t)return null;return{node:fe({id:t,provider:n})}};class je extends d.DecoratorNode{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new je({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return fe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return n.jsx("iframe",{height:ye,width:ve,src:Ce(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(be,this.__id),e.setAttribute(Ne,this.__provider),e.setAttribute("height",ye),e.setAttribute("width",ve),e.setAttribute("src",Ce(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:_e,priority:0})}}}function we(){const[e,t]=o.useState(!1),[i,r]=o.useState(!1),[s,l]=o.useState(""),[a]=y.useLexicalComposerContext();return o.useEffect(()=>{e||(l(""),r(!1))},[e]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("button",{type:"button",className:`size-8 lexical-btn ${e?"toolbarActive":"toolbar"} icon`,onClick:()=>t(!0),children:n.jsx(E.FaYoutube,{size:18,color:"red"})}),n.jsxs(me,{open:e,onClose:()=>t(!1),children:[n.jsx("div",{className:"lte-dialog-header",children:"Embed Video"}),n.jsxs("div",{className:"lte-dialog-body",children:[n.jsx("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:s,onChange:e=>l(e.target.value)}),i&&n.jsx("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s,onClick:()=>{if(!s)return;let e=null,n=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);i&&11===i[2]?.length&&(e="youtube",n=i[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",n=o[1]),n&&e?(a.update(()=>{const t=fe({id:n,provider:e});d.$insertNodes([t])}),l(""),r(!1),t(!1)):r(!0)},children:"Embed"})})]})]})}function ke({value:e}){return n.jsx("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:e}})}function Te({value:e,triggerLabel:t="Preview"}){const[i,r]=o.useState(!1);return console.log(e),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx(A.VscPreview,{size:18}),n.jsx("span",{children:t})]}),n.jsxs(me,{open:i,onClose:()=>r(!1),forPreview:!0,children:[n.jsx("div",{className:"lte-dialog-header",children:"Content Preview"}),n.jsxs("div",{className:"lte-preview-container",children:[n.jsx("div",{className:"lte-preview-title",children:"CONTENT"}),n.jsx(ke,{value:e})]})]})]})}const Se=({value:i})=>{const[s]=y.useLexicalComposerContext(),[l,a]=o.useState({[e.Undo]:!0,[e.Redo]:!0}),[c,u]=o.useState(!1),[h,g]=o.useState({[e.LeftAlign]:!0}),[m,x]=o.useState({[t.Normal]:!0}),[f,b]=o.useState("paragraph"),[N,C]=o.useState("https://");let j=!0;const w=()=>{if(j){const e=s.getRootElement();e&&(e.scrollTop=0,j=!1)}const n=d.$getSelection();if(d.$isRangeSelection(n)){const i={[e.Bold]:n.hasFormat("bold"),[e.Italics]:n.hasFormat("italic"),[e.Underline]:n.hasFormat("underline"),[e.Uppercase]:n.hasFormat("uppercase"),[e.Lowercase]:n.hasFormat("lowercase"),[e.Capitalize]:n.hasFormat("capitalize"),[e.Strikethrough]:n.hasFormat("strikethrough"),[e.Superscript]:n.hasFormat("superscript"),[e.Subscript]:n.hasFormat("subscript"),[e.Code]:n.hasFormat("code"),[e.Highlight]:n.hasFormat("highlight")};g(i);const o=n.anchor.getNode(),l="root"===o.getKey()?o:o.getTopLevelElementOrThrow(),a=l.getKey();if(!s.getElementByKey(a))return;if(p.$isListNode(l)){const e=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(o,p.ListNode),t=e?e.getTag():l.getTag();b(t)}else if("paragraph"===l.getType()||r.$isHeadingNode(l)){let e=null;r.$isHeadingNode(l)&&(e=l.getTag());const n={[t.H1]:"h1"===e,[t.H2]:"h2"===e,[t.H3]:"h3"===e,[t.H4]:"h4"===e,[t.H5]:"h5"===e,[t.H6]:"h6"===e,[t.Normal]:"paragraph"===l.getType()};b(l.getType()),x(n)}else b(l.getType());const c=(d.$isElementNode(o)?o:l).getFormat();g(t=>({...t,[e.LeftAlign]:0===c||1===c,[e.CenterAlign]:2===c,[e.RightAlign]:3===c,[e.JustifyAlign]:4===c})),"quote"===l.getType()?g(t=>({...t,[e.Quote]:!0})):g(t=>({...t,[e.Quote]:!1}));const h=n.anchor.getNode(),m=h.getParent();v.$isLinkNode(m)?(g(t=>({...t,[e.Link]:!0})),C(m.getURL()),u(!0)):v.$isLinkNode(h)?(g(t=>({...t,[e.Link]:!0})),C(h.getURL()),u(!0)):(g(t=>({...t,[e.Link]:!1})),C("https://"),u(!1))}};o.useEffect(()=>V(s.registerUpdateListener(({editorState:e})=>{e.read(()=>{w()})}),s.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(w(),!1),1),s.registerCommand(d.CAN_UNDO_COMMAND,e=>(a(t=>({...t,undo:!e})),!1),1),s.registerCommand(d.CAN_REDO_COMMAND,e=>(a(t=>({...t,redo:!e})),!1),1)),[]);const k=t=>{switch(t){case e.Bold:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"bold");break;case e.Italics:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"italic");break;case e.Underline:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"underline");break;case e.Lowercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"lowercase");break;case e.Uppercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"uppercase");break;case e.Capitalize:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"capitalize");break;case e.Strikethrough:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"strikethrough");break;case e.Superscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"superscript");break;case e.Subscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"subscript");break;case e.Highlight:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"highlight");break;case e.Code:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"code");break;case e.Quote:s.update(()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&r.$isQuoteNode(t)?function(e,t,n=q){if(null===e)return;const i=e.getStartEndPoints(),o=new Map;let r=null;if(i){const[e,t]=i;r=d.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const n=d.$findMatchingParent(e.getNode(),d.INTERNAL_$isBlock),s=d.$findMatchingParent(t.getNode(),d.INTERNAL_$isBlock);d.$isElementNode(n)&&o.set(n.getKey(),n),d.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(d.$isElementNode(t)&&d.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===i){const e=d.$findMatchingParent(t,d.INTERNAL_$isBlock);d.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,i]of o){const o=t();n(i,o),i.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(d.$getSelection())&&d.$setSelection(r)}(e,()=>d.$createParagraphNode()):W(e,()=>r.$createQuoteNode())}});break;case e.Link:T(),u(!0);break;case e.LeftAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"left");break;case e.RightAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"right");break;case e.CenterAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"center");break;case e.JustifyAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"justify");break;case e.Undo:s.dispatchCommand(d.UNDO_COMMAND,void 0);break;case e.Redo:s.dispatchCommand(d.REDO_COMMAND,void 0)}},T=o.useCallback(()=>{s.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&!e.isCollapsed()&&(c?s.dispatchCommand(v.TOGGLE_LINK_COMMAND,null):""!==N&&s.dispatchCommand(v.TOGGLE_LINK_COMMAND,N))})},[s,c,N]),S=o.useCallback(()=>{C(""),s.dispatchCommand(v.TOGGLE_LINK_COMMAND,null),u(!1)},[s]);return n.jsxs("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[O.map(({id:t,label:i,icon:o})=>t===e.Divider?n.jsx(ie,{},t):n.jsx(ae,{content:i,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),disabled:!!l[t],children:o})},i)),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(oe,{updateHeading:e=>{s.update(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&W(t,"normal"===e?()=>d.$createParagraphNode():()=>r.$createHeadingNode(e))})},headingSelectionMap:m}),n.jsx(ie,{})]}),$.map(({id:t,label:i,icon:o})=>t===e.Divider?n.jsx(ie,{},t):n.jsx(ae,{content:i,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),children:o})},t)),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(de,{blockType:f}),n.jsx(ie,{})]}),n.jsx(ce,{}),n.jsx(ne,{onAction:k,selectionMap:h}),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(se,{onAction:k,alignmentSelectionMap:h}),n.jsx(ie,{})]}),n.jsx(ae,{content:"Link",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[e.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(e.Link),disabled:!!l[e.Link],children:n.jsx(_.IoIosLink,{})})}),c&&n.jsx(re,{linkUrl:N,setLinkUrl:C,removeLink:S,onConfirm:e=>{s.dispatchCommand(v.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),C(e),u(!1)},onCancel:()=>{C(""),u(!1)}}),n.jsx(xe,{}),n.jsx(we,{}),n.jsx(Te,{value:i})]})};function Ee(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 n=document.createElement("div"),i=d.$getRoot().getChildren();for(let o=0;o<i.length;o++)Ae(e,i[o],n,t);return n.innerHTML}function Ae(e,t,n,i=null){let o=null===i||t.isSelected(i);const r=d.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==i){let e=d.$cloneWithProperties(t);e=d.$isTextNode(e)&&null!==i?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!d.$isTokenOrSegmented(t)&&null!==n){const[i,o]=n,r=e.isBackward(),s=i.getNode(),l=o.getNode(),a=t.is(s),c=t.is(l);if(a||c){const[n,i]=d.$getCharacterOffsets(e),o=s.is(l),a=t.is(r?l:s),c=t.is(r?s:l);let u,h=0;o?(h=n>i?i:n,u=n>i?n:i):a?(h=r?i:n,u=void 0):c&&(h=0,u=r?n:i),t.__text=t.__text.slice(h,u)}}return t}(i,e):e,s=e}const l=d.$isElementNode(s)?s.getChildren():[],a=d.getRegisteredNode(e,s.getType());let c;c=a&&void 0!==a.exportDOM?a.exportDOM(e,s):s.exportDOM(e);const{element:u,after:h}=c;if(!u)return!1;const p=document.createDocumentFragment();for(let n=0;n<l.length;n++){const r=l[n],s=Ae(e,r,p,i);!o&&d.$isElementNode(t)&&s&&t.extractWithChild(r,i,"html")&&(o=!0)}if(o&&!r){if((d.isHTMLElement(u)||d.isDocumentFragment(u))&&u.append(p),n.append(u),h){const e=h.call(s,u);e&&(d.isDocumentFragment(u)?u.replaceChildren(e):u.replaceWith(e))}}else n.append(p);return o}const Le=new Set(["STYLE","SCRIPT"]);function Me(e,t,n,i,o=new Map,r){let s=[];if(Le.has(e.nodeName))return s;let l=null;const a=function(e,t){const{nodeName:n}=e,i=t._htmlConversions.get(n.toLowerCase());let o=null;if(void 0!==i)for(const t of i){const n=t(e);null!==n&&(null===o||(o.priority||0)<=(n.priority||0))&&(o=n)}return null!==o?o.conversion:null}(e,t),c=a?a(e):null;let u=null;if(null!==c){u=c.after;const t=c.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of o)if(l=e(l,r),!l)break;l&&s.push(...Array.isArray(t)?t:[l])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const h=e.childNodes;let p=[];const g=(null==l||!d.$isRootOrShadowRoot(l))&&(null!=l&&d.$isBlockElementNode(l)||i);for(let e=0;e<h.length;e++)p.push(...Me(h[e],t,n,g,new Map(o),l));return null!=u&&(p=u(p)),d.isBlockDomNode(e)&&(p=function(e,t,n){const i=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(d.$isBlockElementNode(s))i&&!s.getFormat()&&s.setFormat(i),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&d.$isBlockElementNode(t[e+1])){const e=n();e.setFormat(i),e.append(...r),o.push(e),r=[]}}return o}(e,p,g?()=>{const e=new d.ArtificialNode__DO_NOT_USE;return n.push(e),e}:d.$createParagraphNode)),null==l?p.length>0?s=s.concat(p):d.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(d.isInlineDomNode(e.nextSibling)&&d.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(d.$createLineBreakNode())):d.$isElementNode(l)&&l.append(...p),s}function Re({value:e,onChange:t}){const[i]=y.useLexicalComposerContext(),[r,s]=o.useState(!0);return o.useEffect(()=>{e&&r&&(s(!1),i.update(()=>{if(Ee(i)!==e){d.$getRoot().clear();const t=(new DOMParser).parseFromString(e,"text/html"),n=function(e,t){const n=d.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let i=[];const o=[];for(const t of n)if(!Le.has(t.nodeName)){const n=Me(t,e,o,!1);null!==n&&(i=i.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof d.ArtificialNode__DO_NOT_USE&&t.insertAfter(d.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(o),i}(i,t);d.$insertNodes(n)}}))},[i,e,r]),o.useEffect(()=>{s(!0)},[e]),n.jsx(M.OnChangePlugin,{onChange:e=>{e.read(()=>{t(Ee(i))})}})}const $e=({id:e})=>new He({id:e}),Oe="data-lexical-youtube",De="315px",Fe="560px",Be=e=>`https://www.youtube-nocookie.com/embed/${e}`,Ie=e=>{const t=e?.getAttribute(Oe);if(!t)return null;return{node:$e({id:t})}};class He extends d.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new He({id:e.__id,key:e.getKey()})}static importJSON(e){return $e({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return n.jsx("iframe",{height:De,width:Fe,src:Be(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Oe,this.__id),e.setAttribute("height",De),e.setAttribute("width",Fe),e.setAttribute("src",Be(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Ie,priority:0})}}}class Pe extends d.TextNode{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new Pe(e.__text,e.__key)}static importDOM(){const e=d.TextNode.importDOM();return{...e,span:()=>({conversion:Ue(e?.span),priority:1}),div:()=>({conversion:Ue(e?.div),priority:1}),p:()=>({conversion:Ue(e?.p),priority:1}),b:()=>({conversion:Ue(e?.b),priority:1}),strong:()=>({conversion:Ue(e?.strong),priority:1}),i:()=>({conversion:Ue(e?.i),priority:1}),em:()=>({conversion:Ue(e?.em),priority:1}),u:()=>({conversion:Ue(e?.u),priority:1}),s:()=>({conversion:Ue(e?.s),priority:1}),strike:()=>({conversion:Ue(e?.strike),priority:1}),code:()=>({conversion:Ue(e?.code),priority:1})}}static importJSON(e){return function(e=""){return d.$applyNodeReplacement(new Pe(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Ue(e){return t=>{const n=e?.(t);if(!n)return null;const i=n.conversion(t);if(!i)return i;const o=t.style,r=[];o.backgroundColor&&r.push(`background-color: ${o.backgroundColor}`),o.color&&r.push(`color: ${o.color}`),o.fontFamily&&r.push(`font-family: ${o.fontFamily}`),o.fontWeight&&r.push(`font-weight: ${o.fontWeight}`),o.fontSize&&r.push(`font-size: ${o.fontSize}`),o.fontStyle&&r.push(`font-style: ${o.fontStyle}`),o.textDecoration&&r.push(`text-decoration: ${o.textDecoration}`),o.whiteSpace&&r.push(`white-space: ${o.whiteSpace}`),o.textAlign&&r.push(`text-align: ${o.textAlign}`);const s=t.getAttribute("style");if(s){s.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!r.some(e=>e.startsWith(t))&&r.push(e.trim())})}return{...i,forChild:(e,t)=>{const n=i?.forChild??(e=>e),o=n(e,t);if(d.$isTextNode(o)&&r.length>0){const e=r.join("; ");return o.setStyle(e)}return o}}}}const qe={text:{bold:"lexical-bold",underline:"lexical-underline",italic:"lexical-italic",strikethrough:"lexical-strikethrough",underlineStrikethrough:"lexical-underline-strikethrough",uppercase:"lexical-uppercase",lowercase:"lexical-lowercase",capitalize:"lexical-capitalize",code:"lexical-code"},paragraph:"lexical-paragraph",list:{ul:"lexical-list-ul",ol:"lexical-list-ol",listitem:"lexical-listitem"},quote:"lexical-quote",link:"lexical-link"},ze=o.memo(function({name:e,value:t,onChange:g,placeholder:m,maxWidth:x=null,height:f=null}){const b=o.useMemo(()=>({namespace:e,theme:qe,onError:e=>{console.error("Lexical error:",e)},nodes:[Pe,{replace:d.TextNode,with:e=>new Pe(e.__text),withKlass:Pe},r.HeadingNode,s.CodeHighlightNode,s.CodeNode,p.ListNode,p.ListItemNode,r.QuoteNode,v.LinkNode,ge,He,je]}),[e]);return n.jsx("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:x||"1090px"},children:n.jsxs(i.LexicalComposer,{initialConfig:b,children:[n.jsx("div",{className:"lexical-toolbar-container",children:n.jsx(Se,{value:t})}),n.jsx("div",{className:"lexical-editor-inner",children:n.jsx(l.RichTextPlugin,{contentEditable:n.jsx(a.ContentEditable,{className:"lexical-content-editable",style:{height:f||"500px"}}),placeholder:n.jsx("div",{className:"lexical-placeholder",children:m||"Some Text"}),ErrorBoundary:c.LexicalErrorBoundary})}),n.jsx(u.HistoryPlugin,{}),n.jsx(h.ListPlugin,{}),n.jsx(L.LinkPlugin,{}),n.jsx(Re,{value:t,onChange:g})]})})});exports.LexicalTextEditor=ze;
1
+ "use strict";var e,t,n=require("react/jsx-runtime"),i=require("@lexical/react/LexicalComposer"),o=require("react"),r=require("@lexical/rich-text"),s=require("@lexical/code"),l=require("@lexical/react/LexicalRichTextPlugin"),a=require("@lexical/react/LexicalContentEditable"),c=require("@lexical/react/LexicalErrorBoundary"),d=require("lexical"),u=require("@lexical/react/LexicalHistoryPlugin"),h=require("@lexical/react/LexicalListPlugin"),p=require("@lexical/list"),g=require("react-icons/rx"),m=require("react-icons/tb"),x=require("react-icons/bs"),f=require("react-icons/ai"),b=require("react-icons/io5"),N=require("react-icons/pi"),y=require("@lexical/react/LexicalComposerContext"),v=require("@lexical/link"),C=require("react-icons/hi2"),_=require("react-icons/io"),j=require("react-icons/md"),w=require("react-icons/bi"),k=require("react-color"),T=require("react-dom"),S=require("react-icons/lu"),E=require("react-icons/fa"),A=require("react-icons/vsc"),L=require("@lexical/react/LexicalLinkPlugin"),M=require("@lexical/react/LexicalOnChangePlugin");!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"}(e||(e={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(t||(t={}));const R=[{id:e.Lowercase,icon:n.jsx(g.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:e.Uppercase,icon:n.jsx(g.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:e.Capitalize,icon:n.jsx(g.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:e.Strikethrough,icon:n.jsx(f.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:e.Highlight,icon:n.jsx(N.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:e.Superscript,icon:n.jsx(x.BsSuperscript,{}),label:"Superscript"},{id:e.Subscript,icon:n.jsx(x.BsSubscript,{}),label:"Subscript"}],$=[{id:e.Bold,icon:n.jsx(m.TbBold,{}),label:"Bold"},{id:e.Italics,icon:n.jsx(m.TbItalic,{}),label:"Italics"},{id:e.Underline,icon:n.jsx(m.TbUnderline,{}),label:"Underline"},{id:e.Divider},{id:e.Quote,icon:n.jsx(x.BsChatSquareQuote,{}),label:"Quote"},{id:e.Code,icon:n.jsx(b.IoCodeSlashOutline,{}),label:"Code"}],O=[{id:e.Undo,icon:n.jsx(x.BsArrowCounterclockwise,{}),label:"Undo"},{id:e.Redo,icon:n.jsx(x.BsArrowClockwise,{}),label:"Redo"},{id:e.Divider}],D=[{id:e.LeftAlign,icon:n.jsx(x.BsJustifyLeft,{}),label:"Left Align"},{id:e.CenterAlign,icon:n.jsx(x.BsTextCenter,{}),label:"Center Align"},{id:e.RightAlign,icon:n.jsx(x.BsJustifyRight,{}),label:"Right Align"},{id:e.JustifyAlign,icon:n.jsx(x.BsJustify,{}),label:"Justify Align"}],F=[{id:"normal",label:"Normal",icon:n.jsx(x.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:n.jsx(x.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:n.jsx(x.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:n.jsx(x.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:n.jsx(x.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:n.jsx(x.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:n.jsx(x.BsTypeH6,{})}];function B(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const I=new Map;function H(e){let t=I.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,i]=e.split(/:([^]+)/);n&&i&&(t[n.trim()]=i.trim())}return t}(e),I.set(e,t)),t}function P(e,t){(d.$isRangeSelection(e)?e.isCollapsed():d.$isTextNode(e)||d.$isElementNode(e))||B(280);const n=H(d.$isRangeSelection(e)?e.style:d.$isTextNode(e)?e.getStyle():e.getTextStyle()),i=Object.entries(t).reduce((t,[i,o])=>("function"==typeof o?t[i]=o(n[i],e):null===o?delete t[i]:t[i]=o,t),{...n}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(i);d.$isRangeSelection(e)||d.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),I.set(o,i)}function U(e,t){if(d.$isRangeSelection(e)&&e.isCollapsed()){P(e,t);const n=e.anchor.getNode();d.$isElementNode(n)&&n.isEmpty()&&P(n,t)}!function(e){const t=d.$getSelection();if(!t)return;const n=new Map,i=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(d.$isRangeSelection(t))for(const e of d.$caretRangeFromSelection(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!d.$isTextNode(t)||!t.canHaveFormat())continue;const[n,o]=i(t);o!==n&&(d.$isTokenOrSegmented(t)||0===n&&o===t.getTextContentSize()?e(t):e(t.splitText(n,o)[0===n?0:1]))}d.$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:n}=e,{key:i,offset:o,type:r}=t;t.set(n.key,n.offset,n.type),n.set(i,o,r)}}(t)}(e=>{P(e,t)})}function q(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function z(e){return e.getNode().isAttached()}function K(e){let t=e;for(;null!==t&&!d.$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function W(e,t,n=null){const i=e.getStartEndPoints(),o=i?i[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(),i=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),i.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let l=null,a=[];for(let i=0;i<s;i++){const o=r[i];d.$isRootOrShadowRoot(o)?(J(e,a,a.length,t,n),a=[],l=o):null===l||null!==l&&d.$hasAncestor(o,l)?a.push(o):(J(e,a,a.length,t,n),a=[o])}J(e,a,a.length,t,n)}function J(e,t,n,i,o=null){if(0===t.length)return;const r=t[0],s=new Map,l=[];let a=d.$isElementNode(r)?r:r.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let c=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,c=!0;break}if(a=a.getParentOrThrow(),d.$isRootOrShadowRoot(a))break}const u=new Set;for(let e=0;e<n;e++){const n=t[e];d.$isElementNode(n)&&0===n.getChildrenSize()&&u.add(n.getKey())}const h=new Set;for(let e=0;e<n;e++){const n=t[e];let o=n.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&d.$isLeafNode(n)&&!h.has(n.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=i();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),l.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),h.add(e.getKey()),d.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>h.add(e))}),K(o)}}else if(u.has(n.getKey())){d.$isElementNode(n)||B(179);const e=i();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),l.push(e),n.remove(!0)}}if(null!==o)for(let e=0;e<l.length;e++){const t=l[e];o.append(t)}let p=null;if(d.$isRootOrShadowRoot(a))if(c)if(null!==o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(d.$isElementNode(e)&&(a=e),null===e)if(o)a.append(o);else for(let e=0;e<l.length;e++){const t=l[e];a.append(t),p=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<l.length;t++){const n=l[t];e.insertBefore(n),p=n}}else if(o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t),p=t}const g=d.$getPreviousSelection();d.$isRangeSelection(g)&&z(g.anchor)&&z(g.focus)?d.$setSelection(g.clone()):null!==p?p.selectEnd():e.dirty=!0}function X(e,t,n){const i=H(e.getStyle());return null!==i&&i[t]||n}function G(e,t,n=""){let i=null;const o=e.getNodes(),r=e.anchor,s=e.focus,l=e.isBackward(),a=l?s.offset:r.offset,c=l?s.getNode():r.getNode();if(d.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const n=H(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==a||!r.is(c))&&d.$isTextNode(r)){const e=X(r,t,n);if(null===i)i=e;else if(i!==e){i="";break}}}return null===i?n:i}const Q="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Y=Q&&"documentMode"in document?document.documentMode:null;function V(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Z({open:e,onOpenChange:t,children:i}){const r=o.useRef(null),s=o.useRef(null);return o.useEffect(()=>{function n(e){r.current?.contains(e.target)||s.current?.contains(e.target)||t(!1)}return e&&document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[e,t]),n.jsx("div",{className:"popover-root",children:o.Children.map(i,e=>e&&"object"==typeof e?e.type===ee?o.cloneElement(e,{triggerRef:r}):e.type===te?o.cloneElement(e,{contentRef:s}):e:e)})}function ee({children:e,triggerRef:t}){return n.jsx("div",{className:"popover-trigger",ref:t,children:e})}function te({open:e,align:t="start",children:i,contentRef:o}){return e?n.jsx("div",{ref:o,className:`popover-content align-${t}`,children:i}):null}function ne({onAction:e,selectionMap:t}){const[i,r]=o.useState(!1),s=o.useRef(null),l=o.useRef(null);return n.jsxs(Z,{open:i,onOpenChange:r,children:[n.jsx(ee,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx("span",{children:"Aa"}),n.jsx(C.HiChevronDown,{className:"chevron "+(i?"rotated":"")})]})}),n.jsx(te,{open:i,align:"start",onClose:()=>r(!1),contentRef:l,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:R.map(({id:i,label:o,icon:s})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),r(!1)},style:{minWidth:130},children:[s,n.jsx("span",{className:"label",children:o})]},i))})})]})}function ie(){return n.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function oe({updateHeading:e,headingSelectionMap:t}){const i=F.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return n.jsxs(Z,{open:r,onOpenChange:s,children:[n.jsx(ee,{triggerRef:l,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:132},children:[i?.icon,n.jsx("span",{children:i?.label}),n.jsx(C.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),n.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:F.map(({id:i,label:o,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),s(!1)},children:[r,n.jsx("span",{className:"label",children:o})]},i))})})]})}function re({linkUrl:e,setLinkUrl:t,onConfirm:i,onCancel:r,removeLink:s}){const[l,a]=o.useState(!1),c=o.useRef(null),d=o.useRef(null);return o.useEffect(()=>{"https://"===e&&a(!0)},[e]),o.useEffect(()=>{l&&d.current?.focus()},[l]),o.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]),n.jsxs("div",{ref:c,className:"lexical-text-editor-link link-editor-container",children:[n.jsx("div",{className:"link-editor-input-wrapper",children:l?n.jsx("input",{ref:d,className:"link-editor-input",value:e,onChange:e=>t(e.target.value),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),i(e),a(!1)):"Escape"===t.key&&(t.preventDefault(),a(!1),r())}}):n.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:e})}),n.jsxs("div",{className:"link-editor-buttons",children:[n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{l?(i(e),a(!1)):a(!0)},children:l?n.jsx(j.MdCheck,{size:18}):n.jsx(x.BsPencilSquare,{size:14})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:n.jsx(w.BiUnlink,{size:14,style:{stroke:"black"}})})]})]})}function se({onAction:e,alignmentSelectionMap:t}){const i=D.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return n.jsxs(Z,{open:r,onOpenChange:s,children:[n.jsx(ee,{triggerRef:l,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:146},children:[i?.icon,n.jsx("span",{children:i?.label}),n.jsx(C.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),n.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:D.map(({id:i,label:o,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[i]?"toolbar-active":"toolbar"),onClick:()=>{e(i),s(!1)},children:[r,n.jsx("span",{className:"label",children:o})]},i))})})]})}function le({color:e,onChange:t,icon:i}){const[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);o.useEffect(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&l.current&&!l.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return n.jsxs("div",{className:"color-picker-wrapper",children:[n.jsx("button",{type:"button",ref:l,className:`size-8 lexical-btn ${r?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:i}),r&&T.createPortal(n.jsx("div",{ref:a,className:"lexical-color-popover "+(r?"open":""),style:{top:l.current?.getBoundingClientRect().bottom,left:l.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:n.jsx(k.SketchPicker,{color:e,onChangeComplete:e=>{t(e.hex)}})}),document.body)]})}Q&&"InputEvent"in window&&!Y&&new window.InputEvent("input");const ae=({content:e,direction:t="top",delay:i=400,children:r})=>{const[s,l]=o.useState(!1),a=o.useRef(null);return n.jsxs("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{a.current=window.setTimeout(()=>{l(!0)},i)},onMouseLeave:()=>{a.current&&clearTimeout(a.current),l(!1)},children:[r,s&&n.jsx("div",{className:`Lexical-Tooltip-Tip ${t}`,children:e})]})};function ce(){const[e]=y.useLexicalComposerContext(),[{color:t,bgColor:i},r]=o.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=G(e,"color","#000"),n=G(e,"background","#fff");r({color:t,bgColor:n})}};o.useEffect(()=>V(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[e]);const l=({property:t,color:n})=>{e.update(()=>{const e=d.$getSelection();e&&U(e,{[t]:n})})};return n.jsxs(n.Fragment,{children:[n.jsx(ae,{content:"Font Color",direction:"bottom",children:n.jsx(le,{color:t,onChange:e=>{l({property:"color",color:e})},icon:n.jsx(f.AiOutlineFontColors,{})})}),n.jsx(ae,{content:"Background Color",direction:"bottom",children:n.jsx(le,{color:i,onChange:e=>{l({property:"background",color:e})},icon:n.jsx(f.AiOutlineBgColors,{})})})]})}function de({blockType:e}){const[t]=y.useLexicalComposerContext();return n.jsxs(n.Fragment,{children:[n.jsx(ae,{content:"Ordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${"ol"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===e?t.dispatchCommand(p.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(p.INSERT_ORDERED_LIST_COMMAND,void 0)},children:n.jsx(x.BsListOl,{})})}),n.jsx(ae,{content:"Unordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${"ul"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===e?t.dispatchCommand(p.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(p.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:n.jsx(x.BsListUl,{})})})]})}const ue=({src:e,altText:t,nodeKey:i,width:r,height:s,maxWidth:l})=>{const[a]=y.useLexicalComposerContext(),c=o.useRef(null),u=o.useRef(null),h=o.useRef(null),p=e=>{if(!h.current||!c.current)return;const t=e.clientX-h.current.x,n=Math.min(l,Math.max(50,h.current.width+t)),i=n*c.current.ratio;c.current.width=n,c.current.height=i;const o=u.current?.querySelector("img");o&&(o.style.width=n+"px",o.style.height=i+"px")},g=()=>{if(!c.current)return;const{width:e,height:t}=c.current;a.update(()=>{const n=d.$getNodeByKey(i);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),c.current=null,h.current=null,window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",g)};return n.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:l},children:[n.jsx("img",{src:e,alt:t,width:"inherit"===r?void 0:r,height:"inherit"===s?void 0:s,style:{maxWidth:"100%",display:"block"}}),n.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=u.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,i=t.naturalHeight/t.naturalWidth,o=n*i;h.current={x:e.clientX,y:e.clientY,width:n,height:o},c.current={width:n,height:o,ratio:i},window.addEventListener("mousemove",p),window.addEventListener("mouseup",g)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},he=e=>d.$applyNodeReplacement(new ge(e)),pe=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let i,o;e.width&&(i=e.width),e.height&&(o=e.height);const r=e.style;if((!i||0===i)&&r.width){const e=parseInt(r.width,10);Number.isNaN(e)||(i=e)}if((!o||0===o)&&r.height){const e=parseInt(r.height,10);Number.isNaN(e)||(o=e)}return{node:he({src:t,altText:n,width:i??"inherit",height:o??"inherit"})}};class ge extends d.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:n=1080,width:i="inherit",height:o="inherit",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=i,this.__height=o}static getType(){return"image"}static clone(e){return new ge({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}exportDOM(){const e=document.createElement("img");return e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),{element:e}}static importDOM(){return{img:()=>({conversion:pe,priority:1})}}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 ge({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}decorate(){return n.jsx(ue,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function me({open:e,onClose:t,forPreview:i=!1,children:r}){const s=o.useRef(null);return o.useEffect(()=>{if(!e)return;const n=e=>{s.current&&!s.current.contains(e.target)&&t()},i=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",i)}},[e,t]),e?n.jsx("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:n.jsxs("div",{ref:s,className:"lte-dialog "+(i?"preview":""),children:[n.jsx("button",{type:"button",className:"lte-dialog-close",onClick:t,children:"×"}),r]})}):null}function xe(){const[e]=y.useLexicalComposerContext(),t=o.useRef(null),[i,r]=o.useState(!1),[s,l]=o.useState(""),[a,c]=o.useState(""),[u,h]=o.useState();return n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("input",{type:"file",ref:t,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&h(t),e.target.value=""}}),n.jsx("button",{type:"button",className:`size-8 lexical-btn ${i?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:n.jsx(b.IoImageOutline,{size:18})}),n.jsxs(me,{open:i,onClose:()=>r(!1),children:[n.jsx("div",{className:"lte-dialog-header",children:"Add Image"}),n.jsxs("div",{className:"lte-dialog-body",children:[n.jsx("input",{className:"lte-input",placeholder:"Alt text",value:a,onChange:e=>c(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Add image by URL",value:s,onChange:e=>l(e.target.value)}),n.jsx("div",{className:"lte-divider",children:n.jsx("span",{children:"or"})}),n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>t.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[n.jsx(S.LuUpload,{size:20}),n.jsx("span",{children:"Upload Image"})]}),u&&n.jsx("div",{className:"lte-file-name",children:u.name})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s&&!u,onClick:()=>{let t=s;u&&(t=URL.createObjectURL(u)),e.update(()=>{const e=he({src:t,altText:a});d.$insertNodes([e])}),h(void 0),c(""),l(""),r(!1)},children:"Add Image"})})]})]})}const fe=({id:e,provider:t})=>new je({id:e,provider:t}),be="data-lexical-video",Ne="data-provider",ye="315px",ve="560px",Ce=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,_e=e=>{const t=e?.getAttribute(be),n=e?.getAttribute(Ne)??"youtube";if(!t)return null;return{node:fe({id:t,provider:n})}};class je extends d.DecoratorNode{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new je({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return fe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return n.jsx("iframe",{height:ye,width:ve,src:Ce(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(be,this.__id),e.setAttribute(Ne,this.__provider),e.setAttribute("height",ye),e.setAttribute("width",ve),e.setAttribute("src",Ce(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:_e,priority:0})}}}function we(){const[e,t]=o.useState(!1),[i,r]=o.useState(!1),[s,l]=o.useState(""),[a]=y.useLexicalComposerContext();return o.useEffect(()=>{e||(l(""),r(!1))},[e]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("button",{type:"button",className:`size-8 lexical-btn ${e?"toolbarActive":"toolbar"} icon`,onClick:()=>t(!0),children:n.jsx(E.FaYoutube,{size:18,color:"red"})}),n.jsxs(me,{open:e,onClose:()=>t(!1),children:[n.jsx("div",{className:"lte-dialog-header",children:"Embed Video"}),n.jsxs("div",{className:"lte-dialog-body",children:[n.jsx("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:s,onChange:e=>l(e.target.value)}),i&&n.jsx("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s,onClick:()=>{if(!s)return;let e=null,n=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);i&&11===i[2]?.length&&(e="youtube",n=i[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",n=o[1]),n&&e?(a.update(()=>{const t=fe({id:n,provider:e});d.$insertNodes([t])}),l(""),r(!1),t(!1)):r(!0)},children:"Embed"})})]})]})}function ke({value:e}){return n.jsx("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:e}})}function Te({value:e,triggerLabel:t="Preview"}){const[i,r]=o.useState(!1);return n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx(A.VscPreview,{size:18}),n.jsx("span",{children:t})]}),n.jsxs(me,{open:i,onClose:()=>r(!1),forPreview:!0,children:[n.jsx("div",{className:"lte-dialog-header",children:"Content Preview"}),n.jsxs("div",{className:"lte-preview-container",children:[n.jsx("div",{className:"lte-preview-title",children:"CONTENT"}),n.jsx(ke,{value:e})]})]})]})}const Se=({value:i})=>{const[s]=y.useLexicalComposerContext(),[l,a]=o.useState({[e.Undo]:!0,[e.Redo]:!0}),[c,u]=o.useState(!1),[h,g]=o.useState({[e.LeftAlign]:!0}),[m,x]=o.useState({[t.Normal]:!0}),[f,b]=o.useState("paragraph"),[N,C]=o.useState("https://");let j=!0;const w=()=>{if(j){const e=s.getRootElement();e&&(e.scrollTop=0,j=!1)}const n=d.$getSelection();if(d.$isRangeSelection(n)){const i={[e.Bold]:n.hasFormat("bold"),[e.Italics]:n.hasFormat("italic"),[e.Underline]:n.hasFormat("underline"),[e.Uppercase]:n.hasFormat("uppercase"),[e.Lowercase]:n.hasFormat("lowercase"),[e.Capitalize]:n.hasFormat("capitalize"),[e.Strikethrough]:n.hasFormat("strikethrough"),[e.Superscript]:n.hasFormat("superscript"),[e.Subscript]:n.hasFormat("subscript"),[e.Code]:n.hasFormat("code"),[e.Highlight]:n.hasFormat("highlight")};g(i);const o=n.anchor.getNode(),l="root"===o.getKey()?o:o.getTopLevelElementOrThrow(),a=l.getKey();if(!s.getElementByKey(a))return;if(p.$isListNode(l)){const e=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(o,p.ListNode),t=e?e.getTag():l.getTag();b(t)}else if("paragraph"===l.getType()||r.$isHeadingNode(l)){let e=null;r.$isHeadingNode(l)&&(e=l.getTag());const n={[t.H1]:"h1"===e,[t.H2]:"h2"===e,[t.H3]:"h3"===e,[t.H4]:"h4"===e,[t.H5]:"h5"===e,[t.H6]:"h6"===e,[t.Normal]:"paragraph"===l.getType()};b(l.getType()),x(n)}else b(l.getType());const c=(d.$isElementNode(o)?o:l).getFormat();g(t=>({...t,[e.LeftAlign]:0===c||1===c,[e.CenterAlign]:2===c,[e.RightAlign]:3===c,[e.JustifyAlign]:4===c})),"quote"===l.getType()?g(t=>({...t,[e.Quote]:!0})):g(t=>({...t,[e.Quote]:!1}));const h=n.anchor.getNode(),m=h.getParent();v.$isLinkNode(m)?(g(t=>({...t,[e.Link]:!0})),C(m.getURL()),u(!0)):v.$isLinkNode(h)?(g(t=>({...t,[e.Link]:!0})),C(h.getURL()),u(!0)):(g(t=>({...t,[e.Link]:!1})),C("https://"),u(!1))}};o.useEffect(()=>V(s.registerUpdateListener(({editorState:e})=>{e.read(()=>{w()})}),s.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(w(),!1),1),s.registerCommand(d.CAN_UNDO_COMMAND,e=>(a(t=>({...t,undo:!e})),!1),1),s.registerCommand(d.CAN_REDO_COMMAND,e=>(a(t=>({...t,redo:!e})),!1),1)),[]);const k=t=>{switch(t){case e.Bold:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"bold");break;case e.Italics:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"italic");break;case e.Underline:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"underline");break;case e.Lowercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"lowercase");break;case e.Uppercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"uppercase");break;case e.Capitalize:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"capitalize");break;case e.Strikethrough:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"strikethrough");break;case e.Superscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"superscript");break;case e.Subscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"subscript");break;case e.Highlight:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"highlight");break;case e.Code:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"code");break;case e.Quote:s.update(()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&r.$isQuoteNode(t)?function(e,t,n=q){if(null===e)return;const i=e.getStartEndPoints(),o=new Map;let r=null;if(i){const[e,t]=i;r=d.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const n=d.$findMatchingParent(e.getNode(),d.INTERNAL_$isBlock),s=d.$findMatchingParent(t.getNode(),d.INTERNAL_$isBlock);d.$isElementNode(n)&&o.set(n.getKey(),n),d.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(d.$isElementNode(t)&&d.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===i){const e=d.$findMatchingParent(t,d.INTERNAL_$isBlock);d.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,i]of o){const o=t();n(i,o),i.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(d.$getSelection())&&d.$setSelection(r)}(e,()=>d.$createParagraphNode()):W(e,()=>r.$createQuoteNode())}});break;case e.Link:T(),u(!0);break;case e.LeftAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"left");break;case e.RightAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"right");break;case e.CenterAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"center");break;case e.JustifyAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"justify");break;case e.Undo:s.dispatchCommand(d.UNDO_COMMAND,void 0);break;case e.Redo:s.dispatchCommand(d.REDO_COMMAND,void 0)}},T=o.useCallback(()=>{s.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&!e.isCollapsed()&&(c?s.dispatchCommand(v.TOGGLE_LINK_COMMAND,null):""!==N&&s.dispatchCommand(v.TOGGLE_LINK_COMMAND,N))})},[s,c,N]),S=o.useCallback(()=>{C(""),s.dispatchCommand(v.TOGGLE_LINK_COMMAND,null),u(!1)},[s]);return n.jsxs("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[O.map(({id:t,label:i,icon:o})=>t===e.Divider?n.jsx(ie,{},t):n.jsx(ae,{content:i,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),disabled:!!l[t],children:o})},i)),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(oe,{updateHeading:e=>{s.update(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&W(t,"normal"===e?()=>d.$createParagraphNode():()=>r.$createHeadingNode(e))})},headingSelectionMap:m}),n.jsx(ie,{})]}),$.map(({id:t,label:i,icon:o})=>t===e.Divider?n.jsx(ie,{},t):n.jsx(ae,{content:i,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),children:o})},t)),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(de,{blockType:f}),n.jsx(ie,{})]}),n.jsx(ce,{}),n.jsx(ne,{onAction:k,selectionMap:h}),n.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[n.jsx(se,{onAction:k,alignmentSelectionMap:h}),n.jsx(ie,{})]}),n.jsx(ae,{content:"Link",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-8 lexical-btn ${h[e.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(e.Link),disabled:!!l[e.Link],children:n.jsx(_.IoIosLink,{})})}),c&&n.jsx(re,{linkUrl:N,setLinkUrl:C,removeLink:S,onConfirm:e=>{s.dispatchCommand(v.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),C(e),u(!1)},onCancel:()=>{C(""),u(!1)}}),n.jsx(xe,{}),n.jsx(we,{}),n.jsx(Te,{value:i})]})};function Ee(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 n=document.createElement("div"),i=d.$getRoot().getChildren();for(let o=0;o<i.length;o++)Ae(e,i[o],n,t);return n.innerHTML}function Ae(e,t,n,i=null){let o=null===i||t.isSelected(i);const r=d.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==i){let e=d.$cloneWithProperties(t);e=d.$isTextNode(e)&&null!==i?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!d.$isTokenOrSegmented(t)&&null!==n){const[i,o]=n,r=e.isBackward(),s=i.getNode(),l=o.getNode(),a=t.is(s),c=t.is(l);if(a||c){const[n,i]=d.$getCharacterOffsets(e),o=s.is(l),a=t.is(r?l:s),c=t.is(r?s:l);let u,h=0;o?(h=n>i?i:n,u=n>i?n:i):a?(h=r?i:n,u=void 0):c&&(h=0,u=r?n:i),t.__text=t.__text.slice(h,u)}}return t}(i,e):e,s=e}const l=d.$isElementNode(s)?s.getChildren():[],a=d.getRegisteredNode(e,s.getType());let c;c=a&&void 0!==a.exportDOM?a.exportDOM(e,s):s.exportDOM(e);const{element:u,after:h}=c;if(!u)return!1;const p=document.createDocumentFragment();for(let n=0;n<l.length;n++){const r=l[n],s=Ae(e,r,p,i);!o&&d.$isElementNode(t)&&s&&t.extractWithChild(r,i,"html")&&(o=!0)}if(o&&!r){if((d.isHTMLElement(u)||d.isDocumentFragment(u))&&u.append(p),n.append(u),h){const e=h.call(s,u);e&&(d.isDocumentFragment(u)?u.replaceChildren(e):u.replaceWith(e))}}else n.append(p);return o}const Le=new Set(["STYLE","SCRIPT"]);function Me(e,t,n,i,o=new Map,r){let s=[];if(Le.has(e.nodeName))return s;let l=null;const a=function(e,t){const{nodeName:n}=e,i=t._htmlConversions.get(n.toLowerCase());let o=null;if(void 0!==i)for(const t of i){const n=t(e);null!==n&&(null===o||(o.priority||0)<=(n.priority||0))&&(o=n)}return null!==o?o.conversion:null}(e,t),c=a?a(e):null;let u=null;if(null!==c){u=c.after;const t=c.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of o)if(l=e(l,r),!l)break;l&&s.push(...Array.isArray(t)?t:[l])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const h=e.childNodes;let p=[];const g=(null==l||!d.$isRootOrShadowRoot(l))&&(null!=l&&d.$isBlockElementNode(l)||i);for(let e=0;e<h.length;e++)p.push(...Me(h[e],t,n,g,new Map(o),l));return null!=u&&(p=u(p)),d.isBlockDomNode(e)&&(p=function(e,t,n){const i=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(d.$isBlockElementNode(s))i&&!s.getFormat()&&s.setFormat(i),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&d.$isBlockElementNode(t[e+1])){const e=n();e.setFormat(i),e.append(...r),o.push(e),r=[]}}return o}(e,p,g?()=>{const e=new d.ArtificialNode__DO_NOT_USE;return n.push(e),e}:d.$createParagraphNode)),null==l?p.length>0?s=s.concat(p):d.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(d.isInlineDomNode(e.nextSibling)&&d.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(d.$createLineBreakNode())):d.$isElementNode(l)&&l.append(...p),s}function Re({value:e,onChange:t}){const[i]=y.useLexicalComposerContext(),[r,s]=o.useState(!0);return o.useEffect(()=>{e&&r&&(s(!1),i.update(()=>{if(Ee(i)!==e){d.$getRoot().clear();const t=(new DOMParser).parseFromString(e,"text/html"),n=function(e,t){const n=d.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let i=[];const o=[];for(const t of n)if(!Le.has(t.nodeName)){const n=Me(t,e,o,!1);null!==n&&(i=i.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof d.ArtificialNode__DO_NOT_USE&&t.insertAfter(d.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(o),i}(i,t);d.$insertNodes(n)}}))},[i,e,r]),o.useEffect(()=>{s(!0)},[e]),n.jsx(M.OnChangePlugin,{onChange:e=>{e.read(()=>{t(Ee(i))})}})}const $e=({id:e})=>new He({id:e}),Oe="data-lexical-youtube",De="315px",Fe="560px",Be=e=>`https://www.youtube-nocookie.com/embed/${e}`,Ie=e=>{const t=e?.getAttribute(Oe);if(!t)return null;return{node:$e({id:t})}};class He extends d.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new He({id:e.__id,key:e.getKey()})}static importJSON(e){return $e({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return n.jsx("iframe",{height:De,width:Fe,src:Be(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Oe,this.__id),e.setAttribute("height",De),e.setAttribute("width",Fe),e.setAttribute("src",Be(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Ie,priority:0})}}}class Pe extends d.TextNode{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new Pe(e.__text,e.__key)}static importDOM(){const e=d.TextNode.importDOM();return{...e,span:()=>({conversion:Ue(e?.span),priority:1}),div:()=>({conversion:Ue(e?.div),priority:1}),p:()=>({conversion:Ue(e?.p),priority:1}),b:()=>({conversion:Ue(e?.b),priority:1}),strong:()=>({conversion:Ue(e?.strong),priority:1}),i:()=>({conversion:Ue(e?.i),priority:1}),em:()=>({conversion:Ue(e?.em),priority:1}),u:()=>({conversion:Ue(e?.u),priority:1}),s:()=>({conversion:Ue(e?.s),priority:1}),strike:()=>({conversion:Ue(e?.strike),priority:1}),code:()=>({conversion:Ue(e?.code),priority:1})}}static importJSON(e){return function(e=""){return d.$applyNodeReplacement(new Pe(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Ue(e){return t=>{const n=e?.(t);if(!n)return null;const i=n.conversion(t);if(!i)return i;const o=t.style,r=[];o.backgroundColor&&r.push(`background-color: ${o.backgroundColor}`),o.color&&r.push(`color: ${o.color}`),o.fontFamily&&r.push(`font-family: ${o.fontFamily}`),o.fontWeight&&r.push(`font-weight: ${o.fontWeight}`),o.fontSize&&r.push(`font-size: ${o.fontSize}`),o.fontStyle&&r.push(`font-style: ${o.fontStyle}`),o.textDecoration&&r.push(`text-decoration: ${o.textDecoration}`),o.whiteSpace&&r.push(`white-space: ${o.whiteSpace}`),o.textAlign&&r.push(`text-align: ${o.textAlign}`);const s=t.getAttribute("style");if(s){s.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!r.some(e=>e.startsWith(t))&&r.push(e.trim())})}return{...i,forChild:(e,t)=>{const n=i?.forChild??(e=>e),o=n(e,t);if(d.$isTextNode(o)&&r.length>0){const e=r.join("; ");return o.setStyle(e)}return o}}}}const qe={text:{bold:"lexical-bold",underline:"lexical-underline",italic:"lexical-italic",strikethrough:"lexical-strikethrough",underlineStrikethrough:"lexical-underline-strikethrough",uppercase:"lexical-uppercase",lowercase:"lexical-lowercase",capitalize:"lexical-capitalize",code:"lexical-code"},paragraph:"lexical-paragraph",list:{ul:"lexical-list-ul",ol:"lexical-list-ol",listitem:"lexical-listitem"},quote:"lexical-quote",link:"lexical-link"},ze=o.memo(function({name:e,value:t,onChange:g,placeholder:m,maxWidth:x=null,height:f=null}){const b=o.useMemo(()=>({namespace:e,theme:qe,onError:e=>{console.error("Lexical error:",e)},nodes:[Pe,{replace:d.TextNode,with:e=>new Pe(e.__text),withKlass:Pe},r.HeadingNode,s.CodeHighlightNode,s.CodeNode,p.ListNode,p.ListItemNode,r.QuoteNode,v.LinkNode,ge,He,je]}),[e]);return n.jsx("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:x||"1090px"},children:n.jsxs(i.LexicalComposer,{initialConfig:b,children:[n.jsx("div",{className:"lexical-toolbar-container",children:n.jsx(Se,{value:t})}),n.jsx("div",{className:"lexical-editor-inner",children:n.jsx(l.RichTextPlugin,{contentEditable:n.jsx(a.ContentEditable,{className:"lexical-content-editable",style:{height:f||"500px"}}),placeholder:n.jsx("div",{className:"lexical-placeholder",children:m||"Some Text"}),ErrorBoundary:c.LexicalErrorBoundary})}),n.jsx(u.HistoryPlugin,{}),n.jsx(h.ListPlugin,{}),n.jsx(L.LinkPlugin,{}),n.jsx(Re,{value:t,onChange:g})]})})});exports.LexicalTextEditor=ze;
2
2
  //# sourceMappingURL=index.js.map