@tc96/cli 0.0.0-stage → 0.27.0

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.
Files changed (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -2
  3. package/cli.js +1395 -0
  4. package/package.json +35 -4
  5. package/registry/agent-builder.json +503 -0
  6. package/registry/aggregate.json +4 -0
  7. package/registry/app-shell-1.json +81 -0
  8. package/registry/app-shell-2.json +89 -0
  9. package/registry/app-shell-3.json +109 -0
  10. package/registry/app-shell-4.json +104 -0
  11. package/registry/app-shell-5.json +106 -0
  12. package/registry/bulk-import-1.json +151 -0
  13. package/registry/card-1.json +104 -0
  14. package/registry/card-2.json +97 -0
  15. package/registry/card-3.json +104 -0
  16. package/registry/card-4.json +98 -0
  17. package/registry/card-5.json +85 -0
  18. package/registry/card-6.json +98 -0
  19. package/registry/card-7.json +104 -0
  20. package/registry/card-8.json +106 -0
  21. package/registry/card-9.json +92 -0
  22. package/registry/charts.json +30 -0
  23. package/registry/chat-assistant.json +110 -0
  24. package/registry/chats-panel.json +97 -0
  25. package/registry/checklist.json +307 -0
  26. package/registry/collection-layouts.json +836 -0
  27. package/registry/collection-views.json +836 -0
  28. package/registry/collection.json +831 -0
  29. package/registry/dashboard-1.json +160 -0
  30. package/registry/dashboard-2.json +153 -0
  31. package/registry/dashboard-3.json +154 -0
  32. package/registry/dashboard-4.json +168 -0
  33. package/registry/detail-sheet.json +54 -0
  34. package/registry/editable.json +36 -0
  35. package/registry/empty-state-1.json +40 -0
  36. package/registry/empty-state-2.json +39 -0
  37. package/registry/empty-state-3.json +61 -0
  38. package/registry/empty-state-4.json +39 -0
  39. package/registry/empty-state-5.json +47 -0
  40. package/registry/empty-state-6.json +40 -0
  41. package/registry/flow-canvas.json +198 -0
  42. package/registry/flow-inspector.json +151 -0
  43. package/registry/flow-step-library.json +112 -0
  44. package/registry/forgot-password-1.json +73 -0
  45. package/registry/forgot-password-2.json +73 -0
  46. package/registry/icon-row.json +52 -0
  47. package/registry/impact-map.json +75 -0
  48. package/registry/list-1.json +129 -0
  49. package/registry/list-2.json +117 -0
  50. package/registry/list-3.json +129 -0
  51. package/registry/list-4.json +105 -0
  52. package/registry/list-5.json +98 -0
  53. package/registry/list-6.json +92 -0
  54. package/registry/list.json +52 -0
  55. package/registry/login-1.json +89 -0
  56. package/registry/login-10.json +88 -0
  57. package/registry/login-2.json +81 -0
  58. package/registry/login-3.json +90 -0
  59. package/registry/login-4.json +81 -0
  60. package/registry/login-5.json +82 -0
  61. package/registry/login-6.json +88 -0
  62. package/registry/login-7.json +83 -0
  63. package/registry/login-8.json +81 -0
  64. package/registry/login-9.json +88 -0
  65. package/registry/lookup-create-1.json +157 -0
  66. package/registry/magic-link-6.json +79 -0
  67. package/registry/navbar-1.json +66 -0
  68. package/registry/navbar-2.json +48 -0
  69. package/registry/navbar-3.json +50 -0
  70. package/registry/navbar-4.json +39 -0
  71. package/registry/navbar-5.json +50 -0
  72. package/registry/next-steps-1.json +147 -0
  73. package/registry/onboarding-1.json +114 -0
  74. package/registry/onboarding-2.json +78 -0
  75. package/registry/onboarding-3.json +71 -0
  76. package/registry/otp-1.json +73 -0
  77. package/registry/properties.json +523 -0
  78. package/registry/record-dialog.json +88 -0
  79. package/registry/record-group.json +190 -0
  80. package/registry/record-preview.json +70 -0
  81. package/registry/record-status-list.json +70 -0
  82. package/registry/reset-password-1.json +92 -0
  83. package/registry/reset-password-2.json +98 -0
  84. package/registry/reset-password-6.json +91 -0
  85. package/registry/rich-text-editor.json +93 -0
  86. package/registry/run-monitor.json +198 -0
  87. package/registry/settings-1.json +119 -0
  88. package/registry/settings-10.json +218 -0
  89. package/registry/settings-11.json +129 -0
  90. package/registry/settings-12.json +130 -0
  91. package/registry/settings-13.json +130 -0
  92. package/registry/settings-14.json +173 -0
  93. package/registry/settings-15.json +149 -0
  94. package/registry/settings-16.json +129 -0
  95. package/registry/settings-17.json +117 -0
  96. package/registry/settings-18.json +117 -0
  97. package/registry/settings-19.json +125 -0
  98. package/registry/settings-2.json +123 -0
  99. package/registry/settings-20.json +112 -0
  100. package/registry/settings-21.json +116 -0
  101. package/registry/settings-22.json +118 -0
  102. package/registry/settings-23.json +118 -0
  103. package/registry/settings-3.json +123 -0
  104. package/registry/settings-4.json +116 -0
  105. package/registry/settings-5.json +119 -0
  106. package/registry/settings-6.json +125 -0
  107. package/registry/settings-7.json +128 -0
  108. package/registry/settings-8.json +116 -0
  109. package/registry/settings-9.json +118 -0
  110. package/registry/settings-shell.json +60 -0
  111. package/registry/settings.json +82 -0
  112. package/registry/signup-1.json +100 -0
  113. package/registry/signup-2.json +93 -0
  114. package/registry/signup-3.json +83 -0
  115. package/registry/signup-6.json +99 -0
  116. package/registry/state-surface.json +58 -0
  117. package/registry/stats-1.json +116 -0
  118. package/registry/stats-2.json +115 -0
  119. package/registry/stats-3.json +97 -0
  120. package/registry/stats-4.json +92 -0
  121. package/registry/stats-5.json +103 -0
  122. package/registry/stats-6.json +105 -0
  123. package/registry/stats-7.json +103 -0
  124. package/registry/stats.json +64 -0
  125. package/registry/timeline-1.json +97 -0
  126. package/registry/timeline-2.json +102 -0
  127. package/registry/timeline-3.json +68 -0
  128. package/registry/timeline-4.json +86 -0
  129. package/registry/ui/accordion.json +15 -0
  130. package/registry/ui/alert-dialog.json +14 -0
  131. package/registry/ui/alert.json +50 -0
  132. package/registry/ui/autocomplete.json +18 -0
  133. package/registry/ui/avatar.json +14 -0
  134. package/registry/ui/badge.json +51 -0
  135. package/registry/ui/breadcrumb.json +15 -0
  136. package/registry/ui/button.json +25 -0
  137. package/registry/ui/calendar.json +15 -0
  138. package/registry/ui/card.json +14 -0
  139. package/registry/ui/chat.json +115 -0
  140. package/registry/ui/checkbox-group.json +14 -0
  141. package/registry/ui/checkbox.json +14 -0
  142. package/registry/ui/collapsible.json +14 -0
  143. package/registry/ui/combobox.json +18 -0
  144. package/registry/ui/command.json +17 -0
  145. package/registry/ui/composer-clipboard.json +14 -0
  146. package/registry/ui/composer-document.json +14 -0
  147. package/registry/ui/composer-editor.json +16 -0
  148. package/registry/ui/composer-query.json +12 -0
  149. package/registry/ui/composer.json +17 -0
  150. package/registry/ui/context-menu.json +23 -0
  151. package/registry/ui/dialog.json +18 -0
  152. package/registry/ui/drawer.json +18 -0
  153. package/registry/ui/empty.json +14 -0
  154. package/registry/ui/field.json +22 -0
  155. package/registry/ui/fieldset.json +14 -0
  156. package/registry/ui/form.json +14 -0
  157. package/registry/ui/frame.json +12 -0
  158. package/registry/ui/gauge.json +31 -0
  159. package/registry/ui/group.json +17 -0
  160. package/registry/ui/icon-frame.json +31 -0
  161. package/registry/ui/input-group.json +17 -0
  162. package/registry/ui/input.json +14 -0
  163. package/registry/ui/kbd.json +12 -0
  164. package/registry/ui/label.json +14 -0
  165. package/registry/ui/menu.json +39 -0
  166. package/registry/ui/meter.json +14 -0
  167. package/registry/ui/number-field.json +17 -0
  168. package/registry/ui/otp-field.json +31 -0
  169. package/registry/ui/pagination.json +17 -0
  170. package/registry/ui/popover.json +14 -0
  171. package/registry/ui/preview-card.json +14 -0
  172. package/registry/ui/progress.json +14 -0
  173. package/registry/ui/radio-group.json +14 -0
  174. package/registry/ui/render-anchor.json +12 -0
  175. package/registry/ui/scroll-area.json +14 -0
  176. package/registry/ui/segmented-control.json +14 -0
  177. package/registry/ui/select.json +16 -0
  178. package/registry/ui/separator.json +14 -0
  179. package/registry/ui/sheet.json +18 -0
  180. package/registry/ui/sidebar.json +25 -0
  181. package/registry/ui/skeleton.json +24 -0
  182. package/registry/ui/slider.json +14 -0
  183. package/registry/ui/spinner.json +14 -0
  184. package/registry/ui/switch.json +14 -0
  185. package/registry/ui/table.json +14 -0
  186. package/registry/ui/tabs.json +16 -0
  187. package/registry/ui/text.json +31 -0
  188. package/registry/ui/textarea.json +14 -0
  189. package/registry/ui/toast.json +89 -0
  190. package/registry/ui/toggle-group.json +18 -0
  191. package/registry/ui/toggle.json +15 -0
  192. package/registry/ui/toolbar.json +14 -0
  193. package/registry/ui/tooltip.json +14 -0
  194. package/registry/ui/use-composer-editor.json +17 -0
  195. package/registry/ui/use-copy-to-clipboard.json +12 -0
  196. package/registry/ui/use-media-query.json +12 -0
  197. package/registry/view.json +831 -0
  198. package/registry/widgets.json +319 -0
  199. package/registry/wizard.json +89 -0
  200. package/registry/workflow-editor.json +460 -0
@@ -0,0 +1,115 @@
1
+ {
2
+ "name": "chat",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/chat/chat-bubble.tsx",
7
+ "content": "\"use client\";\n\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatBubbleProps = useRender.ComponentProps<\"div\"> & {\n align?: \"start\" | \"end\";\n variant?: \"default\" | \"muted\";\n grouped?: boolean;\n};\n\nexport function ChatBubble({\n align = \"start\",\n variant = \"default\",\n grouped = false,\n className,\n render,\n ...props\n}: ChatBubbleProps): ReactElement {\n const defaultProps = {\n \"data-slot\": \"chat-bubble\",\n \"data-align\": align,\n \"data-variant\": variant,\n \"data-grouped\": grouped || undefined,\n className: cn(\n \"relative flex min-w-0 flex-col gap-2 rounded-2xl px-3.5 py-2.5 text-foreground\",\n variant === \"default\" ? \"bg-foreground/12\" : \"bg-foreground/4\",\n !grouped && (align === \"end\" ? \"rounded-se-md\" : \"rounded-ss-md\"),\n className,\n ),\n };\n\n return useRender({\n defaultTagName: \"div\",\n render,\n props: mergeProps<\"div\">(defaultProps, props),\n });\n}\n\nexport function ChatBubbleReactions({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-bubble-reactions\"\n className={cn(\"flex flex-wrap gap-1 px-0.5\", className)}\n {...props}\n />\n );\n}\n"
8
+ },
9
+ {
10
+ "path": "registry/default/ui/chat/chat-collapsible-message.tsx",
11
+ "content": "\"use client\";\n\nimport { CaretDownIcon, CaretUpIcon } from \"@phosphor-icons/react\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport { useState } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport {\n Collapsible,\n CollapsiblePanel,\n CollapsibleTrigger,\n} from \"@tc96/ui/collapsible\";\nimport { splitChatMessagePreview } from \"./lib/split-chat-message-preview\";\n\nexport type ChatCollapsibleMessageProps = {\n text: string;\n showMoreLabel: string;\n showLessLabel: string;\n side: \"incoming\" | \"outgoing\";\n maxPreviewLength?: number;\n defaultOpen?: boolean;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n renderText?: (text: string) => ReactNode;\n className?: string;\n};\n\nfunction renderPlainText(text: string): ReactElement {\n return (\n <p className=\"m-0 whitespace-pre-wrap break-words text-sm leading-[1.55]\">\n {text}\n </p>\n );\n}\n\nfunction ChatCollapsibleMessage({\n text,\n showMoreLabel,\n showLessLabel,\n side,\n maxPreviewLength,\n defaultOpen = false,\n open,\n onOpenChange,\n renderText = renderPlainText,\n className,\n}: ChatCollapsibleMessageProps): ReactElement {\n const { preview, remainder } = splitChatMessagePreview(\n text,\n maxPreviewLength,\n );\n if (!remainder) {\n return <div className={cn(\"min-w-0\", className)}>{renderText(text)}</div>;\n }\n\n return (\n <ExpandableChatMessage\n text={text}\n preview={preview}\n renderText={renderText}\n showMoreLabel={showMoreLabel}\n showLessLabel={showLessLabel}\n side={side}\n className={className}\n defaultOpen={defaultOpen}\n open={open}\n onOpenChange={onOpenChange}\n />\n );\n}\n\nfunction ExpandableChatMessage({\n text,\n preview,\n renderText,\n showMoreLabel,\n showLessLabel,\n side,\n className,\n defaultOpen,\n open: controlledOpen,\n onOpenChange,\n}: {\n text: string;\n preview: string;\n renderText: (text: string) => ReactNode;\n showMoreLabel: string;\n showLessLabel: string;\n side: \"incoming\" | \"outgoing\";\n className?: string;\n defaultOpen: boolean;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}): ReactElement {\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const open = controlledOpen ?? internalOpen;\n const setOpen = (nextOpen: boolean): void => {\n if (controlledOpen === undefined) setInternalOpen(nextOpen);\n onOpenChange?.(nextOpen);\n };\n const Icon = open ? CaretUpIcon : CaretDownIcon;\n\n return (\n <Collapsible\n open={open}\n onOpenChange={setOpen}\n className={cn(\"flex min-w-0 flex-col\", className)}\n >\n <div className=\"grid\">\n <div\n data-slot=\"chat-collapsible-preview\"\n aria-hidden={open || undefined}\n className={cn(\n \"mask-[linear-gradient(to_bottom,black_calc(100%-3rem),transparent)] col-start-1 row-start-1 self-start\",\n open && \"invisible\",\n )}\n >\n {renderText(preview)}\n </div>\n <CollapsiblePanel className=\"col-start-1 row-start-1 min-w-0 motion-reduce:transition-none\">\n <div\n aria-hidden={!open || undefined}\n className={open ? undefined : \"invisible\"}\n >\n {renderText(text)}\n </div>\n </CollapsiblePanel>\n </div>\n <CollapsibleTrigger\n type=\"button\"\n className={cn(\n \"mt-2 flex w-fit items-center gap-1 text-start text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n side === \"outgoing\"\n ? \"text-foreground/80 hover:text-foreground\"\n : \"text-muted-foreground hover:text-foreground\",\n )}\n >\n {open ? showLessLabel : showMoreLabel}\n <Icon aria-hidden=\"true\" className=\"size-3.5 shrink-0\" />\n </CollapsibleTrigger>\n </Collapsible>\n );\n}\n\nexport { ChatCollapsibleMessage, splitChatMessagePreview };\n"
12
+ },
13
+ {
14
+ "path": "registry/default/ui/chat/chat-conversation.tsx",
15
+ "content": "\"use client\";\n\nimport type { ComponentProps, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport {\n ScrollAreaPrimitive,\n ScrollBar,\n} from \"@tc96/ui/scroll-area\";\nimport { ChatJumpToLatestButton } from \"./chat-jump-to-latest-button\";\nimport type { ChatScrollController } from \"./hooks/use-chat-scroll\";\n\nexport type ChatConversationProps = ComponentProps<\"div\"> & {\n scroll: ChatScrollController;\n label: string;\n jumpLabel: ReactNode;\n contentClassName?: string;\n overlay?: ReactNode;\n inactive?: boolean;\n /** \"off\" when the caller announces arrivals itself, e.g. so paged-in history isn't read out. */\n live?: \"polite\" | \"off\";\n};\n\nexport function ChatConversation({\n scroll,\n label,\n jumpLabel,\n contentClassName,\n children,\n overlay,\n inactive = false,\n live,\n className,\n ...props\n}: ChatConversationProps): ReactElement {\n return (\n <div\n data-slot=\"chat-conversation\"\n className={cn(\"relative isolate flex min-h-0 flex-1 flex-col\", className)}\n {...props}\n >\n <ScrollAreaPrimitive.Root\n inert={inactive}\n className=\"size-full min-h-0 touch-auto before:pointer-events-none before:absolute before:inset-x-0 before:top-0 before:z-10 before:h-6 before:bg-linear-to-b before:from-popover before:to-transparent before:opacity-0 before:content-[''] after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:z-10 after:h-6 after:bg-linear-to-t after:from-popover after:to-transparent after:opacity-0 after:content-[''] data-overflow-y-end:after:opacity-100 data-overflow-y-start:before:opacity-100\"\n >\n <ScrollAreaPrimitive.Viewport\n ref={scroll.viewportRef}\n role=\"log\"\n aria-label={label}\n aria-live={live}\n aria-relevant=\"additions text\"\n data-slot=\"scroll-area-viewport\"\n className=\"h-full rounded-[inherit] outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset data-has-overflow-y:overscroll-y-contain data-has-overflow-x:overscroll-x-contain\"\n onScroll={scroll.onScroll}\n >\n <ScrollAreaPrimitive.Content\n data-slot=\"scroll-area-content\"\n className={cn(\"px-4 pb-4\", contentClassName)}\n style={{ minWidth: 0 }}\n >\n {children}\n </ScrollAreaPrimitive.Content>\n </ScrollAreaPrimitive.Viewport>\n <ScrollBar orientation=\"vertical\" />\n <ScrollBar orientation=\"horizontal\" />\n <ScrollAreaPrimitive.Corner data-slot=\"scroll-area-corner\" />\n </ScrollAreaPrimitive.Root>\n {scroll.showJump && !inactive && (\n <div className=\"pointer-events-none absolute inset-x-0 bottom-3 z-30 flex justify-center\">\n <ChatJumpToLatestButton onClick={scroll.scrollToLatest}>\n {jumpLabel}\n </ChatJumpToLatestButton>\n </div>\n )}\n {overlay}\n </div>\n );\n}\n"
16
+ },
17
+ {
18
+ "path": "registry/default/ui/chat/chat-date-pill.tsx",
19
+ "content": "\"use client\";\n\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport function ChatDatePill({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-date-pill\"\n className={cn(\n \"pointer-events-none sticky top-4 z-20 mx-auto flex h-6 w-fit items-center justify-center rounded-full border bg-popover/90 px-2 font-medium text-foreground text-xs backdrop-blur-xs\",\n className,\n )}\n {...props}\n />\n );\n}\n"
20
+ },
21
+ {
22
+ "path": "registry/default/ui/chat/chat-delivery-indicator.tsx",
23
+ "content": "\"use client\";\n\nimport { ChecksIcon, CheckIcon, WarningCircleIcon, ClockIcon } from \"@phosphor-icons/react\";\nimport type { ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatDeliveryIndicatorProps = {\n status: \"sending\" | \"sent\" | \"delivered\" | \"read\" | \"failed\";\n label: string;\n};\n\nexport function ChatDeliveryIndicator({\n status,\n label,\n}: ChatDeliveryIndicatorProps): ReactElement {\n const Icon = {\n sending: ClockIcon,\n sent: CheckIcon,\n delivered: ChecksIcon,\n read: ChecksIcon,\n failed: WarningCircleIcon,\n }[status];\n\n return (\n <span\n role=\"img\"\n aria-label={label}\n title={label}\n data-slot=\"chat-delivery-indicator\"\n >\n <Icon\n aria-hidden=\"true\"\n className={cn(\n \"size-3\",\n status === \"read\" && \"text-sky-600 dark:text-sky-400\",\n status === \"failed\" && \"text-destructive\",\n )}\n />\n </span>\n );\n}\n"
24
+ },
25
+ {
26
+ "path": "registry/default/ui/chat/chat-jump-to-latest-button.tsx",
27
+ "content": "\"use client\";\n\nimport { ArrowDownIcon } from \"@phosphor-icons/react\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport { Button, type ButtonProps } from \"@tc96/ui/button\";\n\nexport type ChatJumpToLatestButtonProps = Omit<\n ButtonProps,\n \"children\" | \"size\" | \"variant\"\n> & {\n children: ReactNode;\n};\n\nexport function ChatJumpToLatestButton({\n className,\n children,\n ...props\n}: ChatJumpToLatestButtonProps): ReactElement {\n return (\n <div\n data-slot=\"chat-jump-to-latest\"\n className=\"rounded-full bg-popover/90 backdrop-blur-xs\"\n >\n <Button\n variant=\"outline\"\n size=\"xs\"\n className={cn(\n \"pointer-events-auto gap-2 rounded-full before:rounded-full\",\n className,\n )}\n {...props}\n >\n <ArrowDownIcon aria-hidden=\"true\" />\n {children}\n </Button>\n </div>\n );\n}\n"
28
+ },
29
+ {
30
+ "path": "registry/default/ui/chat/chat-members.tsx",
31
+ "content": "\"use client\";\n\nimport type { ComponentProps, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatMemberEntry = {\n id: string;\n name: ReactNode;\n avatar?: ReactNode;\n badges?: ReactNode;\n action?: ReactNode;\n dimmed?: boolean;\n};\n\nexport type ChatMemberListProps = ComponentProps<\"ul\"> & {\n members: readonly ChatMemberEntry[];\n};\n\nexport function ChatMemberList({\n members,\n className,\n ...props\n}: ChatMemberListProps): ReactElement {\n return (\n <ul\n data-slot=\"chat-member-list\"\n className={cn(\"m-0 flex list-none flex-col gap-2 p-0\", className)}\n {...props}\n >\n {members.map((member) => (\n <li key={member.id} className=\"flex min-w-0 items-center gap-3\">\n {member.avatar}\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-x-1.5 gap-y-1\">\n <span\n className={cn(\n \"truncate text-sm\",\n member.dimmed ? \"text-muted-foreground\" : \"font-medium\",\n )}\n >\n {member.name}\n </span>\n {member.badges}\n </div>\n {member.action}\n </li>\n ))}\n </ul>\n );\n}\n\nexport type ChatMemberSectionProps = ChatMemberListProps & {\n label: string;\n heading?: ReactNode;\n};\n\nexport function ChatMemberSection({\n label,\n heading,\n members,\n ...props\n}: ChatMemberSectionProps): ReactElement | null {\n if (!members.length) return null;\n return (\n <section aria-label={label} className=\"flex flex-col gap-4\">\n {heading && (\n <h3 className=\"m-0 flex items-center gap-2 font-medium text-muted-foreground text-xs\">\n {heading}\n </h3>\n )}\n <ChatMemberList members={members} {...props} />\n </section>\n );\n}\n"
32
+ },
33
+ {
34
+ "path": "registry/default/ui/chat/chat-message-actions.tsx",
35
+ "content": "\"use client\";\n\nimport { ArrowElbowDownLeftIcon, DotsThreeIcon } from \"@phosphor-icons/react\";\nimport type { ComponentProps, ReactElement, ReactNode, RefObject } from \"react\";\nimport { useRef, useState } from \"react\";\nimport { Button } from \"@tc96/ui/button\";\nimport { Menu, MenuPopup, MenuTrigger } from \"@tc96/ui/menu\";\nimport { Toolbar, ToolbarButton } from \"@tc96/ui/toolbar\";\nimport {\n Tooltip,\n TooltipPopup,\n TooltipTrigger,\n} from \"@tc96/ui/tooltip\";\nimport { useChatPopupDismissal } from \"./hooks/use-chat-popup-dismissal\";\n\nexport type ChatMessageActionToolbarProps = {\n side: \"incoming\" | \"outgoing\";\n toolbarLabel: string;\n reactionPicker?: (toolbarRef: RefObject<HTMLDivElement | null>) => ReactNode;\n menuTriggerRef?: RefObject<HTMLButtonElement | null>;\n menuFinalFocus?: ComponentProps<typeof MenuPopup>[\"finalFocus\"];\n} & (\n | { onReply: () => void; replyLabel: string; replyTooltip: string }\n | { onReply?: never; replyLabel?: never; replyTooltip?: never }\n) &\n (\n | { menuChildren: ReactNode; moreLabel: string; moreTooltip: string }\n | { menuChildren?: never; moreLabel?: never; moreTooltip?: never }\n );\n\nexport function ChatMessageActionToolbar({\n side,\n toolbarLabel,\n reactionPicker,\n replyLabel,\n replyTooltip,\n onReply,\n moreLabel,\n moreTooltip,\n menuChildren,\n menuTriggerRef: suppliedMenuTriggerRef,\n menuFinalFocus,\n}: ChatMessageActionToolbarProps): ReactElement | null {\n const [menuOpen, setMenuOpen] = useState(false);\n const [menuDismissedOutside, setMenuDismissedOutside] = useState(false);\n const toolbarRef = useRef<HTMLDivElement>(null);\n const ownMenuTriggerRef = useRef<HTMLButtonElement>(null);\n const menuTriggerRef = suppliedMenuTriggerRef ?? ownMenuTriggerRef;\n\n useChatPopupDismissal(menuOpen, menuTriggerRef, () => setMenuOpen(false));\n\n if (!reactionPicker && !onReply && !menuChildren) return null;\n\n return (\n <Toolbar\n ref={toolbarRef}\n aria-label={toolbarLabel}\n data-slot=\"chat-message-action-toolbar\"\n className=\"z-10 min-w-max flex-none items-center gap-0 self-center rounded-full bg-transparent p-0.5 opacity-0 pointer-coarse:opacity-100 transition-opacity group-hover/message:opacity-100 has-data-popup-open:opacity-100 has-focus-visible:opacity-100 motion-reduce:transition-none\"\n >\n {reactionPicker?.(toolbarRef)}\n {onReply && (\n <Tooltip>\n <TooltipTrigger\n render={\n <ToolbarButton\n render={\n <Button\n size=\"icon-xs\"\n variant=\"ghost\"\n className=\"pointer-coarse:size-8 rounded-full before:rounded-full\"\n aria-label={replyLabel}\n onMouseDown={(event) => {\n if (event.button === 0) event.preventDefault();\n }}\n onClick={onReply}\n />\n }\n />\n }\n >\n <ArrowElbowDownLeftIcon aria-hidden=\"true\" />\n </TooltipTrigger>\n <TooltipPopup>{replyTooltip}</TooltipPopup>\n </Tooltip>\n )}\n {menuChildren && (\n <Menu\n open={menuOpen}\n onOpenChange={(open, details) => {\n setMenuDismissedOutside(\n details.reason === \"outside-press\" ||\n details.reason === \"focus-out\",\n );\n setMenuOpen(open);\n }}\n >\n <Tooltip>\n <TooltipTrigger\n render={\n <ToolbarButton\n render={\n <MenuTrigger\n ref={menuTriggerRef}\n render={\n <Button\n size=\"icon-xs\"\n variant=\"ghost\"\n className=\"pointer-coarse:size-8 rounded-full before:rounded-full\"\n aria-label={moreLabel}\n data-message-actions=\"\"\n />\n }\n />\n }\n />\n }\n >\n <DotsThreeIcon aria-hidden=\"true\" />\n </TooltipTrigger>\n <TooltipPopup>{moreTooltip}</TooltipPopup>\n </Tooltip>\n <MenuPopup\n anchor={toolbarRef}\n align={side === \"outgoing\" ? \"start\" : \"end\"}\n finalFocus={menuDismissedOutside ? false : menuFinalFocus}\n >\n {menuChildren}\n </MenuPopup>\n </Menu>\n )}\n </Toolbar>\n );\n}\n"
36
+ },
37
+ {
38
+ "path": "registry/default/ui/chat/chat-message-bubble.tsx",
39
+ "content": "\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport type { ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport { ChatBubble, type ChatBubbleProps } from \"./chat-bubble\";\n\nexport type ChatMessageBubbleProps = Omit<\n ChatBubbleProps,\n \"align\" | \"variant\" | \"grouped\" | \"render\"\n> & {\n side: \"incoming\" | \"outgoing\";\n firstInGroup?: boolean;\n animateEntrance?: boolean;\n highlighted?: boolean;\n onAnimationComplete?: () => void;\n};\n\nexport function ChatMessageBubble({\n side,\n firstInGroup = true,\n animateEntrance = false,\n highlighted = false,\n children,\n className,\n onAnimationComplete,\n ...props\n}: ChatMessageBubbleProps): ReactElement {\n const reduceMotion = useReducedMotion();\n const entranceOrigin =\n side === \"outgoing\"\n ? \"origin-top-right rtl:origin-top-left\"\n : \"origin-top-left rtl:origin-top-right\";\n return (\n <ChatBubble\n {...props}\n align={side === \"outgoing\" ? \"end\" : \"start\"}\n variant={side === \"outgoing\" ? \"default\" : \"muted\"}\n grouped={!firstInGroup}\n data-slot=\"chat-message-bubble\"\n className={cn(highlighted ? \"origin-center\" : entranceOrigin, className)}\n render={\n <motion.div\n initial={\n animateEntrance && !reduceMotion\n ? { transform: \"scale(0.92)\" }\n : false\n }\n animate={highlighted && !reduceMotion ? \"attention\" : \"rest\"}\n variants={{\n rest: {\n transform: \"scale(1)\",\n transition: reduceMotion\n ? { duration: 0 }\n : { type: \"spring\", duration: 0.35, bounce: 0.45 },\n },\n attention: {\n transform: [\"scale(1)\", \"scale(1.05)\", \"scale(1)\"],\n transition: {\n duration: 0.42,\n times: [0, 0.28, 1],\n ease: [\n [0.16, 1, 0.3, 1],\n [0.34, 1.56, 0.64, 1],\n ],\n },\n },\n }}\n onAnimationComplete={onAnimationComplete}\n />\n }\n >\n {children}\n {highlighted && (\n <motion.div\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute inset-0 rounded-[inherit] ring-2 ring-foreground/25 ring-offset-2 ring-offset-background\"\n initial={{ opacity: 0 }}\n animate={{ opacity: [0, 1, 0] }}\n transition={{ duration: 0.42, times: [0, 0.28, 1], ease: \"easeOut\" }}\n />\n )}\n </ChatBubble>\n );\n}\n"
40
+ },
41
+ {
42
+ "path": "registry/default/ui/chat/chat-message-info.tsx",
43
+ "content": "\"use client\";\n\nimport type { ReactElement, ReactNode } from \"react\";\nimport { type ChatMemberEntry, ChatMemberSection } from \"./chat-members\";\nimport { ChatMessageFooter } from \"./chat-message-layout\";\n\nexport type ChatMessageInfoProps = {\n message: ReactNode;\n metadata: ReactNode;\n groups: readonly {\n id: string;\n label: string;\n icon?: ReactNode;\n members: readonly ChatMemberEntry[];\n }[];\n};\n\nexport function ChatMessageInfo({\n message,\n metadata,\n groups,\n}: ChatMessageInfoProps): ReactElement {\n return (\n <div data-slot=\"chat-message-info\">\n <div className=\"mb-7 flex flex-col items-end gap-1\">\n <div className=\"w-fit min-w-0 max-w-[83%]\">{message}</div>\n <ChatMessageFooter>{metadata}</ChatMessageFooter>\n </div>\n <div className=\"flex flex-col gap-7\">\n {groups.map((group) => (\n <ChatMemberSection\n key={group.id}\n label={group.label}\n heading={\n <>\n {group.icon}\n {group.label}\n </>\n }\n members={group.members}\n />\n ))}\n </div>\n </div>\n );\n}\n"
44
+ },
45
+ {
46
+ "path": "registry/default/ui/chat/chat-message-layout.tsx",
47
+ "content": "\"use client\";\n\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatMessageLayoutProps = useRender.ComponentProps<\"article\"> & {\n align?: \"start\" | \"end\";\n};\n\nexport function ChatMessageLayout({\n align = \"start\",\n className,\n render,\n ...props\n}: ChatMessageLayoutProps): ReactElement {\n const defaultProps = {\n \"data-slot\": \"chat-message\",\n \"data-align\": align,\n className: cn(\n \"group/message relative grid scroll-m-8 grid-cols-1 items-start rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring has-[>[data-slot=chat-message-avatar]]:grid-cols-[auto_minmax(0,1fr)] has-[>[data-slot=chat-message-avatar]]:gap-x-2 has-[>[data-slot=chat-message-header]]:gap-y-1\",\n className,\n ),\n };\n\n return useRender({\n defaultTagName: \"article\",\n render,\n props: mergeProps<\"article\">(defaultProps, props),\n });\n}\n\nexport function ChatMessageAvatar({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-message-avatar\"\n className={cn(\"col-start-1 row-start-2 w-7\", className)}\n {...props}\n />\n );\n}\n\nexport function ChatMessageHeader({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-message-header\"\n className={cn(\n \"col-start-1 in-[[data-slot=chat-message]:has(>[data-slot=chat-message-avatar])]:col-start-2 row-start-1 px-1 font-medium text-muted-foreground text-xs group-data-[align=end]/message:justify-self-end\",\n className,\n )}\n {...props}\n />\n );\n}\n\nexport function ChatMessageContent({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-message-content\"\n className={cn(\n \"col-start-1 in-[[data-slot=chat-message]:has(>[data-slot=chat-message-avatar])]:col-start-2 row-start-2 flex min-w-0 flex-col gap-1 group-data-[align=end]/message:items-end\",\n className,\n )}\n {...props}\n />\n );\n}\n\nexport function ChatMessageFooter({\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-message-footer\"\n className={cn(\n \"flex items-center gap-1.5 px-1 pt-0.5 text-[.625rem] text-muted-foreground\",\n className,\n )}\n {...props}\n />\n );\n}\n"
48
+ },
49
+ {
50
+ "path": "registry/default/ui/chat/chat-message-text.tsx",
51
+ "content": "import type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatMessageTextProps = Omit<ComponentProps<\"p\">, \"children\"> & {\n text: string;\n mentions?: readonly string[];\n};\n\nexport function ChatMessageText({\n text,\n mentions = [],\n className,\n ...props\n}: ChatMessageTextProps): ReactElement {\n const names = new Set(mentions.map((name) => `@${name}`));\n const parts = text.split(/(@[\\p{L}\\p{N}_.-]+)/u);\n return (\n <p\n className={cn(\n \"m-0 whitespace-pre-wrap break-words text-sm leading-[1.55]\",\n className,\n )}\n {...props}\n >\n {parts.map((part, index) => {\n if (index > 0 && !/(?:^|\\s)$/.test(parts[index - 1] ?? \"\")) return part;\n const mention = names.has(part) ? part : part.replace(/[.-]+$/, \"\");\n if (!names.has(mention)) return part;\n return (\n <span key={`${index}-${part}`}>\n <span className=\"font-medium\">{mention}</span>\n {part.slice(mention.length)}\n </span>\n );\n })}\n </p>\n );\n}\n"
52
+ },
53
+ {
54
+ "path": "registry/default/ui/chat/chat-message.tsx",
55
+ "content": "\"use client\";\n\nimport type { ReactElement, ReactNode } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport { ChatBubbleReactions } from \"./chat-bubble\";\nimport {\n ChatMessageBubble,\n type ChatMessageBubbleProps,\n} from \"./chat-message-bubble\";\nimport {\n ChatMessageAvatar,\n ChatMessageContent,\n ChatMessageFooter,\n ChatMessageHeader,\n ChatMessageLayout,\n type ChatMessageLayoutProps,\n} from \"./chat-message-layout\";\nimport { ChatMessageText } from \"./chat-message-text\";\n\ntype ChatMessageAnimationProps = Pick<\n ChatMessageBubbleProps,\n \"animateEntrance\" | \"highlighted\" | \"onAnimationComplete\"\n>;\n\nexport type ChatMessageProps = Omit<\n ChatMessageLayoutProps,\n \"align\" | \"children\"\n> &\n ChatMessageAnimationProps & {\n side: \"incoming\" | \"outgoing\";\n author?: ReactNode;\n avatar?: ReactNode;\n grouped?: boolean;\n lifted?: boolean;\n children: ReactNode;\n actions?: ReactNode;\n reactions?: ReactNode;\n footer?: ReactNode;\n bubble?: boolean;\n bubbleProps?: Omit<\n ChatMessageBubbleProps,\n \"side\" | \"firstInGroup\" | \"children\" | keyof ChatMessageAnimationProps\n >;\n };\n\nexport function ChatMessage({\n side,\n author,\n avatar,\n grouped = false,\n lifted = false,\n children,\n actions,\n reactions,\n footer,\n bubble = true,\n bubbleProps,\n animateEntrance,\n highlighted,\n onAnimationComplete,\n ...props\n}: ChatMessageProps): ReactElement {\n const own = side === \"outgoing\";\n return (\n <ChatMessageLayout align={own ? \"end\" : \"start\"} {...props}>\n {!own && !grouped && author && (\n <ChatMessageHeader className={lifted ? \"invisible\" : undefined}>\n {author}\n </ChatMessageHeader>\n )}\n {!own && avatar && (\n <ChatMessageAvatar className={lifted ? \"invisible\" : undefined}>\n {!grouped && avatar}\n </ChatMessageAvatar>\n )}\n <ChatMessageContent>\n {bubble ? (\n <div\n className={cn(\n \"flex w-full min-w-0 items-center gap-2\",\n own && \"flex-row-reverse\",\n )}\n >\n <div className=\"relative min-w-0 max-w-[83%] shrink\">\n <ChatMessageBubble\n {...bubbleProps}\n side={side}\n firstInGroup={!grouped}\n animateEntrance={animateEntrance}\n highlighted={highlighted}\n onAnimationComplete={onAnimationComplete}\n className={cn(lifted && \"invisible\", bubbleProps?.className)}\n >\n {typeof children === \"string\" ? (\n <ChatMessageText text={children} />\n ) : (\n children\n )}\n </ChatMessageBubble>\n </div>\n {actions}\n </div>\n ) : (\n children\n )}\n {reactions && <ChatBubbleReactions>{reactions}</ChatBubbleReactions>}\n {footer && <ChatMessageFooter>{footer}</ChatMessageFooter>}\n </ChatMessageContent>\n </ChatMessageLayout>\n );\n}\n"
56
+ },
57
+ {
58
+ "path": "registry/default/ui/chat/chat-reaction-chip.tsx",
59
+ "content": "\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport type { ComponentProps, ReactElement, ReactNode } from \"react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport {\n Popover,\n PopoverPopup,\n PopoverTrigger,\n} from \"@tc96/ui/popover\";\nimport { Toggle } from \"@tc96/ui/toggle\";\nimport { useChatPopupDismissal } from \"./hooks/use-chat-popup-dismissal\";\n\nexport type ChatReactionChipProps = {\n animateEntrance?: boolean;\n emoji: string;\n count: number;\n selected: boolean;\n label: string;\n onClick: () => void;\n reactorContent?: ReactNode;\n reactorLabel?: string;\n popupAlign?: ComponentProps<typeof PopoverPopup>[\"align\"];\n className?: string;\n};\n\nexport function ChatReactionChip({\n animateEntrance = false,\n emoji,\n count,\n selected,\n label,\n onClick,\n className,\n reactorContent,\n reactorLabel,\n popupAlign,\n}: ChatReactionChipProps): ReactElement {\n const reduceMotion = useReducedMotion();\n const [animateReaction, setAnimateReaction] = useState(false);\n const previouslySelected = useRef(selected);\n useEffect(() => {\n setAnimateReaction(selected && !previouslySelected.current);\n previouslySelected.current = selected;\n }, [selected]);\n\n const [open, setOpen] = useState(false);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const anchorRef = useRef<HTMLSpanElement>(null);\n const popupRef = useRef<HTMLDivElement>(null);\n const holdTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const touchOrigin = useRef<{ x: number; y: number } | null>(null);\n const suppressClick = useRef(false);\n const clearHold = useCallback((): void => {\n if (holdTimer.current !== null) clearTimeout(holdTimer.current);\n holdTimer.current = null;\n }, []);\n\n useEffect(() => clearHold, [clearHold]);\n\n useChatPopupDismissal(open, triggerRef, () => {\n clearHold();\n if (touchOrigin.current) suppressClick.current = true;\n touchOrigin.current = null;\n setOpen(false);\n });\n\n const chip = (\n <Toggle\n data-slot=\"chat-reaction-chip\"\n variant=\"outline\"\n size=\"sm\"\n aria-label={label}\n pressed={selected}\n className={cn(\n \"h-6 min-w-0 gap-1 rounded-full px-2 text-xs shadow-none transition-transform duration-150 [-webkit-touch-callout:none] before:rounded-full active:scale-95 data-pressed:border-primary/48 data-pressed:bg-primary/12 motion-reduce:scale-100 motion-reduce:transition-none sm:h-6 sm:min-w-0 sm:text-xs dark:data-pressed:bg-primary/8\",\n className,\n )}\n onPressedChange={(_, details) => {\n if (suppressClick.current) {\n suppressClick.current = false;\n details.cancel();\n return;\n }\n onClick();\n }}\n >\n <motion.span\n className=\"inline-flex\"\n initial={false}\n animate={\n animateReaction && !reduceMotion\n ? {\n transform: [\n \"scale(1) rotate(0deg)\",\n \"scale(1.55) rotate(-12deg)\",\n \"scale(1.12) rotate(6deg)\",\n \"scale(1) rotate(0deg)\",\n ],\n }\n : { transform: \"scale(1) rotate(0deg)\" }\n }\n transition={{\n duration: reduceMotion ? 0 : 0.44,\n times: [0, 0.35, 0.65, 1],\n ease: \"easeOut\",\n }}\n >\n {emoji}\n </motion.span>\n <span className=\"tabular-nums\">{count}</span>\n </Toggle>\n );\n\n const content = !reactorContent ? (\n chip\n ) : (\n <Popover\n open={open}\n onOpenChange={(nextOpen, details) => {\n if (details.reason === \"trigger-press\") {\n details.cancel();\n return;\n }\n if (\n details.reason === \"trigger-hover\" &&\n !window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches\n ) {\n details.cancel();\n return;\n }\n setOpen(nextOpen);\n }}\n >\n <span ref={anchorRef} className=\"inline-flex\">\n <PopoverTrigger\n ref={triggerRef}\n openOnHover\n delay={300}\n closeDelay={150}\n render={chip}\n onFocus={(event) => {\n if (\n event.currentTarget.matches(\":focus-visible\") &&\n !touchOrigin.current\n )\n setOpen(true);\n }}\n onBlur={(event) => {\n if (!popupRef.current?.contains(event.relatedTarget))\n setOpen(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" || event.key === \" \")\n suppressClick.current = false;\n }}\n onPointerDown={(event) => {\n suppressClick.current = false;\n if (event.pointerType !== \"touch\" || !event.isPrimary) return;\n touchOrigin.current = { x: event.clientX, y: event.clientY };\n clearHold();\n holdTimer.current = setTimeout(() => {\n holdTimer.current = null;\n suppressClick.current = true;\n setOpen(true);\n }, 500);\n }}\n onPointerMove={(event) => {\n const origin = touchOrigin.current;\n if (\n !origin ||\n Math.hypot(event.clientX - origin.x, event.clientY - origin.y) <=\n 8\n )\n return;\n clearHold();\n suppressClick.current = true;\n touchOrigin.current = null;\n setOpen(false);\n }}\n onPointerUp={() => {\n clearHold();\n touchOrigin.current = null;\n }}\n onPointerCancel={() => {\n clearHold();\n touchOrigin.current = null;\n suppressClick.current = true;\n setOpen(false);\n }}\n onContextMenu={(event) => {\n if (touchOrigin.current || suppressClick.current)\n event.preventDefault();\n }}\n />\n </span>\n <PopoverPopup\n anchor={anchorRef}\n align={popupAlign}\n ref={popupRef}\n initialFocus={false}\n finalFocus={false}\n aria-label={reactorLabel}\n className=\"w-52 **:data-[slot=popover-viewport]:p-1.5\"\n >\n {reactorContent}\n </PopoverPopup>\n </Popover>\n );\n\n return (\n <motion.span\n className={cn(\n \"inline-flex origin-top\",\n animateEntrance && !reduceMotion && \"will-change-transform\",\n )}\n initial={\n animateEntrance && !reduceMotion\n ? { opacity: 0, transform: \"scale(0.55)\" }\n : false\n }\n animate={{ opacity: 1, transform: \"scale(1)\" }}\n transition={\n reduceMotion\n ? { duration: 0 }\n : {\n transform: { type: \"spring\", duration: 0.44, bounce: 0.45 },\n opacity: { duration: 0.12 },\n }\n }\n >\n {content}\n </motion.span>\n );\n}\n"
60
+ },
61
+ {
62
+ "path": "registry/default/ui/chat/chat-reaction-picker.tsx",
63
+ "content": "\"use client\";\n\nimport { HeartIcon } from \"@phosphor-icons/react\";\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { useRef, useState } from \"react\";\nimport { Button } from \"@tc96/ui/button\";\nimport {\n Popover,\n PopoverPopup,\n PopoverTrigger,\n} from \"@tc96/ui/popover\";\nimport { ToolbarButton } from \"@tc96/ui/toolbar\";\nimport {\n Tooltip,\n TooltipPopup,\n TooltipTrigger,\n} from \"@tc96/ui/tooltip\";\nimport { useChatPopupDismissal } from \"./hooks/use-chat-popup-dismissal\";\n\nexport type ChatReactionPickerProps = {\n inToolbar?: boolean;\n options: readonly { emoji: string; label: string }[];\n selectedEmojis: readonly string[];\n triggerLabel: string;\n triggerTooltip: string;\n popupLabel: string;\n popupAlign?: ComponentProps<typeof PopoverPopup>[\"align\"];\n popupAnchor?: ComponentProps<typeof PopoverPopup>[\"anchor\"];\n onSelect: (emoji: string) => void;\n};\n\nexport function ChatReactionPicker({\n inToolbar = false,\n options,\n selectedEmojis,\n triggerLabel,\n triggerTooltip,\n popupLabel,\n popupAlign,\n popupAnchor,\n onSelect,\n}: ChatReactionPickerProps): ReactElement {\n const [open, setOpen] = useState(false);\n const triggerRef = useRef<HTMLButtonElement>(null);\n\n useChatPopupDismissal(open, triggerRef, () => setOpen(false));\n\n const trigger = (\n <PopoverTrigger\n ref={triggerRef}\n render={\n <Button\n size=\"icon-xs\"\n variant=\"ghost\"\n className=\"pointer-coarse:size-8 rounded-full before:rounded-full\"\n aria-label={triggerLabel}\n onMouseDown={(event) => {\n if (event.button === 0) event.preventDefault();\n }}\n />\n }\n />\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <Tooltip>\n <TooltipTrigger\n render={inToolbar ? <ToolbarButton render={trigger} /> : trigger}\n >\n <HeartIcon aria-hidden=\"true\" className=\"size-3.5\" />\n </TooltipTrigger>\n <TooltipPopup>{triggerTooltip}</TooltipPopup>\n </Tooltip>\n <PopoverPopup\n anchor={popupAnchor}\n side=\"top\"\n align={popupAlign}\n aria-label={popupLabel}\n initialFocus={(interaction) => interaction === \"keyboard\"}\n finalFocus={(interaction) => interaction === \"keyboard\"}\n className=\"transform-gpu rounded-full before:rounded-full **:data-[slot=popover-viewport]:p-1\"\n >\n <div className=\"flex\">\n {options.map(({ emoji, label }) => (\n <Button\n key={emoji}\n aria-label={label}\n aria-pressed={selectedEmojis.includes(emoji)}\n variant=\"ghost\"\n size=\"icon-lg\"\n className=\"rounded-full before:rounded-full\"\n onMouseDown={(event) => {\n if (event.button === 0) event.preventDefault();\n }}\n onClick={() => {\n onSelect(emoji);\n setOpen(false);\n }}\n >\n <span aria-hidden=\"true\" className=\"text-lg leading-none\">\n {emoji}\n </span>\n </Button>\n ))}\n </div>\n </PopoverPopup>\n </Popover>\n );\n}\n"
64
+ },
65
+ {
66
+ "path": "registry/default/ui/chat/chat-reply-preview.tsx",
67
+ "content": "\"use client\";\n\nimport { XIcon } from \"@phosphor-icons/react\";\nimport { motion, usePresence, useReducedMotion } from \"motion/react\";\nimport type { ReactElement, ReactNode, RefObject } from \"react\";\nimport { useLayoutEffect, useRef, useState } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport { Button } from \"@tc96/ui/button\";\nimport { ScrollArea } from \"@tc96/ui/scroll-area\";\nimport {\n Tooltip,\n TooltipPopup,\n TooltipTrigger,\n} from \"@tc96/ui/tooltip\";\nimport { ChatMessageBubble } from \"./chat-message-bubble\";\n\nexport type ChatReplyTarget = {\n source: HTMLDivElement;\n width: number;\n firstInGroup: boolean;\n};\n\nexport type ChatReplyPreviewProps = {\n target: ChatReplyTarget;\n side: \"incoming\" | \"outgoing\";\n avatar?: ReactNode;\n author: ReactNode;\n replyLabel: ReactNode;\n cancelLabel: string;\n children: ReactNode;\n dismissalRef: RefObject<\"cancel\" | \"send\">;\n onCancel: () => void;\n};\n\nexport function ChatReplyPreview({\n target,\n side,\n avatar,\n author,\n replyLabel,\n cancelLabel,\n children,\n dismissalRef,\n onCancel,\n}: ChatReplyPreviewProps): ReactElement {\n const anchorRef = useRef<HTMLDivElement>(null);\n const bubbleRef = useRef<HTMLDivElement>(null);\n const [origin, setOrigin] = useState<number | null>(null);\n const reduceMotion = useReducedMotion();\n const [isPresent, safeToRemove] = usePresence();\n const own = side === \"outgoing\";\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: Remeasure the source on exit after the viewport or keyboard may have moved.\n useLayoutEffect(() => {\n const anchor = anchorRef.current;\n const bubble = bubbleRef.current;\n if (!anchor || !bubble) return;\n const destination = anchor.getBoundingClientRect();\n const source = target.source.getBoundingClientRect();\n setOrigin(source.top - destination.top - bubble.offsetTop);\n }, [isPresent, target]);\n const returning =\n dismissalRef.current === \"cancel\" && target.source.isConnected;\n\n return (\n <>\n <motion.button\n type=\"button\"\n tabIndex={-1}\n aria-label={cancelLabel}\n className=\"absolute inset-0 z-40 cursor-default touch-none bg-popover/32 backdrop-blur-sm before:pointer-events-none before:absolute before:inset-x-0 before:top-0 before:h-6 before:bg-linear-to-b before:from-popover before:to-transparent before:content-['']\"\n initial={{ opacity: 0 }}\n animate={{ opacity: isPresent ? 1 : 0 }}\n transition={{ duration: reduceMotion ? 0 : 0.22 }}\n onClick={onCancel}\n onMouseDown={(event) => {\n if (event.button === 0) event.preventDefault();\n }}\n onWheel={(event) => event.preventDefault()}\n />\n <div className=\"pointer-events-none absolute inset-0 z-50 overflow-clip\">\n <ScrollArea\n overscrollContain\n className=\"**:data-[slot=scroll-area-content]:flex **:data-[slot=scroll-area-content]:min-h-full **:data-[slot=scroll-area-content]:flex-col **:data-[slot=scroll-area-content]:py-4 [&_[data-slot=scroll-area-scrollbar]]:pointer-events-auto\"\n >\n <div\n ref={anchorRef}\n data-slot=\"chat-reply-focus\"\n className=\"relative mx-4 mt-auto shrink-0\"\n >\n <motion.div\n aria-hidden=\"true\"\n className=\"absolute -inset-x-4 -top-20 -bottom-4 bg-linear-to-t from-[calc(100%-4rem)] from-popover to-transparent\"\n initial={{ opacity: 0 }}\n animate={{ opacity: isPresent ? 1 : 0 }}\n transition={{ duration: reduceMotion ? 0 : 0.22 }}\n />\n <motion.div\n key={origin === null ? \"measuring\" : \"positioned\"}\n initial={\n reduceMotion\n ? false\n : { transform: `translateY(${origin ?? 0}px)`, opacity: 1 }\n }\n animate={\n isPresent\n ? { transform: \"translateY(0px)\", opacity: 1 }\n : {\n transform: returning\n ? `translateY(${origin ?? 0}px)`\n : \"translateY(6px)\",\n opacity: returning ? 1 : 0,\n }\n }\n transition={\n reduceMotion\n ? { duration: 0 }\n : isPresent || returning\n ? {\n type: \"tween\",\n duration: 0.35,\n ease: [0.3, 0.84, 0.24, 1],\n }\n : { duration: 0.3, ease: [0.22, 1, 0.36, 1] }\n }\n onAnimationComplete={() => {\n if (!isPresent) safeToRemove?.();\n }}\n className={cn(\n \"relative grid items-start gap-y-1\",\n own\n ? \"grid-cols-1\"\n : \"grid-cols-[1.75rem_minmax(0,1fr)] gap-x-2\",\n origin === null && \"invisible\",\n )}\n >\n {!own && (\n <motion.div\n className=\"col-start-1 row-start-2 w-7\"\n initial={{ opacity: target.firstInGroup ? 1 : 0 }}\n animate={{\n opacity: isPresent || target.firstInGroup ? 1 : 0,\n }}\n transition={{ duration: reduceMotion ? 0 : 0.18 }}\n >\n {avatar}\n </motion.div>\n )}\n <motion.div\n className={cn(\n \"flex h-lh min-w-0 max-w-full items-center gap-2 px-1 font-medium text-muted-foreground text-xs\",\n own ? \"justify-self-end\" : \"col-start-2 row-start-1\",\n )}\n initial={{ opacity: !own && target.firstInGroup ? 1 : 0 }}\n animate={{\n opacity: isPresent || (!own && target.firstInGroup) ? 1 : 0,\n }}\n transition={{ duration: reduceMotion ? 0 : 0.18 }}\n >\n <span role=\"status\" className=\"min-w-0 truncate\">\n {isPresent ? replyLabel : author}\n </span>\n </motion.div>\n <div\n ref={bubbleRef}\n style={{ width: target.width }}\n className={cn(\n \"pointer-events-auto relative row-start-2 max-w-full rounded-2xl bg-popover\",\n own ? \"justify-self-end\" : \"col-start-2\",\n target.firstInGroup &&\n (own ? \"rounded-se-md\" : \"rounded-ss-md\"),\n )}\n >\n <ChatMessageBubble\n side={own ? \"outgoing\" : \"incoming\"}\n firstInGroup={target.firstInGroup}\n >\n {children}\n </ChatMessageBubble>\n <motion.div\n className={cn(\n \"absolute -top-2.5 z-10 flex rounded-full bg-popover\",\n own ? \"-start-2.5\" : \"-end-2.5\",\n )}\n initial={{ opacity: 0 }}\n animate={{ opacity: isPresent ? 1 : 0 }}\n transition={{ duration: reduceMotion ? 0 : 0.18 }}\n >\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n size=\"icon-xs\"\n variant=\"outline\"\n aria-label={cancelLabel}\n className=\"size-6 rounded-full before:rounded-full\"\n onMouseDown={(event) => {\n if (event.button === 0) event.preventDefault();\n }}\n onClick={onCancel}\n />\n }\n >\n <XIcon aria-hidden=\"true\" />\n </TooltipTrigger>\n <TooltipPopup>{cancelLabel}</TooltipPopup>\n </Tooltip>\n </motion.div>\n </div>\n </motion.div>\n </div>\n </ScrollArea>\n </div>\n </>\n );\n}\n"
68
+ },
69
+ {
70
+ "path": "registry/default/ui/chat/chat-reply-reference.tsx",
71
+ "content": "\"use client\";\n\nimport { ArrowElbowDownRightIcon } from \"@phosphor-icons/react\";\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatReplyReferenceProps = Omit<\n ComponentProps<\"button\">,\n \"children\"\n> & {\n author: string;\n preview: string;\n};\n\nexport function ChatReplyReference({\n author,\n preview,\n className,\n ...props\n}: ChatReplyReferenceProps): ReactElement {\n return (\n <button\n type=\"button\"\n data-slot=\"chat-reply-reference\"\n className={cn(\n \"group/reply-reference flex min-w-0 items-start gap-1.5 text-start text-xs outline-none transition-colors focus-visible:rounded-sm focus-visible:text-primary focus-visible:ring-2 focus-visible:ring-current enabled:hover:text-primary motion-reduce:transition-none\",\n className,\n )}\n {...props}\n >\n <ArrowElbowDownRightIcon\n aria-hidden=\"true\"\n className=\"mt-0.5 size-3.5 shrink-0 opacity-64 transition-opacity group-hover/reply-reference:opacity-100 group-focus-visible/reply-reference:opacity-100\"\n />\n <span className=\"flex min-w-0 flex-col gap-0.5\">\n <span className=\"font-medium\">{author}</span>\n <span className=\"line-clamp-2 text-foreground/80\">{preview}</span>\n </span>\n </button>\n );\n}\n"
72
+ },
73
+ {
74
+ "path": "registry/default/ui/chat/chat-states.tsx",
75
+ "content": "\"use client\";\n\nimport type { ReactElement, ReactNode } from \"react\";\nimport { Children } from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyMedia,\n EmptyTitle,\n} from \"@tc96/ui/empty\";\nimport { Skeleton } from \"@tc96/ui/skeleton\";\nimport {\n ChatMessageAvatar,\n ChatMessageContent,\n ChatMessageHeader,\n ChatMessageLayout,\n} from \"./chat-message-layout\";\n\nexport type ChatEmptyStateProps = {\n title: ReactNode;\n description: ReactNode;\n icon: ReactNode;\n children?: ReactNode;\n};\n\nexport function ChatEmptyState({\n title,\n description,\n icon,\n children,\n}: ChatEmptyStateProps): ReactElement {\n return (\n <Empty role=\"status\" className=\"min-h-64 gap-4 py-10 md:py-10\">\n <EmptyHeader>\n <EmptyMedia variant=\"icon\" className=\"mb-2 bg-popover\">\n {icon}\n </EmptyMedia>\n <EmptyTitle>{title}</EmptyTitle>\n <EmptyDescription>{description}</EmptyDescription>\n </EmptyHeader>\n {Children.toArray(children).length > 0 && (\n <EmptyContent>{children}</EmptyContent>\n )}\n </Empty>\n );\n}\n\nconst LOADING_ROWS = [\n { id: \"first\", side: \"incoming\" },\n { id: \"second\", side: \"outgoing\" },\n { id: \"third\", side: \"incoming\" },\n { id: \"fourth\", side: \"outgoing\" },\n] as const;\n\nexport function ChatLoadingState({\n label,\n children,\n}: {\n label: string;\n children?: ReactNode;\n}): ReactElement {\n return (\n <div role=\"status\" className=\"flex flex-col gap-5 py-4\">\n <span className=\"sr-only\">{label}</span>\n {LOADING_ROWS.map(({ side, id }) => (\n <ChatMessageLayout\n key={id}\n align={side === \"outgoing\" ? \"end\" : \"start\"}\n aria-hidden=\"true\"\n >\n {side === \"incoming\" && (\n <>\n <ChatMessageHeader>\n <Skeleton className=\"h-3 w-20 motion-reduce:animate-none\" />\n </ChatMessageHeader>\n <ChatMessageAvatar>\n <Skeleton className=\"size-7 rounded-full motion-reduce:animate-none\" />\n </ChatMessageAvatar>\n </>\n )}\n <ChatMessageContent>\n <Skeleton\n className={cn(\n \"h-11 w-56 max-w-[83%] rounded-2xl motion-reduce:animate-none\",\n side === \"incoming\" ? \"rounded-ss-md\" : \"rounded-se-md\",\n )}\n />\n <Skeleton className=\"mx-1 h-2 w-9 motion-reduce:animate-none\" />\n </ChatMessageContent>\n </ChatMessageLayout>\n ))}\n {children}\n </div>\n );\n}\n\nexport function ChatStatusBar({\n title,\n description,\n action,\n}: {\n title: ReactNode;\n description: ReactNode;\n action?: ReactNode;\n}): ReactElement {\n return (\n <div\n role=\"status\"\n className=\"flex shrink-0 items-center justify-between gap-3 border-border/60 border-y bg-muted/72 px-5 py-2.5\"\n >\n <div className=\"text-xs\">\n <p className=\"m-0 font-medium\">{title}</p>\n <p className=\"m-0 mt-1 text-muted-foreground\">{description}</p>\n </div>\n {action}\n </div>\n );\n}\n"
76
+ },
77
+ {
78
+ "path": "registry/default/ui/chat/chat-typing-indicator.tsx",
79
+ "content": "\"use client\";\n\nimport {\n AnimatePresence,\n motion,\n usePresence,\n useReducedMotion,\n} from \"motion/react\";\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { Fragment } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport type ChatTypingIndicatorProps = Omit<\n ComponentProps<\"div\">,\n \"children\"\n> & {\n label: string;\n visible?: boolean;\n};\n\nexport function ChatTypingIndicator({\n label,\n visible = true,\n className,\n ...props\n}: ChatTypingIndicatorProps): ReactElement {\n return (\n <AnimatePresence>\n {visible && (\n <Fragment key=\"typing\">\n <ChatTypingIndicatorContent\n label={label}\n className={className}\n {...props}\n />\n </Fragment>\n )}\n </AnimatePresence>\n );\n}\n\nfunction ChatTypingIndicatorContent({\n label,\n className,\n ...props\n}: Omit<ChatTypingIndicatorProps, \"visible\">): ReactElement {\n const reduceMotion = useReducedMotion();\n const [isPresent, safeToRemove] = usePresence();\n return (\n <motion.div\n className=\"overflow-hidden\"\n initial={{ height: 0, opacity: 0 }}\n animate={\n isPresent ? { height: \"auto\", opacity: 1 } : { height: 0, opacity: 0 }\n }\n transition={{\n duration: reduceMotion ? 0 : 0.2,\n ease: [0.22, 1, 0.36, 1],\n }}\n onAnimationComplete={() => {\n if (!isPresent) safeToRemove?.();\n }}\n >\n <div\n role=\"status\"\n data-slot=\"chat-typing-indicator\"\n className={cn(\"flex items-center gap-2.5\", className)}\n {...props}\n >\n <motion.div\n aria-hidden=\"true\"\n className=\"flex origin-bottom-left items-center gap-1 rounded-2xl rounded-es-md bg-muted/72 px-3 py-3.5 rtl:origin-bottom-right\"\n initial={{ transform: reduceMotion ? \"scale(1)\" : \"scale(0.92)\" }}\n animate={{\n transform: isPresent || reduceMotion ? \"scale(1)\" : \"scale(0.96)\",\n }}\n transition={{\n duration: reduceMotion ? 0 : 0.2,\n ease: [0.22, 1, 0.36, 1],\n }}\n >\n {[0, 1, 2].map((dot) => (\n <motion.span\n key={dot}\n className=\"block size-1.5 rounded-full bg-muted-foreground\"\n initial={{\n transform: \"translateY(0px) scale(0.8)\",\n opacity: 0.4,\n }}\n animate={\n reduceMotion\n ? { transform: \"translateY(0px) scale(1)\", opacity: 1 }\n : {\n transform: [\n \"translateY(0px) scale(0.8)\",\n \"translateY(-2px) scale(1.1)\",\n \"translateY(0px) scale(0.8)\",\n \"translateY(0px) scale(0.8)\",\n ],\n opacity: [0.4, 1, 0.4, 0.4],\n }\n }\n transition={\n reduceMotion\n ? { duration: 0 }\n : {\n duration: 1.4,\n times: [0, 0.22, 0.44, 1],\n delay: dot * 0.16,\n repeat: Number.POSITIVE_INFINITY,\n ease: \"easeInOut\",\n }\n }\n />\n ))}\n </motion.div>\n <span className=\"min-w-0 text-muted-foreground text-xs\">{label}</span>\n </div>\n </motion.div>\n );\n}\n"
80
+ },
81
+ {
82
+ "path": "registry/default/ui/chat/chat-unread-divider.tsx",
83
+ "content": "\"use client\";\n\nimport type { ComponentProps, ReactElement } from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport function ChatUnreadDivider({\n children,\n className,\n ...props\n}: ComponentProps<\"div\">): ReactElement {\n return (\n <div\n data-slot=\"chat-unread-divider\"\n className={cn(\n \"my-4 flex items-center gap-3 font-medium text-foreground text-xs\",\n className,\n )}\n {...props}\n >\n <span aria-hidden=\"true\" className=\"h-px flex-1 bg-input\" />\n {children}\n <span aria-hidden=\"true\" className=\"h-px flex-1 bg-input\" />\n </div>\n );\n}\n"
84
+ },
85
+ {
86
+ "path": "registry/default/ui/chat/hooks/use-chat-popup-dismissal.ts",
87
+ "content": "\"use client\";\n\nimport { type RefObject, useEffect, useRef } from \"react\";\n\nexport function useChatPopupDismissal(\n active: boolean,\n triggerRef: RefObject<HTMLElement | null>,\n onDismiss: () => void,\n): void {\n const onDismissRef = useRef(onDismiss);\n useEffect(() => {\n onDismissRef.current = onDismiss;\n }, [onDismiss]);\n\n useEffect(() => {\n const trigger = triggerRef.current;\n if (!active || !trigger) return;\n const ownerDocument = trigger.ownerDocument;\n const onScrollInput = (event: Event): void => {\n if (!(event.target instanceof Element)) return;\n if (event.target.closest('[role=\"menu\"], [data-slot=\"popover-popup\"]'))\n return;\n if (event instanceof KeyboardEvent) {\n if (\n event.defaultPrevented ||\n ![\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"PageUp\",\n \"PageDown\",\n \"Home\",\n \"End\",\n \" \",\n ].includes(event.key) ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.target.closest(\n \"input, textarea, select, button, a, [contenteditable], [role=menu], [role=listbox], [role=combobox], [role=slider], [role=tablist]\",\n )\n )\n return;\n }\n const isScrollable = (element: Element): boolean => {\n const style = getComputedStyle(element);\n const page = element === ownerDocument.scrollingElement;\n return (\n (element.scrollHeight > element.clientHeight &&\n (page || /auto|scroll/.test(style.overflowY))) ||\n (element.scrollWidth > element.clientWidth &&\n (page || /auto|scroll/.test(style.overflowX)))\n );\n };\n // Dismiss on input in the scroller, never on automatic scrolling or menu navigation.\n for (\n let element: Element | null = event.target;\n element;\n element = element.parentElement\n ) {\n if (!isScrollable(element)) continue;\n if (element.contains(trigger)) onDismissRef.current();\n return;\n }\n // Modal menus intercept wheel/touch input with a backdrop over the scroller.\n const point =\n event instanceof WheelEvent\n ? event\n : event instanceof TouchEvent\n ? event.touches[0]\n : undefined;\n if (!point) return;\n for (\n let element = trigger.parentElement;\n element;\n element = element.parentElement\n ) {\n if (!isScrollable(element)) continue;\n const bounds = element.getBoundingClientRect();\n if (\n point.clientX >= bounds.left &&\n point.clientX <= bounds.right &&\n point.clientY >= bounds.top &&\n point.clientY <= bounds.bottom\n ) {\n onDismissRef.current();\n return;\n }\n }\n };\n const scrollInputs = [\"wheel\", \"touchmove\", \"keydown\"] as const;\n for (const type of scrollInputs)\n ownerDocument.addEventListener(type, onScrollInput, { passive: true });\n return () => {\n for (const type of scrollInputs)\n ownerDocument.removeEventListener(type, onScrollInput);\n };\n }, [active, triggerRef]);\n}\n"
88
+ },
89
+ {
90
+ "path": "registry/default/ui/chat/hooks/use-chat-scroll.ts",
91
+ "content": "\"use client\";\n\nimport {\n type UIEvent,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nexport type ChatScrollOptions = {\n active?: boolean;\n paused?: boolean;\n itemCount: number;\n layoutKey?: string | number;\n onReachEnd?: () => void;\n};\n\nexport function useChatScroll({\n active = true,\n paused = false,\n itemCount,\n layoutKey,\n onReachEnd,\n}: ChatScrollOptions) {\n const viewportRef = useRef<HTMLDivElement>(null);\n const atBottomRef = useRef(true);\n const [showJump, setShowJump] = useState(false);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: Follow content changes before scroll events can misinterpret the new height.\n useLayoutEffect(() => {\n const viewport = viewportRef.current;\n if (!active || paused || !viewport) return;\n // Follow before a scroll event can interpret newly added height as scrolling away.\n if (atBottomRef.current) {\n viewport.scrollTop = viewport.scrollHeight;\n setShowJump(false);\n } else {\n setShowJump(\n viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight > 64,\n );\n }\n }, [active, paused, itemCount, layoutKey]);\n\n useEffect(() => {\n if (!active || paused) return;\n let observer: ResizeObserver | undefined;\n const frame = requestAnimationFrame(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n observer = new ResizeObserver(() => {\n if (atBottomRef.current) viewport.scrollTop = viewport.scrollHeight;\n });\n observer.observe(viewport);\n if (viewport.firstElementChild)\n observer.observe(viewport.firstElementChild);\n });\n return () => {\n cancelAnimationFrame(frame);\n observer?.disconnect();\n };\n }, [active, paused]);\n\n const updatePosition = (): void => {\n const viewport = viewportRef.current;\n atBottomRef.current = Boolean(\n viewport &&\n viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < 64,\n );\n };\n\n const onScroll = (_event: UIEvent<HTMLDivElement>): void => {\n if (paused) return;\n updatePosition();\n setShowJump(!atBottomRef.current);\n if (atBottomRef.current) onReachEnd?.();\n };\n\n const resetScroll = (atBottom = true): void => {\n atBottomRef.current = atBottom;\n setShowJump(!atBottom);\n requestAnimationFrame(() => {\n const viewport = viewportRef.current;\n if (viewport) viewport.scrollTop = atBottom ? viewport.scrollHeight : 0;\n });\n };\n\n const scrollToLatest = (): void => {\n atBottomRef.current = true;\n const viewport = viewportRef.current;\n viewport?.scrollTo({\n top: viewport.scrollHeight,\n behavior: window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n ? \"auto\"\n : \"smooth\",\n });\n };\n\n return {\n viewportRef,\n atBottomRef,\n showJump,\n onScroll,\n resetScroll,\n updatePosition,\n scrollToLatest,\n };\n}\n\nexport type ChatScrollController = ReturnType<typeof useChatScroll>;\n"
92
+ },
93
+ {
94
+ "path": "registry/default/ui/chat/lib/split-chat-message-preview.ts",
95
+ "content": "export function splitChatMessagePreview(\n text: string,\n maxPreviewLength = 500,\n): { preview: string; remainder: string | null } {\n if (text.length <= maxPreviewLength)\n return { preview: text, remainder: null };\n\n const limit = Math.max(1, Math.floor(maxPreviewLength));\n const paragraphBreak = text.lastIndexOf(\"\\n\\n\", limit);\n let splitAt = limit;\n if (paragraphBreak > limit / 2) {\n splitAt = paragraphBreak;\n } else {\n for (let index = limit; index > 0; index--) {\n if (/\\s/u.test(text[index] ?? \"\")) {\n splitAt = index;\n break;\n }\n }\n }\n\n if (typeof Intl.Segmenter === \"function\") {\n const segments = new Intl.Segmenter(undefined, {\n granularity: \"grapheme\",\n }).segment(text);\n for (const { index, segment } of segments) {\n if (index + segment.length > splitAt) {\n splitAt = index || segment.length;\n break;\n }\n }\n } else if (/^[\\uDC00-\\uDFFF]$/u.test(text[splitAt] ?? \"\")) {\n splitAt = splitAt === 1 ? 2 : splitAt - 1;\n }\n\n return {\n preview: text.slice(0, splitAt).trimEnd(),\n remainder: text.slice(splitAt).trimStart() || null,\n };\n}\n"
96
+ }
97
+ ],
98
+ "dependencies": [
99
+ "@base-ui/react@1.8.0",
100
+ "@phosphor-icons/react@2.1.10",
101
+ "motion@14.0.0"
102
+ ],
103
+ "registryDependencies": [
104
+ "@ui/button",
105
+ "@ui/collapsible",
106
+ "@ui/empty",
107
+ "@ui/menu",
108
+ "@ui/popover",
109
+ "@ui/scroll-area",
110
+ "@ui/skeleton",
111
+ "@ui/toggle",
112
+ "@ui/toolbar",
113
+ "@ui/tooltip"
114
+ ]
115
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "checkbox-group",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/checkbox-group.tsx",
7
+ "content": "\"use client\";\n\nimport { CheckboxGroup as CheckboxGroupPrimitive } from \"@base-ui/react/checkbox-group\";\nimport type React from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport function CheckboxGroup({\n className,\n ...props\n}: CheckboxGroupPrimitive.Props): React.ReactElement {\n return (\n <CheckboxGroupPrimitive\n className={cn(\"flex flex-col items-start gap-3\", className)}\n {...props}\n />\n );\n}\n\nexport { CheckboxGroupPrimitive };\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0"
12
+ ],
13
+ "registryDependencies": []
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "checkbox",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/checkbox.tsx",
7
+ "content": "\"use client\";\n\nimport { Checkbox as CheckboxPrimitive } from \"@base-ui/react/checkbox\";\nimport type React from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport function Checkbox({\n className,\n ...props\n}: CheckboxPrimitive.Root.Props): React.ReactElement {\n return (\n <CheckboxPrimitive.Root\n className={cn(\n \"relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[.25rem] border border-input bg-background not-dark:bg-clip-padding shadow-xs/5 outline-none ring-ring transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[3px] not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:cursor-not-allowed data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none\",\n className,\n )}\n data-slot=\"checkbox\"\n {...props}\n >\n <CheckboxPrimitive.Indicator\n className=\"absolute -inset-px flex items-center justify-center rounded-[.25rem] text-primary-foreground data-unchecked:hidden data-checked:bg-primary data-indeterminate:text-foreground\"\n data-slot=\"checkbox-indicator\"\n render={(\n props: React.ComponentProps<\"span\">,\n state: CheckboxPrimitive.Indicator.State,\n ) => (\n <span {...props}>\n {state.indeterminate ? (\n <svg\n aria-hidden=\"true\"\n className=\"size-3.5 sm:size-3\"\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"3\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12h13.496\" />\n </svg>\n ) : (\n <svg\n aria-hidden=\"true\"\n className=\"size-3.5 sm:size-3\"\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"3\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n )}\n </span>\n )}\n />\n </CheckboxPrimitive.Root>\n );\n}\n\nexport { CheckboxPrimitive };\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0"
12
+ ],
13
+ "registryDependencies": []
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "collapsible",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/collapsible.tsx",
7
+ "content": "\"use client\";\n\nimport { Collapsible as CollapsiblePrimitive } from \"@base-ui/react/collapsible\";\nimport type React from \"react\";\nimport { cn } from \"@tc96/utils\";\n\nexport function Collapsible({\n ...props\n}: CollapsiblePrimitive.Root.Props): React.ReactElement {\n return <CollapsiblePrimitive.Root data-slot=\"collapsible\" {...props} />;\n}\n\nexport function CollapsibleTrigger({\n className,\n ...props\n}: CollapsiblePrimitive.Trigger.Props): React.ReactElement {\n return (\n <CollapsiblePrimitive.Trigger\n className={className}\n data-slot=\"collapsible-trigger\"\n {...props}\n />\n );\n}\n\nexport function CollapsiblePanel({\n className,\n ...props\n}: CollapsiblePrimitive.Panel.Props): React.ReactElement {\n return (\n <CollapsiblePrimitive.Panel\n className={cn(\n \"h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-200 data-ending-style:h-0 data-starting-style:h-0\",\n className,\n )}\n data-slot=\"collapsible-panel\"\n {...props}\n />\n );\n}\n\nexport { CollapsiblePrimitive, CollapsiblePanel as CollapsibleContent };\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0"
12
+ ],
13
+ "registryDependencies": []
14
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "combobox",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/combobox.tsx",
7
+ "content": "\"use client\";\n\nimport { Combobox as ComboboxPrimitive } from \"@base-ui/react/combobox\";\nimport { CaretUpDownIcon, XIcon } from \"@phosphor-icons/react\";\nimport * as React from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport { Input } from \"@tc96/ui/input\";\nimport { ScrollArea } from \"@tc96/ui/scroll-area\";\n\nexport const ComboboxContext: React.Context<{\n chipsRef: React.RefObject<Element | null> | null;\n multiple: boolean;\n}> = React.createContext<{\n chipsRef: React.RefObject<Element | null> | null;\n multiple: boolean;\n}>({\n chipsRef: null,\n multiple: false,\n});\n\nexport function Combobox<\n Value,\n Multiple extends boolean | undefined = false,\n Item = Value,\n>(\n props: ComboboxPrimitive.Root.Props<Value, Multiple, Item>,\n): React.ReactElement {\n const chipsRef = React.useRef<Element | null>(null);\n return (\n <ComboboxContext.Provider value={{ chipsRef, multiple: !!props.multiple }}>\n <ComboboxPrimitive.Root {...props} />\n </ComboboxContext.Provider>\n );\n}\n\nexport function ComboboxChipsInput({\n className,\n size,\n ...props\n}: Omit<ComboboxPrimitive.Input.Props, \"size\"> & {\n size?: \"sm\" | \"default\" | \"lg\" | number;\n ref?: React.Ref<HTMLInputElement>;\n}): React.ReactElement {\n const sizeValue = (size ?? \"default\") as \"sm\" | \"default\" | \"lg\" | number;\n\n return (\n <ComboboxPrimitive.Input\n className={cn(\n \"min-w-12 flex-1 text-base text-foreground outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5\",\n sizeValue === \"sm\" ? \"ps-1.5\" : \"ps-2\",\n className,\n )}\n data-size={typeof sizeValue === \"string\" ? sizeValue : undefined}\n data-slot=\"combobox-chips-input\"\n size={typeof sizeValue === \"number\" ? sizeValue : undefined}\n {...props}\n />\n );\n}\n\nexport function ComboboxInput({\n className,\n showTrigger = true,\n showClear = false,\n startAddon,\n size,\n triggerProps,\n clearProps,\n ...props\n}: Omit<ComboboxPrimitive.Input.Props, \"size\"> & {\n showTrigger?: boolean;\n showClear?: boolean;\n startAddon?: React.ReactNode;\n size?: \"sm\" | \"default\" | \"lg\" | number;\n ref?: React.Ref<HTMLInputElement>;\n triggerProps?: ComboboxPrimitive.Trigger.Props;\n clearProps?: ComboboxPrimitive.Clear.Props;\n}): React.ReactElement {\n const sizeValue = (size ?? \"default\") as \"sm\" | \"default\" | \"lg\" | number;\n\n return (\n <ComboboxPrimitive.InputGroup\n className=\"relative not-has-[>*.w-full]:w-fit w-full text-foreground has-disabled:opacity-64\"\n data-slot=\"combobox-input-group\"\n >\n {startAddon && (\n <div\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:-mx-0.5\"\n data-slot=\"combobox-start-addon\"\n >\n {startAddon}\n </div>\n )}\n <ComboboxPrimitive.Input\n className={cn(\n startAddon &&\n \"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]\",\n sizeValue === \"sm\"\n ? \"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5\"\n : \"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7\",\n className,\n )}\n data-slot=\"combobox-input\"\n render={\n <Input\n className=\"has-disabled:opacity-100\"\n nativeInput\n size={sizeValue}\n />\n }\n {...props}\n />\n {showTrigger && (\n <ComboboxTrigger\n aria-label=\"Show options\"\n className={cn(\n \"absolute top-1/2 inline-flex size-8 shrink-0 -translate-y-1/2 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n sizeValue === \"sm\" ? \"end-0\" : \"end-0.5\",\n )}\n {...triggerProps}\n >\n <ComboboxPrimitive.Icon aria-hidden=\"true\" data-slot=\"combobox-icon\">\n <CaretUpDownIcon aria-hidden=\"true\" />\n </ComboboxPrimitive.Icon>\n </ComboboxTrigger>\n )}\n {showClear && (\n <ComboboxClear\n aria-label=\"Clear selection\"\n className={cn(\n \"absolute top-1/2 inline-flex size-8 shrink-0 -translate-y-1/2 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n sizeValue === \"sm\" ? \"end-0\" : \"end-0.5\",\n )}\n {...clearProps}\n >\n <XIcon aria-hidden=\"true\" />\n </ComboboxClear>\n )}\n </ComboboxPrimitive.InputGroup>\n );\n}\n\nexport function ComboboxTrigger({\n className,\n children,\n ...props\n}: ComboboxPrimitive.Trigger.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Trigger\n className={className}\n data-slot=\"combobox-trigger\"\n {...props}\n >\n {children}\n </ComboboxPrimitive.Trigger>\n );\n}\n\nexport function ComboboxPopup({\n className,\n children,\n side = \"bottom\",\n sideOffset = 4,\n alignOffset,\n align = \"start\",\n anchor: anchorProp,\n portalProps,\n ...props\n}: ComboboxPrimitive.Popup.Props & {\n align?: ComboboxPrimitive.Positioner.Props[\"align\"];\n sideOffset?: ComboboxPrimitive.Positioner.Props[\"sideOffset\"];\n alignOffset?: ComboboxPrimitive.Positioner.Props[\"alignOffset\"];\n side?: ComboboxPrimitive.Positioner.Props[\"side\"];\n anchor?: ComboboxPrimitive.Positioner.Props[\"anchor\"];\n portalProps?: ComboboxPrimitive.Portal.Props;\n}): React.ReactElement {\n const { chipsRef } = React.useContext(ComboboxContext);\n const anchor = anchorProp ?? chipsRef;\n\n return (\n <ComboboxPrimitive.Portal {...portalProps}>\n <ComboboxPrimitive.Positioner\n align={align}\n alignOffset={alignOffset}\n anchor={anchor}\n className=\"z-50 select-none\"\n data-slot=\"combobox-positioner\"\n side={side}\n sideOffset={sideOffset}\n >\n <span\n className={cn(\n \"relative flex max-h-full min-w-(--anchor-width) max-w-(--available-width) origin-(--transform-origin) rounded-lg border bg-popover not-dark:bg-clip-padding shadow-lg/5 transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]\",\n className,\n )}\n >\n <ComboboxPrimitive.Popup\n className=\"flex max-h-[min(var(--available-height),23rem)] flex-1 flex-col text-foreground\"\n data-slot=\"combobox-popup\"\n {...props}\n >\n {children}\n </ComboboxPrimitive.Popup>\n </span>\n </ComboboxPrimitive.Positioner>\n </ComboboxPrimitive.Portal>\n );\n}\n\nexport function ComboboxItem({\n className,\n children,\n ...props\n}: ComboboxPrimitive.Item.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Item\n className={cn(\n \"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[minmax(0,1fr)_.75rem] items-center gap-4 rounded-sm py-1 ps-2 pe-2.5 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"combobox-item\"\n {...props}\n >\n <div className=\"wrap-anywhere col-start-1 min-w-0\">{children}</div>\n <ComboboxPrimitive.ItemIndicator className=\"col-start-2 -me-0.5\">\n <svg\n aria-hidden=\"true\"\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </ComboboxPrimitive.ItemIndicator>\n </ComboboxPrimitive.Item>\n );\n}\n\nexport function ComboboxSeparator({\n className,\n ...props\n}: ComboboxPrimitive.Separator.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Separator\n className={cn(\"mx-2 my-1 h-px bg-border last:hidden\", className)}\n data-slot=\"combobox-separator\"\n {...props}\n />\n );\n}\n\nexport function ComboboxGroup({\n className,\n ...props\n}: ComboboxPrimitive.Group.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Group\n className={cn(\"[[role=group]+&]:mt-1.5\", className)}\n data-slot=\"combobox-group\"\n {...props}\n />\n );\n}\n\nexport function ComboboxGroupLabel({\n className,\n ...props\n}: ComboboxPrimitive.GroupLabel.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.GroupLabel\n className={cn(\n \"px-2 py-1.5 font-medium text-muted-foreground text-xs\",\n className,\n )}\n data-slot=\"combobox-group-label\"\n {...props}\n />\n );\n}\n\nexport function ComboboxEmpty({\n className,\n ...props\n}: ComboboxPrimitive.Empty.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Empty\n className={cn(\n \"not-empty:p-2 text-center text-base text-muted-foreground sm:text-sm\",\n className,\n )}\n data-slot=\"combobox-empty\"\n {...props}\n />\n );\n}\n\nexport function ComboboxRow({\n className,\n ...props\n}: ComboboxPrimitive.Row.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Row\n className={className}\n data-slot=\"combobox-row\"\n {...props}\n />\n );\n}\n\nexport const ComboboxValue: typeof ComboboxPrimitive.Value =\n ComboboxPrimitive.Value;\n\nexport function ComboboxList({\n className,\n ...props\n}: ComboboxPrimitive.List.Props): React.ReactElement {\n return (\n <ScrollArea overscrollContain scrollbarGutter scrollFade>\n <ComboboxPrimitive.List\n className={cn(\n \"not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3\",\n className,\n )}\n data-slot=\"combobox-list\"\n {...props}\n />\n </ScrollArea>\n );\n}\n\nexport function ComboboxClear({\n className,\n ...props\n}: ComboboxPrimitive.Clear.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Clear\n className={className}\n data-slot=\"combobox-clear\"\n {...props}\n />\n );\n}\n\nexport function ComboboxStatus({\n className,\n ...props\n}: ComboboxPrimitive.Status.Props): React.ReactElement {\n return (\n <ComboboxPrimitive.Status\n className={cn(\n \"px-3 py-2 font-medium text-muted-foreground text-xs empty:m-0 empty:p-0\",\n className,\n )}\n data-slot=\"combobox-status\"\n {...props}\n />\n );\n}\n\nexport const ComboboxCollection: typeof ComboboxPrimitive.Collection =\n ComboboxPrimitive.Collection;\n\nexport function ComboboxChips({\n className,\n children,\n startAddon,\n ...props\n}: ComboboxPrimitive.Chips.Props & {\n startAddon?: React.ReactNode;\n}): React.ReactElement {\n const { chipsRef } = React.useContext(ComboboxContext);\n\n return (\n <ComboboxPrimitive.Chips\n className={cn(\n \"relative inline-flex min-h-9 w-full flex-wrap gap-1 rounded-lg border border-input bg-background not-dark:bg-clip-padding p-[calc(--spacing(1)-1px)] text-base shadow-xs/5 outline-none ring-ring/24 transition-shadow *:min-h-7 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-disabled:not-focus-within:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-within:border-ring focus-within:ring-[3px] has-disabled:pointer-events-none has-data-[size=lg]:min-h-10 has-data-[size=sm]:min-h-8 has-aria-invalid:border-destructive/36 has-disabled:opacity-64 has-[:disabled,:focus-within,[aria-invalid]]:shadow-none focus-within:has-aria-invalid:border-destructive/64 focus-within:has-aria-invalid:ring-destructive/16 has-data-[size=lg]:*:min-h-8 has-data-[size=sm]:*:min-h-6 sm:min-h-8 sm:text-sm sm:has-data-[size=lg]:min-h-9 sm:has-data-[size=sm]:min-h-7 sm:*:min-h-6 sm:has-data-[size=lg]:*:min-h-7 sm:has-data-[size=sm]:*:min-h-5 dark:not-has-disabled:bg-input/32 dark:has-aria-invalid:ring-destructive/24 dark:not-has-disabled:not-focus-within:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)]\",\n className,\n )}\n data-slot=\"combobox-chips\"\n ref={chipsRef as React.Ref<HTMLDivElement> | null}\n {...props}\n >\n {startAddon && (\n <div\n aria-hidden=\"true\"\n className=\"flex shrink-0 items-center ps-2 opacity-80 has-[~[data-size=sm]]:has-[+[data-slot=combobox-chip]]:pe-1.5 has-[~[data-size=sm]]:ps-1.5 has-[+[data-slot=combobox-chip]]:pe-2 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:-ms-0.5 [&_svg]:-me-1.5\"\n data-slot=\"combobox-start-addon\"\n >\n {startAddon}\n </div>\n )}\n {children}\n </ComboboxPrimitive.Chips>\n );\n}\n\nexport function ComboboxChip({\n children,\n removeProps,\n ...props\n}: ComboboxPrimitive.Chip.Props & {\n removeProps?: ComboboxPrimitive.ChipRemove.Props;\n}): React.ReactElement {\n return (\n <ComboboxPrimitive.Chip\n className=\"flex items-center rounded-[calc(var(--radius-md)-1px)] bg-accent ps-2 font-medium text-accent-foreground text-sm outline-none sm:text-xs/(--text-xs--line-height) [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5\"\n data-slot=\"combobox-chip\"\n {...props}\n >\n {children}\n <ComboboxChipRemove {...removeProps} />\n </ComboboxPrimitive.Chip>\n );\n}\n\nexport function ComboboxChipRemove(\n props: ComboboxPrimitive.ChipRemove.Props,\n): React.ReactElement {\n return (\n <ComboboxPrimitive.ChipRemove\n aria-label=\"Remove\"\n className=\"h-full shrink-0 cursor-pointer px-1.5 opacity-80 hover:opacity-100 [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5\"\n data-slot=\"combobox-chip-remove\"\n {...props}\n >\n <XIcon aria-hidden=\"true\" />\n </ComboboxPrimitive.ChipRemove>\n );\n}\n\nexport const createComboboxItems: typeof ComboboxPrimitive.createItems =\n ComboboxPrimitive.createItems;\n\nexport const useComboboxFilter: typeof ComboboxPrimitive.useFilter =\n ComboboxPrimitive.useFilter;\n\nexport { ComboboxPrimitive };\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0",
12
+ "@phosphor-icons/react@2.1.10"
13
+ ],
14
+ "registryDependencies": [
15
+ "@ui/input",
16
+ "@ui/scroll-area"
17
+ ]
18
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "command",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/command.tsx",
7
+ "content": "\"use client\";\n\nimport { Dialog as CommandDialogPrimitive } from \"@base-ui/react/dialog\";\nimport { MagnifyingGlassIcon } from \"@phosphor-icons/react\";\nimport type * as React from \"react\";\nimport { cn } from \"@tc96/utils\";\nimport {\n Autocomplete,\n AutocompleteCollection,\n AutocompleteEmpty,\n AutocompleteGroup,\n AutocompleteGroupLabel,\n AutocompleteInput,\n AutocompleteItem,\n AutocompleteList,\n AutocompleteSeparator,\n} from \"@tc96/ui/autocomplete\";\n\nexport const CommandDialog: typeof CommandDialogPrimitive.Root =\n CommandDialogPrimitive.Root;\n\nexport const CommandDialogPortal: typeof CommandDialogPrimitive.Portal =\n CommandDialogPrimitive.Portal;\n\nexport const CommandCreateHandle: typeof CommandDialogPrimitive.createHandle =\n CommandDialogPrimitive.createHandle;\n\nexport function CommandDialogTrigger(\n props: CommandDialogPrimitive.Trigger.Props,\n): React.ReactElement {\n return (\n <CommandDialogPrimitive.Trigger\n data-slot=\"command-dialog-trigger\"\n {...props}\n />\n );\n}\n\nexport function CommandDialogBackdrop({\n className,\n ...props\n}: CommandDialogPrimitive.Backdrop.Props): React.ReactElement {\n return (\n <CommandDialogPrimitive.Backdrop\n className={cn(\n \"fixed inset-0 z-50 bg-black/32 backdrop-blur-sm transition-all duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-[-webkit-touch-callout:none]:absolute\",\n className,\n )}\n data-slot=\"command-dialog-backdrop\"\n {...props}\n />\n );\n}\n\nexport function CommandDialogViewport({\n className,\n ...props\n}: CommandDialogPrimitive.Viewport.Props): React.ReactElement {\n return (\n <CommandDialogPrimitive.Viewport\n className={cn(\n \"fixed inset-0 z-50 flex flex-col items-center px-4 py-[max(--spacing(4),4vh)] sm:py-[10vh]\",\n className,\n )}\n data-slot=\"command-dialog-viewport\"\n {...props}\n />\n );\n}\n\nexport function CommandDialogPopup({\n className,\n children,\n portalProps,\n ...props\n}: CommandDialogPrimitive.Popup.Props & {\n portalProps?: CommandDialogPrimitive.Portal.Props;\n}): React.ReactElement {\n return (\n <CommandDialogPortal {...portalProps}>\n <CommandDialogBackdrop />\n <CommandDialogViewport>\n <CommandDialogPrimitive.Popup\n className={cn(\n \"relative row-start-2 flex max-h-105 min-h-0 w-full min-w-0 max-w-xl -translate-y-[calc(1.25rem*var(--nested-dialogs))] scale-[calc(1-0.1*var(--nested-dialogs))] flex-col rounded-2xl border bg-popover not-dark:bg-clip-padding text-popover-foreground opacity-[calc(1-0.1*var(--nested-dialogs))] shadow-lg/5 outline-none transition-[scale,opacity,translate] duration-200 ease-in-out will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:bg-muted/72 before:shadow-[0_1px_--theme(--color-black/4%)] data-nested:data-ending-style:translate-y-8 data-nested:data-starting-style:translate-y-8 data-nested-dialog-open:origin-top data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 **:data-[slot=scroll-area-viewport]:data-has-overflow-y:pe-1 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]\",\n className,\n )}\n data-slot=\"command-dialog-popup\"\n {...props}\n >\n {children}\n </CommandDialogPrimitive.Popup>\n </CommandDialogViewport>\n </CommandDialogPortal>\n );\n}\n\nexport function Command({\n autoHighlight = \"always\",\n keepHighlight = true,\n ...props\n}: React.ComponentProps<typeof Autocomplete>): React.ReactElement {\n return (\n <Autocomplete\n autoHighlight={autoHighlight}\n inline\n keepHighlight={keepHighlight}\n open\n {...props}\n />\n );\n}\n\nexport function CommandInput({\n className,\n placeholder = undefined,\n ...props\n}: React.ComponentProps<typeof AutocompleteInput>): React.ReactElement {\n return (\n <div className=\"px-2.5 py-1.5\">\n <AutocompleteInput\n autoFocus\n className={cn(\n \"border-transparent! bg-transparent! shadow-none before:hidden has-focus-visible:ring-0\",\n className,\n )}\n placeholder={placeholder}\n size=\"lg\"\n startAddon={<MagnifyingGlassIcon aria-hidden=\"true\" />}\n {...props}\n />\n </div>\n );\n}\n\nexport function CommandList({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteList>): React.ReactElement {\n return (\n <AutocompleteList\n className={cn(\"not-empty:scroll-py-2 not-empty:p-2\", className)}\n data-slot=\"command-list\"\n {...props}\n />\n );\n}\n\nexport function CommandEmpty({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteEmpty>): React.ReactElement {\n return (\n <AutocompleteEmpty\n className={cn(\"not-empty:py-6\", className)}\n data-slot=\"command-empty\"\n {...props}\n />\n );\n}\n\nexport function CommandPanel({\n className,\n ...props\n}: React.ComponentProps<\"div\">): React.ReactElement {\n return (\n <div\n className={cn(\n \"relative -mx-px not-has-[+[data-slot=command-footer]]:-mb-px min-h-0 rounded-t-xl not-has-[+[data-slot=command-footer]]:rounded-b-2xl border border-b-0 bg-popover bg-clip-padding shadow-xs/5 [clip-path:inset(0_1px)] not-has-[+[data-slot=command-footer]]:[clip-path:inset(0_1px_1px_1px_round_0_0_calc(var(--radius-2xl)-1px)_calc(var(--radius-2xl)-1px))] before:pointer-events-none before:absolute before:inset-0 before:rounded-t-[calc(var(--radius-xl)-1px)] **:data-[slot=scroll-area-scrollbar]:mt-2\",\n className,\n )}\n {...props}\n />\n );\n}\n\nexport function CommandGroup({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteGroup>): React.ReactElement {\n return (\n <AutocompleteGroup\n className={className}\n data-slot=\"command-group\"\n {...props}\n />\n );\n}\n\nexport function CommandGroupLabel({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteGroupLabel>): React.ReactElement {\n return (\n <AutocompleteGroupLabel\n className={className}\n data-slot=\"command-group-label\"\n {...props}\n />\n );\n}\n\nexport const CommandCollection = AutocompleteCollection;\n\nexport function CommandItem({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteItem>): React.ReactElement {\n return (\n <AutocompleteItem\n className={cn(\"py-1.5\", className)}\n data-slot=\"command-item\"\n {...props}\n />\n );\n}\n\nexport function CommandSeparator({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompleteSeparator>): React.ReactElement {\n return (\n <AutocompleteSeparator\n className={cn(\"my-2\", className)}\n data-slot=\"command-separator\"\n {...props}\n />\n );\n}\n\nexport function CommandShortcut({\n className,\n ...props\n}: React.ComponentProps<\"kbd\">): React.ReactElement {\n return (\n <kbd\n className={cn(\n \"ms-auto font-medium font-sans text-muted-foreground/96 text-xs tracking-widest in-data-highlighted:text-muted-foreground\",\n className,\n )}\n data-slot=\"command-shortcut\"\n {...props}\n />\n );\n}\n\nexport function CommandFooter({\n className,\n ...props\n}: React.ComponentProps<\"div\">): React.ReactElement {\n return (\n <div\n className={cn(\n \"flex items-center justify-between gap-2 rounded-b-[calc(var(--radius-2xl)-1px)] border-t px-5 py-3 text-muted-foreground text-xs\",\n className,\n )}\n data-slot=\"command-footer\"\n {...props}\n />\n );\n}\n\nexport { CommandDialogPrimitive };\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0",
12
+ "@phosphor-icons/react@2.1.10"
13
+ ],
14
+ "registryDependencies": [
15
+ "@ui/autocomplete"
16
+ ]
17
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "composer-clipboard",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/lib/composer-clipboard.ts",
7
+ "content": "import type { ComposerPart, ComposerValue } from \"./composer-document\";\n\nexport const COMPOSER_CLIPBOARD_TYPE = \"application/x-coss-composer\";\n\nexport function parseComposerClipboard(raw: string): ComposerValue | null {\n if (!raw || raw.length > 100_000) return null;\n try {\n const value: unknown = JSON.parse(raw);\n if (!Array.isArray(value) || value.length > 1_000) return null;\n const parts: ComposerPart[] = [];\n for (const part of value) {\n if (!part || typeof part !== \"object\") return null;\n if (part.type === \"text\" && typeof part.text === \"string\") {\n parts.push({ type: \"text\", text: part.text });\n continue;\n }\n if (\n (part.type !== \"mention\" && part.type !== \"action\") ||\n typeof part.id !== \"string\" ||\n typeof part.label !== \"string\" ||\n typeof part.trigger !== \"string\"\n )\n return null;\n parts.push({\n type: part.type,\n id: part.id,\n label: part.label,\n trigger: part.trigger,\n ...(typeof part.kind === \"string\" ? { kind: part.kind } : {}),\n ...(typeof part.data === \"string\" ? { data: part.data } : {}),\n ...(typeof part.text === \"string\" ? { text: part.text } : {}),\n });\n }\n return parts;\n } catch {\n return null;\n }\n}\n"
8
+ }
9
+ ],
10
+ "dependencies": [],
11
+ "registryDependencies": [
12
+ "@ui/composer-document"
13
+ ]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "composer-document",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/lib/composer-document.ts",
7
+ "content": "import type { ReactNode } from \"react\";\nimport { getComposerQuery } from \"@tc96/ui/lib/composer-query\";\n\ntype ComposerPart =\n | { type: \"text\"; text: string }\n | {\n type: \"mention\" | \"action\";\n id: string;\n label: string;\n trigger: string;\n kind?: string;\n data?: string;\n text?: string;\n };\n\ntype ComposerValue = readonly ComposerPart[];\ntype ComposerTokenPart = Exclude<ComposerPart, { type: \"text\" }>;\n\ntype ComposerItemValue = {\n id: string;\n label: string;\n disabled?: boolean;\n description?: string;\n icon?: ReactNode;\n type?: \"mention\" | \"action\";\n kind?: string;\n data?: string;\n text?: string;\n};\n\ntype ComposerTrigger = {\n character: string;\n items: readonly ComposerItemValue[];\n status?: \"ready\" | \"loading\" | \"error\";\n itemsFor?: string;\n queryKey?: string;\n showEmpty?: boolean;\n maxQueryLength?: number;\n filter?: ((item: ComposerItemValue, query: string) => boolean) | null;\n};\n\ntype ComposerQuery = { character: string; text: string; key: string };\n\nconst queryNodeIds = new WeakMap<Text, number>();\nlet nextQueryNodeId = 0;\n\ntype ActiveQuery = ComposerQuery & {\n node: Text;\n start: number;\n end: number;\n};\n\nfunction pushText(parts: ComposerPart[], text: string): void {\n if (!text) return;\n const previous = parts[parts.length - 1];\n if (previous?.type === \"text\") previous.text += text;\n else parts.push({ type: \"text\", text });\n}\n\nfunction readValue(\n root: HTMLElement,\n ignoreTrailingPlaceholder = true,\n): ComposerValue {\n if (root instanceof HTMLTextAreaElement) {\n return root.value ? [{ type: \"text\", text: root.value }] : [];\n }\n const parts: ComposerPart[] = [];\n function children(parent: HTMLElement): void {\n const nodes = Array.from(parent.childNodes);\n for (const [index, node] of nodes.entries()) {\n if (node instanceof Text) {\n pushText(parts, node.data);\n continue;\n }\n if (!(node instanceof HTMLElement)) continue;\n const tokenType = node.dataset.composerToken;\n if (tokenType === \"mention\" || tokenType === \"action\") {\n parts.push({\n type: tokenType,\n id: node.dataset.id ?? \"\",\n label: node.dataset.label ?? \"\",\n trigger: node.dataset.trigger ?? \"@\",\n ...(node.dataset.kind ? { kind: node.dataset.kind } : {}),\n ...(node.dataset.data !== undefined\n ? { data: node.dataset.data }\n : {}),\n ...(node.dataset.text !== undefined\n ? { text: node.dataset.text }\n : {}),\n });\n } else if (node.tagName === \"BR\") {\n if (node.hasAttribute(\"data-composer-placeholder\")) continue;\n // Browsers end empty lines with a placeholder BR, which is not another newline.\n if (!ignoreTrailingPlaceholder || index !== nodes.length - 1)\n pushText(parts, \"\\n\");\n } else {\n const isBlock = node.tagName === \"DIV\" || node.tagName === \"P\";\n if (\n isBlock &&\n index > 0 &&\n !(nodes[index - 1] instanceof HTMLBRElement)\n )\n pushText(parts, \"\\n\");\n children(node);\n if (isBlock && index < nodes.length - 1) {\n const next = nodes[index + 1];\n if (\n !(\n next instanceof HTMLElement &&\n (next.tagName === \"DIV\" || next.tagName === \"P\")\n )\n )\n pushText(parts, \"\\n\");\n }\n }\n }\n }\n children(root);\n return parts;\n}\n\nfunction normalizeValue(value: ComposerValue): ComposerValue {\n const parts: ComposerPart[] = [];\n for (const part of value) {\n if (part.type === \"text\") pushText(parts, part.text);\n else parts.push(part);\n }\n return parts;\n}\n\nfunction equalValue(left: ComposerValue, right: ComposerValue): boolean {\n const a = normalizeValue(left);\n const b = normalizeValue(right);\n return (\n a.length === b.length &&\n a.every((part, index) => {\n const other = b[index];\n if (part.type === \"text\")\n return other?.type === \"text\" && part.text === other.text;\n return (\n other?.type !== \"text\" &&\n other?.type === part.type &&\n other.id === part.id &&\n other.label === part.label &&\n other.trigger === part.trigger &&\n other.kind === part.kind &&\n other.data === part.data &&\n other.text === part.text\n );\n })\n );\n}\n\nfunction getComposerText(value: ComposerValue): string {\n return value\n .map((part) =>\n part.type === \"text\"\n ? part.text\n : (part.text ?? `${part.trigger}${part.label}`),\n )\n .join(\"\");\n}\n\nfunction createToken(part: ComposerTokenPart): HTMLSpanElement {\n const token = document.createElement(\"span\");\n token.dataset.composerToken = part.type;\n token.dataset.id = part.id;\n token.dataset.label = part.label;\n token.dataset.trigger = part.trigger;\n if (part.kind) token.dataset.kind = part.kind;\n if (part.data !== undefined) token.dataset.data = part.data;\n if (part.text !== undefined) token.dataset.text = part.text;\n token.contentEditable = \"false\";\n const fallback = document.createElement(\"span\");\n fallback.dataset.slot = \"composer-token-fallback\";\n fallback.textContent = part.text ?? `${part.trigger}${part.label}`;\n const renderer = document.createElement(\"span\");\n renderer.dataset.slot = \"composer-token-renderer\";\n token.append(fallback, renderer);\n return token;\n}\n\nfunction writeValue(root: HTMLElement, value: ComposerValue): void {\n if (root instanceof HTMLTextAreaElement) {\n root.value = getComposerText(value);\n return;\n }\n const fragment = document.createDocumentFragment();\n for (const part of value) {\n if (part.type !== \"text\") fragment.append(createToken(part));\n else if (part.text) fragment.append(document.createTextNode(part.text));\n }\n if (getComposerText(value).endsWith(\"\\n\")) {\n const placeholder = document.createElement(\"br\");\n placeholder.dataset.composerPlaceholder = \"\";\n fragment.append(placeholder);\n }\n root.replaceChildren(fragment);\n}\n\nfunction insertPlainText(root: HTMLElement, text: string): void {\n const selection = window.getSelection();\n if (\n !selection?.rangeCount ||\n !root.contains(selection.anchorNode) ||\n !root.contains(selection.focusNode)\n )\n return;\n const range = selection.getRangeAt(0);\n range.deleteContents();\n const node = document.createTextNode(text.replace(/\\r\\n?/g, \"\\n\"));\n range.insertNode(node);\n range.setStart(node, node.length);\n range.collapse(true);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\nfunction placeCaretAfterToken(\n root: HTMLElement,\n selection: Selection | null,\n): void {\n if (!selection?.rangeCount) return;\n const range = selection.getRangeAt(0);\n if (!range.collapsed) return;\n const anchor = selection.anchorNode;\n const token = (\n anchor instanceof Element ? anchor : anchor?.parentElement\n )?.closest(\"[data-composer-token]\");\n if (token && root.contains(token)) {\n const next = token.nextSibling;\n if (next instanceof Text && /^\\s/u.test(next.data)) {\n selection.collapse(next, 1);\n } else if (token.parentNode) {\n selection.collapse(\n token.parentNode,\n Array.from(token.parentNode.childNodes).indexOf(token) + 1,\n );\n }\n return;\n }\n const { startContainer, startOffset } = range;\n if (startContainer instanceof Text) {\n if (/^\\s/u.test(startContainer.data.slice(startOffset)))\n selection.collapse(startContainer, startOffset + 1);\n } else {\n const next = startContainer.childNodes[startOffset];\n if (next instanceof Text && /^\\s/u.test(next.data))\n selection.collapse(next, 1);\n }\n}\n\nfunction currentQuery(\n root: HTMLElement,\n triggers: readonly ComposerTrigger[],\n): ActiveQuery | null {\n const selection = window.getSelection();\n if (!selection?.isCollapsed || !root.contains(selection.anchorNode))\n return null;\n const node = selection.anchorNode;\n if (\n !(node instanceof Text) ||\n node.parentElement?.closest(\"[data-composer-token]\")\n )\n return null;\n let caret = selection.anchorOffset;\n let merged = false;\n // Paste and token deletion can leave one query split across adjacent text nodes.\n while (node.previousSibling instanceof Text) {\n const previous = node.previousSibling;\n caret += previous.length;\n node.insertData(0, previous.data);\n previous.remove();\n merged = true;\n }\n while (node.nextSibling instanceof Text) {\n const next = node.nextSibling;\n node.appendData(next.data);\n next.remove();\n merged = true;\n }\n if (merged) selection.collapse(node, caret);\n const query = getComposerQuery(\n node.data,\n caret,\n triggers.map((trigger) => trigger.character),\n );\n if (\n !query ||\n query.text.length >\n (triggers.find((trigger) => trigger.character === query.character)\n ?.maxQueryLength ?? Number.POSITIVE_INFINITY)\n )\n return null;\n if (\n query.start === 0 &&\n node.previousSibling?.textContent &&\n !/\\s$/u.test(node.previousSibling.textContent)\n )\n return null;\n if (!queryNodeIds.has(node)) queryNodeIds.set(node, ++nextQueryNodeId);\n return {\n ...query,\n node,\n key: `${queryNodeIds.get(node)}:${query.character}:${query.start}:${caret}:${query.text}`,\n };\n}\n\nfunction getFilteredItems(\n trigger: ComposerTrigger | undefined,\n query: ActiveQuery | null,\n defaultFilter: (text: string, query: string) => boolean,\n): readonly ComposerItemValue[] {\n if (\n !trigger ||\n !query ||\n (trigger.status && trigger.status !== \"ready\") ||\n (trigger.itemsFor !== undefined && trigger.itemsFor !== query.text) ||\n (trigger.queryKey !== undefined && trigger.queryKey !== query.key)\n )\n return [];\n if (trigger.filter === null) return trigger.items;\n return trigger.items.filter((item) =>\n trigger.filter\n ? trigger.filter(item, query.text)\n : defaultFilter(item.label, query.text),\n );\n}\n\nfunction hasVisibleItems(\n trigger: ComposerTrigger | undefined,\n options: readonly ComposerItemValue[],\n): boolean {\n return Boolean(\n trigger &&\n (options.length ||\n trigger.showEmpty ||\n trigger.status === \"loading\" ||\n trigger.status === \"error\"),\n );\n}\n\nfunction insertItem(\n input: HTMLDivElement,\n query: ActiveQuery,\n suggestion: ComposerItemValue,\n): void {\n const range = document.createRange();\n range.setStart(query.node, query.start);\n range.setEnd(query.node, query.end);\n const selection = window.getSelection();\n selection?.removeAllRanges();\n selection?.addRange(range);\n input.focus({ preventScroll: true });\n const token = createToken({\n type: suggestion.type ?? \"mention\",\n id: suggestion.id,\n label: suggestion.label,\n trigger: query.character,\n ...(suggestion.kind ? { kind: suggestion.kind } : {}),\n ...(suggestion.data !== undefined ? { data: suggestion.data } : {}),\n ...(suggestion.text !== undefined ? { text: suggestion.text } : {}),\n });\n const hasSeparator = /^\\s/u.test(query.node.data.slice(query.end));\n const trailingSpace = hasSeparator ? \"\" : \" \";\n range.deleteContents();\n const space = trailingSpace ? document.createTextNode(trailingSpace) : null;\n if (space) range.insertNode(space);\n range.insertNode(token);\n if (space) range.setStart(space, 1);\n else range.setStartAfter(token);\n range.collapse(true);\n selection?.removeAllRanges();\n selection?.addRange(range);\n placeCaretAfterToken(input, selection);\n input.focus({ preventScroll: true });\n}\n\ntype ComposerSelection = { anchor: number; focus: number };\n\n// Use canonical text offsets so chip labels and their icons do not move the caret.\nfunction readSelection(input: HTMLElement): ComposerSelection | null {\n if (input instanceof HTMLTextAreaElement) {\n return document.activeElement === input\n ? {\n anchor:\n input.selectionDirection === \"backward\"\n ? input.selectionEnd\n : input.selectionStart,\n focus:\n input.selectionDirection === \"backward\"\n ? input.selectionStart\n : input.selectionEnd,\n }\n : null;\n }\n const selection = window.getSelection();\n if (\n !selection?.anchorNode ||\n !selection.focusNode ||\n !input.contains(selection.anchorNode) ||\n !input.contains(selection.focusNode)\n )\n return null;\n function offset(node: Node, position: number): number {\n const range = document.createRange();\n range.selectNodeContents(input);\n range.setEnd(node, position);\n const fragment = document.createElement(\"div\");\n fragment.append(range.cloneContents());\n return getComposerText(readValue(fragment, false)).length;\n }\n return {\n anchor: offset(selection.anchorNode, selection.anchorOffset),\n focus: offset(selection.focusNode, selection.focusOffset),\n };\n}\n\nfunction restoreSelection(\n input: HTMLElement,\n selection: ComposerSelection | null,\n): void {\n if (!selection) return;\n if (input instanceof HTMLTextAreaElement) {\n input.setSelectionRange(\n Math.min(selection.anchor, selection.focus),\n Math.max(selection.anchor, selection.focus),\n selection.anchor > selection.focus ? \"backward\" : \"forward\",\n );\n return;\n }\n function point(offset: number): [Node, number] {\n let remaining = offset;\n for (const [index, node] of Array.from(input.childNodes).entries()) {\n const length =\n node instanceof HTMLElement && node.dataset.composerToken\n ? (\n node.dataset.text ??\n `${node.dataset.trigger ?? \"\"}${node.dataset.label ?? \"\"}`\n ).length\n : (node.textContent ?? \"\").length;\n if (remaining <= length) {\n if (node instanceof Text) return [node, remaining];\n return [input, index + (remaining > 0 ? 1 : 0)];\n }\n remaining -= length;\n }\n return [input, input.childNodes.length];\n }\n const [anchor, anchorOffset] = point(selection.anchor);\n const [focus, focusOffset] = point(selection.focus);\n window\n .getSelection()\n ?.setBaseAndExtent(anchor, anchorOffset, focus, focusOffset);\n}\n\ntype ComposerSnapshot = {\n value: ComposerValue;\n selection: ComposerSelection | null;\n};\n\nexport {\n type ActiveQuery,\n type ComposerItemValue,\n type ComposerPart,\n type ComposerQuery,\n type ComposerSelection,\n type ComposerSnapshot,\n type ComposerTokenPart,\n type ComposerTrigger,\n type ComposerValue,\n currentQuery,\n equalValue,\n getComposerText,\n getFilteredItems,\n hasVisibleItems,\n insertItem,\n insertPlainText,\n readSelection,\n readValue,\n restoreSelection,\n writeValue,\n};\n"
8
+ }
9
+ ],
10
+ "dependencies": [],
11
+ "registryDependencies": [
12
+ "@ui/composer-query"
13
+ ]
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "composer-editor",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/lib/composer-editor.ts",
7
+ "content": "\"use client\";\n\nimport { Popover as PopoverPrimitive } from \"@base-ui/react/popover\";\nimport type {\n ComponentProps,\n Context,\n KeyboardEvent,\n MouseEvent,\n ReactElement,\n ReactNode,\n RefObject,\n} from \"react\";\nimport {\n createContext,\n createElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n type ComposerEditorController,\n type ComposerItemValue,\n type ComposerQuery,\n type ComposerValue,\n type UseComposerEditorOptions,\n useComposerEditor,\n} from \"@tc96/ui/hooks/use-composer-editor\";\n\ntype ComposerEditorOptions = Omit<\n UseComposerEditorOptions,\n \"value\" | \"onValueChange\"\n> & {\n value?: ComposerValue;\n defaultValue?: ComposerValue;\n onValueChange?: UseComposerEditorOptions[\"onValueChange\"];\n name?: string;\n getSuggestionsAnnouncement?: (count: number) => string;\n};\n\ntype ComposerContextValue = ComposerEditorController & { reset: () => void };\nconst ComposerEditorContext: Context<ComposerContextValue | null> =\n createContext<ComposerContextValue | null>(null);\n\nfunction useComposerEditorContext(): ComposerContextValue | null {\n return useContext(ComposerEditorContext);\n}\n\nfunction useComposerContext(): Pick<\n ComposerContextValue,\n | \"value\"\n | \"isEmpty\"\n | \"canSubmit\"\n | \"disabled\"\n | \"readOnly\"\n | \"status\"\n | \"submit\"\n | \"insertTrigger\"\n | \"reset\"\n> {\n const context = useComposerEditorContext();\n if (!context)\n throw new Error(\"useComposerContext must be used within Composer.\");\n const {\n value,\n isEmpty,\n canSubmit,\n disabled,\n readOnly,\n status,\n submit,\n insertTrigger,\n reset,\n } = context;\n return {\n value,\n isEmpty,\n canSubmit,\n disabled,\n readOnly,\n status,\n submit,\n insertTrigger,\n reset,\n };\n}\n\nfunction useComposerAnchorContext():\n | RefObject<HTMLFormElement | null>\n | undefined {\n return useComposerEditorContext()?.rootRef;\n}\n\nconst emptyValue: ComposerValue = [];\n\nfunction ComposerEditorProvider({\n value: controlledValue,\n defaultValue = emptyValue,\n onValueChange,\n getSuggestionsAnnouncement,\n children,\n ...options\n}: ComposerEditorOptions & { children: ReactNode }): ReactElement {\n const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);\n const editor = useComposerEditor({\n ...options,\n value: controlledValue ?? uncontrolledValue,\n onValueChange: (nextValue, details) => {\n if (controlledValue === undefined) setUncontrolledValue(nextValue);\n onValueChange?.(nextValue, details);\n },\n });\n const reset = () => editor.reset(defaultValue);\n const resetRef = useRef(reset);\n resetRef.current = reset;\n useEffect(() => {\n const form = editor.rootRef.current?.closest(\"form\");\n if (!form) return;\n const onReset = (event: Event) => {\n queueMicrotask(() => {\n if (!event.defaultPrevented) resetRef.current();\n });\n };\n form.addEventListener(\"reset\", onReset);\n return () => form.removeEventListener(\"reset\", onReset);\n });\n\n return createElement(\n ComposerEditorContext.Provider,\n { value: { ...editor, reset } },\n createElement(\n ComposerSuggestions,\n { ...editor.suggestions, getSuggestionsAnnouncement },\n children,\n ),\n );\n}\n\ntype RegisteredItem = { element: HTMLElement; disabled: boolean };\ntype SuggestionsContextValue = {\n items: readonly ComposerItemValue[];\n listId: string;\n highlightedId: string | undefined;\n inputProps: ComponentProps<\"div\">;\n registerItem: (id: string, item: RegisteredItem | null) => void;\n registerList: (element: HTMLElement | null) => void;\n highlightItem: (value: ComposerItemValue) => void;\n selectItem: (value: ComposerItemValue) => void;\n};\nconst ComposerSuggestionsContext: Context<SuggestionsContextValue | null> =\n createContext<SuggestionsContextValue | null>(null);\nfunction useComposerSuggestionsContext(): SuggestionsContextValue | null {\n return useContext(ComposerSuggestionsContext);\n}\n\nfunction defaultAnnouncement(count: number): string {\n return `${count} suggestion${count === 1 ? \"\" : \"s\"} available. Use the up and down arrow keys to navigate.`;\n}\n\nfunction ComposerSuggestions({\n enabled,\n items,\n open,\n onOpenChange,\n onItemSelect,\n getSuggestionsAnnouncement = defaultAnnouncement,\n submitOnEmptySuggestions,\n children,\n}: {\n enabled: boolean;\n submitOnEmptySuggestions: boolean;\n items: readonly ComposerItemValue[];\n open: boolean;\n onOpenChange: (open: boolean) => void;\n onItemSelect: (item: ComposerItemValue) => void;\n getSuggestionsAnnouncement?: (count: number) => string;\n children?: ReactNode;\n}): ReactElement {\n const listId = useId();\n const [highlightedValue, setHighlightedValue] = useState<string>();\n const [registered, setRegistered] = useState<\n ReadonlyMap<string, RegisteredItem>\n >(() => new Map());\n const [listElement, registerList] = useState<HTMLElement | null>(null);\n const registerItem = useCallback(\n (id: string, item: RegisteredItem | null) => {\n setRegistered((previous) => {\n const next = new Map(previous);\n if (item) next.set(id, item);\n else next.delete(id);\n return next;\n });\n },\n [],\n );\n const enabledItems = items.filter(\n (item) =>\n !item.disabled &&\n registered.has(item.id) &&\n !registered.get(item.id)?.disabled,\n );\n const highlightedId =\n enabledItems.find((item) => item.id === highlightedValue)?.id ??\n enabledItems[0]?.id;\n\n function selectItem(value: ComposerItemValue): void {\n const item = enabledItems.find((item) => item.id === value.id);\n if (!open || !item) return;\n onItemSelect(item);\n onOpenChange(false);\n setHighlightedValue(undefined);\n }\n\n function onKeyDown(event: KeyboardEvent<HTMLDivElement>): void {\n if (\n !open ||\n event.defaultPrevented ||\n event.nativeEvent.isComposing ||\n event.nativeEvent.keyCode === 229\n )\n return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n onOpenChange(false);\n setHighlightedValue(undefined);\n } else if (\n event.key === \"Tab\" ||\n (event.key === \"Enter\" && event.shiftKey)\n ) {\n onOpenChange(false);\n } else if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n if (!enabledItems.length) return;\n const direction = event.key === \"ArrowDown\" ? 1 : -1;\n const index = enabledItems.findIndex((item) => item.id === highlightedId);\n const item =\n enabledItems[\n (index + direction + enabledItems.length) % enabledItems.length\n ];\n if (!item) return;\n setHighlightedValue(item.id);\n registered.get(item.id)?.element.scrollIntoView({ block: \"nearest\" });\n } else if (event.key === \"Enter\" && !event.shiftKey) {\n if (!enabledItems.length && submitOnEmptySuggestions) return;\n event.preventDefault();\n const item = enabledItems.find((item) => item.id === highlightedId);\n if (item) selectItem(item);\n }\n }\n\n return createElement(\n ComposerSuggestionsContext.Provider,\n {\n value: {\n items,\n listId,\n highlightedId,\n registerItem,\n registerList,\n inputProps: {\n \"aria-autocomplete\": enabled ? \"list\" : undefined,\n \"aria-haspopup\": enabled ? \"listbox\" : undefined,\n \"aria-controls\": open ? listElement?.id || undefined : undefined,\n \"aria-activedescendant\":\n open && listElement && highlightedId\n ? registered.get(highlightedId)?.element.id || undefined\n : undefined,\n onKeyDown,\n },\n highlightItem: (value) => setHighlightedValue(value.id),\n selectItem,\n },\n },\n createElement(\n PopoverPrimitive.Root,\n {\n open,\n onOpenChange: (nextOpen: boolean) => {\n if (!nextOpen) setHighlightedValue(undefined);\n onOpenChange(nextOpen);\n },\n },\n children,\n createElement(\n \"span\",\n {\n role: \"status\",\n \"aria-atomic\": true,\n style: {\n position: \"absolute\",\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n whiteSpace: \"nowrap\",\n },\n },\n open && listElement && enabledItems.length\n ? getSuggestionsAnnouncement(enabledItems.length)\n : \"\",\n ),\n ),\n );\n}\n\nfunction useComposerItem(\n value: ComposerItemValue | undefined,\n disabled: boolean,\n) {\n const suggestions = useComposerSuggestionsContext();\n const registerItem = suggestions?.registerItem;\n const id = value?.id;\n const ref = useCallback(\n (element: HTMLElement | null) => {\n if (id !== undefined)\n registerItem?.(id, element ? { element, disabled } : null);\n },\n [id, disabled, registerItem],\n );\n const highlighted = id !== undefined && id === suggestions?.highlightedId;\n return {\n ref,\n highlighted,\n props: {\n id:\n id !== undefined && suggestions\n ? `${suggestions.listId}-${encodeURIComponent(id)}`\n : undefined,\n role: suggestions ? \"option\" : undefined,\n tabIndex: suggestions ? -1 : undefined,\n \"aria-selected\": suggestions ? highlighted : undefined,\n \"aria-disabled\": disabled || undefined,\n \"data-highlighted\": highlighted ? \"\" : undefined,\n \"data-disabled\": disabled ? \"\" : undefined,\n onPointerMove: () => {\n if (!disabled && value) suggestions?.highlightItem(value);\n },\n onClick: () => {\n if (!disabled && value) suggestions?.selectItem(value);\n },\n onMouseDown: (event: MouseEvent<HTMLButtonElement>) => {\n if (suggestions) event.preventDefault();\n },\n },\n };\n}\n\nfunction focusComposerInput(\n event: MouseEvent<HTMLFormElement>,\n preventDefault: boolean,\n): void {\n if (event.defaultPrevented || !(event.target instanceof Element)) return;\n const interactive = event.target.closest(\n \"button, a, input, select, textarea, label, summary, [data-slot='composer-input'], [contenteditable], [role='button'], [role='combobox'], [role='menuitem'], [tabindex]:not([tabindex='-1'])\",\n );\n if (\n interactive &&\n interactive !== event.currentTarget &&\n event.currentTarget.contains(interactive)\n )\n return;\n const input = event.currentTarget.querySelector<HTMLElement>(\n '[data-slot=\"composer-input\"]',\n );\n if (!input || input.matches(\":disabled, [aria-disabled='true']\")) return;\n if (preventDefault) event.preventDefault();\n input.focus();\n}\n\nfunction useComposerInputLayout() {\n const editor = useComposerEditorContext();\n const scrollRef = useRef<HTMLDivElement>(null);\n const [input, setInput] = useState<HTMLElement | null>(null);\n const scheduleMeasureRef = useRef<(() => void) | null>(null);\n useLayoutEffect(() => {\n for (const host of editor?.tokenHosts ?? []) {\n const fallback = host.previousElementSibling;\n if (fallback instanceof HTMLElement) fallback.hidden = true;\n }\n }, [editor?.tokenHosts]);\n useLayoutEffect(() => {\n const scroll = scrollRef.current;\n if (!scroll || !input) return;\n const frame = scroll.closest<HTMLElement>('[data-slot=\"composer\"]');\n const controls = new Set<HTMLElement>();\n let animationFrame: number | null = null;\n\n function scheduleMeasure(): void {\n if (animationFrame !== null) return;\n animationFrame = requestAnimationFrame(() => {\n animationFrame = null;\n measure();\n });\n }\n\n const observer = new ResizeObserver(scheduleMeasure);\n\n function measure(): void {\n if (!scroll || !input) return;\n // Observe the groups themselves: their wrapper has no box in compact mode.\n // Reconcile here so conditional controls don't require a new observer.\n const nextControls = new Set(\n frame?.querySelectorAll<HTMLElement>(\n ':scope > [data-slot=\"composer-actions\"] > [data-slot=\"composer-action-group\"]',\n ),\n );\n for (const control of controls) {\n if (!nextControls.has(control)) {\n observer.unobserve(control);\n controls.delete(control);\n }\n }\n for (const control of nextControls) {\n if (!controls.has(control)) {\n observer.observe(control);\n controls.add(control);\n }\n }\n const style = getComputedStyle(input);\n const lineHeight =\n Number.parseFloat(style.lineHeight) ||\n Number.parseFloat(style.fontSize) * 1.2;\n const padding =\n Number.parseFloat(style.paddingTop) +\n Number.parseFloat(style.paddingBottom);\n for (const [property, value] of [\n [\"--composer-line-height\", `${lineHeight}px`],\n [\"--composer-input-padding\", `${padding}px`],\n ] as const) {\n if (scroll.style.getPropertyValue(property) !== value) {\n scroll.style.setProperty(property, value);\n }\n }\n if (!frame || frame.dataset.layout !== \"adaptive\" || !controls.size) {\n frame?.removeAttribute(\"data-multiline\");\n return;\n }\n const minRows = Number.parseFloat(\n style.getPropertyValue(\"--composer-min-rows\"),\n );\n if (minRows > 1) {\n frame.toggleAttribute(\"data-multiline\", true);\n return;\n }\n\n // Measure at the narrow, one-line width even after the actions move below.\n // This keeps the layout from oscillating when full-width text fits one line.\n frame.removeAttribute(\"data-multiline\");\n const minHeight = input.style.getPropertyValue(\"min-height\");\n const minHeightPriority = input.style.getPropertyPriority(\"min-height\");\n input.style.setProperty(\"min-height\", \"0px\", \"important\");\n const contentHeight = input.scrollHeight;\n if (minHeight) {\n input.style.setProperty(\"min-height\", minHeight, minHeightPriority);\n } else {\n input.style.removeProperty(\"min-height\");\n }\n frame.toggleAttribute(\n \"data-multiline\",\n contentHeight > lineHeight * 1.5 + padding,\n );\n }\n scheduleMeasureRef.current = scheduleMeasure;\n measure();\n observer.observe(input);\n if (frame) observer.observe(frame);\n input.addEventListener(\"input\", scheduleMeasure);\n window.addEventListener(\"resize\", scheduleMeasure);\n document.fonts.addEventListener(\"loadingdone\", scheduleMeasure);\n return () => {\n scheduleMeasureRef.current = null;\n if (animationFrame !== null) cancelAnimationFrame(animationFrame);\n observer.disconnect();\n input.removeEventListener(\"input\", scheduleMeasure);\n window.removeEventListener(\"resize\", scheduleMeasure);\n document.fonts.removeEventListener(\"loadingdone\", scheduleMeasure);\n };\n }, [input]);\n // Controlled drafts, layout props, and conditional actions can change without\n // an input event. Coalesce these commits with input and resize notifications.\n useLayoutEffect(() => {\n scheduleMeasureRef.current?.();\n });\n return { scrollRef, inputRef: setInput };\n}\n\nexport {\n type ComposerChangeDetails,\n type ComposerItemValue,\n type ComposerPart,\n type ComposerQuery,\n type ComposerTokenPart,\n type ComposerTrigger,\n type ComposerValue,\n getComposerText,\n useComposerFilter,\n} from \"@tc96/ui/hooks/use-composer-editor\";\nexport type { ComposerEditorOptions };\nexport {\n ComposerEditorProvider,\n focusComposerInput,\n useComposerAnchorContext,\n useComposerContext,\n useComposerEditorContext,\n useComposerInputLayout,\n useComposerItem,\n useComposerSuggestionsContext,\n};\n"
8
+ }
9
+ ],
10
+ "dependencies": [
11
+ "@base-ui/react@1.8.0"
12
+ ],
13
+ "registryDependencies": [
14
+ "@ui/use-composer-editor"
15
+ ]
16
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "composer-query",
3
+ "type": "registry:ui",
4
+ "files": [
5
+ {
6
+ "path": "registry/default/ui/lib/composer-query.ts",
7
+ "content": "export function getComposerQuery(\n text: string,\n caret: number,\n triggers: readonly string[],\n): { character: string; text: string; start: number; end: number } | null {\n let start = -1;\n let character = \"\";\n for (const trigger of triggers) {\n if (!trigger || trigger.length > caret) continue;\n const index = text.lastIndexOf(trigger, caret - trigger.length);\n if (index > start) {\n start = index;\n character = trigger;\n }\n }\n if (start < 0 || (start > 0 && !/\\s/u.test(text.charAt(start - 1))))\n return null;\n\n const beforeCaret = text.slice(start + character.length, caret);\n if (/^\\s/u.test(beforeCaret)) return null;\n if (!/^[\\p{L}\\p{M}\\p{N}\\p{Zs}_.’'-]*$/u.test(beforeCaret)) return null;\n\n // Complete the word at the caret without consuming subsequent prose.\n const suffix = /^[\\p{L}\\p{M}\\p{N}_.’'-]*/u.exec(text.slice(caret))?.[0] ?? \"\";\n return {\n character,\n text: (beforeCaret + suffix).replace(/\\p{Zs}+/gu, \" \").trim(),\n start,\n end: caret + suffix.length,\n };\n}\n"
8
+ }
9
+ ],
10
+ "dependencies": [],
11
+ "registryDependencies": []
12
+ }