@blocknote/core 0.47.1 → 0.47.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -1
- package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -1
- package/dist/{BlockNoteSchema-CwhtPpVC.cjs → BlockNoteSchema-CCs_V3lo.cjs} +2 -2
- package/dist/{BlockNoteSchema-CwhtPpVC.cjs.map → BlockNoteSchema-CCs_V3lo.cjs.map} +1 -1
- package/dist/{BlockNoteSchema-dmbNkHA-.js → BlockNoteSchema-ooiKsd5B.js} +2 -2
- package/dist/{BlockNoteSchema-dmbNkHA-.js.map → BlockNoteSchema-ooiKsd5B.js.map} +1 -1
- package/dist/{TrailingNode-F9hX_UlQ.js → TrailingNode-GzE59m_7.js} +585 -415
- package/dist/TrailingNode-GzE59m_7.js.map +1 -0
- package/dist/TrailingNode-n0WdMPUl.cjs +2 -0
- package/dist/TrailingNode-n0WdMPUl.cjs.map +1 -0
- package/dist/blocknote.cjs +4 -4
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +938 -862
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/defaultBlocks-Dg9kQWXm.cjs +6 -0
- package/dist/defaultBlocks-Dg9kQWXm.cjs.map +1 -0
- package/dist/{defaultBlocks-Caw1U1oV.js → defaultBlocks-ZzGbYgQn.js} +611 -530
- package/dist/defaultBlocks-ZzGbYgQn.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.cjs.map +1 -1
- package/dist/extensions.js +33 -54
- package/dist/extensions.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +25 -24
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +1 -10
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +4 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -1
- package/src/api/parsers/html/parseHTML.ts +2 -0
- package/src/api/parsers/html/util/normalizeWhitespace.ts +87 -0
- package/src/blocks/Heading/block.ts +48 -1
- package/src/blocks/ListItem/ToggleListItem/block.ts +51 -1
- package/src/blocks/Paragraph/block.ts +1 -1
- package/src/blocks/getDetailsContent.ts +77 -0
- package/src/comments/threadstore/TipTapThreadStore.ts +5 -5
- package/src/comments/threadstore/tiptap/types.ts +131 -0
- package/src/editor/Block.css +6 -0
- package/src/editor/BlockNoteEditor.ts +9 -14
- package/src/editor/managers/ExtensionManager/symbol.ts +0 -1
- package/src/editor/managers/SelectionManager.ts +3 -1
- package/src/extensions/DropCursor/DropCursor.ts +262 -25
- package/src/extensions/DropCursor/utils.ts +195 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +15 -10
- package/src/i18n/locales/fa.ts +4 -21
- package/src/i18n/locales/index.ts +1 -1
- package/src/i18n/locales/ru.ts +1 -1
- package/src/i18n/locales/uz.ts +22 -4
- package/src/index.ts +1 -0
- package/src/schema/blocks/createSpec.ts +33 -45
- package/src/schema/blocks/types.ts +101 -1
- package/types/src/api/parsers/html/util/normalizeWhitespace.d.ts +6 -0
- package/types/src/blocks/getDetailsContent.d.ts +19 -0
- package/types/src/comments/threadstore/TipTapThreadStore.d.ts +1 -1
- package/types/src/comments/threadstore/tiptap/types.d.ts +73 -0
- package/types/src/editor/BlockNoteEditor.d.ts +6 -9
- package/types/src/extensions/DropCursor/DropCursor.d.ts +42 -5
- package/types/src/extensions/DropCursor/utils.d.ts +48 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.d.ts +3 -3
- package/types/src/schema/blocks/types.d.ts +31 -1
- package/dist/TrailingNode-DHOdUVUO.cjs +0 -2
- package/dist/TrailingNode-DHOdUVUO.cjs.map +0 -1
- package/dist/TrailingNode-F9hX_UlQ.js.map +0 -1
- package/dist/defaultBlocks-CSB5GiAu.cjs +0 -6
- package/dist/defaultBlocks-CSB5GiAu.cjs.map +0 -1
- package/dist/defaultBlocks-Caw1U1oV.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var De=Object.create;var G=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Oe=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var Ae=(o,e,n)=>e in o?G(o,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[e]=n;var Le=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Pe(e))!Me.call(o,r)&&r!==n&&G(o,r,{get:()=>e[r],enumerable:!(t=Be(e,r))||t.enumerable});return o};var se=(o,e,n)=>(n=o!=null?De(Oe(o)):{},Le(e||!o||!o.__esModule?G(n,"default",{value:o,enumerable:!0}):n,o));var k=(o,e,n)=>Ae(o,typeof e!="symbol"?e+"":e,n);const E=require("prosemirror-state"),$=require("@tiptap/core"),Ne=require("fast-deep-equal"),v=require("./blockToNode-CumVjgem.cjs"),M=require("./defaultBlocks-Dg9kQWXm.cjs"),I=require("./BlockNoteExtension-BWw0r8Gy.cjs"),V=require("y-prosemirror"),Re=require("yjs"),z=require("@tiptap/pm/state"),Ve=require("prosemirror-transform"),J=require("@tiptap/pm/history"),R=require("prosemirror-view"),He=require("uuid"),ie=require("@tiptap/pm/model"),q=require("prosemirror-model"),_e=require("rehype-parse"),Fe=require("rehype-remark"),Ue=require("remark-gfm"),$e=require("remark-stringify"),ze=require("unified"),qe=require("hast-util-from-dom"),Ke=require("unist-util-visit"),L=require("prosemirror-tables"),K=o=>o&&typeof o=="object"&&"default"in o?o:{default:o};function Ye(o){if(o&&typeof o=="object"&&"default"in o)return o;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const n in o)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(o,n);Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>o[n]})}}return e.default=o,Object.freeze(e)}const je=K(Ne),N=Ye(Re),Xe=K(_e),We=K(Fe),Ge=K(Ue),Je=K($e);function pe(o){const e=Array.from(o.classList).filter(n=>!n.startsWith("bn-"))||[];e.length>0?o.className=e.join(" "):o.removeAttribute("class")}function ge(o,e,n,t){var a;let r;if(e)if(typeof e=="string")r=v.inlineContentToNodes([e],o.pmSchema);else if(Array.isArray(e))r=v.inlineContentToNodes(e,o.pmSchema);else if(e.type==="tableContent")r=v.tableContentToNodes(e,o.pmSchema);else throw new v.UnreachableCaseError(e.type);else throw new Error("blockContent is required");const i=((t==null?void 0:t.document)??document).createDocumentFragment();for(const c of r)if(c.type.name!=="text"&&o.schema.inlineContentSchema[c.type.name]){const l=o.schema.inlineContentSpecs[c.type.name].implementation;if(l){const u=v.nodeToCustomInlineContent(c,o.schema.inlineContentSchema,o.schema.styleSchema),h=l.toExternalHTML?l.toExternalHTML(u,o):l.render.call({renderType:"dom",props:void 0},u,()=>{},o);if(h){if(i.appendChild(h.dom),h.contentDOM){const p=n.serializeFragment(c.content,t);h.contentDOM.dataset.editable="",h.contentDOM.appendChild(p)}continue}}}else if(c.type.name==="text"){let l=document.createTextNode(c.textContent);for(const u of c.marks.toReversed())if(u.type.name in o.schema.styleSpecs){const h=(o.schema.styleSpecs[u.type.name].implementation.toExternalHTML??o.schema.styleSpecs[u.type.name].implementation.render)(u.attrs.stringValue,o);h.contentDOM.appendChild(l),l=h.dom}else{const h=u.type.spec.toDOM(u,!0),p=q.DOMSerializer.renderSpec(document,h);p.contentDOM.appendChild(l),l=p.dom}i.appendChild(l)}else{const l=n.serializeFragment(q.Fragment.from([c]),t);i.appendChild(l)}return i.childNodes.length===1&&((a=i.firstChild)==null?void 0:a.nodeType)===1&&pe(i.firstChild),i}function Qe(o,e,n,t,r,s,i,a){var w,y,b,C,T,D,A,H,P;const c=(a==null?void 0:a.document)??document,l=e.pmSchema.nodes.blockContainer,u=n.props||{};for(const[S,x]of Object.entries(e.schema.blockSchema[n.type].propSchema))!(S in u)&&x.default!==void 0&&(u[S]=x.default);const h=(y=(w=l.spec)==null?void 0:w.toDOM)==null?void 0:y.call(w,l.create({id:n.id,...u})),p=Array.from(h.dom.attributes),m=e.blockImplementations[n.type].implementation,f=((b=m.toExternalHTML)==null?void 0:b.call({},{...n,props:u},e,{nestingLevel:i}))||m.render.call({},{...n,props:u},e),d=c.createDocumentFragment();if(f.dom.classList.contains("bn-block-content")){const S=[...p,...Array.from(f.dom.attributes)].filter(x=>x.name.startsWith("data")&&x.name!=="data-content-type"&&x.name!=="data-file-block"&&x.name!=="data-node-view-wrapper"&&x.name!=="data-node-type"&&x.name!=="data-id"&&x.name!=="data-editable");for(const x of S)f.dom.firstChild.setAttribute(x.name,x.value);pe(f.dom.firstChild),i>0&&f.dom.firstChild.setAttribute("data-nesting-level",i.toString()),d.append(...Array.from(f.dom.childNodes))}else d.append(f.dom),i>0&&f.dom.setAttribute("data-nesting-level",i.toString());if(f.contentDOM&&n.content){const S=ge(e,n.content,t,a);f.contentDOM.appendChild(S)}let g;if(r.has(n.type)?g="OL":s.has(n.type)&&(g="UL"),g){if(((C=o.lastChild)==null?void 0:C.nodeName)!==g){const S=c.createElement(g);g==="OL"&&"start"in u&&u.start&&(u==null?void 0:u.start)!==1&&S.setAttribute("start",u.start+""),o.append(S)}o.lastChild.appendChild(d)}else o.append(d);if(n.children&&n.children.length>0){const S=c.createDocumentFragment();if(be(S,e,n.children,t,r,s,i+1,a),((T=o.lastChild)==null?void 0:T.nodeName)==="UL"||((D=o.lastChild)==null?void 0:D.nodeName)==="OL")for(;((A=S.firstChild)==null?void 0:A.nodeName)==="UL"||((H=S.firstChild)==null?void 0:H.nodeName)==="OL";)o.lastChild.lastChild.appendChild(S.firstChild);"childrenDOM"in f&&f.childrenDOM?f.childrenDOM.append(S):e.pmSchema.nodes[n.type].isInGroup("blockContent")?o.append(S):(P=f.contentDOM)==null||P.append(S)}}const be=(o,e,n,t,r,s,i=0,a)=>{for(const c of n)Qe(o,e,c,t,r,s,i,a)},Ze=(o,e,n,t,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return be(a,o,e,n,t,r,0,s),a},ee=(o,e)=>{const n=q.DOMSerializer.fromSchema(o);return{exportBlocks:(t,r)=>{const s=Ze(e,t,n,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem","toggleListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(t,r)=>{const s=ge(e,t,n,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function et(o,e){if(e===0)return;const n=o.resolve(e);for(let t=n.depth;t>0;t--){const r=n.node(t);if(M.isNodeBlock(r))return r.attrs.id}}function tt(o){return o.getMeta("paste")?{type:"paste"}:o.getMeta("uiEvent")==="drop"?{type:"drop"}:o.getMeta("history$")?{type:o.getMeta("history$").redo?"redo":"undo"}:o.getMeta("y-sync$")?o.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}function ae(o){const e="__root__",n={},t={},r=v.getPmSchema(o);return o.descendants((s,i)=>{if(!M.isNodeBlock(s))return!0;const a=et(o,i),c=a??e;t[c]||(t[c]=[]);const l=v.nodeToBlock(s,r);return n[s.attrs.id]={block:l,parentId:a},t[c].push(s.attrs.id),!0}),{byId:n,childrenByParent:t}}function ot(o,e){const n=new Set;if(!o||!e)return n;const t=new Set(o),r=e.filter(d=>t.has(d)),s=o.filter(d=>r.includes(d));if(s.length<=1||r.length<=1)return n;const i={};for(let d=0;d<s.length;d++)i[s[d]]=d;const a=r.map(d=>i[d]),c=a.length,l=[],u=[],h=new Array(c).fill(-1),p=(d,g)=>{let w=0,y=d.length;for(;w<y;){const b=w+y>>>1;d[b]<g?w=b+1:y=b}return w};for(let d=0;d<c;d++){const g=a[d],w=p(l,g);w>0&&(h[d]=u[w-1]),w===l.length?(l.push(g),u.push(d)):(l[w]=g,u[w]=d)}const m=new Set;let f=u[u.length-1]??-1;for(;f!==-1;)m.add(f),f=h[f];for(let d=0;d<r.length;d++)m.has(d)||n.add(r[d]);return n}function we(o,e=[]){const n=tt(o),t=$.combineTransactionSteps(o.before,[o,...e]),r=ae(t.before),s=ae(t.doc),i=[],a=new Set;Object.keys(s.byId).filter(m=>!(m in r.byId)).forEach(m=>{i.push({type:"insert",block:s.byId[m].block,source:n,prevBlock:void 0}),a.add(m)}),Object.keys(r.byId).filter(m=>!(m in s.byId)).forEach(m=>{i.push({type:"delete",block:r.byId[m].block,source:n,prevBlock:void 0}),a.add(m)}),Object.keys(s.byId).filter(m=>m in r.byId).forEach(m=>{var w,y;const f=r.byId[m],d=s.byId[m];f.parentId!==d.parentId?(i.push({type:"move",block:d.block,prevBlock:f.block,source:n,prevParent:f.parentId?(w=r.byId[f.parentId])==null?void 0:w.block:void 0,currentParent:d.parentId?(y=s.byId[d.parentId])==null?void 0:y.block:void 0}),a.add(m)):je.default({...f.block,children:void 0},{...d.block,children:void 0})||(i.push({type:"update",block:d.block,prevBlock:f.block,source:n}),a.add(m))});const c=r.childrenByParent,l=s.childrenByParent,u="__root__",h=new Set([...Object.keys(c),...Object.keys(l)]),p=new Set;return h.forEach(m=>{const f=ot(c[m],l[m]);f.size!==0&&f.forEach(d=>{var b,C;const g=r.byId[d],w=s.byId[d];!g||!w||g.parentId!==w.parentId||a.has(d)||(g.parentId??u)!==m||p.has(d)||(p.add(d),i.push({type:"move",block:w.block,prevBlock:g.block,source:n,prevParent:g.parentId?(b=r.byId[g.parentId])==null?void 0:b.block:void 0,currentParent:w.parentId?(C=s.byId[w.parentId])==null?void 0:C.block:void 0}),a.add(d))})}),i}const nt=I.createExtension(()=>{const o=[];return{key:"blockChange",prosemirrorPlugins:[new E.Plugin({key:new E.PluginKey("blockChange"),filterTransaction:e=>{let n;return o.reduce((t,r)=>t===!1?t:r({getChanges(){return n||(n=we(e),n)},tr:e})!==!1,!0)}})],subscribe(e){return o.push(e),()=>{o.splice(o.indexOf(e),1)}}}});function le(o){const e=o.charAt(0)==="#"?o.substring(1,7):o,n=parseInt(e.substring(0,2),16),t=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16),i=[n/255,t/255,r/255].map(c=>c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4));return .2126*i[0]+.7152*i[1]+.0722*i[2]<=.179}function rt(o){const e=document.createElement("span");e.classList.add("bn-collaboration-cursor__base");const n=document.createElement("span");n.setAttribute("contentedEditable","false"),n.classList.add("bn-collaboration-cursor__caret"),n.setAttribute("style",`background-color: ${o.color}; color: ${le(o.color)?"white":"black"}`);const t=document.createElement("span");return t.classList.add("bn-collaboration-cursor__label"),t.setAttribute("style",`background-color: ${o.color}; color: ${le(o.color)?"white":"black"}`),t.insertBefore(document.createTextNode(o.name),null),n.insertBefore(t,null),e.insertBefore(document.createTextNode(""),null),e.insertBefore(n,null),e.insertBefore(document.createTextNode(""),null),e}const Q=I.createExtension(({options:o})=>{const e=new Map,n=o.provider&&"awareness"in o.provider&&typeof o.provider.awareness=="object"?o.provider.awareness:void 0;return n&&("setLocalStateField"in n&&typeof n.setLocalStateField=="function"&&n.setLocalStateField("user",o.user),"on"in n&&typeof n.on=="function"&&o.showCursorLabels!=="always"&&n.on("change",({updated:t})=>{for(const r of t){const s=e.get(r);s&&(setTimeout(()=>{s.element.setAttribute("data-active","")},10),s.hideTimeout&&clearTimeout(s.hideTimeout),e.set(r,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)}))}})),{key:"yCursor",prosemirrorPlugins:[n?V.yCursorPlugin(n,{selectionBuilder:V.defaultSelectionBuilder,cursorBuilder(t,r){let s=e.get(r);if(!s){const i=(o.renderCursor??rt)(t);o.showCursorLabels!=="always"&&(i.addEventListener("mouseenter",()=>{const a=e.get(r);a.element.setAttribute("data-active",""),a.hideTimeout&&(clearTimeout(a.hideTimeout),e.set(r,{element:a.element,hideTimeout:void 0}))}),i.addEventListener("mouseleave",()=>{const a=e.get(r);e.set(r,{element:a.element,hideTimeout:setTimeout(()=>{a.element.removeAttribute("data-active")},2e3)})})),s={element:i,hideTimeout:void 0},e.set(r,s)}return s.element}}):void 0].filter(Boolean),dependsOn:["ySync"],updateUser(t){n==null||n.setLocalStateField("user",t)}}}),X=I.createExtension(({options:o})=>({key:"ySync",prosemirrorPlugins:[V.ySyncPlugin(o.fragment)],runsBefore:["default"]})),W=I.createExtension(()=>({key:"yUndo",prosemirrorPlugins:[V.yUndoPlugin()],dependsOn:["yCursor","ySync"],undoCommand:V.undoCommand,redoCommand:V.redoCommand}));function st(o,e){const n=o.doc;if(o._item===null){const t=Array.from(n.share.keys()).find(r=>n.share.get(r)===o);if(t==null)throw new Error("type does not exist in other ydoc");return e.get(t,o.constructor)}else{const t=o._item,r=e.store.clients.get(t.id.client)??[],s=N.findIndexSS(r,t.id.clock);return r[s].content.type}}const it=I.createExtension(({editor:o,options:e})=>{let n;const t=I.createStore({isForked:!1});return{key:"yForkDoc",store:t,fork(){if(n)return;const r=e.fragment;if(!r)throw new Error("No fragment to fork from");const s=new N.Doc;N.applyUpdate(s,N.encodeStateAsUpdate(r.doc));const i=st(r,s);n={undoStack:V.yUndoPluginKey.getState(o.prosemirrorState).undoManager.undoStack,originalFragment:r,forkedFragment:i},o.unregisterExtension([W,Q,X]);const a={...e,fragment:i};o.registerExtension([X(a),W()]),t.setState({isForked:!0})},merge({keepChanges:r}){if(!n)return;o.unregisterExtension(["ySync","yCursor","yUndo"]);const{originalFragment:s,forkedFragment:i,undoStack:a}=n;if(o.registerExtension([X(e),Q(e),W()]),V.yUndoPluginKey.getState(o.prosemirrorState).undoManager.undoStack=a,r){const c=N.encodeStateAsUpdate(i.doc,N.encodeStateVector(s.doc));N.applyUpdate(s.doc,c,o)}n=void 0,t.setState({isForked:!1})}}}),ye=(o,e)=>{e(o),o.forEach(n=>{n instanceof N.XmlElement&&ye(n,e)})},at=(o,e)=>{const n=new Map;return o.forEach(t=>{t instanceof N.XmlElement&&ye(t,r=>{if(r.nodeName==="blockContainer"&&r.hasAttribute("id")){const s=r.getAttribute("textColor"),i=r.getAttribute("backgroundColor"),a={textColor:s===M.defaultProps.textColor.default?void 0:s,backgroundColor:i===M.defaultProps.backgroundColor.default?void 0:i};(a.textColor||a.backgroundColor)&&n.set(r.getAttribute("id"),a)}})}),n.size===0?!1:(e.doc.descendants((t,r)=>{if(t.type.name==="blockContainer"&&n.has(t.attrs.id)){const s=e.doc.nodeAt(r+1);if(!s)throw new Error("No element found");e.setNodeMarkup(r+1,void 0,{...s.attrs,...n.get(t.attrs.id)})}}),!0)},lt=[at],ct=I.createExtension(({options:o})=>{let e=!1;const n=new z.PluginKey("schemaMigration");return{key:"schemaMigration",prosemirrorPlugins:[new z.Plugin({key:n,appendTransaction:(t,r,s)=>{if(e||!t.some(a=>a.getMeta("y-sync$"))||t.every(a=>!a.docChanged)||!o.fragment.firstChild)return;const i=s.tr;for(const a of lt)a(o.fragment,i);if(e=!0,!!i.docChanged)return i}})]}});function ce(o,e){return!o||!e?!1:!!o.closest(`.${e}`)}function dt(o,e,n,t,r){const s=o.state.doc.resolve(e.pos);if(!!s.parent.inlineContent||e.orientation==="inline")return null;const a=s.nodeBefore,c=s.nodeAfter;if(!a&&!c)return null;const l=e.orientation==="block-vertical-left"||e.orientation==="block-vertical-right",u=l?e.pos:e.pos-(a?a.nodeSize:0),h=o.nodeDOM(u);if(!h)return null;const p=h.getBoundingClientRect();if(l){const d=n/2*t,g=e.orientation==="block-vertical-left"?p.left:p.right;return{left:g-d,right:g+d,top:p.top,bottom:p.bottom}}let m=a?p.bottom:p.top;a&&c&&(m=(m+o.nodeDOM(e.pos).getBoundingClientRect().top)/2);const f=n/2*r;return{left:p.left,right:p.right,top:m-f,bottom:m+f}}function ut(o,e,n,t){const r=o.coordsAtPos(e.pos),s=n/2*t;return{left:r.left-s,right:r.left+s,top:r.top,bottom:r.bottom}}function ht(o,e){o.classList.toggle("prosemirror-dropcursor-inline",e==="inline"),o.classList.toggle("prosemirror-dropcursor-block-horizontal",e==="block-horizontal"),o.classList.toggle("prosemirror-dropcursor-block-vertical-left",e==="block-vertical-left"),o.classList.toggle("prosemirror-dropcursor-block-vertical-right",e==="block-vertical-right"),o.classList.toggle("prosemirror-dropcursor-block",e==="block-horizontal"),o.classList.toggle("prosemirror-dropcursor-vertical",e==="block-vertical-left"||e==="block-vertical-right")}function mt(o){if(!o||o===document.body&&getComputedStyle(o).position==="static")return{parentLeft:-window.pageXOffset,parentTop:-window.pageYOffset};const e=o.getBoundingClientRect(),n=e.width/o.offsetWidth,t=e.height/o.offsetHeight;return{parentLeft:e.left-o.scrollLeft*n,parentTop:e.top-o.scrollTop*t}}const ke="bn-drag-exclude",ft=I.createExtension(({editor:o,options:e})=>{var d,g,w,y;let n=null,t=null,r=-1,s=null;const i={width:((d=e.dropCursor)==null?void 0:d.width)??5,color:((g=e.dropCursor)==null?void 0:g.color)??"#ddeeff",exclude:((w=e.dropCursor)==null?void 0:w.exclude)??ke,hooks:(y=e.dropCursor)==null?void 0:y.hooks},a=b=>{(b==null?void 0:b.pos)===(n==null?void 0:n.pos)&&(b==null?void 0:b.orientation)===(n==null?void 0:n.orientation)||(n=b,b==null?(t&&t.parentNode&&t.parentNode.removeChild(t),t=null):c())},c=()=>{if(!n)return;const b=o.prosemirrorView,C=b.dom,T=C.getBoundingClientRect(),D=T.width/C.offsetWidth,A=T.height/C.offsetHeight,P=dt(b,n,i.width,D,A)??ut(b,n,i.width,D),S=b.dom.offsetParent;t||(t=S.appendChild(document.createElement("div")),t.style.cssText="position: absolute; z-index: 50; pointer-events: none;",i.color&&(t.style.backgroundColor=i.color)),ht(t,n.orientation);const{parentLeft:x,parentTop:oe}=mt(S);t.style.left=(P.left-x)/D+"px",t.style.top=(P.top-oe)/A+"px",t.style.width=(P.right-P.left)/D+"px",t.style.height=(P.bottom-P.top)/A+"px"},l=b=>{clearTimeout(r),r=window.setTimeout(()=>a(null),b)},u=b=>{const C=b;s=C.target instanceof Element?C.target:null},h=b=>{var S;const C=b;if(s&&ce(s,i.exclude)||C.target instanceof Element&&ce(C.target,i.exclude))return;const T=o.prosemirrorView;if(!T.editable)return;const D=T.posAtCoords({left:C.clientX,top:C.clientY}),A=D&&D.inside>=0&&T.state.doc.nodeAt(D.inside),H=A&&A.type.spec.disableDropCursor,P=typeof H=="function"?H(T,D,C):H;if(D&&!P){let x=D.pos;if(T.dragging&&T.dragging.slice){const U=Ve.dropPoint(T.state.doc,x,T.dragging.slice);U!=null&&(x=U)}const Te=!T.state.doc.resolve(x).parent.inlineContent,ne={pos:x,orientation:Te?"block-horizontal":"inline"};let re=ne;if((S=i.hooks)!=null&&S.computeDropPosition){const U=i.hooks.computeDropPosition({editor:o,event:C,view:T,defaultPosition:ne});if(U===null){a(null);return}re=U}a(re),l(5e3)}},p=b=>{const C=b;(!(C.relatedTarget instanceof Node)||!o.prosemirrorView.dom.contains(C.relatedTarget))&&a(null)},m=()=>{l(20)},f=()=>{l(20),s=null};return{key:"dropCursor",mount({signal:b,dom:C,root:T}){T.addEventListener("dragstart",u,{capture:!0,signal:b}),C.addEventListener("dragover",h,{signal:b}),C.addEventListener("dragleave",p,{signal:b}),C.addEventListener("drop",m,{signal:b}),C.addEventListener("dragend",f,{signal:b}),b.addEventListener("abort",()=>{clearTimeout(r),a(null)})}}}),pt=I.createExtension(({editor:o})=>{const e=I.createStore(!1),n=()=>o.transact(t=>{var s;if(t.selection.empty||t.selection instanceof E.NodeSelection&&(t.selection.node.type.spec.content==="inline*"||((s=t.selection.node.firstChild)==null?void 0:s.type.spec.content)==="inline*")||t.selection instanceof E.TextSelection&&t.doc.textBetween(t.selection.from,t.selection.to).length===0)return!1;let r=!1;return t.selection.content().content.descendants(i=>(i.type.spec.code&&(r=!0),!r)),!r});return{key:"formattingToolbar",store:e,mount({dom:t,signal:r}){let s=!1;const i=o.onChange(()=>{s||e.setState(n())}),a=o.onSelectionChange(()=>{s||e.setState(n())});t.addEventListener("pointerdown",()=>{s=!0,e.setState(!1)},{signal:r}),o.prosemirrorView.root.addEventListener("pointerup",()=>{s=!1,o.isFocused()&&e.setState(n())},{signal:r,capture:!0}),t.addEventListener("pointercancel",()=>{s=!1},{signal:r,capture:!0}),r.addEventListener("abort",()=>{i(),a()})}}}),gt=I.createExtension(()=>({key:"history",prosemirrorPlugins:[J.history()],undoCommand:J.undo,redoCommand:J.redo})),bt=I.createExtension(({editor:o})=>{function e(r){let s=o.prosemirrorView.nodeDOM(r);for(;s&&s.parentElement;){if(s.nodeName==="A")return s;s=s.parentElement}return null}function n(r,s){return o.transact(i=>{const a=i.doc.resolve(r),c=a.marks().find(u=>u.type.name===s);if(!c)return;const l=$.getMarkRange(a,c.type);if(l)return{range:l,mark:c,get text(){return i.doc.textBetween(l.from,l.to)},get position(){return $.posToDOMRect(o.prosemirrorView,l.from,l.to).toJSON()}}})}function t(){return o.transact(r=>{const s=r.selection;if(s.empty)return n(s.anchor,"link")})}return{key:"linkToolbar",getLinkAtSelection:t,getLinkElementAtPos:e,getMarkAtPos:n,getLinkAtElement(r){return o.transact(()=>{const s=o.prosemirrorView.posAtDOM(r,0)+1;return n(s,"link")})},editLink(r,s,i=o.transact(a=>a.selection.anchor)){o.transact(a=>{const c=v.getPmSchema(a),{range:l}=n(i+1,"link")||{range:{from:a.selection.from,to:a.selection.to}};l&&(a.insertText(s,l.from,l.to),a.addMark(l.from,l.from+s.length,c.mark("link",{href:r})))}),o.prosemirrorView.focus()},deleteLink(r=o.transact(s=>s.selection.anchor)){o.transact(s=>{const i=v.getPmSchema(s),{range:a}=n(r+1,"link")||{range:{from:s.selection.from,to:s.selection.to}};a&&s.removeMark(a.from,a.to,i.marks.link).setMeta("preventAutolink",!0)}),o.prosemirrorView.focus()}}}),wt=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],yt="https",kt=new E.PluginKey("node-selection-keyboard"),Ct=I.createExtension(()=>({key:"nodeSelectionKeyboard",prosemirrorPlugins:[new E.Plugin({key:kt,props:{handleKeyDown:(o,e)=>{if("node"in o.state.selection){if(e.ctrlKey||e.metaKey)return!1;if(e.key.length===1)return e.preventDefault(),!0;if(e.key==="Enter"&&!e.isComposing&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey){const n=o.state.tr;return o.dispatch(n.insert(o.state.tr.selection.$to.after(),o.state.schema.nodes.paragraph.createChecked()).setSelection(new E.TextSelection(n.doc.resolve(o.state.tr.selection.$to.after()+1)))),!0}}return!1}}})]})),vt=new E.PluginKey("blocknote-placeholder"),St=I.createExtension(({editor:o,options:e})=>{const n=e.placeholders;return{key:"placeholder",prosemirrorPlugins:[new E.Plugin({key:vt,view:t=>{const r=`placeholder-selector-${He.v4()}`;t.dom.classList.add(r);const s=document.createElement("style"),i=o._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),t.root instanceof window.ShadowRoot?t.root.append(s):t.root.head.appendChild(s);const a=s.sheet,c=(l="")=>`.${r} .bn-block-content${l} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:l,emptyDocument:u,...h}=n||{};for(const[f,d]of Object.entries(h)){const g=`[data-content-type="${f}"]`;a.insertRule(`${c(g)} { content: ${JSON.stringify(d)}; }`)}const p="[data-is-only-empty-block]",m="[data-is-empty-and-focused]";a.insertRule(`${c(p)} { content: ${JSON.stringify(u)}; }`),a.insertRule(`${c(m)} { content: ${JSON.stringify(l)}; }`)}catch(l){console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",l)}return{destroy:()=>{t.root instanceof window.ShadowRoot?t.root.removeChild(s):t.root.head.removeChild(s)}}},props:{decorations:t=>{const{doc:r,selection:s}=t;if(!o.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];t.doc.content.size===6&&i.push(R.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,c=a.parent;if(c.content.size===0){const l=a.before();i.push(R.Decoration.node(l,l+c.nodeSize,{"data-is-empty-and-focused":"true"}))}return R.DecorationSet.create(r,i)}}})]}}),de=new E.PluginKey("previous-blocks"),xt={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Et=I.createExtension(()=>{let o;return{key:"previousBlockType",prosemirrorPlugins:[new E.Plugin({key:de,view(e){return{update:async(n,t)=>{var r;((r=this.key)==null?void 0:r.getState(n.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{n.dispatch(n.state.tr.setMeta(de,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,n,t,r){if(n.currentTransactionOldBlockAttrs={},n.updatedBlocks.clear(),!e.docChanged||t.doc.eq(r.doc))return n;const s={},i=$.findChildren(t.doc,l=>l.attrs.id),a=new Map(i.map(l=>[l.node.attrs.id,l])),c=$.findChildren(r.doc,l=>l.attrs.id);for(const l of c){const u=a.get(l.node.attrs.id),h=u==null?void 0:u.node.firstChild,p=l.node.firstChild;if(u&&h&&p){const m={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:r.doc.resolve(l.pos).depth},f={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:t.doc.resolve(u.pos).depth};s[l.node.attrs.id]=f,n.currentTransactionOldBlockAttrs[l.node.attrs.id]=f,JSON.stringify(f)!==JSON.stringify(m)&&(f["depth-change"]=f.depth-m.depth,n.updatedBlocks.add(l.node.attrs.id))}}return n.prevTransactionOldBlockAttrs=s,n}},props:{decorations(e){const n=this.getState(e);if(n.updatedBlocks.size===0)return;const t=[];return e.doc.descendants((r,s)=>{if(!r.attrs.id||!n.updatedBlocks.has(r.attrs.id))return;const i=n.currentTransactionOldBlockAttrs[r.attrs.id],a={};for(const[l,u]of Object.entries(i))a["data-prev-"+xt[l]]=u||"none";const c=R.Decoration.node(s,s+r.nodeSize,{...a});t.push(c)}),R.DecorationSet.create(e.doc,t)}}})]}});function Ce(o,e){var n,t;for(;o&&o.parentElement&&o.parentElement!==e.dom&&((n=o.getAttribute)==null?void 0:n.call(o,"data-node-type"))!=="blockContainer";)o=o.parentElement;if(((t=o.getAttribute)==null?void 0:t.call(o,"data-node-type"))==="blockContainer")return{node:o,id:o.getAttribute("data-id")}}function It(){const o=e=>{let n=e.children.length;for(let t=0;t<n;t++){const r=e.children[t];if(r.type==="element"&&(o(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(t,1,...r.children);const s=r.children.length-1;n+=s,t+=s}else e.children.splice(t,1),n--,t--}};return o}function Tt(){const o=e=>{var n;if(e.children&&"length"in e.children&&e.children.length)for(let t=e.children.length-1;t>=0;t--){const r=e.children[t],s=t+1<e.children.length?e.children[t+1]:void 0;r.type==="element"&&r.tagName==="input"&&((n=r.properties)==null?void 0:n.type)==="checkbox"&&(s==null?void 0:s.type)==="element"&&s.tagName==="p"?(s.tagName="span",s.children.splice(0,0,qe.fromDom(document.createTextNode(" ")))):o(r)}};return o}function Dt(){return o=>{Ke.visit(o,"element",(e,n,t)=>{var r,s,i,a;if(t&&e.tagName==="video"){const c=((r=e.properties)==null?void 0:r.src)||((s=e.properties)==null?void 0:s["data-url"])||"",l=((i=e.properties)==null?void 0:i.title)||((a=e.properties)==null?void 0:a["data-name"])||"";t.children[n]={type:"text",value:``}}})}}function te(o){return ze.unified().use(Xe.default,{fragment:!0}).use(Dt).use(It).use(Tt).use(We.default).use(Ge.default).use(Je.default,{handlers:{text:n=>n.value}}).processSync(o).value}function Bt(o,e,n,t){const s=ee(e,n).exportBlocks(o,t);return te(s)}function ve(o){const e=[];return o.descendants(n=>{var r,s;const t=v.getPmSchema(n);return n.type.name==="blockContainer"&&((r=n.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:n.type.name==="columnList"&&n.childCount===1?((s=n.firstChild)==null||s.forEach(i=>{e.push(v.nodeToBlock(i,t))}),!1):n.type.isInGroup("bnBlock")?(e.push(v.nodeToBlock(n,t)),!1):!0}),e}class _ extends E.Selection{constructor(n,t){super(n,t);k(this,"nodes");const r=n.node();this.nodes=[],n.doc.nodesBetween(n.pos,t.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(n,t,r=t){return new _(n.resolve(t),n.resolve(r))}content(){return new q.Slice(q.Fragment.from(this.nodes),0,0)}eq(n){if(!(n instanceof _)||this.nodes.length!==n.nodes.length||this.from!==n.from||this.to!==n.to)return!1;for(let t=0;t<this.nodes.length;t++)if(!this.nodes[t].eq(n.nodes[t]))return!1;return!0}map(n,t){const r=t.mapResult(this.from),s=t.mapResult(this.to);return s.deleted?E.Selection.near(n.resolve(r.pos)):r.deleted?E.Selection.near(n.resolve(s.pos)):new _(n.resolve(r.pos),n.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}E.Selection.jsonID("multiple-node",_);let O;function Pt(o,e){let n,t;const r=e.resolve(o.from).node().type.spec.group==="blockContent",s=e.resolve(o.to).node().type.spec.group==="blockContent",i=Math.min(o.$anchor.depth,o.$head.depth);if(r&&s){const a=o.$from.start(i-1),c=o.$to.end(i-1);n=e.resolve(a-1).pos,t=e.resolve(c+1).pos}else n=o.from,t=o.to;return{from:n,to:t}}function ue(o,e,n=e){e===n&&(n+=o.state.doc.resolve(e+1).node().nodeSize);const t=o.domAtPos(e).node.cloneNode(!0),r=o.domAtPos(e).node,s=(h,p)=>Array.prototype.indexOf.call(h.children,p),i=s(r,o.domAtPos(e+1).node.parentElement),a=s(r,o.domAtPos(n-1).node.parentElement);for(let h=r.childElementCount-1;h>=0;h--)(h>a||h<i)&&t.removeChild(t.children[h]);Se(o.root),O=t;const c=O.getElementsByTagName("iframe");for(let h=0;h<c.length;h++){const p=c[h],m=p.parentElement;m&&m.removeChild(p)}const u=o.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");O.className=O.className+" bn-drag-preview "+u,o.root instanceof ShadowRoot?o.root.appendChild(O):o.root.body.appendChild(O)}function Se(o){O!==void 0&&(o instanceof ShadowRoot?o.removeChild(O):o.body.removeChild(O),O=void 0)}function Ot(o,e,n){if(!o.dataTransfer||n.headless)return;const t=n.prosemirrorView,r=M.getNodeById(e.id,t.state.doc);if(!r)throw new Error(`Block with ID ${e.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=t.state.selection,a=t.state.doc,{from:c,to:l}=Pt(i,a),u=c<=s&&s<l,h=i.$anchor.node()!==i.$head.node()||i instanceof _;u&&h?(t.dispatch(t.state.tr.setSelection(_.create(a,c,l))),ue(t,c,l)):(t.dispatch(t.state.tr.setSelection(E.NodeSelection.create(t.state.doc,s))),ue(t,s));const p=t.state.selection.content(),m=n.pmSchema,f=t.serializeForClipboard(p).dom.innerHTML,d=ee(m,n),g=ve(p.content),w=d.exportBlocks(g,{}),y=te(w);o.dataTransfer.clearData(),o.dataTransfer.setData("blocknote/html",f),o.dataTransfer.setData("text/html",w),o.dataTransfer.setData("text/plain",y),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(O,0,0)}}const he=250;function Z(o,e,n=!0){const t=o.root.elementsFromPoint(e.left,e.top);for(const r of t)if(o.dom.contains(r))return n&&r.closest("[data-node-type=columnList]")?Z(o,{left:e.left+50,top:e.top},!1):Ce(r,o)}function Mt(o,e){if(!e.dom.firstChild)return;const n=e.dom.firstChild.getBoundingClientRect(),t={left:Math.min(Math.max(n.left+10,o.x),n.right-10),top:o.y},r=Z(e,t);if(!r)return;const s=r.node.getBoundingClientRect();return Z(e,{left:s.right-10,top:o.y},!1)}class xe{constructor(e,n,t){k(this,"state");k(this,"emitUpdate");k(this,"mousePos");k(this,"hoveredBlock");k(this,"menuFrozen",!1);k(this,"isDragOrigin",!1);k(this,"updateState",e=>{this.state=e,this.emitUpdate(this.state)});k(this,"updateStateFromMousePos",()=>{var t,r,s,i,a;if(this.menuFrozen||!this.mousePos)return;const e=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((e==null?void 0:e.element)!==this.pmView.dom||e.distance>he){(t=this.state)!=null&&t.show&&(this.state.show=!1,this.updateState(this.state));return}const n=Mt(this.mousePos,this.pmView);if(!n||!this.editor.isEditable){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.updateState(this.state));return}if(!((s=this.state)!=null&&s.show&&((i=this.hoveredBlock)!=null&&i.hasAttribute("data-id"))&&((a=this.hoveredBlock)==null?void 0:a.getAttribute("data-id"))===n.id)&&(this.hoveredBlock=n.node,this.editor.isEditable)){const c=n.node.getBoundingClientRect(),l=n.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(l?l.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,c.y,c.width,c.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});k(this,"onDragStart",e=>{var i;const n=(i=e.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!n||this.pmView.dragging)return;const t=document.createElement("div");t.innerHTML=n;const s=ie.DOMParser.fromSchema(this.pmView.state.schema).parse(t,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new ie.Slice(s.content,0,0),move:!0}});k(this,"findClosestEditorElement",e=>{const n=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(n.length===0)return null;let t=n[0],r=Number.MAX_VALUE;return n.forEach(s=>{const i=s.querySelector(".bn-block-group").getBoundingClientRect(),a=e.clientX<i.left?i.left-e.clientX:e.clientX>i.right?e.clientX-i.right:0,c=e.clientY<i.top?i.top-e.clientY:e.clientY>i.bottom?e.clientY-i.bottom:0,l=Math.sqrt(Math.pow(a,2)+Math.pow(c,2));l<r&&(r=l,t=s)}),{element:t,distance:r}});k(this,"onDragOver",e=>{var r;if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||((r=e.dataTransfer)==null?void 0:r.types.includes("blocknote/html"))||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;const t=this.getDragEventContext(e);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e)});k(this,"closeDropCursor",()=>{const e=new Event("dragleave",{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)});k(this,"getDragEventContext",e=>{var l,u;if(!(this.pmView.dragging!==null||this.isDragOrigin||((l=e.dataTransfer)==null?void 0:l.types.includes("blocknote/html"))||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;const t=!((u=e.dataTransfer)!=null&&u.types.includes("blocknote/html"))&&!!this.pmView.dragging,r=!!this.isDragOrigin,s=t||r,i=this.findClosestEditorElement(e);if(!i||i.distance>he)return;const a=i.element===this.pmView.dom,c=a&&i.distance===0;if(!(!a&&!s))return{isDropPoint:a,isDropWithinEditorBounds:c,isDragOrigin:s}});k(this,"onDrop",e=>{var a;if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||((a=e.dataTransfer)==null?void 0:a.types.includes("blocknote/html"))||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;const t=this.getDragEventContext(e);if(!t){this.closeDropCursor();return}const{isDropPoint:r,isDropWithinEditorBounds:s,isDragOrigin:i}=t;if(!s&&r&&this.dispatchSyntheticEvent(e),r){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(z.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}else if(i){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}});k(this,"onDragEnd",e=>{e.synthetic||(this.pmView.dragging=null)});k(this,"onKeyDown",e=>{var n;(n=this.state)!=null&&n.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});k(this,"onMouseMove",e=>{var s;if(this.menuFrozen)return;this.mousePos={x:e.clientX,y:e.clientY};const n=this.pmView.dom.getBoundingClientRect(),t=this.mousePos.x>n.left&&this.mousePos.x<n.right&&this.mousePos.y>n.top&&this.mousePos.y<n.bottom,r=this.pmView.dom.parentElement;if(t&&e&&e.target&&!(r===e.target||r.contains(e.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});this.editor=e,this.pmView=n,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");t(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0)}dispatchSyntheticEvent(e){const n=new Event(e.type,e),t=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=e.clientX,n.clientY=e.clientY,n.clientX=Math.min(Math.max(e.clientX,t.left),t.left+t.width),n.clientY=Math.min(Math.max(e.clientY,t.top),t.top+t.height),n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}update(e,n){var r;!n.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0)}}const Ee=new z.PluginKey("SideMenuPlugin"),At=I.createExtension(({editor:o})=>{let e;const n=I.createStore(void 0);return{key:"sideMenu",store:n,prosemirrorPlugins:[new z.Plugin({key:Ee,view:t=>(e=new xe(o,t,r=>{n.setState({...r})}),e)})],blockDragStart(t,r){e&&(e.isDragOrigin=!0),Ot(t,r,o)},blockDragEnd(){Se(o.prosemirrorView.root),e&&(e.isDragOrigin=!1),o.blur()},freezeMenu(){e.menuFrozen=!0,e.state.show=!0,e.emitUpdate(e.state)},unfreezeMenu(){e.menuFrozen=!1,e.state.show=!1,e.emitUpdate(e.state)}}});let Y;async function Lt(){return Y||(Y=(async()=>{const[o,e]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),n="default"in o?o.default:o,t="default"in e?e.default:e;return await n.init({data:t}),{emojiMart:n,emojiData:t}})(),Y)}async function Nt(o,e){if(!("text"in o.schema.inlineContentSchema)||o.schema.inlineContentSchema.text!==M.defaultInlineContentSchema.text)return[];const{emojiData:n,emojiMart:t}=await Lt();return(e.trim()===""?Object.values(n.emojis):await t.SearchIndex.search(e)).map(s=>({id:s.skins[0].native,onItemClick:()=>o.insertInlineContent(s.skins[0].native+" ")}))}let B;function me(o){B||(B=document.createElement("div"),B.innerHTML="_",B.style.opacity="0",B.style.height="1px",B.style.width="1px",o instanceof Document?o.body.appendChild(B):o.appendChild(B))}function Rt(o){B&&(o instanceof Document?o.body.removeChild(B):o.removeChild(B),B=void 0)}function j(o){return Array.prototype.indexOf.call(o.parentElement.childNodes,o)}function Vt(o){let e=o;for(;e&&e.nodeName!=="TD"&&e.nodeName!=="TH"&&!e.classList.contains("tableWrapper");){if(e.classList.contains("ProseMirror"))return;const n=e.parentNode;if(!n||!(n instanceof Element))return;e=n}return e.nodeName==="TD"||e.nodeName==="TH"?{type:"cell",domNode:e,tbodyNode:e.closest("tbody")}:{type:"wrapper",domNode:e,tbodyNode:e.querySelector("tbody")}}function Ht(o,e){const n=e.querySelectorAll(o);for(let t=0;t<n.length;t++)n[t].style.visibility="hidden"}class Ie{constructor(e,n,t){k(this,"state");k(this,"emitUpdate");k(this,"tableId");k(this,"tablePos");k(this,"tableElement");k(this,"menuFrozen",!1);k(this,"mouseState","up");k(this,"prevWasEditable",null);k(this,"viewMousedownHandler",()=>{this.mouseState="down"});k(this,"mouseUpHandler",e=>{this.mouseState="up",this.mouseMoveHandler(e)});k(this,"mouseMoveHandler",e=>{var l,u,h,p,m,f,d,g;if(this.menuFrozen||this.mouseState==="selecting"||!(e.target instanceof Element)||!this.pmView.dom.contains(e.target))return;const n=Vt(e.target);if((n==null?void 0:n.type)==="cell"&&this.mouseState==="down"&&!((l=this.state)!=null&&l.draggingState)){this.mouseState="selecting",(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n.tbodyNode)return;const t=n.tbodyNode.getBoundingClientRect(),r=Ce(n.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(w=>M.getNodeById(r.id,w.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=v.nodeToBlock(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(M.editorHasBlockWithType(this.editor,"table")&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const c=(p=n.domNode.closest(".tableWrapper"))==null?void 0:p.querySelector(".table-widgets-container");if((n==null?void 0:n.type)==="wrapper"){const w=e.clientY>=t.bottom-1&&e.clientY<t.bottom+20,y=e.clientX>=t.right-1&&e.clientX<t.right+20,b=((m=this.state)==null?void 0:m.block.id)!==s.id||e.clientX>t.right||e.clientY>t.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:w,showAddOrRemoveColumnsButton:y,referencePosTable:t,block:s,widgetContainer:c,colIndex:b||(f=this.state)==null?void 0:f.colIndex,rowIndex:b||(d=this.state)==null?void 0:d.rowIndex,referencePosCell:b||(g=this.state)==null?void 0:g.referencePosCell}}else{const w=j(n.domNode),y=j(n.domNode.parentElement),b=n.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===y&&this.state.colIndex===w)return;this.state={show:!0,showAddOrRemoveColumnsButton:w===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:t,block:s,draggingState:void 0,referencePosCell:b,colIndex:w,rowIndex:y,widgetContainer:c}}return this.emitUpdate(),!1});k(this,"dragOverHandler",e=>{var p;if(((p=this.state)==null?void 0:p.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",Ht(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const n={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)},t=this.pmView.root.elementsFromPoint(n.left,n.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(t.length===0)return;const r=t[0];let s=!1;const i=j(r.parentElement),a=j(r),c=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,u=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==c;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?n.top:n.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,s=!0),s&&this.emitUpdate(),u&&this.editor.transact(m=>m.setMeta(F,!0))});k(this,"dropHandler",e=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");e.preventDefault();const{draggingState:n,colIndex:t,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(n.draggedCellOrientation==="row"){if(!v.canRowBeDraggedInto(this.state.block,n.originalIndex,r))return!1;const i=v.moveRow(this.state.block,n.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!v.canColumnBeDraggedInto(this.state.block,n.originalIndex,t))return!1;const i=v.moveColumn(this.state.block,n.originalIndex,t),[a]=s.splice(n.originalIndex,1);s.splice(t,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=e,this.pmView=n,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");t(this.state)},n.dom.addEventListener("mousemove",this.mouseMoveHandler),n.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),n.root.addEventListener("dragover",this.dragOverHandler),n.root.addEventListener("drop",this.dropHandler)}update(){var r;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||this.state.block.type!=="table"||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:e,width:n}=v.getDimensionsOfTable(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=e&&(this.state.rowIndex=e-1),this.state.colIndex>=n&&(this.state.colIndex=n-1));const t=this.tableElement.querySelector("tbody");if(!t)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){const i=t.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=t.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const F=new E.PluginKey("TableHandlesPlugin"),_t=I.createExtension(({editor:o})=>{let e;const n=I.createStore(void 0);return{key:"tableHandles",store:n,prosemirrorPlugins:[new E.Plugin({key:F,view:t=>(e=new Ie(o,t,r=>{n.setState(r.block?{...r,draggingState:r.draggingState?{...r.draggingState}:void 0}:void 0)}),e),props:{decorations:t=>{if(e===void 0||e.state===void 0||e.state.draggingState===void 0||e.tablePos===void 0)return;const r=e.state.draggingState.draggedCellOrientation==="row"?e.state.rowIndex:e.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=e.state,{originalIndex:c,draggedCellOrientation:l}=a;if(r===c||!i||l==="row"&&!v.canRowBeDraggedInto(i,c,r)||l==="col"&&!v.canColumnBeDraggedInto(i,c,r))return R.DecorationSet.create(t.doc,s);const u=t.doc.resolve(e.tablePos+1);return e.state.draggingState.draggedCellOrientation==="row"?v.getCellsAtRowHandle(e.state.block,r).forEach(({row:p,col:m})=>{const f=t.doc.resolve(u.posAtIndex(p)+1),d=t.doc.resolve(f.posAtIndex(m)+1),g=d.node(),w=d.pos+(r>c?g.nodeSize-2:0);s.push(R.Decoration.widget(w,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.left="0",y.style.right="0",r>c?y.style.bottom="-2px":y.style.top="-3px",y.style.height="4px",y}))}):v.getCellsAtColumnHandle(e.state.block,r).forEach(({row:p,col:m})=>{const f=t.doc.resolve(u.posAtIndex(p)+1),d=t.doc.resolve(f.posAtIndex(m)+1),g=d.node(),w=d.pos+(r>c?g.nodeSize-2:0);s.push(R.Decoration.widget(w,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.top="0",y.style.bottom="0",r>c?y.style.right="-2px":y.style.left="-3px",y.style.width="4px",y}))}),R.DecorationSet.create(t.doc,s)}}})],colDragStart(t){if(e===void 0||e.state===void 0||e.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");e.state.draggingState={draggedCellOrientation:"col",originalIndex:e.state.colIndex,mousePos:t.clientX},e.emitUpdate(),o.transact(r=>r.setMeta(F,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.colIndex,newIndex:e.state.colIndex,tablePos:e.tablePos})),!o.headless&&(me(o.prosemirrorView.root),t.dataTransfer.setDragImage(B,0,0),t.dataTransfer.effectAllowed="move")},rowDragStart(t){if(e.state===void 0||e.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");e.state.draggingState={draggedCellOrientation:"row",originalIndex:e.state.rowIndex,mousePos:t.clientY},e.emitUpdate(),o.transact(r=>r.setMeta(F,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.rowIndex,newIndex:e.state.rowIndex,tablePos:e.tablePos})),!o.headless&&(me(o.prosemirrorView.root),t.dataTransfer.setDragImage(B,0,0),t.dataTransfer.effectAllowed="copyMove")},dragEnd(){if(e.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");e.state.draggingState=void 0,e.emitUpdate(),o.transact(t=>t.setMeta(F,null)),!o.headless&&Rt(o.prosemirrorView.root)},freezeHandles(){e.menuFrozen=!0},unfreezeHandles(){e.menuFrozen=!1},getCellsAtRowHandle(t,r){return v.getCellsAtRowHandle(t,r)},getCellsAtColumnHandle(t,r){return v.getCellsAtColumnHandle(t,r)},setCellSelection(t,r,s=r){if(!e)throw new Error("Table handles view not initialized");const i=t.doc.resolve(e.tablePos+1),a=t.doc.resolve(i.posAtIndex(r.row)+1),c=t.doc.resolve(a.posAtIndex(r.col)),l=t.doc.resolve(i.posAtIndex(s.row)+1),u=t.doc.resolve(l.posAtIndex(s.col)),h=t.tr;return h.setSelection(new L.CellSelection(c,u)),t.apply(h)},addRowOrColumn(t,r){o.exec((s,i)=>{const a=this.setCellSelection(s,r.orientation==="row"?{row:t,col:0}:{row:0,col:t});return r.orientation==="row"?r.side==="above"?L.addRowBefore(a,i):L.addRowAfter(a,i):r.side==="left"?L.addColumnBefore(a,i):L.addColumnAfter(a,i)})},removeRowOrColumn(t,r){return r==="row"?o.exec((s,i)=>{const a=this.setCellSelection(s,{row:t,col:0});return L.deleteRow(a,i)}):o.exec((s,i)=>{const a=this.setCellSelection(s,{row:0,col:t});return L.deleteColumn(a,i)})},mergeCells(t){return o.exec((r,s)=>{const i=t?this.setCellSelection(r,t.relativeStartCell,t.relativeEndCell):r;return L.mergeCells(i,s)})},splitCell(t){return o.exec((r,s)=>{const i=t?this.setCellSelection(r,t):r;return L.splitCell(i,s)})},getCellSelection(){return o.transact(t=>{const r=t.selection;let s=r.$from,i=r.$to;if(M.isTableCellSelection(r)){const{ranges:d}=r;d.forEach(g=>{s=g.$from.min(s??g.$from),i=g.$to.max(i??g.$to)})}else if(s=t.doc.resolve(r.$from.pos-r.$from.parentOffset-1),i=t.doc.resolve(r.$to.pos-r.$to.parentOffset-1),s.pos===0||i.pos===0)return;const a=t.doc.resolve(s.pos-s.parentOffset-1),c=t.doc.resolve(i.pos-i.parentOffset-1),l=t.doc.resolve(a.pos-a.parentOffset-1),u=s.index(a.depth),h=a.index(l.depth),p=i.index(c.depth),m=c.index(l.depth),f=[];for(let d=h;d<=m;d++)for(let g=u;g<=p;g++)f.push({row:d,col:g});return{from:{row:h,col:u},to:{row:m,col:p},cells:f}})},getMergeDirection(t){return o.transact(r=>{const s=M.isTableCellSelection(r.selection)?r.selection:void 0;if(!s||!t||s.ranges.length<=1)return;const i=this.getCellSelection();if(i)return v.areInSameColumn(i.from,i.to,t)?"vertical":"horizontal"})},cropEmptyRowsOrColumns(t,r){return v.cropEmptyRowsOrColumns(t,r)},addRowsOrColumns(t,r,s){return v.addRowsOrColumns(t,r,s)}}}),fe=new E.PluginKey("trailingNode"),Ft=I.createExtension(()=>({key:"trailingNode",prosemirrorPlugins:[new E.Plugin({key:fe,appendTransaction:(o,e,n)=>{const{doc:t,tr:r,schema:s}=n,i=fe.getState(n),a=t.content.size-2,c=s.nodes.blockContainer,l=s.nodes.paragraph;if(i)return r.insert(a,c.create(void 0,l.create()))},state:{init:(o,e)=>{},apply:(o,e)=>{if(!o.docChanged)return e;let n=o.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")return!0;const t=n.firstChild;if(!t)throw new Error("Expected blockContent");return n.nodeSize>4||t.type.spec.content!=="inline*"}}})]}));exports.BlockChangeExtension=nt;exports.DEFAULT_LINK_PROTOCOL=yt;exports.DRAG_EXCLUSION_CLASSNAME=ke;exports.DropCursorExtension=ft;exports.ForkYDocExtension=it;exports.FormattingToolbarExtension=pt;exports.HistoryExtension=gt;exports.LinkToolbarExtension=bt;exports.NodeSelectionKeyboardExtension=Ct;exports.PlaceholderExtension=St;exports.PreviousBlockTypeExtension=Et;exports.SchemaMigration=ct;exports.SideMenuExtension=At;exports.SideMenuView=xe;exports.TableHandlesExtension=_t;exports.TableHandlesView=Ie;exports.TrailingNodeExtension=Ft;exports.VALID_LINK_PROTOCOLS=wt;exports.YCursorExtension=Q;exports.YSyncExtension=X;exports.YUndoExtension=W;exports.blocksToMarkdown=Bt;exports.cleanHTMLToMarkdown=te;exports.createExternalHTMLExporter=ee;exports.fragmentToBlocks=ve;exports.getBlocksChangedByTransaction=we;exports.getDefaultEmojiPickerItems=Nt;exports.sideMenuPluginKey=Ee;exports.tableHandlesPluginKey=F;
|
|
2
|
+
//# sourceMappingURL=TrailingNode-n0WdMPUl.cjs.map
|