@real1ty-obsidian-plugins/utils 2.5.0 → 2.7.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.
Files changed (44) hide show
  1. package/dist/core/evaluator/filter.d.ts.map +1 -1
  2. package/dist/core/evaluator/filter.js.map +1 -1
  3. package/dist/core/frontmatter-value.d.ts +143 -0
  4. package/dist/core/frontmatter-value.d.ts.map +1 -0
  5. package/dist/core/frontmatter-value.js +408 -0
  6. package/dist/core/frontmatter-value.js.map +1 -0
  7. package/dist/core/index.d.ts +1 -0
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +1 -0
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/file/index.d.ts +1 -0
  12. package/dist/file/index.d.ts.map +1 -1
  13. package/dist/file/index.js +1 -0
  14. package/dist/file/index.js.map +1 -1
  15. package/dist/file/link-parser.d.ts +26 -0
  16. package/dist/file/link-parser.d.ts.map +1 -1
  17. package/dist/file/link-parser.js +59 -0
  18. package/dist/file/link-parser.js.map +1 -1
  19. package/dist/file/property-utils.d.ts +55 -0
  20. package/dist/file/property-utils.d.ts.map +1 -0
  21. package/dist/file/property-utils.js +90 -0
  22. package/dist/file/property-utils.js.map +1 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/inputs/index.d.ts +2 -0
  28. package/dist/inputs/index.d.ts.map +1 -0
  29. package/dist/inputs/index.js +2 -0
  30. package/dist/inputs/index.js.map +1 -0
  31. package/dist/inputs/input-filter-manager.d.ts +72 -0
  32. package/dist/inputs/input-filter-manager.d.ts.map +1 -0
  33. package/dist/inputs/input-filter-manager.js +140 -0
  34. package/dist/inputs/input-filter-manager.js.map +1 -0
  35. package/package.json +2 -1
  36. package/src/core/evaluator/filter.ts +0 -2
  37. package/src/core/frontmatter-value.ts +528 -0
  38. package/src/core/index.ts +1 -0
  39. package/src/file/index.ts +1 -0
  40. package/src/file/link-parser.ts +73 -0
  41. package/src/file/property-utils.ts +114 -0
  42. package/src/index.ts +2 -0
  43. package/src/inputs/index.ts +1 -0
  44. package/src/inputs/input-filter-manager.ts +194 -0
@@ -3,5 +3,6 @@ export * from "./file";
3
3
  export * from "./file-operations";
4
4
  export * from "./frontmatter";
5
5
  export * from "./link-parser";
6
+ export * from "./property-utils";
6
7
  export * from "./templater";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
@@ -3,5 +3,6 @@ export * from "./file";
3
3
  export * from "./file-operations";
4
4
  export * from "./frontmatter";
5
5
  export * from "./link-parser";
6
+ export * from "./property-utils";
6
7
  export * from "./templater";
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +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"]}
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,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./frontmatter\";\nexport * from \"./link-parser\";\nexport * from \"./property-utils\";\nexport * from \"./templater\";\n"]}
@@ -6,4 +6,30 @@
6
6
  * Normalizes paths and handles malformed links gracefully.
7
7
  */
8
8
  export declare const extractFilePathFromLink: (link: string) => string | null;
9
+ /**
10
+ * Parses an Obsidian wiki link to extract the file path.
11
+ * Handles formats like:
12
+ * - [[path/to/file]]
13
+ * - [[path/to/file|Display Name]]
14
+ *
15
+ * @param link - The wiki link string
16
+ * @returns The file path without the [[ ]] brackets, or null if invalid
17
+ */
18
+ export declare function parseWikiLink(link: string): string | null;
19
+ /**
20
+ * Parses a property value that can be a single link or an array of links.
21
+ * Extracts file paths from all valid wiki links.
22
+ *
23
+ * @param value - The property value (string, string[], or undefined)
24
+ * @returns Array of file paths, empty if no valid links found
25
+ */
26
+ export declare function parsePropertyLinks(value: string | string[] | undefined): string[];
27
+ /**
28
+ * Formats a file path as an Obsidian wiki link with display name.
29
+ * Example: "Projects/MyProject" -> "[[Projects/MyProject|MyProject]]"
30
+ *
31
+ * @param filePath - The file path to format
32
+ * @returns The formatted wiki link with display name alias
33
+ */
34
+ export declare function formatWikiLink(filePath: string): string;
9
35
  //# sourceMappingURL=link-parser.d.ts.map
@@ -1 +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"}
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;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAezD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAQjF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAqBvD"}
@@ -16,4 +16,63 @@ export const extractFilePathFromLink = (link) => {
16
16
  return null;
17
17
  return filePath.endsWith(".md") ? filePath : `${filePath}.md`;
18
18
  };
