@innoviatech/lexical-text-editor 3.0.1 → 3.0.2
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/constants/index.d.ts +19 -22
- 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/package.json +1 -1
|
@@ -38,49 +38,46 @@ export declare enum HeadingAction {
|
|
|
38
38
|
H5 = "h5",
|
|
39
39
|
H6 = "h6"
|
|
40
40
|
}
|
|
41
|
-
export declare const RICH_TEXT_FORMAT_OPTIONS:
|
|
41
|
+
export declare const RICH_TEXT_FORMAT_OPTIONS: {
|
|
42
42
|
id: RichTextAction;
|
|
43
43
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
44
44
|
label: string;
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
}[];
|
|
46
|
+
export declare const RICH_TEXT_OPTIONS: {
|
|
47
47
|
id: RichTextAction;
|
|
48
48
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
49
49
|
label: string;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export declare const RICH_TEXT_OPTIONS: ({
|
|
50
|
+
}[];
|
|
51
|
+
export declare const RICH_HIGHLIGHT_OPTIONS: {
|
|
53
52
|
id: RichTextAction;
|
|
54
53
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
55
54
|
label: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
icon?: undefined;
|
|
59
|
-
label?: undefined;
|
|
60
|
-
})[];
|
|
61
|
-
export declare const RICH_REDO_UNDO_OPTIONS: ({
|
|
55
|
+
}[];
|
|
56
|
+
export declare const RICH_QUOTE_CODE_OPTIONS: {
|
|
62
57
|
id: RichTextAction;
|
|
63
58
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
64
59
|
label: string;
|
|
65
|
-
}
|
|
60
|
+
}[];
|
|
61
|
+
export declare const RICH_REDO_UNDO_OPTIONS: {
|
|
66
62
|
id: RichTextAction;
|
|
67
|
-
icon
|
|
68
|
-
label
|
|
69
|
-
}
|
|
70
|
-
export declare const
|
|
63
|
+
icon: import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
label: string;
|
|
65
|
+
}[];
|
|
66
|
+
export declare const RICH_BLOCK_OPTIONS: {
|
|
71
67
|
id: RichTextAction;
|
|
72
68
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
73
69
|
label: string;
|
|
74
70
|
}[];
|
|
75
|
-
export declare const
|
|
71
|
+
export declare const RICH_HLINE_OPTIONS: {
|
|
76
72
|
id: RichTextAction;
|
|
77
73
|
icon: import("react/jsx-runtime").JSX.Element;
|
|
78
74
|
label: string;
|
|
79
|
-
}
|
|
75
|
+
}[];
|
|
76
|
+
export declare const RICH_ALIGNMENT_OPTIONS: {
|
|
80
77
|
id: RichTextAction;
|
|
81
|
-
icon
|
|
82
|
-
label
|
|
83
|
-
}
|
|
78
|
+
icon: import("react/jsx-runtime").JSX.Element;
|
|
79
|
+
label: string;
|
|
80
|
+
}[];
|
|
84
81
|
export declare const LOW_PRIORIRTY = 1;
|
|
85
82
|
export declare const HEADINGS: {
|
|
86
83
|
id: string;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{LexicalComposer as o}from"@lexical/react/LexicalComposer";import i,{useRef as l,useEffect as r,cloneElement as a,useState as c,useCallback as s,useMemo as d}from"react";import{$isHeadingNode as u,$isQuoteNode as h,$createQuoteNode as p,$createHeadingNode as m,HeadingNode as g,QuoteNode as f}from"@lexical/rich-text";import{$isCodeNode as b,$createCodeNode as y,CodeHighlightNode as v,CodeNode as x}from"@lexical/code";import{RichTextPlugin as w}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as C}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as k}from"@lexical/react/LexicalErrorBoundary";import{$createRangeSelection as N,$findMatchingParent as S,INTERNAL_$isBlock as _,$isElementNode as L,$getSelection as T,$setSelection as E,$isRootOrShadowRoot as A,$hasAncestor as R,$isRangeSelection as M,$isTextNode as D,$isTokenOrSegmented as F,$getCharacterOffsets as z,$isLeafNode as W,$getPreviousSelection as O,$caretRangeFromSelection as I,$getRoot as H,$getNodeByKey as U,SELECTION_CHANGE_COMMAND as $,$createParagraphNode as P,KEY_TAB_COMMAND as B,OUTDENT_CONTENT_COMMAND as K,INDENT_CONTENT_COMMAND as J,COMMAND_PRIORITY_EDITOR as V,DecoratorNode as j,$applyNodeReplacement as q,PASTE_COMMAND as Q,COMMAND_PRIORITY_LOW as X,$insertNodes as Y,CAN_REDO_COMMAND as G,CAN_UNDO_COMMAND as Z,REDO_COMMAND as ee,UNDO_COMMAND as te,FORMAT_ELEMENT_COMMAND as ne,FORMAT_TEXT_COMMAND as oe,isDOMDocumentNode as ie,ArtificialNode__DO_NOT_USE as le,$createLineBreakNode as re,$cloneWithProperties as ae,getRegisteredNode as ce,isHTMLElement as se,isDocumentFragment as de,$isBlockElementNode as ue,isBlockDomNode as he,isInlineDomNode as pe,TextNode as me}from"lexical";import{HistoryPlugin as ge}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as fe}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as be,INSERT_ORDERED_LIST_COMMAND as ye,INSERT_UNORDERED_LIST_COMMAND as ve,ListNode as xe,$isListNode as we,ListItemNode as Ce}from"@lexical/list";import{INSERT_HORIZONTAL_RULE_COMMAND as ke,HorizontalRuleNode as Ne}from"@lexical/react/LexicalHorizontalRuleNode";import{HorizontalRulePlugin as Se}from"@lexical/react/LexicalHorizontalRulePlugin";import{TablePlugin as _e}from"@lexical/react/LexicalTablePlugin";import{$findCellNode as Le,INSERT_TABLE_COMMAND as Te,$isTableCellNode as Ee,TableCellHeaderStates as Ae,$insertTableRowAtSelection as Re,$deleteTableRowAtSelection as Me,$insertTableColumnAtSelection as De,$deleteTableColumnAtSelection as Fe,TableNode as ze,TableRowNode as We,TableCellNode as Oe}from"@lexical/table";import{RxLetterCaseLowercase as Ie,RxLetterCaseUppercase as He,RxLetterCaseCapitalize as Ue}from"react-icons/rx";import{TbBold as $e,TbItalic as Pe,TbUnderline as Be,TbSeparatorHorizontal as Ke,TbArrowsLeftRight as Je}from"react-icons/tb";import{BsSuperscript as Ve,BsSubscript as je,BsChatSquareQuote as qe,BsArrowCounterclockwise as Qe,BsArrowClockwise as Xe,BsJustifyLeft as Ye,BsTextCenter as Ge,BsJustifyRight as Ze,BsJustify as et,BsTextParagraph as tt,BsTypeH1 as nt,BsTypeH2 as ot,BsTypeH3 as it,BsTypeH4 as lt,BsTypeH5 as rt,BsTypeH6 as at,BsPencilSquare as ct,BsListOl as st,BsListUl as dt,BsTable as ut,BsFullscreenExit as ht,BsFullscreen as pt,BsThreeDots as mt,BsSun as gt,BsMoon as ft}from"react-icons/bs";import{AiOutlineStrikethrough as bt,AiOutlineFontColors as yt,AiOutlineBgColors as vt}from"react-icons/ai";import{IoCodeSlashOutline as xt,IoChevronUp as wt,IoChevronDown as Ct,IoClose as kt,IoImageOutline as Nt,IoSearchOutline as St,IoCodeOutline as _t}from"react-icons/io5";import{PiHighlighterLight as Lt}from"react-icons/pi";import{RiEraserLine as Tt,RiIndentIncrease as Et,RiIndentDecrease as At,RiFontFamily as Rt,RiFontSize as Mt}from"react-icons/ri";import{useLexicalComposerContext as Dt}from"@lexical/react/LexicalComposerContext";import{TOGGLE_LINK_COMMAND as Ft,$isLinkNode as zt,LinkNode as Wt}from"@lexical/link";import{HiChevronDown as Ot}from"react-icons/hi2";import{createPortal as It}from"react-dom";import{IoIosLink as Ht}from"react-icons/io";import{MdCheck as Ut,MdMonitor as $t,MdWrapText as Pt}from"react-icons/md";import{BiUnlink as Bt}from"react-icons/bi";import{SketchPicker as Kt}from"react-color";import{LuUpload as Jt}from"react-icons/lu";import{FaYoutube as Vt}from"react-icons/fa";import{VscPreview as jt}from"react-icons/vsc";import{LinkPlugin as qt}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as Qt}from"@lexical/react/LexicalOnChangePlugin";var Xt,Yt;!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"}(Xt||(Xt={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(Yt||(Yt={}));const Gt=[{id:Xt.Lowercase,icon:e(Ie,{}),label:"Lowercase"},{id:Xt.Uppercase,icon:e(He,{}),label:"Uppercase"},{id:Xt.Capitalize,icon:e(Ue,{}),label:"Capitalize"},{id:Xt.Strikethrough,icon:e(bt,{}),label:"Strikethrough"},{id:Xt.Highlight,icon:e(Lt,{}),label:"Highlight",fontSize:10},{id:Xt.Superscript,icon:e(Ve,{}),label:"Superscript"},{id:Xt.Subscript,icon:e(je,{}),label:"Subscript"}],Zt=[{id:Xt.Bold,icon:e($e,{}),label:"Bold"},{id:Xt.Italics,icon:e(Pe,{}),label:"Italics"},{id:Xt.Underline,icon:e(Be,{}),label:"Underline"},{id:Xt.Divider},{id:Xt.Quote,icon:e(qe,{}),label:"Quote"},{id:Xt.Code,icon:e(xt,{}),label:"Code"},{id:Xt.ClearFormatting,icon:e(Tt,{}),label:"Clear Formatting"}],en=[{id:Xt.Undo,icon:e(Qe,{}),label:"Undo"},{id:Xt.Redo,icon:e(Xe,{}),label:"Redo"},{id:Xt.Divider}],tn=[{id:Xt.LeftAlign,icon:e(Ye,{}),label:"Left Align"},{id:Xt.CenterAlign,icon:e(Ge,{}),label:"Center Align"},{id:Xt.RightAlign,icon:e(Ze,{}),label:"Right Align"},{id:Xt.JustifyAlign,icon:e(et,{}),label:"Justify Align"}],nn=[{id:Xt.Indent,icon:e(Et,{}),label:"Indent"},{id:Xt.Outdent,icon:e(At,{}),label:"Outdent"},{id:Xt.Divider},{id:Xt.HorizontalRule,icon:e(Ke,{}),label:"Horizontal Rule"}],on=[{id:"normal",label:"Normal",icon:e(tt,{})},{id:"h1",label:"Heading 1",icon:e(nt,{})},{id:"h2",label:"Heading 2",icon:e(ot,{})},{id:"h3",label:"Heading 3",icon:e(it,{})},{id:"h4",label:"Heading 4",icon:e(lt,{})},{id:"h5",label:"Heading 5",icon:e(rt,{})},{id:"h6",label:"Heading 6",icon:e(at,{})}],ln=[{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 rn(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 an=new Map;function cn(e){let t=an.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),an.set(e,t)),t}function sn(e,t){(M(e)?e.isCollapsed():D(e)||L(e))||rn(280);const n=cn(M(e)?e.style:D(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);M(e)||D(e)?e.setStyle(i):e.setTextStyle(i),an.set(i,o)}function dn(e,t){if(M(e)&&e.isCollapsed()){sn(e,t);const n=e.anchor.getNode();L(n)&&n.isEmpty()&&sn(n,t)}!function(e){const t=T();if(!t)return;const n=new Map,o=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(M(t))for(const e of I(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const i=t.getNodes();for(const t of i){if(!D(t)||!t.canHaveFormat())continue;const[n,i]=o(t);i!==n&&(F(t)||0===n&&i===t.getTextContentSize()?e(t):e(t.splitText(n,i)[0===n?0:1]))}M(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=>{sn(e,t)})}function un(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function hn(e,t,n=un){if(null===e)return;const o=e.getStartEndPoints(),i=new Map;let l=null;if(o){const[e,t]=o;l=N(),l.anchor.set(e.key,e.offset,e.type),l.focus.set(t.key,t.offset,t.type);const n=S(e.getNode(),_),r=S(t.getNode(),_);L(n)&&i.set(n.getKey(),n),L(r)&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(L(t)&&_(t))i.set(t.getKey(),t);else if(null===o){const e=S(t,_);L(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(T())&&E(l)}function pn(e){return e.getNode().isAttached()}function mn(e){let t=e;for(;null!==t&&!A(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function gn(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 a=null,c=[];for(let o=0;o<r;o++){const i=l[o];A(i)?(fn(e,c,c.length,t,n),c=[],a=i):null===a||null!==a&&R(i,a)?c.push(i):(fn(e,c,c.length,t,n),c=[i])}fn(e,c,c.length,t,n)}function fn(e,t,n,o,i=null){if(0===t.length)return;const l=t[0],r=new Map,a=[];let c=L(l)?l:l.getParentOrThrow();c.isInline()&&(c=c.getParentOrThrow());let s=!1;for(;null!==c;){const e=c.getPreviousSibling();if(null!==e){c=e,s=!0;break}if(c=c.getParentOrThrow(),A(c))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];L(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const u=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&&W(n)&&!u.has(n.getKey())){const e=i.getKey();if(void 0===r.get(e)){const t=o();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),a.push(t),r.set(e,t),i.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),L(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),mn(i)}}else if(d.has(n.getKey())){L(n)||rn(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),a.push(e),n.remove(!0)}}if(null!==i)for(let e=0;e<a.length;e++){const t=a[e];i.append(t)}let h=null;if(A(c))if(s)if(null!==i)c.insertAfter(i);else for(let e=a.length-1;e>=0;e--){const t=a[e];c.insertAfter(t)}else{const e=c.getFirstChild();if(L(e)&&(c=e),null===e)if(i)c.append(i);else for(let e=0;e<a.length;e++){const t=a[e];c.append(t),h=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<a.length;t++){const n=a[t];e.insertBefore(n),h=n}}else if(i)c.insertAfter(i);else for(let e=a.length-1;e>=0;e--){const t=a[e];c.insertAfter(t),h=t}const p=O();M(p)&&pn(p.anchor)&&pn(p.focus)?E(p.clone()):null!==h?h.selectEnd():e.dirty=!0}function bn(e,t,n){const o=cn(e.getStyle());return null!==o&&o[t]||n}function yn(e,t,n=""){let o=null;const i=e.getNodes(),l=e.anchor,r=e.focus,a=e.isBackward(),c=a?r.offset:l.offset,s=a?r.getNode():l.getNode();if(M(e)&&e.isCollapsed()&&""!==e.style){const n=cn(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!==c||!l.is(s))&&D(l)){const e=bn(l,t,n);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?n:o}const vn="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,xn=vn&&"documentMode"in document?document.documentMode:null;function wn(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Cn(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function kn({open:t,onOpenChange:n,children:o}){const c=l(null),s=l(null);return r(()=>{function e(e){c.current?.contains(e.target)||s.current?.contains(e.target)||n(!1)}return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,n]),e("div",{className:"popover-root",children:i.Children.map(o,e=>e&&"object"==typeof e?e.type===Nn?a(e,{triggerRef:c}):e.type===Sn?a(e,{contentRef:s,triggerRef:c}):e:e)})}function Nn({children:t,triggerRef:n}){return e("div",{className:"popover-trigger",ref:n,children:t})}function Sn({open:t,align:n="start",children:o,contentRef:a,triggerRef:c}){const s=l(null),[d,u]=i.useState(!1);return r(()=>{if(!t)return;const e=()=>{const e=s.current,t=c?.current;if(!e||!t)return;const o=t.closest(".lexical-text-editor"),i=!!o?.classList.contains("lexical-dark");e.classList.contains("lexical-dark")!==i&&e.classList.toggle("lexical-dark",i);const l=t.getBoundingClientRect(),r=e.offsetWidth,a=e.offsetHeight;let d=l.left;"center"===n?d=l.left+l.width/2-r/2:"end"===n&&(d=l.right-r),d=Math.max(8,Math.min(window.innerWidth-r-8,d));let h=l.bottom+4;h+a>window.innerHeight-8&&l.top>a+8&&(h=l.top-a-4),e.style.left=`${d}px`,e.style.top=`${h}px`,u(i)};return e(),requestAnimationFrame(e),window.addEventListener("resize",e),document.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),document.removeEventListener("scroll",e,!0)}},[t,n,c]),t?It(e("div",{ref:s,className:"lexical-text-editor"+(d?" lexical-dark":""),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:e("div",{ref:e=>{a.current=e},className:"popover-content",style:{position:"static",top:"auto",left:"auto",borderRadius:6,border:"none",boxShadow:"none",margin:0,width:"100%"},children:o})}),document.body):null}function _n({onAction:n,selectionMap:o}){const[i,r]=c(!1),a=l(null),s=l(null);return t(kn,{open:i,onOpenChange:r,children:[e(Nn,{triggerRef:a,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[e("span",{children:"Aa"}),e(Ot,{className:"chevron "+(i?"rotated":"")})]})}),e(Sn,{open:i,align:"start",onClose:()=>r(!1),contentRef:s,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:Gt.map(({id:i,label:l,icon:a})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),r(!1)},style:{minWidth:130},children:[a,e("span",{className:"label",children:l})]},i))})})]})}function Ln(){return e("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function Tn({updateHeading:n,headingSelectionMap:o}){const i=on.find(e=>o[e.id]),[r,a]=c(!1),s=l(null),d=l(null);return t(kn,{open:r,onOpenChange:a,children:[e(Nn,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>a(e=>!e),style:{minWidth:132},children:[i?.icon,e("span",{children:i?.label}),e(Ot,{className:"chevron "+(r?"rotated":"")})]})}),e(Sn,{open:r,align:"start",onClose:()=>a(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:on.map(({id:i,label:l,icon:r})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),a(!1)},children:[r,e("span",{className:"label",children:l})]},i))})})]})}function En({linkUrl:n,setLinkUrl:o,onConfirm:i,onCancel:a,removeLink:s}){const[d,u]=c(!1),h=l(null),p=l(null);return r(()=>{"https://"===n&&u(!0)},[n]),r(()=>{d&&p.current?.focus()},[d]),r(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&a()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]),t("div",{ref:h,className:"lexical-text-editor-link link-editor-container",children:[e("div",{className:"link-editor-input-wrapper",children:d?e("input",{ref:p,className:"link-editor-input",value:n,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),i(n),u(!1)):"Escape"===e.key&&(e.preventDefault(),u(!1),a())}}):e("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:n})}),t("div",{className:"link-editor-buttons",children:[e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{d?(i(n),u(!1)):u(!0)},children:d?e(Ut,{size:18}):e(ct,{size:14})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:e(Bt,{size:14,style:{stroke:"black"}})})]})]})}function An({onClose:n}){const[o]=Dt(),[i,a]=c(""),[s,d]=c(""),[u,h]=c(!1),[p,m]=c([]),[g,f]=c(0),b=l(null);r(()=>{b.current?.focus()},[]);const y=()=>{if(!i)return[];const e=u?i:i.toLowerCase(),t=[],n=H().getAllTextNodes();for(const o of n){const n=u?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};r(()=>{const e=o.getEditorState().read(y);m(e),f(0)},[o,i,u]),r(()=>o.registerUpdateListener(({editorState:e})=>{const t=e.read(y);m(t),f(e=>0===t.length?0:Math.min(e,t.length-1))}),[o,i,u]);const v=e=>{if(0===p.length)return;const t=(g+e+p.length)%p.length,n=p[t];f(t),o.update(()=>{const e=U(n.key);D(e)&&e.select(n.start,n.start+i.length)}),requestAnimationFrame(()=>{const e=o.getElementByKey(n.key);e?.scrollIntoView({block:"nearest"})})},x=i.length>0,w=p.length>0;return t("div",{className:"lexical-find-replace",onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),n())},children:[t("div",{className:"lexical-fr-row",children:[e("input",{ref:b,className:"lexical-fr-input",placeholder:"Find",value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v(e.shiftKey?-1:1))}}),e("span",{className:"lexical-fr-count",children:w?`${g+1} of ${p.length}`:x?"0 results":""})]}),e("div",{className:"lexical-fr-row",children:e("input",{className:"lexical-fr-input",placeholder:"Replace with",value:s,onChange:e=>d(e.target.value)})}),t("div",{className:"lexical-fr-row",children:[t("label",{className:"lexical-fr-case",children:[e("input",{type:"checkbox",checked:u,onChange:e=>h(e.target.checked)}),e("span",{children:"Match case"})]}),e("span",{style:{flex:1}}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>v(-1),disabled:!w,"aria-label":"Previous match",children:e(wt,{})}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>v(1),disabled:!w,"aria-label":"Next match",children:e(Ct,{})}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{o.update(()=>{const e=y();if(0===e.length)return m([]),void f(0);const t=e[Math.min(g,e.length-1)],n=U(t.key);D(n)&&n.spliceText(t.start,i.length,s,!0)})},disabled:!w,children:"Replace"}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{o.update(()=>{const e=y();for(let t=e.length-1;t>=0;t--){const n=e[t],o=U(n.key);D(o)&&o.spliceText(n.start,i.length,s,!1)}})},disabled:!w,children:"Replace All"}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:n,"aria-label":"Close find and replace",children:e(kt,{})})]})]})}function Rn({anchorRef:t,onClose:n,children:o}){const i=l(null);return r(()=>{const e=e=>{const o=e.target;!i.current||i.current.contains(o)||t.current&&t.current.contains(o)||n()},o=e=>{"Escape"===e.key&&n()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",o)}},[t,n]),e("div",{ref:i,className:"lte-overflow-panel",children:e("div",{className:"lte-overflow-grid",children:o})})}function Mn({onAction:n,alignmentSelectionMap:o}){const i=tn.find(e=>o[e.id]),[r,a]=c(!1),s=l(null),d=l(null);return t(kn,{open:r,onOpenChange:a,children:[e(Nn,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>a(e=>!e),style:{minWidth:146},children:[i?.icon,e("span",{children:i?.label}),e(Ot,{className:"chevron "+(r?"rotated":"")})]})}),e(Sn,{open:r,align:"start",onClose:()=>a(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:tn.map(({id:i,label:l,icon:r})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),a(!1)},children:[r,e("span",{className:"label",children:l})]},i))})})]})}function Dn({color:n,onChange:o,icon:i}){const[a,s]=c(!1),d=l(null),u=l(null);r(()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return t("div",{className:"color-picker-wrapper",children:[e("button",{type:"button",ref:d,className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:i}),a&&It(e("div",{ref:u,className:"lexical-color-popover "+(a?"open":""),style:{top:d.current?.getBoundingClientRect().bottom,left:d.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e(Kt,{color:n,onChangeComplete:e=>{o(e.hex)}})}),document.body)]})}function Fn(){const[o]=Dt(),[{color:i,bgColor:l},a]=c({color:"#000",bgColor:"#fff"}),s=()=>{const e=T();if(M(e)){const t=yn(e,"color","#000"),n=yn(e,"background","#fff");a({color:t,bgColor:n})}};r(()=>wn(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),o.registerCommand($,()=>(s(),!1),1)),[o]);const d=({property:e,color:t})=>{o.update(()=>{const n=T();n&&dn(n,{[e]:t})})};return t(n,{children:[e(Dn,{color:i,onChange:e=>{d({property:"color",color:e})},icon:e(yt,{})}),e(Dn,{color:l,onChange:e=>{d({property:"background",color:e})},icon:e(vt,{})})]})}function zn({icon:n,tooltipLabel:o,currentValue:i,options:r,onSelect:a,minWidth:s=132}){const d=r.find(e=>""!==e.id&&e.id===i),[u,h]=c(!1),p=l(null),m=l(null);return t(kn,{open:u,onOpenChange:h,children:[e(Nn,{triggerRef:p,children:t("button",{type:"button","aria-label":o,className:"lexical-btn heading-trigger font-trigger "+(u?"toolbar-active":"toolbar"),style:{minWidth:s},onClick:()=>h(e=>!e),children:[n,e("span",{children:d?.label??"Default"}),e(Ot,{className:"chevron "+(u?"rotated":"")})]})}),e(Sn,{open:u,align:"start",onClose:()=>h(!1),contentRef:m,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:r.map(t=>e("button",{type:"button",className:"lexical-btn "+(""===t.id&&""===i||""!==t.id&&t.id===i?"toolbar-active":"toolbar"),onClick:()=>{a(t.id),h(!1)},children:e("span",{className:"label",children:t.label})},t.label))})})]})}vn&&"InputEvent"in window&&!xn&&new window.InputEvent("input");const Wn=[{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 On(){const[t]=Dt(),[n,o]=c(""),i=()=>{const e=T();if(M(e)){const t=yn(e,"font-family","");o((e=>e.replace(/['"]/g,"").trim())(t))}};r(()=>wn(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{i()})}),t.registerCommand($,()=>(i(),!1),1)),[t]);return e(zn,{icon:e(Rt,{}),tooltipLabel:"Font Family",currentValue:n,options:Wn,onSelect:e=>{t.update(()=>{const t=T();M(t)&&dn(t,{"font-family":""===e?null:e})})}})}const In=[{id:"",label:"Default"},...[12,14,16,18,20,24,28,32,36,48].map(e=>({id:`${e}px`,label:`${e}`}))];function Hn(){const[t]=Dt(),[n,o]=c(""),i=()=>{const e=T();if(M(e)){const t=yn(e,"font-size","");o((e=>e.trim())(t))}};r(()=>wn(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{i()})}),t.registerCommand($,()=>(i(),!1),1)),[t]);return e(zn,{icon:e(Mt,{}),tooltipLabel:"Font Size",currentValue:n,options:In,onSelect:e=>{t.update(()=>{const t=T();M(t)&&dn(t,{"font-size":""===e?null:e})})}})}function Un(){const[n]=Dt(),[o,i]=c(!1),[a,s]=c(null),[d,u]=c(!1),h=l(null),p=l(null),m=()=>{const e=T();if(M(e)){const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow(),o=b(n);i(o),o&&s(n.getLanguage()??null)}};r(()=>wn(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{m()})}),n.registerCommand($,()=>(m(),!1),1)),[n]);const g=ln.find(e=>e.id===a)?.label??"Plain Text";return t(kn,{open:d,onOpenChange:u,children:[e(Nn,{triggerRef:h,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>u(e=>!e),children:[e(xt,{}),e("span",{children:g}),e(Ot,{className:"chevron "+(d?"rotated":"")})]})}),e(Sn,{open:d,align:"start",onClose:()=>u(!1),contentRef:p,children:t("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[t("button",{type:"button",className:"lexical-btn "+(o?"toolbar-active":"toolbar"),onClick:()=>{n.update(()=>{const e=T();if(!M(e))return;const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow();if(b(n))hn(e,()=>P());else{const t=a??"javascript";hn(e,()=>y(t))}}),u(!1)},style:{minWidth:150},children:[e(xt,{}),e("span",{className:"label",children:o?"Remove Code Block":"Code Block"})]}),e("div",{className:"w-full h-[1px] bg-gray-200 my-1"}),e("div",{style:{display:"flex",flexDirection:"column",gap:5,maxHeight:260,overflowY:"auto"},children:ln.map(({id:t,label:o})=>e("button",{type:"button",className:"lexical-btn "+(a===t?"toolbar-active":"toolbar"),onClick:()=>{var e;s(e=t),n.update(()=>{const t=T();if(!M(t))return;const n=t.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow();b(o)&&o.setLanguage(e)}),u(!1)},style:{minWidth:150},children:e("span",{className:"label",children:o})},t))})]})})]})}const $n=({content:n,direction:o="top",delay:i=400,children:r})=>{const[a,s]=c(!1),[d,u]=c(null),h=l(null),p=l(null),m=()=>{h.current=window.setTimeout(()=>{const e=p.current;if(e){const t=e.getBoundingClientRect();u({left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height})}s(!0)},i)},g=()=>{h.current&&clearTimeout(h.current),s(!1)};if(!d)return e("div",{ref:p,className:"Lexical-Tooltip-Wrapper",onMouseEnter:m,onMouseLeave:g,children:r});const f=d.left+d.width/2,b=d.top+d.height/2,y="bottom"===o?{top:d.bottom+10,left:f,bottom:"auto"}:"top"===o?{bottom:window.innerHeight-d.top+10,top:"auto",left:f}:"right"===o?{left:d.right+10,right:"auto",top:b}:{left:"auto",right:window.innerWidth-d.left+10,top:b};return t("div",{ref:p,className:"Lexical-Tooltip-Wrapper",onMouseEnter:m,onMouseLeave:g,children:[r,a&&It(e("div",{className:`Lexical-Tooltip-Tip ${o}`,style:{position:"fixed",pointerEvents:"none",...y,zIndex:1e4},children:n}),document.body)]})};function Pn({blockType:o}){const[i]=Dt();r(()=>wn(i.registerCommand(B,e=>{const t=T();if(!M(t))return!1;return!!Cn(t.anchor.getNode(),xe)&&(e.preventDefault(),i.dispatchCommand(e.shiftKey?K:J,void 0),!0)},V)),[i]);return t(n,{children:[e($n,{content:"Ordered list",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${"ol"===o?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===o?i.dispatchCommand(be,void 0):i.dispatchCommand(ye,void 0)},children:e(st,{})})}),e($n,{content:"Unordered list",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${"ul"===o?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===o?i.dispatchCommand(be,void 0):i.dispatchCommand(ve,void 0)},children:e(dt,{})})})]})}function Bn(){const[n]=Dt(),[o,i]=c(!1),[a,s]=c(!1),[d,u]=c(null),h=l(null),p=l(null),m=()=>{const e=T();if(M(e)){const t=Le(e.anchor.getNode());i(!!t)}else i(!1)};r(()=>wn(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{m()})}),n.registerCommand($,()=>(m(),!1),1)),[n]);const g=e=>{n.update(()=>{const t=T();M(t)&&e()}),s(!1)},f=d?`${d.rows} × ${d.cols}`:"Insert Table";return t(kn,{open:a,onOpenChange:s,children:[e(Nn,{triggerRef:h,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),children:[e(ut,{}),e(Ot,{className:"chevron "+(a?"rotated":"")})]})}),e(Sn,{open:a,align:"start",onClose:()=>s(!1),contentRef:p,children:t("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t("div",{style:{width:"fit-content"},children:[e("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,r=d&&i<=d.rows&&l<=d.cols;return e("div",{onMouseEnter:()=>u({rows:i,cols:l}),onClick:()=>{return e=i,t=l,n.dispatchCommand(Te,{rows:String(e),columns:String(t),includeHeaders:!1}),void s(!1);var e,t},style:{width:18,height:18,borderRadius:3,border:"1px solid #d1d5db",backgroundColor:r?"#c7d2fe":"#fff",cursor:"pointer"}},o)})}),e("div",{style:{fontSize:12,color:"#6b7280",marginTop:4},children:f})]}),e("div",{className:"w-full h-[1px] bg-gray-200"}),t("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Re(!1)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert row above"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Re(!0)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert row below"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Me()}),style:{minWidth:160},children:e("span",{className:"label",children:"Delete row"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{De(!1)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert column left"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{De(!0)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert column right"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Fe()}),style:{minWidth:160},children:e("span",{className:"label",children:"Delete column"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>{g(()=>{const e=T();if(!M(e))return;const t=Le(e.anchor.getNode());if(!t)return;const n=t.getParent();if(!n)return;const o=n.getChildren().filter(Ee),i=o.some(e=>e.hasHeaderState(Ae.ROW));for(const e of o)e.setHeaderStyles(i?Ae.NO_STATUS:Ae.ROW,Ae.ROW)})},style:{minWidth:160},children:e("span",{className:"label",children:"Toggle header row"})})]})]})})]})}const Kn=({src:n,altText:o,nodeKey:i,width:r,height:a,maxWidth:s,caption:d=""})=>{const[u]=Dt(),[h,p]=c(!1),[m,g]=c(d),f=l(null),b=l(null),y=l(null),v=l(null),x=e=>{if(!v.current||!b.current)return;const t=e.clientX-v.current.x,n=Math.min(s,Math.max(50,v.current.width+t)),o=n*b.current.ratio;b.current.width=n,b.current.height=o;const i=y.current?.querySelector("img");i&&(i.style.width=n+"px",i.style.height=o+"px")},w=()=>{if(!b.current)return;const{width:e,height:t}=b.current;u.update(()=>{const n=U(i);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),b.current=null,v.current=null,window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",w)},C=()=>{p(!1),u.update(()=>{const e=U(i);e&&"function"==typeof e.setCaption&&e.setCaption(m)})},k=()=>{g(d),p(!0),setTimeout(()=>f.current?.focus(),0)};return t("div",{ref:y,style:{display:"inline-block",position:"relative",maxWidth:s},children:[e("img",{src:n,alt:o,width:"inherit"===r?void 0:r,height:"inherit"===a?void 0:a,style:{maxWidth:"100%",display:"block"}}),(d||h)&&e("div",{style:{textAlign:"center",marginTop:4},children:h?e("input",{ref:f,className:"lte-input",style:{width:"100%",textAlign:"center"},value:m,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C()}}):e("span",{style:{fontSize:13,color:"#666",cursor:"text",display:"inline-block",minWidth:20,minHeight:18},onClick:k,children:d})}),!d&&!h&&e("div",{style:{textAlign:"center",marginTop:2},children:e("span",{style:{fontSize:12,color:"#999",cursor:"pointer"},onClick:k,children:"+ Add caption"})}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=y.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,o=t.naturalHeight/t.naturalWidth,i=n*o;v.current={x:e.clientX,y:e.clientY,width:n,height:i},b.current={width:n,height:i,ratio:o},window.addEventListener("mousemove",x),window.addEventListener("mouseup",w)},style:{position:"absolute",bottom:d||h?40:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Jn=e=>q(new jn(e)),Vn=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:Jn({src:t,altText:n,width:o??"inherit",height:i??"inherit"})}};class jn extends j{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 jn({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:Vn,priority:1}),figure:()=>({conversion:e=>{const t=e.querySelector("img");if(!t)return null;const n=e.querySelector("figcaption"),o=n?.textContent||"",i=Vn(t);return i?.node instanceof jn&&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 jn({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 e(Kn,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth,caption:this.__caption})}}function qn({open:n,onClose:o,forPreview:i=!1,children:a}){const c=l(null);return r(()=>{if(!n)return;const e=e=>{c.current&&!c.current.contains(e.target)&&o()},t=e=>{"Escape"===e.key&&o()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[n,o]),n?e("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:t("div",{ref:c,className:"lte-dialog "+(i?"preview":""),children:[e("button",{type:"button",className:"lte-dialog-close",onClick:o,children:"×"}),a]})}):null}async function Qn(e,{src:t,altText:n="",caption:o=""}){e.update(()=>{const e=Jn({src:t,altText:n,caption:o});Y([e])})}function Xn({onImageUpload:n}){const[o]=Dt(),i=l(null),[a,d]=c(!1),[u,h]=c(""),[p,m]=c(""),[g,f]=c(""),[b,y]=c(),[v,x]=c(!1),w=s(async(e,t="",i="")=>{let l;l=n?await n(e):URL.createObjectURL(e),Qn(o,{src:l,altText:t,caption:i})},[o,n]);return r(()=>{const e=o.registerCommand(Q,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&&w(t,"","").catch(console.error),!0}}return!1},X);return()=>e()},[o,w]),t("div",{className:"lexical-text-editor-dialog",children:[e("input",{type:"file",ref:i,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&y(t),e.target.value=""}}),e($n,{content:"Add Image",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>d(e=>!e),children:e(Nt,{size:18})})}),t(qn,{open:a,onClose:()=>d(!1),children:[e("div",{className:"lte-dialog-header",children:"Add Image"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Alt text",value:p,onChange:e=>m(e.target.value)}),e("input",{className:"lte-input",placeholder:"Caption",value:g,onChange:e=>f(e.target.value)}),e("input",{className:"lte-input",placeholder:"Add image by URL",value:u,onChange:e=>h(e.target.value)}),e("div",{className:"lte-divider",children:e("span",{children:"or"})}),t("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>i.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[e(Jt,{size:20}),e("span",{children:"Upload Image"})]}),b&&e("div",{className:"lte-file-name",children:b.name})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!u&&!b||v,onClick:async()=>{if(!v){if(b){x(!0);try{await w(b,p,g)}catch(e){return console.error("Image upload failed:",e),void x(!1)}x(!1)}else{if(!u)return;Qn(o,{src:u,altText:p,caption:g})}y(void 0),m(""),f(""),h(""),d(!1)}},children:v?"Uploading...":"Add Image"})})]})]})}const Yn=({id:e,provider:t})=>new io({id:e,provider:t}),Gn="data-lexical-video",Zn="data-provider",eo="315px",to="560px",no=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,oo=e=>{const t=e?.getAttribute(Gn),n=e?.getAttribute(Zn)??"youtube";if(!t)return null;return{node:Yn({id:t,provider:n})}};class io extends j{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new io({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Yn({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e("iframe",{height:eo,width:to,src:no(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Gn,this.__id),e.setAttribute(Zn,this.__provider),e.setAttribute("height",eo),e.setAttribute("width",to),e.setAttribute("src",no(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:oo,priority:0})}}}function lo(){const[n,o]=c(!1),[i,l]=c(!1),[a,s]=c(""),[d]=Dt();return r(()=>{n||(s(""),l(!1))},[n]),t("div",{className:"lexical-text-editor-dialog",children:[e($n,{content:"Embed Video",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>o(!0),children:e(Vt,{size:18,color:"red"})})}),t(qn,{open:n,onClose:()=>o(!1),children:[e("div",{className:"lte-dialog-header",children:"Embed Video"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:a,onChange:e=>s(e.target.value)}),i&&e("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!a,onClick:()=>{if(!a)return;let e=null,t=null;const n=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(a);n&&11===n[2]?.length&&(e="youtube",t=n[2]);const i=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(a);i&&i[1]&&(e="drive",t=i[1]),t&&e?(d.update(()=>{const n=Yn({id:t,provider:e});Y([n])}),s(""),l(!1),o(!1)):l(!0)},children:"Embed"})})]})]})}function ro({value:t}){return e("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:t}})}function ao({value:n,triggerLabel:o="Preview"}){const[i,l]=c(!1);return t("div",{className:"lexical-text-editor-dialog",children:[e($n,{content:o,direction:"bottom",children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[e(jt,{size:18}),e("span",{children:o})]})}),t(qn,{open:i,onClose:()=>l(!1),forPreview:!0,children:[e("div",{className:"lte-dialog-header",children:"Content Preview"}),t("div",{className:"lte-preview-container",children:[e("div",{className:"lte-preview-title",children:"CONTENT"}),e(ro,{value:n})]})]})]})}const co=[{id:"fontFamily"},{id:"fontSize"},{id:"color"},{id:"textFormats",primary:!0},{id:"dropdown"},{id:"lists"},{id:"blockOptions"},{id:"primaryAlignment",primary:!0},{id:"primaryLink",primary:!0},{id:"codeBlock"},{id:"image"},{id:"video"},{id:"table"},{id:"utility"},{id:"preview"}];co.filter(e=>!e.primary).map(e=>e.id);const so=["textFormats","lists","primaryAlignment","primaryLink","fontFamily","fontSize","color","dropdown","codeBlock","blockOptions","image","video","table","utility","preview"],uo=({value:o,onImageUpload:i,sourceView:a=!1,onToggleSourceView:d,fullscreen:g=!1,onToggleFullscreen:f,toolbarStyle:b="wrap"})=>{const y="normal"===b?"collapse":b,[v]=Dt(),[x,w]=c({[Xt.Undo]:!0,[Xt.Redo]:!0}),[C,k]=c(!1),[N,S]=c(!1),[_,E]=c(0),[A,R]=c(!1),F=l(null),z=l(null),W=l(null),O=l({}),I=l({}),H=l(0),U=l(null),B=l(null),[V,j]=c({[Xt.LeftAlign]:!0}),[q,Q]=c({[Yt.Normal]:!0}),[X,Y]=c("paragraph"),[ie,le]=c("https://");let re=!0;const ae=()=>{if(re){const e=v.getRootElement();e&&(e.scrollTop=0,re=!1)}const e=T();if(M(e)){const t={[Xt.Bold]:e.hasFormat("bold"),[Xt.Italics]:e.hasFormat("italic"),[Xt.Underline]:e.hasFormat("underline"),[Xt.Uppercase]:e.hasFormat("uppercase"),[Xt.Lowercase]:e.hasFormat("lowercase"),[Xt.Capitalize]:e.hasFormat("capitalize"),[Xt.Strikethrough]:e.hasFormat("strikethrough"),[Xt.Superscript]:e.hasFormat("superscript"),[Xt.Subscript]:e.hasFormat("subscript"),[Xt.Code]:e.hasFormat("code"),[Xt.Highlight]:e.hasFormat("highlight")};j(t);const n=e.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow(),i=o.getKey();if(!v.getElementByKey(i))return;if(we(o)){const e=Cn(n,xe),t=e?e.getTag():o.getTag();Y(t)}else if("paragraph"===o.getType()||u(o)){let e=null;u(o)&&(e=o.getTag());const t={[Yt.H1]:"h1"===e,[Yt.H2]:"h2"===e,[Yt.H3]:"h3"===e,[Yt.H4]:"h4"===e,[Yt.H5]:"h5"===e,[Yt.H6]:"h6"===e,[Yt.Normal]:"paragraph"===o.getType()};Y(o.getType()),Q(t)}else Y(o.getType());const l=(L(n)?n:o).getFormat();j(e=>({...e,[Xt.LeftAlign]:0===l||1===l,[Xt.CenterAlign]:2===l,[Xt.RightAlign]:3===l,[Xt.JustifyAlign]:4===l})),"quote"===o.getType()?j(e=>({...e,[Xt.Quote]:!0})):j(e=>({...e,[Xt.Quote]:!1}));const r=e.anchor.getNode(),a=r.getParent();zt(a)?(j(e=>({...e,[Xt.Link]:!0})),le(a.getURL()),k(!0)):zt(r)?(j(e=>({...e,[Xt.Link]:!0})),le(r.getURL()),k(!0)):(j(e=>({...e,[Xt.Link]:!1})),le("https://"),k(!1))}};r(()=>wn(v.registerUpdateListener(({editorState:e})=>{e.read(()=>{ae()})}),v.registerCommand($,()=>(ae(),!1),1),v.registerCommand(Z,e=>(w(t=>({...t,undo:!e})),!1),1),v.registerCommand(G,e=>(w(t=>({...t,redo:!e})),!1),1)),[]);const ce="scrollbar"===y,se=s(()=>{if("collapse"!==y)return;const e=F.current;if(!e)return;const t=e.clientWidth;if(t<=0)return;const n=z.current?z.current.offsetWidth:0,o=so.map(e=>{const t=O.current[e];return t&&"none"!==t.style.display&&(I.current[e]=t.offsetWidth),I.current[e]??0});W.current&&(H.current=W.current.offsetWidth);const i=H.current||40,l=e=>{const t=1+(e>0?1:0)+(so.length-e);let l=n+6*Math.max(0,t-1)+(e>0?i:0);for(let t=0;t<so.length-e;t++)l+=o[t];return l};let r=_;for(;r<so.length&&l(r)>t;)r++;for(;r>0&&l(r-1)<=t;)r--;E(e=>e===r?e:r)},[_,y]);r(()=>{se()});const de=l(()=>{});de.current=se,r(()=>{if("undefined"==typeof ResizeObserver)return;const e=F.current;if(!e)return;const t=new ResizeObserver(()=>{de.current(),fe.current()});return t.observe(e),()=>t.disconnect()},[]),r(()=>{0===_&&R(!1)},[_]),r(()=>{"collapse"!==y&&E(0)},[y]);const ue=s(()=>{if("scrollbar"!==y)return;const e=F.current,t=U.current,n=B.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,a=l>0?e.scrollLeft/l*r:0;n.style.width=`${i}px`,n.style.transform=`translateX(${a}px)`},[b]),he=s(e=>{e.stopPropagation(),e.preventDefault();const t=F.current,n=B.current;if(!t||!n)return;const o=e.clientX,i=t.scrollLeft,l=t.clientWidth,r=Math.max(24,l/t.scrollWidth*l),a=t.scrollWidth-l,c=l-r,s=e=>{const n=e.clientX-o;t.scrollLeft=c>0?i+n/c*a:0},d=()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",d)};document.addEventListener("pointermove",s),document.addEventListener("pointerup",d)},[]),pe=s(e=>{const t=F.current,n=U.current;if(!t||!n)return;const o=n.getBoundingClientRect(),i=(e.clientX-o.left)/o.width;t.scrollLeft=i*t.scrollWidth-t.clientWidth/2},[]),me=l(null),ge=s(()=>{const e=me.current;if(e)for(const t of e.querySelectorAll(".lte-toolbar-row svg:not(.chevron), .lte-overflow-panel svg:not(.chevron)")){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 a=Math.min(22,Math.max(17,15/r));parseFloat(e.style.width)!==a&&(e.style.width=`${a}px`,e.style.height=`${a}px`)}catch{}}},[]);r(()=>{ge()}),r(()=>{ue()});const fe=l(()=>{});fe.current=ue,r(()=>{if("scrollbar"!==y)return;const e=F.current;if(!e)return;const t=()=>ue();return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[y,ue]);const be=e=>{switch(e){case Xt.Bold:v.dispatchCommand(oe,"bold");break;case Xt.Italics:v.dispatchCommand(oe,"italic");break;case Xt.Underline:v.dispatchCommand(oe,"underline");break;case Xt.Lowercase:v.dispatchCommand(oe,"lowercase");break;case Xt.Uppercase:v.dispatchCommand(oe,"uppercase");break;case Xt.Capitalize:v.dispatchCommand(oe,"capitalize");break;case Xt.Strikethrough:v.dispatchCommand(oe,"strikethrough");break;case Xt.Superscript:v.dispatchCommand(oe,"superscript");break;case Xt.Subscript:v.dispatchCommand(oe,"subscript");break;case Xt.Highlight:v.dispatchCommand(oe,"highlight");break;case Xt.Code:v.dispatchCommand(oe,"code");break;case Xt.Quote:v.update(()=>{const e=T();if(M(e)){const t=e.anchor.getNode().getParent();t&&h(t)?hn(e,()=>P()):gn(e,()=>p())}});break;case Xt.Link:ye(),k(!0);break;case Xt.LeftAlign:v.dispatchCommand(ne,"left");break;case Xt.RightAlign:v.dispatchCommand(ne,"right");break;case Xt.CenterAlign:v.dispatchCommand(ne,"center");break;case Xt.JustifyAlign:v.dispatchCommand(ne,"justify");break;case Xt.Undo:v.dispatchCommand(te,void 0);break;case Xt.Redo:v.dispatchCommand(ee,void 0);break;case Xt.ClearFormatting:v.update(()=>{const e=T();if(!M(e))return;const t=e.getNodes().filter(D);for(const e of t)e.setFormat(0),e.setStyle("")});break;case Xt.HorizontalRule:v.dispatchCommand(ke,void 0);break;case Xt.Indent:v.dispatchCommand(J,void 0);break;case Xt.Outdent:v.dispatchCommand(K,void 0)}},ye=s(()=>{v.update(()=>{const e=T();M(e)&&!e.isCollapsed()&&(C?v.dispatchCommand(Ft,null):""!==ie&&v.dispatchCommand(Ft,ie))})},[v,C,ie]),ve=s(()=>{le(""),v.dispatchCommand(Ft,null),k(!1)},[v]),Ce=e=>so.indexOf(e)>=so.length-_,Ne={textFormats:e(n,{children:Zt.map(({id:t,label:n,icon:o})=>t===Xt.Divider?e(Ln,{},t):e($n,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${V[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>be(t),children:o})},t))}),primaryAlignment:t(n,{children:[e(Mn,{onAction:be,alignmentSelectionMap:V}),e(Ln,{})]}),primaryLink:e($n,{content:"Link",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${V[Xt.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>be(Xt.Link),disabled:!!x[Xt.Link],children:e(Ht,{})})}),lists:t(n,{children:[e(Pn,{blockType:X}),e(Ln,{})]}),blockOptions:e(n,{children:nn.map(({id:t,label:n,icon:o})=>t===Xt.Divider?e(Ln,{},t):e($n,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${V[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>be(t),children:o})},t))}),fontFamily:e(On,{}),fontSize:e(Hn,{}),color:e(Fn,{}),codeBlock:e(Un,{}),dropdown:e(_n,{onAction:be,selectionMap:V}),image:e(Xn,{onImageUpload:i}),video:e(lo,{}),table:e(Bn,{}),utility:t(n,{children:[e(Ln,{}),e($n,{content:"Find & Replace",direction:"bottom",children:e("button",{type:"button","aria-label":"Find & Replace",className:`size-10 lexical-btn ${N?"toolbarActive":"toolbar"} icon`,onClick:()=>S(e=>!e),children:e(St,{})})}),e($n,{content:"Source Code View",direction:"bottom",children:e("button",{type:"button","aria-label":"Source Code View",className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>d?.(),children:e(_t,{})})}),e($n,{content:g?"Exit Fullscreen":"Fullscreen",direction:"bottom",children:e("button",{type:"button","aria-label":g?"Exit Fullscreen":"Fullscreen",className:`size-10 lexical-btn ${g?"toolbarActive":"toolbar"} icon`,onClick:()=>f?.(),children:e(g?ht:pt,{})})})]}),preview:e(ao,{value:o})};return t("div",{ref:me,className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[t("div",{ref:F,className:"lte-toolbar-row "+(ce?"useScroll":"collapse"===y?"lte-nowrap":"lte-wrap"),children:[t("div",{ref:z,className:"lte-toolbar-primary",style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[en.map(({id:t,label:n,icon:o})=>t===Xt.Divider?e(Ln,{},t):e($n,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${V[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>be(t),disabled:!!x[t],children:o})},n)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Tn,{updateHeading:e=>{v.update(()=>{const t=T();M(t)&&gn(t,"normal"===e?()=>P():()=>m(e))})},headingSelectionMap:q}),e(Ln,{})]})]}),co.map(({id:t})=>{const n=Ce(t);return e("div",{ref:e=>{O.current[t]=e},style:n?{display:"none"}:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:n?null:Ne[t]},t)}),_>0&&e($n,{content:"More tools",direction:"bottom",children:e("button",{type:"button",ref:W,"aria-label":"More tools",className:`size-10 lexical-btn ${A?"toolbarActive":"toolbar"} icon`,onClick:()=>R(e=>!e),children:e(mt,{})})})]}),ce&&e("div",{ref:U,className:"lte-custom-scrollbar",onPointerDown:pe,"aria-hidden":"true",children:e("div",{ref:B,className:"lte-custom-scrollbar-thumb",onPointerDown:he})}),C&&e(En,{linkUrl:ie,setLinkUrl:le,removeLink:ve,onConfirm:e=>{v.dispatchCommand(Ft,{url:e,target:"_blank"}),le(e),k(!1)},onCancel:()=>{le(""),k(!1)}}),A&&e(Rn,{anchorRef:W,onClose:()=>R(!1),children:co.map(({id:e})=>e).filter(e=>Ce(e)&&Ne[e]).map(t=>e("div",{className:"lte-overflow-item",children:Ne[t]},t))}),N&&e(An,{onClose:()=>S(!1)})]})};function ho(e,t){const n=ie(t)?t.body.childNodes:t.childNodes;let o=[];const i=[];for(const t of n)if(!go.has(t.nodeName)){const n=fo(t,e,i,!1);null!==n&&(o=o.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof le&&t.insertAfter(re());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(i),o}function po(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=H().getChildren();for(let i=0;i<o.length;i++)mo(e,o[i],n,t);return n.innerHTML}function mo(e,t,n,o=null){let i=null===o||t.isSelected(o);const l=L(t)&&t.excludeFromCopy("html");let r=t;if(null!==o){let e=ae(t);e=D(e)&&null!==o?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!F(t)&&null!==n){const[o,i]=n,l=e.isBackward(),r=o.getNode(),a=i.getNode(),c=t.is(r),s=t.is(a);if(c||s){const[n,o]=z(e),i=r.is(a),c=t.is(l?a:r),s=t.is(l?r:a);let d,u=0;i?(u=n>o?o:n,d=n>o?n:o):c?(u=l?o:n,d=void 0):s&&(u=0,d=l?n:o),t.__text=t.__text.slice(u,d)}}return t}(o,e):e,r=e}const a=L(r)?r.getChildren():[],c=ce(e,r.getType());let s;s=c&&void 0!==c.exportDOM?c.exportDOM(e,r):r.exportDOM(e);const{element:d,after:u}=s;if(!d)return!1;const h=document.createDocumentFragment();for(let n=0;n<a.length;n++){const l=a[n],r=mo(e,l,h,o);!i&&L(t)&&r&&t.extractWithChild(l,o,"html")&&(i=!0)}if(i&&!l){if((se(d)||de(d))&&d.append(h),n.append(d),u){const e=u.call(r,d);e&&(de(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(h);return i}const go=new Set(["STYLE","SCRIPT"]);function fo(e,t,n,o,i=new Map,l){let r=[];if(go.has(e.nodeName))return r;let a=null;const c=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),s=c?c(e):null;let d=null;if(null!==s){d=s.after;const t=s.node;if(a=Array.isArray(t)?t[t.length-1]:t,null!==a){for(const[,e]of i)if(a=e(a,l),!a)break;a&&r.push(...Array.isArray(t)?t:[a])}null!=s.forChild&&i.set(e.nodeName,s.forChild)}const u=e.childNodes;let h=[];const p=(null==a||!A(a))&&(null!=a&&ue(a)||o);for(let e=0;e<u.length;e++)h.push(...fo(u[e],t,n,p,new Map(i),a));return null!=d&&(h=d(h)),he(e)&&(h=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(ue(r))o&&!r.getFormat()&&r.setFormat(o),i.push(r);else if(l.push(r),e===t.length-1||e<t.length-1&&ue(t[e+1])){const e=n();e.setFormat(o),e.append(...l),i.push(e),l=[]}}return i}(e,h,p?()=>{const e=new le;return n.push(e),e}:P)),null==a?h.length>0?r=r.concat(h):he(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(pe(e.nextSibling)&&pe(e.previousSibling))}(e)&&(r=r.concat(re())):L(a)&&a.append(...h),r}function bo({value:t,onChange:n}){const[o]=Dt(),[i,l]=c(!0);return r(()=>{t&&i&&(l(!1),o.update(()=>{if(po(o)!==t){H().clear();const e=(new DOMParser).parseFromString(t,"text/html"),n=ho(o,e);Y(n)}}))},[o,t,i]),r(()=>{l(!0)},[t]),e(Qt,{onChange:e=>{e.read(()=>{n(po(o))})}})}function yo({applyRef:n,onExit:o}){const[i]=Dt(),[a,s]=c(()=>i.getEditorState().read(()=>po(i))),d=l(a),u=e=>{e!==d.current&&(i.update(()=>{const t=H();if(t.clear(),t.selectEnd(),e){const t=(new DOMParser).parseFromString(e,"text/html"),n=ho(i,t);n.length>0&&Y(n)}}),d.current=e)};return r(()=>(n.current=()=>{u(a),o()},()=>{n.current=null}),[n,a,o,i]),t("div",{className:"lexical-source-view",children:[e("textarea",{className:"lexical-source-textarea",value:a,onChange:e=>s(e.target.value),"aria-label":"HTML source",spellCheck:!1}),t("div",{className:"lexical-source-actions",children:[e($n,{content:"Apply HTML to the editor",direction:"top",children:t("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>u(a),children:[e(Ut,{size:16}),e("span",{className:"label",children:"Update"})]})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{u(a),o()},children:"Done"})]})]})}function vo({showWordCount:n=!0,showCharCount:o=!0,rightSlot:i}){const[l]=Dt(),[a,s]=c({words:0,chars:0});return r(()=>{const e=e=>{e.read(()=>{const e=H().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]),t("div",{className:"lexical-status-bar",children:[n&&t("span",{children:[a.words," words"]}),o&&t("span",{children:[a.chars," characters"]}),i&&e("div",{className:"lexical-status-bar-right",children:i})]})}function xo({theme:n,toolbarStyle:o,onThemeChange:i,onToolbarStyleChange:l}){const r="normal"===o?"collapse":o,a=[{value:"light",label:"Light theme",icon:e(gt,{})},{value:"dark",label:"Dark theme",icon:e(ft,{})},{value:"system",label:"Follow system theme",icon:e($t,{})}],c=[{value:"wrap",label:"Toolbar: wrap to new lines",icon:e(Pt,{})},{value:"collapse",label:'Toolbar: collapse into "..."',icon:e(mt,{})},{value:"scrollbar",label:"Toolbar: scroll in one row",icon:e(Je,{})}];return t("div",{className:"lexical-display-controls",role:"group","aria-label":"Display settings",children:[e("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Theme",children:a.map(t=>e($n,{content:t.label,direction:"top",children:e("button",{type:"button",role:"radio","aria-checked":n===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(n===t.value?"active":""),onClick:()=>i?.(t.value),children:t.icon})},t.value))}),e("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Toolbar style",children:c.map(t=>e($n,{content:t.label,direction:"top",children:e("button",{type:"button",role:"radio","aria-checked":r===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(r===t.value?"active":""),onClick:()=>l?.(t.value),children:t.icon})},t.value))})]})}const wo=({id:e})=>new Lo({id:e}),Co="data-lexical-youtube",ko="315px",No="560px",So=e=>`https://www.youtube-nocookie.com/embed/${e}`,_o=e=>{const t=e?.getAttribute(Co);if(!t)return null;return{node:wo({id:t})}};class Lo extends j{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new Lo({id:e.__id,key:e.getKey()})}static importJSON(e){return wo({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:ko,width:No,src:So(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Co,this.__id),e.setAttribute("height",ko),e.setAttribute("width",No),e.setAttribute("src",So(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:_o,priority:0})}}}class To extends me{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new To(e.__text,e.__key)}static importDOM(){const e=me.importDOM();return{...e,span:()=>({conversion:Eo(e?.span),priority:1}),div:()=>({conversion:Eo(e?.div),priority:1}),p:()=>({conversion:Eo(e?.p),priority:1}),b:()=>({conversion:Eo(e?.b),priority:1}),strong:()=>({conversion:Eo(e?.strong),priority:1}),i:()=>({conversion:Eo(e?.i),priority:1}),em:()=>({conversion:Eo(e?.em),priority:1}),u:()=>({conversion:Eo(e?.u),priority:1}),s:()=>({conversion:Eo(e?.s),priority:1}),strike:()=>({conversion:Eo(e?.strike),priority:1}),code:()=>({conversion:Eo(e?.code),priority:1})}}static importJSON(e){return function(e=""){return q(new To(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Eo(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(i)&&l.length>0){const e=l.join("; ");return i.setStyle(e)}return i}}}}const Ao={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"}},Ro=i.memo(function({name:n,value:i,onChange:a,placeholder:s,maxWidth:u=null,height:h=null,onImageUpload:p,showWordCount:m=!0,showCharCount:b=!0,theme:y="system",toolbarStyle:N="collapse",showDisplayControls:S=!0,onThemeChange:_,onToolbarStyleChange:L}){const[T,E]=c(!1),[A,R]=c(!1),M=l(null),[D,F]=c(!1),[z,W]=c(y),[O,I]=c("normal"===N?"collapse":N);r(()=>{W(y)},[y]),r(()=>{I("normal"===N?"collapse":N)},[N]),r(()=>{if("system"!==z||"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))},[z]);const H="dark"===z||"system"===z&&D;r(()=>{if(!A)return;const e=e=>{"Escape"===e.key&&R(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[A]);const U=d(()=>({namespace:n,theme:Ao,onError:e=>{console.error("Lexical error:",e)},nodes:[To,{replace:me,with:e=>new To(e.__text),withKlass:To},g,v,x,xe,Ce,f,Wt,jn,Lo,io,Ne,ze,We,Oe]}),[n]);return e("div",{className:`lexical-text-editor lexical-editor-container ${A?"lexical-fullscreen":""} ${H?"lexical-dark":""}`,style:{maxWidth:A?"none":u||"1090px"},children:t(o,{initialConfig:U,children:[e("div",{className:"lexical-toolbar-container",children:e(uo,{value:i,onImageUpload:p,sourceView:T,onToggleSourceView:()=>{E(e=>!e||(M.current?.(),!1))},fullscreen:A,onToggleFullscreen:()=>{R(e=>!e)},toolbarStyle:O})}),e("div",{className:"lexical-editor-inner",style:T?{display:"none"}:void 0,children:e(w,{contentEditable:e(C,{className:"lexical-content-editable",style:{height:h||"500px"}}),placeholder:e("div",{className:"lexical-placeholder",children:s||"Some Text"}),ErrorBoundary:k})}),T&&e(yo,{applyRef:M,onExit:()=>E(!1)}),(m||b||S)&&e(vo,{showWordCount:m,showCharCount:b,rightSlot:S?e(xo,{theme:z,toolbarStyle:O,onThemeChange:e=>{W(e),_?.(e)},onToolbarStyleChange:e=>{I(e),L?.(e)}}):void 0}),e(ge,{}),e(fe,{}),e(_e,{}),e(Se,{}),e(qt,{}),e(bo,{value:i,onChange:a})]})})});export{Ro as LexicalTextEditor};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{LexicalComposer as o}from"@lexical/react/LexicalComposer";import i,{useRef as l,useEffect as r,cloneElement as a,useState as c,useCallback as s,useMemo as d}from"react";import{$isHeadingNode as u,$isQuoteNode as h,$createQuoteNode as p,$createHeadingNode as m,HeadingNode as g,QuoteNode as b}from"@lexical/rich-text";import{$isCodeNode as f,$createCodeNode as y,CodeHighlightNode as v,CodeNode as x}from"@lexical/code";import{RichTextPlugin as w}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as C}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as k}from"@lexical/react/LexicalErrorBoundary";import{$createRangeSelection as N,$findMatchingParent as S,INTERNAL_$isBlock as _,$isElementNode as L,$getSelection as T,$setSelection as E,$isRootOrShadowRoot as A,$hasAncestor as M,$isRangeSelection as R,$isTextNode as D,$isTokenOrSegmented as z,$getCharacterOffsets as F,$isLeafNode as W,$getPreviousSelection as O,$caretRangeFromSelection as I,$getRoot as H,$getNodeByKey as U,SELECTION_CHANGE_COMMAND as $,$createParagraphNode as P,KEY_TAB_COMMAND as K,OUTDENT_CONTENT_COMMAND as B,INDENT_CONTENT_COMMAND as J,COMMAND_PRIORITY_EDITOR as q,DecoratorNode as V,$applyNodeReplacement as j,PASTE_COMMAND as Q,COMMAND_PRIORITY_LOW as X,$insertNodes as Y,CAN_REDO_COMMAND as G,CAN_UNDO_COMMAND as Z,REDO_COMMAND as ee,UNDO_COMMAND as te,FORMAT_ELEMENT_COMMAND as ne,FORMAT_TEXT_COMMAND as oe,isDOMDocumentNode as ie,ArtificialNode__DO_NOT_USE as le,$createLineBreakNode as re,$cloneWithProperties as ae,getRegisteredNode as ce,isHTMLElement as se,isDocumentFragment as de,$isBlockElementNode as ue,isBlockDomNode as he,isInlineDomNode as pe,TextNode as me}from"lexical";import{HistoryPlugin as ge}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as be}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as fe,INSERT_ORDERED_LIST_COMMAND as ye,INSERT_UNORDERED_LIST_COMMAND as ve,ListNode as xe,$isListNode as we,ListItemNode as Ce}from"@lexical/list";import{INSERT_HORIZONTAL_RULE_COMMAND as ke,HorizontalRuleNode as Ne}from"@lexical/react/LexicalHorizontalRuleNode";import{HorizontalRulePlugin as Se}from"@lexical/react/LexicalHorizontalRulePlugin";import{TablePlugin as _e}from"@lexical/react/LexicalTablePlugin";import{$findCellNode as Le,INSERT_TABLE_COMMAND as Te,$isTableCellNode as Ee,TableCellHeaderStates as Ae,$insertTableRowAtSelection as Me,$deleteTableRowAtSelection as Re,$insertTableColumnAtSelection as De,$deleteTableColumnAtSelection as ze,TableNode as Fe,TableRowNode as We,TableCellNode as Oe}from"@lexical/table";import{RxLetterCaseLowercase as Ie,RxLetterCaseUppercase as He,RxLetterCaseCapitalize as Ue}from"react-icons/rx";import{TbBold as $e,TbItalic as Pe,TbUnderline as Ke,TbSeparatorHorizontal as Be,TbArrowsLeftRight as Je}from"react-icons/tb";import{BsSuperscript as qe,BsSubscript as Ve,BsChatSquareQuote as je,BsArrowCounterclockwise as Qe,BsArrowClockwise as Xe,BsJustifyLeft as Ye,BsTextCenter as Ge,BsJustifyRight as Ze,BsJustify as et,BsTextParagraph as tt,BsTypeH1 as nt,BsTypeH2 as ot,BsTypeH3 as it,BsTypeH4 as lt,BsTypeH5 as rt,BsTypeH6 as at,BsPencilSquare as ct,BsListOl as st,BsListUl as dt,BsTable as ut,BsFullscreenExit as ht,BsFullscreen as pt,BsThreeDots as mt,BsSun as gt,BsMoon as bt}from"react-icons/bs";import{AiOutlineStrikethrough as ft,AiOutlineFontColors as yt,AiOutlineBgColors as vt}from"react-icons/ai";import{IoCodeSlashOutline as xt,IoChevronUp as wt,IoChevronDown as Ct,IoClose as kt,IoImageOutline as Nt,IoSearchOutline as St,IoCodeOutline as _t}from"react-icons/io5";import{PiHighlighterLight as Lt}from"react-icons/pi";import{RiEraserLine as Tt,RiIndentIncrease as Et,RiIndentDecrease as At,RiFontFamily as Mt}from"react-icons/ri";import{useLexicalComposerContext as Rt}from"@lexical/react/LexicalComposerContext";import{TOGGLE_LINK_COMMAND as Dt,$isLinkNode as zt,LinkNode as Ft}from"@lexical/link";import{HiChevronDown as Wt}from"react-icons/hi2";import{createPortal as Ot}from"react-dom";import{IoIosLink as It}from"react-icons/io";import{MdCheck as Ht,MdMonitor as Ut,MdWrapText as $t}from"react-icons/md";import{BiUnlink as Pt}from"react-icons/bi";import{SketchPicker as Kt}from"react-color";import{LuMinus as Bt,LuPlus as Jt,LuUpload as qt}from"react-icons/lu";import{FaYoutube as Vt}from"react-icons/fa";import{VscPreview as jt}from"react-icons/vsc";import{LinkPlugin as Qt}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as Xt}from"@lexical/react/LexicalOnChangePlugin";var Yt,Gt;!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"}(Yt||(Yt={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(Gt||(Gt={}));const Zt=[{id:Yt.Lowercase,icon:e(Ie,{}),label:"Lowercase"},{id:Yt.Uppercase,icon:e(He,{}),label:"Uppercase"},{id:Yt.Capitalize,icon:e(Ue,{}),label:"Capitalize"},{id:Yt.Superscript,icon:e(qe,{}),label:"Superscript"},{id:Yt.Subscript,icon:e(Ve,{}),label:"Subscript"}],en=[{id:Yt.Bold,icon:e($e,{}),label:"Bold"},{id:Yt.Italics,icon:e(Pe,{}),label:"Italics"},{id:Yt.Underline,icon:e(Ke,{}),label:"Underline"},{id:Yt.Strikethrough,icon:e(ft,{}),label:"Strikethrough"}],tn=[{id:Yt.Highlight,icon:e(Lt,{}),label:"Highlight"}],nn=[{id:Yt.Quote,icon:e(je,{}),label:"Quote"},{id:Yt.Code,icon:e(xt,{}),label:"Code"}],on=[{id:Yt.Undo,icon:e(Qe,{}),label:"Undo"},{id:Yt.Redo,icon:e(Xe,{}),label:"Redo"},{id:Yt.ClearFormatting,icon:e(Tt,{}),label:"Clear Formatting"}],ln=[{id:Yt.Indent,icon:e(Et,{}),label:"Indent"},{id:Yt.Outdent,icon:e(At,{}),label:"Outdent"}],rn=[{id:Yt.HorizontalRule,icon:e(Be,{}),label:"Horizontal Rule"}],an=[{id:Yt.LeftAlign,icon:e(Ye,{}),label:"Left Align"},{id:Yt.CenterAlign,icon:e(Ge,{}),label:"Center Align"},{id:Yt.RightAlign,icon:e(Ze,{}),label:"Right Align"},{id:Yt.JustifyAlign,icon:e(et,{}),label:"Justify Align"}],cn=[{id:"normal",label:"Normal",icon:e(tt,{})},{id:"h1",label:"Heading 1",icon:e(nt,{})},{id:"h2",label:"Heading 2",icon:e(ot,{})},{id:"h3",label:"Heading 3",icon:e(it,{})},{id:"h4",label:"Heading 4",icon:e(lt,{})},{id:"h5",label:"Heading 5",icon:e(rt,{})},{id:"h6",label:"Heading 6",icon:e(at,{})}],sn=[{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 dn(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 un=new Map;function hn(e){let t=un.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),un.set(e,t)),t}function pn(e,t){(R(e)?e.isCollapsed():D(e)||L(e))||dn(280);const n=hn(R(e)?e.style:D(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);R(e)||D(e)?e.setStyle(i):e.setTextStyle(i),un.set(i,o)}function mn(e,t){if(R(e)&&e.isCollapsed()){pn(e,t);const n=e.anchor.getNode();L(n)&&n.isEmpty()&&pn(n,t)}!function(e){const t=T();if(!t)return;const n=new Map,o=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(R(t))for(const e of I(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const i=t.getNodes();for(const t of i){if(!D(t)||!t.canHaveFormat())continue;const[n,i]=o(t);i!==n&&(z(t)||0===n&&i===t.getTextContentSize()?e(t):e(t.splitText(n,i)[0===n?0:1]))}R(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=>{pn(e,t)})}function gn(e,t){const n=e.getFormatType(),o=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),o!==t.getIndent()&&t.setIndent(o)}function bn(e,t,n=gn){if(null===e)return;const o=e.getStartEndPoints(),i=new Map;let l=null;if(o){const[e,t]=o;l=N(),l.anchor.set(e.key,e.offset,e.type),l.focus.set(t.key,t.offset,t.type);const n=S(e.getNode(),_),r=S(t.getNode(),_);L(n)&&i.set(n.getKey(),n),L(r)&&i.set(r.getKey(),r)}for(const t of e.getNodes())if(L(t)&&_(t))i.set(t.getKey(),t);else if(null===o){const e=S(t,_);L(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(T())&&E(l)}function fn(e){return e.getNode().isAttached()}function yn(e){let t=e;for(;null!==t&&!A(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function vn(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 a=null,c=[];for(let o=0;o<r;o++){const i=l[o];A(i)?(xn(e,c,c.length,t,n),c=[],a=i):null===a||null!==a&&M(i,a)?c.push(i):(xn(e,c,c.length,t,n),c=[i])}xn(e,c,c.length,t,n)}function xn(e,t,n,o,i=null){if(0===t.length)return;const l=t[0],r=new Map,a=[];let c=L(l)?l:l.getParentOrThrow();c.isInline()&&(c=c.getParentOrThrow());let s=!1;for(;null!==c;){const e=c.getPreviousSibling();if(null!==e){c=e,s=!0;break}if(c=c.getParentOrThrow(),A(c))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];L(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const u=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&&W(n)&&!u.has(n.getKey())){const e=i.getKey();if(void 0===r.get(e)){const t=o();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),a.push(t),r.set(e,t),i.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),L(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),yn(i)}}else if(d.has(n.getKey())){L(n)||dn(179);const e=o();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),a.push(e),n.remove(!0)}}if(null!==i)for(let e=0;e<a.length;e++){const t=a[e];i.append(t)}let h=null;if(A(c))if(s)if(null!==i)c.insertAfter(i);else for(let e=a.length-1;e>=0;e--){const t=a[e];c.insertAfter(t)}else{const e=c.getFirstChild();if(L(e)&&(c=e),null===e)if(i)c.append(i);else for(let e=0;e<a.length;e++){const t=a[e];c.append(t),h=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<a.length;t++){const n=a[t];e.insertBefore(n),h=n}}else if(i)c.insertAfter(i);else for(let e=a.length-1;e>=0;e--){const t=a[e];c.insertAfter(t),h=t}const p=O();R(p)&&fn(p.anchor)&&fn(p.focus)?E(p.clone()):null!==h?h.selectEnd():e.dirty=!0}function wn(e,t,n){const o=hn(e.getStyle());return null!==o&&o[t]||n}function Cn(e,t,n=""){let o=null;const i=e.getNodes(),l=e.anchor,r=e.focus,a=e.isBackward(),c=a?r.offset:l.offset,s=a?r.getNode():l.getNode();if(R(e)&&e.isCollapsed()&&""!==e.style){const n=hn(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!==c||!l.is(s))&&D(l)){const e=wn(l,t,n);if(null===o)o=e;else if(o!==e){o="";break}}}return null===o?n:o}const kn="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Nn=kn&&"documentMode"in document?document.documentMode:null;function Sn(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function _n(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function Ln({open:t,onOpenChange:n,children:o}){const c=l(null),s=l(null);return r(()=>{function e(e){c.current?.contains(e.target)||s.current?.contains(e.target)||n(!1)}return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,n]),e("div",{className:"popover-root",children:i.Children.map(o,e=>e&&"object"==typeof e?e.type===Tn?a(e,{triggerRef:c}):e.type===En?a(e,{contentRef:s,triggerRef:c}):e:e)})}function Tn({children:t,triggerRef:n}){return e("div",{className:"popover-trigger",ref:n,children:t})}function En({open:t,align:n="start",children:o,contentRef:a,triggerRef:c}){const s=l(null),[d,u]=i.useState(!1);return r(()=>{if(!t)return;const e=()=>{const e=s.current,t=c?.current;if(!e||!t)return;const o=t.closest(".lexical-text-editor"),i=!!o?.classList.contains("lexical-dark");e.classList.contains("lexical-dark")!==i&&e.classList.toggle("lexical-dark",i);const l=t.getBoundingClientRect(),r=e.offsetWidth,a=e.offsetHeight;let d=l.left;"center"===n?d=l.left+l.width/2-r/2:"end"===n&&(d=l.right-r),d=Math.max(8,Math.min(window.innerWidth-r-8,d));let h=l.bottom+4;h+a>window.innerHeight-8&&l.top>a+8&&(h=l.top-a-4),e.style.left=`${d}px`,e.style.top=`${h}px`,u(i)};return e(),requestAnimationFrame(e),window.addEventListener("resize",e),document.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),document.removeEventListener("scroll",e,!0)}},[t,n,c]),t?Ot(e("div",{ref:s,className:"lexical-text-editor"+(d?" 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:e("div",{ref:e=>{a.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 An({onAction:n,selectionMap:o}){const[i,r]=c(!1),a=l(null),s=l(null);return t(Ln,{open:i,onOpenChange:r,children:[e(Tn,{triggerRef:a,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[e("span",{children:"Aa"}),e(Wt,{className:"chevron "+(i?"rotated":"")})]})}),e(En,{open:i,align:"start",onClose:()=>r(!1),contentRef:s,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:Zt.map(({id:i,label:l,icon:a})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),r(!1)},style:{minWidth:130},children:[a,e("span",{className:"label",children:l})]},i))})})]})}function Mn(){return e("div",{className:"lexical-separator"})}function Rn({updateHeading:n,headingSelectionMap:o}){const i=cn.find(e=>o[e.id]),[r,a]=c(!1),s=l(null),d=l(null);return t(Ln,{open:r,onOpenChange:a,children:[e(Tn,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>a(e=>!e),style:{minWidth:132},children:[i?.icon,e("span",{children:i?.label}),e(Wt,{className:"chevron "+(r?"rotated":"")})]})}),e(En,{open:r,align:"start",onClose:()=>a(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:cn.map(({id:i,label:l,icon:r})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),a(!1)},children:[r,e("span",{className:"label",children:l})]},i))})})]})}function Dn({linkUrl:n,setLinkUrl:o,onConfirm:i,onCancel:a,removeLink:s}){const[d,u]=c(!1),h=l(null),p=l(null);return r(()=>{"https://"===n&&u(!0)},[n]),r(()=>{d&&p.current?.focus()},[d]),r(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&a()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]),t("div",{ref:h,className:"lexical-text-editor-link link-editor-container",children:[e("div",{className:"link-editor-input-wrapper",children:d?e("input",{ref:p,className:"link-editor-input",value:n,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),i(n),u(!1)):"Escape"===e.key&&(e.preventDefault(),u(!1),a())}}):e("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:n})}),t("div",{className:"link-editor-buttons",children:[e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{d?(i(n),u(!1)):u(!0)},children:d?e(Ht,{size:18}):e(ct,{size:14})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:e(Pt,{size:14,style:{stroke:"black"}})})]})]})}function zn({onClose:n}){const[o]=Rt(),[i,a]=c(""),[s,d]=c(""),[u,h]=c(!1),[p,m]=c([]),[g,b]=c(0),f=l(null);r(()=>{f.current?.focus()},[]);const y=()=>{if(!i)return[];const e=u?i:i.toLowerCase(),t=[],n=H().getAllTextNodes();for(const o of n){const n=u?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};r(()=>{const e=o.getEditorState().read(y);m(e),b(0)},[o,i,u]),r(()=>o.registerUpdateListener(({editorState:e})=>{const t=e.read(y);m(t),b(e=>0===t.length?0:Math.min(e,t.length-1))}),[o,i,u]);const v=e=>{if(0===p.length)return;const t=(g+e+p.length)%p.length,n=p[t];b(t),o.update(()=>{const e=U(n.key);D(e)&&e.select(n.start,n.start+i.length)}),requestAnimationFrame(()=>{const e=o.getElementByKey(n.key);e?.scrollIntoView({block:"nearest"})})},x=i.length>0,w=p.length>0;return t("div",{className:"lexical-find-replace",onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),n())},children:[t("div",{className:"lexical-fr-row",children:[e("input",{ref:f,className:"lexical-fr-input",placeholder:"Find",value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v(e.shiftKey?-1:1))}}),e("span",{className:"lexical-fr-count",children:w?`${g+1} of ${p.length}`:x?"0 results":""})]}),e("div",{className:"lexical-fr-row",children:e("input",{className:"lexical-fr-input",placeholder:"Replace with",value:s,onChange:e=>d(e.target.value)})}),t("div",{className:"lexical-fr-row",children:[t("label",{className:"lexical-fr-case",children:[e("input",{type:"checkbox",checked:u,onChange:e=>h(e.target.checked)}),e("span",{children:"Match case"})]}),e("span",{style:{flex:1}}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>v(-1),disabled:!w,"aria-label":"Previous match",children:e(wt,{})}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>v(1),disabled:!w,"aria-label":"Next match",children:e(Ct,{})}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{o.update(()=>{const e=y();if(0===e.length)return m([]),void b(0);const t=e[Math.min(g,e.length-1)],n=U(t.key);D(n)&&n.spliceText(t.start,i.length,s,!0)})},disabled:!w,children:"Replace"}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:()=>{o.update(()=>{const e=y();for(let t=e.length-1;t>=0;t--){const n=e[t],o=U(n.key);D(o)&&o.spliceText(n.start,i.length,s,!1)}})},disabled:!w,children:"Replace All"}),e("button",{type:"button",className:"lexical-btn toolbar",onClick:n,"aria-label":"Close find and replace",children:e(kt,{})})]})]})}function Fn({anchorRef:t,onClose:n,children:o}){const i=l(null);return r(()=>{const e=e=>{const o=e.target;o instanceof HTMLElement&&o.closest("[data-lte-popover-portal]")||!i.current||i.current.contains(o)||t.current&&t.current.contains(o)||n()},o=e=>{"Escape"===e.key&&n()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",o)}},[t,n]),e("div",{ref:i,className:"lte-overflow-panel",onMouseDown:e=>e.preventDefault(),children:e("div",{className:"lte-overflow-grid",children:o})})}function Wn({onAction:n,alignmentSelectionMap:o}){const i=an.find(e=>o[e.id]),[r,a]=c(!1),s=l(null),d=l(null);return t(Ln,{open:r,onOpenChange:a,children:[e(Tn,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>a(e=>!e),style:{minWidth:146},children:[i?.icon,e("span",{children:i?.label}),e(Wt,{className:"chevron "+(r?"rotated":"")})]})}),e(En,{open:r,align:"start",onClose:()=>a(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:an.map(({id:i,label:l,icon:r})=>t("button",{type:"button",className:"lexical-btn "+(o[i]?"toolbar-active":"toolbar"),onClick:()=>{n(i),a(!1)},children:[r,e("span",{className:"label",children:l})]},i))})})]})}function On({color:n,onChange:o,icon:i}){const[a,s]=c(!1),d=l(null),u=l(null);r(()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return t("div",{className:"color-picker-wrapper",children:[e("button",{type:"button",ref:d,className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:i}),a&&Ot(e("div",{ref:u,className:"lexical-color-popover "+(a?"open":""),"data-lte-popover-portal":"true",style:{top:d.current?.getBoundingClientRect().bottom,left:d.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>{e.preventDefault(),(e=>{e.preventDefault()})(e)},children:e(Kt,{color:n,onChangeComplete:e=>{o(e.hex)}})}),document.body)]})}function In(){const[o]=Rt(),[{color:i,bgColor:l},a]=c({color:"#000",bgColor:"#fff"}),s=()=>{const e=T();if(R(e)){const t=Cn(e,"color","#000"),n=Cn(e,"background","#fff");a({color:t,bgColor:n})}};r(()=>Sn(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),o.registerCommand($,()=>(s(),!1),1)),[o]);const d=({property:e,color:t})=>{o.update(()=>{const n=T();n&&mn(n,{[e]:t})})};return t(n,{children:[e(On,{color:i,onChange:e=>{d({property:"color",color:e})},icon:e(yt,{})}),e(On,{color:l,onChange:e=>{d({property:"background",color:e})},icon:e(vt,{})})]})}function Hn({icon:n,tooltipLabel:o,currentValue:i,options:r,onSelect:a,minWidth:s=132}){const d=r.find(e=>""!==e.id&&e.id===i),[u,h]=c(!1),p=l(null),m=l(null);return t(Ln,{open:u,onOpenChange:h,children:[e(Tn,{triggerRef:p,children:t("button",{type:"button","aria-label":o,className:"lexical-btn heading-trigger font-trigger "+(u?"toolbar-active":"toolbar"),style:{minWidth:s},onClick:()=>h(e=>!e),children:[n,e("span",{children:d?.label??"Default"}),e(Wt,{className:"chevron "+(u?"rotated":"")})]})}),e(En,{open:u,align:"start",onClose:()=>h(!1),contentRef:m,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:r.map(t=>e("button",{type:"button",className:"lexical-btn "+(""===t.id&&""===i||""!==t.id&&t.id===i?"toolbar-active":"toolbar"),onClick:()=>{a(t.id),h(!1)},children:e("span",{className:"label",children:t.label})},t.label))})})]})}kn&&"InputEvent"in window&&!Nn&&new window.InputEvent("input");const Un=[{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 $n(){const[t]=Rt(),[n,o]=c(""),i=()=>{const e=T();if(R(e)){const t=Cn(e,"font-family","");o((e=>e.replace(/['"]/g,"").trim())(t))}};r(()=>Sn(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{i()})}),t.registerCommand($,()=>(i(),!1),1)),[t]);return e(Hn,{icon:e(Mt,{}),tooltipLabel:"Font Family",currentValue:n,options:Un,onSelect:e=>{t.update(()=>{const t=T();R(t)&&mn(t,{"font-family":""===e?null:e})})}})}const Pn=({content:n,direction:o="top",delay:i=400,children:r})=>{const[a,s]=c(!1),[d,u]=c(null),h=l(null),p=l(null),m=()=>{h.current=window.setTimeout(()=>{const e=p.current;if(e){const t=e.getBoundingClientRect();u({left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height})}s(!0)},i)},g=()=>{h.current&&clearTimeout(h.current),s(!1)};if(!d)return e("div",{ref:p,className:"Lexical-Tooltip-Wrapper",onMouseEnter:m,onMouseLeave:g,children:r});const b=d.left+d.width/2,f=d.top+d.height/2,y="bottom"===o?{top:d.bottom+10,left:b,bottom:"auto"}:"top"===o?{bottom:window.innerHeight-d.top+10,top:"auto",left:b}:"right"===o?{left:d.right+10,right:"auto",top:f}:{left:"auto",right:window.innerWidth-d.left+10,top:f};return t("div",{ref:p,className:"Lexical-Tooltip-Wrapper",onMouseEnter:m,onMouseLeave:g,children:[r,a&&Ot(e("div",{className:`Lexical-Tooltip-Tip ${o}`,style:{position:"fixed",pointerEvents:"none",...y,zIndex:1e4},children:n}),document.body)]})};function Kn(){const[n]=Rt(),[o,i]=c(""),l=()=>{const e=T();if(R(e)){let t=Bn(Cn(e,"font-size",""));if(!t)try{const o=n.getElementByKey(e.anchor.getNode().getKey());o&&(t=window.getComputedStyle(o).fontSize||"")}catch{}i(Bn(t))}};r(()=>Sn(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{l()})}),n.registerCommand($,()=>(l(),!1),1)),[n]);const a=e=>{const t=Number.parseInt(o,10);(e=>{const t=Math.min(90,Math.max(6,e));n.update(()=>{const e=T();R(e)&&mn(e,{"font-size":`${t}px`})})})((Number.isNaN(t)?16:t)+e)},s=Number.parseInt(o,10),d=Number.isNaN(s)?null:s;return t("div",{className:"lexical-stepper","aria-label":"Font Size",role:"group",children:[e(Pn,{content:"Decrease font size",direction:"bottom",children:e("button",{type:"button","aria-label":"Decrease Font Size",className:"lexical-stepper-btn",disabled:null!==d&&d<=6,onClick:()=>a(-1),children:e(Bt,{})})}),e("span",{className:"lexical-stepper-value",children:d??"—"}),e(Pn,{content:"Increase font size",direction:"bottom",children:e("button",{type:"button","aria-label":"Increase Font Size",className:"lexical-stepper-btn",disabled:null!==d&&d>=90,onClick:()=>a(1),children:e(Jt,{})})})]})}const Bn=e=>e.trim();function Jn(){const[n]=Rt(),[o,i]=c(!1),[a,s]=c(null),[d,u]=c(!1),h=l(null),p=l(null),m=()=>{const e=T();if(R(e)){const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow(),o=f(n);i(o),o&&s(n.getLanguage()??null)}};r(()=>Sn(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{m()})}),n.registerCommand($,()=>(m(),!1),1)),[n]);const g=sn.find(e=>e.id===a)?.label??"Plain Text";return t(Ln,{open:d,onOpenChange:u,children:[e(Tn,{triggerRef:h,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>u(e=>!e),children:[e(xt,{}),e("span",{children:g}),e(Wt,{className:"chevron "+(d?"rotated":"")})]})}),e(En,{open:d,align:"start",onClose:()=>u(!1),contentRef:p,children:t("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[t("button",{type:"button",className:"lexical-btn "+(o?"toolbar-active":"toolbar"),onClick:()=>{n.update(()=>{const e=T();if(!R(e))return;const t=e.anchor.getNode(),n="root"===t.getKey()?t:t.getTopLevelElementOrThrow();if(f(n))bn(e,()=>P());else{const t=a??"javascript";bn(e,()=>y(t))}}),u(!1)},style:{minWidth:150},children:[e(xt,{}),e("span",{className:"label",children:o?"Remove Code Block":"Code Block"})]}),e("div",{className:"w-full h-[1px] bg-gray-200 my-1"}),e("div",{style:{display:"flex",flexDirection:"column",gap:5,maxHeight:260,overflowY:"auto"},children:sn.map(({id:t,label:o})=>e("button",{type:"button",className:"lexical-btn "+(a===t?"toolbar-active":"toolbar"),onClick:()=>{var e;s(e=t),n.update(()=>{const t=T();if(!R(t))return;const n=t.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow();f(o)&&o.setLanguage(e)}),u(!1)},style:{minWidth:150},children:e("span",{className:"label",children:o})},t))})]})})]})}function qn({blockType:o}){const[i]=Rt();r(()=>Sn(i.registerCommand(K,e=>{const t=T();if(!R(t))return!1;return!!_n(t.anchor.getNode(),xe)&&(e.preventDefault(),i.dispatchCommand(e.shiftKey?B:J,void 0),!0)},q)),[i]);return t(n,{children:[e(Pn,{content:"Ordered list",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${"ol"===o?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===o?i.dispatchCommand(fe,void 0):i.dispatchCommand(ye,void 0)},children:e(st,{})})}),e(Pn,{content:"Unordered list",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${"ul"===o?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===o?i.dispatchCommand(fe,void 0):i.dispatchCommand(ve,void 0)},children:e(dt,{})})})]})}function Vn(){const[n]=Rt(),[o,i]=c(!1),[a,s]=c(!1),[d,u]=c(null),h=l(null),p=l(null),m=()=>{const e=T();if(R(e)){const t=Le(e.anchor.getNode());i(!!t)}else i(!1)};r(()=>Sn(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{m()})}),n.registerCommand($,()=>(m(),!1),1)),[n]);const g=e=>{n.update(()=>{const t=T();R(t)&&e()}),s(!1)},b=d?`${d.rows} × ${d.cols}`:"Insert Table";return t(Ln,{open:a,onOpenChange:s,children:[e(Tn,{triggerRef:h,children:t("button",{type:"button","aria-label":"Insert Table",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),children:[e(ut,{}),e(Wt,{className:"chevron "+(a?"rotated":"")})]})}),e(En,{open:a,align:"start",onClose:()=>s(!1),contentRef:p,children:t("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t("div",{style:{width:"fit-content"},children:[e("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,r=d&&i<=d.rows&&l<=d.cols;return e("div",{onMouseEnter:()=>u({rows:i,cols:l}),onClick:()=>{return e=i,t=l,n.update(()=>{if(!R(T())){const e=H().getFirstChild();L(e)&&e.select(0,0)}}),n.dispatchCommand(Te,{rows:String(e),columns:String(t),includeHeaders:!1}),void s(!1);var e,t},style:{width:18,height:18,borderRadius:3,border:"1px solid #d1d5db",backgroundColor:r?"#c7d2fe":"#fff",cursor:"pointer"}},o)})}),e("div",{style:{fontSize:12,color:"#6b7280",marginTop:4},children:b})]}),e("div",{className:"w-full h-[1px] bg-gray-200"}),t("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Me(!1)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert row above"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Me(!0)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert row below"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{Re()}),style:{minWidth:160},children:e("span",{className:"label",children:"Delete row"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{De(!1)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert column left"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{De(!0)}),style:{minWidth:160},children:e("span",{className:"label",children:"Insert column right"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>g(()=>{ze()}),style:{minWidth:160},children:e("span",{className:"label",children:"Delete column"})}),e("button",{type:"button",className:"lexical-btn toolbar",disabled:!o,onClick:()=>{g(()=>{const e=T();if(!R(e))return;const t=Le(e.anchor.getNode());if(!t)return;const n=t.getParent();if(!n)return;const o=n.getChildren().filter(Ee),i=o.some(e=>e.hasHeaderState(Ae.ROW));for(const e of o)e.setHeaderStyles(i?Ae.NO_STATUS:Ae.ROW,Ae.ROW)})},style:{minWidth:160},children:e("span",{className:"label",children:"Toggle header row"})})]})]})})]})}const jn=({src:n,altText:o,nodeKey:i,width:r,height:a,maxWidth:s,caption:d=""})=>{const[u]=Rt(),[h,p]=c(!1),[m,g]=c(d),b=l(null),f=l(null),y=l(null),v=l(null),x=e=>{if(!v.current||!f.current)return;const t=e.clientX-v.current.x,n=Math.min(s,Math.max(50,v.current.width+t)),o=n*f.current.ratio;f.current.width=n,f.current.height=o;const i=y.current?.querySelector("img");i&&(i.style.width=n+"px",i.style.height=o+"px")},w=()=>{if(!f.current)return;const{width:e,height:t}=f.current;u.update(()=>{const n=U(i);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),f.current=null,v.current=null,window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",w)},C=()=>{p(!1),u.update(()=>{const e=U(i);e&&"function"==typeof e.setCaption&&e.setCaption(m)})},k=()=>{g(d),p(!0),setTimeout(()=>b.current?.focus(),0)};return t("div",{ref:y,style:{display:"inline-block",position:"relative",maxWidth:s},children:[e("img",{src:n,alt:o,width:"inherit"===r?void 0:r,height:"inherit"===a?void 0:a,style:{maxWidth:"100%",display:"block"}}),(d||h)&&e("div",{style:{textAlign:"center",marginTop:4},children:h?e("input",{ref:b,className:"lte-input",style:{width:"100%",textAlign:"center"},value:m,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C()}}):e("span",{style:{fontSize:13,color:"#666",cursor:"text",display:"inline-block",minWidth:20,minHeight:18},onClick:k,children:d})}),!d&&!h&&e("div",{style:{textAlign:"center",marginTop:2},children:e("span",{style:{fontSize:12,color:"#999",cursor:"pointer"},onClick:k,children:"+ Add caption"})}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=y.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,o=t.naturalHeight/t.naturalWidth,i=n*o;v.current={x:e.clientX,y:e.clientY,width:n,height:i},f.current={width:n,height:i,ratio:o},window.addEventListener("mousemove",x),window.addEventListener("mouseup",w)},style:{position:"absolute",bottom:d||h?40:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Qn=e=>j(new Yn(e)),Xn=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:Qn({src:t,altText:n,width:o??"inherit",height:i??"inherit"})}};class Yn extends V{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 Yn({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:Xn,priority:1}),figure:()=>({conversion:e=>{const t=e.querySelector("img");if(!t)return null;const n=e.querySelector("figcaption"),o=n?.textContent||"",i=Xn(t);return i?.node instanceof Yn&&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 Yn({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 e(jn,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth,caption:this.__caption})}}function Gn({open:n,onClose:o,forPreview:i=!1,children:a}){const c=l(null);return r(()=>{if(!n)return;const e=e=>{c.current&&!c.current.contains(e.target)&&o()},t=e=>{"Escape"===e.key&&o()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[n,o]),n?e("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:t("div",{ref:c,className:"lte-dialog "+(i?"preview":""),children:[e("button",{type:"button",className:"lte-dialog-close",onClick:o,children:"×"}),a]})}):null}async function Zn(e,{src:t,altText:n="",caption:o=""}){e.update(()=>{const e=Qn({src:t,altText:n,caption:o});Y([e])})}function eo({onImageUpload:n}){const[o]=Rt(),i=l(null),[a,d]=c(!1),[u,h]=c(""),[p,m]=c(""),[g,b]=c(""),[f,y]=c(),[v,x]=c(!1),w=s(async(e,t="",i="")=>{let l;l=n?await n(e):URL.createObjectURL(e),Zn(o,{src:l,altText:t,caption:i})},[o,n]);return r(()=>{const e=o.registerCommand(Q,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&&w(t,"","").catch(console.error),!0}}return!1},X);return()=>e()},[o,w]),t("div",{className:"lexical-text-editor-dialog",children:[e("input",{type:"file",ref:i,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&y(t),e.target.value=""}}),e(Pn,{content:"Add Image",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>d(e=>!e),children:e(Nt,{size:18})})}),t(Gn,{open:a,onClose:()=>d(!1),children:[e("div",{className:"lte-dialog-header",children:"Add Image"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Alt text",value:p,onChange:e=>m(e.target.value)}),e("input",{className:"lte-input",placeholder:"Caption",value:g,onChange:e=>b(e.target.value)}),e("input",{className:"lte-input",placeholder:"Add image by URL",value:u,onChange:e=>h(e.target.value)}),e("div",{className:"lte-divider",children:e("span",{children:"or"})}),t("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>i.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[e(qt,{size:20}),e("span",{children:"Upload Image"})]}),f&&e("div",{className:"lte-file-name",children:f.name})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!u&&!f||v,onClick:async()=>{if(!v){if(f){x(!0);try{await w(f,p,g)}catch(e){return console.error("Image upload failed:",e),void x(!1)}x(!1)}else{if(!u)return;Zn(o,{src:u,altText:p,caption:g})}y(void 0),m(""),b(""),h(""),d(!1)}},children:v?"Uploading...":"Add Image"})})]})]})}const to=({id:e,provider:t})=>new co({id:e,provider:t}),no="data-lexical-video",oo="data-provider",io="315px",lo="560px",ro=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,ao=e=>{const t=e?.getAttribute(no),n=e?.getAttribute(oo)??"youtube";if(!t)return null;return{node:to({id:t,provider:n})}};class co extends V{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new co({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return to({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e("iframe",{height:io,width:lo,src:ro(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(no,this.__id),e.setAttribute(oo,this.__provider),e.setAttribute("height",io),e.setAttribute("width",lo),e.setAttribute("src",ro(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:ao,priority:0})}}}function so(){const[n,o]=c(!1),[i,l]=c(!1),[a,s]=c(""),[d]=Rt();return r(()=>{n||(s(""),l(!1))},[n]),t("div",{className:"lexical-text-editor-dialog",children:[e(Pn,{content:"Embed Video",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>o(!0),children:e(Vt,{size:18,color:"red"})})}),t(Gn,{open:n,onClose:()=>o(!1),children:[e("div",{className:"lte-dialog-header",children:"Embed Video"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:a,onChange:e=>s(e.target.value)}),i&&e("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!a,onClick:()=>{if(!a)return;let e=null,t=null;const n=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(a);n&&11===n[2]?.length&&(e="youtube",t=n[2]);const i=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(a);i&&i[1]&&(e="drive",t=i[1]),t&&e?(d.update(()=>{const n=to({id:t,provider:e});Y([n])}),s(""),l(!1),o(!1)):l(!0)},children:"Embed"})})]})]})}function uo({value:t}){return e("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:t}})}function ho({value:n,triggerLabel:o="Preview"}){const[i,l]=c(!1);return t("div",{className:"lexical-text-editor-dialog",children:[e(Pn,{content:o,direction:"bottom",children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(i?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[e(jt,{size:18}),e("span",{children:o})]})}),t(Gn,{open:i,onClose:()=>l(!1),forPreview:!0,children:[e("div",{className:"lte-dialog-header",children:"Content Preview"}),t("div",{className:"lte-preview-container",children:[e("div",{className:"lte-preview-title",children:"CONTENT"}),e(uo,{value:n})]})]})]})}const po=[{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"}],mo=po.map(e=>e.id),go=({value:o,onImageUpload:i,sourceView:a=!1,onToggleSourceView:d,fullscreen:g=!1,onToggleFullscreen:b,toolbarStyle:f="wrap"})=>{const y="normal"===f?"collapse":f,[v]=Rt(),[x,w]=c({[Yt.Undo]:!0,[Yt.Redo]:!0}),[C,k]=c(!1),[N,S]=c(!1),[_,E]=c(0),[A,M]=c(!1),z=l(null),F=l(null),W=l(null),O=l({}),I=l({}),H=l(0),U=l(null),K=l(null),[q,V]=c({[Yt.LeftAlign]:!0}),[j,Q]=c({[Gt.Normal]:!0}),[X,Y]=c("paragraph"),[ie,le]=c("https://");let re=!0;const ae=()=>{if(re){const e=v.getRootElement();e&&(e.scrollTop=0,re=!1)}const e=T();if(R(e)){const t={[Yt.Bold]:e.hasFormat("bold"),[Yt.Italics]:e.hasFormat("italic"),[Yt.Underline]:e.hasFormat("underline"),[Yt.Uppercase]:e.hasFormat("uppercase"),[Yt.Lowercase]:e.hasFormat("lowercase"),[Yt.Capitalize]:e.hasFormat("capitalize"),[Yt.Strikethrough]:e.hasFormat("strikethrough"),[Yt.Superscript]:e.hasFormat("superscript"),[Yt.Subscript]:e.hasFormat("subscript"),[Yt.Code]:e.hasFormat("code"),[Yt.Highlight]:e.hasFormat("highlight")};V(t);const n=e.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow(),i=o.getKey();if(!v.getElementByKey(i))return;if(we(o)){const e=_n(n,xe),t=e?e.getTag():o.getTag();Y(t)}else if("paragraph"===o.getType()||u(o)){let e=null;u(o)&&(e=o.getTag());const t={[Gt.H1]:"h1"===e,[Gt.H2]:"h2"===e,[Gt.H3]:"h3"===e,[Gt.H4]:"h4"===e,[Gt.H5]:"h5"===e,[Gt.H6]:"h6"===e,[Gt.Normal]:"paragraph"===o.getType()};Y(o.getType()),Q(t)}else Y(o.getType());const l=(L(n)?n:o).getFormat();V(e=>({...e,[Yt.LeftAlign]:0===l||1===l,[Yt.CenterAlign]:2===l,[Yt.RightAlign]:3===l,[Yt.JustifyAlign]:4===l})),"quote"===o.getType()?V(e=>({...e,[Yt.Quote]:!0})):V(e=>({...e,[Yt.Quote]:!1}));const r=e.anchor.getNode(),a=r.getParent();zt(a)?(V(e=>({...e,[Yt.Link]:!0})),le(a.getURL()),k(!0)):zt(r)?(V(e=>({...e,[Yt.Link]:!0})),le(r.getURL()),k(!0)):(V(e=>({...e,[Yt.Link]:!1})),le("https://"),k(!1))}};r(()=>Sn(v.registerUpdateListener(({editorState:e})=>{e.read(()=>{ae()})}),v.registerCommand($,()=>(ae(),!1),1),v.registerCommand(Z,e=>(w(t=>({...t,undo:!e})),!1),1),v.registerCommand(G,e=>(w(t=>({...t,redo:!e})),!1),1)),[]);const ce="scrollbar"===y,se=s(()=>{if("collapse"!==y)return;const e=z.current;if(!e)return;const t=e.clientWidth;if(t<=0)return;const n=F.current?F.current.offsetWidth:0,o=mo.map(e=>{const t=O.current[e];return t&&"none"!==t.style.display&&(I.current[e]=t.offsetWidth),I.current[e]??0});W.current&&(H.current=W.current.offsetWidth);const i=H.current||40,l=e=>{const t=1+(e>0?1:0)+(mo.length-e);let l=n+6*Math.max(0,t-1)+(e>0?i:0);for(let t=0;t<mo.length-e;t++)l+=o[t];return l};let r=_;for(;r<mo.length&&l(r)>t;)r++;for(;r>0&&l(r-1)<=t;)r--;E(e=>e===r?e:r)},[_,y]);r(()=>{se()});const de=l(()=>{});de.current=se,r(()=>{if("undefined"==typeof ResizeObserver)return;const e=z.current;if(!e)return;const t=new ResizeObserver(()=>{de.current(),be.current()});return t.observe(e),()=>t.disconnect()},[]),r(()=>{0===_&&M(!1)},[_]),r(()=>{"collapse"!==y&&E(0)},[y]);const ue=s(()=>{if("scrollbar"!==y)return;const e=z.current,t=U.current,n=K.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,a=l>0?e.scrollLeft/l*r:0;n.style.width=`${i}px`,n.style.transform=`translateX(${a}px)`},[f]),he=s(e=>{e.stopPropagation(),e.preventDefault();const t=z.current,n=K.current;if(!t||!n)return;const o=e.clientX,i=t.scrollLeft,l=t.clientWidth,r=Math.max(24,l/t.scrollWidth*l),a=t.scrollWidth-l,c=l-r,s=e=>{const n=e.clientX-o;t.scrollLeft=c>0?i+n/c*a:0},d=()=>{document.removeEventListener("pointermove",s),document.removeEventListener("pointerup",d)};document.addEventListener("pointermove",s),document.addEventListener("pointerup",d)},[]),pe=s(e=>{const t=z.current,n=U.current;if(!t||!n)return;const o=n.getBoundingClientRect(),i=(e.clientX-o.left)/o.width;t.scrollLeft=i*t.scrollWidth-t.clientWidth/2},[]),me=l(null),ge=s(()=>{const e=me.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 a=Math.min(22,Math.max(17,15/r));parseFloat(e.style.width)!==a&&(e.style.width=`${a}px`,e.style.height=`${a}px`)}catch{}}},[]);r(()=>{ge()}),r(()=>{ue()});const be=l(()=>{});be.current=ue,r(()=>{if("scrollbar"!==y)return;const e=z.current;if(!e)return;const t=()=>ue();return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[y,ue]);const fe=e=>{switch(e){case Yt.Bold:v.dispatchCommand(oe,"bold");break;case Yt.Italics:v.dispatchCommand(oe,"italic");break;case Yt.Underline:v.dispatchCommand(oe,"underline");break;case Yt.Lowercase:v.dispatchCommand(oe,"lowercase");break;case Yt.Uppercase:v.dispatchCommand(oe,"uppercase");break;case Yt.Capitalize:v.dispatchCommand(oe,"capitalize");break;case Yt.Strikethrough:v.dispatchCommand(oe,"strikethrough");break;case Yt.Superscript:v.dispatchCommand(oe,"superscript");break;case Yt.Subscript:v.dispatchCommand(oe,"subscript");break;case Yt.Highlight:v.dispatchCommand(oe,"highlight");break;case Yt.Code:v.dispatchCommand(oe,"code");break;case Yt.Quote:v.update(()=>{const e=T();if(R(e)){const t=e.anchor.getNode().getParent();t&&h(t)?bn(e,()=>P()):vn(e,()=>p())}});break;case Yt.Link:ye(),k(!0);break;case Yt.LeftAlign:v.dispatchCommand(ne,"left");break;case Yt.RightAlign:v.dispatchCommand(ne,"right");break;case Yt.CenterAlign:v.dispatchCommand(ne,"center");break;case Yt.JustifyAlign:v.dispatchCommand(ne,"justify");break;case Yt.Undo:v.dispatchCommand(te,void 0);break;case Yt.Redo:v.dispatchCommand(ee,void 0);break;case Yt.ClearFormatting:v.update(()=>{const e=T();if(!R(e))return;const t=e.getNodes().filter(D);for(const e of t)e.setFormat(0),e.setStyle("")});break;case Yt.HorizontalRule:v.dispatchCommand(ke,void 0);break;case Yt.Indent:v.dispatchCommand(J,void 0);break;case Yt.Outdent:v.dispatchCommand(B,void 0)}},ye=s(()=>{v.update(()=>{const e=T();R(e)&&!e.isCollapsed()&&(C?v.dispatchCommand(Dt,null):""!==ie&&v.dispatchCommand(Dt,ie))})},[v,C,ie]),ve=s(()=>{le(""),v.dispatchCommand(Dt,null),k(!1)},[v]),Ce=e=>mo.indexOf(e)>=mo.length-_,Ne={headings:e(Rn,{updateHeading:e=>{v.update(()=>{const t=T();R(t)&&vn(t,"normal"===e?()=>P():()=>m(e))})},headingSelectionMap:j}),fontFamily:e($n,{}),fontSize:e(Kn,{}),textFormats:e(n,{children:en.map(({id:t,label:n,icon:o})=>t===Yt.Divider?e(Mn,{},t):e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),children:o})},t))}),dropdown:e(An,{onAction:fe,selectionMap:q}),color:t(n,{children:[e(In,{}),tn.map(({id:t,label:n,icon:o})=>e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),children:o})},t))]}),quoteCode:e(n,{children:nn.map(({id:t,label:n,icon:o})=>e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),children:o})},t))}),codeBlock:e(Jn,{}),alignment:e(Wn,{onAction:fe,alignmentSelectionMap:q}),lists:e(qn,{blockType:X}),blockOptions:e(n,{children:ln.map(({id:t,label:n,icon:o})=>t===Yt.Divider?e(Mn,{},t):e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),children:o})},t))}),table:e(Vn,{}),hline:e(n,{children:rn.map(({id:t,label:n,icon:o})=>e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),children:o})},t))}),link:e(Pn,{content:"Link",direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[Yt.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(Yt.Link),disabled:!!x[Yt.Link],children:e(It,{})})}),image:e(eo,{onImageUpload:i}),video:e(so,{}),utility:t(n,{children:[e(Pn,{content:"Find & Replace",direction:"bottom",children:e("button",{type:"button","aria-label":"Find & Replace",className:`size-10 lexical-btn ${N?"toolbarActive":"toolbar"} icon`,onClick:()=>S(e=>!e),children:e(St,{})})}),e(Pn,{content:"Source Code View",direction:"bottom",children:e("button",{type:"button","aria-label":"Source Code View",className:`size-10 lexical-btn ${a?"toolbarActive":"toolbar"} icon`,onClick:()=>d?.(),children:e(_t,{})})}),e(Pn,{content:g?"Exit Fullscreen":"Fullscreen",direction:"bottom",children:e("button",{type:"button","aria-label":g?"Exit Fullscreen":"Fullscreen",className:`size-10 lexical-btn ${g?"toolbarActive":"toolbar"} icon`,onClick:()=>b?.(),children:e(g?ht:pt,{})})})]}),preview:e(ho,{value:o})};return t("div",{ref:me,className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[t("div",{ref:z,className:"lte-toolbar-row "+(ce?"useScroll":"collapse"===y?"lte-nowrap":"lte-wrap"),onMouseDown:e=>e.preventDefault(),children:[e("div",{ref:F,className:"lte-toolbar-primary",style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:on.map(({id:t,label:n,icon:o})=>t===Yt.Divider?e(Mn,{},t):e(Pn,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-10 lexical-btn ${q[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>fe(t),disabled:!!x[t],children:o})},n))}),po.map(({id:n,sep:o})=>{const i=Ce(n);return t("div",{ref:e=>{O.current[n]=e},style:i?{display:"none"}:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[o?e(Mn,{}):null,i?null:Ne[n]]},n)}),_>0&&e(Pn,{content:"More tools",direction:"bottom",children:e("button",{type:"button",ref:W,"aria-label":"More tools",className:`size-10 lexical-btn ${A?"toolbarActive":"toolbar"} icon`,onClick:()=>M(e=>!e),children:e(mt,{})})})]}),ce&&e("div",{ref:U,className:"lte-custom-scrollbar",onPointerDown:pe,"aria-hidden":"true",children:e("div",{ref:K,className:"lte-custom-scrollbar-thumb",onPointerDown:he})}),C&&e(Dn,{linkUrl:ie,setLinkUrl:le,removeLink:ve,onConfirm:e=>{v.dispatchCommand(Dt,{url:e,target:"_blank"}),le(e),k(!1)},onCancel:()=>{le(""),k(!1)}}),A&&e(Fn,{anchorRef:W,onClose:()=>M(!1),children:po.filter(({id:e})=>Ce(e)&&Ne[e]).map(({id:n,sep:o},i)=>t("div",{className:"lte-overflow-item",children:[o&&i>0?e(Mn,{}):null,Ne[n]]},n))}),N&&e(zn,{onClose:()=>S(!1)})]})};function bo(e,t){const n=ie(t)?t.body.childNodes:t.childNodes;let o=[];const i=[];for(const t of n)if(!vo.has(t.nodeName)){const n=xo(t,e,i,!1);null!==n&&(o=o.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof le&&t.insertAfter(re());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(i),o}function fo(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=H().getChildren();for(let i=0;i<o.length;i++)yo(e,o[i],n,t);return n.innerHTML}function yo(e,t,n,o=null){let i=null===o||t.isSelected(o);const l=L(t)&&t.excludeFromCopy("html");let r=t;if(null!==o){let e=ae(t);e=D(e)&&null!==o?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!z(t)&&null!==n){const[o,i]=n,l=e.isBackward(),r=o.getNode(),a=i.getNode(),c=t.is(r),s=t.is(a);if(c||s){const[n,o]=F(e),i=r.is(a),c=t.is(l?a:r),s=t.is(l?r:a);let d,u=0;i?(u=n>o?o:n,d=n>o?n:o):c?(u=l?o:n,d=void 0):s&&(u=0,d=l?n:o),t.__text=t.__text.slice(u,d)}}return t}(o,e):e,r=e}const a=L(r)?r.getChildren():[],c=ce(e,r.getType());let s;s=c&&void 0!==c.exportDOM?c.exportDOM(e,r):r.exportDOM(e);const{element:d,after:u}=s;if(!d)return!1;const h=document.createDocumentFragment();for(let n=0;n<a.length;n++){const l=a[n],r=yo(e,l,h,o);!i&&L(t)&&r&&t.extractWithChild(l,o,"html")&&(i=!0)}if(i&&!l){if((se(d)||de(d))&&d.append(h),n.append(d),u){const e=u.call(r,d);e&&(de(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(h);return i}const vo=new Set(["STYLE","SCRIPT"]);function xo(e,t,n,o,i=new Map,l){let r=[];if(vo.has(e.nodeName))return r;let a=null;const c=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),s=c?c(e):null;let d=null;if(null!==s){d=s.after;const t=s.node;if(a=Array.isArray(t)?t[t.length-1]:t,null!==a){for(const[,e]of i)if(a=e(a,l),!a)break;a&&r.push(...Array.isArray(t)?t:[a])}null!=s.forChild&&i.set(e.nodeName,s.forChild)}const u=e.childNodes;let h=[];const p=(null==a||!A(a))&&(null!=a&&ue(a)||o);for(let e=0;e<u.length;e++)h.push(...xo(u[e],t,n,p,new Map(i),a));return null!=d&&(h=d(h)),he(e)&&(h=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(ue(r))o&&!r.getFormat()&&r.setFormat(o),i.push(r);else if(l.push(r),e===t.length-1||e<t.length-1&&ue(t[e+1])){const e=n();e.setFormat(o),e.append(...l),i.push(e),l=[]}}return i}(e,h,p?()=>{const e=new le;return n.push(e),e}:P)),null==a?h.length>0?r=r.concat(h):he(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(pe(e.nextSibling)&&pe(e.previousSibling))}(e)&&(r=r.concat(re())):L(a)&&a.append(...h),r}function wo({value:t,onChange:n}){const[o]=Rt(),[i,l]=c(!0);return r(()=>{t&&i&&(l(!1),o.update(()=>{if(fo(o)!==t){H().clear();const e=(new DOMParser).parseFromString(t,"text/html"),n=bo(o,e);Y(n)}}))},[o,t,i]),r(()=>{l(!0)},[t]),e(Xt,{onChange:e=>{e.read(()=>{n(fo(o))})}})}function Co({applyRef:n,onExit:o}){const[i]=Rt(),[a,s]=c(()=>i.getEditorState().read(()=>fo(i))),d=l(a),u=e=>{e!==d.current&&(i.update(()=>{const t=H();if(t.clear(),t.selectEnd(),e){const t=(new DOMParser).parseFromString(e,"text/html"),n=bo(i,t);n.length>0&&Y(n)}}),d.current=e)};return r(()=>(n.current=()=>{u(a),o()},()=>{n.current=null}),[n,a,o,i]),t("div",{className:"lexical-source-view",children:[e("textarea",{className:"lexical-source-textarea",value:a,onChange:e=>s(e.target.value),"aria-label":"HTML source",spellCheck:!1}),t("div",{className:"lexical-source-actions",children:[e(Pn,{content:"Apply HTML to the editor",direction:"top",children:t("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>u(a),children:[e(Ht,{size:16}),e("span",{className:"label",children:"Update"})]})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{u(a),o()},children:"Done"})]})]})}function ko({showWordCount:n=!0,showCharCount:o=!0,rightSlot:i}){const[l]=Rt(),[a,s]=c({words:0,chars:0});return r(()=>{const e=e=>{e.read(()=>{const e=H().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]),t("div",{className:"lexical-status-bar",children:[n&&t("span",{children:[a.words," words"]}),o&&t("span",{children:[a.chars," characters"]}),i&&e("div",{className:"lexical-status-bar-right",children:i})]})}function No({theme:n,toolbarStyle:o,onThemeChange:i,onToolbarStyleChange:l}){const r="normal"===o?"collapse":o,a=[{value:"light",label:"Light theme",icon:e(gt,{})},{value:"dark",label:"Dark theme",icon:e(bt,{})},{value:"system",label:"Follow system theme",icon:e(Ut,{})}],c=[{value:"wrap",label:"Toolbar: wrap to new lines",icon:e($t,{})},{value:"collapse",label:'Toolbar: collapse into "..."',icon:e(mt,{})},{value:"scrollbar",label:"Toolbar: scroll in one row",icon:e(Je,{})}];return t("div",{className:"lexical-display-controls",role:"group","aria-label":"Display settings",children:[e("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Theme",children:a.map(t=>e(Pn,{content:t.label,direction:"top",children:e("button",{type:"button",role:"radio","aria-checked":n===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(n===t.value?"active":""),onClick:()=>i?.(t.value),children:t.icon})},t.value))}),e("div",{className:"lte-mini-seg",role:"radiogroup","aria-label":"Toolbar style",children:c.map(t=>e(Pn,{content:t.label,direction:"top",children:e("button",{type:"button",role:"radio","aria-checked":r===t.value,"aria-label":t.label,className:"lte-mini-btn btn "+(r===t.value?"active":""),onClick:()=>l?.(t.value),children:t.icon})},t.value))})]})}const So=({id:e})=>new Mo({id:e}),_o="data-lexical-youtube",Lo="315px",To="560px",Eo=e=>`https://www.youtube-nocookie.com/embed/${e}`,Ao=e=>{const t=e?.getAttribute(_o);if(!t)return null;return{node:So({id:t})}};class Mo extends V{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new Mo({id:e.__id,key:e.getKey()})}static importJSON(e){return So({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:Lo,width:To,src:Eo(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(_o,this.__id),e.setAttribute("height",Lo),e.setAttribute("width",To),e.setAttribute("src",Eo(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Ao,priority:0})}}}class Ro extends me{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new Ro(e.__text,e.__key)}static importDOM(){const e=me.importDOM();return{...e,span:()=>({conversion:Do(e?.span),priority:1}),div:()=>({conversion:Do(e?.div),priority:1}),p:()=>({conversion:Do(e?.p),priority:1}),b:()=>({conversion:Do(e?.b),priority:1}),strong:()=>({conversion:Do(e?.strong),priority:1}),i:()=>({conversion:Do(e?.i),priority:1}),em:()=>({conversion:Do(e?.em),priority:1}),u:()=>({conversion:Do(e?.u),priority:1}),s:()=>({conversion:Do(e?.s),priority:1}),strike:()=>({conversion:Do(e?.strike),priority:1}),code:()=>({conversion:Do(e?.code),priority:1})}}static importJSON(e){return function(e=""){return j(new Ro(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Do(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(i)&&l.length>0){const e=l.join("; ");return i.setStyle(e)}return i}}}}const zo={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"}},Fo=i.memo(function({name:n,value:i,onChange:a,placeholder:s,maxWidth:u=null,height:h=null,onImageUpload:p,showWordCount:m=!0,showCharCount:f=!0,theme:y="system",toolbarStyle:N="collapse",showDisplayControls:S=!0,onThemeChange:_,onToolbarStyleChange:L}){const[T,E]=c(!1),[A,M]=c(!1),R=l(null),[D,z]=c(!1),[F,W]=c(y),[O,I]=c("normal"===N?"collapse":N);r(()=>{W(y)},[y]),r(()=>{I("normal"===N?"collapse":N)},[N]),r(()=>{if("system"!==F||"undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-color-scheme: dark)");z(e.matches);const t=e=>z(e.matches);return e.addEventListener?(e.addEventListener("change",t),()=>e.removeEventListener("change",t)):(e.addListener(t),()=>e.removeListener(t))},[F]);const H="dark"===F||"system"===F&&D;r(()=>{if(!A)return;const e=e=>{"Escape"===e.key&&M(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[A]);const U=d(()=>({namespace:n,theme:zo,onError:e=>{console.error("Lexical error:",e)},nodes:[Ro,{replace:me,with:e=>new Ro(e.__text),withKlass:Ro},g,v,x,xe,Ce,b,Ft,Yn,Mo,co,Ne,Fe,We,Oe]}),[n]);return e("div",{className:`lexical-text-editor lexical-editor-container ${A?"lexical-fullscreen":""} ${H?"lexical-dark":""}`,style:{maxWidth:A?"none":u||"1090px"},children:t(o,{initialConfig:U,children:[e("div",{className:"lexical-toolbar-container",children:e(go,{value:i,onImageUpload:p,sourceView:T,onToggleSourceView:()=>{E(e=>!e||(R.current?.(),!1))},fullscreen:A,onToggleFullscreen:()=>{M(e=>!e)},toolbarStyle:O})}),e("div",{className:"lexical-editor-inner",style:T?{display:"none"}:void 0,children:e(w,{contentEditable:e(C,{className:"lexical-content-editable",style:{height:h||"500px"}}),placeholder:e("div",{className:"lexical-placeholder",children:s||"Some Text"}),ErrorBoundary:k})}),T&&e(Co,{applyRef:R,onExit:()=>E(!1)}),(m||f||S)&&e(ko,{showWordCount:m,showCharCount:f,rightSlot:S?e(No,{theme:F,toolbarStyle:O,onThemeChange:e=>{W(e),_?.(e)},onToolbarStyleChange:e=>{I(e),L?.(e)}}):void 0}),e(ge,{}),e(be,{}),e(_e,{}),e(Se,{}),e(Qt,{}),e(wo,{value:i,onChange:a})]})})});export{Fo as LexicalTextEditor};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|