@@ -369,14 +369,14 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
369369 // Check if this is a node we were trying to create
370370 if (_documentBuilder.uncommittedNodes.containsKey (nodeId)) {
371371 _logger.info ('Node $nodeId was deleted before it was committed, removing from uncommitted nodes' );
372- _documentBuilder.uncommittedNodes. remove (nodeId);
372+ _documentBuilder.removeUncommittedNode (nodeId);
373373 return ;
374374 }
375375
376376 _logger.info ('Node $nodeId was deleted, will delete block $blockId on server' );
377377
378378 // Remove from our mappings
379- _documentBuilder.nodeToBlockMap. remove (nodeId);
379+ _documentBuilder.removeNodeMapping (nodeId);
380380
381381 // Remove from blocks list if it exists
382382 _blocks.remove (blockId);
@@ -437,13 +437,13 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
437437 // Create block through BlockService
438438 final block = await _blockService.createBlock (
439439 noteId! ,
440- extractedData, // Pass the complete object with content and metadata
440+ extractedData,
441441 blockType,
442442 order
443443 );
444444
445445 // Update our mappings
446- _documentBuilder.nodeToBlockMap[ nodeId] = block.id;
446+ _documentBuilder.linkNodeToBlock ( nodeId, block.id) ;
447447 _blocks[block.id] = block;
448448
449449 // Add to note blocks map
@@ -453,7 +453,7 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
453453 }
454454
455455 // Remove from uncommitted nodes
456- _documentBuilder.uncommittedNodes. remove (nodeId);
456+ _documentBuilder.removeUncommittedNode (nodeId);
457457
458458 // Subscribe to this block
459459 _webSocketService.subscribe ('block' , id: block.id);
@@ -465,7 +465,7 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
465465 } catch (e) {
466466 _logger.error ('Failed to create block for node $nodeId : $e ' );
467467 // Remove from uncommitted nodes to prevent infinite retry loops
468- _documentBuilder.uncommittedNodes. remove (nodeId);
468+ _documentBuilder.removeUncommittedNode (nodeId);
469469 }
470470 }
471471
@@ -653,30 +653,6 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
653653 (_activeNoteIds.contains (eventNoteId ?? '' ));
654654
655655 if (shouldUpdate) {
656- try {
657- // Try to construct block from event payload
658- final existingBlock = _blocks[blockId];
659- if (existingBlock != null ) {
660- final updatedBlock = Block (
661- id: blockId,
662- noteId: existingBlock.noteId,
663- type: existingBlock.type,
664- order: existingBlock.order,
665- content: parsedMessage.payload['content' ],
666- metadata: parsedMessage.payload['metadata' ],
667- updatedAt: DateTime .now (),
668- createdAt: existingBlock.createdAt
669- );
670-
671- _blocks[blockId] = updatedBlock;
672- _updateDocumentWithBlock (updatedBlock);
673- _enqueueNotification ();
674- return ;
675- }
676- } catch (e) {
677- _logger.error ('Error creating block from payload: $e ' );
678- // Fall back to fetching the block
679- }
680656 fetchBlockById (blockId).then ((block) {
681657 if (block != null ) {
682658 _updateDocumentWithBlock (block);
@@ -799,8 +775,7 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
799775 if (! _noteBlocksMap[block.noteId]! .contains (block.id)) {
800776 _noteBlocksMap[block.noteId]! .add (block.id);
801777 }
802-
803- // Let _updateDocumentWithBlock handle the document update logic
778+
804779 _updateDocumentWithBlock (block);
805780 }
806781
@@ -944,11 +919,16 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
944919 } else if (type == 'task' ) {
945920 metadata['is_completed' ] = false ;
946921 }
922+
923+ final payload = {
924+ "metadata" : metadata,
925+ "content" : content,
926+ };
947927
948928 // Create block on server
949929 final block = await _blockService.createBlock (
950930 _noteId! ,
951- content ,
931+ payload ,
952932 type,
953933 order
954934 );
@@ -994,7 +974,7 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
994974 if (node != null ) {
995975 _documentBuilder.document.deleteNode (nodeId);
996976 }
997- _documentBuilder.nodeToBlockMap. remove (nodeId);
977+ _documentBuilder.removeNodeMapping (nodeId);
998978 }
999979 } finally {
1000980 _updatingDocument = false ;
@@ -1588,15 +1568,10 @@ class NoteEditorProvider with ChangeNotifier implements NoteEditorViewModel {
15881568 await _createBlockForNode (nodeId, node);
15891569 } else {
15901570 // Node no longer exists, remove from tracking
1591- _documentBuilder.uncommittedNodes. remove (nodeId);
1571+ _documentBuilder.removeUncommittedNode (nodeId);
15921572 }
15931573 }
15941574 }
1595-
1596- @override
1597- void markBlockAsModified (String blockId) {
1598- _documentBuilder.markBlockAsModified (blockId);
1599- }
16001575
16011576 @override
16021577 Future <void > fetchBlockFromEvent (String blockId) async {
0 commit comments