@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
10 lines (9 loc) • 191 kB
JavaScript
"use strict";var hr=Object.create;var nt=Object.defineProperty;var fr=Object.getOwnPropertyDescriptor;var mr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,br=Object.prototype.hasOwnProperty;var kr=(e,n,t)=>n in e?nt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var wr=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of mr(n))!br.call(e,r)&&r!==t&&nt(e,r,{get:()=>n[r],enumerable:!(o=fr(n,r))||o.enumerable});return e};var W=(e,n,t)=>(t=e!=null?hr(gr(e)):{},wr(n||!e||!e.__esModule?nt(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>kr(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("prosemirror-model"),pe=require("prosemirror-transform"),k=require("@tiptap/core"),y=require("prosemirror-state"),cn=require("uuid"),yr=require("prosemirror-highlight"),Cr=require("prosemirror-highlight/shiki"),vr=require("@tiptap/extension-bold"),Sr=require("@tiptap/extension-code"),Er=require("@tiptap/extension-italic"),Br=require("@tiptap/extension-strike"),Tr=require("@tiptap/extension-underline"),xr=require("@tiptap/extension-table-cell"),Pr=require("@tiptap/extension-table-header"),A=require("prosemirror-tables"),Mr=require("@tiptap/extension-gapcursor"),Ir=require("@tiptap/extension-history"),Lr=require("@tiptap/extension-link"),Ar=require("@tiptap/extension-text"),N=require("y-prosemirror"),M=require("prosemirror-view"),Nr=require("yjs"),Wt=require("prosemirror-history"),Hr=require("prosemirror-dropcursor"),Dr=require("./en-BXVKCwYt.cjs"),Ee=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function Or(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 Rr=Ee(vr),_r=Ee(Sr),Vr=Ee(Er),Ur=Ee(Br),Fr=Ee(Tr),ce=Or(Nr);function $r(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 zr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return $r(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 cn.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=zr(b);g.forEach(({node:C,pos:S})=>{let P;const R=(P=a.doc.nodeAt(S))===null||P===void 0?void 0:P.attrs[c];if(R===null){const v=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(v)===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(v.toJSON())){a.setNodeMarkup(S,void 0,{...C.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(S,void 0,{...C.attrs,[c]:d()});return}const{deleted:z}=h.invert().mapResult(S);z&&w.includes(R)&&a.setNodeMarkup(S,void 0,{...C.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let r;return e!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?n=!0:n=!1,e=null,!1},paste:()=>(n=!0,!1)},transformPasted:t=>{if(!n)return t;const{types:o,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(s(l.content)));return}const c=l.type.create({...l.attrs,[r]:null},s(l.content),l.marks);a.push(c)}),E.Fragment.from(a)};return n=!1,new E.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function it(e){return e.type==="link"}function Ct(e){return typeof e!="string"&&e.type==="link"}function ne(e){return typeof e!="string"&&e.type==="text"}function _e(e){var n,t,o,r,s;return qe(e)?{...e}:he(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 he(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function qe(e){return he(e)&&e.props!==void 0&&e.content!==void 0}function fe(e){return qe(e)?e.props.colspan??1:1}function Ve(e){return qe(e)?e.props.rowspan??1:1}class K extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Wr(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 dn=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function J(e,n="Ctrl"){return dn()?e.replace("Mod","⌘"):e.replace("Mod",n)}function X(...e){return e.filter(n=>n).join(" ")}const Kr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function j(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 at=(e,n)=>{let t=re(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 qr(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"]}},vt=["backgroundColor","textColor"];function ve(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function jr(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function me(e){const n={};return Object.entries(e).filter(([t,o])=>!vt.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 un(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=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;!vt.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=X("bn-inline-content",e.contentDOM.className)),{...e,dom:i}}function G(e){return k.Node.create(e)}function St(e,n){return{config:e,implementation:n}}function Q(e,n,t){return St({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:at,toExternalHTML:at})}function Et(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function pn(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function hn(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 ge(e,n){const t=G({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return me(e.propSchema)},parseHTML(){return hn(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=un(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,i);return e.isSelectable===!1&&pn(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 St(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 Y(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 Z(e){return je(e.node,e.posBeforeNode)}function be(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 B(e){const n=Y(e.doc,e.selection.anchor);return Z(n)}function Te(e){const n=Y(e.doc,e.selection.anchor);return Z(n)}function H(e){return"doc"in e?e.doc.type.schema:e.type.schema}function fn(e){return e.cached.blockNoteEditor}function ke(e){return fn(e).schema}function Ge(e){return ke(e).blockSchema}function Ye(e){return ke(e).inlineContentSchema}function le(e){return ke(e).styleSchema}function Je(e){return fn(e).blockCache}function Bt(e,n,t){var s,i;const o={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},r=[];e.content.forEach((a,l,c)=>{const d={cells:[]};c===0&&a.content.forEach(u=>{let h=u.attrs.colwidth;h==null&&(h=new Array(u.attrs.colspan??1).fill(void 0)),o.columnWidths.push(...h)}),d.cells=a.content.content.map((u,h)=>(r[c]||(r[c]=[]),r[c][h]=u.type.name==="tableHeader",{type:"tableCell",content:u.content.content.map(m=>xe(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],w=g[0];return w&&ne(b)&&ne(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(ne(r))r.text+=`
`;else if(it(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(Ue(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 K(c.propSchema)}r?ne(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}):it(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 Ue(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=le(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 C=c.propSchema;b in C&&!(C[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=Bt(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new K(u.content);const m={id:l,type:u.type,props:d,content:f,children:h};return s==null||s.set(e,m),m}function mn(e,n,t=Ge(n),o=Ye(n),r=le(n),s=Je(n)){const i=[];return e.firstChild.descendants(a=>(i.push(T(a,n,t,o,r,s)),!1)),i}function gn(e,n,t=Ge(n),o=Ye(n),r=le(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 R=i(f.firstChild,Math.max(0,l-1),w?Math.max(0,c-1):0);u=R.blockCutAtStart,w&&(h=R.blockCutAtEnd),d.push(...R.blocks);return}const C=T(f,n,t,o,r,s),S=f.childCount>1?f.child(1):void 0;let P=[];if(S){const R=i(S,0,w?Math.max(0,c-1):0);P=R.blocks,w&&(h=R.blockCutAtEnd)}w&&!S&&c>1&&(h=C.id),b&&l>1&&(u=C.id),d.push({...C,children:P})}),{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 lt(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 bn(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 kn(e,n){return{config:e,implementation:n}}function wn(e,n){return kn({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function Tt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function yn(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 Gr(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 me(e.propSchema)},addKeyboardShortcuts(){return bn(e)},parseHTML(){return yn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render(Ue(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return lt(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render(Ue(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=$([a],s.pmSchema);s.transact(c=>c.replaceWith(r(),r()+o.nodeSize,l))},s);return lt(i,e.type,o.attrs,e.propSchema)}}});return wn(t,e.propSchema)}function Cn(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 vn(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 xt(e,n){return{config:e,implementation:n}}function te(e,n){return xt({type:e.name,propSchema:n},{mark:e})}function Pt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Sn(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 Yr(e,n){const t=k.Mark.create({name:e.type,addAttributes(){return Cn(e.propSchema)},parseHTML(){return Sn(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 K(e.propSchema);return vn(r,e.type,o.attrs.stringValue,e.propSchema)}});return xt(e,{mark:t})}function oe(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=_e(e.content.rows[s].cells[i]),l=Ve(a),c=fe(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 ae(e,n,t=oe(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+=fe(s)}),t=Math.max(t,r)}),{height:n,width:t}}function En(e,n,t=oe(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 ct(e,n){var s;const t=oe(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)=>En({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 dt(e,n){var s;const t=oe(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)=>En({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 Jr(e,n,t,o=oe(e)){const{col:r}=ae({row:0,col:n},e,o),{col:s}=ae({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),Se(o)}function Xr(e,n,t,o=oe(e)){const{row:r}=ae({row:n,col:0},e,o),{row:s}=ae({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),Se(o)}function ut(e){return e?he(e)?ut(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:ne(n)?n.text.length===0:Ct(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function Zr(e,n,t=oe(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>ut(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=>ut(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 Qr(e,n,t,o=oe(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:_e("")});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:_e("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return Se(o)}function Bn(e,n,t){const o=ct(e,t);if(!o.some(l=>Ve(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=Ve(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function Tn(e,n,t){const o=dt(e,t);if(!o.some(l=>fe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=fe(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function es(e,n,t){const o=ae(e,t),r=ae(n,t);return o.col===r.col}function Kt(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 K(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 ts(e,n,t){const o=n.marks.link.create({href:e.href});return pt(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 pt(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Kt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Kt(s,n,t,o));return r}function $(e,n,t,o=le(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...pt(s,n,o,t)):Ct(s)?r.push(...ts(s,n,o)):ne(s)?r.push(...pt([s],n,o,t)):r.push(xn(s,n,o));return r}function Pe(e,n,t=le(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=ae({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(he(f)){f.content&&(b=$(f.content,n,"tableParagraph",t));const P=fe(f);P>1&&(C=new Array(P).fill(!1).map((R,z)=>i[w.col+z]??void 0))}else b=$(f,n,"tableParagraph",t);const S=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...he(f)?f.props:{},colwidth:C},n.nodes.tableParagraph.createChecked(g,b));c.push(S)}const u=n.nodes.tableRow.createChecked({},c);o.push(u)}return o}function xn(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=$([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=$(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 K(e.content.type);return o}function re(e,n,t=le(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(re(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=xn(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 F(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!Fe(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function Fe(e){return e.type.isInGroup("bnBlock")}function ns(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 Pn(e,n=[]){let t={type:"local"};e.getMeta("paste")?t={type:"paste"}:e.getMeta("uiEvent")==="drop"?t={type:"drop"}:e.getMeta("history$")?t={type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")&&(e.getMeta("y-sync$").isUndoRedoOperation?t={type:"undo-redo"}:t={type:"yjs-remote"});const o=H(e),r=k.combineTransactionSteps(e.before,[e,...n]),s=k.getChangedRanges(r),i=s.flatMap(u=>k.findChildrenInRange(r.before,u.oldRange,Fe)).map(({node:u})=>T(u,o)),a=s.flatMap(u=>k.findChildrenInRange(r.doc,u.newRange,Fe)).map(({node:u})=>T(u,o)),l=new Map(a.map(u=>[u.id,u])),c=new Map(i.map(u=>[u.id,u])),d=[];for(const[u,h]of l)c.has(u)||d.push({type:"insert",block:h,source:t,prevBlock:void 0});for(const[u,h]of c)l.has(u)||d.push({type:"delete",block:h,source:t,prevBlock:void 0});for(const[u,h]of l)if(c.has(u)){const f=c.get(u);ns(f,h)&&d.push({type:"update",block:h,prevBlock:f,source:t})}return d}function Mn(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=H(e),i=n.map(d=>re(d,s)),a=F(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 pe.ReplaceStep(l,l,new E.Slice(E.Fragment.from(i),0,0))),i.map(d=>T(d,s))}function ht(e,n,t){const o=H(e),r=t.map(d=>re(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 D=(e,n)=>({tr:t,dispatch:o})=>(o&&It(t,e,n),!0);function It(e,n,t,o,r){const s=be(e.doc.resolve(n)),i=H(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;qt(t,e,s),os(t,e,a,l,s,d,u)}else if(!s.isBlockContainer&&l.isInGroup("bnBlock"))qt(t,e,s);else{const d=T(s.bnBlock.node,i);e.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,re({children:d.children,...t},i));return}e.setNodeMarkup(s.bnBlock.beforePos,c,{...s.bnBlock.node.attrs,...t.props})}function os(e,n,t,o,r,s,i){const a=H(n);let l="keep";if(e.content)if(typeof e.content=="string")l=$([e.content],a,o.name);else if(Array.isArray(e.content))l=$(e.content,a,o.name);else if(e.content.type==="tableContent")l=Pe(e.content,a);else throw new K(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 E.Slice(E.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 qt(e,n,t){const o=H(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>re(s,o));if(t.childContainer)n.step(new pe.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new E.Slice(E.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function In(e,n,t,o,r){const s=typeof n=="string"?n:n.id,i=F(s,e.doc);if(!i)throw new Error(`Block with ID ${s} not found`);It(e,i.posBeforeNode,t,o,r);const a=e.doc.resolve(i.posBeforeNode+1).node(),l=H(e);return T(a,l)}function Ln(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function An(e,n,t,o){let r;if(n)if(typeof n=="string")r=$([n],e.pmSchema);else if(Array.isArray(n))r=$(n,e.pmSchema);else if(n.type==="tableContent")r=Pe(n,e.pmSchema);else throw new K(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(E.Fragment.from(r),o);return s.nodeType===1&&Ln(s),s}function rs(e,n,t,o,r,s,i){var g,b,w,C,S,P,R,z;const a=(i==null?void 0:i.document)??document,l=n.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[x,v]of Object.entries(n.schema.blockSchema[t.type].propSchema))v.default!==void 0&&(c[x]=v.default)}const d=(b=(g=l.spec)==null?void 0:g.toDOM)==null?void 0:b.call(g,l.create({id:t.id,...c})),u=Array.from(d.dom.attributes),h=n.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},n),f=a.createDocumentFragment();if(h.dom.classList.contains("bn-block-content")){const x=[...u,...Array.from(h.dom.attributes)].filter(v=>v.name.startsWith("data")&&v.name!=="data-content-type"&&v.name!=="data-file-block"&&v.name!=="data-node-view-wrapper"&&v.name!=="data-node-type"&&v.name!=="data-id"&&v.name!=="data-index"&&v.name!=="data-editable");for(const v of x)h.dom.firstChild.setAttribute(v.name,v.value);Ln(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const x=An(n,t.content,o,i);h.contentDOM.appendChild(x)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((w=e.lastChild)==null?void 0:w.nodeName)!==m){const v=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&v.setAttribute("start",c.start+""),e.append(v)}const x=a.createElement("li");x.append(f),e.lastChild.appendChild(x)}else e.append(f);if(t.children&&t.children.length>0){const x=a.createDocumentFragment();if(Nn(x,n,t.children,o,r,s,i),((C=e.lastChild)==null?void 0:C.nodeName)==="UL"||((S=e.lastChild)==null?void 0:S.nodeName)==="OL")for(;((P=x.firstChild)==null?void 0:P.nodeName)==="UL"||((R=x.firstChild)==null?void 0:R.nodeName)==="OL";)e.lastChild.lastChild.appendChild(x.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(x):(z=h.contentDOM)==null||z.append(x)}}const Nn=(e,n,t,o,r,s,i)=>{for(const a of t)rs(e,n,a,o,r,s,i)},ss=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return Nn(a,e,n,t,o,r,s),a},Me=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=ss(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=An(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function is(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=$([n],e.pmSchema,o);else if(Array.isArray(n))s=$(n,e.pmSchema,o);else if(n.type==="tableContent")s=Pe(n,e.pmSchema);else throw new K(n.type);else throw new Error("blockContent is required");return t.serializeFragment(E.Fragment.from(s),r)}function as(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=is(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=Hn(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(Dn(e,n.children,t,r))),d.dom}function Hn(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=as(e,a,t,i,o);s.appendChild(l)}return s}const Dn=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Hn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},On=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>Dn(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}},Rn=(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>',Vn=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}},Xe=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=Rn(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=Vn(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},Ze=(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}},jt=e=>({url:e.src||void 0}),Un='<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>',Fn={backgroundColor:I.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},$n={type:"audio",propSchema:Fn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},zn=(e,n)=>{const t=document.createElement("div");t.innerHTML=Un;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,Xe(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Wn=e=>{if(e.tagName==="AUDIO")return e.closest("figure")?void 0:jt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...jt(t),caption:o}}},Kn=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?Ze(n,e.props.caption):Le(n,e.props.caption):{dom:n}},qn=ge($n,{render:zn,parse:Wn,toExternalHTML:Kn}),ft=Symbol.for("blocknote.shikiParser"),Oe=Symbol.for("blocknote.shikiHighlighterPromise"),jn={language:{default:"text"}},ls=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?ot(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}=j(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}=j(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[Oe]=n[Oe]||e.editor.settings.codeBlock.createHighlighter(),n[Oe].then(c=>{t=c});const l=ot(e.editor.settings.codeBlock,a.language);return!l||l==="text"||l==="none"||l==="plaintext"||l==="txt"?[]:t.getLoadedLanguages().includes(l)?(o||(o=n[ft]||Cr.createParser(t),n[ft]=o),o(a)):t.loadLanguage(l)};return[yr.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:ot(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(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(`
`);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}}}}),Gn=Q(ls,jn);function ot(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 cs=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]}}),ds=te(cs,"string"),us=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]}}),ps=te(us,"string"),mt=e=>({url:e.src||void 0}),Yn={backgroundColor:I.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},Jn={type:"file",propSchema:Yn,content:"none",isFileBlock:!0},Xn=(e,n)=>Xe(e,n),Zn=e=>{if(e.tagName==="EMBED")return e.closest("figure")?void 0:mt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...mt(t),caption:o}}},Qn=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}},eo=ge(Jn,{render:Xn,parse:Zn,toExternalHTML:Qn}),to={...I,level:{default:1,values:[1,2,3]}},hs=G({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return me(to)},addInputRules(){return[...[1,2,3].map(e=>new k.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:n,chain:t,range:o})=>{const r=B(n);!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||t().command(D(r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(D(e.bnBlock.beforePos,{type:"heading",props:{level:1}}))},"Mod-Alt-2":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(D(e.bnBlock.beforePos,{type:"heading",props:{level:2}}))},"Mod-Alt-3":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(D(e.bnBlock.beforePos,{type:"heading",props:{level:3}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:e,HTMLAttributes:n}){var t,o;return j(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)||{})}}),fs=Q(hs,to),Lt=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=Xe(e,n,t,r,s),l=i;e.props.url&&e.props.showPreview&&(e.props.previewWidth?l.style.width=`${e.props.previewWidth}px`:l.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",