@@ -15,7 +15,7 @@ const BATCH_SIZE = 50;
1515
1616export function parseCsv ( text : string ) : { headers : string [ ] ; rows : Record < string , string > [ ] } {
1717 const lines = text . split ( / \r ? \n / ) ;
18- if ( lines . length === 0 ) return { headers : [ ] , rows : [ ] } ;
18+ if ( lines . length === 0 || lines [ 0 ] . trim ( ) === '' ) return { headers : [ ] , rows : [ ] } ;
1919
2020 const headers = parseCsvRow ( lines [ 0 ] ) ;
2121 const rows : Record < string , string > [ ] = [ ] ;
@@ -84,19 +84,14 @@ export async function importCsv(plugin: Mols2BasesPlugin): Promise<void> {
8484
8585 try {
8686 const content = await readFileAsText ( file ) ;
87- const { headers , rows } = parseCsv ( content ) ;
87+ const { rows } = parseCsv ( content ) ;
8888
8989 if ( rows . length === 0 ) {
9090 notice . hide ( ) ;
9191 new Notice ( 'No data rows found in the CSV file.' ) ;
9292 return ;
9393 }
9494
95- // Auto-detect SMILES column (case-insensitive)
96- const smilesHeader = headers . find (
97- ( h ) => h . toLowerCase ( ) === plugin . settings . csvSmilesField . toLowerCase ( ) ,
98- ) ;
99-
10095 notice . setMessage ( `Importing ${ rows . length } rows...` ) ;
10196
10297 // Create folder based on filename
@@ -108,38 +103,19 @@ export async function importCsv(plugin: Mols2BasesPlugin): Promise<void> {
108103 }
109104
110105 // Create .base file early so the view populates as notes arrive
111- const baseContent = buildBaseFile (
112- `${ folderPath } .base` ,
113- smilesHeader ? `note.${ plugin . settings . csvSmilesField } ` : undefined ,
114- ) ;
106+ const baseContent = buildBaseFile ( `${ folderPath } .base` ) ;
115107 const basePath = normalizePath ( `${ folderPath } .base` ) ;
116108 const baseFile = await plugin . app . vault . create ( basePath , baseContent ) ;
117109 await plugin . app . workspace . getLeaf ( false ) . openFile ( baseFile ) ;
118110
119- // Show warning if no SMILES column was found
120- if ( ! smilesHeader ) {
121- new Notice (
122- `No "${ plugin . settings . csvSmilesField } " column found — select the molecule property in the view options.` ,
123- 5000 ,
124- ) ;
125- }
126-
127- // Find first non-smiles header for note naming
128- const nameHeader = headers . find ( ( h ) => h !== smilesHeader ) ;
129-
130111 for ( let i = 0 ; i < rows . length ; i ++ ) {
131112 const row = rows [ i ] ;
132- const name = ( nameHeader && row [ nameHeader ] ?. trim ( ) ) || `row_${ i + 1 } ` ;
113+ const name = `row_${ i + 1 } ` ;
133114
134- // Build frontmatter
135115 const frontmatter : Record < string , string > = { } ;
136- if ( smilesHeader ) {
137- frontmatter [ smilesHeader ] = row [ smilesHeader ] ;
138- }
139116 frontmatter [ INTERNAL_KEYS . LINK ] = `[[${ baseName } .base]]` ;
140117
141118 for ( const [ key , value ] of Object . entries ( row ) ) {
142- if ( smilesHeader && key === smilesHeader ) continue ;
143119 if ( ! frontmatter [ key ] ) {
144120 frontmatter [ key ] = value ;
145121 }
@@ -150,7 +126,6 @@ export async function importCsv(plugin: Mols2BasesPlugin): Promise<void> {
150126 const finalPath = await uniquePath ( plugin . app , notePath ) ;
151127 await plugin . app . vault . create ( finalPath , `---\n${ yaml } ---\n` ) ;
152128
153- // Yield to the event loop after each batch
154129 if ( ( i + 1 ) % BATCH_SIZE === 0 ) {
155130 notice . setMessage ( `Importing rows... (${ i + 1 } / ${ rows . length } )` ) ;
156131 await sleep ( 0 ) ;
0 commit comments