From 4e8f100fb047b4efa0da343254ab0da68aae44b9 Mon Sep 17 00:00:00 2001 From: iLiftALot Date: Wed, 13 Nov 2024 01:29:15 -0500 Subject: [PATCH] Working on workflow... --- esbuild.config.mjs | 29 ++-- main.js | 420 +-------------------------------------------- package.json | 4 +- 3 files changed, 23 insertions(+), 430 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 6dc3332..640c536 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -152,24 +152,25 @@ const context = await esbuild.context({ process.exit(1); }) -try { - //symlinkSync(sourcePath, targetPath); - //logs.push(`Symlink created: ${targetPath} -> ${sourcePath}`); - - // Copy the file instead of creating a symlink - copyFileSync(sourcePath, targetPath); - logs.push(`Copied file: ${sourcePath} -> ${targetPath}`); -} catch (error) { - console.error(`Error creating symlink: ${error}\nLogs:\n${logs.join('\n')}`); - process.exit(1); +function copyMainJs() { + try { + // Copy the file instead of creating a symlink + copyFileSync(sourcePath, targetPath); + logs.push(`Copied file: ${sourcePath} -> ${targetPath}`); + + logs = logs.join('\n'); + if (shouldLog) console.log(logs); + } catch (error) { + console.error(`Error creating symlink: ${error}\nLogs:\n${logs.join('\n')}`); + process.exit(1); + } } -logs = logs.join('\n'); -if (shouldLog) console.log(logs); - if (prod) { await context.rebuild(); - process.exit(0); + copyMainJs(); + await context.dispose(); } else { + copyMainJs(); await context.watch(); } diff --git a/main.js b/main.js index 8aca44d..f5f07c0 100644 --- a/main.js +++ b/main.js @@ -3,417 +3,9 @@ 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: () => InstaTocPlugin -}); -module.exports = __toCommonJS(main_exports); - -// -var define_Process_env_default = { envPath: "/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.env", pluginRoot: "/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc", pluginManifest: { id: "insta-toc", name: "Insta TOC", version: "2.0.2", minAppVersion: "0.15.0", description: "Simultaneously generate, update, and maintain a table of contents for your notes.", author: "Nick C.", autherUrl: "https://github.com/iLiftALot/insta-toc", isDesktopOnly: false }, pluginSettingsPath: "/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc/data.json", pluginSettings: {}, projectRoot: "/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc", vaultRoot: "/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync", vaultName: "My Sync" }; - -// src/main.ts -var import_obsidian2 = require("obsidian"); - -// src/Settings.ts -var DEFAULT_SETTINGS = { - tocString: `> [!SUMMARY] Table of Contents`, - shouldGenToc: false -}; - -// src/SettingsTab.ts -var import_obsidian = require("obsidian"); -var SettingTab = 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("Setting #1").setDesc("It's a secret").addText((text) => text.setPlaceholder("Enter your secret").setValue(this.plugin.settings.tocString).onChange(async (value) => { - this.plugin.settings.tocString = value; - await this.plugin.saveSettings(); - })); - new import_obsidian.Setting(containerEl).setName("TOC Files").setDesc("Insert files to automatically ").addText((text) => text.setPlaceholder("Enter your secret").setValue(this.plugin.settings.tocString).onChange(async (value) => { - this.plugin.settings.tocString = value; - await this.plugin.saveSettings(); - })); - } -}; - -// node_modules/deepmerge-ts/dist/index.mjs -var actions = { - defaultMerge: Symbol("deepmerge-ts: default merge"), - skip: Symbol("deepmerge-ts: skip") -}; -var actionsInto = { - defaultMerge: actions.defaultMerge -}; -function defaultMetaDataUpdater(previousMeta, metaMeta) { - return metaMeta; -} -function defaultFilterValues(values, meta) { - return values.filter((value) => value !== void 0); -} -var ObjectType; -(function(ObjectType2) { - ObjectType2[ObjectType2["NOT"] = 0] = "NOT"; - ObjectType2[ObjectType2["RECORD"] = 1] = "RECORD"; - ObjectType2[ObjectType2["ARRAY"] = 2] = "ARRAY"; - ObjectType2[ObjectType2["SET"] = 3] = "SET"; - ObjectType2[ObjectType2["MAP"] = 4] = "MAP"; - ObjectType2[ObjectType2["OTHER"] = 5] = "OTHER"; -})(ObjectType || (ObjectType = {})); -function getObjectType(object) { - if (typeof object !== "object" || object === null) { - return 0; - } - if (Array.isArray(object)) { - return 2; - } - if (isRecord(object)) { - return 1; - } - if (object instanceof Set) { - return 3; - } - if (object instanceof Map) { - return 4; - } - return 5; -} -function getKeys(objects) { - const keys = /* @__PURE__ */ new Set(); - for (const object of objects) { - for (const key of [...Object.keys(object), ...Object.getOwnPropertySymbols(object)]) { - keys.add(key); - } - } - return keys; -} -function objectHasProperty(object, property) { - return typeof object === "object" && Object.prototype.propertyIsEnumerable.call(object, property); -} -function getIterableOfIterables(iterables) { - let m_iterablesIndex = 0; - let m_iterator = iterables[0]?.[Symbol.iterator](); - return { - [Symbol.iterator]() { - return { - next() { - do { - if (m_iterator === void 0) { - return { done: true, value: void 0 }; - } - const result = m_iterator.next(); - if (result.done === true) { - m_iterablesIndex += 1; - m_iterator = iterables[m_iterablesIndex]?.[Symbol.iterator](); - continue; - } - return { - done: false, - value: result.value - }; - } while (true); - } - }; - } - }; -} -var validRecordToStringValues = ["[object Object]", "[object Module]"]; -function isRecord(value) { - if (!validRecordToStringValues.includes(Object.prototype.toString.call(value))) { - return false; - } - const { constructor } = value; - if (constructor === void 0) { - return true; - } - const prototype = constructor.prototype; - if (prototype === null || typeof prototype !== "object" || !validRecordToStringValues.includes(Object.prototype.toString.call(prototype))) { - return false; - } - if (!prototype.hasOwnProperty("isPrototypeOf")) { - return false; - } - return true; -} -function mergeRecords$1(values, utils, meta) { - const result = {}; - for (const key of getKeys(values)) { - const propValues = []; - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - if (propValues.length === 0) { - continue; - } - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values - }); - const propertyResult = mergeUnknowns(propValues, utils, updatedMeta); - if (propertyResult === actions.skip) { - continue; - } - if (key === "__proto__") { - Object.defineProperty(result, key, { - value: propertyResult, - configurable: true, - enumerable: true, - writable: true - }); - } else { - result[key] = propertyResult; - } - } - return result; -} -function mergeArrays$1(values) { - return values.flat(); -} -function mergeSets$1(values) { - return new Set(getIterableOfIterables(values)); -} -function mergeMaps$1(values) { - return new Map(getIterableOfIterables(values)); -} -function mergeOthers$1(values) { - return values.at(-1); -} -var mergeFunctions = { - mergeRecords: mergeRecords$1, - mergeArrays: mergeArrays$1, - mergeSets: mergeSets$1, - mergeMaps: mergeMaps$1, - mergeOthers: mergeOthers$1 -}; -function deepmerge(...objects) { - return deepmergeCustom({})(...objects); -} -function deepmergeCustom(options, rootMetaData) { - const utils = getUtils(options, customizedDeepmerge); - function customizedDeepmerge(...objects) { - return mergeUnknowns(objects, utils, rootMetaData); - } - return customizedDeepmerge; -} -function getUtils(options, customizedDeepmerge) { - return { - defaultMergeFunctions: mergeFunctions, - mergeFunctions: { - ...mergeFunctions, - ...Object.fromEntries(Object.entries(options).filter(([key, option]) => Object.hasOwn(mergeFunctions, key)).map(([key, option]) => option === false ? [key, mergeFunctions.mergeOthers] : [key, option])) - }, - metaDataUpdater: options.metaDataUpdater ?? defaultMetaDataUpdater, - deepmerge: customizedDeepmerge, - useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false, - filterValues: options.filterValues === false ? void 0 : options.filterValues ?? defaultFilterValues, - actions - }; -} -function mergeUnknowns(values, utils, meta) { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - if (filteredValues.length === 0) { - return void 0; - } - if (filteredValues.length === 1) { - return mergeOthers(filteredValues, utils, meta); - } - const type = getObjectType(filteredValues[0]); - if (type !== 0 && type !== 5) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - return mergeOthers(filteredValues, utils, meta); - } - } - switch (type) { - case 1: { - return mergeRecords(filteredValues, utils, meta); - } - case 2: { - return mergeArrays(filteredValues, utils, meta); - } - case 3: { - return mergeSets(filteredValues, utils, meta); - } - case 4: { - return mergeMaps(filteredValues, utils, meta); - } - default: { - return mergeOthers(filteredValues, utils, meta); - } - } -} -function mergeRecords(values, utils, meta) { - const result = utils.mergeFunctions.mergeRecords(values, utils, meta); - if (result === actions.defaultMerge || utils.useImplicitDefaultMerging && result === void 0 && utils.mergeFunctions.mergeRecords !== utils.defaultMergeFunctions.mergeRecords) { - return utils.defaultMergeFunctions.mergeRecords(values, utils, meta); - } - return result; -} -function mergeArrays(values, utils, meta) { - const result = utils.mergeFunctions.mergeArrays(values, utils, meta); - if (result === actions.defaultMerge || utils.useImplicitDefaultMerging && result === void 0 && utils.mergeFunctions.mergeArrays !== utils.defaultMergeFunctions.mergeArrays) { - return utils.defaultMergeFunctions.mergeArrays(values); - } - return result; -} -function mergeSets(values, utils, meta) { - const result = utils.mergeFunctions.mergeSets(values, utils, meta); - if (result === actions.defaultMerge || utils.useImplicitDefaultMerging && result === void 0 && utils.mergeFunctions.mergeSets !== utils.defaultMergeFunctions.mergeSets) { - return utils.defaultMergeFunctions.mergeSets(values); - } - return result; -} -function mergeMaps(values, utils, meta) { - const result = utils.mergeFunctions.mergeMaps(values, utils, meta); - if (result === actions.defaultMerge || utils.useImplicitDefaultMerging && result === void 0 && utils.mergeFunctions.mergeMaps !== utils.defaultMergeFunctions.mergeMaps) { - return utils.defaultMergeFunctions.mergeMaps(values); - } - return result; -} -function mergeOthers(values, utils, meta) { - const result = utils.mergeFunctions.mergeOthers(values, utils, meta); - if (result === actions.defaultMerge || utils.useImplicitDefaultMerging && result === void 0 && utils.mergeFunctions.mergeOthers !== utils.defaultMergeFunctions.mergeOthers) { - return utils.defaultMergeFunctions.mergeOthers(values); - } - return result; -} - -// typings/Utility.js -function debounce(func, wait) { - let timeout = null; - return function(...args) { - if (timeout !== null) { - clearTimeout(timeout); - } - timeout = window.setTimeout(() => { - func.apply(this, args); - timeout = null; - }, wait); - }; -} - -// src/main.ts -var InstaTocPlugin = class extends import_obsidian2.Plugin { - constructor(app, manifest) { - const mainManifest = manifest ?? define_Process_env_default.pluginManifest; - super(app, mainManifest); - this.app = app; - } - async onload() { - console.log("Loading Insta TOC Plugin"); - await this.loadSettings(); - this.addSettingTab(new SettingTab(this.app, this)); - this.registerMarkdownCodeBlockProcessor( - "insta-toc", - async (source, el, ctx) => { - const pathWithFileExtension = ctx.sourcePath; - const filePath = pathWithFileExtension.substring(0, pathWithFileExtension.lastIndexOf(".")); - const listRegex = /^(\s*)-\s*(.*)/; - const lines = source.split("\n"); - const processedSource = lines.map((line) => { - const match = line.match(listRegex); - if (!match) return line; - const [, indent, contentText] = match; - const navLink = `${filePath}#${contentText}`; - return `${indent}- [[${navLink}|${contentText}]]`; - }).join("\n"); - await import_obsidian2.MarkdownRenderer.render(this.app, processedSource, el, pathWithFileExtension, this); - } - ); - this.registerEvent( - this.app.vault.on( - "modify", - debounce(this.handleEditorChange.bind(this), 2e3) - ) - ); - } - onunload() { - console.log("Unloading Insta TOC Plugin"); - } - async loadSettings() { - let mergedSettings = DEFAULT_SETTINGS; - const settingsData = await this.loadData(); - if (settingsData) { - mergedSettings = deepmerge(DEFAULT_SETTINGS, settingsData); - } - this.settings = mergedSettings; - } - async saveSettings() { - await this.saveData(this.settings); - } - // Provides the insert location range for the new insta-toc codeblock - getTocInsertPosition(instaTocSection) { - const startLine = instaTocSection.position.start.line; - const startCh = 0; - const endLine = instaTocSection.position.end.line; - const endCh = instaTocSection.position.end.col; - const tocStartPos = { line: startLine, ch: startCh }; - const tocEndPos = { line: endLine, ch: endCh }; - return { from: tocStartPos, to: tocEndPos }; - } - // Generates a new insta-toc codeblock - generateToc(fileHeadings) { - const tocHeadingRefs = []; - if (fileHeadings.length > 0) { - fileHeadings.forEach((headingCache) => { - const headingLevel = headingCache.level; - const headingText = headingCache.heading; - const tocHeadingRef = `${" ".repeat((headingLevel - 1) * 4)}- ${headingText}`; - tocHeadingRefs.push(tocHeadingRef); - }); - } - const tocContent = tocHeadingRefs.join("\n"); - return `\`\`\`insta-toc -${tocContent} -\`\`\``; - } - // Dynamically update the TOC - updateAutoToc(editor, file) { - const fileCache = this.app.metadataCache.getFileCache(file); - const fileHeadings = fileCache?.headings ?? []; - const instaTocSection = fileCache?.sections ? fileCache.sections.find( - (section) => section.type === "code" && editor.getLine(section.position.start.line) === "```insta-toc" - ) : void 0; - if (!instaTocSection) return; - const tocInsertRange = this.getTocInsertPosition(instaTocSection); - const newTocBlock = this.generateToc(fileHeadings); - editor.replaceRange(newTocBlock, tocInsertRange.from, tocInsertRange.to); - } - // Main control method to handle all active file changes - async handleEditorChange() { - const activeEditor = this.app.workspace.activeEditor; - const editor = activeEditor?.editor; - const file = activeEditor?.file ?? void 0; - if (!activeEditor || !editor || !file) return; - if (editor) this.updateAutoToc(editor, file); - } -}; -//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL21haW4udHMiLCAiPGRlZmluZTpQcm9jZXNzLmVudj4iLCAiLi4vLi4vc3JjL1NldHRpbmdzLnRzIiwgIi4uLy4uL3NyYy9TZXR0aW5nc1RhYi50cyIsICI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mVyRWwuZW1wdHkoKTtcblxuICAgICAgICBuZXcgU2V0dGluZyhjb250YWluZXJFbClcbiAgICAgICAgICAgIC5zZXROYW1lKCdTZXR0aW5nICMxJylcbiAgICAgICAgICAgIC5zZXREZXNjKCdJdFxcJ3MgYSBzZWNyZXQnKVxuICAgICAgICAgICAgLmFkZFRleHQodGV4dCA9PiB0ZXh0XG4gICAgICAgICAgICAgICAgLnNldFBsYWNlaG9sZGVyKCdFbnRlciB5b3VyIHNlY3JldCcpXG4gICAgICAgICAgICAgICAgLnNldFZhbHVlKHRoaXMucGx1Z2luLnNldHRpbmdzLnRvY1N0cmluZylcbiAgICAgICAgICAgICAgICAub25DaGFuZ2UoYXN5bmMgKHZhbHVlKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMucGx1Z2luLnNldHRpbmdzLnRvY1N0cmluZyA9IHZhbHVlO1xuICAgICAgICAgICAgICAgICAgICBhd2FpdCB0aGlzLnBsdWdpbi5zYXZlU2V0dGluZ3MoKTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgIG5ldyBTZXR0aW5nKGNvbnRhaW5lckVsKVxuICAgICAgICAgICAgLnNldE5hbWUoJ1RPQyBGaWxlcycpXG4gICAgICAgICAgICAuc2V0RGVzYygnSW5zZXJ0IGZpbGVzIHRvIGF1dG9tYXRpY2FsbHkgJylcbiAgICAgICAgICAgIC5hZGRUZXh0KHRleHQgPT4gdGV4dFxuICAgICAgICAgICAgICAgIC5zZXRQbGFjZWhvbGRlcignRW50ZXIgeW91ciBzZWNyZXQnKVxuICAgICAgICAgICAgICAgIC5zZXRWYWx1ZSh0aGlzLnBsdWdpbi5zZXR0aW5ncy50b2NTdHJpbmcpXG4gICAgICAgICAgICAgICAgLm9uQ2hhbmdlKGFzeW5jICh2YWx1ZSkgPT4ge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnBsdWdpbi5zZXR0aW5ncy50b2NTdHJpbmcgPSB2YWx1ZTtcbiAgICAgICAgICAgIC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25lOiB0cnVlLCB2YWx1ZTogdW5kZWZpbmVkIH07XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSBtX2l0ZXJhdG9yLm5leHQoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHQuZG9uZSA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1faXRlcmFibGVzSW5kZXggKz0gMTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtX2l0ZXJhdG9yID0gaXRlcmFibGVzW21faXRlcmFibGVzSW5kZXhdPy5bU3ltYm9sLml0ZXJhdG9yXSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkb25lOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZTogcmVzdWx0LnZhbHVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAodHJ1ZSk7XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0sXG4gICAgfTtcbn1cbi8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSB1bmljb3JuL3ByZWZlci1zZXQtaGFzIC0tIEFycmF5IGlzIG1vcmUgcGVyZm9ybWFudCBmb3IgYSBsb3cgbnVtYmVyIG9mIGVsZW1lbnRzLlxuY29uc3QgdmFsaWRSZWNvcmRUb1N0cmluZ1ZhbHVlcyA9IFtcIltvYmplY3QgT2JqZWN0XVwiLCBcIltvYmplY3QgTW9kdWxlXVwiXTtcbi8qKlxuICogRG9lcyB0aGUgZ2l2ZW4gb2JqZWN0IGFwcGVhciB0byBiZSBhIHJlY29yZ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QUFDLGdCQUFpQjtBQUd0QixVQUFNLGlCQUE4QixLQUFLLHFCQUFxQixlQUFlO0FBQzdFLFVBQU0sY0FBYyxLQUFLLFlBQVksWUFBWTtBQUdqRCxXQUFPLGFBQWEsYUFBYSxlQUFlLE1BQU0sZUFBZSxFQUFFO0FBQUEsRUFDeEU7QUFBQTtBQUFBLEVBR0EsTUFBYyxxQkFBb0M7QUFDakQsVUFBTSxlQUF3QyxLQUFLLElBQUksVUFBVTtBQUNqRSxVQUFNLFNBQTZCLGNBQWM7QUFDakQsVUFBTSxPQUEwQixjQUFjLFFBQVE7QUFFdEQsUUFBSSxDQUFDLGdCQUFnQixDQUFDLFVBQVUsQ0FBQyxLQUFNO0FBR3ZDLFFBQUksT0FBUSxNQUFLLGNBQWMsUUFBUSxJQUFJO0FBQUEsRUFDNUM7QUFDRDsiLAogICJuYW1lcyI6IFsiaW1wb3J0X29ic2lkaWFuIiwgIk9iamVjdFR5cGUiXQp9Cg== +var h=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var k=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!x.call(t,o)&&o!==n&&h(t,o,{get:()=>e[o],enumerable:!(r=C(e,o))||r.enumerable});return t};var V=t=>$(h({},"__esModule",{value:!0}),t);var ee={};k(ee,{default:()=>p});module.exports=V(ee);var g={envPath:"/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.env",pluginRoot:"/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc",pluginManifest:{id:"insta-toc",name:"Insta TOC",version:"2.0.2",minAppVersion:"0.15.0",description:"Simultaneously generate, update, and maintain a table of contents for your notes.",author:"Nick C.",autherUrl:"https://github.com/iLiftALot/insta-toc",isDesktopOnly:!1},pluginSettingsPath:"/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc/data.json",pluginSettings:{},projectRoot:"/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync/.obsidian/plugins/insta-toc",vaultRoot:"/Users/nicholascorbin/Desktop/Knowledge/MyObsidian/ObsidianBackup/My Sync",vaultName:"My Sync"};var m=require("obsidian");var M={tocString:"> [!SUMMARY] Table of Contents",shouldGenToc:!1};var f=require("obsidian"),d=class extends f.PluginSettingTab{constructor(e,n){super(e,n),this.plugin=n}display(){let{containerEl:e}=this;e.empty(),new f.Setting(e).setName("Setting #1").setDesc("It's a secret").addText(n=>n.setPlaceholder("Enter your secret").setValue(this.plugin.settings.tocString).onChange(async r=>{this.plugin.settings.tocString=r,await this.plugin.saveSettings()})),new f.Setting(e).setName("TOC Files").setDesc("Insert files to automatically ").addText(n=>n.setPlaceholder("Enter your secret").setValue(this.plugin.settings.tocString).onChange(async r=>{this.plugin.settings.tocString=r,await this.plugin.saveSettings()}))}};var c={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},ce={defaultMerge:c.defaultMerge};function H(t,e){return e}function L(t,e){return t.filter(n=>n!==void 0)}var E;(function(t){t[t.NOT=0]="NOT",t[t.RECORD=1]="RECORD",t[t.ARRAY=2]="ARRAY",t[t.SET=3]="SET",t[t.MAP=4]="MAP",t[t.OTHER=5]="OTHER"})(E||(E={}));function R(t){return typeof t!="object"||t===null?0:Array.isArray(t)?2:G(t)?1:t instanceof Set?3:t instanceof Map?4:5}function j(t){let e=new Set;for(let n of t)for(let r of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])e.add(r);return e}function N(t,e){return typeof t=="object"&&Object.prototype.propertyIsEnumerable.call(t,e)}function v(t){let e=0,n=t[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let r=n.next();if(r.done===!0){e+=1,n=t[e]?.[Symbol.iterator]();continue}return{done:!1,value:r.value}}while(!0)}}}}}var b=["[object Object]","[object Module]"];function G(t){if(!b.includes(Object.prototype.toString.call(t)))return!1;let{constructor:e}=t;if(e===void 0)return!0;let n=e.prototype;return!(n===null||typeof n!="object"||!b.includes(Object.prototype.toString.call(n))||!n.hasOwnProperty("isPrototypeOf"))}function Y(t,e,n){let r={};for(let o of j(t)){let i=[];for(let u of t)N(u,o)&&i.push(u[o]);if(i.length===0)continue;let s=e.metaDataUpdater(n,{key:o,parents:t}),a=T(i,e,s);a!==c.skip&&(o==="__proto__"?Object.defineProperty(r,o,{value:a,configurable:!0,enumerable:!0,writable:!0}):r[o]=a)}return r}function z(t){return t.flat()}function B(t){return new Set(v(t))}function K(t){return new Map(v(t))}function W(t){return t.at(-1)}var l={mergeRecords:Y,mergeArrays:z,mergeSets:B,mergeMaps:K,mergeOthers:W};function O(...t){return q({})(...t)}function q(t,e){let n=J(t,r);function r(...o){return T(o,n,e)}return r}function J(t,e){return{defaultMergeFunctions:l,mergeFunctions:{...l,...Object.fromEntries(Object.entries(t).filter(([n,r])=>Object.hasOwn(l,n)).map(([n,r])=>r===!1?[n,l.mergeOthers]:[n,r]))},metaDataUpdater:t.metaDataUpdater??H,deepmerge:e,useImplicitDefaultMerging:t.enableImplicitDefaultMerging??!1,filterValues:t.filterValues===!1?void 0:t.filterValues??L,actions:c}}function T(t,e,n){let r=e.filterValues?.(t,n)??t;if(r.length===0)return;if(r.length===1)return S(r,e,n);let o=R(r[0]);if(o!==0&&o!==5){for(let i=1;i{t.apply(this,r),n=null},e)}}var p=class extends m.Plugin{constructor(e,n){let r=n??g.pluginManifest;super(e,r),this.app=e}async onload(){console.log("Loading Insta TOC Plugin"),await this.loadSettings(),this.addSettingTab(new d(this.app,this)),this.registerMarkdownCodeBlockProcessor("insta-toc",async(e,n,r)=>{let o=r.sourcePath,i=o.substring(0,o.lastIndexOf(".")),s=/^(\s*)-\s*(.*)/,u=e.split(` +`).map(y=>{let F=y.match(s);if(!F)return y;let[,w,I]=F,A=`${i}#${I}`;return`${w}- [[${A}|${I}]]`}).join(` +`);await m.MarkdownRenderer.render(this.app,u,n,o,this)}),this.registerEvent(this.app.vault.on("modify",P(this.handleEditorChange.bind(this),2e3)))}onunload(){console.log("Unloading Insta TOC Plugin")}async loadSettings(){let e=M,n=await this.loadData();n&&(e=O(M,n)),this.settings=e}async saveSettings(){await this.saveData(this.settings)}getTocInsertPosition(e){let n=e.position.start.line,r=0,o=e.position.end.line,i=e.position.end.col;return{from:{line:n,ch:r},to:{line:o,ch:i}}}generateToc(e){let n=[];return e.length>0&&e.forEach(o=>{let i=o.level,s=o.heading,a=`${" ".repeat((i-1)*4)}- ${s}`;n.push(a)}),`\`\`\`insta-toc +${n.join(` +`)} +\`\`\``}updateAutoToc(e,n){let r=this.app.metadataCache.getFileCache(n),o=r?.headings??[],i=r?.sections?r.sections.find(u=>u.type==="code"&&e.getLine(u.position.start.line)==="```insta-toc"):void 0;if(!i)return;let s=this.getTocInsertPosition(i),a=this.generateToc(o);e.replaceRange(a,s.from,s.to)}async handleEditorChange(){let e=this.app.workspace.activeEditor,n=e?.editor,r=e?.file??void 0;!e||!n||!r||n&&this.updateAutoToc(n,r)}}; diff --git a/package.json b/package.json index f797622..63457b5 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/iLiftALot/insta-toc.git" }, "homepage": "https://github.com/iLiftALot/insta-toc", - "main": "dist/dev/main.js", + "main": "dist/build/main.js", "scripts": { "dev:log": "node esbuild.config.mjs logger && terser -o dist/dev/main.js dist/dev/main.js", "dev": "node esbuild.config.mjs && terser -o dist/dev/main.js dist/dev/main.js", @@ -41,4 +41,4 @@ "dependencies": { "deepmerge-ts": "7.1.3" } -} +} \ No newline at end of file