This commit is contained in:
Zsolt Viczian
2021-08-22 12:38:09 +02:00
parent 6d28546677
commit caee4f7500
6 changed files with 155 additions and 126 deletions

View File

@@ -3,6 +3,7 @@ import {
nanoid,
FRONTMATTER_KEY_CUSTOM_PREFIX,
FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS,
FRONTMATTER_KEY_CUSTOM_URL_PREFIX,
} from "./constants";
import { measureText } from "./ExcalidrawAutomate";
import ExcalidrawPlugin from "./main";
@@ -17,6 +18,7 @@ const DRAWING_REG = /[\r\n]# Drawing[\r\n](```json[\r\n])?(.*)(```)?(%%)?/gm;
//![[link|alias]]![alias](link)
//1 2 3 4 5 6
export const REG_LINK_BACKETS = /(!)?\[\[([^|\]]+)\|?(.+)?]]|(!)?\[(.*)\]\((.*)\)/g;
export const REG_LINKINDEX_HYPERLINK = /^\w+:\/\//;
export function getJSON(data:string):string {
const res = data.matchAll(DRAWING_REG);
@@ -32,16 +34,15 @@ export class ExcalidrawData {
private textElements:Map<string,{raw:string, parsed:string}> = null;
public scene:any = null;
private file:TFile = null;
private settings:ExcalidrawSettings;
private app:App;
private showLinkBrackets: boolean;
private linkPrefix: string;
private urlPrefix: string;
private textMode: TextMode = TextMode.raw;
private plugin: ExcalidrawPlugin;
constructor(plugin: ExcalidrawPlugin) {
this.plugin = plugin;
this.settings = plugin.settings;
this.app = plugin.app;
}
@@ -59,6 +60,7 @@ export class ExcalidrawData {
//The drawing will use these values until next drawing is loaded or this drawing is re-loaded
this.setShowLinkBrackets();
this.setLinkPrefix();
this.setUrlPrefix();
this.scene = null;
@@ -66,7 +68,7 @@ export class ExcalidrawData {
//should be loaded as the scene.
//This feature is mostly likely only relevant to people who use Obsidian and Logseq on the same vault and edit .excalidraw
//drawings in Logseq.
if (this.settings.syncExcalidraw) {
if (this.plugin.settings.syncExcalidraw) {
const excalfile = file.path.substring(0,file.path.lastIndexOf('.md')) + '.excalidraw';
const f = this.app.vault.getAbstractFileByPath(excalfile);
if(f && f instanceof TFile && f.stat.mtime>file.stat.mtime) { //the .excalidraw file is newer then the .md file
@@ -115,6 +117,7 @@ export class ExcalidrawData {
this.textElements = new Map<string,{raw:string, parsed:string}>();
this.setShowLinkBrackets();
this.setLinkPrefix();
this.setUrlPrefix();
this.scene = JSON.parse(data);
this.findNewTextElementsInScene();
await this.setTextMode(TextMode.raw,true); //legacy files are always displayed in raw mode.
@@ -230,31 +233,6 @@ export class ExcalidrawData {
}
}
/**
* update text element map by deleting entries that are no long in the scene
* and updating the textElement map based on the text updated in the scene
*/
private updateTextElementsFromSceneRawOnly() {
for(const key of this.textElements.keys()){
//find text element in the scene
const el = this.scene.elements?.filter((el:any)=> el.type=="text" && el.id==key);
if(el.length==0) {
this.textElements.delete(key); //if no longer in the scene, delete the text element
} else {
if(!this.textElements.has(key)) {
this.textElements.set(key,{raw: el[0].text,parsed: null});
this.parseasync(key,el[0].text);
} else {
const text = (this.textMode == TextMode.parsed) ? this.textElements.get(key).parsed : this.textElements.get(key).raw;
if(text != el[0].text) {
this.textElements.set(key,{raw: el[0].text,parsed: null});
this.parseasync(key,el[0].text);
}
}
}
}
}
private async parseasync(key:string, raw:string) {
this.textElements.set(key,{raw:raw,parsed: await this.parse(raw)});
}
@@ -300,6 +278,7 @@ export class ExcalidrawData {
let position = 0;
const res = text.matchAll(REG_LINK_BACKETS);
let linkIcon = false;
let urlIcon = false;
let parts;
while(!(parts=res.next()).done) {
if (parts.value[1] || parts.value[4]) { //transclusion
@@ -308,8 +287,11 @@ export class ExcalidrawData {
} else {
const parsedLink = this.parseLinks(text,position,parts);
if(parsedLink) {
linkIcon = true;
outString += parsedLink;
if(!(urlIcon || linkIcon))
//[2]: is wiki link? [2] link text, [6] link text
if((parts.value[2] ? parts.value[2]:parts.value[6]).match(REG_LINKINDEX_HYPERLINK)) urlIcon = true;
else linkIcon = true;
}
}
position = parts.value.index + parts.value[0].length;
@@ -318,6 +300,9 @@ export class ExcalidrawData {
if (linkIcon) {
outString = this.linkPrefix + outString;
}
if (urlIcon) {
outString = this.urlPrefix + outString;
}
return outString;
}
@@ -344,12 +329,16 @@ export class ExcalidrawData {
let position = 0;
const res = text.matchAll(REG_LINK_BACKETS);
let linkIcon = false;
let urlIcon = false;
let parts;
while(!(parts=res.next()).done) {
const parsedLink = this.parseLinks(text,position,parts);
if(parsedLink) {
linkIcon = true;
outString += parsedLink;
if(!(urlIcon || linkIcon))
//[2]: is wiki link? [2] link text, [6] link text
if((parts.value[2] ? parts.value[2]:parts.value[6]).match(REG_LINKINDEX_HYPERLINK)) urlIcon = true;
else linkIcon = true;
}
position = parts.value.index + parts.value[0].length;
}
@@ -357,6 +346,9 @@ export class ExcalidrawData {
if (linkIcon) {
outString = this.linkPrefix + outString;
}
if (urlIcon) {
outString = this.urlPrefix + outString;
}
return outString;
}
@@ -374,18 +366,19 @@ export class ExcalidrawData {
return outString + this.plugin.getMarkdownDrawingSection(JSON.stringify(this.scene));
}
public syncElements(newScene:any):boolean {
public async syncElements(newScene:any):Promise<boolean> {
//console.log("Excalidraw.Data.syncElements()");
this.scene = newScene;//JSON_parse(newScene);
const result = this.setLinkPrefix() || this.setShowLinkBrackets() || this.findNewTextElementsInScene();
this.updateTextElementsFromSceneRawOnly();
const result = this.setLinkPrefix() || this.setUrlPrefix() || this.setShowLinkBrackets() || this.findNewTextElementsInScene();
//this.updateTextElementsFromSceneRawOnly();
await this.updateTextElementsFromScene();
return result;
}
public async updateScene(newScene:any){
//console.log("Excalidraw.Data.updateScene()");
this.scene = JSON_parse(newScene);
const result = this.setLinkPrefix() || this.setShowLinkBrackets() || this.findNewTextElementsInScene();
const result = this.setLinkPrefix() || this.setUrlPrefix() || this.setShowLinkBrackets() || this.findNewTextElementsInScene();
await this.updateTextElementsFromScene();
if(result) {
await this.updateSceneTextElements();
@@ -426,20 +419,33 @@ export class ExcalidrawData {
if (fileCache?.frontmatter && fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_PREFIX]!=null) {
this.linkPrefix=fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_PREFIX];
} else {
this.linkPrefix = this.settings.linkPrefix;
this.linkPrefix = this.plugin.settings.linkPrefix;
}
return linkPrefix != this.linkPrefix;
}
private setUrlPrefix():boolean {
const urlPrefix = this.urlPrefix;
const fileCache = this.app.metadataCache.getFileCache(this.file);
if (fileCache?.frontmatter && fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_URL_PREFIX]!=null) {
this.urlPrefix=fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_URL_PREFIX];
} else {
this.urlPrefix = this.plugin.settings.urlPrefix;
}
return urlPrefix != this.urlPrefix;
}
private setShowLinkBrackets():boolean {
const showLinkBrackets = this.showLinkBrackets;
const fileCache = this.app.metadataCache.getFileCache(this.file);
if (fileCache?.frontmatter && fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS]!=null) {
this.showLinkBrackets=fileCache.frontmatter[FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS]!=false;
} else {
this.showLinkBrackets = this.settings.showLinkBrackets;
this.showLinkBrackets = this.plugin.settings.showLinkBrackets;
}
return showLinkBrackets != this.showLinkBrackets;
}
}

View File

@@ -35,7 +35,7 @@ import {
import ExcalidrawPlugin from './main';
import {ExcalidrawAutomate} from './ExcalidrawAutomate';
import { t } from "./lang/helpers";
import { ExcalidrawData, REG_LINK_BACKETS } from "./ExcalidrawData";
import { ExcalidrawData, REG_LINKINDEX_HYPERLINK, REG_LINK_BACKETS } from "./ExcalidrawData";
import { checkAndCreateFolder, download, getNewUniqueFilepath, splitFolderAndFilename } from "./Utils";
import { Prompt } from "./Prompt";
@@ -55,7 +55,6 @@ export interface ExportSettings {
withTheme: boolean
}
const REG_LINKINDEX_HYPERLINK = /^\w+:\/\//;
const REG_LINKINDEX_INVALIDCHARS = /[<>:"\\|?*]/g;
export default class ExcalidrawView extends TextFileView {
@@ -74,8 +73,8 @@ export default class ExcalidrawView extends TextFileView {
public textMode:TextMode = TextMode.raw;
private textIsParsed_Element:HTMLElement;
private textIsRaw_Element:HTMLElement;
private gotoFullscreen:HTMLElement;
private exitFullscreen:HTMLElement;
/* private gotoFullscreen:HTMLElement;
private exitFullscreen:HTMLElement;*/
private preventReload:boolean = true;
public compatibilityMode: boolean = false;
//store key state for view mode link resolution
@@ -152,8 +151,17 @@ export default class ExcalidrawView extends TextFileView {
}
async save(preventReload:boolean=true) {
if(!this.getScene) return;
this.preventReload = preventReload;
this.dirty = null;
if(this.compatibilityMode) {
await this.excalidrawData.syncElements(this.getScene());
} else {
if(await this.excalidrawData.syncElements(this.getScene()) && !this.autosaving) {
await this.loadDrawing(false);
}
}
await super.save();
}
@@ -164,9 +172,6 @@ export default class ExcalidrawView extends TextFileView {
//console.log("ExcalidrawView.getViewData()");
if(!this.getScene) return this.data;
if(!this.compatibilityMode) {
if(this.excalidrawData.syncElements(this.getScene()) && !this.autosaving) {
this.loadDrawing(false);
}
let trimLocation = this.data.search("# Text Elements\n");
if(trimLocation == -1) trimLocation = this.data.search("# Drawing\n");
if(trimLocation == -1) return this.data;
@@ -183,7 +188,6 @@ export default class ExcalidrawView extends TextFileView {
return header + this.excalidrawData.generateMD();
}
if(this.compatibilityMode) {
this.excalidrawData.syncElements(this.getScene());
const scene = this.excalidrawData.scene;
if(!this.autosaving) {
if(this.plugin.settings.autoexportSVG) this.saveSVG(scene);
@@ -204,7 +208,8 @@ export default class ExcalidrawView extends TextFileView {
}
if(text.match(REG_LINKINDEX_HYPERLINK)) {
window.open(text,"_blank");
return; }
return;
}
//![[link|alias]]![alias](link)
//1 2 3 4 5 6
@@ -220,7 +225,9 @@ 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();
//if(this.gotoFullscreen.style.display=="none") this.toggleFullscreen();
document.exitFullscreen();
this.zoomToFit();
return;
}
@@ -245,7 +252,11 @@ export default class ExcalidrawView extends TextFileView {
}
try {
const f = view.file;
if(ev.shiftKey && this.gotoFullscreen.style.display=="none") this.toggleFullscreen();
//if(ev.shiftKey && this.gotoFullscreen.style.display=="none") this.toggleFullscreen();
if(ev.shiftKey) {
document.exitFullscreen();
this.zoomToFit();
}
view.app.workspace.openLinkText(text,view.file.path,ev.shiftKey);
} catch (e) {
new Notice(e,4000);
@@ -264,12 +275,19 @@ export default class ExcalidrawView extends TextFileView {
this.addAction("link",t("OPEN_LINK"), (ev)=>this.handleLinkClick(this,ev));
this.gotoFullscreen = this.addAction(FULLSCREEN_ICON_NAME,"",()=>this.toggleFullscreen());
this.exitFullscreen = this.addAction(EXIT_FULLSCREEN_ICON_NAME,"",()=>this.toggleFullscreen());
this.exitFullscreen.hide();
//@ts-ignore
if(this.app.isMobile) this.gotoFullscreen.hide();
if(!this.app.isMobile) {
this.addAction(FULLSCREEN_ICON_NAME,"Press ESC to exit fullscreen mode",()=>{
this.contentEl.requestFullscreen({navigationUI: "hide"});
if(this.excalidrawWrapperRef) this.excalidrawWrapperRef.current.focus();
this.zoomToFit();
});
}
//this.gotoFullscreen = this.addAction(FULLSCREEN_ICON_NAME,"Press ESC to exit fullscreen mode",()=>this.toggleFullscreen());
//this.exitFullscreen = this.addAction(EXIT_FULLSCREEN_ICON_NAME,"",()=>this.toggleFullscreen());
//this.exitFullscreen.hide();
//@ts-ignore
//if(this.app.isMobile) this.gotoFullscreen.hide();
//this is to solve sliding panes bug
if (this.app.workspace.layoutReady) {
@@ -282,11 +300,11 @@ export default class ExcalidrawView extends TextFileView {
this.setupAutosaveTimer();
}
private toggleFullscreen() {
/*private toggleFullscreen() {
//@ts-ignore
if(this.app.isMobile) return;
if(this.exitFullscreen.style.display=="none") {
this.containerEl.requestFullscreen();
this.containerEl.requestFullscreen({ navigationUI: "hide" });
this.gotoFullscreen.hide();
this.exitFullscreen.show();
} else {
@@ -295,7 +313,7 @@ export default class ExcalidrawView extends TextFileView {
this.exitFullscreen.hide();
}
this.zoomToFit();
}
}*/
public async changeTextMode(textMode:TextMode,reload:boolean=true) {
this.textMode = textMode;
@@ -343,7 +361,7 @@ export default class ExcalidrawView extends TextFileView {
if(file) this.data = await this.app.vault.read(file);
if(fullreload) await this.excalidrawData.loadData(this.data, this.file,this.textMode);
else await this.excalidrawData.setTextMode(this.textMode);
this.loadDrawing(false);
await this.loadDrawing(false);
this.dirty = null;
}
@@ -372,7 +390,7 @@ export default class ExcalidrawView extends TextFileView {
if(!(await this.excalidrawData.loadData(data, this.file,this.textMode))) return;
}
if(clear) this.clear();
this.loadDrawing(true)
await this.loadDrawing(true)
});
}
@@ -380,7 +398,7 @@ export default class ExcalidrawView extends TextFileView {
*
* @param justloaded - a flag to trigger zoom to fit after the drawing has been loaded
*/
private loadDrawing(justloaded:boolean) {
private async loadDrawing(justloaded:boolean) {
const excalidrawData = this.excalidrawData.scene;
if(this.excalidrawRef) {
const viewModeEnabled = this.excalidrawRef.current.getAppState().viewModeEnabled;
@@ -402,13 +420,11 @@ export default class ExcalidrawView extends TextFileView {
if(this.excalidrawWrapperRef) this.excalidrawWrapperRef.current.focus();
} else {
this.justLoaded = justloaded;
(async() => {
this.instantiateExcalidraw({
elements: excalidrawData.elements,
appState: excalidrawData.appState,
libraryItems: await this.getLibrary(),
});
})();
this.instantiateExcalidraw({
elements: excalidrawData.elements,
appState: excalidrawData.appState,
libraryItems: await this.getLibrary(),
});
}
}
@@ -737,15 +753,22 @@ export default class ExcalidrawView extends TextFileView {
this.plugin.hover.linkText = linktext;
this.plugin.hover.sourcePath = this.file.path;
hoverPreviewTarget = e.target;
hoverPreviewTarget = this.contentEl; //e.target;
this.app.workspace.trigger('hover-link', {
event: this.mouseEvent,
source: VIEW_TYPE_EXCALIDRAW,
hoverParent: e.target,
targetEl: e.target,
hoverParent: hoverPreviewTarget,
targetEl: hoverPreviewTarget,
linktext: this.plugin.hover.linkText,
});
hoverPoint = currentPosition;
if(document.fullscreenElement === this.contentEl) {
const self = this;
setTimeout(()=>{
const popover = document.body.querySelector("div.popover");
if(popover) self.contentEl.append(popover);
},100)
}
}
},
onKeyUp: (e:any) => {

View File

@@ -5,6 +5,7 @@ import {customAlphabet} from "nanoid";
export const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',8);
export const FRONTMATTER_KEY = "excalidraw-plugin";
export const FRONTMATTER_KEY_CUSTOM_PREFIX = "excalidraw-link-prefix";
export const FRONTMATTER_KEY_CUSTOM_URL_PREFIX = "excalidraw-url-prefix";
export const FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS = "excalidraw-link-brackets";
export const VIEW_TYPE_EXCALIDRAW = "excalidraw";
export const ICON_NAME = "excalidraw-icon";
@@ -14,8 +15,8 @@ export const RERENDER_EVENT = "excalidraw-embed-rerender";
export const BLANK_DRAWING = '{"type":"excalidraw","version":2,"source":"https://excalidraw.com","elements":[],"appState":{"gridSize":null,"viewBackgroundColor":"#ffffff"}}';
export const FRONTMATTER = ["---","",`${FRONTMATTER_KEY}: unlocked`,"","---", "==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==", "",""].join("\n");
export const EMPTY_MESSAGE = "Hit enter to create a new drawing";
export const TEXT_DISPLAY_PARSED_ICON_NAME = "presentation";
export const TEXT_DISPLAY_RAW_ICON_NAME = "quote-glyph";
export const TEXT_DISPLAY_PARSED_ICON_NAME = "quote-glyph";
export const TEXT_DISPLAY_RAW_ICON_NAME = "presentation";
export const FULLSCREEN_ICON_NAME="fullscreen";
export const EXIT_FULLSCREEN_ICON_NAME = "exit-fullscreen";
export const DISK_ICON_NAME = "disk";

View File

@@ -1,4 +1,4 @@
import { FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS, FRONTMATTER_KEY_CUSTOM_PREFIX } from "src/constants";
import { FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS, FRONTMATTER_KEY_CUSTOM_PREFIX, FRONTMATTER_KEY_CUSTOM_URL_PREFIX } from "src/constants";
// English
export default {
@@ -39,8 +39,8 @@ export default {
FILENAME_INVALID_CHARS: 'File name cannot contain any of the following characters: * " \\  < > : | ?',
FILE_DOES_NOT_EXIST: "File does not exist. Hold down ALT (or ALT+SHIFT) and CLICK link button to create a new file.",
FORCE_SAVE: "Force-save to update transclusions in adjacent panes.\n(Please note, that autosave is always on)",
RAW: "Text-elements are displayed in RAW mode. Click button to change to PREVIEW mode.",
PARSED: "Text-elements are displayed in PREVIEW mode. Click button to change to RAW mode.",
RAW: "Change to PREVIEW mode (only effects text-elements with links or transclusions)",
PARSED: "Change to RAW mode (only effects text-elements with links or transclusions)",
NOFILE: "Excalidraw (no file)",
COMPATIBILITY_MODE: "*.excalidraw file opened in compatibility mode. Convert to new format for full plugin functionality.",
CONVERT_FILE: "Convert to new format",
@@ -77,13 +77,17 @@ export default {
"When Obsidian files change, the matching [[link]] in your drawings will also change. " +
"If you don't want text accidentally changing in your drawings use [[links|with aliases]].",
LINK_BRACKETS_NAME: "Show [[brackets]] around links",
LINK_BRACKETS_DESC: "In preview (locked) mode, when parsing Text Elements, place brackets around links. " +
LINK_BRACKETS_DESC: "In PREVIEW mode, when parsing Text Elements, place brackets around links. " +
"You can override this setting for a specific drawing by adding '" + FRONTMATTER_KEY_CUSTOM_LINK_BRACKETS +
": true/false' to the file\'s frontmatter.",
LINK_PREFIX_NAME:"Link prefix",
LINK_PREFIX_DESC:"In preview (locked) mode, if the Text Element contains a link, precede the text with these characters. " +
LINK_PREFIX_DESC:"In PREVIEW mode, if the Text Element contains a link, precede the text with these characters. " +
"You can override this setting for a specific drawing by adding \'" + FRONTMATTER_KEY_CUSTOM_PREFIX +
': "👉 "\' to the file\'s frontmatter.',
': "📍 "\' to the file\'s frontmatter.',
URL_PREFIX_NAME:"URL prefix",
URL_PREFIX_DESC:"In PREVIEW mode, if the Text Element contains a URL link, precede the text with these characters. " +
"You can override this setting for a specific drawing by adding \'" + FRONTMATTER_KEY_CUSTOM_URL_PREFIX +
': "🌐 "\' to the file\'s frontmatter.',
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.",
@@ -128,7 +132,7 @@ export default {
FILETYPE_DESC: "Excalidraw files will receive an indicator using the emojii or text defined in the next setting.",
FILETAG_NAME: "Set the type indicator for excalidraw.md files",
FILETAG_DESC: "The text or emojii to display as type indicator.",
INSERT_EMOJI: "Insert an emoji",
//openDrawings.ts

View File

@@ -893,14 +893,11 @@ export default class ExcalidrawPlugin extends Plugin {
);
//save open drawings when user quits the application
const quitEventHandler = (tasks: Tasks) => {
const quitEventHandler = async (tasks: Tasks) => {
const leaves = self.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
for (let i=0;i<leaves.length;i++) {
(leaves[i].view as ExcalidrawView).save();
await (leaves[i].view as ExcalidrawView).save(true);
}
this.settings.drawingOpenCount += this.opencount;
this.settings.loadCount++;
//this.saveSettings();
}
self.registerEvent(
self.app.workspace.on("quit",quitEventHandler)

View File

@@ -18,7 +18,7 @@ export interface ExcalidrawSettings {
width: string,
showLinkBrackets: boolean,
linkPrefix: string,
//autosave: boolean;
urlPrefix: string,
allowCtrlClick: boolean, //if disabled only the link button in the view header will open links
pngExportScale: number,
exportWithTheme: boolean,
@@ -44,8 +44,8 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
displaySVGInPreview: true,
width: '400',
linkPrefix: "📍",
urlPrefix: "🌐",
showLinkBrackets: true,
//autosave: false,
allowCtrlClick: true,
pngExportScale: 1,
exportWithTheme: true,
@@ -65,13 +65,31 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
export class ExcalidrawSettingTab extends PluginSettingTab {
plugin: ExcalidrawPlugin;
private requestEmbedUpdate:boolean = false;
private requestReloadDrawings:boolean = false;
constructor(app: App, plugin: ExcalidrawPlugin) {
super(app, plugin);
this.plugin = plugin;
}
async hide() {
if(this.requestReloadDrawings) {
const exs = this.plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
for(const v of exs) {
if(v.view instanceof ExcalidrawView) {
await v.view.save(false);
await v.view.reload(true);
}
}
this.requestEmbedUpdate = true;
}
if(this.requestEmbedUpdate) this.plugin.triggerEmbedUpdates();
}
display(): void {
this.requestEmbedUpdate = false;
this.requestReloadDrawings = false;
let {containerEl} = this;
this.containerEl.empty();
@@ -97,28 +115,6 @@ 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");
@@ -163,17 +159,6 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
this.containerEl.createEl('h1', {text: t("LINKS_HEAD")});
this.containerEl.createEl('p',{
text: t("LINKS_DESC")});
const reloadDrawings = async () => {
const exs = this.plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
for(const v of exs) {
if(v.view instanceof ExcalidrawView) {
await v.view.save(false);
v.view.reload(true);
}
}
this.plugin.triggerEmbedUpdates();
}
new Setting(containerEl)
.setName(t("LINK_BRACKETS_NAME"))
@@ -183,19 +168,32 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.showLinkBrackets = value;
await this.plugin.saveSettings();
reloadDrawings();
this.requestReloadDrawings = true;
}));
new Setting(containerEl)
.setName(t("LINK_PREFIX_NAME"))
.setDesc(t("LINK_PREFIX_DESC"))
.addText(text => text
.setPlaceholder('📍')
.setPlaceholder(t("INSERT_EMOJI"))
.setValue(this.plugin.settings.linkPrefix)
.onChange(async (value) => {
.onChange((value) => {
console.log(value);
this.plugin.settings.linkPrefix = value;
this.plugin.saveSettings();
this.requestReloadDrawings = true;
}));
new Setting(containerEl)
.setName(t("URL_PREFIX_NAME"))
.setDesc(t("URL_PREFIX_DESC"))
.addText(text => text
.setPlaceholder(t("INSERT_EMOJI"))
.setValue(this.plugin.settings.urlPrefix)
.onChange(async (value) => {
this.plugin.settings.urlPrefix = value;
await this.plugin.saveSettings();
reloadDrawings();
this.requestReloadDrawings = true;
}));
new Setting(containerEl)
@@ -231,7 +229,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.width = value;
await this.plugin.saveSettings();
this.plugin.triggerEmbedUpdates();
this.requestEmbedUpdate = true;
}));
let scaleText:HTMLDivElement;
@@ -245,7 +243,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.onChange(async (value)=> {
scaleText.innerText = " " + value.toString();
this.plugin.settings.pngExportScale = value;
this.plugin.saveSettings();
await this.plugin.saveSettings();
}))
.settingEl.createDiv('',(el)=>{
scaleText = el;
@@ -262,7 +260,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.exportWithBackground = value;
await this.plugin.saveSettings();
this.plugin.triggerEmbedUpdates();
this.requestEmbedUpdate = true;
}));
new Setting(containerEl)
@@ -273,7 +271,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.exportWithTheme = value;
await this.plugin.saveSettings();
this.plugin.triggerEmbedUpdates();
this.requestEmbedUpdate = true;
}));
this.containerEl.createEl('h1', {text: t("EXPORT_HEAD")});
@@ -359,7 +357,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
.setName(t("FILETAG_NAME"))
.setDesc(t("FILETAG_DESC"))
.addText(text => text
.setPlaceholder('✏️')
.setPlaceholder(t("INSERT_EMOJI"))
.setValue(this.plugin.settings.experimentalFileTag)
.onChange(async (value) => {
this.plugin.settings.experimentalFileTag = value;