19
+ /**
20
+ * Parses an Obsidian wiki link to extract the file path.
21
+ * Handles formats like:
22
+ * - [[path/to/file]]
23
+ * - [[path/to/file|Display Name]]
24
+ *
25
+ * @param link - The wiki link string
26
+ * @returns The file path without the [[ ]] brackets, or null if invalid
27
+ */
28
+ export function parseWikiLink(link) {
29
+ if (!link || typeof link !== "string") {
30
+ return null;
31
+ }
32
+ const trimmed = link.trim();
33
+ // Match [[path/to/file]] or [[path/to/file|Display Name]]
34
+ const match = trimmed.match(/^\[\[([^\]|]+)(?:\|[^\]]+)?\]\]$/);
35
+ if (!match) {
36
+ return null;
37
+ }
38
+ return match[1].trim();
39
+ }
40
+ /**
41
+ * Parses a property value that can be a single link or an array of links.
42
+ * Extracts file paths from all valid wiki links.
43
+ *
44
+ * @param value - The property value (string, string[], or undefined)
45
+ * @returns Array of file paths, empty if no valid links found
46
+ */
47
+ export function parsePropertyLinks(value) {
48
+ if (!value) {
49
+ return [];
50
+ }
51
+ const links = Array.isArray(value) ? value : [value];
52
+ return links.map((link) => parseWikiLink(link)).filter((path) => path !== null);
53
+ }
54
+ /**
55
+ * Formats a file path as an Obsidian wiki link with display name.
56
+ * Example: "Projects/MyProject" -> "[[Projects/MyProject|MyProject]]"
57
+ *
58
+ * @param filePath - The file path to format
59
+ * @returns The formatted wiki link with display name alias
60
+ */
61
+ export function formatWikiLink(filePath) {
62
+ if (!filePath || typeof filePath !== "string") {
63
+ return "";
64
+ }
65
+ const trimmed = filePath.trim();
66
+ if (!trimmed) {
67
+ return "";
68
+ }
69
+ // Extract the filename (last segment after the last /)
70
+ const segments = trimmed.split("/");
71
+ const displayName = segments[segments.length - 1];
72
+ // If there's no path separator, just return simple link
73
+ if (segments.length === 1) {
74
+ return `[[${trimmed}]]`;
75
+ }
76
+ return `[[${trimmed}|${displayName}]]`;
77
+ }
19
78
  //# sourceMappingURL=link-parser.js.map
