@dashx/react 0.1.5 → 0.1.7

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 (155) hide show
  1. package/dist/cjs/components/avatar.d.ts +5 -0
  2. package/dist/cjs/components/avatar.js +2 -0
  3. package/dist/cjs/components/avatar.js.map +7 -0
  4. package/dist/cjs/components/flex.d.ts +70 -0
  5. package/dist/cjs/components/flex.js +1 -1
  6. package/dist/cjs/components/flex.js.map +3 -3
  7. package/dist/cjs/components/index.d.ts +1 -0
  8. package/dist/cjs/components/index.js +1 -1
  9. package/dist/cjs/components/index.js.map +2 -2
  10. package/dist/cjs/components/markdown-renderer.d.ts +8 -0
  11. package/dist/cjs/components/markdown-renderer.js +2 -0
  12. package/dist/cjs/components/markdown-renderer.js.map +7 -0
  13. package/dist/cjs/components/popover copy.d.ts +47 -0
  14. package/dist/cjs/components/text-area.d.ts +1 -0
  15. package/dist/cjs/components/text-area.js +1 -1
  16. package/dist/cjs/components/text-area.js.map +3 -3
  17. package/dist/cjs/hooks/index.d.ts +2 -0
  18. package/dist/cjs/hooks/index.js +1 -1
  19. package/dist/cjs/hooks/index.js.map +3 -3
  20. package/dist/cjs/hooks/use-agent.d.ts +15 -0
  21. package/dist/cjs/hooks/use-agent.js +2 -0
  22. package/dist/cjs/hooks/use-agent.js.map +7 -0
  23. package/dist/cjs/hooks/use-animated-text.d.ts +11 -0
  24. package/dist/cjs/hooks/use-animated-text.js +2 -0
  25. package/dist/cjs/hooks/use-animated-text.js.map +7 -0
  26. package/dist/cjs/hooks/use-auto-scroll.d.ts +13 -0
  27. package/dist/cjs/hooks/use-auto-scroll.js +2 -0
  28. package/dist/cjs/hooks/use-auto-scroll.js.map +7 -0
  29. package/dist/cjs/index.d.ts +2 -0
  30. package/dist/cjs/index.js +1 -1
  31. package/dist/cjs/index.js.map +2 -2
  32. package/dist/cjs/legacy.d.ts +2 -0
  33. package/dist/cjs/legacy.js +2 -0
  34. package/dist/cjs/legacy.js.map +7 -0
  35. package/dist/cjs/providers/DashXProvider.d.ts +2 -1
  36. package/dist/cjs/providers/DashXProvider.js +1 -1
  37. package/dist/cjs/providers/DashXProvider.js.map +2 -2
  38. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  39. package/dist/cjs/variants/avatar.d.ts +212 -0
  40. package/dist/cjs/variants/avatar.js +2 -0
  41. package/dist/cjs/variants/avatar.js.map +7 -0
  42. package/dist/cjs/variants/base-input.d.ts +1 -1
  43. package/dist/cjs/variants/base-input.js +1 -1
  44. package/dist/cjs/variants/base-input.js.map +2 -2
  45. package/dist/cjs/variants/button copy.d.ts +254 -0
  46. package/dist/cjs/variants/checkbox.d.ts +1 -1
  47. package/dist/cjs/widgets/Chat.d.ts +15 -0
  48. package/dist/cjs/widgets/Chat.js +2 -0
  49. package/dist/cjs/widgets/Chat.js.map +7 -0
  50. package/dist/cjs/widgets/ChatBody.d.ts +14 -0
  51. package/dist/cjs/widgets/ChatBody.js +2 -0
  52. package/dist/cjs/widgets/ChatBody.js.map +7 -0
  53. package/dist/cjs/widgets/ChatFooter.d.ts +7 -0
  54. package/dist/cjs/widgets/ChatFooter.js +2 -0
  55. package/dist/cjs/widgets/ChatFooter.js.map +7 -0
  56. package/dist/cjs/widgets/ChatHeader.d.ts +9 -0
  57. package/dist/cjs/widgets/ChatHeader.js +2 -0
  58. package/dist/cjs/widgets/ChatHeader.js.map +7 -0
  59. package/dist/cjs/widgets/ChatPopover.d.ts +3 -0
  60. package/dist/cjs/widgets/ChatPopover.js +2 -0
  61. package/dist/cjs/widgets/ChatPopover.js.map +7 -0
  62. package/dist/cjs/widgets/NotificationBell.js +1 -1
  63. package/dist/cjs/widgets/NotificationBell.js.map +2 -2
  64. package/dist/cjs/widgets/index.d.ts +2 -0
  65. package/dist/cjs/widgets/index.js +1 -1
  66. package/dist/cjs/widgets/index.js.map +3 -3
  67. package/dist/esm/components/avatar.d.ts +5 -0
  68. package/dist/esm/components/avatar.js +2 -0
  69. package/dist/esm/components/avatar.js.map +7 -0
  70. package/dist/esm/components/flex.d.ts +70 -0
  71. package/dist/esm/components/flex.js +1 -1
  72. package/dist/esm/components/flex.js.map +3 -3
  73. package/dist/esm/components/index.d.ts +1 -0
  74. package/dist/esm/components/index.js +1 -1
  75. package/dist/esm/components/index.js.map +2 -2
  76. package/dist/esm/components/markdown-renderer.d.ts +8 -0
  77. package/dist/esm/components/markdown-renderer.js +2 -0
  78. package/dist/esm/components/markdown-renderer.js.map +7 -0
  79. package/dist/esm/components/popover copy.d.ts +47 -0
  80. package/dist/esm/components/text-area.d.ts +1 -0
  81. package/dist/esm/components/text-area.js +1 -1
  82. package/dist/esm/components/text-area.js.map +3 -3
  83. package/dist/esm/hooks/index.d.ts +2 -0
  84. package/dist/esm/hooks/index.js +1 -1
  85. package/dist/esm/hooks/index.js.map +3 -3
  86. package/dist/esm/hooks/use-agent.d.ts +15 -0
  87. package/dist/esm/hooks/use-agent.js +2 -0
  88. package/dist/esm/hooks/use-agent.js.map +7 -0
  89. package/dist/esm/hooks/use-animated-text.d.ts +11 -0
  90. package/dist/esm/hooks/use-animated-text.js +2 -0
  91. package/dist/esm/hooks/use-animated-text.js.map +7 -0
  92. package/dist/esm/hooks/use-auto-scroll.d.ts +13 -0
  93. package/dist/esm/hooks/use-auto-scroll.js +2 -0
  94. package/dist/esm/hooks/use-auto-scroll.js.map +7 -0
  95. package/dist/esm/index.d.ts +2 -0
  96. package/dist/esm/index.js +1 -1
  97. package/dist/esm/index.js.map +2 -2
  98. package/dist/esm/legacy.d.ts +2 -0
  99. package/dist/esm/legacy.js +2 -0
  100. package/dist/esm/legacy.js.map +7 -0
  101. package/dist/esm/providers/DashXProvider.d.ts +2 -1
  102. package/dist/esm/providers/DashXProvider.js +1 -1
  103. package/dist/esm/providers/DashXProvider.js.map +2 -2
  104. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  105. package/dist/esm/variants/avatar.d.ts +212 -0
  106. package/dist/esm/variants/avatar.js +2 -0
  107. package/dist/esm/variants/avatar.js.map +7 -0
  108. package/dist/esm/variants/base-input.d.ts +1 -1
  109. package/dist/esm/variants/base-input.js +1 -1
  110. package/dist/esm/variants/base-input.js.map +2 -2
  111. package/dist/esm/variants/button copy.d.ts +254 -0
  112. package/dist/esm/variants/checkbox.d.ts +1 -1
  113. package/dist/esm/widgets/Chat.d.ts +15 -0
  114. package/dist/esm/widgets/Chat.js +2 -0
  115. package/dist/esm/widgets/Chat.js.map +7 -0
  116. package/dist/esm/widgets/ChatBody.d.ts +14 -0
  117. package/dist/esm/widgets/ChatBody.js +2 -0
  118. package/dist/esm/widgets/ChatBody.js.map +7 -0
  119. package/dist/esm/widgets/ChatFooter.d.ts +7 -0
  120. package/dist/esm/widgets/ChatFooter.js +2 -0
  121. package/dist/esm/widgets/ChatFooter.js.map +7 -0
  122. package/dist/esm/widgets/ChatHeader.d.ts +9 -0
  123. package/dist/esm/widgets/ChatHeader.js +2 -0
  124. package/dist/esm/widgets/ChatHeader.js.map +7 -0
  125. package/dist/esm/widgets/ChatPopover.d.ts +3 -0
  126. package/dist/esm/widgets/ChatPopover.js +2 -0
  127. package/dist/esm/widgets/ChatPopover.js.map +7 -0
  128. package/dist/esm/widgets/NotificationBell.js +1 -1
  129. package/dist/esm/widgets/NotificationBell.js.map +2 -2
  130. package/dist/esm/widgets/index.d.ts +2 -0
  131. package/dist/esm/widgets/index.js +1 -1
  132. package/dist/esm/widgets/index.js.map +2 -2
  133. package/package.json +5 -3
  134. package/src/components/avatar.tsx +32 -0
  135. package/src/components/flex.tsx +7 -2
  136. package/src/components/index.ts +1 -0
  137. package/src/components/markdown-renderer.tsx +57 -0
  138. package/src/components/text-area.tsx +23 -11
  139. package/src/hooks/index.ts +2 -0
  140. package/src/hooks/use-agent.ts +89 -0
  141. package/src/hooks/use-animated-text.ts +67 -0
  142. package/src/hooks/use-auto-scroll.ts +65 -0
  143. package/src/index.ts +2 -1
  144. package/src/legacy.ts +2 -0
  145. package/src/providers/DashXProvider.tsx +4 -3
  146. package/src/variants/avatar.ts +31 -0
  147. package/src/variants/base-input.ts +1 -1
  148. package/src/widgets/Chat.tsx +96 -0
  149. package/src/widgets/ChatBody.tsx +171 -0
  150. package/src/widgets/ChatFooter.tsx +62 -0
  151. package/src/widgets/ChatHeader.tsx +26 -0
  152. package/src/widgets/ChatPopover.tsx +42 -0
  153. package/src/widgets/NotificationBell.tsx +1 -1
  154. package/src/widgets/index.ts +2 -0
  155. package/styles.css +122 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/widgets/ChatHeader.tsx"],
