@innoviatech/lexical-text-editor 3.0.2 → 3.0.3
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.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -1
- package/dist/plugins/InlineCodeExitPlugin.d.ts +17 -0
- package/dist/plugins/toolbarOverflowContext.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e,t,n=require("react/jsx-runtime"),o=require("@lexical/react/LexicalComposer"),i=require("react"),l=require("@lexical/rich-text"),r=require("@lexical/code"),s=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("@lexical/react/LexicalHorizontalRuleNode"),m=require("@lexical/react/LexicalHorizontalRulePlugin"),x=require("@lexical/react/LexicalTablePlugin"),f=require("@lexical/table"),b=require("react-icons/rx"),y=require("react-icons/tb"),C=require("react-icons/bs"),N=require("react-icons/ai"),v=require("react-icons/io5"),j=require("react-icons/pi"),w=require("react-icons/ri"),S=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/link"),T=require("react-icons/hi2"),E=require("react-dom"),_=require("react-icons/io"),R=require("react-icons/md"),L=require("react-icons/bi"),M=require("react-color"),$=require("react-icons/lu"),A=require("react-icons/fa"),O=require("react-icons/vsc"),D=require("@lexical/react/LexicalLinkPlugin"),I=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.ClearFormatting="clearFormatting",e.CodeBlock="codeBlock",e.HorizontalRule="horizontalRule",e.Indent="indent",e.Outdent="outdent",e.Table="table",e.FindReplace="findReplace",e.SourceView="sourceView",e.Fullscreen="fullscreen"}(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 F=[{id:e.Lowercase,icon:n.jsx(b.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:e.Uppercase,icon:n.jsx(b.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:e.Capitalize,icon:n.jsx(b.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:e.Superscript,icon:n.jsx(C.BsSuperscript,{}),label:"Superscript"},{id:e.Subscript,icon:n.jsx(C.BsSubscript,{}),label:"Subscript"}],H=[{id:e.Bold,icon:n.jsx(y.TbBold,{}),label:"Bold"},{id:e.Italics,icon:n.jsx(y.TbItalic,{}),label:"Italics"},{id:e.Underline,icon:n.jsx(y.TbUnderline,{}),label:"Underline"},{id:e.Strikethrough,icon:n.jsx(N.AiOutlineStrikethrough,{}),label:"Strikethrough"}],B=[{id:e.Highlight,icon:n.jsx(j.PiHighlighterLight,{}),label:"Highlight"}],z=[{id:e.Quote,icon:n.jsx(C.BsChatSquareQuote,{}),label:"Quote"},{id:e.Code,icon:n.jsx(v.IoCodeSlashOutline,{}),label:"Code"}],P=[{id:e.Undo,icon:n.jsx(C.BsArrowCounterclockwise,{}),label:"Undo"},{id:e.Redo,icon:n.jsx(C.BsArrowClockwise,{}),label:"Redo"},{id:e.ClearFormatting,icon:n.jsx(w.RiEraserLine,{}),label:"Clear Formatting"}],W=[{id:e.Indent,icon:n.jsx(w.RiIndentIncrease,{}),label:"Indent"},{id:e.Outdent,icon:n.jsx(w.RiIndentDecrease,{}),label:"Outdent"}],U=[{id:e.HorizontalRule,icon:n.jsx(y.TbSeparatorHorizontal,{}),label:"Horizontal Rule"}],q=[{id:e.LeftAlign,icon:n.jsx(C.BsJustifyLeft,{}),label:"Left Align"},{id:e.CenterAlign,icon:n.jsx(C.BsTextCenter,{}),label:"Center Align"},{id:e.RightAlign,icon:n.jsx(C.BsJustifyRight,{}),label:"Right Align"},{id:e.JustifyAlign,icon:n.jsx(C.BsJustify,{}),label:"Justify Align"}],K=[{id:"normal",label:"Normal",icon:n.jsx(C.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:n.jsx(C.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:n.jsx(C.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:n.jsx(C.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:n.jsx(C.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:n.jsx(C.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:n.jsx(C.BsTypeH6,{})}],J=[{id:"plaintext",label:"Plain Text"},{id:"javascript",label:"JavaScript"},{id:"typescript",label:"TypeScript"},{id:"python",label:"Python"},{id:"java",label:"Java"},{id:"csharp",label:"C#"},{id:"cpp",label:"C++"},{id:"php",label:"PHP"},{id:"ruby",label:"Ruby"},{id:"go",label:"Go"},{id:"rust",label:"Rust"},{id:"swift",label:"Swift"},{id:"kotlin",label:"Kotlin"},{id:"html",label:"HTML"},{id:"css",label:"CSS"},{id:"sql",label:"SQL"},{id:"json",label:"JSON"},{id:"bash",label:"Bash"},{id:"markdown",label:"Markdown"},{id:"yaml",label:"YAML"},{id:"xml",label:"XML"}];function G(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.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 X=new Map;function V(e){let t=X.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,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim())}return t}(e),X.set(e,t)),t}function Q(e,t){(d.$isRangeSelection(e)?e.isCollapsed():d.$isTextNode(e)||d.$isElementNode(e))||G(280);const n=V(d.$isRangeSelection(e)?e.style:d.$isTextNode(e)?e.getStyle():e.getTextStyle()),o=Object.entries(t).reduce((t,[o,i])=>("function"==typeof i?t[o]=i(n[o],e):null===i?delete t[o]:t[o]=i,t),{...n}),i=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(o);d.$isRangeSelection(e)||d.$isTextNode(e)?e.setStyle(i):e.setTextStyle(i),X.set(i,o)}function Y(e,t){if(d.$isRangeSelection(e)&&e.isCollapsed()){Q(e,t);const n=e.anchor.getNode();d.$isElementNode(n)&&n.isEmpty()&&Q(n,t)}!function(e){const t=d.$getSelection();if(!t)return;const n=new Map,o=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 i=t.getNodes();for(const t of i){if(!d.$isTextNode(t)||!t.canHaveFormat())continue;const[n,i]=o(t);i!==n&&(d.$isTokenOrSegmented(t)||0===n&&i===t.getTextContentSize()?e(t):e(t.splitText(n,i)[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:o,offset:i,type:l}=t;t.set(n.key,n.offset,n.type),n.set(o,i,l)}}(t)}(e=>{Q(e,t)})}function Z(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function ee(e,t,n=Z){if(null===e)return;const o=e.getStartEndPoints(),i=new Map;let l=null;if(o){const[e,t]=o;l=d.$createRangeSelection(),l.anchor.set(e.key,e.offset,e.type),l.focus.set(t.key,t.offset,t.type);const n=d.$findMatchingParent(e.getNode(),d.INTERNAL_$isBlock),r=d.$findMatchingParent(t.getNode(),d.INTERNAL_$isBlock);d.$isElementNode(n)&&i.set(n.getKey(),n),d.$isElementNode(r)&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(d.$isElementNode(t)&&d.INTERNAL_$isBlock(t))i.set(t.getKey(),t);else if(null===o){const e=d.$findMatchingParent(t,d.INTERNAL_$isBlock);d.$isElementNode(e)&&i.set(e.getKey(),e)}for(const[e,o]of i){const i=t();n(o,i),o.replace(i,!0),l&&(e===l.anchor.key&&l.anchor.set(i.getKey(),l.anchor.offset,l.anchor.type),e===l.focus.key&&l.focus.set(i.getKey(),l.focus.offset,l.focus.type))}l&&e.is(d.$getSelection())&&d.$setSelection(l)}function te(e){return e.getNode().isAttached()}function ne(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 oe(e,t,n=null){const o=e.getStartEndPoints(),i=o?o[0]:null,l=e.getNodes(),r=l.length;if(null!==i&&(0===r||1===r&&"element"===i.type&&0===i.getNode().getChildrenSize())){const e="text"===i.type?i.getNode().getParentOrThrow():i.getNode(),o=e.getChildren();let l=t();return l.setFormat(e.getFormatType()),l.setIndent(e.getIndent()),o.forEach(e=>l.append(e)),n&&(l=n.append(l)),void e.replace(l)}let s=null,a=[];for(let o=0;o<r;o++){const i=l[o];d.$isRootOrShadowRoot(i)?(ie(e,a,a.length,t,n),a=[],s=i):null===s||null!==s&&d.$hasAncestor(i,s)?a.push(i):(ie(e,a,a.length,t,n),a=[i])}ie(e,a,a.length,t,n)}function ie(e,t,n,o,i=null){if(0===t.length)return;const l=t[0],r=new Map,s=[];let a=d.$isElementNode(l)?l:l.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 i=n.getParent();if(null!==i&&i.isInline()&&(i=i.getParent()),null!==i&&d.$isLeafNode(n)&&!h.has(n.getKey())){const e=i.getKey();if(void 0===r.get(e)){const t=o();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),s.push(t),r.set(e,t),i.getChildren().forEach(e=>{t.append(e),h.add(e.getKey()),d.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>h.add(e))}),ne(i)}}else if(u.has(n.getKey())){d.$isElementNode(n)||G(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),s.push(e),n.remove(!0)}}if(null!==i)for(let e=0;e<s.length;e++){const t=s[e];i.append(t)}let p=null;if(d.$isRootOrShadowRoot(a))if(c)if(null!==i)a.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(d.$isElementNode(e)&&(a=e),null===e)if(i)a.append(i);else for(let e=0;e<s.length;e++){const t=s[e];a.append(t),p=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<s.length;t++){const n=s[t];e.insertBefore(n),p=n}}else if(i)a.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];a.insertAfter(t),p=t}const g=d.$getPreviousSelection();d.$isRangeSelection(g)&&te(g.anchor)&&te(g.focus)?d.$setSelection(g.clone()):null!==p?p.selectEnd():e.dirty=!0}function le(e,t,n){const o=V(e.getStyle());return null!==o&&o[t]||n}function re(e,t,n=""){let o=null;const i=e.getNodes(),l=e.anchor,r=e.focus,s=e.isBackward(),a=s?r.offset:l.offset,c=s?r.getNode():l.getNode();if(d.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const n=V(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<i.length;e++){const l=i[e];if((0===e||0!==a||!l.is(c))&&d.$isTextNode(l)){const e=le(l,t,n);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?n:o}const se="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ae=se&&"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,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function ue({open:e,onOpenChange:t,children:o}){const l=i.useRef(null),r=i.useRef(null);return i.useEffect(()=>{function n(e){l.current?.contains(e.target)||r.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:i.Children.map(o,e=>e&&"object"==typeof e?e.type===he?i.cloneElement(e,{triggerRef:l}):e.type===pe?i.cloneElement(e,{contentRef:r,triggerRef:l}):e:e)})}function he({children:e,triggerRef:t}){return n.jsx("div",{className:"popover-trigger",ref:t,children:e})}function pe({open:e,align:t="start",children:o,contentRef:l,triggerRef:r}){const s=i.useRef(null),[a,c]=i.useState(!1);return i.useEffect(()=>{if(!e)return;const n=()=>{const e=s.current,n=r?.current;if(!e||!n)return;const o=n.closest(".lexical-text-editor"),i=!!o?.classList.contains("lexical-dark");e.classList.contains("lexical-dark")!==i&&e.classList.toggle("lexical-dark",i);const l=n.getBoundingClientRect(),a=e.offsetWidth,d=e.offsetHeight;let u=l.left;"center"===t?u=l.left+l.width/2-a/2:"end"===t&&(u=l.right-a),u=Math.max(8,Math.min(window.innerWidth-a-8,u));let h=l.bottom+4;h+d>window.innerHeight-8&&l.top>d+8&&(h=l.top-d-4),e.style.left=`${u}px`,e.style.top=`${h}px`,c(i)};return n(),requestAnimationFrame(n),window.addEventListener("resize",n),document.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),document.removeEventListener("scroll",n,!0)}},[e,t,r]),e?E.createPortal(n.jsx("div",{ref:s,className:"lexical-text-editor"+(a?" lexical-dark":""),"data-lte-popover-portal":"true",onMouseDown:e=>e.preventDefault(),style:{position:"fixed",top:0,left:0,zIndex:9999,background:"transparent",border:"none",borderRadius:0,boxShadow:"none",padding:0,margin:0,height:"fit-content",maxWidth:"none"},children:n.jsx("div",{ref:e=>{l.current=e},className:"popover-content",style:{position:"static",top:"auto",left:"auto",borderRadius:6,border:"none",margin:0,width:"100%"},children:o})}),document.body):null}function ge({onAction:e,selectionMap:t}){const[o,l]=i.useState(!1),r=i.useRef(null),s=i.useRef(null);return n.jsxs(ue,{open:o,onOpenChange:l,children:[n.jsx(he,{triggerRef:r,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[n.jsx("span",{children:"Aa"}),n.jsx(T.HiChevronDown,{className:"chevron "+(o?"rotated":"")})]})}),n.jsx(pe,{open:o,align:"start",onClose:()=>l(!1),contentRef:s,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:F.map(({id:o,label:i,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),l(!1)},style:{minWidth:130},children:[r,n.jsx("span",{className:"label",children:i})]},o))})})]})}function me(){return n.jsx("div",{className:"lexical-separator"})}function xe({updateHeading:e,headingSelectionMap:t}){const o=K.find(e=>t[e.id]),[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);return n.jsxs(ue,{open:l,onOpenChange:r,children:[n.jsx(he,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),style:{minWidth:132},children:[o?.icon,n.jsx("span",{children:o?.label}),n.jsx(T.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(pe,{open:l,align:"start",onClose:()=>r(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:K.map(({id:o,label:i,icon:l})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),r(!1)},children:[l,n.jsx("span",{className:"label",children:i})]},o))})})]})}function fe({linkUrl:e,setLinkUrl:t,onConfirm:o,onCancel:l,removeLink:r}){const[s,a]=i.useState(!1),c=i.useRef(null),d=i.useRef(null);return i.useEffect(()=>{"https://"===e&&a(!0)},[e]),i.useEffect(()=>{s&&d.current?.focus()},[s]),i.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]),n.jsxs("div",{ref:c,className:"lexical-text-editor-link link-editor-container",children:[n.jsx("div",{className:"link-editor-input-wrapper",children:s?n.jsx("input",{ref:d,className:"link-editor-input",value:e,onChange:e=>t(e.target.value),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),o(e),a(!1)):"Escape"===t.key&&(t.preventDefault(),a(!1),l())}}):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:()=>{s?(o(e),a(!1)):a(!0)},children:s?n.jsx(R.MdCheck,{size:18}):n.jsx(C.BsPencilSquare,{size:14})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:r,children:n.jsx(L.BiUnlink,{size:14,style:{stroke:"black"}})})]})]})}function be({onClose:e}){const[t]=S.useLexicalComposerContext(),[o,l]=i.useState(""),[r,s]=i.useState(""),[a,c]=i.useState(!1),[u,h]=i.useState([]),[p,g]=i.useState(0),m=i.useRef(null);i.useEffect(()=>{m.current?.focus()},[]);const x=()=>{if(!o)return[];const e=a?o:o.toLowerCase(),t=[],n=d.$getRoot().getAllTextNodes();for(const o of n){const n=a?o.getTextContent():o.getTextContent().toLowerCase();let i=n.indexOf(e);for(;-1!==i;)t.push({key:o.getKey(),start:i}),i=n.indexOf(e,i+e.length)}return t};i.useEffect(()=>{const e=t.getEditorState().read(x);h(e),g(0)},[t,o,a]),i.useEffect(()=>t.registerUpdateListener(({editorState:e})=>{const t=e.read(x);h(t),g(e=>0===t.length?0:Math.min(e,t.length-1))}),[t,o,a]);const f=e=>{if(0===u.length)return;const n=(p+e+u.length)%u.length,i=u[n];g(n),t.update(()=>{const e=d.$getNodeByKey(i.key);d.$isTextNode(e)&&e.select(i.start,i.start+o.length)}),requestAnimationFrame(()=>{const e=t.getElementByKey(i.key);e?.scrollIntoView({block:"nearest"})})},b=o.length>0,y=u.length>0;return n.jsxs("div",{className:"lexical-find-replace",onKeyDown:t=>{"Escape"===t.key&&(t.preventDefault(),e())},children:[n.jsxs("div",{className:"lexical-fr-row",children:[n.jsx("input",{ref:m,className:"lexical-fr-input",placeholder:"Find",value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f(e.shiftKey?-1:1))}}),n.jsx("span",{className:"lexical-fr-count",children:y?`${p+1} of ${u.length}`:b?"0 results":""})]}),n.jsx("div",{className:"lexical-fr-row",children:n.jsx("input",{className:"lexical-fr-input",placeholder:"Replace with",value:r,onChange:e=>s(e.target.value)})}),n.jsxs("div",{className:"lexical-fr-row",children:[n.jsxs("label",{className:"lexical-fr-case",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:e=>c(e.target.checked)}),n.jsx("span",{children:"Match case"})]}),n.jsx("span",{style:{flex:1}}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>f(-1),disabled:!y,"aria-label":"Previous match",children:n.jsx(v.IoChevronUp,{})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>f(1),disabled:!y,"aria-label":"Next match",children:n.jsx(v.IoChevronDown,{})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{t.update(()=>{const e=x();if(0===e.length)return h([]),void g(0);const t=e[Math.min(p,e.length-1)],n=d.$getNodeByKey(t.key);d.$isTextNode(n)&&n.spliceText(t.start,o.length,r,!0)})},disabled:!y,children:"Replace"}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{t.update(()=>{const e=x();for(let t=e.length-1;t>=0;t--){const n=e[t],i=d.$getNodeByKey(n.key);d.$isTextNode(i)&&i.spliceText(n.start,o.length,r,!1)}})},disabled:!y,children:"Replace All"}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:e,"aria-label":"Close find and replace",children:n.jsx(v.IoClose,{})})]})]})}function ye({anchorRef:e,onClose:t,children:o}){const l=i.useRef(null);return i.useEffect(()=>{const n=n=>{const o=n.target;o instanceof HTMLElement&&o.closest("[data-lte-popover-portal]")||!l.current||l.current.contains(o)||e.current&&e.current.contains(o)||t()},o=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",o)}},[e,t]),n.jsx("div",{ref:l,className:"lte-overflow-panel",onMouseDown:e=>e.preventDefault(),children:n.jsx("div",{className:"lte-overflow-grid",children:o})})}function Ce({onAction:e,alignmentSelectionMap:t}){const o=q.find(e=>t[e.id]),[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);return n.jsxs(ue,{open:l,onOpenChange:r,children:[n.jsx(he,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),style:{minWidth:146},children:[o?.icon,n.jsx("span",{children:o?.label}),n.jsx(T.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(pe,{open:l,align:"start",onClose:()=>r(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:q.map(({id:o,label:i,icon:l})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),r(!1)},children:[l,n.jsx("span",{className:"label",children:i})]},o))})})]})}function Ne({color:e,onChange:t,icon:o}){const[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);i.useEffect(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&s.current&&!s.current.contains(e.target)&&r(!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:s,className:`size-10 lexical-btn ${l?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:o}),l&&E.createPortal(n.jsx("div",{ref:a,className:"lexical-color-popover "+(l?"open":""),"data-lte-popover-portal":"true",style:{top:s.current?.getBoundingClientRect().bottom,left:s.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>{e.preventDefault(),(e=>{e.preventDefault()})(e)},children:n.jsx(M.SketchPicker,{color:e,onChangeComplete:e=>{t(e.hex)}})}),document.body)]})}function ve(){const[e]=S.useLexicalComposerContext(),[{color:t,bgColor:o},l]=i.useState({color:"#000",bgColor:"#fff"}),r=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=re(e,"color","#000"),n=re(e,"background","#fff");l({color:t,bgColor:n})}};i.useEffect(()=>ce(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{r()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(r(),!1),1)),[e]);const s=({property:t,color:n})=>{e.update(()=>{const e=d.$getSelection();e&&Y(e,{[t]:n})})};return n.jsxs(n.Fragment,{children:[n.jsx(Ne,{color:t,onChange:e=>{s({property:"color",color:e})},icon:n.jsx(N.AiOutlineFontColors,{})}),n.jsx(Ne,{color:o,onChange:e=>{s({property:"background",color:e})},icon:n.jsx(N.AiOutlineBgColors,{})})]})}function je({icon:e,tooltipLabel:t,currentValue:o,options:l,onSelect:r,minWidth:s=132}){const a=l.find(e=>""!==e.id&&e.id===o),[c,d]=i.useState(!1),u=i.useRef(null),h=i.useRef(null);return n.jsxs(ue,{open:c,onOpenChange:d,children:[n.jsx(he,{triggerRef:u,children:n.jsxs("button",{type:"button","aria-label":t,className:"lexical-btn heading-trigger font-trigger "+(c?"toolbar-active":"toolbar"),style:{minWidth:s},onClick:()=>d(e=>!e),children:[e,n.jsx("span",{children:a?.label??"Default"}),n.jsx(T.HiChevronDown,{className:"chevron "+(c?"rotated":"")})]})}),n.jsx(pe,{open:c,align:"start",onClose:()=>d(!1),contentRef:h,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:l.map(e=>n.jsx("button",{type:"button",className:"lexical-btn "+(""===e.id&&""===o||""!==e.id&&e.id===o?"toolbar-active":"toolbar"),onClick:()=>{r(e.id),d(!1)},children:n.jsx("span",{className:"label",children:e.label})},e.label))})})]})}se&&"InputEvent"in window&&!ae&&new window.InputEvent("input");const we=[{id:"",label:"Default"},{id:"Inter",label:"Inter"},{id:"System UI",label:"System"},{id:"serif",label:"Serif"},{id:"monospace",label:"Monospace"},{id:"cursive",label:"Cursive"},{id:"Georgia",label:"Georgia"},{id:"Courier New",label:"Courier"}];function Se(){const[e]=S.useLexicalComposerContext(),[t,o]=i.useState(""),l=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=re(e,"font-family","");o((e=>e.replace(/['"]/g,"").trim())(t))}};i.useEffect(()=>ce(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{l()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(l(),!1),1)),[e]);return n.jsx(je,{icon:n.jsx(w.RiFontFamily,{}),tooltipLabel:"Font Family",currentValue:t,options:we,onSelect:t=>{e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&Y(e,{"font-family":""===t?null:t})})}})}const ke=({content:e,direction:t="top",delay:o=400,children:l})=>{const[r,s]=i.useState(!1),[a,c]=i.useState(null),d=i.useRef(null),u=i.useRef(null),h=()=>{d.current=window.setTimeout(()=>{const e=u.current;if(e){const t=e.getBoundingClientRect();c({left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height})}s(!0)},o)},p=()=>{d.current&&clearTimeout(d.current),s(!1)};if(!a)return n.jsx("div",{ref:u,className:"Lexical-Tooltip-Wrapper",onMouseEnter:h,onMouseLeave:p,children:l});const g=a.left+a.width/2,m=a.top+a.height/2,x="bottom"===t?{top:a.bottom+10,left:g,bottom:"auto"}:"top"===t?{bottom:window.innerHeight-a.top+10,top:"auto",left:g}:"right"===t?{left:a.right+10,right:"auto",top:m}:{left:"auto",right:window.innerWidth-a.left+10,top:m};return n.jsxs("div",{ref:u,className:"Lexical-Tooltip-Wrapper",onMouseEnter:h,onMouseLeave:p,children:[l,r&&E.createPortal(n.jsx("div",{className:`Lexical-Tooltip-Tip ${t}`,style:{position:"fixed",pointerEvents:"none",...x,zIndex:1e4},children:e}),document.body)]})};function Te(){const[e]=S.useLexicalComposerContext(),[t,o]=i.useState(""),l=()=>{const t=d.$getSelection();if(d.$isRangeSelection(t)){let n=Ee(re(t,"font-size",""));if(!n)try{const o=e.getElementByKey(t.anchor.getNode().getKey());o&&(n=window.getComputedStyle(o).fontSize||"")}catch{}o(Ee(n))}};i.useEffect(()=>ce(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{l()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(l(),!1),1)),[e]);const r=n=>{const o=Number.parseInt(t,10);(t=>{const n=Math.min(90,Math.max(6,t));e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&Y(e,{"font-size":`${n}px`})})})((Number.isNaN(o)?16:o)+n)},s=Number.parseInt(t,10),a=Number.isNaN(s)?null:s;return n.jsxs("div",{className:"lexical-stepper","aria-label":"Font Size",role:"group",children:[n.jsx(ke,{content:"Decrease font size",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Decrease Font Size",className:"lexical-stepper-btn",disabled:null!==a&&a<=6,onClick:()=>r(-1),children:n.jsx($.LuMinus,{})})}),n.jsx("span",{className:"lexical-stepper-value",children:a??"—"}),n.jsx(ke,{content:"Increase font size",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Increase Font Size",className:"lexical-stepper-btn",disabled:null!==a&&a>=90,onClick:()=>r(1),children:n.jsx($.LuPlus,{})})})]})}const Ee=e=>e.trim();function _e(){const[e]=S.useLexicalComposerContext(),[t,o]=i.useState(!1),[l,s]=i.useState(null),[a,c]=i.useState(!1),u=i.useRef(null),h=i.useRef(null),p=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow(),i=r.$isCodeNode(n);o(i),i&&s(n.getLanguage()??null)}};i.useEffect(()=>ce(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{p()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(p(),!1),1)),[e]);const g=J.find(e=>e.id===l)?.label??"Plain Text";return n.jsxs(ue,{open:a,onOpenChange:c,children:[n.jsx(he,{triggerRef:u,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(t?"toolbar-active":"toolbar"),onClick:()=>c(e=>!e),children:[n.jsx(v.IoCodeSlashOutline,{}),n.jsx("span",{children:g}),n.jsx(T.HiChevronDown,{className:"chevron "+(a?"rotated":"")})]})}),n.jsx(pe,{open:a,align:"start",onClose:()=>c(!1),contentRef:h,children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[n.jsxs("button",{type:"button",className:"lexical-btn "+(t?"toolbar-active":"toolbar"),onClick:()=>{e.update(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow();if(r.$isCodeNode(n))ee(e,()=>d.$createParagraphNode());else{const t=l??"javascript";ee(e,()=>r.$createCodeNode(t))}}),c(!1)},style:{minWidth:150},children:[n.jsx(v.IoCodeSlashOutline,{}),n.jsx("span",{className:"label",children:t?"Remove Code Block":"Code Block"})]}),n.jsx("div",{className:"w-full h-[1px] bg-gray-200 my-1"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5,maxHeight:260,overflowY:"auto"},children:J.map(({id:t,label:o})=>n.jsx("button",{type:"button",className:"lexical-btn "+(l===t?"toolbar-active":"toolbar"),onClick:()=>{var n;s(n=t),e.update(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.anchor.getNode(),o="root"===t.getKey()?t:t.getTopLevelElementOrThrow();r.$isCodeNode(o)&&o.setLanguage(n)}),c(!1)},style:{minWidth:150},children:n.jsx("span",{className:"label",children:o})},t))})]})})]})}function Re({blockType:e}){const[t]=S.useLexicalComposerContext();i.useEffect(()=>ce(t.registerCommand(d.KEY_TAB_COMMAND,e=>{const n=d.$getSelection();if(!d.$isRangeSelection(n))return!1;return!!de(n.anchor.getNode(),p.ListNode)&&(e.preventDefault(),t.dispatchCommand(e.shiftKey?d.OUTDENT_CONTENT_COMMAND:d.INDENT_CONTENT_COMMAND,void 0),!0)},d.COMMAND_PRIORITY_EDITOR)),[t]);return n.jsxs(n.Fragment,{children:[n.jsx(ke,{content:"Ordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 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(C.BsListOl,{})})}),n.jsx(ke,{content:"Unordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 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(C.BsListUl,{})})})]})}function Le(){const[e]=S.useLexicalComposerContext(),[t,o]=i.useState(!1),[l,r]=i.useState(!1),[s,a]=i.useState(null),c=i.useRef(null),u=i.useRef(null),h=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=f.$findCellNode(e.anchor.getNode());o(!!t)}else o(!1)};i.useEffect(()=>ce(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{h()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(h(),!1),1)),[e]);const p=t=>{e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&t()}),r(!1)},g=s?`${s.rows} × ${s.cols}`:"Insert Table";return n.jsxs(ue,{open:l,onOpenChange:r,children:[n.jsx(he,{triggerRef:c,children:n.jsxs("button",{type:"button","aria-label":"Insert Table",className:"lexical-btn heading-trigger "+(t?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx(C.BsTable,{}),n.jsx(T.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(pe,{open:l,align:"start",onClose:()=>r(!1),contentRef:u,children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[n.jsxs("div",{style:{width:"fit-content"},children:[n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},children:Array.from({length:25},(t,o)=>{const i=Math.floor(o/5)+1,l=o%5+1,c=s&&i<=s.rows&&l<=s.cols;return n.jsx("div",{onMouseEnter:()=>a({rows:i,cols:l}),onClick:()=>{return t=i,n=l,e.update(()=>{if(!d.$isRangeSelection(d.$getSelection())){const e=d.$getRoot().getFirstChild();d.$isElementNode(e)&&e.select(0,0)}}),e.dispatchCommand(f.INSERT_TABLE_COMMAND,{rows:String(t),columns:String(n),includeHeaders:!1}),void r(!1);var t,n},style:{width:18,height:18,borderRadius:3,border:"1px solid #d1d5db",backgroundColor:c?"#c7d2fe":"#fff",cursor:"pointer"}},o)})}),n.jsx("div",{style:{fontSize:12,color:"#6b7280",marginTop:4},children:g})]}),n.jsx("div",{className:"w-full h-[1px] bg-gray-200"}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableRowAtSelection(!1)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert row above"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableRowAtSelection(!0)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert row below"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$deleteTableRowAtSelection()}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Delete row"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableColumnAtSelection(!1)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert column left"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableColumnAtSelection(!0)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert column right"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$deleteTableColumnAtSelection()}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Delete column"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>{p(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=f.$findCellNode(e.anchor.getNode());if(!t)return;const n=t.getParent();if(!n)return;const o=n.getChildren().filter(f.$isTableCellNode),i=o.some(e=>e.hasHeaderState(f.TableCellHeaderStates.ROW));for(const e of o)e.setHeaderStyles(i?f.TableCellHeaderStates.NO_STATUS:f.TableCellHeaderStates.ROW,f.TableCellHeaderStates.ROW)})},style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Toggle header row"})})]})]})})]})}const Me=({src:e,altText:t,nodeKey:o,width:l,height:r,maxWidth:s,caption:a=""})=>{const[c]=S.useLexicalComposerContext(),[u,h]=i.useState(!1),[p,g]=i.useState(a),m=i.useRef(null),x=i.useRef(null),f=i.useRef(null),b=i.useRef(null),y=e=>{if(!b.current||!x.current)return;const t=e.clientX-b.current.x,n=Math.min(s,Math.max(50,b.current.width+t)),o=n*x.current.ratio;x.current.width=n,x.current.height=o;const i=f.current?.querySelector("img");i&&(i.style.width=n+"px",i.style.height=o+"px")},C=()=>{if(!x.current)return;const{width:e,height:t}=x.current;c.update(()=>{const n=d.$getNodeByKey(o);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),x.current=null,b.current=null,window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",C)},N=()=>{h(!1),c.update(()=>{const e=d.$getNodeByKey(o);e&&"function"==typeof e.setCaption&&e.setCaption(p)})},v=()=>{g(a),h(!0),setTimeout(()=>m.current?.focus(),0)};return n.jsxs("div",{ref:f,style:{display:"inline-block",position:"relative",maxWidth:s},children:[n.jsx("img",{src:e,alt:t,width:"inherit"===l?void 0:l,height:"inherit"===r?void 0:r,style:{maxWidth:"100%",display:"block"}}),(a||u)&&n.jsx("div",{style:{textAlign:"center",marginTop:4},children:u?n.jsx("input",{ref:m,className:"lte-input",style:{width:"100%",textAlign:"center"},value:p,onChange:e=>g(e.target.value),onBlur:N,onKeyDown:e=>{"Enter"===e.key&&N()}}):n.jsx("span",{style:{fontSize:13,color:"#666",cursor:"text",display:"inline-block",minWidth:20,minHeight:18},onClick:v,children:a})}),!a&&!u&&n.jsx("div",{style:{textAlign:"center",marginTop:2},children:n.jsx("span",{style:{fontSize:12,color:"#999",cursor:"pointer"},onClick:v,children:"+ Add caption"})}),n.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=f.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,o=t.naturalHeight/t.naturalWidth,i=n*o;b.current={x:e.clientX,y:e.clientY,width:n,height:i},x.current={width:n,height:i,ratio:o},window.addEventListener("mousemove",y),window.addEventListener("mouseup",C)},style:{position:"absolute",bottom:a||u?40:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},$e=e=>d.$applyNodeReplacement(new Oe(e)),Ae=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let o,i;e.width&&(o=e.width),e.height&&(i=e.height);const l=e.style;if((!o||0===o)&&l.width){const e=parseInt(l.width,10);Number.isNaN(e)||(o=e)}if((!i||0===i)&&l.height){const e=parseInt(l.height,10);Number.isNaN(e)||(i=e)}return{node:$e({src:t,altText:n,width:o??"inherit",height:i??"inherit"})}};class Oe extends d.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:n=1080,width:o="inherit",height:i="inherit",caption:l="",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=o,this.__height=i,this.__caption=l}static getType(){return"image"}static clone(e){return new Oe({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,caption:e.__caption,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");if(e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),this.__caption){const t=document.createElement("figure"),n=document.createElement("figcaption");return n.textContent=this.__caption,t.appendChild(e),t.appendChild(n),{element:t}}return{element:e}}static importDOM(){return{img:()=>({conversion:Ae,priority:1}),figure:()=>({conversion:e=>{const t=e.querySelector("img");if(!t)return null;const n=e.querySelector("figcaption"),o=n?.textContent||"",i=Ae(t);return i?.node instanceof Oe&&o&&(i.node.__caption=o),i},priority:1})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height,caption:this.__caption}}static importJSON(e){return new Oe({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height,caption:e.caption})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}setCaption(e){this.getWritable().__caption=e}decorate(){return n.jsx(Me,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth,caption:this.__caption})}}function De({open:e,onClose:t,forPreview:o=!1,children:l}){const r=i.useRef(null);return i.useEffect(()=>{if(!e)return;const n=e=>{r.current&&!r.current.contains(e.target)&&t()},o=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",o)}},[e,t]),e?n.jsx("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:n.jsxs("div",{ref:r,className:"lte-dialog "+(o?"preview":""),children:[n.jsx("button",{type:"button",className:"lte-dialog-close",onClick:t,children:"×"}),l]})}):null}async function Ie(e,{src:t,altText:n="",caption:o=""}){e.update(()=>{const e=$e({src:t,altText:n,caption:o});d.$insertNodes([e])})}function Fe({onImageUpload:e}){const[t]=S.useLexicalComposerContext(),o=i.useRef(null),[l,r]=i.useState(!1),[s,a]=i.useState(""),[c,u]=i.useState(""),[h,p]=i.useState(""),[g,m]=i.useState(),[x,f]=i.useState(!1),b=i.useCallback(async(n,o="",i="")=>{let l;l=e?await e(n):URL.createObjectURL(n),Ie(t,{src:l,altText:o,caption:i})},[t,e]);return i.useEffect(()=>{const e=t.registerCommand(d.PASTE_COMMAND,e=>{if(e instanceof ClipboardEvent){const t=e.clipboardData?.items;if(!t)return!1;for(const n of t)if(n.type.startsWith("image/")){e.preventDefault();const t=n.getAsFile();return t&&b(t,"","").catch(console.error),!0}}return!1},d.COMMAND_PRIORITY_LOW);return()=>e()},[t,b]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("input",{type:"file",ref:o,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&m(t),e.target.value=""}}),n.jsx(ke,{content:"Add Image",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${l?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:n.jsx(v.IoImageOutline,{size:18})})}),n.jsxs(De,{open:l,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:c,onChange:e=>u(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Caption",value:h,onChange:e=>p(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Add image by URL",value:s,onChange:e=>a(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:()=>o.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[n.jsx($.LuUpload,{size:20}),n.jsx("span",{children:"Upload Image"})]}),g&&n.jsx("div",{className:"lte-file-name",children:g.name})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s&&!g||x,onClick:async()=>{if(!x){if(g){f(!0);try{await b(g,c,h)}catch(e){return console.error("Image upload failed:",e),void f(!1)}f(!1)}else{if(!s)return;Ie(t,{src:s,altText:c,caption:h})}m(void 0),u(""),p(""),a(""),r(!1)}},children:x?"Uploading...":"Add Image"})})]})]})}const He=({id:e,provider:t})=>new Ke({id:e,provider:t}),Be="data-lexical-video",ze="data-provider",Pe="315px",We="560px",Ue=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,qe=e=>{const t=e?.getAttribute(Be),n=e?.getAttribute(ze)??"youtube";if(!t)return null;return{node:He({id:t,provider:n})}};class Ke 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 Ke({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return He({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:Pe,width:We,src:Ue(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(ze,this.__provider),e.setAttribute("height",Pe),e.setAttribute("width",We),e.setAttribute("src",Ue(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:qe,priority:0})}}}function Je(){const[e,t]=i.useState(!1),[o,l]=i.useState(!1),[r,s]=i.useState(""),[a]=S.useLexicalComposerContext();return i.useEffect(()=>{e||(s(""),l(!1))},[e]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx(ke,{content:"Embed Video",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${e?"toolbarActive":"toolbar"} icon`,onClick:()=>t(!0),children:n.jsx(A.FaYoutube,{size:18,color:"red"})})}),n.jsxs(De,{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:r,onChange:e=>s(e.target.value)}),o&&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:!r,onClick:()=>{if(!r)return;let e=null,n=null;const o=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(r);o&&11===o[2]?.length&&(e="youtube",n=o[2]);const i=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(r);i&&i[1]&&(e="drive",n=i[1]),n&&e?(a.update(()=>{const t=He({id:n,provider:e});d.$insertNodes([t])}),s(""),l(!1),t(!1)):l(!0)},children:"Embed"})})]})]})}function Ge({value:e}){return n.jsx("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:e}})}function Xe({value:e,triggerLabel:t="Preview"}){const[o,l]=i.useState(!1);return n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx(ke,{content:t,direction:"bottom",children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[n.jsx(O.VscPreview,{size:18}),n.jsx("span",{children:t})]})}),n.jsxs(De,{open:o,onClose:()=>l(!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(Ge,{value:e})]})]})]})}const Ve=[{id:"headings",sep:!0},{id:"fontFamily"},{id:"fontSize"},{id:"textFormats",sep:!0},{id:"dropdown",sep:!0},{id:"color",sep:!0},{id:"quoteCode",sep:!0},{id:"codeBlock"},{id:"alignment",sep:!0},{id:"lists",sep:!0},{id:"blockOptions"},{id:"table",sep:!0},{id:"hline"},{id:"link",sep:!0},{id:"image"},{id:"video"},{id:"utility",sep:!0},{id:"preview"}],Qe=Ve.map(e=>e.id),Ye=({value:o,onImageUpload:r,sourceView:s=!1,onToggleSourceView:a,fullscreen:c=!1,onToggleFullscreen:u,toolbarStyle:h="wrap"})=>{const m="normal"===h?"collapse":h,[x]=S.useLexicalComposerContext(),[f,b]=i.useState({[e.Undo]:!0,[e.Redo]:!0}),[y,N]=i.useState(!1),[j,w]=i.useState(!1),[T,E]=i.useState(0),[R,L]=i.useState(!1),M=i.useRef(null),$=i.useRef(null),A=i.useRef(null),O=i.useRef({}),D=i.useRef({}),I=i.useRef(0),F=i.useRef(null),q=i.useRef(null),[K,J]=i.useState({[e.LeftAlign]:!0}),[G,X]=i.useState({[t.Normal]:!0}),[V,Q]=i.useState("paragraph"),[Y,Z]=i.useState("https://");let te=!0;const ne=()=>{if(te){const e=x.getRootElement();e&&(e.scrollTop=0,te=!1)}const n=d.$getSelection();if(d.$isRangeSelection(n)){const o={[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")};J(o);const i=n.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),s=r.getKey();if(!x.getElementByKey(s))return;if(p.$isListNode(r)){const e=de(i,p.ListNode),t=e?e.getTag():r.getTag();Q(t)}else if("paragraph"===r.getType()||l.$isHeadingNode(r)){let e=null;l.$isHeadingNode(r)&&(e=r.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"===r.getType()};Q(r.getType()),X(n)}else Q(r.getType());const a=(d.$isElementNode(i)?i:r).getFormat();J(t=>({...t,[e.LeftAlign]:0===a||1===a,[e.CenterAlign]:2===a,[e.RightAlign]:3===a,[e.JustifyAlign]:4===a})),"quote"===r.getType()?J(t=>({...t,[e.Quote]:!0})):J(t=>({...t,[e.Quote]:!1}));const c=n.anchor.getNode(),u=c.getParent();k.$isLinkNode(u)?(J(t=>({...t,[e.Link]:!0})),Z(u.getURL()),N(!0)):k.$isLinkNode(c)?(J(t=>({...t,[e.Link]:!0})),Z(c.getURL()),N(!0)):(J(t=>({...t,[e.Link]:!1})),Z("https://"),N(!1))}};i.useEffect(()=>ce(x.registerUpdateListener(({editorState:e})=>{e.read(()=>{ne()})}),x.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(ne(),!1),1),x.registerCommand(d.CAN_UNDO_COMMAND,e=>(b(t=>({...t,undo:!e})),!1),1),x.registerCommand(d.CAN_REDO_COMMAND,e=>(b(t=>({...t,redo:!e})),!1),1)),[]);const ie="scrollbar"===m,le=i.useCallback(()=>{if("collapse"!==m)return;const e=M.current;if(!e)return;const t=e.clientWidth;if(t<=0)return;const n=$.current?$.current.offsetWidth:0,o=Qe.map(e=>{const t=O.current[e];return t&&"none"!==t.style.display&&(D.current[e]=t.offsetWidth),D.current[e]??0});A.current&&(I.current=A.current.offsetWidth);const i=I.current||40,l=e=>{const t=1+(e>0?1:0)+(Qe.length-e);let l=n+6*Math.max(0,t-1)+(e>0?i:0);for(let t=0;t<Qe.length-e;t++)l+=o[t];return l};let r=T;for(;r<Qe.length&&l(r)>t;)r++;for(;r>0&&l(r-1)<=t;)r--;E(e=>e===r?e:r)},[T,m]);i.useEffect(()=>{le()});const re=i.useRef(()=>{});re.current=le,i.useEffect(()=>{if("undefined"==typeof ResizeObserver)return;const e=M.current;if(!e)return;const t=new ResizeObserver(()=>{re.current(),Ne.current()});return t.observe(e),()=>t.disconnect()},[]),i.useEffect(()=>{0===T&&L(!1)},[T]),i.useEffect(()=>{"collapse"!==m&&E(0)},[m]);const se=i.useCallback(()=>{if("scrollbar"!==m)return;const e=M.current,t=F.current,n=q.current;if(!e||!t||!n)return;const o=e.clientWidth;if(e.scrollWidth-o<=1)return void(t.style.display="none");t.style.display="flex";const i=Math.max(24,o/e.scrollWidth*o),l=e.scrollWidth-o,r=o-i,s=l>0?e.scrollLeft/l*r:0;n.style.width=`${i}px`,n.style.transform=`translateX(${s}px)`},[h]),ae=i.useCallback(e=>{e.stopPropagation(),e.preventDefault();const t=M.current,n=q.current;if(!t||!n)return;const o=e.clientX,i=t.scrollLeft,l=t.clientWidth,r=Math.max(24,l/t.scrollWidth*l),s=t.scrollWidth-l,a=l-r,c=e=>{const n=e.clientX-o;t.scrollLeft=a>0?i+n/a*s:0},d=()=>{document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",d)};document.addEventListener("pointermove",c),document.addEventListener("pointerup",d)},[]),ue=i.useCallback(e=>{const t=M.current,n=F.current;if(!t||!n)return;const o=n.getBoundingClientRect(),i=(e.clientX-o.left)/o.width;t.scrollLeft=i*t.scrollWidth-t.clientWidth/2},[]),he=i.useRef(null),pe=i.useCallback(()=>{const e=he.current;if(e)for(const t of e.querySelectorAll(".lte-toolbar-row svg:not(.chevron), .lte-overflow-panel svg:not(.chevron)")){if(t.closest(".lexical-stepper"))continue;const e=t;try{const t=e.viewBox?.baseVal;if(!t||!t.width)continue;let n=1/0,o=1/0,i=-1/0,l=-1/0;if(e.querySelectorAll("path, circle, rect, ellipse, polygon, polyline, line").forEach(e=>{const t=e.getBBox();(t.width||t.height)&&(n=Math.min(n,t.x),o=Math.min(o,t.y),i=Math.max(i,t.x+t.width),l=Math.max(l,t.y+t.height))}),i===-1/0)continue;const r=((i-n)/t.width+(l-o)/t.height)/2;if(!isFinite(r)||r<=0)continue;const s=Math.min(22,Math.max(17,15/r));parseFloat(e.style.width)!==s&&(e.style.width=`${s}px`,e.style.height=`${s}px`)}catch{}}},[]);i.useEffect(()=>{pe()}),i.useEffect(()=>{se()});const Ne=i.useRef(()=>{});Ne.current=se,i.useEffect(()=>{if("scrollbar"!==m)return;const e=M.current;if(!e)return;const t=()=>se();return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[m,se]);const je=t=>{switch(t){case e.Bold:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"bold");break;case e.Italics:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"italic");break;case e.Underline:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"underline");break;case e.Lowercase:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"lowercase");break;case e.Uppercase:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"uppercase");break;case e.Capitalize:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"capitalize");break;case e.Strikethrough:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"strikethrough");break;case e.Superscript:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"superscript");break;case e.Subscript:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"subscript");break;case e.Highlight:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"highlight");break;case e.Code:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"code");break;case e.Quote:x.update(()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&l.$isQuoteNode(t)?ee(e,()=>d.$createParagraphNode()):oe(e,()=>l.$createQuoteNode())}});break;case e.Link:we(),N(!0);break;case e.LeftAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"left");break;case e.RightAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"right");break;case e.CenterAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"center");break;case e.JustifyAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"justify");break;case e.Undo:x.dispatchCommand(d.UNDO_COMMAND,void 0);break;case e.Redo:x.dispatchCommand(d.REDO_COMMAND,void 0);break;case e.ClearFormatting:x.update(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.getNodes().filter(d.$isTextNode);for(const e of t)e.setFormat(0),e.setStyle("")});break;case e.HorizontalRule:x.dispatchCommand(g.INSERT_HORIZONTAL_RULE_COMMAND,void 0);break;case e.Indent:x.dispatchCommand(d.INDENT_CONTENT_COMMAND,void 0);break;case e.Outdent:x.dispatchCommand(d.OUTDENT_CONTENT_COMMAND,void 0)}},we=i.useCallback(()=>{x.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&!e.isCollapsed()&&(y?x.dispatchCommand(k.TOGGLE_LINK_COMMAND,null):""!==Y&&x.dispatchCommand(k.TOGGLE_LINK_COMMAND,Y))})},[x,y,Y]),Ee=i.useCallback(()=>{Z(""),x.dispatchCommand(k.TOGGLE_LINK_COMMAND,null),N(!1)},[x]),Me=e=>Qe.indexOf(e)>=Qe.length-T,$e={headings:n.jsx(xe,{updateHeading:e=>{x.update(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&oe(t,"normal"===e?()=>d.$createParagraphNode():()=>l.$createHeadingNode(e))})},headingSelectionMap:G}),fontFamily:n.jsx(Se,{}),fontSize:n.jsx(Te,{}),textFormats:n.jsx(n.Fragment,{children:H.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(me,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(t),children:i})},t))}),dropdown:n.jsx(ge,{onAction:je,selectionMap:K}),color:n.jsxs(n.Fragment,{children:[n.jsx(ve,{}),B.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(e),children:o})},e))]}),quoteCode:n.jsx(n.Fragment,{children:z.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(e),children:o})},e))}),codeBlock:n.jsx(_e,{}),alignment:n.jsx(Ce,{onAction:je,alignmentSelectionMap:K}),lists:n.jsx(Re,{blockType:V}),blockOptions:n.jsx(n.Fragment,{children:W.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(me,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(t),children:i})},t))}),table:n.jsx(Le,{}),hline:n.jsx(n.Fragment,{children:U.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(e),children:o})},e))}),link:n.jsx(ke,{content:"Link",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[e.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(e.Link),disabled:!!f[e.Link],children:n.jsx(_.IoIosLink,{})})}),image:n.jsx(Fe,{onImageUpload:r}),video:n.jsx(Je,{}),utility:n.jsxs(n.Fragment,{children:[n.jsx(ke,{content:"Find & Replace",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Find & Replace",className:`size-10 lexical-btn ${j?"toolbarActive":"toolbar"} icon`,onClick:()=>w(e=>!e),children:n.jsx(v.IoSearchOutline,{})})}),n.jsx(ke,{content:"Source Code View",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Source Code View",className:`size-10 lexical-btn ${s?"toolbarActive":"toolbar"} icon`,onClick:()=>a?.(),children:n.jsx(v.IoCodeOutline,{})})}),n.jsx(ke,{content:c?"Exit Fullscreen":"Fullscreen",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":c?"Exit Fullscreen":"Fullscreen",className:`size-10 lexical-btn ${c?"toolbarActive":"toolbar"} icon`,onClick:()=>u?.(),children:c?n.jsx(C.BsFullscreenExit,{}):n.jsx(C.BsFullscreen,{})})})]}),preview:n.jsx(Xe,{value:o})};return n.jsxs("div",{ref:he,className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[n.jsxs("div",{ref:M,className:"lte-toolbar-row "+(ie?"useScroll":"collapse"===m?"lte-nowrap":"lte-wrap"),onMouseDown:e=>e.preventDefault(),children:[n.jsx("div",{ref:$,className:"lte-toolbar-primary",style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:P.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(me,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${K[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>je(t),disabled:!!f[t],children:i})},o))}),Ve.map(({id:e,sep:t})=>{const o=Me(e);return n.jsxs("div",{ref:t=>{O.current[e]=t},style:o?{display:"none"}:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[t?n.jsx(me,{}):null,o?null:$e[e]]},e)}),T>0&&n.jsx(ke,{content:"More tools",direction:"bottom",children:n.jsx("button",{type:"button",ref:A,"aria-label":"More tools",className:`size-10 lexical-btn ${R?"toolbarActive":"toolbar"} icon`,onClick:()=>L(e=>!e),children:n.jsx(C.BsThreeDots,{})})})]}),ie&&n.jsx("div",{ref:F,className:"lte-custom-scrollbar",onPointerDown:ue,"aria-hidden":"true",children:n.jsx("div",{ref:q,className:"lte-custom-scrollbar-thumb",onPointerDown:ae})}),y&&n.jsx(fe,{linkUrl:Y,setLinkUrl:Z,removeLink:Ee,onConfirm:e=>{x.dispatchCommand(k.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),Z(e),N(!1)},onCancel:()=>{Z(""),N(!1)}}),R&&n.jsx(ye,{anchorRef:A,onClose:()=>L(!1),children:Ve.filter(({id:e})=>Me(e)&&$e[e]).map(({id:e,sep:t},o)=>n.jsxs("div",{className:"lte-overflow-item",children:[t&&o>0?n.jsx(me,{}):null,$e[e]]},e))}),j&&n.jsx(be,{onClose:()=>w(!1)})]})};function Ze(e,t){const n=d.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let o=[];const i=[];for(const t of n)if(!nt.has(t.nodeName)){const n=ot(t,e,i,!1);null!==n&&(o=o.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()}}(i),o}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 n=document.createElement("div"),o=d.$getRoot().getChildren();for(let i=0;i<o.length;i++)tt(e,o[i],n,t);return n.innerHTML}function tt(e,t,n,o=null){let i=null===o||t.isSelected(o);const l=d.$isElementNode(t)&&t.excludeFromCopy("html");let r=t;if(null!==o){let e=d.$cloneWithProperties(t);e=d.$isTextNode(e)&&null!==o?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!d.$isTokenOrSegmented(t)&&null!==n){const[o,i]=n,l=e.isBackward(),r=o.getNode(),s=i.getNode(),a=t.is(r),c=t.is(s);if(a||c){const[n,o]=d.$getCharacterOffsets(e),i=r.is(s),a=t.is(l?s:r),c=t.is(l?r:s);let u,h=0;i?(h=n>o?o:n,u=n>o?n:o):a?(h=l?o:n,u=void 0):c&&(h=0,u=l?n:o),t.__text=t.__text.slice(h,u)}}return t}(o,e):e,r=e}const s=d.$isElementNode(r)?r.getChildren():[],a=d.getRegisteredNode(e,r.getType());let c;c=a&&void 0!==a.exportDOM?a.exportDOM(e,r):r.exportDOM(e);const{element:u,after:h}=c;if(!u)return!1;const p=document.createDocumentFragment();for(let n=0;n<s.length;n++){const l=s[n],r=tt(e,l,p,o);!i&&d.$isElementNode(t)&&r&&t.extractWithChild(l,o,"html")&&(i=!0)}if(i&&!l){if((d.isHTMLElement(u)||d.isDocumentFragment(u))&&u.append(p),n.append(u),h){const e=h.call(r,u);e&&(d.isDocumentFragment(u)?u.replaceChildren(e):u.replaceWith(e))}}else n.append(p);return i}const nt=new Set(["STYLE","SCRIPT"]);function ot(e,t,n,o,i=new Map,l){let r=[];if(nt.has(e.nodeName))return r;let s=null;const a=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let i=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===i||(i.priority||0)<=(n.priority||0))&&(i=n)}return null!==i?i.conversion:null}(e,t),c=a?a(e):null;let u=null;if(null!==c){u=c.after;const t=c.node;if(s=Array.isArray(t)?t[t.length-1]:t,null!==s){for(const[,e]of i)if(s=e(s,l),!s)break;s&&r.push(...Array.isArray(t)?t:[s])}null!=c.forChild&&i.set(e.nodeName,c.forChild)}const h=e.childNodes;let p=[];const g=(null==s||!d.$isRootOrShadowRoot(s))&&(null!=s&&d.$isBlockElementNode(s)||o);for(let e=0;e<h.length;e++)p.push(...ot(h[e],t,n,g,new Map(i),s));return null!=u&&(p=u(p)),d.isBlockDomNode(e)&&(p=function(e,t,n){const o=e.style.textAlign,i=[];let l=[];for(let e=0;e<t.length;e++){const r=t[e];if(d.$isBlockElementNode(r))o&&!r.getFormat()&&r.setFormat(o),i.push(r);else if(l.push(r),e===t.length-1||e<t.length-1&&d.$isBlockElementNode(t[e+1])){const e=n();e.setFormat(o),e.append(...l),i.push(e),l=[]}}return i}(e,p,g?()=>{const e=new d.ArtificialNode__DO_NOT_USE;return n.push(e),e}:d.$createParagraphNode)),null==s?p.length>0?r=r.concat(p):d.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(d.isInlineDomNode(e.nextSibling)&&d.isInlineDomNode(e.previousSibling))}(e)&&(r=r.concat(d.$createLineBreakNode())):d.$isElementNode(s)&&s.append(...p),r}function it({value:e,onChange:t}){const[o]=S.useLexicalComposerContext(),[l,r]=i.useState(!0);return i.useEffect(()=>{e&&l&&(r(!1),o.update(()=>{if(et(o)!==e){d.$getRoot().clear();const t=(new DOMParser).parseFromString(e,"text/html"),n=Ze(o,t);d.$insertNodes(n)}}))},[o,e,l]),i.useEffect(()=>{r(!0)},[e]),n.jsx(I.OnChangePlugin,{onChange:e=>{e.read(()=>{t(et(o))})}})}function lt({applyRef:e,onExit:t}){const[o]=S.useLexicalComposerContext(),[l,r]=i.useState(()=>o.getEditorState().read(()=>et(o))),s=i.useRef(l),a=e=>{e!==s.current&&(o.update(()=>{const t=d.$getRoot();if(t.clear(),t.selectEnd(),e){const t=(new DOMParser).parseFromString(e,"text/html"),n=Ze(o,t);n.length>0&&d.$insertNodes(n)}}),s.current=e)};return i.useEffect(()=>(e.current=()=>{a(l),t()},()=>{e.current=null}),[e,l,t,o]),n.jsxs("div",{className:"lexical-source-view",children:[n.jsx("textarea",{className:"lexical-source-textarea",value:l,onChange:e=>r(e.target.value),"aria-label":"HTML source",spellCheck:!1}),n.jsxs("div",{className:"lexical-source-actions",children:[n.jsx(ke,{content:"Apply HTML to the editor",direction:"top",children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>a(l),children:[n.jsx(R.MdCheck,{size:16}),n.jsx("span",{className:"label",children:"Update"})]})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{a(l),t()},children:"Done"})]})]})}function rt({showWordCount:e=!0,showCharCount:t=!0,rightSlot:o}){const[l]=S.useLexicalComposerContext(),[r,s]=i.useState({words:0,chars:0});return i.useEffect(()=>{const e=e=>{e.read(()=>{const e=d.$getRoot().getTextContent(),t=e.trim();s({words:t?t.split(/\s+/).length:0,chars:e.length})})};return e(l.getEditorState()),l.registerUpdateListener(({editorState:t})=>{e(t)})},[l]),n.jsxs("div",{className:"lexical-status-bar",children:[e&&n.jsxs("span",{children:[r.words," words"]}),t&&n.jsxs("span",{children:[r.chars," characters"]}),o&&n.jsx("div",{className:"lexical-status-bar-right",children:o})]})}function st({theme:e,toolbarStyle:t,onThemeChange:o,onToolbarStyleChange:i}){const l="normal"===t?"collapse":t,r=[{value:"light",label:"Light theme",icon:n.jsx(C.BsSun,{})},{value:"dark",label:"Dark theme",icon:n.jsx(C.BsMoon,{})},{value:"system",label:"Follow system theme",icon:n.jsx(R.MdMonitor,{})}],s=[{value:"wrap",label:"Toolbar: wrap to new lines",icon:n.jsx(R.MdWrapText,{})},{value:"collapse",label:'Toolbar: collapse into "..."',icon:n.jsx(C.BsThreeDots,{})},{value:"scrollbar",label:"Toolbar: scroll in one row",icon:n.jsx(y.TbArrowsLeftRight,{})}];return n.jsxs("div",{className:"lexical-display-controls",role:"group","aria-label":"Display settings",children:[n.jsx("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Theme",children:r.map(t=>n.jsx(ke,{content:t.label,direction:"top",children:n.jsx("button",{type:"button",role:"radio","aria-checked":e===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(e===t.value?"active":""),onClick:()=>o?.(t.value),children:t.icon})},t.value))}),n.jsx("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Toolbar style",children:s.map(e=>n.jsx(ke,{content:e.label,direction:"top",children:n.jsx("button",{type:"button",role:"radio","aria-checked":l===e.value,"aria-label":e.label,className:"lte-mini-btn btn "+(l===e.value?"active":""),onClick:()=>i?.(e.value),children:e.icon})},e.value))})]})}const at=({id:e})=>new gt({id:e}),ct="data-lexical-youtube",dt="315px",ut="560px",ht=e=>`https://www.youtube-nocookie.com/embed/${e}`,pt=e=>{const t=e?.getAttribute(ct);if(!t)return null;return{node:at({id:t})}};class gt extends d.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new gt({id:e.__id,key:e.getKey()})}static importJSON(e){return at({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return n.jsx("iframe",{height:dt,width:ut,src:ht(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(ct,this.__id),e.setAttribute("height",dt),e.setAttribute("width",ut),e.setAttribute("src",ht(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:pt,priority:0})}}}class mt extends d.TextNode{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new mt(e.__text,e.__key)}static importDOM(){const e=d.TextNode.importDOM();return{...e,span:()=>({conversion:xt(e?.span),priority:1}),div:()=>({conversion:xt(e?.div),priority:1}),p:()=>({conversion:xt(e?.p),priority:1}),b:()=>({conversion:xt(e?.b),priority:1}),strong:()=>({conversion:xt(e?.strong),priority:1}),i:()=>({conversion:xt(e?.i),priority:1}),em:()=>({conversion:xt(e?.em),priority:1}),u:()=>({conversion:xt(e?.u),priority:1}),s:()=>({conversion:xt(e?.s),priority:1}),strike:()=>({conversion:xt(e?.strike),priority:1}),code:()=>({conversion:xt(e?.code),priority:1})}}static importJSON(e){return function(e=""){return d.$applyNodeReplacement(new mt(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function xt(e){return t=>{const n=e?.(t);if(!n)return null;const o=n.conversion(t);if(!o)return o;const i=t.style,l=[];i.backgroundColor&&l.push(`background-color: ${i.backgroundColor}`),i.color&&l.push(`color: ${i.color}`),i.fontFamily&&l.push(`font-family: ${i.fontFamily}`),i.fontWeight&&l.push(`font-weight: ${i.fontWeight}`),i.fontSize&&l.push(`font-size: ${i.fontSize}`),i.fontStyle&&l.push(`font-style: ${i.fontStyle}`),i.textDecoration&&l.push(`text-decoration: ${i.textDecoration}`),i.whiteSpace&&l.push(`white-space: ${i.whiteSpace}`),i.textAlign&&l.push(`text-align: ${i.textAlign}`);const r=t.getAttribute("style");if(r){r.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!l.some(e=>e.startsWith(t))&&l.push(e.trim())})}return{...o,forChild:(e,t)=>{const n=o?.forChild??(e=>e),i=n(e,t);if(d.$isTextNode(i)&&l.length>0){const e=l.join("; ");return i.setStyle(e)}return i}}}}const ft={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",code:"lexical-code-block",hr:"lexical-hr",indent:"lexical-indent",table:"lexical-table",tableRow:"lexical-table-row",tableCell:"lexical-table-cell",codeHighlight:{keyword:"lexical-code-token-keyword",string:"lexical-code-token-string",number:"lexical-code-token-number",comment:"lexical-code-token-comment",function:"lexical-code-token-function",operator:"lexical-code-token-operator",punctuation:"lexical-code-token-punctuation"}},bt=i.memo(function({name:e,value:t,onChange:b,placeholder:y,maxWidth:C=null,height:N=null,onImageUpload:v,showWordCount:j=!0,showCharCount:w=!0,theme:S="system",toolbarStyle:T="collapse",showDisplayControls:E=!0,onThemeChange:_,onToolbarStyleChange:R}){const[L,M]=i.useState(!1),[$,A]=i.useState(!1),O=i.useRef(null),[I,F]=i.useState(!1),[H,B]=i.useState(S),[z,P]=i.useState("normal"===T?"collapse":T);i.useEffect(()=>{B(S)},[S]),i.useEffect(()=>{P("normal"===T?"collapse":T)},[T]),i.useEffect(()=>{if("system"!==H||"undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-color-scheme: dark)");F(e.matches);const t=e=>F(e.matches);return e.addEventListener?(e.addEventListener("change",t),()=>e.removeEventListener("change",t)):(e.addListener(t),()=>e.removeListener(t))},[H]);const W="dark"===H||"system"===H&&I;i.useEffect(()=>{if(!$)return;const e=e=>{"Escape"===e.key&&A(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[$]);const U=i.useMemo(()=>({namespace:e,theme:ft,onError:e=>{console.error("Lexical error:",e)},nodes:[mt,{replace:d.TextNode,with:e=>new mt(e.__text),withKlass:mt},l.HeadingNode,r.CodeHighlightNode,r.CodeNode,p.ListNode,p.ListItemNode,l.QuoteNode,k.LinkNode,Oe,gt,Ke,g.HorizontalRuleNode,f.TableNode,f.TableRowNode,f.TableCellNode]}),[e]);return n.jsx("div",{className:`lexical-text-editor lexical-editor-container ${$?"lexical-fullscreen":""} ${W?"lexical-dark":""}`,style:{maxWidth:$?"none":C||"1090px"},children:n.jsxs(o.LexicalComposer,{initialConfig:U,children:[n.jsx("div",{className:"lexical-toolbar-container",children:n.jsx(Ye,{value:t,onImageUpload:v,sourceView:L,onToggleSourceView:()=>{M(e=>!e||(O.current?.(),!1))},fullscreen:$,onToggleFullscreen:()=>{A(e=>!e)},toolbarStyle:z})}),n.jsx("div",{className:"lexical-editor-inner",style:L?{display:"none"}:void 0,children:n.jsx(s.RichTextPlugin,{contentEditable:n.jsx(a.ContentEditable,{className:"lexical-content-editable",style:{height:N||"500px"}}),placeholder:n.jsx("div",{className:"lexical-placeholder",children:y||"Some Text"}),ErrorBoundary:c.LexicalErrorBoundary})}),L&&n.jsx(lt,{applyRef:O,onExit:()=>M(!1)}),(j||w||E)&&n.jsx(rt,{showWordCount:j,showCharCount:w,rightSlot:E?n.jsx(st,{theme:H,toolbarStyle:z,onThemeChange:e=>{B(e),_?.(e)},onToolbarStyleChange:e=>{P(e),R?.(e)}}):void 0}),n.jsx(u.HistoryPlugin,{}),n.jsx(h.ListPlugin,{}),n.jsx(x.TablePlugin,{}),n.jsx(m.HorizontalRulePlugin,{}),n.jsx(D.LinkPlugin,{}),n.jsx(it,{value:t,onChange:b})]})})});exports.LexicalTextEditor=bt;
|
|
1
|
+
"use strict";var e,t,n=require("react/jsx-runtime"),o=require("@lexical/react/LexicalComposer"),i=require("react"),l=require("@lexical/rich-text"),r=require("@lexical/code"),s=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("@lexical/react/LexicalHorizontalRuleNode"),m=require("@lexical/react/LexicalHorizontalRulePlugin"),x=require("@lexical/react/LexicalTablePlugin"),f=require("@lexical/table"),b=require("react-icons/rx"),N=require("react-icons/tb"),y=require("react-icons/bs"),C=require("react-icons/ai"),v=require("react-icons/io5"),j=require("react-icons/pi"),S=require("react-icons/ri"),w=require("@lexical/react/LexicalComposerContext"),T=require("@lexical/link"),k=require("react-icons/hi2"),E=require("react-dom"),_=require("react-icons/io"),R=require("react-icons/md"),$=require("react-icons/bi"),M=require("react-color"),L=require("react-icons/lu"),A=require("react-icons/fa"),O=require("react-icons/vsc"),D=require("@lexical/react/LexicalLinkPlugin"),F=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.ClearFormatting="clearFormatting",e.CodeBlock="codeBlock",e.HorizontalRule="horizontalRule",e.Indent="indent",e.Outdent="outdent",e.Table="table",e.FindReplace="findReplace",e.SourceView="sourceView",e.Fullscreen="fullscreen"}(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 I=[{id:e.Lowercase,icon:n.jsx(b.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:e.Uppercase,icon:n.jsx(b.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:e.Capitalize,icon:n.jsx(b.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:e.Superscript,icon:n.jsx(y.BsSuperscript,{}),label:"Superscript"},{id:e.Subscript,icon:n.jsx(y.BsSubscript,{}),label:"Subscript"}],H=[{id:e.Bold,icon:n.jsx(N.TbBold,{}),label:"Bold"},{id:e.Italics,icon:n.jsx(N.TbItalic,{}),label:"Italics"},{id:e.Underline,icon:n.jsx(N.TbUnderline,{}),label:"Underline"},{id:e.Strikethrough,icon:n.jsx(C.AiOutlineStrikethrough,{}),label:"Strikethrough"}],B=[{id:e.Highlight,icon:n.jsx(j.PiHighlighterLight,{}),label:"Highlight"}],z=[{id:e.Quote,icon:n.jsx(y.BsChatSquareQuote,{}),label:"Quote"},{id:e.Code,icon:n.jsx(v.IoCodeSlashOutline,{}),label:"Code"}],P=[{id:e.Undo,icon:n.jsx(y.BsArrowCounterclockwise,{}),label:"Undo"},{id:e.Redo,icon:n.jsx(y.BsArrowClockwise,{}),label:"Redo"},{id:e.ClearFormatting,icon:n.jsx(S.RiEraserLine,{}),label:"Clear Formatting"}],W=[{id:e.Indent,icon:n.jsx(S.RiIndentIncrease,{}),label:"Indent"},{id:e.Outdent,icon:n.jsx(S.RiIndentDecrease,{}),label:"Outdent"}],U=[{id:e.HorizontalRule,icon:n.jsx(N.TbSeparatorHorizontal,{}),label:"Horizontal Rule"}],K=[{id:e.LeftAlign,icon:n.jsx(y.BsJustifyLeft,{}),label:"Left Align"},{id:e.CenterAlign,icon:n.jsx(y.BsTextCenter,{}),label:"Center Align"},{id:e.RightAlign,icon:n.jsx(y.BsJustifyRight,{}),label:"Right Align"},{id:e.JustifyAlign,icon:n.jsx(y.BsJustify,{}),label:"Justify Align"}],q=[{id:"normal",label:"Normal",icon:n.jsx(y.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:n.jsx(y.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:n.jsx(y.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:n.jsx(y.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:n.jsx(y.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:n.jsx(y.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:n.jsx(y.BsTypeH6,{})}],G=[{id:"plaintext",label:"Plain Text"},{id:"javascript",label:"JavaScript"},{id:"typescript",label:"TypeScript"},{id:"python",label:"Python"},{id:"java",label:"Java"},{id:"csharp",label:"C#"},{id:"cpp",label:"C++"},{id:"php",label:"PHP"},{id:"ruby",label:"Ruby"},{id:"go",label:"Go"},{id:"rust",label:"Rust"},{id:"swift",label:"Swift"},{id:"kotlin",label:"Kotlin"},{id:"html",label:"HTML"},{id:"css",label:"CSS"},{id:"sql",label:"SQL"},{id:"json",label:"JSON"},{id:"bash",label:"Bash"},{id:"markdown",label:"Markdown"},{id:"yaml",label:"YAML"},{id:"xml",label:"XML"}],J=i.createContext(()=>{});function X(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.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 V=new Map;function Y(e){let t=V.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,o]=e.split(/:([^]+)/);n&&o&&(t[n.trim()]=o.trim())}return t}(e),V.set(e,t)),t}function Q(e,t){(d.$isRangeSelection(e)?e.isCollapsed():d.$isTextNode(e)||d.$isElementNode(e))||X(280);const n=Y(d.$isRangeSelection(e)?e.style:d.$isTextNode(e)?e.getStyle():e.getTextStyle()),o=Object.entries(t).reduce((t,[o,i])=>("function"==typeof i?t[o]=i(n[o],e):null===i?delete t[o]:t[o]=i,t),{...n}),i=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(o);d.$isRangeSelection(e)||d.$isTextNode(e)?e.setStyle(i):e.setTextStyle(i),V.set(i,o)}function Z(e,t){if(d.$isRangeSelection(e)&&e.isCollapsed()){Q(e,t);const n=e.anchor.getNode();d.$isElementNode(n)&&n.isEmpty()&&Q(n,t)}!function(e){const t=d.$getSelection();if(!t)return;const n=new Map,o=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 i=t.getNodes();for(const t of i){if(!d.$isTextNode(t)||!t.canHaveFormat())continue;const[n,i]=o(t);i!==n&&(d.$isTokenOrSegmented(t)||0===n&&i===t.getTextContentSize()?e(t):e(t.splitText(n,i)[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:o,offset:i,type:l}=t;t.set(n.key,n.offset,n.type),n.set(o,i,l)}}(t)}(e=>{Q(e,t)})}function ee(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function te(e,t,n=ee){if(null===e)return;const o=e.getStartEndPoints(),i=new Map;let l=null;if(o){const[e,t]=o;l=d.$createRangeSelection(),l.anchor.set(e.key,e.offset,e.type),l.focus.set(t.key,t.offset,t.type);const n=d.$findMatchingParent(e.getNode(),d.INTERNAL_$isBlock),r=d.$findMatchingParent(t.getNode(),d.INTERNAL_$isBlock);d.$isElementNode(n)&&i.set(n.getKey(),n),d.$isElementNode(r)&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(d.$isElementNode(t)&&d.INTERNAL_$isBlock(t))i.set(t.getKey(),t);else if(null===o){const e=d.$findMatchingParent(t,d.INTERNAL_$isBlock);d.$isElementNode(e)&&i.set(e.getKey(),e)}for(const[e,o]of i){const i=t();n(o,i),o.replace(i,!0),l&&(e===l.anchor.key&&l.anchor.set(i.getKey(),l.anchor.offset,l.anchor.type),e===l.focus.key&&l.focus.set(i.getKey(),l.focus.offset,l.focus.type))}l&&e.is(d.$getSelection())&&d.$setSelection(l)}function ne(e){return e.getNode().isAttached()}function oe(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 ie(e,t,n=null){const o=e.getStartEndPoints(),i=o?o[0]:null,l=e.getNodes(),r=l.length;if(null!==i&&(0===r||1===r&&"element"===i.type&&0===i.getNode().getChildrenSize())){const e="text"===i.type?i.getNode().getParentOrThrow():i.getNode(),o=e.getChildren();let l=t();return l.setFormat(e.getFormatType()),l.setIndent(e.getIndent()),o.forEach(e=>l.append(e)),n&&(l=n.append(l)),void e.replace(l)}let s=null,a=[];for(let o=0;o<r;o++){const i=l[o];d.$isRootOrShadowRoot(i)?(le(e,a,a.length,t,n),a=[],s=i):null===s||null!==s&&d.$hasAncestor(i,s)?a.push(i):(le(e,a,a.length,t,n),a=[i])}le(e,a,a.length,t,n)}function le(e,t,n,o,i=null){if(0===t.length)return;const l=t[0],r=new Map,s=[];let a=d.$isElementNode(l)?l:l.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 i=n.getParent();if(null!==i&&i.isInline()&&(i=i.getParent()),null!==i&&d.$isLeafNode(n)&&!h.has(n.getKey())){const e=i.getKey();if(void 0===r.get(e)){const t=o();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),s.push(t),r.set(e,t),i.getChildren().forEach(e=>{t.append(e),h.add(e.getKey()),d.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>h.add(e))}),oe(i)}}else if(u.has(n.getKey())){d.$isElementNode(n)||X(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),s.push(e),n.remove(!0)}}if(null!==i)for(let e=0;e<s.length;e++){const t=s[e];i.append(t)}let p=null;if(d.$isRootOrShadowRoot(a))if(c)if(null!==i)a.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(d.$isElementNode(e)&&(a=e),null===e)if(i)a.append(i);else for(let e=0;e<s.length;e++){const t=s[e];a.append(t),p=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<s.length;t++){const n=s[t];e.insertBefore(n),p=n}}else if(i)a.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];a.insertAfter(t),p=t}const g=d.$getPreviousSelection();d.$isRangeSelection(g)&&ne(g.anchor)&&ne(g.focus)?d.$setSelection(g.clone()):null!==p?p.selectEnd():e.dirty=!0}function re(e,t,n){const o=Y(e.getStyle());return null!==o&&o[t]||n}function se(e,t,n=""){let o=null;const i=e.getNodes(),l=e.anchor,r=e.focus,s=e.isBackward(),a=s?r.offset:l.offset,c=s?r.getNode():l.getNode();if(d.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const n=Y(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<i.length;e++){const l=i[e];if((0===e||0!==a||!l.is(c))&&d.$isTextNode(l)){const e=re(l,t,n);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?n:o}const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ce=ae&&"documentMode"in document?document.documentMode:null;function de(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function ue(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function he({open:e,onOpenChange:t,children:o}){const l=i.useRef(null),r=i.useRef(null);return i.useEffect(()=>{function n(e){l.current?.contains(e.target)||r.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:i.Children.map(o,e=>e&&"object"==typeof e?e.type===pe?i.cloneElement(e,{triggerRef:l}):e.type===ge?i.cloneElement(e,{contentRef:r,triggerRef:l}):e:e)})}function pe({children:e,triggerRef:t}){return n.jsx("div",{className:"popover-trigger",ref:t,children:e})}function ge({open:e,align:t="start",children:o,contentRef:l,triggerRef:r}){const s=i.useRef(null),[a,c]=i.useState(!1);return i.useEffect(()=>{if(!e)return;const n=()=>{const e=s.current,n=r?.current;if(!e||!n)return;const o=n.closest(".lexical-text-editor"),i=!!o?.classList.contains("lexical-dark");e.classList.contains("lexical-dark")!==i&&e.classList.toggle("lexical-dark",i);const l=n.getBoundingClientRect(),a=e.offsetWidth,d=e.offsetHeight;let u=l.left;"center"===t?u=l.left+l.width/2-a/2:"end"===t&&(u=l.right-a),u=Math.max(8,Math.min(window.innerWidth-a-8,u));let h=l.bottom+4;h+d>window.innerHeight-8&&l.top>d+8&&(h=l.top-d-4),e.style.left=`${u}px`,e.style.top=`${h}px`,c(i)};return n(),requestAnimationFrame(n),window.addEventListener("resize",n),document.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),document.removeEventListener("scroll",n,!0)}},[e,t,r]),e?E.createPortal(n.jsx("div",{ref:s,className:"lexical-text-editor"+(a?" lexical-dark":""),"data-lte-popover-portal":"true",onMouseDown:e=>e.preventDefault(),style:{position:"fixed",top:0,left:0,zIndex:9999,background:"transparent",border:"none",borderRadius:0,boxShadow:"none",padding:0,margin:0,height:"fit-content",maxWidth:"none"},children:n.jsx("div",{ref:e=>{l.current=e},className:"popover-content",style:{position:"static",top:"auto",left:"auto",borderRadius:6,border:"none",margin:0,width:"100%"},children:o})}),document.body):null}function me({onAction:e,selectionMap:t}){const[o,l]=i.useState(!1),r=i.useRef(null),s=i.useRef(null);return n.jsxs(he,{open:o,onOpenChange:l,children:[n.jsx(pe,{triggerRef:r,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[n.jsx("span",{children:"Aa"}),n.jsx(k.HiChevronDown,{className:"chevron "+(o?"rotated":"")})]})}),n.jsx(ge,{open:o,align:"start",onClose:()=>l(!1),contentRef:s,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:I.map(({id:o,label:i,icon:r})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),l(!1)},style:{minWidth:130},children:[r,n.jsx("span",{className:"label",children:i})]},o))})})]})}function xe(){return n.jsx("div",{className:"lexical-separator"})}function fe({updateHeading:e,headingSelectionMap:t}){const o=q.find(e=>t[e.id]),[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);return n.jsxs(he,{open:l,onOpenChange:r,children:[n.jsx(pe,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),style:{minWidth:132},children:[o?.icon,n.jsx("span",{children:o?.label}),n.jsx(k.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(ge,{open:l,align:"start",onClose:()=>r(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:q.map(({id:o,label:i,icon:l})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),r(!1)},children:[l,n.jsx("span",{className:"label",children:i})]},o))})})]})}function be({linkUrl:e,setLinkUrl:t,onConfirm:o,onCancel:l,removeLink:r}){const[s,a]=i.useState(!1),c=i.useRef(null),d=i.useRef(null);return i.useEffect(()=>{"https://"===e&&a(!0)},[e]),i.useEffect(()=>{s&&d.current?.focus()},[s]),i.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]),n.jsxs("div",{ref:c,className:"lexical-text-editor-link link-editor-container",children:[n.jsx("div",{className:"link-editor-input-wrapper",children:s?n.jsx("input",{ref:d,className:"link-editor-input",value:e,onChange:e=>t(e.target.value),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),o(e),a(!1)):"Escape"===t.key&&(t.preventDefault(),a(!1),l())}}):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:()=>{s?(o(e),a(!1)):a(!0)},children:s?n.jsx(R.MdCheck,{size:18}):n.jsx(y.BsPencilSquare,{size:14})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:r,children:n.jsx($.BiUnlink,{size:14,style:{stroke:"black"}})})]})]})}function Ne({onClose:e}){const[t]=w.useLexicalComposerContext(),[o,l]=i.useState(""),[r,s]=i.useState(""),[a,c]=i.useState(!1),[u,h]=i.useState([]),[p,g]=i.useState(0),m=i.useRef(null);i.useEffect(()=>{m.current?.focus()},[]);const x=()=>{if(!o)return[];const e=a?o:o.toLowerCase(),t=[],n=d.$getRoot().getAllTextNodes();for(const o of n){const n=a?o.getTextContent():o.getTextContent().toLowerCase();let i=n.indexOf(e);for(;-1!==i;)t.push({key:o.getKey(),start:i}),i=n.indexOf(e,i+e.length)}return t};i.useEffect(()=>{const e=t.getEditorState().read(x);h(e),g(0)},[t,o,a]),i.useEffect(()=>t.registerUpdateListener(({editorState:e})=>{const t=e.read(x);h(t),g(e=>0===t.length?0:Math.min(e,t.length-1))}),[t,o,a]);const f=e=>{if(0===u.length)return;const n=(p+e+u.length)%u.length,i=u[n];g(n),t.update(()=>{const e=d.$getNodeByKey(i.key);d.$isTextNode(e)&&e.select(i.start,i.start+o.length)}),requestAnimationFrame(()=>{const e=t.getElementByKey(i.key);e?.scrollIntoView({block:"nearest"})})},b=o.length>0,N=u.length>0;return n.jsxs("div",{className:"lexical-find-replace",onKeyDown:t=>{"Escape"===t.key&&(t.preventDefault(),e())},children:[n.jsxs("div",{className:"lexical-fr-row",children:[n.jsx("input",{ref:m,className:"lexical-fr-input",placeholder:"Find",value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f(e.shiftKey?-1:1))}}),n.jsx("span",{className:"lexical-fr-count",children:N?`${p+1} of ${u.length}`:b?"0 results":""})]}),n.jsx("div",{className:"lexical-fr-row",children:n.jsx("input",{className:"lexical-fr-input",placeholder:"Replace with",value:r,onChange:e=>s(e.target.value)})}),n.jsxs("div",{className:"lexical-fr-row",children:[n.jsxs("label",{className:"lexical-fr-case",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:e=>c(e.target.checked)}),n.jsx("span",{children:"Match case"})]}),n.jsx("span",{style:{flex:1}}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>f(-1),disabled:!N,"aria-label":"Previous match",children:n.jsx(v.IoChevronUp,{})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>f(1),disabled:!N,"aria-label":"Next match",children:n.jsx(v.IoChevronDown,{})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{t.update(()=>{const e=x();if(0===e.length)return h([]),void g(0);const t=e[Math.min(p,e.length-1)],n=d.$getNodeByKey(t.key);d.$isTextNode(n)&&n.spliceText(t.start,o.length,r,!0)})},disabled:!N,children:"Replace"}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{t.update(()=>{const e=x();for(let t=e.length-1;t>=0;t--){const n=e[t],i=d.$getNodeByKey(n.key);d.$isTextNode(i)&&i.spliceText(n.start,o.length,r,!1)}})},disabled:!N,children:"Replace All"}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",onClick:e,"aria-label":"Close find and replace",children:n.jsx(v.IoClose,{})})]})]})}function ye({anchorRef:e,onClose:t,children:o}){const l=i.useRef(null);return i.useEffect(()=>{const n=n=>{const o=n.target;o instanceof HTMLElement&&o.closest("[data-lte-popover-portal]")||!l.current||l.current.contains(o)||e.current&&e.current.contains(o)||t()},o=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",o)}},[e,t]),n.jsx("div",{ref:l,className:"lte-overflow-panel",onMouseDown:e=>e.preventDefault(),children:n.jsx("div",{className:"lte-overflow-grid",children:o})})}function Ce({onAction:e,alignmentSelectionMap:t}){const o=K.find(e=>t[e.id]),[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);return n.jsxs(he,{open:l,onOpenChange:r,children:[n.jsx(pe,{triggerRef:s,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),style:{minWidth:146},children:[o?.icon,n.jsx("span",{children:o?.label}),n.jsx(k.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(ge,{open:l,align:"start",onClose:()=>r(!1),contentRef:a,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:K.map(({id:o,label:i,icon:l})=>n.jsxs("button",{type:"button",className:"lexical-btn "+(t[o]?"toolbar-active":"toolbar"),onClick:()=>{e(o),r(!1)},children:[l,n.jsx("span",{className:"label",children:i})]},o))})})]})}function ve({color:e,onChange:t,icon:o}){const[l,r]=i.useState(!1),s=i.useRef(null),a=i.useRef(null);i.useEffect(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&s.current&&!s.current.contains(e.target)&&r(!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:s,className:`size-10 lexical-btn ${l?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:o}),l&&E.createPortal(n.jsx("div",{ref:a,className:"lexical-color-popover "+(l?"open":""),"data-lte-popover-portal":"true",style:{top:s.current?.getBoundingClientRect().bottom,left:s.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>{e.preventDefault(),(e=>{e.preventDefault()})(e)},children:n.jsx(M.SketchPicker,{color:e,onChangeComplete:e=>{t(e.hex)}})}),document.body)]})}function je(){const[e]=w.useLexicalComposerContext(),[{color:t,bgColor:o},l]=i.useState({color:"#000",bgColor:"#fff"}),r=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=se(e,"color","#000"),n=se(e,"background","#fff");l({color:t,bgColor:n})}};i.useEffect(()=>de(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{r()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(r(),!1),1)),[e]);const s=({property:t,color:n})=>{e.update(()=>{const e=d.$getSelection();e&&Z(e,{[t]:n})})};return n.jsxs(n.Fragment,{children:[n.jsx(ve,{color:t,onChange:e=>{s({property:"color",color:e})},icon:n.jsx(C.AiOutlineFontColors,{})}),n.jsx(ve,{color:o,onChange:e=>{s({property:"background",color:e})},icon:n.jsx(C.AiOutlineBgColors,{})})]})}function Se({icon:e,tooltipLabel:t,currentValue:o,options:l,onSelect:r,minWidth:s=132}){const a=l.find(e=>""!==e.id&&e.id===o),[c,d]=i.useState(!1),u=i.useRef(null),h=i.useRef(null);return n.jsxs(he,{open:c,onOpenChange:d,children:[n.jsx(pe,{triggerRef:u,children:n.jsxs("button",{type:"button","aria-label":t,className:"lexical-btn heading-trigger font-trigger "+(c?"toolbar-active":"toolbar"),style:{minWidth:s},onClick:()=>d(e=>!e),children:[e,n.jsx("span",{children:a?.label??"Default"}),n.jsx(k.HiChevronDown,{className:"chevron "+(c?"rotated":"")})]})}),n.jsx(ge,{open:c,align:"start",onClose:()=>d(!1),contentRef:h,children:n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:l.map(e=>n.jsx("button",{type:"button",className:"lexical-btn "+(""===e.id&&""===o||""!==e.id&&e.id===o?"toolbar-active":"toolbar"),onClick:()=>{r(e.id),d(!1)},children:n.jsx("span",{className:"label",children:e.label})},e.label))})})]})}ae&&"InputEvent"in window&&!ce&&new window.InputEvent("input");const we=[{id:"",label:"Default"},{id:"Inter",label:"Inter"},{id:"System UI",label:"System"},{id:"serif",label:"Serif"},{id:"monospace",label:"Monospace"},{id:"cursive",label:"Cursive"},{id:"Georgia",label:"Georgia"},{id:"Courier New",label:"Courier"}];function Te(){const[e]=w.useLexicalComposerContext(),[t,o]=i.useState(""),l=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=se(e,"font-family","");o((e=>e.replace(/['"]/g,"").trim())(t))}};i.useEffect(()=>de(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{l()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(l(),!1),1)),[e]);return n.jsx(Se,{icon:n.jsx(y.BsFonts,{}),tooltipLabel:"Font Family",currentValue:t,options:we,onSelect:t=>{e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&Z(e,{"font-family":""===t?null:t})})}})}const ke=({content:e,direction:t="top",delay:o=400,children:l})=>{const[r,s]=i.useState(!1),[a,c]=i.useState(null),d=i.useRef(null),u=i.useRef(null),h=()=>{d.current=window.setTimeout(()=>{const e=u.current;if(e){const t=e.getBoundingClientRect();c({left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height})}s(!0)},o)},p=()=>{d.current&&clearTimeout(d.current),s(!1)};if(!a)return n.jsx("div",{ref:u,className:"Lexical-Tooltip-Wrapper",onMouseEnter:h,onMouseLeave:p,children:l});const g=a.left+a.width/2,m=a.top+a.height/2,x="bottom"===t?{top:a.bottom+10,left:g,bottom:"auto"}:"top"===t?{bottom:window.innerHeight-a.top+10,top:"auto",left:g}:"right"===t?{left:a.right+10,right:"auto",top:m}:{left:"auto",right:window.innerWidth-a.left+10,top:m};return n.jsxs("div",{ref:u,className:"Lexical-Tooltip-Wrapper",onMouseEnter:h,onMouseLeave:p,children:[l,r&&E.createPortal(n.jsx("div",{className:`Lexical-Tooltip-Tip ${t}`,style:{position:"fixed",pointerEvents:"none",...x,zIndex:1e4},children:e}),document.body)]})};function Ee(){const[e]=w.useLexicalComposerContext(),[t,o]=i.useState(""),[l,r]=i.useState(null),s=i.useRef(null),a=()=>{const t=d.$getSelection();if(d.$isRangeSelection(t)){let n=_e(se(t,"font-size",""));if(!n)try{const o=e.getElementByKey(t.anchor.getNode().getKey());o&&(n=window.getComputedStyle(o).fontSize||"")}catch{}o(_e(n)),document.activeElement!==s.current&&r(null)}};i.useEffect(()=>de(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{a()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(a(),!1),1)),[e]);const c=t=>{const n=Math.min(90,Math.max(6,t));e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&Z(e,{"font-size":`${n}px`})})},u=e=>{const n=l??t,o=Number.parseInt(n,10),i=Number.isNaN(o)?16:o;c(i+e)},h=()=>{const e=l;if(r(null),null===e)return;const n=Number.parseInt(e,10);if(Number.isNaN(n))return;n!==Number.parseInt(t,10)&&c(n)},p=Number.parseInt(t,10),g=Number.isNaN(p)?null:p;return n.jsxs("div",{className:"lexical-stepper","aria-label":"Font Size",role:"group",children:[n.jsx(ke,{content:"Decrease font size",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Decrease Font Size",className:"lexical-stepper-btn",disabled:null!==g&&g<=6,onClick:()=>u(-1),children:n.jsx(L.LuMinus,{})})}),n.jsx("input",{ref:s,type:"text",inputMode:"numeric",className:"lexical-stepper-value lexical-stepper-input","aria-label":"Font size in pixels",placeholder:"—",title:"Click to type a size (6-90), then press Enter",value:l??(null!==g?String(g):""),onChange:e=>r(e.target.value.replace(/[^\d]/g,"")),onFocus:e=>e.currentTarget.select(),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),h(),e.currentTarget.blur()):"Escape"===e.key?(e.preventDefault(),r(null),e.currentTarget.blur()):"ArrowUp"!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),h(),u("ArrowUp"===e.key?1:-1)),e.stopPropagation()},onBlur:h}),n.jsx(ke,{content:"Increase font size",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Increase Font Size",className:"lexical-stepper-btn",disabled:null!==g&&g>=90,onClick:()=>u(1),children:n.jsx(L.LuPlus,{})})})]})}const _e=e=>e.trim();function Re(){const[e]=w.useLexicalComposerContext(),t=i.useContext(J),[o,l]=i.useState(!1),[s,a]=i.useState(null),[c,u]=i.useState(!1),h=i.useRef(null),p=i.useRef(null),g=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow(),o=r.$isCodeNode(n);l(o),o&&a(n.getLanguage()??null)}};i.useEffect(()=>de(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{g()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(g(),!1),1)),[e]);const m=G.find(e=>e.id===s)?.label??"Plain Text";return n.jsxs(he,{open:c,onOpenChange:u,children:[n.jsx(pe,{triggerRef:h,children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>u(e=>!e),children:[n.jsx(v.IoCodeSlashOutline,{}),n.jsx("span",{children:m}),n.jsx(k.HiChevronDown,{className:"chevron "+(c?"rotated":"")})]})}),n.jsx(ge,{open:c,align:"start",onClose:()=>u(!1),contentRef:p,children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[n.jsxs("button",{type:"button",className:"lexical-btn "+(o?"toolbar-active":"toolbar"),onClick:()=>{e.update(()=>{if(!d.$isRangeSelection(d.$getSelection())){const e=d.$getRoot().getFirstChild();d.$isElementNode(e)&&e.select(0,0)}const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow();if(r.$isCodeNode(n))te(e,()=>d.$createParagraphNode());else{const t=s??"javascript";te(e,()=>r.$createCodeNode(t))}}),t(),u(!1)},style:{minWidth:150},children:[n.jsx(v.IoCodeSlashOutline,{}),n.jsx("span",{className:"label",children:o?"Remove Code Block":"Code Block"})]}),n.jsx("div",{className:"w-full h-[1px] bg-gray-200 my-1"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5,maxHeight:260,overflowY:"auto"},children:G.map(({id:o,label:i})=>n.jsx("button",{type:"button",className:"lexical-btn "+(s===o?"toolbar-active":"toolbar"),onClick:()=>{var n;a(n=o),e.update(()=>{if(!d.$isRangeSelection(d.$getSelection())){const e=d.$getRoot().getFirstChild();d.$isElementNode(e)&&e.select(0,0)}const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.anchor.getNode(),o="root"===t.getKey()?t:t.getTopLevelElementOrThrow();r.$isCodeNode(o)?o.setLanguage(n):te(e,()=>r.$createCodeNode(n))}),t(),u(!1)},style:{minWidth:150},children:n.jsx("span",{className:"label",children:i})},o))})]})})]})}function $e({blockType:e}){const[t]=w.useLexicalComposerContext();i.useEffect(()=>de(t.registerCommand(d.KEY_TAB_COMMAND,e=>{const n=d.$getSelection();if(!d.$isRangeSelection(n))return!1;return!!ue(n.anchor.getNode(),p.ListNode)&&(e.preventDefault(),t.dispatchCommand(e.shiftKey?d.OUTDENT_CONTENT_COMMAND:d.INDENT_CONTENT_COMMAND,void 0),!0)},d.COMMAND_PRIORITY_EDITOR)),[t]);return n.jsxs(n.Fragment,{children:[n.jsx(ke,{content:"Ordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 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(y.BsListOl,{})})}),n.jsx(ke,{content:"Unordered list",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 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(y.BsListUl,{})})})]})}function Me(){const[e]=w.useLexicalComposerContext(),[t,o]=i.useState(!1),[l,r]=i.useState(!1),[s,a]=i.useState(null),c=i.useRef(null),u=i.useRef(null),h=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=f.$findCellNode(e.anchor.getNode());o(!!t)}else o(!1)};i.useEffect(()=>de(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{h()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(h(),!1),1)),[e]);const p=t=>{e.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&t()}),r(!1)},g=s?`${s.rows} × ${s.cols}`:"Insert Table";return n.jsxs(he,{open:l,onOpenChange:r,children:[n.jsx(pe,{triggerRef:c,children:n.jsxs("button",{type:"button","aria-label":"Insert Table",className:"lexical-btn heading-trigger "+(t?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[n.jsx(y.BsTable,{}),n.jsx(k.HiChevronDown,{className:"chevron "+(l?"rotated":"")})]})}),n.jsx(ge,{open:l,align:"start",onClose:()=>r(!1),contentRef:u,children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[n.jsxs("div",{style:{width:"fit-content"},children:[n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 18px)",gap:3},children:Array.from({length:25},(t,o)=>{const i=Math.floor(o/5)+1,l=o%5+1,c=s&&i<=s.rows&&l<=s.cols;return n.jsx("div",{onMouseEnter:()=>a({rows:i,cols:l}),onClick:()=>{return t=i,n=l,e.update(()=>{if(!d.$isRangeSelection(d.$getSelection())){const e=d.$getRoot().getFirstChild();d.$isElementNode(e)&&e.select(0,0)}}),e.dispatchCommand(f.INSERT_TABLE_COMMAND,{rows:String(t),columns:String(n),includeHeaders:!1}),void r(!1);var t,n},style:{width:18,height:18,borderRadius:3,border:"1px solid #d1d5db",backgroundColor:c?"#c7d2fe":"#fff",cursor:"pointer"}},o)})}),n.jsx("div",{style:{fontSize:12,color:"#6b7280",marginTop:4},children:g})]}),n.jsx("div",{className:"w-full h-[1px] bg-gray-200"}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableRowAtSelection(!1)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert row above"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableRowAtSelection(!0)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert row below"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$deleteTableRowAtSelection()}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Delete row"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableColumnAtSelection(!1)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert column left"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$insertTableColumnAtSelection(!0)}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Insert column right"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>p(()=>{f.$deleteTableColumnAtSelection()}),style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Delete column"})}),n.jsx("button",{type:"button",className:"lexical-btn toolbar",disabled:!t,onClick:()=>{p(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=f.$findCellNode(e.anchor.getNode());if(!t)return;const n=t.getParent();if(!n)return;const o=n.getChildren().filter(f.$isTableCellNode),i=o.some(e=>e.hasHeaderState(f.TableCellHeaderStates.ROW));for(const e of o)e.setHeaderStyles(i?f.TableCellHeaderStates.NO_STATUS:f.TableCellHeaderStates.ROW,f.TableCellHeaderStates.ROW)})},style:{minWidth:160},children:n.jsx("span",{className:"label",children:"Toggle header row"})})]})]})})]})}const Le=({src:e,altText:t,nodeKey:o,width:l,height:r,maxWidth:s,caption:a=""})=>{const[c]=w.useLexicalComposerContext(),[u,h]=i.useState(!1),[p,g]=i.useState(a),m=i.useRef(null),x=i.useRef(null),f=i.useRef(null),b=i.useRef(null),N=e=>{if(!b.current||!x.current)return;const t=e.clientX-b.current.x,n=Math.min(s,Math.max(50,b.current.width+t)),o=n*x.current.ratio;x.current.width=n,x.current.height=o;const i=f.current?.querySelector("img");i&&(i.style.width=n+"px",i.style.height=o+"px")},y=()=>{if(!x.current)return;const{width:e,height:t}=x.current;c.update(()=>{const n=d.$getNodeByKey(o);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),x.current=null,b.current=null,window.removeEventListener("mousemove",N),window.removeEventListener("mouseup",y)},C=()=>{h(!1),c.update(()=>{const e=d.$getNodeByKey(o);e&&"function"==typeof e.setCaption&&e.setCaption(p)})},v=()=>{g(a),h(!0),setTimeout(()=>m.current?.focus(),0)};return n.jsxs("div",{ref:f,style:{display:"inline-block",position:"relative",maxWidth:s},children:[n.jsx("img",{src:e,alt:t,width:"inherit"===l?void 0:l,height:"inherit"===r?void 0:r,style:{maxWidth:"100%",display:"block"}}),(a||u)&&n.jsx("div",{style:{textAlign:"center",marginTop:4},children:u?n.jsx("input",{ref:m,className:"lte-input",style:{width:"100%",textAlign:"center"},value:p,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C()}}):n.jsx("span",{style:{fontSize:13,color:"#666",cursor:"text",display:"inline-block",minWidth:20,minHeight:18},onClick:v,children:a})}),!a&&!u&&n.jsx("div",{style:{textAlign:"center",marginTop:2},children:n.jsx("span",{style:{fontSize:12,color:"#999",cursor:"pointer"},onClick:v,children:"+ Add caption"})}),n.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=f.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,o=t.naturalHeight/t.naturalWidth,i=n*o;b.current={x:e.clientX,y:e.clientY,width:n,height:i},x.current={width:n,height:i,ratio:o},window.addEventListener("mousemove",N),window.addEventListener("mouseup",y)},style:{position:"absolute",bottom:a||u?40:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Ae=e=>d.$applyNodeReplacement(new De(e)),Oe=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let o,i;e.width&&(o=e.width),e.height&&(i=e.height);const l=e.style;if((!o||0===o)&&l.width){const e=parseInt(l.width,10);Number.isNaN(e)||(o=e)}if((!i||0===i)&&l.height){const e=parseInt(l.height,10);Number.isNaN(e)||(i=e)}return{node:Ae({src:t,altText:n,width:o??"inherit",height:i??"inherit"})}};class De extends d.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:n=1080,width:o="inherit",height:i="inherit",caption:l="",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=o,this.__height=i,this.__caption=l}static getType(){return"image"}static clone(e){return new De({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,caption:e.__caption,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");if(e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),this.__caption){const t=document.createElement("figure"),n=document.createElement("figcaption");return n.textContent=this.__caption,t.appendChild(e),t.appendChild(n),{element:t}}return{element:e}}static importDOM(){return{img:()=>({conversion:Oe,priority:1}),figure:()=>({conversion:e=>{const t=e.querySelector("img");if(!t)return null;const n=e.querySelector("figcaption"),o=n?.textContent||"",i=Oe(t);return i?.node instanceof De&&o&&(i.node.__caption=o),i},priority:1})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height,caption:this.__caption}}static importJSON(e){return new De({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height,caption:e.caption})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}setCaption(e){this.getWritable().__caption=e}decorate(){return n.jsx(Le,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth,caption:this.__caption})}}function Fe({open:e,onClose:t,forPreview:o=!1,children:l}){const r=i.useRef(null);return i.useEffect(()=>{if(!e)return;const n=e=>{r.current&&!r.current.contains(e.target)&&t()},o=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",o)}},[e,t]),e?n.jsx("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:n.jsxs("div",{ref:r,className:"lte-dialog "+(o?"preview":""),children:[n.jsx("button",{type:"button",className:"lte-dialog-close",onClick:t,children:"×"}),l]})}):null}async function Ie(e,{src:t,altText:n="",caption:o=""}){e.update(()=>{const e=Ae({src:t,altText:n,caption:o});d.$insertNodes([e])})}function He({onImageUpload:e}){const[t]=w.useLexicalComposerContext(),o=i.useRef(null),[l,r]=i.useState(!1),[s,a]=i.useState(""),[c,u]=i.useState(""),[h,p]=i.useState(""),[g,m]=i.useState(),[x,f]=i.useState(!1),b=i.useCallback(async(n,o="",i="")=>{let l;l=e?await e(n):URL.createObjectURL(n),Ie(t,{src:l,altText:o,caption:i})},[t,e]);return i.useEffect(()=>{const e=t.registerCommand(d.PASTE_COMMAND,e=>{if(e instanceof ClipboardEvent){const t=e.clipboardData?.items;if(!t)return!1;for(const n of t)if(n.type.startsWith("image/")){e.preventDefault();const t=n.getAsFile();return t&&b(t,"","").catch(console.error),!0}}return!1},d.COMMAND_PRIORITY_LOW);return()=>e()},[t,b]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx("input",{type:"file",ref:o,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&m(t),e.target.value=""}}),n.jsx(ke,{content:"Add Image",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${l?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:n.jsx(v.IoImageOutline,{size:18})})}),n.jsxs(Fe,{open:l,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:c,onChange:e=>u(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Caption",value:h,onChange:e=>p(e.target.value)}),n.jsx("input",{className:"lte-input",placeholder:"Add image by URL",value:s,onChange:e=>a(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:()=>o.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[n.jsx(L.LuUpload,{size:20}),n.jsx("span",{children:"Upload Image"})]}),g&&n.jsx("div",{className:"lte-file-name",children:g.name})]}),n.jsx("div",{className:"lte-dialog-footer",children:n.jsx("button",{type:"button",className:"lte-primary-btn",disabled:!s&&!g||x,onClick:async()=>{if(!x){if(g){f(!0);try{await b(g,c,h)}catch(e){return console.error("Image upload failed:",e),void f(!1)}f(!1)}else{if(!s)return;Ie(t,{src:s,altText:c,caption:h})}m(void 0),u(""),p(""),a(""),r(!1)}},children:x?"Uploading...":"Add Image"})})]})]})}const Be=({id:e,provider:t})=>new Ge({id:e,provider:t}),ze="data-lexical-video",Pe="data-provider",We="315px",Ue="560px",Ke=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,qe=e=>{const t=e?.getAttribute(ze),n=e?.getAttribute(Pe)??"youtube";if(!t)return null;return{node:Be({id:t,provider:n})}};class Ge 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 Ge({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Be({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:We,width:Ue,src:Ke(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(ze,this.__id),e.setAttribute(Pe,this.__provider),e.setAttribute("height",We),e.setAttribute("width",Ue),e.setAttribute("src",Ke(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:qe,priority:0})}}}function Je(){const[e,t]=i.useState(!1),[o,l]=i.useState(!1),[r,s]=i.useState(""),[a]=w.useLexicalComposerContext();return i.useEffect(()=>{e||(s(""),l(!1))},[e]),n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx(ke,{content:"Embed Video",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${e?"toolbarActive":"toolbar"} icon`,onClick:()=>t(!0),children:n.jsx(A.FaYoutube,{size:18,color:"red"})})}),n.jsxs(Fe,{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:r,onChange:e=>s(e.target.value)}),o&&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:!r,onClick:()=>{if(!r)return;let e=null,n=null;const o=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(r);o&&11===o[2]?.length&&(e="youtube",n=o[2]);const i=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(r);i&&i[1]&&(e="drive",n=i[1]),n&&e?(a.update(()=>{const t=Be({id:n,provider:e});d.$insertNodes([t])}),s(""),l(!1),t(!1)):l(!0)},children:"Embed"})})]})]})}function Xe({value:e}){return n.jsx("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:e}})}function Ve({value:e,triggerLabel:t="Preview"}){const[o,l]=i.useState(!1);return n.jsxs("div",{className:"lexical-text-editor-dialog",children:[n.jsx(ke,{content:t,direction:"bottom",children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[n.jsx(O.VscPreview,{size:18}),n.jsx("span",{children:t})]})}),n.jsxs(Fe,{open:o,onClose:()=>l(!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(Xe,{value:e})]})]})]})}const Ye=[{id:"headings",sep:!0},{id:"fontFamily"},{id:"fontSize"},{id:"textFormats",sep:!0},{id:"dropdown",sep:!0},{id:"color",sep:!0},{id:"quoteCode",sep:!0},{id:"codeBlock"},{id:"alignment",sep:!0},{id:"lists",sep:!0},{id:"blockOptions"},{id:"table",sep:!0},{id:"hline"},{id:"link",sep:!0},{id:"image"},{id:"video"},{id:"utility",sep:!0},{id:"preview"}],Qe=Ye.map(e=>e.id),Ze=({value:o,onImageUpload:r,sourceView:s=!1,onToggleSourceView:a,fullscreen:c=!1,onToggleFullscreen:u,toolbarStyle:h="wrap"})=>{const m="normal"===h?"collapse":h,[x]=w.useLexicalComposerContext(),[f,b]=i.useState({[e.Undo]:!0,[e.Redo]:!0}),[N,C]=i.useState(!1),[j,S]=i.useState(!1),[k,E]=i.useState(0),[R,$]=i.useState(!1),M=i.useCallback(()=>$(!1),[]),L=i.useRef(null),A=i.useRef(null),O=i.useRef(null),D=i.useRef({}),F=i.useRef({}),I=i.useRef(0),K=i.useRef(null),q=i.useRef(null),[G,X]=i.useState({[e.LeftAlign]:!0}),[V,Y]=i.useState({[t.Normal]:!0}),[Q,Z]=i.useState("paragraph"),[ee,ne]=i.useState("https://");let oe=!0;const le=()=>{if(oe){const e=x.getRootElement();e&&(e.scrollTop=0,oe=!1)}const n=d.$getSelection();if(d.$isRangeSelection(n)){const o={[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")};X(o);const i=n.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),s=r.getKey();if(!x.getElementByKey(s))return;if(p.$isListNode(r)){const e=ue(i,p.ListNode),t=e?e.getTag():r.getTag();Z(t)}else if("paragraph"===r.getType()||l.$isHeadingNode(r)){let e=null;l.$isHeadingNode(r)&&(e=r.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"===r.getType()};Z(r.getType()),Y(n)}else Z(r.getType());const a=(d.$isElementNode(i)?i:r).getFormat();X(t=>({...t,[e.LeftAlign]:0===a||1===a,[e.CenterAlign]:2===a,[e.RightAlign]:3===a,[e.JustifyAlign]:4===a})),"quote"===r.getType()?X(t=>({...t,[e.Quote]:!0})):X(t=>({...t,[e.Quote]:!1}));const c=n.anchor.getNode(),u=c.getParent();T.$isLinkNode(u)?(X(t=>({...t,[e.Link]:!0})),ne(u.getURL()),C(!0)):T.$isLinkNode(c)?(X(t=>({...t,[e.Link]:!0})),ne(c.getURL()),C(!0)):(X(t=>({...t,[e.Link]:!1})),ne("https://"),C(!1))}};i.useEffect(()=>de(x.registerUpdateListener(({editorState:e})=>{e.read(()=>{le()})}),x.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(le(),!1),1),x.registerCommand(d.CAN_UNDO_COMMAND,e=>(b(t=>({...t,undo:!e})),!1),1),x.registerCommand(d.CAN_REDO_COMMAND,e=>(b(t=>({...t,redo:!e})),!1),1)),[]);const re="scrollbar"===m,se=i.useCallback(()=>{if("collapse"!==m)return;const e=L.current;if(!e)return;const t=e.clientWidth;if(t<=0)return;const n=A.current?A.current.offsetWidth:0,o=Qe.map(e=>{const t=D.current[e];return t&&"none"!==t.style.display&&(F.current[e]=t.offsetWidth),F.current[e]??0});O.current&&(I.current=O.current.offsetWidth);const i=I.current||40,l=e=>{const t=1+(e>0?1:0)+(Qe.length-e);let l=n+6*Math.max(0,t-1)+(e>0?i:0);for(let t=0;t<Qe.length-e;t++)l+=o[t];return l};let r=k;for(;r<Qe.length&&l(r)>t;)r++;for(;r>0&&l(r-1)<=t;)r--;E(e=>e===r?e:r)},[k,m]);i.useEffect(()=>{se()});const ae=i.useRef(()=>{});ae.current=se,i.useEffect(()=>{if("undefined"==typeof ResizeObserver)return;const e=L.current;if(!e)return;const t=new ResizeObserver(()=>{ae.current(),Se.current()});return t.observe(e),()=>t.disconnect()},[]),i.useEffect(()=>{0===k&&$(!1)},[k]),i.useEffect(()=>{"collapse"!==m&&E(0)},[m]);const ce=i.useCallback(()=>{if("scrollbar"!==m)return;const e=L.current,t=K.current,n=q.current;if(!e||!t||!n)return;const o=e.clientWidth;if(e.scrollWidth-o<=1)return void(t.style.display="none");t.style.display="flex";const i=Math.max(24,o/e.scrollWidth*o),l=e.scrollWidth-o,r=o-i,s=l>0?e.scrollLeft/l*r:0;n.style.width=`${i}px`,n.style.transform=`translateX(${s}px)`},[h]),he=i.useCallback(e=>{e.stopPropagation(),e.preventDefault();const t=L.current,n=q.current;if(!t||!n)return;const o=e.clientX,i=t.scrollLeft,l=t.clientWidth,r=Math.max(24,l/t.scrollWidth*l),s=t.scrollWidth-l,a=l-r,c=e=>{const n=e.clientX-o;t.scrollLeft=a>0?i+n/a*s:0},d=()=>{document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",d)};document.addEventListener("pointermove",c),document.addEventListener("pointerup",d)},[]),pe=i.useCallback(e=>{const t=L.current,n=K.current;if(!t||!n)return;const o=n.getBoundingClientRect(),i=(e.clientX-o.left)/o.width;t.scrollLeft=i*t.scrollWidth-t.clientWidth/2},[]),ge=i.useRef(null),ve=i.useCallback(()=>{const e=ge.current;if(e)for(const t of e.querySelectorAll(".lte-toolbar-row svg:not(.chevron), .lte-overflow-panel svg:not(.chevron)")){if(t.closest(".lexical-stepper"))continue;const e=t;try{const t=e.viewBox?.baseVal;if(!t||!t.width)continue;let n=1/0,o=1/0,i=-1/0,l=-1/0;if(e.querySelectorAll("path, circle, rect, ellipse, polygon, polyline, line").forEach(e=>{const t=e.getBBox();(t.width||t.height)&&(n=Math.min(n,t.x),o=Math.min(o,t.y),i=Math.max(i,t.x+t.width),l=Math.max(l,t.y+t.height))}),i===-1/0)continue;const r=((i-n)/t.width+(l-o)/t.height)/2;if(!isFinite(r)||r<=0)continue;const s=Math.min(22,Math.max(17,15/r));parseFloat(e.style.width)!==s&&(e.style.width=`${s}px`,e.style.height=`${s}px`)}catch{}}},[]);i.useEffect(()=>{ve()}),i.useEffect(()=>{ce()});const Se=i.useRef(()=>{});Se.current=ce,i.useEffect(()=>{if("scrollbar"!==m)return;const e=L.current;if(!e)return;const t=()=>ce();return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[m,ce]);const we=t=>{switch(t){case e.Bold:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"bold");break;case e.Italics:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"italic");break;case e.Underline:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"underline");break;case e.Lowercase:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"lowercase");break;case e.Uppercase:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"uppercase");break;case e.Capitalize:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"capitalize");break;case e.Strikethrough:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"strikethrough");break;case e.Superscript:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"superscript");break;case e.Subscript:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"subscript");break;case e.Highlight:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"highlight");break;case e.Code:x.dispatchCommand(d.FORMAT_TEXT_COMMAND,"code");break;case e.Quote:x.update(()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&l.$isQuoteNode(t)?te(e,()=>d.$createParagraphNode()):ie(e,()=>l.$createQuoteNode())}});break;case e.Link:_e(),C(!0);break;case e.LeftAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"left");break;case e.RightAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"right");break;case e.CenterAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"center");break;case e.JustifyAlign:x.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"justify");break;case e.Undo:x.dispatchCommand(d.UNDO_COMMAND,void 0);break;case e.Redo:x.dispatchCommand(d.REDO_COMMAND,void 0);break;case e.ClearFormatting:x.update(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.getNodes().filter(d.$isTextNode);for(const e of t)e.setFormat(0),e.setStyle("")});break;case e.HorizontalRule:x.dispatchCommand(g.INSERT_HORIZONTAL_RULE_COMMAND,void 0);break;case e.Indent:x.dispatchCommand(d.INDENT_CONTENT_COMMAND,void 0);break;case e.Outdent:x.dispatchCommand(d.OUTDENT_CONTENT_COMMAND,void 0)}},_e=i.useCallback(()=>{x.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&!e.isCollapsed()&&(N?x.dispatchCommand(T.TOGGLE_LINK_COMMAND,null):""!==ee&&x.dispatchCommand(T.TOGGLE_LINK_COMMAND,ee))})},[x,N,ee]),Le=i.useCallback(()=>{ne(""),x.dispatchCommand(T.TOGGLE_LINK_COMMAND,null),C(!1)},[x]),Ae=e=>Qe.indexOf(e)>=Qe.length-k,Oe={headings:n.jsx(fe,{updateHeading:e=>{x.update(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&ie(t,"normal"===e?()=>d.$createParagraphNode():()=>l.$createHeadingNode(e))})},headingSelectionMap:V}),fontFamily:n.jsx(Te,{}),fontSize:n.jsx(Ee,{}),textFormats:n.jsx(n.Fragment,{children:H.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(xe,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(t),children:i})},t))}),dropdown:n.jsx(me,{onAction:we,selectionMap:G}),color:n.jsxs(n.Fragment,{children:[n.jsx(je,{}),B.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(e),children:o})},e))]}),quoteCode:n.jsx(n.Fragment,{children:z.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(e),children:o})},e))}),codeBlock:n.jsx(Re,{}),alignment:n.jsx(Ce,{onAction:we,alignmentSelectionMap:G}),lists:n.jsx($e,{blockType:Q}),blockOptions:n.jsx(n.Fragment,{children:W.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(xe,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(t),children:i})},t))}),table:n.jsx(Me,{}),hline:n.jsx(n.Fragment,{children:U.map(({id:e,label:t,icon:o})=>n.jsx(ke,{content:t,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[e]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(e),children:o})},e))}),link:n.jsx(ke,{content:"Link",direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[e.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(e.Link),disabled:!!f[e.Link],children:n.jsx(_.IoIosLink,{})})}),image:n.jsx(He,{onImageUpload:r}),video:n.jsx(Je,{}),utility:n.jsxs(n.Fragment,{children:[n.jsx(ke,{content:"Find & Replace",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Find & Replace",className:`size-10 lexical-btn ${j?"toolbarActive":"toolbar"} icon`,onClick:()=>S(e=>!e),children:n.jsx(v.IoSearchOutline,{})})}),n.jsx(ke,{content:"Source Code View",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":"Source Code View",className:`size-10 lexical-btn ${s?"toolbarActive":"toolbar"} icon`,onClick:()=>a?.(),children:n.jsx(v.IoCodeOutline,{})})}),n.jsx(ke,{content:c?"Exit Fullscreen":"Fullscreen",direction:"bottom",children:n.jsx("button",{type:"button","aria-label":c?"Exit Fullscreen":"Fullscreen",className:`size-10 lexical-btn ${c?"toolbarActive":"toolbar"} icon`,onClick:()=>u?.(),children:c?n.jsx(y.BsFullscreenExit,{}):n.jsx(y.BsFullscreen,{})})})]}),preview:n.jsx(Ve,{value:o})};return n.jsx(J.Provider,{value:M,children:n.jsxs("div",{ref:ge,className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[n.jsxs("div",{ref:L,className:"lte-toolbar-row "+(re?"useScroll":"collapse"===m?"lte-nowrap":"lte-wrap"),onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:[n.jsx("div",{ref:A,className:"lte-toolbar-primary",style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:P.map(({id:t,label:o,icon:i})=>t===e.Divider?n.jsx(xe,{},t):n.jsx(ke,{content:o,direction:"bottom",children:n.jsx("button",{type:"button",className:`size-10 lexical-btn ${G[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>we(t),disabled:!!f[t],children:i})},o))}),Ye.map(({id:e,sep:t})=>{const o=Ae(e);return n.jsxs("div",{ref:t=>{D.current[e]=t},style:o?{display:"none"}:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[t?n.jsx(xe,{}):null,o?null:Oe[e]]},e)}),k>0&&n.jsx(ke,{content:"More tools",direction:"bottom",children:n.jsx("button",{type:"button",ref:O,"aria-label":"More tools",className:`size-10 lexical-btn ${R?"toolbarActive":"toolbar"} icon`,onClick:()=>$(e=>!e),children:n.jsx(y.BsThreeDots,{})})})]}),re&&n.jsx("div",{ref:K,className:"lte-custom-scrollbar",onPointerDown:pe,"aria-hidden":"true",children:n.jsx("div",{ref:q,className:"lte-custom-scrollbar-thumb",onPointerDown:he})}),N&&n.jsx(be,{linkUrl:ee,setLinkUrl:ne,removeLink:Le,onConfirm:e=>{x.dispatchCommand(T.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),ne(e),C(!1)},onCancel:()=>{ne(""),C(!1)}}),R&&n.jsx(ye,{anchorRef:O,onClose:()=>$(!1),children:Ye.filter(({id:e})=>Ae(e)&&Oe[e]).map(({id:e,sep:t},o)=>n.jsxs("div",{className:"lte-overflow-item",children:[t&&o>0?n.jsx(xe,{}):null,Oe[e]]},e))}),j&&n.jsx(Ne,{onClose:()=>S(!1)})]})})};function et(){const[e]=w.useLexicalComposerContext();return i.useEffect(()=>{let t=!1;return de(e.registerCommand(d.KEY_ENTER_COMMAND,()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return!1;const n=e.anchor.getNode();return d.$isTextNode(n)&&n.hasFormat("code")&&e.anchor.offset===n.getTextContentSize()&&(t=!0),!1},d.COMMAND_PRIORITY_HIGH),e.registerCommand(d.KEY_DOWN_COMMAND,t=>{if(t.ctrlKey||t.metaKey||t.altKey)return!1;const n=t.key;if(1!==n.length)return!1;const o=d.$getSelection();if(!d.$isRangeSelection(o)||!o.isCollapsed())return!1;const i=o.anchor.getNode();if(!d.$isTextNode(i)||i.hasFormat("code"))return!1;if(0!==o.anchor.offset)return!1;const l=i.getPreviousSibling();if(!d.$isTextNode(l)||!l.hasFormat("code"))return!1;t.preventDefault();const r=l.getKey();return e.update(()=>{const e=d.$getNodeByKey(r);if(!d.$isTextNode(e)||!e.hasFormat("code"))return;e.setTextContent(e.getTextContent()+n);const t=e.getTextContentSize();e.select(t,t)}),!0},d.COMMAND_PRIORITY_HIGH),e.registerUpdateListener(({editorState:n})=>{t&&(t=!1,n.read(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&e.update(()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return;const t=e.anchor.getNode(),n=e=>d.$isTextNode(e)&&0===e.getTextContentSize()&&e.hasFormat("code");if(d.$isTextNode(t))if(n(t))t.setFormat(0);else{let e=t.getPreviousSibling();for(;e&&d.$isTextNode(e)&&0===e.getTextContentSize();)e.hasFormat("code")&&e.setFormat(0),e=e.getPreviousSibling()}else if(d.$isElementNode(t))if(0===t.getChildrenSize())e.hasFormat("code")&&e.setFormat(0);else{const e=t.getFirstChild();n(e)&&d.$isTextNode(e)&&e.setFormat(0)}d.$isTextNode(t)&&t.hasFormat("code")||e.hasFormat("code")&&e.setFormat(0)})}))}))},[e]),null}function tt(e,t){const n=d.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let o=[];const i=[];for(const t of n)if(!it.has(t.nodeName)){const n=lt(t,e,i,!1);null!==n&&(o=o.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()}}(i),o}function nt(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"),o=d.$getRoot().getChildren();for(let i=0;i<o.length;i++)ot(e,o[i],n,t);return n.innerHTML}function ot(e,t,n,o=null){let i=null===o||t.isSelected(o);const l=d.$isElementNode(t)&&t.excludeFromCopy("html");let r=t;if(null!==o){let e=d.$cloneWithProperties(t);e=d.$isTextNode(e)&&null!==o?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!d.$isTokenOrSegmented(t)&&null!==n){const[o,i]=n,l=e.isBackward(),r=o.getNode(),s=i.getNode(),a=t.is(r),c=t.is(s);if(a||c){const[n,o]=d.$getCharacterOffsets(e),i=r.is(s),a=t.is(l?s:r),c=t.is(l?r:s);let u,h=0;i?(h=n>o?o:n,u=n>o?n:o):a?(h=l?o:n,u=void 0):c&&(h=0,u=l?n:o),t.__text=t.__text.slice(h,u)}}return t}(o,e):e,r=e}const s=d.$isElementNode(r)?r.getChildren():[],a=d.getRegisteredNode(e,r.getType());let c;c=a&&void 0!==a.exportDOM?a.exportDOM(e,r):r.exportDOM(e);const{element:u,after:h}=c;if(!u)return!1;const p=document.createDocumentFragment();for(let n=0;n<s.length;n++){const l=s[n],r=ot(e,l,p,o);!i&&d.$isElementNode(t)&&r&&t.extractWithChild(l,o,"html")&&(i=!0)}if(i&&!l){if((d.isHTMLElement(u)||d.isDocumentFragment(u))&&u.append(p),n.append(u),h){const e=h.call(r,u);e&&(d.isDocumentFragment(u)?u.replaceChildren(e):u.replaceWith(e))}}else n.append(p);return i}const it=new Set(["STYLE","SCRIPT"]);function lt(e,t,n,o,i=new Map,l){let r=[];if(it.has(e.nodeName))return r;let s=null;const a=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let i=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===i||(i.priority||0)<=(n.priority||0))&&(i=n)}return null!==i?i.conversion:null}(e,t),c=a?a(e):null;let u=null;if(null!==c){u=c.after;const t=c.node;if(s=Array.isArray(t)?t[t.length-1]:t,null!==s){for(const[,e]of i)if(s=e(s,l),!s)break;s&&r.push(...Array.isArray(t)?t:[s])}null!=c.forChild&&i.set(e.nodeName,c.forChild)}const h=e.childNodes;let p=[];const g=(null==s||!d.$isRootOrShadowRoot(s))&&(null!=s&&d.$isBlockElementNode(s)||o);for(let e=0;e<h.length;e++)p.push(...lt(h[e],t,n,g,new Map(i),s));return null!=u&&(p=u(p)),d.isBlockDomNode(e)&&(p=function(e,t,n){const o=e.style.textAlign,i=[];let l=[];for(let e=0;e<t.length;e++){const r=t[e];if(d.$isBlockElementNode(r))o&&!r.getFormat()&&r.setFormat(o),i.push(r);else if(l.push(r),e===t.length-1||e<t.length-1&&d.$isBlockElementNode(t[e+1])){const e=n();e.setFormat(o),e.append(...l),i.push(e),l=[]}}return i}(e,p,g?()=>{const e=new d.ArtificialNode__DO_NOT_USE;return n.push(e),e}:d.$createParagraphNode)),null==s?p.length>0?r=r.concat(p):d.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(d.isInlineDomNode(e.nextSibling)&&d.isInlineDomNode(e.previousSibling))}(e)&&(r=r.concat(d.$createLineBreakNode())):d.$isElementNode(s)&&s.append(...p),r}function rt({value:e,onChange:t}){const[o]=w.useLexicalComposerContext(),[l,r]=i.useState(!0);return i.useEffect(()=>{e&&l&&(r(!1),o.update(()=>{if(nt(o)!==e){d.$getRoot().clear();const t=(new DOMParser).parseFromString(e,"text/html"),n=tt(o,t);d.$insertNodes(n)}}))},[o,e,l]),i.useEffect(()=>{r(!0)},[e]),n.jsx(F.OnChangePlugin,{onChange:e=>{e.read(()=>{t(nt(o))})}})}function st({applyRef:e,onExit:t}){const[o]=w.useLexicalComposerContext(),[l,r]=i.useState(()=>o.getEditorState().read(()=>nt(o))),s=i.useRef(l),a=e=>{e!==s.current&&(o.update(()=>{const t=d.$getRoot();if(t.clear(),t.selectEnd(),e){const t=(new DOMParser).parseFromString(e,"text/html"),n=tt(o,t);n.length>0&&d.$insertNodes(n)}}),s.current=e)};return i.useEffect(()=>(e.current=()=>{a(l),t()},()=>{e.current=null}),[e,l,t,o]),n.jsxs("div",{className:"lexical-source-view",children:[n.jsx("textarea",{className:"lexical-source-textarea",value:l,onChange:e=>r(e.target.value),"aria-label":"HTML source",spellCheck:!1}),n.jsxs("div",{className:"lexical-source-actions",children:[n.jsx(ke,{content:"Apply HTML to the editor",direction:"top",children:n.jsxs("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>a(l),children:[n.jsx(R.MdCheck,{size:16}),n.jsx("span",{className:"label",children:"Update"})]})}),n.jsx("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{a(l),t()},children:"Done"})]})]})}function at({showWordCount:e=!0,showCharCount:t=!0,rightSlot:o}){const[l]=w.useLexicalComposerContext(),[r,s]=i.useState({words:0,chars:0});return i.useEffect(()=>{const e=e=>{e.read(()=>{const e=d.$getRoot().getTextContent(),t=e.trim();s({words:t?t.split(/\s+/).length:0,chars:e.length})})};return e(l.getEditorState()),l.registerUpdateListener(({editorState:t})=>{e(t)})},[l]),n.jsxs("div",{className:"lexical-status-bar",children:[e&&n.jsxs("span",{children:[r.words," words"]}),t&&n.jsxs("span",{children:[r.chars," characters"]}),o&&n.jsx("div",{className:"lexical-status-bar-right",children:o})]})}function ct({theme:e,toolbarStyle:t,onThemeChange:o,onToolbarStyleChange:i}){const l="normal"===t?"collapse":t,r=[{value:"light",label:"Light theme",icon:n.jsx(y.BsSun,{})},{value:"dark",label:"Dark theme",icon:n.jsx(y.BsMoon,{})},{value:"system",label:"Follow system theme",icon:n.jsx(R.MdMonitor,{})}],s=[{value:"wrap",label:"Toolbar: wrap to new lines",icon:n.jsx(R.MdWrapText,{})},{value:"collapse",label:'Toolbar: collapse into "..."',icon:n.jsx(y.BsThreeDots,{})},{value:"scrollbar",label:"Toolbar: scroll in one row",icon:n.jsx(N.TbArrowsLeftRight,{})}];return n.jsxs("div",{className:"lexical-display-controls",role:"group","aria-label":"Display settings",children:[n.jsx("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Theme",children:r.map(t=>n.jsx(ke,{content:t.label,direction:"top",children:n.jsx("button",{type:"button",role:"radio","aria-checked":e===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(e===t.value?"active":""),onClick:()=>o?.(t.value),children:t.icon})},t.value))}),n.jsx("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Toolbar style",children:s.map(e=>n.jsx(ke,{content:e.label,direction:"top",children:n.jsx("button",{type:"button",role:"radio","aria-checked":l===e.value,"aria-label":e.label,className:"lte-mini-btn btn "+(l===e.value?"active":""),onClick:()=>i?.(e.value),children:e.icon})},e.value))})]})}const dt=({id:e})=>new xt({id:e}),ut="data-lexical-youtube",ht="315px",pt="560px",gt=e=>`https://www.youtube-nocookie.com/embed/${e}`,mt=e=>{const t=e?.getAttribute(ut);if(!t)return null;return{node:dt({id:t})}};class xt extends d.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new xt({id:e.__id,key:e.getKey()})}static importJSON(e){return dt({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return n.jsx("iframe",{height:ht,width:pt,src:gt(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(ut,this.__id),e.setAttribute("height",ht),e.setAttribute("width",pt),e.setAttribute("src",gt(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:mt,priority:0})}}}class ft extends d.TextNode{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new ft(e.__text,e.__key)}static importDOM(){const e=d.TextNode.importDOM();return{...e,span:()=>({conversion:bt(e?.span),priority:1}),div:()=>({conversion:bt(e?.div),priority:1}),p:()=>({conversion:bt(e?.p),priority:1}),b:()=>({conversion:bt(e?.b),priority:1}),strong:()=>({conversion:bt(e?.strong),priority:1}),i:()=>({conversion:bt(e?.i),priority:1}),em:()=>({conversion:bt(e?.em),priority:1}),u:()=>({conversion:bt(e?.u),priority:1}),s:()=>({conversion:bt(e?.s),priority:1}),strike:()=>({conversion:bt(e?.strike),priority:1}),code:()=>({conversion:bt(e?.code),priority:1})}}static importJSON(e){return function(e=""){return d.$applyNodeReplacement(new ft(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function bt(e){return t=>{const n=e?.(t);if(!n)return null;const o=n.conversion(t);if(!o)return o;const i=t.style,l=[];i.backgroundColor&&l.push(`background-color: ${i.backgroundColor}`),i.color&&l.push(`color: ${i.color}`),i.fontFamily&&l.push(`font-family: ${i.fontFamily}`),i.fontWeight&&l.push(`font-weight: ${i.fontWeight}`),i.fontSize&&l.push(`font-size: ${i.fontSize}`),i.fontStyle&&l.push(`font-style: ${i.fontStyle}`),i.textDecoration&&l.push(`text-decoration: ${i.textDecoration}`),i.whiteSpace&&l.push(`white-space: ${i.whiteSpace}`),i.textAlign&&l.push(`text-align: ${i.textAlign}`);const r=t.getAttribute("style");if(r){r.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!l.some(e=>e.startsWith(t))&&l.push(e.trim())})}return{...o,forChild:(e,t)=>{const n=o?.forChild??(e=>e),i=n(e,t);if(d.$isTextNode(i)&&l.length>0){const e=l.join("; ");return i.setStyle(e)}return i}}}}const Nt={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",code:"lexical-code-block",hr:"lexical-hr",indent:"lexical-indent",table:"lexical-table",tableRow:"lexical-table-row",tableCell:"lexical-table-cell",codeHighlight:{keyword:"lexical-code-token-keyword",string:"lexical-code-token-string",number:"lexical-code-token-number",comment:"lexical-code-token-comment",function:"lexical-code-token-function",operator:"lexical-code-token-operator",punctuation:"lexical-code-token-punctuation"}},yt=i.memo(function({name:e,value:t,onChange:b,placeholder:N,maxWidth:y=null,height:C=null,onImageUpload:v,showWordCount:j=!0,showCharCount:S=!0,theme:w="system",toolbarStyle:k="collapse",showDisplayControls:E=!0,onThemeChange:_,onToolbarStyleChange:R}){const[$,M]=i.useState(!1),[L,A]=i.useState(!1),O=i.useRef(null),[F,I]=i.useState(!1),[H,B]=i.useState(w),[z,P]=i.useState("normal"===k?"collapse":k);i.useEffect(()=>{B(w)},[w]),i.useEffect(()=>{P("normal"===k?"collapse":k)},[k]),i.useEffect(()=>{if("system"!==H||"undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-color-scheme: dark)");I(e.matches);const t=e=>I(e.matches);return e.addEventListener?(e.addEventListener("change",t),()=>e.removeEventListener("change",t)):(e.addListener(t),()=>e.removeListener(t))},[H]);const W="dark"===H||"system"===H&&F;i.useEffect(()=>{if(!L)return;const e=e=>{"Escape"===e.key&&A(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[L]);const U=i.useMemo(()=>({namespace:e,theme:Nt,onError:e=>{console.error("Lexical error:",e)},nodes:[ft,{replace:d.TextNode,with:e=>new ft(e.__text),withKlass:ft},l.HeadingNode,r.CodeHighlightNode,r.CodeNode,p.ListNode,p.ListItemNode,l.QuoteNode,T.LinkNode,De,xt,Ge,g.HorizontalRuleNode,f.TableNode,f.TableRowNode,f.TableCellNode]}),[e]);return n.jsx("div",{className:`lexical-text-editor lexical-editor-container ${L?"lexical-fullscreen":""} ${W?"lexical-dark":""}`,style:{maxWidth:L?"none":y||"1090px"},children:n.jsxs(o.LexicalComposer,{initialConfig:U,children:[n.jsx("div",{className:"lexical-toolbar-container",children:n.jsx(Ze,{value:t,onImageUpload:v,sourceView:$,onToggleSourceView:()=>{M(e=>!e||(O.current?.(),!1))},fullscreen:L,onToggleFullscreen:()=>{A(e=>!e)},toolbarStyle:z})}),n.jsx("div",{className:"lexical-editor-inner",style:$?{display:"none"}:void 0,children:n.jsx(s.RichTextPlugin,{contentEditable:n.jsx(a.ContentEditable,{className:"lexical-content-editable",style:{height:C||"500px"}}),placeholder:n.jsx("div",{className:"lexical-placeholder",children:N||"Some Text"}),ErrorBoundary:c.LexicalErrorBoundary})}),$&&n.jsx(st,{applyRef:O,onExit:()=>M(!1)}),(j||S||E)&&n.jsx(at,{showWordCount:j,showCharCount:S,rightSlot:E?n.jsx(ct,{theme:H,toolbarStyle:z,onThemeChange:e=>{B(e),_?.(e)},onToolbarStyleChange:e=>{P(e),R?.(e)}}):void 0}),n.jsx(u.HistoryPlugin,{}),n.jsx(h.ListPlugin,{}),n.jsx(x.TablePlugin,{}),n.jsx(m.HorizontalRulePlugin,{}),n.jsx(D.LinkPlugin,{}),n.jsx(et,{}),n.jsx(rt,{value:t,onChange:b})]})})});exports.LexicalTextEditor=yt;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|