Applies Obsidian linter and fixes code issues
Applies linting rules to the codebase and resolves identified issues. Addresses: - Renamed headings in settings tabs to improve UI consistency and style. - Resolved require() style imports - Added void operator to ensure correct promise handling. - Replaced deprecated Obsidian API calls. - Enforces sentence case to enhance UI text consistency.
This commit is contained in:
37 files changed
+4314
-872
No files matched your search
@@ -20,7 +20,7 @@ export class ExportConfigModal extends Modal {
|
||||
plugin: obsidianTypstPDFExport;
|
||||
private state: ModalState;
|
||||
private sections: Map<string, ModalSection> = new Map();
|
||||
private onSubmit: (config: ExportConfig) => void;
|
||||
private onSubmit: (config: ExportConfig) => void | Promise<void>;
|
||||
private onCancel?: () => void;
|
||||
private renderer: ModalRenderer;
|
||||
private validator: ModalValidator;
|
||||
@@ -29,7 +29,7 @@ export class ExportConfigModal extends Modal {
|
||||
app: App,
|
||||
plugin: obsidianTypstPDFExport,
|
||||
settings: Partial<ExportConfigModalSettings>,
|
||||
onSubmit: (config: ExportConfig) => void,
|
||||
onSubmit: (config: ExportConfig) => void | Promise<void>,
|
||||
onCancel?: () => void
|
||||
) {
|
||||
super(app);
|
||||
@@ -38,7 +38,7 @@ export class ExportConfigModal extends Modal {
|
||||
this.onCancel = onCancel;
|
||||
|
||||
// Initialize state
|
||||
this.state = new ModalState(settings);
|
||||
this.state = new ModalState(settings, app);
|
||||
|
||||
// Register sections
|
||||
this.registerSections();
|
||||
@@ -81,9 +81,9 @@ export class ExportConfigModal extends Modal {
|
||||
|
||||
// Initialize renderer with content container
|
||||
this.renderer.initialize(contentContainer);
|
||||
|
||||
|
||||
// Load available templates
|
||||
this.loadAvailableTemplates();
|
||||
void this.loadAvailableTemplates();
|
||||
}
|
||||
|
||||
private async loadAvailableTemplates(): Promise<void> {
|
||||
@@ -117,10 +117,10 @@ export class ExportConfigModal extends Modal {
|
||||
|
||||
// Re-render sections to update UI
|
||||
this.renderer.refreshSections();
|
||||
|
||||
|
||||
// Reload templates to update the dropdown
|
||||
this.loadAvailableTemplates();
|
||||
|
||||
void this.loadAvailableTemplates();
|
||||
|
||||
ExportErrorHandler.showSettingsReset();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ModalSection } from './modalTypes';
|
||||
export interface ModalRendererCallbacks {
|
||||
onReset: () => void;
|
||||
onCancel: () => void;
|
||||
onSubmit: () => void;
|
||||
onSubmit: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
export class ModalRenderer {
|
||||
@@ -47,7 +47,6 @@ export class ModalRenderer {
|
||||
initialize(contentContainer: HTMLElement): void {
|
||||
this.contentContainer = contentContainer;
|
||||
this.setupInitialLayout();
|
||||
this.addModalStyles();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,9 +118,9 @@ export class ModalRenderer {
|
||||
// Progress bar container
|
||||
const progressBarContainer = this.progressContainer.createDiv('export-progress-bar-container');
|
||||
this.progressBar = progressBarContainer.createDiv('export-progress-bar');
|
||||
|
||||
|
||||
// Progress percentage
|
||||
const _progressPercent = this.progressContainer.createEl('div', {
|
||||
this.progressContainer.createEl('div', {
|
||||
cls: 'export-progress-percent',
|
||||
text: '0%'
|
||||
});
|
||||
@@ -135,7 +134,7 @@ export class ModalRenderer {
|
||||
|
||||
// Reset button (left side)
|
||||
this.resetButton = buttonContainer.createEl('button', {
|
||||
text: 'Reset to Defaults',
|
||||
text: 'Reset to defaults',
|
||||
cls: 'mod-muted'
|
||||
});
|
||||
this.resetButton.addEventListener('click', () => this.callbacks.onReset());
|
||||
@@ -219,7 +218,7 @@ export class ModalRenderer {
|
||||
}
|
||||
|
||||
const errorContainer = this.formContainer.createDiv('validation-errors');
|
||||
errorContainer.createEl('h4', { text: 'Validation Errors', cls: 'error-title' });
|
||||
errorContainer.createEl('h4', { text: 'Validation errors', cls: 'error-title' });
|
||||
|
||||
const errorList = errorContainer.createEl('ul');
|
||||
errors.forEach(error => {
|
||||
@@ -251,241 +250,4 @@ export class ModalRenderer {
|
||||
// Remove after 5 seconds
|
||||
setTimeout(() => warningContainer.remove(), 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom CSS styles for the modal
|
||||
*/
|
||||
private addModalStyles(): void {
|
||||
// Add custom styles for the modal
|
||||
const style = document.createElement('style');
|
||||
style.textContent = `
|
||||
.export-config-modal {
|
||||
width: 90vw;
|
||||
max-width: 520px;
|
||||
height: 80vh;
|
||||
max-height: 600px;
|
||||
}
|
||||
|
||||
.export-config-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.export-config-header {
|
||||
padding: 16px 24px 8px 24px;
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.export-config-header h2 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.export-note-title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.export-config-form {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px 24px;
|
||||
}
|
||||
|
||||
.export-config-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.export-config-section:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.export-config-section-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 4px;
|
||||
border-bottom: 1px solid var(--background-modifier-border-hover);
|
||||
}
|
||||
|
||||
.export-config-buttons {
|
||||
padding: 16px 24px;
|
||||
border-top: 1px solid var(--background-modifier-border);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.export-config-buttons .right-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Progress styles */
|
||||
.export-progress-container {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.export-progress-container.export-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.export-progress-container.export-progress-visible {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.export-form-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.export-progress-text {
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.export-progress-bar-container {
|
||||
width: 100%;
|
||||
height: 8px;
|
||||
background-color: var(--background-modifier-border);
|
||||
border-radius: 4px;
|
||||
margin-bottom: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.export-progress-bar {
|
||||
height: 100%;
|
||||
background-color: var(--interactive-accent);
|
||||
border-radius: 4px;
|
||||
width: var(--progress-width, 0%);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.export-progress-percent {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* Form field styles */
|
||||
.export-setting-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.export-setting-item-info {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.export-setting-item-name {
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.export-setting-item-description {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.export-setting-item-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.export-setting-item-control input,
|
||||
.export-setting-item-control select {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Folder suggest styles */
|
||||
.export-folder-suggest-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.export-folder-suggest-input {
|
||||
width: 100%;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 4px;
|
||||
background: var(--background-primary);
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
.export-folder-suggest-input:focus {
|
||||
border-color: var(--interactive-accent);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Validation styles */
|
||||
.validation-errors, .validation-warnings {
|
||||
background: var(--background-modifier-error);
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.validation-warnings {
|
||||
background: var(--background-modifier-warning);
|
||||
}
|
||||
|
||||
.error-title {
|
||||
color: var(--text-error);
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.warning-title {
|
||||
color: var(--text-warning);
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.validation-errors ul, .validation-warnings ul {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.export-validation-error {
|
||||
color: var(--text-error);
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.export-validation-warning {
|
||||
color: var(--text-warning);
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* Template variable styles */
|
||||
.export-template-variables {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.export-template-variable {
|
||||
margin-bottom: 8px;
|
||||
padding: 8px;
|
||||
background: var(--background-secondary);
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.export-template-variable-name {
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.export-template-variable-description {
|
||||
color: var(--text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
`;
|
||||
|
||||
if (!document.head.querySelector('style[data-export-config-modal]')) {
|
||||
style.setAttribute('data-export-config-modal', 'true');
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,9 @@ export class BehaviorSection implements ModalSection {
|
||||
|
||||
render(containerEl: HTMLElement, state: ModalState): void {
|
||||
this.container = containerEl.createDiv('export-section');
|
||||
this.container.createEl('h3', { text: 'Export Behavior' });
|
||||
new Setting(this.container)
|
||||
.setName('Export behavior')
|
||||
.setHeading();
|
||||
|
||||
this.createBehaviorToggles(state);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ export class GeneralSection implements ModalSection {
|
||||
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' });
|
||||
new Setting(this.container)
|
||||
.setName('General settings')
|
||||
.setHeading();
|
||||
|
||||
this.createTemplateSelection(state);
|
||||
this.createFormatSelection(state);
|
||||
|
||||
@@ -13,7 +13,9 @@ export class LayoutSection implements ModalSection {
|
||||
|
||||
render(containerEl: HTMLElement, state: ModalState): void {
|
||||
this.container = containerEl.createDiv('export-section');
|
||||
this.container.createEl('h3', { text: 'Page Layout' });
|
||||
new Setting(this.container)
|
||||
.setName('Page layout')
|
||||
.setHeading();
|
||||
|
||||
this.createPageSizeSettings(state);
|
||||
this.createOrientationSettings(state);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { Setting } from 'obsidian';
|
||||
import { ModalSection, ModalState, ValidationResult } from '../modalTypes';
|
||||
import { SUPPORTED_PAPER_SIZES } from '../../../utils/paperSizeMapper';
|
||||
import { ExportFormat } from '../../../core/settings';
|
||||
|
||||
export class PageSetupSection implements ModalSection {
|
||||
private container: HTMLElement | null = null;
|
||||
@@ -13,7 +14,9 @@ export class PageSetupSection implements ModalSection {
|
||||
|
||||
render(containerEl: HTMLElement, state: ModalState): void {
|
||||
this.container = containerEl.createDiv('export-section');
|
||||
this.container.createEl('h3', { text: 'Page Setup' });
|
||||
new Setting(this.container)
|
||||
.setName('Page setup')
|
||||
.setHeading();
|
||||
|
||||
this.createPageSizeSettings(state);
|
||||
this.createOrientationSettings(state);
|
||||
@@ -53,12 +56,12 @@ export class PageSetupSection implements ModalSection {
|
||||
.setValue(String(state.templateVariables.orientation || 'portrait'))
|
||||
.onChange(value => {
|
||||
const isLandscape = value === 'landscape';
|
||||
state.updateTemplateVariables({
|
||||
state.updateTemplateVariables({
|
||||
orientation: value,
|
||||
flipped: isLandscape,
|
||||
// Auto-adjust width for single-page mode when flipped
|
||||
...(isLandscape && state.settings.format === 'single-page'
|
||||
? { width: 'auto' }
|
||||
...(isLandscape && state.settings.format === ExportFormat.SinglePage
|
||||
? { width: 'auto' }
|
||||
: {})
|
||||
});
|
||||
});
|
||||
@@ -69,7 +72,7 @@ export class PageSetupSection implements ModalSection {
|
||||
if (!this.container) return;
|
||||
|
||||
const marginsContainer = this.container.createDiv('margins-container');
|
||||
marginsContainer.createEl('h4', { text: 'Text Margins' });
|
||||
marginsContainer.createEl('h4', { text: 'Text margins' });
|
||||
marginsContainer.createEl('p', {
|
||||
text: 'Enter margins in centimeters (e.g., "2.5", "1.8", "3.0")',
|
||||
cls: 'setting-item-description'
|
||||
|
||||
@@ -13,10 +13,12 @@ export class TypographySection implements ModalSection {
|
||||
render(containerEl: HTMLElement, state: ModalState, app?: App): void {
|
||||
if (app) this.app = app;
|
||||
this.container = containerEl.createDiv('export-section');
|
||||
this.container.createEl('h3', { text: 'Typography' });
|
||||
new Setting(this.container)
|
||||
.setName('Typography')
|
||||
.setHeading();
|
||||
|
||||
// Create font settings asynchronously
|
||||
this.createFontSettings(state);
|
||||
void this.createFontSettings(state);
|
||||
this.createFontSizeSettings(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Centralized state management for the Export Configuration Modal
|
||||
*/
|
||||
|
||||
import { App } from 'obsidian';
|
||||
import { ExportConfigModalSettings, ExportConfig, ModalState as IModalState } from '../modalTypes';
|
||||
import { ExportFormat, obsidianTypstPDFExportSettings } from '../../../core/settings';
|
||||
|
||||
@@ -13,7 +14,7 @@ export class ModalState implements IModalState {
|
||||
private changeListeners: Set<() => void> = new Set();
|
||||
private static readonly STORAGE_KEY = 'typst-export-modal-state';
|
||||
|
||||
constructor(initialSettings: Partial<ExportConfigModalSettings>) {
|
||||
constructor(initialSettings: Partial<ExportConfigModalSettings>, private app: App) {
|
||||
// Load from localStorage if available
|
||||
const savedState = this.loadFromStorage();
|
||||
|
||||
@@ -174,7 +175,7 @@ export class ModalState implements IModalState {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current state to localStorage
|
||||
* Save current state to vault-specific storage
|
||||
*/
|
||||
private saveToStorage(): void {
|
||||
const stateToSave = {
|
||||
@@ -187,25 +188,25 @@ export class ModalState implements IModalState {
|
||||
},
|
||||
templateVariables: this.templateVariables
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
localStorage.setItem(ModalState.STORAGE_KEY, JSON.stringify(stateToSave));
|
||||
this.app.saveLocalStorage(ModalState.STORAGE_KEY, JSON.stringify(stateToSave));
|
||||
} catch (error) {
|
||||
console.warn('Failed to save modal state to localStorage:', error);
|
||||
console.warn('Failed to save modal state to vault storage:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load state from localStorage
|
||||
* Load state from vault-specific storage
|
||||
*/
|
||||
private loadFromStorage(): { settings: Partial<ExportConfigModalSettings>, templateVariables: Record<string, string | number | boolean> } | null {
|
||||
try {
|
||||
const saved = localStorage.getItem(ModalState.STORAGE_KEY);
|
||||
const saved = this.app.loadLocalStorage(ModalState.STORAGE_KEY);
|
||||
if (saved) {
|
||||
return JSON.parse(saved);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load modal state from localStorage:', error);
|
||||
console.warn('Failed to load modal state from vault storage:', error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user