Family History Narrative Outline Builder
Narrative Metadata
The central idea or theme that unites the story (e.g., resilience, immigration, love).
Define Major Chapters (Chronological or Thematic)
Chapter List (Drag to Reorder)
Detail Scenes, Quotes, and Key Facts
Scene Details List
Review your complete narrative outline and export options.
Click "Next" or "Previous" to refresh this preview.
Please define chapters in Tab 2 first.
'; return; } let sceneIndex = 1; narrativeData.chapters.forEach(chap => { const header = document.createElement('h4'); header.style.cssText = 'color: #8b5cf6; margin-top: 15px; margin-bottom: 5px; border-bottom: 1px solid #ddd; padding-bottom: 5px;'; header.textContent = `Chapter ${narrativeData.chapters.indexOf(chap) + 1}: ${chap.name}`; sceneInputs.list.appendChild(header); if (chap.scenes.length === 0) { const p = document.createElement('p'); p.style.cssText = 'color: #6c757d; font-size: 0.9em; margin-left: 10px;'; p.textContent = 'No scenes detailed for this chapter.'; sceneInputs.list.appendChild(p); return; } chap.scenes.forEach(scene => { const div = document.createElement('div'); div.className = 'fhn-list-item'; div.style.borderLeftColor = '#38bdf8'; // Secondary color for scenes div.dataset.id = scene.id; div.innerHTML = `Scene ${sceneIndex++}: ${escapeHTML(scene.text.substring(0, 80))}... (Source: ${escapeHTML(scene.source)})
`; sceneInputs.list.appendChild(div); }); }); }; const addScene = () => { const chapId = parseInt(sceneInputs.chapterSelect.value, 10); const source = sceneInputs.source.value.trim(); const text = sceneInputs.newScene.value.trim(); if (isNaN(chapId)) return alert('Please select a chapter.'); if (!text) return alert('Scene description/quote is required.'); const chapter = narrativeData.chapters.find(c => c.id === chapId); if (!chapter) return alert('Selected chapter not found.'); chapter.scenes.push({ id: chapter.id * 1000 + chapter.scenes.length + 1, // Unique ID text: text, source: source || 'Uncited' }); sceneInputs.newScene.value = ''; sceneInputs.source.value = ''; renderScenes(); }; const removeScene = (id) => { narrativeData.chapters.forEach(chap => { chap.scenes = chap.scenes.filter(s => s.id !== id); }); renderScenes(); }; // --- Tab 4 Logic: Export --- const getPlanData = () => { // Update metadata from Tab 1 narrativeData.title = inputs.title.value; narrativeData.subject = inputs.subject.value; narrativeData.timePeriod = inputs.timePeriod.value; narrativeData.thesis = inputs.thesis.value; return narrativeData; }; const generatePreview = () => { const data = getPlanData(); let outlineHTML = ''; data.chapters.forEach((chap, chapIndex) => { outlineHTML += `Chapter ${chapIndex + 1}: ${escapeHTML(chap.name)}
`; if (chap.scenes.length === 0) { outlineHTML += `(No scenes or key details defined for this chapter.)
`; return; } outlineHTML += '- ';
chap.scenes.forEach(scene => {
outlineHTML += `
- ${escapeHTML(scene.text.split('\n')[0].substring(0, 100))}...
Source: ${escapeHTML(scene.source)}
`; }); outlineHTML += '${escapeHTML(data.title)}
Subject: ${escapeHTML(data.subject)} | Period: ${escapeHTML(data.timePeriod)}
I. Narrative Thesis/Theme
${escapeHTML(data.thesis)}
II. Chapter Outline
${outlineHTML || 'Please define chapters in Tab 2.
'} `; }; const downloadTxt = () => { const data = getPlanData(); let content = `FAMILY HISTORY NARRATIVE OUTLINE\n`; content += "========================================\n"; content += `Title: ${data.title}\n`; content += `Subject: ${data.subject}\n`; content += `Period: ${data.timePeriod}\n`; content += "========================================\n\n"; content += "I. NARRATIVE THESIS/THEME\n"; content += `${data.thesis}\n\n`; content += "II. CHAPTER OUTLINE\n"; data.chapters.forEach((chap, chapIndex) => { content += `\nCHAPTER ${chapIndex + 1}: ${chap.name.toUpperCase()}\n`; content += "----------------------------------------\n"; if (chap.scenes.length === 0) { content += " (No scenes defined)\n"; return; } chap.scenes.forEach((scene, sceneIndex) => { content += ` ${sceneIndex + 1}. SCENE: ${scene.text.split('\n')[0]}\n`; content += ` Source: ${scene.source}\n`; }); }); const blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = `${data.title.replace(/ /g, '_')}_outline.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(a.href); }; const downloadPDF = () => { if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { alert('Error: jsPDF library not loaded.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF('p', 'mm', 'a4'); const data = getPlanData(); const margin = 20; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - margin * 2; let yPos = 20; const addWrappedText = (text, size, style, color = [52, 73, 94], lineSpacing = 6, indent = 0) => { doc.setFontSize(size); doc.setFont(undefined, style); doc.setTextColor(color[0], color[1], color[2]); const splitText = doc.splitTextToSize(text, usableWidth - indent); if (yPos + (splitText.length * lineSpacing) > 280) { doc.addPage(); yPos = 20; } doc.text(splitText, margin + indent, yPos); yPos += (splitText.length * lineSpacing); return splitText.length; }; // 1. Title & Metadata addWrappedText(data.title.toUpperCase(), 18, 'bold', [44, 62, 80], 8, 0); yPos -= 5; addWrappedText(`Subject: ${data.subject} | Period: ${data.timePeriod}`, 10, 'normal', [108, 117, 125], 5, 0); yPos += 10; // 2. Thesis addWrappedText("I. NARRATIVE THESIS/THEME", 14, 'bold', [139, 92, 246]); yPos += 2; addWrappedText(data.thesis, 11, 'normal'); yPos += 5; // 3. Chapters and Scenes addWrappedText("II. CHAPTER OUTLINE", 14, 'bold', [139, 92, 246]); yPos += 2; data.chapters.forEach((chap, chapIndex) => { // Chapter Header yPos += 3; addWrappedText(`CHAPTER ${chapIndex + 1}: ${chap.name.toUpperCase()}`, 12, 'bold', [44, 62, 80]); yPos -= 1; if (chap.scenes.length === 0) { addWrappedText("(No scenes or key details defined for this chapter.)", 10, 'italic', [108, 117, 125], 5, 5); return; } chap.scenes.forEach((scene, sceneIndex) => { yPos += 1; const sceneText = `${sceneIndex + 1}. ${scene.text.split('\n')[0]}...`; // Scene Text (Bold) addWrappedText(sceneText, 10, 'bold', [52, 73, 94], 5, 5); yPos -= 2; // Source (Italic) addWrappedText(`Source: ${scene.source}`, 9, 'italic', [108, 117, 125], 4, 15); yPos -= 1; }); yPos += 3; // Space between chapters }); doc.save(`${data.title.replace(/ /g, '_')}_narrative_outline.pdf`); }; // --- Event Listeners --- // Tab 2 Listeners chapterInputs.addBtn.addEventListener('click', addChapter); chapterInputs.list.addEventListener('click', (e) => { if (e.target.dataset.removeId) { removeChapter(parseInt(e.target.dataset.removeId)); } }); // Tab 3 Listeners sceneInputs.addBtn.addEventListener('click', addScene); sceneInputs.list.addEventListener('click', (e) => { if (e.target.dataset.removeSceneId) { removeScene(parseInt(e.target.dataset.removeSceneId)); } }); // Tab 4 Listeners refreshBtn.addEventListener('click', generatePreview); downloadPdfBtn.addEventListener('click', downloadPDF); downloadTxtBtn.addEventListener('click', downloadTxt); // Global Navigation nextBtn.addEventListener('click', () => showTab(currentTab + 1)); prevBtn.addEventListener('click', () => showTab(currentTab - 1)); // --- Initialization --- showTab(1); // Set initial state });