Skip to content

Commit

Permalink
feat(List/Matrix View): ✨ Option to change the order of the direction…
Browse files Browse the repository at this point in the history
…s for each hierarchy (fix #224)
  • Loading branch information
SkepticMystic committed Jan 1, 2022
1 parent 5651ceb commit ca3c35b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 27 deletions.
48 changes: 41 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21104,6 +21104,7 @@ const DEFAULT_SETTINGS = {
showTrail: true,
showGrid: true,
showPrevNext: true,
squareDirectionsOrder: [0, 1, 2, 3, 4],
limitTrailCheckboxes: [],
limitJumpToFirstFields: [],
showAll: false,
Expand Down Expand Up @@ -24857,9 +24858,10 @@ class MatrixView extends require$$0.ItemView {
const realTos = reals.map((real) => real.to);
return implieds.filter((implied) => !realTos.includes(implied.to));
}
getHierSquares(userHiers, currFile, settings) {
getHierSquares(userHiers, currFile) {
const { plugin } = this;
const { mainG } = plugin;
const { mainG, settings } = plugin;
const { alphaSortAsc, enableAlphaSort, treatCurrNodeAsImpliedSibling, squareDirectionsOrder, } = settings;
if (!mainG)
return [];
const { basename } = currFile;
Expand Down Expand Up @@ -24892,7 +24894,7 @@ class MatrixView extends require$$0.ItemView {
closedUp.forEachOutEdge(basename, (k, a, s, par) => {
if (hier.up.includes(a.field)) {
closedUp.forEachInEdge(par, (k, a, s, t) => {
if (s === basename && !settings.treatCurrNodeAsImpliedSibling)
if (s === basename && !treatCurrNodeAsImpliedSibling)
return;
iSamesII.push(this.toInternalLinkObj(s, false, t));
});
Expand All @@ -24918,9 +24920,8 @@ class MatrixView extends require$$0.ItemView {
const getFieldInHier = (dir) => hier[dir][0]
? hier[dir].join(", ")
: `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`;
const { alphaSortAsc } = settings;
const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip];
if (settings.enableAlphaSort) {
if (enableAlphaSort) {
squares.forEach((sq) => sq.sort((a, b) => {
var _a, _b;
return ((_a = a.alt) !== null && _a !== void 0 ? _a : a.to) < ((_b = b.alt) !== null && _b !== void 0 ? _b : b.to)
Expand All @@ -24945,7 +24946,7 @@ class MatrixView extends require$$0.ItemView {
{ iN },
{ ip },
]);
return [
const square = [
{
realItems: ru,
impliedItems: iu,
Expand All @@ -24972,6 +24973,7 @@ class MatrixView extends require$$0.ItemView {
field: getFieldInHier("prev"),
},
];
return squareDirectionsOrder.map((order) => square[order]);
});
}
async draw() {
Expand Down Expand Up @@ -25007,7 +25009,7 @@ class MatrixView extends require$$0.ItemView {
await this.draw();
};
});
const hierSquares = this.getHierSquares(userHiers, currFile, settings).filter((squareArr) => squareArr.some((square) => square.realItems.length + square.impliedItems.length > 0));
const hierSquares = this.getHierSquares(userHiers, currFile).filter((squareArr) => squareArr.some((sq) => sq.realItems.length + sq.impliedItems.length > 0));
const compInput = {
target: contentEl,
props: {
Expand Down Expand Up @@ -25195,6 +25197,38 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}));
new require$$0.Setting(MLViewDetails)
.setName("Directions Order")
.setDesc(fragWithHTML(`Change the order in which the directions appear in the M/L view. Use numbers to change the order, the default is "up, same, down, next, prev" (<code>01234</code>).
<ul>
<li>0 = up</li>
<li>1 = same</li>
<li>2 = down</li>
<li>3 = next</li>
<li>4 = prev</li>
</ul>
<strong>Note:</strong> You can only change the order of the directions. You can't add or remove directions.`))
.addText((text) => {
text.setValue(settings.squareDirectionsOrder.join(""));
text.inputEl.onblur = async () => {
const value = text.getValue();
if (value.length === 5 &&
value.includes("0") &&
value.includes("1") &&
value.includes("2") &&
value.includes("3") &&
value.includes("4")) {
settings.squareDirectionsOrder = value
.split("")
.map((order) => Number.parseInt(order));
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
}
else {
new require$$0.Notice('The value must be a 5 digit number using only the digits "0", "1", "2", "3", "4"');
}
};
});
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.")
Expand Down
40 changes: 40 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,46 @@ export class BCSettingTab extends PluginSettingTab {
})
);

new Setting(MLViewDetails)
.setName("Directions Order")
.setDesc(
fragWithHTML(
`Change the order in which the directions appear in the M/L view. Use numbers to change the order, the default is "up, same, down, next, prev" (<code>01234</code>).
<ul>
<li>0 = up</li>
<li>1 = same</li>
<li>2 = down</li>
<li>3 = next</li>
<li>4 = prev</li>
</ul>
<strong>Note:</strong> You can only change the order of the directions. You can't add or remove directions.`
)
)
.addText((text) => {
text.setValue(settings.squareDirectionsOrder.join(""));
text.inputEl.onblur = async () => {
const value = text.getValue();
if (
value.length === 5 &&
value.includes("0") &&
value.includes("1") &&
value.includes("2") &&
value.includes("3") &&
value.includes("4")
) {
settings.squareDirectionsOrder = value
.split("")
.map((order) => Number.parseInt(order));
await plugin.saveSettings();
await plugin.getActiveTYPEView(MATRIX_VIEW).draw();
} else {
new Notice(
'The value must be a 5 digit number using only the digits "0", "1", "2", "3", "4"'
);
}
};
});

new Setting(MLViewDetails)
.setName("Enable Alpahebtical Sorting")
.setDesc(
Expand Down
38 changes: 18 additions & 20 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "./constants";
import { getOppDir, getReflexiveClosure, getSubInDirs } from "./graphUtils";
import type {
BCSettings,
Directions,
internalLinkObj,
SquareProps,
Expand Down Expand Up @@ -105,13 +104,15 @@ export default class MatrixView extends ItemView {
getOrder = (node: string) =>
Number.parseInt(this.plugin.mainG.getNodeAttribute(node, "order"));

getHierSquares(
userHiers: UserHier[],
currFile: TFile,
settings: BCSettings
): SquareProps[][] {
getHierSquares(userHiers: UserHier[], currFile: TFile): SquareProps[][] {
const { plugin } = this;
const { mainG } = plugin;
const { mainG, settings } = plugin;
const {
alphaSortAsc,
enableAlphaSort,
treatCurrNodeAsImpliedSibling,
squareDirectionsOrder,
} = settings;
if (!mainG) return [];

const { basename } = currFile;
Expand Down Expand Up @@ -168,8 +169,7 @@ export default class MatrixView extends ItemView {
closedUp.forEachOutEdge(basename, (k, a, s, par) => {
if (hier.up.includes(a.field)) {
closedUp.forEachInEdge(par, (k, a, s, t) => {
if (s === basename && !settings.treatCurrNodeAsImpliedSibling)
return;
if (s === basename && !treatCurrNodeAsImpliedSibling) return;
iSamesII.push(this.toInternalLinkObj(s, false, t));
});
}
Expand Down Expand Up @@ -200,10 +200,9 @@ export default class MatrixView extends ItemView {
? hier[dir].join(", ")
: `${hier[getOppDir(dir)].join(",")}${ARROW_DIRECTIONS[dir]}`;

const { alphaSortAsc } = settings;
const squares = [ru, rs, rd, rn, rp, iu, is, id, iN, ip];

if (settings.enableAlphaSort) {
if (enableAlphaSort) {
squares.forEach((sq) =>
sq.sort((a, b) =>
(a.alt ?? a.to) < (b.alt ?? b.to)
Expand Down Expand Up @@ -231,7 +230,7 @@ export default class MatrixView extends ItemView {
{ ip },
]);

return [
const square = [
{
realItems: ru,
impliedItems: iu,
Expand Down Expand Up @@ -260,6 +259,8 @@ export default class MatrixView extends ItemView {
field: getFieldInHier("prev"),
},
];

return squareDirectionsOrder.map((order) => square[order]);
});
}

Expand Down Expand Up @@ -312,14 +313,11 @@ export default class MatrixView extends ItemView {
}
);

const hierSquares = this.getHierSquares(
userHiers,
currFile,
settings
).filter((squareArr) =>
squareArr.some(
(square) => square.realItems.length + square.impliedItems.length > 0
)
const hierSquares = this.getHierSquares(userHiers, currFile).filter(
(squareArr) =>
squareArr.some(
(sq) => sq.realItems.length + sq.impliedItems.length > 0
)
);

const compInput = {
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
showTrail: true,
showGrid: true,
showPrevNext: true,
squareDirectionsOrder: [0, 1, 2, 3, 4],
limitTrailCheckboxes: [],
limitJumpToFirstFields: [],
showAll: false,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface BCSettings {
showPrevNext: boolean;
showRefreshNotice: boolean;
showTrail: boolean;
squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[];
trailSeperator: string;
treatCurrNodeAsImpliedSibling: boolean;
trimDendronNotes: boolean;
Expand Down

0 comments on commit ca3c35b

Please sign in to comment.