Refactors project structure for improved modularity
Moves components and modules to more appropriate directories. This change improves project organization and maintainability by grouping related files into logical directories, enhancing code discoverability and reducing potential naming conflicts.
This commit is contained in:
16 files changed
+21
-21
No files matched your search
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* General Section for Export Configuration Modal
|
||||
* Handles template selection, format options, and output settings
|
||||
*/
|
||||
|
||||
import { Setting, App } from 'obsidian';
|
||||
import { ModalSection, ModalState, ValidationResult } from '../modalTypes';
|
||||
import { ExportFormat } from '../../../core/settings';
|
||||
import { FolderSuggest } from '../../components/FolderSuggest';
|
||||
|
||||
export class GeneralSection implements ModalSection {
|
||||
private container: HTMLElement | null = null;
|
||||
private templateDropdown: any = null;
|
||||
private outputFolderInput: HTMLInputElement | null = null;
|
||||
private app: App;
|
||||
|
||||
render(containerEl: HTMLElement, state: ModalState, app?: App): void {
|
||||
if (app) this.app = app;
|
||||
this.container = containerEl.createDiv('export-section');
|
||||
this.container.createEl('h3', { text: 'General Settings' });
|
||||
|
||||
this.createTemplateSelection(state);
|
||||
this.createFormatSelection(state);
|
||||
this.createOutputSettings(state);
|
||||
}
|
||||
|
||||
private createTemplateSelection(state: ModalState): void {
|
||||
if (!this.container) return;
|
||||
|
||||
new Setting(this.container)
|
||||
.setName('Typst template')
|
||||
.setDesc('Select template for document styling')
|
||||
.addDropdown(dropdown => {
|
||||
// Filter out universal-wrapper.pandoc.typ and populate with available templates
|
||||
const filteredTemplates = state.settings.availableTemplates
|
||||
.filter(template => template !== 'universal-wrapper.pandoc.typ');
|
||||
|
||||
filteredTemplates.forEach(template => {
|
||||
dropdown.addOption(template, this.getTemplateDisplayName(template));
|
||||
});
|
||||
|
||||
dropdown
|
||||
.setValue(state.settings.template || 'default.typ')
|
||||
.onChange(value => {
|
||||
state.updateSettings({ template: value });
|
||||
});
|
||||
|
||||
this.templateDropdown = dropdown;
|
||||
});
|
||||
}
|
||||
|
||||
private createFormatSelection(state: ModalState): void {
|
||||
if (!this.container) return;
|
||||
|
||||
new Setting(this.container)
|
||||
.setName('PDF format')
|
||||
.setDesc('Choose document layout format')
|
||||
.addDropdown(dropdown => {
|
||||
dropdown
|
||||
.addOption(ExportFormat.Standard, 'Standard (multi-page PDF)')
|
||||
.addOption(ExportFormat.SinglePage, 'Single-page (continuous layout)')
|
||||
.setValue(state.settings.format || ExportFormat.Standard)
|
||||
.onChange(value => {
|
||||
state.updateSettings({ format: value as ExportFormat });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private createOutputSettings(state: ModalState): void {
|
||||
if (!this.container) return;
|
||||
|
||||
new Setting(this.container)
|
||||
.setName('Output folder')
|
||||
.setDesc('Folder where PDFs will be saved (relative to vault root)')
|
||||
.addText(text => {
|
||||
const input = text
|
||||
.setPlaceholder('exports')
|
||||
.setValue(state.settings.outputFolder || 'exports')
|
||||
.onChange(value => {
|
||||
state.updateSettings({ outputFolder: value });
|
||||
});
|
||||
this.outputFolderInput = input.inputEl;
|
||||
|
||||
// Add folder autosuggest
|
||||
if (this.app) {
|
||||
new FolderSuggest(this.app, input.inputEl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getTemplateDisplayName(template: string): string {
|
||||
// Remove extension and capitalize
|
||||
const name = template.replace(/\.(typ|pandoc\.typ)$/, '');
|
||||
return name.charAt(0).toUpperCase() + name.slice(1).replace(/-/g, ' ');
|
||||
}
|
||||
|
||||
validate(): ValidationResult {
|
||||
const errors: string[] = [];
|
||||
const warnings: string[] = [];
|
||||
|
||||
// Validate output folder
|
||||
if (this.outputFolderInput) {
|
||||
const value = this.outputFolderInput.value.trim();
|
||||
if (!value) {
|
||||
errors.push('Output folder is required');
|
||||
} else if (value.startsWith('/') || value.startsWith('\\')) {
|
||||
warnings.push('Output folder should be relative to vault root');
|
||||
}
|
||||
}
|
||||
|
||||
// Check template selection
|
||||
if (!this.templateDropdown || !this.templateDropdown.getValue()) {
|
||||
errors.push('Template selection is required');
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
warnings
|
||||
};
|
||||
}
|
||||
|
||||
updateAvailableTemplates(templates: string[]): void {
|
||||
if (!this.templateDropdown) return;
|
||||
|
||||
const currentValue = this.templateDropdown.getValue();
|
||||
|
||||
// Filter out universal-wrapper.pandoc.typ and clear/repopulate dropdown
|
||||
const filteredTemplates = templates.filter(template => template !== 'universal-wrapper.pandoc.typ');
|
||||
|
||||
this.templateDropdown.selectEl.empty();
|
||||
filteredTemplates.forEach(template => {
|
||||
this.templateDropdown.addOption(template, this.getTemplateDisplayName(template));
|
||||
});
|
||||
|
||||
// Restore selection if still available
|
||||
if (filteredTemplates.includes(currentValue)) {
|
||||
this.templateDropdown.setValue(currentValue);
|
||||
} else if (filteredTemplates.length > 0) {
|
||||
this.templateDropdown.setValue(filteredTemplates[0]);
|
||||
}
|
||||
}
|
||||
|
||||
getId(): string {
|
||||
return 'general';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user