mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 06:53:43 +00:00
refactor: replace PluginHost any types with Obsidian App/TFile
Use App, TFile, PluginManifest from obsidian in PluginHost interface. Remove `as any` cast in ParallelReaderSettingTab by accepting Plugin & PluginHost intersection type. Add typed params to vault.ts and modal.ts constructors. Change-Id: I94487d2654fd829c69364dabe9fbd5dc009097b6
This commit is contained in:
parent
22f0781334
commit
89139c37dc
4 changed files with 19 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
import { Modal } from 'obsidian';
|
||||
import { type App, Modal } from 'obsidian';
|
||||
import type { CardPatch, PluginHost, ResolvedCard } from './types';
|
||||
import { addTextButton } from './ui-helpers';
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ export class CardEditModal extends Modal {
|
|||
card: ResolvedCard;
|
||||
onSave: (patch: CardPatch) => void | Promise<void>;
|
||||
|
||||
constructor(app, plugin: PluginHost, card: ResolvedCard, onSave: (patch: CardPatch) => void | Promise<void>) {
|
||||
constructor(app: App, plugin: PluginHost, card: ResolvedCard, onSave: (patch: CardPatch) => void | Promise<void>) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.card = card || ({} as ResolvedCard);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
import { Notice, PluginSettingTab, requestUrl, Setting } from 'obsidian';
|
||||
import { type App, Notice, type Plugin, PluginSettingTab, requestUrl, Setting } from 'obsidian';
|
||||
import { resolveCliPath, runCli } from './cli';
|
||||
import { testApiBackend } from './providers';
|
||||
import {
|
||||
|
|
@ -36,10 +36,10 @@ async function testBackend(settings) {
|
|||
}
|
||||
|
||||
export class ParallelReaderSettingTab extends PluginSettingTab {
|
||||
plugin: PluginHost;
|
||||
plugin: Plugin & PluginHost;
|
||||
|
||||
constructor(app, plugin: PluginHost) {
|
||||
super(app, plugin as any);
|
||||
constructor(app: App, plugin: Plugin & PluginHost) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
|
|
|||
14
src/types.ts
14
src/types.ts
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import type { App, PluginManifest, TFile } from 'obsidian';
|
||||
|
||||
/* ---------- Card types ---------- */
|
||||
|
||||
/** Raw card as returned by the LLM and stored in cache (no computed fields). */
|
||||
|
|
@ -114,16 +116,16 @@ export interface PromptPair {
|
|||
* main.ts and the extracted modules.
|
||||
*/
|
||||
export interface PluginHost {
|
||||
app: { vault: any; workspace: any };
|
||||
app: App;
|
||||
settings: PluginSettings;
|
||||
cache: Record<string, CacheEntry>;
|
||||
manifest?: { id: string };
|
||||
manifest: PluginManifest;
|
||||
t(key: string, vars?: Record<string, string | number>): string;
|
||||
isGeneratingFile(file: any): boolean;
|
||||
cancelGenerationForFile(file: any): boolean;
|
||||
runForFile(file: any, force: boolean): Promise<void>;
|
||||
isGeneratingFile(file: TFile | null): boolean;
|
||||
cancelGenerationForFile(file: TFile | null): boolean;
|
||||
runForFile(file: TFile | null, force: boolean): Promise<void>;
|
||||
copyCurrentViewMarkdown(): Promise<void>;
|
||||
scrollEditorToLine(line: number, file: any): Promise<void>;
|
||||
scrollEditorToLine(line: number, file: TFile | null): Promise<void>;
|
||||
cacheReplaceCards(filePath: string, cards: ResolvedCard[]): Promise<boolean>;
|
||||
saveSettings(): Promise<void>;
|
||||
saveSettingsDebounced(delayMs?: number): void;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
export function normalizeVaultPath(path) {
|
||||
import type { App } from 'obsidian';
|
||||
|
||||
export function normalizeVaultPath(path: string): string {
|
||||
return String(path || '')
|
||||
.split('/')
|
||||
.map((part) => part.trim())
|
||||
|
|
@ -8,14 +10,14 @@ export function normalizeVaultPath(path) {
|
|||
.join('/');
|
||||
}
|
||||
|
||||
export function folderPathsForTarget(folderPath) {
|
||||
export function folderPathsForTarget(folderPath: string): string[] {
|
||||
const normalized = normalizeVaultPath(folderPath);
|
||||
if (!normalized) return [];
|
||||
const parts = normalized.split('/');
|
||||
return parts.map((_, idx) => parts.slice(0, idx + 1).join('/'));
|
||||
}
|
||||
|
||||
export async function ensureVaultFolder(app, folderPath) {
|
||||
export async function ensureVaultFolder(app: App, folderPath: string) {
|
||||
for (const folder of folderPathsForTarget(folderPath)) {
|
||||
if (app.vault.getAbstractFileByPath(folder)) continue;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue