Replies: 1 comment
-
Obsidian 0.15.3 update to support dragging and dropping workspace panes between windows.
obsidian-excalidraw-plugin/src/ExcalidrawView.ts Lines 890 to 897 in 08e4e1f |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Obsidian 0.15.0 introduced Popout Windows (Popouts). The challenge with Popouts is that the plugin is executed in the context of the main workspace's document/window, but the Excalidraw React app including the Canvas and all the Event Listeners must run in the context of the Popouts' document/window context. This means Excalidraw and React must be individually deployed to all popout windows.
I found two ways for solving this problem:
Rejected Option: Modify the Excalidraw package
Solution summary: Pass the host document/window object as a component property (ownerDocument/ownerWindow) when initializing Excalidraw. Modify all references to document/window in the Excalidraw code to reference the ownerDocument/ownerWindow object.
Considerations: The drawback of this solution is a divergence from the main Excalidraw package, thus making deployment of future Excalidraw improvements more difficult.
I implemented this change to the Excalidraw package in this commit/branch. The change turned out to be less invasive than I thought it would be, however, while using the solution I ran into some hidden problems. I solved the ones I found, but there might be a number of others still. I released a version of the plugin based on this approach for beta testing as Excalidraw 1.7.0
Final verdict: This is not a sustainable approach because of the hidden issue, but more so because of the ongoing burden of maintaining a highly customized codebase.
Current Solution: Load React and the Excalidraw packages separately to each window
Solution summary:
ownerWindow
andownerDocument
duringonload()
getPackage(win:Window):Packages
) in the plugin.Store
ownerWindow
andownerDocument
onview.onload
obsidian-excalidraw-plugin/src/ExcalidrawView.ts
Lines 890 to 895 in 108293a
Re-write references
I introduced constants for the referenced objects to minimize impact to code readability
getPackage()
Package loaderIn
main.ts
:obsidian-excalidraw-plugin/src/main.ts
Lines 172 to 188 in 108293a
Modified build process
In rollup.config.js:
window.eval.call(window, <<Script String>>)
I execute the following code:const EXCALIDRAW_PACKAGES
with the base 64 string, andgetPackages()
because I have references to React in my plugin, unless I initialized React right at the beginning of my plugin load process, the plugin did not load due to missing React dependencies. For Popouts I initialize React usinggetPackages()
inmain.ts
.rollup-plugin-postprocess
I replacevar React = require('react');
with the code I stiched together.Beta Was this translation helpful? Give feedback.
All reactions