@blocknote/core 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -17
- package/dist/blocknote.js +1611 -1408
- 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 +8 -4
- package/src/api/blockManipulation/blockManipulation.test.ts +19 -15
- package/src/api/blockManipulation/blockManipulation.ts +107 -17
- package/src/api/exporters/html/externalHTMLExporter.ts +3 -7
- package/src/api/exporters/html/htmlConversion.test.ts +6 -3
- package/src/api/exporters/html/internalHTMLSerializer.ts +3 -7
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +3 -3
- package/src/api/exporters/markdown/markdownExporter.test.ts +7 -3
- package/src/api/exporters/markdown/markdownExporter.ts +2 -6
- package/src/api/nodeConversions/nodeConversions.test.ts +14 -7
- package/src/api/nodeConversions/nodeConversions.ts +1 -2
- package/src/api/parsers/html/parseHTML.test.ts +5 -1
- package/src/api/parsers/html/parseHTML.ts +2 -6
- package/src/api/parsers/html/util/nestedLists.ts +11 -1
- package/src/api/parsers/markdown/parseMarkdown.test.ts +3 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +2 -6
- package/src/api/testUtil/cases/customBlocks.ts +18 -16
- package/src/api/testUtil/cases/customInlineContent.ts +12 -13
- package/src/api/testUtil/cases/customStyles.ts +12 -10
- package/src/api/testUtil/index.ts +4 -2
- package/src/api/testUtil/partialBlockTestUtil.ts +2 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +1 -2
- package/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +8 -1
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +13 -0
- package/src/blocks/defaultBlockHelpers.ts +3 -3
- package/src/blocks/defaultBlockTypeGuards.ts +84 -0
- package/src/blocks/defaultBlocks.ts +29 -3
- package/src/editor/Block.css +2 -31
- package/src/editor/BlockNoteEditor.ts +219 -263
- package/src/editor/BlockNoteExtensions.ts +5 -2
- package/src/editor/BlockNoteSchema.ts +98 -0
- package/src/editor/BlockNoteTipTapEditor.ts +162 -0
- package/src/editor/cursorPositionTypes.ts +2 -6
- package/src/editor/editor.css +0 -1
- package/src/editor/selectionTypes.ts +2 -6
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +22 -29
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +26 -27
- package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +45 -51
- package/src/extensions/Placeholder/PlaceholderExtension.ts +81 -88
- package/src/extensions/SideMenu/SideMenuPlugin.ts +55 -56
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +8 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +353 -0
- package/src/extensions/{SlashMenu/defaultSlashMenuItems.ts → SuggestionMenu/getDefaultSlashMenuItems.ts} +119 -89
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +62 -45
- package/src/extensions-shared/UiElementPosition.ts +4 -0
- package/src/index.ts +6 -6
- package/src/pm-nodes/BlockContainer.ts +5 -9
- package/src/schema/blocks/types.ts +15 -15
- package/src/schema/inlineContent/createSpec.ts +2 -2
- package/src/schema/inlineContent/types.ts +1 -1
- package/src/util/browser.ts +6 -4
- package/src/util/typescript.ts +7 -4
- package/types/src/api/blockManipulation/blockManipulation.d.ts +6 -1
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +2 -1
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +2 -1
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +2 -1
- package/types/src/api/nodeConversions/nodeConversions.d.ts +2 -1
- package/types/src/api/parsers/html/parseHTML.d.ts +2 -1
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -1
- package/types/src/api/testUtil/cases/customBlocks.d.ts +72 -13
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +281 -6
- package/types/src/api/testUtil/cases/customStyles.d.ts +247 -13
- package/types/src/api/testUtil/index.d.ts +4 -2
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +2 -1
- package/types/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +6 -1
- package/types/src/blocks/defaultBlockHelpers.d.ts +2 -2
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +24 -0
- package/types/src/blocks/defaultBlocks.d.ts +21 -15
- package/types/src/editor/BlockNoteEditor.d.ts +48 -53
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
- package/types/src/editor/BlockNoteSchema.d.ts +34 -0
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +28 -0
- package/types/src/editor/cursorPositionTypes.d.ts +2 -1
- package/types/src/editor/selectionTypes.d.ts +2 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -6
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +2 -2
- package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +15 -14
- package/types/src/extensions/Placeholder/PlaceholderExtension.d.ts +2 -15
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +8 -7
- package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +8 -0
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +31 -0
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +10 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +7 -7
- package/types/src/extensions-shared/UiElementPosition.d.ts +4 -0
- package/types/src/index.d.ts +6 -6
- package/types/src/pm-nodes/BlockContainer.d.ts +3 -2
- package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
- package/types/src/schema/blocks/types.d.ts +15 -15
- package/types/src/schema/inlineContent/types.d.ts +1 -1
- package/types/src/util/browser.d.ts +1 -0
- package/types/src/util/typescript.d.ts +1 -0
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +0 -12
- package/src/extensions/SlashMenu/SlashMenuPlugin.ts +0 -53
- package/src/extensions-shared/BaseUiElementTypes.ts +0 -8
- package/src/extensions-shared/README.md +0 -3
- package/src/extensions-shared/suggestion/SuggestionItem.ts +0 -3
- package/src/extensions-shared/suggestion/SuggestionPlugin.ts +0 -448
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +0 -7
- package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +0 -13
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +0 -3
- package/types/src/extensions-shared/BaseUiElementTypes.d.ts +0 -7
- package/types/src/extensions-shared/suggestion/SuggestionItem.d.ts +0 -3
- package/types/src/extensions-shared/suggestion/SuggestionPlugin.d.ts +0 -36
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-100.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-100.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-200.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-200.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-300.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-300.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-500.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-500.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-600.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-600.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-700.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-700.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-800.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-800.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-900.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-900.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-regular.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-regular.woff2 +0 -0
- /package/src/{assets/fonts-inter.css → fonts/inter.css} +0 -0
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`?e.nodes.hardBreak.create():e.text(i,o))}function
|
|
3
|
-
`;else if(
|
|
1
|
+
(function(d,k){typeof exports=="object"&&typeof module<"u"?k(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"],k):(d=typeof globalThis<"u"?globalThis:d||self,k(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,k,z,At,le,b,y,Dt,Ae,_t,Ot,Ut,Rt,zt,Ft,Vt,qt,De,$t,Gt,Kt,jt,_e,x,Wt,Jt,Xt,Yt,Qt,Zt,en,tn){"use strict";var Jo=Object.defineProperty;var Xo=(d,k,z)=>k in d?Jo(d,k,{enumerable:!0,configurable:!0,writable:!0,value:z}):d[k]=z;var u=(d,k,z)=>(Xo(d,typeof k!="symbol"?k+"":k,z),z);const T=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},Oe=T(z),Ue=T(At),nn=T(_t),on=T(Ot),rn=T(Ut),sn=T(Rt),an=T(zt),ln=T($t),Re=T(Gt),cn=T(Kt),dn=T(jt),un=T(_e),hn=T(Wt),pn=T(Jt);function mn(n,e=JSON.stringify){const t={};return n.filter(o=>{const i=e(o);return Object.prototype.hasOwnProperty.call(t,i)?!1:t[i]=!0})}function fn(n){const e=n.filter((o,i)=>n.indexOf(o)!==i);return mn(e)}const $=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 Dt.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,e=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(t,o,i)=>{const r=t.some(g=>g.docChanged)&&!o.doc.eq(i.doc),s=this.options.filterTransaction&&t.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,t),{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),A=fn(I);E.forEach(({node:B,pos:q})=>{let X;const te=(X=a.doc.nodeAt(q))===null||X===void 0?void 0:X.attrs[c];if(te===null){const Le=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(Le)===null){const ae=JSON.parse(JSON.stringify(i.doc.toJSON()));if(ae.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(ae.content)===JSON.stringify(Le.toJSON())){a.setNodeMarkup(q,void 0,{...B.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(q,void 0,{...B.attrs,[c]:h()});return}const{deleted:w}=f.invert().mapResult(q);w&&A.includes(te)&&a.setNodeMarkup(q,void 0,{...B.attrs,[c]:h()})})}),!!a.steps.length)return a},view(t){const o=i=>{let r;n=!((r=t.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let i;return(n!==t.dom.parentElement||((i=o.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;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)}),k.Fragment.from(a)};return e=!1,new k.Slice(r(t.content),t.openStart,t.openEnd)}}})]}});function ze(n){const e=n.attrs.id,t=n.firstChild,o=t.type,i=n.childCount===2?n.lastChild.childCount:0;return{id:e,node:n,contentNode:t,contentType:o,numChildBlocks:i}}function v(n,e){const o=n.nodeSize-2;if(e<=1)for(e=1+1;n.resolve(e).parent.type.name!=="blockContainer"&&e<o;)e++;else if(e>=o)for(e=o-1;n.resolve(e).parent.type.name!=="blockContainer"&&e>1;)e--;n.resolve(e).parent.type.name==="blockGroup"&&e++;const i=n.resolve(e),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}=ze(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 ce(n){return n.type==="link"}function de(n){return typeof n!="string"&&n.type==="link"}function G(n){return typeof n!="string"&&n.type==="text"}class P extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function Fe(n,e,t){const o=[];for(const[i,r]of Object.entries(n.styles)){const s=t[i];if(!s)throw new Error(`style ${i} not found in styleSchema`);if(s.propSchema==="boolean")o.push(e.mark(i));else if(s.propSchema==="string")o.push(e.mark(i,{stringValue:r}));else throw new P(s.propSchema)}return n.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
|
|
2
|
+
`?e.nodes.hardBreak.create():e.text(i,o))}function gn(n,e,t){const o=e.marks.link.create({href:n.href});return ue(n.content,e,t).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 ue(n,e,t){const o=[];if(typeof n=="string")return o.push(...Fe({type:"text",text:n,styles:{}},e,t)),o;for(const i of n)o.push(...Fe(i,e,t));return o}function Y(n,e,t){const o=[];for(const i of n)typeof i=="string"?o.push(...ue(i,e,t)):de(i)?o.push(...gn(i,e,t)):G(i)?o.push(...ue([i],e,t)):o.push(Ve(i,e,t));return o}function he(n,e,t){const o=[];for(const i of n.rows){const r=[];for(const a of i.cells){let l;if(!a)l=e.nodes.tableParagraph.create({});else if(typeof a=="string")l=e.nodes.tableParagraph.create({},e.text(a));else{const h=Y(a,e,t);l=e.nodes.tableParagraph.create({},h)}const c=e.nodes.tableCell.create({},l);r.push(c)}const s=e.nodes.tableRow.create({},r);o.push(s)}return o}function Ve(n,e,t){let o,i=n.type;if(i===void 0&&(i="paragraph"),!e.nodes[i])throw new Error(`node type ${i} not found in schema`);if(!n.content)o=e.nodes[i].create(n.props);else if(typeof n.content=="string")o=e.nodes[i].create(n.props,e.text(n.content));else if(Array.isArray(n.content)){const r=Y(n.content,e,t);o=e.nodes[i].create(n.props,r)}else if(n.content.type==="tableContent"){const r=he(n.content,e,t);o=e.nodes[i].create(n.props,r)}else throw new P(n.content.type);return o}function L(n,e,t){let o=n.id;o===void 0&&(o=$.options.generateID());const i=Ve(n,e,t),r=[];if(n.children)for(const a of n.children)r.push(L(a,e,t));const s=e.nodes.blockGroup.create({},r);return e.nodes.blockContainer.create({id:o,...n.props},r.length>0?[i,s]:i)}function bn(n,e,t){const o={type:"tableContent",rows:[]};return n.content.forEach(i=>{const r={cells:[]};i.content.forEach(s=>{r.cells.push(ne(s.firstChild,e,t))}),o.rows.push(r)}),o}function ne(n,e,t){const o=[];let i;return n.content.forEach(r=>{if(r.type.name==="hardBreak"){if(i)if(G(i))i.text+=`
|
|
3
|
+
`;else if(ce(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(he(r,e,t));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const d=t[l.type.name];if(!d)throw new Error(`style ${l.type.name} not found in styleSchema`);if(d.propSchema==="boolean")s[d.type]=!0;else if(d.propSchema==="string")s[d.type]=l.attrs.stringValue;else throw new D(d.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}):de(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 he(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 d=i.propSchema;a in d&&(o[a]=l)}let r;return i.content==="styled"?r=oe(n,e,t):r=void 0,{type:n.type.name,props:o,content:r}}function I(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=Re(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 T=e[s.contentType.name];if(!T)throw Error("Block is of an unrecognized type: "+s.contentType.name);const M=T.propSchema;m in M&&(l[m]=g)}const d=e[s.contentType.name],c=[];for(let m=0;m<s.numChildBlocks;m++)c.push(I(n.lastChild.child(m),e,t,o,i));let h;if(d.content==="inline")h=oe(s.contentNode,t,o);else if(d.content==="table")h=gn(s.contentNode,t,o);else if(d.content==="none")h=void 0;else throw new D(d.content);const f={id:a,type:d.type,props:l,content:h,children:c};return i==null||i.set(n,f),f}function bn(n){return n.document||window.document}const Ve=(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}=y.DOMSerializer.renderSpec(bn(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 d=o.blockImplementations[a.type.name].implementation,h=(i?d.toExternalHTML:d.toInternalHTML)(I(n,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache),o);if(h.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");h.contentDOM.appendChild(t.serializeFragment(a.content,e))}s.appendChild(h.dom)}l!==void 0&&t.serializeFragment(y.Fragment.from(l),e,s)}else t.serializeFragment(n.content,e,s)}return r},Ue=(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 d=o.children[a].children[0],c=d.children[0],h=d.children.length===2?d.children[1]:null,f=e.has(c.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(c.properties.dataContentType)?"ol":"ul":null;if(h!==null&&t(h),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=Le.fromDom(document.createElement(m)));const g=Le.fromDom(document.createElement("li"));g.children.push(c.children[0]),h!==null&&g.children.push(...h.children),r.children.push(g)}else if(h!==null){o.children.splice(a+1,0,...h.children),o.children[a]=c.children[0];const g=h.children.length;a+=g,i+=g}else o.children[a]=c.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return t}const Z=(n,e)=>{const t=y.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>Ve(o,i,t,e,!0),t.exportProseMirrorFragment=o=>le.unified().use(De.default,{fragment:!0}).use(kn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(_e.default).processSync(Ue(o,t)).value,t.exportBlocks=o=>{const i=o.map(s=>_(s,n,e.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.exportProseMirrorFragment(y.Fragment.from(r))},t},me=(n,e)=>{const t=y.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>Ve(o,i,t,e,!1),t.serializeProseMirrorFragment=o=>Ue(o,t),t.serializeBlocks=o=>{const i=o.map(s=>_(s,n,e.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.serializeProseMirrorFragment(y.Fragment.from(r))},t},yn=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/")},qe=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function Sn(n){return qe()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(e=>e).join(" ")}function Q(n,e,t,o){const i=document.createElement("div");i.className=O("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=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 $e=(n,e)=>{const t=_(n,e._tiptapEditor.schema,e.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},H={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 Ge(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 ie(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=O("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=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function U(n){return b.Node.create(n)}function be(n,e){return{config:n,implementation:e}}function j(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:$e,toExternalHTML:$e})}function ke(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function je(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 Ke(n,e){const t=U({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return ge(n.propSchema)},parseHTML(){return je(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=Ge(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=e.render(r,i);return ie(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 ie(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)),ie(s,o.type,o.props,n.propSchema,r)}})}function We(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 Xe(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 Je(n,e){return{config:n,implementation:e}}function Ye(n,e){return Je({type:n.name,propSchema:e,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function ye(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function Ze(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 wn(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 Xe(n)},parseHTML(){return Ze(n)},renderHTML({node:o}){const i=this.options.editor,r=e.render(he(o,i.inlineContentSchema,i.styleSchema));return We(r,n.type,o.attrs,n.propSchema)}});return Ye(t,n.propSchema)}function Qe(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 et(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 Se(n,e){return{config:n,implementation:e}}function R(n,e){return Se({type:n.name,propSchema:e},{mark:n})}function we(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function tt(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 vn(n,e){const t=b.Mark.create({name:n.type,addAttributes(){return Qe(n.propSchema)},parseHTML(){return tt(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 D(n.propSchema);return et(i,n.type,o.attrs.stringValue,n.propSchema)}});return Se(n,{mark:t})}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]}}),En=R(Tn,"string"),Cn=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=R(Cn,"string"),xn={...H,level:{default:1,values:[1,2,3]}},Bn=U({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 Q(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)||{})}}),In=j(Bn,xn);class K{constructor(){p(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 nt{constructor(e,t,o){p(this,"imageToolbarState");p(this,"updateImageToolbar");p(this,"prevWasEditable",null);p(this,"mouseDownHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"dragstartHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"blurHandler",e=>{var o;const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(o=this.imageToolbarState)!=null&&o.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"scrollHandler",()=>{var e;if((e=this.imageToolbarState)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=t.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=e,this.pmView=t,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");o(this.imageToolbarState)},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.imageToolbarState)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.updateImageToolbar();return}(!e.state.selection.eq(t.selection)||!e.state.doc.eq(t.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}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 W=new k.PluginKey("ImageToolbarPlugin");class ot extends K{constructor(t){super();p(this,"view");p(this,"plugin");this.plugin=new k.Plugin({key:W,view:o=>(this.view=new nt(W,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(W))==null?void 0:r.block}}}})}onUpdate(t){return this.on("update",t)}}const Pn={textAlignment:H.textAlignment,backgroundColor:H.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,Hn=Ke({type:"image",propSchema:Pn,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 d=document.createElement("div");d.className="bn-image-resize-handle",d.style.left="4px";const c=document.createElement("div");c.className="bn-image-resize-handle",c.style.right="4px";const h=document.createElement("p");h.className="bn-image-caption",h.innerText=n.props.caption,h.style.padding=n.props.caption?"4px":"";const f=()=>{var te;const w=((te=e.getSelection())==null?void 0:te.blocks)||[];[e.getTextCursorPosition().block,...w].find(q=>q.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(d)&&a.contains(c)&&(a.removeChild(d),a.removeChild(c));return}let L;it(n.props.textAlignment)==="center"?m.handleUsed==="left"?L=m.initialWidth+(m.initialClientX-w.clientX)*2:L=m.initialWidth+(w.clientX-m.initialClientX)*2:m.handleUsed==="left"?L=m.initialWidth+m.initialClientX-w.clientX:L=m.initialWidth+w.clientX-m.initialClientX,L<rt?l.style.width=`${rt}px`:L>e.domElement.firstElementChild.clientWidth?l.style.width=`${e.domElement.firstElementChild.clientWidth}px`:l.style.width=`${L}px`},T=w=>{(!w.target||!a.contains(w.target)||!e.isEditable)&&a.contains(d)&&a.contains(c)&&(a.removeChild(d),a.removeChild(c)),m&&(m=void 0,e.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},M=w=>{w.preventDefault()},x=()=>{e._tiptapEditor.view.dispatch(e._tiptapEditor.state.tr.setMeta(W,{block:n}))},v=()=>{e.isEditable&&(a.appendChild(d),a.appendChild(c))},S=w=>{w.relatedTarget===d||w.relatedTarget===c||m||e.isEditable&&a.contains(d)&&a.contains(c)&&(a.removeChild(d),a.removeChild(c))},C=w=>{w.preventDefault(),a.appendChild(d),a.appendChild(c),m={handleUsed:"left",initialWidth:n.props.width,initialClientX:w.clientX}},B=w=>{w.preventDefault(),a.appendChild(d),a.appendChild(c),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(h),n.props.url===""?t.appendChild(o):t.appendChild(s),window.addEventListener("mousemove",g),window.addEventListener("mouseup",T),o.addEventListener("mousedown",M),o.addEventListener("click",x),l.addEventListener("mouseenter",v),l.addEventListener("mouseleave",S),d.addEventListener("mousedown",C),c.addEventListener("mousedown",B),{dom:t,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",T),o.removeEventListener("mousedown",M),o.removeEventListener("click",x),d.removeEventListener("mousedown",C),c.removeEventListener("mousedown",B)}}},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}}}),st=n=>{const{node:e,contentType:t}=E(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)])},Ln={...H},Nn=U({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:()=>st(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 Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),An=j(Nn,Ln),Dn=new k.PluginKey("numbered-list-indexing"),_n=()=>new k.Plugin({key:Dn,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,d=E(o.doc,s+1);if(d===void 0)return;if(!l){const f=E(o.doc,s-2);if(f===void 0)return;if(!(d.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const x=g.attrs.index;a=(parseInt(x)+1).toString()}}}d.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),On={...H},Rn=U({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:()=>st(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[_n()]},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 Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Fn=j(Rn,On),zn={...H},Vn=U({name:"paragraph",content:"inline*",group:"blockContent",parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Un=j(Vn,zn),qn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Ne.columnResizing({cellMinWidth:100}),Ne.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))}}}),$n={...H},Gn=U({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(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]}}),Kn=j(Gn,$n,[qn,jn,Vt.TableHeader.extend({content:"tableContent"}),zt.TableCell.extend({content:"tableContent"}),Ut.TableRow]),ve={paragraph:Un,heading:In,bulletListItem:An,numberedListItem:Fn,image:Hn,table:Kn},Te=ke(ve),Ee={bold:R(tn.default,"boolean"),italic:R(on.default,"boolean"),underline:R(sn.default,"boolean"),strike:R(rn.default,"boolean"),code:R(nn.default,"boolean"),textColor:Mn,backgroundColor:En},Wn=we(Ee),Ce={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Xn=ye(Ce);function Me(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 Jn(n,e,t="before",o){const i=o._tiptapEditor,r=typeof e=="string"?e:e.id,s=[];for(const c of n)s.push(_(c,i.schema,o.styleSchema));const{node:a,posBeforeNode:l}=Me(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 c=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(l+a.firstChild.nodeSize+1,c))}const d=[];for(const c of s)d.push(I(c,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache));return d}function Yn(n,e,t){const o=t._tiptapEditor,i=typeof n=="string"?n:n.id,{posBeforeNode:r}=Me(i,o.state.doc);o.commands.BNUpdateBlock(r+1,e);const s=o.state.doc.resolve(r+1).node();return I(s,t.blockSchema,t.inlineContentSchema,t.styleSchema,t.blockCache)}function at(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,d)=>{if(r.size===0)return!1;if(l.type.name!=="blockContainer"||!r.has(l.attrs.id))return!0;s.push(I(l,e.blockSchema,e.inlineContentSchema,e.styleSchema,e.blockCache)),r.delete(l.attrs.id),a=(t==null?void 0:t(l,d,i,a))||a;const c=i.doc.nodeSize;i.delete(d-a-1,d-a+l.nodeSize+1);const h=i.doc.nodeSize;return a+=c-h,!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 ao(n,e,t,o,i){const r=le.unified().use(dn.default).use(Oe.default).use(cn.default,{handlers:{...Ae.defaultHandlers,code:so}}).use(_e.default).processSync(n);return dt(r.value,e,t,o,i)}class ct{constructor(e,t,o){p(this,"formattingToolbarState");p(this,"updateFormattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"prevWasEditable",null);p(this,"shouldShow",({state:e})=>!e.selection.empty);p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});p(this,"dragHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});p(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.formattingToolbarState)!=null&&o.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"scrollHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=e,this.pmView=t,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.formattingToolbarState)},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,d=Math.min(...l.map(g=>g.$from.pos)),c=Math.max(...l.map(g=>g.$to.pos)),h=(f=this.shouldShow)==null?void 0:f.call(this,{view:e,state:o,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((m=this.formattingToolbarState)!=null&&m.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();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 ut=new k.PluginKey("FormattingToolbarPlugin");class pt extends K{constructor(t){super();p(this,"view");p(this,"plugin");this.plugin=new k.Plugin({key:ut,view:o=>(this.view=new ct(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class lo{constructor(e,t,o){p(this,"hyperlinkToolbarState");p(this,"updateHyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(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});p(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.hyperlinkToolbarState)!=null&&o.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});p(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.referencePos=b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=e,this.pmView=t,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");o(this.hyperlinkToolbarState)},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.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}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.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}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.hyperlinkToolbarState={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.updateHyperlinkToolbar();return}if((t=this.hyperlinkToolbarState)!=null&&t.show&&e&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ht=new k.PluginKey("HyperlinkToolbarPlugin");class mt extends K{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"editHyperlink",(t,o)=>{this.view.editHyperlink(t,o)});p(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new k.Plugin({key:ht,view:o=>(this.view=new lo(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}const co=b.findParentNode(n=>n.type.name==="blockContainer");class uo{constructor(e,t,o=()=>{}){p(this,"suggestionsMenuState");p(this,"updateSuggestionsMenu");p(this,"pluginState");p(this,"handleScroll",()=>{var e;if((e=this.suggestionsMenuState)!=null&&e.show){const t=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=t.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=e,this.pluginKey=t,this.pluginState=Be(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");o(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const o=this.pluginKey.getState(t),i=this.pluginKey.getState(e.state),r=!o.active&&i.active,s=o.active&&!i.active,a=o.active&&i.active;if(!r&&!a&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:l.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function Be(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const ft=(n,e,t,o,i=()=>[],r=()=>{})=>{if(o.length!==1)throw new Error("'char' should be a single character");let s;const a=l=>{l.dispatch(l.state.tr.setMeta(t,{deactivate:!0}))};return{plugin:new k.Plugin({key:t,view:()=>(s=new uo(n,t,e),s),state:{init(){return Be()},apply(l,d,c,h){var m,g,T,M;if(l.getMeta("orderedListIndexing")!==void 0)return d;if((m=l.getMeta(t))!=null&&m.activate)return{active:!0,triggerCharacter:((g=l.getMeta(t))==null?void 0:g.triggerCharacter)||"",queryStartPos:h.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const f={...d};if(f.items=i(h.doc.textBetween(d.queryStartPos,h.selection.from)),f.notFoundCount=0,f.items.length===0&&(f.notFoundCount=Math.max(0,d.notFoundCount+(h.selection.from-c.selection.from))),h.selection.from!==h.selection.to||(T=l.getMeta(t))!=null&&T.deactivate||l.getMeta("focus")||l.getMeta("blur")||l.getMeta("pointer")||d.active&&h.selection.from<d.queryStartPos||f.notFoundCount>3)return Be();if(((M=l.getMeta(t))==null?void 0:M.selectedItemIndexChanged)!==void 0){let x=l.getMeta(t).selectedItemIndexChanged;x<0?x=d.items.length-1:x>=d.items.length&&(x=0),f.keyboardHoveredItemIndex=x}else c.selection.from!==h.selection.from&&(f.keyboardHoveredItemIndex=0);return f}},props:{handleKeyDown(l,d){const c=this.getState(l.state).active;if(d.key===o&&!c)return l.dispatch(l.state.tr.insertText(o).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:o})),!0;if(!c)return!1;const{triggerCharacter:h,queryStartPos:f,items:m,keyboardHoveredItemIndex:g}=t.getState(l.state);return d.key==="ArrowUp"?(l.dispatch(l.state.tr.setMeta(t,{selectedItemIndexChanged:g-1})),!0):d.key==="ArrowDown"?(l.dispatch(l.state.tr.setMeta(t,{selectedItemIndexChanged:g+1})),!0):d.key==="Enter"?(m.length===0||(a(l),n._tiptapEditor.chain().focus().deleteRange({from:f-h.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:n})),!0):d.key==="Escape"?(a(l),!0):!1},decorations(l){const{active:d,decorationId:c,queryStartPos:h,triggerCharacter:f}=this.getState(l);if(!d)return null;if(f===""){const m=co(l.selection);if(m)return N.DecorationSet.create(l.doc,[N.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":c})])}return N.DecorationSet.create(l.doc,[N.Decoration.inline(h-f.length,h,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:l=>{a(n._tiptapEditor.view),n._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:l,editor:n})}}},re=new k.PluginKey("SlashMenuPlugin");class gt extends K{constructor(t,o){super();p(this,"plugin");p(this,"itemCallback");const i=ft(t,r=>{this.emit("update",r)},re,"/",r=>o.filter(({name:s,aliases:a})=>s.toLowerCase().startsWith(r.toLowerCase())||a&&a.filter(l=>l.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(t){return this.on("update",t)}}class X extends k.Selection{constructor(t,o){super(t,o);p(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 X(t.resolve(o),t.resolve(i))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof X)||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?k.Selection.near(t.resolve(i.pos)):i.deleted?k.Selection.near(t.resolve(r.pos)):new X(t.resolve(i.pos),t.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let F;function se(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 po(n,e){const t=se(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 ho(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 bt(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=(c,h)=>Array.prototype.indexOf.call(c.children,h),s=r(i,n.domAtPos(e+1).node.parentElement),a=r(i,n.domAtPos(t-1).node.parentElement);for(let c=i.childElementCount-1;c>=0;c--)(c>a||c<s)&&o.removeChild(o.children[c]);kt(),F=o;const d=n.dom.className.split(" ").filter(c=>c!=="ProseMirror"&&c!=="bn-root"&&c!=="bn-editor").join(" ");F.className=F.className+" bn-drag-preview "+d,document.body.appendChild(F)}function kt(){F!==void 0&&(document.body.removeChild(F),F=void 0)}function mo(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=po(i,t);if(r!=null){const s=t.state.selection,a=t.state.doc,{from:l,to:d}=ho(s,a),c=l<=r&&r<d,h=s.$anchor.node()!==s.$head.node()||s instanceof X;c&&h?(t.dispatch(t.state.tr.setSelection(X.create(a,l,d))),bt(t,l,d)):(t.dispatch(t.state.tr.setSelection(k.NodeSelection.create(t.state.doc,r))),bt(t,r));const f=t.state.selection.content(),m=e._tiptapEditor.schema,T=me(m,e).serializeProseMirrorFragment(f.content),x=Z(m,e).exportProseMirrorFragment(f.content),v=xe(x);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",T),n.dataTransfer.setData("text/html",x),n.dataTransfer.setData("text/plain",v),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(F,0,0),t.dragging={slice:f,move:!0}}}class yt{constructor(e,t,o){p(this,"sideMenuState");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuFrozen",!1);p(this,"onDragStart",()=>{this.isDragging=!0});p(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)}});p(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)}});p(this,"onKeyDown",e=>{var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseDown",e=>{this.sideMenuState&&!this.sideMenuState.show&&(this.sideMenuState.show=!0,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseMove",e=>{var d,c,h,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))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=t.x;const s={left:t.left+t.width/2,top:e.clientY},a=se(s,this.pmView);if(!a||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((h=this.sideMenuState)!=null&&h.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.sideMenuState={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.updateSideMenu(this.sideMenuState)}});p(this,"onScroll",()=>{var e;if((e=this.sideMenuState)!=null&&e.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.updateSideMenu(this.sideMenuState)}});this.editor=e,this.pmView=t,this.updateSideMenu=o,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.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),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.sideMenuState)!=null&&l.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),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=E(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 d=a+1,c=d+2;this.editor._tiptapEditor.chain().BNCreateBlock(d).BNUpdateBlock(c,{type:"paragraph",props:{}}).setTextSelection(c).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(re,{activate:!0,type:"drag"}))}}const St=new k.PluginKey("SideMenuPlugin");class wt extends K{constructor(t){super();p(this,"sideMenuView");p(this,"plugin");p(this,"addBlock",()=>this.sideMenuView.addBlock());p(this,"blockDragStart",t=>{this.sideMenuView.isDragging=!0,mo(t,this.editor)});p(this,"blockDragEnd",()=>kt());p(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);p(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=t,this.plugin=new k.Plugin({key:St,view:o=>(this.sideMenuView=new yt(t,o,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(t){return this.on("update",t)}}function fo(n){let e=n.getTextCursorPosition().block,t=n.blockSchema[e.type].content;for(;t==="none";)e=n.getTextCursorPosition().nextBlock,t=n.blockSchema[e.type].content,n.setTextCursorPosition(e,"end")}function z(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 fo(n),o}const vt=(n=Te)=>{var t,o,i;const e=[];return"heading"in n&&"level"in n.heading.propSchema&&((t=n.heading.propSchema.level.values)!=null&&t.includes(1)&&e.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>z(r,{type:"heading",props:{level:1}})}),(o=n.heading.propSchema.level.values)!=null&&o.includes(2)&&e.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>z(r,{type:"heading",props:{level:2}})}),(i=n.heading.propSchema.level.values)!=null&&i.includes(3)&&e.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>z(r,{type:"heading",props:{level:3}})})),"bulletListItem"in n&&e.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>z(r,{type:"bulletListItem"})}),"numberedListItem"in n&&e.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>z(r,{type:"numberedListItem"})}),"paragraph"in n&&e.push({name:"Paragraph",aliases:["p"],execute:r=>z(r,{type:"paragraph"})}),"table"in n&&e.push({name:"Table",aliases:["table"],execute:r=>{z(r,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})}}),"image"in n&&e.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{const s=z(r,{type:"image"});r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(W,{block:s}))}}),e};let A;function Tt(){A||(A=document.createElement("div"),A.innerHTML="_",A.style.opacity="0",A.style.height="1px",A.style.width="1px",document.body.appendChild(A))}function go(){A&&(document.body.removeChild(A),A=void 0)}function ae(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function bo(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function ko(n){n.forEach(e=>{const t=document.getElementsByClassName(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"})}class Et{constructor(e,t,o){p(this,"state");p(this,"updateState");p(this,"tableId");p(this,"tablePos");p(this,"menuFrozen",!1);p(this,"prevWasEditable",null);p(this,"mouseMoveHandler",e=>{var d;if(this.menuFrozen)return;const t=bo(e.target);if(!t||!this.editor.isEditable){(d=this.state)!=null&&d.show&&(this.state.show=!1,this.updateState());return}const o=ae(t),i=ae(t.parentElement),r=t.getBoundingClientRect(),s=t.parentElement.parentElement.getBoundingClientRect(),a=se(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((c,h)=>typeof l<"u"?!1:c.type.name!=="blockContainer"||c.attrs.id!==a.id?!0:(l=I(c,this.editor.blockSchema,this.editor.inlineContentSchema,this.editor.styleSchema,this.editor.blockCache),this.tablePos=h+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.updateState(),!1});p(this,"dragOverHandler",e=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",ko(["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=ae(i.parentElement),a=ae(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,c=(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 h=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.updateState(),c&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});p(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}})});p(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.updateState()}});this.editor=e,this.pmView=t,this.updateState=()=>{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 k.PluginKey("TableHandlesPlugin");class Ct extends K{constructor(t){super();p(this,"view");p(this,"plugin");p(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.updateState(),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(A,0,0),t.dataTransfer.effectAllowed="move"});p(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.updateState(),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(A,0,0),t.dataTransfer.effectAllowed="copyMove"});p(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),go()});p(this,"freezeHandles",()=>this.view.menuFrozen=!0);p(this,"unfreezeHandles",()=>this.view.menuFrozen=!1);this.editor=t,this.plugin=new k.Plugin({key:J,view:o=>(this.view=new Et(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 N.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),d=l.node();for(let c=0;c<d.childCount;c++){const h=o.doc.resolve(l.posAtIndex(c)+1),f=h.node(),m=h.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(N.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 d=o.doc.resolve(s.posAtIndex(l)+1),c=o.doc.resolve(d.posAtIndex(i)+1),h=c.node(),f=c.pos+(i>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(N.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 N.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=Z(n.state.schema,e).exportProseMirrorFragment(t),a=xe(s);return{internalHTML:i,externalHTML:s,plainText:a}}const yo=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new k.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 k.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 k.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}}}})]}}),So=["blocknote/html","text/html","text/plain"],wo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{paste(e,t){t.preventDefault();let o=null;for(const i of So)if(t.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=t.clipboardData.getData(o);o==="text/html"&&(i=lt(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),vo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:H.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):H.backgroundColor.default,renderHTML:n=>n.backgroundColor!==H.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),To=new k.PluginKey("blocknote-placeholder"),Eo=b.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"bn-is-editor-empty",emptyNodeClass:"bn-is-empty",isFilterClass:"bn-is-filter",hasAnchorClass:"bn-has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new k.Plugin({key:To,props:{decorations:n=>{const{doc:e,selection:t}=n,o=re.getState(n),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(i)return e.descendants((a,l)=>{const d=r>=l&&r<=l+a.nodeSize,c=!a.isLeaf&&!a.childCount;if((d||!this.options.showOnlyCurrent)&&c){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),d&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&h.push(this.options.isFilterClass);const f=N.Decoration.node(l,l+a.nodeSize,{class:h.join(" ")});s.push(f)}return this.options.includeChildren}),N.DecorationSet.create(e,s)}}})]}}),Co=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}}}}]}}),Mo=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:H.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):H.textColor.default,renderHTML:n=>n.textColor!==H.textColor.default&&{"data-text-color":n.textColor}}}}]}}),xo=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(a)return r.insert(l,d.create(void 0,c.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*"}}})]}}),Bo=new k.PluginKey("non-editable-block"),Io=()=>new k.Plugin({key:Bo,props:{handleKeyDown:(n,e)=>{"node"in n.state.selection&&e.key.length===1&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey&&e.preventDefault()}}}),xt=new k.PluginKey("previous-blocks"),Po={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Ho=()=>{let n;return new k.Plugin({key:xt,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(xt,{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,d=>d.attrs.id),a=new Map(s.map(d=>[d.node.attrs.id,d])),l=b.findChildren(i.doc,d=>d.attrs.id);for(const d of l){const c=a.get(d.node.attrs.id),h=c==null?void 0:c.node.firstChild,f=d.node.firstChild;if(c&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(c.pos).depth};r[d.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,t.updatedBlocks.add(d.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[d,c]of Object.entries(s))a["data-prev-"+Po[d]]=c||"none";const l=N.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),N.DecorationSet.create(e.doc,o)}}})},Lo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},No=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(Lo))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.blockContainer)||{},...n},o=document.createElement("div");o.className=O("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=E(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=E(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(_(m,t.schema,this.options.editor.styleSchema));a.childCount===2?t.tr.replace(r+l.nodeSize+1,s-1,new y.Slice(y.Fragment.from(f),0,0)):t.tr.insert(r+l.nodeSize,t.schema.nodes.blockGroup.create({},f))}const d=l.type.name,c=e.type||d;let h="keep";if(e.content)if(typeof e.content=="string")h=[t.schema.text(e.content)];else if(Array.isArray(e.content))h=ne(e.content,t.schema,this.options.editor.styleSchema);else if(e.content.type==="tableContent")h=pe(e.content,t.schema,this.options.editor.styleSchema);else throw new D(e.content.type);else{const f=t.schema.nodes[d].spec.content,m=t.schema.nodes[c].spec.content;f===""||m!==f&&(h=[])}h==="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[c].create({...l.attrs,...e.props},h)).setSelection(t.schema.nodes[c].spec.content===""?new k.NodeSelection(t.tr.doc.resolve(r)):t.schema.nodes[c].spec.content==="inline*"?new k.TextSelection(t.tr.doc.resolve(r)):new k.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=E(e.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:d,depth:c}=r;if(s.childCount===2){const m=e.doc.resolve(l+a.nodeSize+1),g=e.doc.resolve(d-1),T=m.blockRange(g);t&&e.tr.lift(T,c-1)}let h=n-1,f=E(e.doc,h);for(;f.numChildBlocks>0;)if(h--,f=E(e.doc,h),f===void 0)return!1;return t&&(t(e.tr.deleteRange(l,l+a.nodeSize).replace(h-1,l,new y.Slice(a.content,0,0)).scrollIntoView()),e.tr.setSelection(new k.TextSelection(e.doc.resolve(h-1)))),!0},BNSplitBlock:(n,e)=>({state:t,dispatch:o})=>{const i=E(t.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:d}=i,c=t.doc.cut(a+1,n),h=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,h.content.size>0?new y.Slice(y.Fragment.from(h),d+2,d+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(s).type,r.attrs),t.tr.setSelection(new k.TextSelection(t.doc.resolve(g))),t.tr.replace(a+1,l-1,c.content.size>0?new y.Slice(y.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Ho(),Io()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=E(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}=E(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=E(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,d=s===2,c=s-1;return!d&&a&&l&&r===2?o.BNMergeBlocks(c):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=E(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,d=i.selection.from===a-1,c=i.selection.empty,h=r.childCount===2;if(!l&&d&&c&&!h){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}=E(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,d=r.textContent.length===0,c=s>2;return a&&l&&d&&c?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=E(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,d=i.selection.anchor===i.selection.head,c=s.textContent.length===0;if(l&&d&&c){const h=a+1,f=h+2;return r().BNCreateBlock(h).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=E(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),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2)}}}),Ao=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=O("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}}}),Do=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Bt=n=>{var t;const e=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Jt.Gapcursor,Eo.configure({includeChildren:!0,showOnlyCurrent:!1}),$.configure({types:["blockContainer"]}),Yt.HardBreak,en.Text,Qt.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),Mo,vo,Co,Do,No.configure({editor:n.editor,domAttributes:n.domAttributes}),Ao.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})]),yo(n.editor),wo(n.editor),Xt.Dropcursor.configure({width:5,color:"#ddeeff"}),xo];if(n.collaboration){if(e.push(un.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 _o(n,e){const t=[];return n.forEach((o,i,r)=>{r!==e&&t.push(o)}),y.Fragment.from(t)}function Oo(n,e){let t=y.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=_o(t,o+1))}const r=e.state.schema.nodes.blockContainer.create(void 0,i);t=t.replaceChild(o,r)}return new y.Slice(t,n.openStart,n.openEnd)}const qo="",$o="",Ro={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ie{constructor(e){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"ready",!1);p(this,"sideMenu");p(this,"formattingToolbar");p(this,"slashMenu");p(this,"hyperlinkToolbar");p(this,"imageToolbar");p(this,"tableHandles");p(this,"uploadFile");var l,d,c,h,f,m,g,T,M,x;this.options=e;const t={defaultStyles:!0,blockSpecs:e.blockSpecs||ve,styleSpecs:e.styleSpecs||Ee,inlineContentSpecs:e.inlineContentSpecs||Ce,...e};this.blockSchema=ke(t.blockSpecs),this.inlineContentSchema=ye(t.inlineContentSpecs),this.styleSchema=we(t.styleSpecs),this.blockImplementations=t.blockSpecs,this.inlineContentImplementations=t.inlineContentSpecs,this.styleImplementations=t.styleSpecs,this.sideMenu=new wt(this),this.formattingToolbar=new pt(this),this.slashMenu=new gt(this,t.slashMenuItems||vt(this.blockSchema)),this.hyperlinkToolbar=new mt(this),this.imageToolbar=new ot(this),this.blockSchema.table===Te.table&&(this.tableHandles=new Ct(this));const o=Bt({editor:this,domAttributes:t.domAttributes||{},blockSchema:this.blockSchema,blockSpecs:t.blockSpecs,styleSpecs:t.styleSpecs,inlineContentSpecs:t.inlineContentSpecs,collaboration:t.collaboration}),i=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin,...this.tableHandles?[this.tableHandles.plugin]:[]]});o.push(i),this.uploadFile=t.uploadFile,t.collaboration&&t.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const r=t.initialContent||(e.collaboration?void 0:[{type:"paragraph",id:$.options.generateID()}]),s=this.styleSchema,a={...Ro,...t._tiptapOptions,onBeforeCreate(v){var L,Y;(Y=(L=t._tiptapOptions)==null?void 0:L.onBeforeCreate)==null||Y.call(L,v);const S=v.editor.schema;let C;const B=S.nodes.doc.createAndFill;S.nodes.doc.createAndFill=(...te)=>{if(C)return C;const q=B.apply(S.nodes.doc,te),Lt=JSON.parse(JSON.stringify(q.toJSON()));return Lt.content[0].content[0].attrs.id="initialBlockId",C=y.Node.fromJSON(S,Lt),q};const w=S.node("doc",void 0,S.node("blockGroup",void 0,[_({id:"initialBlockId",type:"paragraph"},S,s)]));v.editor.options.content=w.toJSON()},onCreate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onCreate)==null||C.call(S,v),r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(B=t.onEditorReady)==null||B.call(t,this),this.ready=!0},onUpdate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onUpdate)==null||C.call(S,v),this.ready&&((B=t.onEditorContentChange)==null||B.call(t,this))},onSelectionUpdate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onSelectionUpdate)==null||C.call(S,v),this.ready&&((B=t.onTextCursorPositionChange)==null||B.call(t,this))},editable:e.editable!==void 0?e.editable:((l=t._tiptapOptions)==null?void 0:l.editable)!==void 0?(d=t._tiptapOptions)==null?void 0:d.editable:!0,extensions:t.enableBlockNoteExtensions===!1?((c=t._tiptapOptions)==null?void 0:c.extensions)||[]:[...((h=t._tiptapOptions)==null?void 0:h.extensions)||[],...o],editorProps:{...(f=t._tiptapOptions)==null?void 0:f.editorProps,attributes:{...(g=(m=t._tiptapOptions)==null?void 0:m.editorProps)==null?void 0:g.attributes,...(T=t.domAttributes)==null?void 0:T.editor,class:O("bn-root","bn-editor",t.defaultStyles?"bn-default-styles":"",((x=(M=t.domAttributes)==null?void 0:M.editor)==null?void 0:x.class)||"")},transformPasted:Oo}};t.parentElement&&(a.element=t.parentElement),this._tiptapEditor=new b.Editor(a)}static create(e={}){return new Ie(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(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(I(t,this.blockSchema,this.inlineContentSchema,this.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=I(i,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.topLevelBlocks.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}=E(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:I(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:I(a,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:I(l,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:i}=Me(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=E(this._tiptapEditor.state.doc,i+2),a=this.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 D(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(I(this._tiptapEditor.state.doc.resolve(o).node(),this.blockSchema,this.inlineContentSchema,this.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 Jn(e,t,o,this)}updateBlock(e,t){return Yn(e,t,this)}removeBlocks(e){return Zn(e,this)}replaceBlocks(e,t){return Qn(e,t,this)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks();for(const o of t){const i=this.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.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 D(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.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 D(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}=E(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}=E(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(e=this.topLevelBlocks){return Z(this._tiptapEditor.schema,this).exportBlocks(e)}async tryParseHTMLToBlocks(e){return dt(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(e=this.topLevelBlocks){return to(e,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(e){return ao(e,this.blockSchema,this.inlineContentSchema,this.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)}}function Pe(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function It(n){return typeof n=="string"?Pe(n):Array.isArray(n)?n.flatMap(e=>typeof e=="string"?Pe(e):ce(e)?{...e,content:Pe(e.content)}:G(e)?e:{props:{},...e,content:It(e.content)}):n}function Fo(n,e){return e.map(t=>He(n,t))}function He(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:It(t.content),children:t.children.map(o=>He(n,o))}}function Pt(n){n.id||(n.id=$.options.generateID()),n.children&&Ht(n.children)}function Ht(n){for(const e of n)Pt(e)}u.BlockNoteEditor=Ie,u.FormattingToolbarProsemirrorPlugin=pt,u.FormattingToolbarView=ct,u.HyperlinkToolbarProsemirrorPlugin=mt,u.ImageToolbarProsemirrorPlugin=ot,u.ImageToolbarView=nt,u.SideMenuProsemirrorPlugin=wt,u.SideMenuView=yt,u.SlashMenuProsemirrorPlugin=gt,u.TableHandlesProsemirrorPlugin=Ct,u.TableHandlesView=Et,u.UniqueID=$,u.UnreachableCaseError=D,u.addIdsToBlock=Pt,u.addIdsToBlocks=Ht,u.addInlineContentAttributes=We,u.addInlineContentKeyboardShortcuts=Xe,u.addStyleAttributes=et,u.blockToNode=_,u.camelToDataKebab=ee,u.contentNodeToInlineContent=oe,u.createBlockSpec=Ke,u.createBlockSpecFromStronglyTypedTiptapNode=j,u.createExternalHTMLExporter=Z,u.createInlineContentSpec=wn,u.createInlineContentSpecFromTipTapNode=Ye,u.createInternalBlockSpec=be,u.createInternalHTMLSerializer=me,u.createInternalInlineContentSpec=Je,u.createInternalStyleSpec=Se,u.createStronglyTypedTiptapNode=U,u.createStyleSpec=vn,u.createStyleSpecFromTipTapMark=R,u.defaultBlockSchema=Te,u.defaultBlockSpecs=ve,u.defaultInlineContentSchema=Xn,u.defaultInlineContentSpecs=Ce,u.defaultProps=H,u.defaultStyleSchema=Wn,u.defaultStyleSpecs=Ee,u.formatKeyboardShortcut=Sn,u.formattingToolbarPluginKey=ut,u.getBlockFromPos=Ge,u.getBlockNoteExtensions=Bt,u.getBlockSchemaFromSpecs=ke,u.getDefaultSlashMenuItems=vt,u.getDraggableBlockFromCoords=se,u.getInlineContentParseRules=Ze,u.getInlineContentSchemaFromSpecs=ye,u.getParseRules=je,u.getStyleParseRules=tt,u.getStyleSchemaFromSpecs=we,u.hyperlinkToolbarPluginKey=ht,u.imageToolbarPluginKey=W,u.inheritedProps=fe,u.inlineContentToNodes=ne,u.isAppleOS=qe,u.isLinkInlineContent=de,u.isPartialLinkInlineContent=ce,u.isStyledTextInlineContent=G,u.mergeCSSClasses=O,u.nodeToBlock=I,u.nodeToCustomInlineContent=he,u.partialBlockToBlockForTesting=He,u.partialBlocksToBlocksForTesting=Fo,u.propsToAttributes=ge,u.setupSuggestionsMenu=ft,u.sideMenuPluginKey=St,u.slashMenuPluginKey=re,u.stylePropsToAttributes=Qe,u.tableContentToNodes=pe,u.tableHandlesPluginKey=J,u.uploadToTmpFilesDotOrg_DEV_ONLY=yn,u.wrapInBlockStructure=ie,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
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 to(n,e){return lt(n,e)}function no(n,e,t){const o=t._tiptapEditor,i=[];for(const l of e)i.push(L(l,o.schema,t.schema.styleSchema));const r=typeof n[0]=="string"?n[0]:n[0].id,s=lt(n,t,(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,t.schema.blockSchema,t.schema.inlineContentSchema,t.schema.styleSchema,t.blockCache));return{insertedBlocks:a,removedBlocks:s}}function oo(n,e,t,o={updateSelection:!0}){const i=t._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(e.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,e),o.updateSelection&&b.selectionToInsertionEnd(r,r.steps.length-1,-1),i.view.dispatch(r),!0}function io(){const n=e=>{let t=e.children.length;for(let o=0;o<t;o++){const i=e.children[o];if(i.type==="element"&&(n(i),i.tagName==="u"))if(i.children.length>0){e.children.splice(o,1,...i.children);const r=i.children.length-1;t+=r,o+=r}else e.children.splice(o,1),t--,o--}};return n}function Be(n){return le.unified().use(Oe.default,{fragment:!0}).use(io).use(ln.default).use(Re.default).use(cn.default).processSync(n).value}function ro(n,e,t){const i=Q(e,t).exportBlocks(n);return Be(i)}function so(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function ao(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function lo(n){n.querySelectorAll("li > ul, li > ol").forEach(e=>{const t=so(e),o=e.parentElement,i=Array.from(o.childNodes).slice(t+1);e.remove(),i.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",e),i.reverse().forEach(r=>{if(ao(r))return;const s=document.createElement("li");s.append(r),e.insertAdjacentElement("afterend",s)}),o.childNodes.length===0&&o.remove()})}function co(n){n.querySelectorAll("li + ul, li + ol").forEach(e=>{var r,s;const t=e.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);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 ct=null;function uo(){return ct||(ct=document.implementation.createHTMLDocument("title"))}function dt(n){if(typeof n=="string"){const e=uo().createElement("div");e.innerHTML=n,n=e}return lo(n),co(n),n}async function ut(n,e,t,o,i){const r=dt(n),a=k.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),e,t,o));return l}function ho(n,e){const t=e.value?e.value+`
|
|
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"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|