1.2.0-alpha-3

This commit is contained in:
Zsolt Viczian
2021-07-04 22:37:04 +02:00
parent ebcf807501
commit e81787ee4b
5 changed files with 78 additions and 25 deletions

View File

@@ -175,7 +175,7 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin) {
elements.push(this.elementsDict[this.elementIds[i]]);
}
plugin.createDrawing(
params?.filename ? params.filename + '.excalidraw' : this.plugin.getNextDefaultFilename(),
params?.filename ? params.filename + '.excalidraw.md' : this.plugin.getNextDefaultFilename(),
params?.onNewPane ? params.onNewPane : false,
params?.foldername ? params.foldername : this.plugin.settings.folder,
FRONTMATTER + exportSceneToMD(

View File

@@ -60,7 +60,7 @@ export default class ExcalidrawView extends TextFileView {
private justLoaded: boolean = false;
private plugin: ExcalidrawPlugin;
private dirty: boolean = false;
private autosaveTimer: any = null;
public autosaveTimer: any = null;
public isTextLocked:boolean = false;
private lockedElement:HTMLElement;
private unlockedElement:HTMLElement;
@@ -240,16 +240,19 @@ export default class ExcalidrawView extends TextFileView {
}
}
private setupAutosaveTimer() {
public setupAutosaveTimer() {
const timer = async () => {
//console.log("ExcalidrawView.autosaveTimer(), dirty", this.dirty);
if(this.dirty) {
console.log("autosave",Date.now());
this.dirty = false;
if(this.excalidrawRef) await this.save();
this.plugin.triggerEmbedUpdates();
}
}
this.autosaveTimer = setInterval(timer,30000);
if(this.plugin.settings.autosave) {
this.autosaveTimer = setInterval(timer,30000);
}
}
//save current drawing when user closes workspace leaf

View File

@@ -22,6 +22,11 @@ export default {
INSERT_LINK: "Insert link to file",
INSERT_LATEX: "Insert LaTeX-symbol (e.g. $\\theta$)",
ENTER_LATEX: "Enter a valid LaTeX expression",
MIGRATION_NOTICE: "Welcome to Excalidraw 1.2\n\nThis version comes with major changes / improvements!\n\n"+
"⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠\n\nDrawings you created with version 1.1.x need to be migrated, they will not work out of the box. Please open the command palette CTRL+P and select " +
"'Excalidraw: MIGRATE to version 1.2: convert *.excalidraw to *.md files'\n\n⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠ ⚠\n\n" +
"This version comes with many new features and possibilities. Please read the description in Community Plugins to find out more.\n\n" +
"Thank you!",
//ExcalidrawView.ts
OPEN_AS_MD: "Open as Markdown",
@@ -48,7 +53,12 @@ export default {
TEMPLATE_DESC: "Full filepath to the Excalidraw template. " +
"E.g.: If your template is in the default Excalidraw folder and it's name is " +
"Template.excalidraw, the setting would be: Excalidraw/Template.excalidraw",
FILENAME_HEAD: "Filenam for drawings",
AUTOSAVE_NAME: "Autosave",
AUTOSAVE_DESC: "Automatically save the active drawing every 30 seconds. Save normally happens when you close Excalidraw or Obsidian, or move "+
"focus to another pane. In rare cases autosave may slightly disrupt your drawing flow. I created this feature with mobile " +
"phones in mind (I only have experience with Android), where 'swiping out Obsidian to close it' led to some data loss, and because " +
"I wasn't able to force save on application termination on mobiles. If you use Excalidraw on a desktop this is likely not needed.",
FILENAME_HEAD: "Filename",
FILENAME_DESC: "<p>The auto-generated filename consists of a prefix and a date. " +
"e.g.'Drawing 2021-05-24 12.58.07'.</p>"+
"<p>Click this link for the <a href='https://momentjs.com/docs/#/displaying/format/'>"+
@@ -58,7 +68,7 @@ export default {
FILENAME_PREFIX_DESC: "The first part of the filename",
FILENAME_DATE_NAME: "Filename date",
FILENAME_DATE_DESC: "The second part of the filename",
LINKS_HEAD: "Links in drawings",
LINKS_HEAD: "Links",
LINKS_DESC: "CTRL/META + CLICK on Text Elements to open them as links. " +
"If the selected text has more than one [[valid Obsidian links]], only the first will be opened. " +
"If the text starts as a valid web link (i.e. https:// or http://), then " +
@@ -76,7 +86,7 @@ export default {
LINK_CTRL_CLICK_NAME: "CTRL + CLICK on text to open them as links",
LINK_CTRL_CLICK_DESC: "You can turn this feature off if it interferes with default Excalidraw features you want to use. If " +
"this is turned off, only the link button in the title bar of the drawing pane will open links.",
EMBED_HEAD: "Embedded/Export image settings",
EMBED_HEAD: "Embed & Export",
EMBED_WIDTH_NAME: "Default width of embedded (transcluded) image",
EMBED_WIDTH_DESC: "The default width of an embedded drawing. You can specify a custom " +
"width when embedding an image using the ![[drawing.excalidraw|100]] or " +

View File

@@ -15,6 +15,7 @@ import {
Tasks,
MarkdownRenderer,
ViewState,
Notice,
} from "obsidian";
import {
@@ -94,8 +95,20 @@ export default class ExcalidrawPlugin extends Plugin {
//inspiration taken from kanban:
//https://github.com/mgmeyers/obsidian-kanban/blob/44118e25661bff9ebfe54f71ae33805dc88ffa53/src/main.ts#L267
this.registerMonkeyPatches();
this.migrationNotice();
}
private migrationNotice(){
const self = this;
this.app.workspace.onLayoutReady(async () => {
const excalidrawFiles = (self.app.vault.getFiles() || []).filter((f:TFile) => f.extension=="excalidraw");
if(excalidrawFiles.length > 0) {
if(Date.now()<1627775999000) //display message until July 31 2021
new Notice(t("MIGRATION_NOTICE"),30000);
}
});
}
/**
* Displays a transcluded .excalidraw image in markdown preview mode
*/
@@ -265,15 +278,17 @@ export default class ExcalidrawPlugin extends Plugin {
});
const fileMenuHandler = (menu: Menu, file: TFile) => {
if (file instanceof TFolder) {
menu.addItem((item: MenuItem) => {
item.setTitle(t("CREATE_NEW"))
.setIcon(ICON_NAME)
.onClick(evt => {
this.createDrawing(this.getNextDefaultFilename(),false,file.path);
})
});
}
menu.addItem((item: MenuItem) => {
item.setTitle(t("CREATE_NEW"))
.setIcon(ICON_NAME)
.onClick(evt => {
let folderpath = file.path;
if(file instanceof TFile) {
folderpath = normalizePath(file.path.substr(0,file.path.lastIndexOf(file.name)));
}
this.createDrawing(this.getNextDefaultFilename(),false,folderpath);
})
});
};
this.registerEvent(
@@ -695,14 +710,17 @@ export default class ExcalidrawPlugin extends Plugin {
//save Excalidraw leaf and update embeds when switching to another leaf
const activeLeafChangeEventHandler = async (leaf:WorkspaceLeaf) => {
const activeview:ExcalidrawView = (leaf.view instanceof ExcalidrawView) ? leaf.view as ExcalidrawView : null;
if(self.activeExcalidrawView && self.activeExcalidrawView != activeview) {
await self.activeExcalidrawView.save();
self.triggerEmbedUpdates(self.activeExcalidrawView.file?.path);
const activeExcalidrawView = self.activeExcalidrawView;
const newActiveview:ExcalidrawView = (leaf.view instanceof ExcalidrawView) ? leaf.view as ExcalidrawView : null;
if(activeExcalidrawView && activeExcalidrawView != newActiveview) {
await activeExcalidrawView.save();
if(activeExcalidrawView.file) {
self.triggerEmbedUpdates(activeExcalidrawView.file.path);
}
}
self.activeExcalidrawView = activeview;
if(self.activeExcalidrawView) {
self.lastActiveExcalidrawFilePath = self.activeExcalidrawView.file?.path;
self.activeExcalidrawView = newActiveview;
if(newActiveview) {
self.lastActiveExcalidrawFilePath = newActiveview.file?.path;
}
};
self.registerEvent(

View File

@@ -16,7 +16,7 @@ export interface ExcalidrawSettings {
width: string,
showLinkBrackets: boolean,
linkPrefix: string,
// validLinksOnly: boolean, //valid link as in [[valid Obsidian link]] - how to treat text elements in drawings
autosave: boolean;
allowCtrlClick: boolean, //if disabled only the link button in the view header will open links
exportWithTheme: boolean,
exportWithBackground: boolean,
@@ -34,7 +34,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
width: '400',
linkPrefix: ">> ",
showLinkBrackets: true,
// validLinksOnly: false,
autosave: false,
allowCtrlClick: true,
exportWithTheme: true,
exportWithBackground: true,
@@ -78,6 +78,28 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName(t("AUTOSAVE_NAME"))
.setDesc(t("AUTOSAVE_DESC"))
.addToggle(toggle => toggle
.setValue(this.plugin.settings.autosave)
.onChange(async (value) => {
this.plugin.settings.autosave = value;
await this.plugin.saveSettings();
const exs = this.plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
for(const v of exs) {
if(v.view instanceof ExcalidrawView) {
if(v.view.autosaveTimer) {
clearInterval(v.view.autosaveTimer)
v.view.autosaveTimer = null;
}
if(value) {
v.view.setupAutosaveTimer();
}
}
}
}));
this.containerEl.createEl('h1', {text: t("FILENAME_HEAD")});
containerEl.createDiv('',(el) => {
el.innerHTML = t("FILENAME_DESC");