raycast-linux/src/lib/components/nodes/shared/dropdown.ts
2025-07-09 10:11:16 -07:00

37 lines
1 KiB
TypeScript

import type { UINode } from '$lib/types';
import { getTypedProps, type DropdownItemProps } from '$lib/props';
export function getDropdownItems(node: UINode, uiTree: Map<number, UINode>): DropdownItemProps[] {
const items: DropdownItemProps[] = [];
if (!node) return items;
function traverse(children: number[]) {
for (const childId of children) {
const childNode = uiTree.get(childId);
if (!childNode) continue;
if (
childNode.type === 'List.Dropdown.Item' ||
childNode.type === 'Grid.Dropdown.Item' ||
childNode.type === 'Form.Dropdown.Item'
) {
const itemProps = getTypedProps({
...childNode,
type: 'List.Dropdown.Item'
});
if (itemProps) {
items.push(itemProps);
}
} else if (
childNode.type === 'List.Dropdown.Section' ||
childNode.type === 'Grid.Dropdown.Section' ||
childNode.type === 'Form.Dropdown.Section'
) {
if (childNode.children) traverse(childNode.children);
}
}
}
if (node.children) traverse(node.children);
return items;
}