@v-c/tree 1.1.2 → 1.2.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.
@@ -112,7 +112,6 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
112
112
  default: void 0
113
113
  },
114
114
  motion: {
115
- type: Object,
116
115
  required: false,
117
116
  default: void 0
118
117
  },
@@ -146,7 +145,6 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
146
145
  default: void 0
147
146
  },
148
147
  eventKey: {
149
- type: [String, Number],
150
148
  required: false,
151
149
  default: void 0
152
150
  },
@@ -166,7 +164,6 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
166
164
  default: void 0
167
165
  },
168
166
  id: {
169
- type: [String, Number],
170
167
  required: false,
171
168
  default: void 0
172
169
  },
@@ -201,16 +198,9 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
201
198
  default: void 0
202
199
  },
203
200
  title: {
204
- type: [
205
- Object,
206
- Function,
207
- String,
208
- Number,
209
- null,
210
- Boolean,
211
- Array
212
- ],
201
+ type: Function,
213
202
  required: false,
203
+ skipCheck: true,
214
204
  default: void 0
215
205
  },
216
206
  dragOver: {
@@ -248,7 +238,6 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
248
238
  default: void 0
249
239
  },
250
240
  onMouseMove: {
251
- type: Function,
252
241
  required: false,
253
242
  default: void 0
254
243
  },
