@umbraci/jsmind 0.9.13 → 0.10.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/jsmind.history.js +1 -1
- package/dist/jsmind.history.js.map +1 -1
- package/es/jsmind.history.js +1 -1
- package/es/jsmind.history.js.map +1 -1
- package/lib/jsmind.history.js +1 -1
- package/lib/jsmind.history.js.map +1 -1
- package/package.json +1 -1
- package/types/generated/plugins/history/history-diff.d.ts +61 -6
- package/types/generated/plugins/history/jsmind.history.d.ts +2 -0
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flatten a tree into a Map of nodes keyed by id.
|
|
3
|
+
*
|
|
4
|
+
* Note: When using custom fieldNames, make sure to pass the correct field names in opts.fields.
|
|
5
|
+
* For example, if you configured fieldNames: { topic: 'name' }, you should pass fields: ['name', 'data', 'id'].
|
|
6
|
+
*
|
|
3
7
|
* @param {NodeTreeFormat|NodeTreeData} tree - The tree to flatten
|
|
4
8
|
* @param {FlattenOptions} [opts] - Flatten options
|
|
5
9
|
* @returns {Map<string, FlatNode>} Map of node id -> flattened node object
|
|
10
|
+
*
|
|
6
11
|
* @example
|
|
12
|
+
* // With default fieldNames
|
|
7
13
|
* const tree = { data: { id: 'root', topic: 'Root', children: [...] } };
|
|
8
14
|
* const flatMap = flatten(tree);
|
|
9
15
|
* const rootNode = flatMap.get('root'); // { id: 'root', topic: 'Root', data: {...}, _parentid: null, _order: 0 }
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With custom fieldNames: { topic: 'name' }
|
|
19
|
+
* const tree = { data: { id: 'root', name: 'Root', children: [...] } };
|
|
20
|
+
* const flatMap = flatten(tree, { fields: ['name', 'data', 'id'] });
|
|
21
|
+
* const rootNode = flatMap.get('root'); // { id: 'root', name: 'Root', data: {...}, _parentid: null, _order: 0 }
|
|
10
22
|
*/
|
|
11
23
|
export function flatten(tree: NodeTreeFormat | NodeTreeData, opts?: FlattenOptions): Map<string, FlatNode>;
|
|
12
24
|
/**
|
|
13
|
-
* Compute diff between two snapshots
|
|
25
|
+
* Compute diff between two snapshots.
|
|
26
|
+
*
|
|
27
|
+
* Note: When using custom fieldNames, make sure to pass the correct field names in opts.fields.
|
|
28
|
+
* For example, if you configured fieldNames: { topic: 'name' }, you should pass fields: ['name', 'data', 'id'].
|
|
29
|
+
* When using jm.history.diff(), this is automatically handled for you.
|
|
30
|
+
*
|
|
14
31
|
* @param {NodeTreeFormat|NodeTreeData} a - First snapshot (before)
|
|
15
32
|
* @param {NodeTreeFormat|NodeTreeData} b - Second snapshot (after)
|
|
16
33
|
* @param {DiffOptions} [opts] - Diff options
|
|
17
34
|
* @returns {DiffResult} Diff result with created, updated, deleted nodes, and optionally categorized updates
|
|
35
|
+
*
|
|
18
36
|
* @example
|
|
19
|
-
* // Basic usage
|
|
37
|
+
* // Basic usage with default fieldNames
|
|
20
38
|
* const result = diff(snapshot1, snapshot2);
|
|
21
39
|
* console.log(result.created); // Newly created nodes
|
|
22
40
|
* console.log(result.updated); // Updated nodes with changes
|
|
@@ -30,8 +48,17 @@ export function flatten(tree: NodeTreeFormat | NodeTreeData, opts?: FlattenOptio
|
|
|
30
48
|
* console.log(result.movedAndModified); // Nodes that were both moved and modified
|
|
31
49
|
*
|
|
32
50
|
* @example
|
|
33
|
-
* //
|
|
34
|
-
* const result = diff(snapshot1, snapshot2, { fields: ['
|
|
51
|
+
* // With custom fieldNames: { topic: 'name' }
|
|
52
|
+
* const result = diff(snapshot1, snapshot2, { fields: ['name', 'data', 'id'] });
|
|
53
|
+
* // Now the diff will correctly detect changes in the 'name' field
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Using jm.history.diff() (recommended - automatically handles fieldNames)
|
|
57
|
+
* const before = jm.get_data('node_tree');
|
|
58
|
+
* // ... make changes ...
|
|
59
|
+
* const after = jm.get_data('node_tree');
|
|
60
|
+
* const result = jm.history.diff(before, after);
|
|
61
|
+
* // fieldNames are automatically applied, no need to specify fields manually
|
|
35
62
|
*/
|
|
36
63
|
export function diff(a: NodeTreeFormat | NodeTreeData, b: NodeTreeFormat | NodeTreeData, opts?: DiffOptions): DiffResult;
|
|
37
64
|
export type NodeTreeFormat = {
|
|
@@ -218,9 +245,21 @@ export type DiffResult = {
|
|
|
218
245
|
};
|
|
219
246
|
export type FlattenOptions = {
|
|
220
247
|
/**
|
|
221
|
-
* - Array of field names to include. Defaults to ['topic', 'data', 'id']
|
|
248
|
+
* - Array of field names to include. Defaults to ['topic', 'data', 'id'].
|
|
249
|
+
* When using custom fieldNames (e.g., { id: 'key', topic: 'name' }), this should be
|
|
250
|
+
* ['name', 'data', 'key'] to match the actual field names in the data.
|
|
222
251
|
*/
|
|
223
252
|
fields?: string[];
|
|
253
|
+
/**
|
|
254
|
+
* - The field name to use as the node ID. Defaults to 'id'.
|
|
255
|
+
* When using custom fieldNames (e.g., { id: 'key' }), this should be 'key'.
|
|
256
|
+
*/
|
|
257
|
+
idKey?: string;
|
|
258
|
+
/**
|
|
259
|
+
* - The field name to use for children array. Defaults to 'children'.
|
|
260
|
+
* When using custom fieldNames (e.g., { children: 'items' }), this should be 'items'.
|
|
261
|
+
*/
|
|
262
|
+
childrenKey?: string;
|
|
224
263
|
/**
|
|
225
264
|
* - Whether to include _parentid and _order. Defaults to true
|
|
226
265
|
*/
|
|
@@ -228,9 +267,25 @@ export type FlattenOptions = {
|
|
|
228
267
|
};
|
|
229
268
|
export type DiffOptions = {
|
|
230
269
|
/**
|
|
231
|
-
* - Array of field names to compare. Defaults to ['topic', 'data', 'id']
|
|
270
|
+
* - Array of field names to compare. Defaults to ['topic', 'data', 'id'].
|
|
271
|
+
* When using custom fieldNames (e.g., { id: 'key', topic: 'name' }), this should be
|
|
272
|
+
* ['name', 'data', 'key'] to match the actual field names in the data.
|
|
273
|
+
* Note: When using jm.history.diff(), this is automatically handled based
|
|
274
|
+
* on the configured fieldNames, so you don't need to specify it manually.
|
|
232
275
|
*/
|
|
233
276
|
fields?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* - The field name to use as the node ID. Defaults to 'id'.
|
|
279
|
+
* When using custom fieldNames (e.g., { id: 'key' }), this should be 'key'.
|
|
280
|
+
* Note: When using jm.history.diff(), this is automatically handled.
|
|
281
|
+
*/
|
|
282
|
+
idKey?: string;
|
|
283
|
+
/**
|
|
284
|
+
* - The field name to use for children array. Defaults to 'children'.
|
|
285
|
+
* When using custom fieldNames (e.g., { children: 'items' }), this should be 'items'.
|
|
286
|
+
* Note: When using jm.history.diff(), this is automatically handled.
|
|
287
|
+
*/
|
|
288
|
+
childrenKey?: string;
|
|
234
289
|
/**
|
|
235
290
|
* - Whether to include _parentid and _order in comparison. Defaults to true
|
|
236
291
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export default HistoryPlugin;
|
|
2
2
|
export type JsMind = import("../../jsmind.js").default;
|
|
3
|
+
export type DiffResult = import("./history-diff.js").DiffResult;
|
|
4
|
+
export type DiffOptions = import("./history-diff.js").DiffOptions;
|
|
3
5
|
/**
|
|
4
6
|
* HistoryPlugin skeleton (Task 1)
|
|
5
7
|
*/
|