@veltra/desktop 1.15.7 → 1.16.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.
Files changed (38) hide show
  1. package/dist/components/multi-tree-select/multi-tree-select.js +44 -8
  2. package/dist/components/multi-tree-select/multi-tree-select.js.map +1 -1
  3. package/dist/components/table/style2.css +7 -0
  4. package/dist/components/table/table.js +46 -7
  5. package/dist/components/table/table.js.map +1 -1
  6. package/dist/components/table/use-cell-tip.js +62 -0
  7. package/dist/components/table/use-cell-tip.js.map +1 -0
  8. package/dist/components/tree/forest.js +47 -0
  9. package/dist/components/tree/forest.js.map +1 -0
  10. package/dist/components/tree/tree-node.js +3 -3
  11. package/dist/components/tree/tree-node.js.map +1 -1
  12. package/dist/components/tree/tree-node2.js +9 -0
  13. package/dist/components/tree/tree-node2.js.map +1 -1
  14. package/dist/components/tree/tree.js +1 -0
  15. package/dist/components/tree/tree.js.map +1 -1
  16. package/dist/components/tree/use-check.js +17 -1
  17. package/dist/components/tree/use-check.js.map +1 -1
  18. package/dist/components/tree/use-tree-nodes.js +6 -33
  19. package/dist/components/tree/use-tree-nodes.js.map +1 -1
  20. package/dist/components/tree-select/tree-select.js +1 -0
  21. package/dist/components/tree-select/tree-select.js.map +1 -1
  22. package/dist/types/multi-tree-select.d.ts +8 -1
  23. package/dist/types/tree.d.ts +9 -0
  24. package/package.json +1 -1
  25. package/src/components/multi-tree-select/__test__/show-checkbox.test.ts +216 -0
  26. package/src/components/multi-tree-select/multi-tree-select.vue +44 -9
  27. package/src/components/table/__test__/cell-tip.test.ts +117 -0
  28. package/src/components/table/style.scss +12 -0
  29. package/src/components/table/table.vue +44 -7
  30. package/src/components/table/use-cell-tip.ts +76 -0
  31. package/src/components/tree/__test__/show-checkbox.test.ts +153 -0
  32. package/src/components/tree/forest.ts +63 -0
  33. package/src/components/tree/tree-node.ts +11 -0
  34. package/src/components/tree/tree-node.vue +4 -2
  35. package/src/components/tree/use-check.ts +20 -3
  36. package/src/components/tree/use-tree-nodes.ts +10 -41
  37. package/src/types/multi-tree-select.ts +9 -1
  38. package/src/types/tree.ts +9 -0
