Skip to content

Commit

Permalink
fix(getFieldValues): 🐛 Handle DataArrays (dv proxies)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 10, 2021
1 parent 09e3c15 commit 63e57d7
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 37 deletions.
77 changes: 60 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict';

var obsidian = require('obsidian');
var util = require('util');
require('path');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var util__default = /*#__PURE__*/_interopDefaultLegacy(util);

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function createCommonjsModule(fn) {
Expand Down Expand Up @@ -6399,25 +6404,63 @@ function getFieldValues(frontmatterCache, field, settings) {
rawValues.forEach((rawItem) => {
if (!rawItem)
return;
if (typeof rawItem === "string" || typeof rawItem === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = rawItem.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) => link.match(dropHeaderOrAlias)[1].split("/").last());
values.push(...strs);
}
else {
values.push(rawItemAsString.split("/").last());
}
let unProxied = [rawItem];
if (util__default['default'].types.isProxy(rawItem)) {
unProxied = [];
// Definitely a proxy the first time
const firstValue = Object.assign({}, rawItem);
firstValue.values.forEach((firstVal) => {
if (util__default['default'].types.isProxy(firstVal)) {
const secondValue = Object.assign({}, firstVal);
const secondValues = secondValue.values;
if (secondValues) {
secondValues.forEach((secondVal) => {
if (util__default['default'].types.isProxy(secondVal)) {
const thirdValues = Object.assign({}, secondVal).values;
thirdValues.forEach((thirdVal) => {
unProxied.push(thirdVal);
});
}
else {
if (typeof secondValues === "string") {
unProxied.push(secondValues);
}
else {
unProxied.push(...secondValues);
}
}
});
}
else {
unProxied.push(secondValue);
}
}
else {
unProxied.push(firstVal);
}
});
}
else if (rawItem.path !== undefined) {
superDebug(settings, { rawItem });
const lastSplit = rawItem.path.split("/").last();
if (lastSplit !== undefined) {
values.push(lastSplit);
unProxied.forEach((value) => {
console.log({ unproxiedValue: value });
if (typeof value === "string" || typeof value === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = value.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) => link.match(dropHeaderOrAlias)[1].split("/").last());
values.push(...strs);
}
else {
values.push(rawItemAsString.split("/").last());
}
}
}
else if (value.path !== undefined) {
const lastSplit = value.path.split("/").last();
if (lastSplit !== undefined) {
values.push(lastSplit);
}
}
});
});
}
return values;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"graphlib": "^2.1.8",
"hierarchy-js": "^1.0.4",
"juggl-api": "git+https://github.com/HEmile/juggl-api.git",
"nodejs": "^0.0.0",
"svelte": "3.35.0"
}
}
77 changes: 57 additions & 20 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
} from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import type MatrixView from "src/MatrixView";
import util from "util";

export function sum(arr: number[]): number {
return arr.reduce((a, b) => a + b);
Expand Down Expand Up @@ -243,33 +244,69 @@ export function getFieldValues(
// Dont't add anything, it's not a link
// }
} else {
const rawValues: (string | number | dvLink | Pos | TFile | undefined)[] =
[rawValuesPreFlat].flat(4);
type RawValue = string | number | dvLink | Pos | TFile | undefined;
const rawValues: (RawValue | typeof Proxy)[] = [rawValuesPreFlat].flat(4);

superDebug(settings, `${field} of: ${frontmatterCache?.file?.path}`);
superDebug(settings, rawValues);

rawValues.forEach((rawItem) => {
if (!rawItem) return;
if (typeof rawItem === "string" || typeof rawItem === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = rawItem.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) =>
link.match(dropHeaderOrAlias)[1].split("/").last()
);
values.push(...strs);
} else {
values.push(rawItemAsString.split("/").last());
}
} else if (rawItem.path !== undefined) {
superDebug(settings, { rawItem });
const lastSplit = rawItem.path.split("/").last();
if (lastSplit !== undefined) {
values.push(lastSplit);
}

let unProxied = [rawItem];
if (util.types.isProxy(rawItem)) {
unProxied = [];

// Definitely a proxy the first time
const firstValue = Object.assign({}, rawItem);
firstValue.values.forEach((firstVal: RawValue | typeof Proxy) => {
if (util.types.isProxy(firstVal)) {
const secondValue = Object.assign({}, firstVal);
const secondValues = secondValue.values;
if (secondValues) {
secondValues.forEach((secondVal: RawValue | typeof Proxy) => {
if (util.types.isProxy(secondVal)) {
const thirdValues = Object.assign({}, secondVal).values;
thirdValues.forEach((thirdVal: RawValue | typeof Proxy) => {
unProxied.push(thirdVal);
});
} else {
if (typeof secondValues === "string") {
unProxied.push(secondValues);
} else {
unProxied.push(...secondValues);
}
}
});
} else {
unProxied.push(secondValue);
}
} else {
unProxied.push(firstVal);
}
});
}
unProxied.forEach((value) => {
console.log({ unproxiedValue: value });
if (typeof value === "string" || typeof value === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = value.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) =>
link.match(dropHeaderOrAlias)[1].split("/").last()
);
values.push(...strs);
} else {
values.push(rawItemAsString.split("/").last());
}
} else if (value.path !== undefined) {
const lastSplit = value.path.split("/").last();
if (lastSplit !== undefined) {
values.push(lastSplit);
}
}
});
});
}
return values;
Expand Down

0 comments on commit 63e57d7

Please sign in to comment.