@wair/editor 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ 'use client';
2
+ "use client";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@tiptap/react`),l=require(`react`);l=s(l);let u=require(`react/jsx-runtime`),d=require(`lucide-react`),f=require(`@radix-ui/react-toggle`);f=s(f);let p=require(`class-variance-authority`),m=require(`clsx`),h=require(`tailwind-merge`),g=require(`@radix-ui/react-tooltip`);g=s(g);let _=require(`@/lib/utils`),v=require(`@radix-ui/react-slot`),y=require(`@radix-ui/react-popover`);y=s(y);let b=require(`@radix-ui/react-label`);b=s(b);let x=require(`@radix-ui/react-separator`);x=s(x);let S=require(`@tiptap/starter-kit`);S=s(S);let C=require(`@tiptap/extension-text-style`),w=require(`@tiptap/extension-text-align`);w=s(w);let T=require(`@tiptap/extensions`),E=require(`@tiptap/extension-list`),D=require(`@tiptap/extension-file-handler`);D=s(D);let O=require(`@tiptap/extension-code-block-lowlight`);O=s(O);let ee=require(`lowlight`),k=require(`copy-to-clipboard`);k=s(k);let A=require(`@radix-ui/react-dropdown-menu`);A=s(A);let te=require(`@tiptap/extension-image`),ne=require(`react-medium-image-zoom`),re=require(`react-cropper`),j=require(`@radix-ui/react-dialog`);j=s(j),require(`react-medium-image-zoom/dist/styles.css`);let M=require(`highlight.js/lib/languages/css`);M=s(M);let ie=require(`highlight.js/lib/languages/javascript`);ie=s(ie);let ae=require(`highlight.js/lib/languages/typescript`);ae=s(ae);let oe=require(`highlight.js/lib/languages/xml`);oe=s(oe),require(`highlight.js/styles/github.css`);let N=require(`@tiptap/core`),se=require(`@tiptap/extension-link`);se=s(se);let P=require(`@tiptap/pm/state`),F=require(`@tiptap/extension-table`),I=require(`@tiptap/pm/view`),L=require(`@tiptap/pm/tables`),ce=require(`@tiptap/extension-mathematics`),le=require(`@tiptap/react/menus`),ue=require(`@floating-ui/react`),de=require(`@tiptap/extension-drag-handle-react`);const fe=(0,l.createContext)({}),R=()=>{let e=(0,l.useContext)(fe);if(!e)throw Error(`useCurrentEditor 必须在 EditorProvider 内部使用`);if(!e.editor)throw Error(`EditorProvider 未提供 editor`);return e},pe=({editor:e,children:t})=>e?(0,u.jsx)(fe.Provider,{value:{editor:e},children:t}):null,me={1:d.Heading1,2:d.Heading2,3:d.Heading3,4:d.Heading4,5:d.Heading5,6:d.Heading6},z=e=>({label:`标题${e}`,icon:me[e],id:`heading${e}`,onClick:t=>t.chain().focus().clearNodes().setHeading({level:e}).run(),isActive:t=>t[`isHeading${e}`]}),B={label:`撤销`,icon:d.Undo2,id:`undo`,onClick:e=>e.chain().focus().undo().run(),disabled:e=>!e.canUndo,shortcutKeys:[`mod`,`Z`]},V={label:`重做`,icon:d.Redo2,id:`redo`,onClick:e=>e.chain().focus().redo().run(),disabled:e=>!e.canRedo,shortcutKeys:[`mod`,`shift`,`Z`]},H={label:`正文`,icon:d.Type,id:`paragraph`,onClick:e=>e.chain().focus().clearNodes().setParagraph().run(),isActive:e=>e.isParagraph},he={label:`引用`,icon:d.Quote,id:`blockquote`,onClick:e=>e.chain().focus().clearNodes().setBlockquote().run(),isActive:e=>e.isBlockquote},ge={label:`代码块`,icon:d.CodeXml,id:`codeBlock`,onClick:e=>e.chain().focus().clearNodes().setCodeBlock().run(),isActive:e=>e.isCodeBlock},_e={label:`有序列表`,icon:d.ListOrdered,id:`orderedList`,onClick:e=>e.chain().focus().clearNodes().toggleOrderedList().run(),isActive:e=>e.isOrderedList},ve={label:`无序列表`,icon:d.List,id:`bulletList`,onClick:e=>e.chain().focus().clearNodes().toggleBulletList().run(),isActive:e=>e.isBulletList},ye={label:`待办任务`,icon:d.ListTodo,id:`todoList`,onClick:e=>e.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e.isTaskList},be={select:[z(1),z(2),z(3),z(4),z(5),H,he,ge],out:[ve,_e,ye]},xe={label:`左对齐`,icon:d.AlignLeft,id:`leftAlign`,onClick:e=>e.chain().setTextAlign(`left`).run(),isActive:e=>e.isAlignLeft},Se={label:`右对齐`,icon:d.AlignRight,id:`rightAlign`,onClick:e=>e.chain().setTextAlign(`right`).run(),isActive:e=>e.isAlignRight},Ce={label:`居中对齐`,icon:d.AlignCenter,id:`centerAlign`,onClick:e=>e.chain().setTextAlign(`center`).run(),isActive:e=>e.isAlignCenter},we={label:`两端对齐`,icon:d.AlignJustify,id:`justifyAlign`,onClick:e=>e.chain().setTextAlign(`justify`).run(),isActive:e=>e.isAlignJustify},Te=[xe,Se,Ce,we],Ee={label:`加粗`,icon:d.BoldIcon,id:`bold`,onClick:e=>e.chain().focus().toggleBold().run(),isActive:e=>e.isBold,disabled:e=>!e.canBold,shortcutKeys:[`mod`,`B`]},De={label:`斜体`,icon:d.ItalicIcon,id:`italic`,onClick:e=>e.chain().focus().toggleItalic().run(),isActive:e=>e.isItalic,disabled:e=>!e.canItalic,shortcutKeys:[`mod`,`I`]},Oe={label:`下划线`,icon:d.UnderlineIcon,id:`underline`,onClick:e=>e.chain().focus().toggleUnderline().run(),isActive:e=>e.isUnderline,disabled:e=>!e.canUnderline,shortcutKeys:[`mod`,`U`]},ke={label:`删除线`,icon:d.StrikethroughIcon,id:`strike`,onClick:e=>e.chain().focus().toggleStrike().run(),isActive:e=>e.isStrike,disabled:e=>!e.canStrike,shortcutKeys:[`mod`,`shift`,`S`]},Ae={label:`行内代码`,icon:d.Code,id:`inlineCode`,onClick:e=>e.chain().focus().toggleCode().run(),isActive:e=>e.isCode,disabled:e=>!e.canCode,shortcutKeys:[`mod`,`E`]},je=[Ee,De,Oe,ke,Ae],Me=[z(1),z(2),z(3),z(4),z(5),H,he,ge,ve,_e,ye];function U(...e){return(0,h.twMerge)((0,m.clsx)(e))}const Ne=(0,p.cva)(`inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap`,{variants:{variant:{default:`bg-transparent`,outline:`border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground`},size:{default:`h-9 px-2 min-w-9`,sm:`h-8 px-1.5 min-w-8`,lg:`h-10 px-2.5 min-w-10`}},defaultVariants:{variant:`default`,size:`default`}}),Pe=l.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,u.jsx)(f.Root,{ref:i,"data-slot":`toggle`,className:U(Ne({variant:t,size:n,className:e})),...r}));Pe.displayName=f.Root.displayName;function Fe({delayDuration:e=0,...t}){return(0,u.jsx)(g.Provider,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Ie({...e}){return(0,u.jsx)(Fe,{children:(0,u.jsx)(g.Root,{"data-slot":`tooltip`,...e})})}function Le({...e}){return(0,u.jsx)(g.Trigger,{"data-slot":`tooltip-trigger`,...e})}function Re({className:e,sideOffset:t=0,children:n,...r}){return(0,u.jsx)(g.Portal,{children:(0,u.jsxs)(g.Content,{"data-slot":`tooltip-content`,sideOffset:t,className:(0,_.cn)(`origin-(--radix-tooltip-content-transform-origin) z-50 w-fit text-balance rounded-md bg-foreground px-3 py-1.5 text-xs text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r,children:[n,(0,u.jsx)(g.Arrow,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}const ze=(0,p.cva)(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,sm:`h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}}),W=l.forwardRef(({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i},a)=>(0,u.jsx)(r?v.Slot:`button`,{ref:a,"data-slot":`button`,"data-variant":t,"data-size":n,className:U(ze({variant:t,size:n,className:e})),...i}));W.displayName=`Button`;const G=l.forwardRef(({isActive:e,children:t,tooltip:n,className:r,tooltipOptions:i,shortcutKeys:a,...o},s)=>{let c=(0,u.jsx)(Pe,{size:`sm`,ref:s,className:U(`text-content-first size-7 gap-1 rounded border-none p-0`,{"bg-primary/5":e},r),...o,children:t});return n?(0,u.jsx)(Fe,{delayDuration:300,children:(0,u.jsxs)(Ie,{children:[(0,u.jsx)(Le,{asChild:!0,children:c}),(0,u.jsx)(Re,{...i,children:(0,u.jsx)(`div`,{className:`flex flex-col items-center text-center`,children:n})})]})}):c});G.displayName=`ToolbarButton`;const K=l.memo(l.forwardRef(({children:e,tooltip:t,className:n,...r},i)=>(0,u.jsx)(Fe,{children:(0,u.jsxs)(Ie,{children:[(0,u.jsx)(Le,{children:(0,u.jsx)(W,{ref:i,variant:`ghost`,className:U(`text-content-first relative flex size-7 flex-row rounded p-0`,`bg-transparent hover:bg-transparent`,n),...r,children:e})}),(0,u.jsx)(Re,{side:`bottom`,children:t})]})})));function q({...e}){return(0,u.jsx)(y.Root,{"data-slot":`popover`,...e})}function J({...e}){return(0,u.jsx)(y.Trigger,{"data-slot":`popover-trigger`,...e})}function Y({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,u.jsx)(y.Portal,{children:(0,u.jsx)(y.Content,{"data-slot":`popover-content`,align:t,sideOffset:n,className:U(`origin-(--radix-popover-content-transform-origin) outline-hidden z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r})})}const X=()=>{let{editor:e}=R();return(0,c.useEditorState)({editor:e,selector:e=>{let{editor:t}=e,n=(e,n={})=>t.isActive(e,n)??!1,r=(e,n={})=>t.can().chain()[e]?.(n)?.run();return{isBold:n(`bold`),canBold:r(`toggleBold`),isItalic:n(`italic`),canItalic:r(`toggleItalic`),isUnderline:n(`underline`),canUnderline:r(`toggleUnderline`),isStrike:n(`strike`),canStrike:r(`toggleStrike`),isCode:n(`code`),canCode:r(`toggleCode`),isParagraph:n(`paragraph`),isHeading1:n(`heading`,{level:1}),isHeading2:n(`heading`,{level:2}),isHeading3:n(`heading`,{level:3}),isHeading4:n(`heading`,{level:4}),isHeading5:n(`heading`,{level:5}),isHeading6:n(`heading`,{level:6}),isBulletList:n(`bulletList`),isOrderedList:n(`orderedList`),isTaskList:n(`taskList`),isBlockquote:n(`blockquote`),isCodeBlock:n(`codeBlock`),canUndo:t.can().undo(),canRedo:t.can().redo(),isAlignLeft:n({textAlign:`left`}),isAlignRight:n({textAlign:`right`}),isAlignCenter:n({textAlign:`center`}),isAlignJustify:n({textAlign:`justify`}),isTable:n(`table`),canTable:r(`insertTable`)}}})},Be=({nodeFormatActions:e})=>{let{editor:t}=R(),n=X(),r=e.find(e=>e.isActive?.(n))??H;return(0,u.jsxs)(q,{children:[(0,u.jsx)(J,{asChild:!0,children:(0,u.jsxs)(W,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,u.jsx)(r.icon,{size:20}),(0,u.jsx)(d.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,u.jsx)(Y,{className:`border-line z-50 w-40 rounded-xl border bg-white px-2 py-1 shadow-xl`,align:`start`,sideOffset:18,children:e.map(e=>(0,u.jsxs)(`div`,{onClick:()=>{e.onClick(t)},className:U(`flex cursor-pointer items-center rounded-sm p-2 text-sm hover:bg-accent`,r.label===e.label?`text-primary`:``),children:[(0,u.jsx)(e.icon,{size:`20`,className:`mr-3`}),(0,u.jsx)(`span`,{children:e.label}),r.label===e.label&&(0,u.jsx)(d.Check,{size:`16`,className:`ml-auto items-end`})]},e.id))})]})};var Ve=(0,l.memo)(Be);const He=({textFormatActions:e,tooltipOptions:t})=>{let{editor:n}=R(),r=X();return(0,u.jsx)(u.Fragment,{children:e.map(e=>(0,u.jsx)(G,{isActive:e.isActive?.(r),onClick:()=>e.onClick(n),disabled:e.disabled?.(r),tooltip:e.label,tooltipOptions:t,shortcutKeys:e.shortcutKeys,children:(0,u.jsx)(e.icon,{size:20})},e.id))})};var Ue=(0,l.memo)(He);function We({className:e,...t}){return(0,u.jsx)(b.Root,{"data-slot":`label`,className:(0,_.cn)(`flex select-none items-center gap-2 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50 group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50`,e),...t})}function Ge({className:e,type:t,...n}){return(0,u.jsx)(`input`,{type:t,"data-slot":`input`,className:(0,_.cn)(`shadow-xs h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base outline-none transition-[color,box-shadow] selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,e),...n})}const Ke=l.forwardRef(({onSave:e,defaultUrl:t,defaultText:n,className:r},i)=>{let a=l.useRef(null),[o,s]=l.useState(t||``),[c,d]=l.useState(n||``),f=l.useCallback(t=>{t.preventDefault(),a.current&&(Array.from(a.current.querySelectorAll(`input`)).every(e=>e.checkValidity())?e(o,c):a.current.querySelectorAll(`input`).forEach(e=>{e.checkValidity()||e.reportValidity()}))},[e,o,c]);return l.useImperativeHandle(i,()=>a.current),(0,u.jsx)(`div`,{className:`shadow-box w-full min-w-80 rounded-xl p-4`,ref:a,children:(0,u.jsxs)(`div`,{className:U(`space-y-4`,r),children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(We,{children:`链接`}),(0,u.jsx)(Ge,{type:`url`,required:!0,placeholder:`输入链接`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&f(e)}})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(We,{children:`文本`}),(0,u.jsx)(Ge,{type:`text`,placeholder:`输入文本`,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&f(e)}})]}),(0,u.jsx)(`div`,{className:`flex justify-end space-x-2`,children:(0,u.jsx)(W,{type:`button`,onClick:f,children:`保存`})})]})})});Ke.displayName=`LinkEditPanel`;const qe=({tooltipOptions:e})=>{let{editor:t}=R(),{href:n,text:r,isActive:i}=(0,c.useEditorState)({editor:t,selector:e=>{let{from:n,to:r}=e.editor.state.selection,{href:i}=e.editor.getAttributes(`link`);return{href:i,text:t.state.doc.textBetween(n,r,` `),isActive:t.isActive(`link`)}}}),a=(0,l.useCallback)((e,n)=>{t.chain().extendMarkRange(`link`).insertContent({type:`text`,text:n,marks:[{type:`link`,attrs:{href:e,target:`_blank`}}]}).setLink({href:e,target:`_blank`}).focus().run()},[t]);return(0,u.jsxs)(q,{defaultOpen:i,children:[(0,u.jsx)(J,{asChild:!0,children:(0,u.jsx)(G,{pressed:i,isActive:i,tooltip:`插入链接`,tooltipOptions:e,children:(0,u.jsx)(d.LinkIcon,{size:19})})}),(0,u.jsx)(Y,{align:`center`,className:`z-50 w-max`,sideOffset:18,children:(0,u.jsx)(Ke,{defaultUrl:n,defaultText:r,onSave:a})})]})};var Je=qe;const Ye=`#111111.#414141.#707070.#B8B8B8.#E7E7E7.#FFFFFF.#4D0000.#800000.#B30000.#FF0000.#FF4C4C.#FFB2B2.#4D2D16.#804B25.#B36934.#FF964A.#FFB580.#FFDFC9.#4D4110.#806D1B.#B39926.#FFDA36.#FFE572.#FFF4C3.#084623.#0D7539.#12A451.#19EA73.#5EF09D.#BAF9D5.#003845.#005E72.#0083A0.#00BBE5.#4CCFED.#B2EBF7.#021C4D.#032F80.#0542B3.#075EFF.#518EFF.#B5CFFF.#36204D.#5A3580.#7E4AB3.#B46AFF.#CA97FF.#E8D2FF`.split(`.`),Xe=()=>{let{editor:e}=R(),{activeColorItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeColorItem:Ye.find(t=>e.isActive(`textStyle`,{color:t}))})});return(0,u.jsxs)(y.Root,{children:[(0,u.jsx)(y.Trigger,{asChild:!0,children:(0,u.jsxs)(W,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,u.jsx)(d.Baseline,{size:20,color:t}),(0,u.jsx)(d.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,u.jsx)(y.Content,{className:`border-line shadow-box z-50 w-[242px] rounded-xl border bg-white p-4`,align:`center`,sideOffset:18,children:(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`text-content-first border-line mb-[10px] flex h-8 cursor-pointer items-center justify-center rounded-lg border text-sm`,onClick:()=>{e.chain().focus().unsetColor().run()},children:`默认颜色`}),(0,u.jsx)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:Ye.map(n=>(0,u.jsx)(`span`,{className:U(`hover:border-content-first flex h-7 w-7 cursor-pointer items-center justify-center rounded-sm border border-transparent`,{"border-content-first":t===n}),onClick:()=>{e.chain().focus().unsetColor().run(),e.chain().focus().setColor(n).run()},children:(0,u.jsx)(`span`,{className:`border-line h-6 w-6 rounded-sm border`,style:{backgroundColor:n}})},n))})]})})]})};var Ze=Xe;const Qe=[`#FF0000`,`#FF4C4C`,`#FFB2B2`,`#FF964A`,`#FFB580`,`#FFDFC9`,`#FFDA36`,`#FFE572`,`#FFF4C3`,`#19EA73`,`#5EF09D`,`#BAF9D5`,`#00BBE5`,`#4CCFED`,`#B2EBF7`,`#075EFF`,`#518EFF`,`#B5CFFF`,`#B46AFF`,`#CA97FF`,`#E8D2FF`,`#707070`,`#B8B8B8`,`#E7E7E7`],$e=()=>{let{editor:e}=R(),{activeHighlightItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeHighlightItem:Qe.find(t=>e.isActive(`highlight`,{color:t}))})});return(0,u.jsxs)(y.Root,{children:[(0,u.jsx)(y.Trigger,{asChild:!0,children:(0,u.jsxs)(W,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,u.jsx)(d.Highlighter,{size:20,color:t}),(0,u.jsx)(d.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,u.jsx)(y.Content,{className:`border-line shadow-box z-50 w-[242px] rounded-xl border bg-white p-4`,align:`center`,sideOffset:18,children:(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`text-content-first border-line mb-[10px] flex h-8 cursor-pointer items-center justify-center rounded-lg border text-sm`,onClick:()=>{e.chain().focus().unsetBackgroundColor().run()},children:`默认颜色`}),(0,u.jsx)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:Qe.map(n=>(0,u.jsx)(`span`,{className:U(`hover:border-content-first flex h-7 w-7 cursor-pointer items-center justify-center rounded-sm border border-transparent`,{"border-content-first":t===n}),onClick:()=>{e.chain().focus().unsetBackgroundColor().run(),e.chain().focus().setBackgroundColor(n).run()},children:(0,u.jsx)(`span`,{className:`border-line h-6 w-6 rounded-sm border`,style:{backgroundColor:n}})},n))})]})})]})};var et=$e;const tt=()=>{let{editor:e}=R(),[t,n]=(0,l.useState)(!1),r=X(),i=Te.find(e=>e.isActive?.(r))??xe;return(0,u.jsxs)(q,{open:t,onOpenChange:n,children:[(0,u.jsx)(J,{asChild:!0,children:(0,u.jsxs)(W,{onClick:()=>n(!0),variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,u.jsx)(i.icon,{strokeWidth:1.5,size:`20`}),(0,u.jsx)(d.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,u.jsx)(Y,{className:`border-line z-50 w-40 rounded-xl border bg-white px-2 py-1 shadow-xl`,align:`start`,sideOffset:18,children:Te.map(t=>(0,u.jsxs)(`div`,{onClick:()=>{t.onClick(e),n(!1)},className:U(`flex cursor-pointer items-center rounded-sm p-2 text-sm hover:bg-accent`,i?.label===t.label?`text-primary`:``),children:[(0,u.jsx)(t.icon,{size:`20`,className:`mr-3`}),(0,u.jsx)(`span`,{children:t.label}),i?.label===t.label&&(0,u.jsx)(d.Check,{size:`16`,className:`ml-auto items-end`})]},t.id))})]})};var nt=(0,l.memo)(tt);const rt=()=>{let{editor:e}=R();return(0,u.jsx)(W,{variant:`ghost`,className:`aspect-square h-7 gap-1 rounded px-1`,onClick:()=>{let t=document.createElement(`input`);t.type=`file`,t.accept=`image/*`,t.onchange=async t=>{let n=t.target.files?.[0];n&&e.commands.setImages([{src:n}])},t.click()},children:(0,u.jsx)(d.ImagePlus,{size:`20`})})};var it=rt;const at=10,ot=100,st=50,ct=2,lt=10,ut=840,dt=120,ft=120,pt=e=>Array.from({length:e}).map((e,t)=>t+1);function mt(){let{editor:e}=R(),{canTable:t,isTable:n}=X();function r(n){t&&e.chain().focus().insertTable({...n,withHeaderRow:!1}).run()}let[i,a]=l.default.useState(!0),[o,s]=l.default.useState({rows:10,cols:10}),[c,f]=l.default.useState({rows:2,cols:2});function p(e,t){e===o.rows&&s(t=>({...t,rows:Math.min(e+1,10)})),t===o.cols&&s(e=>({...e,cols:Math.min(t+1,10)})),f({rows:e,cols:t})}function m(e,t){r({rows:e,cols:t,withHeaderRow:i}),h()}function h(){a(!1),s({rows:10,cols:10}),f({rows:2,cols:2})}return(0,u.jsxs)(q,{children:[(0,u.jsx)(J,{asChild:!0,children:(0,u.jsx)(G,{"data-state":`off`,disabled:!t||n,tooltip:`插入表格`,tooltipOptions:{side:`bottom`},isActive:n,children:(0,u.jsx)(d.Table,{size:20})})}),(0,u.jsx)(Y,{className:`z-50 w-full !p-2`,align:`start`,side:`bottom`,sideOffset:18,children:(0,u.jsxs)(`div`,{className:`table-grid-size-editor p-0`,children:[(0,u.jsx)(`div`,{className:`flex flex-col flex-wrap justify-between gap-1`,children:pt(o?.rows)?.map(e=>(0,u.jsx)(`div`,{className:`flex gap-1`,children:pt(o?.cols)?.map(t=>(0,u.jsx)(`div`,{className:`border-line box-border h-4 w-4 cursor-pointer rounded-[2px] border-solid bg-gray-200 ${t<=c.cols&&e<=c.rows?`bg-primary/60`:`bg-gray-100`}`,onMouseOver:()=>p(e,t),onMouseDown:()=>m(e,t)},`c-${t}`))},`r-${e}`))}),(0,u.jsxs)(`div`,{className:`mt-2 text-center text-sm text-zinc-600`,children:[c.rows,` x `,c.cols]})]})})]})}var ht=mt;function Z({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,u.jsx)(x.Root,{"data-slot":`separator`,decorative:n,orientation:t,className:U(`bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=vertical]:h-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px`,e),...r})}const gt=[`undo`,`redo`,`separator`,`node-selector`,`text-selector`,`link`,`color`,`bg`,`align`,`separator`,`image`,`table`],_t=({config:e=gt,appendItems:t})=>{let{editor:n}=R(),r=X();if(!n)return null;let i=e=>({isActive:e.isActive?.(r)??!1,disabled:e.disabled?.(r)??!1,onClick:()=>e.onClick(n)}),a=(e,t)=>{switch(typeof e==`string`?e:e.key){case`undo`:return(0,u.jsx)(G,{...i(B),tooltip:B.label,shortcutKeys:B.shortcutKeys,children:(0,u.jsx)(B.icon,{size:20})},t);case`redo`:return(0,u.jsx)(G,{...i(V),tooltip:V.label,shortcutKeys:V.shortcutKeys,children:(0,u.jsx)(V.icon,{size:20})},t);case`separator`:return(0,u.jsx)(Z,{orientation:`vertical`,className:`bg-line h-4`},t);case`node-selector`:return(0,u.jsx)(Ve,{nodeFormatActions:be.select},t);case`text-selector`:return(0,u.jsx)(Ue,{textFormatActions:je},t);case`link`:return(0,u.jsx)(Je,{},t);case`color`:return(0,u.jsx)(Ze,{},t);case`bg`:return(0,u.jsx)(et,{},t);case`align`:return(0,u.jsx)(nt,{},t);case`image`:return(0,u.jsx)(it,{},t);case`table`:return(0,u.jsx)(ht,{},t);default:return typeof e!=`string`&&e.render?(0,u.jsx)(l.default.Fragment,{children:e.render(n)},t):null}};return(0,u.jsxs)(`div`,{className:`z-99 flex flex-wrap items-center gap-1 border-b bg-white px-4 py-2 shadow-sm`,children:[e.map((e,t)=>a(e,t)),t]})};function vt({...e}){return(0,u.jsx)(A.Root,{"data-slot":`dropdown-menu`,...e})}function yt({...e}){return(0,u.jsx)(A.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function bt({className:e,sideOffset:t=4,...n}){return(0,u.jsx)(A.Portal,{children:(0,u.jsx)(A.Content,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:U(`max-h-(--radix-dropdown-menu-content-available-height) origin-(--radix-dropdown-menu-content-transform-origin) z-50 min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})})}function xt({className:e,inset:t,variant:n=`default`,...r}){return(0,u.jsx)(A.Item,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:U(`data-[variant=destructive]:*:[svg]:!text-destructive outline-hidden relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[disabled]:opacity-50 data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0`,e),...r})}function St({className:e,...t}){return(0,u.jsx)(A.Separator,{"data-slot":`dropdown-menu-separator`,className:U(`bg-border -mx-1 my-1 h-px`,e),...t})}const Ct=({language:e,content:t,extension:n,updateAttributes:r})=>{let[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!0),f=(0,l.useRef)(null),p=()=>{a(!0),setTimeout(()=>{a(!1)},2e3)},m=e=>i?(0,u.jsx)(d.Check,{color:`#16a34a`,...e}):(0,u.jsx)(d.Copy,{color:`#777`,...e}),h=o?d.ChevronDown:d.ChevronRight,g=o?{}:{height:0,overflow:`hidden`};return(0,u.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-muted`,children:[(0,u.jsxs)(`div`,{contentEditable:!1,className:`bg-gray relative box-border flex h-9 w-full flex-row items-center justify-between px-4 py-1`,children:[(0,u.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 w-6 rounded-full text-content-second`,onClick:()=>s(!o),children:(0,u.jsx)(h,{size:14,color:`#777`,style:{verticalAlign:`-0.125em`}})}),(0,u.jsxs)(vt,{children:[(0,u.jsx)(yt,{asChild:!0,children:(0,u.jsx)(`span`,{className:`min-w-[50px] cursor-pointer text-sm text-[#999]`,children:e||`请选择语言`})}),(0,u.jsx)(bt,{className:`max-h-96 overflow-y-auto`,children:n.options.lowlight.listLanguages().map((e,t)=>(0,u.jsx)(xt,{onClick:()=>{r({language:e})},children:e},t))})]}),(0,u.jsx)(`div`,{className:`flex gap-1`,children:(0,u.jsx)(K,{onClick:()=>{(0,k.default)(t||f.current?.innerText||``),p()},tooltip:i?`已复制`:`复制`,className:`h-6 w-6 text-content-second`,children:(0,u.jsx)(m,{size:16})})})]}),(0,u.jsx)(`div`,{style:g,ref:f,children:(0,u.jsx)(`pre`,{children:(0,u.jsx)(c.NodeViewContent,{as:`code`})})})]})},wt=e=>{let{node:t,extension:n,updateAttributes:r}=e,i=t.attrs.language,a=t.textContent;return(0,u.jsx)(c.NodeViewWrapper,{"data-drag-handle":!0,children:(0,u.jsx)(Ct,{content:a,language:i,extension:n,updateAttributes:r})})};function Tt({initialWidth:e,initialHeight:t,contentWidth:n,contentHeight:r,gridInterval:i,minWidth:a,minHeight:o,maxWidth:s,onDimensionsChange:c}){let[u,d]=(0,l.useState)({width:Math.max(e??a,a),height:Math.max(t??o,o)}),[f,p]=(0,l.useState)(1/0),[m,h]=(0,l.useState)({x:0,y:0}),[g,_]=(0,l.useState)(u),[v,y]=(0,l.useState)(),b=(0,l.useCallback)((e,t)=>{let r=Math.max(a,Math.min(n??a,i/100*t));return Math.min(t,Math.max(e,r))},[i,n,a]),x=(0,l.useCallback)(e=>{if(e.preventDefault(),!v)return;let t=0,s=0;switch(v){case`tl`:t=m.x-e.pageX,s=m.y-e.pageY;break;case`tr`:t=e.pageX-m.x,s=m.y-e.pageY;break;case`bl`:t=m.x-e.pageX,s=e.pageY-m.y;break;case`br`:t=e.pageX-m.x,s=e.pageY-m.y;break;case`top`:t=m.x,s=m.y-e.pageY;break;case`right`:t=e.pageX-m.x,s=m.y;break;case`bottom`:t=m.x,s=e.pageY-m.y;break;case`left`:t=m.x-e.pageX,s=m.y;break}let c=n&&r?n/r:g.width/g.height,l=g.width,u=g.height;if([`tl`,`tr`,`bl`,`br`].includes(v)){let e=Math.abs(t)>Math.abs(s*c)?t/g.width:s/g.height;l=g.width+g.width*e,u=l/c}else [`left`,`right`].includes(v)?l=g.width+t:[`top`,`bottom`].includes(v)&&(u=g.height+s);let p=i/100*f;[`tl`,`tr`,`bl`,`br`].includes(v)&&(l=Math.round(l/p)*p,u=l/c),[`tl`,`tr`,`bl`,`br`,`left`,`right`].includes(v)&&(l=b(l,f),[`tl`,`tr`,`bl`,`br`].includes(v)&&(u=l/c)),d({width:Math.max(l,a),height:Math.max(u,o)})},[b,v,f,m,i,r,n,g,a,o]),S=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),h({x:0,y:0}),y(void 0),c?.(u)},[c,u]),C=(0,l.useCallback)(e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),d({width:Math.max(g.width,a),height:Math.max(g.height,o)}),y(void 0))},[g,a,o]),w=(0,l.useCallback)(e=>t=>{t.preventDefault(),t.stopPropagation(),console.log(`initiateResize direction`,e),p(s),_({width:Math.max(b(u.width,s),a),height:Math.max(u.height,o)}),h({x:t.pageX,y:t.pageY}),y(e)},[s,b,u.width,u.height,a,o]);return(0,l.useEffect)(()=>{if(v)return document.addEventListener(`keydown`,C),document.addEventListener(`pointermove`,x),document.addEventListener(`pointerup`,S),()=>{document.removeEventListener(`keydown`,C),document.removeEventListener(`pointermove`,x),document.removeEventListener(`pointerup`,S)}},[v,C,x,S]),{initiateResize:w,isResizing:!!v,updateDimensions:d,currentWidth:Math.max(u.width,a),currentHeight:Math.max(u.height,o)}}function Et({...e}){return(0,u.jsx)(j.Root,{"data-slot":`dialog`,...e})}function Dt({...e}){return(0,u.jsx)(j.Portal,{"data-slot":`dialog-portal`,...e})}function Ot({className:e,...t}){return(0,u.jsx)(j.Overlay,{"data-slot":`dialog-overlay`,className:(0,_.cn)(`fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t})}function kt({className:e,children:t,showCloseButton:n=!0,...r}){return(0,u.jsxs)(Dt,{"data-slot":`dialog-portal`,children:[(0,u.jsx)(Ot,{}),(0,u.jsxs)(j.Content,{"data-slot":`dialog-content`,className:(0,_.cn)(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,u.jsxs)(j.Close,{"data-slot":`dialog-close`,className:`rounded-xs focus:outline-hidden absolute right-4 top-4 opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0`,children:[(0,u.jsx)(d.XIcon,{}),(0,u.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function At({className:e,...t}){return(0,u.jsx)(`div`,{"data-slot":`dialog-header`,className:(0,_.cn)(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function jt({className:e,...t}){return(0,u.jsx)(j.Title,{"data-slot":`dialog-title`,className:(0,_.cn)(`text-lg font-semibold leading-none`,e),...t})}function Mt({editor:e,open:t,onOpenChange:n,imageSrc:r,onComplete:i}){let a=(0,l.useRef)(null),o=()=>{if(a.current){let t=a.current?.cropper;t&&t.getCroppedCanvas().toBlob(async t=>{if(!t)return;let r=new File([t],`cropped-image.jpg`,{type:`image/jpeg`}),a=e?.extensionManager?.extensions?.find(e=>e.name===`image`);if(a?.options?.uploadFn)try{i(await a.options.uploadFn(r)),n(!1)}catch(e){console.error(`Image upload failed:`,e)}},`image/jpeg`)}},s=e=>{a.current?.cropper&&a.current.cropper.setAspectRatio(e||NaN)},c=e=>{a.current?.cropper&&a.current.cropper.rotate(e)},f=(e,t)=>{if(a.current?.cropper){let n=a.current.cropper;e&&n.scaleX(-n.getData().scaleX||-1),t&&n.scaleY(-n.getData().scaleY||-1)}},p=[{type:`aspectRatio`,buttons:[{icon:d.Maximize,label:`自由`,action:()=>s(void 0)},{icon:d.Square,label:`1:1`,action:()=>s(1)},{icon:d.RatioIcon,label:`3:2`,action:()=>s(3/2)},{icon:d.RatioIcon,label:`16:9`,action:()=>s(16/9)}]},{type:`flip`,buttons:[{icon:d.FlipVertical,label:`垂直翻转`,action:()=>f(!1,!0)},{icon:d.FlipHorizontal,label:`水平翻转`,action:()=>f(!0,!1)}]},{type:`rotate`,buttons:[{icon:d.RotateCcwSquare,label:`向左90°`,action:()=>c(-90)},{icon:d.RotateCwSquare,label:`向右90°`,action:()=>c(90)}]},{type:`actions`,buttons:[{icon:d.RefreshCw,label:`重置`,action:()=>{a.current?.cropper&&(a.current.cropper.reset(),s(void 0))}},{icon:d.X,label:`放弃`,action:()=>n(!1)},{icon:d.Check,label:`完成`,action:o}]}];return(0,u.jsx)(Et,{open:t,onOpenChange:n,children:(0,u.jsxs)(kt,{showCloseButton:!1,className:`flex h-[720px] max-h-[90vh] max-w-screen-lg flex-col gap-0 px-8 pb-0 pt-8`,children:[(0,u.jsx)(At,{className:`hidden`,children:(0,u.jsx)(jt,{children:`编辑图片`})}),(0,u.jsx)(`div`,{className:`relative w-full flex-grow overflow-hidden rounded-md`,children:(0,u.jsx)(re.Cropper,{ref:a,src:r,style:{height:`100%`,width:`100%`},initialAspectRatio:void 0,viewMode:0,dragMode:`move`,autoCropArea:1})}),(0,u.jsx)(`div`,{className:`flex h-20 items-center justify-center gap-2`,children:p.map((e,t)=>(0,u.jsxs)(l.default.Fragment,{children:[e.buttons.map(({icon:e,label:t,action:n,variant:r=`ghost`})=>(0,u.jsxs)(W,{variant:r,className:`flex h-14 w-14 flex-col items-center justify-center gap-1 hover:bg-transparent hover:text-primary`,onClick:n,children:[(0,u.jsx)(e,{size:20}),(0,u.jsx)(`span`,{className:`text-xs`,children:t})]},t)),t<p.length-1&&(0,u.jsx)(Z,{orientation:`vertical`,className:`h-12`})]},e.type))})]})})}const Nt=l.memo(l.forwardRef(({children:e,className:t,...n},r)=>(0,u.jsx)(`div`,{ref:r,className:U(`absolute -top-14 left-0 opacity-0 group-hover/node-image:opacity-100`,`border-line z-50 flex items-center gap-3 rounded-xl border bg-white px-3 py-2 shadow-[0px_0px_20px_0px_rgba(0,0,0,0.1)]`,t),...n,children:e})));Nt.displayName=`ActionWrapper`;const Pt=l.memo(({editor:e,node:t,imageState:n,setImageState:r,updateAttributes:i})=>{let[a,o]=l.useState(!1),s=t=>{r(e=>({...e,src:t,isServerUploading:!1})),i({src:t}),e.commands.setImages([{src:t}]),e.chain().focus().run()},c=[{icon:d.AlignLeft,tooltip:`左对齐`,onClick:()=>i({align:`left`})},{icon:d.AlignCenter,tooltip:`居中对齐`,onClick:()=>i({align:`center`})},{icon:d.AlignRight,tooltip:`右对齐`,onClick:()=>i({align:`right`})}],f=[{icon:d.Maximize,tooltip:`预览`,onClick:()=>{r(e=>({...e,isZoomed:!0}))}},{icon:d.Trash2,tooltip:`移除`,onClick:()=>{e.commands.command(({tr:e,dispatch:t})=>{let{selection:n}=e,r=e.doc.nodeAt(n.from);return r&&r.type.name===`image`&&t?(e.deleteSelection(),!0):!1})}}];return(0,u.jsxs)(Nt,{children:[c.map(({icon:e,tooltip:t,onClick:n},r)=>(0,u.jsx)(K,{tooltip:t,onClick:n,children:(0,u.jsx)(e,{size:`20`})},r)),(0,u.jsx)(Z,{className:`h-5`,orientation:`vertical`}),f.map(({icon:e,tooltip:t,onClick:n},r)=>(0,u.jsx)(K,{tooltip:t,onClick:n,children:(0,u.jsx)(e,{size:`20`})},r)),(0,u.jsx)(Mt,{editor:e,onOpenChange:o,open:a,onComplete:s,imageSrc:n.src})]})});Pt.displayName=`ImageActions`;const Ft=l.memo(()=>(0,u.jsx)(`div`,{className:U(`flex flex-row items-center justify-center`,`absolute inset-0 rounded bg-[var(--mt-overlay)] opacity-100 transition-opacity`),children:(0,u.jsx)(d.LoaderCircle,{className:`size-7 animate-spin`})}));Ft.displayName=`ImageOverlay`;const It=[`tl`,`tr`,`bl`,`br`],Lt=({className:e,initiateResize:t})=>{let n=l.useCallback(e=>{let t=``;switch(e){case`tl`:t=`top-0 left-0 -translate-x-1/2 -translate-y-1/2 h-3 w-3 cursor-nwse-resize`;break;case`tr`:t=`top-0 right-0 translate-x-1/2 -translate-y-1/2 h-3 w-3 cursor-nesw-resize`;break;case`bl`:t=`bottom-0 left-0 -translate-x-1/2 translate-y-1/2 h-3 w-3 cursor-nesw-resize`;break;case`br`:t=`bottom-0 right-0 translate-x-1/2 translate-y-1/2 h-3 w-3 cursor-nwse-resize`;break;case`top`:t=`top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 h-3 w-3 cursor-ns-resize`;break;case`right`:t=`top-1/2 right-0 translate-x-1/2 -translate-y-1/2 h-3 w-3 cursor-ew-resize`;break;case`bottom`:t=`bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 h-3 w-3 cursor-ns-resize`;break;case`left`:t=`top-1/2 left-0 -translate-x-1/2 -translate-y-1/2 h-3 w-3 cursor-ew-resize`;break;default:}return U(`absolute z-10 block border border-primary bg-white`,t)},[]);return(0,u.jsx)(`div`,{className:U(`absolute left-0 top-0 z-10 h-full w-full cursor-pointer border border-primary`,e),children:It?.map(e=>(0,u.jsx)(`span`,{className:n(e),onPointerDown:n=>t(e)(n)},e))})};Lt.displayName=`ResizeHandle`;const Rt=async e=>{let t=await(await fetch(e)).blob();return new Promise((e,n)=>{let r=new FileReader;r.onloadend=()=>{typeof r.result==`string`?e(r.result):n(Error(`Failed to convert Blob to base64`))},r.onerror=n,r.readAsDataURL(t)})},zt=e=>{let t=e.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);return t&&t.length>1?t[1]:`unknown`},Bt=e=>{if(e.startsWith(`data:`)){let t=e.match(/^data:[^;]+;base64,(.+)$/);if(t&&t[1])e=t[1];else return!1}try{return btoa(atob(e))===e}catch{return!1}},Vt=(e,{allowedMimeTypes:t,maxFileSize:n})=>{let r=e instanceof File?e.type:zt(e),i=e instanceof File?e.size:atob(e.split(`,`)[1]).length;return{isValidType:t.length===0||t.includes(r)||t.includes(`${r.split(`/`)[0]}/*`),isValidSize:!n||i<=n}},Ht=(e,t,n,r,i)=>{let{isValidType:a,isValidSize:o}=Vt(e,t);a&&o?r.push(n):(a||i.push({file:e,reason:`type`}),o||i.push({file:e,reason:`size`}))},Ut=(e,t={requireHostname:!1})=>{if(e.includes(`
3
+ `))return!1;try{let n=new URL(e);return[`javascript:`,`file:`,`vbscript:`,...t.allowBase64?[]:[`data:`]].includes(n.protocol)?!1:t.allowBase64&&n.protocol===`data:`?/^data:image\/[a-z]+;base64,/.test(e):n.hostname?!0:n.protocol!==``&&(n.pathname.startsWith(`//`)||n.pathname.startsWith(`http`))&&!t.requireHostname}catch{return!1}},Wt=(e,t={})=>{if(e)return t.allowBase64&&e.startsWith(`data:image`)?Ut(e,{requireHostname:!1,allowBase64:!0})?e:void 0:Ut(e,{requireHostname:!1,allowBase64:t.allowBase64})||/^(\/|#|mailto:|sms:|fax:|tel:)/.test(e)?e:`https://${e}`},Gt=(e,t)=>{let n=[],r=[];return e.forEach(e=>{let i=`src`in e?e.src:e;i instanceof File?Ht(i,t,e,n,r):typeof i==`string`&&(Bt(i)?t.allowBase64?Ht(i,t,e,n,r):r.push({file:i,reason:`base64NotAllowed`}):Wt(i,{allowBase64:t.allowBase64})?n.push(e):r.push({file:i,reason:`invalidBase64`}))}),[n,r]},Kt=({editor:e,node:t,selected:n,updateAttributes:r})=>{let{src:i,width:a,height:o,align:s,fileName:f,fileType:p}=t.attrs,[m,h]=l.useState({src:i,isServerUploading:!1,imageLoaded:!1,isZoomed:!1,error:!1,naturalSize:{width:a,height:o}}),g=l.useRef(null),_=l.useCallback(({width:e,height:t})=>{r({width:e,height:t})},[r]),v=()=>{e.commands.command(({tr:e,dispatch:t})=>{let{selection:n}=e,r=e.doc.nodeAt(n.from);return r&&r.type.name===`image`&&t?(e.deleteSelection(),!0):!1})},y=840*(m.naturalSize.width/m.naturalSize.height),b=g.current?parseFloat(getComputedStyle(g.current).getPropertyValue(`--editor-width`)):1/0,{currentWidth:x,currentHeight:S,updateDimensions:C,initiateResize:w,isResizing:T}=Tt({initialWidth:a??m.naturalSize.width,initialHeight:o??m.naturalSize.height,contentWidth:m.naturalSize.width,contentHeight:m.naturalSize.height,gridInterval:.1,onDimensionsChange:_,minWidth:120,minHeight:120,maxWidth:b>0?b:y}),E=l.useCallback(e=>{let t=e.target,n={width:t.naturalWidth,height:t.naturalHeight};h(e=>({...e,naturalSize:n,imageLoaded:!0})),r({width:t.width||n.width,height:t.height||n.height,alt:t.alt,title:t.title}),a||C(e=>({...e,width:n.width}))},[a,r,C]),D=l.useCallback(()=>{h(e=>({...e,error:!0,imageLoaded:!0}))},[]),O=async()=>{let{uploadFn:t}=e.options.extensions.find(e=>e.name===`image`)?.options??{};if(i.startsWith(`blob:`)||i.startsWith(`http`)&&i.includes(`pixabay.com`)){if(m.isServerUploading)return;if(t)try{h(e=>({...e,isServerUploading:!0}));let e;e=i.startsWith(`blob:`)?await(await fetch(i)).blob():await(await fetch(i,{mode:`cors`})).blob();let n=await t(new File([e],`${f||`image`}.jpg`,{type:p||e.type}));h(e=>({...e,src:n,isServerUploading:!1})),r({src:n})}catch(e){console.error(`图片上传失败:`,e),h(e=>({...e,error:!0,isServerUploading:!1}))}else try{let e=await Rt(i);h(t=>({...t,src:e})),r({src:e})}catch{h(e=>({...e,error:!0}))}i.startsWith(`blob:`)&&URL.revokeObjectURL(i)}};return l.useEffect(()=>{O()},[i]),(0,u.jsx)(c.NodeViewWrapper,{ref:g,"data-drag-handle":!0,className:`relative flex justify-center`,style:{justifyContent:s},children:(0,u.jsx)(`div`,{className:`node-image group/node-image relative rounded-md object-contain`,style:{maxWidth:`min(${y}px, 100%)`,width:x,maxHeight:840,aspectRatio:`${m.naturalSize.width} / ${m.naturalSize.height}`},children:(0,u.jsxs)(`div`,{className:U(`relative flex h-full cursor-default flex-col items-center gap-2 rounded`),children:[(0,u.jsxs)(`div`,{className:`relative h-full`,children:[!m.imageLoaded&&!m.error&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,u.jsx)(d.LoaderCircle,{className:`size-7 animate-spin`})}),(0,u.jsx)(ne.Controlled,{isZoomed:m.isZoomed,onZoomChange:()=>h(e=>({...e,isZoomed:!1})),children:(0,u.jsx)(`img`,{className:U(`h-auto rounded transition-shadow`,{"opacity-30":!m.imageLoaded||m.error}),style:{maxWidth:`min(100%, ${y}px)`,minWidth:`120px`,maxHeight:840,cursor:`pointer`},onDoubleClick:()=>{h(e=>({...e,isZoomed:!0}))},width:x,height:S,src:m.src,onError:D,onLoad:E,alt:t.attrs.alt||``})})]}),m.isServerUploading&&(0,u.jsx)(Ft,{}),e.isEditable&&m.imageLoaded&&!m.error&&!m.isServerUploading&&(n||T)&&(0,u.jsx)(Lt,{initiateResize:w}),m.error&&(0,u.jsx)(Nt,{children:(0,u.jsx)(K,{tooltip:`移除图片`,onClick:v,children:(0,u.jsx)(d.Trash2,{className:`size-4`})})}),!T&&!m.error&&!m.isServerUploading&&(0,u.jsx)(Pt,{editor:e,node:t,imageState:m,setImageState:h,updateAttributes:r})]})})})},qt=(e,t,n)=>{let r=e instanceof Error?e:Error(`Unknown error`);n?.(r,t)},Jt=async(e,t)=>{let{src:n}=e;try{let r=await(await fetch(n)).blob();await navigator.clipboard.write([new ClipboardItem({[r.type]:r})]),t.onActionSuccess?.({...e,action:`copyImage`})}catch(n){qt(n,{...e,action:`copyImage`},t.onActionError)}},Yt=async(e,t)=>{let{src:n}=e;try{await navigator.clipboard.writeText(n),t.onActionSuccess?.({...e,action:`copyLink`})}catch(n){qt(n,{...e,action:`copyLink`},t.onActionError)}},Xt=te.Image.extend({atom:!0,addOptions(){return{...this.parent?.(),allowedMimeTypes:[],maxFileSize:0,uploadFn:void 0}},addAttributes(){return{...this.parent?.(),width:{default:void 0},height:{default:void 0},align:{default:`center`,parseHTML:e=>e.getAttribute(`align`),renderHTML:e=>({align:e.align})},fileName:{default:void 0},fileType:{default:void 0}}},addCommands(){return{setImages:e=>({commands:t,editor:n})=>{let[r,i]=Gt(e,{allowedMimeTypes:this.options.allowedMimeTypes,maxFileSize:this.options.maxFileSize,allowBase64:this.options.allowBase64});return i.length>0&&this.options.onValidationError&&this.options.onValidationError(i),r.length>0&&(r.forEach(async e=>{if(e.src instanceof File){let r=e.src,i=URL.createObjectURL(r);if(t.insertContent({type:this.name,attrs:{src:i,fileName:r.name}}),this.options.uploadFn){let e=await this.options.uploadFn(r,n);n.commands.updateAttributes(this.name,{src:e})}}else t.insertContent({type:this.name,attrs:{src:e.src}})}),r.map(e=>{if(e.src instanceof File){let t=URL.createObjectURL(e.src);return{type:this.type.name,attrs:{src:t,alt:e.alt,title:e.title,fileName:e.src.name,fileType:e.src.type,width:400}}}else return{type:this.type.name,attrs:{src:e.src,alt:e.alt,title:e.title,fileName:null,fileType:null,width:400}}})),!1},setImageInline:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e}),updateImage:e=>({commands:t})=>(console.log(`updateImage options: `,e),t.updateAttributes(this.name,e)),setAlignImage:e=>({commands:t})=>t.updateAttributes(this.name,{align:e}),copyImage:e=>()=>((this.options.customCopyImage||Jt)({...e,action:`copyImage`},this.options),!0),copyLink:e=>()=>((this.options.customCopyLink||Yt)({...e,action:`copyLink`},this.options),!0)}},addNodeView(){return(0,c.ReactNodeViewRenderer)(Kt,{className:`block-node`})}});var Zt=Xt;const Qt=se.default.extend({inclusive:!1,parseHTML(){return[{tag:`a[href]:not([data-type="button"]):not([href *= "javascript:" i])`}]},renderHTML({HTMLAttributes:e}){return[`a`,(0,N.mergeAttributes)(this.options.HTMLAttributes,e,{class:`link`}),0]},addProseMirrorPlugins(){return[...this.parent?.()||[],new P.Plugin({props:{handleClick(e,t){let{schema:n,doc:r,tr:i}=e.state,a=(0,N.getMarkRange)(r.resolve(t),n.marks.link);if(!a)return;let{from:o,to:s}=a,c=Math.min(o,s),l=Math.max(o,s);if(t<c||t>l)return;let u=r.resolve(c),d=r.resolve(l),f=i.setSelection(new P.TextSelection(u,d));e.dispatch(f)}}})]}});var $t=Qt;const en={aiGenerationIsSelection:!1,aiGenerationIsLoading:!1,aiGenerationActive:!1,aiGenerationHasMessage:!1,commentInputVisible:!1,lockDragHandle:!1,isDragging:!1},tn=N.Extension.create({name:`uiState`,addStorage(){return{uiState:{...en}}},addCommands(){let e=e=>t=>()=>(this.storage[e]=t,!0),t=(e,t)=>()=>()=>(this.storage[e]=t,!0);return{aiGenerationSetIsSelection:e(`aiGenerationIsSelection`),aiGenerationSetIsLoading:e(`aiGenerationIsLoading`),aiGenerationHasMessage:e(`aiGenerationHasMessage`),aiGenerationShow:t(`aiGenerationActive`,!0),aiGenerationHide:t(`aiGenerationActive`,!1),commentInputShow:t(`commentInputVisible`,!0),commentInputHide:t(`commentInputVisible`,!1),setLockDragHandle:e(`lockDragHandle`),setIsDragging:e(`isDragging`),resetUiState:()=>()=>(Object.assign(this.storage,{...en}),!0)}},onCreate(){this.storage={...en}}}),nn=[`image`,`codeBlock`,`link`,`table`,`title`],rn=e=>{let t=e;for(;t&&![`TD`,`TH`].includes(t.tagName);)t=t.parentElement;let n=t&&t.querySelector&&t.querySelector(`a.grip-column.selected`),r=t&&t.querySelector&&t.querySelector(`a.grip-row.selected`);return!!(n||r)},an=(e,t)=>{let{from:n,to:r}=e.state.selection,i=!1;e.state.doc.nodesBetween(n,r,(e,t)=>{e.type.name===`title`&&(i=!0)});let a=nn.some(t=>e.isActive(t)),o=rn(t);return a||o||i},on=({editor:e})=>{let{doc:t,selection:n,selection:{empty:r,from:i,to:a}}=e.state,o=!t.textBetween(i,a).length&&(0,N.isTextSelection)(n);return!(r||o||!e.isEditable)},sn=e=>(0,N.findParentNode)(e=>e.type.spec.tableRole&&e.type.spec.tableRole===`table`)(e),cn=e=>t=>{if(Q(t)){let n=L.TableMap.get(t.$anchorCell.node(-1)),r=t.$anchorCell.start(-1),i=n.cellsInRect(e),a=n.cellsInRect(n.rectBetween(t.$anchorCell.pos-r,t.$headCell.pos-r));for(let e=0,t=i.length;e<t;e+=1)if(a.indexOf(i[e])===-1)return!1;return!0}return!1},Q=e=>e instanceof L.CellSelection,ln=e=>t=>{if(Q(t)){let n=L.TableMap.get(t.$anchorCell.node(-1));return cn({left:e,right:e+1,top:0,bottom:n.height})(t)}return!1},un=e=>t=>Q(t)?cn({left:0,right:L.TableMap.get(t.$anchorCell.node(-1)).width,top:e,bottom:e+1})(t):!1,dn=e=>{if(Q(e)){let t=L.TableMap.get(e.$anchorCell.node(-1));return cn({left:0,right:t.width,top:0,bottom:t.height})(e)}return!1},fn=e=>t=>{let n=sn(t);if(n){let t=L.TableMap.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((e,r)=>{if(r>=0&&r<=t.width-1){let i=t.cellsInRect({left:r,right:r+1,top:0,bottom:t.height});return e.concat(i.map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t}}))}return e},[])}return null},pn=e=>t=>{let n=sn(t);if(n){let t=L.TableMap.get(n.node);return(Array.isArray(e)?e:Array.from([e])).reduce((e,r)=>{if(r>=0&&r<=t.height-1){let i=t.cellsInRect({left:0,right:t.width,top:r,bottom:r+1});return e.concat(i.map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t}}))}return e},[])}return null},mn=e=>t=>n=>{let r=sn(n.selection),i=e===`row`;if(r){let e=L.TableMap.get(r.node);if(t>=0&&t<(i?e.height:e.width)){let a=i?0:t,o=i?t:0,s=i?e.width:t+1,c=i?t+1:e.height,l=e.cellsInRect({left:a,top:o,right:i?s:a+1,bottom:i?o+1:c}),u=c-o===1?l:e.cellsInRect({left:i?a:s-1,top:i?c-1:o,right:s,bottom:c}),d=r.start+l[0],f=r.start+u[u.length-1],p=n.doc.resolve(d),m=n.doc.resolve(f);return n.setSelection(new L.CellSelection(m,p))}}return n},hn=mn(`column`),gn=mn(`row`),_n=N.Node.create({name:`tableCell`,content:`block+`,tableRole:`cell`,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`td`}]},renderHTML({HTMLAttributes:e}){return[`td`,(0,N.mergeAttributes)(this.options.HTMLAttributes,e),0]},addAttributes(){return{colspan:{default:1,parseHTML:e=>{let t=e.getAttribute(`colspan`);return t?parseInt(t,10):1}},rowspan:{default:1,parseHTML:e=>{let t=e.getAttribute(`rowspan`);return t?parseInt(t,10):1}},colwidth:{default:null,parseHTML:e=>{let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):null}},style:{default:null}}},addProseMirrorPlugins(){let{isEditable:e}=this.editor;return[new P.Plugin({props:{decorations:t=>{if(!e)return I.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=fn(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(I.Decoration.widget(e+1,()=>{let e=un(t)(r),n=`grip-row`;e&&(n+=` selected`),t===0&&(n+=` first`),t===a.length-1&&(n+=` last`);let i=document.createElement(`a`);return i.className=n,i.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopImmediatePropagation(),this.editor.view.dispatch(gn(t)(this.editor.state.tr))}),i}))}),I.DecorationSet.create(n,i)}}})]}}),vn=F.TableHeader.extend({addProseMirrorPlugins(){let{isEditable:e}=this.editor;return[new P.Plugin({props:{decorations:t=>{if(!e)return I.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=pn(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(I.Decoration.widget(e+1,()=>{let e=ln(t)(r),n=`grip-column`;e&&(n+=` selected`),t===0&&(n+=` first`),t===a.length-1&&(n+=` last`);let i=document.createElement(`a`);return i.className=n,i.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopImmediatePropagation(),this.editor.view.dispatch(hn(t)(this.editor.state.tr))}),i}))}),I.DecorationSet.create(n,i)}}})]}}),yn=F.TableRow.extend({allowGapCursor:!1}),bn=F.Table.extend({addOptions(){return{...this.parent?.(),resizable:!0,lastColumnResizable:!0,allowTableNodeSelection:!0,HTMLAttributes:{}}},addExtensions(){return[yn.configure(this.options.tableRow),vn.configure(this.options.tableHeader),_n.configure(this.options.tableCell)]}});var xn=bn;const $=(0,ee.createLowlight)(ee.common);$.register(`html`,oe.default),$.register(`css`,M.default),$.register(`js`,ie.default),$.register(`ts`,ae.default);const Sn=e=>{let{uploadFn:t}=e;return[C.TextStyleKit,S.default,T.Placeholder.configure({placeholder:({node:e})=>{let t=e?.type?.name;return t===`title`?`未命名文档`:t===`heading`?`标题${e.attrs.level}`:t===`codeBlock`?`请输入代码`:t===`table`?``:`请输入内容`}}),T.Focus.configure({className:`node-focused`,mode:`all`}),w.default.configure({types:[`heading`,`paragraph`]}),C.Color,C.BackgroundColor,E.TaskList,E.TaskItem,xn,T.Gapcursor,Zt.configure({allowedMimeTypes:[`image/*`],maxFileSize:10*1024*1024,allowBase64:!1,uploadFn:t,onActionSuccess(e){console.log(`Image action success:`,e)},onValidationError(e){e.forEach(e=>{})}}),T.Dropcursor,D.default.configure({allowedMimeTypes:[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],onDrop:(e,n,r)=>{n.forEach(async n=>{let i=URL.createObjectURL(n);if(e.chain().insertContentAt(r,{type:`image`,attrs:{src:i,fileName:n.name}}).focus().run(),t)try{let r=await t(n,e);e.commands.updateAttributes(`image`,{src:r})}catch(e){console.error(`上传失败:`,e)}finally{URL.revokeObjectURL(i)}})},onPaste:(e,n,r)=>{if(r)return!1;n.forEach(async n=>{let r=URL.createObjectURL(n);if(e.chain().insertContentAt(e.state.selection.anchor,{type:`image`,attrs:{src:r}}).focus().run(),t)try{let r=await t(n,e);e.commands.updateAttributes(`image`,{src:r})}catch(e){console.error(`粘贴上传失败:`,e)}finally{URL.revokeObjectURL(r)}})}}),T.Selection.configure({className:`selection`}),$t.configure({openOnClick:`whenNotEditable`}),O.default.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(wt)}}).configure({lowlight:$}),tn,ce.Mathematics]},Cn=()=>{let{editor:e}=R();return(0,u.jsx)(le.BubbleMenu,{editor:e,pluginKey:`textBubbleMenu`,shouldShow:(0,l.useCallback)(t=>{let{view:n,from:r,to:i}=t;if(!n||n.dragging)return!1;let a=n.domAtPos(r||0).node,o=n.nodeDOM(r||0)||a,s=e.state.selection instanceof P.NodeSelection;return an(e,o)||s?!1:on({editor:e})},[e]),updateDelay:100,options:{placement:`top-start`,onShow:()=>{},onHide:()=>{console.log(`textBubbleMenu onHidden`)}},appendTo:()=>document.body,children:(0,u.jsxs)(`div`,{className:`flex h-[52px] items-center justify-center gap-3 rounded-xl border-primary/10 bg-white px-4 shadow-[0px_0px_20px_0px_rgba(0,0,0,0.1)]`,children:[(0,u.jsx)(Z,{orientation:`vertical`,className:`bg-line h-4`}),(0,u.jsx)(Ue,{textFormatActions:je}),(0,u.jsx)(Je,{}),(0,u.jsx)(Ze,{}),(0,u.jsx)(et,{})]})})};var wn=Cn;const Tn=({currentNode:e,currentNodePos:t})=>{let{editor:n}=R(),r=X();return(0,u.jsx)(`div`,{className:`gap flex flex-wrap gap-[12px]`,children:Me.map(e=>(0,u.jsx)(G,{isActive:e.isActive?.(r),onClick:()=>e.onClick(n),disabled:e.disabled?.(r),tooltip:e.label,shortcutKeys:e.shortcutKeys,children:(0,u.jsx)(e.icon,{size:20})},e.id))})};var En=Tn;const Dn=({withSlashCommandTrigger:e=!0,mobileBreakpoint:t=768,...n})=>{let{editor:r}=R(),[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(null),[c,f]=(0,l.useState)(-1),p=(0,l.useCallback)(e=>{e.node&&s(e.node),f(e.pos)},[]);(0,l.useEffect)(()=>{r&&(r.commands.setLockDragHandle(i),r.commands.setMeta(`lockDragHandle`,i))},[r,i]);let m=(0,l.useMemo)(()=>({middleware:[(0,ue.offset)(e=>{let{rects:t}=e,n=t.reference.height,r=t.floating.height,i=n/2-r/2;return{mainAxis:16,crossAxis:n>40?0:i}})]}),[]),h=(0,l.useCallback)(()=>{r&&r.commands.setIsDragging(!0)},[r]),g=(0,l.useCallback)(()=>{r&&(r.commands.setIsDragging(!1),setTimeout(()=>{r.view.dom.blur(),r.view.focus()},0))},[r]),_=()=>{r.chain().setMeta(`hideDragHandle`,!0).run(),r.chain().setNodeSelection(c).run();let e=o?.textContent;console.log(e),(0,k.default)(e||``)},v=()=>{r.chain().setMeta(`hideDragHandle`,!0).setNodeSelection(c).deleteSelection().run()};return r?(0,u.jsx)(`div`,{style:{"--drag-handle-main-axis-offset":`16px`},children:(0,u.jsx)(de.DragHandle,{editor:r,onNodeChange:p,computePositionConfig:m,onElementDragStart:h,onElementDragEnd:g,...n,children:(0,u.jsxs)(vt,{open:i,onOpenChange:a,children:[(0,u.jsx)(yt,{asChild:!0,children:(0,u.jsx)(W,{variant:`ghost`,size:`icon`,className:`z-1 drag-handle flex h-8 w-8 items-center justify-center rounded-lg bg-gray-200 hover:bg-gray-300`,children:(0,u.jsx)(d.GripVertical,{size:16})})}),(0,u.jsxs)(bt,{className:`z-50 w-[164px] border-none p-[8px] shadow-[0_0px_12px_0px_rgba(0,0,0,0.1)]`,align:`start`,side:`bottom`,sideOffset:0,children:[[`image`,`table`].indexOf(o?.type.name||``)===-1&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(En,{currentNode:o,currentNodePos:c}),(0,u.jsx)(St,{}),(0,u.jsxs)(xt,{className:`flex cursor-pointer gap-3`,onClick:_,children:[(0,u.jsx)(d.Copy,{size:16}),(0,u.jsx)(`span`,{children:`复制`})]})]}),(0,u.jsxs)(xt,{onClick:v,className:`flex cursor-pointer gap-3`,children:[(0,u.jsx)(d.Trash2,{size:16}),(0,u.jsx)(`span`,{children:`删除`})]})]})]})})}):null};var On=Dn;function kn(){let{editor:e}=R(),t=(0,c.useEditorState)({editor:e,selector:e=>{let{selection:t,doc:n}=e.editor.state,r=fn(0)(t),i=pn(0)(t),a=0,o=0;return n.nodesBetween(t.from,t.to,e=>{e.type.name===`table`&&(a=e.childCount,o=e.firstChild?e.firstChild.childCount:0)}),{canAddColumnBefore:e.editor.can().addColumnBefore(),canAddColumnAfter:e.editor.can().addColumnAfter(),canDeleteColumn:e.editor.can().deleteColumn(),canAddRowBefore:e.editor.can().addRowBefore(),canAddRowAfter:e.editor.can().addRowAfter(),canDeleteRow:e.editor.can().deleteRow(),canSplitCell:e.editor.can().splitCell(),canMergeCell:e.editor.can().mergeCells(),canDeleteTable:e.editor.can().deleteTable(),isRowGripSelected:r?.some((e,n)=>un(n)(t)),isColumnGripSelected:i?.some((e,n)=>ln(n)(t)),rowCount:a,columnCount:o}}}),n=(0,l.useCallback)(({editor:e,state:t,view:n,from:r})=>{if(!t||!r)return!1;let i=n.domAtPos(r).node,a=n.nodeDOM(r)||i;return!e.isActive(`table`)||!a||dn(t.selection)?!1:Q(t.selection)},[]),r=n=>{console.log(`onAddColumn selectorState.columnCount`,t.columnCount),!(t.columnCount>=50)&&(n===`before`?e.chain().focus().addColumnBefore().run():e.chain().focus().addColumnAfter().run())},i=n=>{console.log(`onAddRow selectorState.rowCount`,t.rowCount),!(t.rowCount>=100)&&(n===`before`?e.chain().focus().addRowBefore().run():e.chain().focus().addRowAfter().run())};return(0,u.jsx)(le.BubbleMenu,{editor:e,pluginKey:`tableBubbleMenu`,shouldShow:n,updateDelay:0,className:`z-20`,options:{offset:{mainAxis:0,crossAxis:8},placement:`top-start`,onShow:()=>{},onHide:()=>{console.log(`tableBubbleMenu onHidden`)}},children:(0,u.jsxs)(`div`,{className:`border-line z-50 flex w-full items-center gap-3 rounded-xl border bg-white px-3 py-2 shadow-[0px_0px_20px_0px_rgba(0,0,0,0.1)]`,children:[t.isColumnGripSelected&&(0,u.jsx)(G,{tooltip:`在前面插入列`,onClick:()=>{r(`before`)},"tooltip-options":{sideOffset:15},disabled:!t.canAddColumnBefore,children:(0,u.jsx)(d.ArrowLeftToLine,{size:20})}),t.isColumnGripSelected&&(0,u.jsx)(G,{tooltip:`在后面插入列`,onClick:()=>{r(`after`)},"tooltip-options":{sideOffset:15},disabled:!t.canAddColumnAfter,children:(0,u.jsx)(d.ArrowRightToLine,{size:20})}),t.isColumnGripSelected&&(0,u.jsx)(G,{tooltip:`删除列`,onClick:()=>{e.chain().focus().deleteColumn().run()},"tooltip-options":{sideOffset:15},disabled:!t.canDeleteColumn,children:(0,u.jsx)(d.Trash2,{size:20})}),t.isRowGripSelected&&(0,u.jsx)(G,{onClick:()=>{i(`before`)},tooltip:`在上面插入行`,"tooltip-options":{sideOffset:15},disabled:!t.canAddRowBefore,children:(0,u.jsx)(d.ArrowUpToLine,{size:20})}),t.isRowGripSelected&&(0,u.jsx)(G,{onClick:()=>{i(`after`)},tooltip:`在下面插入行`,"tooltip-options":{sideOffset:15},disabled:!t.canAddRowBefore,children:(0,u.jsx)(d.ArrowDownToLine,{size:20})}),t.isRowGripSelected&&(0,u.jsx)(G,{onClick:()=>{e.chain().focus().deleteRow().run()},tooltip:`删除行`,"tooltip-options":{sideOffset:15},disabled:!t.canDeleteRow,children:(0,u.jsx)(d.Trash2,{size:20})}),(0,u.jsx)(G,{onClick:()=>{e.chain().focus().mergeCells().run()},tooltip:`合并单元格`,"tooltip-options":{sideOffset:15},disabled:!t.canMergeCell,children:(0,u.jsx)(d.TableCellsMerge,{size:20})}),(0,u.jsx)(G,{onClick:()=>{e.chain().focus().splitCell().run()},tooltip:`拆分单元格`,"tooltip-options":{sideOffset:15},disabled:!t.canSplitCell,children:(0,u.jsx)(d.TableCellsSplit,{size:20})})]})})}var An=(0,l.memo)(kn);const jn=({value:e,onChange:t,onImageUpload:n,className:r,showToolbar:i=!0,showBubbleMenu:a=!0,showTableMenu:o=!0,showBlockMenu:s=!0,toolbarProps:l,onInitEditor:d})=>{let f=(0,c.useEditor)({immediatelyRender:!1,extensions:Sn({uploadFn:n}),content:e,editorProps:{attributes:{class:`w-full focus:outline-none`}},onUpdate:({editor:e})=>{t(e.getHTML())},onCreate:({editor:e})=>{d?.(e)}});return f?(0,u.jsxs)(pe,{editor:f,children:[i&&(0,u.jsx)(_t,{...l}),a&&(0,u.jsx)(wn,{}),o&&(0,u.jsx)(An,{}),s&&(0,u.jsx)(On,{}),(0,u.jsx)(c.EditorContent,{editor:f,className:U(`w-full`,r)})]}):null};exports.TiptapComponent=jn,exports.Toolbar=_t;
4
+ //# sourceMappingURL=index.cjs.map