main.js
  1  /*
  2  THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
  3  if you want to view the source, please visit the github repository of this plugin
  4  */
  5  
  6  var __create = Object.create;
  7  var __defProp = Object.defineProperty;
  8  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  9  var __getOwnPropNames = Object.getOwnPropertyNames;
 10  var __getProtoOf = Object.getPrototypeOf;
 11  var __hasOwnProp = Object.prototype.hasOwnProperty;
 12  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
 13  var __export = (target, all) => {
 14    __markAsModule(target);
 15    for (var name in all)
 16      __defProp(target, name, { get: all[name], enumerable: true });
 17  };
 18  var __reExport = (target, module2, desc) => {
 19    if (module2 && typeof module2 === "object" || typeof module2 === "function") {
 20      for (let key of __getOwnPropNames(module2))
 21        if (!__hasOwnProp.call(target, key) && key !== "default")
 22          __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
 23    }
 24    return target;
 25  };
 26  var __toModule = (module2) => {
 27    return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
 28  };
 29  var __async = (__this, __arguments, generator) => {
 30    return new Promise((resolve, reject) => {
 31      var fulfilled = (value) => {
 32        try {
 33          step(generator.next(value));
 34        } catch (e) {
 35          reject(e);
 36        }
 37      };
 38      var rejected = (value) => {
 39        try {
 40          step(generator.throw(value));
 41        } catch (e) {
 42          reject(e);
 43        }
 44      };
 45      var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
 46      step((generator = generator.apply(__this, __arguments)).next());
 47    });
 48  };
 49  
 50  // src/main.ts
 51  __export(exports, {
 52    default: () => FileHider
 53  });
 54  
 55  // src/commands/toggleVisibility.ts
 56  var VisibilityToggleCommand = class {
 57    constructor(plugin) {
 58      plugin.addCommand({
 59        id: "oa-fh-toggle-visibility",
 60        name: "Toggle Visibility",
 61        callback: () => {
 62          plugin.toggleVisibility();
 63        }
 64      });
 65    }
 66  };
 67  
 68  // src/settings/hiddenToggle.ts
 69  var import_obsidian = __toModule(require("obsidian"));
 70  var VisibilityToggleSetting = class {
 71    static create(plugin, container) {
 72      return new import_obsidian.Setting(container).setName(`Hidden File Visibility`).setDesc(`Toggle whether or not files and folders that are told to be hidden will be hidden or not.`).addToggle((toggle) => {
 73        toggle.setValue(!plugin.settings.hidden).onChange(() => {
 74          plugin.toggleVisibility();
 75        });
 76      });
 77    }
 78  };
 79  
 80  // src/main.ts
 81  var import_obsidian4 = __toModule(require("obsidian"));
 82  
 83  // src/settings/manageHiddenPaths.ts
 84  var import_obsidian3 = __toModule(require("obsidian"));
 85  
 86  // src/modals/HiddenList.ts
 87  var import_obsidian2 = __toModule(require("obsidian"));
 88  var HiddenPathsModal = class extends import_obsidian2.Modal {
 89    constructor(plugin) {
 90      super(plugin.app);
 91      this.plugin = plugin;
 92    }
 93    onOpen() {
 94      const { contentEl: content } = this;
 95      content.createEl(`h1`, { text: `Hidden Files and Folders` });
 96      content.createEl(`hr`);
 97      let body = content.createEl(`div`, { cls: `hidden-list-modal-body` });
 98      this.plugin.settings.hiddenList.forEach((path) => {
 99        let c = body.createEl(`div`);
100        new import_obsidian2.Setting(c).setName(path).addButton((btn) => {
101          btn.setIcon(`cross`).setTooltip(`Remove`).onClick((e) => {
102            this.plugin.unhidePath(path);
103            c.hide();
104          });
105        });
106      });
107    }
108    onClose() {
109      const { contentEl } = this;
110      contentEl.empty();
111    }
112  };
113  
114  // src/settings/manageHiddenPaths.ts
115  var ManageHiddenPaths = class {
116    static create(plugin, container) {
117      return new import_obsidian3.Setting(container).setName(`Hidden Files and Folders`).setDesc(`Add or remove files and folders from the list that are being hidden`).addButton((b) => {
118        b.setButtonText(`Manage`).onClick((event) => {
119          if (!event.isTrusted) {
120            return;
121          }
122          new HiddenPathsModal(plugin).open();
123        });
124      });
125    }
126  };
127  
128  // src/utils.ts
129  function changePathVisibility(path, hide) {
130    let n = document.querySelector(`[data-path="${path}"]`);
131    if (!n) {
132      return;
133    }
134    ;
135    let p = n.parentElement;
136    if (hide) {
137      p.style.display = `none`;
138    } else {
139      p.style.display = ``;
140    }
141    ;
142  }
143  
144  // src/main.ts
145  var FileHider = class extends import_obsidian4.Plugin {
146    constructor() {
147      super(...arguments);
148      this.settings = {
149        hidden: true,
150        hiddenList: []
151      };
152      this.style = null;
153    }
154    onload() {
155      return __async(this, null, function* () {
156        yield this.loadSettings();
157        this.registerEvent(this.app.workspace.on(`file-menu`, (menu, file) => {
158          if (file instanceof import_obsidian4.TFolder) {
159            menu.addItem((i) => {
160              if (this.settings.hiddenList.includes(file.path)) {
161                i.setTitle(`Unhide Folder`).setIcon(`eye`).onClick(() => {
162                  this.unhidePath(file.path);
163                });
164              } else {
165                i.setTitle(`Hide Folder`).setIcon(`eye-off`).onClick(() => {
166                  changePathVisibility(file.path, this.settings.hidden);
167                  this.settings.hiddenList.push(file.path);
168                  this.saveSettings();
169                });
170              }
171              ;
172            });
173          } else {
174            menu.addItem((i) => {
175              if (this.settings.hiddenList.includes(file.path)) {
176                i.setTitle(`Unhide File`).setIcon(`eye`).onClick((e) => {
177                  this.unhidePath(file.path);
178                });
179              } else {
180                i.setTitle(`Hide File`).setIcon(`eye-off`).onClick((e) => {
181                  changePathVisibility(file.path, this.settings.hidden);
182                  this.settings.hiddenList.push(file.path);
183                  this.saveSettings();
184                });
185              }
186              ;
187            });
188          }
189          ;
190        }));
191        this.app.workspace.onLayoutReady(() => {
192          setTimeout(() => {
193            for (const path of this.settings.hiddenList) {
194              changePathVisibility(path, this.settings.hidden);
195            }
196            ;
197          }, 200);
198        });
199        new VisibilityToggleCommand(this);
200        this.addSettingTab(new FileHiderSettingsTab(this.app, this));
201      });
202    }
203    loadSettings() {
204      return __async(this, null, function* () {
205        this.settings = Object.assign({}, this.settings, yield this.loadData());
206      });
207    }
208    saveSettings() {
209      return __async(this, null, function* () {
210        yield this.saveData(this.settings);
211      });
212    }
213    toggleVisibility() {
214      this.settings.hidden = !this.settings.hidden;
215      for (const path of this.settings.hiddenList) {
216        changePathVisibility(path, this.settings.hidden);
217      }
218      ;
219      this.saveSettings();
220    }
221    unhidePath(path) {
222      let i = this.settings.hiddenList.indexOf(path);
223      this.settings.hiddenList.splice(i, 1);
224      changePathVisibility(path, false);
225      this.saveSettings();
226    }
227  };
228  var FileHiderSettingsTab = class extends import_obsidian4.PluginSettingTab {
229    constructor(app, plugin) {
230      super(app, plugin);
231      this.plugin = plugin;
232    }
233    display() {
234      const { containerEl: container } = this;
235      container.empty();
236      VisibilityToggleSetting.create(this.plugin, container);
237      ManageHiddenPaths.create(this.plugin, container);
238    }
239  };