luxe-edit 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +5 -1
- package/dist/index.mjs +5 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A beautiful, customizable rich text editor for React built on Lexical with customizable toolbars and floating toolbar support.
|
|
4
4
|
|
|
5
|
+
🌐 **Live Demo**: [https://luxe-tools.github.io/luxe-edit/](https://luxe-tools.github.io/luxe-edit/)
|
|
6
|
+
|
|
7
|
+
🌐 **[View Live Demo →](https://luxe-tools.github.io/luxe-edit/)**
|
|
8
|
+
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
11
|
```bash
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import { InitialConfigType } from '@lexical/react/LexicalComposer';
|
|
5
|
+
import { EditorState, LexicalEditor } from 'lexical';
|
|
5
6
|
|
|
6
7
|
type ToolbarItemType = 'undo' | 'redo' | 'divider' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'alignJustify' | 'textColor' | 'backgroundColor' | 'fullscreen' | 'headingDropdown' | 'link';
|
|
7
8
|
interface ToolbarItem {
|
|
@@ -25,14 +26,42 @@ interface ToolbarProps {
|
|
|
25
26
|
}
|
|
26
27
|
declare function Toolbar({ items, onFullscreenToggle, isFullscreen }: ToolbarProps): react_jsx_runtime.JSX.Element;
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Get the editor content as JSON
|
|
31
|
+
*/
|
|
32
|
+
declare function getEditorJSON(editorState: EditorState): any;
|
|
33
|
+
/**
|
|
34
|
+
* Get the editor content as plain text
|
|
35
|
+
*/
|
|
36
|
+
declare function getEditorText(editorState: EditorState): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get the editor content as formatted text (preserves headings and formatting)
|
|
39
|
+
*/
|
|
40
|
+
declare function getEditorFormattedText(editorState: EditorState): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get DOM HTML from editor instance
|
|
43
|
+
*/
|
|
44
|
+
declare function getEditorDOM(editor: any): string;
|
|
45
|
+
/**
|
|
46
|
+
* Convert JSON to tree structure for display
|
|
47
|
+
*/
|
|
48
|
+
declare function getEditorTree(json: any): any;
|
|
49
|
+
|
|
28
50
|
interface LuxeEditorProps {
|
|
29
51
|
initialConfig: Partial<InitialConfigType>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional initial editor content as a serialized Lexical editor state (JSON).
|
|
54
|
+
* This is ideal for loading content from a database for editing.
|
|
55
|
+
*/
|
|
56
|
+
initialJSON?: any;
|
|
30
57
|
showFloatingToolbar?: boolean;
|
|
31
58
|
showToolbar?: boolean;
|
|
32
59
|
toolbarItems?: ToolbarItem[];
|
|
33
60
|
floatingToolbarItems?: ToolbarItem[];
|
|
61
|
+
onChange?: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
62
|
+
ignoreInitialChange?: boolean;
|
|
34
63
|
children?: React__default.ReactNode;
|
|
35
64
|
}
|
|
36
|
-
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
65
|
+
declare function LuxeEditor({ initialConfig, initialJSON, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, onChange, ignoreInitialChange, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
37
66
|
|
|
38
|
-
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType };
|
|
67
|
+
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType, getEditorDOM, getEditorFormattedText, getEditorJSON, getEditorText, getEditorTree };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import { InitialConfigType } from '@lexical/react/LexicalComposer';
|
|
5
|
+
import { EditorState, LexicalEditor } from 'lexical';
|
|
5
6
|
|
|
6
7
|
type ToolbarItemType = 'undo' | 'redo' | 'divider' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'alignJustify' | 'textColor' | 'backgroundColor' | 'fullscreen' | 'headingDropdown' | 'link';
|
|
7
8
|
interface ToolbarItem {
|
|
@@ -25,14 +26,42 @@ interface ToolbarProps {
|
|
|
25
26
|
}
|
|
26
27
|
declare function Toolbar({ items, onFullscreenToggle, isFullscreen }: ToolbarProps): react_jsx_runtime.JSX.Element;
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Get the editor content as JSON
|
|
31
|
+
*/
|
|
32
|
+
declare function getEditorJSON(editorState: EditorState): any;
|
|
33
|
+
/**
|
|
34
|
+
* Get the editor content as plain text
|
|
35
|
+
*/
|
|
36
|
+
declare function getEditorText(editorState: EditorState): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get the editor content as formatted text (preserves headings and formatting)
|
|
39
|
+
*/
|
|
40
|
+
declare function getEditorFormattedText(editorState: EditorState): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get DOM HTML from editor instance
|
|
43
|
+
*/
|
|
44
|
+
declare function getEditorDOM(editor: any): string;
|
|
45
|
+
/**
|
|
46
|
+
* Convert JSON to tree structure for display
|
|
47
|
+
*/
|
|
48
|
+
declare function getEditorTree(json: any): any;
|
|
49
|
+
|
|
28
50
|
interface LuxeEditorProps {
|
|
29
51
|
initialConfig: Partial<InitialConfigType>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional initial editor content as a serialized Lexical editor state (JSON).
|
|
54
|
+
* This is ideal for loading content from a database for editing.
|
|
55
|
+
*/
|
|
56
|
+
initialJSON?: any;
|
|
30
57
|
showFloatingToolbar?: boolean;
|
|
31
58
|
showToolbar?: boolean;
|
|
32
59
|
toolbarItems?: ToolbarItem[];
|
|
33
60
|
floatingToolbarItems?: ToolbarItem[];
|
|
61
|
+
onChange?: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
62
|
+
ignoreInitialChange?: boolean;
|
|
34
63
|
children?: React__default.ReactNode;
|
|
35
64
|
}
|
|
36
|
-
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
65
|
+
declare function LuxeEditor({ initialConfig, initialJSON, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, onChange, ignoreInitialChange, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
37
66
|
|
|
38
|
-
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType };
|
|
67
|
+
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType, getEditorDOM, getEditorFormattedText, getEditorJSON, getEditorText, getEditorTree };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var ge=Object.create;var _=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var me=(e,s)=>{for(var r in s)_(e,r,{get:s[r],enumerable:!0})},V=(e,s,r,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let d of fe(s))!xe.call(e,d)&&d!==r&&_(e,d,{get:()=>s[d],enumerable:!(t=he(s,d))||t.enumerable});return e};var ye=(e,s,r)=>(r=e!=null?ge(be(e)):{},V(s||!e||!e.__esModule?_(r,"default",{value:e,enumerable:!0}):r,e)),Ce=e=>V(_({},"__esModule",{value:!0}),e);var Re={};me(Re,{FloatingToolbarPlugin:()=>G,LuxeEditor:()=>we,Toolbar:()=>B});module.exports=Ce(Re);var Q=ye(require("react")),ae=require("@lexical/react/LexicalComposer"),le=require("@lexical/react/LexicalRichTextPlugin"),ie=require("@lexical/react/LexicalContentEditable"),se=require("@lexical/react/LexicalHistoryPlugin"),de=require("@lexical/react/LexicalErrorBoundary"),pe=require("@lexical/react/LexicalLinkPlugin"),ce=require("@lexical/rich-text"),X=require("@lexical/link"),J=require("lexical");var oe=require("@lexical/react/LexicalComposerContext"),v=require("lexical"),q=require("@lexical/selection"),j=require("@lexical/rich-text"),D=require("react"),ne=require("react-dom");var ee=require("@lexical/react/LexicalComposerContext"),te=require("@lexical/utils"),n=require("lexical"),Y=require("@lexical/selection"),P=require("@lexical/rich-text"),W=require("@lexical/link"),h=require("react"),i=require("react/jsx-runtime"),Z=["#000000","#ffffff","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#808080","#800000","#008000","#000080","#808000","#800080","#008080"];function U(e){return{undo:"\u21B6",redo:"\u21B7",divider:"",bold:"B",italic:"I",underline:"U",strikethrough:"S",heading1:"H1",heading2:"H2",heading3:"H3",heading4:"H4",heading5:"H5",heading6:"H6",paragraph:"P",alignLeft:"\u2B05",alignCenter:"\u2B0C",alignRight:"\u27A1",alignJustify:"\u2B0C",textColor:"A",backgroundColor:"\u2B1B",fullscreen:"\u26F6",headingDropdown:"Normal",link:"\u{1F517}"}[e]||e}function Te(){return(0,i.jsx)("div",{style:{width:"1px",height:"24px",background:"#e5e7eb",margin:"0 4px"}})}function ve({item:e,onAction:s}){let[r,t]=(0,h.useState)(!1),d=(0,h.useRef)(null),f=e.colors||Z;return(0,h.useEffect)(()=>{let l=x=>{d.current&&!d.current.contains(x.target)&&t(!1)};if(r)return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[r]),e.color?(0,i.jsx)("button",{onClick:()=>s(e,e.color),title:`${e.type==="textColor"?"Text":"Background"} Color: ${e.color}`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:e.type==="backgroundColor"?e.color:"white",color:e.type==="textColor"?e.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center"},children:e.icon||U(e.type)}):(0,i.jsxs)("div",{style:{position:"relative"},ref:d,children:[(0,i.jsxs)("button",{onClick:()=>t(!r),title:`${e.type==="textColor"?"Text":"Background"} Color`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:[e.icon||(0,i.jsx)("span",{style:{display:"block",width:"20px",height:"20px",background:e.type==="backgroundColor"?"linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%)":"currentColor",backgroundSize:e.type==="backgroundColor"?"8px 8px":"auto",backgroundPosition:e.type==="backgroundColor"?"0 0, 0 4px, 4px -4px, -4px 0px":"auto"},children:e.type==="textColor"&&(0,i.jsx)("span",{style:{color:"#000",fontSize:"12px"},children:"A"})}),(0,i.jsx)("span",{style:{marginLeft:"4px",fontSize:"10px"},children:"\u25BC"})]}),r&&(0,i.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"8px",display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"160px"},children:[f.map(l=>(0,i.jsxs)("button",{onClick:()=>{s(e,l),t(!1)},title:l,style:{width:"24px",height:"24px",borderRadius:"4px",border:e.type==="textColor"?`3px solid ${l}`:"1px solid #e5e7eb",background:e.type==="backgroundColor"?l:"white",color:e.type==="textColor"?"#000":"inherit",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",position:"relative"},children:[e.type==="textColor"&&(0,i.jsx)("span",{style:{color:l,fontSize:"14px",fontWeight:"bold",lineHeight:"1"},children:"A"}),e.type==="backgroundColor"&&l==="#ffffff"&&(0,i.jsx)("span",{style:{color:"#000",fontSize:"10px",border:"1px solid #ccc",width:"12px",height:"12px",display:"block"},children:"\u25A1"})]},l)),(0,i.jsx)("input",{type:"color",onChange:l=>{s(e,l.target.value),t(!1)},style:{gridColumn:"1 / -1",width:"100%",height:"32px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer"}})]})]})}function ke({item:e,onAction:s,currentBlockType:r="paragraph"}){let[t,d]=(0,h.useState)(!1),f=(0,h.useRef)(null);(0,h.useEffect)(()=>{let c=o=>{f.current&&!f.current.contains(o.target)&&d(!1)};if(t)return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[t]);let l=()=>r==="paragraph"?"Normal":r.startsWith("h")?`Heading ${r.replace("h","")}`:"Normal",x=c=>{s(e,void 0,c),d(!1)},m=[{value:"paragraph",label:"Normal"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}];return(0,i.jsxs)("div",{style:{position:"relative"},ref:f,children:[(0,i.jsxs)("button",{onClick:()=>d(!t),title:"Heading",style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"100px",height:"32px",display:"flex",alignItems:"center",justifyContent:"space-between",position:"relative",fontSize:r==="paragraph"?"14px":r==="h1"?"20px":r==="h2"?"18px":r==="h3"?"16px":"14px",fontWeight:r!=="paragraph"?"bold":"normal"},children:[(0,i.jsx)("span",{children:e.label||l()}),(0,i.jsx)("span",{style:{marginLeft:"8px",fontSize:"10px"},children:"\u25BC"})]}),t&&(0,i.jsx)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"150px"},children:m.map(c=>(0,i.jsx)("button",{onClick:()=>x(c.value),style:{width:"100%",padding:"8px 12px",border:"none",background:r===c.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:c.value==="paragraph"?"14px":c.value==="h1"?"20px":c.value==="h2"?"18px":c.value==="h3"?"16px":"14px",fontWeight:c.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:o=>{r!==c.value&&(o.currentTarget.style.background="#f3f4f6")},onMouseLeave:o=>{r!==c.value?o.currentTarget.style.background="transparent":o.currentTarget.style.background="#e5e7eb"},children:c.label},c.value))})]})}function Ne({item:e,onAction:s,editor:r}){let[t,d]=(0,h.useState)(!1),[f,l]=(0,h.useState)(""),[x,m]=(0,h.useState)(!1),c=(0,h.useRef)(null),o=(0,h.useRef)(null);(0,h.useEffect)(()=>{let a=()=>{r.getEditorState().read(()=>{let H=(0,n.$getSelection)();if((0,n.$isRangeSelection)(H)){let L=H.getNodes(),w=null;for(let K of L){let p=K.getParent();for(;p!==null;){if((0,W.$isLinkNode)(p)){w=p;break}p=p.getParent()}if(w)break}w&&(0,W.$isLinkNode)(w)?(m(!0),l(w.getURL())):(m(!1),l(""))}else m(!1),l("")})},b=r.registerUpdateListener(()=>{a()}),g=r.registerCommand(n.SELECTION_CHANGE_COMMAND,()=>(a(),!1),n.COMMAND_PRIORITY_LOW);return a(),()=>{b(),g()}},[r]),(0,h.useEffect)(()=>{let a=b=>{c.current&&!c.current.contains(b.target)&&d(!1)};if(t)return document.addEventListener("mousedown",a),setTimeout(()=>o.current?.focus(),0),()=>document.removeEventListener("mousedown",a)},[t,x,f]);let y=()=>{if(!f.trim()){r.dispatchCommand(W.TOGGLE_LINK_COMMAND,null),d(!1),l("");return}let a=f.trim();!a.startsWith("http://")&&!a.startsWith("https://")&&!a.startsWith("mailto:")&&!a.startsWith("#")&&!a.startsWith("/")&&(a="https://"+a),r.dispatchCommand(W.TOGGLE_LINK_COMMAND,a),d(!1),l("")},u=()=>{r.dispatchCommand(W.TOGGLE_LINK_COMMAND,null),d(!1),l("")},T=a=>{a.key==="Enter"?(a.preventDefault(),y()):a.key==="Escape"&&(d(!1),l(""))};return(0,i.jsxs)("div",{style:{position:"relative"},ref:c,children:[(0,i.jsx)("button",{onClick:()=>{d(!t)},title:x?"Edit Link":"Insert Link",style:{padding:"6px 12px",border:"none",background:x?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:a=>{x||(a.currentTarget.style.background="#f3f4f6")},onMouseLeave:a=>{x?a.currentTarget.style.background="#e5e7eb":a.currentTarget.style.background="transparent"},children:e.icon||U(e.type)}),t&&(0,i.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"300px"},children:[(0,i.jsx)("input",{ref:o,type:"text",placeholder:"Enter URL (e.g., https://example.com)",value:f,onChange:a=>l(a.target.value),onKeyDown:T,style:{width:"100%",padding:"8px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",marginBottom:"8px"}}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[x&&(0,i.jsx)("button",{onClick:u,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px",color:"#dc2626"},children:"Remove"}),(0,i.jsx)("button",{onClick:()=>d(!1),style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:"Cancel"}),(0,i.jsx)("button",{onClick:y,style:{padding:"6px 12px",border:"none",background:"#3b82f6",color:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:x?"Update":"Insert"})]})]})]})}function Ee({item:e,active:s=!1,disabled:r=!1,onAction:t,currentBlockType:d}){let l=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,x=e.label||U(e.type);return e.type==="divider"?(0,i.jsx)(Te,{}):e.type==="headingDropdown"?(0,i.jsx)(ke,{item:e,onAction:t,currentBlockType:d}):e.type==="textColor"||e.type==="backgroundColor"?(0,i.jsx)(ve,{item:e,onAction:t}):(0,i.jsx)("button",{onClick:()=>t(e),disabled:r,title:e.type.charAt(0).toUpperCase()+e.type.slice(1).replace(/([A-Z])/g," $1").trim(),style:{padding:"6px 12px",border:"none",background:s?"#e5e7eb":"transparent",cursor:r?"not-allowed":"pointer",borderRadius:"4px",fontWeight:e.type==="bold"?"bold":"normal",fontStyle:e.type==="italic"?"italic":"normal",textDecoration:e.type==="underline"?"underline":e.type==="strikethrough"?"line-through":"none",fontSize:l?`${18-l*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s",opacity:r?.5:1},onMouseEnter:m=>{!r&&!s&&(m.currentTarget.style.background="#f3f4f6")},onMouseLeave:m=>{s?m.currentTarget.style.background="#e5e7eb":m.currentTarget.style.background="transparent"},children:e.icon||x})}function B({items:e,onFullscreenToggle:s,isFullscreen:r=!1}){let[t]=(0,ee.useLexicalComposerContext)(),[d,f]=(0,h.useState)(!1),[l,x]=(0,h.useState)(!1),[m,c]=(0,h.useState)(!1),[o,y]=(0,h.useState)(!1),[u,T]=(0,h.useState)(!1),[a,b]=(0,h.useState)(!1),[g,H]=(0,h.useState)("paragraph"),L=(0,h.useCallback)(()=>{let p=(0,n.$getSelection)();if((0,n.$isRangeSelection)(p)){c(p.hasFormat("bold")),y(p.hasFormat("italic")),T(p.hasFormat("underline")),b(p.hasFormat("strikethrough"));let R=p.anchor.getNode(),S=R.getKey()==="root"?R:R.getTopLevelElementOrThrow(),C=S.getKey();if(t.getElementByKey(C)!==null){let E=(0,P.$isHeadingNode)(S)?S.getTag():S.getType();H(E)}}},[t]);(0,h.useEffect)(()=>(0,te.mergeRegister)(t.registerUpdateListener(({editorState:p})=>{p.read(()=>{L()})}),t.registerCommand(n.SELECTION_CHANGE_COMMAND,()=>(L(),!1),n.COMMAND_PRIORITY_LOW),t.registerCommand(n.CAN_UNDO_COMMAND,p=>(f(p),!1),n.COMMAND_PRIORITY_LOW),t.registerCommand(n.CAN_REDO_COMMAND,p=>(x(p),!1),n.COMMAND_PRIORITY_LOW)),[t,L]);let w=(0,h.useCallback)((p,R,S)=>{let{type:C}=p;if(C==="fullscreen"){s?.();return}if(C==="undo"){t.dispatchCommand(n.UNDO_COMMAND,void 0);return}if(C==="redo"){t.dispatchCommand(n.REDO_COMMAND,void 0);return}if(C==="textColor"&&R){t.update(()=>{let N=(0,n.$getSelection)();(0,n.$isRangeSelection)(N)&&(0,Y.$patchStyleText)(N,{color:R})});return}if(C==="backgroundColor"&&R){t.update(()=>{let N=(0,n.$getSelection)();(0,n.$isRangeSelection)(N)&&(0,Y.$patchStyleText)(N,{"background-color":R})});return}if(C==="bold"||C==="italic"||C==="underline"||C==="strikethrough"){t.dispatchCommand(n.FORMAT_TEXT_COMMAND,C);return}if(C==="alignLeft"){t.dispatchCommand(n.FORMAT_ELEMENT_COMMAND,"left");return}if(C==="alignCenter"){t.dispatchCommand(n.FORMAT_ELEMENT_COMMAND,"center");return}if(C==="alignRight"){t.dispatchCommand(n.FORMAT_ELEMENT_COMMAND,"right");return}if(C==="alignJustify"){t.dispatchCommand(n.FORMAT_ELEMENT_COMMAND,"justify");return}if(C==="headingDropdown"&&S){if(S==="paragraph")t.update(()=>{let N=(0,n.$getSelection)();if((0,n.$isRangeSelection)(N)){let E=N.anchor.getNode(),k=E.getKey()==="root"?E:E.getTopLevelElementOrThrow(),I=k.getKey();if(t.getElementByKey(I)!==null&&(0,P.$isHeadingNode)(k)&&(0,n.$isElementNode)(k)){let $=(0,n.$createParagraphNode)(),O=k.getChildren();$.append(...O),k.replace($),$.selectEnd()}}});else{let N=S;t.update(()=>{let E=(0,n.$getSelection)();if((0,n.$isRangeSelection)(E)){let k=E.anchor.getNode(),I=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),A=I.getKey();if(t.getElementByKey(A)!==null&&(0,n.$isElementNode)(I)){let O=(0,P.$createHeadingNode)(N),F=I.getChildren();O.append(...F),I.replace(O),O.selectEnd()}}})}return}if(C.startsWith("heading")&&C!=="headingDropdown"){let E=`h${parseInt(C.replace("heading",""))}`;t.update(()=>{let k=(0,n.$getSelection)();if((0,n.$isRangeSelection)(k)){let I=k.anchor.getNode(),A=I.getKey()==="root"?I:I.getTopLevelElementOrThrow(),$=A.getKey();if(t.getElementByKey($)!==null&&(0,n.$isElementNode)(A)){let F=(0,P.$createHeadingNode)(E),ue=A.getChildren();F.append(...ue),A.replace(F),F.selectEnd()}}});return}if(C==="paragraph"){t.update(()=>{let N=(0,n.$getSelection)();if((0,n.$isRangeSelection)(N)){let E=N.anchor.getNode(),k=E.getKey()==="root"?E:E.getTopLevelElementOrThrow(),I=k.getKey();if(t.getElementByKey(I)!==null&&(0,P.$isHeadingNode)(k)&&(0,n.$isElementNode)(k)){let $=(0,n.$createParagraphNode)(),O=k.getChildren();$.append(...O),k.replace($),$.selectEnd()}}});return}},[t,s]),K=p=>{switch(p){case"undo":return{disabled:!d};case"redo":return{disabled:!l};case"bold":return{active:m};case"italic":return{active:o};case"underline":return{active:u};case"strikethrough":return{active:a};case"fullscreen":return{active:r};case"heading1":return{active:g==="h1"};case"heading2":return{active:g==="h2"};case"heading3":return{active:g==="h3"};case"heading4":return{active:g==="h4"};case"heading5":return{active:g==="h5"};case"heading6":return{active:g==="h6"};case"paragraph":return{active:g==="paragraph"};default:return{}}};return(0,i.jsx)("div",{className:"luxe-toolbar",style:{display:"flex",gap:"4px",alignItems:"center",background:"white",borderBottom:"1px solid #e5e7eb",borderRadius:"8px 8px 0 0",padding:"8px",flexWrap:"wrap"},children:e.map((p,R)=>{let S=K(p.type);return p.type==="link"?(0,i.jsx)(Ne,{item:p,onAction:w,editor:t},`${p.type}-${R}`):(0,i.jsx)(Ee,{item:p,active:S.active,disabled:S.disabled,onAction:w,currentBlockType:g},`${p.type}-${R}`)})})}var z=require("react/jsx-runtime"),Ie=[{type:"bold"},{type:"italic"},{type:"underline"}];function Le(e){let s=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(r=>s.includes(r.type))}function G({enabled:e=!0,items:s}){let r=s?Le(s).slice(0,4):Ie,[t]=(0,oe.useLexicalComposerContext)(),[d,f]=(0,D.useState)(null),[l,x]=(0,D.useState)(null);(0,D.useEffect)(()=>{let o=t.getRootElement();o&&x(o)},[t]);let m=(0,D.useCallback)(()=>{if(!l)return;let o=window.getSelection();if(!o||o.rangeCount===0||o.isCollapsed){f(null);return}try{let y=o.getRangeAt(0);if(!l.contains(y.commonAncestorContainer)){f(null);return}let u=y.getBoundingClientRect();u&&u.width>0&&u.height>0?t.getEditorState().read(()=>{let T=(0,v.$getSelection)();T&&(0,v.$isRangeSelection)(T)&&!T.isCollapsed()?f({x:u.left+u.width/2,y:u.top-40}):f(null)}):f(null)}catch{f(null)}},[t,l]);(0,D.useEffect)(()=>{if(!l)return;let o=t.registerUpdateListener(()=>{setTimeout(()=>m(),10)});return()=>{o()}},[t,l,m]),(0,D.useEffect)(()=>{let o=()=>{setTimeout(()=>m(),50)},y=()=>{setTimeout(()=>m(),50)},u=()=>{setTimeout(()=>m(),50)};return document.addEventListener("mouseup",o),document.addEventListener("keyup",y),document.addEventListener("selectionchange",u),()=>{document.removeEventListener("mouseup",o),document.removeEventListener("keyup",y),document.removeEventListener("selectionchange",u)}},[m]);let c=(0,D.useCallback)((o,y)=>{let{type:u}=o;if(u==="textColor"&&y){t.update(()=>{let T=(0,v.$getSelection)();(0,v.$isRangeSelection)(T)&&(0,q.$patchStyleText)(T,{color:y})});return}if(u==="backgroundColor"&&y){t.update(()=>{let T=(0,v.$getSelection)();(0,v.$isRangeSelection)(T)&&(0,q.$patchStyleText)(T,{"background-color":y})});return}if(u==="bold"||u==="italic"||u==="underline"||u==="strikethrough"){t.dispatchCommand(v.FORMAT_TEXT_COMMAND,u);return}if(u.startsWith("heading")){let a=`h${parseInt(u.replace("heading",""))}`;t.update(()=>{let b=(0,v.$getSelection)();if((0,v.$isRangeSelection)(b)){let g=b.anchor.getNode(),H=g.getKey()==="root"?g:g.getTopLevelElementOrThrow(),L=H.getKey();if(t.getElementByKey(L)!==null&&(0,v.$isElementNode)(H)){let K=(0,j.$createHeadingNode)(a),p=H.getChildren();K.append(...p),H.replace(K),K.selectEnd()}}});return}if(u==="paragraph"){t.update(()=>{let T=(0,v.$getSelection)();if((0,v.$isRangeSelection)(T)){let a=T.anchor.getNode(),b=a.getKey()==="root"?a:a.getTopLevelElementOrThrow(),g=b.getKey();if(t.getElementByKey(g)!==null&&(0,j.$isHeadingNode)(b)&&(0,v.$isElementNode)(b)){let L=(0,v.$createParagraphNode)(),w=b.getChildren();L.append(...w),b.replace(L),L.selectEnd()}}});return}},[t]);return!e||!r||r.length===0||!d?null:(0,ne.createPortal)((0,z.jsx)("div",{className:"luxe-floating-toolbar",style:{position:"fixed",top:`${d.y}px`,left:`${d.x}px`,transform:"translateX(-50%)",display:"flex",gap:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3},children:r.map((o,y)=>{let u=o.label||U(o.type),a=o.type.startsWith("heading")?parseInt(o.type.replace("heading","")):null;if(o.type==="textColor"||o.type==="backgroundColor"){let b=o.colors||Z.slice(0,6);return(0,z.jsx)("div",{style:{display:"flex",gap:"2px"},children:o.color?(0,z.jsx)("button",{onClick:()=>c(o,o.color),title:`${o.type==="textColor"?"Text":"Background"} Color`,style:{padding:"4px 8px",border:"1px solid #e5e7eb",background:o.type==="backgroundColor"?o.color:"white",color:o.type==="textColor"?o.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"28px",height:"28px"},children:o.type==="textColor"?"A":"\u25A0"}):b.map(g=>(0,z.jsx)("button",{onClick:()=>c(o,g),title:g,style:{width:"24px",height:"24px",border:o.type==="textColor"?`3px solid ${g}`:"1px solid #e5e7eb",background:o.type==="backgroundColor"?g:"white",color:o.type==="textColor"?"#000":"inherit",cursor:"pointer",borderRadius:"3px",fontSize:"10px",display:"flex",alignItems:"center",justifyContent:"center"},children:o.type==="textColor"&&(0,z.jsx)("span",{style:{color:g,fontSize:"12px",fontWeight:"bold",lineHeight:"1"},children:"A"})},g))},`${o.type}-${y}`)}return(0,z.jsx)("button",{onClick:()=>c(o),title:o.type.charAt(0).toUpperCase()+o.type.slice(1),style:{padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",borderRadius:"4px",fontWeight:o.type==="bold"?"bold":"normal",fontStyle:o.type==="italic"?"italic":"normal",textDecoration:o.type==="underline"?"underline":o.type==="strikethrough"?"line-through":"none",fontSize:a?`${18-a*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:b=>{b.currentTarget.style.background="#f3f4f6"},onMouseLeave:b=>{b.currentTarget.style.background="transparent"},children:o.icon||u},`${o.type}-${y}`)})}),document.body)}var M=require("react/jsx-runtime"),re={paragraph:"luxe-paragraph",heading:{h1:"luxe-heading-h1",h2:"luxe-heading-h2",h3:"luxe-heading-h3",h4:"luxe-heading-h4",h5:"luxe-heading-h5",h6:"luxe-heading-h6"},text:{bold:"luxe-bold",italic:"luxe-italic",underline:"luxe-underline",strikethrough:"luxe-strikethrough"}};function we({initialConfig:e,showFloatingToolbar:s=!0,showToolbar:r=!0,toolbarItems:t,floatingToolbarItems:d,children:f}){let[l,x]=Q.default.useState(!1),m=[ce.HeadingNode,J.ParagraphNode,J.TextNode,X.LinkNode,X.AutoLinkNode],c=e.theme?{...re,...e.theme}:re,{theme:o,...y}=e,u={namespace:"LuxeEditor",theme:c,nodes:m,onError:g=>console.error(g),...y},a=t||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],b=Q.default.useCallback(()=>{x(g=>!g)},[]);return(0,M.jsx)(ae.LexicalComposer,{initialConfig:u,children:(0,M.jsxs)("div",{className:`luxe-editor-container ${l?"luxe-editor-fullscreen":""}`,children:[r&&a&&a.length>0&&(0,M.jsx)(B,{items:a,onFullscreenToggle:b,isFullscreen:l}),(0,M.jsx)(le.RichTextPlugin,{contentEditable:(0,M.jsx)(ie.ContentEditable,{className:"luxe-input"}),placeholder:(0,M.jsx)("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:de.LexicalErrorBoundary}),(0,M.jsx)(se.HistoryPlugin,{}),(0,M.jsx)(pe.LinkPlugin,{}),s&&(0,M.jsx)(G,{enabled:!0,items:d||a}),f]})})}0&&(module.exports={FloatingToolbarPlugin,LuxeEditor,Toolbar});
|
|
2
|
+
"use strict";var ve=Object.create;var J=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var Ie=(e,r)=>{for(var o in r)J(e,o,{get:r[o],enumerable:!0})},oe=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of Ee(r))!Le.call(e,l)&&l!==o&&J(e,l,{get:()=>r[l],enumerable:!(t=ke(r,l))||t.enumerable});return e};var we=(e,r,o)=>(o=e!=null?ve(Ne(e)):{},oe(r||!e||!e.__esModule?J(o,"default",{value:e,enumerable:!0}):o,e)),Se=e=>oe(J({},"__esModule",{value:!0}),e);var Fe={};Ie(Fe,{FloatingToolbarPlugin:()=>X,LuxeEditor:()=>We,Toolbar:()=>j,getEditorDOM:()=>pe,getEditorFormattedText:()=>ce,getEditorJSON:()=>se,getEditorText:()=>de,getEditorTree:()=>ue});module.exports=Se(Fe);var z=we(require("react")),fe=require("@lexical/react/LexicalComposer"),he=require("@lexical/react/LexicalRichTextPlugin"),be=require("@lexical/react/LexicalContentEditable"),me=require("@lexical/react/LexicalHistoryPlugin"),xe=require("@lexical/react/LexicalErrorBoundary"),ye=require("@lexical/react/LexicalLinkPlugin"),Te=require("@lexical/rich-text"),q=require("@lexical/link"),Y=require("lexical"),te=require("@lexical/react/LexicalComposerContext");var ie=require("@lexical/react/LexicalComposerContext"),v=require("lexical"),V=require("@lexical/selection"),G=require("@lexical/rich-text"),D=require("react"),ae=require("react-dom");var ne=require("@lexical/react/LexicalComposerContext"),re=require("@lexical/utils"),a=require("lexical"),Z=require("@lexical/selection"),W=require("@lexical/rich-text"),F=require("@lexical/link"),b=require("react"),p=require("react/jsx-runtime"),Q=["#000000","#ffffff","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#808080","#800000","#008000","#000080","#808000","#800080","#008080"];function B(e){return{undo:"\u21B6",redo:"\u21B7",divider:"",bold:"B",italic:"I",underline:"U",strikethrough:"S",heading1:"H1",heading2:"H2",heading3:"H3",heading4:"H4",heading5:"H5",heading6:"H6",paragraph:"P",alignLeft:"\u2B05",alignCenter:"\u2B0C",alignRight:"\u27A1",alignJustify:"\u2B0C",textColor:"A",backgroundColor:"\u2B1B",fullscreen:"\u26F6",headingDropdown:"Normal",link:"\u{1F517}"}[e]||e}function Re(){return(0,p.jsx)("div",{style:{width:"1px",height:"24px",background:"#e5e7eb",margin:"0 4px"}})}function Me({item:e,onAction:r}){let[o,t]=(0,b.useState)(!1),l=(0,b.useRef)(null),s=e.colors||Q;return(0,b.useEffect)(()=>{let i=u=>{l.current&&!l.current.contains(u.target)&&t(!1)};if(o)return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[o]),e.color?(0,p.jsx)("button",{onClick:()=>r(e,e.color),title:`${e.type==="textColor"?"Text":"Background"} Color: ${e.color}`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:e.type==="backgroundColor"?e.color:"white",color:e.type==="textColor"?e.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center"},children:e.icon||B(e.type)}):(0,p.jsxs)("div",{style:{position:"relative"},ref:l,children:[(0,p.jsxs)("button",{onClick:()=>t(!o),title:`${e.type==="textColor"?"Text":"Background"} Color`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:[e.icon||(0,p.jsx)("span",{style:{display:"block",width:"20px",height:"20px",background:e.type==="backgroundColor"?"linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%)":"currentColor",backgroundSize:e.type==="backgroundColor"?"8px 8px":"auto",backgroundPosition:e.type==="backgroundColor"?"0 0, 0 4px, 4px -4px, -4px 0px":"auto"},children:e.type==="textColor"&&(0,p.jsx)("span",{style:{color:"#000",fontSize:"12px"},children:"A"})}),(0,p.jsx)("span",{style:{marginLeft:"4px",fontSize:"10px"},children:"\u25BC"})]}),o&&(0,p.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"8px",display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"160px"},children:[s.map(i=>(0,p.jsxs)("button",{onClick:()=>{r(e,i),t(!1)},title:i,style:{width:"24px",height:"24px",borderRadius:"4px",border:e.type==="textColor"?`3px solid ${i}`:"1px solid #e5e7eb",background:e.type==="backgroundColor"?i:"white",color:e.type==="textColor"?"#000":"inherit",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",position:"relative"},children:[e.type==="textColor"&&(0,p.jsx)("span",{style:{color:i,fontSize:"14px",fontWeight:"bold",lineHeight:"1"},children:"A"}),e.type==="backgroundColor"&&i==="#ffffff"&&(0,p.jsx)("span",{style:{color:"#000",fontSize:"10px",border:"1px solid #ccc",width:"12px",height:"12px",display:"block"},children:"\u25A1"})]},i)),(0,p.jsx)("input",{type:"color",onChange:i=>{r(e,i.target.value),t(!1)},style:{gridColumn:"1 / -1",width:"100%",height:"32px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer"}})]})]})}function He({item:e,onAction:r,currentBlockType:o="paragraph"}){let[t,l]=(0,b.useState)(!1),s=(0,b.useRef)(null);(0,b.useEffect)(()=>{let c=n=>{s.current&&!s.current.contains(n.target)&&l(!1)};if(t)return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[t]);let i=()=>o==="paragraph"?"Normal":o.startsWith("h")?`Heading ${o.replace("h","")}`:"Normal",u=c=>{r(e,void 0,c),l(!1)},f=[{value:"paragraph",label:"Normal"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}];return(0,p.jsxs)("div",{style:{position:"relative"},ref:s,children:[(0,p.jsxs)("button",{onClick:()=>l(!t),title:"Heading",style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"100px",height:"32px",display:"flex",alignItems:"center",justifyContent:"space-between",position:"relative",fontSize:o==="paragraph"?"14px":o==="h1"?"20px":o==="h2"?"18px":o==="h3"?"16px":"14px",fontWeight:o!=="paragraph"?"bold":"normal"},children:[(0,p.jsx)("span",{children:e.label||i()}),(0,p.jsx)("span",{style:{marginLeft:"8px",fontSize:"10px"},children:"\u25BC"})]}),t&&(0,p.jsx)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"150px"},children:f.map(c=>(0,p.jsx)("button",{onClick:()=>u(c.value),style:{width:"100%",padding:"8px 12px",border:"none",background:o===c.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:c.value==="paragraph"?"14px":c.value==="h1"?"20px":c.value==="h2"?"18px":c.value==="h3"?"16px":"14px",fontWeight:c.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:n=>{o!==c.value&&(n.currentTarget.style.background="#f3f4f6")},onMouseLeave:n=>{o!==c.value?n.currentTarget.style.background="transparent":n.currentTarget.style.background="#e5e7eb"},children:c.label},c.value))})]})}function $e({item:e,onAction:r,editor:o}){let[t,l]=(0,b.useState)(!1),[s,i]=(0,b.useState)(""),[u,f]=(0,b.useState)(!1),c=(0,b.useRef)(null),n=(0,b.useRef)(null);(0,b.useEffect)(()=>{let d=()=>{o.getEditorState().read(()=>{let R=(0,a.$getSelection)();if((0,a.$isRangeSelection)(R)){let E=R.getNodes(),I=null;for(let M of E){let h=M.getParent();for(;h!==null;){if((0,F.$isLinkNode)(h)){I=h;break}h=h.getParent()}if(I)break}I&&(0,F.$isLinkNode)(I)?(f(!0),i(I.getURL())):(f(!1),i(""))}else f(!1),i("")})},y=o.registerUpdateListener(()=>{d()}),x=o.registerCommand(a.SELECTION_CHANGE_COMMAND,()=>(d(),!1),a.COMMAND_PRIORITY_LOW);return d(),()=>{y(),x()}},[o]),(0,b.useEffect)(()=>{let d=y=>{c.current&&!c.current.contains(y.target)&&l(!1)};if(t)return document.addEventListener("mousedown",d),setTimeout(()=>n.current?.focus(),0),()=>document.removeEventListener("mousedown",d)},[t,u,s]);let m=()=>{if(!s.trim()){o.dispatchCommand(F.TOGGLE_LINK_COMMAND,null),l(!1),i("");return}let d=s.trim();!d.startsWith("http://")&&!d.startsWith("https://")&&!d.startsWith("mailto:")&&!d.startsWith("#")&&!d.startsWith("/")&&(d="https://"+d),o.dispatchCommand(F.TOGGLE_LINK_COMMAND,d),l(!1),i("")},g=()=>{o.dispatchCommand(F.TOGGLE_LINK_COMMAND,null),l(!1),i("")},C=d=>{d.key==="Enter"?(d.preventDefault(),m()):d.key==="Escape"&&(l(!1),i(""))};return(0,p.jsxs)("div",{style:{position:"relative"},ref:c,children:[(0,p.jsx)("button",{onClick:()=>{l(!t)},title:u?"Edit Link":"Insert Link",style:{padding:"6px 12px",border:"none",background:u?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:d=>{u||(d.currentTarget.style.background="#f3f4f6")},onMouseLeave:d=>{u?d.currentTarget.style.background="#e5e7eb":d.currentTarget.style.background="transparent"},children:e.icon||B(e.type)}),t&&(0,p.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"300px"},children:[(0,p.jsx)("input",{ref:n,type:"text",placeholder:"Enter URL (e.g., https://example.com)",value:s,onChange:d=>i(d.target.value),onKeyDown:C,style:{width:"100%",padding:"8px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",marginBottom:"8px"}}),(0,p.jsxs)("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[u&&(0,p.jsx)("button",{onClick:g,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px",color:"#dc2626"},children:"Remove"}),(0,p.jsx)("button",{onClick:()=>l(!1),style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:"Cancel"}),(0,p.jsx)("button",{onClick:m,style:{padding:"6px 12px",border:"none",background:"#3b82f6",color:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:u?"Update":"Insert"})]})]})]})}function Oe({item:e,active:r=!1,disabled:o=!1,onAction:t,currentBlockType:l}){let i=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,u=e.label||B(e.type);return e.type==="divider"?(0,p.jsx)(Re,{}):e.type==="headingDropdown"?(0,p.jsx)(He,{item:e,onAction:t,currentBlockType:l}):e.type==="textColor"||e.type==="backgroundColor"?(0,p.jsx)(Me,{item:e,onAction:t}):(0,p.jsx)("button",{onClick:()=>t(e),disabled:o,title:e.type.charAt(0).toUpperCase()+e.type.slice(1).replace(/([A-Z])/g," $1").trim(),style:{padding:"6px 12px",border:"none",background:r?"#e5e7eb":"transparent",cursor:o?"not-allowed":"pointer",borderRadius:"4px",fontWeight:e.type==="bold"?"bold":"normal",fontStyle:e.type==="italic"?"italic":"normal",textDecoration:e.type==="underline"?"underline":e.type==="strikethrough"?"line-through":"none",fontSize:i?`${18-i*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s",opacity:o?.5:1},onMouseEnter:f=>{!o&&!r&&(f.currentTarget.style.background="#f3f4f6")},onMouseLeave:f=>{r?f.currentTarget.style.background="#e5e7eb":f.currentTarget.style.background="transparent"},children:e.icon||u})}function j({items:e,onFullscreenToggle:r,isFullscreen:o=!1}){let[t]=(0,ne.useLexicalComposerContext)(),[l,s]=(0,b.useState)(!1),[i,u]=(0,b.useState)(!1),[f,c]=(0,b.useState)(!1),[n,m]=(0,b.useState)(!1),[g,C]=(0,b.useState)(!1),[d,y]=(0,b.useState)(!1),[x,R]=(0,b.useState)("paragraph"),E=(0,b.useCallback)(()=>{let h=(0,a.$getSelection)();if((0,a.$isRangeSelection)(h)){c(h.hasFormat("bold")),m(h.hasFormat("italic")),C(h.hasFormat("underline")),y(h.hasFormat("strikethrough"));let H=h.anchor.getNode(),$=H.getKey()==="root"?H:H.getTopLevelElementOrThrow(),T=$.getKey();if(t.getElementByKey(T)!==null){let L=(0,W.$isHeadingNode)($)?$.getTag():$.getType();R(L)}}},[t]);(0,b.useEffect)(()=>(0,re.mergeRegister)(t.registerUpdateListener(({editorState:h})=>{h.read(()=>{E()})}),t.registerCommand(a.SELECTION_CHANGE_COMMAND,()=>(E(),!1),a.COMMAND_PRIORITY_LOW),t.registerCommand(a.CAN_UNDO_COMMAND,h=>(s(h),!1),a.COMMAND_PRIORITY_LOW),t.registerCommand(a.CAN_REDO_COMMAND,h=>(u(h),!1),a.COMMAND_PRIORITY_LOW)),[t,E]);let I=(0,b.useCallback)((h,H,$)=>{let{type:T}=h;if(T==="fullscreen"){r?.();return}if(T==="undo"){t.dispatchCommand(a.UNDO_COMMAND,void 0);return}if(T==="redo"){t.dispatchCommand(a.REDO_COMMAND,void 0);return}if(T==="textColor"&&H){t.update(()=>{let N=(0,a.$getSelection)();(0,a.$isRangeSelection)(N)&&(0,Z.$patchStyleText)(N,{color:H})});return}if(T==="backgroundColor"&&H){t.update(()=>{let N=(0,a.$getSelection)();(0,a.$isRangeSelection)(N)&&(0,Z.$patchStyleText)(N,{"background-color":H})});return}if(T==="bold"||T==="italic"||T==="underline"||T==="strikethrough"){t.dispatchCommand(a.FORMAT_TEXT_COMMAND,T);return}if(T==="alignLeft"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"left");return}if(T==="alignCenter"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"center");return}if(T==="alignRight"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"right");return}if(T==="alignJustify"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"justify");return}if(T==="headingDropdown"&&$){if($==="paragraph")t.update(()=>{let N=(0,a.$getSelection)();if((0,a.$isRangeSelection)(N)){let L=N.anchor.getNode(),k=L.getKey()==="root"?L:L.getTopLevelElementOrThrow(),S=k.getKey();if(t.getElementByKey(S)!==null&&(0,W.$isHeadingNode)(k)&&(0,a.$isElementNode)(k)){let A=(0,a.$createParagraphNode)(),P=k.getChildren();A.append(...P),k.replace(A),A.selectEnd()}}});else{let N=$;t.update(()=>{let L=(0,a.$getSelection)();if((0,a.$isRangeSelection)(L)){let k=L.anchor.getNode(),S=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),K=S.getKey();if(t.getElementByKey(K)!==null&&(0,a.$isElementNode)(S)){let P=(0,W.$createHeadingNode)(N),_=S.getChildren();P.append(..._),S.replace(P),P.selectEnd()}}})}return}if(T.startsWith("heading")&&T!=="headingDropdown"){let L=`h${parseInt(T.replace("heading",""))}`;t.update(()=>{let k=(0,a.$getSelection)();if((0,a.$isRangeSelection)(k)){let S=k.anchor.getNode(),K=S.getKey()==="root"?S:S.getTopLevelElementOrThrow(),A=K.getKey();if(t.getElementByKey(A)!==null&&(0,a.$isElementNode)(K)){let _=(0,W.$createHeadingNode)(L),Ce=K.getChildren();_.append(...Ce),K.replace(_),_.selectEnd()}}});return}if(T==="paragraph"){t.update(()=>{let N=(0,a.$getSelection)();if((0,a.$isRangeSelection)(N)){let L=N.anchor.getNode(),k=L.getKey()==="root"?L:L.getTopLevelElementOrThrow(),S=k.getKey();if(t.getElementByKey(S)!==null&&(0,W.$isHeadingNode)(k)&&(0,a.$isElementNode)(k)){let A=(0,a.$createParagraphNode)(),P=k.getChildren();A.append(...P),k.replace(A),A.selectEnd()}}});return}},[t,r]),M=h=>{switch(h){case"undo":return{disabled:!l};case"redo":return{disabled:!i};case"bold":return{active:f};case"italic":return{active:n};case"underline":return{active:g};case"strikethrough":return{active:d};case"fullscreen":return{active:o};case"heading1":return{active:x==="h1"};case"heading2":return{active:x==="h2"};case"heading3":return{active:x==="h3"};case"heading4":return{active:x==="h4"};case"heading5":return{active:x==="h5"};case"heading6":return{active:x==="h6"};case"paragraph":return{active:x==="paragraph"};default:return{}}};return(0,p.jsx)("div",{className:"luxe-toolbar",style:{display:"flex",gap:"4px",alignItems:"center",background:"white",borderBottom:"1px solid #e5e7eb",borderRadius:"8px 8px 0 0",padding:"8px",flexWrap:"wrap"},children:e.map((h,H)=>{let $=M(h.type);return h.type==="link"?(0,p.jsx)($e,{item:h,onAction:I,editor:t},`${h.type}-${H}`):(0,p.jsx)(Oe,{item:h,active:$.active,disabled:$.disabled,onAction:I,currentBlockType:x},`${h.type}-${H}`)})})}var U=require("react/jsx-runtime"),Ae=[{type:"bold"},{type:"italic"},{type:"underline"}];function De(e){let r=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(o=>r.includes(o.type))}function X({enabled:e=!0,items:r}){let o=r?De(r).slice(0,4):Ae,[t]=(0,ie.useLexicalComposerContext)(),[l,s]=(0,D.useState)(null),[i,u]=(0,D.useState)(null);(0,D.useEffect)(()=>{let n=t.getRootElement();n&&u(n)},[t]);let f=(0,D.useCallback)(()=>{if(!i)return;let n=window.getSelection();if(!n||n.rangeCount===0||n.isCollapsed){s(null);return}try{let m=n.getRangeAt(0);if(!i.contains(m.commonAncestorContainer)){s(null);return}let g=m.getBoundingClientRect();g&&g.width>0&&g.height>0?t.getEditorState().read(()=>{let C=(0,v.$getSelection)();C&&(0,v.$isRangeSelection)(C)&&!C.isCollapsed()?s({x:g.left+g.width/2,y:g.top-40}):s(null)}):s(null)}catch{s(null)}},[t,i]);(0,D.useEffect)(()=>{if(!i)return;let n=t.registerUpdateListener(()=>{setTimeout(()=>f(),10)});return()=>{n()}},[t,i,f]),(0,D.useEffect)(()=>{let n=()=>{setTimeout(()=>f(),50)},m=()=>{setTimeout(()=>f(),50)},g=()=>{setTimeout(()=>f(),50)};return document.addEventListener("mouseup",n),document.addEventListener("keyup",m),document.addEventListener("selectionchange",g),()=>{document.removeEventListener("mouseup",n),document.removeEventListener("keyup",m),document.removeEventListener("selectionchange",g)}},[f]);let c=(0,D.useCallback)((n,m)=>{let{type:g}=n;if(g==="textColor"&&m){t.update(()=>{let C=(0,v.$getSelection)();(0,v.$isRangeSelection)(C)&&(0,V.$patchStyleText)(C,{color:m})});return}if(g==="backgroundColor"&&m){t.update(()=>{let C=(0,v.$getSelection)();(0,v.$isRangeSelection)(C)&&(0,V.$patchStyleText)(C,{"background-color":m})});return}if(g==="bold"||g==="italic"||g==="underline"||g==="strikethrough"){t.dispatchCommand(v.FORMAT_TEXT_COMMAND,g);return}if(g.startsWith("heading")){let d=`h${parseInt(g.replace("heading",""))}`;t.update(()=>{let y=(0,v.$getSelection)();if((0,v.$isRangeSelection)(y)){let x=y.anchor.getNode(),R=x.getKey()==="root"?x:x.getTopLevelElementOrThrow(),E=R.getKey();if(t.getElementByKey(E)!==null&&(0,v.$isElementNode)(R)){let M=(0,G.$createHeadingNode)(d),h=R.getChildren();M.append(...h),R.replace(M),M.selectEnd()}}});return}if(g==="paragraph"){t.update(()=>{let C=(0,v.$getSelection)();if((0,v.$isRangeSelection)(C)){let d=C.anchor.getNode(),y=d.getKey()==="root"?d:d.getTopLevelElementOrThrow(),x=y.getKey();if(t.getElementByKey(x)!==null&&(0,G.$isHeadingNode)(y)&&(0,v.$isElementNode)(y)){let E=(0,v.$createParagraphNode)(),I=y.getChildren();E.append(...I),y.replace(E),E.selectEnd()}}});return}},[t]);return!e||!o||o.length===0||!l?null:(0,ae.createPortal)((0,U.jsx)("div",{className:"luxe-floating-toolbar",style:{position:"fixed",top:`${l.y}px`,left:`${l.x}px`,transform:"translateX(-50%)",display:"flex",gap:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3},children:o.map((n,m)=>{let g=n.label||B(n.type),d=n.type.startsWith("heading")?parseInt(n.type.replace("heading","")):null;if(n.type==="textColor"||n.type==="backgroundColor"){let y=n.colors||Q.slice(0,6);return(0,U.jsx)("div",{style:{display:"flex",gap:"2px"},children:n.color?(0,U.jsx)("button",{onClick:()=>c(n,n.color),title:`${n.type==="textColor"?"Text":"Background"} Color`,style:{padding:"4px 8px",border:"1px solid #e5e7eb",background:n.type==="backgroundColor"?n.color:"white",color:n.type==="textColor"?n.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"28px",height:"28px"},children:n.type==="textColor"?"A":"\u25A0"}):y.map(x=>(0,U.jsx)("button",{onClick:()=>c(n,x),title:x,style:{width:"24px",height:"24px",border:n.type==="textColor"?`3px solid ${x}`:"1px solid #e5e7eb",background:n.type==="backgroundColor"?x:"white",color:n.type==="textColor"?"#000":"inherit",cursor:"pointer",borderRadius:"3px",fontSize:"10px",display:"flex",alignItems:"center",justifyContent:"center"},children:n.type==="textColor"&&(0,U.jsx)("span",{style:{color:x,fontSize:"12px",fontWeight:"bold",lineHeight:"1"},children:"A"})},x))},`${n.type}-${m}`)}return(0,U.jsx)("button",{onClick:()=>c(n),title:n.type.charAt(0).toUpperCase()+n.type.slice(1),style:{padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",borderRadius:"4px",fontWeight:n.type==="bold"?"bold":"normal",fontStyle:n.type==="italic"?"italic":"normal",textDecoration:n.type==="underline"?"underline":n.type==="strikethrough"?"line-through":"none",fontSize:d?`${18-d*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:y=>{y.currentTarget.style.background="#f3f4f6"},onMouseLeave:y=>{y.currentTarget.style.background="transparent"},children:n.icon||g},`${n.type}-${m}`)})}),document.body)}var O=require("lexical"),le=require("@lexical/rich-text");function se(e){return e.toJSON()}function de(e){let r="";return e.read(()=>{r=(0,O.$getRoot)().getTextContent()}),r}function ee(e,r){let o=(r&1)!==0,t=(r&2)!==0,l=(r&4)!==0,s=(r&8)!==0;return o&&t?e=`***${e}***`:o?e=`**${e}**`:t&&(e=`*${e}*`),l&&(e=`__${e}__`),s&&(e=`~~${e}~~`),e}function ce(e){let r="";return e.read(()=>{let t=(0,O.$getRoot)().getChildren(),l=s=>{let i="";if((0,le.$isHeadingNode)(s)){let u=s.getTag(),f=parseInt(u.replace("h","")),c="#".repeat(f),n=s.getChildren(),m="";for(let g of n)(0,O.$isTextNode)(g)?m+=ee(g.getTextContent(),g.getFormat()):(0,O.$isElementNode)(g)&&(m+=l(g));i+=`${c} ${m}
|
|
3
|
+
|
|
4
|
+
`}else if((0,O.$isElementNode)(s)){let u=s.getChildren(),f="";for(let n of u)(0,O.$isTextNode)(n)?f+=ee(n.getTextContent(),n.getFormat()):(0,O.$isElementNode)(n)&&(f+=l(n));let c=s.getType();c==="paragraph"?i+=f+`
|
|
5
|
+
|
|
6
|
+
`:i+=f}else(0,O.$isTextNode)(s)&&(i+=ee(s.getTextContent(),s.getFormat()));return i};for(let s of t)r+=l(s)}),r.trim()}function pe(e){if(!e)return"";try{let r=e.getRootElement();if(!r)return"";let o=r.querySelector('[contenteditable="true"]');if(o)return(o.innerHTML||"").trim()||"";if(r.hasAttribute("contenteditable")&&r.getAttribute("contenteditable")==="true")return r.innerHTML||"";let t=Array.from(r.children).filter(l=>{let s=l.id||"",i=l.className||"";return!s.includes("toolbar")&&!i.includes("toolbar")});if(t.length>0){for(let l of t)if(l.hasAttribute("contenteditable"))return l.innerHTML||"";return t[0].innerHTML||""}return r.innerHTML||""}catch(r){return console.error("Error getting editor DOM:",r),""}}function ue(e){if(!e||!e.root)return null;let r=(o,t=0)=>{if(!o)return null;let l=o.type||"unknown",s=o.key||"",i=o.children||[],u={type:l,key:s,depth:t,children:[]};return o.tag&&(u.tag=o.tag),o.format!==void 0&&(u.format=o.format),o.text&&(u.text=o.text.substring(0,50)+(o.text.length>50?"...":"")),o.style&&(u.style=o.style),o.indent&&(u.indent=o.indent),o.direction&&(u.direction=o.direction),Array.isArray(i)&&(u.children=i.map(f=>r(f,t+1)).filter(Boolean)),u};return r(e.root)}var w=require("react/jsx-runtime"),ge={paragraph:"luxe-paragraph",heading:{h1:"luxe-heading-h1",h2:"luxe-heading-h2",h3:"luxe-heading-h3",h4:"luxe-heading-h4",h5:"luxe-heading-h5",h6:"luxe-heading-h6"},text:{bold:"luxe-bold",italic:"luxe-italic",underline:"luxe-underline",strikethrough:"luxe-strikethrough"}};function Ke({onChange:e,ignoreInitialChange:r}){let[o]=(0,te.useLexicalComposerContext)(),t=z.default.useRef(!0);return z.default.useEffect(()=>o.registerUpdateListener(({editorState:l,prevEditorState:s})=>{if(r&&t.current&&s.isEmpty()){t.current=!1;return}t.current=!1,e(l,o)}),[o,e,r]),null}function Pe({initialJSON:e}){let[r]=(0,te.useLexicalComposerContext)(),o=z.default.useRef(!1);return z.default.useEffect(()=>{if(!(!e||o.current))try{let t=r.parseEditorState(e);r.setEditorState(t),o.current=!0}catch(t){console.error("LuxeEditor: Failed to parse initialJSON",t)}},[r,e]),null}function We({initialConfig:e,initialJSON:r,showFloatingToolbar:o=!0,showToolbar:t=!0,toolbarItems:l,floatingToolbarItems:s,onChange:i,ignoreInitialChange:u=!0,children:f}){let[c,n]=z.default.useState(!1),m=[Te.HeadingNode,Y.ParagraphNode,Y.TextNode,q.LinkNode,q.AutoLinkNode],g=e.theme?{...ge,...e.theme}:ge,{theme:C,...d}=e,y=d.onUpdate,x={namespace:"LuxeEditor",theme:g,nodes:m,onError:M=>console.error(M),onUpdate:y,...d},E=l||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],I=z.default.useCallback(()=>{n(M=>!M)},[]);return(0,w.jsx)(fe.LexicalComposer,{initialConfig:x,children:(0,w.jsxs)("div",{className:`luxe-editor-container ${c?"luxe-editor-fullscreen":""}`,children:[t&&E&&E.length>0&&(0,w.jsx)(j,{items:E,onFullscreenToggle:I,isFullscreen:c}),(0,w.jsx)(he.RichTextPlugin,{contentEditable:(0,w.jsx)(be.ContentEditable,{className:"luxe-input"}),placeholder:(0,w.jsx)("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:xe.LexicalErrorBoundary}),(0,w.jsx)(me.HistoryPlugin,{}),(0,w.jsx)(ye.LinkPlugin,{}),i&&(0,w.jsx)(Ke,{onChange:i,ignoreInitialChange:u}),r&&(0,w.jsx)(Pe,{initialJSON:r}),o&&(0,w.jsx)(X,{enabled:!0,items:s||E}),f]})})}0&&(module.exports={FloatingToolbarPlugin,LuxeEditor,Toolbar,getEditorDOM,getEditorFormattedText,getEditorJSON,getEditorText,getEditorTree});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import pe from"react";import{LexicalComposer as $e}from"@lexical/react/LexicalComposer";import{RichTextPlugin as De}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as Ae}from"@lexical/react/LexicalContentEditable";import{HistoryPlugin as Oe}from"@lexical/react/LexicalHistoryPlugin";import{LexicalErrorBoundary as Ke}from"@lexical/react/LexicalErrorBoundary";import{LinkPlugin as Pe}from"@lexical/react/LexicalLinkPlugin";import{HeadingNode as We}from"@lexical/rich-text";import{LinkNode as ze,AutoLinkNode as Fe}from"@lexical/link";import{ParagraphNode as Ue,TextNode as _e}from"lexical";import{useLexicalComposerContext as Ee}from"@lexical/react/LexicalComposerContext";import{$getSelection as U,$isRangeSelection as _,FORMAT_TEXT_COMMAND as Ie,$createParagraphNode as Le,$isElementNode as le}from"lexical";import{$patchStyleText as ie}from"@lexical/selection";import{$createHeadingNode as we,$isHeadingNode as Re}from"@lexical/rich-text";import{useCallback as se,useEffect as Q,useState as de}from"react";import{createPortal as Se}from"react-dom";import{useLexicalComposerContext as ge}from"@lexical/react/LexicalComposerContext";import{mergeRegister as he}from"@lexical/utils";import{$getSelection as D,$isRangeSelection as A,$createParagraphNode as ee,$isElementNode as B,CAN_REDO_COMMAND as fe,CAN_UNDO_COMMAND as be,COMMAND_PRIORITY_LOW as G,FORMAT_ELEMENT_COMMAND as j,FORMAT_TEXT_COMMAND as xe,REDO_COMMAND as me,SELECTION_CHANGE_COMMAND as ae,UNDO_COMMAND as ye}from"lexical";import{$patchStyleText as te}from"@lexical/selection";import{$createHeadingNode as oe,$isHeadingNode as J}from"@lexical/rich-text";import{$isLinkNode as ne,TOGGLE_LINK_COMMAND as Y}from"@lexical/link";import{useCallback as re,useEffect as z,useState as N,useRef as X}from"react";import{jsx as c,jsxs as M}from"react/jsx-runtime";var Z=["#000000","#ffffff","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#808080","#800000","#008000","#000080","#808000","#800080","#008080"];function F(e){return{undo:"\u21B6",redo:"\u21B7",divider:"",bold:"B",italic:"I",underline:"U",strikethrough:"S",heading1:"H1",heading2:"H2",heading3:"H3",heading4:"H4",heading5:"H5",heading6:"H6",paragraph:"P",alignLeft:"\u2B05",alignCenter:"\u2B0C",alignRight:"\u27A1",alignJustify:"\u2B0C",textColor:"A",backgroundColor:"\u2B1B",fullscreen:"\u26F6",headingDropdown:"Normal",link:"\u{1F517}"}[e]||e}function Ce(){return c("div",{style:{width:"1px",height:"24px",background:"#e5e7eb",margin:"0 4px"}})}function Te({item:e,onAction:h}){let[r,t]=N(!1),p=X(null),u=e.colors||Z;return z(()=>{let a=f=>{p.current&&!p.current.contains(f.target)&&t(!1)};if(r)return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[r]),e.color?c("button",{onClick:()=>h(e,e.color),title:`${e.type==="textColor"?"Text":"Background"} Color: ${e.color}`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:e.type==="backgroundColor"?e.color:"white",color:e.type==="textColor"?e.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center"},children:e.icon||F(e.type)}):M("div",{style:{position:"relative"},ref:p,children:[M("button",{onClick:()=>t(!r),title:`${e.type==="textColor"?"Text":"Background"} Color`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:[e.icon||c("span",{style:{display:"block",width:"20px",height:"20px",background:e.type==="backgroundColor"?"linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%)":"currentColor",backgroundSize:e.type==="backgroundColor"?"8px 8px":"auto",backgroundPosition:e.type==="backgroundColor"?"0 0, 0 4px, 4px -4px, -4px 0px":"auto"},children:e.type==="textColor"&&c("span",{style:{color:"#000",fontSize:"12px"},children:"A"})}),c("span",{style:{marginLeft:"4px",fontSize:"10px"},children:"\u25BC"})]}),r&&M("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"8px",display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"160px"},children:[u.map(a=>M("button",{onClick:()=>{h(e,a),t(!1)},title:a,style:{width:"24px",height:"24px",borderRadius:"4px",border:e.type==="textColor"?`3px solid ${a}`:"1px solid #e5e7eb",background:e.type==="backgroundColor"?a:"white",color:e.type==="textColor"?"#000":"inherit",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",position:"relative"},children:[e.type==="textColor"&&c("span",{style:{color:a,fontSize:"14px",fontWeight:"bold",lineHeight:"1"},children:"A"}),e.type==="backgroundColor"&&a==="#ffffff"&&c("span",{style:{color:"#000",fontSize:"10px",border:"1px solid #ccc",width:"12px",height:"12px",display:"block"},children:"\u25A1"})]},a)),c("input",{type:"color",onChange:a=>{h(e,a.target.value),t(!1)},style:{gridColumn:"1 / -1",width:"100%",height:"32px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer"}})]})]})}function ve({item:e,onAction:h,currentBlockType:r="paragraph"}){let[t,p]=N(!1),u=X(null);z(()=>{let i=o=>{u.current&&!u.current.contains(o.target)&&p(!1)};if(t)return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[t]);let a=()=>r==="paragraph"?"Normal":r.startsWith("h")?`Heading ${r.replace("h","")}`:"Normal",f=i=>{h(e,void 0,i),p(!1)},b=[{value:"paragraph",label:"Normal"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}];return M("div",{style:{position:"relative"},ref:u,children:[M("button",{onClick:()=>p(!t),title:"Heading",style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"100px",height:"32px",display:"flex",alignItems:"center",justifyContent:"space-between",position:"relative",fontSize:r==="paragraph"?"14px":r==="h1"?"20px":r==="h2"?"18px":r==="h3"?"16px":"14px",fontWeight:r!=="paragraph"?"bold":"normal"},children:[c("span",{children:e.label||a()}),c("span",{style:{marginLeft:"8px",fontSize:"10px"},children:"\u25BC"})]}),t&&c("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"150px"},children:b.map(i=>c("button",{onClick:()=>f(i.value),style:{width:"100%",padding:"8px 12px",border:"none",background:r===i.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:i.value==="paragraph"?"14px":i.value==="h1"?"20px":i.value==="h2"?"18px":i.value==="h3"?"16px":"14px",fontWeight:i.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:o=>{r!==i.value&&(o.currentTarget.style.background="#f3f4f6")},onMouseLeave:o=>{r!==i.value?o.currentTarget.style.background="transparent":o.currentTarget.style.background="#e5e7eb"},children:i.label},i.value))})]})}function ke({item:e,onAction:h,editor:r}){let[t,p]=N(!1),[u,a]=N(""),[f,b]=N(!1),i=X(null),o=X(null);z(()=>{let n=()=>{r.getEditorState().read(()=>{let R=D();if(A(R)){let E=R.getNodes(),I=null;for(let K of E){let l=K.getParent();for(;l!==null;){if(ne(l)){I=l;break}l=l.getParent()}if(I)break}I&&ne(I)?(b(!0),a(I.getURL())):(b(!1),a(""))}else b(!1),a("")})},g=r.registerUpdateListener(()=>{n()}),d=r.registerCommand(ae,()=>(n(),!1),G);return n(),()=>{g(),d()}},[r]),z(()=>{let n=g=>{i.current&&!i.current.contains(g.target)&&p(!1)};if(t)return document.addEventListener("mousedown",n),setTimeout(()=>o.current?.focus(),0),()=>document.removeEventListener("mousedown",n)},[t,f,u]);let x=()=>{if(!u.trim()){r.dispatchCommand(Y,null),p(!1),a("");return}let n=u.trim();!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("mailto:")&&!n.startsWith("#")&&!n.startsWith("/")&&(n="https://"+n),r.dispatchCommand(Y,n),p(!1),a("")},s=()=>{r.dispatchCommand(Y,null),p(!1),a("")},y=n=>{n.key==="Enter"?(n.preventDefault(),x()):n.key==="Escape"&&(p(!1),a(""))};return M("div",{style:{position:"relative"},ref:i,children:[c("button",{onClick:()=>{p(!t)},title:f?"Edit Link":"Insert Link",style:{padding:"6px 12px",border:"none",background:f?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:n=>{f||(n.currentTarget.style.background="#f3f4f6")},onMouseLeave:n=>{f?n.currentTarget.style.background="#e5e7eb":n.currentTarget.style.background="transparent"},children:e.icon||F(e.type)}),t&&M("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"300px"},children:[c("input",{ref:o,type:"text",placeholder:"Enter URL (e.g., https://example.com)",value:u,onChange:n=>a(n.target.value),onKeyDown:y,style:{width:"100%",padding:"8px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",marginBottom:"8px"}}),M("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[f&&c("button",{onClick:s,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px",color:"#dc2626"},children:"Remove"}),c("button",{onClick:()=>p(!1),style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:"Cancel"}),c("button",{onClick:x,style:{padding:"6px 12px",border:"none",background:"#3b82f6",color:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:f?"Update":"Insert"})]})]})]})}function Ne({item:e,active:h=!1,disabled:r=!1,onAction:t,currentBlockType:p}){let a=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,f=e.label||F(e.type);return e.type==="divider"?c(Ce,{}):e.type==="headingDropdown"?c(ve,{item:e,onAction:t,currentBlockType:p}):e.type==="textColor"||e.type==="backgroundColor"?c(Te,{item:e,onAction:t}):c("button",{onClick:()=>t(e),disabled:r,title:e.type.charAt(0).toUpperCase()+e.type.slice(1).replace(/([A-Z])/g," $1").trim(),style:{padding:"6px 12px",border:"none",background:h?"#e5e7eb":"transparent",cursor:r?"not-allowed":"pointer",borderRadius:"4px",fontWeight:e.type==="bold"?"bold":"normal",fontStyle:e.type==="italic"?"italic":"normal",textDecoration:e.type==="underline"?"underline":e.type==="strikethrough"?"line-through":"none",fontSize:a?`${18-a*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s",opacity:r?.5:1},onMouseEnter:b=>{!r&&!h&&(b.currentTarget.style.background="#f3f4f6")},onMouseLeave:b=>{h?b.currentTarget.style.background="#e5e7eb":b.currentTarget.style.background="transparent"},children:e.icon||f})}function q({items:e,onFullscreenToggle:h,isFullscreen:r=!1}){let[t]=ge(),[p,u]=N(!1),[a,f]=N(!1),[b,i]=N(!1),[o,x]=N(!1),[s,y]=N(!1),[n,g]=N(!1),[d,R]=N("paragraph"),E=re(()=>{let l=D();if(A(l)){i(l.hasFormat("bold")),x(l.hasFormat("italic")),y(l.hasFormat("underline")),g(l.hasFormat("strikethrough"));let L=l.anchor.getNode(),w=L.getKey()==="root"?L:L.getTopLevelElementOrThrow(),m=w.getKey();if(t.getElementByKey(m)!==null){let v=J(w)?w.getTag():w.getType();R(v)}}},[t]);z(()=>he(t.registerUpdateListener(({editorState:l})=>{l.read(()=>{E()})}),t.registerCommand(ae,()=>(E(),!1),G),t.registerCommand(be,l=>(u(l),!1),G),t.registerCommand(fe,l=>(f(l),!1),G)),[t,E]);let I=re((l,L,w)=>{let{type:m}=l;if(m==="fullscreen"){h?.();return}if(m==="undo"){t.dispatchCommand(ye,void 0);return}if(m==="redo"){t.dispatchCommand(me,void 0);return}if(m==="textColor"&&L){t.update(()=>{let T=D();A(T)&&te(T,{color:L})});return}if(m==="backgroundColor"&&L){t.update(()=>{let T=D();A(T)&&te(T,{"background-color":L})});return}if(m==="bold"||m==="italic"||m==="underline"||m==="strikethrough"){t.dispatchCommand(xe,m);return}if(m==="alignLeft"){t.dispatchCommand(j,"left");return}if(m==="alignCenter"){t.dispatchCommand(j,"center");return}if(m==="alignRight"){t.dispatchCommand(j,"right");return}if(m==="alignJustify"){t.dispatchCommand(j,"justify");return}if(m==="headingDropdown"&&w){if(w==="paragraph")t.update(()=>{let T=D();if(A(T)){let v=T.anchor.getNode(),C=v.getKey()==="root"?v:v.getTopLevelElementOrThrow(),k=C.getKey();if(t.getElementByKey(k)!==null&&J(C)&&B(C)){let S=ee(),$=C.getChildren();S.append(...$),C.replace(S),S.selectEnd()}}});else{let T=w;t.update(()=>{let v=D();if(A(v)){let C=v.anchor.getNode(),k=C.getKey()==="root"?C:C.getTopLevelElementOrThrow(),H=k.getKey();if(t.getElementByKey(H)!==null&&B(k)){let $=oe(T),W=k.getChildren();$.append(...W),k.replace($),$.selectEnd()}}})}return}if(m.startsWith("heading")&&m!=="headingDropdown"){let v=`h${parseInt(m.replace("heading",""))}`;t.update(()=>{let C=D();if(A(C)){let k=C.anchor.getNode(),H=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),S=H.getKey();if(t.getElementByKey(S)!==null&&B(H)){let W=oe(v),ue=H.getChildren();W.append(...ue),H.replace(W),W.selectEnd()}}});return}if(m==="paragraph"){t.update(()=>{let T=D();if(A(T)){let v=T.anchor.getNode(),C=v.getKey()==="root"?v:v.getTopLevelElementOrThrow(),k=C.getKey();if(t.getElementByKey(k)!==null&&J(C)&&B(C)){let S=ee(),$=C.getChildren();S.append(...$),C.replace(S),S.selectEnd()}}});return}},[t,h]),K=l=>{switch(l){case"undo":return{disabled:!p};case"redo":return{disabled:!a};case"bold":return{active:b};case"italic":return{active:o};case"underline":return{active:s};case"strikethrough":return{active:n};case"fullscreen":return{active:r};case"heading1":return{active:d==="h1"};case"heading2":return{active:d==="h2"};case"heading3":return{active:d==="h3"};case"heading4":return{active:d==="h4"};case"heading5":return{active:d==="h5"};case"heading6":return{active:d==="h6"};case"paragraph":return{active:d==="paragraph"};default:return{}}};return c("div",{className:"luxe-toolbar",style:{display:"flex",gap:"4px",alignItems:"center",background:"white",borderBottom:"1px solid #e5e7eb",borderRadius:"8px 8px 0 0",padding:"8px",flexWrap:"wrap"},children:e.map((l,L)=>{let w=K(l.type);return l.type==="link"?c(ke,{item:l,onAction:I,editor:t},`${l.type}-${L}`):c(Ne,{item:l,active:w.active,disabled:w.disabled,onAction:I,currentBlockType:d},`${l.type}-${L}`)})})}import{jsx as P}from"react/jsx-runtime";var Me=[{type:"bold"},{type:"italic"},{type:"underline"}];function He(e){let h=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(r=>h.includes(r.type))}function V({enabled:e=!0,items:h}){let r=h?He(h).slice(0,4):Me,[t]=Ee(),[p,u]=de(null),[a,f]=de(null);Q(()=>{let o=t.getRootElement();o&&f(o)},[t]);let b=se(()=>{if(!a)return;let o=window.getSelection();if(!o||o.rangeCount===0||o.isCollapsed){u(null);return}try{let x=o.getRangeAt(0);if(!a.contains(x.commonAncestorContainer)){u(null);return}let s=x.getBoundingClientRect();s&&s.width>0&&s.height>0?t.getEditorState().read(()=>{let y=U();y&&_(y)&&!y.isCollapsed()?u({x:s.left+s.width/2,y:s.top-40}):u(null)}):u(null)}catch{u(null)}},[t,a]);Q(()=>{if(!a)return;let o=t.registerUpdateListener(()=>{setTimeout(()=>b(),10)});return()=>{o()}},[t,a,b]),Q(()=>{let o=()=>{setTimeout(()=>b(),50)},x=()=>{setTimeout(()=>b(),50)},s=()=>{setTimeout(()=>b(),50)};return document.addEventListener("mouseup",o),document.addEventListener("keyup",x),document.addEventListener("selectionchange",s),()=>{document.removeEventListener("mouseup",o),document.removeEventListener("keyup",x),document.removeEventListener("selectionchange",s)}},[b]);let i=se((o,x)=>{let{type:s}=o;if(s==="textColor"&&x){t.update(()=>{let y=U();_(y)&&ie(y,{color:x})});return}if(s==="backgroundColor"&&x){t.update(()=>{let y=U();_(y)&&ie(y,{"background-color":x})});return}if(s==="bold"||s==="italic"||s==="underline"||s==="strikethrough"){t.dispatchCommand(Ie,s);return}if(s.startsWith("heading")){let n=`h${parseInt(s.replace("heading",""))}`;t.update(()=>{let g=U();if(_(g)){let d=g.anchor.getNode(),R=d.getKey()==="root"?d:d.getTopLevelElementOrThrow(),E=R.getKey();if(t.getElementByKey(E)!==null&&le(R)){let K=we(n),l=R.getChildren();K.append(...l),R.replace(K),K.selectEnd()}}});return}if(s==="paragraph"){t.update(()=>{let y=U();if(_(y)){let n=y.anchor.getNode(),g=n.getKey()==="root"?n:n.getTopLevelElementOrThrow(),d=g.getKey();if(t.getElementByKey(d)!==null&&Re(g)&&le(g)){let E=Le(),I=g.getChildren();E.append(...I),g.replace(E),E.selectEnd()}}});return}},[t]);return!e||!r||r.length===0||!p?null:Se(P("div",{className:"luxe-floating-toolbar",style:{position:"fixed",top:`${p.y}px`,left:`${p.x}px`,transform:"translateX(-50%)",display:"flex",gap:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3},children:r.map((o,x)=>{let s=o.label||F(o.type),n=o.type.startsWith("heading")?parseInt(o.type.replace("heading","")):null;if(o.type==="textColor"||o.type==="backgroundColor"){let g=o.colors||Z.slice(0,6);return P("div",{style:{display:"flex",gap:"2px"},children:o.color?P("button",{onClick:()=>i(o,o.color),title:`${o.type==="textColor"?"Text":"Background"} Color`,style:{padding:"4px 8px",border:"1px solid #e5e7eb",background:o.type==="backgroundColor"?o.color:"white",color:o.type==="textColor"?o.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"28px",height:"28px"},children:o.type==="textColor"?"A":"\u25A0"}):g.map(d=>P("button",{onClick:()=>i(o,d),title:d,style:{width:"24px",height:"24px",border:o.type==="textColor"?`3px solid ${d}`:"1px solid #e5e7eb",background:o.type==="backgroundColor"?d:"white",color:o.type==="textColor"?"#000":"inherit",cursor:"pointer",borderRadius:"3px",fontSize:"10px",display:"flex",alignItems:"center",justifyContent:"center"},children:o.type==="textColor"&&P("span",{style:{color:d,fontSize:"12px",fontWeight:"bold",lineHeight:"1"},children:"A"})},d))},`${o.type}-${x}`)}return P("button",{onClick:()=>i(o),title:o.type.charAt(0).toUpperCase()+o.type.slice(1),style:{padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",borderRadius:"4px",fontWeight:o.type==="bold"?"bold":"normal",fontStyle:o.type==="italic"?"italic":"normal",textDecoration:o.type==="underline"?"underline":o.type==="strikethrough"?"line-through":"none",fontSize:n?`${18-n*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:g=>{g.currentTarget.style.background="#f3f4f6"},onMouseLeave:g=>{g.currentTarget.style.background="transparent"},children:o.icon||s},`${o.type}-${x}`)})}),document.body)}import{jsx as O,jsxs as Be}from"react/jsx-runtime";var ce={paragraph:"luxe-paragraph",heading:{h1:"luxe-heading-h1",h2:"luxe-heading-h2",h3:"luxe-heading-h3",h4:"luxe-heading-h4",h5:"luxe-heading-h5",h6:"luxe-heading-h6"},text:{bold:"luxe-bold",italic:"luxe-italic",underline:"luxe-underline",strikethrough:"luxe-strikethrough"}};function Nt({initialConfig:e,showFloatingToolbar:h=!0,showToolbar:r=!0,toolbarItems:t,floatingToolbarItems:p,children:u}){let[a,f]=pe.useState(!1),b=[We,Ue,_e,ze,Fe],i=e.theme?{...ce,...e.theme}:ce,{theme:o,...x}=e,s={namespace:"LuxeEditor",theme:i,nodes:b,onError:d=>console.error(d),...x},n=t||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],g=pe.useCallback(()=>{f(d=>!d)},[]);return O($e,{initialConfig:s,children:Be("div",{className:`luxe-editor-container ${a?"luxe-editor-fullscreen":""}`,children:[r&&n&&n.length>0&&O(q,{items:n,onFullscreenToggle:g,isFullscreen:a}),O(De,{contentEditable:O(Ae,{className:"luxe-input"}),placeholder:O("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:Ke}),O(Oe,{}),O(Pe,{}),h&&O(V,{enabled:!0,items:p||n}),u]})})}export{V as FloatingToolbarPlugin,Nt as LuxeEditor,q as Toolbar};
|
|
2
|
+
import W from"react";import{LexicalComposer as Be}from"@lexical/react/LexicalComposer";import{RichTextPlugin as Je}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as je}from"@lexical/react/LexicalContentEditable";import{HistoryPlugin as Ge}from"@lexical/react/LexicalHistoryPlugin";import{LexicalErrorBoundary as Xe}from"@lexical/react/LexicalErrorBoundary";import{LinkPlugin as qe}from"@lexical/react/LexicalLinkPlugin";import{HeadingNode as Ye}from"@lexical/rich-text";import{LinkNode as Ze,AutoLinkNode as Qe}from"@lexical/link";import{ParagraphNode as Ve,TextNode as et}from"lexical";import{useLexicalComposerContext as be}from"@lexical/react/LexicalComposerContext";import{useLexicalComposerContext as Re}from"@lexical/react/LexicalComposerContext";import{$getSelection as _,$isRangeSelection as B,FORMAT_TEXT_COMMAND as Me,$createParagraphNode as He,$isElementNode as ce}from"lexical";import{$patchStyleText as pe}from"@lexical/selection";import{$createHeadingNode as $e,$isHeadingNode as Oe}from"@lexical/rich-text";import{useCallback as ue,useEffect as V,useState as ge}from"react";import{createPortal as Ae}from"react-dom";import{useLexicalComposerContext as xe}from"@lexical/react/LexicalComposerContext";import{mergeRegister as ye}from"@lexical/utils";import{$getSelection as D,$isRangeSelection as K,$createParagraphNode as re,$isElementNode as J,CAN_REDO_COMMAND as Te,CAN_UNDO_COMMAND as Ce,COMMAND_PRIORITY_LOW as G,FORMAT_ELEMENT_COMMAND as j,FORMAT_TEXT_COMMAND as ve,REDO_COMMAND as ke,SELECTION_CHANGE_COMMAND as de,UNDO_COMMAND as Ee}from"lexical";import{$patchStyleText as ie}from"@lexical/selection";import{$createHeadingNode as ae,$isHeadingNode as q}from"@lexical/rich-text";import{$isLinkNode as le,TOGGLE_LINK_COMMAND as Y}from"@lexical/link";import{useCallback as se,useEffect as U,useState as L,useRef as X}from"react";import{jsx as b,jsxs as $}from"react/jsx-runtime";var Z=["#000000","#ffffff","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#808080","#800000","#008000","#000080","#808000","#800080","#008080"];function z(e){return{undo:"\u21B6",redo:"\u21B7",divider:"",bold:"B",italic:"I",underline:"U",strikethrough:"S",heading1:"H1",heading2:"H2",heading3:"H3",heading4:"H4",heading5:"H5",heading6:"H6",paragraph:"P",alignLeft:"\u2B05",alignCenter:"\u2B0C",alignRight:"\u27A1",alignJustify:"\u2B0C",textColor:"A",backgroundColor:"\u2B1B",fullscreen:"\u26F6",headingDropdown:"Normal",link:"\u{1F517}"}[e]||e}function Ne(){return b("div",{style:{width:"1px",height:"24px",background:"#e5e7eb",margin:"0 4px"}})}function Le({item:e,onAction:r}){let[o,t]=L(!1),l=X(null),a=e.colors||Z;return U(()=>{let i=c=>{l.current&&!l.current.contains(c.target)&&t(!1)};if(o)return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[o]),e.color?b("button",{onClick:()=>r(e,e.color),title:`${e.type==="textColor"?"Text":"Background"} Color: ${e.color}`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:e.type==="backgroundColor"?e.color:"white",color:e.type==="textColor"?e.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center"},children:e.icon||z(e.type)}):$("div",{style:{position:"relative"},ref:l,children:[$("button",{onClick:()=>t(!o),title:`${e.type==="textColor"?"Text":"Background"} Color`,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"40px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:[e.icon||b("span",{style:{display:"block",width:"20px",height:"20px",background:e.type==="backgroundColor"?"linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%)":"currentColor",backgroundSize:e.type==="backgroundColor"?"8px 8px":"auto",backgroundPosition:e.type==="backgroundColor"?"0 0, 0 4px, 4px -4px, -4px 0px":"auto"},children:e.type==="textColor"&&b("span",{style:{color:"#000",fontSize:"12px"},children:"A"})}),b("span",{style:{marginLeft:"4px",fontSize:"10px"},children:"\u25BC"})]}),o&&$("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"8px",display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"160px"},children:[a.map(i=>$("button",{onClick:()=>{r(e,i),t(!1)},title:i,style:{width:"24px",height:"24px",borderRadius:"4px",border:e.type==="textColor"?`3px solid ${i}`:"1px solid #e5e7eb",background:e.type==="backgroundColor"?i:"white",color:e.type==="textColor"?"#000":"inherit",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",position:"relative"},children:[e.type==="textColor"&&b("span",{style:{color:i,fontSize:"14px",fontWeight:"bold",lineHeight:"1"},children:"A"}),e.type==="backgroundColor"&&i==="#ffffff"&&b("span",{style:{color:"#000",fontSize:"10px",border:"1px solid #ccc",width:"12px",height:"12px",display:"block"},children:"\u25A1"})]},i)),b("input",{type:"color",onChange:i=>{r(e,i.target.value),t(!1)},style:{gridColumn:"1 / -1",width:"100%",height:"32px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer"}})]})]})}function Ie({item:e,onAction:r,currentBlockType:o="paragraph"}){let[t,l]=L(!1),a=X(null);U(()=>{let d=n=>{a.current&&!a.current.contains(n.target)&&l(!1)};if(t)return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[t]);let i=()=>o==="paragraph"?"Normal":o.startsWith("h")?`Heading ${o.replace("h","")}`:"Normal",c=d=>{r(e,void 0,d),l(!1)},u=[{value:"paragraph",label:"Normal"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}];return $("div",{style:{position:"relative"},ref:a,children:[$("button",{onClick:()=>l(!t),title:"Heading",style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",minWidth:"100px",height:"32px",display:"flex",alignItems:"center",justifyContent:"space-between",position:"relative",fontSize:o==="paragraph"?"14px":o==="h1"?"20px":o==="h2"?"18px":o==="h3"?"16px":"14px",fontWeight:o!=="paragraph"?"bold":"normal"},children:[b("span",{children:e.label||i()}),b("span",{style:{marginLeft:"8px",fontSize:"10px"},children:"\u25BC"})]}),t&&b("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"150px"},children:u.map(d=>b("button",{onClick:()=>c(d.value),style:{width:"100%",padding:"8px 12px",border:"none",background:o===d.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:d.value==="paragraph"?"14px":d.value==="h1"?"20px":d.value==="h2"?"18px":d.value==="h3"?"16px":"14px",fontWeight:d.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:n=>{o!==d.value&&(n.currentTarget.style.background="#f3f4f6")},onMouseLeave:n=>{o!==d.value?n.currentTarget.style.background="transparent":n.currentTarget.style.background="#e5e7eb"},children:d.label},d.value))})]})}function we({item:e,onAction:r,editor:o}){let[t,l]=L(!1),[a,i]=L(""),[c,u]=L(!1),d=X(null),n=X(null);U(()=>{let s=()=>{o.getEditorState().read(()=>{let I=D();if(K(I)){let C=I.getNodes(),E=null;for(let w of C){let g=w.getParent();for(;g!==null;){if(le(g)){E=g;break}g=g.getParent()}if(E)break}E&&le(E)?(u(!0),i(E.getURL())):(u(!1),i(""))}else u(!1),i("")})},m=o.registerUpdateListener(()=>{s()}),h=o.registerCommand(de,()=>(s(),!1),G);return s(),()=>{m(),h()}},[o]),U(()=>{let s=m=>{d.current&&!d.current.contains(m.target)&&l(!1)};if(t)return document.addEventListener("mousedown",s),setTimeout(()=>n.current?.focus(),0),()=>document.removeEventListener("mousedown",s)},[t,c,a]);let f=()=>{if(!a.trim()){o.dispatchCommand(Y,null),l(!1),i("");return}let s=a.trim();!s.startsWith("http://")&&!s.startsWith("https://")&&!s.startsWith("mailto:")&&!s.startsWith("#")&&!s.startsWith("/")&&(s="https://"+s),o.dispatchCommand(Y,s),l(!1),i("")},p=()=>{o.dispatchCommand(Y,null),l(!1),i("")},y=s=>{s.key==="Enter"?(s.preventDefault(),f()):s.key==="Escape"&&(l(!1),i(""))};return $("div",{style:{position:"relative"},ref:d,children:[b("button",{onClick:()=>{l(!t)},title:c?"Edit Link":"Insert Link",style:{padding:"6px 12px",border:"none",background:c?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:s=>{c||(s.currentTarget.style.background="#f3f4f6")},onMouseLeave:s=>{c?s.currentTarget.style.background="#e5e7eb":s.currentTarget.style.background="transparent"},children:e.icon||z(e.type)}),t&&$("div",{style:{position:"absolute",top:"100%",left:0,marginTop:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3,minWidth:"300px"},children:[b("input",{ref:n,type:"text",placeholder:"Enter URL (e.g., https://example.com)",value:a,onChange:s=>i(s.target.value),onKeyDown:y,style:{width:"100%",padding:"8px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",marginBottom:"8px"}}),$("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[c&&b("button",{onClick:p,style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px",color:"#dc2626"},children:"Remove"}),b("button",{onClick:()=>l(!1),style:{padding:"6px 12px",border:"1px solid #e5e7eb",background:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:"Cancel"}),b("button",{onClick:f,style:{padding:"6px 12px",border:"none",background:"#3b82f6",color:"white",cursor:"pointer",borderRadius:"4px",fontSize:"14px"},children:c?"Update":"Insert"})]})]})]})}function Se({item:e,active:r=!1,disabled:o=!1,onAction:t,currentBlockType:l}){let i=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,c=e.label||z(e.type);return e.type==="divider"?b(Ne,{}):e.type==="headingDropdown"?b(Ie,{item:e,onAction:t,currentBlockType:l}):e.type==="textColor"||e.type==="backgroundColor"?b(Le,{item:e,onAction:t}):b("button",{onClick:()=>t(e),disabled:o,title:e.type.charAt(0).toUpperCase()+e.type.slice(1).replace(/([A-Z])/g," $1").trim(),style:{padding:"6px 12px",border:"none",background:r?"#e5e7eb":"transparent",cursor:o?"not-allowed":"pointer",borderRadius:"4px",fontWeight:e.type==="bold"?"bold":"normal",fontStyle:e.type==="italic"?"italic":"normal",textDecoration:e.type==="underline"?"underline":e.type==="strikethrough"?"line-through":"none",fontSize:i?`${18-i*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s",opacity:o?.5:1},onMouseEnter:u=>{!o&&!r&&(u.currentTarget.style.background="#f3f4f6")},onMouseLeave:u=>{r?u.currentTarget.style.background="#e5e7eb":u.currentTarget.style.background="transparent"},children:e.icon||c})}function Q({items:e,onFullscreenToggle:r,isFullscreen:o=!1}){let[t]=xe(),[l,a]=L(!1),[i,c]=L(!1),[u,d]=L(!1),[n,f]=L(!1),[p,y]=L(!1),[s,m]=L(!1),[h,I]=L("paragraph"),C=se(()=>{let g=D();if(K(g)){d(g.hasFormat("bold")),f(g.hasFormat("italic")),y(g.hasFormat("underline")),m(g.hasFormat("strikethrough"));let S=g.anchor.getNode(),R=S.getKey()==="root"?S:S.getTopLevelElementOrThrow(),x=R.getKey();if(t.getElementByKey(x)!==null){let k=q(R)?R.getTag():R.getType();I(k)}}},[t]);U(()=>ye(t.registerUpdateListener(({editorState:g})=>{g.read(()=>{C()})}),t.registerCommand(de,()=>(C(),!1),G),t.registerCommand(Ce,g=>(a(g),!1),G),t.registerCommand(Te,g=>(c(g),!1),G)),[t,C]);let E=se((g,S,R)=>{let{type:x}=g;if(x==="fullscreen"){r?.();return}if(x==="undo"){t.dispatchCommand(Ee,void 0);return}if(x==="redo"){t.dispatchCommand(ke,void 0);return}if(x==="textColor"&&S){t.update(()=>{let v=D();K(v)&&ie(v,{color:S})});return}if(x==="backgroundColor"&&S){t.update(()=>{let v=D();K(v)&&ie(v,{"background-color":S})});return}if(x==="bold"||x==="italic"||x==="underline"||x==="strikethrough"){t.dispatchCommand(ve,x);return}if(x==="alignLeft"){t.dispatchCommand(j,"left");return}if(x==="alignCenter"){t.dispatchCommand(j,"center");return}if(x==="alignRight"){t.dispatchCommand(j,"right");return}if(x==="alignJustify"){t.dispatchCommand(j,"justify");return}if(x==="headingDropdown"&&R){if(R==="paragraph")t.update(()=>{let v=D();if(K(v)){let k=v.anchor.getNode(),T=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),N=T.getKey();if(t.getElementByKey(N)!==null&&q(T)&&J(T)){let M=re(),A=T.getChildren();M.append(...A),T.replace(M),M.selectEnd()}}});else{let v=R;t.update(()=>{let k=D();if(K(k)){let T=k.anchor.getNode(),N=T.getKey()==="root"?T:T.getTopLevelElementOrThrow(),O=N.getKey();if(t.getElementByKey(O)!==null&&J(N)){let A=ae(v),F=N.getChildren();A.append(...F),N.replace(A),A.selectEnd()}}})}return}if(x.startsWith("heading")&&x!=="headingDropdown"){let k=`h${parseInt(x.replace("heading",""))}`;t.update(()=>{let T=D();if(K(T)){let N=T.anchor.getNode(),O=N.getKey()==="root"?N:N.getTopLevelElementOrThrow(),M=O.getKey();if(t.getElementByKey(M)!==null&&J(O)){let F=ae(k),me=O.getChildren();F.append(...me),O.replace(F),F.selectEnd()}}});return}if(x==="paragraph"){t.update(()=>{let v=D();if(K(v)){let k=v.anchor.getNode(),T=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),N=T.getKey();if(t.getElementByKey(N)!==null&&q(T)&&J(T)){let M=re(),A=T.getChildren();M.append(...A),T.replace(M),M.selectEnd()}}});return}},[t,r]),w=g=>{switch(g){case"undo":return{disabled:!l};case"redo":return{disabled:!i};case"bold":return{active:u};case"italic":return{active:n};case"underline":return{active:p};case"strikethrough":return{active:s};case"fullscreen":return{active:o};case"heading1":return{active:h==="h1"};case"heading2":return{active:h==="h2"};case"heading3":return{active:h==="h3"};case"heading4":return{active:h==="h4"};case"heading5":return{active:h==="h5"};case"heading6":return{active:h==="h6"};case"paragraph":return{active:h==="paragraph"};default:return{}}};return b("div",{className:"luxe-toolbar",style:{display:"flex",gap:"4px",alignItems:"center",background:"white",borderBottom:"1px solid #e5e7eb",borderRadius:"8px 8px 0 0",padding:"8px",flexWrap:"wrap"},children:e.map((g,S)=>{let R=w(g.type);return g.type==="link"?b(we,{item:g,onAction:E,editor:t},`${g.type}-${S}`):b(Se,{item:g,active:R.active,disabled:R.disabled,onAction:E,currentBlockType:h},`${g.type}-${S}`)})})}import{jsx as P}from"react/jsx-runtime";var De=[{type:"bold"},{type:"italic"},{type:"underline"}];function Ke(e){let r=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(o=>r.includes(o.type))}function ee({enabled:e=!0,items:r}){let o=r?Ke(r).slice(0,4):De,[t]=Re(),[l,a]=ge(null),[i,c]=ge(null);V(()=>{let n=t.getRootElement();n&&c(n)},[t]);let u=ue(()=>{if(!i)return;let n=window.getSelection();if(!n||n.rangeCount===0||n.isCollapsed){a(null);return}try{let f=n.getRangeAt(0);if(!i.contains(f.commonAncestorContainer)){a(null);return}let p=f.getBoundingClientRect();p&&p.width>0&&p.height>0?t.getEditorState().read(()=>{let y=_();y&&B(y)&&!y.isCollapsed()?a({x:p.left+p.width/2,y:p.top-40}):a(null)}):a(null)}catch{a(null)}},[t,i]);V(()=>{if(!i)return;let n=t.registerUpdateListener(()=>{setTimeout(()=>u(),10)});return()=>{n()}},[t,i,u]),V(()=>{let n=()=>{setTimeout(()=>u(),50)},f=()=>{setTimeout(()=>u(),50)},p=()=>{setTimeout(()=>u(),50)};return document.addEventListener("mouseup",n),document.addEventListener("keyup",f),document.addEventListener("selectionchange",p),()=>{document.removeEventListener("mouseup",n),document.removeEventListener("keyup",f),document.removeEventListener("selectionchange",p)}},[u]);let d=ue((n,f)=>{let{type:p}=n;if(p==="textColor"&&f){t.update(()=>{let y=_();B(y)&&pe(y,{color:f})});return}if(p==="backgroundColor"&&f){t.update(()=>{let y=_();B(y)&&pe(y,{"background-color":f})});return}if(p==="bold"||p==="italic"||p==="underline"||p==="strikethrough"){t.dispatchCommand(Me,p);return}if(p.startsWith("heading")){let s=`h${parseInt(p.replace("heading",""))}`;t.update(()=>{let m=_();if(B(m)){let h=m.anchor.getNode(),I=h.getKey()==="root"?h:h.getTopLevelElementOrThrow(),C=I.getKey();if(t.getElementByKey(C)!==null&&ce(I)){let w=$e(s),g=I.getChildren();w.append(...g),I.replace(w),w.selectEnd()}}});return}if(p==="paragraph"){t.update(()=>{let y=_();if(B(y)){let s=y.anchor.getNode(),m=s.getKey()==="root"?s:s.getTopLevelElementOrThrow(),h=m.getKey();if(t.getElementByKey(h)!==null&&Oe(m)&&ce(m)){let C=He(),E=m.getChildren();C.append(...E),m.replace(C),C.selectEnd()}}});return}},[t]);return!e||!o||o.length===0||!l?null:Ae(P("div",{className:"luxe-floating-toolbar",style:{position:"fixed",top:`${l.y}px`,left:`${l.x}px`,transform:"translateX(-50%)",display:"flex",gap:"4px",background:"white",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"4px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",zIndex:1e3},children:o.map((n,f)=>{let p=n.label||z(n.type),s=n.type.startsWith("heading")?parseInt(n.type.replace("heading","")):null;if(n.type==="textColor"||n.type==="backgroundColor"){let m=n.colors||Z.slice(0,6);return P("div",{style:{display:"flex",gap:"2px"},children:n.color?P("button",{onClick:()=>d(n,n.color),title:`${n.type==="textColor"?"Text":"Background"} Color`,style:{padding:"4px 8px",border:"1px solid #e5e7eb",background:n.type==="backgroundColor"?n.color:"white",color:n.type==="textColor"?n.color:"#000",cursor:"pointer",borderRadius:"4px",minWidth:"28px",height:"28px"},children:n.type==="textColor"?"A":"\u25A0"}):m.map(h=>P("button",{onClick:()=>d(n,h),title:h,style:{width:"24px",height:"24px",border:n.type==="textColor"?`3px solid ${h}`:"1px solid #e5e7eb",background:n.type==="backgroundColor"?h:"white",color:n.type==="textColor"?"#000":"inherit",cursor:"pointer",borderRadius:"3px",fontSize:"10px",display:"flex",alignItems:"center",justifyContent:"center"},children:n.type==="textColor"&&P("span",{style:{color:h,fontSize:"12px",fontWeight:"bold",lineHeight:"1"},children:"A"})},h))},`${n.type}-${f}`)}return P("button",{onClick:()=>d(n),title:n.type.charAt(0).toUpperCase()+n.type.slice(1),style:{padding:"6px 12px",border:"none",background:"transparent",cursor:"pointer",borderRadius:"4px",fontWeight:n.type==="bold"?"bold":"normal",fontStyle:n.type==="italic"?"italic":"normal",textDecoration:n.type==="underline"?"underline":n.type==="strikethrough"?"line-through":"none",fontSize:s?`${18-s*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:m=>{m.currentTarget.style.background="#f3f4f6"},onMouseLeave:m=>{m.currentTarget.style.background="transparent"},children:n.icon||p},`${n.type}-${f}`)})}),document.body)}import{$getRoot as fe,$isElementNode as te,$isTextNode as oe}from"lexical";import{$isHeadingNode as Pe}from"@lexical/rich-text";function We(e){return e.toJSON()}function Fe(e){let r="";return e.read(()=>{r=fe().getTextContent()}),r}function ne(e,r){let o=(r&1)!==0,t=(r&2)!==0,l=(r&4)!==0,a=(r&8)!==0;return o&&t?e=`***${e}***`:o?e=`**${e}**`:t&&(e=`*${e}*`),l&&(e=`__${e}__`),a&&(e=`~~${e}~~`),e}function Ue(e){let r="";return e.read(()=>{let t=fe().getChildren(),l=a=>{let i="";if(Pe(a)){let c=a.getTag(),u=parseInt(c.replace("h","")),d="#".repeat(u),n=a.getChildren(),f="";for(let p of n)oe(p)?f+=ne(p.getTextContent(),p.getFormat()):te(p)&&(f+=l(p));i+=`${d} ${f}
|
|
3
|
+
|
|
4
|
+
`}else if(te(a)){let c=a.getChildren(),u="";for(let n of c)oe(n)?u+=ne(n.getTextContent(),n.getFormat()):te(n)&&(u+=l(n));let d=a.getType();d==="paragraph"?i+=u+`
|
|
5
|
+
|
|
6
|
+
`:i+=u}else oe(a)&&(i+=ne(a.getTextContent(),a.getFormat()));return i};for(let a of t)r+=l(a)}),r.trim()}function ze(e){if(!e)return"";try{let r=e.getRootElement();if(!r)return"";let o=r.querySelector('[contenteditable="true"]');if(o)return(o.innerHTML||"").trim()||"";if(r.hasAttribute("contenteditable")&&r.getAttribute("contenteditable")==="true")return r.innerHTML||"";let t=Array.from(r.children).filter(l=>{let a=l.id||"",i=l.className||"";return!a.includes("toolbar")&&!i.includes("toolbar")});if(t.length>0){for(let l of t)if(l.hasAttribute("contenteditable"))return l.innerHTML||"";return t[0].innerHTML||""}return r.innerHTML||""}catch(r){return console.error("Error getting editor DOM:",r),""}}function _e(e){if(!e||!e.root)return null;let r=(o,t=0)=>{if(!o)return null;let l=o.type||"unknown",a=o.key||"",i=o.children||[],c={type:l,key:a,depth:t,children:[]};return o.tag&&(c.tag=o.tag),o.format!==void 0&&(c.format=o.format),o.text&&(c.text=o.text.substring(0,50)+(o.text.length>50?"...":"")),o.style&&(c.style=o.style),o.indent&&(c.indent=o.indent),o.direction&&(c.direction=o.direction),Array.isArray(i)&&(c.children=i.map(u=>r(u,t+1)).filter(Boolean)),c};return r(e.root)}import{jsx as H,jsxs as nt}from"react/jsx-runtime";var he={paragraph:"luxe-paragraph",heading:{h1:"luxe-heading-h1",h2:"luxe-heading-h2",h3:"luxe-heading-h3",h4:"luxe-heading-h4",h5:"luxe-heading-h5",h6:"luxe-heading-h6"},text:{bold:"luxe-bold",italic:"luxe-italic",underline:"luxe-underline",strikethrough:"luxe-strikethrough"}};function tt({onChange:e,ignoreInitialChange:r}){let[o]=be(),t=W.useRef(!0);return W.useEffect(()=>o.registerUpdateListener(({editorState:l,prevEditorState:a})=>{if(r&&t.current&&a.isEmpty()){t.current=!1;return}t.current=!1,e(l,o)}),[o,e,r]),null}function ot({initialJSON:e}){let[r]=be(),o=W.useRef(!1);return W.useEffect(()=>{if(!(!e||o.current))try{let t=r.parseEditorState(e);r.setEditorState(t),o.current=!0}catch(t){console.error("LuxeEditor: Failed to parse initialJSON",t)}},[r,e]),null}function _t({initialConfig:e,initialJSON:r,showFloatingToolbar:o=!0,showToolbar:t=!0,toolbarItems:l,floatingToolbarItems:a,onChange:i,ignoreInitialChange:c=!0,children:u}){let[d,n]=W.useState(!1),f=[Ye,Ve,et,Ze,Qe],p=e.theme?{...he,...e.theme}:he,{theme:y,...s}=e,m=s.onUpdate,h={namespace:"LuxeEditor",theme:p,nodes:f,onError:w=>console.error(w),onUpdate:m,...s},C=l||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],E=W.useCallback(()=>{n(w=>!w)},[]);return H(Be,{initialConfig:h,children:nt("div",{className:`luxe-editor-container ${d?"luxe-editor-fullscreen":""}`,children:[t&&C&&C.length>0&&H(Q,{items:C,onFullscreenToggle:E,isFullscreen:d}),H(Je,{contentEditable:H(je,{className:"luxe-input"}),placeholder:H("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:Xe}),H(Ge,{}),H(qe,{}),i&&H(tt,{onChange:i,ignoreInitialChange:c}),r&&H(ot,{initialJSON:r}),o&&H(ee,{enabled:!0,items:a||C}),u]})})}export{ee as FloatingToolbarPlugin,_t as LuxeEditor,Q as Toolbar,ze as getEditorDOM,Ue as getEditorFormattedText,We as getEditorJSON,Fe as getEditorText,_e as getEditorTree};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "luxe-edit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A beautiful, customizable rich text editor for React built on Lexical with customizable toolbars and floating toolbar support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
|
-
"url": "git+https://github.com/
|
|
41
|
+
"url": "git+https://github.com/luxe-tools/luxe-edit.git"
|
|
42
42
|
},
|
|
43
|
-
"homepage": "https://github.com/
|
|
43
|
+
"homepage": "https://github.com/luxe-tools/luxe-edit#readme",
|
|
44
44
|
"bugs": {
|
|
45
|
-
"url": "https://github.com/
|
|
45
|
+
"url": "https://github.com/luxe-tools/luxe-edit/issues"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "^18.0.0 || ^19.0.0",
|