diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 605964eb..ab205125 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -81,10 +81,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { await plugin.saveSettings(); plugin.refreshIntervalID = window.setInterval(async () => { - if (plugin.trailDiv || plugin.matrixView) { - plugin.currGraphs = await plugin.initGraphs(); - } - if (plugin.trailDiv) { + plugin.currGraphs = await plugin.initGraphs(); + if (plugin.settings.showTrail) { await plugin.drawTrail(); } if (plugin.matrixView) { @@ -149,43 +147,39 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { containerEl.createEl("h3", { text: "Breadcrumb Trail" }); new Setting(containerEl) - .setName("Show Breadcrumb Trail") + .setName("Show Breadcrumbs") .setDesc( "Show a trail of notes leading from your index note down to the current note you are in (if a path exists)" ) .addToggle((toggle) => toggle.setValue(plugin.settings.showTrail).onChange(async (value) => { plugin.settings.showTrail = value; - await plugin.saveSettings(); - if (value) { - plugin.trailDiv = createDiv({ - cls: `breadcrumbs-trail is-readable-line-width${plugin.settings.respectReadableLineLength - ? " markdown-preview-sizer markdown-preview-section" - : "" - }`, - }); - await plugin.drawTrail(); - } else { - plugin.trailDiv.remove(); - } + await plugin.drawTrail(); }) ); + new Setting(containerEl) - .setName("Trail or Table mode") + .setName("Trail or Table or Both") .setDesc( - "Wether to show the regular breadcrumb trails, or a table view. On = Trail, Off = Table" + "Wether to show the regular breadcrumb trails, the table view, neither, or both. 1 = Only Trail, 2 = Only Grid, 3 = Both" ) - .addToggle((toggle) => - toggle - .setValue(plugin.settings.trailOrTable) + .addText((text) => { + text + .setPlaceholder("Index Note") + .setValue(plugin.settings.trailOrTable.toString()) .onChange(async (value) => { - plugin.settings.trailOrTable = value; - await plugin.saveSettings(); - await plugin.drawTrail() - }) - ); + const num = parseInt(value); + if ([1, 2, 3].includes(num)) { + plugin.settings.trailOrTable = num as 1 | 2 | 3; + await plugin.saveSettings(); + await plugin.drawTrail(); + } else { + new Notice("The value has to be 1, 2, or 3") + } + }); + }); new Setting(containerEl) .setName("Index/Home Note(s)") diff --git a/src/interfaces.ts b/src/interfaces.ts index 3726357a..1ceb3223 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -11,7 +11,7 @@ export interface BreadcrumbsSettings { showNameOrType: boolean; showRelationType: boolean; showTrail: boolean; - trailOrTable: boolean; + trailOrTable: 1 | 2 | 3; showAll: boolean; noPathMessage: string; trailSeperator: string; diff --git a/src/main.ts b/src/main.ts index 428bc781..a3debedc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,7 +14,7 @@ import type { neighbourObj } from "src/interfaces"; import MatrixView from "src/MatrixView"; -import { closeImpliedLinks, debug, getFileFrontmatterArr, getNeighbourObjArr, isInVault, openOrSwitch } from "src/sharedFunctions"; +import { closeImpliedLinks, debug, getFileFrontmatterArr, getNeighbourObjArr, isInVault } from "src/sharedFunctions"; import TrailGrid from "./TrailGrid.svelte"; import TrailPath from "./TrailPath.svelte"; @@ -22,15 +22,15 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = { parentFieldName: "parent", siblingFieldName: "sibling", childFieldName: "child", - indexNote: ["Index"], + indexNote: [""], refreshIntervalTime: 0, defaultView: true, showNameOrType: true, showRelationType: true, showTrail: true, - trailOrTable: false, + trailOrTable: 3, showAll: false, - noPathMessage: `No path to index note was found`, + noPathMessage: `This note has no real or implied parents`, trailSeperator: "→", respectReadableLineLength: true, debugMode: false, @@ -211,16 +211,7 @@ export default class BreadcrumbsPlugin extends Plugin { indexNotes.forEach((index) => { let step = index; - // Check if indexNote exists - if ( - !isInVault(this.app, index) - ) { - return [ - `${index} is not a note in your vault. Please change the settings for Index Notes` - ]; - } - // Check if a path even exists - else if (paths[step].distance !== Infinity) { + if (paths[step].distance !== Infinity) { const breadcrumbs: string[] = []; // Walk it until arriving at `from` while (paths[step].distance !== 0) { @@ -247,41 +238,55 @@ export default class BreadcrumbsPlugin extends Plugin { } async drawTrail(): Promise { - const { gParents, gChildren } = this.currGraphs; - const closedParents = closeImpliedLinks(gParents, gChildren) - const sortedTrails = this.getBreadcrumbs(closedParents); - const currFile = this.app.workspace.getActiveFile(); - const settings = this.settings - - // Get the container div of the active note - const previewView = document.querySelector( - "div.mod-active div.view-content div.markdown-preview-view" - ); - previewView.querySelector('div.breadcrumbs-trail')?.remove() - - const trailDiv = createDiv() - previewView.prepend(trailDiv) - - this.visited.push([currFile.path, trailDiv]) + if (this.settings.showTrail) { - trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength - ? " markdown-preview-sizer markdown-preview-section" - : "" - }` + const { gParents, gChildren } = this.currGraphs; + const closedParents = closeImpliedLinks(gParents, gChildren) + const sortedTrails = this.getBreadcrumbs(closedParents); + const currFile = this.app.workspace.getActiveFile(); + const settings = this.settings - previewView.prepend(trailDiv); - - trailDiv.empty(); - if (settings.trailOrTable) { - new TrailPath({ - target: trailDiv, - props: { sortedTrails, app: this.app, settings, currFile } - }) - } else { - new TrailGrid({ - target: trailDiv, - props: { sortedTrails, app: this.app, settings } - }) + // Get the container div of the active note + const previewView = document.querySelector( + "div.mod-active div.view-content div.markdown-preview-view" + ); + previewView.querySelector('div.breadcrumbs-trail')?.remove() + + const trailDiv = createDiv() + previewView.prepend(trailDiv) + + this.visited.push([currFile.path, trailDiv]) + + trailDiv.className = `breadcrumbs-trail is-readable-line-width${settings.respectReadableLineLength + ? " markdown-preview-sizer markdown-preview-section" + : "" + }` + + previewView.prepend(trailDiv); + + trailDiv.empty(); + + + if (settings.trailOrTable === 1) { + new TrailPath({ + target: trailDiv, + props: { sortedTrails, app: this.app, settings, currFile } + }) + } else if (settings.trailOrTable === 2) { + new TrailGrid({ + target: trailDiv, + props: { sortedTrails, app: this.app, settings } + }) + } else { + new TrailPath({ + target: trailDiv, + props: { sortedTrails, app: this.app, settings, currFile } + }); + new TrailGrid({ + target: trailDiv, + props: { sortedTrails, app: this.app, settings } + }) + } } }