mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
1.3.9
This commit is contained in:
@@ -43,9 +43,15 @@ export interface ExcalidrawAutomate extends Window {
|
||||
filename?: string,
|
||||
foldername?:string,
|
||||
templatePath?:string,
|
||||
onNewPane?: boolean
|
||||
onNewPane?: boolean,
|
||||
frontmatterKeys?:{
|
||||
"excalidraw-plugin"?: "raw"|"parsed",
|
||||
"excalidraw-link-prefix"?: string,
|
||||
"excalidraw-link-brackets"?: boolean,
|
||||
"excalidraw-url-prefix"?: string
|
||||
}
|
||||
}
|
||||
):Promise<void>;
|
||||
):Promise<string>;
|
||||
createSVG (templatePath?:string):Promise<SVGSVGElement>;
|
||||
createPNG (templatePath?:string):Promise<any>;
|
||||
wrapText (text:string, lineLen:number):string;
|
||||
|
||||
@@ -35,7 +35,7 @@ Returns the element object matching the id. If the element does not exist, retur
|
||||
```typescript
|
||||
async create(params?:{filename: string, foldername:string, templatePath:string, onNewPane: boolean})
|
||||
```
|
||||
Creates the drawing and opens it.
|
||||
Creates the drawing and opens it. Returns the full filepath of the created file.
|
||||
|
||||
`filename` is the filename without extension of the drawing to be created. If `null`, then Excalidraw will generate a filename.
|
||||
|
||||
@@ -45,9 +45,30 @@ Creates the drawing and opens it.
|
||||
|
||||
`onNewPane` defines where the new drawing should be created. `false` will open the drawing on the current active leaf. `true` will open the drawing by vertically splitting the current leaf.
|
||||
|
||||
`frontmatterKeys` are the set of frontmatter keys to apply to the document
|
||||
{
|
||||
excalidraw-plugin?: "raw"|"parsed",
|
||||
excalidraw-link-prefix?: string,
|
||||
excalidraw-link-brackets?: boolean,
|
||||
excalidraw-url-prefix?: string
|
||||
}
|
||||
|
||||
Example:
|
||||
```javascript
|
||||
create({filename:"my drawing", foldername:"myfolder/subfolder/", templatePath: "Excalidraw/template.excalidraw", onNewPane: true});
|
||||
create (
|
||||
{
|
||||
filename:"my drawing",
|
||||
foldername:"myfolder/subfolder/",
|
||||
templatePath: "Excalidraw/template.excalidraw",
|
||||
onNewPane: true,
|
||||
frontmatterKeys: {
|
||||
"excalidraw-plugin": "parsed",
|
||||
"excalidraw-link-prefix": "",
|
||||
"excalidraw-link-brackets": true,
|
||||
"excalidraw-url-prefix": "🌐",
|
||||
}
|
||||
}
|
||||
);
|
||||
```
|
||||
### createSVG()
|
||||
```typescript
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.3.8",
|
||||
"version": "1.3.9",
|
||||
"minAppVersion": "0.12.0",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -61,9 +61,15 @@ export interface ExcalidrawAutomate extends Window {
|
||||
filename?: string,
|
||||
foldername?:string,
|
||||
templatePath?:string,
|
||||
onNewPane?: boolean
|
||||
onNewPane?: boolean,
|
||||
frontmatterKeys?:{
|
||||
"excalidraw-plugin"?: "raw"|"parsed",
|
||||
"excalidraw-link-prefix"?: string,
|
||||
"excalidraw-link-brackets"?: boolean,
|
||||
"excalidraw-url-prefix"?: string
|
||||
}
|
||||
}
|
||||
):Promise<void>;
|
||||
):Promise<string>;
|
||||
createSVG (templatePath?:string):Promise<SVGSVGElement>;
|
||||
createPNG (templatePath?:string):Promise<any>;
|
||||
wrapText (text:string, lineLen:number):string;
|
||||
@@ -243,15 +249,43 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
|
||||
getElement(id:string):ExcalidrawElement {
|
||||
return this.elementsDict[id];
|
||||
},
|
||||
async create(params?:{filename?: string, foldername?:string, templatePath?:string, onNewPane?: boolean}) {
|
||||
async create (
|
||||
params?:{
|
||||
filename?: string,
|
||||
foldername?:string,
|
||||
templatePath?:string,
|
||||
onNewPane?: boolean,
|
||||
frontmatterKeys?:{
|
||||
"excalidraw-plugin"?: "raw"|"parsed",
|
||||
"excalidraw-link-prefix"?: string,
|
||||
"excalidraw-link-brackets"?: boolean,
|
||||
"excalidraw-url-prefix"?: string
|
||||
}
|
||||
}
|
||||
):Promise<string> {
|
||||
const template = params?.templatePath ? (await getTemplate(params.templatePath)) : null;
|
||||
let elements = template ? template.elements : [];
|
||||
elements = elements.concat(this.getElements());
|
||||
plugin.createDrawing(
|
||||
let frontmatter:string;
|
||||
if(params?.frontmatterKeys) {
|
||||
const keys = Object.keys(params.frontmatterKeys);
|
||||
if(!keys.includes("excalidraw-plugin")) {
|
||||
params.frontmatterKeys["excalidraw-plugin"] = "parsed";
|
||||
}
|
||||
frontmatter = "---\n\n";
|
||||
for(const key of Object.keys(params.frontmatterKeys)) {
|
||||
//@ts-ignore
|
||||
frontmatter += key + ": " + (params.frontmatterKeys[key]==="" ? '""' : params.frontmatterKeys[key]) +"\n";
|
||||
}
|
||||
frontmatter += "\n---\n";
|
||||
} else {
|
||||
frontmatter = template?.frontmatter ? template.frontmatter : FRONTMATTER;
|
||||
}
|
||||
return plugin.createDrawing(
|
||||
params?.filename ? params.filename + '.excalidraw.md' : this.plugin.getNextDefaultFilename(),
|
||||
params?.onNewPane ? params.onNewPane : false,
|
||||
params?.foldername ? params.foldername : this.plugin.settings.folder,
|
||||
FRONTMATTER + plugin.exportSceneToMD(
|
||||
frontmatter + plugin.exportSceneToMD(
|
||||
JSON.stringify({
|
||||
type: "excalidraw",
|
||||
version: 2,
|
||||
@@ -704,21 +738,27 @@ export function measureText (newText:string, fontSize:number, fontFamily:number)
|
||||
return {w: width, h: height, baseline: baseline };
|
||||
};
|
||||
|
||||
async function getTemplate(fileWithPath: string):Promise<{elements: any,appState: any}> {
|
||||
async function getTemplate(fileWithPath: string):Promise<{elements: any,appState: any, frontmatter: string}> {
|
||||
const app = window.ExcalidrawAutomate.plugin.app;
|
||||
const vault = app.vault;
|
||||
const file = app.metadataCache.getFirstLinkpathDest(normalizePath(fileWithPath),'');
|
||||
if(file && file instanceof TFile) {
|
||||
const data = await vault.read(file);
|
||||
|
||||
let trimLocation = data.search("# Text Elements\n");
|
||||
if(trimLocation == -1) trimLocation = data.search("# Drawing\n");
|
||||
|
||||
const excalidrawData = JSON_parse(getJSON(data));
|
||||
return {
|
||||
elements: excalidrawData.elements,
|
||||
appState: excalidrawData.appState,
|
||||
frontmatter: data.substring(0,trimLocation)
|
||||
};
|
||||
};
|
||||
return {
|
||||
elements: [],
|
||||
appState: {},
|
||||
frontmatter: null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
} from "./constants";
|
||||
import { measureText } from "./ExcalidrawAutomate";
|
||||
import ExcalidrawPlugin from "./main";
|
||||
import { ExcalidrawSettings } from "./settings";
|
||||
import {
|
||||
JSON_parse
|
||||
} from "./constants";
|
||||
|
||||
@@ -218,9 +218,11 @@ export default class ExcalidrawView extends TextFileView {
|
||||
//@ts-ignore
|
||||
search[0].view.setQuery("tag:"+tags.value[1]);
|
||||
this.app.workspace.revealLeaf(search[0]);
|
||||
//if(this.gotoFullscreen.style.display=="none") this.toggleFullscreen();
|
||||
document.exitFullscreen();
|
||||
this.zoomToFit();
|
||||
//if(this.gotoFullscreen.style.display=="none") this.toggleFullscreen();
|
||||
if(document.fullscreenElement === this.contentEl) {
|
||||
document.exitFullscreen();
|
||||
this.zoomToFit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -341,7 +343,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
}
|
||||
if(!this.excalidrawRef) return;
|
||||
if(!this.file) return;
|
||||
if(file) this.data = await this.app.vault.read(file);
|
||||
if(file) this.data = await this.app.vault.cachedRead(file);
|
||||
if(fullreload) await this.excalidrawData.loadData(this.data, this.file,this.textMode);
|
||||
else await this.excalidrawData.setTextMode(this.textMode);
|
||||
await this.loadDrawing(false);
|
||||
|
||||
@@ -1088,7 +1088,7 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
return outString + this.getMarkdownDrawingSection(data);
|
||||
}
|
||||
|
||||
public async createDrawing(filename: string, onNewPane: boolean, foldername?: string, initData?:string) {
|
||||
public async createDrawing(filename: string, onNewPane: boolean, foldername?: string, initData?:string):Promise<string> {
|
||||
const folderpath = normalizePath(foldername ? foldername: this.settings.folder);
|
||||
await checkAndCreateFolder(this.app.vault,folderpath); //create folder if it does not exist
|
||||
|
||||
@@ -1096,10 +1096,11 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
|
||||
if(initData) {
|
||||
this.openDrawing(await this.app.vault.create(fname,initData),onNewPane);
|
||||
return;
|
||||
return fname;
|
||||
}
|
||||
|
||||
this.openDrawing(await this.app.vault.create(fname,await this.getBlankDrawing()), onNewPane);
|
||||
return fname;
|
||||
}
|
||||
|
||||
public async setMarkdownView(leaf: WorkspaceLeaf) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"1.3.8": "0.11.13"
|
||||
"1.3.9": "0.11.13"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user