@real1ty-obsidian-plugins/utils 2.2.3 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -9
- package/dist/{async-utils.d.ts → async/async.d.ts} +1 -1
- package/dist/async/async.d.ts.map +1 -0
- package/dist/{async-utils.js → async/async.js} +1 -1
- package/dist/async/async.js.map +1 -0
- package/dist/async/batch-operations.d.ts.map +1 -0
- package/dist/async/batch-operations.js.map +1 -0
- package/dist/async/index.d.ts +3 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +3 -0
- package/dist/async/index.js.map +1 -0
- package/dist/core/evaluator-base.d.ts.map +1 -0
- package/dist/core/evaluator-base.js.map +1 -0
- package/dist/core/generate.d.ts.map +1 -0
- package/dist/core/generate.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/{date-recurrence-utils.d.ts → date/date-recurrence.d.ts} +1 -1
- package/dist/date/date-recurrence.d.ts.map +1 -0
- package/dist/{date-recurrence-utils.js → date/date-recurrence.js} +1 -1
- package/dist/date/date-recurrence.js.map +1 -0
- package/dist/{date-utils.d.ts → date/date.d.ts} +1 -1
- package/dist/date/date.d.ts.map +1 -0
- package/dist/{date-utils.js → date/date.js} +1 -1
- package/dist/date/date.js.map +1 -0
- package/dist/date/index.d.ts +3 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/index.js +3 -0
- package/dist/date/index.js.map +1 -0
- package/dist/{child-reference-utils.d.ts → file/child-reference.d.ts} +1 -1
- package/dist/file/child-reference.d.ts.map +1 -0
- package/dist/{child-reference-utils.js → file/child-reference.js} +1 -1
- package/dist/file/child-reference.js.map +1 -0
- package/dist/file/file-operations.d.ts.map +1 -0
- package/dist/{file-operations.js → file/file-operations.js} +2 -2
- package/dist/file/file-operations.js.map +1 -0
- package/dist/file/file.d.ts +263 -0
- package/dist/file/file.d.ts.map +1 -0
- package/dist/file/file.js +466 -0
- package/dist/file/file.js.map +1 -0
- package/dist/{frontmatter-utils.d.ts → file/frontmatter.d.ts} +1 -1
- package/dist/file/frontmatter.d.ts.map +1 -0
- package/dist/{frontmatter-utils.js → file/frontmatter.js} +1 -1
- package/dist/file/frontmatter.js.map +1 -0
- package/dist/file/index.d.ts +7 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +7 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/link-parser.d.ts.map +1 -0
- package/dist/file/link-parser.js.map +1 -0
- package/dist/{templater-utils.d.ts → file/templater.d.ts} +1 -1
- package/dist/file/templater.d.ts.map +1 -0
- package/dist/{templater-utils.js → file/templater.js} +1 -1
- package/dist/file/templater.js.map +1 -0
- package/dist/index.d.ts +6 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -15
- package/dist/index.js.map +1 -1
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +3 -0
- package/dist/settings/index.js.map +1 -0
- package/dist/settings/settings-store.d.ts.map +1 -0
- package/dist/settings/settings-store.js.map +1 -0
- package/dist/settings/settings-ui-builder.d.ts.map +1 -0
- package/dist/settings/settings-ui-builder.js.map +1 -0
- package/dist/string/index.d.ts +2 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/index.js +2 -0
- package/dist/string/index.js.map +1 -0
- package/dist/{string-utils.d.ts → string/string.d.ts} +1 -1
- package/dist/string/string.d.ts.map +1 -0
- package/dist/{string-utils.js → string/string.js} +1 -1
- package/dist/string/string.js.map +1 -0
- package/dist/testing/mocks/obsidian.d.ts +1 -0
- package/dist/testing/mocks/obsidian.d.ts.map +1 -1
- package/dist/testing/mocks/obsidian.js +6 -0
- package/dist/testing/mocks/obsidian.js.map +1 -1
- package/package.json +3 -5
- package/src/async/async.ts +117 -0
- package/src/async/batch-operations.ts +53 -0
- package/src/async/index.ts +2 -0
- package/src/core/evaluator-base.ts +118 -0
- package/src/core/generate.ts +22 -0
- package/src/core/index.ts +2 -0
- package/src/date/date-recurrence.ts +244 -0
- package/src/date/date.ts +111 -0
- package/src/date/index.ts +2 -0
- package/src/file/child-reference.ts +76 -0
- package/src/file/file-operations.ts +197 -0
- package/src/file/file.ts +570 -0
- package/src/file/frontmatter.ts +80 -0
- package/src/file/index.ts +6 -0
- package/src/file/link-parser.ts +18 -0
- package/src/file/templater.ts +75 -0
- package/src/index.ts +14 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/settings-store.ts +88 -0
- package/src/settings/settings-ui-builder.ts +507 -0
- package/src/string/index.ts +1 -0
- package/src/string/string.ts +26 -0
- package/src/testing/index.ts +23 -0
- package/src/testing/mocks/obsidian.ts +331 -0
- package/src/testing/mocks/utils.ts +113 -0
- package/src/testing/setup.ts +19 -0
- package/dist/async-utils.d.ts.map +0 -1
- package/dist/async-utils.js.map +0 -1
- package/dist/batch-operations.d.ts.map +0 -1
- package/dist/batch-operations.js.map +0 -1
- package/dist/child-reference-utils.d.ts.map +0 -1
- package/dist/child-reference-utils.js.map +0 -1
- package/dist/date-recurrence-utils.d.ts.map +0 -1
- package/dist/date-recurrence-utils.js.map +0 -1
- package/dist/date-utils.d.ts.map +0 -1
- package/dist/date-utils.js.map +0 -1
- package/dist/evaluator-base.d.ts.map +0 -1
- package/dist/evaluator-base.js.map +0 -1
- package/dist/file-operations.d.ts.map +0 -1
- package/dist/file-operations.js.map +0 -1
- package/dist/file-utils.d.ts +0 -6
- package/dist/file-utils.d.ts.map +0 -1
- package/dist/file-utils.js +0 -25
- package/dist/file-utils.js.map +0 -1
- package/dist/frontmatter-utils.d.ts.map +0 -1
- package/dist/frontmatter-utils.js.map +0 -1
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js.map +0 -1
- package/dist/link-parser.d.ts.map +0 -1
- package/dist/link-parser.js.map +0 -1
- package/dist/settings-store.d.ts.map +0 -1
- package/dist/settings-store.js.map +0 -1
- package/dist/settings-ui-builder.d.ts.map +0 -1
- package/dist/settings-ui-builder.js.map +0 -1
- package/dist/string-utils.d.ts.map +0 -1
- package/dist/string-utils.js.map +0 -1
- package/dist/templater-utils.d.ts.map +0 -1
- package/dist/templater-utils.js.map +0 -1
- /package/dist/{batch-operations.d.ts → async/batch-operations.d.ts} +0 -0
- /package/dist/{batch-operations.js → async/batch-operations.js} +0 -0
- /package/dist/{evaluator-base.d.ts → core/evaluator-base.d.ts} +0 -0
- /package/dist/{evaluator-base.js → core/evaluator-base.js} +0 -0
- /package/dist/{generate.d.ts → core/generate.d.ts} +0 -0
- /package/dist/{generate.js → core/generate.js} +0 -0
- /package/dist/{file-operations.d.ts → file/file-operations.d.ts} +0 -0
- /package/dist/{link-parser.d.ts → file/link-parser.d.ts} +0 -0
- /package/dist/{link-parser.js → file/link-parser.js} +0 -0
- /package/dist/{settings-store.d.ts → settings/settings-store.d.ts} +0 -0
- /package/dist/{settings-store.js → settings/settings-store.js} +0 -0
- /package/dist/{settings-ui-builder.d.ts → settings/settings-ui-builder.d.ts} +0 -0
- /package/dist/{settings-ui-builder.js → settings/settings-ui-builder.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/file/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAMhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CActE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,G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EAAE,MAAM,GAAG,MAAM,CAQtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAQtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAU7E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAe3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAoDxE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5E;AAMD,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,MAOnD,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,MAEtD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,OAGjF,CAAC"}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { normalizePath, TFile } from "obsidian";
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// File Path Operations
|
|
5
|
+
// ============================================================================
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a TFile object from the vault by its path.
|
|
8
|
+
* Handles path normalization using Obsidian's normalizePath utility.
|
|
9
|
+
*
|
|
10
|
+
* **Important**: Obsidian file paths ALWAYS include the `.md` extension.
|
|
11
|
+
* The TFile.path property returns paths like "folder/file.md", not "folder/file".
|
|
12
|
+
*
|
|
13
|
+
* @param app - The Obsidian App instance
|
|
14
|
+
* @param filePath - Path to the file (will be normalized, should include .md extension)
|
|
15
|
+
* @returns TFile if found, null otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Correct: Include .md extension
|
|
20
|
+
* const file = getFileByPath(app, "folder/note.md");
|
|
21
|
+
*
|
|
22
|
+
* // For wikilinks without extension, add .md
|
|
23
|
+
* const linkPath = "MyNote";
|
|
24
|
+
* const file = getFileByPath(app, `${linkPath}.md`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function getFileByPath(app, filePath) {
|
|
28
|
+
// Normalize the path using Obsidian's utility
|
|
29
|
+
// This handles slashes, spaces, and platform-specific path issues
|
|
30
|
+
const normalizedPath = normalizePath(filePath);
|
|
31
|
+
// Use Vault's direct lookup method (most efficient)
|
|
32
|
+
// Prefer getFileByPath if available, otherwise use getAbstractFileByPath
|
|
33
|
+
if (typeof app.vault.getFileByPath === "function") {
|
|
34
|
+
return app.vault.getFileByPath(normalizedPath);
|
|
35
|
+
}
|
|
36
|
+
const abstractFile = app.vault.getAbstractFileByPath(normalizedPath);
|
|
37
|
+
return abstractFile instanceof TFile ? abstractFile : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Ensures a file path includes the .md extension.
|
|
41
|
+
* Use this when working with wikilinks or user input that may omit extensions.
|
|
42
|
+
*
|
|
43
|
+
* @param path - File path that may or may not include .md extension
|
|
44
|
+
* @returns Path guaranteed to end with .md
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* ensureMarkdownExtension("MyNote") // "MyNote.md"
|
|
49
|
+
* ensureMarkdownExtension("MyNote.md") // "MyNote.md"
|
|
50
|
+
* ensureMarkdownExtension("folder/note") // "folder/note.md"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function ensureMarkdownExtension(path) {
|
|
54
|
+
return path.endsWith(".md") ? path : `${path}.md`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Removes the .md extension from a file path if present.
|
|
58
|
+
* Useful for displaying file names or creating wikilinks.
|
|
59
|
+
*
|
|
60
|
+
* @param path - File path that may include .md extension
|
|
61
|
+
* @returns Path without .md extension
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* removeMarkdownExtension("folder/note.md") // "folder/note"
|
|
66
|
+
* removeMarkdownExtension("folder/note") // "folder/note"
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function removeMarkdownExtension(path) {
|
|
70
|
+
return path.endsWith(".md") ? path.slice(0, -3) : path;
|
|
71
|
+
}
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// File Name Extraction
|
|
74
|
+
// ============================================================================
|
|
75
|
+
/**
|
|
76
|
+
* Extracts the display name from a file path or wiki link.
|
|
77
|
+
*
|
|
78
|
+
* Handles various formats:
|
|
79
|
+
* - `[[path/to/file|Alias]]` -> returns "Alias"
|
|
80
|
+
* - `[[path/to/file]]` -> returns "file"
|
|
81
|
+
* - `path/to/file.md` -> returns "file"
|
|
82
|
+
* - `file.md` -> returns "file"
|
|
83
|
+
*
|
|
84
|
+
* @param input - File path or wiki link string
|
|
85
|
+
* @returns The display name to show in the UI
|
|
86
|
+
*/
|
|
87
|
+
export function extractDisplayName(input) {
|
|
88
|
+
if (!input)
|
|
89
|
+
return "";
|
|
90
|
+
// Remove any surrounding whitespace
|
|
91
|
+
const trimmed = input.trim();
|
|
92
|
+
// Check if it's a wiki link format [[path|alias]] or [[path]]
|
|
93
|
+
const wikiLinkMatch = trimmed.match(/^\[\[([^\]]+)\]\]$/);
|
|
94
|
+
if (wikiLinkMatch) {
|
|
95
|
+
const innerContent = wikiLinkMatch[1];
|
|
96
|
+
// Check if there's an alias (pipe character)
|
|
97
|
+
const pipeIndex = innerContent.indexOf("|");
|
|
98
|
+
if (pipeIndex !== -1) {
|
|
99
|
+
// Return the alias (everything after the pipe)
|
|
100
|
+
return innerContent.substring(pipeIndex + 1).trim();
|
|
101
|
+
}
|
|
102
|
+
// No alias, extract filename from path
|
|
103
|
+
const path = innerContent.trim();
|
|
104
|
+
const lastSlashIndex = path.lastIndexOf("/");
|
|
105
|
+
const filename = lastSlashIndex !== -1 ? path.substring(lastSlashIndex + 1) : path;
|
|
106
|
+
return filename.replace(/\.md$/i, "");
|
|
107
|
+
}
|
|
108
|
+
// Not a wiki link, treat as regular path
|
|
109
|
+
const lastSlashIndex = trimmed.lastIndexOf("/");
|
|
110
|
+
const filename = lastSlashIndex !== -1 ? trimmed.substring(lastSlashIndex + 1) : trimmed;
|
|
111
|
+
return filename.replace(/\.md$/i, "");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Extracts the actual file path from a wiki link or returns the path as-is.
|
|
115
|
+
*
|
|
116
|
+
* Handles:
|
|
117
|
+
* - `[[path/to/file|Alias]]` -> returns "path/to/file.md"
|
|
118
|
+
* - `[[path/to/file]]` -> returns "path/to/file.md"
|
|
119
|
+
* - `path/to/file.md` -> returns "path/to/file.md"
|
|
120
|
+
*
|
|
121
|
+
* @param input - File path or wiki link string
|
|
122
|
+
* @returns The actual file path (with .md extension)
|
|
123
|
+
*/
|
|
124
|
+
export function extractFilePath(input) {
|
|
125
|
+
if (!input)
|
|
126
|
+
return "";
|
|
127
|
+
const trimmed = input.trim();
|
|
128
|
+
// Check if it's a wiki link format [[path|alias]] or [[path]]
|
|
129
|
+
const wikiLinkMatch = trimmed.match(/^\[\[([^\]]+)\]\]$/);
|
|
130
|
+
if (wikiLinkMatch) {
|
|
131
|
+
const innerContent = wikiLinkMatch[1];
|
|
132
|
+
// Check if there's an alias (pipe character)
|
|
133
|
+
const pipeIndex = innerContent.indexOf("|");
|
|
134
|
+
const path = pipeIndex !== -1 ? innerContent.substring(0, pipeIndex).trim() : innerContent.trim();
|
|
135
|
+
// Ensure .md extension
|
|
136
|
+
return path.endsWith(".md") ? path : `${path}.md`;
|
|
137
|
+
}
|
|
138
|
+
// Not a wiki link, ensure .md extension
|
|
139
|
+
return trimmed.endsWith(".md") ? trimmed : `${trimmed}.md`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a comprehensive file context object containing all relevant file information.
|
|
143
|
+
* Handles path normalization, file lookup, and metadata caching.
|
|
144
|
+
*/
|
|
145
|
+
export function getFileContext(app, path) {
|
|
146
|
+
const pathWithExt = ensureMarkdownExtension(path);
|
|
147
|
+
const baseName = removeMarkdownExtension(path);
|
|
148
|
+
const file = getFileByPath(app, pathWithExt);
|
|
149
|
+
const cache = file ? app.metadataCache.getFileCache(file) : null;
|
|
150
|
+
const frontmatter = cache === null || cache === void 0 ? void 0 : cache.frontmatter;
|
|
151
|
+
return {
|
|
152
|
+
path,
|
|
153
|
+
pathWithExt,
|
|
154
|
+
baseName,
|
|
155
|
+
file,
|
|
156
|
+
frontmatter,
|
|
157
|
+
cache,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Helper function to work with file context that automatically handles file not found cases.
|
|
162
|
+
* Returns null if the file doesn't exist, otherwise executes the callback with the context.
|
|
163
|
+
*/
|
|
164
|
+
export function withFileContext(app, path, callback) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const context = getFileContext(app, path);
|
|
167
|
+
if (!context.file) {
|
|
168
|
+
console.warn(`File not found: ${context.pathWithExt}`);
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return yield callback(context);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
// ============================================================================
|
|
175
|
+
// File Path Generation
|
|
176
|
+
// ============================================================================
|
|
177
|
+
/**
|
|
178
|
+
* Generates a unique file path by appending a counter if the file already exists.
|
|
179
|
+
* Automatically adds .md extension if not present.
|
|
180
|
+
*
|
|
181
|
+
* @param app - The Obsidian App instance
|
|
182
|
+
* @param folder - Folder path (empty string for root, no trailing slash needed)
|
|
183
|
+
* @param baseName - Base file name without extension
|
|
184
|
+
* @returns Unique file path that doesn't exist in the vault
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* // If "MyNote.md" exists, returns "MyNote 1.md"
|
|
189
|
+
* const path = getUniqueFilePath(app, "", "MyNote");
|
|
190
|
+
*
|
|
191
|
+
* // With folder: "Projects/Task.md" -> "Projects/Task 1.md"
|
|
192
|
+
* const path = getUniqueFilePath(app, "Projects", "Task");
|
|
193
|
+
*
|
|
194
|
+
* // Root folder handling
|
|
195
|
+
* const path = getUniqueFilePath(app, "/", "Note"); // -> "Note.md"
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function getUniqueFilePath(app, folder, baseName) {
|
|
199
|
+
const normalizedFolder = folder && folder !== "/" ? folder : "";
|
|
200
|
+
const folderPath = normalizedFolder ? `${normalizedFolder}/` : "";
|
|
201
|
+
let fileName = `${baseName}.md`;
|
|
202
|
+
let fullPath = `${folderPath}${fileName}`;
|
|
203
|
+
let counter = 1;
|
|
204
|
+
while (app.vault.getAbstractFileByPath(fullPath)) {
|
|
205
|
+
fileName = `${baseName} ${counter}.md`;
|
|
206
|
+
fullPath = `${folderPath}${fileName}`;
|
|
207
|
+
counter++;
|
|
208
|
+
}
|
|
209
|
+
return fullPath;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Generates a unique file path by appending a counter if the file already exists.
|
|
213
|
+
* Supports custom file extensions.
|
|
214
|
+
*
|
|
215
|
+
* @param app - The Obsidian App instance
|
|
216
|
+
* @param folder - Folder path (empty string for root)
|
|
217
|
+
* @param baseName - Base file name without extension
|
|
218
|
+
* @param extension - File extension (defaults to "md")
|
|
219
|
+
* @returns Unique file path that doesn't exist in the vault
|
|
220
|
+
*/
|
|
221
|
+
export const generateUniqueFilePath = (app, folder, baseName, extension = "md") => {
|
|
222
|
+
const folderPath = folder ? `${folder}/` : "";
|
|
223
|
+
let filePath = `${folderPath}${baseName}.${extension}`;
|
|
224
|
+
let counter = 1;
|
|
225
|
+
while (app.vault.getAbstractFileByPath(filePath)) {
|
|
226
|
+
filePath = `${folderPath}${baseName} ${counter++}.${extension}`;
|
|
227
|
+
}
|
|
228
|
+
return filePath;
|
|
229
|
+
};
|
|
230
|
+
// ============================================================================
|
|
231
|
+
// Folder Note Operations
|
|
232
|
+
// ============================================================================
|
|
233
|
+
/**
|
|
234
|
+
* Checks if a file is a folder note.
|
|
235
|
+
* A folder note is a file whose name matches its parent folder name.
|
|
236
|
+
*
|
|
237
|
+
* @param filePath - Path to the file (e.g., "tasks/tasks.md")
|
|
238
|
+
* @returns true if the file is a folder note, false otherwise
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* isFolderNote("tasks/tasks.md") // true
|
|
243
|
+
* isFolderNote("tasks/subtask.md") // false
|
|
244
|
+
* isFolderNote("note.md") // false (no parent folder)
|
|
245
|
+
* isFolderNote("projects/docs/docs.md") // true
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export function isFolderNote(filePath) {
|
|
249
|
+
if (!filePath)
|
|
250
|
+
return false;
|
|
251
|
+
// Remove .md extension for comparison
|
|
252
|
+
const pathWithoutExt = removeMarkdownExtension(filePath);
|
|
253
|
+
// Split path into segments
|
|
254
|
+
const segments = pathWithoutExt.split("/");
|
|
255
|
+
// Need at least 2 segments (folder/file)
|
|
256
|
+
if (segments.length < 2)
|
|
257
|
+
return false;
|
|
258
|
+
// Get the file name (last segment) and parent folder name (second to last)
|
|
259
|
+
const fileName = segments[segments.length - 1];
|
|
260
|
+
const parentFolderName = segments[segments.length - 2];
|
|
261
|
+
// File is a folder note if its name matches the parent folder
|
|
262
|
+
return fileName === parentFolderName;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets the folder path for a file.
|
|
266
|
+
*
|
|
267
|
+
* @param filePath - Path to the file (e.g., "tasks/subtask.md")
|
|
268
|
+
* @returns Folder path without trailing slash, or empty string if file is in root
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* getFolderPath("tasks/subtask.md") // "tasks"
|
|
273
|
+
* getFolderPath("projects/docs/notes.md") // "projects/docs"
|
|
274
|
+
* getFolderPath("note.md") // ""
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
export function getFolderPath(filePath) {
|
|
278
|
+
if (!filePath)
|
|
279
|
+
return "";
|
|
280
|
+
const lastSlashIndex = filePath.lastIndexOf("/");
|
|
281
|
+
if (lastSlashIndex === -1)
|
|
282
|
+
return "";
|
|
283
|
+
return filePath.substring(0, lastSlashIndex);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Gets all markdown files in a specific folder (non-recursive).
|
|
287
|
+
*
|
|
288
|
+
* @param app - The Obsidian App instance
|
|
289
|
+
* @param folderPath - Path to the folder (e.g., "tasks")
|
|
290
|
+
* @returns Array of TFile objects in the folder
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* const files = getFilesInFolder(app, "tasks");
|
|
295
|
+
* // Returns [task1.md, task2.md, tasks.md] but not tasks/subtasks/file.md
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export function getFilesInFolder(app, folderPath) {
|
|
299
|
+
const allFiles = app.vault.getMarkdownFiles();
|
|
300
|
+
return allFiles.filter((file) => {
|
|
301
|
+
const fileFolder = getFolderPath(file.path);
|
|
302
|
+
return fileFolder === folderPath;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Gets all markdown files in a folder and its subfolders recursively.
|
|
307
|
+
*
|
|
308
|
+
* @param app - The Obsidian App instance
|
|
309
|
+
* @param folderPath - Path to the folder (e.g., "tasks")
|
|
310
|
+
* @returns Array of TFile objects in the folder tree
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* const files = getAllFilesInFolderTree(app, "tasks");
|
|
315
|
+
* // Returns all .md files in tasks/ and all its subdirectories
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export function getAllFilesInFolderTree(app, folderPath) {
|
|
319
|
+
const allFiles = app.vault.getMarkdownFiles();
|
|
320
|
+
const normalizedFolder = folderPath ? `${folderPath}/` : "";
|
|
321
|
+
return allFiles.filter((file) => {
|
|
322
|
+
if (!normalizedFolder)
|
|
323
|
+
return true; // Root folder includes all files
|
|
324
|
+
return file.path.startsWith(normalizedFolder);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Gets the parent file path based on folder structure.
|
|
329
|
+
* For a file in a folder, the parent is the folder note if it exists.
|
|
330
|
+
*
|
|
331
|
+
* @param app - The Obsidian App instance
|
|
332
|
+
* @param filePath - Path to the file
|
|
333
|
+
* @returns Path to parent file, or null if no parent exists
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* // If tasks/tasks.md exists
|
|
338
|
+
* getParentByFolder(app, "tasks/subtask.md") // "tasks/tasks.md"
|
|
339
|
+
*
|
|
340
|
+
* // If parent folder note doesn't exist
|
|
341
|
+
* getParentByFolder(app, "tasks/subtask.md") // null
|
|
342
|
+
*
|
|
343
|
+
* // Root level file
|
|
344
|
+
* getParentByFolder(app, "note.md") // null
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export function getParentByFolder(app, filePath) {
|
|
348
|
+
const folderPath = getFolderPath(filePath);
|
|
349
|
+
if (!folderPath)
|
|
350
|
+
return null; // File is at root level
|
|
351
|
+
// Check if folder note exists
|
|
352
|
+
const folderSegments = folderPath.split("/");
|
|
353
|
+
const parentFolderName = folderSegments[folderSegments.length - 1];
|
|
354
|
+
const potentialParentPath = `${folderPath}/${parentFolderName}.md`;
|
|
355
|
+
const parentFile = getFileByPath(app, potentialParentPath);
|
|
356
|
+
return parentFile ? potentialParentPath : null;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Gets all child file paths based on folder structure.
|
|
360
|
+
* Works for both folder notes and regular files.
|
|
361
|
+
*
|
|
362
|
+
* For folder notes (e.g., "tasks/tasks.md"):
|
|
363
|
+
* - Returns all files directly in the folder (excluding the folder note)
|
|
364
|
+
* - Includes subfolder notes one level down
|
|
365
|
+
*
|
|
366
|
+
* For regular files (e.g., "tasks/task1.md"):
|
|
367
|
+
* - Returns the folder note from matching subfolder if it exists (e.g., "tasks/task1/task1.md")
|
|
368
|
+
*
|
|
369
|
+
* @param app - The Obsidian App instance
|
|
370
|
+
* @param filePath - Path to the file
|
|
371
|
+
* @returns Array of child file paths
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* // For tasks/tasks.md (folder note)
|
|
376
|
+
* getChildrenByFolder(app, "tasks/tasks.md")
|
|
377
|
+
* // Returns ["tasks/task1.md", "tasks/task2.md", "tasks/subtasks/subtasks.md"]
|
|
378
|
+
*
|
|
379
|
+
* // For tasks/task1.md (regular file with matching subfolder)
|
|
380
|
+
* getChildrenByFolder(app, "tasks/task1.md")
|
|
381
|
+
* // Returns ["tasks/task1/task1.md"] if it exists
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
export function getChildrenByFolder(app, filePath) {
|
|
385
|
+
const allFiles = app.vault.getMarkdownFiles();
|
|
386
|
+
// Case 1: Folder note - get all files in the folder
|
|
387
|
+
if (isFolderNote(filePath)) {
|
|
388
|
+
const folderPath = getFolderPath(filePath);
|
|
389
|
+
const children = [];
|
|
390
|
+
allFiles.forEach((file) => {
|
|
391
|
+
// Skip the folder note itself
|
|
392
|
+
if (file.path === filePath)
|
|
393
|
+
return;
|
|
394
|
+
const fileFolder = getFolderPath(file.path);
|
|
395
|
+
// Direct child: file is in the same folder as the folder note
|
|
396
|
+
if (fileFolder === folderPath) {
|
|
397
|
+
children.push(file.path);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
// Subfolder note: file is a folder note one level deeper
|
|
401
|
+
// e.g., for "tasks/tasks.md", include "tasks/subtasks/subtasks.md"
|
|
402
|
+
if (fileFolder.startsWith(`${folderPath}/`)) {
|
|
403
|
+
// Check if it's exactly one level deeper and is a folder note
|
|
404
|
+
const relativePath = fileFolder.substring(folderPath.length + 1);
|
|
405
|
+
const isOneLevel = !relativePath.includes("/");
|
|
406
|
+
if (isOneLevel && isFolderNote(file.path)) {
|
|
407
|
+
children.push(file.path);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return children;
|
|
412
|
+
}
|
|
413
|
+
// Case 2: Regular file - check for matching subfolder with folder note
|
|
414
|
+
const pathWithoutExt = removeMarkdownExtension(filePath);
|
|
415
|
+
const fileName = pathWithoutExt.split("/").pop() || "";
|
|
416
|
+
const potentialChildFolder = `${pathWithoutExt}`;
|
|
417
|
+
const potentialChildPath = `${potentialChildFolder}/${fileName}.md`;
|
|
418
|
+
// Check if the child folder note exists
|
|
419
|
+
const childFile = getFileByPath(app, potentialChildPath);
|
|
420
|
+
return childFile ? [potentialChildPath] : [];
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Finds all root nodes in a folder tree.
|
|
424
|
+
* Root nodes are files at the top level of the folder (directly in the folder, not in subfolders).
|
|
425
|
+
*
|
|
426
|
+
* @param app - The Obsidian App instance
|
|
427
|
+
* @param folderPath - Path to the folder
|
|
428
|
+
* @returns Array of root file paths
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* // For folder structure:
|
|
433
|
+
* // tasks/
|
|
434
|
+
* // tasks.md (folder note)
|
|
435
|
+
* // task1.md
|
|
436
|
+
* // subtasks/
|
|
437
|
+
* // subtasks.md
|
|
438
|
+
* // subtask1.md
|
|
439
|
+
*
|
|
440
|
+
* findRootNodesInFolder(app, "tasks")
|
|
441
|
+
* // Returns ["tasks/tasks.md", "tasks/task1.md"]
|
|
442
|
+
* // Excludes subtasks/subtasks.md and subtasks/subtask1.md (they're in subfolder)
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
export function findRootNodesInFolder(app, folderPath) {
|
|
446
|
+
return getFilesInFolder(app, folderPath).map((file) => file.path);
|
|
447
|
+
}
|
|
448
|
+
// ============================================================================
|
|
449
|
+
// Legacy Utility Functions (kept for backwards compatibility)
|
|
450
|
+
// ============================================================================
|
|
451
|
+
export const sanitizeForFilename = (input) => {
|
|
452
|
+
return input
|
|
453
|
+
.replace(/[<>:"/\\|?*]/g, "") // Remove invalid filename characters
|
|
454
|
+
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
|
455
|
+
.replace(/-+/g, "-") // Replace multiple hyphens with single
|
|
456
|
+
.replace(/^-|-$/g, "") // Remove leading/trailing hyphens
|
|
457
|
+
.toLowerCase();
|
|
458
|
+
};
|
|
459
|
+
export const getFilenameFromPath = (filePath) => {
|
|
460
|
+
return filePath.split("/").pop() || "Unknown";
|
|
461
|
+
};
|
|
462
|
+
export const isFileInConfiguredDirectory = (filePath, directory) => {
|
|
463
|
+
const normalizedDir = directory.endsWith("/") ? directory.slice(0, -1) : directory;
|
|
464
|
+
return filePath.startsWith(`${normalizedDir}/`) || filePath === normalizedDir;
|
|
465
|
+
};
|
|
466
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file/file.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAQ,EAAE,QAAgB;IACvD,8CAA8C;IAC9C,kEAAkE;IAClE,MAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CA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C;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC/D,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,SAAS,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,SAAiB,EAAW,EAAE;IAC3F,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,GAAG,CAAC,IAAI,QAAQ,KAAK,aAAa,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["import type { App, CachedMetadata } from \"obsidian\";\nimport { normalizePath, TFile } from \"obsidian\";\n\n// ============================================================================\n// File Path Operations\n// ============================================================================\n\n/**\n * Retrieves a TFile object from the vault by its path.\n * Handles path normalization using Obsidian's normalizePath utility.\n *\n * **Important**: Obsidian file paths ALWAYS include the `.md` extension.\n * The TFile.path property returns paths like \"folder/file.md\", not \"folder/file\".\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file (will be normalized, should include .md extension)\n * @returns TFile if found, null otherwise\n *\n * @example\n * ```ts\n * // Correct: Include .md extension\n * const file = getFileByPath(app, \"folder/note.md\");\n *\n * // For wikilinks without extension, add .md\n * const linkPath = \"MyNote\";\n * const file = getFileByPath(app, `${linkPath}.md`);\n * ```\n */\nexport function getFileByPath(app: App, filePath: string): TFile | null {\n\t// Normalize the path using Obsidian's utility\n\t// This handles slashes, spaces, and platform-specific path issues\n\tconst normalizedPath = normalizePath(filePath);\n\n\t// Use Vault's direct lookup method (most efficient)\n\t// Prefer getFileByPath if available, otherwise use getAbstractFileByPath\n\tif (typeof app.vault.getFileByPath === \"function\") {\n\t\treturn app.vault.getFileByPath(normalizedPath);\n\t}\n\n\tconst abstractFile = app.vault.getAbstractFileByPath(normalizedPath);\n\n\treturn abstractFile instanceof TFile ? abstractFile : null;\n}\n\n/**\n * Ensures a file path includes the .md extension.\n * Use this when working with wikilinks or user input that may omit extensions.\n *\n * @param path - File path that may or may not include .md extension\n * @returns Path guaranteed to end with .md\n *\n * @example\n * ```ts\n * ensureMarkdownExtension(\"MyNote\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"MyNote.md\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"folder/note\") // \"folder/note.md\"\n * ```\n */\nexport function ensureMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n}\n\n/**\n * Removes the .md extension from a file path if present.\n * Useful for displaying file names or creating wikilinks.\n *\n * @param path - File path that may include .md extension\n * @returns Path without .md extension\n *\n * @example\n * ```ts\n * removeMarkdownExtension(\"folder/note.md\") // \"folder/note\"\n * removeMarkdownExtension(\"folder/note\") // \"folder/note\"\n * ```\n */\nexport function removeMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path.slice(0, -3) : path;\n}\n\n// ============================================================================\n// File Name Extraction\n// ============================================================================\n\n/**\n * Extracts the display name from a file path or wiki link.\n *\n * Handles various formats:\n * - `[[path/to/file|Alias]]` -> returns \"Alias\"\n * - `[[path/to/file]]` -> returns \"file\"\n * - `path/to/file.md` -> returns \"file\"\n * - `file.md` -> returns \"file\"\n *\n * @param input - File path or wiki link string\n * @returns The display name to show in the UI\n */\nexport function extractDisplayName(input: string): string {\n\tif (!input) return \"\";\n\n\t// Remove any surrounding whitespace\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tif (pipeIndex !== -1) {\n\t\t\t// Return the alias (everything after the pipe)\n\t\t\treturn innerContent.substring(pipeIndex + 1).trim();\n\t\t}\n\n\t\t// No alias, extract filename from path\n\t\tconst path = innerContent.trim();\n\n\t\tconst lastSlashIndex = path.lastIndexOf(\"/\");\n\n\t\tconst filename = lastSlashIndex !== -1 ? path.substring(lastSlashIndex + 1) : path;\n\n\t\treturn filename.replace(/\\.md$/i, \"\");\n\t}\n\n\t// Not a wiki link, treat as regular path\n\tconst lastSlashIndex = trimmed.lastIndexOf(\"/\");\n\n\tconst filename = lastSlashIndex !== -1 ? trimmed.substring(lastSlashIndex + 1) : trimmed;\n\n\treturn filename.replace(/\\.md$/i, \"\");\n}\n\n/**\n * Extracts the actual file path from a wiki link or returns the path as-is.\n *\n * Handles:\n * - `[[path/to/file|Alias]]` -> returns \"path/to/file.md\"\n * - `[[path/to/file]]` -> returns \"path/to/file.md\"\n * - `path/to/file.md` -> returns \"path/to/file.md\"\n *\n * @param input - File path or wiki link string\n * @returns The actual file path (with .md extension)\n */\nexport function extractFilePath(input: string): string {\n\tif (!input) return \"\";\n\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tconst path =\n\t\t\tpipeIndex !== -1 ? innerContent.substring(0, pipeIndex).trim() : innerContent.trim();\n\n\t\t// Ensure .md extension\n\t\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n\t}\n\n\t// Not a wiki link, ensure .md extension\n\treturn trimmed.endsWith(\".md\") ? trimmed : `${trimmed}.md`;\n}\n\n// ============================================================================\n// File Context\n// ============================================================================\n\nexport interface FileContext {\n\tpath: string;\n\tpathWithExt: string;\n\tbaseName: string;\n\tfile: TFile | null;\n\tfrontmatter: Record<string, any> | undefined;\n\tcache: CachedMetadata | null;\n}\n\n/**\n * Creates a comprehensive file context object containing all relevant file information.\n * Handles path normalization, file lookup, and metadata caching.\n */\nexport function getFileContext(app: App, path: string): FileContext {\n\tconst pathWithExt = ensureMarkdownExtension(path);\n\n\tconst baseName = removeMarkdownExtension(path);\n\n\tconst file = getFileByPath(app, pathWithExt);\n\n\tconst cache = file ? app.metadataCache.getFileCache(file) : null;\n\n\tconst frontmatter = cache?.frontmatter;\n\n\treturn {\n\t\tpath,\n\t\tpathWithExt,\n\t\tbaseName,\n\t\tfile,\n\t\tfrontmatter,\n\t\tcache,\n\t};\n}\n\n/**\n * Helper function to work with file context that automatically handles file not found cases.\n * Returns null if the file doesn't exist, otherwise executes the callback with the context.\n */\nexport async function withFileContext<T>(\n\tapp: App,\n\tpath: string,\n\tcallback: (context: FileContext) => Promise<T> | T\n): Promise<T | null> {\n\tconst context = getFileContext(app, path);\n\n\tif (!context.file) {\n\t\tconsole.warn(`File not found: ${context.pathWithExt}`);\n\t\treturn null;\n\t}\n\n\treturn await callback(context);\n}\n\n// ============================================================================\n// File Path Generation\n// ============================================================================\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Automatically adds .md extension if not present.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root, no trailing slash needed)\n * @param baseName - Base file name without extension\n * @returns Unique file path that doesn't exist in the vault\n *\n * @example\n * ```ts\n * // If \"MyNote.md\" exists, returns \"MyNote 1.md\"\n * const path = getUniqueFilePath(app, \"\", \"MyNote\");\n *\n * // With folder: \"Projects/Task.md\" -> \"Projects/Task 1.md\"\n * const path = getUniqueFilePath(app, \"Projects\", \"Task\");\n *\n * // Root folder handling\n * const path = getUniqueFilePath(app, \"/\", \"Note\"); // -> \"Note.md\"\n * ```\n */\nexport function getUniqueFilePath(app: App, folder: string, baseName: string): string {\n\tconst normalizedFolder = folder && folder !== \"/\" ? folder : \"\";\n\tconst folderPath = normalizedFolder ? `${normalizedFolder}/` : \"\";\n\n\tlet fileName = `${baseName}.md`;\n\tlet fullPath = `${folderPath}${fileName}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(fullPath)) {\n\t\tfileName = `${baseName} ${counter}.md`;\n\t\tfullPath = `${folderPath}${fileName}`;\n\t\tcounter++;\n\t}\n\n\treturn fullPath;\n}\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Supports custom file extensions.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root)\n * @param baseName - Base file name without extension\n * @param extension - File extension (defaults to \"md\")\n * @returns Unique file path that doesn't exist in the vault\n */\nexport const generateUniqueFilePath = (\n\tapp: App,\n\tfolder: string,\n\tbaseName: string,\n\textension: string = \"md\"\n): string => {\n\tconst folderPath = folder ? `${folder}/` : \"\";\n\tlet filePath = `${folderPath}${baseName}.${extension}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(filePath)) {\n\t\tfilePath = `${folderPath}${baseName} ${counter++}.${extension}`;\n\t}\n\n\treturn filePath;\n};\n\n// ============================================================================\n// Folder Note Operations\n// ============================================================================\n\n/**\n * Checks if a file is a folder note.\n * A folder note is a file whose name matches its parent folder name.\n *\n * @param filePath - Path to the file (e.g., \"tasks/tasks.md\")\n * @returns true if the file is a folder note, false otherwise\n *\n * @example\n * ```ts\n * isFolderNote(\"tasks/tasks.md\") // true\n * isFolderNote(\"tasks/subtask.md\") // false\n * isFolderNote(\"note.md\") // false (no parent folder)\n * isFolderNote(\"projects/docs/docs.md\") // true\n * ```\n */\nexport function isFolderNote(filePath: string): boolean {\n\tif (!filePath) return false;\n\n\t// Remove .md extension for comparison\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\t// Split path into segments\n\tconst segments = pathWithoutExt.split(\"/\");\n\n\t// Need at least 2 segments (folder/file)\n\tif (segments.length < 2) return false;\n\n\t// Get the file name (last segment) and parent folder name (second to last)\n\tconst fileName = segments[segments.length - 1];\n\tconst parentFolderName = segments[segments.length - 2];\n\n\t// File is a folder note if its name matches the parent folder\n\treturn fileName === parentFolderName;\n}\n\n/**\n * Gets the folder path for a file.\n *\n * @param filePath - Path to the file (e.g., \"tasks/subtask.md\")\n * @returns Folder path without trailing slash, or empty string if file is in root\n *\n * @example\n * ```ts\n * getFolderPath(\"tasks/subtask.md\") // \"tasks\"\n * getFolderPath(\"projects/docs/notes.md\") // \"projects/docs\"\n * getFolderPath(\"note.md\") // \"\"\n * ```\n */\nexport function getFolderPath(filePath: string): string {\n\tif (!filePath) return \"\";\n\n\tconst lastSlashIndex = filePath.lastIndexOf(\"/\");\n\n\tif (lastSlashIndex === -1) return \"\";\n\n\treturn filePath.substring(0, lastSlashIndex);\n}\n\n/**\n * Gets all markdown files in a specific folder (non-recursive).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder\n *\n * @example\n * ```ts\n * const files = getFilesInFolder(app, \"tasks\");\n * // Returns [task1.md, task2.md, tasks.md] but not tasks/subtasks/file.md\n * ```\n */\nexport function getFilesInFolder(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\treturn allFiles.filter((file) => {\n\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\treturn fileFolder === folderPath;\n\t});\n}\n\n/**\n * Gets all markdown files in a folder and its subfolders recursively.\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder tree\n *\n * @example\n * ```ts\n * const files = getAllFilesInFolderTree(app, \"tasks\");\n * // Returns all .md files in tasks/ and all its subdirectories\n * ```\n */\nexport function getAllFilesInFolderTree(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\tconst normalizedFolder = folderPath ? `${folderPath}/` : \"\";\n\n\treturn allFiles.filter((file) => {\n\t\tif (!normalizedFolder) return true; // Root folder includes all files\n\n\t\treturn file.path.startsWith(normalizedFolder);\n\t});\n}\n\n/**\n * Gets the parent file path based on folder structure.\n * For a file in a folder, the parent is the folder note if it exists.\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Path to parent file, or null if no parent exists\n *\n * @example\n * ```ts\n * // If tasks/tasks.md exists\n * getParentByFolder(app, \"tasks/subtask.md\") // \"tasks/tasks.md\"\n *\n * // If parent folder note doesn't exist\n * getParentByFolder(app, \"tasks/subtask.md\") // null\n *\n * // Root level file\n * getParentByFolder(app, \"note.md\") // null\n * ```\n */\nexport function getParentByFolder(app: App, filePath: string): string | null {\n\tconst folderPath = getFolderPath(filePath);\n\n\tif (!folderPath) return null; // File is at root level\n\n\t// Check if folder note exists\n\tconst folderSegments = folderPath.split(\"/\");\n\n\tconst parentFolderName = folderSegments[folderSegments.length - 1];\n\n\tconst potentialParentPath = `${folderPath}/${parentFolderName}.md`;\n\n\tconst parentFile = getFileByPath(app, potentialParentPath);\n\n\treturn parentFile ? potentialParentPath : null;\n}\n\n/**\n * Gets all child file paths based on folder structure.\n * Works for both folder notes and regular files.\n *\n * For folder notes (e.g., \"tasks/tasks.md\"):\n * - Returns all files directly in the folder (excluding the folder note)\n * - Includes subfolder notes one level down\n *\n * For regular files (e.g., \"tasks/task1.md\"):\n * - Returns the folder note from matching subfolder if it exists (e.g., \"tasks/task1/task1.md\")\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Array of child file paths\n *\n * @example\n * ```ts\n * // For tasks/tasks.md (folder note)\n * getChildrenByFolder(app, \"tasks/tasks.md\")\n * // Returns [\"tasks/task1.md\", \"tasks/task2.md\", \"tasks/subtasks/subtasks.md\"]\n *\n * // For tasks/task1.md (regular file with matching subfolder)\n * getChildrenByFolder(app, \"tasks/task1.md\")\n * // Returns [\"tasks/task1/task1.md\"] if it exists\n * ```\n */\nexport function getChildrenByFolder(app: App, filePath: string): string[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\t// Case 1: Folder note - get all files in the folder\n\tif (isFolderNote(filePath)) {\n\t\tconst folderPath = getFolderPath(filePath);\n\n\t\tconst children: string[] = [];\n\n\t\tallFiles.forEach((file) => {\n\t\t\t// Skip the folder note itself\n\t\t\tif (file.path === filePath) return;\n\n\t\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\t\t// Direct child: file is in the same folder as the folder note\n\t\t\tif (fileFolder === folderPath) {\n\t\t\t\tchildren.push(file.path);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Subfolder note: file is a folder note one level deeper\n\t\t\t// e.g., for \"tasks/tasks.md\", include \"tasks/subtasks/subtasks.md\"\n\t\t\tif (fileFolder.startsWith(`${folderPath}/`)) {\n\t\t\t\t// Check if it's exactly one level deeper and is a folder note\n\t\t\t\tconst relativePath = fileFolder.substring(folderPath.length + 1);\n\n\t\t\t\tconst isOneLevel = !relativePath.includes(\"/\");\n\n\t\t\t\tif (isOneLevel && isFolderNote(file.path)) {\n\t\t\t\t\tchildren.push(file.path);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn children;\n\t}\n\n\t// Case 2: Regular file - check for matching subfolder with folder note\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\tconst fileName = pathWithoutExt.split(\"/\").pop() || \"\";\n\n\tconst potentialChildFolder = `${pathWithoutExt}`;\n\n\tconst potentialChildPath = `${potentialChildFolder}/${fileName}.md`;\n\n\t// Check if the child folder note exists\n\tconst childFile = getFileByPath(app, potentialChildPath);\n\n\treturn childFile ? [potentialChildPath] : [];\n}\n\n/**\n * Finds all root nodes in a folder tree.\n * Root nodes are files at the top level of the folder (directly in the folder, not in subfolders).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder\n * @returns Array of root file paths\n *\n * @example\n * ```ts\n * // For folder structure:\n * // tasks/\n * // tasks.md (folder note)\n * // task1.md\n * // subtasks/\n * // subtasks.md\n * // subtask1.md\n *\n * findRootNodesInFolder(app, \"tasks\")\n * // Returns [\"tasks/tasks.md\", \"tasks/task1.md\"]\n * // Excludes subtasks/subtasks.md and subtasks/subtask1.md (they're in subfolder)\n * ```\n */\nexport function findRootNodesInFolder(app: App, folderPath: string): string[] {\n\treturn getFilesInFolder(app, folderPath).map((file) => file.path);\n}\n\n// ============================================================================\n// Legacy Utility Functions (kept for backwards compatibility)\n// ============================================================================\n\nexport const sanitizeForFilename = (input: string): string => {\n\treturn input\n\t\t.replace(/[<>:\"/\\\\|?*]/g, \"\") // Remove invalid filename characters\n\t\t.replace(/\\s+/g, \"-\") // Replace spaces with hyphens\n\t\t.replace(/-+/g, \"-\") // Replace multiple hyphens with single\n\t\t.replace(/^-|-$/g, \"\") // Remove leading/trailing hyphens\n\t\t.toLowerCase();\n};\n\nexport const getFilenameFromPath = (filePath: string): string => {\n\treturn filePath.split(\"/\").pop() || \"Unknown\";\n};\n\nexport const isFileInConfiguredDirectory = (filePath: string, directory: string): boolean => {\n\tconst normalizedDir = directory.endsWith(\"/\") ? directory.slice(0, -1) : directory;\n\treturn filePath.startsWith(`${normalizedDir}/`) || filePath === normalizedDir;\n};\n"]}
|
|
@@ -12,4 +12,4 @@ export declare function parseFrontmatterValue(stringValue: string): unknown;
|
|
|
12
12
|
* Converts a record of string values back to their original frontmatter types.
|
|
13
13
|
*/
|
|
14
14
|
export declare function parseFrontmatterRecord(record: Record<string, string>): Record<string, unknown>;
|
|
15
|
-
//# sourceMappingURL=frontmatter
|
|
15
|
+
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/file/frontmatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAsClE;AAED;;GAEG;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OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAChC,CAAC;QAAC,WAAM,CAAC;YACR,wCAAwC;YACxC,OAAO,WAAW,CAAC;QACpB,CAAC;IACF,CAAC;IAED,iBAAiB;IACjB,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,WAAW,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,gDAAgD;IAChD,IAAI,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACzC,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC;QACZ,CAAC;IACF,CAAC;IAED,4CAA4C;IAC5C,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA8B;IACpE,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * Serializes a frontmatter value to a string representation for display in input fields.\n * Converts arrays, objects, booleans, and numbers to their string representations.\n */\nexport function serializeFrontmatterValue(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn \"\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\n\tif (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\treturn String(value);\n\t}\n\n\tif (Array.isArray(value) || typeof value === \"object\") {\n\t\treturn JSON.stringify(value);\n\t}\n\n\treturn String(value);\n}\n\n/**\n * Parses a string value back to its original frontmatter type.\n * Detects and converts to: arrays, objects, booleans, numbers, or keeps as string.\n */\nexport function parseFrontmatterValue(stringValue: string): unknown {\n\t// Empty string\n\tif (stringValue === \"\") {\n\t\treturn \"\";\n\t}\n\n\t// Try to parse as JSON (arrays, objects, null)\n\tif (\n\t\t(stringValue.startsWith(\"[\") && stringValue.endsWith(\"]\")) ||\n\t\t(stringValue.startsWith(\"{\") && stringValue.endsWith(\"}\")) ||\n\t\tstringValue === \"null\"\n\t) {\n\t\ttry {\n\t\t\treturn JSON.parse(stringValue);\n\t\t} catch {\n\t\t\t// If JSON parse fails, return as string\n\t\t\treturn stringValue;\n\t\t}\n\t}\n\n\t// Parse booleans\n\tif (stringValue === \"true\") {\n\t\treturn true;\n\t}\n\tif (stringValue === \"false\") {\n\t\treturn false;\n\t}\n\n\t// Parse numbers (including integers and floats)\n\tif (/^-?\\d+(\\.\\d+)?$/.test(stringValue)) {\n\t\tconst num = Number(stringValue);\n\t\tif (!Number.isNaN(num)) {\n\t\t\treturn num;\n\t\t}\n\t}\n\n\t// Return as string if no other type matches\n\treturn stringValue;\n}\n\n/**\n * Converts a record of string values back to their original frontmatter types.\n */\nexport function parseFrontmatterRecord(record: Record<string, string>): Record<string, unknown> {\n\tconst parsed: Record<string, unknown> = {};\n\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tparsed[key] = parseFrontmatterValue(value);\n\t}\n\n\treturn parsed;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./frontmatter\";\nexport * from \"./link-parser\";\nexport * from \"./templater\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-parser.d.ts","sourceRoot":"","sources":["../../src/file/link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAU/D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-parser.js","sourceRoot":"","sources":["../../src/file/link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAiB,EAAE;IACtE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACzD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpE,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,KAAK,CAAC;AAC/D,CAAC,CAAC","sourcesContent":["/**\n * Handles different link formats and edge cases:\n * [[FileName]] -> FileName.md\n * [[Folder/FileName]] -> Folder/FileName.md\n * [[Folder/FileName|DisplayName]] -> Folder/FileName.md\n * Normalizes paths and handles malformed links gracefully.\n */\nexport const extractFilePathFromLink = (link: string): string | null => {\n\tconst match = link.match(/\\[\\[([^|\\]]+?)(?:\\|.*?)?\\]\\]/);\n\tif (!match) return null;\n\n\tconst filePath = match[1].trim();\n\tif (!filePath) return null;\n\n\tif (filePath.includes(\"[[\") || filePath.includes(\"]]\")) return null;\n\n\treturn filePath.endsWith(\".md\") ? filePath : `${filePath}.md`;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type App, type TFile } from "obsidian";
|
|
2
2
|
export declare function isTemplaterAvailable(app: App): boolean;
|
|
3
3
|
export declare function createFromTemplate(app: App, templatePath: string, targetFolder?: string, filename?: string, openNewNote?: boolean): Promise<TFile | null>;
|
|
4
|
-
//# sourceMappingURL=templater
|
|
4
|
+
//# sourceMappingURL=templater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater.d.ts","sourceRoot":"","sources":["../../src/file/templater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAyB,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAgCvE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGtD;AAED,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,UAAQ,GACjB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CA+BvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater.js","sourceRoot":"","sources":["../../src/file/templater.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MAAM,EAAE,aAAa,EAAc,MAAM,UAAU,CAAC;AAEvE,MAAM,YAAY,GAAG,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CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;YACtE,IAAI,MAAM,CACT,0FAA0F,CAC1F,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,uBAAuB,YAAY,EAAE,CAAC,CAAC;YACrD,IAAI,MAAM,CAAC,4BAA4B,YAAY,2CAA2C,CAAC,CAAC;YAChG,OAAO,IAAI,CAAC;QACb,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,6BAA6B,CAC5D,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,CACX,CAAC;YAEF,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;YAC3D,IAAI,MAAM,CAAC,8EAA8E,CAAC,CAAC;YAC3F,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;CAAA","sourcesContent":["import { type App, Notice, normalizePath, type TFile } from \"obsidian\";\n\nconst TEMPLATER_ID = \"templater-obsidian\";\n\ntype CreateFn = (\n\ttemplateFile: TFile,\n\tfolder?: string,\n\tfilename?: string,\n\topenNewNote?: boolean\n) => Promise<TFile | undefined>;\n\ninterface TemplaterLike {\n\tcreate_new_note_from_template: CreateFn;\n}\n\nasync function waitForTemplater(app: App, timeoutMs = 8000): Promise<TemplaterLike | null> {\n\tawait new Promise<void>((resolve) => app.workspace.onLayoutReady(resolve));\n\n\tconst started = Date.now();\n\twhile (Date.now() - started < timeoutMs) {\n\t\tconst plug: any = (app as any).plugins?.getPlugin?.(TEMPLATER_ID);\n\t\tconst api = plug?.templater ?? null;\n\n\t\tconst createFn: CreateFn | undefined = api?.create_new_note_from_template?.bind(api);\n\t\tif (typeof createFn === \"function\") {\n\t\t\treturn { create_new_note_from_template: createFn };\n\t\t}\n\t\tawait new Promise((r) => setTimeout(r, 150));\n\t}\n\treturn null;\n}\n\nexport function isTemplaterAvailable(app: App): boolean {\n\tconst instance = (app as any).plugins?.getPlugin?.(TEMPLATER_ID);\n\treturn !!instance;\n}\n\nexport async function createFromTemplate(\n\tapp: App,\n\ttemplatePath: string,\n\ttargetFolder?: string,\n\tfilename?: string,\n\topenNewNote = false\n): Promise<TFile | null> {\n\tconst templater = await waitForTemplater(app);\n\tif (!templater) {\n\t\tconsole.warn(\"Templater isn't ready yet (or not installed/enabled).\");\n\t\tnew Notice(\n\t\t\t\"Templater plugin is not available or enabled. Please ensure it is installed and enabled.\"\n\t\t);\n\t\treturn null;\n\t}\n\n\tconst templateFile = app.vault.getFileByPath(normalizePath(templatePath));\n\tif (!templateFile) {\n\t\tconsole.error(`Template not found: ${templatePath}`);\n\t\tnew Notice(`Template file not found: ${templatePath}. Please ensure the template file exists.`);\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst newFile = await templater.create_new_note_from_template(\n\t\t\ttemplateFile,\n\t\t\ttargetFolder,\n\t\t\tfilename,\n\t\t\topenNewNote\n\t\t);\n\n\t\treturn newFile ?? null;\n\t} catch (error) {\n\t\tconsole.error(\"Error creating file from template:\", error);\n\t\tnew Notice(\"Error creating file from template. Please ensure the template file is valid.\");\n\t\treturn null;\n\t}\n}\n"]}
|