mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
before updating renderWebview
This commit is contained in:
@@ -651,7 +651,8 @@ export default class ExcalidrawView extends TextFileView {
|
||||
}
|
||||
|
||||
// !triggerReload means file has not changed. No need to re-export
|
||||
if (!triggerReload && !this.semaphores.autosaving && !this.semaphores.viewunload) {
|
||||
//https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1209 (added popout unload to the condition)
|
||||
if (!triggerReload && !this.semaphores.autosaving && (!this.semaphores.viewunload || this.semaphores.popoutUnload)) {
|
||||
const autoexportPreference = this.excalidrawData.autoexportPreference;
|
||||
if (
|
||||
(autoexportPreference === AutoexportPreference.inherit && this.plugin.settings.autoexportSVG) ||
|
||||
@@ -1698,10 +1699,23 @@ export default class ExcalidrawView extends TextFileView {
|
||||
const leaf = this.leaf;
|
||||
(async () => {
|
||||
let confirmation:boolean = true;
|
||||
let counter = 0;
|
||||
const timestamp = Date.now();
|
||||
while (!imageCache.isReady() && confirmation) {
|
||||
const message = `You've been now wating for <b>${Math.round((Date.now()-timestamp)/1000)}</b> seconds. `
|
||||
imageCache.initializationNotice = true;
|
||||
const confirmationPrompt = new ConfirmationPrompt(plugin,t("CACHE_NOT_READY"));
|
||||
const confirmationPrompt = new ConfirmationPrompt(plugin,
|
||||
`${counter>0
|
||||
? counter%4 === 0
|
||||
? message + "The CACHE is still loading.<br><br>"
|
||||
: counter%4 === 1
|
||||
? message + "Watch the top rigth corner for the notification.<br><br>"
|
||||
: counter%4 === 2
|
||||
? message + "I really, really hope the backup will work for you! <br><br>"
|
||||
: message + "I am sorry, it is taking a while, there is not much I can do... <br><br>"
|
||||
: ""}${t("CACHE_NOT_READY")}`);
|
||||
confirmation = await confirmationPrompt.waitForClose
|
||||
counter++;
|
||||
}
|
||||
|
||||
const drawingBAK = await imageCache.getBAKFromCache(file.path);
|
||||
@@ -3807,10 +3821,20 @@ export default class ExcalidrawView extends TextFileView {
|
||||
appState: UIAppState,
|
||||
) => {
|
||||
try {
|
||||
if(!this.file || !element || !element.link || element.link.length === 0 || useDefaultExcalidrawFrame(element)) {
|
||||
const useExcalidrawFrame = useDefaultExcalidrawFrame(element);
|
||||
|
||||
if(!this.file || !element || !element.link || element.link.length === 0 || useExcalidrawFrame) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if(element.link.match(REG_LINKINDEX_HYPERLINK)) {
|
||||
if(!useExcalidrawFrame) {
|
||||
return renderWebView(element.link, radius, this, element.id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const res = REGEX_LINK.getRes(element.link).next();
|
||||
if(!res || (!res.value && res.done)) {
|
||||
return null;
|
||||
@@ -3819,7 +3843,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
let linkText = REGEX_LINK.getLink(res);
|
||||
|
||||
if(linkText.match(REG_LINKINDEX_HYPERLINK)) {
|
||||
if(DEVICE.isDesktop) {
|
||||
if(!useExcalidrawFrame) {
|
||||
return renderWebView(linkText, radius, this, element.id);
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -16,6 +16,7 @@ export const {
|
||||
getBoundTextMaxWidth,
|
||||
exportToSvg,
|
||||
exportToBlob,
|
||||
mutateElement,
|
||||
//@ts-ignore
|
||||
} = excalidrawLib;
|
||||
|
||||
|
||||
@@ -161,6 +161,18 @@ function RenderObsidianView(
|
||||
|
||||
//if subpath is defined, create a canvas node else create a workspace leaf
|
||||
if(subpath && view.canvasNodeFactory.isInitialized()) {
|
||||
const keepontop = (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);
|
||||
}, 150);
|
||||
}
|
||||
}
|
||||
leafRef.current.node = view.canvasNodeFactory.createFileNote(file, subpath, containerRef.current, element.id);
|
||||
} else {
|
||||
(async () => {
|
||||
@@ -174,18 +186,17 @@ function RenderObsidianView(
|
||||
//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);
|
||||
patchMobileView(view);
|
||||
})();
|
||||
}
|
||||
app.workspace.setActiveLeaf(view.leaf);
|
||||
|
||||
return () => {}; //cleanup on unmount
|
||||
}, [linkText, subpath, view, containerRef, app, radius, leafRef]);
|
||||
}, [linkText, subpath, containerRef, radius]);
|
||||
|
||||
react.useEffect(() => {
|
||||
if(isEditingRef.current) {
|
||||
@@ -227,7 +238,7 @@ function RenderObsidianView(
|
||||
view.canvasNodeFactory.startEditing(leafRef.current.node, theme);
|
||||
}
|
||||
}
|
||||
}, [leafRef.current?.leaf, element]);
|
||||
}, [leafRef.current?.leaf, element.id]);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Set isActiveRef and switch to preview mode when the iframe is not active
|
||||
@@ -262,7 +273,21 @@ function RenderObsidianView(
|
||||
//Handle canvas node
|
||||
view.canvasNodeFactory.stopEditing(leafRef.current.node);
|
||||
}
|
||||
}, [containerRef, leafRef, isActiveRef, appState, element, view, linkText, subpath, file, theme, isEditingRef, view.canvasNodeFactory]);
|
||||
}, [
|
||||
containerRef,
|
||||
leafRef,
|
||||
isActiveRef,
|
||||
appState.activeIFrame?.element,
|
||||
appState.activeIFrame?.state,
|
||||
element,
|
||||
view,
|
||||
linkText,
|
||||
subpath,
|
||||
file,
|
||||
theme,
|
||||
isEditingRef,
|
||||
view.canvasNodeFactory
|
||||
]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -92,15 +92,10 @@ export default {
|
||||
COMPATIBILITY_MODE:
|
||||
"*.excalidraw file opened in compatibility mode. Convert to new format for full plugin functionality.",
|
||||
CONVERT_FILE: "Convert to new format",
|
||||
BACKUP_AVAILABLE: "There was an error loading your drawing. This could be because Obsidian terminated unexpectedly during a save operation (e.g. you 'swiped' Obsidian away on your mobile device in an unlucky moment). " +
|
||||
"<br><br><b>GOOD NEWS</b>: There is a local backup available. Note however, if the last time you modified this drawing you were using Obsidian on different device (i.e. now you are on your desktop and you modified it on your tablet), that other device will likely have a more recent backup available. " +
|
||||
"Try opening the drawing on your other device first, and restoring the backup from that local backup. " +
|
||||
"<br><br>Would you like to load the backup?",
|
||||
BACKUP_AVAILABLE: "We encountered an error while loading your drawing. This might have occurred if Obsidian unexpectedly closed during a save operation. For example, if you accidentally closed Obsidian on your mobile device while saving.<br><br><b>GOOD NEWS:</b> Fortunately, a local backup is available. However, please note that if you last modified this drawing on a different device (e.g., tablet) and you are now on your desktop, that other device likely has a more recent backup.<br><br>I recommend trying to open the drawing on your other device first and restore the backup from its local storage.<br><br>Would you like to load the backup?",
|
||||
BACKUP_RESTORED: "Backup restored",
|
||||
CACHE_NOT_READY: "I am sorry, but there was an error loading your file. The plugin has a backup cache, but it looks like as if you've just started Obsidian. Initialization of the Backup Cache " +
|
||||
"can take up to a minute (or more depending on your device). You will be notified when the cache initialization is completed." +
|
||||
"<br><br>Press OK to try again, or Cancel to manually correct your file or to come back later.",
|
||||
OBSIDIAN_TOOLS_PANEL: "Obsidian Tools Panel",
|
||||
CACHE_NOT_READY: "I apologize for the inconvenience, but an error occurred while loading your file.<br><br><mark>Having a little patience can save you a lot of time...</mark><br><br>The plugin has a backup cache, but it appears that you have just started Obsidian. Initializing the Backup Cache may take some time, usually up to a minute or more depending on your device's performance. You will receive a notification in the top right corner when the cache initialization is complete.<br><br>Please press OK to attempt loading the file again and check if the cache has finished initializing. If you see a completely empty file behind this message, I recommend waiting until the backup cache is ready before proceeding. Alternatively, you can choose Cancel to manually correct your file.<br>",
|
||||
OBSIDIAN_TOOLS_PANEL: "Obsidian Tools Panel",
|
||||
|
||||
//settings.ts
|
||||
RELEASE_NOTES_NAME: "Display Release Notes after update",
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ActionButton } from "./ActionButton";
|
||||
import { ICONS } from "./ActionIcons";
|
||||
import { t } from "src/lang/helpers";
|
||||
import { ScriptEngine } from "src/Scripts";
|
||||
import { REG_BLOCK_REF_CLEAN, ROOTELEMENTSIZE, nanoid, sceneCoordsToViewportCoords } from "src/Constants";
|
||||
import { REG_BLOCK_REF_CLEAN, ROOTELEMENTSIZE, mutateElement, nanoid, sceneCoordsToViewportCoords } from "src/Constants";
|
||||
import { ExcalidrawAutomate } from "src/ExcalidrawAutomate";
|
||||
import { getEA } from "src";
|
||||
import { REGEX_LINK, REG_LINKINDEX_HYPERLINK } from "src/ExcalidrawData";
|
||||
import { errorlog, rotatePoint } from "src/utils/Utils";
|
||||
import { processLinkText, useDefaultExcalidrawFrame } from "src/utils/CustomIFrameUtils";
|
||||
|
||||
export class IFrameMenu {
|
||||
@@ -30,21 +29,47 @@ export class IFrameMenu {
|
||||
view.file.path,
|
||||
file.extension === "md",
|
||||
)
|
||||
const ea:ExcalidrawAutomate = getEA(this.view);
|
||||
ea.copyViewElementsToEAforEditing([element]);
|
||||
(ea.getElement(element.id) as any).link = `[[${path}${subpath}]]`;
|
||||
const link = `[[${path}${subpath}]]`;
|
||||
mutateElement (element,{link});
|
||||
view.excalidrawData.elementLinks.set(element.id, link);
|
||||
view.setDirty(99);
|
||||
view.updateScene({appState: {activeIFrame: null}});
|
||||
ea.addElementsToView(false,true);
|
||||
}
|
||||
|
||||
private menuFadeTimeout: number = 0;
|
||||
private menuElementId: string = null;
|
||||
private handleMouseEnter () {
|
||||
clearTimeout(this.menuFadeTimeout);
|
||||
this.containerRef.current?.style.setProperty("opacity", "1");
|
||||
};
|
||||
|
||||
private handleMouseLeave () {
|
||||
const self = this;
|
||||
this.menuFadeTimeout = window.setTimeout(() => {
|
||||
self.containerRef.current?.style.setProperty("opacity", "0.2");
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
|
||||
renderButtons(appState: AppState) {
|
||||
const view = this.view;
|
||||
const api = view?.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
if(!api) return null;
|
||||
if(!appState.activeIFrame || appState.activeIFrame.state !== "active") return null;
|
||||
if(!appState.activeIFrame || appState.activeIFrame.state !== "active" || appState.viewModeEnabled) {
|
||||
this.menuElementId = null;
|
||||
if(this.menuFadeTimeout) {
|
||||
clearTimeout(this.menuFadeTimeout);
|
||||
this.menuFadeTimeout = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const element = appState.activeIFrame?.element as ExcalidrawIFrameElement;
|
||||
if(this.menuElementId !== element.id) {
|
||||
this.menuElementId = element.id;
|
||||
this.handleMouseLeave();
|
||||
}
|
||||
let link = element.link;
|
||||
if(!link) return null;
|
||||
|
||||
const isExcalidrawiFrame = useDefaultExcalidrawFrame(element);
|
||||
let isObsidianiFrame = element.link?.match(REG_LINKINDEX_HYPERLINK);
|
||||
@@ -72,7 +97,11 @@ export class IFrameMenu {
|
||||
style={{
|
||||
top,
|
||||
left,
|
||||
opacity: 1,
|
||||
}}
|
||||
onMouseEnter={()=>this.handleMouseEnter()}
|
||||
onPointerDown={()=>this.handleMouseEnter()}
|
||||
onMouseLeave={()=>this.handleMouseLeave()}
|
||||
>
|
||||
<div
|
||||
className="Island"
|
||||
@@ -173,7 +202,11 @@ export class IFrameMenu {
|
||||
style={{
|
||||
top,
|
||||
left,
|
||||
opacity: 1,
|
||||
}}
|
||||
onMouseEnter={()=>this.handleMouseEnter()}
|
||||
onPointerDown={()=>this.handleMouseEnter()}
|
||||
onMouseLeave={()=>this.handleMouseLeave()}
|
||||
>
|
||||
<div
|
||||
className="Island"
|
||||
|
||||
Reference in New Issue
Block a user