@innoviatech/lexical-text-editor 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +237 -236
- 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/package.json +1 -1
- package/src/components/AlignmentSelectionList.tsx +2 -2
- package/src/components/ColorPicker.tsx +1 -1
- package/src/components/ContentPreview.tsx +2 -1
- package/src/components/DropdownList.tsx +2 -2
- package/src/components/HeadingSelectionList.tsx +2 -2
- package/src/components/LinkModal.tsx +4 -4
- package/src/components/common/Dialog.tsx +1 -1
- package/src/nodes/ImageNode.tsx +0 -3
- package/src/plugins/ImagePlugin.tsx +4 -4
- package/src/plugins/ListPlugin.tsx +2 -2
- package/src/plugins/ToolbarPlugin.tsx +3 -3
- package/src/plugins/VideoPlugin.tsx +2 -3
- package/src/styles/lexical-editor.css +3 -3
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 x}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as y}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 xe,TbUnderline as ye}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(xe,{}),label:"Italics"},{id:ct.Underline,icon:e(ye,{}),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 xt(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function yt(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)&&yt(p.anchor)&&yt(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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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",{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}),[x,y]=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();y(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()};y(o.getType()),v(t)}else y(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=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()):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",{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",{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:x}),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",{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: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 vn(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 yn={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:yn,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(x,{contentEditable:e(y,{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}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 console.log(n),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};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|