mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Merge branch 'master' of https://github.com/zsviczian/obsidian-excalidraw-plugin
This commit is contained in:
@@ -10,11 +10,13 @@ If there are frames, the script will use the frames for the presentation. Frames
|
||||
|
||||
```javascript
|
||||
*/
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.8.17")) {
|
||||
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.23")) {
|
||||
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
|
||||
return;
|
||||
}
|
||||
|
||||
const hostLeaf = ea.targetView.leaf;
|
||||
const hostView = hostLeaf.view;
|
||||
const statusBarElement = document.querySelector("div.status-bar");
|
||||
const ctrlKey = ea.targetView.modifierKeyDown.ctrlKey || ea.targetView.modifierKeyDown.metaKey;
|
||||
const altKey = ea.targetView.modifierKeyDown.altKey || ctrlKey;
|
||||
@@ -36,10 +38,13 @@ const SVG_LEFT_ARROW = ea.obsidian.getIcon("lucide-arrow-left").outerHTML;
|
||||
const SVG_EDIT = ea.obsidian.getIcon("lucide-pencil").outerHTML;
|
||||
const SVG_MAXIMIZE = ea.obsidian.getIcon("lucide-maximize").outerHTML;
|
||||
const SVG_MINIMIZE = ea.obsidian.getIcon("lucide-minimize").outerHTML;
|
||||
const SVG_LASER_ON = ea.obsidian.getIcon("lucide-hand").outerHTML;
|
||||
const SVG_LASER_OFF = ea.obsidian.getIcon("lucide-wand").outerHTML;
|
||||
|
||||
//-------------------------------
|
||||
//utility & convenience functions
|
||||
//-------------------------------
|
||||
let isLaserOn = false;
|
||||
let slide = 0;
|
||||
let isFullscreen = false;
|
||||
const ownerDocument = ea.targetView.ownerDocument;
|
||||
@@ -310,6 +315,9 @@ const scrollToNextRect = async ({left,top,right,bottom,nextZoom},steps = TRANSIT
|
||||
}
|
||||
}
|
||||
excalidrawAPI.updateScene({appState:{shouldCacheIgnoreZoom:false}});
|
||||
if(isLaserOn) {
|
||||
excalidrawAPI.setActiveTool({type: "laser"});
|
||||
}
|
||||
busy = false;
|
||||
}
|
||||
|
||||
@@ -450,6 +458,22 @@ const createPresentationNavigationPanel = () => {
|
||||
margin: 0px auto;`
|
||||
}
|
||||
});
|
||||
|
||||
el.createEl("button",{
|
||||
attr: {
|
||||
title: "Toggle Laser Pointer and Panning Mode"
|
||||
}
|
||||
}, button => {
|
||||
button.innerHTML = isLaserOn ? SVG_LASER_ON : SVG_LASER_OFF;
|
||||
button.onclick = () => {
|
||||
isLaserOn = !isLaserOn;
|
||||
excalidrawAPI.setActiveTool({
|
||||
type: isLaserOn ? "laser" : "selection"
|
||||
})
|
||||
button.innerHTML = isLaserOn ? SVG_LASER_ON : SVG_LASER_OFF;
|
||||
}
|
||||
});
|
||||
|
||||
el.createEl("button",{
|
||||
attr: {
|
||||
title: "Toggle fullscreen. If you hold ALT/OPT when starting the presentation it will not go fullscreen."
|
||||
@@ -504,7 +528,8 @@ const createPresentationNavigationPanel = () => {
|
||||
// keyboard navigation
|
||||
//--------------------
|
||||
const keydownListener = (e) => {
|
||||
if(ea.targetView.leaf !== app.workspace.activeLeaf) return;
|
||||
if(hostLeaf !== app.workspace.activeLeaf) return;
|
||||
if(hostLeaf.width === 0 && hostLeaf.height === 0) return;
|
||||
e.preventDefault();
|
||||
switch(e.key) {
|
||||
case "Escape":
|
||||
@@ -630,6 +655,9 @@ const initializeEventListners = () => {
|
||||
// Exit presentation
|
||||
//----------------------------
|
||||
const exitPresentation = async (openForEdit = false) => {
|
||||
//this is a hack, not sure why ea loses target view when other scripts are executed while the presentation is running
|
||||
ea.targetView = hostView;
|
||||
isLaserOn = false;
|
||||
statusBarElement.style.display = "inherit";
|
||||
if(openForEdit) ea.targetView.preventAutozoom();
|
||||
await exitFullscreen();
|
||||
@@ -680,7 +708,8 @@ const exitPresentation = async (openForEdit = false) => {
|
||||
//Resets pointer offsets. Ugly solution.
|
||||
//During testing offsets were wrong after presentation, but don't know why.
|
||||
//This should solve it even if they are wrong.
|
||||
ea.targetView.refresh();
|
||||
hostView.refresh();
|
||||
excalidrawAPI.setActiveTool({type: "selection"});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user