-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
7 lines (6 loc) · 21.5 KB
/
Copy pathmain.js
File metadata and controls
7 lines (6 loc) · 21.5 KB
1
2
3
4
5
6
7
/*
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 S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},N=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!_.call(n,r)&&r!==t&&L(n,r,{get:()=>e[r],enumerable:!(o=S(e,r))||o.enumerable});return n};var O=n=>N(L({},"__esModule",{value:!0}),n);var U={};A(U,{default:()=>T});module.exports=O(U);var F=require("obsidian");var P={bookmarks:[],folders:[],defaultUrl:"https://www.google.com",showBookmarkPanel:!0,interceptLinks:!1},c="side-bookmark-view";function x(){return Date.now().toString(36)+Math.random().toString(36).substring(2,9)}var f=class{constructor(e){this.listeners=[];this.plugin=e,this.data={...P}}async load(){let e=await this.plugin.loadData();e&&(this.data={...P,...e})}async save(){await this.plugin.saveData(this.data)}onChange(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}notify(){for(let e of this.listeners)e()}get defaultUrl(){return this.data.defaultUrl}set defaultUrl(e){this.data.defaultUrl=e}get showBookmarkPanel(){return this.data.showBookmarkPanel}set showBookmarkPanel(e){this.data.showBookmarkPanel=e}get interceptLinks(){return this.data.interceptLinks}set interceptLinks(e){this.data.interceptLinks=e}get bookmarks(){return this.data.bookmarks}get folders(){return this.data.folders}async addBookmark(e,t,o=null){let r=this.data.bookmarks.filter(l=>l.folderId===o),s=r.length>0?Math.max(...r.map(l=>l.order)):-1,i={id:x(),type:"bookmark",title:e,url:t,folderId:o,order:s+1};return this.data.bookmarks.push(i),await this.save(),this.notify(),i}async removeBookmark(e){this.data.bookmarks=this.data.bookmarks.filter(t=>t.id!==e),await this.save(),this.notify()}async updateBookmark(e,t){let o=this.data.bookmarks.find(r=>r.id===e);o&&(Object.assign(o,t),await this.save(),this.notify())}async moveBookmark(e,t){await this.updateBookmark(e,{folderId:t})}async addFolder(e,t=null){let o=this.data.folders.filter(i=>i.parentId===t),r=o.length>0?Math.max(...o.map(i=>i.order)):-1,s={id:x(),type:"folder",name:e,parentId:t,collapsed:!1,order:r+1};return this.data.folders.push(s),await this.save(),this.notify(),s}async removeFolder(e){let t=this.getDescendantFolderIds(e),o=[e,...t];this.data.bookmarks=this.data.bookmarks.filter(r=>{var s;return!o.includes((s=r.folderId)!=null?s:"")}),this.data.folders=this.data.folders.filter(r=>!o.includes(r.id)),await this.save(),this.notify()}async updateFolder(e,t){let o=this.data.folders.find(r=>r.id===e);o&&(Object.assign(o,t),await this.save(),this.notify())}async toggleFolder(e){let t=this.data.folders.find(o=>o.id===e);t&&(t.collapsed=!t.collapsed,await this.save(),this.notify())}getBookmarksByFolder(e){return this.data.bookmarks.filter(t=>t.folderId===e).sort((t,o)=>t.order-o.order)}getSubFolders(e){return this.data.folders.filter(t=>t.parentId===e).sort((t,o)=>t.order-o.order)}getFolder(e){return this.data.folders.find(t=>t.id===e)}getBookmark(e){return this.data.bookmarks.find(t=>t.id===e)}getTreeItems(e){let t=this.getSubFolders(e),o=this.getBookmarksByFolder(e);return[...t,...o].sort((s,i)=>s.order-i.order)}hasBookmarkWithUrl(e){return this.data.bookmarks.some(t=>t.url===e)}getDescendantFolderIds(e){let t=this.data.folders.filter(r=>r.parentId===e),o=[];for(let r of t)o.push(r.id),o.push(...this.getDescendantFolderIds(r.id));return o}};var D=require("obsidian");var u=require("obsidian"),b=class{constructor(e){this.webviewEl=null;this.currentUrl="";this.currentTitle="";this.onAddBookmark=null;this.containerEl=e.createDiv({cls:"sb-browser-panel"}),this.navBarEl=this.containerEl.createDiv({cls:"sb-nav-bar"});let t=this.navBarEl.createDiv({cls:"sb-nav-buttons"});this.backBtn=t.createDiv({cls:"sb-nav-btn",attr:{"aria-label":"Back"}}),(0,u.setIcon)(this.backBtn,"arrow-left"),this.backBtn.addEventListener("click",()=>this.goBack()),this.forwardBtn=t.createDiv({cls:"sb-nav-btn",attr:{"aria-label":"Forward"}}),(0,u.setIcon)(this.forwardBtn,"arrow-right"),this.forwardBtn.addEventListener("click",()=>this.goForward()),this.refreshBtn=t.createDiv({cls:"sb-nav-btn",attr:{"aria-label":"Reload"}}),(0,u.setIcon)(this.refreshBtn,"refresh-cw"),this.refreshBtn.addEventListener("click",()=>this.reload()),this.urlInput=this.navBarEl.createEl("input",{cls:"sb-url-input",attr:{type:"text",placeholder:"Enter URL...",spellcheck:"false"}}),this.urlInput.addEventListener("keydown",o=>{o.key==="Enter"&&this.navigateToInput()}),this.urlInput.addEventListener("focus",()=>{this.urlInput.select()}),this.bookmarkBtn=this.navBarEl.createDiv({cls:"sb-nav-btn sb-bookmark-btn",attr:{"aria-label":"Add bookmark"}}),(0,u.setIcon)(this.bookmarkBtn,"star"),this.bookmarkBtn.addEventListener("click",()=>{this.onAddBookmark&&this.currentUrl&&this.onAddBookmark(this.currentTitle||this.currentUrl,this.currentUrl)}),this.webviewContainer=this.containerEl.createDiv({cls:"sb-webview-container"})}navigate(e){let t=e.trim();t&&(/^https?:\/\//i.test(t)||(t="https://"+t),this.currentUrl=t,this.urlInput.value=t,this.createOrUpdateWebview(t))}goBack(){var e;if(this.webviewEl){let t=this.webviewEl;(e=t.goBack)==null||e.call(t)}}goForward(){var e;if(this.webviewEl){let t=this.webviewEl;(e=t.goForward)==null||e.call(t)}}reload(){var e;if(this.webviewEl){let t=this.webviewEl;(e=t.reload)==null||e.call(t)}}getUrl(){return this.currentUrl}getTitle(){return this.currentTitle}destroy(){this.webviewEl&&(this.webviewEl.remove(),this.webviewEl=null),this.containerEl.remove()}navigateToInput(){let e=this.urlInput.value.trim();e&&this.navigate(e)}createOrUpdateWebview(e){this.webviewContainer.empty();let t=this.webviewContainer.createEl("webview",{attr:{src:e,allowpopups:""},cls:"sb-webview"});t.addEventListener("did-navigate",o=>{let r=o;typeof r.url=="string"&&(this.currentUrl=r.url,this.urlInput.value=r.url)}),t.addEventListener("did-navigate-in-page",o=>{let r=o;typeof r.url=="string"&&(this.currentUrl=r.url,this.urlInput.value=r.url)}),t.addEventListener("page-title-updated",o=>{let r=o;typeof r.title=="string"&&(this.currentTitle=r.title)}),t.addEventListener("dom-ready",()=>{let o=t;o.getURL&&(this.currentUrl=o.getURL(),this.urlInput.value=this.currentUrl),o.getTitle&&(this.currentTitle=o.getTitle())}),t.addEventListener("new-window",o=>{let r=o;typeof r.url=="string"&&this.navigate(r.url)}),this.webviewEl=t}};var d=require("obsidian");var a=require("obsidian"),m=class extends a.Modal{constructor(e,t,o="",r="",s=null,i){super(e),this.store=t,this.title=o,this.url=r,this.folderId=s,this.onSave=i!=null?i:null}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("side-bookmark-modal"),e.createEl("h3",{text:"Add bookmark"}),new a.Setting(e).setName("Title").addText(t=>t.setPlaceholder("Enter bookmark title").setValue(this.title).onChange(o=>{this.title=o})),new a.Setting(e).setName("URL").addText(t=>t.setPlaceholder("https://example.com").setValue(this.url).onChange(o=>{this.url=o})),new a.Setting(e).setName("Folder").addDropdown(t=>{var o;t.addOption("__root__","(No folder)");for(let r of this.store.folders)t.addOption(r.id,this.getFolderPath(r));t.setValue((o=this.folderId)!=null?o:"__root__"),t.onChange(r=>{this.folderId=r==="__root__"?null:r})}),new a.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(async()=>{if(!this.url.trim())return;this.title.trim()||(this.title=this.url);let o=this.url.trim();/^https?:\/\//i.test(o)||(o="https://"+o),this.onSave?this.onSave(this.title.trim(),o,this.folderId):await this.store.addBookmark(this.title.trim(),o,this.folderId),this.close()})).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close()))}onClose(){let{contentEl:e}=this;e.empty()}getFolderPath(e){let t=[e.name],o=e;for(;o!=null&&o.parentId;)o=this.store.getFolder(o.parentId),o&&t.unshift(o.name);return t.join(" / ")}},w=class extends a.Modal{constructor(e,t,o,r,s,i){super(e),this.store=t,this.bookmarkId=o,this.title=r,this.url=s,this.folderId=i}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("side-bookmark-modal"),e.createEl("h3",{text:"Edit bookmark"}),new a.Setting(e).setName("Title").addText(t=>t.setPlaceholder("Enter bookmark title").setValue(this.title).onChange(o=>{this.title=o})),new a.Setting(e).setName("URL").addText(t=>t.setPlaceholder("https://example.com").setValue(this.url).onChange(o=>{this.url=o})),new a.Setting(e).setName("Folder").addDropdown(t=>{var o;t.addOption("__root__","(No folder)");for(let r of this.store.folders)t.addOption(r.id,this.getFolderPath(r));t.setValue((o=this.folderId)!=null?o:"__root__"),t.onChange(r=>{this.folderId=r==="__root__"?null:r})}),new a.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(async()=>{if(!this.url.trim())return;this.title.trim()||(this.title=this.url);let o=this.url.trim();/^https?:\/\//i.test(o)||(o="https://"+o),await this.store.updateBookmark(this.bookmarkId,{title:this.title.trim(),url:o,folderId:this.folderId}),this.close()})).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close()))}onClose(){let{contentEl:e}=this;e.empty()}getFolderPath(e){let t=[e.name],o=e;for(;o!=null&&o.parentId;)o=this.store.getFolder(o.parentId),o&&t.unshift(o.name);return t.join(" / ")}},v=class extends a.Modal{constructor(e,t,o=null){super(e),this.store=t,this.folderName="",this.parentId=o}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("side-bookmark-modal"),e.createEl("h3",{text:"New folder"}),new a.Setting(e).setName("Folder name").addText(t=>t.setPlaceholder("Enter folder name").setValue(this.folderName).onChange(o=>{this.folderName=o})),new a.Setting(e).setName("Parent folder").addDropdown(t=>{var o;t.addOption("__root__","(Root level)");for(let r of this.store.folders)t.addOption(r.id,this.getFolderPath(r));t.setValue((o=this.parentId)!=null?o:"__root__"),t.onChange(r=>{this.parentId=r==="__root__"?null:r})}),new a.Setting(e).addButton(t=>t.setButtonText("Create").setCta().onClick(async()=>{this.folderName.trim()&&(await this.store.addFolder(this.folderName.trim(),this.parentId),this.close())})).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close()))}onClose(){let{contentEl:e}=this;e.empty()}getFolderPath(e){let t=[e.name],o=e;for(;o!=null&&o.parentId;)o=this.store.getFolder(o.parentId),o&&t.unshift(o.name);return t.join(" / ")}},B=class extends a.Modal{constructor(e,t,o,r){super(e),this.store=t,this.folderId=o,this.folderName=r}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("side-bookmark-modal"),e.createEl("h3",{text:"Edit folder"}),new a.Setting(e).setName("Folder name").addText(t=>t.setPlaceholder("Enter folder name").setValue(this.folderName).onChange(o=>{this.folderName=o})),new a.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(async()=>{this.folderName.trim()&&(await this.store.updateFolder(this.folderId,{name:this.folderName.trim()}),this.close())})).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close()))}onClose(){let{contentEl:e}=this;e.empty()}},g=class extends a.Modal{constructor(e,t,o){super(e),this.message=t,this.onConfirm=o}onOpen(){let{contentEl:e}=this;e.empty(),e.addClass("side-bookmark-modal"),e.createEl("h3",{text:"Confirm delete"}),e.createEl("p",{text:this.message}),new a.Setting(e).addButton(t=>t.setButtonText("Delete").setWarning().onClick(async()=>{await this.onConfirm(),this.close()})).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close()))}onClose(){let{contentEl:e}=this;e.empty()}};var E=class{constructor(e,t,o){this.collapsed=!1;this.unsubscribe=null;this.onNavigate=null;this.app=e,this.store=o,this.containerEl=t.createDiv({cls:"sb-bookmark-panel"}),this.headerEl=this.containerEl.createDiv({cls:"sb-bookmark-header"});let r=this.headerEl.createDiv({cls:"sb-bookmark-header-left"}),s=r.createDiv({cls:"sb-collapse-icon"});(0,d.setIcon)(s,"chevron-down"),r.createSpan({text:"Bookmarks",cls:"sb-bookmark-title"}),r.addEventListener("click",()=>{this.toggleCollapse()});let l=this.headerEl.createDiv({cls:"sb-bookmark-header-right"}).createDiv({cls:"sb-add-btn-group"}),p=l.createDiv({cls:"sb-header-btn",attr:{"aria-label":"Add bookmark"}});(0,d.setIcon)(p,"plus"),p.addEventListener("click",C=>{C.stopPropagation(),new m(this.app,this.store).open()});let h=l.createDiv({cls:"sb-header-btn",attr:{"aria-label":"New folder"}});(0,d.setIcon)(h,"folder-plus"),h.addEventListener("click",C=>{C.stopPropagation(),new v(this.app,this.store).open()}),this.listEl=this.containerEl.createDiv({cls:"sb-bookmark-list"}),this.unsubscribe=this.store.onChange(()=>{this.renderList()}),this.renderList()}toggleCollapse(){this.collapsed=!this.collapsed,this.containerEl.toggleClass("sb-collapsed",this.collapsed);let e=this.headerEl.querySelector(".sb-collapse-icon");e&&(e.empty(),(0,d.setIcon)(e,this.collapsed?"chevron-right":"chevron-down"))}destroy(){this.unsubscribe&&this.unsubscribe(),this.containerEl.remove()}renderList(){if(this.listEl.empty(),this.store.getTreeItems(null).length===0){let t=this.listEl.createDiv({cls:"sb-empty-state"}),o=t.createDiv({cls:"sb-empty-icon"});(0,d.setIcon)(o,"bookmark"),t.createDiv({text:"No bookmarks",cls:"sb-empty-text"}),t.createDiv({text:"Click the + button or \u2B50 icon to add a bookmark",cls:"sb-empty-hint"});return}this.renderTreeLevel(this.listEl,null,0)}renderTreeLevel(e,t,o){let r=this.store.getTreeItems(t);for(let s of r)s.type==="folder"?this.renderFolder(e,s,o):this.renderBookmark(e,s,o)}renderFolder(e,t,o){let r=e.createDiv({cls:"sb-tree-item sb-folder-item",attr:{"data-id":t.id,"data-type":"folder",draggable:"true"}});r.style.paddingLeft=`${o*16+4}px`;let s=r.createDiv({cls:"sb-tree-item-row"}),i=s.createDiv({cls:"sb-folder-collapse"});(0,d.setIcon)(i,t.collapsed?"chevron-right":"chevron-down");let l=s.createDiv({cls:"sb-item-icon"});(0,d.setIcon)(l,t.collapsed?"folder":"folder-open"),s.createSpan({text:t.name,cls:"sb-item-label"});let p=this.store.getBookmarksByFolder(t.id).length+this.store.getSubFolders(t.id).length;if(p>0&&s.createSpan({text:`${p}`,cls:"sb-count-badge"}),s.addEventListener("click",()=>{this.store.toggleFolder(t.id)}),s.addEventListener("contextmenu",h=>{h.preventDefault(),h.stopPropagation(),this.showFolderContextMenu(h,t)}),this.setupDragEvents(r,t),!t.collapsed){let h=e.createDiv({cls:"sb-folder-children"});this.renderTreeLevel(h,t.id,o+1)}}renderBookmark(e,t,o){let r=e.createDiv({cls:"sb-tree-item sb-bookmark-item",attr:{"data-id":t.id,"data-type":"bookmark",draggable:"true"}});r.style.paddingLeft=`${o*16+24}px`;let s=r.createDiv({cls:"sb-tree-item-row"}),i=s.createDiv({cls:"sb-item-icon"});(0,d.setIcon)(i,"globe"),s.createSpan({text:t.title,cls:"sb-item-label"}),s.addEventListener("click",()=>{this.onNavigate&&this.onNavigate(t.url)}),s.addEventListener("contextmenu",l=>{l.preventDefault(),l.stopPropagation(),this.showBookmarkContextMenu(l,t)}),this.setupDragEvents(r,t)}showBookmarkContextMenu(e,t){let o=new d.Menu;o.addItem(r=>{r.setTitle("Open"),r.setIcon("external-link"),r.onClick(()=>{this.onNavigate&&this.onNavigate(t.url)})}),o.addSeparator(),o.addItem(r=>{r.setTitle("Edit"),r.setIcon("pencil"),r.onClick(()=>{new w(this.app,this.store,t.id,t.title,t.url,t.folderId).open()})}),o.addItem(r=>{r.setTitle("Move to..."),r.setIcon("folder-input"),r.onClick(()=>{this.showMoveMenu(e,t)})}),o.addSeparator(),o.addItem(r=>{r.setTitle("Delete"),r.setIcon("trash-2"),r.onClick(()=>{new g(this.app,`Are you sure you want to delete bookmark "${t.title}"?`,async()=>{await this.store.removeBookmark(t.id)}).open()})}),o.showAtMouseEvent(e)}showFolderContextMenu(e,t){let o=new d.Menu;o.addItem(r=>{r.setTitle("Add bookmark to this folder"),r.setIcon("plus"),r.onClick(()=>{new m(this.app,this.store,"","",t.id).open()})}),o.addItem(r=>{r.setTitle("Add sub-folder"),r.setIcon("folder-plus"),r.onClick(()=>{new v(this.app,this.store,t.id).open()})}),o.addSeparator(),o.addItem(r=>{r.setTitle("Rename"),r.setIcon("pencil"),r.onClick(()=>{new B(this.app,this.store,t.id,t.name).open()})}),o.addSeparator(),o.addItem(r=>{r.setTitle("Delete folder"),r.setIcon("trash-2"),r.onClick(()=>{let s=this.store.getBookmarksByFolder(t.id).length,i=this.store.getSubFolders(t.id).length,l=`Are you sure you want to delete folder "${t.name}"?`;(s>0||i>0)&&(l+=`
It contains ${s} bookmarks and ${i} folders, which will all be deleted.`),new g(this.app,l,async()=>{await this.store.removeFolder(t.id)}).open()})}),o.showAtMouseEvent(e)}showMoveMenu(e,t){let o=new d.Menu;t.folderId!==null&&(o.addItem(r=>{r.setTitle("(Root level)"),r.setIcon("corner-left-up"),r.onClick(async()=>{await this.store.moveBookmark(t.id,null)})}),o.addSeparator());for(let r of this.store.folders)r.id!==t.folderId&&o.addItem(s=>{s.setTitle(r.name),s.setIcon("folder"),s.onClick(async()=>{await this.store.moveBookmark(t.id,r.id)})});o.showAtMouseEvent(e)}setupDragEvents(e,t){e.addEventListener("dragstart",o=>{o.dataTransfer&&(o.dataTransfer.setData("text/plain",JSON.stringify({id:t.id,type:t.type})),o.dataTransfer.effectAllowed="move"),e.addClass("sb-dragging")}),e.addEventListener("dragend",()=>{e.removeClass("sb-dragging"),this.listEl.querySelectorAll(".sb-drop-target").forEach(o=>o.removeClass("sb-drop-target"))}),e.addEventListener("dragover",o=>{o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect="move"),e.addClass("sb-drop-target")}),e.addEventListener("dragleave",()=>{e.removeClass("sb-drop-target")}),e.addEventListener("drop",o=>{if(o.preventDefault(),e.removeClass("sb-drop-target"),!!o.dataTransfer)try{let r=JSON.parse(o.dataTransfer.getData("text/plain"));if(!r.id||!r.type)return;r.type==="bookmark"&&t.type==="folder"&&this.store.moveBookmark(r.id,t.id)}catch(r){}})}};var y=class extends D.ItemView{constructor(t,o){super(t);this.browserPanel=null;this.bookmarkPanel=null;this.plugin=o}getViewType(){return c}getDisplayText(){return"Side bookmark"}getIcon(){return"bookmark"}onOpen(){let t=this.contentEl;t.empty(),t.addClass("sb-container"),this.browserPanel=new b(t),this.browserPanel.onAddBookmark=(r,s)=>{new m(this.app,this.plugin.store,r,s,null,(i,l,p)=>{this.plugin.store.addBookmark(i,l,p)}).open()};let o=this.plugin.store.defaultUrl;return o&&this.browserPanel.navigate(o),this.bookmarkPanel=new E(this.app,t,this.plugin.store),this.bookmarkPanel.onNavigate=r=>{this.browserPanel&&this.browserPanel.navigate(r)},this.plugin.store.showBookmarkPanel||this.bookmarkPanel.toggleCollapse(),Promise.resolve()}onClose(){return this.browserPanel&&(this.browserPanel.destroy(),this.browserPanel=null),this.bookmarkPanel&&(this.bookmarkPanel.destroy(),this.bookmarkPanel=null),Promise.resolve()}navigateTo(t){this.browserPanel&&this.browserPanel.navigate(t)}};var k=require("obsidian"),I=class extends k.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){let{containerEl:e}=this;e.empty(),new k.Setting(e).setName("Default homepage").setDesc("The URL to load when the plugin opens.").addText(o=>o.setPlaceholder("https://www.google.com").setValue(this.plugin.store.defaultUrl).onChange(async r=>{this.plugin.store.defaultUrl=r,await this.plugin.store.save()})),new k.Setting(e).setName("Show bookmark panel by default").setDesc("Expand the bookmark list panel automatically when the plugin opens.").addToggle(o=>o.setValue(this.plugin.store.showBookmarkPanel).onChange(async r=>{this.plugin.store.showBookmarkPanel=r,await this.plugin.store.save()})),new k.Setting(e).setName("Intercept note links").setDesc("When enabled, clicking external links (http/https) in notes opens them in the built-in browser instead of the system browser. Hold Cmd/Ctrl while clicking to bypass and use the system browser.").addToggle(o=>o.setValue(this.plugin.store.interceptLinks).onChange(async r=>{this.plugin.store.interceptLinks=r,await this.plugin.store.save()})),new k.Setting(e).setName("Statistics").setHeading();let t=e.createDiv({cls:"sb-settings-stats"});t.createEl("p",{text:`Bookmarks: ${this.plugin.store.bookmarks.length}`}),t.createEl("p",{text:`Folders: ${this.plugin.store.folders.length}`})}};var T=class extends F.Plugin{constructor(){super(...arguments);this.modifierKeyPressed=!1}async onload(){this.store=new f(this),await this.store.load(),this.registerView(c,t=>new y(t,this)),this.addRibbonIcon("bookmark","Side bookmark",()=>{this.activateView()}),this.addCommand({id:"open",name:"Open",callback:()=>{this.activateView()}}),this.addSettingTab(new I(this.app,this)),this.registerDomEvent(activeDocument,"click",this.handleLinkClick.bind(this),!0),this.registerDomEvent(activeDocument,"keydown",t=>{(t.key==="Meta"||t.key==="Control"||t.metaKey||t.ctrlKey)&&(this.modifierKeyPressed=!0)}),this.registerDomEvent(activeDocument,"keyup",t=>{(t.key==="Meta"||t.key==="Control"||!t.metaKey&&!t.ctrlKey)&&(this.modifierKeyPressed=!1)}),this.registerDomEvent(activeWindow,"blur",()=>{this.modifierKeyPressed=!1}),this.originalWindowOpen=window.open,window.open=(t,o,r)=>{if(this.store.interceptLinks&&t&&!this.modifierKeyPressed){let s=t.toString();if(/^https?:\/\//i.test(s))return this.openUrlInSideBookmark(s),null}return this.originalWindowOpen.call(window,t,o,r)}}onunload(){this.originalWindowOpen&&(window.open=this.originalWindowOpen)}handleLinkClick(t){if(!this.store.interceptLinks)return;let r=t.target.closest("a");if(!r)return;let s=r.getAttribute("href")||r.href;!s||!/^https?:\/\//i.test(s)||t.metaKey||t.ctrlKey||r.closest(".sb-browser-panel")||r.closest("webview")||(t.preventDefault(),t.stopPropagation(),this.openUrlInSideBookmark(s))}async openUrlInSideBookmark(t){let{workspace:o}=this.app,r=o.getLeavesOfType(c);if(r.length===0)await this.activateView(),r=o.getLeavesOfType(c);else{let i=r[0];i&&o.revealLeaf(i)}let s=r[0];if(s){let i=s.view;typeof i.navigateTo=="function"&&i.navigateTo(t)}}async activateView(){let{workspace:t}=this.app,o=t.getLeavesOfType(c);if(o.length>0)t.revealLeaf(o[0]);else{let r=t.getRightLeaf(!1);r&&(await r.setViewState({type:c,active:!0}),t.revealLeaf(r))}}};