generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DownView): ✨ New view! Show all paths going down the child tree.…
… Update on active-leaf-change, press `freeze` to freeze the current view
- Loading branch information
1 parent
258e0bc
commit a59c79b
Showing
4 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<script lang="ts"> | ||
import { | ||
hoverPreview, | ||
isInVault, | ||
openOrSwitch, | ||
} from "obsidian-community-lib"; | ||
import FaFire from "svelte-icons/fa/FaFire.svelte"; | ||
import FaRegSnowflake from "svelte-icons/fa/FaRegSnowflake.svelte"; | ||
import type DownView from "../DownView"; | ||
import { | ||
dfsAllPaths, | ||
getReflexiveClosure, | ||
getSubInDirs, | ||
} from "../graphUtils"; | ||
import type BCPlugin from "../main"; | ||
export let plugin: BCPlugin; | ||
export let view: DownView; | ||
const { settings } = plugin; | ||
const { userHiers } = settings; | ||
let frozen = false; | ||
let { basename } = plugin.app.workspace.getActiveFile(); | ||
plugin.app.workspace.on("active-leaf-change", () => { | ||
if (frozen) return; | ||
basename = plugin.app.workspace.getActiveFile().basename; | ||
}); | ||
let lines: [string, string][]; | ||
$: { | ||
const { mainG } = plugin; | ||
const upnDown = getSubInDirs(mainG, "up", "down"); | ||
const closed = getReflexiveClosure(upnDown, userHiers); | ||
const down = getSubInDirs(closed, "down"); | ||
const allPaths = dfsAllPaths(down, basename); | ||
const index = plugin.createIndex(allPaths); | ||
console.log({ allPaths, index, down: down.inspect() }); | ||
lines = index.split("\n").map((line) => line.split("- ")) as [ | ||
string, | ||
string | ||
][]; | ||
} | ||
</script> | ||
|
||
<div> | ||
<span | ||
class="icon nav-action-button" | ||
aria-label={frozen ? `Frozen on: ${basename}` : "Unfrozen"} | ||
aria-label-position="left" | ||
on:click={() => { | ||
frozen = !frozen; | ||
if (!frozen) basename = plugin.app.workspace.getActiveFile().basename; | ||
}} | ||
> | ||
{#if frozen} | ||
<FaRegSnowflake /> | ||
{:else} | ||
<FaFire /> | ||
{/if} | ||
</span> | ||
<button | ||
class="icon" | ||
aria-label="Refresh Stats View (also refreshes Breadcrumbs Index)" | ||
on:click={async () => { | ||
await plugin.refreshIndex(); | ||
await view.draw(); | ||
}} | ||
> | ||
↻ | ||
</button> | ||
</div> | ||
|
||
{#each lines as line} | ||
{#if line.length > 1} | ||
<div> | ||
<pre>{line[0] + "- "}</pre> | ||
<span | ||
class="internal-link" | ||
on:click={async (e) => await openOrSwitch(plugin.app, line[1], e)} | ||
on:mouseover={(e) => hoverPreview(e, view, line[1])} | ||
> | ||
<!-- svelte-ignore a11y-missing-attribute --> | ||
<a | ||
class="internal-link {isInVault(plugin.app, line[1]) | ||
? '' | ||
: 'is-unresolved'}">{line[1]}</a | ||
> | ||
</span> | ||
</div> | ||
{/if} | ||
{/each} | ||
|
||
<style> | ||
pre { | ||
display: inline; | ||
} | ||
.is-unresolved { | ||
color: var(--text-muted); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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<void> {} | ||
|
||
onClose(): Promise<void> { | ||
if (this.view) { | ||
this.view.$destroy(); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
async draw(): Promise<void> { | ||
this.contentEl.empty(); | ||
|
||
this.view = new Down({ | ||
target: this.contentEl, | ||
props: { plugin: this.plugin, view: this }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters