From 5ababaaa1a719493dcc4e673181c1589fd8e2f7e Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Wed, 23 Jun 2021 19:34:28 +0200 Subject: [PATCH] View simplified, option to showRelationTypes --- src/BreadcrumbsSettingTab.ts | 11 ++++++ src/List.svelte | 75 ++++++++++++++---------------------- src/Lists.svelte | 8 ++-- src/Matrix.svelte | 35 ++++++----------- src/MatrixView.ts | 62 ++++++++++++++--------------- src/Square.svelte | 43 ++++++++++++--------- src/main.ts | 11 ++---- 7 files changed, 116 insertions(+), 129 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 73884381..e008aa65 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -77,5 +77,16 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { console.log(this.plugin.settings.indexNote); }) ); + + new Setting(containerEl) + .setName("Show Relationship Type") + .setDesc("Show whether a link is real or implied") + .addToggle((toggle) => toggle + .setValue(this.plugin.settings.showRelationType) + .onChange(async (value) => { + this.plugin.settings.showRelationType = value; + await this.plugin.saveSettings(); + }) + ); } } diff --git a/src/List.svelte b/src/List.svelte index aff58c12..fb9d8282 100644 --- a/src/List.svelte +++ b/src/List.svelte @@ -1,8 +1,9 @@

{currFile}

{#each lists as list} {#if list.realItems.length > 0 || list.impliedItems.length > 0} - + {/if} {/each} diff --git a/src/Matrix.svelte b/src/Matrix.svelte index 63004233..72ea951a 100644 --- a/src/Matrix.svelte +++ b/src/Matrix.svelte @@ -1,27 +1,24 @@ diff --git a/src/MatrixView.ts b/src/MatrixView.ts index d8789849..83aab971 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -227,12 +227,11 @@ export default class MatrixView extends ItemView { this.contentEl.empty(); const button = this.contentEl.createEl("button", { - text: this.matrixQ ? "Matrix" : "List", + text: this.matrixQ ? "List" : "Matrix", }); button.addEventListener("click", async () => { this.matrixQ = !this.matrixQ; - button.innerText = this.matrixQ ? "Matrix" : "List"; - console.log(this.matrixQ); + button.innerText = this.matrixQ ? "List" : "Matrix"; await this.draw(); }); @@ -261,10 +260,12 @@ export default class MatrixView extends ItemView { /// Implied Siblings const currParents = gParents.successors(currFile.basename) ?? []; const impliedSiblingsArr: internalLinkObj[] = []; + if (currParents.length) { currParents.forEach((parent) => { const impliedSiblings = gParents.predecessors(parent) ?? []; const indexCurrNote = impliedSiblings.indexOf(currFile.basename); + impliedSiblings.splice(indexCurrNote, 1); impliedSiblings.forEach((impliedSibling) => { impliedSiblingsArr.push({ @@ -283,31 +284,31 @@ export default class MatrixView extends ItemView { app: this.app, }; - const topSquare: SquareProps = { - realItems: [ - { - to: settings.indexNote, - currFile: currFile, - cls: this.resolvedClass(settings.indexNote, currFile), - }, - ], - impliedItems: [], - fieldName: "Top", - app: this.app, - }; - - const currSquare: SquareProps = { - realItems: [ - { - to: currFile.basename, - currFile: currFile, - cls: this.resolvedClass(currFile.basename, currFile), - }, - ], - impliedItems: [], - fieldName: "Current", - app: this.app, - }; + // const topSquare: SquareProps = { + // realItems: [ + // { + // to: settings.indexNote, + // currFile: currFile, + // cls: this.resolvedClass(settings.indexNote, currFile), + // }, + // ], + // impliedItems: [], + // fieldName: "Top", + // app: this.app, + // }; + + // const currSquare: SquareProps = { + // realItems: [ + // { + // to: currFile.basename, + // currFile: currFile, + // cls: this.resolvedClass(currFile.basename, currFile), + // }, + // ], + // impliedItems: [], + // fieldName: "Current", + // app: this.app, + // }; const siblingSquare: SquareProps = { realItems: realSiblings, @@ -328,10 +329,9 @@ export default class MatrixView extends ItemView { target: this.contentEl, props: { parents: parentsSquare, - top: topSquare, - current: currSquare, siblings: siblingSquare, children: childrenSquare, + settings: settings, }, }); } else { @@ -339,9 +339,9 @@ export default class MatrixView extends ItemView { target: this.contentEl, props: { parents: parentsSquare, - top: topSquare, siblings: siblingSquare, children: childrenSquare, + settings: settings, }, }); } diff --git a/src/Square.svelte b/src/Square.svelte index 37e7400b..e27db0e7 100644 --- a/src/Square.svelte +++ b/src/Square.svelte @@ -1,49 +1,54 @@ -
+

{fieldName}

{#if realItems.length} -
Real
- {#if realItems.length > 1} + {#if settings.showRelationType} +
Real
+ {/if}
    {#each realItems as realItem}
  1. - openLink(realItem)}>{realItem.to} + openLink(realItem)}>{realItem.to}
  2. {/each}
- {:else} - openLink(realItems[0])}>{realItems[0].to} - {/if} {/if} {#if impliedItems.length} -
Implied
- {#if impliedItems.length > 1} + {#if settings.showRelationType} +
Implied
+ {/if}
    {#each impliedItems as impliedItem}
  1. - openLink(impliedItem)}>{impliedItem.to} + openLink(impliedItem)}>{impliedItem.to}
  2. {/each}
- {:else} - openLink(impliedItems[0])}>{impliedItems[0].to} - {/if} {/if}
@@ -54,5 +59,7 @@ import type { internalLinkObj, SquareProps } from "src/MatrixView"; border: 2px solid white; border-radius: 5px; padding: 5px; + height: fit-content; + position: relative; } diff --git a/src/main.ts b/src/main.ts index 7b487700..a13e2c92 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ import MatrixView from "src/MatrixView"; // import ListView from "src/ListView"; interface BreadcrumbsSettings { + showRelationType: boolean; parentFieldName: string; siblingFieldName: string; childFieldName: string; @@ -16,6 +17,7 @@ interface BreadcrumbsSettings { } const DEFAULT_SETTINGS: BreadcrumbsSettings = { + showRelationType: true, parentFieldName: "parent", siblingFieldName: "sibling", childFieldName: "child", @@ -34,16 +36,9 @@ export default class BreadcrumbsPlugin extends Plugin { this.registerView( VIEW_TYPE_BREADCRUMBS_MATRIX, - (leaf: WorkspaceLeaf) => - (this.matrixView = new MatrixView(leaf, this)) + (leaf: WorkspaceLeaf) => (this.matrixView = new MatrixView(leaf, this)) ); - // this.registerView( - // VIEW_TYPE_BREADCRUMBS_LIST, - // (leaf: WorkspaceLeaf) => - // (this.listView = new ListView(leaf, this)) - // ); - this.addCommand({ id: "show-breadcrumb-matrix-view", name: "Open Matrix View",