@innoviatech/lexical-text-editor 2.0.5 → 2.0.7
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 +57 -10
- package/dist/components/ImageComponent.d.ts +1 -0
- package/dist/components/LexicalTextEditor.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- 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/nodes/ImageNode.d.ts +5 -1
- package/dist/plugins/ImagePlugin.d.ts +3 -1
- package/dist/plugins/ToolbarPlugin.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/ImageComponent.tsx +68 -2
- package/src/components/LexicalTextEditor.tsx +3 -2
- package/src/nodes/ImageNode.tsx +37 -0
- package/src/plugins/ImagePlugin.tsx +85 -14
- package/src/plugins/ToolbarPlugin.tsx +2 -2
- package/innoviatech-lexical-text-editor-2.0.4.tgz +0 -0
package/README.md
CHANGED
|
@@ -5,8 +5,11 @@ A powerful, customizable rich text editor component built with Lexical and React
|
|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
## What's New in v2.0
|
|
8
|
+
## What's New in v2.0.7
|
|
9
9
|
|
|
10
|
+
- **Image Upload Handler** — Custom upload endpoint support via `onImageUpload` prop
|
|
11
|
+
- **Image Captions** — Add and edit captions on images inline
|
|
12
|
+
- **Paste Image Support** — Paste images from clipboard with automatic upload
|
|
10
13
|
- **No Tailwind CSS Required** - Now uses raw CSS for styling
|
|
11
14
|
- **Reduced Dependencies** - Fewer peer dependencies to install
|
|
12
15
|
- **Simpler Setup** - Import CSS and start using immediately
|
|
@@ -21,7 +24,7 @@ A powerful, customizable rich text editor component built with Lexical and React
|
|
|
21
24
|
- 🎨 **Rich Text Editing** — Bold, italic, underline, strikethrough, code blocks
|
|
22
25
|
- 📝 **Text Formatting** — Headers, paragraphs, lists (bulleted & numbered), quotes
|
|
23
26
|
- 🔗 **Link Support** — Insert and edit hyperlinks
|
|
24
|
-
- 🖼️ **Media Embedding** — Images
|
|
27
|
+
- 🖼️ **Media Embedding** — Images (with captions & resize), YouTube videos
|
|
25
28
|
- 🎯 **Customizable Toolbar** — Modern, intuitive interface
|
|
26
29
|
- 🎨 **Color Picker** — Text and background color options
|
|
27
30
|
- 📱 **Responsive Design** — Works on desktop and mobile
|
|
@@ -69,14 +72,15 @@ export default App;
|
|
|
69
72
|
|
|
70
73
|
## Props
|
|
71
74
|
|
|
72
|
-
| Prop
|
|
73
|
-
|
|
74
|
-
| `name`
|
|
75
|
-
| `value`
|
|
76
|
-
| `onChange`
|
|
77
|
-
| `placeholder
|
|
78
|
-
| `maxWidth` | `string` | No
|
|
79
|
-
| `height`
|
|
75
|
+
| Prop | Type | Required | Default | Description |
|
|
76
|
+
|----------------|-------------------------------------|----------|---------------|----------------------------------------------------------|
|
|
77
|
+
| `name` | `string` | Yes | — | Unique identifier for the editor instance |
|
|
78
|
+
| `value` | `string` | Yes | — | Current editor content (HTML string) |
|
|
79
|
+
| `onChange` | `(value: string) => void` | Yes | — | Callback fired when content changes |
|
|
80
|
+
| `placeholder` | `string` | No | `"Some Text"` | Placeholder text when editor is empty |
|
|
81
|
+
| `maxWidth` | `string` | No | `"1090px"` | Adjust the maximum width (`'80%'` or `'800px'`) |
|
|
82
|
+
| `height` | `string` | No | `"500px"` | Adjust the height (`'50vh'` or `'500px'`) |
|
|
83
|
+
| `onImageUpload`| `(file: File) => Promise<string>` | No | — | Custom handler for uploading images to your server |
|
|
80
84
|
|
|
81
85
|
|
|
82
86
|
|
|
@@ -115,6 +119,49 @@ export default App;
|
|
|
115
119
|
```
|
|
116
120
|
|
|
117
121
|
|
|
122
|
+
### Image Upload Handler
|
|
123
|
+
|
|
124
|
+
Upload images to your own server instead of using temporary blob URLs:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import React, { useState } from 'react';
|
|
128
|
+
import { LexicalTextEditor } from '@innoviatech/lexical-text-editor';
|
|
129
|
+
import '@innoviatech/lexical-text-editor/style.css';
|
|
130
|
+
|
|
131
|
+
function App() {
|
|
132
|
+
const [content, setContent] = useState('');
|
|
133
|
+
|
|
134
|
+
const handleImageUpload = async (file: File): Promise<string> => {
|
|
135
|
+
const formData = new FormData();
|
|
136
|
+
formData.append('image', file);
|
|
137
|
+
|
|
138
|
+
const res = await fetch('/api/upload', {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
body: formData,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const data = await res.json();
|
|
144
|
+
if (!data.url) throw new Error('Upload failed');
|
|
145
|
+
return data.url; // permanent URL stored in editor content
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<LexicalTextEditor
|
|
150
|
+
name="editor"
|
|
151
|
+
value={content}
|
|
152
|
+
onChange={setContent}
|
|
153
|
+
onImageUpload={handleImageUpload}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
When `onImageUpload` is provided, images selected via the dialog, pasted from clipboard, or drag-dropped will be uploaded to your endpoint. The returned URL is stored permanently in the editor content (unlike temporary blob URLs).
|
|
160
|
+
|
|
161
|
+
### Image Captions
|
|
162
|
+
|
|
163
|
+
Images support captions. When inserting an image via the dialog, fill in the **Caption** field. After insertion, click the caption text below the image to edit it inline, or click **"+ Add caption"** to add one.
|
|
164
|
+
|
|
118
165
|
## Toolbar Features
|
|
119
166
|
|
|
120
167
|
- Text Formatting: Bold, Italic, Underline, Strikethrough
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{LexicalComposer as i}from"@lexical/react/LexicalComposer";import o,{useRef as r,useEffect as l,cloneElement as c,useState as a,useCallback as s,useMemo as d}from"react";import{$isHeadingNode as u,$isQuoteNode as h,$createQuoteNode as p,$createHeadingNode as m,HeadingNode as g,QuoteNode as f}from"@lexical/rich-text";import{CodeHighlightNode as b,CodeNode as v}from"@lexical/code";import{RichTextPlugin as y}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as x}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as w}from"@lexical/react/LexicalErrorBoundary";import{$createRangeSelection as C,$findMatchingParent as k,INTERNAL_$isBlock as _,$isElementNode as N,$getSelection as S,$setSelection as L,$isRootOrShadowRoot as A,$hasAncestor as T,$isRangeSelection as E,$isTextNode as D,$isTokenOrSegmented as M,$getCharacterOffsets as O,$isLeafNode as z,$getPreviousSelection as F,$caretRangeFromSelection as R,SELECTION_CHANGE_COMMAND as H,$getNodeByKey as U,DecoratorNode as I,$applyNodeReplacement as P,$insertNodes as $,CAN_REDO_COMMAND as W,CAN_UNDO_COMMAND as K,REDO_COMMAND as B,UNDO_COMMAND as J,FORMAT_ELEMENT_COMMAND as j,FORMAT_TEXT_COMMAND as q,$createParagraphNode as Q,$getRoot as Y,isDOMDocumentNode as G,ArtificialNode__DO_NOT_USE as X,$createLineBreakNode as V,$cloneWithProperties as Z,getRegisteredNode as ee,isHTMLElement as te,isDocumentFragment as ne,$isBlockElementNode as ie,isBlockDomNode as oe,isInlineDomNode as re,TextNode as le}from"lexical";import{HistoryPlugin as ce}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as ae}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as se,INSERT_ORDERED_LIST_COMMAND as de,INSERT_UNORDERED_LIST_COMMAND as ue,$isListNode as he,ListNode as pe,ListItemNode as me}from"@lexical/list";import{RxLetterCaseLowercase as ge,RxLetterCaseUppercase as fe,RxLetterCaseCapitalize as be}from"react-icons/rx";import{TbBold as ve,TbItalic as ye,TbUnderline as xe}from"react-icons/tb";import{BsSuperscript as we,BsSubscript as Ce,BsChatSquareQuote as ke,BsArrowCounterclockwise as _e,BsArrowClockwise as Ne,BsJustifyLeft as Se,BsTextCenter as Le,BsJustifyRight as Ae,BsJustify as Te,BsTextParagraph as Ee,BsTypeH1 as De,BsTypeH2 as Me,BsTypeH3 as Oe,BsTypeH4 as ze,BsTypeH5 as Fe,BsTypeH6 as Re,BsPencilSquare as He,BsListOl as Ue,BsListUl as Ie}from"react-icons/bs";import{AiOutlineStrikethrough as Pe,AiOutlineFontColors as $e,AiOutlineBgColors as We}from"react-icons/ai";import{IoCodeSlashOutline as Ke,IoImageOutline as Be}from"react-icons/io5";import{PiHighlighterLight as Je}from"react-icons/pi";import{useLexicalComposerContext as je}from"@lexical/react/LexicalComposerContext";import{TOGGLE_LINK_COMMAND as qe,$isLinkNode as Qe,LinkNode as Ye}from"@lexical/link";import{HiChevronDown as Ge}from"react-icons/hi2";import{IoIosLink as Xe}from"react-icons/io";import{MdCheck as Ve}from"react-icons/md";import{BiUnlink as Ze}from"react-icons/bi";import{SketchPicker as et}from"react-color";import{createPortal as tt}from"react-dom";import{LuUpload as nt}from"react-icons/lu";import{FaYoutube as it}from"react-icons/fa";import{VscPreview as ot}from"react-icons/vsc";import{LinkPlugin as rt}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as lt}from"@lexical/react/LexicalOnChangePlugin";var ct,at;!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(ct||(ct={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(at||(at={}));const st=[{id:ct.Lowercase,icon:e(ge,{}),label:"Lowercase"},{id:ct.Uppercase,icon:e(fe,{}),label:"Uppercase"},{id:ct.Capitalize,icon:e(be,{}),label:"Capitalize"},{id:ct.Strikethrough,icon:e(Pe,{}),label:"Strikethrough"},{id:ct.Highlight,icon:e(Je,{}),label:"Highlight",fontSize:10},{id:ct.Superscript,icon:e(we,{}),label:"Superscript"},{id:ct.Subscript,icon:e(Ce,{}),label:"Subscript"}],dt=[{id:ct.Bold,icon:e(ve,{}),label:"Bold"},{id:ct.Italics,icon:e(ye,{}),label:"Italics"},{id:ct.Underline,icon:e(xe,{}),label:"Underline"},{id:ct.Divider},{id:ct.Quote,icon:e(ke,{}),label:"Quote"},{id:ct.Code,icon:e(Ke,{}),label:"Code"}],ut=[{id:ct.Undo,icon:e(_e,{}),label:"Undo"},{id:ct.Redo,icon:e(Ne,{}),label:"Redo"},{id:ct.Divider}],ht=[{id:ct.LeftAlign,icon:e(Se,{}),label:"Left Align"},{id:ct.CenterAlign,icon:e(Le,{}),label:"Center Align"},{id:ct.RightAlign,icon:e(Ae,{}),label:"Right Align"},{id:ct.JustifyAlign,icon:e(Te,{}),label:"Justify Align"}],pt=[{id:"normal",label:"Normal",icon:e(Ee,{})},{id:"h1",label:"Heading 1",icon:e(De,{})},{id:"h2",label:"Heading 2",icon:e(Me,{})},{id:"h3",label:"Heading 3",icon:e(Oe,{})},{id:"h4",label:"Heading 4",icon:e(ze,{})},{id:"h5",label:"Heading 5",icon:e(Fe,{})},{id:"h6",label:"Heading 6",icon:e(Re,{})}];function mt(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const gt=new Map;function ft(e){let t=gt.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,i]=e.split(/:([^]+)/);n&&i&&(t[n.trim()]=i.trim())}return t}(e),gt.set(e,t)),t}function bt(e,t){(E(e)?e.isCollapsed():D(e)||N(e))||mt(280);const n=ft(E(e)?e.style:D(e)?e.getStyle():e.getTextStyle()),i=Object.entries(t).reduce((t,[i,o])=>("function"==typeof o?t[i]=o(n[i],e):null===o?delete t[i]:t[i]=o,t),{...n}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(i);E(e)||D(e)?e.setStyle(o):e.setTextStyle(o),gt.set(o,i)}function vt(e,t){if(E(e)&&e.isCollapsed()){bt(e,t);const n=e.anchor.getNode();N(n)&&n.isEmpty()&&bt(n,t)}!function(e){const t=S();if(!t)return;const n=new Map,i=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(E(t))for(const e of R(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!D(t)||!t.canHaveFormat())continue;const[n,o]=i(t);o!==n&&(M(t)||0===n&&o===t.getTextContentSize()?e(t):e(t.splitText(n,o)[0===n?0:1]))}E(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:i,offset:o,type:r}=t;t.set(n.key,n.offset,n.type),n.set(i,o,r)}}(t)}(e=>{bt(e,t)})}function yt(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function xt(e){return e.getNode().isAttached()}function wt(e){let t=e;for(;null!==t&&!A(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function Ct(e,t,n=null){const i=e.getStartEndPoints(),o=i?i[0]:null,r=e.getNodes(),l=r.length;if(null!==o&&(0===l||1===l&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),i=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),i.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let c=null,a=[];for(let i=0;i<l;i++){const o=r[i];A(o)?(kt(e,a,a.length,t,n),a=[],c=o):null===c||null!==c&&T(o,c)?a.push(o):(kt(e,a,a.length,t,n),a=[o])}kt(e,a,a.length,t,n)}function kt(e,t,n,i,o=null){if(0===t.length)return;const r=t[0],l=new Map,c=[];let a=N(r)?r:r.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let s=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,s=!0;break}if(a=a.getParentOrThrow(),A(a))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];N(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const u=new Set;for(let e=0;e<n;e++){const n=t[e];let o=n.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&z(n)&&!u.has(n.getKey())){const e=o.getKey();if(void 0===l.get(e)){const t=i();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),c.push(t),l.set(e,t),o.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),N(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),wt(o)}}else if(d.has(n.getKey())){N(n)||mt(179);const e=i();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),c.push(e),n.remove(!0)}}if(null!==o)for(let e=0;e<c.length;e++){const t=c[e];o.append(t)}let h=null;if(A(a))if(s)if(null!==o)a.insertAfter(o);else for(let e=c.length-1;e>=0;e--){const t=c[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(N(e)&&(a=e),null===e)if(o)a.append(o);else for(let e=0;e<c.length;e++){const t=c[e];a.append(t),h=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<c.length;t++){const n=c[t];e.insertBefore(n),h=n}}else if(o)a.insertAfter(o);else for(let e=c.length-1;e>=0;e--){const t=c[e];a.insertAfter(t),h=t}const p=F();E(p)&&xt(p.anchor)&&xt(p.focus)?L(p.clone()):null!==h?h.selectEnd():e.dirty=!0}function _t(e,t,n){const i=ft(e.getStyle());return null!==i&&i[t]||n}function Nt(e,t,n=""){let i=null;const o=e.getNodes(),r=e.anchor,l=e.focus,c=e.isBackward(),a=c?l.offset:r.offset,s=c?l.getNode():r.getNode();if(E(e)&&e.isCollapsed()&&""!==e.style){const n=ft(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==a||!r.is(s))&&D(r)){const e=_t(r,t,n);if(null===i)i=e;else if(i!==e){i="";break}}}return null===i?n:i}const St="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Lt=St&&"documentMode"in document?document.documentMode:null;function At(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Tt({open:t,onOpenChange:n,children:i}){const a=r(null),s=r(null);return l(()=>{function e(e){a.current?.contains(e.target)||s.current?.contains(e.target)||n(!1)}return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,n]),e("div",{className:"popover-root",children:o.Children.map(i,e=>e&&"object"==typeof e?e.type===Et?c(e,{triggerRef:a}):e.type===Dt?c(e,{contentRef:s}):e:e)})}function Et({children:t,triggerRef:n}){return e("div",{className:"popover-trigger",ref:n,children:t})}function Dt({open:t,align:n="start",children:i,contentRef:o}){return t?e("div",{ref:o,className:`popover-content align-${n}`,children:i}):null}function Mt({onAction:n,selectionMap:i}){const[o,l]=a(!1),c=r(null),s=r(null);return t(Tt,{open:o,onOpenChange:l,children:[e(Et,{triggerRef:c,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[e("span",{children:"Aa"}),e(Ge,{className:"chevron "+(o?"rotated":"")})]})}),e(Dt,{open:o,align:"start",onClose:()=>l(!1),contentRef:s,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:st.map(({id:o,label:r,icon:c})=>t("button",{type:"button",className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),l(!1)},style:{minWidth:130},children:[c,e("span",{className:"label",children:r})]},o))})})]})}function Ot(){return e("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function zt({updateHeading:n,headingSelectionMap:i}){const o=pt.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Tt,{open:l,onOpenChange:c,children:[e(Et,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>c(e=>!e),style:{minWidth:132},children:[o?.icon,e("span",{children:o?.label}),e(Ge,{className:"chevron "+(l?"rotated":"")})]})}),e(Dt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:pt.map(({id:o,label:r,icon:l})=>t("button",{type:"button",className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),c(!1)},children:[l,e("span",{className:"label",children:r})]},o))})})]})}function Ft({linkUrl:n,setLinkUrl:i,onConfirm:o,onCancel:c,removeLink:s}){const[d,u]=a(!1),h=r(null),p=r(null);return l(()=>{"https://"===n&&u(!0)},[n]),l(()=>{d&&p.current?.focus()},[d]),l(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&c()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]),t("div",{ref:h,className:"lexical-text-editor-link link-editor-container",children:[e("div",{className:"link-editor-input-wrapper",children:d?e("input",{ref:p,className:"link-editor-input",value:n,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o(n),u(!1)):"Escape"===e.key&&(e.preventDefault(),u(!1),c())}}):e("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:n})}),t("div",{className:"link-editor-buttons",children:[e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onClick:()=>{d?(o(n),u(!1)):u(!0)},children:d?e(Ve,{size:18}):e(He,{size:14})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:e(Ze,{size:14,style:{stroke:"black"}})})]})]})}function Rt({onAction:n,alignmentSelectionMap:i}){const o=ht.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Tt,{open:l,onOpenChange:c,children:[e(Et,{triggerRef:s,children:t("button",{type:"button",className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>c(e=>!e),style:{minWidth:146},children:[o?.icon,e("span",{children:o?.label}),e(Ge,{className:"chevron "+(l?"rotated":"")})]})}),e(Dt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:ht.map(({id:o,label:r,icon:l})=>t("button",{type:"button",className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),c(!1)},children:[l,e("span",{className:"label",children:r})]},o))})})]})}function Ht({color:n,onChange:i,icon:o}){const[c,s]=a(!1),d=r(null),u=r(null);l(()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return t("div",{className:"color-picker-wrapper",children:[e("button",{type:"button",ref:d,className:`size-8 lexical-btn ${c?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:o}),c&&tt(e("div",{ref:u,className:"lexical-color-popover "+(c?"open":""),style:{top:d.current?.getBoundingClientRect().bottom,left:d.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e(et,{color:n,onChangeComplete:e=>{i(e.hex)}})}),document.body)]})}St&&"InputEvent"in window&&!Lt&&new window.InputEvent("input");const Ut=({content:n,direction:i="top",delay:o=400,children:l})=>{const[c,s]=a(!1),d=r(null);return t("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{d.current=window.setTimeout(()=>{s(!0)},o)},onMouseLeave:()=>{d.current&&clearTimeout(d.current),s(!1)},children:[l,c&&e("div",{className:`Lexical-Tooltip-Tip ${i}`,children:n})]})};function It(){const[i]=je(),[{color:o,bgColor:r},c]=a({color:"#000",bgColor:"#fff"}),s=()=>{const e=S();if(E(e)){const t=Nt(e,"color","#000"),n=Nt(e,"background","#fff");c({color:t,bgColor:n})}};l(()=>At(i.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),i.registerCommand(H,()=>(s(),!1),1)),[i]);const d=({property:e,color:t})=>{i.update(()=>{const n=S();n&&vt(n,{[e]:t})})};return t(n,{children:[e(Ut,{content:"Font Color",direction:"bottom",children:e(Ht,{color:o,onChange:e=>{d({property:"color",color:e})},icon:e($e,{})})}),e(Ut,{content:"Background Color",direction:"bottom",children:e(Ht,{color:r,onChange:e=>{d({property:"background",color:e})},icon:e(We,{})})})]})}function Pt({blockType:i}){const[o]=je();return t(n,{children:[e(Ut,{content:"Ordered list",direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${"ol"===i?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===i?o.dispatchCommand(se,void 0):o.dispatchCommand(de,void 0)},children:e(Ue,{})})}),e(Ut,{content:"Unordered list",direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${"ul"===i?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===i?o.dispatchCommand(se,void 0):o.dispatchCommand(ue,void 0)},children:e(Ie,{})})})]})}const $t=({src:n,altText:i,nodeKey:o,width:l,height:c,maxWidth:a})=>{const[s]=je(),d=r(null),u=r(null),h=r(null),p=e=>{if(!h.current||!d.current)return;const t=e.clientX-h.current.x,n=Math.min(a,Math.max(50,h.current.width+t)),i=n*d.current.ratio;d.current.width=n,d.current.height=i;const o=u.current?.querySelector("img");o&&(o.style.width=n+"px",o.style.height=i+"px")},m=()=>{if(!d.current)return;const{width:e,height:t}=d.current;s.update(()=>{const n=U(o);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),d.current=null,h.current=null,window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",m)};return t("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:a},children:[e("img",{src:n,alt:i,width:"inherit"===l?void 0:l,height:"inherit"===c?void 0:c,style:{maxWidth:"100%",display:"block"}}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=u.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,i=t.naturalHeight/t.naturalWidth,o=n*i;h.current={x:e.clientX,y:e.clientY,width:n,height:o},d.current={width:n,height:o,ratio:i},window.addEventListener("mousemove",p),window.addEventListener("mouseup",m)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Wt=e=>P(new Bt(e)),Kt=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let i,o;e.width&&(i=e.width),e.height&&(o=e.height);const r=e.style;if((!i||0===i)&&r.width){const e=parseInt(r.width,10);Number.isNaN(e)||(i=e)}if((!o||0===o)&&r.height){const e=parseInt(r.height,10);Number.isNaN(e)||(o=e)}return{node:Wt({src:t,altText:n,width:i??"inherit",height:o??"inherit"})}};class Bt extends I{constructor({src:e="",altText:t="",maxWidth:n=1080,width:i="inherit",height:o="inherit",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=i,this.__height=o}static getType(){return"image"}static clone(e){return new Bt({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}exportDOM(){const e=document.createElement("img");return e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),{element:e}}static importDOM(){return{img:()=>({conversion:Kt,priority:1})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height}}static importJSON(e){return new Bt({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}decorate(){return e($t,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function Jt({open:n,onClose:i,forPreview:o=!1,children:c}){const a=r(null);return l(()=>{if(!n)return;const e=e=>{a.current&&!a.current.contains(e.target)&&i()},t=e=>{"Escape"===e.key&&i()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[n,i]),n?e("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:t("div",{ref:a,className:"lte-dialog "+(o?"preview":""),children:[e("button",{type:"button",className:"lte-dialog-close",onClick:i,children:"×"}),c]})}):null}function jt(){const[n]=je(),i=r(null),[o,l]=a(!1),[c,s]=a(""),[d,u]=a(""),[h,p]=a();return t("div",{className:"lexical-text-editor-dialog",children:[e("input",{type:"file",ref:i,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&p(t),e.target.value=""}}),e("button",{type:"button",className:`size-8 lexical-btn ${o?"toolbarActive":"toolbar"} icon`,onClick:()=>l(e=>!e),children:e(Be,{size:18})}),t(Jt,{open:o,onClose:()=>l(!1),children:[e("div",{className:"lte-dialog-header",children:"Add Image"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Alt text",value:d,onChange:e=>u(e.target.value)}),e("input",{className:"lte-input",placeholder:"Add image by URL",value:c,onChange:e=>s(e.target.value)}),e("div",{className:"lte-divider",children:e("span",{children:"or"})}),t("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>i.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[e(nt,{size:20}),e("span",{children:"Upload Image"})]}),h&&e("div",{className:"lte-file-name",children:h.name})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!c&&!h,onClick:()=>{let e=c;h&&(e=URL.createObjectURL(h)),n.update(()=>{const t=Wt({src:e,altText:d});$([t])}),p(void 0),u(""),s(""),l(!1)},children:"Add Image"})})]})]})}const qt=({id:e,provider:t})=>new en({id:e,provider:t}),Qt="data-lexical-video",Yt="data-provider",Gt="315px",Xt="560px",Vt=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,Zt=e=>{const t=e?.getAttribute(Qt),n=e?.getAttribute(Yt)??"youtube";if(!t)return null;return{node:qt({id:t,provider:n})}};class en extends I{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new en({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return qt({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e("iframe",{height:Gt,width:Xt,src:Vt(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Qt,this.__id),e.setAttribute(Yt,this.__provider),e.setAttribute("height",Gt),e.setAttribute("width",Xt),e.setAttribute("src",Vt(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Zt,priority:0})}}}function tn(){const[n,i]=a(!1),[o,r]=a(!1),[c,s]=a(""),[d]=je();return l(()=>{n||(s(""),r(!1))},[n]),t("div",{className:"lexical-text-editor-dialog",children:[e("button",{type:"button",className:`size-8 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>i(!0),children:e(it,{size:18,color:"red"})}),t(Jt,{open:n,onClose:()=>i(!1),children:[e("div",{className:"lte-dialog-header",children:"Embed Video"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:c,onChange:e=>s(e.target.value)}),o&&e("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!c,onClick:()=>{if(!c)return;let e=null,t=null;const n=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(c);n&&11===n[2]?.length&&(e="youtube",t=n[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(c);o&&o[1]&&(e="drive",t=o[1]),t&&e?(d.update(()=>{const n=qt({id:t,provider:e});$([n])}),s(""),r(!1),i(!1)):r(!0)},children:"Embed"})})]})]})}function nn({value:t}){return e("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:t}})}function on({value:n,triggerLabel:i="Preview"}){const[o,r]=a(!1);return t("div",{className:"lexical-text-editor-dialog",children:[t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[e(ot,{size:18}),e("span",{children:i})]}),t(Jt,{open:o,onClose:()=>r(!1),forPreview:!0,children:[e("div",{className:"lte-dialog-header",children:"Content Preview"}),t("div",{className:"lte-preview-container",children:[e("div",{className:"lte-preview-title",children:"CONTENT"}),e(nn,{value:n})]})]})]})}const rn=({value:n})=>{const[i]=je(),[o,r]=a({[ct.Undo]:!0,[ct.Redo]:!0}),[c,d]=a(!1),[g,f]=a({[ct.LeftAlign]:!0}),[b,v]=a({[at.Normal]:!0}),[y,x]=a("paragraph"),[w,A]=a("https://");let T=!0;const D=()=>{if(T){const e=i.getRootElement();e&&(e.scrollTop=0,T=!1)}const e=S();if(E(e)){const t={[ct.Bold]:e.hasFormat("bold"),[ct.Italics]:e.hasFormat("italic"),[ct.Underline]:e.hasFormat("underline"),[ct.Uppercase]:e.hasFormat("uppercase"),[ct.Lowercase]:e.hasFormat("lowercase"),[ct.Capitalize]:e.hasFormat("capitalize"),[ct.Strikethrough]:e.hasFormat("strikethrough"),[ct.Superscript]:e.hasFormat("superscript"),[ct.Subscript]:e.hasFormat("subscript"),[ct.Code]:e.hasFormat("code"),[ct.Highlight]:e.hasFormat("highlight")};f(t);const n=e.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow(),r=o.getKey();if(!i.getElementByKey(r))return;if(he(o)){const e=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(n,pe),t=e?e.getTag():o.getTag();x(t)}else if("paragraph"===o.getType()||u(o)){let e=null;u(o)&&(e=o.getTag());const t={[at.H1]:"h1"===e,[at.H2]:"h2"===e,[at.H3]:"h3"===e,[at.H4]:"h4"===e,[at.H5]:"h5"===e,[at.H6]:"h6"===e,[at.Normal]:"paragraph"===o.getType()};x(o.getType()),v(t)}else x(o.getType());const l=(N(n)?n:o).getFormat();f(e=>({...e,[ct.LeftAlign]:0===l||1===l,[ct.CenterAlign]:2===l,[ct.RightAlign]:3===l,[ct.JustifyAlign]:4===l})),"quote"===o.getType()?f(e=>({...e,[ct.Quote]:!0})):f(e=>({...e,[ct.Quote]:!1}));const c=e.anchor.getNode(),a=c.getParent();Qe(a)?(f(e=>({...e,[ct.Link]:!0})),A(a.getURL()),d(!0)):Qe(c)?(f(e=>({...e,[ct.Link]:!0})),A(c.getURL()),d(!0)):(f(e=>({...e,[ct.Link]:!1})),A("https://"),d(!1))}};l(()=>At(i.registerUpdateListener(({editorState:e})=>{e.read(()=>{D()})}),i.registerCommand(H,()=>(D(),!1),1),i.registerCommand(K,e=>(r(t=>({...t,undo:!e})),!1),1),i.registerCommand(W,e=>(r(t=>({...t,redo:!e})),!1),1)),[]);const M=e=>{switch(e){case ct.Bold:i.dispatchCommand(q,"bold");break;case ct.Italics:i.dispatchCommand(q,"italic");break;case ct.Underline:i.dispatchCommand(q,"underline");break;case ct.Lowercase:i.dispatchCommand(q,"lowercase");break;case ct.Uppercase:i.dispatchCommand(q,"uppercase");break;case ct.Capitalize:i.dispatchCommand(q,"capitalize");break;case ct.Strikethrough:i.dispatchCommand(q,"strikethrough");break;case ct.Superscript:i.dispatchCommand(q,"superscript");break;case ct.Subscript:i.dispatchCommand(q,"subscript");break;case ct.Highlight:i.dispatchCommand(q,"highlight");break;case ct.Code:i.dispatchCommand(q,"code");break;case ct.Quote:i.update(()=>{const e=S();if(E(e)){const t=e.anchor.getNode().getParent();t&&h(t)?function(e,t,n=yt){if(null===e)return;const i=e.getStartEndPoints(),o=new Map;let r=null;if(i){const[e,t]=i;r=C(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const n=k(e.getNode(),_),l=k(t.getNode(),_);N(n)&&o.set(n.getKey(),n),N(l)&&o.set(l.getKey(),l)}for(const t of e.getNodes())if(N(t)&&_(t))o.set(t.getKey(),t);else if(null===i){const e=k(t,_);N(e)&&o.set(e.getKey(),e)}for(const[e,i]of o){const o=t();n(i,o),i.replace(o,!0),r&&(e===r.anchor.key&&r.anchor.set(o.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(o.getKey(),r.focus.offset,r.focus.type))}r&&e.is(S())&&L(r)}(e,()=>Q()):Ct(e,()=>p())}});break;case ct.Link:O(),d(!0);break;case ct.LeftAlign:i.dispatchCommand(j,"left");break;case ct.RightAlign:i.dispatchCommand(j,"right");break;case ct.CenterAlign:i.dispatchCommand(j,"center");break;case ct.JustifyAlign:i.dispatchCommand(j,"justify");break;case ct.Undo:i.dispatchCommand(J,void 0);break;case ct.Redo:i.dispatchCommand(B,void 0)}},O=s(()=>{i.update(()=>{const e=S();E(e)&&!e.isCollapsed()&&(c?i.dispatchCommand(qe,null):""!==w&&i.dispatchCommand(qe,w))})},[i,c,w]),z=s(()=>{A(""),i.dispatchCommand(qe,null),d(!1)},[i]);return t("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[ut.map(({id:t,label:n,icon:i})=>t===ct.Divider?e(Ot,{},t):e(Ut,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${g[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(t),disabled:!!o[t],children:i})},n)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(zt,{updateHeading:e=>{i.update(()=>{const t=S();E(t)&&Ct(t,"normal"===e?()=>Q():()=>m(e))})},headingSelectionMap:b}),e(Ot,{})]}),dt.map(({id:t,label:n,icon:i})=>t===ct.Divider?e(Ot,{},t):e(Ut,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${g[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(t),children:i})},t)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Pt,{blockType:y}),e(Ot,{})]}),e(It,{}),e(Mt,{onAction:M,selectionMap:g}),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Rt,{onAction:M,alignmentSelectionMap:g}),e(Ot,{})]}),e(Ut,{content:"Link",direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${g[ct.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(ct.Link),disabled:!!o[ct.Link],children:e(Xe,{})})}),c&&e(Ft,{linkUrl:w,setLinkUrl:A,removeLink:z,onConfirm:e=>{i.dispatchCommand(qe,{url:e,target:"_blank"}),A(e),d(!1)},onCancel:()=>{A(""),d(!1)}}),e(jt,{}),e(tn,{}),e(on,{value:n})]})};function ln(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const n=document.createElement("div"),i=Y().getChildren();for(let o=0;o<i.length;o++)cn(e,i[o],n,t);return n.innerHTML}function cn(e,t,n,i=null){let o=null===i||t.isSelected(i);const r=N(t)&&t.excludeFromCopy("html");let l=t;if(null!==i){let e=Z(t);e=D(e)&&null!==i?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!M(t)&&null!==n){const[i,o]=n,r=e.isBackward(),l=i.getNode(),c=o.getNode(),a=t.is(l),s=t.is(c);if(a||s){const[n,i]=O(e),o=l.is(c),a=t.is(r?c:l),s=t.is(r?l:c);let d,u=0;o?(u=n>i?i:n,d=n>i?n:i):a?(u=r?i:n,d=void 0):s&&(u=0,d=r?n:i),t.__text=t.__text.slice(u,d)}}return t}(i,e):e,l=e}const c=N(l)?l.getChildren():[],a=ee(e,l.getType());let s;s=a&&void 0!==a.exportDOM?a.exportDOM(e,l):l.exportDOM(e);const{element:d,after:u}=s;if(!d)return!1;const h=document.createDocumentFragment();for(let n=0;n<c.length;n++){const r=c[n],l=cn(e,r,h,i);!o&&N(t)&&l&&t.extractWithChild(r,i,"html")&&(o=!0)}if(o&&!r){if((te(d)||ne(d))&&d.append(h),n.append(d),u){const e=u.call(l,d);e&&(ne(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(h);return o}const an=new Set(["STYLE","SCRIPT"]);function sn(e,t,n,i,o=new Map,r){let l=[];if(an.has(e.nodeName))return l;let c=null;const a=function(e,t){const{nodeName:n}=e,i=t._htmlConversions.get(n.toLowerCase());let o=null;if(void 0!==i)for(const t of i){const n=t(e);null!==n&&(null===o||(o.priority||0)<=(n.priority||0))&&(o=n)}return null!==o?o.conversion:null}(e,t),s=a?a(e):null;let d=null;if(null!==s){d=s.after;const t=s.node;if(c=Array.isArray(t)?t[t.length-1]:t,null!==c){for(const[,e]of o)if(c=e(c,r),!c)break;c&&l.push(...Array.isArray(t)?t:[c])}null!=s.forChild&&o.set(e.nodeName,s.forChild)}const u=e.childNodes;let h=[];const p=(null==c||!A(c))&&(null!=c&&ie(c)||i);for(let e=0;e<u.length;e++)h.push(...sn(u[e],t,n,p,new Map(o),c));return null!=d&&(h=d(h)),oe(e)&&(h=function(e,t,n){const i=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const l=t[e];if(ie(l))i&&!l.getFormat()&&l.setFormat(i),o.push(l);else if(r.push(l),e===t.length-1||e<t.length-1&&ie(t[e+1])){const e=n();e.setFormat(i),e.append(...r),o.push(e),r=[]}}return o}(e,h,p?()=>{const e=new X;return n.push(e),e}:Q)),null==c?h.length>0?l=l.concat(h):oe(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(re(e.nextSibling)&&re(e.previousSibling))}(e)&&(l=l.concat(V())):N(c)&&c.append(...h),l}function dn({value:t,onChange:n}){const[i]=je(),[o,r]=a(!0);return l(()=>{t&&o&&(r(!1),i.update(()=>{if(ln(i)!==t){Y().clear();const e=(new DOMParser).parseFromString(t,"text/html"),n=function(e,t){const n=G(t)?t.body.childNodes:t.childNodes;let i=[];const o=[];for(const t of n)if(!an.has(t.nodeName)){const n=sn(t,e,o,!1);null!==n&&(i=i.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof X&&t.insertAfter(V());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(o),i}(i,e);$(n)}}))},[i,t,o]),l(()=>{r(!0)},[t]),e(lt,{onChange:e=>{e.read(()=>{n(ln(i))})}})}const un=({id:e})=>new bn({id:e}),hn="data-lexical-youtube",pn="315px",mn="560px",gn=e=>`https://www.youtube-nocookie.com/embed/${e}`,fn=e=>{const t=e?.getAttribute(hn);if(!t)return null;return{node:un({id:t})}};class bn extends I{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new bn({id:e.__id,key:e.getKey()})}static importJSON(e){return un({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:pn,width:mn,src:gn(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(hn,this.__id),e.setAttribute("height",pn),e.setAttribute("width",mn),e.setAttribute("src",gn(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:fn,priority:0})}}}class vn extends le{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new vn(e.__text,e.__key)}static importDOM(){const e=le.importDOM();return{...e,span:()=>({conversion:yn(e?.span),priority:1}),div:()=>({conversion:yn(e?.div),priority:1}),p:()=>({conversion:yn(e?.p),priority:1}),b:()=>({conversion:yn(e?.b),priority:1}),strong:()=>({conversion:yn(e?.strong),priority:1}),i:()=>({conversion:yn(e?.i),priority:1}),em:()=>({conversion:yn(e?.em),priority:1}),u:()=>({conversion:yn(e?.u),priority:1}),s:()=>({conversion:yn(e?.s),priority:1}),strike:()=>({conversion:yn(e?.strike),priority:1}),code:()=>({conversion:yn(e?.code),priority:1})}}static importJSON(e){return function(e=""){return P(new vn(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function yn(e){return t=>{const n=e?.(t);if(!n)return null;const i=n.conversion(t);if(!i)return i;const o=t.style,r=[];o.backgroundColor&&r.push(`background-color: ${o.backgroundColor}`),o.color&&r.push(`color: ${o.color}`),o.fontFamily&&r.push(`font-family: ${o.fontFamily}`),o.fontWeight&&r.push(`font-weight: ${o.fontWeight}`),o.fontSize&&r.push(`font-size: ${o.fontSize}`),o.fontStyle&&r.push(`font-style: ${o.fontStyle}`),o.textDecoration&&r.push(`text-decoration: ${o.textDecoration}`),o.whiteSpace&&r.push(`white-space: ${o.whiteSpace}`),o.textAlign&&r.push(`text-align: ${o.textAlign}`);const l=t.getAttribute("style");if(l){l.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!r.some(e=>e.startsWith(t))&&r.push(e.trim())})}return{...i,forChild:(e,t)=>{const n=i?.forChild??(e=>e),o=n(e,t);if(D(o)&&r.length>0){const e=r.join("; ");return o.setStyle(e)}return o}}}}const xn={text:{bold:"lexical-bold",underline:"lexical-underline",italic:"lexical-italic",strikethrough:"lexical-strikethrough",underlineStrikethrough:"lexical-underline-strikethrough",uppercase:"lexical-uppercase",lowercase:"lexical-lowercase",capitalize:"lexical-capitalize",code:"lexical-code"},paragraph:"lexical-paragraph",list:{ul:"lexical-list-ul",ol:"lexical-list-ol",listitem:"lexical-listitem"},quote:"lexical-quote",link:"lexical-link"},wn=o.memo(function({name:n,value:o,onChange:r,placeholder:l,maxWidth:c=null,height:a=null}){const s=d(()=>({namespace:n,theme:xn,onError:e=>{console.error("Lexical error:",e)},nodes:[vn,{replace:le,with:e=>new vn(e.__text),withKlass:vn},g,b,v,pe,me,f,Ye,Bt,bn,en]}),[n]);return e("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:c||"1090px"},children:t(i,{initialConfig:s,children:[e("div",{className:"lexical-toolbar-container",children:e(rn,{value:o})}),e("div",{className:"lexical-editor-inner",children:e(y,{contentEditable:e(x,{className:"lexical-content-editable",style:{height:a||"500px"}}),placeholder:e("div",{className:"lexical-placeholder",children:l||"Some Text"}),ErrorBoundary:w})}),e(ce,{}),e(ae,{}),e(rt,{}),e(dn,{value:o,onChange:r})]})})});export{wn as LexicalTextEditor};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{LexicalComposer as i}from"@lexical/react/LexicalComposer";import o,{useRef as r,useEffect as l,cloneElement as c,useState as a,useCallback as s,useMemo as d}from"react";import{$isHeadingNode as u,$isQuoteNode as h,$createQuoteNode as p,$createHeadingNode as m,HeadingNode as g,QuoteNode as f}from"@lexical/rich-text";import{CodeHighlightNode as b,CodeNode as v}from"@lexical/code";import{RichTextPlugin as y}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as x}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as w}from"@lexical/react/LexicalErrorBoundary";import{$createRangeSelection as C,$findMatchingParent as _,INTERNAL_$isBlock as k,$isElementNode as N,$getSelection as S,$setSelection as A,$isRootOrShadowRoot as L,$hasAncestor as T,$isRangeSelection as E,$isTextNode as D,$isTokenOrSegmented as M,$getCharacterOffsets as z,$isLeafNode as O,$getPreviousSelection as U,$caretRangeFromSelection as F,SELECTION_CHANGE_COMMAND as I,$getNodeByKey as R,DecoratorNode as H,$applyNodeReplacement as W,PASTE_COMMAND as P,COMMAND_PRIORITY_LOW as $,$insertNodes as K,CAN_REDO_COMMAND as B,CAN_UNDO_COMMAND as J,REDO_COMMAND as j,UNDO_COMMAND as q,FORMAT_ELEMENT_COMMAND as Q,FORMAT_TEXT_COMMAND as Y,$createParagraphNode as G,$getRoot as X,isDOMDocumentNode as V,ArtificialNode__DO_NOT_USE as Z,$createLineBreakNode as ee,$cloneWithProperties as te,getRegisteredNode as ne,isHTMLElement as ie,isDocumentFragment as oe,$isBlockElementNode as re,isBlockDomNode as le,isInlineDomNode as ce,TextNode as ae}from"lexical";import{HistoryPlugin as se}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as de}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as ue,INSERT_ORDERED_LIST_COMMAND as he,INSERT_UNORDERED_LIST_COMMAND as pe,$isListNode as me,ListNode as ge,ListItemNode as fe}from"@lexical/list";import{RxLetterCaseLowercase as be,RxLetterCaseUppercase as ve,RxLetterCaseCapitalize as ye}from"react-icons/rx";import{TbBold as xe,TbItalic as we,TbUnderline as Ce}from"react-icons/tb";import{BsSuperscript as _e,BsSubscript as ke,BsChatSquareQuote as Ne,BsArrowCounterclockwise as Se,BsArrowClockwise as Ae,BsJustifyLeft as Le,BsTextCenter as Te,BsJustifyRight as Ee,BsJustify as De,BsTextParagraph as Me,BsTypeH1 as ze,BsTypeH2 as Oe,BsTypeH3 as Ue,BsTypeH4 as Fe,BsTypeH5 as Ie,BsTypeH6 as Re,BsPencilSquare as He,BsListOl as We,BsListUl as Pe}from"react-icons/bs";import{AiOutlineStrikethrough as $e,AiOutlineFontColors as Ke,AiOutlineBgColors as Be}from"react-icons/ai";import{IoCodeSlashOutline as Je,IoImageOutline as je}from"react-icons/io5";import{PiHighlighterLight as qe}from"react-icons/pi";import{useLexicalComposerContext as Qe}from"@lexical/react/LexicalComposerContext";import{TOGGLE_LINK_COMMAND as Ye,$isLinkNode as Ge,LinkNode as Xe}from"@lexical/link";import{HiChevronDown as Ve}from"react-icons/hi2";import{IoIosLink as Ze}from"react-icons/io";import{MdCheck as et}from"react-icons/md";import{BiUnlink as tt}from"react-icons/bi";import{SketchPicker as nt}from"react-color";import{createPortal as it}from"react-dom";import{LuUpload as ot}from"react-icons/lu";import{FaYoutube as rt}from"react-icons/fa";import{VscPreview as lt}from"react-icons/vsc";import{LinkPlugin as ct}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as at}from"@lexical/react/LexicalOnChangePlugin";var st,dt;!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"}(st||(st={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(dt||(dt={}));const ut=[{id:st.Lowercase,icon:e(be,{}),label:"Lowercase"},{id:st.Uppercase,icon:e(ve,{}),label:"Uppercase"},{id:st.Capitalize,icon:e(ye,{}),label:"Capitalize"},{id:st.Strikethrough,icon:e($e,{}),label:"Strikethrough"},{id:st.Highlight,icon:e(qe,{}),label:"Highlight",fontSize:10},{id:st.Superscript,icon:e(_e,{}),label:"Superscript"},{id:st.Subscript,icon:e(ke,{}),label:"Subscript"}],ht=[{id:st.Bold,icon:e(xe,{}),label:"Bold"},{id:st.Italics,icon:e(we,{}),label:"Italics"},{id:st.Underline,icon:e(Ce,{}),label:"Underline"},{id:st.Divider},{id:st.Quote,icon:e(Ne,{}),label:"Quote"},{id:st.Code,icon:e(Je,{}),label:"Code"}],pt=[{id:st.Undo,icon:e(Se,{}),label:"Undo"},{id:st.Redo,icon:e(Ae,{}),label:"Redo"},{id:st.Divider}],mt=[{id:st.LeftAlign,icon:e(Le,{}),label:"Left Align"},{id:st.CenterAlign,icon:e(Te,{}),label:"Center Align"},{id:st.RightAlign,icon:e(Ee,{}),label:"Right Align"},{id:st.JustifyAlign,icon:e(De,{}),label:"Justify Align"}],gt=[{id:"normal",label:"Normal",icon:e(Me,{})},{id:"h1",label:"Heading 1",icon:e(ze,{})},{id:"h2",label:"Heading 2",icon:e(Oe,{})},{id:"h3",label:"Heading 3",icon:e(Ue,{})},{id:"h4",label:"Heading 4",icon:e(Fe,{})},{id:"h5",label:"Heading 5",icon:e(Ie,{})},{id:"h6",label:"Heading 6",icon:e(Re,{})}];function ft(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 bt=new Map;function vt(e){let t=bt.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),bt.set(e,t)),t}function yt(e,t){(E(e)?e.isCollapsed():D(e)||N(e))||ft(280);const n=vt(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),bt.set(o,i)}function xt(e,t){if(E(e)&&e.isCollapsed()){yt(e,t);const n=e.anchor.getNode();N(n)&&n.isEmpty()&&yt(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 F(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=>{yt(e,t)})}function wt(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function Ct(e){return e.getNode().isAttached()}function _t(e){let t=e;for(;null!==t&&!L(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function kt(e,t,n=null){const i=e.getStartEndPoints(),o=i?i[0]:null,r=e.getNodes(),l=r.length;if(null!==o&&(0===l||1===l&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),i=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),i.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let c=null,a=[];for(let i=0;i<l;i++){const o=r[i];L(o)?(Nt(e,a,a.length,t,n),a=[],c=o):null===c||null!==c&&T(o,c)?a.push(o):(Nt(e,a,a.length,t,n),a=[o])}Nt(e,a,a.length,t,n)}function Nt(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(),L(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&&O(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))}),_t(o)}}else if(d.has(n.getKey())){N(n)||ft(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(L(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=U();E(p)&&Ct(p.anchor)&&Ct(p.focus)?A(p.clone()):null!==h?h.selectEnd():e.dirty=!0}function St(e,t,n){const i=vt(e.getStyle());return null!==i&&i[t]||n}function At(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=vt(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=St(r,t,n);if(null===i)i=e;else if(i!==e){i="";break}}}return null===i?n:i}const Lt="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Tt=Lt&&"documentMode"in document?document.documentMode:null;function Et(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Dt({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===Mt?c(e,{triggerRef:a}):e.type===zt?c(e,{contentRef:s}):e:e)})}function Mt({children:t,triggerRef:n}){return e("div",{className:"popover-trigger",ref:n,children:t})}function zt({open:t,align:n="start",children:i,contentRef:o}){return t?e("div",{ref:o,className:`popover-content align-${n}`,children:i}):null}function Ot({onAction:n,selectionMap:i}){const[o,l]=a(!1),c=r(null),s=r(null);return t(Dt,{open:o,onOpenChange:l,children:[e(Mt,{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(Ve,{className:"chevron "+(o?"rotated":"")})]})}),e(zt,{open:o,align:"start",onClose:()=>l(!1),contentRef:s,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:ut.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 Ut(){return e("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function Ft({updateHeading:n,headingSelectionMap:i}){const o=gt.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Dt,{open:l,onOpenChange:c,children:[e(Mt,{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(Ve,{className:"chevron "+(l?"rotated":"")})]})}),e(zt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:gt.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 It({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(et,{size:18}):e(He,{size:14})}),e("button",{type:"button",className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:e(tt,{size:14,style:{stroke:"black"}})})]})]})}function Rt({onAction:n,alignmentSelectionMap:i}){const o=mt.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Dt,{open:l,onOpenChange:c,children:[e(Mt,{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(Ve,{className:"chevron "+(l?"rotated":"")})]})}),e(zt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:mt.map(({id:o,label:r,icon:l})=>t("button",{type:"button",className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),c(!1)},children:[l,e("span",{className:"label",children:r})]},o))})})]})}function 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&&it(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(nt,{color:n,onChangeComplete:e=>{i(e.hex)}})}),document.body)]})}Lt&&"InputEvent"in window&&!Tt&&new window.InputEvent("input");const Wt=({content:n,direction:i="top",delay:o=400,children:l})=>{const[c,s]=a(!1),d=r(null);return t("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{d.current=window.setTimeout(()=>{s(!0)},o)},onMouseLeave:()=>{d.current&&clearTimeout(d.current),s(!1)},children:[l,c&&e("div",{className:`Lexical-Tooltip-Tip ${i}`,children:n})]})};function Pt(){const[i]=Qe(),[{color:o,bgColor:r},c]=a({color:"#000",bgColor:"#fff"}),s=()=>{const e=S();if(E(e)){const t=At(e,"color","#000"),n=At(e,"background","#fff");c({color:t,bgColor:n})}};l(()=>Et(i.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),i.registerCommand(I,()=>(s(),!1),1)),[i]);const d=({property:e,color:t})=>{i.update(()=>{const n=S();n&&xt(n,{[e]:t})})};return t(n,{children:[e(Wt,{content:"Font Color",direction:"bottom",children:e(Ht,{color:o,onChange:e=>{d({property:"color",color:e})},icon:e(Ke,{})})}),e(Wt,{content:"Background Color",direction:"bottom",children:e(Ht,{color:r,onChange:e=>{d({property:"background",color:e})},icon:e(Be,{})})})]})}function $t({blockType:i}){const[o]=Qe();return t(n,{children:[e(Wt,{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(ue,void 0):o.dispatchCommand(he,void 0)},children:e(We,{})})}),e(Wt,{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(ue,void 0):o.dispatchCommand(pe,void 0)},children:e(Pe,{})})})]})}const Kt=({src:n,altText:i,nodeKey:o,width:l,height:c,maxWidth:s,caption:d=""})=>{const[u]=Qe(),[h,p]=a(!1),[m,g]=a(d),f=r(null),b=r(null),v=r(null),y=r(null),x=e=>{if(!y.current||!b.current)return;const t=e.clientX-y.current.x,n=Math.min(s,Math.max(50,y.current.width+t)),i=n*b.current.ratio;b.current.width=n,b.current.height=i;const o=v.current?.querySelector("img");o&&(o.style.width=n+"px",o.style.height=i+"px")},w=()=>{if(!b.current)return;const{width:e,height:t}=b.current;u.update(()=>{const n=R(o);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),b.current=null,y.current=null,window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",w)},C=()=>{p(!1),u.update(()=>{const e=R(o);e&&"function"==typeof e.setCaption&&e.setCaption(m)})},_=()=>{g(d),p(!0),setTimeout(()=>f.current?.focus(),0)};return t("div",{ref:v,style:{display:"inline-block",position:"relative",maxWidth:s},children:[e("img",{src:n,alt:i,width:"inherit"===l?void 0:l,height:"inherit"===c?void 0:c,style:{maxWidth:"100%",display:"block"}}),(d||h)&&e("div",{style:{textAlign:"center",marginTop:4},children:h?e("input",{ref:f,className:"lte-input",style:{width:"100%",textAlign:"center"},value:m,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C()}}):e("span",{style:{fontSize:13,color:"#666",cursor:"text",display:"inline-block",minWidth:20,minHeight:18},onClick:_,children:d})}),!d&&!h&&e("div",{style:{textAlign:"center",marginTop:2},children:e("span",{style:{fontSize:12,color:"#999",cursor:"pointer"},onClick:_,children:"+ Add caption"})}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=v.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,i=t.naturalHeight/t.naturalWidth,o=n*i;y.current={x:e.clientX,y:e.clientY,width:n,height:o},b.current={width:n,height:o,ratio:i},window.addEventListener("mousemove",x),window.addEventListener("mouseup",w)},style:{position:"absolute",bottom:d||h?40:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Bt=e=>W(new jt(e)),Jt=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:Bt({src:t,altText:n,width:i??"inherit",height:o??"inherit"})}};class jt extends H{constructor({src:e="",altText:t="",maxWidth:n=1080,width:i="inherit",height:o="inherit",caption:r="",key:l}={src:"",altText:""}){super(l),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=i,this.__height=o,this.__caption=r}static getType(){return"image"}static clone(e){return new jt({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,caption:e.__caption,key:e.getKey()})}createDOM(){return document.createElement("span")}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}exportDOM(){const e=document.createElement("img");if(e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),this.__caption){const t=document.createElement("figure"),n=document.createElement("figcaption");return n.textContent=this.__caption,t.appendChild(e),t.appendChild(n),{element:t}}return{element:e}}static importDOM(){return{img:()=>({conversion:Jt,priority:1}),figure:()=>({conversion:e=>{const t=e.querySelector("img");if(!t)return null;const n=e.querySelector("figcaption"),i=n?.textContent||"",o=Jt(t);return o?.node instanceof jt&&i&&(o.node.__caption=i),o},priority:1})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height,caption:this.__caption}}static importJSON(e){return new jt({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height,caption:e.caption})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}setCaption(e){this.getWritable().__caption=e}decorate(){return e(Kt,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth,caption:this.__caption})}}function qt({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}async function Qt(e,{src:t,altText:n="",caption:i=""}){e.update(()=>{const e=Bt({src:t,altText:n,caption:i});K([e])})}function Yt({onImageUpload:n}){const[i]=Qe(),o=r(null),[c,d]=a(!1),[u,h]=a(""),[p,m]=a(""),[g,f]=a(""),[b,v]=a(),[y,x]=a(!1),w=s(async(e,t="",o="")=>{let r;r=n?await n(e):URL.createObjectURL(e),Qt(i,{src:r,altText:t,caption:o})},[i,n]);return l(()=>{const e=i.registerCommand(P,e=>{if(e instanceof ClipboardEvent){const t=e.clipboardData?.items;if(!t)return!1;for(const n of t)if(n.type.startsWith("image/")){e.preventDefault();const t=n.getAsFile();return t&&w(t,"","").catch(console.error),!0}}return!1},$);return()=>e()},[i,w]),t("div",{className:"lexical-text-editor-dialog",children:[e("input",{type:"file",ref:o,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&v(t),e.target.value=""}}),e("button",{type:"button",className:`size-8 lexical-btn ${c?"toolbarActive":"toolbar"} icon`,onClick:()=>d(e=>!e),children:e(je,{size:18})}),t(qt,{open:c,onClose:()=>d(!1),children:[e("div",{className:"lte-dialog-header",children:"Add Image"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Alt text",value:p,onChange:e=>m(e.target.value)}),e("input",{className:"lte-input",placeholder:"Caption",value:g,onChange:e=>f(e.target.value)}),e("input",{className:"lte-input",placeholder:"Add image by URL",value:u,onChange:e=>h(e.target.value)}),e("div",{className:"lte-divider",children:e("span",{children:"or"})}),t("button",{type:"button",className:"lexical-btn heading-trigger toolbar-active",onClick:()=>o.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[e(ot,{size:20}),e("span",{children:"Upload Image"})]}),b&&e("div",{className:"lte-file-name",children:b.name})]}),e("div",{className:"lte-dialog-footer",children:e("button",{type:"button",className:"lte-primary-btn",disabled:!u&&!b||y,onClick:async()=>{if(!y){if(b){x(!0);try{await w(b,p,g)}catch(e){return console.error("Image upload failed:",e),void x(!1)}x(!1)}else{if(!u)return;Qt(i,{src:u,altText:p,caption:g})}v(void 0),m(""),f(""),h(""),d(!1)}},children:y?"Uploading...":"Add Image"})})]})]})}const Gt=({id:e,provider:t})=>new on({id:e,provider:t}),Xt="data-lexical-video",Vt="data-provider",Zt="315px",en="560px",tn=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,nn=e=>{const t=e?.getAttribute(Xt),n=e?.getAttribute(Vt)??"youtube";if(!t)return null;return{node:Gt({id:t,provider:n})}};class on extends H{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new on({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return Gt({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:Zt,width:en,src:tn(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Xt,this.__id),e.setAttribute(Vt,this.__provider),e.setAttribute("height",Zt),e.setAttribute("width",en),e.setAttribute("src",tn(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:nn,priority:0})}}}function rn(){const[n,i]=a(!1),[o,r]=a(!1),[c,s]=a(""),[d]=Qe();return l(()=>{n||(s(""),r(!1))},[n]),t("div",{className:"lexical-text-editor-dialog",children:[e("button",{type:"button",className:`size-8 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>i(!0),children:e(rt,{size:18,color:"red"})}),t(qt,{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=Gt({id:t,provider:e});K([n])}),s(""),r(!1),i(!1)):r(!0)},children:"Embed"})})]})]})}function ln({value:t}){return e("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:t}})}function cn({value:n,triggerLabel:i="Preview"}){const[o,r]=a(!1);return t("div",{className:"lexical-text-editor-dialog",children:[t("button",{type:"button",className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[e(lt,{size:18}),e("span",{children:i})]}),t(qt,{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(ln,{value:n})]})]})]})}const an=({value:n,onImageUpload:i})=>{const[o]=Qe(),[r,c]=a({[st.Undo]:!0,[st.Redo]:!0}),[d,g]=a(!1),[f,b]=a({[st.LeftAlign]:!0}),[v,y]=a({[dt.Normal]:!0}),[x,w]=a("paragraph"),[L,T]=a("https://");let D=!0;const M=()=>{if(D){const e=o.getRootElement();e&&(e.scrollTop=0,D=!1)}const e=S();if(E(e)){const t={[st.Bold]:e.hasFormat("bold"),[st.Italics]:e.hasFormat("italic"),[st.Underline]:e.hasFormat("underline"),[st.Uppercase]:e.hasFormat("uppercase"),[st.Lowercase]:e.hasFormat("lowercase"),[st.Capitalize]:e.hasFormat("capitalize"),[st.Strikethrough]:e.hasFormat("strikethrough"),[st.Superscript]:e.hasFormat("superscript"),[st.Subscript]:e.hasFormat("subscript"),[st.Code]:e.hasFormat("code"),[st.Highlight]:e.hasFormat("highlight")};b(t);const n=e.anchor.getNode(),i="root"===n.getKey()?n:n.getTopLevelElementOrThrow(),r=i.getKey();if(!o.getElementByKey(r))return;if(me(i)){const e=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(n,ge),t=e?e.getTag():i.getTag();w(t)}else if("paragraph"===i.getType()||u(i)){let e=null;u(i)&&(e=i.getTag());const t={[dt.H1]:"h1"===e,[dt.H2]:"h2"===e,[dt.H3]:"h3"===e,[dt.H4]:"h4"===e,[dt.H5]:"h5"===e,[dt.H6]:"h6"===e,[dt.Normal]:"paragraph"===i.getType()};w(i.getType()),y(t)}else w(i.getType());const l=(N(n)?n:i).getFormat();b(e=>({...e,[st.LeftAlign]:0===l||1===l,[st.CenterAlign]:2===l,[st.RightAlign]:3===l,[st.JustifyAlign]:4===l})),"quote"===i.getType()?b(e=>({...e,[st.Quote]:!0})):b(e=>({...e,[st.Quote]:!1}));const c=e.anchor.getNode(),a=c.getParent();Ge(a)?(b(e=>({...e,[st.Link]:!0})),T(a.getURL()),g(!0)):Ge(c)?(b(e=>({...e,[st.Link]:!0})),T(c.getURL()),g(!0)):(b(e=>({...e,[st.Link]:!1})),T("https://"),g(!1))}};l(()=>Et(o.registerUpdateListener(({editorState:e})=>{e.read(()=>{M()})}),o.registerCommand(I,()=>(M(),!1),1),o.registerCommand(J,e=>(c(t=>({...t,undo:!e})),!1),1),o.registerCommand(B,e=>(c(t=>({...t,redo:!e})),!1),1)),[]);const z=e=>{switch(e){case st.Bold:o.dispatchCommand(Y,"bold");break;case st.Italics:o.dispatchCommand(Y,"italic");break;case st.Underline:o.dispatchCommand(Y,"underline");break;case st.Lowercase:o.dispatchCommand(Y,"lowercase");break;case st.Uppercase:o.dispatchCommand(Y,"uppercase");break;case st.Capitalize:o.dispatchCommand(Y,"capitalize");break;case st.Strikethrough:o.dispatchCommand(Y,"strikethrough");break;case st.Superscript:o.dispatchCommand(Y,"superscript");break;case st.Subscript:o.dispatchCommand(Y,"subscript");break;case st.Highlight:o.dispatchCommand(Y,"highlight");break;case st.Code:o.dispatchCommand(Y,"code");break;case st.Quote:o.update(()=>{const e=S();if(E(e)){const t=e.anchor.getNode().getParent();t&&h(t)?function(e,t,n=wt){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=_(e.getNode(),k),l=_(t.getNode(),k);N(n)&&o.set(n.getKey(),n),N(l)&&o.set(l.getKey(),l)}for(const t of e.getNodes())if(N(t)&&k(t))o.set(t.getKey(),t);else if(null===i){const e=_(t,k);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())&&A(r)}(e,()=>G()):kt(e,()=>p())}});break;case st.Link:O(),g(!0);break;case st.LeftAlign:o.dispatchCommand(Q,"left");break;case st.RightAlign:o.dispatchCommand(Q,"right");break;case st.CenterAlign:o.dispatchCommand(Q,"center");break;case st.JustifyAlign:o.dispatchCommand(Q,"justify");break;case st.Undo:o.dispatchCommand(q,void 0);break;case st.Redo:o.dispatchCommand(j,void 0)}},O=s(()=>{o.update(()=>{const e=S();E(e)&&!e.isCollapsed()&&(d?o.dispatchCommand(Ye,null):""!==L&&o.dispatchCommand(Ye,L))})},[o,d,L]),U=s(()=>{T(""),o.dispatchCommand(Ye,null),g(!1)},[o]);return t("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[pt.map(({id:t,label:n,icon:i})=>t===st.Divider?e(Ut,{},t):e(Wt,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${f[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>z(t),disabled:!!r[t],children:i})},n)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Ft,{updateHeading:e=>{o.update(()=>{const t=S();E(t)&&kt(t,"normal"===e?()=>G():()=>m(e))})},headingSelectionMap:v}),e(Ut,{})]}),ht.map(({id:t,label:n,icon:i})=>t===st.Divider?e(Ut,{},t):e(Wt,{content:n,direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${f[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>z(t),children:i})},t)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e($t,{blockType:x}),e(Ut,{})]}),e(Pt,{}),e(Ot,{onAction:z,selectionMap:f}),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Rt,{onAction:z,alignmentSelectionMap:f}),e(Ut,{})]}),e(Wt,{content:"Link",direction:"bottom",children:e("button",{type:"button",className:`size-8 lexical-btn ${f[st.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>z(st.Link),disabled:!!r[st.Link],children:e(Ze,{})})}),d&&e(It,{linkUrl:L,setLinkUrl:T,removeLink:U,onConfirm:e=>{o.dispatchCommand(Ye,{url:e,target:"_blank"}),T(e),g(!1)},onCancel:()=>{T(""),g(!1)}}),e(Yt,{onImageUpload:i}),e(rn,{}),e(cn,{value:n})]})};function sn(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=X().getChildren();for(let o=0;o<i.length;o++)dn(e,i[o],n,t);return n.innerHTML}function dn(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=te(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]=z(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=ne(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=dn(e,r,h,i);!o&&N(t)&&l&&t.extractWithChild(r,i,"html")&&(o=!0)}if(o&&!r){if((ie(d)||oe(d))&&d.append(h),n.append(d),u){const e=u.call(l,d);e&&(oe(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(h);return o}const un=new Set(["STYLE","SCRIPT"]);function hn(e,t,n,i,o=new Map,r){let l=[];if(un.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||!L(c))&&(null!=c&&re(c)||i);for(let e=0;e<u.length;e++)h.push(...hn(u[e],t,n,p,new Map(o),c));return null!=d&&(h=d(h)),le(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(re(l))i&&!l.getFormat()&&l.setFormat(i),o.push(l);else if(r.push(l),e===t.length-1||e<t.length-1&&re(t[e+1])){const e=n();e.setFormat(i),e.append(...r),o.push(e),r=[]}}return o}(e,h,p?()=>{const e=new Z;return n.push(e),e}:G)),null==c?h.length>0?l=l.concat(h):le(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(ce(e.nextSibling)&&ce(e.previousSibling))}(e)&&(l=l.concat(ee())):N(c)&&c.append(...h),l}function pn({value:t,onChange:n}){const[i]=Qe(),[o,r]=a(!0);return l(()=>{t&&o&&(r(!1),i.update(()=>{if(sn(i)!==t){X().clear();const e=(new DOMParser).parseFromString(t,"text/html"),n=function(e,t){const n=V(t)?t.body.childNodes:t.childNodes;let i=[];const o=[];for(const t of n)if(!un.has(t.nodeName)){const n=hn(t,e,o,!1);null!==n&&(i=i.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof Z&&t.insertAfter(ee());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(o),i}(i,e);K(n)}}))},[i,t,o]),l(()=>{r(!0)},[t]),e(at,{onChange:e=>{e.read(()=>{n(sn(i))})}})}const mn=({id:e})=>new xn({id:e}),gn="data-lexical-youtube",fn="315px",bn="560px",vn=e=>`https://www.youtube-nocookie.com/embed/${e}`,yn=e=>{const t=e?.getAttribute(gn);if(!t)return null;return{node:mn({id:t})}};class xn extends H{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new xn({id:e.__id,key:e.getKey()})}static importJSON(e){return mn({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:fn,width:bn,src:vn(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(gn,this.__id),e.setAttribute("height",fn),e.setAttribute("width",bn),e.setAttribute("src",vn(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:yn,priority:0})}}}class wn extends ae{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new wn(e.__text,e.__key)}static importDOM(){const e=ae.importDOM();return{...e,span:()=>({conversion:Cn(e?.span),priority:1}),div:()=>({conversion:Cn(e?.div),priority:1}),p:()=>({conversion:Cn(e?.p),priority:1}),b:()=>({conversion:Cn(e?.b),priority:1}),strong:()=>({conversion:Cn(e?.strong),priority:1}),i:()=>({conversion:Cn(e?.i),priority:1}),em:()=>({conversion:Cn(e?.em),priority:1}),u:()=>({conversion:Cn(e?.u),priority:1}),s:()=>({conversion:Cn(e?.s),priority:1}),strike:()=>({conversion:Cn(e?.strike),priority:1}),code:()=>({conversion:Cn(e?.code),priority:1})}}static importJSON(e){return function(e=""){return W(new wn(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function Cn(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 _n={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"},kn=o.memo(function({name:n,value:o,onChange:r,placeholder:l,maxWidth:c=null,height:a=null,onImageUpload:s}){const u=d(()=>({namespace:n,theme:_n,onError:e=>{console.error("Lexical error:",e)},nodes:[wn,{replace:ae,with:e=>new wn(e.__text),withKlass:wn},g,b,v,ge,fe,f,Xe,jt,xn,on]}),[n]);return e("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:c||"1090px"},children:t(i,{initialConfig:u,children:[e("div",{className:"lexical-toolbar-container",children:e(an,{value:o,onImageUpload:s})}),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(se,{}),e(de,{}),e(ct,{}),e(pn,{value:o,onChange:r})]})})});export{kn as LexicalTextEditor};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|