Files
shadcn-ui/apps/v4/app/(create)/lib/utils.ts
shadcn 86d9b00084 chore: update deps (#9022)
* feat: init

* fix

* fix

* fix

* feat

* feat

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: implement icons

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: update init command

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: dialog

* feat

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: add registry:base item type

* feat: rename frame to canva

* fix

* feat

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fi

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: add all colors

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* feat: add outfit font

* fix

* fix

* fix

* fix

* fix

* chore: changeset

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
2025-12-12 21:01:44 +04:00

45 lines
1.1 KiB
TypeScript

import { type RegistryItem } from "shadcn/schema"
const mapping = {
"registry:block": "Blocks",
"registry:example": "Components",
}
export function groupItemsByType(
items: Pick<RegistryItem, "name" | "title" | "type">[]
) {
const grouped = items.reduce(
(acc, item) => {
acc[item.type] = [...(acc[item.type] || []), item]
return acc
},
{} as Record<string, Pick<RegistryItem, "name" | "title" | "type">[]>
)
return Object.entries(grouped)
.map(([type, items]) => ({
type,
title: mapping[type as keyof typeof mapping] || type,
items,
}))
.sort((a, b) => {
const aIndex = Object.keys(mapping).indexOf(a.type)
const bIndex = Object.keys(mapping).indexOf(b.type)
// If both are in mapping, sort by their order.
if (aIndex !== -1 && bIndex !== -1) {
return aIndex - bIndex
}
// If only a is in mapping, it comes first.
if (aIndex !== -1) {
return -1
}
// If only b is in mapping, it comes first.
if (bIndex !== -1) {
return 1
}
// If neither is in mapping, maintain original order.
return 0
})
}