vault backup: 2022-09-19 13:48:59

This commit is contained in:
Daniel Bulant 2022-09-19 13:48:59 +02:00
parent d762580b9c
commit f27f505b0e
11 changed files with 8437 additions and 9668 deletions

View file

@ -12,7 +12,7 @@
"checkpointList": [ "checkpointList": [
{ {
"path": "/", "path": "/",
"date": "2022-09-15", "date": "2022-09-17",
"size": 899584 "size": 899584
} }
], ],
@ -795,6 +795,14 @@
{ {
"date": "2022-09-15", "date": "2022-09-15",
"value": 403 "value": 403
},
{
"date": "2022-09-16",
"value": 0
},
{
"date": "2022-09-17",
"value": 0
} }
] ]
} }

View file

@ -5,7 +5,7 @@
"scriptFolderPath": "Excalidraw/Scripts", "scriptFolderPath": "Excalidraw/Scripts",
"compress": false, "compress": false,
"autosave": true, "autosave": true,
"autosaveInterval": 10000, "autosaveInterval": 15000,
"drawingFilenamePrefix": "Drawing ", "drawingFilenamePrefix": "Drawing ",
"drawingEmbedPrefixWithFilename": true, "drawingEmbedPrefixWithFilename": true,
"drawingFilnameEmbedPostfix": " ", "drawingFilnameEmbedPostfix": " ",
@ -71,7 +71,7 @@
"mdCSS": "", "mdCSS": "",
"scriptEngineSettings": {}, "scriptEngineSettings": {},
"defaultTrayMode": false, "defaultTrayMode": false,
"previousRelease": "1.7.19", "previousRelease": "1.7.20",
"showReleaseNotes": true, "showReleaseNotes": true,
"showNewVersionNotification": true, "showNewVersionNotification": true,
"mathjaxSourceURL": "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js", "mathjaxSourceURL": "https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-svg.js",

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{ {
"id": "obsidian-excalidraw-plugin", "id": "obsidian-excalidraw-plugin",
"name": "Excalidraw", "name": "Excalidraw",
"version": "1.7.19", "version": "1.7.20",
"minAppVersion": "0.15.6", "minAppVersion": "0.15.6",
"description": "An Obsidian plugin to edit and view Excalidraw drawings", "description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian", "author": "Zsolt Viczian",

File diff suppressed because it is too large Load diff

View file

@ -4,5 +4,5 @@
"description": "Backup your vault with Git.", "description": "Backup your vault with Git.",
"isDesktopOnly": false, "isDesktopOnly": false,
"js": "main.js", "js": "main.js",
"version": "2.1.0" "version": "2.1.1"
} }

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{ {
"id": "obsidian-kanban", "id": "obsidian-kanban",
"name": "Kanban", "name": "Kanban",
"version": "1.3.17", "version": "1.3.20",
"minAppVersion": "0.15.3", "minAppVersion": "0.15.3",
"description": "Create markdown-backed Kanban boards in Obsidian.", "description": "Create markdown-backed Kanban boards in Obsidian.",
"author": "mgmeyers", "author": "mgmeyers",

File diff suppressed because one or more lines are too long

View file

@ -1765,8 +1765,7 @@ var Suggest = class {
} }
}; };
var TextInputSuggest = class { var TextInputSuggest = class {
constructor(app, inputEl) { constructor(inputEl) {
this.app = app;
this.inputEl = inputEl; this.inputEl = inputEl;
this.scope = new import_obsidian2.Scope(); this.scope = new import_obsidian2.Scope();
this.suggestEl = createDiv("suggestion-container"); this.suggestEl = createDiv("suggestion-container");
@ -1789,13 +1788,13 @@ var TextInputSuggest = class {
} }
if (suggestions.length > 0) { if (suggestions.length > 0) {
this.suggest.setSuggestions(suggestions); this.suggest.setSuggestions(suggestions);
this.open(this.app.dom.appContainerEl, this.inputEl); this.open(app.dom.appContainerEl, this.inputEl);
} else { } else {
this.close(); this.close();
} }
} }
open(container, inputEl) { open(container, inputEl) {
this.app.keymap.pushScope(this.scope); app.keymap.pushScope(this.scope);
container.appendChild(this.suggestEl); container.appendChild(this.suggestEl);
this.popper = createPopper(inputEl, this.suggestEl, { this.popper = createPopper(inputEl, this.suggestEl, {
placement: "bottom-start", placement: "bottom-start",
@ -1818,7 +1817,7 @@ var TextInputSuggest = class {
}); });
} }
close() { close() {
this.app.keymap.popScope(this.scope); app.keymap.popScope(this.scope);
this.suggest.setSuggestions([]); this.suggest.setSuggestions([]);
if (this.popper) if (this.popper)
this.popper.destroy(); this.popper.destroy();
@ -1829,7 +1828,7 @@ var TextInputSuggest = class {
// src/settings/suggesters/FolderSuggester.ts // src/settings/suggesters/FolderSuggester.ts
var FolderSuggest = class extends TextInputSuggest { var FolderSuggest = class extends TextInputSuggest {
getSuggestions(inputStr) { getSuggestions(inputStr) {
const abstractFiles = this.app.vault.getAllLoadedFiles(); const abstractFiles = app.vault.getAllLoadedFiles();
const folders = []; const folders = [];
const lowerCaseInputStr = inputStr.toLowerCase(); const lowerCaseInputStr = inputStr.toLowerCase();
abstractFiles.forEach((folder) => { abstractFiles.forEach((folder) => {
@ -1863,7 +1862,7 @@ function escape_RegExp(str) {
function generate_dynamic_command_regex() { function generate_dynamic_command_regex() {
return /(<%(?:-|_)?\s*[*~]{0,1})\+((?:.|\s)*?%>)/g; return /(<%(?:-|_)?\s*[*~]{0,1})\+((?:.|\s)*?%>)/g;
} }
function resolve_tfolder(app, folder_str) { function resolve_tfolder(folder_str) {
folder_str = (0, import_obsidian4.normalizePath)(folder_str); folder_str = (0, import_obsidian4.normalizePath)(folder_str);
const folder = app.vault.getAbstractFileByPath(folder_str); const folder = app.vault.getAbstractFileByPath(folder_str);
if (!folder) { if (!folder) {
@ -1874,7 +1873,7 @@ function resolve_tfolder(app, folder_str) {
} }
return folder; return folder;
} }
function resolve_tfile(app, file_str) { function resolve_tfile(file_str) {
file_str = (0, import_obsidian4.normalizePath)(file_str); file_str = (0, import_obsidian4.normalizePath)(file_str);
const file = app.vault.getAbstractFileByPath(file_str); const file = app.vault.getAbstractFileByPath(file_str);
if (!file) { if (!file) {
@ -1885,8 +1884,8 @@ function resolve_tfile(app, file_str) {
} }
return file; return file;
} }
function get_tfiles_from_folder(app, folder_str) { function get_tfiles_from_folder(folder_str) {
const folder = resolve_tfolder(app, folder_str); const folder = resolve_tfolder(folder_str);
const files = []; const files = [];
import_obsidian4.Vault.recurseChildren(folder, (file) => { import_obsidian4.Vault.recurseChildren(folder, (file) => {
if (file instanceof import_obsidian4.TFile) { if (file instanceof import_obsidian4.TFile) {
@ -1914,9 +1913,8 @@ var FileSuggestMode;
FileSuggestMode2[FileSuggestMode2["ScriptFiles"] = 1] = "ScriptFiles"; FileSuggestMode2[FileSuggestMode2["ScriptFiles"] = 1] = "ScriptFiles";
})(FileSuggestMode || (FileSuggestMode = {})); })(FileSuggestMode || (FileSuggestMode = {}));
var FileSuggest = class extends TextInputSuggest { var FileSuggest = class extends TextInputSuggest {
constructor(app, inputEl, plugin, mode) { constructor(inputEl, plugin, mode) {
super(app, inputEl); super(inputEl);
this.app = app;
this.inputEl = inputEl; this.inputEl = inputEl;
this.plugin = plugin; this.plugin = plugin;
this.mode = mode; this.mode = mode;
@ -1938,7 +1936,7 @@ var FileSuggest = class extends TextInputSuggest {
} }
} }
getSuggestions(input_str) { getSuggestions(input_str) {
const all_files = errorWrapperSync(() => get_tfiles_from_folder(this.app, this.get_folder(this.mode)), this.get_error_msg(this.mode)); const all_files = errorWrapperSync(() => get_tfiles_from_folder(this.get_folder(this.mode)), this.get_error_msg(this.mode));
if (!all_files) { if (!all_files) {
return []; return [];
} }
@ -1979,9 +1977,8 @@ var DEFAULT_SETTINGS = {
enable_ribbon_icon: true enable_ribbon_icon: true
}; };
var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab { var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
constructor(app, plugin) { constructor(plugin) {
super(app, plugin); super(app, plugin);
this.app = app;
this.plugin = plugin; this.plugin = plugin;
} }
display() { display() {
@ -2006,7 +2003,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
} }
add_template_folder_setting() { add_template_folder_setting() {
new import_obsidian6.Setting(this.containerEl).setName("Template folder location").setDesc("Files in this folder will be available as templates.").addSearch((cb) => { new import_obsidian6.Setting(this.containerEl).setName("Template folder location").setDesc("Files in this folder will be available as templates.").addSearch((cb) => {
new FolderSuggest(this.app, cb.inputEl); new FolderSuggest(cb.inputEl);
cb.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.templates_folder).onChange((new_folder) => { cb.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.templates_folder).onChange((new_folder) => {
this.plugin.settings.templates_folder = new_folder; this.plugin.settings.templates_folder = new_folder;
this.plugin.save_settings(); this.plugin.save_settings();
@ -2067,7 +2064,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
this.plugin.save_settings(); this.plugin.save_settings();
if (this.plugin.settings.enable_ribbon_icon) { if (this.plugin.settings.enable_ribbon_icon) {
this.plugin.addRibbonIcon("templater-icon", "Templater", () => __async(this, null, function* () { this.plugin.addRibbonIcon("templater-icon", "Templater", () => __async(this, null, function* () {
this.fuzzy_suggester.insert_template(); this.plugin.fuzzy_suggester.insert_template();
})).setAttribute("id", "rb-templater-icon"); })).setAttribute("id", "rb-templater-icon");
} else { } else {
(_a = document.getElementById("rb-templater-icon")) == null ? void 0 : _a.remove(); (_a = document.getElementById("rb-templater-icon")) == null ? void 0 : _a.remove();
@ -2082,7 +2079,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
new import_obsidian6.Setting(this.containerEl).setDesc(desc); new import_obsidian6.Setting(this.containerEl).setDesc(desc);
this.plugin.settings.enabled_templates_hotkeys.forEach((template, index) => { this.plugin.settings.enabled_templates_hotkeys.forEach((template, index) => {
const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => { const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => {
new FileSuggest(this.app, cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles); new FileSuggest(cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles);
cb.setPlaceholder("Example: folder1/template_file").setValue(template).onChange((new_template) => { cb.setPlaceholder("Example: folder1/template_file").setValue(template).onChange((new_template) => {
if (new_template && this.plugin.settings.enabled_templates_hotkeys.contains(new_template)) { if (new_template && this.plugin.settings.enabled_templates_hotkeys.contains(new_template)) {
log_error(new TemplaterError("This template is already bound to a hotkey")); log_error(new TemplaterError("This template is already bound to a hotkey"));
@ -2095,8 +2092,8 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
cb.containerEl.addClass("templater_search"); cb.containerEl.addClass("templater_search");
}).addExtraButton((cb) => { }).addExtraButton((cb) => {
cb.setIcon("any-key").setTooltip("Configure Hotkey").onClick(() => { cb.setIcon("any-key").setTooltip("Configure Hotkey").onClick(() => {
this.app.setting.openTabById("hotkeys"); app.setting.openTabById("hotkeys");
const tab = this.app.setting.activeTab; const tab = app.setting.activeTab;
tab.searchInputEl.value = "Templater: Insert"; tab.searchInputEl.value = "Templater: Insert";
tab.updateHotkeyVisibility(); tab.updateHotkeyVisibility();
}); });
@ -2159,7 +2156,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
}); });
this.plugin.settings.folder_templates.forEach((folder_template, index) => { this.plugin.settings.folder_templates.forEach((folder_template, index) => {
const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => { const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => {
new FolderSuggest(this.app, cb.inputEl); new FolderSuggest(cb.inputEl);
cb.setPlaceholder("Folder").setValue(folder_template.folder).onChange((new_folder) => { cb.setPlaceholder("Folder").setValue(folder_template.folder).onChange((new_folder) => {
if (new_folder && this.plugin.settings.folder_templates.some((e) => e.folder == new_folder)) { if (new_folder && this.plugin.settings.folder_templates.some((e) => e.folder == new_folder)) {
log_error(new TemplaterError("This folder already has a template associated with it")); log_error(new TemplaterError("This folder already has a template associated with it"));
@ -2170,7 +2167,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
}); });
cb.containerEl.addClass("templater_search"); cb.containerEl.addClass("templater_search");
}).addSearch((cb) => { }).addSearch((cb) => {
new FileSuggest(this.app, cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles); new FileSuggest(cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles);
cb.setPlaceholder("Template").setValue(folder_template.template).onChange((new_template) => { cb.setPlaceholder("Template").setValue(folder_template.template).onChange((new_template) => {
this.plugin.settings.folder_templates[index].template = new_template; this.plugin.settings.folder_templates[index].template = new_template;
this.plugin.save_settings(); this.plugin.save_settings();
@ -2205,7 +2202,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
new import_obsidian6.Setting(this.containerEl).setDesc(desc); new import_obsidian6.Setting(this.containerEl).setDesc(desc);
this.plugin.settings.startup_templates.forEach((template, index) => { this.plugin.settings.startup_templates.forEach((template, index) => {
const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => { const s = new import_obsidian6.Setting(this.containerEl).addSearch((cb) => {
new FileSuggest(this.app, cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles); new FileSuggest(cb.inputEl, this.plugin, FileSuggestMode.TemplateFiles);
cb.setPlaceholder("Example: folder1/template_file").setValue(template).onChange((new_template) => { cb.setPlaceholder("Example: folder1/template_file").setValue(template).onChange((new_template) => {
if (new_template && this.plugin.settings.startup_templates.contains(new_template)) { if (new_template && this.plugin.settings.startup_templates.contains(new_template)) {
log_error(new TemplaterError("This startup template already exist")); log_error(new TemplaterError("This startup template already exist"));
@ -2240,7 +2237,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
text: "documentation" text: "documentation"
}), " for more information."); }), " for more information.");
new import_obsidian6.Setting(this.containerEl).setName("Script files folder location").setDesc(desc).addSearch((cb) => { new import_obsidian6.Setting(this.containerEl).setName("Script files folder location").setDesc(desc).addSearch((cb) => {
new FolderSuggest(this.app, cb.inputEl); new FolderSuggest(cb.inputEl);
cb.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.user_scripts_folder).onChange((new_folder) => { cb.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.user_scripts_folder).onChange((new_folder) => {
this.plugin.settings.user_scripts_folder = new_folder; this.plugin.settings.user_scripts_folder = new_folder;
this.plugin.save_settings(); this.plugin.save_settings();
@ -2252,7 +2249,7 @@ var TemplaterSettingTab = class extends import_obsidian6.PluginSettingTab {
if (!this.plugin.settings.user_scripts_folder) { if (!this.plugin.settings.user_scripts_folder) {
name = "No User Scripts folder set"; name = "No User Scripts folder set";
} else { } else {
const files = errorWrapperSync(() => get_tfiles_from_folder(this.app, this.plugin.settings.user_scripts_folder), `User Scripts folder doesn't exist`); const files = errorWrapperSync(() => get_tfiles_from_folder(this.plugin.settings.user_scripts_folder), `User Scripts folder doesn't exist`);
if (!files || files.length === 0) { if (!files || files.length === 0) {
name = "No User Scripts detected"; name = "No User Scripts detected";
} else { } else {
@ -2376,17 +2373,16 @@ var OpenMode;
OpenMode2[OpenMode2["CreateNoteTemplate"] = 1] = "CreateNoteTemplate"; OpenMode2[OpenMode2["CreateNoteTemplate"] = 1] = "CreateNoteTemplate";
})(OpenMode || (OpenMode = {})); })(OpenMode || (OpenMode = {}));
var FuzzySuggester = class extends import_obsidian7.FuzzySuggestModal { var FuzzySuggester = class extends import_obsidian7.FuzzySuggestModal {
constructor(app, plugin) { constructor(plugin) {
super(app); super(app);
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.setPlaceholder("Type name of a template..."); this.setPlaceholder("Type name of a template...");
} }
getItems() { getItems() {
if (!this.plugin.settings.templates_folder) { if (!this.plugin.settings.templates_folder) {
return this.app.vault.getMarkdownFiles(); return app.vault.getMarkdownFiles();
} }
const files = errorWrapperSync(() => get_tfiles_from_folder(this.app, this.plugin.settings.templates_folder), `Couldn't retrieve template files from templates folder ${this.plugin.settings.templates_folder}`); const files = errorWrapperSync(() => get_tfiles_from_folder(this.plugin.settings.templates_folder), `Couldn't retrieve template files from templates folder ${this.plugin.settings.templates_folder}`);
if (!files) { if (!files) {
return []; return [];
} }
@ -2432,8 +2428,7 @@ var import_obsidian13 = __toModule(require("obsidian"));
// src/core/functions/internal_functions/InternalModule.ts // src/core/functions/internal_functions/InternalModule.ts
var InternalModule = class { var InternalModule = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.static_functions = new Map(); this.static_functions = new Map();
this.dynamic_functions = new Map(); this.dynamic_functions = new Map();
@ -2545,7 +2540,7 @@ var InternalModuleFile = class extends InternalModule {
} }
generate_content() { generate_content() {
return __async(this, null, function* () { return __async(this, null, function* () {
return yield this.app.vault.read(this.config.target_file); return yield app.vault.read(this.config.target_file);
}); });
} }
generate_create_new() { generate_create_new() {
@ -2572,7 +2567,7 @@ var InternalModuleFile = class extends InternalModule {
} }
generate_cursor_append() { generate_cursor_append() {
return (content) => { return (content) => {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian8.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian8.MarkdownView);
if (active_view === null) { if (active_view === null) {
log_error(new TemplaterError("No active view, can't append to cursor.")); log_error(new TemplaterError("No active view, can't append to cursor."));
return; return;
@ -2584,19 +2579,14 @@ var InternalModuleFile = class extends InternalModule {
}; };
} }
generate_exists() { generate_exists() {
return (filename) => { return (filename) => __async(this, null, function* () {
let match; return yield app.vault.exists(filename);
if ((match = this.linkpath_regex.exec(filename)) !== null) { });
filename = match[1];
}
const file = this.app.metadataCache.getFirstLinkpathDest(filename, "");
return file != null;
};
} }
generate_find_tfile() { generate_find_tfile() {
return (filename) => { return (filename) => {
const path = (0, import_obsidian8.normalizePath)(filename); const path = (0, import_obsidian8.normalizePath)(filename);
return this.app.metadataCache.getFirstLinkpathDest(path, ""); return app.metadataCache.getFirstLinkpathDest(path, "");
}; };
} }
generate_folder() { generate_folder() {
@ -2621,7 +2611,7 @@ var InternalModuleFile = class extends InternalModule {
} }
let inc_file_content; let inc_file_content;
if (include_link instanceof import_obsidian8.TFile) { if (include_link instanceof import_obsidian8.TFile) {
inc_file_content = yield this.app.vault.read(include_link); inc_file_content = yield app.vault.read(include_link);
} else { } else {
let match; let match;
if ((match = this.linkpath_regex.exec(include_link)) === null) { if ((match = this.linkpath_regex.exec(include_link)) === null) {
@ -2629,14 +2619,14 @@ var InternalModuleFile = class extends InternalModule {
throw new TemplaterError("Invalid file format, provide an obsidian link between quotes."); throw new TemplaterError("Invalid file format, provide an obsidian link between quotes.");
} }
const { path, subpath } = (0, import_obsidian8.parseLinktext)(match[1]); const { path, subpath } = (0, import_obsidian8.parseLinktext)(match[1]);
const inc_file = this.app.metadataCache.getFirstLinkpathDest(path, ""); const inc_file = app.metadataCache.getFirstLinkpathDest(path, "");
if (!inc_file) { if (!inc_file) {
this.include_depth -= 1; this.include_depth -= 1;
throw new TemplaterError(`File ${include_link} doesn't exist`); throw new TemplaterError(`File ${include_link} doesn't exist`);
} }
inc_file_content = yield this.app.vault.read(inc_file); inc_file_content = yield app.vault.read(inc_file);
if (subpath) { if (subpath) {
const cache = this.app.metadataCache.getFileCache(inc_file); const cache = app.metadataCache.getFileCache(inc_file);
if (cache) { if (cache) {
const result = (0, import_obsidian8.resolveSubpath)(cache, subpath); const result = (0, import_obsidian8.resolveSubpath)(cache, subpath);
if (result) { if (result) {
@ -2672,19 +2662,24 @@ var InternalModuleFile = class extends InternalModule {
yield window.app.vault.createFolder(dir); yield window.app.vault.createFolder(dir);
} }
} }
yield this.app.fileManager.renameFile(file, new_path); yield app.fileManager.renameFile(file, new_path);
return ""; return "";
}); });
} }
generate_path() { generate_path() {
return (relative = false) => { return (relative = false) => {
let vault_path = "";
if (import_obsidian8.Platform.isMobileApp) { if (import_obsidian8.Platform.isMobileApp) {
return UNSUPPORTED_MOBILE_TEMPLATE; const vault_adapter = app.vault.adapter.fs.uri;
} const vault_base = app.vault.adapter.basePath;
if (!(this.app.vault.adapter instanceof import_obsidian8.FileSystemAdapter)) { vault_path = `${vault_adapter}/${vault_base}`;
} else {
if (app.vault.adapter instanceof import_obsidian8.FileSystemAdapter) {
vault_path = app.vault.adapter.getBasePath();
} else {
throw new TemplaterError("app.vault is not a FileSystemAdapter instance"); throw new TemplaterError("app.vault is not a FileSystemAdapter instance");
} }
const vault_path = this.app.vault.adapter.getBasePath(); }
if (relative) { if (relative) {
return this.config.target_file.path; return this.config.target_file.path;
} else { } else {
@ -2698,13 +2693,13 @@ var InternalModuleFile = class extends InternalModule {
throw new TemplaterError("File name cannot contain any of these characters: \\ / :"); throw new TemplaterError("File name cannot contain any of these characters: \\ / :");
} }
const new_path = (0, import_obsidian8.normalizePath)(`${this.config.target_file.parent.path}/${new_title}.${this.config.target_file.extension}`); const new_path = (0, import_obsidian8.normalizePath)(`${this.config.target_file.parent.path}/${new_title}.${this.config.target_file.extension}`);
yield this.app.fileManager.renameFile(this.config.target_file, new_path); yield app.fileManager.renameFile(this.config.target_file, new_path);
return ""; return "";
}); });
} }
generate_selection() { generate_selection() {
return () => { return () => {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian8.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian8.MarkdownView);
if (active_view == null) { if (active_view == null) {
throw new TemplaterError("Active view is null, can't read selection."); throw new TemplaterError("Active view is null, can't read selection.");
} }
@ -2713,9 +2708,12 @@ var InternalModuleFile = class extends InternalModule {
}; };
} }
generate_tags() { generate_tags() {
const cache = this.app.metadataCache.getFileCache(this.config.target_file); const cache = app.metadataCache.getFileCache(this.config.target_file);
if (cache) {
return (0, import_obsidian8.getAllTags)(cache); return (0, import_obsidian8.getAllTags)(cache);
} }
return null;
}
generate_title() { generate_title() {
return this.config.target_file.basename; return this.config.target_file.basename;
} }
@ -2769,12 +2767,20 @@ var InternalModuleWeb = class extends InternalModule {
generate_random_picture() { generate_random_picture() {
return (size, query, include_size = false) => __async(this, null, function* () { return (size, query, include_size = false) => __async(this, null, function* () {
try { try {
const response = yield this.getRequest(`https://source.unsplash.com/random/${size != null ? size : ""}?${query != null ? query : ""}`); const response = yield this.getRequest(`https://templater-unsplash.fly.dev/${query ? "?q=" + query : ""}`).then((res) => res.json());
const url = response.url; let url = response.full;
if (include_size) { if (size && !include_size) {
return `![tp.web.random_picture|${size}](${url})`; if (size.includes("x")) {
const [width, height] = size.split("x");
url = url.concat(`&w=${width}&h=${height}`);
} else {
url = url.concat(`&w=${size}`);
} }
return `![tp.web.random_picture](${url})`; }
if (include_size) {
return `![photo by ${response.photog} on Unsplash|${size}](${url})`;
}
return `![photo by ${response.photog} on Unsplash](${url})`;
} catch (error) { } catch (error) {
new TemplaterError("Error generating random picture"); new TemplaterError("Error generating random picture");
return "Error generating random picture"; return "Error generating random picture";
@ -2795,7 +2801,7 @@ var InternalModuleFrontmatter = class extends InternalModule {
} }
create_dynamic_templates() { create_dynamic_templates() {
return __async(this, null, function* () { return __async(this, null, function* () {
const cache = this.app.metadataCache.getFileCache(this.config.target_file); const cache = app.metadataCache.getFileCache(this.config.target_file);
this.dynamic_functions = new Map(Object.entries((cache == null ? void 0 : cache.frontmatter) || {})); this.dynamic_functions = new Map(Object.entries((cache == null ? void 0 : cache.frontmatter) || {}));
}); });
} }
@ -2807,7 +2813,7 @@ var import_obsidian11 = __toModule(require("obsidian"));
// src/core/functions/internal_functions/system/PromptModal.ts // src/core/functions/internal_functions/system/PromptModal.ts
var import_obsidian9 = __toModule(require("obsidian")); var import_obsidian9 = __toModule(require("obsidian"));
var PromptModal = class extends import_obsidian9.Modal { var PromptModal = class extends import_obsidian9.Modal {
constructor(app, prompt_text, default_value, multi_line) { constructor(prompt_text, default_value, multi_line) {
super(app); super(app);
this.prompt_text = prompt_text; this.prompt_text = prompt_text;
this.default_value = default_value; this.default_value = default_value;
@ -2884,13 +2890,13 @@ var PromptModal = class extends import_obsidian9.Modal {
// src/core/functions/internal_functions/system/SuggesterModal.ts // src/core/functions/internal_functions/system/SuggesterModal.ts
var import_obsidian10 = __toModule(require("obsidian")); var import_obsidian10 = __toModule(require("obsidian"));
var SuggesterModal = class extends import_obsidian10.FuzzySuggestModal { var SuggesterModal = class extends import_obsidian10.FuzzySuggestModal {
constructor(app, text_items, items, placeholder, limit) { constructor(text_items, items, placeholder, limit) {
super(app); super(app);
this.text_items = text_items; this.text_items = text_items;
this.items = items; this.items = items;
this.submitted = false; this.submitted = false;
this.setPlaceholder(placeholder); this.setPlaceholder(placeholder);
this.limit = limit; limit && (this.limit = limit);
} }
getItems() { getItems() {
return this.items; return this.items;
@ -2950,7 +2956,7 @@ var InternalModuleSystem = class extends InternalModule {
} }
generate_prompt() { generate_prompt() {
return (prompt_text, default_value, throw_on_cancel = false, multi_line = false) => __async(this, null, function* () { return (prompt_text, default_value, throw_on_cancel = false, multi_line = false) => __async(this, null, function* () {
const prompt = new PromptModal(this.app, prompt_text, default_value, multi_line); const prompt = new PromptModal(prompt_text, default_value, multi_line);
const promise = new Promise((resolve2, reject) => prompt.openAndGetValue(resolve2, reject)); const promise = new Promise((resolve2, reject) => prompt.openAndGetValue(resolve2, reject));
try { try {
return yield promise; return yield promise;
@ -2964,7 +2970,7 @@ var InternalModuleSystem = class extends InternalModule {
} }
generate_suggester() { generate_suggester() {
return (text_items, items, throw_on_cancel = false, placeholder = "", limit) => __async(this, null, function* () { return (text_items, items, throw_on_cancel = false, placeholder = "", limit) => __async(this, null, function* () {
const suggester = new SuggesterModal(this.app, text_items, items, placeholder, limit); const suggester = new SuggesterModal(text_items, items, placeholder, limit);
const promise = new Promise((resolve2, reject) => suggester.openAndGetValue(resolve2, reject)); const promise = new Promise((resolve2, reject) => suggester.openAndGetValue(resolve2, reject));
try { try {
return yield promise; return yield promise;
@ -3001,16 +3007,15 @@ var InternalModuleConfig = class extends InternalModule {
// src/core/functions/internal_functions/InternalFunctions.ts // src/core/functions/internal_functions/InternalFunctions.ts
var InternalFunctions = class { var InternalFunctions = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.modules_array = []; this.modules_array = [];
this.modules_array.push(new InternalModuleDate(this.app, this.plugin)); this.modules_array.push(new InternalModuleDate(this.plugin));
this.modules_array.push(new InternalModuleFile(this.app, this.plugin)); this.modules_array.push(new InternalModuleFile(this.plugin));
this.modules_array.push(new InternalModuleWeb(this.app, this.plugin)); this.modules_array.push(new InternalModuleWeb(this.plugin));
this.modules_array.push(new InternalModuleFrontmatter(this.app, this.plugin)); this.modules_array.push(new InternalModuleFrontmatter(this.plugin));
this.modules_array.push(new InternalModuleSystem(this.app, this.plugin)); this.modules_array.push(new InternalModuleSystem(this.plugin));
this.modules_array.push(new InternalModuleConfig(this.app, this.plugin)); this.modules_array.push(new InternalModuleConfig(this.plugin));
} }
init() { init() {
return __async(this, null, function* () { return __async(this, null, function* () {
@ -3035,7 +3040,7 @@ var import_child_process = __toModule(require("child_process"));
var import_util = __toModule(require("util")); var import_util = __toModule(require("util"));
var import_obsidian12 = __toModule(require("obsidian")); var import_obsidian12 = __toModule(require("obsidian"));
var UserSystemFunctions = class { var UserSystemFunctions = class {
constructor(app, plugin) { constructor(plugin) {
this.plugin = plugin; this.plugin = plugin;
if (import_obsidian12.Platform.isMobileApp || !(app.vault.adapter instanceof import_obsidian12.FileSystemAdapter)) { if (import_obsidian12.Platform.isMobileApp || !(app.vault.adapter instanceof import_obsidian12.FileSystemAdapter)) {
this.cwd = ""; this.cwd = "";
@ -3091,14 +3096,13 @@ var UserSystemFunctions = class {
// src/core/functions/user_functions/UserScriptFunctions.ts // src/core/functions/user_functions/UserScriptFunctions.ts
var UserScriptFunctions = class { var UserScriptFunctions = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
} }
generate_user_script_functions() { generate_user_script_functions() {
return __async(this, null, function* () { return __async(this, null, function* () {
const user_script_functions = new Map(); const user_script_functions = new Map();
const files = errorWrapperSync(() => get_tfiles_from_folder(this.app, this.plugin.settings.user_scripts_folder), `Couldn't find user script folder "${this.plugin.settings.user_scripts_folder}"`); const files = errorWrapperSync(() => get_tfiles_from_folder(this.plugin.settings.user_scripts_folder), `Couldn't find user script folder "${this.plugin.settings.user_scripts_folder}"`);
if (!files) { if (!files) {
return new Map(); return new Map();
} }
@ -3112,14 +3116,14 @@ var UserScriptFunctions = class {
} }
load_user_script_function(file, user_script_functions) { load_user_script_function(file, user_script_functions) {
return __async(this, null, function* () { return __async(this, null, function* () {
let req = (s) => { const req = (s) => {
return window.require && window.require(s); return window.require && window.require(s);
}; };
let exp = {}; const exp = {};
let mod = { const mod = {
exports: exp exports: exp
}; };
const file_content = yield this.app.vault.read(file); const file_content = yield app.vault.read(file);
const wrapping_fn = window.eval("(function anonymous(require, module, exports){" + file_content + "\n})"); const wrapping_fn = window.eval("(function anonymous(require, module, exports){" + file_content + "\n})");
wrapping_fn(req, mod, exp); wrapping_fn(req, mod, exp);
const user_function = exp["default"] || mod.exports; const user_function = exp["default"] || mod.exports;
@ -3142,10 +3146,10 @@ var UserScriptFunctions = class {
// src/core/functions/user_functions/UserFunctions.ts // src/core/functions/user_functions/UserFunctions.ts
var UserFunctions = class { var UserFunctions = class {
constructor(app, plugin) { constructor(plugin) {
this.plugin = plugin; this.plugin = plugin;
this.user_system_functions = new UserSystemFunctions(app, plugin); this.user_system_functions = new UserSystemFunctions(plugin);
this.user_script_functions = new UserScriptFunctions(app, plugin); this.user_script_functions = new UserScriptFunctions(plugin);
} }
generate_object(config2) { generate_object(config2) {
return __async(this, null, function* () { return __async(this, null, function* () {
@ -3155,7 +3159,7 @@ var UserFunctions = class {
user_system_functions = yield this.user_system_functions.generate_object(config2); user_system_functions = yield this.user_system_functions.generate_object(config2);
} }
if (this.plugin.settings.user_scripts_folder) { if (this.plugin.settings.user_scripts_folder) {
user_script_functions = yield this.user_script_functions.generate_object(config2); user_script_functions = yield this.user_script_functions.generate_object();
} }
return __spreadValues(__spreadValues({}, user_system_functions), user_script_functions); return __spreadValues(__spreadValues({}, user_system_functions), user_script_functions);
}); });
@ -3170,11 +3174,10 @@ var FunctionsMode;
FunctionsMode2[FunctionsMode2["USER_INTERNAL"] = 1] = "USER_INTERNAL"; FunctionsMode2[FunctionsMode2["USER_INTERNAL"] = 1] = "USER_INTERNAL";
})(FunctionsMode || (FunctionsMode = {})); })(FunctionsMode || (FunctionsMode = {}));
var FunctionsGenerator = class { var FunctionsGenerator = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.internal_functions = new InternalFunctions(this.app, this.plugin); this.internal_functions = new InternalFunctions(this.plugin);
this.user_functions = new UserFunctions(this.app, this.plugin); this.user_functions = new UserFunctions(this.plugin);
} }
init() { init() {
return __async(this, null, function* () { return __async(this, null, function* () {
@ -3750,10 +3753,9 @@ var RunMode;
RunMode2[RunMode2["StartupTemplate"] = 5] = "StartupTemplate"; RunMode2[RunMode2["StartupTemplate"] = 5] = "StartupTemplate";
})(RunMode || (RunMode = {})); })(RunMode || (RunMode = {}));
var Templater = class { var Templater = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.functions_generator = new FunctionsGenerator(this.app, this.plugin); this.functions_generator = new FunctionsGenerator(this.plugin);
this.parser = new Parser(); this.parser = new Parser();
} }
setup() { setup() {
@ -3763,7 +3765,7 @@ var Templater = class {
}); });
} }
create_running_config(template_file, target_file, run_mode) { create_running_config(template_file, target_file, run_mode) {
const active_file = this.app.workspace.getActiveFile(); const active_file = app.workspace.getActiveFile();
return { return {
template_file, template_file,
target_file, target_file,
@ -3773,7 +3775,7 @@ var Templater = class {
} }
read_and_parse_template(config2) { read_and_parse_template(config2) {
return __async(this, null, function* () { return __async(this, null, function* () {
const template_content = yield this.app.vault.read(config2.template_file); const template_content = yield app.vault.read(config2.template_file);
return this.parse_template(config2, template_content); return this.parse_template(config2, template_content);
}); });
} }
@ -3788,26 +3790,26 @@ var Templater = class {
create_new_note_from_template(template, folder, filename, open_new_note = true) { create_new_note_from_template(template, folder, filename, open_new_note = true) {
return __async(this, null, function* () { return __async(this, null, function* () {
if (!folder) { if (!folder) {
const new_file_location = this.app.vault.getConfig("newFileLocation"); const new_file_location = app.vault.getConfig("newFileLocation");
switch (new_file_location) { switch (new_file_location) {
case "current": { case "current": {
const active_file = this.app.workspace.getActiveFile(); const active_file = app.workspace.getActiveFile();
if (active_file) { if (active_file) {
folder = active_file.parent; folder = active_file.parent;
} }
break; break;
} }
case "folder": case "folder":
folder = this.app.fileManager.getNewFileParent(""); folder = app.fileManager.getNewFileParent("");
break; break;
case "root": case "root":
folder = this.app.vault.getRoot(); folder = app.vault.getRoot();
break; break;
default: default:
break; break;
} }
} }
const created_note = yield this.app.fileManager.createNewMarkdownFile(folder, filename != null ? filename : "Untitled"); const created_note = yield app.fileManager.createNewMarkdownFile(folder, filename != null ? filename : "Untitled");
let running_config; let running_config;
let output_content; let output_content;
if (template instanceof import_obsidian13.TFile) { if (template instanceof import_obsidian13.TFile) {
@ -3822,16 +3824,16 @@ var Templater = class {
}), "Template parsing error, aborting."); }), "Template parsing error, aborting.");
} }
if (output_content == null) { if (output_content == null) {
yield this.app.vault.delete(created_note); yield app.vault.delete(created_note);
return; return;
} }
yield this.app.vault.modify(created_note, output_content); yield app.vault.modify(created_note, output_content);
this.app.workspace.trigger("templater:new-note-from-template", { app.workspace.trigger("templater:new-note-from-template", {
file: created_note, file: created_note,
content: output_content content: output_content
}); });
if (open_new_note) { if (open_new_note) {
const active_leaf = this.app.workspace.getLeaf(false); const active_leaf = app.workspace.getLeaf(false);
if (!active_leaf) { if (!active_leaf) {
log_error(new TemplaterError("No active leaf")); log_error(new TemplaterError("No active leaf"));
return; return;
@ -3849,7 +3851,7 @@ var Templater = class {
} }
append_template_to_active_file(template_file) { append_template_to_active_file(template_file) {
return __async(this, null, function* () { return __async(this, null, function* () {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian13.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian13.MarkdownView);
if (active_view === null) { if (active_view === null) {
log_error(new TemplaterError("No active view, can't append templates.")); log_error(new TemplaterError("No active view, can't append templates."));
return; return;
@ -3865,7 +3867,7 @@ var Templater = class {
const doc = editor.getDoc(); const doc = editor.getDoc();
const oldSelections = doc.listSelections(); const oldSelections = doc.listSelections();
doc.replaceSelection(output_content); doc.replaceSelection(output_content);
this.app.workspace.trigger("templater:template-appended", { app.workspace.trigger("templater:template-appended", {
view: active_view, view: active_view,
content: output_content, content: output_content,
oldSelections, oldSelections,
@ -3883,8 +3885,8 @@ var Templater = class {
if (output_content == null) { if (output_content == null) {
return; return;
} }
yield this.app.vault.modify(file, output_content); yield app.vault.modify(file, output_content);
this.app.workspace.trigger("templater:new-note-from-template", { app.workspace.trigger("templater:new-note-from-template", {
file, file,
content: output_content content: output_content
}); });
@ -3892,7 +3894,7 @@ var Templater = class {
}); });
} }
overwrite_active_file_commands() { overwrite_active_file_commands() {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian13.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian13.MarkdownView);
if (active_view === null) { if (active_view === null) {
log_error(new TemplaterError("Active view is null, can't overwrite content")); log_error(new TemplaterError("Active view is null, can't overwrite content"));
return; return;
@ -3908,8 +3910,8 @@ var Templater = class {
if (output_content == null) { if (output_content == null) {
return; return;
} }
yield this.app.vault.modify(file, output_content); yield app.vault.modify(file, output_content);
this.app.workspace.trigger("templater:overwrite-file", { app.workspace.trigger("templater:overwrite-file", {
file, file,
content: output_content content: output_content
}); });
@ -3925,9 +3927,10 @@ var Templater = class {
let functions_object; let functions_object;
while (node = walker.nextNode()) { while (node = walker.nextNode()) {
let content = node.nodeValue; let content = node.nodeValue;
let match; if (content !== null) {
if ((match = dynamic_command_regex.exec(content)) != null) { let match = dynamic_command_regex.exec(content);
const file = this.app.metadataCache.getFirstLinkpathDest("", ctx.sourcePath); if (match !== null) {
const file = app.metadataCache.getFirstLinkpathDest("", ctx.sourcePath);
if (!file || !(file instanceof import_obsidian13.TFile)) { if (!file || !(file instanceof import_obsidian13.TFile)) {
return; return;
} }
@ -3937,6 +3940,7 @@ var Templater = class {
functions_object = yield this.functions_generator.generate_object(config2, FunctionsMode.USER_INTERNAL); functions_object = yield this.functions_generator.generate_object(config2, FunctionsMode.USER_INTERNAL);
this.current_functions_object = functions_object; this.current_functions_object = functions_object;
} }
}
while (match != null) { while (match != null) {
const complete_command = match[1] + match[2]; const complete_command = match[1] + match[2];
const command_output = yield errorWrapper(() => __async(this, null, function* () { const command_output = yield errorWrapper(() => __async(this, null, function* () {
@ -3974,22 +3978,39 @@ var Templater = class {
if (file.path.includes(template_folder) && template_folder !== "/") { if (file.path.includes(template_folder) && template_folder !== "/") {
return; return;
} }
yield new Promise((resolve2) => {
let timeout;
const file_open_ref = app.workspace.on("file-open", (opened_file) => __async(this, null, function* () {
if (opened_file !== file) {
return;
}
window.clearTimeout(timeout);
app.workspace.offref(file_open_ref);
yield delay(300); yield delay(300);
if (file.stat.size == 0 && templater.plugin.settings.enable_folder_templates) { if (file.stat.size == 0 && templater.plugin.settings.enable_folder_templates) {
const folder_template_match = templater.get_new_file_template_for_folder(file.parent); const folder_template_match = templater.get_new_file_template_for_folder(file.parent);
if (!folder_template_match) { if (!folder_template_match) {
resolve2();
return; return;
} }
const template_file = yield errorWrapper(() => __async(this, null, function* () { const template_file = yield errorWrapper(() => __async(this, null, function* () {
return resolve_tfile(templater.app, folder_template_match); return resolve_tfile(folder_template_match);
}), `Couldn't find template ${folder_template_match}`); }), `Couldn't find template ${folder_template_match}`);
if (template_file == null) { if (template_file == null) {
resolve2();
return; return;
} }
yield templater.write_template_to_file(template_file, file); yield templater.write_template_to_file(template_file, file);
} else { } else {
yield templater.overwrite_file_commands(file); yield templater.overwrite_file_commands(file);
} }
resolve2();
}));
timeout = window.setTimeout(() => {
app.workspace.offref(file_open_ref);
resolve2();
}, 300);
});
}); });
} }
execute_startup_scripts() { execute_startup_scripts() {
@ -3998,7 +4019,7 @@ var Templater = class {
if (!template) { if (!template) {
continue; continue;
} }
const file = errorWrapperSync(() => resolve_tfile(this.app, template), `Couldn't find startup template "${template}"`); const file = errorWrapperSync(() => resolve_tfile(template), `Couldn't find startup template "${template}"`);
if (!file) { if (!file) {
continue; continue;
} }
@ -4014,14 +4035,13 @@ var Templater = class {
// src/handlers/EventHandler.ts // src/handlers/EventHandler.ts
var import_obsidian14 = __toModule(require("obsidian")); var import_obsidian14 = __toModule(require("obsidian"));
var EventHandler = class { var EventHandler = class {
constructor(app, plugin, templater, settings) { constructor(plugin, templater, settings) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.templater = templater; this.templater = templater;
this.settings = settings; this.settings = settings;
} }
setup() { setup() {
this.app.workspace.onLayoutReady(() => { app.workspace.onLayoutReady(() => {
this.update_trigger_file_on_creation(); this.update_trigger_file_on_creation();
}); });
this.update_syntax_highlighting(); this.update_syntax_highlighting();
@ -4029,35 +4049,35 @@ var EventHandler = class {
} }
update_syntax_highlighting() { update_syntax_highlighting() {
if (this.plugin.settings.syntax_highlighting) { if (this.plugin.settings.syntax_highlighting) {
this.syntax_highlighting_event = this.app.workspace.on("codemirror", (cm) => { this.syntax_highlighting_event = app.workspace.on("codemirror", (cm) => {
cm.setOption("mode", "templater"); cm.setOption("mode", "templater");
}); });
this.app.workspace.iterateCodeMirrors((cm) => { app.workspace.iterateCodeMirrors((cm) => {
cm.setOption("mode", "templater"); cm.setOption("mode", "templater");
}); });
this.plugin.registerEvent(this.syntax_highlighting_event); this.plugin.registerEvent(this.syntax_highlighting_event);
} else { } else {
if (this.syntax_highlighting_event) { if (this.syntax_highlighting_event) {
this.app.vault.offref(this.syntax_highlighting_event); app.vault.offref(this.syntax_highlighting_event);
} }
this.app.workspace.iterateCodeMirrors((cm) => { app.workspace.iterateCodeMirrors((cm) => {
cm.setOption("mode", "hypermd"); cm.setOption("mode", "hypermd");
}); });
} }
} }
update_trigger_file_on_creation() { update_trigger_file_on_creation() {
if (this.settings.trigger_on_file_creation) { if (this.settings.trigger_on_file_creation) {
this.trigger_on_file_creation_event = this.app.vault.on("create", (file) => Templater.on_file_creation(this.templater, file)); this.trigger_on_file_creation_event = app.vault.on("create", (file) => Templater.on_file_creation(this.templater, file));
this.plugin.registerEvent(this.trigger_on_file_creation_event); this.plugin.registerEvent(this.trigger_on_file_creation_event);
} else { } else {
if (this.trigger_on_file_creation_event) { if (this.trigger_on_file_creation_event) {
this.app.vault.offref(this.trigger_on_file_creation_event); app.vault.offref(this.trigger_on_file_creation_event);
this.trigger_on_file_creation_event = void 0; this.trigger_on_file_creation_event = void 0;
} }
} }
} }
update_file_menu() { update_file_menu() {
this.plugin.registerEvent(this.app.workspace.on("file-menu", (menu, file) => { this.plugin.registerEvent(app.workspace.on("file-menu", (menu, file) => {
if (file instanceof import_obsidian14.TFolder) { if (file instanceof import_obsidian14.TFolder) {
menu.addItem((item) => { menu.addItem((item) => {
item.setTitle("Create new note from template").setIcon("templater-icon").onClick(() => { item.setTitle("Create new note from template").setIcon("templater-icon").onClick(() => {
@ -4071,8 +4091,7 @@ var EventHandler = class {
// src/handlers/CommandHandler.ts // src/handlers/CommandHandler.ts
var CommandHandler = class { var CommandHandler = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
} }
setup() { setup() {
@ -4144,7 +4163,7 @@ var CommandHandler = class {
id: new_template, id: new_template,
name: `Insert ${new_template}`, name: `Insert ${new_template}`,
callback: () => { callback: () => {
const template = errorWrapperSync(() => resolve_tfile(this.app, new_template), `Couldn't find the template file associated with this hotkey`); const template = errorWrapperSync(() => resolve_tfile(new_template), `Couldn't find the template file associated with this hotkey`);
if (!template) { if (!template) {
return; return;
} }
@ -4155,7 +4174,7 @@ var CommandHandler = class {
} }
remove_template_hotkey(template) { remove_template_hotkey(template) {
if (template) { if (template) {
this.app.commands.removeCommand(`${this.plugin.manifest.id}:${template}`); app.commands.removeCommand(`${this.plugin.manifest.id}:${template}`);
} }
} }
}; };
@ -4166,21 +4185,20 @@ var import_obsidian17 = __toModule(require("obsidian"));
// src/editor/CursorJumper.ts // src/editor/CursorJumper.ts
var import_obsidian15 = __toModule(require("obsidian")); var import_obsidian15 = __toModule(require("obsidian"));
var CursorJumper = class { var CursorJumper = class {
constructor(app) { constructor() {
this.app = app;
} }
jump_to_next_cursor_location() { jump_to_next_cursor_location() {
return __async(this, null, function* () { return __async(this, null, function* () {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian15.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian15.MarkdownView);
if (!active_view) { if (!active_view) {
return; return;
} }
const active_file = active_view.file; const active_file = active_view.file;
yield active_view.save(); yield active_view.save();
const content = yield this.app.vault.read(active_file); const content = yield app.vault.read(active_file);
const { new_content, positions } = this.replace_and_get_cursor_positions(content); const { new_content, positions } = this.replace_and_get_cursor_positions(content);
if (positions) { if (positions) {
yield this.app.vault.modify(active_file, new_content); yield app.vault.modify(active_file, new_content);
this.set_cursor_location(positions); this.set_cursor_location(positions);
} }
}); });
@ -4207,7 +4225,7 @@ var CursorJumper = class {
return {}; return {};
} }
cursor_matches.sort((m1, m2) => { cursor_matches.sort((m1, m2) => {
return Number(m1.groups["order"]) - Number(m2.groups["order"]); return Number(m1.groups && m1.groups["order"]) - Number(m2.groups && m2.groups["order"]);
}); });
const match_str = cursor_matches[0][0]; const match_str = cursor_matches[0][0];
cursor_matches = cursor_matches.filter((m) => { cursor_matches = cursor_matches.filter((m) => {
@ -4227,7 +4245,7 @@ var CursorJumper = class {
return { new_content: content, positions }; return { new_content: content, positions };
} }
set_cursor_location(positions) { set_cursor_location(positions) {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian15.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian15.MarkdownView);
if (!active_view) { if (!active_view) {
return; return;
} }
@ -4251,7 +4269,16 @@ var tp = { config: { name: "config", description: "This module exposes Templater
var documentation_default = { tp }; var documentation_default = { tp };
// src/editor/TpDocumentation.ts // src/editor/TpDocumentation.ts
var module_names = ["config", "date", "file", "frontmatter", "obsidian", "system", "user", "web"]; var module_names = [
"config",
"date",
"file",
"frontmatter",
"obsidian",
"system",
"user",
"web"
];
var module_names_checker = new Set(module_names); var module_names_checker = new Set(module_names);
function is_module_name(x) { function is_module_name(x) {
return typeof x === "string" && module_names_checker.has(x); return typeof x === "string" && module_names_checker.has(x);
@ -4263,8 +4290,7 @@ function is_function_documentation(x) {
return false; return false;
} }
var Documentation = class { var Documentation = class {
constructor(app) { constructor() {
this.app = app;
this.documentation = documentation_default; this.documentation = documentation_default;
} }
get_all_modules_documentation() { get_all_modules_documentation() {
@ -4272,7 +4298,7 @@ var Documentation = class {
} }
get_all_functions_documentation(module_name) { get_all_functions_documentation(module_name) {
if (!this.documentation.tp[module_name].functions) { if (!this.documentation.tp[module_name].functions) {
return null; return;
} }
return Object.values(this.documentation.tp[module_name].functions); return Object.values(this.documentation.tp[module_name].functions);
} }
@ -4293,25 +4319,23 @@ var Documentation = class {
// src/editor/Autocomplete.ts // src/editor/Autocomplete.ts
var Autocomplete = class extends import_obsidian16.EditorSuggest { var Autocomplete = class extends import_obsidian16.EditorSuggest {
constructor(app, plugin) { constructor() {
super(app); super(app);
this.app = app;
this.plugin = plugin;
this.tp_keyword_regex = /tp\.(?<module>[a-z]*)?(?<fn_trigger>\.(?<fn>[a-z_]*)?)?$/; this.tp_keyword_regex = /tp\.(?<module>[a-z]*)?(?<fn_trigger>\.(?<fn>[a-z_]*)?)?$/;
this.documentation = new Documentation(this.app); this.documentation = new Documentation();
} }
onTrigger(cursor, editor, file) { onTrigger(cursor, editor, _file) {
const range = editor.getRange({ line: cursor.line, ch: 0 }, { line: cursor.line, ch: cursor.ch }); const range = editor.getRange({ line: cursor.line, ch: 0 }, { line: cursor.line, ch: cursor.ch });
const match = this.tp_keyword_regex.exec(range); const match = this.tp_keyword_regex.exec(range);
if (!match) { if (!match) {
return null; return null;
} }
let query; let query;
const module_name = match.groups["module"] || ""; const module_name = match.groups && match.groups["module"] || "";
this.module_name = module_name; this.module_name = module_name;
if (match.groups["fn_trigger"]) { if (match.groups && match.groups["fn_trigger"]) {
if (module_name == "" || !is_module_name(module_name)) { if (module_name == "" || !is_module_name(module_name)) {
return; return null;
} }
this.function_trigger = true; this.function_trigger = true;
this.function_name = match.groups["fn"] || ""; this.function_name = match.groups["fn"] || "";
@ -4350,8 +4374,8 @@ var Autocomplete = class extends import_obsidian16.EditorSuggest {
el.createEl("div", { text: value.description }); el.createEl("div", { text: value.description });
} }
} }
selectSuggestion(value, evt) { selectSuggestion(value, _evt) {
const active_view = this.app.workspace.getActiveViewOfType(import_obsidian16.MarkdownView); const active_view = app.workspace.getActiveViewOfType(import_obsidian16.MarkdownView);
if (!active_view) { if (!active_view) {
return; return;
} }
@ -5641,15 +5665,14 @@ var TP_INTERPOLATION_TAG_TOKEN_CLASS = "templater-interpolation-tag";
var TP_RAW_TAG_TOKEN_CLASS = "templater-raw-tag"; var TP_RAW_TAG_TOKEN_CLASS = "templater-raw-tag";
var TP_EXEC_TAG_TOKEN_CLASS = "templater-execution-tag"; var TP_EXEC_TAG_TOKEN_CLASS = "templater-execution-tag";
var Editor2 = class { var Editor2 = class {
constructor(app, plugin) { constructor(plugin) {
this.app = app;
this.plugin = plugin; this.plugin = plugin;
this.cursor_jumper = new CursorJumper(this.app); this.cursor_jumper = new CursorJumper();
} }
setup() { setup() {
return __async(this, null, function* () { return __async(this, null, function* () {
yield this.registerCodeMirrorMode(); yield this.registerCodeMirrorMode();
this.plugin.registerEditorSuggest(new Autocomplete(this.app, this.plugin)); this.plugin.registerEditorSuggest(new Autocomplete(app));
}); });
} }
jump_to_next_cursor_location(file = null, auto_jump = false) { jump_to_next_cursor_location(file = null, auto_jump = false) {
@ -5657,7 +5680,7 @@ var Editor2 = class {
if (auto_jump && !this.plugin.settings.auto_jump_to_cursor) { if (auto_jump && !this.plugin.settings.auto_jump_to_cursor) {
return; return;
} }
if (file && this.app.workspace.getActiveFile() !== file) { if (file && app.workspace.getActiveFile() !== file) {
return; return;
} }
yield this.cursor_jumper.jump_to_next_cursor_location(); yield this.cursor_jumper.jump_to_next_cursor_location();
@ -5719,7 +5742,7 @@ var Editor2 = class {
state.tag_class = ""; state.tag_class = "";
return `line-${TP_INLINE_CLASS} ${TP_CMD_TOKEN_CLASS} ${TP_CLOSING_TAG_TOKEN_CLASS} ${tag_class}`; return `line-${TP_INLINE_CLASS} ${TP_CMD_TOKEN_CLASS} ${TP_CLOSING_TAG_TOKEN_CLASS} ${tag_class}`;
} }
const js_result = js_mode.token(stream, state); const js_result = js_mode.token && js_mode.token(stream, state);
if (stream.peek() == null && state.freeLine) { if (stream.peek() == null && state.freeLine) {
keywords += ` line-background-templater-command-bg`; keywords += ` line-background-templater-command-bg`;
} }
@ -5760,14 +5783,14 @@ var TemplaterPlugin = class extends import_obsidian18.Plugin {
onload() { onload() {
return __async(this, null, function* () { return __async(this, null, function* () {
yield this.load_settings(); yield this.load_settings();
this.templater = new Templater(this.app, this); this.templater = new Templater(this);
yield this.templater.setup(); yield this.templater.setup();
this.editor_handler = new Editor2(this.app, this); this.editor_handler = new Editor2(this);
yield this.editor_handler.setup(); yield this.editor_handler.setup();
this.fuzzy_suggester = new FuzzySuggester(this.app, this); this.fuzzy_suggester = new FuzzySuggester(this);
this.event_handler = new EventHandler(this.app, this, this.templater, this.settings); this.event_handler = new EventHandler(this, this.templater, this.settings);
this.event_handler.setup(); this.event_handler.setup();
this.command_handler = new CommandHandler(this.app, this); this.command_handler = new CommandHandler(this);
this.command_handler.setup(); this.command_handler.setup();
(0, import_obsidian18.addIcon)("templater-icon", ICON_DATA); (0, import_obsidian18.addIcon)("templater-icon", ICON_DATA);
if (this.settings.enable_ribbon_icon) { if (this.settings.enable_ribbon_icon) {
@ -5775,8 +5798,8 @@ var TemplaterPlugin = class extends import_obsidian18.Plugin {
this.fuzzy_suggester.insert_template(); this.fuzzy_suggester.insert_template();
})).setAttribute("id", "rb-templater-icon"); })).setAttribute("id", "rb-templater-icon");
} }
this.addSettingTab(new TemplaterSettingTab(this.app, this)); this.addSettingTab(new TemplaterSettingTab(this));
this.app.workspace.onLayoutReady(() => { app.workspace.onLayoutReady(() => {
this.templater.execute_startup_scripts(); this.templater.execute_startup_scripts();
}); });
}); });

View file

@ -1,7 +1,7 @@
{ {
"id": "templater-obsidian", "id": "templater-obsidian",
"name": "Templater", "name": "Templater",
"version": "1.14.1", "version": "1.14.2",
"description": "Create and use templates", "description": "Create and use templates",
"minAppVersion": "0.11.13", "minAppVersion": "0.11.13",
"author": "SilentVoid", "author": "SilentVoid",