Skip to content

Commit

Permalink
feat(API): ✨ Expose more function on API + Add API to global window o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
SkepticMystic committed Feb 12, 2022
1 parent f3e125b commit ad20594
Show file tree
Hide file tree
Showing 6 changed files with 17,064 additions and 17,005 deletions.
33,991 changes: 17,007 additions & 16,984 deletions main.js

Large diffs are not rendered by default.

46 changes: 27 additions & 19 deletions src/API.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
export {};
// import type { MultiGraph } from "graphology";
// import type { App } from "obsidian";
// import type BCPlugin from "./main";
// import { buildObsGraph } from "./Utils/graphUtils";
// import type { BCAPIInterface } from "./interfaces";
import type { App } from "obsidian";
import type { BCAPII, Directions } from "./interfaces";
import type BCPlugin from "./main";
import {
buildObsGraph,
dfsAllPaths,
getSubForFields,
getSubInDirs,
} from "./Utils/graphUtils";

// export class BCAPI implements BCAPIInterface {
// app: App;
// mainG: MultiGraph;
// closedG: MultiGraph;
export class BCAPI implements BCAPII {
app: App;
plugin: BCPlugin;

// public constructor(app: App, mainG: MultiGraph, closedG: MultiGraph) {
// this.app = app;
// this.mainG = mainG;
// this.closedG = closedG;
// }
public constructor(app: App, plugin: BCPlugin) {
this.app = app;
this.plugin = plugin;
}

// public buildObsG() {
// buildObsGraph;
// }
// }
public buildObsGraph = () => buildObsGraph(this.app);

public getSubInDirs = (dirs: Directions[], g = this.plugin.mainG) =>
getSubInDirs(g, ...dirs);

public getSubForFields = (fields: string[], g = this.plugin.mainG) =>
getSubForFields(g, fields);

public dfsAllPaths = (fromNode: string, g = this.plugin.mainG) =>
dfsAllPaths(g, fromNode);
}
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ export const ILLEGAL_FILENAME_CHARS = [
export const DATAVIEW_MISSING =
"The Dataview plugin must be installed for this to work";

export const API_NAME = "BCAPI";

export const DEFAULT_SETTINGS: BCSettings = {
addDendronNotes: false,
addDateNotes: false,
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export { buildObsGraph } from "./Utils/graphUtils";
export {
buildObsGraph,
getSubInDirs,
getSubForFields,
dfsAllPaths,
} from "./Utils/graphUtils";
7 changes: 7 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,10 @@ export interface EdgeAttr {
field: string;
implied?: string;
}

export interface BCAPII {
buildObsGraph: () => MultiGraph;
getSubInDirs: (dirs: Directions[], g?: MultiGraph) => MultiGraph;
getSubForFields: (fields: Directions[], g?: MultiGraph) => MultiGraph;
dfsAllPaths: (fromNode: string, g?: MultiGraph) => string[][];
}
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
openView,
wait,
} from "obsidian-community-lib/dist/utils";
import { BCAPI } from "./API";
import { Debugger } from "src/Debugger";
import { HierarchyNoteSelectorModal } from "./AlternativeHierarchies/HierarchyNotes/HierNoteModal";
import { getCodeblockCB } from "./Codeblocks";
Expand All @@ -23,9 +24,16 @@ import {
TRAIL_ICON,
TRAIL_ICON_SVG,
TREE_VIEW,
API_NAME,
} from "./constants";
import { FieldSuggestor } from "./FieldSuggestor";
import type { BCSettings, Directions, MyView, ViewInfo } from "./interfaces";
import type {
BCAPII,
BCSettings,
Directions,
MyView,
ViewInfo,
} from "./interfaces";
import { buildClosedG, buildMainG, refreshIndex } from "./refreshIndex";
import { RelationSuggestor } from "./RelationSuggestor";
import { BCSettingTab } from "./Settings/BreadcrumbsSettingTab";
Expand All @@ -48,6 +56,7 @@ export default class BCPlugin extends Plugin {
layoutChange: EventRef = undefined;
db: Debugger;
VIEWS: ViewInfo[];
api: BCAPII;
private bcStore: BCStore;

registerActiveLeafChangeEvent() {
Expand Down Expand Up @@ -260,6 +269,11 @@ export default class BCPlugin extends Plugin {
this.bcStore = new BCStore(this.mainG, this.app.metadataCache);
jugglPlugin.registerStore(this.bcStore);
}

this.api = new BCAPI(app, this);
// Register API to global window object.
(window[API_NAME] = this.api) &&
this.register(() => delete window[API_NAME]);
}

getActiveTYPEView(type: string): MyView | null {
Expand Down

0 comments on commit ad20594

Please sign in to comment.