4
+ "sourcesContent": ["import React from 'react';\nimport type { AiAgent } from '@dashx/browser';\n\nimport { Flex, Heading } from '../components';\n\ntype ChatHeaderProps = {\n agent: AiAgent;\n children?: React.ReactNode;\n};\n\nconst ChatHeader = ({ agent, children }: ChatHeaderProps) => {\n return (\n <Flex\n align=\"center\"\n className=\"border-b border-b-gray-400/40 px-6 py-4\"\n justify=\"between\"\n >\n <Heading size={3}>{agent.name}</Heading>\n {children}\n </Flex>\n );\n};\n\nexport type { ChatHeaderProps }\n\nexport default ChatHeader;\n"],
5
+ "mappings": "AAYI,OAKE,OAAAA,EALF,QAAAC,MAAA,oBAZJ,MAAkB,QAGlB,OAAS,QAAAC,EAAM,WAAAC,MAAe,gBAO9B,MAAMC,EAAa,CAAC,CAAE,MAAAC,EAAO,SAAAC,CAAS,IAElCL,EAACC,EAAA,CACC,MAAM,SACN,UAAU,0CACV,QAAQ,UAER,UAAAF,EAACG,EAAA,CAAQ,KAAM,EAAI,SAAAE,EAAM,KAAK,EAC7BC,GACH,EAMJ,IAAOC,EAAQH",
6
+ "names": ["jsx", "jsxs", "Flex", "Heading", "ChatHeader", "agent", "children", "ChatHeader_default"]
7
+ }
@@ -0,0 +1,3 @@
1
+ import { type ChatWrapperProps } from './Chat.js';
2
+ declare const ChatPopup: ({ publicEmbedKey, ...props }: ChatWrapperProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default ChatPopup;
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as T}from"react/jsx-runtime";import{useState as l}from"react";import{Chat as v}from"./Chat.js";import{Button as P,Flex as d,Popover as o,Theme as f}from"../components";import{BotMessageSquareIcon as u}from"../icons/index.js";import C from"../hooks/use-agent.js";const c=({publicEmbedKey:r,...t})=>{const{agent:s,messages:n,isThinking:a,error:p,sendMessage:i,conversationId:g}=C({publicEmbedKey:r}),[h,m]=l(!1);return e(f,{children:e(d,{className:"fixed right-4 bottom-4 z-50",children:T(o.Root,{onOpenChange:m,children:[e(o.Trigger,{children:e(P,{shape:"square",roundness:"full",variant:"fill",size:"large",children:e(u,{})})}),e(o.Content,{spacing:"large",width:"350px",height:"450px",children:e(v,{agent:s,conversationId:g,messages:n,isThinking:a,error:p,sendMessage:i,borderless:!0,withChatHeader:!0,withPopoverClose:!0,isPopoverOpen:h,...t})})]})})})};var R=c;export{R as default};
2
+ //# sourceMappingURL=ChatPopover.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/widgets/ChatPopover.tsx"],
4
+ "sourcesContent": ["import React, { useState } from 'react';\n\nimport { Chat, type ChatWrapperProps } from './Chat.js';\nimport { Button, Flex, Popover, Theme } from '../components';\nimport { BotMessageSquareIcon } from '../icons/index.js';\nimport useAgent from '../hooks/use-agent.js';\n\nconst ChatPopup = ({ publicEmbedKey, ...props }: ChatWrapperProps) => {\n const { agent, messages, isThinking, error, sendMessage, conversationId } = useAgent({ publicEmbedKey });\n const [isPopoverOpen, setIsPopoverOpen] = useState(false);\n\n return (\n <Theme>\n <Flex className=\"fixed right-4 bottom-4 z-50\">\n <Popover.Root onOpenChange={setIsPopoverOpen}>\n <Popover.Trigger>\n <Button shape=\"square\" roundness=\"full\" variant=\"fill\" size=\"large\">\n <BotMessageSquareIcon />\n </Button>\n </Popover.Trigger>\n <Popover.Content spacing=\"large\" width=\"350px\" height=\"450px\">\n <Chat\n agent={agent}\n conversationId={conversationId}\n messages={messages}\n isThinking={isThinking}\n error={error}\n sendMessage={sendMessage}\n borderless\n withChatHeader\n withPopoverClose\n isPopoverOpen={isPopoverOpen}\n {...props}\n />\n </Popover.Content>\n </Popover.Root>\n </Flex>\n </Theme>\n );\n};\n\nexport default ChatPopup;\n"],
5
+ "mappings": "AAcQ,OAGM,OAAAA,EAHN,QAAAC,MAAA,oBAdR,OAAgB,YAAAC,MAAgB,QAEhC,OAAS,QAAAC,MAAmC,YAC5C,OAAS,UAAAC,EAAQ,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,gBAC7C,OAAS,wBAAAC,MAA4B,oBACrC,OAAOC,MAAc,wBAErB,MAAMC,EAAY,CAAC,CAAE,eAAAC,EAAgB,GAAGC,CAAM,IAAwB,CACpE,KAAM,CAAE,MAAAC,EAAO,SAAAC,EAAU,WAAAC,EAAY,MAAAC,EAAO,YAAAC,EAAa,eAAAC,CAAe,EAAIT,EAAS,CAAE,eAAAE,CAAe,CAAC,EACjG,CAACQ,EAAeC,CAAgB,EAAIlB,EAAS,EAAK,EAExD,OACEF,EAACO,EAAA,CACC,SAAAP,EAACK,EAAA,CAAK,UAAU,8BACd,SAAAJ,EAACK,EAAQ,KAAR,CAAa,aAAcc,EAC1B,UAAApB,EAACM,EAAQ,QAAR,CACC,SAAAN,EAACI,EAAA,CAAO,MAAM,SAAS,UAAU,OAAO,QAAQ,OAAO,KAAK,QAC1D,SAAAJ,EAACQ,EAAA,EAAqB,EACxB,EACF,EACAR,EAACM,EAAQ,QAAR,CAAgB,QAAQ,QAAQ,MAAM,QAAQ,OAAO,QACpD,SAAAN,EAACG,EAAA,CACC,MAAOU,EACP,eAAgBK,EAChB,SAAUJ,EACV,WAAYC,EACZ,MAAOC,EACP,YAAaC,EACb,WAAU,GACV,eAAc,GACd,iBAAgB,GAChB,cAAeE,EACd,GAAGP,EACN,EACF,GACF,EACF,EACF,CAEJ,EAEA,IAAOS,EAAQX",
6
+ "names": ["jsx", "jsxs", "useState", "Chat", "Button", "Flex", "Popover", "Theme", "BotMessageSquareIcon", "useAgent", "ChatPopup", "publicEmbedKey", "props", "agent", "messages", "isThinking", "error", "sendMessage", "conversationId", "isPopoverOpen", "setIsPopoverOpen", "ChatPopover_default"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{intlFormatDistance as u}from"date-fns";import{useInApp as c}from"../hooks/index.js";import{Button as s,Card as m,Flex as i,Heading as T,Popover as r,Text as n,Theme as h,Tooltip as a}from"../components";import{Inbox as v,Mail as x,MailOpen as f,X as y}from"../icons/index.js";const C=()=>{let{markNotificationAsRead:d,markNotificationAsUnread:p,notifications:l,unreadNotificationsCount:g}=c();return e(h,{children:o(r.Root,{children:[o(a.Root,{children:[e(a.Trigger,{children:e(r.Trigger,{children:e(s,{shape:"square",roundness:"full",variant:g?"fill":"ghost",children:e(v,{})})})}),e(a.Content,{content:"Notification"})]}),o(r.Content,{spacing:"large",width:"350px",height:"450px",children:[e(r.Header,{asChild:!0,children:o(i,{justify:"between",align:"center",children:[e(T,{size:3,children:"Notifications"}),e(r.Close,{children:e(s,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:e(y,{})})})]})}),e(r.Body,{children:o(i,{direction:"column",gap:1,children:[l.length<0&&e(i,{justify:"center",align:"center",children:e(n,{variant:"tertiary",size:2,children:"No notifications yet."})}),l.map(t=>e(m,{children:o(i,{align:"center",gap:4,justify:"between",children:[o(i,{direction:"column",gap:1,children:[e(n,{as:"p",variant:"secondary",weight:"semibold",size:2,children:t.renderedContent.body}),e(n,{size:1,variant:"tertiary",children:u(t.sentAt,new Date)})]}),o(a.Root,{children:[e(a.Trigger,{children:e(s,{shape:"square",variant:"ghost",roundness:"full",mode:t.readAt?"subtle":"distinct",onPress:()=>{t.readAt?p(t.id):d(t.id)},children:t.readAt?e(f,{}):e(x,{})})}),e(a.Content,{content:t.readAt?"Mark as unread":"Mark as read"})]})]})},t.id))]})}),e(r.Footer,{asChild:!0,children:e(n,{as:"p",align:"center",color:"accent",variant:"tertiary",size:1,children:"Powered by DashX"})})]})]})})};var B=C;export{B as default};
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{intlFormatDistance as u}from"date-fns";import{useInApp as c}from"../hooks/index.js";import{Button as s,Card as m,Flex as i,Heading as T,Popover as r,Text as n,Theme as h,Tooltip as a}from"../components";import{Inbox as v,Mail as x,MailOpen as f,X as y}from"../icons/index.js";const C=()=>{let{markNotificationAsRead:d,markNotificationAsUnread:p,notifications:l,unreadNotificationsCount:g}=c();return e(h,{children:o(r.Root,{children:[o(a.Root,{children:[e(a.Trigger,{children:e(r.Trigger,{children:e(s,{shape:"square",roundness:"full",variant:g?"fill":"ghost",children:e(v,{})})})}),e(a.Content,{content:"Notification"})]}),o(r.Content,{spacing:"large",width:"350px",height:"450px",children:[e(r.Header,{asChild:!0,children:o(i,{justify:"between",align:"center",children:[e(T,{size:3,children:"Notifications"}),e(r.Close,{children:e(s,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:e(y,{})})})]})}),e(r.Body,{children:o(i,{direction:"column",gap:1,children:[l.length===0&&e(i,{justify:"center",align:"center",children:e(n,{variant:"tertiary",size:2,children:"No notifications yet."})}),l.map(t=>e(m,{children:o(i,{align:"center",gap:4,justify:"between",children:[o(i,{direction:"column",gap:1,children:[e(n,{as:"p",variant:"secondary",weight:"semibold",size:2,children:t.renderedContent.body}),e(n,{size:1,variant:"tertiary",children:u(t.sentAt,new Date)})]}),o(a.Root,{children:[e(a.Trigger,{children:e(s,{shape:"square",variant:"ghost",roundness:"full",mode:t.readAt?"subtle":"distinct",onPress:()=>{t.readAt?p(t.id):d(t.id)},children:t.readAt?e(f,{}):e(x,{})})}),e(a.Content,{content:t.readAt?"Mark as unread":"Mark as read"})]})]})},t.id))]})}),e(r.Footer,{asChild:!0,children:e(n,{as:"p",align:"center",color:"accent",variant:"tertiary",size:1,children:"Powered by DashX"})})]})]})})};var B=C;export{B as default};
2
2
  //# sourceMappingURL=NotificationBell.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/widgets/NotificationBell.tsx"],
