UNPKG

@blocknote/react

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

1 lines 89.8 kB
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./defaultCommentEditorSchema-Cow33c_f.cjs`),t=require(`./FloatingThreadController-BDiAihkl.cjs`),n=require(`./FloatingComposerController-B4zPPPwD.cjs`);let r=require(`react`);r=e.v(r,1);let i=require(`@blocknote/core/comments`),a=require(`@blocknote/core/extensions`),o=require(`@floating-ui/react`),s=require(`@blocknote/core`),c=require(`react/jsx-runtime`),l=require(`@tiptap/core`),u=require(`react-icons/ri`),d=require(`react-icons/ai`),f=require(`react-icons/md`),p=require(`react-dom`),m=require(`@tiptap/react`),h=require(`react-dom/client`),g=require(`react-icons/tb`);var _=t=>{let{blockId:n,children:i,portalElement:a,...o}=t,l=e.m();return(0,c.jsx)(e.u,{reference:(0,r.useMemo)(()=>l.transact(e=>{if(!n)return;let t=(0,s.getNodeById)(n,e.doc);if(!t)return;let{node:r}=l.prosemirrorView.domAtPos(t.posBeforeNode+1);if(r instanceof Element)return{element:r}}),[l,n]),portalElement:a,...o,children:n!==void 0&&i})},v=t=>{let n=e.l(),i=e.s(),a=e.m(),o=a.getBlock(t.blockId),[l,u]=(0,r.useState)(``),d=(0,r.useCallback)(e=>{u(e.currentTarget.value)},[]),f=(0,r.useCallback)(e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),a.updateBlock(o.id,{props:{name:(0,s.filenameFromURL)(l),url:l}}))},[a,o.id,l]),p=(0,r.useCallback)(()=>{a.updateBlock(o.id,{props:{name:(0,s.filenameFromURL)(l),url:l}})},[a,o.id,l]);return(0,c.jsxs)(n.FilePanel.TabPanel,{className:`bn-tab-panel`,children:[(0,c.jsx)(n.FilePanel.TextInput,{className:`bn-text-input`,placeholder:i.file_panel.embed.url_placeholder,value:l,onChange:d,onKeyDown:f,"data-test":`embed-input`}),(0,c.jsx)(n.FilePanel.Button,{className:`bn-button`,onClick:p,"data-test":`embed-input-button`,children:i.file_panel.embed.embed_button[o.type]||i.file_panel.embed.embed_button.file})]})},y=t=>{let n=e.l(),i=e.s(),{setLoading:a}=t,o=e.m(),s=o.getBlock(t.blockId),[l,u]=(0,r.useState)(!1);(0,r.useEffect)(()=>{l&&setTimeout(()=>{u(!1)},3e3)},[l]);let d=(0,r.useCallback)(e=>{if(e===null)return;async function n(e){if(a(!0),o.uploadFile!==void 0)try{let n=await o.uploadFile(e,t.blockId);typeof n==`string`&&(n={props:{name:e.name,url:n}}),o.updateBlock(t.blockId,n)}catch{u(!0)}finally{a(!1)}}n(e)},[t.blockId,o,a]),f=o.schema.blockSpecs[s.type],p=f.implementation.meta?.fileBlockAccept?.length?f.implementation.meta.fileBlockAccept.join(`,`):`*/*`;return(0,c.jsxs)(n.FilePanel.TabPanel,{className:`bn-tab-panel`,children:[(0,c.jsx)(n.FilePanel.FileInput,{className:`bn-file-input`,"data-test":`upload-input`,accept:p,placeholder:i.file_panel.upload.file_placeholder[s.type]||i.file_panel.upload.file_placeholder.file,value:null,onChange:d}),l&&(0,c.jsx)(`div`,{className:`bn-error-text`,children:i.file_panel.upload.upload_error})]})},b=t=>{let n=e.l(),i=e.s(),a=e.m(),[o,s]=(0,r.useState)(!1),l=t.tabs??[...a.uploadFile===void 0?[]:[{name:i.file_panel.upload.title,tabPanel:(0,c.jsx)(y,{blockId:t.blockId,setLoading:s})}],{name:i.file_panel.embed.title,tabPanel:(0,c.jsx)(v,{blockId:t.blockId})}],[u,d]=(0,r.useState)(t.defaultOpenTab||l[0].name);return(0,c.jsx)(n.FilePanel.Root,{className:`bn-panel`,defaultOpenTab:u,openTab:u,setOpenTab:d,tabs:l,loading:o})},x=t=>{let n=e.m(),i=e.f(a.FilePanelExtension),s=e.p(a.FilePanelExtension),l=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:!!s,onOpenChange:(e,t,r)=>{e||i.closeMenu(),r===`escape-key`&&n.focus()},middleware:[(0,o.offset)(10),(0,o.flip)()],...t.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:90},...t.floatingUIOptions?.elementProps}}),[s,n,i,t.floatingUIOptions]),u=t.filePanel||b;return(0,c.jsx)(_,{blockId:s,portalElement:t.portalElement,...l,children:s&&(0,c.jsx)(u,{blockId:s})})},S={bold:u.RiBold,italic:u.RiItalic,underline:u.RiUnderline,strike:u.RiStrikethrough,code:u.RiCodeFill};function ee(e,t){return e in t.schema.styleSchema&&t.schema.styleSchema[e].type===e&&t.schema.styleSchema[e].propSchema===`boolean`}var C=t=>{let n=e.s(),i=e.l(),a=e.m(),o=e.o({editor:a,selector:({editor:e})=>{if(!(!e.isEditable||!ee(t.basicTextStyle,e)||!(e.getSelection()?.blocks||[e.getTextCursorPosition().block]).find(e=>e.content!==void 0)))return t.basicTextStyle in e.getActiveStyles()?{active:!0}:{active:!1}}}),l=(0,r.useCallback)(e=>{a.focus(),a.toggleStyles({[e]:!0})},[a,t]);if(o===void 0)return null;let u=S[t.basicTextStyle];return(0,c.jsx)(i.FormattingToolbar.Button,{className:`bn-button`,"data-test":t.basicTextStyle,onClick:()=>l(t.basicTextStyle),isSelected:o.active,label:n.formatting_toolbar[t.basicTextStyle].tooltip,mainTooltip:n.formatting_toolbar[t.basicTextStyle].tooltip,secondaryTooltip:(0,s.formatKeyboardShortcut)(n.formatting_toolbar[t.basicTextStyle].secondary_tooltip,n.generic.ctrl_shortcut),icon:(0,c.jsx)(u,{})})},w=e=>{let t=e.textColor||`default`,n=e.backgroundColor||`default`,i=e.size||16;return(0,c.jsx)(`div`,{className:`bn-color-icon`,"data-background-color":n,"data-text-color":t,style:(0,r.useMemo)(()=>({pointerEvents:`none`,fontSize:(i*.75).toString()+`px`,height:i.toString()+`px`,lineHeight:i.toString()+`px`,textAlign:`center`,width:i.toString()+`px`}),[i]),children:`A`})},T=[`default`,`gray`,`brown`,`red`,`orange`,`yellow`,`green`,`blue`,`purple`,`pink`],E=t=>{let n=e.l(),r=e.s();return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(()=>t.text?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.Generic.Menu.Label,{children:r.color_picker.text_title}),T.map(e=>(0,c.jsx)(n.Generic.Menu.Item,{onClick:()=>{t.onClick&&t.onClick(),t.text.setColor(e)},"data-test":`text-color-`+e,icon:(0,c.jsx)(w,{textColor:e,size:t.iconSize}),checked:t.text.color===e,children:r.color_picker.colors[e]},`text-color-`+e))]}):null,{}),(0,c.jsx)(()=>t.background?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.Generic.Menu.Label,{children:r.color_picker.background_title}),T.map(e=>(0,c.jsx)(n.Generic.Menu.Item,{onClick:()=>{t.onClick&&t.onClick(),t.background.setColor(e)},"data-test":`background-color-`+e,icon:(0,c.jsx)(w,{backgroundColor:e,size:t.iconSize}),checked:t.background.color===e,children:r.color_picker.colors[e]},`background-color-`+e))]}):null,{})]})};function D(e,t){return`${e}Color`in t.schema.styleSchema&&t.schema.styleSchema[`${e}Color`].type===`${e}Color`&&t.schema.styleSchema[`${e}Color`].propSchema===`string`}var O=()=>{let t=e.l(),n=e.s(),i=e.m(),a=D(`text`,i),o=D(`background`,i),s=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable||!(e.getSelection()?.blocks||[e.getTextCursorPosition().block]).find(e=>e.content!==void 0))return;let t=D(`text`,e),n=D(`background`,e);if(!(!t&&!n))return{textColor:t?e.getActiveStyles().textColor||`default`:void 0,backgroundColor:n?e.getActiveStyles().backgroundColor||`default`:void 0}}}),l=(0,r.useCallback)(e=>{if(!a)throw Error(`Tried to set text color, but style does not exist in editor schema.`);e===`default`?i.removeStyles({textColor:e}):i.addStyles({textColor:e}),setTimeout(()=>{i.focus()})},[i,a]),u=(0,r.useCallback)(e=>{if(!o)throw Error(`Tried to set background color, but style does not exist in editor schema.`);e===`default`?i.removeStyles({backgroundColor:e}):i.addStyles({backgroundColor:e}),setTimeout(()=>{i.focus()})},[o,i]);return s===void 0?null:(0,c.jsxs)(t.Generic.Menu.Root,{children:[(0,c.jsx)(t.Generic.Menu.Trigger,{children:(0,c.jsx)(t.FormattingToolbar.Button,{className:`bn-button`,"data-test":`colors`,label:n.formatting_toolbar.colors.tooltip,mainTooltip:n.formatting_toolbar.colors.tooltip,icon:(0,c.jsx)(w,{textColor:s.textColor,backgroundColor:s.backgroundColor,size:20})})}),(0,c.jsx)(t.Generic.Menu.Dropdown,{className:`bn-menu-dropdown bn-color-picker-dropdown`,children:(0,c.jsx)(E,{text:s.textColor?{color:s.textColor,setColor:l}:void 0,background:s.backgroundColor?{color:s.backgroundColor,setColor:u}:void 0})})]})},k=e=>{for(let t of a.VALID_LINK_PROTOCOLS)if(e.startsWith(t))return e;return`${a.DEFAULT_LINK_PROTOCOL}://${e}`},A=t=>{let n=e.l(),i=e.s(),{editLink:o}=e.f(a.LinkToolbarExtension),{url:s,text:l,showTextField:d}=t,[f,p]=(0,r.useState)(s),[m,h]=(0,r.useState)(l);(0,r.useEffect)(()=>{p(s),h(l)},[l,s]);let g=(0,r.useCallback)(e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),o(k(f),m,t.range.from),t.setToolbarOpen?.(!1),t.setToolbarPositionFrozen?.(!1))},[o,f,m,t]),_=(0,r.useCallback)(e=>p(e.currentTarget.value),[]),v=(0,r.useCallback)(e=>h(e.currentTarget.value),[]),y=(0,r.useCallback)(()=>{o(k(f),m,t.range.from),t.setToolbarOpen?.(!1),t.setToolbarPositionFrozen?.(!1)},[o,f,m,t]);return(0,c.jsxs)(n.Generic.Form.Root,{children:[(0,c.jsx)(n.Generic.Form.TextInput,{className:`bn-text-input`,name:`url`,icon:(0,c.jsx)(u.RiLink,{}),autoFocus:!0,placeholder:i.link_toolbar.form.url_placeholder,value:f,onKeyDown:g,onChange:_,onSubmit:y}),d!==!1&&(0,c.jsx)(n.Generic.Form.TextInput,{className:`bn-text-input`,name:`title`,icon:(0,c.jsx)(u.RiText,{}),placeholder:i.link_toolbar.form.title_placeholder,value:m,onKeyDown:g,onChange:v,onSubmit:y})]})};function j(e){return`link`in e.schema.inlineContentSchema&&e.schema.inlineContentSchema.link===`link`}var M=()=>{let t=e.m(),n=e.a(),i=e.l(),o=e.s(),l=e.f(a.FormattingToolbarExtension),{showSelection:d}=e.f(a.ShowSelectionExtension),[f,p]=(0,r.useState)(!1);(0,r.useEffect)(()=>(d(f,`createLinkButton`),()=>d(!1,`createLinkButton`)),[f,d]);let m=e.o({editor:t,selector:({editor:e})=>{if(!(!e.isEditable||!j(e)||(0,s.isTableCellSelection)(e.prosemirrorState.selection)||!(e.getSelection()?.blocks||[e.getTextCursorPosition().block]).find(e=>e.content!==void 0)))return{url:e.getSelectedLinkUrl(),text:e.getSelectedText(),range:{from:e.prosemirrorState.selection.from,to:e.prosemirrorState.selection.to}}}});return(0,r.useEffect)(()=>{p(!1)},[m]),(0,r.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`k`&&(p(!0),e.preventDefault())};return n?.addEventListener(`keydown`,e),()=>{n?.removeEventListener(`keydown`,e)}},[n]),m===void 0?null:(0,c.jsxs)(i.Generic.Popover.Root,{open:f,onOpenChange:p,children:[(0,c.jsx)(i.Generic.Popover.Trigger,{children:(0,c.jsx)(i.FormattingToolbar.Button,{className:`bn-button`,"data-test":`createLink`,label:o.formatting_toolbar.link.tooltip,mainTooltip:o.formatting_toolbar.link.tooltip,secondaryTooltip:(0,s.formatKeyboardShortcut)(o.formatting_toolbar.link.secondary_tooltip,o.generic.ctrl_shortcut),icon:(0,c.jsx)(u.RiLink,{}),onClick:()=>p(e=>!e)})}),(0,c.jsx)(i.Generic.Popover.Content,{className:`bn-popover-content bn-form-popover`,variant:`form-popover`,children:(0,c.jsx)(A,{url:m.url||``,text:m.text,range:m.range,showTextField:!1,setToolbarOpen:e=>l.store.setState(e)})})]})},N=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`,caption:`string`}))return n}}),[o,l]=(0,r.useState)(!1),d=(0,r.useCallback)(e=>{a!==void 0&&(0,s.editorHasBlockWithType)(i,a.type,{caption:`string`})&&i.updateBlock(a.id,{props:{caption:e.currentTarget.value}})},[a,i]),f=(0,r.useCallback)(e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),l(!1))},[]);return a===void 0?null:(0,c.jsxs)(n.Generic.Popover.Root,{open:o,onOpenChange:l,children:[(0,c.jsx)(n.Generic.Popover.Trigger,{children:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.file_caption.tooltip,mainTooltip:t.formatting_toolbar.file_caption.tooltip,icon:(0,c.jsx)(u.RiInputField,{}),onClick:()=>l(e=>!e)})}),(0,c.jsx)(n.Generic.Popover.Content,{className:`bn-popover-content bn-form-popover`,variant:`form-popover`,children:(0,c.jsx)(n.Generic.Form.Root,{children:(0,c.jsx)(n.Generic.Form.TextInput,{name:`file-caption`,icon:(0,c.jsx)(u.RiInputField,{}),value:a.props.caption,autoFocus:!0,placeholder:t.formatting_toolbar.file_caption.input_placeholder,onKeyDown:f,onChange:d})})})]})},P=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`}))return n}}),o=(0,r.useCallback)(()=>{a!==void 0&&(i.focus(),i.removeBlocks([a.id]))},[a,i]);return a===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.file_delete.tooltip[a.type]||t.formatting_toolbar.file_delete.tooltip.file,mainTooltip:t.formatting_toolbar.file_delete.tooltip[a.type]||t.formatting_toolbar.file_delete.tooltip.file,icon:(0,c.jsx)(u.RiDeleteBin7Line,{}),onClick:o})},F=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`,name:`string`}))return n}}),[o,l]=(0,r.useState)(!1),d=(0,r.useCallback)(e=>{a!==void 0&&(0,s.editorHasBlockWithType)(i,a.type,{name:`string`})&&i.updateBlock(a.id,{props:{name:e.currentTarget.value}})},[a,i]),f=(0,r.useCallback)(e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),l(!1))},[]);return a===void 0?null:(0,c.jsxs)(n.Generic.Popover.Root,{open:o,onOpenChange:l,children:[(0,c.jsx)(n.Generic.Popover.Trigger,{children:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.file_rename.tooltip[a.type]||t.formatting_toolbar.file_rename.tooltip.file,mainTooltip:t.formatting_toolbar.file_rename.tooltip[a.type]||t.formatting_toolbar.file_rename.tooltip.file,icon:(0,c.jsx)(u.RiFontFamily,{}),onClick:()=>l(e=>!e)})}),(0,c.jsx)(n.Generic.Popover.Content,{className:`bn-popover-content bn-form-popover`,variant:`form-popover`,children:(0,c.jsx)(n.Generic.Form.Root,{children:(0,c.jsx)(n.Generic.Form.TextInput,{name:`file-name`,icon:(0,c.jsx)(u.RiFontFamily,{}),value:a.props.name,autoFocus:!0,placeholder:t.formatting_toolbar.file_rename.input_placeholder[a.type]||t.formatting_toolbar.file_rename.input_placeholder.file,onKeyDown:f,onChange:d})})})]})},te=()=>{let t=e.s(),n=e.l(),r=e.o({editor:e.m(),selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`}))return n}});return r===void 0?null:(0,c.jsxs)(n.Generic.Popover.Root,{position:`bottom`,children:[(0,c.jsx)(n.Generic.Popover.Trigger,{children:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,mainTooltip:t.formatting_toolbar.file_replace.tooltip[r.type]||t.formatting_toolbar.file_replace.tooltip.file,label:t.formatting_toolbar.file_replace.tooltip[r.type]||t.formatting_toolbar.file_replace.tooltip.file,icon:(0,c.jsx)(u.RiImageEditFill,{})})}),(0,c.jsx)(n.Generic.Popover.Content,{className:`bn-popover-content bn-panel-popover`,variant:`panel-popover`,children:(0,c.jsx)(b,{blockId:r.id})})]})},ne=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!(!e.isEditable||!(e.getSelection()?.blocks||[e.getTextCursorPosition().block]).find(e=>e.content!==void 0)))return{canNestBlock:e.canNestBlock()}}}),o=(0,r.useCallback)(()=>{a!==void 0&&a.canNestBlock&&(i.focus(),i.nestBlock())},[i,a]);return a===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,"data-test":`nestBlock`,onClick:o,isDisabled:!a.canNestBlock,label:t.formatting_toolbar.nest.tooltip,mainTooltip:t.formatting_toolbar.nest.tooltip,secondaryTooltip:(0,s.formatKeyboardShortcut)(t.formatting_toolbar.nest.secondary_tooltip,t.generic.ctrl_shortcut),icon:(0,c.jsx)(u.RiIndentIncrease,{})})},re=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!(!e.isEditable||!(e.getSelection()?.blocks||[e.getTextCursorPosition().block]).find(e=>e.content!==void 0)))return{canUnnestBlock:e.canUnnestBlock()}}}),o=(0,r.useCallback)(()=>{a!==void 0&&a.canUnnestBlock&&(i.focus(),i.unnestBlock())},[i,a]);return a===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,"data-test":`unnestBlock`,onClick:o,isDisabled:!a.canUnnestBlock,label:t.formatting_toolbar.unnest.tooltip,mainTooltip:t.formatting_toolbar.unnest.tooltip,secondaryTooltip:(0,s.formatKeyboardShortcut)(t.formatting_toolbar.unnest.secondary_tooltip,t.generic.ctrl_shortcut),icon:(0,c.jsx)(u.RiIndentDecrease,{})})},ie=e=>[{name:e.slash_menu.paragraph.title,type:`paragraph`,icon:u.RiText},{name:e.slash_menu.heading.title,type:`heading`,props:{level:1,isToggleable:!1},icon:u.RiH1},{name:e.slash_menu.heading_2.title,type:`heading`,props:{level:2,isToggleable:!1},icon:u.RiH2},{name:e.slash_menu.heading_3.title,type:`heading`,props:{level:3,isToggleable:!1},icon:u.RiH3},{name:e.slash_menu.heading_4.title,type:`heading`,props:{level:4,isToggleable:!1},icon:u.RiH4},{name:e.slash_menu.heading_5.title,type:`heading`,props:{level:5,isToggleable:!1},icon:u.RiH5},{name:e.slash_menu.heading_6.title,type:`heading`,props:{level:6,isToggleable:!1},icon:u.RiH6},{name:e.slash_menu.toggle_heading.title,type:`heading`,props:{level:1,isToggleable:!0},icon:u.RiH1},{name:e.slash_menu.toggle_heading_2.title,type:`heading`,props:{level:2,isToggleable:!0},icon:u.RiH2},{name:e.slash_menu.toggle_heading_3.title,type:`heading`,props:{level:3,isToggleable:!0},icon:u.RiH3},{name:e.slash_menu.quote.title,type:`quote`,icon:u.RiQuoteText},{name:e.slash_menu.toggle_list.title,type:`toggleListItem`,icon:u.RiPlayList2Fill},{name:e.slash_menu.bullet_list.title,type:`bulletListItem`,icon:u.RiListUnordered},{name:e.slash_menu.numbered_list.title,type:`numberedListItem`,icon:u.RiListOrdered},{name:e.slash_menu.check_list.title,type:`checkListItem`,icon:u.RiListCheck3}],ae=t=>{let n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>e.getSelection()?.blocks||[e.getTextCursorPosition().block]}),o=a[0],l=(0,r.useMemo)(()=>(t.items||ie(i.dictionary)).filter(e=>(0,s.editorHasBlockWithType)(i,e.type,Object.fromEntries(Object.entries(e.props||{}).map(([e,t])=>[e,typeof t])))),[i,t.items]),u=(0,r.useMemo)(()=>l.map(e=>{let t=e.icon,n=e.type===o.type,r=Object.entries(e.props||{}).filter(([e,t])=>t!==o.props[e]).length===0;return{text:e.name,icon:(0,c.jsx)(t,{size:16}),onClick:()=>{i.focus(),i.transact(()=>{for(let t of a)i.updateBlock(t,{type:e.type,props:e.props})})},isSelected:n&&r}}),[i,l,o.props,o.type,a]);return!(0,r.useMemo)(()=>u.find(e=>e.isSelected)!==void 0,[u])||!i.isEditable?null:(0,c.jsx)(n.FormattingToolbar.Select,{className:`bn-select`,items:u})},oe=()=>{let t=e.s(),n=e.l(),i=e.f(`comments`),{store:o}=e.f(a.FormattingToolbarExtension),s=(0,r.useCallback)(()=>{i.startPendingComment(),o.setState(!1)},[i,o]);return(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.comment.tooltip,mainTooltip:t.formatting_toolbar.comment.tooltip,icon:(0,c.jsx)(u.RiChat3Line,{}),onClick:s})},se=()=>e.m().getExtension(`comments`)?(0,c.jsx)(oe,{}):null,ce=()=>{let t=e.s(),n=e.l(),i=e.m(),a=(0,r.useCallback)(()=>{i._tiptapEditor.chain().focus().addPendingComment().run()},[i]);return!i._tiptapEditor.commands.addPendingComment||!i.isEditable?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.comment.tooltip,mainTooltip:t.formatting_toolbar.comment.tooltip,icon:(0,c.jsx)(u.RiChat3Line,{}),onClick:a})};function I(e,t){try{let n=new URL(e,t);if(n.protocol!==`javascript:`)return n.href}catch{}return`#`}var le=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`}))return n}}),o=(0,r.useCallback)(()=>{a!==void 0&&(i.focus(),i.resolveFileUrl?i.resolveFileUrl(a.props.url).then(e=>window.open(I(e,window.location.href))):window.open(I(a.props.url,window.location.href)))},[a,i]);return a===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.file_download.tooltip[a.type]||t.formatting_toolbar.file_download.tooltip.file,mainTooltip:t.formatting_toolbar.file_download.tooltip[a.type]||t.formatting_toolbar.file_download.tooltip.file,icon:(0,c.jsx)(u.RiDownload2Fill,{}),onClick:o})},ue=()=>{let t=e.s(),n=e.l(),i=e.m(),a=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if((0,s.blockHasType)(n,e,n.type,{url:`string`,showPreview:`boolean`}))return n}}),o=(0,r.useCallback)(()=>{a!==void 0&&(0,s.editorHasBlockWithType)(i,a.type,{showPreview:`boolean`})&&i.updateBlock(a.id,{props:{showPreview:!a.props.showPreview}})},[a,i]);return a===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:`Toggle preview`,mainTooltip:t.formatting_toolbar.file_preview_toggle.tooltip,icon:(0,c.jsx)(u.RiImageAddFill,{}),isSelected:a.props.showPreview,onClick:o})},de=()=>{let t=e.s(),n=e.l(),i=e.m(),o=e.f(a.TableHandlesExtension),s=e.o({editor:i,selector:({editor:e})=>{if(!e.isEditable||!e.settings.tables.splitCells)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block];if(t.length!==1)return;let n=t[0];if(n.type===`table`)return{mergeDirection:o.getMergeDirection(n)}}}),l=(0,r.useCallback)(()=>{o?.mergeCells()},[o]);return s===void 0?null:(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,label:t.formatting_toolbar.table_cell_merge.tooltip,mainTooltip:t.formatting_toolbar.table_cell_merge.tooltip,icon:s.mergeDirection===`horizontal`?(0,c.jsx)(u.RiMergeCellsHorizontal,{}):(0,c.jsx)(u.RiMergeCellsVertical,{}),onClick:l})},fe=()=>e.m().getExtension(a.TableHandlesExtension)?(0,c.jsx)(de,{}):null,pe={left:u.RiAlignLeft,center:u.RiAlignCenter,right:u.RiAlignRight,justify:u.RiAlignJustify},L=t=>{let n=e.l(),i=e.s(),o=e.m(),l=e.o({editor:o,selector:({editor:e})=>{if(!e.isEditable)return;let t=e.getSelection()?.blocks||[e.getTextCursorPosition().block],n=t[0];if((0,s.blockHasType)(n,e,n.type,{textAlignment:s.defaultProps.textAlignment}))return{textAlignment:n.props.textAlignment,blocks:t};if(t.length===1&&(0,s.blockHasType)(n,e,`table`))return e.getExtension(a.TableHandlesExtension)?.getCellSelection()?{textAlignment:(0,s.mapTableCell)(n.content.rows[0].cells[0]).props.textAlignment,blocks:[n]}:void 0}}),u=(0,r.useCallback)(e=>{if(l!==void 0){o.focus();for(let t of l.blocks)if((0,s.blockHasType)(t,o,t.type,{textAlignment:s.defaultProps.textAlignment})&&(0,s.editorHasBlockWithType)(o,t.type,{textAlignment:s.defaultProps.textAlignment}))o.updateBlock(t,{props:{textAlignment:e}});else if(t.type===`table`){let n=o.getExtension(a.TableHandlesExtension)?.getCellSelection();if(!n)continue;let r=t.content.rows.map(e=>({...e,cells:e.cells.map(e=>(0,s.mapTableCell)(e))}));n.cells.forEach(({row:t,col:n})=>{r[t].cells[n].props.textAlignment=e}),o.updateBlock(t,{type:`table`,content:{...t.content,type:`tableContent`,rows:r}}),o.setTextCursorPosition(t)}}},[o,l]);if(l===void 0)return null;let d=pe[t.textAlignment];return(0,c.jsx)(n.FormattingToolbar.Button,{className:`bn-button`,"data-test":`alignText${t.textAlignment.slice(0,1).toUpperCase()+t.textAlignment.slice(1)}`,onClick:()=>u(t.textAlignment),isSelected:l.textAlignment===t.textAlignment,label:i.formatting_toolbar[`align_${t.textAlignment}`].tooltip,mainTooltip:i.formatting_toolbar[`align_${t.textAlignment}`].tooltip,icon:(0,c.jsx)(d,{})})},me=e=>[(0,c.jsx)(ae,{items:e},`blockTypeSelect`),(0,c.jsx)(fe,{},`tableCellMergeButton`),(0,c.jsx)(N,{},`fileCaptionButton`),(0,c.jsx)(te,{},`replaceFileButton`),(0,c.jsx)(F,{},`fileRenameButton`),(0,c.jsx)(P,{},`fileDeleteButton`),(0,c.jsx)(le,{},`fileDownloadButton`),(0,c.jsx)(ue,{},`filePreviewButton`),(0,c.jsx)(C,{basicTextStyle:`bold`},`boldStyleButton`),(0,c.jsx)(C,{basicTextStyle:`italic`},`italicStyleButton`),(0,c.jsx)(C,{basicTextStyle:`underline`},`underlineStyleButton`),(0,c.jsx)(C,{basicTextStyle:`strike`},`strikeStyleButton`),(0,c.jsx)(L,{textAlignment:`left`},`textAlignLeftButton`),(0,c.jsx)(L,{textAlignment:`center`},`textAlignCenterButton`),(0,c.jsx)(L,{textAlignment:`right`},`textAlignRightButton`),(0,c.jsx)(O,{},`colorStyleButton`),(0,c.jsx)(ne,{},`nestBlockButton`),(0,c.jsx)(re,{},`unnestBlockButton`),(0,c.jsx)(M,{},`createLinkButton`),(0,c.jsx)(se,{},`addCommentButton`),(0,c.jsx)(ce,{},`addTiptapCommentButton`)],R=t=>(0,c.jsx)(e.l().FormattingToolbar.Root,{className:`bn-toolbar bn-formatting-toolbar`,children:t.children||me(t.blockTypeSelectItems)}),he=e=>{switch(e){case`left`:return`top-start`;case`center`:return`top`;case`right`:return`top-end`;default:return`top-start`}},ge=t=>{let n=e.m(),i=e.f(a.FormattingToolbarExtension,{editor:n}),l=e.p(a.FormattingToolbarExtension,{editor:n}),u=e.o({editor:n,selector:({editor:e})=>i.store.state?{from:e.prosemirrorState.selection.from,to:e.prosemirrorState.selection.to}:void 0}),d=e.o({editor:n,selector:({editor:e})=>{let t=e.getTextCursorPosition().block;return(0,s.blockHasType)(t,e,t.type,{textAlignment:s.defaultProps.textAlignment})?he(t.props.textAlignment):`top-start`}}),f=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:l,onOpenChange:(e,t,r)=>{i.store.setState(e),r===`escape-key`&&n.focus()},placement:d,middleware:[(0,o.offset)(10),(0,o.shift)(),(0,o.flip)()],...t.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:40},...t.floatingUIOptions?.elementProps}}),[l,d,t.floatingUIOptions,i.store,n]),p=t.formattingToolbar||R;return(0,c.jsx)(e.i,{position:u,portalElement:t.portalElement,...f,children:l&&(0,c.jsx)(p,{})})},_e=t=>{let n=e.l(),r=e.s(),{deleteLink:i}=e.f(a.LinkToolbarExtension);return(0,c.jsx)(n.LinkToolbar.Button,{className:`bn-button`,label:r.link_toolbar.delete.tooltip,mainTooltip:r.link_toolbar.delete.tooltip,isSelected:!1,onClick:()=>{i(t.range.from),t.setToolbarOpen?.(!1)},icon:(0,c.jsx)(u.RiLinkUnlink,{})})},ve=t=>{let n=e.l(),r=e.s();return(0,c.jsxs)(n.Generic.Popover.Root,{onOpenChange:t.setToolbarPositionFrozen,children:[(0,c.jsx)(n.Generic.Popover.Trigger,{children:(0,c.jsx)(n.LinkToolbar.Button,{className:`bn-button`,mainTooltip:r.link_toolbar.edit.tooltip,isSelected:!1,children:r.link_toolbar.edit.text})}),(0,c.jsx)(n.Generic.Popover.Content,{className:`bn-popover-content bn-form-popover`,variant:`form-popover`,children:(0,c.jsx)(A,{url:t.url,text:t.text,range:t.range,setToolbarOpen:t.setToolbarOpen,setToolbarPositionFrozen:t.setToolbarPositionFrozen})})]})},ye=t=>{let n=e.l(),r=e.s();return(0,c.jsx)(n.LinkToolbar.Button,{className:`bn-button`,mainTooltip:r.link_toolbar.open.tooltip,label:r.link_toolbar.open.tooltip,isSelected:!1,onClick:()=>{window.open(I(t.url,window.location.href),`_blank`)},icon:(0,c.jsx)(u.RiExternalLinkFill,{})})},be=t=>(0,c.jsx)(e.l().LinkToolbar.Root,{className:`bn-toolbar bn-link-toolbar`,children:t.children||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(ve,{url:t.url,text:t.text,range:t.range,setToolbarOpen:t.setToolbarOpen,setToolbarPositionFrozen:t.setToolbarPositionFrozen}),(0,c.jsx)(ye,{url:t.url}),(0,c.jsx)(_e,{range:t.range,setToolbarOpen:t.setToolbarOpen})]})}),xe=t=>{let n=e.m(),[i,s]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),d=e.a(),f=e.f(a.LinkToolbarExtension),[p,m]=(0,r.useState)(void 0);(0,r.useEffect)(()=>{let e=()=>{let e=f.getLinkAtSelection();if(!e){m(void 0),l||s(!1);return}m({cursorType:`text`,url:e.mark.attrs.href,text:e.text,range:e.range,element:f.getLinkElementAtPos(e.range.from)}),l||s(!0)},t=e=>{if(p!==void 0&&p.cursorType===`text`||!(e.target instanceof HTMLElement))return;let t=f.getLinkAtElement(e.target);t&&m({cursorType:`mouse`,url:t.mark.attrs.href,text:t.text,range:t.range,element:f.getLinkElementAtPos(t.range.from)})},r=n.onChange(e),i=n.onSelectionChange(e);return d?.addEventListener(`mouseover`,t),()=>{r(),i(),d?.removeEventListener(`mouseover`,t)}},[n,d,f,p,l]);let h=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:i,onOpenChange:(e,t,r)=>{l||p!==void 0&&p.cursorType===`text`&&r===`hover`||(r===`escape-key`&&n.focus(),s(e))},placement:`top-start`,middleware:[(0,o.offset)(10),(0,o.flip)()],...t.floatingUIOptions?.useFloatingOptions},useHoverProps:{enabled:p!==void 0&&p.cursorType===`mouse`,delay:{open:250,close:250},handleClose:(0,o.safePolygon)(),...t.floatingUIOptions?.useHoverProps},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:50},...t.floatingUIOptions?.elementProps}}),[n,p,t.floatingUIOptions,i,l]),g=(0,r.useMemo)(()=>p?.element?{element:p.element}:void 0,[p?.element]);if(!n.isEditable)return null;let _=t.linkToolbar||be;return(0,c.jsx)(e.u,{reference:g,portalElement:t.portalElement,...h,children:p&&(0,c.jsx)(_,{url:p.url,text:p.text,range:p.range,setToolbarOpen:s,setToolbarPositionFrozen:u})})},Se=()=>{let t=e.l(),n=e.s(),i=e.m(),o=e.f(a.SuggestionMenu),s=e.p(a.SideMenuExtension,{editor:i,selector:e=>e?.block}),l=(0,r.useCallback)(()=>{if(s===void 0)return;let e=s.content;if(e!==void 0&&Array.isArray(e)&&e.length===0)i.setTextCursorPosition(s),o.openSuggestionMenu(`/`);else{let e=i.insertBlocks([{type:`paragraph`}],s,`after`)[0];i.setTextCursorPosition(e),o.openSuggestionMenu(`/`)}},[s,i,o]);return s===void 0?null:(0,c.jsx)(t.SideMenu.Button,{className:`bn-button`,label:n.side_menu.add_block_label,icon:(0,c.jsx)(d.AiOutlinePlus,{size:24,onClick:l,"data-test":`dragHandleAdd`})})},Ce=t=>{let n=e.l(),r=e.m(),i=e.p(a.SideMenuExtension,{editor:r,selector:e=>e?.block});return i===void 0||!(0,s.blockHasType)(i,r,i.type,{textColor:`string`})&&!(0,s.blockHasType)(i,r,i.type,{backgroundColor:`string`})?null:(0,c.jsxs)(n.Generic.Menu.Root,{position:`right`,sub:!0,children:[(0,c.jsx)(n.Generic.Menu.Trigger,{sub:!0,children:(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,subTrigger:!0,children:t.children})}),(0,c.jsx)(n.Generic.Menu.Dropdown,{sub:!0,className:`bn-menu-dropdown bn-color-picker-dropdown`,children:(0,c.jsx)(E,{iconSize:18,text:(0,s.blockHasType)(i,r,i.type,{textColor:`string`})&&(0,s.editorHasBlockWithType)(r,i.type,{textColor:`string`})?{color:i.props.textColor,setColor:e=>r.updateBlock(i,{type:i.type,props:{textColor:e}})}:void 0,background:(0,s.blockHasType)(i,r,i.type,{backgroundColor:`string`})&&(0,s.editorHasBlockWithType)(r,i.type,{backgroundColor:`string`})?{color:i.props.backgroundColor,setColor:e=>r.updateBlock(i,{props:{backgroundColor:e}})}:void 0})})]})},we=t=>{let n=e.l(),r=e.m(),i=e.p(a.SideMenuExtension,{editor:r,selector:e=>e?.block});return i===void 0?null:(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,onClick:()=>{let e=r.getSelection()?.blocks,t=e&&e.some(e=>e.id===i.id)?e:[i];r.removeBlocks(t)},children:t.children})},Te=t=>{let n=e.l(),r=e.m(),i=e.p(a.SideMenuExtension,{editor:r,selector:e=>e?.block});if(i===void 0||i.type!==`table`||!r.settings.tables.headers)return null;let o=!!i.content.headerRows;return(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,checked:o,onClick:()=>{r.updateBlock(i,{content:{...i.content,headerRows:o?void 0:1}})},children:t.children})},Ee=t=>{let n=e.l(),r=e.m(),i=e.p(a.SideMenuExtension,{editor:r,selector:e=>e?.block});if(i===void 0||i.type!==`table`||!r.settings.tables.headers)return null;let o=!!i.content.headerCols;return(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,checked:o,onClick:()=>{r.updateBlock(i,{content:{...i.content,headerCols:o?void 0:1}})},children:t.children})},De=t=>{let n=e.l(),r=e.s();return(0,c.jsx)(n.Generic.Menu.Dropdown,{className:`bn-menu-dropdown bn-drag-handle-menu`,children:t.children||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(we,{children:r.drag_handle.delete_menuitem}),(0,c.jsx)(Ce,{children:r.drag_handle.colors_menuitem}),(0,c.jsx)(Te,{children:r.drag_handle.header_row_menuitem}),(0,c.jsx)(Ee,{children:r.drag_handle.header_column_menuitem})]})})},Oe=t=>{let n=e.l(),r=e.s(),i=e.f(a.SideMenuExtension),o=e.p(a.SideMenuExtension,{selector:e=>e?.block});if(o===void 0)return null;let s=t.dragHandleMenu||De;return(0,c.jsxs)(n.Generic.Menu.Root,{onOpenChange:e=>{e?i.freezeMenu():i.unfreezeMenu()},position:`left`,children:[(0,c.jsx)(n.Generic.Menu.Trigger,{children:(0,c.jsx)(n.SideMenu.Button,{label:r.side_menu.drag_handle_label,draggable:!0,onDragStart:e=>i.blockDragStart(e,o),onDragEnd:i.blockDragEnd,className:`bn-button`,icon:(0,c.jsx)(f.MdDragIndicator,{size:24,"data-test":`dragHandle`})})}),(0,c.jsx)(s,{children:t.children})]})},ke=t=>{let n=e.l(),i=e.m(),o=e.p(a.SideMenuExtension,{editor:i,selector:e=>e?.block}),s=(0,r.useMemo)(()=>{if(o===void 0)return{};let e={"data-block-type":o.type};return o.type===`heading`&&(e[`data-level`]=o.props.level.toString()),i.schema.blockSpecs[o.type].implementation.meta?.fileBlockAccept&&(o.props.url?e[`data-url`]=`true`:e[`data-url`]=`false`),e},[o,i.schema.blockSpecs]);return(0,c.jsx)(n.SideMenu.Root,{className:`bn-side-menu`,...s,children:t.children||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(Se,{}),(0,c.jsx)(Oe,{dragHandleMenu:t.dragHandleMenu})]})})},Ae=t=>{let n=e.m(),{show:i,block:s}=e.p(a.SideMenuExtension,{selector:e=>e===void 0?void 0:{show:e.show,block:e.block}})||{},l=(0,r.useCallback)((e,t,r)=>{let i=!1;return(0,o.autoUpdate)(e,t,()=>{if(!i){i=!0;return}n.getExtension(a.SideMenuExtension)?.hideMenuIfNotFrozen()},{ancestorScroll:!0,ancestorResize:!1,elementResize:!1,layoutShift:!1})},[n]),u=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:i,placement:`left-start`,whileElementsMounted:l,...t.floatingUIOptions?.useFloatingOptions},useDismissProps:{enabled:!1,...t.floatingUIOptions?.useDismissProps},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:20},...t.floatingUIOptions?.elementProps}}),[t.floatingUIOptions,i,l]),d=t.sideMenu||ke;return(0,c.jsx)(_,{blockId:i?s?.id:void 0,portalElement:t.portalElement,...u,children:s?.id&&(0,c.jsx)(d,{})})};async function je(e,t){return(await(0,a.getDefaultEmojiPickerItems)(e,t)).map(({id:e,onItemClick:t})=>({id:e,onItemClick:t,icon:e}))}function Me(t){let n=e.l(),i=e.s(),{items:a,loadingState:o,selectedIndex:s,onItemClick:l,columns:u}=t,d=o===`loading-initial`||o===`loading`?(0,c.jsx)(n.GridSuggestionMenu.Loader,{className:`bn-grid-suggestion-menu-loader`,columns:u}):null,f=(0,r.useMemo)(()=>{let e=[];for(let t=0;t<a.length;t++){let r=a[t];e.push((0,c.jsx)(n.GridSuggestionMenu.Item,{className:`bn-grid-suggestion-menu-item`,item:r,id:`bn-grid-suggestion-menu-item-${t}`,isSelected:t===s,onClick:()=>l?.(r)},r.id))}return e},[n,a,l,s]);return(0,c.jsxs)(n.GridSuggestionMenu.Root,{id:`bn-grid-suggestion-menu`,columns:u,className:`bn-grid-suggestion-menu`,children:[d,f,f.length===0&&t.loadingState===`loaded`&&(0,c.jsx)(n.GridSuggestionMenu.EmptyItem,{className:`bn-grid-suggestion-menu-empty-item`,columns:u,children:i.suggestion_menu.no_items_title})]})}function z(e,t,n,i=3){let a=(0,r.useRef)(0);(0,r.useEffect)(()=>{t!==void 0&&(e.length>0?a.current=t.length:t.length-a.current>i&&n())},[n,i,e.length,t])}function B(e,t){let[n,i]=(0,r.useState)([]),[a,o]=(0,r.useState)(!1),s=(0,r.useRef)(void 0),c=(0,r.useRef)(void 0);return(0,r.useEffect)(()=>{let n=e;s.current=e,o(!0),t(e).then(e=>{s.current===n&&(i(e),o(!1),c.current=n)})},[e,t]),{items:n||[],usedQuery:c.current,loadingState:c.current===void 0?`loading-initial`:a?`loading`:`loaded`}}function Ne(t,n,i,a,o){let s=e.a(t),[c,l]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e=e=>(e.key===`ArrowLeft`&&(e.preventDefault(),i.length&&l((c-1+i.length)%i.length)),e.key===`ArrowRight`&&(e.preventDefault(),i.length&&l((c+1+i.length)%i.length)),e.key===`ArrowUp`?(e.preventDefault(),i.length&&l((c-a+i.length)%i.length),!0):e.key===`ArrowDown`?(e.preventDefault(),i.length&&l((c+a)%i.length),!0):e.key===`Enter`&&!e.isComposing?(e.stopPropagation(),e.preventDefault(),i.length&&o?.(i[c]),!0):!1);return s?.addEventListener(`keydown`,e,!0),()=>{s?.removeEventListener(`keydown`,e,!0)}},[s,i,c,o,a,a!==void 0&&a>1]),(0,r.useEffect)(()=>{l(0)},[n]),{selectedIndex:i.length===0?void 0:c}}function Pe(t){let n=e.g().setContentEditableProps,i=e.m(),{getItems:a,gridSuggestionMenuComponent:o,query:s,clearQuery:l,closeMenu:u,onItemClick:d,columns:f}=t,p=(0,r.useCallback)(e=>{u(),l(),d?.(e)},[d,u,l]),{items:m,usedQuery:h,loadingState:g}=B(s,a);z(m,h,u);let{selectedIndex:_}=Ne(i,s,m,f,p);return(0,r.useEffect)(()=>(n(e=>({...e,"aria-expanded":!0,"aria-controls":`bn-suggestion-menu`})),()=>{n(e=>({...e,"aria-expanded":!1,"aria-controls":void 0}))}),[n]),(0,r.useEffect)(()=>(n(e=>({...e,"aria-activedescendant":_?`bn-suggestion-menu-item-`+_:void 0})),()=>{n(e=>({...e,"aria-activedescendant":void 0}))}),[n,_]),(0,c.jsx)(o,{items:m,onItemClick:p,loadingState:g,selectedIndex:_,columns:f})}function Fe(t){let n=e.m(),i=e.a(),{triggerCharacter:s,gridSuggestionMenuComponent:l,columns:u,shouldOpen:d,minQueryLength:f,onItemClick:p,getItems:m}=t,h=(0,r.useMemo)(()=>p||(e=>{e.onItemClick(n)}),[n,p]),g=(0,r.useMemo)(()=>m||(async e=>await je(n,e)),[n,m]),_=e.f(a.SuggestionMenu);(0,r.useEffect)(()=>{_.addSuggestionMenu({triggerCharacter:s,shouldOpen:d})},[_,s,d]);let v=e.p(a.SuggestionMenu),y=e.p(a.SuggestionMenu,{selector:e=>({element:i?.firstChild||void 0,getBoundingClientRect:()=>e?.referencePos||new DOMRect})}),b=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:v?.show&&v?.triggerCharacter===s,onOpenChange:e=>{e||_.closeMenu()},placement:`bottom-start`,middleware:[(0,o.offset)(10),(0,o.autoPlacement)({allowedPlacements:[`bottom-start`,`top-start`],padding:10}),(0,o.shift)(),(0,o.size)({apply({elements:e,availableHeight:t}){e.floating.style.maxHeight=`${Math.max(0,t)}px`},padding:10})],...t.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{onMouseDownCapture:e=>e.preventDefault(),style:{zIndex:70},...t.floatingUIOptions?.elementProps}}),[t.floatingUIOptions,v?.show,v?.triggerCharacter,_,s]);return!v||!v.ignoreQueryLength&&f&&(v.query.startsWith(` `)||v.query.length<f)?null:(0,c.jsx)(e.u,{reference:y,portalElement:t.portalElement,...b,children:s&&(0,c.jsx)(Pe,{query:v.query,closeMenu:_.closeMenu,clearQuery:_.clearQuery,getItems:g,columns:u,gridSuggestionMenuComponent:l||Me,onItemClick:h})})}function Ie(t){let n=e.l(),i=e.s(),{items:a,loadingState:o,selectedIndex:l,onItemClick:u}=t,d=o===`loading-initial`||o===`loading`?(0,c.jsx)(n.SuggestionMenu.Loader,{className:`bn-suggestion-menu-loader`}):null,f=(0,r.useMemo)(()=>{let e,t=[];for(let r=0;r<a.length;r++){let i=a[r];i.group!==e&&(e=i.group,t.push((0,c.jsx)(n.SuggestionMenu.Label,{className:`bn-suggestion-menu-label`,children:e},e))),t.push((0,c.jsx)(n.SuggestionMenu.Item,{className:(0,s.mergeCSSClasses)(`bn-suggestion-menu-item`,i.size===`small`?`bn-suggestion-menu-item-small`:``),item:i,id:`bn-suggestion-menu-item-${r}`,isSelected:r===l,onClick:()=>u?.(i)},i.title))}return t},[n,a,u,l]);return(0,c.jsxs)(n.SuggestionMenu.Root,{id:`bn-suggestion-menu`,className:`bn-suggestion-menu`,children:[f,f.length===0&&(t.loadingState===`loading`||t.loadingState===`loaded`)&&(0,c.jsx)(n.SuggestionMenu.EmptyItem,{className:`bn-suggestion-menu-item`,children:i.suggestion_menu.no_items_title}),d]})}function Le(e,t){let[n,i]=(0,r.useState)(0);return{selectedIndex:n,setSelectedIndex:i,handler:r=>{if(r.key===`ArrowUp`)return r.preventDefault(),e.length&&i((n-1+e.length)%e.length),!0;if(r.key===`ArrowDown`)return r.preventDefault(),e.length&&i((n+1)%e.length),!0;if(r.key===`PageUp`)return r.preventDefault(),e.length&&i(0),!0;if(r.key===`PageDown`)return r.preventDefault(),e.length&&i(e.length-1),!0;let a=Re(r)?r.nativeEvent.isComposing:r.isComposing;return r.key===`Enter`&&!a?(r.preventDefault(),r.stopPropagation(),e.length&&t?.(e[n]),!0):!1}}}function Re(e){return e.nativeEvent!==void 0}function ze(t,n,i,a,o){let s=e.a(),{selectedIndex:c,setSelectedIndex:l,handler:u}=Le(i,a);return(0,r.useEffect)(()=>{let e=o||s;return e?.addEventListener(`keydown`,u,!0),()=>{e?.removeEventListener(`keydown`,u,!0)}},[s,i,c,a,o,u]),(0,r.useEffect)(()=>{l(0)},[n,l]),{selectedIndex:i.length===0?void 0:c}}function Be(t){let n=e.g().setContentEditableProps,i=e.m(),{getItems:a,suggestionMenuComponent:o,query:s,clearQuery:l,closeMenu:u,onItemClick:d}=t,f=(0,r.useCallback)(e=>{u(),l(),d?.(e)},[d,u,l]),{items:p,usedQuery:m,loadingState:h}=B(s,a);z(p,m,u);let{selectedIndex:g}=ze(i,s,p,f);return(0,r.useEffect)(()=>(n(e=>({...e,"aria-expanded":!0,"aria-controls":`bn-suggestion-menu`})),()=>{n(e=>({...e,"aria-expanded":!1,"aria-controls":void 0}))}),[n]),(0,r.useEffect)(()=>(n(e=>({...e,"aria-activedescendant":g?`bn-suggestion-menu-item-`+g:void 0})),()=>{n(e=>({...e,"aria-activedescendant":void 0}))}),[n,g]),(0,c.jsx)(o,{items:p,onItemClick:f,loadingState:h,selectedIndex:g})}var Ve={heading:u.RiH1,heading_2:u.RiH2,heading_3:u.RiH3,heading_4:u.RiH4,heading_5:u.RiH5,heading_6:u.RiH6,toggle_heading:u.RiH1,toggle_heading_2:u.RiH2,toggle_heading_3:u.RiH3,quote:u.RiQuoteText,toggle_list:u.RiPlayList2Fill,numbered_list:u.RiListOrdered,bullet_list:u.RiListUnordered,check_list:u.RiListCheck3,paragraph:u.RiText,table:u.RiTable2,image:u.RiImage2Fill,video:u.RiFilmLine,audio:u.RiVolumeUpFill,file:u.RiFile2Line,emoji:u.RiEmotionFill,code_block:u.RiCodeBlock,divider:u.RiSubtractLine};function He(e){return(0,a.getDefaultSlashMenuItems)(e).map(e=>{let t=Ve[e.key];return{...e,icon:(0,c.jsx)(t,{size:18})}})}function Ue(t){let n=e.m(),i=e.a(),{triggerCharacter:s,suggestionMenuComponent:l,shouldOpen:u,minQueryLength:d,onItemClick:f,getItems:p}=t,m=(0,r.useMemo)(()=>f||(e=>{e.onItemClick(n)}),[n,f]),h=(0,r.useMemo)(()=>p||(async e=>(0,a.filterSuggestionItems)(He(n),e)),[n,p]),g=e.f(a.SuggestionMenu);(0,r.useEffect)(()=>{g.addSuggestionMenu({triggerCharacter:s,shouldOpen:u})},[g,s,u]);let _=e.p(a.SuggestionMenu),v=e.p(a.SuggestionMenu,{selector:e=>({element:i?.firstChild||void 0,getBoundingClientRect:()=>e?.referencePos||new DOMRect})}),y=(0,r.useMemo)(()=>({...t.floatingUIOptions,useFloatingOptions:{open:_?.show&&_?.triggerCharacter===s,onOpenChange:e=>{e||g.closeMenu()},placement:`bottom-start`,middleware:[(0,o.offset)(10),(0,o.autoPlacement)({allowedPlacements:[`bottom-start`,`top-start`],padding:10}),(0,o.shift)(),(0,o.size)({apply({elements:e,availableHeight:t}){e.floating.style.maxHeight=`${Math.max(0,t)}px`},padding:10})],...t.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...t.floatingUIOptions?.focusManagerProps},elementProps:{onMouseDownCapture:e=>e.preventDefault(),style:{zIndex:80},...t.floatingUIOptions?.elementProps}}),[t.floatingUIOptions,_?.show,_?.triggerCharacter,g,s]);return!_||!_.ignoreQueryLength&&d&&(_.query.startsWith(` `)||_.query.length<d)?null:(0,c.jsx)(e.u,{reference:v,portalElement:t.portalElement,...y,children:s&&(0,c.jsx)(Be,{query:_.query,closeMenu:g.closeMenu,clearQuery:g.clearQuery,getItems:h,suggestionMenuComponent:l||Ie,onItemClick:m})})}var We=(e,t=.3)=>{let n=Math.floor(e)+t,r=Math.ceil(e)-t;return e>=n&&e<=r?Math.round(e):e<n?Math.floor(e):Math.ceil(e)},Ge=t=>{let n=e.l(),i=e.m(),o=e.f(a.TableHandlesExtension),l=e.p(a.TableHandlesExtension,{selector:e=>e?.block}),d=(0,r.useRef)(!1),[f,p]=(0,r.useState)(),m=(0,r.useCallback)(e=>{o.freezeHandles(),t.hideOtherElements(!0),l&&(p({originalContent:l.content,originalCroppedContent:{rows:o.cropEmptyRowsOrColumns(l,t.orientation===`addOrRemoveColumns`?`columns`:`rows`)},startPos:t.orientation===`addOrRemoveColumns`?e.clientX:e.clientY}),d.current=!1,e.preventDefault())},[l,t,o]),h=(0,r.useCallback)(()=>{!l||d.current||i.updateBlock(l,{type:`table`,content:{...l.content,rows:t.orientation===`addOrRemoveColumns`?o.addRowsOrColumns(l,`columns`,1):o.addRowsOrColumns(l,`rows`,1)}})},[l,i,t.orientation,o]);return(0,r.useEffect)(()=>{let e=e=>{if(!l)return;if(!f)throw Error(`editingState is undefined`);d.current=!0;let n=(t.orientation===`addOrRemoveColumns`?e.clientX:e.clientY)-f.startPos,r=t.orientation===`addOrRemoveColumns`?f.originalCroppedContent.rows[0]?.cells.length??0:f.originalCroppedContent.rows.length,a=t.orientation===`addOrRemoveColumns`?f.originalContent.rows[0]?.cells.length??0:f.originalContent.rows.length,c=t.orientation===`addOrRemoveColumns`?l.content.rows[0].cells.length:l.content.rows.length,u=a+We(n/(t.orientation===`addOrRemoveColumns`?s.EMPTY_CELL_WIDTH:s.EMPTY_CELL_HEIGHT),.3);u>=r&&u>0&&u!==c&&(i.updateBlock(l,{type:`table`,content:{...l.content,rows:t.orientation===`addOrRemoveColumns`?o.addRowsOrColumns({type:`table`,content:f.originalCroppedContent},`columns`,u-r):o.addRowsOrColumns({type:`table`,content:f.originalCroppedContent},`rows`,u-r)}}),l.content&&i.setTextCursorPosition(l))};return f&&window.addEventListener(`mousemove`,e),()=>{window.removeEventListener(`mousemove`,e)}},[l,f,i,t.orientation,o]),(0,r.useEffect)(()=>{let e=()=>{t.hideOtherElements(!1),o.unfreezeHandles(),p(void 0)};return f&&window.addEventListener(`mouseup`,e),()=>{window.removeEventListener(`mouseup`,e)}},[f,t,o]),i.isEditable?(0,c.jsx)(n.TableHandle.ExtendButton,{className:(0,s.mergeCSSClasses)(`bn-extend-button`,t.orientation===`addOrRemoveColumns`?`bn-extend-button-add-remove-columns`:`bn-extend-button-add-remove-rows`,f===null?``:`bn-extend-button-editing`),onClick:h,onMouseDown:m,children:t.children||(0,c.jsx)(u.RiAddFill,{size:18,"data-test":`extendButton`})}):null},Ke=t=>{let n=e.l(),r=e.s(),i=e.m(),{block:o,colIndex:l,rowIndex:u}=e.p(a.TableHandlesExtension,{selector:e=>({block:e?.block,colIndex:e?.colIndex,rowIndex:e?.rowIndex})}),d=(e,t)=>{if(o===void 0||l===void 0||u===void 0)return;let n=o.content.rows.map(e=>({...e,cells:e.cells.map(e=>(0,s.mapTableCell)(e))}));t===`text`?n[u].cells[l].props.textColor=e:n[u].cells[l].props.backgroundColor=e,i.updateBlock(o,{type:`table`,content:{...o.content,rows:n}}),i.setTextCursorPosition(o)};if(o===void 0||l===void 0||u===void 0)return null;let f=o.content.rows[u]?.cells?.[l];return!f||i.settings.tables.cellTextColor===!1&&i.settings.tables.cellBackgroundColor===!1?null:(0,c.jsxs)(n.Generic.Menu.Root,{position:`right`,sub:!0,children:[(0,c.jsx)(n.Generic.Menu.Trigger,{sub:!0,children:(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,subTrigger:!0,children:t.children||r.drag_handle.colors_menuitem})}),(0,c.jsx)(n.Generic.Menu.Dropdown,{sub:!0,className:`bn-menu-dropdown bn-color-picker-dropdown`,children:(0,c.jsx)(E,{iconSize:18,text:i.settings.tables.cellTextColor?{color:(0,s.isTableCell)(f)?f.props.textColor:`default`,setColor:e=>d(e,`text`)}:void 0,background:i.settings.tables.cellBackgroundColor?{color:(0,s.isTableCell)(f)?f.props.backgroundColor:`default`,setColor:e=>d(e,`background`)}:void 0})})]})},qe=()=>{let t=e.l(),n=e.s(),r=e.m(),i=e.f(a.TableHandlesExtension),{block:o,colIndex:l,rowIndex:u}=e.p(a.TableHandlesExtension,{selector:e=>({block:e?.block,colIndex:e?.colIndex,rowIndex:e?.rowIndex})});if(o===void 0||l===void 0||u===void 0)return null;let d=o.content.rows[u]?.cells?.[l];return!d||!(0,s.isTableCell)(d)||(0,s.getRowspan)(d)===1&&(0,s.getColspan)(d)===1||!r.settings.tables.splitCells?null:(0,c.jsx)(t.Generic.Menu.Item,{onClick:()=>{i.splitCell({row:u,col:l})},children:n.table_handle.split_cell_menuitem})},Je=t=>(0,c.jsx)(e.l().Generic.Menu.Dropdown,{className:`bn-menu-dropdown bn-table-handle-menu`,children:t.children||(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(qe,{}),(0,c.jsx)(Ke,{})]})}),Ye=t=>{let n=e.l(),r=e.m(),i=e.f(a.TableHandlesExtension),o=t.tableCellMenu||Je;return!r.settings.tables.splitCells&&!r.settings.tables.cellBackgroundColor&&!r.settings.tables.cellTextColor?null:(0,c.jsxs)(n.Generic.Menu.Root,{onOpenChange:e=>{e?(i.freezeHandles(),t.hideOtherElements(!0)):(i.unfreezeHandles(),t.hideOtherElements(!1),r.focus())},position:`right`,children:[(0,c.jsx)(n.Generic.Menu.Trigger,{children:(0,c.jsx)(n.Generic.Menu.Button,{className:`bn-table-cell-handle`,children:t.children||(0,c.jsx)(f.MdArrowDropDown,{size:12,"data-test":`tableCellHandle`})})}),(0,c.jsx)(o,{})]})},Xe=t=>{let n=e.l(),r=e.s(),i=e.f(a.TableHandlesExtension),o=e.p(a.TableHandlesExtension,{selector:e=>t.orientation===`column`?e?.colIndex:e?.rowIndex});return i===void 0||o===void 0?null:(0,c.jsx)(n.Generic.Menu.Item,{onClick:()=>{i.addRowOrColumn(o,t.orientation===`row`?{orientation:`row`,side:t.side}:{orientation:`column`,side:t.side})},children:r.table_handle[`add_${t.side}_menuitem`]})},Ze=t=>{let n=e.l(),r=e.s(),i=e.f(a.TableHandlesExtension),o=e.p(a.TableHandlesExtension,{selector:e=>t.orientation===`column`?e?.colIndex:e?.rowIndex});return i===void 0||o===void 0?null:(0,c.jsx)(n.Generic.Menu.Item,{onClick:()=>i.removeRowOrColumn(o,t.orientation),children:t.orientation===`row`?r.table_handle.delete_row_menuitem:r.table_handle.delete_column_menuitem})},Qe=t=>{let n=e.l(),i=e.s(),o=e.m(),l=e.f(a.TableHandlesExtension),{block:u,index:d}=e.p(a.TableHandlesExtension,{selector:e=>({block:e?.block,index:t.orientation===`column`?e?.colIndex:e?.rowIndex})}),f=(0,r.useMemo)(()=>l===void 0||u===void 0||d===void 0?[]:t.orientation===`row`?l.getCellsAtRowHandle(u,d):l.getCellsAtColumnHandle(u,d),[u,d,t.orientation,l]),p=(e,t)=>{if(u===void 0)return;let n=u.content.rows.map(e=>({...e,cells:e.cells.map(e=>(0,s.mapTableCell)(e))}));f.forEach(({row:r,col:i})=>{t===`text`?n[r].cells[i].props.textColor=e:n[r].cells[i].props.backgroundColor=e}),o.updateBlock(u,{type:`table`,content:{...u.content,rows:n}}),o.setTextCursorPosition(u)};if(!f||!f[0]||!l||o.settings.tables.cellTextColor===!1&&o.settings.tables.cellBackgroundColor===!1)return null;let m=(0,s.mapTableCell)(f[0].cell);return(0,c.jsxs)(n.Generic.Menu.Root,{position:`right`,sub:!0,children:[(0,c.jsx)(n.Generic.Menu.Trigger,{sub:!0,children:(0,c.jsx)(n.Generic.Menu.Item,{className:`bn-menu-item`,subTrigger:!0,children:t.children||i.drag_handle.colors_menuitem})}),(0,c.jsx)(n.Generic.Menu.Dropdown,{sub:!0,className:`bn-menu-dropdown bn-color-picker-dropdown`,children:(0,c.jsx)(E,{iconSize:18,text: