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.

12 lines
31 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
2 years ago
var Q=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var ye=(f,n)=>{for(var e in n)Q(f,e,{get:n[e],enumerable:!0})},we=(f,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ge(n))!fe.call(f,i)&&i!==e&&Q(f,i,{get:()=>n[i],enumerable:!(t=he(n,i))||t.enumerable});return f};var me=f=>we(Q({},"__esModule",{value:!0}),f);var xe={};ye(xe,{default:()=>J});module.exports=me(xe);var ue=require("obsidian");var T=require("obsidian");var _=class{constructor(){this.values=new Map}put(n,e){this.values.set(n,e)}get(n,e){var t;return(t=this.values.get(n))!=null?t:e}getFirst(n,e){for(let t=0;t<n.length;t++){let i=n[t];if(this.containsKey(i))return this.get(i,e)}return e}containsKey(n){return this.values.has(n)}getKeys(){return Array.from(this.values.keys())}removeKey(n){return this.values.delete(n)}clear(){this.values.clear()}};var y=class{static setActive(n){y.isActive=n,y.isActive||this.clear()}static setAutoExpire(n){y.baseMinutesToExpire=n!=null?n:0,y.updateExpiryTime()}static setLevel(n){y.level!=n&&(y.level=n,this.clear())}static updateExpiryTime(){y.baseMinutesToExpire==0||y.baseMinutesToExpire==null?y.expiryTime=null:y.expiryTime=Date.now()+y.baseMinutesToExpire*1e3*60}static putByPath(n,e){if(!y.isActive)return;let t=y.getPathCacheKey(e);this.cache.put(t,n),y.updateExpiryTime()}static getByPath(n){if(!y.isActive)return y.blankPasswordAndHint;this.clearIfExpired(),y.updateExpiryTime();let e=y.getPathCacheKey(n);return this.cache.get(e,y.blankPasswordAndHint)}static getPathCacheKey(n){let e=n.split("/").slice(0,-1).join("/");switch(y.level){case y.LevelParentPath:return e;default:return n}}static clearIfExpired(){y.expiryTime!=null&&(Date.now()<y.expiryTime||this.clear())}static clearForPath(n){let e=y.getPathCacheKey(n);this.cache.removeKey(e)}static clear(){this.cache.clear()}},u=y;u.isActive=!0,u.blankPasswordAndHint={password:"",hint:""},u.cache=new _,u.baseMinutesToExpire=0,u.expiryTime=null,u.LevelFullPath="fullPath",u.LevelParentPath="parentPath",u.level=y.LevelFullPath;var B=class extends T.PluginSettingTab{constructor(e,t,i,s){super(e,t);this.plugin=t,this.settings=i,this.features=s}display(){let{containerEl:e}=this;e.empty(),e.createEl("h1",{text:"Settings for Meld Encrypt"}),new T.Setting(e).setHeading().setName("Common Settings"),new T.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting.").addToggle(r=>{r.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let t=()=>{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="Always"),i.setName(`Remember Password (${o})`)};new T.Setting(e).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting.").addToggle(r=>{r.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveSettings(),u.setActive(this.settings.rememberPassword),t()})});let i=new T.Setting(e).setDesc("The number of minutes to remember passwords.").addSlider(r=>{r.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(async o=>{this.settings.rememberPasswordTimeout=o,await this.plugin.saveSettings(),u.setAutoExpire(this.settings.rememberPasswordTimeout),t()})}),s=new T.Setting(e).setDesc("Remember passwords by using").addDropdown(r=>{r.addOption(u.LevelFullPath,"Full Path").addOption(u.LevelParentPath,"Parent Path").setValue(this.settings.rememberPasswordLevel).onChange(async o=>{this.settings.rememberPasswordLevel=o,await this.plugin.saveSettings(),u.setLevel(this.settings.rememberPasswordLevel),t()})});t(),this.features.forEach(r=>{r.buildSettingsUi(e,async()=>await this.plugin.saveSettings())})}};var P=require("obsidian");var k=require("obsidian"),I=class extends k.Modal{constructor(e,t,i=""){super(e);this.decryptInPlace=!1;this.canDecryptInPlac
`).slice(e,t+1).join(`
`)}static findFirstMarker(n,e,t=0){let i=null,s=null;return n.forEach(r=>{let o=e.indexOf(r,t);o!=-1&&(i==null||o<i)&&(i=o,s=r)}),s==null||i==null?null:{marker:s,position:i}}};var v=require("obsidian");var m=require("obsidian");var V=class{static get showInlineTitle(){var n;return(n=app.vault.getConfig("showInlineTitle"))!=null?n:!0}static get readableLineLength(){var n;return(n=app.vault.getConfig("readableLineLength"))!=null?n:!0}};var K="meld-encrypted-file-content-view",q=class extends m.TextFileView{constructor(e,t){var i;super(e);this.iconReadingView="book-open";this.iconSourceView="code";this.iconToggleEditView="edit";this.iconLockFile="lock";this.iconChangePassword="key";this.currentView=0;this.encryptionPassword="";this.hint="";this.currentEditorSourceText="";this.settings=t,this.defaultEditNoteView=(i=t.defaultView)!=null?i:"Source",this.currentEditNoteMode=this.defaultEditNoteView,this.elActionEditView=this.addAction(this.iconSourceView,"Source",()=>this.actionToggleEditMode()),this.elActionReadingView=this.addAction(this.iconReadingView,"Reading",()=>this.actionToggleEditMode()),this.elActionIconLockNote=this.addAction(this.iconLockFile,"Lock",()=>this.actionLockFile()),this.elActionChangePassword=this.addAction(this.iconChangePassword,"Change Password",()=>this.actionChangePassword()),this.elActionEditView.hide(),this.elActionReadingView.hide(),this.elActionIconLockNote.hide(),this.elActionChangePassword.hide(),this.containerEl.classList.add("meld-encrypt-encrypted-note-view"),this.contentEl.classList.add("meld-encrypt-encrypted-note-view-content")}actionToggleEditMode(){this.currentView==2&&(this.currentEditNoteMode=="Reading"?this.currentEditNoteMode="Source":this.currentEditNoteMode=="Source"&&(this.currentEditNoteMode="Reading"),this.refreshView(2))}actionLockFile(){this.encryptionPassword="",u.clearForPath(this.file.path),this.refreshView(1)}actionChangePassword(){this.refreshView(3)}onPaneMenu(e,t){t=="tab-header"&&this.currentView==2&&(e.addItem(i=>{i.setSection("action").setIcon(this.iconToggleEditView).setTitle("Toggle Editing/Reading").onClick(()=>this.actionToggleEditMode())}),e.addItem(i=>{i.setSection("action").setIcon(this.iconLockFile).setTitle("Lock").onClick(()=>this.actionLockFile())}),e.addItem(i=>{i.setSection("action").setIcon(this.iconChangePassword).setTitle("Change Password").onClick(()=>this.actionChangePassword())})),super.onPaneMenu(e,t)}addHeader(e,t){var i;e.createDiv({text:`\u{1F510} ${t} \u{1F510}`,cls:"encrypted-note-message"}),V.showInlineTitle&&e.createDiv({text:(i=this.file)==null?void 0:i.basename,cls:"inline-title"})}validatePassword(e){return e.length==0?"Password is too short":""}validateConfirm(e,t){return e===t?"":"Password doesn't match"}addNewNoteView(e){this.addHeader(e,"This note will be encrypted");let t=this.addUserInputContainer(e);new m.Setting(t).setDesc("Please provide a password and hint to start editing this note.");let i=async(c,d,g)=>{let w=this.validatePassword(c),M=this.validateConfirm(c,d);p.setDesc(w),h.setDesc(M),w.length===0&&M.length===0&&(this.encryptionPassword=c,this.hint=g,V.showInlineTitle||(this.currentEditorSourceText=`# ${this.file.basename}
2 years ago
2 years ago
`),await this.encodeAndSave(),u.putByPath({password:c,hint:g},this.file.path),this.currentEditNoteMode="Source",this.refreshView(2))},s=u.getByPath(this.file.path),r=s.password,o="",a=s.hint,p=b.buildPasswordSetting({container:t,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:c=>{r=c,p.setDesc(this.validatePassword(r)),h.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var d;r=c,r.length>0&&((d=h.controlEl.querySelector("input"))==null||d.focus())}}),h=b.buildPasswordSetting({container:t,name:"Confirm:",autoFocus:!1,onChangeCallback:c=>{o=c,p.setDesc(this.validatePassword(r)),h.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var g;o=c,r===o&&((g=l.controlEl.querySelector("input"))==null||g.focus())}}),l=new m.Setting(t).setName("Hint:").addText(c=>{c.setValue(a),c.onChange(d=>{a=d})});l.controlEl.on("keydown","*",c=>{c.key==="Enter"&&(c.preventDefault(),i(r,o,a))}),new m.Setting(t).addButton(c=>{c.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(d=>i(r,o,a))})}addDecryptNoteView(e){this.addHeader(e,"This note is encrypted");let t=this.addUserInputContainer(e);new m.Setting(t).setDesc("Please provide a password to unlock this note."),b.buildPasswordSetting({container:t,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s},onEnterCallback:async()=>await this.handleDecryptButtonClick()}),new m.Setting(t).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(r=>this.handleDecryptButtonClick())});let i=u.getByPath(this.file.path);this.encryptionPassword=i.password,this.decryptWithPassword(i.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 L.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=O.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 t=e.createDiv({cls:"editor-source-view"});t.spellcheck=!0,t.autocapitalize="on",t.translate=!1,t.contentEditable="true",t.innerText=this.currentEditorSourceText,t.focus(),t.on("input","*",async(i,s)=>{this.currentEditorSourceText=t.innerText,await this.encodeAndSave()})}addEditorReadingView(e){this.elActionEditView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Reading an encrypted note");let t=e.createDiv({cls:"editor-reading-view"});m.MarkdownRenderer.renderMarkdown(this.currentEditorSourceText,t,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 t=this.addUserInputContainer(e),i="",s="",r="",o=async(l,c,d)=>{let g=this.validatePassword(l),w=this.validateConfirm(l,c);a.setDesc(g),p.setDesc(w),g.length===0&&w.length===0&&(this.encryptionPassword=l,this.hint=d,this.encodeAndSave(),this.refreshView(2),u.putByPath({password:l,hint:d},this.file.path),new m.Notice("Password and Hint were changed"))},a=b.buildPasswordSetting({container:t,name:"New Password:",autoFocus:!0,onChangeCallback:l=>{i=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var c;i=l,i.length>0&&((c=p.controlEl.querySelector("input"))==null||c.focus())}}),p=b.buildPasswordSetting({container:t,name:"Confirm:",onChangeCallback:l=>{s=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var d;s=l,i===s&&((d=h.controlEl.querySelector("input"))==null||d.focus())}}),h=new m.Setting(t).setName("New Hint:").addText(l=>{l.onChange(c=>{r=c})});h.controlEl.on("keydown","*",l=>{l.key==="Enter"&&(l.preventDefault(),o(i,s,r))}),new m.Setting(t).addButton(l=>{l.removeCta().setIcon("cross").setTooltip("Cancel").onClick(()=>{this.refreshView(2)})}).addButton(l=>{l.setCta().setIcon("check