tiptap-notion-editor 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),x=require("react"),N=require("@tiptap/react"),Et=require("@tiptap/extension-drag-handle-react"),m=require("lucide-react"),je=require("class-variance-authority"),S=require("radix-ui"),It=require("clsx"),zt=require("tailwind-merge"),de=require("@tiptap/pm/model"),D=require("@tiptap/pm/state"),I=require("@floating-ui/dom"),P=require("@tiptap/pm/tables"),Xe=require("@tiptap/react/menus"),ke=require("react-dom"),Dt=require("@tiptap/extension-blockquote"),Pt=require("@tiptap/extension-bold"),Bt=require("@tiptap/extension-code"),Vt=require("@tiptap/extension-code-block-lowlight"),Ot=require("@tiptap/extension-document"),ze=require("@tiptap/extension-emoji"),$t=require("@tiptap/extension-hard-break"),qt=require("@tiptap/extension-heading"),Ft=require("@tiptap/extension-highlight"),Ut=require("@tiptap/extension-horizontal-rule"),_t=require("@tiptap/extension-italic"),Wt=require("@tiptap/extension-link"),Zt=require("@tiptap/extension-list"),Kt=require("@tiptap/extension-mathematics"),Gt=require("@tiptap/extension-mention"),Xt=require("@tiptap/extension-paragraph"),Jt=require("@tiptap/extension-placeholder"),Yt=require("@tiptap/extension-strike"),Qt=require("@tiptap/extension-subscript"),en=require("@tiptap/extension-superscript"),tn=require("@tiptap/extension-table-of-contents"),nn=require("@tiptap/extension-text"),on=require("@tiptap/extension-text-align"),ye=require("@tiptap/extension-text-style"),rn=require("@tiptap/extension-underline"),sn=require("@tiptap/extension-unique-id"),me=require("@tiptap/extensions"),De=require("lowlight"),ln=require("uuid"),an=require("@tiptap/extension-image"),Z=require("@tiptap/core"),re=require("@tiptap/extension-table"),cn=require("@tiptap/extension-file-handler"),dn=require("@tanstack/react-virtual"),ue=require("cmdk"),un=require("@tiptap/suggestion");function y(...e){return zt.twMerge(It.clsx(e))}const pn=async e=>{if(!e||!e.state)return console.warn("Tiptap copy operation failed: Editor instance is uninitialized."),!1;const{selection:t,doc:o}=e.state;let r=null;if(t instanceof D.NodeSelection?r=t.node:t instanceof D.TextSelection&&(r=t.$from.parent),!r||r.type.name==="doc")return console.warn("Tiptap copy operation failed: No copyable block node selected."),!1;try{const i=e.schema,l=de.DOMSerializer.fromSchema(i).serializeNode(r),a=document.createElement("div");a.appendChild(l);const d=a.innerHTML,c=r.textContent||"",u=new ClipboardItem({"text/html":new Blob([d],{type:"text/html"}),"text/plain":new Blob([c],{type:"text/plain"})});return await navigator.clipboard.write([u]),!0}catch(i){return console.error("Fatal: Failed to write selected block node to clipboard.",i),!1}},mn=e=>{if(!e||!e.state)return console.warn("Tiptap delete operation failed: Editor instance is uninitialized."),!1;const{selection:t}=e.state;let o=t.from,r=t.to;if(t instanceof D.NodeSelection)o=t.from,r=t.to;else if(t instanceof D.TextSelection){const i=t.$from.depth;if(i===0)return!1;o=t.$from.before(i),r=t.$from.after(i)}return e.chain().deleteRange({from:o,to:r}).focus().run()},fn=e=>{if(!e||!e.state)return console.warn("Tiptap delete operation failed: Editor instance is uninitialized."),!1;const{selection:t}=e.state;let o=t instanceof D.NodeSelection?t.node:null,r=t.from;if(o||(o=t.$from.parent,r=t.$from.before(t.$from.depth)),o){const i=r+o.nodeSize;e.chain().insertContentAt(i,o.toJSON()).focus().setTextSelection(i+1).run()}},hn=(e,t)=>{if(!e||!e.state)return!1;const{selection:o}=e.state;let r=null,i=null;if(o instanceof D.NodeSelection)r=o.node.type.name,i=o.from;else if(o instanceof D.TextSelection){const s=o.$from.depth;s>0&&(r=o.$from.parent.type.name,i=o.$from.before(s))}return r&&i!==null&&r!=="doc"?e.chain().focus().updateAttributes(r,{universalBgColor:t}).run():!1};function gn(e){if(!e)return;const{from:t}=e.state.selection,{left:o,right:r,top:i,bottom:s}=e.view.coordsAtPos(t);return new DOMRect(o,i,r-o,s-i)}function xn({editor:e,clientRect:t,element:o,placement:r="bottom-start",strategy:i="absolute",middleware:s=[I.shift(),I.flip()],offsetValue:l}){if(!o)return;const a=t||(e?gn(e):null);if(!a)return;const d={getBoundingClientRect:()=>a},c=l?[I.offset(l),...s]:s;return I.computePosition(d,o,{placement:r,strategy:i,middleware:c}).then(({x:u,y:p,strategy:h})=>{Object.assign(o.style,{width:"max-content",position:h,left:`${u}px`,top:`${p}px`})})}const bn=je.cva("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/90",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function z({className:e,variant:t="default",size:o="default",asChild:r=!1,...i}){const s=r?S.Slot.Root:"button";return n.jsx(s,{"data-slot":"button","data-variant":t,"data-size":o,className:y(bn({variant:t,size:o,className:e})),...i})}function Cn({delayDuration:e=0,...t}){return n.jsx(S.Tooltip.Provider,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function vn({...e}){return n.jsx(S.Tooltip.Root,{"data-slot":"tooltip",...e})}function wn({...e}){return n.jsx(S.Tooltip.Trigger,{"data-slot":"tooltip-trigger",...e})}function yn({className:e,sideOffset:t=0,children:o,...r}){return n.jsx(S.Tooltip.Portal,{children:n.jsxs(S.Tooltip.Content,{"data-slot":"tooltip-content",sideOffset:t,className:y("z-50 inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 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 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r,children:[o,n.jsx(S.Tooltip.Arrow,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}const K=({children:e,content:t,className:o,showTooltip:r=!0})=>n.jsxs(vn,{children:[n.jsx(wn,{asChild:!0,children:e}),r&&t&&n.jsx(yn,{className:o,children:n.jsx("p",{children:t})})]});function Ne({...e}){return n.jsx(S.DropdownMenu.Root,{"data-slot":"dropdown-menu",...e})}function Ae({...e}){return n.jsx(S.DropdownMenu.Portal,{"data-slot":"dropdown-menu-portal",...e})}function Me({...e}){return n.jsx(S.DropdownMenu.Trigger,{"data-slot":"dropdown-menu-trigger",...e})}function Se({className:e,align:t="start",sideOffset:o=4,...r}){return n.jsx(S.DropdownMenu.Portal,{children:n.jsx(S.DropdownMenu.Content,{"data-slot":"dropdown-menu-content",sideOffset:o,align:t,className:y("z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 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 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r})})}function X({...e}){return n.jsx(S.DropdownMenu.Group,{"data-slot":"dropdown-menu-group",...e})}function F({className:e,inset:t,variant:o="default",...r}){return n.jsx(S.DropdownMenu.Item,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":o,className:y("group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",e),...r})}function Je({className:e,inset:t,...o}){return n.jsx(S.DropdownMenu.Label,{"data-slot":"dropdown-menu-label","data-inset":t,className:y("px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",e),...o})}function W({className:e,...t}){return n.jsx(S.DropdownMenu.Separator,{"data-slot":"dropdown-menu-separator",className:y("-mx-1 my-1 h-px bg-border",e),...t})}function ae({className:e,...t}){return n.jsx("span",{"data-slot":"dropdown-menu-shortcut",className:y("ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",e),...t})}function Te({...e}){return n.jsx(S.DropdownMenu.Sub,{"data-slot":"dropdown-menu-sub",...e})}function Le({className:e,inset:t,children:o,...r}){return n.jsxs(S.DropdownMenu.SubTrigger,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:y("flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r,children:[o,n.jsx(m.ChevronRightIcon,{className:"ml-auto"})]})}function Re({className:e,...t}){return n.jsx(S.DropdownMenu.SubContent,{"data-slot":"dropdown-menu-sub-content",className:y("z-50 min-w-24 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...t})}function ie({className:e,children:t,...o}){return n.jsxs(S.ScrollArea.Root,{"data-slot":"scroll-area",className:y("relative",e),...o,children:[n.jsx(S.ScrollArea.Viewport,{"data-slot":"scroll-area-viewport",className:"size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1",children:t}),n.jsx(jn,{}),n.jsx(S.ScrollArea.Corner,{})]})}function jn({className:e,orientation:t="vertical",...o}){return n.jsx(S.ScrollArea.ScrollAreaScrollbar,{"data-slot":"scroll-area-scrollbar","data-orientation":t,orientation:t,className:y("flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent",e),...o,children:n.jsx(S.ScrollArea.ScrollAreaThumb,{"data-slot":"scroll-area-thumb",className:"relative flex-1 rounded-full bg-border"})})}const kn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 2C20.6569 2 22 3.34315 22 5V19C22 20.6569 20.6569 22 19 22H15C13.3431 22 12 20.6569 12 19V5C12 3.34315 13.3431 2 15 2H19ZM14 19C14 19.5523 14.4477 20 15 20H19C19.5523 20 20 19.5523 20 19V13H14V19ZM15 4C14.4477 4 14 4.44772 14 5V11H20V5C20 4.44772 19.5523 4 19 4H15Z",fill:"currentColor"}),n.jsx("path",{d:"M6 8C6.55228 8 7 8.44772 7 9V11H9C9.55228 11 10 11.4477 10 12C10 12.5523 9.55228 13 9 13H7V15C7 15.5523 6.55228 16 6 16C5.44772 16 5 15.5523 5 15V13H3C2.44772 13 2 12.5523 2 12C2 11.4477 2.44772 11 3 11H5V9C5 8.44772 5.44772 8 6 8Z",fill:"currentColor"})]}),Nn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 2C10.6569 2 12 3.34315 12 5V19C12 20.6569 10.6569 22 9 22H5C3.34315 22 2 20.6569 2 19V5C2 3.34315 3.34315 2 5 2H9ZM4 19C4 19.5523 4.44772 20 5 20H9C9.55228 20 10 19.5523 10 19V13H4V19ZM5 4C4.44772 4 4 4.44772 4 5V11H10V5C10 4.44772 9.55228 4 9 4H5Z",fill:"currentColor"}),n.jsx("path",{d:"M18 8C18.5523 8 19 8.44772 19 9V11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H19V15C19 15.5523 18.5523 16 18 16C17.4477 16 17 15.5523 17 15V13H15C14.4477 13 14 12.5523 14 12C14 11.4477 14.4477 11 15 11H17V9C17 8.44772 17.4477 8 18 8Z",fill:"currentColor"})]}),An=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 12C20.6569 12 22 13.3431 22 15V19C22 20.6569 20.6569 22 19 22H5C3.34315 22 2 20.6569 2 19V15C2 13.3431 3.34315 12 5 12H19ZM5 14C4.44772 14 4 14.4477 4 15V19C4 19.5523 4.44772 20 5 20H11V14H5ZM13 20H19C19.5523 20 20 19.5523 20 19V15C20 14.4477 19.5523 14 19 14H13V20Z",fill:"currentColor"}),n.jsx("path",{d:"M12 2C12.5523 2 13 2.44772 13 3V5H15C15.5523 5 16 5.44772 16 6C16 6.55228 15.5523 7 15 7H13V9C13 9.55228 12.5523 10 12 10C11.4477 10 11 9.55228 11 9V7H9C8.44772 7 8 6.55228 8 6C8 5.44772 8.44772 5 9 5H11V3C11 2.44772 11.4477 2 12 2Z",fill:"currentColor"})]}),Mn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12 14C12.5523 14 13 14.4477 13 15V17H15C15.5523 17 16 17.4477 16 18C16 18.5523 15.5523 19 15 19H13V21C13 21.5523 12.5523 22 12 22C11.4477 22 11 21.5523 11 21V19H9C8.44772 19 8 18.5523 8 18C8 17.4477 8.44772 17 9 17H11V15C11 14.4477 11.4477 14 12 14Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 2C20.6569 2 22 3.34315 22 5V9C22 10.6569 20.6569 12 19 12H5C3.34315 12 2 10.6569 2 9V5C2 3.34315 3.34315 2 5 2H19ZM5 4C4.44772 4 4 4.44772 4 5V9C4 9.55228 4.44772 10 5 10H11V4H5ZM13 10H19C19.5523 10 20 9.55228 20 9V5C20 4.44772 19.5523 4 19 4H13V10Z",fill:"currentColor"})]}),Pe=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{d:"M10 16C10.5177 16 10.9438 16.3933 10.9951 16.8975L11 17V19C11 20.6569 9.65685 22 8 22H4C2.34315 22 1 20.6569 1 19V17C1 16.4477 1.44772 16 2 16C2.55228 16 3 16.4477 3 17V19C3 19.5523 3.44772 20 4 20H8C8.55228 20 9 19.5523 9 19V17L9.00488 16.8975C9.05621 16.3933 9.48232 16 10 16Z",fill:"currentColor"}),n.jsx("path",{d:"M22 16C22.5177 16 22.9438 16.3933 22.9951 16.8975L23 17V19C23 20.6569 21.6569 22 20 22H16C14.3431 22 13 20.6569 13 19V17C13 16.4477 13.4477 16 14 16C14.5523 16 15 16.4477 15 17V19C15 19.5523 15.4477 20 16 20H20C20.5523 20 21 19.5523 21 19V17L21.0049 16.8975C21.0562 16.3933 21.4823 16 22 16Z",fill:"currentColor"}),n.jsx("path",{d:"M5.29297 8.29297C5.68349 7.90244 6.31651 7.90244 6.70703 8.29297L9.70703 11.293L9.77539 11.3691C10.0957 11.7619 10.0731 12.3409 9.70703 12.707L6.70703 15.707C6.31651 16.0975 5.68349 16.0975 5.29297 15.707C4.90245 15.3165 4.90245 14.6835 5.29297 14.293L6.58594 13H3C2.44772 13 2 12.5523 2 12C2 11.4477 2.44772 11 3 11H6.58594L5.29297 9.70703C4.90245 9.31651 4.90245 8.68349 5.29297 8.29297Z",fill:"currentColor"}),n.jsx("path",{d:"M17.293 8.29297C17.6835 7.90245 18.3165 7.90246 18.707 8.29297C19.0976 8.68349 19.0976 9.31651 18.707 9.70703L17.4141 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H17.4141L18.707 14.293C19.0976 14.6835 19.0976 15.3165 18.707 15.707C18.3165 16.0976 17.6835 16.0976 17.293 15.707L14.293 12.707L14.2246 12.6309C13.9043 12.2381 13.9269 11.6591 14.293 11.293L17.293 8.29297Z",fill:"currentColor"}),n.jsx("path",{d:"M8 2C9.65685 2 11 3.34315 11 5V7C11 7.55228 10.5523 8 10 8C9.44771 8 9 7.55228 9 7V5C9 4.44772 8.55228 4 8 4H4C3.44772 4 3 4.44772 3 5V7C3 7.55228 2.55228 8 2 8C1.44772 8 1 7.55228 1 7V5C1 3.34315 2.34315 2 4 2H8Z",fill:"currentColor"}),n.jsx("path",{d:"M20 2C21.6569 2 23 3.34315 23 5V7C23 7.55228 22.5523 8 22 8C21.4477 8 21 7.55228 21 7V5C21 4.44772 20.5523 4 20 4H16C15.4477 4 15 4.44772 15 5V7C15 7.55228 14.5523 8 14 8C13.4477 8 13 7.55228 13 7V5C13 3.34315 14.3431 2 16 2H20Z",fill:"currentColor"})]}),q=({icon:e,label:t,onClick:o,variant:r="default",disabled:i=!1,className:s})=>n.jsxs(F,{className:y(pe,s,{"text-destructive hover:bg-destructive/10 focus:bg-destructive/10 focus:text-destructive":r==="destructive","text-muted-foreground hover:bg-accent hover:text-accent-foreground":r==="default"}),onClick:o,disabled:i,children:[n.jsx(e,{className:"size-4 shrink-0"}),n.jsx("span",{children:t})]}),He=e=>n.jsx("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z",fill:"currentColor"})}),Sn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{d:"M3 16C3.55228 16 4 16.4477 4 17V19L4.00488 19.0986C4.02757 19.3276 4.12883 19.5429 4.29297 19.707C4.48051 19.8946 4.73478 20 5 20H7C7.55228 20 8 20.4477 8 21C8 21.5523 7.55228 22 7 22H5C4.20435 22 3.44151 21.6837 2.87891 21.1211C2.3163 20.5585 2 19.7957 2 19V17C2 16.4477 2.44772 16 3 16Z",fill:"currentColor"}),n.jsx("path",{d:"M21 16C21.5523 16 22 16.4477 22 17V19C22 19.7957 21.6837 20.5585 21.1211 21.1211C20.5585 21.6837 19.7957 22 19 22H17C16.4477 22 16 21.5523 16 21C16 20.4477 16.4477 20 17 20H19C19.2652 20 19.5195 19.8946 19.707 19.707C19.8946 19.5195 20 19.2652 20 19V17C20 16.4477 20.4477 16 21 16Z",fill:"currentColor"}),n.jsx("path",{d:"M7 16C7.55228 16 8 16.4477 8 17C8 17.5523 7.55228 18 7 18C6.44772 18 6 17.5523 6 17C6 16.4477 6.44772 16 7 16Z",fill:"currentColor"}),n.jsx("path",{d:"M12 16C12.5523 16 13 16.4477 13 17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17C11 16.4477 11.4477 16 12 16Z",fill:"currentColor"}),n.jsx("path",{d:"M17 16C17.5523 16 18 16.4477 18 17C18 17.5523 17.5523 18 17 18C16.4477 18 16 17.5523 16 17C16 16.4477 16.4477 16 17 16Z",fill:"currentColor"}),n.jsx("path",{d:"M7 11C7.55228 11 8 11.4477 8 12C8 12.5523 7.55228 13 7 13C6.44772 13 6 12.5523 6 12C6 11.4477 6.44772 11 7 11Z",fill:"currentColor"}),n.jsx("path",{d:"M12 11C12.5523 11 13 11.4477 13 12C13 12.5523 12.5523 13 12 13C11.4477 13 11 12.5523 11 12C11 11.4477 11.4477 11 12 11Z",fill:"currentColor"}),n.jsx("path",{d:"M17 11C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13C16.4477 13 16 12.5523 16 12C16 11.4477 16.4477 11 17 11Z",fill:"currentColor"}),n.jsx("path",{d:"M7 2C7.55228 2 8 2.44772 8 3C8 3.55228 7.55228 4 7 4H5C4.73478 4 4.4805 4.10543 4.29297 4.29297C4.10543 4.4805 4 4.73478 4 5V7C4 7.55228 3.55228 8 3 8C2.44772 8 2 7.55228 2 7V5C2 4.20435 2.3163 3.44152 2.87891 2.87891C3.44152 2.3163 4.20435 2 5 2H7Z",fill:"currentColor"}),n.jsx("path",{d:"M7 6C7.55228 6 8 6.44772 8 7C8 7.55228 7.55228 8 7 8C6.44772 8 6 7.55228 6 7C6 6.44772 6.44772 6 7 6Z",fill:"currentColor"}),n.jsx("path",{d:"M12 6C12.5523 6 13 6.44772 13 7C13 7.55228 12.5523 8 12 8C11.4477 8 11 7.55228 11 7C11 6.44772 11.4477 6 12 6Z",fill:"currentColor"}),n.jsx("path",{d:"M17 6C17.5523 6 18 6.44772 18 7C18 7.55228 17.5523 8 17 8C16.4477 8 16 7.55228 16 7C16 6.44772 16.4477 6 17 6Z",fill:"currentColor"}),n.jsx("path",{d:"M19 2C19.7957 2 20.5585 2.3163 21.1211 2.87891C21.6837 3.44151 22 4.20435 22 5V7C22 7.55228 21.5523 8 21 8C20.4477 8 20 7.55228 20 7V5C20 4.73478 19.8946 4.48051 19.707 4.29297C19.5429 4.12883 19.3276 4.02757 19.0986 4.00488L19 4H17C16.4477 4 16 3.55228 16 3C16 2.44772 16.4477 2 17 2H19Z",fill:"currentColor"})]}),Ee=152,Tn="--default-cell-min-width",ce="table-handle-reposition",se="data-dragging",le=e=>{const t=e.selection;let o=null;if(t.anchorCell)o=t.anchorCell.pos;else{const c=t.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){o=c.before(u);break}}}if(o===null)return null;const r=e.doc.resolve(o);let i=null,s=-1;for(let c=r.depth;c>0;c--)if(r.node(c).type.name==="table"){i=r.node(c),s=r.before(c);break}if(!i||s===-1)return null;const l=P.TableMap.get(i),a=o-s-1,d=l.findCell(a);return{tableNode:i,tablePos:s,map:l,cellPos:o,cellRect:d}};function Ln(e,t,o=!0){const{state:r,view:i}=e,{tr:s,schema:l}=r,a=r.doc.nodeAt(t);if(!a||a.type.name!=="table")return!1;const d=a.firstChild;if(!d)return!1;const c=[];for(let h=0;h<d.childCount;h++){const f=l.nodes.tableCell.createAndFill();f&&c.push(f)}const u=l.nodes.tableRow.create(null,de.Fragment.from(c)),p=t+a.nodeSize-1;return s.insert(p,u),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Rn(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table"||l.childCount<=1)return!1;const a=l.lastChild;if(!a)return!1;let d=!0;if(a.forEach(u=>{u.textContent.trim()!==""&&(d=!1)}),!d)return!1;const c=t+l.nodeSize-a.nodeSize-1;return s.delete(c,c+a.nodeSize),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Hn(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table")return!1;const a=P.TableMap.get(l);return P.addColumn(s,Ye(l,t,a),a.width),In(l)&&zn(s,t,a.width,Ee),s.setMeta("addToHistory",o),i.dispatch(s),!0}function En(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table")return!1;const a=P.TableMap.get(l);if(a.width<=1)return!1;const d=a.width-1;for(let c=0;c<a.height;c++){const u=l.nodeAt(a.map[c*a.width+d]);if(u&&u.textContent.trim()!=="")return!1}return P.removeColumn(s,Ye(l,t,a),d),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Ye(e,t,o){return{map:o,table:e,tableStart:t+1,top:0,left:0,bottom:o.height,right:o.width}}function In(e){const t=e.firstChild;if(!t)return!1;for(let o=0;o<t.childCount;o++){const r=t.child(o).attrs.colwidth;if(!r||r.some(i=>!i))return!1}return!0}function zn(e,t,o,r){const i=e.doc.nodeAt(t);if(!i)return;const s=P.TableMap.get(i);if(!(o>=s.width))for(let l=0;l<s.height;l++){const a=t+1+s.map[l*s.width+o],d=e.doc.nodeAt(a);d&&e.setNodeMarkup(a,void 0,{...d.attrs,colwidth:[r]})}}const Be=(e,t)=>e.chain().focus().command(({state:o,dispatch:r})=>{const i=le(o);if(!i)return!1;const s=i.cellRect.left,l=t==="left"?s-1:s+1;return l>=0&&l<i.map.width?r?P.moveTableColumn({from:s,to:l})(o,r):!0:!1}).run(),Ve=(e,t)=>e.chain().focus().command(({state:o,dispatch:r})=>{const i=le(o);if(!i)return!1;const s=i.cellRect.top,l=t==="up"?s-1:s+1;return l>=0&&l<i.map.height?r?P.moveTableRow({from:s,to:l})(o,r):!0:!1}).run(),Dn=e=>e.chain().focus().command(({state:t,dispatch:o})=>{const r=le(t);if(!r||!o)return!1;const{tableNode:i,tablePos:s,cellRect:l}=r,a=l.top,d=t.tr,c=i.child(a),u=c.copy(de.Fragment.fromJSON(t.schema,c.content.toJSON()));let p=s+1;for(let h=0;h<=a;h++)p+=i.child(h).nodeSize;return d.insert(p,u),o(d),!0}).run(),Pn=e=>e.chain().focus().command(({state:t,dispatch:o})=>{const r=le(t);if(!r||!o)return!1;const{tableNode:i,tablePos:s,map:l,cellRect:a}=r,d=a.left,c=t.tr;let u=0;for(let p=0;p<l.height;p++){const h=p*l.width+d,f=l.map[h],b=s+1+f,g=t.doc.nodeAt(b);if(!g)continue;const v=g.copy(de.Fragment.fromJSON(t.schema,g.content.toJSON())),j=b+g.nodeSize+u;c.insert(j,v),u+=v.nodeSize}return o(c),!0}).run(),Oe=(e,t)=>{const{backgroundColor:o,textColor:r}=t;return e.chain().focus().command(({state:i,tr:s,dispatch:l})=>{const a=i.selection,d=[];if(a instanceof P.CellSelection||a.forEachCell)a.forEachCell((c,u)=>{d.push(u)});else{const c=a.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){d.push(c.before(u));break}}}return d.length===0?!1:(l&&(d.forEach(c=>{const u=s.doc.nodeAt(c);if(u){if(o!==void 0){const p=u.attrs;s.setNodeMarkup(c,void 0,{...p,background:o==="transparent"?null:o})}if(r!==void 0){const p=c+1,h=c+u.nodeSize-1,f=i.schema.marks.textStyle.create({color:r});s.removeMark(p,h,i.schema.marks.textStyle),s.addMark(p,h,f)}}}),l(s)),!0)}).run()},ne=(e,t)=>{const{horizontal:o,vertical:r}=t;return e.chain().focus().command(({state:i,tr:s,dispatch:l})=>{const a=i.selection,d=[];if(a instanceof P.CellSelection||a.forEachCell)a.forEachCell((c,u)=>{d.push(u)});else{const c=a.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){d.push(c.before(u));break}}}return d.length===0?!1:(l&&(d.forEach(c=>{const u=s.doc.nodeAt(c);if(!u)return;const p={...u.attrs};o&&(p.alignment=o),r&&(p.verticalAlignment=r),s.setNodeMarkup(c,void 0,p)}),l(s)),!0)}).run()},Bn=e=>{const t={isInsideTable:!1,horizontal:"left",vertical:"top"};if(!e)return t;const o=le(e.state);if(!o)return t;const{tableNode:r,map:i,cellPos:s}=o,l=e.state.doc.nodeAt(s);return l?{isInsideTable:!0,horizontal:l.attrs.alignment||"left",vertical:l.attrs.verticalAlignment||"top"}:t},Qe={common:{close:"Đóng",delete:"Xoá",color:"Màu",recentlyUsed:"Dùng gần đây",noResults:"Không tìm thấy kết quả",moreOptions:"Tuỳ chọn khác"},align:{left:"Căn trái",center:"Căn giữa",right:"Căn phải",justify:"Căn đều",top:"Căn trên",middle:"Căn giữa theo chiều dọc",bottom:"Căn dưới"},marks:{bold:"In đậm",italic:"In nghiêng",underline:"Gạch chân",strike:"Gạch ngang",code:"Mã",link:"Liên kết"},placeholder:{emptyDocument:"Nhập nội dung, hoặc gõ '/' để mở danh sách lệnh…",heading:e=>`Tiêu đề ${e}`},slash:{filterTag:"Bộ lọc",filterHint:"Bộ lọc…",groups:{style:"Định dạng",insert:"Chèn",upload:"Tải lên"}},blocks:{text:{title:"Văn bản",description:"Bắt đầu viết với văn bản thường."},heading1:{title:"Tiêu đề 1",description:"Tiêu đề lớn."},heading2:{title:"Tiêu đề 2",description:"Tiêu đề vừa."},heading3:{title:"Tiêu đề 3",description:"Tiêu đề nhỏ."},bulletList:{title:"Danh sách gạch đầu dòng",description:"Danh sách không đánh số."},orderedList:{title:"Danh sách đánh số",description:"Danh sách có đánh số thứ tự."},taskList:{title:"Danh sách công việc",description:"Danh sách có ô đánh dấu hoàn thành."},blockquote:{title:"Trích dẫn",description:"Chèn một khối trích dẫn."},codeBlock:{title:"Khối mã",description:"Chèn một khối mã nguồn."},hardBreak:{title:"Ngắt dòng",description:"Xuống dòng trong cùng một đoạn."},clearLine:{title:"Xoá dòng",description:"Xoá sạch nội dung dòng hiện tại."},separator:{title:"Đường kẻ ngang",description:"Chèn một đường phân cách."},emoji:{title:"Emoji",description:"Chèn biểu tượng cảm xúc."},mention:{title:"Nhắc đến",description:"Nhắc đến một người."},table:{title:"Bảng",description:"Chèn một bảng."},tableOfContents:{title:"Mục lục",description:"Chèn mục lục tự cập nhật theo các tiêu đề."},image:{title:"Hình ảnh",description:"Chèn vùng tải ảnh lên."},attachment:{title:"Tệp đính kèm",description:"Tải lên Word, PDF, bảng tính…"}},bubble:{turnInto:"Chuyển thành",linkPlaceholder:"Dán liên kết…",improve:"Cải thiện",pasteLink:"Dán liên kết…",textColor:"Màu chữ",backgroundColor:"Màu nền",increaseIndent:"Tăng thụt lề",decreaseIndent:"Giảm thụt lề"},drag:{handleHint:"Nhấn để mở tuỳ chọn, giữ để kéo",resetFormatting:"Xoá định dạng",duplicate:"Nhân đôi",copyToClipboard:"Sao chép",copyAnchorLink:"Sao chép liên kết neo",askAi:"Hỏi AI",insertBlock:"Chèn khối"},table:{alignment:"Căn chỉnh",alignLeft:"Căn trái",alignCenter:"Căn giữa",alignRight:"Căn phải",alignJustify:"Căn đều",alignTop:"Căn trên",alignMiddle:"Căn giữa theo chiều dọc",alignBottom:"Căn dưới",mergeCells:"Gộp ô",splitCell:"Tách ô",insertRowBefore:"Chèn hàng phía trên",insertRowAfter:"Chèn hàng phía dưới",insertColumnBefore:"Chèn cột bên trái",insertColumnAfter:"Chèn cột bên phải",deleteRow:"Xoá hàng",deleteColumn:"Xoá cột",duplicateRow:"Nhân đôi hàng",duplicateColumn:"Nhân đôi cột",clearRowContents:"Xoá nội dung hàng",clearColumnContents:"Xoá nội dung cột",moveRowUp:"Chuyển hàng lên",moveRowDown:"Chuyển hàng xuống",moveColumnLeft:"Chuyển cột sang trái",moveColumnRight:"Chuyển cột sang phải",deleteTable:"Xoá bảng"},image:{clickToUpload:"Nhấn để tải ảnh lên",delete:"Xoá ảnh",orDragAndDrop:"hoặc kéo thả vào đây",limitHint:(e,t)=>`Tối đa ${e} tệp, mỗi tệp ${t}MB.`,clearAll:"Xoá tất cả",caption:"Chú thích",download:"Tải ảnh về",replace:"Thay ảnh"},emojiPicker:{empty:"Không tìm thấy emoji",loading:"Đang tải…"},attachment:{clickToUpload:"Nhấn để chọn tệp (Word, PDF, bảng tính…)",uploading:"Đang tải tệp lên…",download:"Tải tệp về"},toc:{title:"Mục lục",empty:"Chưa có tiêu đề nào"}},et={common:{close:"Close",delete:"Delete",color:"Color",recentlyUsed:"Recently used",noResults:"No results found",moreOptions:"More options"},align:{left:"Align left",center:"Align center",right:"Align right",justify:"Justify",top:"Align top",middle:"Align middle",bottom:"Align bottom"},marks:{bold:"Bold",italic:"Italic",underline:"Underline",strike:"Strikethrough",code:"Code",link:"Link"},placeholder:{emptyDocument:"Write, or type '/' for commands…",heading:e=>`Heading ${e}`},slash:{filterTag:"Filters",filterHint:"Filters…",groups:{style:"Style",insert:"Insert",upload:"Upload"}},blocks:{text:{title:"Text",description:"Just start typing with plain text."},heading1:{title:"Heading 1",description:"Big section heading."},heading2:{title:"Heading 2",description:"Medium section heading."},heading3:{title:"Heading 3",description:"Small section heading."},bulletList:{title:"Bullet list",description:"An unordered list."},orderedList:{title:"Numbered list",description:"A list with numbering."},taskList:{title:"To-do list",description:"A list with checkboxes."},blockquote:{title:"Blockquote",description:"Insert a quote block."},codeBlock:{title:"Code block",description:"Insert a block of code."},hardBreak:{title:"Line break",description:"Break a line inside a paragraph."},clearLine:{title:"Clear line",description:"Clear the current line."},separator:{title:"Divider",description:"Insert a horizontal rule."},emoji:{title:"Emoji",description:"Insert an emoji."},mention:{title:"Mention",description:"Mention a person."},table:{title:"Table",description:"Insert a table."},tableOfContents:{title:"Table of contents",description:"Insert a live outline of your headings."},image:{title:"Image",description:"Insert an image upload zone."},attachment:{title:"Attachment",description:"Upload a Word, PDF or spreadsheet file."}},bubble:{turnInto:"Turn into",linkPlaceholder:"Paste a link…",improve:"Improve",pasteLink:"Paste a link…",textColor:"Text color",backgroundColor:"Background color",increaseIndent:"Increase indent",decreaseIndent:"Decrease indent"},drag:{handleHint:"Click for options, hold to drag",resetFormatting:"Reset formatting",duplicate:"Duplicate",copyToClipboard:"Copy to clipboard",copyAnchorLink:"Copy anchor link",askAi:"Ask AI",insertBlock:"Insert block"},table:{alignment:"Alignment",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignJustify:"Justify",alignTop:"Align top",alignMiddle:"Align middle",alignBottom:"Align bottom",mergeCells:"Merge cells",splitCell:"Split cell",insertRowBefore:"Insert row above",insertRowAfter:"Insert row below",insertColumnBefore:"Insert column left",insertColumnAfter:"Insert column right",deleteRow:"Delete row",deleteColumn:"Delete column",duplicateRow:"Duplicate row",duplicateColumn:"Duplicate column",clearRowContents:"Clear row contents",clearColumnContents:"Clear column contents",moveRowUp:"Move row up",moveRowDown:"Move row down",moveColumnLeft:"Move column left",moveColumnRight:"Move column right",deleteTable:"Delete table"},image:{clickToUpload:"Click to upload",delete:"Delete image",orDragAndDrop:"or drag and drop",limitHint:(e,t)=>`Maximum ${e} file${e===1?"":"s"}, ${t}MB each.`,clearAll:"Clear all",caption:"Caption",download:"Download image",replace:"Replace"},emojiPicker:{empty:"No emoji found",loading:"Loading…"},attachment:{clickToUpload:"Click to choose a file (Word, PDF, spreadsheet…)",uploading:"Uploading file…",download:"Download file"},toc:{title:"Table of contents",empty:"No headings found"}},Y="vi",$e={vi:Qe,en:et},ge=(e=Y)=>$e[e]??$e[Y],tt=x.createContext(ge(Y)),Vn=({locale:e=Y,children:t})=>{const o=x.useMemo(()=>ge(e),[e]);return n.jsx(tt.Provider,{value:o,children:t})},H=()=>x.useContext(tt),nt=({editor:e})=>{const t=H(),{horizontal:o,vertical:r}=Bn(e);return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(Sn,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:t.table.alignment})]}),n.jsx(Ae,{children:n.jsxs(Re,{sideOffset:8,alignOffset:-90,className:"w-50 z-120",children:[n.jsx(q,{onClick:()=>ne(e,{horizontal:"left"}),icon:m.TextAlignStart,label:t.table.alignLeft,className:o==="left"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.TextAlignCenter,label:t.table.alignCenter,onClick:()=>ne(e,{horizontal:"center"}),className:o==="center"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.TextAlignEnd,label:t.table.alignRight,onClick:()=>ne(e,{horizontal:"right"}),className:o==="right"?"text-foreground! bg-accent!":""}),n.jsx(W,{}),n.jsx(q,{icon:m.AlignVerticalJustifyStart,label:t.table.alignTop,onClick:()=>ne(e,{vertical:"top"}),className:r==="top"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.AlignVerticalJustifyCenter,label:t.table.alignMiddle,onClick:()=>ne(e,{vertical:"middle"}),className:r==="middle"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.AlignVerticalJustifyEnd,label:t.table.alignBottom,onClick:()=>ne(e,{vertical:"bottom"}),className:r==="bottom"?"text-foreground! bg-accent!":""})]})})]})},ot=({color:e,onClick:t})=>n.jsxs(F,{onClick:t,className:"py-1.5 rounded-lg text-muted-foreground px-2.5 gap-2",children:[e.type==="text"?n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-color-text",style:{color:`var(--tt-color-text-${e.value})`,"--color-text-button-color":`var(--tt-color-text-${e.value})`},children:n.jsx(He,{})}):n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-highlight",style:{"--highlight-color":e.value==="default"?"var(--background)":`var(--tt-color-highlight-${e.value})`}}),e.name," ",e.type]}),rt="recentlyUsedColors",On=3,qe=[{name:"Default",value:"default",type:""},{name:"Gray",value:"gray",type:""},{name:"Brown",value:"brown",type:""},{name:"Orange",value:"orange",type:""},{name:"Yellow",value:"yellow",type:""},{name:"Green",value:"green",type:""},{name:"Blue",value:"blue",type:""},{name:"Purple",value:"purple",type:""},{name:"Pink",value:"pink",type:""},{name:"Red",value:"red",type:""}],Q=e=>[{title:e.bubble.textColor,colors:qe.map(t=>({...t,type:"text"}))},{title:e.bubble.backgroundColor,colors:qe.map(t=>({...t,type:"background"}))}],xe=()=>{if(typeof window>"u")return[];const e=localStorage.getItem(rt);return e?JSON.parse(e):[]},Ie=(e,t,o)=>{const i=xe().filter(l=>l.value!==e.value||l.type!==e.type),s=[e,...i].slice(0,On);localStorage.setItem(rt,JSON.stringify(s)),t(()=>[{title:o.common.recentlyUsed,colors:s},...Q(o)])},st=({editor:e})=>{const t=H();if(!e)return;const[o,r]=x.useState(()=>{const i=xe();return i.length>0?[{title:t.common.recentlyUsed,colors:i},...Q(t)]:Q(t)});return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(m.PaintBucket,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:t.common.color})]}),n.jsx(Ae,{children:n.jsx(Re,{sideOffset:8,className:"w-55 pr-px z-120",children:n.jsx(ie,{className:"h-90 p-0.5 pr-3",children:o.map(i=>n.jsxs(X,{children:[n.jsx(Je,{className:"text-foreground",children:i.title}),i.colors.map(s=>n.jsx(ot,{onClick:()=>{if(Ie(s,r,t),s.type==="background"){Oe(e,{backgroundColor:`var(--tt-color-text-${s.value})`});return}Oe(e,{textColor:`var(--tt-color-text-${s.value})`})},color:s},s.value))]},i.title))})})})]})},$n=e=>{const t={isInsideTable:!1,currentColumnIndex:-1,isFirstColumn:!0,isLastColumn:!0,currentRowIndex:-1,isFirstRow:!0,isLastRow:!0};if(!e)return t;const{state:o}=e,r=o.selection;let i=null;if(r.anchorCell)i=r.anchorCell.pos;else{const f=r.$anchor;for(let b=f.depth;b>0;b--){const g=f.node(b).type.name;if(g==="tableCell"||g==="tableHeader"){i=f.before(b);break}}}if(i===null)return t;const s=o.doc.resolve(i);let l=null,a=-1;for(let f=s.depth;f>0;f--)if(s.node(f).type.name==="table"){l=s.node(f),a=s.before(f);break}if(!l||a===-1)return t;const d=P.TableMap.get(l),c=i-a-1,u=d.findCell(c),p=u.left,h=u.top;return{isInsideTable:!0,currentColumnIndex:p,isFirstColumn:p===0,isLastColumn:p===d.width-1,currentRowIndex:h,isFirstRow:h===0,isLastRow:h===d.height-1}},Fe=(e,t)=>{if(!e)return!1;const o=le(e.state);if(!o)return!1;const{tableNode:r,map:i,cellRect:s}=o;if(t==="column"){const l=s.left;for(let a=0;a<i.height;a++){const d=a*i.width+l,c=i.map[d],u=r.nodeAt(c);if(u&&u.textContent.trim().length>0)return!0}}if(t==="row"){const l=s.top;for(let a=0;a<i.width;a++){const d=l*i.width+a,c=i.map[d],u=r.nodeAt(c);if(u&&u.textContent.trim().length>0)return!0}}return!1},pe="flex items-center gap-2 px-2.5 rounded-md text-sm font-medium transition-colors cursor-pointer w-full",Ue=({editor:e,type:t,pluginKey:o})=>{const r=H(),[i,s]=x.useState(!1),l=t==="row",a=l?m.EllipsisVerticalIcon:m.EllipsisIcon,d=l?"w-3 h-full rounded flex items-center justify-center transition-colors":"w-full h-3 rounded flex items-center justify-center transition-colors",c=j=>{s(j),e.chain().command(({tr:C})=>(C.setMeta(o,{openedMenu:j}),!0)).run()},{isInsideTable:u,isFirstColumn:p,isLastColumn:h,isFirstRow:f,isLastRow:b}=$n(e),g=Fe(e,"row"),v=Fe(e,"column");return n.jsxs(Ne,{open:i,onOpenChange:c,children:[n.jsx(Me,{className:y(d,{"bg-primary text-primary-foreground":i,"text-secondary-foreground bg-accent":!i}),children:n.jsx(a,{className:"size-4 shrink-0"})}),n.jsx(Se,{className:"shadow-xl w-60 pr-px",align:"start",side:l?"right":"bottom",children:n.jsxs(ie,{className:"h-70 overflow-hidden overflow-y-auto p-0.5 pr-3",children:[n.jsxs(X,{children:[n.jsx(q,{icon:l?m.ArrowUp:m.ArrowLeft,label:l?r.table.moveRowUp:r.table.moveColumnLeft,onClick:()=>{l?Ve(e,"up"):Be(e,"left")},disabled:l?f:p}),n.jsx(q,{icon:l?m.ArrowDown:m.ArrowRight,label:l?r.table.moveRowDown:r.table.moveColumnRight,onClick:()=>{l?Ve(e,"down"):Be(e,"right")},disabled:l?b:h})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(q,{icon:l?An:kn,label:l?r.table.insertRowBefore:r.table.insertColumnBefore,onClick:()=>l?e.chain().focus().addRowBefore().run():e.chain().focus().addColumnBefore().run()}),n.jsx(q,{icon:l?Mn:Nn,label:l?r.table.insertRowAfter:r.table.insertColumnAfter,onClick:()=>l?e.chain().focus().addRowAfter().run():e.chain().focus().addColumnAfter().run()})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(st,{editor:e}),n.jsx(nt,{editor:e}),(g||v)&&n.jsx(q,{icon:m.SquareX,label:l?r.table.clearRowContents:r.table.clearColumnContents,onClick:()=>e.chain().focus().command(({state:j,dispatch:C})=>P.deleteCellSelection(j,C)).run()})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(q,{icon:m.CopyIcon,label:l?r.table.duplicateRow:r.table.duplicateColumn,onClick:()=>l?Dn(e):Pn(e)}),n.jsx(q,{icon:m.Trash,label:l?r.table.deleteRow:r.table.deleteColumn,variant:"destructive",onClick:()=>l?e.chain().focus().deleteRow().run():e.chain().focus().deleteColumn().run()})]})]})})]})},qn=({editor:e,setColor:t})=>{const o=H(),[r,i]=x.useState(()=>{const s=xe();return s.length>0?[{title:o.common.recentlyUsed,colors:s},...Q(o)]:Q(o)});return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(m.PaintBucket,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:o.common.color})]}),n.jsx(Ae,{children:n.jsx(Re,{sideOffset:8,className:"w-55 pr-px z-120",children:n.jsx(ie,{className:"h-90 p-0.5 pr-3",children:r.map(s=>n.jsxs(X,{children:[n.jsx(Je,{className:"text-foreground",children:s.title}),s.colors.map(l=>n.jsx(ot,{onClick:()=>t(l),color:l},l.value))]},s.title))})})})]})},Fn={placement:"left-start",strategy:"absolute"},it=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),[i,s]=x.useState(null);if(!e)return;const l=c=>{const u=c.currentTarget.closest(".drag-handle");if(!u)return null;const p=u.getBoundingClientRect(),h=p.right+20,f=p.top+p.height/2;return e.view.posAtCoords({left:h,top:f})},a=c=>{c.preventDefault(),c.stopPropagation();const u=l(c);if(u&&u.pos!==null){const p=e.state.doc.resolve(u.pos),h=p.end(p.depth);e.chain().insertContentAt(h,{type:"paragraph",content:[{type:"text",text:"/"}]}).focus().run()}},d=c=>{const u=l(c);if(!u||u.pos===null)return;const p=e.state.doc.resolve(u.pos);let h=p.depth;for(let g=p.depth;g>0;g--){const v=p.node(g)?.type.name;if(v==="blockquote"||v==="bulletList"||v==="orderedList"||v==="table"){h=g;break}}const f=p.before(h),b=p.node(h);if(f!==void 0&&b&&b.type.name!=="doc"){const{tr:g}=e.state,v=D.NodeSelection.create(e.state.doc,f);e.view.dispatch(g.setSelection(v)),s(b.type.name),console.log("Active Block Node Status:",b.type.name),r(!0)}};return n.jsx(Et,{className:"drag-handle",editor:e,nested:!1,computePositionConfig:Fn,children:n.jsxs("div",{className:"flex items-center gap-1 mr-2 ",children:[n.jsx(K,{content:t.drag.insertBlock,children:n.jsx(z,{onClick:a,variant:"ghost",className:"",size:"icon-sm",children:n.jsx(m.Plus,{})})}),n.jsx("div",{className:"relative",children:n.jsxs(Ne,{open:o,onOpenChange:r,children:[n.jsx(K,{className:"max-w-30 text-center",content:"Click for options Hold for dragging",children:n.jsx(z,{onClick:d,variant:"ghost",size:"icon-sm",children:n.jsx(m.GripVertical,{})})}),n.jsx(Me,{className:"sr-only",children:"open"}),n.jsx(Un,{editor:e})]})})]})})},Un=({editor:e})=>{const t=H(),o=r=>{if(Ie(r,()=>{},t),r.type==="text"){e.chain().focus().setColor(`var(--tt-color-text-${r.value})`).run();return}hn(e,`var(--tt-color-text-${r.value})`)};return n.jsxs(Se,{align:"center",sideOffset:30,side:"left",className:"w-55",children:[n.jsx(qn,{setColor:o,editor:e}),n.jsxs(F,{className:y("text-muted-foreground"),children:[n.jsx(m.RotateCcw,{})," ",t.drag.resetFormatting]}),n.jsx(W,{}),n.jsxs(F,{onClick:()=>fn(e),className:y("text-muted-foreground"),children:[n.jsx(m.Copy,{})," ",t.drag.duplicate,n.jsx(ae,{children:"⌘D"})]}),n.jsxs(F,{onClick:()=>pn(e),className:y("text-muted-foreground"),children:[n.jsx(m.Clipboard,{})," ",t.drag.copyToClipboard,n.jsx(ae,{children:"⌘C"})]}),n.jsxs(F,{disabled:!0,className:y("text-muted-foreground"),children:[n.jsx(m.Link,{})," ",t.drag.copyAnchorLink,n.jsx(ae,{children:"⌘^L"})]}),n.jsx(W,{}),n.jsxs(F,{disabled:!0,className:y("text-muted-foreground"),children:[n.jsx(m.Sparkles,{})," ",t.drag.askAi,n.jsx(ae,{children:"⌘J"})]}),n.jsx(W,{}),n.jsxs(F,{onClick:()=>mn(e),variant:"destructive",children:[n.jsx(m.Trash,{})," ",t.common.delete,n.jsx(ae,{children:"Del"})]})]})},V=({onClick:e,isActive:t,icon:o,className:r,text:i,size:s,showTooltip:l,tooltip:a,disabled:d,...c})=>{const u=()=>{if(x.isValidElement(o))return x.cloneElement(o,{className:y("stroke-[2.75]",o.props.className)});const p=o;return n.jsx(p,{className:"stroke-[2.75]"})};return n.jsx(K,{content:a,showTooltip:l,children:n.jsxs(z,{size:s||(i?"default":"icon"),variant:t?"secondary":"ghost",className:y("",r),onClick:e,disabled:d,...c,children:[u()," ",i]})})};function J({className:e,orientation:t="horizontal",decorative:o=!0,...r}){return n.jsx(S.Separator.Root,{"data-slot":"separator",decorative:o,orientation:t,className:y("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",e),...r})}const _n=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M4 2C4 1.44772 3.55228 1 3 1C2.44772 1 2 1.44772 2 2V22C2 22.5523 2.44772 23 3 23C3.55228 23 4 22.5523 4 22V2Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M10 4C8.34315 4 7 5.34315 7 7V17C7 18.6569 8.34315 20 10 20H19C20.6569 20 22 18.6569 22 17V7C22 5.34315 20.6569 4 19 4H10ZM9 7C9 6.44772 9.44772 6 10 6H19C19.5523 6 20 6.44772 20 7V17C20 17.5523 19.5523 18 19 18H10C9.44772 18 9 17.5523 9 17V7Z",fill:"currentColor"})]}),Wn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M21 1C21.5523 1 22 1.44772 22 2V22C22 22.5523 21.5523 23 21 23C20.4477 23 20 22.5523 20 22V2C20 1.44772 20.4477 1 21 1Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M2 7C2 5.34315 3.34315 4 5 4H14C15.6569 4 17 5.34315 17 7V17C17 18.6569 15.6569 20 14 20H5C3.34315 20 2 18.6569 2 17V7ZM5 6C4.44772 6 4 6.44772 4 7V17C4 17.5523 4.44772 18 5 18H14C14.5523 18 15 17.5523 15 17V7C15 6.44772 14.5523 6 14 6H5Z",fill:"currentColor"})]}),Zn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12 1C12.5523 1 13 1.44772 13 2V22C13 22.5523 12.5523 23 12 23C11.4477 23 11 22.5523 11 22V2C11 1.44772 11.4477 1 12 1Z",fill:"currentColor"}),n.jsx("path",{d:"M2 7C2 5.34315 3.34315 4 5 4H7C7.55228 4 8 4.44772 8 5C8 5.55228 7.55228 6 7 6H5C4.44772 6 4 6.44772 4 7V17C4 17.5523 4.44772 18 5 18H7C7.55228 18 8 18.4477 8 19C8 19.5523 7.55228 20 7 20H5C3.34315 20 2 18.6569 2 17V7Z",fill:"currentColor"}),n.jsx("path",{d:"M19 4C20.6569 4 22 5.34315 22 7V17C22 18.6569 20.6569 20 19 20H17C16.4477 20 16 19.5523 16 19C16 18.4477 16.4477 18 17 18H19C19.5523 18 20 17.5523 20 17V7C20 6.44772 19.5523 6 19 6H17C16.4477 6 16 5.55228 16 5C16 4.44772 16.4477 4 17 4H19Z",fill:"currentColor"})]}),lt=({editor:e,onReplaceClick:t})=>{const o=H();if(!e)return;const{alignment:r}=e.getAttributes("image"),i=l=>{e.chain().focus().updateAttributes("image",{alignment:l}).run()},s=()=>{e.chain().focus().deleteNode("image").insertContent({type:"imageUpload"}).run()};return n.jsxs(Xe.BubbleMenu,{pluginKey:"imageMenu",editor:e,shouldShow:({editor:l,view:a})=>a.hasFocus()&&l.isActive("image"),options:{offset:6},className:"bg-card not-prose border shadow-xl rounded-xl px-0.5 flex items-center gap-1 py-0.5",children:[n.jsxs("div",{className:" flex items-center gap-1 ",children:[n.jsx(V,{tooltip:o.align.left,icon:n.jsx(_n,{}),isActive:r==="left",onClick:()=>i("left")}),n.jsx(V,{tooltip:o.align.center,icon:n.jsx(Zn,{}),isActive:r==="center",onClick:()=>i("center")}),n.jsx(V,{tooltip:o.align.right,icon:n.jsx(Wn,{}),isActive:r==="right",onClick:()=>i("right")})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:o.image.download,icon:m.Download,onClick:()=>e.chain().focus().toggleBold().run()}),n.jsx(V,{tooltip:"Replace",icon:m.RefreshCcw,onClick:s}),n.jsx(V,{variant:"destructive",tooltip:o.image.delete,icon:m.Trash2,onClick:()=>e.chain().focus().deleteSelection().run()})]})]})};function be({...e}){return n.jsx(S.Popover.Root,{"data-slot":"popover",...e})}function Ce({...e}){return n.jsx(S.Popover.Trigger,{"data-slot":"popover-trigger",...e})}function ve({className:e,align:t="center",sideOffset:o=4,...r}){return n.jsx(S.Popover.Portal,{children:n.jsx(S.Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:y("z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r})})}const Kn=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),[i,s]=x.useState(""),{isLink:l,activeUrl:a}=N.useEditorState({editor:e,selector:p=>({isLink:p.editor.isActive("link"),activeUrl:p.editor.getAttributes("link").href||""})});x.useEffect(()=>{o&&s(a)},[o,a]);const d=x.useCallback(()=>{if(i)try{e.chain().focus().extendMarkRange("link").setLink({href:i}).run(),r(!1)}catch(p){console.error(p)}},[e,i]),c=x.useCallback(()=>{try{e.chain().focus().extendMarkRange("link").unsetLink().run(),s(""),r(!1)}catch(p){console.error(p)}},[e]),u=p=>{p.key==="Enter"&&(p.preventDefault(),d())};return n.jsxs(be,{open:o,onOpenChange:r,children:[n.jsx(K,{content:t.marks.link,children:n.jsx(Ce,{asChild:!0,children:n.jsx(z,{variant:l?"secondary":"ghost",size:"icon",children:n.jsx(m.Link,{className:y(l&&"text-blue-500")})})})}),n.jsx(ve,{className:"p-1.5 rounded-xl w-78.75 shadow-xl",side:"bottom",align:"center",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("input",{value:i,onChange:p=>s(p.target.value),onKeyDown:u,className:"border-0 outline-0 min-w-48 text-sm w-full h-8 py-1 pl-2.5 pr-0 bg-transparent",placeholder:t.bubble.linkPlaceholder,autoFocus:!0}),n.jsx("div",{children:n.jsx(z,{disabled:!i,onClick:d,variant:"ghost",size:"icon",type:"button",children:n.jsx(m.CornerDownLeft,{})})}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(z,{disabled:!i,variant:"ghost",size:"icon",asChild:!0,children:n.jsx("a",{href:i||void 0,target:"_blank",rel:"noopener noreferrer",className:y(!i&&"pointer-events-none opacity-50"),children:n.jsx(m.ExternalLink,{})})}),n.jsx(z,{disabled:!l,onClick:c,variant:"destructive",size:"icon",children:n.jsx(m.Trash,{})})]})]})})]})},Gn=({editor:e})=>{const t=H(),o=e.getAttributes("paragraph")["data-indent-level"]||e.getAttributes("heading")["data-indent-level"]||0,r=o<=0,i=o>=10;return n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:t.bubble.decreaseIndent,disabled:r,icon:m.ListIndentDecrease,onClick:()=>e.chain().focus().outdent().run()}),n.jsx(V,{tooltip:t.bubble.increaseIndent,disabled:i,icon:m.ListIndentIncrease,onClick:()=>e.chain().focus().indent().run()})]})},Xn=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),{isSubscript:i,isSuperscript:s,isAlignLeft:l,isAlignRight:a,isAlignCenter:d,isAlignJustify:c}=N.useEditorState({editor:e,selector:u=>({isSubscript:u.editor.isActive("subscript"),isSuperscript:u.editor.isActive("superscript"),isAlignLeft:u.editor.isActive({textAlign:"left"}),isAlignRight:u.editor.isActive({textAlign:"right"}),isAlignCenter:u.editor.isActive({textAlign:"center"}),isAlignJustify:u.editor.isActive({textAlign:"justify"})})});return n.jsxs(be,{open:o,onOpenChange:r,children:[n.jsx(K,{content:t.common.moreOptions,children:n.jsx(Ce,{asChild:!0,children:n.jsx(z,{variant:"ghost",size:"icon",children:n.jsx(m.EllipsisVertical,{})})})}),n.jsx(ve,{className:"p-1 rounded-xl max-w-fit shadow-xl",side:"top",align:"center",onOpenAutoFocus:u=>u.preventDefault(),children:n.jsxs("div",{className:"flex gap-0.5",children:[n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:"Subscript",isActive:i,icon:m.Subscript,onClick:()=>e.chain().focus().toggleSubscript().run()}),n.jsx(V,{tooltip:"Superscript",isActive:s,icon:m.Superscript,onClick:()=>e.chain().focus().toggleSuperscript().run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:t.align.left,isActive:l,icon:m.TextAlignStart,onClick:()=>e.chain().focus().toggleTextAlign("left").run()}),n.jsx(V,{tooltip:t.align.center,isActive:d,icon:m.TextAlignCenter,onClick:()=>e.chain().focus().toggleTextAlign("center").run()}),n.jsx(V,{tooltip:t.align.right,isActive:a,icon:m.TextAlignEnd,onClick:()=>e.chain().focus().toggleTextAlign("right").run()}),n.jsx(V,{tooltip:t.align.justify,isActive:c,icon:m.TextAlignJustify,onClick:()=>e.chain().focus().toggleTextAlign("justify").run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsx(Gn,{editor:e})]})})]})},Jn=({tooltip:e,color:t,onClick:o,editor:r})=>{const{isActive:i}=N.useEditorState({editor:r,selector:s=>({isActive:s.editor.isActive("textStyle",{color:`var(--tt-color-text-${t})`})})});return n.jsx(n.Fragment,{children:n.jsx(K,{content:e,children:n.jsx(z,{size:"icon",variant:i?"secondary":"ghost",style:{"--color-text-button-color":`var(--tt-color-text-${t})`},onClick:o,children:n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-color-text",style:{color:`var(--tt-color-text-${t})`},children:n.jsx(He,{})})})})})},Yn=({tooltip:e,color:t,onClick:o,editor:r})=>{const{isActive:i}=N.useEditorState({editor:r,selector:s=>({isActive:s.editor.isActive("highlight",{color:t.value==="default"?"var(--background)":`var(--tt-color-highlight-${t.value})`})})});return n.jsx(n.Fragment,{children:n.jsx(K,{content:e,children:n.jsx(z,{size:"icon",variant:i?"secondary":"ghost",onClick:o,children:n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-highlight",style:{"--highlight-color":t.value==="default"?"var(--background)":`var(--tt-color-highlight-${t.value})`}})})})})},Qn=({editor:e})=>{const t=H(),[o,r]=x.useState(()=>{const l=xe();return l.length>0?[{title:t.common.recentlyUsed,colors:l},...Q(t)]:Q(t)}),{textColor:i,highlightColor:s}=N.useEditorState({editor:e,selector:l=>({textColor:l.editor.getAttributes("textStyle").color,highlightColor:l.editor.getAttributes("highlight")})});return n.jsxs(be,{children:[n.jsx(K,{content:t.bubble.textColor,children:n.jsx(Ce,{asChild:!0,children:n.jsxs(z,{variant:"ghost",className:"p-2 gap-1",children:[n.jsx("span",{className:`size-5 flex items-center justify-center border rounded-full
2
- tiptap-button-color-text-popover`,style:{"--active-highlight-color":s?.color},children:n.jsx(He,{style:{color:i}})}),n.jsx(m.ChevronDown,{className:"size-3",size:10})]})})}),n.jsx(eo,{items:o,editor:e,handleAddRecentUsed:l=>Ie(l,r,t)})]})},eo=({items:e,editor:t,handleAddRecentUsed:o})=>n.jsx(ve,{onOpenAutoFocus:r=>r.preventDefault(),className:"w-47 rounded-2xl p-0 pr-px bg-popover shadow-2xl z-50 overflow-hidden",children:n.jsx(ie,{className:"h-66.25 p-1.5 pr-2.5",children:e.map((r,i)=>n.jsx("div",{children:n.jsxs("div",{className:"min-w-max flex relative flex-col justify-center align-middle",children:[n.jsx("div",{className:"capitalize pt-3 pb-1 px-1.5 leading-normal font-medium text-xs text-muted-foreground",children:r.title}),n.jsx("div",{className:"grid grid-cols-5 gap-0.5 pl-1",children:r.colors.map(s=>s.type==="text"?n.jsx(Jn,{editor:t,color:s.value,tooltip:`${s.name} ${s.type}`,onClick:()=>{t.chain().focus().setColor(`var(--tt-color-text-${s.value})`).run(),o(s)}}):s.type==="background"?n.jsx(Yn,{editor:t,color:s,tooltip:`${s.name} ${s.type}`,onClick:()=>{t.chain().focus().toggleHighlight({color:`var(--tt-color-highlight-${s.value})`}).run(),o(s)}}):"")})]})},r.title))})}),at={title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:n.jsx(m.Type,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run()}},ct={title:"Heading 1",description:"Big heading.",searchTerms:["h1","title","big","large"],icon:n.jsx(m.Heading1,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run()}},dt={title:"Heading 2",description:"Medium heading.",searchTerms:["h2","subtitle","medium"],icon:n.jsx(m.Heading2,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run()}},ut={title:"Heading 3",description:"Small heading.",searchTerms:["h3","subtitle","small"],icon:n.jsx(m.Heading3,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run()}},to={title:"Blockquote",description:"Add blockquote.",searchTerms:["quote","blockquote"],icon:n.jsx(m.TextQuote,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},pt={title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:n.jsx(m.List,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBulletList().run()}},mt={title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:n.jsx(m.ListOrdered,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleOrderedList().run()}},ft={title:"Tod-do list",description:"Create a todo list",searchTerms:["list","task","todo"],icon:n.jsx(m.ListTodo,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run()}},ht={title:"Code Block",description:"Insert a custom HTML block",searchTerms:["html","code","custom"],icon:n.jsx(m.CodeXmlIcon,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}},no=e=>[{title:e.bubble.turnInto,commands:[{...at,...e.blocks.text},{...ct,...e.blocks.heading1},{...dt,...e.blocks.heading2},{...ut,...e.blocks.heading3},{...pt,...e.blocks.bulletList},{...mt,...e.blocks.orderedList},{...ft,...e.blocks.taskList},{...ht,...e.blocks.codeBlock}]}],oo=e=>[{title:e.blocks.heading1.title,icon:m.Heading1,level:1},{title:e.blocks.heading2.title,icon:m.Heading2,level:2},{title:e.blocks.heading3.title,icon:m.Heading3,level:3}],ro=({editor:e})=>{const t=H(),o=oo(t),r=no(t),{activeBlock:i,isParagraph:s,isBulletList:l,isOrderedList:a,isTaskList:d,isBlockquote:c,isCodeBlock:u,headingLevel:p}=N.useEditorState({editor:e,selector:f=>{const b=o.find(g=>f.editor.isActive("heading",{level:g.level}));return{activeBlock:f.editor.getAttributes("paragraph"),isParagraph:f.editor.isActive("paragraph"),isBulletList:f.editor.isActive("bulletList"),isOrderedList:f.editor.isActive("orderedList"),isTaskList:f.editor.isActive("taskList"),isBlockquote:f.editor.isActive("blockquote"),isCodeBlock:f.editor.isActive("codeBlock"),headingLevel:b?b.title:null}}}),h=()=>s?t.blocks.text.title:p||(l?t.blocks.bulletList.title:a?t.blocks.orderedList.title:d?"To-do list":c?t.blocks.blockquote.title:u?t.blocks.codeBlock.title:t.blocks.text.title);return n.jsxs(be,{children:[n.jsx(Ce,{asChild:!0,children:n.jsxs(z,{variant:"ghost",children:[h()," ",n.jsx(m.ChevronDown,{})]})}),n.jsx(ve,{className:"w-48 rounded-2xl p-0 pr-px bg-popover shadow-2xl z-50 overflow-hidden",children:n.jsx(ie,{className:"h-66.25 p-1.5 pr-2.5",children:r.map((f,b)=>n.jsx("div",{children:n.jsxs("div",{className:"min-w-max flex relative flex-col justify-center align-middle",children:[n.jsx("div",{className:"capitalize pt-3 pb-1 px-1.5 leading-normal font-medium text-xs text-muted-foreground",children:f.title}),n.jsxs("div",{className:"flex flex-col",children:[n.jsxs(z,{variant:s?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().setParagraph().run(),children:[n.jsx(m.Type,{})," ",t.blocks.text.title]}),o.map(g=>n.jsx(so,{head:g,editor:e})),n.jsxs(z,{variant:l?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleBulletList().run(),children:[n.jsx(m.List,{})," ",t.blocks.bulletList.title]}),n.jsxs(z,{variant:a?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleOrderedList().run(),children:[n.jsx(m.ListOrdered,{})," ",t.blocks.orderedList.title]}),n.jsxs(z,{variant:d?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleTaskList().run(),children:[n.jsx(m.ListTodo,{})," ",t.blocks.taskList.title]}),n.jsxs(z,{disabled:d,variant:c?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleBlockquote().run(),children:[n.jsx(m.TextQuote,{})," ",t.blocks.blockquote.title]}),n.jsxs(z,{disabled:d,variant:u?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleCodeBlock().run(),children:[n.jsx(m.CodeXmlIcon,{})," ",t.blocks.codeBlock.title]})]})]})},f.title))})})]})},so=({head:e,editor:t})=>{const{isActive:o}=N.useEditorState({editor:t,selector:r=>({isActive:r.editor.isActive("heading",{level:e.level})})});return n.jsxs(z,{variant:o?"secondary":"ghost",className:"w-full justify-start",onClick:()=>t.chain().focus().toggleHeading({level:e.level}).run(),children:[n.jsx(e.icon,{})," ",e.title]})},gt=({editor:e})=>{const t=H();if(!e)return;const{isBold:o,isItalic:r,isStrikethrough:i,isUnderline:s,isCode:l}=N.useEditorState({editor:e,selector:a=>({isBold:a.editor.isActive("bold"),isItalic:a.editor.isActive("italic"),isStrikethrough:a.editor.isActive("strike"),isUnderline:a.editor.isActive("underline"),isCode:a.editor.isActive("code")})});return n.jsxs(Xe.BubbleMenu,{editor:e,pluginKey:"textMenu",className:"bg-card not-prose border shadow-xl rounded-xl px-1 flex items-center gap-1 py-1",shouldShow:({editor:a,view:d,state:c,from:u,to:p})=>a.isActive("image")||a.isActive("imageUpload")||a.isActive("table")?!1:d.hasFocus()&&!c.selection.empty,children:[n.jsx(ro,{editor:e}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:" flex items-center gap-1 ",children:[n.jsx(V,{tooltip:t.marks.bold,icon:m.Bold,isActive:o,onClick:()=>e.chain().focus().toggleBold().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.italic,icon:m.Italic,isActive:r,onClick:()=>e.chain().focus().toggleItalic().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.underline,icon:m.Underline,isActive:s,onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:l}),n.jsx(V,{tooltip:"Strikethrough",icon:m.Strikethrough,isActive:i,onClick:()=>e.chain().focus().toggleStrike().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.code,icon:m.Code,isActive:l,onClick:()=>e.chain().focus().toggleCode().run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:" flex gap-0.5",children:[n.jsx(Kn,{editor:e}),n.jsx(Qn,{editor:e})]}),n.jsx(J,{orientation:"vertical"}),n.jsx(Xn,{editor:e})]})},fe=new D.PluginKey("table-row-menu-handle"),he=new D.PluginKey("table-column-menu-handle"),io=({pluginKey:e,editor:t,element:o,menuType:r,options:i})=>{const s=i??{strategy:"absolute",placement:"top",offset:0,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},l=r==="row",a=[];let d=!1,c=!1,u,p;const h=()=>(a.length>0||(s.flip&&a.push(I.flip(typeof s.flip!="boolean"?s.flip:void 0)),s.shift&&a.push(I.shift(typeof s.shift!="boolean"?s.shift:void 0)),s.offset&&a.push(I.offset(typeof s.offset!="boolean"?s.offset:void 0)),s.arrow&&a.push(I.arrow(s.arrow)),s.size&&a.push(I.size(typeof s.size!="boolean"?s.size:void 0)),s.autoPlacement&&a.push(I.autoPlacement(typeof s.autoPlacement!="boolean"?s.autoPlacement:void 0)),s.hide&&a.push(I.hide(typeof s.hide!="boolean"?s.hide:void 0)),s.inline&&a.push(I.inline(typeof s.inline!="boolean"?s.inline:void 0))),a),f=()=>{if(p===void 0)return;const C=p;t.chain().command(({tr:w,state:A})=>{const R=A.doc.resolve(C),k=(l?P.CellSelection.rowSelection:P.CellSelection.colSelection)(R);return w.setSelection(k),!0}).run()},b=(C,w)=>{c||(o.style.visibility="visible",o.style.opacity="1",w?.appendChild(o),s.onShow?.(),c=!0)},g=()=>{!c||e.getState(t.view.state)?.openedMenu||(o.style.visibility="hidden",o.style.opacity="0",o.remove(),s.onHide?.(),c=!1,p=void 0,u=void 0)},v=(C,w)=>{if(e.getState(C.state)?.openedMenu)return;const R={getBoundingClientRect:()=>w,getClientRects:()=>[w]};I.computePosition(R,o,{placement:s.placement,strategy:s.strategy,middleware:h()}).then(({x:T,y:k,strategy:E})=>{l?o.style.height=`${w.height}px`:o.style.width=`${w.width}px`,o.style.position=E,o.style.left=`${T}px`,o.style.top=`${k}px`,c&&s.onUpdate?.()})},j=(C,w)=>{const A=w.target;if(!A)return;if(P.columnResizingPluginKey.getState(C.state)?.dragging){g();return}if(P.tableEditingKey.getState(C.state)!==null){g();return}if(l&&he.getState(C.state)?.openedMenu){g();return}else if(fe.getState(C.state)?.openedMenu){g();return}if(e.getState(C.state)?.openedMenu)return;const T=C.posAtDOM(A,0);if(T===void 0)return;let k,E;if(C.state.doc.nodesBetween(T,T,(ee,te)=>ee.type.name==="tableHeader"||ee.type.name==="tableCell"?(k=te,!1):(ee.type.name==="table"&&(E=te),!0)),E===void 0){g();return}u!==E&&g(),u=E;const M=C.nodeDOM(E);if(!M||!(M instanceof HTMLDivElement)){g();return}const L=M.querySelector("table");if(!L)return;const B=L.getBoundingClientRect(),U=16;if(w.x>B.right+U){g();return}if(w.x<B.left-U){g();return}if(w.y<B.top-U){g();return}if(w.y>B.bottom+U){g();return}if(k===void 0||p===k)return;const $=C.nodeDOM(k);if(!$||!($ instanceof HTMLTableCellElement))return;const _=$.getBoundingClientRect();p=k,l?_.x=B.x:_.y=B.y,v(C,_),!c&&b(C,M.querySelector(".table-controls"))};return new D.Plugin({key:e,state:{init:()=>({openedMenu:!1}),apply:(C,w)=>{const A=C.getMeta(e);return A?{openedMenu:A.openedMenu}:w}},view:()=>({update:(C,w)=>{const A=e.getState(w),R=e.getState(C.state),T=A!==R;if(T&&R?.openedMenu&&f(),l&&he.getState(C.state)?.openedMenu){g();return}else if(fe.getState(C.state)?.openedMenu){g();return}const k=!w?.selection.eq(C.state.selection),E=!w?.doc.eq(C.state.doc),{composing:M}=C;if(M||!k&&!E&&!T||!t.isActive("table"))return;if(p===void 0){g();return}const B=C.state.doc.nodeAt(p),U=N.findParentNodeClosestToPos(C.state.doc.resolve(p),Ht=>Ht.type.name==="table");if(!U||!B){g();return}const $=C.nodeDOM(p),_=C.nodeDOM(U.pos);if(!_||!(_ instanceof HTMLDivElement)){g();return}if(!$||!($ instanceof HTMLTableCellElement)){g();return}const ee=_.querySelector("table");if(!ee)return;const te=ee.getBoundingClientRect(),we=$.getBoundingClientRect();l?we.x=te.x:we.y=te.y,v(C,we)},destroy:()=>{g(),s.onDestroy?.()}}),props:{handleDOMEvents:{mousemove:(C,w)=>{d||(window.requestAnimationFrame(()=>{j(C,w),d=!1}),d=!0)},mousedown:j}}})},_e=({ref:e,children:t,pluginProps:o})=>{const r=x.useRef(document.createElement("div"));return x.useEffect(()=>{typeof e=="function"?e(r.current):e&&(e.current=r.current)},[e]),x.useEffect(()=>{const i=o.editor,s=r.current;if(s.style.visibility="hidden",s.style.position="absolute",i.isDestroyed)return;const l=io({...o,element:s});return i.registerPlugin(l),()=>{i.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{s.parentNode&&s.parentNode.removeChild(s)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),r.current)},lo=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),{canMergeCell:i,canSplitCell:s,canClearContents:l}=N.useEditorState({editor:e,equalityFn:(a,d)=>a.canMergeCell===d?.canMergeCell&&a.canSplitCell===d.canSplitCell&&a.canClearContents===d.canClearContents,selector:a=>{const d=a.editor,{selection:c}=d.state,{from:u,to:p,ranges:h}=c;if(!a.editor.isActive("table"))return{canMergeCell:!1,canSplitCell:!1,canClearContents:!1};let f=!1,b=0,g=0;if(c instanceof D.TextSelection&&d.state.doc.nodesBetween(u,p,(v,j)=>{const C=v.type.name;if(C==="tableHeader"||C==="tableCell"){const w=d.view.nodeDOM(j);return f=w.colSpan>1||w.rowSpan>1,!1}return!0}),c instanceof P.CellSelection){b=c.ranges.length;for(const v of h){const{$from:j,$to:C}=v;d.state.doc.nodesBetween(j.pos,C.pos,w=>(w.isTextblock&&(g+=w.content.size),!0))}}return{canMergeCell:b>1,canSplitCell:f,canClearContents:g>0}}});return n.jsxs(Ne,{open:o,onOpenChange:r,children:[n.jsx(Me,{className:y("absolute flex items-center justify-center top-1/2 -translate-y-1/2 hover:-right-2.25 bg-primary size-2 hover:size-4 rounded-full cursor-pointer pointer-events-auto",{"size-4 -right-2.25":o,"-right-1.25":!o}),asChild:!0,children:n.jsx("button",{onPointerDown:a=>{a.preventDefault(),r(!0)},children:n.jsx(m.EqualIcon,{className:y("size-3.5 text-primary-foreground opacity-0 hover:opacity-100",{"opacity-100":o})})})}),n.jsxs(Se,{className:"flex max-h-80 w-55 flex-col overflow-hidden overflow-y-auto shadow-xl",align:"start",side:"bottom",children:[n.jsxs(X,{children:[n.jsxs(F,{hidden:!i,onClick:()=>{e.chain().focus().mergeCells().run()},children:[n.jsx(Pe,{})," ",t.table.mergeCells]}),n.jsxs(F,{hidden:!s,onClick:()=>{e.chain().focus().splitCell().run()},children:[n.jsx(Pe,{})," ",t.table.splitCell]})]}),(i||s)&&n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(st,{editor:e}),n.jsx(nt,{editor:e})]}),l&&n.jsx(W,{}),l&&n.jsxs(F,{className:pe,onClick:()=>{e.chain().focus().command(({state:a,dispatch:d})=>P.deleteCellSelection(a,d)).run()},children:[n.jsx(m.SquareX,{})," ",t.table.clearColumnContents]})]})]})},ao=({pluginKey:e,editor:t,element:o,options:r})=>{const i=r??{strategy:"absolute",placement:"bottom-start",offset:({rects:b})=>({mainAxis:-b.reference.height}),flip:!1,shift:!1,arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},s=[];let l=!1,a;const d=()=>(s.length>0||(i.flip&&s.push(I.flip(typeof i.flip!="boolean"?i.flip:void 0)),i.shift&&s.push(I.shift(typeof i.shift!="boolean"?i.shift:void 0)),i.offset&&s.push(I.offset(typeof i.offset!="boolean"?i.offset:void 0)),i.arrow&&s.push(I.arrow(i.arrow)),i.size&&s.push(I.size(typeof i.size!="boolean"?i.size:void 0)),i.autoPlacement&&s.push(I.autoPlacement(typeof i.autoPlacement!="boolean"?i.autoPlacement:void 0)),i.hide&&s.push(I.hide(typeof i.hide!="boolean"?i.hide:void 0)),i.inline&&s.push(I.inline(typeof i.inline!="boolean"?i.inline:void 0))),s),c=b=>{const{domRect:g,selectionRect:v}=f(b);if(!g||!v){p();return}o.style.width=`${v.width}px`,o.style.height=`${v.height}px`;const j={getBoundingClientRect:()=>g,getClientRects:()=>[g]};I.computePosition(j,o,{placement:i.placement,strategy:i.strategy,middleware:d()}).then(({x:C,y:w,strategy:A})=>{o.style.position=A,o.style.left=`${C}px`,o.style.top=`${w}px`,l&&i.onUpdate?.()})},u=(b,g)=>{l||(o.style.visibility="visible",o.style.opacity="1",g?.appendChild(o),l=!0)},p=()=>{l&&(o.style.visibility="hidden",o.style.opacity="0",o.remove(),l=!1,a=void 0)},h=()=>{t.isActive("table")&&c(t.view)},f=b=>{let g,v;const{selection:j}=b.state;if(j instanceof P.CellSelection){let C,w,A,R;j.forEachCell((T,k)=>{const M=b.nodeDOM(k).getBoundingClientRect();v||(v=M),C=Math.min(C??M.top,M.top),w=Math.min(w??M.left,M.left),A=Math.max(A??M.right,M.right),R=Math.max(R??M.bottom,M.bottom),g={width:A-w,height:R-C},M.left<v.left&&M.top<v.top&&(v=M)})}return j instanceof D.TextSelection&&b.state.doc.nodesBetween(j.from,j.to,(C,w)=>{const A=C.type.name;if(A==="tableHeader"||A==="tableCell"){const T=b.nodeDOM(w).getBoundingClientRect();return v=T,g={width:T.width,height:T.height},!1}return!0}),{domRect:v,selectionRect:g}};return new D.Plugin({key:e,view:()=>(window.addEventListener("resize",h),{update:(b,g)=>{const v=!g?.selection.eq(b.state.selection),j=!g?.doc.eq(b.state.doc),{composing:C}=b;if(C||!v&&!j)return;if(!t.isActive("table")){p();return}c(b);const{ranges:A}=b.state.selection,R=Math.min(...A.map(M=>M.$from.pos)),T=Math.max(...A.map(M=>M.$to.pos));let k;if(t.state.doc.nodesBetween(R,T,(M,L)=>(M.type.name==="table"&&(k=L),!1)),k===void 0){p();return}if(a!==k&&p(),a=k,l)return;const E=b.nodeDOM(k);if(!E){p();return}u(b,E.querySelector(".table-selection-container"))},destroy:()=>{window.removeEventListener("resize",h),p(),i.onDestroy?.()}}),props:{handleDOMEvents:{mousemove:b=>{P.columnResizingPluginKey.getState(b.state)?.dragging&&c(b)}}}})};function co({ref:e,children:t,pluginProps:o}){const r=x.useRef(document.createElement("div"));return x.useEffect(()=>{typeof e=="function"?e(r.current):e&&(e.current=r.current)},[e]),x.useEffect(()=>{const i=o.editor,s=r.current;if(s.style.visibility="hidden",s.style.position="absolute",s.className=y("border-2 border-primary pointer-events-none"),i.isDestroyed)return;const l=ao({...o,element:s});return i.registerPlugin(l),()=>{i.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{s.parentNode&&s.parentNode.removeChild(s)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),r.current)}const uo=new D.PluginKey("add-row-plugin"),po=new D.PluginKey("add-column-plugin"),mo=4,fo=16,ho={row:{delta:(e,t)=>e.clientY-t,measure:e=>e.querySelector("tr:last-child")?.getBoundingClientRect().height??0,insert:Ln,remove:Rn},column:{delta:(e,t)=>e.clientX-t,measure:e=>e.querySelector("tr:first-child > *:last-child")?.getBoundingClientRect().width??0,insert:Hn,remove:En}};function xt(e,t){const o=ho[t];return r=>{r.preventDefault(),r.stopPropagation();const i=r.currentTarget.parentElement,s=i?.getAttribute("data-table-pos"),l=i?.closest(".table-wrapper")?.querySelector("table");if(!i||!s||!l)return;const a=parseInt(s,10),d=t==="row"?r.clientY:r.clientX,c=Math.max(o.measure(l),fo);let u=0;i.setAttribute(se,"true");const p=()=>i.dispatchEvent(new CustomEvent(ce)),h=b=>{const g=Math.round(o.delta(b,d)/c);for(;g>u&&o.insert(e,a);)u+=1;for(;g<u&&o.remove(e,a);)u-=1;p()},f=b=>{Math.abs(o.delta(b,d))<mo&&o.insert(e,a),i.removeAttribute(se),p(),window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",f)};window.addEventListener("mousemove",h),window.addEventListener("mouseup",f)}}function go({editor:e}){const t=xt(e,"row");return n.jsx("button",{className:"w-full h-3 bg-accent flex justify-center items-center rounded-full mt-1 cursor-ns-resize selection:bg-transparent",onMouseDown:t,children:n.jsx(m.Plus,{size:12})})}function xo({editor:e}){const t=xt(e,"column");return n.jsx("button",{className:"w-3 h-full bg-accent flex justify-center items-center rounded-full ml-1 cursor-ew-resize selection:bg-transparent",onMouseDown:t,children:n.jsx(m.Plus,{size:12})})}function bo({editor:e,element:t,pluginKey:o}){const r=s=>{t.style.transition="opacity 0.2s ease",t.style.opacity=s},i=()=>{const s=t.closest(".table-wrapper")?.querySelector("table");s&&(t.style.width=`${s.offsetWidth}px`)};return new D.Plugin({key:o,props:{handleDOMEvents:{mouseover(s,l){const a=l.target;if(t.hasAttribute(se))return!1;const d=t.contains(a),c=a.closest("table tr:last-child");if(d||c){const u=a.closest(".table-wrapper"),p=u?.querySelector("table"),h=u?.querySelector(".table-controls");if(h&&p){const f=s.posAtDOM(p,0);return t.setAttribute("data-table-pos",String(f-1)),h.contains(t)||(t.style.position="",h.appendChild(t)),t.style.width=`${p.offsetWidth}px`,r("1"),!1}}return r("0"),!1},mouseleave(){return t.hasAttribute(se)||r("0"),!1}}},view(){return t.style.opacity="0",t.style.visibility="visible",t.addEventListener(ce,i),{destroy(){t.removeEventListener(ce,i),t.remove()}}}})}const We=({ref:e,children:t,pluginProps:o,createPlugin:r=bo})=>{const i=x.useRef(document.createElement("div")),s=x.useRef(r);return s.current=r,x.useEffect(()=>{typeof e=="function"?e(i.current):e&&(e.current=i.current)},[e]),x.useEffect(()=>{const l=o.editor,a=i.current;if(a.style.visibility="hidden",a.style.position="absolute",l.isDestroyed)return;const d=s.current({...o,element:a});return l.registerPlugin(d),()=>{l.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{a.parentNode&&a.parentNode.removeChild(a)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),i.current)},Co=12,vo=4,wo=Co+vo;function yo({editor:e,element:t,pluginKey:o}){const r=l=>{t.style.transition="opacity 0.2s ease",t.style.opacity=l},i=(l,a)=>{const d=l.getBoundingClientRect(),c=a.getBoundingClientRect();t.style.position="absolute",t.style.top=`${c.top-d.top+l.scrollTop}px`,t.style.left=`${c.right-d.left+l.scrollLeft}px`,t.style.width=`${wo}px`,t.style.height=`${c.height}px`},s=()=>{const l=t.closest(".table-wrapper"),a=l?.querySelector("table");l&&a&&i(l,a)};return new D.Plugin({key:o,props:{handleDOMEvents:{mouseover(l,a){const d=a.target;if(t.hasAttribute(se))return!1;const c=t.contains(d),u=d.closest("td, th"),p=!!u&&u.parentElement?.lastElementChild===u;if(c||p){const h=d.closest(".table-wrapper"),f=h?.querySelector("table"),b=h?.querySelector(".table-controls");if(h&&b&&f){const g=l.posAtDOM(f,0);return t.setAttribute("data-table-pos",String(g-1)),b.contains(t)||b.appendChild(t),i(h,f),r("1"),!1}}return r("0"),!1},mouseleave(){return t.hasAttribute(se)||r("0"),!1}}},view(){return t.style.opacity="0",t.style.visibility="visible",t.addEventListener(ce,s),{destroy(){t.removeEventListener(ce,s),t.remove()}}}})}const bt=({editor:e})=>{const t=x.useMemo(()=>{if(e)return{editor:e,menuType:"column",pluginKey:he,options:{placement:"top-start",offset:{mainAxis:4}}}},[e]),o=x.useMemo(()=>{if(e)return{editor:e,menuType:"row",pluginKey:fe,options:{placement:"left-start",offset:{mainAxis:4}}}},[e]),r=x.useMemo(()=>{if(e)return{editor:e,pluginKey:uo}},[e]),i=x.useMemo(()=>{if(e)return{editor:e,pluginKey:po}},[e]),s=x.useMemo(()=>{if(e)return{editor:e,pluginKey:new D.PluginKey("table-selection-overlay")}},[e]);return e?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[t&&n.jsx(_e,{pluginProps:t,children:n.jsx(Ue,{pluginKey:he,type:"column",editor:e})}),o&&n.jsx(_e,{pluginProps:o,children:n.jsx(Ue,{pluginKey:fe,type:"row",editor:e})})]}),r&&n.jsx(We,{pluginProps:r,children:n.jsx(go,{editor:e})}),i&&n.jsx(We,{pluginProps:i,createPlugin:yo,children:n.jsx(xo,{editor:e})}),s&&n.jsx(co,{pluginProps:s,children:n.jsx(lo,{editor:e})})]}):null},jo=({items:e,scrollOver:t})=>{const o=H(),r=i=>{const s=document.getElementById(i);s&&s.scrollIntoView({behavior:"smooth",block:"start"})};return e.length===0?n.jsx("p",{className:"text-xs text-muted-foreground italic p-2",children:o.toc.empty}):n.jsx("div",{className:"toc-sidebar-progress",children:e.map(i=>n.jsx("div",{onClick:()=>r(i.id),className:y("toc-sidebar-progress-line",{"toc-sidebar-progress-line-active":t?i.isScrolledOver:i.isActive}),style:{"--toc-depth":i.level}},i.id))})},Ct=({items:e,scrollOver:t})=>{const o=H();return n.jsxs("div",{className:"flex flex-col gap-1 w-full text-sm text-neutral-600 dark:text-neutral-400",children:[n.jsx("div",{className:"px-3 py-2 text-xs font-semibold tracking-wider text-neutral-400 uppercase select-none",children:o.toc.title}),e.map(r=>n.jsx("button",{onClick:()=>{document.getElementById(r.id)?.scrollIntoView({behavior:"smooth"})},className:y(" flex items-center w-full px-3 py-1.5 text-left rounded-md transition-all duration-200 ease-in-out group relative hover:bg-accent",{"bg-accent text-muted-foreground!":!t&&r.isActive,"text-gray-500":t&&r.isScrolledOver}),style:{paddingLeft:`${((r.level||1)-1)*12+12}px`},children:n.jsx("span",{className:"truncate",children:r.textContent})},r.id||r.textContent))]})},ko=({items:e})=>n.jsx("div",{className:"toc-sidebar-nav",children:n.jsx("div",{className:"toc-sidebar-popover w-62.5 p-2 pr-px rounded-2xl border border-border shadow-xl bg-popover",children:n.jsx(ie,{className:"h-96 pr-4 **:space-y-px",children:e.map(t=>n.jsx("div",{onClick:()=>{document.getElementById(t.id)?.scrollIntoView({behavior:"smooth"})},className:y("toc-sidebar-item text-sm hover:bg-secondary hover:text-foreground text-muted-foreground rounded-md ",{"bg-secondary text-foreground":t.isActive}),style:{"--toc-depth":t.level},children:t.textContent},t.id))})})}),No=x.memo(jo),vt=({editor:e,variant:t="content",scrollOver:o=!1})=>{if(!e)return null;const[r,i]=x.useState(null),s=N.useEditorState({editor:e,selector:l=>l.editor.storage.tableOfContents?.content||[]});return x.useRef({}),n.jsx("aside",{className:y("toc-sidebar not-prose ",{"sticky top-20 self-start h-fit":t==="content",relative:t==="line"}),children:n.jsxs("div",{className:y("toc-sidebar-wrapper",{"w-60 p-2 h-full border-l flex flex-col":t==="content","fixed top-1/2 right-4 -translate-y-1/2 z-50":t==="line"}),children:[t==="line"&&n.jsxs("div",{className:"toc-sidebar-inner",children:[n.jsx(No,{items:s,scrollOver:o}),n.jsx(ko,{items:s})]}),t==="content"&&n.jsx(Ct,{items:s,scrollOver:o})]})})},Ao=e=>{const t=x.useRef(null);return x.useLayoutEffect(()=>{t.current=e},[e]),x.useCallback((...o)=>{if(t.current===null)throw new Error("Handler is not assigned");return t.current(...o)},[])};function Mo(e,t){return e/t}function So(e,t){return e<=0||t<=0?0:e/t}const Ze=20,To=600,Ke=400;function Lo({node:e,editor:t,updateAttributes:o,getPos:r}){const{src:i,alt:s,alignment:l,width:a,height:d}=e.attrs,[c,u]=x.useState(!1),p=x.useRef(null),h=x.useRef(null),f=x.useRef(null),b=Ao(v=>{if(!f.current||!h.current)return;v.preventDefault(),v.stopPropagation();const j=p.current?.parentElement?p.current.parentElement.offsetWidth:To,C=v.currentTarget.dataset.direction||"--",w=v.clientX,A=v.clientY,R=f.current.offsetWidth,T=f.current.offsetHeight;let k=R,E=T;const M=C.charAt(1)==="w"?-1:1,L=C.charAt(0)==="n"?-1:1,B=()=>{window.removeEventListener("mousemove",U,{capture:!0}),window.removeEventListener("mouseup",B,{capture:!0});const $=Mo(k,E);o({width:k,height:E,aspectRatio:$})},U=$=>{if(k=Math.max(R+M*($.clientX-w),Ze),E=Math.max(T+L*($.clientY-A),Ze),k>j&&(k=j),E>Ke&&(E=Ke),e.attrs.lockAspectRatio){const _=e.attrs.aspectRatio&&isFinite(e.attrs.aspectRatio)&&e.attrs.aspectRatio>0?e.attrs.aspectRatio:R/T;E=So(k,_)}if(h.current&&(h.current.style.width=`${k}px`,p.current?.setAttribute("data-width",String(k))),!$.buttons)return B()};window.addEventListener("mousemove",U,{capture:!0}),window.addEventListener("mouseup",B,{capture:!0})}),g=a?`${a}px`:"auto";return n.jsx(N.NodeViewWrapper,{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:"tiptap-image transition-all duration-200 select-none","data-align":l,"data-width":a||a,ref:p,children:n.jsx("div",{className:"tiptap-image-container",style:{width:g},ref:h,children:n.jsxs("div",{className:"tiptap-image-content relative",children:[n.jsx("img",{"data-drag-handle":!0,ref:f,contentEditable:!1,draggable:!1,className:"tiptap-image-img cursor-pointer",src:i,alt:s??"",onDragStart:v=>v.preventDefault(),style:{height:"auto",display:"block",userSelect:"none",WebkitUserDrag:"none"}}),c&&n.jsxs(n.Fragment,{children:[n.jsx("div",{onMouseDown:b,"data-direction":"-w",className:"tiptap-image-handle tiptap-image-handle-left"}),n.jsx("div",{onMouseDown:b,"data-direction":"-e",className:"tiptap-image-handle tiptap-image-handle-right"})]})]})})})}const Ro=an.extend({draggable:!0,addAttributes(){return{...this.parent?.(),alignment:{default:"center"},"data-width":{default:0},width:{default:0,parseHTML:e=>{const t=e.getAttribute("data-width")||e.style.width;return t?parseInt(t,10):0},renderHTML:e=>e["data-width"]}}},addNodeView(){return N.ReactNodeViewRenderer(Lo,{className:"not-prose min-h-10",attrs:{"data-placeholder":"Start writing..."}})}}),wt=x.createContext({}),Ho=({onOpenAttachment:e,children:t})=>{const o=x.useMemo(()=>({onOpenAttachment:e}),[e]);return n.jsx(wt.Provider,{value:o,children:t})},Eo=()=>x.useContext(wt),Io=(e,t)=>{const o=`${e??""} ${t??""}`.toLowerCase();return/pdf/.test(o)||/word|document|\.docx?$|\.rtf|\.odt/.test(o)?m.FileText:/sheet|excel|csv|\.xlsx?$|\.ods/.test(o)?m.FileSpreadsheet:/presentation|powerpoint|\.pptx?$|\.odp/.test(o)?m.Presentation:/zip|rar|7z|tar|gzip/.test(o)?m.FileArchive:m.File},Ge="shrink-0 rounded-md p-2 text-muted-foreground hover:bg-[var(--tt-menu-item-hover-bg)] hover:text-foreground",zo=e=>{const t=["B","KB","MB","GB"];let o=e,r=0;for(;o>=1024&&r<t.length-1;)o/=1024,r+=1;return`${o<10&&r>0?o.toFixed(1):Math.round(o)} ${t[r]}`};function Do({node:e,selected:t}){const o=H(),{onOpenAttachment:r}=Eo(),i=e.attrs,{src:s,name:l,size:a,mime:d}=i,c=Io(d,l),u=l??s??"";return n.jsx(N.NodeViewWrapper,{className:"not-prose my-3","data-type":"attachment","data-drag-handle":!0,children:n.jsxs("div",{contentEditable:!1,className:`flex items-center gap-3 rounded-lg border p-3 transition-colors ${t?"border-[var(--tt-menu-item-hover-bg)] bg-[var(--tt-menu-item-hover-bg)]":"border-border hover:bg-[var(--tt-menu-item-hover-bg)]"}`,children:[n.jsx(c,{className:"size-8 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate font-medium text-sm",children:u}),typeof a=="number"&&a>0?n.jsx("div",{className:"text-muted-foreground text-xs",children:zo(a)}):null]}),s?n.jsx("a",{href:s,download:l??void 0,target:"_blank",rel:"noreferrer",title:o.attachment.download,"aria-label":o.attachment.download,className:Ge,children:n.jsx(m.Download,{className:"size-4"})}):i.fileId&&r?n.jsx("button",{type:"button",onClick:()=>r(i),title:o.attachment.download,"aria-label":o.attachment.download,className:Ge,children:n.jsx(m.Download,{className:"size-4"})}):null]})})}const Po=Z.Node.create({name:"attachment",group:"block",atom:!0,draggable:!0,selectable:!0,addAttributes(){return{fileId:{default:null},src:{default:null},name:{default:null},size:{default:null,parseHTML:e=>{const t=e.getAttribute("data-size");return t?Number(t):null}},mime:{default:null}}},parseHTML(){return[{tag:'div[data-type="attachment"]'}]},renderHTML({HTMLAttributes:e}){const{size:t,...o}=e;return["div",Z.mergeAttributes({"data-type":"attachment"},o,t==null?{}:{"data-size":String(t)})]},addNodeView(){return N.ReactNodeViewRenderer(Do)},addCommands(){return{setAttachment:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),Bo=e=>typeof e=="number"&&e>=0;function Vo(e){const t=H(),o=x.useRef(null),[r,i]=x.useState(!1),s=e.extension.options,l=s.maxSize??25*1024*1024,a=async d=>{if(!s.upload){s.onError?.(new Error("[notion-editor] chưa cấu hình `uploadAttachment`."));return}if(d.size>l){s.onError?.(new Error(`[notion-editor] tệp vượt quá ${Math.round(l/1024/1024)}MB.`));return}i(!0);try{const c=await s.upload(d),u=typeof c=="string"?{src:c,fileId:null}:{src:c.src??null,fileId:c.fileId??null},p=e.getPos();if(!Bo(p))return;e.editor.chain().focus().deleteRange({from:p,to:p+1}).insertContentAt(p,{type:"attachment",attrs:{...u,name:d.name,size:d.size,mime:d.type||null}}).run(),s.onSuccess?.(u.src??u.fileId??"")}catch(c){s.onError?.(c instanceof Error?c:new Error(String(c)))}finally{i(!1)}};return n.jsx(N.NodeViewWrapper,{className:"not-prose my-3","data-type":"attachment-upload",children:n.jsxs("div",{contentEditable:!1,children:[n.jsxs("button",{type:"button",disabled:r,onClick:()=>o.current?.click(),className:"flex w-full items-center gap-3 rounded-lg border border-border border-dashed p-4 text-left text-muted-foreground text-sm hover:bg-[var(--tt-menu-item-hover-bg)] disabled:opacity-60",children:[n.jsx(m.Paperclip,{className:"size-5 shrink-0"}),n.jsx("span",{children:r?t.attachment.uploading:t.attachment.clickToUpload})]}),n.jsx("input",{ref:o,type:"file",accept:s.accept,className:"hidden",onChange:d=>{const c=d.target.files?.[0];d.target.value="",c&&a(c)}})]})})}const Oo=N.Node.create({name:"attachmentUpload",group:"block",draggable:!0,selectable:!0,atom:!0,addOptions(){return{accept:void 0,limit:1,maxSize:25*1024*1024,upload:void 0,onError:void 0,onSuccess:void 0,HTMLAttributes:{}}},addAttributes(){return{accept:{default:this.options.accept},limit:{default:this.options.limit},maxSize:{default:this.options.maxSize}}},parseHTML(){return[{tag:'div[data-type="attachment-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",N.mergeAttributes({"data-type":"attachment-upload"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Vo)}});function $o(e){const{state:t,view:o}=e,{doc:r,selection:i}=t,s=D.Selection.findFrom(i.$to,1,!0);if(s)return o.dispatch(t.tr.setSelection(s).scrollIntoView()),!0;const l=t.schema.nodes.paragraph;if(!l)return console.warn("No paragraph node type found in schema."),!1;const a=r.content.size,d=l.create();let c=t.tr.insert(a,d);const u=c.doc.resolve(a+1);return c=c.setSelection(D.TextSelection.near(u)).scrollIntoView(),o.dispatch(c),!0}function qo(e){return typeof e=="number"&&e>=0}const Fo=({maxSize:e,limit:t})=>{const o=H();return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"tiptap-image-upload-dropzone",children:[n.jsx(m.FileImage,{size:50,className:"tiptap-image-upload-dropzone-rect-primary"}),n.jsx("div",{className:"tiptap-image-upload-icon-container",children:n.jsx(m.CloudUploadIcon,{className:"tiptap-image-upload-icon"})})]}),n.jsxs("div",{className:"tiptap-image-upload-content",children:[n.jsxs("span",{className:"tiptap-image-upload-text",children:[n.jsx("em",{children:o.image.clickToUpload})," ",o.image.orDragAndDrop]}),n.jsx("span",{className:"tiptap-image-upload-subtext",children:o.image.limitHint(t,e/1024/1024)})]})]})},Uo=({onFile:e,children:t})=>{const[o,r]=x.useState(!1),[i,s]=x.useState(!1),l=u=>{u.preventDefault(),u.stopPropagation(),s(!0)},a=u=>{u.preventDefault(),u.stopPropagation(),u.currentTarget.contains(u.relatedTarget)||(s(!1),r(!1))},d=u=>{u.preventDefault(),u.stopPropagation(),r(!0)},c=u=>{u.preventDefault(),u.stopPropagation(),s(!1),r(!1);const p=Array.from(u.dataTransfer.files);p.length>0&&e(p)};return n.jsx("div",{className:`tiptap-image-upload-drag-area ${i?"drag-active":""} ${o?"drag-over":""}`,onDragEnter:l,onDragLeave:a,onDragOver:d,onDrop:c,children:t})},_o=({fileItem:e,onRemove:t})=>{const o=r=>{if(r===0)return"0 Bytes";const i=1024,s=["Bytes","KB","MB","GB"],l=Math.floor(Math.log(r)/Math.log(i));return`${parseFloat((r/Math.pow(i,l)).toFixed(2))} ${s[l]}`};return n.jsxs("div",{className:"tiptap-image-upload-preview",children:[e.status==="uploading"&&n.jsx("div",{className:"tiptap-image-upload-progress",style:{width:`${e.progress}%`}}),n.jsxs("div",{className:"tiptap-image-upload-preview-content",children:[n.jsxs("div",{className:"tiptap-image-upload-file-info",children:[n.jsx("div",{className:"tiptap-image-upload-file-icon",children:n.jsx(m.CloudUploadIcon,{})}),n.jsxs("div",{className:"tiptap-image-upload-details",children:[n.jsx("span",{className:"tiptap-image-upload-text",children:e.file.name}),n.jsx("span",{className:"tiptap-image-upload-subtext",children:o(e.file.size)})]})]}),n.jsxs("div",{className:"tiptap-image-upload-actions",children:[e.status==="uploading"&&n.jsxs("span",{className:"tiptap-image-upload-progress-text",children:[e.progress,"%"]}),n.jsx(z,{size:"icon",type:"button",variant:"ghost",onClick:r=>{r.stopPropagation(),t()},children:n.jsx(m.XIcon,{className:"tiptap-button-icon"})})]})]})]})};function Wo(e){const[t,o]=x.useState([]),r=async a=>{if(a.size>e.maxSize){const p=new Error(`File size exceeds maximum allowed (${e.maxSize/1024/1024}MB)`);return e.onError?.(p),null}const d=new AbortController,c=crypto.randomUUID(),u={id:c,file:a,progress:0,status:"uploading",abortController:d};o(p=>[...p,u]);try{if(!e.upload)throw new Error("[notion-editor] chưa cấu hình `uploadImage`, không có chỗ để tải ảnh lên");const p=await e.upload(a,h=>{o(f=>f.map(b=>b.id===c?{...b,progress:h.progress}:b))},d.signal);if(console.log(p),!p)throw new Error("Upload failed: No URL returned");return d.signal.aborted?null:(o(h=>h.map(f=>f.id===c?{...f,status:"success",url:p,progress:100}:f)),e.onSuccess?.(p),p)}catch(p){return d.signal.aborted||(o(h=>h.map(f=>f.id===c?{...f,status:"error",progress:0}:f)),e.onError?.(p instanceof Error?p:new Error("Upload failed"))),null}};return{fileItems:t,uploadFiles:async a=>{if(!a||a.length===0)return e.onError?.(new Error("No files to upload")),[];if(e.limit&&a.length>e.limit)return e.onError?.(new Error(`Maximum ${e.limit} file${e.limit===1?"":"s"} allowed`)),[];const d=a.map(u=>r(u));return(await Promise.all(d)).filter(u=>u!==null)},removeFileItem:a=>{o(d=>{const c=d.find(u=>u.id===a);return c?.abortController&&c.abortController.abort(),c?.url&&URL.revokeObjectURL(c.url),d.filter(u=>u.id!==a)})},clearAllFiles:()=>{t.forEach(a=>{a.abortController&&a.abortController.abort(),a.url&&URL.revokeObjectURL(a.url)}),o([])}}}const Zo=e=>{const t=H(),{accept:o,limit:r,maxSize:i}=e.node.attrs,s=x.useRef(null),l=e.extension,a={maxSize:i,limit:r,accept:o,upload:l.options.upload,onSuccess:l.options.onSuccess,onError:v=>{console.error("[notion-editor] tải ảnh thất bại:",v),l.options.onError?.(v)}},{fileItems:d,uploadFiles:c,removeFileItem:u,clearAllFiles:p}=Wo(a),h=async v=>{const j=await c(v);if(j.length>0){const C=e.getPos();if(qo(C)){const w=j.map((A,R)=>{const T=v[R]?.name.replace(/\.[^/.]+$/,"")||"unknown";return{type:l.options.type,attrs:{src:A,alt:T,title:T}}});e.editor.chain().focus().deleteRange({from:C,to:C+e.node.nodeSize}).insertContentAt(C,w[0]).run(),$o(e.editor)}}},f=v=>{const j=v.target.files;if(!j||j.length===0){l.options.onError?.(new Error("No file selected"));return}h(Array.from(j))},b=()=>{s.current&&d.length===0&&(s.current.value="",s.current.click())},g=d.length>0;return n.jsxs(N.NodeViewWrapper,{className:"tiptap-image-upload py-8",tabIndex:0,onClick:b,children:[!g&&n.jsx(Uo,{onFile:h,children:n.jsx(Fo,{maxSize:i,limit:r})}),g&&n.jsxs("div",{className:"tiptap-image-upload-previews",children:[d.length>1&&n.jsxs("div",{className:"tiptap-image-upload-header",children:[n.jsxs("span",{children:["Uploading ",d.length," files"]}),n.jsx(z,{type:"button",variant:"ghost",onClick:v=>{v.stopPropagation(),p()},children:t.image.clearAll})]}),d.map(v=>n.jsx(_o,{fileItem:v,onRemove:()=>u(v.id)},v.id))]}),n.jsx("input",{ref:s,name:"file",accept:o,type:"file",multiple:r>1,onChange:f,onClick:v=>v.stopPropagation()})]})},Ko=N.Node.create({name:"imageUpload",group:"block",draggable:!0,selectable:!0,atom:!0,addOptions(){return{type:"image",accept:"image/*",limit:1,maxSize:1048576,upload:void 0,onError:void 0,onSuccess:void 0,HTMLAttributes:{}}},addAttributes(){return{accept:{default:this.options.accept},limit:{default:this.options.limit},maxSize:{default:this.options.maxSize}}},parseHTML(){return[{tag:'div[data-type="image-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",N.mergeAttributes({"data-type":"image-upload"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Zo)},addCommands(){return{setImageUploadNode:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{const{selection:t}=e.state,{nodeAfter:o}=t.$from;if(o&&o.type.name==="imageUpload"&&e.isActive("imageUpload")){const r=e.view.nodeDOM(t.$from.pos);if(r&&r instanceof HTMLElement){const i=r.firstChild;if(i&&i instanceof HTMLElement)return i.click(),!0}}return!1}}}}),Go=re.Table.extend({renderHTML({node:e,HTMLAttributes:t}){const{colgroup:o,tableWidth:r,tableMinWidth:i}=re.createColGroup(e,this.options.cellMinWidth);return["div",{class:y("table-wrapper overflow-x-auto overflow-y-hidden p-4 -ml-4 relative")},"table",Z.mergeAttributes(this.options.HTMLAttributes,t,{style:r?`width: ${r}`:`min-width: ${i}`}),o,["table",0]]},addNodeView(){return({node:e,HTMLAttributes:t})=>{const o=document.createElement("div");o.setAttribute("data-content-type","table");const r=document.createElement("div");r.className=y("table-wrapper overflow-x-auto overflow-y-hidden p-4 -ml-4 relative");const i=document.createElement("div");i.className="table-container";const s=document.createElement("table");Object.entries(this.options.HTMLAttributes).forEach(([p,h])=>{s.setAttribute(p,h)}),Object.entries(t).forEach(([p,h])=>{s.setAttribute(p,h)}),s.style.setProperty(Tn,`${Ee}px`);let l=null;const a=p=>{const{colgroup:h,tableWidth:f,tableMinWidth:b}=re.createColGroup(p,this.options.cellMinWidth),g=de.DOMSerializer.renderSpec(document,h).dom;s.style.width=f??"",s.style.minWidth=f?"":b??"",l?s.replaceChild(g,l):s.prepend(g),l=g};a(e);const d=document.createElement("tbody");s.append(d),i.append(s);const c=document.createElement("div");c.className="table-controls";const u=document.createElement("div");return u.className="table-selection-container",r.append(i,c,u),o.append(r),{dom:o,contentDOM:d,update:p=>p.type!==e.type?!1:(a(p),!0),ignoreMutation:p=>!0}}}}),Xo=Z.Extension.create({name:"custom-table-kit",addExtensions(){return[Go.configure({HTMLAttributes:{class:y("border-collapse w-full not-prose")},lastColumnResizable:!1,allowTableNodeSelection:!0,resizable:!0,cellMinWidth:Ee}),re.TableHeader.extend({addAttributes(){return{...this.parent?.(),background:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.background?{style:`background-color: ${e.background}`}:{}},alignment:{default:"left",parseHTML:e=>e.style.textAlign||"left",renderHTML:e=>e.alignment?{style:`text-align: ${e.alignment}`}:{}},verticalAlign:{default:"top",parseHTML:e=>e.style.verticalAlign||"top",renderHTML:e=>({style:`vertical-align: ${e.verticalAlign}`})}}}}).configure({HTMLAttributes:{class:y("border border-border p-2 text-start font-semibold")}}),re.TableRow,re.TableCell.extend({addAttributes(){return{...this.parent?.(),background:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.background?{style:`background-color: ${e.background}`}:{}},alignment:{default:"left",parseHTML:e=>e.style.textAlign||"left",renderHTML:e=>e.alignment?{style:`text-align: ${e.alignment}`}:{}},verticalAlign:{default:"top",parseHTML:e=>e.style.verticalAlign||"top",renderHTML:e=>({style:`vertical-align: ${e.verticalAlign}`})}}}}).configure({HTMLAttributes:{class:"border border-border p-2"}})]}});function Jo({editor:e}){const t=N.useEditorState({editor:e,selector:o=>o.editor.storage.tableOfContents?.content??[]});return n.jsx(N.NodeViewWrapper,{className:"not-prose my-4 rounded-lg border border-border p-2","data-type":"table-of-contents",children:n.jsx("div",{contentEditable:!1,children:n.jsx(Ct,{items:t,scrollOver:!1})})})}const Yo=Z.Node.create({name:"tableOfContentsNode",group:"block",atom:!0,selectable:!0,draggable:!0,parseHTML(){return[{tag:'div[data-type="table-of-contents"]'}]},renderHTML({HTMLAttributes:e}){return["div",Z.mergeAttributes({"data-type":"table-of-contents"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Jo)}}),Qo=e=>e.type.startsWith("image/");function er({uploadImage:e,uploadAttachment:t}){const o=async(r,i,s)=>{const l=Qo(i),a=l?e:t;if(!a){if(!l){console.error("[notion-editor] chưa cấu hình `uploadAttachment`, bỏ qua tệp:",i.name);return}const d=new FileReader;d.onload=()=>{r.chain().insertContentAt(s,{type:"image",attrs:{src:d.result}}).focus().run()},d.readAsDataURL(i);return}try{const d=await a(i),c=typeof d=="string"?{src:d,fileId:null}:{src:d.src??null,fileId:d.fileId??null};r.chain().insertContentAt(s,l?{type:"image",attrs:{src:c.src}}:{type:"attachment",attrs:{...c,name:i.name,size:i.size,mime:i.type}}).focus().run()}catch(d){console.error("[notion-editor] chèn tệp thất bại:",d)}};return cn.configure({onDrop:(r,i,s)=>{for(const l of i)o(r,l,s)},onPaste:(r,i,s)=>{if(s)return!1;for(const l of i)o(r,l,r.state.selection.anchor)}})}const tr=Z.Extension.create({name:"globalBlockBackground",addGlobalAttributes(){return[{types:["paragraph","heading","bulletList","orderedList","listItem","table","tableCell","tableRow","blockquote"],attributes:{universalBgColor:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.universalBgColor?{style:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),x=require("react"),N=require("@tiptap/react"),Et=require("@tiptap/extension-drag-handle-react"),m=require("lucide-react"),je=require("class-variance-authority"),S=require("radix-ui"),It=require("clsx"),zt=require("tailwind-merge"),de=require("@tiptap/pm/model"),D=require("@tiptap/pm/state"),I=require("@floating-ui/dom"),P=require("@tiptap/pm/tables"),Xe=require("@tiptap/react/menus"),ke=require("react-dom"),Dt=require("@tiptap/extension-blockquote"),Pt=require("@tiptap/extension-bold"),Bt=require("@tiptap/extension-code"),Vt=require("@tiptap/extension-code-block-lowlight"),Ot=require("@tiptap/extension-document"),ze=require("@tiptap/extension-emoji"),$t=require("@tiptap/extension-hard-break"),qt=require("@tiptap/extension-heading"),Ft=require("@tiptap/extension-highlight"),Ut=require("@tiptap/extension-horizontal-rule"),_t=require("@tiptap/extension-italic"),Wt=require("@tiptap/extension-link"),Zt=require("@tiptap/extension-list"),Kt=require("@tiptap/extension-mathematics"),Gt=require("@tiptap/extension-mention"),Xt=require("@tiptap/extension-paragraph"),Jt=require("@tiptap/extension-placeholder"),Yt=require("@tiptap/extension-strike"),Qt=require("@tiptap/extension-subscript"),en=require("@tiptap/extension-superscript"),tn=require("@tiptap/extension-table-of-contents"),nn=require("@tiptap/extension-text"),on=require("@tiptap/extension-text-align"),ye=require("@tiptap/extension-text-style"),rn=require("@tiptap/extension-underline"),sn=require("@tiptap/extension-unique-id"),me=require("@tiptap/extensions"),De=require("lowlight"),ln=require("uuid"),an=require("@tiptap/extension-image"),Z=require("@tiptap/core"),re=require("@tiptap/extension-table"),cn=require("@tiptap/extension-file-handler"),dn=require("@tanstack/react-virtual"),ue=require("cmdk"),un=require("@tiptap/suggestion");function y(...e){return zt.twMerge(It.clsx(e))}const pn=async e=>{if(!e||!e.state)return console.warn("Tiptap copy operation failed: Editor instance is uninitialized."),!1;const{selection:t,doc:o}=e.state;let r=null;if(t instanceof D.NodeSelection?r=t.node:t instanceof D.TextSelection&&(r=t.$from.parent),!r||r.type.name==="doc")return console.warn("Tiptap copy operation failed: No copyable block node selected."),!1;try{const i=e.schema,l=de.DOMSerializer.fromSchema(i).serializeNode(r),a=document.createElement("div");a.appendChild(l);const d=a.innerHTML,c=r.textContent||"",u=new ClipboardItem({"text/html":new Blob([d],{type:"text/html"}),"text/plain":new Blob([c],{type:"text/plain"})});return await navigator.clipboard.write([u]),!0}catch(i){return console.error("Fatal: Failed to write selected block node to clipboard.",i),!1}},mn=e=>{if(!e||!e.state)return console.warn("Tiptap delete operation failed: Editor instance is uninitialized."),!1;const{selection:t}=e.state;let o=t.from,r=t.to;if(t instanceof D.NodeSelection)o=t.from,r=t.to;else if(t instanceof D.TextSelection){const i=t.$from.depth;if(i===0)return!1;o=t.$from.before(i),r=t.$from.after(i)}return e.chain().deleteRange({from:o,to:r}).focus().run()},fn=e=>{if(!e||!e.state)return console.warn("Tiptap delete operation failed: Editor instance is uninitialized."),!1;const{selection:t}=e.state;let o=t instanceof D.NodeSelection?t.node:null,r=t.from;if(o||(o=t.$from.parent,r=t.$from.before(t.$from.depth)),o){const i=r+o.nodeSize;e.chain().insertContentAt(i,o.toJSON()).focus().setTextSelection(i+1).run()}},hn=(e,t)=>{if(!e||!e.state)return!1;const{selection:o}=e.state;let r=null,i=null;if(o instanceof D.NodeSelection)r=o.node.type.name,i=o.from;else if(o instanceof D.TextSelection){const s=o.$from.depth;s>0&&(r=o.$from.parent.type.name,i=o.$from.before(s))}return r&&i!==null&&r!=="doc"?e.chain().focus().updateAttributes(r,{universalBgColor:t}).run():!1};function gn(e){if(!e)return;const{from:t}=e.state.selection,{left:o,right:r,top:i,bottom:s}=e.view.coordsAtPos(t);return new DOMRect(o,i,r-o,s-i)}function xn({editor:e,clientRect:t,element:o,placement:r="bottom-start",strategy:i="absolute",middleware:s=[I.shift(),I.flip()],offsetValue:l}){if(!o)return;const a=t||(e?gn(e):null);if(!a)return;const d={getBoundingClientRect:()=>a},c=l?[I.offset(l),...s]:s;return I.computePosition(d,o,{placement:r,strategy:i,middleware:c}).then(({x:u,y:p,strategy:h})=>{Object.assign(o.style,{width:"max-content",position:h,left:`${u}px`,top:`${p}px`})})}const bn=je.cva("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/90",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function z({className:e,variant:t="default",size:o="default",asChild:r=!1,...i}){const s=r?S.Slot.Root:"button";return n.jsx(s,{"data-slot":"button","data-variant":t,"data-size":o,className:y(bn({variant:t,size:o,className:e})),...i})}function Cn({delayDuration:e=0,...t}){return n.jsx(S.Tooltip.Provider,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function vn({...e}){return n.jsx(S.Tooltip.Root,{"data-slot":"tooltip",...e})}function wn({...e}){return n.jsx(S.Tooltip.Trigger,{"data-slot":"tooltip-trigger",...e})}function yn({className:e,sideOffset:t=0,children:o,...r}){return n.jsx(S.Tooltip.Portal,{children:n.jsxs(S.Tooltip.Content,{"data-slot":"tooltip-content",sideOffset:t,className:y("z-(--notion-editor-z-tooltip) inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 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 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r,children:[o,n.jsx(S.Tooltip.Arrow,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}const K=({children:e,content:t,className:o,showTooltip:r=!0})=>n.jsxs(vn,{children:[n.jsx(wn,{asChild:!0,children:e}),r&&t&&n.jsx(yn,{className:o,children:n.jsx("p",{children:t})})]});function Ne({...e}){return n.jsx(S.DropdownMenu.Root,{"data-slot":"dropdown-menu",...e})}function Ae({...e}){return n.jsx(S.DropdownMenu.Portal,{"data-slot":"dropdown-menu-portal",...e})}function Me({...e}){return n.jsx(S.DropdownMenu.Trigger,{"data-slot":"dropdown-menu-trigger",...e})}function Se({className:e,align:t="start",sideOffset:o=4,...r}){return n.jsx(S.DropdownMenu.Portal,{children:n.jsx(S.DropdownMenu.Content,{"data-slot":"dropdown-menu-content",sideOffset:o,align:t,className:y("z-(--notion-editor-z-menu) max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 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 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r})})}function X({...e}){return n.jsx(S.DropdownMenu.Group,{"data-slot":"dropdown-menu-group",...e})}function F({className:e,inset:t,variant:o="default",...r}){return n.jsx(S.DropdownMenu.Item,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":o,className:y("group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",e),...r})}function Je({className:e,inset:t,...o}){return n.jsx(S.DropdownMenu.Label,{"data-slot":"dropdown-menu-label","data-inset":t,className:y("px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",e),...o})}function W({className:e,...t}){return n.jsx(S.DropdownMenu.Separator,{"data-slot":"dropdown-menu-separator",className:y("-mx-1 my-1 h-px bg-border",e),...t})}function ae({className:e,...t}){return n.jsx("span",{"data-slot":"dropdown-menu-shortcut",className:y("ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",e),...t})}function Te({...e}){return n.jsx(S.DropdownMenu.Sub,{"data-slot":"dropdown-menu-sub",...e})}function Le({className:e,inset:t,children:o,...r}){return n.jsxs(S.DropdownMenu.SubTrigger,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:y("flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r,children:[o,n.jsx(m.ChevronRightIcon,{className:"ml-auto"})]})}function Re({className:e,...t}){return n.jsx(S.DropdownMenu.SubContent,{"data-slot":"dropdown-menu-sub-content",className:y("z-(--notion-editor-z-menu) min-w-24 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...t})}function ie({className:e,children:t,...o}){return n.jsxs(S.ScrollArea.Root,{"data-slot":"scroll-area",className:y("relative",e),...o,children:[n.jsx(S.ScrollArea.Viewport,{"data-slot":"scroll-area-viewport",className:"size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1",children:t}),n.jsx(jn,{}),n.jsx(S.ScrollArea.Corner,{})]})}function jn({className:e,orientation:t="vertical",...o}){return n.jsx(S.ScrollArea.ScrollAreaScrollbar,{"data-slot":"scroll-area-scrollbar","data-orientation":t,orientation:t,className:y("flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent",e),...o,children:n.jsx(S.ScrollArea.ScrollAreaThumb,{"data-slot":"scroll-area-thumb",className:"relative flex-1 rounded-full bg-border"})})}const kn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 2C20.6569 2 22 3.34315 22 5V19C22 20.6569 20.6569 22 19 22H15C13.3431 22 12 20.6569 12 19V5C12 3.34315 13.3431 2 15 2H19ZM14 19C14 19.5523 14.4477 20 15 20H19C19.5523 20 20 19.5523 20 19V13H14V19ZM15 4C14.4477 4 14 4.44772 14 5V11H20V5C20 4.44772 19.5523 4 19 4H15Z",fill:"currentColor"}),n.jsx("path",{d:"M6 8C6.55228 8 7 8.44772 7 9V11H9C9.55228 11 10 11.4477 10 12C10 12.5523 9.55228 13 9 13H7V15C7 15.5523 6.55228 16 6 16C5.44772 16 5 15.5523 5 15V13H3C2.44772 13 2 12.5523 2 12C2 11.4477 2.44772 11 3 11H5V9C5 8.44772 5.44772 8 6 8Z",fill:"currentColor"})]}),Nn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 2C10.6569 2 12 3.34315 12 5V19C12 20.6569 10.6569 22 9 22H5C3.34315 22 2 20.6569 2 19V5C2 3.34315 3.34315 2 5 2H9ZM4 19C4 19.5523 4.44772 20 5 20H9C9.55228 20 10 19.5523 10 19V13H4V19ZM5 4C4.44772 4 4 4.44772 4 5V11H10V5C10 4.44772 9.55228 4 9 4H5Z",fill:"currentColor"}),n.jsx("path",{d:"M18 8C18.5523 8 19 8.44772 19 9V11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H19V15C19 15.5523 18.5523 16 18 16C17.4477 16 17 15.5523 17 15V13H15C14.4477 13 14 12.5523 14 12C14 11.4477 14.4477 11 15 11H17V9C17 8.44772 17.4477 8 18 8Z",fill:"currentColor"})]}),An=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 12C20.6569 12 22 13.3431 22 15V19C22 20.6569 20.6569 22 19 22H5C3.34315 22 2 20.6569 2 19V15C2 13.3431 3.34315 12 5 12H19ZM5 14C4.44772 14 4 14.4477 4 15V19C4 19.5523 4.44772 20 5 20H11V14H5ZM13 20H19C19.5523 20 20 19.5523 20 19V15C20 14.4477 19.5523 14 19 14H13V20Z",fill:"currentColor"}),n.jsx("path",{d:"M12 2C12.5523 2 13 2.44772 13 3V5H15C15.5523 5 16 5.44772 16 6C16 6.55228 15.5523 7 15 7H13V9C13 9.55228 12.5523 10 12 10C11.4477 10 11 9.55228 11 9V7H9C8.44772 7 8 6.55228 8 6C8 5.44772 8.44772 5 9 5H11V3C11 2.44772 11.4477 2 12 2Z",fill:"currentColor"})]}),Mn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12 14C12.5523 14 13 14.4477 13 15V17H15C15.5523 17 16 17.4477 16 18C16 18.5523 15.5523 19 15 19H13V21C13 21.5523 12.5523 22 12 22C11.4477 22 11 21.5523 11 21V19H9C8.44772 19 8 18.5523 8 18C8 17.4477 8.44772 17 9 17H11V15C11 14.4477 11.4477 14 12 14Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M19 2C20.6569 2 22 3.34315 22 5V9C22 10.6569 20.6569 12 19 12H5C3.34315 12 2 10.6569 2 9V5C2 3.34315 3.34315 2 5 2H19ZM5 4C4.44772 4 4 4.44772 4 5V9C4 9.55228 4.44772 10 5 10H11V4H5ZM13 10H19C19.5523 10 20 9.55228 20 9V5C20 4.44772 19.5523 4 19 4H13V10Z",fill:"currentColor"})]}),Pe=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{d:"M10 16C10.5177 16 10.9438 16.3933 10.9951 16.8975L11 17V19C11 20.6569 9.65685 22 8 22H4C2.34315 22 1 20.6569 1 19V17C1 16.4477 1.44772 16 2 16C2.55228 16 3 16.4477 3 17V19C3 19.5523 3.44772 20 4 20H8C8.55228 20 9 19.5523 9 19V17L9.00488 16.8975C9.05621 16.3933 9.48232 16 10 16Z",fill:"currentColor"}),n.jsx("path",{d:"M22 16C22.5177 16 22.9438 16.3933 22.9951 16.8975L23 17V19C23 20.6569 21.6569 22 20 22H16C14.3431 22 13 20.6569 13 19V17C13 16.4477 13.4477 16 14 16C14.5523 16 15 16.4477 15 17V19C15 19.5523 15.4477 20 16 20H20C20.5523 20 21 19.5523 21 19V17L21.0049 16.8975C21.0562 16.3933 21.4823 16 22 16Z",fill:"currentColor"}),n.jsx("path",{d:"M5.29297 8.29297C5.68349 7.90244 6.31651 7.90244 6.70703 8.29297L9.70703 11.293L9.77539 11.3691C10.0957 11.7619 10.0731 12.3409 9.70703 12.707L6.70703 15.707C6.31651 16.0975 5.68349 16.0975 5.29297 15.707C4.90245 15.3165 4.90245 14.6835 5.29297 14.293L6.58594 13H3C2.44772 13 2 12.5523 2 12C2 11.4477 2.44772 11 3 11H6.58594L5.29297 9.70703C4.90245 9.31651 4.90245 8.68349 5.29297 8.29297Z",fill:"currentColor"}),n.jsx("path",{d:"M17.293 8.29297C17.6835 7.90245 18.3165 7.90246 18.707 8.29297C19.0976 8.68349 19.0976 9.31651 18.707 9.70703L17.4141 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H17.4141L18.707 14.293C19.0976 14.6835 19.0976 15.3165 18.707 15.707C18.3165 16.0976 17.6835 16.0976 17.293 15.707L14.293 12.707L14.2246 12.6309C13.9043 12.2381 13.9269 11.6591 14.293 11.293L17.293 8.29297Z",fill:"currentColor"}),n.jsx("path",{d:"M8 2C9.65685 2 11 3.34315 11 5V7C11 7.55228 10.5523 8 10 8C9.44771 8 9 7.55228 9 7V5C9 4.44772 8.55228 4 8 4H4C3.44772 4 3 4.44772 3 5V7C3 7.55228 2.55228 8 2 8C1.44772 8 1 7.55228 1 7V5C1 3.34315 2.34315 2 4 2H8Z",fill:"currentColor"}),n.jsx("path",{d:"M20 2C21.6569 2 23 3.34315 23 5V7C23 7.55228 22.5523 8 22 8C21.4477 8 21 7.55228 21 7V5C21 4.44772 20.5523 4 20 4H16C15.4477 4 15 4.44772 15 5V7C15 7.55228 14.5523 8 14 8C13.4477 8 13 7.55228 13 7V5C13 3.34315 14.3431 2 16 2H20Z",fill:"currentColor"})]}),q=({icon:e,label:t,onClick:o,variant:r="default",disabled:i=!1,className:s})=>n.jsxs(F,{className:y(pe,s,{"text-destructive hover:bg-destructive/10 focus:bg-destructive/10 focus:text-destructive":r==="destructive","text-muted-foreground hover:bg-accent hover:text-accent-foreground":r==="default"}),onClick:o,disabled:i,children:[n.jsx(e,{className:"size-4 shrink-0"}),n.jsx("span",{children:t})]}),He=e=>n.jsx("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12.8944 5.55279C12.725 5.214 12.3787 5 12 5C11.6212 5 11.2749 5.214 11.1055 5.55279L5.10555 17.5528C4.85856 18.0468 5.05878 18.6474 5.55276 18.8944C6.04674 19.1414 6.64741 18.9412 6.8944 18.4472L8.64957 14.9369C8.75862 14.9777 8.87671 15 9 15H15C15.1233 15 15.2413 14.9777 15.3504 14.9369L17.1055 18.4472C17.3525 18.9412 17.9532 19.1414 18.4472 18.8944C18.9412 18.6474 19.1414 18.0468 18.8944 17.5528L12.8944 5.55279ZM14.3819 13L12 8.23607L9.61801 13H14.3819Z",fill:"currentColor"})}),Sn=e=>n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...e,children:[n.jsx("path",{d:"M3 16C3.55228 16 4 16.4477 4 17V19L4.00488 19.0986C4.02757 19.3276 4.12883 19.5429 4.29297 19.707C4.48051 19.8946 4.73478 20 5 20H7C7.55228 20 8 20.4477 8 21C8 21.5523 7.55228 22 7 22H5C4.20435 22 3.44151 21.6837 2.87891 21.1211C2.3163 20.5585 2 19.7957 2 19V17C2 16.4477 2.44772 16 3 16Z",fill:"currentColor"}),n.jsx("path",{d:"M21 16C21.5523 16 22 16.4477 22 17V19C22 19.7957 21.6837 20.5585 21.1211 21.1211C20.5585 21.6837 19.7957 22 19 22H17C16.4477 22 16 21.5523 16 21C16 20.4477 16.4477 20 17 20H19C19.2652 20 19.5195 19.8946 19.707 19.707C19.8946 19.5195 20 19.2652 20 19V17C20 16.4477 20.4477 16 21 16Z",fill:"currentColor"}),n.jsx("path",{d:"M7 16C7.55228 16 8 16.4477 8 17C8 17.5523 7.55228 18 7 18C6.44772 18 6 17.5523 6 17C6 16.4477 6.44772 16 7 16Z",fill:"currentColor"}),n.jsx("path",{d:"M12 16C12.5523 16 13 16.4477 13 17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17C11 16.4477 11.4477 16 12 16Z",fill:"currentColor"}),n.jsx("path",{d:"M17 16C17.5523 16 18 16.4477 18 17C18 17.5523 17.5523 18 17 18C16.4477 18 16 17.5523 16 17C16 16.4477 16.4477 16 17 16Z",fill:"currentColor"}),n.jsx("path",{d:"M7 11C7.55228 11 8 11.4477 8 12C8 12.5523 7.55228 13 7 13C6.44772 13 6 12.5523 6 12C6 11.4477 6.44772 11 7 11Z",fill:"currentColor"}),n.jsx("path",{d:"M12 11C12.5523 11 13 11.4477 13 12C13 12.5523 12.5523 13 12 13C11.4477 13 11 12.5523 11 12C11 11.4477 11.4477 11 12 11Z",fill:"currentColor"}),n.jsx("path",{d:"M17 11C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13C16.4477 13 16 12.5523 16 12C16 11.4477 16.4477 11 17 11Z",fill:"currentColor"}),n.jsx("path",{d:"M7 2C7.55228 2 8 2.44772 8 3C8 3.55228 7.55228 4 7 4H5C4.73478 4 4.4805 4.10543 4.29297 4.29297C4.10543 4.4805 4 4.73478 4 5V7C4 7.55228 3.55228 8 3 8C2.44772 8 2 7.55228 2 7V5C2 4.20435 2.3163 3.44152 2.87891 2.87891C3.44152 2.3163 4.20435 2 5 2H7Z",fill:"currentColor"}),n.jsx("path",{d:"M7 6C7.55228 6 8 6.44772 8 7C8 7.55228 7.55228 8 7 8C6.44772 8 6 7.55228 6 7C6 6.44772 6.44772 6 7 6Z",fill:"currentColor"}),n.jsx("path",{d:"M12 6C12.5523 6 13 6.44772 13 7C13 7.55228 12.5523 8 12 8C11.4477 8 11 7.55228 11 7C11 6.44772 11.4477 6 12 6Z",fill:"currentColor"}),n.jsx("path",{d:"M17 6C17.5523 6 18 6.44772 18 7C18 7.55228 17.5523 8 17 8C16.4477 8 16 7.55228 16 7C16 6.44772 16.4477 6 17 6Z",fill:"currentColor"}),n.jsx("path",{d:"M19 2C19.7957 2 20.5585 2.3163 21.1211 2.87891C21.6837 3.44151 22 4.20435 22 5V7C22 7.55228 21.5523 8 21 8C20.4477 8 20 7.55228 20 7V5C20 4.73478 19.8946 4.48051 19.707 4.29297C19.5429 4.12883 19.3276 4.02757 19.0986 4.00488L19 4H17C16.4477 4 16 3.55228 16 3C16 2.44772 16.4477 2 17 2H19Z",fill:"currentColor"})]}),Ee=152,Tn="--default-cell-min-width",ce="table-handle-reposition",se="data-dragging",le=e=>{const t=e.selection;let o=null;if(t.anchorCell)o=t.anchorCell.pos;else{const c=t.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){o=c.before(u);break}}}if(o===null)return null;const r=e.doc.resolve(o);let i=null,s=-1;for(let c=r.depth;c>0;c--)if(r.node(c).type.name==="table"){i=r.node(c),s=r.before(c);break}if(!i||s===-1)return null;const l=P.TableMap.get(i),a=o-s-1,d=l.findCell(a);return{tableNode:i,tablePos:s,map:l,cellPos:o,cellRect:d}};function Ln(e,t,o=!0){const{state:r,view:i}=e,{tr:s,schema:l}=r,a=r.doc.nodeAt(t);if(!a||a.type.name!=="table")return!1;const d=a.firstChild;if(!d)return!1;const c=[];for(let h=0;h<d.childCount;h++){const f=l.nodes.tableCell.createAndFill();f&&c.push(f)}const u=l.nodes.tableRow.create(null,de.Fragment.from(c)),p=t+a.nodeSize-1;return s.insert(p,u),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Rn(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table"||l.childCount<=1)return!1;const a=l.lastChild;if(!a)return!1;let d=!0;if(a.forEach(u=>{u.textContent.trim()!==""&&(d=!1)}),!d)return!1;const c=t+l.nodeSize-a.nodeSize-1;return s.delete(c,c+a.nodeSize),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Hn(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table")return!1;const a=P.TableMap.get(l);return P.addColumn(s,Ye(l,t,a),a.width),In(l)&&zn(s,t,a.width,Ee),s.setMeta("addToHistory",o),i.dispatch(s),!0}function En(e,t,o=!0){const{state:r,view:i}=e,{tr:s}=r,l=r.doc.nodeAt(t);if(!l||l.type.name!=="table")return!1;const a=P.TableMap.get(l);if(a.width<=1)return!1;const d=a.width-1;for(let c=0;c<a.height;c++){const u=l.nodeAt(a.map[c*a.width+d]);if(u&&u.textContent.trim()!=="")return!1}return P.removeColumn(s,Ye(l,t,a),d),s.setMeta("addToHistory",o),i.dispatch(s),!0}function Ye(e,t,o){return{map:o,table:e,tableStart:t+1,top:0,left:0,bottom:o.height,right:o.width}}function In(e){const t=e.firstChild;if(!t)return!1;for(let o=0;o<t.childCount;o++){const r=t.child(o).attrs.colwidth;if(!r||r.some(i=>!i))return!1}return!0}function zn(e,t,o,r){const i=e.doc.nodeAt(t);if(!i)return;const s=P.TableMap.get(i);if(!(o>=s.width))for(let l=0;l<s.height;l++){const a=t+1+s.map[l*s.width+o],d=e.doc.nodeAt(a);d&&e.setNodeMarkup(a,void 0,{...d.attrs,colwidth:[r]})}}const Be=(e,t)=>e.chain().focus().command(({state:o,dispatch:r})=>{const i=le(o);if(!i)return!1;const s=i.cellRect.left,l=t==="left"?s-1:s+1;return l>=0&&l<i.map.width?r?P.moveTableColumn({from:s,to:l})(o,r):!0:!1}).run(),Ve=(e,t)=>e.chain().focus().command(({state:o,dispatch:r})=>{const i=le(o);if(!i)return!1;const s=i.cellRect.top,l=t==="up"?s-1:s+1;return l>=0&&l<i.map.height?r?P.moveTableRow({from:s,to:l})(o,r):!0:!1}).run(),Dn=e=>e.chain().focus().command(({state:t,dispatch:o})=>{const r=le(t);if(!r||!o)return!1;const{tableNode:i,tablePos:s,cellRect:l}=r,a=l.top,d=t.tr,c=i.child(a),u=c.copy(de.Fragment.fromJSON(t.schema,c.content.toJSON()));let p=s+1;for(let h=0;h<=a;h++)p+=i.child(h).nodeSize;return d.insert(p,u),o(d),!0}).run(),Pn=e=>e.chain().focus().command(({state:t,dispatch:o})=>{const r=le(t);if(!r||!o)return!1;const{tableNode:i,tablePos:s,map:l,cellRect:a}=r,d=a.left,c=t.tr;let u=0;for(let p=0;p<l.height;p++){const h=p*l.width+d,f=l.map[h],b=s+1+f,g=t.doc.nodeAt(b);if(!g)continue;const v=g.copy(de.Fragment.fromJSON(t.schema,g.content.toJSON())),j=b+g.nodeSize+u;c.insert(j,v),u+=v.nodeSize}return o(c),!0}).run(),Oe=(e,t)=>{const{backgroundColor:o,textColor:r}=t;return e.chain().focus().command(({state:i,tr:s,dispatch:l})=>{const a=i.selection,d=[];if(a instanceof P.CellSelection||a.forEachCell)a.forEachCell((c,u)=>{d.push(u)});else{const c=a.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){d.push(c.before(u));break}}}return d.length===0?!1:(l&&(d.forEach(c=>{const u=s.doc.nodeAt(c);if(u){if(o!==void 0){const p=u.attrs;s.setNodeMarkup(c,void 0,{...p,background:o==="transparent"?null:o})}if(r!==void 0){const p=c+1,h=c+u.nodeSize-1,f=i.schema.marks.textStyle.create({color:r});s.removeMark(p,h,i.schema.marks.textStyle),s.addMark(p,h,f)}}}),l(s)),!0)}).run()},ne=(e,t)=>{const{horizontal:o,vertical:r}=t;return e.chain().focus().command(({state:i,tr:s,dispatch:l})=>{const a=i.selection,d=[];if(a instanceof P.CellSelection||a.forEachCell)a.forEachCell((c,u)=>{d.push(u)});else{const c=a.$anchor;for(let u=c.depth;u>0;u--){const p=c.node(u).type.name;if(p==="tableCell"||p==="tableHeader"){d.push(c.before(u));break}}}return d.length===0?!1:(l&&(d.forEach(c=>{const u=s.doc.nodeAt(c);if(!u)return;const p={...u.attrs};o&&(p.alignment=o),r&&(p.verticalAlignment=r),s.setNodeMarkup(c,void 0,p)}),l(s)),!0)}).run()},Bn=e=>{const t={isInsideTable:!1,horizontal:"left",vertical:"top"};if(!e)return t;const o=le(e.state);if(!o)return t;const{tableNode:r,map:i,cellPos:s}=o,l=e.state.doc.nodeAt(s);return l?{isInsideTable:!0,horizontal:l.attrs.alignment||"left",vertical:l.attrs.verticalAlignment||"top"}:t},Qe={common:{close:"Đóng",delete:"Xoá",color:"Màu",recentlyUsed:"Dùng gần đây",noResults:"Không tìm thấy kết quả",moreOptions:"Tuỳ chọn khác"},align:{left:"Căn trái",center:"Căn giữa",right:"Căn phải",justify:"Căn đều",top:"Căn trên",middle:"Căn giữa theo chiều dọc",bottom:"Căn dưới"},marks:{bold:"In đậm",italic:"In nghiêng",underline:"Gạch chân",strike:"Gạch ngang",code:"Mã",link:"Liên kết"},placeholder:{emptyDocument:"Nhập nội dung, hoặc gõ '/' để mở danh sách lệnh…",heading:e=>`Tiêu đề ${e}`},slash:{filterTag:"Bộ lọc",filterHint:"Bộ lọc…",groups:{style:"Định dạng",insert:"Chèn",upload:"Tải lên"}},blocks:{text:{title:"Văn bản",description:"Bắt đầu viết với văn bản thường."},heading1:{title:"Tiêu đề 1",description:"Tiêu đề lớn."},heading2:{title:"Tiêu đề 2",description:"Tiêu đề vừa."},heading3:{title:"Tiêu đề 3",description:"Tiêu đề nhỏ."},bulletList:{title:"Danh sách gạch đầu dòng",description:"Danh sách không đánh số."},orderedList:{title:"Danh sách đánh số",description:"Danh sách có đánh số thứ tự."},taskList:{title:"Danh sách công việc",description:"Danh sách có ô đánh dấu hoàn thành."},blockquote:{title:"Trích dẫn",description:"Chèn một khối trích dẫn."},codeBlock:{title:"Khối mã",description:"Chèn một khối mã nguồn."},hardBreak:{title:"Ngắt dòng",description:"Xuống dòng trong cùng một đoạn."},clearLine:{title:"Xoá dòng",description:"Xoá sạch nội dung dòng hiện tại."},separator:{title:"Đường kẻ ngang",description:"Chèn một đường phân cách."},emoji:{title:"Emoji",description:"Chèn biểu tượng cảm xúc."},mention:{title:"Nhắc đến",description:"Nhắc đến một người."},table:{title:"Bảng",description:"Chèn một bảng."},tableOfContents:{title:"Mục lục",description:"Chèn mục lục tự cập nhật theo các tiêu đề."},image:{title:"Hình ảnh",description:"Chèn vùng tải ảnh lên."},attachment:{title:"Tệp đính kèm",description:"Tải lên Word, PDF, bảng tính…"}},bubble:{turnInto:"Chuyển thành",linkPlaceholder:"Dán liên kết…",improve:"Cải thiện",pasteLink:"Dán liên kết…",textColor:"Màu chữ",backgroundColor:"Màu nền",increaseIndent:"Tăng thụt lề",decreaseIndent:"Giảm thụt lề"},drag:{handleHint:"Nhấn để mở tuỳ chọn, giữ để kéo",resetFormatting:"Xoá định dạng",duplicate:"Nhân đôi",copyToClipboard:"Sao chép",copyAnchorLink:"Sao chép liên kết neo",askAi:"Hỏi AI",insertBlock:"Chèn khối"},table:{alignment:"Căn chỉnh",alignLeft:"Căn trái",alignCenter:"Căn giữa",alignRight:"Căn phải",alignJustify:"Căn đều",alignTop:"Căn trên",alignMiddle:"Căn giữa theo chiều dọc",alignBottom:"Căn dưới",mergeCells:"Gộp ô",splitCell:"Tách ô",insertRowBefore:"Chèn hàng phía trên",insertRowAfter:"Chèn hàng phía dưới",insertColumnBefore:"Chèn cột bên trái",insertColumnAfter:"Chèn cột bên phải",deleteRow:"Xoá hàng",deleteColumn:"Xoá cột",duplicateRow:"Nhân đôi hàng",duplicateColumn:"Nhân đôi cột",clearRowContents:"Xoá nội dung hàng",clearColumnContents:"Xoá nội dung cột",moveRowUp:"Chuyển hàng lên",moveRowDown:"Chuyển hàng xuống",moveColumnLeft:"Chuyển cột sang trái",moveColumnRight:"Chuyển cột sang phải",deleteTable:"Xoá bảng"},image:{clickToUpload:"Nhấn để tải ảnh lên",delete:"Xoá ảnh",orDragAndDrop:"hoặc kéo thả vào đây",limitHint:(e,t)=>`Tối đa ${e} tệp, mỗi tệp ${t}MB.`,clearAll:"Xoá tất cả",caption:"Chú thích",download:"Tải ảnh về",replace:"Thay ảnh"},emojiPicker:{empty:"Không tìm thấy emoji",loading:"Đang tải…"},attachment:{clickToUpload:"Nhấn để chọn tệp (Word, PDF, bảng tính…)",uploading:"Đang tải tệp lên…",download:"Tải tệp về"},toc:{title:"Mục lục",empty:"Chưa có tiêu đề nào"}},et={common:{close:"Close",delete:"Delete",color:"Color",recentlyUsed:"Recently used",noResults:"No results found",moreOptions:"More options"},align:{left:"Align left",center:"Align center",right:"Align right",justify:"Justify",top:"Align top",middle:"Align middle",bottom:"Align bottom"},marks:{bold:"Bold",italic:"Italic",underline:"Underline",strike:"Strikethrough",code:"Code",link:"Link"},placeholder:{emptyDocument:"Write, or type '/' for commands…",heading:e=>`Heading ${e}`},slash:{filterTag:"Filters",filterHint:"Filters…",groups:{style:"Style",insert:"Insert",upload:"Upload"}},blocks:{text:{title:"Text",description:"Just start typing with plain text."},heading1:{title:"Heading 1",description:"Big section heading."},heading2:{title:"Heading 2",description:"Medium section heading."},heading3:{title:"Heading 3",description:"Small section heading."},bulletList:{title:"Bullet list",description:"An unordered list."},orderedList:{title:"Numbered list",description:"A list with numbering."},taskList:{title:"To-do list",description:"A list with checkboxes."},blockquote:{title:"Blockquote",description:"Insert a quote block."},codeBlock:{title:"Code block",description:"Insert a block of code."},hardBreak:{title:"Line break",description:"Break a line inside a paragraph."},clearLine:{title:"Clear line",description:"Clear the current line."},separator:{title:"Divider",description:"Insert a horizontal rule."},emoji:{title:"Emoji",description:"Insert an emoji."},mention:{title:"Mention",description:"Mention a person."},table:{title:"Table",description:"Insert a table."},tableOfContents:{title:"Table of contents",description:"Insert a live outline of your headings."},image:{title:"Image",description:"Insert an image upload zone."},attachment:{title:"Attachment",description:"Upload a Word, PDF or spreadsheet file."}},bubble:{turnInto:"Turn into",linkPlaceholder:"Paste a link…",improve:"Improve",pasteLink:"Paste a link…",textColor:"Text color",backgroundColor:"Background color",increaseIndent:"Increase indent",decreaseIndent:"Decrease indent"},drag:{handleHint:"Click for options, hold to drag",resetFormatting:"Reset formatting",duplicate:"Duplicate",copyToClipboard:"Copy to clipboard",copyAnchorLink:"Copy anchor link",askAi:"Ask AI",insertBlock:"Insert block"},table:{alignment:"Alignment",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignJustify:"Justify",alignTop:"Align top",alignMiddle:"Align middle",alignBottom:"Align bottom",mergeCells:"Merge cells",splitCell:"Split cell",insertRowBefore:"Insert row above",insertRowAfter:"Insert row below",insertColumnBefore:"Insert column left",insertColumnAfter:"Insert column right",deleteRow:"Delete row",deleteColumn:"Delete column",duplicateRow:"Duplicate row",duplicateColumn:"Duplicate column",clearRowContents:"Clear row contents",clearColumnContents:"Clear column contents",moveRowUp:"Move row up",moveRowDown:"Move row down",moveColumnLeft:"Move column left",moveColumnRight:"Move column right",deleteTable:"Delete table"},image:{clickToUpload:"Click to upload",delete:"Delete image",orDragAndDrop:"or drag and drop",limitHint:(e,t)=>`Maximum ${e} file${e===1?"":"s"}, ${t}MB each.`,clearAll:"Clear all",caption:"Caption",download:"Download image",replace:"Replace"},emojiPicker:{empty:"No emoji found",loading:"Loading…"},attachment:{clickToUpload:"Click to choose a file (Word, PDF, spreadsheet…)",uploading:"Uploading file…",download:"Download file"},toc:{title:"Table of contents",empty:"No headings found"}},Y="vi",$e={vi:Qe,en:et},ge=(e=Y)=>$e[e]??$e[Y],tt=x.createContext(ge(Y)),Vn=({locale:e=Y,children:t})=>{const o=x.useMemo(()=>ge(e),[e]);return n.jsx(tt.Provider,{value:o,children:t})},H=()=>x.useContext(tt),nt=({editor:e})=>{const t=H(),{horizontal:o,vertical:r}=Bn(e);return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(Sn,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:t.table.alignment})]}),n.jsx(Ae,{children:n.jsxs(Re,{sideOffset:8,alignOffset:-90,className:"w-50 z-(--notion-editor-z-menu)",children:[n.jsx(q,{onClick:()=>ne(e,{horizontal:"left"}),icon:m.TextAlignStart,label:t.table.alignLeft,className:o==="left"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.TextAlignCenter,label:t.table.alignCenter,onClick:()=>ne(e,{horizontal:"center"}),className:o==="center"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.TextAlignEnd,label:t.table.alignRight,onClick:()=>ne(e,{horizontal:"right"}),className:o==="right"?"text-foreground! bg-accent!":""}),n.jsx(W,{}),n.jsx(q,{icon:m.AlignVerticalJustifyStart,label:t.table.alignTop,onClick:()=>ne(e,{vertical:"top"}),className:r==="top"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.AlignVerticalJustifyCenter,label:t.table.alignMiddle,onClick:()=>ne(e,{vertical:"middle"}),className:r==="middle"?"text-foreground! bg-accent!":""}),n.jsx(q,{icon:m.AlignVerticalJustifyEnd,label:t.table.alignBottom,onClick:()=>ne(e,{vertical:"bottom"}),className:r==="bottom"?"text-foreground! bg-accent!":""})]})})]})},ot=({color:e,onClick:t})=>n.jsxs(F,{onClick:t,className:"py-1.5 rounded-lg text-muted-foreground px-2.5 gap-2",children:[e.type==="text"?n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-color-text",style:{color:`var(--tt-color-text-${e.value})`,"--color-text-button-color":`var(--tt-color-text-${e.value})`},children:n.jsx(He,{})}):n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-highlight",style:{"--highlight-color":e.value==="default"?"var(--background)":`var(--tt-color-highlight-${e.value})`}}),e.name," ",e.type]}),rt="recentlyUsedColors",On=3,qe=[{name:"Default",value:"default",type:""},{name:"Gray",value:"gray",type:""},{name:"Brown",value:"brown",type:""},{name:"Orange",value:"orange",type:""},{name:"Yellow",value:"yellow",type:""},{name:"Green",value:"green",type:""},{name:"Blue",value:"blue",type:""},{name:"Purple",value:"purple",type:""},{name:"Pink",value:"pink",type:""},{name:"Red",value:"red",type:""}],Q=e=>[{title:e.bubble.textColor,colors:qe.map(t=>({...t,type:"text"}))},{title:e.bubble.backgroundColor,colors:qe.map(t=>({...t,type:"background"}))}],xe=()=>{if(typeof window>"u")return[];const e=localStorage.getItem(rt);return e?JSON.parse(e):[]},Ie=(e,t,o)=>{const i=xe().filter(l=>l.value!==e.value||l.type!==e.type),s=[e,...i].slice(0,On);localStorage.setItem(rt,JSON.stringify(s)),t(()=>[{title:o.common.recentlyUsed,colors:s},...Q(o)])},st=({editor:e})=>{const t=H();if(!e)return;const[o,r]=x.useState(()=>{const i=xe();return i.length>0?[{title:t.common.recentlyUsed,colors:i},...Q(t)]:Q(t)});return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(m.PaintBucket,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:t.common.color})]}),n.jsx(Ae,{children:n.jsx(Re,{sideOffset:8,className:"w-55 pr-px z-(--notion-editor-z-menu)",children:n.jsx(ie,{className:"h-90 p-0.5 pr-3",children:o.map(i=>n.jsxs(X,{children:[n.jsx(Je,{className:"text-foreground",children:i.title}),i.colors.map(s=>n.jsx(ot,{onClick:()=>{if(Ie(s,r,t),s.type==="background"){Oe(e,{backgroundColor:`var(--tt-color-text-${s.value})`});return}Oe(e,{textColor:`var(--tt-color-text-${s.value})`})},color:s},s.value))]},i.title))})})})]})},$n=e=>{const t={isInsideTable:!1,currentColumnIndex:-1,isFirstColumn:!0,isLastColumn:!0,currentRowIndex:-1,isFirstRow:!0,isLastRow:!0};if(!e)return t;const{state:o}=e,r=o.selection;let i=null;if(r.anchorCell)i=r.anchorCell.pos;else{const f=r.$anchor;for(let b=f.depth;b>0;b--){const g=f.node(b).type.name;if(g==="tableCell"||g==="tableHeader"){i=f.before(b);break}}}if(i===null)return t;const s=o.doc.resolve(i);let l=null,a=-1;for(let f=s.depth;f>0;f--)if(s.node(f).type.name==="table"){l=s.node(f),a=s.before(f);break}if(!l||a===-1)return t;const d=P.TableMap.get(l),c=i-a-1,u=d.findCell(c),p=u.left,h=u.top;return{isInsideTable:!0,currentColumnIndex:p,isFirstColumn:p===0,isLastColumn:p===d.width-1,currentRowIndex:h,isFirstRow:h===0,isLastRow:h===d.height-1}},Fe=(e,t)=>{if(!e)return!1;const o=le(e.state);if(!o)return!1;const{tableNode:r,map:i,cellRect:s}=o;if(t==="column"){const l=s.left;for(let a=0;a<i.height;a++){const d=a*i.width+l,c=i.map[d],u=r.nodeAt(c);if(u&&u.textContent.trim().length>0)return!0}}if(t==="row"){const l=s.top;for(let a=0;a<i.width;a++){const d=l*i.width+a,c=i.map[d],u=r.nodeAt(c);if(u&&u.textContent.trim().length>0)return!0}}return!1},pe="flex items-center gap-2 px-2.5 rounded-md text-sm font-medium transition-colors cursor-pointer w-full",Ue=({editor:e,type:t,pluginKey:o})=>{const r=H(),[i,s]=x.useState(!1),l=t==="row",a=l?m.EllipsisVerticalIcon:m.EllipsisIcon,d=l?"w-3 h-full rounded flex items-center justify-center transition-colors":"w-full h-3 rounded flex items-center justify-center transition-colors",c=j=>{s(j),e.chain().command(({tr:C})=>(C.setMeta(o,{openedMenu:j}),!0)).run()},{isInsideTable:u,isFirstColumn:p,isLastColumn:h,isFirstRow:f,isLastRow:b}=$n(e),g=Fe(e,"row"),v=Fe(e,"column");return n.jsxs(Ne,{open:i,onOpenChange:c,children:[n.jsx(Me,{className:y(d,{"bg-primary text-primary-foreground":i,"text-secondary-foreground bg-accent":!i}),children:n.jsx(a,{className:"size-4 shrink-0"})}),n.jsx(Se,{className:"shadow-xl w-60 pr-px",align:"start",side:l?"right":"bottom",children:n.jsxs(ie,{className:"h-70 overflow-hidden overflow-y-auto p-0.5 pr-3",children:[n.jsxs(X,{children:[n.jsx(q,{icon:l?m.ArrowUp:m.ArrowLeft,label:l?r.table.moveRowUp:r.table.moveColumnLeft,onClick:()=>{l?Ve(e,"up"):Be(e,"left")},disabled:l?f:p}),n.jsx(q,{icon:l?m.ArrowDown:m.ArrowRight,label:l?r.table.moveRowDown:r.table.moveColumnRight,onClick:()=>{l?Ve(e,"down"):Be(e,"right")},disabled:l?b:h})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(q,{icon:l?An:kn,label:l?r.table.insertRowBefore:r.table.insertColumnBefore,onClick:()=>l?e.chain().focus().addRowBefore().run():e.chain().focus().addColumnBefore().run()}),n.jsx(q,{icon:l?Mn:Nn,label:l?r.table.insertRowAfter:r.table.insertColumnAfter,onClick:()=>l?e.chain().focus().addRowAfter().run():e.chain().focus().addColumnAfter().run()})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(st,{editor:e}),n.jsx(nt,{editor:e}),(g||v)&&n.jsx(q,{icon:m.SquareX,label:l?r.table.clearRowContents:r.table.clearColumnContents,onClick:()=>e.chain().focus().command(({state:j,dispatch:C})=>P.deleteCellSelection(j,C)).run()})]}),n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(q,{icon:m.CopyIcon,label:l?r.table.duplicateRow:r.table.duplicateColumn,onClick:()=>l?Dn(e):Pn(e)}),n.jsx(q,{icon:m.Trash,label:l?r.table.deleteRow:r.table.deleteColumn,variant:"destructive",onClick:()=>l?e.chain().focus().deleteRow().run():e.chain().focus().deleteColumn().run()})]})]})})]})},qn=({editor:e,setColor:t})=>{const o=H(),[r,i]=x.useState(()=>{const s=xe();return s.length>0?[{title:o.common.recentlyUsed,colors:s},...Q(o)]:Q(o)});return n.jsxs(Te,{children:[n.jsxs(Le,{className:pe,children:[n.jsx(m.PaintBucket,{className:"size-4 shrink-0 text-muted-foreground"}),n.jsx("span",{children:o.common.color})]}),n.jsx(Ae,{children:n.jsx(Re,{sideOffset:8,className:"w-55 pr-px z-(--notion-editor-z-menu)",children:n.jsx(ie,{className:"h-90 p-0.5 pr-3",children:r.map(s=>n.jsxs(X,{children:[n.jsx(Je,{className:"text-foreground",children:s.title}),s.colors.map(l=>n.jsx(ot,{onClick:()=>t(l),color:l},l.value))]},s.title))})})})]})},Fn={placement:"left-start",strategy:"absolute"},it=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),[i,s]=x.useState(null);if(!e)return;const l=c=>{const u=c.currentTarget.closest(".drag-handle");if(!u)return null;const p=u.getBoundingClientRect(),h=p.right+20,f=p.top+p.height/2;return e.view.posAtCoords({left:h,top:f})},a=c=>{c.preventDefault(),c.stopPropagation();const u=l(c);if(u&&u.pos!==null){const p=e.state.doc.resolve(u.pos),h=p.end(p.depth);e.chain().insertContentAt(h,{type:"paragraph",content:[{type:"text",text:"/"}]}).focus().run()}},d=c=>{const u=l(c);if(!u||u.pos===null)return;const p=e.state.doc.resolve(u.pos);let h=p.depth;for(let g=p.depth;g>0;g--){const v=p.node(g)?.type.name;if(v==="blockquote"||v==="bulletList"||v==="orderedList"||v==="table"){h=g;break}}const f=p.before(h),b=p.node(h);if(f!==void 0&&b&&b.type.name!=="doc"){const{tr:g}=e.state,v=D.NodeSelection.create(e.state.doc,f);e.view.dispatch(g.setSelection(v)),s(b.type.name),console.log("Active Block Node Status:",b.type.name),r(!0)}};return n.jsx(Et,{className:"drag-handle",editor:e,nested:!1,computePositionConfig:Fn,children:n.jsxs("div",{className:"flex items-center gap-1 mr-2 ",children:[n.jsx(K,{content:t.drag.insertBlock,children:n.jsx(z,{onClick:a,variant:"ghost",className:"",size:"icon-sm",children:n.jsx(m.Plus,{})})}),n.jsx("div",{className:"relative",children:n.jsxs(Ne,{open:o,onOpenChange:r,children:[n.jsx(K,{className:"max-w-30 text-center",content:"Click for options Hold for dragging",children:n.jsx(z,{onClick:d,variant:"ghost",size:"icon-sm",children:n.jsx(m.GripVertical,{})})}),n.jsx(Me,{className:"sr-only",children:"open"}),n.jsx(Un,{editor:e})]})})]})})},Un=({editor:e})=>{const t=H(),o=r=>{if(Ie(r,()=>{},t),r.type==="text"){e.chain().focus().setColor(`var(--tt-color-text-${r.value})`).run();return}hn(e,`var(--tt-color-text-${r.value})`)};return n.jsxs(Se,{align:"center",sideOffset:30,side:"left",className:"w-55",children:[n.jsx(qn,{setColor:o,editor:e}),n.jsxs(F,{className:y("text-muted-foreground"),children:[n.jsx(m.RotateCcw,{})," ",t.drag.resetFormatting]}),n.jsx(W,{}),n.jsxs(F,{onClick:()=>fn(e),className:y("text-muted-foreground"),children:[n.jsx(m.Copy,{})," ",t.drag.duplicate,n.jsx(ae,{children:"⌘D"})]}),n.jsxs(F,{onClick:()=>pn(e),className:y("text-muted-foreground"),children:[n.jsx(m.Clipboard,{})," ",t.drag.copyToClipboard,n.jsx(ae,{children:"⌘C"})]}),n.jsxs(F,{disabled:!0,className:y("text-muted-foreground"),children:[n.jsx(m.Link,{})," ",t.drag.copyAnchorLink,n.jsx(ae,{children:"⌘^L"})]}),n.jsx(W,{}),n.jsxs(F,{disabled:!0,className:y("text-muted-foreground"),children:[n.jsx(m.Sparkles,{})," ",t.drag.askAi,n.jsx(ae,{children:"⌘J"})]}),n.jsx(W,{}),n.jsxs(F,{onClick:()=>mn(e),variant:"destructive",children:[n.jsx(m.Trash,{})," ",t.common.delete,n.jsx(ae,{children:"Del"})]})]})},V=({onClick:e,isActive:t,icon:o,className:r,text:i,size:s,showTooltip:l,tooltip:a,disabled:d,...c})=>{const u=()=>{if(x.isValidElement(o))return x.cloneElement(o,{className:y("stroke-[2.75]",o.props.className)});const p=o;return n.jsx(p,{className:"stroke-[2.75]"})};return n.jsx(K,{content:a,showTooltip:l,children:n.jsxs(z,{size:s||(i?"default":"icon"),variant:t?"secondary":"ghost",className:y("",r),onClick:e,disabled:d,...c,children:[u()," ",i]})})};function J({className:e,orientation:t="horizontal",decorative:o=!0,...r}){return n.jsx(S.Separator.Root,{"data-slot":"separator",decorative:o,orientation:t,className:y("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",e),...r})}const _n=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M4 2C4 1.44772 3.55228 1 3 1C2.44772 1 2 1.44772 2 2V22C2 22.5523 2.44772 23 3 23C3.55228 23 4 22.5523 4 22V2Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M10 4C8.34315 4 7 5.34315 7 7V17C7 18.6569 8.34315 20 10 20H19C20.6569 20 22 18.6569 22 17V7C22 5.34315 20.6569 4 19 4H10ZM9 7C9 6.44772 9.44772 6 10 6H19C19.5523 6 20 6.44772 20 7V17C20 17.5523 19.5523 18 19 18H10C9.44772 18 9 17.5523 9 17V7Z",fill:"currentColor"})]}),Wn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M21 1C21.5523 1 22 1.44772 22 2V22C22 22.5523 21.5523 23 21 23C20.4477 23 20 22.5523 20 22V2C20 1.44772 20.4477 1 21 1Z",fill:"currentColor"}),n.jsx("path",{"fill-rule":"evenodd",clipRule:"evenodd",d:"M2 7C2 5.34315 3.34315 4 5 4H14C15.6569 4 17 5.34315 17 7V17C17 18.6569 15.6569 20 14 20H5C3.34315 20 2 18.6569 2 17V7ZM5 6C4.44772 6 4 6.44772 4 7V17C4 17.5523 4.44772 18 5 18H14C14.5523 18 15 17.5523 15 17V7C15 6.44772 14.5523 6 14 6H5Z",fill:"currentColor"})]}),Zn=e=>n.jsxs("svg",{...e,width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12 1C12.5523 1 13 1.44772 13 2V22C13 22.5523 12.5523 23 12 23C11.4477 23 11 22.5523 11 22V2C11 1.44772 11.4477 1 12 1Z",fill:"currentColor"}),n.jsx("path",{d:"M2 7C2 5.34315 3.34315 4 5 4H7C7.55228 4 8 4.44772 8 5C8 5.55228 7.55228 6 7 6H5C4.44772 6 4 6.44772 4 7V17C4 17.5523 4.44772 18 5 18H7C7.55228 18 8 18.4477 8 19C8 19.5523 7.55228 20 7 20H5C3.34315 20 2 18.6569 2 17V7Z",fill:"currentColor"}),n.jsx("path",{d:"M19 4C20.6569 4 22 5.34315 22 7V17C22 18.6569 20.6569 20 19 20H17C16.4477 20 16 19.5523 16 19C16 18.4477 16.4477 18 17 18H19C19.5523 18 20 17.5523 20 17V7C20 6.44772 19.5523 6 19 6H17C16.4477 6 16 5.55228 16 5C16 4.44772 16.4477 4 17 4H19Z",fill:"currentColor"})]}),lt=({editor:e,onReplaceClick:t})=>{const o=H();if(!e)return;const{alignment:r}=e.getAttributes("image"),i=l=>{e.chain().focus().updateAttributes("image",{alignment:l}).run()},s=()=>{e.chain().focus().deleteNode("image").insertContent({type:"imageUpload"}).run()};return n.jsxs(Xe.BubbleMenu,{pluginKey:"imageMenu",editor:e,shouldShow:({editor:l,view:a})=>a.hasFocus()&&l.isActive("image"),options:{offset:6},className:"bg-card not-prose border shadow-xl rounded-xl px-0.5 flex items-center gap-1 py-0.5",children:[n.jsxs("div",{className:" flex items-center gap-1 ",children:[n.jsx(V,{tooltip:o.align.left,icon:n.jsx(_n,{}),isActive:r==="left",onClick:()=>i("left")}),n.jsx(V,{tooltip:o.align.center,icon:n.jsx(Zn,{}),isActive:r==="center",onClick:()=>i("center")}),n.jsx(V,{tooltip:o.align.right,icon:n.jsx(Wn,{}),isActive:r==="right",onClick:()=>i("right")})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:o.image.download,icon:m.Download,onClick:()=>e.chain().focus().toggleBold().run()}),n.jsx(V,{tooltip:"Replace",icon:m.RefreshCcw,onClick:s}),n.jsx(V,{variant:"destructive",tooltip:o.image.delete,icon:m.Trash2,onClick:()=>e.chain().focus().deleteSelection().run()})]})]})};function be({...e}){return n.jsx(S.Popover.Root,{"data-slot":"popover",...e})}function Ce({...e}){return n.jsx(S.Popover.Trigger,{"data-slot":"popover-trigger",...e})}function ve({className:e,align:t="center",sideOffset:o=4,...r}){return n.jsx(S.Popover.Portal,{children:n.jsx(S.Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:y("z-(--notion-editor-z-menu) flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r})})}const Kn=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),[i,s]=x.useState(""),{isLink:l,activeUrl:a}=N.useEditorState({editor:e,selector:p=>({isLink:p.editor.isActive("link"),activeUrl:p.editor.getAttributes("link").href||""})});x.useEffect(()=>{o&&s(a)},[o,a]);const d=x.useCallback(()=>{if(i)try{e.chain().focus().extendMarkRange("link").setLink({href:i}).run(),r(!1)}catch(p){console.error(p)}},[e,i]),c=x.useCallback(()=>{try{e.chain().focus().extendMarkRange("link").unsetLink().run(),s(""),r(!1)}catch(p){console.error(p)}},[e]),u=p=>{p.key==="Enter"&&(p.preventDefault(),d())};return n.jsxs(be,{open:o,onOpenChange:r,children:[n.jsx(K,{content:t.marks.link,children:n.jsx(Ce,{asChild:!0,children:n.jsx(z,{variant:l?"secondary":"ghost",size:"icon",children:n.jsx(m.Link,{className:y(l&&"text-blue-500")})})})}),n.jsx(ve,{className:"p-1.5 rounded-xl w-78.75 shadow-xl",side:"bottom",align:"center",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("input",{value:i,onChange:p=>s(p.target.value),onKeyDown:u,className:"border-0 outline-0 min-w-48 text-sm w-full h-8 py-1 pl-2.5 pr-0 bg-transparent",placeholder:t.bubble.linkPlaceholder,autoFocus:!0}),n.jsx("div",{children:n.jsx(z,{disabled:!i,onClick:d,variant:"ghost",size:"icon",type:"button",children:n.jsx(m.CornerDownLeft,{})})}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(z,{disabled:!i,variant:"ghost",size:"icon",asChild:!0,children:n.jsx("a",{href:i||void 0,target:"_blank",rel:"noopener noreferrer",className:y(!i&&"pointer-events-none opacity-50"),children:n.jsx(m.ExternalLink,{})})}),n.jsx(z,{disabled:!l,onClick:c,variant:"destructive",size:"icon",children:n.jsx(m.Trash,{})})]})]})})]})},Gn=({editor:e})=>{const t=H(),o=e.getAttributes("paragraph")["data-indent-level"]||e.getAttributes("heading")["data-indent-level"]||0,r=o<=0,i=o>=10;return n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:t.bubble.decreaseIndent,disabled:r,icon:m.ListIndentDecrease,onClick:()=>e.chain().focus().outdent().run()}),n.jsx(V,{tooltip:t.bubble.increaseIndent,disabled:i,icon:m.ListIndentIncrease,onClick:()=>e.chain().focus().indent().run()})]})},Xn=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),{isSubscript:i,isSuperscript:s,isAlignLeft:l,isAlignRight:a,isAlignCenter:d,isAlignJustify:c}=N.useEditorState({editor:e,selector:u=>({isSubscript:u.editor.isActive("subscript"),isSuperscript:u.editor.isActive("superscript"),isAlignLeft:u.editor.isActive({textAlign:"left"}),isAlignRight:u.editor.isActive({textAlign:"right"}),isAlignCenter:u.editor.isActive({textAlign:"center"}),isAlignJustify:u.editor.isActive({textAlign:"justify"})})});return n.jsxs(be,{open:o,onOpenChange:r,children:[n.jsx(K,{content:t.common.moreOptions,children:n.jsx(Ce,{asChild:!0,children:n.jsx(z,{variant:"ghost",size:"icon",children:n.jsx(m.EllipsisVertical,{})})})}),n.jsx(ve,{className:"p-1 rounded-xl max-w-fit shadow-xl",side:"top",align:"center",onOpenAutoFocus:u=>u.preventDefault(),children:n.jsxs("div",{className:"flex gap-0.5",children:[n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:"Subscript",isActive:i,icon:m.Subscript,onClick:()=>e.chain().focus().toggleSubscript().run()}),n.jsx(V,{tooltip:"Superscript",isActive:s,icon:m.Superscript,onClick:()=>e.chain().focus().toggleSuperscript().run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:"flex gap-0.5",children:[n.jsx(V,{tooltip:t.align.left,isActive:l,icon:m.TextAlignStart,onClick:()=>e.chain().focus().toggleTextAlign("left").run()}),n.jsx(V,{tooltip:t.align.center,isActive:d,icon:m.TextAlignCenter,onClick:()=>e.chain().focus().toggleTextAlign("center").run()}),n.jsx(V,{tooltip:t.align.right,isActive:a,icon:m.TextAlignEnd,onClick:()=>e.chain().focus().toggleTextAlign("right").run()}),n.jsx(V,{tooltip:t.align.justify,isActive:c,icon:m.TextAlignJustify,onClick:()=>e.chain().focus().toggleTextAlign("justify").run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsx(Gn,{editor:e})]})})]})},Jn=({tooltip:e,color:t,onClick:o,editor:r})=>{const{isActive:i}=N.useEditorState({editor:r,selector:s=>({isActive:s.editor.isActive("textStyle",{color:`var(--tt-color-text-${t})`})})});return n.jsx(n.Fragment,{children:n.jsx(K,{content:e,children:n.jsx(z,{size:"icon",variant:i?"secondary":"ghost",style:{"--color-text-button-color":`var(--tt-color-text-${t})`},onClick:o,children:n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-color-text",style:{color:`var(--tt-color-text-${t})`},children:n.jsx(He,{})})})})})},Yn=({tooltip:e,color:t,onClick:o,editor:r})=>{const{isActive:i}=N.useEditorState({editor:r,selector:s=>({isActive:s.editor.isActive("highlight",{color:t.value==="default"?"var(--background)":`var(--tt-color-highlight-${t.value})`})})});return n.jsx(n.Fragment,{children:n.jsx(K,{content:e,children:n.jsx(z,{size:"icon",variant:i?"secondary":"ghost",onClick:o,children:n.jsx("span",{className:"size-5 flex items-center justify-center rounded-full tiptap-button-highlight",style:{"--highlight-color":t.value==="default"?"var(--background)":`var(--tt-color-highlight-${t.value})`}})})})})},Qn=({editor:e})=>{const t=H(),[o,r]=x.useState(()=>{const l=xe();return l.length>0?[{title:t.common.recentlyUsed,colors:l},...Q(t)]:Q(t)}),{textColor:i,highlightColor:s}=N.useEditorState({editor:e,selector:l=>({textColor:l.editor.getAttributes("textStyle").color,highlightColor:l.editor.getAttributes("highlight")})});return n.jsxs(be,{children:[n.jsx(K,{content:t.bubble.textColor,children:n.jsx(Ce,{asChild:!0,children:n.jsxs(z,{variant:"ghost",className:"p-2 gap-1",children:[n.jsx("span",{className:`size-5 flex items-center justify-center border rounded-full
2
+ tiptap-button-color-text-popover`,style:{"--active-highlight-color":s?.color},children:n.jsx(He,{style:{color:i}})}),n.jsx(m.ChevronDown,{className:"size-3",size:10})]})})}),n.jsx(eo,{items:o,editor:e,handleAddRecentUsed:l=>Ie(l,r,t)})]})},eo=({items:e,editor:t,handleAddRecentUsed:o})=>n.jsx(ve,{onOpenAutoFocus:r=>r.preventDefault(),className:"w-47 rounded-2xl p-0 pr-px bg-popover shadow-2xl z-(--notion-editor-z-menu) overflow-hidden",children:n.jsx(ie,{className:"h-66.25 p-1.5 pr-2.5",children:e.map((r,i)=>n.jsx("div",{children:n.jsxs("div",{className:"min-w-max flex relative flex-col justify-center align-middle",children:[n.jsx("div",{className:"capitalize pt-3 pb-1 px-1.5 leading-normal font-medium text-xs text-muted-foreground",children:r.title}),n.jsx("div",{className:"grid grid-cols-5 gap-0.5 pl-1",children:r.colors.map(s=>s.type==="text"?n.jsx(Jn,{editor:t,color:s.value,tooltip:`${s.name} ${s.type}`,onClick:()=>{t.chain().focus().setColor(`var(--tt-color-text-${s.value})`).run(),o(s)}}):s.type==="background"?n.jsx(Yn,{editor:t,color:s,tooltip:`${s.name} ${s.type}`,onClick:()=>{t.chain().focus().toggleHighlight({color:`var(--tt-color-highlight-${s.value})`}).run(),o(s)}}):"")})]})},r.title))})}),at={title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:n.jsx(m.Type,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run()}},ct={title:"Heading 1",description:"Big heading.",searchTerms:["h1","title","big","large"],icon:n.jsx(m.Heading1,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run()}},dt={title:"Heading 2",description:"Medium heading.",searchTerms:["h2","subtitle","medium"],icon:n.jsx(m.Heading2,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run()}},ut={title:"Heading 3",description:"Small heading.",searchTerms:["h3","subtitle","small"],icon:n.jsx(m.Heading3,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run()}},to={title:"Blockquote",description:"Add blockquote.",searchTerms:["quote","blockquote"],icon:n.jsx(m.TextQuote,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},pt={title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:n.jsx(m.List,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBulletList().run()}},mt={title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:n.jsx(m.ListOrdered,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleOrderedList().run()}},ft={title:"Tod-do list",description:"Create a todo list",searchTerms:["list","task","todo"],icon:n.jsx(m.ListTodo,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run()}},ht={title:"Code Block",description:"Insert a custom HTML block",searchTerms:["html","code","custom"],icon:n.jsx(m.CodeXmlIcon,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}},no=e=>[{title:e.bubble.turnInto,commands:[{...at,...e.blocks.text},{...ct,...e.blocks.heading1},{...dt,...e.blocks.heading2},{...ut,...e.blocks.heading3},{...pt,...e.blocks.bulletList},{...mt,...e.blocks.orderedList},{...ft,...e.blocks.taskList},{...ht,...e.blocks.codeBlock}]}],oo=e=>[{title:e.blocks.heading1.title,icon:m.Heading1,level:1},{title:e.blocks.heading2.title,icon:m.Heading2,level:2},{title:e.blocks.heading3.title,icon:m.Heading3,level:3}],ro=({editor:e})=>{const t=H(),o=oo(t),r=no(t),{activeBlock:i,isParagraph:s,isBulletList:l,isOrderedList:a,isTaskList:d,isBlockquote:c,isCodeBlock:u,headingLevel:p}=N.useEditorState({editor:e,selector:f=>{const b=o.find(g=>f.editor.isActive("heading",{level:g.level}));return{activeBlock:f.editor.getAttributes("paragraph"),isParagraph:f.editor.isActive("paragraph"),isBulletList:f.editor.isActive("bulletList"),isOrderedList:f.editor.isActive("orderedList"),isTaskList:f.editor.isActive("taskList"),isBlockquote:f.editor.isActive("blockquote"),isCodeBlock:f.editor.isActive("codeBlock"),headingLevel:b?b.title:null}}}),h=()=>s?t.blocks.text.title:p||(l?t.blocks.bulletList.title:a?t.blocks.orderedList.title:d?"To-do list":c?t.blocks.blockquote.title:u?t.blocks.codeBlock.title:t.blocks.text.title);return n.jsxs(be,{children:[n.jsx(Ce,{asChild:!0,children:n.jsxs(z,{variant:"ghost",children:[h()," ",n.jsx(m.ChevronDown,{})]})}),n.jsx(ve,{className:"w-48 rounded-2xl p-0 pr-px bg-popover shadow-2xl z-(--notion-editor-z-menu) overflow-hidden",children:n.jsx(ie,{className:"h-66.25 p-1.5 pr-2.5",children:r.map((f,b)=>n.jsx("div",{children:n.jsxs("div",{className:"min-w-max flex relative flex-col justify-center align-middle",children:[n.jsx("div",{className:"capitalize pt-3 pb-1 px-1.5 leading-normal font-medium text-xs text-muted-foreground",children:f.title}),n.jsxs("div",{className:"flex flex-col",children:[n.jsxs(z,{variant:s?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().setParagraph().run(),children:[n.jsx(m.Type,{})," ",t.blocks.text.title]}),o.map(g=>n.jsx(so,{head:g,editor:e})),n.jsxs(z,{variant:l?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleBulletList().run(),children:[n.jsx(m.List,{})," ",t.blocks.bulletList.title]}),n.jsxs(z,{variant:a?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleOrderedList().run(),children:[n.jsx(m.ListOrdered,{})," ",t.blocks.orderedList.title]}),n.jsxs(z,{variant:d?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleTaskList().run(),children:[n.jsx(m.ListTodo,{})," ",t.blocks.taskList.title]}),n.jsxs(z,{disabled:d,variant:c?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleBlockquote().run(),children:[n.jsx(m.TextQuote,{})," ",t.blocks.blockquote.title]}),n.jsxs(z,{disabled:d,variant:u?"secondary":"ghost",className:"w-full justify-start",onClick:()=>e.chain().focus().toggleCodeBlock().run(),children:[n.jsx(m.CodeXmlIcon,{})," ",t.blocks.codeBlock.title]})]})]})},f.title))})})]})},so=({head:e,editor:t})=>{const{isActive:o}=N.useEditorState({editor:t,selector:r=>({isActive:r.editor.isActive("heading",{level:e.level})})});return n.jsxs(z,{variant:o?"secondary":"ghost",className:"w-full justify-start",onClick:()=>t.chain().focus().toggleHeading({level:e.level}).run(),children:[n.jsx(e.icon,{})," ",e.title]})},gt=({editor:e})=>{const t=H();if(!e)return;const{isBold:o,isItalic:r,isStrikethrough:i,isUnderline:s,isCode:l}=N.useEditorState({editor:e,selector:a=>({isBold:a.editor.isActive("bold"),isItalic:a.editor.isActive("italic"),isStrikethrough:a.editor.isActive("strike"),isUnderline:a.editor.isActive("underline"),isCode:a.editor.isActive("code")})});return n.jsxs(Xe.BubbleMenu,{editor:e,pluginKey:"textMenu",className:"bg-card not-prose border shadow-xl rounded-xl px-1 flex items-center gap-1 py-1",shouldShow:({editor:a,view:d,state:c,from:u,to:p})=>a.isActive("image")||a.isActive("imageUpload")||a.isActive("table")?!1:d.hasFocus()&&!c.selection.empty,children:[n.jsx(ro,{editor:e}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:" flex items-center gap-1 ",children:[n.jsx(V,{tooltip:t.marks.bold,icon:m.Bold,isActive:o,onClick:()=>e.chain().focus().toggleBold().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.italic,icon:m.Italic,isActive:r,onClick:()=>e.chain().focus().toggleItalic().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.underline,icon:m.Underline,isActive:s,onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:l}),n.jsx(V,{tooltip:"Strikethrough",icon:m.Strikethrough,isActive:i,onClick:()=>e.chain().focus().toggleStrike().run(),disabled:l}),n.jsx(V,{tooltip:t.marks.code,icon:m.Code,isActive:l,onClick:()=>e.chain().focus().toggleCode().run()})]}),n.jsx(J,{orientation:"vertical"}),n.jsxs("div",{className:" flex gap-0.5",children:[n.jsx(Kn,{editor:e}),n.jsx(Qn,{editor:e})]}),n.jsx(J,{orientation:"vertical"}),n.jsx(Xn,{editor:e})]})},fe=new D.PluginKey("table-row-menu-handle"),he=new D.PluginKey("table-column-menu-handle"),io=({pluginKey:e,editor:t,element:o,menuType:r,options:i})=>{const s=i??{strategy:"absolute",placement:"top",offset:0,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},l=r==="row",a=[];let d=!1,c=!1,u,p;const h=()=>(a.length>0||(s.flip&&a.push(I.flip(typeof s.flip!="boolean"?s.flip:void 0)),s.shift&&a.push(I.shift(typeof s.shift!="boolean"?s.shift:void 0)),s.offset&&a.push(I.offset(typeof s.offset!="boolean"?s.offset:void 0)),s.arrow&&a.push(I.arrow(s.arrow)),s.size&&a.push(I.size(typeof s.size!="boolean"?s.size:void 0)),s.autoPlacement&&a.push(I.autoPlacement(typeof s.autoPlacement!="boolean"?s.autoPlacement:void 0)),s.hide&&a.push(I.hide(typeof s.hide!="boolean"?s.hide:void 0)),s.inline&&a.push(I.inline(typeof s.inline!="boolean"?s.inline:void 0))),a),f=()=>{if(p===void 0)return;const C=p;t.chain().command(({tr:w,state:A})=>{const R=A.doc.resolve(C),k=(l?P.CellSelection.rowSelection:P.CellSelection.colSelection)(R);return w.setSelection(k),!0}).run()},b=(C,w)=>{c||(o.style.visibility="visible",o.style.opacity="1",w?.appendChild(o),s.onShow?.(),c=!0)},g=()=>{!c||e.getState(t.view.state)?.openedMenu||(o.style.visibility="hidden",o.style.opacity="0",o.remove(),s.onHide?.(),c=!1,p=void 0,u=void 0)},v=(C,w)=>{if(e.getState(C.state)?.openedMenu)return;const R={getBoundingClientRect:()=>w,getClientRects:()=>[w]};I.computePosition(R,o,{placement:s.placement,strategy:s.strategy,middleware:h()}).then(({x:T,y:k,strategy:E})=>{l?o.style.height=`${w.height}px`:o.style.width=`${w.width}px`,o.style.position=E,o.style.left=`${T}px`,o.style.top=`${k}px`,c&&s.onUpdate?.()})},j=(C,w)=>{const A=w.target;if(!A)return;if(P.columnResizingPluginKey.getState(C.state)?.dragging){g();return}if(P.tableEditingKey.getState(C.state)!==null){g();return}if(l&&he.getState(C.state)?.openedMenu){g();return}else if(fe.getState(C.state)?.openedMenu){g();return}if(e.getState(C.state)?.openedMenu)return;const T=C.posAtDOM(A,0);if(T===void 0)return;let k,E;if(C.state.doc.nodesBetween(T,T,(ee,te)=>ee.type.name==="tableHeader"||ee.type.name==="tableCell"?(k=te,!1):(ee.type.name==="table"&&(E=te),!0)),E===void 0){g();return}u!==E&&g(),u=E;const M=C.nodeDOM(E);if(!M||!(M instanceof HTMLDivElement)){g();return}const L=M.querySelector("table");if(!L)return;const B=L.getBoundingClientRect(),U=16;if(w.x>B.right+U){g();return}if(w.x<B.left-U){g();return}if(w.y<B.top-U){g();return}if(w.y>B.bottom+U){g();return}if(k===void 0||p===k)return;const $=C.nodeDOM(k);if(!$||!($ instanceof HTMLTableCellElement))return;const _=$.getBoundingClientRect();p=k,l?_.x=B.x:_.y=B.y,v(C,_),!c&&b(C,M.querySelector(".table-controls"))};return new D.Plugin({key:e,state:{init:()=>({openedMenu:!1}),apply:(C,w)=>{const A=C.getMeta(e);return A?{openedMenu:A.openedMenu}:w}},view:()=>({update:(C,w)=>{const A=e.getState(w),R=e.getState(C.state),T=A!==R;if(T&&R?.openedMenu&&f(),l&&he.getState(C.state)?.openedMenu){g();return}else if(fe.getState(C.state)?.openedMenu){g();return}const k=!w?.selection.eq(C.state.selection),E=!w?.doc.eq(C.state.doc),{composing:M}=C;if(M||!k&&!E&&!T||!t.isActive("table"))return;if(p===void 0){g();return}const B=C.state.doc.nodeAt(p),U=N.findParentNodeClosestToPos(C.state.doc.resolve(p),Ht=>Ht.type.name==="table");if(!U||!B){g();return}const $=C.nodeDOM(p),_=C.nodeDOM(U.pos);if(!_||!(_ instanceof HTMLDivElement)){g();return}if(!$||!($ instanceof HTMLTableCellElement)){g();return}const ee=_.querySelector("table");if(!ee)return;const te=ee.getBoundingClientRect(),we=$.getBoundingClientRect();l?we.x=te.x:we.y=te.y,v(C,we)},destroy:()=>{g(),s.onDestroy?.()}}),props:{handleDOMEvents:{mousemove:(C,w)=>{d||(window.requestAnimationFrame(()=>{j(C,w),d=!1}),d=!0)},mousedown:j}}})},_e=({ref:e,children:t,pluginProps:o})=>{const r=x.useRef(document.createElement("div"));return x.useEffect(()=>{typeof e=="function"?e(r.current):e&&(e.current=r.current)},[e]),x.useEffect(()=>{const i=o.editor,s=r.current;if(s.style.visibility="hidden",s.style.position="absolute",i.isDestroyed)return;const l=io({...o,element:s});return i.registerPlugin(l),()=>{i.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{s.parentNode&&s.parentNode.removeChild(s)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),r.current)},lo=({editor:e})=>{const t=H(),[o,r]=x.useState(!1),{canMergeCell:i,canSplitCell:s,canClearContents:l}=N.useEditorState({editor:e,equalityFn:(a,d)=>a.canMergeCell===d?.canMergeCell&&a.canSplitCell===d.canSplitCell&&a.canClearContents===d.canClearContents,selector:a=>{const d=a.editor,{selection:c}=d.state,{from:u,to:p,ranges:h}=c;if(!a.editor.isActive("table"))return{canMergeCell:!1,canSplitCell:!1,canClearContents:!1};let f=!1,b=0,g=0;if(c instanceof D.TextSelection&&d.state.doc.nodesBetween(u,p,(v,j)=>{const C=v.type.name;if(C==="tableHeader"||C==="tableCell"){const w=d.view.nodeDOM(j);return f=w.colSpan>1||w.rowSpan>1,!1}return!0}),c instanceof P.CellSelection){b=c.ranges.length;for(const v of h){const{$from:j,$to:C}=v;d.state.doc.nodesBetween(j.pos,C.pos,w=>(w.isTextblock&&(g+=w.content.size),!0))}}return{canMergeCell:b>1,canSplitCell:f,canClearContents:g>0}}});return n.jsxs(Ne,{open:o,onOpenChange:r,children:[n.jsx(Me,{className:y("absolute flex items-center justify-center top-1/2 -translate-y-1/2 hover:-right-2.25 bg-primary size-2 hover:size-4 rounded-full cursor-pointer pointer-events-auto",{"size-4 -right-2.25":o,"-right-1.25":!o}),asChild:!0,children:n.jsx("button",{onPointerDown:a=>{a.preventDefault(),r(!0)},children:n.jsx(m.EqualIcon,{className:y("size-3.5 text-primary-foreground opacity-0 hover:opacity-100",{"opacity-100":o})})})}),n.jsxs(Se,{className:"flex max-h-80 w-55 flex-col overflow-hidden overflow-y-auto shadow-xl",align:"start",side:"bottom",children:[n.jsxs(X,{children:[n.jsxs(F,{hidden:!i,onClick:()=>{e.chain().focus().mergeCells().run()},children:[n.jsx(Pe,{})," ",t.table.mergeCells]}),n.jsxs(F,{hidden:!s,onClick:()=>{e.chain().focus().splitCell().run()},children:[n.jsx(Pe,{})," ",t.table.splitCell]})]}),(i||s)&&n.jsx(W,{}),n.jsxs(X,{children:[n.jsx(st,{editor:e}),n.jsx(nt,{editor:e})]}),l&&n.jsx(W,{}),l&&n.jsxs(F,{className:pe,onClick:()=>{e.chain().focus().command(({state:a,dispatch:d})=>P.deleteCellSelection(a,d)).run()},children:[n.jsx(m.SquareX,{})," ",t.table.clearColumnContents]})]})]})},ao=({pluginKey:e,editor:t,element:o,options:r})=>{const i=r??{strategy:"absolute",placement:"bottom-start",offset:({rects:b})=>({mainAxis:-b.reference.height}),flip:!1,shift:!1,arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},s=[];let l=!1,a;const d=()=>(s.length>0||(i.flip&&s.push(I.flip(typeof i.flip!="boolean"?i.flip:void 0)),i.shift&&s.push(I.shift(typeof i.shift!="boolean"?i.shift:void 0)),i.offset&&s.push(I.offset(typeof i.offset!="boolean"?i.offset:void 0)),i.arrow&&s.push(I.arrow(i.arrow)),i.size&&s.push(I.size(typeof i.size!="boolean"?i.size:void 0)),i.autoPlacement&&s.push(I.autoPlacement(typeof i.autoPlacement!="boolean"?i.autoPlacement:void 0)),i.hide&&s.push(I.hide(typeof i.hide!="boolean"?i.hide:void 0)),i.inline&&s.push(I.inline(typeof i.inline!="boolean"?i.inline:void 0))),s),c=b=>{const{domRect:g,selectionRect:v}=f(b);if(!g||!v){p();return}o.style.width=`${v.width}px`,o.style.height=`${v.height}px`;const j={getBoundingClientRect:()=>g,getClientRects:()=>[g]};I.computePosition(j,o,{placement:i.placement,strategy:i.strategy,middleware:d()}).then(({x:C,y:w,strategy:A})=>{o.style.position=A,o.style.left=`${C}px`,o.style.top=`${w}px`,l&&i.onUpdate?.()})},u=(b,g)=>{l||(o.style.visibility="visible",o.style.opacity="1",g?.appendChild(o),l=!0)},p=()=>{l&&(o.style.visibility="hidden",o.style.opacity="0",o.remove(),l=!1,a=void 0)},h=()=>{t.isActive("table")&&c(t.view)},f=b=>{let g,v;const{selection:j}=b.state;if(j instanceof P.CellSelection){let C,w,A,R;j.forEachCell((T,k)=>{const M=b.nodeDOM(k).getBoundingClientRect();v||(v=M),C=Math.min(C??M.top,M.top),w=Math.min(w??M.left,M.left),A=Math.max(A??M.right,M.right),R=Math.max(R??M.bottom,M.bottom),g={width:A-w,height:R-C},M.left<v.left&&M.top<v.top&&(v=M)})}return j instanceof D.TextSelection&&b.state.doc.nodesBetween(j.from,j.to,(C,w)=>{const A=C.type.name;if(A==="tableHeader"||A==="tableCell"){const T=b.nodeDOM(w).getBoundingClientRect();return v=T,g={width:T.width,height:T.height},!1}return!0}),{domRect:v,selectionRect:g}};return new D.Plugin({key:e,view:()=>(window.addEventListener("resize",h),{update:(b,g)=>{const v=!g?.selection.eq(b.state.selection),j=!g?.doc.eq(b.state.doc),{composing:C}=b;if(C||!v&&!j)return;if(!t.isActive("table")){p();return}c(b);const{ranges:A}=b.state.selection,R=Math.min(...A.map(M=>M.$from.pos)),T=Math.max(...A.map(M=>M.$to.pos));let k;if(t.state.doc.nodesBetween(R,T,(M,L)=>(M.type.name==="table"&&(k=L),!1)),k===void 0){p();return}if(a!==k&&p(),a=k,l)return;const E=b.nodeDOM(k);if(!E){p();return}u(b,E.querySelector(".table-selection-container"))},destroy:()=>{window.removeEventListener("resize",h),p(),i.onDestroy?.()}}),props:{handleDOMEvents:{mousemove:b=>{P.columnResizingPluginKey.getState(b.state)?.dragging&&c(b)}}}})};function co({ref:e,children:t,pluginProps:o}){const r=x.useRef(document.createElement("div"));return x.useEffect(()=>{typeof e=="function"?e(r.current):e&&(e.current=r.current)},[e]),x.useEffect(()=>{const i=o.editor,s=r.current;if(s.style.visibility="hidden",s.style.position="absolute",s.className=y("border-2 border-primary pointer-events-none"),i.isDestroyed)return;const l=ao({...o,element:s});return i.registerPlugin(l),()=>{i.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{s.parentNode&&s.parentNode.removeChild(s)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),r.current)}const uo=new D.PluginKey("add-row-plugin"),po=new D.PluginKey("add-column-plugin"),mo=4,fo=16,ho={row:{delta:(e,t)=>e.clientY-t,measure:e=>e.querySelector("tr:last-child")?.getBoundingClientRect().height??0,insert:Ln,remove:Rn},column:{delta:(e,t)=>e.clientX-t,measure:e=>e.querySelector("tr:first-child > *:last-child")?.getBoundingClientRect().width??0,insert:Hn,remove:En}};function xt(e,t){const o=ho[t];return r=>{r.preventDefault(),r.stopPropagation();const i=r.currentTarget.parentElement,s=i?.getAttribute("data-table-pos"),l=i?.closest(".table-wrapper")?.querySelector("table");if(!i||!s||!l)return;const a=parseInt(s,10),d=t==="row"?r.clientY:r.clientX,c=Math.max(o.measure(l),fo);let u=0;i.setAttribute(se,"true");const p=()=>i.dispatchEvent(new CustomEvent(ce)),h=b=>{const g=Math.round(o.delta(b,d)/c);for(;g>u&&o.insert(e,a);)u+=1;for(;g<u&&o.remove(e,a);)u-=1;p()},f=b=>{Math.abs(o.delta(b,d))<mo&&o.insert(e,a),i.removeAttribute(se),p(),window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",f)};window.addEventListener("mousemove",h),window.addEventListener("mouseup",f)}}function go({editor:e}){const t=xt(e,"row");return n.jsx("button",{className:"w-full h-3 bg-accent flex justify-center items-center rounded-full mt-1 cursor-ns-resize selection:bg-transparent",onMouseDown:t,children:n.jsx(m.Plus,{size:12})})}function xo({editor:e}){const t=xt(e,"column");return n.jsx("button",{className:"w-3 h-full bg-accent flex justify-center items-center rounded-full ml-1 cursor-ew-resize selection:bg-transparent",onMouseDown:t,children:n.jsx(m.Plus,{size:12})})}function bo({editor:e,element:t,pluginKey:o}){const r=s=>{t.style.transition="opacity 0.2s ease",t.style.opacity=s},i=()=>{const s=t.closest(".table-wrapper")?.querySelector("table");s&&(t.style.width=`${s.offsetWidth}px`)};return new D.Plugin({key:o,props:{handleDOMEvents:{mouseover(s,l){const a=l.target;if(t.hasAttribute(se))return!1;const d=t.contains(a),c=a.closest("table tr:last-child");if(d||c){const u=a.closest(".table-wrapper"),p=u?.querySelector("table"),h=u?.querySelector(".table-controls");if(h&&p){const f=s.posAtDOM(p,0);return t.setAttribute("data-table-pos",String(f-1)),h.contains(t)||(t.style.position="",h.appendChild(t)),t.style.width=`${p.offsetWidth}px`,r("1"),!1}}return r("0"),!1},mouseleave(){return t.hasAttribute(se)||r("0"),!1}}},view(){return t.style.opacity="0",t.style.visibility="visible",t.addEventListener(ce,i),{destroy(){t.removeEventListener(ce,i),t.remove()}}}})}const We=({ref:e,children:t,pluginProps:o,createPlugin:r=bo})=>{const i=x.useRef(document.createElement("div")),s=x.useRef(r);return s.current=r,x.useEffect(()=>{typeof e=="function"?e(i.current):e&&(e.current=i.current)},[e]),x.useEffect(()=>{const l=o.editor,a=i.current;if(a.style.visibility="hidden",a.style.position="absolute",l.isDestroyed)return;const d=s.current({...o,element:a});return l.registerPlugin(d),()=>{l.unregisterPlugin(o.pluginKey),window.requestAnimationFrame(()=>{a.parentNode&&a.parentNode.removeChild(a)})}},[o]),ke.createPortal(n.jsx(n.Fragment,{children:t}),i.current)},Co=12,vo=4,wo=Co+vo;function yo({editor:e,element:t,pluginKey:o}){const r=l=>{t.style.transition="opacity 0.2s ease",t.style.opacity=l},i=(l,a)=>{const d=l.getBoundingClientRect(),c=a.getBoundingClientRect();t.style.position="absolute",t.style.top=`${c.top-d.top+l.scrollTop}px`,t.style.left=`${c.right-d.left+l.scrollLeft}px`,t.style.width=`${wo}px`,t.style.height=`${c.height}px`},s=()=>{const l=t.closest(".table-wrapper"),a=l?.querySelector("table");l&&a&&i(l,a)};return new D.Plugin({key:o,props:{handleDOMEvents:{mouseover(l,a){const d=a.target;if(t.hasAttribute(se))return!1;const c=t.contains(d),u=d.closest("td, th"),p=!!u&&u.parentElement?.lastElementChild===u;if(c||p){const h=d.closest(".table-wrapper"),f=h?.querySelector("table"),b=h?.querySelector(".table-controls");if(h&&b&&f){const g=l.posAtDOM(f,0);return t.setAttribute("data-table-pos",String(g-1)),b.contains(t)||b.appendChild(t),i(h,f),r("1"),!1}}return r("0"),!1},mouseleave(){return t.hasAttribute(se)||r("0"),!1}}},view(){return t.style.opacity="0",t.style.visibility="visible",t.addEventListener(ce,s),{destroy(){t.removeEventListener(ce,s),t.remove()}}}})}const bt=({editor:e})=>{const t=x.useMemo(()=>{if(e)return{editor:e,menuType:"column",pluginKey:he,options:{placement:"top-start",offset:{mainAxis:4}}}},[e]),o=x.useMemo(()=>{if(e)return{editor:e,menuType:"row",pluginKey:fe,options:{placement:"left-start",offset:{mainAxis:4}}}},[e]),r=x.useMemo(()=>{if(e)return{editor:e,pluginKey:uo}},[e]),i=x.useMemo(()=>{if(e)return{editor:e,pluginKey:po}},[e]),s=x.useMemo(()=>{if(e)return{editor:e,pluginKey:new D.PluginKey("table-selection-overlay")}},[e]);return e?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[t&&n.jsx(_e,{pluginProps:t,children:n.jsx(Ue,{pluginKey:he,type:"column",editor:e})}),o&&n.jsx(_e,{pluginProps:o,children:n.jsx(Ue,{pluginKey:fe,type:"row",editor:e})})]}),r&&n.jsx(We,{pluginProps:r,children:n.jsx(go,{editor:e})}),i&&n.jsx(We,{pluginProps:i,createPlugin:yo,children:n.jsx(xo,{editor:e})}),s&&n.jsx(co,{pluginProps:s,children:n.jsx(lo,{editor:e})})]}):null},jo=({items:e,scrollOver:t})=>{const o=H(),r=i=>{const s=document.getElementById(i);s&&s.scrollIntoView({behavior:"smooth",block:"start"})};return e.length===0?n.jsx("p",{className:"text-xs text-muted-foreground italic p-2",children:o.toc.empty}):n.jsx("div",{className:"toc-sidebar-progress",children:e.map(i=>n.jsx("div",{onClick:()=>r(i.id),className:y("toc-sidebar-progress-line",{"toc-sidebar-progress-line-active":t?i.isScrolledOver:i.isActive}),style:{"--toc-depth":i.level}},i.id))})},Ct=({items:e,scrollOver:t})=>{const o=H();return n.jsxs("div",{className:"flex flex-col gap-1 w-full text-sm text-neutral-600 dark:text-neutral-400",children:[n.jsx("div",{className:"px-3 py-2 text-xs font-semibold tracking-wider text-neutral-400 uppercase select-none",children:o.toc.title}),e.map(r=>n.jsx("button",{onClick:()=>{document.getElementById(r.id)?.scrollIntoView({behavior:"smooth"})},className:y(" flex items-center w-full px-3 py-1.5 text-left rounded-md transition-all duration-200 ease-in-out group relative hover:bg-accent",{"bg-accent text-muted-foreground!":!t&&r.isActive,"text-gray-500":t&&r.isScrolledOver}),style:{paddingLeft:`${((r.level||1)-1)*12+12}px`},children:n.jsx("span",{className:"truncate",children:r.textContent})},r.id||r.textContent))]})},ko=({items:e})=>n.jsx("div",{className:"toc-sidebar-nav",children:n.jsx("div",{className:"toc-sidebar-popover w-62.5 p-2 pr-px rounded-2xl border border-border shadow-xl bg-popover",children:n.jsx(ie,{className:"h-96 pr-4 **:space-y-px",children:e.map(t=>n.jsx("div",{onClick:()=>{document.getElementById(t.id)?.scrollIntoView({behavior:"smooth"})},className:y("toc-sidebar-item text-sm hover:bg-secondary hover:text-foreground text-muted-foreground rounded-md ",{"bg-secondary text-foreground":t.isActive}),style:{"--toc-depth":t.level},children:t.textContent},t.id))})})}),No=x.memo(jo),vt=({editor:e,variant:t="content",scrollOver:o=!1})=>{if(!e)return null;const[r,i]=x.useState(null),s=N.useEditorState({editor:e,selector:l=>l.editor.storage.tableOfContents?.content||[]});return x.useRef({}),n.jsx("aside",{className:y("toc-sidebar not-prose ",{"sticky top-20 self-start h-fit":t==="content",relative:t==="line"}),children:n.jsxs("div",{className:y("toc-sidebar-wrapper",{"w-60 p-2 h-full border-l flex flex-col":t==="content","fixed top-1/2 right-4 -translate-y-1/2 z-50":t==="line"}),children:[t==="line"&&n.jsxs("div",{className:"toc-sidebar-inner",children:[n.jsx(No,{items:s,scrollOver:o}),n.jsx(ko,{items:s})]}),t==="content"&&n.jsx(Ct,{items:s,scrollOver:o})]})})},Ao=e=>{const t=x.useRef(null);return x.useLayoutEffect(()=>{t.current=e},[e]),x.useCallback((...o)=>{if(t.current===null)throw new Error("Handler is not assigned");return t.current(...o)},[])};function Mo(e,t){return e/t}function So(e,t){return e<=0||t<=0?0:e/t}const Ze=20,To=600,Ke=400;function Lo({node:e,editor:t,updateAttributes:o,getPos:r}){const{src:i,alt:s,alignment:l,width:a,height:d}=e.attrs,[c,u]=x.useState(!1),p=x.useRef(null),h=x.useRef(null),f=x.useRef(null),b=Ao(v=>{if(!f.current||!h.current)return;v.preventDefault(),v.stopPropagation();const j=p.current?.parentElement?p.current.parentElement.offsetWidth:To,C=v.currentTarget.dataset.direction||"--",w=v.clientX,A=v.clientY,R=f.current.offsetWidth,T=f.current.offsetHeight;let k=R,E=T;const M=C.charAt(1)==="w"?-1:1,L=C.charAt(0)==="n"?-1:1,B=()=>{window.removeEventListener("mousemove",U,{capture:!0}),window.removeEventListener("mouseup",B,{capture:!0});const $=Mo(k,E);o({width:k,height:E,aspectRatio:$})},U=$=>{if(k=Math.max(R+M*($.clientX-w),Ze),E=Math.max(T+L*($.clientY-A),Ze),k>j&&(k=j),E>Ke&&(E=Ke),e.attrs.lockAspectRatio){const _=e.attrs.aspectRatio&&isFinite(e.attrs.aspectRatio)&&e.attrs.aspectRatio>0?e.attrs.aspectRatio:R/T;E=So(k,_)}if(h.current&&(h.current.style.width=`${k}px`,p.current?.setAttribute("data-width",String(k))),!$.buttons)return B()};window.addEventListener("mousemove",U,{capture:!0}),window.addEventListener("mouseup",B,{capture:!0})}),g=a?`${a}px`:"auto";return n.jsx(N.NodeViewWrapper,{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:"tiptap-image transition-all duration-200 select-none","data-align":l,"data-width":a||a,ref:p,children:n.jsx("div",{className:"tiptap-image-container",style:{width:g},ref:h,children:n.jsxs("div",{className:"tiptap-image-content relative",children:[n.jsx("img",{"data-drag-handle":!0,ref:f,contentEditable:!1,draggable:!1,className:"tiptap-image-img cursor-pointer",src:i,alt:s??"",onDragStart:v=>v.preventDefault(),style:{height:"auto",display:"block",userSelect:"none",WebkitUserDrag:"none"}}),c&&n.jsxs(n.Fragment,{children:[n.jsx("div",{onMouseDown:b,"data-direction":"-w",className:"tiptap-image-handle tiptap-image-handle-left"}),n.jsx("div",{onMouseDown:b,"data-direction":"-e",className:"tiptap-image-handle tiptap-image-handle-right"})]})]})})})}const Ro=an.extend({draggable:!0,addAttributes(){return{...this.parent?.(),alignment:{default:"center"},"data-width":{default:0},width:{default:0,parseHTML:e=>{const t=e.getAttribute("data-width")||e.style.width;return t?parseInt(t,10):0},renderHTML:e=>e["data-width"]}}},addNodeView(){return N.ReactNodeViewRenderer(Lo,{className:"not-prose min-h-10",attrs:{"data-placeholder":"Start writing..."}})}}),wt=x.createContext({}),Ho=({onOpenAttachment:e,children:t})=>{const o=x.useMemo(()=>({onOpenAttachment:e}),[e]);return n.jsx(wt.Provider,{value:o,children:t})},Eo=()=>x.useContext(wt),Io=(e,t)=>{const o=`${e??""} ${t??""}`.toLowerCase();return/pdf/.test(o)||/word|document|\.docx?$|\.rtf|\.odt/.test(o)?m.FileText:/sheet|excel|csv|\.xlsx?$|\.ods/.test(o)?m.FileSpreadsheet:/presentation|powerpoint|\.pptx?$|\.odp/.test(o)?m.Presentation:/zip|rar|7z|tar|gzip/.test(o)?m.FileArchive:m.File},Ge="shrink-0 rounded-md p-2 text-muted-foreground hover:bg-[var(--tt-menu-item-hover-bg)] hover:text-foreground",zo=e=>{const t=["B","KB","MB","GB"];let o=e,r=0;for(;o>=1024&&r<t.length-1;)o/=1024,r+=1;return`${o<10&&r>0?o.toFixed(1):Math.round(o)} ${t[r]}`};function Do({node:e,selected:t}){const o=H(),{onOpenAttachment:r}=Eo(),i=e.attrs,{src:s,name:l,size:a,mime:d}=i,c=Io(d,l),u=l??s??"";return n.jsx(N.NodeViewWrapper,{className:"not-prose my-3","data-type":"attachment","data-drag-handle":!0,children:n.jsxs("div",{contentEditable:!1,className:`flex items-center gap-3 rounded-lg border p-3 transition-colors ${t?"border-[var(--tt-menu-item-hover-bg)] bg-[var(--tt-menu-item-hover-bg)]":"border-border hover:bg-[var(--tt-menu-item-hover-bg)]"}`,children:[n.jsx(c,{className:"size-8 shrink-0 text-muted-foreground"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate font-medium text-sm",children:u}),typeof a=="number"&&a>0?n.jsx("div",{className:"text-muted-foreground text-xs",children:zo(a)}):null]}),s?n.jsx("a",{href:s,download:l??void 0,target:"_blank",rel:"noreferrer",title:o.attachment.download,"aria-label":o.attachment.download,className:Ge,children:n.jsx(m.Download,{className:"size-4"})}):i.fileId&&r?n.jsx("button",{type:"button",onClick:()=>r(i),title:o.attachment.download,"aria-label":o.attachment.download,className:Ge,children:n.jsx(m.Download,{className:"size-4"})}):null]})})}const Po=Z.Node.create({name:"attachment",group:"block",atom:!0,draggable:!0,selectable:!0,addAttributes(){return{fileId:{default:null},src:{default:null},name:{default:null},size:{default:null,parseHTML:e=>{const t=e.getAttribute("data-size");return t?Number(t):null}},mime:{default:null}}},parseHTML(){return[{tag:'div[data-type="attachment"]'}]},renderHTML({HTMLAttributes:e}){const{size:t,...o}=e;return["div",Z.mergeAttributes({"data-type":"attachment"},o,t==null?{}:{"data-size":String(t)})]},addNodeView(){return N.ReactNodeViewRenderer(Do)},addCommands(){return{setAttachment:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}}}),Bo=e=>typeof e=="number"&&e>=0;function Vo(e){const t=H(),o=x.useRef(null),[r,i]=x.useState(!1),s=e.extension.options,l=s.maxSize??25*1024*1024,a=async d=>{if(!s.upload){s.onError?.(new Error("[notion-editor] chưa cấu hình `uploadAttachment`."));return}if(d.size>l){s.onError?.(new Error(`[notion-editor] tệp vượt quá ${Math.round(l/1024/1024)}MB.`));return}i(!0);try{const c=await s.upload(d),u=typeof c=="string"?{src:c,fileId:null}:{src:c.src??null,fileId:c.fileId??null},p=e.getPos();if(!Bo(p))return;e.editor.chain().focus().deleteRange({from:p,to:p+1}).insertContentAt(p,{type:"attachment",attrs:{...u,name:d.name,size:d.size,mime:d.type||null}}).run(),s.onSuccess?.(u.src??u.fileId??"")}catch(c){s.onError?.(c instanceof Error?c:new Error(String(c)))}finally{i(!1)}};return n.jsx(N.NodeViewWrapper,{className:"not-prose my-3","data-type":"attachment-upload",children:n.jsxs("div",{contentEditable:!1,children:[n.jsxs("button",{type:"button",disabled:r,onClick:()=>o.current?.click(),className:"flex w-full items-center gap-3 rounded-lg border border-border border-dashed p-4 text-left text-muted-foreground text-sm hover:bg-[var(--tt-menu-item-hover-bg)] disabled:opacity-60",children:[n.jsx(m.Paperclip,{className:"size-5 shrink-0"}),n.jsx("span",{children:r?t.attachment.uploading:t.attachment.clickToUpload})]}),n.jsx("input",{ref:o,type:"file",accept:s.accept,className:"hidden",onChange:d=>{const c=d.target.files?.[0];d.target.value="",c&&a(c)}})]})})}const Oo=N.Node.create({name:"attachmentUpload",group:"block",draggable:!0,selectable:!0,atom:!0,addOptions(){return{accept:void 0,limit:1,maxSize:25*1024*1024,upload:void 0,onError:void 0,onSuccess:void 0,HTMLAttributes:{}}},addAttributes(){return{accept:{default:this.options.accept},limit:{default:this.options.limit},maxSize:{default:this.options.maxSize}}},parseHTML(){return[{tag:'div[data-type="attachment-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",N.mergeAttributes({"data-type":"attachment-upload"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Vo)}});function $o(e){const{state:t,view:o}=e,{doc:r,selection:i}=t,s=D.Selection.findFrom(i.$to,1,!0);if(s)return o.dispatch(t.tr.setSelection(s).scrollIntoView()),!0;const l=t.schema.nodes.paragraph;if(!l)return console.warn("No paragraph node type found in schema."),!1;const a=r.content.size,d=l.create();let c=t.tr.insert(a,d);const u=c.doc.resolve(a+1);return c=c.setSelection(D.TextSelection.near(u)).scrollIntoView(),o.dispatch(c),!0}function qo(e){return typeof e=="number"&&e>=0}const Fo=({maxSize:e,limit:t})=>{const o=H();return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"tiptap-image-upload-dropzone",children:[n.jsx(m.FileImage,{size:50,className:"tiptap-image-upload-dropzone-rect-primary"}),n.jsx("div",{className:"tiptap-image-upload-icon-container",children:n.jsx(m.CloudUploadIcon,{className:"tiptap-image-upload-icon"})})]}),n.jsxs("div",{className:"tiptap-image-upload-content",children:[n.jsxs("span",{className:"tiptap-image-upload-text",children:[n.jsx("em",{children:o.image.clickToUpload})," ",o.image.orDragAndDrop]}),n.jsx("span",{className:"tiptap-image-upload-subtext",children:o.image.limitHint(t,e/1024/1024)})]})]})},Uo=({onFile:e,children:t})=>{const[o,r]=x.useState(!1),[i,s]=x.useState(!1),l=u=>{u.preventDefault(),u.stopPropagation(),s(!0)},a=u=>{u.preventDefault(),u.stopPropagation(),u.currentTarget.contains(u.relatedTarget)||(s(!1),r(!1))},d=u=>{u.preventDefault(),u.stopPropagation(),r(!0)},c=u=>{u.preventDefault(),u.stopPropagation(),s(!1),r(!1);const p=Array.from(u.dataTransfer.files);p.length>0&&e(p)};return n.jsx("div",{className:`tiptap-image-upload-drag-area ${i?"drag-active":""} ${o?"drag-over":""}`,onDragEnter:l,onDragLeave:a,onDragOver:d,onDrop:c,children:t})},_o=({fileItem:e,onRemove:t})=>{const o=r=>{if(r===0)return"0 Bytes";const i=1024,s=["Bytes","KB","MB","GB"],l=Math.floor(Math.log(r)/Math.log(i));return`${parseFloat((r/Math.pow(i,l)).toFixed(2))} ${s[l]}`};return n.jsxs("div",{className:"tiptap-image-upload-preview",children:[e.status==="uploading"&&n.jsx("div",{className:"tiptap-image-upload-progress",style:{width:`${e.progress}%`}}),n.jsxs("div",{className:"tiptap-image-upload-preview-content",children:[n.jsxs("div",{className:"tiptap-image-upload-file-info",children:[n.jsx("div",{className:"tiptap-image-upload-file-icon",children:n.jsx(m.CloudUploadIcon,{})}),n.jsxs("div",{className:"tiptap-image-upload-details",children:[n.jsx("span",{className:"tiptap-image-upload-text",children:e.file.name}),n.jsx("span",{className:"tiptap-image-upload-subtext",children:o(e.file.size)})]})]}),n.jsxs("div",{className:"tiptap-image-upload-actions",children:[e.status==="uploading"&&n.jsxs("span",{className:"tiptap-image-upload-progress-text",children:[e.progress,"%"]}),n.jsx(z,{size:"icon",type:"button",variant:"ghost",onClick:r=>{r.stopPropagation(),t()},children:n.jsx(m.XIcon,{className:"tiptap-button-icon"})})]})]})]})};function Wo(e){const[t,o]=x.useState([]),r=async a=>{if(a.size>e.maxSize){const p=new Error(`File size exceeds maximum allowed (${e.maxSize/1024/1024}MB)`);return e.onError?.(p),null}const d=new AbortController,c=crypto.randomUUID(),u={id:c,file:a,progress:0,status:"uploading",abortController:d};o(p=>[...p,u]);try{if(!e.upload)throw new Error("[notion-editor] chưa cấu hình `uploadImage`, không có chỗ để tải ảnh lên");const p=await e.upload(a,h=>{o(f=>f.map(b=>b.id===c?{...b,progress:h.progress}:b))},d.signal);if(console.log(p),!p)throw new Error("Upload failed: No URL returned");return d.signal.aborted?null:(o(h=>h.map(f=>f.id===c?{...f,status:"success",url:p,progress:100}:f)),e.onSuccess?.(p),p)}catch(p){return d.signal.aborted||(o(h=>h.map(f=>f.id===c?{...f,status:"error",progress:0}:f)),e.onError?.(p instanceof Error?p:new Error("Upload failed"))),null}};return{fileItems:t,uploadFiles:async a=>{if(!a||a.length===0)return e.onError?.(new Error("No files to upload")),[];if(e.limit&&a.length>e.limit)return e.onError?.(new Error(`Maximum ${e.limit} file${e.limit===1?"":"s"} allowed`)),[];const d=a.map(u=>r(u));return(await Promise.all(d)).filter(u=>u!==null)},removeFileItem:a=>{o(d=>{const c=d.find(u=>u.id===a);return c?.abortController&&c.abortController.abort(),c?.url&&URL.revokeObjectURL(c.url),d.filter(u=>u.id!==a)})},clearAllFiles:()=>{t.forEach(a=>{a.abortController&&a.abortController.abort(),a.url&&URL.revokeObjectURL(a.url)}),o([])}}}const Zo=e=>{const t=H(),{accept:o,limit:r,maxSize:i}=e.node.attrs,s=x.useRef(null),l=e.extension,a={maxSize:i,limit:r,accept:o,upload:l.options.upload,onSuccess:l.options.onSuccess,onError:v=>{console.error("[notion-editor] tải ảnh thất bại:",v),l.options.onError?.(v)}},{fileItems:d,uploadFiles:c,removeFileItem:u,clearAllFiles:p}=Wo(a),h=async v=>{const j=await c(v);if(j.length>0){const C=e.getPos();if(qo(C)){const w=j.map((A,R)=>{const T=v[R]?.name.replace(/\.[^/.]+$/,"")||"unknown";return{type:l.options.type,attrs:{src:A,alt:T,title:T}}});e.editor.chain().focus().deleteRange({from:C,to:C+e.node.nodeSize}).insertContentAt(C,w[0]).run(),$o(e.editor)}}},f=v=>{const j=v.target.files;if(!j||j.length===0){l.options.onError?.(new Error("No file selected"));return}h(Array.from(j))},b=()=>{s.current&&d.length===0&&(s.current.value="",s.current.click())},g=d.length>0;return n.jsxs(N.NodeViewWrapper,{className:"tiptap-image-upload py-8",tabIndex:0,onClick:b,children:[!g&&n.jsx(Uo,{onFile:h,children:n.jsx(Fo,{maxSize:i,limit:r})}),g&&n.jsxs("div",{className:"tiptap-image-upload-previews",children:[d.length>1&&n.jsxs("div",{className:"tiptap-image-upload-header",children:[n.jsxs("span",{children:["Uploading ",d.length," files"]}),n.jsx(z,{type:"button",variant:"ghost",onClick:v=>{v.stopPropagation(),p()},children:t.image.clearAll})]}),d.map(v=>n.jsx(_o,{fileItem:v,onRemove:()=>u(v.id)},v.id))]}),n.jsx("input",{ref:s,name:"file",accept:o,type:"file",multiple:r>1,onChange:f,onClick:v=>v.stopPropagation()})]})},Ko=N.Node.create({name:"imageUpload",group:"block",draggable:!0,selectable:!0,atom:!0,addOptions(){return{type:"image",accept:"image/*",limit:1,maxSize:1048576,upload:void 0,onError:void 0,onSuccess:void 0,HTMLAttributes:{}}},addAttributes(){return{accept:{default:this.options.accept},limit:{default:this.options.limit},maxSize:{default:this.options.maxSize}}},parseHTML(){return[{tag:'div[data-type="image-upload"]'}]},renderHTML({HTMLAttributes:e}){return["div",N.mergeAttributes({"data-type":"image-upload"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Zo)},addCommands(){return{setImageUploadNode:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{const{selection:t}=e.state,{nodeAfter:o}=t.$from;if(o&&o.type.name==="imageUpload"&&e.isActive("imageUpload")){const r=e.view.nodeDOM(t.$from.pos);if(r&&r instanceof HTMLElement){const i=r.firstChild;if(i&&i instanceof HTMLElement)return i.click(),!0}}return!1}}}}),Go=re.Table.extend({renderHTML({node:e,HTMLAttributes:t}){const{colgroup:o,tableWidth:r,tableMinWidth:i}=re.createColGroup(e,this.options.cellMinWidth);return["div",{class:y("table-wrapper overflow-x-auto overflow-y-hidden p-4 -ml-4 relative")},"table",Z.mergeAttributes(this.options.HTMLAttributes,t,{style:r?`width: ${r}`:`min-width: ${i}`}),o,["table",0]]},addNodeView(){return({node:e,HTMLAttributes:t})=>{const o=document.createElement("div");o.setAttribute("data-content-type","table");const r=document.createElement("div");r.className=y("table-wrapper overflow-x-auto overflow-y-hidden p-4 -ml-4 relative");const i=document.createElement("div");i.className="table-container";const s=document.createElement("table");Object.entries(this.options.HTMLAttributes).forEach(([p,h])=>{s.setAttribute(p,h)}),Object.entries(t).forEach(([p,h])=>{s.setAttribute(p,h)}),s.style.setProperty(Tn,`${Ee}px`);let l=null;const a=p=>{const{colgroup:h,tableWidth:f,tableMinWidth:b}=re.createColGroup(p,this.options.cellMinWidth),g=de.DOMSerializer.renderSpec(document,h).dom;s.style.width=f??"",s.style.minWidth=f?"":b??"",l?s.replaceChild(g,l):s.prepend(g),l=g};a(e);const d=document.createElement("tbody");s.append(d),i.append(s);const c=document.createElement("div");c.className="table-controls";const u=document.createElement("div");return u.className="table-selection-container",r.append(i,c,u),o.append(r),{dom:o,contentDOM:d,update:p=>p.type!==e.type?!1:(a(p),!0),ignoreMutation:p=>!0}}}}),Xo=Z.Extension.create({name:"custom-table-kit",addExtensions(){return[Go.configure({HTMLAttributes:{class:y("border-collapse w-full not-prose")},lastColumnResizable:!1,allowTableNodeSelection:!0,resizable:!0,cellMinWidth:Ee}),re.TableHeader.extend({addAttributes(){return{...this.parent?.(),background:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.background?{style:`background-color: ${e.background}`}:{}},alignment:{default:"left",parseHTML:e=>e.style.textAlign||"left",renderHTML:e=>e.alignment?{style:`text-align: ${e.alignment}`}:{}},verticalAlign:{default:"top",parseHTML:e=>e.style.verticalAlign||"top",renderHTML:e=>({style:`vertical-align: ${e.verticalAlign}`})}}}}).configure({HTMLAttributes:{class:y("border border-border p-2 text-start font-semibold")}}),re.TableRow,re.TableCell.extend({addAttributes(){return{...this.parent?.(),background:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.background?{style:`background-color: ${e.background}`}:{}},alignment:{default:"left",parseHTML:e=>e.style.textAlign||"left",renderHTML:e=>e.alignment?{style:`text-align: ${e.alignment}`}:{}},verticalAlign:{default:"top",parseHTML:e=>e.style.verticalAlign||"top",renderHTML:e=>({style:`vertical-align: ${e.verticalAlign}`})}}}}).configure({HTMLAttributes:{class:"border border-border p-2"}})]}});function Jo({editor:e}){const t=N.useEditorState({editor:e,selector:o=>o.editor.storage.tableOfContents?.content??[]});return n.jsx(N.NodeViewWrapper,{className:"not-prose my-4 rounded-lg border border-border p-2","data-type":"table-of-contents",children:n.jsx("div",{contentEditable:!1,children:n.jsx(Ct,{items:t,scrollOver:!1})})})}const Yo=Z.Node.create({name:"tableOfContentsNode",group:"block",atom:!0,selectable:!0,draggable:!0,parseHTML(){return[{tag:'div[data-type="table-of-contents"]'}]},renderHTML({HTMLAttributes:e}){return["div",Z.mergeAttributes({"data-type":"table-of-contents"},e)]},addNodeView(){return N.ReactNodeViewRenderer(Jo)}}),Qo=e=>e.type.startsWith("image/");function er({uploadImage:e,uploadAttachment:t}){const o=async(r,i,s)=>{const l=Qo(i),a=l?e:t;if(!a){if(!l){console.error("[notion-editor] chưa cấu hình `uploadAttachment`, bỏ qua tệp:",i.name);return}const d=new FileReader;d.onload=()=>{r.chain().insertContentAt(s,{type:"image",attrs:{src:d.result}}).focus().run()},d.readAsDataURL(i);return}try{const d=await a(i),c=typeof d=="string"?{src:d,fileId:null}:{src:d.src??null,fileId:d.fileId??null};r.chain().insertContentAt(s,l?{type:"image",attrs:{src:c.src}}:{type:"attachment",attrs:{...c,name:i.name,size:i.size,mime:i.type}}).focus().run()}catch(d){console.error("[notion-editor] chèn tệp thất bại:",d)}};return cn.configure({onDrop:(r,i,s)=>{for(const l of i)o(r,l,s)},onPaste:(r,i,s)=>{if(s)return!1;for(const l of i)o(r,l,r.state.selection.anchor)}})}const tr=Z.Extension.create({name:"globalBlockBackground",addGlobalAttributes(){return[{types:["paragraph","heading","bulletList","orderedList","listItem","table","tableCell","tableRow","blockquote"],attributes:{universalBgColor:{default:null,parseHTML:e=>e.style.backgroundColor||null,renderHTML:e=>e.universalBgColor?{style:`
3
3
  background-color: ${e.universalBgColor};
4
4
  width: 100%;
5
5
  padding: 5px 6px;
6
6
  box-sizing: border-box;
7
7
  border-radius: 4px;
8
- `.replace(/\s+/g," ").trim()}:{}}}}]}}),nr=Z.Extension.create({name:"indent",addOptions(){return{types:["paragraph","heading"],minLevel:0,maxLevel:10,indentSize:24}},addGlobalAttributes(){return[{types:this.options.types,attributes:{"data-indent":{default:null,parseHTML:e=>e.hasAttribute("data-indent")?"":null,renderHTML:e=>!e["data-indent-level"]||e["data-indent-level"]<=this.options.minLevel?{}:{"data-indent":""}},"data-indent-level":{default:0,parseHTML:e=>{const t=e.getAttribute("data-indent-level");return t?parseInt(t,10):0},renderHTML:e=>!e["data-indent-level"]||e["data-indent-level"]<=this.options.minLevel?{}:{"data-indent-level":e["data-indent-level"],style:`--tt-indent-level: ${e["data-indent-level"]};`}}}}]},addCommands(){const e=(t,o,r)=>{if(!o)return!0;const{selection:i}=t,{from:s,to:l}=i;let a=!1;return t.doc.nodesBetween(s,l,(d,c)=>{if(this.options.types.includes(d.type.name)){const u=d.attrs["data-indent-level"]||0;let p=u+r;return p<this.options.minLevel&&(p=this.options.minLevel),p>this.options.maxLevel&&(p=this.options.maxLevel),p!==u&&(t.setNodeMarkup(c,void 0,{...d.attrs,"data-indent":p>0?"":null,"data-indent-level":p}),a=!0),!1}return!0}),a&&o(t),a};return{indent:()=>({tr:t,dispatch:o})=>e(t,o,1),outdent:()=>({tr:t,dispatch:o})=>e(t,o,-1)}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.indent(),"Shift-Tab":()=>this.editor.commands.outdent(),Backspace:()=>{const{selection:e}=this.editor.state,{empty:t,$anchor:o}=e;return!t||o.parentOffset!==0||(o.parent.attrs["data-indent-level"]||0)<=this.options.minLevel?!1:this.editor.commands.outdent()}}}}),or=({items:e,onSelectIndex:t})=>{const o=x.useRef(null),r=6,i=32,s=2,l=x.useMemo(()=>{const d=[];for(let c=0;c<e.length;c+=r)d.push(e.slice(c,c+r));return d},[e]),a=dn.useVirtualizer({count:l.length,getScrollElement:()=>o.current,estimateSize:()=>i+s,overscan:5});return n.jsx("div",{ref:o,className:"overflow-y-auto select-none scrollbar-none",style:{height:"260px",width:"202px"},children:n.jsx("div",{className:"w-full relative",style:{height:`${a.getTotalSize()}px`},children:a.getVirtualItems().map(d=>{const c=l[d.index];return n.jsx("div",{"data-index":d.index,className:"absolute top-0 left-0 w-full grid grid-cols-6",style:{height:`${i}px`,gap:`${s}px`,transform:`translateY(${d.start}px)`},children:c.map((u,p)=>{const h=d.index*r+p;return n.jsx(K,{content:u.name,children:n.jsx(z,{variant:"secondary",onClick:()=>t(h),size:"icon",style:{width:`${i}px`,height:`${i}px`},className:"p-0 flex items-center justify-center shrink-0",children:u.emoji?n.jsx("span",{className:"text-base leading-none",children:u.emoji}):n.jsx("img",{className:"w-4 h-4",src:u.fallbackImage,alt:u.name})})},u.name)})},d.key)})})})},yt=x.forwardRef((e,t)=>{const o=H(),{items:r}=e,[i,s]=x.useState(0),l=a=>{const d=e.items[a];d&&e.command({name:d.name})};return x.useEffect(()=>s(0),[e.items]),n.jsx("div",{className:" p-1.5 scrollbar-none overflow-y-scroll bg-card rounded-xl border shadow-2xl min-h-10",children:r.length>0?n.jsx(or,{items:r,selectedIndex:i,onSelectIndex:l}):n.jsx("div",{className:"p-1 text-sm text-muted-foreground ",children:o.emojiPicker.empty})})});yt.displayName="EmojiPicker";const rr={items:({editor:e,query:t})=>e.storage.emoji.emojis.filter(({shortcodes:o,tags:r})=>o.find(i=>i.startsWith(t.toLowerCase()))||r.find(i=>i.startsWith(t.toLowerCase()))),allow:({editor:e})=>!e.isActive("codeBlock"),render:()=>{let e=null,t;const o=i=>{const s=new N.ReactRenderer(yt,{props:i,editor:i.editor});return t=i.mount(s.element),s},r=()=>{t?.(),t=void 0,e?.destroy(),e=null};return{onStart:i=>{try{e=o(i)}catch(s){console.error("[notion-editor] không dựng được menu gợi ý:",s),r()}},onUpdate(i){if(!e){try{e=o(i)}catch(s){console.error("[notion-editor] không dựng lại được menu gợi ý:",s)}return}e.updateProps(i)},onKeyDown(i){return i.event.key==="Escape"?(r(),!0):e?.ref?.onKeyDown(i)??!1},onExit:r}}};je.cva("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]","inline-end":"order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]","block-start":"order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2","block-end":"order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"}},defaultVariants:{align:"inline-start"}});je.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",sm:"","icon-xs":"size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function jt({className:e,...t}){return n.jsx(ue.Command,{"data-slot":"command",className:y("flex size-full flex-col overflow-hidden rounded-xl! bg-popover p-1 text-popover-foreground",e),...t})}function kt({className:e,...t}){return n.jsx(ue.Command.List,{"data-slot":"command-list",className:y("no-scrollbar max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto outline-none",e),...t})}function Nt({className:e,...t}){return n.jsx(ue.Command.Empty,{"data-slot":"command-empty",className:y("py-6 text-center text-sm",e),...t})}function At({className:e,...t}){return n.jsx(ue.Command.Group,{"data-slot":"command-group",className:y("overflow-hidden p-1 text-foreground **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground",e),...t})}function Mt({className:e,children:t,...o}){return n.jsxs(ue.Command.Item,{"data-slot":"command-item",className:y("group/command-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none in-data-[slot=dialog-content]:rounded-lg! data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 hover:bg-[var(--tt-menu-item-hover-bg)] data-[selected=true]:bg-[var(--tt-menu-item-hover-bg)] data-[selected=true]:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[selected=true]:*:[svg]:text-foreground",e),...o,children:[t,n.jsx(m.CheckIcon,{className:"ml-auto opacity-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-data-[checked=true]/command-item:opacity-100"})]})}const St=x.forwardRef((e,t)=>{const o=H(),[r,i]=x.useState(0),s=c=>{const u=e.items[c];u&&e.command(u)},l=()=>{e.items.length!==0&&i((r+e.items.length-1)%e.items.length)},a=()=>{e.items.length!==0&&i((r+1)%e.items.length)},d=()=>{s(r)};return x.useEffect(()=>{i(0)},[e.items]),x.useImperativeHandle(t,()=>({onKeyDown:({event:c})=>c.key==="ArrowUp"?(l(),!0):c.key==="ArrowDown"?(a(),!0):c.key==="Enter"?(d(),!0):!1})),n.jsx(jt,{className:"border shadow-2xl w-55 z-[120]",loop:!0,children:n.jsx(kt,{children:e.loading?n.jsxs("div",{className:"item loading p-2 text-sm text-muted-foreground flex items-center gap-2",children:[n.jsx("span",{className:"loading-dot h-2 w-2 animate-pulse rounded-full bg-foreground"}),"Loading…"]}):e.items.length>0?n.jsx(At,{children:e.items.map((c,u)=>n.jsx(Mt,{value:c.label,className:y("rounded-xl",{"bg-[var(--tt-menu-item-hover-bg)]":u===r}),onSelect:()=>s(u),children:c.label},c.id))}):n.jsx(Nt,{children:o.common.noResults})})})});St.displayName="MentionList";function sr(e){return{items:({query:t})=>e(t),render:()=>{let t;const o=r=>{r.clientRect&&xn({editor:r.editor,element:t.element,clientRect:r.clientRect()})};return{onStart:r=>{t=new N.ReactRenderer(St,{props:r,editor:r.editor}),t.element.style.position="absolute",document.body.appendChild(t.element),o(r)},onUpdate(r){t.updateProps(r),o(r)},onKeyDown(r){return r.event.key==="Escape"?(t.destroy(),!0):t.ref?.onKeyDown(r)??!1},onExit(){t.element.remove(),t.destroy()}}}}}const ir=Z.Extension.create({name:"slash-command",addOptions(){return{suggestion:{char:"/",command:({editor:e,range:t,props:o})=>{o.command({editor:e,range:t})},decorationTag:"Filters",decorationContent:"Filters",decorationClass:"bg-secondary outline-[5.5px] outline-secondary px-px rounded after:text-muted-foreground",decorationEmptyClass:"after:content-[attr(data-decoration-content)]"}}},addProseMirrorPlugins(){return[un({editor:this.editor,...this.options.suggestion})]}}),lr={title:"Table",description:"Add a call to action button to email.",searchTerms:["table","row","cell"],icon:n.jsx(m.Table,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertTable().run()}},ar={title:"Emoji",description:"Add a emoji to make it look good.",searchTerms:["emoji"],icon:n.jsx(m.SmilePlus,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent(":").run()}},cr={title:"Separator",description:"Insert a horizontal dividing line.",searchTerms:["separator","hr","line","divider"],icon:n.jsx(m.Minus,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},dr={title:"Table of Contents",description:"Insert a live outline of your headings.",searchTerms:["toc","table of contents","outline","headings"],icon:n.jsx(m.ListOrdered,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"tableOfContentsNode"}).run()}},ur={title:"Image",description:"Add a to drop zon and upload zone.",searchTerms:["image","img","upload","drop"],icon:n.jsx(m.UploadCloud,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"imageUpload"}).run()}},pr={title:"Attachment",description:"Upload a Word, PDF or spreadsheet file.",searchTerms:["file","attachment","word","pdf","excel","doc","tep","tai lieu"],icon:n.jsx(m.Paperclip,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"attachmentUpload"}).run()}},O=(e,{title:t,description:o})=>({...e,title:t,description:o}),mr=e=>[{title:e.slash.groups.style,commands:[O(at,e.blocks.text),O(ct,e.blocks.heading1),O(dt,e.blocks.heading2),O(ut,e.blocks.heading3),O(pt,e.blocks.bulletList),O(mt,e.blocks.orderedList),O(ft,e.blocks.taskList),O(to,e.blocks.blockquote),O(ht,e.blocks.codeBlock)]},{title:e.slash.groups.insert,commands:[O(ar,e.blocks.emoji),O(lr,e.blocks.table),O(cr,e.blocks.separator),O(dr,e.blocks.tableOfContents)]},{title:e.slash.groups.upload,commands:[O(ur,e.blocks.image),O(pr,e.blocks.attachment)]}],oe=e=>e.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/đ/g,"d").replace(/\s+/g," ").trim(),G={titleExact:120,titlePrefix:100,titleWordPrefix:80,titlePart:60,termPrefix:40,termPart:30,description:20,allTokens:10},fr=(e,t)=>e.startsWith(t)||e.includes(` ${t}`),Tt=(e,t)=>{const o=oe(t);if(!o)return 0;const r=oe(e.title),i=e.description?oe(e.description):"",s=(e.searchTerms??[]).map(oe);if(r===o)return G.titleExact;if(r.startsWith(o))return G.titlePrefix;if(fr(r,o))return G.titleWordPrefix;if(r.includes(o))return G.titlePart;if(s.some(a=>a.startsWith(o)))return G.termPrefix;if(s.some(a=>a.includes(o)))return G.termPart;if(i.includes(o))return G.description;const l=o.split(" ").filter(Boolean);if(l.length>1){const a=[r,i,...s].join(" ");if(l.every(d=>a.includes(d)))return G.allTokens}return-1},hr=(e,t)=>oe(t)?e.map(o=>({...o,commands:o.commands.filter(r=>Tt(r,t)>=0)})).filter(o=>o.commands.length>0):e,gr=(e,t)=>{if(!oe(t))return 0;let o=0,r=-1/0;return e.forEach((i,s)=>{const l=Tt(i,t);l>r&&(r=l,o=s)}),o},xr=({groups:e,onSelectIndex:t})=>{let o=0;return n.jsx("div",{className:"space-y-2",children:e.map(r=>{const i=r.commands,s=o;return o+=i.length,n.jsx(At,{heading:r.title,children:i.map((l,a)=>{const d=s+a;return n.jsxs(Mt,{value:String(d),onSelect:()=>t(d),children:[l.icon,n.jsx("span",{children:l.title})]},l.title)})},r.title)})})},Lt=x.forwardRef((e,t)=>{const o=H(),{items:r,command:i,query:s}=e,[l,a]=x.useState(0),d=x.useMemo(()=>r.flatMap(f=>f.commands),[r]),c=gr(d,s);x.useEffect(()=>{a(c)},[c,s]);const u=x.useRef(null);x.useEffect(()=>{u.current?.querySelector(`[data-value="${l}"]`)?.scrollIntoView({block:"nearest"})},[l]);const p=f=>{const b=d[f];b&&i(b)},h=f=>{const b=d.length;b&&a(g=>(g+f+b)%b)};return x.useImperativeHandle(t,()=>({onKeyDown:({event:f})=>{if(!d.length)return!1;switch(f.key){case"ArrowUp":return h(-1),!0;case"ArrowDown":return h(1),!0;case"Enter":case"Tab":return p(l),!0;default:return!1}}})),n.jsx(jt,{className:"border shadow-2xl w-55 z-120",shouldFilter:!1,value:String(l),onValueChange:f=>a(Number(f)),children:n.jsxs(kt,{ref:u,children:[n.jsx(Nt,{children:o.common.noResults}),n.jsx(xr,{groups:r,onSelectIndex:p})]})})});Lt.displayName="SlashMenu";const br=e=>({decorationTag:"SlashFilter",decorationContent:e.slash.filterHint,decorationClass:"bg-secondary outline-[5.5px] outline-secondary px-px rounded after:text-muted-foreground",decorationEmptyClass:"after:content-[attr(data-decoration-content)]",items:({query:t})=>hr(mr(e),t),allow:({editor:t})=>!t.isActive("codeBlock"),render:()=>{let t=null,o;const r=s=>{const l=new N.ReactRenderer(Lt,{props:s,editor:s.editor,className:"not-prose"});return o=s.mount(l.element),l},i=()=>{o?.(),o=void 0,t?.destroy(),t=null};return{onStart:s=>{try{t=r(s)}catch(l){console.error("[notion-editor] không dựng được menu gợi ý:",l),i()}},onUpdate(s){if(!t){try{t=r(s)}catch(l){console.error("[notion-editor] không dựng lại được menu gợi ý:",l)}return}t.updateProps(s)},onKeyDown(s){return s.event.key==="Escape"?(i(),!0):t?.ref?.onKeyDown(s)??!1},onExit:i}}}),Cr=De.createLowlight(De.all),vr=e=>{if(!e.isEmpty)return!1;let t=!0;return e.state.doc.forEach(o=>{o.isTextblock||(t=!1)}),t},wr=e=>({editor:t,node:o})=>o.type.name==="heading"?e.placeholder.heading(o.attrs.level):vr(t)?e.placeholder.emptyDocument:"";function Rt(e={}){const{extensions:t=[],placeholder:o,uploadImage:r,maxImageSize:i=1048576,uploadAttachment:s,maxAttachmentSize:l=25*1024*1024,mentionSource:a,locale:d=Y}=e,c=ge(d),u=[Kt.Mathematics.configure({inlineOptions:{},blockOptions:{},katexOptions:{}}),sn.configure({types:["heading"]}),Dt,$t,me.TrailingNode,Ro,Po,Oo.configure({limit:1,maxSize:l,upload:s,HTMLAttributes:{}}),Ko.configure({accept:"image/*",limit:1,maxSize:i,upload:r,HTMLAttributes:{}}),Ot.Document,me.UndoRedo,Pt.Bold,_t.Italic,Yt.Strike,rn.Underline,Bt.Code,Qt.Subscript,en.Superscript,Wt.Link.configure({openOnClick:!1,enableClickSelection:!0}),on.TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right","justify"]}),Ft.Highlight.configure({multicolor:!0}),ye.TextStyle,ye.Color,ye.BackgroundColor,ir.configure({suggestion:br(c)}),Jt.Placeholder.configure({placeholder:typeof o=="function"?o:wr(o?{...c,placeholder:{...c.placeholder,emptyDocument:o}}:c),dataAttribute:"placeholder",showOnlyWhenEditable:!0}),qt.configure({levels:[1,2,3]}),Xt,tr,nn,Zt.ListKit.configure({listItem:{HTMLAttributes:{class:"not-prose"}},taskList:{HTMLAttributes:{class:"not-prose"}}}),tn.TableOfContents.configure({getId:()=>ln.v4()}),Yo,me.Gapcursor,me.Dropcursor.configure({class:"transition-all duration-300 ease-out"}),Xo,ze.configure({emojis:ze.gitHubEmojis,enableEmoticons:!0,suggestion:rr}),Ut.configure({HTMLAttributes:{class:"my-custom-divider"}}),nr.configure({types:["paragraph","heading"],indentSize:24}),Vt.configure({lowlight:Cr}),er({uploadImage:r,uploadAttachment:s})];return a&&u.push(Gt.Mention.configure({HTMLAttributes:{class:"mention"},suggestion:sr(a)})),[...u,...t]}const yr="notion-editor prose relative dark:prose-invert prose-hr:border-border prose-blockquote:border-l-foreground prose-h1:text-2xl prose-h2:text-xl prose-h3:text-lg prose-pre:bg-popover prose-pre:border prose-pre:border-border prose-pre:text-muted-foreground marker:text-foreground prose-a:text-blue-600 prose-a:hover:text-blue-500 prose-headings:text-inherit focus:outline-none py-10";function jr({content:e,onChange:t,onReady:o,editable:r=!0,showToc:i=!0,tocVariant:s="line",onOpenAttachment:l,onReplaceImage:a,className:d,editorClassName:c,locale:u=Y,autofocus:p=!1,ref:h,...f}){const b=x.useRef(t);b.current=t;const g=x.useRef(o);g.current=o;const{extensions:v,blocks:j,placeholder:C,uploadImage:w,maxImageSize:A,uploadAttachment:R,maxAttachmentSize:T,mentionSource:k}=f,E=x.useMemo(()=>Rt({extensions:v,placeholder:C,uploadImage:w,maxImageSize:A,uploadAttachment:R,maxAttachmentSize:T,mentionSource:k,locale:u}),[v,j,C,w,A,R,T,k,u]),M=x.useMemo(()=>({attributes:{class:y(yr,c)}}),[c]),L=N.useEditor({immediatelyRender:!1,extensions:E,content:e,editable:r,autofocus:p,editorProps:M,onUpdate:({editor:B})=>{b.current?.(B.getJSON(),B)},onCreate:({editor:B})=>{g.current?.(B)}});return x.useEffect(()=>{L&&L.isEditable!==r&&L.setEditable(r)},[L,r]),x.useImperativeHandle(h,()=>({editor:L,getJSON:()=>L?.getJSON()??null,getHTML:()=>L?.getHTML()??"",setContent:B=>L?.commands.setContent(B,{emitUpdate:!1}),focus:()=>L?.commands.focus()}),[L]),L?n.jsx(Vn,{locale:u,children:n.jsx(Ho,{onOpenAttachment:l,children:n.jsx(Cn,{children:n.jsx(N.EditorContext.Provider,{value:{editor:L},children:n.jsx("div",{className:y("notion-like-editor-wrapper",d),children:n.jsxs("div",{className:"notion-like-editor-layout",children:[n.jsx(N.EditorContent,{className:"notion-like-editor-content",editor:L}),r?n.jsxs(n.Fragment,{children:[n.jsx(it,{editor:L}),n.jsx(bt,{editor:L}),n.jsx(gt,{editor:L}),n.jsx(lt,{editor:L,onReplaceClick:a??(()=>{})})]}):null,i?n.jsx(vt,{editor:L,variant:s}):null]})})})})})}):null}const kr=new Set(["image","attachment"]);function Nr(e){const t=new Set,o=r=>{if(r){if(r.type&&kr.has(r.type)){const i=r.attrs?.src;typeof i=="string"&&i&&!i.startsWith("data:")&&t.add(i)}r.content?.forEach(o)}};return o(e??void 0),[...t]}exports.DEFAULT_LOCALE=Y;exports.Draggable=it;exports.ImageBubbleMenu=lt;exports.MyBubbleMenu=gt;exports.NotionEditor=jr;exports.TableHandle=bt;exports.TocSidebar=vt;exports.collectFileUrls=Nr;exports.en=et;exports.extensions=Rt;exports.getMessages=ge;exports.vi=Qe;
8
+ `.replace(/\s+/g," ").trim()}:{}}}}]}}),nr=Z.Extension.create({name:"indent",addOptions(){return{types:["paragraph","heading"],minLevel:0,maxLevel:10,indentSize:24}},addGlobalAttributes(){return[{types:this.options.types,attributes:{"data-indent":{default:null,parseHTML:e=>e.hasAttribute("data-indent")?"":null,renderHTML:e=>!e["data-indent-level"]||e["data-indent-level"]<=this.options.minLevel?{}:{"data-indent":""}},"data-indent-level":{default:0,parseHTML:e=>{const t=e.getAttribute("data-indent-level");return t?parseInt(t,10):0},renderHTML:e=>!e["data-indent-level"]||e["data-indent-level"]<=this.options.minLevel?{}:{"data-indent-level":e["data-indent-level"],style:`--tt-indent-level: ${e["data-indent-level"]};`}}}}]},addCommands(){const e=(t,o,r)=>{if(!o)return!0;const{selection:i}=t,{from:s,to:l}=i;let a=!1;return t.doc.nodesBetween(s,l,(d,c)=>{if(this.options.types.includes(d.type.name)){const u=d.attrs["data-indent-level"]||0;let p=u+r;return p<this.options.minLevel&&(p=this.options.minLevel),p>this.options.maxLevel&&(p=this.options.maxLevel),p!==u&&(t.setNodeMarkup(c,void 0,{...d.attrs,"data-indent":p>0?"":null,"data-indent-level":p}),a=!0),!1}return!0}),a&&o(t),a};return{indent:()=>({tr:t,dispatch:o})=>e(t,o,1),outdent:()=>({tr:t,dispatch:o})=>e(t,o,-1)}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.indent(),"Shift-Tab":()=>this.editor.commands.outdent(),Backspace:()=>{const{selection:e}=this.editor.state,{empty:t,$anchor:o}=e;return!t||o.parentOffset!==0||(o.parent.attrs["data-indent-level"]||0)<=this.options.minLevel?!1:this.editor.commands.outdent()}}}}),or=({items:e,onSelectIndex:t})=>{const o=x.useRef(null),r=6,i=32,s=2,l=x.useMemo(()=>{const d=[];for(let c=0;c<e.length;c+=r)d.push(e.slice(c,c+r));return d},[e]),a=dn.useVirtualizer({count:l.length,getScrollElement:()=>o.current,estimateSize:()=>i+s,overscan:5});return n.jsx("div",{ref:o,className:"overflow-y-auto select-none scrollbar-none",style:{height:"260px",width:"202px"},children:n.jsx("div",{className:"w-full relative",style:{height:`${a.getTotalSize()}px`},children:a.getVirtualItems().map(d=>{const c=l[d.index];return n.jsx("div",{"data-index":d.index,className:"absolute top-0 left-0 w-full grid grid-cols-6",style:{height:`${i}px`,gap:`${s}px`,transform:`translateY(${d.start}px)`},children:c.map((u,p)=>{const h=d.index*r+p;return n.jsx(K,{content:u.name,children:n.jsx(z,{variant:"secondary",onClick:()=>t(h),size:"icon",style:{width:`${i}px`,height:`${i}px`},className:"p-0 flex items-center justify-center shrink-0",children:u.emoji?n.jsx("span",{className:"text-base leading-none",children:u.emoji}):n.jsx("img",{className:"w-4 h-4",src:u.fallbackImage,alt:u.name})})},u.name)})},d.key)})})})},yt=x.forwardRef((e,t)=>{const o=H(),{items:r}=e,[i,s]=x.useState(0),l=a=>{const d=e.items[a];d&&e.command({name:d.name})};return x.useEffect(()=>s(0),[e.items]),n.jsx("div",{className:" p-1.5 scrollbar-none overflow-y-scroll bg-card rounded-xl border shadow-2xl min-h-10",children:r.length>0?n.jsx(or,{items:r,selectedIndex:i,onSelectIndex:l}):n.jsx("div",{className:"p-1 text-sm text-muted-foreground ",children:o.emojiPicker.empty})})});yt.displayName="EmojiPicker";const rr={items:({editor:e,query:t})=>e.storage.emoji.emojis.filter(({shortcodes:o,tags:r})=>o.find(i=>i.startsWith(t.toLowerCase()))||r.find(i=>i.startsWith(t.toLowerCase()))),allow:({editor:e})=>!e.isActive("codeBlock"),render:()=>{let e=null,t;const o=i=>{const s=new N.ReactRenderer(yt,{props:i,editor:i.editor});return t=i.mount(s.element),s},r=()=>{t?.(),t=void 0,e?.destroy(),e=null};return{onStart:i=>{try{e=o(i)}catch(s){console.error("[notion-editor] không dựng được menu gợi ý:",s),r()}},onUpdate(i){if(!e){try{e=o(i)}catch(s){console.error("[notion-editor] không dựng lại được menu gợi ý:",s)}return}e.updateProps(i)},onKeyDown(i){return i.event.key==="Escape"?(r(),!0):e?.ref?.onKeyDown(i)??!1},onExit:r}}};je.cva("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]","inline-end":"order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]","block-start":"order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2","block-end":"order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"}},defaultVariants:{align:"inline-start"}});je.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",sm:"","icon-xs":"size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function jt({className:e,...t}){return n.jsx(ue.Command,{"data-slot":"command",className:y("flex size-full flex-col overflow-hidden rounded-xl! bg-popover p-1 text-popover-foreground",e),...t})}function kt({className:e,...t}){return n.jsx(ue.Command.List,{"data-slot":"command-list",className:y("no-scrollbar max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto outline-none",e),...t})}function Nt({className:e,...t}){return n.jsx(ue.Command.Empty,{"data-slot":"command-empty",className:y("py-6 text-center text-sm",e),...t})}function At({className:e,...t}){return n.jsx(ue.Command.Group,{"data-slot":"command-group",className:y("overflow-hidden p-1 text-foreground **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground",e),...t})}function Mt({className:e,children:t,...o}){return n.jsxs(ue.Command.Item,{"data-slot":"command-item",className:y("group/command-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none in-data-[slot=dialog-content]:rounded-lg! data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 hover:bg-[var(--tt-menu-item-hover-bg)] data-[selected=true]:bg-[var(--tt-menu-item-hover-bg)] data-[selected=true]:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[selected=true]:*:[svg]:text-foreground",e),...o,children:[t,n.jsx(m.CheckIcon,{className:"ml-auto opacity-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-data-[checked=true]/command-item:opacity-100"})]})}const St=x.forwardRef((e,t)=>{const o=H(),[r,i]=x.useState(0),s=c=>{const u=e.items[c];u&&e.command(u)},l=()=>{e.items.length!==0&&i((r+e.items.length-1)%e.items.length)},a=()=>{e.items.length!==0&&i((r+1)%e.items.length)},d=()=>{s(r)};return x.useEffect(()=>{i(0)},[e.items]),x.useImperativeHandle(t,()=>({onKeyDown:({event:c})=>c.key==="ArrowUp"?(l(),!0):c.key==="ArrowDown"?(a(),!0):c.key==="Enter"?(d(),!0):!1})),n.jsx(jt,{className:"border shadow-2xl w-55 z-(--notion-editor-z-menu)",loop:!0,children:n.jsx(kt,{children:e.loading?n.jsxs("div",{className:"item loading p-2 text-sm text-muted-foreground flex items-center gap-2",children:[n.jsx("span",{className:"loading-dot h-2 w-2 animate-pulse rounded-full bg-foreground"}),"Loading…"]}):e.items.length>0?n.jsx(At,{children:e.items.map((c,u)=>n.jsx(Mt,{value:c.label,className:y("rounded-xl",{"bg-[var(--tt-menu-item-hover-bg)]":u===r}),onSelect:()=>s(u),children:c.label},c.id))}):n.jsx(Nt,{children:o.common.noResults})})})});St.displayName="MentionList";function sr(e){return{items:({query:t})=>e(t),render:()=>{let t;const o=r=>{r.clientRect&&xn({editor:r.editor,element:t.element,clientRect:r.clientRect()})};return{onStart:r=>{t=new N.ReactRenderer(St,{props:r,editor:r.editor}),t.element.style.position="absolute",document.body.appendChild(t.element),o(r)},onUpdate(r){t.updateProps(r),o(r)},onKeyDown(r){return r.event.key==="Escape"?(t.destroy(),!0):t.ref?.onKeyDown(r)??!1},onExit(){t.element.remove(),t.destroy()}}}}}const ir=Z.Extension.create({name:"slash-command",addOptions(){return{suggestion:{char:"/",command:({editor:e,range:t,props:o})=>{o.command({editor:e,range:t})},decorationTag:"Filters",decorationContent:"Filters",decorationClass:"bg-secondary outline-[5.5px] outline-secondary px-px rounded after:text-muted-foreground",decorationEmptyClass:"after:content-[attr(data-decoration-content)]"}}},addProseMirrorPlugins(){return[un({editor:this.editor,...this.options.suggestion})]}}),lr={title:"Table",description:"Add a call to action button to email.",searchTerms:["table","row","cell"],icon:n.jsx(m.Table,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertTable().run()}},ar={title:"Emoji",description:"Add a emoji to make it look good.",searchTerms:["emoji"],icon:n.jsx(m.SmilePlus,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent(":").run()}},cr={title:"Separator",description:"Insert a horizontal dividing line.",searchTerms:["separator","hr","line","divider"],icon:n.jsx(m.Minus,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},dr={title:"Table of Contents",description:"Insert a live outline of your headings.",searchTerms:["toc","table of contents","outline","headings"],icon:n.jsx(m.ListOrdered,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"tableOfContentsNode"}).run()}},ur={title:"Image",description:"Add a to drop zon and upload zone.",searchTerms:["image","img","upload","drop"],icon:n.jsx(m.UploadCloud,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"imageUpload"}).run()}},pr={title:"Attachment",description:"Upload a Word, PDF or spreadsheet file.",searchTerms:["file","attachment","word","pdf","excel","doc","tep","tai lieu"],icon:n.jsx(m.Paperclip,{}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).insertContent({type:"attachmentUpload"}).run()}},O=(e,{title:t,description:o})=>({...e,title:t,description:o}),mr=e=>[{title:e.slash.groups.style,commands:[O(at,e.blocks.text),O(ct,e.blocks.heading1),O(dt,e.blocks.heading2),O(ut,e.blocks.heading3),O(pt,e.blocks.bulletList),O(mt,e.blocks.orderedList),O(ft,e.blocks.taskList),O(to,e.blocks.blockquote),O(ht,e.blocks.codeBlock)]},{title:e.slash.groups.insert,commands:[O(ar,e.blocks.emoji),O(lr,e.blocks.table),O(cr,e.blocks.separator),O(dr,e.blocks.tableOfContents)]},{title:e.slash.groups.upload,commands:[O(ur,e.blocks.image),O(pr,e.blocks.attachment)]}],oe=e=>e.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/đ/g,"d").replace(/\s+/g," ").trim(),G={titleExact:120,titlePrefix:100,titleWordPrefix:80,titlePart:60,termPrefix:40,termPart:30,description:20,allTokens:10},fr=(e,t)=>e.startsWith(t)||e.includes(` ${t}`),Tt=(e,t)=>{const o=oe(t);if(!o)return 0;const r=oe(e.title),i=e.description?oe(e.description):"",s=(e.searchTerms??[]).map(oe);if(r===o)return G.titleExact;if(r.startsWith(o))return G.titlePrefix;if(fr(r,o))return G.titleWordPrefix;if(r.includes(o))return G.titlePart;if(s.some(a=>a.startsWith(o)))return G.termPrefix;if(s.some(a=>a.includes(o)))return G.termPart;if(i.includes(o))return G.description;const l=o.split(" ").filter(Boolean);if(l.length>1){const a=[r,i,...s].join(" ");if(l.every(d=>a.includes(d)))return G.allTokens}return-1},hr=(e,t)=>oe(t)?e.map(o=>({...o,commands:o.commands.filter(r=>Tt(r,t)>=0)})).filter(o=>o.commands.length>0):e,gr=(e,t)=>{if(!oe(t))return 0;let o=0,r=-1/0;return e.forEach((i,s)=>{const l=Tt(i,t);l>r&&(r=l,o=s)}),o},xr=({groups:e,onSelectIndex:t})=>{let o=0;return n.jsx("div",{className:"space-y-2",children:e.map(r=>{const i=r.commands,s=o;return o+=i.length,n.jsx(At,{heading:r.title,children:i.map((l,a)=>{const d=s+a;return n.jsxs(Mt,{value:String(d),onSelect:()=>t(d),children:[l.icon,n.jsx("span",{children:l.title})]},l.title)})},r.title)})})},Lt=x.forwardRef((e,t)=>{const o=H(),{items:r,command:i,query:s}=e,[l,a]=x.useState(0),d=x.useMemo(()=>r.flatMap(f=>f.commands),[r]),c=gr(d,s);x.useEffect(()=>{a(c)},[c,s]);const u=x.useRef(null);x.useEffect(()=>{u.current?.querySelector(`[data-value="${l}"]`)?.scrollIntoView({block:"nearest"})},[l]);const p=f=>{const b=d[f];b&&i(b)},h=f=>{const b=d.length;b&&a(g=>(g+f+b)%b)};return x.useImperativeHandle(t,()=>({onKeyDown:({event:f})=>{if(!d.length)return!1;switch(f.key){case"ArrowUp":return h(-1),!0;case"ArrowDown":return h(1),!0;case"Enter":case"Tab":return p(l),!0;default:return!1}}})),n.jsx(jt,{className:"border shadow-2xl w-55 z-(--notion-editor-z-menu)",shouldFilter:!1,value:String(l),onValueChange:f=>a(Number(f)),children:n.jsxs(kt,{ref:u,children:[n.jsx(Nt,{children:o.common.noResults}),n.jsx(xr,{groups:r,onSelectIndex:p})]})})});Lt.displayName="SlashMenu";const br=e=>({decorationTag:"SlashFilter",decorationContent:e.slash.filterHint,decorationClass:"bg-secondary outline-[5.5px] outline-secondary px-px rounded after:text-muted-foreground",decorationEmptyClass:"after:content-[attr(data-decoration-content)]",items:({query:t})=>hr(mr(e),t),allow:({editor:t})=>!t.isActive("codeBlock"),render:()=>{let t=null,o;const r=s=>{const l=new N.ReactRenderer(Lt,{props:s,editor:s.editor,className:"not-prose"});return o=s.mount(l.element),l},i=()=>{o?.(),o=void 0,t?.destroy(),t=null};return{onStart:s=>{try{t=r(s)}catch(l){console.error("[notion-editor] không dựng được menu gợi ý:",l),i()}},onUpdate(s){if(!t){try{t=r(s)}catch(l){console.error("[notion-editor] không dựng lại được menu gợi ý:",l)}return}t.updateProps(s)},onKeyDown(s){return s.event.key==="Escape"?(i(),!0):t?.ref?.onKeyDown(s)??!1},onExit:i}}}),Cr=De.createLowlight(De.all),vr=e=>{if(!e.isEmpty)return!1;let t=!0;return e.state.doc.forEach(o=>{o.isTextblock||(t=!1)}),t},wr=e=>({editor:t,node:o})=>o.type.name==="heading"?e.placeholder.heading(o.attrs.level):vr(t)?e.placeholder.emptyDocument:"";function Rt(e={}){const{extensions:t=[],placeholder:o,uploadImage:r,maxImageSize:i=1048576,uploadAttachment:s,maxAttachmentSize:l=25*1024*1024,mentionSource:a,locale:d=Y}=e,c=ge(d),u=[Kt.Mathematics.configure({inlineOptions:{},blockOptions:{},katexOptions:{}}),sn.configure({types:["heading"]}),Dt,$t,me.TrailingNode,Ro,Po,Oo.configure({limit:1,maxSize:l,upload:s,HTMLAttributes:{}}),Ko.configure({accept:"image/*",limit:1,maxSize:i,upload:r,HTMLAttributes:{}}),Ot.Document,me.UndoRedo,Pt.Bold,_t.Italic,Yt.Strike,rn.Underline,Bt.Code,Qt.Subscript,en.Superscript,Wt.Link.configure({openOnClick:!1,enableClickSelection:!0}),on.TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right","justify"]}),Ft.Highlight.configure({multicolor:!0}),ye.TextStyle,ye.Color,ye.BackgroundColor,ir.configure({suggestion:br(c)}),Jt.Placeholder.configure({placeholder:typeof o=="function"?o:wr(o?{...c,placeholder:{...c.placeholder,emptyDocument:o}}:c),dataAttribute:"placeholder",showOnlyWhenEditable:!0}),qt.configure({levels:[1,2,3]}),Xt,tr,nn,Zt.ListKit.configure({listItem:{HTMLAttributes:{class:"not-prose"}},taskList:{HTMLAttributes:{class:"not-prose"}}}),tn.TableOfContents.configure({getId:()=>ln.v4()}),Yo,me.Gapcursor,me.Dropcursor.configure({class:"transition-all duration-300 ease-out"}),Xo,ze.configure({emojis:ze.gitHubEmojis,enableEmoticons:!0,suggestion:rr}),Ut.configure({HTMLAttributes:{class:"my-custom-divider"}}),nr.configure({types:["paragraph","heading"],indentSize:24}),Vt.configure({lowlight:Cr}),er({uploadImage:r,uploadAttachment:s})];return a&&u.push(Gt.Mention.configure({HTMLAttributes:{class:"mention"},suggestion:sr(a)})),[...u,...t]}const yr="notion-editor prose relative dark:prose-invert prose-hr:border-border prose-blockquote:border-l-foreground prose-h1:text-2xl prose-h2:text-xl prose-h3:text-lg prose-pre:bg-popover prose-pre:border prose-pre:border-border prose-pre:text-muted-foreground marker:text-foreground prose-a:text-blue-600 prose-a:hover:text-blue-500 prose-headings:text-inherit focus:outline-none py-10";function jr({content:e,onChange:t,onReady:o,editable:r=!0,showToc:i=!0,tocVariant:s="line",onOpenAttachment:l,onReplaceImage:a,className:d,editorClassName:c,locale:u=Y,autofocus:p=!1,ref:h,...f}){const b=x.useRef(t);b.current=t;const g=x.useRef(o);g.current=o;const{extensions:v,blocks:j,placeholder:C,uploadImage:w,maxImageSize:A,uploadAttachment:R,maxAttachmentSize:T,mentionSource:k}=f,E=x.useMemo(()=>Rt({extensions:v,placeholder:C,uploadImage:w,maxImageSize:A,uploadAttachment:R,maxAttachmentSize:T,mentionSource:k,locale:u}),[v,j,C,w,A,R,T,k,u]),M=x.useMemo(()=>({attributes:{class:y(yr,c)}}),[c]),L=N.useEditor({immediatelyRender:!1,extensions:E,content:e,editable:r,autofocus:p,editorProps:M,onUpdate:({editor:B})=>{b.current?.(B.getJSON(),B)},onCreate:({editor:B})=>{g.current?.(B)}});return x.useEffect(()=>{L&&L.isEditable!==r&&L.setEditable(r)},[L,r]),x.useImperativeHandle(h,()=>({editor:L,getJSON:()=>L?.getJSON()??null,getHTML:()=>L?.getHTML()??"",setContent:B=>L?.commands.setContent(B,{emitUpdate:!1}),focus:()=>L?.commands.focus()}),[L]),L?n.jsx(Vn,{locale:u,children:n.jsx(Ho,{onOpenAttachment:l,children:n.jsx(Cn,{children:n.jsx(N.EditorContext.Provider,{value:{editor:L},children:n.jsx("div",{className:y("notion-like-editor-wrapper",d),children:n.jsxs("div",{className:"notion-like-editor-layout",children:[n.jsx(N.EditorContent,{className:"notion-like-editor-content",editor:L}),r?n.jsxs(n.Fragment,{children:[n.jsx(it,{editor:L}),n.jsx(bt,{editor:L}),n.jsx(gt,{editor:L}),n.jsx(lt,{editor:L,onReplaceClick:a??(()=>{})})]}):null,i?n.jsx(vt,{editor:L,variant:s}):null]})})})})})}):null}const kr=new Set(["image","attachment"]);function Nr(e){const t=new Set,o=r=>{if(r){if(r.type&&kr.has(r.type)){const i=r.attrs?.src;typeof i=="string"&&i&&!i.startsWith("data:")&&t.add(i)}r.content?.forEach(o)}};return o(e??void 0),[...t]}exports.DEFAULT_LOCALE=Y;exports.Draggable=it;exports.ImageBubbleMenu=lt;exports.MyBubbleMenu=gt;exports.NotionEditor=jr;exports.TableHandle=bt;exports.TocSidebar=vt;exports.collectFileUrls=Nr;exports.en=et;exports.extensions=Rt;exports.getMessages=ge;exports.vi=Qe;
9
9
  //# sourceMappingURL=index.cjs.map