ocean-brain 0.13.0 → 0.13.2

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.
Files changed (48) hide show
  1. package/README.md +5 -3
  2. package/dist/index.js +12 -4
  3. package/package.json +10 -8
  4. package/server/client/dist/assets/{Calendar-CaeK7gTz.js → Calendar-DH3eSSRs.js} +1 -1
  5. package/server/client/dist/assets/{Note-CGI-Y1__.js → Note-CpzLtGVM.js} +1 -1
  6. package/server/client/dist/assets/{Search-DAYHxAml.js → Search-D9detGWk.js} +1 -1
  7. package/server/client/dist/assets/{Tag-CG8b0l1j.js → Tag-Bquqtx23.js} +1 -1
  8. package/server/client/dist/assets/{TagNotes-COyaVsdn.js → TagNotes-CbjfxqAN.js} +1 -1
  9. package/server/client/dist/assets/{Views-BPxlw3vk.js → Views-L4eC96Lx.js} +1 -1
  10. package/server/client/dist/assets/{app-BezcjTfd.js → app-BFM2V_Rx.js} +2 -2
  11. package/server/client/dist/assets/{index-CzZFedXj.js → index-CJPl3MJE.js} +1 -1
  12. package/server/client/dist/assets/{manage-image-detail-9hRTiAsR.js → manage-image-detail-BIDHUR5-.js} +1 -1
  13. package/server/client/dist/assets/mcp-D8footel.js +5 -0
  14. package/server/client/dist/assets/{note-core-DUTqUh5N.js → note-core-YhYEmI_R.js} +1 -1
  15. package/server/client/dist/assets/note-runtime-B3ats-dC.js +153 -0
  16. package/server/client/dist/assets/{note-ui-BaqzP-YU.js → note-ui-BtzPk8gA.js} +1 -1
  17. package/server/client/dist/assets/{placeholder-CZoqs4S3.js → placeholder-DKgxoe_f.js} +1 -1
  18. package/server/client/dist/assets/route-preload.js +2 -2
  19. package/server/client/dist/index.html +1 -1
  20. package/server/dist/app.js +91 -8
  21. package/server/dist/features/auth/http/api.js +9 -8
  22. package/server/dist/features/auth/http/pages.js +27 -28
  23. package/server/dist/features/auth/service.js +7 -27
  24. package/server/dist/features/cache/graphql/cache.type-defs.js +1 -1
  25. package/server/dist/features/image/http/upload.js +2 -2
  26. package/server/dist/features/mcp-admin/http/handlers.js +9 -9
  27. package/server/dist/features/note/http/mcp.js +17 -17
  28. package/server/dist/features/search/http/handlers.js +10 -10
  29. package/server/dist/features/search/search-manager.js +34 -6
  30. package/server/dist/features/tag/http/mcp.js +2 -2
  31. package/server/dist/modules/auth-guard.js +36 -53
  32. package/server/dist/modules/blocknote.js +16 -9
  33. package/server/dist/modules/error-handler.js +17 -20
  34. package/server/dist/modules/mcp-auth.js +50 -56
  35. package/server/dist/modules/rate-limit.js +23 -23
  36. package/server/dist/modules/server-events-handler.js +15 -13
  37. package/server/dist/modules/session-store.js +6 -8
  38. package/server/dist/paths.js +2 -1
  39. package/server/dist/routes/api.js +105 -71
  40. package/server/dist/routes/auth-pages.js +21 -11
  41. package/server/dist/routes/client.js +60 -72
  42. package/server/dist/routes/graphql.js +31 -26
  43. package/server/dist/routes/mcp.js +25 -35
  44. package/server/dist/server.js +14 -16
  45. package/server/client/dist/assets/mcp-ugdCKa6H.js +0 -4
  46. package/server/client/dist/assets/note-runtime-zN5ddTba.js +0 -168
  47. package/server/dist/modules/logger.js +0 -53
  48. package/server/dist/modules/use-async.js +0 -10
