@@ -49,6 +49,7 @@ function insertOrUpdateBlock<
49
49
editor : BlockNoteEditor < BSchema , I , S > ,
50
50
referenceBlock : Block < BSchema , I , S > ,
51
51
newBlock : PartialBlock < BSchema , I , S > ,
52
+ placement : "before" | "after" = "after" ,
52
53
) {
53
54
let insertedBlockId : string | undefined ;
54
55
@@ -61,7 +62,7 @@ function insertOrUpdateBlock<
61
62
insertedBlockId = editor . insertBlocks (
62
63
[ newBlock ] ,
63
64
referenceBlock ,
64
- "after" ,
65
+ placement ,
65
66
) [ 0 ] . id ;
66
67
}
67
68
@@ -156,16 +157,26 @@ export async function handleFileInsertion<
156
157
} ;
157
158
158
159
const pos = editor . prosemirrorView ?. posAtCoords ( coords ) ;
160
+
159
161
if ( ! pos ) {
160
162
return ;
161
163
}
162
164
163
165
insertedBlockId = editor . transact ( ( tr ) => {
164
166
const posInfo = getNearestBlockPos ( tr . doc , pos . pos ) ;
167
+ const blockElement = editor . prosemirrorView ?. dom . querySelector (
168
+ `[data-id="${ posInfo . node . attrs . id } "]` ,
169
+ ) ;
170
+
171
+ const blockRect = blockElement ?. getBoundingClientRect ( ) ;
172
+
165
173
return insertOrUpdateBlock (
166
174
editor ,
167
175
editor . getBlock ( posInfo . node . attrs . id ) ! ,
168
176
fileBlock ,
177
+ blockRect && ( blockRect . top + blockRect . bottom ) / 2 > coords . top
178
+ ? "before"
179
+ : "after" ,
169
180
) ;
170
181
} ) ;
171
182
} else {
0 commit comments