a tool for shared writing and social publishing
at feature/footnotes 32 lines 770 B view raw
1import { useEditorStates } from "src/state/useEditorState"; 2 3export function deleteFootnoteFromBlock( 4 footnoteEntityID: string, 5 blockID: string, 6 rep: any, 7) { 8 if (!rep) return; 9 10 let editorState = useEditorStates.getState().editorStates[blockID]; 11 if (editorState?.view) { 12 let view = editorState.view; 13 let { doc } = view.state; 14 let tr = view.state.tr; 15 let found = false; 16 doc.descendants((node, pos) => { 17 if ( 18 found || 19 node.type.name !== "footnote" || 20 node.attrs.footnoteEntityID !== footnoteEntityID 21 ) 22 return; 23 found = true; 24 tr.delete(pos, pos + node.nodeSize); 25 }); 26 if (found) { 27 view.dispatch(tr); 28 } 29 } 30 31 rep.mutate.deleteFootnote({ footnoteEntityID, blockID }); 32}