Fix sync inconsistencies across devices
Changed APIs to upload assets, reworked saving logic so that files are synced across devices when changed locally.
This commit is contained in:
parent
e165c69664
commit
4555ec275f
5 changed files with 104 additions and 60 deletions
22
src/index.ts
22
src/index.ts
|
@ -1,16 +1,15 @@
|
|||
import {Plugin, Protyle} from 'siyuan';
|
||||
import {
|
||||
getPreviewHTML,
|
||||
getMarkdownBlock,
|
||||
loadIcons,
|
||||
getMenuHTML,
|
||||
generateSiyuanId,
|
||||
findImgSrc,
|
||||
imgSrcToPath
|
||||
imgSrcToIDs, generateTimeString, generateRandomString
|
||||
} from "@/helper";
|
||||
import {editorTabInit, openEditorTab} from "@/editorTab";
|
||||
import {ASSETS_PATH} from "@/const";
|
||||
|
||||
export default class DrawJSPlugin extends Plugin {
|
||||
|
||||
onload() {
|
||||
|
||||
loadIcons(this);
|
||||
|
@ -24,22 +23,21 @@ export default class DrawJSPlugin extends Plugin {
|
|||
filter: ["Insert Drawing", "Add drawing", "whiteboard", "freehand", "graphics", "jsdraw"],
|
||||
html: getMenuHTML("iconDraw", this.i18n.insertDrawing),
|
||||
callback: (protyle: Protyle) => {
|
||||
const path = ASSETS_PATH + generateSiyuanId() + ".svg";
|
||||
protyle.insert(getPreviewHTML(path), true, false);
|
||||
openEditorTab(this, path);
|
||||
const fileID = generateRandomString();
|
||||
const syncID = generateTimeString() + '-' + generateRandomString();
|
||||
protyle.insert(getMarkdownBlock(fileID, syncID), true, false);
|
||||
openEditorTab(this, fileID, syncID);
|
||||
}
|
||||
}];
|
||||
|
||||
this.eventBus.on("open-menu-image", (e: any) => {
|
||||
const path = imgSrcToPath(findImgSrc(e.detail.element));
|
||||
if(path === null) {
|
||||
return;
|
||||
}
|
||||
const ids = imgSrcToIDs(findImgSrc(e.detail.element));
|
||||
if(ids === null) return;
|
||||
e.detail.menu.addItem({
|
||||
icon: "iconDraw",
|
||||
label: "Edit with js-draw",
|
||||
click: () => {
|
||||
openEditorTab(this, path);
|
||||
openEditorTab(this, ids.fileID, ids.syncID);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue