@innoviatech/lexical-text-editor 1.0.5 → 2.0.0
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 +105 -35
- package/dist/components/ContentPreview.d.ts +1 -1
- package/dist/components/HeadingSelectionList.d.ts +1 -1
- package/dist/components/LexicalTextEditor.d.ts +1 -1
- package/dist/components/common/Dialog.d.ts +9 -0
- package/dist/components/common/Popover.d.ts +21 -0
- package/dist/components/common/Tooltip.d.ts +10 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -0
- package/dist/nodes/ExtendedTextNode.d.ts +11 -0
- package/dist/nodes/ImageNode.d.ts +1 -1
- package/dist/plugins/YoutubePlugin.d.ts +1 -0
- package/package.json +20 -16
- package/rollup.config.js +3 -4
- package/src/components/AlignmentSelectionList.tsx +41 -24
- package/src/components/ColorPicker.tsx +7 -21
- package/src/components/ContentPreview.tsx +27 -20
- package/src/components/DropdownList.tsx +39 -24
- package/src/components/HeadingSelectionList.tsx +48 -32
- package/src/components/ImageComponent.tsx +52 -19
- package/src/components/InsertDropdownList.tsx +1 -1
- package/src/components/LexicalTextEditor.tsx +33 -28
- package/src/components/LinkModal.tsx +42 -45
- package/src/components/common/Dialog.tsx +47 -0
- package/src/components/common/Popover.tsx +87 -0
- package/src/components/common/Tooltip.tsx +43 -0
- package/src/components/ui/command.tsx +0 -1
- package/src/nodes/ExtendedTextNode.tsx +174 -0
- package/src/nodes/ImageNode.tsx +48 -9
- package/src/plugins/ColorPlugin.tsx +19 -14
- package/src/plugins/ImagePlugin.tsx +79 -84
- package/src/plugins/ListPlugin.tsx +20 -38
- package/src/plugins/ToolbarPlugin.tsx +76 -78
- package/src/plugins/VideoPlugin.tsx +46 -55
- package/src/plugins/YoutubePlugin.tsx +83 -0
- package/src/styles/lexical-editor.css +962 -3
- package/dist/style.css +0 -3
- package/postcss.config.js +0 -6
- package/src/assets/react.svg +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposer"),i=require("react"),n=require("@lexical/rich-text"),o=require("@lexical/code"),r=require("@lexical/react/LexicalRichTextPlugin"),s=require("@lexical/react/LexicalContentEditable"),a=require("@lexical/react/LexicalErrorBoundary"),l=require("@lexical/react/LexicalHistoryPlugin"),c=require("@lexical/react/LexicalListPlugin"),d=require("@lexical/list"),u=require("react-icons/rx"),h=require("react-icons/tb"),g=require("react-icons/bs"),p=require("react-icons/ai"),m=require("react-icons/io5"),x=require("react-icons/pi"),f=require("@lexical/react/LexicalComposerContext"),b=require("lexical"),v=require("@lexical/link"),N=require("@radix-ui/react-slot"),y=require("class-variance-authority"),j=require("clsx"),C=require("tailwind-merge"),w=require("@radix-ui/react-tooltip"),_=require("@radix-ui/react-popover"),k=require("react-icons/hi2"),T=require("react-icons/io"),A=require("lucide-react"),S=require("react-icons/ti"),E=require("react-color"),O=require("react-dom"),M=require("@radix-ui/react-dialog"),L=require("react-icons/fa"),D=require("react-icons/vsc"),R=require("@lexical/react/LexicalLinkPlugin"),$=require("@lexical/react/LexicalOnChangePlugin");function z(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,n.get?n:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var F,B,I=z(i),H=z(w),P=z(_),q=z(M);!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"}(F||(F={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(B||(B={}));const U=[{id:F.Lowercase,icon:e.jsx(u.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:F.Uppercase,icon:e.jsx(u.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:F.Capitalize,icon:e.jsx(u.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:F.Strikethrough,icon:e.jsx(p.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:F.Highlight,icon:e.jsx(x.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:F.Superscript,icon:e.jsx(g.BsSuperscript,{}),label:"Superscript"},{id:F.Subscript,icon:e.jsx(g.BsSubscript,{}),label:"Subscript"}],K=[{id:F.Bold,icon:e.jsx(h.TbBold,{}),label:"Bold"},{id:F.Italics,icon:e.jsx(h.TbItalic,{}),label:"Italics"},{id:F.Underline,icon:e.jsx(h.TbUnderline,{}),label:"Underline"},{id:F.Divider},{id:F.Quote,icon:e.jsx(g.BsChatSquareQuote,{}),label:"Quote"},{id:F.Code,icon:e.jsx(m.IoCodeSlashOutline,{}),label:"Code"}],W=[{id:F.Undo,icon:e.jsx(g.BsArrowCounterclockwise,{}),label:"Undo"},{id:F.Redo,icon:e.jsx(g.BsArrowClockwise,{}),label:"Redo"},{id:F.Divider}],J=[{id:F.LeftAlign,icon:e.jsx(g.BsJustifyLeft,{}),label:"Left Align"},{id:F.CenterAlign,icon:e.jsx(g.BsTextCenter,{}),label:"Center Align"},{id:F.RightAlign,icon:e.jsx(g.BsJustifyRight,{}),label:"Right Align"},{id:F.JustifyAlign,icon:e.jsx(g.BsJustify,{}),label:"Justify Align"}],X=[{id:"normal",label:"Normal",icon:e.jsx(g.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:e.jsx(g.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:e.jsx(g.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:e.jsx(g.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:e.jsx(g.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:e.jsx(g.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:e.jsx(g.BsTypeH6,{})}];function G(e,...t){const i=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of t)n.append("v",e);throw i.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${i.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Q=new Map;function V(e){let t=Q.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const i=e.split(";");for(const e of i)if(""!==e){const[i,n]=e.split(/:([^]+)/);i&&n&&(t[i.trim()]=n.trim())}return t}(e),Q.set(e,t)),t}function Y(e,t){(b.$isRangeSelection(e)?e.isCollapsed():b.$isTextNode(e)||b.$isElementNode(e))||G(280);const i=V(b.$isRangeSelection(e)?e.style:b.$isTextNode(e)?e.getStyle():e.getTextStyle()),n=Object.entries(t).reduce((t,[n,o])=>("function"==typeof o?t[n]=o(i[n],e):null===o?delete t[n]:t[n]=o,t),{...i}),o=function(e){let t="";for(const i in e)i&&(t+=`${i}: ${e[i]};`);return t}(n);b.$isRangeSelection(e)||b.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),Q.set(o,n)}function Z(e,t){if(b.$isRangeSelection(e)&&e.isCollapsed()){Y(e,t);const i=e.anchor.getNode();b.$isElementNode(i)&&i.isEmpty()&&Y(i,t)}!function(e){const t=b.$getSelection();if(!t)return;const i=new Map,n=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(b.$isRangeSelection(t))for(const e of b.$caretRangeFromSelection(t).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!b.$isTextNode(t)||!t.canHaveFormat())continue;const[i,o]=n(t);o!==i&&(b.$isTokenOrSegmented(t)||0===i&&o===t.getTextContentSize()?e(t):e(t.splitText(i,o)[0===i?0:1]))}b.$isRangeSelection(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:i}=e,{key:n,offset:o,type:r}=t;t.set(i.key,i.offset,i.type),i.set(n,o,r)}}(t)}(e=>{Y(e,t)})}function ee(e,t){const i=e.getFormatType(),n=e.getIndent();i!==t.getFormatType()&&t.setFormat(i),n!==t.getIndent()&&t.setIndent(n)}function te(e){return e.getNode().isAttached()}function ie(e){let t=e;for(;null!==t&&!b.$isRootOrShadowRoot(t);){const e=t.getLatest(),i=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=i}}function ne(e,t,i=null){const n=e.getStartEndPoints(),o=n?n[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),n=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),n.forEach(e=>r.append(e)),i&&(r=i.append(r)),void e.replace(r)}let a=null,l=[];for(let n=0;n<s;n++){const o=r[n];b.$isRootOrShadowRoot(o)?(oe(e,l,l.length,t,i),l=[],a=o):null===a||null!==a&&b.$hasAncestor(o,a)?l.push(o):(oe(e,l,l.length,t,i),l=[o])}oe(e,l,l.length,t,i)}function oe(e,t,i,n,o=null){if(0===t.length)return;const r=t[0],s=new Map,a=[];let l=b.$isElementNode(r)?r:r.getParentOrThrow();l.isInline()&&(l=l.getParentOrThrow());let c=!1;for(;null!==l;){const e=l.getPreviousSibling();if(null!==e){l=e,c=!0;break}if(l=l.getParentOrThrow(),b.$isRootOrShadowRoot(l))break}const d=new Set;for(let e=0;e<i;e++){const i=t[e];b.$isElementNode(i)&&0===i.getChildrenSize()&&d.add(i.getKey())}const u=new Set;for(let e=0;e<i;e++){const i=t[e];let o=i.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&b.$isLeafNode(i)&&!u.has(i.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=n();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),a.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),b.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),ie(o)}}else if(d.has(i.getKey())){b.$isElementNode(i)||G(179);const e=n();e.setFormat(i.getFormatType()),e.setIndent(i.getIndent()),a.push(e),i.remove(!0)}}if(null!==o)for(let e=0;e<a.length;e++){const t=a[e];o.append(t)}let h=null;if(b.$isRootOrShadowRoot(l))if(c)if(null!==o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t)}else{const e=l.getFirstChild();if(b.$isElementNode(e)&&(l=e),null===e)if(o)l.append(o);else for(let e=0;e<a.length;e++){const t=a[e];l.append(t),h=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<a.length;t++){const i=a[t];e.insertBefore(i),h=i}}else if(o)l.insertAfter(o);else for(let e=a.length-1;e>=0;e--){const t=a[e];l.insertAfter(t),h=t}const g=b.$getPreviousSelection();b.$isRangeSelection(g)&&te(g.anchor)&&te(g.focus)?b.$setSelection(g.clone()):null!==h?h.selectEnd():e.dirty=!0}function re(e,t,i){const n=V(e.getStyle());return null!==n&&n[t]||i}function se(e,t,i=""){let n=null;const o=e.getNodes(),r=e.anchor,s=e.focus,a=e.isBackward(),l=a?s.offset:r.offset,c=a?s.getNode():r.getNode();if(b.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const i=V(e.style);if(null!==i&&t in i)return i[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==l||!r.is(c))&&b.$isTextNode(r)){const e=re(r,t,i);if(null===n)n=e;else if(n!==e){n="";break}}}return null===n?i:n}const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,le=ae&&"documentMode"in document?document.documentMode:null;function ce(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function de(...e){return C.twMerge(j.clsx(e))}ae&&"InputEvent"in window&&!le&&new window.InputEvent("input");const ue=y.cva("cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",toolbar:"bg-transparent hover:bg-slate-100/80 text-gray-600",toolbarActive:"bg-slate-100 text-gray-900 ",destructive:"bg-destructive text-white hover:bg-destructive/90",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-2",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}}),he=I.forwardRef(({className:t,variant:i,size:n,asChild:o=!1,...r},s)=>{const a=o?N.Slot:"button";return e.jsx(a,{"data-slot":"button",className:de(ue({variant:i,size:n,className:t})),ref:s,...r})});function ge({delayDuration:t=0,...i}){return e.jsx(H.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...i})}function pe({...t}){return e.jsx(ge,{children:e.jsx(H.Root,{"data-slot":"tooltip",...t})})}function me({...t}){return e.jsx(H.Trigger,{"data-slot":"tooltip-trigger",...t})}function xe({className:t,sideOffset:i=0,children:n,...o}){return e.jsx(H.Portal,{children:e.jsxs(H.Content,{"data-slot":"tooltip-content",sideOffset:i,className:de("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",t),...o,children:[n,e.jsx(H.Arrow,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function fe({...t}){return e.jsx(P.Root,{"data-slot":"popover",...t})}function be({...t}){return e.jsx(P.Trigger,{"data-slot":"popover-trigger",...t})}function ve({className:t,align:i="center",sideOffset:n=4,...o}){return e.jsx(P.Portal,{children:e.jsx(P.Content,{"data-slot":"popover-content",align:i,sideOffset:n,className:de("bg-[#ffffff] text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...o})})}function Ne({onAction:t,selectionMap:n}){const[o,r]=i.useState(!1);return e.jsxs(fe,{open:o,onOpenChange:e=>r(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",onClick:()=>r(!o),size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx("span",{children:"Aa"})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(o?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{className:"p-2 w-fit flex flex-col items-start gap-1",children:U.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ye(){return e.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function je({updateHeading:t,headingSelectionMap:n}){const o=X.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[130px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:X.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function Ce({className:t,type:i,...n}){return e.jsx("input",{type:i,"data-slot":"input",className:de("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",t),...n})}function we({linkUrl:t,setLinkUrl:n,onConfirm:o,onCancel:r,removeLink:s}){const[a,l]=i.useState(!1),c=i.useRef(null),d=i.useRef(null);return i.useEffect(()=>{"https://"===t&&l(!0)},[t]),i.useEffect(()=>{a&&d.current?.focus()},[a]),i.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]),e.jsxs("div",{ref:c,className:de("absolute z-[9999] bottom-[-50px] sm:bottom-[-60px] right-[20px]","bg-white shadow-lg rounded-xl px-1.5 py-1 sm:px-3 sm:py-2 flex items-center space-x-2","border border-gray-200"),children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:a?e.jsx(Ce,{ref:d,className:"h-8 text-sm",value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o(t),l(!1)):"Escape"===e.key&&(e.preventDefault(),l(!1),r())}}):e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 text-sm underline truncate block max-w-full text-start",children:t})}),e.jsxs("div",{children:[e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:()=>{a?(o(t),l(!1)):l(!0)},className:"h-8 w-8",children:a?e.jsx(A.Check,{className:"h-4 w-4"}):e.jsx(A.Pencil,{className:"h-4 w-4"})}),e.jsx(he,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:s,className:"h-8 w-8",children:e.jsx(S.TiDeleteOutline,{className:"h-4 w-4"})})]})]})}function _e({onAction:t,alignmentSelectionMap:n}){const o=J.find(e=>n[e.id]),[r,s]=i.useState(!1);return e.jsxs(fe,{open:r,onOpenChange:e=>s(e),children:[e.jsx(be,{asChild:!0,children:e.jsxs(he,{variant:r?"toolbarActive":"toolbar",onClick:()=>s(!r),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[145px] border-[1px] border-gray-100",children:[o?.icon,e.jsx("span",{children:o?.label})," ",e.jsx(k.HiChevronDown,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e.jsx(ve,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:J.map(({id:i,label:o,icon:r})=>e.jsxs(he,{variant:n[i]?"toolbarActive":"toolbar",onClick:()=>t(i),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[r," ",e.jsx("span",{className:"ml-2",children:o})]},i))})]})}function ke({color:t,onChange:n,icon:o}){const[r,s]=i.useState(!1),a=i.useRef(null),l=i.useRef(null);i.useEffect(()=>{const e=e=>{l.current&&!l.current.contains(e.target)&&a.current&&!a.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return e.jsxs("div",{className:"relative inline-block",children:[e.jsx(he,{ref:a,variant:"ghost",size:"icon",className:"rounded-md text-gray-700 hover:bg-gray-200","aria-label":"Change Color",onClick:()=>s(e=>!e),children:o}),r&&O.createPortal(e.jsx("div",{ref:l,className:"\n absolute z-50 p-2 bg-transparent rounded-md select-none\n transition-all duration-200\n origin-top-left w-fit\n "+(r?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"),style:{top:a.current?.getBoundingClientRect().bottom,left:a.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e.jsx(E.SketchPicker,{color:t,onChangeComplete:e=>{n(e.hex)}})}),document.body)]})}function Te(){const[t]=f.useLexicalComposerContext(),[{color:n,bgColor:o},r]=i.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=se(e,"color","#000"),i=se(e,"background","#fff");r({color:t,bgColor:i})}};i.useEffect(()=>ce(t.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),t.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[t]);const a=({property:e,color:i})=>{t.update(()=>{const t=b.$getSelection();t&&Z(t,{[e]:i})})};return e.jsxs(e.Fragment,{children:[e.jsx(ke,{color:n,onChange:e=>{a({property:"color",color:e})},icon:e.jsx(p.AiOutlineFontColors,{})}),e.jsx(ke,{color:o,onChange:e=>{a({property:"background",color:e})},icon:e.jsx(p.AiOutlineBgColors,{})})]})}function Ae({blockType:t}){const[i]=f.useLexicalComposerContext();return e.jsxs(e.Fragment,{children:[e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ol"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add ordered list",onClick:()=>{"ol"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_ORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListOl,{})})}),e.jsx(xe,{side:"bottom",children:"Ordered list"})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:"ul"===t?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add unordered list",onClick:()=>{"ul"===t?i.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):i.dispatchCommand(d.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:e.jsx(g.BsListUl,{})})}),e.jsx(xe,{side:"bottom",children:"Unordered list"})]})]})}he.displayName="Button";const Se=({src:t,altText:n,nodeKey:o,width:r,height:s,maxWidth:a})=>{const[l]=f.useLexicalComposerContext(),[c,d]=i.useState({width:"number"==typeof r?r:a,height:"number"==typeof s?s:"auto"}),u=i.useRef(null),h=i.useRef(null),g=e=>{if(!h.current)return;const t=e.clientX-h.current.x,i=Math.min(a,Math.max(50,h.current.width+t)),n=i/h.current.width*h.current.height||"auto";d({width:i,height:n})},p=()=>{h.current&&(l.update(()=>{const e=b.$getNodeByKey(o);e&&"function"==typeof e.updateDimensions&&e.updateDimensions(c.width,c.height)}),window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",p))};return e.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:a},children:[e.jsx("img",{src:t,alt:n,style:{width:c.width,height:c.height,maxWidth:"100%",display:"block"}}),e.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),h.current={x:e.clientX,y:e.clientY,width:c.width,height:u.current?.offsetHeight??0},window.addEventListener("mousemove",g),window.addEventListener("mouseup",p)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Ee=e=>b.$applyNodeReplacement(new Me(e)),Oe=e=>{if(e instanceof HTMLImageElement){const{src:t,alt:i}=e;return{node:Ee({src:t,altText:i})}}return null};class Me extends b.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:i=1080,width:n,height:o,key:r}={}){super(r),this.__altText=t,this.__src=e,this.__maxWidth=i,this.__height=o,this.__width=n}static getType(){return"image"}static clone(e){return new Me({altText:e.__altText,src:e.__src,height:e.__height,width:e.__width,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}exportDOM(){const e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__altText),this.__width&&"inherit"!==this.__width&&e.setAttribute("width",String(this.__width)),this.__height&&"inherit"!==this.__height&&e.setAttribute("height",String(this.__height)),{element:e}}static importDOM(){return{img:()=>({conversion:Oe,priority:0})}}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 Me({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const i=this.getWritable();i.__width=e,i.__height=t}updateDOM(){return!1}decorate(){return e.jsx(Se,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function Le({...t}){return e.jsx(q.Root,{"data-slot":"dialog",...t})}function De({...t}){return e.jsx(q.Trigger,{"data-slot":"dialog-trigger",...t})}function Re({...t}){return e.jsx(q.Portal,{"data-slot":"dialog-portal",...t})}function $e({className:t,...i}){return e.jsx(q.Overlay,{"data-slot":"dialog-overlay",className:de("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",t),...i})}function ze({className:t,children:i,showCloseButton:n=!0,...o}){return e.jsxs(Re,{"data-slot":"dialog-portal",children:[e.jsx($e,{}),e.jsxs(q.Content,{"data-slot":"dialog-content","aria-describedby":"",className:de("bg-[#ffffff] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",t),...o,children:[i,n&&e.jsxs(q.Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(A.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Fe({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-header",className:de("flex flex-col gap-2 text-center sm:text-left",t),...i})}function Be({className:t,...i}){return e.jsx("div",{"data-slot":"dialog-footer",className:de("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...i})}function Ie({className:t,...i}){return e.jsx(q.Title,{"data-slot":"dialog-title",className:de("text-lg leading-none font-semibold",t),...i})}function He(){const[t,n]=i.useState(!1),[o,r]=i.useState(""),[s,a]=i.useState(""),[l,c]=i.useState(),d=i.useRef(null),[u]=f.useLexicalComposerContext();return e.jsxs("div",{children:[e.jsx("input",{type:"file",ref:d,accept:"image/*",className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&c(t),e.target.value=""}}),e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(m.IoImageOutline,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Add Image"})}),e.jsx("div",{className:"flex flex-col gap-4 py-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Alt text"}),e.jsx(Ce,{value:o,onChange:e=>r(e.target.value),placeholder:"Add Image by URL"}),e.jsxs("div",{className:"flex items-center w-full text-gray-500 text-sm",children:[e.jsx("div",{className:"flex-grow border-t border-gray-300"}),e.jsx("span",{className:"mx-2",children:"or"}),e.jsx("div",{className:"flex-grow border-t border-gray-300"})]}),e.jsxs("div",{className:"flex flex-col gap-2 w-fit",children:[e.jsxs(he,{variant:"outline",className:"flex items-center gap-2 bg-gray-50 hover:bg-gray-100",onClick:()=>d.current?.click(),children:[e.jsx(A.Upload,{className:"h-4 w-4"})," Upload Image"]}),l&&e.jsx("span",{className:"text-sm text-gray-600",children:l.name})]})]})}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{let e="";o&&(e=o),l&&(e=URL.createObjectURL(l)),u.update(()=>{const t=Ee({src:e,altText:s});b.$insertNodes([t])}),c(void 0),a(""),r(""),n(!1)},disabled:!o&&!l,className:"!bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Add Image"})})]})]})]})}const Pe=({id:e,provider:t})=>new Ge({id:e,provider:t}),qe="data-lexical-video",Ue="data-provider",Ke="315px",We="560px",Je=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,Xe=e=>{const t=e?.getAttribute(qe),i=e?.getAttribute(Ue)??"youtube";if(!t)return null;return{node:Pe({id:t,provider:i})}};class Ge extends b.DecoratorNode{constructor({id:e,provider:t,key:i}){super(i),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new Ge({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Pe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e.jsx("iframe",{height:Ke,width:We,src:Je(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(qe,this.__id),e.setAttribute(Ue,this.__provider),e.setAttribute("height",Ke),e.setAttribute("width",We),e.setAttribute("src",Je(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Xe,priority:0})}}}function Qe(){const[t,n]=i.useState(!1),[o,r]=i.useState(!1),[s,a]=i.useState(""),[l]=f.useLexicalComposerContext();return i.useEffect(()=>{t||(a(""),r(!1))},[t]),e.jsx("div",{children:e.jsxs(Le,{open:t,onOpenChange:n,children:[e.jsx(De,{asChild:!0,children:e.jsx(he,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(L.FaYoutube,{})})}),e.jsxs(ze,{className:"sm:max-w-md",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-lg text-gray-800",children:"Embed Video"})}),e.jsxs("div",{className:"py-2",children:[e.jsx(Ce,{value:s,onChange:e=>a(e.target.value),placeholder:"Add YouTube or Google Drive URL"}),o&&e.jsx("p",{className:"mt-1.5 text-red-800/80 text-[0.8rem]",children:"It's not a valid youtube or google drive URL"})]}),e.jsx(Be,{children:e.jsx(he,{onClick:()=>{if(!s)return;let e=null,t=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);i&&11===i[2]?.length&&(e="youtube",t=i[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",t=o[1]),t&&e?(l.update(()=>{const i=Pe({id:t,provider:e});b.$insertNodes([i])}),a(""),r(!1),n(!1)):r(!0)},disabled:!s,className:"bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Embed"})})]})]})})}function Ve({value:t}){return e.jsx("div",{className:"prose max-w-none",dangerouslySetInnerHTML:{__html:t}})}function Ye({value:t,triggerLabel:n="Preview"}){const[o,r]=i.useState(!1);return e.jsxs(Le,{open:o,onOpenChange:r,children:[e.jsx(De,{asChild:!0,children:e.jsxs(he,{variant:o?"toolbarActive":"toolbar",size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx(D.VscPreview,{})," ",n]})}),e.jsxs(ze,{className:"w-[90vw] md:w-[80vw] lg:w-[70vw] max-w-4xl max-h-[90vh] sm:max-w-[1000px] overflow-y-auto bg-white",children:[e.jsx(Fe,{children:e.jsx(Ie,{className:"!text-xl",children:"Content Preview"})}),e.jsxs("div",{className:" p-[2vw] rounded-lg border min-h-[400px] w-full text-start bg-white",children:[e.jsx("div",{className:"py-1 border-b-2 mb-4 font-medium",children:"CONTENT"}),e.jsx(Ve,{value:t})]})]})]})}const Ze=({value:t})=>{const[o]=f.useLexicalComposerContext(),[r,s]=i.useState({[F.Undo]:!0,[F.Redo]:!0}),[a,l]=i.useState(!1),[c,u]=i.useState({[F.LeftAlign]:!0}),[h,g]=i.useState({[B.Normal]:!0}),[p,m]=i.useState("paragraph"),[x,N]=i.useState("https://");let y=!0;const j=()=>{if(y){const e=o.getRootElement();e&&(e.scrollTop=0,y=!1)}const e=b.$getSelection();if(b.$isRangeSelection(e)){const t={[F.Bold]:e.hasFormat("bold"),[F.Italics]:e.hasFormat("italic"),[F.Underline]:e.hasFormat("underline"),[F.Uppercase]:e.hasFormat("uppercase"),[F.Lowercase]:e.hasFormat("lowercase"),[F.Capitalize]:e.hasFormat("capitalize"),[F.Strikethrough]:e.hasFormat("strikethrough"),[F.Superscript]:e.hasFormat("superscript"),[F.Subscript]:e.hasFormat("subscript"),[F.Code]:e.hasFormat("code"),[F.Highlight]:e.hasFormat("highlight")};u(t);const i=e.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),s=r.getKey();if(!o.getElementByKey(s))return;if(d.$isListNode(r)){const e=function(e,t){let i=e;for(;null!=i;){if(i instanceof t)return i;i=i.getParent()}return null}(i,d.ListNode),t=e?e.getTag():r.getTag();m(t)}else if("paragraph"===r.getType()||n.$isHeadingNode(r)){let e=null;n.$isHeadingNode(r)&&(e=r.getTag());const t={[B.H1]:"h1"===e,[B.H2]:"h2"===e,[B.H3]:"h3"===e,[B.H4]:"h4"===e,[B.H5]:"h5"===e,[B.H6]:"h6"===e,[B.Normal]:"paragraph"===r.getType()};g(t)}else m(r.getType());const a=(b.$isElementNode(i)?i:r).getFormat();u(e=>({...e,[F.LeftAlign]:0===a||1===a,[F.CenterAlign]:2===a,[F.RightAlign]:3===a,[F.JustifyAlign]:4===a})),"quote"===r.getType()?u(e=>({...e,[F.Quote]:!0})):u(e=>({...e,[F.Quote]:!1}));const c=e.anchor.getNode(),h=c.getParent();v.$isLinkNode(h)?(u(e=>({...e,[F.Link]:!0})),N(h.getURL()),l(!0)):v.$isLinkNode(c)?(u(e=>({...e,[F.Link]:!0})),N(c.getURL()),l(!0)):(u(e=>({...e,[F.Link]:!1})),N("https://"),l(!1))}};i.useEffect(()=>ce(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{j()})}),o.registerCommand(b.SELECTION_CHANGE_COMMAND,()=>(j(),!1),1),o.registerCommand(b.CAN_UNDO_COMMAND,e=>(s(t=>({...t,undo:!e})),!1),1),o.registerCommand(b.CAN_REDO_COMMAND,e=>(s(t=>({...t,redo:!e})),!1),1)),[]);const C=e=>{switch(e){case F.Bold:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"bold");break;case F.Italics:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"italic");break;case F.Underline:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"underline");break;case F.Lowercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"lowercase");break;case F.Uppercase:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"uppercase");break;case F.Capitalize:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"capitalize");break;case F.Strikethrough:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"strikethrough");break;case F.Superscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"superscript");break;case F.Subscript:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"subscript");break;case F.Highlight:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"highlight");break;case F.Code:o.dispatchCommand(b.FORMAT_TEXT_COMMAND,"code");break;case F.Quote:o.update(()=>{const e=b.$getSelection();if(b.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&n.$isQuoteNode(t)?function(e,t,i=ee){if(null===e)return;const n=e.getStartEndPoints(),o=new Map;let r=null;if(n){const[e,t]=n;r=b.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const i=b.$findMatchingParent(e.getNode(),b.INTERNAL_$isBlock),s=b.$findMatchingParent(t.getNode(),b.INTERNAL_$isBlock);b.$isElementNode(i)&&o.set(i.getKey(),i),b.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(b.$isElementNode(t)&&b.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===n){const e=b.$findMatchingParent(t,b.INTERNAL_$isBlock);b.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,n]of o){const o=t();i(n,o),n.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(b.$getSelection())&&b.$setSelection(r)}(e,()=>b.$createParagraphNode()):ne(e,()=>n.$createQuoteNode())}});break;case F.Link:w(),l(!0);break;case F.LeftAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"left");break;case F.RightAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"right");break;case F.CenterAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"center");break;case F.JustifyAlign:o.dispatchCommand(b.FORMAT_ELEMENT_COMMAND,"justify");break;case F.Undo:o.dispatchCommand(b.UNDO_COMMAND,void 0);break;case F.Redo:o.dispatchCommand(b.REDO_COMMAND,void 0)}},w=i.useCallback(()=>{console.log("insertlink"),a?o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null):""!==x&&o.dispatchCommand(v.TOGGLE_LINK_COMMAND,x)},[o,a]),_=i.useCallback(()=>{N(""),o.dispatchCommand(v.TOGGLE_LINK_COMMAND,null),l(!1)},[o]);return e.jsxs("div",{className:"relative flex gap-1.5 flex-wrap justify-center items-center p-1.5 pb-2 mb-1 border-b-[1px]",children:[W.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(je,{updateHeading:e=>{o.update(()=>{const t=b.$getSelection();b.$isRangeSelection(t)&&ne(t,"normal"===e?()=>b.$createParagraphNode():()=>n.$createHeadingNode(e))})},headingSelectionMap:h}),e.jsx(ye,{})]}),K.map(({id:t,label:i,icon:n})=>t===F.Divider?e.jsx(ye,{},t):e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[t]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(t),disabled:!!r[t],children:n})}),e.jsx(xe,{side:"bottom",children:i})]},t)),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(Ae,{blockType:p}),e.jsx(ye,{})]}),e.jsx(Te,{}),e.jsx(Ne,{onAction:C,selectionMap:c}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(_e,{onAction:C,alignmentSelectionMap:c}),e.jsx(ye,{})]}),e.jsxs(pe,{delayDuration:700,children:[e.jsx(me,{asChild:!0,children:e.jsx(he,{variant:c[F.Link]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>C(F.Link),disabled:!!r[F.Link],children:e.jsx(T.IoIosLink,{})})}),e.jsx(xe,{side:"bottom",children:"Link"})]}),a&&e.jsx(we,{linkUrl:x,setLinkUrl:N,removeLink:_,onConfirm:e=>{o.dispatchCommand(v.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),N(e),l(!1)},onCancel:()=>{N(""),l(!1)}}),e.jsx(He,{}),e.jsx(Qe,{}),e.jsx(Ye,{value:t})]})};function et(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const i=document.createElement("div"),n=b.$getRoot().getChildren();for(let o=0;o<n.length;o++)tt(e,n[o],i,t);return i.innerHTML}function tt(e,t,i,n=null){let o=null===n||t.isSelected(n);const r=b.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==n){let e=b.$cloneWithProperties(t);e=b.$isTextNode(e)&&null!==n?function(e,t){const i=e.getStartEndPoints();if(t.isSelected(e)&&!b.$isTokenOrSegmented(t)&&null!==i){const[n,o]=i,r=e.isBackward(),s=n.getNode(),a=o.getNode(),l=t.is(s),c=t.is(a);if(l||c){const[i,n]=b.$getCharacterOffsets(e),o=s.is(a),l=t.is(r?a:s),c=t.is(r?s:a);let d,u=0;o?(u=i>n?n:i,d=i>n?i:n):l?(u=r?n:i,d=void 0):c&&(u=0,d=r?i:n),t.__text=t.__text.slice(u,d)}}return t}(n,e):e,s=e}const a=b.$isElementNode(s)?s.getChildren():[],l=b.getRegisteredNode(e,s.getType());let c;c=l&&void 0!==l.exportDOM?l.exportDOM(e,s):s.exportDOM(e);const{element:d,after:u}=c;if(!d)return!1;const h=document.createDocumentFragment();for(let i=0;i<a.length;i++){const r=a[i],s=tt(e,r,h,n);!o&&b.$isElementNode(t)&&s&&t.extractWithChild(r,n,"html")&&(o=!0)}if(o&&!r){if((b.isHTMLElement(d)||b.isDocumentFragment(d))&&d.append(h),i.append(d),u){const e=u.call(s,d);e&&(b.isDocumentFragment(d)?d.replaceChildren(e):d.replaceWith(e))}}else i.append(h);return o}const it=new Set(["STYLE","SCRIPT"]);function nt(e,t,i,n,o=new Map,r){let s=[];if(it.has(e.nodeName))return s;let a=null;const l=function(e,t){const{nodeName:i}=e,n=t._htmlConversions.get(i.toLowerCase());let o=null;if(void 0!==n)for(const t of n){const i=t(e);null!==i&&(null===o||(o.priority||0)<=(i.priority||0))&&(o=i)}return null!==o?o.conversion:null}(e,t),c=l?l(e):null;let d=null;if(null!==c){d=c.after;const t=c.node;if(a=Array.isArray(t)?t[t.length-1]:t,null!==a){for(const[,e]of o)if(a=e(a,r),!a)break;a&&s.push(...Array.isArray(t)?t:[a])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const u=e.childNodes;let h=[];const g=(null==a||!b.$isRootOrShadowRoot(a))&&(null!=a&&b.$isBlockElementNode(a)||n);for(let e=0;e<u.length;e++)h.push(...nt(u[e],t,i,g,new Map(o),a));return null!=d&&(h=d(h)),b.isBlockDomNode(e)&&(h=function(e,t,i){const n=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(b.$isBlockElementNode(s))n&&!s.getFormat()&&s.setFormat(n),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&b.$isBlockElementNode(t[e+1])){const e=i();e.setFormat(n),e.append(...r),o.push(e),r=[]}}return o}(e,h,g?()=>{const e=new b.ArtificialNode__DO_NOT_USE;return i.push(e),e}:b.$createParagraphNode)),null==a?h.length>0?s=s.concat(h):b.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(b.isInlineDomNode(e.nextSibling)&&b.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(b.$createLineBreakNode())):b.$isElementNode(a)&&a.append(...h),s}function ot({value:t,onChange:n}){const[o]=f.useLexicalComposerContext(),[r,s]=i.useState(!0);return i.useEffect(()=>{t&&r&&(s(!1),o.update(()=>{if(et(o)!==t){b.$getRoot().clear();const e=(new DOMParser).parseFromString(t,"text/html"),i=function(e,t){const i=b.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let n=[];const o=[];for(const t of i)if(!it.has(t.nodeName)){const i=nt(t,e,o,!1);null!==i&&(n=n.concat(i))}return function(e){for(const t of e)t.getNextSibling()instanceof b.ArtificialNode__DO_NOT_USE&&t.insertAfter(b.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const i of e)t.insertBefore(i);t.remove()}}(o),n}(o,e);b.$insertNodes(i)}}))},[o,t,r]),i.useEffect(()=>{s(!0)},[t]),e.jsx($.OnChangePlugin,{onChange:e=>{e.read(()=>{n(et(o))})}})}const rt=({id:e})=>new ut({id:e}),st="data-lexical-youtube",at="315px",lt="560px",ct=e=>`https://www.youtube-nocookie.com/embed/${e}`,dt=e=>{const t=e?.getAttribute(st);if(!t)return null;return{node:rt({id:t})}};class ut extends b.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new ut({id:e.__id,key:e.getKey()})}static importJSON(e){return rt({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e.jsx("iframe",{height:at,width:lt,src:ct(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(st,this.__id),e.setAttribute("height",at),e.setAttribute("width",lt),e.setAttribute("src",ct(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:dt,priority:0})}}}const ht={text:{bold:"font-bold",underline:"underline",italic:"italic",strikethrough:"line-through",underlineStrikethrough:"underline line-through",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize",code:"bg-gray-100 border border-gray-300 px-1 rounded text-sm font-mono text-black"},paragraph:"mb-2",list:{ul:"list-disc list-inside pl-6",ol:"list-decimal list-inside pl-6",listitem:"mb-1"},quote:"border-l-4 border-gray-400 pl-4 italic text-gray-800 bg-gray-50 py-2 rounded-r",link:"text-blue-600 underline hover:text-blue-800"},gt=i.memo(function({name:u,value:h,onChange:g,placeholder:p,width:m=null,height:x=null}){const f=i.useMemo(()=>({namespace:u,theme:ht,onError:e=>{console.error("Lexical error:",e)},nodes:[n.HeadingNode,o.CodeHighlightNode,o.CodeNode,d.ListNode,d.ListItemNode,n.QuoteNode,v.LinkNode,Me,ut,Ge]}),[u]);return e.jsx("div",{className:"lexical-text-editor border-[1px] rounded-lg pb-2 scrollbar-thin",style:{width:m||"",maxWidth:m?"":"1090px",height:x||"500px"},children:e.jsxs(t.LexicalComposer,{initialConfig:f,children:[e.jsx("div",{className:"px-2",children:e.jsx(Ze,{value:h})}),e.jsx("div",{className:"relative",children:e.jsx(r.RichTextPlugin,{contentEditable:e.jsx(s.ContentEditable,{className:"text-start w-full h-full text-[14px] p-[8px] overflow-auto outline-0"}),placeholder:e.jsx("div",{className:"absolute text-[#999] top-[8px] left-[10px] text-[14px]",children:p||"Some Text"}),ErrorBoundary:a.LexicalErrorBoundary})}),e.jsx(l.HistoryPlugin,{}),e.jsx(c.ListPlugin,{}),e.jsx(R.LinkPlugin,{}),e.jsx(ot,{value:h,onChange:g})]})})});exports.LexicalTextEditor=gt;
|
|
1
|
+
"use strict";var e,t,i=require("react/jsx-runtime"),n=require("@lexical/react/LexicalComposer"),o=require("react"),r=require("@lexical/rich-text"),s=require("@lexical/code"),l=require("@lexical/react/LexicalRichTextPlugin"),a=require("@lexical/react/LexicalContentEditable"),c=require("@lexical/react/LexicalErrorBoundary"),d=require("lexical"),u=require("@lexical/react/LexicalHistoryPlugin"),h=require("@lexical/react/LexicalListPlugin"),g=require("@lexical/list"),p=require("react-icons/rx"),m=require("react-icons/tb"),x=require("react-icons/bs"),f=require("react-icons/ai"),b=require("react-icons/io5"),N=require("react-icons/pi"),v=require("@lexical/react/LexicalComposerContext"),C=require("@lexical/link"),y=require("react-icons/hi2"),_=require("react-icons/io"),j=require("react-icons/md"),w=require("react-icons/bi"),k=require("react-color"),S=require("react-dom"),T=require("react-icons/lu"),E=require("react-icons/fa"),A=require("react-icons/vsc"),L=require("@lexical/react/LexicalLinkPlugin"),M=require("@lexical/react/LexicalOnChangePlugin");!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(e||(e={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(t||(t={}));const R=[{id:e.Lowercase,icon:i.jsx(p.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:e.Uppercase,icon:i.jsx(p.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:e.Capitalize,icon:i.jsx(p.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:e.Strikethrough,icon:i.jsx(f.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:e.Highlight,icon:i.jsx(N.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:e.Superscript,icon:i.jsx(x.BsSuperscript,{}),label:"Superscript"},{id:e.Subscript,icon:i.jsx(x.BsSubscript,{}),label:"Subscript"}],$=[{id:e.Bold,icon:i.jsx(m.TbBold,{}),label:"Bold"},{id:e.Italics,icon:i.jsx(m.TbItalic,{}),label:"Italics"},{id:e.Underline,icon:i.jsx(m.TbUnderline,{}),label:"Underline"},{id:e.Divider},{id:e.Quote,icon:i.jsx(x.BsChatSquareQuote,{}),label:"Quote"},{id:e.Code,icon:i.jsx(b.IoCodeSlashOutline,{}),label:"Code"}],O=[{id:e.Undo,icon:i.jsx(x.BsArrowCounterclockwise,{}),label:"Undo"},{id:e.Redo,icon:i.jsx(x.BsArrowClockwise,{}),label:"Redo"},{id:e.Divider}],D=[{id:e.LeftAlign,icon:i.jsx(x.BsJustifyLeft,{}),label:"Left Align"},{id:e.CenterAlign,icon:i.jsx(x.BsTextCenter,{}),label:"Center Align"},{id:e.RightAlign,icon:i.jsx(x.BsJustifyRight,{}),label:"Right Align"},{id:e.JustifyAlign,icon:i.jsx(x.BsJustify,{}),label:"Justify Align"}],F=[{id:"normal",label:"Normal",icon:i.jsx(x.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:i.jsx(x.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:i.jsx(x.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:i.jsx(x.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:i.jsx(x.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:i.jsx(x.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:i.jsx(x.BsTypeH6,{})}];function B(e,...t){const i=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of t)n.append("v",e);throw i.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${i.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const I=new Map;function H(e){let t=I.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const i=e.split(";");for(const e of i)if(""!==e){const[i,n]=e.split(/:([^]+)/);i&&n&&(t[i.trim()]=n.trim())}return t}(e),I.set(e,t)),t}function P(e,t){(d.$isRangeSelection(e)?e.isCollapsed():d.$isTextNode(e)||d.$isElementNode(e))||B(280);const i=H(d.$isRangeSelection(e)?e.style:d.$isTextNode(e)?e.getStyle():e.getTextStyle()),n=Object.entries(t).reduce((t,[n,o])=>("function"==typeof o?t[n]=o(i[n],e):null===o?delete t[n]:t[n]=o,t),{...i}),o=function(e){let t="";for(const i in e)i&&(t+=`${i}: ${e[i]};`);return t}(n);d.$isRangeSelection(e)||d.$isTextNode(e)?e.setStyle(o):e.setTextStyle(o),I.set(o,n)}function U(e,t){if(d.$isRangeSelection(e)&&e.isCollapsed()){P(e,t);const i=e.anchor.getNode();d.$isElementNode(i)&&i.isEmpty()&&P(i,t)}!function(e){const t=d.$getSelection();if(!t)return;const i=new Map,n=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(d.$isRangeSelection(t))for(const e of d.$caretRangeFromSelection(t).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!d.$isTextNode(t)||!t.canHaveFormat())continue;const[i,o]=n(t);o!==i&&(d.$isTokenOrSegmented(t)||0===i&&o===t.getTextContentSize()?e(t):e(t.splitText(i,o)[0===i?0:1]))}d.$isRangeSelection(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:i}=e,{key:n,offset:o,type:r}=t;t.set(i.key,i.offset,i.type),i.set(n,o,r)}}(t)}(e=>{P(e,t)})}function q(e,t){const i=e.getFormatType(),n=e.getIndent();i!==t.getFormatType()&&t.setFormat(i),n!==t.getIndent()&&t.setIndent(n)}function z(e){return e.getNode().isAttached()}function K(e){let t=e;for(;null!==t&&!d.$isRootOrShadowRoot(t);){const e=t.getLatest(),i=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=i}}function W(e,t,i=null){const n=e.getStartEndPoints(),o=n?n[0]:null,r=e.getNodes(),s=r.length;if(null!==o&&(0===s||1===s&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),n=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),n.forEach(e=>r.append(e)),i&&(r=i.append(r)),void e.replace(r)}let l=null,a=[];for(let n=0;n<s;n++){const o=r[n];d.$isRootOrShadowRoot(o)?(J(e,a,a.length,t,i),a=[],l=o):null===l||null!==l&&d.$hasAncestor(o,l)?a.push(o):(J(e,a,a.length,t,i),a=[o])}J(e,a,a.length,t,i)}function J(e,t,i,n,o=null){if(0===t.length)return;const r=t[0],s=new Map,l=[];let a=d.$isElementNode(r)?r:r.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let c=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,c=!0;break}if(a=a.getParentOrThrow(),d.$isRootOrShadowRoot(a))break}const u=new Set;for(let e=0;e<i;e++){const i=t[e];d.$isElementNode(i)&&0===i.getChildrenSize()&&u.add(i.getKey())}const h=new Set;for(let e=0;e<i;e++){const i=t[e];let o=i.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&d.$isLeafNode(i)&&!h.has(i.getKey())){const e=o.getKey();if(void 0===s.get(e)){const t=n();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),l.push(t),s.set(e,t),o.getChildren().forEach(e=>{t.append(e),h.add(e.getKey()),d.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>h.add(e))}),K(o)}}else if(u.has(i.getKey())){d.$isElementNode(i)||B(179);const e=n();e.setFormat(i.getFormatType()),e.setIndent(i.getIndent()),l.push(e),i.remove(!0)}}if(null!==o)for(let e=0;e<l.length;e++){const t=l[e];o.append(t)}let g=null;if(d.$isRootOrShadowRoot(a))if(c)if(null!==o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(d.$isElementNode(e)&&(a=e),null===e)if(o)a.append(o);else for(let e=0;e<l.length;e++){const t=l[e];a.append(t),g=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<l.length;t++){const i=l[t];e.insertBefore(i),g=i}}else if(o)a.insertAfter(o);else for(let e=l.length-1;e>=0;e--){const t=l[e];a.insertAfter(t),g=t}const p=d.$getPreviousSelection();d.$isRangeSelection(p)&&z(p.anchor)&&z(p.focus)?d.$setSelection(p.clone()):null!==g?g.selectEnd():e.dirty=!0}function X(e,t,i){const n=H(e.getStyle());return null!==n&&n[t]||i}function G(e,t,i=""){let n=null;const o=e.getNodes(),r=e.anchor,s=e.focus,l=e.isBackward(),a=l?s.offset:r.offset,c=l?s.getNode():r.getNode();if(d.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const i=H(e.style);if(null!==i&&t in i)return i[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==a||!r.is(c))&&d.$isTextNode(r)){const e=X(r,t,i);if(null===n)n=e;else if(n!==e){n="";break}}}return null===n?i:n}const Q="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Y=Q&&"documentMode"in document?document.documentMode:null;function V(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Z({open:e,onOpenChange:t,children:n}){const r=o.useRef(null),s=o.useRef(null);return o.useEffect(()=>{function i(e){r.current?.contains(e.target)||s.current?.contains(e.target)||t(!1)}return e&&document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[e,t]),i.jsx("div",{className:"popover-root",children:o.Children.map(n,e=>e&&"object"==typeof e?e.type===ee?o.cloneElement(e,{triggerRef:r}):e.type===te?o.cloneElement(e,{contentRef:s}):e:e)})}function ee({children:e,triggerRef:t}){return i.jsx("div",{className:"popover-trigger",ref:t,children:e})}function te({open:e,align:t="start",children:n,contentRef:o}){return e?i.jsx("div",{ref:o,className:`popover-content align-${t}`,children:n}):null}function ie({onAction:e,selectionMap:t}){const[n,r]=o.useState(!1),s=o.useRef(null),l=o.useRef(null);return i.jsxs(Z,{open:n,onOpenChange:r,children:[i.jsx(ee,{triggerRef:s,children:i.jsxs("button",{className:"lexical-btn heading-trigger "+(n?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[i.jsx("span",{children:"Aa"}),i.jsx(y.HiChevronDown,{className:"chevron "+(n?"rotated":"")})]})}),i.jsx(te,{open:n,align:"start",onClose:()=>r(!1),contentRef:l,children:i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:R.map(({id:n,label:o,icon:s})=>i.jsxs("button",{className:"lexical-btn "+(t[n]?"toolbar-active":"toolbar"),onClick:()=>{e(n),r(!1)},style:{minWidth:130},children:[s,i.jsx("span",{className:"label",children:o})]},n))})})]})}function ne(){return i.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function oe({updateHeading:e,headingSelectionMap:t}){const n=F.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return i.jsxs(Z,{open:r,onOpenChange:s,children:[i.jsx(ee,{triggerRef:l,children:i.jsxs("button",{className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:132},children:[n?.icon,i.jsx("span",{children:n?.label}),i.jsx(y.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),i.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:F.map(({id:n,label:o,icon:r})=>i.jsxs("button",{className:"lexical-btn "+(t[n]?"toolbar-active":"toolbar"),onClick:()=>{e(n),s(!1)},children:[r,i.jsx("span",{className:"label",children:o})]},n))})})]})}function re({linkUrl:e,setLinkUrl:t,onConfirm:n,onCancel:r,removeLink:s}){const[l,a]=o.useState(!1),c=o.useRef(null),d=o.useRef(null);return o.useEffect(()=>{"https://"===e&&a(!0)},[e]),o.useEffect(()=>{l&&d.current?.focus()},[l]),o.useEffect(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]),i.jsxs("div",{ref:c,className:"lexical-text-editor-link link-editor-container",children:[i.jsx("div",{className:"link-editor-input-wrapper",children:l?i.jsx("input",{ref:d,className:"link-editor-input",value:e,onChange:e=>t(e.target.value),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),n(e),a(!1)):"Escape"===t.key&&(t.preventDefault(),a(!1),r())}}):i.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:e})}),i.jsxs("div",{className:"link-editor-buttons",children:[i.jsx("button",{className:"lexical-btn heading-trigger toolbar",onClick:()=>{l?(n(e),a(!1)):a(!0)},children:l?i.jsx(j.MdCheck,{size:18}):i.jsx(x.BsPencilSquare,{size:14})}),i.jsx("button",{className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:i.jsx(w.BiUnlink,{size:14,style:{stroke:"black"}})})]})]})}function se({onAction:e,alignmentSelectionMap:t}){const n=D.find(e=>t[e.id]),[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);return i.jsxs(Z,{open:r,onOpenChange:s,children:[i.jsx(ee,{triggerRef:l,children:i.jsxs("button",{className:"lexical-btn heading-trigger "+(r?"toolbar-active":"toolbar"),onClick:()=>s(e=>!e),style:{minWidth:146},children:[n?.icon,i.jsx("span",{children:n?.label}),i.jsx(y.HiChevronDown,{className:"chevron "+(r?"rotated":"")})]})}),i.jsx(te,{open:r,align:"start",onClose:()=>s(!1),contentRef:a,children:i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:D.map(({id:n,label:o,icon:r})=>i.jsxs("button",{className:"lexical-btn "+(t[n]?"toolbar-active":"toolbar"),onClick:()=>{e(n),s(!1)},children:[r,i.jsx("span",{className:"label",children:o})]},n))})})]})}function le({color:e,onChange:t,icon:n}){const[r,s]=o.useState(!1),l=o.useRef(null),a=o.useRef(null);o.useEffect(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&l.current&&!l.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return i.jsxs("div",{className:"color-picker-wrapper",children:[i.jsx("button",{ref:l,className:`size-8 lexical-btn ${r?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:n}),r&&S.createPortal(i.jsx("div",{ref:a,className:"lexical-color-popover "+(r?"open":""),style:{top:l.current?.getBoundingClientRect().bottom,left:l.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:i.jsx(k.SketchPicker,{color:e,onChangeComplete:e=>{t(e.hex)}})}),document.body)]})}Q&&"InputEvent"in window&&!Y&&new window.InputEvent("input");const ae=({content:e,direction:t="top",delay:n=400,children:r})=>{const[s,l]=o.useState(!1),a=o.useRef(null);return i.jsxs("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{a.current=window.setTimeout(()=>{l(!0)},n)},onMouseLeave:()=>{a.current&&clearTimeout(a.current),l(!1)},children:[r,s&&i.jsx("div",{className:`Lexical-Tooltip-Tip ${t}`,children:e})]})};function ce(){const[e]=v.useLexicalComposerContext(),[{color:t,bgColor:n},r]=o.useState({color:"#000",bgColor:"#fff"}),s=()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=G(e,"color","#000"),i=G(e,"background","#fff");r({color:t,bgColor:i})}};o.useEffect(()=>V(e.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(s(),!1),1)),[e]);const l=({property:t,color:i})=>{e.update(()=>{const e=d.$getSelection();e&&U(e,{[t]:i})})};return i.jsxs(i.Fragment,{children:[i.jsx(ae,{content:"Font Color",direction:"bottom",children:i.jsx(le,{color:t,onChange:e=>{l({property:"color",color:e})},icon:i.jsx(f.AiOutlineFontColors,{})})}),i.jsx(ae,{content:"Background Color",direction:"bottom",children:i.jsx(le,{color:n,onChange:e=>{l({property:"background",color:e})},icon:i.jsx(f.AiOutlineBgColors,{})})})]})}function de({blockType:e}){const[t]=v.useLexicalComposerContext();return i.jsxs(i.Fragment,{children:[i.jsx(ae,{content:"Ordered list",direction:"bottom",children:i.jsx("button",{className:`size-8 lexical-btn ${"ol"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===e?t.dispatchCommand(g.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(g.INSERT_ORDERED_LIST_COMMAND,void 0)},children:i.jsx(x.BsListOl,{})})}),i.jsx(ae,{content:"Unordered list",direction:"bottom",children:i.jsx("button",{className:`size-8 lexical-btn ${"ul"===e?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===e?t.dispatchCommand(g.REMOVE_LIST_COMMAND,void 0):t.dispatchCommand(g.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:i.jsx(x.BsListUl,{})})})]})}const ue=({src:e,altText:t,nodeKey:n,width:r,height:s,maxWidth:l})=>{const[a]=v.useLexicalComposerContext(),c=o.useRef(null),u=o.useRef(null),h=o.useRef(null),g=e=>{if(!h.current||!c.current)return;const t=e.clientX-h.current.x,i=Math.min(l,Math.max(50,h.current.width+t)),n=i*c.current.ratio;c.current.width=i,c.current.height=n;const o=u.current?.querySelector("img");o&&(o.style.width=i+"px",o.style.height=n+"px")},p=()=>{if(!c.current)return;const{width:e,height:t}=c.current;a.update(()=>{const i=d.$getNodeByKey(n);i&&"function"==typeof i.updateDimensions&&i.updateDimensions(e,t)}),c.current=null,h.current=null,window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",p)};return i.jsxs("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:l},children:[i.jsx("img",{src:e,alt:t,width:"inherit"===r?void 0:r,height:"inherit"===s?void 0:s,style:{maxWidth:"100%",display:"block"}}),i.jsx("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=u.current?.querySelector("img");if(!t)return;const i=t.getBoundingClientRect().width,n=t.naturalHeight/t.naturalWidth,o=i*n;h.current={x:e.clientX,y:e.clientY,width:i,height:o},c.current={width:i,height:o,ratio:n},window.addEventListener("mousemove",g),window.addEventListener("mouseup",p)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},he=e=>d.$applyNodeReplacement(new pe(e)),ge=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:i}=e;let n,o;e.width&&(n=e.width),e.height&&(o=e.height);const r=e.style;if((!n||0===n)&&r.width){const e=parseInt(r.width);isNaN(e)||(n=e)}if((!o||0===o)&&r.height){const e=parseInt(r.height);isNaN(e)||(o=e)}return{node:he({src:t,altText:i,width:n,height:o})}};class pe extends d.DecoratorNode{constructor({src:e="",altText:t="",maxWidth:i=1080,width:n,height:o,key:r}={}){super(r),this.__altText=t,this.__src=e,this.__maxWidth=i,this.__height=o,this.__width=n}static getType(){return"image"}static clone(e){return new pe({altText:e.__altText,src:e.__src,height:e.__height,width:e.__width,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}exportDOM(){const e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__altText),this.__width&&"inherit"!==this.__width&&e.setAttribute("width",String(this.__width)),this.__height&&"inherit"!==this.__height&&e.setAttribute("height",String(this.__height)),{element:e}}static importDOM(){return{img:()=>({conversion:ge,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 pe({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const i=this.getWritable();i.__width=e,i.__height=t}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}decorate(){return i.jsx(ue,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function me({open:e,onClose:t,forPreview:n=!1,children:r}){const s=o.useRef(null);return o.useEffect(()=>{if(!e)return;const i=e=>{s.current&&!s.current.contains(e.target)&&t()},n=e=>{"Escape"===e.key&&t()};return document.addEventListener("mousedown",i),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",n)}},[e,t]),e?i.jsx("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:i.jsxs("div",{ref:s,className:"lte-dialog "+(n?"preview":""),children:[i.jsx("button",{className:"lte-dialog-close",onClick:t,children:"×"}),r]})}):null}function xe(){const[e]=v.useLexicalComposerContext(),t=o.useRef(null),[n,r]=o.useState(!1),[s,l]=o.useState(""),[a,c]=o.useState(""),[u,h]=o.useState();return i.jsxs("div",{className:"lexical-text-editor-dialog",children:[i.jsx("input",{type:"file",ref:t,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&h(t),e.target.value=""}}),i.jsx("button",{className:`size-8 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>r(e=>!e),children:i.jsx(b.IoImageOutline,{size:18})}),i.jsxs(me,{open:n,onClose:()=>r(!1),children:[i.jsx("div",{className:"lte-dialog-header",children:"Add Image"}),i.jsxs("div",{className:"lte-dialog-body",children:[i.jsx("input",{className:"lte-input",placeholder:"Alt text",value:a,onChange:e=>c(e.target.value)}),i.jsx("input",{className:"lte-input",placeholder:"Add image by URL",value:s,onChange:e=>l(e.target.value)}),i.jsx("div",{className:"lte-divider",children:i.jsx("span",{children:"or"})}),i.jsxs("button",{className:"lexical-btn heading-trigger toolbar-active",onClick:()=>t.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[i.jsx(T.LuUpload,{size:20}),i.jsx("span",{children:"Upload Image"})]}),u&&i.jsx("div",{className:"lte-file-name",children:u.name})]}),i.jsx("div",{className:"lte-dialog-footer",children:i.jsx("button",{className:"lte-primary-btn",disabled:!s&&!u,onClick:()=>{let t=s;u&&(t=URL.createObjectURL(u)),e.update(()=>{const e=he({src:t,altText:a});d.$insertNodes([e])}),h(void 0),c(""),l(""),r(!1)},children:"Add Image"})})]})]})}const fe=({id:e,provider:t})=>new je({id:e,provider:t}),be="data-lexical-video",Ne="data-provider",ve="315px",Ce="560px",ye=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,_e=e=>{const t=e?.getAttribute(be),i=e?.getAttribute(Ne)??"youtube";if(!t)return null;return{node:fe({id:t,provider:i})}};class je extends d.DecoratorNode{constructor({id:e,provider:t,key:i}){super(i),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new je({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return fe({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return i.jsx("iframe",{height:ve,width:Ce,src:ye(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(be,this.__id),e.setAttribute(Ne,this.__provider),e.setAttribute("height",ve),e.setAttribute("width",Ce),e.setAttribute("src",ye(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:_e,priority:0})}}}function we(){const[e,t]=o.useState(!1),[n,r]=o.useState(!1),[s,l]=o.useState(""),[a]=v.useLexicalComposerContext();return o.useEffect(()=>{e||(l(""),r(!1))},[e]),i.jsxs("div",{className:"lexical-text-editor-dialog",children:[i.jsx("button",{type:"button",className:`size-8 lexical-btn ${e?"toolbarActive":"toolbar"} icon`,onClick:()=>t(!0),children:i.jsx(E.FaYoutube,{size:18,color:"red"})}),i.jsxs(me,{open:e,onClose:()=>t(!1),children:[i.jsx("div",{className:"lte-dialog-header",children:"Embed Video"}),i.jsxs("div",{className:"lte-dialog-body",children:[i.jsx("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:s,onChange:e=>l(e.target.value)}),n&&i.jsx("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),i.jsx("div",{className:"lte-dialog-footer",children:i.jsx("button",{className:"lte-primary-btn",disabled:!s,onClick:()=>{if(!s)return;let e=null,i=null;const n=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(s);n&&11===n[2]?.length&&(e="youtube",i=n[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(s);o&&o[1]&&(e="drive",i=o[1]),i&&e?(a.update(()=>{const t=fe({id:i,provider:e});d.$insertNodes([t])}),l(""),r(!1),t(!1)):r(!0)},children:"Embed"})})]})]})}function ke({value:e}){return i.jsx("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:e}})}function Se({value:e,triggerLabel:t="Preview"}){const[n,r]=o.useState(!1);return console.log(e),i.jsxs("div",{className:"lexical-text-editor-dialog",children:[i.jsxs("button",{className:"lexical-btn heading-trigger "+(n?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[i.jsx(A.VscPreview,{size:18}),i.jsx("span",{children:t})]}),i.jsxs(me,{open:n,onClose:()=>r(!1),forPreview:!0,children:[i.jsx("div",{className:"lte-dialog-header",children:"Content Preview"}),i.jsxs("div",{className:"lte-preview-container",children:[i.jsx("div",{className:"lte-preview-title",children:"CONTENT"}),i.jsx(ke,{value:e})]})]})]})}const Te=({value:n})=>{const[s]=v.useLexicalComposerContext(),[l,a]=o.useState({[e.Undo]:!0,[e.Redo]:!0}),[c,u]=o.useState(!1),[h,p]=o.useState({[e.LeftAlign]:!0}),[m,x]=o.useState({[t.Normal]:!0}),[f,b]=o.useState("paragraph"),[N,y]=o.useState("https://");let j=!0;const w=()=>{if(j){const e=s.getRootElement();e&&(e.scrollTop=0,j=!1)}const i=d.$getSelection();if(d.$isRangeSelection(i)){const n={[e.Bold]:i.hasFormat("bold"),[e.Italics]:i.hasFormat("italic"),[e.Underline]:i.hasFormat("underline"),[e.Uppercase]:i.hasFormat("uppercase"),[e.Lowercase]:i.hasFormat("lowercase"),[e.Capitalize]:i.hasFormat("capitalize"),[e.Strikethrough]:i.hasFormat("strikethrough"),[e.Superscript]:i.hasFormat("superscript"),[e.Subscript]:i.hasFormat("subscript"),[e.Code]:i.hasFormat("code"),[e.Highlight]:i.hasFormat("highlight")};p(n);const o=i.anchor.getNode(),l="root"===o.getKey()?o:o.getTopLevelElementOrThrow(),a=l.getKey();if(!s.getElementByKey(a))return;if(g.$isListNode(l)){const e=function(e,t){let i=e;for(;null!=i;){if(i instanceof t)return i;i=i.getParent()}return null}(o,g.ListNode),t=e?e.getTag():l.getTag();b(t)}else if("paragraph"===l.getType()||r.$isHeadingNode(l)){let e=null;r.$isHeadingNode(l)&&(e=l.getTag());const i={[t.H1]:"h1"===e,[t.H2]:"h2"===e,[t.H3]:"h3"===e,[t.H4]:"h4"===e,[t.H5]:"h5"===e,[t.H6]:"h6"===e,[t.Normal]:"paragraph"===l.getType()};b(l.getType()),x(i)}else b(l.getType());const c=(d.$isElementNode(o)?o:l).getFormat();p(t=>({...t,[e.LeftAlign]:0===c||1===c,[e.CenterAlign]:2===c,[e.RightAlign]:3===c,[e.JustifyAlign]:4===c})),"quote"===l.getType()?p(t=>({...t,[e.Quote]:!0})):p(t=>({...t,[e.Quote]:!1}));const h=i.anchor.getNode(),m=h.getParent();C.$isLinkNode(m)?(p(t=>({...t,[e.Link]:!0})),y(m.getURL()),u(!0)):C.$isLinkNode(h)?(p(t=>({...t,[e.Link]:!0})),y(h.getURL()),u(!0)):(p(t=>({...t,[e.Link]:!1})),y("https://"),u(!1))}};o.useEffect(()=>V(s.registerUpdateListener(({editorState:e})=>{e.read(()=>{w()})}),s.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(w(),!1),1),s.registerCommand(d.CAN_UNDO_COMMAND,e=>(a(t=>({...t,undo:!e})),!1),1),s.registerCommand(d.CAN_REDO_COMMAND,e=>(a(t=>({...t,redo:!e})),!1),1)),[]);const k=t=>{switch(t){case e.Bold:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"bold");break;case e.Italics:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"italic");break;case e.Underline:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"underline");break;case e.Lowercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"lowercase");break;case e.Uppercase:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"uppercase");break;case e.Capitalize:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"capitalize");break;case e.Strikethrough:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"strikethrough");break;case e.Superscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"superscript");break;case e.Subscript:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"subscript");break;case e.Highlight:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"highlight");break;case e.Code:s.dispatchCommand(d.FORMAT_TEXT_COMMAND,"code");break;case e.Quote:s.update(()=>{const e=d.$getSelection();if(d.$isRangeSelection(e)){const t=e.anchor.getNode().getParent();t&&r.$isQuoteNode(t)?function(e,t,i=q){if(null===e)return;const n=e.getStartEndPoints(),o=new Map;let r=null;if(n){const[e,t]=n;r=d.$createRangeSelection(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const i=d.$findMatchingParent(e.getNode(),d.INTERNAL_$isBlock),s=d.$findMatchingParent(t.getNode(),d.INTERNAL_$isBlock);d.$isElementNode(i)&&o.set(i.getKey(),i),d.$isElementNode(s)&&o.set(s.getKey(),s)}for(const t of e.getNodes())if(d.$isElementNode(t)&&d.INTERNAL_$isBlock(t))o.set(t.getKey(),t);else if(null===n){const e=d.$findMatchingParent(t,d.INTERNAL_$isBlock);d.$isElementNode(e)&&o.set(e.getKey(),e)}for(const[e,n]of o){const o=t();i(n,o),n.replace(o,!0),r&&(e===r.anchor.key&&r.anchor.set(o.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(o.getKey(),r.focus.offset,r.focus.type))}r&&e.is(d.$getSelection())&&d.$setSelection(r)}(e,()=>d.$createParagraphNode()):W(e,()=>r.$createQuoteNode())}});break;case e.Link:S(),u(!0);break;case e.LeftAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"left");break;case e.RightAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"right");break;case e.CenterAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"center");break;case e.JustifyAlign:s.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,"justify");break;case e.Undo:s.dispatchCommand(d.UNDO_COMMAND,void 0);break;case e.Redo:s.dispatchCommand(d.REDO_COMMAND,void 0)}},S=o.useCallback(()=>{s.update(()=>{const e=d.$getSelection();d.$isRangeSelection(e)&&!e.isCollapsed()&&(c?s.dispatchCommand(C.TOGGLE_LINK_COMMAND,null):""!==N&&s.dispatchCommand(C.TOGGLE_LINK_COMMAND,N))})},[s,c,N]),T=o.useCallback(()=>{y(""),s.dispatchCommand(C.TOGGLE_LINK_COMMAND,null),u(!1)},[s]);return i.jsxs("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[O.map(({id:t,label:n,icon:o})=>t===e.Divider?i.jsx(ne,{},t):i.jsx(ae,{content:n,direction:"bottom",children:i.jsx("button",{className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),disabled:!!l[t],children:o})},n)),i.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[i.jsx(oe,{updateHeading:e=>{s.update(()=>{const t=d.$getSelection();d.$isRangeSelection(t)&&W(t,"normal"===e?()=>d.$createParagraphNode():()=>r.$createHeadingNode(e))})},headingSelectionMap:m}),i.jsx(ne,{})]}),$.map(({id:t,label:n,icon:o})=>t===e.Divider?i.jsx(ne,{},t):i.jsx(ae,{content:n,direction:"bottom",children:i.jsx("button",{className:`size-8 lexical-btn ${h[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(t),children:o})},t)),i.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[i.jsx(de,{blockType:f}),i.jsx(ne,{})]}),i.jsx(ce,{}),i.jsx(ie,{onAction:k,selectionMap:h}),i.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[i.jsx(se,{onAction:k,alignmentSelectionMap:h}),i.jsx(ne,{})]}),i.jsx(ae,{content:"Link",direction:"bottom",children:i.jsx("button",{className:`size-8 lexical-btn ${h[e.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>k(e.Link),disabled:!!l[e.Link],children:i.jsx(_.IoIosLink,{})})}),c&&i.jsx(re,{linkUrl:N,setLinkUrl:y,removeLink:T,onConfirm:e=>{s.dispatchCommand(C.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),y(e),u(!1)},onCancel:()=>{y(""),u(!1)}}),i.jsx(xe,{}),i.jsx(we,{}),i.jsx(Se,{value:n})]})};function Ee(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const i=document.createElement("div"),n=d.$getRoot().getChildren();for(let o=0;o<n.length;o++)Ae(e,n[o],i,t);return i.innerHTML}function Ae(e,t,i,n=null){let o=null===n||t.isSelected(n);const r=d.$isElementNode(t)&&t.excludeFromCopy("html");let s=t;if(null!==n){let e=d.$cloneWithProperties(t);e=d.$isTextNode(e)&&null!==n?function(e,t){const i=e.getStartEndPoints();if(t.isSelected(e)&&!d.$isTokenOrSegmented(t)&&null!==i){const[n,o]=i,r=e.isBackward(),s=n.getNode(),l=o.getNode(),a=t.is(s),c=t.is(l);if(a||c){const[i,n]=d.$getCharacterOffsets(e),o=s.is(l),a=t.is(r?l:s),c=t.is(r?s:l);let u,h=0;o?(h=i>n?n:i,u=i>n?i:n):a?(h=r?n:i,u=void 0):c&&(h=0,u=r?i:n),t.__text=t.__text.slice(h,u)}}return t}(n,e):e,s=e}const l=d.$isElementNode(s)?s.getChildren():[],a=d.getRegisteredNode(e,s.getType());let c;c=a&&void 0!==a.exportDOM?a.exportDOM(e,s):s.exportDOM(e);const{element:u,after:h}=c;if(!u)return!1;const g=document.createDocumentFragment();for(let i=0;i<l.length;i++){const r=l[i],s=Ae(e,r,g,n);!o&&d.$isElementNode(t)&&s&&t.extractWithChild(r,n,"html")&&(o=!0)}if(o&&!r){if((d.isHTMLElement(u)||d.isDocumentFragment(u))&&u.append(g),i.append(u),h){const e=h.call(s,u);e&&(d.isDocumentFragment(u)?u.replaceChildren(e):u.replaceWith(e))}}else i.append(g);return o}const Le=new Set(["STYLE","SCRIPT"]);function Me(e,t,i,n,o=new Map,r){let s=[];if(Le.has(e.nodeName))return s;let l=null;const a=function(e,t){const{nodeName:i}=e,n=t._htmlConversions.get(i.toLowerCase());let o=null;if(void 0!==n)for(const t of n){const i=t(e);null!==i&&(null===o||(o.priority||0)<=(i.priority||0))&&(o=i)}return null!==o?o.conversion:null}(e,t),c=a?a(e):null;let u=null;if(null!==c){u=c.after;const t=c.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of o)if(l=e(l,r),!l)break;l&&s.push(...Array.isArray(t)?t:[l])}null!=c.forChild&&o.set(e.nodeName,c.forChild)}const h=e.childNodes;let g=[];const p=(null==l||!d.$isRootOrShadowRoot(l))&&(null!=l&&d.$isBlockElementNode(l)||n);for(let e=0;e<h.length;e++)g.push(...Me(h[e],t,i,p,new Map(o),l));return null!=u&&(g=u(g)),d.isBlockDomNode(e)&&(g=function(e,t,i){const n=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(d.$isBlockElementNode(s))n&&!s.getFormat()&&s.setFormat(n),o.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&d.$isBlockElementNode(t[e+1])){const e=i();e.setFormat(n),e.append(...r),o.push(e),r=[]}}return o}(e,g,p?()=>{const e=new d.ArtificialNode__DO_NOT_USE;return i.push(e),e}:d.$createParagraphNode)),null==l?g.length>0?s=s.concat(g):d.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(d.isInlineDomNode(e.nextSibling)&&d.isInlineDomNode(e.previousSibling))}(e)&&(s=s.concat(d.$createLineBreakNode())):d.$isElementNode(l)&&l.append(...g),s}function Re({value:e,onChange:t}){const[n]=v.useLexicalComposerContext(),[r,s]=o.useState(!0);return o.useEffect(()=>{e&&r&&(s(!1),n.update(()=>{if(Ee(n)!==e){d.$getRoot().clear();const t=(new DOMParser).parseFromString(e,"text/html"),i=function(e,t){const i=d.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let n=[];const o=[];for(const t of i)if(!Le.has(t.nodeName)){const i=Me(t,e,o,!1);null!==i&&(n=n.concat(i))}return function(e){for(const t of e)t.getNextSibling()instanceof d.ArtificialNode__DO_NOT_USE&&t.insertAfter(d.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const i of e)t.insertBefore(i);t.remove()}}(o),n}(n,t);d.$insertNodes(i)}}))},[n,e,r]),o.useEffect(()=>{s(!0)},[e]),i.jsx(M.OnChangePlugin,{onChange:e=>{e.read(()=>{t(Ee(n))})}})}const $e=({id:e})=>new He({id:e}),Oe="data-lexical-youtube",De="315px",Fe="560px",Be=e=>`https://www.youtube-nocookie.com/embed/${e}`,Ie=e=>{const t=e?.getAttribute(Oe);if(!t)return null;return{node:$e({id:t})}};class He extends d.DecoratorNode{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new He({id:e.__id,key:e.getKey()})}static importJSON(e){return $e({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return i.jsx("iframe",{height:De,width:Fe,src:Be(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Oe,this.__id),e.setAttribute("height",De),e.setAttribute("width",Fe),e.setAttribute("src",Be(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Ie,priority:0})}}}class Pe extends d.TextNode{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new Pe(e.__text,e.__key)}static importDOM(){const e=d.TextNode.importDOM();return{...e,span:()=>({conversion:Ue(e?.span),priority:1}),div:()=>({conversion:Ue(e?.div),priority:1}),p:()=>({conversion:Ue(e?.p),priority:1}),b:()=>({conversion:Ue(e?.b),priority:1}),strong:()=>({conversion:Ue(e?.strong),priority:1}),i:()=>({conversion:Ue(e?.i),priority:1}),em:()=>({conversion:Ue(e?.em),priority:1}),u:()=>({conversion:Ue(e?.u),priority:1}),s:()=>({conversion:Ue(e?.s),priority:1}),strike:()=>({conversion:Ue(e?.strike),priority:1}),code:()=>({conversion:Ue(e?.code),priority:1})}}static importJSON(e){return function(e=""){return d.$applyNodeReplacement(new Pe(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Ue(e){return t=>{const i=e?.(t);if(!i)return null;const n=i.conversion(t);if(!n)return n;const o=t.style,r=[];o.backgroundColor&&r.push(`background-color: ${o.backgroundColor}`),o.color&&r.push(`color: ${o.color}`),o.fontFamily&&r.push(`font-family: ${o.fontFamily}`),o.fontWeight&&r.push(`font-weight: ${o.fontWeight}`),o.fontSize&&r.push(`font-size: ${o.fontSize}`),o.fontStyle&&r.push(`font-style: ${o.fontStyle}`),o.textDecoration&&r.push(`text-decoration: ${o.textDecoration}`),o.whiteSpace&&r.push(`white-space: ${o.whiteSpace}`),o.textAlign&&r.push(`text-align: ${o.textAlign}`);const s=t.getAttribute("style");if(s){s.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!r.some(e=>e.startsWith(t))&&r.push(e.trim())})}return{...n,forChild:(e,t)=>{const i=n?.forChild??(e=>e),o=i(e,t);if(d.$isTextNode(o)&&r.length>0){const e=r.join("; ");return o.setStyle(e)}return o}}}}const qe={text:{bold:"lexical-bold",underline:"lexical-underline",italic:"lexical-italic",strikethrough:"lexical-strikethrough",underlineStrikethrough:"lexical-underline-strikethrough",uppercase:"lexical-uppercase",lowercase:"lexical-lowercase",capitalize:"lexical-capitalize",code:"lexical-code"},paragraph:"lexical-paragraph",list:{ul:"lexical-list-ul",ol:"lexical-list-ol",listitem:"lexical-listitem"},quote:"lexical-quote",link:"lexical-link"},ze=o.memo(function({name:e,value:t,onChange:p,placeholder:m,maxWidth:x=null,height:f=null}){const b=o.useMemo(()=>({namespace:e,theme:qe,onError:e=>{console.error("Lexical error:",e)},nodes:[Pe,{replace:d.TextNode,with:e=>new Pe(e.__text),withKlass:Pe},r.HeadingNode,s.CodeHighlightNode,s.CodeNode,g.ListNode,g.ListItemNode,r.QuoteNode,C.LinkNode,pe,He,je]}),[e]);return i.jsx("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:x||"1090px"},children:i.jsxs(n.LexicalComposer,{initialConfig:b,children:[i.jsx("div",{className:"lexical-toolbar-container",children:i.jsx(Te,{value:t})}),i.jsx("div",{className:"lexical-editor-inner",children:i.jsx(l.RichTextPlugin,{contentEditable:i.jsx(a.ContentEditable,{className:"lexical-content-editable",style:{height:f||"500px"}}),placeholder:i.jsx("div",{className:"lexical-placeholder",children:m||"Some Text"}),ErrorBoundary:c.LexicalErrorBoundary})}),i.jsx(u.HistoryPlugin,{}),i.jsx(h.ListPlugin,{}),i.jsx(L.LinkPlugin,{}),i.jsx(Re,{value:t,onChange:p})]})})});exports.LexicalTextEditor=ze;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|