From 55a6f60a8e42f8d73b7f9ee26d49658056c89489 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 9 Jan 2022 20:58:35 +0200 Subject: [PATCH] fix(Path View): :bug: Show aliases in Path/Grid view, too (fix #212) --- main.js | 104 +++++++++++++++++++------------- src/Components/TrailGrid.svelte | 4 +- src/Components/TrailPath.svelte | 4 +- src/sharedFunctions.ts | 18 ++++++ 4 files changed, 85 insertions(+), 45 deletions(-) diff --git a/main.js b/main.js index 3276343e..593344f3 100644 --- a/main.js +++ b/main.js @@ -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 */ @@ -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) { @@ -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) { @@ -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); @@ -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; @@ -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); @@ -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) { @@ -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); } @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -27217,7 +27237,7 @@ 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, @@ -27225,7 +27245,7 @@ function instance$9($$self, $$props, $$invalidate) { ); } catch(error) { console.log(error, { currFile }); - $$invalidate(2, wordCounts[cell] = 0, wordCounts); + $$invalidate(3, wordCounts[cell] = 0, wordCounts); } }); @@ -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 => { @@ -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 ]; @@ -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 }); } } @@ -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; @@ -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); @@ -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); @@ -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; @@ -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) { @@ -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; @@ -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); @@ -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) { @@ -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) { @@ -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 @@ -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 }); } } diff --git a/src/Components/TrailGrid.svelte b/src/Components/TrailGrid.svelte index 0924b356..63ab18de 100644 --- a/src/Components/TrailGrid.svelte +++ b/src/Components/TrailGrid.svelte @@ -13,10 +13,12 @@ import type BCPlugin from "../main"; import { dropDendron, + getAlt, linkClass, normalise, padArray, runs, + splitAndTrim, transpose, } from "../sharedFunctions"; export let sortedTrails: string[][]; @@ -114,7 +116,7 @@ on:mouseover={(e) => hoverPreview(e, activeLeafView, step.value)} >
- {dropDendron(step.value, settings)} + {getAlt(step.value, plugin) ?? dropDendron(step.value, settings)}
{#if step.value && settings.gridDots}
diff --git a/src/Components/TrailPath.svelte b/src/Components/TrailPath.svelte index 2b1a887f..97863a10 100644 --- a/src/Components/TrailPath.svelte +++ b/src/Components/TrailPath.svelte @@ -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[][]; @@ -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)} {#if i < trail.length - 1} {" " + settings.trailSeperator + " "} diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index c14a30c4..59281e5e 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -322,3 +322,21 @@ export function strToRegex(input: string) { export const dropHash = (tag: string) => tag.startsWith("#") ? tag.slice(1) : tag; + +export function getAlt(node: string, plugin: BCPlugin): string | null { + 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 = metadata?.frontmatter?.[altField]; + + const arr: string[] = + typeof value === "string" ? splitAndTrim(value) : value; + if (value) return showAllAliases ? arr.join(", ") : arr[0]; + } + } + } else return null; +}