34 lines
126 KiB
JavaScript
34 lines
126 KiB
JavaScript
/*
|
|||
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||
|
|
if you want to view the source visit the plugins github repository (https://github.com/Vinzent03/obsidian-advanced-uri)
|
||
|
|
*/
|
||
|
|
|
||
|
|
var Ue=Object.create;var Z=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty;var Be=(s,n)=>()=>(n||s((n={exports:{}}).exports,n),n.exports),$e=(s,n)=>{for(var e in n)Z(s,e,{get:n[e],enumerable:!0})},ge=(s,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of He(n))!We.call(s,i)&&i!==e&&Z(s,i,{get:()=>n[i],enumerable:!(t=ze(n,i))||t.enumerable});return s};var Ke=(s,n,e)=>(e=s!=null?Ue(Ne(s)):{},ge(n||!s||!s.__esModule?Z(e,"default",{value:s,enumerable:!0}):e,s)),Ge=s=>ge(Z({},"__esModule",{value:!0}),s);var xe=Be((N,se)=>{(function(n,e){typeof N=="object"&&typeof se=="object"?se.exports=e():typeof define=="function"&&define.amd?define([],e):typeof N=="object"?N.feather=e():n.feather=e()})(typeof self!="undefined"?self:N,function(){return function(s){var n={};function e(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return s[t].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=s,e.c=n,e.d=function(t,i,o){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:o})},e.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},e.p="",e(e.s=0)}({"./dist/icons.json":function(s){s.exports={activity:'<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline>',airplay:'<path d="M5 17H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-1"></path><polygon points="12 15 17 21 7 21 12 15"></polygon>',"alert-circle":'<circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line>',"alert-octagon":'<polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"></polygon><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line>',"alert-triangle":'<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line>',"align-center":'<line x1="18" y1="10" x2="6" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="18" y1="18" x2="6" y2="18"></line>',"align-justify":'<line x1="21" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="3" y2="18"></line>',"align-left":'<line x1="17" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="17" y1="18" x2="3" y2="18"></line>',"align-right":'<line x1="21" y1="10" x2="7" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="7" y2="18"></line>',anchor:'<circle cx="12" cy="5" r="3"></circle><line x1="12" y1="22" x2="12" y2="8"></line><path d="M5 12H2a10 10 0 0 0 20 0h-3"></path>',aperture:'<circle cx="12" cy="12" r="10"></circle><line x1="14.31" y1="8" x2="20.05" y2="17.94"></line><line x1="9.69" y1="8" x2="21.17" y2="8"></line><line x1="7.38" y1="12" x2="13.12" y2="2.06"></line><line x1="9.69" y1="16" x2="3.95" y2="6.06"></line><line x1="14.31" y1="16" x2="2.83" y2="16"></line><line x1="16.62" y1="12" x2="10.88" y2="21.94"></line>',archive:'<polyline points="21 8 21 21 3 21 3 8"></polyline><rect x="1" y="3" width="22" height="5"></rect><line x1="10" y1="12" x2="14" y2="12"></line>',"arrow-down-circle":'<circle cx="12" cy="12" r="10"></circle><polyline points="8 12 12 16 16 12"></polyline><line x1="12" y1="8" x2="12" y2="16"></line>',"arrow-down-left":'<line x1="17" y1="7" x2="7" y2="17"></line><polyline points="17 17 7 17 7 7"></polyline>',"arrow-down-right":'<line x1="7" y1="7" x2="17" y2="17"></line><polyline points="17 7 17 17 7 17"></polyline>',"arrow-down":'<line x1="12" y1="5" x2="12" y2="19"><
|
||
|
|
|
||
|
|
`:" ";return n.replaceRange(`${l}^${a}`,o),a}static shouldInsertAfter(n){if(n.type)return["blockquote","code","table","heading","comment","footnoteDefinition"].includes(n.type)}static getBlockId(n){let e=n.workspace.getActiveViewOfType(me.MarkdownView);if(e){let t=e.editor,i=e.file,o=this.getBlock(n,t,i);if(o)return this.getIdOfBlock(t,o)}}};var ve={openFileOnWrite:!0,openDailyInNewPane:!1,openFileOnWriteInNewPane:!1,openFileWithoutWriteInNewPane:!1,idField:"id",useUID:!1,addFilepathWhenUsingUID:!1,allowEval:!1,includeVaultName:!0,vaultParam:"name",linkFormats:[{name:"Markdown",format:"[{{name}}]({{uri}})"}]};var we=require("obsidian");function je(s){let n=s.internalPlugins.plugins["daily-notes"];if(n&&n.enabled)return!0}function Ze(...s){let n=[];for(let t=0,i=s.length;t<i;t++)n=n.concat(s[t].split("/"));let e=[];for(let t=0,i=n.length;t<i;t++){let o=n[t];!o||o==="."||e.push(o)}return n[0]===""&&e.unshift(""),e.join("/")}async function be(s,n){let{format:e,folder:t}=n.internalPlugins.getEnabledPluginById("daily-notes").options,i=s.format(e);return i.endsWith(".md")||(i+=".md"),(0,we.normalizePath)(Ze(t,i))}var v=require("obsidian");var Me=require("obsidian"),D=class extends Me.SuggestModal{constructor(e,t,i){super(e.app);this.withFormat=t;this.file=i;this.modes=[null,"overwrite","append","prepend"];this.plugin=e,this.setPlaceholder("Type your data to be written to the file or leave it empty to just open it")}getSuggestions(e){e==""&&(e=null);let t=[];for(let i of this.modes)if(!(i==="overwrite"&&!e)){let o;e?i?o=`Write "${e}" in ${i} mode`:o=`Write "${e}"`:i?o=`Open in ${i} mode`:o="Open",t.push({data:e,display:o,mode:i,func:()=>{this.file?this.plugin.tools.copyURI({filepath:this.file,data:e,mode:i},this.withFormat,this.app.vault.getFileByPath(this.file)):this.plugin.tools.copyURI({daily:"true",data:e,mode:i},this.withFormat,void 0)}})}return t}renderSuggestion(e,t){t.innerText=e.display}onChooseSuggestion(e,t){e.func()}};var Ie=require("obsidian"),R=class extends Ie.FuzzySuggestModal{constructor(e,t,i=!0){super(e.app);this.placeHolder=t;this.allowNoFile=i;this.plugin=e,this.setPlaceholder(this.placeHolder)}getItems(){let e=[];this.allowNoFile&&e.push({display:"<Don't specify a file>",source:void 0});let t=this.app.workspace.getActiveFile();return t&&e.push({display:"<Current file>",source:t.path}),[...e,...this.app.vault.getFiles().map(i=>({display:i.path,source:i.path}))]}getItemText(e){return e.display}onChooseItem(e,t){}};var Ae=require("obsidian");function re(s){return s.viewmode?{state:{mode:s.viewmode,source:s.viewmode=="source"}}:void 0}function z(s){return navigator.clipboard.writeText(s)}function J(s,n){var o;let e=(o=n.parent)==null?void 0:o.path,t=e==="/"?"":e,i=n.name;for(let a=1;a<100;a++){let l=W(i),r=t+(t==""?"":"/")+l+` ${a}.md`;if(!(s.vault.getAbstractFileByPath(r)!==null))return r}}function Fe(s,n){let e=new URL(s.vault.getResourcePath(n));return e.host="localhosthostlocal",e.protocol="file",e.search="",e.pathname=decodeURIComponent(e.pathname),e.toString().replace("/localhosthostlocal/","/")}function ce(s,n,e){var a,l;let t=s.metadataCache.getFileCache(n),i=t.sections,o=(a=t.headings)==null?void 0:a.find(r=>r.heading===e);if(o){let r=i.findIndex(u=>u.type==="heading"&&u.position.start.line===o.position.start.line),c=i.slice(r+1),d=c==null?void 0:c.findIndex(u=>u.type==="heading");return{lastLine:((l=c[(d!==-1?d:c.length)-1])!=null?l:i[r]).position.end.line+1,firstLine:i[r].position.end.line+1}}else new Ae.Notice("Can't find heading")}var U=class extends Error{constructor(e,t,i){super(e);this.name="KeyPathError",this.errKey=t,i&&(this.cause=i)}};function Ce(s){let{originalObject:n,key:e,data:t}=s;if(e.startsWith("[")&&e.endsWith("]")){let i=e.substring(1,e.length-1).split(","),o=n;for(let a=0;a<i.length;a++){let l=i[a],r;if(o instanceof Array){if(r=parseInt(l),Number.isNaN(r)&&(r=o.find(p=>p==l)),r===void 0)throw new U(`Failed to resolve or convert "${l}" to a valid array index.`,l);r=Math.min(r,o.length),r=Math.max(r,-1)}if(a==i.length-1){o instanceof Array?r===-1?o.unshift(t):o[r]=t:o[l]=t;return}l
|
||
|
|
${r.message}`):new v.Notice("Failed to update frontmatter, check console for more details")}});return}z(Pe({obj:i,key:e}))}handleWorkspace(n){let e=this.app.internalPlugins.getEnabledPluginById("workspaces");if(!e)new v.Notice("Workspaces plugin is not enabled"),this.plugin.failure(n);else{if(n.saveworkspace=="true"){let t=e.activeWorkspace;e.saveWorkspace(t),new v.Notice(`Saved current workspace to ${t}`)}n.clipboard&&n.clipboard!="false"?this.tools.copyURI({workspace:e.activeWorkspace}):n.workspace!=null&&e.loadWorkspace(n.workspace),this.plugin.success(n)}}async handleCommand(n){if(n.filepath)if(n.mode){if(n.mode=="new"){let t=this.app.metadataCache.getFirstLinkpathDest(n.filepath,"/");t instanceof v.TFile&&(n.filepath=J(this.app,t))}await this.plugin.open({file:n.filepath,mode:"source",parameters:n});let e=this.app.workspace.getActiveViewOfType(v.MarkdownView);if(e){let t=e.editor,i=t.getValue();if(n.mode==="append"){t.setValue(i+`
|
||
|
|
`);let o=t.lineCount();t.setCursor({ch:0,line:o})}else n.mode==="prepend"?(t.setValue(`
|
||
|
|
`+i),t.setCursor({ch:0,line:0})):n.mode==="overwrite"&&t.setValue("")}}else n.line!=null||n.column!=null||n.offset!=null?(await this.plugin.open({file:n.filepath,mode:"source",parameters:n}),await this.plugin.setCursorInLine(n)):await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});else(n.openmode||n.viewmode)&&await this.plugin.open({parameters:n});if(n.commandid)this.app.commands.executeCommandById(n.commandid);else if(n.commandname){let e=this.app.commands.commands;for(let t in e)if(e[t].name===n.commandname){e[t].callback?await e[t].callback():e[t].checkCallback(!1);break}}if(n.confirm&&n.confirm!="false"){await new Promise(t=>setTimeout(t,750));let e=document.querySelector(".mod-cta:not([style*='display: none'])");e.click instanceof Function&&e.click()}this.plugin.success(n)}async handleEval(n){if(n.filepath)if(n.mode){if(n.mode=="new"){let t=this.app.metadataCache.getFirstLinkpathDest(n.filepath,"/");t instanceof v.TFile&&(n.filepath=J(this.app,t))}await this.plugin.open({file:n.filepath,mode:"source",parameters:n});let e=this.app.workspace.getActiveViewOfType(v.MarkdownView);if(e){let t=e.editor,i=t.getValue();if(n.mode==="append"){t.setValue(i+`
|
||
|
|
`);let o=t.lineCount();t.setCursor({ch:0,line:o})}else n.mode==="prepend"?(t.setValue(`
|
||
|
|
`+i),t.setCursor({ch:0,line:0})):n.mode==="overwrite"&&t.setValue("")}}else n.line!=null||n.column!=null||n.offset!=null?(await this.plugin.open({file:n.filepath,mode:"source",parameters:n}),await this.plugin.setCursorInLine(n)):await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});this.plugin.settings.allowEval?((0,eval)(n.eval),this.plugin.success(n)):(new v.Notice("Eval is not allowed. Please enable it in the settings."),this.plugin.failure(n))}async handleDoesFileExist(n){let e=await this.app.vault.adapter.exists(n.filepath);z((e?1:0).toString()),this.plugin.success(n)}async handleSearchAndReplace(n){let e;if(n.filepath){let t=this.app.vault.getAbstractFileByPath(n.filepath);t instanceof v.TFile&&(e=t)}else e=this.app.workspace.getActiveFile();if(e){let t=await this.app.vault.read(e);if(n.searchregex)try{let[,,i,o]=n.searchregex.match(/(\/?)(.+)\1([a-z]*)/i),a=new RegExp(i,o);t=t.replace(a,n.replace),this.plugin.success(n)}catch(i){new v.Notice(`Can't parse ${n.searchregex} as RegEx`),this.plugin.failure(n)}else t=t.replaceAll(n.search,n.replace),this.plugin.success(n);await this.plugin.writeAndOpenFile(e.path,t,n)}else new v.Notice("Cannot find file"),this.plugin.failure(n)}async handleSearch(n){n.filepath&&await this.plugin.open({file:n.filepath,parameters:n});let e=this.app.workspace.getActiveViewOfType(v.FileView);e.currentMode.showSearch();let t=e.currentMode.search;t.searchInputEl.value=n.search,t.searchInputEl.dispatchEvent(new Event("input"))}async handleWrite(n,e=!1){var i;let t;if(n.filepath?t=this.app.vault.getAbstractFileByPath(n.filepath):t=this.app.workspace.getActiveFile(),n.filepath||t){let o,a=(i=n.filepath)!=null?i:t.path;n.mode==="overwrite"?(o=await this.plugin.writeAndOpenFile(a,n.data,n),this.plugin.success(n)):n.mode==="prepend"?(t instanceof v.TFile?o=await this.plugin.prepend(t,n):o=await this.plugin.prepend(a,n),this.plugin.success(n)):n.mode==="append"?(t instanceof v.TFile?o=await this.plugin.append(t,n):o=await this.plugin.append(a,n),this.plugin.success(n)):n.mode==="new"?t instanceof v.TFile?(o=await this.plugin.writeAndOpenFile(J(this.app,t),n.data,n),this.plugin.hookSuccess(n,o)):(o=await this.plugin.writeAndOpenFile(a,n.data,n),this.plugin.hookSuccess(n,o)):!e&&t instanceof v.TFile?(new v.Notice("File already exists"),this.plugin.openExistingFileAndSetCursor(t.path,n),this.plugin.failure(n)):(o=await this.plugin.writeAndOpenFile(a,n.data,n),this.plugin.success(n)),n.uid&&this.tools.writeUIDToFile(o,n.uid)}else new v.Notice("Cannot find file"),this.plugin.failure(n)}async handleOpen(n){if(n.heading!=null){await this.plugin.open({file:n.filepath+"#"+n.heading,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});let e=this.app.workspace.getActiveViewOfType(v.MarkdownView);if(!e)return;let i=this.app.metadataCache.getFileCache(e.file).headings.find(o=>o.heading===n.heading);e.editor.focus(),e.editor.setCursor({line:i.position.start.line+1,ch:0})}else if(n.block!=null){await this.plugin.open({file:n.filepath+"#^"+n.block,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});let e=this.app.workspace.getActiveViewOfType(v.MarkdownView);if(!e)return;let i=this.app.metadataCache.getFileCache(e.file).blocks[n.block.toLowerCase()];e.editor.focus(),i&&e.editor.setCursor({line:i.position.start.line,ch:0})}else await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n}),(n.line!=null||n.column!=null||n.offset!=null)&&await this.plugin.setCursorInLine(n);if(n.mode!=null&&await this.plugin.setCursor(n),n.uid){let e=this.app.workspace.getActiveViewOfType(v.MarkdownView);this.tools.writeUIDToFile(e.file,n.uid)}this.plugin.success(n)}async handleOpenBlock(n){let e=this.tools.getFileFromBlockID(n.block);e&&await this.plugin.chooseHandler({...n,filepath:e.path},!1)}handleCopyFileURI(n,e,t){let i=this.app.workspace.getActiveViewOfType(v.FileView);if(!(!i&&!t)){if(t=t!=null?t:i.file,i instanceof v.MarkdownView){let o=i.editor.getCursor(),a=this.app.meta
|
||
|
|
`),l=`${this.plugin.settings.idField}:`;if(o)a.unshift("---"),a.unshift(`${l} ${e}`),a.unshift("---");else{let d=a.findIndex(p=>p.startsWith(l));d!=-1?a[d]=`${l} ${e}`:a.splice(1,0,`${l} ${e}`)}let r=a.join(`
|
||
|
|
`);return await this.app.vault.modify(n,r),e}async getUIDFromFile(n){var i;let e=(i=this.app.metadataCache.getFileCache(n))!=null?i:await new Promise(o=>{let a=this.app.metadataCache.on("changed",l=>{if(l.path==n.path){let r=this.app.metadataCache.getFileCache(n);this.app.metadataCache.offref(a),o(r)}})}),t=(0,C.parseFrontMatterEntry)(e.frontmatter,this.plugin.settings.idField);if(t!=null)return t instanceof Array?t[0]:t}async generateURI(n){var a;let e="obsidian://adv-uri",t="",i=this.app.vault.getAbstractFileByPath(n.filepath);this.settings.includeVaultName&&(t+="?vault=",this.settings.vaultParam=="id"&&this.app.appId?t+=encodeURIComponent(this.app.appId):t+=encodeURIComponent(this.app.vault.getName())),this.settings.useUID&&i instanceof C.TFile&&i.extension=="md"&&(this.settings.addFilepathWhenUsingUID||(n.filepath=void 0),n.uid=(a=await this.getUIDFromFile(i))!=null?a:await this.writeUIDToFile(i,pe()));let o=Object.keys(n).filter(l=>n[l]).sort((l,r)=>{let c=["filepath","filename","uid","daily"],d=["data","eval"];return c.includes(l)?-1:c.includes(r)||d.includes(l)?1:d.includes(r)?-1:0});for(let l of o)n[l]!=null&&(t+=t?"&":"?",t+=`${l}=${encodeURIComponent(n[l])}`);return t.endsWith("%20")&&(t+="&"),e+t}async copyURI(n,e=!1,t=void 0){var o,a;let i=await this.generateURI(n);if(e){let l=this.settings.linkFormats;if(l.length==0){new C.Notice("No link formats defined in the settings");return}let r;if(l.length==1)r=l[0];else{let d=l.map(h=>h.name),p=await new ne(this.plugin,{options:d,onlySelection:!0,placeholder:"Select link format"}).openAndGetResult();if(!p){new C.Notice("No link format selected");return}r=l.find(h=>h.name==p)}let c=r.format.replace(/\{\{uri\}\}/g,i).replace(/\{\{path\}\}/g,t==null?void 0:t.path).replace(/\{\{folder\}\}/g,(o=t==null?void 0:t.parent)==null?void 0:o.path).replace(/\{\{name\}\}/g,t==null?void 0:t.basename).replace(/\{\{vaultName\}\}/g,this.app.vault.getName()).replace(/\{\{vaultId\}\}/g,this.app.appId);if(t&&c.match(/\{\{uid\}\}/g)){let d=(a=await this.getUIDFromFile(t))!=null?a:t.basename;c=c.replace(/\{\{uid\}\}/g,d)}if(t&&c.match(/\{\{alias\}\}/g)){let d=(0,C.parseFrontMatterAliases)(this.app.metadataCache.getFileCache(t).frontmatter),p=d?d[0]:t==null?void 0:t.basename;c=c.replace(/\{\{alias\}\}/g,p)}await z(c),new C.Notice(`Advanced URI in format "${r.name}" copied to your clipboard`);return}await z(i),new C.Notice("Advanced URI copied to your clipboard")}getFileFromUID(n){var i;let e=this.app.vault.getMarkdownFiles(),t=this.settings.idField;for(let o of e){let a=(0,C.parseFrontMatterEntry)((i=this.app.metadataCache.getFileCache(o))==null?void 0:i.frontmatter,t);if(a instanceof Array){if(a.contains(n))return o}else if(a==n)return o}}getFileFromBlockID(n){var t,i;let e=this.app.vault.getMarkdownFiles();n=n.toLowerCase();for(let o of e)if(((i=(t=this.app.metadataCache.getFileCache(o))==null?void 0:t.blocks)==null?void 0:i[n])!=null)return o}};var oe=require("obsidian"),ie=class extends oe.FuzzySuggestModal{constructor(e){super(e.app);this.plugin=e,this.setPlaceholder("Choose a workspace")}getItems(){let e=this.app.internalPlugins.getEnabledPluginById("workspaces");if(!e)new oe.Notice("Workspaces plugin is not enabled");else return Object.keys(e.workspaces)}getItemText(e){return e}onChooseItem(e,t){this.plugin.tools.copyURI({workspace:e})}};var ae=class extends w.Plugin{constructor(){super(...arguments);this.handlers=new $(this);this.tools=new K(this)}async onload(){await this.loadSettings(),this.addSettingTab(new _(this.app,this)),this.addCommand({id:"copy-uri-current-file",name:"Copy URI for file with options",callback:()=>this.handlers.handleCopyFileURI(!1,!1)}),this.addCommand({id:"copy-uri-current-file-simple",name:"Copy URI for current file",callback:()=>this.handlers.handleCopyFileURI(!0,!1)}),this.addCommand({id:"copy-uri-current-file-with-format",name:"Copy formatted URI for file with options ",callback:()=>this.handlers.handleCopyFileURI(!1,!0)}),this.addCommand({id:"copy-uri-current-file-simple-with-format",name:"Copy formatted URI for current file",callback:()=>this.handlers
|
||
|
|
`),d;if(t.heading){let p=ce(this.app,e,t.heading);if(d=p==null?void 0:p.lastLine,d===void 0)return;p.firstLine==p.lastLine&&t.separator&&(t.separator=`
|
||
|
|
`+t.separator)}else t.line?d=Number(t.line):d=c.length;d=Math.max(1,d),c[d-1]=((a=c[d-1])!=null?a:"")+((l=t.separator)!=null?l:`
|
||
|
|
`)+t.data,o=c.join(`
|
||
|
|
`)}else i=e,o=t.data;return this.writeAndOpenFile(i,o,t)}async prepend(e,t){var a,l,r;let i,o;if(e instanceof w.TFile){i=e.path;let c=await this.app.vault.read(e),d=this.app.metadataCache.getFileCache(e),p=c.split(`
|
||
|
|
`),h;if(t.heading){if(h=(a=ce(this.app,e,t.heading))==null?void 0:a.firstLine,h===void 0)return;h+=1}else t.line?h=Number(t.line):d.frontmatterPosition?h=d.frontmatterPosition.end.line+2:h=1;h=Math.max(1,h),p[h-1]=`${t.data}${(l=t.separator)!=null?l:`
|
||
|
|
`}${(r=p[h-1])!=null?r:""}`,o=p.join(`
|
||
|
|
`)}else i=e,o=t.data;return this.writeAndOpenFile(i,o,t)}async writeAndOpenFile(e,t,i){let o=this.app.vault.getAbstractFileByPath(e);if(o instanceof w.TFile)await this.app.vault.modify(o,t);else{let a=e.split("/"),l=a.slice(0,a.length-1).join("/");a.length>1&&!(this.app.vault.getAbstractFileByPath(l)instanceof w.TFolder)&&await this.app.vault.createFolder(l),/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(t)?await this.app.vault.createBinary(e,(0,w.base64ToArrayBuffer)(t)):await this.app.vault.create(e,t)}return this.openExistingFileAndSetCursor(e,i),this.app.vault.getAbstractFileByPath(e)}async openExistingFileAndSetCursor(e,t){t.openmode!="silent"&&this.settings.openFileOnWrite&&(await this.open({file:e,setting:this.settings.openFileOnWriteInNewPane,parameters:t}),t.line!=null||t.column!=null||t.offset!=null?await this.setCursorInLine(t):t.mode!=null&&await this.setCursor(t))}async open({file:e,setting:t,parameters:i,supportPopover:o,mode:a}){var r;let l;if(i.openmode=="popover"&&(o==null||o)){let c=this.app.plugins.plugins["obsidian-hover-editor"];c||(new w.Notice("Cannot find Hover Editor plugin. Please file an issue."),this.failure(i)),await new Promise(d=>{l=c.spawnPopover(void 0,()=>{this.app.workspace.setActiveLeaf(l,{focus:!0}),d()})})}else{let c=t;if(i.newpane!==void 0&&(c=i.newpane=="true"),i.openmode!==void 0&&(i.openmode=="true"||i.openmode=="false"?c=i.openmode=="true":i.openmode=="popover"?c=!1:w.Platform.isMobile&&i.openmode=="window"||(c=i.openmode)),c=="silent")return;if(w.Platform.isMobileApp&&c=="window"&&(c=!0),e!=null){let d=!1;isBoolean(c)&&this.app.workspace.iterateAllLeaves(p=>{var h;if(((h=p.view.file)==null?void 0:h.path)===i.filepath){if(d&&p.width==0)return;d=!0,this.app.workspace.setActiveLeaf(p,{focus:!0}),l=p}})}l||(l=this.app.workspace.getLeaf(c),this.app.workspace.setActiveLeaf(l,{focus:!0}))}if(e instanceof w.TFile?await l.openFile(e):e!=null&&await this.app.workspace.openLinkText(e,"/",!1,a!=null?{state:{mode:a}}:re(i)),l.view instanceof w.MarkdownView){let c=l.getViewState();a!=null?c.state.mode=a:c.state={...c.state,...(r=re(i))==null?void 0:r.state},await l.setViewState(c)}return l}async setCursor(e){let t=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!t)return;let i=e.mode,o=t.editor,a=t.leaf.getViewState();if(a.state.mode="source",i==="append"){let l=o.lastLine(),r=o.getLine(l).length;await t.leaf.setViewState(a,{focus:!0}),o.setCursor({ch:r,line:l}),t.editor.scrollIntoView({from:{line:l,ch:r},to:{line:l,ch:r}},!0)}else i==="prepend"&&(await t.leaf.setViewState(a,{focus:!0}),o.setCursor({ch:0,line:0}),t.editor.scrollIntoView({from:{line:0,ch:0},to:{line:0,ch:0}},!0));await new Promise(l=>setTimeout(l,10)),e.viewmode=="preview"&&(a.state.mode="preview",await t.leaf.setViewState(a))}async setCursorInLine(e){let t=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!t)return;let i=t.leaf.getViewState(),o=e.line!=null?Number(e.line):void 0,a=e.column?Number(e.column):void 0;i.state.mode="source",await t.leaf.setViewState(i);let l,r;if(e.offset!=null){let c=t.editor.offsetToPos(Number(e.offset));l=c.line,r=c.ch}else{l=o!=null?Math.min(o-1,t.editor.lineCount()-1):t.editor.getCursor().line;let c=t.editor.getLine(l).length-1;r=Math.min(a-1,c)}t.editor.focus(),t.editor.setCursor({line:l,ch:r}),t.editor.scrollIntoView({from:{line:l,ch:r},to:{line:l,ch:r}},!0),await new Promise(c=>setTimeout(c,10)),e.viewmode=="preview"&&(i.state.mode="preview",await t.leaf.setViewState(i))}async loadSettings(){this.settings=Object.assign(ve,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};
|
||
|
|
//! All of these methods are taken from https://www.npmjs.com/package/obsidian-daily-notes-interface.
|
||
|
|
/*! Bundled license information:
|
||
|
|
|
||
|
|
feather-icons/dist/feather.js:
|
||
|
|
(*!
|
||
|
|
Copyright (c) 2016 Jed Watson.
|
||
|
|
Licensed under the MIT License (MIT), see
|
||
|
|
http://jedwatson.github.io/classnames
|
||
|
|
*)
|
||
|
|
*/
|
||
|
|
|
||
|
|
/* nosourcemap */
|