diff --git a/manifest.json b/manifest.json index a312d50..37cbdf8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.9.8", + "version": "1.9.9", "minAppVersion": "1.1.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/package.json b/package.json index 5a62c64..7209e2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-excalidraw-plugin", - "version": "1.9.9", + "version": "1.9.9-2", "description": "This is an Obsidian.md plugin that lets you view and edit Excalidraw drawings", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 27d011f..ddc94aa 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -45,7 +45,7 @@ import { scaleLoadedImage, wrapTextAtCharLength, } from "src/utils/Utils"; -import { getAttachmentsFolderAndFilePath, getNewOrAdjacentLeaf, isObsidianThemeDark } from "src/utils/ObsidianUtils"; +import { getAttachmentsFolderAndFilePath, getLeaf, getNewOrAdjacentLeaf, isObsidianThemeDark } from "src/utils/ObsidianUtils"; import { AppState, BinaryFileData, ExcalidrawImperativeAPI, Point } from "@zsviczian/excalidraw/types/types"; import { EmbeddedFile, EmbeddedFilesLoader, FileData } from "src/EmbeddedFileLoader"; import { tex2dataURL } from "src/LaTeX"; @@ -152,6 +152,20 @@ export class ExcalidrawAutomate { return await newFilePrompt.waitForClose; } + /** + * Generates a new Obsidian Leaf following Excalidraw plugin settings such as open in Main Workspace or not, open in adjacent pane if avaialble, etc. + * @param origo // the currently active leaf, the origin of the new leaf + * @param targetPane //type PaneTarget = "active-pane"|"new-pane"|"popout-window"|"new-tab"|"md-properties"; + * @returns + */ + public getLeaf ( + origo: WorkspaceLeaf, + targetPane?: PaneTarget, + ): WorkspaceLeaf { + const modifierKeys = emulateKeysForLinkClick(targetPane??"new-tab"); + return getLeaf(this.plugin,origo,modifierKeys); + } + plugin: ExcalidrawPlugin; elementsDict: {[key:string]:any}; //contains the ExcalidrawElements currently edited in Automate indexed by el.id imagesDict: {[key: FileId]: any}; //the images files including DataURL, indexed by fileId diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 9fd7481..be3342e 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -116,7 +116,7 @@ import { getTextElementAtPointer, getImageElementAtPointer, getElementWithLinkAt import { ICONS, saveIcon } from "./menu/ActionIcons"; import { ExportDialog } from "./dialogs/ExportDialog"; import { getEA } from "src"; -import { emulateCTRLClickForLinks, externalDragModifierType, internalDragModifierType, isALT, isCTRL, isMETA, isSHIFT, linkClickModifierType, mdPropModifier, ModifierKeys } from "./utils/ModifierkeyHelper"; +import { anyModifierKeysPressed, emulateCTRLClickForLinks, emulateKeysForLinkClick, externalDragModifierType, internalDragModifierType, isALT, isCTRL, isMETA, isSHIFT, linkClickModifierType, mdPropModifier, ModifierKeys } from "./utils/ModifierkeyHelper"; import { setDynamicStyle } from "./utils/DynamicStyling"; import { InsertPDFModal } from "./dialogs/InsertPDFModal"; import { CustomEmbeddable, renderWebView } from "./customEmbeddable"; @@ -1043,9 +1043,8 @@ export default class ExcalidrawView extends TextFileView { new NewFileActions(this.plugin, linkText, keys, this).open(); return; } - if(this.linksAlwaysOpenInANewPane) { - keys.ctrlKey = true; - keys.altKey = true; + if(this.linksAlwaysOpenInANewPane && !anyModifierKeysPressed(keys)) { + keys = emulateKeysForLinkClick("new-pane"); } const leaf = getLeaf(this.plugin,this.leaf,keys); diff --git a/src/customEmbeddable.tsx b/src/customEmbeddable.tsx index 94a4728..5c7ce98 100644 --- a/src/customEmbeddable.tsx +++ b/src/customEmbeddable.tsx @@ -176,7 +176,7 @@ function RenderObsidianView( setTimeout(() => { //@ts-ignore view.ownerWindow.electronWindow.setAlwaysOnTop(false); - }, 150); + }, 500); } } leafRef.current.node = view.canvasNodeFactory.createFileNote(file, subpath, containerRef.current, element.id); diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index 72a8bb8..094b4f3 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -28,40 +28,65 @@ This will avoid any issues with converted files and let you enjoy the new featur Thank you for your understanding. If you have any questions, feel free to reach out. +--- + ## Fixed: - PNG image caching resulting in broken images after Obsidian restarts - SVG export now displays embedded iframes with the correct embed link (note this feature only works when you open the SVGs in a browser outside Obsidian). -## Updated / fixed / new in Excalidraw Automate -- I updated the [ExcalidrawAutomateInterface](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/src/types.d.ts) type definition -- Added new ExcalidrawAutomate function: ${String.fromCharCode(96)} addEmbeddable(topX: number, topY: number, width: number, height: number, url?: string, file?: TFile): string;${String.fromCharCode(96)} +## Updated / fixed in Excalidraw Automate +- I updated ${String.fromCharCode(96)}lib/ExcalidrawAutomate.d.ts${String.fromCharCode(96)} and published a new version of obsidian-excalidraw-plugin type library to npmjs. +- Added new ExcalidrawAutomate functions: ${String.fromCharCode(96)} addEmbeddable()${String.fromCharCode(96)}, ${String.fromCharCode(96)}DEVICE${String.fromCharCode(96)}, ${String.fromCharCode(96)}newFilePrompt()${String.fromCharCode(96)}, and ${String.fromCharCode(96)}getLeaf()${String.fromCharCode(96)} - ${String.fromCharCode(96)}addImage${String.fromCharCode(96)} and ${String.fromCharCode(96)}addElementsToView${String.fromCharCode(96)} were extended with 1-1 additional optional parameter. As a result of ${String.fromCharCode(96)}shouldRestoreElements${String.fromCharCode(96)} defaulting to false, all elements in the scene will no longer be updated (iframes will not blink) when you add elements via script. -- There is a new event hook: onPasteHook. This will be called whenever the user pastes something to the canvas. You can use this callback in case you want to do something additional when the onPaste event occurs. In case you want to prevent the Excalidraw default onPaste action you must return false +- There is a new event hook: ${String.fromCharCode(96)}onPasteHook${String.fromCharCode(96)}. This will be called whenever the user pastes something to the canvas. You can use this callback if you want to do something additional during the onPaste event. In case you want to prevent the Excalidraw default onPaste action you must return false ${String.fromCharCode(96,96,96)}typescript async addImage( topX: number, topY: number, imageFile: TFile | string, - scale: boolean = true, //default is true which will scale the image to MAX_IMAGE_SIZE, false will insert image at 100% of its size - anchor: boolean = true, //only has an effect if "scale" is false. If "anchor" is true the image path will include |100%, if false the image will be inserted at 100%, but if resized by the user it won't pop back to 100% the next time Excalidraw is opened. + scale: boolean = true, + anchor: boolean = true, ): Promise; async addElementsToView( repositionToCursor: boolean = false, save: boolean = true, newElementsOnTop: boolean = false, - shouldRestoreElements: boolean = false, //restore elements - auto-corrects broken, incomplete or old elements included in the update + shouldRestoreElements: boolean = false, ): Promise; onPasteHook: (data: { ea: ExcalidrawAutomate; payload: ClipboardData; event: ClipboardEvent; - excalidrawFile: TFile; //the file receiving the paste event - view: ExcalidrawView; //the excalidraw view receiving the paste - pointerPosition: { x: number; y: number }; //the pointer position on canvas + excalidrawFile: TFile; + view: ExcalidrawView; + pointerPosition: { x: number; y: number }; }) => boolean = null; + +addEmbeddable( + topX: number, + topY: number, + width: number, + height: number, + url?: string, + file?: TFile +): string; + +get DEVICE(): DeviceType; + +newFilePrompt( + newFileNameOrPath: string, + shouldOpenNewFile: boolean, + targetPane?: PaneTarget, + parentFile?: TFile +): Promise; + +getLeaf( + origo: WorkspaceLeaf, + targetPane?: PaneTarget +): WorkspaceLeaf; ${String.fromCharCode(96,96,96)} `, "1.9.8":` diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 765dfac..59aa30c 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -374,7 +374,7 @@ FILENAME_HEAD: "Filename", "or a PNG or an SVG copy. You need to enable auto-export PNG / SVG (see below under Export Settings) for those image types to be available in the dropdown. For drawings that do not have a " + "a corresponding PNG or SVG readily available the command palette action will insert a broken link. You need to open the original drawing and initiate export manually. " + "This option will not autogenerate PNG/SVG files, but will simply reference the already existing files.", - EMBED_WIKILINK_NAME: "Embed SVG or PNG as Wiki link", + EMBED_WIKILINK_NAME: "Embed Drawing using Wiki link", EMBED_WIKILINK_DESC: "Toggle ON: Excalidraw will embed a [[wiki link]]. Toggle OFF: Excalidraw will embed a [markdown](link).", EXPORT_PNG_SCALE_NAME: "PNG export image scale", diff --git a/src/lang/locale/hu.ts b/src/lang/locale/hu.ts new file mode 100644 index 0000000..26d6653 --- /dev/null +++ b/src/lang/locale/hu.ts @@ -0,0 +1,3 @@ +// Magyar + +export default {}; diff --git a/src/types.d.ts b/src/types.d.ts index 3770c47..2f9b056 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,15 +1,4 @@ -import { ExcalidrawBindableElement, ExcalidrawElement, ExcalidrawImageElement, FileId, FillStyle, NonDeletedExcalidrawElement, RoundnessType, StrokeRoundness, StrokeStyle } from "@zsviczian/excalidraw/types/element/types"; -import { AppState, BinaryFileData, ExcalidrawImperativeAPI, Point } from "@zsviczian/excalidraw/types/types"; -import { TFile, WorkspaceLeaf } from "obsidian"; -import { EmbeddedFilesLoader } from "./EmbeddedFileLoader"; import { ExcalidrawAutomate } from "./ExcalidrawAutomate"; -import ExcalidrawView, { ExportSettings } from "./ExcalidrawView"; -import ExcalidrawPlugin from "./main"; -import { ColorMaster } from "colormaster"; -import { TInput } from "colormaster/types"; -import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard"; -import { PaneTarget } from "./utils/ModifierkeyHelper"; - export type ConnectionPoint = "top" | "bottom" | "left" | "right" | null; @@ -33,4 +22,10 @@ export type DeviceType = { isWindows: boolean, isIOS: boolean, isAndroid: boolean -}; \ No newline at end of file +}; + +declare global { + interface Window { + ExcalidrawAutomate: ExcalidrawAutomate; + } +} \ No newline at end of file diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 3037b87..b5e4c7d 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -127,7 +127,7 @@ export function getEmbedFilename( : settings.useExcalidrawExtension ? ".excalidraw.md" : ".md") - ); + ).trim(); } /** diff --git a/src/utils/ModifierkeyHelper.ts b/src/utils/ModifierkeyHelper.ts index 805a01e..40fa328 100644 --- a/src/utils/ModifierkeyHelper.ts +++ b/src/utils/ModifierkeyHelper.ts @@ -108,4 +108,8 @@ export const emulateKeysForLinkClick = (action: PaneTarget): ModifierKeys => { break; } return ev; +} + +export const anyModifierKeysPressed = (e: ModifierKeys): boolean => { + return e.shiftKey || e.ctrlKey || e.metaKey || e.altKey; } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c68891b..244331d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,7 @@ }, "include": [ "**/*.ts", - "**/*.tsx", "src/Dialogs/OpenDrawing.ts" + "**/*.tsx", "src/Dialogs/OpenDrawing.ts", + "src/types.d.ts" ] } \ No newline at end of file diff --git a/tsconfig.prod.json b/tsconfig.prod.json index e27b838..653fe9e 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -19,6 +19,7 @@ }, "include": [ "**/*.ts", - "**/*.tsx", "src/Dialogs/OpenDrawing.ts" + "**/*.tsx", "src/Dialogs/OpenDrawing.ts", + "src/types.d.ts" ] } \ No newline at end of file