Skip to content

Commit

Permalink
fix(Path View): 🐛 Show aliases in Path/Grid view, too (fix #212)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 9, 2022
1 parent 41373e2 commit 55a6f60
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 45 deletions.
104 changes: 62 additions & 42 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22662,7 +22662,26 @@ function strToRegex(input) {
return null;
}
}
const dropHash = (tag) => tag.startsWith("#") ? tag.slice(1) : tag;
const dropHash = (tag) => tag.startsWith("#") ? tag.slice(1) : tag;
function getAlt(node, plugin) {
var _a;
const { app } = plugin;
const { altLinkFields, showAllAliases } = plugin.settings;
if (altLinkFields.length) {
const file = app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _a === void 0 ? void 0 : _a[altField];
const arr = typeof value === "string" ? splitAndTrim(value) : value;
if (value)
return showAllAliases ? arr.join(", ") : arr[0];
}
}
}
else
return null;
}

/* node_modules\svelte-icons\components\IconBase.svelte generated by Svelte v3.35.0 */

Expand Down Expand Up @@ -26925,7 +26944,7 @@ function get_each_context_2$1(ctx, list, i) {
// (81:8) {#if step.value && settings.gridDots}
function create_if_block$3(ctx) {
let div;
let each_value_2 = lodash.range(Math.floor(/*wordCounts*/ ctx[2][/*step*/ ctx[24].value] / 1000));
let each_value_2 = lodash.range(Math.floor(/*wordCounts*/ ctx[3][/*step*/ ctx[24].value] / 1000));
let each_blocks = [];

for (let i = 0; i < each_value_2.length; i += 1) {
Expand All @@ -26950,8 +26969,8 @@ function create_if_block$3(ctx) {
}
},
p(ctx, dirty) {
if (dirty & /*settings, wordCounts*/ 20) {
each_value_2 = lodash.range(Math.floor(/*wordCounts*/ ctx[2][/*step*/ ctx[24].value] / 1000));
if (dirty & /*settings, wordCounts*/ 40) {
each_value_2 = lodash.range(Math.floor(/*wordCounts*/ ctx[3][/*step*/ ctx[24].value] / 1000));
let i;

for (i = 0; i < each_value_2.length; i += 1) {
Expand Down Expand Up @@ -26988,7 +27007,7 @@ function create_each_block_2$1(ctx) {
c() {
span = element("span");
attr(span, "class", "dot svelte-ybyqyo");
set_style(span, "background-color", /*settings*/ ctx[4].dotsColour);
set_style(span, "background-color", /*settings*/ ctx[5].dotsColour);
},
m(target, anchor) {
insert(target, span, anchor);
Expand All @@ -27004,7 +27023,7 @@ function create_each_block_2$1(ctx) {
function create_each_block_1$4(ctx) {
let div1;
let div0;
let t0_value = dropDendron(/*step*/ ctx[24].value, /*settings*/ ctx[4]) + "";
let t0_value = (getAlt(/*step*/ ctx[24].value, /*plugin*/ ctx[2]) ?? dropDendron(/*step*/ ctx[24].value, /*settings*/ ctx[5])) + "";
let t0;
let div0_class_value;
let t1;
Expand All @@ -27013,7 +27032,7 @@ function create_each_block_1$4(ctx) {
let div1_style_value;
let mounted;
let dispose;
let if_block = /*step*/ ctx[24].value && /*settings*/ ctx[4].gridDots && create_if_block$3(ctx);
let if_block = /*step*/ ctx[24].value && /*settings*/ ctx[5].gridDots && create_if_block$3(ctx);

function click_handler(...args) {
return /*click_handler*/ ctx[9](/*step*/ ctx[24], ...args);
Expand All @@ -27034,8 +27053,8 @@ function create_each_block_1$4(ctx) {
attr(div0, "class", div0_class_value = "" + (null_to_empty(linkClass(/*app*/ ctx[1], /*step*/ ctx[24].value)) + " svelte-ybyqyo"));
attr(div1, "class", div1_class_value = "BC-trail-grid-item " + (/*step*/ ctx[24].value === "" ? "BC-filler" : "") + " svelte-ybyqyo");

attr(div1, "style", div1_style_value = "\r\n grid-area: " + (/*step*/ ctx[24].first + 1) + " / " + (/*i*/ ctx[23] + 1) + " / \r\n " + (/*step*/ ctx[24].last + 2) + " / " + (/*i*/ ctx[23] + 2) + ";\r\n " + (/*settings*/ ctx[4].gridHeatmap
? `background-color: ${/*settings*/ ctx[4].heatmapColour}${Math.round(/*children*/ ctx[3][/*step*/ ctx[24].value] * 200 + 55).toString(16)}`
attr(div1, "style", div1_style_value = "\r\n grid-area: " + (/*step*/ ctx[24].first + 1) + " / " + (/*i*/ ctx[23] + 1) + " / \r\n " + (/*step*/ ctx[24].last + 2) + " / " + (/*i*/ ctx[23] + 2) + ";\r\n " + (/*settings*/ ctx[5].gridHeatmap
? `background-color: ${/*settings*/ ctx[5].heatmapColour}${Math.round(/*children*/ ctx[4][/*step*/ ctx[24].value] * 200 + 55).toString(16)}`
: ""));
},
m(target, anchor) {
Expand All @@ -27057,15 +27076,16 @@ function create_each_block_1$4(ctx) {
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty & /*plugin*/ 4 && t0_value !== (t0_value = (getAlt(/*step*/ ctx[24].value, /*plugin*/ ctx[2]) ?? dropDendron(/*step*/ ctx[24].value, /*settings*/ ctx[5])) + "")) set_data(t0, t0_value);

if (dirty & /*app*/ 2 && div0_class_value !== (div0_class_value = "" + (null_to_empty(linkClass(/*app*/ ctx[1], /*step*/ ctx[24].value)) + " svelte-ybyqyo"))) {
attr(div0, "class", div0_class_value);
}

if (/*step*/ ctx[24].value && /*settings*/ ctx[4].gridDots) if_block.p(ctx, dirty);
if (/*step*/ ctx[24].value && /*settings*/ ctx[5].gridDots) if_block.p(ctx, dirty);

if (dirty & /*children*/ 8 && div1_style_value !== (div1_style_value = "\r\n grid-area: " + (/*step*/ ctx[24].first + 1) + " / " + (/*i*/ ctx[23] + 1) + " / \r\n " + (/*step*/ ctx[24].last + 2) + " / " + (/*i*/ ctx[23] + 2) + ";\r\n " + (/*settings*/ ctx[4].gridHeatmap
? `background-color: ${/*settings*/ ctx[4].heatmapColour}${Math.round(/*children*/ ctx[3][/*step*/ ctx[24].value] * 200 + 55).toString(16)}`
if (dirty & /*children*/ 16 && div1_style_value !== (div1_style_value = "\r\n grid-area: " + (/*step*/ ctx[24].first + 1) + " / " + (/*i*/ ctx[23] + 1) + " / \r\n " + (/*step*/ ctx[24].last + 2) + " / " + (/*i*/ ctx[23] + 2) + ";\r\n " + (/*settings*/ ctx[5].gridHeatmap
? `background-color: ${/*settings*/ ctx[5].heatmapColour}${Math.round(/*children*/ ctx[4][/*step*/ ctx[24].value] * 200 + 55).toString(16)}`
: ""))) {
attr(div1, "style", div1_style_value);
}
Expand All @@ -27082,7 +27102,7 @@ function create_each_block_1$4(ctx) {
// (63:2) {#each transposedTrails as col, i}
function create_each_block$5(ctx) {
let each_1_anchor;
let each_value_1 = /*allRuns*/ ctx[7][/*i*/ ctx[23]];
let each_value_1 = /*allRuns*/ ctx[8][/*i*/ ctx[23]];
let each_blocks = [];

for (let i = 0; i < each_value_1.length; i += 1) {
Expand All @@ -27105,8 +27125,8 @@ function create_each_block$5(ctx) {
insert(target, each_1_anchor, anchor);
},
p(ctx, dirty) {
if (dirty & /*allRuns, settings, Math, children, openOrSwitch, app, hoverPreview, activeLeafView, range, wordCounts, linkClass, dropDendron*/ 190) {
each_value_1 = /*allRuns*/ ctx[7][/*i*/ ctx[23]];
if (dirty & /*allRuns, settings, Math, children, openOrSwitch, app, hoverPreview, activeLeafView, range, wordCounts, linkClass, getAlt, plugin, dropDendron*/ 382) {
each_value_1 = /*allRuns*/ ctx[8][/*i*/ ctx[23]];
let i;

for (i = 0; i < each_value_1.length; i += 1) {
Expand Down Expand Up @@ -27137,7 +27157,7 @@ function create_each_block$5(ctx) {

function create_fragment$9(ctx) {
let div;
let each_value = /*transposedTrails*/ ctx[6];
let each_value = /*transposedTrails*/ ctx[7];
let each_blocks = [];

for (let i = 0; i < each_value.length; i += 1) {
Expand All @@ -27153,7 +27173,7 @@ function create_fragment$9(ctx) {
}

attr(div, "class", "BC-trail-grid svelte-ybyqyo");
set_style(div, "grid-template-columns", ("1fr ").repeat(/*transposedTrails*/ ctx[6].length));
set_style(div, "grid-template-columns", ("1fr ").repeat(/*transposedTrails*/ ctx[7].length));
set_style(div, "grid-template-rows", ("1fr ").repeat(/*sortedTrails*/ ctx[0].length));
},
m(target, anchor) {
Expand All @@ -27164,8 +27184,8 @@ function create_fragment$9(ctx) {
}
},
p(ctx, [dirty]) {
if (dirty & /*allRuns, settings, Math, children, openOrSwitch, app, hoverPreview, activeLeafView, range, wordCounts, linkClass, dropDendron*/ 190) {
each_value = /*transposedTrails*/ ctx[6];
if (dirty & /*allRuns, settings, Math, children, openOrSwitch, app, hoverPreview, activeLeafView, range, wordCounts, linkClass, getAlt, plugin, dropDendron*/ 382) {
each_value = /*transposedTrails*/ ctx[7];
let i;

for (i = 0; i < each_value.length; i += 1) {
Expand Down Expand Up @@ -27217,15 +27237,15 @@ function instance$9($$self, $$props, $$invalidate) {

try {
$$invalidate(
2,
3,
wordCounts[cell] = (_a = app.metadataCache.getFirstLinkpathDest(cell, "")) === null || _a === void 0
? void 0
: _a.stat.size,
wordCounts
);
} catch(error) {
console.log(error, { currFile });
$$invalidate(2, wordCounts[cell] = 0, wordCounts);
$$invalidate(3, wordCounts[cell] = 0, wordCounts);
}
});

Expand All @@ -27236,11 +27256,11 @@ function instance$9($$self, $$props, $$invalidate) {
const [up, down] = [getSubInDirs(mainG, "up"), getSubInDirs(mainG, "down")];
const closedParents = closeImpliedLinks(up, down);
const children = {};
allCells.forEach(cell => $$invalidate(3, children[cell] = getOutNeighbours(closedParents, cell).length, children));
allCells.forEach(cell => $$invalidate(4, children[cell] = getOutNeighbours(closedParents, cell).length, children));
const normalisedData = normalise(Object.values(children));

allCells.forEach((cell, i) => {
$$invalidate(3, children[cell] = normalisedData[i], children);
$$invalidate(4, children[cell] = normalisedData[i], children);
});

// const normalisedData = allCells.forEach(cell => {
Expand Down Expand Up @@ -27268,19 +27288,19 @@ function instance$9($$self, $$props, $$invalidate) {
$$self.$$set = $$props => {
if ("sortedTrails" in $$props) $$invalidate(0, sortedTrails = $$props.sortedTrails);
if ("app" in $$props) $$invalidate(1, app = $$props.app);
if ("plugin" in $$props) $$invalidate(8, plugin = $$props.plugin);
if ("plugin" in $$props) $$invalidate(2, plugin = $$props.plugin);
};

return [
sortedTrails,
app,
plugin,
wordCounts,
children,
settings,
activeLeafView,
transposedTrails,
allRuns,
plugin,
click_handler,
mouseover_handler
];
Expand All @@ -27290,7 +27310,7 @@ class TrailGrid extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-ybyqyo-style")) add_css$5();
init(this, options, instance$9, create_fragment$9, safe_not_equal, { sortedTrails: 0, app: 1, plugin: 8 });
init(this, options, instance$9, create_fragment$9, safe_not_equal, { sortedTrails: 0, app: 1, plugin: 2 });
}
}

Expand Down Expand Up @@ -27342,7 +27362,7 @@ function create_else_block$2(ctx) {
insert(target, each_1_anchor, anchor);
},
p(ctx, dirty) {
if (dirty & /*settings, trailsToShow, openOrSwitch, app, hoverPreview, view, dropDendron*/ 58) {
if (dirty & /*settings, trailsToShow, openOrSwitch, app, hoverPreview, view, getAlt, plugin, dropDendron*/ 118) {
each_value_1 = /*trail*/ ctx[10];
let i;

Expand Down Expand Up @@ -27379,7 +27399,7 @@ function create_if_block_1$2(ctx) {
return {
c() {
span = element("span");
span.textContent = `${/*settings*/ ctx[4].noPathMessage}`;
span.textContent = `${/*settings*/ ctx[5].noPathMessage}`;
},
m(target, anchor) {
insert(target, span, anchor);
Expand All @@ -27398,7 +27418,7 @@ function create_if_block_2$1(ctx) {
return {
c() {
span = element("span");
span.textContent = `${" " + /*settings*/ ctx[4].trailSeperator + " "}`;
span.textContent = `${" " + /*settings*/ ctx[5].trailSeperator + " "}`;
},
m(target, anchor) {
insert(target, span, anchor);
Expand All @@ -27413,7 +27433,7 @@ function create_if_block_2$1(ctx) {
// (21:10) {#each trail as crumb, i}
function create_each_block_1$3(ctx) {
let span;
let t0_value = dropDendron(/*crumb*/ ctx[13], /*settings*/ ctx[4]) + "";
let t0_value = (getAlt(/*crumb*/ ctx[13], /*plugin*/ ctx[2]) ?? dropDendron(/*crumb*/ ctx[13], /*settings*/ ctx[5])) + "";
let t0;
let t1;
let if_block_anchor;
Expand Down Expand Up @@ -27457,7 +27477,7 @@ function create_each_block_1$3(ctx) {
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty & /*trailsToShow*/ 8 && t0_value !== (t0_value = dropDendron(/*crumb*/ ctx[13], /*settings*/ ctx[4]) + "")) set_data(t0, t0_value);
if (dirty & /*trailsToShow, plugin*/ 20 && t0_value !== (t0_value = (getAlt(/*crumb*/ ctx[13], /*plugin*/ ctx[2]) ?? dropDendron(/*crumb*/ ctx[13], /*settings*/ ctx[5])) + "")) set_data(t0, t0_value);

if (/*i*/ ctx[15] < /*trail*/ ctx[10].length - 1) {
if (if_block) {
Expand Down Expand Up @@ -27531,7 +27551,7 @@ function create_each_block$4(ctx) {
function create_if_block$2(ctx) {
let div;
let button;
let t_value = (/*showAll*/ ctx[2] ? "Shortest" : "All") + "";
let t_value = (/*showAll*/ ctx[3] ? "Shortest" : "All") + "";
let t;
let mounted;
let dispose;
Expand All @@ -27554,7 +27574,7 @@ function create_if_block$2(ctx) {
}
},
p(ctx, dirty) {
if (dirty & /*showAll*/ 4 && t_value !== (t_value = (/*showAll*/ ctx[2] ? "Shortest" : "All") + "")) set_data(t, t_value);
if (dirty & /*showAll*/ 8 && t_value !== (t_value = (/*showAll*/ ctx[3] ? "Shortest" : "All") + "")) set_data(t, t_value);
},
d(detaching) {
if (detaching) detach(div);
Expand All @@ -27568,7 +27588,7 @@ function create_fragment$8(ctx) {
let span;
let div;
let t;
let each_value = /*trailsToShow*/ ctx[3];
let each_value = /*trailsToShow*/ ctx[4];
let each_blocks = [];

for (let i = 0; i < each_value.length; i += 1) {
Expand Down Expand Up @@ -27603,8 +27623,8 @@ function create_fragment$8(ctx) {
if (if_block) if_block.m(span, null);
},
p(ctx, [dirty]) {
if (dirty & /*settings, trailsToShow, openOrSwitch, app, hoverPreview, view, dropDendron*/ 58) {
each_value = /*trailsToShow*/ ctx[3];
if (dirty & /*settings, trailsToShow, openOrSwitch, app, hoverPreview, view, getAlt, plugin, dropDendron*/ 118) {
each_value = /*trailsToShow*/ ctx[4];
let i;

for (i = 0; i < each_value.length; i += 1) {
Expand Down Expand Up @@ -27661,28 +27681,28 @@ function instance$8($$self, $$props, $$invalidate) {
let showAll = settings.showAll;
const click_handler = async (crumb, e) => await openOrSwitch(app, crumb, e);
const mouseover_handler = (crumb, e) => hoverPreview(e, view, crumb);
const click_handler_1 = () => $$invalidate(2, showAll = !showAll);
const click_handler_1 = () => $$invalidate(3, showAll = !showAll);

$$self.$$set = $$props => {
if ("sortedTrails" in $$props) $$invalidate(0, sortedTrails = $$props.sortedTrails);
if ("app" in $$props) $$invalidate(1, app = $$props.app);
if ("plugin" in $$props) $$invalidate(6, plugin = $$props.plugin);
if ("plugin" in $$props) $$invalidate(2, plugin = $$props.plugin);
};

$$self.$$.update = () => {
if ($$self.$$.dirty & /*showAll, sortedTrails*/ 5) {
$$invalidate(3, trailsToShow = showAll ? sortedTrails : [sortedTrails[0]]);
if ($$self.$$.dirty & /*showAll, sortedTrails*/ 9) {
$$invalidate(4, trailsToShow = showAll ? sortedTrails : [sortedTrails[0]]);
}
};

return [
sortedTrails,
app,
plugin,
showAll,
trailsToShow,
settings,
view,
plugin,
click_handler,
mouseover_handler,
click_handler_1
Expand All @@ -27693,7 +27713,7 @@ class TrailPath extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-3c1frp-style")) add_css$4();
init(this, options, instance$8, create_fragment$8, safe_not_equal, { sortedTrails: 0, app: 1, plugin: 6 });
init(this, options, instance$8, create_fragment$8, safe_not_equal, { sortedTrails: 0, app: 1, plugin: 2 });
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Components/TrailGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import type BCPlugin from "../main";
import {
dropDendron,
getAlt,
linkClass,
normalise,
padArray,
runs,
splitAndTrim,
transpose,
} from "../sharedFunctions";
export let sortedTrails: string[][];
Expand Down Expand Up @@ -114,7 +116,7 @@
on:mouseover={(e) => hoverPreview(e, activeLeafView, step.value)}
>
<div class={linkClass(app, step.value)}>
{dropDendron(step.value, settings)}
{getAlt(step.value, plugin) ?? dropDendron(step.value, settings)}
</div>
{#if step.value && settings.gridDots}
<div class="dots">
Expand Down
4 changes: 2 additions & 2 deletions src/Components/TrailPath.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hoverPreview,
openOrSwitch,
} from "obsidian-community-lib/dist/utils";
import { dropDendron } from "../sharedFunctions";
import { dropDendron, getAlt, splitAndTrim } from "../sharedFunctions";
import type BCPlugin from "../main";
export let sortedTrails: string[][];
Expand Down Expand Up @@ -32,7 +32,7 @@
on:click={async (e) => await openOrSwitch(app, crumb, e)}
on:mouseover={(e) => hoverPreview(e, view, crumb)}
>
{dropDendron(crumb, settings)}
{getAlt(crumb, plugin) ?? dropDendron(crumb, settings)}
</span>
{#if i < trail.length - 1}
<span>{" " + settings.trailSeperator + " "}</span>
Expand Down
Loading

0 comments on commit 55a6f60

Please sign in to comment.