@@ -21,6 +21,7 @@ export const TrackFileDeletionPlugin = (editor: Editor, deleteHandler: TFileHand
2121 [ nodeType : string ] : Set < string > | undefined ;
2222 } = { } ;
2323 if ( ! transactions . some ( ( tr ) => tr . docChanged ) ) return null ;
24+ if ( transactions . some ( ( tr ) => tr . getMeta ( CORE_EDITOR_META . SKIP_FILE_DELETION ) ) ) return null ;
2425
2526 newState . doc . descendants ( ( node ) => {
2627 const nodeType = node . type . name as keyof NodeFileMapType ;
@@ -34,40 +35,35 @@ export const TrackFileDeletionPlugin = (editor: Editor, deleteHandler: TFileHand
3435 }
3536 } ) ;
3637
37- transactions . forEach ( ( transaction ) => {
38- // if the transaction has meta of skipFileDeletion set to true, then return (like while clearing the editor content programmatically)
39- if ( transaction . getMeta ( CORE_EDITOR_META . SKIP_FILE_DELETION ) ) return ;
38+ const removedFiles : TFileNode [ ] = [ ] ;
4039
41- const removedFiles : TFileNode [ ] = [ ] ;
42-
43- // iterate through all the nodes in the old state
44- oldState . doc . descendants ( ( node ) => {
45- const nodeType = node . type . name as keyof NodeFileMapType ;
46- const isAValidNode = NODE_FILE_MAP [ nodeType ] ;
47- // if the node doesn't match, then return as no point in checking
48- if ( ! isAValidNode ) return ;
49- // Check if the node has been deleted or replaced
50- if ( ! newFileSources [ nodeType ] ?. has ( node . attrs . src ) ) {
51- removedFiles . push ( node as TFileNode ) ;
52- }
53- } ) ;
40+ // iterate through all the nodes in the old state
41+ oldState . doc . descendants ( ( node ) => {
42+ const nodeType = node . type . name as keyof NodeFileMapType ;
43+ const isAValidNode = NODE_FILE_MAP [ nodeType ] ;
44+ // if the node doesn't match, then return as no point in checking
45+ if ( ! isAValidNode ) return ;
46+ // Check if the node has been deleted or replaced
47+ if ( ! newFileSources [ nodeType ] ?. has ( node . attrs . src ) ) {
48+ removedFiles . push ( node as TFileNode ) ;
49+ }
50+ } ) ;
5451
55- removedFiles . forEach ( async ( node ) => {
56- const nodeType = node . type . name as keyof NodeFileMapType ;
57- const src = node . attrs . src ;
58- const nodeFileSetDetails = NODE_FILE_MAP [ nodeType ] ;
59- if ( ! nodeFileSetDetails || ! src ) return ;
60- try {
61- editor . storage [ nodeType ] ?. [ nodeFileSetDetails . fileSetName ] ?. set ( src , true ) ;
62- // update assets list storage value
63- editor . commands . updateAssetsList ?.( {
64- idToRemove : node . attrs . id ,
65- } ) ;
66- await deleteHandler ( src ) ;
67- } catch ( error ) {
68- console . error ( "Error deleting file via delete utility plugin:" , error ) ;
69- }
70- } ) ;
52+ removedFiles . forEach ( async ( node ) => {
53+ const nodeType = node . type . name as keyof NodeFileMapType ;
54+ const src = node . attrs . src ;
55+ const nodeFileSetDetails = NODE_FILE_MAP [ nodeType ] ;
56+ if ( ! nodeFileSetDetails || ! src ) return ;
57+ try {
58+ editor . storage [ nodeType ] ?. [ nodeFileSetDetails . fileSetName ] ?. set ( src , true ) ;
59+ // update assets list storage value
60+ editor . commands . updateAssetsList ?.( {
61+ idToRemove : node . attrs . id ,
62+ } ) ;
63+ await deleteHandler ( src ) ;
64+ } catch ( error ) {
65+ console . error ( "Error deleting file via delete utility plugin:" , error ) ;
66+ }
7167 } ) ;
7268
7369 return null ;
0 commit comments