@innoviatech/lexical-text-editor 2.0.4 → 2.0.6

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