diff --git a/manifest.json b/manifest.json index cc58eb3..d6ea549 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.6.17", + "version": "1.6.18", "minAppVersion": "0.12.16", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/package.json b/package.json index 368fbd3..368c356 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "author": "", "license": "MIT", "dependencies": { - "@zsviczian/excalidraw": "0.11.0-obsidian-4", + "@zsviczian/excalidraw": "0.11.0-obsidian-5", "monkey-around": "^2.3.0", "react": "^17.0.2", "react-dom": "^17.0.2", diff --git a/src/ActionButton.tsx b/src/ActionButton.tsx index dcd990c..a1269c3 100644 --- a/src/ActionButton.tsx +++ b/src/ActionButton.tsx @@ -32,12 +32,12 @@ export class ActionButton extends React.Component { }} className="ToolIcon_type_button ToolIcon_size_small ToolIcon_type_button--show ToolIcon" title={this.props.title} - onClick={() => { + onClick={(event: React.MouseEvent) => { if (this.toastMessageTimeout) { window.clearTimeout(this.toastMessageTimeout); this.toastMessageTimeout = 0; } - this.props.action(); + this.props.action(event); }} onPointerDown={() => { this.toastMessageTimeout = window.setTimeout( diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index c9fc38a..d5e75b0 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -308,7 +308,7 @@ export class EmbeddedFilesLoader { const entries = excalidrawData.getFileEntries(); //debug({where:"EmbeddedFileLoader.loadSceneFiles",uid:this.uid,isDark:this.isDark,sceneTheme:excalidrawData.scene.appState.theme}); if (this.isDark === undefined) { - this.isDark = excalidrawData.scene.appState.theme === "dark"; + this.isDark = excalidrawData?.scene?.appState?.theme === "dark"; } let entry; const files: FileData[] = []; diff --git a/src/ExcalidrawData.ts b/src/ExcalidrawData.ts index 3932a58..fe24e6f 100644 --- a/src/ExcalidrawData.ts +++ b/src/ExcalidrawData.ts @@ -399,24 +399,26 @@ export class ExcalidrawData { const text = data.substring(position, parts.value.index); const id: string = parts.value[1]; const textEl = this.scene.elements.filter((el: any) => el.id === id)[0]; - if (textEl.type !== "text") { - //markdown link attached to elements - textEl.link = text; - this.elementLinks.set(id, text); - } else { - const wrapAt = estimateMaxLineLen(textEl.text, textEl.originalText); - const parseRes = await this.parse(text); - this.textElements.set(id, { - raw: text, - parsed: parseRes.parsed, - wrapAt, - }); - if (parseRes.link) { - textEl.link = parseRes.link; - } - //this will set the rawText field of text elements imported from files before 1.3.14, and from other instances of Excalidraw - if (textEl && (!textEl.rawText || textEl.rawText === "")) { - textEl.rawText = text; + if (textEl) { + if (textEl.type !== "text") { + //markdown link attached to elements + textEl.link = text; + this.elementLinks.set(id, text); + } else { + const wrapAt = estimateMaxLineLen(textEl.text, textEl.originalText); + const parseRes = await this.parse(text); + this.textElements.set(id, { + raw: text, + parsed: parseRes.parsed, + wrapAt, + }); + if (parseRes.link) { + textEl.link = parseRes.link; + } + //this will set the rawText field of text elements imported from files before 1.3.14, and from other instances of Excalidraw + if (textEl && (!textEl.rawText || textEl.rawText === "")) { + textEl.rawText = text; + } } } position = parts.value.index + BLOCKREF_LEN; diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index e5d7ca3..d76f11e 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -52,7 +52,7 @@ import { import { checkAndCreateFolder, checkExcalidrawVersion, - //debug, + debug, download, embedFontsInSVG, errorlog, @@ -162,7 +162,7 @@ export default class ExcalidrawView extends TextFileView { //the modifyEventHandler in main.ts will fire when an Excalidraw file has changed (e.g. due to sync) //when a drawing that is currently open in a view receives a sync update, excalidraw reload() is triggered //the preventAutozoomOnLoad flag will prevent the open drawing from autozooming when it is reloaded - preventAutozoomOnLoad: boolean, + preventAutozoom: boolean, autosaving: boolean, //flags that autosaving is in progress. Autosave is an async timer, the flag prevents collision with force save forceSaving: boolean, //flags that forcesaving is in progress. The flag prevents collision with autosaving @@ -182,7 +182,7 @@ export default class ExcalidrawView extends TextFileView { saving: boolean, } = { justLoaded: false, - preventAutozoomOnLoad: false, + preventAutozoom: false, autosaving: false, dirty: null, preventReload: true, @@ -214,6 +214,11 @@ export default class ExcalidrawView extends TextFileView { this.excalidrawData = new ExcalidrawData(plugin); } + preventAutozoom() { + this.semaphores.preventAutozoom=true; + setTimeout(()=>this.semaphores.preventAutozoom = false,2000) + } + public saveExcalidraw(scene?: any) { if (!scene) { if (!this.getScene) { @@ -894,7 +899,7 @@ export default class ExcalidrawView extends TextFileView { const loadOnModifyTrigger = file && file === this.file; if (loadOnModifyTrigger) { this.data = await this.app.vault.cachedRead(file); - this.semaphores.preventAutozoomOnLoad = true; + this.preventAutozoom(); } if (fullreload) { await this.excalidrawData.loadData(this.data, this.file, this.textMode); @@ -1029,7 +1034,7 @@ export default class ExcalidrawView extends TextFileView { e.message === "Cannot read property 'index' of undefined" ? "\n'# Drawing' section is likely missing" : "" - }\n\nTry manually fixing the file or restoring an earlier version from sync history.\n\nYou may also look for the backup file with last working version in the same folder (same filename as your drawing, but starting with a dot. e.g. drawing.md => .drawing.md.bak). Note the backup files do not get synchronized, so look for the backup file on other devices as well.`, + }\n\nTry manually fixing the file or restoring an earlier version from sync history.`, 10000, ); this.setMarkdownView(); @@ -1044,6 +1049,9 @@ export default class ExcalidrawView extends TextFileView { public activeLoader: EmbeddedFilesLoader = null; private nextLoader: EmbeddedFilesLoader = null; public async loadSceneFiles() { + if(!this.excalidrawAPI) { + return; + } const loader = new EmbeddedFilesLoader(this.plugin); const runLoader = (l: EmbeddedFilesLoader) => { @@ -2074,12 +2082,9 @@ export default class ExcalidrawView extends TextFileView { viewModeEnabled = st.viewModeEnabled; if (this.semaphores.justLoaded) { this.semaphores.justLoaded = false; - if (!this.semaphores.preventAutozoomOnLoad) { + if (!this.semaphores.preventAutozoom) { this.zoomToFit(false); } - if(!this.initialContainerSizeUpdate) { //see comment @private updateContainerSize - this.semaphores.preventAutozoomOnLoad = false; - } this.previousSceneVersion = getSceneVersion(et); this.previousBackgroundColor = st.viewBackgroundColor; return; diff --git a/src/Messages.ts b/src/Messages.ts index 6f664b4..72addec 100644 --- a/src/Messages.ts +++ b/src/Messages.ts @@ -24,19 +24,39 @@ If you find this plugin valuable, please consider supporting.
`, +"1.6.18": ` +
+ +
+ +## Fixed +- Modifying properties of a text element in tray mode. [496](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/496) +- Friendly page aliases with iframely should work more reliably now. +- I further improved resilience of loading from a damaged Excalidraw.md file. + +## New Features +### From excalidraw.com +- Added Eraser [4887](https://github.com/excalidraw/excalidraw/pull/4887) + +### Plugin +- New setting for default transcluded-text line-wrap length. This is the default value for "wrapAt" in ${String.fromCharCode(96)}![[file#^block]]{wrapAt}${String.fromCharCode(96)}. Wrapping text using this feature will insert linebreaks in the transcluded text. An alternative approach is to transclude text inside sticky notes, in which case Excalidraw will automatically take care of text wrapping depending on the sticky note's width. [228](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/228) +- New command palette action to toggle fullscreen mode, so you can assign a hotkey. +- I added basic support for left-handed users. Enable it in plugin settings under the "Display" section. Currently, only affects the position of the tray in tray-mode. [510](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/510) +- More flexible filename settings. ⚠ Due to the change, current settings may behave slightly differently compared to before. ⚠ [470](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/470) +`, "1.6.17": `
-# Fixed +## Fixed - Freedraw shape's background color was missing in the SVG export. [#443](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/443) - In rare cases, when you only changed the background color of the drawing or edited the dimensions of an embedded markdown document, or changed an existing LaTeX formula, and then moved to another document in the vault, these changes did not get saved. [#503](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/503) - I resolved an Excalidraw Automate glitch with word wrapping in containers. EA generated containers with fixed line breaks. The same error also affected the conversion of drawings from the "legacy" Excalidraw.com file format. - When you allow/disable autosave in settings, this change will immediately take effect for all open Excalidraw workspace leaves. Until now autosave was activated only after you closed and reopened the Excalidraw view. [#502](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/502) - When you create a text element containing a ${String.fromCharCode(96,96,96)}[[markdown link]]${String.fromCharCode(96,96,96)} in raw mode, the new link was parsed nonetheless, and sometimes the link disappeared, leaving only the parsed text without the actual link. Creating links in raw-mode now works correctly. -# New Features +## New Features - The most recent 5 custom colors from the canvas are now added as color options to the element stroke and element background palette. [#4843](https://github.com/excalidraw/excalidraw/pull/4843) - Vertical text alignment for text in sticky notes [#4852](https://github.com/excalidraw/excalidraw/pull/4852) - Markdown embeds into Excalidraw now receive default styling, including that of tables, blockquotes, and code blocks. I also added a new setting and corresponding frontmatter-key to set the border-color for the embedded markdown document. You can override plugin settings at the document level by adding ${String.fromCharCode(96,96,96)}excalidraw-border-color: steelblue${String.fromCharCode(96,96,96)} to the markdown document you want to embed into your drawing. Valid values are css-color-name|#HEXcolor|any-other-html-standard-format. diff --git a/src/Utils.ts b/src/Utils.ts index 8c3adca..365cd70 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -22,6 +22,7 @@ import ExcalidrawPlugin from "./main"; import { ExcalidrawElement } from "@zsviczian/excalidraw/types/element/types"; import { ExportSettings } from "./ExcalidrawView"; import { compressToBase64, decompressFromBase64 } from "lz-string"; +import { ExcalidrawSettings } from "./Settings"; declare module "obsidian" { interface Workspace { @@ -146,12 +147,15 @@ export function getNewUniqueFilepath( let fname = normalizePath(`${folderpath}/${filename}`); let file: TAbstractFile = vault.getAbstractFileByPath(fname); let i = 0; + const extension = filename.endsWith(".excalidraw.md") + ? ".excalidraw.md" + : filename.slice(filename.lastIndexOf(".")) while (file) { fname = normalizePath( `${folderpath}/${filename.slice( 0, - filename.lastIndexOf("."), - )}_${i}${filename.slice(filename.lastIndexOf("."))}`, + filename.lastIndexOf(extension), + )}_${i}${extension}`, ); i++; file = vault.getAbstractFileByPath(fname); @@ -159,6 +163,34 @@ export function getNewUniqueFilepath( return fname; } +export function getDrawingFilename(settings:ExcalidrawSettings):string { + return settings.drawingFilenamePrefix + + (settings.drawingFilenameDateTime !== "" + ? window.moment().format(settings.drawingFilenameDateTime) + : "") + + (settings.compatibilityMode + ? ".excalidraw" + : settings.useExcalidrawExtension + ? ".excalidraw.md" + : ".md") +} + +export function getEmbedFilename(notename: string, settings:ExcalidrawSettings):string { + return ( + settings.drawingEmbedPrefixWithFilename + ? notename + : "") + + settings.drawingFilnameEmbedPostfix + + (settings.drawingFilenameDateTime !== "" + ? window.moment().format(settings.drawingFilenameDateTime) + : "") + + (settings.compatibilityMode + ? ".excalidraw" + : settings.useExcalidrawExtension + ? ".excalidraw.md" + : ".md") +} + /** * Open or create a folderpath if it does not exist * @param folderpath @@ -523,6 +555,18 @@ export const scaleLoadedImage = ( } }; +export const setLeftHandedMode = (isLeftHanded: boolean) => { + const newStylesheet = document.createElement("style"); + newStylesheet.id = "excalidraw-letf-handed"; + newStylesheet.textContent = `.excalidraw .App-bottom-bar{justify-content:right;}`; + const oldStylesheet = document.getElementById(newStylesheet.id); + if (oldStylesheet) { + document.head.removeChild(oldStylesheet); + } + if(isLeftHanded) + document.head.appendChild(newStylesheet); +} + export const isObsidianThemeDark = () => document.body.classList.contains("theme-dark"); diff --git a/src/constants.ts b/src/constants.ts index 1f9fd45..1dca27b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,6 +44,7 @@ export const FRONTMATTER = [ "---", "", `${FRONTMATTER_KEY}: parsed`, + "tags: [excalidraw]", "", "---", "==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==", diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index ec9f22b..a8ef557 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -126,26 +126,32 @@ export default { "The time interval between saves. Autosave will skip if there are no changes in the drawing.", FILENAME_HEAD: "Filename", FILENAME_DESC: - "

