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.

172 lines
22 KiB

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
11 months ago
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
3 years ago
}
11 months ago
return to;
3 years ago
};
11 months ago
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
3 years ago
// main.ts
11 months ago
var main_exports = {};
__export(main_exports, {
3 years ago
DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
default: () => PackratPlugin
});
11 months ago
module.exports = __toCommonJS(main_exports);
var import_obsidian = require("obsidian");
3 years ago
var DEFAULT_SETTINGS = {
deletion_trigger: "%%done_del%%",
bottom_trigger: "%%done_end%%",
archive_trigger: "%%done_log%%",
archive_filepath: "archive.md"
};
var PackratPlugin = class extends import_obsidian.Plugin {
11 months ago
async onload() {
console.log("Packrat: Loading...");
await this.loadSettings();
this.addSettingTab(new PackratSettingTab(this.app, this));
this.addCommand({
// (to the Command Palette)
id: "run",
name: "Process completed recurring Tasks within the active note",
checkCallback: (checking) => {
const { workspace } = this.app;
const activeFile = workspace.getActiveFile();
if (activeFile && activeFile.extension == "md") {
if (checking) {
return true;
3 years ago
}
11 months ago
this.ProcessCompletedRecurringTasks(activeFile);
} else {
return false;
3 years ago
}
11 months ago
}
3 years ago
});
}
onunload() {
console.log("Packrat: Unloading...");
}
11 months ago
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
3 years ago
}
11 months ago
async saveSettings() {
await this.saveData(this.settings);
3 years ago
}
11 months ago
async ProcessCompletedRecurringTasks(activeFile) {
try {
const { vault } = this.app;
const rruleSignifier = "\u{1F501}".normalize();
const dv_rruleSignifier = "[repeat::";
const deleteTrigger = this.settings.deletion_trigger;
const archiveTrigger = this.settings.archive_trigger;
const bottomTrigger = this.settings.bottom_trigger;
const archiveFilename = this.settings.archive_filepath;
const archiveFile = vault.getAbstractFileByPath(archiveFilename) || await vault.create(archiveFilename, "");
let deletedTaskCount = 0;
let movedTaskCount = 0;
let archivedTaskCount = 0;
let thisLine = "";
let writebackLines = [];
let appendLines = [];
let archiveLines = [];
let results = [];
let fileContents = await vault.read(activeFile);
fileContents = fileContents.split("\n");
for (let i = 0; i < fileContents.length; i++) {
thisLine = fileContents[i];
let firstFive = thisLine.trim().substring(0, 5).toUpperCase();
if (firstFive === "- [X]" && (thisLine.indexOf(rruleSignifier) != -1 || thisLine.indexOf(dv_rruleSignifier) != -1)) {
if (0 < thisLine.indexOf(deleteTrigger)) {
deletedTaskCount += 1;
continue;
3 years ago
}
11 months ago
if (0 < thisLine.indexOf(archiveTrigger)) {
archiveLines.push(thisLine);
archivedTaskCount += 1;
continue;
}
if (0 < thisLine.indexOf(bottomTrigger)) {
appendLines.push(thisLine);
movedTaskCount += 1;
continue;
}
writebackLines.push(thisLine);
} else {
writebackLines.push(thisLine);
3 years ago
}
11 months ago
}
if (archivedTaskCount > 0) {
let archiveFileContents = await vault.read(archiveFile);
archiveFileContents = archiveFileContents.split("\n");
archiveFileContents = archiveFileContents.concat(archiveLines);
vault.modify(archiveFile, archiveFileContents.join("\n"));
}
results = writebackLines.concat(appendLines);
vault.modify(activeFile, results.join("\n"));
var tdMsg = `${deletedTaskCount} tasks deleted
3 years ago
`;
11 months ago
var tmMsg = `${movedTaskCount} tasks moved to end of note
3 years ago
`;
11 months ago
var taMsg = `${archivedTaskCount} tasks archived
3 years ago
`;
11 months ago
const noticeText = tdMsg + tmMsg + taMsg;
new import_obsidian.Notice(noticeText);
} catch (err) {
new import_obsidian.Notice(err);
console.log(err);
return;
}
3 years ago
}
};
var PackratSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.defaultDeletionTrigger = "%%done_del%%";
this.defaultBottomTrigger = "%%done_move%%";
this.defaultArchiveTrigger = "%%done_log%%";
this.defaultArchiveFilepath = "logfile.md";
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Packrat plugin settings" });
11 months ago
new import_obsidian.Setting(containerEl).setName("Deletion trigger").setDesc("Text to trigger deletion of completed recurring Task instance").addText((text) => text.setPlaceholder(this.defaultDeletionTrigger).setValue(this.plugin.settings.deletion_trigger).onChange(async (value) => {
3 years ago
console.log("deletion_trigger: " + value);
this.plugin.settings.deletion_trigger = value;
11 months ago
await this.plugin.saveSettings();
}));
new import_obsidian.Setting(containerEl).setName('"Move to end of file" trigger').setDesc("Text to trigger moving completed recurring Task instance to bottom of Active note").addText((text) => text.setPlaceholder(this.defaultbottomTrigger).setValue(this.plugin.settings.bottom_trigger).onChange(async (value) => {
3 years ago
console.log("bottom_trigger: " + value);
this.plugin.settings.bottom_trigger = value;
11 months ago
await this.plugin.saveSettings();
}));
new import_obsidian.Setting(containerEl).setName("Archive trigger").setDesc("Text to trigger moving completed recurring Task instance to archive note").addText((text) => text.setPlaceholder(this.defaultarchiveTrigger).setValue(this.plugin.settings.archive_trigger).onChange(async (value) => {
3 years ago
console.log("archive_trigger: " + value);
this.plugin.settings.archive_trigger = value;
11 months ago
await this.plugin.saveSettings();
}));
new import_obsidian.Setting(containerEl).setName("Archive file").setDesc('Relative filepath to archive file (include ".md" extension)').addText((text) => text.setPlaceholder(this.defaultArchiveFilepath).setValue(this.plugin.settings.archive_filepath).onChange(async (value) => {
3 years ago
console.log("archive_filepath: " + value);
this.plugin.settings.archive_filepath = value;
11 months ago
await this.plugin.saveSettings();
}));
3 years ago
}
};
11 months ago
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibWFpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0IHsgQXBwLCBOb3RpY2UsIFBsdWdpbiwgUGx1Z2luU2V0dGluZ1RhYiwgU2V0dGluZywgVEZpbGUgfSBmcm9tICdvYnNpZGlhbic7XHJcblxyXG5leHBvcnQgaW50ZXJmYWNlIFBhY2tyYXRTZXR0aW5ncyB7XHJcblx0ZGVsZXRpb25fdHJpZ2dlcjogc3RyaW5nO1xyXG5cdGJvdHRvbV90cmlnZ2VyOiBzdHJpbmc7XHJcblx0YXJjaGl2ZV90cmlnZ2VyOiBzdHJpbmc7XHJcblx0YXJjaGl2ZV9maWxlcGF0aDogc3RyaW5nO1xyXG59XHJcblxyXG5leHBvcnQgY29uc3QgREVGQVVMVF9TRVRUSU5HUzogUGFja3JhdFNldHRpbmdzID0ge1xyXG5cdGRlbGV0aW9uX3RyaWdnZXI6ICclJWRvbmVfZGVsJSUnLFxyXG5cdGJvdHRvbV90cmlnZ2VyOiAnJSVkb25lX2VuZCUlJyxcclxuXHRhcmNoaXZlX3RyaWdnZXI6ICclJWRvbmVfbG9nJSUnLFxyXG5cdGFyY2hpdmVfZmlsZXBhdGg6ICdhcmNoaXZlLm1kJyxcclxufVxyXG5cclxuZXhwb3J0IGRlZmF1bHQgY2xhc3MgUGFja3JhdFBsdWdpbiBleHRlbmRzIFBsdWdpbiB7XHJcblx0c2V0dGluZ3M6IFBhY2tyYXRTZXR0aW5ncztcclxuXHJcblx0YXN5bmMgb25sb2FkKCkge1xyXG5cdFx0Y29uc29sZS5sb2coJ1BhY2tyYXQ6IExvYWRpbmcuLi4nKVxyXG5cclxuXHRcdGF3YWl0IHRoaXMubG9hZFNldHRpbmdzKCk7XHJcblxyXG5cdFx0dGhpcy5hZGRTZXR0aW5nVGFiKG5ldyBQ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