Offer to edit images

Any SVG image in assets/ can now be edited with js-draw. It won't reload automatically (yet)
This commit is contained in:
MassiveBox 2025-04-01 23:03:22 +02:00
parent 5c261b35f2
commit 8d1438de33
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
4 changed files with 240 additions and 18 deletions

View file

@ -1,12 +1,11 @@
import {Plugin, Protyle} from 'siyuan';
import {getPreviewHTML, loadIcons, getMenuHTML, generateSiyuanId} from "@/helper";
import {getPreviewHTML, loadIcons, getMenuHTML, generateSiyuanId, findImgSrc, extractFileID} from "@/helper";
import {createEditor, openEditorTab} from "@/editorTab";
export default class DrawJSPlugin extends Plugin {
onload() {
loadIcons(this);
//const id = Math.random().toString(36).substring(7);
this.addTab({
'type': "whiteboard",
init() {
@ -25,20 +24,21 @@ export default class DrawJSPlugin extends Plugin {
}
}];
this.eventBus.on("open-menu-image", (e: any) => {
const fileID = extractFileID(findImgSrc(e.detail.element));
if(fileID === null) {
return;
}
console.log("got ID" + fileID);
e.detail.menu.addItem({
icon: "iconDraw",
label: "Edit with js-draw",
click: () => {
openEditorTab(this, fileID);
}
})
})
}
onLayoutReady() {
// This function is automatically called when the layout is loaded.
}
onunload() {
// This function is automatically called when the plugin is disabled.
}
uninstall() {
// This function is automatically called when the plugin is uninstalled.
}
}