({
diagram,
newDiagram,
diffMap,
changedNotes,
attributes,
changedNotesAttributes,
changeTypes,
noteMatcher,
}: {
diagram: Diagram;
newDiagram: Diagram;
diffMap: DiffMap;
changedNotes: Map<string, boolean>;
attributes?: NoteDiffAttribute[];
changedNotesAttributes?: NoteDiffAttribute[];
changeTypes?: NoteDiff['type'][];
noteMatcher: (note: Note, notes: Note[]) => Note | undefined;
})
| 1804 | |
| 1805 | // Compare notes between diagrams |
| 1806 | function compareNotes({ |
| 1807 | diagram, |
| 1808 | newDiagram, |
| 1809 | diffMap, |
| 1810 | changedNotes, |
| 1811 | attributes, |
| 1812 | changedNotesAttributes, |
| 1813 | changeTypes, |
| 1814 | noteMatcher, |
| 1815 | }: { |
| 1816 | diagram: Diagram; |
| 1817 | newDiagram: Diagram; |
| 1818 | diffMap: DiffMap; |
| 1819 | changedNotes: Map<string, boolean>; |
| 1820 | attributes?: NoteDiffAttribute[]; |
| 1821 | changedNotesAttributes?: NoteDiffAttribute[]; |
| 1822 | changeTypes?: NoteDiff['type'][]; |
| 1823 | noteMatcher: (note: Note, notes: Note[]) => Note | undefined; |
| 1824 | }) { |
| 1825 | const oldNotes = diagram.notes || []; |
| 1826 | const newNotes = newDiagram.notes || []; |
| 1827 | |
| 1828 | // If changeTypes is empty array, don't check any changes |
| 1829 | if (changeTypes && changeTypes.length === 0) { |
| 1830 | return; |
| 1831 | } |
| 1832 | |
| 1833 | // If changeTypes is undefined, check all types |
| 1834 | const typesToCheck = changeTypes ?? ['added', 'removed', 'changed']; |
| 1835 | |
| 1836 | // Check for added notes |
| 1837 | if (typesToCheck.includes('added')) { |
| 1838 | for (const newNote of newNotes) { |
| 1839 | if (!noteMatcher(newNote, oldNotes)) { |
| 1840 | diffMap.set( |
| 1841 | getDiffMapKey({ |
| 1842 | diffObject: 'note', |
| 1843 | objectId: newNote.id, |
| 1844 | }), |
| 1845 | { |
| 1846 | object: 'note', |
| 1847 | type: 'added', |
| 1848 | noteAdded: newNote, |
| 1849 | } |
| 1850 | ); |
| 1851 | changedNotes.set(newNote.id, true); |
| 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | // Check for removed notes |
| 1857 | if (typesToCheck.includes('removed')) { |
| 1858 | for (const oldNote of oldNotes) { |
| 1859 | if (!noteMatcher(oldNote, newNotes)) { |
| 1860 | diffMap.set( |
| 1861 | getDiffMapKey({ |
| 1862 | diffObject: 'note', |
| 1863 | objectId: oldNote.id, |
no test coverage detected