diff --git a/src/customIFrame.tsx b/src/customIFrame.tsx index 58333a4..b8fbb2c 100644 --- a/src/customIFrame.tsx +++ b/src/customIFrame.tsx @@ -147,13 +147,6 @@ function RenderObsidianView( containerRef.current.removeChild(containerRef.current.lastChild); } - if(isEditingRef.current) { - if(leafRef.current?.node) { - view.canvasNodeFactory.stopEditing(leafRef.current.node); - } - isEditingRef.current = false; - } - const doc = view.ownerDocument; const rootSplit:WorkspaceSplit = new (WorkspaceSplit as ConstructableWorkspaceSplit)(app.workspace, "vertical"); rootSplit.getRoot = () => app.workspace[doc === document ? 'rootSplit' : 'floatingSplit']; @@ -170,20 +163,39 @@ function RenderObsidianView( if(subpath && view.canvasNodeFactory.isInitialized()) { leafRef.current.node = view.canvasNodeFactory.createFileNote(file, subpath, containerRef.current, element.id); } else { - containerRef.current.appendChild(rootSplit.containerEl); - const workspaceLeaf:HTMLDivElement = rootSplit.containerEl.querySelector("div.workspace-leaf"); - if(workspaceLeaf) workspaceLeaf.style.borderRadius = `${radius}px`; (async () => { await leafRef.current.leaf.openFile(file, subpath ? { eState: { subpath }, state: {mode:"preview"} } : undefined); - if (leafRef.current.leaf.view?.getViewType() === "canvas") { + const viewType = leafRef.current.leaf.view?.getViewType(); + if(viewType === "canvas") { leafRef.current.leaf.view.canvas?.setReadonly(true); } + if ((viewType === "markdown") && view.canvasNodeFactory.isInitialized()) { + //I haven't found a better way of deciding if an .md file has its own view (e.g., kanban) or not + //This runs only when the file is added, thus should not be a major performance issue + await leafRef.current.leaf.setViewState({state: {file:null}}) + leafRef.current.node = view.canvasNodeFactory.createFileNote(file, subpath, containerRef.current, element.id); + console.log(`Reloaded element ${element.id} for ${file.path} with subpath of ${subpath}`); + } else { + const workspaceLeaf:HTMLDivElement = rootSplit.containerEl.querySelector("div.workspace-leaf"); + if(workspaceLeaf) workspaceLeaf.style.borderRadius = `${radius}px`; + containerRef.current.appendChild(rootSplit.containerEl); + } patchMobileView(view); })(); } + app.workspace.setActiveLeaf(view.leaf); return () => {}; //cleanup on unmount - }, [linkText, subpath, view, containerRef, app, radius, isEditingRef, leafRef]); + }, [linkText, subpath, view, containerRef, app, radius, leafRef]); + react.useEffect(() => { + if(isEditingRef.current) { + if(leafRef.current?.node) { + view.canvasNodeFactory.stopEditing(leafRef.current.node); + } + isEditingRef.current = false; + } + }, [isEditingRef.current, leafRef]); + //-------------------------------------------------------------------------------- //Switch to edit mode when markdown view is clicked @@ -208,9 +220,6 @@ function RenderObsidianView( return; } leafRef.current.leaf.view.setMode(modes['source']); - //@ts-ignore - window.al = leafRef.current.leaf; - app.workspace.setActiveLeaf(leafRef.current.leaf); isEditingRef.current = true; patchMobileView(view); } else if (leafRef.current?.node) { @@ -247,7 +256,6 @@ function RenderObsidianView( //@ts-ignore leafRef.current.leaf.view.setMode(modes["preview"]); isEditingRef.current = false; - app.workspace.setActiveLeaf(view.leaf); return; } } else if (leafRef.current?.node) { diff --git a/src/menu/IFrameActionsMenu.tsx b/src/menu/IFrameActionsMenu.tsx index 94945a7..6af85dd 100644 --- a/src/menu/IFrameActionsMenu.tsx +++ b/src/menu/IFrameActionsMenu.tsx @@ -3,7 +3,6 @@ import * as React from "react"; import ExcalidrawView from "../ExcalidrawView"; import { ExcalidrawIFrameElement } from "@zsviczian/excalidraw/types/element/types"; import { AppState, ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/types"; -import clsx from "clsx"; import { ActionButton } from "./ActionButton"; import { ICONS } from "./ActionIcons"; import { t } from "src/lang/helpers"; @@ -12,7 +11,7 @@ import { REG_BLOCK_REF_CLEAN, ROOTELEMENTSIZE, nanoid, sceneCoordsToViewportCoor import { ExcalidrawAutomate } from "src/ExcalidrawAutomate"; import { getEA } from "src"; import { REGEX_LINK, REG_LINKINDEX_HYPERLINK } from "src/ExcalidrawData"; -import { errorlog } from "src/utils/Utils"; +import { errorlog, rotatePoint } from "src/utils/Utils"; import { processLinkText, useDefaultExcalidrawFrame } from "src/utils/CustomIFrameUtils"; export class IFrameMenu { @@ -66,7 +65,6 @@ export class IFrameMenu { const { x, y } = sceneCoordsToViewportCoords( { sceneX: element.x, sceneY: element.y }, appState); const top = `${y-2.5*ROOTELEMENTSIZE-appState.offsetTop}px`; const left = `${x-appState.offsetLeft}px`; - const isDark = appState?.theme === "dark"; return (