diff --git a/Blogger/README.md b/Blogger/README.md index 79b221f..8b57be7 100644 --- a/Blogger/README.md +++ b/Blogger/README.md @@ -6,6 +6,7 @@ Blackend for my blog at https://blog.iohub.dev ## Change logs ### v0.2.x-a +* Patch 9: Update to use the new MDE library * Patch 8: Support for antOS 2.0.x * Patch 7: Fix sendmail API security bug * Patch 6: Chage libraries load order diff --git a/Blogger/build/debug/README.md b/Blogger/build/debug/README.md index 79b221f..8b57be7 100644 --- a/Blogger/build/debug/README.md +++ b/Blogger/build/debug/README.md @@ -6,6 +6,7 @@ Blackend for my blog at https://blog.iohub.dev ## Change logs ### v0.2.x-a +* Patch 9: Update to use the new MDE library * Patch 8: Support for antOS 2.0.x * Patch 7: Fix sendmail API security bug * Patch 6: Chage libraries load order diff --git a/Blogger/build/debug/main.js b/Blogger/build/debug/main.js index 18f370e..985e4f6 100644 --- a/Blogger/build/debug/main.js +++ b/Blogger/build/debug/main.js @@ -1 +1 @@ -(function(){var t,e,i,s,a,n;(e=class extends this.OS.application.BaseApplication{constructor(t){super("Blogger",t)}main(){var t;return this.user={},this.cvlist=this.find("cv-list"),this.cvlist.ontreeselect=t=>{var e;if(t)return e=t.data.item.data,this.CVSectionByCID(Number(e.id))},this.inputtags=this.find("input-tags"),this.bloglist=this.find("blog-list"),this.seclist=this.find("cv-sec-list"),t=this.find("photo"),$(t).click(e=>this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"]}).then(e=>t.value=e.file.path).catch(t=>this.error(__("Unable to get file"),t))),this.userdb=new this._api.DB("user"),this.cvcatdb=new this._api.DB("cv_cat"),this.cvsecdb=new this._api.DB("cv_sections"),this.blogdb=new this._api.DB("blogs"),this.tabcontainer=this.find("tabcontainer"),this.tabcontainer.ontabselect=t=>this.fetchData(t.data.container.aid),this.find("bt-user-save").onbtclick=t=>this.saveUser(),this.find("cv-cat-add").onbtclick=t=>{var e;return e=t=>this.openDialog(new s,{title:__("Add category"),tree:t}).then(t=>{var e;return e={name:t.value,pid:t.p.id,publish:1},this.cvcatdb.save(e).then(t=>this.refreshCVCat()).catch(t=>this.error(__("Cannot add new category"),t))}).catch(t=>this.error(t.toString(),t)),this.fetchCVCat().then(t=>e(t)).catch(t=>(e({text:"Porfolio",id:"0",nodes:[]}),this.error(__("Unable to fetch categories"),t)))},this.find("cv-cat-edit").onbtclick=t=>{var e,i;if((i=this.cvlist.selectedItem)&&(e=i.data))return this.fetchCVCat().then(t=>this.openDialog(new s,{title:__("Edit category"),tree:t,cat:e}).then(t=>{var i;return i={id:e.id,publish:e.publish,pid:t.p.id,name:t.value},this.cvcatdb.save(i).then(t=>this.refreshCVCat()).catch(t=>this.error(__("Cannot Edit category"),t))})).catch(t=>this.error(__("Unable to fetch categories"),t))},this.find("cv-cat-del").onbtclick=t=>{var e,i;if((i=this.cvlist.selectedItem)&&(e=i.data))return this.openDialog("YesNoDialog",{title:__("Delete category"),iconclass:"fa fa-question-circle",text:__("Do you really want to delete: {0}?",e.name)}).then(t=>{if(t)return this.deleteCVCat(e)}).catch(t=>this.error(t.toString(),t))},this.find("cv-sec-add").onbtclick=t=>{var e,s;if(s=this.cvlist.selectedItem)return(e=s.data)&&"0"!==e.id?this.openDialog(new i(this),{title:__("New section entry for {0}",e.name)}).then(t=>(t.cid=Number(e.id),t.start=Number(t.start),t.end=Number(t.end),this.cvsecdb.save(t).then(t=>this.CVSectionByCID(Number(e.id))).catch(t=>this.error(__("Cannot save section: {0}",t.toString()),t)))):this.notify(__("Please select a category"))},this.find("cv-sec-move").onbtclick=t=>{var e,i;return(i=this.find("cv-sec-list").selectedItem)?(e=i.data,this.fetchCVCat().then(t=>this.openDialog(new s,{title:__("Move to"),tree:t,selonly:!0}).then(t=>{var i;return i={id:e.id,cid:t.p.id},this.cvsecdb.save(i).then(t=>(this.CVSectionByCID(e.cid),this.find("cv-sec-list").unselect())).catch(t=>this.error(__("Cannot move section"),t))}))):this.notify(__("Please select a section to move"))},this.find("cv-sec-edit").onbtclick=t=>{var e,s;return(s=this.find("cv-sec-list").selectedItem)?(e=s.data,this.openDialog(new i(this),{title:__("Modify section entry"),section:e}).then(t=>(t.cid=Number(e.cid),t.start=Number(t.start),t.end=Number(t.end),this.cvsecdb.save(t).then(t=>this.CVSectionByCID(Number(e.cid))).catch(t=>this.error(__("Cannot save section: {0}",t.toString()),t))))):this.notify(__("Please select a section to edit"))},this.seclist.onitemclose=t=>{var e;if(t)return e=t.data.item.data,this.openDialog("YesNoDialog",{iconclass:"fa fa-question-circle",text:__("Do you really want to delete: {0}?",e.title)}).then(i=>{if(i)return this.cvsecdb.delete(e.id).then(e=>this.seclist.delete(t.data.item)).catch(t=>this.error(__("Cannot delete the section: {0}",t.toString()),t))}),!1},this.editor=new SimpleMDE({element:this.find("markarea"),autoDownloadFontAwesome:!1,autofocus:!0,tabSize:4,indentWithTabs:!0,toolbar:[{name:__("New"),className:"fa fa-file",action:t=>(this.bloglist.unselect(),this.clearEditor())},{name:__("Save"),className:"fa fa-save",action:t=>this.saveBlog()},"|","bold","italic","heading","|","quote","code","unordered-list","ordered-list","|","link","image","table","horizontal-rule",{name:"image",className:"fa fa-file-image-o",action:t=>this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"]}).then(t=>t.file.path.asFileHandle().publish().then(t=>this.editor.codemirror.getDoc().replaceSelection(`![](${this._api.handle.shared}/${t.result})`)).catch(t=>this.error(__("Cannot export file for embedding to text"),t)))},{name:"Youtube",className:"fa fa-youtube",action:t=>this.editor.codemirror.getDoc().replaceSelection("[[youtube:]]")},"|",{name:__("Preview"),className:"fa fa-eye no-disable",action:t=>(this.previewOn=!this.previewOn,SimpleMDE.togglePreview(t),renderMathInElement(this.find("editor-container")))},"|",{name:__("Send mail"),className:"fa fa-paper-plane",action:t=>{var e,i;return(i=this.bloglist.selectedItem)?(e=i.data,this.openDialog(new a(this),{title:__("Send mail"),content:this.editor.value(),id:e.id}).then((function(t){return console.log("Email sent")}))):this.error(__("No post selected"))}}]}),this.bloglist.onlistselect=e=>{var i;if((t=this.bloglist.selectedItem)&&(i=t.data))return this.blogdb.get(Number(i.id)).then(t=>(this.editor.value(t.content),this.inputtags.value=t.tags,this.find("blog-publish").swon=!!Number(t.publish))).catch(t=>this.error(__("Cannot fetch the entry content"),t))},this.bloglist.onitemclose=e=>{var i;if(e)return t=e.data.item,i=t.data,this.openDialog("YesNoDialog",{title:__("Delete a post"),iconclass:"fa fa-question-circle",text:__("Do you really want to delete this post ?")}).then(e=>{if(e)return this.blogdb.delete(i.id).then(e=>(this.bloglist.delete(t),this.bloglist.unselect(),this.clearEditor()))}),!1},this.bindKey("CTRL-S",()=>{var t;if((t=this.tabcontainer.selectedTab)&&"blog-container"===t.container.aid)return this.saveBlog()}),this.on("vboxchange",()=>this.resizeContent()),this.resizeContent(),this.loadBlogs()}fetchData(t){switch(t){case"user-container":return this.userdb.get(null).then(t=>{var e,i,s,a,n;for(this.user=t[0],a=[],e=0,s=(i=this.select("[input-class='user-input']")).length;ethis.error(__("Cannot fetch user data"),t));case"cv-container":return this.refreshCVCat();default:return this.loadBlogs()}}saveUser(){var t,e,i,s;for(t=0,i=(e=this.select("[input-class='user-input']")).length;tthis.notify(__("User data updated"))).catch(t=>this.error(__("Cannot save user data"),t)):this.notify(__("Full name must be entered"))}refreshCVCat(){return this.fetchCVCat().then(t=>(this.cvlist.data=t,this.cvlist.expandAll())).catch(t=>this.error(__("Unable to load categories"),t))}fetchCVCat(){return new Promise((t,e)=>{var i,s;return s={text:"Porfolio",id:"0",nodes:[]},i={order:{name:"ASC"}},this.cvcatdb.find(i).then(e=>(this.catListToTree(e,s,"0"),t(s))).catch((function(t){return e(__e(t))}))})}catListToTree(t,e,i){var s,a,n,r,o;if(0===(n=function(){var e,s,a;for(a=[],e=0,s=t.length;e(e=function(){var t,e,i;for(i=[],t=0,e=s.length;t(this.refreshCVCat(),this.seclist.data=[])).catch(e=>this.error(__("Cannot delete the category: {0} [{1}]",t.name,e.toString()),e)))).catch(e=>this.error(__("Cannot delete all content of: {0} [{1}]",t.name,e.toString()),e))}CVSectionByCID(t){var e;return e={exp:{"=":{cid:t}},order:{start:"DESC"}},this.cvsecdb.find(e).then(t=>{var e,i,s,a;for(i=[],this.find("cv-sec-status").text=__("Found {0} sections",t.length),e=0,s=t.length;ethis.error(t.toString(),t))}saveBlog(){var t,e,i,s,a,n,r;return s=void 0,(a=this.bloglist.selectedItem)&&(s=a.data),n=this.inputtags.value,t=this.editor.value(),(r=new RegExp("^#+(.*)\n","g").exec(t))&&2===r.length?""===n?this.notify(__("Please enter tags")):(e=new Date,i={content:t,title:r[1].trim(),tags:n,ctime:s?s.ctime:e.timestamp(),ctimestr:s?s.ctimestr:e.toString(),utime:e.timestamp(),utimestr:e.toString(),rendered:this.process(this.editor.options.previewRender(t)),publish:this.find("blog-publish").swon?1:0},s&&(i.id=s.id),this.blogdb.save(i).then(t=>this.loadBlogs()).catch(t=>this.error(__("Cannot save blog: {0}",t.toString()),t))):this.notify(__("Please insert a title in the text: beginning with heading"))}process(t){var e,i,s,a,n,r,o,l,h;for(i=function(t){return``},o=/\[\[youtube:([^\]]*)\]\]/g,l=[];null!==(s=o.exec(t));)l.push(s);if(!(l.length>0))return t;for(h="",e=0,a=0,r=l.length;a{var e,s;for(e=0,s=t.length;ethis.error(__("No post found: {0}",t.toString()),t))}resizeContent(){var t,e,i,s,a,n;return i=this.find("editor-container"),e=$(i).children(),a=$(this.scheme).find(".afx-window-top")[0],n=e[1],s=e[4],t=$(this.scheme).height()-$(a).height()-$(n).height()-$(s).height()-90,$(e[2]).css("height",t+"px")}}).singleton=!0,e.dependencies=["pkg://SimpleMDE/main.js","pkg://SimpleMDE/main.css","pkg://Katex/main.js","pkg://Katex/main.css"],this.OS.register("Blogger",e),(s=class t extends this.OS.GUI.BasicDialog{constructor(){super("BloggerCategoryDialog",t.scheme)}main(){var t;if(super.main(),this.tree=this.find("tree"),this.txtinput=this.find("txtinput"),this.find("bt-ok").onbtclick=t=>{var e,i,s;return(e=this.tree.selectedItem)?(i=e.data,""!==(s=this.txtinput.value)||this.data.selonly?this.data.cat&&this.data.cat.id===i.id?this.notify(__("Parent can not be the category itself")):(this.handle&&this.handle({p:i,value:s}),this.quit()):this.notify(__("Please enter category name"))):this.notify(__("Please select a parent category"))},this.find("bt-cancel").onbtclick=t=>this.quit(),this.data&&this.data.tree)return this.data&&this.data.cat&&(this.txtinput.value=this.data.cat.name,(t="0"===this.data.cat.pid?this.data.tree:this.findDataByID(this.data.cat.pid,this.data.tree.nodes))&&(t.selected=!0)),this.tree.data=this.data.tree,this.tree.expandAll()}findDataByID(t,e){var i,s,a;for(s=0,a=e.length;s\n \n \n \n \n \n \n
\n \n \n
\n
\n
\n',i=class extends this.OS.GUI.BasicDialog{constructor(t){super("BloggerCVSectionDiaglog",(t.meta().path+"/cvsection.html").asFileHandle())}main(){var t,e;return super.main(),this.editor=new SimpleMDE({autoDownloadFontAwesome:!1,element:this.find("contentarea"),status:!1,toolbar:!1}),$(this.select('[class = "CodeMirror-scroll"]')[0]).css("min-height","50px"),$(this.select('[class="CodeMirror cm-s-paper CodeMirror-wrap"]')[0]).css("min-height","50px"),t=this.select("[input-class='user-input']"),this.data&&this.data.section&&function(){var i,s,a;for(a=[],i=0,s=t.length;i{var s,a,n,r;for(s={},a=0,n=t.length;athis.resizeContent()),this.resizeContent()}resizeContent(){var t,e,i;return i=this.find("editor-container"),e=$(i).children(),t=$(i).height()-30,$(e[1]).css("height",t+"px")}},(a=class t extends this.OS.GUI.BasicDialog{constructor(t){super("BloggerSendmailDiaglog",(t.meta().path+"/sendmail.html").asFileHandle())}main(){var e,i;return super.main(),this.subdb=new this.parent._api.DB("subscribers"),this.maillinglist=this.find("email-list"),i=new RegExp("^#+(.*)\n","g").exec(this.data.content),this.find("mail-title").value=i[1],e=this.data.content.substring(0,500)+"...",this.find("contentarea").value=t.template.format(this.data.id,e),this.subdb.find({}).then(t=>{var e,i,s;for(e=0,i=t.length;ethis.error(__("Cannot fetch subscribers data: {0}",t.toString()),t)),this.find("bt-sendmail").onbtclick=t=>{var e,i,s,a,n,r;for(i=[],s=0,n=(a=this.maillinglist.items).length;st.error?this.notify(__("Unable to send mail to: {0}",t.result.join(", "))):this.quit()).catch(t=>(console.log(t),this.error(__("Error sending mail: {0}",t.toString()),t))))}}}).template="Hello,\n\nXuan Sang LE has just published a new post on his blog: https://blog.lxsang.me/post/id/{0}\n\n==========\n{1}\n==========\n\n\nRead the full article via:\nhttps://blog.lxsang.me/post/id/{0}\n\nYou receive this email because you have been subscribed to his blog.\n\nHave a nice day,\n\nSent from Blogger, an AntOS application",n=class extends this.OS.GUI.tag.ListViewItemTag{constructor(){super()}ondatachange(){var t,e,i,s,a,n;if(this.data){for(e in n=this.data,i=["content","start","end"],this.closable=n.closable,a=[],s=this.refs)t=s[e],n[e]&&""!==n[e]?i.includes(e)?a.push($(t).text(n[e])):a.push(t.text=n[e]):a.push(void 0);return a}}reload(){}init(){}itemlayout(){return{el:"div",children:[{el:"afx-label",ref:"title",class:"afx-cv-sec-title"},{el:"afx-label",ref:"subtitle",class:"afx-cv-sec-subtitle"},{el:"p",ref:"content",class:"afx-cv-sec-content"},{el:"p",class:"afx-cv-sec-period",children:[{el:"i",ref:"start"},{el:"i",ref:"end",class:"period-end"}]},{el:"afx-label",ref:"location",class:"afx-cv-sec-loc"}]}}},this.OS.GUI.tag.define("afx-blogger-cvsection-item",n),t=class extends this.OS.GUI.tag.ListViewItemTag{constructor(){super()}ondatachange(t){if(this.data)return(t=this.data).closable=!0,this.closable=t.closable,this.refs.title.text=t.title,this.refs.ctimestr.text=__("Created: {0}",t.ctimestr),this.refs.utimestr.text=__("Updated: {0}",t.utimestr)}reload(){}init(){}itemlayout(){return{el:"div",children:[{el:"afx-label",ref:"title",class:"afx-blogpost-title"},{el:"afx-label",ref:"ctimestr",class:"blog-dates"},{el:"afx-label",ref:"utimestr",class:"blog-dates"}]}}},this.OS.GUI.tag.define("afx-blogger-post-item",t)}).call(this); \ No newline at end of file +(function(){var t,e,i,s,a,n;(e=class extends this.OS.application.BaseApplication{constructor(t){super("Blogger",t)}main(){var t;return this.user={},this.cvlist=this.find("cv-list"),this.cvlist.ontreeselect=t=>{var e;if(t)return e=t.data.item.data,this.CVSectionByCID(Number(e.id))},this.inputtags=this.find("input-tags"),this.bloglist=this.find("blog-list"),this.seclist=this.find("cv-sec-list"),t=this.find("photo"),$(t).click(e=>this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"]}).then(e=>t.value=e.file.path).catch(t=>this.error(__("Unable to get file"),t))),this.userdb=new this._api.DB("user"),this.cvcatdb=new this._api.DB("cv_cat"),this.cvsecdb=new this._api.DB("cv_sections"),this.blogdb=new this._api.DB("blogs"),this.tabcontainer=this.find("tabcontainer"),this.tabcontainer.ontabselect=t=>this.fetchData(t.data.container.aid),this.find("bt-user-save").onbtclick=t=>this.saveUser(),this.find("cv-cat-add").onbtclick=t=>{var e;return e=t=>this.openDialog(new s,{title:__("Add category"),tree:t}).then(t=>{var e;return e={name:t.value,pid:t.p.id,publish:1},this.cvcatdb.save(e).then(t=>this.refreshCVCat()).catch(t=>this.error(__("Cannot add new category"),t))}).catch(t=>this.error(t.toString(),t)),this.fetchCVCat().then(t=>e(t)).catch(t=>(e({text:"Porfolio",id:"0",nodes:[]}),this.error(__("Unable to fetch categories"),t)))},this.find("cv-cat-edit").onbtclick=t=>{var e,i;if((i=this.cvlist.selectedItem)&&(e=i.data))return this.fetchCVCat().then(t=>this.openDialog(new s,{title:__("Edit category"),tree:t,cat:e}).then(t=>{var i;return i={id:e.id,publish:e.publish,pid:t.p.id,name:t.value},this.cvcatdb.save(i).then(t=>this.refreshCVCat()).catch(t=>this.error(__("Cannot Edit category"),t))})).catch(t=>this.error(__("Unable to fetch categories"),t))},this.find("cv-cat-del").onbtclick=t=>{var e,i;if((i=this.cvlist.selectedItem)&&(e=i.data))return this.openDialog("YesNoDialog",{title:__("Delete category"),iconclass:"fa fa-question-circle",text:__("Do you really want to delete: {0}?",e.name)}).then(t=>{if(t)return this.deleteCVCat(e)}).catch(t=>this.error(t.toString(),t))},this.find("cv-sec-add").onbtclick=t=>{var e,s;if(s=this.cvlist.selectedItem)return(e=s.data)&&"0"!==e.id?this.openDialog(new i(this),{title:__("New section entry for {0}",e.name)}).then(t=>(t.cid=Number(e.id),t.start=Number(t.start),t.end=Number(t.end),this.cvsecdb.save(t).then(t=>this.CVSectionByCID(Number(e.id))).catch(t=>this.error(__("Cannot save section: {0}",t.toString()),t)))):this.notify(__("Please select a category"))},this.find("cv-sec-move").onbtclick=t=>{var e,i;return(i=this.find("cv-sec-list").selectedItem)?(e=i.data,this.fetchCVCat().then(t=>this.openDialog(new s,{title:__("Move to"),tree:t,selonly:!0}).then(t=>{var i;return i={id:e.id,cid:t.p.id},this.cvsecdb.save(i).then(t=>(this.CVSectionByCID(e.cid),this.find("cv-sec-list").unselect())).catch(t=>this.error(__("Cannot move section"),t))}))):this.notify(__("Please select a section to move"))},this.find("cv-sec-edit").onbtclick=t=>{var e,s;return(s=this.find("cv-sec-list").selectedItem)?(e=s.data,this.openDialog(new i(this),{title:__("Modify section entry"),section:e}).then(t=>(t.cid=Number(e.cid),t.start=Number(t.start),t.end=Number(t.end),this.cvsecdb.save(t).then(t=>this.CVSectionByCID(Number(e.cid))).catch(t=>this.error(__("Cannot save section: {0}",t.toString()),t))))):this.notify(__("Please select a section to edit"))},this.seclist.onitemclose=t=>{var e;if(t)return e=t.data.item.data,this.openDialog("YesNoDialog",{iconclass:"fa fa-question-circle",text:__("Do you really want to delete: {0}?",e.title)}).then(i=>{if(i)return this.cvsecdb.delete(e.id).then(e=>this.seclist.delete(t.data.item)).catch(t=>this.error(__("Cannot delete the section: {0}",t.toString()),t))}),!1},this.editor=new EasyMDE({element:this.find("markarea"),autoDownloadFontAwesome:!1,autofocus:!0,tabSize:4,indentWithTabs:!0,toolbar:[{name:__("New"),className:"fa fa-file",action:t=>(this.bloglist.unselect(),this.clearEditor())},{name:__("Save"),className:"fa fa-save",action:t=>this.saveBlog()},"|","bold","italic","heading","|","quote","code","unordered-list","ordered-list","|","link","image","table","horizontal-rule",{name:"image",className:"fa fa-file-image-o",action:t=>this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"]}).then(t=>t.file.path.asFileHandle().publish().then(t=>this.editor.codemirror.getDoc().replaceSelection(`![](${this._api.handle.shared}/${t.result})`)).catch(t=>this.error(__("Cannot export file for embedding to text"),t)))},{name:"Youtube",className:"fa fa-youtube",action:t=>this.editor.codemirror.getDoc().replaceSelection("[[youtube:]]")},"|",{name:__("Preview"),className:"fa fa-eye no-disable",action:t=>(this.previewOn=!this.previewOn,EasyMDE.togglePreview(t),renderMathInElement(this.find("editor-container")))},"|",{name:__("Send mail"),className:"fa fa-paper-plane",action:t=>{var e,i;return(i=this.bloglist.selectedItem)?(e=i.data,this.openDialog(new a(this),{title:__("Send mail"),content:this.editor.value(),id:e.id}).then((function(t){return console.log("Email sent")}))):this.error(__("No post selected"))}}]}),this.bloglist.onlistselect=e=>{var i;if((t=this.bloglist.selectedItem)&&(i=t.data))return this.blogdb.get(Number(i.id)).then(t=>(this.editor.value(t.content),this.inputtags.value=t.tags,this.find("blog-publish").swon=!!Number(t.publish))).catch(t=>this.error(__("Cannot fetch the entry content"),t))},this.bloglist.onitemclose=e=>{var i;if(e)return t=e.data.item,i=t.data,this.openDialog("YesNoDialog",{title:__("Delete a post"),iconclass:"fa fa-question-circle",text:__("Do you really want to delete this post ?")}).then(e=>{if(e)return this.blogdb.delete(i.id).then(e=>(this.bloglist.delete(t),this.bloglist.unselect(),this.clearEditor()))}),!1},this.bindKey("CTRL-S",()=>{var t;if((t=this.tabcontainer.selectedTab)&&"blog-container"===t.container.aid)return this.saveBlog()}),this.on("resize",()=>this.resizeContent()),this.resizeContent(),this.loadBlogs()}fetchData(t){switch(t){case"user-container":return this.userdb.get(null).then(t=>{var e,i,s,a,n;for(this.user=t[0],a=[],e=0,s=(i=this.select("[input-class='user-input']")).length;ethis.error(__("Cannot fetch user data"),t));case"cv-container":return this.refreshCVCat();default:return this.loadBlogs()}}saveUser(){var t,e,i,s;for(t=0,i=(e=this.select("[input-class='user-input']")).length;tthis.notify(__("User data updated"))).catch(t=>this.error(__("Cannot save user data"),t)):this.notify(__("Full name must be entered"))}refreshCVCat(){return this.fetchCVCat().then(t=>(this.cvlist.data=t,this.cvlist.expandAll())).catch(t=>this.error(__("Unable to load categories"),t))}fetchCVCat(){return new Promise((t,e)=>{var i,s;return s={text:"Porfolio",id:"0",nodes:[]},i={order:{name:"ASC"}},this.cvcatdb.find(i).then(e=>(this.catListToTree(e,s,"0"),t(s))).catch((function(t){return e(__e(t))}))})}catListToTree(t,e,i){var s,a,n,r,o;if(0===(n=function(){var e,s,a;for(a=[],e=0,s=t.length;e(e=function(){var t,e,i;for(i=[],t=0,e=s.length;t(this.refreshCVCat(),this.seclist.data=[])).catch(e=>this.error(__("Cannot delete the category: {0} [{1}]",t.name,e.toString()),e)))).catch(e=>this.error(__("Cannot delete all content of: {0} [{1}]",t.name,e.toString()),e))}CVSectionByCID(t){var e;return e={exp:{"=":{cid:t}},order:{start:"DESC"}},this.cvsecdb.find(e).then(t=>{var e,i,s,a;for(i=[],this.find("cv-sec-status").text=__("Found {0} sections",t.length),e=0,s=t.length;ethis.error(t.toString(),t))}saveBlog(){var t,e,i,s,a,n,r;return s=void 0,(a=this.bloglist.selectedItem)&&(s=a.data),n=this.inputtags.value,t=this.editor.value(),(r=new RegExp("^#+(.*)\n","g").exec(t))&&2===r.length?""===n?this.notify(__("Please enter tags")):(e=new Date,i={content:t,title:r[1].trim(),tags:n,ctime:s?s.ctime:e.timestamp(),ctimestr:s?s.ctimestr:e.toString(),utime:e.timestamp(),utimestr:e.toString(),rendered:this.process(this.editor.options.previewRender(t)),publish:this.find("blog-publish").swon?1:0},s&&(i.id=s.id),this.blogdb.save(i).then(t=>this.loadBlogs()).catch(t=>this.error(__("Cannot save blog: {0}",t.toString()),t))):this.notify(__("Please insert a title in the text: beginning with heading"))}process(t){var e,i,s,a,n,r,o,l,h;for(i=function(t){return``},o=/\[\[youtube:([^\]]*)\]\]/g,l=[];null!==(s=o.exec(t));)l.push(s);if(!(l.length>0))return t;for(h="",e=0,a=0,r=l.length;a{var e,s;for(e=0,s=t.length;ethis.error(__("No post found: {0}",t.toString()),t))}resizeContent(){var t,e,i,s,a,n;return i=this.find("editor-container"),e=$(".EasyMDEContainer",i).children(),a=$(this.scheme).find(".afx-window-top")[0],n=e[0],s=e[3],t=$(this.scheme).height()-$(a).height()-$(n).height()-$(s).height()-90,$(e[1]).css("height",t+"px")}}).singleton=!0,e.dependencies=["pkg://SimpleMDE/main.js","pkg://SimpleMDE/main.css","pkg://Katex/main.js","pkg://Katex/main.css"],this.OS.register("Blogger",e),(s=class t extends this.OS.GUI.BasicDialog{constructor(){super("BloggerCategoryDialog",t.scheme)}main(){var t;if(super.main(),this.tree=this.find("tree"),this.txtinput=this.find("txtinput"),this.find("bt-ok").onbtclick=t=>{var e,i,s;return(e=this.tree.selectedItem)?(i=e.data,""!==(s=this.txtinput.value)||this.data.selonly?this.data.cat&&this.data.cat.id===i.id?this.notify(__("Parent can not be the category itself")):(this.handle&&this.handle({p:i,value:s}),this.quit()):this.notify(__("Please enter category name"))):this.notify(__("Please select a parent category"))},this.find("bt-cancel").onbtclick=t=>this.quit(),this.data&&this.data.tree)return this.data&&this.data.cat&&(this.txtinput.value=this.data.cat.name,(t="0"===this.data.cat.pid?this.data.tree:this.findDataByID(this.data.cat.pid,this.data.tree.nodes))&&(t.selected=!0)),this.tree.data=this.data.tree,this.tree.expandAll()}findDataByID(t,e){var i,s,a;for(s=0,a=e.length;s\n \n \n \n \n \n \n
\n \n \n
\n
\n
\n',i=class extends this.OS.GUI.BasicDialog{constructor(t){super("BloggerCVSectionDiaglog",(t.meta().path+"/cvsection.html").asFileHandle())}main(){var t,e;return super.main(),this.editor=new EasyMDE({autoDownloadFontAwesome:!1,element:this.find("contentarea"),status:!1,toolbar:!1}),$(this.select('[class = "CodeMirror-scroll"]')[0]).css("min-height","50px"),$(this.select('[class="CodeMirror cm-s-paper CodeMirror-wrap"]')[0]).css("min-height","50px"),t=this.select("[input-class='user-input']"),this.data&&this.data.section&&function(){var i,s,a;for(a=[],i=0,s=t.length;i{var s,a,n,r;for(s={},a=0,n=t.length;athis.resizeContent()),this.resizeContent()}resizeContent(){var t,e,i;return i=this.find("editor-container"),e=$(".EasyMDEContainer",i).children(),t=$(i).height()-30,$(e[0]).css("height",t+"px")}},(a=class t extends this.OS.GUI.BasicDialog{constructor(t){super("BloggerSendmailDiaglog",(t.meta().path+"/sendmail.html").asFileHandle())}main(){var e,i;return super.main(),this.subdb=new this.parent._api.DB("subscribers"),this.maillinglist=this.find("email-list"),i=new RegExp("^#+(.*)\n","g").exec(this.data.content),this.find("mail-title").value=i[1],e=this.data.content.substring(0,500)+"...",this.find("contentarea").value=t.template.format(this.data.id,e),this.subdb.find({}).then(t=>{var e,i,s;for(e=0,i=t.length;ethis.error(__("Cannot fetch subscribers data: {0}",t.toString()),t)),this.find("bt-sendmail").onbtclick=t=>{var e,i,s,a,n,r;for(i=[],s=0,n=(a=this.maillinglist.items).length;st.error?this.notify(__("Unable to send mail to: {0}",t.result.join(", "))):this.quit()).catch(t=>(console.log(t),this.error(__("Error sending mail: {0}",t.toString()),t))))}}}).template="Hello,\n\nXuan Sang LE has just published a new post on his blog: https://blog.lxsang.me/post/id/{0}\n\n==========\n{1}\n==========\n\n\nRead the full article via:\nhttps://blog.lxsang.me/post/id/{0}\n\nYou receive this email because you have been subscribed to his blog.\n\nHave a nice day,\n\nSent from Blogger, an AntOS application",n=class extends this.OS.GUI.tag.ListViewItemTag{constructor(){super()}ondatachange(){var t,e,i,s,a,n;if(this.data){for(e in n=this.data,i=["content","start","end"],this.closable=n.closable,a=[],s=this.refs)t=s[e],n[e]&&""!==n[e]?i.includes(e)?a.push($(t).text(n[e])):a.push(t.text=n[e]):a.push(void 0);return a}}reload(){}init(){}itemlayout(){return{el:"div",children:[{el:"afx-label",ref:"title",class:"afx-cv-sec-title"},{el:"afx-label",ref:"subtitle",class:"afx-cv-sec-subtitle"},{el:"p",ref:"content",class:"afx-cv-sec-content"},{el:"p",class:"afx-cv-sec-period",children:[{el:"i",ref:"start"},{el:"i",ref:"end",class:"period-end"}]},{el:"afx-label",ref:"location",class:"afx-cv-sec-loc"}]}}},this.OS.GUI.tag.define("afx-blogger-cvsection-item",n),t=class extends this.OS.GUI.tag.ListViewItemTag{constructor(){super()}ondatachange(t){if(this.data)return(t=this.data).closable=!0,this.closable=t.closable,this.refs.title.text=t.title,this.refs.ctimestr.text=__("Created: {0}",t.ctimestr),this.refs.utimestr.text=__("Updated: {0}",t.utimestr)}reload(){}init(){}itemlayout(){return{el:"div",children:[{el:"afx-label",ref:"title",class:"afx-blogpost-title"},{el:"afx-label",ref:"ctimestr",class:"blog-dates"},{el:"afx-label",ref:"utimestr",class:"blog-dates"}]}}},this.OS.GUI.tag.define("afx-blogger-post-item",t)}).call(this); \ No newline at end of file diff --git a/Blogger/build/debug/package.json b/Blogger/build/debug/package.json index 9700097..29dc296 100644 --- a/Blogger/build/debug/package.json +++ b/Blogger/build/debug/package.json @@ -6,9 +6,9 @@ "author": "Xuan Sang LE", "email": "xsang.le@gmail.com" }, - "version":"0.2.8-a", + "version":"0.2.9-a", "category":"Internet", "iconclass":"fa fa-book", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"], + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"], "mimes":["none"] } \ No newline at end of file diff --git a/Blogger/build/release/Blogger.zip b/Blogger/build/release/Blogger.zip index 7806afc..a1c6026 100644 Binary files a/Blogger/build/release/Blogger.zip and b/Blogger/build/release/Blogger.zip differ diff --git a/Blogger/dialogs.coffee b/Blogger/dialogs.coffee index 24b2570..c38b9a0 100644 --- a/Blogger/dialogs.coffee +++ b/Blogger/dialogs.coffee @@ -81,7 +81,7 @@ class BloggerCVSectionDiaglog extends this.OS.GUI.BasicDialog main: () -> super.main() - @editor = new SimpleMDE + @editor = new EasyMDE autoDownloadFontAwesome: false element: @find "contentarea" status: false @@ -107,14 +107,14 @@ class BloggerCVSectionDiaglog extends this.OS.GUI.BasicDialog @handle data if @handle @quit() - @on "vboxchange", () => @resizeContent() + @on "resize", () => @resizeContent() @resizeContent() resizeContent: () -> container = @find "editor-container" - children = ($ container).children() + children = ($ ".EasyMDEContainer", container).children() cheight = ($ container).height() - 30 - ($ children[1]).css("height", cheight + "px") + ($ children[0]).css("height", cheight + "px") # this dialog is for send mail diff --git a/Blogger/main.coffee b/Blogger/main.coffee index e601d2b..9925b49 100644 --- a/Blogger/main.coffee +++ b/Blogger/main.coffee @@ -187,7 +187,7 @@ class Blogger extends this.OS.application.BaseApplication .catch (e) => @error __("Cannot delete the section: {0}", e.toString()), e return false - @editor = new SimpleMDE + @editor = new EasyMDE element: @find "markarea" autoDownloadFontAwesome: false autofocus: true @@ -237,7 +237,7 @@ class Blogger extends this.OS.application.BaseApplication className: "fa fa-eye no-disable", action: (e) => @previewOn = !@previewOn - SimpleMDE.togglePreview e + EasyMDE.togglePreview e #/console.log @select ".editor-preview editor-preview-active" renderMathInElement @find "editor-container" }, @@ -294,7 +294,7 @@ class Blogger extends this.OS.application.BaseApplication sel = @tabcontainer.selectedTab return unless sel and sel.container.aid is "blog-container" @saveBlog() - @on "vboxchange", () => + @on "resize", () => @resizeContent() @resizeContent() @@ -489,12 +489,12 @@ class Blogger extends this.OS.application.BaseApplication resizeContent: () -> container = @find "editor-container" - children = ($ container).children() + children = ($ ".EasyMDEContainer", container).children() titlebar = (($ @scheme).find ".afx-window-top")[0] - toolbar = children[1] - statusbar = children[4] + toolbar = children[0] + statusbar = children[3] cheight = ($ @scheme).height() - ($ titlebar).height() - ($ toolbar).height() - ($ statusbar).height() - 90 - ($ children[2]).css("height", cheight + "px") + ($ children[1]).css("height", cheight + "px") Blogger.singleton = true Blogger.dependencies = [ diff --git a/Blogger/package.json b/Blogger/package.json index 9700097..29dc296 100644 --- a/Blogger/package.json +++ b/Blogger/package.json @@ -6,9 +6,9 @@ "author": "Xuan Sang LE", "email": "xsang.le@gmail.com" }, - "version":"0.2.8-a", + "version":"0.2.9-a", "category":"Internet", "iconclass":"fa fa-book", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"], + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"], "mimes":["none"] } \ No newline at end of file diff --git a/Booklet/README.md b/Booklet/README.md index d34fb51..171b9e9 100644 --- a/Booklet/README.md +++ b/Booklet/README.md @@ -3,6 +3,8 @@ A back-end tool for my online document hub [https://doc.iohub.dev/antos/](https: ## Change logs +### v0.2.5-a +* Use the new MDE library ### v0.2.3-a * Chage app category name ### v0.2.1-a diff --git a/Booklet/build/debug/README.md b/Booklet/build/debug/README.md index d34fb51..171b9e9 100644 --- a/Booklet/build/debug/README.md +++ b/Booklet/build/debug/README.md @@ -3,6 +3,8 @@ A back-end tool for my online document hub [https://doc.iohub.dev/antos/](https: ## Change logs +### v0.2.5-a +* Use the new MDE library ### v0.2.3-a * Chage app category name ### v0.2.1-a diff --git a/Booklet/build/debug/main.js b/Booklet/build/debug/main.js index 38a0cd1..49643d9 100644 --- a/Booklet/build/debug/main.js +++ b/Booklet/build/debug/main.js @@ -1 +1 @@ -(function(){var t,e,i,r,n,a,s,o;(t=class extends this.OS.application.BaseApplication{constructor(t){super("Booklet",t)}main(){return this.tree=this.find("toc-ui"),this.currentToc=void 0,this.dirty=!1,this.emux=!1,this.on("treeselect",t=>{var e;return e=t.data.item.data,this.currentToc===e||void 0===e||0===e.treepath?this.reloadEditor():(e.treepath=e.path,this.load(e).then(()=>this.open(e)).catch(t=>(e.loaded=!0,this.open(e),this.error(__("Error when loading '{0}': {1}",e.text,t.toString()),t))))}),this.tree.ondragndrop=t=>this.dndhandle(t),this.initEditor(),this.resizeContent(),this.tree.contextmenuHandle=(t,e)=>{var i;if(i=this.contextMenu())return e.items=i,e.onmenuselect=t=>this[t.data.item.data.dataid](),e.show(t)},this.editor.codemirror.on("change",()=>{if(!this.emux&&this.currentToc)return this.currentToc.descFile.dirty=!0,this.dirty=!0})}newChapter(){var t;return this.currentToc&&"Book"===this.currentToc.type?(t=new i(this.book),this.displayToc(),t.treepath=t.path):this.error(__("No book selected"))}newSection(){var t;return this.currentToc&&"Chapter"===this.currentToc.type?(t=new s(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No chapter selected"))}newFile(){var t;return this.currentToc&&"Section"===this.currentToc.type?(t=new n(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No section selected"))}delete(){var t;return this.currentToc?(t=()=>(this.currentToc=void 0,this.displayToc(),this.reloadEditor()),this.currentToc.remove().then(()=>(this.notify(__("Entrie deleted")),t())).catch(e=>(this.error(e.toString(),e),t()))):this.error(__("No entrie select"))}goUp(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.up(this.currentToc),this.displayToc()}goDown(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.down(this.currentToc),this.displayToc()}load(t){return new Promise((e,i)=>t.loaded?e():t.descFile.meta().then(r=>t.descFile.read().then(i=>(t.descFile.cache=i,t.loaded=!0,t.descFile.dirty=!1,e())).catch((function(t){return i(__e(t))}))).catch((function(t){return i(__e(t))})))}dndhandle(t){var e,i;if(t&&t.data&&(e=t.data.from[0].data,i=t.data.to.data,e&&i&&"Book"!==e.type&&"Chapter"!==e.type&&e.parent!==i.parent&&e.parent!==i))return i.type===e.type&&(i=i.parent),i.type===e.parent.type?e.parent.removeChild(e).then(()=>(i.add(e),this.displayToc())):void 0}upload(){if(this.currentToc&&"File"!==this.currentToc.type)return this.currentToc.path.asFileHandle().upload().then(()=>this.notify(__("File uploaded"))).catch(t=>this.error(__("Unable to upload file {0}",t.toString()),t))}contextMenu(){if(this.currentToc)switch(this.currentToc.type){case"Book":return[{text:__("New chapter"),dataid:"newChapter"},{text:__("Delete book"),dataid:"delete"},{text:__("Upload media"),dataid:"upload"}];case"Chapter":return[{text:__("New section"),dataid:"newSection"},{text:__("Delete chapter"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"Section":return[{text:__("New file"),dataid:"newFile"},{text:__("Delete section"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"File":return[{text:__("Delete file"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"}]}}shareFile(t,e){return this.openDialog("FileDialog",{title:__("Select a file"),mimes:t}).then(t=>t.file.path.asFileHandle().publish().then((function(t){return e(t.result)})).catch(t=>this.error(__("Cannot export file for embedding to text"),t))).catch(t=>this.error(t.toString(),t))}initEditor(){var t;return t=this.find("markarea"),this.container=this.find("mycontainer"),this.previewOn=!1,this.editormux=!1,this.editor=new SimpleMDE({element:t,autoDownloadFontAwesome:!1,autofocus:!0,tabSize:4,indentWithTabs:!0,toolbar:["bold","italic","heading","|","quote","code","unordered-list","ordered-list","|","link","image","table","horizontal-rule",{name:"shared image",className:"fa fa-share-square",action:t=>this.shareFile(["image/.*"],t=>this.editor.codemirror.getDoc().replaceSelection(`![](${this._api.handler.shared}/${t})`))},{name:"local image",className:"fa fa-file-image-o",action:t=>{if(this.book)return this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"],root:this.book.path}).then(t=>{var e;return e=t.file.path.replace(this.book.path,""),this.editor.codemirror.getDoc().replaceSelection(`[[@book:image:${e}]]`)}).catch(t=>this.error(t.toString(),t))}},{name:"Youtube",className:"fa fa-youtube",action:t=>{var e,i;return e=this.editor.codemirror.getDoc(),i=this.editor.codemirror.getSelection()||"",e.replaceSelection(`[[youtube:${i}]]`)}},{name:"3d object",className:"fa fa-cube",action:t=>{if(this.book)return this.openDialog("FileDialog",{title:__("Select 3d model"),mimes:["text/wavefront-obj","model/gltf-binary"],root:this.book.path}).then(t=>{var e;return e=t.file.path.replace(this.book.path,""),this.editor.codemirror.getDoc().replaceSelection(`[[@book:3dmodel:${e}]]`)}).catch(t=>this.error(t.toString(),t))}},"|",{name:__("Preview"),className:"fa fa-eye no-disable",action:t=>(SimpleMDE.togglePreview(t),renderMathInElement(this.find("mycontainer")),this.renderLocalElement())}],previewRender:(t,e)=>{var i;return this.book&&(t=t.replace(/\[\[@book:image:([^\]]*)\]\]/g,(t,e)=>`![](${this._api.handle.get}/${this.book.path}/${e})`)),i=this.editor.markdown(t),e.innerHTML=i}}),this.on("hboxchange",t=>this.resizeContent()),this.bindKey("ALT-N",()=>this.actionFile(this.name+"-New")),this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-S",()=>this.actionFile(this.name+"-Save"))}reloadEditor(){return void 0===this.currentToc?(this.editor.value(""),this.scheme.apptitle=this.name):(this.editor.value(this.currentToc.descFile.cache||""),this.scheme.apptitle="Booklet - "+this.currentToc.descFile.path)}saveContext(){if(this.currentToc)return this.currentToc.descFile.cache=this.editor.value()}resizeContent(){var t,e,i,r,n;return e=$(this.container).children(),r=$(this.scheme).find(".afx-window-top")[0],n=e[1],i=e[4],t=$(this.scheme).height()-$(r).height()-$(n).height()-$(i).height()-40,$(e[2]).css("height",t+"px")}menu(){return[{text:"__(File)",nodes:[{text:"__(New booklet)",dataid:this.name+"-New",shortcut:"A-N"},{text:"__(Open a booklet)",dataid:this.name+"-Open",shortcut:"A-O"},{text:"__(Save a booklet)",dataid:this.name+"-Save",shortcut:"C-S"}],onchildselect:t=>this.actionFile(t.data.item.data.dataid)}]}actionFile(t){switch(t){case this.name+"-Open":return this.checkForDirty(()=>this.openDialog("FileDialog",{title:__("Open book"),mimes:["dir"]}).then(t=>(this.book=new e(t.file.path),this.book.read(t.file.path).then(()=>(this.book.treepath=this.book.path,this.tree.selectedItem=void 0,this.displayToc(),this.notify(__("Book loaded")))).catch(t=>this.error(__("Cannot load book: {0}",t.toString()),t)))).catch(t=>this.error(t.toString(),t)));case this.name+"-New":return this.openDialog("FileDialog",{title:__("New book at"),mimes:["dir"],file:{basename:__("BookName")}}).then(t=>this.newAt(`${t.file.path}/${t.name}`)).catch(t=>this.error(t.toString(),t));case this.name+"-Save":if(!this.book)return;return this.currentToc&&this.saveContext(),this.displayToc(),this.book.save().then(()=>(this.dirty=!1,this.notify(__("Book saved")))).catch(t=>this.error(__("Can't save the book : {0}",t.toString()),t))}}checkForDirty(t){return this.dirty?this.ask({title:__("Continue ?"),text:__("Book is unsaved, you want to continue ?")}).then(e=>{if(e)return t()}):t()}open(t){return this.emux=!0,this.saveContext(),this.currentToc=t,this.reloadEditor(),this.displayToc(),this.emux=!1}newAt(t){return this.tree.selectedItem=void 0,this.book=new e(t),this.book.treepath=this.book.path,this.currentToc=void 0,this.reloadEditor(),this.displayToc()}displayToc(){return this.book.toc(),this.tree.data=this.book,this.tree.expandAll()}cleanup(t){if(this.dirty)return t.preventDefault(),this.checkForDirty(()=>(this.dirty=!1,this.quit()))}renderLocalElement(){}}).dependencies=["pkg://SimpleMDE/main.js","pkg://SimpleMDE/main.css","pkg://Katex/main.js","pkg://Katex/main.css"],this.OS.register("Booklet",t),r=class{constructor(t){this.text=t,this.loaded=!0}save(){}remove(){}toc(){}updateName(){var t;return(t=new RegExp("^s*#+(.*)\n","g").exec(this.descFile.cache))&&2===t.length?(this.hasMeta&&this.metaFile&&(this.metaFile.dirty=!0),this.parent&&this.parent.hasMeta&&this.parent.metaFile&&(this.parent.metaFile.dirty=!0),this.text=t[1].trim()):this.text}remove(){return new Promise((t,e)=>{var i;return(i=this.path.asFileHandle()).meta().then(r=>i.remove().then(i=>this.parent?this.parent.removeChild(this).then((function(){return t()})).catch((function(t){return e(__e(t))})):t()).catch((function(t){return e(__e(t))}))).catch(i=>this.parent?this.parent.removeChild(this).then((function(){return t()})).catch((function(t){return e(__e(t))})):t())})}},a=class extends r{constructor(t,e,i){super("Untitle"),this.type=t,this.path=e,this.hasMeta=i,this.init()}init(){return this.cnt=0,this.nodes=[],this.hasMeta&&(this.metaFile=(this.path+"/meta.json").asFileHandle()),this.descFile=(this.path+"/INTRO.md").asFileHandle()}up(t){var e;if(t&&(e=this.nodes.indexOf(t))>0)return this.nodes.splice(e,1),this.nodes.splice(e-1,0,t)}down(t){var e;if(t&&(e=this.nodes.indexOf(t))>=0&&e(this.nodes.splice(this.nodes.indexOf(t),1),this.hasMeta&&this.metaFile?(this.metaFile.dirty=!0,this.updateMeta().then((function(){return e()})).catch((function(t){return i(__e(t))}))):e()))}read(t){return new Promise((e,i)=>(this.path=t,this.init(),this.loaded=!1,this.metaFile.meta().then(t=>this.metaFile.read("json").then(t=>{var i,r,n,a,s,h,c;for(this.text=t.name,s=[],r=n=0,a=(h=t.entries).length;n{var n,a;return 0===r.length?(this.cnt=t.cnt,e()):(n=r.splice(0,1)[0],(a=new o[n.type](this)).name=n.name,a.read(n.path.replace("book://",this.root)).then(()=>i(r)).catch(t=>i(r)))})(s)}).catch((function(t){return i(__e(t))}))).catch((function(t){return i(__e(t))}))))}size(){return this.nodes.length}mkdir(){return new Promise((t,e)=>{var i;return(i=this.path.asFileHandle()).meta().then(e=>t()).catch(r=>{var n;return n=i.basename,(i=i.parent().asFileHandle()).mk(n).then(e=>t()).catch((function(t){return e(__e(t))}))})})}mkdirs(){return new Promise((t,e)=>{var i,r,n,a,s,o;if(a=[],"Section"!==this.type)for(i=r=0,n=(s=this.nodes).length;r{var i;return(i=r=>0===r.length?t():r.splice(0,1)[0].mkdirs().then(()=>i(r)).catch((function(t){return e(__e(t))})))(a)}).catch((function(t){return e(__e(t))}))})}updateMeta(){return new Promise((t,e)=>{var i,r,n,a,s,o,h;if(!this.metaFile.dirty)return t();for(r=[],n=a=0,s=(o=this.nodes).length;a(this.metaFile.dirty=!1,t())).catch((function(t){return e(__e(t))}))})}update(){return new Promise((t,e)=>this.updateMeta().then(()=>this.descFile.dirty?this.descFile.write("text/plain").then(e=>(this.descFile.dirty=!1,t())).catch((function(t){return e(__e(t))})):t()).catch((function(t){return e(__e(t))})))}updateAll(){return new Promise((t,e)=>{var i,r,n,a,s,o;for(a=[],i=r=0,n=(s=this.nodes).length;r{var i;return(i=r=>0===r.length?t():r.splice(0,1)[0].updateAll().then(()=>i(r)).catch((function(t){return e(__e(t))})))(a)}).catch((function(t){return e(__e(t))}))})}toc(){var t,e,i;for(this.updateName(),t=0,e=(i=this.nodes).length;tthis.mkdirs().then(()=>this.updateAll().then(()=>t()).catch((function(t){return e(__e(t))}))).catch((function(t){return e(__e(t))})))}},Chapter:i=class extends a{constructor(t){super("Chapter",`${t.path}/c_${t.cnt}`,!0),t.add(this)}},Section:s=class extends a{constructor(t){super("Section",`${t.path}/s_${t.cnt}`,!0),t.add(this)}},File:n=class extends r{constructor(t){super("Untitle file"),this.section=t,this.hasMeta=!1,this.type="File",this.path=`${this.section.path}/f_${this.section.cnt}.md`,this.descFile=this.path.asFileHandle(),this.section.add(this)}updateAll(){return new Promise((t,e)=>this.descFile.dirty?this.descFile.write("text/plain").then(e=>(this.descFile.dirty=!1,t())).catch(t=>e(__e(t))):t())}read(t){return new Promise((e,i)=>(this.loaded=!1,this.treepath=t,this.path=t,this.descFile=this.path.asFileHandle(),e()))}toc(){return this.updateName(),this}}}}).call(this); \ No newline at end of file +(function(){var t,e,i,r,n,a,s,o;(t=class extends this.OS.application.BaseApplication{constructor(t){super("Booklet",t)}main(){return this.tree=this.find("toc-ui"),this.currentToc=void 0,this.dirty=!1,this.emux=!1,this.on("treeselect",t=>{var e;return e=t.data.item.data,this.currentToc===e||void 0===e||0===e.treepath?this.reloadEditor():(e.treepath=e.path,this.load(e).then(()=>this.open(e)).catch(t=>(e.loaded=!0,this.open(e),this.error(__("Error when loading '{0}': {1}",e.text,t.toString()),t))))}),this.tree.ondragndrop=t=>this.dndhandle(t),this.initEditor(),this.resizeContent(),this.tree.contextmenuHandle=(t,e)=>{var i;if(i=this.contextMenu())return e.items=i,e.onmenuselect=t=>this[t.data.item.data.dataid](),e.show(t)},this.editor.codemirror.on("change",()=>{if(!this.emux&&this.currentToc)return this.currentToc.descFile.dirty=!0,this.dirty=!0})}newChapter(){var t;return this.currentToc&&"Book"===this.currentToc.type?(t=new i(this.book),this.displayToc(),t.treepath=t.path):this.error(__("No book selected"))}newSection(){var t;return this.currentToc&&"Chapter"===this.currentToc.type?(t=new s(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No chapter selected"))}newFile(){var t;return this.currentToc&&"Section"===this.currentToc.type?(t=new n(this.currentToc),this.displayToc(),t.treepath=t.path):this.error(__("No section selected"))}delete(){var t;return this.currentToc?(t=()=>(this.currentToc=void 0,this.displayToc(),this.reloadEditor()),this.currentToc.remove().then(()=>(this.notify(__("Entrie deleted")),t())).catch(e=>(this.error(e.toString(),e),t()))):this.error(__("No entrie select"))}goUp(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.up(this.currentToc),this.displayToc()}goDown(){if(this.currentToc&&"Book"!==this.currentToc.type)return this.currentToc.parent.down(this.currentToc),this.displayToc()}load(t){return new Promise((e,i)=>t.loaded?e():t.descFile.meta().then(r=>t.descFile.read().then(i=>(t.descFile.cache=i,t.loaded=!0,t.descFile.dirty=!1,e())).catch((function(t){return i(__e(t))}))).catch((function(t){return i(__e(t))})))}dndhandle(t){var e,i;if(t&&t.data&&(e=t.data.from[0].data,i=t.data.to.data,e&&i&&"Book"!==e.type&&"Chapter"!==e.type&&e.parent!==i.parent&&e.parent!==i))return i.type===e.type&&(i=i.parent),i.type===e.parent.type?e.parent.removeChild(e).then(()=>(i.add(e),this.displayToc())):void 0}upload(){if(this.currentToc&&"File"!==this.currentToc.type)return this.currentToc.path.asFileHandle().upload().then(()=>this.notify(__("File uploaded"))).catch(t=>this.error(__("Unable to upload file {0}",t.toString()),t))}contextMenu(){if(this.currentToc)switch(this.currentToc.type){case"Book":return[{text:__("New chapter"),dataid:"newChapter"},{text:__("Delete book"),dataid:"delete"},{text:__("Upload media"),dataid:"upload"}];case"Chapter":return[{text:__("New section"),dataid:"newSection"},{text:__("Delete chapter"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"Section":return[{text:__("New file"),dataid:"newFile"},{text:__("Delete section"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"},{text:__("Upload media"),dataid:"upload"}];case"File":return[{text:__("Delete file"),dataid:"delete"},{text:__("Go up"),dataid:"goUp"},{text:__("Go down"),dataid:"goDown"}]}}shareFile(t,e){return this.openDialog("FileDialog",{title:__("Select a file"),mimes:t}).then(t=>t.file.path.asFileHandle().publish().then((function(t){return e(t.result)})).catch(t=>this.error(__("Cannot export file for embedding to text"),t))).catch(t=>this.error(t.toString(),t))}initEditor(){var t;return t=this.find("markarea"),this.container=this.find("mycontainer"),this.previewOn=!1,this.editormux=!1,this.editor=new EasyMDE({element:t,autoDownloadFontAwesome:!1,autofocus:!0,tabSize:4,indentWithTabs:!0,toolbar:["bold","italic","heading","|","quote","code","unordered-list","ordered-list","|","link","image","table","horizontal-rule",{name:"shared image",className:"fa fa-share-square",action:t=>this.shareFile(["image/.*"],t=>this.editor.codemirror.getDoc().replaceSelection(`![](${this._api.handler.shared}/${t})`))},{name:"local image",className:"fa fa-file-image-o",action:t=>{if(this.book)return this.openDialog("FileDialog",{title:__("Select image file"),mimes:["image/.*"],root:this.book.path}).then(t=>{var e;return e=t.file.path.replace(this.book.path,""),this.editor.codemirror.getDoc().replaceSelection(`[[@book:image:${e}]]`)}).catch(t=>this.error(t.toString(),t))}},{name:"Youtube",className:"fa fa-youtube",action:t=>{var e,i;return e=this.editor.codemirror.getDoc(),i=this.editor.codemirror.getSelection()||"",e.replaceSelection(`[[youtube:${i}]]`)}},{name:"3d object",className:"fa fa-cube",action:t=>{if(this.book)return this.openDialog("FileDialog",{title:__("Select 3d model"),mimes:["text/wavefront-obj","model/gltf-binary"],root:this.book.path}).then(t=>{var e;return e=t.file.path.replace(this.book.path,""),this.editor.codemirror.getDoc().replaceSelection(`[[@book:3dmodel:${e}]]`)}).catch(t=>this.error(t.toString(),t))}},"|",{name:__("Preview"),className:"fa fa-eye no-disable",action:t=>(EasyMDE.togglePreview(t),renderMathInElement(this.find("mycontainer")),this.renderLocalElement())}],previewRender:(t,e)=>{var i;return this.book&&(t=t.replace(/\[\[@book:image:([^\]]*)\]\]/g,(t,e)=>`![](${this._api.handle.get}/${this.book.path}/${e})`)),i=this.editor.markdown(t),e.innerHTML=i}}),this.on("resize",t=>this.resizeContent()),this.bindKey("ALT-N",()=>this.actionFile(this.name+"-New")),this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-S",()=>this.actionFile(this.name+"-Save"))}reloadEditor(){return void 0===this.currentToc?(this.editor.value(""),this.scheme.apptitle=this.name):(this.editor.value(this.currentToc.descFile.cache||""),this.scheme.apptitle="Booklet - "+this.currentToc.descFile.path)}saveContext(){if(this.currentToc)return this.currentToc.descFile.cache=this.editor.value()}resizeContent(){var t,e,i,r,n;return e=$(".EasyMDEContainer",this.container).children(),r=$(this.scheme).find(".afx-window-top")[0],n=e[0],i=e[3],t=$(this.scheme).height()-$(r).height()-$(n).height()-$(i).height()-40,$(e[1]).css("height",t+"px")}menu(){return[{text:"__(File)",nodes:[{text:"__(New booklet)",dataid:this.name+"-New",shortcut:"A-N"},{text:"__(Open a booklet)",dataid:this.name+"-Open",shortcut:"A-O"},{text:"__(Save a booklet)",dataid:this.name+"-Save",shortcut:"C-S"}],onchildselect:t=>this.actionFile(t.data.item.data.dataid)}]}actionFile(t){switch(t){case this.name+"-Open":return this.checkForDirty(()=>this.openDialog("FileDialog",{title:__("Open book"),mimes:["dir"]}).then(t=>(this.book=new e(t.file.path),this.book.read(t.file.path).then(()=>(this.book.treepath=this.book.path,this.tree.selectedItem=void 0,this.displayToc(),this.notify(__("Book loaded")))).catch(t=>this.error(__("Cannot load book: {0}",t.toString()),t)))).catch(t=>this.error(t.toString(),t)));case this.name+"-New":return this.openDialog("FileDialog",{title:__("New book at"),mimes:["dir"],file:{basename:__("BookName")}}).then(t=>this.newAt(`${t.file.path}/${t.name}`)).catch(t=>this.error(t.toString(),t));case this.name+"-Save":if(!this.book)return;return this.currentToc&&this.saveContext(),this.displayToc(),this.book.save().then(()=>(this.dirty=!1,this.notify(__("Book saved")))).catch(t=>this.error(__("Can't save the book : {0}",t.toString()),t))}}checkForDirty(t){return this.dirty?this.ask({title:__("Continue ?"),text:__("Book is unsaved, you want to continue ?")}).then(e=>{if(e)return t()}):t()}open(t){return this.emux=!0,this.saveContext(),this.currentToc=t,this.reloadEditor(),this.displayToc(),this.emux=!1}newAt(t){return this.tree.selectedItem=void 0,this.book=new e(t),this.book.treepath=this.book.path,this.currentToc=void 0,this.reloadEditor(),this.displayToc()}displayToc(){return this.book.toc(),this.tree.data=this.book,this.tree.expandAll()}cleanup(t){if(this.dirty)return t.preventDefault(),this.checkForDirty(()=>(this.dirty=!1,this.quit()))}renderLocalElement(){}}).dependencies=["pkg://SimpleMDE/main.js","pkg://SimpleMDE/main.css","pkg://Katex/main.js","pkg://Katex/main.css"],this.OS.register("Booklet",t),r=class{constructor(t){this.text=t,this.loaded=!0}save(){}remove(){}toc(){}updateName(){var t;return(t=new RegExp("^s*#+(.*)\n","g").exec(this.descFile.cache))&&2===t.length?(this.hasMeta&&this.metaFile&&(this.metaFile.dirty=!0),this.parent&&this.parent.hasMeta&&this.parent.metaFile&&(this.parent.metaFile.dirty=!0),this.text=t[1].trim()):this.text}remove(){return new Promise((t,e)=>{var i;return(i=this.path.asFileHandle()).meta().then(r=>i.remove().then(i=>this.parent?this.parent.removeChild(this).then((function(){return t()})).catch((function(t){return e(__e(t))})):t()).catch((function(t){return e(__e(t))}))).catch(i=>this.parent?this.parent.removeChild(this).then((function(){return t()})).catch((function(t){return e(__e(t))})):t())})}},a=class extends r{constructor(t,e,i){super("Untitle"),this.type=t,this.path=e,this.hasMeta=i,this.init()}init(){return this.cnt=0,this.nodes=[],this.hasMeta&&(this.metaFile=(this.path+"/meta.json").asFileHandle()),this.descFile=(this.path+"/INTRO.md").asFileHandle()}up(t){var e;if(t&&(e=this.nodes.indexOf(t))>0)return this.nodes.splice(e,1),this.nodes.splice(e-1,0,t)}down(t){var e;if(t&&(e=this.nodes.indexOf(t))>=0&&e(this.nodes.splice(this.nodes.indexOf(t),1),this.hasMeta&&this.metaFile?(this.metaFile.dirty=!0,this.updateMeta().then((function(){return e()})).catch((function(t){return i(__e(t))}))):e()))}read(t){return new Promise((e,i)=>(this.path=t,this.init(),this.loaded=!1,this.metaFile.meta().then(t=>this.metaFile.read("json").then(t=>{var i,r,n,a,s,h,c;for(this.text=t.name,s=[],r=n=0,a=(h=t.entries).length;n{var n,a;return 0===r.length?(this.cnt=t.cnt,e()):(n=r.splice(0,1)[0],(a=new o[n.type](this)).name=n.name,a.read(n.path.replace("book://",this.root)).then(()=>i(r)).catch(t=>i(r)))})(s)}).catch((function(t){return i(__e(t))}))).catch((function(t){return i(__e(t))}))))}size(){return this.nodes.length}mkdir(){return new Promise((t,e)=>{var i;return(i=this.path.asFileHandle()).meta().then(e=>t()).catch(r=>{var n;return n=i.basename,(i=i.parent().asFileHandle()).mk(n).then(e=>t()).catch((function(t){return e(__e(t))}))})})}mkdirs(){return new Promise((t,e)=>{var i,r,n,a,s,o;if(a=[],"Section"!==this.type)for(i=r=0,n=(s=this.nodes).length;r{var i;return(i=r=>0===r.length?t():r.splice(0,1)[0].mkdirs().then(()=>i(r)).catch((function(t){return e(__e(t))})))(a)}).catch((function(t){return e(__e(t))}))})}updateMeta(){return new Promise((t,e)=>{var i,r,n,a,s,o,h;if(!this.metaFile.dirty)return t();for(r=[],n=a=0,s=(o=this.nodes).length;a(this.metaFile.dirty=!1,t())).catch((function(t){return e(__e(t))}))})}update(){return new Promise((t,e)=>this.updateMeta().then(()=>this.descFile.dirty?this.descFile.write("text/plain").then(e=>(this.descFile.dirty=!1,t())).catch((function(t){return e(__e(t))})):t()).catch((function(t){return e(__e(t))})))}updateAll(){return new Promise((t,e)=>{var i,r,n,a,s,o;for(a=[],i=r=0,n=(s=this.nodes).length;r{var i;return(i=r=>0===r.length?t():r.splice(0,1)[0].updateAll().then(()=>i(r)).catch((function(t){return e(__e(t))})))(a)}).catch((function(t){return e(__e(t))}))})}toc(){var t,e,i;for(this.updateName(),t=0,e=(i=this.nodes).length;tthis.mkdirs().then(()=>this.updateAll().then(()=>t()).catch((function(t){return e(__e(t))}))).catch((function(t){return e(__e(t))})))}},Chapter:i=class extends a{constructor(t){super("Chapter",`${t.path}/c_${t.cnt}`,!0),t.add(this)}},Section:s=class extends a{constructor(t){super("Section",`${t.path}/s_${t.cnt}`,!0),t.add(this)}},File:n=class extends r{constructor(t){super("Untitle file"),this.section=t,this.hasMeta=!1,this.type="File",this.path=`${this.section.path}/f_${this.section.cnt}.md`,this.descFile=this.path.asFileHandle(),this.section.add(this)}updateAll(){return new Promise((t,e)=>this.descFile.dirty?this.descFile.write("text/plain").then(e=>(this.descFile.dirty=!1,t())).catch(t=>e(__e(t))):t())}read(t){return new Promise((e,i)=>(this.loaded=!1,this.treepath=t,this.path=t,this.descFile=this.path.asFileHandle(),e()))}toc(){return this.updateName(),this}}}}).call(this); \ No newline at end of file diff --git a/Booklet/build/debug/package.json b/Booklet/build/debug/package.json index 50fbbd3..6f548a9 100644 --- a/Booklet/build/debug/package.json +++ b/Booklet/build/debug/package.json @@ -7,9 +7,9 @@ "author": "Xuan Sang LE", "email": "mrsang@lxsang.me" }, - "version":"0.2.4-a", + "version":"0.2.5-a", "category":"Office", "iconclass":"bi bi-journals", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"], + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"], "mimes":["dir"] } \ No newline at end of file diff --git a/Booklet/build/release/Booklet.zip b/Booklet/build/release/Booklet.zip index 8667cb3..5b0f395 100644 Binary files a/Booklet/build/release/Booklet.zip and b/Booklet/build/release/Booklet.zip differ diff --git a/Booklet/coffees/main.coffee b/Booklet/coffees/main.coffee index 82a0d9f..00eef0a 100644 --- a/Booklet/coffees/main.coffee +++ b/Booklet/coffees/main.coffee @@ -166,7 +166,7 @@ class Booklet extends this.OS.application.BaseApplication @previewOn = false @editormux = false - @editor = new SimpleMDE + @editor = new EasyMDE element: markarea autoDownloadFontAwesome: false autofocus: true @@ -232,7 +232,7 @@ class Booklet extends this.OS.application.BaseApplication name: __("Preview"), className: "fa fa-eye no-disable", action: (e) => - SimpleMDE.togglePreview e + EasyMDE.togglePreview e #/console.log @select ".editor-preview editor-preview-active" renderMathInElement @find "mycontainer" @renderLocalElement() @@ -246,7 +246,7 @@ class Booklet extends this.OS.application.BaseApplication preview.innerHTML = html - @on "hboxchange", (e) => @resizeContent() + @on "resize", (e) => @resizeContent() @bindKey "ALT-N", () => @actionFile "#{@name}-New" @bindKey "ALT-O", () => @actionFile "#{@name}-Open" @bindKey "CTRL-S", () => @actionFile "#{@name}-Save" @@ -263,12 +263,12 @@ class Booklet extends this.OS.application.BaseApplication @currentToc.descFile.cache = @editor.value() resizeContent: () -> - children = ($ @container).children() + children = ($ ".EasyMDEContainer", @container).children() titlebar = (($ @scheme).find ".afx-window-top")[0] - toolbar = children[1] - statusbar = children[4] + toolbar = children[0] + statusbar = children[3] cheight = ($ @scheme).height() - ($ titlebar).height() - ($ toolbar).height() - ($ statusbar).height() - 40 - ($ children[2]).css("height", cheight + "px") + ($ children[1]).css("height", cheight + "px") menu: () -> diff --git a/Booklet/package.json b/Booklet/package.json index 50fbbd3..6f548a9 100644 --- a/Booklet/package.json +++ b/Booklet/package.json @@ -7,9 +7,9 @@ "author": "Xuan Sang LE", "email": "mrsang@lxsang.me" }, - "version":"0.2.4-a", + "version":"0.2.5-a", "category":"Office", "iconclass":"bi bi-journals", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"], + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"], "mimes":["dir"] } \ No newline at end of file diff --git a/packages.json b/packages.json index 80318ae..c75cf7f 100644 --- a/packages.json +++ b/packages.json @@ -95,8 +95,8 @@ "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/Blogger/README.md", "category": "Internet", "author": "Xuan Sang LE", - "version": "0.2.8-a", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"],"mimes":["none"], + "version": "0.2.9-a", + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"],"mimes":["none"], "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/Blogger/build/release/Blogger.zip" }, { @@ -105,8 +105,8 @@ "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/Booklet/README.md", "category": "Office", "author": "Xuan Sang LE", - "version": "0.2.4-a", - "dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"],"mimes":["dir"], + "version": "0.2.5-a", + "dependencies": ["SimpleMDE@2.18.0-r","Katex@0.11.1-r"],"mimes":["dir"], "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/Booklet/build/release/Booklet.zip" }, {