luxe-edit 0.1.2 → 0.1.4
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 +26 -2
- package/dist/index.d.ts +26 -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,37 @@ 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>;
|
|
30
52
|
showFloatingToolbar?: boolean;
|
|
31
53
|
showToolbar?: boolean;
|
|
32
54
|
toolbarItems?: ToolbarItem[];
|
|
33
55
|
floatingToolbarItems?: ToolbarItem[];
|
|
56
|
+
onChange?: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
57
|
+
ignoreInitialChange?: boolean;
|
|
34
58
|
children?: React__default.ReactNode;
|
|
35
59
|
}
|
|
36
|
-
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
60
|
+
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, onChange, ignoreInitialChange, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
37
61
|
|
|
38
|
-
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType };
|
|
62
|
+
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,37 @@ 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>;
|
|
30
52
|
showFloatingToolbar?: boolean;
|
|
31
53
|
showToolbar?: boolean;
|
|
32
54
|
toolbarItems?: ToolbarItem[];
|
|
33
55
|
floatingToolbarItems?: ToolbarItem[];
|
|
56
|
+
onChange?: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
57
|
+
ignoreInitialChange?: boolean;
|
|
34
58
|
children?: React__default.ReactNode;
|
|
35
59
|
}
|
|
36
|
-
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
60
|
+
declare function LuxeEditor({ initialConfig, showFloatingToolbar, showToolbar, toolbarItems, floatingToolbarItems, onChange, ignoreInitialChange, children }: LuxeEditorProps): react_jsx_runtime.JSX.Element;
|
|
37
61
|
|
|
38
|
-
export { FloatingToolbarPlugin, LuxeEditor, type LuxeEditorProps, Toolbar, type ToolbarItem, type ToolbarItemType };
|
|
62
|
+
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 fe=Object.getOwnPropertyDescriptor;var he=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 he(s))!xe.call(e,d)&&d!==r&&_(e,d,{get:()=>s[d],enumerable:!(t=fe(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"),f=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,f.useState)(!1),d=(0,f.useRef)(null),h=e.colors||Z;return(0,f.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:[h.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,f.useState)(!1),h=(0,f.useRef)(null);(0,f.useEffect)(()=>{let c=o=>{h.current&&!h.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:h,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,f.useState)(!1),[h,l]=(0,f.useState)(""),[x,m]=(0,f.useState)(!1),c=(0,f.useRef)(null),o=(0,f.useRef)(null);(0,f.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,f.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,h]);let y=()=>{if(!h.trim()){r.dispatchCommand(W.TOGGLE_LINK_COMMAND,null),d(!1),l("");return}let a=h.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:h,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,h]=(0,f.useState)(!1),[l,x]=(0,f.useState)(!1),[m,c]=(0,f.useState)(!1),[o,y]=(0,f.useState)(!1),[u,T]=(0,f.useState)(!1),[a,b]=(0,f.useState)(!1),[g,H]=(0,f.useState)("paragraph"),L=(0,f.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,f.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=>(h(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,f.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,h]=(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){h(null);return}try{let y=o.getRangeAt(0);if(!l.contains(y.commonAncestorContainer)){h(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()?h({x:u.left+u.width/2,y:u.top-40}):h(null)}):h(null)}catch{h(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=!1,toolbarItems:t,floatingToolbarItems:d,children:h}){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:"bold"},{type:"italic"}],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}),h]})})}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})},te=(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)):{},te(r||!e||!e.__esModule?j(o,"default",{value:e,enumerable:!0}):o,e)),Re=e=>te(j({},"__esModule",{value:!0}),e);var Pe={};Ie(Pe,{FloatingToolbarPlugin:()=>X,LuxeEditor:()=>Ke,Toolbar:()=>J,getEditorDOM:()=>ce,getEditorFormattedText:()=>de,getEditorJSON:()=>le,getEditorText:()=>se,getEditorTree:()=>pe});module.exports=Re(Pe);var _=we(require("react")),ge=require("@lexical/react/LexicalComposer"),fe=require("@lexical/react/LexicalRichTextPlugin"),he=require("@lexical/react/LexicalContentEditable"),be=require("@lexical/react/LexicalHistoryPlugin"),me=require("@lexical/react/LexicalErrorBoundary"),xe=require("@lexical/react/LexicalLinkPlugin"),ye=require("@lexical/rich-text"),q=require("@lexical/link"),Y=require("lexical"),Te=require("@lexical/react/LexicalComposerContext");var re=require("@lexical/react/LexicalComposerContext"),v=require("lexical"),V=require("@lexical/selection"),G=require("@lexical/rich-text"),D=require("react"),ie=require("react-dom");var oe=require("@lexical/react/LexicalComposerContext"),ne=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 Se(){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 $e({item:e,onAction:r,currentBlockType:o="paragraph"}){let[t,l]=(0,b.useState)(!1),s=(0,b.useRef)(null);(0,b.useEffect)(()=>{let g=n=>{s.current&&!s.current.contains(n.target)&&l(!1)};if(t)return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[t]);let i=()=>o==="paragraph"?"Normal":o.startsWith("h")?`Heading ${o.replace("h","")}`:"Normal",u=g=>{r(e,void 0,g),l(!1)},h=[{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:h.map(g=>(0,p.jsx)("button",{onClick:()=>u(g.value),style:{width:"100%",padding:"8px 12px",border:"none",background:o===g.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:g.value==="paragraph"?"14px":g.value==="h1"?"20px":g.value==="h2"?"18px":g.value==="h3"?"16px":"14px",fontWeight:g.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:n=>{o!==g.value&&(n.currentTarget.style.background="#f3f4f6")},onMouseLeave:n=>{o!==g.value?n.currentTarget.style.background="transparent":n.currentTarget.style.background="#e5e7eb"},children:g.label},g.value))})]})}function He({item:e,onAction:r,editor:o}){let[t,l]=(0,b.useState)(!1),[s,i]=(0,b.useState)(""),[u,h]=(0,b.useState)(!1),g=(0,b.useRef)(null),n=(0,b.useRef)(null);(0,b.useEffect)(()=>{let d=()=>{o.getEditorState().read(()=>{let H=(0,a.$getSelection)();if((0,a.$isRangeSelection)(H)){let E=H.getNodes(),w=null;for(let N of E){let c=N.getParent();for(;c!==null;){if((0,F.$isLinkNode)(c)){w=c;break}c=c.getParent()}if(w)break}w&&(0,F.$isLinkNode)(w)?(h(!0),i(w.getURL())):(h(!1),i(""))}else h(!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=>{g.current&&!g.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("")},f=()=>{o.dispatchCommand(F.TOGGLE_LINK_COMMAND,null),l(!1),i("")},T=d=>{d.key==="Enter"?(d.preventDefault(),m()):d.key==="Escape"&&(l(!1),i(""))};return(0,p.jsxs)("div",{style:{position:"relative"},ref:g,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:T,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:f,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)(Se,{}):e.type==="headingDropdown"?(0,p.jsx)($e,{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:h=>{!o&&!r&&(h.currentTarget.style.background="#f3f4f6")},onMouseLeave:h=>{r?h.currentTarget.style.background="#e5e7eb":h.currentTarget.style.background="transparent"},children:e.icon||u})}function J({items:e,onFullscreenToggle:r,isFullscreen:o=!1}){let[t]=(0,oe.useLexicalComposerContext)(),[l,s]=(0,b.useState)(!1),[i,u]=(0,b.useState)(!1),[h,g]=(0,b.useState)(!1),[n,m]=(0,b.useState)(!1),[f,T]=(0,b.useState)(!1),[d,y]=(0,b.useState)(!1),[x,H]=(0,b.useState)("paragraph"),E=(0,b.useCallback)(()=>{let c=(0,a.$getSelection)();if((0,a.$isRangeSelection)(c)){g(c.hasFormat("bold")),m(c.hasFormat("italic")),T(c.hasFormat("underline")),y(c.hasFormat("strikethrough"));let R=c.anchor.getNode(),S=R.getKey()==="root"?R:R.getTopLevelElementOrThrow(),C=S.getKey();if(t.getElementByKey(C)!==null){let I=(0,W.$isHeadingNode)(S)?S.getTag():S.getType();H(I)}}},[t]);(0,b.useEffect)(()=>(0,ne.mergeRegister)(t.registerUpdateListener(({editorState:c})=>{c.read(()=>{E()})}),t.registerCommand(a.SELECTION_CHANGE_COMMAND,()=>(E(),!1),a.COMMAND_PRIORITY_LOW),t.registerCommand(a.CAN_UNDO_COMMAND,c=>(s(c),!1),a.COMMAND_PRIORITY_LOW),t.registerCommand(a.CAN_REDO_COMMAND,c=>(u(c),!1),a.COMMAND_PRIORITY_LOW)),[t,E]);let w=(0,b.useCallback)((c,R,S)=>{let{type:C}=c;if(C==="fullscreen"){r?.();return}if(C==="undo"){t.dispatchCommand(a.UNDO_COMMAND,void 0);return}if(C==="redo"){t.dispatchCommand(a.REDO_COMMAND,void 0);return}if(C==="textColor"&&R){t.update(()=>{let L=(0,a.$getSelection)();(0,a.$isRangeSelection)(L)&&(0,Z.$patchStyleText)(L,{color:R})});return}if(C==="backgroundColor"&&R){t.update(()=>{let L=(0,a.$getSelection)();(0,a.$isRangeSelection)(L)&&(0,Z.$patchStyleText)(L,{"background-color":R})});return}if(C==="bold"||C==="italic"||C==="underline"||C==="strikethrough"){t.dispatchCommand(a.FORMAT_TEXT_COMMAND,C);return}if(C==="alignLeft"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"left");return}if(C==="alignCenter"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"center");return}if(C==="alignRight"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"right");return}if(C==="alignJustify"){t.dispatchCommand(a.FORMAT_ELEMENT_COMMAND,"justify");return}if(C==="headingDropdown"&&S){if(S==="paragraph")t.update(()=>{let L=(0,a.$getSelection)();if((0,a.$isRangeSelection)(L)){let I=L.anchor.getNode(),k=I.getKey()==="root"?I:I.getTopLevelElementOrThrow(),M=k.getKey();if(t.getElementByKey(M)!==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 L=S;t.update(()=>{let I=(0,a.$getSelection)();if((0,a.$isRangeSelection)(I)){let k=I.anchor.getNode(),M=k.getKey()==="root"?k:k.getTopLevelElementOrThrow(),K=M.getKey();if(t.getElementByKey(K)!==null&&(0,a.$isElementNode)(M)){let P=(0,W.$createHeadingNode)(L),z=M.getChildren();P.append(...z),M.replace(P),P.selectEnd()}}})}return}if(C.startsWith("heading")&&C!=="headingDropdown"){let I=`h${parseInt(C.replace("heading",""))}`;t.update(()=>{let k=(0,a.$getSelection)();if((0,a.$isRangeSelection)(k)){let M=k.anchor.getNode(),K=M.getKey()==="root"?M:M.getTopLevelElementOrThrow(),A=K.getKey();if(t.getElementByKey(A)!==null&&(0,a.$isElementNode)(K)){let z=(0,W.$createHeadingNode)(I),Ce=K.getChildren();z.append(...Ce),K.replace(z),z.selectEnd()}}});return}if(C==="paragraph"){t.update(()=>{let L=(0,a.$getSelection)();if((0,a.$isRangeSelection)(L)){let I=L.anchor.getNode(),k=I.getKey()==="root"?I:I.getTopLevelElementOrThrow(),M=k.getKey();if(t.getElementByKey(M)!==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]),N=c=>{switch(c){case"undo":return{disabled:!l};case"redo":return{disabled:!i};case"bold":return{active:h};case"italic":return{active:n};case"underline":return{active:f};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((c,R)=>{let S=N(c.type);return c.type==="link"?(0,p.jsx)(He,{item:c,onAction:w,editor:t},`${c.type}-${R}`):(0,p.jsx)(Oe,{item:c,active:S.active,disabled:S.disabled,onAction:w,currentBlockType:x},`${c.type}-${R}`)})})}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,re.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 h=(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 f=m.getBoundingClientRect();f&&f.width>0&&f.height>0?t.getEditorState().read(()=>{let T=(0,v.$getSelection)();T&&(0,v.$isRangeSelection)(T)&&!T.isCollapsed()?s({x:f.left+f.width/2,y:f.top-40}):s(null)}):s(null)}catch{s(null)}},[t,i]);(0,D.useEffect)(()=>{if(!i)return;let n=t.registerUpdateListener(()=>{setTimeout(()=>h(),10)});return()=>{n()}},[t,i,h]),(0,D.useEffect)(()=>{let n=()=>{setTimeout(()=>h(),50)},m=()=>{setTimeout(()=>h(),50)},f=()=>{setTimeout(()=>h(),50)};return document.addEventListener("mouseup",n),document.addEventListener("keyup",m),document.addEventListener("selectionchange",f),()=>{document.removeEventListener("mouseup",n),document.removeEventListener("keyup",m),document.removeEventListener("selectionchange",f)}},[h]);let g=(0,D.useCallback)((n,m)=>{let{type:f}=n;if(f==="textColor"&&m){t.update(()=>{let T=(0,v.$getSelection)();(0,v.$isRangeSelection)(T)&&(0,V.$patchStyleText)(T,{color:m})});return}if(f==="backgroundColor"&&m){t.update(()=>{let T=(0,v.$getSelection)();(0,v.$isRangeSelection)(T)&&(0,V.$patchStyleText)(T,{"background-color":m})});return}if(f==="bold"||f==="italic"||f==="underline"||f==="strikethrough"){t.dispatchCommand(v.FORMAT_TEXT_COMMAND,f);return}if(f.startsWith("heading")){let d=`h${parseInt(f.replace("heading",""))}`;t.update(()=>{let y=(0,v.$getSelection)();if((0,v.$isRangeSelection)(y)){let x=y.anchor.getNode(),H=x.getKey()==="root"?x:x.getTopLevelElementOrThrow(),E=H.getKey();if(t.getElementByKey(E)!==null&&(0,v.$isElementNode)(H)){let N=(0,G.$createHeadingNode)(d),c=H.getChildren();N.append(...c),H.replace(N),N.selectEnd()}}});return}if(f==="paragraph"){t.update(()=>{let T=(0,v.$getSelection)();if((0,v.$isRangeSelection)(T)){let d=T.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)(),w=y.getChildren();E.append(...w),y.replace(E),E.selectEnd()}}});return}},[t]);return!e||!o||o.length===0||!l?null:(0,ie.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 f=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:()=>g(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:()=>g(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:()=>g(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||f},`${n.type}-${m}`)})}),document.body)}var O=require("lexical"),ae=require("@lexical/rich-text");function le(e){return e.toJSON()}function se(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 de(e){let r="";return e.read(()=>{let t=(0,O.$getRoot)().getChildren(),l=s=>{let i="";if((0,ae.$isHeadingNode)(s)){let u=s.getTag(),h=parseInt(u.replace("h","")),g="#".repeat(h),n=s.getChildren(),m="";for(let f of n)(0,O.$isTextNode)(f)?m+=ee(f.getTextContent(),f.getFormat()):(0,O.$isElementNode)(f)&&(m+=l(f));i+=`${g} ${m}
|
|
3
|
+
|
|
4
|
+
`}else if((0,O.$isElementNode)(s)){let u=s.getChildren(),h="";for(let n of u)(0,O.$isTextNode)(n)?h+=ee(n.getTextContent(),n.getFormat()):(0,O.$isElementNode)(n)&&(h+=l(n));let g=s.getType();g==="paragraph"?i+=h+`
|
|
5
|
+
|
|
6
|
+
`:i+=h}else(0,O.$isTextNode)(s)&&(i+=ee(s.getTextContent(),s.getFormat()));return i};for(let s of t)r+=l(s)}),r.trim()}function ce(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 pe(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(h=>r(h,t+1)).filter(Boolean)),u};return r(e.root)}var $=require("react/jsx-runtime"),ue={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({initialConfig:e,showFloatingToolbar:r=!0,showToolbar:o=!0,toolbarItems:t,floatingToolbarItems:l,onChange:s,ignoreInitialChange:i=!0,children:u}){let[h,g]=_.default.useState(!1),n=[ye.HeadingNode,Y.ParagraphNode,Y.TextNode,q.LinkNode,q.AutoLinkNode],m=e.theme?{...ue,...e.theme}:ue,{theme:f,...T}=e,d=T.onUpdate,y=_.default.memo(()=>{let[N]=(0,Te.useLexicalComposerContext)(),c=_.default.useRef(!0);return _.default.useEffect(()=>{if(s)return N.registerUpdateListener(({editorState:R,prevEditorState:S})=>{if(i&&c.current&&S.isEmpty()){c.current=!1;return}c.current=!1,s(R,N)})},[N,s,i]),null}),x={namespace:"LuxeEditor",theme:m,nodes:n,onError:N=>console.error(N),onUpdate:d,...T},E=t||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],w=_.default.useCallback(()=>{g(N=>!N)},[]);return(0,$.jsx)(ge.LexicalComposer,{initialConfig:x,children:(0,$.jsxs)("div",{className:`luxe-editor-container ${h?"luxe-editor-fullscreen":""}`,children:[o&&E&&E.length>0&&(0,$.jsx)(J,{items:E,onFullscreenToggle:w,isFullscreen:h}),(0,$.jsx)(fe.RichTextPlugin,{contentEditable:(0,$.jsx)(he.ContentEditable,{className:"luxe-input"}),placeholder:(0,$.jsx)("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:me.LexicalErrorBoundary}),(0,$.jsx)(be.HistoryPlugin,{}),(0,$.jsx)(xe.LinkPlugin,{}),s&&(0,$.jsx)(y,{}),r&&(0,$.jsx)(X,{enabled:!0,items:l||E}),u]})})}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 fe}from"@lexical/utils";import{$getSelection as D,$isRangeSelection as A,$createParagraphNode as ee,$isElementNode as B,CAN_REDO_COMMAND as he,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:f}){let[r,t]=N(!1),p=X(null),u=e.colors||Z;return z(()=>{let a=h=>{p.current&&!p.current.contains(h.target)&&t(!1)};if(r)return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[r]),e.color?c("button",{onClick:()=>f(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:()=>{f(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=>{f(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:f,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",h=i=>{f(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:()=>h(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:f,editor:r}){let[t,p]=N(!1),[u,a]=N(""),[h,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,h,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:h?"Edit Link":"Insert Link",style:{padding:"6px 12px",border:"none",background:h?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s"},onMouseEnter:n=>{h||(n.currentTarget.style.background="#f3f4f6")},onMouseLeave:n=>{h?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:[h&&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:h?"Update":"Insert"})]})]})]})}function Ne({item:e,active:f=!1,disabled:r=!1,onAction:t,currentBlockType:p}){let a=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,h=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:f?"#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&&!f&&(b.currentTarget.style.background="#f3f4f6")},onMouseLeave:b=>{f?b.currentTarget.style.background="#e5e7eb":b.currentTarget.style.background="transparent"},children:e.icon||h})}function q({items:e,onFullscreenToggle:f,isFullscreen:r=!1}){let[t]=ge(),[p,u]=N(!1),[a,h]=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(()=>fe(t.registerUpdateListener(({editorState:l})=>{l.read(()=>{E()})}),t.registerCommand(ae,()=>(E(),!1),G),t.registerCommand(be,l=>(u(l),!1),G),t.registerCommand(he,l=>(h(l),!1),G)),[t,E]);let I=re((l,L,w)=>{let{type:m}=l;if(m==="fullscreen"){f?.();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,f]),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 f=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(r=>f.includes(r.type))}function V({enabled:e=!0,items:f}){let r=f?He(f).slice(0,4):Me,[t]=Ee(),[p,u]=de(null),[a,h]=de(null);Q(()=>{let o=t.getRootElement();o&&h(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:f=!0,showToolbar:r=!1,toolbarItems:t,floatingToolbarItems:p,children:u}){let[a,h]=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:"bold"},{type:"italic"}],g=pe.useCallback(()=>{h(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,{}),f&&O(V,{enabled:!0,items:p||n}),u]})})}export{V as FloatingToolbarPlugin,Nt as LuxeEditor,q as Toolbar};
|
|
2
|
+
import B from"react";import{LexicalComposer as ze}from"@lexical/react/LexicalComposer";import{RichTextPlugin as Be}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as je}from"@lexical/react/LexicalContentEditable";import{HistoryPlugin as Je}from"@lexical/react/LexicalHistoryPlugin";import{LexicalErrorBoundary as Ge}from"@lexical/react/LexicalErrorBoundary";import{LinkPlugin as Xe}from"@lexical/react/LexicalLinkPlugin";import{HeadingNode as qe}from"@lexical/rich-text";import{LinkNode as Ye,AutoLinkNode as Ze}from"@lexical/link";import{ParagraphNode as Qe,TextNode as Ve}from"lexical";import{useLexicalComposerContext as et}from"@lexical/react/LexicalComposerContext";import{useLexicalComposerContext as Re}from"@lexical/react/LexicalComposerContext";import{$getSelection as _,$isRangeSelection as z,FORMAT_TEXT_COMMAND as Se,$createParagraphNode as Me,$isElementNode as ce}from"lexical";import{$patchStyleText as pe}from"@lexical/selection";import{$createHeadingNode as $e,$isHeadingNode as He}from"@lexical/rich-text";import{useCallback as ue,useEffect as V,useState as ge}from"react";import{createPortal as Oe}from"react-dom";import{useLexicalComposerContext as me}from"@lexical/react/LexicalComposerContext";import{mergeRegister as xe}from"@lexical/utils";import{$getSelection as D,$isRangeSelection as K,$createParagraphNode as re,$isElementNode as j,CAN_REDO_COMMAND as ye,CAN_UNDO_COMMAND as Te,COMMAND_PRIORITY_LOW as G,FORMAT_ELEMENT_COMMAND as J,FORMAT_TEXT_COMMAND as Ce,REDO_COMMAND as ve,SELECTION_CHANGE_COMMAND as de,UNDO_COMMAND as ke}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 F,useState as R,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 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 Ee(){return b("div",{style:{width:"1px",height:"24px",background:"#e5e7eb",margin:"0 4px"}})}function Ne({item:e,onAction:i}){let[n,t]=R(!1),l=X(null),a=e.colors||Z;return F(()=>{let r=c=>{l.current&&!l.current.contains(c.target)&&t(!1)};if(n)return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[n]),e.color?b("button",{onClick:()=>i(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)}):$("div",{style:{position:"relative"},ref:l,children:[$("button",{onClick:()=>t(!n),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"})]}),n&&$("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(r=>$("button",{onClick:()=>{i(e,r),t(!1)},title:r,style:{width:"24px",height:"24px",borderRadius:"4px",border:e.type==="textColor"?`3px solid ${r}`:"1px solid #e5e7eb",background:e.type==="backgroundColor"?r:"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:r,fontSize:"14px",fontWeight:"bold",lineHeight:"1"},children:"A"}),e.type==="backgroundColor"&&r==="#ffffff"&&b("span",{style:{color:"#000",fontSize:"10px",border:"1px solid #ccc",width:"12px",height:"12px",display:"block"},children:"\u25A1"})]},r)),b("input",{type:"color",onChange:r=>{i(e,r.target.value),t(!1)},style:{gridColumn:"1 / -1",width:"100%",height:"32px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer"}})]})]})}function Le({item:e,onAction:i,currentBlockType:n="paragraph"}){let[t,l]=R(!1),a=X(null);F(()=>{let p=o=>{a.current&&!a.current.contains(o.target)&&l(!1)};if(t)return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[t]);let r=()=>n==="paragraph"?"Normal":n.startsWith("h")?`Heading ${n.replace("h","")}`:"Normal",c=p=>{i(e,void 0,p),l(!1)},g=[{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:n==="paragraph"?"14px":n==="h1"?"20px":n==="h2"?"18px":n==="h3"?"16px":"14px",fontWeight:n!=="paragraph"?"bold":"normal"},children:[b("span",{children:e.label||r()}),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:g.map(p=>b("button",{onClick:()=>c(p.value),style:{width:"100%",padding:"8px 12px",border:"none",background:n===p.value?"#e5e7eb":"transparent",cursor:"pointer",borderRadius:"4px",textAlign:"left",fontSize:p.value==="paragraph"?"14px":p.value==="h1"?"20px":p.value==="h2"?"18px":p.value==="h3"?"16px":"14px",fontWeight:p.value!=="paragraph"?"bold":"normal",display:"flex",alignItems:"center"},onMouseEnter:o=>{n!==p.value&&(o.currentTarget.style.background="#f3f4f6")},onMouseLeave:o=>{n!==p.value?o.currentTarget.style.background="transparent":o.currentTarget.style.background="#e5e7eb"},children:p.label},p.value))})]})}function Ie({item:e,onAction:i,editor:n}){let[t,l]=R(!1),[a,r]=R(""),[c,g]=R(!1),p=X(null),o=X(null);F(()=>{let s=()=>{n.getEditorState().read(()=>{let S=D();if(K(S)){let C=S.getNodes(),N=null;for(let v of C){let d=v.getParent();for(;d!==null;){if(le(d)){N=d;break}d=d.getParent()}if(N)break}N&&le(N)?(g(!0),r(N.getURL())):(g(!1),r(""))}else g(!1),r("")})},m=n.registerUpdateListener(()=>{s()}),h=n.registerCommand(de,()=>(s(),!1),G);return s(),()=>{m(),h()}},[n]),F(()=>{let s=m=>{p.current&&!p.current.contains(m.target)&&l(!1)};if(t)return document.addEventListener("mousedown",s),setTimeout(()=>o.current?.focus(),0),()=>document.removeEventListener("mousedown",s)},[t,c,a]);let f=()=>{if(!a.trim()){n.dispatchCommand(Y,null),l(!1),r("");return}let s=a.trim();!s.startsWith("http://")&&!s.startsWith("https://")&&!s.startsWith("mailto:")&&!s.startsWith("#")&&!s.startsWith("/")&&(s="https://"+s),n.dispatchCommand(Y,s),l(!1),r("")},u=()=>{n.dispatchCommand(Y,null),l(!1),r("")},x=s=>{s.key==="Enter"?(s.preventDefault(),f()):s.key==="Escape"&&(l(!1),r(""))};return $("div",{style:{position:"relative"},ref:p,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||U(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:o,type:"text",placeholder:"Enter URL (e.g., https://example.com)",value:a,onChange:s=>r(s.target.value),onKeyDown:x,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:u,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 we({item:e,active:i=!1,disabled:n=!1,onAction:t,currentBlockType:l}){let r=e.type.startsWith("heading")&&e.type!=="headingDropdown"?parseInt(e.type.replace("heading","")):null,c=e.label||U(e.type);return e.type==="divider"?b(Ee,{}):e.type==="headingDropdown"?b(Le,{item:e,onAction:t,currentBlockType:l}):e.type==="textColor"||e.type==="backgroundColor"?b(Ne,{item:e,onAction:t}):b("button",{onClick:()=>t(e),disabled:n,title:e.type.charAt(0).toUpperCase()+e.type.slice(1).replace(/([A-Z])/g," $1").trim(),style:{padding:"6px 12px",border:"none",background:i?"#e5e7eb":"transparent",cursor:n?"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:r?`${18-r*2}px`:"14px",minWidth:"32px",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.2s",opacity:n?.5:1},onMouseEnter:g=>{!n&&!i&&(g.currentTarget.style.background="#f3f4f6")},onMouseLeave:g=>{i?g.currentTarget.style.background="#e5e7eb":g.currentTarget.style.background="transparent"},children:e.icon||c})}function Q({items:e,onFullscreenToggle:i,isFullscreen:n=!1}){let[t]=me(),[l,a]=R(!1),[r,c]=R(!1),[g,p]=R(!1),[o,f]=R(!1),[u,x]=R(!1),[s,m]=R(!1),[h,S]=R("paragraph"),C=se(()=>{let d=D();if(K(d)){p(d.hasFormat("bold")),f(d.hasFormat("italic")),x(d.hasFormat("underline")),m(d.hasFormat("strikethrough"));let L=d.anchor.getNode(),I=L.getKey()==="root"?L:L.getTopLevelElementOrThrow(),y=I.getKey();if(t.getElementByKey(y)!==null){let E=q(I)?I.getTag():I.getType();S(E)}}},[t]);F(()=>xe(t.registerUpdateListener(({editorState:d})=>{d.read(()=>{C()})}),t.registerCommand(de,()=>(C(),!1),G),t.registerCommand(Te,d=>(a(d),!1),G),t.registerCommand(ye,d=>(c(d),!1),G)),[t,C]);let N=se((d,L,I)=>{let{type:y}=d;if(y==="fullscreen"){i?.();return}if(y==="undo"){t.dispatchCommand(ke,void 0);return}if(y==="redo"){t.dispatchCommand(ve,void 0);return}if(y==="textColor"&&L){t.update(()=>{let k=D();K(k)&&ie(k,{color:L})});return}if(y==="backgroundColor"&&L){t.update(()=>{let k=D();K(k)&&ie(k,{"background-color":L})});return}if(y==="bold"||y==="italic"||y==="underline"||y==="strikethrough"){t.dispatchCommand(Ce,y);return}if(y==="alignLeft"){t.dispatchCommand(J,"left");return}if(y==="alignCenter"){t.dispatchCommand(J,"center");return}if(y==="alignRight"){t.dispatchCommand(J,"right");return}if(y==="alignJustify"){t.dispatchCommand(J,"justify");return}if(y==="headingDropdown"&&I){if(I==="paragraph")t.update(()=>{let k=D();if(K(k)){let E=k.anchor.getNode(),T=E.getKey()==="root"?E:E.getTopLevelElementOrThrow(),w=T.getKey();if(t.getElementByKey(w)!==null&&q(T)&&j(T)){let M=re(),A=T.getChildren();M.append(...A),T.replace(M),M.selectEnd()}}});else{let k=I;t.update(()=>{let E=D();if(K(E)){let T=E.anchor.getNode(),w=T.getKey()==="root"?T:T.getTopLevelElementOrThrow(),O=w.getKey();if(t.getElementByKey(O)!==null&&j(w)){let A=ae(k),W=w.getChildren();A.append(...W),w.replace(A),A.selectEnd()}}})}return}if(y.startsWith("heading")&&y!=="headingDropdown"){let E=`h${parseInt(y.replace("heading",""))}`;t.update(()=>{let T=D();if(K(T)){let w=T.anchor.getNode(),O=w.getKey()==="root"?w:w.getTopLevelElementOrThrow(),M=O.getKey();if(t.getElementByKey(M)!==null&&j(O)){let W=ae(E),be=O.getChildren();W.append(...be),O.replace(W),W.selectEnd()}}});return}if(y==="paragraph"){t.update(()=>{let k=D();if(K(k)){let E=k.anchor.getNode(),T=E.getKey()==="root"?E:E.getTopLevelElementOrThrow(),w=T.getKey();if(t.getElementByKey(w)!==null&&q(T)&&j(T)){let M=re(),A=T.getChildren();M.append(...A),T.replace(M),M.selectEnd()}}});return}},[t,i]),v=d=>{switch(d){case"undo":return{disabled:!l};case"redo":return{disabled:!r};case"bold":return{active:g};case"italic":return{active:o};case"underline":return{active:u};case"strikethrough":return{active:s};case"fullscreen":return{active:n};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((d,L)=>{let I=v(d.type);return d.type==="link"?b(Ie,{item:d,onAction:N,editor:t},`${d.type}-${L}`):b(we,{item:d,active:I.active,disabled:I.disabled,onAction:N,currentBlockType:h},`${d.type}-${L}`)})})}import{jsx as P}from"react/jsx-runtime";var Ae=[{type:"bold"},{type:"italic"},{type:"underline"}];function De(e){let i=["bold","italic","underline","strikethrough","textColor","backgroundColor"];return e.filter(n=>i.includes(n.type))}function ee({enabled:e=!0,items:i}){let n=i?De(i).slice(0,4):Ae,[t]=Re(),[l,a]=ge(null),[r,c]=ge(null);V(()=>{let o=t.getRootElement();o&&c(o)},[t]);let g=ue(()=>{if(!r)return;let o=window.getSelection();if(!o||o.rangeCount===0||o.isCollapsed){a(null);return}try{let f=o.getRangeAt(0);if(!r.contains(f.commonAncestorContainer)){a(null);return}let u=f.getBoundingClientRect();u&&u.width>0&&u.height>0?t.getEditorState().read(()=>{let x=_();x&&z(x)&&!x.isCollapsed()?a({x:u.left+u.width/2,y:u.top-40}):a(null)}):a(null)}catch{a(null)}},[t,r]);V(()=>{if(!r)return;let o=t.registerUpdateListener(()=>{setTimeout(()=>g(),10)});return()=>{o()}},[t,r,g]),V(()=>{let o=()=>{setTimeout(()=>g(),50)},f=()=>{setTimeout(()=>g(),50)},u=()=>{setTimeout(()=>g(),50)};return document.addEventListener("mouseup",o),document.addEventListener("keyup",f),document.addEventListener("selectionchange",u),()=>{document.removeEventListener("mouseup",o),document.removeEventListener("keyup",f),document.removeEventListener("selectionchange",u)}},[g]);let p=ue((o,f)=>{let{type:u}=o;if(u==="textColor"&&f){t.update(()=>{let x=_();z(x)&&pe(x,{color:f})});return}if(u==="backgroundColor"&&f){t.update(()=>{let x=_();z(x)&&pe(x,{"background-color":f})});return}if(u==="bold"||u==="italic"||u==="underline"||u==="strikethrough"){t.dispatchCommand(Se,u);return}if(u.startsWith("heading")){let s=`h${parseInt(u.replace("heading",""))}`;t.update(()=>{let m=_();if(z(m)){let h=m.anchor.getNode(),S=h.getKey()==="root"?h:h.getTopLevelElementOrThrow(),C=S.getKey();if(t.getElementByKey(C)!==null&&ce(S)){let v=$e(s),d=S.getChildren();v.append(...d),S.replace(v),v.selectEnd()}}});return}if(u==="paragraph"){t.update(()=>{let x=_();if(z(x)){let s=x.anchor.getNode(),m=s.getKey()==="root"?s:s.getTopLevelElementOrThrow(),h=m.getKey();if(t.getElementByKey(h)!==null&&He(m)&&ce(m)){let C=Me(),N=m.getChildren();C.append(...N),m.replace(C),C.selectEnd()}}});return}},[t]);return!e||!n||n.length===0||!l?null:Oe(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:n.map((o,f)=>{let u=o.label||U(o.type),s=o.type.startsWith("heading")?parseInt(o.type.replace("heading","")):null;if(o.type==="textColor"||o.type==="backgroundColor"){let m=o.colors||Z.slice(0,6);return P("div",{style:{display:"flex",gap:"2px"},children:o.color?P("button",{onClick:()=>p(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"}):m.map(h=>P("button",{onClick:()=>p(o,h),title:h,style:{width:"24px",height:"24px",border:o.type==="textColor"?`3px solid ${h}`:"1px solid #e5e7eb",background:o.type==="backgroundColor"?h:"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:h,fontSize:"12px",fontWeight:"bold",lineHeight:"1"},children:"A"})},h))},`${o.type}-${f}`)}return P("button",{onClick:()=>p(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: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:o.icon||u},`${o.type}-${f}`)})}),document.body)}import{$getRoot as fe,$isElementNode as te,$isTextNode as oe}from"lexical";import{$isHeadingNode as Ke}from"@lexical/rich-text";function Pe(e){return e.toJSON()}function We(e){let i="";return e.read(()=>{i=fe().getTextContent()}),i}function ne(e,i){let n=(i&1)!==0,t=(i&2)!==0,l=(i&4)!==0,a=(i&8)!==0;return n&&t?e=`***${e}***`:n?e=`**${e}**`:t&&(e=`*${e}*`),l&&(e=`__${e}__`),a&&(e=`~~${e}~~`),e}function Fe(e){let i="";return e.read(()=>{let t=fe().getChildren(),l=a=>{let r="";if(Ke(a)){let c=a.getTag(),g=parseInt(c.replace("h","")),p="#".repeat(g),o=a.getChildren(),f="";for(let u of o)oe(u)?f+=ne(u.getTextContent(),u.getFormat()):te(u)&&(f+=l(u));r+=`${p} ${f}
|
|
3
|
+
|
|
4
|
+
`}else if(te(a)){let c=a.getChildren(),g="";for(let o of c)oe(o)?g+=ne(o.getTextContent(),o.getFormat()):te(o)&&(g+=l(o));let p=a.getType();p==="paragraph"?r+=g+`
|
|
5
|
+
|
|
6
|
+
`:r+=g}else oe(a)&&(r+=ne(a.getTextContent(),a.getFormat()));return r};for(let a of t)i+=l(a)}),i.trim()}function Ue(e){if(!e)return"";try{let i=e.getRootElement();if(!i)return"";let n=i.querySelector('[contenteditable="true"]');if(n)return(n.innerHTML||"").trim()||"";if(i.hasAttribute("contenteditable")&&i.getAttribute("contenteditable")==="true")return i.innerHTML||"";let t=Array.from(i.children).filter(l=>{let a=l.id||"",r=l.className||"";return!a.includes("toolbar")&&!r.includes("toolbar")});if(t.length>0){for(let l of t)if(l.hasAttribute("contenteditable"))return l.innerHTML||"";return t[0].innerHTML||""}return i.innerHTML||""}catch(i){return console.error("Error getting editor DOM:",i),""}}function _e(e){if(!e||!e.root)return null;let i=(n,t=0)=>{if(!n)return null;let l=n.type||"unknown",a=n.key||"",r=n.children||[],c={type:l,key:a,depth:t,children:[]};return n.tag&&(c.tag=n.tag),n.format!==void 0&&(c.format=n.format),n.text&&(c.text=n.text.substring(0,50)+(n.text.length>50?"...":"")),n.style&&(c.style=n.style),n.indent&&(c.indent=n.indent),n.direction&&(c.direction=n.direction),Array.isArray(r)&&(c.children=r.map(g=>i(g,t+1)).filter(Boolean)),c};return i(e.root)}import{jsx as H,jsxs as tt}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 Ut({initialConfig:e,showFloatingToolbar:i=!0,showToolbar:n=!0,toolbarItems:t,floatingToolbarItems:l,onChange:a,ignoreInitialChange:r=!0,children:c}){let[g,p]=B.useState(!1),o=[qe,Qe,Ve,Ye,Ze],f=e.theme?{...he,...e.theme}:he,{theme:u,...x}=e,s=x.onUpdate,m=B.memo(()=>{let[v]=et(),d=B.useRef(!0);return B.useEffect(()=>{if(a)return v.registerUpdateListener(({editorState:L,prevEditorState:I})=>{if(r&&d.current&&I.isEmpty()){d.current=!1;return}d.current=!1,a(L,v)})},[v,a,r]),null}),h={namespace:"LuxeEditor",theme:f,nodes:o,onError:v=>console.error(v),onUpdate:s,...x},C=t||[{type:"undo"},{type:"redo"},{type:"divider"},{type:"bold"},{type:"italic"},{type:"underline"},{type:"strikethrough"},{type:"divider"},{type:"headingDropdown"},{type:"divider"},{type:"link"}],N=B.useCallback(()=>{p(v=>!v)},[]);return H(ze,{initialConfig:h,children:tt("div",{className:`luxe-editor-container ${g?"luxe-editor-fullscreen":""}`,children:[n&&C&&C.length>0&&H(Q,{items:C,onFullscreenToggle:N,isFullscreen:g}),H(Be,{contentEditable:H(je,{className:"luxe-input"}),placeholder:H("div",{className:"luxe-placeholder",children:"Start writing..."}),ErrorBoundary:Ge}),H(Je,{}),H(Xe,{}),a&&H(m,{}),i&&H(ee,{enabled:!0,items:l||C}),c]})})}export{ee as FloatingToolbarPlugin,Ut as LuxeEditor,Q as Toolbar,Ue as getEditorDOM,Fe as getEditorFormattedText,Pe as getEditorJSON,We 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.4",
|
|
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",
|