The auto-generated filename consists of a prefix and a date. " + - "e.g.'Drawing 2021-05-24 12.58.07'.

" + "

Click this link for the " + "date and time format reference.

", - FILENAME_SAMPLE: "The current file format is: ", + FILENAME_SAMPLE: "Filename for a new drawing is: ", + FILENAME_EMBED_SAMPLE: "Filename for a new embedded drawing is: ", FILENAME_PREFIX_NAME: "Filename prefix", FILENAME_PREFIX_DESC: "The first part of the filename", - FILENAME_PREFIX_EMBED_NAME: "Filename prefix for embedded files", + FILENAME_PREFIX_EMBED_NAME: "Filename prefix when embedding a new drawing into a markdown note", FILENAME_PREFIX_EMBED_DESC: - "Name of the newly inserted drawing should start with the name of the active note " + - "when using the command palette action: 'Create a new drawing and embed into active document'. " + - "On: yes, Off: not", - FILENAME_DATE_NAME: "Filename date", - FILENAME_DATE_DESC: "The second part of the filename", + "Should the filename of the newly inserted drawing start with the name of the active markdown note " + + "when using the command palette action: Create a new drawing and embed into active document? " + + "ON: Yes, OFF: Not", + FILENAME_POSTFIX_NAME: "Custom text after markdown Note's name when embedding", + FILENAME_POSTFIX_DESC: "Effects filename only when embedding into a markdown document. This is text will be inserted after the note's name, but before the date.", + FILENAME_DATE_NAME: "Filename Date", + FILENAME_DATE_DESC: "The last part of the filename. Leave empty if you do not want a date.", + FILENAME_EXCALIDRAW_EXTENSION_NAME: ".excalidraw.md or .md", + FILENAME_EXCALIDRAW_EXTENSION_DESC: "This setting does not apply if you use Excalidraw in compatibility mode, " + + "i.e. you are not using Excalidraw markdown files. Toggle ON = filename ends with .excalidraw.md, Toggle OFF = filename ends with .md", /*SVG_IN_MD_NAME: "SVG Snapshot to markdown file", SVG_IN_MD_DESC: "If the switch is 'on' Excalidraw will include an SVG snapshot in the markdown file. "+ "When SVG snapshots are saved to the Excalidraw.md file, drawings that include large png, jpg, gif images may take extreme long time to open in markdown view. " + "On the other hand, SVG snapshots provide some level of platform independence and longevity to your drawings. Even if Excalidraw will no longer exist, the snapshot " + "can be opened with an app that reads SVGs. In addition hover previews will be less resource intensive if SVG snapshots are enabled.",*/ DISPLAY_HEAD: "Display", + LEFTHANDED_MODE_NAME: "Left-handed mode", + LEFTHANDED_MODE_DESC: "Currently only has effect in tray-mode. If turned on, the tray will be on the right side.", MATCH_THEME_NAME: "New drawing to match Obsidian theme", MATCH_THEME_DESC: "If theme is dark, new drawing will be created in dark mode. This does not apply when you use a template for new drawings. " + @@ -377,4 +383,5 @@ export default { //ObsidianMenu.tsx GOTO_FULLSCREEN: "Goto fullscreen mode", EXIT_FULLSCREEN: "Exit fullscreen mode", + TOGGLE_FULLSCREEN: "Toggle fullscreen mode", }; diff --git a/src/lang/locale/zh-cn.ts b/src/lang/locale/zh-cn.ts index 16dc547..c31503c 100644 --- a/src/lang/locale/zh-cn.ts +++ b/src/lang/locale/zh-cn.ts @@ -92,7 +92,7 @@ export default { "例如 'Drawing 2021-05-24 12.58.07'。

