diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index dd8de86..e9623e9 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -1,21 +1,23 @@ name: CI -on: push +on: + push: + pull_request: jobs: eslint: runs-on: ubuntu-latest steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Install modules - run: npm i + - name: Install modules + run: npm i - - name: Run build - run: npm run build + - name: Run build + run: npm run build - - name: Check TypeScript - run: npx tsc --noEmit + - name: Check TypeScript + run: npx tsc --noEmit - - name: Run ESLint - run: npx eslint ./src/ + - name: Run ESLint + run: npx eslint ./src/ diff --git a/src/main.ts b/src/main.ts index bb077eb..aefd95e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,9 +7,13 @@ import {FolderNoteModule} from "./modules/FolderNoteModule"; // Remember to rename these classes and interfaces! export default class FolderIndexPlugin extends Plugin { + // @ts-ignore settings: PluginSetting; + // @ts-ignore graphManipulator: GraphManipulatorModule | null; + // @ts-ignore folderNodeModule: FolderNoteModule; + // @ts-ignore eventManager: EventEmitter oldGraphSetting = false static PLUGIN: FolderIndexPlugin; @@ -38,7 +42,7 @@ export default class FolderIndexPlugin extends Plugin { this.registerEvent(this.app.workspace.on("layout-change", this.onLayoutChange.bind(this))) this.eventManager.on("settingsUpdate", this.onSettingsUpdate.bind(this)) - this.registerMarkdownCodeBlockProcessor("folder-index-content", (source, el, ctx) => { + this.registerMarkdownCodeBlockProcessor("folder-index-content", (_source, el, ctx) => { ctx.addChild(new IndexContentProcessorModule(this.app, this, ctx.sourcePath, el)) }) @@ -53,7 +57,8 @@ export default class FolderIndexPlugin extends Plugin { if (this.settings.graphOverwrite) { this.graphManipulator = new GraphManipulatorModule(this.app, this) } else { - this.graphManipulator.unload() + if (this.graphManipulator) + this.graphManipulator.unload() } this.oldGraphSetting = this.settings.graphOverwrite } diff --git a/src/models/PluginSettingsTab.ts b/src/models/PluginSettingsTab.ts index 448526d..eeffc84 100644 --- a/src/models/PluginSettingsTab.ts +++ b/src/models/PluginSettingsTab.ts @@ -80,7 +80,7 @@ export class PluginSettingsTab extends PluginSettingTab { await this.plugin.saveSettings() })) - let textFeld: TextAreaComponent = null; + let textFeld: TextAreaComponent | null = null; new Setting(containerEl) .setName("Initial Content") .setDesc("Set the initial content for new folder indexes.") @@ -90,7 +90,7 @@ export class PluginSettingsTab extends PluginSettingTab { .setTooltip("Reset to default") .onClick(async () => { this.plugin.settings.indexFileInitText = DEFAULT_SETTINGS.indexFileInitText - textFeld.setValue(this.plugin.settings.indexFileInitText) + textFeld?.setValue(this.plugin.settings.indexFileInitText) await this.plugin.saveSettings() } )) diff --git a/src/modules/FolderNoteModule.ts b/src/modules/FolderNoteModule.ts index 9429d5d..cf3bc5d 100644 --- a/src/modules/FolderNoteModule.ts +++ b/src/modules/FolderNoteModule.ts @@ -29,21 +29,23 @@ export class FolderNoteModule { // FolderNoteModule.showAllIndexFiles() } + private getTargetFromEvent(event: MouseEvent): HTMLElement | null { if (!(event.target instanceof HTMLElement)) { - return + return null } const target = event.target // @ts-ignore - This is a hack to get the active plugins. + // noinspection JSUnresolvedReference const activePlugins: Set = this.app.plugins.enabledPlugins // Compatibility with https://github.com/ozntel/file-tree-alternative if (activePlugins.has("file-tree-alternative")) { if (target.classList.contains("oz-folder-name")) { - return target.parentElement.parentElement.parentElement + return (target.parentElement?.parentElement?.parentElement) ?? null } if (target.classList.contains("oz-folder-block")) { - return target.parentElement.parentElement + return (target.parentElement?.parentElement) ?? null } } @@ -110,6 +112,8 @@ export class FolderNoteModule { if (this.plugin.settings.autoCreateIndexFile) { const name = path.split(/\//).last() try { + if (!name) + return false const file = await this.app.vault.create(path, this.plugin.settings.indexFileInitText.replace("{{folder}}", name)) new Notice(`Created index file ${file.basename}`) return true @@ -181,7 +185,7 @@ export class FolderNoteModule { if (currentState.state.file == this.previousState.state.file) return; - const currentFile = await this.app.vault.getAbstractFileByPath(currentState.state.file) as TFile + const currentFile = this.app.vault.getAbstractFileByPath(currentState.state.file) as TFile // We did not open an index file, so we need to check if the previous mode was set by this plugin if (!isIndexFile(currentFile.path)) { diff --git a/src/modules/GraphManipulatorModule.ts b/src/modules/GraphManipulatorModule.ts index 0bbf7d7..bc75a5c 100644 --- a/src/modules/GraphManipulatorModule.ts +++ b/src/modules/GraphManipulatorModule.ts @@ -28,6 +28,8 @@ export class GraphManipulatorModule { constructor(private app: App, private plugin: FolderIndexPlugin) { this.app = app this.plugin = plugin + this.graphsLeafs = [] + this.oldGraphOverwrite = this.plugin.settings.graphOverwrite this.load() } @@ -49,7 +51,8 @@ export class GraphManipulatorModule { if (this.plugin.settings.graphOverwrite) { this.render(engine) } else { - engine.oldRender() + if (engine.oldRender) + engine.oldRender() } } // We may need to rerender the graph view, so we do this here. @@ -88,6 +91,7 @@ export class GraphManipulatorModule { const engine = this.getEngine(value) if (engine.oldRender != null) { engine.render = engine.oldRender + // @ts-ignore delete engine.oldRender this.clearGraph(engine) engine.render() @@ -96,7 +100,12 @@ export class GraphManipulatorModule { } render(engine: DataEngine) { - const renderSettings = engine.getOptions() + const renderSettings: { + showOrphans: boolean, + showAttachments: boolean, + showTags: boolean, + hideUnresolved: boolean + } = engine.getOptions() const graph: Graph = {} this.app.vault.getFiles().forEach(async file => { @@ -146,7 +155,7 @@ export class GraphManipulatorModule { } if (cache.frontmatter != null) { const frontMatterTags = parseFrontMatterTags(cache.frontmatter) - if (frontMatterTags != null && renderSettings.showTags == true) { + if (frontMatterTags != null && renderSettings.showTags) { frontMatterTags.forEach(tag => { graph[tag] = { links: {}, @@ -156,7 +165,7 @@ export class GraphManipulatorModule { }) } } - if (cache.tags != null && renderSettings.showTags == true) { + if (cache.tags != null && renderSettings.showTags) { cache.tags.forEach(tag => { // We have to add it, it will not add itself. @@ -187,7 +196,7 @@ export class GraphManipulatorModule { } let type: NodeType = "" - if (this.app.workspace.getActiveFile() != null && this.app.workspace.getActiveFile().path == file.path) { + if (this.app.workspace.getActiveFile() != null && this.app.workspace.getActiveFile()?.path == file.path) { type = "focused" } else if (file.extension != "md") { type = "attachment" @@ -227,10 +236,13 @@ export class GraphManipulatorModule { const fileFilter = engine.fileFilter // eslint-disable-next-line @typescript-eslint/no-explicit-any return !searchQueries || ("" === nodeType ? filePath === engineOptions.localFile || (fileFilter.hasOwnProperty(filePath) ? fileFilter[filePath] : !engine.hasFilter) : "tag" === nodeType ? searchQueries.every((function (e: any) { + + // noinspection JSUnresolvedReference return !!e.color || !!e.query.matchTag(filePath) } // eslint-disable-next-line @typescript-eslint/no-explicit-any )) : "attachment" !== nodeType || searchQueries.every((function (e: any) { + // noinspection JSUnresolvedReference return !!e.color || !!e.query.matchFilepath(filePath) } ))) diff --git a/src/modules/IndexContentProcessorModule.ts b/src/modules/IndexContentProcessorModule.ts index 60d13e2..88698a2 100644 --- a/src/modules/IndexContentProcessorModule.ts +++ b/src/modules/IndexContentProcessorModule.ts @@ -42,7 +42,7 @@ export class IndexContentProcessorModule extends MarkdownRenderChild { private async render() { this.container.empty() - const folder: TAbstractFile = this.app.vault.getAbstractFileByPath(this.filePath) + const folder: TAbstractFile | null = this.app.vault.getAbstractFileByPath(this.filePath) if (folder instanceof TFile) { const files = folder.parent.children const renderer = new MarkdownTextRenderer(this.plugin, this.app) diff --git a/src/types/MarkdownTextRenderer.ts b/src/types/MarkdownTextRenderer.ts index 875f3b1..7541bb5 100644 --- a/src/types/MarkdownTextRenderer.ts +++ b/src/types/MarkdownTextRenderer.ts @@ -57,7 +57,7 @@ export class MarkdownTextRenderer { let markdownText = "" markdownText += this.buildMarkdownLinkString(this.getTitleFromPath(file.path), encodeURI(file.path), indentLevel, isFolder) - const headers: HeadingCache[] | null = this.app.metadataCache.getFileCache(file)?.headings + const headers: HeadingCache[] | null = this.app.metadataCache.getFileCache(file)?.headings ?? [] if (headers && !this.plugin.settings.disableHeadlines) { const headerTree = this.buildHeaderTree(headers) if (this.plugin.settings.headlineLimit !== 0) { diff --git a/tsconfig.json b/tsconfig.json index 1383e2f..d4d7f15 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,24 @@ { - "compilerOptions": { - "baseUrl": ".", - "inlineSourceMap": true, - "inlineSources": true, - "module": "ESNext", - "target": "ES6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "isolatedModules": true, - "lib": [ - "DOM", - "ES5", - "ES6", - "ES7" - ] - }, - "include": [ - "**/*.ts" - ] + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "strict": true, + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "lib": [ + "DOM", + "ES5", + "ES6", + "ES7" + ] + }, + "include": [ + "**/*.ts" + ] }