@@ -49,6 +49,8 @@ export function useCheck(options: Options): UseCheckReturned {
49
49
  let lastDict: Map<any, TreeNode> | null = null
50
50
 
51
51
  function checkNode(node: TreeNode): void {
52
+ // 不渲染复选框的节点不是勾选值:不选中自身,也不参与向上计数
53
+ if (!node.showCheckbox) return
52
54
  if (node.checked) return
53
55
  node.checked = true
54
56
  if (!props.checkStrictly && node.parent) {
@@ -58,6 +60,7 @@ export function useCheck(options: Options): UseCheckReturned {
58
60
  }
59
61
 
60
62
  function uncheckNode(node: TreeNode): void {
63
+ if (!node.showCheckbox) return
61
64
  if (!node.checked) return
62
65
  node.checked = false
63
66
  if (!props.checkStrictly && node.parent) {
@@ -66,6 +69,22 @@ export function useCheck(options: Options): UseCheckReturned {
66
69
  checkedData.delete(node.data)
67
70
  }
68
71
 
72
+ /** 父节点是否视为已全选:分母只统计渲染了复选框的子节点 */
73
+ function isAllChildrenChecked(parent: TreeNode): boolean {
74
+ const count = parent.checkableChildrenCount
75
+ return count > 0 && parent.childrenCheckCount === count
76
+ }
77
+
78
+ /**
79
+ * 按子节点勾选情况同步父节点状态。
80
+ * @description 没有可勾选子节点时无法由子节点状态推导父节点,保持父节点自身状态,
81
+ * 否则点击父节点自身会被立即回滚。
82
+ */
83
+ function syncParentChecked(parent: TreeNode): void {
84
+ if (!parent.checkableChildrenCount) return
85
+ isAllChildrenChecked(parent) ? checkNode(parent) : uncheckNode(parent)
86
+ }
87
+
69
88
  /**
70
89
  * 模型值是否由事件触发
71
90
  */
@@ -152,9 +171,7 @@ export function useCheck(options: Options): UseCheckReturned {
152
171
  const { parent } = node
153
172
 
154
173
  if (parent) {
155
- const parentChecked = parent.childrenCheckCount === parent.children!.length
156
-
157
- parentChecked ? checkNode(parent) : uncheckNode(parent)
174
+ syncParentChecked(parent)
158
175
  }
159
176
  })
160
177
  }
@@ -1,9 +1,9 @@
1
- import { Forest } from '@cat-kit/core'
2
- import { fieldKey } from '@veltra/utils'
1
+ import type { Forest } from '@cat-kit/core'
3
2
  import { computed, shallowRef, triggerRef, watch, type ShallowRef, type ComputedRef } from 'vue'
4
3
 
5
4
  import type { TreeProps } from '../../types'
6
- import { TreeNode } from './tree-node'
5
+ import { createTreeForest } from './forest'
6
+ import type { TreeNode } from './tree-node'
7
7
 
8
8
  interface Options {
9
9
  props: TreeProps
@@ -25,53 +25,21 @@ export function useTreeNodes(options: Options): UseTreeNodesReturned {
25
25
  // - computed 会因为任一 prop 变化(尤其是内联 disabledNode 函数)而整棵重建,
26
26
  // 丢失 expanded/checked/visible 等运行时状态;
27
27
  // - 显式 watch 仅在真正影响结构的输入变化时才重建,行为可控、可测量。
28
- const forestRef = shallowRef<Forest<Record<string, unknown>, any>>(
29
- new Forest<Record<string, unknown>, any>({
30
- data: [],
31
- childrenKey: props.childrenKey ?? 'children'
32
- })
33
- )
28
+ const forestRef = shallowRef<Forest<Record<string, unknown>, any>>(createTreeForest({ data: [] }))
34
29
 
35
30
  const nodeDictRef = shallowRef<Map<string | number, TreeNode>>(new Map())
36
31
 
37
32
  const nodes = shallowRef<TreeNode[]>([])
38
33
 
39
- function buildForest(): Forest<Record<string, unknown>, any> {
40
- const { expandAll = false } = props
41
- const childrenKey = props.childrenKey ?? 'children'
42
- const valueKey = fieldKey(props.valueKey, 'value')
43
- const labelKey = fieldKey(props.labelKey, 'label')
44
-
45
- return new Forest<Record<string, unknown>, any>({
46
- data: (props.data ?? []) as Record<string, unknown>[],
47
- childrenKey,
48
- createNode: (data, index, depth, _f, parent) => {
49
- const node = new TreeNode({
50
- data: data as Record<string, any>,
51
- index,
52
- depth,
53
- parent: parent as TreeNode | undefined,
54
- valueKey,
55
- labelKey
56
- })
57
- node.expanded = expandAll
58
- return node
59
- }
60
- })
61
- }
62
-
63
34
  function rebuildForest(): void {
64
- const nextForest = buildForest()
35
+ const nextForest = createTreeForest(props)
65
36
  const nextDict = new Map<string | number, TreeNode>()
66
- const { disabledNode } = props
67
37
 
68
- // Forest 的 createNode 返回时 children 尚未挂载,因此 disabledNode 必须在
69
- // 整棵树构建完成后再调用,才能安全访问 node.children / node.isLeaf。
38
+ // 整棵树构建完成后节点才是完整的,disabledNode / showCheckbox 由 createTreeForest
39
+ // 在此之后统一判定,这里只需收集节点字典。
70
40
  nextForest.dfs((node) => {
71
- if (disabledNode && node.data) {
72
- node.disabled = disabledNode(node.data as Record<string, any>, node) ?? false
73
- }
74
- nextDict.set(node.key, node)
41
+ const tn = node as unknown as TreeNode
42
+ nextDict.set(tn.key, tn)
75
43
  })
76
44
 
77
45
  forestRef.value = nextForest
@@ -112,6 +80,7 @@ export function useTreeNodes(options: Options): UseTreeNodesReturned {
112
80
  [
113
81
  () => props.data,
114
82
  () => props.disabledNode,
83
+ () => props.showCheckbox,
115
84
  () => props.childrenKey,
116
85
  () => props.valueKey,
117
86
  () => props.labelKey,
@@ -1,7 +1,7 @@
1
1
  import type { DeconstructValue, FormComponentProps } from '@veltra/utils'
2
2
  import type { CSSProperties } from 'vue'
3
3
 
4
- import type { TreeProps } from './tree'
4
+ import type { TreeProps, TreeNode } from './tree'
5
5
  /** 树形多选组件组件属性 */
6
6
  export interface MultiTreeSelectProps
7
7
  extends
@@ -9,6 +9,14 @@ export interface MultiTreeSelectProps
9
9
  Omit<TreeProps, 'selected' | 'checked' | 'selectable' | 'checkable' | 'data'> {
10
10
  modelValue?: (string | number)[]
11
11
 
12
+ /**
13
+ * 是否渲染某个节点的复选框,签名与 `UTree` 一致,返回值原样透传给内部树。
14
+ * @description 返回 `false` 的节点不渲染 checkbox,也不会作为勾选值:头部全选总数、
15
+ * 标签回显与 `modelValue` 联动都跳过它;其后代各自判定,不受影响。
16
+ * @default 不传时每个节点都渲染复选框
17
+ */
18
+ showCheckbox?: (item: Record<string, any>, node: TreeNode) => boolean
19
+
12
20
  /**
13
21
  * 树数据
14
22
  * @description 如果传入一个函数,那么filterable会被强制启用;
package/src/types/tree.ts CHANGED
@@ -17,6 +17,8 @@ export interface TreeNode<Data extends Record<string, any> = Record<string, any>
17
17
  checked: boolean
18
18
  indeterminate: boolean
19
19
  disabled: boolean
20
+ /** 是否渲染复选框,由 `showCheckbox` 在整棵树构建完成后判定,默认 true */
21
+ showCheckbox: boolean
20
22
  label: string
21
23
  key: string | number
22
24
  childrenCheckCount: number
@@ -51,6 +53,13 @@ export interface TreeProps {
51
53
  * 在整棵树构建完成后调用,可安全访问 `node.children` / `node.isLeaf`。
52
54
  */
53
55
  disabledNode?: (item: Record<string, any>, node: TreeNode) => boolean
56
+ /**
57
+ * 是否渲染某个节点的复选框。返回 `false` 的节点不渲染 checkbox,也不作为勾选值参与
58
+ * 级联勾选、向上冒泡、全选与 `update:checked`;其后代各自判定,不受影响。
59
+ * 在整棵树构建完成后调用,可安全访问 `node.children` / `node.isLeaf`。
60
+ * @default 不传时每个节点都渲染复选框
61
+ */
62
+ showCheckbox?: (item: Record<string, any>, node: TreeNode) => boolean
54
63
  /** 可多选 */
55
64
  checkable?: boolean
56
65
  /**