Skip to content

Commit

Permalink
feat: Initial work on juggl code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Jan 12, 2022
1 parent 465103c commit e92021d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"graphology-traversal": "^0.2.2",
"graphology-types": "^0.23.0",
"hierarchy-js": "^1.0.4",
"juggl-api": "git+https://github.com/HEmile/juggl-api.git",
"juggl-api": "github:HEmile/juggl-api",
"loglevel": "^1.8.0",
"obsidian-community-lib": "^1.2.0",
"svelte": "3.35.0",
Expand Down
13 changes: 1 addition & 12 deletions src/Components/CBTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@
export let dir: Directions;
export let fields: string[];
export let title: string;
export let flat: string;
export let content: string;
export let index: any;
export let lines: [string, string][];
export let froms: string[];
export let min: number;
export let max: number;
export let basename: string;
const {settings, app} = plugin;
const lines = index
.split("\n")
.map((line) => {
const pair = line.split("- ");
return [flat === "true" ? "" : pair[0], pair.slice(1).join("- ")] as [
string,
string
];
})
.filter((pair) => pair[1] !== "");
const indentToDepth = (indent: string) => indent.length / 2 + 1;
Expand Down
41 changes: 40 additions & 1 deletion src/Visualisations/CBJuggl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import type {ParsedCodeblock} from "../interfaces";
import type BCPlugin from "../main";
import {getPlugin, IJugglSettings} from 'juggl-api';