@@ -1,2 +1,2 @@
1
- import{r as d,j as r,w as Zt,b as pe,a as ae}from"./floating-ui.react-dom-BWTnA00G.js";import{$ as Xt,q as Jt,U as en,s as tn,v as B,w as R,L as nn,I as on,P as z,D as P,n as Y,Z as U,a as S,C as ge,K as ie,M as Z,b as rn,O as ln,i as be,c as D,Y as _e,V as Ge,d as an,o as sn,e as et,A as cn,x as tt,f as nt,u as dn,g as un,N as X,W as mn,T as ot,H as pn,r as $e,h as gn,j as bn,k as fn,l as hn,m as xn,F as j,p as Re}from"./note-core-DUTqUh5N.js";import{aL as vn,aM as Cn,aN as Me,aO as kn,aP as jn,aQ as wn,aR as yn,aS as Sn,aT as Tn,aU as ve,aV as _n,aW as Rn,I as En,aX as He,aY as In,aZ as Mn,a_ as Pn,a$ as Nn,b0 as Bn,b1 as A,b2 as J,b3 as ee,T as On,b4 as rt,b5 as se,b6 as Fn,b7 as Dn,b8 as Ln,b9 as An,ba as zn,bb as Gn,bc as $n,bd as Hn,be as Pe,bf as lt,bg as it,bh as at,bi as st,bj as ct,bk as ce,bl as de,bm as ue,bn as dt,bo as ut,bp as mt,bq as pt,br as Ue,bs as Un,bt as Ve,bu as Vn,bv as qn,bw as Kn,bx as Qn,by as Wn,bz as Yn,bA as Zn,bB as Xn,bC as Jn,bD as eo,bE as to,bF as no,bG as oo,bH as ro,bI as gt,bJ as bt,bK as lo,bL as io,bM as ao,bN as ft,bO as so,bP as co,bQ as uo,bR as mo,bS as po,bT as ht,bU as xt,N as go,bV as bo,bW as fo,bX as ho,bY as $,bZ as vt,b_ as xo,b$ as M,c0 as N,c1 as V,c2 as vo,c3 as Ct,c4 as Ne,c5 as kt,c6 as Co,c7 as ko,c8 as Be,c9 as jo,ca as wo,cb as yo,cc as So,cd as jt,ce as wt,cf as Oe,cg as To,ch as _o,ci as oe,cj as Ro,ck as qe,cl as Eo,cm as Io}from"./note-runtime-zN5ddTba.js";import{_ as me}from"./preload-helper-BXl3LOEh.js";import{c as Mo}from"./useNoteMutate-BjvZUmtX.js";var yt=d.createContext(void 0);function O(e){return d.useContext(yt)}function v(e){let o=O();if(!o?.editor)throw Error("useBlockNoteEditor was called outside of a BlockNoteContext provider or BlockNoteView component");return o.editor}function w(e,o){let t=(o?.editor??v()).getExtension(e);if(!t)throw Error("Extension not found",{cause:{plugin:e}});return t}function y(e,o){let{store:t}=w(e,o);if(!t)throw Error("Store not found on plugin",{cause:{plugin:e}});return vn(t,o?.selector)}function Po(e){let o=new DOMRect,t="getBoundingClientRect"in e?()=>e.getBoundingClientRect():()=>e.element.getBoundingClientRect();return()=>e.element&&(e.cacheMountedBoundingClientRect??!0)?(e.element.isConnected&&(o=t()),o):t()}function No(e,o){return e?o?(t,n,l)=>{let i=e(t,n,l),s=o(t,n,l);return()=>{i?.(),s?.()}}:e:o}var L=e=>{let o=v(),t=o?.portalElement;if(!t)throw Error("Portal element not found");let{whileElementsMounted:n,...l}=e.useFloatingOptions??{},{refs:i,floatingStyles:s,context:a}=Cn({whileElementsMounted:No(Me,e.useFloatingOptions?.whileElementsMounted),...l}),{isMounted:c,styles:u}=kn(a,e.useTransitionStylesProps),{status:m}=jn(a,e.useTransitionStatusProps),{getFloatingProps:p}=wn([yn(a,e.useDismissProps),Sn(a,{enabled:!1,...e.useHoverProps})]),g=d.useRef(""),b=d.useRef(null),f=Tn([b,i.setFloating]);if(d.useEffect(()=>{if(e.reference){let C="element"in e.reference?e.reference.element:void 0;C!==void 0&&(e.focusManagerProps?.disabled||!o.isWithinEditor(C))&&i.setReference(C),i.setPositionReference({getBoundingClientRect:Po(e.reference),contextElement:C})}},[e.reference,i,e.focusManagerProps?.disabled,o]),d.useEffect(()=>{(m==="initial"||m==="open")&&b.current?.innerHTML&&(g.current=b.current.innerHTML)},[m,e.reference,e.children]),!c)return!1;let x={...e.elementProps,style:{display:"flex",...e.elementProps?.style,zIndex:`calc(var(--bn-ui-base-z-index, 0) + ${e.elementProps?.style?.zIndex||0})`,...s,...u},...p()};return m==="close"?r.jsx(ve,{root:t,children:r.jsx("div",{ref:f,...x,dangerouslySetInnerHTML:{__html:g.current}})}):e.focusManagerProps?.disabled?r.jsx(ve,{root:t,children:r.jsx("div",{ref:f,...x,children:e.children})}):r.jsx(ve,{root:t,children:r.jsx(_n,{...e.focusManagerProps,context:a,children:r.jsx("div",{ref:f,...x,children:e.children})})})},St=d.createContext(void 0);function h(){return d.useContext(St)}function k(){return O().editor.dictionary}var Bo=typeof window<"u"?d.useLayoutEffect:d.useEffect,Oo=class{transactionNumber=0;lastTransactionNumber=0;lastSnapshot;editor;subscribers=new Set;constructor(o){this.editor=o,this.lastSnapshot={editor:o,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(o){return this.subscribers.add(o),()=>{this.subscribers.delete(o)}}watch(o,t){if(this.editor=o,this.editor){let n=()=>{this.transactionNumber+=1,this.subscribers.forEach(s=>s())},l=this.editor._tiptapEditor,i={all:["transaction","create","mount","unmount"],mount:["create","mount","unmount"],selection:["selectionUpdate"],change:["update"]};for(let s of i[t])l.on(s,n);return()=>{for(let s of i[t])l.off(s,n)}}}};function E(e){let o=O(),t=e.editor||o?.editor||null,n=e.on||"all",[l]=d.useState(()=>new Oo(t)),i=Zt.useSyncExternalStoreWithSelector(l.subscribe,l.getSnapshot,l.getServerSnapshot,e.selector,e.equalityFn??Rn);return Bo(()=>l.watch(t,n),[t,l,n]),d.useDebugValue(i),i}function q(e){let o=O();return e||=o?.editor,E({editor:e,selector:t=>t.editor?.domElement,equalityFn:(t,n)=>t===n,on:"mount"})}var Fe=e=>{let{position:o,children:t,...n}=e,{from:l,to:i}=o||{},s=v(),a=q();return r.jsx(L,{reference:d.useMemo(()=>{if(!(l===void 0||i===void 0))return{element:a?.firstElementChild||void 0,getBoundingClientRect:()=>En(s.prosemirrorView,l,i??l)}},[s,a,l,i]),...n,children:o!==void 0&&t})},De=(e={},o=[])=>d.useMemo(()=>{let t=Xt.create(e);return window&&(window.ProseMirror=t._tiptapEditor),t},o),Le=e=>{let[o,t]=d.useState(!1),n=E({editor:e.editor,selector:({editor:a})=>a.isEmpty}),l=h(),i=d.useCallback(()=>{t(!0)},[]),s=d.useCallback(()=>{t(!1)},[]);return d.useEffect(()=>{e.editable&&e.autoFocus&&e.editor.focus()},[e.autoFocus,e.editable,e.editor]),r.jsxs(r.Fragment,{children:[r.jsx(l.Comments.Editor,{autoFocus:e.autoFocus,className:"bn-comment-editor",editor:e.editor,onFocus:i,onBlur:s,editable:e.editable}),e.actions&&r.jsx("div",{className:"bn-comment-actions-wrapper",children:r.jsx(e.actions,{isFocused:o,isEmpty:n})})]})},{textColor:ui,backgroundColor:mi,...Fo}=en,Ae=Jt.create({blockSpecs:{paragraph:tn()},styleSpecs:Fo}),Ke=Object.defineProperty,Tt=(e,o)=>{let t={};for(var n in e)Ke(t,n,{get:e[n],enumerable:!0});return Ke(t,Symbol.toStringTag,{value:"Module"}),t},Ce;async function Do(){return Ce||(Ce=(async()=>{let[e,o]=await Promise.all([me(()=>import("./module-RjUF93sV.js"),[]),me(()=>import("./native-48B9X9Wg.js"),[])]),t="default"in e?e.default:e,n="default"in o?o.default:o;return await t.init({data:n}),{emojiMart:t,emojiData:n}})(),Ce)}function Lo(e){let o=d.useRef(null),t=d.useRef(null);return t.current&&t.current.update(e),d.useEffect(()=>((async()=>{let{emojiMart:n}=await Do();t.current=new n.Picker({...e,ref:o})})(),()=>{t.current=null}),[]),pe.createElement("div",{ref:o})}var Qe=e=>{let[o,t]=d.useState(!1),n=h(),l=O(),i=l.editor?.portalElement;if(!i)throw Error("Portal root not found");return r.jsxs(n.Generic.Popover.Root,{open:o,portalRoot:i,children:[r.jsx(n.Generic.Popover.Trigger,{children:r.jsx("div",{onClick:s=>{s.preventDefault(),s.stopPropagation(),t(!o),e.onOpenChange?.(!o)},style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.children})}),r.jsx(n.Generic.Popover.Content,{className:"bn-emoji-picker-popover",variant:"panel-popover",children:r.jsx(Lo,{perLine:7,onClickOutside:()=>{t(!1),e.onOpenChange?.(!1)},onEmojiSelect:s=>{e.onEmojiSelect(s),t(!1),e.onOpenChange?.(!1)},theme:l?.colorSchemePreference})})]})};function _t(e){return fe([e]).get(e)}function fe(e){let o=w(B).userStore,t=d.useCallback(()=>{let l=new Map;for(let i of e){let s=o.getUser(i);s&&l.set(i,s)}return l},[o,e]),n=d.useMemo(()=>({current:t()}),[t]);return d.useSyncExternalStore(d.useCallback(l=>{let i=o.subscribe(s=>{n.current=t(),l()});return o.loadUsers(e),i},[o,t,e,n]),()=>n.current)}var Ao=e=>{let o=h(),t=k(),n=w(B),l=e.comment.reactions.find(c=>c.emoji===e.emoji);if(!l)throw Error("Trying to render reaction badge for non-existing reaction");let[i,s]=d.useState([]),a=fe(i);return r.jsx(o.Generic.Badge.Root,{className:R("bn-badge","bn-comment-reaction"),text:l.userIds.length.toString(),icon:l.emoji,isSelected:n.threadStore.auth.canDeleteReaction(e.comment,l.emoji),onClick:()=>e.onReactionSelect(l.emoji),onMouseEnter:()=>s(l.userIds),mainTooltip:t.comments.reactions.reacted_by,secondaryTooltip:`${Array.from(a.values()).map(c=>c.username).join(`
1
+ import{r as d,j as r,w as Zt,b as pe,a as ae}from"./floating-ui.react-dom-BWTnA00G.js";import{$ as Xt,q as Jt,U as en,s as tn,v as B,w as R,L as nn,I as on,P as z,D as P,n as Y,Z as U,a as S,C as ge,K as ie,M as Z,b as rn,O as ln,i as be,c as D,Y as _e,V as Ge,d as an,o as sn,e as et,A as cn,x as tt,f as nt,u as dn,g as un,N as X,W as mn,T as ot,H as pn,r as $e,h as gn,j as bn,k as fn,l as hn,m as xn,F as j,p as Re}from"./note-core-YhYEmI_R.js";import{aL as vn,aM as Cn,aN as Me,aO as kn,aP as jn,aQ as wn,aR as yn,aS as Sn,aT as Tn,aU as ve,aV as _n,aW as Rn,I as En,aX as He,aY as In,aZ as Mn,a_ as Pn,a$ as Nn,b0 as Bn,b1 as A,b2 as J,b3 as ee,T as On,b4 as rt,b5 as se,b6 as Fn,b7 as Dn,b8 as Ln,b9 as An,ba as zn,bb as Gn,bc as $n,bd as Hn,be as Pe,bf as lt,bg as it,bh as at,bi as st,bj as ct,bk as ce,bl as de,bm as ue,bn as dt,bo as ut,bp as mt,bq as pt,br as Ue,bs as Un,bt as Ve,bu as Vn,bv as qn,bw as Kn,bx as Qn,by as Wn,bz as Yn,bA as Zn,bB as Xn,bC as Jn,bD as eo,bE as to,bF as no,bG as oo,bH as ro,bI as gt,bJ as bt,bK as lo,bL as io,bM as ao,bN as ft,bO as so,bP as co,bQ as uo,bR as mo,bS as po,bT as ht,bU as xt,N as go,bV as bo,bW as fo,bX as ho,bY as $,bZ as vt,b_ as xo,b$ as M,c0 as N,c1 as V,c2 as vo,c3 as Ct,c4 as Ne,c5 as kt,c6 as Co,c7 as ko,c8 as Be,c9 as jo,ca as wo,cb as yo,cc as So,cd as jt,ce as wt,cf as Oe,cg as To,ch as _o,ci as oe,cj as Ro,ck as qe,cl as Eo,cm as Io}from"./note-runtime-B3ats-dC.js";import{_ as me}from"./preload-helper-BXl3LOEh.js";import{c as Mo}from"./useNoteMutate-BjvZUmtX.js";var yt=d.createContext(void 0);function O(e){return d.useContext(yt)}function v(e){let o=O();if(!o?.editor)throw Error("useBlockNoteEditor was called outside of a BlockNoteContext provider or BlockNoteView component");return o.editor}function w(e,o){let t=(o?.editor??v()).getExtension(e);if(!t)throw Error("Extension not found",{cause:{plugin:e}});return t}function y(e,o){let{store:t}=w(e,o);if(!t)throw Error("Store not found on plugin",{cause:{plugin:e}});return vn(t,o?.selector)}function Po(e){let o=new DOMRect,t="getBoundingClientRect"in e?()=>e.getBoundingClientRect():()=>e.element.getBoundingClientRect();return()=>e.element&&(e.cacheMountedBoundingClientRect??!0)?(e.element.isConnected&&(o=t()),o):t()}function No(e,o){return e?o?(t,n,l)=>{let i=e(t,n,l),s=o(t,n,l);return()=>{i?.(),s?.()}}:e:o}var L=e=>{let o=v(),t=o?.portalElement;if(!t)throw Error("Portal element not found");let{whileElementsMounted:n,...l}=e.useFloatingOptions??{},{refs:i,floatingStyles:s,context:a}=Cn({whileElementsMounted:No(Me,e.useFloatingOptions?.whileElementsMounted),...l}),{isMounted:c,styles:u}=kn(a,e.useTransitionStylesProps),{status:m}=jn(a,e.useTransitionStatusProps),{getFloatingProps:p}=wn([yn(a,e.useDismissProps),Sn(a,{enabled:!1,...e.useHoverProps})]),g=d.useRef(""),b=d.useRef(null),f=Tn([b,i.setFloating]);if(d.useEffect(()=>{if(e.reference){let C="element"in e.reference?e.reference.element:void 0;C!==void 0&&(e.focusManagerProps?.disabled||!o.isWithinEditor(C))&&i.setReference(C),i.setPositionReference({getBoundingClientRect:Po(e.reference),contextElement:C})}},[e.reference,i,e.focusManagerProps?.disabled,o]),d.useEffect(()=>{(m==="initial"||m==="open")&&b.current?.innerHTML&&(g.current=b.current.innerHTML)},[m,e.reference,e.children]),!c)return!1;let x={...e.elementProps,style:{display:"flex",...e.elementProps?.style,zIndex:`calc(var(--bn-ui-base-z-index, 0) + ${e.elementProps?.style?.zIndex||0})`,...s,...u},...p()};return m==="close"?r.jsx(ve,{root:t,children:r.jsx("div",{ref:f,...x,dangerouslySetInnerHTML:{__html:g.current}})}):e.focusManagerProps?.disabled?r.jsx(ve,{root:t,children:r.jsx("div",{ref:f,...x,children:e.children})}):r.jsx(ve,{root:t,children:r.jsx(_n,{...e.focusManagerProps,context:a,children:r.jsx("div",{ref:f,...x,children:e.children})})})},St=d.createContext(void 0);function h(){return d.useContext(St)}function k(){return O().editor.dictionary}var Bo=typeof window<"u"?d.useLayoutEffect:d.useEffect,Oo=class{transactionNumber=0;lastTransactionNumber=0;lastSnapshot;editor;subscribers=new Set;constructor(o){this.editor=o,this.lastSnapshot={editor:o,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(o){return this.subscribers.add(o),()=>{this.subscribers.delete(o)}}watch(o,t){if(this.editor=o,this.editor){let n=()=>{this.transactionNumber+=1,this.subscribers.forEach(s=>s())},l=this.editor._tiptapEditor,i={all:["transaction","create","mount","unmount"],mount:["create","mount","unmount"],selection:["selectionUpdate"],change:["update"]};for(let s of i[t])l.on(s,n);return()=>{for(let s of i[t])l.off(s,n)}}}};function E(e){let o=O(),t=e.editor||o?.editor||null,n=e.on||"all",[l]=d.useState(()=>new Oo(t)),i=Zt.useSyncExternalStoreWithSelector(l.subscribe,l.getSnapshot,l.getServerSnapshot,e.selector,e.equalityFn??Rn);return Bo(()=>l.watch(t,n),[t,l,n]),d.useDebugValue(i),i}function q(e){let o=O();return e||=o?.editor,E({editor:e,selector:t=>t.editor?.domElement,equalityFn:(t,n)=>t===n,on:"mount"})}var Fe=e=>{let{position:o,children:t,...n}=e,{from:l,to:i}=o||{},s=v(),a=q();return r.jsx(L,{reference:d.useMemo(()=>{if(!(l===void 0||i===void 0))return{element:a?.firstElementChild||void 0,getBoundingClientRect:()=>En(s.prosemirrorView,l,i??l)}},[s,a,l,i]),...n,children:o!==void 0&&t})},De=(e={},o=[])=>d.useMemo(()=>{let t=Xt.create(e);return window&&(window.ProseMirror=t._tiptapEditor),t},o),Le=e=>{let[o,t]=d.useState(!1),n=E({editor:e.editor,selector:({editor:a})=>a.isEmpty}),l=h(),i=d.useCallback(()=>{t(!0)},[]),s=d.useCallback(()=>{t(!1)},[]);return d.useEffect(()=>{e.editable&&e.autoFocus&&e.editor.focus()},[e.autoFocus,e.editable,e.editor]),r.jsxs(r.Fragment,{children:[r.jsx(l.Comments.Editor,{autoFocus:e.autoFocus,className:"bn-comment-editor",editor:e.editor,onFocus:i,onBlur:s,editable:e.editable}),e.actions&&r.jsx("div",{className:"bn-comment-actions-wrapper",children:r.jsx(e.actions,{isFocused:o,isEmpty:n})})]})},{textColor:ui,backgroundColor:mi,...Fo}=en,Ae=Jt.create({blockSpecs:{paragraph:tn()},styleSpecs:Fo}),Ke=Object.defineProperty,Tt=(e,o)=>{let t={};for(var n in e)Ke(t,n,{get:e[n],enumerable:!0});return Ke(t,Symbol.toStringTag,{value:"Module"}),t},Ce;async function Do(){return Ce||(Ce=(async()=>{let[e,o]=await Promise.all([me(()=>import("./module-RjUF93sV.js"),[]),me(()=>import("./native-48B9X9Wg.js"),[])]),t="default"in e?e.default:e,n="default"in o?o.default:o;return await t.init({data:n}),{emojiMart:t,emojiData:n}})(),Ce)}function Lo(e){let o=d.useRef(null),t=d.useRef(null);return t.current&&t.current.update(e),d.useEffect(()=>((async()=>{let{emojiMart:n}=await Do();t.current=new n.Picker({...e,ref:o})})(),()=>{t.current=null}),[]),pe.createElement("div",{ref:o})}var Qe=e=>{let[o,t]=d.useState(!1),n=h(),l=O(),i=l.editor?.portalElement;if(!i)throw Error("Portal root not found");return r.jsxs(n.Generic.Popover.Root,{open:o,portalRoot:i,children:[r.jsx(n.Generic.Popover.Trigger,{children:r.jsx("div",{onClick:s=>{s.preventDefault(),s.stopPropagation(),t(!o),e.onOpenChange?.(!o)},style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.children})}),r.jsx(n.Generic.Popover.Content,{className:"bn-emoji-picker-popover",variant:"panel-popover",children:r.jsx(Lo,{perLine:7,onClickOutside:()=>{t(!1),e.onOpenChange?.(!1)},onEmojiSelect:s=>{e.onEmojiSelect(s),t(!1),e.onOpenChange?.(!1)},theme:l?.colorSchemePreference})})]})};function _t(e){return fe([e]).get(e)}function fe(e){let o=w(B).userStore,t=d.useCallback(()=>{let l=new Map;for(let i of e){let s=o.getUser(i);s&&l.set(i,s)}return l},[o,e]),n=d.useMemo(()=>({current:t()}),[t]);return d.useSyncExternalStore(d.useCallback(l=>{let i=o.subscribe(s=>{n.current=t(),l()});return o.loadUsers(e),i},[o,t,e,n]),()=>n.current)}var Ao=e=>{let o=h(),t=k(),n=w(B),l=e.comment.reactions.find(c=>c.emoji===e.emoji);if(!l)throw Error("Trying to render reaction badge for non-existing reaction");let[i,s]=d.useState([]),a=fe(i);return r.jsx(o.Generic.Badge.Root,{className:R("bn-badge","bn-comment-reaction"),text:l.userIds.length.toString(),icon:l.emoji,isSelected:n.threadStore.auth.canDeleteReaction(e.comment,l.emoji),onClick:()=>e.onReactionSelect(l.emoji),onMouseEnter:()=>s(l.userIds),mainTooltip:t.comments.reactions.reacted_by,secondaryTooltip:`${Array.from(a.values()).map(c=>c.username).join(`
2
2
  `)}`},l.emoji)},Rt=({comment:e,thread:o,showResolveButton:t})=>{let n=w(B),l=k(),i=De({initialContent:e.body,trailingBlock:!1,dictionary:{...l,placeholders:{emptyDocument:l.placeholders.edit_comment}},schema:n.commentEditorSchema||Ae}),s=h(),[a,c]=d.useState(!1),[u,m]=d.useState(!1),p=n.threadStore,g=d.useCallback(()=>{c(!0)},[]),b=d.useCallback(()=>{i.replaceBlocks(i.document,e.body),c(!1)},[i,e.body]),f=d.useCallback(async _=>{await p.updateComment({commentId:e.id,comment:{body:i.document},threadId:o.id}),c(!1)},[e,o.id,i,p]),x=d.useCallback(async()=>{await p.deleteComment({commentId:e.id,threadId:o.id})},[e,o.id,p]),C=d.useCallback(async _=>{p.auth.canAddReaction(e,_)?await p.addReaction({threadId:o.id,commentId:e.id,emoji:_}):p.auth.canDeleteReaction(e,_)&&await p.deleteReaction({threadId:o.id,commentId:e.id,emoji:_})},[p,e,o.id]),T=d.useCallback(async()=>{await p.resolveThread({threadId:o.id})},[o.id,p]),I=d.useCallback(async()=>{await p.unresolveThread({threadId:o.id})},[o.id,p]),F=_t(e.userId);if(!e.body)return null;let Q,te=p.auth.canAddReaction(e),K=p.auth.canDeleteComment(e),ne=p.auth.canUpdateComment(e),xe=t&&(o.resolved?p.auth.canUnresolveThread(o):p.auth.canResolveThread(o));a||(Q=r.jsxs(s.Generic.Toolbar.Root,{className:R("bn-action-toolbar","bn-comment-actions"),variant:"action-toolbar",children:[te&&r.jsx(Qe,{onEmojiSelect:_=>C(_.native),onOpenChange:m,children:r.jsx(s.Generic.Toolbar.Button,{mainTooltip:l.comments.actions.add_reaction,variant:"compact",children:r.jsx(He,{size:16})},"add-reaction")}),xe&&(o.resolved?r.jsx(s.Generic.Toolbar.Button,{mainTooltip:"Re-open",variant:"compact",onClick:I,children:r.jsx(In,{size:16})},"reopen"):r.jsx(s.Generic.Toolbar.Button,{mainTooltip:l.comments.actions.resolve,variant:"compact",onClick:T,children:r.jsx(Mn,{size:16})},"resolve")),(K||ne)&&r.jsxs(s.Generic.Menu.Root,{position:"bottom-start",children:[r.jsx(s.Generic.Menu.Trigger,{children:r.jsx(s.Generic.Toolbar.Button,{mainTooltip:l.comments.actions.more_actions,variant:"compact",children:r.jsx(Pn,{size:16})},"more-actions")}),r.jsxs(s.Generic.Menu.Dropdown,{className:"bn-menu-dropdown",children:[ne&&r.jsx(s.Generic.Menu.Item,{icon:r.jsx(Nn,{}),onClick:g,children:l.comments.actions.edit_comment},"edit-comment"),K&&r.jsx(s.Generic.Menu.Item,{icon:r.jsx(Bn,{}),onClick:x,children:l.comments.actions.delete_comment},"delete-comment")]})]})]}));let G=e.createdAt.toLocaleDateString(void 0,{month:"short",day:"numeric"});if(!e.body)throw Error("soft deletes are not yet supported");return r.jsx(s.Comments.Comment,{authorInfo:F??"loading",timeString:G,edited:e.updatedAt.getTime()!==e.createdAt.getTime(),showActions:"hover",actions:Q,className:"bn-thread-comment",emojiPickerOpen:u,children:r.jsx(Le,{autoFocus:a,editor:i,editable:a,actions:e.reactions.length>0||a?({isEmpty:_})=>r.jsxs(r.Fragment,{children:[e.reactions.length>0&&!a&&r.jsxs(s.Generic.Badge.Group,{className:R("bn-badge-group","bn-comment-reactions"),children:[e.reactions.map(H=>r.jsx(Ao,{comment:e,emoji:H.emoji,onReactionSelect:C},H.emoji)),te&&r.jsx(Qe,{onEmojiSelect:H=>C(H.native),onOpenChange:m,children:r.jsx(s.Generic.Badge.Root,{className:R("bn-badge","bn-comment-add-reaction"),text:"+",icon:r.jsx(He,{size:16}),mainTooltip:l.comments.actions.add_reaction})})]}),a&&r.jsxs(s.Generic.Toolbar.Root,{variant:"action-toolbar",className:R("bn-action-toolbar","bn-comment-actions"),children:[r.jsx(s.Generic.Toolbar.Button,{mainTooltip:l.comments.save_button_text,variant:"compact",onClick:f,isDisabled:_,children:l.comments.save_button_text}),r.jsx(s.Generic.Toolbar.Button,{className:"bn-button",mainTooltip:l.comments.cancel_button_text,variant:"compact",onClick:b,children:l.comments.cancel_button_text})]})]}):void 0})})},Et=({thread:e,maxCommentsBeforeCollapse:o})=>{let t=h(),n=k(),l=fe(e.resolvedBy?[e.resolvedBy]:[]),i=e.comments.map((s,a)=>r.jsx(Rt,{thread:e,comment:s,showResolveButton:a===0},s.id+JSON.stringify(s.body||"{}")));if(e.resolved&&e.resolvedUpdatedAt&&e.resolvedBy){if(!l.get(e.resolvedBy))throw Error(`User ${e.resolvedBy} resolved thread ${e.id}, but their data could not be found.`);let s=e.comments.findLastIndex(a=>e.resolvedUpdatedAt.getTime()>a.createdAt.getTime())+1;i.splice(s,0,r.jsx(t.Comments.Comment,{className:"bn-thread-comment",authorInfo:e.resolvedBy&&l.get(e.resolvedBy)||"loading",timeString:e.resolvedUpdatedAt.toLocaleDateString(void 0,{month:"short",day:"numeric"}),edited:!1,showActions:!1,children:r.jsx("div",{className:"bn-resolved-text",children:n.comments.sidebar.marked_as_resolved})},"resolved-comment"))}return o&&i.length>o&&i.splice(1,i.length-2,r.jsx(t.Comments.ExpandSectionsPrompt,{className:"bn-thread-expand-prompt",children:n.comments.sidebar.more_replies(e.comments.length-2)},"expand-prompt")),i},ze=({thread:e,selected:o,referenceText:t,maxCommentsBeforeCollapse:n,onFocus:l,onBlur:i,tabIndex:s})=>{let a=h(),c=k(),u=w(B),m=De({trailingBlock:!1,dictionary:{...c,placeholders:{emptyDocument:c.placeholders.comment_reply}},schema:u.commentEditorSchema||Ae}),p=d.useCallback(async()=>{await u.threadStore.addComment({comment:{body:m.document},threadId:e.id}),m.removeBlocks(m.document)},[u,m,e.id]);return r.jsxs(a.Comments.Card,{className:"bn-thread",headerText:t,onFocus:l,onBlur:i,selected:o,tabIndex:s,children:[r.jsx(a.Comments.CardSection,{className:"bn-thread-comments",children:r.jsx(Et,{thread:e,maxCommentsBeforeCollapse:o?void 0:n||5})}),o&&r.jsx(a.Comments.CardSection,{className:"bn-thread-composer",children:r.jsx(Le,{autoFocus:!1,editable:!0,editor:m,actions:({isEmpty:g})=>g?null:r.jsx(a.Generic.Toolbar.Root,{variant:"action-toolbar",className:R("bn-action-toolbar","bn-comment-actions"),children:r.jsx(a.Generic.Toolbar.Button,{mainTooltip:c.comments.save_button_text,variant:"compact",isDisabled:g,onClick:p,children:c.comments.save_button_text})})})})]})};function It(){let e=w(B).threadStore,o=d.useRef(void 0);return o.current||=e.getThreads(),d.useSyncExternalStore(d.useCallback(t=>e.subscribe(n=>{o.current=n,t()}),[e]),()=>o.current)}var zo=Tt({default:()=>Mt});function Mt(e){let o=v(),t=w(B),n=y(B,{editor:o,selector:c=>c.selectedThreadId?{id:c.selectedThreadId,position:c.threadPositions.get(c.selectedThreadId)}:void 0}),l=It(),i=d.useMemo(()=>n?l.get(n.id):void 0,[n,l]),s=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:!!n,onOpenChange:(c,u,m)=>{m==="escape-key"&&o.focus(),c||t.selectThread(void 0)},placement:"bottom",middleware:[A(10),J(),ee()],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:30},...e.floatingUIOptions?.elementProps}}),[t,o,e.floatingUIOptions,n]),a=e.floatingThread||ze;return r.jsx(Fe,{position:n?.position,...s,children:i&&r.jsx(a,{thread:i,selected:!0})})}const Go=Object.freeze(Object.defineProperty({__proto__:null,a:Et,c:fe,i:ze,n:zo,o:Rt,r:It,s:_t,t:Mt},Symbol.toStringTag,{value:"Module"}));function Pt(){let e=v(),o=w(B),t=h(),n=k(),l=De({trailingBlock:!1,dictionary:{...n,placeholders:{emptyDocument:n.placeholders.new_comment}},schema:o.commentEditorSchema||Ae});return r.jsx(t.Comments.Card,{className:"bn-thread",children:r.jsx(Le,{autoFocus:!0,editable:!0,editor:l,actions:({isEmpty:i})=>r.jsx(t.Generic.Toolbar.Root,{className:R("bn-action-toolbar","bn-comment-actions"),variant:"action-toolbar",children:r.jsx(t.Generic.Toolbar.Button,{className:"bn-button",mainTooltip:"Save",variant:"compact",isDisabled:i,onClick:async()=>{await o.createThread({initialComment:{body:l.document}}),o.stopPendingComment(),e.transact(s=>{s.setSelection(On.create(s.doc,s.selection.to))}),e.focus()},children:"Save"})})})})}var $o=Tt({default:()=>Nt});function Nt(e){let o=v(),t=w(B),n=y(B,{editor:o,selector:a=>a.pendingComment}),l=E({editor:o,selector:({editor:a})=>n?{from:a.prosemirrorState.selection.from,to:a.prosemirrorState.selection.to}:void 0}),i=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:!!n,onOpenChange:a=>{a||(t.stopPendingComment(),o.focus())},placement:"bottom",middleware:[A(10),J(),ee()],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!1},elementProps:{style:{zIndex:60},...e.floatingUIOptions?.elementProps}}),[t,o,n,e.floatingUIOptions]),s=e.floatingComposer||Pt;return r.jsx(Fe,{position:l,...i,children:r.jsx(s,{})})}const Ho=Object.freeze(Object.defineProperty({__proto__:null,n:$o,r:Pt,t:Nt},Symbol.toStringTag,{value:"Module"}));var Bt=e=>{let{blockId:o,children:t,...n}=e,l=v();return r.jsx(L,{reference:d.useMemo(()=>l.transact(i=>{if(!o)return;let s=et(o,i.doc);if(!s)return;let{node:a}=l.prosemirrorView.domAtPos(s.posBeforeNode+1);if(a instanceof Element)return{element:a}}),[l,o]),...n,children:o!==void 0&&t})},Uo=e=>{let o=h(),t=k(),n=v(),l=n.getBlock(e.blockId),[i,s]=d.useState(""),a=d.useCallback(m=>{s(m.currentTarget.value)},[]),c=d.useCallback(m=>{m.key==="Enter"&&!m.nativeEvent.isComposing&&(m.preventDefault(),n.updateBlock(l.id,{props:{name:Ge(i),url:i}}))},[n,l.id,i]),u=d.useCallback(()=>{n.updateBlock(l.id,{props:{name:Ge(i),url:i}})},[n,l.id,i]);return r.jsxs(o.FilePanel.TabPanel,{className:"bn-tab-panel",children:[r.jsx(o.FilePanel.TextInput,{className:"bn-text-input",placeholder:t.file_panel.embed.url_placeholder,value:i,onChange:a,onKeyDown:c,"data-test":"embed-input"}),r.jsx(o.FilePanel.Button,{className:"bn-button",onClick:u,"data-test":"embed-input-button",children:t.file_panel.embed.embed_button[l.type]||t.file_panel.embed.embed_button.file})]})},Vo=e=>{let o=h(),t=k(),{setLoading:n}=e,l=v(),i=l.getBlock(e.blockId),[s,a]=d.useState(!1);d.useEffect(()=>{s&&setTimeout(()=>{a(!1)},3e3)},[s]);let c=d.useCallback(p=>{if(p===null)return;async function g(b){if(n(!0),l.uploadFile!==void 0)try{let f=await l.uploadFile(b,e.blockId);typeof f=="string"&&(f={props:{name:b.name,url:f}}),l.updateBlock(e.blockId,f)}catch{a(!0)}finally{n(!1)}}g(p)},[e.blockId,l,n]),u=l.schema.blockSpecs[i.type],m=u.implementation.meta?.fileBlockAccept?.length?u.implementation.meta.fileBlockAccept.join(","):"*/*";return r.jsxs(o.FilePanel.TabPanel,{className:"bn-tab-panel",children:[r.jsx(o.FilePanel.FileInput,{className:"bn-file-input","data-test":"upload-input",accept:m,placeholder:t.file_panel.upload.file_placeholder[i.type]||t.file_panel.upload.file_placeholder.file,value:null,onChange:c}),s&&r.jsx("div",{className:"bn-error-text",children:t.file_panel.upload.upload_error})]})},Ot=e=>{let o=h(),t=k(),n=v(),[l,i]=d.useState(!1),s=e.tabs??[...n.uploadFile===void 0?[]:[{name:t.file_panel.upload.title,tabPanel:r.jsx(Vo,{blockId:e.blockId,setLoading:i})}],{name:t.file_panel.embed.title,tabPanel:r.jsx(Uo,{blockId:e.blockId})}],[a,c]=d.useState(e.defaultOpenTab||s[0].name);return r.jsx(o.FilePanel.Root,{className:"bn-panel",defaultOpenTab:a,openTab:a,setOpenTab:c,tabs:s,loading:l})},qo=e=>{let o=v(),t=w(_e),n=y(_e),l=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:!!n,onOpenChange:(s,a,c)=>{s||t.closeMenu(),c==="escape-key"&&o.focus()},middleware:[A(10),ee()],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:90},...e.floatingUIOptions?.elementProps}}),[n,o,t,e.floatingUIOptions]),i=e.filePanel||Ot;return r.jsx(Bt,{blockId:n,...l,children:n&&r.jsx(i,{blockId:n})})},Ko={bold:Xn,italic:Zn,underline:Yn,strike:Wn,code:Qn};function Qo(e,o){return e in o.schema.styleSchema&&o.schema.styleSchema[e].type===e&&o.schema.styleSchema[e].propSchema==="boolean"}var re=e=>{let o=k(),t=h(),n=v(),l=E({editor:n,selector:({editor:a})=>{if(!(!a.isEditable||!Qo(e.basicTextStyle,a)||!(a.getSelection()?.blocks||[a.getTextCursorPosition().block]).find(c=>c.content!==void 0)))return e.basicTextStyle in a.getActiveStyles()?{active:!0}:{active:!1}}}),i=d.useCallback(a=>{n.focus(),n.toggleStyles({[a]:!0})},[n,e]);if(l===void 0)return null;let s=Ko[e.basicTextStyle];return r.jsx(t.FormattingToolbar.Button,{className:"bn-button","data-test":e.basicTextStyle,onClick:()=>i(e.basicTextStyle),isSelected:l.active,label:o.formatting_toolbar[e.basicTextStyle].tooltip,mainTooltip:o.formatting_toolbar[e.basicTextStyle].tooltip,secondaryTooltip:ge(o.formatting_toolbar[e.basicTextStyle].secondary_tooltip,o.generic.ctrl_shortcut),icon:r.jsx(s,{})})},Ee=e=>{let o=e.textColor||"default",t=e.backgroundColor||"default",n=e.size||16;return r.jsx("div",{className:"bn-color-icon","data-background-color":t,"data-text-color":o,style:d.useMemo(()=>({pointerEvents:"none",fontSize:(n*.75).toString()+"px",height:n.toString()+"px",lineHeight:n.toString()+"px",textAlign:"center",width:n.toString()+"px"}),[n]),children:"A"})},We=["default","gray","brown","red","orange","yellow","green","blue","purple","pink"],he=e=>{let o=h(),t=k();return r.jsxs(r.Fragment,{children:[r.jsx(()=>e.text?r.jsxs(r.Fragment,{children:[r.jsx(o.Generic.Menu.Label,{children:t.color_picker.text_title}),We.map(n=>r.jsx(o.Generic.Menu.Item,{onClick:()=>{e.onClick&&e.onClick(),e.text.setColor(n)},"data-test":"text-color-"+n,icon:r.jsx(Ee,{textColor:n,size:e.iconSize}),checked:e.text.color===n,children:t.color_picker.colors[n]},"text-color-"+n))]}):null,{}),r.jsx(()=>e.background?r.jsxs(r.Fragment,{children:[r.jsx(o.Generic.Menu.Label,{children:t.color_picker.background_title}),We.map(n=>r.jsx(o.Generic.Menu.Item,{onClick:()=>{e.onClick&&e.onClick(),e.background.setColor(n)},"data-test":"background-color-"+n,icon:r.jsx(Ee,{backgroundColor:n,size:e.iconSize}),checked:e.background.color===n,children:t.color_picker.colors[n]},"background-color-"+n))]}):null,{})]})};function le(e,o){return`${e}Color`in o.schema.styleSchema&&o.schema.styleSchema[`${e}Color`].type===`${e}Color`&&o.schema.styleSchema[`${e}Color`].propSchema==="string"}var Wo=()=>{let e=h(),o=k(),t=v(),n=le("text",t),l=le("background",t),i=E({editor:t,selector:({editor:c})=>{if(!c.isEditable||!(c.getSelection()?.blocks||[c.getTextCursorPosition().block]).find(p=>p.content!==void 0))return;let u=le("text",c),m=le("background",c);if(!(!u&&!m))return{textColor:u?c.getActiveStyles().textColor||"default":void 0,backgroundColor:m?c.getActiveStyles().backgroundColor||"default":void 0}}}),s=d.useCallback(c=>{if(!n)throw Error("Tried to set text color, but style does not exist in editor schema.");c==="default"?t.removeStyles({textColor:c}):t.addStyles({textColor:c}),setTimeout(()=>{t.focus()})},[t,n]),a=d.useCallback(c=>{if(!l)throw Error("Tried to set background color, but style does not exist in editor schema.");c==="default"?t.removeStyles({backgroundColor:c}):t.addStyles({backgroundColor:c}),setTimeout(()=>{t.focus()})},[l,t]);return i===void 0?null:r.jsxs(e.Generic.Menu.Root,{children:[r.jsx(e.Generic.Menu.Trigger,{children:r.jsx(e.FormattingToolbar.Button,{className:"bn-button","data-test":"colors",label:o.formatting_toolbar.colors.tooltip,mainTooltip:o.formatting_toolbar.colors.tooltip,icon:r.jsx(Ee,{textColor:i.textColor,backgroundColor:i.backgroundColor,size:20})})}),r.jsx(e.Generic.Menu.Dropdown,{className:"bn-menu-dropdown bn-color-picker-dropdown",children:r.jsx(he,{text:i.textColor?{color:i.textColor,setColor:s}:void 0,background:i.backgroundColor?{color:i.backgroundColor,setColor:a}:void 0})})]})},Ye=e=>{for(let o of an)if(e.startsWith(o))return e;return`${sn}://${e}`},Ft=e=>{let o=h(),t=k(),{editLink:n}=w(be),{url:l,text:i,showTextField:s}=e,[a,c]=d.useState(l),[u,m]=d.useState(i);d.useEffect(()=>{c(l),m(i)},[i,l]);let p=d.useCallback(x=>{x.key==="Enter"&&!x.nativeEvent.isComposing&&(x.preventDefault(),n(Ye(a),u,e.range.from),e.setToolbarOpen?.(!1),e.setToolbarPositionFrozen?.(!1))},[n,a,u,e]),g=d.useCallback(x=>c(x.currentTarget.value),[]),b=d.useCallback(x=>m(x.currentTarget.value),[]),f=d.useCallback(()=>{n(Ye(a),u,e.range.from),e.setToolbarOpen?.(!1),e.setToolbarPositionFrozen?.(!1)},[n,a,u,e]);return r.jsxs(o.Generic.Form.Root,{children:[r.jsx(o.Generic.Form.TextInput,{className:"bn-text-input",name:"url",icon:r.jsx(gt,{}),autoFocus:!0,placeholder:t.link_toolbar.form.url_placeholder,value:a,onKeyDown:p,onChange:g,onSubmit:f}),s!==!1&&r.jsx(o.Generic.Form.TextInput,{className:"bn-text-input",name:"title",icon:r.jsx(Pe,{}),placeholder:t.link_toolbar.form.title_placeholder,value:u,onKeyDown:p,onChange:b,onSubmit:f})]})};function Yo(e){return"link"in e.schema.inlineContentSchema&&e.schema.inlineContentSchema.link==="link"}var Zo=()=>{let e=v(),o=q(),t=h(),n=k(),l=w(Y),{showSelection:i}=w(rn),[s,a]=d.useState(!1);d.useEffect(()=>(i(s,"createLinkButton"),()=>i(!1,"createLinkButton")),[s,i]);let c=E({editor:e,selector:({editor:u})=>{if(!(!u.isEditable||!Yo(u)||ln(u.prosemirrorState.selection)||!(u.getSelection()?.blocks||[u.getTextCursorPosition().block]).find(m=>m.content!==void 0)))return{url:u.getSelectedLinkUrl(),text:u.getSelectedText(),range:{from:u.prosemirrorState.selection.from,to:u.prosemirrorState.selection.to}}}});return d.useEffect(()=>{a(!1)},[c]),d.useEffect(()=>{let u=m=>{(m.ctrlKey||m.metaKey)&&m.key==="k"&&(a(!0),m.preventDefault())};return o?.addEventListener("keydown",u),()=>{o?.removeEventListener("keydown",u)}},[o]),c===void 0?null:r.jsxs(t.Generic.Popover.Root,{open:s,onOpenChange:a,children:[r.jsx(t.Generic.Popover.Trigger,{children:r.jsx(t.FormattingToolbar.Button,{className:"bn-button","data-test":"createLink",label:n.formatting_toolbar.link.tooltip,mainTooltip:n.formatting_toolbar.link.tooltip,secondaryTooltip:ge(n.formatting_toolbar.link.secondary_tooltip,n.generic.ctrl_shortcut),icon:r.jsx(gt,{}),onClick:()=>a(u=>!u)})}),r.jsx(t.Generic.Popover.Content,{className:"bn-popover-content bn-form-popover",variant:"form-popover",children:r.jsx(Ft,{url:c.url||"",text:c.text,range:c.range,showTextField:!1,setToolbarOpen:u=>l.store.setState(u)})})]})},Xo=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:c})=>{if(!c.isEditable)return;let u=c.getSelection()?.blocks||[c.getTextCursorPosition().block];if(u.length!==1)return;let m=u[0];if(P(m,c,m.type,{url:"string",caption:"string"}))return m}}),[l,i]=d.useState(!1),s=d.useCallback(c=>{n!==void 0&&U(t,n.type,{caption:"string"})&&t.updateBlock(n.id,{props:{caption:c.currentTarget.value}})},[n,t]),a=d.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(c.preventDefault(),i(!1))},[]);return n===void 0?null:r.jsxs(o.Generic.Popover.Root,{open:l,onOpenChange:i,children:[r.jsx(o.Generic.Popover.Trigger,{children:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.file_caption.tooltip,mainTooltip:e.formatting_toolbar.file_caption.tooltip,icon:r.jsx(Ue,{}),onClick:()=>i(c=>!c)})}),r.jsx(o.Generic.Popover.Content,{className:"bn-popover-content bn-form-popover",variant:"form-popover",children:r.jsx(o.Generic.Form.Root,{children:r.jsx(o.Generic.Form.TextInput,{name:"file-caption",icon:r.jsx(Ue,{}),value:n.props.caption,autoFocus:!0,placeholder:e.formatting_toolbar.file_caption.input_placeholder,onKeyDown:a,onChange:s})})})]})},Jo=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:i})=>{if(!i.isEditable)return;let s=i.getSelection()?.blocks||[i.getTextCursorPosition().block];if(s.length!==1)return;let a=s[0];if(P(a,i,a.type,{url:"string"}))return a}}),l=d.useCallback(()=>{n!==void 0&&(t.focus(),t.removeBlocks([n.id]))},[n,t]);return n===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.file_delete.tooltip[n.type]||e.formatting_toolbar.file_delete.tooltip.file,mainTooltip:e.formatting_toolbar.file_delete.tooltip[n.type]||e.formatting_toolbar.file_delete.tooltip.file,icon:r.jsx(Vn,{}),onClick:l})},er=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:c})=>{if(!c.isEditable)return;let u=c.getSelection()?.blocks||[c.getTextCursorPosition().block];if(u.length!==1)return;let m=u[0];if(P(m,c,m.type,{url:"string",name:"string"}))return m}}),[l,i]=d.useState(!1),s=d.useCallback(c=>{n!==void 0&&U(t,n.type,{name:"string"})&&t.updateBlock(n.id,{props:{name:c.currentTarget.value}})},[n,t]),a=d.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(c.preventDefault(),i(!1))},[]);return n===void 0?null:r.jsxs(o.Generic.Popover.Root,{open:l,onOpenChange:i,children:[r.jsx(o.Generic.Popover.Trigger,{children:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.file_rename.tooltip[n.type]||e.formatting_toolbar.file_rename.tooltip.file,mainTooltip:e.formatting_toolbar.file_rename.tooltip[n.type]||e.formatting_toolbar.file_rename.tooltip.file,icon:r.jsx(Ve,{}),onClick:()=>i(c=>!c)})}),r.jsx(o.Generic.Popover.Content,{className:"bn-popover-content bn-form-popover",variant:"form-popover",children:r.jsx(o.Generic.Form.Root,{children:r.jsx(o.Generic.Form.TextInput,{name:"file-name",icon:r.jsx(Ve,{}),value:n.props.name,autoFocus:!0,placeholder:e.formatting_toolbar.file_rename.input_placeholder[n.type]||e.formatting_toolbar.file_rename.input_placeholder.file,onKeyDown:a,onChange:s})})})]})},tr=()=>{let e=k(),o=h(),t=E({editor:v(),selector:({editor:n})=>{if(!n.isEditable)return;let l=n.getSelection()?.blocks||[n.getTextCursorPosition().block];if(l.length!==1)return;let i=l[0];if(P(i,n,i.type,{url:"string"}))return i}});return t===void 0?null:r.jsxs(o.Generic.Popover.Root,{position:"bottom",children:[r.jsx(o.Generic.Popover.Trigger,{children:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",mainTooltip:e.formatting_toolbar.file_replace.tooltip[t.type]||e.formatting_toolbar.file_replace.tooltip.file,label:e.formatting_toolbar.file_replace.tooltip[t.type]||e.formatting_toolbar.file_replace.tooltip.file,icon:r.jsx(Un,{})})}),r.jsx(o.Generic.Popover.Content,{className:"bn-popover-content bn-panel-popover",variant:"panel-popover",children:r.jsx(Ot,{blockId:t.id})})]})},nr=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:i})=>{if(!(!i.isEditable||!(i.getSelection()?.blocks||[i.getTextCursorPosition().block]).find(s=>s.content!==void 0)))return{canNestBlock:i.canNestBlock()}}}),l=d.useCallback(()=>{n!==void 0&&n.canNestBlock&&(t.focus(),t.nestBlock())},[t,n]);return n===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button","data-test":"nestBlock",onClick:l,isDisabled:!n.canNestBlock,label:e.formatting_toolbar.nest.tooltip,mainTooltip:e.formatting_toolbar.nest.tooltip,secondaryTooltip:ge(e.formatting_toolbar.nest.secondary_tooltip,e.generic.ctrl_shortcut),icon:r.jsx(oo,{})})},or=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:i})=>{if(!(!i.isEditable||!(i.getSelection()?.blocks||[i.getTextCursorPosition().block]).find(s=>s.content!==void 0)))return{canUnnestBlock:i.canUnnestBlock()}}}),l=d.useCallback(()=>{n!==void 0&&n.canUnnestBlock&&(t.focus(),t.unnestBlock())},[t,n]);return n===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button","data-test":"unnestBlock",onClick:l,isDisabled:!n.canUnnestBlock,label:e.formatting_toolbar.unnest.tooltip,mainTooltip:e.formatting_toolbar.unnest.tooltip,secondaryTooltip:ge(e.formatting_toolbar.unnest.secondary_tooltip,e.generic.ctrl_shortcut),icon:r.jsx(ro,{})})},rr=e=>[{name:e.slash_menu.paragraph.title,type:"paragraph",icon:Pe},{name:e.slash_menu.heading.title,type:"heading",props:{level:1,isToggleable:!1},icon:ue},{name:e.slash_menu.heading_2.title,type:"heading",props:{level:2,isToggleable:!1},icon:de},{name:e.slash_menu.heading_3.title,type:"heading",props:{level:3,isToggleable:!1},icon:ce},{name:e.slash_menu.heading_4.title,type:"heading",props:{level:4,isToggleable:!1},icon:mt},{name:e.slash_menu.heading_5.title,type:"heading",props:{level:5,isToggleable:!1},icon:ut},{name:e.slash_menu.heading_6.title,type:"heading",props:{level:6,isToggleable:!1},icon:dt},{name:e.slash_menu.toggle_heading.title,type:"heading",props:{level:1,isToggleable:!0},icon:ue},{name:e.slash_menu.toggle_heading_2.title,type:"heading",props:{level:2,isToggleable:!0},icon:de},{name:e.slash_menu.toggle_heading_3.title,type:"heading",props:{level:3,isToggleable:!0},icon:ce},{name:e.slash_menu.quote.title,type:"quote",icon:ct},{name:e.slash_menu.toggle_list.title,type:"toggleListItem",icon:st},{name:e.slash_menu.bullet_list.title,type:"bulletListItem",icon:it},{name:e.slash_menu.numbered_list.title,type:"numberedListItem",icon:at},{name:e.slash_menu.check_list.title,type:"checkListItem",icon:lt}],lr=e=>{let o=h(),t=v(),n=E({editor:t,selector:({editor:a})=>a.getSelection()?.blocks||[a.getTextCursorPosition().block]}),l=n[0],i=d.useMemo(()=>(e.items||rr(t.dictionary)).filter(a=>U(t,a.type,Object.fromEntries(Object.entries(a.props||{}).map(([c,u])=>[c,typeof u])))),[t,e.items]),s=d.useMemo(()=>i.map(a=>{let c=a.icon,u=a.type===l.type,m=Object.entries(a.props||{}).filter(([p,g])=>g!==l.props[p]).length===0;return{text:a.name,icon:r.jsx(c,{size:16}),onClick:()=>{t.focus(),t.transact(()=>{for(let p of n)t.updateBlock(p,{type:a.type,props:a.props})})},isSelected:u&&m}}),[t,i,l.props,l.type,n]);return!d.useMemo(()=>s.find(a=>a.isSelected)!==void 0,[s])||!t.isEditable?null:r.jsx(o.FormattingToolbar.Select,{className:"bn-select",items:s})},ir=()=>{let e=k(),o=h(),t=w("comments"),{store:n}=w(Y),l=d.useCallback(()=>{t.startPendingComment(),n.setState(!1)},[t,n]);return r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.comment.tooltip,mainTooltip:e.formatting_toolbar.comment.tooltip,icon:r.jsx(bt,{}),onClick:l})},ar=()=>v().getExtension("comments")?r.jsx(ir,{}):null,sr=()=>{let e=k(),o=h(),t=v(),n=d.useCallback(()=>{t._tiptapEditor.chain().focus().addPendingComment().run()},[t]);return!t._tiptapEditor.commands.addPendingComment||!t.isEditable?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.comment.tooltip,mainTooltip:e.formatting_toolbar.comment.tooltip,icon:r.jsx(bt,{}),onClick:n})};function Ie(e,o){try{let t=new URL(e,o);if(t.protocol!=="javascript:")return t.href}catch{}return"#"}var cr=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:i})=>{let s=i.getSelection()?.blocks||[i.getTextCursorPosition().block];if(s.length!==1)return;let a=s[0];if(P(a,i,a.type,{url:"string"}))return a}}),l=d.useCallback(()=>{n!==void 0&&(t.focus(),t.resolveFileUrl?t.resolveFileUrl(n.props.url).then(i=>window.open(Ie(i,window.location.href))):window.open(Ie(n.props.url,window.location.href)))},[n,t]);return n===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.file_download.tooltip[n.type]||e.formatting_toolbar.file_download.tooltip.file,mainTooltip:e.formatting_toolbar.file_download.tooltip[n.type]||e.formatting_toolbar.file_download.tooltip.file,icon:r.jsx(qn,{}),onClick:l})},dr=()=>{let e=k(),o=h(),t=v(),n=E({editor:t,selector:({editor:i})=>{if(!i.isEditable)return;let s=i.getSelection()?.blocks||[i.getTextCursorPosition().block];if(s.length!==1)return;let a=s[0];if(P(a,i,a.type,{url:"string",showPreview:"boolean"}))return a}}),l=d.useCallback(()=>{n!==void 0&&U(t,n.type,{showPreview:"boolean"})&&t.updateBlock(n.id,{props:{showPreview:!n.props.showPreview}})},[n,t]);return n===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:"Toggle preview",mainTooltip:e.formatting_toolbar.file_preview_toggle.tooltip,icon:r.jsx(Kn,{}),isSelected:n.props.showPreview,onClick:l})},ur=()=>{let e=k(),o=h(),t=v(),n=w(S),l=E({editor:t,selector:({editor:s})=>{if(!s.isEditable||!s.settings.tables.splitCells)return;let a=s.getSelection()?.blocks||[s.getTextCursorPosition().block];if(a.length!==1)return;let c=a[0];if(c.type==="table")return{mergeDirection:n.getMergeDirection(c)}}}),i=d.useCallback(()=>{n?.mergeCells()},[n]);return l===void 0?null:r.jsx(o.FormattingToolbar.Button,{className:"bn-button",label:e.formatting_toolbar.table_cell_merge.tooltip,mainTooltip:e.formatting_toolbar.table_cell_merge.tooltip,icon:l.mergeDirection==="horizontal"?r.jsx(lo,{}):r.jsx(io,{}),onClick:i})},mr=()=>v().getExtension(S)?r.jsx(ur,{}):null,pr={left:no,center:to,right:eo,justify:Jn},ke=e=>{let o=h(),t=k(),n=v(),l=E({editor:n,selector:({editor:a})=>{if(!a.isEditable)return;let c=a.getSelection()?.blocks||[a.getTextCursorPosition().block],u=c[0];if(P(u,a,u.type,{textAlignment:ie.textAlignment}))return{textAlignment:u.props.textAlignment,blocks:c};if(c.length===1&&P(u,a,"table"))return a.getExtension(S)?.getCellSelection()?{textAlignment:Z(u.content.rows[0].cells[0]).props.textAlignment,blocks:[u]}:void 0}}),i=d.useCallback(a=>{if(l!==void 0){n.focus();for(let c of l.blocks)if(P(c,n,c.type,{textAlignment:ie.textAlignment})&&U(n,c.type,{textAlignment:ie.textAlignment}))n.updateBlock(c,{props:{textAlignment:a}});else if(c.type==="table"){let u=n.getExtension(S)?.getCellSelection();if(!u)continue;let m=c.content.rows.map(p=>({...p,cells:p.cells.map(g=>Z(g))}));u.cells.forEach(({row:p,col:g})=>{m[p].cells[g].props.textAlignment=a}),n.updateBlock(c,{type:"table",content:{...c.content,type:"tableContent",rows:m}}),n.setTextCursorPosition(c)}}},[n,l]);if(l===void 0)return null;let s=pr[e.textAlignment];return r.jsx(o.FormattingToolbar.Button,{className:"bn-button","data-test":`alignText${e.textAlignment.slice(0,1).toUpperCase()+e.textAlignment.slice(1)}`,onClick:()=>i(e.textAlignment),isSelected:l.textAlignment===e.textAlignment,label:t.formatting_toolbar[`align_${e.textAlignment}`].tooltip,mainTooltip:t.formatting_toolbar[`align_${e.textAlignment}`].tooltip,icon:r.jsx(s,{})})},Dt=e=>[r.jsx(lr,{items:e},"blockTypeSelect"),r.jsx(mr,{},"tableCellMergeButton"),r.jsx(Xo,{},"fileCaptionButton"),r.jsx(tr,{},"replaceFileButton"),r.jsx(er,{},"fileRenameButton"),r.jsx(Jo,{},"fileDeleteButton"),r.jsx(cr,{},"fileDownloadButton"),r.jsx(dr,{},"filePreviewButton"),r.jsx(re,{basicTextStyle:"bold"},"boldStyleButton"),r.jsx(re,{basicTextStyle:"italic"},"italicStyleButton"),r.jsx(re,{basicTextStyle:"underline"},"underlineStyleButton"),r.jsx(re,{basicTextStyle:"strike"},"strikeStyleButton"),r.jsx(ke,{textAlignment:"left"},"textAlignLeftButton"),r.jsx(ke,{textAlignment:"center"},"textAlignCenterButton"),r.jsx(ke,{textAlignment:"right"},"textAlignRightButton"),r.jsx(Wo,{},"colorStyleButton"),r.jsx(nr,{},"nestBlockButton"),r.jsx(or,{},"unnestBlockButton"),r.jsx(Zo,{},"createLinkButton"),r.jsx(ar,{},"addCommentButton"),r.jsx(sr,{},"addTiptapCommentButton")],Lt=e=>r.jsx(h().FormattingToolbar.Root,{className:"bn-toolbar bn-formatting-toolbar",children:e.children||Dt(e.blockTypeSelectItems)}),gr=e=>{switch(e){case"left":return"top-start";case"center":return"top";case"right":return"top-end";default:return"top-start"}},At=e=>{let o=v(),t=w(Y,{editor:o}),n=y(Y,{editor:o}),l=E({editor:o,selector:({editor:c})=>t.store.state?{from:c.prosemirrorState.selection.from,to:c.prosemirrorState.selection.to}:void 0}),i=E({editor:o,selector:({editor:c})=>{let u=c.getTextCursorPosition().block;return P(u,c,u.type,{textAlignment:ie.textAlignment})?gr(u.props.textAlignment):"top-start"}}),s=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:n,onOpenChange:(c,u,m)=>{t.store.setState(c),m==="escape-key"&&o.focus()},placement:i,middleware:[A(10),J(),ee()],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:40},...e.floatingUIOptions?.elementProps}}),[n,i,e.floatingUIOptions,t.store,o]),a=e.formattingToolbar||Lt;return r.jsx(Fe,{position:l,...s,children:n&&r.jsx(a,{})})},br=e=>{let o=h(),t=k(),{deleteLink:n}=w(be);return r.jsx(o.LinkToolbar.Button,{className:"bn-button",label:t.link_toolbar.delete.tooltip,mainTooltip:t.link_toolbar.delete.tooltip,isSelected:!1,onClick:()=>{n(e.range.from),e.setToolbarOpen?.(!1)},icon:r.jsx(mo,{})})},fr=e=>{let o=h(),t=k();return r.jsxs(o.Generic.Popover.Root,{onOpenChange:e.setToolbarPositionFrozen,children:[r.jsx(o.Generic.Popover.Trigger,{children:r.jsx(o.LinkToolbar.Button,{className:"bn-button",mainTooltip:t.link_toolbar.edit.tooltip,isSelected:!1,children:t.link_toolbar.edit.text})}),r.jsx(o.Generic.Popover.Content,{className:"bn-popover-content bn-form-popover",variant:"form-popover",children:r.jsx(Ft,{url:e.url,text:e.text,range:e.range,setToolbarOpen:e.setToolbarOpen,setToolbarPositionFrozen:e.setToolbarPositionFrozen})})]})},hr=e=>{let o=h(),t=k();return r.jsx(o.LinkToolbar.Button,{className:"bn-button",mainTooltip:t.link_toolbar.open.tooltip,label:t.link_toolbar.open.tooltip,isSelected:!1,onClick:()=>{window.open(Ie(e.url,window.location.href),"_blank")},icon:r.jsx(uo,{})})},xr=e=>r.jsx(h().LinkToolbar.Root,{className:"bn-toolbar bn-link-toolbar",children:e.children||r.jsxs(r.Fragment,{children:[r.jsx(fr,{url:e.url,text:e.text,range:e.range,setToolbarOpen:e.setToolbarOpen,setToolbarPositionFrozen:e.setToolbarPositionFrozen}),r.jsx(hr,{url:e.url}),r.jsx(br,{range:e.range,setToolbarOpen:e.setToolbarOpen})]})}),vr=e=>{let o=v(),[t,n]=d.useState(!1),[l,i]=d.useState(!1),s=q(),a=w(be),[c,u]=d.useState(void 0);d.useEffect(()=>{let b=()=>{let T=a.getLinkAtSelection();if(!T){u(void 0),l||n(!1);return}u({cursorType:"text",url:T.mark.attrs.href,text:T.text,range:T.range,element:a.getLinkElementAtPos(T.range.from)}),l||n(!0)},f=T=>{if(c!==void 0&&c.cursorType==="text"||!(T.target instanceof HTMLElement))return;let I=a.getLinkAtElement(T.target);I&&u({cursorType:"mouse",url:I.mark.attrs.href,text:I.text,range:I.range,element:a.getLinkElementAtPos(I.range.from)})},x=o.onChange(b),C=o.onSelectionChange(b);return s?.addEventListener("mouseover",f),()=>{x(),C(),s?.removeEventListener("mouseover",f)}},[o,s,a,c,l]);let m=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:t,onOpenChange:(b,f,x)=>{l||c!==void 0&&c.cursorType==="text"&&x==="hover"||(x==="escape-key"&&o.focus(),n(b))},placement:"top-start",middleware:[A(10),ee()],...e.floatingUIOptions?.useFloatingOptions},useHoverProps:{enabled:c!==void 0&&c.cursorType==="mouse",delay:{open:250,close:250},handleClose:ao(),...e.floatingUIOptions?.useHoverProps},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:50},...e.floatingUIOptions?.elementProps}}),[o,c,e.floatingUIOptions,t,l]),p=d.useMemo(()=>c?.element?{element:c.element}:void 0,[c?.element]);if(!o.isEditable)return null;let g=e.linkToolbar||xr;return r.jsx(L,{reference:p,...m,children:c&&r.jsx(g,{url:c.url,text:c.text,range:c.range,setToolbarOpen:n,setToolbarPositionFrozen:i})})},Cr=()=>{let e=h(),o=k(),t=v(),n=w(z),l=y(D,{editor:t,selector:s=>s?.block}),i=d.useCallback(()=>{if(l===void 0)return;let s=l.content;if(s!==void 0&&Array.isArray(s)&&s.length===0)t.setTextCursorPosition(l),n.openSuggestionMenu("/");else{let a=t.insertBlocks([{type:"paragraph"}],l,"after")[0];t.setTextCursorPosition(a),n.openSuggestionMenu("/")}},[l,t,n]);return l===void 0?null:r.jsx(e.SideMenu.Button,{className:"bn-button",label:o.side_menu.add_block_label,icon:r.jsx(po,{size:24,onClick:i,"data-test":"dragHandleAdd"})})},kr=e=>{let o=h(),t=v(),n=y(D,{editor:t,selector:l=>l?.block});return n===void 0||!P(n,t,n.type,{textColor:"string"})&&!P(n,t,n.type,{backgroundColor:"string"})?null:r.jsxs(o.Generic.Menu.Root,{position:"right",sub:!0,children:[r.jsx(o.Generic.Menu.Trigger,{sub:!0,children:r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",subTrigger:!0,children:e.children})}),r.jsx(o.Generic.Menu.Dropdown,{sub:!0,className:"bn-menu-dropdown bn-color-picker-dropdown",children:r.jsx(he,{iconSize:18,text:P(n,t,n.type,{textColor:"string"})&&U(t,n.type,{textColor:"string"})?{color:n.props.textColor,setColor:l=>t.updateBlock(n,{type:n.type,props:{textColor:l}})}:void 0,background:P(n,t,n.type,{backgroundColor:"string"})&&U(t,n.type,{backgroundColor:"string"})?{color:n.props.backgroundColor,setColor:l=>t.updateBlock(n,{props:{backgroundColor:l}})}:void 0})})]})},jr=e=>{let o=h(),t=v(),n=y(D,{editor:t,selector:l=>l?.block});return n===void 0?null:r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",onClick:()=>t.removeBlocks([n]),children:e.children})},wr=e=>{let o=h(),t=v(),n=y(D,{editor:t,selector:i=>i?.block});if(n===void 0||n.type!=="table"||!t.settings.tables.headers)return null;let l=!!n.content.headerRows;return r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",checked:l,onClick:()=>{t.updateBlock(n,{content:{...n.content,headerRows:l?void 0:1}})},children:e.children})},yr=e=>{let o=h(),t=v(),n=y(D,{editor:t,selector:i=>i?.block});if(n===void 0||n.type!=="table"||!t.settings.tables.headers)return null;let l=!!n.content.headerCols;return r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",checked:l,onClick:()=>{t.updateBlock(n,{content:{...n.content,headerCols:l?void 0:1}})},children:e.children})},Sr=e=>{let o=h(),t=k();return r.jsx(o.Generic.Menu.Dropdown,{className:"bn-menu-dropdown bn-drag-handle-menu",children:e.children||r.jsxs(r.Fragment,{children:[r.jsx(jr,{children:t.drag_handle.delete_menuitem}),r.jsx(kr,{children:t.drag_handle.colors_menuitem}),r.jsx(wr,{children:t.drag_handle.header_row_menuitem}),r.jsx(yr,{children:t.drag_handle.header_column_menuitem})]})})},Tr=e=>{let o=h(),t=k(),n=w(D),l=y(D,{selector:s=>s?.block});if(l===void 0)return null;let i=e.dragHandleMenu||Sr;return r.jsxs(o.Generic.Menu.Root,{onOpenChange:s=>{s?n.freezeMenu():n.unfreezeMenu()},position:"left",children:[r.jsx(o.Generic.Menu.Trigger,{children:r.jsx(o.SideMenu.Button,{label:t.side_menu.drag_handle_label,draggable:!0,onDragStart:s=>n.blockDragStart(s,l),onDragEnd:n.blockDragEnd,className:"bn-button",icon:r.jsx(ft,{size:24,"data-test":"dragHandle"})})}),r.jsx(i,{children:e.children})]})},_r=e=>{let o=h(),t=v(),n=y(D,{editor:t,selector:i=>i?.block}),l=d.useMemo(()=>{if(n===void 0)return{};let i={"data-block-type":n.type};return n.type==="heading"&&(i["data-level"]=n.props.level.toString()),t.schema.blockSpecs[n.type].implementation.meta?.fileBlockAccept&&(n.props.url?i["data-url"]="true":i["data-url"]="false"),i},[n,t.schema.blockSpecs]);return r.jsx(o.SideMenu.Root,{className:"bn-side-menu",...l,children:e.children||r.jsxs(r.Fragment,{children:[r.jsx(Cr,{}),r.jsx(Tr,{dragHandleMenu:e.dragHandleMenu})]})})},Rr=e=>{let o=v(),{show:t,block:n}=y(D,{selector:a=>a===void 0?void 0:{show:a.show,block:a.block}})||{},l=d.useCallback((a,c,u)=>{let m=!1;return Me(a,c,()=>{if(!m){m=!0;return}o.getExtension(D)?.hideMenuIfNotFrozen()},{ancestorScroll:!0,ancestorResize:!1,elementResize:!1,layoutShift:!1})},[o]),i=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:t,placement:"left-start",whileElementsMounted:l,...e.floatingUIOptions?.useFloatingOptions},useDismissProps:{enabled:!1,...e.floatingUIOptions?.useDismissProps},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{style:{zIndex:20},...e.floatingUIOptions?.elementProps}}),[e.floatingUIOptions,t,l]),s=e.sideMenu||_r;return r.jsx(Bt,{blockId:t?n?.id:void 0,...i,children:n?.id&&r.jsx(s,{})})};async function Er(e,o){return(await cn(e,o)).map(({id:t,onItemClick:n})=>({id:t,onItemClick:n,icon:t}))}function Ir(e){let o=h(),t=k(),{items:n,loadingState:l,selectedIndex:i,onItemClick:s,columns:a}=e,c=l==="loading-initial"||l==="loading"?r.jsx(o.GridSuggestionMenu.Loader,{className:"bn-grid-suggestion-menu-loader",columns:a}):null,u=d.useMemo(()=>{let m=[];for(let p=0;p<n.length;p++){let g=n[p];m.push(r.jsx(o.GridSuggestionMenu.Item,{className:"bn-grid-suggestion-menu-item",item:g,id:`bn-grid-suggestion-menu-item-${p}`,isSelected:p===i,onClick:()=>s?.(g)},g.id))}return m},[o,n,s,i]);return r.jsxs(o.GridSuggestionMenu.Root,{id:"bn-grid-suggestion-menu",columns:a,className:"bn-grid-suggestion-menu",children:[c,u,u.length===0&&e.loadingState==="loaded"&&r.jsx(o.GridSuggestionMenu.EmptyItem,{className:"bn-grid-suggestion-menu-empty-item",columns:a,children:t.suggestion_menu.no_items_title})]})}function zt(e,o,t,n=3){let l=d.useRef(0);d.useEffect(()=>{o!==void 0&&(e.length>0?l.current=o.length:o.length-l.current>n&&t())},[t,n,e.length,o])}function Gt(e,o){let[t,n]=d.useState([]),[l,i]=d.useState(!1),s=d.useRef(void 0),a=d.useRef(void 0);return d.useEffect(()=>{let c=e;s.current=e,i(!0),o(e).then(u=>{s.current===c&&(n(u),i(!1),a.current=c)})},[e,o]),{items:t||[],usedQuery:a.current,loadingState:a.current===void 0?"loading-initial":l?"loading":"loaded"}}function Mr(e,o,t,n,l){let i=q(e),[s,a]=d.useState(0);return d.useEffect(()=>{let c=u=>(u.key==="ArrowLeft"&&(u.preventDefault(),t.length&&a((s-1+t.length)%t.length)),u.key==="ArrowRight"&&(u.preventDefault(),t.length&&a((s+1+t.length)%t.length)),u.key==="ArrowUp"?(u.preventDefault(),t.length&&a((s-n+t.length)%t.length),!0):u.key==="ArrowDown"?(u.preventDefault(),t.length&&a((s+n)%t.length),!0):u.key==="Enter"&&!u.isComposing?(u.stopPropagation(),u.preventDefault(),t.length&&l?.(t[s]),!0):!1);return i?.addEventListener("keydown",c,!0),()=>{i?.removeEventListener("keydown",c,!0)}},[i,t,s,l,n,n!==void 0&&n>1]),d.useEffect(()=>{a(0)},[o]),{selectedIndex:t.length===0?void 0:s}}function Pr(e){let o=O().setContentEditableProps,t=v(),{getItems:n,gridSuggestionMenuComponent:l,query:i,clearQuery:s,closeMenu:a,onItemClick:c,columns:u}=e,m=d.useCallback(x=>{a(),s(),c?.(x)},[c,a,s]),{items:p,usedQuery:g,loadingState:b}=Gt(i,n);zt(p,g,a);let{selectedIndex:f}=Mr(t,i,p,u,m);return d.useEffect(()=>(o(x=>({...x,"aria-expanded":!0,"aria-controls":"bn-suggestion-menu"})),()=>{o(x=>({...x,"aria-expanded":!1,"aria-controls":void 0}))}),[o]),d.useEffect(()=>(o(x=>({...x,"aria-activedescendant":f?"bn-suggestion-menu-item-"+f:void 0})),()=>{o(x=>({...x,"aria-activedescendant":void 0}))}),[o,f]),r.jsx(l,{items:p,onItemClick:m,loadingState:b,selectedIndex:f,columns:u})}function Nr(e){let o=v(),t=q(),{triggerCharacter:n,gridSuggestionMenuComponent:l,columns:i,shouldOpen:s,minQueryLength:a,onItemClick:c,getItems:u}=e,m=d.useMemo(()=>c||(C=>{C.onItemClick(o)}),[o,c]),p=d.useMemo(()=>u||(async C=>await Er(o,C)),[o,u]),g=w(z);d.useEffect(()=>{g.addSuggestionMenu({triggerCharacter:n,shouldOpen:s})},[g,n,s]);let b=y(z),f=y(z,{selector:C=>({element:t?.firstChild||void 0,getBoundingClientRect:()=>C?.referencePos||new DOMRect})}),x=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:b?.show&&b?.triggerCharacter===n,onOpenChange:C=>{C||g.closeMenu()},placement:"bottom-start",middleware:[A(10),rt({allowedPlacements:["bottom-start","top-start"],padding:10}),J(),se({apply({elements:C,availableHeight:T}){C.floating.style.maxHeight=`${Math.max(0,T)}px`},padding:10})],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{onMouseDownCapture:C=>C.preventDefault(),style:{zIndex:70},...e.floatingUIOptions?.elementProps}}),[e.floatingUIOptions,b?.show,b?.triggerCharacter,g,n]);return!b||!b.ignoreQueryLength&&a&&(b.query.startsWith(" ")||b.query.length<a)?null:r.jsx(L,{reference:f,...x,children:n&&r.jsx(Pr,{query:b.query,closeMenu:g.closeMenu,clearQuery:g.clearQuery,getItems:p,columns:i,gridSuggestionMenuComponent:l||Ir,onItemClick:m})})}function Br(e){let o=h(),t=k(),{items:n,loadingState:l,selectedIndex:i,onItemClick:s}=e,a=l==="loading-initial"||l==="loading"?r.jsx(o.SuggestionMenu.Loader,{className:"bn-suggestion-menu-loader"}):null,c=d.useMemo(()=>{let u,m=[];for(let p=0;p<n.length;p++){let g=n[p];g.group!==u&&(u=g.group,m.push(r.jsx(o.SuggestionMenu.Label,{className:"bn-suggestion-menu-label",children:u},u))),m.push(r.jsx(o.SuggestionMenu.Item,{className:R("bn-suggestion-menu-item",g.size==="small"?"bn-suggestion-menu-item-small":""),item:g,id:`bn-suggestion-menu-item-${p}`,isSelected:p===i,onClick:()=>s?.(g)},g.title))}return m},[o,n,s,i]);return r.jsxs(o.SuggestionMenu.Root,{id:"bn-suggestion-menu",className:"bn-suggestion-menu",children:[c,c.length===0&&(e.loadingState==="loading"||e.loadingState==="loaded")&&r.jsx(o.SuggestionMenu.EmptyItem,{className:"bn-suggestion-menu-item",children:t.suggestion_menu.no_items_title}),a]})}function Or(e,o){let[t,n]=d.useState(0);return{selectedIndex:t,setSelectedIndex:n,handler:l=>{if(l.key==="ArrowUp")return l.preventDefault(),e.length&&n((t-1+e.length)%e.length),!0;if(l.key==="ArrowDown")return l.preventDefault(),e.length&&n((t+1)%e.length),!0;if(l.key==="PageUp")return l.preventDefault(),e.length&&n(0),!0;if(l.key==="PageDown")return l.preventDefault(),e.length&&n(e.length-1),!0;let i=Fr(l)?l.nativeEvent.isComposing:l.isComposing;return l.key==="Enter"&&!i?(l.preventDefault(),l.stopPropagation(),e.length&&o?.(e[t]),!0):!1}}}function Fr(e){return e.nativeEvent!==void 0}function Dr(e,o,t,n,l){let i=q(),{selectedIndex:s,setSelectedIndex:a,handler:c}=Or(t,n);return d.useEffect(()=>{let u=i;return u?.addEventListener("keydown",c,!0),()=>{u?.removeEventListener("keydown",c,!0)}},[i,t,s,n,l,c]),d.useEffect(()=>{a(0)},[o,a]),{selectedIndex:t.length===0?void 0:s}}function Lr(e){let o=O().setContentEditableProps,t=v(),{getItems:n,suggestionMenuComponent:l,query:i,clearQuery:s,closeMenu:a,onItemClick:c}=e,u=d.useCallback(f=>{a(),s(),c?.(f)},[c,a,s]),{items:m,usedQuery:p,loadingState:g}=Gt(i,n);zt(m,p,a);let{selectedIndex:b}=Dr(t,i,m,u);return d.useEffect(()=>(o(f=>({...f,"aria-expanded":!0,"aria-controls":"bn-suggestion-menu"})),()=>{o(f=>({...f,"aria-expanded":!1,"aria-controls":void 0}))}),[o]),d.useEffect(()=>(o(f=>({...f,"aria-activedescendant":b?"bn-suggestion-menu-item-"+b:void 0})),()=>{o(f=>({...f,"aria-activedescendant":void 0}))}),[o,b]),r.jsx(l,{items:m,onItemClick:u,loadingState:g,selectedIndex:b})}var Ar={heading:ue,heading_2:de,heading_3:ce,heading_4:mt,heading_5:ut,heading_6:dt,toggle_heading:ue,toggle_heading_2:de,toggle_heading_3:ce,quote:ct,toggle_list:st,numbered_list:at,bullet_list:it,check_list:lt,paragraph:Pe,table:Hn,image:$n,video:Gn,audio:zn,file:An,emoji:Ln,code_block:Dn,divider:Fn};function zr(e){return on(e).map(o=>{let t=Ar[o.key];return{...o,icon:r.jsx(t,{size:18})}})}function Gr(e){let o=v(),t=q(),{triggerCharacter:n,suggestionMenuComponent:l,shouldOpen:i,minQueryLength:s,onItemClick:a,getItems:c}=e,u=d.useMemo(()=>a||(x=>{x.onItemClick(o)}),[o,a]),m=d.useMemo(()=>c||(async x=>nn(zr(o),x)),[o,c]),p=w(z);d.useEffect(()=>{p.addSuggestionMenu({triggerCharacter:n,shouldOpen:i})},[p,n,i]);let g=y(z),b=y(z,{selector:x=>({element:t?.firstChild||void 0,getBoundingClientRect:()=>x?.referencePos||new DOMRect})}),f=d.useMemo(()=>({...e.floatingUIOptions,useFloatingOptions:{open:g?.show&&g?.triggerCharacter===n,onOpenChange:x=>{x||p.closeMenu()},placement:"bottom-start",middleware:[A(10),rt({allowedPlacements:["bottom-start","top-start"],padding:10}),J(),se({apply({elements:x,availableHeight:C}){x.floating.style.maxHeight=`${Math.max(0,C)}px`},padding:10})],...e.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!0,...e.floatingUIOptions?.focusManagerProps},elementProps:{onMouseDownCapture:x=>x.preventDefault(),style:{zIndex:80},...e.floatingUIOptions?.elementProps}}),[e.floatingUIOptions,g?.show,g?.triggerCharacter,p,n]);return!g||!g.ignoreQueryLength&&s&&(g.query.startsWith(" ")||g.query.length<s)?null:r.jsx(L,{reference:b,...f,children:n&&r.jsx(Lr,{query:g.query,closeMenu:p.closeMenu,clearQuery:p.clearQuery,getItems:m,suggestionMenuComponent:l||Br,onItemClick:u})})}var $r=(e,o=.3)=>{let t=Math.floor(e)+o,n=Math.ceil(e)-o;return e>=t&&e<=n?Math.round(e):e<t?Math.floor(e):Math.ceil(e)},Hr=e=>{let o=h(),t=v(),n=w(S),l=y(S,{selector:m=>m?.block}),i=d.useRef(!1),[s,a]=d.useState(),c=d.useCallback(m=>{n.freezeHandles(),e.hideOtherElements(!0),l&&(a({originalContent:l.content,originalCroppedContent:{rows:n.cropEmptyRowsOrColumns(l,e.orientation==="addOrRemoveColumns"?"columns":"rows")},startPos:e.orientation==="addOrRemoveColumns"?m.clientX:m.clientY}),i.current=!1,m.preventDefault())},[l,e,n]),u=d.useCallback(()=>{!l||i.current||t.updateBlock(l,{type:"table",content:{...l.content,rows:e.orientation==="addOrRemoveColumns"?n.addRowsOrColumns(l,"columns",1):n.addRowsOrColumns(l,"rows",1)}})},[l,t,e.orientation,n]);return d.useEffect(()=>{let m=p=>{if(!l)return;if(!s)throw Error("editingState is undefined");i.current=!0;let g=(e.orientation==="addOrRemoveColumns"?p.clientX:p.clientY)-s.startPos,b=e.orientation==="addOrRemoveColumns"?s.originalCroppedContent.rows[0]?.cells.length??0:s.originalCroppedContent.rows.length,f=e.orientation==="addOrRemoveColumns"?s.originalContent.rows[0]?.cells.length??0:s.originalContent.rows.length,x=e.orientation==="addOrRemoveColumns"?l.content.rows[0].cells.length:l.content.rows.length,C=f+$r(g/(e.orientation==="addOrRemoveColumns"?dn:un),.3);C>=b&&C>0&&C!==x&&(t.updateBlock(l,{type:"table",content:{...l.content,rows:e.orientation==="addOrRemoveColumns"?n.addRowsOrColumns({type:"table",content:s.originalCroppedContent},"columns",C-b):n.addRowsOrColumns({type:"table",content:s.originalCroppedContent},"rows",C-b)}}),l.content&&t.setTextCursorPosition(l))};return s&&window.addEventListener("mousemove",m),()=>{window.removeEventListener("mousemove",m)}},[l,s,t,e.orientation,n]),d.useEffect(()=>{let m=()=>{e.hideOtherElements(!1),n.unfreezeHandles(),a(void 0)};return s&&window.addEventListener("mouseup",m),()=>{window.removeEventListener("mouseup",m)}},[s,e,n]),t.isEditable?r.jsx(o.TableHandle.ExtendButton,{className:R("bn-extend-button",e.orientation==="addOrRemoveColumns"?"bn-extend-button-add-remove-columns":"bn-extend-button-add-remove-rows",s===null?"":"bn-extend-button-editing"),onClick:u,onMouseDown:c,children:e.children||r.jsx(so,{size:18,"data-test":"extendButton"})}):null},Ur=e=>{let o=h(),t=k(),n=v(),{block:l,colIndex:i,rowIndex:s}=y(S,{selector:u=>({block:u?.block,colIndex:u?.colIndex,rowIndex:u?.rowIndex})}),a=(u,m)=>{if(l===void 0||i===void 0||s===void 0)return;let p=l.content.rows.map(g=>({...g,cells:g.cells.map(b=>Z(b))}));m==="text"?p[s].cells[i].props.textColor=u:p[s].cells[i].props.backgroundColor=u,n.updateBlock(l,{type:"table",content:{...l.content,rows:p}}),n.setTextCursorPosition(l)};if(l===void 0||i===void 0||s===void 0)return null;let c=l.content.rows[s]?.cells?.[i];return!c||n.settings.tables.cellTextColor===!1&&n.settings.tables.cellBackgroundColor===!1?null:r.jsxs(o.Generic.Menu.Root,{position:"right",sub:!0,children:[r.jsx(o.Generic.Menu.Trigger,{sub:!0,children:r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",subTrigger:!0,children:e.children||t.drag_handle.colors_menuitem})}),r.jsx(o.Generic.Menu.Dropdown,{sub:!0,className:"bn-menu-dropdown bn-color-picker-dropdown",children:r.jsx(he,{iconSize:18,text:n.settings.tables.cellTextColor?{color:X(c)?c.props.textColor:"default",setColor:u=>a(u,"text")}:void 0,background:n.settings.tables.cellBackgroundColor?{color:X(c)?c.props.backgroundColor:"default",setColor:u=>a(u,"background")}:void 0})})]})},Vr=()=>{let e=h(),o=k(),t=v(),n=w(S),{block:l,colIndex:i,rowIndex:s}=y(S,{selector:c=>({block:c?.block,colIndex:c?.colIndex,rowIndex:c?.rowIndex})});if(l===void 0||i===void 0||s===void 0)return null;let a=l.content.rows[s]?.cells?.[i];return!a||!X(a)||nt(a)===1&&tt(a)===1||!t.settings.tables.splitCells?null:r.jsx(e.Generic.Menu.Item,{onClick:()=>{n.splitCell({row:s,col:i})},children:o.table_handle.split_cell_menuitem})},qr=e=>r.jsx(h().Generic.Menu.Dropdown,{className:"bn-menu-dropdown bn-table-handle-menu",children:e.children||r.jsxs(r.Fragment,{children:[r.jsx(Vr,{}),r.jsx(Ur,{})]})}),Kr=e=>{let o=h(),t=v(),n=w(S),l=e.tableCellMenu||qr;return!t.settings.tables.splitCells&&!t.settings.tables.cellBackgroundColor&&!t.settings.tables.cellTextColor?null:r.jsxs(o.Generic.Menu.Root,{onOpenChange:i=>{i?(n.freezeHandles(),e.hideOtherElements(!0)):(n.unfreezeHandles(),e.hideOtherElements(!1),t.focus())},position:"right",children:[r.jsx(o.Generic.Menu.Trigger,{children:r.jsx(o.Generic.Menu.Button,{className:"bn-table-cell-handle",children:e.children||r.jsx(co,{size:12,"data-test":"tableCellHandle"})})}),r.jsx(l,{})]})},Ze=e=>{let o=h(),t=k(),n=w(S),l=y(S,{selector:i=>e.orientation==="column"?i?.colIndex:i?.rowIndex});return n===void 0||l===void 0?null:r.jsx(o.Generic.Menu.Item,{onClick:()=>{n.addRowOrColumn(l,e.orientation==="row"?{orientation:"row",side:e.side}:{orientation:"column",side:e.side})},children:t.table_handle[`add_${e.side}_menuitem`]})},Qr=e=>{let o=h(),t=k(),n=w(S),l=y(S,{selector:i=>e.orientation==="column"?i?.colIndex:i?.rowIndex});return n===void 0||l===void 0?null:r.jsx(o.Generic.Menu.Item,{onClick:()=>n.removeRowOrColumn(l,e.orientation),children:e.orientation==="row"?t.table_handle.delete_row_menuitem:t.table_handle.delete_column_menuitem})},Wr=e=>{let o=h(),t=k(),n=v(),l=w(S),{block:i,index:s}=y(S,{selector:m=>({block:m?.block,index:e.orientation==="column"?m?.colIndex:m?.rowIndex})}),a=d.useMemo(()=>l===void 0||i===void 0||s===void 0?[]:e.orientation==="row"?l.getCellsAtRowHandle(i,s):l.getCellsAtColumnHandle(i,s),[i,s,e.orientation,l]),c=(m,p)=>{if(i===void 0)return;let g=i.content.rows.map(b=>({...b,cells:b.cells.map(f=>Z(f))}));a.forEach(({row:b,col:f})=>{p==="text"?g[b].cells[f].props.textColor=m:g[b].cells[f].props.backgroundColor=m}),n.updateBlock(i,{type:"table",content:{...i.content,rows:g}}),n.setTextCursorPosition(i)};if(!a||!a[0]||!l||n.settings.tables.cellTextColor===!1&&n.settings.tables.cellBackgroundColor===!1)return null;let u=Z(a[0].cell);return r.jsxs(o.Generic.Menu.Root,{position:"right",sub:!0,children:[r.jsx(o.Generic.Menu.Trigger,{sub:!0,children:r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",subTrigger:!0,children:e.children||t.drag_handle.colors_menuitem})}),r.jsx(o.Generic.Menu.Dropdown,{sub:!0,className:"bn-menu-dropdown bn-color-picker-dropdown",children:r.jsx(he,{iconSize:18,text:n.settings.tables.cellTextColor?{color:a.every(({cell:m})=>X(m)&&m.props.textColor===u.props.textColor)?u.props.textColor:"default",setColor:m=>{c(m,"text")}}:void 0,background:n.settings.tables.cellBackgroundColor?{color:a.every(({cell:m})=>X(m)&&m.props.backgroundColor===u.props.backgroundColor)?u.props.backgroundColor:"default",setColor:m=>c(m,"background")}:void 0})})]})},Yr=e=>{let o=h(),t=k(),n=v(),l=w(S),{block:i,index:s}=y(S,{selector:c=>({block:c?.block,index:e.orientation==="column"?c?.colIndex:c?.rowIndex})});if(l===void 0||i===void 0||s!==0||e.orientation!=="row"||!n.settings.tables.headers)return null;let a=!!i.content.headerRows;return r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",checked:a,onClick:()=>{n.updateBlock(i,{...i,content:{...i.content,headerRows:a?void 0:1}})},children:t.drag_handle.header_row_menuitem})},Zr=e=>{let o=h(),t=k(),n=v(),l=w(S),i=y(S,{selector:c=>c?.block}),s=y(S,{selector:c=>e.orientation==="column"?c?.colIndex:c?.rowIndex});if(!l||s!==0||!i||e.orientation!=="column"||!n.settings.tables.headers)return null;let a=!!i.content.headerCols;return r.jsx(o.Generic.Menu.Item,{className:"bn-menu-item",checked:a,onClick:()=>{n.updateBlock(i,{...i,content:{...i.content,headerCols:a?void 0:1}})},children:t.drag_handle.header_column_menuitem})},Xr=e=>r.jsx(h().Generic.Menu.Dropdown,{className:"bn-table-handle-menu",children:e.children||r.jsxs(r.Fragment,{children:[r.jsx(Qr,{orientation:e.orientation}),r.jsx(Ze,{orientation:e.orientation,side:e.orientation==="row"?"above":"left"}),r.jsx(Ze,{orientation:e.orientation,side:e.orientation==="row"?"below":"right"}),r.jsx(Yr,{orientation:e.orientation}),r.jsx(Zr,{orientation:e.orientation}),r.jsx(Wr,{orientation:e.orientation})]})}),Jr=e=>{let o=v(),t=h(),[n,l]=d.useState(!1),i=e.tableHandleMenu||Xr,s=w(S),a=y(S),c=d.useMemo(()=>!s||!a||!a.block||a.block.type!=="table"?!1:e.orientation==="column"?s.getCellsAtColumnHandle(a.block,a.colIndex).every(({cell:u})=>tt(u)===1):s.getCellsAtRowHandle(a.block,a.rowIndex).every(({cell:u})=>nt(u)===1),[e.orientation,a,s]);return a?r.jsxs(t.Generic.Menu.Root,{onOpenChange:u=>{u?(s.freezeHandles(),e.hideOtherElements(!0)):(s.unfreezeHandles(),e.hideOtherElements(!1),o.focus())},position:"right",children:[r.jsx(t.Generic.Menu.Trigger,{children:r.jsx(t.TableHandle.Root,{className:R("bn-table-handle",n?"bn-table-handle-dragging":"",c?"":"bn-table-handle-not-draggable"),draggable:c,onDragStart:u=>{l(!0),e.hideOtherElements(!0),e.orientation==="column"?s.colDragStart(u):s.rowDragStart(u)},onDragEnd:()=>{s.dragEnd(),e.hideOtherElements(!1),l(!1)},style:e.orientation==="column"?{transform:"rotate(0.25turn)"}:void 0,children:e.children||r.jsx(ft,{size:24,"data-test":"tableHandle"})})}),r.jsx(i,{orientation:e.orientation})]}):null},el=e=>{let o=v(),[t,n]=d.useState(),l=y(S),i=d.useMemo(()=>{let p={};if(l===void 0)return{};let g=et(l.block.id,o.prosemirrorState.doc);if(!g)return{};let b=g.posBeforeNode+1,f=o.prosemirrorView.domAtPos(b+1).node;if(!(f instanceof Element))return{};if(p.tableReference={element:f},l.rowIndex===void 0||l.colIndex===void 0)return p;let x=o.prosemirrorState.doc.resolve(b+1).posAtIndex(l.rowIndex),C=o.prosemirrorState.doc.resolve(x+1).posAtIndex(l.colIndex),T=o.prosemirrorView.domAtPos(C+1).node;return T instanceof Element?(p.cellReference={element:T},p.rowReference={element:f,getBoundingClientRect:()=>{let I=f.getBoundingClientRect(),F=T.getBoundingClientRect();return new DOMRect(I.x,l.draggingState&&l.draggingState.draggedCellOrientation==="row"?l.draggingState.mousePos-F.height/2:F.y,I.width,F.height)}},p.columnReference={element:f,getBoundingClientRect:()=>{let I=f.getBoundingClientRect(),F=T.getBoundingClientRect();return new DOMRect(l.draggingState&&l.draggingState.draggedCellOrientation==="col"?l.draggingState.mousePos-F.width/2:F.x,I.y,F.width,I.height)}},p):{}},[o,l]),s=d.useCallback((p,g,b)=>{let f=!1;return Me(p,g,()=>{if(!f){f=!0;return}o.getExtension(S)?.hideHandlesIfNotFrozen()},{ancestorScroll:!0,ancestorResize:!1,elementResize:!1,layoutShift:!1})},[o]),a=d.useMemo(()=>l===void 0?void 0:{rowTableHandle:{useFloatingOptions:{open:l.show&&l.rowIndex!==void 0&&(!t||t==="rowTableHandle"),placement:"left",middleware:[A(-10)],whileElementsMounted:s},focusManagerProps:{disabled:!0},elementProps:{style:{zIndex:10}}},columnTableHandle:{useFloatingOptions:{open:l.show&&l.colIndex!==void 0&&(!t||t==="columnTableHandle"),placement:"top",middleware:[A(-12)],whileElementsMounted:s},focusManagerProps:{disabled:!0},elementProps:{style:{zIndex:10}}},tableCellHandle:{useFloatingOptions:{open:l.show&&l.rowIndex!==void 0&&l.colIndex!==void 0&&(!t||t==="tableCellHandle"),placement:"top-end",middleware:[A({mainAxis:-15,crossAxis:-1})],whileElementsMounted:s},focusManagerProps:{disabled:!0},elementProps:{style:{zIndex:10}}},extendRowsButton:{useFloatingOptions:{open:l.show&&l.showAddOrRemoveRowsButton&&(!t||t==="extendRowsButton"),placement:"bottom",whileElementsMounted:s,middleware:[se({apply({rects:p,elements:g}){Object.assign(g.floating.style,{width:`${p.reference.width}px`})}})]},focusManagerProps:{disabled:!0},elementProps:{style:{zIndex:10}}},extendColumnsButton:{useFloatingOptions:{open:l.show&&l.showAddOrRemoveColumnsButton&&(!t||t==="extendColumnsButton"),placement:"right",whileElementsMounted:s,middleware:[se({apply({rects:p,elements:g}){Object.assign(g.floating.style,{height:`${p.reference.height}px`})}})]},focusManagerProps:{disabled:!0},elementProps:{style:{zIndex:10}}}},[t,l,s]);if(!l)return null;let c=e.tableHandle||Jr,u=e.extendButton||Hr,m=e.tableCellHandle||Kr;return r.jsxs(r.Fragment,{children:[r.jsx(L,{reference:i?.rowReference,...a?.rowTableHandle,children:l.show&&l.rowIndex!==void 0&&(!t||t==="rowTableHandle")&&r.jsx(c,{orientation:"row",hideOtherElements:p=>n(p?"rowTableHandle":void 0)})}),r.jsx(L,{reference:i?.columnReference,...a?.columnTableHandle,children:l.show&&l.colIndex!==void 0&&(!t||t==="columnTableHandle")&&r.jsx(c,{orientation:"column",hideOtherElements:p=>n(p?"columnTableHandle":void 0)})}),r.jsx(L,{reference:i?.cellReference,...a?.tableCellHandle,children:l.show&&l.rowIndex!==void 0&&l.colIndex!==void 0&&(!t||t==="tableCellHandle")&&r.jsx(m,{hideOtherElements:p=>n(p?"tableCellHandle":void 0)})}),r.jsx(L,{reference:i?.tableReference,...a?.extendRowsButton,children:l.show&&l.showAddOrRemoveRowsButton&&(!t||t==="extendRowsButton")&&r.jsx(u,{orientation:"addOrRemoveRows",hideOtherElements:p=>n(p?"extendRowsButton":void 0)})}),r.jsx(L,{reference:i?.tableReference,...a?.extendColumnsButton,children:l.show&&l.showAddOrRemoveColumnsButton&&(!t||t==="extendColumnsButton")&&r.jsx(u,{orientation:"addOrRemoveColumns",hideOtherElements:p=>n(p?"extendColumnsButton":void 0)})})]})},tl=d.lazy(()=>me(()=>Promise.resolve().then(()=>Ho),void 0).then(e=>e.n)),nl=d.lazy(()=>me(()=>Promise.resolve().then(()=>Go),void 0).then(e=>e.n));function ol(e){let o=v();if(!o)throw Error("BlockNoteDefaultUI must be used within a BlockNoteContext.Provider");return r.jsxs(r.Fragment,{children:[o.getExtension(Y)&&e.formattingToolbar!==!1&&r.jsx(At,{}),o.getExtension(be)&&e.linkToolbar!==!1&&r.jsx(vr,{}),o.getExtension(z)&&e.slashMenu!==!1&&r.jsx(Gr,{triggerCharacter:"/",shouldOpen:t=>!t.selection.$from.parent.type.isInGroup("tableContent")}),o.getExtension(z)&&e.emojiPicker!==!1&&r.jsx(Nr,{triggerCharacter:":",columns:10,minQueryLength:2}),o.getExtension(D)&&e.sideMenu!==!1&&r.jsx(Rr,{}),o.getExtension(_e)&&e.filePanel!==!1&&r.jsx(qo,{}),o.getExtension(S)&&e.tableHandles!==!1&&r.jsx(el,{}),o.getExtension(B)&&e.comments!==!1&&r.jsxs(d.Suspense,{children:[r.jsx(tl,{}),r.jsx(nl,{})]})]})}function rl(e,o){let t=O();o||=t?.editor,d.useEffect(()=>{if(!o)throw Error("'editor' is required, either from BlockNoteContext or as a function argument");return o.onChange(e)},[e,o])}function ll(e,o,t){let n=O();o||=n?.editor,d.useEffect(()=>{if(!o)throw Error("'editor' is required, either from BlockNoteContext or as a function argument");return o.onSelectionChange(e,t)},[e,o,t])}var $t=()=>{let e=d.useMemo(()=>window.matchMedia?.("(prefers-color-scheme: dark)"),[]),o=d.useMemo(()=>window.matchMedia?.("(prefers-color-scheme: light)"),[]),t=e?.matches,n=o?.matches,[l,i]=d.useState(t?"dark":n?"light":"no-preference");return d.useEffect(()=>{i(t?"dark":n?"light":"no-preference")},[t,n]),d.useEffect(()=>{if(typeof e?.addEventListener=="function"){let s=({matches:c})=>c&&i("dark"),a=({matches:c})=>c&&i("light");return e?.addEventListener("change",s),o?.addEventListener("change",a),()=>{e?.removeEventListener("change",s),o?.removeEventListener("change",a)}}else{let s=()=>i(e.matches?"dark":o.matches?"light":"no-preference");return e?.addEventListener("change",s),o?.addEventListener("change",s),()=>{e?.removeEventListener("change",s),o?.removeEventListener("change",s)}}},[e,o]),l},Ht=d.createContext(void 0);function il(){return d.useContext(Ht)}function al(){let e=new Set,o={};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return o},getServerSnapshot(){return o},setRenderer(t,n){o={...o,[t]:ae.createPortal(n.reactElement,n.element,t)},e.forEach(l=>l())},removeRenderer(t){let n={...o};delete n[t],o=n,e.forEach(l=>l())}}}var sl=({contentComponent:e})=>{let o=d.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot);return r.jsx(r.Fragment,{children:Object.values(o)})},cl=d.forwardRef((e,o)=>{let[t,n]=d.useState();return d.useImperativeHandle(o,()=>(l,i)=>{ae.flushSync(()=>{n({node:l,container:i})}),n(void 0)},[]),r.jsx(r.Fragment,{children:t&&ae.createPortal(t.node,t.container)})}),Xe=()=>{};function dl(e,o){let{editor:t,className:n,theme:l,children:i,editable:s,onSelectionChange:a,onChange:c,formattingToolbar:u,linkToolbar:m,slashMenu:p,emojiPicker:g,sideMenu:b,filePanel:f,tableHandles:x,comments:C,autoFocus:T,renderEditor:I=!0,...F}=e,[Q,te]=d.useState(),K=O(),ne=$t(),xe=K?.colorSchemePreference||ne,G=l||(xe==="dark"?"dark":"light"),_=h(),H=d.useMemo(()=>({formattingToolbar:_?u:!1,linkToolbar:_?m:!1,sideMenu:_?b:!1,slashMenu:_?p:!1,filePanel:_?f:!1,tableHandles:_?x:!1,emojiPicker:_?g:!1,comments:_?C:!1}),[C,_,g,f,u,m,b,p,x]);rl(c||Xe,t),ll(a||Xe,t);let Kt=d.useCallback(Yt=>{t.elementRenderer=Yt},[t]);d.useEffect(()=>{if(!t.portalElement)throw Error("Portal element not found");t.portalElement.className=R("bn-root",G,n||""),t.portalElement.setAttribute("data-color-scheme",G)},[t,G,n]);let Qt=d.useMemo(()=>({...K,editor:t,setContentEditableProps:te,colorSchemePreference:G}),[K,t,G]),Wt=d.useMemo(()=>({editorProps:{autoFocus:T,contentEditableProps:Q,editable:s},defaultUIProps:H}),[T,Q,s,H]);return r.jsx(yt.Provider,{value:Qt,children:r.jsxs(Ht.Provider,{value:Wt,children:[r.jsx(cl,{ref:Kt}),r.jsx(ul,{className:n,renderEditor:I,editorColorScheme:G,ref:o,...F,children:i})]})})}var ul=pe.forwardRef(({className:e,renderEditor:o,editorColorScheme:t,children:n,...l},i)=>r.jsx("div",{className:R("bn-root","bn-container",t,e),"data-color-scheme":t,...l,ref:i,children:o?r.jsx(pl,{children:n}):n})),ml=pe.forwardRef(dl),pl=e=>{let o=il(),t=v(),n=d.useMemo(()=>al(),[]),l=d.useCallback(i=>{t.isEditable=o.editorProps.editable!==!1,t._tiptapEditor.contentComponent=n,i?t.mount(i):t.unmount()},[o.editorProps.editable,t,n]);return r.jsxs(r.Fragment,{children:[r.jsx(sl,{contentComponent:n}),r.jsx(gl,{...o.editorProps,...e,mount:l}),r.jsx(ol,{...o.defaultUIProps}),e.children]})},gl=e=>{let{autoFocus:o,mount:t,contentEditableProps:n}=e;return r.jsx("div",{"aria-autocomplete":"list","aria-haspopup":"listbox","data-bn-autofocus":o,ref:t,...n})};function W(e,o){let t,n=document.createElement("div"),l;if(o?.elementRenderer)o.elementRenderer(e(c=>t=c||void 0),n);else{if(!o?.headless)throw Error("elementRenderer not available, expected headless editor");l=Mo.createRoot(n),ae.flushSync(()=>{l.render(e(c=>t=c||void 0))})}if(!n.childElementCount)return console.warn("ReactInlineContentSpec: renderHTML() failed"),{dom:document.createElement("span")};t?.setAttribute("data-tmp-find","true");let i=n.cloneNode(!0),s=i.firstElementChild,a=i.querySelector("[data-tmp-find]");return a?.removeAttribute("data-tmp-find"),l?.unmount(),{dom:s,contentDOM:a||void 0}}function je(e){return r.jsx(xt,{onDragOver:o=>o.preventDefault(),...Object.fromEntries(Object.entries(e.domAttributes||{}).filter(([o])=>o!=="class")),className:R("bn-block-content",e.domAttributes?.class||""),"data-content-type":e.blockType,...Object.fromEntries(Object.entries(e.blockProps).filter(([o,t])=>t!==e.propSchema[o].default).map(([o,t])=>[ot(o),t])),"data-file-block":e.isFileBlock===!0||void 0,children:e.children})}function pi(e,o,t){return(n={})=>{let l=typeof e=="function"?e(n):e,i=typeof o=="function"?o(n):o,s=t?typeof t=="function"?t(n):t:void 0;return{config:l,implementation:{...i,toExternalHTML(a,c,u){let m=i.toExternalHTML||i.render;return W(p=>r.jsx(je,{blockType:a.type,blockProps:a.props,propSchema:l.propSchema,domAttributes:this.blockContentDOMAttributes,isFileBlock:i.meta?.fileBlockAccept!==void 0,children:r.jsx(m,{block:a,editor:c,contentRef:g=>{p(g),g&&(g.className=R("bn-inline-content",g.className))},context:u})}),c)},render(a,c){if(this.renderType==="nodeView")return pt(u=>{let m=mn(u.getPos,c,u.editor,l.type),p=ht().nodeViewContentRef;if(!p)throw Error("nodeViewContentRef is not set");let g=i.render;return r.jsx(je,{blockType:m.type,blockProps:m.props,propSchema:l.propSchema,isFileBlock:!!i.meta?.fileBlockAccept,domAttributes:this.blockContentDOMAttributes,children:r.jsx(g,{block:m,editor:c,contentRef:b=>{p(b),b&&(b.className=R("bn-inline-content",b.className),b.dataset.nodeViewContent="")}})})},{className:"bn-react-node-view-renderer"})(this.props);{let u=i.render;return W(m=>r.jsx(je,{blockType:a.type,blockProps:a.props,propSchema:l.propSchema,domAttributes:this.blockContentDOMAttributes,children:r.jsx(u,{block:a,editor:c,contentRef:p=>{m(p),p&&(p.className=R("bn-inline-content",p.className))}})}),c)}}},extensions:s}}}pe.memo(({thread:e,selectedThreadId:o,maxCommentsBeforeCollapse:t,referenceText:n})=>{let l=w(B),i=d.useCallback(a=>{a.target.closest(".bn-action-toolbar")||l.selectThread(e.id)},[l,e.id]),s=d.useCallback(a=>{if(!a.relatedTarget||a.relatedTarget.closest(".bn-action-toolbar"))return;let c=a.target instanceof Node?a.target:null,u=a.relatedTarget instanceof Node?a.relatedTarget.closest(".bn-thread"):null;(!c||!u||!u.contains(c))&&l.selectThread(void 0)},[l]);return r.jsx(ze,{thread:e,selected:e.id===o,referenceText:n,maxCommentsBeforeCollapse:t,onFocus:i,onBlur:s,tabIndex:0})});function we(e){return r.jsx(xt,{as:"span",className:"bn-inline-content-section","data-inline-content-type":e.inlineContentType,...Object.fromEntries(Object.entries(e.inlineContentProps).filter(([o,t])=>t!==e.propSchema[o].default).map(([o,t])=>[ot(o),t])),children:e.children})}function gi(e,o){let t=go.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",draggable:o.meta?.draggable,content:e.content==="styled"?"inline*":"",addAttributes(){return hn(e.propSchema)},addKeyboardShortcuts(){return fn(e)},parseHTML(){return bn(e,o.parse)},renderHTML({node:n}){let l=this.options.editor,i=$e(n,l.schema.inlineContentSchema,l.schema.styleSchema),s=o.toExternalHTML||o.render;return gn(W(a=>r.jsx(s,{contentRef:c=>{a(c),c&&(c.dataset.editable="")},inlineContent:i,updateInlineContent:()=>{},editor:l}),l),e.type,n.attrs,e.propSchema)},addNodeView(){let n=this.options.editor;return l=>pt(i=>{let s=ht().nodeViewContentRef;if(!s)throw Error("nodeViewContentRef is not set");let a=o.render;return r.jsx(we,{inlineContentProps:i.node.attrs,inlineContentType:e.type,propSchema:e.propSchema,children:r.jsx(a,{contentRef:c=>{s(c),c&&(c.dataset.editable="")},editor:n,inlineContent:$e(i.node,n.schema.inlineContentSchema,n.schema.styleSchema),updateInlineContent:c=>{let u=pn([c],n.pmSchema),m=i.getPos();m!==void 0&&n.transact(p=>p.replaceWith(m,m+i.node.nodeSize,u))}})})},{className:"bn-ic-react-node-view-renderer",as:"span"})(l)}});return xn(e,{...o,node:t,render(n,l,i){let s=o.render;return W(a=>r.jsx(we,{inlineContentProps:n.props,inlineContentType:e.type,propSchema:e.propSchema,children:r.jsx(s,{contentRef:c=>{a(c),c&&(c.dataset.editable="")},editor:i,inlineContent:n,updateInlineContent:l})}),i)},toExternalHTML(n,l){let i=o.toExternalHTML||o.render;return W(s=>r.jsx(we,{inlineContentProps:n.props,inlineContentType:e.type,propSchema:e.propSchema,children:r.jsx(i,{contentRef:a=>{s(a),a&&(a.dataset.editable="")},editor:l,inlineContent:n,updateInlineContent:()=>{}})}),l)}})}function Ut(e,o){let t=e.getBoundingClientRect(),n=o.getBoundingClientRect(),l=t.top<n.top,i=t.bottom>n.bottom;return l&&i?"both":l?"top":i?"bottom":"none"}function bl(e){return o=>{e.forEach(t=>{typeof t=="function"?t(o):t!=null&&(t.current=o)})}}var Vt=(e,o,t=!1)=>{let n=[];function l(i,s="--bn"){for(let a in i){let c=`${s}-${a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}`;typeof i[a]=="object"?l(i[a],c):(typeof i[a]=="number"&&(i[a]=`${i[a]}px`),t?o.style.removeProperty(c):o.style.setProperty(c,i[a].toString()))}}return l(e),n},Je=(e,o)=>Vt(e,o),fl={colors:{editor:{text:void 0,background:void 0},menu:{text:void 0,background:void 0},tooltip:{text:void 0,background:void 0},hovered:{text:void 0,background:void 0},selected:{text:void 0,background:void 0},disabled:{text:void 0,background:void 0},shadow:void 0,border:void 0,sideMenu:void 0,highlights:{gray:{text:void 0,background:void 0},brown:{text:void 0,background:void 0},red:{text:void 0,background:void 0},orange:{text:void 0,background:void 0},yellow:{text:void 0,background:void 0},green:{text:void 0,background:void 0},blue:{text:void 0,background:void 0},purple:{text:void 0,background:void 0},pink:{text:void 0,background:void 0}}},borderRadius:void 0,fontFamily:void 0},hl=e=>Vt(fl,e,!0),qt=e=>r.jsxs(Oe,{gap:0,className:"bn-tooltip",children:[r.jsx($,{size:"sm",lineClamp:5,children:e.mainTooltip}),e.secondaryTooltip&&r.jsx($,{size:"xs",lineClamp:5,children:e.secondaryTooltip})]}),ye=d.forwardRef((e,o)=>{let{className:t,children:n,mainTooltip:l,secondaryTooltip:i,icon:s,isSelected:a,isDisabled:c,onClick:u,label:m,variant:p,...g}=e;j(g,!1);let[b,f]=d.useState(!1),x=n?r.jsx(V,{"aria-label":m,className:t,onMouseDown:C=>{Re()&&C.currentTarget.focus()},onClick:C=>{f(!0),u?.(C)},onPointerLeave:()=>f(!1),"aria-pressed":a,"data-selected":a||void 0,"data-test":l?l.slice(0,1).toLowerCase()+l.replace(/\s+/g,"").slice(1):void 0,size:p==="compact"?"compact-xs":"xs",disabled:c||!1,ref:o,...g,children:n}):r.jsx(Ne,{className:t,"aria-label":m,onMouseDown:C=>{Re()&&C.currentTarget.focus()},onClick:C=>{f(!0),u?.(C)},onPointerLeave:()=>f(!1),"aria-pressed":a,"data-selected":a||void 0,"data-test":l?l.slice(0,1).toLowerCase()+l.replace(/\s+/g,"").slice(1):void 0,size:p==="compact"?20:30,disabled:c||!1,ref:o,...g,children:s});return l?r.jsx(kt,{disabled:b,withinPortal:!1,label:r.jsx(qt,{mainTooltip:l,secondaryTooltip:i}),children:x}):x}),xl=d.forwardRef((e,o)=>{let{className:t,text:n,icon:l,isSelected:i,mainTooltip:s,secondaryTooltip:a,onClick:c,onMouseEnter:u,...m}=e;j(m,!1);let[p,g]=d.useState(!1),b=r.jsxs(Io,{className:t,checked:i===!0,wrapperProps:{onMouseEnter:u,onMouseLeave:()=>g(!1),onClick:f=>{g(!0),c?.(f)}},variant:"light",icon:null,ref:o,children:[r.jsx("span",{children:l}),r.jsx("span",{children:n})]});return!s||p?b:r.jsx(kt,{refProp:"rootRef",withinPortal:!1,label:r.jsx(qt,{mainTooltip:s,secondaryTooltip:a}),children:b})}),vl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l),r.jsx(M,{className:t,ref:o,children:n})}),Cl=d.forwardRef((e,o)=>{let{className:t,children:n,headerText:l,selected:i,onFocus:s,onBlur:a,tabIndex:c,...u}=e;return j(u,!1),r.jsxs(vt,{className:R(t,i?"selected":""),onFocus:s,onBlur:a,tabIndex:c,ref:o,children:[l&&r.jsx($,{className:"bn-header-text",children:l}),n]})}),kl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l,!1),r.jsx(vt.Section,{className:t,ref:o,children:n})}),jl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l,!1),r.jsx(ho,{className:t,label:r.jsx($,{children:n}),ref:o})}),wl=d.forwardRef((e,o)=>{let{authorInfo:t,timeString:n,edited:l,...i}=e,s=k();return j(i,!1),t==="loading"?r.jsxs(M,{children:[r.jsx(qe,{height:24,width:24}),r.jsx("div",{children:r.jsx(qe,{height:12,width:100})})]}):r.jsxs(M,{children:[r.jsx(Eo,{src:t.avatarUrl,alt:t.username,radius:"xl",size:"sm",color:"initials"}),r.jsxs($,{fz:"sm",fw:"bold",children:[t.username,r.jsxs($,{fz:"xs",c:"dimmed",span:!0,ml:"xs",children:[n," ",l&&`(${s.comments.edited})`]})]})]})}),yl=d.forwardRef((e,o)=>{let{className:t,showActions:n,authorInfo:l,timeString:i,edited:s,actions:a,emojiPickerOpen:c,children:u,...m}=e,{hovered:p,ref:g}=xo(),b=bl([o,g]);return j(m,!1),r.jsxs(M,{pos:"relative",ref:b,className:t,children:[a&&(n===!0||n===void 0||n==="hover"&&p||c)?r.jsx(M,{style:{position:"absolute",right:0,top:0,zIndex:10},children:a}):null,r.jsx(wl,{...e}),u]})}),Sl=d.forwardRef((e,o)=>{let{className:t,autoFocus:n,onFocus:l,onBlur:i,editor:s,editable:a,...c}=e;j(c,!1);let u=O();return r.jsx(ri,{autoFocus:n,className:t,editor:e.editor,sideMenu:!1,slashMenu:!1,tableHandles:!1,filePanel:!1,formattingToolbar:!1,editable:a,theme:u?.colorSchemePreference,ref:o,onFocus:l,onBlur:i,children:r.jsx(At,{formattingToolbar:Tl})})}),Tl=()=>r.jsx(Lt,{blockTypeSelectItems:[],children:Dt([]).filter(e=>e.key!=="nestBlockButton"&&e.key!=="unnestBlockButton")}),_l=d.forwardRef((e,o)=>{let{className:t,name:n,label:l,variant:i,icon:s,value:a,autoFocus:c,placeholder:u,disabled:m,onKeyDown:p,onChange:g,onSubmit:b,autoComplete:f,"aria-activedescendant":x,rightSection:C,...T}=e;return j(T),r.jsx(jt,{size:"xs",className:R(t||"",i==="large"?"bn-mt-input-large":""),ref:o,name:n,label:l,leftSection:s,value:a,autoFocus:c,"data-autofocus":c?"true":void 0,rightSection:C,placeholder:u,disabled:m,onKeyDown:p,onChange:g,onSubmit:b,autoComplete:f,"aria-activedescendant":x})}),Rl=d.createContext(void 0),El=e=>{let{children:o,onOpenChange:t,position:n,sub:l,...i}=e;return j(i),l?r.jsx(N.Sub,{transitionProps:{duration:250,exitDelay:250},withinPortal:!1,middlewares:{flip:!0,shift:!0,inline:!1,size:!0},onChange:t,position:n,children:o}):r.jsx(N,{withinPortal:!1,middlewares:{flip:!0,shift:!0,inline:!1,size:!0},onChange:t,position:n,returnFocus:!1,children:o})},Il=d.forwardRef((e,o)=>{let{className:t,children:n,icon:l,checked:i,subTrigger:s,onClick:a,...c}=e;return j(c,!1),r.jsx(s?N.Sub.Item:N.Item,{className:t,ref:o,leftSection:l,rightSection:i?r.jsx(Ct,{size:10}):i===!1?r.jsx("div",{className:"bn-tick-space"}):null,onClick:a,...c,children:n})}),Ml=e=>{let{children:o,sub:t,...n}=e;return j(n),r.jsx(t?N.Sub.Target:N.Target,{children:o})},Pl=d.forwardRef((e,o)=>{let{className:t,children:n,sub:l,...i}=e;j(i);let s=d.useContext(Rl);return r.jsx(l?N.Sub.Dropdown:N.Dropdown,{className:t,ref:o,onMouseOver:s?.onMenuMouseOver,onMouseLeave:s?.onMenuMouseLeave,children:n})}),Nl=d.forwardRef((e,o)=>{let{className:t,...n}=e;return j(n),r.jsx(N.Divider,{className:t,ref:o})}),Bl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l),r.jsx(N.Label,{className:t,ref:o,children:n})}),Ol=d.forwardRef((e,o)=>{let{className:t,children:n,icon:l,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,label:u,...m}=e;return j(m,!1),l?r.jsx(Ne,{size:24,className:t,ref:o,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,"aria-label":u,...m,children:l}):r.jsx(V,{className:t,ref:o,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,"aria-label":u,...m,children:n})}),Fl=d.forwardRef((e,o)=>{let{className:t,tabs:n,defaultOpenTab:l,openTab:i,setOpenTab:s,loading:a,...c}=e;return j(c),r.jsx(M,{className:t,ref:o,children:r.jsxs(oe,{value:i,defaultValue:l,onChange:s,children:[a&&r.jsx(Ro,{visible:a}),r.jsx(oe.List,{children:n.map(u=>r.jsx(oe.Tab,{"data-test":`${u.name.toLowerCase()}-tab`,value:u.name,children:u.name},u.name))}),n.map(u=>r.jsx(oe.Panel,{value:u.name,children:u.tabPanel},u.name))]})})}),Dl=d.forwardRef((e,o)=>{let{className:t,children:n,onClick:l,label:i,...s}=e;return j(s),r.jsx(V,{size:"xs","aria-label":i,className:t,ref:o,onClick:l,...s,children:n})}),Ll=d.forwardRef((e,o)=>{let{className:t,accept:n,value:l,placeholder:i,onChange:s,...a}=e;return j(a),r.jsx(_o,{size:"xs",className:t,ref:o,accept:n,value:l,placeholder:i,onChange:s,...a})}),Al=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l),r.jsx("div",{className:t,ref:o,children:n})}),zl=d.forwardRef((e,o)=>{let{className:t,value:n,placeholder:l,onKeyDown:i,onChange:s,...a}=e;return j(a),r.jsx(jt,{size:"xs","data-test":"embed-input",className:t,ref:o,value:n,placeholder:l,onKeyDown:i,onChange:s})}),Gl=e=>{let{open:o,onOpenChange:t,position:n,portalRoot:l,children:i,...s}=e;return j(s),r.jsx(So,{middlewares:{size:{padding:20}},withinPortal:!!l,portalProps:l?{target:l}:void 0,opened:o,onChange:t,position:n,children:i})},$l=e=>{let{children:o,...t}=e;return j(t),r.jsx(yo,{children:o})},Hl=d.forwardRef((e,o)=>{let{className:t,children:n,variant:l,...i}=e;return j(i),r.jsx(wo,{className:t,ref:o,children:n})}),Ul=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l,!1),r.jsx(M,{align:"center",gap:0,className:t,ref:o,...l,children:n})}),Vl=d.forwardRef((e,o)=>{let{className:t,children:n,icon:l,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,label:u,...m}=e;return j(m,!1),l?r.jsx(Ne,{size:24,className:t,ref:o,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,"aria-label":u,...m,children:l}):r.jsx(V,{className:t,ref:o,onClick:i,onDragEnd:s,onDragStart:a,draggable:c,"aria-label":u,...m,children:n})}),ql=d.forwardRef((e,o)=>{let{className:t,children:n,id:l,...i}=e;return j(i),r.jsx(Oe,{gap:0,className:t,ref:o,id:l,role:"listbox",children:n})}),Kl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l),r.jsx(M,{className:t,ref:o,children:r.jsx(M,{className:"bn-mt-suggestion-menu-item-title",children:n})})}),Ql=d.forwardRef((e,o)=>{let{className:t,isSelected:n,onClick:l,item:i,id:s,...a}=e;j(a);let c=d.useRef(null);return d.useEffect(()=>{!c.current||!n||Ut(c.current,c.current.closest(".bn-suggestion-menu, #ai-suggestion-menu"))!=="none"&&c.current.scrollIntoView({block:"nearest"})},[n]),r.jsxs(M,{gap:0,className:t,ref:Be(o,c),id:s,role:"option",onMouseDown:u=>u.preventDefault(),onClick:l,"aria-selected":n||void 0,children:[i.icon&&r.jsx(M,{className:"bn-mt-suggestion-menu-item-section","data-position":"left",children:i.icon}),r.jsxs(Oe,{gap:0,className:"bn-mt-suggestion-menu-item-body",children:[r.jsx($,{className:"bn-mt-suggestion-menu-item-title",children:i.title}),r.jsx($,{className:"bn-mt-suggestion-menu-item-subtitle",children:i.subtext})]}),i.badge&&r.jsx(M,{"data-position":"right",className:"bn-mt-suggestion-menu-item-section",children:r.jsx(To,{size:"xs",children:i.badge})})]})}),Wl=d.forwardRef((e,o)=>{let{className:t,children:n,...l}=e;return j(l),r.jsx(M,{className:t,ref:o,children:n})}),Yl=d.forwardRef((e,o)=>{let{className:t,...n}=e;return j(n),r.jsx(wt,{className:t,type:"dots",size:16,ref:o})}),Zl=d.forwardRef((e,o)=>{let{className:t,children:n,id:l,columns:i,...s}=e;return j(s),r.jsx("div",{className:t,style:{gridTemplateColumns:`repeat(${i}, 1fr)`},ref:o,id:l,role:"grid",children:n})}),Xl=d.forwardRef((e,o)=>{let{className:t,children:n,columns:l,...i}=e;return j(i),r.jsx(M,{className:t,style:{gridColumn:`1 / ${l+1}`},ref:o,children:r.jsx(M,{className:"bn-mt-suggestion-menu-item-title",children:n})})}),Jl=d.forwardRef((e,o)=>{let{className:t,isSelected:n,onClick:l,item:i,id:s,...a}=e;j(a);let c=d.useRef(null);return d.useEffect(()=>{!c.current||!n||Ut(c.current,c.current.closest(".bn-grid-suggestion-menu"))!=="none"&&c.current.scrollIntoView({block:"nearest"})},[n]),r.jsx("div",{className:t,ref:Be(o,c),id:s,role:"option",onClick:l,"aria-selected":n||void 0,children:i.icon})}),ei=d.forwardRef((e,o)=>{let{className:t,children:n,columns:l,...i}=e;return j(i),r.jsx(wt,{className:t,style:{gridColumn:`1 / ${l+1}`},type:"dots",ref:o})}),ti=d.forwardRef((e,o)=>{let{children:t,className:n,onMouseDown:l,onClick:i,...s}=e;return j(s,!1),r.jsx(V,{className:n,ref:o,onMouseDown:l,onClick:i,...s,children:t})}),ni=d.forwardRef((e,o)=>{let{className:t,children:n,draggable:l,onDragStart:i,onDragEnd:s,style:a,label:c,...u}=e;return j(u,!1),r.jsx(V,{className:t,ref:o,"aria-label":c,draggable:l,onDragStart:i,onDragEnd:s,style:a,...u,children:n})}),Se=d.forwardRef((e,o)=>{let{className:t,children:n,onMouseEnter:l,onMouseLeave:i,variant:s,...a}=e;j(a);let{ref:c,focused:u}=Co();return r.jsx(ko,{className:t,ref:Be(o,c,jo(u)),role:"toolbar",onMouseEnter:l,onMouseLeave:i,gap:s==="action-toolbar"?2:void 0,children:n})}),Te=d.forwardRef((e,o)=>{let{className:t,items:n,isDisabled:l,...i}=e;j(i);let s=n.filter(a=>a.isSelected)[0];return s?r.jsxs(N,{withinPortal:!1,transitionProps:{exitDuration:0},disabled:l,middlewares:{flip:!0,shift:!0,inline:!1,size:!0},children:[r.jsx(N.Target,{children:r.jsx(V,{onMouseDown:a=>{Re()&&a.currentTarget.focus()},leftSection:s.icon,rightSection:r.jsx(vo,{}),size:"xs",variant:"subtle",disabled:l,children:s.text})}),r.jsx(N.Dropdown,{className:t,ref:o,children:n.map(a=>r.jsx(N.Item,{onClick:a.onClick,leftSection:a.icon,rightSection:a.isSelected?r.jsx(Ct,{size:10,className:"bn-tick-icon"}):r.jsx("div",{className:"bn-tick-space"}),disabled:a.isDisabled,children:a.text},a.text))})]}):null}),oi={FormattingToolbar:{Root:Se,Button:ye,Select:Te},FilePanel:{Root:Fl,Button:Dl,FileInput:Ll,TabPanel:Al,TextInput:zl},GridSuggestionMenu:{Root:Zl,Item:Jl,EmptyItem:Xl,Loader:ei},LinkToolbar:{Root:Se,Button:ye,Select:Te},SideMenu:{Root:Ul,Button:Vl},SuggestionMenu:{Root:ql,Item:Ql,EmptyItem:Kl,Label:Wl,Loader:Yl},TableHandle:{Root:ni,ExtendButton:ti},Generic:{Badge:{Root:xl,Group:vl},Form:{Root:e=>r.jsx("div",{children:e.children}),TextInput:_l},Menu:{Root:El,Trigger:Ml,Dropdown:Pl,Divider:Nl,Label:Bl,Item:Il,Button:Ol},Popover:{Root:Gl,Trigger:$l,Content:Hl},Toolbar:{Root:Se,Button:ye,Select:Te}},Comments:{Comment:yl,Editor:Sl,Card:Cl,CardSection:kl,ExpandSectionsPrompt:jl}},ri=e=>{let{className:o,theme:t,editor:n,...l}=e,i=O(),s=$t(),a=i?.colorSchemePreference||s,c=typeof t=="string"?t:a==="no-preference"?"light":a,u=d.useCallback(g=>{if(g&&(hl(g),typeof t=="object")){if("light"in t&&"dark"in t){Je(t[a==="dark"?"dark":"light"],g);return}Je(t,g);return}},[a,t]);d.useEffect(()=>{if(!n.portalElement)throw Error("Portal element not found");n.portalElement.setAttribute("data-mantine-color-scheme",c),u(n.portalElement)},[n,u,c]);let m=d.useContext(bo),p=r.jsx(St.Provider,{value:oi,children:r.jsx(ml,{"data-mantine-color-scheme":c,className:R("bn-mantine",o||""),theme:typeof t=="object"?void 0:t,editor:n,...l,ref:u})});return m?p:r.jsx(fo,{withCssVariables:!1,getRootElement:()=>{},children:p})};export{De as K,gi as L,v as M,pi as Z,ri as a,Gr as h,zr as m};