@@ -278,41 +267,18 @@ var MotionTreeNode = /* @__PURE__ */ defineComponent((props) => {
278
267
  default: void 0
279
268
  },
280
269
  icon: {
281
- type: [
282
- Object,
283
- Function,
284
- String,
285
- Number,
286
- null,
287
- Boolean,
288
- Array
289
- ],
270
+ type: Function,
290
271
  required: false,
272
+ skipCheck: true,
291
273
  default: void 0
292
274
  },
293
275
  switcherIcon: {
294
- type: [
295
- Object,
296
- Function,
297
- String,
298
- Number,
299
- null,
300
- Boolean,
301
- Array
302
- ],
276
+ type: Function,
303
277
  required: false,
278
+ skipCheck: true,
304
279
  default: void 0
305
280
  },
306
281
  children: {
307
- type: [
308
- Object,
309
- Function,
310
- String,
311
- Number,
312
- null,
313
- Boolean,
314
- Array
315
- ],
316
282
  required: false,
317
283
  default: void 0
318
284
  }
package/dist/NodeList.js CHANGED
@@ -245,20 +245,12 @@ var NodeList = /* @__PURE__ */ defineComponent((props, { attrs, expose }) => {
245
245
  required: false,
246
246
  default: void 0
247
247
  },
248
- dragOverNodeKey: {
249
- type: [
250
- String,
251
- Number,
252
- null
253
- ],
254
- required: true
255
- },
248
+ dragOverNodeKey: { required: true },
256
249
  dropPosition: {
257
250
  type: [Number, null],
258
251
  required: true
259
252
  },
260
253
  motion: {
261
- type: Object,
262
254
  required: false,
263
255
  default: void 0
264
256
  },
package/dist/Tree.js CHANGED
@@ -82,12 +82,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
82
82
  return keys;
83
83
  };
84
84
  const expandedKeys = shallowRef(getInitExpandedKeys());
85
- /**
86
- * Set the uncontrolled `expandedKeys`. Guarded centrally so a controlled
87
- * `expandedKeys` is never clobbered — the watcher below owns it in that case.
88
- */
89
85
  const setExpandedKeys = (keys) => {
90
- if (props.expandedKeys !== void 0) return;
91
86
  expandedKeys.value = keys;
92
87
  };
93
88
  watch(() => props.expandedKeys, () => {
@@ -202,6 +197,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
202
197
  return flattenNodes.value.find(({ key }) => key === activeKey.value) || null;
203
198
  });
204
199
  const scrollTo = (scroll) => {
200
+ if (scroll && typeof scroll === "object" && "autoExpand" in scroll && scroll.autoExpand && props.expandedKeys === void 0) setExpandedKeys(arrAdd(expandedKeys.value, scroll.key));
205
201
  listRef.value?.scrollTo(scroll);
206
202
  };
207
203
  expose({
@@ -480,7 +476,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
480
476
  let newExpandedKeys = [...expandedKeys.value];
481
477
  const entity = getEntity(keyEntities.value, nodeProps.eventKey);
482
478
  if (entity && (entity.children || []).length) newExpandedKeys = arrAdd(expandedKeys.value, nodeProps.eventKey);
483
- setExpandedKeys(newExpandedKeys);
479
+ if (props.expandedKeys === void 0) setExpandedKeys(newExpandedKeys);
484
480
  props.onExpand?.(newExpandedKeys, {
485
481
  node: convertNodePropsToEventData(nodeProps),
486
482
  expanded: true,
@@ -792,11 +788,6 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
792
788
  default: void 0
793
789
  },
794
790
  activeKey: {
795
- type: [
796
- String,
797
- Number,
798
- null
799
- ],
800
791
  required: false,
801
792
  default: void 0
802
793
  },
@@ -826,16 +817,9 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
826
817
  default: void 0
827
818
  },
828
819
  icon: {
829
- type: [
830
- Object,
831
- Function,
832
- String,
833
- Number,
834
- null,
835
- Boolean,
836
- Array
837
- ],
820
+ type: Function,
838
821
  required: false,
822
+ skipCheck: true,
839
823
  default: void 0
840
824
  },
841
825
  selectable: {
@@ -859,16 +843,9 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
859
843
  default: void 0
860
844
  },
861
845
  checkable: {
862
- type: [
863
- Boolean,
864
- Object,
865
- Function,
866
- String,
867
- Number,
868
- null,
869
- Array
870
- ],
846
+ type: Boolean,
871
847
  required: false,
848
+ skipCheck: true,
872
849
  default: void 0
873
850
  },
874
851
  checkStrictly: {
@@ -1071,21 +1048,13 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
1071
1048
  default: void 0
1072
1049
  },
1073
1050
  motion: {
1074
- type: Object,
1075
1051
  required: false,
1076
1052
  default: void 0
1077
1053
  },
1078
1054
  switcherIcon: {
1079
- type: [
1080
- Object,
1081
- Function,
1082
- String,
1083
- Number,
1084
- null,
1085
- Boolean,
1086
- Array
1087
- ],
1055
+ type: Function,
1088
1056
  required: false,
1057
+ skipCheck: true,
1089
1058
  default: void 0
1090
1059
  },
1091
1060
  height: {
package/dist/TreeNode.js CHANGED
@@ -27,6 +27,7 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
27
27
  if (typeof props.selectable === "boolean") return props.selectable;
28
28
  return context.selectable;
29
29
  });
30
+ const isUnselectable = computed(() => !context.checkable && !isSelectable.value);
30
31
  const hasChildren = computed(() => {
31
32
  const { children } = getEntity(context.keyEntities, props.eventKey) || {};
32
33
  return Boolean((children || []).length);
@@ -225,6 +226,7 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
225
226
  "aria-disabled": isDisabled.value,
226
227
  "class": clsx(props.className, `${context.prefixCls}-treenode`, context.classNames?.item, {
227
228
  [`${context.prefixCls}-treenode-disabled`]: isDisabled.value,
229
+ [`${context.prefixCls}-treenode-unselectable`]: isUnselectable.value,
228
230
  [`${context.prefixCls}-treenode-switcher-${props.expanded ? "open" : "close"}`]: !memoizedIsLeaf.value,
229
231
  [`${context.prefixCls}-treenode-checkbox-checked`]: props.checked,
230
232
  [`${context.prefixCls}-treenode-checkbox-indeterminate`]: props.halfChecked,
@@ -270,7 +272,6 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
270
272
  }, {
271
273
  props: {
272
274
  eventKey: {
273
- type: [String, Number],
274
275
  required: false,
275
276
  default: void 0
276
277
  },
@@ -290,7 +291,6 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
290
291
  default: void 0
291
292
  },
292
293
  id: {
293
- type: [String, Number],
294
294
  required: false,
295
295
  default: void 0
296
296
  },
@@ -330,16 +330,9 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
330
330
  default: void 0
331
331
  },
332
332
  title: {
333
- type: [
334
- Object,
335
- Function,
336
- String,
337
- Number,
338
- null,
339
- Boolean,
340
- Array
341
- ],
333
+ type: Function,
342
334
  required: false,
335
+ skipCheck: true,
343
336
  default: void 0
344
337
  },
345
338
  dragOver: {
@@ -386,7 +379,6 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
386
379
  default: void 0
387
380
  },
388
381
  onMouseMove: {
389
- type: Function,
390
382
  required: false,
391
383
  default: void 0
392
384
  },
@@ -416,41 +408,18 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
416
408
  default: void 0
417
409
  },
418
410
  icon: {
419
- type: [
420
- Object,
421
- Function,
422
- String,
423
- Number,
424
- null,
425
- Boolean,
426
- Array
427
- ],
411
+ type: Function,
428
412
  required: false,
413
+ skipCheck: true,
429
414
  default: void 0
430
415
  },
431
416
  switcherIcon: {
432
- type: [
433
- Object,
434
- Function,
435
- String,
436
- Number,
437
- null,
438
- Boolean,
439
- Array
440
- ],
417
+ type: Function,
441
418
  required: false,
419
+ skipCheck: true,
442
420
  default: void 0
443
421
  },
444
422
  children: {
445
- type: [
446
- Object,
447
- Function,
448
- String,
449
- Number,
450
- null,
451
- Boolean,
452
- Array
453
- ],
454
423
  required: false,
455
424
  default: void 0
456
425
  }
@@ -0,0 +1,9 @@
1
+ import { MaybeRefOrGetter } from 'vue';
2
+ import { BasicDataNode, DataEntity, DataNode, FieldNames, Key } from '../interface';
3
+ export interface UseTreeConfig {
4
+ fieldNames?: MaybeRefOrGetter<FieldNames | undefined>;
5
+ }
6
+ export interface TreeInstance<TreeDataType extends DataNode | BasicDataNode = DataNode> {
7
+ getPath: (key: Key) => DataEntity<TreeDataType>[];
8
+ }
9
+ export default function useTree<TreeDataType extends DataNode | BasicDataNode = DataNode>(treeData: MaybeRefOrGetter<TreeDataType[]>, config?: UseTreeConfig): TreeInstance<TreeDataType>;
@@ -0,0 +1,23 @@
1
+ import getEntity from "../utils/keyUtil.js";
2
+ import { convertDataToEntities } from "../utils/treeUtil.js";
3
+ import { computed, toValue } from "vue";
4
+ //#region src/hooks/useTree.ts
5
+ function useTree(treeData, config = {}) {
6
+ const { fieldNames } = config;
7
+ const keyEntities = computed(() => {
8
+ const { keyEntities } = convertDataToEntities(toValue(treeData), { fieldNames: toValue(fieldNames) });
9
+ return keyEntities;
10
+ });
11
+ const getPath = (key) => {
12
+ const path = [];
13
+ let entity = getEntity(keyEntities.value, key);
14
+ while (entity) {
15
+ path.unshift(entity);
16
+ entity = entity.parent;
17
+ }
18
+ return path;
19
+ };
20
+ return { getPath };
21
+ }
22
+ //#endregion
23
+ export { useTree as default };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
+ import { TreeInstance, UseTreeConfig, default as useTree } from './hooks/useTree';
1
2
  import { BasicDataNode, DataEntity, DataNode, EventDataNode, FieldNames, FlattenNode, IconType, Key, KeyEntities, ScrollTo, TreeNodeProps } from './interface';
2
3
  import { ExpandAction, TreeProps, TreeRef, default as Tree } from './Tree';
3
4
  import { default as TreeNode } from './TreeNode';
4
5
  export { UnstableContextKey } from './contextTypes';
5
- export { TreeNode };
6
+ export { TreeNode, useTree };
6
7
  export { arrAdd, arrDel, calcDropPosition, calcSelectedKeys, conductExpandParent, getDragChildrenKeys, isFirstChild, isLastChild, parseCheckedKeys, posToArr } from './util.ts';
7
8
  export { conductCheck } from './utils/conductUtil';
8
9
  export { convertDataToEntities, convertTreeToData, fillFieldNames, flattenTreeData } from './utils/treeUtil';
9
- export type { BasicDataNode, DataEntity, DataNode, EventDataNode, ExpandAction, FieldNames, FlattenNode, IconType, Key, KeyEntities, ScrollTo, TreeNodeProps, TreeProps, TreeRef, };
10
+ export type { BasicDataNode, DataEntity, DataNode, EventDataNode, ExpandAction, FieldNames, FlattenNode, IconType, Key, KeyEntities, ScrollTo, TreeInstance, TreeNodeProps, TreeProps, TreeRef, UseTreeConfig, };
10
11
  type TreeType = typeof Tree & {
11
12
  TreeNode: typeof TreeNode;
12
13
  };
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ import TreeNode from "./TreeNode.js";
4
4
  import { arrAdd, arrDel, calcDropPosition, calcSelectedKeys, conductExpandParent, getDragChildrenKeys, isFirstChild, isLastChild, parseCheckedKeys, posToArr } from "./util.js";
5
5
  import { conductCheck } from "./utils/conductUtil.js";
6
6
  import Tree from "./Tree.js";
7
+ import useTree from "./hooks/useTree.js";
7
8
  //#region src/index.ts
8
9
  var ExportTree = Tree;
9
10
  ExportTree.TreeNode = TreeNode;
10
11
  //#endregion
11
- export { TreeNode, UnstableContextKey, arrAdd, arrDel, calcDropPosition, calcSelectedKeys, conductCheck, conductExpandParent, convertDataToEntities, convertTreeToData, ExportTree as default, fillFieldNames, flattenTreeData, getDragChildrenKeys, isFirstChild, isLastChild, parseCheckedKeys, posToArr };
12
+ export { TreeNode, UnstableContextKey, arrAdd, arrDel, calcDropPosition, calcSelectedKeys, conductCheck, conductExpandParent, convertDataToEntities, convertTreeToData, ExportTree as default, fillFieldNames, flattenTreeData, getDragChildrenKeys, isFirstChild, isLastChild, parseCheckedKeys, posToArr, useTree };
@@ -1,8 +1,18 @@
1
1
  import { MouseEventHandler } from '@v-c/util/dist/EventInterface';
2
2
  import { Key as VCKey, VueNode } from '@v-c/util/dist/type';
3
+ import { ScrollTo as VirtualListScrollTo } from '@v-c/virtual-list';
3
4
  import { CSSProperties, VNode } from 'vue';
4
- export type { ScrollTo } from '@v-c/virtual-list';
5
5
  export type Key = VCKey;
6
+ type VirtualListScrollConfig = Exclude<NonNullable<Parameters<VirtualListScrollTo>[0]>, number>;
7
+ type ScrollTarget = Extract<VirtualListScrollConfig, {
8
+ key: Key;
9
+ }>;
10
+ type TreeScrollConfig = (Exclude<VirtualListScrollConfig, ScrollTarget> & {
11
+ autoExpand?: never;
12
+ }) | (ScrollTarget & {
13
+ autoExpand?: boolean;
14
+ });
15
+ export type ScrollTo = (scroll?: number | TreeScrollConfig | null) => void;
6
16
  /**
7
17
  * Typescript not support `bigint` as index type yet.
8
18
  * We use this to mark the `bigint` type is for `Key` usage.
@@ -120,3 +130,4 @@ export interface FieldNames {
120
130
  key?: string;
121
131
  children?: string;
122
132
  }
133
+ export {};
package/dist/util.d.ts CHANGED
@@ -5,8 +5,8 @@ export interface AllowDropOptions<TreeDataType extends BasicDataNode = DataNode>
5
5
  dropPosition: -1 | 0 | 1;
6
6
  }
7
7
  export type AllowDrop<TreeDataType extends BasicDataNode = DataNode> = (options: AllowDropOptions<TreeDataType>) => boolean;
8
- export declare function arrDel(list: Key[], value: Key): import('packages/util/dist/type').Key[];
9
- export declare function arrAdd(list: Key[], value: Key): import('packages/util/dist/type').Key[];
8
+ export declare function arrDel(list: Key[], value: Key): VCKey[];
9
+ export declare function arrAdd(list: Key[], value: Key): VCKey[];
10
10
  export declare function posToArr(pos: string): string[];
11
11
  export declare function getDragChildrenKeys<TreeDataType extends BasicDataNode = DataNode>(dragNodeKey: Key, keyEntities: KeyEntities<TreeDataType>): Key[];
12
12
  export declare function isLastChild<TreeDataType extends BasicDataNode = DataNode>(treeNodeEntity: DataEntity<TreeDataType>): boolean;
@@ -25,7 +25,7 @@ export declare function calcDropPosition<TreeDataType extends BasicDataNode = Da
25
25
  };
26
26
  export declare function calcSelectedKeys(selectedKeys: Key[], { multiple }: {
27
27
  multiple?: boolean;
28
- }): import('packages/util/dist/type').Key[] | undefined;
28
+ }): VCKey[] | undefined;
29
29
  export declare function parseCheckedKeys(keys: Key[] | {
30
30
  checked: Key[];
31
31
  halfChecked: Key[];
@@ -1,7 +1,7 @@
1
1
  import { BasicDataNode, DataEntity, DataNode, EventDataNode, FieldNames, FlattenNode, GetKey, Key, KeyEntities, NodeElement, TreeNodeProps } from '../interface';
2
2
  export declare function getPosition(level: string | number, index: number): string;
3
3
  export declare function isTreeNode(node: NodeElement): boolean;
4
- export declare function getKey(key: Key, pos: string): import('packages/util/dist/type').Key;
4
+ export declare function getKey(key: Key, pos: string): any;
5
5
  export declare function fillFieldNames(fieldNames?: FieldNames): Required<FieldNames>;
6
6
  export declare function warningWithoutKey(treeData: DataNode[], fieldNames: FieldNames): void;
7
7
  export declare function convertTreeToData(rootNodes: any): DataNode[];
@@ -47,7 +47,7 @@ export interface TreeNodeRequiredProps<TreeDataType extends BasicDataNode = Data
47
47
  keyEntities: KeyEntities<TreeDataType>;
48
48
  }
49
49
  export declare function getTreeNodeProps<TreeDataType extends BasicDataNode = DataNode>(key: Key, { expandedKeys, selectedKeys, loadedKeys, loadingKeys, checkedKeys, halfCheckedKeys, dragOverNodeKey, dropPosition, keyEntities, }: TreeNodeRequiredProps<TreeDataType>): {
50
- eventKey: import('packages/util/dist/type').Key;
50
+ eventKey: VCKey;
51
51
  expanded: boolean;
52
52
  selected: boolean;
53
53
  loaded: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/tree",
3
3
  "type": "module",
4
- "version": "1.1.2",
4
+ "version": "1.2.0",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@v-c/util": "^1.1.0",
38
- "@v-c/virtual-list": "^1.1.0"
38
+ "@v-c/virtual-list": "^1.1.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "vite build",