/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD */ var N=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var W=(n,i)=>{for(var e in i)N(n,e,{get:i[e],enumerable:!0})},_=(n,i,e,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of $(i))!O.call(n,s)&&s!==e&&N(n,s,{get:()=>i[s],enumerable:!(t=R(i,s))||t.enumerable});return n};var H=n=>_(N({},"__esModule",{value:!0}),n);var G={};W(G,{default:()=>k});module.exports=H(G);var I=require("obsidian");var L=require("obsidian");var P=require("obsidian");async function y(n,i,e){let t=n.workspace.getActiveViewOfType(P.MarkdownView);(t==null?void 0:t.file)===i&&await t.save(),await n.fileManager.processFrontMatter(i,e)}function v(n,i,e){var r;n[i.property]=e;let t=o=>o.split(/\s+/).filter(Boolean),s=new Set(i.steps.flatMap(o=>t(o.cssclass))),a=n.cssclasses,l=(Array.isArray(a)?a:typeof a=="string"?t(a):[]).map(String),d=i.steps.find(o=>o.value===e),p=l.filter(o=>!s.has(o));for(let o of t((r=d==null?void 0:d.cssclass)!=null?r:""))p.includes(o)||p.push(o);p.length?n.cssclasses=p:a!==void 0&&delete n.cssclasses}var m={symbol:"",property:"",valueMode:"single",source:"open",values:[],flowId:""},A={rules:[{...m,symbol:"@",property:"type"}],flows:[]},S=["#","[","/",":"];function F(n,i,e){return[...n].length!==1?"Use exactly one character.":/[\p{L}\p{N}\s]/u.test(n)?"Letters, digits and spaces are not allowed.":S.includes(n)?`"${n}" is reserved (${S.join(" ")}).`:i.some((t,s)=>s!==e&&t.symbol===n)?`"${n}" is already used by another trigger.`:null}function D(n,i){let e=n.rules[i];if(F(e.symbol,n.rules,i))return null;if(e.source==="flow"){let t=n.flows.find(s=>s.id===e.flowId);return t&&t.property?{property:t.property,flow:t}:null}return e.property?{property:e.property,flow:null}:null}function w(n){return n.steps.filter(i=>i.value.trim()!=="")}var x=class{constructor(i){this.plugin=i;this.registered=[]}sync(){for(let i of this.registered)this.plugin.removeCommand(i);this.registered=[];for(let i of this.plugin.settings.flows)this.add(i,1,"next","next step"),this.add(i,-1,"previous","previous step")}add(i,e,t,s){let a=`flow-${i.id}-${t}`;this.registered.push(a),this.plugin.addCommand({id:a,name:`${i.name||i.property||"Unnamed flow"}: ${s}`,checkCallback:l=>{let d=this.plugin.app.workspace.getActiveFile();return!d||d.extension!=="md"||!i.property||w(i).length===0?!1:(l||U(this.plugin,d,i,e),!0)}})}};async function U(n,i,e,t){let s=w(e),a="";try{await y(n.app,i,l=>{let d=s.findIndex(r=>r.value===String(l[e.property])),p=d===-1?0:d+t;if(p<0||p>=s.length){if(!e.loop){a=`${e.property}: already at the ${t===1?"last":"first"} step`;return}p=(p+s.length)%s.length}v(l,e,s[p].value),a=`${e.property}: ${s[p].value}`}),new L.Notice(a)}catch(l){console.error("FFLOW: could not move flow step",l),new L.Notice(`FFLOW: could not set "${e.property}". See console.`)}}var h=require("obsidian");var T=class extends h.PluginSettingTab{constructor(e,t){super(e,t);this.plugin=t;this.save=()=>this.plugin.saveSettings()}display(){let{containerEl:e}=this,t=this.plugin.settings;e.empty(),new h.Setting(e).setHeading().setName("Triggers").setDesc(`Type a symbol at the start of a word, pick a value: the typed text disappears and the value goes to the frontmatter. Reserved: ${S.join(" ")}`).addButton(s=>s.setButtonText("Add trigger").onClick(async()=>{t.rules.push({...m,values:[]}),await this.save(),this.display()})),t.rules.forEach((s,a)=>this.renderRule(s,a)),new h.Setting(e).setHeading().setName("Flows").setDesc("Ordered values for a property. Each step can add cssclasses. Every flow gets \u201Cnext step\u201D and \u201Cprevious step\u201D commands for hotkeys.").addButton(s=>s.setButtonText("Hotkeys").onClick(()=>this.openHotkeys())).addButton(s=>s.setButtonText("Add flow").onClick(async()=>{t.flows.push({id:Date.now().toString(36),name:"",property:"",loop:!1,steps:[{value:"",cssclass:""}]}),await this.save(),this.display()})),t.flows.forEach((s,a)=>this.renderFlow(s,a))}renderRule(e,t){let s=this.plugin.settings,a=e.source==="flow"?s.flows.find(o=>o.id===e.flowId):void 0,l=createFragment(),d=l.createSpan(),p=()=>{let o=a?a.property:e.property;d.setText(`${e.symbol||"?"} \u2192 ${o||"?"}`)};p();let r=new h.SettingGroup(this.containerEl).setHeading(l).addClass("fflow-group");if(r.addExtraButton(o=>o.setIcon("trash").setTooltip("Delete trigger").onClick(async()=>{s.rules.splice(t,1),await this.save(),this.display()})),r.addSetting(o=>{o.setName("Symbol");let c=o.descEl.createDiv({cls:"fflow-error"}),u=g=>{var f;return c.setText(g?(f=F(g,s.rules,t))!=null?f:"":"Pick a symbol.")};u(e.symbol),o.addText(g=>{g.setPlaceholder("@").setValue(e.symbol),g.inputEl.addClass("fflow-symbol"),g.onChange(async f=>{u(f),!F(f,s.rules,t)&&(e.symbol=f,p(),await this.save())})})}),r.addSetting(o=>o.setName("Values from").setDesc(e.source==="open"?"Every value already used for the property in the vault. New values are allowed.":e.source==="finite"?"Only the values listed below.":"The steps of the flow. Picking one also applies its cssclasses.").addDropdown(c=>{c.addOption("open","Vault (open list)").addOption("finite","Fixed list");for(let u of s.flows)c.addOption(`flow:${u.id}`,`Flow: ${u.name||u.property||"unnamed"}`);c.setValue(e.source==="flow"?`flow:${e.flowId}`:e.source).onChange(async u=>{u.startsWith("flow:")?(e.source="flow",e.flowId=u.slice(5)):e.source=u,await this.save(),this.display()})})),e.source==="flow"){a||r.addSetting(o=>o.setName("Flow deleted").setDesc("Pick another source.").descEl.addClass("fflow-error"));return}r.addSetting(o=>o.setName("Property").addText(c=>c.setPlaceholder("type").setValue(e.property).onChange(async u=>{e.property=u.trim(),p(),await this.save()})).addDropdown(c=>c.addOptions({single:"Single value",list:"List"}).setValue(e.valueMode).onChange(async u=>{e.valueMode=u,await this.save()}))),e.source==="finite"&&r.addSetting(o=>o.setName("Values").setDesc("One per line, in display order.").addTextArea(c=>{c.setValue(e.values.join(` `)).onChange(async u=>{e.values=u.split(` `).map(g=>g.trim()).filter(Boolean),await this.save()}),c.inputEl.rows=5}))}renderFlow(e,t){let s=this.plugin.settings,a=createFragment(),l=a.createSpan(),d=()=>l.setText(e.name||e.property||"New flow");d();let p=new h.SettingGroup(this.containerEl).setHeading(a).addClass("fflow-group");p.addExtraButton(r=>r.setIcon("trash").setTooltip("Delete flow").onClick(async()=>{s.flows.splice(t,1);for(let o of s.rules)o.source==="flow"&&o.flowId===e.id&&(o.source="open",o.property=e.property);await this.save(),this.display()})),p.addSetting(r=>r.setName("Name and property").setDesc("The name labels the hotkey commands.").addText(o=>o.setPlaceholder("Status").setValue(e.name).onChange(async c=>{e.name=c,d(),await this.save()})).addText(o=>o.setPlaceholder("status").setValue(e.property).onChange(async c=>{e.property=c.trim(),d(),await this.save()}))),p.addSetting(r=>r.setName("Loop").setDesc("After the last step, \u201Cnext\u201D goes back to the first.").addToggle(o=>o.setValue(e.loop).onChange(async c=>{e.loop=c,await this.save()}))),e.steps.forEach((r,o)=>{p.addSetting(c=>{c.setName(`Step ${o+1}`).setClass("fflow-step"),c.addText(g=>g.setPlaceholder("value").setValue(r.value).onChange(async f=>{r.value=f.trim(),await this.save()})),c.addText(g=>g.setPlaceholder("cssclasses (optional)").setValue(r.cssclass).onChange(async f=>{r.cssclass=f.trim(),await this.save()}));let u=async g=>{e.steps.splice(g,0,...e.steps.splice(o,1)),await this.save(),this.display()};c.addExtraButton(g=>g.setIcon("arrow-up").setTooltip("Move up").setDisabled(o===0).onClick(()=>u(o-1))),c.addExtraButton(g=>g.setIcon("arrow-down").setTooltip("Move down").setDisabled(o===e.steps.length-1).onClick(()=>u(o+1))),c.addExtraButton(g=>g.setIcon("x").setTooltip("Remove step").onClick(async()=>{e.steps.splice(o,1),await this.save(),this.display()}))})}),p.addSetting(r=>r.addButton(o=>o.setButtonText("Add step").onClick(async()=>{e.steps.push({value:"",cssclass:""}),await this.save(),this.display()})))}openHotkeys(){let e=Reflect.get(this.app,"setting");if(!e||typeof e!="object"||!("openTabById"in e)||typeof e.openTabById!="function")return;let t=e.openTabById("hotkeys"),s=t&&typeof t=="object"&&"searchComponent"in t?t.searchComponent:null;s instanceof h.SearchComponent&&(s.setValue(this.plugin.manifest.name),s.inputEl.dispatchEvent(new Event("input")))}};var b=require("obsidian");var E=class{constructor(i){this.app=i;this.cache=new Map}invalidate(){this.cache.clear()}get(i){var t,s,a;let e=this.cache.get(i);if(e)return e;e=new Map;for(let l of this.app.vault.getMarkdownFiles()){let d=(s=(t=this.app.metadataCache.getFileCache(l))==null?void 0:t.frontmatter)==null?void 0:s[i];for(let p of new Set(B(d)))e.set(p,((a=e.get(p))!=null?a:0)+1)}return this.cache.set(i,e),e}};function B(n){return Array.isArray(n)?n.flatMap(B):typeof n=="string"?n.trim()?[n.trim()]:[]:typeof n=="number"||typeof n=="boolean"?[String(n)]:[]}var M=n=>n!==void 0&&/\s/.test(n),C=class extends b.EditorSuggest{constructor(e,t,s){super(e);this.plugin=t;this.index=s;this.active=null}onTrigger(e,t,s){let a=t.getLine(e.line).slice(0,e.ch),l=a.length;for(;l>0&&!M(a[l-1]);)l--;let d=a.slice(l);if(!d)return null;let p=this.plugin.settings,r=p.rules.findIndex(c=>c.symbol===d[0]),o=r===-1?null:D(p,r);return!o||j(t,e.line)||q(t,e.line,a.slice(0,l))?null:(this.active={rule:p.rules[r],...o},{start:{line:e.line,ch:l},end:e,query:d.slice(1)})}getSuggestions(e){let t=this.active;if(!t)return[];let{rule:s,flow:a}=t,l=e.query.toLowerCase(),d=a?w(a).map(r=>({value:r.value,isNew:!1})):s.source==="finite"?s.values.map(r=>({value:r,isNew:!1})):[...this.index.get(t.property)].sort((r,o)=>o[1]-r[1]||r[0].localeCompare(o[0])).map(([r,o])=>({value:r,count:o,isNew:!1})),p=d.filter(r=>r.value.toLowerCase().includes(l));return p.sort((r,o)=>+!r.value.toLowerCase().startsWith(l)-+!o.value.toLowerCase().startsWith(l)),s.source==="open"&&l&&!d.some(r=>r.value.toLowerCase()===l)&&p.push({value:e.query,isNew:!0}),p}renderSuggestion(e,t){if(t.addClass("fflow-suggestion"),e.isNew){t.createSpan({cls:"fflow-new",text:"New: "}),t.createSpan({text:e.value});return}t.createSpan({text:e.value}),e.count!==void 0&&t.createSpan({cls:"fflow-count",text:String(e.count)})}selectSuggestion(e,t){let s=this.context,a=this.active;!s||!a||this.apply(s,a,e.value)}async apply(e,{rule:t,property:s,flow:a},l){let{editor:d,file:p,start:r}=e,o=d.getLine(r.line),c=e.end.ch;for(;c{if(a){v(u,a,l);return}if(t.valueMode==="single"){u[s]=l;return}let g=u[s],f=g==null?[]:Array.isArray(g)?g:[g];f.some(V=>String(V)===l)||f.push(l),u[s]=f})}catch(u){console.error("FFLOW: could not update frontmatter",u),new b.Notice(`FFLOW: could not set "${s}". See console.`)}}};function j(n,i){if(n.getLine(0)!=="---")return!1;for(let e=1;ee.invalidate())),this.registerEvent(this.app.metadataCache.on("deleted",()=>e.invalidate())),this.registerEditorSuggest(new C(this.app,this,e)),this.flowCommands.sync(),this.addSettingTab(new T(this.app,this))}async loadSettings(){var t,s,a;let e=(t=await this.loadData())!=null?t:{};this.settings={rules:((s=e.rules)!=null?s:A.rules).map(l=>({...m,...l})),flows:(a=e.flows)!=null?a:[]}}async saveSettings(){await this.saveData(this.settings),this.flowCommands.sync()}};