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
39 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
11 months ago
var oe=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var xe=(m,t)=>{for(var e in t)oe(m,e,{get:t[e],enumerable:!0})},Se=(m,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ce(t))!Fe.call(m,i)&&i!==e&&oe(m,i,{get:()=>t[i],enumerable:!(n=Te(t,i))||n.enumerable});return m};var Ie=m=>Se(oe({},"__esModule",{value:!0}),m);var Le={};xe(Le,{default:()=>re});module.exports=Ie(Le);var be=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 ae=require("obsidian"),R=class{static getFilePathWithNewExtension(t,e){return(0,ae.normalizePath)(t.parent.path+"/"+t.basename+"."+e)}static getFilePathExcludingExtension(t){return(0,ae.normalizePath)(t.parent.path+"/"+t.basename)}};var g=class{static setActive(t){g.isActive=t,g.isActive||this.clear()}static setAutoExpire(t){g.baseMinutesToExpire=t!=null?t:0,g.updateExpiryTime()}static setLevel(t){g.level!=t&&(g.allLevels.contains(t)&&(g.level=t),g.level=g.LevelFilename,this.clear())}static updateExpiryTime(){g.baseMinutesToExpire==0||g.baseMinutesToExpire==null?g.expiryTime=null:g.expiryTime=Date.now()+g.baseMinutesToExpire*1e3*60}static putByFile(t,e){if(!g.isActive)return;let n=g.getFileCacheKey(e);this.cache.put(n,t),g.updateExpiryTime()}static getByFile(t){if(!g.isActive)return g.blankPasswordAndHint;this.clearIfExpired(),g.updateExpiryTime();let e=g.getFileCacheKey(t);return this.cache.get(e,g.blankPasswordAndHint)}static putByPath(t,e){if(!g.isActive)return;let n=g.getPathCacheKey(e);this.cache.put(n,t),g.updateExpiryTime()}static getByPath(t){if(!g.isActive)return g.blankPasswordAndHint;this.clearIfExpired(),g.updateExpiryTime();let e=g.getPathCacheKey(t);return this.cache.get(e,g.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(g.level){case g.LevelParentPath:return e;default:return t}}static getFileCacheKey(t){switch(g.level){case g.LevelParentPath:return t.parent.path;default:return R.getFilePathExcludingExtension(t)}}static clearIfExpired(){g.expiryTime!=null&&(Date.now()<g.expiryTime||this.clear())}static clearForFile(t){let e=g.getFileCacheKey(t);this.cache.removeKey(e)}static clearForPath(t){let e=g.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){this.cache.clear()}},f=g;f.isActive=!0,f.blankPasswordAndHint={password:"",hint:""},f.cache=new J,f.baseMinutesToExpire=0,f.expiryTime=null,f.LevelFilename="filename",f.LevelParentPath="parentPath",f.allLevels=[g.LevelFilename,g.LevelParentPath],f.level=g.LevelFilename;var _=class extends k.PluginSettingTab{constructor(e,n,i,s){super(e,n);this.plugin=n,this.settings=i,this.features=s}display(){let{containerEl:e}=this;e.empty(),new k.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting. (Recommended)").addToggle(r=>{r.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let n=()=>{if(!this.settings.rememberPassword){i.settingEl.hide(),s.settingEl.hide();return}i.settingEl.show(),s.settingEl.show();let r=this.settings.rememberPasswordTimeout,o=`For ${r} minutes`;r==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(r=>{r.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveSettings(),f.setActive(this.settings.rememberPassword),n()})});let i=new k.Setting(e).setDesc("The number of minutes to remember passwords.")
2 years ago
11 months ago
`),await this.encodeAndSave(),f.putByFile({password:d,hint:l},this.file),this.currentEditNoteMode="Source",this.refreshView(2))},s=f.getByFile(this.file),r=s.password,o="",a=s.hint,c=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:d=>{r=d,c.setDesc(this.validatePassword(r)),w.setDesc(this.validateConfirm(r,o))},onEnterCallback:d=>{var u;r=d,r.length>0&&((u=w.controlEl.querySelector("input"))==null||u.focus())}}),w=P.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:d=>{o=d,c.setDesc(this.validatePassword(r)),w.setDesc(this.validateConfirm(r,o))},onEnterCallback:d=>{var l;o=d,r===o&&((l=h.controlEl.querySelector("input"))==null||l.focus())}}),h=new y.Setting(n).setName("Hint:").addText(d=>{d.setValue(a),d.onChange(u=>{a=u})});h.controlEl.on("keydown","*",d=>{d.key==="Enter"&&(d.preventDefault(),i(r,o,a))}),new y.Setting(n).addButton(d=>{d.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(u=>i(r,o,a))})}addDecryptNoteView(e){this.addHeader(e,"This note is encrypted");let n=this.addUserInputContainer(e);new y.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:r=>{this.encryptionPassword=r,i.setDesc(this.validatePassword(this.encryptionPassword))},onEnterCallback:async()=>await this.handleDecryptButtonClick()});new y.Setting(n).addButton(r=>{r.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(o=>this.handleDecryptButtonClick())});let s=f.getByFile(this.file);this.encryptionPassword=s.password,s.password.length>0&&this.decryptWithPassword(s.password).then(r=>{r!=null&&(this.currentEditorSourceText=r,this.refreshView(2),new y.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 y.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,s)=>{i.key=="Tab"&&this.handleTabInEditor(i,n)}),n.on("input","*",async(i,s)=>{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 s=!e.shiftKey;for(let r=0;r<i.rangeCount;r++){let o=i.getRangeAt(r),a=this.getRangeNodes(o);for(let c=0;c<a.length;c++){let w=a[c];w instanceof Text&&(s?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"});y.MarkdownRenderer.renderMarkdown(this.currentEditorSourceText,n,this.file.path,this).catch(i=>{console.error(i)}),n.on("click","a.internal-link",async(i,s)=>{if(s instanceof HTMLAnchorElement){let r=(0,y.normalizePath)(decodeURI(s.pathname));this.app.workspace.openLinkText(r,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="",s="",r="",o=async(h,d,u)=>{let l=this.validatePassword(h),p=this.validateConfirm(h,d);a.setD