@splicetree/adapter-vue 2.0.0 → 3.0.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Ref, ShallowRef, WritableComputedRef } from "vue";
1
+ import { ComputedRef, Ref, ShallowRef, WritableComputedRef } from "vue";
2
2
  import { SpliceTreeData, SpliceTreeData as SpliceTreeData$1, SpliceTreeInstance, SpliceTreeInstance as SpliceTreeInstance$1, SpliceTreeNode, SpliceTreeNode as SpliceTreeNode$1, UseSpliceTreeOptions, UseSpliceTreeOptions as UseSpliceTreeOptions$1 } from "@splicetree/core";
3
3
 
4
4
  //#region src/index.d.ts
@@ -8,12 +8,15 @@ interface UseSpliceTreeReturn<T extends SpliceTreeData$1 = SpliceTreeData$1> ext
8
8
  /** 原始 Set 引用(当启用 selectable 插件时存在) */
9
9
  selectedKeysSet?: Set<string>;
10
10
  }
11
+ type UseSpliceTreeVueOptions<T extends SpliceTreeData$1 = SpliceTreeData$1> = UseSpliceTreeOptions$1<T> & {
12
+ expandedKeys?: ComputedRef<string | string[]> | Ref<string | string[]> | WritableComputedRef<string | string[]>;
13
+ };
11
14
  /**
12
15
  * Vue 3 适配器
13
16
  * - 以 shallowRef 暴露 items,使其在核心派发 visibility 事件时刷新
14
17
  * - 保留核心 API 的完整返回(展开/收起/移动等方法)
15
18
  * - 适用于任意自定义渲染逻辑与组件绑定
16
19
  */
17
- declare function useSpliceTree<T extends SpliceTreeData$1 = SpliceTreeData$1>(data: Ref<T[]> | T[] | WritableComputedRef<T[]>, options?: UseSpliceTreeOptions$1<T>): UseSpliceTreeReturn<T>;
20
+ declare function useSpliceTree<T extends SpliceTreeData$1 = SpliceTreeData$1>(data: T[] | Ref<T[]> | ComputedRef<T[]> | WritableComputedRef<T[]>, options?: UseSpliceTreeVueOptions<T>): UseSpliceTreeReturn<T>;
18
21
  //#endregion
19
- export { type SpliceTreeData, type SpliceTreeInstance, type SpliceTreeNode, type UseSpliceTreeOptions, UseSpliceTreeReturn, useSpliceTree };
22
+ export { type SpliceTreeData, type SpliceTreeInstance, type SpliceTreeNode, type UseSpliceTreeOptions, UseSpliceTreeReturn, UseSpliceTreeVueOptions, useSpliceTree };
package/dist/index.js CHANGED
@@ -462,6 +462,21 @@ function useSpliceTree(data, options = {}) {
462
462
  const api = shallowRef();
463
463
  const items = shallowRef(api.value?.items?.() ?? []);
464
464
  const selectedKeys = shallowRef([]);
465
+ const applyExpandedKeys = (value) => {
466
+ if (!api.value || value === void 0) return;
467
+ const list = Array.isArray(value) ? value : [value];
468
+ const toExpand = /* @__PURE__ */ new Set();
469
+ for (const id of list) {
470
+ const node = api.value.getNode(id);
471
+ if (!node) continue;
472
+ let cur = node;
473
+ while (cur) {
474
+ toExpand.add(cur.id);
475
+ cur = cur.getParent();
476
+ }
477
+ }
478
+ if (toExpand.size) api.value.expand(Array.from(toExpand));
479
+ };
465
480
  const createTree = () => {
466
481
  api.value = createSpliceTree(toValue(data), options);
467
482
  api.value.events.on("visibility", () => {
@@ -470,14 +485,22 @@ function useSpliceTree(data, options = {}) {
470
485
  });
471
486
  items.value = api.value.items();
472
487
  if (api.value?.selectedKeys instanceof Set) selectedKeys.value = Array.from(api.value.selectedKeys);
488
+ applyExpandedKeys(options?.expandedKeys ? toValue(options.expandedKeys) : void 0);
473
489
  };
474
490
  createTree();
475
491
  watch(() => toValue(data), () => {
476
492
  api.value.syncData(toValue(data));
493
+ applyExpandedKeys(options?.expandedKeys ? toValue(options.expandedKeys) : void 0);
477
494
  }, {
478
495
  deep: true,
479
496
  immediate: false
480
497
  });
498
+ watch(() => options?.expandedKeys ? toValue(options.expandedKeys) : void 0, (val) => {
499
+ applyExpandedKeys(val);
500
+ }, {
501
+ deep: true,
502
+ immediate: true
503
+ });
481
504
  return {
482
505
  ...api.value,
483
506
  items,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/adapter-vue",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "3.0.1",
5
5
  "author": {
6
6
  "email": "michael.cocova@gmail.com",
7
7
  "name": "Michael Cocova"
@@ -30,7 +30,7 @@
30
30
  "unplugin-vue": "^7.1.0",
31
31
  "vue": "^3.0.0",
32
32
  "vue-tsc": "^3.1.5",
33
- "@splicetree/core": "2.0.0"
33
+ "@splicetree/core": "3.0.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"