🔧 more options for PDF export
This commit is contained in:
@@ -35,6 +35,15 @@
|
||||
grid-column: 2;
|
||||
}
|
||||
|
||||
.export-format-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.export-format-field {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.export-page-range {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -6,18 +6,23 @@ export interface ExportOptions {
|
||||
showChapterTitle: boolean
|
||||
includeCover: boolean
|
||||
includeFrontMatter: boolean
|
||||
includePartSeparators: boolean
|
||||
pageFrom: number | null
|
||||
pageTo: number | null
|
||||
font: 'courier' | 'times' | 'georgia'
|
||||
pageSize: 'letter' | 'a4'
|
||||
titleOnFirstPage: boolean
|
||||
boldHeadings: boolean
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'exportDialogPrefs'
|
||||
|
||||
function loadPrefs(): Pick<ExportOptions, 'romanNumerals' | 'showChapterTitle' | 'includeCover' | 'includeFrontMatter'> {
|
||||
function loadPrefs(): Pick<ExportOptions, 'romanNumerals' | 'showChapterTitle' | 'includeCover' | 'includeFrontMatter' | 'includePartSeparators' | 'font' | 'pageSize' | 'titleOnFirstPage' | 'boldHeadings'> {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (raw) return JSON.parse(raw)
|
||||
if (raw) return { font: 'courier', pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false, includePartSeparators: true, ...JSON.parse(raw) }
|
||||
} catch { /* ignore */ }
|
||||
return { romanNumerals: true, showChapterTitle: false, includeCover: true, includeFrontMatter: true }
|
||||
return { romanNumerals: true, showChapterTitle: false, includeCover: true, includeFrontMatter: true, includePartSeparators: true, font: 'courier', pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false }
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -31,6 +36,11 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
const [showChapterTitle, setShowChapterTitle] = useState(prefs.showChapterTitle)
|
||||
const [includeCover, setIncludeCover] = useState(prefs.includeCover)
|
||||
const [includeFrontMatter, setIncludeFrontMatter] = useState(prefs.includeFrontMatter)
|
||||
const [includePartSeparators, setIncludePartSeparators] = useState(prefs.includePartSeparators)
|
||||
const [font, setFont] = useState(prefs.font)
|
||||
const [pageSize, setPageSize] = useState(prefs.pageSize)
|
||||
const [titleOnFirstPage, setTitleOnFirstPage] = useState(prefs.titleOnFirstPage)
|
||||
const [boldHeadings, setBoldHeadings] = useState(prefs.boldHeadings)
|
||||
const [pageFrom, setPageFrom] = useState('')
|
||||
const [pageTo, setPageTo] = useState('')
|
||||
const overlayRef = useRef<HTMLDivElement>(null)
|
||||
@@ -48,14 +58,14 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
}
|
||||
|
||||
const savePrefs = (patch: Partial<typeof prefs>): void => {
|
||||
const next = { romanNumerals, showChapterTitle, includeCover, includeFrontMatter, ...patch }
|
||||
const next = { romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, font, pageSize, titleOnFirstPage, boldHeadings, ...patch }
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(next))
|
||||
}
|
||||
|
||||
const handleExport = (): void => {
|
||||
const from = pageFrom.trim() ? parseInt(pageFrom, 10) : null
|
||||
const to = pageTo.trim() ? parseInt(pageTo, 10) : null
|
||||
onExport({ romanNumerals, showChapterTitle, includeCover, includeFrontMatter, pageFrom: from, pageTo: to })
|
||||
onExport({ romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, pageFrom: from, pageTo: to, font, pageSize, titleOnFirstPage, boldHeadings })
|
||||
}
|
||||
|
||||
const pageRangeValid = (): boolean => {
|
||||
@@ -116,6 +126,64 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
<span className="export-toggle-label">Include front & back matter</span>
|
||||
<span className="export-toggle-hint">Prologue, Content Warning, Epilogue</span>
|
||||
</label>
|
||||
|
||||
<label className="export-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={includePartSeparators}
|
||||
onChange={e => { setIncludePartSeparators(e.target.checked); savePrefs({ includePartSeparators: e.target.checked }) }}
|
||||
/>
|
||||
<span className="export-toggle-label">Include part labels</span>
|
||||
<span className="export-toggle-hint">Part name above the first chapter of each part</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="export-format-row">
|
||||
<div className="settings-field export-format-field">
|
||||
<span className="settings-label">Font</span>
|
||||
<select
|
||||
className="settings-input"
|
||||
value={font}
|
||||
onChange={e => { const v = e.target.value as ExportOptions['font']; setFont(v); savePrefs({ font: v }) }}
|
||||
>
|
||||
<option value="courier">Courier New</option>
|
||||
<option value="times">Times New Roman</option>
|
||||
<option value="georgia">Georgia</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-field export-format-field">
|
||||
<span className="settings-label">Page size</span>
|
||||
<select
|
||||
className="settings-input"
|
||||
value={pageSize}
|
||||
onChange={e => { const v = e.target.value as ExportOptions['pageSize']; setPageSize(v); savePrefs({ pageSize: v }) }}
|
||||
>
|
||||
<option value="letter">Letter</option>
|
||||
<option value="a4">A4</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="export-toggles">
|
||||
<label className="export-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={titleOnFirstPage}
|
||||
onChange={e => { setTitleOnFirstPage(e.target.checked); savePrefs({ titleOnFirstPage: e.target.checked }) }}
|
||||
/>
|
||||
<span className="export-toggle-label">Title on first page</span>
|
||||
<span className="export-toggle-hint">Manuscript title bold and centered above chapter one</span>
|
||||
</label>
|
||||
|
||||
<label className="export-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={boldHeadings}
|
||||
onChange={e => { setBoldHeadings(e.target.checked); savePrefs({ boldHeadings: e.target.checked }) }}
|
||||
/>
|
||||
<span className="export-toggle-label">Bold chapter headings</span>
|
||||
<span className="export-toggle-hint">Chapter numbers and titles in bold</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="settings-field">
|
||||
|
||||
Reference in New Issue
Block a user