- One outline for the whole study plus one per chunk (picker at the top); chunk outlines can start from the chunk's verses, each carrying its words - Points can have a type (illustration, application, quote, question, transition), minutes (with a running total), a longer note, verse text fetched from a passage, and cross-references / word studies attached from the chunk - Share (system share sheet, or copy), Print / PDF, Copy as text, Word and Markdown downloads for any one outline - All of it included in the Markdown, HTML/PDF and Word study exports, with each chunk's outline under that chunk Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
// Taking one outline out of the app: print or save as PDF, share it, or download it.
|
|
import { buildOutlineHtml } from './bibleUtils.jsx';
|
|
import { outlineToText } from './outline.js';
|
|
|
|
const slug = (s) => String(s).replace(/[^\w]+/g, '-').replace(/^-|-$/g, '') || 'outline';
|
|
|
|
function downloadBlob(blob, filename) {
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = filename;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.remove();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
// What gets shared as text: a heading, then the outline.
|
|
export const outlineShareText = ({ title, subtitle = '', tree }) => `${title}${subtitle ? `\n${subtitle}` : ''}\n\n${outlineToText(tree)}`;
|
|
|
|
// Opens a print-ready page of just this outline. Returns false when the browser blocked the window.
|
|
export function printOutline({ title, subtitle, tree }) {
|
|
const win = window.open('', '_blank');
|
|
if (!win) return false;
|
|
win.document.write(buildOutlineHtml({ title, subtitle, tree }));
|
|
win.document.close();
|
|
win.onload = () => { win.focus(); win.print(); };
|
|
return true;
|
|
}
|
|
|
|
// Uses the phone/tablet/computer share sheet when there is one (Messages, Mail, AirDrop…), otherwise
|
|
// copies the text. -> 'shared' | 'copied' | 'cancelled' | 'failed'
|
|
export async function shareOutline(outline) {
|
|
const text = outlineShareText(outline);
|
|
if (navigator.share) {
|
|
try {
|
|
await navigator.share({ title: `${outline.title} — Outline`, text });
|
|
return 'shared';
|
|
} catch (err) {
|
|
if (err?.name === 'AbortError') return 'cancelled';
|
|
// fall through to copying
|
|
}
|
|
}
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
return 'copied';
|
|
} catch {
|
|
return 'failed';
|
|
}
|
|
}
|
|
|
|
export function downloadOutlineMarkdown({ title, subtitle, tree }) {
|
|
const text = `# ${title}\n\n${subtitle ? `*${subtitle}*\n\n` : ''}${tree.length ? outlineToText(tree) : ''}\n`;
|
|
downloadBlob(new Blob([text], { type: 'text/markdown;charset=utf-8' }), `${slug(title)}-outline.md`);
|
|
}
|
|
|
|
export async function downloadOutlineDocx(outline) {
|
|
const { buildOutlineDocxBlob } = await import('./docxExport.js'); // the Word library only loads when used
|
|
downloadBlob(await buildOutlineDocxBlob(outline), `${slug(outline.title)}-outline.docx`);
|
|
}
|