first commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
if you want to view the source, please visit the github repository of this plugin
|
||||
*/
|
||||
|
||||
var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(u,o)=>{for(var s in o)L(u,s,{get:o[s],enumerable:!0})},W=(u,o,s,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of B(o))!H.call(u,t)&&t!==s&&L(u,t,{get:()=>o[t],enumerable:!(e=j(o,t))||e.enumerable});return u};var P=u=>W(L({},"__esModule",{value:!0}),u);var z={};M(z,{default:()=>C});module.exports=P(z);var r=require("obsidian"),F={ignoreSubstrings:["#donotsort"],statuses:["- [ ]","- [/]","- [x]","- [-]","- [>]","- [<]"],sortedStatuses:["- [x]","- [-]"],sortedSubstrings:["\u{1F53A}","\u23EB","\u{1F53D}","\u23EC"],intervalSeconds:5,reorderOnTabChange:!1},f=!1,m=null,C=class extends r.Plugin{constructor(){super(...arguments);this.lastActiveLeaf=null}async onload(){var s;await this.loadSettings(),this.addSettingTab(new T(this.app,this)),this.lastActiveLeaf=(s=this.app.workspace.activeLeaf)!=null?s:null,this.addCommand({id:"reorder-completed-tasks",name:"Reorder completed tasks",callback:()=>{f=!1;let e=this.app.workspace.activeLeaf;if(e)this.reorderLeaf(e);else{let t=this.app.workspace.getActiveViewOfType(r.MarkdownView);t&&this.reorderView(t)}}}),this.registerEvent(this.app.vault.on("modify",e=>{f=!0})),this.registerEvent(this.app.workspace.on("active-leaf-change",e=>{let t=this.lastActiveLeaf;this.lastActiveLeaf=e!=null?e:null,this.settings.reorderOnTabChange&&f&&t&&this.reorderLeaf(t)})),this.scheduleReorderInterval()}onunload(){}scheduleReorderInterval(){if(m!==null&&(window.clearInterval(m),m=null),this.settings.intervalSeconds<=0)return;let s=window.setInterval(()=>{if(f){f=!1;let e=this.app.workspace.activeLeaf;e&&this.reorderLeaf(e)}},this.settings.intervalSeconds*1e3);m=s,this.registerInterval(s)}findSortval(s,e,t=!1){for(let[a,h]of e.entries())if(t&&s.indexOf(h)>=0||s.startsWith(h))return a+1;return 0}lineHasChecklist(s){return this.settings.statuses.some(e=>s.startsWith(e))}reorderLeaf(s){let e=s.view;if(!(e instanceof r.MarkdownView))return;let t=s.getViewState();t&&t.state&&t.state.mode=="preview"&&s.setViewState({...t,state:{mode:"source",source:!1}}),this.reorderView(e),t&&t.state&&t.state.mode=="preview"&&window.setTimeout(()=>{s.setViewState(t)},10)}reorderView(s){var I;let e=s.file;if(e){let n=this.app.metadataCache.getFileCache(e),i=(I=n==null?void 0:n.frontmatter)==null?void 0:I.completedTasks;if(typeof i=="boolean"&&i===!1||typeof i=="string"&&i.trim().toLowerCase()==="false")return}let t=s.editor,a=t.getCursor("anchor"),h=t.getCursor("head"),y=t.getValue(),w=[],c=[],g=-1,O=!1,S=!1,d=y.split(`
|
||||
`);for(let n=0;n<d.length;n++){let i=d[n],l=n>0?d[n-1]:!1,p=n+1<d.length?d[n+1]:!1,A=n===h.line;!S&&this.settings.ignoreSubstrings.some(v=>i.indexOf(v)>=0)&&(S=!0);let N=this.lineHasChecklist(i.trim()),R=p?this.lineHasChecklist(p.trim()):!1,D=this.lineHasChecklist(i);if(!D&&N&&g>=0?c[g].sublines.push({line:i,sublines:[],hasCursor:A,statusSortval:0,subSortval:0}):(c.push({line:i,sublines:[],hasCursor:A,statusSortval:0,subSortval:0}),D&&(g=c.length-1)),!p||N!==R){let v=g>=0;v&&(O=S,S=!1),w.push({lines:c,hasChecklists:v,ignoreBlock:O}),c=[],g=-1}}if(!w.some(n=>n.hasChecklists))return;let V=n=>n.map(i=>{let l=i.line.trimStart();return i.statusSortval=this.findSortval(l,this.settings.sortedStatuses),i.subSortval=this.settings.sortedSubstrings.length-this.findSortval(l,this.settings.sortedSubstrings,!0),i.sublines.length&&(i.sublines=V(i.sublines)),i}).sort((i,l)=>i.statusSortval!=l.statusSortval?i.statusSortval>l.statusSortval?1:-1:i.subSortval!=l.subSortval?i.subSortval>l.subSortval?1:-1:0),E=w.map(n=>n.ignoreBlock||!n.hasChecklists?n.lines:V(n.lines)).flat(),b=h.line,k=[];E.forEach((n,i)=>{n.hasCursor&&(b=i),k.push(n.line),n.sublines.forEach((l,p)=>{l.hasCursor&&(b=i+p),k.push(l.line)})});let x=k.join(`
|
||||
`);x!==y&&(t.setValue(x),t.setSelection({line:b,ch:h.ch}))}async loadSettings(){this.settings=Object.assign({},F,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}},T=class extends r.PluginSettingTab{constructor(s,e){super(s,e);this.plugin=e}display(){let{containerEl:s}=this;s.empty(),new r.Setting(s).setName("Statuses").setDesc("Comma separated. Lines beginning with any of these are recognized as todo's.").addTextArea(e=>e.setValue(this.plugin.settings.statuses.join(",")).onChange(async t=>{this.plugin.settings.statuses=t.split(",").map(a=>a&&a.trim()),await this.plugin.saveSettings()})),new r.Setting(s).setName("Sorting").setDesc("Comma separated. Sort order for statuses, from high to low.").addTextArea(e=>e.setValue(this.plugin.settings.sortedStatuses.join(",")).onChange(async t=>{this.plugin.settings.sortedStatuses=t.split(",").map(a=>a&&a.trim()),await this.plugin.saveSettings()})),new r.Setting(s).setName("Subsorting").setDesc("Comma separated. Strings for sub-sorting, from high to low.").addTextArea(e=>e.setValue(this.plugin.settings.sortedSubstrings.join(",")).onChange(async t=>{this.plugin.settings.sortedSubstrings=t.split(",").map(a=>a&&a.trim()),await this.plugin.saveSettings()})),new r.Setting(s).setName("Blacklist words").setDesc("Comma separated. Add any of these above a list to have this plugin ignore it.").addTextArea(e=>e.setValue(this.plugin.settings.ignoreSubstrings.join(",")).onChange(async t=>{this.plugin.settings.ignoreSubstrings=t.split(",").map(a=>a&&a.trim()),await this.plugin.saveSettings()})),new r.Setting(s).setName("Interval").setDesc("Interval at which the plugin runs, in seconds. Set to 0 to disable automatic sorting.").addText(e=>e.setValue(""+this.plugin.settings.intervalSeconds).onChange(async t=>{let a=parseInt(t);this.plugin.settings.intervalSeconds=Math.max(0,Math.min(999,isNaN(a)?0:a)),await this.plugin.saveSettings(),this.plugin.scheduleReorderInterval()})),new r.Setting(s).setName("Reorder on tab change").setDesc("Reorder the active note when switching tabs or focus.").addToggle(e=>e.setValue(this.plugin.settings.reorderOnTabChange).onChange(async t=>{this.plugin.settings.reorderOnTabChange=t,await this.plugin.saveSettings()}))}};
|
||||
|
||||
/* nosourcemap */
|
||||
Reference in New Issue
Block a user