/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/main.ts var main_exports = {}; __export(main_exports, { default: () => FavoritePlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian6 = require("obsidian"); // src/lib/utils.ts var import_obsidian = require("obsidian"); function createFavoriteButton(isFavorite = false, icon = "star", fillIcon = false) { const trailingButton = document.createElement("span"); trailingButton.classList.add("fav-btn"); if (isFavorite) { trailingButton.classList.add("is-favorite"); if (fillIcon) { trailingButton.classList.add("fav-icon-filled"); } } else { trailingButton.classList.remove("is-favorite"); trailingButton.classList.remove("fav-icon-filled"); } (0, import_obsidian.setIcon)(trailingButton, icon); return trailingButton; } // src/constants.ts var DEFAULT_SETTINGS = { icon: "star", filled: false, favorites: /* @__PURE__ */ new Set() }; var SETTINGS_ICON_BTN_ID = "fv-select-icon-btn"; // src/variants/BasePlugin.ts var BasePluginContract = class { }; var BasePlugin = class extends BasePluginContract { constructor(plugin, app) { super(); this.isEnabled = false; this.plugin = plugin; this.app = app; this.init(); } async init() { await this.loadSettings(); } async loadSettings() { this.settings = Object.assign( {}, DEFAULT_SETTINGS, await this.plugin.loadData() ); this.favorites = new Set(Object.values(this.settings.favorites)); } async saveSettings() { await this.plugin.saveData({ ...this.settings, favorites: Object.assign({}, Array.from(this.favorites)) }); } isFavorite(filePath) { return this.favorites.has(filePath); } removeFavorite(filePath) { this.favorites.delete(filePath); this.saveSettings(); } onFileDelete(file) { this.removeFavorite(file.path); } toggleFavorite(filePath) { if (this.isFavorite(filePath)) { this.favorites.delete(filePath); } else { this.favorites.add(filePath); } this.saveSettings(); } }; // src/variants/DesktopPlugin.ts var import_obsidian4 = require("obsidian"); // src/tabs/settings-tab.ts var import_obsidian3 = require("obsidian"); // src/modals/choose-icon-modal.ts var import_obsidian2 = require("obsidian"); var ChooseFromIconList = class extends import_obsidian2.FuzzySuggestModal { constructor(plugin, issub = false) { super(plugin.app); this.plugin = plugin; this.issub = issub; this.setPlaceholder("Choose an icon"); } capitalJoin(string) { const icon = string.split(" "); return icon.map((icon2) => { return icon2[0].toUpperCase() + icon2.substring(1); }).join(" "); } getItems() { return (0, import_obsidian2.getIconIds)(); } getItemText(item) { return this.capitalJoin( item.replace("feather-", "").replace("remix-", "").replace("bx-", "").replace(/([A-Z])/g, " $1").trim().replace(/-/gi, " ") ); } renderSuggestion(icon, iconItem) { const span = createSpan({ cls: "fv-icon-item" }); iconItem.appendChild(span); (0, import_obsidian2.setIcon)(span, icon.item); super.renderSuggestion(icon, iconItem); } async onChooseItem(item) { this.plugin.variant.settings.icon = item; (0, import_obsidian2.setIcon)( document.querySelector( `#${SETTINGS_ICON_BTN_ID}` ), item ); await this.plugin.variant.saveSettings(); this.plugin.variant.reload(); setTimeout(() => { dispatchEvent(new Event("print-greeting-to-console")); }, 100); } }; // src/tabs/settings-tab.ts var FavoritePluginSettingsTab = class extends import_obsidian3.PluginSettingTab { constructor(app, plugin) { super(app, plugin); this.plugin = plugin; } display() { const { containerEl } = this; containerEl.empty(); new import_obsidian3.Setting(containerEl).setName("Favorite Icon").setDesc("Choose your favorite icon").addButton((el) => { el.setIcon(this.plugin.variant.settings.icon); el.onClick(async () => { new ChooseFromIconList(this.plugin, false).open(); }); this.plugin.variant.saveSettings(); }).controlEl.children[0].setAttr("id", SETTINGS_ICON_BTN_ID); new import_obsidian3.Setting(containerEl).setName("Fill Icon").setDesc("If you want to fill the icon or not").addToggle((el) => { el.setValue(this.plugin.variant.settings.filled); el.onChange(async (value) => { this.plugin.variant.settings.filled = value; this.plugin.variant.saveSettings(); this.plugin.variant.reload(); }); }); const donationDiv = containerEl.createEl("div", { cls: "donate-section" }); const donateText = createEl("p", { text: "If you like this Plugin and are considering donating to support continued development, use the button below!" }); donationDiv.appendChild(donateText); donationDiv.appendChild( this.createDonateButton("https://www.buymeacoffee.com/mahmudz") ); } createDonateButton(link) { const a = createEl("a"); a.setAttribute("href", link); a.addClass("buymeacoffee-img"); const img = createEl("img", { attr: { src: "https://img.buymeacoffee.com/button-api/?text=Buy me a coffee &emoji=&slug=mahmudz&button_colour=BD5FFF&font_colour=ffffff&font_family=Poppins&outline_colour=000000&coffee_colour=FFDD00" } }); a.appendChild(img); return a; } }; // src/variants/DesktopPlugin.ts var DesktopPlugin = class extends BasePlugin { getFileExplorer() { return this.app.workspace.containerEl.find(".nav-files-container"); } onFolderExpand(e) { if (this.isEnabled) { this.addFavoriteIconToFolder(e.currentTarget); } else { const parentElement = e.currentTarget; this.removeFavoriteIconFromChild(parentElement); } } addFavoriteIconToItem(listItem) { var _a; const filePath = (_a = listItem.getAttribute("data-path")) != null ? _a : ""; const trailingButton = createFavoriteButton( this.isFavorite(filePath), this.settings.icon, this.settings.filled ); trailingButton.addEventListener("click", (e) => { const favoriteButton = e.currentTarget; if (favoriteButton) { const titleEl = favoriteButton.parentElement; const filePath2 = titleEl.getAttribute("data-path"); this.toggleFavorite(filePath2); if (this.isFavorite(filePath2)) { favoriteButton.classList.add("is-favorite"); if (this.settings.filled) { trailingButton.classList.add("fav-icon-filled"); } } else { favoriteButton.classList.remove("is-favorite"); trailingButton.classList.remove("fav-icon-filled"); } } }); listItem.appendChild(trailingButton); } addFavoriteIconToFolder(folderEl) { const listItems = folderEl.querySelectorAll( ".nav-folder, .nav-file-title" ); listItems.forEach((listItem) => { const isAlreadyExists = listItem.find(".fav-btn"); if (isAlreadyExists) { return; } if (listItem.classList.contains("nav-file-title")) { listItem.addClass("fav-nav-file-title"); this.addFavoriteIconToItem(listItem); } else if (!listItem.classList.contains("is-collapsed")) { setTimeout(() => { this.addFavoriteIconToFolder(listItem); }, 200); } else { listItem.addEventListener( "click", this.onFolderExpand.bind(this), { once: true } ); } }); } addFavoriteIcons() { const parent = this.getFileExplorer(); if (parent) { this.addFavoriteIconToFolder(parent); } } removeFavoriteIconFromChild(folderEl) { const listItems = folderEl.querySelectorAll( ".nav-folder, .nav-file-title" ); listItems.forEach((listItem) => { if (listItem.classList.contains("nav-file-title")) { listItem.findAll(".fav-btn").forEach((el) => el.remove()); listItem.removeClass("fav-nav-file-title"); } else { this.removeFavoriteIconFromChild(listItem); } }); } removeFavoriteIcons() { const fileExplorer = this.getFileExplorer(); if (fileExplorer) { this.removeFavoriteIconFromChild(fileExplorer); } } reload() { this.removeFavoriteIcons(); this.addFavoriteIcons(); } onFileCreate(file) { setTimeout(() => { const listItem = this.app.workspace.containerEl.find( `[data-path="${file.path}"]` ); listItem.classList.add("fav-nav-file-title"); this.addFavoriteIconToItem(listItem); }, 100); } async onload() { this.isEnabled = true; this.app.workspace.onLayoutReady(async () => { if (import_obsidian4.Platform.isTablet || import_obsidian4.Platform.isDesktop) { setTimeout(() => { var _a; this.addFavoriteIcons(); (_a = this.getFileExplorer()) == null ? void 0 : _a.findAll(".nav-file-title").forEach((el) => { el.classList.add("fav-nav-file-title"); }); }, 300); this.app.vault.on("create", this.onFileCreate.bind(this)); this.app.vault.on("delete", this.onFileDelete.bind(this)); } }); this.plugin.addSettingTab( new FavoritePluginSettingsTab( this.app, this.plugin ) ); } destroy() { var _a; this.isEnabled = false; (_a = this.getFileExplorer()) == null ? void 0 : _a.findAll(".nav-file-title").forEach((el) => { el.classList.remove("fav-nav-file-title"); }); this.app.vault.off("create", this.onFileCreate.bind(this)); this.app.vault.off("delete", this.onFileDelete.bind(this)); this.removeFavoriteIcons(); } }; // src/variants/MobilePlugin.ts var import_obsidian5 = require("obsidian"); var MobilePlugin = class extends BasePlugin { constructor() { super(...arguments); this.onSidebarButtonClick = () => { const explorer = this.getFileExplorer(); if (!this.app.workspace.leftSplit.collapsed) { setTimeout(() => { this.addFavoriteIconToFolder(explorer); }, 50); } }; } getFileListElements(parentEl) { return parentEl.querySelectorAll(".nav-folder, .nav-file-title"); } getFileExplorer() { var _a; return (_a = this.app.workspace.getLeavesOfType("file-explorer").pop()) == null ? void 0 : _a.view.containerEl; } removeFavoriteIconFromChild(folderEl) { const listItems = this.getFileListElements(folderEl); listItems.forEach((listItem) => { if (listItem.classList.contains("nav-file-title")) { listItem.findAll(".mobile-fav-btn").forEach((el) => el.remove()); listItem.removeClass("fav-nav-file-title"); } else { this.removeFavoriteIconFromChild(listItem); } }); } createFavoriteButton(isFavorite = false) { const trailingButton = document.createElement("span"); trailingButton.classList.add("mobile-fav-btn"); if (isFavorite) { trailingButton.classList.add("is-favorite"); } else { trailingButton.classList.remove("is-favorite"); } (0, import_obsidian5.setIcon)(trailingButton, this.settings.icon); return trailingButton; } addFavoriteIconToItem(listItem) { var _a; const favButton = listItem.find(".mobile-fav-btn"); const filePath = (_a = listItem.getAttribute("data-path")) != null ? _a : ""; const favorite = this.isFavorite(filePath); if (favButton) { if (favorite) { favButton.classList.add("is-favorite"); } else { favButton.classList.remove("is-favorite"); } return; } listItem.addClass("fav-nav-file-title"); const trailingButton = this.createFavoriteButton(favorite); listItem.appendChild(trailingButton); } addFavoriteIconToFolder(folderEl) { const listItems = this.getFileListElements(folderEl); listItems.forEach((listItem) => { if (listItem.classList.contains("nav-file-title")) { this.addFavoriteIconToItem(listItem); } else { this.addFavoriteIconToFolder(listItem); } }); } getHeaderFavoriteActionButton() { const itemView = this.app.workspace.getActiveViewOfType(import_obsidian5.ItemView); return itemView == null ? void 0 : itemView.containerEl.querySelector( '.clickable-icon.view-action[aria-label="Favorite"]' ); } itemViewAlreadyHasButton() { return this.getHeaderFavoriteActionButton() != null; } getSidebarToggleButton() { var _a, _b, _c; if (import_obsidian5.Platform.isTablet) { return (_a = this.app.workspace.containerEl) == null ? void 0 : _a.querySelector( ".sidebar-toggle-button" ); } return (_c = (_b = this.app.workspace.getActiveViewOfType(import_obsidian5.ItemView)) == null ? void 0 : _b.containerEl) == null ? void 0 : _c.querySelector( 'button[aria-label="Expand"]' ); } registerSidebarToggleEvents() { const btn = this.getSidebarToggleButton(); btn == null ? void 0 : btn.addEventListener("click", this.onSidebarButtonClick); } deregisterSidebarToggleEvents() { const btn = this.getSidebarToggleButton(); btn == null ? void 0 : btn.removeEventListener("click", this.onSidebarButtonClick); } updateHeaderButtonState() { var _a; const filePath = (_a = this.app.workspace.getActiveFile()) == null ? void 0 : _a.path; const btn = this.getHeaderFavoriteActionButton(); if (this.isFavorite(filePath)) { btn == null ? void 0 : btn.classList.remove("mobile-header-fav-idle"); btn == null ? void 0 : btn.classList.add("is-favorite"); } else { btn == null ? void 0 : btn.classList.remove("is-favorite"); btn == null ? void 0 : btn.classList.add("mobile-header-fav-idle"); } } onHeaderButtonClick() { var _a; const filePath = (_a = this.app.workspace.getActiveFile()) == null ? void 0 : _a.path; if (!filePath) { return; } this.toggleFavorite(filePath); this.updateHeaderButtonState(); } addFavoriteButtonToHeader() { var _a; const filePath = (_a = this.app.workspace.getActiveFile()) == null ? void 0 : _a.path; if (!filePath) { return; } const itemView = this.app.workspace.getActiveViewOfType(import_obsidian5.ItemView); const action = itemView == null ? void 0 : itemView.addAction( this.settings.icon, "Favorite", this.onHeaderButtonClick.bind(this) ); action == null ? void 0 : action.classList.add( this.isFavorite(filePath) ? "is-favorite" : "mobile-header-fav-idle" ); } onload() { this.app.workspace.on("window-open", () => { console.log("open"); }); this.app.workspace.onLayoutReady(() => { setTimeout(() => { this.addFavoriteButtonToHeader(); this.registerSidebarToggleEvents(); this.onSidebarButtonClick(); }, 100); this.plugin.registerEvent( this.app.workspace.on("active-leaf-change", (leaf) => { if (!this.itemViewAlreadyHasButton()) { this.addFavoriteButtonToHeader(); } this.updateHeaderButtonState(); }) ); this.plugin.registerEvent( this.app.vault.on("delete", this.onFileDelete.bind(this)) ); }); } reload() { } destroy() { var _a, _b; this.isEnabled = false; (_a = this.getHeaderFavoriteActionButton()) == null ? void 0 : _a.remove(); this.deregisterSidebarToggleEvents(); (_b = this.getFileExplorer()) == null ? void 0 : _b.findAll(".nav-file-title").forEach((el) => { el.classList.remove("fav-nav-file-title"); el.find(".mobile-fav-btn").remove(); }); } }; // src/main.ts var FavoritePlugin = class extends import_obsidian6.Plugin { constructor(app, manifest) { super(app, manifest); if (import_obsidian6.Platform.isDesktop) { this.variant = new DesktopPlugin(this, this.app); } if (import_obsidian6.Platform.isMobile) { this.variant = new MobilePlugin(this, this.app); } } onload() { var _a; (_a = this.variant) == null ? void 0 : _a.onload(); } onunload() { var _a; (_a = this.variant) == null ? void 0 : _a.destroy(); } }; /* nosourcemap */