Improves export config modal and template vars
Refactors the export configuration modal to provide a better user experience and more accurate default values. - Removes the batch export feature from the right-click menu. - Updates the template variables to derive from the settings tab. - Modifies the reset function in the export config modal to reset to plugin defaults. - Improves font handling and font size settings in the TypographySection of the export config modal, including slider for font size. - Enhances default template variable initialization in the ModalState.
This commit is contained in:
5 files changed
+120
-106
No files matched your search
@@ -288,17 +288,6 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
menu.addSeparator();
|
|
||||||
|
|
||||||
menu.addItem((item) =>
|
|
||||||
item
|
|
||||||
.setTitle('Batch export...')
|
|
||||||
.setIcon('folder-output')
|
|
||||||
.onClick(() => {
|
|
||||||
this.batchExportNotes();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
menu.showAtMouseEvent(event);
|
menu.showAtMouseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,21 +328,21 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
openAfterExport: this.settings.behavior.openAfterExport,
|
openAfterExport: this.settings.behavior.openAfterExport,
|
||||||
preserveFolderStructure: this.settings.behavior.preserveFolderStructure,
|
preserveFolderStructure: this.settings.behavior.preserveFolderStructure,
|
||||||
availableTemplates: availableTemplates,
|
availableTemplates: availableTemplates,
|
||||||
// Template variables from plugin defaults
|
// Template variables from settings tab values
|
||||||
templateVariables: {
|
templateVariables: {
|
||||||
pageSize: this.settings.exportDefaults.pageSize,
|
pageSize: this.settings.pageSetup.size,
|
||||||
orientation: this.settings.exportDefaults.orientation,
|
orientation: this.settings.pageSetup.orientation,
|
||||||
flipped: this.settings.exportDefaults.orientation === 'landscape',
|
flipped: this.settings.pageSetup.orientation === 'landscape',
|
||||||
marginTop: this.settings.exportDefaults.marginTop,
|
marginTop: this.settings.pageSetup.margins.top.toString(),
|
||||||
marginBottom: this.settings.exportDefaults.marginBottom,
|
marginBottom: this.settings.pageSetup.margins.bottom.toString(),
|
||||||
marginLeft: this.settings.exportDefaults.marginLeft,
|
marginLeft: this.settings.pageSetup.margins.left.toString(),
|
||||||
marginRight: this.settings.exportDefaults.marginRight,
|
marginRight: this.settings.pageSetup.margins.right.toString(),
|
||||||
bodyFont: this.settings.exportDefaults.bodyFont,
|
bodyFont: this.settings.typography.fonts.body,
|
||||||
headingFont: this.settings.exportDefaults.headingFont,
|
headingFont: this.settings.typography.fonts.heading,
|
||||||
monospaceFont: this.settings.exportDefaults.monospaceFont,
|
monospaceFont: this.settings.typography.fonts.monospace,
|
||||||
bodyFontSize: this.settings.exportDefaults.bodyFontSize,
|
bodyFontSize: this.settings.typography.fontSizes.body,
|
||||||
// Auto-adjust width for single-page landscape mode
|
// Auto-adjust width for single-page landscape mode
|
||||||
...(this.settings.exportDefaults.orientation === 'landscape' && this.settings.exportDefaults.format === 'single-page'
|
...(this.settings.pageSetup.orientation === 'landscape' && this.settings.exportDefaults.format === 'single-page'
|
||||||
? { width: 'auto' }
|
? { width: 'auto' }
|
||||||
: {})
|
: {})
|
||||||
}
|
}
|
||||||
@@ -552,15 +541,6 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Batch export multiple notes
|
|
||||||
*/
|
|
||||||
private async batchExportNotes(): Promise<void> {
|
|
||||||
// This would show a modal to select multiple files
|
|
||||||
// Implementation deferred for now
|
|
||||||
new Notice('Batch export feature coming soon');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export an entire folder to PDF
|
* Export an entire folder to PDF
|
||||||
|
|||||||
@@ -192,8 +192,27 @@ export class ExportConfigModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleReset(): void {
|
private handleReset(): void {
|
||||||
// Reset state to defaults
|
// Create plugin defaults object from settings tab values
|
||||||
this.state.reset();
|
const pluginDefaults = {
|
||||||
|
template: this.plugin.settings.exportDefaults.template,
|
||||||
|
format: this.plugin.settings.exportDefaults.format,
|
||||||
|
outputFolder: this.plugin.settings.outputFolder,
|
||||||
|
openAfterExport: this.plugin.settings.behavior.openAfterExport,
|
||||||
|
preserveFolderStructure: this.plugin.settings.behavior.preserveFolderStructure,
|
||||||
|
pageSize: this.plugin.settings.pageSetup.size,
|
||||||
|
orientation: this.plugin.settings.pageSetup.orientation,
|
||||||
|
marginTop: this.plugin.settings.pageSetup.margins.top.toString(),
|
||||||
|
marginBottom: this.plugin.settings.pageSetup.margins.bottom.toString(),
|
||||||
|
marginLeft: this.plugin.settings.pageSetup.margins.left.toString(),
|
||||||
|
marginRight: this.plugin.settings.pageSetup.margins.right.toString(),
|
||||||
|
bodyFont: this.plugin.settings.typography.fonts.body,
|
||||||
|
headingFont: this.plugin.settings.typography.fonts.heading,
|
||||||
|
monospaceFont: this.plugin.settings.typography.fonts.monospace,
|
||||||
|
bodyFontSize: this.plugin.settings.typography.fontSizes.body
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reset state to plugin defaults
|
||||||
|
this.state.reset(pluginDefaults);
|
||||||
|
|
||||||
// Re-render sections to update UI
|
// Re-render sections to update UI
|
||||||
this.renderSections();
|
this.renderSections();
|
||||||
|
|||||||
@@ -15,81 +15,90 @@ export class TypographySection implements ModalSection {
|
|||||||
this.container = containerEl.createDiv('export-section');
|
this.container = containerEl.createDiv('export-section');
|
||||||
this.container.createEl('h3', { text: 'Typography' });
|
this.container.createEl('h3', { text: 'Typography' });
|
||||||
|
|
||||||
|
// Create font settings asynchronously
|
||||||
this.createFontSettings(state);
|
this.createFontSettings(state);
|
||||||
this.createFontSizeSettings(state);
|
this.createFontSizeSettings(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private createFontSettings(state: ModalState): void {
|
private async createFontSettings(state: ModalState): Promise<void> {
|
||||||
if (!this.container) return;
|
if (!this.container) return;
|
||||||
|
|
||||||
|
// Get available fonts from cache
|
||||||
|
const availableFonts = await this.getAvailableFonts(state);
|
||||||
|
|
||||||
// Body font dropdown
|
// Body font dropdown
|
||||||
new Setting(this.container)
|
new Setting(this.container)
|
||||||
.setName('Body font')
|
.setName('Body font')
|
||||||
.setDesc('Primary font for document text')
|
.setDesc('Primary font for document text')
|
||||||
.addDropdown(async (dropdown) => {
|
.addDropdown(dropdown => {
|
||||||
try {
|
const currentFont = state.templateVariables.bodyFont || 'Times New Roman';
|
||||||
const fonts = await this.getAvailableFonts(state);
|
|
||||||
fonts.forEach(font => {
|
// Add all available fonts
|
||||||
|
availableFonts.forEach(font => {
|
||||||
dropdown.addOption(font, font);
|
dropdown.addOption(font, font);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add current font if it's not in the list
|
||||||
|
if (!availableFonts.includes(currentFont)) {
|
||||||
|
dropdown.addOption(currentFont, currentFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set current value and change handler
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(state.templateVariables.bodyFont || 'Concourse OT')
|
.setValue(currentFont)
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ bodyFont: value });
|
state.updateTemplateVariables({ bodyFont: value });
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load fonts:', error);
|
|
||||||
// Fallback to hardcoded fonts
|
|
||||||
this.addFallbackBodyFonts(dropdown, state);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Heading font dropdown
|
// Heading font dropdown
|
||||||
new Setting(this.container)
|
new Setting(this.container)
|
||||||
.setName('Heading font')
|
.setName('Heading font')
|
||||||
.setDesc('Font for headings and titles')
|
.setDesc('Font for headings and titles')
|
||||||
.addDropdown(async (dropdown) => {
|
.addDropdown(dropdown => {
|
||||||
try {
|
const currentFont = state.templateVariables.headingFont || 'Times New Roman';
|
||||||
const fonts = await this.getAvailableFonts(state);
|
|
||||||
fonts.forEach(font => {
|
// Add all available fonts
|
||||||
|
availableFonts.forEach(font => {
|
||||||
dropdown.addOption(font, font);
|
dropdown.addOption(font, font);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add current font if it's not in the list
|
||||||
|
if (!availableFonts.includes(currentFont)) {
|
||||||
|
dropdown.addOption(currentFont, currentFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set current value and change handler
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(state.templateVariables.headingFont || 'Concourse OT')
|
.setValue(currentFont)
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ headingFont: value });
|
state.updateTemplateVariables({ headingFont: value });
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load fonts:', error);
|
|
||||||
// Fallback to hardcoded fonts
|
|
||||||
this.addFallbackBodyFonts(dropdown, state);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Monospace font dropdown
|
// Monospace font dropdown
|
||||||
new Setting(this.container)
|
new Setting(this.container)
|
||||||
.setName('Monospace font')
|
.setName('Monospace font')
|
||||||
.setDesc('Font for code blocks and inline code')
|
.setDesc('Font for code blocks and inline code')
|
||||||
.addDropdown(async (dropdown) => {
|
.addDropdown(dropdown => {
|
||||||
try {
|
const currentFont = state.templateVariables.monospaceFont || 'Courier New';
|
||||||
const fonts = await this.getAvailableFonts(state);
|
|
||||||
// Filter for common monospace fonts or show all
|
// Add all available fonts
|
||||||
fonts.forEach(font => {
|
availableFonts.forEach(font => {
|
||||||
dropdown.addOption(font, font);
|
dropdown.addOption(font, font);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add current font if it's not in the list
|
||||||
|
if (!availableFonts.includes(currentFont)) {
|
||||||
|
dropdown.addOption(currentFont, currentFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set current value and change handler
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(state.templateVariables.monospaceFont || 'Source Code Pro')
|
.setValue(currentFont)
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ monospaceFont: value });
|
state.updateTemplateVariables({ monospaceFont: value });
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load fonts:', error);
|
|
||||||
// Fallback to hardcoded monospace fonts
|
|
||||||
this.addFallbackMonospaceFonts(dropdown, state);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,19 +108,14 @@ export class TypographySection implements ModalSection {
|
|||||||
// Body font size
|
// Body font size
|
||||||
new Setting(this.container)
|
new Setting(this.container)
|
||||||
.setName('Body font size')
|
.setName('Body font size')
|
||||||
.setDesc('Base font size for document text')
|
.setDesc('Base font size for document text (in points)')
|
||||||
.addDropdown(dropdown => {
|
.addSlider(slider => slider
|
||||||
dropdown
|
.setLimits(8, 16, 0.5)
|
||||||
.addOption('9pt', '9pt - Small')
|
.setValue(state.templateVariables.bodyFontSize || 11)
|
||||||
.addOption('10pt', '10pt - Compact')
|
.setDynamicTooltip()
|
||||||
.addOption('11pt', '11pt - Standard')
|
|
||||||
.addOption('12pt', '12pt - Large')
|
|
||||||
.addOption('14pt', '14pt - Extra Large')
|
|
||||||
.setValue(state.templateVariables.bodyFontSize || '11pt')
|
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ bodyFontSize: value });
|
state.updateTemplateVariables({ bodyFontSize: value });
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper methods for fonts - similar to settings tab
|
// Helper methods for fonts - similar to settings tab
|
||||||
@@ -157,7 +161,7 @@ export class TypographySection implements ModalSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFallbackBodyFonts(dropdown: any, state: ModalState): void {
|
private addFallbackBodyFonts(dropdown: any, state: ModalState, fontType: 'body' | 'heading'): void {
|
||||||
dropdown
|
dropdown
|
||||||
.addOption('Concourse OT', 'Concourse OT')
|
.addOption('Concourse OT', 'Concourse OT')
|
||||||
.addOption('Times New Roman', 'Times New Roman')
|
.addOption('Times New Roman', 'Times New Roman')
|
||||||
@@ -167,10 +171,17 @@ export class TypographySection implements ModalSection {
|
|||||||
.addOption('Calibri', 'Calibri')
|
.addOption('Calibri', 'Calibri')
|
||||||
.addOption('Cambria', 'Cambria')
|
.addOption('Cambria', 'Cambria')
|
||||||
.addOption('Palatino', 'Palatino')
|
.addOption('Palatino', 'Palatino')
|
||||||
.addOption('Book Antiqua', 'Book Antiqua')
|
.addOption('Book Antiqua', 'Book Antiqua');
|
||||||
.setValue(state.templateVariables.bodyFont || state.templateVariables.headingFont || 'Concourse OT')
|
|
||||||
|
// Set the appropriate value based on font type
|
||||||
|
const currentValue = fontType === 'body'
|
||||||
|
? state.templateVariables.bodyFont
|
||||||
|
: state.templateVariables.headingFont;
|
||||||
|
|
||||||
|
dropdown
|
||||||
|
.setValue(currentValue || 'Concourse OT')
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
if (dropdown.containerEl.closest('.setting-item')?.querySelector('.setting-item-name')?.textContent?.includes('Body')) {
|
if (fontType === 'body') {
|
||||||
state.updateTemplateVariables({ bodyFont: value });
|
state.updateTemplateVariables({ bodyFont: value });
|
||||||
} else {
|
} else {
|
||||||
state.updateTemplateVariables({ headingFont: value });
|
state.updateTemplateVariables({ headingFont: value });
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ export class ModalState implements IModalState {
|
|||||||
...initialSettings
|
...initialSettings
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize template variables with defaults, then saved state
|
// Use ONLY the passed templateVariables, with minimal fallbacks
|
||||||
|
// Priority: initialSettings > savedState > absolute minimal fallbacks
|
||||||
this.templateVariables = {
|
this.templateVariables = {
|
||||||
|
// Only provide absolute minimal fallbacks for required fields
|
||||||
pageSize: 'a4',
|
pageSize: 'a4',
|
||||||
orientation: 'portrait',
|
orientation: 'portrait',
|
||||||
flipped: false,
|
flipped: false,
|
||||||
@@ -45,12 +47,14 @@ export class ModalState implements IModalState {
|
|||||||
marginBottom: '0.8in',
|
marginBottom: '0.8in',
|
||||||
marginLeft: '1in',
|
marginLeft: '1in',
|
||||||
marginRight: '0.6in',
|
marginRight: '0.6in',
|
||||||
bodyFont: 'Concourse OT',
|
bodyFont: 'Times New Roman', // Generic fallback
|
||||||
headingFont: 'Concourse OT',
|
headingFont: 'Times New Roman', // Generic fallback
|
||||||
monospaceFont: 'Source Code Pro',
|
monospaceFont: 'Courier New', // Generic fallback
|
||||||
bodyFontSize: '11pt',
|
bodyFontSize: '11pt',
|
||||||
|
// Apply saved state if any
|
||||||
...savedState?.templateVariables,
|
...savedState?.templateVariables,
|
||||||
...this.settings.templateVariables
|
// Apply passed settings (this should be the plugin defaults)
|
||||||
|
...initialSettings.templateVariables
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update settings to include merged template variables
|
// Update settings to include merged template variables
|
||||||
@@ -131,34 +135,34 @@ export class ModalState implements IModalState {
|
|||||||
/**
|
/**
|
||||||
* Reset state to defaults
|
* Reset state to defaults
|
||||||
*/
|
*/
|
||||||
reset(): void {
|
reset(pluginDefaults: any): void {
|
||||||
// Reset to plugin defaults, not localStorage defaults
|
// Reset to plugin defaults, not hardcoded defaults
|
||||||
this.settings = {
|
this.settings = {
|
||||||
...this.settings,
|
...this.settings,
|
||||||
template: 'default.typ',
|
template: pluginDefaults.template,
|
||||||
format: ExportFormat.Standard,
|
format: pluginDefaults.format,
|
||||||
outputFolder: 'exports',
|
outputFolder: pluginDefaults.outputFolder || 'exports',
|
||||||
templateVariables: {},
|
templateVariables: {},
|
||||||
progressPercent: 0,
|
progressPercent: 0,
|
||||||
currentOperation: '',
|
currentOperation: '',
|
||||||
isExporting: false,
|
isExporting: false,
|
||||||
canCancel: false,
|
canCancel: false,
|
||||||
openAfterExport: false,
|
openAfterExport: pluginDefaults.openAfterExport || false,
|
||||||
preserveFolderStructure: false
|
preserveFolderStructure: pluginDefaults.preserveFolderStructure || false
|
||||||
};
|
};
|
||||||
|
|
||||||
this.templateVariables = {
|
this.templateVariables = {
|
||||||
pageSize: 'a4',
|
pageSize: pluginDefaults.pageSize,
|
||||||
orientation: 'portrait',
|
orientation: pluginDefaults.orientation,
|
||||||
flipped: false,
|
flipped: pluginDefaults.orientation === 'landscape',
|
||||||
marginTop: '1in',
|
marginTop: pluginDefaults.marginTop,
|
||||||
marginBottom: '0.8in',
|
marginBottom: pluginDefaults.marginBottom,
|
||||||
marginLeft: '1in',
|
marginLeft: pluginDefaults.marginLeft,
|
||||||
marginRight: '0.6in',
|
marginRight: pluginDefaults.marginRight,
|
||||||
bodyFont: 'Concourse OT',
|
bodyFont: pluginDefaults.bodyFont,
|
||||||
headingFont: 'Concourse OT',
|
headingFont: pluginDefaults.headingFont,
|
||||||
monospaceFont: 'Source Code Pro',
|
monospaceFont: pluginDefaults.monospaceFont,
|
||||||
bodyFontSize: '11pt'
|
bodyFontSize: pluginDefaults.bodyFontSize
|
||||||
};
|
};
|
||||||
|
|
||||||
this.settings.templateVariables = this.templateVariables;
|
this.settings.templateVariables = this.templateVariables;
|
||||||
|
|||||||
+1
-1
@@ -56,6 +56,6 @@ export interface ModalState {
|
|||||||
buildExportConfig(): ExportConfig;
|
buildExportConfig(): ExportConfig;
|
||||||
notifyChange(): void;
|
notifyChange(): void;
|
||||||
setProgress(percent: number, operation: string): void;
|
setProgress(percent: number, operation: string): void;
|
||||||
reset(): void;
|
reset(pluginDefaults: any): void;
|
||||||
onChange(listener: () => void): void;
|
onChange(listener: () => void): void;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user