@innoviatech/lexical-text-editor 1.0.6 → 2.0.1

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.
Files changed (46) hide show
  1. package/README.md +107 -36
  2. package/dist/components/ContentPreview.d.ts +1 -1
  3. package/dist/components/HeadingSelectionList.d.ts +1 -1
  4. package/dist/components/LexicalTextEditor.d.ts +1 -1
  5. package/dist/components/common/Dialog.d.ts +9 -0
  6. package/dist/components/common/Popover.d.ts +21 -0
  7. package/dist/components/common/Tooltip.d.ts +10 -0
  8. package/dist/components/ui/button.d.ts +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.esm.js +1 -1
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lexical-editor.css +1 -0
  15. package/dist/nodes/ExtendedTextNode.d.ts +11 -0
  16. package/dist/nodes/ImageNode.d.ts +10 -14
  17. package/dist/plugins/YoutubePlugin.d.ts +1 -0
  18. package/editor_screenshot.png +0 -0
  19. package/innoviatech-lexical-text-editor-2.0.0.tgz +0 -0
  20. package/package.json +20 -16
  21. package/rollup.config.js +3 -4
  22. package/src/components/AlignmentSelectionList.tsx +41 -24
  23. package/src/components/ColorPicker.tsx +7 -21
  24. package/src/components/ContentPreview.tsx +26 -20
  25. package/src/components/DropdownList.tsx +39 -24
  26. package/src/components/HeadingSelectionList.tsx +48 -32
  27. package/src/components/ImageComponent.tsx +52 -19
  28. package/src/components/InsertDropdownList.tsx +1 -1
  29. package/src/components/LexicalTextEditor.tsx +33 -28
  30. package/src/components/LinkModal.tsx +42 -45
  31. package/src/components/common/Dialog.tsx +47 -0
  32. package/src/components/common/Popover.tsx +87 -0
  33. package/src/components/common/Tooltip.tsx +43 -0
  34. package/src/components/ui/command.tsx +0 -1
  35. package/src/nodes/ExtendedTextNode.tsx +174 -0
  36. package/src/nodes/ImageNode.tsx +87 -48
  37. package/src/plugins/ColorPlugin.tsx +19 -14
  38. package/src/plugins/ImagePlugin.tsx +79 -84
  39. package/src/plugins/ListPlugin.tsx +20 -38
  40. package/src/plugins/ToolbarPlugin.tsx +76 -78
  41. package/src/plugins/VideoPlugin.tsx +46 -55
  42. package/src/plugins/YoutubePlugin.tsx +83 -0
  43. package/src/styles/lexical-editor.css +961 -3
  44. package/dist/style.css +0 -3
  45. package/postcss.config.js +0 -6
  46. package/src/assets/react.svg +0 -1
package/README.md CHANGED
@@ -1,6 +1,19 @@
1
- # @innoviatech/lexical-text-editor
1
+ # @innoviatech/lexical-text-editor v2.0
2
+
3
+ A powerful, customizable rich text editor component built with Lexical and React. Features a modern toolbar, image support, video embedding, and comprehensive text formatting options.
4
+
5
+ ![Editor preview](./editor_screenshot.png)
6
+
7
+ ## What's New in v2.0
8
+
9
+ - **No Tailwind CSS Required** - Now uses raw CSS for styling
10
+ - **Reduced Dependencies** - Fewer peer dependencies to install
11
+ - **Simpler Setup** - Import CSS and start using immediately
12
+ - **Lightweight** - Smaller bundle size
13
+ - **Better Compatibility** - Works with any React project setup
14
+
15
+
2
16
 
3
- A powerful, customizable rich text editor component built with Lexical, React, and Tailwind CSS. Features a modern toolbar, image support, video embedding, and comprehensive text formatting options.
4
17
 
5
18
  ## Features
6
19
 
@@ -11,10 +24,9 @@ A powerful, customizable rich text editor component built with Lexical, React, a
11
24
  - 🎯 **Customizable Toolbar** — Modern, intuitive interface
12
25
  - 🎨 **Color Picker** — Text and background color options
13
26
  - 📱 **Responsive Design** — Works on desktop and mobile
14
- - 🎪 **Radix UI Components** — Accessible, well-designed UI elements
15
27
  - ⚡ **TypeScript Support** — Fully typed for better development experience
16
28
 
17
- ---
29
+
18
30
 
19
31
  ## Installation
20
32
 
@@ -22,19 +34,9 @@ A powerful, customizable rich text editor component built with Lexical, React, a
22
34
  npm install @innoviatech/lexical-text-editor
23
35
  ```
24
36
 
25
- ### Peer Dependencies
26
-
27
- This package requires several peer dependencies. Make sure to install them in your project:
28
-
29
- ```bash
30
- # UI dependencies (required for full functionality)
31
- npm install react-icons lucide-react @radix-ui/react-slot @radix-ui/react-tooltip @radix-ui/react-popover @radix-ui/react-dialog clsx tailwind-merge class-variance-authority react-color
32
- ```
33
-
34
- ### Configure Tailwind CSS
35
- Setup tailwindcss according to the offical installation process:
37
+ ### No Peer Dependencies Required! 🎉
36
38
 
37
- Link: https://tailwindcss.com/docs/installation
39
+ Version 2.0 eliminates the need for Tailwind CSS and multiple UI libraries. Just install the package and start using it!
38
40
 
39
41
 
40
42
  ## Quick Start
@@ -48,21 +50,21 @@ function App() {
48
50
  const [content, setContent] = useState('');
49
51
 
50
52
  return (
51
- <div className='p-5 mx-auto'>
53
+ <>
52
54
  <LexicalTextEditor
53
55
  name="my-editor"
54
56
  value={content}
55
57
  onChange={setContent}
56
58
  placeholder="Start typing your content here..."
57
59
  />
58
- </div>
60
+ </>
59
61
  );
60
62
  }
61
63
 
62
64
  export default App;
63
65
  ```
64
66
 
65
- ---
67
+
66
68
 
67
69
  ## Props
68
70
 
@@ -70,12 +72,12 @@ export default App;
70
72
  |-------------|-------------------------------------|----------|---------------|---------------------------------------------|
71
73
  | `name` | `string` | Yes | — | Unique identifier for the editor instance |
72
74
  | `value` | `string` | Yes | — | Current editor content (HTML string) |
73
- | `width` | `string` | No | "1090px" | Adjust the width accoding to the need ('100%' or '100px') |
74
- | `height` | `string` | No | "500px" | Adjust the height accoding to the need ('100vh' or '100px') |
75
75
  | `onChange` | `(value: string) => void` | Yes | — | Callback fired when content changes |
76
76
  | `placeholder`| `string` | No | `"Some Text"` | Placeholder text when editor is empty |
77
+ | `maxWidth` | `string` | No | "1090px" | Adjust the maximum width accoding to the need ('80%' or '800px') |
78
+ | `height` | `string` | No | "500px" | Adjust the height accoding to the need ('50vh' or '500px') |
79
+
77
80
 
78
- ---
79
81
 
80
82
  ## Advanced Usage
81
83
 
@@ -94,15 +96,17 @@ function App() {
94
96
  };
95
97
 
96
98
  return (
97
- <div>
99
+ <form onSubmit={handleSave}>
98
100
  <LexicalTextEditor
99
101
  name="content-editor"
100
102
  value={content}
101
103
  onChange={setContent}
102
104
  placeholder="Write your content..."
105
+ maxWidth="600px"
106
+ height="400px"
103
107
  />
104
- <button onClick={handleSave}>Save Content</button>
105
- </div>
108
+ <button type="submit">Save Content</button>
109
+ </form>
106
110
  );
107
111
  }
108
112
 
@@ -124,7 +128,6 @@ export default App;
124
128
  - Quotes: Blockquote formatting
125
129
  - Undo/Redo, Clear formatting, Remove link
126
130
 
127
- ---
128
131
 
129
132
  ## Browser Support
130
133
 
@@ -133,33 +136,101 @@ export default App;
133
136
  - Safari 14+
134
137
  - Edge 90+
135
138
 
136
- ---
137
139
 
138
140
  ## Troubleshooting
139
141
 
140
- - **Missing peer dependencies:** install required packages
142
+
141
143
  - **CSS not loading:** `import '@innoviatech/lexical-text-editor/style.css'`
142
- - **Icons not showing:** verify `react-icons` and `lucide-react`
143
- - **Toolbar not working:** ensure Radix UI peer deps installed
144
+ - **Editor not rendering:** Check that React 18+ or next.js 14+ is installed
145
+ - **TypeScript errors:** Update to TypeScript 5.0+
146
+ - **Missing styles:** Verify the CSS import path is correct
147
+
144
148
 
145
- ---
146
149
 
147
150
  ## Version Compatibility
148
151
 
149
152
  - React 18+
153
+ - Next.js 14+
150
154
  - Lexical 0.36.0+
151
155
  - TypeScript 5.0+
152
156
 
153
- ---
154
157
 
155
158
  ## License
156
159
 
157
160
  MIT © Innoviatech
158
161
 
159
- ---
162
+ ## Support & Community
163
+
164
+ ### Get Help
165
+
166
+ We're here to help you succeed with our editor! Here are the best ways to get support:
160
167
 
