PDF fixes, insert audio files, local graph view improvements

This commit is contained in:
zsviczian committed 2025-08-22 06:55:53 +02:00
1 parent 88e27a35ef
commit 89f2a3beb5
6 files changed
+58 -38

No files matched your search

+3
View File
@@ -21,3 +21,6 @@ yarn.lock
.DS_Store
.lock
.lock
# Obsidian files
Obsidian
+4
View File
@@ -19,7 +19,11 @@ I build this plugin in my free time, as a labor of love. Curious about the philo
`,
"2.15.1":`
## Fixed
- PDF improvements
- It was not possible to scroll the embedded PDF. [#9891](https://github.com/excalidraw/excalidraw/pull/9891)
- Embedded PDF pages were blurred (pixelated).
- Pasting an oversized image resulted in an error message and Excalidraw dumping the scene. [#2453](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/2453), [#9878](https://github.com/excalidraw/excalidraw/issues/9878)
- Insert Any File now supports adding Audio files.
## New
- New option in settings under "Zoom and Pan". Pan with right mouse button (Miro‑style): right‑click and drag to pan the canvas. Press 'm' for the context menu (disabled while editing text). 🙏 [@mfuria](https://github.com/mfuria) for making this happen! [#2450](https://github.com/zsviczian/obsidian-excalidraw-plugin/pull/2450), [#329](https://github.com/zsviczian/excalidraw/pull/329)
+5 -6
View File
@@ -1,7 +1,7 @@
import { NonDeletedExcalidrawElement } from "@zsviczian/excalidraw/types/element/src/types";
import { DEVICE, REG_LINKINDEX_INVALIDCHARS } from "src/constants/constants";
import { getParentOfClass } from "./obsidianUtils";
import { App, Notice, TFile, WorkspaceLeaf } from "obsidian";
import { App, TFile, WorkspaceLeaf } from "obsidian";
import { getLinkParts } from "./utils";
import ExcalidrawView from "src/view/ExcalidrawView";
@@ -58,15 +58,14 @@ export const generateEmbeddableLink = (src: string, theme: "light" | "dark"):str
}
export function setFileToLocalGraph(app: App, file: TFile) {
let lgv;
let lgv: any;
app.workspace.iterateAllLeaves((l) => {
if (l.view?.getViewType() === "localgraph") lgv = l.view;
});
if(!lgv) return;
try {
//@ts-ignore
const loadFile = lgv?.loadFile;
if (loadFile) {
loadFile(file);
if (lgv.loadFile && lgv.file !== file) {
lgv.loadFile(file);
}
} catch (e) {
console.error(e);
+35 -24
View File
@@ -1,4 +1,4 @@
import { NonDeletedExcalidrawElement } from "@zsviczian/excalidraw/types/element/src/types";
import { ExcalidrawEmbeddableElement, NonDeletedExcalidrawElement } from "@zsviczian/excalidraw/types/element/src/types";
import ExcalidrawView from "src/view/ExcalidrawView";
import { Notice, WorkspaceLeaf, WorkspaceSplit } from "obsidian";
import * as React from "react";
@@ -9,7 +9,7 @@ import { ObsidianCanvasNode } from "src/view/managers/CanvasNodeFactory";
import { processLinkText, patchMobileView, setFileToLocalGraph } from "src/utils/customEmbeddableUtils";
import { EmbeddableMDCustomProps } from "src/shared/Dialogs/EmbeddableSettings";
const CANVAS_VIEWTYPES = new Set(["markdown", "bases"]);
const CANVAS_VIEWTYPES = new Set(["markdown", "bases", "audio", "video"]);
declare module "obsidian" {
interface Workspace {
@@ -76,11 +76,11 @@ export function renderWebView (src: string, view: ExcalidrawView, id: string, _:
function RenderObsidianView(
{ mdProps, element, linkText, view, containerRef, activeEmbeddable, theme, canvasColor }:{
mdProps: EmbeddableMDCustomProps;
element: NonDeletedExcalidrawElement;
element: ExcalidrawEmbeddableElement;
linkText: string;
view: ExcalidrawView;
containerRef: React.RefObject<HTMLDivElement>;
activeEmbeddable: {element: NonDeletedExcalidrawElement; state: string};
activeEmbeddable: {element: ExcalidrawEmbeddableElement; state: string};
theme: string;
canvasColor: string;
}): JSX.Element {
@@ -166,6 +166,21 @@ function RenderObsidianView(
}
}, [isActiveRef.current]);
const setKeepOnTop = () => {
const keepontop = (view.app.workspace.activeLeaf === view.leaf) && DEVICE.isDesktop;
if (keepontop) {
//@ts-ignore
if(!view.ownerWindow.electronWindow.isAlwaysOnTop()) {
//@ts-ignore
view.ownerWindow.electronWindow.setAlwaysOnTop(true);
setTimeout(() => {
//@ts-ignore
view.ownerWindow.electronWindow.setAlwaysOnTop(false);
}, 500);
}
}
}
//--------------------------------------------------------------------------------
//Mount the workspace leaf or the canvas node depending on subpath
//--------------------------------------------------------------------------------
@@ -194,21 +209,6 @@ function RenderObsidianView(
editNode: null,
};
const setKeepOnTop = () => {
const keepontop = (view.app.workspace.activeLeaf === view.leaf) && DEVICE.isDesktop;
if (keepontop) {
//@ts-ignore
if(!view.ownerWindow.electronWindow.isAlwaysOnTop()) {
//@ts-ignore
view.ownerWindow.electronWindow.setAlwaysOnTop(true);
setTimeout(() => {
//@ts-ignore
view.ownerWindow.electronWindow.setAlwaysOnTop(false);
}, 500);
}
}
}
//if subpath is defined, create a canvas node else create a workspace leaf
if(subpath && view.canvasNodeFactory.isInitialized()) {
setKeepOnTop();
@@ -257,7 +257,7 @@ function RenderObsidianView(
//--------------------------------------------------------------------------------
//Set colors of the canvas node
//--------------------------------------------------------------------------------
function setColors (canvasNode: HTMLDivElement, element: NonDeletedExcalidrawElement, mdProps: EmbeddableMDCustomProps, canvasColor: string) {
function setColors (canvasNode: HTMLDivElement, element: ExcalidrawEmbeddableElement, mdProps: EmbeddableMDCustomProps, canvasColor: string) {
if(!mdProps) return;
if (!leafRef.current?.hasOwnProperty("node")) return;
@@ -378,6 +378,11 @@ function RenderObsidianView(
event?.stopPropagation();
}
if(isActiveRef.current && leafRef.current?.leaf) {
setKeepOnTop();
view.app.workspace.setActiveLeaf(leafRef.current.leaf, { focus: true });
}
if (isActiveRef.current && !isEditingRef.current && leafRef.current?.leaf) {
if(leafRef.current.leaf.view?.getViewType() === "markdown") {
const api:ExcalidrawImperativeAPI = view.excalidrawAPI;
@@ -402,13 +407,13 @@ function RenderObsidianView(
view.canvasNodeFactory.startEditing(leafRef.current.node, newTheme);
}
}
}, [leafRef.current?.leaf, element.id, view, themeRef.current]);
}, [leafRef.current?.leaf, element.id, view, themeRef.current, isActiveRef.current, isEditingRef.current]);
if(leafRef.current) leafRef.current.editNode = handleClick;
// Event listener for key press
React.useEffect(() => {
const handleKeyPress = (event: KeyboardEvent) => {
if (event.key === "Enter") {
if (event.key === "Enter" && !isActiveRef.current) {
handleClick(event); // Call handleClick function when Enter key is pressed
}
};
@@ -418,7 +423,7 @@ function RenderObsidianView(
return () => {
document.removeEventListener("keydown", handleKeyPress); // Remove event listener when component unmounts
};
}, [handleClick]);
}, [handleClick, isActiveRef.current]);
//--------------------------------------------------------------------------------
// Set isActiveRef and switch to preview mode when the iframe is not active
@@ -436,6 +441,11 @@ function RenderObsidianView(
return;
}
if(leafRef.current?.leaf) {
setKeepOnTop();
view.app.workspace.setActiveLeaf(leafRef.current.leaf, { focus: true });
}
if(file !== view.file) {
setFileToLocalGraph(view.app, file);
}
@@ -468,6 +478,7 @@ function RenderObsidianView(
}, [
containerRef,
leafRef,
activeEmbeddable?.state,
isActiveRef,
activeEmbeddable?.element,
activeEmbeddable?.state,
@@ -482,7 +493,7 @@ function RenderObsidianView(
};
export const CustomEmbeddable: React.FC<{element: NonDeletedExcalidrawElement; view: ExcalidrawView; appState: UIAppState; linkText: string}> = ({ element, view, appState, linkText }) => {
export const CustomEmbeddable: React.FC<{element: ExcalidrawEmbeddableElement; view: ExcalidrawView; appState: UIAppState; linkText: string}> = ({ element, view, appState, linkText }) => {
const React = view.packages.react;
const containerRef: React.RefObject<HTMLDivElement> = React.useRef(null);
const theme = getTheme(view, appState.theme);
+6 -8
View File
@@ -34,6 +34,7 @@ export interface ObsidianCanvasNode {
isEditing: boolean;
file: TFile;
detach: Function;
isEditable: Function;
}
export class CanvasNodeFactory {
@@ -112,12 +113,11 @@ export class CanvasNodeFactory {
}
public async startEditing(node: ObsidianCanvasNode, theme: string) {
if (!this.initialized || !node) return;
if (!this.initialized || !node || !node.isEditable()) return;
try {
//if (node.file === this.view.file) {
await this.view.setEmbeddableNodeIsEditing();
//}
await this.view.setEmbeddableNodeIsEditing();
node.startEditing();
node.isEditing = true;
@@ -138,12 +138,10 @@ export class CanvasNodeFactory {
}
public stopEditing(node: ObsidianCanvasNode) {
if (!this.initialized || !node || !node.isEditing) return;
if (!this.initialized || !node || !node.isEditing || !node.isEditable()) return;
try {
//if (node.file === this.view.file) {
this.view.clearEmbeddableNodeIsEditing();
//}
this.view.clearEmbeddableNodeIsEditing();
node.child.showPreview();
node.isEditing = false;
this.observer?.disconnect();
+5
View File
@@ -857,3 +857,8 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
fill: none;
pointer-events: none;
}
/*remove blur from PDF embed*/
.excalidraw__embeddable-container canvas {
image-rendering: auto;
}