mirror of
https://github.com/lostpaul/obsidian-folder-overview.git
synced 2026-07-22 05:35:07 +00:00
Fix build issues
This commit is contained in:
parent
2bc9795b1f
commit
f047859cc9
12 changed files with 967 additions and 2350 deletions
|
|
@ -29,8 +29,7 @@ export function registerOverviewCommands(plugin: FolderOverviewPlugin | FolderNo
|
|||
});
|
||||
|
||||
plugin.registerEvent(
|
||||
// eslint-disable-next-line max-len
|
||||
plugin.app.workspace.on('editor-menu', (menu: Menu, editor: Editor, _view: MarkdownView) => {
|
||||
(plugin.app.workspace as any).on('editor-menu', (menu: Menu, editor: Editor, _view: MarkdownView) => {
|
||||
const { line } = editor.getCursor();
|
||||
const lineText = editor.getLine(line);
|
||||
if (lineText.trim() === '' || lineText.trim() === '>') {
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@ export class FolderOverview {
|
|||
plugin: FolderOverviewPlugin | FolderNotesPlugin;
|
||||
ctx: MarkdownPostProcessorContext;
|
||||
source: string;
|
||||
folderName: string | null;
|
||||
folderName: string | undefined;
|
||||
el: HTMLElement;
|
||||
pathBlacklist: string[] = [];
|
||||
folders: TFolder[] = [];
|
||||
sourceFolder: TFolder | undefined | null;
|
||||
root: HTMLElement;
|
||||
listEl: HTMLUListElement;
|
||||
root: HTMLElement | undefined;
|
||||
listEl: HTMLUListElement | undefined;
|
||||
defaultSettings: defaultOverviewSettings;
|
||||
sourceFile: TFile | undefined;
|
||||
counter = 0;
|
||||
|
|
@ -156,7 +156,7 @@ export class FolderOverview {
|
|||
|
||||
await this.renderTitle(
|
||||
this.sourceFolder, sourceFolderPath,
|
||||
this.sourceFile as TFile, titleEl,
|
||||
this.sourceFile, titleEl,
|
||||
);
|
||||
|
||||
if (!this.validateSourceFolder(this.sourceFolder, sourceFolderPath)) {
|
||||
|
|
@ -317,14 +317,14 @@ export class FolderOverview {
|
|||
|
||||
private handleLinkList(files: TAbstractFile[]): void {
|
||||
if (this.yaml.useActualLinks) {
|
||||
if (this.sourceFile) {
|
||||
setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
if (this.sourceFile instanceof TFile) {
|
||||
updateLinkList(
|
||||
files, this.plugin, this.yaml,
|
||||
this.pathBlacklist, this.sourceFile as TFile,
|
||||
this.pathBlacklist, this.sourceFile,
|
||||
);
|
||||
}, this.LINK_LIST_UPDATE_DELAY_MS);
|
||||
}
|
||||
}
|
||||
}, this.LINK_LIST_UPDATE_DELAY_MS);
|
||||
} else {
|
||||
removeLinkList(this.plugin, this.sourceFile, this.yaml);
|
||||
}
|
||||
|
|
@ -557,6 +557,7 @@ export class FolderOverview {
|
|||
|
||||
getElFromOverview(path: string): HTMLElement | null {
|
||||
const selector = `[data-path='${CSS.escape(path)}']`;
|
||||
if (!this.listEl) return null;
|
||||
const el = this.listEl.querySelector(selector) as HTMLElement | null;
|
||||
return el;
|
||||
}
|
||||
|
|
@ -711,7 +712,7 @@ export function sortFiles(
|
|||
}
|
||||
|
||||
if (a_IsFile && b_IsFile) {
|
||||
return compareFiles(a as TFile, b as TFile);
|
||||
return compareFiles(a, b);
|
||||
}
|
||||
|
||||
return EQUAL;
|
||||
|
|
|
|||
16
src/main.ts
16
src/main.ts
|
|
@ -11,23 +11,21 @@ import { FolderOverview, type defaultOverviewSettings } from './FolderOverview';
|
|||
import { DEFAULT_SETTINGS, SettingsTab, type defaultSettings } from './settings';
|
||||
import { registerOverviewCommands } from './Commands';
|
||||
import { FolderOverviewSettings } from './modals/Settings';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import { FrontMatterTitlePluginHandler } from './utils/FmtpHandler';
|
||||
import { updateAllOverviews } from './utils/functions';
|
||||
import { FvIndexDB } from './utils/IndexDB';
|
||||
|
||||
export default class FolderOverviewPlugin extends Plugin {
|
||||
settings: defaultSettings;
|
||||
settingsTab: SettingsTab;
|
||||
fmtpHandler: FrontMatterTitlePluginHandler;
|
||||
fvIndexDB: FvIndexDB;
|
||||
settings: defaultSettings = DEFAULT_SETTINGS;
|
||||
settingsTab: SettingsTab = new SettingsTab(this);
|
||||
fmtpHandler: FrontMatterTitlePluginHandler | undefined;
|
||||
fvIndexDB: FvIndexDB = new FvIndexDB(this);
|
||||
async onload(): Promise<void> {
|
||||
await this.loadSettings();
|
||||
this.settingsTab = new SettingsTab(this);
|
||||
this.addSettingTab(this.settingsTab);
|
||||
this.settingsTab.display();
|
||||
registerOverviewCommands(this);
|
||||
this.fvIndexDB = new FvIndexDB(this);
|
||||
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
this.registerView(FOLDER_OVERVIEW_VIEW, (leaf: WorkspaceLeaf) => {
|
||||
|
|
@ -57,7 +55,7 @@ export default class FolderOverviewPlugin extends Plugin {
|
|||
this.handleOverviewBlock(source, el, ctx);
|
||||
},
|
||||
);
|
||||
console.log('loading Folder Overview plugin');
|
||||
console.debug('loading Folder Overview plugin');
|
||||
}
|
||||
|
||||
handleVaultChange(): void {
|
||||
|
|
@ -110,7 +108,7 @@ export default class FolderOverviewPlugin extends Plugin {
|
|||
}
|
||||
|
||||
async onunload(): Promise<void> {
|
||||
console.log('Unloading Folder Overview plugin');
|
||||
console.debug('Unloading Folder Overview plugin');
|
||||
}
|
||||
|
||||
async loadSettings(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||
|
||||
constructor(plugin: FolderOverviewPlugin) {
|
||||
super(plugin.app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
|
|
@ -248,7 +249,6 @@ export async function createOverviewSettings(
|
|||
'Find more information about the title in the documentation. ' +
|
||||
'There is also a list of variables you can use',
|
||||
href:
|
||||
// eslint-disable-next-line max-len
|
||||
'https://lostpaul.github.io/obsidian-folder-notes/Folder%20overview/#title',
|
||||
});
|
||||
link.target = '_blank';
|
||||
|
|
@ -308,7 +308,6 @@ export async function createOverviewSettings(
|
|||
const link = frag.createEl('a', {
|
||||
text: 'Find more information about this setting in the documentation.',
|
||||
href:
|
||||
// eslint-disable-next-line max-len
|
||||
'https://lostpaul.github.io/obsidian-folder-notes/Folder%20overview/#folder-path',
|
||||
});
|
||||
link.target = '_blank';
|
||||
|
|
@ -377,6 +376,7 @@ export async function createOverviewSettings(
|
|||
createOrReplaceSetting(contentEl, 'use-wikilinks', changedSection, (settingEl) => {
|
||||
new Setting(settingEl)
|
||||
.setName('Use wikilinks')
|
||||
// eslint-disable-next-line max-len
|
||||
.setDesc('Choose if the links in the link list should be in wikilink format or markdown link format (e.g., [[link]] vs [link](url)).')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
|
|
@ -458,8 +458,8 @@ export async function createOverviewSettings(
|
|||
.addOption('list', 'List')
|
||||
.addOption('explorer', 'Explorer')
|
||||
.setValue(yaml?.style || 'list')
|
||||
.onChange(async (value: 'list') => {
|
||||
yaml.style = value;
|
||||
.onChange((value: string) => {
|
||||
yaml.style = value as 'list' | 'explorer';
|
||||
updateSettings(
|
||||
contentEl, yaml, plugin, false,
|
||||
defaultSettings, el, ctx, file,
|
||||
|
|
@ -614,8 +614,8 @@ export async function createOverviewSettings(
|
|||
.addOption('created', 'Created')
|
||||
.addOption('modified', 'Modified')
|
||||
.setValue(yaml?.sortBy || 'name')
|
||||
.onChange(async (value: 'name' | 'created' | 'modified') => {
|
||||
yaml.sortBy = value;
|
||||
.onChange(async (value: string) => {
|
||||
yaml.sortBy = value as 'name' | 'created' | 'modified';
|
||||
updateSettings(
|
||||
contentEl, yaml, plugin, false,
|
||||
defaultSettings, el, ctx, file,
|
||||
|
|
@ -675,7 +675,6 @@ export async function createOverviewSettings(
|
|||
changedSection,
|
||||
(settingEl) => {
|
||||
new Setting(settingEl)
|
||||
// eslint-disable-next-line max-len
|
||||
.setName('Only show empty folders which are on the first level of the folder overview')
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class CardsOverview {
|
|||
this.plugin = folderOverview.plugin;
|
||||
this.folderOverview = folderOverview;
|
||||
this.yaml = folderOverview.yaml;
|
||||
this.root = folderOverview.root;
|
||||
this.root = folderOverview.root!;
|
||||
this.ctx = folderOverview.ctx;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,13 @@ export class FileExplorerOverview {
|
|||
|
||||
async renderFileExplorer(): Promise<void> {
|
||||
this.disconnectListeners();
|
||||
const plugin = this.plugin;
|
||||
const ctx = this.folderOverview.ctx;
|
||||
const root = this.folderOverview.root;
|
||||
const yaml = this.folderOverview.yaml;
|
||||
const folderOverview = this.folderOverview;
|
||||
const { plugin: plugin, ctx, root, yaml, folderOverview } = {
|
||||
plugin: this.plugin,
|
||||
ctx: this.folderOverview.ctx,
|
||||
root: this.folderOverview.root,
|
||||
yaml: this.folderOverview.yaml,
|
||||
folderOverview: this.folderOverview,
|
||||
};
|
||||
let folder: HTMLElement | null = null;
|
||||
if (plugin instanceof FolderNotesPlugin) {
|
||||
folder = getFileExplorerElement(yaml.folderPath, plugin);
|
||||
|
|
@ -78,7 +80,7 @@ export class FileExplorerOverview {
|
|||
const sourceFolderPath = tFolder?.path || '';
|
||||
|
||||
folderElement = document.querySelectorAll('.nav-files-container')[0] as HTMLElement;
|
||||
if (!folderElement) {
|
||||
if (!folderElement && root) {
|
||||
folderElement = root.createDiv({
|
||||
cls: 'nav-files-container',
|
||||
});
|
||||
|
|
@ -166,12 +168,12 @@ export class FileExplorerOverview {
|
|||
folderOverview.yaml.depth,
|
||||
folderOverview.pathBlacklist,
|
||||
folderOverview.yaml,
|
||||
folderOverview.sourceFile
|
||||
folderOverview.sourceFile,
|
||||
);
|
||||
const sortedFiles = sortFiles(
|
||||
(allFiles ?? []).filter((file): file is TAbstractFile => file !== null),
|
||||
folderOverview.yaml,
|
||||
folderOverview.plugin
|
||||
folderOverview.plugin,
|
||||
);
|
||||
|
||||
const folders = sortedFiles.filter((child) => child instanceof TFolder);
|
||||
|
|
@ -430,9 +432,13 @@ export class FileExplorerOverview {
|
|||
folderTitle.draggable = true;
|
||||
folderTitle.addEventListener('dragstart', (e) => {
|
||||
const { dragManager } = this.plugin.app;
|
||||
const dragData = dragManager.dragFolder(e, child);
|
||||
dragManager.onDragStart(e, dragData);
|
||||
folderTitle?.classList.add('is-being-dragged');
|
||||
if (dragManager && typeof dragManager.dragFolder === 'function') {
|
||||
const dragData = dragManager.dragFolder(e, child);
|
||||
if (typeof dragManager.onDragStart === 'function') {
|
||||
dragManager.onDragStart(e, dragData);
|
||||
}
|
||||
folderTitle?.classList.add('is-being-dragged');
|
||||
}
|
||||
});
|
||||
|
||||
folderTitle.addEventListener('dragend', () => {
|
||||
|
|
@ -491,10 +497,14 @@ export class FileExplorerOverview {
|
|||
if (yaml.allowDragAndDrop) {
|
||||
fileTitle.draggable = true;
|
||||
fileTitle.addEventListener('dragstart', (e) => {
|
||||
const dragManager = plugin.app.dragManager;
|
||||
const dragData = dragManager.dragFile(e, child);
|
||||
dragManager.onDragStart(e, dragData);
|
||||
fileTitle.classList.add('is-being-dragged');
|
||||
const { dragManager } = plugin.app;
|
||||
if (dragManager && typeof dragManager.dragFile === 'function') {
|
||||
const dragData = dragManager.dragFile(e, child);
|
||||
if (typeof dragManager.onDragStart === 'function') {
|
||||
dragManager.onDragStart(e, dragData);
|
||||
}
|
||||
fileTitle.classList.add('is-being-dragged');
|
||||
}
|
||||
});
|
||||
|
||||
fileTitle.addEventListener('dragend', () => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
type FolderOverview, type defaultOverviewSettings,
|
||||
} from '../FolderOverview';
|
||||
import { getFolderPathFromString } from '../../../functions/utils';
|
||||
import FolderOverviewPlugin from '../main';
|
||||
import type FolderOverviewPlugin from '../main';
|
||||
import FolderNotesPlugin from '../../../main';
|
||||
|
||||
export async function renderListOverview(
|
||||
|
|
@ -43,6 +43,7 @@ export async function renderListOverview(
|
|||
files.filter((f) => f instanceof TFolder), folderOverview.yaml, plugin,
|
||||
);
|
||||
files = sortFiles(files.filter((f) => f instanceof TFile), folderOverview.yaml, plugin);
|
||||
if (!ul) { return; }
|
||||
folders.forEach(async (file) => {
|
||||
if (file instanceof TFolder) {
|
||||
if (yaml.includeTypes.includes('folder')) {
|
||||
|
|
@ -94,7 +95,7 @@ function debounce(func: Function, wait: number) {
|
|||
let timeout: number | undefined;
|
||||
return (...args: unknown[]): void => {
|
||||
clearTimeout(timeout);
|
||||
timeout = window.setTimeout(() => func.apply(this, args), wait);
|
||||
timeout = window.setTimeout(() => func(...args), wait);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -180,13 +181,13 @@ async function goThroughFolders(
|
|||
const files = sortFiles(
|
||||
allFiles.filter((file): file is TFile => !(file instanceof TFolder) && file !== null),
|
||||
yaml,
|
||||
plugin
|
||||
plugin,
|
||||
);
|
||||
|
||||
const folders = sortFiles(
|
||||
allFiles.filter((file): file is TFolder => (file instanceof TFolder) && file !== null),
|
||||
yaml,
|
||||
plugin
|
||||
plugin,
|
||||
);
|
||||
const ul = list.createEl('ul', { cls: 'folder-overview-list' });
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import type { App, TFile, TFolder } from 'obsidian';
|
|||
import type FolderOverviewPlugin from '../main';
|
||||
export class FrontMatterTitlePluginHandler {
|
||||
plugin: FolderOverviewPlugin;
|
||||
app: App;
|
||||
app!: App;
|
||||
api: ApiInterface | null = null;
|
||||
deffer: DeferInterface | null = null;
|
||||
modifiedFolders: Map<string, TFolder> = new Map();
|
||||
eventRef: ListenerRef<'manager:update'>;
|
||||
dispatcher: EventDispatcherInterface<Events>;
|
||||
eventRef: ListenerRef<'manager:update'> | null = null;
|
||||
dispatcher: EventDispatcherInterface<Events> | null = null;
|
||||
constructor(plugin: FolderOverviewPlugin) {
|
||||
this.plugin = plugin;
|
||||
this.app = plugin.app;
|
||||
|
|
@ -40,7 +40,7 @@ export class FrontMatterTitlePluginHandler {
|
|||
|
||||
deleteEvent(): void {
|
||||
if (this.eventRef) {
|
||||
this.dispatcher.removeListener(this.eventRef);
|
||||
this.dispatcher?.removeListener(this.eventRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@ export class ListComponent {
|
|||
emitter: CustomEventEmitter;
|
||||
containerEl: HTMLElement;
|
||||
controlEl: HTMLElement;
|
||||
emptyStateEl: HTMLElement;
|
||||
emptyStateEl: HTMLElement | undefined;
|
||||
listEl: HTMLElement;
|
||||
values: string[];
|
||||
defaultValues: string[];
|
||||
constructor(containerEl: HTMLElement, values: string[] = [], defaultValues: string[] = []) {
|
||||
this.values = [];
|
||||
this.emitter = new CustomEventEmitter();
|
||||
this.containerEl = containerEl;
|
||||
this.controlEl = containerEl.querySelector('.setting-item-control') || containerEl;
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ export function getFolderPathFromString(path: string): string {
|
|||
const folderPath = path.substring(0, subString);
|
||||
if (folderPath === '') {
|
||||
return '/';
|
||||
} else {
|
||||
return folderPath;
|
||||
}
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
const CODE_BLOCK_END_NOT_FOUND = -1;
|
||||
|
|
@ -60,12 +59,12 @@ export async function updateAllOverviews(
|
|||
return;
|
||||
}
|
||||
|
||||
if (!hasOverviewYaml(this, file)) {
|
||||
if (!hasOverviewYaml(plugin, file)) {
|
||||
plugin.fvIndexDB.removeNote(file.path);
|
||||
return;
|
||||
}
|
||||
|
||||
const overviews = await getOverviews(this, file);
|
||||
const overviews = await getOverviews(plugin, file);
|
||||
overviews.forEach(async (overview) => {
|
||||
if (!overview.useActualLinks) return;
|
||||
let files: TAbstractFile[] = [];
|
||||
|
|
@ -74,7 +73,7 @@ export async function updateAllOverviews(
|
|||
sourceFolderPath = '/';
|
||||
}
|
||||
|
||||
const sourceFolder = this.app.vault.getAbstractFileByPath(sourceFolderPath);
|
||||
const sourceFolder = plugin.app.vault.getAbstractFileByPath(sourceFolderPath);
|
||||
if (!(sourceFolder instanceof TFolder) && sourceFolderPath !== '/') { return; }
|
||||
|
||||
if (sourceFolder?.path === '/') {
|
||||
|
|
@ -95,7 +94,7 @@ export async function updateAllOverviews(
|
|||
files = getAllFiles(files, sourceFolderPath, overview.depth);
|
||||
const filteredFiles = await filterFiles(
|
||||
files,
|
||||
this,
|
||||
plugin,
|
||||
sourceFolderPath,
|
||||
overview.depth,
|
||||
[],
|
||||
|
|
@ -109,9 +108,9 @@ export async function updateAllOverviews(
|
|||
files = getAllFiles(files, sourceFolderPath, overview.depth);
|
||||
}
|
||||
|
||||
files = sortFiles(files, overview, this);
|
||||
files = sortFiles(files, overview, plugin);
|
||||
|
||||
updateLinkList(files, this, overview, [], file);
|
||||
updateLinkList(files, plugin, overview, [], file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ import { parseOverviewTitle } from './utils/functions';
|
|||
|
||||
export class FolderOverviewView extends ItemView {
|
||||
plugin: FolderOverviewPlugin | FolderNotesPlugin;
|
||||
activeFile: TFile | null;
|
||||
overviewId: string | null;
|
||||
activeFile: TFile | undefined | null;
|
||||
overviewId: string | undefined;
|
||||
yaml: defaultOverviewSettings;
|
||||
defaultSettings: defaultOverviewSettings;
|
||||
contentEl: HTMLElement = this.containerEl.children[1] as HTMLElement;
|
||||
changedSection: string | null | undefined;
|
||||
modal: FolderOverviewSettings;
|
||||
modal: FolderOverviewSettings | undefined;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, plugin: FolderOverviewPlugin | FolderNotesPlugin) {
|
||||
super(leaf);
|
||||
|
|
@ -33,7 +33,10 @@ export class FolderOverviewView extends ItemView {
|
|||
this.defaultSettings = plugin.settings.defaultOverviewSettings;
|
||||
} else if (plugin instanceof FolderNotesPlugin) {
|
||||
this.defaultSettings = plugin.settings.defaultOverview;
|
||||
} else {
|
||||
throw new Error('Plugin must be an instance of FolderOverviewPlugin or FolderNotesPlugin');
|
||||
}
|
||||
this.yaml = this.defaultSettings;
|
||||
|
||||
this.registerEvent(
|
||||
this.plugin.app.workspace.on('file-open', (file) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue