Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PR #1

Merged
merged 18 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "breadcrumbs",
"name": "Breadcrumbs",
"version": "4.2.11-beta",
"version": "4.2.18-beta",
"minAppVersion": "1.0.0",
"description": "Add structured hierarchies to your notes",
"author": "SkepticMystic",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breadcrumbs",
"version": "4.2.11-beta",
"version": "4.2.18-beta",
"description": "Add typed-links to your Obsidian notes",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 4 additions & 6 deletions src/codeblocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ const parse_source = (
issue.path.join("."),
).map((issue) => ({
message: issue.message,
path: issue.path.join("."),
code: "invalid_field_value" as const,
path: issue.path
.map((key) => (typeof key === "number" ? key + 1 : key))
.join(" > "),
})),
);

Expand All @@ -68,11 +70,7 @@ const parse_source = (
errors.push({
path: "yaml",
code: "invalid_yaml",
message: CodeblockSchema.error.zod_invalid_enum_msg(
"yaml" as any,
CodeblockSchema.FIELDS,
invalid_fields.join(", "),
),
message: `The following is not a valid codeblock field: \`${invalid_fields[0]}\`. Valid options are: ${CodeblockSchema.FIELDS.join(", ")}`,
});
}

Expand Down
26 changes: 25 additions & 1 deletion src/codeblocks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const FIELDS = [
"show-attributes",
"mermaid-direction",
"mermaid-renderer",
"mermaid-curve",
] as const;
type CodeblockField = (typeof FIELDS)[number];

Expand Down Expand Up @@ -150,7 +151,7 @@ const build = (input: Record<string, unknown>, data: InputData) => {
input["merge-fields"],
),
})
.default(false),
.default(true),

content: z
.enum(["open", "closed"], {
Expand Down Expand Up @@ -190,6 +191,15 @@ const build = (input: Record<string, unknown>, data: InputData) => {
),
})
.optional(),
"mermaid-curve": z
.enum(Mermaid.CURVE_STYLES, {
message: zod_invalid_enum_msg(
"mermaid-curve",
Mermaid.CURVE_STYLES,
input["mermaid-curve"],
),
})
.optional(),

"show-attributes": z
.array(z.enum(EDGE_ATTRIBUTES), {
Expand Down Expand Up @@ -336,6 +346,20 @@ const build = (input: Record<string, unknown>, data: InputData) => {
}

return options;
})
.superRefine((options, ctx) => {
if (options["mermaid-curve"] && options["mermaid-renderer"]) {
ctx.addIssue({
code: "custom",
path: ["mermaid-curve"],
message: `Cannot specify both a mermaid curve and a renderer. _Try removing one of the fields._
**Example**: \`mermaid-curve: ${options["mermaid-curve"]}\`, or \`mermaid-renderer: ${options["mermaid-renderer"]}\``,
});

return false;
}

return true;
});
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/codeblocks/CodeblockErrors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
codeblock docs
</a> for more info
</p>

<p>
Version: <code>{plugin.manifest.version}</code>
</p>
{/if}
1 change: 1 addition & 0 deletions src/components/codeblocks/CodeblockMermaid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<MermaidDiagram {plugin} {mermaid} source_path={file_path} />
</div>
{:else}
<!-- TODO(HELP-MSG) -->
<p class="search-empty-state">No paths found.</p>
{/if}
</div>
1 change: 1 addition & 0 deletions src/components/codeblocks/CodeblockTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
</div>
</div>
{:else}
<!-- TODO(HELP-MSG) -->
<p class="search-empty-state">No paths found</p>
{/if}
</div>
8 changes: 4 additions & 4 deletions src/components/settings/TransitiveImpliedRelations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
const new_length = transitives.push({
name: "",
chain: [],
rounds: 1,
// NOTE: Max by default, users can lower if needed
// It seems to fit with intuition that the implied relations just keep going
rounds: 10,
close_reversed: false,
close_field: settings.edge_fields[0].label,
});
Expand Down Expand Up @@ -212,9 +214,7 @@
<div class="flex items-center gap-2">
<ChevronOpener open={opens[rule_i]} />

<code>
{name} ({rule.rounds} rounds)
</code>
<code> {name} </code>
</div>

