Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-registry-titles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": patch
---

Include registry item titles in `searchRegistries` results and fuzzy matching.
1 change: 1 addition & 0 deletions apps/v4/content/docs/registry/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Returns matching items wrapped in pagination metadata:
"items": [
{
"name": "button",
"title": "Button",
"type": "registry:ui",
"description": "A button component.",
"registry": "@shadcn",
Expand Down
7 changes: 7 additions & 0 deletions apps/v4/registry/directory.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"description": "Puffy, pastel claymorphism components and app blocks for React, built with Tailwind CSS v4 and Radix UI.",
"logo": "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect x='3' y='3' width='26' height='26' rx='9' fill='#c9a8ff'/><path d='M5 12c5-5 17-5 22 0v8c-5 5-17 5-22 0z' fill='var(--foreground)' fill-opacity='.16'/></svg>"
},
{
"name": "@23rd",
"homepage": "https://23rd.dev",
"url": "https://23rd.dev/r/{name}.json",
"description": "Opinionated components for shippers.",
"logo": "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200' fill='none'><rect width='200' height='200' rx='11' fill='black'/><path d='M21.5 30H163.5L21.5 128.5L177.5 96.5V136.5V186H21.5' stroke='white' stroke-width='8'/><path d='M70 7H90V192H70V7Z' fill='white'/><path d='M110 7H130V192H110V7Z' fill='white'/></svg>"
},
{
"name": "@7ovr",
"homepage": "https://7ovr.com",
Expand Down
1 change: 1 addition & 0 deletions packages/shadcn/src/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export const registryResolvedItemsTreeSchema = registryItemCommonSchema

export const searchResultItemSchema = z.object({
name: z.string(),
title: z.string().optional(),
type: z.string().optional(),
description: z.string().optional(),
registry: z.string(),
Expand Down
43 changes: 43 additions & 0 deletions packages/shadcn/src/registry/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("searchRegistries", () => {
items: [
{
name: "button",
title: "Button",
type: "registry:ui",
description: "A button component",
},
Expand Down Expand Up @@ -64,6 +65,7 @@ describe("searchRegistries", () => {
items: [
{
name: "button",
title: "Button",
type: "registry:ui",
description: "A button component",
registry: "@shadcn",
Expand Down Expand Up @@ -95,6 +97,47 @@ describe("searchRegistries", () => {
mockGetRegistry.mockRestore()
})

it("includes titles in the SDK output and searches them", async () => {
vi.mock("./api", () => ({
getRegistry: vi.fn(),
}))

const mockGetRegistry = vi.mocked(getRegistry)

mockGetRegistry.mockResolvedValue({
name: "test/registry",
homepage: "https://test.com",
items: [
{
name: "account-menu",
title: "User Settings",
type: "registry:ui",
description: "An account menu",
},
{
name: "button",
type: "registry:ui",
description: "A button component",
},
],
})

const results = await searchRegistries(["@test"], { query: "settings" })

expect(results.items).toEqual([
{
name: "account-menu",
title: "User Settings",
type: "registry:ui",
description: "An account menu",
registry: "@test",
addCommandArgument: "@test/account-menu",
},
])

mockGetRegistry.mockRestore()
})

it("should apply search filter when query is provided", async () => {
vi.mock("./api", () => ({
getRegistry: vi.fn(),
Expand Down
5 changes: 4 additions & 1 deletion packages/shadcn/src/registry/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async function searchRegistriesWithContext(

const itemsWithRegistry = (outcome.value.items || []).map((item) => ({
name: item.name,
title: item.title,
type: item.type,
description: item.description,
registry,
Expand Down Expand Up @@ -207,7 +208,7 @@ async function searchRegistriesWithContext(
localItems = searchItems(localItems, {
query,
limit: localItems.length,
keys: ["name", "description"],
keys: ["name", "title", "description"],
}) as z.infer<typeof searchResultItemSchema>[]
}

Expand Down Expand Up @@ -259,6 +260,7 @@ async function searchRegistriesWithContext(
const searchableItemSchema = z
.object({
name: z.string(),
title: z.string().optional(),
type: z.string().optional(),
description: z.string().optional(),
registry: z.string().optional(),
Expand All @@ -271,6 +273,7 @@ type SearchableItem = z.infer<typeof searchableItemSchema>
function searchItems<
T extends {
name: string
title?: string
type?: string
description?: string
addCommandArgument?: string
Expand Down
Loading