@@ -1 +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
+ {"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;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,OAAO,GAAG,IAAI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O,IAAI,CAAC;IACzB,CAAC;IAED,OAAO,KAAK,OAAO,IAAI,WAAW,IAAI,CAAC;AACxC,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\n/**\n * Parses an Obsidian wiki link to extract the file path.\n * Handles formats like:\n * - [[path/to/file]]\n * - [[path/to/file|Display Name]]\n *\n * @param link - The wiki link string\n * @returns The file path without the [[ ]] brackets, or null if invalid\n */\nexport function parseWikiLink(link: string): string | null {\n\tif (!link || typeof link !== \"string\") {\n\t\treturn null;\n\t}\n\n\tconst trimmed = link.trim();\n\n\t// Match [[path/to/file]] or [[path/to/file|Display Name]]\n\tconst match = trimmed.match(/^\\[\\[([^\\]|]+)(?:\\|[^\\]]+)?\\]\\]$/);\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\treturn match[1].trim();\n}\n\n/**\n * Parses a property value that can be a single link or an array of links.\n * Extracts file paths from all valid wiki links.\n *\n * @param value - The property value (string, string[], or undefined)\n * @returns Array of file paths, empty if no valid links found\n */\nexport function parsePropertyLinks(value: string | string[] | undefined): string[] {\n\tif (!value) {\n\t\treturn [];\n\t}\n\n\tconst links = Array.isArray(value) ? value : [value];\n\n\treturn links.map((link) => parseWikiLink(link)).filter((path): path is string => path !== null);\n}\n\n/**\n * Formats a file path as an Obsidian wiki link with display name.\n * Example: \"Projects/MyProject\" -> \"[[Projects/MyProject|MyProject]]\"\n *\n * @param filePath - The file path to format\n * @returns The formatted wiki link with display name alias\n */\nexport function formatWikiLink(filePath: string): string {\n\tif (!filePath || typeof filePath !== \"string\") {\n\t\treturn \"\";\n\t}\n\n\tconst trimmed = filePath.trim();\n\n\tif (!trimmed) {\n\t\treturn \"\";\n\t}\n\n\t// Extract the filename (last segment after the last /)\n\tconst segments = trimmed.split(\"/\");\n\tconst displayName = segments[segments.length - 1];\n\n\t// If there's no path separator, just return simple link\n\tif (segments.length === 1) {\n\t\treturn `[[${trimmed}]]`;\n\t}\n\n\treturn `[[${trimmed}|${displayName}]]`;\n}\n"]}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Adds a link to a property, avoiding duplicates using normalized path comparison.
3
+ * Prevents cycles and duplicate relationships by comparing normalized paths.
4
+ *
5
+ * **Important**: linkPath should be WITHOUT .md extension (wikilink format).
6
+ *
7
+ * @param currentValue - The current property value (can be string, string[], or undefined)
8
+ * @param linkPath - The file path to add (without .md extension, e.g., "folder/file")
9
+ * @returns New array with link added, or same array if link already exists
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * addLinkToProperty(undefined, "MyNote") // ["[[MyNote]]"]
14
+ * addLinkToProperty("[[Note1]]", "Note2") // ["[[Note1]]", "[[Note2]]"]
15
+ * addLinkToProperty(["[[Note1]]"], "Note2") // ["[[Note1]]", "[[Note2]]"]
16
+ * addLinkToProperty(["[[Note1]]"], "Note1") // ["[[Note1]]"] (no change - duplicate prevented)
17
+ * addLinkToProperty(["[[Folder/Note]]"], "folder/note") // ["[[Folder/Note]]", "[[folder/note|note]]"] (case-sensitive, different entry)
18
+ * ```
19
+ */
20
+ export declare function addLinkToProperty(currentValue: string | string[] | undefined, linkPath: string): string[];
21
+ /**
22
+ * Removes a link from a property using normalized path comparison.
23
+ *
24
+ * @param currentValue - The current property value (can be string, string[], or undefined)
25
+ * @param linkPath - The file path to remove (without .md extension)
26
+ * @returns New array with link removed (can be empty)
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * removeLinkFromProperty(["[[Note1]]", "[[Note2]]"], "Note1") // ["[[Note2]]"]
31
+ * removeLinkFromProperty(["[[Note1]]"], "Note1") // []
32
+ * removeLinkFromProperty("[[Note1]]", "Note1") // []
33
+ * removeLinkFromProperty(undefined, "Note1") // []
34
+ * removeLinkFromProperty(["[[Folder/Note]]"], "Folder/Note") // [] (case-sensitive removal)
35
+ * ```
36
+ */
37
+ export declare function removeLinkFromProperty(currentValue: string | string[] | undefined, linkPath: string): string[];
38
+ /**
39
+ * Checks if a link exists in a property using normalized path comparison.
40
+ *
41
+ * @param currentValue - The current property value (can be string, string[], or undefined)
42
+ * @param linkPath - The file path to check (without .md extension)
43
+ * @returns True if the link exists
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * hasLinkInProperty(["[[Note1]]", "[[Note2]]"], "Note1") // true
48
+ * hasLinkInProperty("[[Note1]]", "Note1") // true
49
+ * hasLinkInProperty([], "Note1") // false
50
+ * hasLinkInProperty(undefined, "Note1") // false
51
+ * hasLinkInProperty(["[[Folder/Note]]"], "Folder/Note") // true (case-sensitive match)
52
+ * ```
53
+ */
54
+ export declare function hasLinkInProperty(currentValue: string | string[] | undefined, linkPath: string): boolean;
55
+ //# sourceMappingURL=property-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-utils.d.ts","sourceRoot":"","sources":["../../src/file/property-utils.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EAC3C,QAAQ,EAAE,MAAM,GACd,MAAM,EAAE,CAsBV;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACrC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EAC3C,QAAQ,EAAE,MAAM,GACd,MAAM,EAAE,CAiBV;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EAC3C,QAAQ,EAAE,MAAM,GACd,OAAO,CAMT"}
@@ -0,0 +1,90 @@
1
+ import { normalizePath } from "obsidian";
2
+ import { formatWikiLink, parsePropertyLinks } from "./link-parser";
3
+ /**
4
+ * Adds a link to a property, avoiding duplicates using normalized path comparison.
5
+ * Prevents cycles and duplicate relationships by comparing normalized paths.
6
+ *
7
+ * **Important**: linkPath should be WITHOUT .md extension (wikilink format).
8
+ *
9
+ * @param currentValue - The current property value (can be string, string[], or undefined)
10
+ * @param linkPath - The file path to add (without .md extension, e.g., "folder/file")
11
+ * @returns New array with link added, or same array if link already exists
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * addLinkToProperty(undefined, "MyNote") // ["[[MyNote]]"]
16
+ * addLinkToProperty("[[Note1]]", "Note2") // ["[[Note1]]", "[[Note2]]"]
17
+ * addLinkToProperty(["[[Note1]]"], "Note2") // ["[[Note1]]", "[[Note2]]"]
18
+ * addLinkToProperty(["[[Note1]]"], "Note1") // ["[[Note1]]"] (no change - duplicate prevented)
19
+ * addLinkToProperty(["[[Folder/Note]]"], "folder/note") // ["[[Folder/Note]]", "[[folder/note|note]]"] (case-sensitive, different entry)
20
+ * ```
21
+ */
22
+ export function addLinkToProperty(currentValue, linkPath) {
23
+ // Handle undefined or null
24
+ if (currentValue === undefined || currentValue === null) {
25
+ return [formatWikiLink(linkPath)];
26
+ }
27
+ // Normalize to array
28
+ const currentArray = Array.isArray(currentValue) ? currentValue : [currentValue];
29
+ const existingPaths = parsePropertyLinks(currentArray);
30
+ // Normalize paths for comparison to prevent duplicates with different casing or separators
31
+ const normalizedLinkPath = normalizePath(linkPath);
32
+ const normalizedExistingPaths = existingPaths.map((p) => normalizePath(p));
33
+ // Only add if not already present (using normalized path comparison)
34
+ if (!normalizedExistingPaths.includes(normalizedLinkPath)) {
35
+ return [...currentArray, formatWikiLink(linkPath)];
36
+ }
37
+ return currentArray;
38
+ }
39
+ /**
40
+ * Removes a link from a property using normalized path comparison.
41
+ *
42
+ * @param currentValue - The current property value (can be string, string[], or undefined)
43
+ * @param linkPath - The file path to remove (without .md extension)
44
+ * @returns New array with link removed (can be empty)
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * removeLinkFromProperty(["[[Note1]]", "[[Note2]]"], "Note1") // ["[[Note2]]"]
49
+ * removeLinkFromProperty(["[[Note1]]"], "Note1") // []
50
+ * removeLinkFromProperty("[[Note1]]", "Note1") // []
51
+ * removeLinkFromProperty(undefined, "Note1") // []
52
+ * removeLinkFromProperty(["[[Folder/Note]]"], "Folder/Note") // [] (case-sensitive removal)
53
+ * ```
54
+ */
55
+ export function removeLinkFromProperty(currentValue, linkPath) {
56
+ if (currentValue === undefined || currentValue === null) {
57
+ return [];
58
+ }
59
+ // Normalize to array
60
+ const currentArray = Array.isArray(currentValue) ? currentValue : [currentValue];
61
+ const normalizedLinkPath = normalizePath(linkPath);
62
+ return currentArray.filter((item) => {
63
+ const parsed = parsePropertyLinks([item])[0];
64
+ if (!parsed)
65
+ return true; // Keep invalid entries
66
+ return normalizePath(parsed) !== normalizedLinkPath;
67
+ });
68
+ }
69
+ /**
70
+ * Checks if a link exists in a property using normalized path comparison.
71
+ *
72
+ * @param currentValue - The current property value (can be string, string[], or undefined)
73
+ * @param linkPath - The file path to check (without .md extension)
74
+ * @returns True if the link exists
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * hasLinkInProperty(["[[Note1]]", "[[Note2]]"], "Note1") // true
79
+ * hasLinkInProperty("[[Note1]]", "Note1") // true
80
+ * hasLinkInProperty([], "Note1") // false
81
+ * hasLinkInProperty(undefined, "Note1") // false
82
+ * hasLinkInProperty(["[[Folder/Note]]"], "Folder/Note") // true (case-sensitive match)
83
+ * ```
84
+ */
85
+ export function hasLinkInProperty(currentValue, linkPath) {
86
+ const existingPaths = parsePropertyLinks(currentValue);
87
+ const normalizedLinkPath = normalizePath(linkPath);
88
+ return existingPaths.some((path) => normalizePath(path) === normalizedLinkPath);
89
+ }
90
+ //# sourceMappingURL=property-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-utils.js","sourceRoot":"","sources":["../../src/file/property-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAChC,YAA2C,EAC3C,QAAgB;IAEhB,2BAA2B;IAC3B,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QACzD,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,qBAAqB;IACrB,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAEjF,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAEvD,2FAA2F;IAC3F,MAAM,kBAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnD,MAAM,uBAAuB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,qEAAqE;IACrE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC3D,OAAO,CAAC,GAAG,YAAY,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACrC,YAA2C,EAC3C,QAAgB;IAEhB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QACzD,OAAO,EAAE,CAAC;IACX,CAAC;IAED,qBAAqB;IACrB,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAEjF,MAAM,kBAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACnC,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE7C,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,CAAC,uBAAuB;QAEjD,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,kBAAkB,CAAC;IACrD,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAChC,YAA2C,EAC3C,QAAgB;IAEhB,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAEvD,MAAM,kBAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,kBAAkB,CAAC,CAAC;AACjF,CAAC","sourcesContent":["import { normalizePath } from \"obsidian\";\n\nimport { formatWikiLink, parsePropertyLinks } from \"./link-parser\";\n\n/**\n * Adds a link to a property, avoiding duplicates using normalized path comparison.\n * Prevents cycles and duplicate relationships by comparing normalized paths.\n *\n * **Important**: linkPath should be WITHOUT .md extension (wikilink format).\n *\n * @param currentValue - The current property value (can be string, string[], or undefined)\n * @param linkPath - The file path to add (without .md extension, e.g., \"folder/file\")\n * @returns New array with link added, or same array if link already exists\n *\n * @example\n * ```ts\n * addLinkToProperty(undefined, \"MyNote\") // [\"[[MyNote]]\"]\n * addLinkToProperty(\"[[Note1]]\", \"Note2\") // [\"[[Note1]]\", \"[[Note2]]\"]\n * addLinkToProperty([\"[[Note1]]\"], \"Note2\") // [\"[[Note1]]\", \"[[Note2]]\"]\n * addLinkToProperty([\"[[Note1]]\"], \"Note1\") // [\"[[Note1]]\"] (no change - duplicate prevented)\n * addLinkToProperty([\"[[Folder/Note]]\"], \"folder/note\") // [\"[[Folder/Note]]\", \"[[folder/note|note]]\"] (case-sensitive, different entry)\n * ```\n */\nexport function addLinkToProperty(\n\tcurrentValue: string | string[] | undefined,\n\tlinkPath: string\n): string[] {\n\t// Handle undefined or null\n\tif (currentValue === undefined || currentValue === null) {\n\t\treturn [formatWikiLink(linkPath)];\n\t}\n\n\t// Normalize to array\n\tconst currentArray = Array.isArray(currentValue) ? currentValue : [currentValue];\n\n\tconst existingPaths = parsePropertyLinks(currentArray);\n\n\t// Normalize paths for comparison to prevent duplicates with different casing or separators\n\tconst normalizedLinkPath = normalizePath(linkPath);\n\n\tconst normalizedExistingPaths = existingPaths.map((p) => normalizePath(p));\n\n\t// Only add if not already present (using normalized path comparison)\n\tif (!normalizedExistingPaths.includes(normalizedLinkPath)) {\n\t\treturn [...currentArray, formatWikiLink(linkPath)];\n\t}\n\n\treturn currentArray;\n}\n\n/**\n * Removes a link from a property using normalized path comparison.\n *\n * @param currentValue - The current property value (can be string, string[], or undefined)\n * @param linkPath - The file path to remove (without .md extension)\n * @returns New array with link removed (can be empty)\n *\n * @example\n * ```ts\n * removeLinkFromProperty([\"[[Note1]]\", \"[[Note2]]\"], \"Note1\") // [\"[[Note2]]\"]\n * removeLinkFromProperty([\"[[Note1]]\"], \"Note1\") // []\n * removeLinkFromProperty(\"[[Note1]]\", \"Note1\") // []\n * removeLinkFromProperty(undefined, \"Note1\") // []\n * removeLinkFromProperty([\"[[Folder/Note]]\"], \"Folder/Note\") // [] (case-sensitive removal)\n * ```\n */\nexport function removeLinkFromProperty(\n\tcurrentValue: string | string[] | undefined,\n\tlinkPath: string\n): string[] {\n\tif (currentValue === undefined || currentValue === null) {\n\t\treturn [];\n\t}\n\n\t// Normalize to array\n\tconst currentArray = Array.isArray(currentValue) ? currentValue : [currentValue];\n\n\tconst normalizedLinkPath = normalizePath(linkPath);\n\n\treturn currentArray.filter((item) => {\n\t\tconst parsed = parsePropertyLinks([item])[0];\n\n\t\tif (!parsed) return true; // Keep invalid entries\n\n\t\treturn normalizePath(parsed) !== normalizedLinkPath;\n\t});\n}\n\n/**\n * Checks if a link exists in a property using normalized path comparison.\n *\n * @param currentValue - The current property value (can be string, string[], or undefined)\n * @param linkPath - The file path to check (without .md extension)\n * @returns True if the link exists\n *\n * @example\n * ```ts\n * hasLinkInProperty([\"[[Note1]]\", \"[[Note2]]\"], \"Note1\") // true\n * hasLinkInProperty(\"[[Note1]]\", \"Note1\") // true\n * hasLinkInProperty([], \"Note1\") // false\n * hasLinkInProperty(undefined, \"Note1\") // false\n * hasLinkInProperty([\"[[Folder/Note]]\"], \"Folder/Note\") // true (case-sensitive match)\n * ```\n */\nexport function hasLinkInProperty(\n\tcurrentValue: string | string[] | undefined,\n\tlinkPath: string\n): boolean {\n\tconst existingPaths = parsePropertyLinks(currentValue);\n\n\tconst normalizedLinkPath = normalizePath(linkPath);\n\n\treturn existingPaths.some((path) => normalizePath(path) === normalizedLinkPath);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./async";
2
2
  export * from "./core";