4
- "sourcesContent": ["import { intlFormatDistance } from 'date-fns';\n\nimport { useInApp } from '../hooks/index.js';\nimport { Button, Card, Flex, Heading, Popover, Text, Theme, Tooltip } from '../components';\nimport { Inbox, Mail, MailOpen, X } from '../icons/index.js';\n\nconst NotificationBell = () => {\n let {\n markNotificationAsRead,\n markNotificationAsUnread,\n notifications,\n unreadNotificationsCount,\n } = useInApp();\n\n return (\n <Theme>\n <Popover.Root>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Popover.Trigger>\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant={unreadNotificationsCount ? 'fill' : 'ghost'}\n >\n <Inbox />\n </Button>\n </Popover.Trigger>\n </Tooltip.Trigger>\n <Tooltip.Content content=\"Notification\" />\n </Tooltip.Root>\n <Popover.Content spacing=\"large\" width=\"350px\" height=\"450px\">\n <Popover.Header asChild>\n <Flex justify=\"between\" align=\"center\">\n <Heading size={3}>Notifications</Heading>\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n </Flex>\n </Popover.Header>\n <Popover.Body>\n <Flex direction=\"column\" gap={1}>\n {notifications.length < 0 && (\n <Flex justify=\"center\" align=\"center\">\n <Text variant=\"tertiary\" size={2}>\n No notifications yet.\n </Text>\n </Flex>\n )}\n {notifications.map((notification) => (\n <Card key={notification.id}>\n <Flex align=\"center\" gap={4} justify=\"between\">\n <Flex direction=\"column\" gap={1}>\n <Text as=\"p\" variant=\"secondary\" weight=\"semibold\" size={2}>\n {notification.renderedContent.body}\n </Text>\n <Text size={1} variant=\"tertiary\">\n {intlFormatDistance(notification.sentAt, new Date())}\n </Text>\n </Flex>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Button\n shape=\"square\"\n variant=\"ghost\"\n roundness=\"full\"\n mode={notification.readAt ? 'subtle' : 'distinct'}\n onPress={() => {\n if (notification.readAt) {\n markNotificationAsUnread(notification.id);\n } else {\n markNotificationAsRead(notification.id);\n }\n }}\n >\n {notification.readAt ? <MailOpen /> : <Mail />}\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Content\n content={notification.readAt ? 'Mark as unread' : 'Mark as read'}\n />\n </Tooltip.Root>\n </Flex>\n </Card>\n ))}\n </Flex>\n </Popover.Body>\n <Popover.Footer asChild>\n <Text as=\"p\" align=\"center\" color=\"accent\" variant=\"tertiary\" size={1}>\n Powered by DashX\n </Text>\n </Popover.Footer>\n </Popover.Content>\n </Popover.Root>\n </Theme>\n );\n};\n\nexport default NotificationBell;\n"],
5
- "mappings": "AAiBQ,OAQQ,OAAAA,EARR,QAAAC,MAAA,oBAjBR,OAAS,sBAAAC,MAA0B,WAEnC,OAAS,YAAAC,MAAgB,oBACzB,OAAS,UAAAC,EAAQ,QAAAC,EAAM,QAAAC,EAAM,WAAAC,EAAS,WAAAC,EAAS,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,gBAC3E,OAAS,SAAAC,EAAO,QAAAC,EAAM,YAAAC,EAAU,KAAAC,MAAS,oBAEzC,MAAMC,EAAmB,IAAM,CAC7B,GAAI,CACF,uBAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,yBAAAC,CACF,EAAIjB,EAAS,EAEb,OACEH,EAACU,EAAA,CACC,SAAAT,EAACO,EAAQ,KAAR,CACC,UAAAP,EAACU,EAAQ,KAAR,CACC,UAAAX,EAACW,EAAQ,QAAR,CACC,SAAAX,EAACQ,EAAQ,QAAR,CACC,SAAAR,EAACI,EAAA,CACC,MAAM,SACN,UAAU,OACV,QAASgB,EAA2B,OAAS,QAE7C,SAAApB,EAACY,EAAA,EAAM,EACT,EACF,EACF,EACAZ,EAACW,EAAQ,QAAR,CAAgB,QAAQ,eAAe,GAC1C,EACAV,EAACO,EAAQ,QAAR,CAAgB,QAAQ,QAAQ,MAAM,QAAQ,OAAO,QACpD,UAAAR,EAACQ,EAAQ,OAAR,CAAe,QAAO,GACrB,SAAAP,EAACK,EAAA,CAAK,QAAQ,UAAU,MAAM,SAC5B,UAAAN,EAACO,EAAA,CAAQ,KAAM,EAAG,yBAAa,EAC/BP,EAACQ,EAAQ,MAAR,CACC,SAAAR,EAACI,EAAA,CAAO,MAAM,SAAS,UAAU,OAAO,QAAQ,QAAQ,KAAK,SAAS,MAAM,QAC1E,SAAAJ,EAACe,EAAA,EAAE,EACL,EACF,GACF,EACF,EACAf,EAACQ,EAAQ,KAAR,CACC,SAAAP,EAACK,EAAA,CAAK,UAAU,SAAS,IAAK,EAC3B,UAAAa,EAAc,OAAS,GACtBnB,EAACM,EAAA,CAAK,QAAQ,SAAS,MAAM,SAC3B,SAAAN,EAACS,EAAA,CAAK,QAAQ,WAAW,KAAM,EAAG,iCAElC,EACF,EAEDU,EAAc,IAAKE,GAClBrB,EAACK,EAAA,CACC,SAAAJ,EAACK,EAAA,CAAK,MAAM,SAAS,IAAK,EAAG,QAAQ,UACnC,UAAAL,EAACK,EAAA,CAAK,UAAU,SAAS,IAAK,EAC5B,UAAAN,EAACS,EAAA,CAAK,GAAG,IAAI,QAAQ,YAAY,OAAO,WAAW,KAAM,EACtD,SAAAY,EAAa,gBAAgB,KAChC,EACArB,EAACS,EAAA,CAAK,KAAM,EAAG,QAAQ,WACpB,SAAAP,EAAmBmB,EAAa,OAAQ,IAAI,IAAM,EACrD,GACF,EACApB,EAACU,EAAQ,KAAR,CACC,UAAAX,EAACW,EAAQ,QAAR,CACC,SAAAX,EAACI,EAAA,CACC,MAAM,SACN,QAAQ,QACR,UAAU,OACV,KAAMiB,EAAa,OAAS,SAAW,WACvC,QAAS,IAAM,CACTA,EAAa,OACfH,EAAyBG,EAAa,EAAE,EAExCJ,EAAuBI,EAAa,EAAE,CAE1C,EAEC,SAAAA,EAAa,OAASrB,EAACc,EAAA,EAAS,EAAKd,EAACa,EAAA,EAAK,EAC9C,EACF,EACAb,EAACW,EAAQ,QAAR,CACC,QAASU,EAAa,OAAS,iBAAmB,eACpD,GACF,GACF,GAhCSA,EAAa,EAiCxB,CACD,GACH,EACF,EACArB,EAACQ,EAAQ,OAAR,CAAe,QAAO,GACrB,SAAAR,EAACS,EAAA,CAAK,GAAG,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,WAAW,KAAM,EAAG,4BAEvE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOa,EAAQN",
4
+ "sourcesContent": ["import { intlFormatDistance } from 'date-fns';\n\nimport { useInApp } from '../hooks/index.js';\nimport { Button, Card, Flex, Heading, Popover, Text, Theme, Tooltip } from '../components';\nimport { Inbox, Mail, MailOpen, X } from '../icons/index.js';\n\nconst NotificationBell = () => {\n let {\n markNotificationAsRead,\n markNotificationAsUnread,\n notifications,\n unreadNotificationsCount,\n } = useInApp();\n\n return (\n <Theme>\n <Popover.Root>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Popover.Trigger>\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant={unreadNotificationsCount ? 'fill' : 'ghost'}\n >\n <Inbox />\n </Button>\n </Popover.Trigger>\n </Tooltip.Trigger>\n <Tooltip.Content content=\"Notification\" />\n </Tooltip.Root>\n <Popover.Content spacing=\"large\" width=\"350px\" height=\"450px\">\n <Popover.Header asChild>\n <Flex justify=\"between\" align=\"center\">\n <Heading size={3}>Notifications</Heading>\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n </Flex>\n </Popover.Header>\n <Popover.Body>\n <Flex direction=\"column\" gap={1}>\n {notifications.length === 0 && (\n <Flex justify=\"center\" align=\"center\">\n <Text variant=\"tertiary\" size={2}>\n No notifications yet.\n </Text>\n </Flex>\n )}\n {notifications.map((notification) => (\n <Card key={notification.id}>\n <Flex align=\"center\" gap={4} justify=\"between\">\n <Flex direction=\"column\" gap={1}>\n <Text as=\"p\" variant=\"secondary\" weight=\"semibold\" size={2}>\n {notification.renderedContent.body}\n </Text>\n <Text size={1} variant=\"tertiary\">\n {intlFormatDistance(notification.sentAt, new Date())}\n </Text>\n </Flex>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Button\n shape=\"square\"\n variant=\"ghost\"\n roundness=\"full\"\n mode={notification.readAt ? 'subtle' : 'distinct'}\n onPress={() => {\n if (notification.readAt) {\n markNotificationAsUnread(notification.id);\n } else {\n markNotificationAsRead(notification.id);\n }\n }}\n >\n {notification.readAt ? <MailOpen /> : <Mail />}\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Content\n content={notification.readAt ? 'Mark as unread' : 'Mark as read'}\n />\n </Tooltip.Root>\n </Flex>\n </Card>\n ))}\n </Flex>\n </Popover.Body>\n <Popover.Footer asChild>\n <Text as=\"p\" align=\"center\" color=\"accent\" variant=\"tertiary\" size={1}>\n Powered by DashX\n </Text>\n </Popover.Footer>\n </Popover.Content>\n </Popover.Root>\n </Theme>\n );\n};\n\nexport default NotificationBell;\n"],
5
+ "mappings": "AAiBQ,OAQQ,OAAAA,EARR,QAAAC,MAAA,oBAjBR,OAAS,sBAAAC,MAA0B,WAEnC,OAAS,YAAAC,MAAgB,oBACzB,OAAS,UAAAC,EAAQ,QAAAC,EAAM,QAAAC,EAAM,WAAAC,EAAS,WAAAC,EAAS,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,gBAC3E,OAAS,SAAAC,EAAO,QAAAC,EAAM,YAAAC,EAAU,KAAAC,MAAS,oBAEzC,MAAMC,EAAmB,IAAM,CAC7B,GAAI,CACF,uBAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,yBAAAC,CACF,EAAIjB,EAAS,EAEb,OACEH,EAACU,EAAA,CACC,SAAAT,EAACO,EAAQ,KAAR,CACC,UAAAP,EAACU,EAAQ,KAAR,CACC,UAAAX,EAACW,EAAQ,QAAR,CACC,SAAAX,EAACQ,EAAQ,QAAR,CACC,SAAAR,EAACI,EAAA,CACC,MAAM,SACN,UAAU,OACV,QAASgB,EAA2B,OAAS,QAE7C,SAAApB,EAACY,EAAA,EAAM,EACT,EACF,EACF,EACAZ,EAACW,EAAQ,QAAR,CAAgB,QAAQ,eAAe,GAC1C,EACAV,EAACO,EAAQ,QAAR,CAAgB,QAAQ,QAAQ,MAAM,QAAQ,OAAO,QACpD,UAAAR,EAACQ,EAAQ,OAAR,CAAe,QAAO,GACrB,SAAAP,EAACK,EAAA,CAAK,QAAQ,UAAU,MAAM,SAC5B,UAAAN,EAACO,EAAA,CAAQ,KAAM,EAAG,yBAAa,EAC/BP,EAACQ,EAAQ,MAAR,CACC,SAAAR,EAACI,EAAA,CAAO,MAAM,SAAS,UAAU,OAAO,QAAQ,QAAQ,KAAK,SAAS,MAAM,QAC1E,SAAAJ,EAACe,EAAA,EAAE,EACL,EACF,GACF,EACF,EACAf,EAACQ,EAAQ,KAAR,CACC,SAAAP,EAACK,EAAA,CAAK,UAAU,SAAS,IAAK,EAC3B,UAAAa,EAAc,SAAW,GACxBnB,EAACM,EAAA,CAAK,QAAQ,SAAS,MAAM,SAC3B,SAAAN,EAACS,EAAA,CAAK,QAAQ,WAAW,KAAM,EAAG,iCAElC,EACF,EAEDU,EAAc,IAAKE,GAClBrB,EAACK,EAAA,CACC,SAAAJ,EAACK,EAAA,CAAK,MAAM,SAAS,IAAK,EAAG,QAAQ,UACnC,UAAAL,EAACK,EAAA,CAAK,UAAU,SAAS,IAAK,EAC5B,UAAAN,EAACS,EAAA,CAAK,GAAG,IAAI,QAAQ,YAAY,OAAO,WAAW,KAAM,EACtD,SAAAY,EAAa,gBAAgB,KAChC,EACArB,EAACS,EAAA,CAAK,KAAM,EAAG,QAAQ,WACpB,SAAAP,EAAmBmB,EAAa,OAAQ,IAAI,IAAM,EACrD,GACF,EACApB,EAACU,EAAQ,KAAR,CACC,UAAAX,EAACW,EAAQ,QAAR,CACC,SAAAX,EAACI,EAAA,CACC,MAAM,SACN,QAAQ,QACR,UAAU,OACV,KAAMiB,EAAa,OAAS,SAAW,WACvC,QAAS,IAAM,CACTA,EAAa,OACfH,EAAyBG,EAAa,EAAE,EAExCJ,EAAuBI,EAAa,EAAE,CAE1C,EAEC,SAAAA,EAAa,OAASrB,EAACc,EAAA,EAAS,EAAKd,EAACa,EAAA,EAAK,EAC9C,EACF,EACAb,EAACW,EAAQ,QAAR,CACC,QAASU,EAAa,OAAS,iBAAmB,eACpD,GACF,GACF,GAhCSA,EAAa,EAiCxB,CACD,GACH,EACF,EACArB,EAACQ,EAAQ,OAAR,CAAe,QAAO,GACrB,SAAAR,EAACS,EAAA,CAAK,GAAG,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,WAAW,KAAM,EAAG,4BAEvE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOa,EAAQN",
6
6
  "names": ["jsx", "jsxs", "intlFormatDistance", "useInApp", "Button", "Card", "Flex", "Heading", "Popover", "Text", "Theme", "Tooltip", "Inbox", "Mail", "MailOpen", "X", "NotificationBell", "markNotificationAsRead", "markNotificationAsUnread", "notifications", "unreadNotificationsCount", "notification", "NotificationBell_default"]