@@ -1,4 +1,4 @@
1
- import{r as x,j as e}from"./floating-ui.react-dom-BWTnA00G.js";import{g as J,a as V,b as $,P as v,f as j,M as W}from"./useNoteMutate-BjvZUmtX.js";import{g as w,u as Z,q as N,P as ee,T as s,s as ae,B as C,F as se,M as d,L as b,I as P,k as te,l as D,h as le,e as ne}from"./time-PxWila4-.js";import{F as re}from"./app-BezcjTfd.js";import{S as k}from"./SurfaceCard-D5QxOte_.js";import{d as ie}from"./url-DKUMNVCI.js";import{s as oe}from"./CaretUp.es-C8iY5OlB.js";import{n as ce}from"./Plus.es-Dy6onD-Z.js";import"./preload-helper-BXl3LOEh.js";import"./Graph-hVj6vAYJ.js";const O=["id","name","template","replacement","createdAt","updatedAt"],de=new Set(O),me=`query FetchPlaceholders(
1
+ import{r as x,j as e}from"./floating-ui.react-dom-BWTnA00G.js";import{g as J,a as V,b as $,P as v,f as j,M as W}from"./useNoteMutate-BjvZUmtX.js";import{g as w,u as Z,q as N,P as ee,T as s,s as ae,B as C,F as se,M as d,L as b,I as P,k as te,l as D,h as le,e as ne}from"./time-PxWila4-.js";import{F as re}from"./app-BFM2V_Rx.js";import{S as k}from"./SurfaceCard-D5QxOte_.js";import{d as ie}from"./url-DKUMNVCI.js";import{s as oe}from"./CaretUp.es-C8iY5OlB.js";import{n as ce}from"./Plus.es-Dy6onD-Z.js";import"./preload-helper-BXl3LOEh.js";import"./Graph-hVj6vAYJ.js";const O=["id","name","template","replacement","createdAt","updatedAt"],de=new Set(O),me=`query FetchPlaceholders(
2
2
  $searchFilter: SearchFilterInput,
3
3
  $pagination: PaginationInput
4
4
  ) {
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Note-CGI-Y1__.js","assets/floating-ui.react-dom-BWTnA00G.js","assets/time-PxWila4-.js","assets/url-DKUMNVCI.js","assets/useNoteMutate-BjvZUmtX.js","assets/Callout-CcYyvHQP.js","assets/Info.es-CYxg-Vku.js","assets/NotePropertiesPanel-6P7UfRBR.js","assets/AuxiliaryPanelHeader-HAttwVby.js","assets/LinkSimple.es-B-P-7Iem.js","assets/Plus.es-Dy6onD-Z.js","assets/SurfaceCard-D5QxOte_.js","assets/useReminderMutate-C5n-5LM-.js","assets/note-ui-BaqzP-YU.js","assets/note-core-DUTqUh5N.js","assets/note-runtime-zN5ddTba.js","assets/preload-helper-BXl3LOEh.js","assets/note-ui-DL8owV-U.css","assets/image.api-ChvlfuZg.js","assets/FlowArrow.es-Dxee98ir.js","assets/Copy.es-fMv0ETir.js","assets/tag.api-DEUROVKQ.js","assets/File.es-CHtXXafR.js","assets/Graph-CdEu8eAn.js","assets/transform-BUB79_za.js","assets/isObject-U9U2HXiq.js","assets/toNumber-DE3J3kMD.js","assets/ordinal-Cboi1Yqb.js","assets/init-Gi6I4Gst.js","assets/colors-Cc3OSVma.js","assets/min-tv6RD-6E.js","assets/Graph-hVj6vAYJ.js","assets/ArrowRight.es-BlNsZQFs.js","assets/CaretUp.es-C8iY5OlB.js","assets/FileText.es-DPIwDCEe.js"])))=>i.map(i=>d[i]);
2
- import{_ as r}from"./preload-helper-BXl3LOEh.js";import{A as n,N as a,G as _}from"./url-DKUMNVCI.js";const l=new Set(Object.values(n).filter(t=>t!==a).map(t=>t.split("/")[1]).filter(t=>!!t)),s=t=>{const o=t.split("/").filter(Boolean);if(o.length!==1)return null;const[e]=o;return`/${e}`===_?"graph":!e||l.has(e)?null:"note"},i=s(window.location.pathname);i==="note"?r(()=>import("./Note-CGI-Y1__.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).catch(()=>{}):i==="graph"&&r(()=>import("./Graph-CdEu8eAn.js"),__vite__mapDeps([23,1,2,3,24,25,26,27,28,29,30,31,32,19,33,34,6,9])).catch(()=>{});
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Note-CpzLtGVM.js","assets/floating-ui.react-dom-BWTnA00G.js","assets/time-PxWila4-.js","assets/url-DKUMNVCI.js","assets/useNoteMutate-BjvZUmtX.js","assets/Callout-CcYyvHQP.js","assets/Info.es-CYxg-Vku.js","assets/NotePropertiesPanel-6P7UfRBR.js","assets/AuxiliaryPanelHeader-HAttwVby.js","assets/LinkSimple.es-B-P-7Iem.js","assets/Plus.es-Dy6onD-Z.js","assets/SurfaceCard-D5QxOte_.js","assets/useReminderMutate-C5n-5LM-.js","assets/note-ui-BtzPk8gA.js","assets/note-core-YhYEmI_R.js","assets/note-runtime-B3ats-dC.js","assets/preload-helper-BXl3LOEh.js","assets/note-ui-DL8owV-U.css","assets/image.api-ChvlfuZg.js","assets/FlowArrow.es-Dxee98ir.js","assets/Copy.es-fMv0ETir.js","assets/tag.api-DEUROVKQ.js","assets/File.es-CHtXXafR.js","assets/Graph-CdEu8eAn.js","assets/transform-BUB79_za.js","assets/isObject-U9U2HXiq.js","assets/toNumber-DE3J3kMD.js","assets/ordinal-Cboi1Yqb.js","assets/init-Gi6I4Gst.js","assets/colors-Cc3OSVma.js","assets/min-tv6RD-6E.js","assets/Graph-hVj6vAYJ.js","assets/ArrowRight.es-BlNsZQFs.js","assets/CaretUp.es-C8iY5OlB.js","assets/FileText.es-DPIwDCEe.js"])))=>i.map(i=>d[i]);
2
+ import{_ as r}from"./preload-helper-BXl3LOEh.js";import{A as n,N as a,G as _}from"./url-DKUMNVCI.js";const l=new Set(Object.values(n).filter(t=>t!==a).map(t=>t.split("/")[1]).filter(t=>!!t)),s=t=>{const o=t.split("/").filter(Boolean);if(o.length!==1)return null;const[e]=o;return`/${e}`===_?"graph":!e||l.has(e)?null:"note"},i=s(window.location.pathname);i==="note"?r(()=>import("./Note-CpzLtGVM.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).catch(()=>{}):i==="graph"&&r(()=>import("./Graph-CdEu8eAn.js"),__vite__mapDeps([23,1,2,3,24,25,26,27,28,29,30,31,32,19,33,34,6,9])).catch(()=>{});
@@ -8,7 +8,7 @@
8
8
  <link rel="icon" type="image/png" href="/icon.png" />
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>Ocean Brain</title>
11
- <script type="module" crossorigin src="/assets/app-BezcjTfd.js"></script>
11
+ <script type="module" crossorigin src="/assets/app-BFM2V_Rx.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/floating-ui.react-dom-BWTnA00G.js">
13
13
  <link rel="modulepreload" crossorigin href="/assets/url-DKUMNVCI.js">
14
14
  <link rel="modulepreload" crossorigin href="/assets/time-PxWila4-.js">
@@ -1,29 +1,112 @@
1
- import express from "express";
1
+ import fastifyCookie, { Signer } from "@fastify/cookie";
2
+ import fastifyCsrfProtection from "@fastify/csrf-protection";
3
+ import fastifyFormbody from "@fastify/formbody";
4
+ import fastifyRateLimit from "@fastify/rate-limit";
5
+ import fastifySession from "@fastify/session";
6
+ import Fastify from "fastify";
2
7
  import { createMcpAdminService } from "./features/mcp-admin/service.js";
3
8
  import { purgeExpiredNoteSnapshots } from "./features/note/services/snapshot.js";
4
9
  import { purgeExpiredTrashedNotes } from "./features/note/services/trash.js";
5
- import { createSessionMiddleware } from "./modules/auth-guard.js";
6
- import { createErrorHandler } from "./modules/error-handler.js";
7
- import logger from "./modules/logger.js";
10
+ import { closeDefaultSemanticSearchManager } from "./features/search/search-manager.js";
11
+ import { createAppError, createErrorHandler } from "./modules/error-handler.js";
12
+ import { AUTH_SESSION_IDLE_TIMEOUT_MS, createSessionStore } from "./modules/session-store.js";
8
13
  import { createApiRouter, createAuthPagesRouter, createClientRouter, createGraphqlRouter } from "./routes/index.js";
14
+ const MAX_REQUEST_BODY_BYTES = 50 * 1024 * 1024;
15
+ const isHttpLoggerEnabled = (loggerOption) => loggerOption ?? process.env.OCEAN_BRAIN_HTTP_LOG?.toLowerCase() !== "false";
16
+ const createLoggerOptions = () => ({
17
+ level: "info",
18
+ serializers: {
19
+ req(request) {
20
+ return {
21
+ method: request.method,
22
+ url: request.url,
23
+ remoteAddress: request.ip,
24
+ userAgent: request.headers["user-agent"]
25
+ };
26
+ },
27
+ res(reply) {
28
+ return { statusCode: reply.statusCode };
29
+ }
30
+ }
31
+ });
32
+ const createFastifyApplication = (options = {}) => Fastify({
33
+ bodyLimit: MAX_REQUEST_BODY_BYTES,
34
+ routerOptions: { ignoreTrailingSlash: true },
35
+ logger: isHttpLoggerEnabled(options.logger) ? createLoggerOptions() : false
36
+ });
37
+ const registerRequestInfrastructure = (app, authConfig) => {
38
+ app.addHook("onRequest", (request, _reply, done) => {
39
+ const contentEncoding = request.headers["content-encoding"];
40
+ if (contentEncoding && contentEncoding.toLowerCase() !== "identity") {
41
+ done(createAppError(415, "UNSUPPORTED_CONTENT_ENCODING", "Compressed request bodies are not supported."));
42
+ return;
43
+ }
44
+ done();
45
+ });
46
+ app.register(fastifyCookie);
47
+ app.register(fastifyFormbody);
48
+ app.register(fastifyRateLimit, {
49
+ global: false,
50
+ enableDraftSpec: true
51
+ });
52
+ if (authConfig.mode !== "password") {
53
+ return;
54
+ }
55
+ const sessionStore = createSessionStore();
56
+ app.addHook("onClose", (_instance, done) => {
57
+ if ("stopPruning" in sessionStore && typeof sessionStore.stopPruning === "function") {
58
+ sessionStore.stopPruning();
59
+ }
60
+ done();
61
+ });
62
+ app.register(fastifySession, {
63
+ // Preserve the configured secret bytes and support legacy secrets shorter than 32 characters.
64
+ secret: new Signer(authConfig.sessionSecret),
65
+ cookieName: authConfig.cookieName,
66
+ cookiePrefix: "s:",
67
+ store: sessionStore,
68
+ saveUninitialized: false,
69
+ rolling: true,
70
+ cookie: {
71
+ maxAge: AUTH_SESSION_IDLE_TIMEOUT_MS,
72
+ httpOnly: true,
73
+ sameSite: "lax",
74
+ secure: process.env.NODE_ENV === "production",
75
+ path: "/"
76
+ }
77
+ });
78
+ app.register(fastifyCsrfProtection, {
79
+ sessionPlugin: "@fastify/session",
80
+ logLevel: "debug"
81
+ });
82
+ };
9
83
  const createApp = (authConfig, options = {}) => {
10
84
  const mcpAdminService = createMcpAdminService();
11
85
  return createAppWithMcpAuth(authConfig, mcpAdminService, options);
12
86
  };
13
87
  const createAppWithMcpAuth = (authConfig, mcpAdminService, options = {}) => {
14
- const app = options.application ?? express();
15
- app.locals.authConfig = authConfig;
16
- void Promise.all([purgeExpiredNoteSnapshots(), purgeExpiredTrashedNotes()]).catch((error) => {
88
+ const app = options.application ?? createFastifyApplication(options);
89
+ const startupCleanup = Promise.all([purgeExpiredNoteSnapshots(), purgeExpiredTrashedNotes()]).catch((error) => {
17
90
  const message = error instanceof Error ? error.message : "Unknown recovery cleanup error";
18
91
  process.stderr.write(`[recovery] Startup cleanup failed: ${message}
19
92
  `);
20
93
  });
21
- app.use(logger).use(createSessionMiddleware(authConfig)).use(express.urlencoded({ extended: false, inflate: false })).use(express.json({ limit: "50mb", inflate: false })).use("/api", createApiRouter(authConfig, mcpAdminService)).use(createAuthPagesRouter(authConfig)).use("/graphql", createGraphqlRouter(authConfig, mcpAdminService)).use(createClientRouter(authConfig, options.clientContentMiddleware)).use(createErrorHandler());
94
+ app.addHook("onClose", async () => {
95
+ await startupCleanup;
96
+ await closeDefaultSemanticSearchManager();
97
+ });
98
+ registerRequestInfrastructure(app, authConfig);
99
+ app.setErrorHandler(createErrorHandler(authConfig));
100
+ app.register(createApiRouter(authConfig, mcpAdminService), { prefix: "/api" });
101
+ app.register(createAuthPagesRouter(authConfig));
102
+ app.register(createGraphqlRouter(authConfig, mcpAdminService));
103
+ app.register(createClientRouter(authConfig, options.clientContentHandler));
22
104
  return app;
23
105
  };
24
106
  var app_default = createApp;
25
107
  export {
26
108
  createApp,
27
109
  createAppWithMcpAuth,
110
+ createFastifyApplication,
28
111
  app_default as default
29
112
  };
@@ -10,7 +10,7 @@ import {
10
10
  setSessionStatusHeaders
11
11
  } from "../service.js";
12
12
  const createLoginHandler = (authConfig) => {
13
- return async (req, res) => {
13
+ return async (req, reply) => {
14
14
  const expectedPassword = assertPasswordLoginAvailable(authConfig);
15
15
  const password = typeof req.body?.password === "string" ? req.body.password : "";
16
16
  if (!password || !compareSharedSecret(expectedPassword, password)) {
@@ -18,22 +18,23 @@ const createLoginHandler = (authConfig) => {
18
18
  }
19
19
  await regenerateSession(req);
20
20
  req.session.authenticated = true;
21
- refreshCsrfToken(req);
22
- res.status(200).json(buildSessionResponse(authConfig, req)).end();
21
+ refreshCsrfToken(authConfig, reply);
22
+ return reply.status(200).send(buildSessionResponse(authConfig, req));
23
23
  };
24
24
  };
25
25
  const createLogoutHandler = (authConfig) => {
26
- return async (req, res) => {
26
+ return async (req, reply) => {
27
27
  if (authConfig.mode === "password") {
28
28
  await destroySession(req);
29
29
  }
30
- res.status(200).json(buildAuthSessionResponse(authConfig, false)).end();
30
+ return reply.status(200).send(buildAuthSessionResponse(authConfig, false));
31
31
  };
32
32
  };
33
33
  const createSessionStatusHandler = (authConfig) => {
34
- return async (req, res) => {
35
- setSessionStatusHeaders(res);
36
- res.status(200).json(buildSessionResponse(authConfig, req)).end();
34
+ return async (req, reply) => {
35
+ setSessionStatusHeaders(reply);
36
+ refreshCsrfToken(authConfig, reply);
37
+ return reply.status(200).send(buildSessionResponse(authConfig, req));
37
38
  };
38
39
  };
39
40
  export {
@@ -1,3 +1,4 @@
1
+ import { issueCsrfToken } from "../../../modules/auth-guard.js";
1
2
  import {
2
3
  compareSharedSecret,
3
4
  destroySession,
@@ -7,65 +8,63 @@ import {
7
8
  sanitizeRedirectPath
8
9
  } from "../service.js";
9
10
  import { renderLoginPage } from "./login-page.js";
10
- const setLoginPageHeaders = (res) => {
11
- res.set("Cache-Control", "no-store");
11
+ const setLoginPageHeaders = (reply) => {
12
+ reply.header("Cache-Control", "no-store");
12
13
  };
13
14
  const createLoginPageHandler = (authConfig) => {
14
- return async (req, res) => {
15
+ return async (req, reply) => {
15
16
  if (authConfig.mode !== "password" || req.session?.authenticated) {
16
- setLoginPageHeaders(res);
17
- res.redirect(303, sanitizeRedirectPath(req.query.next));
18
- return;
17
+ setLoginPageHeaders(reply);
18
+ return reply.redirect(sanitizeRedirectPath(req.query.next), 303);
19
19
  }
20
20
  const nextPath = sanitizeRedirectPath(req.query.next);
21
- setLoginPageHeaders(res);
22
- res.status(200).type("html").send(
21
+ const csrfToken = issueCsrfToken(authConfig, reply);
22
+ setLoginPageHeaders(reply);
23
+ return reply.status(200).type("text/html; charset=utf-8").send(
23
24
  renderLoginPage({
24
25
  nextPath,
25
- csrfToken: res.locals._csrf,
26
+ csrfToken,
26
27
  sessionGeneration: getSessionGeneration()
27
28
  })
28
- ).end();
29
+ );
29
30
  };
30
31
  };
31
32
  const createLoginPageSubmitHandler = (authConfig) => {
32
- return async (req, res) => {
33
+ return async (req, reply) => {
33
34
  const nextPath = sanitizeRedirectPath(req.body?.next);
34
35
  if (authConfig.mode !== "password" || !authConfig.password) {
35
- setLoginPageHeaders(res);
36
- res.redirect(303, nextPath);
37
- return;
36
+ setLoginPageHeaders(reply);
37
+ return reply.redirect(nextPath, 303);
38
38
  }
39
39
  const password = typeof req.body?.password === "string" ? req.body.password : "";
40
40
  if (!password || !compareSharedSecret(authConfig.password, password)) {
41
- setLoginPageHeaders(res);
42
- res.status(401).type("html").send(
41
+ const csrfToken = issueCsrfToken(authConfig, reply);
42
+ setLoginPageHeaders(reply);
43
+ return reply.status(401).type("text/html; charset=utf-8").send(
43
44
  renderLoginPage({
44
45
  nextPath,
45
46
  errorMessage: "Invalid password",
46
- csrfToken: res.locals._csrf,
47
+ csrfToken,
47
48
  sessionGeneration: getSessionGeneration()
48
49
  })
49
- ).end();
50
- return;
50
+ );
51
51
  }
52
52
  await regenerateSession(req);
53
53
  req.session.authenticated = true;
54
- refreshCsrfToken(req);
55
- setLoginPageHeaders(res);
56
- res.redirect(303, nextPath);
54
+ refreshCsrfToken(authConfig, reply);
55
+ setLoginPageHeaders(reply);
56
+ return reply.redirect(nextPath, 303);
57
57
  };
58
58
  };
59
59
  const createLogoutPageHandler = (authConfig) => {
60
- return async (req, res) => {
60
+ return async (req, reply) => {
61
61
  if (authConfig.mode === "password") {
62
62
  await destroySession(req);
63
- setLoginPageHeaders(res);
64
- res.redirect(303, "/login");
65
- return;
63
+ setLoginPageHeaders(reply);
64
+ return reply.redirect("/login", 303);
66
65
  }
67
- setLoginPageHeaders(res);
68
- res.redirect(303, "/");
66
+ setLoginPageHeaders(reply);
67
+ return reply.redirect("/", 303);
69
68
  };
70
69
  };
71
70
  export {
@@ -1,6 +1,7 @@
1
1
  import { buildAuthSessionResponse } from "@baejino/auth";
2
2
  import { compareSharedSecret as compareCommonSharedSecret } from "@baejino/auth/crypto";
3
3
  import crypto from "crypto";
4
+ import { issueCsrfToken } from "../../modules/auth-guard.js";
4
5
  import { sanitizeRedirectPath } from "../../modules/auth-redirect.js";
5
6
  import { createAppError } from "../../modules/error-handler.js";
6
7
  const AUTH_SESSION_GENERATION_HEADER = "X-Ocean-Brain-Session-Generation";
@@ -18,44 +19,23 @@ const comparePassword = async (password, storedHash) => {
18
19
  };
19
20
  const compareSharedSecret = compareCommonSharedSecret;
20
21
  const buildSessionResponse = (authConfig, req) => buildAuthSessionResponse(authConfig, Boolean(req.session?.authenticated));
21
- const setSessionStatusHeaders = (res) => {
22
- res.set(AUTH_SESSION_GENERATION_HEADER, getSessionGeneration());
23
- res.set("Cache-Control", "no-store");
24
- };
25
- const refreshCsrfToken = (req) => {
26
- const requestWithCsrf = req;
27
- requestWithCsrf.csrfToken?.();
22
+ const setSessionStatusHeaders = (reply) => {
23
+ reply.header(AUTH_SESSION_GENERATION_HEADER, getSessionGeneration());
24
+ reply.header("Cache-Control", "no-store");
28
25
  };
26
+ const refreshCsrfToken = (authConfig, reply) => issueCsrfToken(authConfig, reply);
29
27
  const assertPasswordLoginAvailable = (authConfig) => {
30
28
  if (authConfig.mode !== "password") {
31
29
  throw createAppError(409, "AUTH_OPEN_MODE", "Login is unavailable while auth mode is open.");
32
30
  }
33
31
  return authConfig.password;
34
32
  };
35
- const regenerateSession = async (req) => {
36
- await new Promise((resolve, reject) => {
37
- req.session.regenerate((error) => {
38
- if (error) {
39
- reject(error);
40
- return;
41
- }
42
- resolve();
43
- });
44
- });
45
- };
33
+ const regenerateSession = async (req) => req.session.regenerate();
46
34
  const destroySession = async (req) => {
47
35
  if (!req.session) {
48
36
  return;
49
37
  }
50
- await new Promise((resolve, reject) => {
51
- req.session.destroy((error) => {
52
- if (error) {
53
- reject(error);
54
- return;
55
- }
56
- resolve();
57
- });
58
- });
38
+ await req.session.destroy();
59
39
  };
60
40
  export {
61
41
  AUTH_SESSION_GENERATION_HEADER,
@@ -9,7 +9,7 @@ const cacheType = gql`
9
9
  const cacheQuery = gql`
10
10
  type Query {
11
11
  allCaches: [Cache!]!
12
- cache(key: String!): Cache!
12
+ cache(key: String!): Cache
13
13
  }
14
14
  `;
15
15
  const cacheMutation = gql`