@blocknote/core 0.29.0 → 0.30.0

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 (69) hide show
  1. package/README.md +125 -0
  2. package/dist/blocknote.cjs +9 -9
  3. package/dist/blocknote.cjs.map +1 -1
  4. package/dist/blocknote.js +1479 -1339
  5. package/dist/blocknote.js.map +1 -1
  6. package/dist/locales.cjs +1 -1
  7. package/dist/locales.cjs.map +1 -1
  8. package/dist/locales.js +751 -9
  9. package/dist/locales.js.map +1 -1
  10. package/dist/style.css +1 -1
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/dist/webpack-stats.json +1 -1
  13. package/package.json +3 -6
  14. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +0 -7
  15. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -5
  16. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +0 -20
  17. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +0 -12
  18. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -6
  19. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +0 -17
  20. package/src/api/clipboard/fromClipboard/pasteExtension.ts +19 -1
  21. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -0
  22. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +32 -18
  23. package/src/blocks/FileBlockContent/FileBlockContent.ts +5 -0
  24. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +9 -2
  25. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +3 -0
  26. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +10 -2
  27. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +9 -25
  28. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +14 -3
  29. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +9 -26
  30. package/src/blocks/ListItemBlockContent/getListItemContent.ts +115 -0
  31. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +6 -2
  32. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +6 -1
  33. package/src/blocks/TableBlockContent/TableBlockContent.ts +71 -14
  34. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +10 -2
  35. package/src/blocks/defaultBlockHelpers.ts +16 -0
  36. package/src/editor/Block.css +2 -1
  37. package/src/editor/BlockNoteEditor.ts +103 -60
  38. package/src/editor/BlockNoteExtensions.ts +14 -5
  39. package/src/extensions/Collaboration/CursorPlugin.ts +152 -0
  40. package/src/extensions/Collaboration/SyncPlugin.ts +15 -0
  41. package/src/extensions/Collaboration/UndoPlugin.ts +14 -0
  42. package/src/extensions/FilePanel/FilePanelPlugin.ts +31 -22
  43. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +2 -4
  44. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +3 -0
  45. package/src/i18n/locales/index.ts +2 -0
  46. package/src/i18n/locales/ru.ts +2 -2
  47. package/src/i18n/locales/sk.ts +355 -0
  48. package/src/i18n/locales/zh-tw.ts +390 -0
  49. package/src/pm-nodes/BlockContainer.ts +7 -6
  50. package/src/schema/blocks/createSpec.ts +1 -1
  51. package/src/schema/blocks/internal.ts +0 -1
  52. package/src/schema/blocks/types.ts +2 -1
  53. package/types/src/api/blockManipulation/setupTestEnv.d.ts +8 -4
  54. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +8 -4
  55. package/types/src/blocks/ListItemBlockContent/getListItemContent.d.ts +28 -0
  56. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +8 -4
  57. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -0
  58. package/types/src/blocks/defaultBlocks.d.ts +16 -8
  59. package/types/src/editor/BlockNoteEditor.d.ts +18 -1
  60. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +31 -0
  61. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +7 -0
  62. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +6 -0
  63. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +1 -1
  64. package/types/src/i18n/locales/index.d.ts +2 -0
  65. package/types/src/i18n/locales/sk.d.ts +313 -0
  66. package/types/src/i18n/locales/zh-tw.d.ts +2 -0
  67. package/types/src/schema/blocks/types.d.ts +2 -1
  68. package/src/extensions/Collaboration/createCollaborationExtensions.ts +0 -147
  69. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +0 -17
