/* 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); var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; // main.ts var main_exports = {}; __export(main_exports, { default: () => FileIndexPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian = require("obsidian"); var _reloadIgnoreRegExpsIfIgnoreFileChangedBinding, _recreateFileIndexBinding; var _FileIndexPlugin = class extends import_obsidian.Plugin { constructor() { super(...arguments); this.ignoreRegExps = []; __privateAdd(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding, this.reloadIgnoreRegExpsIfIgnoreFileChanged.bind(this)); __privateAdd(this, _recreateFileIndexBinding, this.recreateFileIndex.bind(this)); } async reloadIgnoreRegExps() { const ignoreFile = this.app.vault.getAbstractFileByPath(_FileIndexPlugin.FILE_IGNORE_PATH); if (ignoreFile === null) { console.debug("[FileIndexPlugin] Ignore file does not exist, not ignoring anything:", _FileIndexPlugin.FILE_IGNORE_PATH); this.ignoreRegExps = []; } else if (ignoreFile instanceof import_obsidian.TFolder) { console.debug("[FileIndexPlugin] Ignore file is actually a folder, not ignoring anything:", _FileIndexPlugin.FILE_IGNORE_PATH); this.ignoreRegExps = []; } else if (ignoreFile instanceof import_obsidian.TFile) { const ignoreJSON = await this.app.vault.cachedRead(ignoreFile); const ignoreContents = JSON.parse(ignoreJSON); this.ignoreRegExps = ignoreContents.map((re) => new RegExp(re)); console.debug("[FileIndexPlugin] Determined ignore list to be:", this.ignoreRegExps); } else { console.error("[FileIndexPlugin] Ignore file is of an unknown type, not doing anything:", _FileIndexPlugin.FILE_IGNORE_PATH); } } async reloadIgnoreRegExpsIfIgnoreFileChanged(file) { if (file.path === _FileIndexPlugin.FILE_IGNORE_PATH) { await this.reloadIgnoreRegExps(); } } async recreateFileIndex() { const files = this.app.vault.getFiles(); const basenames = {}; const paths = []; for (const file of files) { let ignored = false; for (const regexp of this.ignoreRegExps) { if (file.path.match(regexp)) { ignored = true; break; } } if (ignored) { continue; } paths.push(file.path); let basename; if (file.extension === "md") { basename = file.basename.toLocaleLowerCase(); } else { basename = file.basename.toLocaleLowerCase() + "." + file.extension.toLocaleLowerCase(); } if (basenames.hasOwnProperty(basename)) { console.warn("[FileIndexPlugin] Multiple files with the same basename detected:", basenames[basename], file.path); } basenames[basename] = file.path; } paths.sort(); const index = { basenames, paths }; console.debug("[FileIndexPlugin] Determined index to be:", index); const indexContents = JSON.stringify(index, null, " "); const indexFile = this.app.vault.getAbstractFileByPath(_FileIndexPlugin.FILE_INDEX_PATH); if (indexFile === null) { console.debug("[FileIndexPlugin] File index does not exist, creating it right now at:", _FileIndexPlugin.FILE_INDEX_PATH); await this.app.vault.create(_FileIndexPlugin.FILE_INDEX_PATH, indexContents); } else if (indexFile instanceof import_obsidian.TFolder) { console.debug("[FileIndexPlugin] Cannot create file index, as there's a folder at:", _FileIndexPlugin.FILE_INDEX_PATH); } else if (indexFile instanceof import_obsidian.TFile) { console.debug("[FileIndexPlugin] File index already exists, overwriting contents of:", _FileIndexPlugin.FILE_INDEX_PATH); await this.app.vault.modify(indexFile, indexContents); } else { console.error("[FileIndexPlugin] File index is of an unknown type, not doing anything:", _FileIndexPlugin.FILE_INDEX_PATH); } } async onload() { this.addCommand({ id: "recreate", name: "Force file index recreation", callback: this.recreateFileIndex.bind(this) }); this.app.workspace.onLayoutReady(async () => { await this.reloadIgnoreRegExps(); await this.recreateFileIndex(); this.registerEvent( this.app.vault.on("create", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding)) ); this.registerEvent( this.app.vault.on("delete", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding)) ); this.registerEvent( this.app.vault.on("rename", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding)) ); this.registerEvent( this.app.vault.on("create", __privateGet(this, _recreateFileIndexBinding)) ); this.registerEvent( this.app.vault.on("delete", __privateGet(this, _recreateFileIndexBinding)) ); this.registerEvent( this.app.vault.on("rename", __privateGet(this, _recreateFileIndexBinding)) ); }); } onunload() { } }; var FileIndexPlugin = _FileIndexPlugin; _reloadIgnoreRegExpsIfIgnoreFileChangedBinding = new WeakMap(); _recreateFileIndexBinding = new WeakMap(); FileIndexPlugin.FILE_IGNORE_PATH = "file-index-ignore.json"; FileIndexPlugin.FILE_INDEX_PATH = "file-index.json";