@blocknote/core 0.51.2 → 0.51.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +3 -3
- package/dist/{blocks-KyMOxPT3.cjs → blocks-Bm6IfL1R.cjs} +2 -2
- package/dist/{blocks-KyMOxPT3.cjs.map → blocks-Bm6IfL1R.cjs.map} +1 -1
- package/dist/{blocks-D0lMxErU.js → blocks-DGsP5WKr.js} +4 -5
- package/dist/{blocks-D0lMxErU.js.map → blocks-DGsP5WKr.js.map} +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +1 -1
- package/dist/{extensions-D2mx2C9y.js → extensions-Co4y7P63.js} +2 -2
- package/dist/{extensions-D2mx2C9y.js.map → extensions-Co4y7P63.js.map} +1 -1
- package/dist/{extensions-Cutrafjg.cjs → extensions-IJK3t0sz.cjs} +2 -2
- package/dist/{extensions-Cutrafjg.cjs.map → extensions-IJK3t0sz.cjs.map} +1 -1
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +2 -2
- package/dist/{src-D5R5YzV7.cjs → src-B6rlChSc.cjs} +2 -2
- package/dist/{src-D5R5YzV7.cjs.map → src-B6rlChSc.cjs.map} +1 -1
- package/dist/{src-Dvmif2FY.js → src-Bcud0PIg.js} +3 -3
- package/dist/{src-Dvmif2FY.js.map → src-Bcud0PIg.js.map} +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.js +1 -1
- package/package.json +1 -1
- package/src/blocks/Table/TableExtension.test.ts +126 -0
- package/src/blocks/Table/TableExtension.ts +3 -14
- package/src/editor/Block.css +18 -0
- package/src/editor/BlockNoteEditor.test.ts +19 -1
- package/types/src/blocks/Table/TableExtension.test.d.ts +1 -0
package/dist/extensions.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./blocks-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./blocks-Bm6IfL1R.cjs`),t=require(`./extensions-IJK3t0sz.cjs`),n=require(`./ShowSelection-DhXglbt8.cjs`);exports.BlockChangeExtension=t.E,exports.DEFAULT_LINK_PROTOCOL=t.h,exports.DRAG_EXCLUSION_CLASSNAME=t.y,exports.DropCursorExtension=t.b,exports.FilePanelExtension=e.mt,exports.ForkYDocExtension=t.S,exports.FormattingToolbarExtension=e.m,exports.HistoryExtension=t.v,exports.LinkToolbarExtension=t._,exports.NodeSelectionKeyboardExtension=t.m,exports.PlaceholderExtension=t.p,exports.PreviousBlockTypeExtension=t.f,exports.SchemaMigration=t.x,exports.ShowSelectionExtension=n.t,exports.SideMenuExtension=t.o,exports.SideMenuView=t.s,exports.SuggestionMenu=e.f,exports.TableHandlesExtension=t.n,exports.TableHandlesView=t.r,exports.TrailingNodeExtension=t.t,exports.VALID_LINK_PROTOCOLS=t.g,exports.YCursorExtension=t.T,exports.YSyncExtension=t.w,exports.YUndoExtension=t.C,exports.filterSuggestionItems=e.l,exports.getDefaultEmojiPickerItems=t.a,exports.getDefaultSlashMenuItems=e.u,exports.insertOrUpdateBlockForSlashMenu=e.d,exports.sideMenuPluginKey=t.c,exports.tableHandlesPluginKey=t.i;
|
package/dist/extensions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as e, f as t, l as n, m as r, mt as i, u as a } from "./blocks-
|
|
2
|
-
import { C as o, E as s, S as c, T as l, _ as u, a as d, b as f, c as p, f as m, g as h, h as g, i as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, v as T, w as E, x as D, y as O } from "./extensions-
|
|
1
|
+
import { d as e, f as t, l as n, m as r, mt as i, u as a } from "./blocks-DGsP5WKr.js";
|
|
2
|
+
import { C as o, E as s, S as c, T as l, _ as u, a as d, b as f, c as p, f as m, g as h, h as g, i as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, v as T, w as E, x as D, y as O } from "./extensions-Co4y7P63.js";
|
|
3
3
|
import { t as k } from "./ShowSelection-BsHFfdMi.js";
|
|
4
4
|
export { s as BlockChangeExtension, g as DEFAULT_LINK_PROTOCOL, O as DRAG_EXCLUSION_CLASSNAME, f as DropCursorExtension, i as FilePanelExtension, c as ForkYDocExtension, r as FormattingToolbarExtension, T as HistoryExtension, u as LinkToolbarExtension, v as NodeSelectionKeyboardExtension, x as PlaceholderExtension, m as PreviousBlockTypeExtension, D as SchemaMigration, k as ShowSelectionExtension, b as SideMenuExtension, C as SideMenuView, t as SuggestionMenu, y as TableHandlesExtension, S as TableHandlesView, w as TrailingNodeExtension, h as VALID_LINK_PROTOCOLS, l as YCursorExtension, E as YSyncExtension, o as YUndoExtension, n as filterSuggestionItems, d as getDefaultEmojiPickerItems, a as getDefaultSlashMenuItems, e as insertOrUpdateBlockForSlashMenu, p as sideMenuPluginKey, _ as tableHandlesPluginKey };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./BlockNoteExtension-ab0REuob.cjs`),t=require(`./blocks-
|
|
1
|
+
const e=require(`./BlockNoteExtension-ab0REuob.cjs`),t=require(`./blocks-Bm6IfL1R.cjs`),n=require(`./extensions-IJK3t0sz.cjs`),r=require(`./ShowSelection-DhXglbt8.cjs`),i=require(`./en-Cj5r8sW_.cjs`),a=require(`./EventEmitter-DHdSnYCD.cjs`);let o=require(`prosemirror-model`),s=require(`prosemirror-transform`),c=require(`@tiptap/core`),l=require(`prosemirror-state`),u=require(`@tiptap/pm/model`),d=require(`prosemirror-tables`),f=require(`@tiptap/pm/state`),p=require(`@handlewithcare/prosemirror-inputrules`),m=require(`@tiptap/pm/keymap`),h=require(`@tiptap/extensions/gap-cursor`),g=require(`@tiptap/extension-text`);function _(e,t){let n=[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:e=>{let t=e;return t.matches(`[data-editable]`)?t:t.querySelector(`[data-editable]`)||t}}];return t&&n.push({tag:`*`,getAttrs(e){if(typeof e==`string`)return!1;let n=t?.(e);return n===void 0?!1:n}}),n}function ee(e,n){return t.$t(c.Node.create({name:e.type,inline:!0,group:`inline`,draggable:n.meta?.draggable,selectable:e.content===`styled`,atom:e.content===`none`,content:e.content===`styled`?`inline*`:``,addAttributes(){return t.Dn(e.propSchema)},addKeyboardShortcuts(){return t.Qt(e)},parseHTML(){return _(e,n.parse)},renderHTML({node:r}){let i=this.options.editor;return t.Zt(n.render.call({renderType:`dom`,props:void 0},t.on(r,i.schema.inlineContentSchema,i.schema.styleSchema),()=>{},i),e.type,r.attrs,e.propSchema)},addNodeView(){return r=>{let{node:i,getPos:a}=r,o=this.options.editor;return t.Zt(n.render.call({renderType:`nodeView`,props:r},t.on(i,o.schema.inlineContentSchema,o.schema.styleSchema),e=>{let n=t.At([e],o.pmSchema),r=a();r&&o.transact(e=>e.replaceWith(r,r+i.nodeSize,n))},o),e.type,i.attrs,e.propSchema)}}}),e.propSchema,{...n,toExternalHTML:n.toExternalHTML,render(r,i,a){return t.Zt(n.render(r,i,a),e.type,r.props,e.propSchema)}})}function te(e,n,r,i=`before`){let a=typeof r==`string`?r:r.id,c=t.fn(e),l=n.map(e=>{let n=t.kt(e,c);return n.check(),n}),u=t.Dt(a,e.doc);if(!u)throw Error(`Block with ID ${a} not found`);let d=u.posBeforeNode;return i===`after`&&(d+=u.node.nodeSize),e.step(new s.ReplaceStep(d,d,new o.Slice(o.Fragment.from(l),0,0))),l.map(e=>t.an(e,c))}function v(e){if(!e||e.type.name!==`column`)throw Error(`Invalid columnPos: does not point to column node.`);let t=e.firstChild;if(!t)throw Error(`Invalid column: does not have child node.`);let n=t.firstChild;if(!n)throw Error(`Invalid blockContainer: does not have child node.`);return e.childCount===1&&t.childCount===1&&n.type.name===`paragraph`&&n.content.content.length===0}function y(e,t){let n=e.doc.resolve(t),r=n.nodeAfter;if(!r||r.type.name!==`columnList`)throw Error(`Invalid columnListPos: does not point to columnList node.`);for(let t=r.childCount-1;t>=0;t--){let r=e.doc.resolve(n.pos+1).posAtIndex(t),i=e.doc.resolve(r).nodeAfter;if(!i||i.type.name!==`column`)throw Error(`Invalid columnPos: does not point to column node.`);v(i)&&e.delete(r,r+i.nodeSize)}}function b(e,t){y(e,t);let n=e.doc.resolve(t).nodeAfter;if(!n||n.type.name!==`columnList`)throw Error(`Invalid columnListPos: does not point to columnList node.`);if(n.childCount>2)return;if(n.childCount<2)throw Error(`Invalid columnList: contains fewer than two children.`);let r=t+1,i=e.doc.resolve(r).nodeAfter,a=t+n.nodeSize-1,c=e.doc.resolve(a).nodeBefore;if(!i||!c)throw Error(`Invalid columnList: does not contain children.`);let l=v(i),u=v(c);if(l&&u){e.delete(t,t+n.nodeSize);return}if(l){e.step(new s.ReplaceAroundStep(t,t+n.nodeSize,a-c.nodeSize+1,a-1,o.Slice.empty,0,!1));return}if(u){e.step(new s.ReplaceAroundStep(t,t+n.nodeSize,r+1,r+i.nodeSize-1,o.Slice.empty,0,!1));return}}function x(e,n,r){let i=t.fn(e),a=r.map(e=>{let n=t.kt(e,i);return n.check(),n}),o=new Set(n.map(e=>typeof e==`string`?e:e.id)),s=[],c=new Set,l=typeof n[0]==`string`?n[0]:n[0].id,u=0;if(e.doc.descendants((n,d)=>{if(o.size===0)return!1;if(!n.type.isInGroup(`bnBlock`)||!o.has(n.attrs.id))return!0;if(s.push(t.an(n,i)),o.delete(n.attrs.id),r.length>0&&n.attrs.id===l){let t=e.doc.nodeSize;e.insert(d,a);let n=e.doc.nodeSize;u+=t-n}let f=e.doc.nodeSize,p=e.doc.resolve(d-u);p.node().type.name===`column`?c.add(p.before(-1)):p.node().type.name===`columnList`&&c.add(p.before()),p.node().type.name===`blockGroup`&&p.node(p.depth-1).type.name!==`doc`&&p.node().childCount===1?e.delete(p.before(),p.after()):e.delete(d-u,d-u+n.nodeSize);let m=e.doc.nodeSize;return u+=f-m,!1}),o.size>0){let e=[...o].join(`
|
|
2
2
|
`);throw Error(`Blocks with the following IDs could not be found in the editor: `+e)}return c.forEach(t=>b(e,t)),{insertedBlocks:a.map(e=>t.an(e,i)),removedBlocks:s}}function ne(e,n,r,i,a){let s;if(!n)throw Error(`blockContent is required`);if(typeof n==`string`)s=t.At([n],e.pmSchema,i);else if(Array.isArray(n))s=t.At(n,e.pmSchema,i);else if(n.type===`tableContent`)s=t.jt(n,e.pmSchema);else throw new t.zn(n.type);let c=(a?.document??document).createDocumentFragment();for(let n of s)if(n.type.name!==`text`&&e.schema.inlineContentSchema[n.type.name]){let i=e.schema.inlineContentSpecs[n.type.name].implementation;if(i){let o=t.on(n,e.schema.inlineContentSchema,e.schema.styleSchema),s=i.render.call({renderType:`dom`,props:void 0},o,()=>{},e);if(s){if(c.appendChild(s.dom),s.contentDOM){let e=r.serializeFragment(n.content,a);s.contentDOM.dataset.editable=``,s.contentDOM.appendChild(e)}continue}}}else if(n.type.name===`text`){let t=document.createTextNode(n.textContent);for(let r of n.marks.toReversed())if(r.type.name in e.schema.styleSpecs){let n=e.schema.styleSpecs[r.type.name].implementation.render(r.attrs.stringValue,e);n.contentDOM.appendChild(t),t=n.dom}else{let e=r.type.spec.toDOM(r,!0),n=o.DOMSerializer.renderSpec(document,e);n.contentDOM.appendChild(t),t=n.dom}c.appendChild(t)}else{let e=r.serializeFragment(o.Fragment.from([n]),a);c.appendChild(e)}return c}function re(e,t,n,r){let i=e.pmSchema.nodes.blockContainer,a=t.props||{};for(let[n,r]of Object.entries(e.schema.blockSchema[t.type].propSchema))!(n in a)&&r.default!==void 0&&(a[n]=r.default);let o=t.children||[],s=e.blockImplementations[t.type].implementation.render.call({renderType:`dom`,props:void 0},{...t,props:a,children:o},e);if(s.contentDOM&&t.content){let i=ne(e,t.content,n,t.type,r);s.contentDOM.appendChild(i)}if(e.pmSchema.nodes[t.type].isInGroup(`bnBlock`)){if(t.children&&t.children.length>0){let i=ie(e,t.children,n,r);s.contentDOM?.append(i)}return s.dom}let c=i.spec?.toDOM?.(i.create({id:t.id,...a}));return c.contentDOM?.appendChild(s.dom),t.children&&t.children.length>0&&c.contentDOM?.appendChild(ae(e,t.children,n,r)),c.dom}function ie(e,t,n,r){let i=(r?.document??document).createDocumentFragment();for(let a of t){let t=re(e,a,n,r);i.appendChild(t)}return i}var ae=(e,t,n,r)=>{let i=e.pmSchema.nodes.blockGroup,a=i.spec.toDOM(i.create({})),o=ie(e,t,n,r);return a.contentDOM?.appendChild(o),a.dom},oe=e=>(e.querySelectorAll(`[data-content-type="numberedListItem"]`).forEach(e=>{let t=e.closest(`.bn-block-outer`)?.previousElementSibling?.querySelector(`[data-content-type="numberedListItem"]`);if(!t)e.setAttribute(`data-index`,e.getAttribute(`data-start`)||`1`);else{let n=t.getAttribute(`data-index`);e.setAttribute(`data-index`,(parseInt(n||`0`)+1).toString())}}),e),se=e=>(e.querySelectorAll(`[data-content-type="checkListItem"] input`).forEach(e=>{e.disabled=!0}),e),ce=e=>(e.querySelectorAll(`.bn-toggle-wrapper[data-show-children="false"]`).forEach(e=>{e.setAttribute(`data-show-children`,`true`)}),e),le=e=>(e.querySelectorAll(`[data-content-type="table"] table`).forEach(e=>{e.setAttribute(`style`,`--default-cell-min-width: 120px;`),e.setAttribute(`data-show-children`,`true`)}),e),ue=e=>(e.querySelectorAll(`[data-content-type="table"] table`).forEach(e=>{let t=document.createElement(`div`);t.className=`tableWrapper`;let n=document.createElement(`div`);n.className=`tableWrapper-inner`,t.appendChild(n),e.parentElement?.appendChild(t),t.appendChild(e)}),e),de=e=>(e.querySelectorAll(`.bn-inline-content:empty`).forEach(e=>{let t=document.createElement(`span`);t.className=`ProseMirror-trailingBreak`,t.setAttribute(`style`,`display: inline-block;`),e.appendChild(t)}),e),fe=(e,t)=>{let n=o.DOMSerializer.fromSchema(e),r=[oe,se,ce,le,ue,de];return{serializeBlocks:(e,i)=>{let a=ae(t,e,n,i);for(let e of r)a=e(a);return a.outerHTML}}};function pe(e){return e.transact(e=>{let n=t.yn(e.doc,e.selection.anchor);if(e.selection instanceof d.CellSelection)return{type:`cell`,anchorBlockId:n.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-n.posBeforeNode,headCellOffset:e.selection.$headCell.pos-n.posBeforeNode};if(e.selection instanceof l.NodeSelection)return{type:`node`,anchorBlockId:n.node.attrs.id};{let r=t.yn(e.doc,e.selection.head);return{type:`text`,anchorBlockId:n.node.attrs.id,headBlockId:r.node.attrs.id,anchorOffset:e.selection.anchor-n.posBeforeNode,headOffset:e.selection.head-r.posBeforeNode}}})}function me(e,n){let r=t.Dt(n.anchorBlockId,e.doc)?.posBeforeNode;if(r===void 0)throw Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let i;if(n.type===`cell`)i=d.CellSelection.create(e.doc,r+n.anchorCellOffset,r+n.headCellOffset);else if(n.type===`node`)i=l.NodeSelection.create(e.doc,r+1);else{let a=t.Dt(n.headBlockId,e.doc)?.posBeforeNode;if(a===void 0)throw Error(`Could not find block with ID ${n.headBlockId} to update selection`);i=l.TextSelection.create(e.doc,r+n.anchorOffset,a+n.headOffset)}e.setSelection(i)}function he(e){return e.flatMap(e=>e.type===`column`?e.children:[e])}function S(e,t,n,r){e.transact(()=>{let i=e.getBlock(n);if(i?.type===`columnList`){let t=r===`after`?e.getNextBlock(i):e.getPrevBlock(i);t&&(n=t,r=r===`after`?`before`:`after`)}e.removeBlocks(t),e.insertBlocks(he(t),n,r)})}function C(e,t,n){e.transact(r=>{let i=e.getSelection()?.blocks||[e.getTextCursorPosition().block],a=pe(e);S(e,i,t,n),me(r,a)})}function w(e){return!e||e.type!==`columnList`}function T(e,t,n){let r,i;if(t?t.children.length>0?(r=t.children[t.children.length-1],i=`after`):(r=t,i=`before`):n&&(r=n,i=`before`),!r||!i)return;let a=e.getParentBlock(r);return w(a)?{referenceBlock:r,placement:i}:T(e,i===`after`?r:e.getPrevBlock(r),a)}function E(e,t,n){let r,i;if(t?t.children.length>0?(r=t.children[0],i=`before`):(r=t,i=`after`):n&&(r=n,i=`after`),!r||!i)return;let a=e.getParentBlock(r);return w(a)?{referenceBlock:r,placement:i}:E(e,i===`before`?r:e.getNextBlock(r),a)}function ge(e,t){e.transact(()=>{let n;if(t){if(n=e.getBlock(t),!n)return}else n=e.getSelection()?.blocks[0]||e.getTextCursorPosition().block;let r=T(e,e.getPrevBlock(n),e.getParentBlock(n));r&&(t?S(e,[n],r.referenceBlock,r.placement):C(e,r.referenceBlock,r.placement))})}function _e(e,t){e.transact(()=>{let n;if(t){if(n=e.getBlock(t),!n)return}else{let t=e.getSelection();n=t?.blocks[t?.blocks.length-1]||e.getTextCursorPosition().block}let r=E(e,e.getNextBlock(n),e.getParentBlock(n));r&&(t?S(e,[n],r.referenceBlock,r.placement):C(e,r.referenceBlock,r.placement))})}function ve(e,t,n){let{$from:r,$to:i}=e.selection,a=r.blockRange(i,e=>e.childCount>0&&(e.type.name===`blockGroup`||e.type.name===`column`));if(!a)return!1;let c=a.startIndex;if(c===0)return!1;let l=a.parent.child(c-1);if(l.type!==t)return!1;let u=l.lastChild&&l.lastChild.type===n,d=o.Fragment.from(u?t.create():null),f=new o.Slice(o.Fragment.from(t.create(null,o.Fragment.from(n.create(null,d)))),u?3:1,0),p=a.start,m=a.end;return e.step(new s.ReplaceAroundStep(p-(u?3:1),m,p,m,f,1,!0)).scrollIntoView(),!0}function D(e){return e.transact(t=>ve(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function ye(e,t,n,r){let i=r.end,a=r.$to.end(r.depth);if(i<a){let c=r.parent.child(r.endIndex-1),l=c.lastChild&&c.lastChild.type===n;e.step(new s.ReplaceAroundStep(i-(l?2:1),a,i,a,new o.Slice(o.Fragment.from(t.create(null,n.create())),l?2:1,0),+!l,!0)),r=new o.NodeRange(e.doc.resolve(r.$from.pos),e.doc.resolve(a),r.depth)}let c=(0,s.liftTarget)(r);if(c==null)return!1;e.lift(r,c);let l=e.doc.resolve(e.mapping.map(i,-1)-1);return(0,s.canJoin)(e.doc,l.pos)&&l.nodeBefore.type===l.nodeAfter.type&&e.join(l.pos),e.scrollIntoView(),!0}function O(e,t,n){let{$from:r,$to:i}=e.selection,a=r.blockRange(i,e=>e.childCount>0&&(e.type.name===`blockGroup`||e.type.name===`column`));return a&&r.node(a.depth-1).type===t?ye(e,t,n,a):!1}function be(e){return e.transact(t=>O(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function xe(e){return e.transact(e=>{let{bnBlock:n}=t._n(e);return e.doc.resolve(n.beforePos).nodeBefore!==null})}function Se(e){return e.transact(e=>{let{bnBlock:n}=t._n(e);return e.doc.resolve(n.beforePos).depth>1})}function Ce(e,n){let r=typeof n==`string`?n:n.id,i=t.fn(e),a=t.Dt(r,e);if(a)return t.an(a.node,i)}function we(e,n){let r=t.Dt(typeof n==`string`?n:n.id,e),i=t.fn(e);if(!r)return;let a=e.resolve(r.posBeforeNode).nodeBefore;if(a)return t.an(a,i)}function Te(e,n){let r=t.Dt(typeof n==`string`?n:n.id,e),i=t.fn(e);if(!r)return;let a=e.resolve(r.posBeforeNode+r.node.nodeSize).nodeAfter;if(a)return t.an(a,i)}function Ee(e,n){let r=typeof n==`string`?n:n.id,i=t.fn(e),a=t.Dt(r,e);if(!a)return;let o=e.resolve(a.posBeforeNode),s=o.node(),c=o.node(-1),l=c.type.name===`doc`?void 0:s.type.name===`blockGroup`?c:s;if(l)return t.an(l,i)}var De=class{constructor(e){this.editor=e}get document(){return this.editor.transact(e=>t.in(e.doc,this.editor.pmSchema))}getBlock(e){return this.editor.transact(t=>Ce(t.doc,e))}getPrevBlock(e){return this.editor.transact(t=>we(t.doc,e))}getNextBlock(e){return this.editor.transact(t=>Te(t.doc,e))}getParentBlock(e){return this.editor.transact(t=>Ee(t.doc,e))}forEachBlock(e,t=!1){let n=this.document.slice();t&&n.reverse();function r(n){for(let i of n)if(e(i)===!1||!r(t?i.children.slice().reverse():i.children))return!1;return!0}r(n)}insertBlocks(e,t,n=`before`){return this.editor.transact(r=>te(r,e,t,n))}updateBlock(e,n){return this.editor.transact(r=>t.wt(r,e,n))}removeBlocks(e){return this.editor.transact(t=>x(t,e,[]).removedBlocks)}replaceBlocks(e,t){return this.editor.transact(n=>x(n,e,t))}canNestBlock(){return xe(this.editor)}nestBlock(){D(this.editor)}canUnnestBlock(){return Se(this.editor)}unnestBlock(){be(this.editor)}moveBlocksUp(e){return ge(this.editor,e)}moveBlocksDown(e){return _e(this.editor,e)}},Oe=class extends a.t{constructor(e){super(),this.editor=e,e.on(`create`,()=>{e._tiptapEditor.on(`update`,({transaction:t,appendedTransactions:n})=>{this.emit(`onChange`,{editor:e,transaction:t,appendedTransactions:n})}),e._tiptapEditor.on(`selectionUpdate`,({transaction:t})=>{this.emit(`onSelectionChange`,{editor:e,transaction:t})}),e._tiptapEditor.on(`mount`,()=>{this.emit(`onMount`,{editor:e})}),e._tiptapEditor.on(`unmount`,()=>{this.emit(`onUnmount`,{editor:e})})})}onChange(e,t=!0){let r=({transaction:r,appendedTransactions:i})=>{!t&&ke(r)||e(this.editor,{getChanges(){return n.D(r,i)}})};return this.on(`onChange`,r),()=>{this.off(`onChange`,r)}}onSelectionChange(e,t=!1){let n=n=>{!t&&ke(n.transaction)||e(this.editor)};return this.on(`onSelectionChange`,n),()=>{this.off(`onSelectionChange`,n)}}onMount(e){return this.on(`onMount`,e),()=>{this.off(`onMount`,e)}}onUnmount(e){return this.on(`onUnmount`,e),()=>{this.off(`onUnmount`,e)}}};function ke(e){return!!e.getMeta(`y-sync$`)}function Ae(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function je(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||``)}function Me(e){e.querySelectorAll(`li > ul, li > ol`).forEach(e=>{let t=Ae(e),n=e.parentElement,r=Array.from(n.childNodes).slice(t+1);e.remove(),r.forEach(e=>{e.remove()}),n.insertAdjacentElement(`afterend`,e),r.reverse().forEach(t=>{if(je(t))return;let n=document.createElement(`li`);n.append(t),e.insertAdjacentElement(`afterend`,n)}),n.childNodes.length===0&&n.remove()})}function Ne(e){e.querySelectorAll(`li + ul, li + ol`).forEach(e=>{let t=e.previousElementSibling,n=document.createElement(`div`);t.insertAdjacentElement(`afterend`,n),n.append(t);let r=document.createElement(`div`);for(r.setAttribute(`data-node-type`,`blockGroup`),n.append(r);n.nextElementSibling?.nodeName===`UL`||n.nextElementSibling?.nodeName===`OL`;)r.append(n.nextElementSibling)})}var Pe=null;function Fe(){return Pe||=document.implementation.createHTMLDocument(`title`)}function Ie(e){if(typeof e==`string`){let t=Fe().createElement(`div`);t.innerHTML=e,e=t}return Me(e),Ne(e),e}function Le(e){let t=e.ownerDocument.createTreeWalker(e,128),n;for(;n=t.nextNode();)if(/^\s*notionvc:/.test(n.nodeValue||``))return!0;return!1}function Re(e){let t=new Set([`PRE`,`CODE`]),n=e.ownerDocument.createTreeWalker(e,4,{acceptNode(n){let r=n.parentElement;for(;r&&r!==e;){if(t.has(r.tagName))return 2;r=r.parentElement}return 1}}),r=[],i;for(;i=n.nextNode();)r.push(i);for(let e of r)e.nodeValue&&/[\r\n]/.test(e.nodeValue)&&(e.nodeValue=e.nodeValue.replace(/[ \t\r\n\f]+/g,` `))}function ze(e){Le(e)||Re(e)}function k(e,n){let r=Ie(e);ze(r);let i=o.DOMParser.fromSchema(n).parse(r,{topNode:n.nodes.blockGroup.create()}),a=[];for(let e=0;e<i.childCount;e++)a.push(t.an(i.child(e),n));return a}function A(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function Be(e){return e?/\w/.test(e):!1}function j(e,t,n){let r=t>0?e[t-1]:void 0,i=t+n<e.length?e[t+n]:void 0;return Be(r)&&Be(i)}function Ve(e,t){if(e[t]!==`\\`||t+1>=e.length)return null;let n=e[t+1];return n===`
|
|
3
3
|
`?{html:`<br>
|
|
4
4
|
`,end:t+2}:"\\`*_{}[]()#+-.!~|>".includes(n)?{html:A(n),end:t+2}:null}function He(e,t){return e[t]==="`"?it(e,t):null}function Ue(e,t){return e[t]!==`!`||e[t+1]!==`[`?null:at(e,t)}function We(e,t){return e[t]===`[`?ot(e,t):null}function Ge(e,t){return e[t]!==`~`||e[t+1]!==`~`?null:P(e,t,`~~`,`<del>`,`</del>`)}function Ke(e,t){return e[t]===`*`&&e[t+1]===`*`&&e[t+2]===`*`||e[t]===`_`&&e[t+1]===`_`&&e[t+2]===`_`&&!j(e,t,3)?P(e,t,e.substring(t,t+3),`<strong><em>`,`</em></strong>`):null}function qe(e,t){return e[t]===`*`&&e[t+1]===`*`||e[t]===`_`&&e[t+1]===`_`&&!j(e,t,2)?P(e,t,e.substring(t,t+2),`<strong>`,`</strong>`):null}function Je(e,t){return e[t]===`*`||e[t]===`_`&&!j(e,t,1)?P(e,t,e[t],`<em>`,`</em>`):null}function Ye(e,t){return e[t]===`
|
|
@@ -18,4 +18,4 @@ const e=require(`./BlockNoteExtension-ab0REuob.cjs`),t=require(`./blocks-KyMOxPT
|
|
|
18
18
|
`}}),bn=(e,n)=>{let r=e.resolve(n),i=r.depth-1;if(i<1)return;let a=r.before(i),o=e.resolve(a).nodeAfter;if(o)return o.type.spec.group?.includes(`bnBlock`)?t.hn(e.resolve(a)):bn(e,a)},X=(e,n)=>{let r=e.resolve(n),i=r.index();if(i===0)return;let a=r.posAtIndex(i-1);return t.hn(e.resolve(a))},Z=(e,n)=>{let r=e.resolve(n),i=r.index();if(i===r.node().childCount-1)return;let a=r.posAtIndex(i+1);return t.hn(e.resolve(a))},Q=(e,n)=>{for(;n.childContainer;){let r=n.childContainer.node,i=e.resolve(n.childContainer.beforePos+1).posAtIndex(r.childCount-1);n=t.hn(e.resolve(i))}return n},xn=(e,t)=>e.isBlockContainer&&e.blockContent.node.type.spec.content===`inline*`&&e.blockContent.node.childCount>0&&t.isBlockContainer&&t.blockContent.node.type.spec.content===`inline*`,Sn=(e,t,n,r)=>{if(!r.isBlockContainer)throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(r.childContainer){let n=e.doc.resolve(r.childContainer.beforePos+1),i=e.doc.resolve(r.childContainer.afterPos-1),a=n.blockRange(i);if(t){let t=e.doc.resolve(r.bnBlock.beforePos);e.tr.lift(a,t.depth)}}if(t){if(!n.isBlockContainer)throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);t(e.tr.delete(n.blockContent.afterPos-1,r.blockContent.beforePos+1))}return!0},Cn=e=>({state:n,dispatch:r})=>{let i=t.hn(n.doc.resolve(e)),a=X(n.doc,i.bnBlock.beforePos);if(!a)return!1;let o=Q(n.doc,a);return xn(o,i)?Sn(n,r,o,i):!1},wn=c.Extension.create({priority:50,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({chain:e,commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:e})=>{let r=t.gn(e);if(!r.isBlockContainer)return!1;let i=e.selection.from===r.blockContent.beforePos+1,a=r.blockContent.node.type.name===`paragraph`;return i&&!a?n.command(t.Tt(r.bnBlock.beforePos,{type:`paragraph`,props:{}})):!1}),()=>n.command(({state:e,tr:n})=>{let r=t.gn(e);if(!r.isBlockContainer)return!1;let{blockContent:i}=r;return e.selection.from===i.beforePos+1?O(n,n.doc.type.schema.nodes.blockContainer,n.doc.type.schema.nodes.blockGroup):!1}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,o=X(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer||o.blockContent.node.type.spec.content!==`inline*`)return!1;let s=n.selection.from===a.beforePos+1,c=n.selection.empty,l=i.beforePos;return s&&c?e().command(Cn(l)).scrollIntoView().run():!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.gn(e);if(!i.isBlockContainer||e.selection.from!==i.blockContent.beforePos+1)return!1;let a=X(e.doc,i.bnBlock.beforePos);if(!a||a.isBlockContainer)return!1;if(r){let e=a.bnBlock.afterPos-1,t=n.doc.resolve(e-1);return n.delete(i.bnBlock.beforePos,i.bnBlock.afterPos),n.insert(t.pos,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(t.pos+1))),!0}return!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.gn(e);if(!i.isBlockContainer||n.selection.from!==i.blockContent.beforePos+1)return!1;let a=n.doc.resolve(i.bnBlock.beforePos);if(a.nodeBefore||a.node().type.name!==`column`)return!1;let o=n.doc.resolve(i.bnBlock.beforePos),s=n.doc.resolve(o.before()),c=s.before();return r&&(n.delete(i.bnBlock.beforePos,i.bnBlock.afterPos),b(n,c),s.pos===c+1?(n.insert(c,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(c)))):(n.insert(s.pos-1,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(s.pos))))),!0}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;if(r.blockContent.node.childCount===0&&r.blockContent.node.type.spec.content===`inline*`){let t=X(n.doc,r.bnBlock.beforePos);if(!t)return!1;let i=Q(n.doc,t);if(!i.isBlockContainer||!i||!i.isBlockContainer)return!1;let a=e();if(r.childContainer&&a.insertContentAt(r.bnBlock.afterPos,r.childContainer?.node.content),i.blockContent.node.type.spec.content===`tableRow+`){let e=r.bnBlock.beforePos-1-1-1-1-1;a=a.setTextSelection(e)}else if(i.blockContent.node.type.spec.content===``)a=a.setNodeSelection(i.blockContent.beforePos);else{let e=i.blockContent.afterPos-1;a=a.setTextSelection(e)}return a.deleteRange({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;let i=n.selection.from===r.blockContent.beforePos+1,a=n.selection.empty,o=X(n.doc,r.bnBlock.beforePos);if(o&&i&&a){let t=Q(n.doc,o);if(!t.isBlockContainer)return!1;if(t.blockContent.node.type.spec.content===``||t.blockContent.node.type.spec.content===`inline*`&&t.blockContent.node.childCount===0)return e().cut({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos},t.bnBlock.afterPos).deleteRange({from:t.bnBlock.beforePos,to:t.bnBlock.afterPos}).run()}return!1})]),n=()=>this.editor.commands.first(({chain:e,commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer||!r.childContainer)return!1;let{blockContent:i,childContainer:a}=r,s=n.selection.from===i.afterPos-1,c=n.selection.empty,l=t.hn(n.doc.resolve(a.beforePos+1));if(!l.isBlockContainer)return!1;if(s&&c){let t=l.blockContent.node,r=t.type.spec.content===`inline*`,s=i.node.type.spec.content===`inline*`;return e().insertContentAt(l.bnBlock.afterPos,l.childContainer?.node.content||o.Fragment.empty).deleteRange(a.node.childCount===1?{from:a.beforePos,to:a.afterPos}:{from:l.bnBlock.beforePos,to:l.bnBlock.afterPos}).insertContentAt(n.selection.from,r&&s?t.content:null).setTextSelection(n.selection.from).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,o=Z(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;let s=n.selection.from===a.afterPos-1,c=n.selection.empty,l=i.afterPos;return s&&c?e().command(Cn(l)).scrollIntoView().run():!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.gn(e);if(!i.isBlockContainer||e.selection.from!==i.blockContent.afterPos-1)return!1;let a=Z(e.doc,i.bnBlock.beforePos);if(!a||a.isBlockContainer)return!1;if(r){let e=a.bnBlock.beforePos+1,t=n.doc.resolve(e+1);return n.delete(t.pos,t.pos+t.nodeAfter.nodeSize),b(n,a.bnBlock.beforePos),n.insert(i.bnBlock.afterPos,t.nodeAfter),n.setSelection(l.TextSelection.near(n.doc.resolve(t.pos))),!0}return!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.gn(e);if(!i.isBlockContainer||n.selection.from!==i.blockContent.afterPos-1)return!1;let a=n.doc.resolve(i.bnBlock.afterPos);if(a.nodeAfter||a.node().type.name!==`column`)return!1;let o=n.doc.resolve(i.bnBlock.afterPos),s=n.doc.resolve(o.after()),c=s.after();if(r){let e=s.pos===c-1?c:s.pos+1,r=t.hn(n.doc.resolve(e));n.delete(r.bnBlock.beforePos,r.bnBlock.afterPos),b(n,c-s.node().nodeSize),n.insert(o.pos,r.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(e)))}return!0}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;let{blockContent:i}=r,a=n.selection.from===i.afterPos-1,s=n.selection.empty;if(a&&s){let t=(e,n)=>{let r=Z(e,n);if(r)return r;let i=bn(e,n);if(i)return t(e,i.bnBlock.beforePos)},a=t(n.doc,r.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let s=a.blockContent.node,c=s.type.spec.content===`inline*`,l=i.node.type.spec.content===`inline*`;return e().insertContentAt(a.bnBlock.afterPos,a.childContainer?.node.content||o.Fragment.empty).deleteRange({from:a.bnBlock.beforePos,to:a.bnBlock.afterPos}).insertContentAt(n.selection.from,c&&l?s.content:null).setTextSelection(n.selection.from).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;if(r.blockContent.node.childCount===0&&r.blockContent.node.type.spec.content===`inline*`){let t=Z(n.doc,r.bnBlock.beforePos);if(!t||!t.isBlockContainer)return!1;let i=e();if(t.blockContent.node.type.spec.content===`tableRow+`){let e=r.bnBlock.afterPos+1+1+1+1+1;i=i.setTextSelection(e)}else i=t.blockContent.node.type.spec.content===``?i.setNodeSelection(t.blockContent.beforePos):i.setTextSelection(t.blockContent.beforePos+1);return i.deleteRange({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.gn(n);if(!r.isBlockContainer)return!1;let i=n.selection.from===r.blockContent.afterPos-1,a=n.selection.empty,o=Z(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;if(o&&i&&a&&(o.blockContent.node.type.spec.content===``||o.blockContent.node.type.spec.content===`inline*`&&o.blockContent.node.childCount===0)){let t=o.bnBlock.node.lastChild.content;return e().deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).insertContentAt(r.bnBlock.afterPos,o.bnBlock.node.childCount===2?t:null).run()}return!1})]),r=(e=!1)=>this.editor.commands.first(({commands:n,tr:r})=>[()=>n.command(({state:e,tr:n})=>{let r=t.gn(e);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,{depth:o}=e.doc.resolve(i.beforePos),s=e.selection.$anchor.parentOffset===0,c=e.selection.anchor===e.selection.head,l=a.node.childCount===0;return s&&c&&l&&o>1?O(n,n.doc.type.schema.nodes.blockContainer,n.doc.type.schema.nodes.blockGroup):!1}),()=>n.command(({state:n})=>{let i=t.gn(n),a=this.options.editor.schema.blockSchema[i.blockNoteType].meta?.hardBreakShortcut??`shift+enter`;if(a===`none`)return!1;if(a===`shift+enter`&&e||a===`enter`){let e=r.storedMarks||r.selection.$head.marks().filter(e=>this.editor.extensionManager.splittableMarks.includes(e.type.name));return r.insert(r.selection.head,r.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e),!0}return!1}),()=>n.command(({state:e,dispatch:n,tr:r})=>{let i=t.gn(e);if(!i.isBlockContainer)return!1;let{bnBlock:a,blockContent:o}=i,s=e.selection.$anchor.parentOffset===0,c=e.selection.anchor===e.selection.head,u=o.node.childCount===0;if(s&&c&&u){let t=a.afterPos,o=t+2;if(n){let n=e.schema.nodes.blockContainer.createAndFill(void 0,[e.schema.nodes.paragraph.createAndFill()||void 0,i.childContainer?.node].filter(e=>e!==void 0));r.insert(t,n).setSelection(new l.TextSelection(r.doc.resolve(o))).scrollIntoView(),i.childContainer&&r.delete(i.childContainer.beforePos,i.childContainer.afterPos)}return!0}return!1}),()=>n.command(({state:e,chain:n})=>{let r=t.gn(e);if(!r.isBlockContainer)return!1;let{blockContent:i}=r,a=e.selection.$anchor.parentOffset===0;return i.node.childCount===0?!1:(n().deleteSelection().command(t.H(e.selection.from,a,a)).run(),!0)})]);return{Backspace:e,Delete:n,Enter:()=>r(),"Shift-Enter":()=>r(!0),Tab:()=>this.options.tabBehavior!==`prefer-indent`&&(this.options.editor.getExtension(t.m)?.store.state||this.options.editor.getExtension(t.mt)?.store.state!==void 0)?!1:D(this.options.editor),"Shift-Tab":()=>this.options.tabBehavior!==`prefer-indent`&&(this.options.editor.getExtension(t.m)?.store.state||this.options.editor.getExtension(t.mt)?.store.state!==void 0)?!1:be(this.options.editor),"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}}),Tn=c.Mark.create({name:`insertion`,inclusive:!1,excludes:`deletion modification insertion`,addAttributes(){return{id:{default:null,validate:`number`}}},extendMarkSchema(e){return e.name===`insertion`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[`ins`,{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:`display: contents`}},0]},parseDOM:[{tag:`ins`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}:{}}}),En=c.Mark.create({name:`deletion`,inclusive:!1,excludes:`insertion modification deletion`,addAttributes(){return{id:{default:null,validate:`number`}}},extendMarkSchema(e){return e.name===`deletion`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[`del`,{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:`display: contents`}},0]},parseDOM:[{tag:`del`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}:{}}}),Dn=c.Mark.create({name:`modification`,inclusive:!1,excludes:`deletion insertion`,addAttributes(){return{id:{default:null,validate:`number`},type:{validate:`string`},attrName:{default:null,validate:`string|null`},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(e){return e.name===`modification`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[t?`span`:`div`,{"data-type":`modification`,"data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0]},parseDOM:[{tag:`span[data-type='modification']`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}:!1}},{tag:`div[data-type='modification']`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}:!1}}]}:{}}}),On=c.Extension.create({name:`textAlignment`,addGlobalAttributes(){return[{types:[`tableCell`,`tableHeader`],attributes:{textAlignment:{default:`left`,parseHTML:e=>e.getAttribute(`data-text-alignment`),renderHTML:e=>e.textAlignment===`left`?{}:{"data-text-alignment":e.textAlignment}}}}]}}),kn=c.Extension.create({name:`blockTextColor`,addGlobalAttributes(){return[{types:[`table`,`tableCell`,`tableHeader`],attributes:{textColor:t.yt()}}]}}),An={blockColor:`data-block-color`,blockStyle:`data-block-style`,id:`data-id`,depth:`data-depth`,depthChange:`data-depth-change`},jn=c.Node.create({name:`blockContainer`,group:`blockGroupChild bnBlock`,content:`blockContent blockGroup?`,priority:50,defining:!0,marks:`insertion modification deletion`,parseHTML(){return[{tag:`div[data-node-type=`+this.name+`]`,getAttrs:e=>{if(typeof e==`string`)return!1;let t={};for(let[n,r]of Object.entries(An))e.getAttribute(r)&&(t[n]=e.getAttribute(r));return t}},{tag:`div[data-node-type="blockOuter"]`,skip:!0}]},renderHTML({HTMLAttributes:e}){let n=document.createElement(`div`);n.className=`bn-block-outer`,n.setAttribute(`data-node-type`,`blockOuter`);for(let[t,r]of Object.entries(e))t!==`class`&&n.setAttribute(t,r);let r={...this.options.domAttributes?.block||{},...e},i=document.createElement(`div`);i.className=t.Rn(`bn-block`,r.class),i.setAttribute(`data-node-type`,this.name);for(let[e,t]of Object.entries(r))e!==`class`&&i.setAttribute(e,t);return n.appendChild(i),{dom:n,contentDOM:i}}}),Mn=c.Node.create({name:`blockGroup`,group:`childContainer`,content:`blockGroupChild+`,marks:`deletion insertion modification`,parseHTML(){return[{tag:`div`,getAttrs:e=>typeof e==`string`?!1:e.getAttribute(`data-node-type`)===`blockGroup`?null:!1}]},renderHTML({HTMLAttributes:e}){let n={...this.options.domAttributes?.blockGroup||{},...e},r=document.createElement(`div`);r.className=t.Rn(`bn-block-group`,n.class),r.setAttribute(`data-node-type`,`blockGroup`);for(let[e,t]of Object.entries(n))e!==`class`&&r.setAttribute(e,t);return{dom:r,contentDOM:r}}}),Nn=c.Node.create({name:`doc`,topNode:!0,content:`blockGroup`,marks:`insertion modification deletion`}),Pn=e.t(({options:e})=>({key:`collaboration`,blockNoteExtensions:[n.S(e),n.T(e),n.w(e),n.C(),n.x(e)]}));function Fn(e,n){return[c.extensions.ClipboardTextSerializer,c.extensions.Commands,c.extensions.Editable,c.extensions.FocusEvents,c.extensions.Tabindex,h.Gapcursor,t.Yn.configure({types:[`blockContainer`,`columnList`,`column`],setIdAttribute:n.setIdAttribute,isWithinEditor:e.isWithinEditor}),yn,g.Text,Tn,En,Dn,...Object.values(e.schema.styleSpecs).map(t=>t.implementation.mark.configure({editor:e})),kn,vn,On,c.Extension.create({name:`OverrideEscape`,addKeyboardShortcuts:()=>({Escape:()=>e.getExtension(t.f)?.shown()?!1:(e.blur(),!0)})}),Nn,jn.configure({editor:e,domAttributes:n.domAttributes}),wn.configure({editor:e,tabBehavior:n.tabBehavior}),Mn.configure({domAttributes:n.domAttributes}),...Object.values(e.schema.inlineContentSpecs).filter(e=>e.config!==`link`&&e.config!==`text`).map(t=>t.implementation.node.configure({editor:e})),...Object.values(e.schema.blockSpecs).flatMap(t=>[...`node`in t.implementation?[t.implementation.node.configure({editor:e,domAttributes:n.domAttributes})]:[]]),_n(e),pn(e,n.pasteHandler||(e=>e.defaultPasteHandler())),Yt(e)]}function In(e,i){let a=[n.E(),n.b(i),t.mt(i),t.m(i),Wt({HTMLAttributes:i.links?.HTMLAttributes??{},onClick:i.links?.onClick,...i.links?.isValidLink?{isValidLink:i.links.isValidLink}:{}}),n._(i),n.m(),n.p(i),r.t(i),n.o(i),t.f(i),...i.trailingBlock===!1?[]:[n.t()]];return i.collaboration?a.push(Pn(i.collaboration)):a.push(n.v()),`table`in e.schema.blockSpecs&&a.push(n.n(i)),i.animations!==!1&&a.push(n.f()),a}var Ln=class{disabledExtensions=new Set;extensions=[];abortMap=new Map;extensionFactories=new Map;extensionPlugins=new Map;constructor(e,t){this.editor=e,this.options=t,e.onMount(()=>{for(let t of this.extensions)if(t.mount){let n=new window.AbortController,r=t.mount({dom:e.prosemirrorView.dom,root:e.prosemirrorView.root,signal:n.signal});r&&n.signal.addEventListener(`abort`,()=>{r()}),this.abortMap.set(t,n)}}),e.onUnmount(()=>{for(let[e,t]of this.abortMap.entries())this.abortMap.delete(e),t.abort()}),this.disabledExtensions=new Set(t.disableExtensions||[]);for(let e of In(this.editor,this.options))this.addExtension(e);for(let e of this.options.extensions??[])this.addExtension(e);for(let e of Object.values(this.editor.schema.blockSpecs))for(let t of e.extensions??[])this.addExtension(t)}registerExtension(e){let t=[].concat(e).filter(Boolean);if(!t.length){console.warn(`No extensions found to register`,e);return}let n=t.map(e=>this.addExtension(e)).filter(Boolean),r=new Set;for(let e of n)e?.tiptapExtensions&&console.warn(`Extension ${e.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,e),e?.inputRules?.length&&console.warn(`Extension ${e.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,e),this.getProsemirrorPluginsFromExtension(e).plugins.forEach(e=>{r.add(e)});this.updatePlugins(e=>[...e,...r])}addExtension(t){let n;if(n=typeof t==`function`?t({editor:this.editor}):t,!(!n||this.disabledExtensions.has(n.key))){if(typeof t==`function`){let t=n[e.r];typeof t==`function`&&this.extensionFactories.set(t,n)}if(this.extensions.push(n),n.blockNoteExtensions)for(let e of n.blockNoteExtensions)this.addExtension(e);return n}}resolveExtensions(e){let t=[];if(typeof e==`function`){let n=this.extensionFactories.get(e);n&&t.push(n)}else if(Array.isArray(e))for(let n of e)t.push(...this.resolveExtensions(n));else if(typeof e==`object`&&`key`in e)t.push(e);else if(typeof e==`string`){let n=this.extensions.find(t=>t.key===e);n&&t.push(n)}return t}unregisterExtension(e){let t=this.resolveExtensions(e);if(!t.length){console.warn(`No extensions found to unregister`,e);return}let n=!1,r=new Set;for(let i of t)this.extensions=this.extensions.filter(e=>e!==i),this.extensionFactories.forEach((e,t)=>{e===i&&this.extensionFactories.delete(t)}),this.abortMap.get(i)?.abort(),this.abortMap.delete(i),this.extensionPlugins.get(i)?.forEach(e=>{r.add(e)}),this.extensionPlugins.delete(i),i.tiptapExtensions&&!n&&(n=!0,console.warn(`Extension ${i.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`,e));this.updatePlugins(e=>e.filter(e=>!r.has(e)))}updatePlugins(e){let t=this.editor.prosemirrorState,n=t.reconfigure({plugins:e(t.plugins.slice())});this.editor.prosemirrorView.updateState(n)}getTiptapExtensions(){let e=Fn(this.editor,this.options).filter(e=>!this.disabledExtensions.has(e.name)),n=t.Ut(this.extensions),r=new Map;for(let t of this.extensions){t.tiptapExtensions&&e.push(...t.tiptapExtensions);let i=n(t.key),{plugins:a,inputRules:o}=this.getProsemirrorPluginsFromExtension(t);a.length&&e.push(c.Extension.create({name:t.key,priority:i,addProseMirrorPlugins:()=>a})),o.length&&(r.has(i)||r.set(i,[]),r.get(i).push(...o))}e.push(c.Extension.create({name:`blocknote-input-rules`,addProseMirrorPlugins(){let e=[];Array.from(r.keys()).sort().reverse().forEach(t=>{e.push(...r.get(t))});let t=(0,p.inputRules)({rules:e});return[t,new l.Plugin({props:{handleKeyDown(e,n){if(n.key!==`Enter`||n.shiftKey||n.ctrlKey||n.metaKey||n.altKey)return!1;let{$cursor:r}=e.state.selection;return r?!!t.props.handleTextInput?.call(t,e,r.pos,r.pos,`
|
|
19
19
|
`,()=>e.state.tr.insertText(`
|
|
20
20
|
`,r.pos,r.pos)):!1}}})]}}));for(let t of this.options._tiptapOptions?.extensions??[])e.push(t);return e}getProsemirrorPluginsFromExtension(e){let n=[...e.prosemirrorPlugins??[]],r=[];return!e.prosemirrorPlugins?.length&&!Object.keys(e.keyboardShortcuts||{}).length&&!e.inputRules?.length?{plugins:n,inputRules:r}:(this.extensionPlugins.set(e,n),e.inputRules?.length&&r.push(...e.inputRules.map(e=>new p.InputRule(e.find,(n,r,i,a)=>{let o=e.replace({match:r,range:{from:i,to:a},editor:this.editor});if(o){let e=n.tr,r=t._n(e);if(!r.isBlockContainer||this.editor.schema.blockSchema[r.blockNoteType]?.content!==`inline`)return null;e.deleteRange(i,a),t.Et(e,r.bnBlock.beforePos,o);let s=r.bnBlock.node.attrs.id;return s&&V(e,s,`start`),e}return null},{undoable:!0}))),Object.keys(e.keyboardShortcuts||{}).length&&n.push((0,m.keymap)(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([e,t])=>[e,()=>t({editor:this.editor})])))),{plugins:n,inputRules:r})}getExtensions(){return new Map(this.extensions.map(e=>[e.key,e]))}getExtension(e){if(typeof e==`string`)return this.extensions.find(t=>t.key===e)||void 0;if(typeof e==`function`)return this.extensionFactories.get(e)||void 0;throw Error(`Invalid extension type: ${typeof e}`)}hasExtension(e){return typeof e==`string`?this.extensions.some(t=>t.key===e):typeof e==`object`&&`key`in e?this.extensions.some(t=>t.key===e.key):typeof e==`function`?this.extensionFactories.has(e):!1}};function $(e,t){let{$from:n,$to:r}=t;if(n.pos>n.start()&&n.pos<e.content.size){let t=e.textBetween(n.pos,n.pos+1);if(/^[\w\p{P}]$/u.test(t)){let t=e.textBetween(n.start(),n.pos).match(/[\w\p{P}]+$/u);t&&(n=e.resolve(n.pos-t[0].length))}}if(r.pos<r.end()&&r.pos>0){let t=e.textBetween(r.pos-1,r.pos);if(/^[\w\p{P}]$/u.test(t)){let t=e.textBetween(r.pos,r.end()).match(/^[\w\p{P}]+/u);t&&(r=e.resolve(r.pos+t[0].length))}}return{$from:n,$to:r,from:n.pos,to:r.pos}}function Rn(e){let n=t.fn(e);if(e.selection.empty||`node`in e.selection)return;let r=e.doc.resolve(t.yn(e.doc,e.selection.from).posBeforeNode),i=e.doc.resolve(t.yn(e.doc,e.selection.to).posBeforeNode),a=(i,a)=>{let o=r.posAtIndex(i,a),s=e.doc.resolve(o).nodeAfter;if(!s)throw Error(`Error getting selection - node not found at position ${o}`);return t.an(s,n)},o=[],s=r.sharedDepth(i.pos),c=r.index(s),l=i.index(s);if(r.depth>s){o.push(t.an(r.nodeAfter,n));for(let e=r.depth;e>s;e--)if(r.node(e).type.isInGroup(`childContainer`)){let t=r.index(e)+1,n=r.node(e).childCount;for(let r=t;r<n;r++)o.push(a(r,e))}}else o.push(a(c,s));for(let e=c+1;e<=l;e++)o.push(a(e,s));if(o.length===0)throw Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:o}}function zn(e,n,r){let i=typeof n==`string`?n:n.id,a=typeof r==`string`?r:r.id,o=t.ln(t.fn(e));if(i===a)throw Error(`Attempting to set selection with the same anchor and head blocks (id ${i})`);let s=t.Dt(i,e.doc);if(!s)throw Error(`Block with ID ${i} not found`);let c=t.Dt(a,e.doc);if(!c)throw Error(`Block with ID ${a} not found`);let u=t.mn(s),f=t.mn(c),p=o.blockSchema[u.blockNoteType],m=o.blockSchema[f.blockNoteType];if(!u.isBlockContainer||p.content===`none`)throw Error(`Attempting to set selection anchor in block without content (id ${i})`);if(!f.isBlockContainer||m.content===`none`)throw Error(`Attempting to set selection anchor in block without content (id ${a})`);let h,g;if(p.content===`table`){let e=d.TableMap.get(u.blockContent.node);h=u.blockContent.beforePos+e.positionAt(0,0,u.blockContent.node)+1+2}else h=u.blockContent.beforePos+1;if(m.content===`table`){let t=d.TableMap.get(f.blockContent.node),n=f.blockContent.beforePos+t.positionAt(t.height-1,t.width-1,f.blockContent.node)+1;g=n+e.doc.resolve(n).nodeAfter.nodeSize-2}else g=f.blockContent.afterPos-1;e.setSelection(l.TextSelection.create(e.doc,h,g))}function Bn(e,n=!1){let r=t.fn(e),i=n?$(e.doc,e.selection):e.selection,a=i.$from,o=i.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;o.parentOffset===0&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;a.parentOffset===0&&a.depth>0;)a=e.doc.resolve(a.pos-1);for(;a.parentOffset>=a.parent.nodeSize-2&&a.depth>0;)a=e.doc.resolve(a.pos+1);let s=t.sn(e.doc.slice(a.pos,o.pos,!0),r);return{_meta:{startPos:a.pos,endPos:o.pos},...s}}var Vn=class{constructor(e){this.editor=e}getSelection(){return this.editor.transact(e=>Rn(e))}getSelectionCutBlocks(e=!1){return this.editor.transact(t=>Bn(t,e))}setSelection(e,t){return this.editor.transact(n=>zn(n,e,t))}getTextCursorPosition(){return this.editor.transact(e=>_t(e))}setTextCursorPosition(e,t=`start`){return this.editor.transact(n=>V(n,e,t))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;let{selection:e}=this.editor.prosemirrorState,{ranges:t}=e,n=Math.min(...t.map(e=>e.$from.pos)),r=Math.max(...t.map(e=>e.$to.pos));if((0,c.isNodeSelection)(e)){let e=this.editor.prosemirrorView.nodeDOM(n);if(e)return e.getBoundingClientRect()}return(0,c.posToDOMRect)(this.editor.prosemirrorView,n,r).toJSON()}},Hn=class{constructor(e){this.editor=e}activeTransaction=null;can(e){try{return this.isInCan=!0,e()}finally{this.isInCan=!1}}isInCan=!1;exec(e){if(this.activeTransaction)throw Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");if(this.isInCan)return this.canExec(e);let t=this.prosemirrorState,n=this.prosemirrorView;return e(t,e=>this.prosemirrorView.dispatch(e),n)}canExec(e){if(this.activeTransaction)throw Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");let t=this.prosemirrorState,n=this.prosemirrorView;return e(t,void 0,n)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this.editor._tiptapEditor.state.tr;let t=e(this.activeTransaction),n=this.activeTransaction;return this.activeTransaction=null,n&&(n.docChanged||n.selectionSet||n.scrolledIntoView||n.storedMarksSet||!n.isGeneric)&&this.prosemirrorView.dispatch(n),t}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this.editor._tiptapEditor.state}get prosemirrorView(){return this.editor._tiptapEditor.view}isFocused(){return this.prosemirrorView?.hasFocus()||!1}focus(){this.prosemirrorView?.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw Error(`no editor, but also not headless?`);return!1}return this.editor._tiptapEditor.isEditable===void 0?!0:this.editor._tiptapEditor.isEditable}set isEditable(e){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw Error(`no editor, but also not headless?`);return}this.editor._tiptapEditor.options.editable!==e&&this.editor._tiptapEditor.setEditable(e)}undo(){let e=this.editor.getExtension(`yUndo`);if(e)return this.exec(e.undoCommand);let t=this.editor.getExtension(`history`);if(t)return this.exec(t.undoCommand);throw Error(`No undo plugin found`)}redo(){let e=this.editor.getExtension(`yUndo`);if(e)return this.exec(e.redoCommand);let t=this.editor.getExtension(`history`);if(t)return this.exec(t.redoCommand);throw Error(`No redo plugin found`)}};function Un(e,t,n,r={updateSelection:!0}){let{from:i,to:a}=typeof t==`number`?{from:t,to:t}:{from:t.from,to:t.to},o=!0,s=!0,l=``;if(n.forEach(e=>{e.check(),o&&e.isText&&e.marks.length===0?l+=e.text:o=!1,s=s?e.isBlock:!1}),i===a&&s){let{parent:t}=e.doc.resolve(i);t.isTextblock&&!t.type.spec.code&&!t.childCount&&(--i,a+=1)}return o?e.insertText(l,i,a):e.replaceWith(i,a,n),r.updateSelection&&(0,c.selectionToInsertionEnd)(e,e.steps.length-1,-1),!0}var Wn=class{constructor(e){this.editor=e}insertInlineContent(e,{updateSelection:n=!1}={}){let r=t.At(e,this.editor.pmSchema);this.editor.transact(e=>{Un(e,{from:e.selection.from,to:e.selection.to},r,{updateSelection:n})})}getActiveStyles(){return this.editor.transact(e=>{let t={},n=e.selection.$to.marks();for(let e of n){let n=this.editor.schema.styleSchema[e.type.name];if(!n){e.type.name!==`link`&&!e.type.spec.blocknoteIgnore&&console.warn(`mark not found in styleschema`,e.type.name);continue}n.propSchema===`boolean`?t[n.type]=!0:t[n.type]=e.attrs.stringValue}return t})}addStyles(e){for(let[n,r]of Object.entries(e)){let e=this.editor.schema.styleSchema[n];if(!e)throw Error(`style ${n} not found in styleSchema`);if(e.propSchema===`boolean`)this.editor._tiptapEditor.commands.setMark(n);else if(e.propSchema===`string`)this.editor._tiptapEditor.commands.setMark(n,{stringValue:r});else throw new t.zn(e.propSchema)}}removeStyles(e){for(let t of Object.keys(e))this.editor._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){for(let[n,r]of Object.entries(e)){let e=this.editor.schema.styleSchema[n];if(!e)throw Error(`style ${n} not found in styleSchema`);if(e.propSchema===`boolean`)this.editor._tiptapEditor.commands.toggleMark(n);else if(e.propSchema===`string`)this.editor._tiptapEditor.commands.toggleMark(n,{stringValue:r});else throw new t.zn(e.propSchema)}}getSelectedText(){return this.editor.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getLinkMarkAtPos(e){return this.editor.transact(t=>{let n=t.doc.resolve(e),r=n.marks().find(e=>e.type.name===`link`);if(!r)return;let i=(0,c.getMarkRange)(n,r.type);if(i)return{href:r.attrs.href,from:i.from,to:i.to,text:t.doc.textBetween(i.from,i.to)}})}getSelectedLinkUrl(){return this.editor.transact(e=>this.getLinkMarkAtPos(e.selection.from)?.href)}createLink(e,t){e!==``&&this.editor.transact(n=>{let{from:r,to:i}=n.selection,a=this.editor.pmSchema.mark(`link`,{href:e});t?n.insertText(t,r,i).addMark(r,r+t.length,a):n.addMark(r,i,a)})}editLink(e,t,n=this.editor.transact(e=>e.selection.anchor)){this.editor.transact(r=>{let{from:i,to:a}=this.getLinkMarkAtPos(n+1)||{from:r.selection.from,to:r.selection.to},o=this.editor.pmSchema.mark(`link`,{href:e});t!==r.doc.textBetween(i,a)&&r.insertText(t,i,a),r.addMark(i,i+t.length,o)}),this.editor.prosemirrorView.focus()}deleteLink(e=this.editor.transact(e=>e.selection.anchor)){this.editor.transact(t=>{let{from:n,to:r}=this.getLinkMarkAtPos(e+1)||{from:t.selection.from,to:t.selection.to};t.removeMark(n,r,this.editor.pmSchema.marks.link).setMeta(`preventAutolink`,!0)}),this.editor.prosemirrorView.focus()}};function Gn(e){return(0,c.findParentNodeClosestToPos)(e.state.selection.$from,e=>e.type.name===`tableCell`||e.type.name===`tableHeader`)!==void 0}function Kn(e,t){let n=t.nodes.hardBreak,r=u.Fragment.empty;return e.forEach(e=>{e.isTextblock&&e.childCount>0?(r=r.append(e.content),r=r.addToEnd(n.create())):e.isText?r=r.addToEnd(e):e.isBlock&&e.childCount>0&&(r=r.append(Kn(e.content,t)),r=r.addToEnd(n.create()))}),r.lastChild?.type===n&&(r=r.cut(0,r.size-1)),r}function qn(e,t){let n=[];return e.forEach((e,r,i)=>{i!==t&&n.push(e)}),u.Fragment.from(n)}function Jn(e,t){let n=[];for(let r=0;r<e.childCount;r++)if(e.child(r).type.name===`tableRow`)if(n.length>0&&n[n.length-1].type.name===`table`){let t=n[n.length-1],i=t.copy(t.content.addToEnd(e.child(r)));n[n.length-1]=i}else{let i=t.nodes.table.createChecked(void 0,e.child(r));n.push(i)}else n.push(e.child(r));return e=u.Fragment.from(n),e}function Yn(e,t){let n=u.Fragment.from(e.content);n=Jn(n,t.state.schema);let r=Xn(n,t,e);if(r)return r;if(Gn(t)){let e=!1;if(n.descendants(t=>{t.type.isInGroup(`tableContent`)&&(e=!0)}),!e&&!t.state.schema.nodes.tableParagraph.validContent(n))return new u.Slice(Kn(n,t.state.schema),0,0)}if(!Zn(n,t))return new u.Slice(n,e.openStart,e.openEnd);for(let e=0;e<n.childCount;e++)if(n.child(e).type.spec.group===`blockContent`){let r=[n.child(e)];if(e+1<n.childCount&&n.child(e+1).type.name===`blockGroup`){let t=n.child(e+1).child(0).child(0);(t.type.name===`bulletListItem`||t.type.name===`numberedListItem`||t.type.name===`checkListItem`)&&(r.push(n.child(e+1)),n=qn(n,e+1))}let i=t.state.schema.nodes.blockContainer.createChecked(void 0,r);n=n.replaceChild(e,i)}return new u.Slice(n,e.openStart,e.openEnd)}function Xn(e,n,r){if(Gn(n)||n.dragging)return null;let i=t.gn(n.state),a=i.isBlockContainer?i.blockContent.node:null;if(!a||a.type.name===`paragraph`||a.type.spec.content!==`inline*`||a.childCount>0)return null;let o=e.firstChild,s=o?.firstChild,c=s?.firstChild;if(o?.type.name!==`blockGroup`||s?.type.name!==`blockContainer`||c?.type.name!==`paragraph`)return null;let l=a.type.create(a.attrs,c.content),d=s.copy(s.content.replaceChild(0,l)),f=o.copy(o.content.replaceChild(0,d));return new u.Slice(e.replaceChild(0,f),r.openStart,r.openEnd)}function Zn(e,n){let r=e.childCount===1,i=e.firstChild?.type.spec.content===`inline*`,a=e.firstChild?.type.spec.content===`tableRow+`;if(r){if(i)return!1;if(a){let e=t.gn(n.state);if(e.isBlockContainer)return e.blockContent.node.type.spec.content!==`tableRow+`}}return!0}var Qn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1},$n=class e extends a.t{pmSchema;_tiptapEditor;elementRenderer=null;blockCache=new WeakMap;dictionary;schema;blockImplementations;inlineContentImplementations;styleImplementations;uploadFile;onUploadStartCallbacks=[];onUploadEndCallbacks=[];resolveFileUrl;settings;static create(t){return new e(t??{})}constructor(e){super(),this.options=e,this.dictionary=e.dictionary||i.t,this.settings={tables:{splitCells:e?.tables?.splitCells??!1,cellBackgroundColor:e?.tables?.cellBackgroundColor??!1,cellTextColor:e?.tables?.cellTextColor??!1,headers:e?.tables?.headers??!1}};let n={defaultStyles:!0,schema:e.schema||t.t.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(this.schema=n.schema,this.blockImplementations=n.schema.blockSpecs,this.inlineContentImplementations=n.schema.inlineContentSpecs,this.styleImplementations=n.schema.styleSpecs,n.uploadFile){let e=n.uploadFile;this.uploadFile=async(t,n)=>{this.onUploadStartCallbacks.forEach(e=>e.apply(this,[n]));try{return await e(t,n)}finally{this.onUploadEndCallbacks.forEach(e=>e.apply(this,[n]))}}}this.resolveFileUrl=n.resolveFileUrl,this._eventManager=new Oe(this),this._extensionManager=new Ln(this,n);let r=this._extensionManager.getTiptapExtensions(),a=this._extensionManager.hasExtension(`ySync`)||this._extensionManager.hasExtension(`liveblocksExtension`);a&&n.initialContent&&console.warn(`When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider`);let s={...Qn,...n._tiptapOptions,element:null,autofocus:n.autofocus??!1,extensions:r,editorProps:{...n._tiptapOptions?.editorProps,attributes:{tabIndex:`0`,...n._tiptapOptions?.editorProps?.attributes,...n.domAttributes?.editor,class:t.Rn(`bn-editor`,n.defaultStyles?`bn-default-styles`:``,n.domAttributes?.editor?.class||``)},transformPasted:Yn}};try{let e=n.initialContent||(a?[{type:`paragraph`,id:`initialBlockId`}]:[{type:`paragraph`,id:t.Yn.options.generateID()}]);if(!Array.isArray(e)||e.length===0)throw Error(`initialContent must be a non-empty array of blocks, received: `+e);let r=(0,c.getSchema)(s.extensions),i=(0,c.createDocument)({type:`doc`,content:[{type:`blockGroup`,content:e.map(e=>t.kt(e,r,this.schema.styleSchema).toJSON())}]},r,s.parseOptions);this._tiptapEditor=new c.Editor({...s,content:i.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(e){throw Error("Error creating document from blocks passed as `initialContent`",{cause:e})}let l,u=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...e)=>{if(l)return l;let t=u.apply(this.pmSchema.nodes.doc,e),n=JSON.parse(JSON.stringify(t.toJSON()));return n.content[0].content[0].attrs.id=`initialBlockId`,l=o.Node.fromJSON(this.pmSchema,n),l},this.pmSchema.cached.blockNoteEditor=this,this._tiptapEditor.on(`mount`,()=>{this.headless=!1}),this._tiptapEditor.on(`unmount`,()=>{this.headless=!0}),this._blockManager=new De(this),this._exportManager=new gt(this),this._selectionManager=new Vn(this),this._stateManager=new Hn(this),this._styleManager=new Wn(this),this.emit(`create`)}_blockManager;_eventManager;_exportManager;_extensionManager;_selectionManager;_stateManager;_styleManager;get extensions(){return this._extensionManager.getExtensions()}exec(e){return this._stateManager.exec(e)}canExec(e){return this._stateManager.canExec(e)}transact(e){return this._stateManager.transact(e)}unregisterExtension=(...e)=>this._extensionManager.unregisterExtension(...e);registerExtension=(...e)=>this._extensionManager.registerExtension(...e);getExtension=((...e)=>this._extensionManager.getExtension(...e));mount=(e,t)=>{let n=e.getRootNode(),r=typeof ShadowRoot<`u`&&n instanceof ShadowRoot;(t?.portalTarget??e.parentElement??(r?n:document.body)).appendChild(this.portalElement),this._tiptapEditor.mount({mount:e})};unmount=()=>{this.portalElement?.remove(),this._tiptapEditor.unmount()};get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){if(!this.headless)return this.prosemirrorView?.dom}_portalElement;get portalElement(){if(typeof document>`u`)throw Error(`Portal element accessed, but not available in headless mode`);return this._portalElement||=document.createElement(`div`),this._portalElement}isWithinEditor=e=>!!(this.domElement?.parentElement?.contains(e)||this.portalElement?.contains(e));isFocused(){return this.headless?!1:this.prosemirrorView?.hasFocus()||!1}headless=!0;focus(){this.headless||this.prosemirrorView.focus()}blur(){this.headless||this.domElement?.blur()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{let t=this.onUploadStartCallbacks.indexOf(e);t>-1&&this.onUploadStartCallbacks.splice(t,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{let t=this.onUploadEndCallbacks.indexOf(e);t>-1&&this.onUploadEndCallbacks.splice(t,1)}}get topLevelBlocks(){return this.document}get document(){return this._blockManager.document}getBlock(e){return this._blockManager.getBlock(e)}getPrevBlock(e){return this._blockManager.getPrevBlock(e)}getNextBlock(e){return this._blockManager.getNextBlock(e)}getParentBlock(e){return this._blockManager.getParentBlock(e)}forEachBlock(e,t=!1){this._blockManager.forEachBlock(e,t)}onEditorContentChange(e){this._tiptapEditor.on(`update`,e)}onEditorSelectionChange(e){this._tiptapEditor.on(`selectionUpdate`,e)}onBeforeChange(e){return this._extensionManager.getExtension(n.E).subscribe(e)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(e,t=`start`){return this._selectionManager.setTextCursorPosition(e,t)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(e=!1){return this._selectionManager.getSelectionCutBlocks(e)}setSelection(e,t){return this._selectionManager.setSelection(e,t)}get isEditable(){return this._stateManager.isEditable}set isEditable(e){this._stateManager.isEditable=e}insertBlocks(e,t,n=`before`){return this._blockManager.insertBlocks(e,t,n)}updateBlock(e,t){return this._blockManager.updateBlock(e,t)}removeBlocks(e){return this._blockManager.removeBlocks(e)}replaceBlocks(e,t){return this._blockManager.replaceBlocks(e,t)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(e,{updateSelection:t=!1}={}){this._styleManager.insertInlineContent(e,{updateSelection:t})}getActiveStyles(){return this._styleManager.getActiveStyles()}addStyles(e){this._styleManager.addStyles(e)}removeStyles(e){this._styleManager.removeStyles(e)}toggleStyles(e){this._styleManager.toggleStyles(e)}getSelectedText(){return this._styleManager.getSelectedText()}getSelectedLinkUrl(){return this._styleManager.getSelectedLinkUrl()}createLink(e,t){this._styleManager.createLink(e,t)}getLinkMarkAtPos(e){return this._styleManager.getLinkMarkAtPos(e)}editLink(e,t,n){this._styleManager.editLink(e,t,n)}deleteLink(e){this._styleManager.deleteLink(e)}canNestBlock(){return this._blockManager.canNestBlock()}nestBlock(){this._blockManager.nestBlock()}canUnnestBlock(){return this._blockManager.canUnnestBlock()}unnestBlock(){this._blockManager.unnestBlock()}moveBlocksUp(e){return this._blockManager.moveBlocksUp(e)}moveBlocksDown(e){return this._blockManager.moveBlocksDown(e)}blocksToHTMLLossy(e=this.document){return this._exportManager.blocksToHTMLLossy(e)}blocksToFullHTML(e=this.document){return this._exportManager.blocksToFullHTML(e)}tryParseHTMLToBlocks(e){return this._exportManager.tryParseHTMLToBlocks(e)}blocksToMarkdownLossy(e=this.document){return this._exportManager.blocksToMarkdownLossy(e)}tryParseMarkdownToBlocks(e){return this._exportManager.tryParseMarkdownToBlocks(e)}onChange(e,t){return this._eventManager.onChange(e,t)}onSelectionChange(e,t){return this._eventManager.onSelectionChange(e,t)}onMount(e){return this._eventManager.onMount(e)}onUnmount(e){return this._eventManager.onUnmount(e)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){let e=this.document;return e.length===0||e.length===1&&e[0].type===`paragraph`&&e[0].content.length===0}pasteHTML(e,t=!1){this._exportManager.pasteHTML(e,t)}pasteText(e){return this._exportManager.pasteText(e)}pasteMarkdown(e){return this._exportManager.pasteMarkdown(e)}},er=class{constructor(e,t,n){this.mappings=t,this.options=n}async resolveFile(e){if(!this.options?.resolveFileUrl)return(await fetch(e)).blob();let t=await this.options.resolveFileUrl(e);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(e){return Object.entries(e).map(([e,t])=>this.mappings.styleMapping[e](t,this))}mapInlineContent(e){return this.mappings.inlineContentMapping[e.type](e,this)}transformInlineContent(e){return e.map(e=>this.mapInlineContent(e))}async mapBlock(e,t,n,r){return this.mappings.blockMapping[e.type](e,this,t,n,r)}};function tr(e){return{createBlockMapping:e=>e,createInlineContentMapping:e=>e,createStyleMapping:e=>e}}function nr(e,...t){let n=[...e];for(let e of t)for(let t of e){let e=n.findLastIndex(e=>e.group===t.group);e===-1?n.push(t):n.splice(e+1,0,t)}return n}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return $n}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return tr}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return er}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return nr}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return te}});
|
|
21
|
-
//# sourceMappingURL=src-
|
|
21
|
+
//# sourceMappingURL=src-B6rlChSc.cjs.map
|