@@ -1,13 +1,13 @@
1
- "use strict";var jo=Object.create;var Xe=Object.defineProperty;var Go=Object.getOwnPropertyDescriptor;var Xo=Object.getOwnPropertyNames;var Jo=Object.getPrototypeOf,Yo=Object.prototype.hasOwnProperty;var Zo=(e,n,t)=>n in e?Xe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Qo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Xo(n))!Yo.call(e,r)&&r!==t&&Xe(e,r,{get:()=>n[r],enumerable:!(o=Go(n,r))||o.enumerable});return e};var F=(e,n,t)=>(t=e!=null?jo(Jo(e)):{},Qo(n||!e||!e.__esModule?Xe(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>Zo(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("prosemirror-model"),de=require("prosemirror-transform"),k=require("@tiptap/core"),w=require("prosemirror-state"),Xt=require("uuid"),er=require("prosemirror-highlight"),tr=require("prosemirror-highlight/shiki"),P=require("prosemirror-tables"),nr=require("@tiptap/extension-bold"),or=require("@tiptap/extension-code"),rr=require("@tiptap/extension-italic"),sr=require("@tiptap/extension-strike"),ir=require("@tiptap/extension-underline"),ar=require("@tiptap/extension-table-cell"),lr=require("@tiptap/extension-table-header"),cr=require("@tiptap/extension-table-row"),dr=require("@tiptap/extension-gapcursor"),ur=require("@tiptap/extension-history"),pr=require("@tiptap/extension-link"),hr=require("@tiptap/extension-text"),fr=require("@tiptap/extension-collaboration"),mr=require("@tiptap/extension-collaboration-cursor"),x=require("prosemirror-view"),oe=require("y-prosemirror"),gr=require("prosemirror-dropcursor"),br=require("./en-D4taoCs4.cjs"),ie=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},kr=ie(nr),wr=ie(or),yr=ie(rr),Cr=ie(sr),vr=ie(ir),Sr=ie(fr),Br=ie(mr);class U extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Er(e,n=!0){const{"data-test":t,...o}=e;if(Object.keys(o).length>0&&n)throw new Error("Object must be empty "+JSON.stringify(e))}function K(e,n){const t=e.resolve(n);if(t.nodeAfter&&t.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:t.pos,node:t.nodeAfter};let o=t.depth,r=t.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:t.before(o),node:r};o--,r=t.node(o)}const s=[];e.descendants((a,l)=>{a.type.isInGroup("bnBlock")&&s.push(l)}),console.warn(`Position ${n} is not within a blockContainer node.`);const i=e.resolve(s.find(a=>a>=n)||s[s.length-1]);return{posBeforeNode:i.pos,node:i.nodeAfter}}function Ue(e,n){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type}`);const t=e,o=n,r=o+t.nodeSize,s={node:t,beforePos:o,afterPos:r};if(t.type.name==="blockContainer"){let i,a;if(t.forEach((l,c)=>{if(l.type.spec.group==="blockContent"){const d=l,u=o+c+1,h=u+l.nodeSize;i={node:d,beforePos:u,afterPos:h}}else if(l.type.name==="blockGroup"){const d=l,u=o+c+1,h=u+l.nodeSize;a={node:d,beforePos:u,afterPos:h}}}),!i)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${t}`);return{isBlockContainer:!0,bnBlock:s,blockContent:i,childContainer:a,blockNoteType:i.node.type.name}}else{if(!s.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${s.node}`);return{isBlockContainer:!1,bnBlock:s,childContainer:s,blockNoteType:s.node.type.name}}}function X(e){return Ue(e.node,e.posBeforeNode)}function he(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return Ue(e.nodeAfter,e.pos)}function B(e){const n=K(e.doc,e.selection.anchor);return X(n)}function Ce(e){const n=K(e.doc,e.selection.anchor);return X(n)}function Tr(e,n=JSON.stringify){const t={};return e.filter(o=>{const r=n(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function xr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return Tr(n)}const ve=k.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return e.mockID===void 0?e.mockID=0:e.mockID++,e.mockID.toString()}return Xt.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const n={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...n,id:e[this.options.attributeName]}:n}}}}]},addProseMirrorPlugins(){let e=null,n=!1;return[new w.Plugin({key:new w.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const s=t.some(m=>m.docChanged)&&!o.doc.eq(r.doc),i=this.options.filterTransaction&&t.some(m=>{let g,b;return!(!((b=(g=this.options).filterTransaction)===null||b===void 0)&&b.call(g,m))});if(!s||i)return;const{tr:a}=r,{types:l,attributeName:c,generateID:d}=this.options,u=k.combineTransactionSteps(o.doc,t),{mapping:h}=u;if(k.getChangedRanges(u).forEach(({newRange:m})=>{const g=k.findChildrenInRange(r.doc,m,C=>l.includes(C.type.name)),b=g.map(({node:C})=>C.attrs[c]).filter(C=>C!==null),y=xr(b);g.forEach(({node:C,pos:v})=>{let L;const q=(L=a.doc.nodeAt(v))===null||L===void 0?void 0:L.attrs[c];if(q===null){const S=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(S)===null){const ae=JSON.parse(JSON.stringify(r.doc.toJSON()));if(ae.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(ae.content)===JSON.stringify(S.toJSON())){a.setNodeMarkup(v,void 0,{...C.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(v,void 0,{...C.attrs,[c]:d()});return}const{deleted:j}=h.invert().mapResult(v);j&&y.includes(q)&&a.setNodeMarkup(v,void 0,{...C.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let r;return e!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?n=!0:n=!1,e=null,!1},paste:()=>(n=!0,!1)},transformPasted:t=>{if(!n)return t;const{types:o,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(s(l.content)));return}const c=l.type.create({...l.attrs,[r]:null},s(l.content),l.marks);a.push(c)}),E.Fragment.from(a)};return n=!1,new E.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function Ze(e){return e.type==="link"}function dt(e){return typeof e!="string"&&e.type==="link"}function ee(e){return typeof e!="string"&&e.type==="text"}function De(e){var n,t,o,r,s;return $e(e)?{...e}:ue(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:((n=e.props)==null?void 0:n.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((o=e.props)==null?void 0:o.textAlignment)??"left",colspan:((r=e.props)==null?void 0:r.colspan)??1,rowspan:((s=e.props)==null?void 0:s.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function ue(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function $e(e){return ue(e)&&e.props!==void 0&&e.content!==void 0}function pe(e){return $e(e)?e.props.colspan??1:1}function Oe(e){return $e(e)?e.props.rowspan??1:1}const Jt=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function G(e,n="Ctrl"){return Jt()?e.replace("Mod","⌘"):e.replace("Mod",n)}function J(...e){return e.filter(n=>n).join(" ")}const Mr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function z(e,n,t,o){const r=document.createElement("div");r.className=J("bn-block-content",t.class),r.setAttribute("data-content-type",e);for(const[i,a]of Object.entries(t))i!=="class"&&r.setAttribute(i,a);const s=document.createElement(n);s.className=J("bn-inline-content",o.class);for(const[i,a]of Object.entries(o))i!=="class"&&s.setAttribute(i,a);return r.appendChild(s),{dom:r,contentDOM:s}}const Qe=(e,n)=>{let t=ne(e,n.pmSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const o=n.pmSchema.nodes[t.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=o(t);if(typeof r!="object"||!("dom"in r))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return r},M={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},ut=["backgroundColor","textColor"];function we(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Pr(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function fe(e){const n={};return Object.entries(e).filter(([t,o])=>!ut.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(we(t));if(s===null)return null;if(o.default===void 0&&o.type==="boolean"||o.default!==void 0&&typeof o.default=="boolean")return s==="true"?!0:s==="false"?!1:null;if(o.default===void 0&&o.type==="number"||o.default!==void 0&&typeof o.default=="number"){const i=parseFloat(s);return!Number.isNaN(i)&&Number.isFinite(i)?i:null}return s},renderHTML:r=>r[t]!==o.default?{[we(t)]:r[t]}:{}}}),n}function Yt(e,n,t,o){if(typeof e=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=t.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const a=n.getBlock(i);if(a.type!==o)throw new Error("Block type does not match");return a}function ke(e,n,t,o,r=!1,s){const i=document.createElement("div");if(s!==void 0)for(const[a,l]of Object.entries(s))a!=="class"&&i.setAttribute(a,l);i.className=J("bn-block-content",(s==null?void 0:s.class)||""),i.setAttribute("data-content-type",n);for(const[a,l]of Object.entries(t)){const d=o[a].default;!ut.includes(a)&&l!==d&&i.setAttribute(we(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=J("bn-inline-content",e.contentDOM.className),e.contentDOM.setAttribute("data-editable","")),{...e,dom:i}}function W(e){return k.Node.create(e)}function pt(e,n){return{config:e,implementation:n}}function Y(e,n,t){return pt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:Qe,toExternalHTML:Qe})}function ht(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Zt(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function Qt(e,n){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:"[data-editable]"}];return n&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=n==null?void 0:n(o);return r===void 0?!1:r}}),t}function me(e,n){const t=W({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return fe(e.propSchema)},parseHTML(){return Qt(e,n.parse)},renderHTML({HTMLAttributes:o}){const r=document.createElement("div");return ke({dom:r,contentDOM:e.content==="inline"?r:void 0},e.type,{},e.propSchema,e.isFileBlock,o)},addNodeView(){return({getPos:o})=>{var c;const r=this.options.editor,s=Yt(o,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=n.render(s,r),l=ke(a,s.type,s.props,e.propSchema,i);return e.isSelectable===!1&&Zt(l,this.editor),l}}});if(t.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return pt(e,{node:t,toInternalHTML:(o,r)=>{var a;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},i=n.render(o,r);return ke(i,o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var a,l;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let i=(l=n.toExternalHTML)==null?void 0:l.call(n,o,r);return i===void 0&&(i=n.render(o,r)),ke(i,o.type,o.props,e.propSchema,s)}})}function N(e){return"doc"in e?e.doc.type.schema:e.type.schema}function en(e){return e.cached.blockNoteEditor}function Se(e){return en(e).schema}function Ir(e){return Se(e).blockSchema}function Lr(e){return Se(e).inlineContentSchema}function ze(e){return Se(e).styleSchema}function Ar(e){return en(e).blockCache}function ft(e,n,t){var s,i;const o={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},r=[];e.content.forEach((a,l,c)=>{const d={cells:[]};c===0&&a.content.forEach(u=>{let h=u.attrs.colwidth;h==null&&(h=new Array(u.attrs.colspan??1).fill(void 0)),o.columnWidths.push(...h)}),d.cells=a.content.content.map((u,h)=>(r[c]||(r[c]=[]),r[c][h]=u.type.name==="tableHeader",{type:"tableCell",content:u.content.content.map(m=>Be(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],y=g[0];return y&&ee(b)&&ee(y)&&JSON.stringify(b.styles)===JSON.stringify(y.styles)?(b.text+=`
2
- `+y.text,m.push(...g.slice(1)),m):(m.push(...g),m)},[]),props:{colspan:u.attrs.colspan,rowspan:u.attrs.rowspan,backgroundColor:u.attrs.backgroundColor,textColor:u.attrs.textColor,textAlignment:u.attrs.textAlignment}})),o.rows.push(d)});for(let a=0;a<r.length;a++)(s=r[a])!=null&&s.every(l=>l)&&(o.headerRows=(o.headerRows??0)+1);for(let a=0;a<((i=r[0])==null?void 0:i.length);a++)r!=null&&r.every(l=>l[a])&&(o.headerCols=(o.headerCols??0)+1);return o}function Be(e,n,t){const o=[];let r;return e.content.forEach(s=>{if(s.type.name==="hardBreak"){if(r)if(ee(r))r.text+=`
3
- `;else if(Ze(r))r.content[r.content.length-1].text+=`
1
+ "use strict";var Zo=Object.create;var Je=Object.defineProperty;var Qo=Object.getOwnPropertyDescriptor;var er=Object.getOwnPropertyNames;var tr=Object.getPrototypeOf,nr=Object.prototype.hasOwnProperty;var or=(e,n,t)=>n in e?Je(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var rr=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of er(n))!nr.call(e,r)&&r!==t&&Je(e,r,{get:()=>n[r],enumerable:!(o=Qo(n,r))||o.enumerable});return e};var $=(e,n,t)=>(t=e!=null?Zo(tr(e)):{},rr(n||!e||!e.__esModule?Je(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>or(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("prosemirror-model"),ce=require("prosemirror-transform"),k=require("@tiptap/core"),w=require("prosemirror-state"),en=require("uuid"),sr=require("prosemirror-highlight"),ir=require("prosemirror-highlight/shiki"),I=require("prosemirror-tables"),ar=require("@tiptap/extension-bold"),lr=require("@tiptap/extension-code"),cr=require("@tiptap/extension-italic"),dr=require("@tiptap/extension-strike"),ur=require("@tiptap/extension-underline"),pr=require("@tiptap/extension-table-cell"),hr=require("@tiptap/extension-table-header"),fr=require("@tiptap/extension-table-row"),mr=require("@tiptap/extension-gapcursor"),gr=require("@tiptap/extension-history"),br=require("@tiptap/extension-link"),kr=require("@tiptap/extension-text"),V=require("y-prosemirror"),M=require("prosemirror-view"),wr=require("prosemirror-dropcursor"),Dt=require("prosemirror-history"),yr=require("./en-D4taoCs4.cjs"),ye=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},Cr=ye(ar),vr=ye(lr),Sr=ye(cr),Br=ye(dr),Er=ye(ur);class z extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Tr(e,n=!0){const{"data-test":t,...o}=e;if(Object.keys(o).length>0&&n)throw new Error("Object must be empty "+JSON.stringify(e))}function G(e,n){const t=e.resolve(n);if(t.nodeAfter&&t.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:t.pos,node:t.nodeAfter};let o=t.depth,r=t.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:t.before(o),node:r};o--,r=t.node(o)}const s=[];e.descendants((a,l)=>{a.type.isInGroup("bnBlock")&&s.push(l)}),console.warn(`Position ${n} is not within a blockContainer node.`);const i=e.resolve(s.find(a=>a>=n)||s[s.length-1]);return{posBeforeNode:i.pos,node:i.nodeAfter}}function $e(e,n){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type}`);const t=e,o=n,r=o+t.nodeSize,s={node:t,beforePos:o,afterPos:r};if(t.type.name==="blockContainer"){let i,a;if(t.forEach((l,c)=>{if(l.type.spec.group==="blockContent"){const d=l,u=o+c+1,h=u+l.nodeSize;i={node:d,beforePos:u,afterPos:h}}else if(l.type.name==="blockGroup"){const d=l,u=o+c+1,h=u+l.nodeSize;a={node:d,beforePos:u,afterPos:h}}}),!i)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${t}`);return{isBlockContainer:!0,bnBlock:s,blockContent:i,childContainer:a,blockNoteType:i.node.type.name}}else{if(!s.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${s.node}`);return{isBlockContainer:!1,bnBlock:s,childContainer:s,blockNoteType:s.node.type.name}}}function J(e){return $e(e.node,e.posBeforeNode)}function pe(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return $e(e.nodeAfter,e.pos)}function E(e){const n=G(e.doc,e.selection.anchor);return J(n)}function Ce(e){const n=G(e.doc,e.selection.anchor);return J(n)}function xr(e,n=JSON.stringify){const t={};return e.filter(o=>{const r=n(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Mr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return xr(n)}const ve=k.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return e.mockID===void 0?e.mockID=0:e.mockID++,e.mockID.toString()}return en.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const n={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...n,id:e[this.options.attributeName]}:n}}}}]},addProseMirrorPlugins(){let e=null,n=!1;return[new w.Plugin({key:new w.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const s=t.some(m=>m.docChanged)&&!o.doc.eq(r.doc),i=this.options.filterTransaction&&t.some(m=>{let g,b;return!(!((b=(g=this.options).filterTransaction)===null||b===void 0)&&b.call(g,m))});if(!s||i)return;const{tr:a}=r,{types:l,attributeName:c,generateID:d}=this.options,u=k.combineTransactionSteps(o.doc,t),{mapping:h}=u;if(k.getChangedRanges(u).forEach(({newRange:m})=>{const g=k.findChildrenInRange(r.doc,m,C=>l.includes(C.type.name)),b=g.map(({node:C})=>C.attrs[c]).filter(C=>C!==null),y=Mr(b);g.forEach(({node:C,pos:v})=>{let L;const j=(L=a.doc.nodeAt(v))===null||L===void 0?void 0:L.attrs[c];if(j===null){const S=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(S)===null){const ie=JSON.parse(JSON.stringify(r.doc.toJSON()));if(ie.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(ie.content)===JSON.stringify(S.toJSON())){a.setNodeMarkup(v,void 0,{...C.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(v,void 0,{...C.attrs,[c]:d()});return}const{deleted:F}=h.invert().mapResult(v);F&&y.includes(j)&&a.setNodeMarkup(v,void 0,{...C.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let r;return e!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?n=!0:n=!1,e=null,!1},paste:()=>(n=!0,!1)},transformPasted:t=>{if(!n)return t;const{types:o,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(s(l.content)));return}const c=l.type.create({...l.attrs,[r]:null},s(l.content),l.marks);a.push(c)}),B.Fragment.from(a)};return n=!1,new B.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function et(e){return e.type==="link"}function ht(e){return typeof e!="string"&&e.type==="link"}function te(e){return typeof e!="string"&&e.type==="text"}function De(e){var n,t,o,r,s;return ze(e)?{...e}:de(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:((n=e.props)==null?void 0:n.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((o=e.props)==null?void 0:o.textAlignment)??"left",colspan:((r=e.props)==null?void 0:r.colspan)??1,rowspan:((s=e.props)==null?void 0:s.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function de(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function ze(e){return de(e)&&e.props!==void 0&&e.content!==void 0}function ue(e){return ze(e)?e.props.colspan??1:1}function Oe(e){return ze(e)?e.props.rowspan??1:1}const tn=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function X(e,n="Ctrl"){return tn()?e.replace("Mod","⌘"):e.replace("Mod",n)}function Y(...e){return e.filter(n=>n).join(" ")}const Pr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function q(e,n,t,o){const r=document.createElement("div");r.className=Y("bn-block-content",t.class),r.setAttribute("data-content-type",e);for(const[i,a]of Object.entries(t))i!=="class"&&r.setAttribute(i,a);const s=document.createElement(n);s.className=Y("bn-inline-content",o.class);for(const[i,a]of Object.entries(o))i!=="class"&&s.setAttribute(i,a);return r.appendChild(s),{dom:r,contentDOM:s}}const tt=(e,n)=>{let t=oe(e,n.pmSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const o=n.pmSchema.nodes[t.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=o(t);if(typeof r!="object"||!("dom"in r))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return r};function Ir(e){const n=e.querySelectorAll("p");if(n.length>1){const t=n[0];for(let o=1;o<n.length;o++){const r=n[o];t.innerHTML+="<br>"+r.innerHTML,r.remove()}}}const P={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},ft=["backgroundColor","textColor"];function ke(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Lr(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function he(e){const n={};return Object.entries(e).filter(([t,o])=>!ft.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(ke(t));if(s===null)return null;if(o.default===void 0&&o.type==="boolean"||o.default!==void 0&&typeof o.default=="boolean")return s==="true"?!0:s==="false"?!1:null;if(o.default===void 0&&o.type==="number"||o.default!==void 0&&typeof o.default=="number"){const i=parseFloat(s);return!Number.isNaN(i)&&Number.isFinite(i)?i:null}return s},renderHTML:r=>r[t]!==o.default?{[ke(t)]:r[t]}:{}}}),n}function nn(e,n,t,o){if(typeof e=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=t.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const a=n.getBlock(i);if(a.type!==o)throw new Error("Block type does not match");return a}function be(e,n,t,o,r=!1,s){const i=document.createElement("div");if(s!==void 0)for(const[a,l]of Object.entries(s))a!=="class"&&i.setAttribute(a,l);i.className=Y("bn-block-content",(s==null?void 0:s.class)||""),i.setAttribute("data-content-type",n);for(const[a,l]of Object.entries(t)){const d=o[a].default;!ft.includes(a)&&l!==d&&i.setAttribute(ke(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=Y("bn-inline-content",e.contentDOM.className)),{...e,dom:i}}function K(e){return k.Node.create(e)}function mt(e,n){return{config:e,implementation:n}}function Z(e,n,t){return mt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:tt,toExternalHTML:tt})}function gt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function on(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function rn(e,n){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return n&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=n==null?void 0:n(o);return r===void 0?!1:r}}),t}function fe(e,n){const t=K({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return he(e.propSchema)},parseHTML(){return rn(e,n.parse)},renderHTML({HTMLAttributes:o}){const r=document.createElement("div");return be({dom:r,contentDOM:e.content==="inline"?r:void 0},e.type,{},e.propSchema,e.isFileBlock,o)},addNodeView(){return({getPos:o})=>{var c;const r=this.options.editor,s=nn(o,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=n.render(s,r),l=be(a,s.type,s.props,e.propSchema,i);return e.isSelectable===!1&&on(l,this.editor),l}}});if(t.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return mt(e,{node:t,toInternalHTML:(o,r)=>{var a;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},i=n.render(o,r);return be(i,o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var a,l;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let i=(l=n.toExternalHTML)==null?void 0:l.call(n,o,r);return i===void 0&&(i=n.render(o,r)),be(i,o.type,o.props,e.propSchema,s)}})}function N(e){return"doc"in e?e.doc.type.schema:e.type.schema}function sn(e){return e.cached.blockNoteEditor}function Se(e){return sn(e).schema}function Ar(e){return Se(e).blockSchema}function Nr(e){return Se(e).inlineContentSchema}function We(e){return Se(e).styleSchema}function Hr(e){return sn(e).blockCache}function bt(e,n,t){var s,i;const o={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},r=[];e.content.forEach((a,l,c)=>{const d={cells:[]};c===0&&a.content.forEach(u=>{let h=u.attrs.colwidth;h==null&&(h=new Array(u.attrs.colspan??1).fill(void 0)),o.columnWidths.push(...h)}),d.cells=a.content.content.map((u,h)=>(r[c]||(r[c]=[]),r[c][h]=u.type.name==="tableHeader",{type:"tableCell",content:u.content.content.map(m=>Be(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],y=g[0];return y&&te(b)&&te(y)&&JSON.stringify(b.styles)===JSON.stringify(y.styles)?(b.text+=`
2
+ `+y.text,m.push(...g.slice(1)),m):(m.push(...g),m)},[]),props:{colspan:u.attrs.colspan,rowspan:u.attrs.rowspan,backgroundColor:u.attrs.backgroundColor,textColor:u.attrs.textColor,textAlignment:u.attrs.textAlignment}})),o.rows.push(d)});for(let a=0;a<r.length;a++)(s=r[a])!=null&&s.every(l=>l)&&(o.headerRows=(o.headerRows??0)+1);for(let a=0;a<((i=r[0])==null?void 0:i.length);a++)r!=null&&r.every(l=>l[a])&&(o.headerCols=(o.headerCols??0)+1);return o}function Be(e,n,t){const o=[];let r;return e.content.forEach(s=>{if(s.type.name==="hardBreak"){if(r)if(te(r))r.text+=`
3
+ `;else if(et(r))r.content[r.content.length-1].text+=`
4
4
  `;else throw new Error("unexpected");else r={type:"text",text:`
5
- `,styles:{}};return}if(s.type.name!=="link"&&s.type.name!=="text"){if(!n[s.type.name]){console.warn("unrecognized inline content type",s.type.name);return}r&&(o.push(r),r=void 0),o.push(Re(s,n,t));return}const i={};let a;for(const l of s.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c){if(l.type.spec.blocknoteIgnore)continue;throw new Error(`style ${l.type.name} not found in styleSchema`)}if(c.propSchema==="boolean")i[c.type]=!0;else if(c.propSchema==="string")i[c.type]=l.attrs.stringValue;else throw new U(c.propSchema)}r?ee(r)?a?(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=s.textContent:(o.push(r),r={type:"text",text:s.textContent,styles:i}):Ze(r)&&(a?r.href===a.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=s.textContent:r.content.push({type:"text",text:s.textContent,styles:i}):(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):(o.push(r),r={type:"text",text:s.textContent,styles:i})):a?r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}:r={type:"text",text:s.textContent,styles:i}}),r&&o.push(r),o}function Re(e,n,t){if(e.type.name==="text"||e.type.name==="link")throw new Error("unexpected");const o={},r=n[e.type.name];for(const[a,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);const c=r.propSchema;a in c&&(o[a]=l)}let s;return r.content==="styled"?s=Be(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function T(e,n,t=Ir(n),o=Lr(n),r=ze(n),s=Ar(n)){var g;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const i=s==null?void 0:s.get(e);if(i)return i;const a=Ue(e,0);let l=a.bnBlock.node.attrs.id;l===null&&(l=ve.options.generateID());const c=t[a.blockNoteType];if(!c)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const d={};for(const[b,y]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const C=c.propSchema;b in C&&!(C[b].default===void 0&&y===void 0)&&(d[b]=y)}const u=t[a.blockNoteType],h=[];(g=a.childContainer)==null||g.node.forEach(b=>{h.push(T(b,n,t,o,r,s))});let f;if(u.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");f=Be(a.blockContent.node,o,r)}else if(u.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");f=ft(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new U(u.content);const m={id:l,type:u.type,props:d,content:f,children:h};return s==null||s.set(e,m),m}function et(e,n,t,o){return e.dom.setAttribute("data-inline-content-type",n),Object.entries(t).filter(([r,s])=>{const i=o[r];return s!==i.default}).map(([r,s])=>[we(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function tn(e){return{Backspace:({editor:n})=>{const t=n.state.selection.$from;return n.state.selection.empty&&t.node().type.name===e.type&&t.parentOffset===0}}}function nn(e,n){return{config:e,implementation:n}}function on(e,n){return nn({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function mt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function rn(e){return[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Nr(e,n){const t=k.Node.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",content:e.content==="styled"?"inline*":"",addAttributes(){return fe(e.propSchema)},addKeyboardShortcuts(){return tn(e)},parseHTML(){return rn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render(Re(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return et(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render(Re(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=V([a],s.pmSchema);s.dispatch(s.prosemirrorView.state.tr.replaceWith(r(),r()+o.nodeSize,l))},s);return et(i,e.type,o.attrs,e.propSchema)}}});return on(t,e.propSchema)}function sn(e){return e==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:n=>n.getAttribute("data-value"),renderHTML:n=>n.stringValue!==void 0?{"data-value":n.stringValue}:{}}}}function an(e,n,t,o){return e.dom.setAttribute("data-style-type",n),o==="string"&&e.dom.setAttribute("data-value",t),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function gt(e,n){return{config:e,implementation:n}}function Q(e,n){return gt({type:e.name,propSchema:n},{mark:e})}function bt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function ln(e){return[{tag:`[data-style-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Hr(e,n){const t=k.Mark.create({name:e.type,addAttributes(){return sn(e.propSchema)},parseHTML(){return ln(e)},renderHTML({mark:o}){let r;if(e.propSchema==="boolean")r=n.render();else if(e.propSchema==="string")r=n.render(o.attrs.stringValue);else throw new U(e.propSchema);return an(r,e.type,o.attrs.stringValue,e.propSchema)}});return gt(e,{mark:t})}function te(e){const{height:n,width:t}=kt(e),o=new Array(n).fill(!1).map(()=>new Array(t).fill(null)),r=(s,i)=>{for(let a=s;a<n;a++)for(let l=i;l<t;l++)if(!o[a][l])return{row:a,col:l};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let s=0;s<e.content.rows.length;s++)for(let i=0;i<e.content.rows[s].cells.length;i++){const a=De(e.content.rows[s].cells[i]),l=Oe(a),c=pe(a),{row:d,col:u}=r(s,i);for(let h=d;h<d+l;h++)for(let f=u;f<u+c;f++){if(o[h][f])throw new Error(`Unable to create occupancy grid for table, cell at ${h},${f} is already occupied`);o[h][f]={row:s,col:i,rowspan:l,colspan:c,cell:a}}}return o}function ye(e){const n=new Set;return e.map(t=>({cells:t.map(o=>n.has(o.row+":"+o.col)?!1:(n.add(o.row+":"+o.col),o.cell)).filter(o=>o!==!1)}))}function se(e,n,t=te(n)){for(let o=0;o<t.length;o++)for(let r=0;r<t[o].length;r++){const s=t[o][r];if(s.row===e.row&&s.col===e.col)return{row:o,col:r,cell:s.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function kt(e){const n=e.content.rows.length;let t=0;return e.content.rows.forEach(o=>{let r=0;o.cells.forEach(s=>{r+=pe(s)}),t=Math.max(t,r)}),{height:n,width:t}}function cn(e,n,t=te(n)){var r;const o=(r=t[e.row])==null?void 0:r[e.col];if(o)return{row:o.row,col:o.col,cell:o.cell}}function tt(e,n){var s;const t=te(e);if(n<0||n>=t.length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[o])==null?void 0:s[0];if(!a)return[];o+=a.rowspan}const r=new Array(t[0].length).fill(!1).map((i,a)=>cn({row:o,col:a},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function nt(e,n){var s;const t=te(e);if(n<0||n>=t[0].length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[0])==null?void 0:s[o];if(!a)return[];o+=a.colspan}const r=new Array(t.length).fill(!1).map((i,a)=>cn({row:a,col:o},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function Dr(e,n,t,o=te(e)){const{col:r}=se({row:0,col:n},e,o),{col:s}=se({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),ye(o)}function Or(e,n,t,o=te(e)){const{row:r}=se({row:n,col:0},e,o),{row:s}=se({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),ye(o)}function ot(e){return e?ue(e)?ot(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:ee(n)?n.text.length===0:dt(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function Rr(e,n,t=te(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>ot(l[i].cell)&&l[i].colspan===1);i--)s++;for(let i=t.length-1;i>=0;i--){const a=Math.max(t[i].length-s,1);t[i]=t[i].slice(0,a)}return ye(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>ot(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),ye(t)}function _r(e,n,t,o=te(e)){const{width:r,height:s}=kt(e);if(n==="columns")o.forEach((i,a)=>{if(t>=0)for(let l=0;l<t;l++)i.push({row:a,col:Math.max(...i.map(c=>c.col))+1,rowspan:1,colspan:1,cell:De("")});else i.splice(r+t,-1*t)});else if(t>0)for(let i=0;i<t;i++){const a=new Array(r).fill(null).map((l,c)=>({row:s+i,col:c,rowspan:1,colspan:1,cell:De("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return ye(o)}function dn(e,n,t){const o=tt(e,t);if(!o.some(l=>Oe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=Oe(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function un(e,n,t){const o=nt(e,t);if(!o.some(l=>pe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=pe(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function Vr(e,n,t){const o=se(e,t),r=se(n,t);return o.col===r.col}function Lt(e,n,t,o){const r=[];for(const[i,a]of Object.entries(e.styles)){const l=t[i];if(!l)throw new Error(`style ${i} not found in styleSchema`);if(l.propSchema==="boolean")r.push(n.mark(i));else if(l.propSchema==="string")r.push(n.mark(i,{stringValue:a}));else throw new U(l.propSchema)}return!o||!n.nodes[o].spec.code?e.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
6
- `?n.nodes.hardBreak.createChecked():n.text(i,r)):[n.text(e.text,r)]}function Fr(e,n,t){const o=n.marks.link.create({href:e.href});return rt(e.content,n,t).map(r=>{if(r.type.name==="text")return r.mark([...r.marks,o]);if(r.type.name==="hardBreak")return r;throw new Error("unexpected node type")})}function rt(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Lt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Lt(s,n,t,o));return r}function V(e,n,t,o=ze(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...rt(s,n,o,t)):dt(s)?r.push(...Fr(s,n,o)):ee(s)?r.push(...rt([s],n,o,t)):r.push(pn(s,n,o));return r}function Ee(e,n,t=ze(n)){const o=[],r=new Array(e.headerRows??0).fill(!0),s=new Array(e.headerCols??0).fill(!0),i=e.columnWidths??[];for(let a=0;a<e.rows.length;a++){const l=e.rows[a],c=[],d=r[a];for(let h=0;h<l.cells.length;h++){const f=l.cells[h],m=s[h],g=void 0;let b=null;const y=se({row:a,col:h},{content:e});let C=i[y.col]?[i[y.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(ue(f)){f.content&&(b=V(f.content,n,"tableParagraph",t));const L=pe(f);L>1&&(C=new Array(L).fill(!1).map((q,j)=>i[y.col+j]??void 0))}else b=V(f,n,"tableParagraph",t);const v=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...ue(f)?f.props:{},colwidth:C},n.nodes.tableParagraph.createChecked(g,b));c.push(v)}const u=n.nodes.tableRow.createChecked({},c);o.push(u)}return o}function pn(e,n,t){let o,r=e.type;if(r===void 0&&(r="paragraph"),!n.nodes[r])throw new Error(`node type ${r} not found in schema`);if(!e.content)o=n.nodes[r].createChecked(e.props);else if(typeof e.content=="string"){const s=V([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=V(e.content,n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Ee(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new U(e.content.type);return o}function ne(e,n,t=ze(n)){let o=e.id;o===void 0&&(o=ve.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(ne(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=pn(e,n,t),a=r.length>0?n.nodes.blockGroup.createChecked({},r):void 0;return n.nodes.blockContainer.createChecked({id:o,...e.props},a?[i,a]:i)}else{if(n.nodes[e.type].isInGroup("bnBlock"))return n.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}}function _(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!_e(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function _e(e){return e.type.isInGroup("bnBlock")}function Ur(e,n){return e.id!==n.id||e.type!==n.type||JSON.stringify(e.props)!==JSON.stringify(n.props)||JSON.stringify(e.content)!==JSON.stringify(n.content)}function hn(e,n=[]){let t={type:"local"};e.getMeta("paste")?t={type:"paste"}:e.getMeta("uiEvent")==="drop"?t={type:"drop"}:e.getMeta("history$")?t={type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")&&(e.getMeta("y-sync$").isUndoRedoOperation?t={type:"undo-redo"}:t={type:"yjs-remote"});const o=N(e),r=k.combineTransactionSteps(e.before,[e,...n]),s=k.getChangedRanges(r),i=s.flatMap(u=>k.findChildrenInRange(r.before,u.oldRange,_e)).map(({node:u})=>T(u,o)),a=s.flatMap(u=>k.findChildrenInRange(r.doc,u.newRange,_e)).map(({node:u})=>T(u,o)),l=new Map(a.map(u=>[u.id,u])),c=new Map(i.map(u=>[u.id,u])),d=[];for(const[u,h]of l)c.has(u)||d.push({type:"insert",block:h,source:t,prevBlock:void 0});for(const[u,h]of c)l.has(u)||d.push({type:"delete",block:h,source:t,prevBlock:void 0});for(const[u,h]of l)if(c.has(u)){const f=c.get(u);Ur(f,h)&&d.push({type:"update",block:h,prevBlock:f,source:t})}return d}const A=(e,n)=>({tr:t,dispatch:o})=>(o&&fn(t,e,n),!0),fn=(e,n,t)=>{const o=he(e.doc.resolve(n)),r=N(e),s=r.nodes[o.blockNoteType],i=r.nodes[t.type||o.blockNoteType],a=i.isInGroup("bnBlock")?i:r.nodes.blockContainer;if(o.isBlockContainer&&i.isInGroup("blockContent"))At(t,e,o),$r(t,e,s,i,o);else if(!o.isBlockContainer&&i.isInGroup("bnBlock"))At(t,e,o);else{const l=T(o.bnBlock.node,r);e.replaceWith(o.bnBlock.beforePos,o.bnBlock.afterPos,ne({children:l.children,...t},r));return}e.setNodeMarkup(o.bnBlock.beforePos,a,{...o.bnBlock.node.attrs,...t.props})};function $r(e,n,t,o,r){const s=N(n);let i="keep";if(e.content)if(typeof e.content=="string")i=V([e.content],s,o.name);else if(Array.isArray(e.content))i=V(e.content,s,o.name);else if(e.content.type==="tableContent")i=Ee(e.content,s);else throw new U(e.content.type);else t.spec.content===""||o.spec.content!==t.spec.content&&(i=[]);i==="keep"?n.setNodeMarkup(r.blockContent.beforePos,e.type===void 0?void 0:s.nodes[e.type],{...r.blockContent.node.attrs,...e.props}):n.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},i))}function At(e,n,t){const o=N(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>ne(s,o));if(t.childContainer)n.step(new de.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new E.Slice(E.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function mn(e,n,t){const o=typeof n=="string"?n:n.id,r=_(o,e.doc);if(!r)throw new Error(`Block with ID ${o} not found`);fn(e,r.posBeforeNode,t);const s=e.doc.resolve(r.posBeforeNode+1).node(),i=N(e);return T(s,i)}function gn(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function bn(e,n,t,o){let r;if(n)if(typeof n=="string")r=V([n],e.pmSchema);else if(Array.isArray(n))r=V(n,e.pmSchema);else if(n.type==="tableContent")r=Ee(n,e.pmSchema);else throw new U(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(E.Fragment.from(r),o);return s.nodeType===1&&gn(s),s}function zr(e,n,t,o,r,s,i){var g,b,y,C,v,L,q,j;const a=(i==null?void 0:i.document)??document,l=n.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[I,S]of Object.entries(n.schema.blockSchema[t.type].propSchema))S.default!==void 0&&(c[I]=S.default)}const d=(b=(g=l.spec)==null?void 0:g.toDOM)==null?void 0:b.call(g,l.create({id:t.id,...c})),u=Array.from(d.dom.attributes),h=n.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},n),f=a.createDocumentFragment();if(h.dom.classList.contains("bn-block-content")){const I=[...u,...Array.from(h.dom.attributes)].filter(S=>S.name.startsWith("data")&&S.name!=="data-content-type"&&S.name!=="data-file-block"&&S.name!=="data-node-view-wrapper"&&S.name!=="data-node-type"&&S.name!=="data-id"&&S.name!=="data-index"&&S.name!=="data-editable");for(const S of I)h.dom.firstChild.setAttribute(S.name,S.value);gn(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const I=bn(n,t.content,o,i);h.contentDOM.appendChild(I)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((y=e.lastChild)==null?void 0:y.nodeName)!==m){const S=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&S.setAttribute("start",c.start+""),e.append(S)}const I=a.createElement("li");I.append(f),e.lastChild.appendChild(I)}else e.append(f);if(t.children&&t.children.length>0){const I=a.createDocumentFragment();if(kn(I,n,t.children,o,r,s,i),((C=e.lastChild)==null?void 0:C.nodeName)==="UL"||((v=e.lastChild)==null?void 0:v.nodeName)==="OL")for(;((L=I.firstChild)==null?void 0:L.nodeName)==="UL"||((q=I.firstChild)==null?void 0:q.nodeName)==="OL";)e.lastChild.lastChild.appendChild(I.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(I):(j=h.contentDOM)==null||j.append(I)}}const kn=(e,n,t,o,r,s,i)=>{for(const a of t)zr(e,n,a,o,r,s,i)},Wr=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return kn(a,e,n,t,o,r,s),a},Te=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=Wr(n,o,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=bn(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function qr(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=V([n],e.pmSchema,o);else if(Array.isArray(n))s=V(n,e.pmSchema,o);else if(n.type==="tableContent")s=Ee(n,e.pmSchema);else throw new U(n.type);else throw new Error("blockContent is required");return t.serializeFragment(E.Fragment.from(s),r)}function Kr(e,n,t,o,r){var u,h,f,m,g;const s=e.pmSchema.nodes.blockContainer;let i=n.props;if(!n.props){i={};for(const[b,y]of Object.entries(e.schema.blockSchema[n.type].propSchema))y.default!==void 0&&(i[b]=y.default)}const l=e.blockImplementations[n.type].implementation.toInternalHTML({...n,props:i},e);if(n.type==="numberedListItem"&&l.dom.setAttribute("data-index",o.toString()),l.contentDOM&&n.content){const b=qr(e,n.content,t,n.type,r);l.contentDOM.appendChild(b)}if(e.pmSchema.nodes[n.type].isInGroup("bnBlock")){if(n.children&&n.children.length>0){const b=wn(e,n.children,t,r);(u=l.contentDOM)==null||u.append(b)}return l.dom}const d=(f=(h=s.spec)==null?void 0:h.toDOM)==null?void 0:f.call(h,s.create({id:n.id,...i}));return(m=d.contentDOM)==null||m.appendChild(l.dom),n.children&&n.children.length>0&&((g=d.contentDOM)==null||g.appendChild(yn(e,n.children,t,r))),d.dom}function wn(e,n,t,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();let i=0;for(const a of n){a.type==="numberedListItem"?i++:i=0;const l=Kr(e,a,t,i,o);s.appendChild(l)}return s}const yn=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=wn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},Cn=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>yn(n,o,t,r).outerHTML}},xe=(e,n)=>{const t=e.querySelector(n);if(!t)return;const o=e.querySelector("figcaption"),r=(o==null?void 0:o.textContent)??void 0;return{targetElement:t,caption:r}},vn=(e,n,t,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",o?s.appendChild(o):s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(s);const i=document.createElement("p");i.className="bn-add-file-button-text",i.innerHTML=t||n.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{n.transact(c=>c.setMeta(n.filePanel.plugin,{block:e}))};return r.addEventListener("mousedown",a,!0),r.addEventListener("click",l,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",a,!0),r.removeEventListener("click",l,!0)}}},Sn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',Bn=e=>{const n=document.createElement("div");n.className="bn-file-name-with-icon";const t=document.createElement("div");t.className="bn-file-icon",t.innerHTML=Sn,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},We=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=vn(e,n,o,r);s.appendChild(a.dom);const l=n.onUploadStart(c=>{if(c===e.id){s.removeChild(a.dom);const d=document.createElement("div");d.className="bn-file-loading-preview",d.textContent="Loading...",s.appendChild(d)}});return{dom:s,destroy:()=>{l(),a.destroy()}}}const i={dom:s};if(e.props.showPreview===!1||!t){const a=Bn(e);s.appendChild(a.dom),i.destroy=()=>{var l;(l=a.destroy)==null||l.call(a)}}else s.appendChild(t.dom);if(e.props.caption){const a=document.createElement("p");a.className="bn-file-caption",a.textContent=e.props.caption,s.appendChild(a)}return i},qe=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Me=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Nt=e=>({url:e.src||void 0}),En='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>',Tn={backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},xn={type:"audio",propSchema:Tn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Mn=(e,n)=>{const t=document.createElement("div");t.innerHTML=En;const o=document.createElement("audio");return o.className="bn-audio",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(r=>{o.src=r}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,We(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Pn=e=>{if(e.tagName==="AUDIO")return Nt(e);if(e.tagName==="FIGURE"){const n=xe(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...Nt(t),caption:o}}},In=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("audio"),n.src=e.props.url):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?qe(n,e.props.caption):Me(n,e.props.caption):{dom:n}},Ln=me(xn,{render:Mn,parse:Pn,toExternalHTML:In}),st=Symbol.for("blocknote.shikiParser"),Ne=Symbol.for("blocknote.shikiHighlighterPromise"),An={language:{default:"text"}},jr=W({name:"codeBlock",content:"inline*",group:"blockContent",marks:"",code:!0,defining:!0,addOptions(){return{defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}},addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:n=>{let t=n,o=null;(t==null?void 0:t.tagName)==="DIV"&&(t==null?void 0:t.dataset.contentType)==="codeBlock"&&(t=t.children[0]),(t==null?void 0:t.tagName)==="PRE"&&(t=t==null?void 0:t.children[0]);const r=t==null?void 0:t.getAttribute("data-language");if(r)o=r.toLowerCase();else{const i=[...(t==null?void 0:t.className.split(" "))||[]].filter(a=>a.startsWith("language-")).map(a=>a.replace("language-",""));i.length>0&&(o=i[0].toLowerCase())}return o?Ht(e.editor.settings.codeBlock,o):null},renderHTML:n=>n.language?{class:`language-${n.language}`,"data-language":n.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:"code"},{tag:"pre",contentElement:"code",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var r,s;const n=document.createElement("pre"),{dom:t,contentDOM:o}=z(this.name,"code",((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},{...((s=this.options.domAttributes)==null?void 0:s.inlineContent)||{},...e});return t.removeChild(o),t.appendChild(n),n.appendChild(o),{dom:t,contentDOM:o}},addNodeView(){const e=this.options;return({editor:n,node:t,getPos:o,HTMLAttributes:r})=>{var u,h;const s=document.createElement("pre"),i=document.createElement("select"),a=document.createElement("div"),{dom:l,contentDOM:c}=z(this.name,"code",{...((u=this.options.domAttributes)==null?void 0:u.blockContent)||{},...r},((h=this.options.domAttributes)==null?void 0:h.inlineContent)||{}),d=f=>{const m=f.target.value;n.commands.command(({tr:g})=>(g.setNodeAttribute(o(),"language",m),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([f,{name:m}])=>{const g=document.createElement("option");g.value=f,g.text=m,i.appendChild(g)}),a.contentEditable="false",i.value=t.attrs.language||e.editor.settings.codeBlock.defaultLanguage,l.removeChild(c),l.appendChild(a),l.appendChild(s),s.appendChild(c),a.appendChild(i),i.addEventListener("change",d),{dom:l,contentDOM:c,update:f=>f.type===this.type,destroy:()=>{i.removeEventListener("change",d)}}}},addProseMirrorPlugins(){const e=this.options,n=globalThis;let t,o,r=!1;const s=a=>{if(!e.editor.settings.codeBlock.createHighlighter)return process.env.NODE_ENV==="development"&&!r&&(console.log("For syntax highlighting of code blocks, you must provide a highlighter function"),r=!0),[];if(!t)return n[Ne]=n[Ne]||e.editor.settings.codeBlock.createHighlighter(),n[Ne].then(c=>{t=c});const l=a.language;return l&&l!=="text"&&!t.getLoadedLanguages().includes(l)&&l in e.editor.settings.codeBlock.supportedLanguages?t.loadLanguage(l):(o||(o=n[st]||tr.createParser(t),n[st]=o),o(a))};return[er.createHighlightPlugin({parser:s,languageExtractor:a=>a.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new k.InputRule({find:/^```(.*?)\s$/,handler:({state:n,range:t,match:o})=>{const r=n.doc.resolve(t.from),s=o[1].trim(),i={language:Ht(e.editor.settings.codeBlock,s)};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;n.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(w.TextSelection.create(n.tr.doc,t.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:n}=e.state,{$from:t}=n;if(e.isActive(this.name)&&!t.parent.textContent&&k.isTextSelection(n)){const o=t.pos-t.parentOffset-2;return e.chain().setNodeSelection(o).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>this.options.indentLineWithTab&&e.isActive(this.name)?(e.commands.insertContent(" "),!0):!1,Enter:({editor:e})=>{const{$from:n}=e.state.selection;if(!e.isActive(this.name))return!1;const t=n.parentOffset===n.parent.nodeSize-2,o=n.parent.textContent.endsWith(`
5
+ `,styles:{}};return}if(s.type.name!=="link"&&s.type.name!=="text"){if(!n[s.type.name]){console.warn("unrecognized inline content type",s.type.name);return}r&&(o.push(r),r=void 0),o.push(Re(s,n,t));return}const i={};let a;for(const l of s.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c){if(l.type.spec.blocknoteIgnore)continue;throw new Error(`style ${l.type.name} not found in styleSchema`)}if(c.propSchema==="boolean")i[c.type]=!0;else if(c.propSchema==="string")i[c.type]=l.attrs.stringValue;else throw new z(c.propSchema)}r?te(r)?a?(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=s.textContent:(o.push(r),r={type:"text",text:s.textContent,styles:i}):et(r)&&(a?r.href===a.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=s.textContent:r.content.push({type:"text",text:s.textContent,styles:i}):(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):(o.push(r),r={type:"text",text:s.textContent,styles:i})):a?r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}:r={type:"text",text:s.textContent,styles:i}}),r&&o.push(r),o}function Re(e,n,t){if(e.type.name==="text"||e.type.name==="link")throw new Error("unexpected");const o={},r=n[e.type.name];for(const[a,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);const c=r.propSchema;a in c&&(o[a]=l)}let s;return r.content==="styled"?s=Be(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function T(e,n,t=Ar(n),o=Nr(n),r=We(n),s=Hr(n)){var g;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const i=s==null?void 0:s.get(e);if(i)return i;const a=$e(e,0);let l=a.bnBlock.node.attrs.id;l===null&&(l=ve.options.generateID());const c=t[a.blockNoteType];if(!c)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const d={};for(const[b,y]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const C=c.propSchema;b in C&&!(C[b].default===void 0&&y===void 0)&&(d[b]=y)}const u=t[a.blockNoteType],h=[];(g=a.childContainer)==null||g.node.forEach(b=>{h.push(T(b,n,t,o,r,s))});let f;if(u.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");f=Be(a.blockContent.node,o,r)}else if(u.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");f=bt(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new z(u.content);const m={id:l,type:u.type,props:d,content:f,children:h};return s==null||s.set(e,m),m}function nt(e,n,t,o){return e.dom.setAttribute("data-inline-content-type",n),Object.entries(t).filter(([r,s])=>{const i=o[r];return s!==i.default}).map(([r,s])=>[ke(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function an(e){return{Backspace:({editor:n})=>{const t=n.state.selection.$from;return n.state.selection.empty&&t.node().type.name===e.type&&t.parentOffset===0}}}function ln(e,n){return{config:e,implementation:n}}function cn(e,n){return ln({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function kt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function dn(e){return[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Dr(e,n){const t=k.Node.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",content:e.content==="styled"?"inline*":"",addAttributes(){return he(e.propSchema)},addKeyboardShortcuts(){return an(e)},parseHTML(){return dn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render(Re(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return nt(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render(Re(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=U([a],s.pmSchema);s.dispatch(s.prosemirrorView.state.tr.replaceWith(r(),r()+o.nodeSize,l))},s);return nt(i,e.type,o.attrs,e.propSchema)}}});return cn(t,e.propSchema)}function un(e){return e==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:n=>n.getAttribute("data-value"),renderHTML:n=>n.stringValue!==void 0?{"data-value":n.stringValue}:{}}}}function pn(e,n,t,o){return e.dom.setAttribute("data-style-type",n),o==="string"&&e.dom.setAttribute("data-value",t),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function wt(e,n){return{config:e,implementation:n}}function ee(e,n){return wt({type:e.name,propSchema:n},{mark:e})}function yt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function hn(e){return[{tag:`[data-style-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Or(e,n){const t=k.Mark.create({name:e.type,addAttributes(){return un(e.propSchema)},parseHTML(){return hn(e)},renderHTML({mark:o}){let r;if(e.propSchema==="boolean")r=n.render();else if(e.propSchema==="string")r=n.render(o.attrs.stringValue);else throw new z(e.propSchema);return pn(r,e.type,o.attrs.stringValue,e.propSchema)}});return wt(e,{mark:t})}function ne(e){const{height:n,width:t}=Ct(e),o=new Array(n).fill(!1).map(()=>new Array(t).fill(null)),r=(s,i)=>{for(let a=s;a<n;a++)for(let l=i;l<t;l++)if(!o[a][l])return{row:a,col:l};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let s=0;s<e.content.rows.length;s++)for(let i=0;i<e.content.rows[s].cells.length;i++){const a=De(e.content.rows[s].cells[i]),l=Oe(a),c=ue(a),{row:d,col:u}=r(s,i);for(let h=d;h<d+l;h++)for(let f=u;f<u+c;f++){if(o[h][f])throw new Error(`Unable to create occupancy grid for table, cell at ${h},${f} is already occupied`);o[h][f]={row:s,col:i,rowspan:l,colspan:c,cell:a}}}return o}function we(e){const n=new Set;return e.map(t=>({cells:t.map(o=>n.has(o.row+":"+o.col)?!1:(n.add(o.row+":"+o.col),o.cell)).filter(o=>o!==!1)}))}function se(e,n,t=ne(n)){for(let o=0;o<t.length;o++)for(let r=0;r<t[o].length;r++){const s=t[o][r];if(s.row===e.row&&s.col===e.col)return{row:o,col:r,cell:s.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function Ct(e){const n=e.content.rows.length;let t=0;return e.content.rows.forEach(o=>{let r=0;o.cells.forEach(s=>{r+=ue(s)}),t=Math.max(t,r)}),{height:n,width:t}}function fn(e,n,t=ne(n)){var r;const o=(r=t[e.row])==null?void 0:r[e.col];if(o)return{row:o.row,col:o.col,cell:o.cell}}function ot(e,n){var s;const t=ne(e);if(n<0||n>=t.length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[o])==null?void 0:s[0];if(!a)return[];o+=a.rowspan}const r=new Array(t[0].length).fill(!1).map((i,a)=>fn({row:o,col:a},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function rt(e,n){var s;const t=ne(e);if(n<0||n>=t[0].length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[0])==null?void 0:s[o];if(!a)return[];o+=a.colspan}const r=new Array(t.length).fill(!1).map((i,a)=>fn({row:a,col:o},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function Rr(e,n,t,o=ne(e)){const{col:r}=se({row:0,col:n},e,o),{col:s}=se({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),we(o)}function Vr(e,n,t,o=ne(e)){const{row:r}=se({row:n,col:0},e,o),{row:s}=se({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),we(o)}function st(e){return e?de(e)?st(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:te(n)?n.text.length===0:ht(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function _r(e,n,t=ne(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>st(l[i].cell)&&l[i].colspan===1);i--)s++;for(let i=t.length-1;i>=0;i--){const a=Math.max(t[i].length-s,1);t[i]=t[i].slice(0,a)}return we(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>st(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),we(t)}function Ur(e,n,t,o=ne(e)){const{width:r,height:s}=Ct(e);if(n==="columns")o.forEach((i,a)=>{if(t>=0)for(let l=0;l<t;l++)i.push({row:a,col:Math.max(...i.map(c=>c.col))+1,rowspan:1,colspan:1,cell:De("")});else i.splice(r+t,-1*t)});else if(t>0)for(let i=0;i<t;i++){const a=new Array(r).fill(null).map((l,c)=>({row:s+i,col:c,rowspan:1,colspan:1,cell:De("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return we(o)}function mn(e,n,t){const o=ot(e,t);if(!o.some(l=>Oe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=Oe(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function gn(e,n,t){const o=rt(e,t);if(!o.some(l=>ue(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=ue(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function Fr(e,n,t){const o=se(e,t),r=se(n,t);return o.col===r.col}function Ot(e,n,t,o){const r=[];for(const[i,a]of Object.entries(e.styles)){const l=t[i];if(!l)throw new Error(`style ${i} not found in styleSchema`);if(l.propSchema==="boolean")r.push(n.mark(i));else if(l.propSchema==="string")r.push(n.mark(i,{stringValue:a}));else throw new z(l.propSchema)}return!o||!n.nodes[o].spec.code?e.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
6
+ `?n.nodes.hardBreak.createChecked():n.text(i,r)):[n.text(e.text,r)]}function $r(e,n,t){const o=n.marks.link.create({href:e.href});return it(e.content,n,t).map(r=>{if(r.type.name==="text")return r.mark([...r.marks,o]);if(r.type.name==="hardBreak")return r;throw new Error("unexpected node type")})}function it(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Ot({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Ot(s,n,t,o));return r}function U(e,n,t,o=We(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...it(s,n,o,t)):ht(s)?r.push(...$r(s,n,o)):te(s)?r.push(...it([s],n,o,t)):r.push(bn(s,n,o));return r}function Ee(e,n,t=We(n)){const o=[],r=new Array(e.headerRows??0).fill(!0),s=new Array(e.headerCols??0).fill(!0),i=e.columnWidths??[];for(let a=0;a<e.rows.length;a++){const l=e.rows[a],c=[],d=r[a];for(let h=0;h<l.cells.length;h++){const f=l.cells[h],m=s[h],g=void 0;let b=null;const y=se({row:a,col:h},{content:e});let C=i[y.col]?[i[y.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(de(f)){f.content&&(b=U(f.content,n,"tableParagraph",t));const L=ue(f);L>1&&(C=new Array(L).fill(!1).map((j,F)=>i[y.col+F]??void 0))}else b=U(f,n,"tableParagraph",t);const v=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...de(f)?f.props:{},colwidth:C},n.nodes.tableParagraph.createChecked(g,b));c.push(v)}const u=n.nodes.tableRow.createChecked({},c);o.push(u)}return o}function bn(e,n,t){let o,r=e.type;if(r===void 0&&(r="paragraph"),!n.nodes[r])throw new Error(`node type ${r} not found in schema`);if(!e.content)o=n.nodes[r].createChecked(e.props);else if(typeof e.content=="string"){const s=U([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=U(e.content,n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Ee(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new z(e.content.type);return o}function oe(e,n,t=We(n)){let o=e.id;o===void 0&&(o=ve.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(oe(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=bn(e,n,t),a=r.length>0?n.nodes.blockGroup.createChecked({},r):void 0;return n.nodes.blockContainer.createChecked({id:o,...e.props},a?[i,a]:i)}else{if(n.nodes[e.type].isInGroup("bnBlock"))return n.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}}function _(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!Ve(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function Ve(e){return e.type.isInGroup("bnBlock")}function zr(e,n){return e.id!==n.id||e.type!==n.type||JSON.stringify(e.props)!==JSON.stringify(n.props)||JSON.stringify(e.content)!==JSON.stringify(n.content)}function kn(e,n=[]){let t={type:"local"};e.getMeta("paste")?t={type:"paste"}:e.getMeta("uiEvent")==="drop"?t={type:"drop"}:e.getMeta("history$")?t={type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")&&(e.getMeta("y-sync$").isUndoRedoOperation?t={type:"undo-redo"}:t={type:"yjs-remote"});const o=N(e),r=k.combineTransactionSteps(e.before,[e,...n]),s=k.getChangedRanges(r),i=s.flatMap(u=>k.findChildrenInRange(r.before,u.oldRange,Ve)).map(({node:u})=>T(u,o)),a=s.flatMap(u=>k.findChildrenInRange(r.doc,u.newRange,Ve)).map(({node:u})=>T(u,o)),l=new Map(a.map(u=>[u.id,u])),c=new Map(i.map(u=>[u.id,u])),d=[];for(const[u,h]of l)c.has(u)||d.push({type:"insert",block:h,source:t,prevBlock:void 0});for(const[u,h]of c)l.has(u)||d.push({type:"delete",block:h,source:t,prevBlock:void 0});for(const[u,h]of l)if(c.has(u)){const f=c.get(u);zr(f,h)&&d.push({type:"update",block:h,prevBlock:f,source:t})}return d}const A=(e,n)=>({tr:t,dispatch:o})=>(o&&wn(t,e,n),!0),wn=(e,n,t)=>{const o=pe(e.doc.resolve(n)),r=N(e),s=r.nodes[o.blockNoteType],i=r.nodes[t.type||o.blockNoteType],a=i.isInGroup("bnBlock")?i:r.nodes.blockContainer;if(o.isBlockContainer&&i.isInGroup("blockContent"))Rt(t,e,o),Wr(t,e,s,i,o);else if(!o.isBlockContainer&&i.isInGroup("bnBlock"))Rt(t,e,o);else{const l=T(o.bnBlock.node,r);e.replaceWith(o.bnBlock.beforePos,o.bnBlock.afterPos,oe({children:l.children,...t},r));return}e.setNodeMarkup(o.bnBlock.beforePos,a,{...o.bnBlock.node.attrs,...t.props})};function Wr(e,n,t,o,r){const s=N(n);let i="keep";if(e.content)if(typeof e.content=="string")i=U([e.content],s,o.name);else if(Array.isArray(e.content))i=U(e.content,s,o.name);else if(e.content.type==="tableContent")i=Ee(e.content,s);else throw new z(e.content.type);else t.spec.content===""||o.spec.content!==t.spec.content&&(i=[]);i==="keep"?n.setNodeMarkup(r.blockContent.beforePos,e.type===void 0?void 0:s.nodes[e.type],{...r.blockContent.node.attrs,...e.props}):n.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},i))}function Rt(e,n,t){const o=N(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>oe(s,o));if(t.childContainer)n.step(new ce.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new B.Slice(B.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function yn(e,n,t){const o=typeof n=="string"?n:n.id,r=_(o,e.doc);if(!r)throw new Error(`Block with ID ${o} not found`);wn(e,r.posBeforeNode,t);const s=e.doc.resolve(r.posBeforeNode+1).node(),i=N(e);return T(s,i)}function Cn(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function vn(e,n,t,o){let r;if(n)if(typeof n=="string")r=U([n],e.pmSchema);else if(Array.isArray(n))r=U(n,e.pmSchema);else if(n.type==="tableContent")r=Ee(n,e.pmSchema);else throw new z(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(B.Fragment.from(r),o);return s.nodeType===1&&Cn(s),s}function qr(e,n,t,o,r,s,i){var g,b,y,C,v,L,j,F;const a=(i==null?void 0:i.document)??document,l=n.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[x,S]of Object.entries(n.schema.blockSchema[t.type].propSchema))S.default!==void 0&&(c[x]=S.default)}const d=(b=(g=l.spec)==null?void 0:g.toDOM)==null?void 0:b.call(g,l.create({id:t.id,...c})),u=Array.from(d.dom.attributes),h=n.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},n),f=a.createDocumentFragment();if(h.dom.classList.contains("bn-block-content")){const x=[...u,...Array.from(h.dom.attributes)].filter(S=>S.name.startsWith("data")&&S.name!=="data-content-type"&&S.name!=="data-file-block"&&S.name!=="data-node-view-wrapper"&&S.name!=="data-node-type"&&S.name!=="data-id"&&S.name!=="data-index"&&S.name!=="data-editable");for(const S of x)h.dom.firstChild.setAttribute(S.name,S.value);Cn(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const x=vn(n,t.content,o,i);h.contentDOM.appendChild(x)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((y=e.lastChild)==null?void 0:y.nodeName)!==m){const S=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&S.setAttribute("start",c.start+""),e.append(S)}const x=a.createElement("li");x.append(f),e.lastChild.appendChild(x)}else e.append(f);if(t.children&&t.children.length>0){const x=a.createDocumentFragment();if(Sn(x,n,t.children,o,r,s,i),((C=e.lastChild)==null?void 0:C.nodeName)==="UL"||((v=e.lastChild)==null?void 0:v.nodeName)==="OL")for(;((L=x.firstChild)==null?void 0:L.nodeName)==="UL"||((j=x.firstChild)==null?void 0:j.nodeName)==="OL";)e.lastChild.lastChild.appendChild(x.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(x):(F=h.contentDOM)==null||F.append(x)}}const Sn=(e,n,t,o,r,s,i)=>{for(const a of t)qr(e,n,a,o,r,s,i)},Kr=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return Sn(a,e,n,t,o,r,s),a},Te=(e,n)=>{const t=B.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=Kr(n,o,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=vn(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function jr(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=U([n],e.pmSchema,o);else if(Array.isArray(n))s=U(n,e.pmSchema,o);else if(n.type==="tableContent")s=Ee(n,e.pmSchema);else throw new z(n.type);else throw new Error("blockContent is required");return t.serializeFragment(B.Fragment.from(s),r)}function Gr(e,n,t,o,r){var u,h,f,m,g;const s=e.pmSchema.nodes.blockContainer;let i=n.props;if(!n.props){i={};for(const[b,y]of Object.entries(e.schema.blockSchema[n.type].propSchema))y.default!==void 0&&(i[b]=y.default)}const l=e.blockImplementations[n.type].implementation.toInternalHTML({...n,props:i},e);if(n.type==="numberedListItem"&&l.dom.setAttribute("data-index",o.toString()),l.contentDOM&&n.content){const b=jr(e,n.content,t,n.type,r);l.contentDOM.appendChild(b)}if(e.pmSchema.nodes[n.type].isInGroup("bnBlock")){if(n.children&&n.children.length>0){const b=Bn(e,n.children,t,r);(u=l.contentDOM)==null||u.append(b)}return l.dom}const d=(f=(h=s.spec)==null?void 0:h.toDOM)==null?void 0:f.call(h,s.create({id:n.id,...i}));return(m=d.contentDOM)==null||m.appendChild(l.dom),n.children&&n.children.length>0&&((g=d.contentDOM)==null||g.appendChild(En(e,n.children,t,r))),d.dom}function Bn(e,n,t,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();let i=0;for(const a of n){a.type==="numberedListItem"?i++:i=0;const l=Gr(e,a,t,i,o);s.appendChild(l)}return s}const En=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Bn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},Tn=(e,n)=>{const t=B.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>En(n,o,t,r).outerHTML}},xe=(e,n)=>{const t=e.querySelector(n);if(!t)return;const o=e.querySelector("figcaption"),r=(o==null?void 0:o.textContent)??void 0;return{targetElement:t,caption:r}},xn=(e,n,t,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",o?s.appendChild(o):s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(s);const i=document.createElement("p");i.className="bn-add-file-button-text",i.innerHTML=t||n.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{n.transact(c=>c.setMeta(n.filePanel.plugin,{block:e}))};return r.addEventListener("mousedown",a,!0),r.addEventListener("click",l,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",a,!0),r.removeEventListener("click",l,!0)}}},Mn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',Pn=e=>{const n=document.createElement("div");n.className="bn-file-name-with-icon";const t=document.createElement("div");t.className="bn-file-icon",t.innerHTML=Mn,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},qe=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=xn(e,n,o,r);s.appendChild(a.dom);const l=n.onUploadStart(c=>{if(c===e.id){s.removeChild(a.dom);const d=document.createElement("div");d.className="bn-file-loading-preview",d.textContent="Loading...",s.appendChild(d)}});return{dom:s,destroy:()=>{l(),a.destroy()}}}const i={dom:s};if(e.props.showPreview===!1||!t){const a=Pn(e);s.appendChild(a.dom),i.destroy=()=>{var l;(l=a.destroy)==null||l.call(a)}}else s.appendChild(t.dom);if(e.props.caption){const a=document.createElement("p");a.className="bn-file-caption",a.textContent=e.props.caption,s.appendChild(a)}return i},Ke=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Me=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Vt=e=>({url:e.src||void 0}),In='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>',Ln={backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},An={type:"audio",propSchema:Ln,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Nn=(e,n)=>{const t=document.createElement("div");t.innerHTML=In;const o=document.createElement("audio");return o.className="bn-audio",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(r=>{o.src=r}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,qe(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Hn=e=>{if(e.tagName==="AUDIO")return e.closest("figure")?void 0:Vt(e);if(e.tagName==="FIGURE"){const n=xe(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...Vt(t),caption:o}}},Dn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("audio"),n.src=e.props.url):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ke(n,e.props.caption):Me(n,e.props.caption):{dom:n}},On=fe(An,{render:Nn,parse:Hn,toExternalHTML:Dn}),at=Symbol.for("blocknote.shikiParser"),Ne=Symbol.for("blocknote.shikiHighlighterPromise"),Rn={language:{default:"text"}},Xr=K({name:"codeBlock",content:"inline*",group:"blockContent",marks:"",code:!0,defining:!0,addOptions(){return{defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}},addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:n=>{let t=n,o=null;(t==null?void 0:t.tagName)==="DIV"&&(t==null?void 0:t.dataset.contentType)==="codeBlock"&&(t=t.children[0]),(t==null?void 0:t.tagName)==="PRE"&&(t=t==null?void 0:t.children[0]);const r=t==null?void 0:t.getAttribute("data-language");if(r)o=r.toLowerCase();else{const i=[...(t==null?void 0:t.className.split(" "))||[]].filter(a=>a.startsWith("language-")).map(a=>a.replace("language-",""));i.length>0&&(o=i[0].toLowerCase())}return o?Ye(e.editor.settings.codeBlock,o)??o:null},renderHTML:n=>n.language?{class:`language-${n.language}`,"data-language":n.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",contentElement:"code",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var r,s;const n=document.createElement("pre"),{dom:t,contentDOM:o}=q(this.name,"code",((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},{...((s=this.options.domAttributes)==null?void 0:s.inlineContent)||{},...e});return t.removeChild(o),t.appendChild(n),n.appendChild(o),{dom:t,contentDOM:o}},addNodeView(){const e=this.options;return({editor:n,node:t,getPos:o,HTMLAttributes:r})=>{var u,h;const s=document.createElement("pre"),i=document.createElement("select"),a=document.createElement("div"),{dom:l,contentDOM:c}=q(this.name,"code",{...((u=this.options.domAttributes)==null?void 0:u.blockContent)||{},...r},((h=this.options.domAttributes)==null?void 0:h.inlineContent)||{}),d=f=>{const m=f.target.value;n.commands.command(({tr:g})=>(g.setNodeAttribute(o(),"language",m),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([f,{name:m}])=>{const g=document.createElement("option");g.value=f,g.text=m,i.appendChild(g)}),a.contentEditable="false",i.value=t.attrs.language||e.editor.settings.codeBlock.defaultLanguage,l.removeChild(c),l.appendChild(a),l.appendChild(s),s.appendChild(c),a.appendChild(i),i.addEventListener("change",d),{dom:l,contentDOM:c,update:f=>f.type===this.type,destroy:()=>{i.removeEventListener("change",d)}}}},addProseMirrorPlugins(){const e=this.options,n=globalThis;let t,o,r=!1;const s=a=>{if(!e.editor.settings.codeBlock.createHighlighter)return process.env.NODE_ENV==="development"&&!r&&(console.log("For syntax highlighting of code blocks, you must provide a `codeBlock.createHighlighter` function"),r=!0),[];if(!t)return n[Ne]=n[Ne]||e.editor.settings.codeBlock.createHighlighter(),n[Ne].then(c=>{t=c});const l=Ye(e.editor.settings.codeBlock,a.language);return!l||l==="text"||l==="none"||l==="plaintext"||l==="txt"?[]:t.getLoadedLanguages().includes(l)?(o||(o=n[at]||ir.createParser(t),n[at]=o),o(a)):t.loadLanguage(l)};return[sr.createHighlightPlugin({parser:s,languageExtractor:a=>a.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new k.InputRule({find:/^```(.*?)\s$/,handler:({state:n,range:t,match:o})=>{const r=n.doc.resolve(t.from),s=o[1].trim(),i={language:Ye(e.editor.settings.codeBlock,s)??s};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;n.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(w.TextSelection.create(n.tr.doc,t.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:n}=e.state,{$from:t}=n;if(e.isActive(this.name)&&!t.parent.textContent&&k.isTextSelection(n)){const o=t.pos-t.parentOffset-2;return e.chain().setNodeSelection(o).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>this.options.indentLineWithTab&&e.isActive(this.name)?(e.commands.insertContent(" "),!0):!1,Enter:({editor:e})=>{const{$from:n}=e.state.selection;if(!e.isActive(this.name))return!1;const t=n.parentOffset===n.parent.nodeSize-2,o=n.parent.textContent.endsWith(`
7
7
 
8
8
  `);return!t||!o?(e.commands.insertContent(`
9
- `),!0):e.chain().command(({tr:r})=>(r.delete(n.pos-2,n.pos),!0)).exitCode().run()},"Shift-Enter":({editor:e})=>{const{$from:n}=e.state.selection;return e.isActive(this.name)?(e.chain().insertContentAt(n.pos-n.parentOffset+n.parent.nodeSize,{type:"paragraph"}).run(),!0):!1}}}}),Nn=Y(jr,An);function Ht(e,n){var t;return((t=Object.entries(e.supportedLanguages).find(([o,{aliases:r}])=>(r==null?void 0:r.includes(n))||o===n))==null?void 0:t[0])||n}const it=e=>({url:e.src||void 0}),Hn={backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},Dn={type:"file",propSchema:Hn,content:"none",isFileBlock:!0},On=(e,n)=>We(e,n),Rn=e=>{if(e.tagName==="EMBED")return it(e);if(e.tagName==="FIGURE"){const n=xe(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...it(t),caption:o}}},_n=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add file",{dom:t}}const n=document.createElement("a");return n.href=e.props.url,n.textContent=e.props.name||e.props.url,e.props.caption?Me(n,e.props.caption):{dom:n}},Vn=me(Dn,{render:On,parse:Rn,toExternalHTML:_n}),wt=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=We(e,n,t,r,s),l=i;e.props.url&&e.props.showPreview&&(l.style.width=`${e.props.previewWidth}px`);const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";let u,h=e.props.previewWidth;const f=v=>{if(!u){!n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d));return}let L;e.props.textAlignment==="center"?u.handleUsed==="left"?L=u.initialWidth+(u.initialClientX-v.clientX)*2:L=u.initialWidth+(v.clientX-u.initialClientX)*2:u.handleUsed==="left"?L=u.initialWidth+u.initialClientX-v.clientX:L=u.initialWidth+v.clientX-u.initialClientX,h=Math.max(L,64),l.style.width=`${h}px`},m=v=>{(!v.target||!l.contains(v.target)||!n.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),u&&(u=void 0,n.updateBlock(e,{props:{previewWidth:h}}))},g=()=>{n.isEditable&&(o.appendChild(c),o.appendChild(d))},b=v=>{v.relatedTarget===c||v.relatedTarget===d||u||n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},y=v=>{v.preventDefault(),u={handleUsed:"left",initialWidth:l.clientWidth,initialClientX:v.clientX}},C=v=>{v.preventDefault(),u={handleUsed:"right",initialWidth:l.clientWidth,initialClientX:v.clientX}};return window.addEventListener("mousemove",f),window.addEventListener("mouseup",m),l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",b),c.addEventListener("mousedown",y),d.addEventListener("mousedown",C),{dom:l,destroy:()=>{a==null||a(),window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",m),l.removeEventListener("mouseenter",g),l.removeEventListener("mouseleave",b),c.removeEventListener("mousedown",y),d.removeEventListener("mousedown",C)}}},Gr=async e=>{const n=new FormData;return n.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:n})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},Dt=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},Fn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>',Un={textAlignment:M.textAlignment,backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},$n={type:"image",propSchema:Un,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},zn=(e,n)=>{const t=document.createElement("div");t.innerHTML=Fn;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),wt(e,n,{dom:o},o,n.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},Wn=e=>{if(e.tagName==="IMG")return Dt(e);if(e.tagName==="FIGURE"){const n=xe(e,"img");if(!n)return;const{targetElement:t,caption:o}=n;return{...Dt(t),caption:o}}},qn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add image",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("img"),n.src=e.props.url,n.alt=e.props.name||e.props.caption||"BlockNote image",n.width=e.props.previewWidth):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?qe(n,e.props.caption):Me(n,e.props.caption):{dom:n}},Kn=me($n,{render:zn,parse:Wn,toExternalHTML:qn}),jn={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Gn=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},Xn=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},Jn=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},Yn=me(jn,{render:Gn,parse:Xn,toExternalHTML:Jn}),Xr=k.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-background-color")?{stringValue:e.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),Jr=Q(Xr,"string"),Yr=k.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-text-color")?{stringValue:e.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),Zr=Q(Yr,"string"),Zn={...M,level:{default:1,values:[1,2,3]}},Qr=W({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return fe(Zn)},addInputRules(){return[...[1,2,3].map(e=>new k.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:n,chain:t,range:o})=>{const r=B(n);!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||t().command(A(r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:1}}))},"Mod-Alt-2":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:2}}))},"Mod-Alt-3":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:3}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:e,HTMLAttributes:n}){var t,o;return z(this.name,`h${e.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),es=Y(Qr,Zn),Qn=(e,n,t)=>({state:o,dispatch:r})=>{const s=K(o.doc,e),i=X(s);if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const a=[{type:i.bnBlock.node.type,attrs:t?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:n?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:t?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,a),!0},yt=e=>{const{blockInfo:n,selectionEmpty:t}=e.transact(s=>({blockInfo:Ce(s),selectionEmpty:s.selection.anchor===s.selection.head}));if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n;return!(r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!t?!1:e._tiptapEditor.commands.first(({state:s,chain:i,commands:a})=>[()=>a.command(()=>r.node.childCount===0?a.command(A(o.beforePos,{type:"paragraph",props:{}})):!1),()=>a.command(()=>r.node.childCount>0?(i().deleteSelection().command(Qn(s.selection.from,!0)).run(),!0):!1)])},ts={...M},ns=W({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new k.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>yt(this.options.editor),"Mod-Shift-8":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.tagName==="UL"||n.tagName==="DIV"&&n.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:e=>{if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return z(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),os=Y(ns,ts),eo={...M,checked:{default:!1}},rs=W({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return fe(eo)},addInputRules(){return[new k.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:t.from,to:t.to})}}),new k.InputRule({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>yt(this.options.editor),"Mod-Shift-9":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"input",getAttrs:e=>typeof e=="string"?!1:e.type==="checkbox"?{checked:e.checked}:!1,node:"checkListItem"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="UL"||n.tagName==="DIV"&&n.parentElement.tagName==="UL"){const t=e.querySelector("input[type=checkbox]")||null;return t===null?!1:{checked:t.checked}}return!1},node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:n}){var s,i;const t=document.createElement("input");t.type="checkbox",t.checked=e.attrs.checked,e.attrs.checked&&t.setAttribute("checked","");const{dom:o,contentDOM:r}=z(this.name,"p",{...((s=this.options.domAttributes)==null?void 0:s.blockContent)||{},...n},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{});return o.insertBefore(t,r),{dom:o,contentDOM:r}},addNodeView(){return({node:e,getPos:n,editor:t,HTMLAttributes:o})=>{var d,u;const r=document.createElement("div"),s=document.createElement("div");s.contentEditable="false";const i=document.createElement("input");i.type="checkbox",i.checked=e.attrs.checked,e.attrs.checked&&i.setAttribute("checked","");const a=()=>{if(!t.isEditable){i.checked=!i.checked;return}if(typeof n!="boolean"){const h=K(t.state.doc,n());if(h.node.type.name!=="blockContainer")throw new Error(`Expected blockContainer node, got ${h.node.type.name}`);this.editor.commands.command(A(h.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=z(this.name,"p",{...((d=this.options.domAttributes)==null?void 0:d.blockContent)||{},...o},((u=this.options.domAttributes)==null?void 0:u.inlineContent)||{});if(typeof n!="boolean"){const f="label-"+this.editor.state.doc.resolve(n()).node().attrs.id;i.setAttribute("aria-labelledby",f),c.id=f}return l.removeChild(c),l.appendChild(r),r.appendChild(s),r.appendChild(c),s.appendChild(i),{dom:l,contentDOM:c,destroy:()=>{i.removeEventListener("change",a)}}}}}),ss=Y(rs,eo),is=new w.PluginKey("numbered-list-indexing"),as=()=>new w.Plugin({key:is,appendTransaction:(e,n,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((s,i)=>{var a;if(s.type.name==="blockContainer"&&s.firstChild.type.name==="numberedListItem"){let l=`${s.firstChild.attrs.start||1}`;const c=X({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=o.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=X({posBeforeNode:c.bnBlock.beforePos-d.nodeSize,node:d});if(m.blockNoteType==="numberedListItem"){if(!m.isBlockContainer)throw new Error("impossible");const b=m.blockContent.node.attrs.index;l=(parseInt(b)+1).toString()}}const u=c.blockContent.node,h=u.attrs.index,f=((a=d==null?void 0:d.firstChild)==null?void 0:a.type.name)!=="numberedListItem";if(h!==l||u.attrs.start&&!f){r=!0;const{start:m,...g}=u.attrs;o.setNodeMarkup(c.blockContent.beforePos,void 0,{...g,index:l,...typeof m=="number"&&f&&{start:m}})}}}),r?o:null}}),to={...M,start:{default:void 0,type:"number"}},ls=W({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...fe(to),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}},addInputRules(){return[new k.InputRule({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:n,range:t,match:o})=>{const r=B(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem")return;const s=parseInt(o[1]);n().command(A(r.bnBlock.beforePos,{type:"numberedListItem",props:s===1&&{}||{start:s}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>yt(this.options.editor),"Mod-Shift-7":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[as()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="OL"||n.tagName==="DIV"&&n.parentElement.tagName==="OL"){const t=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||t===1?{}:{start:t}}return!1},node:"numberedListItem"},{tag:"p",getAttrs:e=>{if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return z(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),cs=Y(ls,to),ds={...M},us=W({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,getAttrs:e=>{var n;return typeof e=="string"||!((n=e.textContent)!=null&&n.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var n,t;return z(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ps=Y(us,ds),hs={...M},fs=W({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new k.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"blockquote",node:"quote"}]},renderHTML({HTMLAttributes:e}){var n,t;return z(this.name,"blockquote",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ms=Y(fs,hs),gs=35,Ct=120,bs=31,ks=k.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[P.columnResizing({cellMinWidth:gs,defaultCellMinWidth:Ct,View:null}),P.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.insertContent({type:"hardBreak"}),!0):!1,Backspace:()=>{const e=this.editor.state.selection,n=e.empty,t=e.$head.parentOffset===0,o=e.$head.node().type.name==="tableParagraph";return n&&t&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>P.goToNextCell(1)(e,n,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>P.goToNextCell(-1)(e,n,t))}},extendNodeSchema(e){const n={name:e.name,options:e.options,storage:e.storage};return{tableRole:k.callOrReturn(k.getExtensionField(e,"tableRole",n))}}}),ws={textColor:M.textColor},ys=W({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var n,t;return z(this.name,"table",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:n})=>{var o;class t extends P.TableView{constructor(s,i,a){super(s,i),this.node=s,this.cellMinWidth=i,this.blockContentHTMLAttributes=a;const l=document.createElement("div");l.className=J("bn-block-content",a.class),l.setAttribute("data-content-type","table");for(const[h,f]of Object.entries(a))h!=="class"&&l.setAttribute(h,f);const c=this.dom,d=document.createElement("div");d.className="tableWrapper-inner",d.appendChild(c.firstChild),c.appendChild(d),l.appendChild(c);const u=document.createElement("div");u.className="table-widgets-container",u.style.position="relative",c.appendChild(u),this.dom=l}ignoreMutation(s){return!s.target.closest(".tableWrapper-inner")||super.ignoreMutation(s)}}return new t(e,Ct,{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...n})}}}),Cs=W({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{preserveWhitespace:"full",priority:210,context:"tableContent",tag:"p",getAttrs:e=>({})},{tag:"p",getAttrs:e=>{if(typeof e=="string"||!e.textContent)return!1;const n=e.parentElement;return n===null?!1:n.tagName==="TD"?{}:!1}}]},renderHTML({HTMLAttributes:e}){return["p",e,0]}}),vs=Y(ys,ws,[ks,Cs,lr.TableHeader.extend({content:"tableContent+"}),ar.TableCell.extend({content:"tableContent+"}),cr.TableRow]),Ot=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},no='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>',oo={textAlignment:M.textAlignment,backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},ro={type:"video",propSchema:oo,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},so=(e,n)=>{const t=document.createElement("div");t.innerHTML=no;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),wt(e,n,{dom:o},o,n.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},io=e=>{if(e.tagName==="VIDEO")return Ot(e);if(e.tagName==="FIGURE"){const n=xe(e,"video");if(!n)return;const{targetElement:t,caption:o}=n;return{...Ot(t),caption:o}}},ao=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add video",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("video"),n.src=e.props.url,n.width=e.props.previewWidth):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?qe(n,e.props.caption):Me(n,e.props.caption):{dom:n}},lo=me(ro,{render:so,parse:io,toExternalHTML:ao}),vt={paragraph:ps,heading:es,quote:ms,codeBlock:Nn,bulletListItem:os,numberedListItem:cs,checkListItem:ss,table:vs,file:Vn,image:Kn,video:lo,audio:Ln},co=ht(vt),St={bold:Q(kr.default,"boolean"),italic:Q(yr.default,"boolean"),underline:Q(vr.default,"boolean"),strike:Q(Cr.default,"boolean"),code:Q(wr.default,"boolean"),textColor:Zr,backgroundColor:Jr},Ss=bt(St),Bt={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},uo=mt(Bt);function D(e,n){return e in n.schema.blockSchema&&n.schema.blockSchema[e]===co[e]}function po(e,n){return e in n.schema.inlineContentSchema&&n.schema.inlineContentSchema[e]===uo[e]}function ho(e,n,t){return n.type===e&&n.type in t.schema.blockSchema&&D(n.type,t)}function Bs(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock||!1}function Es(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock&&"showPreview"in n.schema.blockSchema[e.type].propSchema||!1}function Ts(e,n){return n.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function fo(e,n,t){return n in t.schema.blockSchema&&e in t.schema.blockSchema[n].propSchema&&t.schema.blockSchema[n].propSchema[e]===M[e]}function xs(e,n,t){return fo(e,n.type,t)}function at(e){return e instanceof P.CellSelection}function Ms(e){let n=e.getTextCursorPosition().block,t=e.schema.blockSchema[n.type].content;for(;t==="none";){if(n=e.getTextCursorPosition().nextBlock,n===void 0)return;t=e.schema.blockSchema[n.type].content,e.setTextCursorPosition(n,"end")}}function H(e,n){const t=e.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(t.content)&&(t.content.length===1&&ee(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?(o=e.updateBlock(t,n),e.setTextCursorPosition(o)):(o=e.insertBlocks([n],t,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),Ms(e),o}function Ps(e){const n=[];return D("heading",e)&&n.push({onItemClick:()=>{H(e,{type:"heading",props:{level:1}})},badge:G("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{H(e,{type:"heading",props:{level:2}})},badge:G("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{H(e,{type:"heading",props:{level:3}})},badge:G("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),D("quote",e)&&n.push({onItemClick:()=>{H(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),D("numberedListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"numberedListItem"})},badge:G("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),D("bulletListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"bulletListItem"})},badge:G("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),D("checkListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"checkListItem"})},badge:G("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),D("paragraph",e)&&n.push({onItemClick:()=>{H(e,{type:"paragraph"})},badge:G("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),D("codeBlock",e)&&n.push({onItemClick:()=>{H(e,{type:"codeBlock"})},badge:G("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),D("table",e)&&n.push({onItemClick:()=>{H(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),D("image",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"image"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"image",...e.dictionary.slash_menu.image}),D("video",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"video"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"video",...e.dictionary.slash_menu.video}),D("audio",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"audio"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),D("file",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"file"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"file",...e.dictionary.slash_menu.file}),n.push({onItemClick:()=>{e.openSuggestionMenu(":",{deleteTriggerCharacter:!0,ignoreQueryLength:!0})},key:"emoji",...e.dictionary.slash_menu.emoji}),n}function Is(e,n){return e.filter(({title:t,aliases:o})=>t.toLowerCase().includes(n.toLowerCase())||o&&o.filter(r=>r.toLowerCase().includes(n.toLowerCase())).length!==0)}function Je(e){return e&&Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}class ge{constructor(n){p(this,"blockSpecs");p(this,"inlineContentSpecs");p(this,"styleSpecs");p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"BlockNoteEditor","only for types");p(this,"Block","only for types");p(this,"PartialBlock","only for types");this.blockSpecs=Je(n==null?void 0:n.blockSpecs)||vt,this.inlineContentSpecs=Je(n==null?void 0:n.inlineContentSpecs)||Bt,this.styleSpecs=Je(n==null?void 0:n.styleSpecs)||St,this.blockSchema=ht(this.blockSpecs),this.inlineContentSchema=mt(this.inlineContentSpecs),this.styleSchema=bt(this.styleSpecs)}static create(n){return new ge(n)}}const Et=ge.create({blockSpecs:{pageBreak:Yn}}),Ls=e=>ge.create({blockSpecs:{...e.blockSpecs,...Et.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function mo(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===Et.blockSchema.pageBreak}function As(e){const n=[];return mo(e)&&n.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{H(e,{type:"pageBreak"})},key:"page_break"}),n}function Ns(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=N(e),i=n.map(d=>ne(d,s)),a=_(r,e.doc);if(!a)throw new Error(`Block with ID ${r} not found`);let l=a.posBeforeNode;return o==="after"&&(l+=a.node.nodeSize),e.step(new de.ReplaceStep(l,l,new E.Slice(E.Fragment.from(i),0,0))),i.map(d=>T(d,s))}function Hs(e){return e.transact(n=>{const t=K(n.doc,n.selection.anchor);if(n.selection instanceof P.CellSelection)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:n.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:n.selection.$headCell.pos-t.posBeforeNode};if(n.selection instanceof w.NodeSelection)return{type:"node",anchorBlockId:t.node.attrs.id};{const o=K(n.doc,n.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:o.node.attrs.id,anchorOffset:n.selection.anchor-t.posBeforeNode,headOffset:n.selection.head-o.posBeforeNode}}})}function Ds(e,n){var r,s;const t=(r=_(n.anchorBlockId,e.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let o;if(n.type==="cell")o=P.CellSelection.create(e.doc,t+n.anchorCellOffset,t+n.headCellOffset);else if(n.type==="node")o=w.NodeSelection.create(e.doc,t+1);else{const i=(s=_(n.headBlockId,e.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${n.headBlockId} to update selection`);o=w.TextSelection.create(e.doc,t+n.anchorOffset,i+n.headOffset)}e.setSelection(o)}function lt(e){return e.map(n=>n.type==="columnList"?n.children.map(t=>lt(t.children)).flat():{...n,children:lt(n.children)}).flat()}function go(e,n,t){e.transact(o=>{var i;const r=((i=e.getSelection())==null?void 0:i.blocks)||[e.getTextCursorPosition().block],s=Hs(e);e.removeBlocks(r),e.insertBlocks(lt(r),n,t),Ds(o,s)})}function bo(e){return!e||e.type!=="columnList"}function ko(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[n.children.length-1],r="after"):(o=n,r="before"):t&&(o=t,r="before"),!o||!r)return;const s=e.getParentBlock(o);return bo(s)?{referenceBlock:o,placement:r}:ko(e,r==="after"?o:e.getPrevBlock(o),s)}function wo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[0],r="before"):(o=n,r="after"):t&&(o=t,r="after"),!o||!r)return;const s=e.getParentBlock(o);return bo(s)?{referenceBlock:o,placement:r}:wo(e,r==="before"?o:e.getNextBlock(o),s)}function Os(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[0])||e.getTextCursorPosition().block,o=ko(e,e.getPrevBlock(t),e.getParentBlock(t));o&&go(e,o.referenceBlock,o.placement)})}function Rs(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[(n==null?void 0:n.blocks.length)-1])||e.getTextCursorPosition().block,o=wo(e,e.getNextBlock(t),e.getParentBlock(t));o&&go(e,o.referenceBlock,o.placement)})}function _s(e,n){return function(t,o){const{$from:r,$to:s}=t.selection,i=r.blockRange(s,d=>d.childCount>0&&(d.type.name==="blockGroup"||d.type.name==="column"));if(!i)return!1;const a=i.startIndex;if(a===0)return!1;const c=i.parent.child(a-1);if(c.type!==e)return!1;if(o){const d=c.lastChild&&c.lastChild.type===n,u=E.Fragment.from(d?e.create():null),h=new E.Slice(E.Fragment.from(e.create(null,E.Fragment.from(n.create(null,u)))),d?3:1,0),f=i.start,m=i.end;o(t.tr.step(new de.ReplaceAroundStep(f-(d?3:1),m,f,m,h,1,!0)).scrollIntoView())}return!0}}function yo(e){return e.exec((n,t)=>_s(n.schema.nodes.blockContainer,n.schema.nodes.blockGroup)(n,t))}function Vs(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function Fs(e){return e.transact(n=>{const{bnBlock:t}=Ce(n);return n.doc.resolve(t.beforePos).nodeBefore!==null})}function Us(e){return e.transact(n=>{const{bnBlock:t}=Ce(n);return n.doc.resolve(t.beforePos).depth>1})}function Rt(e,n,t){const o=N(e),r=t.map(d=>ne(d,o)),s=new Set(n.map(d=>typeof d=="string"?d:d.id)),i=[],a=typeof n[0]=="string"?n[0]:n[0].id;let l=0;if(e.doc.descendants((d,u)=>{if(s.size===0)return!1;if(!d.type.isInGroup("bnBlock")||!s.has(d.attrs.id))return!0;if(i.push(T(d,o)),s.delete(d.attrs.id),t.length>0&&d.attrs.id===a){const g=e.doc.nodeSize;e.insert(u,r);const b=e.doc.nodeSize;l+=g-b}const h=e.doc.nodeSize,f=e.doc.resolve(u-l);f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?e.delete(f.before(),f.after()):e.delete(u-l,u-l+d.nodeSize);const m=e.doc.nodeSize;return l+=h-m,!1}),s.size>0){const d=[...s].join(`
10
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+d)}return{insertedBlocks:r.map(d=>T(d,o)),removedBlocks:i}}function $s(e,n){const t=typeof n=="string"?n:n.id,o=N(e),r=_(t,e);if(r)return T(r.node,o)}function zs(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e),r=N(e);if(!o)return;const i=e.resolve(o.posBeforeNode).nodeBefore;if(i)return T(i,r)}function Ws(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e),r=N(e);if(!o)return;const i=e.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return T(i,r)}function qs(e,n){const t=typeof n=="string"?n:n.id,o=N(e),r=_(t,e);if(!r)return;const s=e.resolve(r.posBeforeNode),i=s.node(),a=s.node(-1),l=a.type.name!=="doc"?i.type.name==="blockGroup"?a:i:void 0;if(l)return T(l,o)}function Ks(e,n,t,o={updateSelection:!0}){let{from:r,to:s}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},i=!0,a=!0,l="";if(t.forEach(c=>{c.check(),i&&c.isText&&c.marks.length===0?l+=c.text:i=!1,a=a?c.isBlock:!1}),r===s&&a){const{parent:c}=e.doc.resolve(r);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(r-=1,s+=1)}return i?e.insertText(l,r,s):e.replaceWith(r,s,t),o.updateSelection&&k.selectionToInsertionEnd(e,e.steps.length-1,-1),!0}function js(e){const n=N(e);if(e.selection.empty||"node"in e.selection)return;const t=e.doc.resolve(K(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(K(e.doc,e.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),h=e.doc.resolve(u).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${u}`);return T(h,n)},s=[],i=t.sharedDepth(o.pos),a=t.index(i),l=o.index(i);if(t.depth>i){s.push(T(t.nodeAfter,n));for(let c=t.depth;c>i;c--)if(t.node(c).type.isInGroup("childContainer")){const u=t.index(c)+1,h=t.node(c).childCount;for(let f=u;f<h;f++)s.push(r(f,c))}}else s.push(r(a,i));for(let c=a+1;c<=l;c++)s.push(r(c,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:s}}function Gs(e,n,t){const o=typeof n=="string"?n:n.id,r=typeof t=="string"?t:t.id,s=N(e),i=Se(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const a=_(o,e.doc);if(!a)throw new Error(`Block with ID ${o} not found`);const l=_(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const c=X(a),d=X(l),u=i.blockSchema[c.blockNoteType],h=i.blockSchema[d.blockNoteType];if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!d.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let f,m;if(u.content==="table"){const g=P.TableMap.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(h.content==="table"){const g=P.TableMap.get(d.blockContent.node),b=d.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,d.blockContent.node)+1,y=e.doc.resolve(b).nodeAfter.nodeSize;m=b+y-2}else m=d.blockContent.afterPos-1;e.setSelection(w.TextSelection.create(e.doc,f,m))}function Xs(e){const{bnBlock:n}=Ce(e),t=N(e.doc),o=e.doc.resolve(n.beforePos),r=o.nodeBefore,s=e.doc.resolve(n.afterPos).nodeAfter;let i;return o.depth>1&&(i=o.node(),i.type.isInGroup("bnBlock")||(i=o.node(o.depth-1))),{block:T(n.node,t),prevBlock:r===null?void 0:T(r,t),nextBlock:s===null?void 0:T(s,t),parentBlock:i===void 0?void 0:T(i,t)}}function Co(e,n,t="start"){const o=typeof n=="string"?n:n.id,r=N(e.doc),s=Se(r),i=_(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const a=X(i),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){e.setSelection(w.NodeSelection.create(e.doc,c.beforePos));return}if(l==="inline")t==="start"?e.setSelection(w.TextSelection.create(e.doc,c.beforePos+1)):e.setSelection(w.TextSelection.create(e.doc,c.afterPos-1));else if(l==="table")t==="start"?e.setSelection(w.TextSelection.create(e.doc,c.beforePos+4)):e.setSelection(w.TextSelection.create(e.doc,c.afterPos-4));else throw new U(l)}else{const c=t==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;Co(e,c.attrs.id,t)}}exports.esmDependencies=void 0;async function Ke(){if(exports.esmDependencies)return exports.esmDependencies;const e=await Promise.all([import("rehype-parse"),import("rehype-stringify"),import("unified"),import("hast-util-from-dom"),import("rehype-remark"),import("remark-gfm"),import("remark-stringify"),import("remark-parse"),import("remark-rehype"),import("rehype-format")]);return exports.esmDependencies={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},exports.esmDependencies}function Js(){const e=n=>{let t=n.children.length;for(let o=0;o<t;o++){const r=n.children[o];if(r.type==="element"&&(e(r),r.tagName==="u"))if(r.children.length>0){n.children.splice(o,1,...r.children);const s=r.children.length-1;t+=s,o+=s}else n.children.splice(o,1),t--,o--}};return e}function Ys(){const e=exports.esmDependencies;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const n=t=>{var o;if(t.children&&"length"in t.children&&t.children.length)for(let r=t.children.length-1;r>=0;r--){const s=t.children[r],i=r+1<t.children.length?t.children[r+1]:void 0;s.type==="element"&&s.tagName==="input"&&((o=s.properties)==null?void 0:o.type)==="checkbox"&&(i==null?void 0:i.type)==="element"&&i.tagName==="p"?(i.tagName="span",i.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):n(s)}};return n}function je(e){const n=exports.esmDependencies;if(!n)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return n.unified.unified().use(n.rehypeParse.default,{fragment:!0}).use(Js).use(Ys).use(n.rehypeRemark.default).use(n.remarkGfm.default).use(n.remarkStringify.default,{handlers:{text:o=>o.value}}).processSync(e).value}async function vo(e,n,t,o){await Ke();const s=Te(n,t).exportBlocks(e,o);return je(s)}function Zs(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Qs(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function ei(e){e.querySelectorAll("li > ul, li > ol").forEach(n=>{const t=Zs(n),o=n.parentElement,r=Array.from(o.childNodes).slice(t+1);n.remove(),r.forEach(s=>{s.remove()}),o.insertAdjacentElement("afterend",n),r.reverse().forEach(s=>{if(Qs(s))return;const i=document.createElement("li");i.append(s),n.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function ti(e){e.querySelectorAll("li + ul, li + ol").forEach(n=>{var s,i;const t=n.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),o.append(r);((s=o.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=o.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(o.nextElementSibling)})}let _t=null;function ni(){return _t||(_t=document.implementation.createHTMLDocument("title"))}function So(e){if(typeof e=="string"){const n=ni().createElement("div");n.innerHTML=e,e=n}return ei(e),ti(e),e}async function Tt(e,n){const t=So(e),r=E.DOMParser.fromSchema(n).parse(t,{topNode:n.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(T(r.child(i),n));return s}function oi(e,n){const t=n.value?n.value:"",o={};n.lang&&(o["data-language"]=n.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return n.meta&&(r.data={meta:n.meta}),e.patch(n,r),r=e.applyData(n,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(n,r),r}async function xt(e){const n=await Ke();return n.unified.unified().use(n.remarkParse.default).use(n.remarkGfm.default).use(n.remarkRehype.default,{handlers:{...n.remarkRehype.defaultHandlers,code:oi}}).use(n.rehypeStringify.default).processSync(e).value}async function Bo(e,n){const t=await xt(e);return Tt(t,n)}const Mt=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function ri(e,n){if(!e.startsWith(".")||!n.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===n}function si(e,n){const t=e.split("/"),o=n.split("/");if(t.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${n} is not a valid MIME type.`);return t[1]==="*"||o[1]==="*"?t[0]===o[0]:(t[0]==="*"||o[0]==="*"||t[0]===o[0])&&t[1]===o[1]}function Vt(e,n,t){let o;return Array.isArray(n.content)&&n.content.length===0?o=e.updateBlock(n,t).id:o=e.insertBlocks([t],n,"after")[0].id,o}async function Eo(e,n){var i;if(!n.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const t="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(t===null)return;let o=null;for(const a of Mt)if(t.types.includes(a)){o=a;break}if(o!=="Files")return;const r=t.items;if(!r)return;e.preventDefault();const s=Object.values(n.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<r.length;a++){let l="file";for(const d of s)for(const u of d.fileBlockAccept||[]){const h=u.startsWith("."),f=r[a].getAsFile();if(f&&(!h&&f.type&&si(r[a].type,u)||h&&ri("."+f.name.split(".").pop(),u))){l=d.type;break}}const c=r[a].getAsFile();if(c){const d={type:l,props:{name:c.name}};let u;if(e.type==="paste"){const m=n.getTextCursorPosition().block;u=Vt(n,m,d)}else if(e.type==="drop"){const m={left:e.clientX,top:e.clientY},g=(i=n.prosemirrorView)==null?void 0:i.posAtCoords(m);if(!g)return;u=n.transact(b=>{const y=K(b.doc,g.pos);return Vt(n,n.getBlock(y.node.attrs.id),d)})}else return;const h=await n.uploadFile(c,u),f=typeof h=="string"?{props:{url:h}}:{...h};n.updateBlock(u,f)}}}const ii=e=>k.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{drop(n,t){if(!e.isEditable)return;let o=null;for(const r of Mt)if(t.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(Eo(t,e),!0):!1}}}})]}});async function ai(e,n){const{schema:t}=n.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!t.nodes.codeBlock)return n.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;return i?(n.pasteHTML(`<pre><code class="language-${i}">${o.replace(/\r\n?/g,`
11
- `)}</code></pre>`),!0):!1}const li=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,ci=new RegExp("(?:\\s|^)(_|__|\\*|\\*\\*|~~|==|\\+\\+)(?!\\s).{1,64}(?<!\\s)(?=\\1)"),di=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,ui=new RegExp("(?:\\s|^)`(?!\\s)[^`]{1,48}(?<!\\s)`([^\\w]|$)"),pi=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,hi=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,fi=/\n{2} {0,3}-{2,48}\n{2}/,mi=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,gi=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,bi=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,ki=/^\s*\|(.+\|)+\s*$/m,wi=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,yi=/^\s*\|(.+\|)+\s*$/m,Ci=e=>li.test(e)||ci.test(e)||di.test(e)||ui.test(e)||pi.test(e)||hi.test(e)||fi.test(e)||mi.test(e)||gi.test(e)||bi.test(e)||ki.test(e)||wi.test(e)||yi.test(e);function vi({event:e,editor:n,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:o}){let r;for(const i of Mt)if(e.clipboardData.types.includes(i)){r=i;break}if(!r)return!0;if(r==="vscode-editor-data")return ai(e,n.prosemirrorView),!0;if(r==="Files")return Eo(e,n),!0;const s=e.clipboardData.getData(r);if(r==="blocknote/html")return n.pasteHTML(s,!0),!0;if(r==="text/markdown")return n.pasteMarkdown(s),!0;if(t){const i=e.clipboardData.getData("text/plain");if(Ci(i))return n.pasteMarkdown(i),!0}return r==="text/html"?(n.pasteHTML(s),!0):o?(n.pasteMarkdown(s),!0):(n.pasteText(s),!0)}const Si=(e,n)=>k.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{paste(t,o){if(o.preventDefault(),!!e.isEditable)return n({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>vi({event:o,editor:e,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function To(e){const n=[];return e.descendants(t=>{var r,s;const o=N(t);return t.type.name==="blockContainer"&&((r=t.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:t.type.name==="columnList"&&t.childCount===1?((s=t.firstChild)==null||s.forEach(i=>{n.push(T(i,o))}),!1):t.type.isInGroup("bnBlock")?(n.push(T(t,o)),!1):!0}),n}function Bi(e,n,t){var a;let o=!1;const r=e.state.selection instanceof P.CellSelection;if(!r){const l=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,c=[];for(let d=0;d<l.childCount;d++)c.push(l.child(d));o=c.find(d=>d.type.isInGroup("bnBlock")||d.type.name==="blockGroup"||d.type.spec.group==="blockContent")===void 0,o&&(n=l)}let s;const i=Te(e.state.schema,t);if(r){((a=n.firstChild)==null?void 0:a.type.name)==="table"&&(n=n.firstChild.content);const l=ft(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=Be(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=To(n);s=i.exportBlocks(l,{})}return s}function Pt(e,n){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&n.transact(i=>i.setSelection(new w.NodeSelection(i.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=Bi(e,o,n),s=je(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const Ft=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let n=e.focusNode;for(;n;){if(n instanceof HTMLElement&&n.getAttribute("contenteditable")==="false")return!0;n=n.parentElement}return!1},Ut=(e,n,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Pt(n,e);t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},Ei=e=>k.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{copy(n,t){return Ft()||Ut(e,n,t),!0},cut(n,t){return Ft()||(Ut(e,n,t),n.editable&&n.dispatch(n.state.tr.deleteSelection())),!0},dragstart(n,t){if(!("node"in n.state.selection)||n.state.selection.node.type.spec.group!=="blockContent")return;e.transact(i=>i.setSelection(new w.NodeSelection(i.doc.resolve(n.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Pt(n,e);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),Ti=k.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:M.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):M.backgroundColor.default,renderHTML:e=>e.backgroundColor===M.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]}}),xi=e=>{var o;const n=[];n.push(Sr.default.configure({fragment:e.fragment}));const t=(o=e.provider)==null?void 0:o.awareness;if(t){const r=new Map;e.showCursorLabels!=="always"&&t.on("change",({updated:a})=>{for(const l of a){const c=r.get(l);c&&(c.element.setAttribute("data-active",""),c.hideTimeout&&clearTimeout(c.hideTimeout),r.set(l,{element:c.element,hideTimeout:setTimeout(()=>{c.element.removeAttribute("data-active")},2e3)}))}});const s=a=>{const l=document.createElement("span");l.classList.add("bn-collaboration-cursor__base");const c=document.createElement("span");c.setAttribute("contentedEditable","false"),c.classList.add("bn-collaboration-cursor__caret"),c.setAttribute("style",`background-color: ${a.color}`);const d=document.createElement("span");return d.classList.add("bn-collaboration-cursor__label"),d.setAttribute("style",`background-color: ${a.color}`),d.insertBefore(document.createTextNode(a.name),null),c.insertBefore(d,null),l.insertBefore(document.createTextNode("⁠"),null),l.insertBefore(c,null),l.insertBefore(document.createTextNode("⁠"),null),l},i=(a,l)=>{var d;let c=r.get(l);if(!c){const u=((d=e==null?void 0:e.renderCursor)==null?void 0:d.call(e,a))||s(a);(e==null?void 0:e.showCursorLabels)!=="always"&&(u.addEventListener("mouseenter",()=>{const h=r.get(l);h.element.setAttribute("data-active",""),h.hideTimeout&&(clearTimeout(h.hideTimeout),r.set(l,{element:h.element,hideTimeout:void 0}))}),u.addEventListener("mouseleave",()=>{const h=r.get(l);r.set(l,{element:h.element,hideTimeout:setTimeout(()=>{h.element.removeAttribute("data-active")},2e3)})})),c={element:u,hideTimeout:void 0},r.set(l,c)}return c.element};n.push(Br.default.configure({user:e.user,render:i,provider:e.provider}))}return n},xo=k.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}},renderHTML({HTMLAttributes:e}){return["span",k.mergeAttributes(e,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(e){return e.name==="comment"?{blocknoteIgnore:!0}:{}}});class Z{constructor(){p(this,"callbacks",{})}on(n,t){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(t),()=>this.off(n,t)}emit(n,...t){const o=this.callbacks[n];o&&o.forEach(r=>r.apply(this,t))}off(n,t){const o=this.callbacks[n];o&&(t?this.callbacks[n]=o.filter(r=>r!==t):delete this.callbacks[n])}removeAllListeners(){this.callbacks={}}}class Mi extends Z{constructor(t){super();p(this,"userCache",new Map);p(this,"loadingUsers",new Set);this.resolveUsers=t}async loadUsers(t){const o=t.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(o.length!==0){for(const r of o)this.loadingUsers.add(r);try{const r=await this.resolveUsers(o);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of o)this.loadingUsers.delete(r)}}}getUser(t){return this.userCache.get(t)}subscribe(t){return this.on("update",t)}}const Pe=new w.PluginKey("blocknote-comments"),Pi="SET_SELECTED_THREAD_ID";function Ii(e,n){const t=new Map;return e.descendants((o,r)=>{o.marks.forEach(s=>{if(s.type.name===n){const i=s.attrs.threadId;if(!i)return;const a=r,l=a+o.nodeSize,c=t.get(i)??{from:1/0,to:0};t.set(i,{from:Math.min(a,c.from),to:Math.max(l,c.to)})}})}),t}class Li extends Z{constructor(t,o,r){super();p(this,"plugin");p(this,"userStore");p(this,"pendingComment",!1);p(this,"selectedThreadId");p(this,"threadPositions",new Map);p(this,"updateMarksFromThreads",t=>{this.editor.transact(o=>{o.doc.descendants((r,s)=>{r.marks.forEach(i=>{if(i.type.name===this.markType){const a=i.type,l=i.attrs.threadId,c=t.get(l),d=!!(!c||c.resolved||c.deletedAt);if(d!==i.attrs.orphan){const u=Math.max(s,0),h=Math.min(s+r.nodeSize,o.doc.content.size-1);o.removeMark(u,h,i),o.addMark(u,h,a.create({...i.attrs,orphan:d})),d&&this.selectedThreadId===l&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})});if(this.editor=t,this.threadStore=o,this.markType=r,!t.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new Mi(t.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),t.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),t.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const s=this;this.plugin=new w.Plugin({key:Pe,state:{init(){return{decorations:x.DecorationSet.empty}},apply(i,a){const l=i.getMeta(Pe);if(!i.docChanged&&!l)return a;const c=i.docChanged?Ii(i.doc,s.markType):s.threadPositions;(c.size>0||s.threadPositions.size>0)&&(s.threadPositions=c,s.emitStateUpdate());const d=[];if(s.selectedThreadId){const u=c.get(s.selectedThreadId);u&&d.push(x.Decoration.inline(u.from,u.to,{class:"bn-thread-mark-selected"}))}return{decorations:x.DecorationSet.create(i.doc,d)}}},props:{decorations(i){var a;return((a=Pe.getState(i))==null?void 0:a.decorations)??x.DecorationSet.empty},handleClick:(i,a,l)=>{if(l.button!==0)return;const c=i.state.doc.nodeAt(a);if(!c){s.selectThread(void 0);return}const d=c.marks.find(h=>h.type.name===r&&h.attrs.orphan!==!0),u=d==null?void 0:d.attrs.threadId;s.selectThread(u,!1)}}})}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(t){return this.on("update",t)}selectThread(t,o=!0){var r,s;if(this.selectedThreadId!==t&&(this.selectedThreadId=t,this.emitStateUpdate(),this.editor.transact(i=>i.setMeta(Pe,{name:Pi})),t&&o)){const i=this.threadPositions.get(t);if(!i)return;(s=(r=this.editor.prosemirrorView)==null?void 0:r.domAtPos(i.from).node)==null||s.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(t){const o=await this.threadStore.createThread(t);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=oe.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?oe.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:o.id,selection:a})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:o.id})}}class Mo{constructor(n,t,o,r){p(this,"state");p(this,"emitUpdate");p(this,"mouseDownHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"dragstartHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;if((n=this.state)!=null&&n.show){const t=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!t)return;this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate()}});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pluginKey=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var r,s;const o=this.pluginKey.getState(n.state);if(!((r=this.state)!=null&&r.show)&&o.block&&this.editor.isEditable){const i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!i)return;this.state={show:!0,referencePos:i.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!n.state.selection.eq(t.selection)||!n.state.doc.eq(t.doc)||!this.editor.isEditable)&&(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const Ye=new w.PluginKey("FilePanelPlugin");class Po extends Z{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>{var t;return(t=this.view)==null?void 0:t.closeMenu()});this.plugin=new w.Plugin({key:Ye,view:o=>(this.view=new Mo(t,Ye,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:o=>{var s;return{block:(s=o.getMeta(Ye))==null?void 0:s.block}}}})}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}class Io{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"shouldShow",({state:n,from:t,to:o})=>{const{doc:r,selection:s}=n,{empty:i}=s,a=!r.textBetween(t,o).length&&k.isTextSelection(n.selection);return s.$from.parent.type.spec.code||k.isNodeSelection(s)&&s.node.type.spec.code?!1:!(i||a)});p(this,"blurHandler",n=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;n&&n.relatedTarget&&(t===n.relatedTarget||t.contains(n.relatedTarget)||n.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});p(this,"dragHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var h;const{state:o,composing:r}=n,{selection:s}=o,i=t&&t.selection.from===o.selection.from&&t.selection.to===o.selection.to;if(r||i)return;const{ranges:a}=s,l=Math.min(...a.map(f=>f.$from.pos)),c=Math.max(...a.map(f=>f.$to.pos)),d=this.shouldShow({view:n,state:o,from:l,to:c}),u=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(d||this.preventHide)&&!u){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((h=this.state)!=null&&h.show&&!this.preventHide&&(!d||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:n}=this.pmView,{selection:t}=n,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(k.isNodeSelection(t)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return k.posToDOMRect(this.pmView,r,s)}}const Lo=new w.PluginKey("FormattingToolbarPlugin");class Ao extends Z{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new w.Plugin({key:Lo,view:o=>(this.view=new Io(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}const Ai=k.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:e}){return["br",k.mergeAttributes(this.options.HTMLAttributes,e)]},renderText(){return`
12
- `}}),$t=(e,n)=>{const t=e.resolve(n);if(t.depth<=1)return;const o=t.posAtIndex(t.index(t.depth-1),t.depth-1);return he(e.resolve(o))},He=(e,n)=>{const t=e.resolve(n),o=t.index();if(o===0)return;const r=t.posAtIndex(o-1);return he(e.resolve(r))},No=(e,n)=>{for(;n.childContainer;){const t=n.childContainer.node,o=e.resolve(n.childContainer.beforePos+1).posAtIndex(t.childCount-1);n=he(e.resolve(o))}return n},Ni=(e,n)=>e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*"&&e.blockContent.node.childCount>0&&n.isBlockContainer&&n.blockContent.node.type.spec.content==="inline*",Hi=(e,n,t,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const r=e.doc.resolve(o.childContainer.beforePos+1),s=e.doc.resolve(o.childContainer.afterPos-1),i=r.blockRange(s);if(n){const a=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,a.depth)}}if(n){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);n(e.tr.delete(t.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0},zt=e=>({state:n,dispatch:t})=>{const o=n.doc.resolve(e),r=he(o),s=He(n.doc,r.bnBlock.beforePos);if(!s)return!1;const i=No(n.doc,s);return Ni(i,r)?Hi(n,t,i,r):!1},Di=k.Extension.create({priority:50,addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({chain:o,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const a=s.selection.from===i.blockContent.beforePos+1,l=i.blockContent.node.type.name==="paragraph";return a&&!l?r.command(A(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const{blockContent:a}=i;return s.selection.from===a.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,c=s.selection.from===l.beforePos+1,d=s.selection.empty,u=a.beforePos;return c&&d?o().command(zt(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=B(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||He(s.doc,a.bnBlock.beforePos))return!1;const d=$t(s.doc,a.bnBlock.beforePos);if((d==null?void 0:d.blockNoteType)!=="column")return!1;const u=d,h=$t(s.doc,u.bnBlock.beforePos);if((h==null?void 0:h.blockNoteType)!=="columnList")throw new Error("parent of column is not a column list");const f=u.childContainer.node.childCount===1,m=f&&h.childContainer.node.childCount===2,g=h.childContainer.node.firstChild===u.bnBlock.node;if(i){const b=s.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos,!1);if(m)if(g){s.tr.step(new de.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,u.bnBlock.afterPos+1,h.bnBlock.afterPos-2,b,b.size,!1));const y=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else{s.tr.step(new de.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,h.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const y=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(w.TextSelection.between(y,y))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(h.bnBlock.beforePos,b.content);const y=s.tr.doc.resolve(h.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else s.tr.delete(u.bnBlock.beforePos-1,u.bnBlock.beforePos+1);else{s.tr.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),g?s.tr.insert(h.bnBlock.beforePos-1,b.content):s.tr.insert(u.bnBlock.beforePos-1,b.content);const y=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(w.TextSelection.between(y,y))}}return!0}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=He(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let c=o();if(l.blockContent.node.type.spec.content==="tableRow+"){const m=i.bnBlock.beforePos-1-1-1-1-1;c=c.setTextSelection(m)}else if(l.blockContent.node.type.spec.content===""){const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setNodeSelection(d)}else{const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setTextSelection(d)}return c.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=He(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=No(s.doc,c);if(!d.isBlockContainer)throw new Error("todo");if(d.blockContent.node.type.spec.content===""||d.blockContent.node.type.spec.content==="inline*"&&d.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},d.bnBlock.afterPos).deleteRange({from:d.bnBlock.beforePos,to:d.bnBlock.afterPos}).run()}return!1})]),n=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=B(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:a,childContainer:l}=s,{depth:c}=r.doc.resolve(i.beforePos),d=i.afterPos===r.doc.nodeSize-3,u=r.selection.from===a.afterPos-1,h=r.selection.empty;if(!d&&u&&h&&!(l!==void 0)){let m=c,g=i.afterPos+1,b=r.doc.resolve(g).depth;for(;b<m;)m=b,g+=2,b=r.doc.resolve(g).depth;return o.command(zt(g-1))}return!1})]),t=(o=!1)=>this.editor.commands.first(({commands:r})=>[()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,{depth:c}=s.doc.resolve(a.beforePos),d=s.selection.$anchor.parentOffset===0,u=s.selection.anchor===s.selection.head,h=l.node.childCount===0,f=c>1;return d&&u&&h&&f?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=B(s),a=this.options.editor.schema.blockSchema[i.blockNoteType].hardBreakShortcut??"shift+enter";return a==="none"?!1:a==="shift+enter"&&o||a==="enter"?r.insertContent({type:"hardBreak"}):!1}),()=>r.command(({state:s,dispatch:i})=>{const a=B(s);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,d=s.selection.$anchor.parentOffset===0,u=s.selection.anchor===s.selection.head,h=c.node.childCount===0;if(d&&u&&h){const f=l.afterPos,m=f+2;if(i){const g=s.schema.nodes.blockContainer.createAndFill();s.tr.insert(f,g).scrollIntoView(),s.tr.setSelection(new w.TextSelection(s.doc.resolve(m)))}return!0}return!1}),()=>r.command(({state:s,chain:i})=>{const a=B(s);if(!a.isBlockContainer)return!1;const{blockContent:l}=a,c=s.selection.$anchor.parentOffset===0;return l.node.childCount===0?!1:(i().deleteSelection().command(Qn(s.selection.from,c,c)).run(),!0)})]);return{Backspace:e,Delete:n,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:yo(this.options.editor)},"Shift-Tab":()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0)}}});class Oi{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredLinkMark");p(this,"mouseHoveredLinkMarkRange");p(this,"keyboardHoveredLinkMark");p(this,"keyboardHoveredLinkMarkRange");p(this,"linkMark");p(this,"linkMarkRange");p(this,"mouseOverHandler",n=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),n.target instanceof HTMLAnchorElement&&n.target.nodeName==="A"){const t=n.target,o=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(o),s=r.marks();for(const i of s)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=i,this.mouseHoveredLinkMarkRange=k.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",n=>{var o;const t=this.pmView.dom.parentElement;this.linkMark&&n&&n.target&&!(t===n.target||t.contains(n.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;this.linkMark!==void 0&&(n=this.state)!=null&&n.show&&(this.state.referencePos=k.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(n,t){var o;this.editor.transact(r=>{const s=N(r);r.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),r.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,s.mark("link",{href:n}))}),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var n;this.editor.transact(t=>t.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}update(n,t,o=!1){var a;const{state:r}=n;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const l=this.pmView.state.selection.$from.marks();for(const c of l)if(c.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=c,this.keyboardHoveredLinkMarkRange=k.getMarkRange(this.pmView.state.selection.$from,c.type,c.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&o&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:k.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((a=this.state)!=null&&a.show&&i&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const Ho=new w.PluginKey("LinkToolbarPlugin");class Do extends Z{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"editLink",(t,o)=>{this.view.editLink(t,o)});p(this,"deleteLink",()=>{this.view.deleteLink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new w.Plugin({key:Ho,view:o=>(this.view=new Oi(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}onUpdate(t){return this.on("update",t)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}const Oo=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],Ro="https",Ri=new w.PluginKey("node-selection-keyboard");class _i{constructor(){p(this,"plugin");this.plugin=new w.Plugin({key:Ri,props:{handleKeyDown:(n,t)=>{if("node"in n.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){const o=n.state.tr;return n.dispatch(o.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new w.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}})}}const Vi=new w.PluginKey("blocknote-placeholder");class Fi{constructor(n,t){p(this,"plugin");this.plugin=new w.Plugin({key:Vi,view:o=>{var c,d;const r=`placeholder-selector-${Xt.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),((c=n.prosemirrorView)==null?void 0:c.root)instanceof ShadowRoot?n.prosemirrorView.root.append(s):(d=n.prosemirrorView)==null||d.root.head.appendChild(s);const a=s.sheet,l=(u="")=>`.${r} .bn-block-content${u} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:u,emptyDocument:h,...f}=t;for(const[b,y]of Object.entries(f)){const C=`[data-content-type="${b}"]`;a.insertRule(`${l(C)} { content: ${JSON.stringify(y)}; }`)}const m="[data-is-only-empty-block]",g="[data-is-empty-and-focused]";a.insertRule(`${l(m)} { content: ${JSON.stringify(h)}; }`),a.insertRule(`${l(g)} { content: ${JSON.stringify(u)}; }`)}catch(u){console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",u)}return{destroy:()=>{var u,h;((u=n.prosemirrorView)==null?void 0:u.root)instanceof ShadowRoot?n.prosemirrorView.root.removeChild(s):(h=n.prosemirrorView)==null||h.root.head.removeChild(s)}}},props:{decorations:o=>{const{doc:r,selection:s}=o;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(x.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,l=a.parent;if(l.content.size===0){const c=a.before();i.push(x.Decoration.node(c,c+l.nodeSize,{"data-is-empty-and-focused":"true"}))}return x.DecorationSet.create(r,i)}}})}}const Wt=new w.PluginKey("previous-blocks"),Ui={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class $i{constructor(){p(this,"plugin");let n;this.plugin=new w.Plugin({key:Wt,view(t){return{update:async(o,r)=>{var s;((s=this.key)==null?void 0:s.getState(o.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(Wt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,o,r,s){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!t.docChanged||r.doc.eq(s.doc))return o;const i={},a=k.findChildren(r.doc,d=>d.attrs.id),l=new Map(a.map(d=>[d.node.attrs.id,d])),c=k.findChildren(s.doc,d=>d.attrs.id);for(const d of c){const u=l.get(d.node.attrs.id),h=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:s.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:r.doc.resolve(u.pos).depth};i[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in o.prevTransactionOldBlockAttrs&&(g=o.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),o.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,o.updatedBlocks.add(d.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=i,o}},props:{decorations(t){const o=this.getState(t);if(o.updatedBlocks.size===0)return;const r=[];return t.doc.descendants((s,i)=>{if(!s.attrs.id||!o.updatedBlocks.has(s.attrs.id))return;const a=o.currentTransactionOldBlockAttrs[s.attrs.id],l={};for(const[d,u]of Object.entries(a))l["data-prev-"+Ui[d]]=u||"none";const c=x.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),x.DecorationSet.create(t.doc,r)}}})}}const qt=new w.PluginKey("blocknote-show-selection");class zi{constructor(n){p(this,"plugin");p(this,"enabled",!1);this.editor=n,this.plugin=new w.Plugin({key:qt,props:{decorations:t=>{const{doc:o,selection:r}=t;if(!this.enabled)return x.DecorationSet.empty;const s=x.Decoration.inline(r.from,r.to,{"data-show-selection":"true"});return x.DecorationSet.create(o,[s])}}})}setEnabled(n){this.enabled!==n&&(this.enabled=n,this.editor.transact(t=>t.setMeta(qt,{})))}getEnabled(){return this.enabled}}function _o(e,n){var t,o;for(;e&&e.parentElement&&e.parentElement!==n.dom&&((t=e.getAttribute)==null?void 0:t.call(e,"data-node-type"))!=="blockContainer";)e=e.parentElement;if(((o=e.getAttribute)==null?void 0:o.call(e,"data-node-type"))==="blockContainer")return{node:e,id:e.getAttribute("data-id")}}class re extends w.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,o,r=o){return new re(t.resolve(o),t.resolve(r))}content(){return new E.Slice(E.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof re)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?w.Selection.near(t.resolve(r.pos)):r.deleted?w.Selection.near(t.resolve(s.pos)):new re(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}w.Selection.jsonID("multiple-node",re);let $;function Wi(e,n){let t,o;const r=n.resolve(e.from).node().type.spec.group==="blockContent",s=n.resolve(e.to).node().type.spec.group==="blockContent",i=Math.min(e.$anchor.depth,e.$head.depth);if(r&&s){const a=e.$from.start(i-1),l=e.$to.end(i-1);t=n.resolve(a-1).pos,o=n.resolve(l+1).pos}else t=e.from,o=e.to;return{from:t,to:o}}function Kt(e,n,t=n){n===t&&(t+=e.state.doc.resolve(n+1).node().nodeSize);const o=e.domAtPos(n).node.cloneNode(!0),r=e.domAtPos(n).node,s=(u,h)=>Array.prototype.indexOf.call(u.children,h),i=s(r,e.domAtPos(n+1).node.parentElement),a=s(r,e.domAtPos(t-1).node.parentElement);for(let u=r.childElementCount-1;u>=0;u--)(u>a||u<i)&&o.removeChild(o.children[u]);Vo(e.root),$=o;const l=$.getElementsByTagName("iframe");for(let u=0;u<l.length;u++){const h=l[u],f=h.parentElement;f&&f.removeChild(h)}const d=e.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");$.className=$.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild($):e.root.body.appendChild($)}function Vo(e){$!==void 0&&(e instanceof ShadowRoot?e.removeChild($):e.body.removeChild($),$=void 0)}function qi(e,n,t){if(!e.dataTransfer)return;const o=t.prosemirrorView;if(!o)return;const r=_(n.id,o.state.doc);if(!r)throw new Error(`Block with ID ${n.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,a=o.state.doc,{from:l,to:c}=Wi(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof re;d&&u?(o.dispatch(o.state.tr.setSelection(re.create(a,l,c))),Kt(o,l,c)):(o.dispatch(o.state.tr.setSelection(w.NodeSelection.create(o.state.doc,s))),Kt(o,s));const h=o.state.selection.content(),f=t.pmSchema,m=o.serializeForClipboard(h).dom.innerHTML,g=Te(f,t),b=To(h.content),y=g.exportBlocks(b,{}),C=je(y);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",y),e.dataTransfer.setData("text/plain",C),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage($,0,0)}}const be=.1;function ct(e,n,t,o=!0){const r=e.root.elementsFromPoint(n.left+(t==="editor"?50:0),n.top);for(const s of r)if(e.dom.contains(s))return o&&s.closest("[data-node-type=columnList]")?ct(e,{left:n.left+50,top:n.top},t,!1):_o(s,e)}function Ki(e,n,t){if(!n.dom.firstChild)return;const o=n.dom.firstChild.getBoundingClientRect(),r={left:e.x,top:e.y},s=r.left<o.left,i=r.left>o.right;t==="viewport"&&(s&&(r.left=o.left+10),i&&(r.left=o.right-10));let a=ct(n,r,t);if(!i&&a){const l=a.node.getBoundingClientRect();r.left=l.right-10,a=ct(n,r,"viewport",!1)}return a}class Fo{constructor(n,t,o,r){p(this,"state");p(this,"emitUpdate");p(this,"mousePos");p(this,"hoveredBlock");p(this,"menuFrozen",!1);p(this,"isDragOrigin",!1);p(this,"updateState",n=>{this.state=n,this.emitUpdate(this.state)});p(this,"updateStateFromMousePos",()=>{var o,r,s,i;if(this.menuFrozen||!this.mousePos)return;const n=Ki(this.mousePos,this.pmView,this.sideMenuDetection);if(!n||!this.editor.isEditable){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}if((r=this.state)!=null&&r.show&&((s=this.hoveredBlock)!=null&&s.hasAttribute("data-id"))&&((i=this.hoveredBlock)==null?void 0:i.getAttribute("data-id"))===n.id)return;this.hoveredBlock=n.node;const t=n.node.firstChild;if(t&&this.editor.isEditable){const a=t.getBoundingClientRect(),l=n.node.closest("[data-node-type=column]");this.updateState({show:!0,referencePos:new DOMRect(l?l.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,a.y,a.width,a.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))})}});p(this,"onDrop",n=>{var r,s;if(this.pmView.dragging===null)return;this.editor._tiptapEditor.commands.blur();const t=n.target instanceof Node&&((r=n.target instanceof HTMLElement?n.target:n.target.parentElement)==null?void 0:r.closest(".bn-editor"))||null;if(t&&(!this.isDragOrigin&&this.pmView.dom===t?this.pmView.dispatch(this.pmView.state.tr.setSelection(w.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.to))):this.isDragOrigin&&this.pmView.dom!==t&&setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0)),this.sideMenuDetection==="editor"||n.synthetic||!((s=n.dataTransfer)!=null&&s.types.includes("blocknote/html")))return;const o=this.pmView.posAtCoords({left:n.clientX,top:n.clientY});if(!o||o.inside===-1){const i=this.createSyntheticEvent(n);this.pmView.dom.dispatchEvent(i)}});p(this,"onDragEnd",()=>{this.pmView.dragging=null});p(this,"onDragStart",n=>{var i;const t=(i=n.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!t)return;if(this.pmView.dragging)throw new Error("New drag was started while an existing drag is ongoing");const o=document.createElement("div");o.innerHTML=t;const s=E.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new E.Slice(s.content,0,0),move:!0}});p(this,"onDragOver",n=>{var o;if(this.sideMenuDetection==="editor"||n.synthetic||!((o=n.dataTransfer)!=null&&o.types.includes("blocknote/html")))return;const t=this.pmView.posAtCoords({left:n.clientX,top:n.clientY});if(!t||t.inside===-1&&this.pmView.dom.firstChild){const r=this.createSyntheticEvent(n);this.pmView.dom.dispatchEvent(r)}});p(this,"onKeyDown",n=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});p(this,"onMouseMove",n=>{var s;if(this.menuFrozen)return;this.mousePos={x:n.clientX,y:n.clientY};const t=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom,r=this.pmView.dom.parentElement;if(o&&n&&n.target&&!(r===n.target||r.contains(n.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});p(this,"onScroll",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state))});this.editor=n,this.sideMenuDetection=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");r(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),Ke(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),o.root.addEventListener("scroll",this.onScroll,!0)}createSyntheticEvent(n){const t=new Event(n.type,n),o=this.pmView.dom.firstChild.getBoundingClientRect();return t.clientX=n.clientX,t.clientY=n.clientY,n.clientX<o.left&&n.clientX>o.left-o.width*be?t.clientX=o.left+o.width*be/2:n.clientX>o.right&&n.clientX<o.right+o.width*be?t.clientX=o.right-o.width*be/2:(n.clientX<o.left||n.clientX>o.right)&&(t.clientX=o.left+be*o.width*2),t.clientY=Math.min(Math.max(n.clientY,o.top),o.top+o.height),t.dataTransfer=n.dataTransfer,t.preventDefault=()=>n.preventDefault(),t.synthetic=!0,t}update(n,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const Uo=new w.PluginKey("SideMenuPlugin");class $o extends Z{constructor(t,o){super();p(this,"view");p(this,"plugin");p(this,"blockDragStart",(t,o)=>{this.view&&(this.view.isDragOrigin=!0),qi(t,o,this.editor)});p(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&Vo(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)});p(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});p(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=t,this.plugin=new w.Plugin({key:Uo,view:r=>(this.view=new Fo(t,o,r,s=>{this.emit("update",s)}),this.view)})}onUpdate(t){return this.on("update",t)}}const Ie=new Map;function ji(e){if(Ie.has(e))return Ie.get(e);const n=new de.Mapping;return e._tiptapEditor.on("transaction",({transaction:t})=>{n.appendMapping(t.mapping)}),e._tiptapEditor.on("destroy",()=>{Ie.delete(e)}),Ie.set(e,n),n}function Gi(e,n,t="left"){const o=oe.ySyncPluginKey.getState(e._tiptapEditor.state);if(!o){const s=ji(e),i=s.maps.length;return()=>s.slice(i).map(n,t==="left"?-1:1)}const r=oe.absolutePositionToRelativePosition(n+(t==="right"?1:0),o.binding.type,o.binding.mapping);return()=>{const s=oe.ySyncPluginKey.getState(e._tiptapEditor.state),i=oe.relativePositionToAbsolutePosition(s.doc,s.binding.type,r,s.binding.mapping);if(i===null)throw new Error("Position not found, cannot track positions");return i+(t==="right"?-1:0)}}const Xi=k.findParentNode(e=>e.type.name==="blockContainer");class Ji{constructor(n,t){p(this,"state");p(this,"emitUpdate");p(this,"rootEl");p(this,"pluginState");p(this,"handleScroll",()=>{var n,t;if((n=this.state)!=null&&n.show){const o=(t=this.rootEl)==null?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!o)return;this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});p(this,"closeMenu",()=>{this.editor.transact(n=>n.setMeta(ce,null))});p(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(n=>n.selection.from)}).run()});var o,r;this.editor=n,this.pluginState=void 0,this.emitUpdate=s=>{var i;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(s,{...this.state,ignoreQueryLength:(i=this.pluginState)==null?void 0:i.ignoreQueryLength})},this.rootEl=(o=this.editor.prosemirrorView)==null?void 0:o.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(n,t){var c;const o=ce.getState(t),r=ce.getState(n.state),s=o===void 0&&r!==void 0,i=o!==void 0&&r===void 0;if(!s&&!(o!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?o:r,i||!this.editor.isEditable){this.state&&(this.state.show=!1),this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&l&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var n;(n=this.rootEl)==null||n.removeEventListener("scroll",this.handleScroll,!0)}}const ce=new w.PluginKey("SuggestionMenuPlugin");class zo extends Z{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"triggerCharacters",[]);p(this,"addTriggerCharacter",t=>{this.triggerCharacters.push(t)});p(this,"removeTriggerCharacter",t=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==t)});p(this,"closeMenu",()=>this.view.closeMenu());p(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new w.Plugin({key:ce,view:()=>(this.view=new Ji(t,(r,s)=>{this.emit(`update ${r}`,s)}),this.view),state:{init(){},apply:(r,s,i,a)=>{if(r.getMeta("orderedListIndexing")!==void 0||r.selection.$from.parent.type.spec.code)return s;const l=r.getMeta(ce);if(typeof l=="object"&&l!==null){s&&this.closeMenu();const d=Gi(t,a.selection.from-l.triggerCharacter.length);return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:()=>d()+l.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:l==null?void 0:l.ignoreQueryLength}}if(s===void 0)return s;if(a.selection.from!==a.selection.to||l===null||r.getMeta("focus")||r.getMeta("blur")||r.getMeta("pointer")||s.triggerCharacter!==void 0&&a.selection.from<s.queryStartPos()||!a.selection.$from.sameParent(a.doc.resolve(s.queryStartPos())))return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos(),a.selection.from),c}},props:{handleTextInput(r,s,i,a){return o.includes(a)?(r.dispatch(r.state.tr.insertText(a)),r.dispatch(r.state.tr.setMeta(ce,{triggerCharacter:a}).scrollIntoView()),!0):!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=Xi(r.selection);if(i)return x.DecorationSet.create(r.doc,[x.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return x.DecorationSet.create(r.doc,[x.Decoration.inline(s.queryStartPos()-s.triggerCharacter.length,s.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}}})}onUpdate(t,o){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,o)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}function Yi(e,n){e.suggestionMenus.addTriggerCharacter(n)}let R;function jt(e){R||(R=document.createElement("div"),R.innerHTML="_",R.style.opacity="0",R.style.height="1px",R.style.width="1px",e instanceof Document?e.body.appendChild(R):e.appendChild(R))}function Zi(e){R&&(e instanceof Document?e.body.removeChild(R):e.removeChild(R),R=void 0)}function Le(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Qi(e){let n=e;for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH"&&!n.classList.contains("tableWrapper");){if(n.classList.contains("ProseMirror"))return;const t=n.parentNode;if(!t||!(t instanceof Element))return;n=t}return n.nodeName==="TD"||n.nodeName==="TH"?{type:"cell",domNode:n,tbodyNode:n.closest("tbody")}:{type:"wrapper",domNode:n,tbodyNode:n.querySelector("tbody")}}function ea(e,n){const t=n.querySelectorAll(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class Wo{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"tableId");p(this,"tablePos");p(this,"tableElement");p(this,"menuFrozen",!1);p(this,"mouseState","up");p(this,"prevWasEditable",null);p(this,"viewMousedownHandler",()=>{this.mouseState="down"});p(this,"mouseUpHandler",n=>{this.mouseState="up",this.mouseMoveHandler(n)});p(this,"mouseMoveHandler",n=>{var c,d,u,h,f,m,g;if(this.menuFrozen||this.mouseState==="selecting"||!(n.target instanceof Element)||!this.pmView.dom.contains(n.target))return;const t=Qi(n.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((c=this.state)!=null&&c.draggingState)){this.mouseState="selecting",(d=this.state)!=null&&d.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t||!this.editor.isEditable){(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t.tbodyNode)return;const o=t.tbodyNode.getBoundingClientRect(),r=_o(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(b=>_(r.id,b.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=T(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(ho("table",a,this.editor)&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const l=(h=t.domNode.closest(".tableWrapper"))==null?void 0:h.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const b=n.clientY>=o.bottom-1&&n.clientY<o.bottom+20,y=n.clientX>=o.right-1&&n.clientX<o.right+20,C=n.clientX>o.right||n.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:b,showAddOrRemoveColumnsButton:y,referencePosTable:o,block:s,widgetContainer:l,colIndex:C||(f=this.state)==null?void 0:f.colIndex,rowIndex:C||(m=this.state)==null?void 0:m.rowIndex,referencePosCell:C||(g=this.state)==null?void 0:g.referencePosCell}}else{const b=Le(t.domNode),y=Le(t.domNode.parentElement),C=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===y&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:C,colIndex:b,rowIndex:y,widgetContainer:l}}return this.emitUpdate(),!1});p(this,"dragOverHandler",n=>{var h;if(((h=this.state)==null?void 0:h.draggingState)===void 0)return;n.preventDefault(),n.dataTransfer.dropEffect="move",ea(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const t={left:Math.min(Math.max(n.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(n.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(t.left,t.top).filter(f=>f.tagName==="TD"||f.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Le(r.parentElement),a=Le(r),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,d=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==l;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const u=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==u&&(this.state.draggingState.mousePos=u,s=!0),s&&this.emitUpdate(),d&&this.editor.transact(f=>f.setMeta(le,!0))});p(this,"dropHandler",n=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");n.preventDefault();const{draggingState:t,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!dn(this.state.block,t.originalIndex,r))return!1;const i=Or(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!un(this.state.block,t.originalIndex,o))return!1;const i=Dr(this.state.block,t.originalIndex,o),[a]=s.splice(t.originalIndex,1);s.splice(o,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var r;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:n,width:t}=kt(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=n&&(this.state.rowIndex=n-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){const i=o.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const le=new w.PluginKey("TableHandlesPlugin");class qo extends Z{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"colDragStart",t=>{if(this.view.state===void 0||this.view.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:t.clientX},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(le,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");jt(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(R,0,0),t.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",t=>{if(this.view.state===void 0||this.view.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:t.clientY},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(le,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");jt(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(R,0,0),t.dataTransfer.effectAllowed="copyMove"});p(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(t=>t.setMeta(le,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Zi(this.editor.prosemirrorView.root)});p(this,"freezeHandles",()=>{this.view.menuFrozen=!0});p(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});p(this,"getCellsAtRowHandle",(t,o)=>tt(t,o));p(this,"getCellsAtColumnHandle",(t,o)=>nt(t,o));p(this,"setCellSelection",(t,o,r=o)=>{const s=this.view;if(!s)throw new Error("Table handles view not initialized");const i=t.doc.resolve(s.tablePos+1),a=t.doc.resolve(i.posAtIndex(o.row)+1),l=t.doc.resolve(a.posAtIndex(o.col)),c=t.doc.resolve(i.posAtIndex(r.row)+1),d=t.doc.resolve(c.posAtIndex(r.col)),u=t.tr;return u.setSelection(new P.CellSelection(l,d)),t.apply(u)});p(this,"addRowOrColumn",(t,o)=>{this.editor.exec((r,s)=>{const i=this.setCellSelection(r,o.orientation==="row"?{row:t,col:0}:{row:0,col:t});return o.orientation==="row"?o.side==="above"?P.addRowBefore(i,s):P.addRowAfter(i,s):o.side==="left"?P.addColumnBefore(i,s):P.addColumnAfter(i,s)})});p(this,"removeRowOrColumn",(t,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:t,col:0});return P.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:t});return P.deleteColumn(i,s)}));p(this,"mergeCells",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t.relativeStartCell,t.relativeEndCell):o;return P.mergeCells(s,r)}));p(this,"splitCell",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t):o;return P.splitCell(s,r)}));p(this,"getCellSelection",()=>this.editor.transact(t=>{const o=t.selection;let r=o.$from,s=o.$to;if(at(o)){const{ranges:m}=o;m.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$to)})}else if(r=t.doc.resolve(o.$from.pos-o.$from.parentOffset-1),s=t.doc.resolve(o.$to.pos-o.$to.parentOffset-1),r.pos===0||s.pos===0)return;const i=t.doc.resolve(r.pos-r.parentOffset-1),a=t.doc.resolve(s.pos-s.parentOffset-1),l=t.doc.resolve(i.pos-i.parentOffset-1),c=r.index(i.depth),d=i.index(l.depth),u=s.index(a.depth),h=a.index(l.depth),f=[];for(let m=d;m<=h;m++)for(let g=c;g<=u;g++)f.push({row:m,col:g});return{from:{row:d,col:c},to:{row:h,col:u},cells:f}}));p(this,"getMergeDirection",t=>this.editor.transact(o=>{const r=at(o.selection)?o.selection:void 0;if(!r||!t||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return Vr(s.from,s.to,t)?"vertical":"horizontal"}));p(this,"cropEmptyRowsOrColumns",(t,o)=>Rr(t,o));p(this,"addRowsOrColumns",(t,o,r)=>_r(t,o,r));this.editor=t,this.plugin=new w.Plugin({key:le,view:o=>(this.view=new Wo(t,o,r=>{this.emit("update",r)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const r=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=this.view.state,{originalIndex:l,draggedCellOrientation:c}=a;if(r===l||!i||c==="row"&&!dn(i,l,r)||c==="col"&&!un(i,l,r))return x.DecorationSet.create(o.doc,s);const d=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?tt(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.left="0",C.style.right="0",r>l?C.style.bottom="-2px":C.style.top="-3px",C.style.height="4px",C}))}):nt(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.top="0",C.style.bottom="0",r>l?C.style.right="-2px":C.style.left="-3px",C.style.width="4px",C}))}),x.DecorationSet.create(o.doc,s)}}})}onUpdate(t){return this.on("update",t)}}const ta=k.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment==="left"?{}:{"data-text-alignment":e.textAlignment}}}}]}}),na=k.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:M.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):M.textColor.default,renderHTML:e=>e.textColor===M.textColor.default?{}:{"data-text-color":e.textColor}}}}]}}),oa=k.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new w.PluginKey(this.name);return[new w.Plugin({key:e,appendTransaction:(n,t,o)=>{const{doc:r,tr:s,schema:i}=o,a=e.getState(o),l=r.content.size-2,c=i.nodes.blockContainer,d=i.nodes.paragraph;if(a)return s.insert(l,c.create(void 0,d.create()))},state:{init:(n,t)=>{},apply:(n,t)=>{if(!n.docChanged)return t;let o=n.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const r=o.firstChild;if(!r)throw new Error("Expected blockContent");return o.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),ra={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},sa=k.Node.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:e=>{if(typeof e=="string")return!1;const n={};for(const[t,o]of Object.entries(ra))e.getAttribute(o)&&(n[t]=e.getAttribute(o));return e.getAttribute("data-node-type")==="blockContainer"?n:!1}}]},renderHTML({HTMLAttributes:e}){var r;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(e))s!=="class"&&n.setAttribute(s,i);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...e},o=document.createElement("div");o.className=J("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(t))s!=="class"&&o.setAttribute(s,i);return n.appendChild(o),{dom:n,contentDOM:o}}}),ia=k.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const n={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},t=document.createElement("div");t.className=J("bn-block-group",n.class),t.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);return{dom:t,contentDOM:t}}}),aa=k.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Ko=e=>{const n={},t=la(e);for(const r of t)n[r.name]=r;n.formattingToolbar=new Ao(e.editor),n.linkToolbar=new Do(e.editor),n.sideMenu=new $o(e.editor,e.sideMenuDetection),n.suggestionMenus=new zo(e.editor),n.filePanel=new Po(e.editor),n.placeholder=new Fi(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new $i),e.tableHandles&&(n.tableHandles=new qo(e.editor)),n.dropCursor={plugin:e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})},n.nodeSelectionKeyboard=new _i,n.showSelection=new zi(e.editor),e.comments&&(n.comments=new Li(e.editor,e.comments.threadStore,xo.name));const o=e.disableExtensions||[];for(const r of o)delete n[r];return n};let Gt=!1;const la=e=>{const n=[k.extensions.ClipboardTextSerializer,k.extensions.Commands,k.extensions.Editable,k.extensions.FocusEvents,k.extensions.Tabindex,dr.Gapcursor,ve.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),Ai,hr.Text,pr.Link.extend({inclusive:!1}).configure({defaultProtocol:Ro,protocols:Gt?[]:Oo}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),na,Ti,ta,k.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),aa,sa.configure({editor:e.editor,domAttributes:e.domAttributes}),Di.configure({editor:e.editor,tabBehavior:e.tabBehavior}),ia.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(t=>t.config!=="link"&&t.config!=="text").map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(o=>o.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),Ei(e.editor),Si(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),ii(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[oa]:[],...e.comments?[xo]:[]];return Gt=!0,e.collaboration?n.push(...xi(e.collaboration)):n.push(ur.History),n};function ca(e,n){const t=[];return e.forEach((o,r,s)=>{s!==n&&t.push(o)}),E.Fragment.from(t)}function da(e,n){const t=[];for(let o=0;o<e.childCount;o++)if(e.child(o).type.name==="tableRow")if(t.length>0&&t[t.length-1].type.name==="table"){const r=t[t.length-1],s=r.copy(r.content.addToEnd(e.child(o)));t[t.length-1]=s}else{const r=n.nodes.table.createChecked(void 0,e.child(o));t.push(r)}else t.push(e.child(o));return e=E.Fragment.from(t),e}function ua(e,n){let t=E.Fragment.from(e.content);if(t=da(t,n.state.schema),!pa(t,n))return new E.Slice(t,e.openStart,e.openEnd);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const r=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.name==="blockGroup"){const i=t.child(o+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(t.child(o+1)),t=ca(t,o+1))}const s=n.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(o,s)}return new E.Slice(t,e.openStart,e.openEnd)}function pa(e,n){var s,i;const t=e.childCount===1,o=((s=e.firstChild)==null?void 0:s.type.spec.content)==="inline*",r=((i=e.firstChild)==null?void 0:i.type.spec.content)==="tableRow+";if(t){if(o)return!1;if(r){const a=B(n.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const Fe=class Fe extends k.Editor{constructor(t,o){super({...t,content:void 0});p(this,"_state");p(this,"mount",(t,o,r)=>{o?(this.options.element=o,this.createViewAlternative(t,r)):this.destroy()});const r=this.schema;let s;const i=r.nodes.doc.createAndFill;r.nodes.doc.createAndFill=(...l)=>{if(s)return s;const c=i.apply(r.nodes.doc,l),d=JSON.parse(JSON.stringify(c.toJSON()));return d.content[0].content[0].attrs.id="initialBlockId",s=E.Node.fromJSON(r,d),s};let a;try{const l=t==null?void 0:t.content.map(c=>ne(c,this.schema,o).toJSON());a=k.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(t.content))}this._state=w.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){if(!this.view){this._state=this.state.apply(t);return}if(this.view.isDestroyed)return;if(this.isCapturingTransaction){this.dispatchTransaction(t);return}const{state:o,transactions:r}=this.state.applyTransaction(t),s=!this.state.selection.eq(o.selection);this.emit("beforeTransaction",{editor:this,transaction:t,nextState:o}),this.view.updateState(o),this.emit("transaction",{editor:this,transaction:t}),s&&this.emit("selectionUpdate",{editor:this,transaction:t});const i=t.getMeta("focus"),a=t.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:t}),a&&this.emit("blur",{editor:this,event:a.event,transaction:t}),!(!t.docChanged||t.getMeta("preventUpdate"))&&(this.emit("update",{editor:this,transaction:t}),this.emit("v3-update",{editor:this,transaction:t,appendedTransactions:r.slice(1)}))}createViewAlternative(t,o){this.contentComponent=o;const r={};this.extensionManager.extensions.forEach(i=>{i.type==="mark"&&i.config.addMarkView&&(r[i.name]=i.config.addMarkView(t))}),this.view=new x.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:r,nodeViews:this.extensionManager.nodeViews});const s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.commands.focus(this.options.autofocus||this.options.element.getAttribute("data-bn-autofocus")==="true",{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};p(Fe,"create",(t,o)=>{var s,i;const r=(s=globalThis==null?void 0:globalThis.window)==null?void 0:s.setTimeout;typeof((i=globalThis==null?void 0:globalThis.window)==null?void 0:i.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new Fe(t,o)}finally{r&&(globalThis.window.setTimeout=r)}});let Ve=Fe;Ve.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const ha={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class It extends Z{constructor(t){var c,d,u,h,f,m,g,b,y,C,v,L,q,j,I;super();p(this,"pmSchema");p(this,"extensions",{});p(this,"headless",!1);p(this,"_tiptapEditor");p(this,"elementRenderer",null);p(this,"blockCache",new WeakMap);p(this,"dictionary");p(this,"schema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"formattingToolbar");p(this,"linkToolbar");p(this,"sideMenu");p(this,"suggestionMenus");p(this,"filePanel");p(this,"tableHandles");p(this,"comments");p(this,"showSelectionPlugin");p(this,"uploadFile");p(this,"onUploadStartCallbacks",[]);p(this,"onUploadEndCallbacks",[]);p(this,"resolveFileUrl");p(this,"resolveUsers");p(this,"settings");p(this,"activeTransaction",null);p(this,"mount",(t,o)=>{this._tiptapEditor.mount(this,t,o)});this.options=t;const o=t;if(o.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(o.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(o.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(o.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||br.en,this.settings={tables:{splitCells:((c=t==null?void 0:t.tables)==null?void 0:c.splitCells)??!1,cellBackgroundColor:((d=t==null?void 0:t.tables)==null?void 0:d.cellBackgroundColor)??!1,cellTextColor:((u=t==null?void 0:t.tables)==null?void 0:u.cellTextColor)??!1,headers:((h=t==null?void 0:t.tables)==null?void 0:h.headers)??!1},codeBlock:{indentLineWithTab:((f=t==null?void 0:t.codeBlock)==null?void 0:f.indentLineWithTab)??!0,defaultLanguage:((m=t==null?void 0:t.codeBlock)==null?void 0:m.defaultLanguage)??"text",supportedLanguages:((g=t==null?void 0:t.codeBlock)==null?void 0:g.supportedLanguages)??{},createHighlighter:((b=t==null?void 0:t.codeBlock)==null?void 0:b.createHighlighter)??void 0}};const r={defaultStyles:!0,schema:t.schema||ge.create(),_headless:!1,...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};if(r.comments&&!r.resolveUsers)throw new Error("resolveUsers is required when using comments");if(this.resolveUsers=r.resolveUsers,this.schema=r.schema,this.blockImplementations=r.schema.blockSpecs,this.inlineContentImplementations=r.schema.inlineContentSpecs,this.styleImplementations=r.schema.styleSpecs,this.extensions=Ko({editor:this,domAttributes:r.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:r.collaboration,trailingBlock:r.trailingBlock,disableExtensions:r.disableExtensions,setIdAttribute:r.setIdAttribute,animations:r.animations??!0,tableHandles:D("table",this),dropCursor:this.options.dropCursor??gr.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,sideMenuDetection:r.sideMenuDetection||"viewport",comments:r.comments,pasteHandler:r.pasteHandler}),(((y=r._tiptapOptions)==null?void 0:y.extensions)||[]).forEach(S=>{this.extensions[S.name]=S}),Object.entries(r._extensions||{}).forEach(([S,O])=>{typeof O=="function"&&(O=O(this)),this.extensions[S]=O}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,r.uploadFile){const S=r.uploadFile;this.uploadFile=async(O,ae)=>{this.onUploadStartCallbacks.forEach(Ge=>Ge.apply(this,[ae]));try{return await S(O,ae)}finally{this.onUploadEndCallbacks.forEach(Ge=>Ge.apply(this,[ae]))}}}this.resolveFileUrl=r.resolveFileUrl,this.headless=r._headless;const s="collaboration"in this.extensions||"liveblocksExtension"in this.extensions;s&&r.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const i=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:ve.options.generateID()}]);if(!Array.isArray(i)||i.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+i);const a=[...Object.entries(this.extensions).map(([S,O])=>{if(O instanceof k.Extension||O instanceof k.Node||O instanceof k.Mark)return O;if(!O.plugin)throw new Error("Extension should either be a TipTap extension or a ProseMirror plugin in a plugin property");return k.Extension.create({name:S,addProseMirrorPlugins:()=>[O.plugin]})})],l={...ha,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(C=r._tiptapOptions)==null?void 0:C.editorProps,attributes:{tabIndex:"0",...(L=(v=r._tiptapOptions)==null?void 0:v.editorProps)==null?void 0:L.attributes,...(q=r.domAttributes)==null?void 0:q.editor,class:J("bn-editor",r.defaultStyles?"bn-default-styles":"",((I=(j=r.domAttributes)==null?void 0:j.editor)==null?void 0:I.class)||"")},transformPasted:ua}};this.headless?this.pmSchema=k.getSchema(l.extensions):(this._tiptapEditor=Ve.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new It(t)}exec(t){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,i=>this._tiptapEditor.dispatch(i),r)}canExec(t){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,void 0,r)}transact(t){if(this.activeTransaction)return t(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const o=t(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this._tiptapEditor.dispatch(r),o}finally{this.activeTransaction=null}}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var t;return(t=this.prosemirrorView)==null?void 0:t.dom}isFocused(){var t;return((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}focus(){var t;(t=this.prosemirrorView)==null||t.focus()}onUploadStart(t){return this.onUploadStartCallbacks.push(t),()=>{const o=this.onUploadStartCallbacks.indexOf(t);o>-1&&this.onUploadStartCallbacks.splice(o,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const o=this.onUploadEndCallbacks.indexOf(t);o>-1&&this.onUploadEndCallbacks.splice(o,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(t=>{const o=[];return t.doc.firstChild.descendants(r=>(o.push(T(r,this.pmSchema)),!1)),o})}getBlock(t){return this.transact(o=>$s(o.doc,t))}getPrevBlock(t){return this.transact(o=>zs(o.doc,t))}getNextBlock(t){return this.transact(o=>Ws(o.doc,t))}getParentBlock(t){return this.transact(o=>qs(o.doc,t))}forEachBlock(t,o=!1){const r=this.document.slice();o&&r.reverse();function s(i){for(const a of i){if(t(a)===!1)return!1;const l=o?a.children.slice().reverse():a.children;if(!s(l))return!1}return!0}s(r)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){return this.transact(t=>Xs(t))}setTextCursorPosition(t,o="start"){return this.transact(r=>Co(r,t,o))}getSelection(){return this.transact(t=>js(t))}setSelection(t,o){return this.transact(r=>Gs(r,t,o))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return this._tiptapEditor.isEditable===void 0?!0:this._tiptapEditor.isEditable}set isEditable(t){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return}this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,o,r="before"){return this.transact(s=>Ns(s,t,o,r))}updateBlock(t,o){return this.transact(r=>mn(r,t,o))}removeBlocks(t){return this.transact(o=>Rt(o,t,[]).removedBlocks)}replaceBlocks(t,o){return this.transact(r=>Rt(r,t,o))}insertInlineContent(t){const o=V(t,this.pmSchema);this.transact(r=>{Ks(r,{from:r.selection.from,to:r.selection.to},o)})}getActiveStyles(){return this.transact(t=>{const o={},r=t.selection.$to.marks();for(const s of r){const i=this.schema.styleSchema[s.type.name];if(!i){s.type.name!=="link"&&!s.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",s.type.name);continue}i.propSchema==="boolean"?o[i.type]=!0:o[i.type]=s.attrs.stringValue}return o})}addStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.setMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.setMark(o,{stringValue:r});else throw new U(s.propSchema)}}removeStyles(t){for(const o of Object.keys(t))this._tiptapEditor.commands.unsetMark(o)}toggleStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.toggleMark(o,{stringValue:r});else throw new U(s.propSchema)}}getSelectedText(){return this.transact(t=>t.doc.textBetween(t.selection.from,t.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,o){if(t==="")return;const r=this.pmSchema.mark("link",{href:t});this.transact(s=>{const{from:i,to:a}=s.selection;o?s.insertText(o,i,a).addMark(i,i+o.length,r):s.setSelection(w.TextSelection.create(s.doc,a)).addMark(i,a,r)})}canNestBlock(){return Fs(this)}nestBlock(){yo(this)}canUnnestBlock(){return Us(this)}unnestBlock(){Vs(this)}moveBlocksUp(){return Os(this)}moveBlocksDown(){return Rs(this)}async blocksToHTMLLossy(t=this.document){return Te(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return Cn(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return Tt(t,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return vo(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return Bo(t,this.pmSchema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}onChange(t){if(this.headless)return;const o=({transaction:r,appendedTransactions:s})=>{t(this,{getChanges:()=>hn(r,s)})};return this._tiptapEditor.on("v3-update",o),()=>{this._tiptapEditor.off("v3-update",o)}}onSelectionChange(t,o){if(this.headless)return;const r=s=>{s.transaction.getMeta(oe.ySyncPluginKey)&&!o||t(this)};return this._tiptapEditor.on("selectionUpdate",r),()=>{this._tiptapEditor.off("selectionUpdate",r)}}onCreate(t){return this.on("create",t),()=>{this.off("create",t)}}getSelectionBoundingBox(){var a;if(!this.prosemirrorView)return;const t=(a=this.prosemirrorView)==null?void 0:a.state,{selection:o}=t,{ranges:r}=o,s=Math.min(...r.map(l=>l.$from.pos)),i=Math.max(...r.map(l=>l.$to.pos));if(k.isNodeSelection(o)){const l=this.prosemirrorView.nodeDOM(s);if(l)return l.getBoundingClientRect()}return k.posToDOMRect(this.prosemirrorView,s,i)}get isEmpty(){const t=this.document;return t.length===0||t.length===1&&t[0].type==="paragraph"&&t[0].content.length===0}openSuggestionMenu(t,o){this.prosemirrorView&&(this.focus(),this.transact(r=>{o!=null&&o.deleteTriggerCharacter&&r.insertText(t),r.scrollIntoView().setMeta(this.suggestionMenus.plugin,{triggerCharacter:t,deleteTriggerCharacter:(o==null?void 0:o.deleteTriggerCharacter)||!1,ignoreQueryLength:(o==null?void 0:o.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(t){this.showSelectionPlugin.setEnabled(t)}convertHtmlToBlockNoteHtml(t){return So(t.trim()).innerHTML}pasteHTML(t,o=!1){var s;let r=t;o||(r=this.convertHtmlToBlockNoteHtml(t)),r&&((s=this.prosemirrorView)==null||s.pasteHTML(r))}pasteText(t){var o;return(o=this.prosemirrorView)==null?void 0:o.pasteText(t)}async pasteMarkdown(t){return this.pasteHTML(await xt(t))}}const fa={gray:{text:"#9b9a97",background:"#ebeced"},brown:{text:"#64473a",background:"#e9e5e3"},red:{text:"#e03e3e",background:"#fbe4e4"},orange:{text:"#d9730d",background:"#f6e9d9"},yellow:{text:"#dfab01",background:"#fbf3db"},green:{text:"#4d6461",background:"#ddedea"},blue:{text:"#0b6e99",background:"#ddebf1"},purple:{text:"#6940a5",background:"#eae4f2"},pink:{text:"#ad1a72",background:"#f4dfeb"}},ma={gray:{text:"#bebdb8",background:"#9b9a97"},brown:{text:"#8e6552",background:"#64473a"},red:{text:"#ec4040",background:"#be3434"},orange:{text:"#e3790d",background:"#b7600a"},yellow:{text:"#dfab01",background:"#b58b00"},green:{text:"#6b8b87",background:"#4d6461"},blue:{text:"#0e87bc",background:"#0b6e99"},purple:{text:"#8552d7",background:"#6940a5"},pink:{text:"#da208f",background:"#ad1a72"}};class ga{constructor(n,t,o){this.mappings=t,this.options=o}async resolveFile(n){var o;if(!((o=this.options)!=null&&o.resolveFileUrl))return(await fetch(n)).blob();const t=await this.options.resolveFileUrl(n);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(n){return Object.entries(n).map(([o,r])=>this.mappings.styleMapping[o](r,this))}mapInlineContent(n){return this.mappings.inlineContentMapping[n.type](n,this)}transformInlineContent(n){return n.map(t=>this.mapInlineContent(t))}async mapBlock(n,t,o){return this.mappings.blockMapping[n.type](n,this,t,o)}}function ba(e){return{createBlockMapping:n=>n,createInlineContentMapping:n=>n,createStyleMapping:n=>n}}let Ae;async function ka(){return Ae||(Ae=(async()=>{const[e,n]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),t="default"in e?e.default:e,o="default"in n?n.default:n;return await t.init({data:o}),{emojiMart:t,emojiData:o}})(),Ae)}async function wa(e,n){if(!po("text",e))return[];const{emojiData:t,emojiMart:o}=await ka();return(n.trim()===""?Object.values(t.emojis):await o.SearchIndex.search(n)).map(s=>({id:s.skins[0].native,onItemClick:()=>e.insertInlineContent(s.skins[0].native+" ")}))}function ya(e,...n){const t=[...e];for(const o of n)for(const r of o){const s=t.findLastIndex(i=>i.group===r.group);s===-1?t.push(r):t.splice(s+1,0,r)}return t}exports.AudioBlock=Ln;exports.BlockNoteEditor=It;exports.BlockNoteSchema=ge;exports.COLORS_DARK_MODE_DEFAULT=ma;exports.COLORS_DEFAULT=fa;exports.CodeBlock=Nn;exports.DEFAULT_LINK_PROTOCOL=Ro;exports.EMPTY_CELL_HEIGHT=bs;exports.EMPTY_CELL_WIDTH=Ct;exports.Exporter=ga;exports.FILE_AUDIO_ICON_SVG=En;exports.FILE_ICON_SVG=Sn;exports.FILE_IMAGE_ICON_SVG=Fn;exports.FILE_VIDEO_ICON_SVG=no;exports.FileBlock=Vn;exports.FilePanelProsemirrorPlugin=Po;exports.FilePanelView=Mo;exports.FormattingToolbarProsemirrorPlugin=Ao;exports.FormattingToolbarView=Io;exports.HTMLToBlocks=Tt;exports.ImageBlock=Kn;exports.LinkToolbarProsemirrorPlugin=Do;exports.PageBreak=Yn;exports.SideMenuProsemirrorPlugin=$o;exports.SideMenuView=Fo;exports.SuggestionMenuProseMirrorPlugin=zo;exports.TableHandlesProsemirrorPlugin=qo;exports.TableHandlesView=Wo;exports.UniqueID=ve;exports.UnreachableCaseError=U;exports.VALID_LINK_PROTOCOLS=Oo;exports.VideoBlock=lo;exports.addInlineContentAttributes=et;exports.addInlineContentKeyboardShortcuts=tn;exports.addStyleAttributes=an;exports.applyNonSelectableBlockFix=Zt;exports.assertEmpty=Er;exports.audioBlockConfig=xn;exports.audioParse=Pn;exports.audioPropSchema=Tn;exports.audioRender=Mn;exports.audioToExternalHTML=In;exports.blockToNode=ne;exports.blocksToMarkdown=vo;exports.camelToDataKebab=we;exports.checkBlockHasDefaultProp=xs;exports.checkBlockIsDefaultType=ho;exports.checkBlockIsFileBlock=Bs;exports.checkBlockIsFileBlockWithPlaceholder=Ts;exports.checkBlockIsFileBlockWithPreview=Es;exports.checkBlockTypeHasDefaultProp=fo;exports.checkDefaultBlockTypeInSchema=D;exports.checkDefaultInlineContentTypeInSchema=po;exports.checkPageBreakBlocksInSchema=mo;exports.cleanHTMLToMarkdown=je;exports.combineByGroup=ya;exports.contentNodeToInlineContent=Be;exports.contentNodeToTableContent=ft;exports.createAddFileButton=vn;exports.createBlockSpec=me;exports.createBlockSpecFromStronglyTypedTiptapNode=Y;exports.createDefaultBlockDOMOutputSpec=z;exports.createExternalHTMLExporter=Te;exports.createFigureWithCaption=qe;exports.createFileBlockWrapper=We;exports.createFileNameWithIcon=Bn;exports.createInlineContentSpec=Nr;exports.createInlineContentSpecFromTipTapNode=on;exports.createInternalBlockSpec=pt;exports.createInternalHTMLSerializer=Cn;exports.createInternalInlineContentSpec=nn;exports.createInternalStyleSpec=gt;exports.createLinkWithCaption=Me;exports.createResizableFileBlockWrapper=wt;exports.createStronglyTypedTiptapNode=W;exports.createStyleSpec=Hr;exports.createStyleSpecFromTipTapMark=Q;exports.createSuggestionMenu=Yi;exports.defaultBlockSchema=co;exports.defaultBlockSpecs=vt;exports.defaultBlockToHTML=Qe;exports.defaultCodeBlockPropSchema=An;exports.defaultInlineContentSchema=uo;exports.defaultInlineContentSpecs=Bt;exports.defaultProps=M;exports.defaultStyleSchema=Ss;exports.defaultStyleSpecs=St;exports.fileBlockConfig=Dn;exports.fileParse=Rn;exports.filePropSchema=Hn;exports.fileRender=On;exports.fileToExternalHTML=_n;exports.filenameFromURL=Pr;exports.filterSuggestionItems=Is;exports.formatKeyboardShortcut=G;exports.formattingToolbarPluginKey=Lo;exports.getBlockFromPos=Yt;exports.getBlockInfo=X;exports.getBlockInfoFromResolvedPos=he;exports.getBlockInfoFromSelection=B;exports.getBlockInfoFromTransaction=Ce;exports.getBlockInfoWithManualOffset=Ue;exports.getBlockNoteExtensions=Ko;exports.getBlockSchemaFromSpecs=ht;exports.getBlocksChangedByTransaction=hn;exports.getColspan=pe;exports.getDefaultEmojiPickerItems=wa;exports.getDefaultSlashMenuItems=Ps;exports.getInlineContentParseRules=rn;exports.getInlineContentSchemaFromSpecs=mt;exports.getNearestBlockPos=K;exports.getNodeById=_;exports.getPageBreakSlashMenuItems=As;exports.getParseRules=Qt;exports.getRowspan=Oe;exports.getStyleParseRules=ln;exports.getStyleSchemaFromSpecs=bt;exports.imageBlockConfig=$n;exports.imageParse=Wn;exports.imagePropSchema=Un;exports.imageRender=zn;exports.imageToExternalHTML=qn;exports.inheritedProps=ut;exports.initializeESMDependencies=Ke;exports.inlineContentToNodes=V;exports.insertOrUpdateBlock=H;exports.isAppleOS=Jt;exports.isLinkInlineContent=Ze;exports.isNodeBlock=_e;exports.isPartialLinkInlineContent=dt;exports.isPartialTableCell=ue;exports.isSafari=Mr;exports.isStyledTextInlineContent=ee;exports.isTableCell=$e;exports.isTableCellSelection=at;exports.linkToolbarPluginKey=Ho;exports.mapTableCell=De;exports.mappingFactory=ba;exports.markdownToBlocks=Bo;exports.markdownToHTML=xt;exports.mergeCSSClasses=J;exports.nodeToBlock=T;exports.nodeToCustomInlineContent=Re;exports.pageBreakConfig=jn;exports.pageBreakParse=Xn;exports.pageBreakRender=Gn;exports.pageBreakSchema=Et;exports.pageBreakToExternalHTML=Jn;exports.parseEmbedElement=it;exports.parseFigureElement=xe;exports.propsToAttributes=fe;exports.selectedFragmentToHTML=Pt;exports.shikiHighlighterPromiseSymbol=Ne;exports.shikiParserSymbol=st;exports.sideMenuPluginKey=Uo;exports.stylePropsToAttributes=sn;exports.tableContentToNodes=Ee;exports.tableHandlesPluginKey=le;exports.updateBlock=mn;exports.updateBlockCommand=A;exports.uploadToTmpFilesDotOrg_DEV_ONLY=Gr;exports.videoBlockConfig=ro;exports.videoParse=io;exports.videoPropSchema=oo;exports.videoRender=so;exports.videoToExternalHTML=ao;exports.withPageBreak=Ls;exports.wrapInBlockStructure=ke;
9
+ `),!0):e.chain().command(({tr:r})=>(r.delete(n.pos-2,n.pos),!0)).exitCode().run()},"Shift-Enter":({editor:e})=>{const{$from:n}=e.state.selection;return e.isActive(this.name)?(e.chain().insertContentAt(n.pos-n.parentOffset+n.parent.nodeSize,{type:"paragraph"}).run(),!0):!1}}}}),Vn=Z(Xr,Rn);function Ye(e,n){var t;return(t=Object.entries(e.supportedLanguages).find(([o,{aliases:r}])=>(r==null?void 0:r.includes(n))||o===n))==null?void 0:t[0]}const lt=e=>({url:e.src||void 0}),_n={backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},Un={type:"file",propSchema:_n,content:"none",isFileBlock:!0},Fn=(e,n)=>qe(e,n),$n=e=>{if(e.tagName==="EMBED")return e.closest("figure")?void 0:lt(e);if(e.tagName==="FIGURE"){const n=xe(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...lt(t),caption:o}}},zn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add file",{dom:t}}const n=document.createElement("a");return n.href=e.props.url,n.textContent=e.props.name||e.props.url,e.props.caption?Me(n,e.props.caption):{dom:n}},Wn=fe(Un,{render:Fn,parse:$n,toExternalHTML:zn}),vt=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=qe(e,n,t,r,s),l=i;e.props.url&&e.props.showPreview&&(e.props.previewWidth?l.style.width=`${e.props.previewWidth}px`:l.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";let u,h=e.props.previewWidth;const f=v=>{var F,x;if(!u){!n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d));return}let L;e.props.textAlignment==="center"?u.handleUsed==="left"?L=u.initialWidth+(u.initialClientX-v.clientX)*2:L=u.initialWidth+(v.clientX-u.initialClientX)*2:u.handleUsed==="left"?L=u.initialWidth+u.initialClientX-v.clientX:L=u.initialWidth+v.clientX-u.initialClientX,h=Math.min(Math.max(L,64),((x=(F=n.domElement)==null?void 0:F.firstElementChild)==null?void 0:x.clientWidth)||Number.MAX_VALUE),l.style.width=`${h}px`},m=v=>{(!v.target||!l.contains(v.target)||!n.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),u&&(u=void 0,n.updateBlock(e,{props:{previewWidth:h}}))},g=()=>{n.isEditable&&(o.appendChild(c),o.appendChild(d))},b=v=>{v.relatedTarget===c||v.relatedTarget===d||u||n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},y=v=>{v.preventDefault(),u={handleUsed:"left",initialWidth:l.clientWidth,initialClientX:v.clientX}},C=v=>{v.preventDefault(),u={handleUsed:"right",initialWidth:l.clientWidth,initialClientX:v.clientX}};return window.addEventListener("mousemove",f),window.addEventListener("mouseup",m),l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",b),c.addEventListener("mousedown",y),d.addEventListener("mousedown",C),{dom:l,destroy:()=>{a==null||a(),window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",m),l.removeEventListener("mouseenter",g),l.removeEventListener("mouseleave",b),c.removeEventListener("mousedown",y),d.removeEventListener("mousedown",C)}}},Jr=async e=>{const n=new FormData;return n.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:n})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},_t=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},qn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>',Kn={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},jn={type:"image",propSchema:Kn,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},Gn=(e,n)=>{const t=document.createElement("div");t.innerHTML=qn;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),vt(e,n,{dom:o},o,n.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},Xn=e=>{if(e.tagName==="IMG")return e.closest("figure")?void 0:_t(e);if(e.tagName==="FIGURE"){const n=xe(e,"img");if(!n)return;const{targetElement:t,caption:o}=n;return{..._t(t),caption:o}}},Jn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add image",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("img"),n.src=e.props.url,n.alt=e.props.name||e.props.caption||"BlockNote image",e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ke(n,e.props.caption):Me(n,e.props.caption):{dom:n}},Yn=fe(jn,{render:Gn,parse:Xn,toExternalHTML:Jn}),Zn={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Qn=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},eo=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},to=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},no=fe(Zn,{render:Qn,parse:eo,toExternalHTML:to}),Yr=k.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-background-color")?{stringValue:e.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),Zr=ee(Yr,"string"),Qr=k.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-text-color")?{stringValue:e.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),es=ee(Qr,"string"),oo={...P,level:{default:1,values:[1,2,3]}},ts=K({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return he(oo)},addInputRules(){return[...[1,2,3].map(e=>new k.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:n,chain:t,range:o})=>{const r=E(n);!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||t().command(A(r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:1}}))},"Mod-Alt-2":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:2}}))},"Mod-Alt-3":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"heading",props:{level:3}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:e,HTMLAttributes:n}){var t,o;return q(this.name,`h${e.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),ns=Z(ts,oo);function St(e,n,t){var u,h,f;const o=B.DOMParser.fromSchema(n),r=e,s=document.createElement("div");s.setAttribute("data-node-type","blockGroup");for(const m of Array.from(r.childNodes))s.appendChild(m.cloneNode(!0));let i=o.parse(s,{topNode:n.nodes.blockGroup.create()});((h=(u=i.firstChild)==null?void 0:u.firstChild)==null?void 0:h.type.name)==="checkListItem"&&(i=i.copy(i.content.cut(i.firstChild.firstChild.nodeSize+2)));const a=(f=i.firstChild)==null?void 0:f.firstChild;if(!(a!=null&&a.isTextblock))return B.Fragment.from(i);const l=n.nodes[t].create({},a.content),c=i.content.cut(a.nodeSize+2);if(c.size>0){const m=i.copy(c);return l.content.addToEnd(m)}return l.content}const ro=(e,n,t)=>({state:o,dispatch:r})=>{const s=G(o.doc,e),i=J(s);if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const a=[{type:i.bnBlock.node.type,attrs:t?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:n?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:t?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,a),!0},Bt=e=>{const{blockInfo:n,selectionEmpty:t}=e.transact(s=>({blockInfo:Ce(s),selectionEmpty:s.selection.anchor===s.selection.head}));if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n;return!(r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!t?!1:e._tiptapEditor.commands.first(({state:s,chain:i,commands:a})=>[()=>a.command(()=>r.node.childCount===0?a.command(A(o.beforePos,{type:"paragraph",props:{}})):!1),()=>a.command(()=>r.node.childCount>0?(i().deleteSelection().command(ro(s.selection.from,!0)).run(),!0):!1)])},os={...P},rs=K({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new k.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=E(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Bt(this.options.editor),"Mod-Shift-8":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"?{}:!1},getContent:(e,n)=>St(e,n,this.name),node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return q(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ss=Z(rs,os),so={...P,checked:{default:!1}},is=K({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return he(so)},addInputRules(){return[new k.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=E(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:t.from,to:t.to})}}),new k.InputRule({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=E(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Bt(this.options.editor),"Mod-Shift-9":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"input",getAttrs:e=>typeof e=="string"||e.closest("[data-content-type]")||e.closest("li")?!1:e.type==="checkbox"?{checked:e.checked}:!1,node:"checkListItem"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"){const o=e.querySelector("input[type=checkbox]")||null;return o===null?!1:{checked:o.checked}}return!1},getContent:(e,n)=>St(e,n,this.name),node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:n}){var s,i;const t=document.createElement("input");t.type="checkbox",t.checked=e.attrs.checked,e.attrs.checked&&t.setAttribute("checked","");const{dom:o,contentDOM:r}=q(this.name,"p",{...((s=this.options.domAttributes)==null?void 0:s.blockContent)||{},...n},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{});return o.insertBefore(t,r),{dom:o,contentDOM:r}},addNodeView(){return({node:e,getPos:n,editor:t,HTMLAttributes:o})=>{var d,u;const r=document.createElement("div"),s=document.createElement("div");s.contentEditable="false";const i=document.createElement("input");i.type="checkbox",i.checked=e.attrs.checked,e.attrs.checked&&i.setAttribute("checked","");const a=()=>{if(!t.isEditable){i.checked=!i.checked;return}if(typeof n!="boolean"){const h=G(t.state.doc,n());if(h.node.type.name!=="blockContainer")throw new Error(`Expected blockContainer node, got ${h.node.type.name}`);this.editor.commands.command(A(h.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=q(this.name,"p",{...((d=this.options.domAttributes)==null?void 0:d.blockContent)||{},...o},((u=this.options.domAttributes)==null?void 0:u.inlineContent)||{});if(typeof n!="boolean"){const f="label-"+this.editor.state.doc.resolve(n()).node().attrs.id;i.setAttribute("aria-labelledby",f),c.id=f}return l.removeChild(c),l.appendChild(r),r.appendChild(s),r.appendChild(c),s.appendChild(i),{dom:l,contentDOM:c,destroy:()=>{i.removeEventListener("change",a)}}}}}),as=Z(is,so),ls=new w.PluginKey("numbered-list-indexing"),cs=()=>new w.Plugin({key:ls,appendTransaction:(e,n,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((s,i)=>{var a;if(s.type.name==="blockContainer"&&s.firstChild.type.name==="numberedListItem"){let l=`${s.firstChild.attrs.start||1}`;const c=J({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=o.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=J({posBeforeNode:c.bnBlock.beforePos-d.nodeSize,node:d});if(m.blockNoteType==="numberedListItem"){if(!m.isBlockContainer)throw new Error("impossible");const b=m.blockContent.node.attrs.index;l=(parseInt(b)+1).toString()}}const u=c.blockContent.node,h=u.attrs.index,f=((a=d==null?void 0:d.firstChild)==null?void 0:a.type.name)!=="numberedListItem";if(h!==l||u.attrs.start&&!f){r=!0;const{start:m,...g}=u.attrs;o.setNodeMarkup(c.blockContent.beforePos,void 0,{...g,index:l,...typeof m=="number"&&f&&{start:m}})}}}),r?o:null}}),io={...P,start:{default:void 0,type:"number"}},ds=K({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...he(io),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}},addInputRules(){return[new k.InputRule({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:n,range:t,match:o})=>{const r=E(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem")return;const s=parseInt(o[1]);n().command(A(r.bnBlock.beforePos,{type:"numberedListItem",props:s===1&&{}||{start:s}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Bt(this.options.editor),"Mod-Shift-7":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[cs()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="OL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="OL"){const o=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||o===1?{}:{start:o}}return!1},getContent:(e,n)=>St(e,n,this.name),priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return q(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),us=Z(ds,io),ps={...P},hs=K({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"p",getAttrs:e=>{var n;return typeof e=="string"||!((n=e.textContent)!=null&&n.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var n,t;return q(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),fs=Z(hs,ps),ms={...P},gs=K({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new k.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:n,range:t})=>{const o=E(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(A(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=E(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(A(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"blockquote",node:"quote"}]},renderHTML({HTMLAttributes:e}){var n,t;return q(this.name,"blockquote",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),bs=Z(gs,ms),ks=35,Et=120,ws=31,ys=k.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[I.columnResizing({cellMinWidth:ks,defaultCellMinWidth:Et,View:null}),I.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.insertContent({type:"hardBreak"}),!0):!1,Backspace:()=>{const e=this.editor.state.selection,n=e.empty,t=e.$head.parentOffset===0,o=e.$head.node().type.name==="tableParagraph";return n&&t&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>I.goToNextCell(1)(e,n,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>I.goToNextCell(-1)(e,n,t))}},extendNodeSchema(e){const n={name:e.name,options:e.options,storage:e.storage};return{tableRole:k.callOrReturn(k.getExtensionField(e,"tableRole",n))}}}),Cs={textColor:P.textColor},vs=K({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var n,t;return q(this.name,"table",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:n})=>{var o;class t extends I.TableView{constructor(s,i,a){super(s,i),this.node=s,this.cellMinWidth=i,this.blockContentHTMLAttributes=a;const l=document.createElement("div");l.className=Y("bn-block-content",a.class),l.setAttribute("data-content-type","table");for(const[h,f]of Object.entries(a))h!=="class"&&l.setAttribute(h,f);const c=this.dom,d=document.createElement("div");d.className="tableWrapper-inner",d.appendChild(c.firstChild),c.appendChild(d),l.appendChild(c);const u=document.createElement("div");u.className="table-widgets-container",u.style.position="relative",c.appendChild(u),this.dom=l}ignoreMutation(s){return!s.target.closest(".tableWrapper-inner")||super.ignoreMutation(s)}}return new t(e,Et,{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...n})}}}),Ss=K({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p",getAttrs:e=>{if(typeof e=="string"||!e.textContent||!e.closest("[data-content-type]"))return!1;const n=e.parentElement;return n===null?!1:n.tagName==="TD"||n.tagName==="TH"?{}:!1},node:"tableParagraph"}]},renderHTML({HTMLAttributes:e}){return["p",e,0]}});function Ut(e,n){const o=B.DOMParser.fromSchema(n).parse(e,{topNode:n.nodes.blockGroup.create()}),r=[];return o.content.descendants(s=>{if(s.isInline)return r.push(s),!1}),B.Fragment.fromArray(r)}const Bs=Z(vs,Cs,[ys,Ss,hr.TableHeader.extend({content:"tableContent+",parseHTML(){return[{tag:"th",getContent:(e,n)=>Ut(e,n)}]}}),pr.TableCell.extend({content:"tableContent+",parseHTML(){return[{tag:"td",getContent:(e,n)=>Ut(e,n)}]}}),fr.TableRow]),Ft=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},ao='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>',lo={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},co={type:"video",propSchema:lo,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},uo=(e,n)=>{const t=document.createElement("div");t.innerHTML=ao;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),vt(e,n,{dom:o},o,n.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},po=e=>{if(e.tagName==="VIDEO")return e.closest("figure")?void 0:Ft(e);if(e.tagName==="FIGURE"){const n=xe(e,"video");if(!n)return;const{targetElement:t,caption:o}=n;return{...Ft(t),caption:o}}},ho=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add video",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("video"),n.src=e.props.url,e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ke(n,e.props.caption):Me(n,e.props.caption):{dom:n}},fo=fe(co,{render:uo,parse:po,toExternalHTML:ho}),Tt={paragraph:fs,heading:ns,quote:bs,codeBlock:Vn,bulletListItem:ss,numberedListItem:us,checkListItem:as,table:Bs,file:Wn,image:Yn,video:fo,audio:On},mo=gt(Tt),xt={bold:ee(Cr.default,"boolean"),italic:ee(Sr.default,"boolean"),underline:ee(Er.default,"boolean"),strike:ee(Br.default,"boolean"),code:ee(vr.default,"boolean"),textColor:es,backgroundColor:Zr},Es=yt(xt),Mt={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},go=kt(Mt);function O(e,n){return e in n.schema.blockSchema&&n.schema.blockSchema[e]===mo[e]}function bo(e,n){return e in n.schema.inlineContentSchema&&n.schema.inlineContentSchema[e]===go[e]}function ko(e,n,t){return n.type===e&&n.type in t.schema.blockSchema&&O(n.type,t)}function Ts(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock||!1}function xs(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock&&"showPreview"in n.schema.blockSchema[e.type].propSchema||!1}function Ms(e,n){return n.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function wo(e,n,t){return n in t.schema.blockSchema&&e in t.schema.blockSchema[n].propSchema&&t.schema.blockSchema[n].propSchema[e]===P[e]}function Ps(e,n,t){return wo(e,n.type,t)}function ct(e){return e instanceof I.CellSelection}function Is(e){let n=e.getTextCursorPosition().block,t=e.schema.blockSchema[n.type].content;for(;t==="none";){if(n=e.getTextCursorPosition().nextBlock,n===void 0)return;t=e.schema.blockSchema[n.type].content,e.setTextCursorPosition(n,"end")}}function H(e,n){const t=e.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(t.content)&&(t.content.length===1&&te(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?(o=e.updateBlock(t,n),e.setTextCursorPosition(o)):(o=e.insertBlocks([n],t,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),Is(e),o}function Ls(e){const n=[];return O("heading",e)&&n.push({onItemClick:()=>{H(e,{type:"heading",props:{level:1}})},badge:X("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{H(e,{type:"heading",props:{level:2}})},badge:X("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{H(e,{type:"heading",props:{level:3}})},badge:X("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),O("quote",e)&&n.push({onItemClick:()=>{H(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),O("numberedListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"numberedListItem"})},badge:X("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),O("bulletListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"bulletListItem"})},badge:X("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),O("checkListItem",e)&&n.push({onItemClick:()=>{H(e,{type:"checkListItem"})},badge:X("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),O("paragraph",e)&&n.push({onItemClick:()=>{H(e,{type:"paragraph"})},badge:X("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),O("codeBlock",e)&&n.push({onItemClick:()=>{H(e,{type:"codeBlock"})},badge:X("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),O("table",e)&&n.push({onItemClick:()=>{H(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),O("image",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"image"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"image",...e.dictionary.slash_menu.image}),O("video",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"video"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"video",...e.dictionary.slash_menu.video}),O("audio",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"audio"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),O("file",e)&&n.push({onItemClick:()=>{const t=H(e,{type:"file"});e.transact(o=>o.setMeta(e.filePanel.plugin,{block:t}))},key:"file",...e.dictionary.slash_menu.file}),n.push({onItemClick:()=>{e.openSuggestionMenu(":",{deleteTriggerCharacter:!0,ignoreQueryLength:!0})},key:"emoji",...e.dictionary.slash_menu.emoji}),n}function As(e,n){return e.filter(({title:t,aliases:o})=>t.toLowerCase().includes(n.toLowerCase())||o&&o.filter(r=>r.toLowerCase().includes(n.toLowerCase())).length!==0)}function Ze(e){return e&&Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}class me{constructor(n){p(this,"blockSpecs");p(this,"inlineContentSpecs");p(this,"styleSpecs");p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"BlockNoteEditor","only for types");p(this,"Block","only for types");p(this,"PartialBlock","only for types");this.blockSpecs=Ze(n==null?void 0:n.blockSpecs)||Tt,this.inlineContentSpecs=Ze(n==null?void 0:n.inlineContentSpecs)||Mt,this.styleSpecs=Ze(n==null?void 0:n.styleSpecs)||xt,this.blockSchema=gt(this.blockSpecs),this.inlineContentSchema=kt(this.inlineContentSpecs),this.styleSchema=yt(this.styleSpecs)}static create(n){return new me(n)}}const Pt=me.create({blockSpecs:{pageBreak:no}}),Ns=e=>me.create({blockSpecs:{...e.blockSpecs,...Pt.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function yo(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===Pt.blockSchema.pageBreak}function Hs(e){const n=[];return yo(e)&&n.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{H(e,{type:"pageBreak"})},key:"page_break"}),n}function Ds(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=N(e),i=n.map(d=>oe(d,s)),a=_(r,e.doc);if(!a)throw new Error(`Block with ID ${r} not found`);let l=a.posBeforeNode;return o==="after"&&(l+=a.node.nodeSize),e.step(new ce.ReplaceStep(l,l,new B.Slice(B.Fragment.from(i),0,0))),i.map(d=>T(d,s))}function Os(e){return e.transact(n=>{const t=G(n.doc,n.selection.anchor);if(n.selection instanceof I.CellSelection)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:n.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:n.selection.$headCell.pos-t.posBeforeNode};if(n.selection instanceof w.NodeSelection)return{type:"node",anchorBlockId:t.node.attrs.id};{const o=G(n.doc,n.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:o.node.attrs.id,anchorOffset:n.selection.anchor-t.posBeforeNode,headOffset:n.selection.head-o.posBeforeNode}}})}function Rs(e,n){var r,s;const t=(r=_(n.anchorBlockId,e.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let o;if(n.type==="cell")o=I.CellSelection.create(e.doc,t+n.anchorCellOffset,t+n.headCellOffset);else if(n.type==="node")o=w.NodeSelection.create(e.doc,t+1);else{const i=(s=_(n.headBlockId,e.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${n.headBlockId} to update selection`);o=w.TextSelection.create(e.doc,t+n.anchorOffset,i+n.headOffset)}e.setSelection(o)}function dt(e){return e.map(n=>n.type==="columnList"?n.children.map(t=>dt(t.children)).flat():{...n,children:dt(n.children)}).flat()}function Co(e,n,t){e.transact(o=>{var i;const r=((i=e.getSelection())==null?void 0:i.blocks)||[e.getTextCursorPosition().block],s=Os(e);e.removeBlocks(r),e.insertBlocks(dt(r),n,t),Rs(o,s)})}function vo(e){return!e||e.type!=="columnList"}function So(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[n.children.length-1],r="after"):(o=n,r="before"):t&&(o=t,r="before"),!o||!r)return;const s=e.getParentBlock(o);return vo(s)?{referenceBlock:o,placement:r}:So(e,r==="after"?o:e.getPrevBlock(o),s)}function Bo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[0],r="before"):(o=n,r="after"):t&&(o=t,r="after"),!o||!r)return;const s=e.getParentBlock(o);return vo(s)?{referenceBlock:o,placement:r}:Bo(e,r==="before"?o:e.getNextBlock(o),s)}function Vs(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[0])||e.getTextCursorPosition().block,o=So(e,e.getPrevBlock(t),e.getParentBlock(t));o&&Co(e,o.referenceBlock,o.placement)})}function _s(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[(n==null?void 0:n.blocks.length)-1])||e.getTextCursorPosition().block,o=Bo(e,e.getNextBlock(t),e.getParentBlock(t));o&&Co(e,o.referenceBlock,o.placement)})}function Us(e,n){return function(t,o){const{$from:r,$to:s}=t.selection,i=r.blockRange(s,d=>d.childCount>0&&(d.type.name==="blockGroup"||d.type.name==="column"));if(!i)return!1;const a=i.startIndex;if(a===0)return!1;const c=i.parent.child(a-1);if(c.type!==e)return!1;if(o){const d=c.lastChild&&c.lastChild.type===n,u=B.Fragment.from(d?e.create():null),h=new B.Slice(B.Fragment.from(e.create(null,B.Fragment.from(n.create(null,u)))),d?3:1,0),f=i.start,m=i.end;o(t.tr.step(new ce.ReplaceAroundStep(f-(d?3:1),m,f,m,h,1,!0)).scrollIntoView())}return!0}}function Eo(e){return e.exec((n,t)=>Us(n.schema.nodes.blockContainer,n.schema.nodes.blockGroup)(n,t))}function Fs(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function $s(e){return e.transact(n=>{const{bnBlock:t}=Ce(n);return n.doc.resolve(t.beforePos).nodeBefore!==null})}function zs(e){return e.transact(n=>{const{bnBlock:t}=Ce(n);return n.doc.resolve(t.beforePos).depth>1})}function $t(e,n,t){const o=N(e),r=t.map(d=>oe(d,o)),s=new Set(n.map(d=>typeof d=="string"?d:d.id)),i=[],a=typeof n[0]=="string"?n[0]:n[0].id;let l=0;if(e.doc.descendants((d,u)=>{if(s.size===0)return!1;if(!d.type.isInGroup("bnBlock")||!s.has(d.attrs.id))return!0;if(i.push(T(d,o)),s.delete(d.attrs.id),t.length>0&&d.attrs.id===a){const g=e.doc.nodeSize;e.insert(u,r);const b=e.doc.nodeSize;l+=g-b}const h=e.doc.nodeSize,f=e.doc.resolve(u-l);f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?e.delete(f.before(),f.after()):e.delete(u-l,u-l+d.nodeSize);const m=e.doc.nodeSize;return l+=h-m,!1}),s.size>0){const d=[...s].join(`
10
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+d)}return{insertedBlocks:r.map(d=>T(d,o)),removedBlocks:i}}function Ws(e,n){const t=typeof n=="string"?n:n.id,o=N(e),r=_(t,e);if(r)return T(r.node,o)}function qs(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e),r=N(e);if(!o)return;const i=e.resolve(o.posBeforeNode).nodeBefore;if(i)return T(i,r)}function Ks(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e),r=N(e);if(!o)return;const i=e.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return T(i,r)}function js(e,n){const t=typeof n=="string"?n:n.id,o=N(e),r=_(t,e);if(!r)return;const s=e.resolve(r.posBeforeNode),i=s.node(),a=s.node(-1),l=a.type.name!=="doc"?i.type.name==="blockGroup"?a:i:void 0;if(l)return T(l,o)}function Gs(e,n,t,o={updateSelection:!0}){let{from:r,to:s}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},i=!0,a=!0,l="";if(t.forEach(c=>{c.check(),i&&c.isText&&c.marks.length===0?l+=c.text:i=!1,a=a?c.isBlock:!1}),r===s&&a){const{parent:c}=e.doc.resolve(r);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(r-=1,s+=1)}return i?e.insertText(l,r,s):e.replaceWith(r,s,t),o.updateSelection&&k.selectionToInsertionEnd(e,e.steps.length-1,-1),!0}function Xs(e){const n=N(e);if(e.selection.empty||"node"in e.selection)return;const t=e.doc.resolve(G(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(G(e.doc,e.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),h=e.doc.resolve(u).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${u}`);return T(h,n)},s=[],i=t.sharedDepth(o.pos),a=t.index(i),l=o.index(i);if(t.depth>i){s.push(T(t.nodeAfter,n));for(let c=t.depth;c>i;c--)if(t.node(c).type.isInGroup("childContainer")){const u=t.index(c)+1,h=t.node(c).childCount;for(let f=u;f<h;f++)s.push(r(f,c))}}else s.push(r(a,i));for(let c=a+1;c<=l;c++)s.push(r(c,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:s}}function Js(e,n,t){const o=typeof n=="string"?n:n.id,r=typeof t=="string"?t:t.id,s=N(e),i=Se(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const a=_(o,e.doc);if(!a)throw new Error(`Block with ID ${o} not found`);const l=_(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const c=J(a),d=J(l),u=i.blockSchema[c.blockNoteType],h=i.blockSchema[d.blockNoteType];if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!d.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let f,m;if(u.content==="table"){const g=I.TableMap.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(h.content==="table"){const g=I.TableMap.get(d.blockContent.node),b=d.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,d.blockContent.node)+1,y=e.doc.resolve(b).nodeAfter.nodeSize;m=b+y-2}else m=d.blockContent.afterPos-1;e.setSelection(w.TextSelection.create(e.doc,f,m))}function Ys(e){const{bnBlock:n}=Ce(e),t=N(e.doc),o=e.doc.resolve(n.beforePos),r=o.nodeBefore,s=e.doc.resolve(n.afterPos).nodeAfter;let i;return o.depth>1&&(i=o.node(),i.type.isInGroup("bnBlock")||(i=o.node(o.depth-1))),{block:T(n.node,t),prevBlock:r===null?void 0:T(r,t),nextBlock:s===null?void 0:T(s,t),parentBlock:i===void 0?void 0:T(i,t)}}function To(e,n,t="start"){const o=typeof n=="string"?n:n.id,r=N(e.doc),s=Se(r),i=_(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const a=J(i),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){e.setSelection(w.NodeSelection.create(e.doc,c.beforePos));return}if(l==="inline")t==="start"?e.setSelection(w.TextSelection.create(e.doc,c.beforePos+1)):e.setSelection(w.TextSelection.create(e.doc,c.afterPos-1));else if(l==="table")t==="start"?e.setSelection(w.TextSelection.create(e.doc,c.beforePos+4)):e.setSelection(w.TextSelection.create(e.doc,c.afterPos-4));else throw new z(l)}else{const c=t==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;To(e,c.attrs.id,t)}}exports.esmDependencies=void 0;async function je(){if(exports.esmDependencies)return exports.esmDependencies;const e=await Promise.all([import("rehype-parse"),import("rehype-stringify"),import("unified"),import("hast-util-from-dom"),import("rehype-remark"),import("remark-gfm"),import("remark-stringify"),import("remark-parse"),import("remark-rehype"),import("rehype-format")]);return exports.esmDependencies={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},exports.esmDependencies}function Zs(){const e=n=>{let t=n.children.length;for(let o=0;o<t;o++){const r=n.children[o];if(r.type==="element"&&(e(r),r.tagName==="u"))if(r.children.length>0){n.children.splice(o,1,...r.children);const s=r.children.length-1;t+=s,o+=s}else n.children.splice(o,1),t--,o--}};return e}function Qs(){const e=exports.esmDependencies;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const n=t=>{var o;if(t.children&&"length"in t.children&&t.children.length)for(let r=t.children.length-1;r>=0;r--){const s=t.children[r],i=r+1<t.children.length?t.children[r+1]:void 0;s.type==="element"&&s.tagName==="input"&&((o=s.properties)==null?void 0:o.type)==="checkbox"&&(i==null?void 0:i.type)==="element"&&i.tagName==="p"?(i.tagName="span",i.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):n(s)}};return n}function Ge(e){const n=exports.esmDependencies;if(!n)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return n.unified.unified().use(n.rehypeParse.default,{fragment:!0}).use(Zs).use(Qs).use(n.rehypeRemark.default).use(n.remarkGfm.default).use(n.remarkStringify.default,{handlers:{text:o=>o.value}}).processSync(e).value}async function xo(e,n,t,o){await je();const s=Te(n,t).exportBlocks(e,o);return Ge(s)}function ei(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function ti(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function ni(e){e.querySelectorAll("li > ul, li > ol").forEach(n=>{const t=ei(n),o=n.parentElement,r=Array.from(o.childNodes).slice(t+1);n.remove(),r.forEach(s=>{s.remove()}),o.insertAdjacentElement("afterend",n),r.reverse().forEach(s=>{if(ti(s))return;const i=document.createElement("li");i.append(s),n.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function oi(e){e.querySelectorAll("li + ul, li + ol").forEach(n=>{var s,i;const t=n.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),o.append(r);((s=o.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=o.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(o.nextElementSibling)})}let zt=null;function ri(){return zt||(zt=document.implementation.createHTMLDocument("title"))}function Mo(e){if(typeof e=="string"){const n=ri().createElement("div");n.innerHTML=e,e=n}return ni(e),oi(e),e}async function It(e,n){const t=Mo(e),r=B.DOMParser.fromSchema(n).parse(t,{topNode:n.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(T(r.child(i),n));return s}function si(e,n){const t=n.value?n.value:"",o={};n.lang&&(o["data-language"]=n.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return n.meta&&(r.data={meta:n.meta}),e.patch(n,r),r=e.applyData(n,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(n,r),r}async function Lt(e){const n=await je();return n.unified.unified().use(n.remarkParse.default).use(n.remarkGfm.default).use(n.remarkRehype.default,{handlers:{...n.remarkRehype.defaultHandlers,code:si}}).use(n.rehypeStringify.default).processSync(e).value}async function Po(e,n){const t=await Lt(e);return It(t,n)}const At=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function ii(e,n){if(!e.startsWith(".")||!n.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===n}function ai(e,n){const t=e.split("/"),o=n.split("/");if(t.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${n} is not a valid MIME type.`);return t[1]==="*"||o[1]==="*"?t[0]===o[0]:(t[0]==="*"||o[0]==="*"||t[0]===o[0])&&t[1]===o[1]}function Wt(e,n,t){let o;return Array.isArray(n.content)&&n.content.length===0?o=e.updateBlock(n,t).id:o=e.insertBlocks([t],n,"after")[0].id,o}async function Io(e,n){var i;if(!n.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const t="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(t===null)return;let o=null;for(const a of At)if(t.types.includes(a)){o=a;break}if(o!=="Files")return;const r=t.items;if(!r)return;e.preventDefault();const s=Object.values(n.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<r.length;a++){let l="file";for(const d of s)for(const u of d.fileBlockAccept||[]){const h=u.startsWith("."),f=r[a].getAsFile();if(f&&(!h&&f.type&&ai(r[a].type,u)||h&&ii("."+f.name.split(".").pop(),u))){l=d.type;break}}const c=r[a].getAsFile();if(c){const d={type:l,props:{name:c.name}};let u;if(e.type==="paste"){const m=n.getTextCursorPosition().block;u=Wt(n,m,d)}else if(e.type==="drop"){const m={left:e.clientX,top:e.clientY},g=(i=n.prosemirrorView)==null?void 0:i.posAtCoords(m);if(!g)return;u=n.transact(b=>{const y=G(b.doc,g.pos);return Wt(n,n.getBlock(y.node.attrs.id),d)})}else return;const h=await n.uploadFile(c,u),f=typeof h=="string"?{props:{url:h}}:{...h};n.updateBlock(u,f)}}}const li=e=>k.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{drop(n,t){if(!e.isEditable)return;let o=null;for(const r of At)if(t.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(Io(t,e),!0):!1}}}})]}}),ci=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,di=new RegExp("(?:\\s|^)(_|__|\\*|\\*\\*|~~|==|\\+\\+)(?!\\s).{1,64}(?<!\\s)(?=\\1)"),ui=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,pi=new RegExp("(?:\\s|^)`(?!\\s)[^`]{1,48}(?<!\\s)`([^\\w]|$)"),hi=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,fi=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,mi=/\n{2} {0,3}-{2,48}\n{2}/,gi=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,bi=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,ki=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,wi=/^\s*\|(.+\|)+\s*$/m,yi=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,Ci=/^\s*\|(.+\|)+\s*$/m,vi=e=>ci.test(e)||di.test(e)||ui.test(e)||pi.test(e)||hi.test(e)||fi.test(e)||mi.test(e)||gi.test(e)||bi.test(e)||ki.test(e)||wi.test(e)||yi.test(e)||Ci.test(e);async function Si(e,n){const{schema:t}=n.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!t.nodes.codeBlock)return n.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;return i?(n.pasteHTML(`<pre><code class="language-${i}">${o.replace(/\r\n?/g,`
11
+ `)}</code></pre>`),!0):!1}function Bi({event:e,editor:n,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:o}){var a;if(n.transact(l=>l.selection.$from.parent.type.spec.code&&l.selection.$to.parent.type.spec.code)){const l=(a=e.clipboardData)==null?void 0:a.getData("text/plain");if(l)return n.pasteText(l),!0}let s;for(const l of At)if(e.clipboardData.types.includes(l)){s=l;break}if(!s)return!0;if(s==="vscode-editor-data")return Si(e,n.prosemirrorView),!0;if(s==="Files")return Io(e,n),!0;const i=e.clipboardData.getData(s);if(s==="blocknote/html")return n.pasteHTML(i,!0),!0;if(s==="text/markdown")return n.pasteMarkdown(i),!0;if(t){const l=e.clipboardData.getData("text/plain");if(vi(l))return n.pasteMarkdown(l),!0}return s==="text/html"?(n.pasteHTML(i),!0):o?(n.pasteMarkdown(i),!0):(n.pasteText(i),!0)}const Ei=(e,n)=>k.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{paste(t,o){if(o.preventDefault(),!!e.isEditable)return n({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>Bi({event:o,editor:e,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function Lo(e){const n=[];return e.descendants(t=>{var r,s;const o=N(t);return t.type.name==="blockContainer"&&((r=t.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:t.type.name==="columnList"&&t.childCount===1?((s=t.firstChild)==null||s.forEach(i=>{n.push(T(i,o))}),!1):t.type.isInGroup("bnBlock")?(n.push(T(t,o)),!1):!0}),n}function Ti(e,n,t){var a;let o=!1;const r=e.state.selection instanceof I.CellSelection;if(!r){const l=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,c=[];for(let d=0;d<l.childCount;d++)c.push(l.child(d));o=c.find(d=>d.type.isInGroup("bnBlock")||d.type.name==="blockGroup"||d.type.spec.group==="blockContent")===void 0,o&&(n=l)}let s;const i=Te(e.state.schema,t);if(r){((a=n.firstChild)==null?void 0:a.type.name)==="table"&&(n=n.firstChild.content);const l=bt(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=Be(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=Lo(n);s=i.exportBlocks(l,{})}return s}function Nt(e,n){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&n.transact(i=>i.setSelection(new w.NodeSelection(i.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=Ti(e,o,n),s=Ge(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const qt=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let n=e.focusNode;for(;n;){if(n instanceof HTMLElement&&n.getAttribute("contenteditable")==="false")return!0;n=n.parentElement}return!1},Kt=(e,n,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Nt(n,e);t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},xi=e=>k.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{copy(n,t){return qt()||Kt(e,n,t),!0},cut(n,t){return qt()||(Kt(e,n,t),n.editable&&n.dispatch(n.state.tr.deleteSelection())),!0},dragstart(n,t){if(!("node"in n.state.selection)||n.state.selection.node.type.spec.group!=="blockContent")return;e.transact(i=>i.setSelection(new w.NodeSelection(i.doc.resolve(n.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Nt(n,e);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),Mi=k.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:P.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):P.backgroundColor.default,renderHTML:e=>e.backgroundColor===P.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]}}),Ue=class Ue{constructor(n){p(this,"plugin");p(this,"provider");p(this,"recentlyUpdatedCursors");p(this,"renderCursor",(n,t)=>{let o=this.recentlyUpdatedCursors.get(t);if(!o){const r=(this.collaboration.renderCursor??Ue.defaultCursorRender)(n);this.collaboration.showCursorLabels!=="always"&&(r.addEventListener("mouseenter",()=>{const s=this.recentlyUpdatedCursors.get(t);s.element.setAttribute("data-active",""),s.hideTimeout&&(clearTimeout(s.hideTimeout),this.recentlyUpdatedCursors.set(t,{element:s.element,hideTimeout:void 0}))}),r.addEventListener("mouseleave",()=>{const s=this.recentlyUpdatedCursors.get(t);this.recentlyUpdatedCursors.set(t,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)})})),o={element:r,hideTimeout:void 0},this.recentlyUpdatedCursors.set(t,o)}return o.element});p(this,"updateUser",n=>{this.provider.awareness.setLocalStateField("user",n)});this.collaboration=n,this.provider=n.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",n.user),n.showCursorLabels!=="always"&&this.provider.awareness.on("change",({updated:t})=>{for(const o of t){const r=this.recentlyUpdatedCursors.get(o);r&&(r.element.setAttribute("data-active",""),r.hideTimeout&&clearTimeout(r.hideTimeout),this.recentlyUpdatedCursors.set(o,{element:r.element,hideTimeout:setTimeout(()=>{r.element.removeAttribute("data-active")},2e3)}))}}),this.plugin=V.yCursorPlugin(this.provider.awareness,{selectionBuilder:V.defaultSelectionBuilder,cursorBuilder:this.renderCursor})}get priority(){return 999}};p(Ue,"defaultCursorRender",n=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base");const o=document.createElement("span");o.setAttribute("contentedEditable","false"),o.classList.add("bn-collaboration-cursor__caret"),o.setAttribute("style",`background-color: ${n.color}`);const r=document.createElement("span");return r.classList.add("bn-collaboration-cursor__label"),r.setAttribute("style",`background-color: ${n.color}`),r.insertBefore(document.createTextNode(n.name),null),o.insertBefore(r,null),t.insertBefore(document.createTextNode("⁠"),null),t.insertBefore(o,null),t.insertBefore(document.createTextNode("⁠"),null),t});let ut=Ue;class Pi{constructor(){p(this,"plugin");this.plugin=V.yUndoPlugin()}get priority(){return 1e3}}class Ii{constructor(n){p(this,"plugin");this.plugin=V.ySyncPlugin(n)}get priority(){return 1001}}const Ao=k.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}},renderHTML({HTMLAttributes:e}){return["span",k.mergeAttributes(e,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(e){return e.name==="comment"?{blocknoteIgnore:!0}:{}}});class Q{constructor(){p(this,"callbacks",{})}on(n,t){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(t),()=>this.off(n,t)}emit(n,...t){const o=this.callbacks[n];o&&o.forEach(r=>r.apply(this,t))}off(n,t){const o=this.callbacks[n];o&&(t?this.callbacks[n]=o.filter(r=>r!==t):delete this.callbacks[n])}removeAllListeners(){this.callbacks={}}}class Li extends Q{constructor(t){super();p(this,"userCache",new Map);p(this,"loadingUsers",new Set);this.resolveUsers=t}async loadUsers(t){const o=t.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(o.length!==0){for(const r of o)this.loadingUsers.add(r);try{const r=await this.resolveUsers(o);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of o)this.loadingUsers.delete(r)}}}getUser(t){return this.userCache.get(t)}subscribe(t){return this.on("update",t)}}const Pe=new w.PluginKey("blocknote-comments"),Ai="SET_SELECTED_THREAD_ID";function Ni(e,n){const t=new Map;return e.descendants((o,r)=>{o.marks.forEach(s=>{if(s.type.name===n){const i=s.attrs.threadId;if(!i)return;const a=r,l=a+o.nodeSize,c=t.get(i)??{from:1/0,to:0};t.set(i,{from:Math.min(a,c.from),to:Math.max(l,c.to)})}})}),t}class Hi extends Q{constructor(t,o,r){super();p(this,"plugin");p(this,"userStore");p(this,"pendingComment",!1);p(this,"selectedThreadId");p(this,"threadPositions",new Map);p(this,"updateMarksFromThreads",t=>{this.editor.transact(o=>{o.doc.descendants((r,s)=>{r.marks.forEach(i=>{if(i.type.name===this.markType){const a=i.type,l=i.attrs.threadId,c=t.get(l),d=!!(!c||c.resolved||c.deletedAt);if(d!==i.attrs.orphan){const u=Math.max(s,0),h=Math.min(s+r.nodeSize,o.doc.content.size-1);o.removeMark(u,h,i),o.addMark(u,h,a.create({...i.attrs,orphan:d})),d&&this.selectedThreadId===l&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})});if(this.editor=t,this.threadStore=o,this.markType=r,!t.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new Li(t.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),t.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),t.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const s=this;this.plugin=new w.Plugin({key:Pe,state:{init(){return{decorations:M.DecorationSet.empty}},apply(i,a){const l=i.getMeta(Pe);if(!i.docChanged&&!l)return a;const c=i.docChanged?Ni(i.doc,s.markType):s.threadPositions;(c.size>0||s.threadPositions.size>0)&&(s.threadPositions=c,s.emitStateUpdate());const d=[];if(s.selectedThreadId){const u=c.get(s.selectedThreadId);u&&d.push(M.Decoration.inline(u.from,u.to,{class:"bn-thread-mark-selected"}))}return{decorations:M.DecorationSet.create(i.doc,d)}}},props:{decorations(i){var a;return((a=Pe.getState(i))==null?void 0:a.decorations)??M.DecorationSet.empty},handleClick:(i,a,l)=>{if(l.button!==0)return;const c=i.state.doc.nodeAt(a);if(!c){s.selectThread(void 0);return}const d=c.marks.find(h=>h.type.name===r&&h.attrs.orphan!==!0),u=d==null?void 0:d.attrs.threadId;s.selectThread(u,!1)}}})}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(t){return this.on("update",t)}selectThread(t,o=!0){var r,s;if(this.selectedThreadId!==t&&(this.selectedThreadId=t,this.emitStateUpdate(),this.editor.transact(i=>i.setMeta(Pe,{name:Ai})),t&&o)){const i=this.threadPositions.get(t);if(!i)return;(s=(r=this.editor.prosemirrorView)==null?void 0:r.domAtPos(i.from).node)==null||s.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(t){const o=await this.threadStore.createThread(t);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=V.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?V.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:o.id,selection:a})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:o.id})}}class No{constructor(n,t,o,r){p(this,"state");p(this,"emitUpdate");p(this,"mouseDownHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"dragstartHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;if((n=this.state)!=null&&n.show){const t=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!t)return;this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate()}});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pluginKey=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var a,l;const o=this.pluginKey.getState(n.state),r=this.pluginKey.getState(t);if(!((a=this.state)!=null&&a.show)&&(o!=null&&o.block)&&this.editor.isEditable){const c=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!c)return;this.state={show:!0,referencePos:c.getBoundingClientRect(),block:o.block},this.emitUpdate();return}const s=(o==null?void 0:o.block)&&!(r!=null&&r.block),i=!(o!=null&&o.block)&&(r==null?void 0:r.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),i&&((l=this.state)!=null&&l.show)&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const Qe=new w.PluginKey("FilePanelPlugin");class Ho extends Q{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>{var t;return(t=this.view)==null?void 0:t.closeMenu()});this.plugin=new w.Plugin({key:Qe,view:o=>(this.view=new No(t,Qe,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:(o,r)=>{const s=o.getMeta(Qe);return s||(!o.getMeta(V.ySyncPluginKey)&&(o.selectionSet||o.docChanged)?{block:void 0}:r)}}})}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}class Do{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"shouldShow",({state:n,from:t,to:o})=>{const{doc:r,selection:s}=n,{empty:i}=s,a=!r.textBetween(t,o).length&&k.isTextSelection(n.selection);return s.$from.parent.type.spec.code||k.isNodeSelection(s)&&s.node.type.spec.code?!1:!(i||a)});p(this,"blurHandler",n=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;n&&n.relatedTarget&&(t===n.relatedTarget||t.contains(n.relatedTarget)||n.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});p(this,"dragHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var f;const{state:o,composing:r}=n,{doc:s,selection:i}=o,a=t&&t.doc.eq(s)&&t.selection.eq(i);if(r||a)return;const{ranges:l}=i,c=Math.min(...l.map(m=>m.$from.pos)),d=Math.max(...l.map(m=>m.$to.pos)),u=this.shouldShow({view:n,state:o,from:c,to:d}),h=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(u||this.preventHide)&&!h){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((f=this.state)!=null&&f.show&&!this.preventHide&&(!u||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:n}=this.pmView,{selection:t}=n,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(k.isNodeSelection(t)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return k.posToDOMRect(this.pmView,r,s)}}const Oo=new w.PluginKey("FormattingToolbarPlugin");class Ro extends Q{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new w.Plugin({key:Oo,view:o=>(this.view=new Do(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}const Di=k.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:e}){return["br",k.mergeAttributes(this.options.HTMLAttributes,e)]},renderText(){return`
12
+ `}}),jt=(e,n)=>{const t=e.resolve(n);if(t.depth<=1)return;const o=t.posAtIndex(t.index(t.depth-1),t.depth-1);return pe(e.resolve(o))},He=(e,n)=>{const t=e.resolve(n),o=t.index();if(o===0)return;const r=t.posAtIndex(o-1);return pe(e.resolve(r))},Vo=(e,n)=>{for(;n.childContainer;){const t=n.childContainer.node,o=e.resolve(n.childContainer.beforePos+1).posAtIndex(t.childCount-1);n=pe(e.resolve(o))}return n},Oi=(e,n)=>e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*"&&e.blockContent.node.childCount>0&&n.isBlockContainer&&n.blockContent.node.type.spec.content==="inline*",Ri=(e,n,t,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const r=e.doc.resolve(o.childContainer.beforePos+1),s=e.doc.resolve(o.childContainer.afterPos-1),i=r.blockRange(s);if(n){const a=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,a.depth)}}if(n){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);n(e.tr.delete(t.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0},Gt=e=>({state:n,dispatch:t})=>{const o=n.doc.resolve(e),r=pe(o),s=He(n.doc,r.bnBlock.beforePos);if(!s)return!1;const i=Vo(n.doc,s);return Oi(i,r)?Ri(n,t,i,r):!1},Vi=k.Extension.create({priority:50,addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({chain:o,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)return!1;const a=s.selection.from===i.blockContent.beforePos+1,l=i.blockContent.node.type.name==="paragraph";return a&&!l?r.command(A(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)return!1;const{blockContent:a}=i;return s.selection.from===a.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,c=s.selection.from===l.beforePos+1,d=s.selection.empty,u=a.beforePos;return c&&d?o().command(Gt(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=E(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||He(s.doc,a.bnBlock.beforePos))return!1;const d=jt(s.doc,a.bnBlock.beforePos);if((d==null?void 0:d.blockNoteType)!=="column")return!1;const u=d,h=jt(s.doc,u.bnBlock.beforePos);if((h==null?void 0:h.blockNoteType)!=="columnList")throw new Error("parent of column is not a column list");const f=u.childContainer.node.childCount===1,m=f&&h.childContainer.node.childCount===2,g=h.childContainer.node.firstChild===u.bnBlock.node;if(i){const b=s.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos,!1);if(m)if(g){s.tr.step(new ce.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,u.bnBlock.afterPos+1,h.bnBlock.afterPos-2,b,b.size,!1));const y=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else{s.tr.step(new ce.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,h.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const y=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(w.TextSelection.between(y,y))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(h.bnBlock.beforePos,b.content);const y=s.tr.doc.resolve(h.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else s.tr.delete(u.bnBlock.beforePos-1,u.bnBlock.beforePos+1);else{s.tr.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),g?s.tr.insert(h.bnBlock.beforePos-1,b.content):s.tr.insert(u.bnBlock.beforePos-1,b.content);const y=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(w.TextSelection.between(y,y))}}return!0}),()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=He(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let c=o();if(l.blockContent.node.type.spec.content==="tableRow+"){const m=i.bnBlock.beforePos-1-1-1-1-1;c=c.setTextSelection(m)}else if(l.blockContent.node.type.spec.content===""){const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setNodeSelection(d)}else{const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setTextSelection(d)}return c.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=He(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=Vo(s.doc,c);if(!d.isBlockContainer)throw new Error("todo");if(d.blockContent.node.type.spec.content===""||d.blockContent.node.type.spec.content==="inline*"&&d.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},d.bnBlock.afterPos).deleteRange({from:d.bnBlock.beforePos,to:d.bnBlock.afterPos}).run()}return!1})]),n=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=E(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:a,childContainer:l}=s,{depth:c}=r.doc.resolve(i.beforePos),d=i.afterPos===r.doc.nodeSize-3,u=r.selection.from===a.afterPos-1,h=r.selection.empty;if(!d&&u&&h&&!(l!==void 0)){let m=c,g=i.afterPos+1,b=r.doc.resolve(g).depth;for(;b<m;)m=b,g+=2,b=r.doc.resolve(g).depth;return o.command(Gt(g-1))}return!1})]),t=(o=!1)=>this.editor.commands.first(({commands:r})=>[()=>r.command(({state:s})=>{const i=E(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,{depth:c}=s.doc.resolve(a.beforePos),d=s.selection.$anchor.parentOffset===0,u=s.selection.anchor===s.selection.head,h=l.node.childCount===0,f=c>1;return d&&u&&h&&f?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=E(s),a=this.options.editor.schema.blockSchema[i.blockNoteType].hardBreakShortcut??"shift+enter";return a==="none"?!1:a==="shift+enter"&&o||a==="enter"?r.insertContent({type:"hardBreak"}):!1}),()=>r.command(({state:s,dispatch:i})=>{const a=E(s);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,d=s.selection.$anchor.parentOffset===0,u=s.selection.anchor===s.selection.head,h=c.node.childCount===0;if(d&&u&&h){const f=l.afterPos,m=f+2;if(i){const g=s.schema.nodes.blockContainer.createAndFill();s.tr.insert(f,g).scrollIntoView(),s.tr.setSelection(new w.TextSelection(s.doc.resolve(m)))}return!0}return!1}),()=>r.command(({state:s,chain:i})=>{const a=E(s);if(!a.isBlockContainer)return!1;const{blockContent:l}=a,c=s.selection.$anchor.parentOffset===0;return l.node.childCount===0?!1:(i().deleteSelection().command(ro(s.selection.from,c,c)).run(),!0)})]);return{Backspace:e,Delete:n,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:Eo(this.options.editor)},"Shift-Tab":()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}});class _i{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredLinkMark");p(this,"mouseHoveredLinkMarkRange");p(this,"keyboardHoveredLinkMark");p(this,"keyboardHoveredLinkMarkRange");p(this,"linkMark");p(this,"linkMarkRange");p(this,"mouseOverHandler",n=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),n.target instanceof HTMLAnchorElement&&n.target.nodeName==="A"){const t=n.target,o=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(o),s=r.marks();for(const i of s)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=i,this.mouseHoveredLinkMarkRange=k.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",n=>{var o;const t=this.pmView.dom.parentElement;this.linkMark&&n&&n.target&&!(t===n.target||t.contains(n.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;this.linkMark!==void 0&&(n=this.state)!=null&&n.show&&(this.state.referencePos=k.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(n,t){var o;this.editor.transact(r=>{const s=N(r);r.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),r.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,s.mark("link",{href:n}))}),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var n;this.editor.transact(t=>t.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}update(n,t,o=!1){var a;const{state:r}=n;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const l=this.pmView.state.selection.$from.marks();for(const c of l)if(c.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=c,this.keyboardHoveredLinkMarkRange=k.getMarkRange(this.pmView.state.selection.$from,c.type,c.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&o&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:k.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((a=this.state)!=null&&a.show&&i&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const _o=new w.PluginKey("LinkToolbarPlugin");class Uo extends Q{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"editLink",(t,o)=>{this.view.editLink(t,o)});p(this,"deleteLink",()=>{this.view.deleteLink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new w.Plugin({key:_o,view:o=>(this.view=new _i(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}onUpdate(t){return this.on("update",t)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}const Fo=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],$o="https",Ui=new w.PluginKey("node-selection-keyboard");class Fi{constructor(){p(this,"plugin");this.plugin=new w.Plugin({key:Ui,props:{handleKeyDown:(n,t)=>{if("node"in n.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){const o=n.state.tr;return n.dispatch(o.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new w.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}})}}const $i=new w.PluginKey("blocknote-placeholder");class zi{constructor(n,t){p(this,"plugin");this.plugin=new w.Plugin({key:$i,view:o=>{var c,d;const r=`placeholder-selector-${en.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),((c=n.prosemirrorView)==null?void 0:c.root)instanceof ShadowRoot?n.prosemirrorView.root.append(s):(d=n.prosemirrorView)==null||d.root.head.appendChild(s);const a=s.sheet,l=(u="")=>`.${r} .bn-block-content${u} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:u,emptyDocument:h,...f}=t;for(const[b,y]of Object.entries(f)){const C=`[data-content-type="${b}"]`;a.insertRule(`${l(C)} { content: ${JSON.stringify(y)}; }`)}const m="[data-is-only-empty-block]",g="[data-is-empty-and-focused]";a.insertRule(`${l(m)} { content: ${JSON.stringify(h)}; }`),a.insertRule(`${l(g)} { content: ${JSON.stringify(u)}; }`)}catch(u){console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",u)}return{destroy:()=>{var u,h;((u=n.prosemirrorView)==null?void 0:u.root)instanceof ShadowRoot?n.prosemirrorView.root.removeChild(s):(h=n.prosemirrorView)==null||h.root.head.removeChild(s)}}},props:{decorations:o=>{const{doc:r,selection:s}=o;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(M.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,l=a.parent;if(l.content.size===0){const c=a.before();i.push(M.Decoration.node(c,c+l.nodeSize,{"data-is-empty-and-focused":"true"}))}return M.DecorationSet.create(r,i)}}})}}const Xt=new w.PluginKey("previous-blocks"),Wi={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class qi{constructor(){p(this,"plugin");let n;this.plugin=new w.Plugin({key:Xt,view(t){return{update:async(o,r)=>{var s;((s=this.key)==null?void 0:s.getState(o.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(Xt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,o,r,s){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!t.docChanged||r.doc.eq(s.doc))return o;const i={},a=k.findChildren(r.doc,d=>d.attrs.id),l=new Map(a.map(d=>[d.node.attrs.id,d])),c=k.findChildren(s.doc,d=>d.attrs.id);for(const d of c){const u=l.get(d.node.attrs.id),h=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:s.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:r.doc.resolve(u.pos).depth};i[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in o.prevTransactionOldBlockAttrs&&(g=o.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),o.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,o.updatedBlocks.add(d.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=i,o}},props:{decorations(t){const o=this.getState(t);if(o.updatedBlocks.size===0)return;const r=[];return t.doc.descendants((s,i)=>{if(!s.attrs.id||!o.updatedBlocks.has(s.attrs.id))return;const a=o.currentTransactionOldBlockAttrs[s.attrs.id],l={};for(const[d,u]of Object.entries(a))l["data-prev-"+Wi[d]]=u||"none";const c=M.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),M.DecorationSet.create(t.doc,r)}}})}}const Jt=new w.PluginKey("blocknote-show-selection");class Ki{constructor(n){p(this,"plugin");p(this,"enabled",!1);this.editor=n,this.plugin=new w.Plugin({key:Jt,props:{decorations:t=>{const{doc:o,selection:r}=t;if(!this.enabled)return M.DecorationSet.empty;const s=M.Decoration.inline(r.from,r.to,{"data-show-selection":"true"});return M.DecorationSet.create(o,[s])}}})}setEnabled(n){this.enabled!==n&&(this.enabled=n,this.editor.transact(t=>t.setMeta(Jt,{})))}getEnabled(){return this.enabled}}function zo(e,n){var t,o;for(;e&&e.parentElement&&e.parentElement!==n.dom&&((t=e.getAttribute)==null?void 0:t.call(e,"data-node-type"))!=="blockContainer";)e=e.parentElement;if(((o=e.getAttribute)==null?void 0:o.call(e,"data-node-type"))==="blockContainer")return{node:e,id:e.getAttribute("data-id")}}class re extends w.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,o,r=o){return new re(t.resolve(o),t.resolve(r))}content(){return new B.Slice(B.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof re)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?w.Selection.near(t.resolve(r.pos)):r.deleted?w.Selection.near(t.resolve(s.pos)):new re(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}w.Selection.jsonID("multiple-node",re);let W;function ji(e,n){let t,o;const r=n.resolve(e.from).node().type.spec.group==="blockContent",s=n.resolve(e.to).node().type.spec.group==="blockContent",i=Math.min(e.$anchor.depth,e.$head.depth);if(r&&s){const a=e.$from.start(i-1),l=e.$to.end(i-1);t=n.resolve(a-1).pos,o=n.resolve(l+1).pos}else t=e.from,o=e.to;return{from:t,to:o}}function Yt(e,n,t=n){n===t&&(t+=e.state.doc.resolve(n+1).node().nodeSize);const o=e.domAtPos(n).node.cloneNode(!0),r=e.domAtPos(n).node,s=(u,h)=>Array.prototype.indexOf.call(u.children,h),i=s(r,e.domAtPos(n+1).node.parentElement),a=s(r,e.domAtPos(t-1).node.parentElement);for(let u=r.childElementCount-1;u>=0;u--)(u>a||u<i)&&o.removeChild(o.children[u]);Wo(e.root),W=o;const l=W.getElementsByTagName("iframe");for(let u=0;u<l.length;u++){const h=l[u],f=h.parentElement;f&&f.removeChild(h)}const d=e.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");W.className=W.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild(W):e.root.body.appendChild(W)}function Wo(e){W!==void 0&&(e instanceof ShadowRoot?e.removeChild(W):e.body.removeChild(W),W=void 0)}function Gi(e,n,t){if(!e.dataTransfer)return;const o=t.prosemirrorView;if(!o)return;const r=_(n.id,o.state.doc);if(!r)throw new Error(`Block with ID ${n.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,a=o.state.doc,{from:l,to:c}=ji(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof re;d&&u?(o.dispatch(o.state.tr.setSelection(re.create(a,l,c))),Yt(o,l,c)):(o.dispatch(o.state.tr.setSelection(w.NodeSelection.create(o.state.doc,s))),Yt(o,s));const h=o.state.selection.content(),f=t.pmSchema,m=o.serializeForClipboard(h).dom.innerHTML,g=Te(f,t),b=Lo(h.content),y=g.exportBlocks(b,{}),C=Ge(y);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",y),e.dataTransfer.setData("text/plain",C),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(W,0,0)}}const ge=.1;function pt(e,n,t,o=!0){const r=e.root.elementsFromPoint(n.left+(t==="editor"?50:0),n.top);for(const s of r)if(e.dom.contains(s))return o&&s.closest("[data-node-type=columnList]")?pt(e,{left:n.left+50,top:n.top},t,!1):zo(s,e)}function Xi(e,n,t){if(!n.dom.firstChild)return;const o=n.dom.firstChild.getBoundingClientRect(),r={left:e.x,top:e.y},s=r.left<o.left,i=r.left>o.right;t==="viewport"&&(s&&(r.left=o.left+10),i&&(r.left=o.right-10));let a=pt(n,r,t);if(!i&&a){const l=a.node.getBoundingClientRect();r.left=l.right-10,a=pt(n,r,"viewport",!1)}return a}class qo{constructor(n,t,o,r){p(this,"state");p(this,"emitUpdate");p(this,"mousePos");p(this,"hoveredBlock");p(this,"menuFrozen",!1);p(this,"isDragOrigin",!1);p(this,"updateState",n=>{this.state=n,this.emitUpdate(this.state)});p(this,"updateStateFromMousePos",()=>{var o,r,s,i;if(this.menuFrozen||!this.mousePos)return;const n=Xi(this.mousePos,this.pmView,this.sideMenuDetection);if(!n||!this.editor.isEditable){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}if((r=this.state)!=null&&r.show&&((s=this.hoveredBlock)!=null&&s.hasAttribute("data-id"))&&((i=this.hoveredBlock)==null?void 0:i.getAttribute("data-id"))===n.id)return;this.hoveredBlock=n.node;const t=n.node.firstChild;if(t&&this.editor.isEditable){const a=t.getBoundingClientRect(),l=n.node.closest("[data-node-type=column]");this.updateState({show:!0,referencePos:new DOMRect(l?l.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,a.y,a.width,a.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))})}});p(this,"onDrop",n=>{var r,s;if(this.pmView.dragging===null)return;this.editor._tiptapEditor.commands.blur();const t=n.target instanceof Node&&((r=n.target instanceof HTMLElement?n.target:n.target.parentElement)==null?void 0:r.closest(".bn-editor"))||null;if(t&&(!this.isDragOrigin&&this.pmView.dom===t?this.pmView.dispatch(this.pmView.state.tr.setSelection(w.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.to))):this.isDragOrigin&&this.pmView.dom!==t&&setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0)),this.sideMenuDetection==="editor"||n.synthetic||!((s=n.dataTransfer)!=null&&s.types.includes("blocknote/html")))return;const o=this.pmView.posAtCoords({left:n.clientX,top:n.clientY});if(!o||o.inside===-1){const i=this.createSyntheticEvent(n);this.pmView.dom.dispatchEvent(i)}});p(this,"onDragEnd",()=>{this.pmView.dragging=null});p(this,"onDragStart",n=>{var i;const t=(i=n.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!t)return;if(this.pmView.dragging)throw new Error("New drag was started while an existing drag is ongoing");const o=document.createElement("div");o.innerHTML=t;const s=B.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new B.Slice(s.content,0,0),move:!0}});p(this,"onDragOver",n=>{var o;if(this.sideMenuDetection==="editor"||n.synthetic||!((o=n.dataTransfer)!=null&&o.types.includes("blocknote/html")))return;const t=this.pmView.posAtCoords({left:n.clientX,top:n.clientY});if(!t||t.inside===-1&&this.pmView.dom.firstChild){const r=this.createSyntheticEvent(n);this.pmView.dom.dispatchEvent(r)}});p(this,"onKeyDown",n=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});p(this,"onMouseMove",n=>{var s;if(this.menuFrozen)return;this.mousePos={x:n.clientX,y:n.clientY};const t=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom,r=this.pmView.dom.parentElement;if(o&&n&&n.target&&!(r===n.target||r.contains(n.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});p(this,"onScroll",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state))});this.editor=n,this.sideMenuDetection=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");r(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),je(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),o.root.addEventListener("scroll",this.onScroll,!0)}createSyntheticEvent(n){const t=new Event(n.type,n),o=this.pmView.dom.firstChild.getBoundingClientRect();return t.clientX=n.clientX,t.clientY=n.clientY,n.clientX<o.left&&n.clientX>o.left-o.width*ge?t.clientX=o.left+o.width*ge/2:n.clientX>o.right&&n.clientX<o.right+o.width*ge?t.clientX=o.right-o.width*ge/2:(n.clientX<o.left||n.clientX>o.right)&&(t.clientX=o.left+ge*o.width*2),t.clientY=Math.min(Math.max(n.clientY,o.top),o.top+o.height),t.dataTransfer=n.dataTransfer,t.preventDefault=()=>n.preventDefault(),t.synthetic=!0,t}update(n,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const Ko=new w.PluginKey("SideMenuPlugin");class jo extends Q{constructor(t,o){super();p(this,"view");p(this,"plugin");p(this,"blockDragStart",(t,o)=>{this.view&&(this.view.isDragOrigin=!0),Gi(t,o,this.editor)});p(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&Wo(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)});p(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});p(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=t,this.plugin=new w.Plugin({key:Ko,view:r=>(this.view=new qo(t,o,r,s=>{this.emit("update",s)}),this.view)})}onUpdate(t){return this.on("update",t)}}const Ie=new Map;function Ji(e){if(Ie.has(e))return Ie.get(e);const n=new ce.Mapping;return e._tiptapEditor.on("transaction",({transaction:t})=>{n.appendMapping(t.mapping)}),e._tiptapEditor.on("destroy",()=>{Ie.delete(e)}),Ie.set(e,n),n}function Yi(e,n,t="left"){const o=V.ySyncPluginKey.getState(e._tiptapEditor.state);if(!o){const s=Ji(e),i=s.maps.length;return()=>s.slice(i).map(n,t==="left"?-1:1)}const r=V.absolutePositionToRelativePosition(n+(t==="right"?1:0),o.binding.type,o.binding.mapping);return()=>{const s=V.ySyncPluginKey.getState(e._tiptapEditor.state),i=V.relativePositionToAbsolutePosition(s.doc,s.binding.type,r,s.binding.mapping);if(i===null)throw new Error("Position not found, cannot track positions");return i+(t==="right"?-1:0)}}const Zi=k.findParentNode(e=>e.type.name==="blockContainer");class Qi{constructor(n,t){p(this,"state");p(this,"emitUpdate");p(this,"rootEl");p(this,"pluginState");p(this,"handleScroll",()=>{var n,t;if((n=this.state)!=null&&n.show){const o=(t=this.rootEl)==null?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!o)return;this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});p(this,"closeMenu",()=>{this.editor.transact(n=>n.setMeta(le,null))});p(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(n=>n.selection.from)}).run()});var o,r;this.editor=n,this.pluginState=void 0,this.emitUpdate=s=>{var i;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(s,{...this.state,ignoreQueryLength:(i=this.pluginState)==null?void 0:i.ignoreQueryLength})},this.rootEl=(o=this.editor.prosemirrorView)==null?void 0:o.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(n,t){var c;const o=le.getState(t),r=le.getState(n.state),s=o===void 0&&r!==void 0,i=o!==void 0&&r===void 0;if(!s&&!(o!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?o:r,i||!this.editor.isEditable){this.state&&(this.state.show=!1),this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&l&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var n;(n=this.rootEl)==null||n.removeEventListener("scroll",this.handleScroll,!0)}}const le=new w.PluginKey("SuggestionMenuPlugin");class Go extends Q{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"triggerCharacters",[]);p(this,"addTriggerCharacter",t=>{this.triggerCharacters.push(t)});p(this,"removeTriggerCharacter",t=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==t)});p(this,"closeMenu",()=>this.view.closeMenu());p(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new w.Plugin({key:le,view:()=>(this.view=new Qi(t,(r,s)=>{this.emit(`update ${r}`,s)}),this.view),state:{init(){},apply:(r,s,i,a)=>{if(r.getMeta("orderedListIndexing")!==void 0||r.selection.$from.parent.type.spec.code)return s;const l=r.getMeta(le);if(typeof l=="object"&&l!==null){s&&this.closeMenu();const d=Yi(t,a.selection.from-l.triggerCharacter.length);return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:()=>d()+l.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:l==null?void 0:l.ignoreQueryLength}}if(s===void 0)return s;if(a.selection.from!==a.selection.to||l===null||r.getMeta("focus")||r.getMeta("blur")||r.getMeta("pointer")||s.triggerCharacter!==void 0&&a.selection.from<s.queryStartPos()||!a.selection.$from.sameParent(a.doc.resolve(s.queryStartPos())))return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos(),a.selection.from),c}},props:{handleTextInput(r,s,i,a){return o.includes(a)?(r.dispatch(r.state.tr.insertText(a)),r.dispatch(r.state.tr.setMeta(le,{triggerCharacter:a}).scrollIntoView()),!0):!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=Zi(r.selection);if(i)return M.DecorationSet.create(r.doc,[M.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return M.DecorationSet.create(r.doc,[M.Decoration.inline(s.queryStartPos()-s.triggerCharacter.length,s.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}}})}onUpdate(t,o){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,o)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}function ea(e,n){e.suggestionMenus.addTriggerCharacter(n)}let R;function Zt(e){R||(R=document.createElement("div"),R.innerHTML="_",R.style.opacity="0",R.style.height="1px",R.style.width="1px",e instanceof Document?e.body.appendChild(R):e.appendChild(R))}function ta(e){R&&(e instanceof Document?e.body.removeChild(R):e.removeChild(R),R=void 0)}function Le(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function na(e){let n=e;for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH"&&!n.classList.contains("tableWrapper");){if(n.classList.contains("ProseMirror"))return;const t=n.parentNode;if(!t||!(t instanceof Element))return;n=t}return n.nodeName==="TD"||n.nodeName==="TH"?{type:"cell",domNode:n,tbodyNode:n.closest("tbody")}:{type:"wrapper",domNode:n,tbodyNode:n.querySelector("tbody")}}function oa(e,n){const t=n.querySelectorAll(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class Xo{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"tableId");p(this,"tablePos");p(this,"tableElement");p(this,"menuFrozen",!1);p(this,"mouseState","up");p(this,"prevWasEditable",null);p(this,"viewMousedownHandler",()=>{this.mouseState="down"});p(this,"mouseUpHandler",n=>{this.mouseState="up",this.mouseMoveHandler(n)});p(this,"mouseMoveHandler",n=>{var c,d,u,h,f,m,g;if(this.menuFrozen||this.mouseState==="selecting"||!(n.target instanceof Element)||!this.pmView.dom.contains(n.target))return;const t=na(n.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((c=this.state)!=null&&c.draggingState)){this.mouseState="selecting",(d=this.state)!=null&&d.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t||!this.editor.isEditable){(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t.tbodyNode)return;const o=t.tbodyNode.getBoundingClientRect(),r=zo(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(b=>_(r.id,b.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=T(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(ko("table",a,this.editor)&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const l=(h=t.domNode.closest(".tableWrapper"))==null?void 0:h.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const b=n.clientY>=o.bottom-1&&n.clientY<o.bottom+20,y=n.clientX>=o.right-1&&n.clientX<o.right+20,C=n.clientX>o.right||n.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:b,showAddOrRemoveColumnsButton:y,referencePosTable:o,block:s,widgetContainer:l,colIndex:C||(f=this.state)==null?void 0:f.colIndex,rowIndex:C||(m=this.state)==null?void 0:m.rowIndex,referencePosCell:C||(g=this.state)==null?void 0:g.referencePosCell}}else{const b=Le(t.domNode),y=Le(t.domNode.parentElement),C=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===y&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:C,colIndex:b,rowIndex:y,widgetContainer:l}}return this.emitUpdate(),!1});p(this,"dragOverHandler",n=>{var h;if(((h=this.state)==null?void 0:h.draggingState)===void 0)return;n.preventDefault(),n.dataTransfer.dropEffect="move",oa(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const t={left:Math.min(Math.max(n.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(n.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(t.left,t.top).filter(f=>f.tagName==="TD"||f.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Le(r.parentElement),a=Le(r),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,d=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==l;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const u=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==u&&(this.state.draggingState.mousePos=u,s=!0),s&&this.emitUpdate(),d&&this.editor.transact(f=>f.setMeta(ae,!0))});p(this,"dropHandler",n=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");n.preventDefault();const{draggingState:t,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!mn(this.state.block,t.originalIndex,r))return!1;const i=Vr(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!gn(this.state.block,t.originalIndex,o))return!1;const i=Rr(this.state.block,t.originalIndex,o),[a]=s.splice(t.originalIndex,1);s.splice(o,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var r;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:n,width:t}=Ct(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=n&&(this.state.rowIndex=n-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){const i=o.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const ae=new w.PluginKey("TableHandlesPlugin");class Jo extends Q{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"colDragStart",t=>{if(this.view.state===void 0||this.view.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:t.clientX},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(ae,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Zt(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(R,0,0),t.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",t=>{if(this.view.state===void 0||this.view.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:t.clientY},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(ae,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Zt(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(R,0,0),t.dataTransfer.effectAllowed="copyMove"});p(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(t=>t.setMeta(ae,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");ta(this.editor.prosemirrorView.root)});p(this,"freezeHandles",()=>{this.view.menuFrozen=!0});p(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});p(this,"getCellsAtRowHandle",(t,o)=>ot(t,o));p(this,"getCellsAtColumnHandle",(t,o)=>rt(t,o));p(this,"setCellSelection",(t,o,r=o)=>{const s=this.view;if(!s)throw new Error("Table handles view not initialized");const i=t.doc.resolve(s.tablePos+1),a=t.doc.resolve(i.posAtIndex(o.row)+1),l=t.doc.resolve(a.posAtIndex(o.col)),c=t.doc.resolve(i.posAtIndex(r.row)+1),d=t.doc.resolve(c.posAtIndex(r.col)),u=t.tr;return u.setSelection(new I.CellSelection(l,d)),t.apply(u)});p(this,"addRowOrColumn",(t,o)=>{this.editor.exec((r,s)=>{const i=this.setCellSelection(r,o.orientation==="row"?{row:t,col:0}:{row:0,col:t});return o.orientation==="row"?o.side==="above"?I.addRowBefore(i,s):I.addRowAfter(i,s):o.side==="left"?I.addColumnBefore(i,s):I.addColumnAfter(i,s)})});p(this,"removeRowOrColumn",(t,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:t,col:0});return I.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:t});return I.deleteColumn(i,s)}));p(this,"mergeCells",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t.relativeStartCell,t.relativeEndCell):o;return I.mergeCells(s,r)}));p(this,"splitCell",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t):o;return I.splitCell(s,r)}));p(this,"getCellSelection",()=>this.editor.transact(t=>{const o=t.selection;let r=o.$from,s=o.$to;if(ct(o)){const{ranges:m}=o;m.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$to)})}else if(r=t.doc.resolve(o.$from.pos-o.$from.parentOffset-1),s=t.doc.resolve(o.$to.pos-o.$to.parentOffset-1),r.pos===0||s.pos===0)return;const i=t.doc.resolve(r.pos-r.parentOffset-1),a=t.doc.resolve(s.pos-s.parentOffset-1),l=t.doc.resolve(i.pos-i.parentOffset-1),c=r.index(i.depth),d=i.index(l.depth),u=s.index(a.depth),h=a.index(l.depth),f=[];for(let m=d;m<=h;m++)for(let g=c;g<=u;g++)f.push({row:m,col:g});return{from:{row:d,col:c},to:{row:h,col:u},cells:f}}));p(this,"getMergeDirection",t=>this.editor.transact(o=>{const r=ct(o.selection)?o.selection:void 0;if(!r||!t||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return Fr(s.from,s.to,t)?"vertical":"horizontal"}));p(this,"cropEmptyRowsOrColumns",(t,o)=>_r(t,o));p(this,"addRowsOrColumns",(t,o,r)=>Ur(t,o,r));this.editor=t,this.plugin=new w.Plugin({key:ae,view:o=>(this.view=new Xo(t,o,r=>{this.emit("update",r)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const r=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=this.view.state,{originalIndex:l,draggedCellOrientation:c}=a;if(r===l||!i||c==="row"&&!mn(i,l,r)||c==="col"&&!gn(i,l,r))return M.DecorationSet.create(o.doc,s);const d=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?ot(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(M.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.left="0",C.style.right="0",r>l?C.style.bottom="-2px":C.style.top="-3px",C.style.height="4px",C}))}):rt(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(M.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.top="0",C.style.bottom="0",r>l?C.style.right="-2px":C.style.left="-3px",C.style.width="4px",C}))}),M.DecorationSet.create(o.doc,s)}}})}onUpdate(t){return this.on("update",t)}}const ra=k.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment==="left"?{}:{"data-text-alignment":e.textAlignment}}}}]}}),sa=k.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:P.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):P.textColor.default,renderHTML:e=>e.textColor===P.textColor.default?{}:{"data-text-color":e.textColor}}}}]}}),ia=k.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new w.PluginKey(this.name);return[new w.Plugin({key:e,appendTransaction:(n,t,o)=>{const{doc:r,tr:s,schema:i}=o,a=e.getState(o),l=r.content.size-2,c=i.nodes.blockContainer,d=i.nodes.paragraph;if(a)return s.insert(l,c.create(void 0,d.create()))},state:{init:(n,t)=>{},apply:(n,t)=>{if(!n.docChanged)return t;let o=n.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const r=o.firstChild;if(!r)throw new Error("Expected blockContent");return o.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),aa={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},la=k.Node.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:e=>{if(typeof e=="string")return!1;const n={};for(const[t,o]of Object.entries(aa))e.getAttribute(o)&&(n[t]=e.getAttribute(o));return n}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:e}){var r;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(e))s!=="class"&&n.setAttribute(s,i);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...e},o=document.createElement("div");o.className=Y("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(t))s!=="class"&&o.setAttribute(s,i);return n.appendChild(o),{dom:n,contentDOM:o}}}),ca=k.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const n={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},t=document.createElement("div");t.className=Y("bn-block-group",n.class),t.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);return{dom:t,contentDOM:t}}}),da=k.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Yo=e=>{var r;const n={},t=ua(e);for(const s of t)n[s.name]=s;e.collaboration&&(n.ySyncPlugin=new Ii(e.collaboration.fragment),n.yUndoPlugin=new Pi,(r=e.collaboration.provider)!=null&&r.awareness&&(n.yCursorPlugin=new ut(e.collaboration))),n.formattingToolbar=new Ro(e.editor),n.linkToolbar=new Uo(e.editor),n.sideMenu=new jo(e.editor,e.sideMenuDetection),n.suggestionMenus=new Go(e.editor),n.filePanel=new Ho(e.editor),n.placeholder=new zi(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new qi),e.tableHandles&&(n.tableHandles=new Jo(e.editor)),n.dropCursor={plugin:e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})},n.nodeSelectionKeyboard=new Fi,n.showSelection=new Ki(e.editor),e.comments&&(n.comments=new Hi(e.editor,e.comments.threadStore,Ao.name));const o=e.disableExtensions||[];for(const s of o)delete n[s];return n};let Qt=!1;const ua=e=>{const n=[k.extensions.ClipboardTextSerializer,k.extensions.Commands,k.extensions.Editable,k.extensions.FocusEvents,k.extensions.Tabindex,mr.Gapcursor,ve.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),Di,kr.Text,br.Link.extend({inclusive:!1}).configure({defaultProtocol:$o,protocols:Qt?[]:Fo}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),sa,Mi,ra,k.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),da,la.configure({editor:e.editor,domAttributes:e.domAttributes}),Vi.configure({editor:e.editor,tabBehavior:e.tabBehavior}),ca.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(t=>t.config!=="link"&&t.config!=="text").map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(o=>o.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),xi(e.editor),Ei(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),li(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[ia]:[],...e.comments?[Ao]:[]];return Qt=!0,e.collaboration||n.push(gr.History),n};function pa(e,n){const t=[];return e.forEach((o,r,s)=>{s!==n&&t.push(o)}),B.Fragment.from(t)}function ha(e,n){const t=[];for(let o=0;o<e.childCount;o++)if(e.child(o).type.name==="tableRow")if(t.length>0&&t[t.length-1].type.name==="table"){const r=t[t.length-1],s=r.copy(r.content.addToEnd(e.child(o)));t[t.length-1]=s}else{const r=n.nodes.table.createChecked(void 0,e.child(o));t.push(r)}else t.push(e.child(o));return e=B.Fragment.from(t),e}function fa(e,n){let t=B.Fragment.from(e.content);if(t=ha(t,n.state.schema),!ma(t,n))return new B.Slice(t,e.openStart,e.openEnd);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const r=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.name==="blockGroup"){const i=t.child(o+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(t.child(o+1)),t=pa(t,o+1))}const s=n.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(o,s)}return new B.Slice(t,e.openStart,e.openEnd)}function ma(e,n){var s,i;const t=e.childCount===1,o=((s=e.firstChild)==null?void 0:s.type.spec.content)==="inline*",r=((i=e.firstChild)==null?void 0:i.type.spec.content)==="tableRow+";if(t){if(o)return!1;if(r){const a=E(n.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const Fe=class Fe extends k.Editor{constructor(t,o){super({...t,content:void 0});p(this,"_state");p(this,"mount",(t,o,r)=>{o?(this.options.element=o,this.createViewAlternative(t,r)):this.destroy()});const r=this.schema;let s;const i=r.nodes.doc.createAndFill;r.nodes.doc.createAndFill=(...l)=>{if(s)return s;const c=i.apply(r.nodes.doc,l),d=JSON.parse(JSON.stringify(c.toJSON()));return d.content[0].content[0].attrs.id="initialBlockId",s=B.Node.fromJSON(r,d),s};let a;try{const l=t==null?void 0:t.content.map(c=>oe(c,this.schema,o).toJSON());a=k.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(t.content))}this._state=w.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){if(!this.view){this._state=this.state.apply(t);return}if(this.view.isDestroyed)return;if(this.isCapturingTransaction){this.dispatchTransaction(t);return}const{state:o,transactions:r}=this.state.applyTransaction(t),s=!this.state.selection.eq(o.selection);this.emit("beforeTransaction",{editor:this,transaction:t,nextState:o}),this.view.updateState(o),this.emit("transaction",{editor:this,transaction:t}),s&&this.emit("selectionUpdate",{editor:this,transaction:t});const i=t.getMeta("focus"),a=t.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:t}),a&&this.emit("blur",{editor:this,event:a.event,transaction:t}),!(!t.docChanged||t.getMeta("preventUpdate"))&&(this.emit("update",{editor:this,transaction:t}),this.emit("v3-update",{editor:this,transaction:t,appendedTransactions:r.slice(1)}))}createViewAlternative(t,o){this.contentComponent=o;const r={};this.extensionManager.extensions.forEach(i=>{i.type==="mark"&&i.config.addMarkView&&(r[i.name]=i.config.addMarkView(t))}),this.view=new M.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:r,nodeViews:this.extensionManager.nodeViews});const s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.commands.focus(this.options.autofocus||this.options.element.getAttribute("data-bn-autofocus")==="true",{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};p(Fe,"create",(t,o)=>{var s,i;const r=(s=globalThis==null?void 0:globalThis.window)==null?void 0:s.setTimeout;typeof((i=globalThis==null?void 0:globalThis.window)==null?void 0:i.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new Fe(t,o)}finally{r&&(globalThis.window.setTimeout=r)}});let _e=Fe;_e.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const ga={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ht extends Q{constructor(t){var c,d,u,h,f,m,g,b,y,C,v,L,j,F,x;super();p(this,"pmSchema");p(this,"extensions",{});p(this,"headless",!1);p(this,"_tiptapEditor");p(this,"elementRenderer",null);p(this,"blockCache",new WeakMap);p(this,"dictionary");p(this,"schema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"formattingToolbar");p(this,"linkToolbar");p(this,"sideMenu");p(this,"suggestionMenus");p(this,"filePanel");p(this,"tableHandles");p(this,"comments");p(this,"showSelectionPlugin");p(this,"cursorPlugin");p(this,"uploadFile");p(this,"onUploadStartCallbacks",[]);p(this,"onUploadEndCallbacks",[]);p(this,"resolveFileUrl");p(this,"resolveUsers");p(this,"settings");p(this,"activeTransaction",null);p(this,"mount",(t,o)=>{this._tiptapEditor.mount(this,t,o)});this.options=t;const o=t;if(o.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(o.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(o.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(o.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||yr.en,this.settings={tables:{splitCells:((c=t==null?void 0:t.tables)==null?void 0:c.splitCells)??!1,cellBackgroundColor:((d=t==null?void 0:t.tables)==null?void 0:d.cellBackgroundColor)??!1,cellTextColor:((u=t==null?void 0:t.tables)==null?void 0:u.cellTextColor)??!1,headers:((h=t==null?void 0:t.tables)==null?void 0:h.headers)??!1},codeBlock:{indentLineWithTab:((f=t==null?void 0:t.codeBlock)==null?void 0:f.indentLineWithTab)??!0,defaultLanguage:((m=t==null?void 0:t.codeBlock)==null?void 0:m.defaultLanguage)??"text",supportedLanguages:((g=t==null?void 0:t.codeBlock)==null?void 0:g.supportedLanguages)??{},createHighlighter:((b=t==null?void 0:t.codeBlock)==null?void 0:b.createHighlighter)??void 0}};const r={defaultStyles:!0,schema:t.schema||me.create(),_headless:!1,...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};if(r.comments&&!r.resolveUsers)throw new Error("resolveUsers is required when using comments");if(this.resolveUsers=r.resolveUsers,this.schema=r.schema,this.blockImplementations=r.schema.blockSpecs,this.inlineContentImplementations=r.schema.inlineContentSpecs,this.styleImplementations=r.schema.styleSpecs,this.extensions=Yo({editor:this,domAttributes:r.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:r.collaboration,trailingBlock:r.trailingBlock,disableExtensions:r.disableExtensions,setIdAttribute:r.setIdAttribute,animations:r.animations??!0,tableHandles:O("table",this),dropCursor:this.options.dropCursor??wr.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,sideMenuDetection:r.sideMenuDetection||"viewport",comments:r.comments,pasteHandler:r.pasteHandler}),(((y=r._tiptapOptions)==null?void 0:y.extensions)||[]).forEach(S=>{this.extensions[S.name]=S}),Object.entries(r._extensions||{}).forEach(([S,D])=>{typeof D=="function"&&(D=D(this)),this.extensions[S]=D}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,this.cursorPlugin=this.extensions.yCursorPlugin,r.uploadFile){const S=r.uploadFile;this.uploadFile=async(D,ie)=>{this.onUploadStartCallbacks.forEach(Xe=>Xe.apply(this,[ie]));try{return await S(D,ie)}finally{this.onUploadEndCallbacks.forEach(Xe=>Xe.apply(this,[ie]))}}}this.resolveFileUrl=r.resolveFileUrl,this.headless=r._headless;const s="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;s&&r.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const i=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:ve.options.generateID()}]);if(!Array.isArray(i)||i.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+i);const a=[...Object.entries(this.extensions).map(([S,D])=>{if(D instanceof k.Extension||D instanceof k.Node||D instanceof k.Mark)return D;if(!D.plugin)throw new Error("Extension should either be a TipTap extension or a ProseMirror plugin in a plugin property");return k.Extension.create({name:S,priority:D.priority,addProseMirrorPlugins:()=>[D.plugin]})})],l={...ga,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(C=r._tiptapOptions)==null?void 0:C.editorProps,attributes:{tabIndex:"0",...(L=(v=r._tiptapOptions)==null?void 0:v.editorProps)==null?void 0:L.attributes,...(j=r.domAttributes)==null?void 0:j.editor,class:Y("bn-editor",r.defaultStyles?"bn-default-styles":"",((x=(F=r.domAttributes)==null?void 0:F.editor)==null?void 0:x.class)||"")},transformPasted:fa}};this.headless?this.pmSchema=k.getSchema(l.extensions):(this._tiptapEditor=_e.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new Ht(t)}exec(t){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,i=>this._tiptapEditor.dispatch(i),r)}canExec(t){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,void 0,r)}transact(t){if(this.activeTransaction)return t(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const o=t(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this._tiptapEditor.dispatch(r),o}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this._tiptapEditor.state}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var t;return(t=this.prosemirrorView)==null?void 0:t.dom}isFocused(){var t;return((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}focus(){var t;(t=this.prosemirrorView)==null||t.focus()}onUploadStart(t){return this.onUploadStartCallbacks.push(t),()=>{const o=this.onUploadStartCallbacks.indexOf(t);o>-1&&this.onUploadStartCallbacks.splice(o,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const o=this.onUploadEndCallbacks.indexOf(t);o>-1&&this.onUploadEndCallbacks.splice(o,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(t=>{const o=[];return t.doc.firstChild.descendants(r=>(o.push(T(r,this.pmSchema)),!1)),o})}getBlock(t){return this.transact(o=>Ws(o.doc,t))}getPrevBlock(t){return this.transact(o=>qs(o.doc,t))}getNextBlock(t){return this.transact(o=>Ks(o.doc,t))}getParentBlock(t){return this.transact(o=>js(o.doc,t))}forEachBlock(t,o=!1){const r=this.document.slice();o&&r.reverse();function s(i){for(const a of i){if(t(a)===!1)return!1;const l=o?a.children.slice().reverse():a.children;if(!s(l))return!1}return!0}s(r)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){return this.transact(t=>Ys(t))}setTextCursorPosition(t,o="start"){return this.transact(r=>To(r,t,o))}getSelection(){return this.transact(t=>Xs(t))}setSelection(t,o){return this.transact(r=>Js(r,t,o))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return this._tiptapEditor.isEditable===void 0?!0:this._tiptapEditor.isEditable}set isEditable(t){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return}this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,o,r="before"){return this.transact(s=>Ds(s,t,o,r))}updateBlock(t,o){return this.transact(r=>yn(r,t,o))}removeBlocks(t){return this.transact(o=>$t(o,t,[]).removedBlocks)}replaceBlocks(t,o){return this.transact(r=>$t(r,t,o))}undo(){return this.options.collaboration?this.exec(V.undoCommand):this.exec(Dt.undo)}redo(){return this.options.collaboration?this.exec(V.redoCommand):this.exec(Dt.redo)}insertInlineContent(t){const o=U(t,this.pmSchema);this.transact(r=>{Gs(r,{from:r.selection.from,to:r.selection.to},o)})}getActiveStyles(){return this.transact(t=>{const o={},r=t.selection.$to.marks();for(const s of r){const i=this.schema.styleSchema[s.type.name];if(!i){s.type.name!=="link"&&!s.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",s.type.name);continue}i.propSchema==="boolean"?o[i.type]=!0:o[i.type]=s.attrs.stringValue}return o})}addStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.setMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.setMark(o,{stringValue:r});else throw new z(s.propSchema)}}removeStyles(t){for(const o of Object.keys(t))this._tiptapEditor.commands.unsetMark(o)}toggleStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.toggleMark(o,{stringValue:r});else throw new z(s.propSchema)}}getSelectedText(){return this.transact(t=>t.doc.textBetween(t.selection.from,t.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,o){if(t==="")return;const r=this.pmSchema.mark("link",{href:t});this.transact(s=>{const{from:i,to:a}=s.selection;o?s.insertText(o,i,a).addMark(i,i+o.length,r):s.setSelection(w.TextSelection.create(s.doc,a)).addMark(i,a,r)})}canNestBlock(){return $s(this)}nestBlock(){Eo(this)}canUnnestBlock(){return zs(this)}unnestBlock(){Fs(this)}moveBlocksUp(){return Vs(this)}moveBlocksDown(){return _s(this)}async blocksToHTMLLossy(t=this.document){return Te(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return Tn(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return It(t,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return xo(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return Po(t,this.pmSchema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this.cursorPlugin.updateUser(t)}onChange(t){if(this.headless)return;const o=({transaction:r,appendedTransactions:s})=>{t(this,{getChanges:()=>kn(r,s)})};return this._tiptapEditor.on("v3-update",o),()=>{this._tiptapEditor.off("v3-update",o)}}onSelectionChange(t,o){if(this.headless)return;const r=s=>{s.transaction.getMeta(V.ySyncPluginKey)&&!o||t(this)};return this._tiptapEditor.on("selectionUpdate",r),()=>{this._tiptapEditor.off("selectionUpdate",r)}}onCreate(t){return this.on("create",t),()=>{this.off("create",t)}}getSelectionBoundingBox(){var a;if(!this.prosemirrorView)return;const t=(a=this.prosemirrorView)==null?void 0:a.state,{selection:o}=t,{ranges:r}=o,s=Math.min(...r.map(l=>l.$from.pos)),i=Math.max(...r.map(l=>l.$to.pos));if(k.isNodeSelection(o)){const l=this.prosemirrorView.nodeDOM(s);if(l)return l.getBoundingClientRect()}return k.posToDOMRect(this.prosemirrorView,s,i)}get isEmpty(){const t=this.document;return t.length===0||t.length===1&&t[0].type==="paragraph"&&t[0].content.length===0}openSuggestionMenu(t,o){this.prosemirrorView&&(this.focus(),this.transact(r=>{o!=null&&o.deleteTriggerCharacter&&r.insertText(t),r.scrollIntoView().setMeta(this.suggestionMenus.plugin,{triggerCharacter:t,deleteTriggerCharacter:(o==null?void 0:o.deleteTriggerCharacter)||!1,ignoreQueryLength:(o==null?void 0:o.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(t){this.showSelectionPlugin.setEnabled(t)}convertHtmlToBlockNoteHtml(t){return Mo(t.trim()).innerHTML}pasteHTML(t,o=!1){var s;let r=t;o||(r=this.convertHtmlToBlockNoteHtml(t)),r&&((s=this.prosemirrorView)==null||s.pasteHTML(r))}pasteText(t){var o;return(o=this.prosemirrorView)==null?void 0:o.pasteText(t)}async pasteMarkdown(t){return this.pasteHTML(await Lt(t))}}const ba={gray:{text:"#9b9a97",background:"#ebeced"},brown:{text:"#64473a",background:"#e9e5e3"},red:{text:"#e03e3e",background:"#fbe4e4"},orange:{text:"#d9730d",background:"#f6e9d9"},yellow:{text:"#dfab01",background:"#fbf3db"},green:{text:"#4d6461",background:"#ddedea"},blue:{text:"#0b6e99",background:"#ddebf1"},purple:{text:"#6940a5",background:"#eae4f2"},pink:{text:"#ad1a72",background:"#f4dfeb"}},ka={gray:{text:"#bebdb8",background:"#9b9a97"},brown:{text:"#8e6552",background:"#64473a"},red:{text:"#ec4040",background:"#be3434"},orange:{text:"#e3790d",background:"#b7600a"},yellow:{text:"#dfab01",background:"#b58b00"},green:{text:"#6b8b87",background:"#4d6461"},blue:{text:"#0e87bc",background:"#0b6e99"},purple:{text:"#8552d7",background:"#6940a5"},pink:{text:"#da208f",background:"#ad1a72"}};class wa{constructor(n,t,o){this.mappings=t,this.options=o}async resolveFile(n){var o;if(!((o=this.options)!=null&&o.resolveFileUrl))return(await fetch(n)).blob();const t=await this.options.resolveFileUrl(n);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(n){return Object.entries(n).map(([o,r])=>this.mappings.styleMapping[o](r,this))}mapInlineContent(n){return this.mappings.inlineContentMapping[n.type](n,this)}transformInlineContent(n){return n.map(t=>this.mapInlineContent(t))}async mapBlock(n,t,o){return this.mappings.blockMapping[n.type](n,this,t,o)}}function ya(e){return{createBlockMapping:n=>n,createInlineContentMapping:n=>n,createStyleMapping:n=>n}}let Ae;async function Ca(){return Ae||(Ae=(async()=>{const[e,n]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),t="default"in e?e.default:e,o="default"in n?n.default:n;return await t.init({data:o}),{emojiMart:t,emojiData:o}})(),Ae)}async function va(e,n){if(!bo("text",e))return[];const{emojiData:t,emojiMart:o}=await Ca();return(n.trim()===""?Object.values(t.emojis):await o.SearchIndex.search(n)).map(s=>({id:s.skins[0].native,onItemClick:()=>e.insertInlineContent(s.skins[0].native+" ")}))}function Sa(e,...n){const t=[...e];for(const o of n)for(const r of o){const s=t.findLastIndex(i=>i.group===r.group);s===-1?t.push(r):t.splice(s+1,0,r)}return t}exports.AudioBlock=On;exports.BlockNoteEditor=Ht;exports.BlockNoteSchema=me;exports.COLORS_DARK_MODE_DEFAULT=ka;exports.COLORS_DEFAULT=ba;exports.CodeBlock=Vn;exports.DEFAULT_LINK_PROTOCOL=$o;exports.EMPTY_CELL_HEIGHT=ws;exports.EMPTY_CELL_WIDTH=Et;exports.Exporter=wa;exports.FILE_AUDIO_ICON_SVG=In;exports.FILE_ICON_SVG=Mn;exports.FILE_IMAGE_ICON_SVG=qn;exports.FILE_VIDEO_ICON_SVG=ao;exports.FileBlock=Wn;exports.FilePanelProsemirrorPlugin=Ho;exports.FilePanelView=No;exports.FormattingToolbarProsemirrorPlugin=Ro;exports.FormattingToolbarView=Do;exports.HTMLToBlocks=It;exports.ImageBlock=Yn;exports.LinkToolbarProsemirrorPlugin=Uo;exports.PageBreak=no;exports.SideMenuProsemirrorPlugin=jo;exports.SideMenuView=qo;exports.SuggestionMenuProseMirrorPlugin=Go;exports.TableHandlesProsemirrorPlugin=Jo;exports.TableHandlesView=Xo;exports.UniqueID=ve;exports.UnreachableCaseError=z;exports.VALID_LINK_PROTOCOLS=Fo;exports.VideoBlock=fo;exports.addInlineContentAttributes=nt;exports.addInlineContentKeyboardShortcuts=an;exports.addStyleAttributes=pn;exports.applyNonSelectableBlockFix=on;exports.assertEmpty=Tr;exports.audioBlockConfig=An;exports.audioParse=Hn;exports.audioPropSchema=Ln;exports.audioRender=Nn;exports.audioToExternalHTML=Dn;exports.blockToNode=oe;exports.blocksToMarkdown=xo;exports.camelToDataKebab=ke;exports.checkBlockHasDefaultProp=Ps;exports.checkBlockIsDefaultType=ko;exports.checkBlockIsFileBlock=Ts;exports.checkBlockIsFileBlockWithPlaceholder=Ms;exports.checkBlockIsFileBlockWithPreview=xs;exports.checkBlockTypeHasDefaultProp=wo;exports.checkDefaultBlockTypeInSchema=O;exports.checkDefaultInlineContentTypeInSchema=bo;exports.checkPageBreakBlocksInSchema=yo;exports.cleanHTMLToMarkdown=Ge;exports.combineByGroup=Sa;exports.contentNodeToInlineContent=Be;exports.contentNodeToTableContent=bt;exports.createAddFileButton=xn;exports.createBlockSpec=fe;exports.createBlockSpecFromStronglyTypedTiptapNode=Z;exports.createDefaultBlockDOMOutputSpec=q;exports.createExternalHTMLExporter=Te;exports.createFigureWithCaption=Ke;exports.createFileBlockWrapper=qe;exports.createFileNameWithIcon=Pn;exports.createInlineContentSpec=Dr;exports.createInlineContentSpecFromTipTapNode=cn;exports.createInternalBlockSpec=mt;exports.createInternalHTMLSerializer=Tn;exports.createInternalInlineContentSpec=ln;exports.createInternalStyleSpec=wt;exports.createLinkWithCaption=Me;exports.createResizableFileBlockWrapper=vt;exports.createStronglyTypedTiptapNode=K;exports.createStyleSpec=Or;exports.createStyleSpecFromTipTapMark=ee;exports.createSuggestionMenu=ea;exports.defaultBlockSchema=mo;exports.defaultBlockSpecs=Tt;exports.defaultBlockToHTML=tt;exports.defaultCodeBlockPropSchema=Rn;exports.defaultInlineContentSchema=go;exports.defaultInlineContentSpecs=Mt;exports.defaultProps=P;exports.defaultStyleSchema=Es;exports.defaultStyleSpecs=xt;exports.fileBlockConfig=Un;exports.fileParse=$n;exports.filePropSchema=_n;exports.fileRender=Fn;exports.fileToExternalHTML=zn;exports.filenameFromURL=Lr;exports.filterSuggestionItems=As;exports.formatKeyboardShortcut=X;exports.formattingToolbarPluginKey=Oo;exports.getBlockFromPos=nn;exports.getBlockInfo=J;exports.getBlockInfoFromResolvedPos=pe;exports.getBlockInfoFromSelection=E;exports.getBlockInfoFromTransaction=Ce;exports.getBlockInfoWithManualOffset=$e;exports.getBlockNoteExtensions=Yo;exports.getBlockSchemaFromSpecs=gt;exports.getBlocksChangedByTransaction=kn;exports.getColspan=ue;exports.getDefaultEmojiPickerItems=va;exports.getDefaultSlashMenuItems=Ls;exports.getInlineContentParseRules=dn;exports.getInlineContentSchemaFromSpecs=kt;exports.getNearestBlockPos=G;exports.getNodeById=_;exports.getPageBreakSlashMenuItems=Hs;exports.getParseRules=rn;exports.getRowspan=Oe;exports.getStyleParseRules=hn;exports.getStyleSchemaFromSpecs=yt;exports.imageBlockConfig=jn;exports.imageParse=Xn;exports.imagePropSchema=Kn;exports.imageRender=Gn;exports.imageToExternalHTML=Jn;exports.inheritedProps=ft;exports.initializeESMDependencies=je;exports.inlineContentToNodes=U;exports.insertOrUpdateBlock=H;exports.isAppleOS=tn;exports.isLinkInlineContent=et;exports.isNodeBlock=Ve;exports.isPartialLinkInlineContent=ht;exports.isPartialTableCell=de;exports.isSafari=Pr;exports.isStyledTextInlineContent=te;exports.isTableCell=ze;exports.isTableCellSelection=ct;exports.linkToolbarPluginKey=_o;exports.mapTableCell=De;exports.mappingFactory=ya;exports.markdownToBlocks=Po;exports.markdownToHTML=Lt;exports.mergeCSSClasses=Y;exports.mergeParagraphs=Ir;exports.nodeToBlock=T;exports.nodeToCustomInlineContent=Re;exports.pageBreakConfig=Zn;exports.pageBreakParse=eo;exports.pageBreakRender=Qn;exports.pageBreakSchema=Pt;exports.pageBreakToExternalHTML=to;exports.parseEmbedElement=lt;exports.parseFigureElement=xe;exports.propsToAttributes=he;exports.selectedFragmentToHTML=Nt;exports.shikiHighlighterPromiseSymbol=Ne;exports.shikiParserSymbol=at;exports.sideMenuPluginKey=Ko;exports.stylePropsToAttributes=un;exports.tableContentToNodes=Ee;exports.tableHandlesPluginKey=ae;exports.updateBlock=yn;exports.updateBlockCommand=A;exports.uploadToTmpFilesDotOrg_DEV_ONLY=Jr;exports.videoBlockConfig=co;exports.videoParse=po;exports.videoPropSchema=lo;exports.videoRender=uo;exports.videoToExternalHTML=ho;exports.withPageBreak=Ns;exports.wrapInBlockStructure=be;
13
13
  //# sourceMappingURL=blocknote.cjs.map