" + "

可参考" + "日期和时间格式说明来进行修改。

", - FILENAME_SAMPLE: "当前文件名的格式为:", + FILENAME_SAMPLE: "当前文件名的格式为:", FILENAME_PREFIX_NAME: "文件名前缀", FILENAME_PREFIX_DESC: "文件名的第一部分", FILENAME_DATE_NAME: "文件名日期", diff --git a/src/main.ts b/src/main.ts index 669deeb..0fa4c86 100644 --- a/src/main.ts +++ b/src/main.ts @@ -72,6 +72,8 @@ import { download, errorlog, getAttachmentsFolderAndFilePath, + getDrawingFilename, + getEmbedFilename, getFontDataURL, getIMGFilename, getIMGPathFromExcalidrawFile, @@ -79,6 +81,7 @@ import { getPNG, isObsidianThemeDark, log, + setLeftHandedMode, sleep, } from "./Utils"; //import { OneOffs } from "./OneOffs"; @@ -92,6 +95,7 @@ import { } from "./MarkdownPostProcessor"; import { FieldSuggestor } from "./FieldSuggestor"; import { ReleaseNotes } from "./ReleaseNotes"; +import { debug } from "./Utils"; declare module "obsidian" { interface App { @@ -602,7 +606,7 @@ export default class ExcalidrawPlugin extends Plugin { this.insertMDDialog = new InsertMDDialog(this); this.addRibbonIcon(ICON_NAME, t("CREATE_NEW"), async (e) => { - this.createAndOpenDrawing(this.getNextDefaultFilename(), e[CTRL_OR_CMD]); //.ctrlKey||e.metaKey); + this.createAndOpenDrawing(getDrawingFilename(this.settings), e[CTRL_OR_CMD]); //.ctrlKey||e.metaKey); }); const fileMenuHandlerCreateNew = (menu: Menu, file: TFile) => { @@ -618,7 +622,7 @@ export default class ExcalidrawPlugin extends Plugin { ); } this.createAndOpenDrawing( - this.getNextDefaultFilename(), + getDrawingFilename(this.settings), false, folderpath, ); @@ -723,7 +727,7 @@ export default class ExcalidrawPlugin extends Plugin { id: "excalidraw-autocreate", name: t("NEW_IN_NEW_PANE"), callback: () => { - this.createAndOpenDrawing(this.getNextDefaultFilename(), true); + this.createAndOpenDrawing(getDrawingFilename(this.settings), true); }, }); @@ -731,7 +735,7 @@ export default class ExcalidrawPlugin extends Plugin { id: "excalidraw-autocreate-on-current", name: t("NEW_IN_ACTIVE_PANE"), callback: () => { - this.createAndOpenDrawing(this.getNextDefaultFilename(), false); + this.createAndOpenDrawing(getDrawingFilename(this.settings), false); }, }); @@ -740,16 +744,7 @@ export default class ExcalidrawPlugin extends Plugin { if (!activeView) { return; } - const prefix = this.settings.drawingEmbedPrefixWithFilename - ? `${activeView.file.basename}_` - : ""; - const date = window - .moment() - .format(this.settings.drawingFilenameDateTime); - const extension = this.settings.compatibilityMode - ? ".excalidraw" - : ".excalidraw.md"; - const filename = prefix + date + extension; + const filename = getEmbedFilename(activeView.file.basename, this.settings); const folder = this.settings.embedUseExcalidrawFolder ? null : ( @@ -826,6 +821,31 @@ export default class ExcalidrawPlugin extends Plugin { }, }); + this.addCommand({ + id: "fullscreen", + name: t("TOGGLE_FULLSCREEN"), + checkCallback: (checking: boolean) => { + if (checking) { + return ( + this.app.workspace.activeLeaf.view.getViewType() === + VIEW_TYPE_EXCALIDRAW + ); + } + const view = this.app.workspace.activeLeaf.view; + if (view instanceof ExcalidrawView) { + if (view.isFullscreen()) { + view.exitFullscreen(); + } else { + view.gotoFullscreen(); + } + return true; + } + return false; + }, + }); + + + /* this.addCommand({ id: "ocr", name: "Test OCR",//t("EXPORT_PNG"), @@ -1171,7 +1191,7 @@ export default class ExcalidrawPlugin extends Plugin { ): Promise { const data = await this.app.vault.read(file); const filename = - file.name.substr(0, file.name.lastIndexOf(".excalidraw")) + + file.name.substring(0, file.name.lastIndexOf(".excalidraw")) + (replaceExtension ? ".md" : ".excalidraw.md"); const fname = getNewUniqueFilepath( this.app.vault, @@ -1488,6 +1508,7 @@ export default class ExcalidrawPlugin extends Plugin { //@ts-ignore const scope = new Scope(self.app.scope); scope.register(["Mod"], "Enter", () => true); + //@ts-ignore self.app.keymap.pushScope(scope); self.popScope = () => { @@ -1614,6 +1635,7 @@ export default class ExcalidrawPlugin extends Plugin { public async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + setLeftHandedMode(this.settings.isLeftHanded); } async saveSettings() { @@ -1672,14 +1694,6 @@ export default class ExcalidrawPlugin extends Plugin { }); } - private getNextDefaultFilename(): string { - return ( - this.settings.drawingFilenamePrefix + - window.moment().format(this.settings.drawingFilenameDateTime) + - (this.settings.compatibilityMode ? ".excalidraw" : ".excalidraw.md") - ); - } - public async getBlankDrawing(): Promise { const template = this.app.metadataCache.getFirstLinkpathDest( normalizePath(this.settings.templateFilePath), diff --git a/src/settings.ts b/src/settings.ts index a1798f8..f29f9b6 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -11,6 +11,7 @@ import { VIEW_TYPE_EXCALIDRAW } from "./Constants"; import ExcalidrawView from "./ExcalidrawView"; import { t } from "./lang/helpers"; import type ExcalidrawPlugin from "./main"; +import { getDrawingFilename, getEmbedFilename, setLeftHandedMode } from "./Utils"; export interface ExcalidrawSettings { folder: string; @@ -22,10 +23,13 @@ export interface ExcalidrawSettings { autosaveInterval: number; drawingFilenamePrefix: string; drawingEmbedPrefixWithFilename: boolean; + drawingFilnameEmbedPostfix: string; drawingFilenameDateTime: string; + useExcalidrawExtension: boolean; displaySVGInPreview: boolean; previewMatchObsidianTheme: boolean; width: string; + isLeftHanded: boolean; matchTheme: boolean; matchThemeAlways: boolean; matchThemeTrigger: boolean; @@ -91,10 +95,13 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = { autosaveInterval: 15000, drawingFilenamePrefix: "Drawing ", drawingEmbedPrefixWithFilename: true, + drawingFilnameEmbedPostfix: " ", drawingFilenameDateTime: "YYYY-MM-DD HH.mm.ss", + useExcalidrawExtension: true, displaySVGInPreview: true, previewMatchObsidianTheme: false, width: "400", + isLeftHanded: false, matchTheme: false, matchThemeAlways: false, matchThemeTrigger: false, @@ -304,11 +311,12 @@ export class ExcalidrawSettingTab extends PluginSettingTab { }); const getFilenameSample = () => { - return `${ - t("FILENAME_SAMPLE") + - this.plugin.settings.drawingFilenamePrefix + - window.moment().format(this.plugin.settings.drawingFilenameDateTime) - }`; + return t("FILENAME_SAMPLE") + "" + + getDrawingFilename(this.plugin.settings) + + "

