From 3a05d36f8c0d77e97b53aec77b0bdfeaf8933b1c Mon Sep 17 00:00:00 2001 From: MassiveBox Date: Thu, 17 Apr 2025 22:27:38 +0200 Subject: [PATCH] Fixes + Version bump --- package.json | 2 +- plugin.json | 2 +- src/config.ts | 2 +- src/editor.ts | 33 +++++++++++++++++++++------------ src/index.ts | 6 +++--- src/protyle.ts | 6 +++++- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 3dd8f4f..f355588 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "siyuan-jsdraw-plugin", - "version": "0.2.2", + "version": "0.3.0", "type": "module", "description": "Include a whiteboard for freehand drawing anywhere in your documents.", "repository": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin", diff --git a/plugin.json b/plugin.json index 8c3ef88..3f18451 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "siyuan-jsdraw-plugin", "author": "massivebox", "url": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin", - "version": "0.2.2", + "version": "0.3.0", "minAppVersion": "3.0.12", "backends": [ "windows", diff --git a/src/config.ts b/src/config.ts index 8ad50dd..52fd764 100644 --- a/src/config.ts +++ b/src/config.ts @@ -121,7 +121,7 @@ export class PluginConfigViewer { Dialog mode provides a larger drawing area, but it's not as handy to use as tabs (default).
The editor will always open as a dialog on mobile. `, - value: this.config.options.grid, + value: this.config.options.dialogOnDesktop, type: 'checkbox' }); diff --git a/src/editor.ts b/src/editor.ts index 9c5e524..8680a40 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -6,6 +6,7 @@ import {Dialog, getFrontend, openTab, Plugin} from "siyuan"; import {findSyncIDInProtyle, replaceSyncID} from "@/protyle"; import DrawJSPlugin from "@/index"; import {DefaultEditorOptions} from "@/config"; +import 'js-draw/styles'; export class PluginEditor { @@ -39,10 +40,21 @@ export class PluginEditor { }); findSyncIDInProtyle(this.fileID).then(async (syncID) => { + + if(syncID == null) { + alert( + "Couldn't find SyncID in protyle for this file.\n" + + "Make sure the drawing you're trying to edit exists in a note.\n" + + "Close this editor tab now, and try to open the editor again." + ); + return; + } + this.syncID = syncID; // restore drawing this.drawingFile = new PluginAsset(this.fileID, syncID, SVG_MIME); await this.drawingFile.loadFromSiYuanFS(); + if(this.drawingFile.getContent() != null) { await this.editor.loadFromSVG(this.drawingFile.getContent()); }else{ @@ -53,6 +65,9 @@ export class PluginEditor { autoresize: true })); } + + }).catch((error) => { + alert("Error loading drawing: " + error); }); } @@ -94,14 +109,7 @@ export class PluginEditor { newSyncID = this.drawingFile.getSyncID(); if(newSyncID != oldSyncID) { // supposed to replace protyle const changed = await replaceSyncID(this.fileID, oldSyncID, newSyncID); // try to change protyle - if(!changed) { - alert( - "Error replacing old sync ID with new one! You may need to manually replace the file path." + - "\nTry saving the drawing again. This is a bug, please open an issue as soon as you can." + - "\nIf your document doesn't show the drawing, you can recover it from the SiYuan workspace directory." - ); - return; // don't delete old drawing if protyle unchanged (could cause confusion) - } + if(!changed) throw new Error("Couldn't replace old images in protyle"); await this.drawingFile.removeOld(oldSyncID); } saveButton.setDisabled(true); @@ -109,7 +117,8 @@ export class PluginEditor { saveButton.setDisabled(false); }, 500); } catch (error) { - alert("Error saving drawing! Enter developer mode to find the error, and a copy of the current status."); + alert("Error saving! The current drawing has been copied to your clipboard. You may need to create a new drawing and paste it there."); + await navigator.clipboard.writeText(svgElem.outerHTML); console.error(error); console.log("Couldn't save SVG: ", svgElem.outerHTML) return; @@ -125,8 +134,8 @@ export class EditorManager { private editor: PluginEditor - constructor(editor: PluginEditor) { - this.editor = editor; + constructor(fileID: string, defaultEditorOptions: DefaultEditorOptions) { + this.editor = new PluginEditor(fileID, defaultEditorOptions); } static registerTab(p: DrawJSPlugin) { @@ -161,7 +170,7 @@ export class EditorManager { toDialog() { const dialog = new Dialog({ width: "100vw", - height: "100vh", + height: getFrontend() == "mobile" ? "100vh" : "90vh", content: `
`, }); dialog.element.querySelector("#DrawingPanel").appendChild(this.editor.getElement()); diff --git a/src/index.ts b/src/index.ts index 4c5a0fe..599bf3a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { imgSrcToIDs, generateTimeString, generateRandomString } from "@/helper"; import {migrate} from "@/migration"; -import {EditorManager, PluginEditor} from "@/editor"; +import {EditorManager} from "@/editor"; import {PluginConfig, PluginConfigViewer} from "@/config"; import {Analytics} from "@/analytics"; @@ -34,7 +34,7 @@ export default class DrawJSPlugin extends Plugin { const fileID = generateRandomString(); const syncID = generateTimeString() + '-' + generateRandomString(); protyle.insert(getMarkdownBlock(fileID, syncID), true, false); - new EditorManager(new PluginEditor(fileID, this.config.getDefaultEditorOptions())).open(this); + new EditorManager(fileID, this.config.getDefaultEditorOptions()).open(this); } }]; @@ -46,7 +46,7 @@ export default class DrawJSPlugin extends Plugin { label: "Edit with js-draw", click: () => { void this.analytics.sendEvent('edit'); - new EditorManager(new PluginEditor(ids.fileID, this.config.getDefaultEditorOptions())).open(this) + new EditorManager(ids.fileID, this.config.getDefaultEditorOptions()).open(this); } }) }) diff --git a/src/protyle.ts b/src/protyle.ts index 2914b3c..5c3e842 100644 --- a/src/protyle.ts +++ b/src/protyle.ts @@ -15,7 +15,11 @@ export async function findSyncIDInProtyle(fileID: string, iter?: number): Promis if(syncID == null) { syncID = ids.syncID; }else if(ids.syncID !== syncID) { - throw new Error("Multiple syncIDs found"); + throw new Error( + "Multiple syncIDs found in documents. Remove the drawings that don't exist from your documents.\n" + + "Sync conflict copies can cause this error, so make sure to delete them, or at least the js-draw drawings they contain.\n" + + "File IDs must be unique. Close this editor tab now." + ); } } }