From 3d0cd5dc11fcd42438d03c1dfb0e4a4b8af070dd Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Tue, 7 Dec 2021 18:58:30 +0200 Subject: [PATCH] fix(List/Matrix View): :bug: Allow empty reverse fields (Fix #203) --- main.js | 27 +++++++++++++++++++++++---- src/MatrixView.ts | 30 +++++++++++++++++++++++------- src/sharedFunctions.ts | 8 ++++++-- src/utils.ts | 7 ------- src/utils2.ts | 1 - 5 files changed, 52 insertions(+), 21 deletions(-) delete mode 100644 src/utils.ts delete mode 100644 src/utils2.ts diff --git a/main.js b/main.js index 6fbdad7c..f449c155 100644 --- a/main.js +++ b/main.js @@ -22257,13 +22257,15 @@ function swapItems(i, j, arr) { return arr; } const linkClass = (app, to, realQ = true) => `internal-link BC-Link ${isInVault(app, to) ? "" : "is-unresolved"} ${realQ ? "" : "BC-Implied"}`; +const fallbackOppField = (field, dir) => `${field} <${ARROW_DIRECTIONS[getOppDir(dir)]}>`; /** Remember to filter by hierarchy in MatrixView! */ function getRealnImplied(plugin, currNode, dir = null) { const realsnImplieds = blankRealNImplied(); const { userHiers } = plugin.settings; plugin.mainG.forEachEdge(currNode, (k, a, s, t) => { + var _a; const { field, dir: edgeDir } = a; - const oppField = getOppFields(userHiers, field)[0]; + const oppField = (_a = getOppFields(userHiers, field)[0]) !== null && _a !== void 0 ? _a : fallbackOppField(field, edgeDir); (dir ? [dir, getOppDir(dir)] : DIRECTIONS$1).forEach((currDir) => { const oppDir = getOppDir(currDir); // Reals @@ -24564,12 +24566,18 @@ class MatrixView extends require$$0.ItemView { return userHiers.map((hier) => { const filteredRealNImplied = blankRealNImplied(); for (const dir in realsnImplieds) { + const oppDir = getOppDir(dir); + const arrow = ARROW_DIRECTIONS[dir]; const { reals, implieds } = realsnImplieds[dir]; filteredRealNImplied[dir].reals = reals - .filter((real) => hier[dir].includes(real.field)) + .filter((real) => hier[dir].includes(real.field) || + (real.field.includes(`<${arrow}>`) && + hier[oppDir].includes(real.field.split(" <")[0]))) .map((item) => this.toInternalLinkObj(item.to, true)); filteredRealNImplied[dir].implieds = implieds - .filter((implied) => hier[dir].includes(implied.field)) + .filter((implied) => hier[dir].includes(implied.field) || + (implied.field.includes(`<${arrow}>`) && + hier[oppDir].includes(implied.field.split(" <")[0]))) .map((item) => this.toInternalLinkObj(item.to, false)); } let { up: { reals: ru, implieds: iu }, same: { reals: rs, implieds: is }, down: { reals: rd, implieds: id }, next: { reals: rn, implieds: iN }, prev: { reals: rp, implieds: ip }, } = filteredRealNImplied; @@ -24613,7 +24621,18 @@ class MatrixView extends require$$0.ItemView { squares.forEach((sq) => sq.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1)); } squares.forEach((sq) => sq.sort((a, b) => a.order - b.order)); - loglevel.debug({ ru }, { rs }, { rd }, { rn }, { rp }, { iu }, { is }, { id }, { iN }, { ip }); + loglevel.info([ + { ru }, + { rs }, + { rd }, + { rn }, + { rp }, + { iu }, + { is }, + { id }, + { iN }, + { ip }, + ]); return [ { realItems: ru, diff --git a/src/MatrixView.ts b/src/MatrixView.ts index 76118c2c..56b52ee3 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -1,4 +1,4 @@ -import { debug, error } from "loglevel"; +import { debug, error, info } from "loglevel"; import { ItemView, Notice, TFile, WorkspaceLeaf } from "obsidian"; import { Debugger } from "src/Debugger"; import Lists from "./Components/Lists.svelte"; @@ -18,7 +18,11 @@ import type { UserHier, } from "./interfaces"; import type BCPlugin from "./main"; -import { getRealnImplied, linkClass } from "./sharedFunctions"; +import { + fallbackOppField, + getRealnImplied, + linkClass, +} from "./sharedFunctions"; export default class MatrixView extends ItemView { private plugin: BCPlugin; @@ -127,13 +131,25 @@ export default class MatrixView extends ItemView { } = blankRealNImplied(); for (const dir in realsnImplieds) { + const oppDir = getOppDir(dir as Directions); + const arrow = ARROW_DIRECTIONS[dir]; const { reals, implieds } = realsnImplieds[dir]; filteredRealNImplied[dir].reals = reals - .filter((real) => hier[dir].includes(real.field)) + .filter( + (real) => + hier[dir].includes(real.field) || + (real.field.includes(`<${arrow}>`) && + hier[oppDir].includes(real.field.split(" <")[0])) + ) .map((item) => this.toInternalLinkObj(item.to, true)); filteredRealNImplied[dir].implieds = implieds - .filter((implied) => hier[dir].includes(implied.field)) + .filter( + (implied) => + hier[dir].includes(implied.field) || + (implied.field.includes(`<${arrow}>`) && + hier[oppDir].includes(implied.field.split(" <")[0])) + ) .map((item) => this.toInternalLinkObj(item.to, false)); } @@ -198,7 +214,7 @@ export default class MatrixView extends ItemView { } squares.forEach((sq) => sq.sort((a, b) => a.order - b.order)); - debug( + info([ { ru }, { rs }, { rd }, @@ -208,8 +224,8 @@ export default class MatrixView extends ItemView { { is }, { id }, { iN }, - { ip } - ); + { ip }, + ]); return [ { diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index 4c4ec3a5..247ff197 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -238,6 +238,9 @@ export const linkClass = (app: App, to: string, realQ = true) => realQ ? "" : "BC-Implied" }`; +export const fallbackOppField = (field: string, dir: Directions) => + `${field} <${ARROW_DIRECTIONS[getOppDir(dir)]}>`; + /** Remember to filter by hierarchy in MatrixView! */ export function getRealnImplied( plugin: BCPlugin, @@ -248,8 +251,9 @@ export function getRealnImplied( const { userHiers } = plugin.settings; plugin.mainG.forEachEdge(currNode, (k, a, s, t) => { - const { field, dir: edgeDir } = a; - const oppField = getOppFields(userHiers, field)[0]; + const { field, dir: edgeDir } = a as { field: string; dir: Directions }; + const oppField = + getOppFields(userHiers, field)[0] ?? fallbackOppField(field, edgeDir); (dir ? [dir, getOppDir(dir)] : DIRECTIONS).forEach((currDir) => { const oppDir = getOppDir(currDir); diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index 013432bb..00000000 --- a/src/utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { camelCase } from "lodash"; -// import Graph from "graphology"; -import { lowerCase } from "./utils2"; - -export function myFunc(str: string) { - return camelCase(lowerCase(str)); -} diff --git a/src/utils2.ts b/src/utils2.ts deleted file mode 100644 index d021d40c..00000000 --- a/src/utils2.ts +++ /dev/null @@ -1 +0,0 @@ -export const lowerCase = (str: string) => str.toLowerCase();