Fixes + Version bump
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled
This commit is contained in:
parent
e815442881
commit
3a05d36f8c
6 changed files with 32 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "siyuan-jsdraw-plugin",
|
"name": "siyuan-jsdraw-plugin",
|
||||||
"version": "0.2.2",
|
"version": "0.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Include a whiteboard for freehand drawing anywhere in your documents.",
|
"description": "Include a whiteboard for freehand drawing anywhere in your documents.",
|
||||||
"repository": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin",
|
"repository": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "siyuan-jsdraw-plugin",
|
"name": "siyuan-jsdraw-plugin",
|
||||||
"author": "massivebox",
|
"author": "massivebox",
|
||||||
"url": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin",
|
"url": "https://git.massive.box/massivebox/siyuan-jsdraw-plugin",
|
||||||
"version": "0.2.2",
|
"version": "0.3.0",
|
||||||
"minAppVersion": "3.0.12",
|
"minAppVersion": "3.0.12",
|
||||||
"backends": [
|
"backends": [
|
||||||
"windows",
|
"windows",
|
||||||
|
|
|
@ -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).<br />
|
Dialog mode provides a larger drawing area, but it's not as handy to use as tabs (default).<br />
|
||||||
The editor will always open as a dialog on mobile.
|
The editor will always open as a dialog on mobile.
|
||||||
`,
|
`,
|
||||||
value: this.config.options.grid,
|
value: this.config.options.dialogOnDesktop,
|
||||||
type: 'checkbox'
|
type: 'checkbox'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {Dialog, getFrontend, openTab, Plugin} from "siyuan";
|
||||||
import {findSyncIDInProtyle, replaceSyncID} from "@/protyle";
|
import {findSyncIDInProtyle, replaceSyncID} from "@/protyle";
|
||||||
import DrawJSPlugin from "@/index";
|
import DrawJSPlugin from "@/index";
|
||||||
import {DefaultEditorOptions} from "@/config";
|
import {DefaultEditorOptions} from "@/config";
|
||||||
|
import 'js-draw/styles';
|
||||||
|
|
||||||
export class PluginEditor {
|
export class PluginEditor {
|
||||||
|
|
||||||
|
@ -39,10 +40,21 @@ export class PluginEditor {
|
||||||
});
|
});
|
||||||
|
|
||||||
findSyncIDInProtyle(this.fileID).then(async (syncID) => {
|
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;
|
this.syncID = syncID;
|
||||||
// restore drawing
|
// restore drawing
|
||||||
this.drawingFile = new PluginAsset(this.fileID, syncID, SVG_MIME);
|
this.drawingFile = new PluginAsset(this.fileID, syncID, SVG_MIME);
|
||||||
await this.drawingFile.loadFromSiYuanFS();
|
await this.drawingFile.loadFromSiYuanFS();
|
||||||
|
|
||||||
if(this.drawingFile.getContent() != null) {
|
if(this.drawingFile.getContent() != null) {
|
||||||
await this.editor.loadFromSVG(this.drawingFile.getContent());
|
await this.editor.loadFromSVG(this.drawingFile.getContent());
|
||||||
}else{
|
}else{
|
||||||
|
@ -53,6 +65,9 @@ export class PluginEditor {
|
||||||
autoresize: true
|
autoresize: true
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}).catch((error) => {
|
||||||
|
alert("Error loading drawing: " + error);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,14 +109,7 @@ export class PluginEditor {
|
||||||
newSyncID = this.drawingFile.getSyncID();
|
newSyncID = this.drawingFile.getSyncID();
|
||||||
if(newSyncID != oldSyncID) { // supposed to replace protyle
|
if(newSyncID != oldSyncID) { // supposed to replace protyle
|
||||||
const changed = await replaceSyncID(this.fileID, oldSyncID, newSyncID); // try to change protyle
|
const changed = await replaceSyncID(this.fileID, oldSyncID, newSyncID); // try to change protyle
|
||||||
if(!changed) {
|
if(!changed) throw new Error("Couldn't replace old images in protyle");
|
||||||
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)
|
|
||||||
}
|
|
||||||
await this.drawingFile.removeOld(oldSyncID);
|
await this.drawingFile.removeOld(oldSyncID);
|
||||||
}
|
}
|
||||||
saveButton.setDisabled(true);
|
saveButton.setDisabled(true);
|
||||||
|
@ -109,7 +117,8 @@ export class PluginEditor {
|
||||||
saveButton.setDisabled(false);
|
saveButton.setDisabled(false);
|
||||||
}, 500);
|
}, 500);
|
||||||
} catch (error) {
|
} 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.error(error);
|
||||||
console.log("Couldn't save SVG: ", svgElem.outerHTML)
|
console.log("Couldn't save SVG: ", svgElem.outerHTML)
|
||||||
return;
|
return;
|
||||||
|
@ -125,8 +134,8 @@ export class EditorManager {
|
||||||
|
|
||||||
private editor: PluginEditor
|
private editor: PluginEditor
|
||||||
|
|
||||||
constructor(editor: PluginEditor) {
|
constructor(fileID: string, defaultEditorOptions: DefaultEditorOptions) {
|
||||||
this.editor = editor;
|
this.editor = new PluginEditor(fileID, defaultEditorOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
static registerTab(p: DrawJSPlugin) {
|
static registerTab(p: DrawJSPlugin) {
|
||||||
|
@ -161,7 +170,7 @@ export class EditorManager {
|
||||||
toDialog() {
|
toDialog() {
|
||||||
const dialog = new Dialog({
|
const dialog = new Dialog({
|
||||||
width: "100vw",
|
width: "100vw",
|
||||||
height: "100vh",
|
height: getFrontend() == "mobile" ? "100vh" : "90vh",
|
||||||
content: `<div id="DrawingPanel" style="width:100%; height: 100%;"></div>`,
|
content: `<div id="DrawingPanel" style="width:100%; height: 100%;"></div>`,
|
||||||
});
|
});
|
||||||
dialog.element.querySelector("#DrawingPanel").appendChild(this.editor.getElement());
|
dialog.element.querySelector("#DrawingPanel").appendChild(this.editor.getElement());
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
imgSrcToIDs, generateTimeString, generateRandomString
|
imgSrcToIDs, generateTimeString, generateRandomString
|
||||||
} from "@/helper";
|
} from "@/helper";
|
||||||
import {migrate} from "@/migration";
|
import {migrate} from "@/migration";
|
||||||
import {EditorManager, PluginEditor} from "@/editor";
|
import {EditorManager} from "@/editor";
|
||||||
import {PluginConfig, PluginConfigViewer} from "@/config";
|
import {PluginConfig, PluginConfigViewer} from "@/config";
|
||||||
import {Analytics} from "@/analytics";
|
import {Analytics} from "@/analytics";
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export default class DrawJSPlugin extends Plugin {
|
||||||
const fileID = generateRandomString();
|
const fileID = generateRandomString();
|
||||||
const syncID = generateTimeString() + '-' + generateRandomString();
|
const syncID = generateTimeString() + '-' + generateRandomString();
|
||||||
protyle.insert(getMarkdownBlock(fileID, syncID), true, false);
|
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",
|
label: "Edit with js-draw",
|
||||||
click: () => {
|
click: () => {
|
||||||
void this.analytics.sendEvent('edit');
|
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);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,7 +15,11 @@ export async function findSyncIDInProtyle(fileID: string, iter?: number): Promis
|
||||||
if(syncID == null) {
|
if(syncID == null) {
|
||||||
syncID = ids.syncID;
|
syncID = ids.syncID;
|
||||||
}else if(ids.syncID !== 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."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue