From e92021d44476bd76c4329dfdd3e1ae798e0a77cb Mon Sep 17 00:00:00 2001 From: Emile Date: Wed, 12 Jan 2022 17:31:49 +0100 Subject: [PATCH] feat: Initial work on juggl code blocks --- package.json | 2 +- src/Components/CBTree.svelte | 13 +---------- src/Visualisations/CBJuggl.ts | 41 ++++++++++++++++++++++++++++++++++- src/constants.ts | 2 +- src/interfaces.ts | 3 ++- src/main.ts | 18 +++++++++++---- yarn.lock | 36 +++++++++++++++--------------- 7 files changed, 77 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index c98f9d30..69e042ef 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Components/CBTree.svelte b/src/Components/CBTree.svelte index 1e7e5c26..3508d63a 100644 --- a/src/Components/CBTree.svelte +++ b/src/Components/CBTree.svelte @@ -10,9 +10,8 @@ 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; @@ -20,16 +19,6 @@ 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; diff --git a/src/Visualisations/CBJuggl.ts b/src/Visualisations/CBJuggl.ts index bc64fe91..56ec9365 100644 --- a/src/Visualisations/CBJuggl.ts +++ b/src/Visualisations/CBJuggl.ts @@ -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) + } } \ No newline at end of file diff --git a/src/constants.ts b/src/constants.ts index 427bf700..bd2c2e36 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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", diff --git a/src/interfaces.ts b/src/interfaces.ts index 9f074cf4..92f5b99a 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -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 { @@ -282,7 +283,7 @@ declare module "obsidian" { } } -export interface ParsedCodeblock { +export interface ParsedCodeblock extends IJugglSettings{ dir: Directions; fields: string[]; title: string; diff --git a/src/main.ts b/src/main.ts index 021edd78..ce3ad686 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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"; @@ -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; @@ -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": @@ -655,7 +665,7 @@ export default class BCPlugin extends Plugin { el, min, max, - index, + lines, froms, basename, ...parsedSource, @@ -663,7 +673,7 @@ export default class BCPlugin extends Plugin { }); break; case "juggl": - createdJugglCB(el, parsedSource); + createdJugglCB(this, el, parsedSource, lines, froms, min, max); break; } } diff --git a/yarn.lock b/yarn.lock index ef20c307..f2468c2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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"