@dataloop-ai/components 0.20.162 → 0.20.163

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": "@dataloop-ai/components",
3
- "version": "0.20.162",
3
+ "version": "0.20.163",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -78,12 +78,70 @@ export function useTreeTableRowSelection(
78
78
  selectedItemsNested.value = []
79
79
  }
80
80
 
81
+ function getParentIds(childId: string): string[] {
82
+ const rows = computedRows.value as DlTableRow[]
83
+ const roots = Array.isArray(rows) ? rows : [rows]
84
+ const stack = roots.map((n) => [n, []])
85
+
86
+ while (stack.length) {
87
+ const [node, path]: [DlTableRow, string[]] = stack.pop() as [
88
+ DlTableRow,
89
+ string[]
90
+ ]
91
+ if (node.id === childId) return path as string[]
92
+ const children = (node as DlTableRow).children
93
+ if (Array.isArray(children) && children.length) {
94
+ for (let i = 0; i < children.length; i++) {
95
+ const c = children[i]
96
+ if (c) stack.push([c, path.concat(node.id)])
97
+ }
98
+ }
99
+ }
100
+ return []
101
+ }
102
+
103
+ function isDescendantOf(
104
+ rows: DlTableRow[],
105
+ parentId: string,
106
+ targets: string[]
107
+ ): boolean {
108
+ if (!Array.isArray(rows)) rows = [rows]
109
+
110
+ const targetSet = new Set(Array.isArray(targets) ? targets : [targets])
111
+ targetSet.delete(parentId)
112
+ if (targetSet.size === 0) return false
113
+
114
+ const stack = rows.slice()
115
+ let parent = null
116
+ while (stack.length) {
117
+ const node = stack.pop()
118
+ if (node && node.id === parentId) {
119
+ parent = node
120
+ break
121
+ }
122
+ if (node && node.children && node.children.length)
123
+ stack.push(...node.children)
124
+ }
125
+ if (!parent) return false
126
+
127
+ const sub = (parent.children && parent.children.slice()) || []
128
+ while (sub.length) {
129
+ const n = sub.pop()
130
+ if (targetSet.has(n.id)) return true
131
+ if (n && n.children && n.children.length) sub.push(...n.children)
132
+ }
133
+ return false
134
+ }
135
+
81
136
  function updateSelection(
82
- keys: string[],
137
+ updatedKeys: string[],
83
138
  rows: (string | DlTableRow)[],
84
139
  added: boolean,
85
140
  evt?: (event: string, val: any) => void
86
141
  ) {
142
+ const keys = added
143
+ ? updatedKeys
144
+ : [...getParentIds(updatedKeys[0]), ...updatedKeys]
87
145
  emit('selection', { rows, added, keys, evt })
88
146
 
89
147
  /*
@@ -162,6 +220,15 @@ export function useTreeTableRowSelection(
162
220
  return false
163
221
  }
164
222
  )
223
+ if (
224
+ isDescendantOf(
225
+ computedRows.value,
226
+ rowKeyValue,
227
+ originalRows.map((item) => (item as DlTableRow).id)
228
+ )
229
+ ) {
230
+ return 'partial'
231
+ }
165
232
  }
166
233
  if (getSelectedRowByRowKey && getOriginalRowByRowKey) {
167
234
  if (