@lyfie/luthor 2.3.1 → 2.3.2

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.
@@ -1,3 +1 @@
1
- import {ImageExtension,TableExtension,IframeEmbedExtension,YouTubeEmbedExtension,ContextMenuExtension,CommandPaletteExtension,SlashCommandExtension,EmojiExtension,DraggableBlockExtension,LinkExtension,textColorExtension,textHighlightExtension,createCustomNodeExtension,createEditorSystem,mergeThemes,defaultLuthorTheme,createEditorThemeStyleVars,FloatingToolbarExtension,FontFamilyExtension,FontSizeExtension,LineHeightExtension,codeExtension,codeIntelligenceExtension,boldExtension,italicExtension,underlineExtension,strikethroughExtension,subscriptExtension,superscriptExtension,horizontalRuleExtension,listExtension,historyExtension,blockFormatExtension,codeFormatExtension,tabIndentExtension,enterKeyBehaviorExtension,RichText,clearLexicalSelection,resolveLinkNodeKeyFromAnchor}from'@lyfie/luthor-headless';import ni,{forwardRef,useState,useMemo,useEffect,useRef,useImperativeHandle,createElement,useLayoutEffect,useCallback}from'react';import {AlignLeft,AlignCenter,AlignRight,Bold,Italic,Underline,Strikethrough,Code,Quote,Unlink,Link,List,ListOrdered,ListChecks,Search,Command,Sun,Moon,Redo2,Undo2,Image,FileCode,Smile,Upload,Type,Table,Minus,IndentDecrease,IndentIncrease,Code2,AlignJustify,Superscript,Subscript,X,ChevronDown,Highlighter,Palette}from'lucide-react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';var Te=["h1","h2","h3","h4","h5","h6"];var It={sections:[{items:["fontFamily","fontSize","lineHeight"]},{items:["bold","italic","underline","strikethrough","textColor","textHighlight"]},{items:["subscript","superscript","code","link"]},{items:["blockFormat","quote","alignLeft","alignCenter","alignRight","alignJustify"]},{items:["unorderedList","orderedList","checkList","indentList","outdentList"]},{items:["table","image","emoji","embed","horizontalRule"]},{items:["codeBlock"]},{items:["undo","redo"]},{items:["commandPalette","themeToggle"]}]};function Dn(e){if(!(e instanceof Element))return false;if(e.closest('[contenteditable="true"]'))return true;let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function Kn(e,t){return Dn(e.target)?vo(t):false}function vo(e){let t=e.key.toLowerCase();return !(!!e.ctrlKey||!!e.metaKey)||e.altKey?false:t==="b"||t==="i"||t==="u"||t==="k"||(t==="z"||t==="y")}function yo(e){return typeof e.setCodeLanguage=="function"&&typeof e.autoDetectCodeLanguage=="function"}function Un(e){return typeof e.toggleSubscript=="function"}function jn(e){return typeof e.toggleSuperscript=="function"}function _n(e){return typeof e.insertIframeEmbed=="function"}function Vn(e){return typeof e.insertYouTubeEmbed=="function"}function $n(e){return typeof e.insertEmoji=="function"}function Jn(e){return e.slice(1)}function qn(e){switch(e){case "h1":return "Convert to large heading";case "h2":return "Convert to medium heading";case "h3":return "Convert to small heading";case "h4":return "Convert to heading level 4";case "h5":return "Convert to heading level 5";case "h6":return "Convert to heading level 6"}}function Yn(e){if(!e||e.length===0)return [...Te];let t=new Set,n=[];for(let o of e)!Te.includes(o)||t.has(o)||(t.add(o),n.push(o));return n.length>0?n:[...Te]}function Jt(e,t){return Xn(qt(t),t?.shortcutConfig).filter(o=>!o.condition||o.condition(e))}function K(e,t){return typeof e[t]=="function"}function Ft(e){if(!e||e.length===0)return new Set;let t=e.map(n=>n.trim()).filter(n=>n.length>0);return new Set(t)}function Gn(e){if(!e)return {allowlist:new Set,denylist:new Set};if(Array.isArray(e)){let n=[];for(let o of e)for(let[l,r]of Object.entries(o))r&&n.push(l);return {allowlist:Ft(n),denylist:new Set}}let t=e;return {allowlist:Ft(t.allowlist),denylist:Ft(t.denylist)}}function Co(e){let t=e.key.trim();return t?{key:t,ctrlKey:!!e.ctrlKey,metaKey:!!e.metaKey,shiftKey:!!e.shiftKey,altKey:!!e.altKey,preventDefault:e.preventDefault}:null}function Qn(e){if(e===false||e===null)return [];let t=Array.isArray(e)?e:[e],n=[];for(let o of t){let l=Co(o);l&&n.push(l);}return n}function Wn(e){return [e.key.toLowerCase(),e.ctrlKey?"ctrl":"",e.metaKey?"meta":"",e.shiftKey?"shift":"",e.altKey?"alt":""].join(":")}function Xn(e,t){if(!t)return [...e];let n=Ft(t.disabledCommandIds),o=t.bindings,l=t.preventNativeConflicts!==false,r=t.preventCollisions!==false,i=new Set;return e.filter(c=>!n.has(c.id)).map(c=>{let u=c.shortcuts?[...c.shortcuts]:void 0;if(!!o&&Object.prototype.hasOwnProperty.call(o,c.id)&&o){let d=o[c.id],p=d===void 0?[]:Qn(d);u=p.length>0?p:void 0;}if(u&&u.length>0){let d=[];for(let p of u){let m=Co(p);if(!m||l&&vo(m))continue;let h=Wn(m);r&&i.has(h)||(i.add(h),d.push(m));}u=d.length>0?d:void 0;}return {...c,shortcuts:u}})}function qt(e){let t=e?.isFeatureEnabled??(()=>true),n=Yn(e?.headingOptions),o=e?.paragraphLabel?.trim()||"Paragraph",l=n.map(r=>{let i=Jn(r);return {id:`block.heading${i}`,label:`Heading ${i}`,description:qn(r),category:"Block",action:a=>a.toggleHeading?.(r),shortcuts:[{key:i,ctrlKey:true,altKey:true}],keywords:["heading",r],condition:a=>t("blockFormat")&&K(a,"toggleHeading")}});return [{id:"format.bold",label:"Toggle Bold",description:"Make text bold or remove bold formatting",category:"Format",action:r=>r.toggleBold?.(),shortcuts:[{key:"b",ctrlKey:true}],keywords:["bold","strong","format"],condition:r=>t("bold")&&K(r,"toggleBold")},{id:"format.italic",label:"Toggle Italic",description:"Make text italic or remove italic formatting",category:"Format",action:r=>r.toggleItalic?.(),shortcuts:[{key:"i",ctrlKey:true}],keywords:["italic","emphasis","format"],condition:r=>t("italic")&&K(r,"toggleItalic")},{id:"format.underline",label:"Toggle Underline",description:"Add or remove underline formatting",category:"Format",action:r=>r.toggleUnderline?.(),shortcuts:[{key:"u",ctrlKey:true}],keywords:["underline","format"],condition:r=>t("underline")&&K(r,"toggleUnderline")},{id:"format.strikethrough",label:"Toggle Strikethrough",description:"Add or remove strikethrough formatting",category:"Format",action:r=>r.toggleStrikethrough?.(),keywords:["strikethrough","format"],condition:r=>t("strikethrough")&&K(r,"toggleStrikethrough")},{id:"format.subscript",label:"Toggle Subscript",description:"Format text as subscript",category:"Format",action:r=>r.toggleSubscript?.(),keywords:["subscript","format"],condition:r=>t("subscript")&&Un(r)},{id:"format.superscript",label:"Toggle Superscript",description:"Format text as superscript",category:"Format",action:r=>r.toggleSuperscript?.(),keywords:["superscript","format"],condition:r=>t("superscript")&&jn(r)},{id:"format.code",label:"Toggle Inline Code",description:"Format text as inline code",category:"Format",action:r=>r.formatText?.("code"),shortcuts:[{key:"`",ctrlKey:true}],keywords:["code","inline","format"],condition:r=>t("codeFormat")&&K(r,"formatText")},{id:"block.paragraph",label:o,description:"Convert to paragraph",category:"Block",action:r=>r.toggleParagraph?.(),shortcuts:[{key:"0",ctrlKey:true,altKey:true}],keywords:["paragraph","text"],condition:r=>t("blockFormat")&&K(r,"toggleParagraph")},...l,{id:"block.quote",label:"Quote",description:"Convert to blockquote",category:"Block",action:r=>r.toggleQuote?.(),keywords:["quote","blockquote"],condition:r=>t("blockFormat")&&K(r,"toggleQuote")},{id:"block.align-left",label:"Align Left",description:"Align selected blocks to the left",category:"Block",action:r=>r.setTextAlignment?.("left"),keywords:["align","left","text"],condition:r=>t("blockFormat")&&K(r,"setTextAlignment")},{id:"block.align-center",label:"Align Center",description:"Center-align selected blocks",category:"Block",action:r=>r.setTextAlignment?.("center"),keywords:["align","center","text"],condition:r=>t("blockFormat")&&K(r,"setTextAlignment")},{id:"block.align-right",label:"Align Right",description:"Align selected blocks to the right",category:"Block",action:r=>r.setTextAlignment?.("right"),keywords:["align","right","text"],condition:r=>t("blockFormat")&&K(r,"setTextAlignment")},{id:"block.align-justify",label:"Justify",description:"Justify selected blocks",category:"Block",action:r=>r.setTextAlignment?.("justify"),keywords:["align","justify","text"],condition:r=>t("blockFormat")&&K(r,"setTextAlignment")},{id:"block.codeblock",label:"Code Block",description:"Convert to code block",category:"Block",action:r=>r.toggleCodeBlock?.(),shortcuts:[{key:"`",ctrlKey:true,shiftKey:true}],keywords:["code","block"],condition:r=>t("code")&&K(r,"toggleCodeBlock")},{id:"block.code-language",label:"Set Code Language",description:"Set language for selected code block",category:"Block",action:r=>{if(!r.setCodeLanguage)return;let i=prompt("Code language (e.g. ts, css, python):")?.trim();i&&r.setCodeLanguage(i);},keywords:["code","language","syntax"],condition:r=>t("codeIntelligence")&&yo(r)},{id:"block.code-language.auto",label:"Auto-Detect Code Language",description:"Detect language from selected code block",category:"Block",action:r=>{r.autoDetectCodeLanguage?.();},keywords:["code","language","auto","detect"],condition:r=>t("codeIntelligence")&&yo(r)},{id:"list.bullet",label:"Bullet List",description:"Create or toggle bullet list",category:"List",action:r=>r.toggleUnorderedList?.(),shortcuts:[{key:"l",ctrlKey:true,shiftKey:true}],keywords:["list","bullet"],condition:r=>t("list")&&K(r,"toggleUnorderedList")},{id:"list.numbered",label:"Numbered List",description:"Create or toggle numbered list",category:"List",action:r=>r.toggleOrderedList?.(),shortcuts:[{key:"l",ctrlKey:true,altKey:true}],keywords:["list","numbered"],condition:r=>t("list")&&K(r,"toggleOrderedList")},{id:"list.check",label:"Checklist",description:"Create or toggle checklist",category:"List",action:r=>r.toggleCheckList?.(),shortcuts:[{key:"x",ctrlKey:true,shiftKey:true}],keywords:["list","check","todo","task"],condition:r=>t("list")&&K(r,"toggleCheckList")},{id:"link.insert",label:"Insert Link",description:"Insert or edit a link",category:"Insert",action:r=>r.insertLink?.(),shortcuts:[{key:"k",ctrlKey:true}],keywords:["link","url"],condition:r=>t("link")&&K(r,"insertLink")},{id:"link.remove",label:"Remove Link",description:"Remove link formatting",category:"Format",action:r=>r.removeLink?.(),shortcuts:[{key:"k",ctrlKey:true,shiftKey:true}],keywords:["unlink","remove","link"],condition:r=>t("link")&&K(r,"removeLink")},{id:"insert.horizontal-rule",label:"Insert Horizontal Rule",description:"Insert a horizontal line separator",category:"Insert",action:r=>r.insertHorizontalRule?.(),keywords:["horizontal","rule","hr","divider","separator"],condition:r=>t("horizontalRule")&&K(r,"insertHorizontalRule")},{id:"insert.image",label:"Insert Image",description:"Insert an image from URL",category:"Insert",action:r=>{let i=prompt("Enter image URL:");if(i){let a=prompt("Enter alt text:")||"";r.insertImage?.({src:i,alt:a});}},keywords:["image","photo"],condition:r=>t("image")&&K(r,"insertImage")},{id:"insert.gif",label:"Insert GIF",description:"Insert an animated GIF from URL",category:"Insert",action:r=>{let i=prompt("Enter GIF URL:");i&&r.insertImage?.({src:i,alt:"GIF"});},keywords:["gif","animated","image"],condition:r=>t("image")&&K(r,"insertImage")},{id:"insert.emoji",label:"Insert Emoji",description:"Insert an emoji character",category:"Insert",action:r=>{let i=prompt("Enter emoji or shortcode (example :sparkles:):")?.trim();if(!i||typeof r.insertEmoji!="function")return;let a=i.match(/^:([a-z0-9_+-]+):$/i);if(a){let c=a[1];if(!c)return;if(typeof r.resolveEmojiShortcode=="function"){let u=r.resolveEmojiShortcode(c);if(u?.emoji){r.insertEmoji(u.emoji);return}}else if(typeof r.getEmojiSuggestions=="function"){let[u]=r.getEmojiSuggestions(c);if(u?.emoji){r.insertEmoji(u.emoji);return}}}r.insertEmoji(i);},keywords:["emoji","reaction","symbol","smile"],condition:r=>t("emoji")&&$n(r)},{id:"insert.table",label:"Insert Table",description:"Insert a 3x3 table",category:"Insert",action:r=>r.insertTable?.({rows:3,columns:3,includeHeaders:true}),keywords:["table","grid"],condition:r=>t("table")&&K(r,"insertTable")},{id:"insert.iframe",label:"Insert iframe",description:"Insert an iframe embed from URL",category:"Insert",action:r=>{if(typeof r.insertIframeEmbed!="function")return;let i=prompt("Enter iframe URL:");i&&r.insertIframeEmbed(i);},keywords:["iframe","embed","url"],condition:r=>t("iframeEmbed")&&_n(r)},{id:"insert.youtube",label:"Insert YouTube Video",description:"Insert an embedded YouTube video",category:"Insert",action:r=>{if(typeof r.insertYouTubeEmbed!="function")return;let i=prompt("Enter YouTube URL:");i&&r.insertYouTubeEmbed(i);},keywords:["youtube","video","embed"],condition:r=>t("youTubeEmbed")&&Vn(r)},{id:"edit.undo",label:"Undo",description:"Undo the last action",category:"Edit",action:r=>r.undo?.(),shortcuts:[{key:"z",ctrlKey:true}],keywords:["undo","revert"],condition:r=>t("history")&&K(r,"undo")},{id:"edit.redo",label:"Redo",description:"Redo the last undone action",category:"Edit",action:r=>r.redo?.(),shortcuts:[{key:"y",ctrlKey:true},{key:"z",ctrlKey:true,shiftKey:true}],keywords:["redo","repeat"],condition:r=>t("history")&&K(r,"redo")},{id:"palette.show",label:"Show Command Palette",description:"Open the command palette",category:"View",action:r=>r.showCommandPalette?.(),shortcuts:[{key:"p",ctrlKey:true,shiftKey:true}],keywords:["command","palette"],condition:r=>t("commandPalette")&&K(r,"showCommandPalette")}]}function ko(e,t){let n=t?.commandPaletteShortcutOnly===true;return Jt(e,t).filter(o=>!n||!!o.shortcuts&&o.shortcuts.length>0).map(o=>({id:o.id,label:o.label,description:o.description,category:o.category,action:()=>o.action(e),keywords:o.keywords,shortcut:o.shortcuts?.[0]?To(o.shortcuts[0]):void 0}))}function Eo(e,t){let n=new Set(["block.paragraph","block.quote","block.codeblock"]),o=a=>a.category==="Insert"||a.category==="List"?true:a.category==="Block"?a.id.startsWith("block.heading")?true:n.has(a.id):false,{allowlist:l,denylist:r}=Gn(t?.slashCommandVisibility),i=l.size>0;return Jt(e,t).filter(o).filter(a=>r.has(a.id)?false:i?l.has(a.id):true).map(a=>({id:a.id,label:a.label,description:a.description,category:a.category,action:()=>a.action(e),keywords:a.keywords,shortcut:a.shortcuts?.[0]?To(a.shortcuts[0]):void 0}))}function To(e){let t=[];return e.ctrlKey&&t.push("Ctrl"),e.metaKey&&t.push("Cmd"),e.altKey&&t.push("Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")}function xo(e,t=document.body,n){let o=Jt(e,n),l=r=>{let i=typeof n?.scope=="function"?n.scope():n?.scope;if(!(i&&r.target instanceof Node&&!i.contains(r.target))){for(let a of o)if(a.shortcuts){for(let c of a.shortcuts)if(!(n?.shortcutConfig?.preventNativeConflicts!==false&&Kn(r,c))&&r.key.toLowerCase()===c.key.toLowerCase()&&!!r.ctrlKey==!!c.ctrlKey&&!!r.metaKey==!!c.metaKey&&!!r.shiftKey==!!c.shiftKey&&!!r.altKey==!!c.altKey){c.preventDefault!==false&&r.preventDefault(),(!a.condition||a.condition(e))&&a.action(e);return}}}};return t.addEventListener("keydown",l),()=>t.removeEventListener("keydown",l)}var wt=Bold,Nt=Italic,Ot=Underline,Ht=Strikethrough,Pt=Code,So=Code2,it=Link,Ze=Unlink,zt=List,At=ListChecks,Rt=ListOrdered,Lo=Undo2,Io=Redo2,Yt=Image,lt=AlignLeft,et=AlignCenter,Fo=AlignJustify,at=AlignRight,Gt=Upload,wo=Minus,No=Table,Oo=FileCode;var Ho=Highlighter;var Bt=Command,Po=Palette,zo=Type,Mt=Quote,Ao=IndentIncrease,Ro=IndentDecrease,Bo=Sun,Mo=Moon,Do=Search,Qt=Smile,Ko=Subscript,Uo=Superscript,jo=ChevronDown,_o=X;function Jo({isOpen:e,onClose:t,commands:n}){let[o,l]=useState(""),[r,i]=useState(0),a=useRef(null),c=useRef(null),u=n.filter(p=>`${p.label} ${p.description||""} ${p.keywords?.join(" ")||""}`.toLowerCase().includes(o.toLowerCase())),C=u.reduce((p,m)=>{let h=m.category||"Other";return p[h]||(p[h]=[]),p[h].push(m),p},{}),d=u;return useEffect(()=>{i(0);},[o]),useEffect(()=>{e&&a.current&&(a.current.focus({preventScroll:true}),l(""),i(0));},[e]),useEffect(()=>{if(!e)return;let p=c.current;if(!p)return;p.querySelector(".luthor-command-palette-item.selected")?.scrollIntoView({block:"nearest"});},[e,r,o]),useEffect(()=>{let p=m=>{if(e)switch(m.key){case "Escape":m.preventDefault(),m.stopPropagation(),t();break;case "ArrowDown":m.preventDefault(),m.stopPropagation(),i(h=>Math.min(h+1,d.length-1));break;case "ArrowUp":m.preventDefault(),m.stopPropagation(),i(h=>Math.max(h-1,0));break;case "Enter":m.preventDefault(),m.stopPropagation(),d[r]&&(d[r].action(),t());break}};return document.addEventListener("keydown",p,true),()=>document.removeEventListener("keydown",p,true)},[e,r,d,t]),e?jsx("div",{className:"luthor-command-palette-overlay",onClick:t,children:jsxs("div",{className:"luthor-command-palette",role:"dialog","aria-modal":"true","aria-label":"Command Palette",onClick:p=>p.stopPropagation(),children:[jsxs("div",{className:"luthor-command-palette-header",children:[jsx(Do,{size:16,className:"luthor-command-palette-icon"}),jsx("input",{ref:a,type:"text",placeholder:"Type a command or search...",value:o,onChange:p=>l(p.target.value),className:"luthor-command-palette-input"}),jsx("kbd",{className:"luthor-command-palette-kbd",children:"ESC"})]}),jsx("div",{ref:c,className:"luthor-command-palette-list",children:Object.keys(C).length===0?jsx("div",{className:"luthor-command-palette-empty",children:"No commands found"}):Object.entries(C).map(([p,m])=>jsxs("div",{className:"luthor-command-palette-group",children:[jsx("div",{className:"luthor-command-palette-group-title",children:p}),m.map(h=>{let U=d.indexOf(h);return jsxs("div",{className:`luthor-command-palette-item ${U===r?"selected":""}`,onClick:()=>{h.action(),t();},onMouseEnter:()=>i(U),children:[jsxs("div",{className:"luthor-command-palette-item-content",children:[jsx("div",{className:"luthor-command-palette-item-title",children:h.label}),h.description&&jsx("div",{className:"luthor-command-palette-item-description",children:h.description})]}),h.shortcut&&jsx("kbd",{className:"luthor-command-palette-item-shortcut",children:h.shortcut})]},h.id)})]},p))}),jsx("div",{className:"luthor-command-palette-footer",children:jsxs("span",{className:"luthor-command-palette-hint",children:[jsx(Bt,{size:14}),jsx("span",{children:"Use arrow keys, Enter, ESC"})]})})]})}):null}var Rr={"--luthor-bg":"#ffffff","--luthor-fg":"#0f172a","--luthor-border":"#e2e8f0","--luthor-border-hover":"#cbd5e1","--luthor-border-active":"#94a3b8","--luthor-accent":"#0f172a","--luthor-accent-hover":"#1e293b","--luthor-shadow":"rgba(0, 0, 0, 0.08)","--luthor-muted":"#f8fafc","--luthor-muted-fg":"#64748b","--luthor-theme-transition":"0.2s ease","--luthor-drag-gutter-width":"56px","--luthor-line-height-ratio":"1","--luthor-toolbar-bg":"#f8fafc","--luthor-toolbar-section-border":"#e2e8f0","--luthor-toolbar-button-fg":"#0f172a","--luthor-toolbar-button-hover-bg":"#f8fafc","--luthor-toolbar-button-hover-border":"#cbd5e1","--luthor-toolbar-button-hover-shadow":"0 4px 12px rgba(0, 0, 0, 0.15)","--luthor-toolbar-button-press-shadow":"0 2px 8px rgba(0, 0, 0, 0.1)","--luthor-toolbar-button-active-bg":"#0f172a","--luthor-toolbar-button-active-border":"#0f172a","--luthor-toolbar-button-active-fg":"#ffffff","--luthor-toolbar-button-active-shadow":"0 2px 8px rgba(0, 0, 0, 0.2)","--luthor-toolbar-button-overlay":"linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%)","--luthor-toolbar-button-active-overlay":"linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%)","--luthor-toolbar-color-indicator-border":"#e2e8f0","--luthor-toolbar-highlight-bg":"#f8fafc","--luthor-quote-bg":"#f8fafc","--luthor-quote-fg":"#0f172a","--luthor-quote-border":"#0f172a","--luthor-syntax-comment":"#64748b","--luthor-syntax-keyword":"#64748b","--luthor-syntax-string":"#64748b","--luthor-syntax-number":"#64748b","--luthor-syntax-function":"#64748b","--luthor-syntax-variable":"#64748b","--luthor-floating-bg":"#ffffff","--luthor-floating-fg":"#0f172a","--luthor-floating-border":"#e2e8f0","--luthor-floating-shadow":"rgba(0, 0, 0, 0.08)","--luthor-floating-muted":"#f8fafc","--luthor-floating-border-hover":"#cbd5e1","--luthor-floating-border-active":"#94a3b8","--luthor-floating-accent":"#0f172a","--luthor-floating-accent-fg":"#ffffff","--luthor-z-dropdown":"20","--luthor-z-popover":"24","--luthor-z-menu":"28","--luthor-z-overlay":"32","--luthor-z-modal":"36","--luthor-preset-bg":"#ffffff","--luthor-preset-fg":"#0f172a","--luthor-preset-border":"#dbe2ea","--luthor-preset-muted":"#f8fafc","--luthor-preset-muted-fg":"#64748b","--luthor-preset-accent":"#2563eb","--luthor-preset-radius":"10px","--luthor-preset-shadow":"0 1px 3px rgba(15, 23, 42, 0.08)","--luthor-preset-content-padding":"16px","--luthor-preset-content-min-height":"180px"};function Br(e){return e?e.closest(".luthor-editor-wrapper"):null}function Mr(e){return e?Br(e)??e:null}function Dr(e){if(typeof window>"u"||!e)return {};let t=window.getComputedStyle(e),n={};for(let[o,l]of Object.entries(Rr)){let r=t.getPropertyValue(o).trim()||l;n[o]=r;}return n}function qe(e){return Dr(Mr(e))}function ut(){if(typeof window>"u")return {};let t=window.getSelection()?.anchorNode;if(!t)return {};let n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;return qe(n)}function Yo({isOpen:e,query:t,position:n,suggestions:o,onClose:l,onExecute:r}){let[i,a]=useState(0);if(useEffect(()=>{a(0);},[t,e]),useEffect(()=>{if(!e)return;let u=C=>{let d=o.length>0;switch(C.key){case "Escape":C.preventDefault(),C.stopPropagation(),l();break;case "ArrowDown":if(!d)return;C.preventDefault(),C.stopPropagation(),a(p=>Math.min(p+1,Math.max(o.length-1,0)));break;case "ArrowUp":if(!d)return;C.preventDefault(),C.stopPropagation(),a(p=>Math.max(p-1,0));break;case "Enter":case "Tab":if(!d||!o[i])return;C.preventDefault(),C.stopPropagation(),r(o[i].emoji);break}};return document.addEventListener("keydown",u,true),()=>document.removeEventListener("keydown",u,true)},[e,l,r,i,o]),!e||!n)return null;let c=jsxs("div",{className:"luthor-emoji-menu",style:{left:n.x,top:n.y,...ut()},onPointerDown:u=>{u.stopPropagation();},onMouseDown:u=>{u.stopPropagation();},children:[jsxs("div",{className:"luthor-emoji-menu-header",children:[jsx("span",{className:"luthor-emoji-menu-title",children:"Emoji"}),jsxs("span",{className:"luthor-emoji-menu-query",children:[":",t]})]}),jsx("div",{className:"luthor-emoji-menu-list",children:o.length===0?jsx("div",{className:"luthor-emoji-menu-empty",children:"No matching emoji"}):o.map((u,C)=>{let d=C===i,p=u.shortcodes[0]?`:${u.shortcodes[0]}:`:"";return jsxs("button",{type:"button",className:`luthor-emoji-menu-item ${d?"selected":""}`,onMouseEnter:()=>a(C),onMouseDown:m=>{m.preventDefault(),m.stopPropagation();},onClick:m=>{m.preventDefault(),m.stopPropagation(),r(u.emoji);},children:[jsx("span",{className:"luthor-emoji-menu-item-symbol","aria-hidden":"true",children:u.emoji}),jsxs("span",{className:"luthor-emoji-menu-item-content",children:[jsx("span",{className:"luthor-emoji-menu-item-title",children:u.label}),p&&jsx("span",{className:"luthor-emoji-menu-item-shortcode",children:p})]})]},`${u.emoji}-${u.label}`)})})]});return typeof document>"u"?c:createPortal(c,document.body)}function Wo({isOpen:e,query:t,position:n,commands:o,onClose:l,onExecute:r}){let[i,a]=useState(0),c=useMemo(()=>{let d=t.trim().toLowerCase();return d?o.filter(p=>`${p.label} ${p.description||""} ${p.keywords?.join(" ")||""}`.toLowerCase().includes(d)):o},[o,t]),u=useMemo(()=>c.reduce((d,p)=>{let m=p.category||"Other";return d[m]||(d[m]=[]),d[m].push(p),d},{}),[c]);if(useEffect(()=>{a(0);},[t,e]),useEffect(()=>{if(!e)return;let d=p=>{let m=c.length>0;switch(p.key){case "Escape":p.preventDefault(),p.stopPropagation(),l();break;case "ArrowDown":if(!m)return;p.preventDefault(),p.stopPropagation(),a(h=>Math.min(h+1,Math.max(c.length-1,0)));break;case "ArrowUp":if(!m)return;p.preventDefault(),p.stopPropagation(),a(h=>Math.max(h-1,0));break;case "Enter":case "Tab":if(!m||!c[i])return;p.preventDefault(),p.stopPropagation(),r(c[i].id);break}};return document.addEventListener("keydown",d,true),()=>document.removeEventListener("keydown",d,true)},[c,e,l,r,i]),!e||!n)return null;let C=jsxs("div",{className:"luthor-slash-menu",style:{left:n.x,top:n.y,...ut()},onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},children:[jsxs("div",{className:"luthor-slash-menu-header",children:[jsx("span",{className:"luthor-slash-menu-title",children:"Insert block"}),jsxs("span",{className:"luthor-slash-menu-query",children:["/",t]})]}),jsx("div",{className:"luthor-slash-menu-list",children:c.length===0?jsx("div",{className:"luthor-slash-menu-empty",children:"No matching commands"}):Object.entries(u).map(([d,p])=>jsxs("div",{className:"luthor-slash-menu-group",children:[jsx("div",{className:"luthor-slash-menu-group-title",children:d}),p.map(m=>{let h=c.indexOf(m);return jsxs("button",{type:"button",className:`luthor-slash-menu-item ${h===i?"selected":""}`,onMouseEnter:()=>a(h),onMouseDown:w=>{w.preventDefault(),w.stopPropagation();},onClick:w=>{w.preventDefault(),w.stopPropagation(),r(m.id);},children:[jsxs("span",{className:"luthor-slash-menu-item-content",children:[jsx("span",{className:"luthor-slash-menu-item-title",children:m.label}),m.description&&jsx("span",{className:"luthor-slash-menu-item-description",children:m.description})]}),m.shortcut&&jsx("kbd",{className:"luthor-slash-menu-item-shortcut",children:m.shortcut})]},m.id)})]},d))})]});return typeof document>"u"?C:createPortal(C,document.body)}function S({children:e,onClick:t,title:n,active:o,disabled:l,className:r,type:i="button"}){return jsx("button",{type:i,className:`luthor-toolbar-button${o?" active":""}${r?` ${r}`:""}`,onClick:t,title:n,disabled:l,children:e})}function Xt({children:e,onClick:t,variant:n="primary",type:o="button",className:l}){return jsx("button",{type:o,onClick:t,className:`${n==="primary"?"luthor-button-primary":"luthor-button-secondary"}${l?` ${l}`:""}`,children:e})}function yt({value:e,onValueChange:t,options:n,placeholder:o="Select..."}){let[l,r]=useState(false),[i,a]=useState(void 0),c=useRef(null),u=useRef(null);useEffect(()=>{if(!l)return;let d=()=>{let p=c.current?.querySelector(".luthor-select-trigger");if(!p)return;let m=p.getBoundingClientRect();a({position:"fixed",top:m.bottom+4,left:m.left,width:m.width,...qe(p)});};return d(),window.addEventListener("resize",d),window.addEventListener("scroll",d,true),()=>{window.removeEventListener("resize",d),window.removeEventListener("scroll",d,true);}},[l]),useEffect(()=>{function d(p){let m=p.target;c.current?.contains(m)||u.current?.contains(m)||r(false);}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[]);let C=n.find(d=>d.value===e);return jsxs("div",{className:"luthor-select",ref:c,children:[jsxs("button",{className:`luthor-select-trigger ${l?"open":""}`,onClick:()=>r(!l),type:"button",children:[jsx("span",{children:C?.label||o}),jsx(jo,{size:14})]}),l&&typeof document<"u"&&createPortal(jsx("div",{ref:u,className:"luthor-select-dropdown",style:i,children:n.map(d=>jsx("button",{className:`luthor-select-option ${e===d.value?"selected":""}`,onClick:()=>{t(d.value),r(false);},type:"button",children:d.label},d.value))}),document.body)]})}function vt({trigger:e,children:t,isOpen:n,onOpenChange:o}){let l=useRef(null),r=useRef(null),i=useRef(null),[a,c]=useState(void 0);return useEffect(()=>{if(!n)return;let u=()=>{let C=r.current;if(!C)return;let d=C.getBoundingClientRect();c({position:"fixed",top:d.bottom+4,left:d.left,...qe(C)});};return u(),window.addEventListener("resize",u),window.addEventListener("scroll",u,true),()=>{window.removeEventListener("resize",u),window.removeEventListener("scroll",u,true);}},[n]),useEffect(()=>{function u(C){let d=C.target;l.current?.contains(d)||i.current?.contains(d)||o(false);}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[o]),jsxs("div",{className:"luthor-dropdown",ref:l,children:[jsx("div",{ref:r,onClick:()=>o(!n),children:e}),n&&typeof document<"u"&&createPortal(jsx("div",{ref:i,className:"luthor-dropdown-content",style:a,children:t}),document.body)]})}function Zo({isOpen:e,onClose:t,title:n,children:o}){let l=useRef(null);return useEffect(()=>{function r(a){l.current&&!l.current.contains(a.target)&&t();}function i(a){a.key==="Escape"&&t();}return e&&(document.addEventListener("mousedown",r),document.addEventListener("keydown",i)),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("keydown",i);}},[e,t]),e?jsx("div",{className:"luthor-dialog-overlay",children:jsxs("div",{className:"luthor-dialog",ref:l,children:[jsxs("div",{className:"luthor-dialog-header",children:[jsx("h3",{className:"luthor-dialog-title",children:n}),jsx("button",{className:"luthor-dialog-close",onClick:t,type:"button",children:jsx(_o,{size:16})})]}),jsx("div",{className:"luthor-dialog-content",children:o})]})}):null}function en({isVisible:e,selectionRect:t,commands:n,activeStates:o,editorTheme:l="light",hide:r,isFeatureEnabled:i=()=>true}){let a=useRef(null),[c,u]=useState(""),[C,d]=useState(""),[p,m]=useState(""),[h,U]=useState(""),[w,P]=useState(""),[J,j]=useState(""),[v,Z]=useState(null),[re,V]=useState(null),[g,F]=useState(null),k=!!o.isIframeEmbedSelected,M=!!o.isYouTubeEmbedSelected,H=i("iframeEmbed"),W=i("youTubeEmbed"),z=i("image"),me=H&&k||W&&M;if(useEffect(()=>{if(!e)return;let I=L=>{let _=L.target;_&&(a.current?.contains(_)||r?.());};return document.addEventListener("mousedown",I,true),document.addEventListener("touchstart",I,true),()=>{document.removeEventListener("mousedown",I,true),document.removeEventListener("touchstart",I,true);}},[e,r]),useEffect(()=>{if(!e||!k)return;let I=false;return typeof n.getIframeEmbedCaption=="function"&&n.getIframeEmbedCaption().then(L=>{I||d(L??"");}),typeof n.getIframeEmbedUrl=="function"&&n.getIframeEmbedUrl().then(L=>{I||u(L??"");}),Z(null),()=>{I=true;}},[n,k,e]),useEffect(()=>{if(!e||!o.imageSelected)return;let I=false;return typeof n.getImageCaption=="function"&&n.getImageCaption().then(L=>{I||m(L??"");}),()=>{I=true;}},[o.imageSelected,n,e]),useEffect(()=>{if(!e||!M)return;let I=false;return typeof n.getYouTubeEmbedCaption=="function"&&n.getYouTubeEmbedCaption().then(L=>{I||U(L??"");}),typeof n.getYouTubeEmbedUrl=="function"&&n.getYouTubeEmbedUrl().then(L=>{I||P(L??"");}),V(null),()=>{I=true;}},[n,e,M]),useEffect(()=>{if(!e||!o.isLink)return;let I=false;return typeof n.getCurrentLink=="function"&&n.getCurrentLink().then(L=>{!I&&L&&j(L.url??"");}),F(null),()=>{I=true;}},[o.isLink,n,e]),!e||!t)return null;let te={...ut(),position:"absolute",top:t.y,left:t.positionFromRight?"auto":t.x,right:t.positionFromRight?10:"auto",zIndex:9999,pointerEvents:"auto"};if(me){let I=R=>{if(k){n.setIframeEmbedAlignment?.(R);return}M&&n.setYouTubeEmbedAlignment?.(R);},L=k?o.isIframeEmbedAlignedLeft:o.isYouTubeEmbedAlignedLeft,_=k?o.isIframeEmbedAlignedCenter:o.isYouTubeEmbedAlignedCenter,We=k?o.isIframeEmbedAlignedRight:o.isYouTubeEmbedAlignedRight,he=k?typeof n.setIframeEmbedCaption=="function":typeof n.setYouTubeEmbedCaption=="function",Ce=k?typeof n.updateIframeEmbedUrl=="function":typeof n.updateYouTubeEmbedUrl=="function",je=k?C:h,ke=k?d:U,ze=k?c:w,G=k?v:re,Ee=()=>{if(he){if(k){n.setIframeEmbedCaption?.(C);return}n.setYouTubeEmbedCaption?.(h);}},Oe=R=>{k?Z(R):V(R);},oe=R=>{k?u(R):P(R);},pe=()=>{if(!Ce)return;if(!(k?n.updateIframeEmbedUrl?.(c)??false:n.updateYouTubeEmbedUrl?.(w)??false)){Oe(k?"Enter a valid http(s) URL":"Enter a valid YouTube URL"),k&&typeof n.getIframeEmbedUrl=="function"?n.getIframeEmbedUrl().then(He=>u(He??"")):!k&&typeof n.getYouTubeEmbedUrl=="function"&&n.getYouTubeEmbedUrl().then(He=>P(He??""));return}Oe(null);};return jsxs("div",{className:"luthor-floating-toolbar","data-theme":l,ref:a,style:te,children:[jsx(S,{onClick:()=>I("left"),active:L,title:"Align Left",children:jsx(lt,{size:14})}),jsx(S,{onClick:()=>I("center"),active:_,title:"Align Center",children:jsx(et,{size:14})}),jsx(S,{onClick:()=>I("right"),active:We,title:"Align Right",children:jsx(at,{size:14})}),he||Ce?jsxs(Fragment,{children:[jsx("div",{className:"luthor-floating-toolbar-separator"}),jsxs("div",{className:"luthor-floating-toolbar-fields",children:[Ce?jsxs("div",{className:"luthor-floating-toolbar-field-row",children:[jsx("input",{type:"url",value:ze,className:`luthor-floating-toolbar-input${G?" is-error":""}`,placeholder:k?"https://example.com/embed":"https://youtube.com/watch?v=...","aria-label":k?"Iframe URL":"YouTube URL","aria-invalid":G?true:void 0,onChange:R=>{oe(R.target.value),G&&Oe(null);},onBlur:pe,onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),pe());}}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-floating-toolbar-action luthor-floating-toolbar-action-primary",onClick:pe,children:"Update URL"})]}):null,he?jsxs("div",{className:"luthor-floating-toolbar-field-row",children:[jsx("input",{type:"text",value:je,className:"luthor-floating-toolbar-input",placeholder:"Add caption","aria-label":k?"Iframe caption":"YouTube caption",onChange:R=>ke(R.target.value),onBlur:Ee,onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),Ee());}}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-floating-toolbar-action",onClick:Ee,children:"Update Caption"})]}):null]})]}):null]})}if(z&&o.imageSelected){let I=typeof n.setImageCaption=="function",L=()=>{I&&n.setImageCaption(p);};return jsxs("div",{className:"luthor-floating-toolbar","data-theme":l,ref:a,style:te,children:[jsx(S,{onClick:()=>n.setImageAlignment("left"),active:o.isImageAlignedLeft,title:"Align Left",children:jsx(lt,{size:14})}),jsx(S,{onClick:()=>n.setImageAlignment("center"),active:o.isImageAlignedCenter,title:"Align Center",children:jsx(et,{size:14})}),jsx(S,{onClick:()=>n.setImageAlignment("right"),active:o.isImageAlignedRight,title:"Align Right",children:jsx(at,{size:14})}),I?jsxs(Fragment,{children:[jsx("div",{className:"luthor-floating-toolbar-separator"}),jsxs("div",{className:"luthor-floating-toolbar-field-row",children:[jsx("input",{type:"text",value:p,className:"luthor-floating-toolbar-input",placeholder:"Add caption","aria-label":"Image caption",onChange:_=>m(_.target.value),onBlur:L,onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),L());}}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-floating-toolbar-action",onClick:L,children:"Update Caption"})]})]}):null]})}let xe=i("bold"),ie=i("italic"),Se=i("underline"),Le=i("strikethrough"),Ie=i("codeFormat"),se=i("blockFormat"),Fe=i("link"),Pe=i("list"),we=xe||ie||Se||Le,ue=Ie||se||Fe,Ne=Pe,fe=!!o.isLink&&typeof n.updateLink=="function"&&typeof n.removeLink=="function",ce=()=>{if(!fe)return;if(!(n.updateLink?.(J)??false)){F("Enter a valid URL"),typeof n.getCurrentLink=="function"&&n.getCurrentLink().then(L=>{j(L?.url??"");});return}F(null);};return !we&&!ue&&!Ne?null:jsxs("div",{className:"luthor-floating-toolbar","data-theme":l,ref:a,style:te,children:[we?jsxs(Fragment,{children:[xe?jsx(S,{onClick:()=>n.toggleBold(),active:o.bold,title:"Bold",children:jsx(wt,{size:14})}):null,ie?jsx(S,{onClick:()=>n.toggleItalic(),active:o.italic,title:"Italic",children:jsx(Nt,{size:14})}):null,Se?jsx(S,{onClick:()=>n.toggleUnderline(),active:o.underline,title:"Underline",children:jsx(Ot,{size:14})}):null,Le?jsx(S,{onClick:()=>n.toggleStrikethrough(),active:o.strikethrough,title:"Strikethrough",children:jsx(Ht,{size:14})}):null]}):null,we&&ue?jsx("div",{className:"luthor-floating-toolbar-separator"}):null,ue?jsxs(Fragment,{children:[Ie?jsx(S,{onClick:()=>n.formatText("code"),active:o.code,title:"Inline Code",children:jsx(Pt,{size:14})}):null,se?jsx(S,{onClick:()=>n.toggleQuote(),active:o.isQuote,title:"Quote",children:jsx(Mt,{size:14})}):null,Fe?jsxs(Fragment,{children:[jsx(S,{onClick:()=>o.isLink?n.removeLink():n.insertLink(),active:o.isLink,title:o.isLink?"Remove Link":"Insert Link",children:o.isLink?jsx(Ze,{size:14}):jsx(it,{size:14})}),fe?jsxs("div",{className:"luthor-floating-toolbar-field-row",children:[jsx("input",{type:"url",value:J,className:`luthor-floating-toolbar-input${g?" is-error":""}`,placeholder:"https://example.com","aria-label":"Link URL","aria-invalid":g?true:void 0,onChange:I=>{j(I.target.value),g&&F(null);},onBlur:ce,onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),ce());}}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-floating-toolbar-action luthor-floating-toolbar-action-primary",onClick:ce,children:"Update Link"}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-floating-toolbar-action luthor-floating-toolbar-action-danger",onClick:()=>n.removeLink(),"aria-label":"Unlink",children:jsx(Ze,{size:13})})]}):null]}):null]}):null,(we||ue)&&Ne?jsx("div",{className:"luthor-floating-toolbar-separator"}):null,Ne?jsxs(Fragment,{children:[jsx(S,{onClick:()=>n.toggleUnorderedList(),active:o.unorderedList,title:"Bullet List",children:jsx(zt,{size:14})}),jsx(S,{onClick:()=>n.toggleOrderedList(),active:o.orderedList,title:"Numbered List",children:jsx(Rt,{size:14})}),jsx(S,{onClick:()=>n.toggleCheckList(),active:o.checkList,title:"Checklist",children:jsx(At,{size:14})})]}):null]})}var Re={commands:{},activeStates:{},editorTheme:"light",isFeatureEnabled:()=>true};function Zt(e,t,n,o=()=>true){Re.commands=e,Re.activeStates=t,Re.editorTheme=n,Re.isFeatureEnabled=o;}function tn(){let e=en,t=new FloatingToolbarExtension;return t.config={...t.config,render:n=>createElement(e,{...n,commands:Re.commands,activeStates:Re.activeStates,editorTheme:Re.editorTheme,isFeatureEnabled:Re.isFeatureEnabled}),getCommands:()=>Re.commands,getActiveStates:()=>Re.activeStates},t}var Wr=120,Xr=58;function Zr(e,t=Xr){return e.length<=t?e:`${e.slice(0,t-3)}...`}function nn(){let e=window.getSelection();return !e||e.rangeCount===0?false:!e.getRangeAt(0).collapsed}function rn(e,t){if(!(e instanceof Element))return null;let n=e.closest("a");return !(n instanceof HTMLAnchorElement)||!t.contains(n)?null:n}function sn({editor:e,commands:t,editorTheme:n="light",disabled:o=false}){let l=useRef(null),r=useRef(null),[i,a]=useState(null),[c,u]=useState(false),[C,d]=useState(""),[p,m]=useState(null),[h,U]=useState(null),w=useCallback(()=>{r.current!==null&&(window.clearTimeout(r.current),r.current=null);},[]),P=useCallback(()=>{w(),a(null),u(false),d(""),m(null),U(null);},[w]),J=useCallback(()=>{w(),r.current=window.setTimeout(()=>{P();},Wr);},[w,P]),j=useCallback(g=>{let F=g.getBoundingClientRect(),k=F.bottom+8,M=Math.max(10,Math.min(F.left,window.innerWidth-340));U({top:k,left:M});},[]),v=useCallback((g,F)=>{if(typeof t.getLinkByKey!="function"){a(k=>!k||k.nodeKey!==g?k:{...k,url:F});return}t.getLinkByKey(g).then(k=>{if(!k){P();return}a(M=>!M||M.nodeKey!==g?M:{...M,url:k.url});});},[t,P]);useEffect(()=>{if(!e||o||typeof window>"u"){P();return}let g=e.getRootElement();if(!g){P();return}let F=W=>{let z=rn(W.target,g);if(!z)return;if(nn()){P();return}w();let me=resolveLinkNodeKeyFromAnchor(e,z);if(!me)return;let te=z.getAttribute("href")??z.href;a({nodeKey:me,url:te,anchorEl:z}),j(z),m(null),c||d(te),v(me,te);},k=W=>{if(!i)return;let z=W.relatedTarget;z&&l.current?.contains(z)||rn(z,g)||J();},M=()=>{nn()&&P();},H=()=>{a(W=>{if(!W)return W;let z=W.anchorEl.isConnected&&g.contains(W.anchorEl)?W.anchorEl:g.querySelector(`a[data-lexical-node-key="${W.nodeKey}"]`);return z?(j(z),{...W,anchorEl:z,url:z.getAttribute("href")??z.href}):(P(),null)});};return g.addEventListener("mouseover",F),g.addEventListener("mouseout",k),document.addEventListener("selectionchange",M),window.addEventListener("scroll",H,true),window.addEventListener("resize",H),()=>{g.removeEventListener("mouseover",F),g.removeEventListener("mouseout",k),document.removeEventListener("selectionchange",M),window.removeEventListener("scroll",H,true),window.removeEventListener("resize",H),w();}},[t,o,e,i,c,P,J,v,j,w]);let Z=useMemo(()=>{if(!(!i||!h))return {...qe(i.anchorEl),position:"fixed",top:h.top,left:h.left,zIndex:10040}},[i,h]);if(!i||!h||typeof document>"u")return null;let re=()=>{(t.removeLinkByKey?.(i.nodeKey)??false)&&P();},V=()=>{let g=C.trim();if(!(t.updateLinkByKey?.(i.nodeKey,g)??false)){m("Enter a valid URL"),v(i.nodeKey,i.url);return}a(k=>!k||k.nodeKey!==i.nodeKey?k:{...k,url:g}),m(null),u(false),queueMicrotask(()=>{v(i.nodeKey,g);});};return createPortal(jsx("div",{ref:l,className:"luthor-floating-toolbar luthor-link-hover-bubble","data-theme":n,style:Z,onMouseEnter:w,onMouseLeave:J,children:c?jsxs(Fragment,{children:[jsx("input",{type:"url",value:C,className:`luthor-link-hover-bubble-input${p?" is-error":""}`,placeholder:"https://example.com","aria-label":"Edit link URL","aria-invalid":p?true:void 0,onChange:g=>{d(g.target.value),p&&m(null);},onKeyDown:g=>{if(g.key==="Enter"){g.preventDefault(),V();return}g.key==="Escape"&&(g.preventDefault(),u(false),d(i.url),m(null));}}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-link-hover-bubble-button luthor-link-hover-bubble-button-primary",onClick:V,children:"Update"}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-link-hover-bubble-button",onClick:()=>{u(false),d(i.url),m(null);},children:"Cancel"})]}):jsxs(Fragment,{children:[jsx("span",{className:"luthor-link-hover-bubble-url",title:i.url,children:Zr(i.url)}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-link-hover-bubble-button",onClick:()=>{d(i.url),u(true),m(null);},children:"Edit"}),jsx("button",{type:"button",className:"luthor-toolbar-button luthor-link-hover-bubble-button luthor-link-hover-bubble-button-danger",onClick:re,"aria-label":"Unlink",children:jsx(Ze,{size:13})})]})}),document.body)}function un({mode:e,onModeChange:t,labels:n,availableModes:o,isConverting:l}){let r=o??["visual","jsonb"],i={visual:n?.visual??"Visual",jsonb:n?.jsonb??"JSONB"};return jsxs("div",{className:"luthor-mode-tabs",children:[r.includes("visual")&&jsxs("button",{className:`luthor-mode-tab ${e==="visual"?"active":""}`,onClick:()=>t("visual"),children:[i.visual,l==="visual"&&jsx("span",{className:"luthor-tab-converting-spinner"})]}),r.includes("jsonb")&&jsxs("button",{className:`luthor-mode-tab ${e==="jsonb"?"active":""}`,onClick:()=>t("jsonb"),children:[i.jsonb,l==="jsonb"&&jsx("span",{className:"luthor-tab-converting-spinner"})]})]})}function cn({value:e,onChange:t,placeholder:n,className:o}){let l=useRef(null);return useLayoutEffect(()=>{let r=l.current;if(!r)return;r.style.height="auto";let i=Math.max(r.scrollHeight,280);r.style.height=`${i}px`;},[e]),jsx("textarea",{ref:l,className:`luthor-source-view${o?` ${o}`:""}`,value:e,onChange:r=>t(r.target.value),placeholder:n,spellCheck:false})}function dn(e,t){let n=`luthor-preset-${e}`;return {placeholder:t,classNames:{container:`luthor-preset ${n} ${n}__container`,contentEditable:`luthor-content-editable ${n}__content`,placeholder:`luthor-placeholder ${n}__placeholder`}}}function oi(e){return e.replace(/\r\n?/g,`
2
- `)}function oo(e){let t=oi(e).trim();if(!t)return "";try{let n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}var no=6,li=["#ffffff","#f2f2f2","#d9d9d9","#bfbfbf","#808080","#404040","#000000","#fbe5d6","#f8cbad","#f4b183","#ed7d31","#c55a11","#fff2cc","#ffe699","#ffd966","#ffc000","#bf9000","#7f6000","#e2f0d9","#c6e0b4","#a9d18e","#70ad47","#548235","#375623","#ddebf7","#bdd7ee","#9dc3e6","#5b9bd5","#2f75b5","#1f4e78","#e4dfec","#d9c2e9","#b4a7d6","#8e7cc3","#674ea7","#351c75"];function Ut(e){return e.trim().toLowerCase().replace(/\s+/g,"")}function ai(e,t){let n=Ut(t);for(let o of e)if(Ut(o.value)===n)return o.color;return null}function si(e,t,n){if(!e||e==="default")return n;let o=ai(t,e);return o||e}function ui(e,t){let n=e.trim();return /^#([\da-f]{6})$/i.test(n)?n:/^#([\da-f]{3})$/i.test(n)?`#${n.slice(1).split("").map(l=>`${l}${l}`).join("")}`:t}function De(e){return e.trim().toLowerCase().replace(/\s+/g,"")}function mn(e){let t=e.split(",")[0]??"";return De(t.replace(/["']/g,""))}function jt(e){let t=e.trim().toLowerCase().match(/^(-?\d*\.?\d+)px$/);if(!t)return null;let n=Number(t[1]);return Number.isFinite(n)?n:null}function Kt(){if(typeof window>"u")return null;let t=window.getSelection()?.anchorNode;if(!t)return null;let n=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;if(!n||!n.closest(".luthor-content-editable"))return null;let l=window.getComputedStyle(n);return {fontFamily:l.fontFamily,fontSize:l.fontSize,lineHeight:l.lineHeight}}function ci(e,t){if(!e)return null;let n=mn(e);return n?t.find(l=>De(l.value)===n?true:mn(l.fontFamily)===n)?.value??null:null}function di(e,t){if(!e)return null;let n=De(e),o=t.find(i=>De(String(i.value))===n?true:De(String(i.fontSize))===n);if(o)return String(o.value);let l=jt(e);if(l==null)return null;let r=null;for(let i of t){let a=jt(String(i.fontSize));if(a==null)continue;let c=Math.abs(a-l);(!r||c<r.distance)&&(r={value:String(i.value),distance:c});}return r?.value??null}function gi(e,t,n){if(!e)return null;let o=De(e),l=n.find(u=>De(u.value)===o?true:De(u.lineHeight)===o);if(l)return l.value;let r=t?jt(t):null,i=jt(e),a=null;if(i!=null&&r!=null&&r>0)a=i/r;else {let u=Number(e);Number.isFinite(u)&&(a=u);}if(a==null)return null;let c=null;for(let u of n){let C=Number(u.lineHeight);if(!Number.isFinite(C))continue;let d=Math.abs(C-a);(!c||d<c.distance)&&(c={value:u.value,distance:d});}return c?.value??null}function fn({title:e,value:t,options:n,recentColors:o,active:l,fallbackColor:r,highlight:i,onChange:a,onClear:c,onAddRecent:u}){let C=useRef(null),d=useRef(null),p=useRef(null),m=useRef(null),h=useRef(null),[U,w]=useState(false),[P,J]=useState(void 0),j=si(t,n,r),v=useMemo(()=>li,[]),Z=useMemo(()=>{let g=[...o].slice(0,no);for(;g.length<no;)g.push("");return g},[o]);useEffect(()=>()=>{m.current&&window.cancelAnimationFrame(m.current);},[]);let re=useCallback(g=>{h.current=g,!m.current&&(m.current=window.requestAnimationFrame(()=>{m.current=null,h.current&&(a(h.current),h.current=null);}));},[a]),V=useCallback(g=>{let F=C.current;if(!F)return;let k=F.getBoundingClientRect();J({position:"fixed",top:k.bottom+6,left:k.left,width:230,visibility:g?"visible":"hidden",...qe(F)});},[]);return useLayoutEffect(()=>{if(!U)return;V(false);let g=window.requestAnimationFrame(()=>{V(true);});return ()=>{window.cancelAnimationFrame(g);}},[U,V]),useEffect(()=>{if(!U)return;let g=M=>{let H=M.target;C.current?.contains(H)||d.current?.contains(H)||w(false);},F=M=>{M.key==="Escape"&&w(false);},k=()=>V(true);return window.addEventListener("resize",k),window.addEventListener("scroll",k,true),document.addEventListener("mousedown",g),document.addEventListener("keydown",F),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k,true),document.removeEventListener("mousedown",g),document.removeEventListener("keydown",F);}},[U,V]),jsxs(Fragment,{children:[jsxs("button",{ref:C,type:"button",className:`luthor-toolbar-button luthor-color-button${l?" active":""}${i?" is-highlight":""}`,title:e,"aria-label":e,onClick:()=>w(g=>!g),children:[i?jsx(Ho,{size:15,className:"luthor-color-button-highlighter"}):jsx("span",{className:"luthor-color-button-letter",children:"A"}),jsx("span",{className:"luthor-color-button-indicator",style:{backgroundColor:j}})]}),U&&typeof document<"u"&&createPortal(jsxs("div",{ref:d,className:"luthor-color-picker",style:P,children:[jsx("div",{className:"luthor-color-picker-header",children:jsx("span",{className:"luthor-color-picker-title",children:e})}),jsxs("div",{className:"luthor-color-picker-section",children:[jsx("p",{className:"luthor-color-picker-label",children:"Colors"}),jsx("div",{className:"luthor-color-swatch-grid",children:v.map(g=>jsx("button",{type:"button",className:"luthor-color-swatch",style:{backgroundColor:g},"aria-label":`Use color ${g}`,onClick:()=>{a(g),u(g),w(false);}},g))})]}),jsxs("div",{className:"luthor-color-picker-section",children:[jsx("p",{className:"luthor-color-picker-label",children:"Recent colors"}),jsx("div",{className:"luthor-color-swatch-row",children:Z.map((g,F)=>jsx("button",{type:"button",className:"luthor-color-swatch",style:{backgroundColor:g||"transparent"},"aria-label":g?`Use recent color ${g}`:"Empty recent color slot",disabled:!g,onClick:()=>{g&&(a(g),u(g),w(false));}},`${g||"empty"}-${F}`))})]}),jsxs("div",{className:"luthor-color-picker-footer",children:[jsx("button",{type:"button",className:"luthor-color-picker-clear",onClick:()=>{c(),w(false);},children:"Reset to Default"}),jsxs("button",{type:"button",className:"luthor-color-picker-custom",onClick:()=>p.current?.click(),children:[jsx(Po,{size:14}),jsx("span",{children:"Custom Color"})]}),jsx("input",{ref:p,type:"color",className:"luthor-color-picker-native luthor-color-picker-native-hidden",value:ui(j,r),onInput:g=>{re(g.target.value);},onChange:g=>{let F=g.target.value;a(F),u(F);}})]})]}),document.body)]})}function mi(e,t){let n=useRef(null),o=useRef(null);return {handlers:useMemo(()=>({insertFromUrl:()=>{let r=prompt("Enter image URL:");if(!r)return;let i=prompt("Enter alt text:")||"",a=prompt("Enter caption (optional):")||void 0;e.insertImage({src:r,alt:i,caption:a});},insertFromFile:()=>n.current?.click(),insertGifFromUrl:()=>{let r=prompt("Enter GIF URL:");if(!r)return;let i=prompt("Enter alt text (optional):")||"GIF";e.insertImage({src:r,alt:i});},insertGifFromFile:()=>o.current?.click(),handleUpload:async r=>{let i=r.target.files?.[0];if(!i)return;let a;if(t)try{a=await t(i);}catch{alert("Failed to upload image");return}else a=URL.createObjectURL(i);e.insertImage({src:a,alt:i.name,file:i}),r.target.value="";},handleGifUpload:async r=>{let i=r.target.files?.[0];if(!i)return;if(!(i.type==="image/gif"||i.name.toLowerCase().endsWith(".gif"))){alert("Please select a GIF file."),r.target.value="";return}let c;if(t)try{c=await t(i);}catch{alert("Failed to upload GIF");return}else c=URL.createObjectURL(i);e.insertImage({src:c,alt:i.name||"GIF",file:i}),r.target.value="";},setAlignment:r=>{e.setImageAlignment(r);},setCaption:()=>{let r=prompt("Enter caption:")||"";e.setImageCaption(r);}}),[e,t]),fileInputRef:n,gifInputRef:o}}function fi(e){return useMemo(()=>({insertIframe:()=>{let t=prompt("Enter iframe URL:");t&&typeof e.insertIframeEmbed=="function"&&e.insertIframeEmbed(t);},insertYouTube:()=>{let t=prompt("Enter YouTube URL:");t&&typeof e.insertYouTubeEmbed=="function"&&e.insertYouTubeEmbed(t);}}),[e])}function hi(e,t){switch(e){case "fontFamily":return t("fontFamily");case "fontSize":return t("fontSize");case "lineHeight":return t("lineHeight");case "textColor":return t("textColor");case "textHighlight":return t("textHighlight");case "subscript":return t("subscript");case "superscript":return t("superscript");case "blockFormat":case "quote":case "alignLeft":case "alignCenter":case "alignRight":case "alignJustify":return t("blockFormat");case "codeBlock":return t("code");case "unorderedList":case "orderedList":case "checkList":case "indentList":case "outdentList":return t("list");case "horizontalRule":return t("horizontalRule");case "table":return t("table");case "image":return t("image");case "emoji":return t("emoji");case "embed":return t("iframeEmbed")||t("youtubeEmbed");case "undo":case "redo":return t("history");default:return true}}function pi(e,t,n){return hi(e,t)?n?.[e]!==false:false}function bi(e,t,n){return {sections:e.sections.map(o=>({...o,items:o.items.filter(l=>pi(l,t,n))})).filter(o=>o.items.length>0)}}function hn({commands:e,hasExtension:t,activeStates:n,isDark:o,toggleTheme:l,onCommandPaletteOpen:r,imageUploadHandler:i,classNames:a,toolbarStyleVars:c,layout:u,toolbarVisibility:C,headingOptions:d,paragraphLabel:p}){let{handlers:m,fileInputRef:h,gifInputRef:U}=mi(e,i),w=fi(e),P=t("iframeEmbed")||t("youtubeEmbed"),J=n.isIframeEmbedSelected||n.isYouTubeEmbedSelected,[j,v]=useState(false),[Z,re]=useState(false),[V,g]=useState(false),[F,k]=useState(false),[M,H]=useState(false),[W,z]=useState("default"),[me,te]=useState([{value:"default",label:"Default"}]),[xe,ie]=useState("default"),[Se,Le]=useState([{value:"default",label:"Default"}]),[Ie,se]=useState("default"),[Fe,Pe]=useState([{value:"default",label:"Default"}]),[we,ue]=useState("default"),[Ne,fe]=useState([{value:"default",label:"Default",color:"inherit"}]),[ce,I]=useState([]),[L,_]=useState("default"),[We,he]=useState([{value:"default",label:"Default",color:"transparent"}]),[Ce,je]=useState([]),[ke,ze]=useState(0),[G,Ee]=useState({rows:3,columns:3,includeHeaders:false});useEffect(()=>{if(typeof document>"u")return;let f=()=>{Kt()&&ze(O=>O+1);};return document.addEventListener("selectionchange",f),()=>{document.removeEventListener("selectionchange",f);}},[]);let Oe=useMemo(()=>t("emoji")?typeof e.getEmojiSuggestions=="function"?e.getEmojiSuggestions(""):typeof e.getEmojiCatalog=="function"?e.getEmojiCatalog():[]:[],[e,t]);useEffect(()=>{if(!t("fontFamily")||typeof e.getFontFamilyOptions!="function")return;let f=e.getFontFamilyOptions().map(O=>({value:O.value,label:O.label})),b=f.length>0?f:[{value:"default",label:"Default"}];te(b),z(O=>b.some(A=>A.value===O)?O:"default");},[e,t]),useEffect(()=>{if(!t("fontFamily")||typeof e.getCurrentFontFamily!="function")return;let f=e.getFontFamilyOptions;if(typeof f!="function")return;let b=false;return e.getCurrentFontFamily().then(O=>{if(b)return;if(O&&O!=="default"){z(O);return}let A=Kt(),le=ci(A?.fontFamily,f());z(le??"default");}),()=>{b=true;}},[n,e,t,ke]),useEffect(()=>{if(!t("fontSize")||typeof e.getFontSizeOptions!="function")return;let f=e.getFontSizeOptions().map(A=>({value:String(A.value).trim(),label:String(A.label).trim()})).filter(A=>A.value.length>0&&A.label.length>0),b=f.some(A=>De(A.value)==="default"),O=f.length===0?[{value:"default",label:"Default"}]:b?f:[{value:"default",label:"Default"},...f];Le(O),ie(A=>O.some(le=>le.value===A)?A:"default");},[e,t]),useEffect(()=>{if(!t("fontSize")||typeof e.getCurrentFontSize!="function")return;let f=e.getFontSizeOptions;if(typeof f!="function")return;let b=false;return e.getCurrentFontSize().then(O=>{if(b)return;if(O&&O!=="default"){ie(O);return}let A=Kt(),le=di(A?.fontSize,f());ie(le??"default");}),()=>{b=true;}},[n,e,t,ke]),useEffect(()=>{if(!t("lineHeight")||typeof e.getLineHeightOptions!="function")return;let f=e.getLineHeightOptions().map(b=>({value:b.value,label:b.label}));f.length>0&&Pe(f);},[e,t]),useEffect(()=>{if(!t("lineHeight")||typeof e.getCurrentLineHeight!="function")return;let f=e.getLineHeightOptions;if(typeof f!="function")return;let b=false;return e.getCurrentLineHeight().then(O=>{if(b)return;if(O){se(O);return}let A=Kt(),le=gi(A?.lineHeight,A?.fontSize,f());se(le??"default");}),()=>{b=true;}},[n,e,t,ke]),useEffect(()=>{if(!t("textColor")||typeof e.getTextColorOptions!="function")return;let f=e.getTextColorOptions().map(b=>({value:b.value,label:b.label,color:b.color}));f.length>0&&fe(f);},[e,t]),useEffect(()=>{if(!t("textColor")||typeof e.getCurrentTextColor!="function")return;let f=false;return e.getCurrentTextColor().then(b=>{f||ue(b??"default");}),()=>{f=true;}},[n,e,t,ke]),useEffect(()=>{if(!t("textHighlight")||typeof e.getTextHighlightOptions!="function")return;let f=e.getTextHighlightOptions().map(b=>({value:b.value,label:b.label,color:b.backgroundColor}));f.length>0&&he(f);},[e,t]),useEffect(()=>{if(!t("textHighlight")||typeof e.getCurrentTextHighlight!="function")return;let f=false;return e.getCurrentTextHighlight().then(b=>{f||_(b??"default");}),()=>{f=true;}},[n,e,t,ke]);let oe=useMemo(()=>{if(!d||d.length===0)return [...Te];let f=new Set,b=[];for(let O of d)!Te.includes(O)||f.has(O)||(f.add(O),b.push(O));return b.length>0?b:[...Te]},[d]),pe=p?.trim()||"Paragraph",Ae=useMemo(()=>{let f=oe.map(b=>({value:b,label:`Heading ${b.slice(1)}`}));return [{value:"p",label:pe},...f]},[oe,pe]),R=n.isH1?"h1":n.isH2?"h2":n.isH3?"h3":n.isH4?"h4":n.isH5?"h5":n.isH6?"h6":"p",He=Ae.some(f=>f.value===R)?R:"p",Xe=f=>{f==="p"?e.toggleParagraph():f.startsWith("h")&&oe.includes(f)&&e.toggleHeading(f);},_e=f=>{f==="default"?e.clearFontFamily?.():e.setFontFamily?.(f),z(f);},Ve=f=>{f==="default"?e.clearFontSize?.():e.setFontSize?.(f),ie(f);},$e=f=>{e.setLineHeight?.(f),se(f);},y=(f,b)=>{f(O=>{let A=Ut(b),le=O.filter(ae=>Ut(ae)!==A);return [b,...le].slice(0,no)});},T=f=>{if(f==="default"){e.clearTextColor?.(),ue("default");return}e.setTextColor?.(f),ue(f);},D=f=>{if(f==="default"){e.clearTextHighlight?.(),_("default");return}e.setTextHighlight?.(f),_(f);},X=f=>{switch(f){case "fontFamily":return t("fontFamily")?jsx(yt,{value:W,onValueChange:_e,options:me,placeholder:"Font"},"fontFamily"):null;case "fontSize":return t("fontSize")?jsx(yt,{value:xe,onValueChange:Ve,options:Se,placeholder:"Size"},"fontSize"):null;case "lineHeight":return t("lineHeight")?jsx(yt,{value:Ie,onValueChange:$e,options:Fe,placeholder:"Line"},"lineHeight"):null;case "textColor":return t("textColor")?jsx(fn,{title:"Text Color",value:we,options:Ne,recentColors:ce,active:n.hasCustomTextColor,fallbackColor:"#0f172a",onChange:T,onClear:()=>T("default"),onAddRecent:b=>y(I,b)},"textColor"):null;case "textHighlight":return t("textHighlight")?jsx(fn,{title:"Text Highlight",value:L,options:We,recentColors:Ce,active:n.hasTextHighlight,fallbackColor:"#fef08a",highlight:true,onChange:D,onClear:()=>D("default"),onAddRecent:b=>y(je,b)},"textHighlight"):null;case "bold":return jsx(S,{onClick:()=>e.toggleBold(),active:n.bold,title:"Bold (Ctrl+B)",children:jsx(wt,{size:16})},"bold");case "italic":return jsx(S,{onClick:()=>e.toggleItalic(),active:n.italic,title:"Italic (Ctrl+I)",children:jsx(Nt,{size:16})},"italic");case "underline":return jsx(S,{onClick:()=>e.toggleUnderline(),active:n.underline,title:"Underline (Ctrl+U)",children:jsx(Ot,{size:16})},"underline");case "strikethrough":return jsx(S,{onClick:()=>e.toggleStrikethrough(),active:n.strikethrough,title:"Strikethrough",children:jsx(Ht,{size:16})},"strikethrough");case "subscript":return t("subscript")?jsx(S,{onClick:()=>e.toggleSubscript?.(),active:n.subscript,title:"Subscript",children:jsx(Ko,{size:16})},"subscript"):null;case "superscript":return t("superscript")?jsx(S,{onClick:()=>e.toggleSuperscript?.(),active:n.superscript,title:"Superscript",children:jsx(Uo,{size:16})},"superscript"):null;case "code":return jsx(S,{onClick:()=>e.formatText("code"),active:n.code,title:"Inline Code",children:jsx(Pt,{size:16})},"code");case "link":return jsx(S,{onClick:()=>n.isLink?e.removeLink():e.insertLink(),active:n.isLink,title:n.isLink?"Remove Link":"Insert Link",children:n.isLink?jsx(Ze,{size:16}):jsx(it,{size:16})},"link");case "blockFormat":return t("blockFormat")?jsx(yt,{value:He,onValueChange:Xe,options:Ae,placeholder:"Format"},"blockFormat"):null;case "quote":return t("blockFormat")?jsx(S,{onClick:()=>e.toggleQuote(),active:n.isQuote,title:"Quote",children:jsx(Mt,{size:16})},"quote"):null;case "alignLeft":return t("blockFormat")?jsx(S,{onClick:()=>e.setTextAlignment("left"),active:n.isTextAlignedLeft,title:"Align Left",children:jsx(lt,{size:16})},"alignLeft"):null;case "alignCenter":return t("blockFormat")?jsx(S,{onClick:()=>e.setTextAlignment("center"),active:n.isTextAlignedCenter,title:"Align Center",children:jsx(et,{size:16})},"alignCenter"):null;case "alignRight":return t("blockFormat")?jsx(S,{onClick:()=>e.setTextAlignment("right"),active:n.isTextAlignedRight,title:"Align Right",children:jsx(at,{size:16})},"alignRight"):null;case "alignJustify":return t("blockFormat")?jsx(S,{onClick:()=>e.setTextAlignment("justify"),active:n.isTextAlignedJustify,title:"Justify",children:jsx(Fo,{size:16})},"alignJustify"):null;case "codeBlock":return t("code")?jsx(S,{onClick:()=>e.toggleCodeBlock(),active:n.isInCodeBlock,title:"Code Block",children:jsx(So,{size:16})},"codeBlock"):null;case "unorderedList":return t("list")?jsx(S,{onClick:()=>e.toggleUnorderedList(),active:n.unorderedList,title:"Bullet List",children:jsx(zt,{size:16})},"unorderedList"):null;case "orderedList":return t("list")?jsx(S,{onClick:()=>e.toggleOrderedList(),active:n.orderedList,title:"Numbered List",children:jsx(Rt,{size:16})},"orderedList"):null;case "checkList":return t("list")?jsx(S,{onClick:()=>e.toggleCheckList(),active:n.checkList,title:"Checklist",children:jsx(At,{size:16})},"checkList"):null;case "indentList":return t("list")?jsx(S,{onClick:()=>e.indentList(),title:"Indent List",disabled:n.checkList,children:jsx(Ao,{size:14})},"indentList"):null;case "outdentList":return t("list")?jsx(S,{onClick:()=>e.outdentList(),title:"Outdent List",disabled:n.checkList,children:jsx(Ro,{size:14})},"outdentList"):null;case "horizontalRule":return t("horizontalRule")?jsx(S,{onClick:()=>e.insertHorizontalRule(),title:"Insert Horizontal Rule",children:jsx(wo,{size:16})},"horizontalRule"):null;case "table":return t("table")?jsx(S,{onClick:()=>H(true),title:"Insert Table",children:jsx(No,{size:16})},"table"):null;case "image":return t("image")?jsxs(Fragment,{children:[jsxs(vt,{trigger:jsx("button",{className:`luthor-toolbar-button ${n.imageSelected?"active":""}`,title:"Insert Image",children:jsx(Yt,{size:16})}),isOpen:j,onOpenChange:v,children:[jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.insertFromUrl(),v(false);},children:[jsx(it,{size:16}),jsx("span",{children:"From URL"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.insertFromFile(),v(false);},children:[jsx(Gt,{size:16}),jsx("span",{children:"Upload File"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.insertGifFromUrl(),v(false);},children:[jsx(Qt,{size:16}),jsx("span",{children:"Insert GIF URL"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.insertGifFromFile(),v(false);},children:[jsx(Gt,{size:16}),jsx("span",{children:"Upload GIF"})]})]},"image"),n.imageSelected&&jsxs(vt,{trigger:jsx("button",{className:"luthor-toolbar-button",title:"Align Image",children:jsx(et,{size:16})}),isOpen:V,onOpenChange:g,children:[jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.setAlignment("left"),g(false);},children:[jsx(lt,{size:16}),jsx("span",{children:"Align Left"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.setAlignment("center"),g(false);},children:[jsx(et,{size:16}),jsx("span",{children:"Align Center"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.setAlignment("right"),g(false);},children:[jsx(at,{size:16}),jsx("span",{children:"Align Right"})]}),jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{m.setCaption(),g(false);},children:[jsx(zo,{size:16}),jsx("span",{children:"Set Caption"})]})]},"imageAlign")]}):null;case "emoji":return !t("emoji")||Oe.length===0?null:jsx(vt,{trigger:jsx("button",{className:"luthor-toolbar-button",title:"Insert Emoji",children:jsx(Qt,{size:16})}),isOpen:Z,onOpenChange:re,children:jsx("div",{className:"luthor-emoji-picker-grid",role:"listbox","aria-label":"Emoji picker",children:Oe.map(b=>jsx("button",{type:"button",className:"luthor-emoji-picker-item",title:b.shortcodes[0]?`${b.label} (:${b.shortcodes[0]}:)`:b.label,onClick:()=>{e.insertEmoji?.(b.emoji),re(false);},children:b.emoji},`${b.emoji}-${b.label}`))})},"emoji");case "embed":return P?jsxs(vt,{trigger:jsx("button",{className:`luthor-toolbar-button ${J?"active":""}`,title:"Insert Embed",children:jsx(Oo,{size:16})}),isOpen:F,onOpenChange:k,children:[t("iframeEmbed")?jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{w.insertIframe(),k(false);},children:[jsx(it,{size:16}),jsx("span",{children:"Embed iframe"})]}):null,t("youtubeEmbed")?jsxs("button",{className:"luthor-dropdown-item",onClick:()=>{w.insertYouTube(),k(false);},children:[jsx(Yt,{size:16}),jsx("span",{children:"Embed YouTube Video"})]}):null]},"embed"):null;case "undo":return t("history")?jsx(S,{onClick:()=>e.undo(),disabled:!n.canUndo,title:"Undo (Ctrl+Z)",children:jsx(Lo,{size:16})},"undo"):null;case "redo":return t("history")?jsx(S,{onClick:()=>e.redo(),disabled:!n.canRedo,title:"Redo (Ctrl+Y)",children:jsx(Io,{size:16})},"redo"):null;case "commandPalette":return jsx(S,{onClick:()=>r?.(),title:"Command Palette (Ctrl+Shift+P)",children:jsx(Bt,{size:16})},"commandPalette");case "themeToggle":return jsx(S,{onClick:l,title:o?"Light Mode":"Dark Mode",children:o?jsx(Bo,{size:16}):jsx(Mo,{size:16})},"themeToggle");default:return null}},q=u??It,Je=useMemo(()=>bi(q,t,C),[q,t,C]);return jsxs(Fragment,{children:[jsx("div",{className:a?.toolbar??"luthor-toolbar",style:c,children:Je.sections.map((f,b)=>{let O=f.items.map((A,le)=>{let ae=X(A);return ae?Array.isArray(ae)?ae.map((Q,Lt)=>Q&&typeof Q=="object"&&"key"in Q&&Q.key!=null?Q:jsx("span",{children:Q},`toolbar-item-${b}-${le}-${Lt}`)):ae.type===ni.Fragment?jsx("span",{children:ae},`toolbar-item-${b}-${le}`):ae&&typeof ae=="object"&&"key"in ae&&ae.key!=null?ae:jsx("span",{children:ae},`toolbar-item-${b}-${le}`):null}).flat().filter(A=>A!==null);return O.length===0?null:jsx("div",{className:a?.section??"luthor-toolbar-section",children:O},b)})}),jsx("input",{ref:h,type:"file",accept:"image/*",onChange:m.handleUpload,className:"luthor-file-input"}),jsx("input",{ref:U,type:"file",accept:"image/gif",onChange:m.handleGifUpload,className:"luthor-file-input"}),jsx(Zo,{isOpen:M,onClose:()=>H(false),title:"Insert Table",children:jsxs("div",{className:"luthor-table-dialog",children:[jsxs("div",{className:"luthor-form-group",children:[jsx("label",{htmlFor:"table-rows",children:"Rows:"}),jsx("input",{id:"table-rows",type:"number",min:"1",max:"20",value:G.rows,onChange:f=>Ee(b=>({...b,rows:parseInt(f.target.value)||1})),className:"luthor-input"})]}),jsxs("div",{className:"luthor-form-group",children:[jsx("label",{htmlFor:"table-columns",children:"Columns:"}),jsx("input",{id:"table-columns",type:"number",min:"1",max:"20",value:G.columns,onChange:f=>Ee(b=>({...b,columns:parseInt(f.target.value)||1})),className:"luthor-input"})]}),jsx("div",{className:"luthor-form-group",children:jsxs("label",{className:"luthor-checkbox-label",children:[jsx("input",{type:"checkbox",checked:G.includeHeaders||false,onChange:f=>Ee(b=>({...b,includeHeaders:f.target.checked})),className:"luthor-checkbox"}),"Include headers"]})}),jsxs("div",{className:"luthor-dialog-actions",children:[jsx(Xt,{variant:"secondary",onClick:()=>H(false),children:"Cancel"}),jsx(Xt,{variant:"primary",onClick:()=>{e.insertTable(G),H(false);},children:"Insert Table"})]})]})})]})}var go=["bold","italic","underline","strikethrough","fontFamily","fontSize","lineHeight","textColor","textHighlight","subscript","superscript","link","horizontalRule","table","list","history","image","blockFormat","code","codeIntelligence","codeFormat","tabIndent","enterKeyBehavior","iframeEmbed","youTubeEmbed","floatingToolbar","contextMenu","commandPalette","slashCommand","emoji","draggableBlock","customNode","themeToggle"],kn={bold:true,italic:true,underline:true,strikethrough:true,fontFamily:true,fontSize:true,lineHeight:true,textColor:true,textHighlight:true,subscript:true,superscript:true,link:true,horizontalRule:true,table:true,list:true,history:true,image:true,blockFormat:true,code:true,codeIntelligence:true,codeFormat:true,tabIndent:true,enterKeyBehavior:true,iframeEmbed:true,youTubeEmbed:true,floatingToolbar:true,contextMenu:true,commandPalette:true,slashCommand:true,emoji:true,draggableBlock:true,customNode:true,themeToggle:true};function xt(e){let t={...kn};if(!e)return t;for(let n of go)typeof e[n]=="boolean"&&(t[n]=e[n]);return t}function En(e,t){return e[t]!==false}var yn=[{value:"default",label:"Default",fontFamily:"inherit"},{value:"inter",label:"Inter",fontFamily:"'Inter', 'Segoe UI', Arial, sans-serif",cssImportUrl:"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"},{value:"merriweather",label:"Merriweather",fontFamily:"'Merriweather', Georgia, 'Times New Roman', serif",cssImportUrl:"https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&display=swap"},{value:"jetbrains-mono",label:"JetBrains Mono",fontFamily:"'JetBrains Mono', 'Courier New', monospace",cssImportUrl:"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap"}],qi={value:"default",label:"Default",fontFamily:"inherit"},vn=[{value:"default",label:"Default",fontSize:"inherit"},{value:"12",label:"12px",fontSize:"12px"},{value:"14",label:"14px",fontSize:"14px"},{value:"16",label:"16px",fontSize:"16px"},{value:"18",label:"18px",fontSize:"18px"},{value:"20",label:"20px",fontSize:"20px"},{value:"24",label:"24px",fontSize:"24px"},{value:"32",label:"32px",fontSize:"32px"}],Yi={value:"default",label:"Default",fontSize:"inherit"},Cn=[{value:"default",label:"Default",lineHeight:"1.5"},{value:"1",label:"1.0",lineHeight:"1"},{value:"1.15",label:"1.15",lineHeight:"1.15"},{value:"1.5",label:"1.5",lineHeight:"1.5"},{value:"1.75",label:"1.75",lineHeight:"1.75"},{value:"2",label:"2.0",lineHeight:"2"}],Gi={value:"default",label:"Default",lineHeight:"1.5"},Tt="1.5",Qi=1;function nt(e){return e.trim().toLowerCase()}function Tn(e){return /^[a-z0-9][a-z0-9-]*$/i.test(e)}function Wi(e){return nt(e)==="default"?true:_t(e)!==null}function Xi(e){let t=e??yn,n=new Set,o=[];for(let r of t){let i=r.value.trim(),a=r.label.trim(),c=r.fontFamily.trim();if(!i||!a||!c||!Tn(i))continue;let u=nt(i);n.has(u)||(n.add(u),o.push({value:i,label:a,fontFamily:c,cssImportUrl:r.cssImportUrl?.trim()||void 0}));}return o.length===0?yn:o.some(r=>nt(r.value)==="default")?o:[qi,...o]}function Zi(e){let t=e??vn,n=new Set,o=[];for(let r of t){let i=String(r.value).trim(),a=String(r.label).trim(),c=String(r.fontSize).trim();if(!i||!a||!c||!Tn(i))continue;let u=nt(i);n.has(u)||(n.add(u),o.push({value:i,label:a,fontSize:c}));}return o.length===0?vn:o.some(r=>nt(r.value)==="default")?o:[Yi,...o]}function _t(e){let t=e.trim();if(!/^\d*\.?\d+$/.test(t))return null;let n=Number(t);return !Number.isFinite(n)||n<Qi?null:n.toString()}function el(e){return typeof e=="number"?Number.isFinite(e)?_t(e.toString())??Tt:Tt:typeof e=="string"?_t(e)??Tt:Tt}function tl(e,t=Tt){let n=e??Cn,o=new Set,l=[];for(let i of n){let a=String(i.value).trim(),c=String(i.label).trim();if(!a||!c||!Wi(a))continue;let u=nt(a);if(o.has(u))continue;if(u==="default"){o.add(u),l.push({value:a,label:c,lineHeight:t});continue}let C=_t(String(i.lineHeight));C&&(o.add(u),l.push({value:a,label:c,lineHeight:C}));}return l.length===0?Cn:l.some(i=>nt(i.value)==="default")?l:[{...Gi,lineHeight:t},...l]}function Qe({children:e}){return jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e})}var ol=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M3.5 11h17"}),jsx("path",{d:"M10.5 14.5h3"}),jsx("path",{d:"M12 2.8v4.4"}),jsx("path",{d:"M9.8 5h4.4"})]}),nl=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M3.5 11h17"}),jsx("path",{d:"M10.5 8.5h3"}),jsx("path",{d:"M12 16.8v4.4"}),jsx("path",{d:"M9.8 19h4.4"})]}),rl=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M11.5 5v14"}),jsx("path",{d:"M7.5 10.5v3"}),jsx("path",{d:"M2.8 12h4.4"}),jsx("path",{d:"M5 9.8v4.4"})]}),il=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M12.5 5v14"}),jsx("path",{d:"M16.5 10.5v3"}),jsx("path",{d:"M16.8 12h4.4"}),jsx("path",{d:"M19 9.8v4.4"})]}),ll=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M3.5 11h17"}),jsx("path",{d:"M9.8 14.8l4.4 4.4"}),jsx("path",{d:"M14.2 14.8l-4.4 4.4"})]}),al=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M12 5v14"}),jsx("path",{d:"M14.8 9.8l4.4 4.4"}),jsx("path",{d:"M19.2 9.8l-4.4 4.4"})]}),sl=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M3.5 10.5h17"}),jsx("path",{d:"M10.5 5v14"}),jsx("path",{d:"M14.8 9.8l4.4 4.4"}),jsx("path",{d:"M19.2 9.8l-4.4 4.4"})]}),ul=()=>jsxs(Qe,{children:[jsx("rect",{x:"3.5",y:"5",width:"17",height:"14",rx:"1.5"}),jsx("path",{d:"M3.5 10.5h17"}),jsx("path",{d:"M10.5 5v14"}),jsx("path",{d:"M3.5 8h17"})]}),Vt=new ImageExtension;Vt.config={...Vt.config,uploadHandler:async e=>URL.createObjectURL(e),defaultAlignment:"center",resizable:true,pasteListener:{insert:true,replace:true},debug:false};var io=new TableExtension;io.config={...io.config,enableContextMenu:true,tableBubbleRenderer:({headersEnabled:e,setHeadersEnabled:t,actions:n})=>jsxs(Fragment,{children:[jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Insert row above","aria-label":"Insert row above",onClick:n.insertRowAbove,children:jsx(ol,{})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Insert row below","aria-label":"Insert row below",onClick:n.insertRowBelow,children:jsx(nl,{})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Insert column left","aria-label":"Insert column left",onClick:n.insertColumnLeft,children:jsx(rl,{})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Insert column right","aria-label":"Insert column right",onClick:n.insertColumnRight,children:jsx(il,{})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Delete selected row","aria-label":"Delete selected row",onClick:n.deleteSelectedRow,children:jsx(ll,{})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon",title:"Delete selected column","aria-label":"Delete selected column",onClick:n.deleteSelectedColumn,children:jsx(al,{})}),jsx("label",{className:"luthor-table-bubble-checkbox",title:"Use first row as table headers",children:jsx("button",{type:"button",className:`luthor-table-bubble-button luthor-table-bubble-button-icon${e?" luthor-table-bubble-button-active":""}`,title:"Use first row as table headers","aria-label":"Use first row as table headers","aria-pressed":e,onClick:()=>t(!e),children:jsx(ul,{})})}),jsx("button",{type:"button",className:"luthor-table-bubble-button luthor-table-bubble-button-icon luthor-table-bubble-button-danger",title:"Delete table","aria-label":"Delete table",onClick:n.deleteTable,children:jsx(sl,{})})]})};var lo=new IframeEmbedExtension;lo.config={...lo.config,defaultWidth:720,defaultHeight:405,defaultAlignment:"center"};var ao=new YouTubeEmbedExtension;ao.config={...ao.config,defaultWidth:720,defaultHeight:405,defaultAlignment:"center",nocookie:true,controls:true,rel:1};var cl=tn(),so=new ContextMenuExtension;so.config={...so.config,preventDefault:true};var dl=new CommandPaletteExtension,gl=new SlashCommandExtension,ml=new EmojiExtension,uo=new DraggableBlockExtension;uo.config={...uo.config,buttonStackPosition:"left"};var co=new LinkExtension;co.config={...co.config,linkSelectedTextOnPaste:true,autoLinkText:true,autoLinkUrls:true};var fl=textColorExtension.configure({options:[{value:"default",label:"Default",color:"inherit"},{value:"slate",label:"Slate",color:"#334155"},{value:"red",label:"Red",color:"#dc2626"},{value:"orange",label:"Orange",color:"#ea580c"},{value:"green",label:"Green",color:"#16a34a"},{value:"blue",label:"Blue",color:"#2563eb"},{value:"purple",label:"Purple",color:"#7c3aed"}]}),hl=textHighlightExtension.configure({options:[{value:"default",label:"Default",backgroundColor:"transparent"},{value:"yellow",label:"Yellow",backgroundColor:"#fef08a"},{value:"green",label:"Green",backgroundColor:"#bbf7d0"},{value:"blue",label:"Blue",backgroundColor:"#bfdbfe"},{value:"pink",label:"Pink",backgroundColor:"#fbcfe8"},{value:"orange",label:"Orange",backgroundColor:"#fed7aa"}]}),{extension:pl}=createCustomNodeExtension({nodeType:"featureCard",defaultPayload:{title:"Headless Custom Node",description:"This block is rendered by createCustomNodeExtension from @lyfie/luthor-headless.",tag:"Custom"},render:({payload:e,isSelected:t})=>jsxs("aside",{className:`luthor-extensive-feature-card${t?" is-selected":""}`,children:[jsx("div",{className:"luthor-extensive-feature-card__tag",children:e.tag??"Custom"}),jsx("h4",{className:"luthor-extensive-feature-card__title",children:e.title??"Custom Node"}),jsx("p",{className:"luthor-extensive-feature-card__description",children:e.description??"Insert strongly typed custom content blocks."})]})});function xn({fontFamilyOptions:e,fontSizeOptions:t,lineHeightOptions:n,minimumDefaultLineHeight:o,featureFlags:l,isDraggableBoxEnabled:r,scaleByRatio:i,syntaxHighlighting:a,codeHighlightProvider:c,loadCodeHighlightProvider:u,maxAutoDetectCodeLength:C,isCopyAllowed:d,languageOptions:p}={}){let m=xt(l),h=Z=>En(m,Z),U=(r??true)&&h("draggableBlock"),w=el(o),P=new FontFamilyExtension().configure({options:Xi(e),cssLoadStrategy:"on-demand"}),J=new FontSizeExtension().configure({options:Zi(t)}),j=new LineHeightExtension().configure({options:tl(n,w),defaultLineHeight:w});Vt.configure({scaleByRatio:i??false}),codeExtension.configure({syntaxHighlighting:a??"auto",provider:c??void 0,loadProvider:u}),codeIntelligenceExtension.configure({provider:c??void 0,loadProvider:u,maxAutoDetectLength:C,isCopyAllowed:d??true,languageOptions:p});let v=[];return h("bold")&&v.push(boldExtension),h("italic")&&v.push(italicExtension),h("underline")&&v.push(underlineExtension),h("strikethrough")&&v.push(strikethroughExtension),h("fontFamily")&&v.push(P),h("fontSize")&&v.push(J),h("lineHeight")&&v.push(j),h("textColor")&&v.push(fl),h("textHighlight")&&v.push(hl),h("subscript")&&v.push(subscriptExtension),h("superscript")&&v.push(superscriptExtension),h("link")&&v.push(co),h("horizontalRule")&&v.push(horizontalRuleExtension),h("table")&&v.push(io),h("list")&&v.push(listExtension),h("history")&&v.push(historyExtension),h("image")&&v.push(Vt),h("blockFormat")&&v.push(blockFormatExtension),h("code")&&v.push(codeExtension),h("codeIntelligence")&&v.push(codeIntelligenceExtension),h("codeFormat")&&v.push(codeFormatExtension),h("tabIndent")&&v.push(tabIndentExtension),h("enterKeyBehavior")&&v.push(enterKeyBehaviorExtension),h("iframeEmbed")&&v.push(lo),h("youTubeEmbed")&&v.push(ao),h("floatingToolbar")&&v.push(cl),h("contextMenu")&&v.push(so),h("commandPalette")&&v.push(dl),h("slashCommand")&&v.push(gl),h("emoji")&&v.push(ml),U&&v.push(uo),h("customNode")&&v.push(pl),v}function St(e){return xn(e)}xn();function Sn(e){if(!e)return "__default__";let t=Object.entries(e).filter(([,n])=>typeof n=="string"&&n.trim().length>0).sort(([n],[o])=>n.localeCompare(o));return t.length>0?JSON.stringify(t):"__default__"}function Ln(e){if(!e)return;let t={},n=(o,l)=>{typeof l=="string"&&l.trim().length>0&&(t[o]=l.trim());};return n("--luthor-fg",e.font?.color),n("--luthor-text-bold-color",e.font?.boldColor),n("--luthor-link-color",e.link?.color),n("--luthor-list-marker-color",e.list?.markerColor),n("--luthor-list-checkbox-color",e.list?.checkboxColor),n("--luthor-quote-bg",e.quote?.backgroundColor),n("--luthor-quote-fg",e.quote?.color),n("--luthor-quote-border",e.quote?.indicatorColor),n("--luthor-table-border-color",e.table?.borderColor),n("--luthor-table-header-bg",e.table?.headerBackgroundColor),n("--luthor-hr-color",e.hr?.color),n("--luthor-placeholder-color",e.placeholder?.color),n("--luthor-codeblock-bg",e.codeblock?.backgroundColor),n("--luthor-toolbar-bg",e.toolbar?.backgroundColor),Object.keys(t).length>0?t:void 0}function In(e){if(!(e instanceof Element))return false;if(e.closest('[contenteditable="true"]'))return true;let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function Fn(e,t){if(e.key.toLowerCase()!==t.key.toLowerCase())return false;let n=e.ctrlKey||e.metaKey;return !(!!t.requiresPrimary!==n||!!t.shift!=!!e.shiftKey||!!t.alt!=!!e.altKey)}function wn(e,t,n){let o={...e??{}};for(let[l,r]of Object.entries(n))(Array.isArray(r)?r:[r]).some(c=>t[c]!==false)||(o[l]=false);return o}function Nn(e,t,n){let o={...e},l=(r,i)=>{t[r]===false&&i();};return l("bold",()=>{o.toggleBold=()=>{};}),l("italic",()=>{o.toggleItalic=()=>{};}),l("underline",()=>{o.toggleUnderline=()=>{};}),l("strikethrough",()=>{o.toggleStrikethrough=()=>{};}),l("codeFormat",()=>{o.formatText=()=>{};}),l("fontFamily",()=>{o.setFontFamily=()=>{},o.clearFontFamily=()=>{};}),l("fontSize",()=>{o.setFontSize=()=>{},o.clearFontSize=()=>{};}),l("lineHeight",()=>{o.setLineHeight=()=>{},o.clearLineHeight=()=>{};}),l("textColor",()=>{o.setTextColor=()=>{},o.clearTextColor=()=>{};}),l("textHighlight",()=>{o.setTextHighlight=()=>{},o.clearTextHighlight=()=>{};}),l("subscript",()=>{o.toggleSubscript=()=>{};}),l("superscript",()=>{o.toggleSuperscript=()=>{};}),l("link",()=>{o.insertLink=()=>{},o.removeLink=()=>{},o.updateLink=()=>false,o.getCurrentLink=async()=>null,o.getLinkByKey=async()=>null,o.updateLinkByKey=()=>false,o.removeLinkByKey=()=>false;}),l("blockFormat",()=>{o.toggleParagraph=()=>{},o.toggleHeading=()=>{},o.toggleQuote=()=>{},o.setTextAlignment=()=>{};}),l("code",()=>{o.toggleCodeBlock=()=>{};}),l("codeIntelligence",()=>{o.setCodeLanguage=()=>{},o.autoDetectCodeLanguage=async()=>null,o.copySelectedCodeBlock=async()=>false;}),l("list",()=>{o.toggleUnorderedList=()=>{},o.toggleOrderedList=()=>{},o.toggleCheckList=()=>{},o.indentList=()=>{},o.outdentList=()=>{};}),l("horizontalRule",()=>{o.insertHorizontalRule=()=>{};}),l("table",()=>{o.insertTable=()=>{};}),l("image",()=>{o.insertImage=()=>{},o.setImageAlignment=()=>{},o.setImageCaption=()=>{},o.getImageCaption=async()=>"";}),l("emoji",()=>{o.insertEmoji=()=>{},o.executeEmojiSuggestion=()=>false,o.closeEmojiSuggestions=()=>{},o.getEmojiSuggestions=()=>[],o.getEmojiCatalog=()=>[],o.resolveEmojiShortcode=()=>null,o.setEmojiCatalog=()=>{},o.setEmojiCatalogAdapter=()=>{},o.getEmojiCatalogAdapter=()=>({search:()=>[],resolveShortcode:()=>null,getAll:()=>[]});}),l("iframeEmbed",()=>{o.insertIframeEmbed=()=>{},o.setIframeEmbedAlignment=()=>{},o.resizeIframeEmbed=()=>{},o.setIframeEmbedCaption=()=>{},o.getIframeEmbedCaption=async()=>"",o.updateIframeEmbedUrl=()=>false,o.getIframeEmbedUrl=async()=>"";}),l("youTubeEmbed",()=>{o.insertYouTubeEmbed=()=>{},o.setYouTubeEmbedAlignment=()=>{},o.resizeYouTubeEmbed=()=>{},o.setYouTubeEmbedCaption=()=>{},o.getYouTubeEmbedCaption=async()=>"",o.updateYouTubeEmbedUrl=()=>false,o.getYouTubeEmbedUrl=async()=>"";}),l("history",()=>{o.undo=()=>{},o.redo=()=>{};}),l("commandPalette",()=>{o.showCommandPalette=()=>{},o.hideCommandPalette=()=>{},o.registerCommand=()=>{},o.unregisterCommand=()=>{};}),l("slashCommand",()=>{o.registerSlashCommand=()=>{},o.unregisterSlashCommand=()=>{},o.setSlashCommands=()=>{},o.closeSlashMenu=()=>{},o.executeSlashCommand=()=>false;}),n&&(o.toggleBold=()=>{},o.toggleItalic=()=>{},o.toggleUnderline=()=>{},o.toggleStrikethrough=()=>{},o.formatText=()=>{},o.setFontFamily=()=>{},o.clearFontFamily=()=>{},o.setFontSize=()=>{},o.clearFontSize=()=>{},o.setLineHeight=()=>{},o.clearLineHeight=()=>{},o.setTextColor=()=>{},o.clearTextColor=()=>{},o.setTextHighlight=()=>{},o.clearTextHighlight=()=>{},o.toggleSubscript=()=>{},o.toggleSuperscript=()=>{},o.insertLink=()=>{},o.removeLink=()=>{},o.updateLink=()=>false,o.toggleParagraph=()=>{},o.toggleHeading=()=>{},o.toggleQuote=()=>{},o.setTextAlignment=()=>{},o.toggleUnorderedList=()=>{},o.toggleOrderedList=()=>{},o.toggleCheckList=()=>{},o.indentList=()=>{},o.outdentList=()=>{},o.insertHorizontalRule=()=>{},o.insertTable=()=>{},o.insertImage=()=>{},o.setImageAlignment=()=>{},o.setImageCaption=()=>{},o.insertIframeEmbed=()=>{},o.setIframeEmbedAlignment=()=>{},o.resizeIframeEmbed=()=>{},o.setIframeEmbedCaption=()=>{},o.updateIframeEmbedUrl=()=>false,o.insertYouTubeEmbed=()=>{},o.setYouTubeEmbedAlignment=()=>{},o.resizeYouTubeEmbed=()=>{},o.setYouTubeEmbedCaption=()=>{},o.updateYouTubeEmbedUrl=()=>false),o}function On(e){return new Set(e)}function Hn(e,t){e.clear();for(let n of t)e.add(n);}function Pn(e,t){return e.has(t)}function zn(e,t){e.add(t);}var N=(e,t=0,n="")=>({type:"text",version:1,text:e,detail:0,format:t,mode:"normal",style:n}),ge=(e,t="",n=0)=>({type:"paragraph",version:1,format:t,indent:n,direction:null,children:e}),mo={root:{type:"root",version:1,format:"",indent:0,direction:null,children:[{type:"heading",version:1,tag:"h1",format:"",indent:0,direction:null,children:[N("Extensive Preset: JSONB-First Feature Showcase")]},ge([N("This starter content is now a native "),N("JSONB",1),N(" document that demonstrates visual editing without Markdown conversion.")]),{type:"heading",version:1,tag:"h2",format:"",indent:0,direction:null,children:[N("Inline formatting + typography")]},ge([N("Bold",1),N(" \u2022 "),N("Italic",2),N(" \u2022 "),N("Underline",8),N(" \u2022 "),N("Strikethrough",4),N(" \u2022 "),N("Inline Code",16),N(" \u2022 "),N("Subscript",32),N(" \u2022 "),N("Superscript",64)]),ge([N("Font family + size + color + highlight + line-height can be combined in one sentence.",0,"font-family: 'Inter', 'Segoe UI', Arial, sans-serif; font-size: 18px; line-height: 1.75; color: #2563eb; background-color: #bfdbfe;")]),{type:"paragraph",version:1,format:"center",indent:0,direction:null,children:[N("Centered paragraph with custom style",0,"font-size: 20px; color: #7c3aed;")]},{type:"paragraph",version:1,format:"right",indent:0,direction:null,children:[N("Right-aligned paragraph with highlight",128,"background-color: #fef08a;")]},{type:"quote",version:1,format:"",indent:0,direction:null,children:[N("\u201CEverything in this demo is persisted in JSONB and can round-trip via visual mode.\u201D")]},{type:"paragraph",version:1,format:"",indent:0,direction:null,children:[{type:"link",version:1,rel:"noreferrer",target:"_blank",title:"Luthor documentation",url:"https://github.com/facebook/lexical",format:"",indent:0,direction:null,children:[N("Example link node")]},N(" with regular sibling text and emoji support \u{1F389}\u{1F525}\u2705.")]},{type:"heading",version:1,tag:"h2",format:"",indent:0,direction:null,children:[N("Lists")]},{type:"list",version:1,listType:"bullet",start:1,tag:"ul",format:"",indent:0,direction:null,children:[{type:"listitem",version:1,value:1,format:"",indent:0,direction:null,children:[ge([N("Bullet item with styled text",0,"color: #16a34a;")])]},{type:"listitem",version:1,value:2,format:"",indent:0,direction:null,children:[ge([N("Nested formatting in lists",1),N(" works great.")])]}]},{type:"list",version:1,listType:"number",start:1,tag:"ol",format:"",indent:0,direction:null,children:[{type:"listitem",version:1,value:1,format:"",indent:0,direction:null,children:[ge([N("Numbered item 1")])]},{type:"listitem",version:1,value:2,format:"",indent:0,direction:null,children:[ge([N("Numbered item 2")])]}]},{type:"list",version:1,listType:"check",start:1,tag:"ul",format:"",indent:0,direction:null,children:[{type:"listitem",version:1,value:1,checked:true,format:"",indent:0,direction:null,children:[ge([N("Checked task item")])]},{type:"listitem",version:1,value:2,checked:false,format:"",indent:0,direction:null,children:[ge([N("Unchecked task item")])]}]},{children:[{detail:0,format:0,mode:"normal",style:"",text:"const",type:"code-highlight",version:1,highlightType:"keyword"},{detail:0,format:0,mode:"normal",style:"",text:" content ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:"=",type:"code-highlight",version:1,highlightType:"operator"},{detail:0,format:0,mode:"normal",style:"",text:" exportApi",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:"toJSON",type:"code-highlight",version:1,highlightType:"function"},{detail:0,format:0,mode:"normal",style:"",text:"(",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:")",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:";",type:"code-highlight",version:1,highlightType:"punctuation"},{type:"linebreak",version:1},{detail:0,format:0,mode:"normal",style:"",text:"await",type:"code-highlight",version:1,highlightType:"keyword"},{detail:0,format:0,mode:"normal",style:"",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:"saveToDatabase",type:"code-highlight",version:1,highlightType:"function"},{detail:0,format:0,mode:"normal",style:"",text:"(",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:"{",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:" jsonb",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:":",type:"code-highlight",version:1,highlightType:"operator"},{detail:0,format:0,mode:"normal",style:"",text:" content ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:"}",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:")",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:";",type:"code-highlight",version:1,highlightType:"punctuation"},{type:"linebreak",version:1},{detail:0,format:0,mode:"normal",style:"",text:"importApi",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:"fromJSON",type:"code-highlight",version:1,highlightType:"function"},{detail:0,format:0,mode:"normal",style:"",text:"(",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:"content",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"",text:")",type:"code-highlight",version:1,highlightType:"punctuation"},{detail:0,format:0,mode:"normal",style:"",text:";",type:"code-highlight",version:1,highlightType:"punctuation"}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript"},{type:"horizontalrule",version:1},{type:"featureCard",version:1,payload:{title:"Custom Node: Feature Card",description:"This block is rendered with createCustomNodeExtension and persists as structured payload.",tag:"Custom"},format:"",indent:0,direction:null,children:[]},{type:"image",version:1,src:"https://images.unsplash.com/photo-1461749280684-dccba630e2f6?auto=format&fit=crop&w=1200&q=80",alt:"Code editor on a laptop",caption:"Image node with caption, center alignment, and persisted dimensions.",alignment:"center",width:780,height:420},{type:"youtube-embed",version:1,src:"https://www.youtube.com/embed/dQw4w9WgXcQ",width:720,height:405,alignment:"center",start:0},{type:"iframe-embed",version:1,src:"https://example.com",width:720,height:405,alignment:"center",title:"Iframe embed example"},{type:"table",version:1,format:"",indent:0,direction:null,children:[{type:"tablerow",version:1,children:[{type:"tablecell",version:1,headerState:3,colSpan:1,rowSpan:1,width:240,backgroundColor:null,children:[ge([N("Feature")])]},{type:"tablecell",version:1,headerState:3,colSpan:1,rowSpan:1,width:320,backgroundColor:null,children:[ge([N("Status")])]}]},{type:"tablerow",version:1,children:[{type:"tablecell",version:1,headerState:0,colSpan:1,rowSpan:1,width:240,backgroundColor:null,children:[ge([N("Visual \u2194 JSONB switching")])]},{type:"tablecell",version:1,headerState:0,colSpan:1,rowSpan:1,width:320,backgroundColor:null,children:[ge([N("Round-trip ready \u2705")])]}]}]},ge([N("Use the toolbar, floating toolbar, slash commands (/), and command palette (Ctrl/Cmd+Shift+P) to explore the full preset.")])]}};JSON.stringify(mo);var{Provider:Il,useEditor:Fl}=createEditorSystem(),An="Write anything...",Rn="Enter JSONB document content...";function wl(e){let n=e.replace(/\r\n?/g,`
3
- `).trim().split(/\n{2,}/).map(l=>l.replace(/\s+/g," ").trim()).filter(l=>l.length>0);return {root:{type:"root",version:1,format:"",indent:0,direction:null,children:(n.length>0?n:[""]).map(l=>({type:"paragraph",version:1,format:"",indent:0,direction:null,children:[{type:"text",version:1,text:l,detail:0,format:0,mode:"normal",style:""}]}))}}}function Nl(e){try{let t=JSON.parse(e);return JSON.stringify(t)}catch{return JSON.stringify(wl(e))}}function Ol(e){return !e||e.length===0?"__default__":JSON.stringify(e.map(t=>({value:t.value.trim(),label:t.label.trim(),fontFamily:t.fontFamily.trim(),cssImportUrl:t.cssImportUrl?.trim()||""})))}function Hl(e){return !e||e.length===0?"__default__":JSON.stringify(e.map(t=>({value:String(t.value).trim(),label:String(t.label).trim(),fontSize:String(t.fontSize).trim()})))}function Pl(e){return !e||e.length===0?"__default__":JSON.stringify(e.map(t=>({value:String(t.value).trim(),label:String(t.label).trim(),lineHeight:String(t.lineHeight).trim()})))}function zl(e){if(typeof e=="number")return !Number.isFinite(e)||e<1?"1.5":e.toString();if(typeof e=="string"){let n=e.trim();if(n.length===0)return "1.5";let o=Number(n);return !Number.isFinite(o)||o<1?"1.5":o.toString()}return "1.5"}function fo(e){return Sn(e)}function Al(e){if(!e)return "__default__";if(Array.isArray(e))return JSON.stringify({mode:"append",values:e.map(o=>o.trim())});let t=e,n=Array.isArray(t.values)?t.values:[];return JSON.stringify({mode:t.mode??"append",values:n.map(o=>o.trim())})}function Rl(e){return Ln(e)}function Bl(e){let t=xt(e);return JSON.stringify(go.map(n=>[n,t[n]]))}function Bn(e){return In(e)}var Ml=[{feature:"bold",key:"b",requiresPrimary:true},{feature:"italic",key:"i",requiresPrimary:true},{feature:"underline",key:"u",requiresPrimary:true},{feature:"link",key:"k",requiresPrimary:true},{feature:"history",key:"z",requiresPrimary:true},{feature:"history",key:"y",requiresPrimary:true},{feature:"history",key:"z",requiresPrimary:true,shift:true},{feature:"commandPalette",key:"p",requiresPrimary:true,shift:true},{feature:"codeFormat",key:"`",requiresPrimary:true},{feature:"code",key:"`",requiresPrimary:true,shift:true},{feature:"list",key:"l",requiresPrimary:true,shift:true},{feature:"list",key:"l",requiresPrimary:true,alt:true},{feature:"list",key:"x",requiresPrimary:true,shift:true},{feature:"blockFormat",key:"0",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"1",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"2",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"3",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"4",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"5",requiresPrimary:true,alt:true},{feature:"blockFormat",key:"6",requiresPrimary:true,alt:true}];function Dl(e,t){return Fn(e,t)}function Kl(e,t,n){return Nn(e,t,n)}var Ul={fontFamily:"fontFamily",fontSize:"fontSize",lineHeight:"lineHeight",textColor:"textColor",textHighlight:"textHighlight",bold:"bold",italic:"italic",underline:"underline",strikethrough:"strikethrough",subscript:"subscript",superscript:"superscript",code:"codeFormat",link:"link",blockFormat:"blockFormat",quote:"blockFormat",alignLeft:"blockFormat",alignCenter:"blockFormat",alignRight:"blockFormat",alignJustify:"blockFormat",codeBlock:"code",unorderedList:"list",orderedList:"list",checkList:"list",indentList:"list",outdentList:"list",horizontalRule:"horizontalRule",table:"table",image:"image",emoji:"emoji",embed:["iframeEmbed","youTubeEmbed"],undo:"history",redo:"history",commandPalette:"commandPalette",themeToggle:"themeToggle"};function jl(e,t){return wn(e,t,Ul)}function _l(e){if(!e||e.length===0)return [...Te];let t=new Set,n=[];for(let o of e)!Te.includes(o)||t.has(o)||(t.add(o),n.push(o));return n.length>0?n:[...Te]}function Vl(e){if(!e)return "__default__";if(Array.isArray(e)){let r=new Set,i=[];for(let a of e)for(let[c,u]of Object.entries(a)){let C=c.trim();!u||!C||r.has(C)||(r.add(C),i.push(C));}return i.length===0?"__default__":JSON.stringify({allowlist:i,denylist:[]})}let t=r=>{if(!r||r.length===0)return [];let i=new Set,a=[];for(let c of r){let u=c.trim();!u||i.has(u)||(i.add(u),a.push(u));}return a},n=e,o=t(n.allowlist),l=t(n.denylist);return o.length===0&&l.length===0?"__default__":JSON.stringify({allowlist:o,denylist:l})}function $l(e){if(!e||e.length===0)return [];let t=new Set,n=[];for(let o of e){let l=o.trim();!l||t.has(l)||(t.add(l),n.push(l));}return n}function Jl(e,t){return e.key.toLowerCase()===t.key.toLowerCase()&&!!e.ctrlKey==!!t.ctrlKey&&!!e.metaKey==!!t.metaKey&&!!e.shiftKey==!!t.shiftKey&&!!e.altKey==!!t.altKey}function ql(e){if(!e)return "__default__";let t=Array.isArray(e.disabledCommandIds)?[...e.disabledCommandIds].map(o=>o.trim()).filter(o=>o.length>0).sort((o,l)=>o.localeCompare(l)):[],n=e.bindings?Object.entries(e.bindings).map(([o,l])=>{if(l===false||l===null)return [o,false];let i=(Array.isArray(l)?l:[l]).map(a=>({key:a.key.trim(),ctrlKey:!!a.ctrlKey,metaKey:!!a.metaKey,shiftKey:!!a.shiftKey,altKey:!!a.altKey,preventDefault:a.preventDefault})).filter(a=>a.key.length>0).sort((a,c)=>{let u=`${a.key}:${a.ctrlKey?1:0}:${a.metaKey?1:0}:${a.shiftKey?1:0}:${a.altKey?1:0}`,C=`${c.key}:${c.ctrlKey?1:0}:${c.metaKey?1:0}:${c.shiftKey?1:0}:${c.altKey?1:0}`;return u.localeCompare(C)});return i.length===0?[o,false]:[o,i]}).sort(([o],[l])=>o.localeCompare(l)):[];return JSON.stringify({disabledCommandIds:t,bindings:n,preventCollisions:e.preventCollisions!==false,preventNativeConflicts:e.preventNativeConflicts!==false})}function Yl({isDark:e,toggleTheme:t,visualPlaceholder:n,jsonbPlaceholder:o,initialMode:l,availableModes:r,onReady:i,toolbarLayout:a,toolbarVisibility:c,toolbarPosition:u,toolbarAlignment:C,toolbarClassName:d,toolbarStyleVars:p,isToolbarEnabled:m,headingOptions:h,paragraphLabel:U,syncHeadingOptionsWithCommands:w,slashCommandVisibility:P,shortcutConfig:J,commandPaletteShortcutOnly:j,featureFlags:v}){let{commands:Z,hasExtension:re,activeStates:V,lexical:g,extensions:F,export:k,import:M}=Fl(),[H,W]=useState(l),[z,me]=useState({jsonb:""}),[te,xe]=useState(null),[ie,Se]=useState(null),[Le,Ie]=useState({isOpen:false,commands:[]}),[se,Fe]=useState({isOpen:false,query:"",position:null,commands:[]}),[Pe,we]=useState({isOpen:false,query:"",position:null,suggestions:[]}),ue=useRef(false),Ne=useMemo(()=>_l(h),[h]),fe=w?Ne:void 0,ce=w?U:void 0,I=V.isInCodeBlock===true,L=useMemo(()=>Kl(Z,v,I),[Z,v,I]),_=useMemo(()=>y=>Object.prototype.hasOwnProperty.call(v,y)?v[y]!==false:true,[v]),We=useMemo(()=>jl(c,v),[c,v]),he=v.draggableBlock!==false,Ce=Vl(P),je=useRef(P),ke=useRef(Ce),ze=ql(J),G=useRef(J),Ee=useRef(ze),Oe=useMemo(()=>$l(J?.disabledCommandIds),[J?.disabledCommandIds]),oe=useMemo(()=>new Set(Oe),[Oe]),pe=useMemo(()=>oe.size===0?[]:qt({headingOptions:fe,paragraphLabel:ce,isFeatureEnabled:_}).filter(y=>oe.has(y.id)).flatMap(y=>y.shortcuts??[]),[oe,fe,ce,_]);ke.current!==Ce&&(ke.current=Ce,je.current=P),Ee.current!==ze&&(Ee.current=ze,G.current=J);let Ae=useRef(On(["visual"])),R=useRef(0);useEffect(()=>{Zt(L,V,e?"dark":"light",_);},[L,V,e,_]);let He=useMemo(()=>({injectJSONB:y=>{setTimeout(()=>{try{let T=JSON.parse(y);M.fromJSON(T);}catch(T){console.error("Failed to inject JSONB:",T);return}},100);},getJSONB:()=>oo(JSON.stringify(k.toJSON()))}),[k,M]);useEffect(()=>{if(!g||!L)return;let y=L,T=ko(y,{headingOptions:fe,paragraphLabel:ce,isFeatureEnabled:_,shortcutConfig:G.current,commandPaletteShortcutOnly:j});typeof y.registerCommand=="function"&&T.forEach(q=>y.registerCommand(q));let D=Eo(y,{headingOptions:fe,paragraphLabel:ce,slashCommandVisibility:je.current,isFeatureEnabled:_,shortcutConfig:G.current});typeof y.setSlashCommands=="function"?y.setSlashCommands(D):D.forEach(q=>y.registerSlashCommand?.(q));let X=xo(y,document.body,{headingOptions:fe,paragraphLabel:ce,isFeatureEnabled:_,shortcutConfig:G.current,scope:()=>g.getRootElement()});return ue.current||(ue.current=true,i?.(He)),()=>{X(),typeof y.unregisterCommand=="function"&&T.forEach(q=>y.unregisterCommand(q.id)),typeof y.setSlashCommands=="function"?y.setSlashCommands([]):D.forEach(q=>y.unregisterSlashCommand?.(q.id));}},[g,L,He,i,fe,ce,Ce,ze,_,j]),useEffect(()=>{let y=()=>g?.getRootElement(),T=Ml.filter(X=>v[X.feature]===false);if(T.length===0)return;let D=X=>{let q=y();q&&X.target instanceof Node&&!q.contains(X.target)||!Bn(X.target)||!T.some(f=>Dl(X,f))||(X.preventDefault(),X.stopPropagation());};return document.addEventListener("keydown",D,true),()=>{document.removeEventListener("keydown",D,true);}},[g,v]),useEffect(()=>{let y=F.find(T=>T.name==="commandPalette");if(!(!y||!y.subscribe))return y.subscribe((T,D)=>{let X=D.filter(q=>oe.has(q.id)?false:j?typeof q.shortcut=="string"&&q.shortcut.trim().length>0:true);Ie({isOpen:T,commands:X});})},[F,oe,j]),useEffect(()=>{if(pe.length===0)return;let y=()=>g?.getRootElement(),T=D=>{let X=y();X&&D.target instanceof Node&&!X.contains(D.target)||!Bn(D.target)||!pe.some(Je=>Jl(D,Je))||(D.preventDefault(),D.stopPropagation());};return document.addEventListener("keydown",T,true),()=>{document.removeEventListener("keydown",T,true);}},[g,pe]),useEffect(()=>{let y=F.find(T=>T.name==="slashCommand");if(!(!y||!y.subscribe))return y.subscribe(T=>{Fe({isOpen:T.isOpen,query:T.query,position:T.position,commands:T.commands});})},[F]),useEffect(()=>{let y=F.find(T=>T.name==="emoji");if(!(!y||!y.subscribe))return y.subscribe(T=>{we({isOpen:T.isOpen,query:T.query,position:T.position,suggestions:T.suggestions});})},[F]),useEffect(()=>!g||!k?void 0:g.registerUpdateListener(()=>{R.current+=1,Hn(Ae.current,["visual"]);}),[g,k]);let Xe=async y=>{if(r.includes(y))try{if(Se(null),H==="jsonb"&&y!=="jsonb"){let T=JSON.parse(z.jsonb);M.fromJSON(T),await new Promise(D=>setTimeout(D,50));}if(H==="visual"&&y!=="visual"&&(g&&clearLexicalSelection(g),g?.getRootElement()?.blur()),W(y),y==="jsonb"&&H!=="jsonb"&&!Pn(Ae.current,"jsonb")){xe("jsonb"),await new Promise(T=>setTimeout(T,50));try{let T=oo(JSON.stringify(k.toJSON()));me(D=>({...D,jsonb:T})),zn(Ae.current,"jsonb");}finally{xe(null);}}y==="visual"&&setTimeout(()=>g?.focus(),100);}catch(T){let D=T instanceof Error?T.message:"Invalid format - could not parse content";Se({mode:H,error:D});}},_e=m?jsx(hn,{commands:L,hasExtension:y=>re(y),activeStates:V,isDark:e,toggleTheme:t,onCommandPaletteOpen:()=>{v.commandPalette!==false&&L.showCommandPalette();},imageUploadHandler:y=>F.find(T=>T.name==="image")?.config?.uploadHandler?.(y)??Promise.resolve(URL.createObjectURL(y)),layout:a??It,toolbarVisibility:We,toolbarStyleVars:p,headingOptions:Ne,paragraphLabel:U,classNames:{toolbar:`luthor-toolbar luthor-toolbar--align-${C}${d?` ${d}`:""}`}}):null,Ve=H==="visual"&&m&&u==="top",$e=H==="visual"&&m&&u==="bottom";return jsxs(Fragment,{children:[jsxs("div",{className:"luthor-editor-header",children:[jsx(un,{mode:H,onModeChange:Xe,availableModes:r,isConverting:te}),Ve&&jsx("div",{className:"luthor-editor-toolbar-slot luthor-editor-toolbar-slot--top",children:_e})]}),jsxs("div",{className:`luthor-editor${he?"":" luthor-editor--draggable-disabled"}`,"data-mode":H,children:[jsxs("div",{className:`luthor-editor-visual-shell${H==="visual"?"":" is-hidden"}${he?"":" luthor-editor-visual-shell--no-gutter"}`,"aria-hidden":H!=="visual",children:[he&&jsx("div",{className:"luthor-editor-visual-gutter","aria-hidden":"true"}),jsx(RichText,{placeholder:n,classNames:{container:"luthor-richtext-container luthor-preset-extensive__container",contentEditable:"luthor-content-editable luthor-preset-extensive__content",placeholder:"luthor-placeholder luthor-preset-extensive__placeholder"}})]}),H!=="visual"&&jsxs("div",{className:"luthor-source-panel",children:[ie&&ie.mode===H&&jsxs("div",{className:"luthor-source-error",children:[jsx("div",{className:"luthor-source-error-icon",children:"\u26A0\uFE0F"}),jsxs("div",{className:"luthor-source-error-message",children:[jsx("strong",{children:"Invalid JSONB"}),jsx("p",{children:ie.error}),jsx("small",{children:"Fix the errors above and try switching modes again"})]})]}),H==="jsonb"&&jsx(cn,{value:z.jsonb,onChange:y=>me(T=>({...T,jsonb:y})),placeholder:o})]})]}),jsx(sn,{editor:g,commands:L,editorTheme:e?"dark":"light",disabled:H!=="visual"}),$e&&jsx("div",{className:"luthor-editor-toolbar-slot luthor-editor-toolbar-slot--bottom",children:_e}),jsx(Jo,{isOpen:Le.isOpen,onClose:()=>L.hideCommandPalette(),commands:Le.commands}),jsx(Wo,{isOpen:se.isOpen,query:se.query,position:se.position,commands:se.commands,onClose:()=>L.closeSlashMenu?.(),onExecute:y=>{L.executeSlashCommand?.(y);}}),jsx(Yo,{isOpen:Pe.isOpen,query:Pe.query,position:Pe.position,suggestions:Pe.suggestions,onClose:()=>L.closeEmojiSuggestions?.(),onExecute:y=>{L.executeEmojiSuggestion?.(y);}})]})}var $t=forwardRef(({className:e,onReady:t,initialTheme:n="light",theme:o,defaultContent:l,showDefaultContent:r=true,placeholder:i=An,initialMode:a="visual",availableModes:c=["visual","jsonb"],variantClassName:u,toolbarLayout:C,toolbarVisibility:d,toolbarPosition:p="top",toolbarAlignment:m="left",toolbarClassName:h,toolbarStyleVars:U,quoteClassName:w,quoteStyleVars:P,defaultSettings:J,editorThemeOverrides:j,isToolbarEnabled:v=true,fontFamilyOptions:Z,fontSizeOptions:re,lineHeightOptions:V,minimumDefaultLineHeight:g=1.5,scaleByRatio:F=false,headingOptions:k,paragraphLabel:M,syncHeadingOptionsWithCommands:H=true,slashCommandVisibility:W,shortcutConfig:z,commandPaletteShortcutOnly:me=false,isDraggableBoxEnabled:te,featureFlags:xe,syntaxHighlighting:ie,codeHighlightProvider:Se,loadCodeHighlightProvider:Le,maxAutoDetectCodeLength:Ie,isCopyAllowed:se=true,languageOptions:Fe},Pe)=>{let[we,ue]=useState(n),Ne=we==="dark",fe=c.includes(a)?a:c[0]??"visual",ce=()=>ue(Ne?"light":"dark"),I=useMemo(()=>typeof i=="string"?{visual:i,jsonb:Rn}:{visual:i.visual??An,jsonb:i.jsonb??Rn},[i]);useEffect(()=>{ue(n);},[n]);let L=useMemo(()=>Ol(Z),[Z]),_=useMemo(()=>Hl(re),[re]),We=useMemo(()=>Pl(V),[V]),he=useMemo(()=>zl(g),[g]),Ce=ie??"unset",je=typeof Ie=="number"?Ie.toString():"unset",ke=useMemo(()=>Al(Fe),[Fe]),ze=se?"copy-on":"copy-off",G=useMemo(()=>typeof te!="boolean"?xe:{...xe??{},draggableBlock:te},[xe,te]),Ee=useMemo(()=>Bl(G),[G]),Oe=useMemo(()=>xt(G),[G]),oe=`${L}::${_}::${We}::${he}::${F?"ratio-on":"ratio-off"}::${Ce}::${je}::${ze}::${ke}::${Ee}`,pe=useRef(Z),Ae=useRef(re),R=useRef(V),He=useRef(g),Xe=useRef(G),_e=useRef(Fe),Ve=useRef(Se),$e=useRef(Le),y=useRef(oe);(y.current!==oe||Ve.current!==Se||$e.current!==Le)&&(y.current=oe,pe.current=Z,Ae.current=re,R.current=V,He.current=g,Xe.current=G,_e.current=Fe,Ve.current=Se,$e.current=Le);let T=useRef(null);if(!T.current||T.current.key!==oe){let Q={fontFamilyOptions:pe.current,fontSizeOptions:Ae.current,lineHeightOptions:R.current,minimumDefaultLineHeight:He.current,scaleByRatio:F,...ie!==void 0?{syntaxHighlighting:ie}:{},...Ve.current!==void 0?{codeHighlightProvider:Ve.current}:{},...$e.current!==void 0?{loadCodeHighlightProvider:$e.current}:{},...Ie!==void 0?{maxAutoDetectCodeLength:Ie}:{},isCopyAllowed:se,..._e.current!==void 0?{languageOptions:_e.current}:{},...typeof te=="boolean"?{isDraggableBoxEnabled:te}:{},...Xe.current?{featureFlags:Xe.current}:{}};T.current={key:oe,value:St(Q)};}let D=T.current.value,X=useMemo(()=>{let Q=mergeThemes(defaultLuthorTheme,o??{});return w?{...Q,quote:`${Q.quote??""} ${w}`.trim()}:Q},[o,w]),q=useMemo(()=>fo(j),[j]),Je=useMemo(()=>fo(P),[P]),f=useMemo(()=>Rl(J),[J]),b=useMemo(()=>fo(f),[f]),O=useMemo(()=>{let Q=f,Lt=createEditorThemeStyleVars(j),po=P,bo={"--luthor-default-line-height":he};return !Q&&!Lt&&!po?bo:{...Q??{},...Lt,...po??{},...bo}},[he,f,j,P,b,q,Je]),[A,le]=useState(null);useImperativeHandle(Pe,()=>A,[A]);let ae=Q=>{le(Q),r&&l===void 0?Q.injectJSONB(JSON.stringify(mo)):l&&Q.injectJSONB(Nl(l)),t?.(Q);};return jsx("div",{className:`luthor-preset luthor-preset-extensive luthor-editor-wrapper ${u||""} ${e||""}`.trim(),"data-editor-theme":we,style:O,children:jsx(Il,{extensions:D,config:{theme:X},children:jsx(Yl,{isDark:Ne,toggleTheme:ce,visualPlaceholder:I.visual,jsonbPlaceholder:I.jsonb,initialMode:fe,availableModes:c,onReady:ae,toolbarLayout:C,toolbarVisibility:d,toolbarPosition:p,toolbarAlignment:m,toolbarClassName:h,toolbarStyleVars:U,isToolbarEnabled:v,headingOptions:k,paragraphLabel:M,syncHeadingOptionsWithCommands:H,slashCommandVisibility:W,shortcutConfig:z,commandPaletteShortcutOnly:me,featureFlags:Oe})})})});$t.displayName="ExtensiveEditor";function ho({className:e,variantClassName:t,showTitle:n=true,title:o="",onTitleChange:l,showActions:r=true,onPin:i,onArchive:a,onColorChange:c,colorOptions:u=["#fef3c7","#dbeafe","#dcfce7"],...C}){return jsxs("div",{className:["luthor-preset-notes",e].filter(Boolean).join(" "),children:[n&&jsx("input",{"data-testid":"notes-title",className:"luthor-notes-title",placeholder:"Title",value:o,onChange:d=>l?.(d.target.value)}),r&&jsxs("div",{className:"luthor-notes-actions","data-testid":"notes-actions",children:[jsx("button",{type:"button",onClick:i,"aria-label":"Pin note",children:"Pin"}),jsx("button",{type:"button",onClick:a,"aria-label":"Archive note",children:"Archive"}),jsx("select",{"aria-label":"Change note color",onChange:d=>c?.(d.target.value),children:u.map(d=>jsx("option",{value:d,children:d},d))})]}),jsx($t,{...C,variantClassName:["luthor-preset-notes__variant",t].filter(Boolean).join(" "),featureFlags:{bold:true,italic:true,underline:true,strikethrough:false,link:true,list:true,blockFormat:false,table:false,image:false,iframeEmbed:false,youTubeEmbed:false,commandPalette:false,slashCommand:false,draggableBlock:false,customNode:false,emoji:false},isToolbarEnabled:false})]})}var Ql={id:"notes",label:"Notes",description:"Compact notes editor with title and actions.",extensions:St({featureFlags:{list:true,image:false,table:false,iframeEmbed:false,youTubeEmbed:false,commandPalette:false,slashCommand:false,draggableBlock:false,customNode:false}}),components:{Editor:ho},toolbar:[],config:dn("notes","Take a note..."),css:"notes/styles.css"};export{ho as NotesEditor,Ql as notesPreset};
1
+ export{a as NotesEditor,b as notesPreset}from'../../chunk-YA4LF3BW.js';import'../../chunk-5KKKDUJW.js';import'../../chunk-MDSRHDWB.js';