@umbraci/jsmind 0.9.13 → 0.10.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umbraci/jsmind",
3
- "version": "0.9.13",
3
+ "version": "0.10.1",
4
4
  "description": "jsMind is a pure javascript library for mindmap, it base on html5 canvas. jsMind was released under BSD license, you can embed it in any project, if only you observe the license.",
5
5
  "main": "lib/jsmind.js",
6
6
  "module": "es/jsmind.js",
@@ -222,8 +222,27 @@ declare class jsMind {
222
222
  /**
223
223
  * Add multiple nodes to the mind map with optimized performance.
224
224
  * Supports standard jsMind formats: node_tree, node_array, and freemind with nested children structure.
225
+ *
226
+ * **Field Names Support**: This method now supports custom field names configured via `options.fieldNames`.
227
+ * You can use your own property names (e.g., 'name' instead of 'topic', 'key' instead of 'id').
228
+ *
229
+ * @example
230
+ * // Using standard field names
231
+ * jm.add_nodes('parent_id', [
232
+ * { id: 'node1', topic: 'Node 1', children: [...] }
233
+ * ]);
234
+ *
235
+ * @example
236
+ * // Using custom field names (requires fieldNames configuration)
237
+ * var jm = new jsMind({
238
+ * fieldNames: { id: 'key', topic: 'name', children: 'items' }
239
+ * });
240
+ * jm.add_nodes('parent_id', [
241
+ * { key: 'node1', name: 'Node 1', items: [...] }
242
+ * ]);
243
+ *
225
244
  * @param {string | import('./jsmind.node.js').Node} parent_node - Parent node for all new nodes
226
- * @param {Array<{id?: string, topic?: string, data?: Record<string, any>, direction?: ('left'|'center'|'right'|'-1'|'0'|'1'|number), children?: Array, [key: string]: any}>} nodes_data - Array of node data objects with same format as add_node
245
+ * @param {Array<{id?: string, topic?: string, data?: Record<string, any>, direction?: ('left'|'center'|'right'|'-1'|'0'|'1'|number), children?: Array, [key: string]: any}>} nodes_data - Array of node data objects. Field names can be customized via options.fieldNames.
227
246
  * @returns {Array<import('./jsmind.node.js').Node|null>} Array of created nodes (flattened from all levels)
228
247
  */
229
248
  add_nodes(parent_node: string | import("./jsmind.node.js").Node, nodes_data: Array<{
@@ -236,14 +255,16 @@ declare class jsMind {
236
255
  }>): Array<import("./jsmind.node.js").Node | null>;
237
256
  /**
238
257
  * Recursively add nodes using existing format processors.
258
+ * Supports custom field names via options.fieldNames configuration.
239
259
  * @private
240
260
  * @param {import('./jsmind.node.js').Node} parent_node
241
- * @param {object} node_data
261
+ * @param {object} node_data - Node data object with standard or custom field names
242
262
  * @returns {Array<import('./jsmind.node.js').Node|null>}
243
263
  */
244
264
  private _add_nodes_recursive;
245
265
  /**
246
266
  * Count expected nodes recursively.
267
+ * Supports custom field names via options.fieldNames configuration.
247
268
  * @private
248
269
  * @param {Array} nodes_data
249
270
  * @returns {number}
@@ -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
- * // Custom fields
34
- * const result = diff(snapshot1, snapshot2, { fields: ['id', 'topic'] });
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
  */