modified: main.ts

modified:   manifest.json
	modified:   package.json
	modified:   tsconfig.json
This commit is contained in:
Michael Wain 2024-04-26 23:37:51 +03:00
parent 2fd512f52f
commit b04d543b87
5 changed files with 4549 additions and 85 deletions

124
main.ts
View File

@ -1,5 +1,9 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Editor, MarkdownView, Plugin, PluginSettingTab, Setting } from 'obsidian';
import * as venn from "@upsetjs/venn.js";
import * as d3 from "d3";
import * as yaml from "js-yaml";
import $ from "jquery";
import { Color } from '@bluefirex/color-ts';
// Remember to rename these classes and interfaces!
interface MyPluginSettings {
@ -13,74 +17,58 @@ const DEFAULT_SETTINGS: MyPluginSettings = {
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
makeString(): string {
let outString: string = '';
let inOptions: string = 'abcdefghijklmnopqrstuvwxyz';
for (let i = 0; i < 16; i++) {
outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
}
return outString;
}
async onload() {
await this.loadSettings();
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
new Notice('This is a notice!');
});
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Status Bar Text');
// This adds a simple command that can be triggered anywhere
this.addCommand({
id: 'open-sample-modal-simple',
name: 'Open sample modal (simple)',
callback: () => {
new SampleModal(this.app).open();
}
});
// This adds an editor command that can perform some operation on the current editor instance
this.addCommand({
id: 'sample-editor-command',
name: 'Sample editor command',
editorCallback: (editor: Editor, view: MarkdownView) => {
console.log(editor.getSelection());
editor.replaceSelection('Sample Editor Command');
}
});
// This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({
id: 'open-sample-modal-complex',
name: 'Open sample modal (complex)',
checkCallback: (checking: boolean) => {
// Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (markdownView) {
// 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.
if (!checking) {
new SampleModal(this.app).open();
}
// This command will only show up in Command Palette when the check function returns true
return true;
}
}
});
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this));
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt);
});
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
this.registerMarkdownCodeBlockProcessor("interweave", (source, el, ctx) => {
try {
let diagram: any = yaml.load(source, { json: true });
const id = "interweave-"+this.makeString();
let di = el.createEl("div");
di.addClass(id);
var chart = venn.VennDiagram();
d3.select(di).datum(diagram).call(chart);
for( let i = 0; i < diagram.length; i++ ) {
const element = diagram[i];
const sets: string = element.sets.join("_");
window.setTimeout(function() {
$("."+id).find("g[data-venn-sets="+sets+"]").find("path").css({"fill-opacity": element.opacity, "fill": element.color});
let clr = Color.fromString(element.color);
const txt_obj = $("."+id).find("g[data-venn-sets=\""+sets+"\"]").find("text");
try {
if( clr == null ) {
throw new Error('Null color');
}
txt_obj.css("fill", clr.isDark() ? "#FFFFFF" : "#000000");
} catch(e) {
txt_obj.css("fill", "#FFFFFF");
}
}, 80);
}
} catch(e) {
let di = el.createEl("pre");
di.setText("Error parsing Interweave diagram.\nIt's syntax should look like this:\n- sets:\n - A\n size: 16\n color: \"#FF0000\"\n opacity: 0.3");
}
});
}
onunload() {
}
onunload() {}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
@ -91,22 +79,6 @@ export default class MyPlugin extends Plugin {
}
}
class SampleModal extends Modal {
constructor(app: App) {
super(app);
}
onOpen() {
const {contentEl} = this;
contentEl.setText('Woah!');
}
onClose() {
const {contentEl} = this;
contentEl.empty();
}
}
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;

View File

@ -1,11 +1,11 @@
{
"id": "sample-plugin",
"name": "Sample Plugin",
"id": "interweave-plugin",
"name": "Interweave",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "Demonstrates some of the capabilities of the Obsidian API.",
"author": "Obsidian",
"authorUrl": "https://obsidian.md",
"fundingUrl": "https://obsidian.md/pricing",
"description": "Venn and Euler diagrams plugin.",
"author": "Alterdekim",
"authorUrl": "https://awain.net",
"fundingUrl": "https://awain.net",
"isDesktopOnly": false
}

4480
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "obsidian-sample-plugin",
"name": "interweave",
"version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"description": "Venn and Euler diagrams plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
@ -9,9 +9,10 @@
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "",
"author": "alterdekim",
"license": "MIT",
"devDependencies": {
"@types/jquery": "^3.5.29",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
@ -20,5 +21,15 @@
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"dependencies": {
"@bluefirex/color-ts": "^1.2.1",
"@types/d3": "^7.4.3",
"@types/js-yaml": "^4.0.9",
"@upsetjs/venn.js": "^1.4.2",
"chroma.ts": "^1.0.10",
"d3": "^7.9.0",
"jquery": "^3.7.1",
"js-yaml": "^4.1.0"
}
}

View File

@ -10,6 +10,7 @@
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"lib": [
"DOM",