@@ -23,42 +23,45 @@ export function insertBlocks<
2323 placement : "before" | "after" | "nested" = "before" ,
2424 editor : BlockNoteEditor < BSchema , I , S >
2525) : Block < BSchema , I , S > [ ] {
26- const ttEditor = editor . _tiptapEditor ;
27-
2826 const id =
2927 typeof referenceBlock === "string" ? referenceBlock : referenceBlock . id ;
3028
3129 const nodesToInsert : Node [ ] = [ ] ;
3230 for ( const blockSpec of blocksToInsert ) {
3331 nodesToInsert . push (
34- blockToNode ( blockSpec , ttEditor . schema , editor . schema . styleSchema )
32+ blockToNode ( blockSpec , editor . pmSchema , editor . schema . styleSchema )
3533 ) ;
3634 }
3735
38- const { node, posBeforeNode } = getNodeById ( id , ttEditor . state . doc ) ;
36+ const { node, posBeforeNode } = getNodeById (
37+ id ,
38+ editor . _tiptapEditor . state . doc
39+ ) ;
3940
4041 if ( placement === "before" ) {
41- ttEditor . view . dispatch (
42- ttEditor . state . tr . insert ( posBeforeNode , nodesToInsert )
42+ editor . dispatch (
43+ editor . _tiptapEditor . state . tr . insert ( posBeforeNode , nodesToInsert )
4344 ) ;
4445 }
4546
4647 if ( placement === "after" ) {
47- ttEditor . view . dispatch (
48- ttEditor . state . tr . insert ( posBeforeNode + node . nodeSize , nodesToInsert )
48+ editor . dispatch (
49+ editor . _tiptapEditor . state . tr . insert (
50+ posBeforeNode + node . nodeSize ,
51+ nodesToInsert
52+ )
4953 ) ;
5054 }
5155
5256 if ( placement === "nested" ) {
5357 // Case if block doesn't already have children.
5458 if ( node . childCount < 2 ) {
55- const blockGroupNode = ttEditor . state . schema . nodes [ "blockGroup" ] . create (
56- { } ,
57- nodesToInsert
58- ) ;
59+ const blockGroupNode = editor . _tiptapEditor . state . schema . nodes [
60+ "blockGroup"
61+ ] . create ( { } , nodesToInsert ) ;
5962
60- ttEditor . view . dispatch (
61- ttEditor . state . tr . insert (
63+ editor . dispatch (
64+ editor . _tiptapEditor . state . tr . insert (
6265 posBeforeNode + node . firstChild ! . nodeSize + 1 ,
6366 blockGroupNode
6467 )
@@ -186,7 +189,7 @@ function removeBlocksWithCallback<
186189 ) ;
187190 }
188191
189- ttEditor . view . dispatch ( tr ) ;
192+ editor . dispatch ( tr ) ;
190193
191194 return removedBlocks ;
192195}
@@ -214,12 +217,10 @@ export function replaceBlocks<
214217 insertedBlocks : Block < BSchema , I , S > [ ] ;
215218 removedBlocks : Block < BSchema , I , S > [ ] ;
216219} {
217- const ttEditor = editor . _tiptapEditor ;
218-
219220 const nodesToInsert : Node [ ] = [ ] ;
220221 for ( const block of blocksToInsert ) {
221222 nodesToInsert . push (
222- blockToNode ( block , ttEditor . schema , editor . schema . styleSchema )
223+ blockToNode ( block , editor . pmSchema , editor . schema . styleSchema )
223224 ) ;
224225 }
225226
@@ -274,8 +275,7 @@ export function insertContentAt<
274275 updateSelection : boolean ;
275276 } = { updateSelection : true }
276277) {
277- const ttEditor = editor . _tiptapEditor ;
278- const tr = ttEditor . state . tr ;
278+ const tr = editor . _tiptapEditor . state . tr ;
279279
280280 // don’t dispatch an empty fragment because this can lead to strange errors
281281 // if (content.toString() === "<>") {
@@ -344,7 +344,7 @@ export function insertContentAt<
344344 selectionToInsertionEnd ( tr , tr . steps . length - 1 , - 1 ) ;
345345 }
346346
347- ttEditor . view . dispatch ( tr ) ;
347+ editor . dispatch ( tr ) ;
348348
349349 return true ;
350350}
0 commit comments