mirror of
https://github.com/ByteAtATime/raycast-linux.git
synced 2025-09-02 12:17:24 +00:00
37 lines
1 KiB
TypeScript
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;
|
|
}
|