@@ -23,42 +23,45 @@ export function insertBlocks<
23
23
placement : "before" | "after" | "nested" = "before" ,
24
24
editor : BlockNoteEditor < BSchema , I , S >
25
25
) : Block < BSchema , I , S > [ ] {
26
- const ttEditor = editor . _tiptapEditor ;
27
-
28
26
const id =
29
27
typeof referenceBlock === "string" ? referenceBlock : referenceBlock . id ;
30
28
31
29
const nodesToInsert : Node [ ] = [ ] ;
32
30
for ( const blockSpec of blocksToInsert ) {
33
31
nodesToInsert . push (
34
- blockToNode ( blockSpec , ttEditor . schema , editor . schema . styleSchema )
32
+ blockToNode ( blockSpec , editor . pmSchema , editor . schema . styleSchema )
35
33
) ;
36
34
}
37
35
38
- const { node, posBeforeNode } = getNodeById ( id , ttEditor . state . doc ) ;
36
+ const { node, posBeforeNode } = getNodeById (
37
+ id ,
38
+ editor . _tiptapEditor . state . doc
39
+ ) ;
39
40
40
41
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 )
43
44
) ;
44
45
}
45
46
46
47
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
+ )
49
53
) ;
50
54
}
51
55
52
56
if ( placement === "nested" ) {
53
57
// Case if block doesn't already have children.
54
58
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 ) ;
59
62
60
- ttEditor . view . dispatch (
61
- ttEditor . state . tr . insert (
63
+ editor . dispatch (
64
+ editor . _tiptapEditor . state . tr . insert (
62
65
posBeforeNode + node . firstChild ! . nodeSize + 1 ,
63
66
blockGroupNode
64
67
)
@@ -186,7 +189,7 @@ function removeBlocksWithCallback<
186
189
) ;
187
190
}
188
191
189
- ttEditor . view . dispatch ( tr ) ;
192
+ editor . dispatch ( tr ) ;
190
193
191
194
return removedBlocks ;
192
195
}
@@ -214,12 +217,10 @@ export function replaceBlocks<
214
217
insertedBlocks : Block < BSchema , I , S > [ ] ;
215
218
removedBlocks : Block < BSchema , I , S > [ ] ;
216
219
} {
217
- const ttEditor = editor . _tiptapEditor ;
218
-
219
220
const nodesToInsert : Node [ ] = [ ] ;
220
221
for ( const block of blocksToInsert ) {
221
222
nodesToInsert . push (
222
- blockToNode ( block , ttEditor . schema , editor . schema . styleSchema )
223
+ blockToNode ( block , editor . pmSchema , editor . schema . styleSchema )
223
224
) ;
224
225
}
225
226
@@ -274,8 +275,7 @@ export function insertContentAt<
274
275
updateSelection : boolean ;
275
276
} = { updateSelection : true }
276
277
) {
277
- const ttEditor = editor . _tiptapEditor ;
278
- const tr = ttEditor . state . tr ;
278
+ const tr = editor . _tiptapEditor . state . tr ;
279
279
280
280
// don’t dispatch an empty fragment because this can lead to strange errors
281
281
// if (content.toString() === "<>") {
@@ -344,7 +344,7 @@ export function insertContentAt<
344
344
selectionToInsertionEnd ( tr , tr . steps . length - 1 , - 1 ) ;
345
345
}
346
346
347
- ttEditor . view . dispatch ( tr ) ;
347
+ editor . dispatch ( tr ) ;
348
348
349
349
return true ;
350
350
}
0 commit comments