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
37 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
1 year ago
var re=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Se=(m,t)=>{for(var e in t)re(m,e,{get:t[e],enumerable:!0})},xe=(m,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Te(t))!Fe.call(m,i)&&i!==e&&re(m,i,{get:()=>t[i],enumerable:!(n=Ce(t,i))||n.enumerable});return m};var Ie=m=>xe(re({},"__esModule",{value:!0}),m);var Le={};Se(Le,{default:()=>se});module.exports=Ie(Le);var be=require("obsidian");var A=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 oe=require("obsidian"),V=class{static getFilePathWithNewExtension(t,e){return(0,oe.normalizePath)(t.parent.path+"/"+t.basename+"."+e)}static getFilePathExcludingExtension(t){return(0,oe.normalizePath)(t.parent.path+"/"+t.basename)}};var d=class{static setActive(t){d.isActive=t,d.isActive||this.clear()}static setAutoExpire(t){d.baseMinutesToExpire=t!=null?t:0,d.updateExpiryTime()}static setLevel(t){d.level!=t&&(d.allLevels.contains(t)&&(d.level=t),d.level=d.LevelFilename,this.clear())}static updateExpiryTime(){d.baseMinutesToExpire==0||d.baseMinutesToExpire==null?d.expiryTime=null:d.expiryTime=Date.now()+d.baseMinutesToExpire*1e3*60}static putByFile(t,e){if(!d.isActive)return;let n=d.getFileCacheKey(e);this.cache.put(n,t),d.updateExpiryTime()}static getByFile(t){if(!d.isActive)return d.blankPasswordAndHint;this.clearIfExpired(),d.updateExpiryTime();let e=d.getFileCacheKey(t);return this.cache.get(e,d.blankPasswordAndHint)}static putByPath(t,e){if(!d.isActive)return;let n=d.getPathCacheKey(e);this.cache.put(n,t),d.updateExpiryTime()}static getByPath(t){if(!d.isActive)return d.blankPasswordAndHint;this.clearIfExpired(),d.updateExpiryTime();let e=d.getPathCacheKey(t);return this.cache.get(e,d.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(d.level){case d.LevelParentPath:return e;default:return t}}static getFileCacheKey(t){switch(d.level){case d.LevelParentPath:return t.parent.path;default:return V.getFilePathExcludingExtension(t)}}static clearIfExpired(){d.expiryTime!=null&&(Date.now()<d.expiryTime||this.clear())}static clearForFile(t){let e=d.getFileCacheKey(t);this.cache.removeKey(e)}static clearForPath(t){let e=d.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){this.cache.clear()}},h=d;h.isActive=!0,h.blankPasswordAndHint={password:"",hint:""},h.cache=new J,h.baseMinutesToExpire=0,h.expiryTime=null,h.LevelFilename="filename",h.LevelParentPath="parentPath",h.allLevels=[d.LevelFilename,d.LevelParentPath],h.level=d.LevelFilename;var _=class extends A.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(),e.createEl("h1",{text:"Settings for Meld Encrypt"}),new A.Setting(e).setHeading().setName("Common Settings"),new A.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 A.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(),h.setActive(this.sett
2 years ago
1 year ago
`),await this.encodeAndSave(),h.putByFile({password:c,hint:f},this.file),this.currentEditNoteMode="Source",this.refreshView(2))},s=h.getByFile(this.file),r=s.password,o="",a=s.hint,u=E.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:c=>{r=c,u.setDesc(this.validatePassword(r)),g.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var l;r=c,r.length>0&&((l=g.controlEl.querySelector("input"))==null||l.focus())}}),g=E.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:c=>{o=c,u.setDesc(this.validatePassword(r)),g.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var f;o=c,r===o&&((f=p.controlEl.querySelector("input"))==null||f.focus())}}),p=new y.Setting(n).setName("Hint:").addText(c=>{c.setValue(a),c.onChange(l=>{a=l})});p.controlEl.on("keydown","*",c=>{c.key==="Enter"&&(c.preventDefault(),i(r,o,a))}),new y.Setting(n).addButton(c=>{c.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(l=>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=E.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=h.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 S.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=x.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 u=0;u<a.length;u++){let g=a[u];g instanceof Text&&(s?g.insertData(0," "):g.data.startsWith(" ")&&g.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)})}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(p,c,l)=>{let f=this.validatePassword(p),w=this.validateConfirm(p,c);a.setDesc(f),u.setDesc(w),f.length===0&&w.length===0&&(this.encryptionPassword=p,this.hint=l,this.encodeAndSave(),this.refreshView(2),h.putByFile({password:p,hint:l},this.file),new y.Notice("Passwo