7
7
  }
@@ -1,3 +1,5 @@
1
+ export { default as Chat } from './Chat.js';
2
+ export { default as ChatPopover } from './ChatPopover.js';
1
3
  export { default as NotificationBell } from './NotificationBell.js';
2
4
  export { default as Preference } from './Preference.js';
3
5
  export { default as Preferences } from './Preferences.js';
@@ -1,2 +1,2 @@
1
- import{default as f}from"./NotificationBell.js";import{default as t}from"./Preference.js";import{default as l}from"./Preferences.js";export{f as NotificationBell,t as Preference,l as Preferences};
1
+ import{default as o}from"./Chat.js";import{default as a}from"./ChatPopover.js";import{default as l}from"./NotificationBell.js";import{default as s}from"./Preference.js";import{default as m}from"./Preferences.js";export{o as Chat,a as ChatPopover,l as NotificationBell,s as Preference,m as Preferences};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/widgets/index.ts"],
4
- "sourcesContent": ["export { default as NotificationBell } from './NotificationBell.js';\nexport { default as Preference } from './Preference.js';\nexport { default as Preferences } from './Preferences.js';\n"],
5
- "mappings": "AAAA,OAAoB,WAAXA,MAAmC,wBAC5C,OAAoB,WAAXA,MAA6B,kBACtC,OAAoB,WAAXA,MAA8B",
4
+ "sourcesContent": ["export { default as Chat } from './Chat.js';\nexport { default as ChatPopover } from './ChatPopover.js';\nexport { default as NotificationBell } from './NotificationBell.js';\nexport { default as Preference } from './Preference.js';\nexport { default as Preferences } from './Preferences.js';\n"],
5
+ "mappings": "AAAA,OAAoB,WAAXA,MAAuB,YAChC,OAAoB,WAAXA,MAA8B,mBACvC,OAAoB,WAAXA,MAAmC,wBAC5C,OAAoB,WAAXA,MAA6B,kBACtC,OAAoB,WAAXA,MAA8B",
6
6
  "names": ["default"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashx/react",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "license": "UNLICENSED",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/cjs/index.js",
@@ -75,7 +75,7 @@
75
75
  "clean": "rm -rf .turbo node_modules dist tokens layout *.css"
76
76
  },
