Skip to content

Commit

Permalink
refactor: Moved code block querying out
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Jan 12, 2022
1 parent a709728 commit 465103c
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 506 deletions.
58 changes: 6 additions & 52 deletions src/Components/CBTree.svelte
Original file line number Diff line number Diff line change
@@ -1,70 +1,24 @@
<script lang="ts">
import { info } from "loglevel";
import { MarkdownPostProcessorContext, Notice } from "obsidian";
import { isInVault, openOrSwitch } from "obsidian-community-lib/dist/utils";
import {
dfsAllPaths,
getOppDir,
getReflexiveClosure,
getSubInDirs,
} from "../graphUtils";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { dropDendron, dropFolder } from "../sharedFunctions";
import RenderMarkdown from "./RenderMarkdown.svelte";
export let plugin: BCPlugin;
export let ctx: MarkdownPostProcessorContext;
export let el: HTMLElement;
export let dir: Directions;
export let fields: string[];
export let title: string;
export let depth: string[];
export let flat: string;
export let content: string;
export let from: string;
export let implied: string;
export let index: any;
export let froms: string[];
export let min: number;
export let max: number;
export let basename: string;
const { settings, app, mainG } = plugin;
const { sourcePath } = ctx;
const currFile = app.metadataCache.getFirstLinkpathDest(sourcePath, "");
const { userHiers } = settings;
const { basename } = currFile;
let min = 1,
max = Infinity;
if (depth !== undefined) {
const minNum = parseInt(depth[0]);
if (!isNaN(minNum)) min = minNum;
const maxNum = parseInt(depth[1]);
if (!isNaN(maxNum)) max = maxNum;
}
let froms = undefined;
if (from !== undefined) {
try {
const api = app.plugins.plugins.dataview?.api;
if (api) {
const pages = api.pagePaths(from)?.values as string[];
froms = pages.map(dropFolder);
} else new Notice("Dataview must be enabled for `from` to work.");
} catch (e) {
new Notice(`The query "${from}" failed.`);
}
}
const oppDir = getOppDir(dir);
const sub =
implied === "false"
? getSubInDirs(mainG, dir)
: getSubInDirs(mainG, dir, oppDir);
const closed = getReflexiveClosure(sub, userHiers);
const subClosed = getSubInDirs(closed, dir);
const allPaths = dfsAllPaths(subClosed, basename);
const index = plugin.createIndex(allPaths, false);
info({ allPaths, index });
const {settings, app} = plugin;
const lines = index
.split("\n")
Expand Down
5 changes: 5 additions & 0 deletions src/Visualisations/CBJuggl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {ParsedCodeblock} from "../interfaces";

export function createdJugglCB(target: HTMLElement, args: ParsedCodeblock) {

}
53 changes: 50 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "obsidian-community-lib/dist/utils";
import { Debugger } from "src/Debugger";
import { BCSettingTab } from "./BreadcrumbsSettingTab";
import CBTree from "./Components/CBTree.svelte";
import CBTree from "./Components/CBTree.svelte";
import NextPrev from "./Components/NextPrev.svelte";
import TrailGrid from "./Components/TrailGrid.svelte";
import TrailPath from "./Components/TrailPath.svelte";
Expand Down Expand Up @@ -87,7 +87,7 @@ import type {
} from "./interfaces";
import MatrixView from "./MatrixView";
import {
createOrUpdateYaml,
createOrUpdateYaml, dropFolder,
dropHash,
dropWikilinks,
fallbackOppField,
Expand All @@ -105,6 +105,7 @@ import {
import StatsView from "./StatsView";
import TreeView from "./TreeView";
import { VisModal } from "./VisModal";
import {createdJugglCB} from "./Visualisations/CBJuggl";

export default class BCPlugin extends Plugin {
settings: BCSettings;
Expand Down Expand Up @@ -605,19 +606,65 @@ export default class BCPlugin extends Plugin {
el.innerHTML = err;
return;
}
let min = 1,
max = Infinity;
let {depth, dir, from, implied} = parsedSource;
if (depth !== undefined) {
const minNum = parseInt(depth[0]);
if (!isNaN(minNum)) min = minNum;
const maxNum = parseInt(depth[1]);
if (!isNaN(maxNum)) max = maxNum;
}

const currFile = this.app.metadataCache.getFirstLinkpathDest(ctx.sourcePath, "");
const { userHiers } = settings;
const { basename } = currFile;

let froms = undefined;
if (from !== undefined) {
try {
const api = this.app.plugins.plugins.dataview?.api;
if (api) {
const pages = api.pagePaths(from)?.values as string[];
froms = pages.map(dropFolder);
} else new Notice("Dataview must be enabled for `from` to work.");
} catch (e) {
new Notice(`The query "${from}" failed.`);
}
}

const oppDir = getOppDir(dir);
const sub =
implied === "false"
? getSubInDirs(this.mainG, dir)
: getSubInDirs(this.mainG, dir, oppDir);
const closed = getReflexiveClosure(sub, userHiers);
const subClosed = getSubInDirs(closed, dir);

const allPaths = dfsAllPaths(subClosed, basename);
const index = this.createIndex(allPaths, false);
info({ allPaths, index });
console.log({allPaths, index})

switch (parsedSource.type) {
case "tree":
new CBTree({
target: el,
props: {
plugin: this,
ctx,
el,
min,
max,
index,
froms,
basename,
...parsedSource,
},
});
break;
case "juggl":
createdJugglCB(el, parsedSource);
break;
}
}
);
Expand Down
Loading

0 comments on commit 465103c

Please sign in to comment.