Skip to content

Commit

Permalink
maybe initial now
Browse files Browse the repository at this point in the history
  • Loading branch information
pinittech committed May 11, 2024
1 parent 7c13506 commit 1e6f5ef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 63 deletions.
57 changes: 27 additions & 30 deletions main.js

Large diffs are not rendered by default.

63 changes: 30 additions & 33 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pdfjs from "@bundled-es-modules/pdfjs-dist/build/pdf";
import OpenAI from "openai";
import Groq from "groq-sdk";
import { around } from "monkey-around";
import { Canvas, ViewportNode, Message, Node, Edge } from "./types";
import { Canvas, ViewportNode, Message, Node, Edge, EdgeDirection } from "./types";
import {
App,
Editor,
Expand All @@ -20,9 +20,8 @@ import {
WorkspaceLeaf,
setTooltip,
setIcon,
View,
} from "obsidian";
import { CanvasData, CanvasFileData, CanvasNodeData, CanvasTextData } from "obsidian/canvas";
import { CanvasFileData, CanvasNodeData, CanvasTextData } from "obsidian/canvas";
import { Extension, RangeSetBuilder, StateField, Transaction } from "@codemirror/state";
import { Decoration, DecorationSet, EditorView } from "@codemirror/view";
var parseString = require("xml2js").parseString;
Expand Down Expand Up @@ -1777,7 +1776,6 @@ export default class CaretPlugin extends Plugin {
break;
case "file":
node.file = content;
if (subpath) node.subpath = subpath;
break;
}

Expand Down Expand Up @@ -1806,15 +1804,14 @@ export default class CaretPlugin extends Plugin {
}
);
};
// TODO - Change this
random = (e: number) => {
let t = [];
for (let n = 0; n < e; n++) {
t.push(((16 * Math.random()) | 0).toString(16));
}
return t.join("");
};
addEdge = (canvas: any, edgeID: string, fromEdge: edgeT, toEdge: edgeT) => {
addEdge = (canvas: any, edgeID: string, fromEdge: EdgeDirection, toEdge: EdgeDirection) => {
if (!canvas) return;

const data = canvas.getData();
Expand All @@ -1837,33 +1834,33 @@ export default class CaretPlugin extends Plugin {
canvas.requestFrame();
};

// Method to insert text into the sidebar
insertTextIntoSidebar(text: string) {
const trimmed_text = text.trim();
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.view.getViewType() === VIEW_NAME_SIDEBAR_CHAT) {
const view = leaf.view as SidebarChat;
if (view.textBox) {
view.textBox.value += trimmed_text;
}
}
});
}

// Method to clear text from the sidebar
clearTextInSidebar() {
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.view.getViewType() === VIEW_NAME_SIDEBAR_CHAT) {
const view = leaf.view as SidebarChat;
if (view.textBox) {
view.textBox.value = ""; // Clear the text box
}
if (view.messagesContainer) {
view.messagesContainer.innerHTML = ""; // Clear the messages container
}
}
});
}
// // Method to insert text into the sidebar
// insertTextIntoSidebar(text: string) {
// const trimmed_text = text.trim();
// this.app.workspace.iterateAllLeaves((leaf) => {
// if (leaf.view.getViewType() === VIEW_NAME_SIDEBAR_CHAT) {
// const view = leaf.view as SidebarChat;
// if (view.textBox) {
// view.textBox.value += trimmed_text;
// }
// }
// });
// }

// // Method to clear text from the sidebar
// clearTextInSidebar() {
// this.app.workspace.iterateAllLeaves((leaf) => {
// if (leaf.view.getViewType() === VIEW_NAME_SIDEBAR_CHAT) {
// const view = leaf.view as SidebarChat;
// if (view.textBox) {
// view.textBox.value = ""; // Clear the text box
// }
// if (view.messagesContainer) {
// view.messagesContainer.innerHTML = ""; // Clear the messages container
// }
// }
// });
// }
addChatIconToRibbon() {
console.log("Add side bar runs");
this.addRibbonIcon("message-square", "Caret Chat", async (evt) => {
Expand Down
2 changes: 2 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export interface Canvas {
requestSave(save?: boolean, triggerBySelf?: boolean): void;
zoomToSelection(): void;
selectOnly(node: Node): void;
importData({}): void;
requestFrame(): void;
}

export interface CanvasMenu {
Expand Down

0 comments on commit 1e6f5ef

Please sign in to comment.