" + + t("FILENAME_EMBED_SAMPLE") + "" + + getEmbedFilename("{NOTE_NAME}",this.plugin.settings) + + ""; }; const filenameEl = containerEl.createEl("p", { text: "" }); @@ -340,10 +348,29 @@ export class ExcalidrawSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.drawingEmbedPrefixWithFilename) .onChange(async (value) => { this.plugin.settings.drawingEmbedPrefixWithFilename = value; + filenameEl.innerHTML = getFilenameSample(); this.applySettingsUpdate(); }), ); + new Setting(containerEl) + .setName(t("FILENAME_POSTFIX_NAME")) + .setDesc(fragWithHTML(t("FILENAME_POSTFIX_DESC"))) + .addText((text) => + text + .setPlaceholder("") + .setValue(this.plugin.settings.drawingFilnameEmbedPostfix) + .onChange(async (value) => { + this.plugin.settings.drawingFilnameEmbedPostfix = value.replaceAll( + /[<>:"/\\|?*]/g, + "_", + ); + text.setValue(this.plugin.settings.drawingFilnameEmbedPostfix); + filenameEl.innerHTML = getFilenameSample(); + this.applySettingsUpdate(); + }), + ); + new Setting(containerEl) .setName(t("FILENAME_DATE_NAME")) .setDesc(fragWithHTML(t("FILENAME_DATE_DESC"))) @@ -361,6 +388,19 @@ export class ExcalidrawSettingTab extends PluginSettingTab { this.applySettingsUpdate(); }), ); + + new Setting(containerEl) + .setName(t("FILENAME_EXCALIDRAW_EXTENSION_NAME")) + .setDesc(fragWithHTML(t("FILENAME_EXCALIDRAW_EXTENSION_DESC"))) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.useExcalidrawExtension) + .onChange(async (value) => { + this.plugin.settings.useExcalidrawExtension = value; + filenameEl.innerHTML = getFilenameSample(); + this.applySettingsUpdate(); + }), + ); let autosaveDropdown: DropdownComponent; @@ -407,6 +447,20 @@ export class ExcalidrawSettingTab extends PluginSettingTab { this.containerEl.createEl("h1", { text: t("DISPLAY_HEAD") }); + new Setting(containerEl) + .setName(t("LEFTHANDED_MODE_NAME")) + .setDesc(fragWithHTML(t("LEFTHANDED_MODE_DESC"))) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.isLeftHanded) + .onChange(async (value) => { + this.plugin.settings.isLeftHanded = value; + setLeftHandedMode(value); + this.applySettingsUpdate(); + }), + ); + + new Setting(containerEl) .setName(t("MATCH_THEME_NAME")) .setDesc(fragWithHTML(t("MATCH_THEME_DESC"))) @@ -1021,6 +1075,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.compatibilityMode) .onChange(async (value) => { this.plugin.settings.compatibilityMode = value; + filenameEl.innerHTML = getFilenameSample(); this.applySettingsUpdate(); }), ); diff --git a/versions.json b/versions.json index f389546..492168b 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { - "1.6.17": "0.12.16", + "1.6.18": "0.12.16", "1.4.2": "0.11.13" } diff --git a/yarn.lock b/yarn.lock index c942f35..0c73c2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2132,10 +2132,10 @@ "resolved" "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz" "version" "4.2.2" -"@zsviczian/excalidraw@0.11.0-obsidian-4": - "integrity" "sha512-LxSorHDxckqEP2GjUUHOLvqUfJHALJQfoXDYJ3JsjMJZ7a74omeUURTjysFPbsyhQW0J4w20iM2oh9srelN4UQ==" - "resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.11.0-obsidian-4.tgz" - "version" "0.11.0-obsidian-4" +"@zsviczian/excalidraw@0.11.0-obsidian-5": + "integrity" "sha512-Lc+/3hPZnAWkqu/utx74RlwjNoZEAQIBg/jJfk8h/x2AP1REpdcttb8WhBSFpWRr4L2ukwNv/GAI6qFF/K/cMg==" + "resolved" "https://registry.npmjs.org/@zsviczian/excalidraw/-/excalidraw-0.11.0-obsidian-5.tgz" + "version" "0.11.0-obsidian-5" dependencies: "dotenv" "10.0.0"