4 lines
39 KiB
JavaScript
Raw Normal View History

2024-04-15 11:54:03 +08:00
var ce=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ve=(i,r)=>{for(var e in r)ce(i,e,{get:r[e],enumerable:!0})},De=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Ie(r))!Fe.call(i,o)&&o!==e&&ce(i,o,{get:()=>r[o],enumerable:!(t=Ae(r,o))||t.enumerable});return i};var Ne=i=>De(ce({},"__esModule",{value:!0}),i);var je={};Ve(je,{default:()=>se,leafName:()=>v,splitName:()=>ne});module.exports=Ne(je);var E=require("obsidian");var L=typeof queueMicrotask=="function"?queueMicrotask:(i=>r=>i.then(r))(Promise.resolve());function pe(i){return i&&typeof i=="object"?JSON.parse(JSON.stringify(i)):i}function T(i,r,e){let t=i.classList.contains(r);return e=e!=null?e:!t,e!==t&&(e?i.classList.add(r):i.classList.remove(r)),e}var h;(i=>Object.assign(i,require("obsidian")))(h||(h={}));var le="use.me",ue="use.factory",z,j,fe=function(){return Object.defineProperties(i(),{this:{get(){if(z)return z;throw new TypeError("No current context")}},me:{value:le},factory:{value:ue}});function i(o){let a=new Map;a.prev=o;let n=Object.assign(o?c=>{let p=a.get(c);if(!p){for(let y=a.prev;y;y=y.prev)if(p=y.get(c)){p=Object.assign(Object.assign({},p),{s:p.s||1});break}p=p||{s:2,v:e},a.set(c,p)}let f,m,g;for(;;)switch(p.s){case 0:return z===n&&j&&j.push(c),p.v;case 1:if(f=p.d,!f||s(()=>f.k.every(y=>n(y)===f.c(y)))){p.s=0;break}p.v=f.f;case 2:p.s=4;try{r(a,c,0,s(m=p.v,c,g=[])),g.length&&(p.d={c:n,f:m,k:g});break}catch(y){p.s=3,p.v=y,p.d=null}case 3:throw p.v;case 4:throw new Error(`Factory ${String(p.v)} didn't resolve ${String(c)}`)}}:c=>fe.this(c),{def(c,p){return r(a,c,2,p),n},set(c,p){return r(a,c,1,p),n},fork(c){let p=i(a);return c!=null?p(c):p}});return o?n.use=n:n;function s(c,p,f){let m=z,g=j;try{return z=n,j=f,c(p)}finally{z=m,j=g}}}function r(o,a,n,s){if(o.has(a)){let c=o.get(a);if(!c.s)throw new Error(`Already read: ${String(a)}`);c.s=n,c.v=s,c.d=null}else o.set(a,{s:n,v:s})}function e(o){if(typeof o[le]=="function")return o[le](o);if(t(o))return typeof o.prototype[ue]=="function"?o.prototype[ue]():new o;throw new ReferenceError(`No config for ${String(o)}`)}function t(o){return typeof o=="function"&&o.prototype!==void 0&&(Object.getPrototypeOf(o.prototype)!==Object.prototype||Object.getOwnPropertyNames(o.prototype).length>1||o.toString().startsWith("class"))}}();var Oe,V=(i=>(i.service=function(r){return i(G).addChild(r),i.this},i.plugin=function(r){if(!F)Oe=r.app,F=i.fork(),F.set(h.Plugin,r),F.set(r.constructor,r),r.addChild(F.use(G));else if(r!==F.use(h.Plugin))throw new TypeError("use.plugin() called on multiple plugins");return F},i.def(h.Plugin,()=>{throw new Error("Plugin not created yet")}),i.def(h.App,()=>i(h.Plugin).app),i))(fe),F;var k=class extends h.Component{constructor(){super(...arguments);this.use=V.service(this)}},G=class extends h.Component{constructor(){super(...arguments);this.children=new Set([this])}onload(){this.loaded=!0}onunload(){this.loaded=!1,this.children.clear()}addChild(e){return this.children.has(e)||(this.children.add(e),this.loaded?L(()=>super.addChild(e)):super.addChild(e)),e}};function Q(i,r){L(()=>i.removeChild(r))}function ve(i,r){let e=new h.Component;e.onload=()=>{Q(i,e),i=null,r()},i.addChild(e)}function u(i,r){let e=Object.keys(r).map(t=>ze(i,t,r[t]));return e.length===1?e[0]:function(){e.forEach(t=>t())}}function ze(i,r,e){let t=i[r],o=i.hasOwnProperty(r),a=e(t);return t&&Object.setPrototypeOf(a,t),Object.setPrototypeOf(n,a),i[r]=n,s;function n(...c){return a===t&&i[r]===n&&s(),a.apply(this,c)}function s(){i[r]===n&&(o?i[r]=t:delete i[r]),a!==t&&(a=t,Object.setPrototypeOf(n,t||Function))}}function _(i,r,e){return t[i]=i,t;function t(...o){return(r[i]===i?r:e).apply(this,o)}}function X(i){let r=app.workspace;switch(i==null?void 0:i.getRoot()){case r.rootSplit:case r.floatingSplit:case r.leftSplit:case r.rightSplit:return!0;default:return!1}}function D(i,r){if(!i)return!1;if(typeof i=="function"&&(r=i,i=app.workspace),r(i))return!0;if(i instanceof h.Workspace)return D(i.rootSplit,r)||D(i.float
.view-header > .view-header-nav-buttons > button:${this.dir<0?"first":"last"}-child`,(t,o)=>{let a=o.matchParent(".workspace-leaf"),n=this.owner.leaves().filter(s=>s.containerEl===a).pop();n&&(t.preventDefault(),t.stopImmediatePropagation(),this.openMenu(t,d.forLeaf(n)))},{capture:!0}))}onunload(){K(this.containerEl,this.oldLabel),this.count.detach(),this.containerEl.toggleClass("mod-active",!1)}setCount(e){this.count.textContent=""+(e||"")}setHistory(e=d.current()){this.updateDisplay(this.history=e)}updateDisplay(e,t=this.containerEl){let o=e[this.dir<0?"lookBehind":"lookAhead"]();t===this.containerEl&&this.setCount(o.length),K(t,o.length?this.oldLabel+`
`+re(o[0]).title:`No ${this.kind} history`),t.toggleClass("mod-active",o.length>0)}openMenu(e,t=this.history){var n;let o=t[this.dir<0?"lookBehind":"lookAhead"]();if(!o.length)return;let a=new w.Menu;(n=a.setUseNativeMenu)==null||n.call(a,!1),a.dom.addClass("pane-relief-history-menu"),a.dom.on("mousedown",".menu-item",s=>{s.stopPropagation()},!0),o.map(re).forEach((s,c)=>this.menuItem(s,c,a,t)),a.showAtPosition({x:e.clientX,y:e.clientY+20}),a.register(u(app.workspace,{setActiveLeaf(s){return function(c,...p){if(!c.containerEl.matchParent(".hover-editor"))return s.call(this,c,...p)}}})),this.owner.historyIsOpen=!0,a.onHide(()=>{this.owner.historyIsOpen=!1,this.owner.display()})}menuItem(e,t,o,a){let{dir:n,kind:s}=this;o.addItem(f=>{c(f),e.file&&p(f.dom)});return;function c(f,m=""){f.setIcon(e.icon).setTitle(m+e.title).onClick(g=>{if(w.Keymap.isModEvent(g))if(W&&a.leaf){app.workspace.duplicateLeaf(a.leaf,w.Keymap.isModEvent(g)).then(y=>{d.forLeaf(y).go((t+1)*n,!0)});return}else a=a.cloneTo(app.workspace.getLeaf(w.Keymap.isModEvent(g)));a.go((t+1)*n,!0)})}function p(f){f.addEventListener("mouseover",m=>{app.workspace.trigger("hover-link",{event:m,source:ye.hoverSource,hoverParent:o.dom,targetEl:f,linktext:e.file.path})}),f.setAttr("draggable","true"),f.addEventListener("dragstart",m=>{let g=app.dragManager,y=g.dragFile(m,e.file);g.onDragStart(m,y)}),f.addEventListener("dragend",m=>o.hide()),f.addEventListener("contextmenu",m=>{let g=new w.Menu;g.addItem(y=>c(y,`Go ${s} to `)).addSeparator(),app.workspace.trigger("file-menu",g,e.file,"link-context-menu"),g.showAtPosition({x:m.clientX,y:m.clientY}),m.stopPropagation()},!0)}}},H=ye;H.hoverSource="pane-relief:history-menu";function re(i){var c,p,f,m,g;let{viewState:{type:r,state:e},eState:t,path:o,raw:a}=i,n=o&&app.vault.getAbstractFileByPath(o),s={icon:(c=a==null?void 0:a.icon)!=null?c:"",title:(p=a==null?void 0:a.title)!=null?p:"",file:n,type:r,state:e,eState:t};return He[r]?[s.icon,s.title]=He[r]:o&&!n?[s.icon,s.title]=["trash","Missing file "+o]:n instanceof w.TFile&&(s.icon=(f=Ke[r])!=null?f:"document",r==="markdown"&&e.mode==="preview"&&(s.icon="lines-of-text"),s.title=n?n.basename+(n.extension!=="md"?"."+n.extension:""):"No file",r==="media-view"&&!n&&(s.title=(g=(m=e.info)==null?void 0:m.filename)!=null?g:s.title)),app.workspace.trigger("pane-relief:format-history-item",s),s}function Ue(i,r,e,t,o){return i.on(r,e,t,o),()=>i.off(r,e,t,o)}function K(i,r){r?i.setAttribute("aria-label",r||void 0):i.removeAttribute("aria-label")}var ae=class extends k{constructor(){super(...arguments);this.setting=new M(this,"pane-relief:focus-lock").of(app.workspace);this.plugin=this.use(A.Plugin);this.statusEl=this.plugin.addStatusBarItem();this.iconEl=this.statusEl.createSpan("pane-relief-focus-lock icon",e=>{e.setAttribute("aria-label-position","top"),e.setAttribute("aria-label-delay","0"),e.setAttribute("data-tooltip-position","top")});this.isLocked=null;this.installed=!1}onload(){this.registerDomEvent(this.iconEl,"click",()=>this.toggle()),ee(this.plugin,{[l("focus-lock","Toggle focus lock (Enable/disable sidebar focusing)")]:()=>()=>this.toggle()}),this.registerEvent(this.setting.onLoadWorkspace(this.onChange,this))}install(){this.installed=!0;let e=this;this.register(u(app.workspace,{setActiveLeaf(t){return function(o,...a){if(!e.isLocked||R(o))return t.call(this,o,...a);if(app.workspace.revealLeaf(o),!this.activeLeaf||!X(this.activeLeaf))return t.call(this,this.getLeaf(),...a)}},revealLeaf(t){return function(o){let a=o.getContainer();if(!e.isLocked||R(o)||!a)return t.call(this,o);let n=u(a,{focus(){return function(){}}});try{return t.call(this,o)}finally{n()}}}})),this.register(u(A.WorkspaceLeaf.prototype,{canNavigate(t){return function(){return t.call(this)&&(!e.isLocked||R(this))}}})),this.register(u(app.internalPlugins.plugins["file-explorer"].instance,{init(t){return function(...a){try{return t.apply(this,a)}finally{e.blockFileExplorerReveal()}}}})),this.blockFileExplorerReveal()}blockFileExplorerReveal(){let e=this,t=app.commands.commands["file-explorer:reveal-active-file"];t&