@wair/editor 0.0.2-beta.1 → 0.0.3
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 +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +233 -369
- package/dist/index.css.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -6
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
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(`@radix-ui/react-slot`),v=require(`@radix-ui/react-popover`);v=s(v);let y=require(`@radix-ui/react-label`);y=s(y);let b=require(`@radix-ui/react-separator`);b=s(b);let x=require(`@tiptap/starter-kit`);x=s(x);let S=require(`@tiptap/extension-text-style`),C=require(`@tiptap/extension-text-align`);C=s(C);let w=require(`@tiptap/extensions`),ee=require(`@tiptap/extension-list`),T=require(`@tiptap/extension-file-handler`);T=s(T);let E=require(`@tiptap/extension-code-block-lowlight`);E=s(E);let D=require(`lowlight`),O=require(`copy-to-clipboard`);O=s(O);let k=require(`@radix-ui/react-dropdown-menu`);k=s(k);let te=require(`@tiptap/extension-image`),ne=require(`react-medium-image-zoom`);require(`react-medium-image-zoom/dist/styles.css`);let A=require(`@tiptap/pm/transform`),j=require(`highlight.js/lib/languages/css`);j=s(j);let M=require(`highlight.js/lib/languages/javascript`);M=s(M);let N=require(`highlight.js/lib/languages/typescript`);N=s(N);let P=require(`highlight.js/lib/languages/xml`);P=s(P),require(`highlight.js/styles/github.css`);let F=require(`@tiptap/core`),re=require(`@tiptap/extension-link`);re=s(re);let I=require(`@tiptap/pm/state`),ie=require(`@tiptap/extension-table`),L=require(`@tiptap/pm/view`),R=require(`@tiptap/pm/tables`),ae=require(`@tiptap/extension-mathematics`),oe=require(`@tiptap/react/menus`),se=require(`@floating-ui/react`),ce=require(`@tiptap/extension-drag-handle-react`);const le=(0,l.createContext)({}),z=()=>{let e=(0,l.useContext)(le);if(!e)throw Error(`useCurrentEditor 必须在 EditorProvider 内部使用`);if(!e.editor)throw Error(`EditorProvider 未提供 editor`);return e},ue=({editor:e,children:t})=>e?(0,u.jsx)(le.Provider,{value:{editor:e},children:t}):null,de={1:d.Heading1,2:d.Heading2,3:d.Heading3,4:d.Heading4,5:d.Heading5,6:d.Heading6},B=e=>({label:`标题${e}`,icon:de[e],id:`heading${e}`,onClick:t=>t.chain().focus().clearNodes().setHeading({level:e}).run(),isActive:t=>t[`isHeading${e}`]}),V={label:`撤销`,icon:d.Undo2,id:`undo`,onClick:e=>e.chain().focus().undo().run(),disabled:e=>!e.canUndo,shortcutKeys:[`mod`,`Z`]},H={label:`重做`,icon:d.Redo2,id:`redo`,onClick:e=>e.chain().focus().redo().run(),disabled:e=>!e.canRedo,shortcutKeys:[`mod`,`shift`,`Z`]},fe={label:`正文`,icon:d.Type,id:`paragraph`,onClick:e=>e.chain().focus().clearNodes().setParagraph().run(),isActive:e=>e.isParagraph},pe={label:`引用`,icon:d.Quote,id:`blockquote`,onClick:e=>e.chain().focus().clearNodes().setBlockquote().run(),isActive:e=>e.isBlockquote},me={label:`代码块`,icon:d.CodeXml,id:`codeBlock`,onClick:e=>e.chain().focus().clearNodes().setCodeBlock().run(),isActive:e=>e.isCodeBlock},he={label:`有序列表`,icon:d.ListOrdered,id:`orderedList`,onClick:e=>e.chain().focus().clearNodes().toggleOrderedList().run(),isActive:e=>e.isOrderedList},ge={label:`无序列表`,icon:d.List,id:`bulletList`,onClick:e=>e.chain().focus().clearNodes().toggleBulletList().run(),isActive:e=>e.isBulletList},_e={label:`待办任务`,icon:d.ListTodo,id:`todoList`,onClick:e=>e.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e.isTaskList},ve={select:[B(1),B(2),B(3),B(4),B(5),fe,pe,me],out:[ge,he,_e]},ye={label:`左对齐`,icon:d.AlignLeft,id:`leftAlign`,onClick:e=>e.chain().setTextAlign(`left`).run(),isActive:e=>e.isAlignLeft},be={label:`右对齐`,icon:d.AlignRight,id:`rightAlign`,onClick:e=>e.chain().setTextAlign(`right`).run(),isActive:e=>e.isAlignRight},xe={label:`居中对齐`,icon:d.AlignCenter,id:`centerAlign`,onClick:e=>e.chain().setTextAlign(`center`).run(),isActive:e=>e.isAlignCenter},Se={label:`两端对齐`,icon:d.AlignJustify,id:`justifyAlign`,onClick:e=>e.chain().setTextAlign(`justify`).run(),isActive:e=>e.isAlignJustify},Ce=[ye,be,xe,Se],we={label:`加粗`,icon:d.BoldIcon,id:`bold`,onClick:e=>e.chain().focus().toggleBold().run(),isActive:e=>e.isBold,disabled:e=>!e.canBold,shortcutKeys:[`mod`,`B`]},Te={label:`斜体`,icon:d.ItalicIcon,id:`italic`,onClick:e=>e.chain().focus().toggleItalic().run(),isActive:e=>e.isItalic,disabled:e=>!e.canItalic,shortcutKeys:[`mod`,`I`]},Ee={label:`下划线`,icon:d.UnderlineIcon,id:`underline`,onClick:e=>e.chain().focus().toggleUnderline().run(),isActive:e=>e.isUnderline,disabled:e=>!e.canUnderline,shortcutKeys:[`mod`,`U`]},De={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`]},Oe={label:`行内代码`,icon:d.Code,id:`inlineCode`,onClick:e=>e.chain().focus().toggleCode().run(),isActive:e=>e.isCode,disabled:e=>!e.canCode,shortcutKeys:[`mod`,`E`]},ke=[we,Te,Ee,De,Oe],Ae=[B(1),B(2),B(3),B(4),B(5),fe,pe,me,ge,he,_e];function U(...e){return(0,h.twMerge)((0,m.clsx)(e))}const je=(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`}}),Me=l.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,u.jsx)(f.Root,{ref:i,"data-slot":`toggle`,className:U(je({variant:t,size:n,className:e})),...r}));Me.displayName=f.Root.displayName;function Ne({delayDuration:e=0,...t}){return(0,u.jsx)(g.Provider,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Pe({...e}){return(0,u.jsx)(Ne,{children:(0,u.jsx)(g.Root,{"data-slot":`tooltip`,...e})})}function Fe({...e}){return(0,u.jsx)(g.Trigger,{"data-slot":`tooltip-trigger`,...e})}function Ie({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:U(`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 Le=(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?_.Slot:`button`,{ref:a,"data-slot":`button`,"data-variant":t,"data-size":n,className:U(Le({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)(Me,{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)(Ne,{delayDuration:300,children:(0,u.jsxs)(Pe,{children:[(0,u.jsx)(Fe,{asChild:!0,children:c}),(0,u.jsx)(Ie,{...i,children:(0,u.jsx)(`div`,{className:`flex flex-col items-center text-center`,children:n})})]})}):c});G.displayName=`ToolbarButton`;const Re=l.memo(l.forwardRef(({children:e,tooltip:t,className:n,...r},i)=>(0,u.jsx)(Ne,{children:(0,u.jsxs)(Pe,{children:[(0,u.jsx)(Fe,{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)(Ie,{side:`bottom`,children:t})]})})));function K({...e}){return(0,u.jsx)(v.Root,{"data-slot":`popover`,...e})}function q({...e}){return(0,u.jsx)(v.Trigger,{"data-slot":`popover-trigger`,...e})}function J({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,u.jsx)(v.Portal,{children:(0,u.jsx)(v.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 Y=()=>{let{editor:e}=z();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`)}}})},ze=({nodeFormatActions:e})=>{let{editor:t}=z(),n=Y(),r=e.find(e=>e.isActive?.(n))??fe;return(0,u.jsxs)(K,{children:[(0,u.jsx)(q,{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)(J,{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 Be=(0,l.memo)(ze);const Ve=({textFormatActions:e,tooltipOptions:t})=>{let{editor:n}=z(),r=Y();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 He=(0,l.memo)(Ve);function Ue({className:e,...t}){return(0,u.jsx)(y.Root,{"data-slot":`label`,className:U(`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 We({className:e,type:t,...n}){return(0,u.jsx)(`input`,{type:t,"data-slot":`input`,className:U(`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 Ge=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)(Ue,{children:`链接`}),(0,u.jsx)(We,{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)(Ue,{children:`文本`}),(0,u.jsx)(We,{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:`保存`})})]})})});Ge.displayName=`LinkEditPanel`;const Ke=({tooltipOptions:e})=>{let{editor:t}=z(),{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)(K,{defaultOpen:i,children:[(0,u.jsx)(q,{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)(J,{align:`center`,className:`z-50 w-max`,sideOffset:18,children:(0,u.jsx)(Ge,{defaultUrl:n,defaultText:r,onSave:a})})]})};var qe=Ke;const Je=`#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(`.`),Ye=()=>{let{editor:e}=z(),{activeColorItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeColorItem:Je.find(t=>e.isActive(`textStyle`,{color:t}))})});return(0,u.jsxs)(v.Root,{children:[(0,u.jsx)(v.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)(v.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:Je.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 Xe=Ye;const Ze=[`#FF0000`,`#FF4C4C`,`#FFB2B2`,`#FF964A`,`#FFB580`,`#FFDFC9`,`#FFDA36`,`#FFE572`,`#FFF4C3`,`#19EA73`,`#5EF09D`,`#BAF9D5`,`#00BBE5`,`#4CCFED`,`#B2EBF7`,`#075EFF`,`#518EFF`,`#B5CFFF`,`#B46AFF`,`#CA97FF`,`#E8D2FF`,`#707070`,`#B8B8B8`,`#E7E7E7`],Qe=()=>{let{editor:e}=z(),{activeHighlightItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeHighlightItem:Ze.find(t=>e.isActive(`highlight`,{color:t}))})});return(0,u.jsxs)(v.Root,{children:[(0,u.jsx)(v.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)(v.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:Ze.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 $e=Qe;const et=()=>{let{editor:e}=z(),[t,n]=(0,l.useState)(!1),r=Y(),i=Ce.find(e=>e.isActive?.(r))??ye;return(0,u.jsxs)(K,{open:t,onOpenChange:n,children:[(0,u.jsx)(q,{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)(J,{className:`border-line z-50 w-40 rounded-xl border bg-white px-2 py-1 shadow-xl`,align:`start`,sideOffset:18,children:Ce.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 tt=(0,l.memo)(et);const nt=()=>{let{editor:e}=z();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 rt=nt;const it=10,at=100,ot=50,st=2,ct=10,lt=840,ut=120,dt=e=>Array.from({length:e}).map((e,t)=>t+1);function ft(){let{editor:e}=z(),{canTable:t,isTable:n}=Y();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)(K,{children:[(0,u.jsx)(q,{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)(J,{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:dt(o?.rows)?.map(e=>(0,u.jsx)(`div`,{className:`flex gap-1`,children:dt(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 pt=ft;function mt({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,u.jsx)(b.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 ht=[`undo`,`redo`,`separator`,`node-selector`,`text-selector`,`link`,`color`,`bg`,`align`,`separator`,`image`,`table`],gt=({config:e=ht,appendItems:t})=>{let{editor:n}=z(),r=Y();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(V),tooltip:V.label,shortcutKeys:V.shortcutKeys,children:(0,u.jsx)(V.icon,{size:20})},t);case`redo`:return(0,u.jsx)(G,{...i(H),tooltip:H.label,shortcutKeys:H.shortcutKeys,children:(0,u.jsx)(H.icon,{size:20})},t);case`separator`:return(0,u.jsx)(mt,{orientation:`vertical`,className:`bg-line h-4`},t);case`node-selector`:return(0,u.jsx)(Be,{nodeFormatActions:ve.select},t);case`text-selector`:return(0,u.jsx)(He,{textFormatActions:ke},t);case`link`:return(0,u.jsx)(qe,{},t);case`color`:return(0,u.jsx)(Xe,{},t);case`bg`:return(0,u.jsx)($e,{},t);case`align`:return(0,u.jsx)(tt,{},t);case`image`:return(0,u.jsx)(rt,{},t);case`table`:return(0,u.jsx)(pt,{},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 _t({...e}){return(0,u.jsx)(k.Root,{"data-slot":`dropdown-menu`,...e})}function vt({...e}){return(0,u.jsx)(k.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function yt({className:e,sideOffset:t=4,...n}){return(0,u.jsx)(k.Portal,{children:(0,u.jsx)(k.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 X({className:e,inset:t,variant:n=`default`,...r}){return(0,u.jsx)(k.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 bt({className:e,...t}){return(0,u.jsx)(k.Separator,{"data-slot":`dropdown-menu-separator`,className:U(`bg-border -mx-1 my-1 h-px`,e),...t})}const xt=({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)(_t,{children:[(0,u.jsx)(vt,{asChild:!0,children:(0,u.jsx)(`span`,{className:`min-w-[50px] cursor-pointer text-sm text-[#999]`,children:e||`请选择语言`})}),(0,u.jsx)(yt,{className:`max-h-96 overflow-y-auto`,children:n.options.lowlight.listLanguages().map((e,t)=>(0,u.jsx)(X,{onClick:()=>{r({language:e})},children:e},t))})]}),(0,u.jsx)(`div`,{className:`flex gap-1`,children:(0,u.jsx)(Re,{onClick:()=>{(0,O.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`})})})]})},St=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)(xt,{content:a,language:i,extension:n,updateAttributes:r})})};function Ct({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)}}const wt=({ref:e,className:t,isResizing:n=!1,...r})=>(0,u.jsx)(`div`,{className:U(`absolute top-1/2 h-10 max-h-full w-1.5 -translate-y-1/2 transform cursor-col-resize rounded border border-solid border-[var(--mt-transparent-foreground)] bg-[var(--mt-bg-secondary)] p-px transition-all`,`opacity-0 [backdrop-filter:saturate(1.8)_blur(20px)]`,{"opacity-80":n,"group-hover/node-image:opacity-80":!n},`before:absolute before:inset-y-0 before:-right-1 before:-left-1`,t),ref:e,...r});wt.displayName=`ResizeHandle`;const Tt=({children:e,className:t,...n})=>(0,u.jsx)(`div`,{className:U(`absolute top-3 right-3 flex flex-row rounded px-0.5 opacity-0 group-hover/node-image:opacity-100`,`border-[0.5px] bg-[var(--mt-bg-secondary)] [backdrop-filter:saturate(1.8)_blur(20px)]`,t),...n,children:e});Tt.displayName=`ActionWrapper`;const Et=({icon:e,tooltip:t,className:n,...r})=>(0,u.jsxs)(Pe,{children:[(0,u.jsx)(Fe,{asChild:!0,children:(0,u.jsx)(W,{variant:`ghost`,className:U(`text-muted-foreground hover:text-foreground relative flex h-7 w-7 flex-row rounded-none p-0`,`bg-transparent hover:bg-transparent`,n),...r,children:e})}),(0,u.jsx)(Ie,{side:`bottom`,children:t})]});Et.displayName=`ActionButton`;const Dt=[{key:`onView`,icon:(0,u.jsx)(d.Eye,{}),tooltip:`View image`},{key:`onDownload`,icon:(0,u.jsx)(d.DownloadIcon,{}),tooltip:`Download image`},{key:`onCopy`,icon:(0,u.jsx)(d.ClipboardCopyIcon,{}),tooltip:`Copy image to clipboard`},{key:`onCopyLink`,icon:(0,u.jsx)(d.Link2Icon,{}),tooltip:`Copy image link`,isLink:!0}],Ot=({shouldMerge:e=!1,isLink:t=!1,...n})=>{let[r,i]=l.useState(!1),a=l.useCallback((e,t)=>{e.preventDefault(),e.stopPropagation(),t?.()},[]),o=l.useMemo(()=>Dt.filter(e=>t||!e.isLink),[t]);return(0,u.jsx)(Tt,{className:U({"opacity-100":r}),children:e?(0,u.jsxs)(_t,{open:r,onOpenChange:i,children:[(0,u.jsx)(vt,{asChild:!0,children:(0,u.jsx)(Et,{icon:(0,u.jsx)(d.DotIcon,{}),tooltip:`Open menu`,onClick:e=>e.preventDefault()})}),(0,u.jsx)(yt,{className:`w-56`,align:`end`,children:o.map(({key:e,icon:t,tooltip:r})=>(0,u.jsx)(X,{onClick:t=>a(t,n[e]),children:(0,u.jsxs)(`div`,{className:`flex flex-row items-center gap-2`,children:[t,(0,u.jsx)(`span`,{children:r})]})},e))})]}):o.map(({key:e,icon:t,tooltip:r})=>(0,u.jsx)(Et,{icon:t,tooltip:r,onClick:t=>a(t,n[e])},e))})};Ot.displayName=`ImageActions`;const kt=(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}},At=(e,t={})=>{if(e)return t.allowBase64&&e.startsWith(`data:image`)?kt(e,{requireHostname:!1,allowBase64:!0})?e:void 0:kt(e,{requireHostname:!1,allowBase64:t.allowBase64})||/^(\/|#|mailto:|sms:|fax:|tel:)/.test(e)?e:`https://${e}`},jt=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)})},Z=()=>Math.random().toString(36).slice(2,11),Mt=(e,t,n,r,i)=>{let{isValidType:a,isValidSize:o}=Nt(e,t);a&&o?r.push(n):(a||i.push({file:e,reason:`type`}),o||i.push({file:e,reason:`size`}))},Nt=(e,{allowedMimeTypes:t,maxFileSize:n})=>{let r=e instanceof File?e.type:Pt(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}},Pt=e=>{let t=e.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);return t&&t.length>1?t[1]:`unknown`},Ft=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}},It=(e,t)=>{let n=[],r=[];return e.forEach(e=>{let i=`src`in e?e.src:e;i instanceof File?Mt(i,t,e,n,r):typeof i==`string`&&(Ft(i)?t.allowBase64?Mt(i,t,e,n,r):r.push({file:i,reason:`base64NotAllowed`}):At(i,{allowBase64:t.allowBase64})?n.push(e):r.push({file:i,reason:`invalidBase64`}))}),[n,r]},Lt=({editor:e,node:t,src:n,onViewClick:r})=>({isLink:kt(n),onView:l.useCallback(()=>{r(!0)},[r]),onDownload:l.useCallback(()=>{e.commands.downloadImage({src:t.attrs.src,alt:t.attrs.alt})},[e.commands,t.attrs.alt,t.attrs.src]),onCopy:l.useCallback(()=>{e.commands.copyImage({src:t.attrs.src})},[e.commands,t.attrs.src]),onCopyLink:l.useCallback(()=>{e.commands.copyLink({src:t.attrs.src})},[e.commands,t.attrs.src]),onRemoveImg:l.useCallback(()=>{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})},[e.commands])});function Rt({className:e,...t}){return(0,u.jsx)(d.Loader2Icon,{role:`status`,"aria-label":`Loading`,className:U(`size-4 animate-spin`,e),...t})}const zt=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)(Rt,{className:`size-7`})}));zt.displayName=`ImageOverlay`;const Bt=600,Vt=120,Ht=120,Ut=e=>({src:typeof e==`string`?e:e.src,id:typeof e==`string`?Z():e.id}),Wt=({editor:e,node:t,selected:n,updateAttributes:r})=>{let{src:i,width:a,height:o,fileName:s}=t.attrs,f=l.useRef(!1),p=l.useMemo(()=>typeof i==`string`?i:i.src,[i]),[m,h]=l.useState({src:p,isServerUploading:!1,imageLoaded:!1,isZoomed:!1,error:!1,naturalSize:{width:a,height:o}}),g=l.useRef(null),[_,v]=l.useState(null),y=l.useCallback(({width:e,height:t})=>{r({width:e,height:t})},[r]),b=600*(m.naturalSize.width/m.naturalSize.height),x=g.current?parseFloat(getComputedStyle(g.current).getPropertyValue(`--editor-width`)):1/0,{isLink:S,onView:C,onDownload:w,onCopy:ee,onCopyLink:T,onRemoveImg:E}=Lt({editor:e,node:t,src:m.src,onViewClick:e=>h(t=>({...t,isZoomed:e}))}),{currentWidth:D,currentHeight:O,updateDimensions:k,initiateResize:te,isResizing:A}=Ct({initialWidth:a??m.naturalSize.width,initialHeight:o??m.naturalSize.height,contentWidth:m.naturalSize.width,contentHeight:m.naturalSize.height,gridInterval:.1,onDimensionsChange:y,minWidth:120,minHeight:120,maxWidth:x>0?x:b}),j=l.useMemo(()=>D<=180,[D]),M=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||k(e=>({...e,width:n.width}))},[a,r,k]),N=l.useCallback(()=>{h(e=>({...e,error:!0,imageLoaded:!0}))},[]),P=l.useCallback(e=>t=>{v(e),te(e)(t)},[te]),F=l.useCallback(()=>{v(null)},[]);return l.useEffect(()=>{A||F()},[A,F]),l.useEffect(()=>{(async()=>{if(!p.startsWith(`blob:`)||f.current)return;f.current=!0;let{uploadFn:t}=e.options.extensions.find(e=>e.name===`image`)?.options??{};if(!t){try{let e=await jt(p);h(t=>({...t,src:e})),r({src:e})}catch{h(e=>({...e,error:!0}))}return}try{h(e=>({...e,isServerUploading:!0}));let n=await(await fetch(p)).blob(),i=Ut(await t(new File([n],s,{type:n.type}),e));h(e=>({...e,...i,isServerUploading:!1})),r(i)}catch{h(e=>({...e,error:!0,isServerUploading:!1}))}})()},[e,s,p,r]),(0,u.jsx)(c.NodeViewWrapper,{ref:g,"data-drag-handle":!0,className:`relative text-center leading-none`,children:(0,u.jsx)(`div`,{className:`group/node-image relative mx-auto rounded-md object-contain`,style:{maxWidth:`min(${b}px, 100%)`,width:D,maxHeight:600,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`,{"outline-primary outline-2 outline-offset-1":n||A}),children:[(0,u.jsxs)(`div`,{className:`h-full contain-paint`,children:[(0,u.jsxs)(`div`,{className:`relative h-full`,children:[m.isServerUploading&&!m.error&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,u.jsx)(Rt,{className:`size-7`})}),m.error&&(0,u.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,u.jsx)(d.Info,{className:`text-destructive size-8`}),(0,u.jsx)(`p`,{className:`text-muted-foreground mt-2 text-sm`,children:`Failed to load image`})]}),(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%, ${b}px)`,minWidth:`120px`,maxHeight:840,cursor:`pointer`},onDoubleClick:()=>{h(e=>({...e,isZoomed:!0}))},width:D,height:O,src:m.src,onError:N,onLoad:M,alt:t.attrs.alt||``})})]}),m.isServerUploading&&(0,u.jsx)(zt,{}),e.isEditable&&m.imageLoaded&&!m.error&&!m.isServerUploading&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(wt,{onPointerDown:P(`left`),className:U(`left-1`,{hidden:A&&_===`right`}),isResizing:A&&_===`left`}),(0,u.jsx)(wt,{onPointerDown:P(`right`),className:U(`right-1`,{hidden:A&&_===`left`}),isResizing:A&&_===`right`})]})]}),m.error&&(0,u.jsx)(Tt,{children:(0,u.jsx)(Re,{tooltip:`移除图片`,onClick:E,children:(0,u.jsx)(d.Trash2,{className:`size-4`})})}),!A&&!m.error&&!m.isServerUploading&&(0,u.jsx)(Ot,{shouldMerge:j,isLink:S,onView:C,onDownload:w,onCopy:ee,onCopyLink:T})]})})})},Gt=(e,t,n)=>{let r=e instanceof Error?e:Error(`Unknown error`);n?.(r,t)},Kt=e=>{let[t,n]=e.split(`,`),r=t.split(`:`)[1].split(`;`)[0],i=r.split(`/`)[1],a=atob(n),o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);return{blob:new Blob([o],{type:r}),extension:i}},qt=async e=>{let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch image`);let n=await t.blob();return{blob:n,extension:n.type.split(/\/|\+/)[1]}},Jt=async e=>e.startsWith(`data:`)?Kt(e):qt(e),Yt=async(e,t,n)=>{let r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=`${t}.${n}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},Xt=async(e,t)=>{let{src:n,alt:r}=e,i=r||`image`;try{let{blob:r,extension:a}=await Jt(n);await Yt(r,i,a),t.onActionSuccess?.({...e,action:`download`})}catch(n){Gt(n,{...e,action:`download`},t.onActionError)}},Zt=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){Gt(n,{...e,action:`copyImage`},t.onActionError)}},Qt=async(e,t)=>{let{src:n}=e;try{await navigator.clipboard.writeText(n),t.onActionSuccess?.({...e,action:`copyLink`})}catch(n){Gt(n,{...e,action:`copyLink`},t.onActionError)}},$t=te.Image.extend({atom:!0,addOptions(){return{...this.parent?.()||{},inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1,allowedMimeTypes:[],maxFileSize:0,uploadFn:void 0,onToggle:void 0,downloadImage:void 0,copyImage:void 0,copyLink:void 0}},addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},id:{default:null},width:{default:null},height:{default:null},fileName:{default:null},align:{default:`center`,parseHTML:e=>e.getAttribute(`align`),renderHTML:e=>({align:e.align})}}},addCommands(){return{setImages:e=>({commands:t})=>{let[n,r]=It(e,{allowedMimeTypes:this.options.allowedMimeTypes,maxFileSize:this.options.maxFileSize,allowBase64:this.options.allowBase64});return r.length>0&&this.options.onValidationError&&this.options.onValidationError(r),n.length>0?t.insertContent(n.map(e=>{if(e.src instanceof File){let t=URL.createObjectURL(e.src),n=Z();return{type:this.type.name,attrs:{id:n,src:t,alt:e.alt,title:e.title,fileName:e.src.name}}}else return{type:this.type.name,attrs:{id:Z(),src:e.src,alt:e.alt,title:e.title,fileName:null}}})):!1},downloadImage:e=>()=>((this.options.downloadImage||Xt)({...e,action:`download`},this.options),!0),copyImage:e=>()=>((this.options.copyImage||Zt)({...e,action:`copyImage`},this.options),!0),copyLink:e=>()=>((this.options.copyLink||Qt)({...e,action:`copyLink`},this.options),!0),toggleImage:()=>({editor:e})=>{let t=document.createElement(`input`);return t.type=`file`,t.accept=this.options.allowedMimeTypes.join(`,`),t.onchange=()=>{let n=t.files;if(!n)return;let[r,i]=It(Array.from(n),{allowedMimeTypes:this.options.allowedMimeTypes,maxFileSize:this.options.maxFileSize,allowBase64:this.options.allowBase64});return i.length>0&&this.options.onValidationError?(this.options.onValidationError(i),!1):(r.length===0||this.options.onToggle&&this.options.onToggle(e,r,e.state.selection.from),!1)},t.click(),!0}}},onTransaction({transaction:e}){e.steps.forEach(t=>{t instanceof A.ReplaceStep&&t.slice.size===0&&e.before.content.cut(t.from,t.to).forEach(e=>{if(e.type.name===`image`){let t=e.attrs;t.src.startsWith(`blob:`)&&URL.revokeObjectURL(t.src),this.options.onImageRemoved?.(t)}})})},addNodeView(){return(0,c.ReactNodeViewRenderer)(Wt,{className:`block-node`})}}),en=re.default.extend({inclusive:!1,parseHTML(){return[{tag:`a[href]:not([data-type="button"]):not([href *= "javascript:" i])`}]},renderHTML({HTMLAttributes:e}){return[`a`,(0,F.mergeAttributes)(this.options.HTMLAttributes,e,{class:`link`}),0]},addProseMirrorPlugins(){return[...this.parent?.()||[],new I.Plugin({props:{handleClick(e,t){let{schema:n,doc:r,tr:i}=e.state,a=(0,F.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 I.TextSelection(u,d));e.dispatch(f)}}})]}});var tn=en;const nn={aiGenerationIsSelection:!1,aiGenerationIsLoading:!1,aiGenerationActive:!1,aiGenerationHasMessage:!1,commentInputVisible:!1,lockDragHandle:!1,isDragging:!1},rn=F.Extension.create({name:`uiState`,addStorage(){return{uiState:{...nn}}},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,{...nn}),!0)}},onCreate(){this.storage={...nn}}}),an=[`image`,`codeBlock`,`link`,`table`,`title`],on=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)},sn=(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=an.some(t=>e.isActive(t)),o=on(t);return a||o||i},cn=({editor:e})=>{let{doc:t,selection:n,selection:{empty:r,from:i,to:a}}=e.state,o=!t.textBetween(i,a).length&&(0,F.isTextSelection)(n);return!(r||o||!e.isEditable)},ln=e=>(0,F.findParentNode)(e=>e.type.spec.tableRole&&e.type.spec.tableRole===`table`)(e),un=e=>t=>{if(Q(t)){let n=R.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 R.CellSelection,dn=e=>t=>{if(Q(t)){let n=R.TableMap.get(t.$anchorCell.node(-1));return un({left:e,right:e+1,top:0,bottom:n.height})(t)}return!1},fn=e=>t=>Q(t)?un({left:0,right:R.TableMap.get(t.$anchorCell.node(-1)).width,top:e,bottom:e+1})(t):!1,pn=e=>{if(Q(e)){let t=R.TableMap.get(e.$anchorCell.node(-1));return un({left:0,right:t.width,top:0,bottom:t.height})(e)}return!1},mn=e=>t=>{let n=ln(t);if(n){let t=R.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},hn=e=>t=>{let n=ln(t);if(n){let t=R.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},gn=e=>t=>n=>{let r=ln(n.selection),i=e===`row`;if(r){let e=R.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 R.CellSelection(m,p))}}return n},_n=gn(`column`),vn=gn(`row`),yn=F.Node.create({name:`tableCell`,content:`block+`,tableRole:`cell`,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`td`}]},renderHTML({HTMLAttributes:e}){return[`td`,(0,F.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 I.Plugin({props:{decorations:t=>{if(!e)return L.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=mn(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(L.Decoration.widget(e+1,()=>{let e=fn(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(vn(t)(this.editor.state.tr))}),i}))}),L.DecorationSet.create(n,i)}}})]}}),bn=ie.TableHeader.extend({addProseMirrorPlugins(){let{isEditable:e}=this.editor;return[new I.Plugin({props:{decorations:t=>{if(!e)return L.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=hn(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(L.Decoration.widget(e+1,()=>{let e=dn(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(_n(t)(this.editor.state.tr))}),i}))}),L.DecorationSet.create(n,i)}}})]}}),xn=ie.TableRow.extend({allowGapCursor:!1}),Sn=ie.Table.extend({addOptions(){return{...this.parent?.(),resizable:!0,lastColumnResizable:!0,allowTableNodeSelection:!0,HTMLAttributes:{}}},addExtensions(){return[xn.configure(this.options.tableRow),bn.configure(this.options.tableHeader),yn.configure(this.options.tableCell)]}});var Cn=Sn;const $=(0,D.createLowlight)(D.common);$.register(`html`,P.default),$.register(`css`,j.default),$.register(`js`,M.default),$.register(`ts`,N.default);const wn=e=>{let{uploadFn:t}=e;return[S.TextStyleKit,x.default,w.Placeholder.configure({placeholder:({node:e})=>{let t=e?.type?.name;return t===`title`?`未命名文档`:t===`heading`?`标题${e.attrs.level}`:t===`codeBlock`?`请输入代码`:t===`table`?``:`请输入内容`}}),w.Focus.configure({className:`node-focused`,mode:`all`}),C.default.configure({types:[`heading`,`paragraph`]}),S.Color,S.BackgroundColor,ee.TaskList,ee.TaskItem,Cn,w.Gapcursor,$t.configure({allowedMimeTypes:[`image/*`],maxFileSize:10*1024*1024,allowBase64:!1,uploadFn:t,onActionSuccess(e){console.log(`Image action success:`,e)},onValidationError(e){e.forEach(e=>{})}}),w.Dropcursor,T.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)}})}}),w.Selection.configure({className:`selection`}),tn.configure({openOnClick:`whenNotEditable`}),E.default.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(St)}}).configure({lowlight:$}),rn,ae.Mathematics]},Tn=()=>{let{editor:e}=z();return(0,u.jsx)(oe.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 I.NodeSelection;return sn(e,o)||s?!1:cn({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)(mt,{orientation:`vertical`,className:`bg-line h-4`}),(0,u.jsx)(He,{textFormatActions:ke}),(0,u.jsx)(qe,{}),(0,u.jsx)(Xe,{}),(0,u.jsx)($e,{})]})})};var En=Tn;const Dn=({currentNode:e,currentNodePos:t})=>{let{editor:n}=z(),r=Y();return(0,u.jsx)(`div`,{className:`gap flex flex-wrap gap-[12px]`,children:Ae.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 On=Dn;const kn=({withSlashCommandTrigger:e=!0,mobileBreakpoint:t=768,...n})=>{let{editor:r}=z(),[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,se.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,O.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)(ce.DragHandle,{editor:r,onNodeChange:p,computePositionConfig:m,onElementDragStart:h,onElementDragEnd:g,...n,children:(0,u.jsxs)(_t,{open:i,onOpenChange:a,children:[(0,u.jsx)(vt,{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)(yt,{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)(On,{currentNode:o,currentNodePos:c}),(0,u.jsx)(bt,{}),(0,u.jsxs)(X,{className:`flex cursor-pointer gap-3`,onClick:_,children:[(0,u.jsx)(d.Copy,{size:16}),(0,u.jsx)(`span`,{children:`复制`})]})]}),(0,u.jsxs)(X,{onClick:v,className:`flex cursor-pointer gap-3`,children:[(0,u.jsx)(d.Trash2,{size:16}),(0,u.jsx)(`span`,{children:`删除`})]})]})]})})}):null};var An=kn;function jn(){let{editor:e}=z(),t=(0,c.useEditorState)({editor:e,selector:e=>{let{selection:t,doc:n}=e.editor.state,r=mn(0)(t),i=hn(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)=>fn(n)(t)),isColumnGripSelected:i?.some((e,n)=>dn(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||pn(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)(oe.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 Mn=(0,l.memo)(jn);const Nn=({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:wn({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)(ue,{editor:f,children:[i&&(0,u.jsx)(gt,{...l}),a&&(0,u.jsx)(En,{}),o&&(0,u.jsx)(Mn,{}),s&&(0,u.jsx)(An,{}),(0,u.jsx)(c.EditorContent,{editor:f,className:U(`w-full`,r)})]}):null};exports.TiptapComponent=Nn,exports.Toolbar=gt;
|
|
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(`lucide-react`),u=require(`react`);u=s(u);let d=require(`sonner`),f=require(`react/jsx-runtime`),p=require(`@floating-ui/react`),m=require(`@tiptap/extension-drag-handle-react`),h=require(`copy-to-clipboard`);h=s(h);let g=require(`@radix-ui/react-toggle`);g=s(g);let _=require(`class-variance-authority`),v=require(`clsx`),y=require(`tailwind-merge`),b=require(`@radix-ui/react-tooltip`);b=s(b);let x=require(`@radix-ui/react-slot`),S=require(`@radix-ui/react-dropdown-menu`);S=s(S);let C=require(`@tiptap/react/menus`),w=require(`@tiptap/core`),T=require(`@tiptap/pm/tables`),E=require(`@tiptap/pm/state`),D=require(`@radix-ui/react-separator`);D=s(D);let O=require(`@radix-ui/react-popover`);O=s(O);let ee=require(`@radix-ui/react-label`);ee=s(ee);let te=require(`@tiptap/extension-code-block-lowlight`);te=s(te);let ne=require(`@tiptap/extension-file-handler`);ne=s(ne);let re=require(`@tiptap/extension-list`),ie=require(`@tiptap/extension-text-align`);ie=s(ie);let ae=require(`@tiptap/extension-text-style`),k=require(`@tiptap/extensions`),A=require(`@tiptap/starter-kit`);A=s(A);let j=require(`highlight.js/lib/languages/css`);j=s(j);let M=require(`highlight.js/lib/languages/javascript`);M=s(M);let oe=require(`highlight.js/lib/languages/typescript`);oe=s(oe);let se=require(`highlight.js/lib/languages/xml`);se=s(se);let ce=require(`lowlight`),le=require(`@tiptap/extension-image`),ue=require(`react-medium-image-zoom`);require(`react-medium-image-zoom/dist/styles.css`),require(`highlight.js/styles/github.css`);let de=require(`@tiptap/extension-mathematics`),fe=require(`@tiptap/extension-link`);fe=s(fe);let pe=require(`@tiptap/extension-table`),N=require(`@tiptap/pm/view`);var me=(e,t,n,r,i,a,o,s)=>{let c=document.documentElement,l=[`light`,`dark`];function u(t){(Array.isArray(e)?e:[e]).forEach(e=>{let n=e===`class`,r=n&&a?i.map(e=>a[e]||e):i;n?(c.classList.remove(...r),c.classList.add(a&&a[t]?a[t]:t)):c.setAttribute(e,t)}),d(t)}function d(e){s&&l.includes(e)&&(c.style.colorScheme=e)}function f(){return window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}if(r)u(r);else try{let e=localStorage.getItem(t)||n;u(o&&e===`system`?f():e)}catch{}},he=[`light`,`dark`],ge=`(prefers-color-scheme: dark)`,_e=typeof window>`u`,ve=u.createContext(void 0),ye={setTheme:e=>{},themes:[]},be=()=>u.useContext(ve)??ye,xe=e=>u.useContext(ve)?u.createElement(u.Fragment,null,e.children):u.createElement(Ce,{...e}),Se=[`light`,`dark`],Ce=({forcedTheme:e,disableTransitionOnChange:t=!1,enableSystem:n=!0,enableColorScheme:r=!0,storageKey:i=`theme`,themes:a=Se,defaultTheme:o=n?`system`:`light`,attribute:s=`data-theme`,value:c,children:l,nonce:d,scriptProps:f})=>{let[p,m]=u.useState(()=>Te(i,o)),[h,g]=u.useState(()=>p===`system`?De():p),_=c?Object.values(c):a,v=u.useCallback(e=>{let i=e;if(!i)return;e===`system`&&n&&(i=De());let a=c?c[i]:i,l=t?Ee(d):null,u=document.documentElement,f=e=>{e===`class`?(u.classList.remove(..._),a&&u.classList.add(a)):e.startsWith(`data-`)&&(a?u.setAttribute(e,a):u.removeAttribute(e))};if(Array.isArray(s)?s.forEach(f):f(s),r){let e=he.includes(o)?o:null,t=he.includes(i)?i:e;u.style.colorScheme=t}l?.()},[d]),y=u.useCallback(e=>{let t=typeof e==`function`?e(p):e;m(t);try{localStorage.setItem(i,t)}catch{}},[p]),b=u.useCallback(t=>{g(De(t)),p===`system`&&n&&!e&&v(`system`)},[p,e]);u.useEffect(()=>{let e=window.matchMedia(ge);return e.addListener(b),b(e),()=>e.removeListener(b)},[b]),u.useEffect(()=>{let e=e=>{e.key===i&&(e.newValue?m(e.newValue):y(o))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[y]),u.useEffect(()=>{v(e??p)},[e,p]);let x=u.useMemo(()=>({theme:p,setTheme:y,forcedTheme:e,resolvedTheme:p===`system`?h:p,themes:n?[...a,`system`]:a,systemTheme:n?h:void 0}),[p,y,e,h,n,a]);return u.createElement(ve.Provider,{value:x},u.createElement(we,{forcedTheme:e,storageKey:i,attribute:s,enableSystem:n,enableColorScheme:r,defaultTheme:o,value:c,themes:a,nonce:d,scriptProps:f}),l)},we=u.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:i,defaultTheme:a,value:o,themes:s,nonce:c,scriptProps:l})=>{let d=JSON.stringify([n,t,a,e,s,o,r,i]).slice(1,-1);return u.createElement(`script`,{...l,suppressHydrationWarning:!0,nonce:typeof window>`u`?c:``,dangerouslySetInnerHTML:{__html:`(${me.toString()})(${d})`}})}),Te=(e,t)=>{if(_e)return;let n;try{n=localStorage.getItem(e)||void 0}catch{}return n||t},Ee=e=>{let t=document.createElement(`style`);return e&&t.setAttribute(`nonce`,e),t.appendChild(document.createTextNode(`*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`)),document.head.appendChild(t),()=>{window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(t)},1)}},De=e=>(e||=window.matchMedia(ge),e.matches?`dark`:`light`);const Oe=({...e})=>{let{theme:t=`system`}=be();return(0,f.jsx)(d.Toaster,{theme:t,className:`toaster group`,icons:{success:(0,f.jsx)(l.CircleCheck,{className:`h-4 w-4`}),info:(0,f.jsx)(l.Info,{className:`h-4 w-4`}),warning:(0,f.jsx)(l.TriangleAlert,{className:`h-4 w-4`}),error:(0,f.jsx)(l.OctagonX,{className:`h-4 w-4`}),loading:(0,f.jsx)(l.LoaderCircle,{className:`h-4 w-4 animate-spin`})},toastOptions:{classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})},ke=Math.min,Ae=Math.max,je={left:`right`,right:`left`,bottom:`top`,top:`bottom`},Me={start:`end`,end:`start`};function Ne(e,t,n){return Ae(e,ke(t,n))}function P(e,t){return typeof e==`function`?e(t):e}function F(e){return e.split(`-`)[0]}function Pe(e){return e.split(`-`)[1]}function Fe(e){return e===`x`?`y`:`x`}function Ie(e){return e===`y`?`height`:`width`}const Le=new Set([`top`,`bottom`]);function I(e){return Le.has(F(e))?`y`:`x`}function Re(e){return Fe(I(e))}function ze(e,t,n){n===void 0&&(n=!1);let r=Pe(e),i=Re(e),a=Ie(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=L(o)),[o,L(o)]}function Be(e){let t=L(e);return[Ve(e),t,Ve(t)]}function Ve(e){return e.replace(/start|end/g,e=>Me[e])}const He=[`left`,`right`],Ue=[`right`,`left`],We=[`top`,`bottom`],Ge=[`bottom`,`top`];function Ke(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Ue:He:t?He:Ue;case`left`:case`right`:return t?We:Ge;default:return[]}}function qe(e,t,n,r){let i=Pe(e),a=Ke(F(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Ve)))),a}function L(e){return e.replace(/left|right|bottom|top/g,e=>je[e])}function Je(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ye(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Je(e)}function Xe(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}async function Ze(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=P(t,e),p=Ye(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Xe(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Xe(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}const Qe=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=P(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=F(r),_=I(o),v=F(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[L(o)]:Be(o)),x=p!==`none`;!d&&x&&b.push(...qe(o,m,p,y));let S=[o,...b],C=await Ze(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=ze(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==I(t))||T.every(e=>I(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=I(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}},$e=new Set([`left`,`top`]);async function et(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=F(n),s=Pe(n),c=I(n)===`y`,l=$e.has(o)?-1:1,u=a&&c?-1:1,d=P(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const tt=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await et(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},nt=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i}=t,{mainAxis:a=!0,crossAxis:o=!1,limiter:s={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...c}=P(e,t),l={x:n,y:r},u=await Ze(t,c),d=I(F(i)),f=Fe(d),p=l[f],m=l[d];if(a){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=p+u[e],r=p-u[t];p=Ne(n,p,r)}if(o){let e=d===`y`?`top`:`left`,t=d===`y`?`bottom`:`right`,n=m+u[e],r=m-u[t];m=Ne(n,m,r)}let h=s.fn({...t,[f]:p,[d]:m});return{...h,data:{x:h.x-n,y:h.y-r,enabled:{[f]:a,[d]:o}}}}}},rt=tt,it=nt,at=Qe,ot=(0,u.createContext)({}),R=()=>{let e=(0,u.useContext)(ot);if(!e)throw Error(`useCurrentEditor 必须在 EditorProvider 内部使用`);if(!e.editor)throw Error(`EditorProvider 未提供 editor`);return e},st=({editor:e,children:t})=>e?(0,f.jsx)(ot.Provider,{value:{editor:e},children:t}):null,z=()=>{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`)}}})};function B(...e){return(0,y.twMerge)((0,v.clsx)(e))}const ct=(0,_.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`}}),lt=u.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,f.jsx)(g.Root,{ref:i,"data-slot":`toggle`,className:B(ct({variant:t,size:n,className:e})),...r}));lt.displayName=g.Root.displayName;function V({delayDuration:e=0,...t}){return(0,f.jsx)(b.Provider,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function ut({...e}){return(0,f.jsx)(V,{children:(0,f.jsx)(b.Root,{"data-slot":`tooltip`,...e})})}function dt({...e}){return(0,f.jsx)(b.Trigger,{"data-slot":`tooltip-trigger`,...e})}function ft({className:e,sideOffset:t=0,children:n,...r}){return(0,f.jsx)(b.Portal,{children:(0,f.jsxs)(b.Content,{"data-slot":`tooltip-content`,sideOffset:t,className:B(`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,f.jsx)(b.Arrow,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}const pt=(0,_.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`}}),H=u.forwardRef(({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i},a)=>(0,f.jsx)(r?x.Slot:`button`,{ref:a,"data-slot":`button`,"data-variant":t,"data-size":n,className:B(pt({variant:t,size:n,className:e})),...i}));H.displayName=`Button`;const U=u.forwardRef(({isActive:e,children:t,tooltip:n,className:r,tooltipOptions:i,shortcutKeys:a,...o},s)=>{let c=(0,f.jsx)(lt,{size:`sm`,ref:s,className:B(`text-content-first size-7 gap-1 rounded border-none p-0`,{"bg-primary/5":e},r),...o,children:t});return n?(0,f.jsx)(V,{delayDuration:300,children:(0,f.jsxs)(ut,{children:[(0,f.jsx)(dt,{asChild:!0,children:c}),(0,f.jsx)(ft,{...i,children:(0,f.jsx)(`div`,{className:`flex flex-col items-center text-center`,children:n})})]})}):c});U.displayName=`ToolbarButton`;const W=u.memo(u.forwardRef(({children:e,tooltip:t,className:n,...r},i)=>(0,f.jsx)(V,{children:(0,f.jsxs)(ut,{children:[(0,f.jsx)(dt,{children:(0,f.jsx)(H,{ref:i,variant:`ghost`,className:B(`text-content-first relative flex size-7 flex-row rounded p-0`,`bg-transparent hover:bg-transparent`,n),...r,children:e})}),(0,f.jsx)(ft,{side:`bottom`,children:t})]})}))),mt={1:l.Heading1,2:l.Heading2,3:l.Heading3,4:l.Heading4,5:l.Heading5,6:l.Heading6},G=e=>({label:`标题${e}`,icon:mt[e],id:`heading${e}`,onClick:t=>t.chain().focus().clearNodes().setHeading({level:e}).run(),isActive:t=>t[`isHeading${e}`]}),K={label:`撤销`,icon:l.Undo2,id:`undo`,onClick:e=>e.chain().focus().undo().run(),disabled:e=>!e.canUndo,shortcutKeys:[`mod`,`Z`]},q={label:`重做`,icon:l.Redo2,id:`redo`,onClick:e=>e.chain().focus().redo().run(),disabled:e=>!e.canRedo,shortcutKeys:[`mod`,`shift`,`Z`]},ht={label:`正文`,icon:l.Type,id:`paragraph`,onClick:e=>e.chain().focus().clearNodes().setParagraph().run(),isActive:e=>e.isParagraph},gt={label:`引用`,icon:l.Quote,id:`blockquote`,onClick:e=>e.chain().focus().clearNodes().setBlockquote().run(),isActive:e=>e.isBlockquote},_t={label:`代码块`,icon:l.CodeXml,id:`codeBlock`,onClick:e=>e.chain().focus().clearNodes().setCodeBlock().run(),isActive:e=>e.isCodeBlock},vt={label:`有序列表`,icon:l.ListOrdered,id:`orderedList`,onClick:e=>e.chain().focus().clearNodes().toggleOrderedList().run(),isActive:e=>e.isOrderedList},yt={label:`无序列表`,icon:l.List,id:`bulletList`,onClick:e=>e.chain().focus().clearNodes().toggleBulletList().run(),isActive:e=>e.isBulletList},bt={label:`待办任务`,icon:l.ListTodo,id:`todoList`,onClick:e=>e.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e.isTaskList},xt={select:[G(1),G(2),G(3),G(4),G(5),ht,gt,_t],out:[yt,vt,bt]},St={label:`左对齐`,icon:l.AlignLeft,id:`leftAlign`,onClick:e=>e.chain().setTextAlign(`left`).run(),isActive:e=>e.isAlignLeft},Ct={label:`右对齐`,icon:l.AlignRight,id:`rightAlign`,onClick:e=>e.chain().setTextAlign(`right`).run(),isActive:e=>e.isAlignRight},wt={label:`居中对齐`,icon:l.AlignCenter,id:`centerAlign`,onClick:e=>e.chain().setTextAlign(`center`).run(),isActive:e=>e.isAlignCenter},Tt={label:`两端对齐`,icon:l.AlignJustify,id:`justifyAlign`,onClick:e=>e.chain().setTextAlign(`justify`).run(),isActive:e=>e.isAlignJustify},Et=[St,Ct,wt,Tt],Dt={label:`加粗`,icon:l.BoldIcon,id:`bold`,onClick:e=>e.chain().focus().toggleBold().run(),isActive:e=>e.isBold,disabled:e=>!e.canBold,shortcutKeys:[`mod`,`B`]},Ot={label:`斜体`,icon:l.ItalicIcon,id:`italic`,onClick:e=>e.chain().focus().toggleItalic().run(),isActive:e=>e.isItalic,disabled:e=>!e.canItalic,shortcutKeys:[`mod`,`I`]},kt={label:`下划线`,icon:l.UnderlineIcon,id:`underline`,onClick:e=>e.chain().focus().toggleUnderline().run(),isActive:e=>e.isUnderline,disabled:e=>!e.canUnderline,shortcutKeys:[`mod`,`U`]},At={label:`删除线`,icon:l.StrikethroughIcon,id:`strike`,onClick:e=>e.chain().focus().toggleStrike().run(),isActive:e=>e.isStrike,disabled:e=>!e.canStrike,shortcutKeys:[`mod`,`shift`,`S`]},jt={label:`行内代码`,icon:l.Code,id:`inlineCode`,onClick:e=>e.chain().focus().toggleCode().run(),isActive:e=>e.isCode,disabled:e=>!e.canCode,shortcutKeys:[`mod`,`E`]},Mt=[Dt,Ot,kt,At,jt],Nt=[G(1),G(2),G(3),G(4),G(5),ht,gt,_t,yt,vt,bt],Pt=({currentNode:e,currentNodePos:t})=>{let{editor:n}=R(),r=z();return(0,f.jsx)(`div`,{className:`gap flex flex-wrap gap-[12px]`,children:Nt.map(e=>(0,f.jsx)(U,{isActive:e.isActive?.(r),onClick:()=>e.onClick(n),disabled:e.disabled?.(r),tooltip:e.label,shortcutKeys:e.shortcutKeys,children:(0,f.jsx)(e.icon,{size:20})},e.id))})};var Ft=Pt;function It({...e}){return(0,f.jsx)(S.Root,{"data-slot":`dropdown-menu`,...e})}function Lt({...e}){return(0,f.jsx)(S.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function Rt({className:e,sideOffset:t=4,...n}){return(0,f.jsx)(S.Portal,{children:(0,f.jsx)(S.Content,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:B(`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 zt({className:e,inset:t,variant:n=`default`,...r}){return(0,f.jsx)(S.Item,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:B(`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 Bt({className:e,...t}){return(0,f.jsx)(S.Separator,{"data-slot":`dropdown-menu-separator`,className:B(`bg-border -mx-1 my-1 h-px`,e),...t})}const Vt=()=>{let{editor:e}=R();if(!e||e.isDestroyed)return null;let[t,n]=(0,u.useState)(!1),[r,i]=(0,u.useState)(null),[a,o]=(0,u.useState)(-1),s=(0,u.useCallback)(e=>{e.node&&i(e.node),o(e.pos)},[]),{refs:c,floatingStyles:d,context:g}=(0,p.useFloating)({open:t,onOpenChange:n,placement:`right-start`,whileElementsMounted:p.autoUpdate,middleware:[(0,p.offset)(8),(0,p.flip)(),(0,p.shift)()]}),{getReferenceProps:_,getFloatingProps:v}=(0,p.useInteractions)([(0,p.useClick)(g),(0,p.useDismiss)(g)]);return(0,f.jsxs)(It,{children:[(0,f.jsx)(m.DragHandle,{pluginKey:`block-drag-handle`,editor:e,onNodeChange:s,className:`transition-all duration-200 ease-in-out z-50 will-change-transform`,computePositionConfig:{middleware:[rt(10),at(),it({padding:5})]},children:(0,f.jsx)(Lt,{asChild:!0,children:(0,f.jsx)(`div`,{className:`
|
|
3
|
+
p-0.5 rounded-md cursor-grab active:cursor-grabbing transition-colors
|
|
4
|
+
${t?`bg-blue-100 text-blue-600`:`hover:bg-gray-100 text-gray-400 hover:text-gray-600`}
|
|
5
|
+
`,children:(0,f.jsx)(l.GripVertical,{size:18})})})}),(0,f.jsxs)(Rt,{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(r?.type.name||``)===-1&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Ft,{currentNode:r,currentNodePos:a}),(0,f.jsx)(Bt,{}),(0,f.jsxs)(zt,{className:`flex cursor-pointer gap-3`,onClick:()=>{e.chain().setMeta(`hideDragHandle`,!0).run(),e.chain().setNodeSelection(a).run();let t=r?.textContent;console.log(t),(0,h.default)(t||``)},children:[(0,f.jsx)(l.Copy,{size:16}),(0,f.jsx)(`span`,{children:`复制`})]})]}),(0,f.jsxs)(zt,{onClick:()=>{e.chain().setMeta(`hideDragHandle`,!0).setNodeSelection(a).deleteSelection().run()},className:`flex cursor-pointer gap-3`,children:[(0,f.jsx)(l.Trash2,{size:16}),(0,f.jsx)(`span`,{children:`删除`})]})]})]})};var Ht=Vt;const Ut=[`image`,`codeBlock`,`link`,`table`,`title`],Wt=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)},Gt=(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=Ut.some(t=>e.isActive(t)),o=Wt(t);return a||o||i},Kt=({editor:e})=>{let{doc:t,selection:n,selection:{empty:r,from:i,to:a}}=e.state,o=!t.textBetween(i,a).length&&(0,w.isTextSelection)(n);return!(r||o||!e.isEditable)},qt=e=>(0,w.findParentNode)(e=>e.type.spec.tableRole&&e.type.spec.tableRole===`table`)(e),Jt=e=>t=>{if(J(t)){let n=T.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},J=e=>e instanceof T.CellSelection,Yt=e=>t=>{if(J(t)){let n=T.TableMap.get(t.$anchorCell.node(-1));return Jt({left:e,right:e+1,top:0,bottom:n.height})(t)}return!1},Xt=e=>t=>J(t)?Jt({left:0,right:T.TableMap.get(t.$anchorCell.node(-1)).width,top:e,bottom:e+1})(t):!1,Zt=e=>{if(J(e)){let t=T.TableMap.get(e.$anchorCell.node(-1));return Jt({left:0,right:t.width,top:0,bottom:t.height})(e)}return!1},Qt=e=>t=>{let n=qt(t);if(n){let t=T.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},$t=e=>t=>{let n=qt(t);if(n){let t=T.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},en=e=>t=>n=>{let r=qt(n.selection),i=e===`row`;if(r){let e=T.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 T.CellSelection(m,p))}}return n},tn=en(`column`),nn=en(`row`),rn=10,an=100,on=50,sn=2,cn=10,ln=840,un=120,dn=120;function fn(){let{editor:e}=R(),t=(0,c.useEditorState)({editor:e,selector:e=>{let{selection:t,doc:n}=e.editor.state,r=Qt(0)(t),i=$t(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)=>Xt(n)(t)),isColumnGripSelected:i?.some((e,n)=>Yt(n)(t)),rowCount:a,columnCount:o}}}),n=(0,u.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||Zt(t.selection)?!1:J(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,f.jsx)(C.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,f.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,f.jsx)(U,{tooltip:`在前面插入列`,onClick:()=>{r(`before`)},"tooltip-options":{sideOffset:15},disabled:!t.canAddColumnBefore,children:(0,f.jsx)(l.ArrowLeftToLine,{size:20})}),t.isColumnGripSelected&&(0,f.jsx)(U,{tooltip:`在后面插入列`,onClick:()=>{r(`after`)},"tooltip-options":{sideOffset:15},disabled:!t.canAddColumnAfter,children:(0,f.jsx)(l.ArrowRightToLine,{size:20})}),t.isColumnGripSelected&&(0,f.jsx)(U,{tooltip:`删除列`,onClick:()=>{e.chain().focus().deleteColumn().run()},"tooltip-options":{sideOffset:15},disabled:!t.canDeleteColumn,children:(0,f.jsx)(l.Trash2,{size:20})}),t.isRowGripSelected&&(0,f.jsx)(U,{onClick:()=>{i(`before`)},tooltip:`在上面插入行`,"tooltip-options":{sideOffset:15},disabled:!t.canAddRowBefore,children:(0,f.jsx)(l.ArrowUpToLine,{size:20})}),t.isRowGripSelected&&(0,f.jsx)(U,{onClick:()=>{i(`after`)},tooltip:`在下面插入行`,"tooltip-options":{sideOffset:15},disabled:!t.canAddRowBefore,children:(0,f.jsx)(l.ArrowDownToLine,{size:20})}),t.isRowGripSelected&&(0,f.jsx)(U,{onClick:()=>{e.chain().focus().deleteRow().run()},tooltip:`删除行`,"tooltip-options":{sideOffset:15},disabled:!t.canDeleteRow,children:(0,f.jsx)(l.Trash2,{size:20})}),(0,f.jsx)(U,{onClick:()=>{e.chain().focus().mergeCells().run()},tooltip:`合并单元格`,"tooltip-options":{sideOffset:15},disabled:!t.canMergeCell,children:(0,f.jsx)(l.TableCellsMerge,{size:20})}),(0,f.jsx)(U,{onClick:()=>{e.chain().focus().splitCell().run()},tooltip:`拆分单元格`,"tooltip-options":{sideOffset:15},disabled:!t.canSplitCell,children:(0,f.jsx)(l.TableCellsSplit,{size:20})})]})})}var pn=(0,u.memo)(fn);function mn({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,f.jsx)(D.Root,{"data-slot":`separator`,decorative:n,orientation:t,className:B(`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 hn=({textFormatActions:e,tooltipOptions:t})=>{let{editor:n}=R(),r=z();return(0,f.jsx)(f.Fragment,{children:e.map(e=>(0,f.jsx)(U,{isActive:e.isActive?.(r),onClick:()=>e.onClick(n),disabled:e.disabled?.(r),tooltip:e.label,tooltipOptions:t,shortcutKeys:e.shortcutKeys,children:(0,f.jsx)(e.icon,{size:20})},e.id))})};var gn=(0,u.memo)(hn);function Y({...e}){return(0,f.jsx)(O.Root,{"data-slot":`popover`,...e})}function X({...e}){return(0,f.jsx)(O.Trigger,{"data-slot":`popover-trigger`,...e})}function Z({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,f.jsx)(O.Portal,{children:(0,f.jsx)(O.Content,{"data-slot":`popover-content`,align:t,sideOffset:n,className:B(`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})})}function _n({className:e,...t}){return(0,f.jsx)(ee.Root,{"data-slot":`label`,className:B(`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 vn({className:e,type:t,...n}){return(0,f.jsx)(`input`,{type:t,"data-slot":`input`,className:B(`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 yn=u.forwardRef(({onSave:e,defaultUrl:t,defaultText:n,className:r},i)=>{let a=u.useRef(null),[o,s]=u.useState(t||``),[c,l]=u.useState(n||``),d=u.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 u.useImperativeHandle(i,()=>a.current),(0,f.jsx)(`div`,{className:`shadow-box w-full min-w-80 rounded-xl p-4`,ref:a,children:(0,f.jsxs)(`div`,{className:B(`space-y-4`,r),children:[(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)(_n,{children:`链接`}),(0,f.jsx)(vn,{type:`url`,required:!0,placeholder:`输入链接`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d(e)}})]}),(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)(_n,{children:`文本`}),(0,f.jsx)(vn,{type:`text`,placeholder:`输入文本`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d(e)}})]}),(0,f.jsx)(`div`,{className:`flex justify-end space-x-2`,children:(0,f.jsx)(H,{type:`button`,onClick:d,children:`保存`})})]})})});yn.displayName=`LinkEditPanel`;const bn=({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,u.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,f.jsxs)(Y,{defaultOpen:i,children:[(0,f.jsx)(X,{asChild:!0,children:(0,f.jsx)(U,{pressed:i,isActive:i,tooltip:`插入链接`,tooltipOptions:e,children:(0,f.jsx)(l.LinkIcon,{size:19})})}),(0,f.jsx)(Z,{align:`center`,className:`z-50 w-max`,sideOffset:18,children:(0,f.jsx)(yn,{defaultUrl:n,defaultText:r,onSave:a})})]})};var xn=bn;const Sn=`#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(`.`),Cn=()=>{let{editor:e}=R(),{activeColorItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeColorItem:Sn.find(t=>e.isActive(`textStyle`,{color:t}))})});return(0,f.jsxs)(O.Root,{children:[(0,f.jsx)(O.Trigger,{asChild:!0,children:(0,f.jsxs)(H,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,f.jsx)(l.Baseline,{size:20,color:t}),(0,f.jsx)(l.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,f.jsx)(O.Content,{className:`border-line shadow-box z-50 w-[242px] rounded-xl border bg-white p-4`,align:`center`,sideOffset:18,children:(0,f.jsxs)(`div`,{children:[(0,f.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,f.jsx)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:Sn.map(n=>(0,f.jsx)(`span`,{className:B(`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,f.jsx)(`span`,{className:`border-line h-6 w-6 rounded-sm border`,style:{backgroundColor:n}})},n))})]})})]})};var wn=Cn;const Tn=[`#FF0000`,`#FF4C4C`,`#FFB2B2`,`#FF964A`,`#FFB580`,`#FFDFC9`,`#FFDA36`,`#FFE572`,`#FFF4C3`,`#19EA73`,`#5EF09D`,`#BAF9D5`,`#00BBE5`,`#4CCFED`,`#B2EBF7`,`#075EFF`,`#518EFF`,`#B5CFFF`,`#B46AFF`,`#CA97FF`,`#E8D2FF`,`#707070`,`#B8B8B8`,`#E7E7E7`],En=()=>{let{editor:e}=R(),{activeHighlightItem:t}=(0,c.useEditorState)({editor:e,selector:({editor:e})=>({activeHighlightItem:Tn.find(t=>e.isActive(`highlight`,{color:t}))})});return(0,f.jsxs)(O.Root,{children:[(0,f.jsx)(O.Trigger,{asChild:!0,children:(0,f.jsxs)(H,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,f.jsx)(l.Highlighter,{size:20,color:t}),(0,f.jsx)(l.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,f.jsx)(O.Content,{className:`border-line shadow-box z-50 w-[242px] rounded-xl border bg-white p-4`,align:`center`,sideOffset:18,children:(0,f.jsxs)(`div`,{children:[(0,f.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,f.jsx)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:Tn.map(n=>(0,f.jsx)(`span`,{className:B(`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,f.jsx)(`span`,{className:`border-line h-6 w-6 rounded-sm border`,style:{backgroundColor:n}})},n))})]})})]})};var Dn=En;const On=()=>{let{editor:e}=R();return(0,f.jsx)(C.BubbleMenu,{editor:e,pluginKey:`textBubbleMenu`,shouldShow:(0,u.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 E.NodeSelection;return Gt(e,o)||s?!1:Kt({editor:e})},[e]),updateDelay:100,options:{placement:`top-start`,onShow:()=>{},onHide:()=>{console.log(`textBubbleMenu onHidden`)}},appendTo:()=>document.body,children:(0,f.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,f.jsx)(mn,{orientation:`vertical`,className:`bg-line h-4`}),(0,f.jsx)(gn,{textFormatActions:Mt}),(0,f.jsx)(xn,{}),(0,f.jsx)(wn,{}),(0,f.jsx)(Dn,{})]})})};var kn=On;const An=({language:e,content:t,extension:n,updateAttributes:r})=>{let[i,a]=(0,u.useState)(!1),[o,s]=(0,u.useState)(!0),d=(0,u.useRef)(null),p=()=>{a(!0),setTimeout(()=>{a(!1)},2e3)},m=e=>i?(0,f.jsx)(l.Check,{color:`#16a34a`,...e}):(0,f.jsx)(l.Copy,{color:`#777`,...e}),g=o?l.ChevronDown:l.ChevronRight,_=o?{}:{height:0,overflow:`hidden`};return(0,f.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-muted`,children:[(0,f.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,f.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 w-6 rounded-full text-content-second`,onClick:()=>s(!o),children:(0,f.jsx)(g,{size:14,color:`#777`,style:{verticalAlign:`-0.125em`}})}),(0,f.jsxs)(It,{children:[(0,f.jsx)(Lt,{asChild:!0,children:(0,f.jsx)(`span`,{className:`min-w-[50px] cursor-pointer text-sm text-[#999]`,children:e||`请选择语言`})}),(0,f.jsx)(Rt,{className:`max-h-96 overflow-y-auto`,children:n.options.lowlight.listLanguages().map((e,t)=>(0,f.jsx)(zt,{onClick:()=>{r({language:e})},children:e},t))})]}),(0,f.jsx)(`div`,{className:`flex gap-1`,children:(0,f.jsx)(W,{onClick:()=>{(0,h.default)(t||d.current?.innerText||``),p()},tooltip:i?`已复制`:`复制`,className:`h-6 w-6 text-content-second`,children:(0,f.jsx)(m,{size:16})})})]}),(0,f.jsx)(`div`,{style:_,ref:d,children:(0,f.jsx)(`pre`,{children:(0,f.jsx)(c.NodeViewContent,{as:`code`})})})]})},jn=e=>{let{node:t,extension:n,updateAttributes:r}=e,i=t.attrs.language,a=t.textContent;return(0,f.jsx)(c.NodeViewWrapper,{"data-drag-handle":!0,children:(0,f.jsx)(An,{content:a,language:i,extension:n,updateAttributes:r})})},Mn=(e,t={requireHostname:!1})=>{if(e.includes(`
|
|
6
|
+
`))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}},Nn=(e,t={})=>{if(e)return t.allowBase64&&e.startsWith(`data:image`)?Mn(e,{requireHostname:!1,allowBase64:!0})?e:void 0:Mn(e,{requireHostname:!1,allowBase64:t.allowBase64})||/^(\/|#|mailto:|sms:|fax:|tel:)/.test(e)?e:`https://${e}`},Pn=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)})},Fn=(e,t,n,r,i)=>{let{isValidType:a,isValidSize:o}=In(e,t);a&&o?r.push(n):(a||i.push({file:e,reason:`type`}),o||i.push({file:e,reason:`size`}))},In=(e,{allowedMimeTypes:t,maxFileSize:n})=>{let r=e instanceof File?e.type:Ln(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}},Ln=e=>{let t=e.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);return t&&t.length>1?t[1]:`unknown`},Rn=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}},zn=(e,t)=>{let n=[],r=[];return e.forEach(e=>{let i=`src`in e?e.src:e;i instanceof File?Fn(i,t,e,n,r):typeof i==`string`&&(Rn(i)?t.allowBase64?Fn(i,t,e,n,r):r.push({file:i,reason:`base64NotAllowed`}):Nn(i,{allowBase64:t.allowBase64})?n.push(e):r.push({file:i,reason:`invalidBase64`}))}),[n,r]},Bn=e=>{if(!e)return;let{doc:t,selection:n}=e,{from:r,to:i}=n,a=r,o=i;if(r===0||t.nodeAt(r)?.type.name===t.firstChild?.type.name){let e=t.content.child(0)?.nodeSize?t.content.child(0).nodeSize:t.nodeSize;a=e,o=e}return o||a};function Vn({initialWidth:e,initialHeight:t,contentWidth:n,contentHeight:r,gridInterval:i,minWidth:a,minHeight:o,maxWidth:s,onDimensionsChange:c}){let[l,d]=(0,u.useState)({width:Math.max(e??a,a),height:Math.max(t??o,o)}),[f,p]=(0,u.useState)(1/0),[m,h]=(0,u.useState)({x:0,y:0}),[g,_]=(0,u.useState)(l),[v,y]=(0,u.useState)(),b=(0,u.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,u.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,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),h({x:0,y:0}),y(void 0),c?.(l)},[c,l]),C=(0,u.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,u.useCallback)(e=>t=>{t.preventDefault(),t.stopPropagation(),console.log(`initiateResize direction`,e),p(s),_({width:Math.max(b(l.width,s),a),height:Math.max(l.height,o)}),h({x:t.pageX,y:t.pageY}),y(e)},[s,b,l.width,l.height,a,o]);return(0,u.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(l.width,a),currentHeight:Math.max(l.height,o)}}const Q=({children:e,className:t,...n})=>(0,f.jsx)(`div`,{className:B(`absolute top-3 right-3 flex flex-row rounded px-0.5 opacity-0 group-hover/node-image:opacity-100 z-[11]`,`border-[0.5px] bg-[var(--mt-bg-secondary)] [backdrop-filter:saturate(1.8)_blur(20px)]`,t),...n,children:e});Q.displayName=`ActionWrapper`;const Hn=u.memo(({editor:e,setImageState:t,updateAttributes:n})=>{let r=[{icon:l.AlignLeft,tooltip:`左对齐`,onClick:()=>n({align:`left`})},{icon:l.AlignCenter,tooltip:`居中对齐`,onClick:()=>n({align:`center`})},{icon:l.AlignRight,tooltip:`右对齐`,onClick:()=>n({align:`right`})}],i=[{icon:l.Maximize,tooltip:`预览`,onClick:()=>{t(e=>({...e,isZoomed:!0}))}},{icon:l.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,f.jsxs)(Q,{children:[r.map(({icon:e,tooltip:t,onClick:n},r)=>(0,f.jsx)(W,{tooltip:t,onClick:n,children:(0,f.jsx)(e,{size:`20`})},r)),(0,f.jsx)(mn,{className:`h-5`,orientation:`vertical`}),i.map(({icon:e,tooltip:t,onClick:n},r)=>(0,f.jsx)(W,{tooltip:t,onClick:n,children:(0,f.jsx)(e,{size:`20`})},r))]})});Hn.displayName=`ImageActions`;const Un=u.memo(()=>(0,f.jsx)(`div`,{className:B(`flex flex-row items-center justify-center`,`absolute inset-0 rounded bg-[var(--mt-overlay)] opacity-100 transition-opacity`),children:(0,f.jsx)(l.LoaderCircle,{className:`size-7 animate-spin`})}));Un.displayName=`ImageOverlay`;const Wn=[`tl`,`tr`,`bl`,`br`],Gn=({className:e,initiateResize:t})=>{let n=u.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 B(`absolute z-10 block border border-primary bg-white`,t)},[]);return(0,f.jsx)(`div`,{className:B(`absolute top-0 left-0 z-10 w-full h-full border border-primary cursor-pointer`,e),children:Wn?.map(e=>(0,f.jsx)(`span`,{className:n(e),onPointerDown:n=>t(e)(n)},e))})};Gn.displayName=`ResizeHandle`;const Kn=({editor:e,node:t,selected:n,updateAttributes:r})=>{let{src:i,width:a,height:o,align:s,fileName:d,fileType:p}=t.attrs,[m,h]=u.useState({src:i,isServerUploading:!1,imageLoaded:!1,isZoomed:!1,error:!1,naturalSize:{width:a,height:o}}),g=u.useRef(null),_=u.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}=Vn({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=u.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=u.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],`${d||`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 Pn(i);h(t=>({...t,src:e})),r({src:e})}catch{h(e=>({...e,error:!0}))}i.startsWith(`blob:`)&&URL.revokeObjectURL(i)}};return u.useEffect(()=>{O()},[i]),(0,f.jsx)(c.NodeViewWrapper,{ref:g,"data-drag-handle":!0,className:`relative flex justify-center`,style:{justifyContent:s},children:(0,f.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,f.jsxs)(`div`,{className:B(`relative flex h-full cursor-default flex-col items-center gap-2 rounded`),children:[(0,f.jsxs)(`div`,{className:`relative h-full`,children:[!m.imageLoaded&&!m.error&&(0,f.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,f.jsx)(l.LoaderCircle,{className:`size-7 animate-spin`})}),(0,f.jsx)(ue.Controlled,{isZoomed:m.isZoomed,onZoomChange:()=>h(e=>({...e,isZoomed:!1})),children:(0,f.jsx)(`img`,{className:B(`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,f.jsx)(Un,{}),e.isEditable&&m.imageLoaded&&!m.error&&!m.isServerUploading&&(n||T)&&(0,f.jsx)(Gn,{initiateResize:w}),m.error&&(0,f.jsx)(Q,{children:(0,f.jsx)(W,{tooltip:`移除图片`,onClick:v,children:(0,f.jsx)(l.Trash2,{className:`size-4`})})}),!T&&!m.error&&!m.isServerUploading&&(0,f.jsx)(Hn,{editor:e,node:t,imageState:m,setImageState:h,updateAttributes:r})]})})})},qn=(e,t,n)=>{let r=e instanceof Error?e:Error(`Unknown error`);n?.(r,t)},Jn=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){qn(n,{...e,action:`copyImage`},t.onActionError)}},Yn=async(e,t)=>{let{src:n}=e;try{await navigator.clipboard.writeText(n),t.onActionSuccess?.({...e,action:`copyLink`})}catch(n){qn(n,{...e,action:`copyLink`},t.onActionError)}},Xn=le.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})=>{let[n,r]=zn(e,{allowedMimeTypes:this.options.allowedMimeTypes,maxFileSize:this.options.maxFileSize,allowBase64:this.options.allowBase64});return r.length>0&&this.options.onValidationError&&this.options.onValidationError(r),n.length>0?t.insertContent(n.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}}}),{updateSelection:!0,insertAt:(e,t)=>{let n=Bn(e);e.insertContentAt(t,n)}}):!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||Jn)({...e,action:`copyImage`},this.options),!0),copyLink:e=>()=>((this.options.customCopyLink||Yn)({...e,action:`copyLink`},this.options),!0)}},addNodeView(){return(0,c.ReactNodeViewRenderer)(Kn,{className:`block-node`})}});var Zn=Xn;const Qn=fe.default.extend({inclusive:!1,parseHTML(){return[{tag:`a[href]:not([data-type="button"]):not([href *= "javascript:" i])`}]},renderHTML({HTMLAttributes:e}){return[`a`,(0,w.mergeAttributes)(this.options.HTMLAttributes,e,{class:`link`}),0]},addProseMirrorPlugins(){return[...this.parent?.()||[],new E.Plugin({props:{handleClick(e,t){let{schema:n,doc:r,tr:i}=e.state,a=(0,w.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 E.TextSelection(u,d));e.dispatch(f)}}})]}});var $n=Qn;const er=w.Node.create({name:`tableCell`,content:`block+`,tableRole:`cell`,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`td`}]},renderHTML({HTMLAttributes:e}){return[`td`,(0,w.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 E.Plugin({props:{decorations:t=>{if(!e)return N.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=Qt(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(N.Decoration.widget(e+1,()=>{let e=Xt(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(nn(t)(this.editor.state.tr))}),i}))}),N.DecorationSet.create(n,i)}}})]}}),tr=pe.TableHeader.extend({addProseMirrorPlugins(){let{isEditable:e}=this.editor;return[new E.Plugin({props:{decorations:t=>{if(!e)return N.DecorationSet.empty;let{doc:n,selection:r}=t,i=[],a=$t(0)(r);return a&&a.forEach(({pos:e},t)=>{i.push(N.Decoration.widget(e+1,()=>{let e=Yt(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(tn(t)(this.editor.state.tr))}),i}))}),N.DecorationSet.create(n,i)}}})]}}),nr=pe.TableRow.extend({allowGapCursor:!1}),rr=pe.Table.extend({addOptions(){return{...this.parent?.(),resizable:!0,lastColumnResizable:!0,allowTableNodeSelection:!0,HTMLAttributes:{}}},addExtensions(){return[nr.configure(this.options.tableRow),tr.configure(this.options.tableHeader),er.configure(this.options.tableCell)]}});var ir=rr;const $=(0,ce.createLowlight)(ce.common);$.register(`html`,se.default),$.register(`css`,j.default),$.register(`js`,M.default),$.register(`ts`,oe.default);const ar=e=>{let{uploadFn:t}=e;return[ae.TextStyleKit,A.default,k.Placeholder.configure({placeholder:({node:e})=>{let t=e?.type?.name;return t===`title`?`未命名文档`:t===`heading`?`标题${e.attrs.level}`:t===`codeBlock`?`请输入代码`:t===`table`?``:`请输入内容`}}),k.Focus.configure({className:`node-focused`,mode:`all`}),ie.default.configure({types:[`heading`,`paragraph`]}),ae.Color,ae.BackgroundColor,re.TaskList,re.TaskItem,ir,k.Gapcursor,Zn.configure({allowedMimeTypes:[`image/*`],maxFileSize:10*1024*1024,allowBase64:!1,uploadFn:t,onValidationError(e){e.forEach(e=>{d.toast.error(`图片校验失败`,{description:e.reason})})},onActionSuccess({action:e}){d.toast.success(`${{copyImage:`复制图片`,copyLink:`复制链接`,download:`下载`}[e]}成功`)},onActionError(e,{action:t}){d.toast.error(`${{copyImage:`复制图片`,copyLink:`复制链接`,download:`下载`}[t]}失败`,{description:e.message})}}),k.Dropcursor,ne.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)}})}}),k.Selection.configure({className:`selection`}),$n.configure({openOnClick:`whenNotEditable`}),te.default.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(jn)}}).configure({lowlight:$}),de.Mathematics]},or=({nodeFormatActions:e})=>{let{editor:t}=R(),n=z(),r=e.find(e=>e.isActive?.(n))??ht;return(0,f.jsxs)(Y,{children:[(0,f.jsx)(X,{asChild:!0,children:(0,f.jsxs)(H,{variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,f.jsx)(r.icon,{size:20}),(0,f.jsx)(l.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,f.jsx)(Z,{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,f.jsxs)(`div`,{onClick:()=>{e.onClick(t)},className:B(`flex cursor-pointer items-center rounded-sm p-2 text-sm hover:bg-accent`,r.label===e.label?`text-primary`:``),children:[(0,f.jsx)(e.icon,{size:`20`,className:`mr-3`}),(0,f.jsx)(`span`,{children:e.label}),r.label===e.label&&(0,f.jsx)(l.Check,{size:`16`,className:`ml-auto items-end`})]},e.id))})]})};var sr=(0,u.memo)(or);const cr=()=>{let{editor:e}=R(),[t,n]=(0,u.useState)(!1),r=z(),i=Et.find(e=>e.isActive?.(r))??St;return(0,f.jsxs)(Y,{open:t,onOpenChange:n,children:[(0,f.jsx)(X,{asChild:!0,children:(0,f.jsxs)(H,{onClick:()=>n(!0),variant:`ghost`,className:`h-7 gap-1 rounded px-1`,children:[(0,f.jsx)(i.icon,{strokeWidth:1.5,size:`20`}),(0,f.jsx)(l.ChevronDown,{size:12,color:`#9fa2ab`})]})}),(0,f.jsx)(Z,{className:`border-line z-50 w-40 rounded-xl border bg-white px-2 py-1 shadow-xl`,align:`start`,sideOffset:18,children:Et.map(t=>(0,f.jsxs)(`div`,{onClick:()=>{t.onClick(e),n(!1)},className:B(`flex cursor-pointer items-center rounded-sm p-2 text-sm hover:bg-accent`,i?.label===t.label?`text-primary`:``),children:[(0,f.jsx)(t.icon,{size:`20`,className:`mr-3`}),(0,f.jsx)(`span`,{children:t.label}),i?.label===t.label&&(0,f.jsx)(l.Check,{size:`16`,className:`ml-auto items-end`})]},t.id))})]})};var lr=(0,u.memo)(cr);const ur=()=>{let{editor:e}=R();return(0,f.jsx)(H,{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,f.jsx)(l.ImagePlus,{size:`20`})})};var dr=ur;const fr=e=>Array.from({length:e}).map((e,t)=>t+1);function pr(){let{editor:e}=R(),{canTable:t,isTable:n}=z();function r(n){t&&e.chain().focus().insertTable({...n,withHeaderRow:!1}).run()}let[i,a]=u.default.useState(!0),[o,s]=u.default.useState({rows:10,cols:10}),[c,d]=u.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)})),d({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}),d({rows:2,cols:2})}return(0,f.jsxs)(Y,{children:[(0,f.jsx)(X,{asChild:!0,children:(0,f.jsx)(U,{"data-state":`off`,disabled:!t||n,tooltip:`插入表格`,tooltipOptions:{side:`bottom`},isActive:n,children:(0,f.jsx)(l.Table,{size:20})})}),(0,f.jsx)(Z,{className:`z-50 w-full !p-2`,align:`start`,side:`bottom`,sideOffset:18,children:(0,f.jsxs)(`div`,{className:`table-grid-size-editor p-0`,children:[(0,f.jsx)(`div`,{className:`flex flex-col flex-wrap justify-between gap-1`,children:fr(o?.rows)?.map(e=>(0,f.jsx)(`div`,{className:`flex gap-1`,children:fr(o?.cols)?.map(t=>(0,f.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,f.jsxs)(`div`,{className:`mt-2 text-center text-sm text-zinc-600`,children:[c.rows,` x `,c.cols]})]})})]})}var mr=pr;const hr=[`undo`,`redo`,`separator`,`node-selector`,`text-selector`,`link`,`color`,`bg`,`align`,`separator`,`image`,`table`],gr=({config:e=hr,appendItems:t})=>{let{editor:n}=R(),r=z();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,f.jsx)(U,{...i(K),tooltip:K.label,shortcutKeys:K.shortcutKeys,children:(0,f.jsx)(K.icon,{size:20})},t);case`redo`:return(0,f.jsx)(U,{...i(q),tooltip:q.label,shortcutKeys:q.shortcutKeys,children:(0,f.jsx)(q.icon,{size:20})},t);case`separator`:return(0,f.jsx)(mn,{orientation:`vertical`,className:`bg-line h-4`},t);case`node-selector`:return(0,f.jsx)(sr,{nodeFormatActions:xt.select},t);case`text-selector`:return(0,f.jsx)(gn,{textFormatActions:Mt},t);case`link`:return(0,f.jsx)(xn,{},t);case`color`:return(0,f.jsx)(wn,{},t);case`bg`:return(0,f.jsx)(Dn,{},t);case`align`:return(0,f.jsx)(lr,{},t);case`image`:return(0,f.jsx)(dr,{},t);case`table`:return(0,f.jsx)(mr,{},t);default:return typeof e!=`string`&&e.render?(0,f.jsx)(u.default.Fragment,{children:e.render(n)},t):null}};return(0,f.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]})},_r=({value:e,onChange:t,onImageUpload:n,className:r,showToolbar:i=!0,showBubbleMenu:a=!0,showTableMenu:o=!0,showBlockMenu:s=!0,toolbarProps:l,onInitEditor:u})=>{let d=(0,c.useEditor)({immediatelyRender:!1,extensions:ar({uploadFn:n}),content:e,editorProps:{attributes:{class:`w-full focus:outline-none`}},onUpdate:({editor:e})=>{t(e.getHTML())},onCreate:({editor:e})=>{u?.(e)}});return d?(0,f.jsxs)(st,{editor:d,children:[i&&(0,f.jsx)(gr,{...l}),a&&(0,f.jsx)(kn,{}),o&&(0,f.jsx)(pn,{}),s&&(0,f.jsx)(Ht,{}),(0,f.jsx)(c.EditorContent,{editor:d,className:B(`w-full not-prose`,!i&&`not-toolbar`,r)}),(0,f.jsx)(Oe,{richColors:!0,position:`top-center`})]}):null};exports.TiptapComponent=_r,exports.Toolbar=gr;
|
|
4
7
|
//# sourceMappingURL=index.cjs.map
|