@real1ty-obsidian-plugins/utils 2.3.0 → 2.5.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/dist/core/evaluator/base.d.ts +22 -0
- package/dist/core/evaluator/base.d.ts.map +1 -0
- package/dist/core/evaluator/base.js +52 -0
- package/dist/core/evaluator/base.js.map +1 -0
- package/dist/core/evaluator/color.d.ts +19 -0
- package/dist/core/evaluator/color.d.ts.map +1 -0
- package/dist/core/evaluator/color.js +25 -0
- package/dist/core/evaluator/color.js.map +1 -0
- package/dist/core/evaluator/excluded.d.ts +32 -0
- package/dist/core/evaluator/excluded.d.ts.map +1 -0
- package/dist/core/evaluator/excluded.js +41 -0
- package/dist/core/evaluator/excluded.js.map +1 -0
- package/dist/core/evaluator/filter.d.ts +15 -0
- package/dist/core/evaluator/filter.d.ts.map +1 -0
- package/dist/core/evaluator/filter.js +27 -0
- package/dist/core/evaluator/filter.js.map +1 -0
- package/dist/core/evaluator/included.d.ts +36 -0
- package/dist/core/evaluator/included.d.ts.map +1 -0
- package/dist/core/evaluator/included.js +51 -0
- package/dist/core/evaluator/included.js.map +1 -0
- package/dist/core/evaluator/index.d.ts +6 -0
- package/dist/core/evaluator/index.d.ts.map +1 -0
- package/dist/core/evaluator/index.js +6 -0
- package/dist/core/evaluator/index.js.map +1 -0
- package/dist/core/expression-utils.d.ts +17 -0
- package/dist/core/expression-utils.d.ts.map +1 -0
- package/dist/core/expression-utils.js +40 -0
- package/dist/core/expression-utils.js.map +1 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.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 +71 -0
- package/src/core/evaluator/color.ts +37 -0
- package/src/core/evaluator/excluded.ts +63 -0
- package/src/core/evaluator/filter.ts +35 -0
- package/src/core/evaluator/included.ts +74 -0
- package/src/core/evaluator/index.ts +5 -0
- package/src/core/expression-utils.ts +53 -0
- package/src/core/generate.ts +22 -0
- package/src/core/index.ts +3 -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/core/evaluator-base.d.ts +0 -52
- package/dist/core/evaluator-base.d.ts.map +0 -1
- package/dist/core/evaluator-base.js +0 -84
- package/dist/core/evaluator-base.js.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BehaviorSubject } from "rxjs";
|
|
2
|
+
export interface BaseRule {
|
|
3
|
+
id: string;
|
|
4
|
+
expression: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Generic base class for evaluating JavaScript expressions against frontmatter objects.
|
|
9
|
+
* Provides reactive compilation of rules via RxJS subscription and safe evaluation.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseEvaluator<TRule extends BaseRule, TSettings> {
|
|
12
|
+
protected rules: TRule[];
|
|
13
|
+
private compiledFunctions;
|
|
14
|
+
private propertyMapping;
|
|
15
|
+
private subscription;
|
|
16
|
+
constructor(settingsStore: BehaviorSubject<TSettings>);
|
|
17
|
+
protected abstract extractRules(settings: TSettings): TRule[];
|
|
18
|
+
destroy(): void;
|
|
19
|
+
protected evaluateRule(rule: TRule, frontmatter: Record<string, unknown>): boolean;
|
|
20
|
+
protected isTruthy(value: any): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,MAAM,CAAC;AAI1D,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,8BAAsB,aAAa,CAAC,KAAK,SAAS,QAAQ,EAAE,SAAS;IACpE,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,CAAM;IAC9B,OAAO,CAAC,iBAAiB,CAA2D;IACpF,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,YAAY,CAA6B;gBAErC,aAAa,EAAE,eAAe,CAAC,SAAS,CAAC;IAQrD,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,KAAK,EAAE;IAE7D,OAAO,IAAI,IAAI;IAMf,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;IA+BlF,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;CAGvC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { buildPropertyMapping, sanitizeExpression } from "../expression-utils";
|
|
2
|
+
/**
|
|
3
|
+
* Generic base class for evaluating JavaScript expressions against frontmatter objects.
|
|
4
|
+
* Provides reactive compilation of rules via RxJS subscription and safe evaluation.
|
|
5
|
+
*/
|
|
6
|
+
export class BaseEvaluator {
|
|
7
|
+
constructor(settingsStore) {
|
|
8
|
+
this.rules = [];
|
|
9
|
+
this.compiledFunctions = new Map();
|
|
10
|
+
this.propertyMapping = new Map();
|
|
11
|
+
this.subscription = null;
|
|
12
|
+
this.subscription = settingsStore.subscribe((settings) => {
|
|
13
|
+
this.rules = this.extractRules(settings);
|
|
14
|
+
this.compiledFunctions.clear();
|
|
15
|
+
this.propertyMapping.clear();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
destroy() {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
21
|
+
this.compiledFunctions.clear();
|
|
22
|
+
this.propertyMapping.clear();
|
|
23
|
+
}
|
|
24
|
+
evaluateRule(rule, frontmatter) {
|
|
25
|
+
if (!rule.enabled || !rule.expression) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
if (this.propertyMapping.size === 0) {
|
|
30
|
+
this.propertyMapping = buildPropertyMapping(Object.keys(frontmatter));
|
|
31
|
+
}
|
|
32
|
+
let compiledFunc = this.compiledFunctions.get(rule.id);
|
|
33
|
+
if (!compiledFunc) {
|
|
34
|
+
const sanitized = sanitizeExpression(rule.expression, this.propertyMapping);
|
|
35
|
+
const params = Array.from(this.propertyMapping.values());
|
|
36
|
+
compiledFunc = new Function(...params, `"use strict"; return ${sanitized};`);
|
|
37
|
+
this.compiledFunctions.set(rule.id, compiledFunc);
|
|
38
|
+
}
|
|
39
|
+
const values = Array.from(this.propertyMapping.keys()).map((key) => frontmatter[key]);
|
|
40
|
+
const result = compiledFunc(...values);
|
|
41
|
+
return result === true;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.warn(`Invalid expression (${rule.id}):`, rule.expression, error);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
isTruthy(value) {
|
|
49
|
+
return value === true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/core/evaluator/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAQ/E;;;GAGG;AACH,MAAM,OAAgB,aAAa;IAMlC,YAAY,aAAyC;QAL3C,UAAK,GAAY,EAAE,CAAC;QACtB,sBAAiB,GAAG,IAAI,GAAG,EAAgD,CAAC;QAC5E,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,iBAAY,GAAwB,IAAI,CAAC;QAGhD,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YACxD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YACzC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACJ,CAAC;IAID,OAAO;;QACN,MAAA,IAAI,CAAC,YAAY,0CAAE,WAAW,EAAE,CAAC;QACjC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAES,YAAY,CAAC,IAAW,EAAE,WAAoC;QACvE,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACJ,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,eAAe,GAAG,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YACvE,CAAC;YAED,IAAI,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAEvD,IAAI,CAAC,YAAY,EAAE,CAAC;gBACnB,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC5E,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;gBACzD,YAAY,GAAG,IAAI,QAAQ,CAAC,GAAG,MAAM,EAAE,wBAAwB,SAAS,GAAG,CAE/D,CAAC;gBACb,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;YACnD,CAAC;YAED,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YACtF,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,MAAM,CAAC,CAAC;YAEvC,OAAO,MAAM,KAAK,IAAI,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YACzE,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAES,QAAQ,CAAC,KAAU;QAC5B,OAAO,KAAK,KAAK,IAAI,CAAC;IACvB,CAAC;CACD","sourcesContent":["import type { BehaviorSubject, Subscription } from \"rxjs\";\n\nimport { buildPropertyMapping, sanitizeExpression } from \"../expression-utils\";\n\nexport interface BaseRule {\n\tid: string;\n\texpression: string;\n\tenabled: boolean;\n}\n\n/**\n * Generic base class for evaluating JavaScript expressions against frontmatter objects.\n * Provides reactive compilation of rules via RxJS subscription and safe evaluation.\n */\nexport abstract class BaseEvaluator<TRule extends BaseRule, TSettings> {\n\tprotected rules: TRule[] = [];\n\tprivate compiledFunctions = new Map<string, ((...args: any[]) => boolean) | null>();\n\tprivate propertyMapping = new Map<string, string>();\n\tprivate subscription: Subscription | null = null;\n\n\tconstructor(settingsStore: BehaviorSubject<TSettings>) {\n\t\tthis.subscription = settingsStore.subscribe((settings) => {\n\t\t\tthis.rules = this.extractRules(settings);\n\t\t\tthis.compiledFunctions.clear();\n\t\t\tthis.propertyMapping.clear();\n\t\t});\n\t}\n\n\tprotected abstract extractRules(settings: TSettings): TRule[];\n\n\tdestroy(): void {\n\t\tthis.subscription?.unsubscribe();\n\t\tthis.compiledFunctions.clear();\n\t\tthis.propertyMapping.clear();\n\t}\n\n\tprotected evaluateRule(rule: TRule, frontmatter: Record<string, unknown>): boolean {\n\t\tif (!rule.enabled || !rule.expression) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tif (this.propertyMapping.size === 0) {\n\t\t\t\tthis.propertyMapping = buildPropertyMapping(Object.keys(frontmatter));\n\t\t\t}\n\n\t\t\tlet compiledFunc = this.compiledFunctions.get(rule.id);\n\n\t\t\tif (!compiledFunc) {\n\t\t\t\tconst sanitized = sanitizeExpression(rule.expression, this.propertyMapping);\n\t\t\t\tconst params = Array.from(this.propertyMapping.values());\n\t\t\t\tcompiledFunc = new Function(...params, `\"use strict\"; return ${sanitized};`) as (\n\t\t\t\t\t...args: any[]\n\t\t\t\t) => boolean;\n\t\t\t\tthis.compiledFunctions.set(rule.id, compiledFunc);\n\t\t\t}\n\n\t\t\tconst values = Array.from(this.propertyMapping.keys()).map((key) => frontmatter[key]);\n\t\t\tconst result = compiledFunc(...values);\n\n\t\t\treturn result === true;\n\t\t} catch (error) {\n\t\t\tconsole.warn(`Invalid expression (${rule.id}):`, rule.expression, error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprotected isTruthy(value: any): boolean {\n\t\treturn value === true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { BaseEvaluator, type BaseRule } from "./base";
|
|
3
|
+
export interface ColorRule extends BaseRule {
|
|
4
|
+
color: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generic evaluator for determining colors based on frontmatter rules.
|
|
8
|
+
* Extends BaseEvaluator to evaluate color rules against frontmatter.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ColorEvaluator<TSettings extends {
|
|
11
|
+
defaultNodeColor: string;
|
|
12
|
+
colorRules: ColorRule[];
|
|
13
|
+
}> extends BaseEvaluator<ColorRule, TSettings> {
|
|
14
|
+
private defaultColor;
|
|
15
|
+
constructor(settingsStore: BehaviorSubject<TSettings>);
|
|
16
|
+
protected extractRules(settings: TSettings): ColorRule[];
|
|
17
|
+
evaluateColor(frontmatter: Record<string, unknown>): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtD,MAAM,WAAW,SAAU,SAAQ,QAAQ;IAC1C,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,qBAAa,cAAc,CAC1B,SAAS,SAAS;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CACtE,SAAQ,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC;IAC5C,OAAO,CAAC,YAAY,CAAS;gBAEjB,aAAa,EAAE,eAAe,CAAC,SAAS,CAAC;IAWrD,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE;IAIxD,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAI3D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseEvaluator } from "./base";
|
|
2
|
+
/**
|
|
3
|
+
* Generic evaluator for determining colors based on frontmatter rules.
|
|
4
|
+
* Extends BaseEvaluator to evaluate color rules against frontmatter.
|
|
5
|
+
*/
|
|
6
|
+
export class ColorEvaluator extends BaseEvaluator {
|
|
7
|
+
constructor(settingsStore) {
|
|
8
|
+
super(settingsStore);
|
|
9
|
+
this.defaultColor = settingsStore.value.defaultNodeColor;
|
|
10
|
+
settingsStore.subscribe((settings) => {
|
|
11
|
+
if (settings.defaultNodeColor) {
|
|
12
|
+
this.defaultColor = settings.defaultNodeColor;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
extractRules(settings) {
|
|
17
|
+
return settings.colorRules;
|
|
18
|
+
}
|
|
19
|
+
evaluateColor(frontmatter) {
|
|
20
|
+
var _a;
|
|
21
|
+
const match = this.rules.find((rule) => this.isTruthy(this.evaluateRule(rule, frontmatter)));
|
|
22
|
+
return (_a = match === null || match === void 0 ? void 0 : match.color) !== null && _a !== void 0 ? _a : this.defaultColor;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/core/evaluator/color.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAiB,MAAM,QAAQ,CAAC;AAMtD;;;GAGG;AACH,MAAM,OAAO,cAEX,SAAQ,aAAmC;IAG5C,YAAY,aAAyC;QACpD,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,gBAAgB,CAAC;QAEzD,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YACpC,IAAI,QAAQ,CAAC,gBAAgB,EAAE,CAAC;gBAC/B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC;YAC/C,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,QAAmB;QACzC,OAAO,QAAQ,CAAC,UAAU,CAAC;IAC5B,CAAC;IAED,aAAa,CAAC,WAAoC;;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7F,OAAO,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,mCAAI,IAAI,CAAC,YAAY,CAAC;IAC1C,CAAC;CACD","sourcesContent":["import type { BehaviorSubject } from \"rxjs\";\n\nimport { BaseEvaluator, type BaseRule } from \"./base\";\n\nexport interface ColorRule extends BaseRule {\n\tcolor: string;\n}\n\n/**\n * Generic evaluator for determining colors based on frontmatter rules.\n * Extends BaseEvaluator to evaluate color rules against frontmatter.\n */\nexport class ColorEvaluator<\n\tTSettings extends { defaultNodeColor: string; colorRules: ColorRule[] },\n> extends BaseEvaluator<ColorRule, TSettings> {\n\tprivate defaultColor: string;\n\n\tconstructor(settingsStore: BehaviorSubject<TSettings>) {\n\t\tsuper(settingsStore);\n\t\tthis.defaultColor = settingsStore.value.defaultNodeColor;\n\n\t\tsettingsStore.subscribe((settings) => {\n\t\t\tif (settings.defaultNodeColor) {\n\t\t\t\tthis.defaultColor = settings.defaultNodeColor;\n\t\t\t}\n\t\t});\n\t}\n\n\tprotected extractRules(settings: TSettings): ColorRule[] {\n\t\treturn settings.colorRules;\n\t}\n\n\tevaluateColor(frontmatter: Record<string, unknown>): string {\n\t\tconst match = this.rules.find((rule) => this.isTruthy(this.evaluateRule(rule, frontmatter)));\n\t\treturn match?.color ?? this.defaultColor;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BehaviorSubject } from "rxjs";
|
|
2
|
+
export interface PathExcludedProperties {
|
|
3
|
+
id: string;
|
|
4
|
+
path: string;
|
|
5
|
+
excludedProperties: string[];
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generic evaluator for determining which frontmatter properties to exclude when creating new nodes.
|
|
10
|
+
*
|
|
11
|
+
* Logic:
|
|
12
|
+
* 1. ALWAYS includes the default excluded properties (e.g., Parent, Child, Related, _ZettelID)
|
|
13
|
+
* 2. Checks if the source file's path matches any path-based exclusion rules
|
|
14
|
+
* 3. First matching path rule's properties are ADDED to the default exclusion list
|
|
15
|
+
* 4. Returns the combined set of excluded properties
|
|
16
|
+
*/
|
|
17
|
+
export declare class ExcludedPropertiesEvaluator<TSettings extends {
|
|
18
|
+
defaultExcludedProperties: string[];
|
|
19
|
+
pathExcludedProperties: PathExcludedProperties[];
|
|
20
|
+
}> {
|
|
21
|
+
private defaultExcludedProperties;
|
|
22
|
+
private pathRules;
|
|
23
|
+
constructor(settingsObservable: BehaviorSubject<TSettings>);
|
|
24
|
+
/**
|
|
25
|
+
* Evaluate which properties should be excluded for a given file path.
|
|
26
|
+
*
|
|
27
|
+
* @param filePath - The file path to match against path rules
|
|
28
|
+
* @returns Array of property names to exclude (always includes defaults + path rule matches)
|
|
29
|
+
*/
|
|
30
|
+
evaluateExcludedProperties(filePath: string): string[];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=excluded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excluded.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/excluded.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,qBAAa,2BAA2B,CACvC,SAAS,SAAS;IACjB,yBAAyB,EAAE,MAAM,EAAE,CAAC;IACpC,sBAAsB,EAAE,sBAAsB,EAAE,CAAC;CACjD;IAED,OAAO,CAAC,yBAAyB,CAAW;IAE5C,OAAO,CAAC,SAAS,CAA2B;gBAEhC,kBAAkB,EAAE,eAAe,CAAC,SAAS,CAAC;IAU1D;;;;;OAKG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;CAkBtD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic evaluator for determining which frontmatter properties to exclude when creating new nodes.
|
|
3
|
+
*
|
|
4
|
+
* Logic:
|
|
5
|
+
* 1. ALWAYS includes the default excluded properties (e.g., Parent, Child, Related, _ZettelID)
|
|
6
|
+
* 2. Checks if the source file's path matches any path-based exclusion rules
|
|
7
|
+
* 3. First matching path rule's properties are ADDED to the default exclusion list
|
|
8
|
+
* 4. Returns the combined set of excluded properties
|
|
9
|
+
*/
|
|
10
|
+
export class ExcludedPropertiesEvaluator {
|
|
11
|
+
constructor(settingsObservable) {
|
|
12
|
+
const assignSettings = (settings) => {
|
|
13
|
+
this.defaultExcludedProperties = settings.defaultExcludedProperties;
|
|
14
|
+
this.pathRules = settings.pathExcludedProperties.filter((rule) => rule.enabled);
|
|
15
|
+
};
|
|
16
|
+
assignSettings(settingsObservable.value);
|
|
17
|
+
settingsObservable.subscribe(assignSettings);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate which properties should be excluded for a given file path.
|
|
21
|
+
*
|
|
22
|
+
* @param filePath - The file path to match against path rules
|
|
23
|
+
* @returns Array of property names to exclude (always includes defaults + path rule matches)
|
|
24
|
+
*/
|
|
25
|
+
evaluateExcludedProperties(filePath) {
|
|
26
|
+
// Always start with default excluded properties
|
|
27
|
+
const excludedProperties = [...this.defaultExcludedProperties];
|
|
28
|
+
// Find first matching path rule and add its excluded properties
|
|
29
|
+
const match = this.pathRules.find((rule) => filePath.startsWith(rule.path));
|
|
30
|
+
if (match) {
|
|
31
|
+
// Add path-specific excluded properties to the defaults
|
|
32
|
+
for (const prop of match.excludedProperties) {
|
|
33
|
+
if (!excludedProperties.includes(prop)) {
|
|
34
|
+
excludedProperties.push(prop);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return excludedProperties;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=excluded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excluded.js","sourceRoot":"","sources":["../../../src/core/evaluator/excluded.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,MAAM,OAAO,2BAA2B;IAUvC,YAAY,kBAA8C;QACzD,MAAM,cAAc,GAAG,CAAC,QAAmB,EAAE,EAAE;YAC9C,IAAI,CAAC,yBAAyB,GAAG,QAAQ,CAAC,yBAAyB,CAAC;YACpE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjF,CAAC,CAAC;QAEF,cAAc,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACzC,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,0BAA0B,CAAC,QAAgB;QAC1C,gDAAgD;QAChD,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC,yBAAyB,CAAC,CAAC;QAE/D,gEAAgE;QAChE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE5E,IAAI,KAAK,EAAE,CAAC;YACX,wDAAwD;YACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,kBAAkB,EAAE,CAAC;gBAC7C,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,kBAAkB,CAAC;IAC3B,CAAC;CACD","sourcesContent":["import type { BehaviorSubject } from \"rxjs\";\n\nexport interface PathExcludedProperties {\n\tid: string;\n\tpath: string;\n\texcludedProperties: string[];\n\tenabled: boolean;\n}\n\n/**\n * Generic evaluator for determining which frontmatter properties to exclude when creating new nodes.\n *\n * Logic:\n * 1. ALWAYS includes the default excluded properties (e.g., Parent, Child, Related, _ZettelID)\n * 2. Checks if the source file's path matches any path-based exclusion rules\n * 3. First matching path rule's properties are ADDED to the default exclusion list\n * 4. Returns the combined set of excluded properties\n */\nexport class ExcludedPropertiesEvaluator<\n\tTSettings extends {\n\t\tdefaultExcludedProperties: string[];\n\t\tpathExcludedProperties: PathExcludedProperties[];\n\t},\n> {\n\tprivate defaultExcludedProperties: string[];\n\n\tprivate pathRules: PathExcludedProperties[];\n\n\tconstructor(settingsObservable: BehaviorSubject<TSettings>) {\n\t\tconst assignSettings = (settings: TSettings) => {\n\t\t\tthis.defaultExcludedProperties = settings.defaultExcludedProperties;\n\t\t\tthis.pathRules = settings.pathExcludedProperties.filter((rule) => rule.enabled);\n\t\t};\n\n\t\tassignSettings(settingsObservable.value);\n\t\tsettingsObservable.subscribe(assignSettings);\n\t}\n\n\t/**\n\t * Evaluate which properties should be excluded for a given file path.\n\t *\n\t * @param filePath - The file path to match against path rules\n\t * @returns Array of property names to exclude (always includes defaults + path rule matches)\n\t */\n\tevaluateExcludedProperties(filePath: string): string[] {\n\t\t// Always start with default excluded properties\n\t\tconst excludedProperties = [...this.defaultExcludedProperties];\n\n\t\t// Find first matching path rule and add its excluded properties\n\t\tconst match = this.pathRules.find((rule) => filePath.startsWith(rule.path));\n\n\t\tif (match) {\n\t\t\t// Add path-specific excluded properties to the defaults\n\t\t\tfor (const prop of match.excludedProperties) {\n\t\t\t\tif (!excludedProperties.includes(prop)) {\n\t\t\t\t\texcludedProperties.push(prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn excludedProperties;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseEvaluator, type BaseRule } from "./base";
|
|
2
|
+
export interface FilterRule extends BaseRule {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Generic evaluator for filtering based on frontmatter expressions.
|
|
6
|
+
* Extends BaseEvaluator to evaluate filter rules against frontmatter.
|
|
7
|
+
* Returns true only if ALL rules evaluate to true.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FilterEvaluator<TSettings extends {
|
|
10
|
+
filterExpressions: string[];
|
|
11
|
+
}> extends BaseEvaluator<FilterRule, TSettings> {
|
|
12
|
+
protected extractRules(settings: TSettings): FilterRule[];
|
|
13
|
+
evaluateFilters(frontmatter: Record<string, unknown>): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtD,MAAM,WAAW,UAAW,SAAQ,QAAQ;CAAG;AAE/C;;;;GAIG;AACH,qBAAa,eAAe,CAC3B,SAAS,SAAS;IAAE,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAAE,CAChD,SAAQ,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC;IAC7C,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,UAAU,EAAE;IAQzD,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;CAY9D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseEvaluator } from "./base";
|
|
2
|
+
/**
|
|
3
|
+
* Generic evaluator for filtering based on frontmatter expressions.
|
|
4
|
+
* Extends BaseEvaluator to evaluate filter rules against frontmatter.
|
|
5
|
+
* Returns true only if ALL rules evaluate to true.
|
|
6
|
+
*/
|
|
7
|
+
export class FilterEvaluator extends BaseEvaluator {
|
|
8
|
+
extractRules(settings) {
|
|
9
|
+
return settings.filterExpressions.map((expression, index) => ({
|
|
10
|
+
id: `filter-${index}`,
|
|
11
|
+
expression: expression.trim(),
|
|
12
|
+
enabled: true,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
evaluateFilters(frontmatter) {
|
|
16
|
+
if (this.rules.length === 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return this.rules.every((rule) => {
|
|
20
|
+
if (!rule.enabled || !rule.expression) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return this.evaluateRule(rule, frontmatter);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/core/evaluator/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAiB,MAAM,QAAQ,CAAC;AAItD;;;;GAIG;AACH,MAAM,OAAO,eAEX,SAAQ,aAAoC;IACnC,YAAY,CAAC,QAAmB;QACzC,OAAO,QAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YAC7D,EAAE,EAAE,UAAU,KAAK,EAAE;YACrB,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE;YAC7B,OAAO,EAAE,IAAI;SACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,WAAoC;QACnD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YACb,CAAC;YACD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { BehaviorSubject } from \"rxjs\";\n\nimport { BaseEvaluator, type BaseRule } from \"./base\";\n\nexport interface FilterRule extends BaseRule {}\n\n/**\n * Generic evaluator for filtering based on frontmatter expressions.\n * Extends BaseEvaluator to evaluate filter rules against frontmatter.\n * Returns true only if ALL rules evaluate to true.\n */\nexport class FilterEvaluator<\n\tTSettings extends { filterExpressions: string[] },\n> extends BaseEvaluator<FilterRule, TSettings> {\n\tprotected extractRules(settings: TSettings): FilterRule[] {\n\t\treturn settings.filterExpressions.map((expression, index) => ({\n\t\t\tid: `filter-${index}`,\n\t\t\texpression: expression.trim(),\n\t\t\tenabled: true,\n\t\t}));\n\t}\n\n\tevaluateFilters(frontmatter: Record<string, unknown>): boolean {\n\t\tif (this.rules.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn this.rules.every((rule) => {\n\t\t\tif (!rule.enabled || !rule.expression) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn this.evaluateRule(rule, frontmatter);\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BehaviorSubject } from "rxjs";
|
|
2
|
+
export interface PathIncludedProperties {
|
|
3
|
+
id: string;
|
|
4
|
+
path: string;
|
|
5
|
+
includedProperties: string[];
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generic evaluator for determining which properties to include in Bases view columns.
|
|
10
|
+
*
|
|
11
|
+
* Logic:
|
|
12
|
+
* 1. ALWAYS includes the default included properties
|
|
13
|
+
* 2. Checks if the file's path matches any path-based inclusion rules
|
|
14
|
+
* 3. First matching path rule's properties are ADDED to the default inclusion list
|
|
15
|
+
* 4. Returns the combined set of included properties in order:
|
|
16
|
+
* - file.name (always first)
|
|
17
|
+
* - default included properties (in specified order)
|
|
18
|
+
* - path-specific included properties (in specified order)
|
|
19
|
+
*/
|
|
20
|
+
export declare class IncludedPropertiesEvaluator<TSettings extends {
|
|
21
|
+
defaultBasesIncludedProperties: string[];
|
|
22
|
+
pathBasesIncludedProperties: PathIncludedProperties[];
|
|
23
|
+
}> {
|
|
24
|
+
private defaultIncludedProperties;
|
|
25
|
+
private pathRules;
|
|
26
|
+
constructor(settingsObservable: BehaviorSubject<TSettings>);
|
|
27
|
+
/**
|
|
28
|
+
* Evaluate which properties should be included in the order array for a given file path.
|
|
29
|
+
* Returns an array with "file.name" as the first element, followed by default and path-specific properties.
|
|
30
|
+
*
|
|
31
|
+
* @param filePath - The file path to match against path rules
|
|
32
|
+
* @returns Array of property names to include in the order (file.name + defaults + path rule matches)
|
|
33
|
+
*/
|
|
34
|
+
evaluateIncludedProperties(filePath: string): string[];
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=included.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"included.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/included.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,2BAA2B,CACvC,SAAS,SAAS;IACjB,8BAA8B,EAAE,MAAM,EAAE,CAAC;IACzC,2BAA2B,EAAE,sBAAsB,EAAE,CAAC;CACtD;IAED,OAAO,CAAC,yBAAyB,CAAW;IAE5C,OAAO,CAAC,SAAS,CAA2B;gBAEhC,kBAAkB,EAAE,eAAe,CAAC,SAAS,CAAC;IAU1D;;;;;;OAMG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;CAyBtD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic evaluator for determining which properties to include in Bases view columns.
|
|
3
|
+
*
|
|
4
|
+
* Logic:
|
|
5
|
+
* 1. ALWAYS includes the default included properties
|
|
6
|
+
* 2. Checks if the file's path matches any path-based inclusion rules
|
|
7
|
+
* 3. First matching path rule's properties are ADDED to the default inclusion list
|
|
8
|
+
* 4. Returns the combined set of included properties in order:
|
|
9
|
+
* - file.name (always first)
|
|
10
|
+
* - default included properties (in specified order)
|
|
11
|
+
* - path-specific included properties (in specified order)
|
|
12
|
+
*/
|
|
13
|
+
export class IncludedPropertiesEvaluator {
|
|
14
|
+
constructor(settingsObservable) {
|
|
15
|
+
const assignSettings = (settings) => {
|
|
16
|
+
this.defaultIncludedProperties = settings.defaultBasesIncludedProperties;
|
|
17
|
+
this.pathRules = settings.pathBasesIncludedProperties.filter((rule) => rule.enabled);
|
|
18
|
+
};
|
|
19
|
+
assignSettings(settingsObservable.value);
|
|
20
|
+
settingsObservable.subscribe(assignSettings);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Evaluate which properties should be included in the order array for a given file path.
|
|
24
|
+
* Returns an array with "file.name" as the first element, followed by default and path-specific properties.
|
|
25
|
+
*
|
|
26
|
+
* @param filePath - The file path to match against path rules
|
|
27
|
+
* @returns Array of property names to include in the order (file.name + defaults + path rule matches)
|
|
28
|
+
*/
|
|
29
|
+
evaluateIncludedProperties(filePath) {
|
|
30
|
+
// Always start with file.name
|
|
31
|
+
const includedProperties = ["file.name"];
|
|
32
|
+
// Add default included properties
|
|
33
|
+
for (const prop of this.defaultIncludedProperties) {
|
|
34
|
+
if (!includedProperties.includes(prop)) {
|
|
35
|
+
includedProperties.push(prop);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Find first matching path rule and add its included properties
|
|
39
|
+
const match = this.pathRules.find((rule) => filePath.startsWith(rule.path));
|
|
40
|
+
if (match) {
|
|
41
|
+
// Add path-specific included properties to the defaults
|
|
42
|
+
for (const prop of match.includedProperties) {
|
|
43
|
+
if (!includedProperties.includes(prop)) {
|
|
44
|
+
includedProperties.push(prop);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return includedProperties;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=included.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"included.js","sourceRoot":"","sources":["../../../src/core/evaluator/included.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,2BAA2B;IAUvC,YAAY,kBAA8C;QACzD,MAAM,cAAc,GAAG,CAAC,QAAmB,EAAE,EAAE;YAC9C,IAAI,CAAC,yBAAyB,GAAG,QAAQ,CAAC,8BAA8B,CAAC;YACzE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtF,CAAC,CAAC;QAEF,cAAc,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACzC,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,0BAA0B,CAAC,QAAgB;QAC1C,8BAA8B;QAC9B,MAAM,kBAAkB,GAAG,CAAC,WAAW,CAAC,CAAC;QAEzC,kCAAkC;QAClC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACnD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;QACF,CAAC;QAED,gEAAgE;QAChE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE5E,IAAI,KAAK,EAAE,CAAC;YACX,wDAAwD;YACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,kBAAkB,EAAE,CAAC;gBAC7C,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,kBAAkB,CAAC;IAC3B,CAAC;CACD","sourcesContent":["import type { BehaviorSubject } from \"rxjs\";\n\nexport interface PathIncludedProperties {\n\tid: string;\n\tpath: string;\n\tincludedProperties: string[];\n\tenabled: boolean;\n}\n\n/**\n * Generic evaluator for determining which properties to include in Bases view columns.\n *\n * Logic:\n * 1. ALWAYS includes the default included properties\n * 2. Checks if the file's path matches any path-based inclusion rules\n * 3. First matching path rule's properties are ADDED to the default inclusion list\n * 4. Returns the combined set of included properties in order:\n * - file.name (always first)\n * - default included properties (in specified order)\n * - path-specific included properties (in specified order)\n */\nexport class IncludedPropertiesEvaluator<\n\tTSettings extends {\n\t\tdefaultBasesIncludedProperties: string[];\n\t\tpathBasesIncludedProperties: PathIncludedProperties[];\n\t},\n> {\n\tprivate defaultIncludedProperties: string[];\n\n\tprivate pathRules: PathIncludedProperties[];\n\n\tconstructor(settingsObservable: BehaviorSubject<TSettings>) {\n\t\tconst assignSettings = (settings: TSettings) => {\n\t\t\tthis.defaultIncludedProperties = settings.defaultBasesIncludedProperties;\n\t\t\tthis.pathRules = settings.pathBasesIncludedProperties.filter((rule) => rule.enabled);\n\t\t};\n\n\t\tassignSettings(settingsObservable.value);\n\t\tsettingsObservable.subscribe(assignSettings);\n\t}\n\n\t/**\n\t * Evaluate which properties should be included in the order array for a given file path.\n\t * Returns an array with \"file.name\" as the first element, followed by default and path-specific properties.\n\t *\n\t * @param filePath - The file path to match against path rules\n\t * @returns Array of property names to include in the order (file.name + defaults + path rule matches)\n\t */\n\tevaluateIncludedProperties(filePath: string): string[] {\n\t\t// Always start with file.name\n\t\tconst includedProperties = [\"file.name\"];\n\n\t\t// Add default included properties\n\t\tfor (const prop of this.defaultIncludedProperties) {\n\t\t\tif (!includedProperties.includes(prop)) {\n\t\t\t\tincludedProperties.push(prop);\n\t\t\t}\n\t\t}\n\n\t\t// Find first matching path rule and add its included properties\n\t\tconst match = this.pathRules.find((rule) => filePath.startsWith(rule.path));\n\n\t\tif (match) {\n\t\t\t// Add path-specific included properties to the defaults\n\t\t\tfor (const prop of match.includedProperties) {\n\t\t\t\tif (!includedProperties.includes(prop)) {\n\t\t\t\t\tincludedProperties.push(prop);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn includedProperties;\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/evaluator/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./base\";\nexport * from \"./color\";\nexport * from \"./excluded\";\nexport * from \"./filter\";\nexport * from \"./included\";\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes a property name for use as a JavaScript function parameter
|
|
3
|
+
* by replacing spaces and special characters with underscores.
|
|
4
|
+
* Adds a prefix to avoid conflicts with JavaScript reserved words.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sanitizePropertyName(name: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Builds a mapping of original property names to sanitized versions
|
|
9
|
+
* suitable for use as JavaScript function parameters.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildPropertyMapping(properties: string[]): Map<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Replaces property names in an expression with their sanitized versions.
|
|
14
|
+
* Sorts by length descending to replace longer property names first and avoid partial matches.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sanitizeExpression(expression: string, propertyMapping: Map<string, string>): string;
|
|
17
|
+
//# sourceMappingURL=expression-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-utils.d.ts","sourceRoot":"","sources":["../../src/core/expression-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ9E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,CAqBR"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes a property name for use as a JavaScript function parameter
|
|
3
|
+
* by replacing spaces and special characters with underscores.
|
|
4
|
+
* Adds a prefix to avoid conflicts with JavaScript reserved words.
|
|
5
|
+
*/
|
|
6
|
+
export function sanitizePropertyName(name) {
|
|
7
|
+
const sanitized = name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
8
|
+
return `prop_${sanitized}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds a mapping of original property names to sanitized versions
|
|
12
|
+
* suitable for use as JavaScript function parameters.
|
|
13
|
+
*/
|
|
14
|
+
export function buildPropertyMapping(properties) {
|
|
15
|
+
const mapping = new Map();
|
|
16
|
+
for (const prop of properties) {
|
|
17
|
+
mapping.set(prop, sanitizePropertyName(prop));
|
|
18
|
+
}
|
|
19
|
+
return mapping;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Replaces property names in an expression with their sanitized versions.
|
|
23
|
+
* Sorts by length descending to replace longer property names first and avoid partial matches.
|
|
24
|
+
*/
|
|
25
|
+
export function sanitizeExpression(expression, propertyMapping) {
|
|
26
|
+
let sanitized = expression;
|
|
27
|
+
// Sort by length descending to replace longer property names first
|
|
28
|
+
const sortedEntries = Array.from(propertyMapping.entries()).sort(([a], [b]) => b.length - a.length);
|
|
29
|
+
for (const [original, sanitizedName] of sortedEntries) {
|
|
30
|
+
if (original !== sanitizedName) {
|
|
31
|
+
const escaped = original.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
32
|
+
// Use a regex that matches the property name not preceded or followed by word characters
|
|
33
|
+
// This allows matching properties with special characters like "My-Property"
|
|
34
|
+
const regex = new RegExp(`(?<!\\w)${escaped}(?!\\w)`, "g");
|
|
35
|
+
sanitized = sanitized.replace(regex, sanitizedName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return sanitized;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=expression-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-utils.js","sourceRoot":"","sources":["../../src/core/expression-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,QAAQ,SAAS,EAAE,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAoB;IACxD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,UAAkB,EAClB,eAAoC;IAEpC,IAAI,SAAS,GAAG,UAAU,CAAC;IAE3B,mEAAmE;IACnE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAC/D,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CACjC,CAAC;IAEF,KAAK,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,aAAa,EAAE,CAAC;QACvD,IAAI,QAAQ,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;YAEhE,yFAAyF;YACzF,6EAA6E;YAC7E,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,OAAO,SAAS,EAAE,GAAG,CAAC,CAAC;YAE3D,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACrD,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Sanitizes a property name for use as a JavaScript function parameter\n * by replacing spaces and special characters with underscores.\n * Adds a prefix to avoid conflicts with JavaScript reserved words.\n */\nexport function sanitizePropertyName(name: string): string {\n\tconst sanitized = name.replace(/[^a-zA-Z0-9_]/g, \"_\");\n\treturn `prop_${sanitized}`;\n}\n\n/**\n * Builds a mapping of original property names to sanitized versions\n * suitable for use as JavaScript function parameters.\n */\nexport function buildPropertyMapping(properties: string[]): Map<string, string> {\n\tconst mapping = new Map<string, string>();\n\n\tfor (const prop of properties) {\n\t\tmapping.set(prop, sanitizePropertyName(prop));\n\t}\n\n\treturn mapping;\n}\n\n/**\n * Replaces property names in an expression with their sanitized versions.\n * Sorts by length descending to replace longer property names first and avoid partial matches.\n */\nexport function sanitizeExpression(\n\texpression: string,\n\tpropertyMapping: Map<string, string>\n): string {\n\tlet sanitized = expression;\n\n\t// Sort by length descending to replace longer property names first\n\tconst sortedEntries = Array.from(propertyMapping.entries()).sort(\n\t\t([a], [b]) => b.length - a.length\n\t);\n\n\tfor (const [original, sanitizedName] of sortedEntries) {\n\t\tif (original !== sanitizedName) {\n\t\t\tconst escaped = original.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n\t\t\t// Use a regex that matches the property name not preceded or followed by word characters\n\t\t\t// This allows matching properties with special characters like \"My-Property\"\n\t\t\tconst regex = new RegExp(`(?<!\\\\w)${escaped}(?!\\\\w)`, \"g\");\n\n\t\t\tsanitized = sanitized.replace(regex, sanitizedName);\n\t\t}\n\t}\n\n\treturn sanitized;\n}\n"]}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./evaluator\";\nexport * from \"./expression-utils\";\nexport * from \"./generate\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real1ty-obsidian-plugins/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Shared utilities for Obsidian plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,10 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist
|
|
24
|
-
"
|
|
25
|
-
"dist/**/*.js.map",
|
|
26
|
-
"dist/**/*.d.ts.map",
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
27
25
|
"README.md",
|
|
28
26
|
"LICENSE"
|
|
29
27
|
],
|