You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
40 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
3 years ago
8 months ago
var ae=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var Fe=(y,t)=>{for(var e in t)ae(y,e,{get:t[e],enumerable:!0})},Se=(y,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ce(t))!xe.call(y,i)&&i!==e&&ae(y,i,{get:()=>t[i],enumerable:!(n=Te(t,i))||n.enumerable});return y};var Ie=y=>Se(ae({},"__esModule",{value:!0}),y);var Le={};Fe(Le,{default:()=>re});module.exports=Ie(Le);var oe=require("obsidian");var k=require("obsidian");var J=class{constructor(){this.values=new Map}put(t,e){this.values.set(t,e)}get(t,e){var n;return(n=this.values.get(t))!=null?n:e}getFirst(t,e){for(let n=0;n<t.length;n++){let i=t[n];if(this.containsKey(i))return this.get(i,e)}return e}containsKey(t){return this.values.has(t)}getKeys(){return Array.from(this.values.keys())}removeKey(t){return this.values.delete(t)}clear(){this.values.clear()}};var le=require("obsidian"),R=class{static getFilePathWithNewExtension(t,e){return(0,le.normalizePath)(t.parent.path+"/"+t.basename+"."+e)}static getFilePathExcludingExtension(t){return(0,le.normalizePath)(t.parent.path+"/"+t.basename)}};var p=class{static setActive(t){p.isActive=t,p.isActive||this.clear()}static setAutoExpire(t){p.baseMinutesToExpire=t!=null?t:0,p.updateExpiryTime()}static setLevel(t){p.level!=t&&(p.allLevels.contains(t)&&(p.level=t),p.level=p.LevelFilename,this.clear())}static updateExpiryTime(){p.baseMinutesToExpire==0||p.baseMinutesToExpire==null?p.expiryTime=null:p.expiryTime=Date.now()+p.baseMinutesToExpire*1e3*60}static putByFile(t,e){if(!p.isActive)return;let n=p.getFileCacheKey(e);this.cache.put(n,t),p.updateExpiryTime()}static getByFile(t){if(!p.isActive)return p.blankPasswordAndHint;this.clearIfExpired(),p.updateExpiryTime();let e=p.getFileCacheKey(t);return this.cache.get(e,p.blankPasswordAndHint)}static putByPath(t,e){if(!p.isActive)return;let n=p.getPathCacheKey(e);this.cache.put(n,t),p.updateExpiryTime()}static getByPath(t){if(!p.isActive)return p.blankPasswordAndHint;this.clearIfExpired(),p.updateExpiryTime();let e=p.getPathCacheKey(t);return this.cache.get(e,p.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(p.level){case p.LevelVault:return"$vault";case p.LevelParentPath:return e;default:return t}}static getFileCacheKey(t){switch(p.level){case p.LevelVault:return"$vault";case p.LevelParentPath:return t.parent.path;default:return R.getFilePathExcludingExtension(t)}}static clearIfExpired(){p.expiryTime!=null&&(Date.now()<p.expiryTime||this.clear())}static clearForFile(t){let e=p.getFileCacheKey(t);this.cache.removeKey(e)}static clearForPath(t){let e=p.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){let t=this.cache.getKeys().length;return this.cache.clear(),t}},g=p;g.isActive=!0,g.blankPasswordAndHint={password:"",hint:""},g.cache=new J,g.baseMinutesToExpire=0,g.expiryTime=null,g.LevelFilename="filename",g.LevelParentPath="parentPath",g.LevelVault="vault",g.allLevels=[p.LevelFilename,p.LevelParentPath,p.LevelVault],g.level=p.LevelVault;var _=class extends k.PluginSettingTab{constructor(e,n,i,r){super(e,n);this.plugin=n,this.settings=i,this.features=r}display(){let{containerEl:e}=this;e.empty(),new k.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting. (Recommended)").addToggle(s=>{s.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let n=()=>{if(!this.settings.rememberPassword){i.settingEl.hide(),r.settingEl.hide();return}i.settingEl.show(),r.settingEl.show();let s=this.settings.rememberPasswordTimeout,o=`For ${s} minutes`;s==0&&(o="Until Obsidian is closed"),i.setName(`Remember Password (${o})`)};new k.Setting(e).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting. Passwords are remembered until they timeout or Obsidian is closed").addToggle(s=>{s.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveS
2 years ago
8 months ago
`),await this.encodeAndSave(),g.putByFile({password:d,hint:c},this.file),this.currentEditNoteMode="Source",this.refreshView(2))},r=g.getByFile(this.file),s=r.password,o="",a=r.hint,l=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:s,onChangeCallback:d=>{s=d,l.setDesc(this.validatePassword(s)),w.setDesc(this.validateConfirm(s,o))},onEnterCallback:d=>{var h;s=d,s.length>0&&((h=w.controlEl.querySelector("input"))==null||h.focus())}}),w=P.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:d=>{o=d,l.setDesc(this.validatePassword(s)),w.setDesc(this.validateConfirm(s,o))},onEnterCallback:d=>{var c;o=d,s===o&&((c=f.controlEl.querySelector("input"))==null||c.focus())}}),f=new m.Setting(n).setName("Hint:").addText(d=>{d.setValue(a),d.onChange(h=>{a=h})});f.controlEl.on("keydown","*",d=>{d.key==="Enter"&&(d.preventDefault(),i(s,o,a))}),new m.Setting(n).addButton(d=>{d.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(h=>i(s,o,a))})}addDecryptNoteView(e){this.addHeader(e,"This note is encrypted");let n=this.addUserInputContainer(e);new m.Setting(n).setDesc("Please provide a password to unlock this note.");let i=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s,i.setDesc(this.validatePassword(this.encryptionPassword))},onEnterCallback:async()=>await this.handleDecryptButtonClick()});new m.Setting(n).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(o=>this.handleDecryptButtonClick())});let r=g.getByFile(this.file);this.encryptionPassword=r.password,r.password.length>0&&this.decryptWithPassword(r.password).then(s=>{s!=null&&(this.currentEditorSourceText=s,this.refreshView(2),new m.Notice("Decrypted using remembered password",2e3))})}async encodeAndSave(){try{let e=await I.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=D.encode(e),this.requestSave()}catch(e){console.error(e),new m.Notice(e,1e4)}}addEditorSourceView(e){this.elActionReadingView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Editing an encrypted note");let n=e.createDiv({cls:"editor-source-view"},i=>{i.spellcheck=!0,i.autocapitalize="on",i.translate=!1,i.contentEditable="plaintext-only",i.style.tabSize="4",i.innerText=this.currentEditorSourceText});n.focus(),n.on("keydown","*",(i,r)=>{i.key=="Tab"&&this.handleTabInEditor(i,n)}),n.on("input","*",async(i,r)=>{this.updateAndSaveEditorSourceText(n)})}async updateAndSaveEditorSourceText(e){this.currentEditorSourceText=e.innerText,await this.encodeAndSave()}handleTabInEditor(e,n){let i=window.getSelection();if(i==null||i.rangeCount<1)return;e.preventDefault();let r=!e.shiftKey;for(let s=0;s<i.rangeCount;s++){let o=i.getRangeAt(s),a=this.getRangeNodes(o);for(let l=0;l<a.length;l++){let w=a[l];w instanceof Text&&(r?w.insertData(0," "):w.data.startsWith(" ")&&w.replaceData(0,1,""))}}this.updateAndSaveEditorSourceText(n)}getRangeNodes(e){let n=Array();if(e.startContainer==e.endContainer)return[e.startContainer];let i=e.startContainer;for(i==e.commonAncestorContainer&&(i=e.commonAncestorContainer.firstChild);i!=null;)e.intersectsNode(i)&&n.push(i),i=i.nextSibling;return n}addEditorReadingView(e){this.elActionEditView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Reading an encrypted note");let n=e.createDiv({cls:"editor-reading-view"});m.MarkdownRenderer.renderMarkdown(this.currentEditorSourceText,n,this.file.path,this).catch(i=>{console.error(i)}),n.on("click","a.internal-link",async(i,r)=>{if(r instanceof HTMLAnchorElement){let s=(0,m.normalizePath)(decodeURI(r.pathname));this.app.workspace.openLinkText(s,this.file.path,i.ctrlKey)}})}addUserInputContainer(e){return e.createDiv({cls:"input-container"})}addChangePasswordView(e){this.addHeader(e,"Change encrypted note password");let n=this.addUserInputContainer(e),i="",r="",s="",o=async(f,d,h)=>{let c=this.validatePassword(f),u=this.validateConfirm(f,d);a.setD