-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
852 lines (789 loc) · 54.5 KB
/
index.html
File metadata and controls
852 lines (789 loc) · 54.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Academic CV Builder</title>
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; }
.loading { display: flex; align-items: center; justify-content: center; height: 100vh; font-size: 1.25rem; color: #475569; }
</style>
</head>
<body>
<div id="root"><div class="loading">Loading CV Builder...</div></div>
<script type="text/babel">
const { useState, useRef, useCallback } = React;
// Initial empty CV state matching biobib structure
const emptyCV = {
personalInfo: {
firstName: '',
middleName: '',
lastName: '',
department: '',
titles: []
},
employmentHistory: [],
education: [],
subspecializations: [],
professionalData: {
universityService: [],
memberships: [],
honorsAwards: [],
currentGrants: [],
previousGrants: [],
externalProfessional: {
nationalCommittee: [],
editorialBoard: [],
adHocReview: [],
nationalPresentations: [],
internationalPresentations: []
},
diversityContributions: [],
otherActivities: {
localProfessional: [],
communityPresentations: []
},
studentInstructional: {
teachingCourses: [],
formalTeaching: [],
supervisory: [],
mentorship: []
},
externalReviews: []
},
bibliography: {
primaryWork: {
originalPeerReviewed: [],
reviewInvited: [],
booksChapters: [],
editorials: [],
commentary: [],
caseReports: []
},
otherWork: {
abstracts: [],
popularWorks: [],
additionalProducts: []
},
workInProgress: []
},
publicationsLink: '',
lastUpdated: null
};
// Icons as simple SVG components
const Icons = {
Upload: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" /></svg>,
Download: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" /></svg>,
Plus: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" /></svg>,
Trash: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>,
ChevronDown: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" /></svg>,
ChevronRight: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" /></svg>,
FileText: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>,
User: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /></svg>,
Briefcase: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" /></svg>,
GraduationCap: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 14l9-5-9-5-9 5 9 5z" /><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z" /></svg>,
Award: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z" /></svg>,
BookOpen: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" /></svg>,
Eye: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" /></svg>,
X: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /></svg>,
Check: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>,
Globe: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9" /></svg>,
Database: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4" /></svg>,
File: () => <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" /></svg>,
AlertCircle: () => <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>,
};
// MEDLINE Parser
function parseMedline(text) {
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
const publications = [];
const records = text.split(/\n\nPMID-/).map((r, i) => i === 0 ? r : 'PMID-' + r);
for (const record of records) {
if (!record.trim()) continue;
const fields = {};
let currentField = null;
let currentValue = [];
const lines = record.split('\n');
for (const line of lines) {
const fieldMatch = line.match(/^([A-Z]{2,4})\s*-\s*(.*)$/);
if (fieldMatch) {
if (currentField) {
if (!fields[currentField]) fields[currentField] = [];
fields[currentField].push(currentValue.join(' ').trim());
}
currentField = fieldMatch[1];
currentValue = [fieldMatch[2]];
} else if (currentField && line.match(/^\s{2,}/)) {
currentValue.push(line.trim());
}
}
if (currentField) {
if (!fields[currentField]) fields[currentField] = [];
fields[currentField].push(currentValue.join(' ').trim());
}
if (fields.TI && fields.TI[0]) {
const authors = (fields.AU || []).join(', ');
const title = fields.TI[0];
const journal = fields.TA ? fields.TA[0] : (fields.JT ? fields.JT[0] : '');
const year = fields.DP ? fields.DP[0].substring(0, 4) : '';
const volume = fields.VI ? fields.VI[0] : '';
const issue = fields.IP ? fields.IP[0] : '';
const pages = fields.PG ? fields.PG[0] : '';
const pmid = fields.PMID ? fields.PMID[0] : '';
const doi = fields.LID ? fields.LID.find(l => l.includes('[doi]'))?.replace(' [doi]', '') : '';
const pubTypes = fields.PT || [];
const isReview = pubTypes.some(pt => pt.toLowerCase().includes('review'));
const isBookChapter = pubTypes.some(pt => pt.toLowerCase().includes('book') || pt.toLowerCase().includes('chapter'));
let citation = '';
if (authors) citation += authors + '. ';
citation += title;
if (!title.endsWith('.')) citation += '.';
if (journal) {
citation += ' ' + journal + '.';
if (year) citation += ' ' + year;
if (volume) {
citation += ';' + volume;
if (issue) citation += '(' + issue + ')';
}
if (pages) citation += ':' + pages;
citation += '.';
}
if (doi) citation += ' doi:' + doi;
if (pmid) citation += ' PMID:' + pmid;
publications.push({
id: Date.now() + Math.random(),
text: citation.trim(),
pmid,
year: parseInt(year) || 0,
isReview,
isBookChapter
});
}
}
publications.sort((a, b) => a.year - b.year);
return publications;
}
// Section configurations
const sections = [
{ id: 'personal', title: 'Personal Information', icon: 'User' },
{ id: 'employment', title: 'Employment History', icon: 'Briefcase' },
{ id: 'education', title: 'Education', icon: 'GraduationCap' },
{ id: 'professional', title: 'Professional Data', icon: 'Award' },
{ id: 'bibliography', title: 'Bibliography', icon: 'BookOpen' }
];
const professionalSubsections = [
{ id: 'universityService', title: 'University Service', description: 'Departmental, college, Academic Senate, campuswide, systemwide', type: 'simple' },
{ id: 'memberships', title: 'Memberships', description: 'Scholarly societies, professional boards, civic organizations', type: 'simple' },
{ id: 'honorsAwards', title: 'Honors and Awards', description: 'Include dates received', type: 'simple' },
{ id: 'grants', title: 'Contracts and Grants', description: 'Current and previous contracts and grants', type: 'grants' },
{ id: 'externalProfessional', title: 'External Professional Activities', description: 'Technical service, reviewer roles, committee service', type: 'nested',
subsections: [
{ id: 'nationalCommittee', title: 'National Committee Service' },
{ id: 'editorialBoard', title: 'Editorial Board' },
{ id: 'adHocReview', title: 'Ad Hoc Review' },
{ id: 'nationalPresentations', title: 'National Presentations' },
{ id: 'internationalPresentations', title: 'International Presentations' }
]
},
{ id: 'diversityContributions', title: 'Diversity Contributions', description: 'Promoting diversity in scholarship, teaching, and service', type: 'simple' },
{ id: 'otherActivities', title: 'Other Activities', description: 'Community service and other activities', type: 'nested',
subsections: [
{ id: 'localProfessional', title: 'Local Professional Presentations' },
{ id: 'communityPresentations', title: 'Community Presentations' }
]
},
{ id: 'studentInstructional', title: 'Student Instructional Activities', description: '', type: 'studentInstructional',
subsections: [
{ id: 'teachingCourses', title: 'Teaching of Students in Courses' },
{ id: 'formalTeaching', title: 'Formal Teaching of Residents, Clinical Fellows and Research Fellows' },
{ id: 'supervisory', title: 'Supervisory and Training Responsibilities' },
{ id: 'mentorship', title: 'Mentorship of Trainees' }
]
},
{ id: 'externalReviews', title: 'External Reviews', description: 'Independent reviews or feature articles appearing in journals or online venues, major newspapers, books, or catalogs', type: 'simple' }
];
const bibliographySubsections = {
primaryWork: [
{ id: 'originalPeerReviewed', title: 'Original Peer-Reviewed Work' },
{ id: 'reviewInvited', title: 'Review and Invited Articles' },
{ id: 'booksChapters', title: 'Books and Book Chapters' },
{ id: 'editorials', title: 'Editorials' },
{ id: 'commentary', title: 'Commentary' },
{ id: 'caseReports', title: 'Case Reports' }
],
otherWork: [
{ id: 'abstracts', title: 'Abstracts' },
{ id: 'popularWorks', title: 'Popular Works' },
{ id: 'additionalProducts', title: 'Additional Products' }
]
};
// Input component
const Input = ({ label, value, onChange, placeholder, multiline, className = '' }) => (
<div className={`space-y-1 ${className}`}>
{label && <label className="block text-xs font-medium text-slate-600">{label}</label>}
{multiline ? (
<textarea
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
rows={2}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm text-slate-800 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-teal-500/30 focus:border-teal-500 transition-all resize-none"
/>
) : (
<input
type="text"
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
className="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm text-slate-800 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-teal-500/30 focus:border-teal-500 transition-all"
/>
)}
</div>
);
// Button component
const Button = ({ children, onClick, variant = 'primary', size = 'md', className = '', disabled = false }) => {
const baseStyles = "inline-flex items-center justify-center gap-1.5 font-medium rounded-lg transition-all duration-200 disabled:opacity-50";
const variants = {
primary: "bg-teal-600 text-white hover:bg-teal-700 shadow-sm",
secondary: "bg-slate-100 text-slate-700 hover:bg-slate-200 border border-slate-200",
danger: "bg-red-500 text-white hover:bg-red-600",
ghost: "text-slate-600 hover:bg-slate-100",
pubmed: "bg-blue-600 text-white hover:bg-blue-700 shadow-sm"
};
const sizes = { sm: "px-2.5 py-1.5 text-xs", md: "px-4 py-2 text-sm" };
return (
<button onClick={onClick} disabled={disabled} className={`${baseStyles} ${variants[variant]} ${sizes[size]} ${className}`}>
{children}
</button>
);
};
// Collapsible Section
const CollapsibleSection = ({ title, iconName, children, defaultOpen = false, badge }) => {
const [isOpen, setIsOpen] = useState(defaultOpen);
const Icon = Icons[iconName] || Icons.FileText;
return (
<div className="bg-white rounded-xl border border-slate-200 overflow-hidden shadow-sm">
<button onClick={() => setIsOpen(!isOpen)} className="w-full px-4 py-3 flex items-center gap-3 hover:bg-slate-50 transition-colors">
<div className="w-8 h-8 rounded-lg bg-teal-50 flex items-center justify-center text-teal-600"><Icon /></div>
<span className="flex-1 text-left font-medium text-slate-700 text-sm">{title}</span>
{badge && <span className="px-2 py-0.5 bg-teal-100 text-teal-700 text-xs font-medium rounded-full">{badge}</span>}
{isOpen ? <Icons.ChevronDown /> : <Icons.ChevronRight />}
</button>
{isOpen && <div className="px-4 pb-4 pt-2 border-t border-slate-100">{children}</div>}
</div>
);
};
// Simple List Editor
const SimpleListEditor = ({ items, setItems, placeholder }) => {
const [newItem, setNewItem] = useState('');
const addItem = () => { if (newItem.trim()) { setItems([...items, { id: Date.now(), text: newItem.trim() }]); setNewItem(''); } };
const deleteItem = (index) => setItems(items.filter((_, i) => i !== index));
const updateItem = (index, value) => { const updated = [...items]; updated[index] = { ...updated[index], text: value }; setItems(updated); };
return (
<div className="space-y-2">
{items.map((item, index) => (
<div key={item.id || index} className="flex gap-2 items-start">
<textarea value={item.text || item} onChange={(e) => updateItem(index, e.target.value)} rows={2} className="flex-1 px-3 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm resize-none focus:outline-none focus:ring-2 focus:ring-teal-500/30" />
<button onClick={() => deleteItem(index)} className="p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg"><Icons.Trash /></button>
</div>
))}
<div className="flex gap-2">
<textarea value={newItem} onChange={(e) => setNewItem(e.target.value)} placeholder={placeholder} rows={2} className="flex-1 px-3 py-2 bg-white border-2 border-dashed border-teal-200 rounded-lg text-sm resize-none focus:outline-none focus:ring-2 focus:ring-teal-500/30" />
<Button onClick={addItem} size="sm" className="self-end"><Icons.Plus /></Button>
</div>
</div>
);
};
// List Item Editor for structured entries
const ListItemEditor = ({ items, setItems, fields, itemName }) => {
const [newItem, setNewItem] = useState({});
const addItem = () => { if (Object.values(newItem).some(v => v && v.trim())) { setItems([...items, { ...newItem, id: Date.now() }]); setNewItem({}); } };
const updateItem = (index, field, value) => { const updated = [...items]; updated[index] = { ...updated[index], [field]: value }; setItems(updated); };
const deleteItem = (index) => setItems(items.filter((_, i) => i !== index));
return (
<div className="space-y-3">
{items.map((item, index) => (
<div key={item.id || index} className="p-3 bg-slate-50 rounded-lg border border-slate-200 space-y-2">
<div className="flex justify-between items-center">
<span className="text-xs font-medium text-slate-500">{itemName} #{index + 1}</span>
<button onClick={() => deleteItem(index)} className="p-1 text-slate-400 hover:text-red-500 rounded"><Icons.Trash /></button>
</div>
<div className="grid grid-cols-2 gap-2">
{fields.map(field => (
<Input key={field.id} label={field.label} value={item[field.id] || ''} onChange={(value) => updateItem(index, field.id, value)} placeholder={field.placeholder} className={field.fullWidth ? 'col-span-2' : ''} />
))}
</div>
</div>
))}
<div className="p-3 bg-teal-50/50 rounded-lg border-2 border-dashed border-teal-200 space-y-2">
<span className="text-xs font-medium text-teal-600">Add New {itemName}</span>
<div className="grid grid-cols-2 gap-2">
{fields.map(field => (
<Input key={field.id} label={field.label} value={newItem[field.id] || ''} onChange={(value) => setNewItem({ ...newItem, [field.id]: value })} placeholder={field.placeholder} className={field.fullWidth ? 'col-span-2' : ''} />
))}
</div>
<Button onClick={addItem} size="sm"><Icons.Plus /> Save/Add</Button>
</div>
</div>
);
};
// Import Modal
const ImportModal = ({ isOpen, onClose, onImport }) => {
const [importType, setImportType] = useState(null);
const [medlineText, setMedlineText] = useState('');
const [parsedPubs, setParsedPubs] = useState([]);
const [selectedPubs, setSelectedPubs] = useState(new Set());
const fileInputRef = useRef(null);
if (!isOpen) return null;
const handleMedlineParse = () => { const pubs = parseMedline(medlineText); setParsedPubs(pubs); setSelectedPubs(new Set(pubs.map(p => p.id))); };
const handleFileSelect = async (e) => {
const file = e.target.files[0];
if (file && file.name.endsWith('.txt')) {
const text = await file.text();
setMedlineText(text);
const pubs = parseMedline(text);
setParsedPubs(pubs);
setSelectedPubs(new Set(pubs.map(p => p.id)));
}
};
const handleImportPubs = () => {
const selected = parsedPubs.filter(p => selectedPubs.has(p.id));
onImport({ type: 'publications', data: { original: selected.filter(p => !p.isReview && !p.isBookChapter), reviews: selected.filter(p => p.isReview), books: selected.filter(p => p.isBookChapter) } });
onClose();
};
const togglePub = (id) => { const newSelected = new Set(selectedPubs); if (newSelected.has(id)) newSelected.delete(id); else newSelected.add(id); setSelectedPubs(newSelected); };
return (
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div className="bg-white rounded-2xl shadow-2xl max-w-3xl w-full max-h-[90vh] overflow-hidden">
<div className="px-5 py-4 border-b flex items-center justify-between bg-gradient-to-r from-teal-600 to-blue-600">
<h2 className="font-bold text-white text-lg">Import Data</h2>
<button onClick={onClose} className="p-1.5 text-white/80 hover:text-white rounded-lg"><Icons.X /></button>
</div>
<div className="p-6 overflow-y-auto max-h-[calc(90vh-140px)]">
{!importType ? (
<div className="space-y-4">
<p className="text-slate-600 text-sm">Choose what you'd like to import:</p>
<button onClick={() => setImportType('medline')} className="w-full p-6 border-2 border-slate-200 rounded-xl hover:border-blue-400 hover:bg-blue-50/50 transition-all text-left">
<div className="w-12 h-12 rounded-xl bg-blue-100 flex items-center justify-center text-blue-600 mb-3"><Icons.Database /></div>
<h3 className="font-semibold text-slate-800 mb-1">PubMed Publications</h3>
<p className="text-sm text-slate-500">Import from MEDLINE format export</p>
</button>
</div>
) : (
<div className="space-y-4">
<button onClick={() => { setImportType(null); setParsedPubs([]); setMedlineText(''); }} className="text-sm text-teal-600 hover:text-teal-700">← Back</button>
<div className="bg-blue-50 border border-blue-200 rounded-xl p-4">
<h3 className="font-semibold text-blue-800 mb-2">Import from PubMed (MEDLINE Format)</h3>
<p className="text-sm text-blue-700 mb-3">Search PubMed → Select citations → Send to → File → Format: MEDLINE</p>
<input ref={fileInputRef} type="file" accept=".txt" onChange={handleFileSelect} className="hidden" />
<Button variant="secondary" size="sm" onClick={() => fileInputRef.current?.click()} className="mb-3"><Icons.Upload /> Upload .txt</Button>
<textarea value={medlineText} onChange={(e) => setMedlineText(e.target.value)} placeholder="Or paste MEDLINE text..." rows={6} className="w-full px-3 py-2 border border-blue-200 rounded-lg text-sm font-mono resize-none" />
{medlineText && parsedPubs.length === 0 && <Button variant="pubmed" size="sm" onClick={handleMedlineParse} className="mt-2">Parse Publications</Button>}
</div>
{parsedPubs.length > 0 && (
<div className="space-y-3">
<div className="flex items-center justify-between">
<h4 className="font-medium">Found {parsedPubs.length} publications ({selectedPubs.size} selected)</h4>
<div className="flex gap-2 text-xs">
<button onClick={() => setSelectedPubs(new Set(parsedPubs.map(p => p.id)))} className="text-teal-600 hover:underline">Select all</button>
<span className="text-slate-300">|</span>
<button onClick={() => setSelectedPubs(new Set())} className="text-teal-600 hover:underline">Select none</button>
</div>
</div>
<div className="max-h-64 overflow-y-auto border rounded-lg divide-y">
{parsedPubs.map(pub => (
<label key={pub.id} className="flex items-start gap-3 p-3 hover:bg-slate-50 cursor-pointer">
<input type="checkbox" checked={selectedPubs.has(pub.id)} onChange={() => togglePub(pub.id)} className="mt-1 rounded" />
<div className="flex-1 min-w-0">
<p className="text-xs text-slate-700 line-clamp-2">{pub.text}</p>
<div className="flex gap-2 mt-1">
<span className="text-xs text-slate-400">{pub.year}</span>
{pub.isReview && <span className="text-xs bg-purple-100 text-purple-700 px-1.5 rounded">Review</span>}
</div>
</div>
</label>
))}
</div>
<Button onClick={handleImportPubs} disabled={selectedPubs.size === 0}>Import {selectedPubs.size} Publications</Button>
</div>
)}
</div>
)}
</div>
</div>
</div>
);
};
// Main Application
function BioBibBuilder() {
const [cv, setCV] = useState(emptyCV);
const [activeSection, setActiveSection] = useState('personal');
const [showPreview, setShowPreview] = useState(false);
const [showImport, setShowImport] = useState(false);
const [message, setMessage] = useState(null);
const fileInputRef = useRef(null);
const updateCV = useCallback((path, value) => {
setCV(prev => {
const newCV = JSON.parse(JSON.stringify(prev));
const keys = path.split('.');
let current = newCV;
for (let i = 0; i < keys.length - 1; i++) current = current[keys[i]];
current[keys[keys.length - 1]] = value;
newCV.lastUpdated = new Date().toISOString();
return newCV;
});
}, []);
const isDuplicate = (newPub, existingPubs) => {
for (const existing of existingPubs) {
const newPmid = newPub.pmid;
const existingPmid = typeof existing === 'object' ? existing.pmid : null;
if (newPmid && existingPmid && newPmid === existingPmid) return true;
const newText = newPub.text || newPub;
const existingText = typeof existing === 'object' ? (existing.text || existing) : existing;
if (typeof newText === 'string' && typeof existingText === 'string') {
if (newText.trim().toLowerCase() === existingText.trim().toLowerCase()) return true;
}
}
return false;
};
const handleImport = ({ type, data }) => {
if (type === 'publications') {
let importedCount = 0;
let skippedCount = 0;
setCV(prev => {
const newCV = JSON.parse(JSON.stringify(prev));
const newOriginal = data.original.filter(pub => {
const exists = isDuplicate(pub, newCV.bibliography.primaryWork.originalPeerReviewed);
if (exists) skippedCount++; else importedCount++;
return !exists;
});
const newReviews = data.reviews.filter(pub => {
const exists = isDuplicate(pub, newCV.bibliography.primaryWork.reviewInvited);
if (exists) skippedCount++; else importedCount++;
return !exists;
});
const newBooks = data.books.filter(pub => {
const exists = isDuplicate(pub, newCV.bibliography.primaryWork.booksChapters);
if (exists) skippedCount++; else importedCount++;
return !exists;
});
newCV.bibliography.primaryWork.originalPeerReviewed = [...newCV.bibliography.primaryWork.originalPeerReviewed, ...newOriginal];
newCV.bibliography.primaryWork.reviewInvited = [...newCV.bibliography.primaryWork.reviewInvited, ...newReviews];
newCV.bibliography.primaryWork.booksChapters = [...newCV.bibliography.primaryWork.booksChapters, ...newBooks];
newCV.lastUpdated = new Date().toISOString();
return newCV;
});
let message = '';
if (importedCount > 0 && skippedCount > 0) {
message = `Imported ${importedCount} publication${importedCount !== 1 ? 's' : ''}, skipped ${skippedCount} duplicate${skippedCount !== 1 ? 's' : ''}`;
} else if (importedCount > 0) {
message = `Imported ${importedCount} publication${importedCount !== 1 ? 's' : ''}!`;
} else {
message = `All ${skippedCount} publication${skippedCount !== 1 ? 's were' : ' was'} already present`;
}
setMessage({ type: 'success', text: message });
setActiveSection('bibliography');
}
setTimeout(() => setMessage(null), 4000);
};
const handleFileUpload = async (event) => {
const file = event.target.files[0];
if (file && file.name.endsWith('.json')) {
try {
const text = await file.text();
const parsed = JSON.parse(text);
setCV({ ...emptyCV, ...parsed, lastUpdated: new Date().toISOString() });
setMessage({ type: 'success', text: 'CV loaded!' });
} catch { setMessage({ type: 'error', text: 'Failed to parse file.' }); }
}
setTimeout(() => setMessage(null), 3000);
};
const exportJSON = () => {
const blob = new Blob([JSON.stringify(cv, null, 2)], { type: 'application/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `biobib_${cv.personalInfo.lastName || 'cv'}_${new Date().toISOString().split('T')[0]}.json`;
a.click();
setMessage({ type: 'success', text: 'JSON exported!' });
setTimeout(() => setMessage(null), 3000);
};
const exportDOCX = async () => {
setMessage({ type: 'success', text: 'Generating DOCX...' });
try {
// Load docx library from unpkg (exposes as window.docx)
if (!window.docx) {
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://unpkg.com/docx@8.5.0/build/index.umd.js';
script.onload = () => {
// Give it a moment to initialize
setTimeout(resolve, 100);
};
script.onerror = () => reject(new Error('Failed to load docx library'));
document.head.appendChild(script);
});
}
// Access the library
const docxLib = window.docx;
if (!docxLib) {
throw new Error('docx library not available');
}
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, AlignmentType, HeadingLevel, BorderStyle, WidthType, ShadingType, PageBreak } = docxLib;
const border = { style: BorderStyle.SINGLE, size: 1, color: "999999" };
const borders = { top: border, bottom: border, left: border, right: border };
const noBorders = { top: { style: BorderStyle.NONE }, bottom: { style: BorderStyle.NONE }, left: { style: BorderStyle.NONE }, right: { style: BorderStyle.NONE } };
const sectionHeading = (text) => new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun({ text, bold: true })], spacing: { before: 400, after: 200 } });
const subsectionHeading = (text) => new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun({ text, bold: true })], spacing: { before: 300, after: 150 } });
const subsubsectionHeading = (text) => new Paragraph({ children: [new TextRun({ text, bold: true, size: 22 })], spacing: { before: 200, after: 100 } });
const tabbedEntry = (fields) => new Paragraph({ children: fields.map((f, i) => new TextRun({ text: (f || '') + (i < fields.length - 1 ? '\t' : ''), size: 22 })), indent: { left: 360 }, spacing: { after: 100 }, tabStops: [{ type: 'left', position: 1800 }, { type: 'left', position: 5400 }] });
const normalParagraph = (text) => new Paragraph({ children: [new TextRun({ text: text || '', size: 22 })], indent: { left: 360 }, spacing: { after: 100 } });
const children = [];
children.push(new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text: 'UCSD ACADEMIC BIOGRAPHY/BIBLIOGRAPHY FORM', bold: true, size: 28 })], spacing: { after: 400 } }));
const fullName = `${cv.personalInfo.lastName || ''}, ${cv.personalInfo.firstName || ''}${cv.personalInfo.middleName ? ' ' + cv.personalInfo.middleName : ''}`;
children.push(new Table({ width: { size: 100, type: WidthType.PERCENTAGE }, rows: [
new TableRow({ children: [
new TableCell({ borders: noBorders, children: [new Paragraph({ children: [new TextRun({ text: 'Name:', bold: true, size: 22 })] })] }),
new TableCell({ borders: noBorders, children: [new Paragraph({ children: [new TextRun({ text: fullName, size: 22 })] })] }),
new TableCell({ borders: noBorders, children: [new Paragraph({ children: [new TextRun({ text: 'Title(s):', bold: true, size: 22 })] })] }),
new TableCell({ borders: noBorders, children: [new Paragraph({ children: [new TextRun({ text: cv.personalInfo.titles?.map(t => t.text || t).join('; ') || '', size: 22 })] })] }),
]}),
new TableRow({ children: [
new TableCell({ borders: noBorders, children: [new Paragraph({ children: [new TextRun({ text: 'Department:', bold: true, size: 22 })] })] }),
new TableCell({ borders: noBorders, columnSpan: 3, children: [new Paragraph({ children: [new TextRun({ text: cv.personalInfo.department || '', size: 22 })] })] }),
]})
]}));
children.push(sectionHeading('Section I: Employment History and Education'));
children.push(subsectionHeading('Previous Applicable Employment'));
if (cv.employmentHistory?.length > 0) {
const rows = [new TableRow({ children: ['Period', 'Institution', 'Location', 'Position'].map(t => new TableCell({ borders, shading: { fill: "E8E8E8", type: ShadingType.CLEAR }, children: [new Paragraph({ children: [new TextRun({ text: t, bold: true, size: 20 })] })] })) })];
cv.employmentHistory.forEach(e => rows.push(new TableRow({ children: [`${e.fromDate || ''}-${e.toDate || ''}`, e.institution || '', e.location || '', e.position || ''].map(t => new TableCell({ borders, children: [new Paragraph({ children: [new TextRun({ text: t, size: 20 })] })] })) })));
children.push(new Table({ width: { size: 100, type: WidthType.PERCENTAGE }, rows }));
}
children.push(subsectionHeading('Education'));
if (cv.education?.length > 0) {
const rows = [new TableRow({ children: ['Institution', 'Dates', 'Location', 'Major', 'Degree', 'Year'].map(t => new TableCell({ borders, shading: { fill: "E8E8E8", type: ShadingType.CLEAR }, children: [new Paragraph({ children: [new TextRun({ text: t, bold: true, size: 20 })] })] })) })];
cv.education.forEach(e => rows.push(new TableRow({ children: [e.institution || '', e.dates || '', e.location || '', e.major || '', e.degree || '', e.dateReceived || ''].map(t => new TableCell({ borders, children: [new Paragraph({ children: [new TextRun({ text: t, size: 20 })] })] })) })));
children.push(new Table({ width: { size: 100, type: WidthType.PERCENTAGE }, rows }));
}
if (cv.subspecializations?.length > 0) {
children.push(subsectionHeading('Certifications & Licenses'));
cv.subspecializations.forEach(c => children.push(tabbedEntry([c.date || '', c.text || ''])));
}
children.push(new Paragraph({ children: [new PageBreak()] }));
children.push(sectionHeading('Section II: Professional Data'));
if (cv.professionalData.universityService?.length > 0) { children.push(subsectionHeading('(a) University Service')); cv.professionalData.universityService.forEach(i => children.push(tabbedEntry([i.date || '', i.text || '']))); }
if (cv.professionalData.memberships?.length > 0) { children.push(subsectionHeading('(b) Memberships')); cv.professionalData.memberships.forEach(i => children.push(tabbedEntry([i.date || '', i.text || '']))); }
if (cv.professionalData.honorsAwards?.length > 0) { children.push(subsectionHeading('(c) Honors and Awards')); cv.professionalData.honorsAwards.forEach(i => children.push(tabbedEntry([i.date || '', i.text || '']))); }
const hasGrants = cv.professionalData.currentGrants?.length > 0 || cv.professionalData.previousGrants?.length > 0;
if (hasGrants) {
children.push(subsectionHeading('(d) Contracts and Grants'));
const addGrantTable = (grants, title) => {
if (!grants?.length) return;
children.push(subsubsectionHeading(title));
const rows = [new TableRow({ children: ['Title', 'Agency', 'Grant #', 'Amount', 'Period', 'Role'].map(t => new TableCell({ borders, shading: { fill: "E8E8E8", type: ShadingType.CLEAR }, children: [new Paragraph({ children: [new TextRun({ text: t, bold: true, size: 18 })] })] })) })];
grants.forEach(g => rows.push(new TableRow({ children: [g.title, g.agency, g.grantNumber, g.amount, g.period, g.role].map(t => new TableCell({ borders, children: [new Paragraph({ children: [new TextRun({ text: t || '', size: 18 })] })] })) })));
children.push(new Table({ width: { size: 100, type: WidthType.PERCENTAGE }, rows }));
};
addGrantTable(cv.professionalData.currentGrants, 'Current Grants');
addGrantTable(cv.professionalData.previousGrants, 'Previous Grants');
}
children.push(new Paragraph({ children: [new PageBreak()] }));
children.push(sectionHeading('Section III: Bibliography'));
children.push(subsectionHeading('A. PRIMARY PUBLISHED WORK'));
let n = 1;
const addPubs = (arr, title) => { if (arr?.length > 0) { children.push(subsubsectionHeading(title)); arr.forEach(p => { children.push(normalParagraph(`${n}. ${p.text || p}`)); n++; }); } };
addPubs(cv.bibliography?.primaryWork?.originalPeerReviewed, 'I. Original Peer-Reviewed Work');
addPubs(cv.bibliography?.primaryWork?.reviewInvited, 'II. Review and Invited Articles');
addPubs(cv.bibliography?.primaryWork?.booksChapters, 'III. Books and Book Chapters');
addPubs(cv.bibliography?.primaryWork?.editorials, 'IV. Editorials');
addPubs(cv.bibliography?.primaryWork?.commentary, 'V. Commentary');
addPubs(cv.bibliography?.primaryWork?.caseReports, 'VI. Case Reports');
const doc = new Document({ styles: { default: { document: { run: { font: "Arial", size: 22 } } } }, sections: [{ properties: { page: { size: { width: 12240, height: 15840 }, margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } }, children }] });
const blob = await Packer.toBlob(doc);
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `biobib_${cv.personalInfo.lastName || 'cv'}_${new Date().toISOString().split('T')[0]}.docx`;
a.click();
setMessage({ type: 'success', text: 'DOCX exported!' });
} catch (err) {
console.error('DOCX Export Error:', err);
setMessage({ type: 'error', text: `Export failed: ${err.message || 'Unknown error'}` });
}
setTimeout(() => setMessage(null), 5000);
};
const pubCount = (arr) => arr?.length || 0;
const totalPubs = pubCount(cv.bibliography?.primaryWork?.originalPeerReviewed) + pubCount(cv.bibliography?.primaryWork?.reviewInvited) + pubCount(cv.bibliography?.primaryWork?.booksChapters) + pubCount(cv.bibliography?.primaryWork?.editorials) + pubCount(cv.bibliography?.primaryWork?.commentary) + pubCount(cv.bibliography?.primaryWork?.caseReports);
const renderPersonalInfo = () => (
<div className="space-y-4">
<div className="grid grid-cols-3 gap-3">
<Input label="First Name" value={cv.personalInfo.firstName} onChange={(v) => updateCV('personalInfo.firstName', v)} placeholder="First" />
<Input label="Middle Name" value={cv.personalInfo.middleName} onChange={(v) => updateCV('personalInfo.middleName', v)} placeholder="Middle" />
<Input label="Last Name" value={cv.personalInfo.lastName} onChange={(v) => updateCV('personalInfo.lastName', v)} placeholder="Last" />
</div>
<Input label="Department" value={cv.personalInfo.department} onChange={(v) => updateCV('personalInfo.department', v)} placeholder="e.g., Department of Medicine" />
<div><label className="block text-xs font-medium text-slate-600 mb-1">Title(s)</label><SimpleListEditor items={cv.personalInfo.titles} setItems={(v) => updateCV('personalInfo.titles', v)} placeholder="e.g., Professor" /></div>
</div>
);
const renderEmployment = () => (
<ListItemEditor items={cv.employmentHistory} setItems={(v) => updateCV('employmentHistory', v)} fields={[{ id: 'fromDate', label: 'From', placeholder: 'Start' }, { id: 'toDate', label: 'To', placeholder: 'End' }, { id: 'institution', label: 'Institution', placeholder: 'Name', fullWidth: true }, { id: 'location', label: 'Location', placeholder: 'City' }, { id: 'position', label: 'Position', placeholder: 'Title' }]} itemName="Position" />
);
const renderEducation = () => (
<div className="space-y-4">
<ListItemEditor items={cv.education} setItems={(v) => updateCV('education', v)} fields={[{ id: 'institution', label: 'Institution', placeholder: 'School' }, { id: 'dates', label: 'Dates', placeholder: '2010-2014' }, { id: 'location', label: 'Location', placeholder: 'City' }, { id: 'major', label: 'Major', placeholder: 'Field' }, { id: 'degree', label: 'Degree', placeholder: 'MD' }, { id: 'dateReceived', label: 'Received', placeholder: '2014' }]} itemName="Education" />
<div className="pt-3 border-t"><label className="block text-xs font-medium text-slate-600 mb-2">Certifications</label><ListItemEditor items={cv.subspecializations} setItems={(v) => updateCV('subspecializations', v)} fields={[{ id: 'text', label: 'Certification', placeholder: 'Board Certified...', fullWidth: true }, { id: 'date', label: 'Date', placeholder: '2018' }]} itemName="Certification" /></div>
</div>
);
const renderProfessional = () => (
<div className="space-y-3">
{professionalSubsections.map(sub => (
<CollapsibleSection key={sub.id} title={sub.title} iconName="Globe" badge={sub.type === 'simple' ? (cv.professionalData[sub.id]?.length || null) : null}>
{sub.description && <p className="text-xs text-slate-500 mb-3">{sub.description}</p>}
{sub.type === 'simple' && <ListItemEditor items={cv.professionalData[sub.id] || []} setItems={(v) => updateCV(`professionalData.${sub.id}`, v)} fields={[{ id: 'text', label: 'Description', placeholder: `Add...`, fullWidth: true }, { id: 'date', label: 'Date(s)', placeholder: '2020-Present' }]} itemName="Entry" />}
{sub.type === 'grants' && (
<div className="space-y-4">
<div className="bg-green-50 border border-green-200 rounded-lg p-4">
<h4 className="font-medium text-green-800 text-sm mb-3">Current Grants</h4>
<ListItemEditor items={cv.professionalData.currentGrants || []} setItems={(v) => updateCV('professionalData.currentGrants', v)} fields={[{ id: 'title', label: 'Title', placeholder: 'Grant title', fullWidth: true }, { id: 'agency', label: 'Agency', placeholder: 'NIH' }, { id: 'grantNumber', label: 'Grant #', placeholder: 'R01...' }, { id: 'amount', label: 'Amount', placeholder: '$500k' }, { id: 'period', label: 'Period', placeholder: '2023-2028' }, { id: 'role', label: 'Role', placeholder: 'PI', fullWidth: true }]} itemName="Grant" />
</div>
<div className="bg-slate-50 border border-slate-200 rounded-lg p-4">
<h4 className="font-medium text-slate-700 text-sm mb-3">Previous Grants</h4>
<ListItemEditor items={cv.professionalData.previousGrants || []} setItems={(v) => updateCV('professionalData.previousGrants', v)} fields={[{ id: 'title', label: 'Title', placeholder: 'Grant title', fullWidth: true }, { id: 'agency', label: 'Agency', placeholder: 'NIH' }, { id: 'grantNumber', label: 'Grant #', placeholder: 'R01...' }, { id: 'amount', label: 'Amount', placeholder: '$500k' }, { id: 'period', label: 'Period', placeholder: '2018-2022' }, { id: 'role', label: 'Role', placeholder: 'PI', fullWidth: true }]} itemName="Grant" />
</div>
</div>
)}
{sub.type === 'nested' && sub.subsections?.map(nested => (
<div key={nested.id} className="border-l-2 border-teal-200 pl-4 mb-3">
<h4 className="font-medium text-slate-700 text-sm mb-2">{nested.title}</h4>
<ListItemEditor items={cv.professionalData[sub.id]?.[nested.id] || []} setItems={(v) => updateCV(`professionalData.${sub.id}.${nested.id}`, v)} fields={[{ id: 'text', label: 'Description', placeholder: `Add...`, fullWidth: true }, { id: 'date', label: 'Date(s)', placeholder: '2020-Present' }]} itemName="Entry" />
</div>
))}
{sub.type === 'studentInstructional' && (
<div className="space-y-4">
<div className="border-l-2 border-teal-200 pl-4">
<h4 className="font-medium text-slate-700 text-sm mb-2">Teaching of Students in Courses</h4>
<ListItemEditor items={cv.professionalData.studentInstructional?.teachingCourses || []} setItems={(v) => updateCV('professionalData.studentInstructional.teachingCourses', v)} fields={[{ id: 'course', label: 'Course', placeholder: 'Course name', fullWidth: true }, { id: 'dates', label: 'Dates', placeholder: '2020-Present' }, { id: 'teachingLoad', label: 'Load', placeholder: '4 lectures/yr' }]} itemName="Course" />
</div>
<div className="border-l-2 border-teal-200 pl-4">
<h4 className="font-medium text-slate-700 text-sm mb-2">Formal Teaching of Residents/Fellows</h4>
<ListItemEditor items={cv.professionalData.studentInstructional?.formalTeaching || []} setItems={(v) => updateCV('professionalData.studentInstructional.formalTeaching', v)} fields={[{ id: 'course', label: 'Course', placeholder: 'Program', fullWidth: true }, { id: 'dates', label: 'Dates', placeholder: '2020-Present' }, { id: 'teachingLoad', label: 'Load', placeholder: 'Weekly' }]} itemName="Teaching" />
</div>
<div className="border-l-2 border-teal-200 pl-4">
<h4 className="font-medium text-slate-700 text-sm mb-2">Supervisory Responsibilities</h4>
<ListItemEditor items={cv.professionalData.studentInstructional?.supervisory || []} setItems={(v) => updateCV('professionalData.studentInstructional.supervisory', v)} fields={[{ id: 'role', label: 'Role', placeholder: 'Program Director', fullWidth: true }, { id: 'dates', label: 'Dates', placeholder: '2020-Present' }, { id: 'timeCommitment', label: 'Time', placeholder: '20%' }]} itemName="Role" />
</div>
<div className="border-l-2 border-teal-200 pl-4">
<h4 className="font-medium text-slate-700 text-sm mb-2">Mentorship of Trainees</h4>
<ListItemEditor items={cv.professionalData.studentInstructional?.mentorship || []} setItems={(v) => updateCV('professionalData.studentInstructional.mentorship', v)} fields={[{ id: 'student', label: 'Student', placeholder: 'Name' }, { id: 'mentorRole', label: 'Role', placeholder: 'Research Advisor' }, { id: 'interaction', label: 'Type', placeholder: 'Research' }, { id: 'menteeType', label: 'Level', placeholder: 'Fellow' }, { id: 'years', label: 'Years', placeholder: '2021-23' }, { id: 'institution', label: 'Inst.', placeholder: 'UCSD' }]} itemName="Mentee" />
</div>
</div>
)}
</CollapsibleSection>
))}
</div>
);
const renderBibliography = () => (
<div className="space-y-4">
<div className="bg-blue-50 border border-blue-200 rounded-xl p-4 flex items-center justify-between">
<div><h4 className="font-medium text-blue-800 text-sm">Import from PubMed</h4><p className="text-xs text-blue-600">Add publications using MEDLINE export</p></div>
<Button variant="pubmed" size="sm" onClick={() => setShowImport(true)}><Icons.Database /> Import</Button>
</div>
<div className="bg-white rounded-xl border p-4">
<h3 className="font-semibold text-slate-800 mb-3">A. Primary Published Work</h3>
{bibliographySubsections.primaryWork.map(sub => (
<CollapsibleSection key={sub.id} title={sub.title} iconName="BookOpen" badge={cv.bibliography?.primaryWork?.[sub.id]?.length || null}>
<SimpleListEditor items={cv.bibliography?.primaryWork?.[sub.id] || []} setItems={(v) => updateCV(`bibliography.primaryWork.${sub.id}`, v)} placeholder="Full citation..." />
</CollapsibleSection>
))}
</div>
<div className="bg-white rounded-xl border p-4">
<h3 className="font-semibold text-slate-800 mb-3">B. Other Work</h3>
{bibliographySubsections.otherWork.map(sub => (
<CollapsibleSection key={sub.id} title={sub.title} iconName="FileText" badge={cv.bibliography?.otherWork?.[sub.id]?.length || null}>
<SimpleListEditor items={cv.bibliography?.otherWork?.[sub.id] || []} setItems={(v) => updateCV(`bibliography.otherWork.${sub.id}`, v)} placeholder="Citation..." />
</CollapsibleSection>
))}
</div>
<div className="bg-white rounded-xl border p-4">
<h3 className="font-semibold text-slate-800 mb-3">C. Work in Progress</h3>
<SimpleListEditor items={cv.bibliography?.workInProgress || []} setItems={(v) => updateCV('bibliography.workInProgress', v)} placeholder="Work in progress..." />
</div>
<Input label="Publications Link" value={cv.publicationsLink} onChange={(v) => updateCV('publicationsLink', v)} placeholder="Google Scholar URL" />
</div>
);
const renderContent = () => {
switch (activeSection) {
case 'personal': return renderPersonalInfo();
case 'employment': return renderEmployment();
case 'education': return renderEducation();
case 'professional': return renderProfessional();
case 'bibliography': return renderBibliography();
default: return null;
}
};
const Icon = Icons[sections.find(s => s.id === activeSection)?.icon] || Icons.FileText;
return (
<div className="min-h-screen bg-gradient-to-br from-slate-50 to-teal-50/30 p-4">
<header className="bg-white rounded-xl shadow-sm border p-4 mb-4">
<div className="flex items-center justify-between flex-wrap gap-3">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-teal-600 flex items-center justify-center text-white"><Icons.FileText /></div>
<div><h1 className="font-bold text-slate-800">Academic CV Builder</h1><p className="text-xs text-slate-500">Follows UCSD Bio-Bib Format</p></div>
</div>
<div className="flex items-center gap-2 flex-wrap">
<input ref={fileInputRef} type="file" accept=".json" onChange={handleFileUpload} className="hidden" />
<Button variant="secondary" size="sm" onClick={() => setShowImport(true)}><Icons.Upload /> Import</Button>
<Button variant="secondary" size="sm" onClick={() => fileInputRef.current?.click()}><Icons.File /> Load</Button>
<Button variant="secondary" size="sm" onClick={exportJSON}><Icons.Download /> JSON</Button>
<Button size="sm" onClick={exportDOCX}><Icons.FileText /> DOCX</Button>
</div>
</div>
</header>
{message && <div className={`mb-4 px-4 py-2 rounded-lg flex items-center gap-2 text-sm ${message.type === 'error' ? 'bg-red-50 text-red-700 border border-red-200' : 'bg-teal-50 text-teal-700 border border-teal-200'}`}>{message.type === 'error' ? <Icons.AlertCircle /> : <Icons.Check />} {message.text}</div>}
<div className="grid grid-cols-12 gap-4">
<nav className="col-span-3">
<div className="bg-white rounded-xl shadow-sm border p-3">
<div className="space-y-1">
{sections.map(section => {
const SectionIcon = Icons[section.icon];
return (
<button key={section.id} onClick={() => setActiveSection(section.id)} className={`w-full flex items-center gap-2 px-3 py-2 rounded-lg transition-all text-sm ${activeSection === section.id ? 'bg-teal-600 text-white' : 'text-slate-600 hover:bg-slate-100'}`}>
<SectionIcon /><span className="font-medium">{section.title}</span>
</button>
);
})}
</div>
<div className="mt-4 pt-4 border-t text-xs">
<h4 className="font-semibold text-slate-400 uppercase mb-2">Stats</h4>
<div className="space-y-1 text-slate-600">
<div className="flex justify-between"><span>Publications</span><span className="font-semibold">{totalPubs}</span></div>
<div className="flex justify-between"><span>Grants</span><span className="font-semibold">{(cv.professionalData.currentGrants?.length || 0) + (cv.professionalData.previousGrants?.length || 0)}</span></div>
<div className="flex justify-between"><span>Positions</span><span className="font-semibold">{cv.employmentHistory?.length || 0}</span></div>
</div>
</div>
</div>
</nav>
<div className="col-span-9">
<div className="bg-white rounded-xl shadow-sm border p-6">
<div className="flex items-center gap-3 mb-6 pb-4 border-b">
<div className="w-12 h-12 rounded-xl bg-teal-50 flex items-center justify-center text-teal-600"><Icon /></div>
<div><h2 className="text-lg font-bold text-slate-800">{sections.find(s => s.id === activeSection)?.title}</h2><p className="text-xs text-slate-500">Section {sections.findIndex(s => s.id === activeSection) + 1} of {sections.length}</p></div>
</div>
{renderContent()}
<div className="flex justify-between mt-6 pt-4 border-t">
<Button variant="ghost" size="sm" onClick={() => { const idx = sections.findIndex(s => s.id === activeSection); if (idx > 0) setActiveSection(sections[idx - 1].id); }} disabled={sections.findIndex(s => s.id === activeSection) === 0}>← Previous</Button>
<Button size="sm" onClick={() => { const idx = sections.findIndex(s => s.id === activeSection); if (idx < sections.length - 1) setActiveSection(sections[idx + 1].id); }} disabled={sections.findIndex(s => s.id === activeSection) === sections.length - 1}>Next →</Button>
</div>
</div>
</div>
</div>
<ImportModal isOpen={showImport} onClose={() => setShowImport(false)} onImport={handleImport} />
</div>
);
}
ReactDOM.render(<BioBibBuilder />, document.getElementById('root'));
</script>
</body>
</html>