Skip to content

Commit

Permalink
fix: Obsidian v0.15+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kometenstaub committed Jun 21, 2022
1 parent 89edd18 commit f245a4b
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 67,428 deletions.
62,549 changes: 0 additions & 62,549 deletions main.js

This file was deleted.

5 changes: 3 additions & 2 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "./Utils/HierUtils";
import { createIndex } from "./Commands/CreateIndex";
import { refreshIndex } from "./refreshIndex";
import {getFile} from "./Utils/ObsidianUtils";

export class BCAPI implements BCAPII {
app: App;
Expand Down Expand Up @@ -47,15 +48,15 @@ export class BCAPI implements BCAPII {
getSubForFields(g, fields);

public dfsAllPaths = (
fromNode = this.app.workspace.getActiveFile()?.basename,
fromNode = getFile()?.basename,
g = this.mainG
) => dfsAllPaths(g, fromNode);

public createIndex = (allPaths: string[][], wikilinks = false) =>
createIndex(allPaths, wikilinks);

public getMatrixNeighbours = (
fromNode = this.app.workspace.getActiveFile()?.basename
fromNode = getFile()?.basename
) => getMatrixNeighbours(this.plugin, fromNode);

public getOppDir = (dir: Directions) => getOppDir(dir);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CreateIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { info } from "loglevel";
import { copy } from "obsidian-community-lib/dist/utils";
import type BCPlugin from "../main";
import { dfsAllPaths, getSinks, getSubInDirs } from "../Utils/graphUtils";
import { makeWiki } from "../Utils/ObsidianUtils";
import {getFile, makeWiki} from "../Utils/ObsidianUtils";

/**
* Returns a copy of `index`, doesn't mutate.
Expand Down Expand Up @@ -80,7 +80,7 @@ export function createIndex(
export async function copyLocalIndex(plugin: BCPlugin) {
const { settings, closedG } = plugin;
const { wikilinkIndex } = settings;
const { basename } = plugin.app.workspace.getActiveFile();
const { basename } = getFile()

const onlyDowns = getSubInDirs(closedG, "down");
const allPaths = dfsAllPaths(onlyDowns, basename);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/WriteBCs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { warn } from "loglevel";
import { Notice, TFile } from "obsidian";
import type BCPlugin from "../main";
import { getOppFields } from "../Utils/HierUtils";
import { changeYaml, splitAtYaml } from "../Utils/ObsidianUtils";
import {changeYaml, getFile, splitAtYaml} from "../Utils/ObsidianUtils";

export async function writeBCToFile(plugin: BCPlugin, currFile?: TFile) {
const { app, settings, mainG } = plugin;
const file = currFile ?? app.workspace.getActiveFile();
const file = currFile ?? getFile();

const { limitWriteBCCheckboxes, writeBCsInline, userHiers } = settings;

Expand Down
3 changes: 2 additions & 1 deletion src/Commands/jumpToFirstDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Notice } from "obsidian";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { getRealnImplied } from "../Utils/graphUtils";
import {getFile} from "../Utils/ObsidianUtils";

export async function jumpToFirstDir(plugin: BCPlugin, dir: Directions) {
const { limitJumpToFirstFields } = plugin.settings;
const file = plugin.app.workspace.getActiveFile();
const file = getFile();
if (!file) {
new Notice("You need to be focussed on a Markdown file");
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/threading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App, normalizePath, Notice, TFile } from "obsidian";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { getFieldInfo, getOppFields } from "../Utils/HierUtils";
import { createOrUpdateYaml, splitAtYaml } from "../Utils/ObsidianUtils";
import {createOrUpdateYaml, getFile, splitAtYaml} from "../Utils/ObsidianUtils";

const resolveThreadingNameTemplate = (
template: string,
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function thread(plugin: BCPlugin, field: string) {
writeBCsInline,
} = settings;

const currFile = app.workspace.getActiveFile();
const currFile = getFile();
if (!currFile) return;

const newFileParent = app.fileManager.getNewFileParent(currFile.path);
Expand Down
7 changes: 4 additions & 3 deletions src/Components/SideTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { dropDendron } from "../Utils/generalUtils";
import { dfsAllPaths, getSubInDirs } from "../Utils/graphUtils";
import type TreeView from "../Views/TreeView";
import {getFile} from "../Utils/ObsidianUtils";
export let plugin: BCPlugin;
export let view: TreeView;
Expand All @@ -23,12 +24,12 @@
let dir: Directions = "down";
let frozen = false;
let { basename } = app.workspace.getActiveFile();
let { basename } = getFile();
plugin.registerEvent(
app.workspace.on("active-leaf-change", () => {
if (frozen) return;
basename = app.workspace.getActiveFile().basename;
basename = getFile()?.basename;
})
);
Expand All @@ -50,7 +51,7 @@
aria-label-position="left"
on:click={() => {
frozen = !frozen;
if (!frozen) basename = app.workspace.getActiveFile().basename;
if (!frozen) basename = getFile()?.basename;
}}
>
{#if frozen}
Expand Down
3 changes: 2 additions & 1 deletion src/Components/VisComp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import { tidyTree } from "../Visualisations/TidyTree";
import { treeMap } from "../Visualisations/TreeMap";
import type { VisModal } from "../Visualisations/VisModal";
import {getFile} from "../Utils/ObsidianUtils";
export let modal: VisModal;
const { app, plugin } = modal;
const { mainG, settings } = plugin;
const { visGraph, visRelation, visClosed, visAll } = settings;
const currFile = app.workspace.getActiveFile();
const currFile = getFile();
const selectors = [
{
Expand Down
12 changes: 10 additions & 2 deletions src/Utils/ObsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import type { MetaeditApi } from "../interfaces";
import type BCPlugin from "../main";
import { splitAndTrim } from "./generalUtils";

export const getFile = (): TFile | null => {
let file = app.workspace.getActiveFile()
if (!file) {
file = app.workspace.lastActiveFile
}
return file;
}

/**
* Get basename from a **Markdown** `path`
* @param {string} path
Expand Down Expand Up @@ -139,7 +147,7 @@ export async function waitForCache(plugin: BCPlugin) {
let basename: string;
while (!basename || !app.plugins.plugins.dataview.api.page(basename)) {
await wait(100);
basename = app?.workspace?.getActiveFile()?.basename;
basename = getFile()?.basename;
}
} else {
await waitForResolvedLinks(app);
Expand All @@ -165,7 +173,7 @@ export function isInsideYaml(app: App): boolean | null {

const { editor } = activeLeaf.view;

const file = workspace.getActiveFile();
const file = getFile();
if (!file) return null;

const { frontmatter } = metadataCache.getFileCache(file);
Expand Down
4 changes: 2 additions & 2 deletions src/Views/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
import type BCPlugin from "../main";
import { splitAndTrim } from "../Utils/generalUtils";
import { getOppDir, getOppFields } from "../Utils/HierUtils";
import { getDVApi, linkClass } from "../Utils/ObsidianUtils";
import {getDVApi, getFile, linkClass} from "../Utils/ObsidianUtils";

export function getMatrixNeighbours(plugin: BCPlugin, currNode: string) {
const { closedG, settings } = plugin;
Expand Down Expand Up @@ -300,7 +300,7 @@ export default class MatrixView extends ItemView {

const { userHiers } = plugin.settings;

const currFile = this.app.workspace.getActiveFile();
const currFile = getFile();
if (!currFile) return;

const hierSquares = this.getHierSquares(userHiers, currFile).filter(
Expand Down
3 changes: 2 additions & 1 deletion src/Visualisations/CirclePacking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { App, TFile } from "obsidian";
import type { AdjListItem, d3Link, d3Node } from "../interfaces";
import { bfsAdjList, dfsFlatAdjList, VisModal } from "./VisModal";
import { openOrSwitch } from "obsidian-community-lib";
import {getFile} from "../Utils/ObsidianUtils";

export const circlePacking = (
graph: Graph,
Expand Down Expand Up @@ -80,7 +81,7 @@ export const circlePacking = (
node.attr("aria-label", (d: AdjListItem) => d.name);

const nodeClick = (event: MouseEvent, dest: string) => {
const currFile = app.workspace.getActiveFile();
const currFile = getFile();
openOrSwitch(app, dest, event);
modal.close();
};
Expand Down
Loading

0 comments on commit f245a4b

Please sign in to comment.