web-component-gallery 2.3.7 → 2.3.8

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/utils/Tree.js CHANGED
@@ -96,7 +96,7 @@ export function joinTreeMessage(
96
96
  node[replaceField] = fields
97
97
  .filter(field => node[field])
98
98
  .map(field => node[field])
99
- .join(' ');
99
+ .join(' ')
100
100
 
101
101
  if (Array.isArray(node[childNode])) {
102
102
  node[childNode].forEach(processNode)
@@ -151,9 +151,7 @@ export function getAllParents(tree, nodeId, { children = 'children', key = 'id'
151
151
  metaInfo.set(node, { parentId })
152
152
  nodeMap.set(node[key], { node, metaInfo })
153
153
 
154
- if (node[children] && Array.isArray(node[children])) {
155
- buildMap(node[children], node[key])
156
- }
154
+ if (node[children]?.length) buildMap(node[children], node[key])
157
155
  })
158
156
  }
159
157
  buildMap(tree)
@@ -162,14 +160,17 @@ export function getAllParents(tree, nodeId, { children = 'children', key = 'id'
162
160
  const path = []
163
161
  let current = nodeMap.get(nodeId)
164
162
  while (current) {
165
- returnObjects
166
- ? path.unshift(current.node) // 直接返回原对象
167
- : path.unshift(current.node[key])
168
-
169
- const parentId = current.metaInfo.get(current.node)?.parentId
170
- current = parentId ? nodeMap.get(parentId) : null
163
+ if (returnObjects) {
164
+ // 直接返回原对象
165
+ path.unshift(current.node)
166
+ } else {
167
+ path.unshift(current.node[key])
168
+ }
169
+ current = current.metaInfo.get(current.node).parentId
170
+ ? nodeMap.get(current.metaInfo.get(current.node).parentId)
171
+ : null
171
172
  }
172
173
 
173
174
  // 对象集合则返回父级
174
- return returnObjects ? path.slice(0, -1) : path.slice(0, -1)
175
- }
175
+ return returnObjects ? path[0] : path
176
+ }