From a59c79b65a8f4742516e2a5b95a158678b286b73 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Tue, 30 Nov 2021 08:44:37 +0200 Subject: [PATCH] feat(DownView): :sparkles: New view! Show all paths going down the child tree. Update on active-leaf-change, press `freeze` to freeze the current view --- src/Components/Down.svelte | 105 +++++++++++++++++++++++++++++++++++++ src/DownView.ts | 49 +++++++++++++++++ src/constants.ts | 3 ++ src/interfaces.ts | 3 +- 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/Components/Down.svelte create mode 100644 src/DownView.ts diff --git a/src/Components/Down.svelte b/src/Components/Down.svelte new file mode 100644 index 00000000..f5a4b11f --- /dev/null +++ b/src/Components/Down.svelte @@ -0,0 +1,105 @@ + + +
+ { + frozen = !frozen; + if (!frozen) basename = plugin.app.workspace.getActiveFile().basename; + }} + > + {#if frozen} + + {:else} + + {/if} + + +
+ +{#each lines as line} + {#if line.length > 1} +
+
{line[0] + "- "}
+ await openOrSwitch(plugin.app, line[1], e)} + on:mouseover={(e) => hoverPreview(e, view, line[1])} + > + + {line[1]} + +
+ {/if} +{/each} + + diff --git a/src/DownView.ts b/src/DownView.ts new file mode 100644 index 00000000..4bfbadd6 --- /dev/null +++ b/src/DownView.ts @@ -0,0 +1,49 @@ +import { ItemView, WorkspaceLeaf } from "obsidian"; +import { DOWN_VIEW } from "./constants"; +import type BCPlugin from "./main"; +import Down from "./Components/Down.svelte"; +import { addFeatherIcon } from "obsidian-community-lib"; + +export default class DownView extends ItemView { + private plugin: BCPlugin; + private view: Down; + + constructor(leaf: WorkspaceLeaf, plugin: BCPlugin) { + super(leaf); + this.plugin = plugin; + } + + async onload(): Promise { + super.onload(); + this.app.workspace.onLayoutReady(async () => { + await this.draw(); + }); + } + + getViewType() { + return DOWN_VIEW; + } + getDisplayText() { + return "Breadcrumbs Down"; + } + + icon = addFeatherIcon("corner-right-down") as string; + + async onOpen(): Promise {} + + onClose(): Promise { + if (this.view) { + this.view.$destroy(); + } + return Promise.resolve(); + } + + async draw(): Promise { + this.contentEl.empty(); + + this.view = new Down({ + target: this.contentEl, + props: { plugin: this.plugin, view: this }, + }); + } +} diff --git a/src/constants.ts b/src/constants.ts index 7c6d16dd..2dc4d8e0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,4 @@ +import DownView from "./DownView"; import DucksView from "./DucksView"; import type { BCSettings, @@ -13,6 +14,7 @@ import StatsView from "./StatsView"; export const MATRIX_VIEW = "BC-matrix"; export const STATS_VIEW = "BC-stats"; export const DUCK_VIEW = "BC-ducks"; +export const DOWN_VIEW = "BC-down"; export const VIEWS: ViewInfo[] = [ { @@ -28,6 +30,7 @@ export const VIEWS: ViewInfo[] = [ openOnLoad: true, }, { plain: "Duck", type: DUCK_VIEW, constructor: DucksView, openOnLoad: false }, + { plain: "Down", type: DOWN_VIEW, constructor: DownView, openOnLoad: true }, ]; export const TRAIL_ICON = "BC-trail-icon"; diff --git a/src/interfaces.ts b/src/interfaces.ts index e38684a8..f1e99a7a 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,6 +1,7 @@ import type { MultiGraph } from "graphology"; import type { LogLevel } from "loglevel"; import type { Constructor, FrontMatterCache, Pos, TFile } from "obsidian"; +import type DownView from "./DownView"; import type { DIRECTIONS } from "./constants"; import type DucksView from "./DucksView"; import type MatrixView from "./MatrixView"; @@ -79,7 +80,7 @@ export type UserHier = { [dir in Directions]: string[]; }; -export type MyView = MatrixView | DucksView | StatsView; +export type MyView = MatrixView | DucksView | StatsView | DownView; export type ViewInfo = { plain: string; type: string;