77
77
  "dependencies": {
78
- "@dashx/browser": "^0.4.4",
78
+ "@dashx/browser": "^0.4.10",
79
79
  "@radix-ui/colors": "^3.0.0",
80
80
  "@radix-ui/primitive": "^1.0.1",
81
81
  "@radix-ui/react-accessible-icon": "^1.0.3",
@@ -122,13 +122,15 @@
122
122
  "prettier": "^3.2.5",
123
123
  "react-aria": "^3.33.1",
124
124
  "react-hot-toast": "^2.4.1",
125
+ "react-markdown": "^10.1.0",
125
126
  "react-remove-scroll-bar": "2.3.4",
126
127
  "react-use-websocket": "^4.8.1",
127
128
  "tailwind-merge": "^2.3.0",
128
129
  "tailwind-variants": "^0.2.1",
129
130
  "tailwindcss": "^4.0.0-alpha.15",
130
131
  "tailwindcss-animate": "^1.0.7",
131
- "tailwindcss-react-aria-components": "^1.1.3"
132
+ "tailwindcss-react-aria-components": "^1.1.3",
133
+ "uuid-random": "^1.3.2"
132
134
  },
133
135
  "peerDependencies": {
134
136
  "@types/react": "*",
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ import * as AvatarPrimitive from '@radix-ui/react-avatar';
3
+ import { Slot } from '@radix-ui/react-slot';
4
+
5
+ import { cn } from '../utils/cn.js';
6
+ import { avatar } from '../variants/avatar.js';
7
+
8
+ import type { AvatarVariantProps } from '../variants/avatar.js';
9
+
10
+ function _Avatar(
11
+ props: AvatarPrimitive.AvatarImageProps &
12
+ AvatarPrimitive.AvatarFallbackProps &
13
+ AvatarVariantProps,
14
+ ref: React.ForwardedRef<HTMLDivElement>,
15
+ ) {
16
+ const { size, roundness, src, alt, delayMs, children } = props;
17
+ return (
18
+ <AvatarPrimitive.Root ref={ref}>
19
+ <AvatarPrimitive.Image
20
+ className={cn('dx', avatar({ size, roundness }))}
21
+ src={src}
22
+ alt={alt}
23
+ data-radius={roundness}
24
+ />
25
+ <AvatarPrimitive.Fallback delayMs={delayMs}>{children}</AvatarPrimitive.Fallback>
26
+ </AvatarPrimitive.Root>
27
+ );
28
+ }
29
+
30
+ const Avatar = React.forwardRef(_Avatar);
31
+
32
+ export { Avatar };
@@ -44,6 +44,11 @@ const flexVariants = tv({
44
44
  start: 'items-start',
45
45
  end: 'items-end',
46
46
  },
47
+ wrap: {
48
+ nowrap: 'flex-nowrap',
49
+ wrap: 'flex-wrap',
50
+ 'wrap-reverse': 'flex-wrap-reverse',
51
+ },
47
52
  },
48
53
  });
