obsidian/.obsidian/plugins/reader-mode/main.js

8 lines
1.4 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var l=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var w=(i,t)=>{for(var e in t)l(i,e,{get:t[e],enumerable:!0})},u=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of p(t))!h.call(i,n)&&n!==e&&l(i,n,{get:()=>t[n],enumerable:!(o=c(t,n))||o.enumerable});return i};var v=i=>u(l({},"__esModule",{value:!0}),i);var f={};w(f,{default:()=>r});module.exports=v(f);var a=require("obsidian"),r=class extends a.Plugin{constructor(){super(...arguments);this.newFilePath=null}async onload(){this.registerEvent(this.app.workspace.on("active-leaf-change",async e=>{if(!e||!(e.view instanceof a.MarkdownView))return;let n=e.view.file;if(!(!n||!(n instanceof a.TFile))){if(this.newFilePath!==n.path){this.newFilePath=null;return}this.newFilePath=null;try{let s=e.getViewState();if(!s.state)return;(await this.app.vault.cachedRead(n)).replace(/^---\s*\n[\s\S]*?\n---\s*\n*/,"").trim()?s.state.mode="preview":s.state.mode="source",await e.setViewState(s)}catch(s){console.error("Error forcing preview mode:",s)}}})),this.registerEvent(this.app.workspace.on("file-open",async e=>{this.newFilePath=e?e.path:null})),this.registerEvent(this.app.vault.on("create",async e=>{e.extension==="md"&&(this.newFilePath=e?e.path:null)}))}};
/* nosourcemap */