mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-30 21:09:53 +00:00
Enable ts-strict for treeUtil.ts (#1238)
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
// @ts-strict-ignore
|
||||
import type { TreeNode } from 'primevue/treenode'
|
||||
|
||||
export function buildTree<T>(
|
||||
items: T[],
|
||||
key: string | ((item: T) => string[])
|
||||
): TreeNode {
|
||||
export function buildTree<T>(items: T[], key: (item: T) => string[]): TreeNode {
|
||||
const root: TreeNode = {
|
||||
key: 'root',
|
||||
label: 'root',
|
||||
@@ -16,7 +12,7 @@ export function buildTree<T>(
|
||||
}
|
||||
|
||||
for (const item of items) {
|
||||
const keys = typeof key === 'string' ? item[key] : key(item)
|
||||
const keys = key(item)
|
||||
let parent = root
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i]
|
||||
@@ -33,7 +29,7 @@ export function buildTree<T>(
|
||||
children: []
|
||||
}
|
||||
map[id] = node
|
||||
parent.children.push(node)
|
||||
parent.children?.push(node)
|
||||
}
|
||||
parent = map[id]
|
||||
}
|
||||
@@ -63,7 +59,7 @@ export function sortedTree(node: TreeNode): TreeNode {
|
||||
if (node.children) {
|
||||
// Sort the children of the current node
|
||||
const sortedChildren = [...node.children].sort((a, b) =>
|
||||
a.label.localeCompare(b.label)
|
||||
(a.label ?? '').localeCompare(b.label ?? '')
|
||||
)
|
||||
// Recursively sort the children and add them to the new node
|
||||
newNode.children = []
|
||||
|
||||
Reference in New Issue
Block a user