3
3
  export * from "./date";
4
4
  export * from "./file";
5
+ export * from "./inputs";
5
6
  export * from "./settings";
6
7
  export * from "./string";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,SAAS,CAAC;AAExB,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,SAAS,CAAC;AAExB,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AAEvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ export * from "./core";
7
7
  export * from "./date";
8
8
  // File operations
9
9
  export * from "./file";
10
+ // Input utilities
11
+ export * from "./inputs";
10
12
  export * from "./settings";
11
13
  // String utilities
12
14
  export * from "./string";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AAEX,kBAAkB;AAClB,cAAc,SAAS,CAAC;AACxB,iBAAiB;AACjB,cAAc,QAAQ,CAAC;AAEvB,kBAAkB;AAClB,cAAc,QAAQ,CAAC;AACvB,kBAAkB;AAClB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,mBAAmB;AACnB,cAAc,UAAU,CAAC","sourcesContent":["// Settings\n\n// Async utilities\nexport * from \"./async\";\n// Core utilities\nexport * from \"./core\";\n\n// Date operations\nexport * from \"./date\";\n// File operations\nexport * from \"./file\";\nexport * from \"./settings\";\n// String utilities\nexport * from \"./string\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AAEX,kBAAkB;AAClB,cAAc,SAAS,CAAC;AACxB,iBAAiB;AACjB,cAAc,QAAQ,CAAC;AAEvB,kBAAkB;AAClB,cAAc,QAAQ,CAAC;AACvB,kBAAkB;AAClB,cAAc,QAAQ,CAAC;AACvB,kBAAkB;AAClB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,mBAAmB;AACnB,cAAc,UAAU,CAAC","sourcesContent":["// Settings\n\n// Async utilities\nexport * from \"./async\";\n// Core utilities\nexport * from \"./core\";\n\n// Date operations\nexport * from \"./date\";\n// File operations\nexport * from \"./file\";\n// Input utilities\nexport * from \"./inputs\";\nexport * from \"./settings\";\n// String utilities\nexport * from \"./string\";\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./input-filter-manager";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inputs/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./input-filter-manager";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/inputs/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC","sourcesContent":["export * from \"./input-filter-manager\";\n"]}
