@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
10 lines (9 loc) • 199 kB
JavaScript
"use strict";var kr=Object.create;var rt=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var yr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,vr=Object.prototype.hasOwnProperty;var Sr=(e,n,t)=>n in e?rt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Er=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of yr(n))!vr.call(e,r)&&r!==t&&rt(e,r,{get:()=>n[r],enumerable:!(o=wr(n,r))||o.enumerable});return e};var K=(e,n,t)=>(t=e!=null?kr(Cr(e)):{},Er(n||!e||!e.__esModule?rt(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>Sr(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("prosemirror-model"),he=require("prosemirror-transform"),k=require("@tiptap/core"),C=require("prosemirror-state"),fn=require("uuid"),Br=require("prosemirror-highlight"),Tr=require("prosemirror-highlight/shiki"),xr=require("@tiptap/extension-bold"),Pr=require("@tiptap/extension-code"),Mr=require("@tiptap/extension-italic"),Ir=require("@tiptap/extension-strike"),Lr=require("@tiptap/extension-underline"),Ar=require("@tiptap/extension-table-cell"),Nr=require("@tiptap/extension-table-header"),H=require("prosemirror-tables"),Dr=require("@tiptap/extension-gapcursor"),Hr=require("@tiptap/extension-history"),Or=require("@tiptap/extension-link"),Rr=require("@tiptap/extension-text"),N=require("y-prosemirror"),D=require("prosemirror-view"),_r=require("yjs"),jt=require("prosemirror-history"),Vr=require("prosemirror-dropcursor"),Ur=require("./en-CsgPjHa4.cjs"),Ee=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function Fr(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const $r=Ee(xr),zr=Ee(Pr),Wr=Ee(Mr),qr=Ee(Ir),Kr=Ee(Lr),ie=Fr(_r);function jr(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 Gr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return jr(n)}const Be=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 fn.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 C.Plugin({key:new C.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,y=>l.includes(y.type.name)),b=g.map(({node:y})=>y.attrs[c]).filter(y=>y!==null),w=Gr(b);g.forEach(({node:y,pos:v})=>{let B;const _=(B=a.doc.nodeAt(v))===null||B===void 0?void 0:B.attrs[c];if(_===null){const x=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(x)===null){const M=JSON.parse(JSON.stringify(r.doc.toJSON()));if(M.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(M.content)===JSON.stringify(x.toJSON())){a.setNodeMarkup(v,void 0,{...y.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(v,void 0,{...y.attrs,[c]:d()});return}const{deleted:q}=h.invert().mapResult(v);q&&w.includes(_)&&a.setNodeMarkup(v,void 0,{...y.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)}),S.Fragment.from(a)};return n=!1,new S.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function lt(e){return e.type==="link"}function St(e){return typeof e!="string"&&e.type==="link"}function oe(e){return typeof e!="string"&&e.type==="text"}function Ve(e){var n,t,o,r,s;return qe(e)?{...e}:fe(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 fe(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function qe(e){return fe(e)&&e.props!==void 0&&e.content!==void 0}function me(e){return qe(e)?e.props.colspan??1:1}function Ue(e){return qe(e)?e.props.rowspan??1:1}class j extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Yr(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))}const mn=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function J(e,n="Ctrl"){return mn()?e.replace("Mod","⌘"):e.replace("Mod",n)}function Q(...e){return[...new Set(e.filter(n=>n).join(" ").split(" "))].join(" ")}const Jr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function $(e,n,t,o){const r=document.createElement("div");r.className=Q("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=Q("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 ct=(e,n)=>{let t=se(e,n.pmSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const o=n.pmSchema.nodes[t.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=o(t);if(typeof r!="object"||!("dom"in r))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return r};function gn(e){const n=e.querySelectorAll("p");if(n.length>1){const t=n[0];for(let o=1;o<n.length;o++){const r=n[o];t.innerHTML+="<br>"+r.innerHTML,r.remove()}}}const I={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},Et=["backgroundColor","textColor"];function ve(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Xr(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function ge(e){const n={};return Object.entries(e).filter(([t,o])=>!Et.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(ve(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?{[ve(t)]:r[t]}:{}}}),n}function Ke(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 Ce(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=Q("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;!Et.includes(a)&&l!==d&&i.setAttribute(ve(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=Q("bn-inline-content",e.contentDOM.className)),{...e,dom:i}}function G(e){return k.Node.create(e)}function Bt(e,n){return{config:e,implementation:n}}function Z(e,n,t){return Bt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:ct,toExternalHTML:ct})}function Tt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function bn(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function kn(e,n){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return n&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=n==null?void 0:n(o);return r===void 0?!1:r}}),t}function be(e,n){const t=G({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return ge(e.propSchema)},parseHTML(){return kn(e,n.parse)},renderHTML({HTMLAttributes:o}){const r=document.createElement("div");return Ce({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=Ke(o,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=n.render(s,r),l=Ce(a,s.type,s.props,e.propSchema,e.isFileBlock,i);return e.isSelectable===!1&&bn(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 Bt(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 Ce(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)),Ce(i,o.type,o.props,e.propSchema,s)}})}function X(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 je(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.name}`);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 ee(e){return je(e.node,e.posBeforeNode)}function ke(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 je(e.nodeAfter,e.pos)}function E(e){const n=X(e.doc,e.selection.anchor);return ee(n)}function Te(e){const n=X(e.doc,e.selection.anchor);return ee(n)}function R(e){return"doc"in e?e.doc.type.schema:e.type.schema}function wn(e){return e.cached.blockNoteEditor}function we(e){return wn(e).schema}function Ge(e){return we(e).blockSchema}function Ye(e){return we(e).inlineContentSchema}function ce(e){return we(e).styleSchema}function Je(e){return wn(e).blockCache}function xt(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=>xe(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],w=g[0];return w&&oe(b)&&oe(w)&&JSON.stringify(b.styles)===JSON.stringify(w.styles)?(b.text+=`
`+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 xe(e,n,t){const o=[];let r;return e.content.forEach(s=>{if(s.type.name==="hardBreak"){if(r)if(oe(r))r.text+=`
`;else if(lt(r))r.content[r.content.length-1].text+=`
`;else throw new Error("unexpected");else r={type:"text",text:`
`,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(Fe(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 j(c.propSchema)}r?oe(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}):lt(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 Fe(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=xe(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function T(e,n,t=Ge(n),o=Ye(n),r=ce(n),s=Je(n)){var g;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const i=s==null?void 0:s.get(e);if(i)return i;const a=je(e,0);let l=a.bnBlock.node.attrs.id;l===null&&(l=Be.options.generateID());const c=t[a.blockNoteType];if(!c)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const d={};for(const[b,w]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const y=c.propSchema;b in y&&!(y[b].default===void 0&&w===void 0)&&(d[b]=w)}const u=t[a.blockNoteType],h=[];(g=a.childContainer)==null||g.node.forEach(b=>{h.push(T(b,n,t,o,r,s))});let f;if(u.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");f=xe(a.blockContent.node,o,r)}else if(u.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");f=xt(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new j(u.content);const m={id:l,type:u.type,props:d,content:f,children:h};return s==null||s.set(e,m),m}function yn(e,n,t=Ge(n),o=Ye(n),r=ce(n),s=Je(n)){const i=[];return e.firstChild.descendants(a=>(i.push(T(a,n,t,o,r,s)),!1)),i}function Cn(e,n,t=Ge(n),o=Ye(n),r=ce(n),s=Je(n)){function i(a,l,c){if(a.type.name!=="blockGroup")throw new Error("unexpected");const d=[];let u,h;return a.forEach((f,m,g)=>{if(f.type.name!=="blockContainer")throw new Error("unexpected");if(f.childCount===0)return;if(f.childCount===0||f.childCount>2)throw new Error("unexpected, blockContainer.childCount: "+f.childCount);const b=g===0,w=g===a.childCount-1;if(f.firstChild.type.name==="blockGroup"){if(!b)throw new Error("unexpected");const _=i(f.firstChild,Math.max(0,l-1),w?Math.max(0,c-1):0);u=_.blockCutAtStart,w&&(h=_.blockCutAtEnd),d.push(..._.blocks);return}const y=T(f,n,t,o,r,s),v=f.childCount>1?f.child(1):void 0;let B=[];if(v){const _=i(v,0,w?Math.max(0,c-1):0);B=_.blocks,w&&(h=_.blockCutAtEnd)}w&&!v&&c>1&&(h=y.id),b&&l>1&&(u=y.id),d.push({...y,children:B})}),{blocks:d,blockCutAtStart:u,blockCutAtEnd:h}}if(e.content.childCount===0)return{blocks:[],blockCutAtStart:void 0,blockCutAtEnd:void 0};if(e.content.childCount!==1)throw new Error("slice must be a single block, did you forget includeParents=true?");return i(e.content.firstChild,Math.max(e.openStart-1,0),Math.max(e.openEnd-1,0))}function dt(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])=>[ve(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function vn(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 Sn(e,n){return{config:e,implementation:n}}function En(e,n){return Sn({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 Bn(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 Zr(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 ge(e.propSchema)},addKeyboardShortcuts(){return vn(e)},parseHTML(){return Bn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render(Fe(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return dt(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render(Fe(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=W([a],s.pmSchema);s.transact(c=>c.replaceWith(r(),r()+o.nodeSize,l))},s);return dt(i,e.type,o.attrs,e.propSchema)}}});return En(t,e.propSchema)}function Tn(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 xn(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 Mt(e,n){return{config:e,implementation:n}}function ne(e,n){return Mt({type:e.name,propSchema:n},{mark:e})}function It(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Pn(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 Qr(e,n){const t=k.Mark.create({name:e.type,addAttributes(){return Tn(e.propSchema)},parseHTML(){return Pn(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 j(e.propSchema);return xn(r,e.type,o.attrs.stringValue,e.propSchema)}});return Mt(e,{mark:t})}function re(e){const{height:n,width:t}=Lt(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=Ve(e.content.rows[s].cells[i]),l=Ue(a),c=me(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 Se(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 le(e,n,t=re(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 Lt(e){const n=e.content.rows.length;let t=0;return e.content.rows.forEach(o=>{let r=0;o.cells.forEach(s=>{r+=me(s)}),t=Math.max(t,r)}),{height:n,width:t}}function Mn(e,n,t=re(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 ut(e,n){var s;const t=re(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)=>Mn({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 pt(e,n){var s;const t=re(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)=>Mn({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 es(e,n,t,o=re(e)){const{col:r}=le({row:0,col:n},e,o),{col:s}=le({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),Se(o)}function ts(e,n,t,o=re(e)){const{row:r}=le({row:n,col:0},e,o),{row:s}=le({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),Se(o)}function ht(e){return e?fe(e)?ht(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:oe(n)?n.text.length===0:St(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function ns(e,n,t=re(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>ht(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 Se(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>ht(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),Se(t)}function os(e,n,t,o=re(e)){const{width:r,height:s}=Lt(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:Ve("")});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:Ve("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return Se(o)}function In(e,n,t){const o=ut(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.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function Ln(e,n,t){const o=pt(e,t);if(!o.some(l=>me(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=me(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function rs(e,n,t){const o=le(e,t),r=le(n,t);return o.col===r.col}function Gt(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")a&&r.push(n.mark(i));else if(l.propSchema==="string")a&&r.push(n.mark(i,{stringValue:a}));else throw new j(l.propSchema)}return!o||!n.nodes[o].spec.code?e.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
`?n.nodes.hardBreak.createChecked():n.text(i,r)):e.text.length>0?[n.text(e.text,r)]:[]}function ss(e,n,t){const o=n.marks.link.create({href:e.href});return ft(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 ft(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Gt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Gt(s,n,t,o));return r}function W(e,n,t,o=ce(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...ft(s,n,o,t)):St(s)?r.push(...ss(s,n,o)):oe(s)?r.push(...ft([s],n,o,t)):r.push(An(s,n,o));return r}function Pe(e,n,t=ce(n)){const o=[],r=new Array(e.headerRows??0).fill(!0),s=new Array(e.headerCols??0).fill(!0),i=e.columnWidths??[];for(let a=0;a<e.rows.length;a++){const l=e.rows[a],c=[],d=r[a];for(let h=0;h<l.cells.length;h++){const f=l.cells[h],m=s[h],g=void 0;let b=null;const w=le({row:a,col:h},{content:e});let y=i[w.col]?[i[w.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(fe(f)){f.content&&(b=W(f.content,n,"tableParagraph",t));const B=me(f);B>1&&(y=new Array(B).fill(!1).map((_,q)=>i[w.col+q]??void 0))}else b=W(f,n,"tableParagraph",t);const v=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...fe(f)?f.props:{},colwidth:y},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=W([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=W(e.content,n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Pe(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new j(e.content.type);return o}function se(e,n,t=ce(n)){let o=e.id;o===void 0&&(o=Be.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(se(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 is(e,n){if(n===0)return;const t=e.resolve(n);for(let o=t.depth;o>0;o--){const r=t.node(o);if(Xe(r))return r.attrs.id}}function z(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!Xe(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function Xe(e){return e.type.isInGroup("bnBlock")}function as(e,n){return e.id!==n.id||e.type!==n.type||JSON.stringify(e.props)!==JSON.stringify(n.props)||JSON.stringify(e.content)!==JSON.stringify(n.content)}function ls(e){return e.getMeta("paste")?{type:"paste"}:e.getMeta("uiEvent")==="drop"?{type:"drop"}:e.getMeta("history$")?{type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")?e.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}function Yt(e){const n={},t=R(e);return e.descendants((o,r)=>{if(Xe(o)){const s=is(e,r);n[o.attrs.id]={block:T(o,t),parentId:s}}return!0}),n}function At(e,n=[]){const t=ls(e),o=k.combineTransactionSteps(e.before,[e,...n]),r=Yt(o.before),s=Yt(o.doc),i=[];return Object.keys(s).filter(a=>!(a in r)).forEach(a=>{i.push({type:"insert",block:s[a].block,source:t,prevBlock:void 0})}),Object.keys(r).filter(a=>!(a in s)).forEach(a=>{i.push({type:"delete",block:r[a].block,source:t,prevBlock:void 0})}),Object.keys(s).filter(a=>a in r).forEach(a=>{var u,h;const l=r[a],c=s[a];l.parentId!==c.parentId?i.push({type:"move",block:c.block,prevBlock:l.block,source:t,prevParent:l.parentId?(u=r[l.parentId])==null?void 0:u.block:void 0,currentParent:c.parentId?(h=s[c.parentId])==null?void 0:h.block:void 0}):as(l.block,c.block)&&i.push({type:"update",block:c.block,prevBlock:l.block,source:t})}),i}function Nn(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=R(e),i=n.map(d=>se(d,s)),a=z(r,e.doc);if(!a)throw new Error(`Block with ID ${r} not found`);let l=a.posBeforeNode;return o==="after"&&(l+=a.node.nodeSize),e.step(new he.ReplaceStep(l,l,new S.Slice(S.Fragment.from(i),0,0))),i.map(d=>T(d,s))}function mt(e,n,t){const o=R(e),r=t.map(d=>se(d,o)),s=new Set(n.map(d=>typeof d=="string"?d:d.id)),i=[],a=typeof n[0]=="string"?n[0]:n[0].id;let l=0;if(e.doc.descendants((d,u)=>{if(s.size===0)return!1;if(!d.type.isInGroup("bnBlock")||!s.has(d.attrs.id))return!0;if(i.push(T(d,o)),s.delete(d.attrs.id),t.length>0&&d.attrs.id===a){const g=e.doc.nodeSize;e.insert(u,r);const b=e.doc.nodeSize;l+=g-b}const h=e.doc.nodeSize,f=e.doc.resolve(u-l);f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?e.delete(f.before(),f.after()):e.delete(u-l,u-l+d.nodeSize);const m=e.doc.nodeSize;return l+=h-m,!1}),s.size>0){const d=[...s].join(`
`);throw Error("Blocks with the following IDs could not be found in the editor: "+d)}return{insertedBlocks:r.map(d=>T(d,o)),removedBlocks:i}}const U=(e,n)=>({tr:t,dispatch:o})=>(o&&Nt(t,e,n),!0);function Nt(e,n,t,o,r){const s=ke(e.doc.resolve(n)),i=R(e);if(o!==void 0&&r!==void 0&&o>r)throw new Error("Invalid replaceFromPos or replaceToPos");const a=i.nodes[s.blockNoteType],l=i.nodes[t.type||s.blockNoteType],c=l.isInGroup("bnBlock")?l:i.nodes.blockContainer;if(s.isBlockContainer&&l.isInGroup("blockContent")){const d=o!==void 0&&o>s.blockContent.beforePos&&o<s.blockContent.afterPos?o-s.blockContent.beforePos-1:void 0,u=r!==void 0&&r>s.blockContent.beforePos&&r<s.blockContent.afterPos?r-s.blockContent.beforePos-1:void 0;Jt(t,e,s),cs(t,e,a,l,s,d,u)}else if(!s.isBlockContainer&&l.isInGroup("bnBlock"))Jt(t,e,s);else{const d=T(s.bnBlock.node,i);e.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,se({children:d.children,...t},i));return}e.setNodeMarkup(s.bnBlock.beforePos,c,{...s.bnBlock.node.attrs,...t.props})}function cs(e,n,t,o,r,s,i){const a=R(n);let l="keep";if(e.content)if(typeof e.content=="string")l=W([e.content],a,o.name);else if(Array.isArray(e.content))l=W(e.content,a,o.name);else if(e.content.type==="tableContent")l=Pe(e.content,a);else throw new j(e.content.type);else t.spec.content===""||o.spec.content!==t.spec.content&&(l=[]);if(l==="keep")n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});else if(s!==void 0||i!==void 0){n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});const c=r.blockContent.beforePos+1+(s??0),d=r.blockContent.beforePos+1+(i??r.blockContent.node.content.size),u=n.doc.resolve(r.blockContent.beforePos).depth,h=n.doc.resolve(c).depth,f=n.doc.resolve(d).depth;n.replace(c,d,new S.Slice(S.Fragment.from(l),h-u-1,f-u-1))}else n.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},l))}function Jt(e,n,t){const o=R(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>se(s,o));if(t.childContainer)n.step(new he.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new S.Slice(S.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function Dn(e,n,t,o,r){const s=typeof n=="string"?n:n.id,i=z(s,e.doc);if(!i)throw new Error(`Block with ID ${s} not found`);Nt(e,i.posBeforeNode,t,o,r);const a=e.doc.resolve(i.posBeforeNode+1).node(),l=R(e);return T(a,l)}function Hn(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function On(e,n,t,o){let r;if(n)if(typeof n=="string")r=W([n],e.pmSchema);else if(Array.isArray(n))r=W(n,e.pmSchema);else if(n.type==="tableContent")r=Pe(n,e.pmSchema);else throw new j(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(S.Fragment.from(r),o);return s.nodeType===1&&Hn(s),s}function ds(e,n,t,o,r,s,i){var g,b,w,y,v,B,_,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[P,x]of Object.entries(n.schema.blockSchema[t.type].propSchema))x.default!==void 0&&(c[P]=x.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 P=[...u,...Array.from(h.dom.attributes)].filter(x=>x.name.startsWith("data")&&x.name!=="data-content-type"&&x.name!=="data-file-block"&&x.name!=="data-node-view-wrapper"&&x.name!=="data-node-type"&&x.name!=="data-id"&&x.name!=="data-index"&&x.name!=="data-editable");for(const x of P)h.dom.firstChild.setAttribute(x.name,x.value);Hn(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const P=On(n,t.content,o,i);h.contentDOM.appendChild(P)}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 x=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&x.setAttribute("start",c.start+""),e.append(x)}const P=a.createElement("li");P.append(f),e.lastChild.appendChild(P)}else e.append(f);if(t.children&&t.children.length>0){const P=a.createDocumentFragment();if(Rn(P,n,t.children,o,r,s,i),((y=e.lastChild)==null?void 0:y.nodeName)==="UL"||((v=e.lastChild)==null?void 0:v.nodeName)==="OL")for(;((B=P.firstChild)==null?void 0:B.nodeName)==="UL"||((_=P.firstChild)==null?void 0:_.nodeName)==="OL";)e.lastChild.lastChild.appendChild(P.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(P):(q=h.contentDOM)==null||q.append(P)}}const Rn=(e,n,t,o,r,s,i)=>{for(const a of t)ds(e,n,a,o,r,s,i)},us=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return Rn(a,e,n,t,o,r,s),a},Me=(e,n)=>{const t=S.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=us(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=On(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function ps(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=W([n],e.pmSchema,o);else if(Array.isArray(n))s=W(n,e.pmSchema,o);else if(n.type==="tableContent")s=Pe(n,e.pmSchema);else throw new j(n.type);else throw new Error("blockContent is required");return t.serializeFragment(S.Fragment.from(s),r)}function hs(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=ps(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=_n(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(Vn(e,n.children,t,r))),d.dom}function _n(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=hs(e,a,t,i,o);s.appendChild(l)}return s}const Vn=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=_n(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},Un=(e,n)=>{const t=S.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>Vn(n,o,t,r).outerHTML}},Ie=(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}},Fn=(e,n,t,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",o?s.appendChild(o):s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(s);const i=document.createElement("p");i.className="bn-add-file-button-text",i.innerHTML=t||n.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{n.transact(c=>c.setMeta(n.filePanel.plugins[0],{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)}}},$n='<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>',zn=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=$n,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},Ze=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=Fn(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=zn(e);s.appendChild(a.dom),i.destroy=()=>{var l;(l=a.destroy)==null||l.call(a)}}else s.appendChild(t.dom);if(e.props.caption){const a=document.createElement("p");a.className="bn-file-caption",a.textContent=e.props.caption,s.appendChild(a)}return i},Qe=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Le=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Xt=e=>({url:e.src||void 0}),Wn='<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>',qn={backgroundColor:I.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},Kn={type:"audio",propSchema:qn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},jn=(e,n)=>{const t=document.createElement("div");t.innerHTML=Wn;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,Ze(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Gn=e=>{if(e.tagName==="AUDIO")return e.closest("figure")?void 0:Xt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...Xt(t),caption:o}}},Yn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("audio"),n.src=e.props.url):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Qe(n,e.props.caption):Le(n,e.props.caption):{dom:n}},Jn=be(Kn,{render:jn,parse:Gn,toExternalHTML:Yn}),gt=Symbol.for("blocknote.shikiParser"),Re=Symbol.for("blocknote.shikiHighlighterPromise"),Xn={language:{default:"text"}},fs=G({name:"codeBlock",content:"inline*",group:"blockContent",marks:"insertion deletion modification",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?st(e.editor.settings.codeBlock,o)??o:null},renderHTML:n=>n.language?{class:`language-${n.language}`,"data-language":n.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",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 `codeBlock.createHighlighter` function"),r=!0),[];if(!t)return n[Re]=n[Re]||e.editor.settings.codeBlock.createHighlighter(),n[Re].then(c=>{t=c});const l=st(e.editor.settings.codeBlock,a.language);return!l||l==="text"||l==="none"||l==="plaintext"||l==="txt"?[]:t.getLoadedLanguages().includes(l)?(o||(o=n[gt]||Tr.createParser(t),n[gt]=o),o(a)):t.loadLanguage(l)};return[Br.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:st(e.editor.settings.codeBlock,s)??s};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;n.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(C.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(`
`);return!t||!o?(e.commands.insertContent(`
`),!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}}}}),Zn=Z(fs,Xn);function st(e,n){var t;return(t=Object.entries(e.supportedLanguages).find(([o,{aliases:r}])=>(r==null?void 0:r.includes(n))||o===n))==null?void 0:t[0]}const ms=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]}}),gs=ne(ms,"string"),bs=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]}}),ks=ne(bs,"string"),bt=e=>({url:e.src||void 0}),Qn={backgroundColor:I.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},eo={type:"file",propSchema:Qn,content:"none",isFileBlock:!0},to=(e,n)=>Ze(e,n),no=e=>{if(e.tagName==="EMBED")return e.closest("figure")?void 0:bt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...bt(t),caption:o}}},oo=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?Le(n,e.props.caption):{dom:n}},ro=be(eo,{render:to,parse:no,toExternalHTML:oo}),so={set:(e,n)=>window.localStorage.setItem(`toggle-${e.id}`,n?"true":"false"),get:e=>window.localStorage.getItem(`toggle-${e.id}`)==="true"},Dt=(e,n,t,o=so)=>{if("isToggleable"in e.props&&!e.props.isToggleable)return{dom:t};const r=document.createElement("div"),s=document.createElement("div");s.className="bn-toggle-wrapper";const i=document.createElement("button");i.className="bn-toggle-button",i.type="button",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';const a=m=>m.preventDefault();i.addEventListener("mousedown",a);const l=()=>{var m;s.getAttribute("data-show-children")==="true"?(s.setAttribute("data-show-children","false"),o.set(n.getBlock(e),!1),r.contains(c)&&r.removeChild(c)):(s.setAttribute("data-show-children","true"),o.set(n.getBlock(e),!0),((m=n.getBlock(e))==null?void 0:m.children.length)===0&&!r.contains(c)&&r.appendChild(c))};i.addEventListener("click",l),s.appendChild(i),s.appendChild(t);const c=document.createElement("button");c.className="bn-toggle-add-block-button",c.type="button",c.textContent="Empty toggle. Click to add a block.";const d=m=>m.preventDefault();c.addEventListener("mousedown",d);const u=()=>{n.transact(()=>{const m=n.updateBlock(e,{children:[{}]});n.setTextCursorPosition(m.children[0].id,"end"),n.focus()})};c.addEventListener("click",u),r.appe