From 023000536fc9003d18e6545ed6b2785ad78c1909 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Sun, 13 Apr 2025 20:26:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=EF=B8=8F=20Commit=20deployable=20p?= =?UTF-8?q?lugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/main.js b/dist/main.js index 2e04ff9..72ec6f8 100644 --- a/dist/main.js +++ b/dist/main.js @@ -3,4 +3,4 @@ THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ -var S=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var C=(r,s)=>{for(var t in s)S(r,t,{get:s[t],enumerable:!0})},I=(r,s,t,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of F(s))!b.call(r,i)&&i!==t&&S(r,i,{get:()=>s[i],enumerable:!(e=w(s,i))||e.enumerable});return r};var A=r=>I(S({},"__esModule",{value:!0}),r);var N={};C(N,{default:()=>M});module.exports=A(N);var L=require("obsidian");var h={mentionTypes:[],matchStart:!0,maxMatchLength:15,stopCharacters:"?!\"'`:;/#+*=&%$\xA7<>"},k="@#+!$%^&*~=-:;><|",T=k.split("");var x=require("obsidian");function u(r,s){if(!r.endsWith(".md"))return null;for(let t=0;t{if(t instanceof x.TFile&&t.extension==="md"){let e=u(t.path,this.settings);e&&this.addFileToMap(e)}}),this.fileMaps}getFileMaps(){return this.fileMaps}updateIndex(s,t){let e=!1,i=u(s,this.settings);if(i&&(this.addFileToMap(i),e=!0),t){let n=u(t,this.settings);n&&(this.removeFileFromMap(n),e=!0)}return e}addFileToMap(s){let t=s.sign;if(!t)return;let e=s.name.toLowerCase();this.fileMaps[t]=this.fileMaps[t]||{},this.fileMaps[t][e]=s}removeFileFromMap(s){let t=s.sign;if(!t||!this.fileMaps[t])return;let e=s.name.toLowerCase();delete this.fileMaps[t][e]}};var c=class{constructor(s,t){this.settings=t,this.fileIndexer=new d(s,t)}initialize(){return this.fileIndexer.initialize()}getFileMaps(){return this.fileIndexer.getFileMaps()}handleFileEvent(s,t){return this.fileIndexer.updateIndex(s.path,t)}getUsedSigns(){return this.settings.mentionTypes.map(s=>s.sign).filter(Boolean)}updateSettings(s){this.settings=s,this.initialize()}};var E=require("obsidian");var m=class extends E.EditorSuggest{constructor(t,e,i){super(t);this.currSign="";this.settings=e,this.mentionManager=i,this.fileMaps=i.getFileMaps()}setSuggestionsMap(t){this.fileMaps=t}onTrigger(t,e,i){let n=e.getLine(t.line).substring(0,t.ch);if(!n)return null;let{signIndex:o,sign:g}=this.findMostRecentSign(n);if(o<0)return null;this.currSign=g;let a=n.substring(o+1);return this.shouldShowSuggestions(a,o,n)?{start:{line:t.line,ch:o},end:{line:t.line,ch:t.ch},query:a}:null}findMostRecentSign(t){let e=this.mentionManager.getUsedSigns(),i=-1,n="";for(let o of e){let g=t.lastIndexOf(o);g!==-1&&g>i&&(i=g,n=o)}return{signIndex:i,sign:n}}shouldShowSuggestions(t,e,i){var g,a;if(!t||t.includes("]]"))return!1;let n=(g=this.settings.maxMatchLength)!=null?g:h.maxMatchLength;if(n&&t.length>n)return!1;let o=(a=this.settings.stopCharacters)!=null?a:h.stopCharacters;if(o){for(let l of o)if(t.includes(l))return!1}return e===0||i[e-1]===" "}getSuggestions(t){let e=[],i=this.fileMaps[this.currSign]||{},n=t.query.toLowerCase();return e=this.getMatchingSuggestions(i,n,t),e.push(this.createNewItemSuggestion(t)),e}getMatchingSuggestions(t,e,i){let n=[];for(let o in t)o&&this.isMatch(o,e)&&n.push({suggestionType:"set",displayText:t[o].name.trim(),linkName:t[o].name,context:i});return n}isMatch(t,e){return this.settings.matchStart?t.startsWith(e):t.includes(e)}createNewItemSuggestion(t){return{suggestionType:"create",displayText:t.query,linkName:t.query,context:t}}renderSuggestion(t,e){if(t.suggestionType==="create"){let i=v(this.settings.mentionTypes,this.currSign),n=(i==null?void 0:i.label)||"Item";e.setText(`Create ${n}: ${t.displayText}`)}else e.setText(t.displayText)}selectSuggestion(t,e){let i=y(this.currSign,t.linkName);t.context.editor.replaceRange(i,t.context.start,t.context.end)}};var p=require("obsidian");var f=class extends p.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){let{containerEl:t}=this,e=this.plugin.settings.mentionTypes.map(i=>i.sign).filter(i=>i!==void 0);t.empty(),new p.Setting(t).setName("Mention Things").setHeading(),this.renderMentionTypesSection(t,e),this.renderGeneralSettings(t)}renderMentionTypesSection(t,e){this.plugin.settings.mentionTypes.forEach((i,n)=>{this.renderMentionTypeRow(t,i,n,e)}),new p.Setting(t).addButton(i=>{i.setButtonText("New Type").setCta().onClick(async()=>{this.plugin.settings.mentionTypes.push({}),await this.plugin.saveSettings(),this.display()})})}renderMentionTypeRow(t,e,i,n){let o=new p.Setting(t),g=this.getAvailableSigns(n,e==null?void 0:e.sign);o.addDropdown(a=>a.addOptions(g).setValue((e==null?void 0:e.sign)||"").onChange(async l=>{this.plugin.settings.mentionTypes[i].sign=l,await this.plugin.saveSettings(),this.display()})),o.addText(a=>a.setPlaceholder('Label. Example "Person"').setValue((e==null?void 0:e.label)||"").onChange(async l=>{this.plugin.settings.mentionTypes[i].label=l,await this.plugin.saveSettings()}).inputEl.addClass("type_label")),o.addExtraButton(a=>a.setIcon("cross").setTooltip("Delete").onClick(async()=>{this.plugin.settings.mentionTypes.splice(i,1),await this.plugin.saveSettings(),this.display()})),o.infoEl.remove()}renderGeneralSettings(t){new p.Setting(t).setName("General Settings").setHeading(),new p.Setting(t).setName("Match from start").setDesc("Whether to suggest only items that start with the search term. When disabled, any part of the name can match the search term").addToggle(e=>{var i;return e.setValue((i=this.plugin.settings.matchStart)!=null?i:!1).onChange(async n=>{this.plugin.settings.matchStart=n,await this.plugin.saveSettings()})}),new p.Setting(t).setName("Max match length").setDesc("Maximum number of characters to match (3-50)").addSlider(e=>{var i;e.setLimits(3,50,1).setValue((i=this.plugin.settings.maxMatchLength)!=null?i:15).setDynamicTooltip().onChange(async n=>{this.plugin.settings.maxMatchLength=n,await this.plugin.saveSettings()})}),new p.Setting(t).setName("Stop characters").setDesc("Characters that will stop the matching process. Leave empty to disable.").addText(e=>{var i;e.setPlaceholder("?!\"'`:;/#+*=&%$\xA7<>").setValue((i=this.plugin.settings.stopCharacters)!=null?i:"?!\"'`:;/#+*=&%$\xA7<>").onChange(async n=>{let o=[...new Set(n.split(""))].join("");this.plugin.settings.stopCharacters=o,await this.plugin.saveSettings()})})}getAvailableSigns(t,e){let i={};return T.forEach(n=>{(e===n||!t.includes(n))&&(i[n]=`${n}Name`)}),i}};var M=class extends L.Plugin{async onload(){await this.loadSettings(),this.mentionManager=new c(this.app,this.settings),this.suggestionProvider=new m(this.app,this.settings,this.mentionManager),this.registerEditorSuggest(this.suggestionProvider),this.addSettingTab(new f(this.app,this)),this.registerFileEvents(),this.app.workspace.onLayoutReady(()=>{let t=this.mentionManager.initialize();this.suggestionProvider.setSuggestionsMap(t)})}registerFileEvents(){this.registerEvent(this.app.vault.on("delete",async t=>{this.mentionManager.handleFileEvent(t)&&this.refreshSuggestions()})),this.registerEvent(this.app.vault.on("create",async t=>{this.mentionManager.handleFileEvent(t)&&this.refreshSuggestions()})),this.registerEvent(this.app.vault.on("rename",async(t,e)=>{this.mentionManager.handleFileEvent(t,e)&&this.refreshSuggestions()}))}refreshSuggestions(){let t=this.mentionManager.getFileMaps();this.suggestionProvider.setSuggestionsMap(t)}async loadSettings(){this.settings=Object.assign({},h,await this.loadData())}async saveSettings(){await this.saveData(this.settings),this.mentionManager&&(this.mentionManager.updateSettings(this.settings),this.refreshSuggestions())}}; +var S=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var C=(r,s)=>{for(var t in s)S(r,t,{get:s[t],enumerable:!0})},I=(r,s,t,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of F(s))!b.call(r,i)&&i!==t&&S(r,i,{get:()=>s[i],enumerable:!(e=w(s,i))||e.enumerable});return r};var A=r=>I(S({},"__esModule",{value:!0}),r);var N={};C(N,{default:()=>M});module.exports=A(N);var L=require("obsidian");var h={mentionTypes:[],matchStart:!0,maxMatchLength:15,stopCharacters:"?!\"'`:;/#+*=&%$\xA7<>"},k="@#+!$%^&*~=-:;><|",T=k.split("");var x=require("obsidian");function u(r,s){if(!r.endsWith(".md"))return null;for(let t=0;t{if(t instanceof x.TFile&&t.extension==="md"){let e=u(t.path,this.settings);e&&this.addFileToMap(e)}}),this.fileMaps}getFileMaps(){return this.fileMaps}updateIndex(s,t){let e=!1,i=u(s,this.settings);if(i&&(this.addFileToMap(i),e=!0),t){let n=u(t,this.settings);n&&(this.removeFileFromMap(n),e=!0)}return e}addFileToMap(s){let t=s.sign;if(!t)return;let e=s.name.toLowerCase();this.fileMaps[t]=this.fileMaps[t]||{},this.fileMaps[t][e]=s}removeFileFromMap(s){let t=s.sign;if(!t||!this.fileMaps[t])return;let e=s.name.toLowerCase();delete this.fileMaps[t][e]}};var c=class{constructor(s,t){this.settings=t,this.fileIndexer=new d(s,t)}initialize(){return this.fileIndexer.initialize()}getFileMaps(){return this.fileIndexer.getFileMaps()}handleFileEvent(s,t){return this.fileIndexer.updateIndex(s.path,t)}getUsedSigns(){return this.settings.mentionTypes.map(s=>s.sign).filter(Boolean)}updateSettings(s){this.settings=s,this.initialize()}};var E=require("obsidian");var m=class extends E.EditorSuggest{constructor(t,e,i){super(t);this.currSign="";this.settings=e,this.mentionManager=i,this.fileMaps=i.getFileMaps()}setSuggestionsMap(t){this.fileMaps=t}onTrigger(t,e,i){let n=e.getLine(t.line).substring(0,t.ch);if(!n)return null;let{signIndex:o,sign:g}=this.findMostRecentSign(n);if(o<0)return null;this.currSign=g;let a=n.substring(o+1);return this.shouldShowSuggestions(a,o,n)?{start:{line:t.line,ch:o},end:{line:t.line,ch:t.ch},query:a}:null}findMostRecentSign(t){let e=this.mentionManager.getUsedSigns(),i=-1,n="";for(let o of e){let g=t.lastIndexOf(o);g!==-1&&g>i&&(i=g,n=o)}return{signIndex:i,sign:n}}shouldShowSuggestions(t,e,i){var g,a;if(!t||t.includes("]]"))return!1;let n=(g=this.settings.maxMatchLength)!=null?g:h.maxMatchLength;if(n&&t.length>n)return!1;let o=(a=this.settings.stopCharacters)!=null?a:h.stopCharacters;if(o){for(let l of o)if(t.includes(l))return!1}return e===0||i[e-1]===" "}getSuggestions(t){let e=[],i=this.fileMaps[this.currSign]||{},n=t.query.toLowerCase();return e=this.getMatchingSuggestions(i,n,t),e.push(this.createNewItemSuggestion(t)),e}getMatchingSuggestions(t,e,i){let n=[];for(let o in t)o&&this.isMatch(o,e)&&n.push({suggestionType:"set",displayText:t[o].name.trim(),linkName:t[o].name,context:i});return n}isMatch(t,e){return this.settings.matchStart?t.startsWith(e):t.includes(e)}createNewItemSuggestion(t){return{suggestionType:"create",displayText:t.query,linkName:t.query,context:t}}renderSuggestion(t,e){if(t.suggestionType==="create"){let i=v(this.settings.mentionTypes,this.currSign),n=(i==null?void 0:i.label)||"Item";e.setText(`Create ${n}: ${t.displayText}`)}else e.setText(t.displayText)}selectSuggestion(t,e){let i=y(this.currSign,t.linkName);t.context.editor.replaceRange(i,t.context.start,t.context.end)}};var p=require("obsidian");var f=class extends p.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){let{containerEl:t}=this,e=this.plugin.settings.mentionTypes.map(i=>i.sign).filter(i=>i!==void 0);t.empty(),new p.Setting(t).setName("Mention Things").setHeading(),this.renderMentionTypesSection(t,e),this.renderGeneralSettings(t)}renderMentionTypesSection(t,e){this.plugin.settings.mentionTypes.forEach((i,n)=>{this.renderMentionTypeRow(t,i,n,e)}),new p.Setting(t).addButton(i=>{i.setButtonText("New type").setCta().onClick(async()=>{this.plugin.settings.mentionTypes.push({}),await this.plugin.saveSettings(),this.display()})})}renderMentionTypeRow(t,e,i,n){let o=new p.Setting(t),g=this.getAvailableSigns(n,e==null?void 0:e.sign);o.addDropdown(a=>a.addOptions(g).setValue((e==null?void 0:e.sign)||"").onChange(async l=>{this.plugin.settings.mentionTypes[i].sign=l,await this.plugin.saveSettings(),this.display()})),o.addText(a=>a.setPlaceholder('Type label, for example "Person"').setValue((e==null?void 0:e.label)||"").onChange(async l=>{this.plugin.settings.mentionTypes[i].label=l,await this.plugin.saveSettings()}).inputEl.addClass("type_label")),o.addExtraButton(a=>a.setIcon("cross").setTooltip("Delete").onClick(async()=>{this.plugin.settings.mentionTypes.splice(i,1),await this.plugin.saveSettings(),this.display()})),o.infoEl.remove()}renderGeneralSettings(t){new p.Setting(t).setName("General settings").setHeading(),new p.Setting(t).setName("Match from start").setDesc("Whether to suggest only items that start with the search term. When disabled, any part of the name can match the search term").addToggle(e=>{var i;return e.setValue((i=this.plugin.settings.matchStart)!=null?i:!1).onChange(async n=>{this.plugin.settings.matchStart=n,await this.plugin.saveSettings()})}),new p.Setting(t).setName("Max match length").setDesc("Maximum number of characters to match (3-50)").addSlider(e=>{var i;e.setLimits(3,50,1).setValue((i=this.plugin.settings.maxMatchLength)!=null?i:15).setDynamicTooltip().onChange(async n=>{this.plugin.settings.maxMatchLength=n,await this.plugin.saveSettings()})}),new p.Setting(t).setName("Stop characters").setDesc("Characters that will stop the matching process. Leave empty to disable.").addText(e=>{var i;e.setPlaceholder("?!\"'`:;/#+*=&%$\xA7<>").setValue((i=this.plugin.settings.stopCharacters)!=null?i:"?!\"'`:;/#+*=&%$\xA7<>").onChange(async n=>{let o=[...new Set(n.split(""))].join("");this.plugin.settings.stopCharacters=o,await this.plugin.saveSettings()})})}getAvailableSigns(t,e){let i={};return T.forEach(n=>{(e===n||!t.includes(n))&&(i[n]=`${n}Name`)}),i}};var M=class extends L.Plugin{async onload(){await this.loadSettings(),this.mentionManager=new c(this.app,this.settings),this.suggestionProvider=new m(this.app,this.settings,this.mentionManager),this.registerEditorSuggest(this.suggestionProvider),this.addSettingTab(new f(this.app,this)),this.registerFileEvents(),this.app.workspace.onLayoutReady(()=>{let t=this.mentionManager.initialize();this.suggestionProvider.setSuggestionsMap(t)})}registerFileEvents(){this.registerEvent(this.app.vault.on("delete",async t=>{this.mentionManager.handleFileEvent(t)&&this.refreshSuggestions()})),this.registerEvent(this.app.vault.on("create",async t=>{this.mentionManager.handleFileEvent(t)&&this.refreshSuggestions()})),this.registerEvent(this.app.vault.on("rename",async(t,e)=>{this.mentionManager.handleFileEvent(t,e)&&this.refreshSuggestions()}))}refreshSuggestions(){let t=this.mentionManager.getFileMaps();this.suggestionProvider.setSuggestionsMap(t)}async loadSettings(){this.settings=Object.assign({},h,await this.loadData())}async saveSettings(){await this.saveData(this.settings),this.mentionManager&&(this.mentionManager.updateSettings(this.settings),this.refreshSuggestions())}};