@@ -0,0 +1,72 @@
1
+ export type FilterChangeCallback = (filterValue: string) => void;
2
+ export interface InputFilterManagerOptions {
3
+ placeholder: string;
4
+ cssClass: string;
5
+ cssPrefix: string;
6
+ onFilterChange: FilterChangeCallback;
7
+ initiallyVisible?: boolean;
8
+ onHide?: () => void;
9
+ debounceMs?: number;
10
+ }
11
+ /**
12
+ * Abstract base class for managing input-based filters with debouncing.
13
+ * Provides a reusable pattern for filter inputs with show/hide functionality,
14
+ * keyboard shortcuts, and debounced updates.
15
+ *
16
+ * @template T - The type of data being filtered (optional, defaults to unknown)
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * class MyFilterManager extends InputFilterManager<MyDataType> {
21
+ * shouldInclude(data: MyDataType): boolean {
22
+ * const filter = this.getCurrentValue().toLowerCase();
23
+ * return data.name.toLowerCase().includes(filter);
24
+ * }
25
+ * }
26
+ *
27
+ * const manager = new MyFilterManager(
28
+ * containerEl,
29
+ * {
30
+ * placeholder: "Filter items...",
31
+ * cssClass: "my-filter-input",
32
+ * onFilterChange: (value) => console.log("Filter changed:", value),
33
+ * initiallyVisible: false,
34
+ * }
35
+ * );
36
+ * ```
37
+ */
38
+ export declare abstract class InputFilterManager<T> {
39
+ protected parentEl: HTMLElement;
40
+ protected containerEl: HTMLElement;
41
+ protected inputEl: HTMLInputElement | null;
42
+ protected debounceTimer: number | null;
43
+ protected currentValue: string;
44
+ protected persistentlyVisible: boolean;
45
+ protected onHide?: () => void;
46
+ protected readonly debounceMs: number;
47
+ protected readonly placeholder: string;
48
+ protected readonly cssClass: string;
49
+ protected readonly cssPrefix: string;
50
+ protected readonly onFilterChange: FilterChangeCallback;
51
+ constructor(parentEl: HTMLElement, options: InputFilterManagerOptions);
52
+ private render;
53
+ private handleInputChange;
54
+ private applyFilterImmediately;
55
+ protected updateFilterValue(value: string): void;
56
+ getCurrentValue(): string;
57
+ show(): void;
58
+ hide(): void;
59
+ focus(): void;
60
+ isVisible(): boolean;
61
+ setPersistentlyVisible(value: boolean): void;
62
+ destroy(): void;
63
+ /**
64
+ * Abstract method that subclasses must implement to determine
65
+ * whether a data item should be included based on the current filter.
66
+ *
67
+ * @param data - The data item to check
68
+ * @returns True if the item should be included, false otherwise
69
+ */
70
+ abstract shouldInclude(data: T): boolean;
71
+ }
72
+ //# sourceMappingURL=input-filter-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-filter-manager.d.ts","sourceRoot":"","sources":["../../src/inputs/input-filter-manager.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;AAIjE,MAAM,WAAW,yBAAyB;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,oBAAoB,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;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base class for managing input-based filters with debouncing.
4
+ * Provides a reusable pattern for filter inputs with show/hide functionality,
5
+ * keyboard shortcuts, and debounced updates.
6
+ *
7
+ * @template T - The type of data being filtered (optional, defaults to unknown)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * class MyFilterManager extends InputFilterManager<MyDataType> {
12
+ * shouldInclude(data: MyDataType): boolean {
13
+ * const filter = this.getCurrentValue().toLowerCase();
14
+ * return data.name.toLowerCase().includes(filter);
15
+ * }
16
+ * }
17
+ *
18
+ * const manager = new MyFilterManager(
19
+ * containerEl,
20
+ * {
21
+ * placeholder: "Filter items...",
22
+ * cssClass: "my-filter-input",
23
+ * onFilterChange: (value) => console.log("Filter changed:", value),
24
+ * initiallyVisible: false,
25
+ * }
26
+ * );
27
+ * ```
28
+ */
29
+ export class InputFilterManager {
30
+ constructor(parentEl, options) {
31
+ this.parentEl = parentEl;
32
+ this.inputEl = null;
33
+ this.debounceTimer = null;
34
+ this.currentValue = "";
35
+ this.persistentlyVisible = false;
36
+ const { placeholder, cssClass, cssPrefix, onFilterChange, initiallyVisible = false, onHide, debounceMs = DEFAULT_DEBOUNCE_MS, } = options;
37
+ this.debounceMs = debounceMs;
38
+ this.placeholder = placeholder;
39
+ this.cssClass = cssClass;
40
+ this.cssPrefix = cssPrefix;
41
+ this.onFilterChange = onFilterChange;
42
+ this.onHide = onHide;
43
+ const classes = `${cssClass}-container${initiallyVisible ? "" : ` ${cssPrefix}-hidden`}`;
44
+ this.containerEl = this.parentEl.createEl("div", {
45
+ cls: classes,
46
+ });
47
+ this.render();
48
+ }
49
+ render() {
50
+ this.inputEl = this.containerEl.createEl("input", {
51
+ type: "text",
52
+ cls: this.cssClass,
53
+ placeholder: this.placeholder,
54
+ });
55
+ this.inputEl.addEventListener("input", () => {
56
+ this.handleInputChange();
57
+ });
58
+ this.inputEl.addEventListener("keydown", (evt) => {
59
+ var _a;
60
+ if (evt.key === "Escape") {
61
+ // Only allow hiding if not persistently visible
62
+ if (!this.persistentlyVisible) {
63
+ this.hide();
64
+ }
65
+ else {
66
+ // Just blur the input if persistently visible
67
+ (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.blur();
68
+ }
69
+ }
70
+ else if (evt.key === "Enter") {
71
+ this.applyFilterImmediately();
72
+ }
73
+ });
74
+ }
75
+ handleInputChange() {
76
+ if (this.debounceTimer !== null) {
77
+ window.clearTimeout(this.debounceTimer);
78
+ }
79
+ this.debounceTimer = window.setTimeout(() => {
80
+ this.applyFilterImmediately();
81
+ }, this.debounceMs);
82
+ }
83
+ applyFilterImmediately() {
84
+ var _a, _b;
85
+ const newValue = (_b = (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.value.trim()) !== null && _b !== void 0 ? _b : "";
86
+ if (newValue !== this.currentValue) {
87
+ this.updateFilterValue(newValue);
88
+ }
89
+ }
90
+ updateFilterValue(value) {
91
+ this.currentValue = value;
92
+ this.onFilterChange(value);
93
+ }
94
+ getCurrentValue() {
95
+ return this.currentValue;
96
+ }
97
+ show() {
98
+ var _a;
99
+ this.containerEl.removeClass(`${this.cssPrefix}-hidden`);
100
+ (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.focus();
101
+ }
102
+ hide() {
103
+ var _a;
104
+ // Don't allow hiding if persistently visible
105
+ if (this.persistentlyVisible) {
106
+ return;
107
+ }
108
+ this.containerEl.addClass(`${this.cssPrefix}-hidden`);
109
+ if (this.inputEl) {
110
+ this.inputEl.value = "";
111
+ }
112
+ this.updateFilterValue("");
113
+ (_a = this.onHide) === null || _a === void 0 ? void 0 : _a.call(this);
114
+ }
115
+ focus() {
116
+ var _a;
117
+ (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.focus();
118
+ }
119
+ isVisible() {
120
+ return !this.containerEl.hasClass(`${this.cssPrefix}-hidden`);
121
+ }
122
+ setPersistentlyVisible(value) {
123
+ this.persistentlyVisible = value;
124
+ if (value) {
125
+ this.show();
126
+ }
127
+ else {
128
+ this.hide();
129
+ }
130
+ }
131
+ destroy() {
132
+ if (this.debounceTimer !== null) {
133
+ window.clearTimeout(this.debounceTimer);
134
+ this.debounceTimer = null;
135
+ }
136
+ this.containerEl.remove();
137
+ this.inputEl = null;
138
+ }
139
+ }
140
+ //# sourceMappingURL=input-filter-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-filter-manager.js","sourceRoot":"","sources":["../../src/inputs/input-filter-manager.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAYhC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAgB,kBAAkB;IAavC,YACW,QAAqB,EAC/B,OAAkC;QADxB,aAAQ,GAAR,QAAQ,CAAa;QAZtB,YAAO,GAA4B,IAAI,CAAC;QACxC,kBAAa,GAAkB,IAAI,CAAC;QACpC,iBAAY,GAAG,EAAE,CAAC;QAClB,wBAAmB,GAAG,KAAK,CAAC;QAYrC,MAAM,EACL,WAAW,EACX,QAAQ,EACR,SAAS,EACT,cAAc,EACd,gBAAgB,GAAG,KAAK,EACxB,MAAM,EACN,UAAU,GAAG,mBAAmB,GAChC,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,MAAM,OAAO,GAAG,GAAG,QAAQ,aAAa,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,SAAS,EAAE,CAAC;QACzF,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE;YAChD,GAAG,EAAE,OAAO;SACZ,CAAC,CAAC;QAEH,IAAI,CAAC,M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,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO;QACN,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACjC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACxC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,CAAC;CAUD","sourcesContent":["export type FilterChangeCallback = (filterValue: string) => void;\n\nconst DEFAULT_DEBOUNCE_MS = 150;\n\nexport interface InputFilterManagerOptions {\n\tplaceholder: string;\n\tcssClass: string;\n\tcssPrefix: string;\n\tonFilterChange: FilterChangeCallback;\n\tinitiallyVisible?: boolean;\n\tonHide?: () => void;\n\tdebounceMs?: number;\n}\n\n/**\n * Abstract base class for managing input-based filters with debouncing.\n * Provides a reusable pattern for filter inputs with show/hide functionality,\n * keyboard shortcuts, and debounced updates.\n *\n * @template T - The type of data being filtered (optional, defaults to unknown)\n *\n * @example\n * ```ts\n * class MyFilterManager extends InputFilterManager<MyDataType> {\n * shouldInclude(data: MyDataType): boolean {\n * const filter = this.getCurrentValue().toLowerCase();\n * return data.name.toLowerCase().includes(filter);\n * }\n * }\n *\n * const manager = new MyFilterManager(\n * containerEl,\n * {\n * placeholder: \"Filter items...\",\n * cssClass: \"my-filter-input\",\n * onFilterChange: (value) => console.log(\"Filter changed:\", value),\n * initiallyVisible: false,\n * }\n * );\n * ```\n */\nexport abstract class InputFilterManager<T> {\n\tprotected containerEl: HTMLElement;\n\tprotected inputEl: HTMLInputElement | null = null;\n\tprotected debounceTimer: number | null = null;\n\tprotected currentValue = \"\";\n\tprotected persistentlyVisible = false;\n\tprotected onHide?: () => void;\n\tprotected readonly debounceMs: number;\n\tprotected readonly placeholder: string;\n\tprotected readonly cssClass: string;\n\tprotected readonly cssPrefix: string;\n\tprotected readonly onFilterChange: FilterChangeCallback;\n\n\tconstructor(\n\t\tprotected parentEl: HTMLElement,\n\t\toptions: InputFilterManagerOptions\n\t) {\n\t\tconst {\n\t\t\tplaceholder,\n\t\t\tcssClass,\n\t\t\tcssPrefix,\n\t\t\tonFilterChange,\n\t\t\tinitiallyVisible = false,\n\t\t\tonHide,\n\t\t\tdebounceMs = DEFAULT_DEBOUNCE_MS,\n\t\t} = options;\n\n\t\tthis.debounceMs = debounceMs;\n\t\tthis.placeholder = placeholder;\n\t\tthis.cssClass = cssClass;\n\t\tthis.cssPrefix = cssPrefix;\n\t\tthis.onFilterChange = onFilterChange;\n\t\tthis.onHide = onHide;\n\n\t\tconst classes = `${cssClass}-container${initiallyVisible ? \"\" : ` ${cssPrefix}-hidden`}`;\n\t\tthis.containerEl = this.parentEl.createEl(\"div\", {\n\t\t\tcls: classes,\n\t\t});\n\n\t\tthis.render();\n\t}\n\n\tprivate render(): void {\n\t\tthis.inputEl = this.containerEl.createEl(\"input\", {\n\t\t\ttype: \"text\",\n\t\t\tcls: this.cssClass,\n\t\t\tplaceholder: this.placeholder,\n\t\t});\n\n\t\tthis.inputEl.addEventListener(\"input\", () => {\n\t\t\tthis.handleInputChange();\n\t\t});\n\n\t\tthis.inputEl.addEventListener(\"keydown\", (evt) => {\n\t\t\tif (evt.key === \"Escape\") {\n\t\t\t\t// Only allow hiding if not persistently visible\n\t\t\t\tif (!this.persistentlyVisible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\t// Just blur the input if persistently visible\n\t\t\t\t\tthis.inputEl?.blur();\n\t\t\t\t}\n\t\t\t} else if (evt.key === \"Enter\") {\n\t\t\t\tthis.applyFilterImmediately();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate handleInputChange(): void {\n\t\tif (this.debounceTimer !== null) {\n\t\t\twindow.clearTimeout(this.debounceTimer);\n\t\t}\n\n\t\tthis.debounceTimer = window.setTimeout(() => {\n\t\t\tthis.applyFilterImmediately();\n\t\t}, this.debounceMs);\n\t}\n\n\tprivate applyFilterImmediately(): void {\n\t\tconst newValue = this.inputEl?.value.trim() ?? \"\";\n\n\t\tif (newValue !== this.currentValue) {\n\t\t\tthis.updateFilterValue(newValue);\n\t\t}\n\t}\n\n\tprotected updateFilterValue(value: string): void {\n\t\tthis.currentValue = value;\n\t\tthis.onFilterChange(value);\n\t}\n\n\tgetCurrentValue(): string {\n\t\treturn this.currentValue;\n\t}\n\n\tshow(): void {\n\t\tthis.containerEl.removeClass(`${this.cssPrefix}-hidden`);\n\t\tthis.inputEl?.focus();\n\t}\n\n\thide(): void {\n\t\t// Don't allow hiding if persistently visible\n\t\tif (this.persistentlyVisible) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.containerEl.addClass(`${this.cssPrefix}-hidden`);\n\n\t\tif (this.inputEl) {\n\t\t\tthis.inputEl.value = \"\";\n\t\t}\n\n\t\tthis.updateFilterValue(\"\");\n\t\tthis.onHide?.();\n\t}\n\n\tfocus(): void {\n\t\tthis.inputEl?.focus();\n\t}\n\n\tisVisible(): boolean {\n\t\treturn !this.containerEl.hasClass(`${this.cssPrefix}-hidden`);\n\t}\n\n\tsetPersistentlyVisible(value: boolean): void {\n\t\tthis.persistentlyVisible = value;\n\n\t\tif (value) {\n\t\t\tthis.show();\n\t\t} else {\n\t\t\tthis.hide();\n\t\t}\n\t}\n\n\tdestroy(): void {\n\t\tif (this.debounceTimer !== null) {\n\t\t\twindow.clearTimeout(this.debounceTimer);\n\t\t\tthis.debounceTimer = null;\n\t\t}\n\n\t\tthis.containerEl.remove();\n\t\tthis.inputEl = null;\n\t}\n\n\t/**\n\t * Abstract method that subclasses must implement to determine\n\t * whether a data item should be included based on the current filter.\n\t *\n\t * @param data - The data item to check\n\t * @returns True if the item should be included, false otherwise\n\t */\n\tabstract shouldInclude(data: T): boolean;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real1ty-obsidian-plugins/utils",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "Shared utilities for Obsidian plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/luxon": "^3.7.1",
47
+ "fast-check": "^4.3.0",
47
48
  "typescript": "5.9.2",
48
49
  "vitest": "^2.0.5"
49
50
  },
@@ -1,5 +1,3 @@
1
- import type { BehaviorSubject } from "rxjs";
2
-
3
1
  import { BaseEvaluator, type BaseRule } from "./base";
4
2
 
5
3
  export interface FilterRule extends BaseRule {}