/* 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); // main.ts var main_exports = {}; __export(main_exports, { default: () => HideFoldersPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian = require("obsidian"); var DEFAULT_SETTINGS = { areFoldersHidden: true, matchCaseInsensitive: true, attachmentFolderNames: ["attachments"] }; var HideFoldersPlugin = class extends import_obsidian.Plugin { async processFolders(recheckPreviouslyHiddenFolders) { if (this.settings.attachmentFolderNames.length === 0) return; if (recheckPreviouslyHiddenFolders) { document.querySelectorAll(".obsidian-hide-folders--hidden").forEach((folder) => { folder.parentElement.style.height = ""; folder.parentElement.style.overflow = ""; folder.removeClass("obsidian-hide-folders--hidden"); }); } this.settings.attachmentFolderNames.forEach((folderName) => { if (this.getFolderNameWithoutPrefix(folderName) === "") return; const folderElements = document.querySelectorAll(this.getQuerySelectorStringForFolderName(folderName)); folderElements.forEach((folder) => { if (!folder || !folder.parentElement) { return; } folder.addClass("obsidian-hide-folders--hidden"); folder.parentElement.style.height = this.settings.areFoldersHidden ? "0" : ""; folder.parentElement.style.overflow = this.settings.areFoldersHidden ? "hidden" : ""; }); }); } getFolderNameWithoutPrefix(folderName) { if (folderName.toLowerCase().startsWith("endswith::")) { return folderName.substring("endsWith::".length).trim(); } else if (folderName.toLowerCase().startsWith("startswith::")) { return folderName.substring("startsWith::".length).trim(); } else { return folderName; } } getQuerySelectorStringForFolderName(folderName) { if (folderName.toLowerCase().startsWith("endswith::")) { return `[data-path$="${this.getFolderNameWithoutPrefix(folderName)}"${this.settings.matchCaseInsensitive ? " i" : ""}]`; } else if (folderName.toLowerCase().startsWith("startswith::")) { return `.nav-folder-title[data-path^="${this.getFolderNameWithoutPrefix(folderName)}"${this.settings.matchCaseInsensitive ? " i" : ""}], .nav-folder-title[data-path*="/${this.getFolderNameWithoutPrefix(folderName)}"${this.settings.matchCaseInsensitive ? " i" : ""}]`; } else { return `[data-path$="/${folderName.trim()}"${this.settings.matchCaseInsensitive ? " i" : ""}], [data-path="${folderName.trim()}"${this.settings.matchCaseInsensitive ? " i" : ""}]`; } } async toggleFunctionality() { this.settings.areFoldersHidden = !this.settings.areFoldersHidden; this.ribbonIconButton.ariaLabel = this.settings.areFoldersHidden ? "Show hidden folders" : "Hide hidden folders again"; (0, import_obsidian.setIcon)(this.ribbonIconButton, this.settings.areFoldersHidden ? "eye" : "eye-off"); this.statusBarItem.innerHTML = this.settings.areFoldersHidden ? "Configured folders are hidden" : ""; await this.processFolders(); } async onload() { console.log("loading plugin hide-folders"); await this.loadSettings(); this.ribbonIconButton = this.addRibbonIcon(this.settings.areFoldersHidden ? "eye" : "eye-off", this.settings.areFoldersHidden ? "Show hidden folders" : "Hide hidden folders again", (evt) => { this.toggleFunctionality(); }); this.statusBarItem = this.addStatusBarItem(); this.statusBarItem.setText(this.settings.areFoldersHidden ? "Attachment folders are hidden" : ""); this.addCommand({ id: "toggle-attachment-folders", name: "Toggle visibility of hidden folders", callback: () => { this.toggleFunctionality(); } }); this.addSettingTab(new HideFoldersPluginSettingTab(this.app, this)); this.mutationObserver = new MutationObserver((mutationRecord) => { mutationRecord.forEach((record) => { var _a, _b; if ((_b = (_a = record.target) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.classList.contains("nav-folder")) { this.processFolders(); } }); }); this.mutationObserver.observe(window.document, { childList: true, subtree: true }); this.registerEvent(this.app.vault.on("rename", () => { window.setTimeout(() => { this.processFolders(); }, 10); })); } onunload() { this.mutationObserver.disconnect(); } async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); } async saveSettings() { await this.saveData(this.settings); await this.processFolders(true); } }; var HideFoldersPluginSettingTab = class extends import_obsidian.PluginSettingTab { constructor(app, plugin) { super(app, plugin); this.plugin = plugin; } display() { const { containerEl } = this; containerEl.empty(); new import_obsidian.Setting(containerEl).setName("Folders to hide").setDesc("The names of the folders to hide, one per line. Either exact folder-names, startsWith::FOLDERPREFIX, or endsWith::FOLDERSUFFIX").addTextArea((text) => text.setPlaceholder("attachments\nendsWith::_attachments").setValue(this.plugin.settings.attachmentFolderNames.join("\n")).onChange(async (value) => { this.plugin.settings.attachmentFolderNames = value.split("\n"); await this.plugin.saveSettings(); })); new import_obsidian.Setting(containerEl).setName("Ignore Upper/lowercase").setDesc("If enabled, 'SOMEFOLDER', 'someFolder', or 'sOmeFoldEr' will all be treated the same and matched.").addToggle((toggle) => toggle.setValue(this.plugin.settings.matchCaseInsensitive).onChange(async (value) => { this.plugin.settings.matchCaseInsensitive = value; await this.plugin.saveSettings(); })); new import_obsidian.Setting(containerEl).setName("Hide folders").setDesc("If the configured folders should be hidden or not").addToggle((toggle) => toggle.setValue(this.plugin.settings.areFoldersHidden).onChange(async (value) => { this.plugin.settings.areFoldersHidden = value; await this.plugin.saveSettings(); })); new import_obsidian.Setting(containerEl).setName("GitHub").setDesc("Report Issues or Ideas, see the Source Code and Contribute.").addButton((button) => button.buttonEl.innerHTML = 'obsidian-hide-folders'); } };