@blocknote/core 0.27.2 → 0.28.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.
- package/dist/blocknote.cjs +10 -10
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1327 -1283
- package/dist/blocknote.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10 -10
- package/dist/locales.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +1 -1
- package/src/api/positionMapping.test.ts +370 -0
- package/src/api/positionMapping.ts +112 -0
- package/src/editor/BlockNoteEditor.ts +1 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -7
- package/src/i18n/locales/de.ts +10 -10
- package/types/src/api/positionMapping.d.ts +25 -0
- package/types/src/api/positionMapping.test.d.ts +1 -0
package/dist/blocknote.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var zn=Object.create;var We=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var qn=Object.getOwnPropertyNames;var jn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Gn=(e,o,t)=>o in e?We(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var Xn=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of qn(o))!Kn.call(e,r)&&r!==t&&We(e,r,{get:()=>o[r],enumerable:!(n=Wn(o,r))||n.enumerable});return e};var V=(e,o,t)=>(t=e!=null?zn(jn(e)):{},Xn(o||!e||!e.__esModule?We(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,o,t)=>Gn(e,typeof o!="symbol"?o+"":o,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("prosemirror-model"),Ie=require("prosemirror-transform"),k=require("@tiptap/core"),y=require("prosemirror-state"),Wt=require("uuid"),Jn=require("prosemirror-highlight"),Yn=require("prosemirror-highlight/shiki"),P=require("prosemirror-tables"),Zn=require("@tiptap/extension-bold"),Qn=require("@tiptap/extension-code"),er=require("@tiptap/extension-italic"),tr=require("@tiptap/extension-strike"),or=require("@tiptap/extension-underline"),nr=require("@tiptap/extension-table-cell"),rr=require("@tiptap/extension-table-header"),sr=require("@tiptap/extension-table-row"),ir=require("@tiptap/extension-gapcursor"),ar=require("@tiptap/extension-history"),lr=require("@tiptap/extension-link"),cr=require("@tiptap/extension-text"),dr=require("@tiptap/extension-collaboration"),ur=require("@tiptap/extension-collaboration-cursor"),x=require("prosemirror-view"),Ge=require("y-prosemirror"),pr=require("prosemirror-dropcursor"),hr=require("./en-D4taoCs4.cjs"),ne=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},fr=ne(Zn),mr=ne(Qn),gr=ne(er),br=ne(tr),kr=ne(or),wr=ne(dr),yr=ne(ur);class F extends Error{constructor(o){super(`Unreachable case: ${o}`)}}function Cr(e,o=!0){const{"data-test":t,...n}=e;if(Object.keys(n).length>0&&o)throw new Error("Object must be empty "+JSON.stringify(e))}function K(e,o){const t=e.resolve(o);if(t.nodeAfter&&t.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:t.pos,node:t.nodeAfter};let n=t.depth,r=t.node(n);for(;n>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:t.before(n),node:r};n--,r=t.node(n)}const s=[];e.descendants((a,l)=>{a.type.isInGroup("bnBlock")&&s.push(l)}),console.warn(`Position ${o} is not within a blockContainer node.`);const i=e.resolve(s.find(a=>a>=o)||s[s.length-1]);return{posBeforeNode:i.pos,node:i.nodeAfter}}function Oe(e,o){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,n=o,r=n+t.nodeSize,s={node:t,beforePos:n,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=n+c+1,h=u+l.nodeSize;i={node:d,beforePos:u,afterPos:h}}else if(l.type.name==="blockGroup"){const d=l,u=n+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 Q(e){return Oe(e.node,e.posBeforeNode)}function ue(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 Oe(e.nodeAfter,e.pos)}function v(e){const o=K(e.doc,e.selection.anchor);return Q(o)}function vr(e,o=JSON.stringify){const t={};return e.filter(n=>{const r=o(n);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Sr(e){const o=e.filter((n,r)=>e.indexOf(n)!==r);return vr(o)}const pe=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 Wt.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 o={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...o,id:e[this.options.attributeName]}:o}}}}]},addProseMirrorPlugins(){let e=null,o=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(t,n,r)=>{const s=t.some(m=>m.docChanged)&&!n.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(n.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),w=Sr(b);g.forEach(({node:C,pos:S})=>{let A;const W=(A=a.doc.nodeAt(S))===null||A===void 0?void 0:A.attrs[c];if(W===null){const E=n.doc.type.createAndFill().content;if(n.doc.content.findDiffStart(E)===null){const re=JSON.parse(JSON.stringify(r.doc.toJSON()));if(re.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(re.content)===JSON.stringify(E.toJSON())){a.setNodeMarkup(S,void 0,{...C.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(S,void 0,{...C.attrs,[c]:d()});return}const{deleted:q}=h.invert().mapResult(S);q&&w.includes(W)&&a.setNodeMarkup(S,void 0,{...C.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const n=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(t,n)=>{let r;return e!==t.dom.parentElement||((r=n.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?o=!0:o=!1,e=null,!1},paste:()=>(o=!0,!1)},transformPasted:t=>{if(!o)return t;const{types:n,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!n.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 o=!1,new B.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function Xe(e){return e.type==="link"}function _e(e){return typeof e!="string"&&e.type==="link"}function G(e){return typeof e!="string"&&e.type==="text"}function Le(e){var o,t,n,r,s;return Re(e)?{...e}:ce(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:((o=e.props)==null?void 0:o.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((n=e.props)==null?void 0:n.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 ce(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function Re(e){return ce(e)&&e.props!==void 0&&e.content!==void 0}function de(e){return Re(e)?e.props.colspan??1:1}function Ae(e){return Re(e)?e.props.rowspan??1:1}const qt=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function j(e,o="Ctrl"){return qt()?e.replace("Mod","⌘"):e.replace("Mod",o)}function X(...e){return e.filter(o=>o).join(" ")}const Er=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function $(e,o,t,n){const r=document.createElement("div");r.className=X("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(o);s.className=X("bn-inline-content",n.class);for(const[i,a]of Object.entries(n))i!=="class"&&s.setAttribute(i,a);return r.appendChild(s),{dom:r,contentDOM:s}}const Je=(e,o)=>{let t=te(e,o.pmSchema,o.schema.styleSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const n=o.pmSchema.nodes[t.type.name].spec.toDOM;if(n===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=n(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"]}},at=["backgroundColor","textColor"];function ke(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Br(e){const o=e.split("/");return!o.length||o[o.length-1]===""?e:o[o.length-1]}function he(e){const o={};return Object.entries(e).filter(([t,n])=>!at.includes(t)).forEach(([t,n])=>{o[t]={default:n.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(ke(t));if(s===null)return null;if(n.default===void 0&&n.type==="boolean"||n.default!==void 0&&typeof n.default=="boolean")return s==="true"?!0:s==="false"?!1:null;if(n.default===void 0&&n.type==="number"||n.default!==void 0&&typeof n.default=="number"){const i=parseFloat(s);return!Number.isNaN(i)&&Number.isFinite(i)?i:null}return s},renderHTML:r=>r[t]!==n.default?{[ke(t)]:r[t]}:{}}}),o}function jt(e,o,t,n){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=o.getBlock(i);if(a.type!==n)throw new Error("Block type does not match");return a}function be(e,o,t,n,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=X("bn-block-content",(s==null?void 0:s.class)||""),i.setAttribute("data-content-type",o);for(const[a,l]of Object.entries(t)){const d=n[a].default;!at.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=X("bn-inline-content",e.contentDOM.className),e.contentDOM.setAttribute("data-editable","")),{...e,dom:i}}function z(e){return k.Node.create(e)}function lt(e,o){return{config:e,implementation:o}}function J(e,o,t){return lt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:o},{node:e,requiredExtensions:t,toInternalHTML:Je,toExternalHTML:Je})}function ct(e){return Object.fromEntries(Object.entries(e).map(([o,t])=>[o,t.config]))}function Kt(e,o){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{o.view.dom.blur()},10),!0)}function Gt(e,o){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:"[data-editable]"}];return o&&t.push({tag:"*",getAttrs(n){if(typeof n=="string")return!1;const r=o==null?void 0:o(n);return r===void 0?!1:r}}),t}function fe(e,o){const t=z({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return he(e.propSchema)},parseHTML(){return Gt(e,o.parse)},renderHTML({HTMLAttributes:n}){const r=document.createElement("div");return be({dom:r,contentDOM:e.content==="inline"?r:void 0},e.type,{},e.propSchema,e.isFileBlock,n)},addNodeView(){return({getPos:n})=>{var c;const r=this.options.editor,s=jt(n,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=o.render(s,r),l=be(a,s.type,s.props,e.propSchema,i);return e.isSelectable===!1&&Kt(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 lt(e,{node:t,toInternalHTML:(n,r)=>{var a;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},i=o.render(n,r);return be(i,n.type,n.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(n,r)=>{var a,l;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let i=(l=o.toExternalHTML)==null?void 0:l.call(o,n,r);return i===void 0&&(i=o.render(n,r)),be(i,n.type,n.props,e.propSchema,s)}})}function dt(e,o,t){var s,i;const n={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)),n.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=>ye(m,o,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],w=g[0];return w&&G(b)&&G(w)&&JSON.stringify(b.styles)===JSON.stringify(w.styles)?(b.text+=`
|
|
2
|
-
`+w.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}})),
|
|
3
|
-
`;else if(
|
|
1
|
+
"use strict";var Wo=Object.create;var Ke=Object.defineProperty;var qo=Object.getOwnPropertyDescriptor;var Ko=Object.getOwnPropertyNames;var jo=Object.getPrototypeOf,Go=Object.prototype.hasOwnProperty;var Xo=(e,n,t)=>n in e?Ke(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Jo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Ko(n))!Go.call(e,r)&&r!==t&&Ke(e,r,{get:()=>n[r],enumerable:!(o=qo(n,r))||o.enumerable});return e};var V=(e,n,t)=>(t=e!=null?Wo(jo(e)):{},Jo(n||!e||!e.__esModule?Ke(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>Xo(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("prosemirror-model"),we=require("prosemirror-transform"),k=require("@tiptap/core"),y=require("prosemirror-state"),qt=require("uuid"),Yo=require("prosemirror-highlight"),Zo=require("prosemirror-highlight/shiki"),M=require("prosemirror-tables"),Qo=require("@tiptap/extension-bold"),er=require("@tiptap/extension-code"),tr=require("@tiptap/extension-italic"),nr=require("@tiptap/extension-strike"),or=require("@tiptap/extension-underline"),rr=require("@tiptap/extension-table-cell"),sr=require("@tiptap/extension-table-header"),ir=require("@tiptap/extension-table-row"),ar=require("@tiptap/extension-gapcursor"),lr=require("@tiptap/extension-history"),cr=require("@tiptap/extension-link"),dr=require("@tiptap/extension-text"),ur=require("@tiptap/extension-collaboration"),pr=require("@tiptap/extension-collaboration-cursor"),x=require("prosemirror-view"),ne=require("y-prosemirror"),hr=require("prosemirror-dropcursor"),fr=require("./en-D4taoCs4.cjs"),re=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},mr=re(Qo),gr=re(er),br=re(tr),kr=re(nr),wr=re(or),yr=re(ur),Cr=re(pr);class F extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Sr(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 j(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 Re(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 Q(e){return Re(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 Re(e.nodeAfter,e.pos)}function S(e){const n=j(e.doc,e.selection.anchor);return Q(n)}function vr(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 Er(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return vr(n)}const he=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 qt.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 y.Plugin({key:new y.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),w=Er(b);g.forEach(({node:C,pos:v})=>{let A;const W=(A=a.doc.nodeAt(v))===null||A===void 0?void 0:A.attrs[c];if(W===null){const E=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(E)===null){const se=JSON.parse(JSON.stringify(r.doc.toJSON()));if(se.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(se.content)===JSON.stringify(E.toJSON())){a.setNodeMarkup(v,void 0,{...C.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(v,void 0,{...C.attrs,[c]:d()});return}const{deleted:q}=h.invert().mapResult(v);q&&w.includes(W)&&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 Je(e){return e.type==="link"}function Ve(e){return typeof e!="string"&&e.type==="link"}function G(e){return typeof e!="string"&&e.type==="text"}function Ne(e){var n,t,o,r,s;return Fe(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 Fe(e){return de(e)&&e.props!==void 0&&e.content!==void 0}function ue(e){return Fe(e)?e.props.colspan??1:1}function He(e){return Fe(e)?e.props.rowspan??1:1}const Kt=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function K(e,n="Ctrl"){return Kt()?e.replace("Mod","⌘"):e.replace("Mod",n)}function X(...e){return e.filter(n=>n).join(" ")}const Br=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function $(e,n,t,o){const r=document.createElement("div");r.className=X("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=X("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 Ye=(e,n)=>{let t=te(e,n.pmSchema,n.schema.styleSchema);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},P={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},lt=["backgroundColor","textColor"];function ye(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Tr(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])=>!lt.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(ye(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?{[ye(t)]:r[t]}:{}}}),n}function jt(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=X("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;!lt.includes(a)&&l!==d&&i.setAttribute(ye(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=X("bn-inline-content",e.contentDOM.className),e.contentDOM.setAttribute("data-editable","")),{...e,dom:i}}function z(e){return k.Node.create(e)}function ct(e,n){return{config:e,implementation:n}}function J(e,n,t){return ct({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:Ye,toExternalHTML:Ye})}function dt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Gt(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function Xt(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=z({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return fe(e.propSchema)},parseHTML(){return Xt(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=jt(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&&Gt(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 ct(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 ut(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=>Se(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],w=g[0];return w&&G(b)&&G(w)&&JSON.stringify(b.styles)===JSON.stringify(w.styles)?(b.text+=`
|
|
2
|
+
`+w.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 Se(e,n,t){const o=[];let r;return e.content.forEach(s=>{if(s.type.name==="hardBreak"){if(r)if(G(r))r.text+=`
|
|
3
|
+
`;else if(Je(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(!
|
|
6
|
-
`?o.nodes.hardBreak.createChecked():o.text(i,r)):[o.text(e.text,r)]}function Nr(e,o,t){const n=o.marks.link.create({href:e.href});return tt(e.content,o,t).map(r=>{if(r.type.name==="text")return r.mark([...r.marks,n]);if(r.type.name==="hardBreak")return r;throw new Error("unexpected node type")})}function tt(e,o,t,n){const r=[];if(typeof e=="string")return r.push(...xt({text:e,styles:{}},o,t,n)),r;for(const s of e)r.push(...xt(s,o,t,n));return r}function R(e,o,t,n){const r=[];for(const s of e)typeof s=="string"?r.push(...tt(s,o,t,n)):_e(s)?r.push(...Nr(s,o,t)):G(s)?r.push(...tt([s],o,t,n)):r.push(so(s,o,t));return r}function Ce(e,o,t){const n=[],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 w=oe({row:a,col:h},{content:e});let C=i[w.col]?[i[w.col]]:null;if(f)if(typeof f=="string")b=o.text(f);else if(ce(f)){f.content&&(b=R(f.content,o,t));const A=de(f);A>1&&(C=new Array(A).fill(!1).map((W,q)=>i[w.col+q]??void 0))}else b=R(f,o,t);const S=o.nodes[m||d?"tableHeader":"tableCell"].createChecked({...ce(f)?f.props:{},colwidth:C},o.nodes.tableParagraph.createChecked(g,b));c.push(S)}const u=o.nodes.tableRow.createChecked({},c);n.push(u)}return n}function so(e,o,t){let n,r=e.type;if(r===void 0&&(r="paragraph"),!o.nodes[r])throw new Error(`node type ${r} not found in schema`);if(!e.content)n=o.nodes[r].createChecked(e.props);else if(typeof e.content=="string"){const s=R([e.content],o,t,r);n=o.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=R(e.content,o,t,r);n=o.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Ce(e.content,o,t);n=o.nodes[r].createChecked(e.props,s)}else throw new F(e.content.type);return n}function te(e,o,t){let n=e.id;n===void 0&&(n=pe.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(te(i,o,t));if(!e.type||o.nodes[e.type].isInGroup("blockContent")){const i=so(e,o,t),a=r.length>0?o.nodes.blockGroup.createChecked({},r):void 0;return o.nodes.blockContainer.createChecked({id:n,...e.props},a?[i,a]:i)}else{if(o.nodes[e.type].isInGroup("bnBlock"))return o.nodes[e.type].createChecked({id:n,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}}function _(e,o){let t,n;if(o.firstChild.descendants((r,s)=>t?!1:!r.type.isInGroup("bnBlock")||r.attrs.id!==e?!0:(t=r,n=s+1,!1)),!(t===void 0||n===void 0))return{node:t,posBeforeNode:n}}const L=(e,o,t)=>({state:n,dispatch:r})=>{const s=ue(n.doc.resolve(o));if(r){const i=n.schema.nodes[s.blockNoteType],a=n.schema.nodes[t.type||s.blockNoteType],l=a.isInGroup("bnBlock")?a:n.schema.nodes.blockContainer;if(s.isBlockContainer&&a.isInGroup("blockContent"))Mt(t,n,e,s),Hr(t,n,e,i,a,s);else if(!s.isBlockContainer&&a.isInGroup("bnBlock"))Mt(t,n,e,s);else{const c=T(s.bnBlock.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache);return n.tr.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,te({children:c.children,...t},n.schema,e.schema.styleSchema)),!0}n.tr.setNodeMarkup(s.bnBlock.beforePos,l,{...s.bnBlock.node.attrs,...t.props})}return!0};function Hr(e,o,t,n,r,s){let i="keep";if(e.content)if(typeof e.content=="string")i=R([e.content],o.schema,t.schema.styleSchema,r.name);else if(Array.isArray(e.content))i=R(e.content,o.schema,t.schema.styleSchema,r.name);else if(e.content.type==="tableContent")i=Ce(e.content,o.schema,t.schema.styleSchema);else throw new F(e.content.type);else n.spec.content===""||r.spec.content!==n.spec.content&&(i=[]);i==="keep"?o.tr.setNodeMarkup(s.blockContent.beforePos,e.type===void 0?void 0:o.schema.nodes[e.type],{...s.blockContent.node.attrs,...e.props}):o.tr.replaceWith(s.blockContent.beforePos,s.blockContent.afterPos,r.createChecked({...s.blockContent.node.attrs,...e.props},i))}function Mt(e,o,t,n){if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>te(s,o.schema,t.schema.styleSchema));if(n.childContainer)o.tr.step(new Ie.ReplaceStep(n.childContainer.beforePos+1,n.childContainer.afterPos-1,new B.Slice(B.Fragment.from(r),0,0)));else{if(!n.isBlockContainer)throw new Error("impossible");o.tr.insert(n.blockContent.afterPos,o.schema.nodes.blockGroup.createChecked({},r))}}}function io(e,o,t){const n=e._tiptapEditor,r=typeof o=="string"?o:o.id,s=_(r,n.state.doc);if(!s)throw new Error(`Block with ID ${r} not found`);n.commands.command(({state:a,dispatch:l})=>(L(e,s.posBeforeNode,t)({state:a,dispatch:l}),!0));const i=n.state.doc.resolve(s.posBeforeNode+1).node();return T(i,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function ao(e){const o=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];o.length>0?e.className=o.join(" "):e.removeAttribute("class")}function lo(e,o,t,n){let r;if(o)if(typeof o=="string")r=R([o],e.pmSchema,e.schema.styleSchema);else if(Array.isArray(o))r=R(o,e.pmSchema,e.schema.styleSchema);else if(o.type==="tableContent")r=Ce(o,e.pmSchema,e.schema.styleSchema);else throw new F(o.type);else throw new Error("blockContent is required");const s=t.serializeFragment(B.Fragment.from(r),n);return s.nodeType===1&&ao(s),s}function Dr(e,o,t,n,r,s,i){var g,b,w,C,S,A,W,q;const a=(i==null?void 0:i.document)??document,l=o.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[I,E]of Object.entries(o.schema.blockSchema[t.type].propSchema))E.default!==void 0&&(c[I]=E.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=o.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},o),f=a.createDocumentFragment();if(h.dom.classList.contains("bn-block-content")){const I=[...u,...Array.from(h.dom.attributes)].filter(E=>E.name.startsWith("data")&&E.name!=="data-content-type"&&E.name!=="data-file-block"&&E.name!=="data-node-view-wrapper"&&E.name!=="data-node-type"&&E.name!=="data-id"&&E.name!=="data-index"&&E.name!=="data-editable");for(const E of I)h.dom.firstChild.setAttribute(E.name,E.value);ao(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const I=lo(o,t.content,n,i);h.contentDOM.appendChild(I)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((w=e.lastChild)==null?void 0:w.nodeName)!==m){const E=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&E.setAttribute("start",c.start+""),e.append(E)}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(co(I,o,t.children,n,r,s,i),((C=e.lastChild)==null?void 0:C.nodeName)==="UL"||((S=e.lastChild)==null?void 0:S.nodeName)==="OL")for(;((A=I.firstChild)==null?void 0:A.nodeName)==="UL"||((W=I.firstChild)==null?void 0:W.nodeName)==="OL";)e.lastChild.lastChild.appendChild(I.firstChild);o.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(I):(q=h.contentDOM)==null||q.append(I)}}const co=(e,o,t,n,r,s,i)=>{for(const a of t)Dr(e,o,a,n,r,s,i)},Or=(e,o,t,n,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return co(a,e,o,t,n,r,s),a},ve=(e,o)=>{const t=B.DOMSerializer.fromSchema(e);return{exportBlocks:(n,r)=>{const s=Or(o,n,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(n,r)=>{const s=lo(o,n,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function _r(e,o,t,n,r){let s;if(o)if(typeof o=="string")s=R([o],e.pmSchema,e.schema.styleSchema,n);else if(Array.isArray(o))s=R(o,e.pmSchema,e.schema.styleSchema,n);else if(o.type==="tableContent")s=Ce(o,e.pmSchema,e.schema.styleSchema);else throw new F(o.type);else throw new Error("blockContent is required");return t.serializeFragment(B.Fragment.from(s),r)}function Rr(e,o,t,n,r){var u,h,f,m,g;const s=e.pmSchema.nodes.blockContainer;let i=o.props;if(!o.props){i={};for(const[b,w]of Object.entries(e.schema.blockSchema[o.type].propSchema))w.default!==void 0&&(i[b]=w.default)}const l=e.blockImplementations[o.type].implementation.toInternalHTML({...o,props:i},e);if(o.type==="numberedListItem"&&l.dom.setAttribute("data-index",n.toString()),l.contentDOM&&o.content){const b=_r(e,o.content,t,o.type,r);l.contentDOM.appendChild(b)}if(e.pmSchema.nodes[o.type].isInGroup("bnBlock")){if(o.children&&o.children.length>0){const b=uo(e,o.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:o.id,...i}));return(m=d.contentDOM)==null||m.appendChild(l.dom),o.children&&o.children.length>0&&((g=d.contentDOM)==null||g.appendChild(po(e,o.children,t,r))),d.dom}function uo(e,o,t,n){const s=((n==null?void 0:n.document)??document).createDocumentFragment();let i=0;for(const a of o){a.type==="numberedListItem"?i++:i=0;const l=Rr(e,a,t,i,n);s.appendChild(l)}return s}const po=(e,o,t,n)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=uo(e,o,t,n);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},ho=(e,o)=>{const t=B.DOMSerializer.fromSchema(e);return{serializeBlocks:(n,r)=>po(o,n,t,r).outerHTML}},Se=(e,o)=>{const t=e.querySelector(o);if(!t)return;const n=e.querySelector("figcaption"),r=(n==null?void 0:n.textContent)??void 0;return{targetElement:t,caption:r}},fo=(e,o,t,n)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",n?s.appendChild(n):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||o.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{o.dispatch(o._tiptapEditor.state.tr.setMeta(o.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)}}},mo='<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>',go=e=>{const o=document.createElement("div");o.className="bn-file-name-with-icon";const t=document.createElement("div");t.className="bn-file-icon",t.innerHTML=mo,o.appendChild(t);const n=document.createElement("p");return n.className="bn-file-name",n.textContent=e.props.name,o.appendChild(n),{dom:o}},Ve=(e,o,t,n,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=fo(e,o,n,r);s.appendChild(a.dom);const l=o.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=go(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},Fe=(e,o)=>{const t=document.createElement("figure"),n=document.createElement("figcaption");return n.textContent=o,t.appendChild(e),t.appendChild(n),{dom:t}},Ee=(e,o)=>{const t=document.createElement("div"),n=document.createElement("p");return n.textContent=o,t.appendChild(e),t.appendChild(n),{dom:t}},Pt=e=>({url:e.src||void 0}),bo='<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>',ko={backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},wo={type:"audio",propSchema:ko,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},yo=(e,o)=>{const t=document.createElement("div");t.innerHTML=bo;const n=document.createElement("audio");return n.className="bn-audio",o.resolveFileUrl?o.resolveFileUrl(e.props.url).then(r=>{n.src=r}):n.src=e.props.url,n.controls=!0,n.contentEditable="false",n.draggable=!1,Ve(e,o,{dom:n},o.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Co=e=>{if(e.tagName==="AUDIO")return Pt(e);if(e.tagName==="FIGURE"){const o=Se(e,"audio");if(!o)return;const{targetElement:t,caption:n}=o;return{...Pt(t),caption:n}}},vo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let o;return e.props.showPreview?(o=document.createElement("audio"),o.src=e.props.url):(o=document.createElement("a"),o.href=e.props.url,o.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Fe(o,e.props.caption):Ee(o,e.props.caption):{dom:o}},So=fe(wo,{render:yo,parse:Co,toExternalHTML:vo}),ot=Symbol.for("blocknote.shikiParser"),Me=Symbol.for("blocknote.shikiHighlighterPromise"),Eo={language:{default:"text"}},Vr=z({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:o=>{let t=o,n=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)n=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&&(n=i[0].toLowerCase())}return n?It(e.editor.settings.codeBlock,n):null},renderHTML:o=>o.language?{class:`language-${o.language}`,"data-language":o.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 o=document.createElement("pre"),{dom:t,contentDOM:n}=$(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(n),t.appendChild(o),o.appendChild(n),{dom:t,contentDOM:n}},addNodeView(){const e=this.options;return({editor:o,node:t,getPos:n,HTMLAttributes:r})=>{var u,h;const s=document.createElement("pre"),i=document.createElement("select"),a=document.createElement("div"),{dom:l,contentDOM:c}=$(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;o.commands.command(({tr:g})=>(g.setNodeAttribute(n(),"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,o=globalThis;let t,n,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 o[Me]=o[Me]||e.editor.settings.codeBlock.createHighlighter(),o[Me].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):(n||(n=o[ot]||Yn.createParser(t),o[ot]=n),n(a))};return[Jn.createHighlightPlugin({parser:s,languageExtractor:a=>a.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new k.InputRule({find:/^```(.*?)\s$/,handler:({state:o,range:t,match:n})=>{const r=o.doc.resolve(t.from),s=n[1].trim(),i={language:It(e.editor.settings.codeBlock,s)};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;o.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(y.TextSelection.create(o.tr.doc,t.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:o}=e.state,{$from:t}=o;if(e.isActive(this.name)&&!t.parent.textContent&&k.isTextSelection(o)){const n=t.pos-t.parentOffset-2;return e.chain().setNodeSelection(n).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:o}=e.state.selection;if(!e.isActive(this.name))return!1;const t=o.parentOffset===o.parent.nodeSize-2,n=o.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(De(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 F(c.propSchema)}r?G(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}):Je(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 De(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=Se(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function T(e,n,t,o,r){var m;if(!e.type.isInGroup("bnBlock"))throw Error("Node must be in bnBlock group, but is of type"+e.type.name);const s=r==null?void 0:r.get(e);if(s)return s;const i=Re(e,0);let a=i.bnBlock.node.attrs.id;a===null&&(a=he.options.generateID());const l=n[i.blockNoteType];if(!l)throw Error("Block is of an unrecognized type: "+i.blockNoteType);const c={};for(const[g,b]of Object.entries({...e.attrs,...i.isBlockContainer?i.blockContent.node.attrs:{}})){const w=l.propSchema;g in w&&!(w[g].default===void 0&&b===void 0)&&(c[g]=b)}const d=n[i.blockNoteType],u=[];(m=i.childContainer)==null||m.node.forEach(g=>{u.push(T(g,n,t,o,r))});let h;if(d.content==="inline"){if(!i.isBlockContainer)throw new Error("impossible");h=Se(i.blockContent.node,t,o)}else if(d.content==="table"){if(!i.isBlockContainer)throw new Error("impossible");h=ut(i.blockContent.node,t,o)}else if(d.content==="none")h=void 0;else throw new F(d.content);const f={id:a,type:d.type,props:c,content:h,children:u};return r==null||r.set(e,f),f}function Ze(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])=>[ye(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function Jt(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 Yt(e,n){return{config:e,implementation:n}}function Zt(e,n){return Yt({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function pt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Qt(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 xr(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 Jt(e)},parseHTML(){return Qt(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render(De(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return Ze(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render(De(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=R([a],s._tiptapEditor.schema,s.schema.styleSchema);s.dispatch(s.prosemirrorView.state.tr.replaceWith(r(),r()+o.nodeSize,l))},s);return Ze(i,e.type,o.attrs,e.propSchema)}}});return Zt(t,e.propSchema)}function en(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 tn(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 ht(e,n){return{config:e,implementation:n}}function Z(e,n){return ht({type:e.name,propSchema:n},{mark:e})}function ft(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function nn(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 Pr(e,n){const t=k.Mark.create({name:e.type,addAttributes(){return en(e.propSchema)},parseHTML(){return nn(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 F(e.propSchema);return tn(r,e.type,o.attrs.stringValue,e.propSchema)}});return ht(e,{mark:t})}function ee(e){const{height:n,width:t}=mt(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=Ne(e.content.rows[s].cells[i]),l=He(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 Ce(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 oe(e,n,t=ee(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 mt(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 on(e,n,t=ee(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 Qe(e,n){var s;const t=ee(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)=>on({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 et(e,n){var s;const t=ee(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)=>on({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 Mr(e,n,t,o=ee(e)){const{col:r}=oe({row:0,col:n},e,o),{col:s}=oe({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),Ce(o)}function Ir(e,n,t,o=ee(e)){const{row:r}=oe({row:n,col:0},e,o),{row:s}=oe({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),Ce(o)}function tt(e){return e?de(e)?tt(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:G(n)?n.text.length===0:Ve(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function Lr(e,n,t=ee(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>tt(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 Ce(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>tt(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),Ce(t)}function Ar(e,n,t,o=ee(e)){const{width:r,height:s}=mt(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:Ne("")});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:Ne("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return Ce(o)}function rn(e,n,t){const o=Qe(e,t);if(!o.some(l=>He(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=He(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function sn(e,n,t){const o=et(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 Nr(e,n,t){const o=oe(e,t),r=oe(n,t);return o.col===r.col}function Pt(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 F(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 Hr(e,n,t){const o=n.marks.link.create({href:e.href});return nt(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 nt(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Pt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Pt(s,n,t,o));return r}function R(e,n,t,o){const r=[];for(const s of e)typeof s=="string"?r.push(...nt(s,n,t,o)):Ve(s)?r.push(...Hr(s,n,t)):G(s)?r.push(...nt([s],n,t,o)):r.push(an(s,n,t));return r}function ve(e,n,t){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 w=oe({row:a,col:h},{content:e});let C=i[w.col]?[i[w.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(de(f)){f.content&&(b=R(f.content,n,t));const A=ue(f);A>1&&(C=new Array(A).fill(!1).map((W,q)=>i[w.col+q]??void 0))}else b=R(f,n,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 an(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=R([e.content],n,t,r);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=R(e.content,n,t,r);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=ve(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new F(e.content.type);return o}function te(e,n,t){let o=e.id;o===void 0&&(o=he.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(te(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=an(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:!r.type.isInGroup("bnBlock")||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}const L=(e,n,t)=>({state:o,dispatch:r})=>{const s=pe(o.doc.resolve(n));if(r){const i=o.schema.nodes[s.blockNoteType],a=o.schema.nodes[t.type||s.blockNoteType],l=a.isInGroup("bnBlock")?a:o.schema.nodes.blockContainer;if(s.isBlockContainer&&a.isInGroup("blockContent"))Mt(t,o,e,s),Dr(t,o,e,i,a,s);else if(!s.isBlockContainer&&a.isInGroup("bnBlock"))Mt(t,o,e,s);else{const c=T(s.bnBlock.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache);return o.tr.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,te({children:c.children,...t},o.schema,e.schema.styleSchema)),!0}o.tr.setNodeMarkup(s.bnBlock.beforePos,l,{...s.bnBlock.node.attrs,...t.props})}return!0};function Dr(e,n,t,o,r,s){let i="keep";if(e.content)if(typeof e.content=="string")i=R([e.content],n.schema,t.schema.styleSchema,r.name);else if(Array.isArray(e.content))i=R(e.content,n.schema,t.schema.styleSchema,r.name);else if(e.content.type==="tableContent")i=ve(e.content,n.schema,t.schema.styleSchema);else throw new F(e.content.type);else o.spec.content===""||r.spec.content!==o.spec.content&&(i=[]);i==="keep"?n.tr.setNodeMarkup(s.blockContent.beforePos,e.type===void 0?void 0:n.schema.nodes[e.type],{...s.blockContent.node.attrs,...e.props}):n.tr.replaceWith(s.blockContent.beforePos,s.blockContent.afterPos,r.createChecked({...s.blockContent.node.attrs,...e.props},i))}function Mt(e,n,t,o){if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>te(s,n.schema,t.schema.styleSchema));if(o.childContainer)n.tr.step(new we.ReplaceStep(o.childContainer.beforePos+1,o.childContainer.afterPos-1,new B.Slice(B.Fragment.from(r),0,0)));else{if(!o.isBlockContainer)throw new Error("impossible");n.tr.insert(o.blockContent.afterPos,n.schema.nodes.blockGroup.createChecked({},r))}}}function ln(e,n,t){const o=e._tiptapEditor,r=typeof n=="string"?n:n.id,s=_(r,o.state.doc);if(!s)throw new Error(`Block with ID ${r} not found`);o.commands.command(({state:a,dispatch:l})=>(L(e,s.posBeforeNode,t)({state:a,dispatch:l}),!0));const i=o.state.doc.resolve(s.posBeforeNode+1).node();return T(i,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}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 dn(e,n,t,o){let r;if(n)if(typeof n=="string")r=R([n],e.pmSchema,e.schema.styleSchema);else if(Array.isArray(n))r=R(n,e.pmSchema,e.schema.styleSchema);else if(n.type==="tableContent")r=ve(n,e.pmSchema,e.schema.styleSchema);else throw new F(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 Or(e,n,t,o,r,s,i){var g,b,w,C,v,A,W,q;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,E]of Object.entries(n.schema.blockSchema[t.type].propSchema))E.default!==void 0&&(c[I]=E.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(E=>E.name.startsWith("data")&&E.name!=="data-content-type"&&E.name!=="data-file-block"&&E.name!=="data-node-view-wrapper"&&E.name!=="data-node-type"&&E.name!=="data-id"&&E.name!=="data-index"&&E.name!=="data-editable");for(const E of I)h.dom.firstChild.setAttribute(E.name,E.value);cn(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const I=dn(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(((w=e.lastChild)==null?void 0:w.nodeName)!==m){const E=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&E.setAttribute("start",c.start+""),e.append(E)}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(un(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(;((A=I.firstChild)==null?void 0:A.nodeName)==="UL"||((W=I.firstChild)==null?void 0:W.nodeName)==="OL";)e.lastChild.lastChild.appendChild(I.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(I):(q=h.contentDOM)==null||q.append(I)}}const un=(e,n,t,o,r,s,i)=>{for(const a of t)Or(e,n,a,o,r,s,i)},_r=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return un(a,e,n,t,o,r,s),a},Ee=(e,n)=>{const t=B.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=_r(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=dn(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function Rr(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=R([n],e.pmSchema,e.schema.styleSchema,o);else if(Array.isArray(n))s=R(n,e.pmSchema,e.schema.styleSchema,o);else if(n.type==="tableContent")s=ve(n,e.pmSchema,e.schema.styleSchema);else throw new F(n.type);else throw new Error("blockContent is required");return t.serializeFragment(B.Fragment.from(s),r)}function Vr(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,w]of Object.entries(e.schema.blockSchema[n.type].propSchema))w.default!==void 0&&(i[b]=w.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=Rr(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=pn(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(hn(e,n.children,t,r))),d.dom}function pn(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=Vr(e,a,t,i,o);s.appendChild(l)}return s}const hn=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=pn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},fn=(e,n)=>{const t=B.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>hn(n,o,t,r).outerHTML}},Be=(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}},mn=(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.dispatch(n._tiptapEditor.state.tr.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)}}},gn='<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=gn,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},Ue=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=mn(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},$e=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Te=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},It=e=>({url:e.src||void 0}),kn='<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>',wn={backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},yn={type:"audio",propSchema:wn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Cn=(e,n)=>{const t=document.createElement("div");t.innerHTML=kn;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,Ue(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Sn=e=>{if(e.tagName==="AUDIO")return It(e);if(e.tagName==="FIGURE"){const n=Be(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...It(t),caption:o}}},vn=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?$e(n,e.props.caption):Te(n,e.props.caption):{dom:n}},En=me(yn,{render:Cn,parse:Sn,toExternalHTML:vn}),ot=Symbol.for("blocknote.shikiParser"),Le=Symbol.for("blocknote.shikiHighlighterPromise"),Bn={language:{default:"text"}},Fr=z({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?Lt(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}=$(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}=$(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[Le]=n[Le]||e.editor.settings.codeBlock.createHighlighter(),n[Le].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[ot]||Zo.createParser(t),n[ot]=o),o(a))};return[Yo.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:Lt(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(y.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
|
-
`);return!t||!
|
|
9
|
-
`),!0):e.chain().command(({tr:r})=>(r.delete(o.pos-2,o.pos),!0)).exitCode().run()},"Shift-Enter":({editor:e})=>{const{$from:o}=e.state.selection;return e.isActive(this.name)?(e.chain().insertContentAt(o.pos-o.parentOffset+o.parent.nodeSize,{type:"paragraph"}).run(),!0):!1}}}}),Bo=J(Vr,Eo);function It(e,o){var t;return((t=Object.entries(e.supportedLanguages).find(([n,{aliases:r}])=>(r==null?void 0:r.includes(o))||n===o))==null?void 0:t[0])||o}const nt=e=>({url:e.src||void 0}),To={backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},xo={type:"file",propSchema:To,content:"none",isFileBlock:!0},Mo=(e,o)=>Ve(e,o),Po=e=>{if(e.tagName==="EMBED")return nt(e);if(e.tagName==="FIGURE"){const o=Se(e,"embed");if(!o)return;const{targetElement:t,caption:n}=o;return{...nt(t),caption:n}}},Io=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add file",{dom:t}}const o=document.createElement("a");return o.href=e.props.url,o.textContent=e.props.name||e.props.url,e.props.caption?Ee(o,e.props.caption):{dom:o}},Lo=fe(xo,{render:Mo,parse:Po,toExternalHTML:Io}),mt=(e,o,t,n,r,s)=>{const{dom:i,destroy:a}=Ve(e,o,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=S=>{if(!u){!o.isEditable&&n.contains(c)&&n.contains(d)&&(n.removeChild(c),n.removeChild(d));return}let A;e.props.textAlignment==="center"?u.handleUsed==="left"?A=u.initialWidth+(u.initialClientX-S.clientX)*2:A=u.initialWidth+(S.clientX-u.initialClientX)*2:u.handleUsed==="left"?A=u.initialWidth+u.initialClientX-S.clientX:A=u.initialWidth+S.clientX-u.initialClientX,h=Math.max(A,64),l.style.width=`${h}px`},m=S=>{(!S.target||!l.contains(S.target)||!o.isEditable)&&n.contains(c)&&n.contains(d)&&(n.removeChild(c),n.removeChild(d)),u&&(u=void 0,o.updateBlock(e,{props:{previewWidth:h}}))},g=()=>{o.isEditable&&(n.appendChild(c),n.appendChild(d))},b=S=>{S.relatedTarget===c||S.relatedTarget===d||u||o.isEditable&&n.contains(c)&&n.contains(d)&&(n.removeChild(c),n.removeChild(d))},w=S=>{S.preventDefault(),u={handleUsed:"left",initialWidth:l.clientWidth,initialClientX:S.clientX}},C=S=>{S.preventDefault(),u={handleUsed:"right",initialWidth:l.clientWidth,initialClientX:S.clientX}};return window.addEventListener("mousemove",f),window.addEventListener("mouseup",m),l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",b),c.addEventListener("mousedown",w),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",w),d.removeEventListener("mousedown",C)}}},Fr=async e=>{const o=new FormData;return o.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:o})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},Lt=e=>{const o=e.src||void 0,t=e.width||void 0;return{url:o,previewWidth:t}},Ao='<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>',No={textAlignment:M.textAlignment,backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},Ho={type:"image",propSchema:No,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},Do=(e,o)=>{const t=document.createElement("div");t.innerHTML=Ao;const n=document.createElement("div");n.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",o.resolveFileUrl?o.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,n.appendChild(r),mt(e,o,{dom:n},n,o.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},Oo=e=>{if(e.tagName==="IMG")return Lt(e);if(e.tagName==="FIGURE"){const o=Se(e,"img");if(!o)return;const{targetElement:t,caption:n}=o;return{...Lt(t),caption:n}}},_o=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add image",{dom:t}}let o;return e.props.showPreview?(o=document.createElement("img"),o.src=e.props.url,o.alt=e.props.name||e.props.caption||"BlockNote image",o.width=e.props.previewWidth):(o=document.createElement("a"),o.href=e.props.url,o.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Fe(o,e.props.caption):Ee(o,e.props.caption):{dom:o}},Ro=fe(Ho,{render:Do,parse:Oo,toExternalHTML:_o}),Vo={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Fo=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},Uo=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},$o=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},zo=fe(Vo,{render:Fo,parse:Uo,toExternalHTML:$o}),Ur=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]}}),$r=Z(Ur,"string"),zr=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]}}),Wr=Z(zr,"string"),Wo={...M,level:{default:1,values:[1,2,3]}},qr=z({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return he(Wo)},addInputRules(){return[...[1,2,3].map(e=>new k.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:o,chain:t,range:n})=>{const r=v(o);!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||t().command(L(this.options.editor,r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:n.from,to:n.to}).run()}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"heading",props:{level:1}}))},"Mod-Alt-2":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"heading",props:{level:2}}))},"Mod-Alt-3":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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:o}){var t,n;return $(this.name,`h${e.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...o},((n=this.options.domAttributes)==null?void 0:n.inlineContent)||{})}}),jr=J(qr,Wo),qo=(e,o,t)=>({state:n,dispatch:r})=>{const s=K(n.doc,e),i=Q(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:o?i.blockContent.node.type:n.schema.nodes.paragraph,attrs:t?{...i.blockContent.node.attrs}:{}}];return r&&n.tr.split(e,2,a),!0},gt=e=>{const o=e._tiptapEditor,t=v(o.state);if(!t.isBlockContainer)return!1;const{bnBlock:n,blockContent:r}=t,s=o.state.selection.anchor===o.state.selection.head;return!(r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!s?!1:o.commands.first(({state:i,chain:a,commands:l})=>[()=>l.command(()=>r.node.childCount===0?l.command(L(e,n.beforePos,{type:"paragraph",props:{}})):!1),()=>l.command(()=>r.node.childCount>0?(a().deleteSelection().command(qo(i.selection.from,!0)).run(),!0):!1)])},Kr={...M},Gr=z({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new k.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:o,range:t})=>{const n=v(e);!n.isBlockContainer||n.blockContent.node.type.spec.content!=="inline*"||o().command(L(this.options.editor,n.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>gt(this.options.editor),"Mod-Shift-8":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 o=e.parentElement;return o===null?!1:o.tagName==="UL"||o.tagName==="DIV"&&o.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:e=>{if(typeof e=="string")return!1;const o=e.parentElement;return o===null?!1:o.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var o,t;return $(this.name,"p",{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Xr=J(Gr,Kr),jo={...M,checked:{default:!1}},Jr=z({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return he(jo)},addInputRules(){return[new k.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:o,range:t})=>{const n=v(e);!n.isBlockContainer||n.blockContent.node.type.spec.content!=="inline*"||o().command(L(this.options.editor,n.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:o,range:t})=>{const n=v(e);!n.isBlockContainer||n.blockContent.node.type.spec.content!=="inline*"||o().command(L(this.options.editor,n.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>gt(this.options.editor),"Mod-Shift-9":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 o=e.parentElement;if(o===null)return!1;if(o.tagName==="UL"||o.tagName==="DIV"&&o.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:o}){var s,i;const t=document.createElement("input");t.type="checkbox",t.checked=e.attrs.checked,e.attrs.checked&&t.setAttribute("checked","");const{dom:n,contentDOM:r}=$(this.name,"p",{...((s=this.options.domAttributes)==null?void 0:s.blockContent)||{},...o},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{});return n.insertBefore(t,r),{dom:n,contentDOM:r}},addNodeView(){return({node:e,getPos:o,editor:t,HTMLAttributes:n})=>{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 o!="boolean"){const h=K(t.state.doc,o());if(h.node.type.name!=="blockContainer")throw new Error(`Expected blockContainer node, got ${h.node.type.name}`);this.editor.commands.command(L(this.options.editor,h.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=$(this.name,"p",{...((d=this.options.domAttributes)==null?void 0:d.blockContent)||{},...n},((u=this.options.domAttributes)==null?void 0:u.inlineContent)||{});if(typeof o!="boolean"){const f="label-"+this.editor.state.doc.resolve(o()).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)}}}}}),Yr=J(Jr,jo),Zr=new y.PluginKey("numbered-list-indexing"),Qr=()=>new y.Plugin({key:Zr,appendTransaction:(e,o,t)=>{const n=t.tr;n.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=Q({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=n.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=Q({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;n.setNodeMarkup(c.blockContent.beforePos,void 0,{...g,index:l,...typeof m=="number"&&f&&{start:m}})}}}),r?n:null}}),Ko={...M,start:{default:void 0,type:"number"}},es=z({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...he(Ko),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:o,range:t,match:n})=>{const r=v(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem")return;const s=parseInt(n[1]);o().command(L(this.options.editor,r.bnBlock.beforePos,{type:"numberedListItem",props:s===1&&{}||{start:s}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>gt(this.options.editor),"Mod-Shift-7":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[Qr()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const o=e.parentElement;if(o===null)return!1;if(o.tagName==="OL"||o.tagName==="DIV"&&o.parentElement.tagName==="OL"){const t=parseInt(o.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 o=e.parentElement;return o===null?!1:o.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var o,t;return $(this.name,"p",{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ts=J(es,Ko),os={...M},ns=z({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,getAttrs:e=>{var o;return typeof e=="string"||!((o=e.textContent)!=null&&o.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var o,t;return $(this.name,"p",{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),rs=J(ns,os),ss={...M},is=z({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new k.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:o,range:t})=>{const n=v(e);!n.isBlockContainer||n.blockContent.node.type.spec.content!=="inline*"||o().command(L(this.options.editor,n.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=v(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"blockquote",node:"quote"}]},renderHTML({HTMLAttributes:e}){var o,t;return $(this.name,"blockquote",{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),as=J(is,ss),ls=35,bt=120,cs=31,ds=k.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[P.columnResizing({cellMinWidth:ls,defaultCellMinWidth:bt,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,o=e.empty,t=e.$head.parentOffset===0,n=e.$head.node().type.name==="tableParagraph";return o&&t&&n},Tab:()=>this.editor.commands.command(({state:e,dispatch:o,view:t})=>P.goToNextCell(1)(e,o,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:o,view:t})=>P.goToNextCell(-1)(e,o,t))}},extendNodeSchema(e){const o={name:e.name,options:e.options,storage:e.storage};return{tableRole:k.callOrReturn(k.getExtensionField(e,"tableRole",o))}}}),us={textColor:M.textColor},ps=z({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var o,t;return $(this.name,"table",{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:o})=>{var n;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=X("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,bt,{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...o})}}}),hs=z({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 o=e.parentElement;return o===null?!1:o.tagName==="TD"?{}:!1}}]},renderHTML({HTMLAttributes:e}){return["p",e,0]}}),fs=J(ps,us,[ds,hs,rr.TableHeader.extend({content:"tableContent+"}),nr.TableCell.extend({content:"tableContent+"}),sr.TableRow]),At=e=>{const o=e.src||void 0,t=e.width||void 0;return{url:o,previewWidth:t}},Go='<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>',Xo={textAlignment:M.textAlignment,backgroundColor:M.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},Jo={type:"video",propSchema:Xo,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},Yo=(e,o)=>{const t=document.createElement("div");t.innerHTML=Go;const n=document.createElement("div");n.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",o.resolveFileUrl?o.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,n.appendChild(r),mt(e,o,{dom:n},n,o.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},Zo=e=>{if(e.tagName==="VIDEO")return At(e);if(e.tagName==="FIGURE"){const o=Se(e,"video");if(!o)return;const{targetElement:t,caption:n}=o;return{...At(t),caption:n}}},Qo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add video",{dom:t}}let o;return e.props.showPreview?(o=document.createElement("video"),o.src=e.props.url,o.width=e.props.previewWidth):(o=document.createElement("a"),o.href=e.props.url,o.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Fe(o,e.props.caption):Ee(o,e.props.caption):{dom:o}},en=fe(Jo,{render:Yo,parse:Zo,toExternalHTML:Qo}),kt={paragraph:rs,heading:jr,quote:as,codeBlock:Bo,bulletListItem:Xr,numberedListItem:ts,checkListItem:Yr,table:fs,file:Lo,image:Ro,video:en,audio:So},tn=ct(kt),wt={bold:Z(fr.default,"boolean"),italic:Z(gr.default,"boolean"),underline:Z(kr.default,"boolean"),strike:Z(br.default,"boolean"),code:Z(mr.default,"boolean"),textColor:Wr,backgroundColor:$r},ms=ht(wt),yt={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},on=ut(yt);function H(e,o){return e in o.schema.blockSchema&&o.schema.blockSchema[e]===tn[e]}function nn(e,o){return e in o.schema.inlineContentSchema&&o.schema.inlineContentSchema[e]===on[e]}function rn(e,o,t){return o.type===e&&o.type in t.schema.blockSchema&&H(o.type,t)}function gs(e,o){return e.type in o.schema.blockSchema&&o.schema.blockSchema[e.type].isFileBlock||!1}function bs(e,o){return e.type in o.schema.blockSchema&&o.schema.blockSchema[e.type].isFileBlock&&"showPreview"in o.schema.blockSchema[e.type].propSchema||!1}function ks(e,o){return o.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function sn(e,o,t){return o in t.schema.blockSchema&&e in t.schema.blockSchema[o].propSchema&&t.schema.blockSchema[o].propSchema[e]===M[e]}function ws(e,o,t){return sn(e,o.type,t)}function rt(e){return e instanceof P.CellSelection}function ys(e){let o=e.getTextCursorPosition().block,t=e.schema.blockSchema[o.type].content;for(;t==="none";){if(o=e.getTextCursorPosition().nextBlock,o===void 0)return;t=e.schema.blockSchema[o.type].content,e.setTextCursorPosition(o,"end")}}function N(e,o){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 n;return Array.isArray(t.content)&&(t.content.length===1&&G(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?(n=e.updateBlock(t,o),e.setTextCursorPosition(n)):(n=e.insertBlocks([o],t,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),ys(e),n}function Cs(e){const o=[];return H("heading",e)&&o.push({onItemClick:()=>{N(e,{type:"heading",props:{level:1}})},badge:j("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{N(e,{type:"heading",props:{level:2}})},badge:j("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{N(e,{type:"heading",props:{level:3}})},badge:j("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),H("quote",e)&&o.push({onItemClick:()=>{N(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),H("numberedListItem",e)&&o.push({onItemClick:()=>{N(e,{type:"numberedListItem"})},badge:j("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),H("bulletListItem",e)&&o.push({onItemClick:()=>{N(e,{type:"bulletListItem"})},badge:j("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),H("checkListItem",e)&&o.push({onItemClick:()=>{N(e,{type:"checkListItem"})},badge:j("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),H("paragraph",e)&&o.push({onItemClick:()=>{N(e,{type:"paragraph"})},badge:j("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),H("codeBlock",e)&&o.push({onItemClick:()=>{N(e,{type:"codeBlock"})},badge:j("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),H("table",e)&&o.push({onItemClick:()=>{N(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),H("image",e)&&o.push({onItemClick:()=>{const t=N(e,{type:"image"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"image",...e.dictionary.slash_menu.image}),H("video",e)&&o.push({onItemClick:()=>{const t=N(e,{type:"video"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"video",...e.dictionary.slash_menu.video}),H("audio",e)&&o.push({onItemClick:()=>{const t=N(e,{type:"audio"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),H("file",e)&&o.push({onItemClick:()=>{const t=N(e,{type:"file"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"file",...e.dictionary.slash_menu.file}),o.push({onItemClick:()=>{e.openSuggestionMenu(":",{deleteTriggerCharacter:!0,ignoreQueryLength:!0})},key:"emoji",...e.dictionary.slash_menu.emoji}),o}function vs(e,o){return e.filter(({title:t,aliases:n})=>t.toLowerCase().includes(o.toLowerCase())||n&&n.filter(r=>r.toLowerCase().includes(o.toLowerCase())).length!==0)}function qe(e){return e&&Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0))}class me{constructor(o){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=qe(o==null?void 0:o.blockSpecs)||kt,this.inlineContentSpecs=qe(o==null?void 0:o.inlineContentSpecs)||yt,this.styleSpecs=qe(o==null?void 0:o.styleSpecs)||wt,this.blockSchema=ct(this.blockSpecs),this.inlineContentSchema=ut(this.inlineContentSpecs),this.styleSchema=ht(this.styleSpecs)}static create(o){return new me(o)}}const Ct=me.create({blockSpecs:{pageBreak:zo}}),Ss=e=>me.create({blockSpecs:{...e.blockSpecs,...Ct.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function an(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===Ct.blockSchema.pageBreak}function Es(e){const o=[];return an(e)&&o.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{N(e,{type:"pageBreak"})},key:"page_break"}),o}function Bs(e,o,t,n="before"){const r=typeof t=="string"?t:t.id,s=[];for(const l of o)s.push(te(l,e.pmSchema,e.schema.styleSchema));const i=_(r,e._tiptapEditor.state.doc);if(!i)throw new Error(`Block with ID ${r} not found`);n==="before"&&e.dispatch(e._tiptapEditor.state.tr.insert(i.posBeforeNode,s)),n==="after"&&e.dispatch(e._tiptapEditor.state.tr.insert(i.posBeforeNode+i.node.nodeSize,s));const a=[];for(const l of s)a.push(T(l,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return a}function Ts(e){const o=e._tiptapEditor.state,t=o.selection,n=K(o.doc,t.anchor);if(t instanceof P.CellSelection)return{type:"cell",anchorBlockId:n.node.attrs.id,anchorCellOffset:t.$anchorCell.pos-n.posBeforeNode,headCellOffset:t.$headCell.pos-n.posBeforeNode};if(e._tiptapEditor.state.selection instanceof y.NodeSelection)return{type:"node",anchorBlockId:n.node.attrs.id};{const r=K(o.doc,t.head);return{type:"text",anchorBlockId:n.node.attrs.id,headBlockId:r.node.attrs.id,anchorOffset:t.anchor-n.posBeforeNode,headOffset:t.head-r.posBeforeNode}}}function xs(e,o){var r,s;const t=(r=_(o.anchorBlockId,e._tiptapEditor.state.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${o.anchorBlockId} to update selection`);let n;if(o.type==="cell")n=P.CellSelection.create(e._tiptapEditor.state.doc,t+o.anchorCellOffset,t+o.headCellOffset);else if(o.type==="node")n=y.NodeSelection.create(e._tiptapEditor.state.doc,t+1);else{const i=(s=_(o.headBlockId,e._tiptapEditor.state.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${o.headBlockId} to update selection`);n=y.TextSelection.create(e._tiptapEditor.state.doc,t+o.anchorOffset,i+o.headOffset)}e.dispatch(e._tiptapEditor.state.tr.setSelection(n))}function st(e){return e.map(o=>o.type==="columnList"?o.children.map(t=>st(t.children)).flat():{...o,children:st(o.children)}).flat()}function ln(e,o,t){var s;const n=((s=e.getSelection())==null?void 0:s.blocks)||[e.getTextCursorPosition().block],r=Ts(e);e.removeBlocks(n),e.insertBlocks(st(n),o,t),xs(e,r)}function cn(e){return!e||e.type!=="columnList"}function dn(e,o,t){let n,r;if(o?o.children.length>0?(n=o.children[o.children.length-1],r="after"):(n=o,r="before"):t&&(n=t,r="before"),!n||!r)return;const s=e.getParentBlock(n);return cn(s)?{referenceBlock:n,placement:r}:dn(e,r==="after"?n:e.getPrevBlock(n),s)}function un(e,o,t){let n,r;if(o?o.children.length>0?(n=o.children[0],r="before"):(n=o,r="after"):t&&(n=t,r="after"),!n||!r)return;const s=e.getParentBlock(n);return cn(s)?{referenceBlock:n,placement:r}:un(e,r==="before"?n:e.getNextBlock(n),s)}function Ms(e){const o=e.getSelection(),t=(o==null?void 0:o.blocks[0])||e.getTextCursorPosition().block,n=dn(e,e.getPrevBlock(t),e.getParentBlock(t));n&&ln(e,n.referenceBlock,n.placement)}function Ps(e){const o=e.getSelection(),t=(o==null?void 0:o.blocks[(o==null?void 0:o.blocks.length)-1])||e.getTextCursorPosition().block,n=un(e,e.getNextBlock(t),e.getParentBlock(t));n&&ln(e,n.referenceBlock,n.placement)}function Is(e,o){return function({state:t,dispatch:n}){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(n){const d=c.lastChild&&c.lastChild.type===o,u=B.Fragment.from(d?e.create():null),h=new B.Slice(B.Fragment.from(e.create(null,B.Fragment.from(o.create(null,u)))),d?3:1,0),f=i.start,m=i.end;n(t.tr.step(new Ie.ReplaceAroundStep(f-(d?3:1),m,f,m,h,1,!0)).scrollIntoView())}return!0}}function pn(e){return e._tiptapEditor.commands.command(Is(e._tiptapEditor.schema.nodes.blockContainer,e._tiptapEditor.schema.nodes.blockGroup))}function Ls(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function As(e){const{bnBlock:o}=v(e._tiptapEditor.state);return e._tiptapEditor.state.doc.resolve(o.beforePos).nodeBefore!==null}function Ns(e){const{bnBlock:o}=v(e._tiptapEditor.state);return e._tiptapEditor.state.doc.resolve(o.beforePos).depth>1}function hn(e,o,t){const n=e._tiptapEditor;let r=n.state.tr;const s=[];for(const u of t)s.push(te(u,e.pmSchema,e.schema.styleSchema));const i=new Set(o.map(u=>typeof u=="string"?u:u.id)),a=[],l=typeof o[0]=="string"?o[0]:o[0].id;let c=0;if(n.state.doc.descendants((u,h)=>{if(i.size===0)return!1;if(!u.type.isInGroup("bnBlock")||!i.has(u.attrs.id))return!0;if(a.push(T(u,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)),i.delete(u.attrs.id),t.length>0&&u.attrs.id===l){const b=r.doc.nodeSize;r=r.insert(h,s);const w=r.doc.nodeSize;c+=b-w}const f=r.doc.nodeSize,m=r.doc.resolve(h-c);m.node().type.name==="blockGroup"&&m.node(m.depth-1).type.name!=="doc"&&m.node().childCount===1?r=r.delete(m.before(),m.after()):r=r.delete(h-c,h-c+u.nodeSize);const g=r.doc.nodeSize;return c+=f-g,!1}),i.size>0){const u=[...i].join(`
|
|
10
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+u)}e.dispatch(r);const d=[];for(const u of s)d.push(T(u,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return{insertedBlocks:d,removedBlocks:a}}function Hs(e,o,t){return hn(e,o,t)}function Ds(e,o){return hn(e,o,[]).removedBlocks}function Os(e,o){const t=typeof o=="string"?o:o.id,n=_(t,e._tiptapEditor.state.doc);if(n)return T(n.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function _s(e,o){const t=typeof o=="string"?o:o.id,n=_(t,e._tiptapEditor.state.doc);if(!n)return;const s=e._tiptapEditor.state.doc.resolve(n.posBeforeNode).nodeBefore;if(s)return T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Rs(e,o){const t=typeof o=="string"?o:o.id,n=_(t,e._tiptapEditor.state.doc);if(!n)return;const s=e._tiptapEditor.state.doc.resolve(n.posBeforeNode+n.node.nodeSize).nodeAfter;if(s)return T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Vs(e,o){const t=typeof o=="string"?o:o.id,n=_(t,e._tiptapEditor.state.doc);if(!n)return;const r=e._tiptapEditor.state.doc.resolve(n.posBeforeNode),s=r.node(),i=r.node(-1),a=i.type.name!=="doc"?s.type.name==="blockGroup"?i:s:void 0;if(a)return T(a,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Fs(e,o,t,n={updateSelection:!0}){const r=t._tiptapEditor.state.tr;let{from:s,to:i}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},a=!0,l=!0,c="";if(o.forEach(d=>{d.check(),a&&d.isText&&d.marks.length===0?c+=d.text:a=!1,l=l?d.isBlock:!1}),s===i&&l){const{parent:d}=r.doc.resolve(s);d.isTextblock&&!d.type.spec.code&&!d.childCount&&(s-=1,i+=1)}return a?r.insertText(c,s,i):r.replaceWith(s,i,o),n.updateSelection&&k.selectionToInsertionEnd(r,r.steps.length-1,-1),t.dispatch(r),!0}function Us(e){const o=e._tiptapEditor.state;if(o.selection.empty||"node"in o.selection)return;const t=o.doc.resolve(K(o.doc,o.selection.from).posBeforeNode),n=o.doc.resolve(K(o.doc,o.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),h=o.doc.resolve(u).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${u}`);return T(h,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)},s=[],i=t.sharedDepth(n.pos),a=t.index(i),l=n.index(i);if(t.depth>i){s.push(T(t.nodeAfter,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));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 (${o.selection})`);return{blocks:s}}function $s(e,o,t){const n=typeof o=="string"?o:o.id,r=typeof t=="string"?t:t.id;if(n===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${n})`);const s=e._tiptapEditor.state.doc,i=_(n,s);if(!i)throw new Error(`Block with ID ${n} not found`);const a=_(r,s);if(!a)throw new Error(`Block with ID ${r} not found`);const l=Q(i),c=Q(a),d=e.schema.blockSchema[l.blockNoteType],u=e.schema.blockSchema[c.blockNoteType];if(!l.isBlockContainer||d.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${n})`);if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let h,f;if(d.content==="table"){const m=P.TableMap.get(l.blockContent.node);h=l.blockContent.beforePos+m.positionAt(0,0,l.blockContent.node)+1+2}else h=l.blockContent.beforePos+1;if(u.content==="table"){const m=P.TableMap.get(c.blockContent.node),g=c.blockContent.beforePos+m.positionAt(m.height-1,m.width-1,c.blockContent.node)+1,b=s.resolve(g).nodeAfter.nodeSize;f=g+b-2}else f=c.blockContent.afterPos-1;e._tiptapEditor.dispatch(e._tiptapEditor.state.tr.setSelection(y.TextSelection.create(e._tiptapEditor.state.doc,h,f)))}function zs(e){const{bnBlock:o}=v(e._tiptapEditor.state),t=e._tiptapEditor.state.doc.resolve(o.beforePos),n=t.nodeBefore,r=e._tiptapEditor.state.doc.resolve(o.afterPos).nodeAfter;let s;return t.depth>1&&(s=t.node(),s.type.isInGroup("bnBlock")||(s=t.node(t.depth-1))),{block:T(o.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),prevBlock:n===null?void 0:T(n,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),nextBlock:r===null?void 0:T(r,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),parentBlock:s===void 0?void 0:T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}}function fn(e,o,t="start"){const n=typeof o=="string"?o:o.id,r=_(n,e._tiptapEditor.state.doc);if(!r)throw new Error(`Block with ID ${n} not found`);const s=Q(r),i=e.schema.blockSchema[s.blockNoteType].content;if(s.isBlockContainer){const a=s.blockContent;if(i==="none"){e._tiptapEditor.commands.setNodeSelection(a.beforePos);return}if(i==="inline")t==="start"?e._tiptapEditor.commands.setTextSelection(a.beforePos+1):e._tiptapEditor.commands.setTextSelection(a.afterPos-1);else if(i==="table")t==="start"?e._tiptapEditor.commands.setTextSelection(a.beforePos+4):e._tiptapEditor.commands.setTextSelection(a.afterPos-4);else throw new F(i)}else{const a=t==="start"?s.childContainer.node.firstChild:s.childContainer.node.lastChild;fn(e,a.attrs.id,t)}}exports.esmDependencies=void 0;async function Ue(){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 Ws(){const e=o=>{let t=o.children.length;for(let n=0;n<t;n++){const r=o.children[n];if(r.type==="element"&&(e(r),r.tagName==="u"))if(r.children.length>0){o.children.splice(n,1,...r.children);const s=r.children.length-1;t+=s,n+=s}else o.children.splice(n,1),t--,n--}};return e}function qs(){const e=exports.esmDependencies;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const o=t=>{var n;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"&&((n=s.properties)==null?void 0:n.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(" ")))):o(s)}};return o}function $e(e){const o=exports.esmDependencies;if(!o)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return o.unified.unified().use(o.rehypeParse.default,{fragment:!0}).use(Ws).use(qs).use(o.rehypeRemark.default).use(o.remarkGfm.default).use(o.remarkStringify.default,{handlers:{text:n=>n.value}}).processSync(e).value}async function mn(e,o,t,n){await Ue();const s=ve(o,t).exportBlocks(e,n);return $e(s)}function js(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Ks(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function Gs(e){e.querySelectorAll("li > ul, li > ol").forEach(o=>{const t=js(o),n=o.parentElement,r=Array.from(n.childNodes).slice(t+1);o.remove(),r.forEach(s=>{s.remove()}),n.insertAdjacentElement("afterend",o),r.reverse().forEach(s=>{if(Ks(s))return;const i=document.createElement("li");i.append(s),o.insertAdjacentElement("afterend",i)}),n.childNodes.length===0&&n.remove()})}function Xs(e){e.querySelectorAll("li + ul, li + ol").forEach(o=>{var s,i;const t=o.previousElementSibling,n=document.createElement("div");t.insertAdjacentElement("afterend",n),n.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),n.append(r);((s=n.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=n.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(n.nextElementSibling)})}let Nt=null;function Js(){return Nt||(Nt=document.implementation.createHTMLDocument("title"))}function gn(e){if(typeof e=="string"){const o=Js().createElement("div");o.innerHTML=e,e=o}return Gs(e),Xs(e),e}async function vt(e,o,t,n,r){const s=gn(e),a=B.DOMParser.fromSchema(r).parse(s,{topNode:r.nodes.blockGroup.create()}),l=[];for(let c=0;c<a.childCount;c++)l.push(T(a.child(c),o,t,n));return l}function Ys(e,o){const t=o.value?o.value:"",n={};o.lang&&(n["data-language"]=o.lang);let r={type:"element",tagName:"code",properties:n,children:[{type:"text",value:t}]};return o.meta&&(r.data={meta:o.meta}),e.patch(o,r),r=e.applyData(o,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(o,r),r}async function St(e){const o=await Ue();return o.unified.unified().use(o.remarkParse.default).use(o.remarkGfm.default).use(o.remarkRehype.default,{handlers:{...o.remarkRehype.defaultHandlers,code:Ys}}).use(o.rehypeStringify.default).processSync(e).value}async function bn(e,o,t,n,r){const s=await St(e);return vt(s,o,t,n,r)}const Et=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function Zs(e,o){if(!e.startsWith(".")||!o.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===o}function Qs(e,o){const t=e.split("/"),n=o.split("/");if(t.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(n.length!==2)throw new Error(`The string ${o} is not a valid MIME type.`);return t[1]==="*"||n[1]==="*"?t[0]===n[0]:(t[0]==="*"||n[0]==="*"||t[0]===n[0])&&t[1]===n[1]}function Ht(e,o,t){let n;return Array.isArray(o.content)&&o.content.length===0?n=e.updateBlock(o,t).id:n=e.insertBlocks([t],o,"after")[0].id,n}async function kn(e,o){var i;if(!o.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 n=null;for(const a of Et)if(t.types.includes(a)){n=a;break}if(n!=="Files")return;const r=t.items;if(!r)return;e.preventDefault();const s=Object.values(o.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&&Qs(r[a].type,u)||h&&Zs("."+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=o.getTextCursorPosition().block;u=Ht(o,m,d)}else if(e.type==="drop"){const m={left:e.clientX,top:e.clientY},g=(i=o.prosemirrorView)==null?void 0:i.posAtCoords(m);if(!g)return;const b=K(o._tiptapEditor.state.doc,g.pos);u=Ht(o,o.getBlock(b.node.attrs.id),d)}else return;const h=await o.uploadFile(c,u),f=typeof h=="string"?{props:{url:h}}:{...h};o.updateBlock(u,f)}}}const ei=e=>k.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{drop(o,t){if(!e.isEditable)return;let n=null;for(const r of Et)if(t.dataTransfer.types.includes(r)){n=r;break}return n===null?!0:n==="Files"?(kn(t,e),!0):!1}}}})]}});async function ti(e,o){const{schema:t}=o.state;if(!e.clipboardData)return!1;const n=e.clipboardData.getData("text/plain");if(!n)return!1;if(!t.nodes.codeBlock)return o.pasteText(n),!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?(o.pasteHTML(`<pre><code class="language-${i}">${n.replace(/\r\n?/g,`
|
|
11
|
-
`)}</code></pre>`),!0):!1}const oi=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,ni=new RegExp("(?:\\s|^)(_|__|\\*|\\*\\*|~~|==|\\+\\+)(?!\\s).{1,64}(?<!\\s)(?=\\1)"),ri=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,si=new RegExp("(?:\\s|^)`(?!\\s)[^`]{1,48}(?<!\\s)`([^\\w]|$)"),ii=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,ai=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,li=/\n{2} {0,3}-{2,48}\n{2}/,ci=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,di=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,ui=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,pi=/^\s*\|(.+\|)+\s*$/m,hi=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,fi=/^\s*\|(.+\|)+\s*$/m,mi=e=>oi.test(e)||ni.test(e)||ri.test(e)||si.test(e)||ii.test(e)||ai.test(e)||li.test(e)||ci.test(e)||di.test(e)||ui.test(e)||pi.test(e)||hi.test(e)||fi.test(e);function gi({event:e,editor:o,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:n}){let r;for(const i of Et)if(e.clipboardData.types.includes(i)){r=i;break}if(!r)return!0;if(r==="vscode-editor-data")return ti(e,o.prosemirrorView),!0;if(r==="Files")return kn(e,o),!0;const s=e.clipboardData.getData(r);if(r==="blocknote/html")return o.pasteHTML(s,!0),!0;if(r==="text/markdown")return o.pasteMarkdown(s),!0;if(t){const i=e.clipboardData.getData("text/plain");if(mi(i))return o.pasteMarkdown(i),!0}return r==="text/html"?(o.pasteHTML(s),!0):n?(o.pasteMarkdown(s),!0):(o.pasteText(s),!0)}const bi=(e,o)=>k.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{paste(t,n){if(n.preventDefault(),!!e.isEditable)return o({event:n,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>gi({event:n,editor:e,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function wn(e,o){const t=[];return e.descendants(n=>{var r,s;return n.type.name==="blockContainer"&&((r=n.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:n.type.name==="columnList"&&n.childCount===1?((s=n.firstChild)==null||s.forEach(i=>{t.push(T(i,o.blockSchema,o.inlineContentSchema,o.styleSchema))}),!1):n.type.isInGroup("bnBlock")?(t.push(T(n,o.blockSchema,o.inlineContentSchema,o.styleSchema)),!1):!0}),t}function ki(e,o,t){var a;let n=!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));n=c.find(d=>d.type.isInGroup("bnBlock")||d.type.name==="blockGroup"||d.type.spec.group==="blockContent")===void 0,n&&(o=l)}let s;const i=ve(e.state.schema,t);if(r){((a=o.firstChild)==null?void 0:a.type.name)==="table"&&(o=o.firstChild.content);const l=dt(o,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(n){const l=ye(o,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=wn(o,t.schema);s=i.exportBlocks(l,{})}return s}function yn(e,o){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&o.dispatch(o._tiptapEditor.state.tr.setSelection(new y.NodeSelection(e.state.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,n=e.state.selection.content().content,r=ki(e,n,o),s=$e(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const Dt=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let o=e.focusNode;for(;o;){if(o instanceof HTMLElement&&o.getAttribute("contenteditable")==="false")return!0;o=o.parentElement}return!1},Ot=(e,o,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:n,externalHTML:r,markdown:s}=yn(o,e);t.clipboardData.setData("blocknote/html",n),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},wi=e=>k.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{copy(o,t){return Dt()||Ot(e,o,t),!0},cut(o,t){return Dt()||(Ot(e,o,t),o.editable&&o.dispatch(o.state.tr.deleteSelection())),!0},dragstart(o,t){if(!("node"in o.state.selection)||o.state.selection.node.type.spec.group!=="blockContent")return;e.dispatch(e._tiptapEditor.state.tr.setSelection(new y.NodeSelection(o.state.doc.resolve(o.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:n,externalHTML:r,markdown:s}=yn(o,e);return t.dataTransfer.setData("blocknote/html",n),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),yi=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}}}}]}}),Ci=e=>{var n;const o=[];o.push(wr.default.configure({fragment:e.fragment}));const t=(n=e.provider)==null?void 0:n.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};o.push(yr.default.configure({user:e.user,render:i,provider:e.provider}))}return o},Cn=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 Y{constructor(){p(this,"callbacks",{})}on(o,t){return this.callbacks[o]||(this.callbacks[o]=[]),this.callbacks[o].push(t),()=>this.off(o,t)}emit(o,...t){const n=this.callbacks[o];n&&n.forEach(r=>r.apply(this,t))}off(o,t){const n=this.callbacks[o];n&&(t?this.callbacks[o]=n.filter(r=>r!==t):delete this.callbacks[o])}removeAllListeners(){this.callbacks={}}}class vi extends Y{constructor(t){super();p(this,"userCache",new Map);p(this,"loadingUsers",new Set);this.resolveUsers=t}async loadUsers(t){const n=t.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(n.length!==0){for(const r of n)this.loadingUsers.add(r);try{const r=await this.resolveUsers(n);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of n)this.loadingUsers.delete(r)}}}getUser(t){return this.userCache.get(t)}subscribe(t){return this.on("update",t)}}const Be=new y.PluginKey("blocknote-comments"),Si="SET_SELECTED_THREAD_ID";function Ei(e,o){const t=new Map;return e.descendants((n,r)=>{n.marks.forEach(s=>{if(s.type.name===o){const i=s.attrs.threadId;if(!i)return;const a=r,l=a+n.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 Bi extends Y{constructor(t,n,r){super();p(this,"plugin");p(this,"userStore");p(this,"pendingComment",!1);p(this,"selectedThreadId");p(this,"threadPositions",new Map);p(this,"updateMarksFromThreads",t=>{const n=this.editor._tiptapEditor;n.state.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{tr:u}=n.state,h=Math.max(s,0),f=Math.min(s+r.nodeSize,n.state.doc.content.size-1);u.removeMark(h,f,i),u.addMark(h,f,a.create({...i.attrs,orphan:d})),n.dispatch(u),d&&this.selectedThreadId===l&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})});if(this.editor=t,this.threadStore=n,this.markType=r,!t.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new vi(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 y.Plugin({key:Be,state:{init(){return{decorations:x.DecorationSet.empty}},apply(i,a){const l=i.getMeta(Be);if(!i.docChanged&&!l)return a;const c=i.docChanged?Ei(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=Be.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,n=!0){var r,s;if(this.selectedThreadId!==t&&(this.selectedThreadId=t,this.emitStateUpdate(),this.editor.dispatch(this.editor.prosemirrorView.state.tr.setMeta(Be,{name:Si})),t&&n)){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 n=await this.threadStore.createThread(t);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=Ge.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?Ge.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:n.id,selection:a})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:n.id})}}class vn{constructor(o,t,n,r){p(this,"state");p(this,"emitUpdate");p(this,"mouseDownHandler",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"dragstartHandler",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var o;if((o=this.state)!=null&&o.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 o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});this.editor=o,this.pluginKey=t,this.pmView=n,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},n.dom.addEventListener("mousedown",this.mouseDownHandler),n.dom.addEventListener("dragstart",this.dragstartHandler),n.root.addEventListener("scroll",this.scrollHandler,!0)}update(o,t){var r,s;const n=this.pluginKey.getState(o.state);if(!((r=this.state)!=null&&r.show)&&n.block&&this.editor.isEditable){const i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${n.block.id}"]`);if(!i)return;this.state={show:!0,referencePos:i.getBoundingClientRect(),block:n.block},this.emitUpdate();return}(!o.state.selection.eq(t.selection)||!o.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 je=new y.PluginKey("FilePanelPlugin");class Sn extends Y{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 y.Plugin({key:je,view:n=>(this.view=new vn(t,je,n,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(n,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:n=>{var s;return{block:(s=n.getMeta(je))==null?void 0:s.block}}}})}get shown(){var t,n;return((n=(t=this.view)==null?void 0:t.state)==null?void 0:n.show)||!1}onUpdate(t){return this.on("update",t)}}class En{constructor(o,t,n){p(this,"state");p(this,"emitUpdate");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"shouldShow",({state:o,from:t,to:n})=>{const{doc:r,selection:s}=o,{empty:i}=s,a=!r.textBetween(t,n).length&&k.isTextSelection(o.selection);return s.$from.parent.type.spec.code||k.isNodeSelection(s)&&s.node.type.spec.code?!1:!(i||a)});p(this,"blurHandler",o=>{var n;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;o&&o.relatedTarget&&(t===o.relatedTarget||t.contains(o.relatedTarget)||o.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(n=this.state)!=null&&n.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 o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});p(this,"closeMenu",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});this.editor=o,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");n(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(o,t){var h;const{state:n,composing:r}=o,{selection:s}=n,i=t&&t.selection.from===n.selection.from&&t.selection.to===n.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:o,state:n,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:o}=this.pmView,{selection:t}=o,{ranges:n}=t,r=Math.min(...n.map(i=>i.$from.pos)),s=Math.max(...n.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 Bn=new y.PluginKey("FormattingToolbarPlugin");class Tn extends Y{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new y.Plugin({key:Bn,view:n=>(this.view=new En(t,n,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(n,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}get shown(){var t,n;return((n=(t=this.view)==null?void 0:t.state)==null?void 0:n.show)||!1}onUpdate(t){return this.on("update",t)}}const Ti=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,o)=>{const t=e.resolve(o);if(t.depth<=1)return;const n=t.posAtIndex(t.index(t.depth-1),t.depth-1);return ue(e.resolve(n))},Pe=(e,o)=>{const t=e.resolve(o),n=t.index();if(n===0)return;const r=t.posAtIndex(n-1);return ue(e.resolve(r))},xn=(e,o)=>{for(;o.childContainer;){const t=o.childContainer.node,n=e.resolve(o.childContainer.beforePos+1).posAtIndex(t.childCount-1);o=ue(e.resolve(n))}return o},xi=(e,o)=>e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*"&&e.blockContent.node.childCount>0&&o.isBlockContainer&&o.blockContent.node.type.spec.content==="inline*",Mi=(e,o,t,n)=>{if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${n.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(n.childContainer){const r=e.doc.resolve(n.childContainer.beforePos+1),s=e.doc.resolve(n.childContainer.afterPos-1),i=r.blockRange(s);if(o){const a=e.doc.resolve(n.bnBlock.beforePos);e.tr.lift(i,a.depth)}}if(o){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${n.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);o(e.tr.delete(t.blockContent.afterPos-1,n.blockContent.beforePos+1))}return!0},Rt=e=>({state:o,dispatch:t})=>{const n=o.doc.resolve(e),r=ue(n),s=Pe(o.doc,r.bnBlock.beforePos);if(!s)return!1;const i=xn(o.doc,s);return xi(i,r)?Mi(o,t,i,r):!1},Pi=k.Extension.create({priority:50,addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({chain:n,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=v(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(L(this.options.editor,i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=v(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=v(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?n().command(Rt(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=v(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||Pe(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 Ie.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,u.bnBlock.afterPos+1,h.bnBlock.afterPos-2,b,b.size,!1));const w=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(y.TextSelection.between(w,w))}else{s.tr.step(new Ie.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,h.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const w=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(y.TextSelection.between(w,w))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(h.bnBlock.beforePos,b.content);const w=s.tr.doc.resolve(h.bnBlock.beforePos);s.tr.setSelection(y.TextSelection.between(w,w))}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 w=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(y.TextSelection.between(w,w))}}return!0}),()=>r.command(({state:s})=>{const i=v(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=Pe(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let c=n();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=v(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=Pe(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=xn(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 n().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},d.bnBlock.afterPos).deleteRange({from:d.bnBlock.beforePos,to:d.bnBlock.afterPos}).run()}return!1})]),o=()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:r})=>{const s=v(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 n.command(Rt(g-1))}return!1})]),t=(n=!1)=>this.editor.commands.first(({commands:r})=>[()=>r.command(({state:s})=>{const i=v(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=v(s),a=this.options.editor.schema.blockSchema[i.blockNoteType].hardBreakShortcut??"shift+enter";return a==="none"?!1:a==="shift+enter"&&n||a==="enter"?r.insertContent({type:"hardBreak"}):!1}),()=>r.command(({state:s,dispatch:i})=>{const a=v(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 y.TextSelection(s.doc.resolve(m)))}return!0}return!1}),()=>r.command(({state:s,chain:i})=>{const a=v(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(qo(s.selection.from,c,c)).run(),!0)})]);return{Backspace:e,Delete:o,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var n,r,s;return this.options.tabBehavior!=="prefer-indent"&&((n=this.options.editor.formattingToolbar)!=null&&n.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:pn(this.options.editor)},"Shift-Tab":()=>{var n,r,s;return this.options.tabBehavior!=="prefer-indent"&&((n=this.options.editor.formattingToolbar)!=null&&n.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 Ii{constructor(o,t,n){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",o=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),o.target instanceof HTMLAnchorElement&&o.target.nodeName==="A"){const t=o.target,n=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(n),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",o=>{var n;const t=this.pmView.dom.parentElement;this.linkMark&&o&&o.target&&!(t===o.target||t.contains(o.target))&&(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var o;this.linkMark!==void 0&&(o=this.state)!=null&&o.show&&(this.state.referencePos=k.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});p(this,"closeMenu",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});this.editor=o,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");n(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(o,t){var r;const n=this.pmView.state.tr.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to);n.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:o})),this.editor.dispatch(n),this.pmView.focus(),(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var o;this.editor.dispatch(this.pmView.state.tr.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}update(o,t,n=!1){var a;const{state:r}=o;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&&n&&(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 Mn=new y.PluginKey("LinkToolbarPlugin");class Pn extends Y{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"editLink",(t,n)=>{this.view.editLink(t,n)});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 y.Plugin({key:Mn,view:n=>(this.view=new Ii(t,n,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(n,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}onUpdate(t){return this.on("update",t)}get shown(){var t,n;return((n=(t=this.view)==null?void 0:t.state)==null?void 0:n.show)||!1}}const In=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],Ln="https",Li=new y.PluginKey("node-selection-keyboard");class Ai{constructor(){p(this,"plugin");this.plugin=new y.Plugin({key:Li,props:{handleKeyDown:(o,t)=>{if("node"in o.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 n=o.state.tr;return o.dispatch(n.insert(o.state.tr.selection.$to.after(),o.state.schema.nodes.paragraph.createChecked()).setSelection(new y.TextSelection(n.doc.resolve(o.state.tr.selection.$to.after()+1)))),!0}}return!1}}})}}const Ni=new y.PluginKey("blocknote-placeholder");class Hi{constructor(o,t){p(this,"plugin");this.plugin=new y.Plugin({key:Ni,view:n=>{var c,d;const r=`placeholder-selector-${Wt.v4()}`;n.dom.classList.add(r);const s=document.createElement("style"),i=o._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),((c=o.prosemirrorView)==null?void 0:c.root)instanceof ShadowRoot?o.prosemirrorView.root.append(s):(d=o.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,w]of Object.entries(f)){const C=`[data-content-type="${b}"]`;a.insertRule(`${l(C)} { content: ${JSON.stringify(w)}; }`)}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=o.prosemirrorView)==null?void 0:u.root)instanceof ShadowRoot?o.prosemirrorView.root.removeChild(s):(h=o.prosemirrorView)==null||h.root.head.removeChild(s)}}},props:{decorations:n=>{const{doc:r,selection:s}=n;if(!o.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];n.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 Vt=new y.PluginKey("previous-blocks"),Di={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class Oi{constructor(){p(this,"plugin");let o;this.plugin=new y.Plugin({key:Vt,view(t){return{update:async(n,r)=>{var s;((s=this.key)==null?void 0:s.getState(n.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{n.dispatch(n.state.tr.setMeta(Vt,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,n,r,s){if(n.currentTransactionOldBlockAttrs={},n.updatedBlocks.clear(),!t.docChanged||r.doc.eq(s.doc))return n;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 n.prevTransactionOldBlockAttrs&&(g=n.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),n.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,n.updatedBlocks.add(d.node.attrs.id))}}return n.prevTransactionOldBlockAttrs=i,n}},props:{decorations(t){const n=this.getState(t);if(n.updatedBlocks.size===0)return;const r=[];return t.doc.descendants((s,i)=>{if(!s.attrs.id||!n.updatedBlocks.has(s.attrs.id))return;const a=n.currentTransactionOldBlockAttrs[s.attrs.id],l={};for(const[d,u]of Object.entries(a))l["data-prev-"+Di[d]]=u||"none";const c=x.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),x.DecorationSet.create(t.doc,r)}}})}}const Ft=new y.PluginKey("blocknote-show-selection");class _i{constructor(o){p(this,"plugin");p(this,"enabled",!1);this.editor=o,this.plugin=new y.Plugin({key:Ft,props:{decorations:t=>{const{doc:n,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(n,[s])}}})}setEnabled(o){var t,n;this.enabled!==o&&(this.enabled=o,(n=this.editor.prosemirrorView)==null||n.dispatch((t=this.editor.prosemirrorView)==null?void 0:t.state.tr.setMeta(Ft,{})))}getEnabled(){return this.enabled}}function An(e,o){var t,n;for(;e&&e.parentElement&&e.parentElement!==o.dom&&((t=e.getAttribute)==null?void 0:t.call(e,"data-node-type"))!=="blockContainer";)e=e.parentElement;if(((n=e.getAttribute)==null?void 0:n.call(e,"data-node-type"))==="blockContainer")return{node:e,id:e.getAttribute("data-id")}}class ie extends y.Selection{constructor(t,n){super(t,n);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,n.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,n,r=n){return new ie(t.resolve(n),t.resolve(r))}content(){return new B.Slice(B.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof ie)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(t.nodes[n]))return!1;return!0}map(t,n){const r=n.mapResult(this.from),s=n.mapResult(this.to);return s.deleted?y.Selection.near(t.resolve(r.pos)):r.deleted?y.Selection.near(t.resolve(s.pos)):new ie(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let U;function Ri(e,o){let t,n;const r=o.resolve(e.from).node().type.spec.group==="blockContent",s=o.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=o.resolve(a-1).pos,n=o.resolve(l+1).pos}else t=e.from,n=e.to;return{from:t,to:n}}function Ut(e,o,t=o){o===t&&(t+=e.state.doc.resolve(o+1).node().nodeSize);const n=e.domAtPos(o).node.cloneNode(!0),r=e.domAtPos(o).node,s=(u,h)=>Array.prototype.indexOf.call(u.children,h),i=s(r,e.domAtPos(o+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)&&n.removeChild(n.children[u]);Nn(e.root),U=n;const l=U.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(" ");U.className=U.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild(U):e.root.body.appendChild(U)}function Nn(e){U!==void 0&&(e instanceof ShadowRoot?e.removeChild(U):e.body.removeChild(U),U=void 0)}function Vi(e,o,t){if(!e.dataTransfer)return;const n=t.prosemirrorView;if(!n)return;const r=_(o.id,n.state.doc);if(!r)throw new Error(`Block with ID ${o.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=n.state.selection,a=n.state.doc,{from:l,to:c}=Ri(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof ie;d&&u?(n.dispatch(n.state.tr.setSelection(ie.create(a,l,c))),Ut(n,l,c)):(n.dispatch(n.state.tr.setSelection(y.NodeSelection.create(n.state.doc,s))),Ut(n,s));const h=n.state.selection.content(),f=t.pmSchema,m=n.serializeForClipboard(h).dom.innerHTML,g=ve(f,t),b=wn(h.content,t.schema),w=g.exportBlocks(b,{}),C=$e(w);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",w),e.dataTransfer.setData("text/plain",C),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(U,0,0)}}const ge=.1;function it(e,o,t,n=!0){const r=e.root.elementsFromPoint(o.left+(t==="editor"?50:0),o.top);for(const s of r)if(e.dom.contains(s))return n&&s.closest("[data-node-type=columnList]")?it(e,{left:o.left+50,top:o.top},t,!1):An(s,e)}function Fi(e,o,t){if(!o.dom.firstChild)return;const n=o.dom.firstChild.getBoundingClientRect(),r={left:e.x,top:e.y},s=r.left<n.left,i=r.left>n.right;t==="viewport"&&(s&&(r.left=n.left+10),i&&(r.left=n.right-10));let a=it(o,r,t);if(!i&&a){const l=a.node.getBoundingClientRect();r.left=l.right-10,a=it(o,r,"viewport",!1)}return a}class Hn{constructor(o,t,n,r){p(this,"state");p(this,"emitUpdate");p(this,"mousePos");p(this,"hoveredBlock");p(this,"menuFrozen",!1);p(this,"isDragOrigin",!1);p(this,"updateState",o=>{this.state=o,this.emitUpdate(this.state)});p(this,"updateStateFromMousePos",()=>{var n,r,s,i;if(this.menuFrozen||!this.mousePos)return;const o=Fi(this.mousePos,this.pmView,this.sideMenuDetection);if(!o||!this.editor.isEditable){(n=this.state)!=null&&n.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"))===o.id)return;this.hoveredBlock=o.node;const t=o.node.firstChild;if(t&&this.editor.isEditable){const a=t.getBoundingClientRect(),l=o.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",o=>{var r,s;if(this.pmView.dragging===null)return;this.editor._tiptapEditor.commands.blur();const t=o.target instanceof Node&&((r=o.target instanceof HTMLElement?o.target:o.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(y.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"||o.synthetic||!((s=o.dataTransfer)!=null&&s.types.includes("blocknote/html")))return;const n=this.pmView.posAtCoords({left:o.clientX,top:o.clientY});if(!n||n.inside===-1){const i=this.createSyntheticEvent(o);this.pmView.dom.dispatchEvent(i)}});p(this,"onDragEnd",()=>{this.pmView.dragging=null});p(this,"onDragStart",o=>{var i;const t=(i=o.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 n=document.createElement("div");n.innerHTML=t;const s=B.DOMParser.fromSchema(this.pmView.state.schema).parse(n,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new B.Slice(s.content,0,0),move:!0}});p(this,"onDragOver",o=>{var n;if(this.sideMenuDetection==="editor"||o.synthetic||!((n=o.dataTransfer)!=null&&n.types.includes("blocknote/html")))return;const t=this.pmView.posAtCoords({left:o.clientX,top:o.clientY});if(!t||t.inside===-1&&this.pmView.dom.firstChild){const r=this.createSyntheticEvent(o);this.pmView.dom.dispatchEvent(r)}});p(this,"onKeyDown",o=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});p(this,"onMouseMove",o=>{var s;if(this.menuFrozen)return;this.mousePos={x:o.clientX,y:o.clientY};const t=this.pmView.dom.getBoundingClientRect(),n=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(n&&o&&o.target&&!(r===o.target||r.contains(o.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});p(this,"onScroll",()=>{var o;(o=this.state)!=null&&o.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state))});this.editor=o,this.sideMenuDetection=t,this.pmView=n,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),Ue(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),n.root.addEventListener("scroll",this.onScroll,!0)}createSyntheticEvent(o){const t=new Event(o.type,o),n=this.pmView.dom.firstChild.getBoundingClientRect();return t.clientX=o.clientX,t.clientY=o.clientY,o.clientX<n.left&&o.clientX>n.left-n.width*ge?t.clientX=n.left+n.width*ge/2:o.clientX>n.right&&o.clientX<n.right+n.width*ge?t.clientX=n.right-n.width*ge/2:(o.clientX<n.left||o.clientX>n.right)&&(t.clientX=n.left+ge*n.width*2),t.clientY=Math.min(Math.max(o.clientY,n.top),n.top+n.height),t.dataTransfer=o.dataTransfer,t.preventDefault=()=>o.preventDefault(),t.synthetic=!0,t}update(o,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var o;(o=this.state)!=null&&o.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 Dn=new y.PluginKey("SideMenuPlugin");class On extends Y{constructor(t,n){super();p(this,"view");p(this,"plugin");p(this,"blockDragStart",(t,n)=>{this.view&&(this.view.isDragOrigin=!0),Vi(t,n,this.editor)});p(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&Nn(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 y.Plugin({key:Dn,view:r=>(this.view=new Hn(t,n,r,s=>{this.emit("update",s)}),this.view)})}onUpdate(t){return this.on("update",t)}}const Ui=k.findParentNode(e=>e.type.name==="blockContainer");class $i{constructor(o,t){p(this,"state");p(this,"emitUpdate");p(this,"rootEl");p(this,"pluginState");p(this,"handleScroll",()=>{var o,t;if((o=this.state)!=null&&o.show){const n=(t=this.rootEl)==null?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!n)return;this.state.referencePos=n.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});p(this,"closeMenu",()=>{this.editor.dispatch(this.editor._tiptapEditor.state.tr.setMeta(ae,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._tiptapEditor.state.selection.from}).run()});var n,r;this.editor=o,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=(n=this.editor.prosemirrorView)==null?void 0:n.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(o,t){var c;const n=ae.getState(t),r=ae.getState(o.state),s=n===void 0&&r!==void 0,i=n!==void 0&&r===void 0;if(!s&&!(n!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?n: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 o;(o=this.rootEl)==null||o.removeEventListener("scroll",this.handleScroll,!0)}}const ae=new y.PluginKey("SuggestionMenuPlugin");class _n extends Y{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(n=>n!==t)});p(this,"closeMenu",()=>this.view.closeMenu());p(this,"clearQuery",()=>this.view.clearQuery());const n=this.triggerCharacters;this.plugin=new y.Plugin({key:ae,view:()=>(this.view=new $i(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(ae);if(typeof l=="object"&&l!==null&&s===void 0)return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:a.selection.from,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)return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos,a.selection.from),c}},props:{handleTextInput(r,s,i,a){const l=this.getState(r.state);return n.includes(a)&&l===void 0?(r.dispatch(r.state.tr.insertText(a).scrollIntoView().setMeta(ae,{triggerCharacter:a})),!0):!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=Ui(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,n){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,n)}get shown(){var t,n;return((n=(t=this.view)==null?void 0:t.state)==null?void 0:n.show)||!1}}function zi(e,o){e.suggestionMenus.addTriggerCharacter(o)}let O;function $t(e){O||(O=document.createElement("div"),O.innerHTML="_",O.style.opacity="0",O.style.height="1px",O.style.width="1px",e instanceof Document?e.body.appendChild(O):e.appendChild(O))}function Wi(e){O&&(e instanceof Document?e.body.removeChild(O):e.removeChild(O),O=void 0)}function Te(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function qi(e){let o=e;for(;o&&o.nodeName!=="TD"&&o.nodeName!=="TH"&&!o.classList.contains("tableWrapper");){if(o.classList.contains("ProseMirror"))return;const t=o.parentNode;if(!t||!(t instanceof Element))return;o=t}return o.nodeName==="TD"||o.nodeName==="TH"?{type:"cell",domNode:o,tbodyNode:o.closest("tbody")}:{type:"wrapper",domNode:o,tbodyNode:o.querySelector("tbody")}}function ji(e,o){const t=o.querySelectorAll(e);for(let n=0;n<t.length;n++)t[n].style.visibility="hidden"}class Rn{constructor(o,t,n){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",o=>{this.mouseState="up",this.mouseMoveHandler(o)});p(this,"mouseMoveHandler",o=>{var c,d,u,h,f,m,g;if(this.menuFrozen||this.mouseState==="selecting"||!(o.target instanceof Element)||!this.pmView.dom.contains(o.target))return;const t=qi(o.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 n=t.tbodyNode.getBoundingClientRect(),r=An(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=_(r.id,this.editor._tiptapEditor.state.doc);if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=T(i.node,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache);if(rn("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=o.clientY>=n.bottom-1&&o.clientY<n.bottom+20,w=o.clientX>=n.right-1&&o.clientX<n.right+20,C=o.clientX>n.right||o.clientY>n.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:b,showAddOrRemoveColumnsButton:w,referencePosTable:n,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=Te(t.domNode),w=Te(t.domNode.parentElement),C=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===w&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:w===s.content.rows.length-1,referencePosTable:n,block:s,draggingState:void 0,referencePosCell:C,colIndex:b,rowIndex:w,widgetContainer:l}}return this.emitUpdate(),!1});p(this,"dragOverHandler",o=>{var h;if(((h=this.state)==null?void 0:h.draggingState)===void 0)return;o.preventDefault(),o.dataTransfer.dropEffect="move",ji(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const t={left:Math.min(Math.max(o.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(o.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},n=this.pmView.root.elementsFromPoint(t.left,t.top).filter(f=>f.tagName==="TD"||f.tagName==="TH");if(n.length===0)return;const r=n[0];let s=!1;const i=Te(r.parentElement),a=Te(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.dispatch(this.pmView.state.tr.setMeta(se,!0))});p(this,"dropHandler",o=>{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.");o.preventDefault();const{draggingState:t,colIndex:n,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!no(this.state.block,t.originalIndex,r))return!1;const i=Pr(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!ro(this.state.block,t.originalIndex,n))return!1;const i=Mr(this.state.block,t.originalIndex,n),[a]=s.splice(t.originalIndex,1);s.splice(n,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=o,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");n(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:o,width:t}=ft(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=o&&(this.state.rowIndex=o-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const n=this.tableElement.querySelector("tbody");if(!n)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=n.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=n.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 se=new y.PluginKey("TableHandlesPlugin");class Vn extends Y{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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(se,{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.");$t(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(O,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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(se,{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.");$t(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(O,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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(se,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Wi(this.editor.prosemirrorView.root)});p(this,"freezeHandles",()=>{this.view.menuFrozen=!0});p(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});p(this,"getCellsAtRowHandle",(t,n)=>Ze(t,n));p(this,"getCellsAtColumnHandle",(t,n)=>Qe(t,n));p(this,"setCellSelection",(t,n=t)=>{const r=this.view;if(!r)throw new Error("Table handles view not initialized");const s=this.editor.prosemirrorState,i=s.doc.resolve(r.tablePos+1),a=s.doc.resolve(i.posAtIndex(t.row)+1),l=s.doc.resolve(a.posAtIndex(t.col)),c=s.doc.resolve(i.posAtIndex(n.row)+1),d=s.doc.resolve(c.posAtIndex(n.col)),u=s.tr;return u.setSelection(new P.CellSelection(l,d)),s.apply(u)});p(this,"addRowOrColumn",(t,n)=>{const r=this.setCellSelection(n.orientation==="row"?{row:t,col:0}:{row:0,col:t});return n.orientation==="row"?n.side==="above"?P.addRowBefore(r,this.editor.dispatch):P.addRowAfter(r,this.editor.dispatch):n.side==="left"?P.addColumnBefore(r,this.editor.dispatch):P.addColumnAfter(r,this.editor.dispatch)});p(this,"removeRowOrColumn",(t,n)=>{const r=this.setCellSelection(n==="row"?{row:t,col:0}:{row:0,col:t});return n==="row"?P.deleteRow(r,this.editor.dispatch):P.deleteColumn(r,this.editor.dispatch)});p(this,"mergeCells",t=>{const n=t?this.setCellSelection(t.relativeStartCell,t.relativeEndCell):this.editor.prosemirrorState;return P.mergeCells(n,this.editor.dispatch)});p(this,"splitCell",t=>{const n=t?this.setCellSelection(t):this.editor.prosemirrorState;return P.splitCell(n,this.editor.dispatch)});p(this,"getCellSelection",()=>{const t=this.editor.prosemirrorState,n=t.selection;let r=n.$from,s=n.$to;if(rt(n)){const{ranges:m}=n;m.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$to)})}else if(r=t.doc.resolve(n.$from.pos-n.$from.parentOffset-1),s=t.doc.resolve(n.$to.pos-n.$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=>{const n=rt(this.editor.prosemirrorState.selection)?this.editor.prosemirrorState.selection:void 0;if(!n||!t||n.ranges.length<=1)return;const r=this.getCellSelection();if(r)return Ar(r.from,r.to,t)?"vertical":"horizontal"});p(this,"cropEmptyRowsOrColumns",(t,n)=>Ir(t,n));p(this,"addRowsOrColumns",(t,n,r)=>Lr(t,n,r));this.editor=t,this.plugin=new y.Plugin({key:se,view:n=>(this.view=new Rn(t,n,r=>{this.emit("update",r)}),this.view),props:{decorations:n=>{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"&&!no(i,l,r)||c==="col"&&!ro(i,l,r))return x.DecorationSet.create(n.doc,s);const d=n.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?Ze(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=n.doc.resolve(d.posAtIndex(h)+1),g=n.doc.resolve(m.posAtIndex(f)+1),b=g.node(),w=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(w,()=>{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}))}):Qe(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=n.doc.resolve(d.posAtIndex(h)+1),g=n.doc.resolve(m.posAtIndex(f)+1),b=g.node(),w=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(w,()=>{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(n.doc,s)}}})}onUpdate(t){return this.on("update",t)}}const Ki=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}}}}]}}),Gi=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}}}}]}}),Xi=k.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new y.PluginKey(this.name);return[new y.Plugin({key:e,appendTransaction:(o,t,n)=>{const{doc:r,tr:s,schema:i}=n,a=e.getState(n),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:(o,t)=>{},apply:(o,t)=>{if(!o.docChanged)return t;let n=o.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")return!0;const r=n.firstChild;if(!r)throw new Error("Expected blockContent");return n.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),Ji={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Yi=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 o={};for(const[t,n]of Object.entries(Ji))e.getAttribute(n)&&(o[t]=e.getAttribute(n));return e.getAttribute("data-node-type")==="blockContainer"?o:!1}}]},renderHTML({HTMLAttributes:e}){var r;const o=document.createElement("div");o.className="bn-block-outer",o.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(e))s!=="class"&&o.setAttribute(s,i);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...e},n=document.createElement("div");n.className=X("bn-block",t.class),n.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(t))s!=="class"&&n.setAttribute(s,i);return o.appendChild(n),{dom:o,contentDOM:n}}}),Zi=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 n;const o={...((n=this.options.domAttributes)==null?void 0:n.blockGroup)||{},...e},t=document.createElement("div");t.className=X("bn-block-group",o.class),t.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(o))r!=="class"&&t.setAttribute(r,s);return{dom:t,contentDOM:t}}}),Qi=k.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Fn=e=>{const o={},t=ea(e);for(const r of t)o[r.name]=r;o.formattingToolbar=new Tn(e.editor),o.linkToolbar=new Pn(e.editor),o.sideMenu=new On(e.editor,e.sideMenuDetection),o.suggestionMenus=new _n(e.editor),o.filePanel=new Sn(e.editor),o.placeholder=new Hi(e.editor,e.placeholders),(e.animations??!0)&&(o.animations=new Oi),e.tableHandles&&(o.tableHandles=new Vn(e.editor)),o.dropCursor={plugin:e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})},o.nodeSelectionKeyboard=new Ai,o.showSelection=new _i(e.editor),e.comments&&(o.comments=new Bi(e.editor,e.comments.threadStore,Cn.name));const n=e.disableExtensions||[];for(const r of n)delete o[r];return o};let zt=!1;const ea=e=>{const o=[k.extensions.ClipboardTextSerializer,k.extensions.Commands,k.extensions.Editable,k.extensions.FocusEvents,k.extensions.Tabindex,ir.Gapcursor,pe.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),Ti,cr.Text,lr.Link.extend({inclusive:!1}).configure({defaultProtocol:Ln,protocols:zt?[]:In}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),Gi,yi,Ki,k.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),Qi,Yi.configure({editor:e.editor,domAttributes:e.domAttributes}),Pi.configure({editor:e.editor,tabBehavior:e.tabBehavior}),Zi.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(n=>n.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),wi(e.editor),bi(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),ei(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[Xi]:[],...e.comments?[Cn]:[]];return zt=!0,e.collaboration?o.push(...Ci(e.collaboration)):o.push(ar.History),o};function ta(e,o){const t=[];return e.forEach((n,r,s)=>{s!==o&&t.push(n)}),B.Fragment.from(t)}function oa(e,o){const t=[];for(let n=0;n<e.childCount;n++)if(e.child(n).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(n)));t[t.length-1]=s}else{const r=o.nodes.table.createChecked(void 0,e.child(n));t.push(r)}else t.push(e.child(n));return e=B.Fragment.from(t),e}function na(e,o){let t=B.Fragment.from(e.content);if(t=oa(t,o.state.schema),!ra(t,o))return new B.Slice(t,e.openStart,e.openEnd);for(let n=0;n<t.childCount;n++)if(t.child(n).type.spec.group==="blockContent"){const r=[t.child(n)];if(n+1<t.childCount&&t.child(n+1).type.name==="blockGroup"){const i=t.child(n+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(t.child(n+1)),t=ta(t,n+1))}const s=o.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(n,s)}return new B.Slice(t,e.openStart,e.openEnd)}function ra(e,o){var s,i;const t=e.childCount===1,n=((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(n)return!1;if(r){const a=v(o.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const De=class De extends k.Editor{constructor(t,n){super({...t,content:void 0});p(this,"_state");p(this,"mount",(t,n,r)=>{n?(this.options.element=n,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=>te(c,this.schema,n).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=y.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){this.view?this.view.dispatch(t):this._state=this.state.apply(t)}createViewAlternative(t,n){this.contentComponent=n;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.dispatchTransaction.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(De,"create",(t,n)=>{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 De(t,n)}finally{r&&(globalThis.window.setTimeout=r)}});let He=De;He.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const sa={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Bt extends Y{constructor(t){var c,d,u,h,f,m,g,b,w,C,S,A,W,q,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,"dispatch",t=>{this._tiptapEditor.dispatch(t)});p(this,"mount",(t,n)=>{this._tiptapEditor.mount(this,t,n)});this.options=t;const n=t;if(n.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(n.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(n.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(n.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||hr.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=Fn({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:H("table",this),dropCursor:this.options.dropCursor??pr.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,sideMenuDetection:r.sideMenuDetection||"viewport",comments:r.comments,pasteHandler:r.pasteHandler}),(((w=r._tiptapOptions)==null?void 0:w.extensions)||[]).forEach(E=>{this.extensions[E.name]=E}),Object.entries(r._extensions||{}).forEach(([E,D])=>{typeof D=="function"&&(D=D(this)),this.extensions[E]=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,r.uploadFile){const E=r.uploadFile;this.uploadFile=async(D,re)=>{this.onUploadStartCallbacks.forEach(ze=>ze.apply(this,[re]));try{return await E(D,re)}finally{this.onUploadEndCallbacks.forEach(ze=>ze.apply(this,[re]))}}}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:pe.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(([E,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:E,addProseMirrorPlugins:()=>[D.plugin]})})],l={...sa,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(C=r._tiptapOptions)==null?void 0:C.editorProps,attributes:{tabIndex:"0",...(A=(S=r._tiptapOptions)==null?void 0:S.editorProps)==null?void 0:A.attributes,...(W=r.domAttributes)==null?void 0:W.editor,class:X("bn-editor",r.defaultStyles?"bn-default-styles":"",((I=(q=r.domAttributes)==null?void 0:q.editor)==null?void 0:I.class)||"")},transformPasted:na}};this.headless?this.pmSchema=k.getSchema(l.extensions):(this._tiptapEditor=He.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.emit("create")}static create(t={}){return new Bt(t)}get prosemirrorView(){return this._tiptapEditor.view}get prosemirrorState(){return this._tiptapEditor.state}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 n=this.onUploadStartCallbacks.indexOf(t);n>-1&&this.onUploadStartCallbacks.splice(n,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const n=this.onUploadEndCallbacks.indexOf(t);n>-1&&this.onUploadEndCallbacks.splice(n,1)}}get topLevelBlocks(){return this.document}get document(){const t=[];return this.prosemirrorState.doc.firstChild.descendants(n=>(t.push(T(n,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){return Os(this,t)}getPrevBlock(t){return _s(this,t)}getNextBlock(t){return Rs(this,t)}getParentBlock(t){return Vs(this,t)}forEachBlock(t,n=!1){const r=this.document.slice();n&&r.reverse();function s(i){for(const a of i){if(t(a)===!1)return!1;const l=n?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 zs(this)}setTextCursorPosition(t,n="start"){fn(this,t,n)}getSelection(){return Us(this)}setSelection(t,n){$s(this,t,n)}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,n,r="before"){return Bs(this,t,n,r)}updateBlock(t,n){return io(this,t,n)}removeBlocks(t){return Ds(this,t)}replaceBlocks(t,n){return Hs(this,t,n)}insertInlineContent(t){const n=R(t,this.pmSchema,this.schema.styleSchema);Fs({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},n,this)}getActiveStyles(){const t={},n=this._tiptapEditor.state.selection.$to.marks();for(const r of n){const s=this.schema.styleSchema[r.type.name];if(!s){r.type.name!=="link"&&!r.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",r.type.name);continue}s.propSchema==="boolean"?t[s.type]=!0:t[s.type]=r.attrs.stringValue}return t}addStyles(t){for(const[n,r]of Object.entries(t)){const s=this.schema.styleSchema[n];if(!s)throw new Error(`style ${n} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.setMark(n);else if(s.propSchema==="string")this._tiptapEditor.commands.setMark(n,{stringValue:r});else throw new F(s.propSchema)}}removeStyles(t){for(const n of Object.keys(t))this._tiptapEditor.commands.unsetMark(n)}toggleStyles(t){for(const[n,r]of Object.entries(t)){const s=this.schema.styleSchema[n];if(!s)throw new Error(`style ${n} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(n);else if(s.propSchema==="string")this._tiptapEditor.commands.toggleMark(n,{stringValue:r});else throw new F(s.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,n){if(t==="")return;const{from:r,to:s}=this._tiptapEditor.state.selection,i=this.pmSchema.mark("link",{href:t});this.dispatch(n?this._tiptapEditor.state.tr.insertText(n,r,s).addMark(r,r+n.length,i):this._tiptapEditor.state.tr.setSelection(y.TextSelection.create(this._tiptapEditor.state.tr.doc,s)).addMark(r,s,i))}canNestBlock(){return As(this)}nestBlock(){pn(this)}canUnnestBlock(){return Ns(this)}unnestBlock(){Ls(this)}moveBlocksUp(){Ms(this)}moveBlocksDown(){Ps(this)}async blocksToHTMLLossy(t=this.document){return ve(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return ho(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return vt(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return mn(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return bn(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,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 n=()=>{t(this)};return this._tiptapEditor.on("update",n),()=>{this._tiptapEditor.off("update",n)}}onSelectionChange(t,n){if(this.headless)return;const r=s=>{s.transaction.getMeta(Ge.ySyncPluginKey)&&!n||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:n}=t,{ranges:r}=n,s=Math.min(...r.map(l=>l.$from.pos)),i=Math.max(...r.map(l=>l.$to.pos));if(k.isNodeSelection(n)){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,n){var i;const r=(i=this.prosemirrorView)==null?void 0:i.state.tr;if(!r)return;const s=n&&n.deleteTriggerCharacter?r.insertText(t):r;this.prosemirrorView.focus(),this.prosemirrorView.dispatch(s.scrollIntoView().setMeta(this.suggestionMenus.plugin,{triggerCharacter:t,deleteTriggerCharacter:(n==null?void 0:n.deleteTriggerCharacter)||!1,ignoreQueryLength:(n==null?void 0:n.ignoreQueryLength)||!1}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(t){this.showSelectionPlugin.setEnabled(t)}convertHtmlToBlockNoteHtml(t){return gn(t.trim()).innerHTML}pasteHTML(t,n=!1){var s;let r=t;n||(r=this.convertHtmlToBlockNoteHtml(t)),r&&((s=this.prosemirrorView)==null||s.pasteHTML(r))}pasteText(t){var n;return(n=this.prosemirrorView)==null?void 0:n.pasteText(t)}async pasteMarkdown(t){return this.pasteHTML(await St(t))}}const ia={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"}},aa={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 la{constructor(o,t,n){this.mappings=t,this.options=n}async resolveFile(o){var n;if(!((n=this.options)!=null&&n.resolveFileUrl))return(await fetch(o)).blob();const t=await this.options.resolveFileUrl(o);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(o){return Object.entries(o).map(([n,r])=>this.mappings.styleMapping[n](r,this))}mapInlineContent(o){return this.mappings.inlineContentMapping[o.type](o,this)}transformInlineContent(o){return o.map(t=>this.mapInlineContent(t))}async mapBlock(o,t,n){return this.mappings.blockMapping[o.type](o,this,t,n)}}function ca(e){return{createBlockMapping:o=>o,createInlineContentMapping:o=>o,createStyleMapping:o=>o}}let xe;async function da(){return xe||(xe=(async()=>{const[e,o]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),t="default"in e?e.default:e,n="default"in o?o.default:o;return await t.init({data:n}),{emojiMart:t,emojiData:n}})(),xe)}async function ua(e,o){if(!nn("text",e))return[];const{emojiData:t,emojiMart:n}=await da();return(o.trim()===""?Object.values(t.emojis):await n.SearchIndex.search(o)).map(s=>({id:s.skins[0].native,onItemClick:()=>e.insertInlineContent(s.skins[0].native+" ")}))}function pa(e,...o){const t=[...e];for(const n of o)for(const r of n){const s=t.findLastIndex(i=>i.group===r.group);s===-1?t.push(r):t.splice(s+1,0,r)}return t}function Ke(e=""){return typeof e=="string"?[{type:"text",text:e,styles:{}}]:e}function le(e){var o,t,n,r,s;return typeof e=="string"?Ke(e):Array.isArray(e)?e.flatMap(i=>typeof i=="string"?Ke(i):_e(i)?{...i,content:Ke(i.content)}:G(i)?i:{props:{},...i,content:le(i.content)}):(e==null?void 0:e.type)==="tableContent"?{type:"tableContent",columnWidths:e.columnWidths,headerRows:e.headerRows,headerCols:e.headerCols,rows:e.rows.map(i=>({...i,cells:i.cells.map(a=>le(a))}))}:(e==null?void 0:e.type)==="tableCell"?{type:"tableCell",content:le(e.content),props:{backgroundColor:((o=e.props)==null?void 0:o.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((n=e.props)==null?void 0:n.textAlignment)??"left",colspan:((r=e.props)==null?void 0:r.colspan)??1,rowspan:((s=e.props)==null?void 0:s.rowspan)??1}}:e}function ha(e,o){return o.map(t=>Tt(e.blockSchema,t))}function Tt(e,o){var r;const t=e[o.type].content,n={id:"",type:o.type,props:{},content:t==="inline"?[]:t==="table"?{type:"tableContent",columnWidths:void 0,headerRows:void 0,headerCols:void 0,rows:[]}:void 0,children:[],...o};if(Object.entries(e[o.type].propSchema).forEach(([s,i])=>{n.props[s]===void 0&&i.default!==void 0&&(n.props[s]=i.default)}),t==="inline"){const s=n.content;n.content=le(s)}else if(t==="table"){const s=n.content;n.content={type:"tableContent",columnWidths:(s==null?void 0:s.columnWidths)||((r=s==null?void 0:s.rows[0])==null?void 0:r.cells.map(()=>{}))||[],headerRows:(s==null?void 0:s.headerRows)||void 0,headerCols:(s==null?void 0:s.headerCols)||void 0,rows:(s==null?void 0:s.rows.map(i=>({cells:i.cells.map(a=>le(a))})))||[]}}return{...n,content:le(n.content),children:n.children.map(s=>Tt(e,s))}}function Un(e){e.id||(e.id=pe.options.generateID()),e.children&&$n(e.children)}function $n(e){for(const o of e)Un(o)}exports.AudioBlock=So;exports.BlockNoteEditor=Bt;exports.BlockNoteSchema=me;exports.COLORS_DARK_MODE_DEFAULT=aa;exports.COLORS_DEFAULT=ia;exports.CodeBlock=Bo;exports.DEFAULT_LINK_PROTOCOL=Ln;exports.EMPTY_CELL_HEIGHT=cs;exports.EMPTY_CELL_WIDTH=bt;exports.Exporter=la;exports.FILE_AUDIO_ICON_SVG=bo;exports.FILE_ICON_SVG=mo;exports.FILE_IMAGE_ICON_SVG=Ao;exports.FILE_VIDEO_ICON_SVG=Go;exports.FileBlock=Lo;exports.FilePanelProsemirrorPlugin=Sn;exports.FilePanelView=vn;exports.FormattingToolbarProsemirrorPlugin=Tn;exports.FormattingToolbarView=En;exports.HTMLToBlocks=vt;exports.ImageBlock=Ro;exports.LinkToolbarProsemirrorPlugin=Pn;exports.PageBreak=zo;exports.SideMenuProsemirrorPlugin=On;exports.SideMenuView=Hn;exports.SuggestionMenuProseMirrorPlugin=_n;exports.TableHandlesProsemirrorPlugin=Vn;exports.TableHandlesView=Rn;exports.UniqueID=pe;exports.UnreachableCaseError=F;exports.VALID_LINK_PROTOCOLS=In;exports.VideoBlock=en;exports.addIdsToBlock=Un;exports.addIdsToBlocks=$n;exports.addInlineContentAttributes=Ye;exports.addInlineContentKeyboardShortcuts=Xt;exports.addStyleAttributes=eo;exports.applyNonSelectableBlockFix=Kt;exports.assertEmpty=Cr;exports.audioBlockConfig=wo;exports.audioParse=Co;exports.audioPropSchema=ko;exports.audioRender=yo;exports.audioToExternalHTML=vo;exports.blockToNode=te;exports.blocksToMarkdown=mn;exports.camelToDataKebab=ke;exports.checkBlockHasDefaultProp=ws;exports.checkBlockIsDefaultType=rn;exports.checkBlockIsFileBlock=gs;exports.checkBlockIsFileBlockWithPlaceholder=ks;exports.checkBlockIsFileBlockWithPreview=bs;exports.checkBlockTypeHasDefaultProp=sn;exports.checkDefaultBlockTypeInSchema=H;exports.checkDefaultInlineContentTypeInSchema=nn;exports.checkPageBreakBlocksInSchema=an;exports.cleanHTMLToMarkdown=$e;exports.combineByGroup=pa;exports.contentNodeToInlineContent=ye;exports.contentNodeToTableContent=dt;exports.createAddFileButton=fo;exports.createBlockSpec=fe;exports.createBlockSpecFromStronglyTypedTiptapNode=J;exports.createDefaultBlockDOMOutputSpec=$;exports.createExternalHTMLExporter=ve;exports.createFigureWithCaption=Fe;exports.createFileBlockWrapper=Ve;exports.createFileNameWithIcon=go;exports.createInlineContentSpec=Tr;exports.createInlineContentSpecFromTipTapNode=Yt;exports.createInternalBlockSpec=lt;exports.createInternalHTMLSerializer=ho;exports.createInternalInlineContentSpec=Jt;exports.createInternalStyleSpec=pt;exports.createLinkWithCaption=Ee;exports.createResizableFileBlockWrapper=mt;exports.createStronglyTypedTiptapNode=z;exports.createStyleSpec=xr;exports.createStyleSpecFromTipTapMark=Z;exports.createSuggestionMenu=zi;exports.defaultBlockSchema=tn;exports.defaultBlockSpecs=kt;exports.defaultBlockToHTML=Je;exports.defaultCodeBlockPropSchema=Eo;exports.defaultInlineContentSchema=on;exports.defaultInlineContentSpecs=yt;exports.defaultProps=M;exports.defaultStyleSchema=ms;exports.defaultStyleSpecs=wt;exports.fileBlockConfig=xo;exports.fileParse=Po;exports.filePropSchema=To;exports.fileRender=Mo;exports.fileToExternalHTML=Io;exports.filenameFromURL=Br;exports.filterSuggestionItems=vs;exports.formatKeyboardShortcut=j;exports.formattingToolbarPluginKey=Bn;exports.getBlockFromPos=jt;exports.getBlockInfo=Q;exports.getBlockInfoFromResolvedPos=ue;exports.getBlockInfoFromSelection=v;exports.getBlockInfoWithManualOffset=Oe;exports.getBlockNoteExtensions=Fn;exports.getBlockSchemaFromSpecs=ct;exports.getColspan=de;exports.getDefaultEmojiPickerItems=ua;exports.getDefaultSlashMenuItems=Cs;exports.getInlineContentParseRules=Zt;exports.getInlineContentSchemaFromSpecs=ut;exports.getNearestBlockPos=K;exports.getNodeById=_;exports.getPageBreakSlashMenuItems=Es;exports.getParseRules=Gt;exports.getRowspan=Ae;exports.getStyleParseRules=to;exports.getStyleSchemaFromSpecs=ht;exports.imageBlockConfig=Ho;exports.imageParse=Oo;exports.imagePropSchema=No;exports.imageRender=Do;exports.imageToExternalHTML=_o;exports.inheritedProps=at;exports.initializeESMDependencies=Ue;exports.inlineContentToNodes=R;exports.insertOrUpdateBlock=N;exports.isAppleOS=qt;exports.isLinkInlineContent=Xe;exports.isPartialLinkInlineContent=_e;exports.isPartialTableCell=ce;exports.isSafari=Er;exports.isStyledTextInlineContent=G;exports.isTableCell=Re;exports.isTableCellSelection=rt;exports.linkToolbarPluginKey=Mn;exports.mapTableCell=Le;exports.mappingFactory=ca;exports.markdownToBlocks=bn;exports.markdownToHTML=St;exports.mergeCSSClasses=X;exports.nodeToBlock=T;exports.nodeToCustomInlineContent=Ne;exports.pageBreakConfig=Vo;exports.pageBreakParse=Uo;exports.pageBreakRender=Fo;exports.pageBreakSchema=Ct;exports.pageBreakToExternalHTML=$o;exports.parseEmbedElement=nt;exports.parseFigureElement=Se;exports.partialBlockToBlockForTesting=Tt;exports.partialBlocksToBlocksForTesting=ha;exports.propsToAttributes=he;exports.shikiHighlighterPromiseSymbol=Me;exports.shikiParserSymbol=ot;exports.sideMenuPluginKey=Dn;exports.stylePropsToAttributes=Qt;exports.tableContentToNodes=Ce;exports.tableHandlesPluginKey=se;exports.updateBlock=io;exports.updateBlockCommand=L;exports.uploadToTmpFilesDotOrg_DEV_ONLY=Fr;exports.videoBlockConfig=Jo;exports.videoParse=Zo;exports.videoPropSchema=Xo;exports.videoRender=Yo;exports.videoToExternalHTML=Qo;exports.withPageBreak=Ss;exports.wrapInBlockStructure=be;
|
|
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}}}}),Tn=J(Fr,Bn);function Lt(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 rt=e=>({url:e.src||void 0}),xn={backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},Pn={type:"file",propSchema:xn,content:"none",isFileBlock:!0},Mn=(e,n)=>Ue(e,n),In=e=>{if(e.tagName==="EMBED")return rt(e);if(e.tagName==="FIGURE"){const n=Be(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...rt(t),caption:o}}},Ln=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?Te(n,e.props.caption):{dom:n}},An=me(Pn,{render:Mn,parse:In,toExternalHTML:Ln}),gt=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=Ue(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 A;e.props.textAlignment==="center"?u.handleUsed==="left"?A=u.initialWidth+(u.initialClientX-v.clientX)*2:A=u.initialWidth+(v.clientX-u.initialClientX)*2:u.handleUsed==="left"?A=u.initialWidth+u.initialClientX-v.clientX:A=u.initialWidth+v.clientX-u.initialClientX,h=Math.max(A,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))},w=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",w),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",w),d.removeEventListener("mousedown",C)}}},Ur=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/")},At=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},Nn='<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>',Hn={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},Dn={type:"image",propSchema:Hn,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},On=(e,n)=>{const t=document.createElement("div");t.innerHTML=Nn;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),gt(e,n,{dom:o},o,n.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},_n=e=>{if(e.tagName==="IMG")return At(e);if(e.tagName==="FIGURE"){const n=Be(e,"img");if(!n)return;const{targetElement:t,caption:o}=n;return{...At(t),caption:o}}},Rn=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?$e(n,e.props.caption):Te(n,e.props.caption):{dom:n}},Vn=me(Dn,{render:On,parse:_n,toExternalHTML:Rn}),Fn={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Un=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},$n=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},zn=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},Wn=me(Fn,{render:Un,parse:$n,toExternalHTML:zn}),$r=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=Z($r,"string"),Wr=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]}}),qr=Z(Wr,"string"),qn={...P,level:{default:1,values:[1,2,3]}},Kr=z({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return fe(qn)},addInputRules(){return[...[1,2,3].map(e=>new k.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:n,chain:t,range:o})=>{const r=S(n);!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||t().command(L(this.options.editor,r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>{const e=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"heading",props:{level:1}}))},"Mod-Alt-2":()=>{const e=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"heading",props:{level:2}}))},"Mod-Alt-3":()=>{const e=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 $(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)||{})}}),jr=J(Kr,qn),Kn=(e,n,t)=>({state:o,dispatch:r})=>{const s=j(o.doc,e),i=Q(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 n=e._tiptapEditor,t=S(n.state);if(!t.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=t,s=n.state.selection.anchor===n.state.selection.head;return!(r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!s?!1:n.commands.first(({state:i,chain:a,commands:l})=>[()=>l.command(()=>r.node.childCount===0?l.command(L(e,o.beforePos,{type:"paragraph",props:{}})):!1),()=>l.command(()=>r.node.childCount>0?(a().deleteSelection().command(Kn(i.selection.from,!0)).run(),!0):!1)])},Gr={...P},Xr=z({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=S(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(L(this.options.editor,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=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Jr=J(Xr,Gr),jn={...P,checked:{default:!1}},Yr=z({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return fe(jn)},addInputRules(){return[new k.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=S(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(L(this.options.editor,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=S(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(L(this.options.editor,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=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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}=$(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=j(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(L(this.options.editor,h.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=$(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)}}}}}),Zr=J(Yr,jn),Qr=new y.PluginKey("numbered-list-indexing"),es=()=>new y.Plugin({key:Qr,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=Q({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=o.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=Q({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}}),Gn={...P,start:{default:void 0,type:"number"}},ts=z({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...fe(Gn),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=S(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem")return;const s=parseInt(o[1]);n().command(L(this.options.editor,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=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[es()]},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 $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ns=J(ts,Gn),os={...P},rs=z({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ss=J(rs,os),is={...P},as=z({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new k.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:n,range:t})=>{const o=S(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(L(this.options.editor,o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=S(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(L(this.options.editor,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 $(this.name,"blockquote",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),ls=J(as,is),cs=35,kt=120,ds=31,us=k.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[M.columnResizing({cellMinWidth:cs,defaultCellMinWidth:kt,View:null}),M.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})=>M.goToNextCell(1)(e,n,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>M.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))}}}),ps={textColor:P.textColor},hs=z({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(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 M.TableView{constructor(s,i,a){super(s,i),this.node=s,this.cellMinWidth=i,this.blockContentHTMLAttributes=a;const l=document.createElement("div");l.className=X("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,kt,{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...n})}}}),fs=z({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]}}),ms=J(hs,ps,[us,fs,sr.TableHeader.extend({content:"tableContent+"}),rr.TableCell.extend({content:"tableContent+"}),ir.TableRow]),Nt=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},Xn='<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>',Jn={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},Yn={type:"video",propSchema:Jn,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},Zn=(e,n)=>{const t=document.createElement("div");t.innerHTML=Xn;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),gt(e,n,{dom:o},o,n.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},Qn=e=>{if(e.tagName==="VIDEO")return Nt(e);if(e.tagName==="FIGURE"){const n=Be(e,"video");if(!n)return;const{targetElement:t,caption:o}=n;return{...Nt(t),caption:o}}},eo=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?$e(n,e.props.caption):Te(n,e.props.caption):{dom:n}},to=me(Yn,{render:Zn,parse:Qn,toExternalHTML:eo}),wt={paragraph:ss,heading:jr,quote:ls,codeBlock:Tn,bulletListItem:Jr,numberedListItem:ns,checkListItem:Zr,table:ms,file:An,image:Vn,video:to,audio:En},no=dt(wt),yt={bold:Z(mr.default,"boolean"),italic:Z(br.default,"boolean"),underline:Z(wr.default,"boolean"),strike:Z(kr.default,"boolean"),code:Z(gr.default,"boolean"),textColor:qr,backgroundColor:zr},gs=ft(yt),Ct={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},oo=pt(Ct);function H(e,n){return e in n.schema.blockSchema&&n.schema.blockSchema[e]===no[e]}function ro(e,n){return e in n.schema.inlineContentSchema&&n.schema.inlineContentSchema[e]===oo[e]}function so(e,n,t){return n.type===e&&n.type in t.schema.blockSchema&&H(n.type,t)}function bs(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock||!1}function ks(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 ws(e,n){return n.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function io(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 ys(e,n,t){return io(e,n.type,t)}function st(e){return e instanceof M.CellSelection}function Cs(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 N(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&&G(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)),Cs(e),o}function Ss(e){const n=[];return H("heading",e)&&n.push({onItemClick:()=>{N(e,{type:"heading",props:{level:1}})},badge:K("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{N(e,{type:"heading",props:{level:2}})},badge:K("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{N(e,{type:"heading",props:{level:3}})},badge:K("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),H("quote",e)&&n.push({onItemClick:()=>{N(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),H("numberedListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"numberedListItem"})},badge:K("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),H("bulletListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"bulletListItem"})},badge:K("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),H("checkListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"checkListItem"})},badge:K("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),H("paragraph",e)&&n.push({onItemClick:()=>{N(e,{type:"paragraph"})},badge:K("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),H("codeBlock",e)&&n.push({onItemClick:()=>{N(e,{type:"codeBlock"})},badge:K("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),H("table",e)&&n.push({onItemClick:()=>{N(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),H("image",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"image"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"image",...e.dictionary.slash_menu.image}),H("video",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"video"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"video",...e.dictionary.slash_menu.video}),H("audio",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"audio"});e.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),H("file",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"file"});e.dispatch(e._tiptapEditor.state.tr.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 vs(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)||wt,this.inlineContentSpecs=je(n==null?void 0:n.inlineContentSpecs)||Ct,this.styleSpecs=je(n==null?void 0:n.styleSpecs)||yt,this.blockSchema=dt(this.blockSpecs),this.inlineContentSchema=pt(this.inlineContentSpecs),this.styleSchema=ft(this.styleSpecs)}static create(n){return new ge(n)}}const St=ge.create({blockSpecs:{pageBreak:Wn}}),Es=e=>ge.create({blockSpecs:{...e.blockSpecs,...St.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function ao(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===St.blockSchema.pageBreak}function Bs(e){const n=[];return ao(e)&&n.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{N(e,{type:"pageBreak"})},key:"page_break"}),n}function Ts(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=[];for(const l of n)s.push(te(l,e.pmSchema,e.schema.styleSchema));const i=_(r,e._tiptapEditor.state.doc);if(!i)throw new Error(`Block with ID ${r} not found`);o==="before"&&e.dispatch(e._tiptapEditor.state.tr.insert(i.posBeforeNode,s)),o==="after"&&e.dispatch(e._tiptapEditor.state.tr.insert(i.posBeforeNode+i.node.nodeSize,s));const a=[];for(const l of s)a.push(T(l,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return a}function xs(e){const n=e._tiptapEditor.state,t=n.selection,o=j(n.doc,t.anchor);if(t instanceof M.CellSelection)return{type:"cell",anchorBlockId:o.node.attrs.id,anchorCellOffset:t.$anchorCell.pos-o.posBeforeNode,headCellOffset:t.$headCell.pos-o.posBeforeNode};if(e._tiptapEditor.state.selection instanceof y.NodeSelection)return{type:"node",anchorBlockId:o.node.attrs.id};{const r=j(n.doc,t.head);return{type:"text",anchorBlockId:o.node.attrs.id,headBlockId:r.node.attrs.id,anchorOffset:t.anchor-o.posBeforeNode,headOffset:t.head-r.posBeforeNode}}}function Ps(e,n){var r,s;const t=(r=_(n.anchorBlockId,e._tiptapEditor.state.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=M.CellSelection.create(e._tiptapEditor.state.doc,t+n.anchorCellOffset,t+n.headCellOffset);else if(n.type==="node")o=y.NodeSelection.create(e._tiptapEditor.state.doc,t+1);else{const i=(s=_(n.headBlockId,e._tiptapEditor.state.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=y.TextSelection.create(e._tiptapEditor.state.doc,t+n.anchorOffset,i+n.headOffset)}e.dispatch(e._tiptapEditor.state.tr.setSelection(o))}function it(e){return e.map(n=>n.type==="columnList"?n.children.map(t=>it(t.children)).flat():{...n,children:it(n.children)}).flat()}function lo(e,n,t){var s;const o=((s=e.getSelection())==null?void 0:s.blocks)||[e.getTextCursorPosition().block],r=xs(e);e.removeBlocks(o),e.insertBlocks(it(o),n,t),Ps(e,r)}function co(e){return!e||e.type!=="columnList"}function uo(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 co(s)?{referenceBlock:o,placement:r}:uo(e,r==="after"?o:e.getPrevBlock(o),s)}function po(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 co(s)?{referenceBlock:o,placement:r}:po(e,r==="before"?o:e.getNextBlock(o),s)}function Ms(e){const n=e.getSelection(),t=(n==null?void 0:n.blocks[0])||e.getTextCursorPosition().block,o=uo(e,e.getPrevBlock(t),e.getParentBlock(t));o&&lo(e,o.referenceBlock,o.placement)}function Is(e){const n=e.getSelection(),t=(n==null?void 0:n.blocks[(n==null?void 0:n.blocks.length)-1])||e.getTextCursorPosition().block,o=po(e,e.getNextBlock(t),e.getParentBlock(t));o&&lo(e,o.referenceBlock,o.placement)}function Ls(e,n){return function({state:t,dispatch: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 we.ReplaceAroundStep(f-(d?3:1),m,f,m,h,1,!0)).scrollIntoView())}return!0}}function ho(e){return e._tiptapEditor.commands.command(Ls(e._tiptapEditor.schema.nodes.blockContainer,e._tiptapEditor.schema.nodes.blockGroup))}function As(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function Ns(e){const{bnBlock:n}=S(e._tiptapEditor.state);return e._tiptapEditor.state.doc.resolve(n.beforePos).nodeBefore!==null}function Hs(e){const{bnBlock:n}=S(e._tiptapEditor.state);return e._tiptapEditor.state.doc.resolve(n.beforePos).depth>1}function fo(e,n,t){const o=e._tiptapEditor;let r=o.state.tr;const s=[];for(const u of t)s.push(te(u,e.pmSchema,e.schema.styleSchema));const i=new Set(n.map(u=>typeof u=="string"?u:u.id)),a=[],l=typeof n[0]=="string"?n[0]:n[0].id;let c=0;if(o.state.doc.descendants((u,h)=>{if(i.size===0)return!1;if(!u.type.isInGroup("bnBlock")||!i.has(u.attrs.id))return!0;if(a.push(T(u,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)),i.delete(u.attrs.id),t.length>0&&u.attrs.id===l){const b=r.doc.nodeSize;r=r.insert(h,s);const w=r.doc.nodeSize;c+=b-w}const f=r.doc.nodeSize,m=r.doc.resolve(h-c);m.node().type.name==="blockGroup"&&m.node(m.depth-1).type.name!=="doc"&&m.node().childCount===1?r=r.delete(m.before(),m.after()):r=r.delete(h-c,h-c+u.nodeSize);const g=r.doc.nodeSize;return c+=f-g,!1}),i.size>0){const u=[...i].join(`
|
|
10
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+u)}e.dispatch(r);const d=[];for(const u of s)d.push(T(u,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return{insertedBlocks:d,removedBlocks:a}}function Ds(e,n,t){return fo(e,n,t)}function Os(e,n){return fo(e,n,[]).removedBlocks}function _s(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e._tiptapEditor.state.doc);if(o)return T(o.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Rs(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e._tiptapEditor.state.doc);if(!o)return;const s=e._tiptapEditor.state.doc.resolve(o.posBeforeNode).nodeBefore;if(s)return T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Vs(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e._tiptapEditor.state.doc);if(!o)return;const s=e._tiptapEditor.state.doc.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(s)return T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Fs(e,n){const t=typeof n=="string"?n:n.id,o=_(t,e._tiptapEditor.state.doc);if(!o)return;const r=e._tiptapEditor.state.doc.resolve(o.posBeforeNode),s=r.node(),i=r.node(-1),a=i.type.name!=="doc"?s.type.name==="blockGroup"?i:s:void 0;if(a)return T(a,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function Us(e,n,t,o={updateSelection:!0}){const r=t._tiptapEditor.state.tr;let{from:s,to:i}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},a=!0,l=!0,c="";if(n.forEach(d=>{d.check(),a&&d.isText&&d.marks.length===0?c+=d.text:a=!1,l=l?d.isBlock:!1}),s===i&&l){const{parent:d}=r.doc.resolve(s);d.isTextblock&&!d.type.spec.code&&!d.childCount&&(s-=1,i+=1)}return a?r.insertText(c,s,i):r.replaceWith(s,i,n),o.updateSelection&&k.selectionToInsertionEnd(r,r.steps.length-1,-1),t.dispatch(r),!0}function $s(e){const n=e._tiptapEditor.state;if(n.selection.empty||"node"in n.selection)return;const t=n.doc.resolve(j(n.doc,n.selection.from).posBeforeNode),o=n.doc.resolve(j(n.doc,n.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),h=n.doc.resolve(u).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${u}`);return T(h,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)},s=[],i=t.sharedDepth(o.pos),a=t.index(i),l=o.index(i);if(t.depth>i){s.push(T(t.nodeAfter,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));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 (${n.selection})`);return{blocks:s}}function zs(e,n,t){const o=typeof n=="string"?n:n.id,r=typeof t=="string"?t:t.id;if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const s=e._tiptapEditor.state.doc,i=_(o,s);if(!i)throw new Error(`Block with ID ${o} not found`);const a=_(r,s);if(!a)throw new Error(`Block with ID ${r} not found`);const l=Q(i),c=Q(a),d=e.schema.blockSchema[l.blockNoteType],u=e.schema.blockSchema[c.blockNoteType];if(!l.isBlockContainer||d.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let h,f;if(d.content==="table"){const m=M.TableMap.get(l.blockContent.node);h=l.blockContent.beforePos+m.positionAt(0,0,l.blockContent.node)+1+2}else h=l.blockContent.beforePos+1;if(u.content==="table"){const m=M.TableMap.get(c.blockContent.node),g=c.blockContent.beforePos+m.positionAt(m.height-1,m.width-1,c.blockContent.node)+1,b=s.resolve(g).nodeAfter.nodeSize;f=g+b-2}else f=c.blockContent.afterPos-1;e._tiptapEditor.dispatch(e._tiptapEditor.state.tr.setSelection(y.TextSelection.create(e._tiptapEditor.state.doc,h,f)))}function Ws(e){const{bnBlock:n}=S(e._tiptapEditor.state),t=e._tiptapEditor.state.doc.resolve(n.beforePos),o=t.nodeBefore,r=e._tiptapEditor.state.doc.resolve(n.afterPos).nodeAfter;let s;return t.depth>1&&(s=t.node(),s.type.isInGroup("bnBlock")||(s=t.node(t.depth-1))),{block:T(n.node,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),prevBlock:o===null?void 0:T(o,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),nextBlock:r===null?void 0:T(r,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache),parentBlock:s===void 0?void 0:T(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}}function mo(e,n,t="start"){const o=typeof n=="string"?n:n.id,r=_(o,e._tiptapEditor.state.doc);if(!r)throw new Error(`Block with ID ${o} not found`);const s=Q(r),i=e.schema.blockSchema[s.blockNoteType].content;if(s.isBlockContainer){const a=s.blockContent;if(i==="none"){e._tiptapEditor.commands.setNodeSelection(a.beforePos);return}if(i==="inline")t==="start"?e._tiptapEditor.commands.setTextSelection(a.beforePos+1):e._tiptapEditor.commands.setTextSelection(a.afterPos-1);else if(i==="table")t==="start"?e._tiptapEditor.commands.setTextSelection(a.beforePos+4):e._tiptapEditor.commands.setTextSelection(a.afterPos-4);else throw new F(i)}else{const a=t==="start"?s.childContainer.node.firstChild:s.childContainer.node.lastChild;mo(e,a.attrs.id,t)}}exports.esmDependencies=void 0;async function ze(){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 qs(){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 Ks(){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 We(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(qs).use(Ks).use(n.rehypeRemark.default).use(n.remarkGfm.default).use(n.remarkStringify.default,{handlers:{text:o=>o.value}}).processSync(e).value}async function go(e,n,t,o){await ze();const s=Ee(n,t).exportBlocks(e,o);return We(s)}function js(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Gs(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function Xs(e){e.querySelectorAll("li > ul, li > ol").forEach(n=>{const t=js(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(Gs(s))return;const i=document.createElement("li");i.append(s),n.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function Js(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 Ht=null;function Ys(){return Ht||(Ht=document.implementation.createHTMLDocument("title"))}function bo(e){if(typeof e=="string"){const n=Ys().createElement("div");n.innerHTML=e,e=n}return Xs(e),Js(e),e}async function vt(e,n,t,o,r){const s=bo(e),a=B.DOMParser.fromSchema(r).parse(s,{topNode:r.nodes.blockGroup.create()}),l=[];for(let c=0;c<a.childCount;c++)l.push(T(a.child(c),n,t,o));return l}function Zs(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 Et(e){const n=await ze();return n.unified.unified().use(n.remarkParse.default).use(n.remarkGfm.default).use(n.remarkRehype.default,{handlers:{...n.remarkRehype.defaultHandlers,code:Zs}}).use(n.rehypeStringify.default).processSync(e).value}async function ko(e,n,t,o,r){const s=await Et(e);return vt(s,n,t,o,r)}const Bt=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function Qs(e,n){if(!e.startsWith(".")||!n.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===n}function ei(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 Dt(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 wo(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 Bt)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&&ei(r[a].type,u)||h&&Qs("."+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=Dt(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;const b=j(n._tiptapEditor.state.doc,g.pos);u=Dt(n,n.getBlock(b.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 ti=e=>k.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{drop(n,t){if(!e.isEditable)return;let o=null;for(const r of Bt)if(t.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(wo(t,e),!0):!1}}}})]}});async function ni(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 oi=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,ri=new RegExp("(?:\\s|^)(_|__|\\*|\\*\\*|~~|==|\\+\\+)(?!\\s).{1,64}(?<!\\s)(?=\\1)"),si=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,ii=new RegExp("(?:\\s|^)`(?!\\s)[^`]{1,48}(?<!\\s)`([^\\w]|$)"),ai=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,li=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,ci=/\n{2} {0,3}-{2,48}\n{2}/,di=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,ui=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,pi=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,hi=/^\s*\|(.+\|)+\s*$/m,fi=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,mi=/^\s*\|(.+\|)+\s*$/m,gi=e=>oi.test(e)||ri.test(e)||si.test(e)||ii.test(e)||ai.test(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);function bi({event:e,editor:n,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:o}){let r;for(const i of Bt)if(e.clipboardData.types.includes(i)){r=i;break}if(!r)return!0;if(r==="vscode-editor-data")return ni(e,n.prosemirrorView),!0;if(r==="Files")return wo(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(gi(i))return n.pasteMarkdown(i),!0}return r==="text/html"?(n.pasteHTML(s),!0):o?(n.pasteMarkdown(s),!0):(n.pasteText(s),!0)}const ki=(e,n)=>k.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.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 yo(e,n){const t=[];return e.descendants(o=>{var r,s;return o.type.name==="blockContainer"&&((r=o.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:o.type.name==="columnList"&&o.childCount===1?((s=o.firstChild)==null||s.forEach(i=>{t.push(T(i,n.blockSchema,n.inlineContentSchema,n.styleSchema))}),!1):o.type.isInGroup("bnBlock")?(t.push(T(o,n.blockSchema,n.inlineContentSchema,n.styleSchema)),!1):!0}),t}function wi(e,n,t){var a;let o=!1;const r=e.state.selection instanceof M.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=Ee(e.state.schema,t);if(r){((a=n.firstChild)==null?void 0:a.type.name)==="table"&&(n=n.firstChild.content);const l=ut(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=Se(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=yo(n,t.schema);s=i.exportBlocks(l,{})}return s}function Co(e,n){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&n.dispatch(n._tiptapEditor.state.tr.setSelection(new y.NodeSelection(e.state.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=wi(e,o,n),s=We(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const Ot=()=>{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},_t=(e,n,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Co(n,e);t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},yi=e=>k.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{copy(n,t){return Ot()||_t(e,n,t),!0},cut(n,t){return Ot()||(_t(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.dispatch(e._tiptapEditor.state.tr.setSelection(new y.NodeSelection(n.state.doc.resolve(n.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=Co(n,e);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),Ci=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}}}}]}}),Si=e=>{var o;const n=[];n.push(yr.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(Cr.default.configure({user:e.user,render:i,provider:e.provider}))}return n},So=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 Y{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 vi extends Y{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 xe=new y.PluginKey("blocknote-comments"),Ei="SET_SELECTED_THREAD_ID";function Bi(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 Ti extends Y{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=>{const o=this.editor._tiptapEditor;o.state.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{tr:u}=o.state,h=Math.max(s,0),f=Math.min(s+r.nodeSize,o.state.doc.content.size-1);u.removeMark(h,f,i),u.addMark(h,f,a.create({...i.attrs,orphan:d})),o.dispatch(u),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 vi(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 y.Plugin({key:xe,state:{init(){return{decorations:x.DecorationSet.empty}},apply(i,a){const l=i.getMeta(xe);if(!i.docChanged&&!l)return a;const c=i.docChanged?Bi(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=xe.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.dispatch(this.editor.prosemirrorView.state.tr.setMeta(xe,{name:Ei})),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=ne.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?ne.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 vo{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 Ge=new y.PluginKey("FilePanelPlugin");class Eo extends Y{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 y.Plugin({key:Ge,view:o=>(this.view=new vo(t,Ge,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(Ge))==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 Bo{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 To=new y.PluginKey("FormattingToolbarPlugin");class xo extends Y{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new y.Plugin({key:To,view:o=>(this.view=new Bo(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 xi=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
|
+
`}}),Rt=(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))},Ae=(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))},Po=(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},Pi=(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*",Mi=(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},Vt=e=>({state:n,dispatch:t})=>{const o=n.doc.resolve(e),r=pe(o),s=Ae(n.doc,r.bnBlock.beforePos);if(!s)return!1;const i=Po(n.doc,s);return Pi(i,r)?Mi(n,t,i,r):!1},Ii=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=S(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(L(this.options.editor,i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=S(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=S(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(Vt(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=S(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||Ae(s.doc,a.bnBlock.beforePos))return!1;const d=Rt(s.doc,a.bnBlock.beforePos);if((d==null?void 0:d.blockNoteType)!=="column")return!1;const u=d,h=Rt(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 we.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,u.bnBlock.afterPos+1,h.bnBlock.afterPos-2,b,b.size,!1));const w=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(y.TextSelection.between(w,w))}else{s.tr.step(new we.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,h.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const w=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(y.TextSelection.between(w,w))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(h.bnBlock.beforePos,b.content);const w=s.tr.doc.resolve(h.bnBlock.beforePos);s.tr.setSelection(y.TextSelection.between(w,w))}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 w=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(y.TextSelection.between(w,w))}}return!0}),()=>r.command(({state:s})=>{const i=S(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=Ae(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=S(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=Ae(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=Po(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=S(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(Vt(g-1))}return!1})]),t=(o=!1)=>this.editor.commands.first(({commands:r})=>[()=>r.command(({state:s})=>{const i=S(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=S(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=S(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 y.TextSelection(s.doc.resolve(m)))}return!0}return!1}),()=>r.command(({state:s,chain:i})=>{const a=S(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(Kn(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:ho(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 Li{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 r;const o=this.pmView.state.tr.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:n})),this.editor.dispatch(o),this.pmView.focus(),(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var n;this.editor.dispatch(this.pmView.state.tr.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 Mo=new y.PluginKey("LinkToolbarPlugin");class Io extends Y{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 y.Plugin({key:Mo,view:o=>(this.view=new Li(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 Lo=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],Ao="https",Ai=new y.PluginKey("node-selection-keyboard");class Ni{constructor(){p(this,"plugin");this.plugin=new y.Plugin({key:Ai,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 y.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}})}}const Hi=new y.PluginKey("blocknote-placeholder");class Di{constructor(n,t){p(this,"plugin");this.plugin=new y.Plugin({key:Hi,view:o=>{var c,d;const r=`placeholder-selector-${qt.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,w]of Object.entries(f)){const C=`[data-content-type="${b}"]`;a.insertRule(`${l(C)} { content: ${JSON.stringify(w)}; }`)}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 Ft=new y.PluginKey("previous-blocks"),Oi={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class _i{constructor(){p(this,"plugin");let n;this.plugin=new y.Plugin({key:Ft,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(Ft,{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-"+Oi[d]]=u||"none";const c=x.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),x.DecorationSet.create(t.doc,r)}}})}}const Ut=new y.PluginKey("blocknote-show-selection");class Ri{constructor(n){p(this,"plugin");p(this,"enabled",!1);this.editor=n,this.plugin=new y.Plugin({key:Ut,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){var t,o;this.enabled!==n&&(this.enabled=n,(o=this.editor.prosemirrorView)==null||o.dispatch((t=this.editor.prosemirrorView)==null?void 0:t.state.tr.setMeta(Ut,{})))}getEnabled(){return this.enabled}}function No(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 ae extends y.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 ae(t.resolve(o),t.resolve(r))}content(){return new B.Slice(B.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof ae)||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?y.Selection.near(t.resolve(r.pos)):r.deleted?y.Selection.near(t.resolve(s.pos)):new ae(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let U;function Vi(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 $t(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]);Ho(e.root),U=o;const l=U.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(" ");U.className=U.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild(U):e.root.body.appendChild(U)}function Ho(e){U!==void 0&&(e instanceof ShadowRoot?e.removeChild(U):e.body.removeChild(U),U=void 0)}function Fi(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}=Vi(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof ae;d&&u?(o.dispatch(o.state.tr.setSelection(ae.create(a,l,c))),$t(o,l,c)):(o.dispatch(o.state.tr.setSelection(y.NodeSelection.create(o.state.doc,s))),$t(o,s));const h=o.state.selection.content(),f=t.pmSchema,m=o.serializeForClipboard(h).dom.innerHTML,g=Ee(f,t),b=yo(h.content,t.schema),w=g.exportBlocks(b,{}),C=We(w);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",w),e.dataTransfer.setData("text/plain",C),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(U,0,0)}}const be=.1;function at(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]")?at(e,{left:n.left+50,top:n.top},t,!1):No(s,e)}function Ui(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=at(n,r,t);if(!i&&a){const l=a.node.getBoundingClientRect();r.left=l.right-10,a=at(n,r,"viewport",!1)}return a}class Do{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=Ui(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(y.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),ze(),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 Oo=new y.PluginKey("SideMenuPlugin");class _o extends Y{constructor(t,o){super();p(this,"view");p(this,"plugin");p(this,"blockDragStart",(t,o)=>{this.view&&(this.view.isDragOrigin=!0),Fi(t,o,this.editor)});p(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&Ho(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 y.Plugin({key:Oo,view:r=>(this.view=new Do(t,o,r,s=>{this.emit("update",s)}),this.view)})}onUpdate(t){return this.on("update",t)}}const Pe=new Map;function $i(e){if(Pe.has(e))return Pe.get(e);const n=new we.Mapping;return e._tiptapEditor.on("transaction",({transaction:t})=>{n.appendMapping(t.mapping)}),e._tiptapEditor.on("destroy",()=>{Pe.delete(e)}),Pe.set(e,n),n}function zi(e,n,t="left"){const o=ne.ySyncPluginKey.getState(e.prosemirrorState);if(!o){const s=$i(e),i=s.maps.length;return()=>s.slice(i).map(n,t==="left"?-1:1)}const r=ne.absolutePositionToRelativePosition(n+(t==="right"?1:0),o.binding.type,o.binding.mapping);return()=>{const s=ne.ySyncPluginKey.getState(e.prosemirrorState),i=ne.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 Wi=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.dispatch(this.editor._tiptapEditor.state.tr.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._tiptapEditor.state.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 y.PluginKey("SuggestionMenuPlugin");class Ro extends Y{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 y.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===void 0){const d=zi(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())return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos(),a.selection.from),c}},props:{handleTextInput(r,s,i,a){const l=this.getState(r.state);return o.includes(a)&&l===void 0?(r.dispatch(r.state.tr.insertText(a).scrollIntoView().setMeta(le,{triggerCharacter:a})),!0):!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=Wi(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 Ki(e,n){e.suggestionMenus.addTriggerCharacter(n)}let O;function zt(e){O||(O=document.createElement("div"),O.innerHTML="_",O.style.opacity="0",O.style.height="1px",O.style.width="1px",e instanceof Document?e.body.appendChild(O):e.appendChild(O))}function ji(e){O&&(e instanceof Document?e.body.removeChild(O):e.removeChild(O),O=void 0)}function Me(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Gi(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 Xi(e,n){const t=n.querySelectorAll(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class Vo{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=Gi(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=No(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=_(r.id,this.editor._tiptapEditor.state.doc);if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=T(i.node,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache);if(so("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,w=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:w,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=Me(t.domNode),w=Me(t.domNode.parentElement),C=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===w&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:w===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:C,colIndex:b,rowIndex:w,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",Xi(".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=Me(r.parentElement),a=Me(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.dispatch(this.pmView.state.tr.setMeta(ie,!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(!rn(this.state.block,t.originalIndex,r))return!1;const i=Ir(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!sn(this.state.block,t.originalIndex,o))return!1;const i=Mr(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}=mt(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 ie=new y.PluginKey("TableHandlesPlugin");class Fo extends Y{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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(ie,{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(O,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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(ie,{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(O,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.dispatch(this.editor._tiptapEditor.state.tr.setMeta(ie,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");ji(this.editor.prosemirrorView.root)});p(this,"freezeHandles",()=>{this.view.menuFrozen=!0});p(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});p(this,"getCellsAtRowHandle",(t,o)=>Qe(t,o));p(this,"getCellsAtColumnHandle",(t,o)=>et(t,o));p(this,"setCellSelection",(t,o=t)=>{const r=this.view;if(!r)throw new Error("Table handles view not initialized");const s=this.editor.prosemirrorState,i=s.doc.resolve(r.tablePos+1),a=s.doc.resolve(i.posAtIndex(t.row)+1),l=s.doc.resolve(a.posAtIndex(t.col)),c=s.doc.resolve(i.posAtIndex(o.row)+1),d=s.doc.resolve(c.posAtIndex(o.col)),u=s.tr;return u.setSelection(new M.CellSelection(l,d)),s.apply(u)});p(this,"addRowOrColumn",(t,o)=>{const r=this.setCellSelection(o.orientation==="row"?{row:t,col:0}:{row:0,col:t});return o.orientation==="row"?o.side==="above"?M.addRowBefore(r,this.editor.dispatch):M.addRowAfter(r,this.editor.dispatch):o.side==="left"?M.addColumnBefore(r,this.editor.dispatch):M.addColumnAfter(r,this.editor.dispatch)});p(this,"removeRowOrColumn",(t,o)=>{const r=this.setCellSelection(o==="row"?{row:t,col:0}:{row:0,col:t});return o==="row"?M.deleteRow(r,this.editor.dispatch):M.deleteColumn(r,this.editor.dispatch)});p(this,"mergeCells",t=>{const o=t?this.setCellSelection(t.relativeStartCell,t.relativeEndCell):this.editor.prosemirrorState;return M.mergeCells(o,this.editor.dispatch)});p(this,"splitCell",t=>{const o=t?this.setCellSelection(t):this.editor.prosemirrorState;return M.splitCell(o,this.editor.dispatch)});p(this,"getCellSelection",()=>{const t=this.editor.prosemirrorState,o=t.selection;let r=o.$from,s=o.$to;if(st(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=>{const o=st(this.editor.prosemirrorState.selection)?this.editor.prosemirrorState.selection:void 0;if(!o||!t||o.ranges.length<=1)return;const r=this.getCellSelection();if(r)return Nr(r.from,r.to,t)?"vertical":"horizontal"});p(this,"cropEmptyRowsOrColumns",(t,o)=>Lr(t,o));p(this,"addRowsOrColumns",(t,o,r)=>Ar(t,o,r));this.editor=t,this.plugin=new y.Plugin({key:ie,view:o=>(this.view=new Vo(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"&&!rn(i,l,r)||c==="col"&&!sn(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"?Qe(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(),w=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(w,()=>{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}))}):et(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(),w=g.pos+(r>l?b.nodeSize-2:0);s.push(x.Decoration.widget(w,()=>{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 Ji=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}}}}]}}),Yi=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}}}}]}}),Zi=k.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new y.PluginKey(this.name);return[new y.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*"}}})]}}),Qi={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},ea=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(Qi))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=X("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}}}),ta=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=X("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}}}),na=k.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Uo=e=>{const n={},t=oa(e);for(const r of t)n[r.name]=r;n.formattingToolbar=new xo(e.editor),n.linkToolbar=new Io(e.editor),n.sideMenu=new _o(e.editor,e.sideMenuDetection),n.suggestionMenus=new Ro(e.editor),n.filePanel=new Eo(e.editor),n.placeholder=new Di(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new _i),e.tableHandles&&(n.tableHandles=new Fo(e.editor)),n.dropCursor={plugin:e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})},n.nodeSelectionKeyboard=new Ni,n.showSelection=new Ri(e.editor),e.comments&&(n.comments=new Ti(e.editor,e.comments.threadStore,So.name));const o=e.disableExtensions||[];for(const r of o)delete n[r];return n};let Wt=!1;const oa=e=>{const n=[k.extensions.ClipboardTextSerializer,k.extensions.Commands,k.extensions.Editable,k.extensions.FocusEvents,k.extensions.Tabindex,ar.Gapcursor,he.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),xi,dr.Text,cr.Link.extend({inclusive:!1}).configure({defaultProtocol:Ao,protocols:Wt?[]:Lo}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),Yi,Ci,Ji,k.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),na,ea.configure({editor:e.editor,domAttributes:e.domAttributes}),Ii.configure({editor:e.editor,tabBehavior:e.tabBehavior}),ta.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})]),yi(e.editor),ki(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),ti(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[Zi]:[],...e.comments?[So]:[]];return Wt=!0,e.collaboration?n.push(...Si(e.collaboration)):n.push(lr.History),n};function ra(e,n){const t=[];return e.forEach((o,r,s)=>{s!==n&&t.push(o)}),B.Fragment.from(t)}function sa(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 ia(e,n){let t=B.Fragment.from(e.content);if(t=sa(t,n.state.schema),!aa(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=ra(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 aa(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=S(n.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const _e=class _e 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=>te(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=y.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){this.view?this.view.dispatch(t):this._state=this.state.apply(t)}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.dispatchTransaction.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(_e,"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 _e(t,o)}finally{r&&(globalThis.window.setTimeout=r)}});let Oe=_e;Oe.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const la={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Tt extends Y{constructor(t){var c,d,u,h,f,m,g,b,w,C,v,A,W,q,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,"dispatch",t=>{this._tiptapEditor.dispatch(t)});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||fr.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=Uo({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:H("table",this),dropCursor:this.options.dropCursor??hr.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,sideMenuDetection:r.sideMenuDetection||"viewport",comments:r.comments,pasteHandler:r.pasteHandler}),(((w=r._tiptapOptions)==null?void 0:w.extensions)||[]).forEach(E=>{this.extensions[E.name]=E}),Object.entries(r._extensions||{}).forEach(([E,D])=>{typeof D=="function"&&(D=D(this)),this.extensions[E]=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,r.uploadFile){const E=r.uploadFile;this.uploadFile=async(D,se)=>{this.onUploadStartCallbacks.forEach(qe=>qe.apply(this,[se]));try{return await E(D,se)}finally{this.onUploadEndCallbacks.forEach(qe=>qe.apply(this,[se]))}}}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:he.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(([E,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:E,addProseMirrorPlugins:()=>[D.plugin]})})],l={...la,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(C=r._tiptapOptions)==null?void 0:C.editorProps,attributes:{tabIndex:"0",...(A=(v=r._tiptapOptions)==null?void 0:v.editorProps)==null?void 0:A.attributes,...(W=r.domAttributes)==null?void 0:W.editor,class:X("bn-editor",r.defaultStyles?"bn-default-styles":"",((I=(q=r.domAttributes)==null?void 0:q.editor)==null?void 0:I.class)||"")},transformPasted:ia}};this.headless?this.pmSchema=k.getSchema(l.extensions):(this._tiptapEditor=Oe.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.emit("create")}static create(t={}){return new Tt(t)}get prosemirrorView(){return this._tiptapEditor.view}get prosemirrorState(){return this._tiptapEditor.state}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(){const t=[];return this.prosemirrorState.doc.firstChild.descendants(o=>(t.push(T(o,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){return _s(this,t)}getPrevBlock(t){return Rs(this,t)}getNextBlock(t){return Vs(this,t)}getParentBlock(t){return Fs(this,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 Ws(this)}setTextCursorPosition(t,o="start"){mo(this,t,o)}getSelection(){return $s(this)}setSelection(t,o){zs(this,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 Ts(this,t,o,r)}updateBlock(t,o){return ln(this,t,o)}removeBlocks(t){return Os(this,t)}replaceBlocks(t,o){return Ds(this,t,o)}insertInlineContent(t){const o=R(t,this.pmSchema,this.schema.styleSchema);Us({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},o,this)}getActiveStyles(){const t={},o=this._tiptapEditor.state.selection.$to.marks();for(const r of o){const s=this.schema.styleSchema[r.type.name];if(!s){r.type.name!=="link"&&!r.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",r.type.name);continue}s.propSchema==="boolean"?t[s.type]=!0:t[s.type]=r.attrs.stringValue}return t}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 F(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 F(s.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,o){if(t==="")return;const{from:r,to:s}=this._tiptapEditor.state.selection,i=this.pmSchema.mark("link",{href:t});this.dispatch(o?this._tiptapEditor.state.tr.insertText(o,r,s).addMark(r,r+o.length,i):this._tiptapEditor.state.tr.setSelection(y.TextSelection.create(this._tiptapEditor.state.tr.doc,s)).addMark(r,s,i))}canNestBlock(){return Ns(this)}nestBlock(){ho(this)}canUnnestBlock(){return Hs(this)}unnestBlock(){As(this)}moveBlocksUp(){Ms(this)}moveBlocksDown(){Is(this)}async blocksToHTMLLossy(t=this.document){return Ee(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return fn(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return vt(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return go(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return ko(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,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=()=>{t(this)};return this._tiptapEditor.on("update",o),()=>{this._tiptapEditor.off("update",o)}}onSelectionChange(t,o){if(this.headless)return;const r=s=>{s.transaction.getMeta(ne.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){var i;const r=(i=this.prosemirrorView)==null?void 0:i.state.tr;if(!r)return;const s=o&&o.deleteTriggerCharacter?r.insertText(t):r;this.prosemirrorView.focus(),this.prosemirrorView.dispatch(s.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 bo(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 Et(t))}}const ca={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"}},da={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 ua{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 pa(e){return{createBlockMapping:n=>n,createInlineContentMapping:n=>n,createStyleMapping:n=>n}}let Ie;async function ha(){return Ie||(Ie=(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}})(),Ie)}async function fa(e,n){if(!ro("text",e))return[];const{emojiData:t,emojiMart:o}=await ha();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 ma(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}function Xe(e=""){return typeof e=="string"?[{type:"text",text:e,styles:{}}]:e}function ce(e){var n,t,o,r,s;return typeof e=="string"?Xe(e):Array.isArray(e)?e.flatMap(i=>typeof i=="string"?Xe(i):Ve(i)?{...i,content:Xe(i.content)}:G(i)?i:{props:{},...i,content:ce(i.content)}):(e==null?void 0:e.type)==="tableContent"?{type:"tableContent",columnWidths:e.columnWidths,headerRows:e.headerRows,headerCols:e.headerCols,rows:e.rows.map(i=>({...i,cells:i.cells.map(a=>ce(a))}))}:(e==null?void 0:e.type)==="tableCell"?{type:"tableCell",content:ce(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}}:e}function ga(e,n){return n.map(t=>xt(e.blockSchema,t))}function xt(e,n){var r;const t=e[n.type].content,o={id:"",type:n.type,props:{},content:t==="inline"?[]:t==="table"?{type:"tableContent",columnWidths:void 0,headerRows:void 0,headerCols:void 0,rows:[]}:void 0,children:[],...n};if(Object.entries(e[n.type].propSchema).forEach(([s,i])=>{o.props[s]===void 0&&i.default!==void 0&&(o.props[s]=i.default)}),t==="inline"){const s=o.content;o.content=ce(s)}else if(t==="table"){const s=o.content;o.content={type:"tableContent",columnWidths:(s==null?void 0:s.columnWidths)||((r=s==null?void 0:s.rows[0])==null?void 0:r.cells.map(()=>{}))||[],headerRows:(s==null?void 0:s.headerRows)||void 0,headerCols:(s==null?void 0:s.headerCols)||void 0,rows:(s==null?void 0:s.rows.map(i=>({cells:i.cells.map(a=>ce(a))})))||[]}}return{...o,content:ce(o.content),children:o.children.map(s=>xt(e,s))}}function $o(e){e.id||(e.id=he.options.generateID()),e.children&&zo(e.children)}function zo(e){for(const n of e)$o(n)}exports.AudioBlock=En;exports.BlockNoteEditor=Tt;exports.BlockNoteSchema=ge;exports.COLORS_DARK_MODE_DEFAULT=da;exports.COLORS_DEFAULT=ca;exports.CodeBlock=Tn;exports.DEFAULT_LINK_PROTOCOL=Ao;exports.EMPTY_CELL_HEIGHT=ds;exports.EMPTY_CELL_WIDTH=kt;exports.Exporter=ua;exports.FILE_AUDIO_ICON_SVG=kn;exports.FILE_ICON_SVG=gn;exports.FILE_IMAGE_ICON_SVG=Nn;exports.FILE_VIDEO_ICON_SVG=Xn;exports.FileBlock=An;exports.FilePanelProsemirrorPlugin=Eo;exports.FilePanelView=vo;exports.FormattingToolbarProsemirrorPlugin=xo;exports.FormattingToolbarView=Bo;exports.HTMLToBlocks=vt;exports.ImageBlock=Vn;exports.LinkToolbarProsemirrorPlugin=Io;exports.PageBreak=Wn;exports.SideMenuProsemirrorPlugin=_o;exports.SideMenuView=Do;exports.SuggestionMenuProseMirrorPlugin=Ro;exports.TableHandlesProsemirrorPlugin=Fo;exports.TableHandlesView=Vo;exports.UniqueID=he;exports.UnreachableCaseError=F;exports.VALID_LINK_PROTOCOLS=Lo;exports.VideoBlock=to;exports.addIdsToBlock=$o;exports.addIdsToBlocks=zo;exports.addInlineContentAttributes=Ze;exports.addInlineContentKeyboardShortcuts=Jt;exports.addStyleAttributes=tn;exports.applyNonSelectableBlockFix=Gt;exports.assertEmpty=Sr;exports.audioBlockConfig=yn;exports.audioParse=Sn;exports.audioPropSchema=wn;exports.audioRender=Cn;exports.audioToExternalHTML=vn;exports.blockToNode=te;exports.blocksToMarkdown=go;exports.camelToDataKebab=ye;exports.checkBlockHasDefaultProp=ys;exports.checkBlockIsDefaultType=so;exports.checkBlockIsFileBlock=bs;exports.checkBlockIsFileBlockWithPlaceholder=ws;exports.checkBlockIsFileBlockWithPreview=ks;exports.checkBlockTypeHasDefaultProp=io;exports.checkDefaultBlockTypeInSchema=H;exports.checkDefaultInlineContentTypeInSchema=ro;exports.checkPageBreakBlocksInSchema=ao;exports.cleanHTMLToMarkdown=We;exports.combineByGroup=ma;exports.contentNodeToInlineContent=Se;exports.contentNodeToTableContent=ut;exports.createAddFileButton=mn;exports.createBlockSpec=me;exports.createBlockSpecFromStronglyTypedTiptapNode=J;exports.createDefaultBlockDOMOutputSpec=$;exports.createExternalHTMLExporter=Ee;exports.createFigureWithCaption=$e;exports.createFileBlockWrapper=Ue;exports.createFileNameWithIcon=bn;exports.createInlineContentSpec=xr;exports.createInlineContentSpecFromTipTapNode=Zt;exports.createInternalBlockSpec=ct;exports.createInternalHTMLSerializer=fn;exports.createInternalInlineContentSpec=Yt;exports.createInternalStyleSpec=ht;exports.createLinkWithCaption=Te;exports.createResizableFileBlockWrapper=gt;exports.createStronglyTypedTiptapNode=z;exports.createStyleSpec=Pr;exports.createStyleSpecFromTipTapMark=Z;exports.createSuggestionMenu=Ki;exports.defaultBlockSchema=no;exports.defaultBlockSpecs=wt;exports.defaultBlockToHTML=Ye;exports.defaultCodeBlockPropSchema=Bn;exports.defaultInlineContentSchema=oo;exports.defaultInlineContentSpecs=Ct;exports.defaultProps=P;exports.defaultStyleSchema=gs;exports.defaultStyleSpecs=yt;exports.fileBlockConfig=Pn;exports.fileParse=In;exports.filePropSchema=xn;exports.fileRender=Mn;exports.fileToExternalHTML=Ln;exports.filenameFromURL=Tr;exports.filterSuggestionItems=vs;exports.formatKeyboardShortcut=K;exports.formattingToolbarPluginKey=To;exports.getBlockFromPos=jt;exports.getBlockInfo=Q;exports.getBlockInfoFromResolvedPos=pe;exports.getBlockInfoFromSelection=S;exports.getBlockInfoWithManualOffset=Re;exports.getBlockNoteExtensions=Uo;exports.getBlockSchemaFromSpecs=dt;exports.getColspan=ue;exports.getDefaultEmojiPickerItems=fa;exports.getDefaultSlashMenuItems=Ss;exports.getInlineContentParseRules=Qt;exports.getInlineContentSchemaFromSpecs=pt;exports.getNearestBlockPos=j;exports.getNodeById=_;exports.getPageBreakSlashMenuItems=Bs;exports.getParseRules=Xt;exports.getRowspan=He;exports.getStyleParseRules=nn;exports.getStyleSchemaFromSpecs=ft;exports.imageBlockConfig=Dn;exports.imageParse=_n;exports.imagePropSchema=Hn;exports.imageRender=On;exports.imageToExternalHTML=Rn;exports.inheritedProps=lt;exports.initializeESMDependencies=ze;exports.inlineContentToNodes=R;exports.insertOrUpdateBlock=N;exports.isAppleOS=Kt;exports.isLinkInlineContent=Je;exports.isPartialLinkInlineContent=Ve;exports.isPartialTableCell=de;exports.isSafari=Br;exports.isStyledTextInlineContent=G;exports.isTableCell=Fe;exports.isTableCellSelection=st;exports.linkToolbarPluginKey=Mo;exports.mapTableCell=Ne;exports.mappingFactory=pa;exports.markdownToBlocks=ko;exports.markdownToHTML=Et;exports.mergeCSSClasses=X;exports.nodeToBlock=T;exports.nodeToCustomInlineContent=De;exports.pageBreakConfig=Fn;exports.pageBreakParse=$n;exports.pageBreakRender=Un;exports.pageBreakSchema=St;exports.pageBreakToExternalHTML=zn;exports.parseEmbedElement=rt;exports.parseFigureElement=Be;exports.partialBlockToBlockForTesting=xt;exports.partialBlocksToBlocksForTesting=ga;exports.propsToAttributes=fe;exports.shikiHighlighterPromiseSymbol=Le;exports.shikiParserSymbol=ot;exports.sideMenuPluginKey=Oo;exports.stylePropsToAttributes=en;exports.tableContentToNodes=ve;exports.tableHandlesPluginKey=ie;exports.updateBlock=ln;exports.updateBlockCommand=L;exports.uploadToTmpFilesDotOrg_DEV_ONLY=Ur;exports.videoBlockConfig=Yn;exports.videoParse=Qn;exports.videoPropSchema=Jn;exports.videoRender=Zn;exports.videoToExternalHTML=eo;exports.withPageBreak=Es;exports.wrapInBlockStructure=ke;
|
|
13
13
|
//# sourceMappingURL=blocknote.cjs.map
|