@real1ty-obsidian-plugins/utils 2.12.0 → 2.15.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/components/frontmatter-propagation-modal.d.ts +16 -0
- package/dist/components/frontmatter-propagation-modal.d.ts.map +1 -0
- package/dist/components/frontmatter-propagation-modal.js +81 -0
- package/dist/components/frontmatter-propagation-modal.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +3 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/input-managers/base.d.ts +30 -0
- package/dist/components/input-managers/base.d.ts.map +1 -0
- package/dist/components/input-managers/base.js +115 -0
- package/dist/components/input-managers/base.js.map +1 -0
- package/dist/components/input-managers/expression.d.ts +12 -0
- package/dist/components/input-managers/expression.d.ts.map +1 -0
- package/dist/components/input-managers/expression.js +56 -0
- package/dist/components/input-managers/expression.js.map +1 -0
- package/dist/components/input-managers/index.d.ts +4 -0
- package/dist/components/input-managers/index.d.ts.map +1 -0
- package/dist/components/input-managers/index.js +4 -0
- package/dist/components/input-managers/index.js.map +1 -0
- package/dist/components/input-managers/search.d.ts +6 -0
- package/dist/components/input-managers/search.d.ts.map +1 -0
- package/dist/components/input-managers/search.js +16 -0
- package/dist/components/input-managers/search.js.map +1 -0
- package/dist/core/evaluator/base.d.ts.map +1 -1
- package/dist/core/evaluator/base.js +12 -3
- package/dist/core/evaluator/base.js.map +1 -1
- package/dist/file/frontmatter-diff.d.ts +38 -0
- package/dist/file/frontmatter-diff.d.ts.map +1 -0
- package/dist/file/frontmatter-diff.js +162 -0
- package/dist/file/frontmatter-diff.js.map +1 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +1 -0
- package/dist/file/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/frontmatter-propagation-modal.ts +111 -0
- package/src/components/index.ts +2 -0
- package/src/components/input-managers/base.ts +150 -0
- package/src/components/input-managers/expression.ts +92 -0
- package/src/components/input-managers/index.ts +3 -0
- package/src/components/input-managers/search.ts +25 -0
- package/src/core/evaluator/base.ts +15 -3
- package/src/file/frontmatter-diff.ts +198 -0
- package/src/file/index.ts +1 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export type Frontmatter = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
export interface FrontmatterChange {
|
|
4
|
+
key: string;
|
|
5
|
+
oldValue: unknown;
|
|
6
|
+
newValue: unknown;
|
|
7
|
+
changeType: "added" | "modified" | "deleted";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FrontmatterDiff {
|
|
11
|
+
hasChanges: boolean;
|
|
12
|
+
changes: FrontmatterChange[];
|
|
13
|
+
added: FrontmatterChange[];
|
|
14
|
+
modified: FrontmatterChange[];
|
|
15
|
+
deleted: FrontmatterChange[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Compares two frontmatter objects and returns a detailed diff.
|
|
20
|
+
* Excludes specified properties from comparison (e.g., Prisma-managed properties).
|
|
21
|
+
*
|
|
22
|
+
* @param oldFrontmatter - The original frontmatter
|
|
23
|
+
* @param newFrontmatter - The updated frontmatter
|
|
24
|
+
* @param excludeProps - Set of property keys to exclude from comparison
|
|
25
|
+
* @returns Detailed diff with categorized changes
|
|
26
|
+
*/
|
|
27
|
+
export function compareFrontmatter(
|
|
28
|
+
oldFrontmatter: Frontmatter,
|
|
29
|
+
newFrontmatter: Frontmatter,
|
|
30
|
+
excludeProps: Set<string> = new Set()
|
|
31
|
+
): FrontmatterDiff {
|
|
32
|
+
const changes: FrontmatterChange[] = [];
|
|
33
|
+
const added: FrontmatterChange[] = [];
|
|
34
|
+
const modified: FrontmatterChange[] = [];
|
|
35
|
+
const deleted: FrontmatterChange[] = [];
|
|
36
|
+
|
|
37
|
+
const allKeys = new Set([...Object.keys(oldFrontmatter), ...Object.keys(newFrontmatter)]);
|
|
38
|
+
|
|
39
|
+
for (const key of allKeys) {
|
|
40
|
+
if (excludeProps.has(key)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const oldValue = oldFrontmatter[key];
|
|
45
|
+
const newValue = newFrontmatter[key];
|
|
46
|
+
|
|
47
|
+
if (!(key in oldFrontmatter) && key in newFrontmatter) {
|
|
48
|
+
const change: FrontmatterChange = {
|
|
49
|
+
key,
|
|
50
|
+
oldValue: undefined,
|
|
51
|
+
newValue,
|
|
52
|
+
changeType: "added",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
changes.push(change);
|
|
56
|
+
added.push(change);
|
|
57
|
+
} else if (key in oldFrontmatter && !(key in newFrontmatter)) {
|
|
58
|
+
const change: FrontmatterChange = {
|
|
59
|
+
key,
|
|
60
|
+
oldValue,
|
|
61
|
+
newValue: undefined,
|
|
62
|
+
changeType: "deleted",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
changes.push(change);
|
|
66
|
+
deleted.push(change);
|
|
67
|
+
} else if (!deepEqual(oldValue, newValue)) {
|
|
68
|
+
const change: FrontmatterChange = {
|
|
69
|
+
key,
|
|
70
|
+
oldValue,
|
|
71
|
+
newValue,
|
|
72
|
+
changeType: "modified",
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
changes.push(change);
|
|
76
|
+
modified.push(change);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
hasChanges: changes.length > 0,
|
|
82
|
+
changes,
|
|
83
|
+
added,
|
|
84
|
+
modified,
|
|
85
|
+
deleted,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Deep equality check for frontmatter values.
|
|
91
|
+
* Handles primitives, arrays, and objects.
|
|
92
|
+
*/
|
|
93
|
+
function deepEqual(a: unknown, b: unknown): boolean {
|
|
94
|
+
if (a === b) return true;
|
|
95
|
+
|
|
96
|
+
if (a === null || b === null || a === undefined || b === undefined) {
|
|
97
|
+
return a === b;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (typeof a !== typeof b) return false;
|
|
101
|
+
|
|
102
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
103
|
+
if (a.length !== b.length) return false;
|
|
104
|
+
return a.every((val, idx) => deepEqual(val, b[idx]));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
108
|
+
const keysA = Object.keys(a as Record<string, unknown>);
|
|
109
|
+
const keysB = Object.keys(b as Record<string, unknown>);
|
|
110
|
+
|
|
111
|
+
if (keysA.length !== keysB.length) return false;
|
|
112
|
+
|
|
113
|
+
return keysA.every((key) =>
|
|
114
|
+
deepEqual((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key])
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Merges multiple frontmatter diffs into a single accumulated diff.
|
|
123
|
+
* Later diffs override earlier ones for the same key.
|
|
124
|
+
*
|
|
125
|
+
* @param diffs - Array of diffs to merge (in chronological order)
|
|
126
|
+
* @returns A single merged diff containing all accumulated changes
|
|
127
|
+
*/
|
|
128
|
+
export function mergeFrontmatterDiffs(diffs: FrontmatterDiff[]): FrontmatterDiff {
|
|
129
|
+
if (diffs.length === 0) {
|
|
130
|
+
return {
|
|
131
|
+
hasChanges: false,
|
|
132
|
+
changes: [],
|
|
133
|
+
added: [],
|
|
134
|
+
modified: [],
|
|
135
|
+
deleted: [],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (diffs.length === 1) {
|
|
140
|
+
return diffs[0];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const changesByKey = new Map<string, FrontmatterChange>();
|
|
144
|
+
|
|
145
|
+
for (const diff of diffs) {
|
|
146
|
+
for (const change of diff.changes) {
|
|
147
|
+
const existing = changesByKey.get(change.key);
|
|
148
|
+
|
|
149
|
+
if (!existing) {
|
|
150
|
+
changesByKey.set(change.key, { ...change });
|
|
151
|
+
} else {
|
|
152
|
+
existing.newValue = change.newValue;
|
|
153
|
+
existing.changeType = change.changeType;
|
|
154
|
+
|
|
155
|
+
if (existing.oldValue === change.newValue) {
|
|
156
|
+
changesByKey.delete(change.key);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const allChanges = Array.from(changesByKey.values());
|
|
163
|
+
const added = allChanges.filter((c) => c.changeType === "added");
|
|
164
|
+
const modified = allChanges.filter((c) => c.changeType === "modified");
|
|
165
|
+
const deleted = allChanges.filter((c) => c.changeType === "deleted");
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
hasChanges: allChanges.length > 0,
|
|
169
|
+
changes: allChanges,
|
|
170
|
+
added,
|
|
171
|
+
modified,
|
|
172
|
+
deleted,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Formats a frontmatter change for display in a modal.
|
|
178
|
+
* Returns a human-readable string describing the change.
|
|
179
|
+
*/
|
|
180
|
+
export function formatChangeForDisplay(change: FrontmatterChange): string {
|
|
181
|
+
const formatValue = (value: unknown): string => {
|
|
182
|
+
if (value === undefined) return "(not set)";
|
|
183
|
+
if (value === null) return "null";
|
|
184
|
+
if (typeof value === "string") return `"${value}"`;
|
|
185
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
186
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
187
|
+
return JSON.stringify(value);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
switch (change.changeType) {
|
|
191
|
+
case "added":
|
|
192
|
+
return `+ ${change.key}: ${formatValue(change.newValue)}`;
|
|
193
|
+
case "deleted":
|
|
194
|
+
return `- ${change.key}: ${formatValue(change.oldValue)}`;
|
|
195
|
+
case "modified":
|
|
196
|
+
return `~ ${change.key}: ${formatValue(change.oldValue)} → ${formatValue(change.newValue)}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
package/src/file/index.ts
CHANGED