import{j as o}from"./query-PJ0ZdjbV.js";import{a as c,d as u,e as w}from"./vendor-CWhr2lg4.js";import{r as C,w as j}from"./with-selector-CmGJjsAK.js";import{a2 as l,cp as S,cq as E,cr as M,cs as A,ct as N,cu as R,ap as f,cv as _}from"./index-BSPIaiZU.js";import{d as D}from"./index-Dh4i1-J3.js";import{L as T}from"./list-ordered-Dn0jhaqK.js";import{L as I}from"./link-2-zJB3uZzB.js";import{U as L}from"./undo-2-CyjnlLm8.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const H=l("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const U=l("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const q=l("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const O=l("Bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const V=l("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const z=l("Heading2",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const B=l("Italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const P=l("List",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const F=l("Pilcrow",[["path",{d:"M13 4v16",key:"8vvj80"}],["path",{d:"M17 4v16",key:"7dpous"}],["path",{d:"M19 4H9.5a4.5 4.5 0 0 0 0 9H13",key:"sh4n9v"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const W=l("Quote",[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=l("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Q=l("Strikethrough",[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const K=l("Underline",[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]]);var v=C(),G=(...e)=>t=>{e.forEach(i=>{typeof i=="function"?i(t):i&&(i.current=t)})},J=({contentComponent:e})=>{const t=v.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot);return o.jsx(o.Fragment,{children:Object.values(t)})};function X(){const e=new Set;let t={},i=!1;const s=()=>{i||!e.size||(i=!0,queueMicrotask(()=>{i=!1,e.forEach(n=>n())}))};return{subscribe(n){return e.add(n),()=>{e.delete(n)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(n,r){t={...t,[n]:w.createPortal(r.reactElement,r.element,n)},s()},removeRenderer(n){const r={...t};delete r[n],t=r,s()}}}var Y=class extends u.Component{constructor(e){super(e),this.editorContentRef=u.createRef()}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){var e;const t=this.props.editor;if(t&&!t.isDestroyed&&((e=t.view.dom)!=null&&e.parentNode)){if(t.contentComponent)return;const i=this.editorContentRef.current;i.append(...t.view.dom.parentNode.childNodes),t.setOptions({element:i}),t.contentComponent=X(),t.createNodeViews(),t.isEditorContentInitialized=!0,this.forceUpdate()}}componentWillUnmount(){var e;const t=this.props.editor;if(t){t.isEditorContentInitialized=!1,t.isDestroyed||t.view.setProps({nodeViews:{}}),t.contentComponent=null;try{if(!((e=t.view.dom)!=null&&e.parentNode))return;const i=document.createElement("div");i.append(...t.view.dom.parentNode.childNodes),t.setOptions({element:i})}catch{}}}render(){const{editor:e,innerRef:t,...i}=this.props;return o.jsxs(o.Fragment,{children:[o.jsx("div",{ref:G(t,this.editorContentRef),...i}),(e==null?void 0:e.contentComponent)&&o.jsx(J,{contentComponent:e.contentComponent})]})}},Z=c.forwardRef((e,t)=>{const i=u.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return u.createElement(Y,{key:i,innerRef:t,...e})}),x=u.memo(Z),ee=typeof window<"u"?c.useLayoutEffect:c.useEffect,te=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let t;const i=n=>{(n==null?void 0:n.transaction)!==void 0&&n.transaction===t||(t=n==null?void 0:n.transaction,this.transactionNumber+=1,this.subscribers.forEach(r=>r()))},s=this.editor;return s.on("transaction",i),s.on("update",i),()=>{s.off("transaction",i),s.off("update",i)}}}};function ne(e){var t;const[i]=c.useState(()=>new te(e.editor)),s=j.useSyncExternalStoreWithSelector(i.subscribe,i.getSnapshot,i.getServerSnapshot,e.selector,(t=e.equalityFn)!=null?t:D);return ee(()=>i.watch(e.editor),[e.editor,i]),c.useDebugValue(s),s}var ie=!1,m=typeof window>"u",se=m||!!(typeof window<"u"&&window.next),re=class g{constructor(t){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId="",this.options=t,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(t){this.editor=t,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(i=>i())}getInitialEditor(){const t=this.options.current.immediatelyRender;let i=t??!0;return m?(i&&ie&&console.warn("SSR detected. `immediatelyRender` has been set to false to avoid hydration mismatches"),i=!1):se&&t===void 0&&(i=!1),i?this.createEditor():null}createEditor(){const t={...this.options.current,onBeforeCreate:(...s)=>{var n,r;return(r=(n=this.options.current).onBeforeCreate)==null?void 0:r.call(n,...s)},onBlur:(...s)=>{var n,r;return(r=(n=this.options.current).onBlur)==null?void 0:r.call(n,...s)},onCreate:(...s)=>{var n,r;return(r=(n=this.options.current).onCreate)==null?void 0:r.call(n,...s)},onDestroy:(...s)=>{var n,r;return(r=(n=this.options.current).onDestroy)==null?void 0:r.call(n,...s)},onFocus:(...s)=>{var n,r;return(r=(n=this.options.current).onFocus)==null?void 0:r.call(n,...s)},onSelectionUpdate:(...s)=>{var n,r;return(r=(n=this.options.current).onSelectionUpdate)==null?void 0:r.call(n,...s)},onTransaction:(...s)=>{var n,r;return(r=(n=this.options.current).onTransaction)==null?void 0:r.call(n,...s)},onUpdate:(...s)=>{var n,r;return(r=(n=this.options.current).onUpdate)==null?void 0:r.call(n,...s)},onContentError:(...s)=>{var n,r;return(r=(n=this.options.current).onContentError)==null?void 0:r.call(n,...s)},onDrop:(...s)=>{var n,r;return(r=(n=this.options.current).onDrop)==null?void 0:r.call(n,...s)},onPaste:(...s)=>{var n,r;return(r=(n=this.options.current).onPaste)==null?void 0:r.call(n,...s)},onDelete:(...s)=>{var n,r;return(r=(n=this.options.current).onDelete)==null?void 0:r.call(n,...s)},onMount:(...s)=>{var n,r;return(r=(n=this.options.current).onMount)==null?void 0:r.call(n,...s)},onUnmount:(...s)=>{var n,r;return(r=(n=this.options.current).onUnmount)==null?void 0:r.call(n,...s)}};return new S(t)}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(t){return this.subscriptions.add(t),()=>{this.subscriptions.delete(t)}}static compareOptions(t,i){return Object.keys(t).every(s=>["onCreate","onBeforeCreate","onDestroy","onUpdate","onTransaction","onFocus","onBlur","onSelectionUpdate","onContentError","onDrop","onPaste"].includes(s)?!0:s==="extensions"&&t.extensions&&i.extensions?t.extensions.length!==i.extensions.length?!1:t.extensions.every((n,r)=>{var p;return n===((p=i.extensions)==null?void 0:p[r])}):t[s]===i[s])}onRender(t){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&t.length===0?g.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(t),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(t){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=t;return}if(this.previousDeps.length===t.length&&this.previousDeps.every((s,n)=>s===t[n]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=t}scheduleDestroy(){const t=this.instanceId,i=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===t){i&&i.setOptions(this.options.current);return}i&&!i.isDestroyed&&(i.destroy(),this.instanceId===t&&this.setEditor(null))},1)}};function oe(e={},t=[]){const i=c.useRef(e);i.current=e;const[s]=c.useState(()=>new re(i)),n=v.useSyncExternalStore(s.subscribe,s.getEditor,s.getServerSnapshot);return c.useDebugValue(n),c.useEffect(s.onRender(t)),ne({editor:n,selector:({transactionNumber:r})=>e.shouldRerenderOnTransaction===!1||e.shouldRerenderOnTransaction===void 0?null:e.immediatelyRender&&r===0?0:r+1}),n}var y=c.createContext({editor:null});y.Consumer;var ae=c.createContext({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),ce=()=>c.useContext(ae);u.forwardRef((e,t)=>{const{onDragStart:i}=ce(),s=e.as||"div";return o.jsx(s,{...e,ref:t,"data-node-view-wrapper":"",onDragStart:i,style:{whiteSpace:"normal",...e.style}})});u.createContext({markViewContentRef:()=>{}});var h=c.createContext({get editor(){throw new Error("useTiptap must be used within a <Tiptap> provider")}});h.displayName="TiptapContext";var le=()=>c.useContext(h);function b({children:e,...t}){const i="editor"in t?t.editor:t.instance;if(!i)throw new Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");const s=c.useMemo(()=>({editor:i}),[i]),n=c.useMemo(()=>({editor:i}),[i]);return o.jsx(y.Provider,{value:n,children:o.jsx(h.Provider,{value:s,children:e})})}b.displayName="Tiptap";function k({...e}){const{editor:t}=le();return o.jsx(x,{editor:t,...e})}k.displayName="Tiptap.Content";Object.assign(b,{Content:k});var ue=E;function a({onClick:e,isActive:t=!1,disabled:i=!1,title:s,children:n}){return o.jsx("button",{type:"button",onClick:e,disabled:i,title:s,className:f("flex h-7 w-7 items-center justify-center rounded-md transition-colors",t?"bg-slate-200 text-slate-800":"text-slate-500 hover:bg-slate-100 hover:text-slate-700",i&&"opacity-40 cursor-not-allowed"),children:n})}function d(){return o.jsx("div",{className:"mx-0.5 h-5 w-px bg-slate-200"})}function de({editor:e}){const t=()=>{const i=e.getAttributes("link").href??"",s=window.prompt("URL",i);if(s!==null){if(s===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:s}).run()}};return o.jsxs("div",{className:"flex flex-wrap items-center gap-0.5 border-b border-slate-200 bg-slate-50/60 px-2 py-1.5",children:[o.jsx(a,{onClick:()=>e.chain().focus().toggleBold().run(),isActive:e.isActive("bold"),title:"Bold",children:o.jsx(O,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),title:"Italic",children:o.jsx(B,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),title:"Underline",children:o.jsx(K,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),title:"Strikethrough",children:o.jsx(Q,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleCode().run(),isActive:e.isActive("code"),title:"Inline Code",children:o.jsx(V,{className:"h-3.5 w-3.5"})}),o.jsx(d,{}),o.jsx(a,{onClick:()=>e.chain().focus().setParagraph().run(),isActive:e.isActive("paragraph"),title:"Paragraph",children:o.jsx(F,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),isActive:e.isActive("heading",{level:2}),title:"Heading",children:o.jsx(z,{className:"h-3.5 w-3.5"})}),o.jsx(d,{}),o.jsx(a,{onClick:()=>e.chain().focus().toggleBulletList().run(),isActive:e.isActive("bulletList"),title:"Bullet List",children:o.jsx(P,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleOrderedList().run(),isActive:e.isActive("orderedList"),title:"Ordered List",children:o.jsx(T,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().toggleBlockquote().run(),isActive:e.isActive("blockquote"),title:"Blockquote",children:o.jsx(W,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().setHorizontalRule().run(),title:"Horizontal Rule",children:o.jsx(_,{className:"h-3.5 w-3.5"})}),o.jsx(d,{}),o.jsx(a,{onClick:()=>e.chain().focus().setTextAlign("left").run(),isActive:e.isActive({textAlign:"left"}),title:"Align Left",children:o.jsx(U,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().setTextAlign("center").run(),isActive:e.isActive({textAlign:"center"}),title:"Align Center",children:o.jsx(H,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().setTextAlign("right").run(),isActive:e.isActive({textAlign:"right"}),title:"Align Right",children:o.jsx(q,{className:"h-3.5 w-3.5"})}),o.jsx(d,{}),o.jsx(a,{onClick:t,isActive:e.isActive("link"),title:"Insert Link",children:o.jsx(I,{className:"h-3.5 w-3.5"})}),o.jsx("div",{className:"flex-1"}),o.jsx(a,{onClick:()=>e.chain().focus().undo().run(),disabled:!e.can().undo(),title:"Undo",children:o.jsx(L,{className:"h-3.5 w-3.5"})}),o.jsx(a,{onClick:()=>e.chain().focus().redo().run(),disabled:!e.can().redo(),title:"Redo",children:o.jsx($,{className:"h-3.5 w-3.5"})})]})}function be({value:e,onChange:t,placeholder:i,className:s}){const n=oe({extensions:[A.configure({heading:{levels:[2,3]}}),ue.configure({placeholder:i??"Start typing..."}),N.configure({openOnClick:!1,HTMLAttributes:{class:"text-blue-600 underline"}}),M,R.configure({types:["heading","paragraph"]})],content:e,onUpdate:({editor:r})=>{t(r.getHTML())},editorProps:{attributes:{class:"prose prose-sm max-w-none focus:outline-none min-h-[140px] px-3 py-2 text-[13px] text-slate-700"}}});return n?o.jsxs("div",{className:f("rounded-md border border-input bg-white overflow-hidden focus-within:ring-2 focus-within:ring-primary/20 focus-within:border-primary/40 transition-colors",s),children:[o.jsx(de,{editor:n}),o.jsx(x,{editor:n})]}):null}export{be as R};
