Skip to content

Commit

Permalink
chore: bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Quorafind committed Jan 30, 2023
1 parent efe2540 commit bc84ad3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 95 deletions.
145 changes: 53 additions & 92 deletions canvasMindMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ItemView, MarkdownFileInfo, Notice, Plugin, requireApiVersion, TFile } from 'obsidian';
import { around } from "monkey-around";
import { addEdge, createChildFileNode, random } from "./utils";

export default class CanvasMindMap extends Plugin {

Expand All @@ -16,58 +17,14 @@ export default class CanvasMindMap extends Plugin {

registerCommands() {
this.addCommand({
id: 'split-into-mindmap',
name: 'Split into mindmap based on H1',
id: 'split-heading-into-mindmap',
name: 'Split Heading into mindmap based on H1',
checkCallback: (checking: boolean) => {
// Conditions to check
const canvasView = app.workspace.getActiveViewOfType(ItemView);
if (canvasView?.getViewType() === "canvas") {
// If checking is true, we're simply "checking" if the command can be run.
// If checking is false, then we want to actually perform the operation.
const random = (e: number) => {
let t = [];
for (let n = 0; n < e; n++) {
t.push((16 * Math.random() | 0).toString(16));
}
return t.join("")
}

const createChildFileNode = (canvas: any, parentNode: any, file: TFile, path: string, y: number) => {
const edge = canvas.edges.get(canvas.getData().edges.first()?.id);
let tempChildNode;
if(!requireApiVersion("1.1.10")) tempChildNode = canvas.createFileNode(file, path, {x: parentNode.x + parentNode.width + 200, y: y, height: parentNode.height * 0.6, width: parentNode.width}, true);
else {
tempChildNode = canvas.createFileNode({
file: file,
subpath: path,
pos: {
x: parentNode.x + parentNode.width + 200,
y: y,
width: parentNode.width,
height: parentNode.height * 0.6
},
size: {
x: parentNode.x + parentNode.width + 200,
y: y,
width: parentNode.width,
height: parentNode.height * 0.6
},
save: true,
focus: false,
});
}
canvas.deselectAll();
canvas.addNode(tempChildNode);

const tempEdge = new edge.constructor(canvas, random(16), {side: "right", node: parentNode}, {side: "left", node: tempChildNode})
canvas.addEdge(tempEdge);

tempEdge.render();
canvas.requestSave();

return tempChildNode;
}


if (!checking) {
// @ts-ignore
Expand Down Expand Up @@ -104,52 +61,58 @@ export default class CanvasMindMap extends Plugin {
}

patchCanvas() {
const random = (e: number) => {
let t = [];
for (let n = 0; n < e; n++) {
t.push((16 * Math.random() | 0).toString(16));
}
return t.join("")
}

const createEdge = async (node1: any, node2: any, canvas: any)=> {
const edge = canvas.edges.get(canvas.getData().edges.first()?.id);

if (edge) {
const tempEdge = new edge.constructor(canvas, random(16), {
if(requireApiVersion("1.1.9")) {
addEdge(canvas, random(16), {
fromOrTo: "from",
side: "right",
node: node1
}, { side: "left", node: node2 })
canvas.addEdge(tempEdge);

tempEdge.render();
},{
fromOrTo: "to",
side: "left",
node: node2
})
} else {
setTimeout(async () => {
const canvasFile = await this.app.vault.cachedRead(canvas.view.file);
const canvasFileData = JSON.parse(canvasFile);

canvasFileData.edges.push({
id: random(16),
fromNode: node1.id,
fromSide: "right",
toNode: node2.id,
toSide: "left"
});
canvasFileData.nodes.push({
id: node2.id,
x: node2.x,
y: node2.y,
width: node2.width,
height: node2.height,
type: "text",
text: node2.text,
})

canvas.setData(canvasFileData);
canvas.requestSave();

// await this.app.vault.modify(canvas.view.file, JSON.stringify(canvasFileData, null, 2));
}, 500);

// Leave code here to prevent error when Obsidian version is lower than 1.1.9??
const edge = canvas.edges.get(canvas.getData().edges.first()?.id);

if (edge) {
const tempEdge = new edge.constructor(canvas, random(16), {
side: "right",
node: node1
}, { side: "left", node: node2 })
canvas.addEdge(tempEdge);

tempEdge.render();


} else {
setTimeout(async () => {
const canvasFile = await this.app.vault.cachedRead(canvas.view.file);
const canvasFileData = JSON.parse(canvasFile);

canvasFileData.edges.push({
id: random(16),
fromNode: node1.id,
fromSide: "right",
toNode: node2.id,
toSide: "left"
});
canvasFileData.nodes.push({
id: node2.id,
x: node2.x,
y: node2.y,
width: node2.width,
height: node2.height,
type: "text",
text: node2.text,
})

canvas.setData(canvasFileData);
canvas.requestSave();
}, 500);
}
}
}

Expand Down Expand Up @@ -359,12 +322,10 @@ export default class CanvasMindMap extends Plugin {

}

const createSlibeNode = async (canvas: any) => {
const createSiblingNode = async (canvas: any) => {
if (canvas.selection.size !== 1) return;
const childNode = canvas.selection.entries().next().value[1];

console.log(childNode);

if (childNode.isEditing) return;

const edges = canvas.getEdgesForNode(childNode).filter((item: any) => {
Expand Down Expand Up @@ -457,7 +418,7 @@ export default class CanvasMindMap extends Plugin {
this.scope.register([], "Enter", async () => {


const node = await createSlibeNode(this.canvas);
const node = await createSiblingNode(this.canvas);
console.log(node);
if(!node) return;

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "canvas-mindmap",
"name": "Canvas Mindmap",
"version": "0.1.2",
"version": "0.1.3",
"minAppVersion": "1.1.0",
"description": "A plugin to make your canvas work like a mindmap.",
"author": "Boninall",
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": "canvas-mindmap",
"version": "0.1.2",
"version": "0.1.3",
"description": "A plugin to make your canvas work like a mindmap.",
"main": "main.js",
"scripts": {
Expand Down
87 changes: 87 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { requireApiVersion, TFile } from "obsidian";

interface edgeT {
fromOrTo: string;
side: string,
node: any,
}

export const random = (e: number) => {
let t = [];
for (let n = 0; n < e; n++) {
t.push((16 * Math.random() | 0).toString(16));
}
return t.join("")
}

export const createChildFileNode = (canvas: any, parentNode: any, file: TFile, path: string, y: number) => {
// const edge = canvas.edges.get(canvas.getData().edges.first()?.id);
let tempChildNode;
if(!requireApiVersion("1.1.10")) {
tempChildNode = canvas.createFileNode(file, path, {
x: parentNode.x + parentNode.width + 200,
y: y,
height: parentNode.height * 0.6,
width: parentNode.width
}, true);
}
else {
tempChildNode = canvas.createFileNode({
file: file,
subpath: path,
pos: {
x: parentNode.x + parentNode.width + 200,
y: y,
width: parentNode.width,
height: parentNode.height * 0.6
},
size: {
x: parentNode.x + parentNode.width + 200,
y: y,
width: parentNode.width,
height: parentNode.height * 0.6
},
save: true,
focus: false,
});
}
canvas.deselectAll();
canvas.addNode(tempChildNode);

// const tempEdge = new edge.constructor(canvas, random(16), {side: "right", node: parentNode}, {side: "left", node: tempChildNode})
// canvas.addEdge(tempEdge);
//
// tempEdge.render();

addEdge(canvas, random(16), {
fromOrTo: "from",
side: "right",
node: parentNode
},{
fromOrTo: "to",
side: "left",
node: tempChildNode
})
canvas.requestSave();

return tempChildNode;
}

export const addEdge = (canvas: any, edgeID: string, fromEdge: edgeT, toEdge: edgeT) => {
if(!canvas) return;

const data = canvas.getData();

if(!data) return;

canvas.importData({
"edges": [
...data.edges,
{"id":edgeID,"fromNode":fromEdge.node.id,"fromSide":fromEdge.side,"toNode":toEdge.node.id,"toSide":toEdge.side}
],
"nodes": data.nodes,
})

canvas.requestFrame();
}

3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"0.0.7": "1.1.0",
"0.1.0": "1.1.0",
"0.1.1": "1.1.0",
"0.1.2": "1.1.0"
"0.1.2": "1.1.0",
"0.1.3": "1.1.0"
}

0 comments on commit bc84ad3

Please sign in to comment.