49
54
 
@@ -53,11 +58,11 @@ type FlexProps = VariantProps<typeof flexVariants> & {
53
58
 
54
59
  const Flex = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement> & FlexProps>(
55
60
  (props, ref) => {
56
- const { className, direction, gap, justify, align, asChild, ...rest } = props;
61
+ const { className, direction, gap, justify, align, wrap, asChild, ...rest } = props;
57
62
  const Comp = asChild ? Slot : 'div';
58
63
  return (
59
64
  <Comp
60
- className={flexVariants({ direction, gap, justify, align, className })}
65
+ className={flexVariants({ direction, gap, justify, align, wrap, className })}
61
66
  ref={ref}
62
67
  {...rest}
63
68
  />
@@ -1,3 +1,4 @@
1
+ export * from './avatar.js';
1
2
  export * from './button.js';
2
3
  export * from './card.js';
3
4
  export * from './checkbox.js';
@@ -0,0 +1,57 @@
1
+ import React from 'react'
2
+ import ReactMarkdown from 'react-markdown'
3
+
4
+ import { Heading } from './heading.js'
5
+ import { Link } from './link.js'
6
+ import { Text } from './text.js'
7
+ import useAnimatedText from '../hooks/use-animated-text.js'
8
+
9
+ type MarkdownRendererProps = {
10
+ children: string,
11
+ animate?: boolean
12
+ animationSpeed?: number
13
+ onAnimationComplete?: () => void
14
+ }
15
+
16
+ function MarkdownRenderer({ children, animate = false, animationSpeed = 8, onAnimationComplete }: MarkdownRendererProps) {
17
+ const { displayedText } = useAnimatedText({
18
+ text: children,
19
+ speed: animationSpeed,
20
+ onComplete: onAnimationComplete,
21
+ enabled: animate
22
+ });
23
+
24
+ return (
25
+ <div className="space-y-6">
26
+ <ReactMarkdown
27
+ components={{
28
+ h1({ children }) {
29
+ return <Heading as="h1" size={4} className="text-gray-900">{children}</Heading>
30
+ },
31
+ h2({ children }) {
32
+ return <Heading as="h2" size={3} className="text-gray-900">{children}</Heading>
33
+ },
34
+ p({ children }) {
35
+ return <Text as="p" className="text-gray-900">{children}</Text>
36
+ },
37
+ ul({ children }) {
38
+ return <ul className="list-disc list-inside">{children}</ul>
39
+ },
40
+ ol({ children }) {
41
+ return <ol className="list-decimal list-inside">{children}</ol>
42
+ },
43
+ li({ children }) {
44
+ return <li className="text-gray-900">{children}</li>
45
+ },
46
+ a({ children, href }) {
47
+ return <Link href={href}>{children}</Link>
48
+ },
49
+ }}
50
+ >
51
+ {displayedText}
52
+ </ReactMarkdown>
53
+ </div>
54
+ )
55
+ }
56
+
57
+ export { MarkdownRenderer }
@@ -1,21 +1,23 @@
1
+ import { filterDOMProps } from '@react-aria/utils';
2
+ import { forwardRef, useRef, type ReactNode, useEffect } from 'react';
1
3
  import { useContextProps, TextFieldContext } from 'react-aria-components';
2
- import { cn } from '../utils/cn.js';
4
+ import { useTextField } from 'react-aria';
5
+ import type { TextFieldProps, ValidationResult } from 'react-aria-components';
3
6
 
4
- import { Flex, Text } from './index.js';
7
+ import { cn } from '../utils/cn.js';
5
8
  import { fieldError } from '../variants/field-error.js';
6
- import { filterDOMProps } from '@react-aria/utils';
7
- import { useTextField } from 'react-aria';
8
- import { forwardRef, useRef, type ReactNode } from 'react';
9
+ import { Flex, Text } from './index.js';
9
10
  import { removeDataAttributes } from '../utils/helpers.js';
10
-
11
- import type { TextFieldProps, ValidationResult } from 'react-aria-components';
12
11
  import { textArea, type TextAreaVariantProps } from '../variants/text-area.js';
13
12
 
13
+ const MAX_HEIGHT = 180;
14
+
14
15
  interface TextAreaProps extends TextFieldProps, TextAreaVariantProps {
15
16
  placeholder?: string;
16
17
  label?: string;
17
18
  description?: string | ReactNode;
18
19
  errorMessage?: string | ((validation: ValidationResult) => string);
20
+ autogrow?: boolean;
19
21
  }
20
22
 
21
23
  function _TextArea(
@@ -26,12 +28,13 @@ function _TextArea(
26
28
  size = 'medium',
27
29
  roundness = 'medium',
28
30
  elevation = 'medium',
31
+ autogrow = false,
29
32
  ...props
30
33
  }: TextAreaProps,
31
34
  ref: React.ForwardedRef<HTMLDivElement>,
32
35
  ) {
33
36
  [props, ref] = useContextProps(props, ref, TextFieldContext);
34
- let inputRef = useRef(null);
37
+ let inputRef = useRef<HTMLTextAreaElement>(null);
35
38
 
36
39
  let { labelProps, inputProps, descriptionProps, errorMessageProps, ...validation } =
37
40
  useTextField<any>(
@@ -43,6 +46,15 @@ function _TextArea(
43
46
  inputRef,
44
47
  );
45
48
 
49
+ useEffect(() => {
50
+ if (autogrow && inputRef.current) {
51
+ inputRef.current.style.height = "0px";
52
+ const scrollHeight = inputRef.current.scrollHeight;
53
+
54
+ inputRef.current.style.height = Math.min(scrollHeight, MAX_HEIGHT) + "px";
55
+ }
56
+ }, [autogrow, inputRef, inputProps.value]);
57
+
46
58
  return (
47
59
  <Flex
48
60
  {...filterDOMProps(props)}
@@ -67,11 +79,11 @@ function _TextArea(
67
79
  {label}
68
80
  </Text>
69
81
  )}
70
- <div role="group" className="relative" data-radius={roundness} data-shadow={elevation}>
82
+ <Flex role="group" className="relative" data-radius={roundness} data-shadow={elevation}>
71
83
  <textarea
72
84
  {...inputProps}
73
85
  ref={inputRef}
74
- className={cn('dx', 'w-full', textArea({ size, roundness, elevation }))}
86
+ className={cn('dx', 'w-full resize-none', textArea({ size, roundness, elevation }))}
75
87
  data-disabled={props.isDisabled || undefined}
76
88
  data-invalid={validation.isInvalid || undefined}
77
89
  data-readonly={props.isReadOnly || undefined}
@@ -92,7 +104,7 @@ function _TextArea(
92
104
  : validation.validationErrors.join(' ')}
93
105
  </Text>
94
106
  )}
95
- </div>
107
+ </Flex>
96
108
  {description && (
97
109
  <Text size={1} variant="tertiary" {...descriptionProps}>
98
110
  {description}
@@ -1,3 +1,5 @@
1
+ export { useWebSocket } from '../providers/DashXProvider.js';
2
+ export { default as useAgent } from './use-agent.js';
1
3
  export { default as useDashXProvider } from './use-dashx-provider.js';
2
4
  export { default as useInApp } from './use-in-app.js';
3
5
  export { default as useProductRelease } from './use-product-release.js';
@@ -0,0 +1,89 @@
1
+ import uuid from 'uuid-random';
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import type { AiAgent, AiMessage } from '@dashx/browser';
4
+
5
+ import useDashXProvider from './use-dashx-provider.js';
6
+
7
+ type UseAgentHookProps = {
8
+ publicEmbedKey: string;
9
+ }
10
+
11
+ type UseAgentHookResponse = {
12
+ agent?: AiAgent;
13
+ conversationId: string | null;
14
+ messages: AiMessage[];
15
+ isThinking: boolean;
16
+ error: string | null;
17
+ sendMessage: (text: string) => Promise<void>;
18
+ }
19
+
20
+ const useAgent = ({ publicEmbedKey }: UseAgentHookProps): UseAgentHookResponse => {
21
+ const dashX = useDashXProvider();
22
+
23
+ const [agent, setAgent] = useState<AiAgent>();
24
+
25
+ const [conversationId, setConversationId] = useState<string | null>(null);
26
+ const [messages, setMessages] = useState<AiMessage[]>([]);
27
+ const [isThinking, setIsThinking] = useState(false);
28
+ const [error, setError] = useState<string | null>(null);
29
+
30
+ useEffect(() => {
31
+ dashX
32
+ .loadAiAgent({
33
+ publicEmbedKey,
34
+ })
35
+ .then((agent) => {
36
+ setAgent(agent);
37
+ setError(null);
38
+ })
39
+ .catch((err) => {
40
+ setError(err);
41
+ });
42
+ }, [dashX, publicEmbedKey]);
43
+
44
+ const sendMessage = useCallback(
45
+ async (text: string) => {
46
+ if (!text.trim() || !agent) return;
47
+
48
+ try {
49
+ setMessages((prev) => [...prev, {
50
+ id: uuid(),
51
+ role: 'user',
52
+ content: text
53
+ } as AiMessage]);
54
+ setIsThinking(true);
55
+ setError(null);
56
+
57
+ const response = await dashX.invokeAiAgent({
58
+ conversationId,
59
+ prompt: text,
60
+ publicEmbedKey,
61
+ });
62
+
63
+ if (response.conversationId && !conversationId) {
64
+ setConversationId(response.conversationId);
65
+ }
66
+
67
+ setMessages((prev) => [...prev, response]);
68
+ } catch (err) {
69
+ setError('Failed to send message');
70
+ } finally {
71
+ setIsThinking(false);
72
+ }
73
+ },
74
+ [dashX, agent, publicEmbedKey, conversationId]
75
+ );
76
+
77
+ return {
78
+ agent,
79
+ conversationId,
80
+ messages,
81
+ isThinking,
82
+ error,
83
+ sendMessage,
84
+ };
85
+ };
86
+
87
+ export type { UseAgentHookProps, UseAgentHookResponse };
88
+
89
+ export default useAgent;
@@ -0,0 +1,67 @@
1
+ import { useState, useEffect, useRef, useCallback } from 'react';
2
+
3
+ type UseAnimatedTextOptions = {
4
+ text: string;
5
+ speed?: number;
6
+ onComplete?: () => void;
7
+ enabled?: boolean;
8
+ };
9
+
10
+ type UseAnimatedTextReturn = {
11
+ displayedText: string;
12
+ };
13
+
14
+ const useAnimatedText = ({
15
+ text,
16
+ speed = 8,
17
+ onComplete,
18
+ enabled = true
19
+ }: UseAnimatedTextOptions): UseAnimatedTextReturn => {
20
+ const [displayedText, setDisplayedText] = useState('');
21
+
22
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
23
+ const currentIndexRef = useRef(0);
24
+ const onCompleteRef = useRef(onComplete);
25
+
26
+ useEffect(() => {
27
+ onCompleteRef.current = onComplete;
28
+ }, [onComplete]);
29
+
30
+ const animate = useCallback(() => {
31
+ if (currentIndexRef.current < text.length) {
32
+ setDisplayedText(text.substring(0, currentIndexRef.current + 1));
33
+ currentIndexRef.current++;
34
+ timeoutRef.current = setTimeout(animate, speed);
35
+ } else {
36
+ onCompleteRef.current?.();
37
+ }
38
+ }, [text, speed]);
39
+
40
+ useEffect(() => {
41
+ if (!text) {
42
+ setDisplayedText('');
43
+ return;
44
+ }
45
+
46
+ if (!enabled) {
47
+ setDisplayedText(text);
48
+ return;
49
+ }
50
+
51
+ currentIndexRef.current = 0;
52
+ setDisplayedText('');
53
+ animate();
54
+
55
+ return () => {
56
+ if (timeoutRef.current) {
57
+ clearTimeout(timeoutRef.current);
58
+ }
59
+ };
60
+ }, [text, animate, enabled]);
61
+
62
+ return {
63
+ displayedText
64
+ };
65
+ }
66
+
67
+ export default useAnimatedText;
@@ -0,0 +1,65 @@
1
+ import { useRef, useCallback, useEffect } from 'react';
2
+
3
+ const SCROLL_BOTTOM_THRESHOLD = 100;
4
+
5
+ type UseAutoScrollOptions = {
6
+ threshold?: number;
7
+ };
8
+
9
+ type UseAutoScrollReturn = {
10
+ scrollAreaRef: React.RefObject<HTMLDivElement>;
11
+ scrollToBottom: (options?: { smooth?: boolean }) => void;
12
+ checkIfUserAtBottom: () => void;
13
+ isUserAtBottom: boolean;
14
+ };
15
+
16
+ const useAutoScroll = ({
17
+ threshold = SCROLL_BOTTOM_THRESHOLD
18
+ }: UseAutoScrollOptions = {}): UseAutoScrollReturn => {
19
+ const scrollAreaRef = useRef<HTMLDivElement>(null);
20
+ const isUserAtBottomRef = useRef(true);
21
+
22
+ const scrollToBottom = useCallback(({ smooth = false } = {}) => {
23
+ if (scrollAreaRef.current) {
24
+ const scrollContainer = scrollAreaRef.current.querySelector('[data-radix-scroll-area-viewport]');
25
+ if (scrollContainer) {
26
+ scrollContainer.scrollTo({
27
+ top: scrollContainer.scrollHeight,
28
+ behavior: smooth ? 'smooth' : 'auto'
29
+ });
30
+ }
31
+ }
32
+ }, []);
33
+
34
+ const checkIfUserAtBottom = useCallback(() => {
35
+ if (scrollAreaRef.current) {
36
+ const scrollContainer = scrollAreaRef.current.querySelector('[data-radix-scroll-area-viewport]');
37
+ if (scrollContainer) {
38
+ const { scrollTop, scrollHeight, clientHeight } = scrollContainer;
39
+ const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
40
+ isUserAtBottomRef.current = distanceFromBottom <= threshold;
41
+ }
42
+ }
43
+ }, [threshold]);
44
+
45
+ useEffect(() => {
46
+ const scrollContainer = scrollAreaRef.current?.querySelector('[data-radix-scroll-area-viewport]');
47
+ if (scrollContainer) {
48
+ const handleScroll = () => {
49
+ checkIfUserAtBottom();
50
+ };
51
+
52
+ scrollContainer.addEventListener('scroll', handleScroll);
53
+ return () => scrollContainer.removeEventListener('scroll', handleScroll);
54
+ }
55
+ }, [checkIfUserAtBottom]);
56
+
57
+ return {
58
+ scrollAreaRef,
59
+ scrollToBottom,
60
+ checkIfUserAtBottom,
61
+ isUserAtBottom: isUserAtBottomRef.current
62
+ };
63
+ };
64
+
65
+ export default useAutoScroll;
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- // export * from './components/index.js';
1
+ export * from './components/index.js';
2
2
  export * from './hooks/index.js';
3
3
  export * from './providers/index.js';
4
+ export * from './widgets/index.js';
package/src/legacy.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './hooks/index.js';
2
+ export * from './providers/index.js';
@@ -1,12 +1,13 @@
1
1
  import DashX from '@dashx/browser';
2
2
  import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
3
- import type { Client, ClientParams, WebsocketMessageType } from '@dashx/browser';
3
+ import type { Client, ClientParams, WebSocketManager, WebsocketMessageType } from '@dashx/browser';
4
4
 
5
5
  const DashXContext = createContext<Client | null>(null);
6
6
 
7
7
  type WebSocketContextType = {
8
8
  isConnected: boolean;
9
9
  subscribe: (callback: (message: WebsocketMessageType) => void) => () => void;
10
+ wsManagerRef: React.RefObject<WebSocketManager>;
10
11
  };
11
12
 
12
13
  const WebSocketContext = createContext<WebSocketContextType | null>(null);
@@ -35,7 +36,7 @@ function DashXProvider({
35
36
 
36
37
  // WebSocket state
37
38
  const [isConnected, setIsConnected] = useState(false);
38
- const wsManagerRef = useRef<any>(null);
39
+ const wsManagerRef = useRef<WebSocketManager | null>(null);
39
40
  const subscribersRef = useRef<Set<(message: WebsocketMessageType) => void>>(new Set());
40
41
 
41
42
  const subscribe = (callback: (message: WebsocketMessageType) => void) => {
@@ -99,7 +100,7 @@ function DashXProvider({
99
100
 
100
101
  return (
101
102
  <DashXContext.Provider value={dashX}>
102
- <WebSocketContext.Provider value={{ isConnected, subscribe }}>
103
+ <WebSocketContext.Provider value={{ isConnected, subscribe, wsManagerRef }}>
103
104
  {children}
104
105
  </WebSocketContext.Provider>
105
106
  </DashXContext.Provider>