refactor: move modal methods to ExportOrchestrator (step 1.9)
Move export modal orchestration from main.ts to ExportOrchestrator: - Move showExportModal() and showExportModalForFiles() methods - Add required imports to ExportOrchestrator (MarkdownView, ExportConfigModal, ModalSettingsHelper) - Replace main.ts methods with delegation calls to ExportOrchestrator - Remove unused imports from main.ts (ModalSettingsHelper, ExportConfigModal, etc.) - Reduce main.ts from 351 → 290 lines (61 lines moved) Improves separation of concerns by consolidating all export orchestration logic in ExportOrchestrator, including modal creation and configuration. Modal functionality preserved through delegation pattern. Total progress: main.ts reduced from 1233 → 290 lines (943 lines extracted, 76% reduction) Build passes successfully ✅ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2 files changed
+78
-66
No files matched your search
@@ -24,16 +24,12 @@ import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from '
|
|||||||
import { FALLBACK_FONTS, PLUGIN_DIRS } from './src/core/constants';
|
import { FALLBACK_FONTS, PLUGIN_DIRS } from './src/core/constants';
|
||||||
import { DependencyChecker } from './src/core/DependencyChecker';
|
import { DependencyChecker } from './src/core/DependencyChecker';
|
||||||
import { SecurityUtils } from './src/core/SecurityUtils';
|
import { SecurityUtils } from './src/core/SecurityUtils';
|
||||||
import { ModalSettingsHelper } from './src/core/ModalSettingsHelper';
|
|
||||||
import { ExportErrorHandler } from './src/core/ExportErrorHandler';
|
import { ExportErrorHandler } from './src/core/ExportErrorHandler';
|
||||||
import { TempDirectoryManager } from './src/core/TempDirectoryManager';
|
import { TempDirectoryManager } from './src/core/TempDirectoryManager';
|
||||||
import { PandocTypstConverter } from './src/converters/PandocTypstConverter';
|
import { PandocTypstConverter } from './src/converters/PandocTypstConverter';
|
||||||
import { MarkdownPreprocessor } from './src/converters/MarkdownPreprocessor';
|
import { MarkdownPreprocessor } from './src/converters/MarkdownPreprocessor';
|
||||||
import { ExportConfigModal } from './src/ui/modal/ExportConfigModal';
|
|
||||||
import { ExportConfig, ExportConfigModalSettings } from './src/ui/modal/modalTypes';
|
|
||||||
import { TemplateManager } from './src/templates/TemplateManager';
|
import { TemplateManager } from './src/templates/TemplateManager';
|
||||||
import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates';
|
import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates';
|
||||||
import { FolderSuggest } from './src/ui/components/FolderSuggest';
|
|
||||||
import { SUPPORTED_PAPER_SIZES } from './src/utils/paperSizeMapper';
|
import { SUPPORTED_PAPER_SIZES } from './src/utils/paperSizeMapper';
|
||||||
import { PluginLifecycle } from './src/plugin/PluginLifecycle';
|
import { PluginLifecycle } from './src/plugin/PluginLifecycle';
|
||||||
import { CommandRegistry } from './src/plugin/CommandRegistry';
|
import { CommandRegistry } from './src/plugin/CommandRegistry';
|
||||||
@@ -128,74 +124,17 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the export configuration modal
|
* Show the export configuration modal (delegated to ExportOrchestrator)
|
||||||
*/
|
*/
|
||||||
async showExportModal(view: MarkdownView): Promise<void> {
|
async showExportModal(view: MarkdownView): Promise<void> {
|
||||||
const file = view.file;
|
return this.exportOrchestrator.showExportModal(view);
|
||||||
if (!file) {
|
|
||||||
new Notice('No active file to export');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get available templates first
|
|
||||||
const availableTemplates = await this.templateManager.getAvailableTemplates();
|
|
||||||
|
|
||||||
// Prepare modal settings using helper
|
|
||||||
const modalSettings = ModalSettingsHelper.prepareForSingleFile(
|
|
||||||
file,
|
|
||||||
availableTemplates,
|
|
||||||
this.settings
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show modal - ModalState will handle localStorage hierarchy automatically
|
|
||||||
const modal = new ExportConfigModal(
|
|
||||||
this.app,
|
|
||||||
this,
|
|
||||||
modalSettings,
|
|
||||||
async (config: ExportConfig) => {
|
|
||||||
await this.exportOrchestrator.exportFileWithConfig(file, config);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.exportOrchestrator.cancelExport();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
modal.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the export configuration modal for multiple files
|
* Show the export configuration modal for multiple files (delegated to ExportOrchestrator)
|
||||||
*/
|
*/
|
||||||
async showExportModalForFiles(files: TFile[]): Promise<void> {
|
async showExportModalForFiles(files: TFile[]): Promise<void> {
|
||||||
if (files.length === 0) {
|
return this.exportOrchestrator.showExportModalForFiles(files);
|
||||||
new Notice('No files to export');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get available templates first
|
|
||||||
const availableTemplates = await this.templateManager.getAvailableTemplates();
|
|
||||||
|
|
||||||
// Prepare modal settings using helper
|
|
||||||
const modalSettings = ModalSettingsHelper.prepareForMultiFile(
|
|
||||||
files,
|
|
||||||
availableTemplates,
|
|
||||||
this.settings
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show modal - ModalState will handle localStorage hierarchy automatically
|
|
||||||
const modal = new ExportConfigModal(
|
|
||||||
this.app,
|
|
||||||
this,
|
|
||||||
modalSettings,
|
|
||||||
async (config: ExportConfig) => {
|
|
||||||
await this.exportOrchestrator.exportFilesWithConfig(files, config);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.exportOrchestrator.cancelExport();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
modal.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
* Handles the coordination and execution of all export workflows
|
* Handles the coordination and execution of all export workflows
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TFile, TFolder, Notice } from 'obsidian';
|
import { TFile, TFolder, Notice, MarkdownView } from 'obsidian';
|
||||||
import type { obsidianTypstPDFExport } from '../../main';
|
import type { obsidianTypstPDFExport } from '../../main';
|
||||||
import { ExportConfig } from '../ui/modal/modalTypes';
|
import { ExportConfig } from '../ui/modal/modalTypes';
|
||||||
|
import { ExportConfigModal } from '../ui/modal/ExportConfigModal';
|
||||||
|
import { ModalSettingsHelper } from '../core/ModalSettingsHelper';
|
||||||
import { MarkdownPreprocessor } from '../converters/MarkdownPreprocessor';
|
import { MarkdownPreprocessor } from '../converters/MarkdownPreprocessor';
|
||||||
import { TempDirectoryManager } from '../core/TempDirectoryManager';
|
import { TempDirectoryManager } from '../core/TempDirectoryManager';
|
||||||
import { ExportErrorHandler } from '../core/ExportErrorHandler';
|
import { ExportErrorHandler } from '../core/ExportErrorHandler';
|
||||||
@@ -55,6 +57,77 @@ export class ExportOrchestrator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the export configuration modal
|
||||||
|
*/
|
||||||
|
async showExportModal(view: MarkdownView): Promise<void> {
|
||||||
|
const file = view.file;
|
||||||
|
if (!file) {
|
||||||
|
new Notice('No active file to export');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get available templates first
|
||||||
|
const availableTemplates = await this.plugin.templateManager.getAvailableTemplates();
|
||||||
|
|
||||||
|
// Prepare modal settings using helper
|
||||||
|
const modalSettings = ModalSettingsHelper.prepareForSingleFile(
|
||||||
|
file,
|
||||||
|
availableTemplates,
|
||||||
|
this.plugin.settings
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show modal - ModalState will handle localStorage hierarchy automatically
|
||||||
|
const modal = new ExportConfigModal(
|
||||||
|
this.plugin.app,
|
||||||
|
this.plugin,
|
||||||
|
modalSettings,
|
||||||
|
async (config: ExportConfig) => {
|
||||||
|
await this.exportFileWithConfig(file, config);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this.cancelExport();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
modal.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the export configuration modal for multiple files
|
||||||
|
*/
|
||||||
|
async showExportModalForFiles(files: TFile[]): Promise<void> {
|
||||||
|
if (files.length === 0) {
|
||||||
|
new Notice('No files to export');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get available templates first
|
||||||
|
const availableTemplates = await this.plugin.templateManager.getAvailableTemplates();
|
||||||
|
|
||||||
|
// Prepare modal settings using helper
|
||||||
|
const modalSettings = ModalSettingsHelper.prepareForMultiFile(
|
||||||
|
files,
|
||||||
|
availableTemplates,
|
||||||
|
this.plugin.settings
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show modal - ModalState will handle localStorage hierarchy automatically
|
||||||
|
const modal = new ExportConfigModal(
|
||||||
|
this.plugin.app,
|
||||||
|
this.plugin,
|
||||||
|
modalSettings,
|
||||||
|
async (config: ExportConfig) => {
|
||||||
|
await this.exportFilesWithConfig(files, config);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this.cancelExport();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
modal.open();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export a file with specific configuration
|
* Export a file with specific configuration
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user