From f8bf507b13ffb1959d56f29aff4a49ba15b93ac6 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 4 Dec 2021 09:14:47 +0200 Subject: [PATCH] feat(List/Matrix View): :sparkles: Option to enbale/disable alphabetical sorting entirely --- main.js | 64 +++++++++++++++++++++++++----------- src/BreadcrumbsSettingTab.ts | 9 ++--- src/MatrixView.ts | 13 +++++--- src/constants.ts | 1 + src/interfaces.ts | 1 + src/main.ts | 6 ++-- 6 files changed, 62 insertions(+), 32 deletions(-) diff --git a/main.js b/main.js index 6fd2424e..0dd3cee8 100644 --- a/main.js +++ b/main.js @@ -20267,12 +20267,16 @@ const DEFAULT_SETTINGS = { downViewWrap: false, dotsColour: "#000000", dvWaitTime: 5000, + enableAlphaSort: true, fieldSuggestor: true, filterImpliedSiblingsOfDifferentTypes: false, limitWriteBCCheckboxStates: {}, - indexNotes: [""], + gridDots: false, + gridHeatmap: false, + heatmapColour: getComputedStyle(document.body).getPropertyValue("--text-accent"), hierarchyNotes: [""], HNUpField: "", + indexNotes: [""], refreshOnNoteChange: false, useAllMetadata: true, openMatrixOnLoad: true, @@ -20291,12 +20295,10 @@ const DEFAULT_SETTINGS = { showGrid: true, showPrevNext: true, limitTrailCheckboxStates: {}, - gridDots: false, - gridHeatmap: false, - heatmapColour: getComputedStyle(document.body).getPropertyValue("--text-accent"), showAll: false, noPathMessage: `This note has no real or implied parents`, trailSeperator: "→", + treatCurrNodeAsImpliedSibling: false, respectReadableLineLength: true, userHiers: [ { @@ -24838,7 +24840,7 @@ class MatrixView extends require$$0.ItemView { : []; currParents.forEach((parent) => { closedUp.forEachInEdge(parent, (k, a, s, t) => { - if (s === basename) + if (s === basename && !settings.treatCurrNodeAsImpliedSibling) return; iSamesII.push(this.toInternalLinkObj(s, false, parent)); }); @@ -24862,9 +24864,11 @@ class MatrixView extends require$$0.ItemView { ? hier[dir].join(", ") : `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`; const { alphaSortAsc } = settings; - [ru, rs, rd, rn, rp, iu, is, id, iN, ip].forEach((a) => a - .sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1) - .sort((a, b) => a.order - b.order)); + const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip]; + if (settings.enableAlphaSort) { + 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 }); return [ { @@ -25966,14 +25970,18 @@ class BCSettingTab extends require$$0.PluginSettingTab { await plugin.saveSettings(); })); // TODO I don't think this setting works anymore. I removed it's functionality when adding multiple hierarchies - new require$$0.Setting(MLViewDetails) - .setName("Show all field names or just relation types") - .setDesc("This changes the headers in matrix/list view. You can have the headers be the list of metadata fields for each relation type (e.g. `parent, broader, upper`). Or you can have them just be the name of the relation type, i.e. 'Parent', 'Sibling', 'Child'. On = show the full list of names.") - .addToggle((toggle) => toggle.setValue(settings.showNameOrType).onChange(async (value) => { - settings.showNameOrType = value; - await plugin.saveSettings(); - await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); - })); + // new Setting(MLViewDetails) + // .setName("Show all field names or just relation types") + // .setDesc( + // "This changes the headers in matrix/list view. You can have the headers be the list of metadata fields for each relation type (e.g. `parent, broader, upper`). Or you can have them just be the name of the relation type, i.e. 'Parent', 'Sibling', 'Child'. On = show the full list of names." + // ) + // .addToggle((toggle) => + // toggle.setValue(settings.showNameOrType).onChange(async (value) => { + // settings.showNameOrType = value; + // await plugin.saveSettings(); + // await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); + // }) + // ); new require$$0.Setting(MLViewDetails) .setName("Show Relationship Type") .setDesc("Show whether a link is real or implied. A real link is one you explicitly put in a note. E.g. parent:: [[Note]]. An implied link is the reverse of a real link. For example, if A is the real parent of B, then B must be the implied child of A.") @@ -25982,6 +25990,15 @@ class BCSettingTab extends require$$0.PluginSettingTab { await plugin.saveSettings(); await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); })); + new require$$0.Setting(MLViewDetails) + .setName("Enable Alpahebtical Sorting") + .setDesc("By default, items in the Matrix view are sorted by the order they appear in your notes. Toggle this on to enable Alphabetical sorting. You can choose ascending/descending order in the setting below.") + .addToggle((toggle) => toggle.setValue(settings.enableAlphaSort).onChange(async (value) => { + settings.enableAlphaSort = value; + await plugin.saveSettings(); + await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); + })); + // TODO hide this setting if !enableAlphaSort new require$$0.Setting(MLViewDetails) .setName("Sort Alphabetically Ascending/Descending") .setDesc("Sort square items alphabetically in Ascending (on) or Descending (off) order.") @@ -25990,6 +26007,16 @@ class BCSettingTab extends require$$0.PluginSettingTab { await plugin.saveSettings(); await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); })); + new require$$0.Setting(MLViewDetails) + .setName("Make Current Note an Implied Sibling") + .setDesc("Techincally, the current note is always it's own implied sibling. By default, it is not show as such. Toggle this on to make it show.") + .addToggle((toggle) => toggle + .setValue(settings.treatCurrNodeAsImpliedSibling) + .onChange(async (value) => { + settings.treatCurrNodeAsImpliedSibling = value; + await plugin.saveSettings(); + await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); + })); new require$$0.Setting(MLViewDetails) .setName("Filter Implied Siblings") .setDesc("Implied siblings are: 1) notes with the same parent, or 2) notes that are real siblings. This setting only applies to type 1 implied siblings. If enabled, Breadcrumbs will filter type 1 implied siblings so that they not only share the same parent, but the parent relation has the exact same type. For example, the two real relations B --parent-> A, and C --parent-> A create an implied sibling between B and C (they have the same parent, A). The two real relations B --parent-> A, and C --up-> A create an implied sibling between B and C (they also have the same parent, A). But if this setting is turned on, the second implied sibling would not show, because the parent types are differnet (parent versus up).") @@ -49802,10 +49829,9 @@ class BCPlugin extends require$$0.Plugin { const { constructor } = this.VIEWS.find((view) => view.type === type); const leaves = this.app.workspace.getLeavesOfType(type); if (leaves && leaves.length >= 1) { - const view = leaves[0].view; - if (view instanceof constructor) { + const { view } = leaves[0]; + if (view instanceof constructor) return view; - } } return null; } diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 5524009d..7c4851f4 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -343,18 +343,19 @@ export class BCSettingTab extends PluginSettingTab { ); new Setting(MLViewDetails) - .setName("Show Relationship Type") + .setName("Enable Alpahebtical Sorting") .setDesc( - "Show whether a link is real or implied. A real link is one you explicitly put in a note. E.g. parent:: [[Note]]. An implied link is the reverse of a real link. For example, if A is the real parent of B, then B must be the implied child of A." + "By default, items in the Matrix view are sorted by the order they appear in your notes. Toggle this on to enable Alphabetical sorting. You can choose ascending/descending order in the setting below." ) .addToggle((toggle) => - toggle.setValue(settings.showRelationType).onChange(async (value) => { - settings.showRelationType = value; + toggle.setValue(settings.enableAlphaSort).onChange(async (value) => { + settings.enableAlphaSort = value; await plugin.saveSettings(); await plugin.getActiveTYPEView(MATRIX_VIEW).draw(); }) ); + // TODO hide this setting if !enableAlphaSort new Setting(MLViewDetails) .setName("Sort Alphabetically Ascending/Descending") .setDesc( diff --git a/src/MatrixView.ts b/src/MatrixView.ts index 6115a9fa..a4e2f0ec 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -193,13 +193,16 @@ export default class MatrixView extends ItemView { : `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`; const { alphaSortAsc } = settings; - [ru, rs, rd, rn, rp, iu, is, id, iN, ip].forEach((a) => - a - .sort((a, b) => + const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip]; + + if (settings.enableAlphaSort) { + squares.forEach((sq) => + sq.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1 ) - .sort((a, b) => a.order - b.order) - ); + ); + } + squares.forEach((sq) => sq.sort((a, b) => a.order - b.order)); debug( { ru }, diff --git a/src/constants.ts b/src/constants.ts index 494b348f..9966b1e7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -144,6 +144,7 @@ export const DEFAULT_SETTINGS: BCSettings = { downViewWrap: false, dotsColour: "#000000", dvWaitTime: 5000, + enableAlphaSort: true, fieldSuggestor: true, filterImpliedSiblingsOfDifferentTypes: false, limitWriteBCCheckboxStates: {}, diff --git a/src/interfaces.ts b/src/interfaces.ts index 031e95e8..7e1e3a90 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -18,6 +18,7 @@ export interface BCSettings { defaultView: boolean; downViewWrap: boolean; dotsColour: string; + enableAlphaSort: boolean; fieldSuggestor: boolean; filterImpliedSiblingsOfDifferentTypes: boolean; gridDots: boolean; diff --git a/src/main.ts b/src/main.ts index 4d1afe9a..db2b2f25 100644 --- a/src/main.ts +++ b/src/main.ts @@ -423,10 +423,8 @@ export default class BCPlugin extends Plugin { const { constructor } = this.VIEWS.find((view) => view.type === type); const leaves = this.app.workspace.getLeavesOfType(type); if (leaves && leaves.length >= 1) { - const view = leaves[0].view; - if (view instanceof constructor) { - return view; - } + const { view } = leaves[0]; + if (view instanceof constructor) return view; } return null; }