161
- ## Support
168
+ ### Report an Issue
169
+ Found a bug or experiencing problems?
170
+ 👉 [Open a GitHub Issue](https://github.com/technohaattech/Lexical-Text-Editor/issues)
162
171
 
163
- For issues and feature requests, open an issue on GitHub.
172
+ **Please include:**
173
+ - 📱 **Environment** (Browser, OS, React/Next.js version)
174
+ - 🔍 **Steps to reproduce**
175
+ - 🎯 **Expected vs Actual behavior**
176
+ - 📋 **Relevant code snippets**
177
+ - 🖼️ **Screenshots** (if applicable)
178
+
179
+ ### Request a Feature
180
+ Have an idea to make the editor even better?
181
+ ✨ [Submit a Feature Request](https://github.com/technohaattech/Lexical-Text-Editor/issues/new?template=feature_request.md)
182
+
183
+
184
+
185
+ ### Documentation
186
+ [Getting Started Guide](https://github.com/technohaattech/Lexical-Text-Editor)
187
+
188
+ ### Video Tutorials
189
+ - [Installation & Setup](https://youtube.com/playlist?list=...) *(Coming Soon!)*
190
+ - [Advanced Features](https://youtube.com/playlist?list=...) *(Coming Soon!)*
191
+ - [Integration Examples](https://youtube.com/playlist?list=...) *(Coming Soon!)*
192
+
193
+ ### Community
194
+ Join our growing community of developers:
195
+
196
+ | Platform | Link | Best For |
197
+ |----------|------|----------|
198
+ | **GitHub Discussions** | [Join Discussion](https://github.com/technohaattech/Lexical-Text-Editor/discussions) | Questions & ideas |
199
+
200
+
201
+ ### Contribute
202
+
203
+ Love our editor? Here's how you can contribute:
204
+
205
+ ### Ways to Contribute
206
+ - 📝 **Improve Documentation** – Help others learn
207
+ - 🔧 **Fix Bugs** – Submit pull requests
208
+ - ✨ **Add Features** – Extend functionality
209
+ - 🧪 **Write Tests** – Improve reliability
210
+ - 🌍 **Translate** – Help with localization
211
+ - 📣 **Spread the Word** – Star the repo, share with others
212
+
213
+
214
+ ### About Innoviatech
215
+
216
+
217
+ **Our Mission**
218
+
219
+ At Innoviatech, we believe that creating great digital experiences should be accessible to every developer. We build tools that empower teams to focus on what matters most.
220
+
221
+
222
+ **Built with Passion**
223
+
224
+ > "Great tools shouldn't get in the way of great ideas. That's why we build editors that feel like an extension of your creativity."
225
+
226
+
227
+
228
+ **Star Us on GitHub!**
229
+
230
+ If you find this project helpful, please consider giving it a star on GitHub. It helps us reach more developers like you!
231
+
232
+ [![Star on GitHub](https://img.shields.io/github/stars/technohaattech/Lexical-Text-Editor?style=social)](https://github.com/technohaattech/Lexical-Text-Editor)
233
+
234
+ ---
164
235
 
165
- Built with ❤️ by Innoviatech
236
+ *Made with ❤️ by the Innoviatech team*
@@ -6,5 +6,5 @@ type ContentPreviewDialogProps = {
6
6
  value: string;
7
7
  triggerLabel?: string;
8
8
  };
9
- export default function ContentPreviewDialog({ value, triggerLabel }: ContentPreviewDialogProps): import("react/jsx-runtime").JSX.Element;
9
+ export default function ContentPreviewDialog({ value, triggerLabel, }: ContentPreviewDialogProps): import("react/jsx-runtime").JSX.Element;
10
10
  export {};
@@ -1,4 +1,4 @@
1
- import { type HeadingTagType } from '@lexical/rich-text';
1
+ import { type HeadingTagType } from "@lexical/rich-text";
2
2
  interface Props {
3
3
  updateHeading: (heading: HeadingTagType | "normal") => void;
4
4
  headingSelectionMap: {
@@ -6,6 +6,6 @@ export interface LexiTexProps {
6
6
  placeholder?: string;
7
7
  name: string;
8
8
  height?: string | null | undefined;
9
- width?: string | null | undefined;
9
+ maxWidth?: string | null | undefined;
10
10
  }
11
11
  export declare const LexicalTextEditor: React.FC<LexiTexProps>;
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from "react";
2
+ interface Props {
3
+ open: boolean;
4
+ onClose: () => void;
5
+ children: ReactNode;
6
+ forPreview?: boolean;
7
+ }
8
+ export default function RawDialog({ open, onClose, forPreview, children }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ interface PopoverProps {
3
+ open: boolean;
4
+ onOpenChange: (open: boolean) => void;
5
+ children: React.ReactNode;
6
+ }
7
+ export declare function Popover({ open, onOpenChange, children }: PopoverProps): import("react/jsx-runtime").JSX.Element;
8
+ interface PopoverTriggerProps {
9
+ children: React.ReactNode;
10
+ triggerRef: React.RefObject<HTMLDivElement | null>;
11
+ }
12
+ export declare function PopoverTrigger({ children, triggerRef }: PopoverTriggerProps): import("react/jsx-runtime").JSX.Element;
13
+ interface PopoverContentProps {
14
+ open: boolean;
15
+ align?: "start" | "center" | "end";
16
+ onClose: () => void;
17
+ children: React.ReactNode;
18
+ contentRef: React.RefObject<HTMLDivElement | null>;
19
+ }
20
+ export declare function PopoverContent({ open, align, children, contentRef, }: PopoverContentProps): import("react/jsx-runtime").JSX.Element;
21
+ export {};
@@ -0,0 +1,10 @@
1
+ import React, { ReactNode } from "react";
2
+ import '../../styles/lexical-editor.css';
3
+ interface TooltipProps {
4
+ content: ReactNode;
5
+ direction?: "top" | "right" | "bottom" | "left";
6
+ delay?: number;
7
+ children: ReactNode;
8
+ }
9
+ declare const TooltipX: React.FC<TooltipProps>;
10
+ export default TooltipX;
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  declare const buttonVariants: (props?: {
3
- variant?: "link" | "default" | "toolbar" | "toolbarActive" | "destructive" | "outline" | "secondary" | "ghost";
3
+ variant?: "link" | "toolbar" | "toolbarActive" | "default" | "destructive" | "outline" | "secondary" | "ghost";
4
4
  size?: "icon" | "default" | "sm" | "lg";
5
5
  } & {
6
6
  className?: string;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ interface LexiTexProps {
6
6
  placeholder?: string;
7
7
  name: string;
8
8
  height?: string | null | undefined;
9
- width?: string | null | undefined;
9
+ maxWidth?: string | null | undefined;
10
10
  }
11
11
  declare const LexicalTextEditor: React.FC<LexiTexProps>;
12
12
 
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as t,Fragment as i}from"react/jsx-runtime";import{LexicalComposer as n}from"@lexical/react/LexicalComposer";import*as r from"react";import o,{useState as a,useRef as l,useEffect as s,useCallback as c,useMemo as d}from"react";import{$isHeadingNode as u,$isQuoteNode as h,$createQuoteNode as m,$createHeadingNode as p,HeadingNode as g,QuoteNode as f}from"@lexical/rich-text";import{CodeHighlightNode as b,CodeNode as x}from"@lexical/code";import{RichTextPlugin as v}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as y}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as w}from"@lexical/react/LexicalErrorBoundary";import{HistoryPlugin as C}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as N}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as k,INSERT_ORDERED_LIST_COMMAND as _,INSERT_UNORDERED_LIST_COMMAND as A,$isListNode as z,ListNode as S,ListItemNode as L}from"@lexical/list";import{RxLetterCaseLowercase as T,RxLetterCaseUppercase as D,RxLetterCaseCapitalize as E}from"react-icons/rx";import{TbBold as O,TbItalic as M,TbUnderline as F}from"react-icons/tb";import{BsSuperscript as H,BsSubscript as U,BsChatSquareQuote as P,BsArrowCounterclockwise as R,BsArrowClockwise as I,BsJustifyLeft as K,BsTextCenter as B,BsJustifyRight as W,BsJustify as j,BsTextParagraph as J,BsTypeH1 as $,BsTypeH2 as Q,BsTypeH3 as q,BsTypeH4 as Y,BsTypeH5 as V,BsTypeH6 as X,BsListOl as G,BsListUl as Z}from"react-icons/bs";import{AiOutlineStrikethrough as ee,AiOutlineFontColors as te,AiOutlineBgColors as ie}from"react-icons/ai";import{IoCodeSlashOutline as ne,IoImageOutline as re}from"react-icons/io5";import{PiHighlighterLight as oe}from"react-icons/pi";import{useLexicalComposerContext as ae}from"@lexical/react/LexicalComposerContext";import{$createRangeSelection as le,$findMatchingParent as se,INTERNAL_$isBlock as ce,$isElementNode as de,$getSelection as ue,$setSelection as he,$isRootOrShadowRoot as me,$hasAncestor as pe,$isRangeSelection as ge,$isTextNode as fe,$isTokenOrSegmented as be,$getCharacterOffsets as xe,$isLeafNode as ve,$getPreviousSelection as ye,$caretRangeFromSelection as we,SELECTION_CHANGE_COMMAND as Ce,$getNodeByKey as Ne,DecoratorNode as ke,$applyNodeReplacement as _e,$insertNodes as Ae,CAN_REDO_COMMAND as ze,CAN_UNDO_COMMAND as Se,REDO_COMMAND as Le,UNDO_COMMAND as Te,FORMAT_ELEMENT_COMMAND as De,FORMAT_TEXT_COMMAND as Ee,$createParagraphNode as Oe,$getRoot as Me,isDOMDocumentNode as Fe,ArtificialNode__DO_NOT_USE as He,$createLineBreakNode as Ue,$cloneWithProperties as Pe,getRegisteredNode as Re,isHTMLElement as Ie,isDocumentFragment as Ke,$isBlockElementNode as Be,isBlockDomNode as We,isInlineDomNode as je}from"lexical";import{TOGGLE_LINK_COMMAND as Je,$isLinkNode as $e,LinkNode as Qe}from"@lexical/link";import{Slot as qe}from"@radix-ui/react-slot";import{cva as Ye}from"class-variance-authority";import{clsx as Ve}from"clsx";import{twMerge as Xe}from"tailwind-merge";import*as Ge from"@radix-ui/react-tooltip";import*as Ze from"@radix-ui/react-popover";import{HiChevronDown as et}from"react-icons/hi2";import{IoIosLink as tt}from"react-icons/io";import{Check as it,Pencil as nt,XIcon as rt,Upload as ot}from"lucide-react";import{TiDeleteOutline as at}from"react-icons/ti";import{SketchPicker as lt}from"react-color";import{createPortal as st}from"react-dom";import*as ct from"@radix-ui/react-dialog";import{FaYoutube as dt}from"react-icons/fa";import{VscPreview as ut}from"react-icons/vsc";import{LinkPlugin as ht}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as mt}from"@lexical/react/LexicalOnChangePlugin";var pt,gt;!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(pt||(pt={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(gt||(gt={}));const ft=[{id:pt.Lowercase,icon:e(T,{}),label:"Lowercase"},{id:pt.Uppercase,icon:e(D,{}),label:"Uppercase"},{id:pt.Capitalize,icon:e(E,{}),label:"Capitalize"},{id:pt.Strikethrough,icon:e(ee,{}),label:"Strikethrough"},{id:pt.Highlight,icon:e(oe,{}),label:"Highlight",fontSize:10},{id:pt.Superscript,icon:e(H,{}),label:"Superscript"},{id:pt.Subscript,icon:e(U,{}),label:"Subscript"}],bt=[{id:pt.Bold,icon:e(O,{}),label:"Bold"},{id:pt.Italics,icon:e(M,{}),label:"Italics"},{id:pt.Underline,icon:e(F,{}),label:"Underline"},{id:pt.Divider},{id:pt.Quote,icon:e(P,{}),label:"Quote"},{id:pt.Code,icon:e(ne,{}),label:"Code"}],xt=[{id:pt.Undo,icon:e(R,{}),label:"Undo"},{id:pt.Redo,icon:e(I,{}),label:"Redo"},{id:pt.Divider}],vt=[{id:pt.LeftAlign,icon:e(K,{}),label:"Left Align"},{id:pt.CenterAlign,icon:e(B,{}),label:"Center Align"},{id:pt.RightAlign,icon:e(W,{}),label:"Right Align"},{id:pt.JustifyAlign,icon:e(j,{}),label:"Justify Align"}],yt=[{id:"normal",label:"Normal",icon:e(J,{})},{id:"h1",label:"Heading 1",icon:e($,{})},{id:"h2",label:"Heading 2",icon:e(Q,{})},{id:"h3",label:"Heading 3",icon:e(q,{})},{id:"h4",label:"Heading 4",icon:e(Y,{})},{id:"h5",label:"Heading 5",icon:e(V,{})},{id:"h6",label:"Heading 6",icon:e(X,{})}];function wt(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 Ct=new Map;function Nt(e){let t=Ct.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),Ct.set(e,t)),t}function kt(e,t){(ge(e)?e.isCollapsed():fe(e)||de(e))||wt(280);const i=Nt(ge(e)?e.style:fe(e)?e.getStyle():e.getTextStyle()),n=Object.entries(t).reduce((t,[n,r])=>("function"==typeof r?t[n]=r(i[n],e):null===r?delete t[n]:t[n]=r,t),{...i}),r=function(e){let t="";for(const i in e)i&&(t+=`${i}: ${e[i]};`);return t}(n);ge(e)||fe(e)?e.setStyle(r):e.setTextStyle(r),Ct.set(r,n)}function _t(e,t){if(ge(e)&&e.isCollapsed()){kt(e,t);const i=e.anchor.getNode();de(i)&&i.isEmpty()&&kt(i,t)}!function(e){const t=ue();if(!t)return;const i=new Map,n=e=>i.get(e.getKey())||[0,e.getTextContentSize()];if(ge(t))for(const e of we(t).getTextSlices())e&&i.set(e.caret.origin.getKey(),e.getSliceIndices());const r=t.getNodes();for(const t of r){if(!fe(t)||!t.canHaveFormat())continue;const[i,r]=n(t);r!==i&&(be(t)||0===i&&r===t.getTextContentSize()?e(t):e(t.splitText(i,r)[0===i?0:1]))}ge(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:r,type:o}=t;t.set(i.key,i.offset,i.type),i.set(n,r,o)}}(t)}(e=>{kt(e,t)})}function At(e,t){const i=e.getFormatType(),n=e.getIndent();i!==t.getFormatType()&&t.setFormat(i),n!==t.getIndent()&&t.setIndent(n)}function zt(e){return e.getNode().isAttached()}function St(e){let t=e;for(;null!==t&&!me(t);){const e=t.getLatest(),i=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=i}}function Lt(e,t,i=null){const n=e.getStartEndPoints(),r=n?n[0]:null,o=e.getNodes(),a=o.length;if(null!==r&&(0===a||1===a&&"element"===r.type&&0===r.getNode().getChildrenSize())){const e="text"===r.type?r.getNode().getParentOrThrow():r.getNode(),n=e.getChildren();let o=t();return o.setFormat(e.getFormatType()),o.setIndent(e.getIndent()),n.forEach(e=>o.append(e)),i&&(o=i.append(o)),void e.replace(o)}let l=null,s=[];for(let n=0;n<a;n++){const r=o[n];me(r)?(Tt(e,s,s.length,t,i),s=[],l=r):null===l||null!==l&&pe(r,l)?s.push(r):(Tt(e,s,s.length,t,i),s=[r])}Tt(e,s,s.length,t,i)}function Tt(e,t,i,n,r=null){if(0===t.length)return;const o=t[0],a=new Map,l=[];let s=de(o)?o:o.getParentOrThrow();s.isInline()&&(s=s.getParentOrThrow());let c=!1;for(;null!==s;){const e=s.getPreviousSibling();if(null!==e){s=e,c=!0;break}if(s=s.getParentOrThrow(),me(s))break}const d=new Set;for(let e=0;e<i;e++){const i=t[e];de(i)&&0===i.getChildrenSize()&&d.add(i.getKey())}const u=new Set;for(let e=0;e<i;e++){const i=t[e];let r=i.getParent();if(null!==r&&r.isInline()&&(r=r.getParent()),null!==r&&ve(i)&&!u.has(i.getKey())){const e=r.getKey();if(void 0===a.get(e)){const t=n();t.setFormat(r.getFormatType()),t.setIndent(r.getIndent()),l.push(t),a.set(e,t),r.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),de(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),St(r)}}else if(d.has(i.getKey())){de(i)||wt(179);const e=n();e.setFormat(i.getFormatType()),e.setIndent(i.getIndent()),l.push(e),i.remove(!0)}}if(null!==r)for(let e=0;e<l.length;e++){const t=l[e];r.append(t)}let h=null;if(me(s))if(c)if(null!==r)s.insertAfter(r);else for(let e=l.length-1;e>=0;e--){const t=l[e];s.insertAfter(t)}else{const e=s.getFirstChild();if(de(e)&&(s=e),null===e)if(r)s.append(r);else for(let e=0;e<l.length;e++){const t=l[e];s.append(t),h=t}else if(null!==r)e.insertBefore(r);else for(let t=0;t<l.length;t++){const i=l[t];e.insertBefore(i),h=i}}else if(r)s.insertAfter(r);else for(let e=l.length-1;e>=0;e--){const t=l[e];s.insertAfter(t),h=t}const m=ye();ge(m)&&zt(m.anchor)&&zt(m.focus)?he(m.clone()):null!==h?h.selectEnd():e.dirty=!0}function Dt(e,t,i){const n=Nt(e.getStyle());return null!==n&&n[t]||i}function Et(e,t,i=""){let n=null;const r=e.getNodes(),o=e.anchor,a=e.focus,l=e.isBackward(),s=l?a.offset:o.offset,c=l?a.getNode():o.getNode();if(ge(e)&&e.isCollapsed()&&""!==e.style){const i=Nt(e.style);if(null!==i&&t in i)return i[t]}for(let e=0;e<r.length;e++){const o=r[e];if((0===e||0!==s||!o.is(c))&&fe(o)){const e=Dt(o,t,i);if(null===n)n=e;else if(n!==e){n="";break}}}return null===n?i:n}const Ot="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Mt=Ot&&"documentMode"in document?document.documentMode:null;function Ft(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Ht(...e){return Xe(Ve(e))}Ot&&"InputEvent"in window&&!Mt&&new window.InputEvent("input");const Ut=Ye("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"}}),Pt=r.forwardRef(({className:t,variant:i,size:n,asChild:r=!1,...o},a)=>e(r?qe:"button",{"data-slot":"button",className:Ht(Ut({variant:i,size:n,className:t})),ref:a,...o}));function Rt({delayDuration:t=0,...i}){return e(Ge.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...i})}function It({...t}){return e(Rt,{children:e(Ge.Root,{"data-slot":"tooltip",...t})})}function Kt({...t}){return e(Ge.Trigger,{"data-slot":"tooltip-trigger",...t})}function Bt({className:i,sideOffset:n=0,children:r,...o}){return e(Ge.Portal,{children:t(Ge.Content,{"data-slot":"tooltip-content",sideOffset:n,className:Ht("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",i),...o,children:[r,e(Ge.Arrow,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function Wt({...t}){return e(Ze.Root,{"data-slot":"popover",...t})}function jt({...t}){return e(Ze.Trigger,{"data-slot":"popover-trigger",...t})}function Jt({className:t,align:i="center",sideOffset:n=4,...r}){return e(Ze.Portal,{children:e(Ze.Content,{"data-slot":"popover-content",align:i,sideOffset:n,className:Ht("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),...r})})}function $t({onAction:i,selectionMap:n}){const[r,o]=a(!1);return t(Wt,{open:r,onOpenChange:e=>o(e),children:[e(jt,{asChild:!0,children:t(Pt,{variant:r?"toolbarActive":"toolbar",onClick:()=>o(!r),size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e("span",{children:"Aa"})," ",e(et,{className:" transition-normal duration-100 "+(r?"rotate-180":"rotate-0")})]})}),e(Jt,{className:"p-2 w-fit flex flex-col items-start gap-1",children:ft.map(({id:r,label:o,icon:a})=>t(Pt,{variant:n[r]?"toolbarActive":"toolbar",onClick:()=>i(r),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e("span",{className:"ml-2",children:o})]},r))})]})}function Qt(){return e("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function qt({updateHeading:i,headingSelectionMap:n}){const r=yt.find(e=>n[e.id]),[o,l]=a(!1);return t(Wt,{open:o,onOpenChange:e=>l(e),children:[e(jt,{asChild:!0,children:t(Pt,{variant:o?"toolbarActive":"toolbar",onClick:()=>l(!o),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[130px] border-[1px] border-gray-100",children:[r?.icon,e("span",{children:r?.label})," ",e(et,{className:" transition-normal duration-100 "+(o?"rotate-180":"rotate-0")})]})}),e(Jt,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:yt.map(({id:r,label:o,icon:a})=>t(Pt,{variant:n[r]?"toolbarActive":"toolbar",onClick:()=>i(r),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e("span",{className:"ml-2",children:o})]},r))})]})}function Yt({className:t,type:i,...n}){return e("input",{type:i,"data-slot":"input",className:Ht("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 Vt({linkUrl:i,setLinkUrl:n,onConfirm:r,onCancel:o,removeLink:c}){const[d,u]=a(!1),h=l(null),m=l(null);return s(()=>{"https://"===i&&u(!0)},[i]),s(()=>{d&&m.current?.focus()},[d]),s(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&o()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[o]),t("div",{ref:h,className:Ht("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("div",{className:"flex-1 min-w-[200px]",children:d?e(Yt,{ref:m,className:"h-8 text-sm",value:i,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),r(i),u(!1)):"Escape"===e.key&&(e.preventDefault(),u(!1),o())}}):e("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 text-sm underline truncate block max-w-full text-start",children:i})}),t("div",{children:[e(Pt,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:()=>{d?(r(i),u(!1)):u(!0)},className:"h-8 w-8",children:e(d?it:nt,{className:"h-4 w-4"})}),e(Pt,{variant:"ghost",size:"icon",onMouseDown:e=>e.preventDefault(),onClick:c,className:"h-8 w-8",children:e(at,{className:"h-4 w-4"})})]})]})}function Xt({onAction:i,alignmentSelectionMap:n}){const r=vt.find(e=>n[e.id]),[o,l]=a(!1);return t(Wt,{open:o,onOpenChange:e=>l(e),children:[e(jt,{asChild:!0,children:t(Pt,{variant:o?"toolbarActive":"toolbar",onClick:()=>l(!o),size:"icon",className:"size-8 w-fit p-2 select-none min-w-[145px] border-[1px] border-gray-100",children:[r?.icon,e("span",{children:r?.label})," ",e(et,{className:" transition-normal duration-100 "+(o?"rotate-180":"rotate-0")})]})}),e(Jt,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:vt.map(({id:r,label:o,icon:a})=>t(Pt,{variant:n[r]?"toolbarActive":"toolbar",onClick:()=>i(r),size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e("span",{className:"ml-2",children:o})]},r))})]})}function Gt({color:i,onChange:n,icon:r}){const[o,c]=a(!1),d=l(null),u=l(null);s(()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return t("div",{className:"relative inline-block",children:[e(Pt,{ref:d,variant:"ghost",size:"icon",className:"rounded-md text-gray-700 hover:bg-gray-200","aria-label":"Change Color",onClick:()=>c(e=>!e),children:r}),o&&st(e("div",{ref:u,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 "+(o?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"),style:{top:d.current?.getBoundingClientRect().bottom,left:d.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e(lt,{color:i,onChangeComplete:e=>{n(e.hex)}})}),document.body)]})}function Zt(){const[n]=ae(),[{color:r,bgColor:o},l]=a({color:"#000",bgColor:"#fff"}),c=()=>{const e=ue();if(ge(e)){const t=Et(e,"color","#000"),i=Et(e,"background","#fff");l({color:t,bgColor:i})}};s(()=>Ft(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{c()})}),n.registerCommand(Ce,()=>(c(),!1),1)),[n]);const d=({property:e,color:t})=>{n.update(()=>{const i=ue();i&&_t(i,{[e]:t})})};return t(i,{children:[e(Gt,{color:r,onChange:e=>{d({property:"color",color:e})},icon:e(te,{})}),e(Gt,{color:o,onChange:e=>{d({property:"background",color:e})},icon:e(ie,{})})]})}function ei({blockType:n}){const[r]=ae();return t(i,{children:[t(It,{delayDuration:700,children:[e(Kt,{asChild:!0,children:e(Pt,{variant:"ol"===n?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add ordered list",onClick:()=>{"ol"===n?r.dispatchCommand(k,void 0):r.dispatchCommand(_,void 0)},children:e(G,{})})}),e(Bt,{side:"bottom",children:"Ordered list"})]}),t(It,{delayDuration:700,children:[e(Kt,{asChild:!0,children:e(Pt,{variant:"ul"===n?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add unordered list",onClick:()=>{"ul"===n?r.dispatchCommand(k,void 0):r.dispatchCommand(A,void 0)},children:e(Z,{})})}),e(Bt,{side:"bottom",children:"Unordered list"})]})]})}Pt.displayName="Button";const ti=({src:i,altText:n,nodeKey:r,width:o,height:s,maxWidth:c})=>{const[d]=ae(),[u,h]=a({width:"number"==typeof o?o:c,height:"number"==typeof s?s:"auto"}),m=l(null),p=l(null),g=e=>{if(!p.current)return;const t=e.clientX-p.current.x,i=Math.min(c,Math.max(50,p.current.width+t)),n=i/p.current.width*p.current.height||"auto";h({width:i,height:n})},f=()=>{p.current&&(d.update(()=>{const e=Ne(r);e&&"function"==typeof e.updateDimensions&&e.updateDimensions(u.width,u.height)}),window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",f))};return t("div",{ref:m,style:{display:"inline-block",position:"relative",maxWidth:c},children:[e("img",{src:i,alt:n,style:{width:u.width,height:u.height,maxWidth:"100%",display:"block"}}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),p.current={x:e.clientX,y:e.clientY,width:u.width,height:m.current?.offsetHeight??0},window.addEventListener("mousemove",g),window.addEventListener("mouseup",f)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},ii=e=>_e(new ri(e)),ni=e=>{if(e instanceof HTMLImageElement){const{src:t,alt:i}=e;return{node:ii({src:t,altText:i})}}return null};class ri extends ke{constructor({src:e="",altText:t="",maxWidth:i=1080,width:n,height:r,key:o}={}){super(o),this.__altText=t,this.__src=e,this.__maxWidth=i,this.__height=r,this.__width=n}static getType(){return"image"}static clone(e){return new ri({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:ni,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 ri({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(ti,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function oi({...t}){return e(ct.Root,{"data-slot":"dialog",...t})}function ai({...t}){return e(ct.Trigger,{"data-slot":"dialog-trigger",...t})}function li({...t}){return e(ct.Portal,{"data-slot":"dialog-portal",...t})}function si({className:t,...i}){return e(ct.Overlay,{"data-slot":"dialog-overlay",className:Ht("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 ci({className:i,children:n,showCloseButton:r=!0,...o}){return t(li,{"data-slot":"dialog-portal",children:[e(si,{}),t(ct.Content,{"data-slot":"dialog-content","aria-describedby":"",className:Ht("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",i),...o,children:[n,r&&t(ct.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(rt,{}),e("span",{className:"sr-only",children:"Close"})]})]})]})}function di({className:t,...i}){return e("div",{"data-slot":"dialog-header",className:Ht("flex flex-col gap-2 text-center sm:text-left",t),...i})}function ui({className:t,...i}){return e("div",{"data-slot":"dialog-footer",className:Ht("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...i})}function hi({className:t,...i}){return e(ct.Title,{"data-slot":"dialog-title",className:Ht("text-lg leading-none font-semibold",t),...i})}function mi(){const[i,n]=a(!1),[r,o]=a(""),[s,c]=a(""),[d,u]=a(),h=l(null),[m]=ae();return t("div",{children:[e("input",{type:"file",ref:h,accept:"image/*",className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&u(t),e.target.value=""}}),t(oi,{open:i,onOpenChange:n,children:[e(ai,{asChild:!0,children:e(Pt,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e(re,{})})}),t(ci,{className:"sm:max-w-md",children:[e(di,{children:e(hi,{className:"!text-lg text-gray-800",children:"Add Image"})}),e("div",{className:"flex flex-col gap-4 py-2",children:t("div",{className:"flex flex-col items-center gap-4",children:[e(Yt,{value:s,onChange:e=>c(e.target.value),placeholder:"Alt text"}),e(Yt,{value:r,onChange:e=>o(e.target.value),placeholder:"Add Image by URL"}),t("div",{className:"flex items-center w-full text-gray-500 text-sm",children:[e("div",{className:"flex-grow border-t border-gray-300"}),e("span",{className:"mx-2",children:"or"}),e("div",{className:"flex-grow border-t border-gray-300"})]}),t("div",{className:"flex flex-col gap-2 w-fit",children:[t(Pt,{variant:"outline",className:"flex items-center gap-2 bg-gray-50 hover:bg-gray-100",onClick:()=>h.current?.click(),children:[e(ot,{className:"h-4 w-4"})," Upload Image"]}),d&&e("span",{className:"text-sm text-gray-600",children:d.name})]})]})}),e(ui,{children:e(Pt,{onClick:()=>{let e="";r&&(e=r),d&&(e=URL.createObjectURL(d)),m.update(()=>{const t=ii({src:e,altText:s});Ae([t])}),u(void 0),c(""),o(""),n(!1)},disabled:!r&&!d,className:"!bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Add Image"})})]})]})]})}const pi=({id:e,provider:t})=>new wi({id:e,provider:t}),gi="data-lexical-video",fi="data-provider",bi="315px",xi="560px",vi=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,yi=e=>{const t=e?.getAttribute(gi),i=e?.getAttribute(fi)??"youtube";if(!t)return null;return{node:pi({id:t,provider:i})}};class wi extends ke{constructor({id:e,provider:t,key:i}){super(i),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new wi({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return pi({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:bi,width:xi,src:vi(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(gi,this.__id),e.setAttribute(fi,this.__provider),e.setAttribute("height",bi),e.setAttribute("width",xi),e.setAttribute("src",vi(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:yi,priority:0})}}}function Ci(){const[i,n]=a(!1),[r,o]=a(!1),[l,c]=a(""),[d]=ae();return s(()=>{i||(c(""),o(!1))},[i]),e("div",{children:t(oi,{open:i,onOpenChange:n,children:[e(ai,{asChild:!0,children:e(Pt,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e(dt,{})})}),t(ci,{className:"sm:max-w-md",children:[e(di,{children:e(hi,{className:"!text-lg text-gray-800",children:"Embed Video"})}),t("div",{className:"py-2",children:[e(Yt,{value:l,onChange:e=>c(e.target.value),placeholder:"Add YouTube or Google Drive URL"}),r&&e("p",{className:"mt-1.5 text-red-800/80 text-[0.8rem]",children:"It's not a valid youtube or google drive URL"})]}),e(ui,{children:e(Pt,{onClick:()=>{if(!l)return;let e=null,t=null;const i=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(l);i&&11===i[2]?.length&&(e="youtube",t=i[2]);const r=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(l);r&&r[1]&&(e="drive",t=r[1]),t&&e?(d.update(()=>{const i=pi({id:t,provider:e});Ae([i])}),c(""),o(!1),n(!1)):o(!0)},disabled:!l,className:"bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Embed"})})]})]})})}function Ni({value:t}){return e("div",{className:"prose max-w-none",dangerouslySetInnerHTML:{__html:t}})}function ki({value:i,triggerLabel:n="Preview"}){const[r,o]=a(!1);return t(oi,{open:r,onOpenChange:o,children:[e(ai,{asChild:!0,children:t(Pt,{variant:r?"toolbarActive":"toolbar",size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e(ut,{})," ",n]})}),t(ci,{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(di,{children:e(hi,{className:"!text-xl",children:"Content Preview"})}),t("div",{className:" p-[2vw] rounded-lg border min-h-[400px] w-full text-start bg-white",children:[e("div",{className:"py-1 border-b-2 mb-4 font-medium",children:"CONTENT"}),e(Ni,{value:i})]})]})]})}const _i=({value:i})=>{const[n]=ae(),[r,o]=a({[pt.Undo]:!0,[pt.Redo]:!0}),[l,d]=a(!1),[g,f]=a({[pt.LeftAlign]:!0}),[b,x]=a({[gt.Normal]:!0}),[v,y]=a("paragraph"),[w,C]=a("https://");let N=!0;const k=()=>{if(N){const e=n.getRootElement();e&&(e.scrollTop=0,N=!1)}const e=ue();if(ge(e)){const t={[pt.Bold]:e.hasFormat("bold"),[pt.Italics]:e.hasFormat("italic"),[pt.Underline]:e.hasFormat("underline"),[pt.Uppercase]:e.hasFormat("uppercase"),[pt.Lowercase]:e.hasFormat("lowercase"),[pt.Capitalize]:e.hasFormat("capitalize"),[pt.Strikethrough]:e.hasFormat("strikethrough"),[pt.Superscript]:e.hasFormat("superscript"),[pt.Subscript]:e.hasFormat("subscript"),[pt.Code]:e.hasFormat("code"),[pt.Highlight]:e.hasFormat("highlight")};f(t);const i=e.anchor.getNode(),r="root"===i.getKey()?i:i.getTopLevelElementOrThrow(),o=r.getKey();if(!n.getElementByKey(o))return;if(z(r)){const e=function(e,t){let i=e;for(;null!=i;){if(i instanceof t)return i;i=i.getParent()}return null}(i,S),t=e?e.getTag():r.getTag();y(t)}else if("paragraph"===r.getType()||u(r)){let e=null;u(r)&&(e=r.getTag());const t={[gt.H1]:"h1"===e,[gt.H2]:"h2"===e,[gt.H3]:"h3"===e,[gt.H4]:"h4"===e,[gt.H5]:"h5"===e,[gt.H6]:"h6"===e,[gt.Normal]:"paragraph"===r.getType()};x(t)}else y(r.getType());const a=(de(i)?i:r).getFormat();f(e=>({...e,[pt.LeftAlign]:0===a||1===a,[pt.CenterAlign]:2===a,[pt.RightAlign]:3===a,[pt.JustifyAlign]:4===a})),"quote"===r.getType()?f(e=>({...e,[pt.Quote]:!0})):f(e=>({...e,[pt.Quote]:!1}));const l=e.anchor.getNode(),s=l.getParent();$e(s)?(f(e=>({...e,[pt.Link]:!0})),C(s.getURL()),d(!0)):$e(l)?(f(e=>({...e,[pt.Link]:!0})),C(l.getURL()),d(!0)):(f(e=>({...e,[pt.Link]:!1})),C("https://"),d(!1))}};s(()=>Ft(n.registerUpdateListener(({editorState:e})=>{e.read(()=>{k()})}),n.registerCommand(Ce,()=>(k(),!1),1),n.registerCommand(Se,e=>(o(t=>({...t,undo:!e})),!1),1),n.registerCommand(ze,e=>(o(t=>({...t,redo:!e})),!1),1)),[]);const _=e=>{switch(e){case pt.Bold:n.dispatchCommand(Ee,"bold");break;case pt.Italics:n.dispatchCommand(Ee,"italic");break;case pt.Underline:n.dispatchCommand(Ee,"underline");break;case pt.Lowercase:n.dispatchCommand(Ee,"lowercase");break;case pt.Uppercase:n.dispatchCommand(Ee,"uppercase");break;case pt.Capitalize:n.dispatchCommand(Ee,"capitalize");break;case pt.Strikethrough:n.dispatchCommand(Ee,"strikethrough");break;case pt.Superscript:n.dispatchCommand(Ee,"superscript");break;case pt.Subscript:n.dispatchCommand(Ee,"subscript");break;case pt.Highlight:n.dispatchCommand(Ee,"highlight");break;case pt.Code:n.dispatchCommand(Ee,"code");break;case pt.Quote:n.update(()=>{const e=ue();if(ge(e)){const t=e.anchor.getNode().getParent();t&&h(t)?function(e,t,i=At){if(null===e)return;const n=e.getStartEndPoints(),r=new Map;let o=null;if(n){const[e,t]=n;o=le(),o.anchor.set(e.key,e.offset,e.type),o.focus.set(t.key,t.offset,t.type);const i=se(e.getNode(),ce),a=se(t.getNode(),ce);de(i)&&r.set(i.getKey(),i),de(a)&&r.set(a.getKey(),a)}for(const t of e.getNodes())if(de(t)&&ce(t))r.set(t.getKey(),t);else if(null===n){const e=se(t,ce);de(e)&&r.set(e.getKey(),e)}for(const[e,n]of r){const r=t();i(n,r),n.replace(r,!0),o&&(e===o.anchor.key&&o.anchor.set(r.getKey(),o.anchor.offset,o.anchor.type),e===o.focus.key&&o.focus.set(r.getKey(),o.focus.offset,o.focus.type))}o&&e.is(ue())&&he(o)}(e,()=>Oe()):Lt(e,()=>m())}});break;case pt.Link:A(),d(!0);break;case pt.LeftAlign:n.dispatchCommand(De,"left");break;case pt.RightAlign:n.dispatchCommand(De,"right");break;case pt.CenterAlign:n.dispatchCommand(De,"center");break;case pt.JustifyAlign:n.dispatchCommand(De,"justify");break;case pt.Undo:n.dispatchCommand(Te,void 0);break;case pt.Redo:n.dispatchCommand(Le,void 0)}},A=c(()=>{console.log("insertlink"),l?n.dispatchCommand(Je,null):""!==w&&n.dispatchCommand(Je,w)},[n,l]),L=c(()=>{C(""),n.dispatchCommand(Je,null),d(!1)},[n]);return t("div",{className:"relative flex gap-1.5 flex-wrap justify-center items-center p-1.5 pb-2 mb-1 border-b-[1px]",children:[xt.map(({id:i,label:n,icon:o})=>i===pt.Divider?e(Qt,{},i):t(It,{delayDuration:700,children:[e(Kt,{asChild:!0,children:e(Pt,{variant:g[i]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>_(i),disabled:!!r[i],children:o})}),e(Bt,{side:"bottom",children:n})]},i)),t("div",{className:"flex gap-1.5 justify-start items-center",children:[e(qt,{updateHeading:e=>{n.update(()=>{const t=ue();ge(t)&&Lt(t,"normal"===e?()=>Oe():()=>p(e))})},headingSelectionMap:b}),e(Qt,{})]}),bt.map(({id:i,label:n,icon:o})=>i===pt.Divider?e(Qt,{},i):t(It,{delayDuration:700,children:[e(Kt,{asChild:!0,children:e(Pt,{variant:g[i]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>_(i),disabled:!!r[i],children:o})}),e(Bt,{side:"bottom",children:n})]},i)),t("div",{className:"flex gap-1.5 justify-start items-center",children:[e(ei,{blockType:v}),e(Qt,{})]}),e(Zt,{}),e($t,{onAction:_,selectionMap:g}),t("div",{className:"flex gap-1.5 justify-start items-center",children:[e(Xt,{onAction:_,alignmentSelectionMap:g}),e(Qt,{})]}),t(It,{delayDuration:700,children:[e(Kt,{asChild:!0,children:e(Pt,{variant:g[pt.Link]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:()=>_(pt.Link),disabled:!!r[pt.Link],children:e(tt,{})})}),e(Bt,{side:"bottom",children:"Link"})]}),l&&e(Vt,{linkUrl:w,setLinkUrl:C,removeLink:L,onConfirm:e=>{n.dispatchCommand(Je,{url:e,target:"_blank"}),C(e),d(!1)},onCancel:()=>{C(""),d(!1)}}),e(mi,{}),e(Ci,{}),e(ki,{value:i})]})};function Ai(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=Me().getChildren();for(let r=0;r<n.length;r++)zi(e,n[r],i,t);return i.innerHTML}function zi(e,t,i,n=null){let r=null===n||t.isSelected(n);const o=de(t)&&t.excludeFromCopy("html");let a=t;if(null!==n){let e=Pe(t);e=fe(e)&&null!==n?function(e,t){const i=e.getStartEndPoints();if(t.isSelected(e)&&!be(t)&&null!==i){const[n,r]=i,o=e.isBackward(),a=n.getNode(),l=r.getNode(),s=t.is(a),c=t.is(l);if(s||c){const[i,n]=xe(e),r=a.is(l),s=t.is(o?l:a),c=t.is(o?a:l);let d,u=0;r?(u=i>n?n:i,d=i>n?i:n):s?(u=o?n:i,d=void 0):c&&(u=0,d=o?i:n),t.__text=t.__text.slice(u,d)}}return t}(n,e):e,a=e}const l=de(a)?a.getChildren():[],s=Re(e,a.getType());let c;c=s&&void 0!==s.exportDOM?s.exportDOM(e,a):a.exportDOM(e);const{element:d,after:u}=c;if(!d)return!1;const h=document.createDocumentFragment();for(let i=0;i<l.length;i++){const o=l[i],a=zi(e,o,h,n);!r&&de(t)&&a&&t.extractWithChild(o,n,"html")&&(r=!0)}if(r&&!o){if((Ie(d)||Ke(d))&&d.append(h),i.append(d),u){const e=u.call(a,d);e&&(Ke(d)?d.replaceChildren(e):d.replaceWith(e))}}else i.append(h);return r}const Si=new Set(["STYLE","SCRIPT"]);function Li(e,t,i,n,r=new Map,o){let a=[];if(Si.has(e.nodeName))return a;let l=null;const s=function(e,t){const{nodeName:i}=e,n=t._htmlConversions.get(i.toLowerCase());let r=null;if(void 0!==n)for(const t of n){const i=t(e);null!==i&&(null===r||(r.priority||0)<=(i.priority||0))&&(r=i)}return null!==r?r.conversion:null}(e,t),c=s?s(e):null;let d=null;if(null!==c){d=c.after;const t=c.node;if(l=Array.isArray(t)?t[t.length-1]:t,null!==l){for(const[,e]of r)if(l=e(l,o),!l)break;l&&a.push(...Array.isArray(t)?t:[l])}null!=c.forChild&&r.set(e.nodeName,c.forChild)}const u=e.childNodes;let h=[];const m=(null==l||!me(l))&&(null!=l&&Be(l)||n);for(let e=0;e<u.length;e++)h.push(...Li(u[e],t,i,m,new Map(r),l));return null!=d&&(h=d(h)),We(e)&&(h=function(e,t,i){const n=e.style.textAlign,r=[];let o=[];for(let e=0;e<t.length;e++){const a=t[e];if(Be(a))n&&!a.getFormat()&&a.setFormat(n),r.push(a);else if(o.push(a),e===t.length-1||e<t.length-1&&Be(t[e+1])){const e=i();e.setFormat(n),e.append(...o),r.push(e),o=[]}}return r}(e,h,m?()=>{const e=new He;return i.push(e),e}:Oe)),null==l?h.length>0?a=a.concat(h):We(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(je(e.nextSibling)&&je(e.previousSibling))}(e)&&(a=a.concat(Ue())):de(l)&&l.append(...h),a}function Ti({value:t,onChange:i}){const[n]=ae(),[r,o]=a(!0);return s(()=>{t&&r&&(o(!1),n.update(()=>{if(Ai(n)!==t){Me().clear();const e=(new DOMParser).parseFromString(t,"text/html"),i=function(e,t){const i=Fe(t)?t.body.childNodes:t.childNodes;let n=[];const r=[];for(const t of i)if(!Si.has(t.nodeName)){const i=Li(t,e,r,!1);null!==i&&(n=n.concat(i))}return function(e){for(const t of e)t.getNextSibling()instanceof He&&t.insertAfter(Ue());for(const t of e){const e=t.getChildren();for(const i of e)t.insertBefore(i);t.remove()}}(r),n}(n,e);Ae(i)}}))},[n,t,r]),s(()=>{o(!0)},[t]),e(mt,{onChange:e=>{e.read(()=>{i(Ai(n))})}})}const Di=({id:e})=>new Ui({id:e}),Ei="data-lexical-youtube",Oi="315px",Mi="560px",Fi=e=>`https://www.youtube-nocookie.com/embed/${e}`,Hi=e=>{const t=e?.getAttribute(Ei);if(!t)return null;return{node:Di({id:t})}};class Ui extends ke{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new Ui({id:e.__id,key:e.getKey()})}static importJSON(e){return Di({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:Oi,width:Mi,src:Fi(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Ei,this.__id),e.setAttribute("height",Oi),e.setAttribute("width",Mi),e.setAttribute("src",Fi(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Hi,priority:0})}}}const Pi={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"},Ri=o.memo(function({name:i,value:r,onChange:o,placeholder:a,width:l=null,height:s=null}){const c=d(()=>({namespace:i,theme:Pi,onError:e=>{console.error("Lexical error:",e)},nodes:[g,b,x,S,L,f,Qe,ri,Ui,wi]}),[i]);return e("div",{className:"lexical-text-editor border-[1px] rounded-lg pb-2 scrollbar-thin",style:{width:l||"",maxWidth:l?"":"1090px",height:s||"500px"},children:t(n,{initialConfig:c,children:[e("div",{className:"px-2",children:e(_i,{value:r})}),e("div",{className:"relative h-full",children:e(v,{contentEditable:e(y,{className:"text-start w-full h-full text-[14px] p-[8px] overflow-auto outline-0"}),placeholder:e("div",{className:"absolute text-[#999] top-[8px] left-[10px] text-[14px]",children:a||"Some Text"}),ErrorBoundary:w})}),e(C,{}),e(N,{}),e(ht,{}),e(Ti,{value:r,onChange:o})]})})});export{Ri 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 x}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as y}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as w}from"@lexical/react/LexicalErrorBoundary";import{$createRangeSelection as C,$findMatchingParent as k,INTERNAL_$isBlock as _,$isElementNode as N,$getSelection as S,$setSelection as L,$isRootOrShadowRoot as A,$hasAncestor as T,$isRangeSelection as E,$isTextNode as D,$isTokenOrSegmented as M,$getCharacterOffsets as O,$isLeafNode as z,$getPreviousSelection as F,$caretRangeFromSelection as R,SELECTION_CHANGE_COMMAND as H,$getNodeByKey as U,DecoratorNode as I,$applyNodeReplacement as P,$insertNodes as $,CAN_REDO_COMMAND as W,CAN_UNDO_COMMAND as K,REDO_COMMAND as B,UNDO_COMMAND as J,FORMAT_ELEMENT_COMMAND as j,FORMAT_TEXT_COMMAND as q,$createParagraphNode as Q,$getRoot as Y,isDOMDocumentNode as G,ArtificialNode__DO_NOT_USE as X,$createLineBreakNode as V,$cloneWithProperties as Z,getRegisteredNode as ee,isHTMLElement as te,isDocumentFragment as ne,$isBlockElementNode as ie,isBlockDomNode as oe,isInlineDomNode as re,TextNode as le}from"lexical";import{HistoryPlugin as ce}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as ae}from"@lexical/react/LexicalListPlugin";import{REMOVE_LIST_COMMAND as se,INSERT_ORDERED_LIST_COMMAND as de,INSERT_UNORDERED_LIST_COMMAND as ue,$isListNode as he,ListNode as pe,ListItemNode as me}from"@lexical/list";import{RxLetterCaseLowercase as ge,RxLetterCaseUppercase as fe,RxLetterCaseCapitalize as be}from"react-icons/rx";import{TbBold as ve,TbItalic as xe,TbUnderline as ye}from"react-icons/tb";import{BsSuperscript as we,BsSubscript as Ce,BsChatSquareQuote as ke,BsArrowCounterclockwise as _e,BsArrowClockwise as Ne,BsJustifyLeft as Se,BsTextCenter as Le,BsJustifyRight as Ae,BsJustify as Te,BsTextParagraph as Ee,BsTypeH1 as De,BsTypeH2 as Me,BsTypeH3 as Oe,BsTypeH4 as ze,BsTypeH5 as Fe,BsTypeH6 as Re,BsPencilSquare as He,BsListOl as Ue,BsListUl as Ie}from"react-icons/bs";import{AiOutlineStrikethrough as Pe,AiOutlineFontColors as $e,AiOutlineBgColors as We}from"react-icons/ai";import{IoCodeSlashOutline as Ke,IoImageOutline as Be}from"react-icons/io5";import{PiHighlighterLight as Je}from"react-icons/pi";import{useLexicalComposerContext as je}from"@lexical/react/LexicalComposerContext";import{TOGGLE_LINK_COMMAND as qe,$isLinkNode as Qe,LinkNode as Ye}from"@lexical/link";import{HiChevronDown as Ge}from"react-icons/hi2";import{IoIosLink as Xe}from"react-icons/io";import{MdCheck as Ve}from"react-icons/md";import{BiUnlink as Ze}from"react-icons/bi";import{SketchPicker as et}from"react-color";import{createPortal as tt}from"react-dom";import{LuUpload as nt}from"react-icons/lu";import{FaYoutube as it}from"react-icons/fa";import{VscPreview as ot}from"react-icons/vsc";import{LinkPlugin as rt}from"@lexical/react/LexicalLinkPlugin";import{OnChangePlugin as lt}from"@lexical/react/LexicalOnChangePlugin";var ct,at;!function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(ct||(ct={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(at||(at={}));const st=[{id:ct.Lowercase,icon:e(ge,{}),label:"Lowercase"},{id:ct.Uppercase,icon:e(fe,{}),label:"Uppercase"},{id:ct.Capitalize,icon:e(be,{}),label:"Capitalize"},{id:ct.Strikethrough,icon:e(Pe,{}),label:"Strikethrough"},{id:ct.Highlight,icon:e(Je,{}),label:"Highlight",fontSize:10},{id:ct.Superscript,icon:e(we,{}),label:"Superscript"},{id:ct.Subscript,icon:e(Ce,{}),label:"Subscript"}],dt=[{id:ct.Bold,icon:e(ve,{}),label:"Bold"},{id:ct.Italics,icon:e(xe,{}),label:"Italics"},{id:ct.Underline,icon:e(ye,{}),label:"Underline"},{id:ct.Divider},{id:ct.Quote,icon:e(ke,{}),label:"Quote"},{id:ct.Code,icon:e(Ke,{}),label:"Code"}],ut=[{id:ct.Undo,icon:e(_e,{}),label:"Undo"},{id:ct.Redo,icon:e(Ne,{}),label:"Redo"},{id:ct.Divider}],ht=[{id:ct.LeftAlign,icon:e(Se,{}),label:"Left Align"},{id:ct.CenterAlign,icon:e(Le,{}),label:"Center Align"},{id:ct.RightAlign,icon:e(Ae,{}),label:"Right Align"},{id:ct.JustifyAlign,icon:e(Te,{}),label:"Justify Align"}],pt=[{id:"normal",label:"Normal",icon:e(Ee,{})},{id:"h1",label:"Heading 1",icon:e(De,{})},{id:"h2",label:"Heading 2",icon:e(Me,{})},{id:"h3",label:"Heading 3",icon:e(Oe,{})},{id:"h4",label:"Heading 4",icon:e(ze,{})},{id:"h5",label:"Heading 5",icon:e(Fe,{})},{id:"h6",label:"Heading 6",icon:e(Re,{})}];function mt(e,...t){const n=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",e);for(const e of t)i.append("v",e);throw n.search=i.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const gt=new Map;function ft(e){let t=gt.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,i]=e.split(/:([^]+)/);n&&i&&(t[n.trim()]=i.trim())}return t}(e),gt.set(e,t)),t}function bt(e,t){(E(e)?e.isCollapsed():D(e)||N(e))||mt(280);const n=ft(E(e)?e.style:D(e)?e.getStyle():e.getTextStyle()),i=Object.entries(t).reduce((t,[i,o])=>("function"==typeof o?t[i]=o(n[i],e):null===o?delete t[i]:t[i]=o,t),{...n}),o=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(i);E(e)||D(e)?e.setStyle(o):e.setTextStyle(o),gt.set(o,i)}function vt(e,t){if(E(e)&&e.isCollapsed()){bt(e,t);const n=e.anchor.getNode();N(n)&&n.isEmpty()&&bt(n,t)}!function(e){const t=S();if(!t)return;const n=new Map,i=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(E(t))for(const e of R(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const o=t.getNodes();for(const t of o){if(!D(t)||!t.canHaveFormat())continue;const[n,o]=i(t);o!==n&&(M(t)||0===n&&o===t.getTextContentSize()?e(t):e(t.splitText(n,o)[0===n?0:1]))}E(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:i,offset:o,type:r}=t;t.set(n.key,n.offset,n.type),n.set(i,o,r)}}(t)}(e=>{bt(e,t)})}function xt(e,t){const n=e.getFormatType(),i=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),i!==t.getIndent()&&t.setIndent(i)}function yt(e){return e.getNode().isAttached()}function wt(e){let t=e;for(;null!==t&&!A(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function Ct(e,t,n=null){const i=e.getStartEndPoints(),o=i?i[0]:null,r=e.getNodes(),l=r.length;if(null!==o&&(0===l||1===l&&"element"===o.type&&0===o.getNode().getChildrenSize())){const e="text"===o.type?o.getNode().getParentOrThrow():o.getNode(),i=e.getChildren();let r=t();return r.setFormat(e.getFormatType()),r.setIndent(e.getIndent()),i.forEach(e=>r.append(e)),n&&(r=n.append(r)),void e.replace(r)}let c=null,a=[];for(let i=0;i<l;i++){const o=r[i];A(o)?(kt(e,a,a.length,t,n),a=[],c=o):null===c||null!==c&&T(o,c)?a.push(o):(kt(e,a,a.length,t,n),a=[o])}kt(e,a,a.length,t,n)}function kt(e,t,n,i,o=null){if(0===t.length)return;const r=t[0],l=new Map,c=[];let a=N(r)?r:r.getParentOrThrow();a.isInline()&&(a=a.getParentOrThrow());let s=!1;for(;null!==a;){const e=a.getPreviousSibling();if(null!==e){a=e,s=!0;break}if(a=a.getParentOrThrow(),A(a))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];N(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const u=new Set;for(let e=0;e<n;e++){const n=t[e];let o=n.getParent();if(null!==o&&o.isInline()&&(o=o.getParent()),null!==o&&z(n)&&!u.has(n.getKey())){const e=o.getKey();if(void 0===l.get(e)){const t=i();t.setFormat(o.getFormatType()),t.setIndent(o.getIndent()),c.push(t),l.set(e,t),o.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),N(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),wt(o)}}else if(d.has(n.getKey())){N(n)||mt(179);const e=i();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),c.push(e),n.remove(!0)}}if(null!==o)for(let e=0;e<c.length;e++){const t=c[e];o.append(t)}let h=null;if(A(a))if(s)if(null!==o)a.insertAfter(o);else for(let e=c.length-1;e>=0;e--){const t=c[e];a.insertAfter(t)}else{const e=a.getFirstChild();if(N(e)&&(a=e),null===e)if(o)a.append(o);else for(let e=0;e<c.length;e++){const t=c[e];a.append(t),h=t}else if(null!==o)e.insertBefore(o);else for(let t=0;t<c.length;t++){const n=c[t];e.insertBefore(n),h=n}}else if(o)a.insertAfter(o);else for(let e=c.length-1;e>=0;e--){const t=c[e];a.insertAfter(t),h=t}const p=F();E(p)&&yt(p.anchor)&&yt(p.focus)?L(p.clone()):null!==h?h.selectEnd():e.dirty=!0}function _t(e,t,n){const i=ft(e.getStyle());return null!==i&&i[t]||n}function Nt(e,t,n=""){let i=null;const o=e.getNodes(),r=e.anchor,l=e.focus,c=e.isBackward(),a=c?l.offset:r.offset,s=c?l.getNode():r.getNode();if(E(e)&&e.isCollapsed()&&""!==e.style){const n=ft(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<o.length;e++){const r=o[e];if((0===e||0!==a||!r.is(s))&&D(r)){const e=_t(r,t,n);if(null===i)i=e;else if(i!==e){i="";break}}}return null===i?n:i}const St="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Lt=St&&"documentMode"in document?document.documentMode:null;function At(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function Tt({open:t,onOpenChange:n,children:i}){const a=r(null),s=r(null);return l(()=>{function e(e){a.current?.contains(e.target)||s.current?.contains(e.target)||n(!1)}return t&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,n]),e("div",{className:"popover-root",children:o.Children.map(i,e=>e&&"object"==typeof e?e.type===Et?c(e,{triggerRef:a}):e.type===Dt?c(e,{contentRef:s}):e:e)})}function Et({children:t,triggerRef:n}){return e("div",{className:"popover-trigger",ref:n,children:t})}function Dt({open:t,align:n="start",children:i,contentRef:o}){return t?e("div",{ref:o,className:`popover-content align-${n}`,children:i}):null}function Mt({onAction:n,selectionMap:i}){const[o,l]=a(!1),c=r(null),s=r(null);return t(Tt,{open:o,onOpenChange:l,children:[e(Et,{triggerRef:c,children:t("button",{className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>l(e=>!e),children:[e("span",{children:"Aa"}),e(Ge,{className:"chevron "+(o?"rotated":"")})]})}),e(Dt,{open:o,align:"start",onClose:()=>l(!1),contentRef:s,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:st.map(({id:o,label:r,icon:c})=>t("button",{className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),l(!1)},style:{minWidth:130},children:[c,e("span",{className:"label",children:r})]},o))})})]})}function Ot(){return e("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function zt({updateHeading:n,headingSelectionMap:i}){const o=pt.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Tt,{open:l,onOpenChange:c,children:[e(Et,{triggerRef:s,children:t("button",{className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>c(e=>!e),style:{minWidth:132},children:[o?.icon,e("span",{children:o?.label}),e(Ge,{className:"chevron "+(l?"rotated":"")})]})}),e(Dt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:pt.map(({id:o,label:r,icon:l})=>t("button",{className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),c(!1)},children:[l,e("span",{className:"label",children:r})]},o))})})]})}function Ft({linkUrl:n,setLinkUrl:i,onConfirm:o,onCancel:c,removeLink:s}){const[d,u]=a(!1),h=r(null),p=r(null);return l(()=>{"https://"===n&&u(!0)},[n]),l(()=>{d&&p.current?.focus()},[d]),l(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&c()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]),t("div",{ref:h,className:"lexical-text-editor-link link-editor-container",children:[e("div",{className:"link-editor-input-wrapper",children:d?e("input",{ref:p,className:"link-editor-input",value:n,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o(n),u(!1)):"Escape"===e.key&&(e.preventDefault(),u(!1),c())}}):e("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"link-editor-url",children:n})}),t("div",{className:"link-editor-buttons",children:[e("button",{className:"lexical-btn heading-trigger toolbar",onClick:()=>{d?(o(n),u(!1)):u(!0)},children:d?e(Ve,{size:18}):e(He,{size:14})}),e("button",{className:"lexical-btn heading-trigger toolbar",onMouseDown:e=>e.preventDefault(),onClick:s,children:e(Ze,{size:14,style:{stroke:"black"}})})]})]})}function Rt({onAction:n,alignmentSelectionMap:i}){const o=ht.find(e=>i[e.id]),[l,c]=a(!1),s=r(null),d=r(null);return t(Tt,{open:l,onOpenChange:c,children:[e(Et,{triggerRef:s,children:t("button",{className:"lexical-btn heading-trigger "+(l?"toolbar-active":"toolbar"),onClick:()=>c(e=>!e),style:{minWidth:146},children:[o?.icon,e("span",{children:o?.label}),e(Ge,{className:"chevron "+(l?"rotated":"")})]})}),e(Dt,{open:l,align:"start",onClose:()=>c(!1),contentRef:d,children:e("div",{style:{display:"flex",flexDirection:"column",gap:5},children:ht.map(({id:o,label:r,icon:l})=>t("button",{className:"lexical-btn "+(i[o]?"toolbar-active":"toolbar"),onClick:()=>{n(o),c(!1)},children:[l,e("span",{className:"label",children:r})]},o))})})]})}function Ht({color:n,onChange:i,icon:o}){const[c,s]=a(!1),d=r(null),u=r(null);l(()=>{const e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return t("div",{className:"color-picker-wrapper",children:[e("button",{ref:d,className:`size-8 lexical-btn ${c?"toolbarActive":"toolbar"} icon`,onClick:()=>s(e=>!e),children:o}),c&&tt(e("div",{ref:u,className:"lexical-color-popover "+(c?"open":""),style:{top:d.current?.getBoundingClientRect().bottom,left:d.current?.getBoundingClientRect().left,position:"absolute"},onMouseDown:e=>e.preventDefault(),children:e(et,{color:n,onChangeComplete:e=>{i(e.hex)}})}),document.body)]})}St&&"InputEvent"in window&&!Lt&&new window.InputEvent("input");const Ut=({content:n,direction:i="top",delay:o=400,children:l})=>{const[c,s]=a(!1),d=r(null);return t("div",{className:"Lexical-Tooltip-Wrapper",onMouseEnter:()=>{d.current=window.setTimeout(()=>{s(!0)},o)},onMouseLeave:()=>{d.current&&clearTimeout(d.current),s(!1)},children:[l,c&&e("div",{className:`Lexical-Tooltip-Tip ${i}`,children:n})]})};function It(){const[i]=je(),[{color:o,bgColor:r},c]=a({color:"#000",bgColor:"#fff"}),s=()=>{const e=S();if(E(e)){const t=Nt(e,"color","#000"),n=Nt(e,"background","#fff");c({color:t,bgColor:n})}};l(()=>At(i.registerUpdateListener(({editorState:e})=>{e.read(()=>{s()})}),i.registerCommand(H,()=>(s(),!1),1)),[i]);const d=({property:e,color:t})=>{i.update(()=>{const n=S();n&&vt(n,{[e]:t})})};return t(n,{children:[e(Ut,{content:"Font Color",direction:"bottom",children:e(Ht,{color:o,onChange:e=>{d({property:"color",color:e})},icon:e($e,{})})}),e(Ut,{content:"Background Color",direction:"bottom",children:e(Ht,{color:r,onChange:e=>{d({property:"background",color:e})},icon:e(We,{})})})]})}function Pt({blockType:i}){const[o]=je();return t(n,{children:[e(Ut,{content:"Ordered list",direction:"bottom",children:e("button",{className:`size-8 lexical-btn ${"ol"===i?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ol"===i?o.dispatchCommand(se,void 0):o.dispatchCommand(de,void 0)},children:e(Ue,{})})}),e(Ut,{content:"Unordered list",direction:"bottom",children:e("button",{className:`size-8 lexical-btn ${"ul"===i?"toolbarActive":"toolbar"} icon`,onClick:()=>{"ul"===i?o.dispatchCommand(se,void 0):o.dispatchCommand(ue,void 0)},children:e(Ie,{})})})]})}const $t=({src:n,altText:i,nodeKey:o,width:l,height:c,maxWidth:a})=>{const[s]=je(),d=r(null),u=r(null),h=r(null),p=e=>{if(!h.current||!d.current)return;const t=e.clientX-h.current.x,n=Math.min(a,Math.max(50,h.current.width+t)),i=n*d.current.ratio;d.current.width=n,d.current.height=i;const o=u.current?.querySelector("img");o&&(o.style.width=n+"px",o.style.height=i+"px")},m=()=>{if(!d.current)return;const{width:e,height:t}=d.current;s.update(()=>{const n=U(o);n&&"function"==typeof n.updateDimensions&&n.updateDimensions(e,t)}),d.current=null,h.current=null,window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",m)};return t("div",{ref:u,style:{display:"inline-block",position:"relative",maxWidth:a},children:[e("img",{src:n,alt:i,width:"inherit"===l?void 0:l,height:"inherit"===c?void 0:c,style:{maxWidth:"100%",display:"block"}}),e("div",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation();const t=u.current?.querySelector("img");if(!t)return;const n=t.getBoundingClientRect().width,i=t.naturalHeight/t.naturalWidth,o=n*i;h.current={x:e.clientX,y:e.clientY,width:n,height:o},d.current={width:n,height:o,ratio:i},window.addEventListener("mousemove",p),window.addEventListener("mouseup",m)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Wt=e=>P(new Bt(e)),Kt=e=>{if(!(e instanceof HTMLImageElement))return null;const{src:t,alt:n}=e;let i,o;e.width&&(i=e.width),e.height&&(o=e.height);const r=e.style;if((!i||0===i)&&r.width){const e=parseInt(r.width,10);Number.isNaN(e)||(i=e)}if((!o||0===o)&&r.height){const e=parseInt(r.height,10);Number.isNaN(e)||(o=e)}return{node:Wt({src:t,altText:n,width:i??"inherit",height:o??"inherit"})}};class Bt extends I{constructor({src:e="",altText:t="",maxWidth:n=1080,width:i="inherit",height:o="inherit",key:r}={src:"",altText:""}){super(r),this.__src=e,this.__altText=t,this.__maxWidth=n,this.__width=i,this.__height=o}static getType(){return"image"}static clone(e){return new Bt({src:e.__src,altText:e.__altText,width:e.__width,height:e.__height,maxWidth:e.__maxWidth,key:e.getKey()})}createDOM(){return document.createElement("span")}updateDOM(e){return e.__width!==this.__width||e.__height!==this.__height}exportDOM(){const e=document.createElement("img");return e.src=this.__src,e.alt=this.__altText,"inherit"!==this.__width&&(e.width=this.__width??0),"inherit"!==this.__height&&(e.height=this.__height??0),{element:e}}static importDOM(){return{img:()=>({conversion:Kt,priority:1})}}exportJSON(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height}}static importJSON(e){return new Bt({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})}updateDimensions(e,t){const n=this.getWritable();n.__width=e,n.__height=t}decorate(){return e($t,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})}}function Jt({open:n,onClose:i,forPreview:o=!1,children:c}){const a=r(null);return l(()=>{if(!n)return;const e=e=>{a.current&&!a.current.contains(e.target)&&i()},t=e=>{"Escape"===e.key&&i()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[n,i]),n?e("div",{className:"lexical-text-editor-dialog lte-dialog-overlay",children:t("div",{ref:a,className:"lte-dialog "+(o?"preview":""),children:[e("button",{className:"lte-dialog-close",onClick:i,children:"×"}),c]})}):null}function jt(){const[n]=je(),i=r(null),[o,l]=a(!1),[c,s]=a(""),[d,u]=a(""),[h,p]=a();return t("div",{className:"lexical-text-editor-dialog",children:[e("input",{type:"file",ref:i,accept:"image/*",className:"lte-hidden",onChange:e=>{const t=e.target.files?.[0];t&&p(t),e.target.value=""}}),e("button",{className:`size-8 lexical-btn ${o?"toolbarActive":"toolbar"} icon`,onClick:()=>l(e=>!e),children:e(Be,{size:18})}),t(Jt,{open:o,onClose:()=>l(!1),children:[e("div",{className:"lte-dialog-header",children:"Add Image"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Alt text",value:d,onChange:e=>u(e.target.value)}),e("input",{className:"lte-input",placeholder:"Add image by URL",value:c,onChange:e=>s(e.target.value)}),e("div",{className:"lte-divider",children:e("span",{children:"or"})}),t("button",{className:"lexical-btn heading-trigger toolbar-active",onClick:()=>i.current?.click(),style:{width:"fit-content",margin:"0 auto"},children:[e(nt,{size:20}),e("span",{children:"Upload Image"})]}),h&&e("div",{className:"lte-file-name",children:h.name})]}),e("div",{className:"lte-dialog-footer",children:e("button",{className:"lte-primary-btn",disabled:!c&&!h,onClick:()=>{let e=c;h&&(e=URL.createObjectURL(h)),n.update(()=>{const t=Wt({src:e,altText:d});$([t])}),p(void 0),u(""),s(""),l(!1)},children:"Add Image"})})]})]})}const qt=({id:e,provider:t})=>new en({id:e,provider:t}),Qt="data-lexical-video",Yt="data-provider",Gt="315px",Xt="560px",Vt=(e,t)=>"drive"===t?`https://drive.google.com/file/d/${e}/preview`:`https://www.youtube-nocookie.com/embed/${e}`,Zt=e=>{const t=e?.getAttribute(Qt),n=e?.getAttribute(Yt)??"youtube";if(!t)return null;return{node:qt({id:t,provider:n})}};class en extends I{constructor({id:e,provider:t,key:n}){super(n),this.__id=e,this.__provider=t}static getType(){return"video"}static clone(e){return new en({id:e.__id,provider:e.__provider,key:e.getKey()})}static importJSON(e){return qt({id:e.id,provider:e.provider})}exportJSON(){return{id:this.__id,provider:this.__provider,type:"video",version:1}}updateDOM(){return!1}decorate(){return e("iframe",{height:Gt,width:Xt,src:Vt(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(Qt,this.__id),e.setAttribute(Yt,this.__provider),e.setAttribute("height",Gt),e.setAttribute("width",Xt),e.setAttribute("src",Vt(this.__id,this.__provider)),{element:e}}static importDOM(){return{iframe:()=>({conversion:Zt,priority:0})}}}function tn(){const[n,i]=a(!1),[o,r]=a(!1),[c,s]=a(""),[d]=je();return l(()=>{n||(s(""),r(!1))},[n]),t("div",{className:"lexical-text-editor-dialog",children:[e("button",{type:"button",className:`size-8 lexical-btn ${n?"toolbarActive":"toolbar"} icon`,onClick:()=>i(!0),children:e(it,{size:18,color:"red"})}),t(Jt,{open:n,onClose:()=>i(!1),children:[e("div",{className:"lte-dialog-header",children:"Embed Video"}),t("div",{className:"lte-dialog-body",children:[e("input",{className:"lte-input",placeholder:"Add YouTube or Google Drive URL",value:c,onChange:e=>s(e.target.value)}),o&&e("p",{className:"lte-error-text",children:"It's not a valid YouTube or Google Drive URL"})]}),e("div",{className:"lte-dialog-footer",children:e("button",{className:"lte-primary-btn",disabled:!c,onClick:()=>{if(!c)return;let e=null,t=null;const n=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(c);n&&11===n[2]?.length&&(e="youtube",t=n[2]);const o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(c);o&&o[1]&&(e="drive",t=o[1]),t&&e?(d.update(()=>{const n=qt({id:t,provider:e});$([n])}),s(""),r(!1),i(!1)):r(!0)},children:"Embed"})})]})]})}function nn({value:t}){return e("div",{className:"lexical-text-editor-html-preview",dangerouslySetInnerHTML:{__html:t}})}function on({value:n,triggerLabel:i="Preview"}){const[o,r]=a(!1);return t("div",{className:"lexical-text-editor-dialog",children:[t("button",{className:"lexical-btn heading-trigger "+(o?"toolbar-active":"toolbar"),onClick:()=>r(e=>!e),children:[e(ot,{size:18}),e("span",{children:i})]}),t(Jt,{open:o,onClose:()=>r(!1),forPreview:!0,children:[e("div",{className:"lte-dialog-header",children:"Content Preview"}),t("div",{className:"lte-preview-container",children:[e("div",{className:"lte-preview-title",children:"CONTENT"}),e(nn,{value:n})]})]})]})}const rn=({value:n})=>{const[i]=je(),[o,r]=a({[ct.Undo]:!0,[ct.Redo]:!0}),[c,d]=a(!1),[g,f]=a({[ct.LeftAlign]:!0}),[b,v]=a({[at.Normal]:!0}),[x,y]=a("paragraph"),[w,A]=a("https://");let T=!0;const D=()=>{if(T){const e=i.getRootElement();e&&(e.scrollTop=0,T=!1)}const e=S();if(E(e)){const t={[ct.Bold]:e.hasFormat("bold"),[ct.Italics]:e.hasFormat("italic"),[ct.Underline]:e.hasFormat("underline"),[ct.Uppercase]:e.hasFormat("uppercase"),[ct.Lowercase]:e.hasFormat("lowercase"),[ct.Capitalize]:e.hasFormat("capitalize"),[ct.Strikethrough]:e.hasFormat("strikethrough"),[ct.Superscript]:e.hasFormat("superscript"),[ct.Subscript]:e.hasFormat("subscript"),[ct.Code]:e.hasFormat("code"),[ct.Highlight]:e.hasFormat("highlight")};f(t);const n=e.anchor.getNode(),o="root"===n.getKey()?n:n.getTopLevelElementOrThrow(),r=o.getKey();if(!i.getElementByKey(r))return;if(he(o)){const e=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(n,pe),t=e?e.getTag():o.getTag();y(t)}else if("paragraph"===o.getType()||u(o)){let e=null;u(o)&&(e=o.getTag());const t={[at.H1]:"h1"===e,[at.H2]:"h2"===e,[at.H3]:"h3"===e,[at.H4]:"h4"===e,[at.H5]:"h5"===e,[at.H6]:"h6"===e,[at.Normal]:"paragraph"===o.getType()};y(o.getType()),v(t)}else y(o.getType());const l=(N(n)?n:o).getFormat();f(e=>({...e,[ct.LeftAlign]:0===l||1===l,[ct.CenterAlign]:2===l,[ct.RightAlign]:3===l,[ct.JustifyAlign]:4===l})),"quote"===o.getType()?f(e=>({...e,[ct.Quote]:!0})):f(e=>({...e,[ct.Quote]:!1}));const c=e.anchor.getNode(),a=c.getParent();Qe(a)?(f(e=>({...e,[ct.Link]:!0})),A(a.getURL()),d(!0)):Qe(c)?(f(e=>({...e,[ct.Link]:!0})),A(c.getURL()),d(!0)):(f(e=>({...e,[ct.Link]:!1})),A("https://"),d(!1))}};l(()=>At(i.registerUpdateListener(({editorState:e})=>{e.read(()=>{D()})}),i.registerCommand(H,()=>(D(),!1),1),i.registerCommand(K,e=>(r(t=>({...t,undo:!e})),!1),1),i.registerCommand(W,e=>(r(t=>({...t,redo:!e})),!1),1)),[]);const M=e=>{switch(e){case ct.Bold:i.dispatchCommand(q,"bold");break;case ct.Italics:i.dispatchCommand(q,"italic");break;case ct.Underline:i.dispatchCommand(q,"underline");break;case ct.Lowercase:i.dispatchCommand(q,"lowercase");break;case ct.Uppercase:i.dispatchCommand(q,"uppercase");break;case ct.Capitalize:i.dispatchCommand(q,"capitalize");break;case ct.Strikethrough:i.dispatchCommand(q,"strikethrough");break;case ct.Superscript:i.dispatchCommand(q,"superscript");break;case ct.Subscript:i.dispatchCommand(q,"subscript");break;case ct.Highlight:i.dispatchCommand(q,"highlight");break;case ct.Code:i.dispatchCommand(q,"code");break;case ct.Quote:i.update(()=>{const e=S();if(E(e)){const t=e.anchor.getNode().getParent();t&&h(t)?function(e,t,n=xt){if(null===e)return;const i=e.getStartEndPoints(),o=new Map;let r=null;if(i){const[e,t]=i;r=C(),r.anchor.set(e.key,e.offset,e.type),r.focus.set(t.key,t.offset,t.type);const n=k(e.getNode(),_),l=k(t.getNode(),_);N(n)&&o.set(n.getKey(),n),N(l)&&o.set(l.getKey(),l)}for(const t of e.getNodes())if(N(t)&&_(t))o.set(t.getKey(),t);else if(null===i){const e=k(t,_);N(e)&&o.set(e.getKey(),e)}for(const[e,i]of o){const o=t();n(i,o),i.replace(o,!0),r&&(e===r.anchor.key&&r.anchor.set(o.getKey(),r.anchor.offset,r.anchor.type),e===r.focus.key&&r.focus.set(o.getKey(),r.focus.offset,r.focus.type))}r&&e.is(S())&&L(r)}(e,()=>Q()):Ct(e,()=>p())}});break;case ct.Link:O(),d(!0);break;case ct.LeftAlign:i.dispatchCommand(j,"left");break;case ct.RightAlign:i.dispatchCommand(j,"right");break;case ct.CenterAlign:i.dispatchCommand(j,"center");break;case ct.JustifyAlign:i.dispatchCommand(j,"justify");break;case ct.Undo:i.dispatchCommand(J,void 0);break;case ct.Redo:i.dispatchCommand(B,void 0)}},O=s(()=>{i.update(()=>{const e=S();E(e)&&!e.isCollapsed()&&(c?i.dispatchCommand(qe,null):""!==w&&i.dispatchCommand(qe,w))})},[i,c,w]),z=s(()=>{A(""),i.dispatchCommand(qe,null),d(!1)},[i]);return t("div",{className:"lexical-toolbar-wrapper",style:{position:"relative",padding:12,marginBottom:4,borderBottom:"1px solid #e5e7eb"},children:[ut.map(({id:t,label:n,icon:i})=>t===ct.Divider?e(Ot,{},t):e(Ut,{content:n,direction:"bottom",children:e("button",{className:`size-8 lexical-btn ${g[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(t),disabled:!!o[t],children:i})},n)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(zt,{updateHeading:e=>{i.update(()=>{const t=S();E(t)&&Ct(t,"normal"===e?()=>Q():()=>m(e))})},headingSelectionMap:b}),e(Ot,{})]}),dt.map(({id:t,label:n,icon:i})=>t===ct.Divider?e(Ot,{},t):e(Ut,{content:n,direction:"bottom",children:e("button",{className:`size-8 lexical-btn ${g[t]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(t),children:i})},t)),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Pt,{blockType:x}),e(Ot,{})]}),e(It,{}),e(Mt,{onAction:M,selectionMap:g}),t("div",{style:{display:"flex",gap:6,justifyContent:"start",alignItems:"center"},children:[e(Rt,{onAction:M,alignmentSelectionMap:g}),e(Ot,{})]}),e(Ut,{content:"Link",direction:"bottom",children:e("button",{className:`size-8 lexical-btn ${g[ct.Link]?"toolbarActive":"toolbar"} icon`,onClick:()=>M(ct.Link),disabled:!!o[ct.Link],children:e(Xe,{})})}),c&&e(Ft,{linkUrl:w,setLinkUrl:A,removeLink:z,onConfirm:e=>{i.dispatchCommand(qe,{url:e,target:"_blank"}),A(e),d(!1)},onCancel:()=>{A(""),d(!1)}}),e(jt,{}),e(tn,{}),e(on,{value:n})]})};function ln(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const n=document.createElement("div"),i=Y().getChildren();for(let o=0;o<i.length;o++)cn(e,i[o],n,t);return n.innerHTML}function cn(e,t,n,i=null){let o=null===i||t.isSelected(i);const r=N(t)&&t.excludeFromCopy("html");let l=t;if(null!==i){let e=Z(t);e=D(e)&&null!==i?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!M(t)&&null!==n){const[i,o]=n,r=e.isBackward(),l=i.getNode(),c=o.getNode(),a=t.is(l),s=t.is(c);if(a||s){const[n,i]=O(e),o=l.is(c),a=t.is(r?c:l),s=t.is(r?l:c);let d,u=0;o?(u=n>i?i:n,d=n>i?n:i):a?(u=r?i:n,d=void 0):s&&(u=0,d=r?n:i),t.__text=t.__text.slice(u,d)}}return t}(i,e):e,l=e}const c=N(l)?l.getChildren():[],a=ee(e,l.getType());let s;s=a&&void 0!==a.exportDOM?a.exportDOM(e,l):l.exportDOM(e);const{element:d,after:u}=s;if(!d)return!1;const h=document.createDocumentFragment();for(let n=0;n<c.length;n++){const r=c[n],l=cn(e,r,h,i);!o&&N(t)&&l&&t.extractWithChild(r,i,"html")&&(o=!0)}if(o&&!r){if((te(d)||ne(d))&&d.append(h),n.append(d),u){const e=u.call(l,d);e&&(ne(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(h);return o}const an=new Set(["STYLE","SCRIPT"]);function sn(e,t,n,i,o=new Map,r){let l=[];if(an.has(e.nodeName))return l;let c=null;const a=function(e,t){const{nodeName:n}=e,i=t._htmlConversions.get(n.toLowerCase());let o=null;if(void 0!==i)for(const t of i){const n=t(e);null!==n&&(null===o||(o.priority||0)<=(n.priority||0))&&(o=n)}return null!==o?o.conversion:null}(e,t),s=a?a(e):null;let d=null;if(null!==s){d=s.after;const t=s.node;if(c=Array.isArray(t)?t[t.length-1]:t,null!==c){for(const[,e]of o)if(c=e(c,r),!c)break;c&&l.push(...Array.isArray(t)?t:[c])}null!=s.forChild&&o.set(e.nodeName,s.forChild)}const u=e.childNodes;let h=[];const p=(null==c||!A(c))&&(null!=c&&ie(c)||i);for(let e=0;e<u.length;e++)h.push(...sn(u[e],t,n,p,new Map(o),c));return null!=d&&(h=d(h)),oe(e)&&(h=function(e,t,n){const i=e.style.textAlign,o=[];let r=[];for(let e=0;e<t.length;e++){const l=t[e];if(ie(l))i&&!l.getFormat()&&l.setFormat(i),o.push(l);else if(r.push(l),e===t.length-1||e<t.length-1&&ie(t[e+1])){const e=n();e.setFormat(i),e.append(...r),o.push(e),r=[]}}return o}(e,h,p?()=>{const e=new X;return n.push(e),e}:Q)),null==c?h.length>0?l=l.concat(h):oe(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(re(e.nextSibling)&&re(e.previousSibling))}(e)&&(l=l.concat(V())):N(c)&&c.append(...h),l}function dn({value:t,onChange:n}){const[i]=je(),[o,r]=a(!0);return l(()=>{t&&o&&(r(!1),i.update(()=>{if(ln(i)!==t){Y().clear();const e=(new DOMParser).parseFromString(t,"text/html"),n=function(e,t){const n=G(t)?t.body.childNodes:t.childNodes;let i=[];const o=[];for(const t of n)if(!an.has(t.nodeName)){const n=sn(t,e,o,!1);null!==n&&(i=i.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof X&&t.insertAfter(V());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(o),i}(i,e);$(n)}}))},[i,t,o]),l(()=>{r(!0)},[t]),e(lt,{onChange:e=>{e.read(()=>{n(ln(i))})}})}const un=({id:e})=>new bn({id:e}),hn="data-lexical-youtube",pn="315px",mn="560px",gn=e=>`https://www.youtube-nocookie.com/embed/${e}`,fn=e=>{const t=e?.getAttribute(hn);if(!t)return null;return{node:un({id:t})}};class bn extends I{constructor({id:e,key:t}){super(t),this.__id=e}static getType(){return"youtube"}static clone(e){return new bn({id:e.__id,key:e.getKey()})}static importJSON(e){return un({id:e.id})}exportJSON(){return{id:this.__id,type:"youtube",version:1}}decorate(){return e("iframe",{height:pn,width:mn,src:gn(this.__id),frameBorder:"0",allowFullScreen:!0})}createDOM(){return document.createElement("div")}exportDOM(){const e=document.createElement("iframe");return e.setAttribute(hn,this.__id),e.setAttribute("height",pn),e.setAttribute("width",mn),e.setAttribute("src",gn(this.__id)),{element:e}}static importDOM(){return{iframe:()=>({conversion:fn,priority:0})}}}class vn extends le{constructor(e,t){super(e,t)}static getType(){return"extended-text"}static clone(e){return new vn(e.__text,e.__key)}static importDOM(){const e=le.importDOM();return{...e,span:()=>({conversion:xn(e?.span),priority:1}),div:()=>({conversion:xn(e?.div),priority:1}),p:()=>({conversion:xn(e?.p),priority:1}),b:()=>({conversion:xn(e?.b),priority:1}),strong:()=>({conversion:xn(e?.strong),priority:1}),i:()=>({conversion:xn(e?.i),priority:1}),em:()=>({conversion:xn(e?.em),priority:1}),u:()=>({conversion:xn(e?.u),priority:1}),s:()=>({conversion:xn(e?.s),priority:1}),strike:()=>({conversion:xn(e?.strike),priority:1}),code:()=>({conversion:xn(e?.code),priority:1})}}static importJSON(e){return function(e=""){return P(new vn(e))}().updateFromJSON(e)}isSimpleText(){return"extended-text"===this.__type&&0===this.__mode}}function xn(e){return t=>{const n=e?.(t);if(!n)return null;const i=n.conversion(t);if(!i)return i;const o=t.style,r=[];o.backgroundColor&&r.push(`background-color: ${o.backgroundColor}`),o.color&&r.push(`color: ${o.color}`),o.fontFamily&&r.push(`font-family: ${o.fontFamily}`),o.fontWeight&&r.push(`font-weight: ${o.fontWeight}`),o.fontSize&&r.push(`font-size: ${o.fontSize}`),o.fontStyle&&r.push(`font-style: ${o.fontStyle}`),o.textDecoration&&r.push(`text-decoration: ${o.textDecoration}`),o.whiteSpace&&r.push(`white-space: ${o.whiteSpace}`),o.textAlign&&r.push(`text-align: ${o.textAlign}`);const l=t.getAttribute("style");if(l){l.split(";").filter(e=>e.trim()).forEach(e=>{const[t]=e.split(":").map(e=>e.trim());t&&!r.some(e=>e.startsWith(t))&&r.push(e.trim())})}return{...i,forChild:(e,t)=>{const n=i?.forChild??(e=>e),o=n(e,t);if(D(o)&&r.length>0){const e=r.join("; ");return o.setStyle(e)}return o}}}}const yn={text:{bold:"lexical-bold",underline:"lexical-underline",italic:"lexical-italic",strikethrough:"lexical-strikethrough",underlineStrikethrough:"lexical-underline-strikethrough",uppercase:"lexical-uppercase",lowercase:"lexical-lowercase",capitalize:"lexical-capitalize",code:"lexical-code"},paragraph:"lexical-paragraph",list:{ul:"lexical-list-ul",ol:"lexical-list-ol",listitem:"lexical-listitem"},quote:"lexical-quote",link:"lexical-link"},wn=o.memo(function({name:n,value:o,onChange:r,placeholder:l,maxWidth:c=null,height:a=null}){const s=d(()=>({namespace:n,theme:yn,onError:e=>{console.error("Lexical error:",e)},nodes:[vn,{replace:le,with:e=>new vn(e.__text),withKlass:vn},g,b,v,pe,me,f,Ye,Bt,bn,en]}),[n]);return e("div",{className:"lexical-text-editor lexical-editor-container",style:{maxWidth:c||"1090px"},children:t(i,{initialConfig:s,children:[e("div",{className:"lexical-toolbar-container",children:e(rn,{value:o})}),e("div",{className:"lexical-editor-inner",children:e(x,{contentEditable:e(y,{className:"lexical-content-editable",style:{height:a||"500px"}}),placeholder:e("div",{className:"lexical-placeholder",children:l||"Some Text"}),ErrorBoundary:w})}),e(ce,{}),e(ae,{}),e(rt,{}),e(dn,{value:o,onChange:r})]})})});export{wn as LexicalTextEditor};
2
2
  //# sourceMappingURL=index.esm.js.map