<div class="flex gap-1">
Expand Down
10 changes: 5 additions & 5 deletions src/const/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,35 @@ export const DEFAULT_SETTINGS: BreadcrumbsSettings = {
implied_relations: {
transitive: [
{
name: "Opposite Direction: up/down",
name: "",
rounds: 1,
chain: [{ field: "up" }],
close_field: "down",
close_reversed: true,
},
{
name: "Opposite Direction: down/up",
name: "",
rounds: 1,
chain: [{ field: "down" }],
close_field: "up",
close_reversed: true,
},
{
name: "Opposite Direction: same/same",
name: "",
rounds: 1,
chain: [{ field: "same" }],
close_field: "same",
close_reversed: true,
},
{
name: "Opposite Direction: next/prev",
name: "",
rounds: 1,
chain: [{ field: "next" }],
close_field: "prev",
close_reversed: true,
},
{
name: "Opposite Direction: prev/next",
name: "",
rounds: 1,
chain: [{ field: "prev" }],
close_field: "next",
Expand Down
22 changes: 11 additions & 11 deletions src/graph/builders/explicit/dataview_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
import { log } from "src/logger";
import type BreadcrumbsPlugin from "src/main";
import { fail, graph_build_fail, succ } from "src/utils/result";
import { GraphConstructionEdgeData } from "wasm/pkg/breadcrumbs_graph_wasm";

const get_dataview_note_info = (
plugin: BreadcrumbsPlugin,
Expand Down Expand Up @@ -58,7 +59,7 @@ export const _add_explicit_edges_dataview_note: ExplicitEdgeBuilder = (
plugin,
all_files,
) => {
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] }
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] };

all_files.obsidian?.forEach(
({ file: dataview_note_file, cache: dataview_note_cache }) => {
Expand Down Expand Up @@ -90,7 +91,8 @@ export const _add_explicit_edges_dataview_note: ExplicitEdgeBuilder = (
dataview_note_path,
);
if (!dataview_note_info.ok) {
if (dataview_note_info.error) results.errors.push(dataview_note_info.error);
if (dataview_note_info.error)
results.errors.push(dataview_note_info.error);
return;
}
const { field, query } = dataview_note_info.data;
Expand All @@ -114,18 +116,16 @@ export const _add_explicit_edges_dataview_note: ExplicitEdgeBuilder = (

pages.forEach((page) => {
// NOTE: I _believe_ we don't need to even safe_add_node, since dv will only return resolved notes
results.edges.push({
source_id: dataview_note_page.file.path,
target_id: page.file.path,
attr: {
results.edges.push(
new GraphConstructionEdgeData(
dataview_note_page.file.path,
page.file.path,
field,
explicit: true,
source: "dataview_note",
},
}
"dataview_note",
),
);
});
});

return results
return results;
};
42 changes: 27 additions & 15 deletions src/graph/builders/explicit/date_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ import type {
ExplicitEdgeBuilder,
} from "src/interfaces/graph";
import { Paths } from "src/utils/paths";
import {
GraphConstructionEdgeData,
GraphConstructionNodeData,
} from "wasm/pkg/breadcrumbs_graph_wasm";

// TODO: Option to point up to month, (and for month to point up to year?)

export const _add_explicit_edges_date_note: ExplicitEdgeBuilder = (
plugin,
all_files,
) => {
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] }
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] };

const date_note_settings = plugin.settings.explicit_edge_sources.date_note;
if (!date_note_settings.enabled) { return results }
else if (
if (!date_note_settings.enabled) {
return results;
} else if (
!plugin.settings.edge_fields.find(
(field) => field.label === date_note_settings.default_field,
)
Expand All @@ -26,7 +31,7 @@ export const _add_explicit_edges_date_note: ExplicitEdgeBuilder = (
message: `The default Date Note field "${date_note_settings.default_field}" is not a valid Breadcrumbs Edge field`,
});

return results
return results;
}

const date_notes: {
Expand Down Expand Up @@ -94,19 +99,26 @@ export const _add_explicit_edges_date_note: ExplicitEdgeBuilder = (
// NOTE: We have a full path, so we can go straight to the file without the given source_path
const target_file = plugin.app.vault.getFileByPath(target_id);
if (!target_file) {
results.nodes.push({ id: target_id, attr: { resolved: false } });
results.nodes.push(
new GraphConstructionNodeData(
target_id,
[],
false,
false,
false,
),
);
}

results.edges.push({
target_id,
source_id: date_note.path,
attr: {
explicit: true,
source: "date_note",
field: date_note_settings.default_field,
}
});
results.edges.push(
new GraphConstructionEdgeData(
target_id,
date_note.path,
date_note_settings.default_field,
"date_note",
),
);
});

return results
return results;
};
30 changes: 17 additions & 13 deletions src/graph/builders/explicit/dendron_note.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { META_ALIAS } from "src/const/metadata_fields";
// import type { BCGraph } from "src/graph/MyMultiGraph";
import type {
BreadcrumbsError,
EdgeBuilderResults,
ExplicitEdgeBuilder,
} from "src/interfaces/graph";
import type BreadcrumbsPlugin from "src/main";
import { Paths } from "src/utils/paths";
import { fail, graph_build_fail, succ } from "src/utils/result";
import {
GraphConstructionEdgeData,
GraphConstructionNodeData,
} from "wasm/pkg/breadcrumbs_graph_wasm";

const get_dendron_note_info = (
plugin: BreadcrumbsPlugin,
Expand Down Expand Up @@ -86,7 +89,9 @@ const handle_dendron_note = (
const target_file = plugin.app.vault.getFileByPath(target_id);

if (!target_file) {
results.nodes.push({ id: target_id, attr: { resolved: false } });
results.nodes.push(
new GraphConstructionNodeData(target_id, [], false, false, false),
);

// If !target_file, we can recursively call handle_dendron_note
// To add the unresolved edges along the way
Expand All @@ -102,25 +107,24 @@ const handle_dendron_note = (
);
}

results.edges.push({
source_id,
target_id,
attr: {
results.edges.push(
new GraphConstructionEdgeData(
source_id,
target_id,
field,
explicit: true,
source: "dendron_note",
}
});
"dendron_note",
),
);
};

export const _add_explicit_edges_dendron_note: ExplicitEdgeBuilder = (
plugin,
all_files,
) => {
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] }
const results: EdgeBuilderResults = { nodes: [], edges: [], errors: [] };

if (!plugin.settings.explicit_edge_sources.dendron_note.enabled) {
return results
return results;
}

all_files.obsidian?.forEach(({ file, cache }) => {
Expand All @@ -131,5 +135,5 @@ export const _add_explicit_edges_dendron_note: ExplicitEdgeBuilder = (
handle_dendron_note(plugin, results, page.file.path, page);
});

return results
return results;
};
Loading