@splicetree/core 3.0.2 → 3.1.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/index.d.ts CHANGED
@@ -62,6 +62,7 @@ interface SpliceTreeNode<T = SpliceTreeData> {
62
62
  * @param expand 不传表示切换;true/false 表示显式设置
63
63
  */
64
64
  toggleExpand: Fn<void, boolean | undefined>;
65
+ updateOriginal: (patch: Partial<T>) => void;
65
66
  }
66
67
  /**
67
68
  * 事件负载映射(可被插件扩展)
@@ -221,6 +222,12 @@ interface SpliceTreeInstance<T = SpliceTreeData> {
221
222
  * @param id 单个 id 或 id 数组
222
223
  */
223
224
  remove: (id: string | string[]) => void;
225
+ /**
226
+ * 更新节点原始数据(非结构字段)
227
+ * - 若包含父级字段变更,将转为 moveNode 处理
228
+ * - 不支持直接修改主键字段
229
+ */
230
+ updateOriginal: (id: string, patch: Partial<T>) => boolean;
224
231
  syncData: (next: T[]) => void;
225
232
  }
226
233
  /**
package/dist/index.js CHANGED
@@ -438,7 +438,10 @@ function createSpliceTree(data, options = {}) {
438
438
  parentCache,
439
439
  childrenCache,
440
440
  expandedKeys,
441
- notify: emitVisibility
441
+ notify: () => {
442
+ applyNodeExtensions();
443
+ emitVisibility();
444
+ }
442
445
  }, parentId, children);
443
446
  },
444
447
  moveNode(id, newParentId, beforeId) {
@@ -465,6 +468,19 @@ function createSpliceTree(data, options = {}) {
465
468
  notify: emitVisibility
466
469
  }, ids);
467
470
  },
471
+ updateOriginal(id, patch) {
472
+ const node = map.get(id);
473
+ if (!node) return false;
474
+ if (Object.prototype.hasOwnProperty.call(patch, keyField)) return false;
475
+ if (Object.prototype.hasOwnProperty.call(patch, parentField)) {
476
+ const nextParent = patch[parentField];
477
+ if (nextParent !== node.getParent()?.id) tree.moveNode(id, nextParent);
478
+ delete patch[parentField];
479
+ }
480
+ Object.assign(node.original, patch);
481
+ emitVisibility();
482
+ return true;
483
+ },
468
484
  syncData(next) {
469
485
  tree.data = next;
470
486
  const built = buildTree(next, keyField, parentField, expandedKeys);
@@ -508,6 +524,9 @@ function createSpliceTree(data, options = {}) {
508
524
  else if (expand) tree.expand(node.id);
509
525
  else tree.collapse(node.id);
510
526
  };
527
+ node.updateOriginal = (patch) => {
528
+ tree.updateOriginal(node.id, patch);
529
+ };
511
530
  }
512
531
  }
513
532
  applyNodeExtensions();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/core",
3
3
  "type": "module",
4
- "version": "3.0.2",
4
+ "version": "3.1.0",
5
5
  "author": {
6
6
  "email": "michael.cocova@gmail.com",
7
7
  "name": "Michael Cocova"