Skip to content

Commit

Permalink
refactor: 🚚 Refactor utils into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 21, 2022
1 parent 98c2dfa commit 5da9196
Show file tree
Hide file tree
Showing 49 changed files with 22,189 additions and 22,124 deletions.
43,158 changes: 21,586 additions & 21,572 deletions main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/AlternativeHierarchies/CSVCrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { MultiGraph } from "graphology";
import { debug } from "loglevel";
import { normalizePath } from "obsidian";
import { dropWikilinks } from "../sharedFunctions";
import { dropWikilinks } from "../Utils/ObsidianUtils";
import type { Directions } from "../interfaces";
import { addEdgeIfNot, addNodesIfNot } from "../graphUtils";
import { debug } from "loglevel";
import type BCPlugin from "../main";
import { addEdgeIfNot, addNodesIfNot } from "../Utils/graphUtils";

export async function getCSVRows(plugin: BCPlugin) {
const { CSVPaths } = plugin.settings;
Expand Down
8 changes: 6 additions & 2 deletions src/AlternativeHierarchies/DendronNotes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { MultiGraph } from "graphology";
import { BC_IGNORE_DENDRON } from "../constants";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import type BCPlugin from "../main";
import { getDVBasename } from "../sharedFunctions";
import {
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

export function addDendronNotesToGraph(
plugin: BCPlugin,
Expand Down
11 changes: 8 additions & 3 deletions src/AlternativeHierarchies/FolderNotes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import type { MultiGraph } from "graphology";
import { TFile, TFolder } from "obsidian";
import { BC_FOLDER_NOTE, BC_FOLDER_NOTE_RECURSIVE } from "../constants";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { BCSettings, dvFrontmatterCache } from "../interfaces";
import type { dvFrontmatterCache } from "../interfaces";
import type BCPlugin from "../main";
import { getDVBasename, getFields, getFolderName } from "../sharedFunctions";
import {
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { getDVBasename, getFolderName } from "../Utils/ObsidianUtils";

const getSubsFromFolder = (folder: TFolder) => {
const otherNotes: TFile[] = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
Notice,
TFile,
} from "obsidian";
import { ModifyHierItemModal } from "./ModifyHierItemModal";
import type { BCSettings } from "../../interfaces";
import type BCPlugin from "../../main";
import { dropWikilinks } from "../../sharedFunctions";
import { dropWikilinks } from "../../Utils/ObsidianUtils";
import { ModifyHierItemModal } from "./ModifyHierItemModal";

interface HNItem {
depth: number;
Expand Down
8 changes: 6 additions & 2 deletions src/AlternativeHierarchies/HierarchyNotes/HierarchyNotes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { MultiGraph } from "graphology";
import { Notice, TFile } from "obsidian";
import { addEdgeIfNot, addNodesIfNot, getOppFields } from "../../graphUtils";
import type { BCSettings, HierarchyNoteItem } from "../../interfaces";
import type BCPlugin from "../../main";
import { fallbackOppField, getFields } from "../../sharedFunctions";
import { addEdgeIfNot, addNodesIfNot } from "../../Utils/graphUtils";
import {
fallbackOppField,
getFields,
getOppFields,
} from "../../Utils/HierUtils";

export async function getHierarchyNoteItems(plugin: BCPlugin, file: TFile) {
const { userHiers } = plugin.settings;
Expand Down
4 changes: 2 additions & 2 deletions src/AlternativeHierarchies/JugglLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { MultiGraph } from "graphology";
import { parseTypedLink } from "juggl-api";
import type { TFile } from "obsidian";
import { splitLinksRegex } from "../constants";
import { getFieldInfo, getTargetOrder, populateMain } from "../graphUtils";
import type { BCSettings, dvFrontmatterCache, JugglLink } from "../interfaces";
import type BCPlugin from "../main";
import { getFields } from "../sharedFunctions";
import { getTargetOrder, populateMain } from "../Utils/graphUtils";
import { getFieldInfo, getFields } from "../Utils/HierUtils";

// TODO I think it'd be better to do this whole thing as an obj instead of JugglLink[]
// => {[note: string]: {type: string, linksInLine: string[]}[]}
Expand Down
9 changes: 7 additions & 2 deletions src/AlternativeHierarchies/LinkNotes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { MultiGraph } from "graphology";
import { BC_LINK_NOTE } from "../constants";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import type BCPlugin from "../main";
import { getDVBasename, getFields } from "../sharedFunctions";
import {
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

export function addLinkNotesToGraph(
plugin: BCPlugin,
Expand Down
12 changes: 9 additions & 3 deletions src/AlternativeHierarchies/NamingSystem.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { MultiGraph } from "graphology";
import type BCPlugin from "../main";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import { getDVBasename, getFields, strToRegex } from "../sharedFunctions";
import type BCPlugin from "../main";
import { strToRegex } from "../Utils/generalUtils";
import {
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

export function addNamingSystemNotesToGraph(
plugin: BCPlugin,
Expand Down
12 changes: 9 additions & 3 deletions src/AlternativeHierarchies/RegexNotes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { MultiGraph } from "graphology";
import { info } from "loglevel";
import type BCPlugin from "../main";
import { BC_REGEX_NOTE, BC_REGEX_NOTE_FIELD } from "../constants";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import { getDVBasename, getFields, strToRegex } from "../sharedFunctions";
import type BCPlugin from "../main";
import { strToRegex } from "../Utils/generalUtils";
import {
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

export function addRegexNotesToGraph(
plugin: BCPlugin,
Expand Down
13 changes: 7 additions & 6 deletions src/AlternativeHierarchies/TagNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
BC_TAG_NOTE_EXACT,
BC_TAG_NOTE_FIELD,
} from "../constants";
import { getSourceOrder, getTargetOrder, populateMain } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import type BCPlugin from "../main";
import { splitAndTrim } from "../Utils/generalUtils";
import {
dropHash,
getDVBasename,
getFields,
splitAndTrim,
} from "../sharedFunctions";
getSourceOrder,
getTargetOrder,
populateMain,
} from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { dropHash, getDVBasename } from "../Utils/ObsidianUtils";

const getAllTags = (app: App, file: TFile, withHash = true): string[] => {
const { tags, frontmatter } = app.metadataCache.getFileCache(file);
Expand Down
7 changes: 4 additions & 3 deletions src/AlternativeHierarchies/TraverseNotes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { MultiGraph } from "graphology";
import { info } from "loglevel";
import { BC_TRAVERSE_NOTE } from "../constants";
import { dfsAllPaths, populateMain, removeCycles } from "../graphUtils";
import type { dvFrontmatterCache } from "../interfaces";
import type BCPlugin from "../main";
import { getDVBasename, getFields } from "../sharedFunctions";
import { dfsAllPaths, populateMain, removeCycles } from "../Utils/graphUtils";
import { getFields } from "../Utils/HierUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

export function addTraverseNotesToGraph(
plugin: BCPlugin,
Expand All @@ -14,7 +15,7 @@ export function addTraverseNotesToGraph(
) {
const { settings } = plugin;
const { userHiers } = settings;

traverseNotes.forEach((altFile) => {
const { file } = altFile;
const basename = getDVBasename(file);
Expand Down
11 changes: 5 additions & 6 deletions src/Codeblocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { MarkdownPostProcessorContext, Notice } from "obsidian";
import { createIndex } from "./Commands/CreateIndex";
import CBTree from "./Components/CBTree.svelte";
import { CODEBLOCK_FIELDS, CODEBLOCK_TYPES, DIRECTIONS } from "./constants";
import type { CodeblockFields, ParsedCodeblock } from "./interfaces";
import type BCPlugin from "./main";
import { dropFolder, splitAndTrim } from "./Utils/generalUtils";
import {
dfsAllPaths,
getFieldInfo,
getOppDir,
getReflexiveClosure,
getSubInDirs,
} from "./graphUtils";
import type { CodeblockFields, ParsedCodeblock } from "./interfaces";
import type BCPlugin from "./main";
import { dropFolder, getFields, splitAndTrim } from "./sharedFunctions";
} from "./Utils/graphUtils";
import { getFieldInfo, getFields, getOppDir } from "./Utils/HierUtils";
import { createJuggl } from "./Visualisations/Juggl";

export function getCodeblockCB(plugin: BCPlugin) {
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CreateIndex.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cloneDeep } from "lodash";
import { info } from "loglevel";
import { copy } from "obsidian-community-lib/dist/utils";
import { dfsAllPaths, getSinks, getSubInDirs } from "../graphUtils";
import type BCPlugin from "../main";
import { makeWiki } from "../sharedFunctions";
import { dfsAllPaths, getSinks, getSubInDirs } from "../Utils/graphUtils";
import { makeWiki } from "../Utils/ObsidianUtils";

/**
* Returns a copy of `index`, doesn't mutate.
Expand Down
8 changes: 2 additions & 6 deletions src/Commands/WriteBCs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Notice, TFile } from "obsidian";
import {
createOrUpdateYaml,
fallbackOppField,
splitAtYaml,
} from "../sharedFunctions";
import type BCPlugin from "../main";
import { getOppFields } from "../graphUtils";
import { fallbackOppField, getOppFields } from "../Utils/HierUtils";
import { createOrUpdateYaml, splitAtYaml } from "../Utils/ObsidianUtils";

export async function writeBCToFile(plugin: BCPlugin, file: TFile) {
const { app, settings, mainG } = plugin;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/jumpToFirstDir.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Notice } from "obsidian";
import { getRealnImplied } from "../sharedFunctions";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { getRealnImplied } from "../Utils/graphUtils";

export async function jumpToFirstDir(plugin: BCPlugin, dir: Directions) {
const { limitJumpToFirstFields } = plugin.settings;
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/threading.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { normalizePath, Notice } from "obsidian";
import { getFieldInfo, getOppFields } from "../graphUtils";
import type BCPlugin from "../main";
import {
createOrUpdateYaml,
fallbackOppField,
splitAtYaml,
} from "../sharedFunctions";
getFieldInfo,
getOppFields,
} from "../Utils/HierUtils";
import { createOrUpdateYaml, splitAtYaml } from "../Utils/ObsidianUtils";

export async function thread(plugin: BCPlugin, field: string) {
const { app, settings } = plugin;
Expand Down
5 changes: 2 additions & 3 deletions src/Components/CBTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { isInVault, openOrSwitch } from "obsidian-community-lib/dist/utils";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { dropDendron, dropFolder } from "../sharedFunctions";
import { dropDendron } from "../Utils/generalUtils";
import RenderMarkdown from "./RenderMarkdown.svelte";
export let plugin: BCPlugin;
Expand All @@ -17,8 +17,7 @@
export let max: number;
export let basename: string;
const {settings, app} = plugin;
const { settings, app } = plugin;
const indentToDepth = (indent: string) => indent.length / 2 + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Lists.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import type { App, TFile } from "obsidian";
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import { dropPathNDendron } from "../sharedFunctions";
import type { BCSettings, SquareProps } from "../interfaces";
import { dropPathNDendron } from "../Utils/generalUtils";
import type MatrixView from "../Views/MatrixView";
export let filteredSquaresArr: SquareProps[][];
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Matrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { App, TFile } from "obsidian";
import { hoverPreview, openOrSwitch } from "obsidian-community-lib";
import type { BCSettings, SquareProps } from "../interfaces";
import { dropPathNDendron } from "../Utils/generalUtils";
import type MatrixView from "../Views/MatrixView";
import { dropPathNDendron } from "../sharedFunctions";
export let filteredSquaresArr: SquareProps[][];
export let currFile: TFile;
Expand Down
4 changes: 2 additions & 2 deletions src/Components/ModifyHNItemComp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { error } from "console";
import { Notice, TFile } from "obsidian";
import { onMount } from "svelte";
import { ARROW_DIRECTIONS } from "../constants";
import type { ModifyHierItemModal } from "../AlternativeHierarchies/HierarchyNotes/ModifyHierItemModal";
import { ARROW_DIRECTIONS } from "../constants";
import type { BCSettings } from "../interfaces";
import { dropWikilinks, makeWiki } from "../sharedFunctions";
import { dropWikilinks, makeWiki } from "../Utils/ObsidianUtils";
export let modal: ModifyHierItemModal;
export let settings: BCSettings;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/NextPrev.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { openOrSwitch } from "obsidian-community-lib";
import type { SquareItem } from "../interfaces";
import type BCPlugin from "../main";
import { linkClass } from "../sharedFunctions";
import { linkClass } from "../Utils/generalUtils";
export let app: App;
export let plugin: BCPlugin;
Expand Down
4 changes: 2 additions & 2 deletions src/Components/SideTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import FaRegSnowflake from "svelte-icons/fa/FaRegSnowflake.svelte";
import { createIndex } from "../Commands/CreateIndex";
import { DIRECTIONS } from "../constants";
import { dfsAllPaths, getOppDir, getSubInDirs } from "../graphUtils";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { refreshIndex } from "../refreshIndex";
import { dropDendron } from "../sharedFunctions";
import { dropDendron } from "../Utils/generalUtils";
import { dfsAllPaths, getSubInDirs } from "../Utils/graphUtils";
import type TreeView from "../Views/TreeView";
export let plugin: BCPlugin;
Expand Down
9 changes: 5 additions & 4 deletions src/Components/Stats.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { sum } from "lodash";
import { debug } from "loglevel";
import { copy } from "obsidian-community-lib";
import { refreshIndex } from "../refreshIndex";
import { Debugger } from "../Debugger";
import { ARROW_DIRECTIONS, DIRECTIONS, STATS_VIEW } from "../constants";
import { closeImpliedLinks, getOppDir, getSubForFields } from "../graphUtils";
import { Debugger } from "../Debugger";
import type { Directions, HierData } from "../interfaces";
import type BCPlugin from "../main";
import { hierToStr, makeWiki } from "../sharedFunctions";
import { refreshIndex } from "../refreshIndex";
import { closeImpliedLinks, getSubForFields } from "../Utils/graphUtils";
import { getOppDir, hierToStr } from "../Utils/HierUtils";
import { makeWiki } from "../Utils/ObsidianUtils";
export let plugin: BCPlugin;
Expand Down
14 changes: 7 additions & 7 deletions src/Components/TrailGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
hoverPreview,
openOrSwitch,
} from "obsidian-community-lib/dist/utils";
import {
getOutNeighbours,
getReflexiveClosure,
getSubInDirs,
} from "../graphUtils";
import type BCPlugin from "../main";
import {
dropDendron,
getAlt,
linkClass,
normalise,
padArray,
runs,
transpose,
} from "../sharedFunctions";
} from "../Utils/generalUtils";
import {
getOutNeighbours,
getReflexiveClosure,
getSubInDirs,
} from "../Utils/graphUtils";
import { getAlt } from "../Utils/ObsidianUtils";
export let sortedTrails: string[][];
export let app: App;
export let plugin: BCPlugin;
Expand Down
3 changes: 2 additions & 1 deletion src/Components/TrailPath.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
hoverPreview,
openOrSwitch,
} from "obsidian-community-lib/dist/utils";
import { dropDendron, getAlt, splitAndTrim } from "../sharedFunctions";
import type BCPlugin from "../main";
import { dropDendron } from "../Utils/generalUtils";
import { getAlt } from "../Utils/ObsidianUtils";
export let sortedTrails: string[][];
export let app: App;
Expand Down
Loading

0 comments on commit 5da9196

Please sign in to comment.