@@ -284,6 +284,9 @@ const EventHandler = struct {
284
284
285
285
const muevt = parser .eventToMutationEvent (evt .? );
286
286
287
+ // TODO get the allocator by another way?
288
+ const alloc = data .cbk .nat_ctx .alloc ;
289
+
287
290
if (std .mem .eql (u8 , t , "DOMAttrModified" )) {
288
291
mrs .first = .{
289
292
.type = "attributes" ,
@@ -305,12 +308,41 @@ const EventHandler = struct {
305
308
if (o .options .characterDataOldValue ) {
306
309
mrs .first .? .oldValue = parser .mutationEventPrevValue (muevt ) catch null ;
307
310
}
311
+ } else if (std .mem .eql (u8 , t , "DOMNodeInserted" )) {
312
+ mrs .first = .{
313
+ .type = "childList" ,
314
+ .target = o .node ,
315
+ .addedNodes = NodeList .init (),
316
+ .removedNodes = NodeList .init (),
317
+ };
318
+
319
+ const rn = parser .mutationEventRelatedNode (muevt ) catch null ;
320
+ if (rn ) | n | {
321
+ mrs .first .? .addedNodes .append (alloc , n ) catch | e | {
322
+ log .err ("mutation event handler error: {any}" , .{e });
323
+ return ;
324
+ };
325
+ }
326
+ } else if (std .mem .eql (u8 , t , "DOMNodeRemoved" )) {
327
+ mrs .first = .{
328
+ .type = "childList" ,
329
+ .target = o .node ,
330
+ .addedNodes = NodeList .init (),
331
+ .removedNodes = NodeList .init (),
332
+ };
333
+
334
+ const rn = parser .mutationEventRelatedNode (muevt ) catch null ;
335
+ if (rn ) | n | {
336
+ mrs .first .? .removedNodes .append (alloc , n ) catch | e | {
337
+ log .err ("mutation event handler error: {any}" , .{e });
338
+ return ;
339
+ };
340
+ }
308
341
} else {
309
342
return ;
310
343
}
311
344
312
- // TODO get the allocator by another way?
313
- var res = CallbackResult .init (data .cbk .nat_ctx .alloc );
345
+ var res = CallbackResult .init (alloc );
314
346
defer res .deinit ();
315
347
316
348
// TODO pass MutationRecords and MutationObserver
0 commit comments