@blocknote/core 0.12.0 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +958 -940
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/api/getCurrentBlockContentType.ts +14 -0
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +50 -21
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +1 -1
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +18 -5
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +7 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +18 -5
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +14 -5
- package/src/editor/BlockNoteEditor.ts +14 -14
- package/src/editor/editor.css +0 -1
- package/src/extensions/{ImageToolbar → ImagePanel}/ImageToolbarPlugin.ts +14 -14
- package/src/extensions/{HyperlinkToolbar/HyperlinkToolbarPlugin.ts → LinkToolbar/LinkToolbarPlugin.ts} +87 -91
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +1 -1
- package/src/index.ts +2 -2
- package/types/src/api/getCurrentBlockContentType.d.ts +2 -0
- package/types/src/editor/BlockNoteEditor.d.ts +5 -5
- package/types/src/extensions/{ImageToolbar → ImagePanel}/ImageToolbarPlugin.d.ts +6 -6
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +40 -0
- package/types/src/index.d.ts +2 -2
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +0 -38
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(d,
|
|
2
|
-
`?
|
|
3
|
-
`;else if(
|
|
1
|
+
(function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("prosemirror-model"),require("rehype-parse"),require("rehype-stringify"),require("unified"),require("@tiptap/core"),require("prosemirror-state"),require("uuid"),require("hast-util-from-dom"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-underline"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("prosemirror-tables"),require("rehype-remark"),require("remark-gfm"),require("remark-stringify"),require("remark-parse"),require("remark-rehype"),require("prosemirror-view"),require("@tiptap/extension-collaboration"),require("@tiptap/extension-collaboration-cursor"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-link"),require("@tiptap/extension-text")):typeof define=="function"&&define.amd?define(["exports","prosemirror-model","rehype-parse","rehype-stringify","unified","@tiptap/core","prosemirror-state","uuid","hast-util-from-dom","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-underline","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","prosemirror-tables","rehype-remark","remark-gfm","remark-stringify","remark-parse","remark-rehype","prosemirror-view","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-link","@tiptap/extension-text"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.blocknote={},d.prosemirrorModel,d.rehypeParse,d.rehypeStringify,d.unified,d.core,d.prosemirrorState,d.uuid,d.hastUtilFromDom,d.Bold,d.Code,d.Italic,d.Strike,d.Underline,d.extensionTableCell,d.extensionTableHeader,d.extensionTableRow,d.prosemirrorTables,d.rehypeRemark,d.remarkGfm,d.remarkStringify,d.remarkParse,d.remarkRehype,d.prosemirrorView,d.Collaboration,d.CollaborationCursor,d.extensionDropcursor,d.extensionGapcursor,d.extensionHardBreak,d.extensionHistory,d.extensionLink,d.extensionText))})(this,function(d,y,F,De,ct,b,k,_e,Dt,Oe,Ue,Re,ze,Fe,Ve,qe,$e,_t,Ge,Ke,je,We,Ot,x,Je,Xe,Ye,Qe,Ze,tn,en,nn){"use strict";var Xo=Object.defineProperty;var Yo=(d,y,F)=>y in d?Xo(d,y,{enumerable:!0,configurable:!0,writable:!0,value:F}):d[y]=F;var u=(d,y,F)=>(Yo(d,typeof y!="symbol"?y+"":y,F),F);const T=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},Ut=T(F),Rt=T(De),on=T(Oe),rn=T(Ue),sn=T(Re),an=T(ze),ln=T(Fe),cn=T(Ge),zt=T(Ke),dn=T(je),un=T(We),hn=T(Ot),pn=T(Je),mn=T(Xe);function fn(n,t=JSON.stringify){const e={};return n.filter(o=>{const i=t(o);return Object.prototype.hasOwnProperty.call(e,i)?!1:e[i]=!0})}function gn(n){const t=n.filter((o,i)=>n.indexOf(o)!==i);return fn(t)}const G=b.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const n=window.__TEST_OPTIONS;return n.mockID===void 0?n.mockID=0:n.mockID++,n.mockID.toString()}return _e.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:n=>n.getAttribute(`data-${this.options.attributeName}`),renderHTML:n=>({[`data-${this.options.attributeName}`]:n[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let n=null,t=!1;return[new k.Plugin({key:new k.PluginKey("uniqueID"),appendTransaction:(e,o,i)=>{const r=e.some(g=>g.docChanged)&&!o.doc.eq(i.doc),s=this.options.filterTransaction&&e.some(g=>{let E,I;return!(!((I=(E=this.options).filterTransaction)===null||I===void 0)&&I.call(E,g))});if(!r||s)return;const{tr:a}=i,{types:l,attributeName:c,generateID:h}=this.options,p=b.combineTransactionSteps(o.doc,e),{mapping:f}=p;if(b.getChangedRanges(p).forEach(({newRange:g})=>{const E=b.findChildrenInRange(i.doc,g,B=>l.includes(B.type.name)),I=E.map(({node:B})=>B.attrs[c]).filter(B=>B!==null),D=gn(I);E.forEach(({node:B,pos:$})=>{let Y;const nt=(Y=a.doc.nodeAt($))===null||Y===void 0?void 0:Y.attrs[c];if(nt===null){const At=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(At)===null){const lt=JSON.parse(JSON.stringify(i.doc.toJSON()));if(lt.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(lt.content)===JSON.stringify(At.toJSON())){a.setNodeMarkup($,void 0,{...B.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup($,void 0,{...B.attrs,[c]:h()});return}const{deleted:v}=f.invert().mapResult($);v&&D.includes(nt)&&a.setNodeMarkup($,void 0,{...B.attrs,[c]:h()})})}),!!a.steps.length)return a},view(e){const o=i=>{let r;n=!((r=e.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?e.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(e,o)=>{let i;return(n!==e.dom.parentElement||((i=o.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(n=null,t=!0),!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:o,attributeName:i}=this.options,r=s=>{const a=[];return s.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(r(l.content)));return}const c=l.type.create({...l.attrs,[i]:null},r(l.content),l.marks);a.push(c)}),y.Fragment.from(a)};return t=!1,new y.Slice(r(e.content),e.openStart,e.openEnd)}}})]}});function Ft(n){const t=n.attrs.id,e=n.firstChild,o=e.type,i=n.childCount===2?n.lastChild.childCount:0;return{id:t,node:n,contentNode:e,contentType:o,numChildBlocks:i}}function w(n,t){const o=n.nodeSize-2;if(t<=1)for(t=1+1;n.resolve(t).parent.type.name!=="blockContainer"&&t<o;)t++;else if(t>=o)for(t=o-1;n.resolve(t).parent.type.name!=="blockContainer"&&t>1;)t--;n.resolve(t).parent.type.name==="blockGroup"&&t++;const i=n.resolve(t),r=i.depth;let s=i.node(r),a=r;for(;;){if(a<0)throw new Error("Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited.");if(s.type.name==="blockContainer")break;a-=1,s=i.node(a)}const{id:l,contentNode:c,contentType:h,numChildBlocks:p}=Ft(s),f=i.start(a),m=i.end(a);return{id:l,node:s,contentNode:c,contentType:h,numChildBlocks:p,startPos:f,endPos:m,depth:a}}function dt(n){return n.type==="link"}function ut(n){return typeof n!="string"&&n.type==="link"}function K(n){return typeof n!="string"&&n.type==="text"}class L extends Error{constructor(t){super(`Unreachable case: ${t}`)}}function Vt(n,t,e){const o=[];for(const[i,r]of Object.entries(n.styles)){const s=e[i];if(!s)throw new Error(`style ${i} not found in styleSchema`);if(s.propSchema==="boolean")o.push(t.mark(i));else if(s.propSchema==="string")o.push(t.mark(i,{stringValue:r}));else throw new L(s.propSchema)}return n.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
|
|
2
|
+
`?t.nodes.hardBreak.create():t.text(i,o))}function bn(n,t,e){const o=t.marks.link.create({href:n.href});return ht(n.content,t,e).map(i=>{if(i.type.name==="text")return i.mark([...i.marks,o]);if(i.type.name==="hardBreak")return i;throw new Error("unexpected node type")})}function ht(n,t,e){const o=[];if(typeof n=="string")return o.push(...Vt({type:"text",text:n,styles:{}},t,e)),o;for(const i of n)o.push(...Vt(i,t,e));return o}function Q(n,t,e){const o=[];for(const i of n)typeof i=="string"?o.push(...ht(i,t,e)):ut(i)?o.push(...bn(i,t,e)):K(i)?o.push(...ht([i],t,e)):o.push(qt(i,t,e));return o}function pt(n,t,e){const o=[];for(const i of n.rows){const r=[];for(const a of i.cells){let l;if(!a)l=t.nodes.tableParagraph.create({});else if(typeof a=="string")l=t.nodes.tableParagraph.create({},t.text(a));else{const h=Q(a,t,e);l=t.nodes.tableParagraph.create({},h)}const c=t.nodes.tableCell.create({},l);r.push(c)}const s=t.nodes.tableRow.create({},r);o.push(s)}return o}function qt(n,t,e){let o,i=n.type;if(i===void 0&&(i="paragraph"),!t.nodes[i])throw new Error(`node type ${i} not found in schema`);if(!n.content)o=t.nodes[i].create(n.props);else if(typeof n.content=="string")o=t.nodes[i].create(n.props,t.text(n.content));else if(Array.isArray(n.content)){const r=Q(n.content,t,e);o=t.nodes[i].create(n.props,r)}else if(n.content.type==="tableContent"){const r=pt(n.content,t,e);o=t.nodes[i].create(n.props,r)}else throw new L(n.content.type);return o}function N(n,t,e){let o=n.id;o===void 0&&(o=G.options.generateID());const i=qt(n,t,e),r=[];if(n.children)for(const a of n.children)r.push(N(a,t,e));const s=t.nodes.blockGroup.create({},r);return t.nodes.blockContainer.create({id:o,...n.props},r.length>0?[i,s]:i)}function kn(n,t,e){const o={type:"tableContent",rows:[]};return n.content.forEach(i=>{const r={cells:[]};i.content.forEach(s=>{r.cells.push(ot(s.firstChild,t,e))}),o.rows.push(r)}),o}function ot(n,t,e){const o=[];let i;return n.content.forEach(r=>{if(r.type.name==="hardBreak"){if(i)if(K(i))i.text+=`
|
|
3
|
+
`;else if(dt(i))i.content[i.content.length-1].text+=`
|
|
4
4
|
`;else throw new Error("unexpected");else i={type:"text",text:`
|
|
5
|
-
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&e[r.type.name]){i&&(o.push(i),i=void 0),o.push(pe(r,e,t));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c)throw new Error(`style ${l.type.name} not found in styleSchema`);if(c.propSchema==="boolean")s[c.type]=!0;else if(c.propSchema==="string")s[c.type]=l.attrs.stringValue;else throw new P(c.propSchema)}i?G(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):ce(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function pe(n,e,t){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=e[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const c=i.propSchema;a in c&&(o[a]=l)}let r;return i.content==="styled"?r=ne(n,e,t):r=void 0,{type:n.type.name,props:o,content:r}}function S(n,e,t,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=ze(n);let a=s.id;a===null&&(a=$.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const E=e[s.contentType.name];if(!E)throw Error("Block is of an unrecognized type: "+s.contentType.name);const I=E.propSchema;m in I&&(l[m]=g)}const c=e[s.contentType.name],h=[];for(let m=0;m<s.numChildBlocks;m++)h.push(S(n.lastChild.child(m),e,t,o,i));let p;if(c.content==="inline")p=ne(s.contentNode,t,o);else if(c.content==="table")p=bn(s.contentNode,t,o);else if(c.content==="none")p=void 0;else throw new P(c.content);const f={id:a,type:c.type,props:l,content:p,children:h};return i==null||i.set(n,f),f}function yn(n){return n.document||window.document}const qe=(n,e,t,o,i)=>{if(!t.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=k.DOMSerializer.renderSpec(yn(e),t.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const c=o.blockImplementations[a.type.name].implementation,p=(i?c.toExternalHTML:c.toInternalHTML)(S(n,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache),o);if(p.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");p.contentDOM.appendChild(t.serializeFragment(a.content,e))}s.appendChild(p.dom)}l!==void 0&&t.serializeFragment(k.Fragment.from(l),e,s)}else t.serializeFragment(n.content,e,s)}return r},$e=(n,e)=>{const t=e.serializeFragment(n),o=document.createElement("div");return o.appendChild(t),o.innerHTML};function kn(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const c=o.children[a].children[0],h=c.children[0],p=c.children.length===2?c.children[1]:null,f=e.has(h.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(h.properties.dataContentType)?"ol":"ul":null;if(p!==null&&t(p),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Ae.fromDom(document.createElement(m)));const g=Ae.fromDom(document.createElement("li"));g.children.push(h.children[0]),p!==null&&g.children.push(...p.children),r.children.push(g)}else if(p!==null){o.children.splice(a+1,0,...p.children),o.children[a]=h.children[0];const g=p.children.length;a+=g,i+=g}else o.children[a]=h.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return t}const Q=(n,e)=>{const t=k.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>qe(o,i,t,e,!0),t.exportProseMirrorFragment=o=>le.unified().use(Oe.default,{fragment:!0}).use(kn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(Ue.default).processSync($e(o,t)).value,t.exportBlocks=o=>{const i=o.map(s=>L(s,n,e.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.exportProseMirrorFragment(k.Fragment.from(r))},t},me=(n,e)=>{const t=k.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>qe(o,i,t,e,!1),t.serializeProseMirrorFragment=o=>$e(o,t),t.serializeBlocks=o=>{const i=o.map(s=>L(s,n,e.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.serializeProseMirrorFragment(k.Fragment.from(r))},t},wn=async n=>{const e=new FormData;return e.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:e})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},Ge=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function F(n){return Ge()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function _(...n){return n.filter(e=>e).join(" ")}const vn=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function Z(n,e,t,o){const i=document.createElement("div");i.className=_("bn-block-content",t.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(t))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(e);r.className=_("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const Ke=(n,e)=>{const t=L(n,e._tiptapEditor.schema,e.schema.styleSchema).firstChild,o=e._tiptapEditor.schema.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 i=o(t);if(typeof i!="object"||!("dom"in i))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 i},C={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},fe=["backgroundColor","textColor"];function ee(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ge(n){const e={};return Object.entries(n).filter(([t,o])=>!fe.includes(t)).forEach(([t,o])=>{e[t]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(ee(t));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[t]!==o.default?{[ee(t)]:i[t]}:{}}}),e}function je(n,e,t,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=t.state.doc.resolve(i).node().attrs.id,a=e.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function oe(n,e,t,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=_("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",e);for(const[s,a]of Object.entries(t))!fe.includes(s)&&a!==o[s].default&&r.setAttribute(ee(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=_("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function V(n){return b.Node.create(n)}function be(n,e){return{config:n,implementation:e}}function K(n,e,t){return be({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:e},{node:n,requiredExtensions:t,toInternalHTML:Ke,toExternalHTML:Ke})}function ye(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function We(n,e){const t=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return e&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=e==null?void 0:e(o);return i===void 0?!1:i}}),t}function Je(n,e){const t=V({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return ge(n.propSchema)},parseHTML(){return We(n,e.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=je(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=e.render(r,i);return oe(a,r.type,r.props,n.propSchema,s)}}});if(t.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return be(n,{node:t,toInternalHTML:(o,i)=>{var a;const r=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},s=e.render(o,i);return oe(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=e.toExternalHTML)==null?void 0:l.call(e,o,i);return s===void 0&&(s=e.render(o,i)),oe(s,o.type,o.props,n.propSchema,r)}})}function Xe(n,e,t,o){return n.dom.setAttribute("data-inline-content-type",e),Object.entries(t).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[ee(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Ye(n){return{Backspace:({editor:e})=>{const t=e.state.selection.$from;return e.state.selection.empty&&t.node().type.name===n.type&&t.parentOffset===0}}}function Qe(n,e){return{config:n,implementation:e}}function Ze(n,e){return Qe({type:n.name,propSchema:e,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function ke(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function et(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:e=>{const t=e;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function En(n,e){const t=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return ge(n.propSchema)},addKeyboardShortcuts(){return Ye(n)},parseHTML(){return et(n)},renderHTML({node:o}){const i=this.options.editor,r=e.render(pe(o,i.schema.inlineContentSchema,i.schema.styleSchema));return Xe(r,n.type,o.attrs,n.propSchema)}});return Ze(t,n.propSchema)}function tt(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:e=>e.getAttribute("data-value"),renderHTML:e=>e.stringValue!==void 0?{"data-value":e.stringValue}:{}}}}function nt(n,e,t,o){return n.dom.setAttribute("data-style-type",e),o==="string"&&n.dom.setAttribute("data-value",t),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function we(n,e){return{config:n,implementation:e}}function O(n,e){return we({type:n.name,propSchema:e},{mark:n})}function ve(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function ot(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:e=>{const t=e;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Sn(n,e){const t=b.Mark.create({name:n.type,addAttributes(){return tt(n.propSchema)},parseHTML(){return ot(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=e.render();else if(n.propSchema==="string")i=e.render(o.attrs.stringValue);else throw new P(n.propSchema);return nt(i,n.type,o.attrs.stringValue,n.propSchema)}});return we(n,{mark:t})}const Cn=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Tn=O(Cn,"string"),xn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Bn=O(xn,"string"),Mn={...C,level:{default:1,values:[1,2,3]}},In=V({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const e=n.getAttribute("data-level"),t=parseInt(e);if(isFinite(t))return t},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:e,chain:t,range:o})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.getAttribute("data-level")}},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:n,HTMLAttributes:e}){var t,o;return Z(this.name,`h${n.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),Pn=K(In,Mn),Nn={textAlignment:C.textAlignment,backgroundColor:C.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},it=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},rt=64,Ln=Je({type:"image",propSchema:Nn,content:"none"},{render:(n,e)=>{const t=document.createElement("div");t.className="bn-image-block-content-wrapper",t.style.alignItems=it(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper";const a=document.createElement("div");a.className="bn-image-wrapper";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,e.domElement.firstElementChild.clientWidth)}px`;const c=document.createElement("div");c.className="bn-image-resize-handle",c.style.left="4px";const h=document.createElement("div");h.className="bn-image-resize-handle",h.style.right="4px";const p=document.createElement("p");p.className="bn-image-caption",p.innerText=n.props.caption,p.style.padding=n.props.caption?"4px":"";const f=()=>{var He;const w=((He=e.getSelection())==null?void 0:He.blocks)||[];[e.getTextCursorPosition().block,...w].find(ae=>ae.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};e.onEditorContentChange(f),e.onEditorSelectionChange(f);let m;const g=w=>{if(!m){!e.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h));return}let D;it(n.props.textAlignment)==="center"?m.handleUsed==="left"?D=m.initialWidth+(m.initialClientX-w.clientX)*2:D=m.initialWidth+(w.clientX-m.initialClientX)*2:m.handleUsed==="left"?D=m.initialWidth+m.initialClientX-w.clientX:D=m.initialWidth+w.clientX-m.initialClientX,D<rt?l.style.width=`${rt}px`:D>e.domElement.firstElementChild.clientWidth?l.style.width=`${e.domElement.firstElementChild.clientWidth}px`:l.style.width=`${D}px`},E=w=>{(!w.target||!a.contains(w.target)||!e.isEditable)&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h)),m&&(m=void 0,e.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},I=w=>{w.preventDefault()},A=()=>{e._tiptapEditor.view.dispatch(e._tiptapEditor.state.tr.setMeta(e.imageToolbar.plugin,{block:n}))},B=()=>{e.isEditable&&(a.appendChild(c),a.appendChild(h))},q=w=>{w.relatedTarget===c||w.relatedTarget===h||m||e.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h))},X=w=>{w.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"left",initialWidth:n.props.width,initialClientX:w.clientX}},te=w=>{w.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"right",initialWidth:n.props.width,initialClientX:w.clientX}};return o.appendChild(i),o.appendChild(r),s.appendChild(a),a.appendChild(l),s.appendChild(p),n.props.url===""?t.appendChild(o):t.appendChild(s),window.addEventListener("mousemove",g),window.addEventListener("mouseup",E),o.addEventListener("mousedown",I),o.addEventListener("click",A),l.addEventListener("mouseenter",B),l.addEventListener("mouseleave",q),c.addEventListener("mousedown",X),h.addEventListener("mousedown",te),{dom:t,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",E),o.removeEventListener("mousedown",I),o.removeEventListener("click",A),c.removeEventListener("mousedown",X),h.removeEventListener("mousedown",te)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const e=document.createElement("figure"),t=document.createElement("img");if(t.src=n.props.url,e.appendChild(t),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,e.appendChild(o)}return{dom:e}},parse:n=>{if(n.tagName==="FIGURE"){const e=n.querySelector("img"),t=n.querySelector("figcaption");return{url:(e==null?void 0:e.getAttribute("src"))||"",caption:(t==null?void 0:t.textContent)||(e==null?void 0:e.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),Ee=n=>{const{node:e,contentType:t}=v(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!t.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},Hn={...C},An=V({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ee(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="UL"||e.tagName==="DIV"&&e.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var e,t;return Z(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Dn=K(An,Hn),_n=new y.PluginKey("numbered-list-indexing"),On=()=>new y.Plugin({key:_n,appendTransaction:(n,e,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return t.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,c=v(o.doc,s+1);if(c===void 0)return;if(!l){const f=v(o.doc,s-2);if(f===void 0)return;if(!(c.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const A=g.attrs.index;a=(parseInt(A)+1).toString()}}}c.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),Un={...C},Rn=V({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ee(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[On()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="OL"||e.tagName==="DIV"&&e.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var e,t;return Z(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),zn=K(Rn,Un),Fn={...C},Vn=V({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{Enter:()=>Ee(this.editor),"Mod-Alt-0":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"paragraph",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var e,t;return Z(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),qn=K(Vn,Fn),$n=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[De.columnResizing({cellMinWidth:100}),De.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.setHardBreak(),!0):!1,Backspace:()=>{const n=this.editor.state.selection,e=n.empty,t=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return e&&t&&o}}},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",e))}}}),Gn={...C},Kn=V({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var e,t;return Z(this.name,"table",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),jn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Wn=K(Kn,Gn,[$n,jn,Vt.TableHeader.extend({content:"tableContent"}),Ft.TableCell.extend({content:"tableContent"}),qt.TableRow]),Se={paragraph:qn,heading:Pn,bulletListItem:Dn,numberedListItem:zn,image:Ln,table:Wn},st=ye(Se),Ce={bold:O(nn.default,"boolean"),italic:O(rn.default,"boolean"),underline:O(an.default,"boolean"),strike:O(sn.default,"boolean"),code:O(on.default,"boolean"),textColor:Bn,backgroundColor:Tn},Jn=ve(Ce),Te={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Xn=ke(Te);function N(n,e){return n in e.schema.blockSchema&&e.schema.blockSchema[n]===st[n]}function Yn(n,e,t){return e.type===n&&e.type in t.schema.blockSchema&&N(e.type,t)}function at(n,e,t){return e in t.schema.blockSchema&&n in t.schema.blockSchema[e].propSchema&&t.schema.blockSchema[e].propSchema[n]===C[n]}function Qn(n,e,t){return at(n,e.type,t)}function xe(n,e){let t,o;if(e.firstChild.descendants((i,r)=>t?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(t=i,o=r+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function Zn(n,e,t="before",o){const i=o._tiptapEditor,r=typeof e=="string"?e:e.id,s=[];for(const h of n)s.push(L(h,i.schema,o.schema.styleSchema));const{node:a,posBeforeNode:l}=xe(r,i.state.doc);if(t==="before"&&i.view.dispatch(i.state.tr.insert(l,s)),t==="after"&&i.view.dispatch(i.state.tr.insert(l+a.nodeSize,s)),t==="nested"&&a.childCount<2){const h=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(l+a.firstChild.nodeSize+1,h))}const c=[];for(const h of s)c.push(S(h,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache));return c}function eo(n,e,t){const o=t._tiptapEditor,i=typeof n=="string"?n:n.id,{posBeforeNode:r}=xe(i,o.state.doc);o.commands.BNUpdateBlock(r+1,e);const s=o.state.doc.resolve(r+1).node();return S(s,t.schema.blockSchema,t.schema.inlineContentSchema,t.schema.styleSchema,t.blockCache)}function lt(n,e,t){const o=e._tiptapEditor,i=o.state.tr,r=new Set(n.map(l=>typeof l=="string"?l:l.id)),s=[];let a=0;if(o.state.doc.descendants((l,c)=>{if(r.size===0)return!1;if(l.type.name!=="blockContainer"||!r.has(l.attrs.id))return!0;s.push(S(l,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)),r.delete(l.attrs.id),a=(t==null?void 0:t(l,c,i,a))||a;const h=i.doc.nodeSize;i.delete(c-a-1,c-a+l.nodeSize+1);const p=i.doc.nodeSize;return a+=h-p,!1}),r.size>0){const l=[...r].join(`
|
|
6
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+l)}return o.view.dispatch(i),s}function
|
|
7
|
-
`:"",o={};e.lang&&(o["data-language"]=e.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return e.meta&&(i.data={meta:e.meta}),n.patch(e,i),i=n.applyData(e,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(e,i),i}function po(n,e,t,o,i){const r=le.unified().use(dn.default).use(Re.default).use(un.default,{handlers:{..._e.defaultHandlers,code:ho}}).use(Ue.default).processSync(n);return ut(r.value,e,t,o,i)}class j{constructor(){u(this,"callbacks",{})}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),()=>this.off(e,t)}emit(e,...t){const o=this.callbacks[e];o&&o.forEach(i=>i.apply(this,t))}off(e,t){const o=this.callbacks[e];o&&(t?this.callbacks[e]=o.filter(i=>i!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}class ht{constructor(e,t,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({state:e})=>!e.selection.empty);u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragHandler",()=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",e=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var e;(e=this.state)!=null&&e.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.dom.addEventListener("mouseup",this.viewMouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("focus",this.focusHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var f,m;const{state:o,composing:i}=e,{doc:r,selection:s}=o,a=t&&t.doc.eq(r)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,c=Math.min(...l.map(g=>g.$from.pos)),h=Math.max(...l.map(g=>g.$to.pos)),p=(f=this.shouldShow)==null?void 0:f.call(this,{view:e,state:o,from:c,to:h});if(this.editor.isEditable&&!this.preventShow&&(p||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((m=this.state)!=null&&m.show&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:e}=this.pmView,{selection:t}=e,{ranges:o}=t,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(t)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const pt=new y.PluginKey("FormattingToolbarPlugin");class mt extends j{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new y.Plugin({key:pt,view:o=>(this.view=new ht(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class mo{constructor(e,t,o){u(this,"state");u(this,"emitUpdate");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(this,"mouseOverHandler",e=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&e.target.nodeName==="A"){const t=e.target,o=this.pmView.posAtDOM(t,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",e=>{var o;const t=this.pmView.dom.parentElement;this.hyperlinkMark&&e&&e.target&&!(t===e.target||t.contains(e.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.state)!=null&&e.show&&(this.state.referencePos=b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.emitUpdate())});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized hyperlink toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(e,t){var i;const o=this.pmView.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:e})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.state)!=null&&i.show&&(this.state.show=!1,this.emitUpdate())}deleteHyperlink(){var e;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate())}update(){var t;if(!this.pmView.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){this.state={show:!0,referencePos:b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.emitUpdate();return}if((t=this.state)!=null&&t.show&&e&&(!this.hyperlinkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ft=new y.PluginKey("HyperlinkToolbarPlugin");class gt extends j{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(t,o)=>{this.view.editHyperlink(t,o)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new y.Plugin({key:ft,view:o=>(this.view=new mo(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class bt{constructor(e,t,o){u(this,"state");u(this,"emitUpdate");u(this,"prevWasEditable",null);u(this,"mouseDownHandler",()=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate())});u(this,"dragstartHandler",()=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate())});u(this,"blurHandler",e=>{var o;const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var e;if((e=this.state)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate()}});this.pluginKey=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.mouseDownHandler),t.dom.addEventListener("dragstart",this.dragstartHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var i,r;const o=this.pluginKey.getState(e.state);if(!((i=this.state)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!e.state.selection.eq(t.selection)||!e.state.doc.eq(t.doc))&&(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const Me=new y.PluginKey("ImageToolbarPlugin");class yt extends j{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new y.Plugin({key:Me,view:o=>(this.view=new bt(Me,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(Me))==null?void 0:r.block}}}})}onUpdate(t){return this.on("update",t)}}const fo=b.findParentNode(n=>n.type.name==="blockContainer");class go{constructor(e,t){u(this,"state");u(this,"emitUpdate");u(this,"pluginState");u(this,"handleScroll",()=>{var e;if((e=this.state)!=null&&e.show){const t=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(U,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=e,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(o,this.state)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const o=U.getState(t),i=U.getState(e.state),r=o===void 0&&i!==void 0,s=o!==void 0&&i===void 0;if(!r&&!(o!==void 0&&i!==void 0)&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){document.removeEventListener("scroll",this.handleScroll)}}const U=new y.PluginKey("SuggestionMenuPlugin");class kt extends j{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",t=>{this.triggerCharacters.push(t)});u(this,"removeTriggerCharacter",t=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==t)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new y.Plugin({key:U,view:()=>(this.view=new go(t,(i,r)=>{this.emit(`update ${i}`,r)}),this.view),state:{init(){},apply(i,r,s,a){if(i.getMeta("orderedListIndexing")!==void 0)return r;const l=i.getMeta(U);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:a.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(a.selection.from!==a.selection.to||l===null||i.getMeta("focus")||i.getMeta("blur")||i.getMeta("pointer")||r.triggerCharacter!==void 0&&a.selection.from<r.queryStartPos)return;const c={...r};return c.query=a.doc.textBetween(r.queryStartPos,a.selection.from),c}},props:{handleKeyDown(i,r){const s=this.getState(i.state);return o.includes(r.key)&&s===void 0?(r.preventDefault(),i.dispatch(i.state.tr.insertText(r.key).scrollIntoView().setMeta(U,{triggerCharacter:r.key})),!0):!1},decorations(i){const r=this.getState(i);if(r===void 0)return null;if(!r.fromUserInput){const s=fo(i.selection);if(s)return x.DecorationSet.create(i.doc,[x.Decoration.node(s.pos,s.pos+s.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return x.DecorationSet.create(i.doc,[x.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(t,o){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,o)}}function bo(n,e){n.suggestionMenus.addTriggerCharacter(e)}class W extends y.Selection{constructor(t,o){super(t,o);u(this,"nodes");const i=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(t,o,i=o){return new W(t.resolve(o),t.resolve(i))}content(){return new k.Slice(k.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof W)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?y.Selection.near(t.resolve(i.pos)):i.deleted?y.Selection.near(t.resolve(r.pos)):new W(t.resolve(i.pos),t.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let R;function ie(n,e){var i;if(!e.dom.isConnected)return;const t=e.posAtCoords(n);if(!t)return;let o=e.domAtPos(t.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function yo(n,e){const t=ie(n,e);if(t&&t.node.nodeType===1){const o=e.docView,i=o.nearestDesc(t.node,!0);return!i||i===o?null:i.posBefore}return null}function ko(n,e){let t,o;const i=e.resolve(n.from).node().type.spec.group==="blockContent",r=e.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);t=e.resolve(a-1).pos,o=e.resolve(l+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function wt(n,e,t=e){e===t&&(t+=n.state.doc.resolve(e+1).node().nodeSize);const o=n.domAtPos(e).node.cloneNode(!0),i=n.domAtPos(e).node,r=(h,p)=>Array.prototype.indexOf.call(h.children,p),s=r(i,n.domAtPos(e+1).node.parentElement),a=r(i,n.domAtPos(t-1).node.parentElement);for(let h=i.childElementCount-1;h>=0;h--)(h>a||h<s)&&o.removeChild(o.children[h]);vt(),R=o;const c=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");R.className=R.className+" bn-drag-preview "+c,document.body.appendChild(R)}function vt(){R!==void 0&&(document.body.removeChild(R),R=void 0)}function wo(n,e){if(!n.dataTransfer)return;const t=e.prosemirrorView,o=t.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=yo(i,t);if(r!=null){const s=t.state.selection,a=t.state.doc,{from:l,to:c}=ko(s,a),h=l<=r&&r<c,p=s.$anchor.node()!==s.$head.node()||s instanceof W;h&&p?(t.dispatch(t.state.tr.setSelection(W.create(a,l,c))),wt(t,l,c)):(t.dispatch(t.state.tr.setSelection(y.NodeSelection.create(t.state.doc,r))),wt(t,r));const f=t.state.selection.content(),m=e._tiptapEditor.schema,E=me(m,e).serializeProseMirrorFragment(f.content),A=Q(m,e).exportProseMirrorFragment(f.content),B=Be(A);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",A),n.dataTransfer.setData("text/plain",B),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(R,0,0),t.dragging={slice:f,move:!0}}}class Et{constructor(e,t,o){u(this,"state");u(this,"emitUpdate");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",e=>{if(this.editor._tiptapEditor.commands.blur(),e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const o=new Event("drop",e),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("dragover",e),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",e=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseDown",e=>{this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseMove",e=>{var c,h,p,f,m;if(this.menuFrozen)return;const t=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=e.clientX>=o.left&&e.clientX<=o.right&&e.clientY>=o.top&&e.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&e&&e.target&&!(r===e.target||r.contains(e.target))){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.horizontalPosAnchor=t.x;const s={left:t.left+t.width/2,top:e.clientY},a=ie(s,this.pmView);if(!a||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.emitUpdate(this.state));return}if((p=this.state)!=null&&p.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.emitUpdate(this.state)}});u(this,"onScroll",()=>{var e;if((e=this.state)!=null&&e.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),document.body.removeEventListener("mousemove",this.onMouseMove,!0),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!0;const t=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!o)return;const i=v(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,startPos:s,endPos:a}=i;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=a+1,h=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(h).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(U,{triggerCharacter:"/",fromUserInput:!1}))}}const St=new y.PluginKey("SideMenuPlugin");class Ct extends j{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",t=>{this.view.isDragging=!0,wo(t,this.editor)});u(this,"blockDragEnd",()=>vt());u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.view.menuFrozen=!1);this.editor=t,this.plugin=new y.Plugin({key:St,view:o=>(this.view=new Et(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}let M;function Tt(){M||(M=document.createElement("div"),M.innerHTML="_",M.style.opacity="0",M.style.height="1px",M.style.width="1px",document.body.appendChild(M))}function vo(){M&&(document.body.removeChild(M),M=void 0)}function re(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function Eo(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function So(n){n.forEach(e=>{const t=document.getElementsByClassName(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"})}class xt{constructor(e,t,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",e=>{var c;if(this.menuFrozen)return;const t=Eo(e.target);if(!t||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=re(t),i=re(t.parentElement),r=t.getBoundingClientRect(),s=t.parentElement.parentElement.getBoundingClientRect(),a=ie(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((h,p)=>typeof l<"u"?!1:h.type.name!=="blockContainer"||h.attrs.id!==a.id?!0:(l=S(h,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache),this.tablePos=p+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",e=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",So(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const t={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(t.left,t.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=re(i.parentElement),a=re(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,h=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const p=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==p&&(this.state.draggingState.mousePos=p,r=!0),r&&this.emitUpdate(),h&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});u(this,"dropHandler",e=>{if(this.state===void 0||this.state.draggingState===void 0)return;e.preventDefault();const t=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=t[this.state.draggingState.originalIndex];t.splice(this.state.draggingState.originalIndex,1),t.splice(this.state.rowIndex,0,o)}else{const o=t.map(i=>i.cells[this.state.draggingState.originalIndex]);t.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:t}})});u(this,"scrollHandler",()=>{var e;if((e=this.state)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=t.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=t.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const J=new y.PluginKey("TableHandlesPlugin");class Bt extends j{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",t=>{if(this.view.state===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:t.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),Tt(),t.dataTransfer.setDragImage(M,0,0),t.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",t=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:t.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),Tt(),t.dataTransfer.setDragImage(M,0,0),t.dataTransfer.effectAllowed="copyMove"});u(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),vo()});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=t,this.plugin=new y.Plugin({key:J,view:o=>(this.view=new xt(t,o,i=>{this.emit("update",i)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return x.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),c=l.node();for(let h=0;h<c.childCount;h++){const p=o.doc.resolve(l.posAtIndex(h)+1),f=p.node(),m=p.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(x.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const c=o.doc.resolve(s.posAtIndex(l)+1),h=o.doc.resolve(c.posAtIndex(i)+1),p=h.node(),f=h.pos+(i>this.view.state.draggingState.originalIndex?p.nodeSize-2:0);r.push(x.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return x.DecorationSet.create(o.doc,r)}}})}onUpdate(t){return this.on("update",t)}}function Mt(n,e){const t=n.state.selection.content().content,i=me(n.state.schema,e).serializeProseMirrorFragment(t),s=Q(n.state.schema,e).exportProseMirrorFragment(t),a=Be(s);return{internalHTML:i,externalHTML:s,plainText:a}}const Co=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{copy(e,t){t.preventDefault(),t.clipboardData.clearData(),"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&e.dispatch(e.state.tr.setSelection(new y.NodeSelection(e.state.doc.resolve(e.state.selection.from-1))));const{internalHTML:o,externalHTML:i,plainText:r}=Mt(e,n);return t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",i),t.clipboardData.setData("text/plain",r),!0},dragstart(e,t){if(!("node"in e.state.selection)||e.state.selection.node.type.spec.group!=="blockContent")return;e.dispatch(e.state.tr.setSelection(new y.NodeSelection(e.state.doc.resolve(e.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{internalHTML:o,externalHTML:i,plainText:r}=Mt(e,n);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",i),t.dataTransfer.setData("text/plain",r),!0}}}})]}}),To=["blocknote/html","text/html","text/plain"],xo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{paste(e,t){t.preventDefault();let o=null;for(const i of To)if(t.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=t.clipboardData.getData(o);o==="text/html"&&(i=dt(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),Bo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:C.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):C.backgroundColor.default,renderHTML:n=>n.backgroundColor!==C.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),Mo=new y.PluginKey("blocknote-placeholder"),Io=b.Extension.create({name:"placeholder",addOptions(){return{placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",bulletListItem:"List",numberedListItem:"List"}}},addProseMirrorPlugins(){const n=this.options.placeholders;return[new y.Plugin({key:Mo,view:()=>{const e=document.createElement("style");document.head.appendChild(e);const t=e.sheet,o=(r="")=>`.bn-block-content${r} .bn-inline-content:has(> .ProseMirror-trailingBreak):before`,i=(r,s=!0)=>{const a=s?"[data-is-empty-and-focused]":"";if(r==="default")return o(a);const l=`[data-content-type="${r}"]`;return o(a+l)};for(const[r,s]of Object.entries(n)){const a=r==="default";t.insertRule(`${i(r,a)}{ content: ${JSON.stringify(s)}; }`),a||t.insertRule(`${i(r,!0)}{ content: ${JSON.stringify(s)}; }`)}return{destroy:()=>{document.head.removeChild(e)}}},props:{decorations:e=>{const{doc:t,selection:o}=e;if(!this.editor.isEditable||!o.empty)return;const r=o.$anchor,s=r.parent;if(s.content.size>0)return null;const a=r.before(),l=x.Decoration.node(a,a+s.nodeSize,{"data-is-empty-and-focused":"true"});return x.DecorationSet.create(t,[l])}}})]}}),Po=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),No=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:C.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):C.textColor.default,renderHTML:n=>n.textColor!==C.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Lo=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new y.PluginKey(this.name);return[new y.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,c=s.nodes.blockContainer,h=s.nodes.paragraph;if(a)return r.insert(l,c.create(void 0,h.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let o=e.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Ho=new y.PluginKey("non-editable-block"),Ao=()=>new y.Plugin({key:Ho,props:{handleKeyDown:(n,e)=>{"node"in n.state.selection&&e.key.length===1&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey&&e.preventDefault()}}}),It=new y.PluginKey("previous-blocks"),Do={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},_o=()=>{let n;return new y.Plugin({key:It,view(e){return{update:async(t,o)=>{var i;((i=this.key)==null?void 0:i.getState(t.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(It,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,o,i){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||o.doc.eq(i.doc))return t;const r={},s=b.findChildren(o.doc,c=>c.attrs.id),a=new Map(s.map(c=>[c.node.attrs.id,c])),l=b.findChildren(i.doc,c=>c.attrs.id);for(const c of l){const h=a.get(c.node.attrs.id),p=h==null?void 0:h.node.firstChild,f=c.node.firstChild;if(h&&p&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(c.pos).depth};let g={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:o.doc.resolve(h.pos).depth};r[c.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(c.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[c.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),t.currentTransactionOldBlockAttrs[c.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,t.updatedBlocks.add(c.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=r,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const o=[];return e.doc.descendants((i,r)=>{if(!i.attrs.id||!t.updatedBlocks.has(i.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[c,h]of Object.entries(s))a["data-prev-"+Do[c]]=h||"none";const l=x.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),x.DecorationSet.create(e.doc,o)}}})},Oo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Uo=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const e={};for(const[t,o]of Object.entries(Oo))n.getAttribute(o)&&(e[t]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:n}){var i;const e=document.createElement("div");e.className="bn-block-outer",e.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&e.setAttribute(r,s);const t={...((i=this.options.domAttributes)==null?void 0:i.block)||{},...n},o=document.createElement("div");o.className=_("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(t))r!=="class"&&o.setAttribute(r,s);return e.appendChild(o),{dom:e,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:e,dispatch:t})=>{const o=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:e,dispatch:t})=>{const o=v(e.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return t&&e.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,e)=>({state:t,dispatch:o})=>{const i=v(t.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(e.children!==void 0){const f=[];for(const m of e.children)f.push(L(m,t.schema,this.options.editor.schema.styleSchema));a.childCount===2?t.tr.replace(r+l.nodeSize+1,s-1,new k.Slice(k.Fragment.from(f),0,0)):t.tr.insert(r+l.nodeSize,t.schema.nodes.blockGroup.create({},f))}const c=l.type.name,h=e.type||c;let p="keep";if(e.content)if(typeof e.content=="string")p=[t.schema.text(e.content)];else if(Array.isArray(e.content))p=Y(e.content,t.schema,this.options.editor.schema.styleSchema);else if(e.content.type==="tableContent")p=he(e.content,t.schema,this.options.editor.schema.styleSchema);else throw new P(e.content.type);else{const f=t.schema.nodes[c].spec.content,m=t.schema.nodes[h].spec.content;f===""||m!==f&&(p=[])}p==="keep"?t.tr.setNodeMarkup(r,e.type===void 0?void 0:t.schema.nodes[e.type],{...l.attrs,...e.props}):t.tr.replaceWith(r,s,t.schema.nodes[h].create({...l.attrs,...e.props},p)).setSelection(t.schema.nodes[h].spec.content===""?new y.NodeSelection(t.tr.doc.resolve(r)):t.schema.nodes[h].spec.content==="inline*"?new y.TextSelection(t.tr.doc.resolve(r)):new y.TextSelection(t.tr.doc.resolve(r+4))),t.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...e.props})}return!0},BNMergeBlocks:n=>({state:e,dispatch:t})=>{const o=e.doc.resolve(n+1).node().type.name==="blockContainer",i=e.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=v(e.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:c,depth:h}=r;if(s.childCount===2){const m=e.doc.resolve(l+a.nodeSize+1),g=e.doc.resolve(c-1),E=m.blockRange(g);t&&e.tr.lift(E,h-1)}let p=n-1,f=v(e.doc,p);for(;f.numChildBlocks>0;)if(p--,f=v(e.doc,p),f===void 0)return!1;return t&&(t(e.tr.deleteRange(l,l+a.nodeSize).replace(p-1,l,new k.Slice(a.content,0,0)).scrollIntoView()),e.tr.setSelection(new y.TextSelection(e.doc.resolve(p-1)))),!0},BNSplitBlock:(n,e)=>({state:t,dispatch:o})=>{const i=v(t.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:c}=i,h=t.doc.cut(a+1,n),p=t.doc.cut(n,l-1),f=t.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(t.tr.insert(m,f),t.tr.replace(g,g+1,p.content.size>0?new k.Slice(k.Fragment.from(p),c+2,c+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(s).type,r.attrs),t.tr.setSelection(new y.TextSelection(t.doc.resolve(g))),t.tr.replace(a+1,l-1,h.content.size>0?new k.Slice(k.Fragment.from(h),c+2,c+2):void 0)),!0}}},addProseMirrorPlugins(){return[_o(),Ao()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=v(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=v(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=v(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,c=s===2,h=s-1;return!c&&a&&l&&r===2?o.BNMergeBlocks(h):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=v(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,c=i.selection.from===a-1,h=i.selection.empty,p=r.childCount===2;if(!l&&c&&h&&!p){let f=s,m=a+2,g=i.doc.resolve(m).depth;for(;g<f;)f=g,m+=2,g=i.doc.resolve(m).depth;return o.BNMergeBlocks(m-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=v(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,c=r.textContent.length===0,h=s>2;return a&&l&&c&&h?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,c=i.selection.anchor===i.selection.head,h=s.textContent.length===0;if(l&&c&&h){const p=a+1,f=p+2;return r().BNCreateBlock(p).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=v(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0)}}}),Ro=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const e={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},t=document.createElement("div");t.className=_("bn-block-group",e.class),t.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(e))i!=="class"&&t.setAttribute(i,r);return{dom:t,contentDOM:t}}}),zo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Pt=n=>{var t;const e=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Yt.Gapcursor,Io.configure({...n.placeholders!==void 0?{placeholders:n.placeholders}:{}}),$.configure({types:["blockContainer"]}),Qt.HardBreak,tn.Text,en.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),No,Bo,Po,zo,Uo.configure({editor:n.editor,domAttributes:n.domAttributes}),Ro.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),Co(n.editor),xo(n.editor),Xt.Dropcursor.configure({width:5,color:"#ddeeff"}),Lo];if(n.collaboration){if(e.push(hn.default.configure({fragment:n.collaboration.fragment})),(t=n.collaboration.provider)!=null&&t.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};e.push(pn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else e.push(Zt.History);return e};function Fo(n,e){const t=[];return n.forEach((o,i,r)=>{r!==e&&t.push(o)}),k.Fragment.from(t)}function Vo(n,e){let t=k.Fragment.from(n.content);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const i=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.spec.group==="blockGroup"){const s=t.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(t.child(o+1)),t=Fo(t,o+1))}const r=e.state.schema.nodes.blockContainer.create(void 0,i);t=t.replaceChild(o,r)}return new k.Slice(t,n.openStart,n.openEnd)}const Qo="";class se{constructor(e){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=(e==null?void 0:e.blockSpecs)||Se,this.inlineContentSpecs=(e==null?void 0:e.inlineContentSpecs)||Te,this.styleSpecs=(e==null?void 0:e.styleSpecs)||Ce,this.blockSchema=ye(this.blockSpecs),this.inlineContentSchema=ke(this.inlineContentSpecs),this.styleSchema=ve(this.styleSpecs)}static create(e){return new se(e)}}class qo extends b.Editor{constructor(t,o){super({...t,content:void 0});u(this,"_state");u(this,"mount",t=>{t?(this.options.element=t,this.createViewAlternative()):this.destroy()});const i=this.schema;let r;const s=i.nodes.doc.createAndFill;i.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=s.apply(i.nodes.doc,l),h=JSON.parse(JSON.stringify(c.toJSON()));return h.content[0].content[0].attrs.id="initialBlockId",r=k.Node.fromJSON(i,h),r};let a;try{const l=t==null?void 0:t.content.map(c=>L(c,this.schema,o).toJSON());a=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(t.content))}this._state=y.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new x.EditorView(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const t=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(t),this.createNodeViews()})}}const Zo="",$o={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ie{constructor(e){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"hyperlinkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"imageToolbar");u(this,"tableHandles");u(this,"uploadFile");var l,c,h,p,f,m,g,E;this.options=e;const t=e;if(t.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(t.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(t.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(t.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");const o={defaultStyles:!0,schema:e.schema||se.create(),...e};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new mt(this),this.hyperlinkToolbar=new gt(this),this.sideMenu=new Ct(this),this.suggestionMenus=new kt(this),N("image",this)&&(this.imageToolbar=new yt(this)),N("table",this)&&(this.tableHandles=new Bt(this));const i=Pt({editor:this,placeholders:o.placeholders,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.hyperlinkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.imageToolbar?[this.imageToolbar.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[]]});i.push(r),this.uploadFile=o.uploadFile,o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const s=o.initialContent||(e.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:$.options.generateID()}]);if(!Array.isArray(s)||s.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+s);const a={...$o,...o._tiptapOptions,content:s,extensions:o.enableBlockNoteExtensions===!1?((l=o._tiptapOptions)==null?void 0:l.extensions)||[]:[...((c=o._tiptapOptions)==null?void 0:c.extensions)||[],...i],editorProps:{...(h=o._tiptapOptions)==null?void 0:h.editorProps,attributes:{...(f=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:f.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:_("bn-editor",o.defaultStyles?"bn-default-styles":"",((E=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:E.class)||"")},transformPasted:Vo}};this._tiptapEditor=new qo(a,this.schema.styleSchema)}static create(e={}){return new Ie(e)}mount(e){this._tiptapEditor.mount(e)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){return this.topLevelBlocks}get document(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(S(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==t?!0:(o=S(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.document.slice();t&&o.reverse();function i(r){for(const s of r){if(!e(s))return!1;const a=t?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:o,endPos:i}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(t-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:S(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:S(a,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:S(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:i}=xe(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=v(this._tiptapEditor.state.doc,i+2),a=this.schema.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")t==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")t==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new P(a)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,o)=>t.type.spec.group!=="blockContent"||o+t.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(e.push(S(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,o="before"){return Zn(e,t,o,this)}updateBlock(e,t){return eo(e,t,this)}removeBlocks(e){return to(e,this)}replaceBlocks(e,t){return no(e,t,this)}insertInlineContent(e){const t=Y(e,this._tiptapEditor.schema,this.schema.styleSchema);oo({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},t,this)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks();for(const o of t){const i=this.schema.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?e[i.type]=!0:e[i.type]=o.attrs.stringValue}return e}addStyles(e){this._tiptapEditor.view.focus();for(const[t,o]of Object.entries(e)){const i=this.schema.styleSchema[t];if(!i)throw new Error(`style ${t} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(t);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(t,{stringValue:o});else throw new P(i.propSchema)}}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){this._tiptapEditor.view.focus();for(const[t,o]of Object.entries(e)){const i=this.schema.styleSchema[t];if(!i)throw new Error(`style ${t} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(t);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(t,{stringValue:o});else throw new P(i.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(e,t){if(e==="")return;const{from:o,to:i}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,o,i).addMark(o,o+t.length,r))}canNestBlock(){const{startPos:e,depth:t}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(e).index(t-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:e}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(e=this.document){return Q(this._tiptapEditor.schema,this).exportBlocks(e)}async tryParseHTMLToBlocks(e){return ut(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(e=this.document){return ro(e,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(e){return po(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(e)}onChange(e){const t=()=>{e(this)};return this._tiptapEditor.on("update",t),()=>{this._tiptapEditor.off("update",t)}}onSelectionChange(e){const t=()=>{e(this)};return this._tiptapEditor.on("selectionUpdate",t),()=>{this._tiptapEditor.off("selectionUpdate",t)}}}function Go(n){let e=n.getTextCursorPosition().block,t=n.schema.blockSchema[e.type].content;for(;t==="none";)e=n.getTextCursorPosition().nextBlock,t=n.schema.blockSchema[e.type].content,n.setTextCursorPosition(e,"end")}function H(n,e){const t=n.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(t.content)&&(t.content.length===1&&G(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?n.updateBlock(t,e):(n.insertBlocks([e],t,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return Go(n),o}function Ko(n){const e=[];return N("heading",n)&&e.push({title:"Heading 1",onItemClick:()=>{H(n,{type:"heading",props:{level:1}})},subtext:"Used for a top-level heading",badge:F("Mod-Alt-1"),aliases:["h","heading1","h1"],group:"Headings"},{title:"Heading 2",onItemClick:()=>{H(n,{type:"heading",props:{level:2}})},subtext:"Used for key sections",badge:F("Mod-Alt-2"),aliases:["h2","heading2","subheading"],group:"Headings"},{title:"Heading 3",onItemClick:()=>{H(n,{type:"heading",props:{level:3}})},subtext:"Used for subsections and group headings",badge:F("Mod-Alt-3"),aliases:["h3","heading3","subheading"],group:"Headings"}),N("numberedListItem",n)&&e.push({title:"Numbered List",onItemClick:()=>{H(n,{type:"numberedListItem"})},subtext:"Used to display a numbered list",badge:F("Mod-Shift-7"),aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"}),N("bulletListItem",n)&&e.push({title:"Bullet List",onItemClick:()=>{H(n,{type:"bulletListItem"})},subtext:"Used to display an unordered list",badge:F("Mod-Shift-8"),aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"}),N("paragraph",n)&&e.push({title:"Paragraph",onItemClick:()=>{H(n,{type:"paragraph"})},subtext:"Used for the body of your document",badge:F("Mod-Alt-0"),aliases:["p","paragraph"],group:"Basic blocks"}),N("table",n)&&e.push({title:"Table",onItemClick:()=>{H(n,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},subtext:"Used for for tables",aliases:["table"],group:"Advanced",badge:void 0}),N("image",n)&&e.push({title:"Image",onItemClick:()=>{const t=H(n,{type:"image"});n.prosemirrorView.dispatch(n._tiptapEditor.state.tr.setMeta(n.imageToolbar.plugin,{block:t}))},subtext:"Insert an image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],group:"Media"}),e}function jo(n,e){return n.filter(({title:t,aliases:o})=>t.toLowerCase().startsWith(e.toLowerCase())||o&&o.filter(i=>i.toLowerCase().startsWith(e.toLowerCase())).length!==0)}function Pe(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function Nt(n){return typeof n=="string"?Pe(n):Array.isArray(n)?n.flatMap(e=>typeof e=="string"?Pe(e):de(e)?{...e,content:Pe(e.content)}:G(e)?e:{props:{},...e,content:Nt(e.content)}):n}function Wo(n,e){return e.map(t=>Ne(n,t))}function Ne(n,e){const t={id:"",type:e.type,props:{},content:n[e.type].content==="inline"?[]:void 0,children:[],...e};return Object.entries(n[e.type].propSchema).forEach(([o,i])=>{t.props[o]===void 0&&(t.props[o]=i.default)}),{...t,content:Nt(t.content),children:t.children.map(o=>Ne(n,o))}}function Lt(n){n.id||(n.id=$.options.generateID()),n.children&&Ht(n.children)}function Ht(n){for(const e of n)Lt(e)}d.BlockNoteEditor=Ie,d.BlockNoteSchema=se,d.FormattingToolbarProsemirrorPlugin=mt,d.FormattingToolbarView=ht,d.HyperlinkToolbarProsemirrorPlugin=gt,d.ImageToolbarProsemirrorPlugin=yt,d.ImageToolbarView=bt,d.SideMenuProsemirrorPlugin=Ct,d.SideMenuView=Et,d.SuggestionMenuProseMirrorPlugin=kt,d.TableHandlesProsemirrorPlugin=Bt,d.TableHandlesView=xt,d.UniqueID=$,d.UnreachableCaseError=P,d.addIdsToBlock=Lt,d.addIdsToBlocks=Ht,d.addInlineContentAttributes=Xe,d.addInlineContentKeyboardShortcuts=Ye,d.addStyleAttributes=nt,d.blockToNode=L,d.camelToDataKebab=ee,d.checkBlockHasDefaultProp=Qn,d.checkBlockIsDefaultType=Yn,d.checkBlockTypeHasDefaultProp=at,d.checkDefaultBlockTypeInSchema=N,d.contentNodeToInlineContent=ne,d.createBlockSpec=Je,d.createBlockSpecFromStronglyTypedTiptapNode=K,d.createExternalHTMLExporter=Q,d.createInlineContentSpec=En,d.createInlineContentSpecFromTipTapNode=Ze,d.createInternalBlockSpec=be,d.createInternalHTMLSerializer=me,d.createInternalInlineContentSpec=Qe,d.createInternalStyleSpec=we,d.createStronglyTypedTiptapNode=V,d.createStyleSpec=Sn,d.createStyleSpecFromTipTapMark=O,d.createSuggestionMenu=bo,d.defaultBlockSchema=st,d.defaultBlockSpecs=Se,d.defaultInlineContentSchema=Xn,d.defaultInlineContentSpecs=Te,d.defaultProps=C,d.defaultStyleSchema=Jn,d.defaultStyleSpecs=Ce,d.filterSuggestionItems=jo,d.formatKeyboardShortcut=F,d.formattingToolbarPluginKey=pt,d.getBlockFromPos=je,d.getBlockNoteExtensions=Pt,d.getBlockSchemaFromSpecs=ye,d.getDefaultSlashMenuItems=Ko,d.getDraggableBlockFromCoords=ie,d.getInlineContentParseRules=et,d.getInlineContentSchemaFromSpecs=ke,d.getParseRules=We,d.getStyleParseRules=ot,d.getStyleSchemaFromSpecs=ve,d.hyperlinkToolbarPluginKey=ft,d.inheritedProps=fe,d.inlineContentToNodes=Y,d.insertOrUpdateBlock=H,d.isAppleOS=Ge,d.isLinkInlineContent=ce,d.isPartialLinkInlineContent=de,d.isSafari=vn,d.isStyledTextInlineContent=G,d.mergeCSSClasses=_,d.nodeToBlock=S,d.nodeToCustomInlineContent=pe,d.partialBlockToBlockForTesting=Ne,d.partialBlocksToBlocksForTesting=Wo,d.propsToAttributes=ge,d.sideMenuPluginKey=St,d.stylePropsToAttributes=tt,d.suggestionMenuPluginKey=U,d.tableContentToNodes=he,d.tableHandlesPluginKey=J,d.uploadToTmpFilesDotOrg_DEV_ONLY=wn,d.wrapInBlockStructure=oe,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
5
|
+
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&t[r.type.name]){i&&(o.push(i),i=void 0),o.push(mt(r,t,e));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const c=e[l.type.name];if(!c)throw new Error(`style ${l.type.name} not found in styleSchema`);if(c.propSchema==="boolean")s[c.type]=!0;else if(c.propSchema==="string")s[c.type]=l.attrs.stringValue;else throw new L(c.propSchema)}i?K(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):dt(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function mt(n,t,e){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=t[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const c=i.propSchema;a in c&&(o[a]=l)}let r;return i.content==="styled"?r=ot(n,t,e):r=void 0,{type:n.type.name,props:o,content:r}}function S(n,t,e,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=Ft(n);let a=s.id;a===null&&(a=G.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const E=t[s.contentType.name];if(!E)throw Error("Block is of an unrecognized type: "+s.contentType.name);const I=E.propSchema;m in I&&(l[m]=g)}const c=t[s.contentType.name],h=[];for(let m=0;m<s.numChildBlocks;m++)h.push(S(n.lastChild.child(m),t,e,o,i));let p;if(c.content==="inline")p=ot(s.contentNode,e,o);else if(c.content==="table")p=kn(s.contentNode,e,o);else if(c.content==="none")p=void 0;else throw new L(c.content);const f={id:a,type:c.type,props:l,content:p,children:h};return i==null||i.set(n,f),f}function yn(n){return n.document||window.document}const $t=(n,t,e,o,i)=>{if(!e.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=y.DOMSerializer.renderSpec(yn(t),e.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const c=o.blockImplementations[a.type.name].implementation,p=(i?c.toExternalHTML:c.toInternalHTML)(S(n,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache),o);if(p.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");p.contentDOM.appendChild(e.serializeFragment(a.content,t))}s.appendChild(p.dom)}l!==void 0&&e.serializeFragment(y.Fragment.from(l),t,s)}else e.serializeFragment(n.content,t,s)}return r},Gt=(n,t)=>{const e=t.serializeFragment(n),o=document.createElement("div");return o.appendChild(e),o.innerHTML};function wn(n){const t=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),e=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const c=o.children[a].children[0],h=c.children[0],p=c.children.length===2?c.children[1]:null,f=t.has(h.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(h.properties.dataContentType)?"ol":"ul":null;if(p!==null&&e(p),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Dt.fromDom(document.createElement(m)));const g=Dt.fromDom(document.createElement("li"));g.children.push(h.children[0]),p!==null&&g.children.push(...p.children),r.children.push(g)}else if(p!==null){o.children.splice(a+1,0,...p.children),o.children[a]=h.children[0];const g=p.children.length;a+=g,i+=g}else o.children[a]=h.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return e}const Z=(n,t)=>{const e=y.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>$t(o,i,e,t,!0),e.exportProseMirrorFragment=o=>ct.unified().use(Ut.default,{fragment:!0}).use(wn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(Rt.default).processSync(Gt(o,e)).value,e.exportBlocks=o=>{const i=o.map(s=>N(s,n,t.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.exportProseMirrorFragment(y.Fragment.from(r))},e},ft=(n,t)=>{const e=y.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>$t(o,i,e,t,!1),e.serializeProseMirrorFragment=o=>Gt(o,e),e.serializeBlocks=o=>{const i=o.map(s=>N(s,n,t.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.serializeProseMirrorFragment(y.Fragment.from(r))},e},vn=async n=>{const t=new FormData;return t.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},Kt=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function V(n){return Kt()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(t=>t).join(" ")}const En=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function tt(n,t,e,o){const i=document.createElement("div");i.className=O("bn-block-content",e.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(e))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(t);r.className=O("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const jt=(n,t)=>{const e=N(n,t._tiptapEditor.schema,t.schema.styleSchema).firstChild,o=t._tiptapEditor.schema.nodes[e.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 i=o(e);if(typeof i!="object"||!("dom"in i))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 i},C={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},gt=["backgroundColor","textColor"];function et(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function bt(n){const t={};return Object.entries(n).filter(([e,o])=>!gt.includes(e)).forEach(([e,o])=>{t[e]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(et(e));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==o.default?{[et(e)]:i[e]}:{}}}),t}function Wt(n,t,e,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=e.state.doc.resolve(i).node().attrs.id,a=t.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function it(n,t,e,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=O("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",t);for(const[s,a]of Object.entries(e))!gt.includes(s)&&a!==o[s].default&&r.setAttribute(et(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function q(n){return b.Node.create(n)}function kt(n,t){return{config:n,implementation:t}}function j(n,t,e){return kt({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:t},{node:n,requiredExtensions:e,toInternalHTML:jt,toExternalHTML:jt})}function yt(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function Jt(n,t){const e=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return t&&e.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=t==null?void 0:t(o);return i===void 0?!1:i}}),e}function Xt(n,t){const e=q({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return bt(n.propSchema)},parseHTML(){return Jt(n,t.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=Wt(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=t.render(r,i);return it(a,r.type,r.props,n.propSchema,s)}}});if(e.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return kt(n,{node:e,toInternalHTML:(o,i)=>{var a;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{},s=t.render(o,i);return it(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=t.toExternalHTML)==null?void 0:l.call(t,o,i);return s===void 0&&(s=t.render(o,i)),it(s,o.type,o.props,n.propSchema,r)}})}function Yt(n,t,e,o){return n.dom.setAttribute("data-inline-content-type",t),Object.entries(e).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[et(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Qt(n){return{Backspace:({editor:t})=>{const e=t.state.selection.$from;return t.state.selection.empty&&e.node().type.name===n.type&&e.parentOffset===0}}}function Zt(n,t){return{config:n,implementation:t}}function te(n,t){return Zt({type:n.name,propSchema:t,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function wt(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function ee(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Sn(n,t){const e=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return bt(n.propSchema)},addKeyboardShortcuts(){return Qt(n)},parseHTML(){return ee(n)},renderHTML({node:o}){const i=this.options.editor,r=t.render(mt(o,i.schema.inlineContentSchema,i.schema.styleSchema));return Yt(r,n.type,o.attrs,n.propSchema)}});return te(e,n.propSchema)}function ne(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:t=>t.getAttribute("data-value"),renderHTML:t=>t.stringValue!==void 0?{"data-value":t.stringValue}:{}}}}function oe(n,t,e,o){return n.dom.setAttribute("data-style-type",t),o==="string"&&n.dom.setAttribute("data-value",e),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function vt(n,t){return{config:n,implementation:t}}function U(n,t){return vt({type:n.name,propSchema:t},{mark:n})}function Et(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function ie(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Cn(n,t){const e=b.Mark.create({name:n.type,addAttributes(){return ne(n.propSchema)},parseHTML(){return ie(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=t.render();else if(n.propSchema==="string")i=t.render(o.attrs.stringValue);else throw new L(n.propSchema);return oe(i,n.type,o.attrs.stringValue,n.propSchema)}});return vt(n,{mark:e})}const Tn=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),xn=U(Tn,"string"),Bn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Mn=U(Bn,"string"),A=n=>{const{contentType:t}=w(n.state.doc,n.state.selection.from);return t.spec.content},In={...C,level:{default:1,values:[1,2,3]}},Ln=q({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const t=n.getAttribute("data-level"),e=parseInt(t);if(isFinite(e))return e},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:e,range:o})=>{A(this.editor)==="inline*"&&e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.getAttribute("data-level")}},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:n,HTMLAttributes:t}){var e,o;return tt(this.name,`h${n.attrs.level}`,{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...t},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),Pn=j(Ln,In),Nn={textAlignment:C.textAlignment,backgroundColor:C.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},re=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},se=64,An=Xt({type:"image",propSchema:Nn,content:"none"},{render:(n,t)=>{const e=document.createElement("div");e.className="bn-image-block-content-wrapper",e.style.alignItems=re(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper";const a=document.createElement("div");a.className="bn-image-wrapper";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,t.domElement.firstElementChild.clientWidth)}px`;const c=document.createElement("div");c.className="bn-image-resize-handle",c.style.left="4px";const h=document.createElement("div");h.className="bn-image-resize-handle",h.style.right="4px";const p=document.createElement("p");p.className="bn-image-caption",p.innerText=n.props.caption,p.style.padding=n.props.caption?"4px":"";const f=()=>{var Ht;const v=((Ht=t.getSelection())==null?void 0:Ht.blocks)||[];[t.getTextCursorPosition().block,...v].find(lt=>lt.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};t.onEditorContentChange(f),t.onEditorSelectionChange(f);let m;const g=v=>{if(!m){!t.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h));return}let _;re(n.props.textAlignment)==="center"?m.handleUsed==="left"?_=m.initialWidth+(m.initialClientX-v.clientX)*2:_=m.initialWidth+(v.clientX-m.initialClientX)*2:m.handleUsed==="left"?_=m.initialWidth+m.initialClientX-v.clientX:_=m.initialWidth+v.clientX-m.initialClientX,_<se?l.style.width=`${se}px`:_>t.domElement.firstElementChild.clientWidth?l.style.width=`${t.domElement.firstElementChild.clientWidth}px`:l.style.width=`${_}px`},E=v=>{(!v.target||!a.contains(v.target)||!t.isEditable)&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h)),m&&(m=void 0,t.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},I=v=>{v.preventDefault()},D=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(t.imagePanel.plugin,{block:n}))},B=()=>{t.isEditable&&(a.appendChild(c),a.appendChild(h))},$=v=>{v.relatedTarget===c||v.relatedTarget===h||m||t.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h))},Y=v=>{v.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"left",initialWidth:n.props.width,initialClientX:v.clientX}},nt=v=>{v.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"right",initialWidth:n.props.width,initialClientX:v.clientX}};return o.appendChild(i),o.appendChild(r),s.appendChild(a),a.appendChild(l),s.appendChild(p),n.props.url===""?e.appendChild(o):e.appendChild(s),window.addEventListener("mousemove",g),window.addEventListener("mouseup",E),o.addEventListener("mousedown",I),o.addEventListener("click",D),l.addEventListener("mouseenter",B),l.addEventListener("mouseleave",$),c.addEventListener("mousedown",Y),h.addEventListener("mousedown",nt),{dom:e,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",E),o.removeEventListener("mousedown",I),o.removeEventListener("click",D),c.removeEventListener("mousedown",Y),h.removeEventListener("mousedown",nt)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const t=document.createElement("figure"),e=document.createElement("img");if(e.src=n.props.url,t.appendChild(e),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,t.appendChild(o)}return{dom:t}},parse:n=>{if(n.tagName==="FIGURE"){const t=n.querySelector("img"),e=n.querySelector("figcaption");return{url:(t==null?void 0:t.getAttribute("src"))||"",caption:(e==null?void 0:e.textContent)||(t==null?void 0:t.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),St=n=>{const{node:t,contentType:e}=w(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!(e.name==="bulletListItem"||e.name==="numberedListItem")||!o?!1:n.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>t.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>t.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},Hn={...C},Dn=q({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:t,range:e})=>{A(this.editor)==="inline*"&&t().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Shift-8":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),_n=j(Dn,Hn),On=new k.PluginKey("numbered-list-indexing"),Un=()=>new k.Plugin({key:On,appendTransaction:(n,t,e)=>{const o=e.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,c=w(o.doc,s+1);if(c===void 0)return;if(!l){const f=w(o.doc,s-2);if(f===void 0)return;if(!(c.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const D=g.attrs.index;a=(parseInt(D)+1).toString()}}}c.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),Rn={...C},zn=q({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:t,range:e})=>{A(this.editor)==="inline*"&&t().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Shift-7":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[Un()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="OL"||t.tagName==="DIV"&&t.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Fn=j(zn,Rn),Vn={...C},qn=q({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Alt-0":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"paragraph",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),$n=j(qn,Vn),Gn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[_t.columnResizing({cellMinWidth:100}),_t.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.setHardBreak(),!0):!1,Backspace:()=>{const n=this.editor.state.selection,t=n.empty,e=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return t&&e&&o}}},extendNodeSchema(n){const t={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",t))}}}),Kn={...C},jn=q({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"table",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Wn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Jn=j(jn,Kn,[Gn,Wn,qe.TableHeader.extend({content:"tableContent"}),Ve.TableCell.extend({content:"tableContent"}),$e.TableRow]),Ct={paragraph:$n,heading:Pn,bulletListItem:_n,numberedListItem:Fn,image:An,table:Jn},ae=yt(Ct),Tt={bold:U(on.default,"boolean"),italic:U(sn.default,"boolean"),underline:U(ln.default,"boolean"),strike:U(an.default,"boolean"),code:U(rn.default,"boolean"),textColor:Mn,backgroundColor:xn},Xn=Et(Tt),xt={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Yn=wt(xt);function P(n,t){return n in t.schema.blockSchema&&t.schema.blockSchema[n]===ae[n]}function Qn(n,t,e){return t.type===n&&t.type in e.schema.blockSchema&&P(t.type,e)}function le(n,t,e){return t in e.schema.blockSchema&&n in e.schema.blockSchema[t].propSchema&&e.schema.blockSchema[t].propSchema[n]===C[n]}function Zn(n,t,e){return le(n,t.type,e)}function Bt(n,t){let e,o;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(e=i,o=r+1,!1)),e===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:o}}function to(n,t,e="before",o){const i=o._tiptapEditor,r=typeof t=="string"?t:t.id,s=[];for(const h of n)s.push(N(h,i.schema,o.schema.styleSchema));const{node:a,posBeforeNode:l}=Bt(r,i.state.doc);if(e==="before"&&i.view.dispatch(i.state.tr.insert(l,s)),e==="after"&&i.view.dispatch(i.state.tr.insert(l+a.nodeSize,s)),e==="nested"&&a.childCount<2){const h=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(l+a.firstChild.nodeSize+1,h))}const c=[];for(const h of s)c.push(S(h,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache));return c}function eo(n,t,e){const o=e._tiptapEditor,i=typeof n=="string"?n:n.id,{posBeforeNode:r}=Bt(i,o.state.doc);o.commands.BNUpdateBlock(r+1,t);const s=o.state.doc.resolve(r+1).node();return S(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function ce(n,t,e){const o=t._tiptapEditor,i=o.state.tr,r=new Set(n.map(l=>typeof l=="string"?l:l.id)),s=[];let a=0;if(o.state.doc.descendants((l,c)=>{if(r.size===0)return!1;if(l.type.name!=="blockContainer"||!r.has(l.attrs.id))return!0;s.push(S(l,t.schema.blockSchema,t.schema.inlineContentSchema,t.schema.styleSchema,t.blockCache)),r.delete(l.attrs.id),a=(e==null?void 0:e(l,c,i,a))||a;const h=i.doc.nodeSize;i.delete(c-a-1,c-a+l.nodeSize+1);const p=i.doc.nodeSize;return a+=h-p,!1}),r.size>0){const l=[...r].join(`
|
|
6
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+l)}return o.view.dispatch(i),s}function no(n,t){return ce(n,t)}function oo(n,t,e){const o=e._tiptapEditor,i=[];for(const l of t)i.push(N(l,o.schema,e.schema.styleSchema));const r=typeof n[0]=="string"?n[0]:n[0].id,s=ce(n,e,(l,c,h,p)=>{if(l.attrs.id===r){const f=h.doc.nodeSize;h.insert(c,i);const m=h.doc.nodeSize;return p+f-m}return p}),a=[];for(const l of i)a.push(S(l,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return{insertedBlocks:a,removedBlocks:s}}function io(n,t,e,o={updateSelection:!0}){const i=e._tiptapEditor,r=i.state.tr;let{from:s,to:a}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},l=!0,c=!0,h="";if(t.forEach(p=>{p.check(),l&&p.isText&&p.marks.length===0?h+=p.text:l=!1,c=c?p.isBlock:!1}),s===a&&c){const{parent:p}=r.doc.resolve(s);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(s-=1,a+=1)}return l?r.insertText(h,s,a):r.replaceWith(s,a,t),o.updateSelection&&b.selectionToInsertionEnd(r,r.steps.length-1,-1),i.view.dispatch(r),!0}function ro(){const n=t=>{let e=t.children.length;for(let o=0;o<e;o++){const i=t.children[o];if(i.type==="element"&&(n(i),i.tagName==="u"))if(i.children.length>0){t.children.splice(o,1,...i.children);const r=i.children.length-1;e+=r,o+=r}else t.children.splice(o,1),e--,o--}};return n}function Mt(n){return ct.unified().use(Ut.default,{fragment:!0}).use(ro).use(cn.default).use(zt.default).use(dn.default).processSync(n).value}function so(n,t,e){const i=Z(t,e).exportBlocks(n);return Mt(i)}function ao(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function lo(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function co(n){n.querySelectorAll("li > ul, li > ol").forEach(t=>{const e=ao(t),o=t.parentElement,i=Array.from(o.childNodes).slice(e+1);t.remove(),i.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",t),i.reverse().forEach(r=>{if(lo(r))return;const s=document.createElement("li");s.append(r),t.insertAdjacentElement("afterend",s)}),o.childNodes.length===0&&o.remove()})}function uo(n){n.querySelectorAll("li + ul, li + ol").forEach(t=>{var r,s;const e=t.previousElementSibling,o=document.createElement("div");e.insertAdjacentElement("afterend",o),o.append(e);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),o.append(i);((r=o.nextElementSibling)==null?void 0:r.nodeName)==="UL"||((s=o.nextElementSibling)==null?void 0:s.nodeName)==="OL";)i.append(o.nextElementSibling)})}let de=null;function ho(){return de||(de=document.implementation.createHTMLDocument("title"))}function ue(n){if(typeof n=="string"){const t=ho().createElement("div");t.innerHTML=n,n=t}return co(n),uo(n),n}async function he(n,t,e,o,i){const r=ue(n),a=y.DOMParser.fromSchema(i).parse(r,{topNode:i.nodes.blockGroup.create()}),l=[];for(let c=0;c<a.childCount;c++)l.push(S(a.child(c),t,e,o));return l}function po(n,t){const e=t.value?t.value+`
|
|
7
|
+
`:"",o={};t.lang&&(o["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),n.patch(t,i),i=n.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(t,i),i}function mo(n,t,e,o,i){const r=ct.unified().use(un.default).use(zt.default).use(hn.default,{handlers:{...Ot.defaultHandlers,code:po}}).use(Rt.default).processSync(n);return he(r.value,t,e,o,i)}class W{constructor(){u(this,"callbacks",{})}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),()=>this.off(t,e)}emit(t,...e){const o=this.callbacks[t];o&&o.forEach(i=>i.apply(this,e))}off(t,e){const o=this.callbacks[t];o&&(e?this.callbacks[t]=o.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class pe{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({state:t})=>!t.selection.empty);u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragHandler),e.dom.addEventListener("dragover",this.dragHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var f,m;const{state:o,composing:i}=t,{doc:r,selection:s}=o,a=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,c=Math.min(...l.map(g=>g.$from.pos)),h=Math.max(...l.map(g=>g.$to.pos)),p=(f=this.shouldShow)==null?void 0:f.call(this,{view:t,state:o,from:c,to:h});if(this.editor.isEditable&&!this.preventShow&&(p||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((m=this.state)!=null&&m.show&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:o}=e,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const me=new k.PluginKey("FormattingToolbarPlugin");class fe extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:me,view:o=>(this.view=new pe(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class fo{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredLinkMark");u(this,"mouseHoveredLinkMarkRange");u(this,"keyboardHoveredLinkMark");u(this,"keyboardHoveredLinkMarkRange");u(this,"linkMark");u(this,"linkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=s,this.mouseHoveredLinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;this.linkMark!==void 0&&(t=this.state)!=null&&t.show&&(this.state.referencePos=b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editLink(t,e){var i;const o=this.pmView.state.tr.insertText(e,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.state)!=null&&i.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=i,this.keyboardHoveredLinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((e=this.state)!=null&&e.show&&t&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ge=new k.PluginKey("LinkToolbarPlugin");class be extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"editLink",(e,o)=>{this.view.editLink(e,o)});u(this,"deleteLink",()=>{this.view.deleteLink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new k.Plugin({key:ge,view:o=>(this.view=new fo(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}const go=b.findParentNode(n=>n.type.name==="blockContainer");class bo{constructor(t,e){u(this,"state");u(this,"emitUpdate");u(this,"pluginState");u(this,"handleScroll",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(R,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=t,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");e(o,this.state)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=R.getState(e),i=R.getState(t.state),r=o===void 0&&i!==void 0,s=o!==void 0&&i===void 0;if(!r&&!(o!==void 0&&i!==void 0)&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){document.removeEventListener("scroll",this.handleScroll)}}const R=new k.PluginKey("SuggestionMenuPlugin");class ke extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)});u(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==e)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new k.Plugin({key:R,view:()=>(this.view=new bo(e,(i,r)=>{this.emit(`update ${i}`,r)}),this.view),state:{init(){},apply(i,r,s,a){if(i.getMeta("orderedListIndexing")!==void 0)return r;const l=i.getMeta(R);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:a.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(a.selection.from!==a.selection.to||l===null||i.getMeta("focus")||i.getMeta("blur")||i.getMeta("pointer")||r.triggerCharacter!==void 0&&a.selection.from<r.queryStartPos)return;const c={...r};return c.query=a.doc.textBetween(r.queryStartPos,a.selection.from),c}},props:{handleKeyDown(i,r){const s=this.getState(i.state);return o.includes(r.key)&&s===void 0?(r.preventDefault(),i.dispatch(i.state.tr.insertText(r.key).scrollIntoView().setMeta(R,{triggerCharacter:r.key})),!0):!1},decorations(i){const r=this.getState(i);if(r===void 0)return null;if(!r.fromUserInput){const s=go(i.selection);if(s)return x.DecorationSet.create(i.doc,[x.Decoration.node(s.pos,s.pos+s.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return x.DecorationSet.create(i.doc,[x.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(e,o){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,o)}}function ko(n,t){n.suggestionMenus.addTriggerCharacter(t)}class J extends k.Selection{constructor(e,o){super(e,o);u(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(e,o,i=o){return new J(e.resolve(o),e.resolve(i))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof J)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?k.Selection.near(e.resolve(i.pos)):i.deleted?k.Selection.near(e.resolve(r.pos)):new J(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let z;function rt(n,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function yo(n,t){const e=rt(n,t);if(e&&e.node.nodeType===1){const o=t.docView,i=o.nearestDesc(e.node,!0);return!i||i===o?null:i.posBefore}return null}function wo(n,t){let e,o;const i=t.resolve(n.from).node().type.spec.group==="blockContent",r=t.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);e=t.resolve(a-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function ye(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),i=n.domAtPos(t).node,r=(h,p)=>Array.prototype.indexOf.call(h.children,p),s=r(i,n.domAtPos(t+1).node.parentElement),a=r(i,n.domAtPos(e-1).node.parentElement);for(let h=i.childElementCount-1;h>=0;h--)(h>a||h<s)&&o.removeChild(o.children[h]);we(),z=o;const c=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");z.className=z.className+" bn-drag-preview "+c,document.body.appendChild(z)}function we(){z!==void 0&&(document.body.removeChild(z),z=void 0)}function vo(n,t){if(!n.dataTransfer)return;const e=t.prosemirrorView,o=e.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=yo(i,e);if(r!=null){const s=e.state.selection,a=e.state.doc,{from:l,to:c}=wo(s,a),h=l<=r&&r<c,p=s.$anchor.node()!==s.$head.node()||s instanceof J;h&&p?(e.dispatch(e.state.tr.setSelection(J.create(a,l,c))),ye(e,l,c)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,r))),ye(e,r));const f=e.state.selection.content(),m=t._tiptapEditor.schema,E=ft(m,t).serializeProseMirrorFragment(f.content),D=Z(m,t).exportProseMirrorFragment(f.content),B=Mt(D);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",D),n.dataTransfer.setData("text/plain",B),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(z,0,0),e.dragging={slice:f,move:!0}}}class ve{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const o=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const o=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",t=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseDown",t=>{this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseMove",t=>{var c,h,p,f,m;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=o.left&&t.clientX<=o.right&&t.clientY>=o.top&&t.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},a=rt(s,this.pmView);if(!a||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.emitUpdate(this.state));return}if((p=this.state)!=null&&p.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.emitUpdate(this.state)}});u(this,"onScroll",()=>{var t;if((t=this.state)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)),document.body.removeEventListener("mousemove",this.onMouseMove,!0),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const i=w(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,startPos:s,endPos:a}=i;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=a+1,h=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(h).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(R,{triggerCharacter:"/",fromUserInput:!1}))}}const Ee=new k.PluginKey("SideMenuPlugin");class Se extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",e=>{this.view.isDragging=!0,vo(e,this.editor)});u(this,"blockDragEnd",()=>we());u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.view.menuFrozen=!1);this.editor=e,this.plugin=new k.Plugin({key:Ee,view:o=>(this.view=new ve(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class Ce{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"prevWasEditable",null);u(this,"mouseDownHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"dragstartHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"blurHandler",t=>{var o;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}});this.pluginKey=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image panel");o(this.state)},e.dom.addEventListener("mousedown",this.mouseDownHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var i,r;const o=this.pluginKey.getState(t.state);if(!((i=this.state)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const It=new k.PluginKey("ImagePanelPlugin");class Te extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:It,view:o=>(this.view=new Ce(It,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(It))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}let M;function xe(){M||(M=document.createElement("div"),M.innerHTML="_",M.style.opacity="0",M.style.height="1px",M.style.width="1px",document.body.appendChild(M))}function Eo(){M&&(document.body.removeChild(M),M=void 0)}function st(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function So(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Co(n){n.forEach(t=>{const e=document.getElementsByClassName(t);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"})}class Be{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",t=>{var c;if(this.menuFrozen)return;const e=So(t.target);if(!e||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=st(e),i=st(e.parentElement),r=e.getBoundingClientRect(),s=e.parentElement.parentElement.getBoundingClientRect(),a=rt(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((h,p)=>typeof l<"u"?!1:h.type.name!=="blockContainer"||h.attrs.id!==a.id?!0:(l=S(h,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache),this.tablePos=p+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",Co(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(e.left,e.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=st(i.parentElement),a=st(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,h=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const p=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==p&&(this.state.draggingState.mousePos=p,r=!0),r&&this.emitUpdate(),h&&this.pmView.dispatch(this.pmView.state.tr.setMeta(X,!0))});u(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const e=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=e[this.state.draggingState.originalIndex];e.splice(this.state.draggingState.originalIndex,1),e.splice(this.state.rowIndex,0,o)}else{const o=e.map(i=>i.cells[this.state.draggingState.originalIndex]);e.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:e}})});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=e.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=e.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const X=new k.PluginKey("TableHandlesPlugin");class Me extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="copyMove"});u(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,null)),Eo()});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=e,this.plugin=new k.Plugin({key:X,view:o=>(this.view=new Be(e,o,i=>{this.emit("update",i)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return x.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),c=l.node();for(let h=0;h<c.childCount;h++){const p=o.doc.resolve(l.posAtIndex(h)+1),f=p.node(),m=p.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(x.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const c=o.doc.resolve(s.posAtIndex(l)+1),h=o.doc.resolve(c.posAtIndex(i)+1),p=h.node(),f=h.pos+(i>this.view.state.draggingState.originalIndex?p.nodeSize-2:0);r.push(x.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return x.DecorationSet.create(o.doc,r)}}})}onUpdate(e){return this.on("update",e)}}function Ie(n,t){const e=n.state.selection.content().content,i=ft(n.state.schema,t).serializeProseMirrorFragment(e),s=Z(n.state.schema,t).exportProseMirrorFragment(e),a=Mt(s);return{internalHTML:i,externalHTML:s,plainText:a}}const To=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{copy(t,e){e.preventDefault(),e.clipboardData.clearData(),"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1))));const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.clipboardData.setData("blocknote/html",o),e.clipboardData.setData("text/html",i),e.clipboardData.setData("text/plain",r),!0},dragstart(t,e){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1)))),e.preventDefault(),e.dataTransfer.clearData();const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.dataTransfer.setData("blocknote/html",o),e.dataTransfer.setData("text/html",i),e.dataTransfer.setData("text/plain",r),!0}}}})]}}),xo=["blocknote/html","text/html","text/plain"],Bo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{paste(t,e){e.preventDefault();let o=null;for(const i of xo)if(e.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=e.clipboardData.getData(o);o==="text/html"&&(i=ue(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),Mo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:C.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):C.backgroundColor.default,renderHTML:n=>n.backgroundColor!==C.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),Io=new k.PluginKey("blocknote-placeholder"),Lo=b.Extension.create({name:"placeholder",addOptions(){return{placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",bulletListItem:"List",numberedListItem:"List"}}},addProseMirrorPlugins(){const n=this.options.placeholders;return[new k.Plugin({key:Io,view:()=>{const t=document.createElement("style");document.head.appendChild(t);const e=t.sheet,o=(r="")=>`.bn-block-content${r} .bn-inline-content:has(> .ProseMirror-trailingBreak):before`,i=(r,s=!0)=>{const a=s?"[data-is-empty-and-focused]":"";if(r==="default")return o(a);const l=`[data-content-type="${r}"]`;return o(a+l)};for(const[r,s]of Object.entries(n)){const a=r==="default";e.insertRule(`${i(r,a)}{ content: ${JSON.stringify(s)}; }`),a||e.insertRule(`${i(r,!0)}{ content: ${JSON.stringify(s)}; }`)}return{destroy:()=>{document.head.removeChild(t)}}},props:{decorations:t=>{const{doc:e,selection:o}=t;if(!this.editor.isEditable||!o.empty)return;const r=o.$anchor,s=r.parent;if(s.content.size>0)return null;const a=r.before(),l=x.Decoration.node(a,a+s.nodeSize,{"data-is-empty-and-focused":"true"});return x.DecorationSet.create(e,[l])}}})]}}),Po=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),No=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:C.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):C.textColor.default,renderHTML:n=>n.textColor!==C.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Ao=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,c=s.nodes.blockContainer,h=s.nodes.paragraph;if(a)return r.insert(l,c.create(void 0,h.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Ho=new k.PluginKey("non-editable-block"),Do=()=>new k.Plugin({key:Ho,props:{handleKeyDown:(n,t)=>{"node"in n.state.selection&&t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&!t.shiftKey&&t.preventDefault()}}}),Le=new k.PluginKey("previous-blocks"),_o={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Oo=()=>{let n;return new k.Plugin({key:Le,view(t){return{update:async(e,o)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(Le,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(i.doc))return e;const r={},s=b.findChildren(o.doc,c=>c.attrs.id),a=new Map(s.map(c=>[c.node.attrs.id,c])),l=b.findChildren(i.doc,c=>c.attrs.id);for(const c of l){const h=a.get(c.node.attrs.id),p=h==null?void 0:h.node.firstChild,f=c.node.firstChild;if(h&&p&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(c.pos).depth};let g={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:o.doc.resolve(h.pos).depth};r[c.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(c.node.attrs.id in e.prevTransactionOldBlockAttrs&&(g=e.prevTransactionOldBlockAttrs[c.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),e.currentTransactionOldBlockAttrs[c.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,e.updatedBlocks.add(c.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[c,h]of Object.entries(s))a["data-prev-"+_o[c]]=h||"none";const l=x.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),x.DecorationSet.create(t.doc,o)}}})},Uo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ro=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(Uo))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){var i;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);const e={...((i=this.options.domAttributes)==null?void 0:i.block)||{},...n},o=document.createElement("div");o.className=O("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(e))r!=="class"&&o.setAttribute(r,s);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=w(t.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(t.children!==void 0){const f=[];for(const m of t.children)f.push(N(m,e.schema,this.options.editor.schema.styleSchema));a.childCount===2?e.tr.replace(r+l.nodeSize+1,s-1,new y.Slice(y.Fragment.from(f),0,0)):e.tr.insert(r+l.nodeSize,e.schema.nodes.blockGroup.create({},f))}const c=l.type.name,h=t.type||c;let p="keep";if(t.content)if(typeof t.content=="string")p=[e.schema.text(t.content)];else if(Array.isArray(t.content))p=Q(t.content,e.schema,this.options.editor.schema.styleSchema);else if(t.content.type==="tableContent")p=pt(t.content,e.schema,this.options.editor.schema.styleSchema);else throw new L(t.content.type);else{const f=e.schema.nodes[c].spec.content,m=e.schema.nodes[h].spec.content;f===""||m!==f&&(p=[])}p==="keep"?e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...l.attrs,...t.props}):e.tr.replaceWith(r,s,e.schema.nodes[h].create({...l.attrs,...t.props},p)).setSelection(e.schema.nodes[h].spec.content===""?new k.NodeSelection(e.tr.doc.resolve(r)):e.schema.nodes[h].spec.content==="inline*"?new k.TextSelection(e.tr.doc.resolve(r)):new k.TextSelection(e.tr.doc.resolve(r+4))),e.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",i=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=w(t.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:c,depth:h}=r;if(s.childCount===2){const m=t.doc.resolve(l+a.nodeSize+1),g=t.doc.resolve(c-1),E=m.blockRange(g);e&&t.tr.lift(E,h-1)}let p=n-1,f=w(t.doc,p);for(;f.numChildBlocks>0;)if(p--,f=w(t.doc,p),f===void 0)return!1;return e&&(e(t.tr.deleteRange(l,l+a.nodeSize).replace(p-1,l,new y.Slice(a.content,0,0)).scrollIntoView()),t.tr.setSelection(new k.TextSelection(t.doc.resolve(p-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:c}=i,h=e.doc.cut(a+1,n),p=e.doc.cut(n,l-1),f=e.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(e.tr.insert(m,f),e.tr.replace(g,g+1,p.content.size>0?new y.Slice(y.Fragment.from(p),c+2,c+2):void 0),t&&e.tr.setBlockType(g,g,e.schema.node(s).type,r.attrs),e.tr.setSelection(new k.TextSelection(e.doc.resolve(g))),e.tr.replace(a+1,l-1,h.content.size>0?new y.Slice(y.Fragment.from(h),c+2,c+2):void 0)),!0}}},addProseMirrorPlugins(){return[Oo(),Do()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=w(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,c=s===2,h=s-1;return!c&&a&&l&&r===2?o.BNMergeBlocks(h):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=w(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,c=i.selection.from===a-1,h=i.selection.empty,p=r.childCount===2;if(!l&&c&&h&&!p){let f=s,m=a+2,g=i.doc.resolve(m).depth;for(;g<f;)f=g,m+=2,g=i.doc.resolve(m).depth;return o.BNMergeBlocks(m-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,c=r.textContent.length===0,h=s>2;return a&&l&&c&&h?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=w(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,c=i.selection.anchor===i.selection.head,h=s.textContent.length===0;if(l&&c&&h){const p=a+1,f=p+2;return r().BNCreateBlock(p).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0)}}}),zo=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=O("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(t))i!=="class"&&e.setAttribute(i,r);return{dom:e,contentDOM:e}}}),Fo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Pe=n=>{var e;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Qe.Gapcursor,Lo.configure({...n.placeholders!==void 0?{placeholders:n.placeholders}:{}}),G.configure({types:["blockContainer"]}),Ze.HardBreak,nn.Text,en.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),No,Mo,Po,Fo,Ro.configure({editor:n.editor,domAttributes:n.domAttributes}),zo.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),To(n.editor),Bo(n.editor),Ye.Dropcursor.configure({width:5,color:"#ddeeff"}),Ao];if(n.collaboration){if(t.push(pn.default.configure({fragment:n.collaboration.fragment})),(e=n.collaboration.provider)!=null&&e.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};t.push(mn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else t.push(tn.History);return t};function Vo(n,t){const e=[];return n.forEach((o,i,r)=>{r!==t&&e.push(o)}),y.Fragment.from(e)}function qo(n,t){let e=y.Fragment.from(n.content);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const i=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.spec.group==="blockGroup"){const s=e.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(e.child(o+1)),e=Vo(e,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,i);e=e.replaceChild(o,r)}return new y.Slice(e,n.openStart,n.openEnd)}class at{constructor(t){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=(t==null?void 0:t.blockSpecs)||Ct,this.inlineContentSpecs=(t==null?void 0:t.inlineContentSpecs)||xt,this.styleSpecs=(t==null?void 0:t.styleSpecs)||Tt,this.blockSchema=yt(this.blockSpecs),this.inlineContentSchema=wt(this.inlineContentSpecs),this.styleSchema=Et(this.styleSpecs)}static create(t){return new at(t)}}class $o extends b.Editor{constructor(e,o){super({...e,content:void 0});u(this,"_state");u(this,"mount",e=>{e?(this.options.element=e,this.createViewAlternative()):this.destroy()});const i=this.schema;let r;const s=i.nodes.doc.createAndFill;i.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=s.apply(i.nodes.doc,l),h=JSON.parse(JSON.stringify(c.toJSON()));return h.content[0].content[0].attrs.id="initialBlockId",r=y.Node.fromJSON(i,h),r};let a;try{const l=e==null?void 0:e.content.map(c=>N(c,this.schema,o).toJSON());a=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(e.content))}this._state=k.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new x.EditorView(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const e=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(e),this.createNodeViews()})}}const Zo="",ti="",Go={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Lt{constructor(t){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"linkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"imagePanel");u(this,"tableHandles");u(this,"uploadFile");var l,c,h,p,f,m,g,E;this.options=t;const e=t;if(e.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(e.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(e.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(e.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");const o={defaultStyles:!0,schema:t.schema||at.create(),...t};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new fe(this),this.linkToolbar=new be(this),this.sideMenu=new Se(this),this.suggestionMenus=new ke(this),P("image",this)&&(this.imagePanel=new Te(this)),P("table",this)&&(this.tableHandles=new Me(this));const i=Pe({editor:this,placeholders:o.placeholders,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.linkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.imagePanel?[this.imagePanel.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[]]});i.push(r),this.uploadFile=o.uploadFile,o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const s=o.initialContent||(t.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:G.options.generateID()}]);if(!Array.isArray(s)||s.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+s);const a={...Go,...o._tiptapOptions,content:s,extensions:o.enableBlockNoteExtensions===!1?((l=o._tiptapOptions)==null?void 0:l.extensions)||[]:[...((c=o._tiptapOptions)==null?void 0:c.extensions)||[],...i],editorProps:{...(h=o._tiptapOptions)==null?void 0:h.editorProps,attributes:{...(f=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:f.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:O("bn-editor",o.defaultStyles?"bn-default-styles":"",((E=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:E.class)||"")},transformPasted:qo}};this._tiptapEditor=new $o(a,this.schema.styleSchema)}static create(t={}){return new Lt(t)}mount(t){this._tiptapEditor.mount(t)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){return this.topLevelBlocks}get document(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(S(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(o=S(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.document.slice();e&&o.reverse();function i(r){for(const s of r){if(!t(s))return!1;const a=e?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:i}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(e-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:S(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:S(a,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:S(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:i}=Bt(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=w(this._tiptapEditor.state.doc,i+2),a=this.schema.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")e==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new L(a)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((e,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(S(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){return to(t,e,o,this)}updateBlock(t,e){return eo(t,e,this)}removeBlocks(t){return no(t,this)}replaceBlocks(t,e){return oo(t,e,this)}insertInlineContent(t){const e=Q(t,this._tiptapEditor.schema,this.schema.styleSchema);io({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},e,this)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks();for(const o of e){const i=this.schema.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=o.attrs.stringValue}return t}addStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new L(i.propSchema)}}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new L(i.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,e){if(t==="")return;const{from:o,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,i).addMark(o,o+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.document){return Z(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return he(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.document){return so(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return mo(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}onChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("update",e),()=>{this._tiptapEditor.off("update",e)}}onSelectionChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("selectionUpdate",e),()=>{this._tiptapEditor.off("selectionUpdate",e)}}}function Ko(n){let t=n.getTextCursorPosition().block,e=n.schema.blockSchema[t.type].content;for(;e==="none";)t=n.getTextCursorPosition().nextBlock,e=n.schema.blockSchema[t.type].content,n.setTextCursorPosition(t,"end")}function H(n,t){const e=n.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(e.content)&&(e.content.length===1&&K(e.content[0])&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0)?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return Ko(n),o}function jo(n){const t=[];return P("heading",n)&&t.push({title:"Heading 1",onItemClick:()=>{H(n,{type:"heading",props:{level:1}})},subtext:"Used for a top-level heading",badge:V("Mod-Alt-1"),aliases:["h","heading1","h1"],group:"Headings"},{title:"Heading 2",onItemClick:()=>{H(n,{type:"heading",props:{level:2}})},subtext:"Used for key sections",badge:V("Mod-Alt-2"),aliases:["h2","heading2","subheading"],group:"Headings"},{title:"Heading 3",onItemClick:()=>{H(n,{type:"heading",props:{level:3}})},subtext:"Used for subsections and group headings",badge:V("Mod-Alt-3"),aliases:["h3","heading3","subheading"],group:"Headings"}),P("numberedListItem",n)&&t.push({title:"Numbered List",onItemClick:()=>{H(n,{type:"numberedListItem"})},subtext:"Used to display a numbered list",badge:V("Mod-Shift-7"),aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"}),P("bulletListItem",n)&&t.push({title:"Bullet List",onItemClick:()=>{H(n,{type:"bulletListItem"})},subtext:"Used to display an unordered list",badge:V("Mod-Shift-8"),aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"}),P("paragraph",n)&&t.push({title:"Paragraph",onItemClick:()=>{H(n,{type:"paragraph"})},subtext:"Used for the body of your document",badge:V("Mod-Alt-0"),aliases:["p","paragraph"],group:"Basic blocks"}),P("table",n)&&t.push({title:"Table",onItemClick:()=>{H(n,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},subtext:"Used for for tables",aliases:["table"],group:"Advanced",badge:void 0}),P("image",n)&&t.push({title:"Image",onItemClick:()=>{const e=H(n,{type:"image"});n.prosemirrorView.dispatch(n._tiptapEditor.state.tr.setMeta(n.imagePanel.plugin,{block:e}))},subtext:"Insert an image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],group:"Media"}),t}function Wo(n,t){return n.filter(({title:e,aliases:o})=>e.toLowerCase().startsWith(t.toLowerCase())||o&&o.filter(i=>i.toLowerCase().startsWith(t.toLowerCase())).length!==0)}function Pt(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function Ne(n){return typeof n=="string"?Pt(n):Array.isArray(n)?n.flatMap(t=>typeof t=="string"?Pt(t):ut(t)?{...t,content:Pt(t.content)}:K(t)?t:{props:{},...t,content:Ne(t.content)}):n}function Jo(n,t){return t.map(e=>Nt(n,e))}function Nt(n,t){const e={id:"",type:t.type,props:{},content:n[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(n[t.type].propSchema).forEach(([o,i])=>{e.props[o]===void 0&&(e.props[o]=i.default)}),{...e,content:Ne(e.content),children:e.children.map(o=>Nt(n,o))}}function Ae(n){n.id||(n.id=G.options.generateID()),n.children&&He(n.children)}function He(n){for(const t of n)Ae(t)}d.BlockNoteEditor=Lt,d.BlockNoteSchema=at,d.FormattingToolbarProsemirrorPlugin=fe,d.FormattingToolbarView=pe,d.ImagePanelProsemirrorPlugin=Te,d.ImagePanelView=Ce,d.LinkToolbarProsemirrorPlugin=be,d.SideMenuProsemirrorPlugin=Se,d.SideMenuView=ve,d.SuggestionMenuProseMirrorPlugin=ke,d.TableHandlesProsemirrorPlugin=Me,d.TableHandlesView=Be,d.UniqueID=G,d.UnreachableCaseError=L,d.addIdsToBlock=Ae,d.addIdsToBlocks=He,d.addInlineContentAttributes=Yt,d.addInlineContentKeyboardShortcuts=Qt,d.addStyleAttributes=oe,d.blockToNode=N,d.camelToDataKebab=et,d.checkBlockHasDefaultProp=Zn,d.checkBlockIsDefaultType=Qn,d.checkBlockTypeHasDefaultProp=le,d.checkDefaultBlockTypeInSchema=P,d.contentNodeToInlineContent=ot,d.createBlockSpec=Xt,d.createBlockSpecFromStronglyTypedTiptapNode=j,d.createExternalHTMLExporter=Z,d.createInlineContentSpec=Sn,d.createInlineContentSpecFromTipTapNode=te,d.createInternalBlockSpec=kt,d.createInternalHTMLSerializer=ft,d.createInternalInlineContentSpec=Zt,d.createInternalStyleSpec=vt,d.createStronglyTypedTiptapNode=q,d.createStyleSpec=Cn,d.createStyleSpecFromTipTapMark=U,d.createSuggestionMenu=ko,d.defaultBlockSchema=ae,d.defaultBlockSpecs=Ct,d.defaultInlineContentSchema=Yn,d.defaultInlineContentSpecs=xt,d.defaultProps=C,d.defaultStyleSchema=Xn,d.defaultStyleSpecs=Tt,d.filterSuggestionItems=Wo,d.formatKeyboardShortcut=V,d.formattingToolbarPluginKey=me,d.getBlockFromPos=Wt,d.getBlockNoteExtensions=Pe,d.getBlockSchemaFromSpecs=yt,d.getDefaultSlashMenuItems=jo,d.getDraggableBlockFromCoords=rt,d.getInlineContentParseRules=ee,d.getInlineContentSchemaFromSpecs=wt,d.getParseRules=Jt,d.getStyleParseRules=ie,d.getStyleSchemaFromSpecs=Et,d.inheritedProps=gt,d.inlineContentToNodes=Q,d.insertOrUpdateBlock=H,d.isAppleOS=Kt,d.isLinkInlineContent=dt,d.isPartialLinkInlineContent=ut,d.isSafari=En,d.isStyledTextInlineContent=K,d.linkToolbarPluginKey=ge,d.mergeCSSClasses=O,d.nodeToBlock=S,d.nodeToCustomInlineContent=mt,d.partialBlockToBlockForTesting=Nt,d.partialBlocksToBlocksForTesting=Jo,d.propsToAttributes=bt,d.sideMenuPluginKey=Ee,d.stylePropsToAttributes=ne,d.suggestionMenuPluginKey=R,d.tableContentToNodes=pt,d.tableHandlesPluginKey=X,d.uploadToTmpFilesDotOrg_DEV_ONLY=vn,d.wrapInBlockStructure=it,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|