mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 06:53:43 +00:00
Move ParallelReaderView to src/view.ts (341 lines), CardEditModal to src/modal.ts (56 lines), ParallelReaderSettingTab to src/settings-tab.ts (370 lines). Add PluginHost interface in types.ts to break circular deps. main.ts reduced from 1613 to 588 lines. Change-Id: I90902e914f162ff92b9a7f7c190b4d397a2c8c12
56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
'use strict';
|
|
|
|
import { Modal } from 'obsidian';
|
|
import type { ResolvedCard, CardPatch, PluginHost } from './types';
|
|
import { addTextButton } from './ui-helpers';
|
|
|
|
export class CardEditModal extends Modal {
|
|
plugin: PluginHost;
|
|
card: ResolvedCard;
|
|
onSave: (patch: CardPatch) => void | Promise<void>;
|
|
|
|
constructor(app, plugin: PluginHost, card: ResolvedCard, onSave: (patch: CardPatch) => void | Promise<void>) {
|
|
super(app);
|
|
this.plugin = plugin;
|
|
this.card = card || ({} as ResolvedCard);
|
|
this.onSave = onSave;
|
|
}
|
|
|
|
onOpen() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
contentEl.createEl('h2', { text: this.plugin.t('editCardTitle') });
|
|
|
|
const titleInput = this.createLabeledInput(contentEl, this.plugin.t('editCardTitleField'), this.card.title || '');
|
|
const gistInput = this.createLabeledTextarea(contentEl, this.plugin.t('editCardGistField'), this.card.gist || '', 3);
|
|
const bulletsInput = this.createLabeledTextarea(contentEl, this.plugin.t('editCardBulletsField'), (this.card.bullets || []).join('\n'), 8);
|
|
|
|
const actions = contentEl.createDiv({ cls: 'parallel-reader-modal-actions' });
|
|
addTextButton(actions, null, this.plugin.t('editCardCancel'), () => this.close(), 'parallel-reader-text-button');
|
|
addTextButton(actions, null, this.plugin.t('editCardSave'), async () => {
|
|
await this.onSave({
|
|
title: titleInput.value.trim() || this.card.title || '',
|
|
gist: gistInput.value.trim(),
|
|
bullets: bulletsInput.value.split(/\r?\n/).map(line => line.trim()).filter(Boolean),
|
|
});
|
|
this.close();
|
|
}, 'parallel-reader-text-button');
|
|
}
|
|
|
|
createLabeledInput(parent, label: string, value: string) {
|
|
const wrapper = parent.createDiv({ cls: 'parallel-reader-modal-field' });
|
|
wrapper.createEl('label', { text: label });
|
|
const input = wrapper.createEl('input', { attr: { type: 'text' } });
|
|
input.value = value;
|
|
return input;
|
|
}
|
|
|
|
createLabeledTextarea(parent, label: string, value: string, rows: number) {
|
|
const wrapper = parent.createDiv({ cls: 'parallel-reader-modal-field' });
|
|
wrapper.createEl('label', { text: label });
|
|
const textarea = wrapper.createEl('textarea');
|
|
textarea.rows = rows;
|
|
textarea.value = value;
|
|
return textarea;
|
|
}
|
|
}
|