export function createdJugglCB(target: HTMLElement, args: ParsedCodeblock) {
function indentToDepth(indent: string) {
return indent.length / 2 + 1;
}

function meetsConditions(indent: string, node: string, froms: string[], min: number, max: number) {
const depth = indentToDepth(indent);
return (
depth >= min &&
depth <= max &&
(froms === undefined || froms.includes(node))
);
}

export function createdJugglCB(plugin: BCPlugin,
target: HTMLElement,
args: ParsedCodeblock,
lines: [string, string][],
froms: string[],
min: number,
max: number) {
try {
const jugglPlugin = getPlugin(plugin.app);
if (!jugglPlugin) {
// TODO: Error handling
return;
}
const nodes = lines
.filter(([indent, node]) => meetsConditions(indent, node, froms, min, max))
.map(([_, node]) => node);
console.log({nodes})
const juggl = jugglPlugin.createJuggl(target, null, null, nodes)
console.log("Created juggl!")
plugin.addChild(juggl);
juggl.load();
console.log({juggl});
}
catch (error) {
plugin.codeblockError(args)
}
}
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ARROW_DIRECTIONS: { [dir in Directions]: string } = {
export const RELATIONS: Relations[] = ["Parent", "Sibling", "Child"];
export const REAlCLOSED = ["Real", "Closed"];
export const ALLUNLINKED = ["All", "No Unlinked"];
export const CODEBLOCK_TYPES = ["tree"];
export const CODEBLOCK_TYPES = ["tree", "juggl"];
export const CODEBLOCK_FIELDS = [
"type",
"dir",
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
import type DucksView from "./DucksView";
import type MatrixView from "./MatrixView";
import type StatsView from "./StatsView";
import type {IJugglSettings} from "juggl-api";

export type DebugLevel = keyof LogLevel;
export interface BCSettings {
Expand Down Expand Up @@ -282,7 +283,7 @@ declare module "obsidian" {
}
}

export interface ParsedCodeblock {
export interface ParsedCodeblock extends IJugglSettings{
dir: Directions;
fields: string[];
title: string;
Expand Down
18 changes: 14 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "obsidian-community-lib/dist/utils";
import { Debugger } from "src/Debugger";
import { BCSettingTab } from "./BreadcrumbsSettingTab";
import CBTree from "./Components/CBTree.svelte";
import CBTree from "./Components/CBTree.svelte";
import NextPrev from "./Components/NextPrev.svelte";
import TrailGrid from "./Components/TrailGrid.svelte";
import TrailPath from "./Components/TrailPath.svelte";
Expand Down Expand Up @@ -608,7 +608,7 @@ export default class BCPlugin extends Plugin {
}
let min = 1,
max = Infinity;
let {depth, dir, from, implied} = parsedSource;
let {depth, dir, from, implied, flat} = parsedSource;
if (depth !== undefined) {
const minNum = parseInt(depth[0]);
if (!isNaN(minNum)) min = minNum;
Expand Down Expand Up @@ -645,6 +645,16 @@ export default class BCPlugin extends Plugin {
const index = this.createIndex(allPaths, false);
info({ allPaths, index });
console.log({allPaths, index})
const lines = index
.split("\n")
.map((line) => {
const pair = line.split("- ");
return [flat === "true" ? "" : pair[0], pair.slice(1).join("- ")] as [
string,
string
];
})
.filter((pair) => pair[1] !== "");

switch (parsedSource.type) {
case "tree":
Expand All @@ -655,15 +665,15 @@ export default class BCPlugin extends Plugin {
el,
min,
max,
index,
lines,
froms,
basename,
...parsedSource,
},
});
break;
case "juggl":
createdJugglCB(el, parsedSource);
createdJugglCB(this, el, parsedSource, lines, froms, min, max);
break;
}
}
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
dependencies:
"@octokit/types" "^6.0.3"

"@octokit/core@^3.5.1":
"@octokit/core@^3.5.0", "@octokit/core@^3.5.1", "@octokit/core@>=2", "@octokit/core@>=3":
"integrity" "sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw=="
"resolved" "https://registry.npmjs.org/@octokit/core/-/core-3.5.1.tgz"
"version" "3.5.1"
Expand Down Expand Up @@ -525,7 +525,7 @@
"eslint-scope" "^5.1.1"
"eslint-utils" "^3.0.0"

"@typescript-eslint/parser@^4.27.0":
"@typescript-eslint/parser@^4.0.0", "@typescript-eslint/parser@^4.27.0":
"integrity" "sha512-UjrMsgnhQIIK82hXGaD+MCN8IfORS1CbMdu7VlZbYa8LCZtbZjJA26De4IPQB7XYZbL8gJ99KWNj0l6WD0guJg=="
"resolved" "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.28.1.tgz"
"version" "4.28.1"
Expand Down Expand Up @@ -584,7 +584,7 @@
"resolved" "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz"
"version" "5.3.1"

"acorn@^7.4.0":
"acorn@^6.0.0 || ^7.0.0 || ^8.0.0", "acorn@^7.4.0":
"integrity" "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A=="
"resolved" "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz"
"version" "7.4.1"
Expand Down Expand Up @@ -1353,7 +1353,7 @@
"resolved" "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz"
"version" "1.0.3"

"cosmiconfig@7.0.0":
"cosmiconfig@>=6", "cosmiconfig@7.0.0":
"integrity" "sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA=="
"resolved" "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.0.tgz"
"version" "7.0.0"
Expand Down Expand Up @@ -1940,7 +1940,7 @@
"resolved" "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz"
"version" "2.1.0"

"eslint@^7.29.0":
"eslint@*", "eslint@^5.0.0 || ^6.0.0 || ^7.0.0", "eslint@^7.29.0", "eslint@>=5":
"integrity" "sha512-VLqz80i3as3NdloY44BQSJpFw534L9Oh+6zJOUaViV4JPd+DaHwutqP7tcpkW3YiXbK6s05RZl7yl7cQn+lijg=="
"resolved" "https://registry.npmjs.org/eslint/-/eslint-7.30.0.tgz"
"version" "7.30.0"
Expand Down Expand Up @@ -2253,7 +2253,7 @@
"resolved" "https://registry.npmjs.org/flatted/-/flatted-3.2.0.tgz"
"version" "3.2.0"

"fp-ts@^2.5.3":
"fp-ts@^2.5.0", "fp-ts@^2.5.3":
"integrity" "sha512-UUpeygu50mV/J96Nk92fzHDznYXJxsO20wrUZGJppja1f8P+fhCaclcqcfubEyrH7XXPsmYn98CJF0BVAEn3ZQ=="
"resolved" "https://registry.npmjs.org/fp-ts/-/fp-ts-2.11.7.tgz"
"version" "2.11.7"
Expand Down Expand Up @@ -2413,7 +2413,7 @@
"graphology-utils" "^2.0.0"
"mnemonist" "^0.38.3"

"graphology-types@^0.23.0":
"graphology-types@^0.23.0", "graphology-types@>=0.20.0", "graphology-types@>=0.23.0":
"integrity" "sha512-6Je1NWU3el7YmybAhRzrOEi79Blhx05EU3wGUCvP5ikaxRXEflrW/5unfw5q/wqfwjryM9tcwUv4M7TZ8yTBYQ=="
"resolved" "https://registry.npmjs.org/graphology-types/-/graphology-types-0.23.0.tgz"
"version" "0.23.0"
Expand Down Expand Up @@ -2887,8 +2887,8 @@
"jsonparse" "^1.2.0"
"through" ">=2.2.7 <3"

"juggl-api@git+https://github.com/HEmile/juggl-api.git":
"resolved" "git+ssh://git@github.com/HEmile/juggl-api.git#1caa564271ca44e2c56cdac947f44b59b200ff44"
"juggl-api@github:HEmile/juggl-api":
"resolved" "git+ssh://git@github.com/HEmile/juggl-api.git#f286b3855858686bc381ed4c47a429d196aafcfd"
"version" "1.0.0"
dependencies:
"@types/cytoscape" "^3.14.11"
Expand Down Expand Up @@ -3137,7 +3137,7 @@
dependencies:
"obliterator" "^2.0.0"

"mocha@^9.1.3":
"mocha@^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X", "mocha@^9.1.3":
"integrity" "sha512-Xcpl9FqXOAYqI3j79pEtHBBnQgVXIhpULjGQa7DVb0Po+VzmSIK9kanAiWLHoRR/dbZ2qpdPshuXr8l1VaHCzw=="
"resolved" "https://registry.npmjs.org/mocha/-/mocha-9.1.3.tgz"
"version" "9.1.3"
Expand Down Expand Up @@ -3888,7 +3888,7 @@
dependencies:
"estree-walker" "^0.6.1"

"rollup@^2.32.1":
"rollup@^1.20.0||^2.0.0", "rollup@^2.14.0", "rollup@^2.30.0", "rollup@^2.32.1", "rollup@>=2.0.0":
"integrity" "sha512-55cSH4CCU6MaPr9TAOyrIC+7qFCHscL7tkNsm1MBfIJRRqRbCEY0mmeFn4Wg8FKsHtEH8r389Fz38r/o+kgXLg=="
"resolved" "https://registry.npmjs.org/rollup/-/rollup-2.52.7.tgz"
"version" "2.52.7"
Expand Down Expand Up @@ -4306,7 +4306,7 @@
"detect-indent" "^6.0.0"
"strip-indent" "^3.0.0"

"svelte@3.35.0":
"svelte@^3.23.0", "svelte@^3.24.0", "svelte@>=3.5.0", "svelte@3.35.0":
"integrity" "sha512-gknlZkR2sXheu/X+B7dDImwANVvK1R0QGQLd8CNIfxxGPeXBmePnxfzb6fWwTQRsYQG7lYkZXvpXJvxvpsoB7g=="
"resolved" "https://registry.npmjs.org/svelte/-/svelte-3.35.0.tgz"
"version" "3.35.0"
Expand Down Expand Up @@ -4477,6 +4477,11 @@
"minimist" "^1.2.0"
"strip-bom" "^3.0.0"

"tslib@*", "tslib@^2", "tslib@^2.2.0":
"integrity" "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
"resolved" "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz"
"version" "2.3.0"

"tslib@^1.14.1":
"integrity" "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
"resolved" "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz"
Expand All @@ -4487,11 +4492,6 @@
"resolved" "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz"
"version" "1.14.1"

"tslib@^2", "tslib@^2.2.0":
"integrity" "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
"resolved" "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz"
"version" "2.3.0"

"tslib@2.1.0":
"integrity" "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
"resolved" "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz"
Expand Down Expand Up @@ -4551,7 +4551,7 @@
"resolved" "https://registry.npmjs.org/typescript-memoize/-/typescript-memoize-1.1.0.tgz"
"version" "1.1.0"

"typescript@*", "typescript@^4.4.2":
"typescript@*", "typescript@^3.9.5 || ^4.0.0", "typescript@^4.4.2", "typescript@>=2.7", "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta", "typescript@>=3.7.0":
"integrity" "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg=="
"resolved" "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz"
"version" "4.5.4"
Expand Down

0 comments on commit e92021d

Please sign in to comment.