@hanzo/ui 4.5.0 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MCP-INSTRUCTIONS.md +73 -0
- package/README-MCP.md +175 -0
- package/bin/cli.js +100 -0
- package/bin/create-registry.js +108 -0
- package/bin/mcp.js +403 -0
- package/bin/npx-registry-mcp.js +15 -0
- package/bin/registry-mcp-wrapper.sh +19 -0
- package/bin/registry-mcp.js +100 -0
- package/bin/start-mcp-server.sh +22 -0
- package/bin/test-mcp.sh +52 -0
- package/bin/update-registry.js +196 -0
- package/blocks/components/screenful-block/index.tsx +2 -0
- package/dist/blocks/components/accordian-block.d.ts +4 -0
- package/dist/blocks/components/accordian-block.jsx +25 -0
- package/dist/blocks/components/block-component-props.d.ts +7 -0
- package/dist/blocks/components/block-component-props.js +1 -0
- package/dist/blocks/components/bullet-cards-block.d.ts +4 -0
- package/dist/blocks/components/bullet-cards-block.jsx +25 -0
- package/dist/blocks/components/card-block/index.d.ts +6 -0
- package/dist/blocks/components/card-block/index.jsx +87 -0
- package/dist/blocks/components/card-block/link-out-button.d.ts +6 -0
- package/dist/blocks/components/card-block/link-out-button.jsx +4 -0
- package/dist/blocks/components/card-block/util.d.ts +4 -0
- package/dist/blocks/components/card-block/util.js +6 -0
- package/dist/blocks/components/carte-blanche-block/index.d.ts +4 -0
- package/dist/blocks/components/carte-blanche-block/index.jsx +82 -0
- package/dist/blocks/components/carte-blanche-block/variant-content-left.d.ts +10 -0
- package/dist/blocks/components/carte-blanche-block/variant-content-left.jsx +23 -0
- package/dist/blocks/components/content.d.ts +10 -0
- package/dist/blocks/components/content.jsx +47 -0
- package/dist/blocks/components/cta-block.d.ts +12 -0
- package/dist/blocks/components/cta-block.jsx +69 -0
- package/dist/blocks/components/enh-heading-block.d.ts +7 -0
- package/dist/blocks/components/enh-heading-block.jsx +142 -0
- package/dist/blocks/components/grid-block/grid-block-mutator.d.ts +5 -0
- package/dist/blocks/components/grid-block/grid-block-mutator.js +1 -0
- package/dist/blocks/components/grid-block/index.d.ts +9 -0
- package/dist/blocks/components/grid-block/index.jsx +56 -0
- package/dist/blocks/components/grid-block/mutator-registry.d.ts +3 -0
- package/dist/blocks/components/grid-block/mutator-registry.js +5 -0
- package/dist/blocks/components/grid-block/table-borders.mutator.d.ts +3 -0
- package/dist/blocks/components/grid-block/table-borders.mutator.js +36 -0
- package/dist/blocks/components/group-block.d.ts +7 -0
- package/dist/blocks/components/group-block.jsx +61 -0
- package/dist/blocks/components/heading-block.d.ts +4 -0
- package/dist/blocks/components/heading-block.jsx +99 -0
- package/dist/blocks/components/image-block.d.ts +7 -0
- package/dist/blocks/components/image-block.jsx +69 -0
- package/dist/blocks/components/index.d.ts +14 -0
- package/dist/blocks/components/index.js +13 -0
- package/dist/blocks/components/screenful-block/content.d.ts +8 -0
- package/dist/blocks/components/screenful-block/content.jsx +71 -0
- package/dist/blocks/components/screenful-block/index.d.ts +12 -0
- package/dist/blocks/components/screenful-block/index.jsx +57 -0
- package/dist/blocks/components/screenful-block/poster-background.d.ts +7 -0
- package/dist/blocks/components/screenful-block/poster-background.jsx +14 -0
- package/dist/blocks/components/screenful-block/video-background.d.ts +8 -0
- package/dist/blocks/components/screenful-block/video-background.jsx +20 -0
- package/dist/blocks/components/space-block.d.ts +4 -0
- package/dist/blocks/components/space-block.jsx +42 -0
- package/dist/blocks/components/video-block.d.ts +9 -0
- package/dist/blocks/components/video-block.jsx +83 -0
- package/dist/blocks/def/accordian-block.d.ts +10 -0
- package/dist/blocks/def/accordian-block.js +2 -0
- package/dist/blocks/def/block.d.ts +4 -0
- package/dist/blocks/def/block.js +1 -0
- package/dist/blocks/def/bullet-cards-block.d.ts +17 -0
- package/dist/blocks/def/bullet-cards-block.js +1 -0
- package/dist/blocks/def/card-block.d.ts +17 -0
- package/dist/blocks/def/card-block.js +2 -0
- package/dist/blocks/def/carte-blanche-block.d.ts +12 -0
- package/dist/blocks/def/carte-blanche-block.js +1 -0
- package/dist/blocks/def/cta-block.d.ts +8 -0
- package/dist/blocks/def/cta-block.js +1 -0
- package/dist/blocks/def/element-block.d.ts +7 -0
- package/dist/blocks/def/element-block.js +2 -0
- package/dist/blocks/def/enh-heading-block.d.ts +22 -0
- package/dist/blocks/def/enh-heading-block.js +1 -0
- package/dist/blocks/def/grid-block.d.ts +12 -0
- package/dist/blocks/def/grid-block.js +1 -0
- package/dist/blocks/def/group-block.d.ts +7 -0
- package/dist/blocks/def/group-block.js +1 -0
- package/dist/blocks/def/heading-block.d.ts +11 -0
- package/dist/blocks/def/heading-block.js +1 -0
- package/dist/blocks/def/image-block.d.ts +26 -0
- package/dist/blocks/def/image-block.js +1 -0
- package/dist/blocks/def/index.d.ts +17 -0
- package/dist/blocks/def/index.js +2 -0
- package/dist/blocks/def/screenful-block.d.ts +41 -0
- package/dist/blocks/def/screenful-block.js +1 -0
- package/dist/blocks/def/space-block.d.ts +47 -0
- package/dist/blocks/def/space-block.js +8 -0
- package/dist/blocks/def/video-block.d.ts +5 -0
- package/dist/blocks/def/video-block.js +1 -0
- package/dist/blocks/index.d.ts +2 -0
- package/dist/blocks/index.js +2 -0
- package/dist/mcp/enhanced-server.d.ts +29 -0
- package/dist/mcp/enhanced-server.js +1128 -0
- package/dist/mcp/index.d.ts +28 -0
- package/dist/mcp/index.js +436 -0
- package/dist/primitives/accordion.d.ts +10 -0
- package/dist/primitives/accordion.jsx +21 -0
- package/dist/primitives/action-button.d.ts +9 -0
- package/dist/primitives/action-button.jsx +16 -0
- package/dist/primitives/apply-typography.d.ts +7 -0
- package/dist/primitives/apply-typography.jsx +38 -0
- package/dist/primitives/aspect-ratio.d.ts +3 -0
- package/dist/primitives/aspect-ratio.jsx +4 -0
- package/dist/primitives/avatar.d.ts +6 -0
- package/dist/primitives/avatar.jsx +11 -0
- package/dist/primitives/badge.d.ts +9 -0
- package/dist/primitives/badge.jsx +18 -0
- package/dist/primitives/breadcrumb.d.ts +19 -0
- package/dist/primitives/breadcrumb.jsx +27 -0
- package/dist/primitives/breakpoint-indicator.d.ts +3 -0
- package/dist/primitives/breakpoint-indicator.jsx +14 -0
- package/dist/primitives/button.d.ts +12 -0
- package/dist/primitives/button.jsx +55 -0
- package/dist/primitives/calendar.d.ts +8 -0
- package/dist/primitives/calendar.jsx +40 -0
- package/dist/primitives/card.d.ts +8 -0
- package/dist/primitives/card.jsx +18 -0
- package/dist/primitives/carousel.d.ts +18 -0
- package/dist/primitives/carousel.jsx +106 -0
- package/dist/primitives/checkbox.d.ts +4 -0
- package/dist/primitives/checkbox.jsx +15 -0
- package/dist/primitives/combobox.d.ts +41 -0
- package/dist/primitives/combobox.jsx +77 -0
- package/dist/primitives/command.d.ts +17 -0
- package/dist/primitives/command.jsx +38 -0
- package/dist/primitives/context-menu.d.ts +27 -0
- package/dist/primitives/context-menu.jsx +57 -0
- package/dist/primitives/dialog-video-controller.d.ts +3 -0
- package/dist/primitives/dialog-video-controller.jsx +24 -0
- package/dist/primitives/dialog.d.ts +28 -0
- package/dist/primitives/dialog.jsx +37 -0
- package/dist/primitives/drawer.d.ts +29 -0
- package/dist/primitives/drawer.jsx +34 -0
- package/dist/primitives/form.d.ts +12 -0
- package/dist/primitives/form.jsx +69 -0
- package/dist/primitives/icons/github.d.ts +4 -0
- package/dist/primitives/icons/github.jsx +6 -0
- package/dist/primitives/icons/index.d.ts +4 -0
- package/dist/primitives/icons/index.js +4 -0
- package/dist/primitives/icons/youtube-logo.d.ts +4 -0
- package/dist/primitives/icons/youtube-logo.jsx +39 -0
- package/dist/primitives/index-common.d.ts +47 -0
- package/dist/primitives/index-common.js +46 -0
- package/dist/primitives/index-next.d.ts +2 -0
- package/dist/primitives/index-next.js +2 -0
- package/dist/primitives/input-otp.d.ts +7 -0
- package/dist/primitives/input-otp.jsx +24 -0
- package/dist/primitives/input.d.ts +5 -0
- package/dist/primitives/input.jsx +11 -0
- package/dist/primitives/label.d.ts +5 -0
- package/dist/primitives/label.jsx +11 -0
- package/dist/primitives/list-adaptor.d.ts +9 -0
- package/dist/primitives/list-adaptor.js +1 -0
- package/dist/primitives/list-box.d.ts +10 -0
- package/dist/primitives/list-box.jsx +14 -0
- package/dist/primitives/loading-spinner.d.ts +5 -0
- package/dist/primitives/loading-spinner.jsx +8 -0
- package/dist/primitives/navigation-menu.d.ts +12 -0
- package/dist/primitives/navigation-menu.jsx +38 -0
- package/dist/primitives/next/image.d.ts +11 -0
- package/dist/primitives/next/image.jsx +42 -0
- package/dist/primitives/next/index.d.ts +7 -0
- package/dist/primitives/next/index.js +7 -0
- package/dist/primitives/next/inline-icon.d.ts +13 -0
- package/dist/primitives/next/inline-icon.jsx +15 -0
- package/dist/primitives/next/link-element.d.ts +23 -0
- package/dist/primitives/next/link-element.jsx +56 -0
- package/dist/primitives/next/mdx-link.d.ts +3 -0
- package/dist/primitives/next/mdx-link.jsx +12 -0
- package/dist/primitives/next/media-stack.d.ts +8 -0
- package/dist/primitives/next/media-stack.jsx +28 -0
- package/dist/primitives/next/nav-items.d.ts +10 -0
- package/dist/primitives/next/nav-items.jsx +24 -0
- package/dist/primitives/next/youtube-embed.d.ts +11 -0
- package/dist/primitives/next/youtube-embed.jsx +23 -0
- package/dist/primitives/popover.d.ts +9 -0
- package/dist/primitives/popover.jsx +18 -0
- package/dist/primitives/progress.d.ts +4 -0
- package/dist/primitives/progress.jsx +9 -0
- package/dist/primitives/radio-group.d.ts +7 -0
- package/dist/primitives/radio-group.jsx +18 -0
- package/dist/primitives/scroll-area.d.ts +5 -0
- package/dist/primitives/scroll-area.jsx +19 -0
- package/dist/primitives/select.d.ts +13 -0
- package/dist/primitives/select.jsx +62 -0
- package/dist/primitives/separator.d.ts +4 -0
- package/dist/primitives/separator.jsx +7 -0
- package/dist/primitives/sheet.d.ts +30 -0
- package/dist/primitives/sheet.jsx +56 -0
- package/dist/primitives/skeleton.d.ts +4 -0
- package/dist/primitives/skeleton.jsx +3 -0
- package/dist/primitives/slider.d.ts +9 -0
- package/dist/primitives/slider.jsx +30 -0
- package/dist/primitives/sonner.d.ts +5 -0
- package/dist/primitives/sonner.jsx +16 -0
- package/dist/primitives/step-indicator.d.ts +9 -0
- package/dist/primitives/step-indicator.jsx +23 -0
- package/dist/primitives/switch.d.ts +6 -0
- package/dist/primitives/switch.jsx +14 -0
- package/dist/primitives/table.d.ts +10 -0
- package/dist/primitives/table.jsx +21 -0
- package/dist/primitives/tabs.d.ts +7 -0
- package/dist/primitives/tabs.jsx +18 -0
- package/dist/primitives/text-area.d.ts +5 -0
- package/dist/primitives/text-area.jsx +9 -0
- package/dist/primitives/toggle-group.d.ts +14 -0
- package/dist/primitives/toggle-group.jsx +28 -0
- package/dist/primitives/toggle.d.ts +14 -0
- package/dist/primitives/toggle.jsx +52 -0
- package/dist/primitives/tooltip.d.ts +11 -0
- package/dist/primitives/tooltip.jsx +18 -0
- package/dist/primitives/video-player.d.ts +6 -0
- package/dist/primitives/video-player.jsx +8 -0
- package/dist/registry/api.d.ts +37 -0
- package/dist/registry/api.js +130 -0
- package/dist/registry/index.d.ts +9 -0
- package/dist/registry/index.js +45 -0
- package/dist/style/theme-provider.d.ts +4 -0
- package/dist/style/theme-provider.jsx +11 -0
- package/dist/tailwind/fontFamily.tailwind.d.ts +8 -0
- package/dist/tailwind/fontFamily.tailwind.js +7 -0
- package/dist/tailwind/fontSize.tailwind.d.ts +36 -0
- package/dist/tailwind/fontSize.tailwind.js +13 -0
- package/dist/tailwind/index.d.ts +3 -0
- package/dist/tailwind/index.js +2 -0
- package/dist/tailwind/screens.tailwind.d.ts +9 -0
- package/dist/tailwind/screens.tailwind.js +8 -0
- package/dist/tailwind/tw-font-desc.d.ts +6 -0
- package/dist/tailwind/tw-font-desc.js +6 -0
- package/dist/types/animation-def.d.ts +2 -0
- package/dist/types/animation-def.js +1 -0
- package/dist/types/breakpoints.d.ts +4 -0
- package/dist/types/breakpoints.js +4 -0
- package/dist/types/bullet-item.d.ts +6 -0
- package/dist/types/bullet-item.js +2 -0
- package/dist/types/button-def.d.ts +29 -0
- package/dist/types/button-def.js +2 -0
- package/dist/types/dimensions.d.ts +5 -0
- package/dist/types/dimensions.js +1 -0
- package/dist/types/grid-def.d.ts +36 -0
- package/dist/types/grid-def.js +33 -0
- package/dist/types/image-def.d.ts +27 -0
- package/dist/types/image-def.js +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +2 -0
- package/dist/types/link-def.d.ts +44 -0
- package/dist/types/link-def.js +1 -0
- package/dist/types/media-stack-def.d.ts +25 -0
- package/dist/types/media-stack-def.js +1 -0
- package/dist/types/t-shirt-size.d.ts +2 -0
- package/dist/types/t-shirt-size.js +1 -0
- package/dist/types/tshirt-dimensions.d.ts +12 -0
- package/dist/types/tshirt-dimensions.js +1 -0
- package/dist/types/video-def.d.ts +9 -0
- package/dist/types/video-def.js +1 -0
- package/dist/util/format-and-abbreviate-as-currency.d.ts +11 -0
- package/dist/util/format-and-abbreviate-as-currency.js +91 -0
- package/dist/util/format-to-max-char.d.ts +5 -0
- package/dist/util/format-to-max-char.js +57 -0
- package/dist/util/index-client.d.ts +2 -0
- package/dist/util/index-client.js +3 -0
- package/dist/util/index.d.ts +17 -0
- package/dist/util/index.js +41 -0
- package/dist/util/number-abbreviate.d.ts +9 -0
- package/dist/util/number-abbreviate.js +30 -0
- package/dist/util/specifier.d.ts +7 -0
- package/dist/util/specifier.js +31 -0
- package/dist/util/spread-to-transform.d.ts +7 -0
- package/dist/util/spread-to-transform.js +18 -0
- package/dist/util/step-animation.d.ts +5 -0
- package/dist/util/step-animation.js +60 -0
- package/dist/util/two-way-map.d.ts +8 -0
- package/dist/util/two-way-map.js +16 -0
- package/mcp/README.md +141 -0
- package/mcp/enhanced-server.ts +1208 -0
- package/mcp/index.ts +518 -0
- package/mcp/package.json +10 -0
- package/package.json +34 -14
- package/primitives/accordion.tsx +5 -5
- package/primitives/button.tsx +6 -3
- package/primitives/dialog.tsx +12 -7
- package/primitives/tabs.tsx +1 -1
- package/primitives/tooltip.tsx +1 -1
- package/public/r/accordion.json +11 -0
- package/public/r/alert.json +11 -0
- package/public/r/avatar.json +11 -0
- package/public/r/badge.json +11 -0
- package/public/r/button.json +11 -0
- package/public/r/card.json +11 -0
- package/public/r/checkbox.json +11 -0
- package/public/r/default.json +6 -0
- package/public/r/dialog.json +11 -0
- package/public/r/input.json +11 -0
- package/public/r/label.json +11 -0
- package/public/r/new-york.json +6 -0
- package/public/r/popover.json +11 -0
- package/public/r/select.json +11 -0
- package/public/r/table.json +11 -0
- package/public/r/tabs.json +11 -0
- package/public/r/toast.json +11 -0
- package/registry/api.ts +164 -0
- package/registry/index.ts +60 -0
- package/registry/package.json +10 -0
- package/registry.json +184 -0
- package/test/test-registry.js +73 -0
- package/tsconfig.json +8 -1
package/primitives/dialog.tsx
CHANGED
|
@@ -17,7 +17,7 @@ const DialogPortal = React.forwardRef<
|
|
|
17
17
|
DialogPortalProps
|
|
18
18
|
>(({ className, children, ...props }, ref) => (
|
|
19
19
|
<DialogPrimitive.Portal {...props}>
|
|
20
|
-
<div className={cn("fixed inset-0 z-
|
|
20
|
+
<div className={cn("fixed inset-0 z-50 flex items-end justify-center sm:items-center", className)}>
|
|
21
21
|
{children}
|
|
22
22
|
</div>
|
|
23
23
|
</DialogPrimitive.Portal>
|
|
@@ -32,9 +32,14 @@ const DialogOverlay = React.forwardRef<
|
|
|
32
32
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
33
33
|
DialogOverlayProps
|
|
34
34
|
>(({ className, ...props }, ref) => (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
<DialogPrimitive.Overlay
|
|
36
|
+
ref={ref}
|
|
37
|
+
className={cn(
|
|
38
|
+
"fixed inset-0 z-50 bg-overlay backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
39
|
+
className
|
|
40
|
+
)}
|
|
41
|
+
{...props}
|
|
42
|
+
/>
|
|
38
43
|
))
|
|
39
44
|
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
|
40
45
|
|
|
@@ -50,7 +55,7 @@ const DialogClose = React.forwardRef<
|
|
|
50
55
|
<DialogPrimitive.Close
|
|
51
56
|
ref={ref}
|
|
52
57
|
className={cn(
|
|
53
|
-
"absolute right-4 top-
|
|
58
|
+
"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",
|
|
54
59
|
className
|
|
55
60
|
)}
|
|
56
61
|
{...props}
|
|
@@ -71,7 +76,7 @@ const DialogContent = React.forwardRef<
|
|
|
71
76
|
<DialogPrimitive.Content
|
|
72
77
|
ref={ref}
|
|
73
78
|
className={cn(
|
|
74
|
-
"fixed z-50 grid w-full gap-4 rounded-t-lg bg-level-1 p-
|
|
79
|
+
"fixed z-50 grid w-full gap-4 rounded-t-lg bg-level-1 p-6 shadow-lg animate-in data-[state=open]:fade-in-90 data-[state=open]:slide-in-from-bottom-10 sm:max-w-lg sm:rounded-lg sm:zoom-in-90 data-[state=open]:sm:slide-in-from-bottom-0",
|
|
75
80
|
className
|
|
76
81
|
)}
|
|
77
82
|
{...props}
|
|
@@ -132,7 +137,7 @@ const DialogDescription = React.forwardRef<
|
|
|
132
137
|
>(({ className, ...props }, ref) => (
|
|
133
138
|
<DialogPrimitive.Description
|
|
134
139
|
ref={ref}
|
|
135
|
-
className={cn("text-sm text-muted", className)}
|
|
140
|
+
className={cn("text-sm text-muted-1", className)}
|
|
136
141
|
{...props}
|
|
137
142
|
/>
|
|
138
143
|
))
|
package/primitives/tabs.tsx
CHANGED
|
@@ -13,7 +13,7 @@ const TabsList = React.forwardRef<
|
|
|
13
13
|
<TabsPrimitive.List
|
|
14
14
|
ref={ref}
|
|
15
15
|
className={cn(
|
|
16
|
-
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-foreground',
|
|
16
|
+
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground',
|
|
17
17
|
className
|
|
18
18
|
)}
|
|
19
19
|
{...props}
|
package/primitives/tooltip.tsx
CHANGED
|
@@ -19,7 +19,7 @@ const TooltipContent = React.forwardRef<
|
|
|
19
19
|
ref={ref}
|
|
20
20
|
sideOffset={sideOffset}
|
|
21
21
|
className={cn(
|
|
22
|
-
'z-
|
|
22
|
+
'z-50 overflow-hidden rounded-md border bg-level-1 px-3 py-1.5 text-sm text-muted-foreground shadow-md animate-in fade-in-50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
23
23
|
className
|
|
24
24
|
)}
|
|
25
25
|
{...props}
|
package/registry/api.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { registryItemSchema, RegistryItem, Registry } from "."
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
const registryCache = new Map<string, Promise<any>>()
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gets the full registry URL based on the registry name or URL provided
|
|
8
|
+
* @param registry - Registry name, URL, or file path
|
|
9
|
+
* @returns The complete registry URL
|
|
10
|
+
*/
|
|
11
|
+
export function getRegistryUrl(registry: string): string {
|
|
12
|
+
// Check if registry is a full URL
|
|
13
|
+
if (registry.startsWith("http")) {
|
|
14
|
+
return registry
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Default to Hanzo registry if REGISTRY_BASE_URL is defined, otherwise use shadcn
|
|
18
|
+
const baseUrl = process.env.REGISTRY_BASE_URL || "https://ui.shadcn.com/registry"
|
|
19
|
+
|
|
20
|
+
// Check if registry is a path to a JSON file
|
|
21
|
+
if (registry.endsWith(".json")) {
|
|
22
|
+
return `${baseUrl}/${registry}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Assume registry is a registry style
|
|
26
|
+
return `${baseUrl}/${registry}/registry.json`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fetches a specific registry item by URL
|
|
31
|
+
* @param itemUrl - The URL of the item to fetch
|
|
32
|
+
* @param basePath - Base path for resolving imports
|
|
33
|
+
* @returns The registry item or null if not found
|
|
34
|
+
*/
|
|
35
|
+
export async function getRegistryItem(
|
|
36
|
+
itemUrl: string,
|
|
37
|
+
basePath: string
|
|
38
|
+
): Promise<RegistryItem | null> {
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(itemUrl)
|
|
41
|
+
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
console.error(`Failed to fetch registry item from ${itemUrl}: ${response.status} ${response.statusText}`)
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const item = await response.json()
|
|
48
|
+
const validatedItem = registryItemSchema.safeParse(item)
|
|
49
|
+
|
|
50
|
+
if (!validatedItem.success) {
|
|
51
|
+
console.error(`Invalid registry item format: ${JSON.stringify(validatedItem.error)}`)
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Process and resolve file paths
|
|
56
|
+
if (validatedItem.data.files) {
|
|
57
|
+
for (const file of validatedItem.data.files) {
|
|
58
|
+
if (!file.content) {
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If the file has a target, we resolve it from the target
|
|
63
|
+
if (file.target) {
|
|
64
|
+
file.target = resolveImport(file.target, basePath)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return validatedItem.data
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(`Error fetching registry item: ${error}`)
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resolves an import path relative to a base path
|
|
78
|
+
* @param importPath - The import path to resolve
|
|
79
|
+
* @param basePath - The base path to resolve against
|
|
80
|
+
* @returns The resolved import path
|
|
81
|
+
*/
|
|
82
|
+
export function resolveImport(importPath: string, basePath: string): string {
|
|
83
|
+
const importParts = importPath?.split("/")
|
|
84
|
+
|
|
85
|
+
// Check if it's a relative import
|
|
86
|
+
if (importPath.startsWith(".")) {
|
|
87
|
+
return [basePath.replace(/^@/, ""), ...importParts].filter(Boolean).join("/")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if it's a scope package
|
|
91
|
+
if (importParts?.[0]?.startsWith("@")) {
|
|
92
|
+
return importPath
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return importPath
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Fetches registry data from one or more paths
|
|
100
|
+
* @param paths - Array of registry paths to fetch
|
|
101
|
+
* @param options - Options for fetching the registry
|
|
102
|
+
* @returns Array of registry data
|
|
103
|
+
*/
|
|
104
|
+
export async function fetchRegistry(
|
|
105
|
+
paths: string[],
|
|
106
|
+
options: { useCache?: boolean } = {}
|
|
107
|
+
): Promise<Registry[]> {
|
|
108
|
+
options = {
|
|
109
|
+
useCache: true,
|
|
110
|
+
...options,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const results = await Promise.all(
|
|
115
|
+
paths.map(async (path) => {
|
|
116
|
+
const url = getRegistryUrl(path)
|
|
117
|
+
|
|
118
|
+
// Check cache first if caching is enabled
|
|
119
|
+
if (options.useCache && registryCache.has(url)) {
|
|
120
|
+
return registryCache.get(url)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Store the promise in the cache before awaiting if caching is enabled
|
|
124
|
+
const fetchPromise = (async () => {
|
|
125
|
+
const response = await fetch(url)
|
|
126
|
+
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Failed to fetch registry from ${url}. ${response.status} ${response.statusText}`
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return response.json()
|
|
134
|
+
})()
|
|
135
|
+
|
|
136
|
+
if (options.useCache) {
|
|
137
|
+
registryCache.set(url, fetchPromise)
|
|
138
|
+
}
|
|
139
|
+
return fetchPromise
|
|
140
|
+
})
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return results
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error(`Error fetching registry: ${error}`)
|
|
146
|
+
throw error
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Gets the URL for a specific registry item
|
|
152
|
+
* @param itemName - The name of the registry item
|
|
153
|
+
* @param registryUrl - The base registry URL
|
|
154
|
+
* @returns The URL for the specific registry item
|
|
155
|
+
*/
|
|
156
|
+
export function getRegistryItemUrl(itemName: string, registryUrl: string): string {
|
|
157
|
+
const registryBaseUrl = registryUrl.replace(/\/registry\.json$/, "")
|
|
158
|
+
return `${registryBaseUrl}/r/${itemName}.json`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Support CommonJS
|
|
162
|
+
if (typeof module !== 'undefined') {
|
|
163
|
+
module.exports = { getRegistryUrl, getRegistryItem, resolveImport, fetchRegistry, getRegistryItemUrl }
|
|
164
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
// Define the file schema to match shadcn/ui's format
|
|
4
|
+
export const fileSchema = z.object({
|
|
5
|
+
path: z.string(),
|
|
6
|
+
content: z.string().optional(),
|
|
7
|
+
type: z.string(),
|
|
8
|
+
target: z.string().optional(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// Registry item schema aligned with shadcn/ui format
|
|
12
|
+
export const registryItemSchema = z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
type: z.string(),
|
|
15
|
+
description: z.string().optional(),
|
|
16
|
+
author: z.string().optional(),
|
|
17
|
+
dependencies: z.array(z.string()).optional(),
|
|
18
|
+
devDependencies: z.array(z.string()).optional(),
|
|
19
|
+
registryDependencies: z.array(z.string()).optional(),
|
|
20
|
+
files: z.array(fileSchema).optional(),
|
|
21
|
+
meta: z.record(z.any()).optional(),
|
|
22
|
+
title: z.string().optional(),
|
|
23
|
+
cssVars: z.record(z.any()).optional(),
|
|
24
|
+
tailwind: z.record(z.any()).optional(),
|
|
25
|
+
category: z.string().optional(),
|
|
26
|
+
subcategory: z.string().optional(),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Registry schema aligned with shadcn/ui format
|
|
30
|
+
export const registrySchema = z.object({
|
|
31
|
+
$schema: z.string().optional(),
|
|
32
|
+
name: z.string(),
|
|
33
|
+
homepage: z.string().optional(),
|
|
34
|
+
style: z.string().optional(),
|
|
35
|
+
items: z.array(registryItemSchema),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Schema for a registry with full content
|
|
39
|
+
export const registryWithContentSchema = registrySchema.extend({
|
|
40
|
+
items: z.array(
|
|
41
|
+
registryItemSchema.extend({
|
|
42
|
+
files: z.array(
|
|
43
|
+
fileSchema.extend({
|
|
44
|
+
content: z.string(),
|
|
45
|
+
})
|
|
46
|
+
),
|
|
47
|
+
})
|
|
48
|
+
),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Type definitions for easier use in TypeScript
|
|
52
|
+
export type RegistryItem = z.infer<typeof registryItemSchema>
|
|
53
|
+
export type Registry = z.infer<typeof registrySchema>
|
|
54
|
+
export type RegistryWithContent = z.infer<typeof registryWithContentSchema>
|
|
55
|
+
export type RegistryFile = z.infer<typeof fileSchema>
|
|
56
|
+
|
|
57
|
+
// Support CommonJS
|
|
58
|
+
if (typeof module !== 'undefined') {
|
|
59
|
+
module.exports = { fileSchema, registryItemSchema, registrySchema, registryWithContentSchema }
|
|
60
|
+
}
|