mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9251d4f1d | ||
|
|
9a57db43f2 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.3.19",
|
||||
"version": "1.3.20",
|
||||
"minAppVersion": "0.12.0",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@zsviczian/excalidraw": "0.9.0-obsidian-13",
|
||||
"@zsviczian/excalidraw": "0.10.0-obsidian-1",
|
||||
"monkey-around": "^2.2.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
|
||||
@@ -326,7 +326,7 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
|
||||
currentItemLinearStrokeSharpness: template? template.appState.currentItemLinearStrokeSharpness : this.style.strokeSharpness,
|
||||
gridSize: template ? template.appState.gridSize : this.canvas.gridSize
|
||||
}
|
||||
}))
|
||||
},null,"\t"))
|
||||
);
|
||||
},
|
||||
async createSVG(templatePath?:string):Promise<SVGSVGElement> {
|
||||
|
||||
@@ -51,7 +51,7 @@ export const REGEX_LINK = {
|
||||
|
||||
export const REG_LINKINDEX_HYPERLINK = /^\w+:\/\//;
|
||||
|
||||
const DRAWING_REG = /\n%%\n# Drawing\n[^`]*(```json\n)(.*)\n[^`]*```[^%]*(%%)?/gm; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/182
|
||||
const DRAWING_REG = /\n%%\n# Drawing\n[^`]*(```json\n)([\s\S]*?)```/gm; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/182
|
||||
const DRAWING_REG_FALLBACK = /\n# Drawing\n(```json\n)?(.*)(```)?(%%)?/gm;
|
||||
export function getJSON(data:string):[string,number] {
|
||||
let res = data.matchAll(DRAWING_REG);
|
||||
@@ -438,7 +438,7 @@ export class ExcalidrawData {
|
||||
for(const key of this.textElements.keys()){
|
||||
outString += this.textElements.get(key).raw+' ^'+key+'\n\n';
|
||||
}
|
||||
return outString + this.plugin.getMarkdownDrawingSection(JSON.stringify(this.scene));
|
||||
return outString + this.plugin.getMarkdownDrawingSection(JSON.stringify(this.scene,null,"\t"));
|
||||
}
|
||||
|
||||
public async syncElements(newScene:any):Promise<boolean> {
|
||||
|
||||
@@ -79,7 +79,6 @@ export default class ExcalidrawView extends TextFileView {
|
||||
private ctrlKeyDown = false;
|
||||
private shiftKeyDown = false;
|
||||
private altKeyDown = false;
|
||||
private mouseEvent:any = null;
|
||||
|
||||
id: string = (this.leaf as any).id;
|
||||
|
||||
@@ -96,8 +95,8 @@ export default class ExcalidrawView extends TextFileView {
|
||||
}
|
||||
const filepath = this.file.path.substring(0,this.file.path.lastIndexOf('.md')) + '.excalidraw';
|
||||
const file = this.app.vault.getAbstractFileByPath(normalizePath(filepath));
|
||||
if(file && file instanceof TFile) this.app.vault.modify(file,JSON.stringify(scene));
|
||||
else this.app.vault.create(filepath,JSON.stringify(scene));
|
||||
if(file && file instanceof TFile) this.app.vault.modify(file,JSON.stringify(scene,null,"\t"));
|
||||
else this.app.vault.create(filepath,JSON.stringify(scene,null,"\t"));
|
||||
}
|
||||
|
||||
public saveSVG(scene?: any) {
|
||||
@@ -197,7 +196,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
if(this.plugin.settings.autoexportSVG) this.saveSVG(scene);
|
||||
if(this.plugin.settings.autoexportPNG) this.savePNG(scene);
|
||||
}
|
||||
return JSON.stringify(scene);
|
||||
return JSON.stringify(scene,null,"\t");
|
||||
}
|
||||
return this.data;
|
||||
}
|
||||
@@ -487,12 +486,12 @@ export default class ExcalidrawView extends TextFileView {
|
||||
const folderpath = splitFolderAndFilename(this.file.path).folderpath;
|
||||
await checkAndCreateFolder(this.app.vault,folderpath); //create folder if it does not exist
|
||||
const fname = getNewUniqueFilepath(this.app.vault,filename,folderpath);
|
||||
this.app.vault.create(fname,JSON.stringify(this.getScene()));
|
||||
this.app.vault.create(fname,JSON.stringify(this.getScene(),null,"\t"));
|
||||
new Notice("Exported to " + fname,6000);
|
||||
});
|
||||
return;
|
||||
}
|
||||
download('data:text/plain;charset=utf-8',encodeURIComponent(JSON.stringify(this.getScene())), this.file.basename+'.excalidraw');
|
||||
download('data:text/plain;charset=utf-8',encodeURIComponent(JSON.stringify(this.getScene(),null,"\t")), this.file.basename+'.excalidraw');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -760,6 +759,18 @@ export default class ExcalidrawView extends TextFileView {
|
||||
if (transfer.types?.includes('text/html') || transfer.types?.includes('text/plain')) return 'copy';
|
||||
}
|
||||
|
||||
let viewModeEnabled = false;
|
||||
const handleLinkClick = () => {
|
||||
selectedTextElement = getTextElementAtPointer(currentPosition);
|
||||
if(selectedTextElement) {
|
||||
const event = new MouseEvent("click", {ctrlKey: true, shiftKey: this.shiftKeyDown, altKey:this.altKeyDown});
|
||||
this.handleLinkClick(this,event);
|
||||
selectedTextElement = null;
|
||||
}
|
||||
}
|
||||
|
||||
let mouseEvent:any = null;
|
||||
|
||||
const excalidrawDiv = React.createElement(
|
||||
"div",
|
||||
{
|
||||
@@ -799,7 +810,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
this.plugin.hover.sourcePath = this.file.path;
|
||||
hoverPreviewTarget = this.contentEl; //e.target;
|
||||
this.app.workspace.trigger('hover-link', {
|
||||
event: this.mouseEvent,
|
||||
event: mouseEvent,
|
||||
source: VIEW_TYPE_EXCALIDRAW,
|
||||
hoverParent: hoverPreviewTarget,
|
||||
targetEl: hoverPreviewTarget,
|
||||
@@ -830,7 +841,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
},
|
||||
onMouseMove: (e:MouseEvent) => {
|
||||
//@ts-ignore
|
||||
this.mouseEvent = e.nativeEvent;
|
||||
mouseEvent = e.nativeEvent;
|
||||
},
|
||||
onMouseOver: (e:MouseEvent) => {
|
||||
clearHoverPreview();
|
||||
@@ -864,17 +875,9 @@ export default class ExcalidrawView extends TextFileView {
|
||||
onPointerUpdate: (p:any) => {
|
||||
currentPosition = p.pointer;
|
||||
if(hoverPreviewTarget && (Math.abs(hoverPoint.x-p.pointer.x)>50 || Math.abs(hoverPoint.y-p.pointer.y)>50)) clearHoverPreview();
|
||||
if(!this.excalidrawRef.current.getAppState().viewModeEnabled) return;
|
||||
const handleLinkClick = () => {
|
||||
selectedTextElement = getTextElementAtPointer(p.pointer);
|
||||
if(selectedTextElement) {
|
||||
const event = new MouseEvent("click", {ctrlKey: true, shiftKey: this.shiftKeyDown, altKey:this.altKeyDown});
|
||||
this.handleLinkClick(this,event);
|
||||
selectedTextElement = null;
|
||||
}
|
||||
}
|
||||
if(!viewModeEnabled) return;
|
||||
|
||||
const buttonDown = !blockOnMouseButtonDown && p.button=="down";
|
||||
const buttonDown = !blockOnMouseButtonDown && p.button === "down";
|
||||
if(buttonDown) {
|
||||
blockOnMouseButtonDown = true;
|
||||
|
||||
@@ -892,11 +895,12 @@ export default class ExcalidrawView extends TextFileView {
|
||||
timestamp = now;
|
||||
return;
|
||||
}
|
||||
if (p.button=="up") {
|
||||
if (p.button === "up") {
|
||||
blockOnMouseButtonDown=false;
|
||||
}
|
||||
},
|
||||
onChange: (et:ExcalidrawElement[],st:AppState) => {
|
||||
viewModeEnabled = st.viewModeEnabled;
|
||||
if(this.justLoaded) {
|
||||
this.justLoaded = false;
|
||||
this.zoomToFit(false);
|
||||
|
||||
@@ -113,6 +113,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
//inspiration taken from kanban:
|
||||
//https://github.com/mgmeyers/obsidian-kanban/blob/44118e25661bff9ebfe54f71ae33805dc88ffa53/src/main.ts#L267
|
||||
this.registerMonkeyPatches();
|
||||
new Notice("Excalidraw was updated. Files opened with this version will not open with the older version. Please update plugin on all your devices.\n\nI will remove this message with next update.",8000);
|
||||
if(this.settings.loadCount<1) this.migrationNotice();
|
||||
const electron:string = process.versions.electron;
|
||||
if(electron.startsWith("8.")) {
|
||||
@@ -1137,7 +1138,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
}
|
||||
outString += te.text+' ^'+id+'\n\n';
|
||||
}
|
||||
return outString + this.getMarkdownDrawingSection(JSON.stringify(JSON_parse(data)));
|
||||
return outString + this.getMarkdownDrawingSection(JSON.stringify(JSON_parse(data),null,"\t"));
|
||||
}
|
||||
|
||||
public async createDrawing(filename: string, onNewPane: boolean, foldername?: string, initData?:string):Promise<string> {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"1.3.19": "0.11.13"
|
||||
"1.3.20": "0.11.13"
|
||||
}
|
||||
|
||||
@@ -1062,10 +1062,10 @@
|
||||
dependencies:
|
||||
"@types/estree" "*"
|
||||
|
||||
"@zsviczian/excalidraw@0.9.0-obsidian-13":
|
||||
"integrity" "sha512-oHXNHsdtbFsKJDeibsJi6DFeqTgb0OrZjE0W1ZgE3VN3CeqC0Ad9okzHMXQgPicpw/XFx1IOtCqZtpQ2Cch/Sw=="
|
||||
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.9.0-obsidian-13.tgz"
|
||||
"version" "0.9.0-obsidian-13"
|
||||
"@zsviczian/excalidraw@0.10.0-obsidian-1":
|
||||
"integrity" "sha512-k9xPYTp8wJlWwcJwVBLjZcbccthEYqiFkIAZRRIGPVAxGUOpyxZdJ5X4/QsmOfiRqErtiq3JboAPnYEHGtLjIg=="
|
||||
"resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.10.0-obsidian-1.tgz"
|
||||
"version" "0.10.0-obsidian-1"
|
||||
|
||||
"abab@^1.0.3":
|
||||
"integrity" "sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4="
|
||||
|
||||
Reference in New Issue
Block a user